[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/content/ -> pagenavigation.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: pagenavigation.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   6  * @license        GNU/GPL, see LICENSE.php
   7  * Joomla! is free software. This version may have been modified pursuant
   8  * to the GNU General Public License, and as distributed it includes or
   9  * is derivative of works licensed under the GNU General Public License or
  10  * other free or open source software licenses.
  11  * See COPYRIGHT.php for copyright notices and details.
  12  */
  13  
  14  // no direct access
  15  defined( '_JEXEC' ) or die( 'Restricted access' );
  16  
  17  $mainframe->registerEvent( 'onBeforeDisplayContent', 'plgContentNavigation' );
  18  
  19  function plgContentNavigation( &$row, &$params, $page=0 )
  20  {
  21      $view        = JRequest::getCmd('view');
  22  
  23      // Get Plugin info
  24      $plugin =& JPluginHelper::getPlugin('content', 'pagenavigation');
  25  
  26      if ($params->get('show_item_navigation') && ($view == 'article'))
  27      {
  28  
  29          $html         = '';
  30          $db         = & JFactory::getDBO();
  31          $user        = & JFactory::getUser();
  32          $nullDate    = $db->getNullDate();
  33  
  34          $date        =& JFactory::getDate();
  35          $config     = & JFactory::getConfig();
  36          $now         = $date->toMySQL();
  37  
  38          $uid         = $row->id;
  39          $option     = 'com_content';
  40          $canPublish = $user->authorize('com_content', 'publish', 'content', 'all');
  41  
  42          // the following is needed as different menu items types utilise a different param to control ordering
  43          // for Blogs the `orderby_sec` param is the order controlling param
  44          // for Table and List views it is the `orderby` param
  45          $params_list = $params->toArray();
  46          if (array_key_exists('orderby_sec', $params_list)) {
  47              $order_method = $params->get('orderby_sec', '');
  48          } else {
  49              $order_method = $params->get('orderby', '');
  50          }
  51          // additional check for invalid sort ordering
  52          if ( $order_method == 'front' ) {
  53              $order_method = '';
  54          }
  55  
  56          // Determine sort order
  57          switch ($order_method)
  58          {
  59              case 'date' :
  60                  $orderby = 'a.created';
  61                  break;
  62  
  63              case 'rdate' :
  64                  $orderby = 'a.created DESC';
  65                  break;
  66  
  67              case 'alpha' :
  68                  $orderby = 'a.title';
  69                  break;
  70  
  71              case 'ralpha' :
  72                  $orderby = 'a.title DESC';
  73                  break;
  74  
  75              case 'hits' :
  76                  $orderby = 'a.hits';
  77                  break;
  78  
  79              case 'rhits' :
  80                  $orderby = 'a.hits DESC';
  81                  break;
  82  
  83              case 'order' :
  84                  $orderby = 'a.ordering';
  85                  break;
  86  
  87              case 'author' :
  88                  $orderby = 'a.created_by_alias, u.name';
  89                  break;
  90  
  91              case 'rauthor' :
  92                  $orderby = 'a.created_by_alias DESC, u.name DESC';
  93                  break;
  94  
  95              case 'front' :
  96                  $orderby = 'f.ordering';
  97                  break;
  98  
  99              default :
 100                  $orderby = 'a.ordering';
 101                  break;
 102          }
 103  
 104          $xwhere = ' AND ( a.state = 1 OR a.state = -1 )' .
 105          ' AND ( publish_up = '.$db->Quote($nullDate).' OR publish_up <= '.$db->Quote($now).' )' .
 106          ' AND ( publish_down = '.$db->Quote($nullDate).' OR publish_down >= '.$db->Quote($now).' )';
 107  
 108          // array of articles in same category correctly ordered
 109          $query = 'SELECT a.id,'
 110          . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'
 111          . ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'
 112          . ' FROM #__content AS a'
 113          . ' LEFT JOIN #__categories AS cc ON cc.id = a.catid'
 114          . ' WHERE a.catid = ' . (int) $row->catid
 115          . ' AND a.state = '. (int) $row->state
 116          . ($canPublish ? '' : ' AND a.access <= ' .(int) $user->get('aid', 0))
 117          . $xwhere
 118          . ' ORDER BY '. $orderby;
 119          $db->setQuery($query);
 120          $list = $db->loadObjectList('id');
 121  
 122          // this check needed if incorrect Itemid is given resulting in an incorrect result
 123          if ( !is_array($list) ) {
 124              $list = array();
 125          }
 126  
 127          reset($list);
 128  
 129          // location of current content item in array list
 130          $location = array_search($uid, array_keys($list));
 131  
 132          $rows = array_values($list);
 133  
 134          $row->prev = null;
 135          $row->next = null;
 136  
 137          if ($location -1 >= 0)     {
 138              // the previous content item cannot be in the array position -1
 139              $row->prev = $rows[$location -1];
 140          }
 141  
 142          if (($location +1) < count($rows)) {
 143              // the next content item cannot be in an array position greater than the number of array postions
 144              $row->next = $rows[$location +1];
 145          }
 146  
 147          $pnSpace = "";
 148          if (JText::_('&lt') || JText::_('&gt')) {
 149              $pnSpace = " ";
 150          }
 151  
 152          if ($row->prev) {
 153              $row->prev = JRoute::_(ContentHelperRoute::getArticleRoute($row->prev->slug, $row->prev->catslug));
 154          } else {
 155              $row->prev = '';
 156          }
 157  
 158          if ($row->next) {
 159              $row->next = JRoute::_(ContentHelperRoute::getArticleRoute($row->next->slug, $row->next->catslug));
 160          } else {
 161              $row->next = '';
 162          }
 163  
 164  
 165          // output
 166          if ($row->prev || $row->next)
 167          {
 168              $html = '
 169              <table align="center" class="pagenav">
 170              <tr>'
 171              ;
 172              if ($row->prev)
 173              {
 174                  $html .= '
 175                  <th class="pagenav_prev">
 176                      <a href="'. $row->prev .'">'
 177                          . JText::_( '&lt' ) . $pnSpace . JText::_( 'Prev' ) . '</a>
 178                  </th>'
 179                  ;
 180              }
 181  
 182              if ($row->prev && $row->next)
 183              {
 184                  $html .= '
 185                  <td width="50">
 186                      &nbsp;
 187                  </td>'
 188                  ;
 189              }
 190  
 191              if ($row->next)
 192              {
 193                  $html .= '
 194                  <th class="pagenav_next">
 195                      <a href="'. $row->next .'">'
 196                          . JText::_( 'Next' ) . $pnSpace . JText::_( '&gt' ) .'</a>
 197                  </th>'
 198                  ;
 199              }
 200              $html .= '
 201              </tr>
 202              </table>'
 203              ;
 204  
 205              // Get the plugin parameters
 206              $pluginParams = new JParameter( $plugin->params );
 207              $position      = $pluginParams->get('position', 1);
 208  
 209              if ($position) {
 210              // display after content
 211                  $row->text .= $html;
 212              } else {
 213              // display before content
 214                  $row->text = $html . $row->text;
 215              }
 216          }
 217      }
 218  
 219      return ;
 220  }


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