From eaef67c91335aea25d005285e9a5b6e76805eb2e Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Sun, 13 Jun 2010 23:13:48 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0=20trunk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit +YUCHENG HU+ git-svn-id: https://svn.code.sf.net/p/hawebs/svn@318 a2543c7e-f6e9-4f8a-8bff-1ffc34733512 --- .../components/com_trash/admin.trash.html.php | 362 ++++++++++++++++ .../components/com_trash/admin.trash.php | 395 ++++++++++++++++++ .../components/com_trash/index.html | 1 + .../com_trash/toolbar.trash.html.php | 48 +++ .../components/com_trash/toolbar.trash.php | 33 ++ .../components/com_trash/trash.xml | 11 + 6 files changed, 850 insertions(+) create mode 100644 oss/joomla/trunk/administrator/components/com_trash/admin.trash.html.php create mode 100644 oss/joomla/trunk/administrator/components/com_trash/admin.trash.php create mode 100644 oss/joomla/trunk/administrator/components/com_trash/index.html create mode 100644 oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.html.php create mode 100644 oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.php create mode 100644 oss/joomla/trunk/administrator/components/com_trash/trash.xml diff --git a/oss/joomla/trunk/administrator/components/com_trash/admin.trash.html.php b/oss/joomla/trunk/administrator/components/com_trash/admin.trash.html.php new file mode 100644 index 00000000..27974435 --- /dev/null +++ b/oss/joomla/trunk/administrator/components/com_trash/admin.trash.html.php @@ -0,0 +1,362 @@ + +
+ + + + + + +
+ : + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + "> + + + + + + + + + +
+ + + + + + + + + + + +
+ getListFooter(); ?> +
+ limitstart;?> + + id ); ?> + + title; ?> + + id; ?> + + sectname; ?> + + catname; ?> +
+
+ + + + + + + +
+ + +
+ + + + + + +
+ : + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + "> + + + + + + + + + +
+ + + + + + + + + + + +
+ getListFooter(); ?> +
+ limitstart;?> + + + + name; ?> + + id; ?> + + menutype; ?> + + type; ?> +
+
+ + + + + + + +
+ +
+ + + + + + + + + + + +
+ + : +
+ +

