[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_frontpage/ -> admin.frontpage.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: admin.frontpage.php 19343 2010-11-03 18:12:02Z ian $
   4  * @package        Joomla
   5  * @subpackage    Content
   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  // Make sure the user is authorized to view this page
  19  $user = & JFactory::getUser();
  20  if (!$user->authorize( 'com_frontpage', 'manage' )) {
  21      $mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
  22  }
  23  
  24  // Set the table directory
  25  JTable::addIncludePath(JPATH_COMPONENT.DS.DS.'tables');
  26  
  27  // Set the helper directory
  28  JHTML::addIncludePath( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_content'.DS.'helper' );
  29  
  30  $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
  31  JArrayHelper::toInteger($cid, array(0));
  32  
  33  switch ( JRequest::getCmd( 'task' ) )
  34  {
  35      case 'publish':
  36          changeFrontPage( $cid, 1, $option );
  37          break;
  38  
  39      case 'unpublish':
  40          changeFrontPage( $cid, 0, $option );
  41          break;
  42  
  43      case 'archive':
  44          changeFrontPage( $cid, -1, $option );
  45          break;
  46  
  47      case 'remove':
  48          removeFrontPage( $cid, $option );
  49          break;
  50  
  51      case 'orderup':
  52          orderFrontPage( $cid[0], -1, $option );
  53          break;
  54  
  55      case 'orderdown':
  56          orderFrontPage( $cid[0], 1, $option );
  57          break;
  58  
  59      case 'saveorder':
  60          saveOrder( $cid );
  61          break;
  62  
  63      case 'accesspublic':
  64          accessMenu( $cid[0], 0 );
  65          break;
  66  
  67      case 'accessregistered':
  68          accessMenu( $cid[0], 1 );
  69          break;
  70  
  71      case 'accessspecial':
  72          accessMenu( $cid[0], 2 );
  73          break;
  74  
  75      default:
  76          viewFrontPage( $option );
  77          break;
  78  }
  79  
  80  
  81  /**
  82  * Compiles a list of frontpage items
  83  */
  84  function viewFrontPage( $option )
  85  {
  86      global $mainframe;
  87  
  88      $db                    =& JFactory::getDBO();
  89      $filter_order        = $mainframe->getUserStateFromRequest( $option.'.filter_order',        'filter_order',        'fpordering',    'cmd' );
  90      $filter_order_Dir    = $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir',    'filter_order_Dir',    '',                'word' );
  91      $filter_state        = $mainframe->getUserStateFromRequest( $option.'.filter_state',        'filter_state',        '',                'word' );
  92      $catid                = $mainframe->getUserStateFromRequest( $option.'.catid',            'catid',            0,                'int' );
  93      $filter_authorid    = $mainframe->getUserStateFromRequest( $option.'.filter_authorid',    'filter_authorid',    0,                'int' );
  94      $filter_sectionid    = $mainframe->getUserStateFromRequest( $option.'.filter_sectionid',    'filter_sectionid',    -1,                'int' );
  95      $search                = $mainframe->getUserStateFromRequest( $option.'.search',            'search',            '',                'string' );
  96      if (strpos($search, '"') !== false) {
  97          $search = str_replace(array('=', '<'), '', $search);
  98      }
  99      $search = JString::strtolower($search);
 100  
 101      $limit        = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
 102      $limitstart    = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
 103  
 104      JToolBarHelper::title( JText::_( 'Frontpage Manager' ), 'frontpage.png' );
 105      JToolBarHelper::archiveList();
 106      JToolBarHelper::publishList();
 107      JToolBarHelper::unpublishList();
 108      JToolBarHelper::custom('remove','delete.png','delete_f2.png','Remove', true);
 109      JToolBarHelper::help( 'screen.frontpage' );
 110  
 111      $where = array(
 112          "c.state >= 0"
 113      );
 114  
 115      // used by filter
 116      if ( $filter_sectionid >= 0 ) {
 117          $where[] = 'c.sectionid = '.(int) $filter_sectionid;
 118      }
 119      if ( $catid > 0 ) {
 120          $where[] = 'c.catid = '.(int) $catid;
 121      }
 122      if ( $filter_authorid > 0 ) {
 123          $where[] = 'c.created_by = '. (int) $filter_authorid;
 124      }
 125      if ( $filter_state ) {
 126          if ( $filter_state == 'P' ) {
 127              $where[] = 'c.state = 1';
 128          } else if ($filter_state == 'U' ) {
 129              $where[] = 'c.state = 0';
 130          }
 131      }
 132  
 133      if ($search) {
 134          $where[] = 'LOWER( c.title ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
 135      }
 136  
 137      $where         = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
 138  
 139      // ensure we have a good vale for $filter_order
 140      if (!in_array($filter_order, array('c.title', 'c.state', 'fpordering', 'groupname', 'c.id', 'sect_name', 'cc.name', 'author', 'cc.title'))) {
 141          $filter_order = 'fpordering';
 142      }
 143  
 144      if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
 145          $filter_order_Dir = '';
 146      }
 147  
 148      $orderby     = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', fpordering';
 149  
 150      // get the total number of records
 151      $query = 'SELECT count(*)'
 152      . ' FROM #__content AS c'
 153      . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
 154      . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"'
 155      . ' INNER JOIN #__content_frontpage AS f ON f.content_id = c.id'
 156      . $where
 157      ;
 158      $db->setQuery( $query );
 159      $total = $db->loadResult();
 160  
 161      jimport('joomla.html.pagination');
 162      $pageNav = new JPagination( $total, $limitstart, $limit );
 163  
 164      $query = 'SELECT c.*, g.name AS groupname, cc.title as name, s.title AS sect_name, u.name AS editor, f.ordering AS fpordering, v.name AS author'
 165      . ' FROM #__content AS c'
 166      . ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
 167      . ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"'
 168      . ' INNER JOIN #__content_frontpage AS f ON f.content_id = c.id'
 169      . ' INNER JOIN #__groups AS g ON g.id = c.access'
 170      . ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
 171      . ' LEFT JOIN #__users AS v ON v.id = c.created_by'
 172      . $where
 173      . $orderby
 174      ;
 175      $db->setQuery( $query, $pageNav->limitstart,$pageNav->limit );
 176      $rows = $db->loadObjectList();
 177      if ($db->getErrorNum()) {
 178          echo $db->stderr();
 179          return false;
 180      }
 181  
 182      // get list of categories for dropdown filter
 183      $query = 'SELECT cc.id AS value, cc.title AS text, section'
 184      . ' FROM #__categories AS cc'
 185      . ' INNER JOIN #__sections AS s ON s.id = cc.section '
 186      . ' ORDER BY s.ordering, cc.ordering'
 187      ;
 188      $db->setQuery( $query );
 189      $categories[]     = JHTML::_('select.option',  '-1', '- '. JText::_( 'Select Category' ) .' -' );
 190      $categories     = array_merge( $categories, $db->loadObjectList() );
 191      $lists['catid'] = JHTML::_('select.genericlist',   $categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $catid );
 192  
 193      // get list of sections for dropdown filter
 194      $javascript            = 'onchange="document.adminForm.submit();"';
 195      $lists['sectionid']    = JHTML::_('list.section',  'filter_sectionid', $filter_sectionid, $javascript );
 196  
 197      // get list of Authors for dropdown filter
 198      $query = 'SELECT c.created_by, u.name'
 199      . ' FROM #__content AS c'
 200      . ' INNER JOIN #__sections AS s ON s.id = c.sectionid'
 201      . ' LEFT JOIN #__users AS u ON u.id = c.created_by'
 202      . ' WHERE c.state <> -1'
 203      . ' AND c.state <> -2'
 204      . ' GROUP BY u.name'
 205      . ' ORDER BY u.name'
 206      ;
 207      $db->setQuery( $query );
 208      $authors[]             = JHTML::_('select.option',  '0', '- '. JText::_( 'Select Author' ) .' -', 'created_by', 'name' );
 209      $authors             = array_merge( $authors, $db->loadObjectList() );
 210      $lists['authorid']    = JHTML::_('select.genericlist',   $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'created_by', 'name', $filter_authorid );
 211  
 212      // state filter
 213      $lists['state']    = JHTML::_('grid.state',  $filter_state );
 214  
 215      // table ordering
 216      $lists['order_Dir']    = $filter_order_Dir;
 217      $lists['order']        = $filter_order;
 218  
 219      // search filter
 220      $lists['search']= $search;
 221  
 222      require_once (JPATH_COMPONENT.DS.'views'.DS.'frontpage.php');
 223      FrontpageView::showList( $rows, $pageNav, $option, $lists );
 224  }
 225  
 226  /**
 227  * Changes the state of one or more content pages
 228  * @param array An array of unique category id numbers
 229  * @param integer 0 if unpublishing, 1 if publishing
 230  */
 231  function changeFrontPage( $cid=null, $state=0, $option )
 232  {
 233      global $mainframe;
 234  
 235      // Check for request forgeries
 236      JRequest::checkToken() or jexit( 'Invalid Token' );
 237  
 238      $db     =& JFactory::getDBO();
 239      $user     =& JFactory::getUser();
 240  
 241      JArrayHelper::toInteger($cid);
 242  
 243      if (count( $cid ) < 1) {
 244          $action = $state == 1 ? 'publish' : ($state == -1 ? 'archive' : 'unpublish');
 245          JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );
 246      }
 247  
 248      $cids = implode( ',', $cid );
 249  
 250      $query = 'UPDATE #__content'
 251      . ' SET state = '.(int) $state
 252      . ' WHERE id IN ( '. $cids .' )'
 253      . ' AND ( checked_out = 0 OR ( checked_out = ' .(int) $user->get('id'). ' ) )'
 254      ;
 255      $db->setQuery( $query );
 256      if (!$db->query()) {
 257          JError::raiseError(500, $db->getErrorMsg() );
 258      }
 259  
 260      if (count( $cid ) == 1) {
 261          $row =& JTable::getInstance('content');
 262          $row->checkin( $cid[0] );
 263      }
 264  
 265      $cache = & JFactory::getCache('com_content');
 266      $cache->clean();
 267  
 268      $mainframe->redirect( 'index.php?option='.$option );
 269  }
 270  
 271  function removeFrontPage( &$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      if (!is_array( $cid ) || count( $cid ) < 1) {
 280          JError::raiseError(500, JText::_( 'Select an item to delete', true ) );
 281      }
 282      $fp =& JTable::getInstance('frontpage', 'Table');
 283      foreach ($cid as $id) {
 284          if (!$fp->delete( $id )) {
 285              JError::raiseError(500, $fp->getError() );
 286          }
 287          $obj =& JTable::getInstance('content');
 288          $obj->load( $id );
 289          $obj->mask = 0;
 290          if (!$obj->store()) {
 291              JError::raiseError(500, $fp->getError() );
 292          }
 293      }
 294      $fp->reorder();
 295  
 296      $cache = & JFactory::getCache('com_content');
 297      $cache->clean();
 298  
 299      $mainframe->redirect( 'index.php?option='.$option );
 300  }
 301  
 302  /**
 303  * Moves the order of a record
 304  * @param integer The increment to reorder by
 305  */
 306  function orderFrontPage( $uid, $inc, $option )
 307  {
 308      global $mainframe;
 309  
 310      // Check for request forgeries
 311      JRequest::checkToken() or jexit( 'Invalid Token' );
 312  
 313      $db =& JFactory::getDBO();
 314  
 315      $fp =& JTable::getInstance('frontpage','Table');
 316      $fp->load( $uid );
 317      $fp->move( $inc );
 318  
 319      $cache = & JFactory::getCache('com_content');
 320      $cache->clean();
 321  
 322      $mainframe->redirect( 'index.php?option='.$option );
 323  }
 324  
 325  /**
 326  * @param integer The id of the article
 327  * @param integer The new access level
 328  * @param string The URL option
 329  */
 330  function accessMenu( $uid, $access )
 331  {
 332      global $mainframe;
 333  
 334      // Check for request forgeries
 335      JRequest::checkToken() or jexit( 'Invalid Token' );
 336  
 337      $db = & JFactory::getDBO();
 338      $row =& JTable::getInstance('content');
 339      $row->load( $uid );
 340      $row->access = $access;
 341  
 342      if ( !$row->check() ) {
 343          return $row->getError();
 344      }
 345      if ( !$row->store() ) {
 346          return $row->getError();
 347      }
 348  
 349      $cache = & JFactory::getCache('com_content');
 350      $cache->clean();
 351  
 352      $mainframe->redirect( 'index.php?option=com_frontpage' );
 353  }
 354  
 355  function saveOrder( &$cid )
 356  {
 357      global $mainframe;
 358  
 359      // Check for request forgeries
 360      JRequest::checkToken() or jexit( 'Invalid Token' );
 361  
 362      $db     =& JFactory::getDBO();
 363      $total    = count( $cid );
 364      $order     = JRequest::getVar( 'order', array(0), 'post', 'array' );
 365  
 366      for( $i=0; $i < $total; $i++ )
 367      {
 368          $query = 'UPDATE #__content_frontpage'
 369          . ' SET ordering = ' . (int) $order[$i]
 370          . ' WHERE content_id = ' . (int) $cid[$i];
 371          $db->setQuery( $query );
 372          if (!$db->query()) {
 373              JError::raiseError(500, $db->getErrorMsg() );
 374          }
 375      }
 376  
 377      $cache = & JFactory::getCache('com_content');
 378      $cache->clean();
 379  
 380      $msg     = JText::_( 'New ordering saved' );
 381      $mainframe->redirect( 'index.php?option=com_frontpage', $msg );
 382  }


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