Source for file category.php

Documentation is available at category.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Legacy
  4.  * @subpackage  View
  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.  * Base HTML View class for the a Category list
  14.  *
  15.  * @package     Joomla.Legacy
  16.  * @subpackage  View
  17.  * @since       3.2
  18.  */
  19. class JViewCategory extends JViewLegacy
  20. {
  21.     /**
  22.      * State data
  23.      *
  24.      * @var    JRegistry 
  25.      * @since  3.2
  26.      */
  27.     protected $state;
  28.  
  29.     /**
  30.      * Category items data
  31.      *
  32.      * @var    array 
  33.      * @since  3.2
  34.      */
  35.     protected $items;
  36.  
  37.     /**
  38.      * The category model object for this category
  39.      *
  40.      * @var    JModelCategory 
  41.      * @since  3.2
  42.      */
  43.     protected $category;
  44.  
  45.     /**
  46.      * The list of other categories for this extension.
  47.      *
  48.      * @var    array 
  49.      * @since  3.2
  50.      */
  51.     protected $categories;
  52.  
  53.     /**
  54.      * Pagination object
  55.      *
  56.      * @var    JPagination 
  57.      * @since  3.2
  58.      */
  59.     protected $pagination;
  60.  
  61.     /**
  62.      * Child objects
  63.      *
  64.      * @var    array 
  65.      * @since  3.2
  66.      */
  67.     protected $children;
  68.  
  69.     /**
  70.      * The name of the extension for the category
  71.      *
  72.      * @var    string 
  73.      * @since  3.2
  74.      */
  75.     protected $extension;
  76.  
  77.     /**
  78.      * The name of the view to link individual items to
  79.      *
  80.      * @var    string 
  81.      * @since  3.2
  82.      */
  83.     protected $viewName;
  84.  
  85.     /**
  86.      * Default title to use for page title
  87.      *
  88.      * @var    string 
  89.      * @since  3.2
  90.      */
  91.     protected $defaultPageTitle;
  92.  
  93.     /**
  94.      * Method with common display elements used in category list displays
  95.      *
  96.      * @return  void 
  97.      *
  98.      * @since   3.2
  99.      */
  100.     public function commonCategoryDisplay()
  101.     {
  102.         $app    JFactory::getApplication();
  103.         $user   JFactory::getUser();
  104.         $params $app->getParams();
  105.  
  106.         // Get some data from the models
  107.         $state      $this->get('State');
  108.         $items      $this->get('Items');
  109.         $category   $this->get('Category');
  110.         $children   $this->get('Children');
  111.         $parent     $this->get('Parent');
  112.         $pagination $this->get('Pagination');
  113.  
  114.         // Check for errors.
  115.         if (count($errors $this->get('Errors')))
  116.         {
  117.             JError::raiseError(500implode("\n"$errors));
  118.  
  119.             return false;
  120.         }
  121.  
  122.         if ($category == false)
  123.         {
  124.             return JError::raiseError(404JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
  125.         }
  126.  
  127.         if ($parent == false)
  128.         {
  129.             return JError::raiseError(404JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
  130.         }
  131.  
  132.         // Check whether category access level allows access.
  133.         $groups $user->getAuthorisedViewLevels();
  134.  
  135.         if (!in_array($category->access$groups))
  136.         {
  137.             return JError::raiseError(403JText::_('JERROR_ALERTNOAUTHOR'));
  138.         }
  139.  
  140.         // Setup the category parameters.
  141.         $cparams          $category->getParams();
  142.         $category->params clone($params);
  143.         $category->params->merge($cparams);
  144.  
  145.         $children array($category->id => $children);
  146.  
  147.         // Escape strings for HTML output
  148.         $this->pageclass_sfx htmlspecialchars($params->get('pageclass_sfx'));
  149.  
  150.         $maxLevel         $params->get('maxLevel'-1);
  151.         $this->maxLevel   &$maxLevel;
  152.         $this->state      = &$state;
  153.         $this->items      = &$items;
  154.         $this->category   = &$category;
  155.         $this->children   = &$children;
  156.         $this->params     &$params;
  157.         $this->parent     &$parent;
  158.         $this->pagination = &$pagination;
  159.         $this->user       &$user;
  160.  
  161.         // Check for layout override only if this is not the active menu item
  162.         // If it is the active menu item, then the view and category id will match
  163.         $active $app->getMenu()->getActive();
  164.  
  165.         if ((!$active|| ((strpos($active->link'view=category'=== false|| (strpos($active->link'&id=' . (string) $this->category->id=== false)))
  166.         {
  167.             if ($layout $category->params->get('category_layout'))
  168.             {
  169.                 $this->setLayout($layout);
  170.             }
  171.         }
  172.         elseif (isset($active->query['layout']))
  173.         {
  174.             // We need to set the layout in case this is an alternative menu item (with an alternative layout)
  175.             $this->setLayout($active->query['layout']);
  176.         }
  177.  
  178.         $this->category->tags new JHelperTags;
  179.         $this->category->tags->getItemTags($this->extension . '.category'$this->category->id);
  180.     }
  181.  
  182.     /**
  183.      * Execute and display a template script.
  184.      *
  185.      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  186.      *
  187.      * @return  mixed  A string if successful, otherwise a Error object.
  188.      *
  189.      * @since   3.2
  190.      */
  191.     public function display($tpl null)
  192.     {
  193.         $this->prepareDocument();
  194.  
  195.         return parent::display($tpl);
  196.     }
  197.  
  198.     /**
  199.      * Method to prepares the document
  200.      *
  201.      * @return  void 
  202.      *
  203.      * @since   3.2
  204.      */
  205.     protected function prepareDocument()
  206.     {
  207.         $app           JFactory::getApplication();
  208.         $menus         $app->getMenu();
  209.         $this->pathway $app->getPathway();
  210.         $title         null;
  211.  
  212.         // Because the application sets a default page title, we need to get it from the menu item itself
  213.         $this->menu $menus->getActive();
  214.  
  215.         if ($this->menu)
  216.         {
  217.             $this->params->def('page_heading'$this->params->get('page_title'$this->menu->title));
  218.         }
  219.         else
  220.         {
  221.             $this->params->def('page_heading'JText::_($this->defaultPageTitle));
  222.         }
  223.  
  224.         $title $this->params->get('page_title''');
  225.  
  226.         if (empty($title))
  227.         {
  228.             $title $app->get('sitename');
  229.         }
  230.         elseif ($app->get('sitename_pagetitles'0== 1)
  231.         {
  232.             $title JText::sprintf('JPAGETITLE'$app->get('sitename')$title);
  233.         }
  234.         elseif ($app->get('sitename_pagetitles'0== 2)
  235.         {
  236.             $title JText::sprintf('JPAGETITLE'$title$app->get('sitename'));
  237.         }
  238.  
  239.         $this->document->setTitle($title);
  240.  
  241.         if ($this->params->get('menu-meta_description'))
  242.         {
  243.             $this->document->setDescription($this->params->get('menu-meta_description'));
  244.         }
  245.  
  246.         if ($this->params->get('menu-meta_keywords'))
  247.         {
  248.             $this->document->setMetadata('keywords'$this->params->get('menu-meta_keywords'));
  249.         }
  250.  
  251.         if ($this->params->get('robots'))
  252.         {
  253.             $this->document->setMetadata('robots'$this->params->get('robots'));
  254.         }
  255.     }
  256.  
  257.     /**
  258.      * Method to add an alternative feed link to a category layout.
  259.      *
  260.      * @return  void 
  261.      *
  262.      * @since   3.2
  263.      */
  264.     protected function addFeed()
  265.     {
  266.         if ($this->params->get('show_feed_link'1== 1)
  267.         {
  268.             $link    '&format=feed&limitstart=';
  269.             $attribs array('type' => 'application/rss+xml''title' => 'RSS 2.0');
  270.             $this->document->addHeadLink(JRoute::_($link '&type=rss')'alternate''rel'$attribs);
  271.             $attribs array('type' => 'application/atom+xml''title' => 'Atom 1.0');
  272.             $this->document->addHeadLink(JRoute::_($link '&type=atom')'alternate''rel'$attribs);
  273.         }
  274.     }
  275. }

Documentation generated on Tue, 19 Nov 2013 14:55:21 +0100 by phpDocumentor 1.4.3