Source for file pagenavigation.php

Documentation is available at pagenavigation.php

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

Documentation generated on Tue, 19 Nov 2013 15:10:06 +0100 by phpDocumentor 1.4.3