+
+ : +
+ "; + foreach ( $items as $item ) { + echo "
  • ". $item->name ."
  • "; + } + echo ""; + ?> +
    +


    + +   +
     
    +

    + + + + + + + "; + } + ?> + +
    + +
    + + + + + + + + + + + +
    + : +
    + +

    +
    + : +
    + "; + foreach ( $items as $item ) { + echo "
  • ". $item->name ."
  • "; + } + echo ""; + ?> +

    +


    +
    + + <?php echo JText::_( 'Restore' ); ?> +   +
    +
     
    +

    + + + + + + + "; + } + ?> + +
    + authorize( 'com_trash', 'manage' )) { + $mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') ); +} + +require_once( JApplicationHelper::getPath( 'admin_html' ) ); + +$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); +$mid = JRequest::getVar( 'mid', array(0), 'post', 'array' ); + +JArrayHelper::toInteger($cid, array(0)); +JArrayHelper::toInteger($mid, array(0)); + +switch ($task) +{ + case 'deleteconfirm': + viewdeleteTrash( $cid, $mid, $option ); + break; + + case 'delete': + deleteTrash( $cid, $option ); + break; + + case 'restoreconfirm': + viewrestoreTrash( $cid, $mid, $option ); + break; + + case 'restore': + restoreTrash( $cid, $option ); + break; + + case 'viewMenu': + viewTrashMenu( $option ); + break; + + case 'viewContent': + viewTrashContent( $option ); + break; + + default: + $return = JRequest::getCmd( 'return', 'viewContent', 'post' ); + if ( $return == 'viewMenu' ) { + viewTrashMenu( $option ); + } else { + viewTrashContent( $option ); + } + break; +} + + +/** +* Compiles a list of trash items +*/ +function viewTrashContent( $option ) +{ + global $mainframe; + + $db =& JFactory::getDBO(); + $filter_order = $mainframe->getUserStateFromRequest( "$option.viewContent.filter_order", 'filter_order', 'sectname', 'cmd' ); + $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.viewContent.filter_order_Dir", 'filter_order_Dir', '', 'word' ); + $search = $mainframe->getUserStateFromRequest( "$option.search", 'search', '', 'string' ); + $search = JString::strtolower( $search ); + + $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' ); + $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' ); + + $where[] = 'c.state = -2'; + + if ($search) { + $where[] = 'LOWER(c.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ); + } + + $where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' ); + $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', s.name, cc.name, c.title'; + + // get the total number of content + $query = 'SELECT count(c.id)' + . ' FROM #__content AS c' + . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid' + . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope = "content"' + . ' LEFT JOIN #__groups AS g ON g.id = c.access' + . ' LEFT JOIN #__users AS u ON u.id = c.checked_out' + . $where + ; + $db->setQuery( $query ); + $total = $db->loadResult(); + + jimport('joomla.html.pagination'); + $pageNav = new JPagination( $total, $limitstart, $limit ); + + // Query articles + $query = 'SELECT c.title, c.id, c.sectionid, c.catid, g.name AS groupname, cc.title AS catname, s.title AS sectname' + . ' FROM #__content AS c' + . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid' + . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"' + . ' LEFT JOIN #__groups AS g ON g.id = c.access' + . ' LEFT JOIN #__users AS u ON u.id = c.checked_out' + . $where + . $orderby + ; + $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); + $contents = $db->loadObjectList(); + + for ( $i = 0; $i < count($contents); $i++ ) { + if ( ( $contents[$i]->sectionid == 0 ) && ( $contents[$i]->catid == 0 ) ) { + $contents[$i]->sectname = JText::_('UNCATEGORIZED'); + } + } + + // table ordering + $lists['order_Dir'] = $filter_order_Dir; + $lists['order'] = $filter_order; + + // search filter + $lists['search']= $search; + + HTML_trash::showListContent( $option, $contents, $pageNav, $lists ); +} + +/** +* Compiles a list of trash items +*/ +function viewTrashMenu( $option ) +{ + global $mainframe; + + $db =& JFactory::getDBO(); + $filter_order = $mainframe->getUserStateFromRequest( "$option.viewMenu.filter_order", 'filter_order', 'm.menutype', 'cmd' ); + $filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.viewMenu.filter_order_Dir", 'filter_order_Dir', '', 'word' ); + $limit = $mainframe->getUserStateFromRequest( "limit", 'limit', $mainframe->getCfg('list_limit'), 'int' ); + $limitstart = $mainframe->getUserStateFromRequest( "$option.viewMenu.limitstart", 'limitstart', 0, 'int' ); + $search = $mainframe->getUserStateFromRequest( "$option.search", 'search', '', 'string' ); + $search = JString::strtolower( $search ); + + $where[] = 'm.published = -2'; + + if ($search) { + $where[] = 'LOWER(m.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false ); + } + + $where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' ); + $orderby = ' ORDER BY '. $filter_order . ' ' . $filter_order_Dir .', m.menutype, m.ordering, m.ordering, m.name'; + + $query = 'SELECT count(*)' + . ' FROM #__menu AS m' + . ' LEFT JOIN #__users AS u ON u.id = m.checked_out' + . $where + ; + $db->setQuery( $query ); + $total = $db->loadResult(); + + jimport('joomla.html.pagination'); + $pageNav = new JPagination( $total, $limitstart, $limit ); + + // Query menu items + $query = 'SELECT m.name, m.id, m.menutype, m.type, com.name AS com_name' + . ' FROM #__menu AS m' + . ' LEFT JOIN #__users AS u ON u.id = m.checked_out' + . ' LEFT JOIN #__components AS com ON com.id = m.componentid AND m.type = "components"' + . $where + . $orderby + ; + $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); + $menus = $db->loadObjectList(); + + // table ordering + $lists['order_Dir'] = $filter_order_Dir; + $lists['order'] = $filter_order; + + // search filter + $lists['search']= $search; + + HTML_trash::showListMenu( $option, $menus, $pageNav, $lists ); +} + + +/** +* Compiles a list of the items you have selected to permanently delte +*/ +function viewdeleteTrash( $cid, $mid, $option ) +{ + global $mainframe; + + $db =& JFactory::getDBO(); + $return = JRequest::getCmd( 'return', 'viewContent', 'post' ); + + JArrayHelper::toInteger($cid, array(0)); + JArrayHelper::toInteger($mid, array(0)); + + // seperate contentids + $cids = implode( ',', $cid ); + $mids = implode( ',', $mid ); + + if ( $cids ) { + // Articles query + $query = 'SELECT a.title AS name' + . ' FROM #__content AS a' + . ' WHERE ( a.id IN ( '.$cids.' ) )' + . ' ORDER BY a.title' + ; + $db->setQuery( $query ); + $items = $db->loadObjectList(); + $id = $cid; + $type = "content"; + } else if ( $mids ) { + // Articles query + $query = 'SELECT a.name' + . ' FROM #__menu AS a' + . ' WHERE ( a.id IN ( '.$mids.' ) )' + . ' ORDER BY a.name' + ; + $db->setQuery( $query ); + $items = $db->loadObjectList(); + $id = $mid; + $type = "menu"; + } + + HTML_trash::showDelete( $option, $id, $items, $type, $return ); +} + + +/** +* Permanently deletes the selected list of trash items +*/ +function deleteTrash( $cid, $option ) +{ + global $mainframe; + + // Check for request forgeries + JRequest::checkToken() or jexit( 'Invalid Token' ); + + $db =& JFactory::getDBO(); + $return = JRequest::getCmd( 'return', 'viewContent', 'post' ); + $type = JRequest::getCmd( 'type', '', 'post' ); + + $total = count( $cid ); + + if ( $type == 'content' ) + { + $obj =& JTable::getInstance('content'); + + require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php'); + $fp = new TableFrontPage( $db ); + foreach ( $cid as $id ) { + $id = intval( $id ); + $obj->delete( $id ); + $fp->delete( $id ); + } + } else if ( $type == "menu" ) { + $obj =& JTable::getInstance('menu'); + foreach ( $cid as $id ) { + $id = intval( $id ); + $obj->delete( $id ); + } + } + + $msg = JText::sprintf( 'Item(s) successfully Deleted', $total ); + $mainframe->redirect( 'index.php?option='.$option.'&task='.$return, $msg ); +} + + +/** +* Compiles a list of the items you have selected to permanently delte +*/ +function viewrestoreTrash( $cid, $mid, $option ) { + global $mainframe; + + $db =& JFactory::getDBO(); + $return = JRequest::getCmd( 'return', 'viewContent', 'post' ); + + JArrayHelper::toInteger($cid, array(0)); + JArrayHelper::toInteger($mid, array(0)); + + // seperate contentids + $cids = implode( ',', $cid ); + $mids = implode( ',', $mid ); + + if ( $cids ) { + // Articles query + $query = 'SELECT a.title AS name' + . ' FROM #__content AS a' + . ' WHERE ( a.id IN ( '.$cids.' ) )' + . ' ORDER BY a.title' + ; + $db->setQuery( $query ); + $items = $db->loadObjectList(); + $id = $cid; + $type = "content"; + } else if ( $mids ) { + // Articles query + $query = 'SELECT a.name' + . ' FROM #__menu AS a' + . ' WHERE ( a.id IN ( '.$mids.' ) )' + . ' ORDER BY a.name' + ; + $db->setQuery( $query ); + $items = $db->loadObjectList(); + $id = $mid; + $type = "menu"; + } + + HTML_trash::showRestore( $option, $id, $items, $type, $return ); +} + + +/** +* Restores items selected to normal - restores to an unpublished state +*/ +function restoreTrash( $cid, $option ) +{ + global $mainframe; + + // Check for request forgeries + JRequest::checkToken() or jexit( 'Invalid Token' ); + + $db = & JFactory::getDBO(); + $type = JRequest::getCmd( 'type', '', 'post' ); + + $total = count( $cid ); + + // restores to an unpublished state + $state = 0; + $ordering = 9999; + + if ( $type == 'content' ) { + $return = 'viewContent'; + + //seperate contentids + JArrayHelper::toInteger($cid, array(0)); + $cids = implode( ',', $cid ); + + // query to restore article + $query = 'UPDATE #__content' + . ' SET state = '.(int) $state.', ordering = '.(int) $ordering + . ' WHERE id IN ( '.$cids.' )' + ; + $db->setQuery( $query ); + if ( !$db->query() ) { + JError::raiseError(500, $db->getErrorMsg() ); + } + } else if ( $type == 'menu' ) { + $return = 'viewMenu'; + + jimport('joomla.application.component.model'); + JModel::addIncludePath(JPATH_BASE.DS.'components'.DS.'com_menus'.DS.'models'); + $model =& JModel::getInstance('List', 'MenusModel'); + $total = $model->fromTrash($cid); + + if (!$total) { + JError::raiseError(500, $db->getErrorMsg() ); + } + } + + $msg = JText::sprintf( 'Item(s) successfully Restored', $total ); + $mainframe->redirect( 'index.php?option='.$option.'&task='.$return, $msg ); +} + +function ReadMenuXML( $type, $component=-1 ) +{ + // xml file for module + $xmlfile = JPATH_ADMINISTRATOR .'/components/com_menus/'. $type .'/'. $type .'.xml'; + + $data = JApplicationHelper::parseXMLInstallFile($xmlfile); + + if ( $data['type'] == 'component' || $data['type'] == 'menu' ) + { + if ( ( $component <> -1 ) && ( $data['name'] == 'Component') ) { + $data['name'] .= ' - '. $component; + } + + $row[0] = $data['name']; + } + + return $row; +} \ No newline at end of file diff --git a/oss/joomla/trunk/administrator/components/com_trash/index.html b/oss/joomla/trunk/administrator/components/com_trash/index.html new file mode 100644 index 00000000..fa6d84e8 --- /dev/null +++ b/oss/joomla/trunk/administrator/components/com_trash/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.html.php b/oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.html.php new file mode 100644 index 00000000..68b7c327 --- /dev/null +++ b/oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.html.php @@ -0,0 +1,48 @@ +['. JText::_( 'Menu Items' ) .']'; + } else { + $text = ': ['. JText::_( 'Articles' ) .']'; + } + + JToolBarHelper::title( JText::_( 'Trash Manager' ) . $text, 'trash.png' ); + JToolBarHelper::custom('restoreconfirm','restore.png','restore_f2.png', 'Restore', true); + JToolBarHelper::custom('deleteconfirm','delete.png','delete_f2.png', 'Delete', true); + JToolBarHelper::help( 'screen.trashmanager' ); + } + + function _RESTORE() { + JToolBarHelper::title( JText::_( 'Restore Items' ), 'restoredb.png' ); + JToolBarHelper::cancel(); + } + + function _DELETE() { + JToolBarHelper::title( JText::_( 'Delete Items' ), 'delete_f2.png' ); + JToolBarHelper::cancel(); + } +} \ No newline at end of file diff --git a/oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.php b/oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.php new file mode 100644 index 00000000..9e06f1c5 --- /dev/null +++ b/oss/joomla/trunk/administrator/components/com_trash/toolbar.trash.php @@ -0,0 +1,33 @@ + + + Trash + Joomla! Project + Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. + http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + admin@joomla.org + www.joomla.org + 1.0.0 + PARAMTRASH +