[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/administrator/components/com_newsfeeds/ -> admin.newsfeeds.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: admin.newsfeeds.php 19343 2010-11-03 18:12:02Z ian $
   4  * @package        Joomla
   5  * @subpackage    Newsfeeds
   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_newsfeeds', 'manage' )) {
  23      $mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
  24  }
  25  
  26  // Set the table directory
  27  JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_newsfeeds'.DS.'tables');
  28  
  29  require_once( JApplicationHelper::getPath( 'admin_html' ) );
  30  
  31  $task     = JRequest::getCmd('task');
  32  
  33  switch ($task) {
  34  
  35      case 'add' :
  36          editNewsFeed(false);
  37          break;
  38      case 'edit':
  39          editNewsFeed(true);
  40          break;
  41  
  42      case 'save':
  43      case 'apply':
  44          saveNewsFeed( );
  45          break;
  46  
  47      case 'publish':
  48          publishNewsFeeds( );
  49          break;
  50  
  51      case 'unpublish':
  52          unPublishNewsFeeds( );
  53          break;
  54  
  55      case 'remove':
  56          removeNewsFeeds( );
  57          break;
  58  
  59      case 'cancel':
  60          cancelNewsFeed( );
  61          break;
  62  
  63      case 'orderup':
  64          moveUpNewsFeed( );
  65          break;
  66  
  67      case 'orderdown':
  68          moveDownNewsFeed( );
  69          break;
  70  
  71      case 'saveorder':
  72          saveOrder( );
  73          break;
  74  
  75      default:
  76          showNewsFeeds( );
  77          break;
  78  }
  79  
  80  /**
  81  * List the records
  82  */
  83  function showNewsFeeds(  )
  84  {
  85      global $mainframe, $option;
  86  
  87      $db                    =& JFactory::getDBO();
  88  
  89      $filter_order        = $mainframe->getUserStateFromRequest( "$option.filter_order",        'filter_order',        'a.ordering',    '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      $filter_catid        = $mainframe->getUserStateFromRequest( "$option.filter_catid",        'filter_catid',        0,                'int' );
  93      $search                = $mainframe->getUserStateFromRequest( "$option.search",            'search',            '',                'string' );
  94      if (strpos($search, '"') !== false) {
  95          $search = str_replace(array('=', '<'), '', $search);
  96      }
  97      $search = JString::strtolower($search);
  98  
  99      $limit        = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
 100      $limitstart    = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
 101  
 102      $where = array();
 103      if ( $filter_catid ) {
 104          $where[] = 'a.catid = '.(int) $filter_catid;
 105      }
 106      if ($search) {
 107          $where[] = 'LOWER(a.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
 108      }
 109      if ( $filter_state ) {
 110          if ( $filter_state == 'P' ) {
 111              $where[] = 'a.published = 1';
 112          } else if ($filter_state == 'U' ) {
 113              $where[] = 'a.published = 0';
 114          }
 115      }
 116  
 117      // sanitize $filter_order
 118      if (!in_array($filter_order, array('a.name', 'a.published', 'a.ordering', 'catname', 'a.numarticles', 'a.cache_time', 'a.id'))) {
 119          $filter_order = 'a.ordering';
 120      }
 121  
 122      if (!in_array(strtoupper($filter_order_Dir), array('ASC', 'DESC'))) {
 123          $filter_order_Dir = '';
 124      }
 125  
 126      $where         = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
 127      if ($filter_order == 'a.ordering'){
 128          $orderby     = ' ORDER BY catname, a.ordering';
 129      } else {
 130          $orderby     = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', catname, a.ordering';
 131      }
 132  
 133      // get the total number of records
 134      $query = 'SELECT COUNT(*) '
 135      . ' FROM #__newsfeeds AS a'
 136      . $where
 137      ;
 138      $db->setQuery( $query );
 139      $total = $db->loadResult();
 140  
 141      jimport('joomla.html.pagination');
 142      $pageNav = new JPagination( $total, $limitstart, $limit );
 143  
 144      // get the subset (based on limits) of required records
 145      $query = 'SELECT a.*, c.title AS catname, u.name AS editor'
 146      . ' FROM #__newsfeeds AS a'
 147      . ' LEFT JOIN #__categories AS c ON c.id = a.catid'
 148      . ' LEFT JOIN #__users AS u ON u.id = a.checked_out'
 149      . $where
 150      . $orderby
 151      ;
 152      $db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
 153  
 154      $rows = $db->loadObjectList();
 155      if ($db->getErrorNum()) {
 156          echo $db->stderr();
 157          return false;
 158      }
 159  
 160      // build list of categories
 161      $javascript = 'onchange="document.adminForm.submit();"';
 162      $lists['catid'] = JHTML::_('list.category',  'filter_catid', 'com_newsfeeds', $filter_catid, $javascript );
 163  
 164      // state filter
 165      $lists['state']    = JHTML::_('grid.state',  $filter_state );
 166  
 167      // table ordering
 168      $lists['order_Dir']    = $filter_order_Dir;
 169      $lists['order']        = $filter_order;
 170  
 171      // search filter
 172      $lists['search']= $search;
 173  
 174      HTML_newsfeeds::showNewsFeeds( $rows, $lists, $pageNav, $option );
 175  }
 176  
 177  /**
 178  * Creates a new or edits and existing user record
 179  */
 180  function editNewsFeed($edit)
 181  {
 182      $db         =& JFactory::getDBO();
 183      $user         =& JFactory::getUser();
 184  
 185      $catid         = JRequest::getVar( 'catid', 0, '', 'int' );
 186      $cid         = JRequest::getVar( 'cid', array(0), '', 'array' );
 187      $option     = JRequest::getCmd( 'option' );
 188      JArrayHelper::toInteger($cid, array(0));
 189  
 190      $row =& JTable::getInstance( 'newsfeed', 'Table' );
 191      // load the row from the db table
 192      if($edit)
 193      $row->load( $cid[0] );
 194  
 195      if ($edit) {
 196          // do stuff for existing records
 197          $row->checkout( $user->get('id') );
 198      } else {
 199          // do stuff for new records
 200          $row->ordering         = 0;
 201          $row->numarticles     = 5;
 202          $row->cache_time     = 3600;
 203          $row->published     = 1;
 204      }
 205  
 206      // build the html select list for ordering
 207      $query = 'SELECT a.ordering AS value, a.name AS text'
 208      . ' FROM #__newsfeeds AS a'
 209      . ' ORDER BY a.ordering'
 210      ;
 211  
 212      if($edit)
 213          $lists['ordering']             = JHTML::_('list.specificordering',  $row, $cid[0], $query );
 214      else
 215          $lists['ordering']             = JHTML::_('list.specificordering',  $row, '', $query );
 216  
 217      // build list of categories
 218      $lists['category']             = JHTML::_('list.category',  'catid', $option, intval( $row->catid ) );
 219      // build the html select list
 220      $lists['published']         = JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $row->published );
 221          $rtl[] = JHTML::_('select.option',  '0', JText::_( 'Site Language Direction' ) );
 222             $rtl[] = JHTML::_('select.option',  '1', JText::_( 'Left to Right Direction' ) );
 223            $rtl[] = JHTML::_('select.option',  '2', JText::_( 'Right to Left Direction' ) );
 224          $lists['rtl'] = JHTML::_('select.genericlist',   $rtl, 'rtl', 'class="inputbox"', 'value', 'text', intval( $row->rtl ) );
 225      HTML_newsfeeds::editNewsFeed( $row, $lists, $option );
 226  }
 227  
 228  /**
 229  * Saves the record from an edit form submit
 230  */
 231  function saveNewsFeed(  )
 232  {
 233      global $mainframe;
 234  
 235      // Check for request forgeries
 236      JRequest::checkToken() or jexit( 'Invalid Token' );
 237  
 238      $db         =& JFactory::getDBO();
 239      $task         = JRequest::getVar( 'task');
 240  
 241      $row         =& JTable::getInstance( 'newsfeed', 'Table' );
 242      if (!$row->bind(JRequest::get('post'))) {
 243          JError::raiseError(500, $row->getError() );
 244      }
 245  
 246      // Sets rtl value when rtl checkbox ticked
 247      $isRtl = JRequest::getInt('rtl');
 248  
 249  
 250      // pre-save checks
 251      if (!$row->check()) {
 252          JError::raiseError(500, $row->getError() );
 253      }
 254  
 255      // if new item, order last in appropriate group
 256      if (!$row->id) {
 257          $where = "catid = " . (int) $row->catid;
 258          $row->ordering = $row->getNextOrder( $where );
 259      }
 260  
 261      // save the changes
 262      if (!$row->store()) {
 263          JError::raiseError(500, $row->getError() );
 264      }
 265      $row->checkin();
 266  
 267      switch ($task)
 268      {
 269          case 'apply':
 270              $msg = JText::_( 'Changes to Newsfeed saved' );
 271              $link = 'index.php?option=com_newsfeeds&task=edit&cid[]='. $row->id ;
 272              break;
 273  
 274          case 'save':
 275          default:
 276              $msg = JText::_( 'Newsfeed saved' );
 277              $link = 'index.php?option=com_newsfeeds';
 278              break;
 279      }
 280  
 281      $mainframe->redirect( $link, $msg );
 282  }
 283  
 284  /**
 285  * Publishes one or more modules
 286  */
 287  function publishNewsFeeds(  ) {
 288      changePublishNewsFeeds( 1 );
 289  }
 290  
 291  /**
 292  * Unpublishes one or more modules
 293  */
 294  function unPublishNewsFeeds(  ) {
 295      changePublishNewsFeeds( 0 );
 296  }
 297  
 298  /**
 299  * Publishes or Unpublishes one or more modules
 300  * @param integer 0 if unpublishing, 1 if publishing
 301  */
 302  function changePublishNewsFeeds( $publish )
 303  {
 304      global $mainframe;
 305  
 306      // Check for request forgeries
 307      JRequest::checkToken() or jexit( 'Invalid Token' );
 308  
 309      $db         =& JFactory::getDBO();
 310      $user         =& JFactory::getUser();
 311  
 312      $cid        = JRequest::getVar('cid', array(), '', 'array');
 313      $option        = JRequest::getCmd('option');
 314      JArrayHelper::toInteger($cid);
 315  
 316      if (empty( $cid )) {
 317          JError::raiseWarning( 500, 'No items selected' );
 318          $mainframe->redirect( 'index.php?option='. $option );
 319      }
 320  
 321      $cids = implode( ',', $cid );
 322  
 323      $query = 'UPDATE #__newsfeeds'
 324      . ' SET published = '.(int) $publish
 325      . ' WHERE id IN ( '. $cids .' )'
 326      . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id') .' ) )'
 327      ;
 328      $db->setQuery( $query );
 329      if (!$db->query()) {
 330          JError::raiseError(500, $db->getErrorMsg() );
 331      }
 332  
 333      if (count( $cid ) == 1) {
 334          $row =& JTable::getInstance( 'newsfeed', 'Table' );
 335          $row->checkin( $cid[0] );
 336      }
 337  
 338      $mainframe->redirect( 'index.php?option='. $option );
 339  }
 340  
 341  /**
 342  * Removes records
 343  */
 344  function removeNewsFeeds( )
 345  {
 346      global $mainframe;
 347  
 348      // Check for request forgeries
 349      JRequest::checkToken() or jexit( 'Invalid Token' );
 350  
 351      $db         =& JFactory::getDBO();
 352      $cid         = JRequest::getVar('cid', array(), '', 'array');
 353      $option     = JRequest::getCmd('option');
 354      JArrayHelper::toInteger($cid);
 355  
 356      if (count($cid) < 1) {
 357          JError::raiseWarning(500, JText::_( 'Select an item to delete', true ) );
 358          $mainframe->redirect( 'index.php?option='. $option );
 359      }
 360  
 361      $cids = implode( ',', $cid );
 362      $query = 'DELETE FROM #__newsfeeds'
 363      . ' WHERE id IN ( '. $cids .' )'
 364      ;
 365      $db->setQuery( $query );
 366      if (!$db->query()) {
 367          echo "<script> alert('".$db->getErrorMsg(true)."'); window.history.go(-1); </script>\n";
 368      }
 369  
 370      $mainframe->redirect( 'index.php?option='. $option );
 371  }
 372  
 373  /**
 374  * Cancels an edit operation
 375  */
 376  function cancelNewsFeed(  )
 377  {
 378      global $mainframe;
 379  
 380      // Check for request forgeries
 381      JRequest::checkToken() or jexit( 'Invalid Token' );
 382  
 383      $db     =& JFactory::getDBO();
 384      $option = JRequest::getCmd('option');
 385  
 386      $row =& JTable::getInstance( 'newsfeed', 'Table' );
 387      $row->bind(JRequest::get('post'));
 388      $row->checkin();
 389      $mainframe->redirect( 'index.php?option='. $option );
 390  }
 391  
 392  /**
 393  * Moves the record up one position
 394  */
 395  function moveUpNewsFeed(  ) {
 396      orderNewsFeed( -1 );
 397  }
 398  
 399  /**
 400  * Moves the record down one position
 401  */
 402  function moveDownNewsFeed(  ) {
 403      orderNewsFeed( 1 );
 404  }
 405  
 406  /**
 407  * Moves the order of a record
 408  * @param integer The direction to reorder, +1 down, -1 up
 409  */
 410  function orderNewsFeed( $inc )
 411  {
 412      global $mainframe;
 413  
 414      // Check for request forgeries
 415      JRequest::checkToken() or jexit( 'Invalid Token' );
 416  
 417      $db        =& JFactory::getDBO();
 418      $cid    = JRequest::getVar('cid', array(0), '', 'array');
 419      $option = JRequest::getCmd('option');
 420      JArrayHelper::toInteger($cid, array(0));
 421  
 422      $limit         = JRequest::getVar( 'limit', 0, '', 'int' );
 423      $limitstart = JRequest::getVar( 'limitstart', 0, '', 'int' );
 424      $catid         = JRequest::getVar( 'catid', 0, '', 'int' );
 425  
 426      $row =& JTable::getInstance( 'newsfeed', 'Table' );
 427      $row->load( $cid[0] );
 428      $row->move( $inc, 'catid = '.(int) $row->catid.' AND published != 0' );
 429  
 430      $mainframe->redirect( 'index.php?option='. $option );
 431  }
 432  
 433  /**
 434  * Saves user reordering entry
 435  */
 436  function saveOrder(  )
 437  {
 438      global $mainframe;
 439  
 440      // Check for request forgeries
 441      JRequest::checkToken() or jexit( 'Invalid Token' );
 442  
 443      $db            =& JFactory::getDBO();
 444      $cid        = JRequest::getVar( 'cid', array(), 'post', 'array' );
 445      JArrayHelper::toInteger($cid);
 446  
 447      $total        = count( $cid );
 448      $order        = JRequest::getVar( 'order', array(0), 'post', 'array' );
 449      JArrayHelper::toInteger($order, array(0));
 450  
 451      $row =& JTable::getInstance( 'newsfeed', 'Table' );
 452      $groupings = array();
 453  
 454      // update ordering values
 455      for( $i=0; $i < $total; $i++ ) {
 456          $row->load( (int) $cid[$i] );
 457          // track categories
 458          $groupings[] = $row->catid;
 459  
 460          if ($row->ordering != $order[$i]) {
 461              $row->ordering = $order[$i];
 462              if (!$row->store()) {
 463                  JError::raiseError(500, $db->getErrorMsg() );
 464              }
 465          }
 466      }
 467  
 468      // execute updateOrder for each parent group
 469      $groupings = array_unique( $groupings );
 470      foreach ($groupings as $group){
 471          $row->reorder('catid = '.(int) $group);
 472      }
 473  
 474      $msg     = JText::_( 'New ordering saved' );
 475      $mainframe->redirect( 'index.php?option=com_newsfeeds', $msg );
 476  }


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