Source for file view.html.php

Documentation is available at view.html.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_content
  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.  * HTML View class for the Content component
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_content
  17.  * @since       1.5
  18.  */
  19. {
  20.     /**
  21.      * @var    array  Array of leading items for blog display
  22.      * @since  3.2
  23.      */
  24.     protected $lead_items = array();
  25.  
  26.     /**
  27.      * @var    array  Array of intro (multicolumn display) items for blog display
  28.      * @since  3.2
  29.      */
  30.     protected $intro_items = array();
  31.  
  32.     /**
  33.      * @var    array  Array of links in blog display
  34.      * @since  3.2
  35.      */
  36.     protected $link_items = array();
  37.  
  38.     /**
  39.      * @var    integer  Number of columns in a multi column display
  40.      * @since  3.2
  41.      */
  42.     protected $columns = 1;
  43.  
  44.     /**
  45.      * @var    string  The name of the extension for the category
  46.      * @since  3.2
  47.      */
  48.     protected $extension = 'com_content';
  49.  
  50.     /**
  51.      * @var    string  Default title to use for page title
  52.      * @since  3.2
  53.      */
  54.     protected $defaultPageTitle = 'JGLOBAL_ARTICLES';
  55.  
  56.     /**
  57.      * @var    string  The name of the view to link individual items to
  58.      * @since  3.2
  59.      */
  60.     protected $viewName = 'article';
  61.  
  62.     /**
  63.      * Execute and display a template script.
  64.      *
  65.      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  66.      *
  67.      * @return  mixed  A string if successful, otherwise a Error object.
  68.      */
  69.     public function display($tpl = null)
  70.     {
  71.         parent::commonCategoryDisplay();
  72.  
  73.         // Prepare the data
  74.         // Get the metrics for the structural page layout.
  75.         $params        = $this->params;
  76.         $numLeading    = $params->def('num_leading_articles', 1);
  77.         $numIntro    = $params->def('num_intro_articles', 4);
  78.         $numLinks    = $params->def('num_links', 4);
  79.  
  80.         // Compute the article slugs and prepare introtext (runs content plugins).
  81.         foreach ($this->items as $item)
  82.         {
  83.             $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
  84.  
  85.             $item->parent_slug = ($item->parent_alias) ? ($item->parent_id . ':' . $item->parent_alias) : $item->parent_id;
  86.  
  87.             // No link for ROOT category
  88.             if ($item->parent_alias == 'root')
  89.             {
  90.                 $item->parent_slug = null;
  91.             }
  92.  
  93.             $item->catslug = $item->category_alias ? ($item->catid.':'.$item->category_alias) : $item->catid;
  94.             $item->event   = new stdClass;
  95.  
  96.             $dispatcher = JEventDispatcher::getInstance();
  97.  
  98.             // Old plugins: Ensure that text property is available
  99.             if (!isset($item->text))
  100.             {
  101.                 $item->text = $item->introtext;
  102.             }
  103.  
  104.             JPluginHelper::importPlugin('content');
  105.             $dispatcher->trigger('onContentPrepare', array ('com_content.category', &$item, &$this->params, 0));
  106.  
  107.             // Old plugins: Use processed text as introtext
  108.             $item->introtext = $item->text;
  109.  
  110.             $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.category', &$item, &$item->params, 0));
  111.             $item->event->afterDisplayTitle = trim(implode("\n", $results));
  112.  
  113.             $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.category', &$item, &$item->params, 0));
  114.             $item->event->beforeDisplayContent = trim(implode("\n", $results));
  115.  
  116.             $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.category', &$item, &$item->params, 0));
  117.             $item->event->afterDisplayContent = trim(implode("\n", $results));
  118.         }
  119.  
  120.         // Check for layout override only if this is not the active menu item
  121.         // If it is the active menu item, then the view and category id will match
  122.         $app = JFactory::getApplication();
  123.         $active    = $app->getMenu()->getActive();
  124.  
  125.         if ((!$active) || ((strpos($active->link, 'view=category') === false) || (strpos($active->link, '&id=' . (string) $this->category->id) === false)))
  126.         {
  127.             // Get the layout from the merged category params
  128.             if ($layout = $this->category->params->get('category_layout'))
  129.             {
  130.                 $this->setLayout($layout);
  131.             }
  132.         }
  133.         // At this point, we are in a menu item, so we don't override the layout
  134.         elseif (isset($active->query['layout']))
  135.         {
  136.             // We need to set the layout from the query in case this is an alternative menu item (with an alternative layout)
  137.             $this->setLayout($active->query['layout']);
  138.         }
  139.  
  140.         // For blog layouts, preprocess the breakdown of leading, intro and linked articles.
  141.         // This makes it much easier for the designer to just interrogate the arrays.
  142.         if (($params->get('layout_type') == 'blog') || ($this->getLayout() == 'blog'))
  143.         {
  144.             //$max = count($this->items);
  145.  
  146.             foreach ($this->items as $i => $item)
  147.             {
  148.                 if ($i < $numLeading)
  149.                 {
  150.                     $this->lead_items[] = $item;
  151.                 }
  152.  
  153.                 elseif ($i >= $numLeading && $i < $numLeading + $numIntro)
  154.                 {
  155.                     $this->intro_items[] = $item;
  156.                 }
  157.  
  158.                 elseif ($i < $numLeading + $numIntro + $numLinks)
  159.                 {
  160.                     $this->link_items[] = $item;
  161.                 }
  162.                 else
  163.                 {
  164.                     continue;
  165.                 }
  166.             }
  167.  
  168.             $this->columns = max(1, $params->def('num_columns', 1));
  169.  
  170.             $params->def('multi_column_order', 1);
  171.         }
  172.  
  173.         return parent::display($tpl);
  174.     }
  175.  
  176.     /**
  177.      * Prepares the document
  178.      *
  179.      * @return  void 
  180.      */
  181.     protected function prepareDocument()
  182.     {
  183.         parent::prepareDocument();
  184.         $menu = $this->menu;
  185.         $id = (int) @$menu->query['id'];
  186.  
  187.         if ($menu && ($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $this->category->id))
  188.         {
  189.             $path = array(array('title' => $this->category->title, 'link' => ''));
  190.             $category = $this->category->getParent();
  191.  
  192.             while (($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $category->id) && $category->id > 1)
  193.             {
  194.                 $path[] = array('title' => $category->title, 'link' => ContentHelperRoute::getCategoryRoute($category->id));
  195.                 $category = $category->getParent();
  196.             }
  197.  
  198.             $path = array_reverse($path);
  199.  
  200.             foreach ($path as $item)
  201.             {
  202.                 $this->pathway->addItem($item['title'], $item['link']);
  203.             }
  204.         }
  205.  
  206.         parent::addFeed();
  207.     }
  208. }

Documentation generated on Tue, 19 Nov 2013 15:17:04 +0100 by phpDocumentor 1.4.3