[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access
   8  defined('_JEXEC') or die;
   9  
  10  /**
  11   * Pagenavigation plugin class.
  12   *
  13   * @package        Joomla.Plugin
  14   * @subpackage    Content.pagenavigation
  15   */
  16  class plgContentPagenavigation extends JPlugin
  17  {
  18      /**
  19       * @since    1.6
  20       */
  21  	public function onContentBeforeDisplay($context, &$row, &$params, $page=0)
  22      {
  23          $view = JRequest::getCmd('view');
  24          $print = JRequest::getBool('print');
  25  
  26          if ($print) {
  27              return false;
  28          }
  29  
  30          if ($params->get('show_item_navigation') && ($context == 'com_content.article') && ($view == 'article')) {
  31              $html = '';
  32              $db        = JFactory::getDbo();
  33              $user    = JFactory::getUser();
  34              $app    = JFactory::getApplication();
  35              $lang    = JFactory::getLanguage();
  36              $nullDate = $db->getNullDate();
  37  
  38              $date    = JFactory::getDate();
  39              $config    = JFactory::getConfig();
  40              $now = $date->toSql();
  41  
  42              $uid    = $row->id;
  43              $option    = 'com_content';
  44              $canPublish = $user->authorise('core.edit.state', $option.'.article.'.$row->id);
  45  
  46              // The following is needed as different menu items types utilise a different param to control ordering.
  47              // For Blogs the `orderby_sec` param is the order controlling param.
  48              // For Table and List views it is the `orderby` param.
  49              $params_list = $params->toArray();
  50              if (array_key_exists('orderby_sec', $params_list)) {
  51                  $order_method = $params->get('orderby_sec', '');
  52              } else {
  53                  $order_method = $params->get('orderby', '');
  54              }
  55              // Additional check for invalid sort ordering.
  56              if ($order_method == 'front') {
  57                  $order_method = '';
  58              }
  59  
  60              // Determine sort order.
  61              switch ($order_method) {
  62                  case 'date' :
  63                      $orderby = 'a.created';
  64                      break;
  65                  case 'rdate' :
  66                      $orderby = 'a.created DESC';
  67                      break;
  68                  case 'alpha' :
  69                      $orderby = 'a.title';
  70                      break;
  71                  case 'ralpha' :
  72                      $orderby = 'a.title DESC';
  73                      break;
  74                  case 'hits' :
  75                      $orderby = 'a.hits';
  76                      break;
  77                  case 'rhits' :
  78                      $orderby = 'a.hits DESC';
  79                      break;
  80                  case 'order' :
  81                      $orderby = 'a.ordering';
  82                      break;
  83                  case 'author' :
  84                      $orderby = 'a.created_by_alias, u.name';
  85                      break;
  86                  case 'rauthor' :
  87                      $orderby = 'a.created_by_alias DESC, u.name DESC';
  88                      break;
  89                  case 'front' :
  90                      $orderby = 'f.ordering';
  91                      break;
  92                  default :
  93                      $orderby = 'a.ordering';
  94                      break;
  95              }
  96  
  97              $xwhere = ' AND (a.state = 1 OR a.state = -1)' .
  98              ' AND (publish_up = '.$db->Quote($nullDate).' OR publish_up <= '.$db->Quote($now).')' .
  99              ' AND (publish_down = '.$db->Quote($nullDate).' OR publish_down >= '.$db->Quote($now).')';
 100  
 101              // Array of articles in same category correctly ordered.
 102              $query    = $db->getQuery(true);
 103             //sqlsrv changes
 104              $case_when = ' CASE WHEN ';
 105              $case_when .= $query->charLength('a.alias');
 106              $case_when .= ' THEN ';
 107              $a_id = $query->castAsChar('a.id');
 108              $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
 109              $case_when .= ' ELSE ';
 110              $case_when .= $a_id.' END as slug';
 111  
 112              $case_when1 = ' CASE WHEN ';
 113              $case_when1 .= $query->charLength('cc.alias');
 114              $case_when1 .= ' THEN ';
 115              $c_id = $query->castAsChar('cc.id');
 116              $case_when1 .= $query->concatenate(array($c_id, 'cc.alias'), ':');
 117              $case_when1 .= ' ELSE ';
 118              $case_when1 .= $c_id.' END as catslug';
 119                $query->select('a.id,'.$case_when.','.$case_when1);
 120              $query->from('#__content AS a');
 121              $query->leftJoin('#__categories AS cc ON cc.id = a.catid');
 122              $query->where('a.catid = '. (int)$row->catid .' AND a.state = '. (int)$row->state
 123                          . ($canPublish ? '' : ' AND a.access = ' .(int)$row->access) . $xwhere);
 124              $query->order($orderby);
 125              if ($app->isSite() && $app->getLanguageFilter()) {
 126                  $query->where('a.language in ('.$db->quote($lang->getTag()).','.$db->quote('*').')');
 127              }
 128  
 129              $db->setQuery($query);
 130              $list = $db->loadObjectList('id');
 131  
 132              // This check needed if incorrect Itemid is given resulting in an incorrect result.
 133              if (!is_array($list)) {
 134                  $list = array();
 135              }
 136  
 137              reset($list);
 138  
 139              // Location of current content item in array list.
 140              $location = array_search($uid, array_keys($list));
 141  
 142              $rows = array_values($list);
 143  
 144              $row->prev = null;
 145              $row->next = null;
 146  
 147              if ($location -1 >= 0)    {
 148                  // The previous content item cannot be in the array position -1.
 149                  $row->prev = $rows[$location -1];
 150              }
 151  
 152              if (($location +1) < count($rows)) {
 153                  // The next content item cannot be in an array position greater than the number of array postions.
 154                  $row->next = $rows[$location +1];
 155              }
 156  
 157              $pnSpace = "";
 158              if (JText::_('JGLOBAL_LT') || JText::_('JGLOBAL_GT')) {
 159                  $pnSpace = " ";
 160              }
 161  
 162              if ($row->prev) {
 163                  $row->prev = JRoute::_(ContentHelperRoute::getArticleRoute($row->prev->slug, $row->prev->catslug));
 164              } else {
 165                  $row->prev = '';
 166              }
 167  
 168              if ($row->next) {
 169                  $row->next = JRoute::_(ContentHelperRoute::getArticleRoute($row->next->slug, $row->next->catslug));
 170              } else {
 171                  $row->next = '';
 172              }
 173  
 174              // Output.
 175              if ($row->prev || $row->next) {
 176                  $html = '
 177                  <ul class="pagenav">'
 178                  ;
 179                  if ($row->prev) {
 180                      $html .= '
 181                      <li class="pagenav-prev">
 182                          <a href="'. $row->prev .'" rel="prev">'
 183                              . JText::_('JGLOBAL_LT') . $pnSpace . JText::_('JPREV') . '</a>
 184                      </li>'
 185                      ;
 186                  }
 187  
 188  
 189  
 190                  if ($row->next) {
 191                      $html .= '
 192                      <li class="pagenav-next">
 193                          <a href="'. $row->next .'" rel="next">'
 194                              . JText::_('JNEXT') . $pnSpace . JText::_('JGLOBAL_GT') .'</a>
 195                      </li>'
 196                      ;
 197                  }
 198                  $html .= '
 199                  </ul>'
 200                  ;
 201  
 202                  $row->pagination = $html;
 203                  $row->paginationposition = $this->params->get('position', 1);
 204                  // This will default to the 1.5 and 1.6-1.7 behavior.
 205                  $row->paginationrelative = $this->params->get('relative',0);
 206              }
 207          }
 208  
 209          return ;
 210      }
 211  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1