[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_trash/ -> admin.trash.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: admin.trash.php 19343 2010-11-03 18:12:02Z ian $
   4  * @package        Joomla
   5  * @subpackage    Trash
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // no direct access
  16  defined( '_JEXEC' ) or die( 'Restricted access' );
  17  
  18  /*
  19   * Make sure the user is authorized to view this page
  20   */
  21  $user = & JFactory::getUser();
  22  if (!$user->authorize( 'com_trash', 'manage' )) {
  23      $mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
  24  }
  25  
  26  require_once( JApplicationHelper::getPath( 'admin_html' ) );
  27  
  28  $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
  29  $mid = JRequest::getVar( 'mid', array(0), 'post', 'array' );
  30  
  31  JArrayHelper::toInteger($cid, array(0));
  32  JArrayHelper::toInteger($mid, array(0));
  33  
  34  switch ($task)
  35  {
  36      case 'deleteconfirm':
  37          viewdeleteTrash( $cid, $mid, $option );
  38          break;
  39  
  40      case 'delete':
  41          deleteTrash( $cid, $option );
  42          break;
  43  
  44      case 'restoreconfirm':
  45          viewrestoreTrash( $cid, $mid, $option );
  46          break;
  47  
  48      case 'restore':
  49          restoreTrash( $cid, $option );
  50          break;
  51  
  52      case 'viewMenu':
  53          viewTrashMenu( $option );
  54          break;
  55  
  56      case 'viewContent':
  57          viewTrashContent( $option );
  58          break;
  59  
  60      default:
  61          $return = JRequest::getCmd( 'return', 'viewContent', 'post' );
  62          if ( $return == 'viewMenu' ) {
  63              viewTrashMenu( $option );
  64          } else {
  65              viewTrashContent( $option );
  66          }
  67          break;
  68  }
  69  
  70  
  71  /**
  72  * Compiles a list of trash items
  73  */
  74  function viewTrashContent( $option )
  75  {
  76      global $mainframe;
  77  
  78      $db                    =& JFactory::getDBO();
  79      $filter_order        = $mainframe->getUserStateFromRequest( "$option.viewContent.filter_order",        'filter_order',        'sectname', 'cmd' );
  80      $filter_order_Dir    = $mainframe->getUserStateFromRequest( "$option.viewContent.filter_order_Dir",    'filter_order_Dir',    '',            'word' );
  81      $search                = $mainframe->getUserStateFromRequest( "$option.search",                        'search',             '',            'string' );
  82      if (strpos($search, '"') !== false) {
  83          $search = str_replace(array('=', '<'), '', $search);
  84      }
  85      $search = JString::strtolower($search);
  86  
  87      $limit        = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
  88      $limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
  89  
  90      $where[] = 'c.state = -2';
  91  
  92      if ($search) {
  93          $where[] = 'LOWER(c.title) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
  94      }
  95  
  96      $where         = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
  97  
  98      // ensure filter_order has a valid value
  99      if (!in_array($filter_order, array('c.title', 'c.id', 'sectname', 'catname'))) {
 100          $filter_order = 'sectname';
 101      }
 102  
 103      if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
 104          $filter_order_Dir = '';
 105      }
 106  
 107      $orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', s.name, cc.name, c.title';
 108  
 109      // get the total number of content
 110      $query = 'SELECT count(c.id)'
 111      . ' FROM #__content AS c'
 112      . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
 113      . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope = "content"'
 114      . ' LEFT JOIN #__groups AS g ON g.id = c.access'
 115      . ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
 116      . $where
 117      ;
 118      $db->setQuery( $query );
 119      $total = $db->loadResult();
 120  
 121      jimport('joomla.html.pagination');
 122      $pageNav = new JPagination( $total, $limitstart, $limit );
 123  
 124      // Query articles
 125      $query = 'SELECT c.title, c.id, c.sectionid, c.catid, g.name AS groupname, cc.title AS catname, s.title AS sectname'
 126      . ' FROM #__content AS c'
 127      . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
 128      . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"'
 129      . ' LEFT JOIN #__groups AS g ON g.id = c.access'
 130      . ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
 131      . $where
 132      . $orderby
 133      ;
 134      $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 135      $contents = $db->loadObjectList();
 136  
 137      for ( $i = 0; $i < count($contents); $i++ ) {
 138          if ( ( $contents[$i]->sectionid == 0 ) && ( $contents[$i]->catid == 0 ) ) {
 139              $contents[$i]->sectname = JText::_('UNCATEGORIZED');
 140          }
 141      }
 142  
 143      // table ordering
 144      $lists['order_Dir']    = $filter_order_Dir;
 145      $lists['order']        = $filter_order;
 146  
 147      // search filter
 148      $lists['search']= $search;
 149  
 150      HTML_trash::showListContent( $option, $contents, $pageNav, $lists );
 151  }
 152  
 153  /**
 154  * Compiles a list of trash items
 155  */
 156  function viewTrashMenu( $option )
 157  {
 158      global $mainframe;
 159  
 160      $db                    =& JFactory::getDBO();
 161      $filter_order        = $mainframe->getUserStateFromRequest( "$option.viewMenu.filter_order",        'filter_order',        'm.menutype',    'cmd' );
 162      $filter_order_Dir    = $mainframe->getUserStateFromRequest( "$option.viewMenu.filter_order_Dir",    'filter_order_Dir',    '',                'word' );
 163      $limit                = $mainframe->getUserStateFromRequest( "limit",                                'limit',            $mainframe->getCfg('list_limit'), 'int' );
 164      $limitstart         = $mainframe->getUserStateFromRequest( "$option.viewMenu.limitstart",        'limitstart',         0,                'int' );
 165      $search                = $mainframe->getUserStateFromRequest( "$option.search",                    'search',            '',                'string' );
 166      if (strpos($search, '"') !== false) {
 167          $search = str_replace(array('=', '<'), '', $search);
 168      }
 169      $search = JString::strtolower($search);
 170  
 171      $where[] = 'm.published = -2';
 172  
 173      if ($search) {
 174          $where[] = 'LOWER(m.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
 175      }
 176  
 177      $where         = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
 178  
 179      // ensure filter_order has a valid value
 180      if (!in_array($filter_order, array('m.name', 'm.id', 'm.menutype', 'm.type'))) {
 181          $filter_order = 'm.menutype';
 182      }
 183  
 184      if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
 185          $filter_order_Dir = '';
 186      }
 187  
 188      $orderby     = ' ORDER BY '. $filter_order . ' ' . $filter_order_Dir .', m.menutype, m.ordering, m.ordering,  m.name';
 189  
 190      $query = 'SELECT count(*)'
 191      . ' FROM #__menu AS m'
 192      . ' LEFT JOIN #__users AS u ON u.id = m.checked_out'
 193      . $where
 194      ;
 195      $db->setQuery( $query );
 196      $total = $db->loadResult();
 197  
 198      jimport('joomla.html.pagination');
 199      $pageNav = new JPagination( $total, $limitstart, $limit );
 200  
 201      // Query menu items
 202      $query = 'SELECT m.name, m.id, m.menutype, m.type, com.name AS com_name'
 203      . ' FROM #__menu AS m'
 204      . ' LEFT JOIN #__users AS u ON u.id = m.checked_out'
 205      . ' LEFT JOIN #__components AS com ON com.id = m.componentid AND m.type = "components"'
 206      . $where
 207      . $orderby
 208      ;
 209      $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 210      $menus = $db->loadObjectList();
 211  
 212      // table ordering
 213      $lists['order_Dir']    = $filter_order_Dir;
 214      $lists['order']        = $filter_order;
 215  
 216      // search filter
 217      $lists['search']= $search;
 218  
 219      HTML_trash::showListMenu( $option, $menus, $pageNav, $lists );
 220  }
 221  
 222  
 223  /**
 224  * Compiles a list of the items you have selected to permanently delte
 225  */
 226  function viewdeleteTrash( $cid, $mid, $option )
 227  {
 228      global $mainframe;
 229  
 230      $db =& JFactory::getDBO();
 231      $return = JRequest::getCmd( 'return', 'viewContent', 'post' );
 232  
 233      JArrayHelper::toInteger($cid, array(0));
 234      JArrayHelper::toInteger($mid, array(0));
 235  
 236      // seperate contentids
 237      $cids = implode( ',', $cid );
 238      $mids = implode( ',', $mid );
 239  
 240      if ( $cids ) {
 241          // Articles query
 242          $query =     'SELECT a.title AS name'
 243          . ' FROM #__content AS a'
 244          . ' WHERE ( a.id IN ( '.$cids.' ) )'
 245          . ' ORDER BY a.title'
 246          ;
 247          $db->setQuery( $query );
 248          $items = $db->loadObjectList();
 249          $id = $cid;
 250          $type = "content";
 251      } else if ( $mids ) {
 252          // Articles query
 253          $query =     'SELECT a.name'
 254          . ' FROM #__menu AS a'
 255          . ' WHERE ( a.id IN ( '.$mids.' ) )'
 256          . ' ORDER BY a.name'
 257          ;
 258          $db->setQuery( $query );
 259          $items = $db->loadObjectList();
 260          $id = $mid;
 261          $type = "menu";
 262      }
 263  
 264      HTML_trash::showDelete( $option, $id, $items, $type, $return );
 265  }
 266  
 267  
 268  /**
 269  * Permanently deletes the selected list of trash items
 270  */
 271  function deleteTrash( $cid, $option )
 272  {
 273      global $mainframe;
 274  
 275      // Check for request forgeries
 276      JRequest::checkToken() or jexit( 'Invalid Token' );
 277  
 278      $db        =& JFactory::getDBO();
 279      $return    = JRequest::getCmd( 'return', 'viewContent', 'post' );
 280      $type    = JRequest::getCmd( 'type', '', 'post' );
 281  
 282      $total = count( $cid );
 283  
 284      if ( $type == 'content' )
 285      {
 286          $obj =& JTable::getInstance('content');
 287  
 288          require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php');
 289          $fp = new TableFrontPage( $db );
 290          foreach ( $cid as $id ) {
 291              $id = intval( $id );
 292              $obj->delete( $id );
 293              $fp->delete( $id );
 294          }
 295      } else if ( $type == "menu" ) {
 296          $obj =& JTable::getInstance('menu');
 297          foreach ( $cid as $id ) {
 298              $id = intval( $id );
 299              $obj->delete( $id );
 300          }
 301      }
 302  
 303      $msg = JText::sprintf( 'Item(s) successfully Deleted', $total );
 304      $mainframe->redirect( 'index.php?option='.$option.'&task='.$return, $msg );
 305  }
 306  
 307  
 308  /**
 309  * Compiles a list of the items you have selected to permanently delte
 310  */
 311  function viewrestoreTrash( $cid, $mid, $option ) {
 312      global $mainframe;
 313  
 314      $db        =& JFactory::getDBO();
 315      $return = JRequest::getCmd( 'return', 'viewContent', 'post' );
 316  
 317      JArrayHelper::toInteger($cid, array(0));
 318      JArrayHelper::toInteger($mid, array(0));
 319  
 320      // seperate contentids
 321      $cids = implode( ',', $cid );
 322      $mids = implode( ',', $mid );
 323  
 324      if ( $cids ) {
 325          // Articles query
 326          $query = 'SELECT a.title AS name'
 327          . ' FROM #__content AS a'
 328          . ' WHERE ( a.id IN ( '.$cids.' ) )'
 329          . ' ORDER BY a.title'
 330          ;
 331          $db->setQuery( $query );
 332          $items = $db->loadObjectList();
 333          $id = $cid;
 334          $type = "content";
 335      } else if ( $mids ) {
 336          // Articles query
 337          $query = 'SELECT a.name'
 338          . ' FROM #__menu AS a'
 339          . ' WHERE ( a.id IN ( '.$mids.' ) )'
 340          . ' ORDER BY a.name'
 341          ;
 342          $db->setQuery( $query );
 343          $items = $db->loadObjectList();
 344          $id = $mid;
 345          $type = "menu";
 346      }
 347  
 348      HTML_trash::showRestore( $option, $id, $items, $type, $return );
 349  }
 350  
 351  
 352  /**
 353  * Restores items selected to normal - restores to an unpublished state
 354  */
 355  function restoreTrash( $cid, $option )
 356  {
 357      global $mainframe;
 358  
 359      // Check for request forgeries
 360      JRequest::checkToken() or jexit( 'Invalid Token' );
 361  
 362      $db        = & JFactory::getDBO();
 363      $type    = JRequest::getCmd( 'type', '', 'post' );
 364  
 365      $total = count( $cid );
 366  
 367      // restores to an unpublished state
 368      $state         = 0;
 369      $ordering     = 9999;
 370  
 371      if ( $type == 'content' ) {
 372          $return = 'viewContent';
 373  
 374          //seperate contentids
 375          JArrayHelper::toInteger($cid, array(0));
 376          $cids = implode( ',', $cid );
 377  
 378          // query to restore article
 379          $query = 'UPDATE #__content'
 380          . ' SET state = '.(int) $state.', ordering = '.(int) $ordering
 381          . ' WHERE id IN ( '.$cids.' )'
 382          ;
 383          $db->setQuery( $query );
 384          if ( !$db->query() ) {
 385              JError::raiseError(500, $db->getErrorMsg() );
 386          }
 387      } else if ( $type == 'menu' ) {
 388          $return = 'viewMenu';
 389  
 390          jimport('joomla.application.component.model');
 391          JModel::addIncludePath(JPATH_BASE.DS.'components'.DS.'com_menus'.DS.'models');
 392          $model =& JModel::getInstance('List', 'MenusModel');
 393          $total = $model->fromTrash($cid);
 394  
 395          if (!$total) {
 396              JError::raiseError(500, $db->getErrorMsg() );
 397          }
 398      }
 399  
 400      $msg = JText::sprintf( 'Item(s) successfully Restored', $total );
 401      $mainframe->redirect( 'index.php?option='.$option.'&task='.$return, $msg );
 402  }
 403  
 404  function ReadMenuXML( $type, $component=-1 )
 405  {
 406      // xml file for module
 407      $xmlfile = JPATH_ADMINISTRATOR .'/components/com_menus/'. $type .'/'. $type .'.xml';
 408  
 409      $data = JApplicationHelper::parseXMLInstallFile($xmlfile);
 410  
 411      if ( $data['type'] == 'component' || $data['type'] == 'menu' )
 412      {
 413          if ( ( $component <> -1 ) && ( $data['name'] == 'Component') ) {
 414              $data['name'] .= ' - '. $component;
 415          }
 416  
 417          $row[0]    = $data['name'];
 418      }
 419  
 420      return $row;
 421  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1