[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_content/views/category/ -> view.html.php (source)

   1  <?php
   2  /**
   3   * @package        Joomla.Site
   4   * @subpackage    com_content
   5   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   6   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   7   */
   8  
   9  // Check to ensure this file is included in Joomla!
  10  defined('_JEXEC') or die;
  11  
  12  jimport('joomla.application.component.view');
  13  
  14  /**
  15   * HTML View class for the Content component
  16   *
  17   * @package        Joomla.Site
  18   * @subpackage    com_content
  19   * @since 1.5
  20   */
  21  class ContentViewCategory extends JView
  22  {
  23      protected $state;
  24      protected $items;
  25      protected $category;
  26      protected $children;
  27      protected $pagination;
  28  
  29      protected $lead_items = array();
  30      protected $intro_items = array();
  31      protected $link_items = array();
  32      protected $columns = 1;
  33  
  34  	function display($tpl = null)
  35      {
  36          $app    = JFactory::getApplication();
  37          $user    = JFactory::getUser();
  38  
  39          // Get some data from the models
  40          $state        = $this->get('State');
  41          $params        = $state->params;
  42          $items        = $this->get('Items');
  43          $category    = $this->get('Category');
  44          $children    = $this->get('Children');
  45          $parent        = $this->get('Parent');
  46          $pagination = $this->get('Pagination');
  47  
  48          // Check for errors.
  49          if (count($errors = $this->get('Errors'))) {
  50              JError::raiseError(500, implode("\n", $errors));
  51              return false;
  52          }
  53  
  54          if ($category == false) {
  55              return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
  56          }
  57  
  58          if ($parent == false) {
  59              return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
  60          }
  61  
  62          // Setup the category parameters.
  63          $cparams = $category->getParams();
  64          $category->params = clone($params);
  65          $category->params->merge($cparams);
  66  
  67          // Check whether category access level allows access.
  68          $user    = JFactory::getUser();
  69          $groups    = $user->getAuthorisedViewLevels();
  70          if (!in_array($category->access, $groups)) {
  71              return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
  72          }
  73  
  74          // PREPARE THE DATA
  75          // Get the metrics for the structural page layout.
  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          for ($i = 0, $n = count($items); $i < $n; $i++)
  82          {
  83              $item = &$items[$i];
  84              $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
  85  
  86              // No link for ROOT category
  87              if ($item->parent_alias == 'root') {
  88                  $item->parent_slug = null;
  89              }
  90  
  91              $item->event = new stdClass();
  92  
  93              $dispatcher = JDispatcher::getInstance();
  94  
  95              // Ignore content plugins on links.
  96              if ($i < $numLeading + $numIntro) {
  97                  $item->introtext = JHtml::_('content.prepare', $item->introtext, '', 'com_content.category');
  98  
  99                  $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$item->params, 0));
 100                  $item->event->afterDisplayTitle = trim(implode("\n", $results));
 101  
 102                  $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$item->params, 0));
 103                  $item->event->beforeDisplayContent = trim(implode("\n", $results));
 104  
 105                  $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$item->params, 0));
 106                  $item->event->afterDisplayContent = trim(implode("\n", $results));
 107              }
 108          }
 109  
 110          // Check for layout override only if this is not the active menu item
 111          // If it is the active menu item, then the view and category id will match
 112          $active    = $app->getMenu()->getActive();
 113          if ((!$active) || ((strpos($active->link, 'view=category') === false) || (strpos($active->link, '&id=' . (string) $category->id) === false))) {
 114              // Get the layout from the merged category params
 115              if ($layout = $category->params->get('category_layout')) {
 116                  $this->setLayout($layout);
 117              }
 118          }
 119          // At this point, we are in a menu item, so we don't override the layout
 120          elseif (isset($active->query['layout'])) {
 121              // We need to set the layout from the query in case this is an alternative menu item (with an alternative layout)
 122              $this->setLayout($active->query['layout']);
 123          }
 124  
 125          // For blog layouts, preprocess the breakdown of leading, intro and linked articles.
 126          // This makes it much easier for the designer to just interrogate the arrays.
 127          if (($params->get('layout_type') == 'blog') || ($this->getLayout() == 'blog')) {
 128              $max = count($items);
 129  
 130              // The first group is the leading articles.
 131              $limit = $numLeading;
 132              for ($i = 0; $i < $limit && $i < $max; $i++) {
 133                  $this->lead_items[$i] = &$items[$i];
 134              }
 135  
 136              // The second group is the intro articles.
 137              $limit = $numLeading + $numIntro;
 138              // Order articles across, then down (or single column mode)
 139              for ($i = $numLeading; $i < $limit && $i < $max; $i++) {
 140                  $this->intro_items[$i] = &$items[$i];
 141              }
 142  
 143              $this->columns = max(1, $params->def('num_columns', 1));
 144              $order = $params->def('multi_column_order', 1);
 145  
 146              if ($order == 0 && $this->columns > 1) {
 147                  // call order down helper
 148                  $this->intro_items = ContentHelperQuery::orderDownColumns($this->intro_items, $this->columns);
 149              }
 150  
 151              $limit = $numLeading + $numIntro + $numLinks;
 152              // The remainder are the links.
 153              for ($i = $numLeading + $numIntro; $i < $limit && $i < $max;$i++)
 154              {
 155                      $this->link_items[$i] = &$items[$i];
 156              }
 157          }
 158  
 159          $children = array($category->id => $children);
 160  
 161          //Escape strings for HTML output
 162          $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
 163  
 164          $this->assign('maxLevel', $params->get('maxLevel', -1));
 165          $this->assignRef('state', $state);
 166          $this->assignRef('items', $items);
 167          $this->assignRef('category', $category);
 168          $this->assignRef('children', $children);
 169          $this->assignRef('params', $params);
 170          $this->assignRef('parent', $parent);
 171          $this->assignRef('pagination', $pagination);
 172          $this->assignRef('user', $user);
 173  
 174          $this->_prepareDocument();
 175  
 176          parent::display($tpl);
 177      }
 178  
 179      /**
 180       * Prepares the document
 181       */
 182  	protected function _prepareDocument()
 183      {
 184          $app        = JFactory::getApplication();
 185          $menus        = $app->getMenu();
 186          $pathway    = $app->getPathway();
 187          $title        = null;
 188  
 189          // Because the application sets a default page title,
 190          // we need to get it from the menu item itself
 191          $menu = $menus->getActive();
 192  
 193          if ($menu) {
 194              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 195          }
 196          else {
 197              $this->params->def('page_heading', JText::_('JGLOBAL_ARTICLES'));
 198          }
 199  
 200          $id = (int) @$menu->query['id'];
 201  
 202          if ($menu && ($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $this->category->id)) {
 203              $path = array(array('title' => $this->category->title, 'link' => ''));
 204              $category = $this->category->getParent();
 205  
 206              while (($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $category->id) && $category->id > 1)
 207              {
 208                  $path[] = array('title' => $category->title, 'link' => ContentHelperRoute::getCategoryRoute($category->id));
 209                  $category = $category->getParent();
 210              }
 211  
 212              $path = array_reverse($path);
 213  
 214              foreach ($path as $item)
 215              {
 216                  $pathway->addItem($item['title'], $item['link']);
 217              }
 218          }
 219  
 220          $title = $this->params->get('page_title', '');
 221  
 222          if (empty($title)) {
 223              $title = $app->getCfg('sitename');
 224          }
 225          elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
 226              $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
 227          }
 228          elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
 229              $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
 230          }
 231  
 232          $this->document->setTitle($title);
 233  
 234          if ($this->category->metadesc)
 235          {
 236              $this->document->setDescription($this->category->metadesc);
 237          }
 238          elseif (!$this->category->metadesc && $this->params->get('menu-meta_description'))
 239          {
 240              $this->document->setDescription($this->params->get('menu-meta_description'));
 241          }
 242  
 243          if ($this->category->metakey)
 244          {
 245              $this->document->setMetadata('keywords', $this->category->metakey);
 246          }
 247          elseif (!$this->category->metakey && $this->params->get('menu-meta_keywords'))
 248          {
 249              $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
 250          }
 251  
 252          if ($this->params->get('robots'))
 253          {
 254              $this->document->setMetadata('robots', $this->params->get('robots'));
 255          }
 256  
 257          if ($app->getCfg('MetaAuthor') == '1') {
 258              $this->document->setMetaData('author', $this->category->getMetadata()->get('author'));
 259          }
 260  
 261          $mdata = $this->category->getMetadata()->toArray();
 262  
 263          foreach ($mdata as $k => $v)
 264          {
 265              if ($v) {
 266                  $this->document->setMetadata($k, $v);
 267              }
 268          }
 269  
 270          // Add feed links
 271          if ($this->params->get('show_feed_link', 1)) {
 272              $link = '&format=feed&limitstart=';
 273              $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
 274              $this->document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
 275              $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
 276              $this->document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
 277          }
 278      }
 279  }


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