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 Article View class for the Content component
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_content
  17.  * @since       1.5
  18.  */
  19. {
  20.     protected $item;
  21.  
  22.     protected $params;
  23.  
  24.     protected $print;
  25.  
  26.     protected $state;
  27.  
  28.     protected $user;
  29.  
  30.     public function display($tpl null)
  31.     {
  32.         $app        JFactory::getApplication();
  33.         $user        JFactory::getUser();
  34.         $dispatcher    JEventDispatcher::getInstance();
  35.  
  36.         $this->item        = $this->get('Item');
  37.         $this->print    = $app->input->getBool('print');
  38.         $this->state    = $this->get('State');
  39.         $this->user        = $user;
  40.  
  41.         // Check for errors.
  42.         if (count($errors $this->get('Errors')))
  43.         {
  44.             JError::raiseWarning(500implode("\n"$errors));
  45.             return false;
  46.         }
  47.  
  48.         // Create a shortcut for $item.
  49.         $item $this->item;
  50.         $item->tagLayout new JLayoutFile('joomla.content.tags');
  51.  
  52.         // Add router helpers.
  53.         $item->slug            $item->alias ($item->id.':'.$item->alias$item->id;
  54.         $item->catslug        $item->category_alias ($item->catid.':'.$item->category_alias$item->catid;
  55.         $item->parent_slug    $item->parent_alias ($item->parent_id ':' $item->parent_alias$item->parent_id;
  56.  
  57.         // No link for ROOT category
  58.         if ($item->parent_alias == 'root')
  59.         {
  60.             $item->parent_slug null;
  61.         }
  62.  
  63.         // TODO: Change based on shownoauth
  64.         $item->readmore_link JRoute::_(ContentHelperRoute::getArticleRoute($item->slug$item->catslug));
  65.  
  66.         // Merge article params. If this is single-article view, menu params override article params
  67.         // Otherwise, article params override menu item params
  68.         $this->params = $this->state->get('params');
  69.         $active $app->getMenu()->getActive();
  70.         $temp clone ($this->params);
  71.  
  72.         // Check to see which parameters should take priority
  73.         if ($active)
  74.         {
  75.             $currentLink $active->link;
  76.  
  77.             // If the current view is the active item and an article view for this article, then the menu item params take priority
  78.             if (strpos($currentLink'view=article'&& (strpos($currentLink'&id='.(string) $item->id)))
  79.             {
  80.                 // Load layout from active query (in case it is an alternative menu item)
  81.                 if (isset($active->query['layout']))
  82.                 {
  83.                     $this->setLayout($active->query['layout']);
  84.                 }
  85.                 // Check for alternative layout of article
  86.                 elseif ($layout $item->params->get('article_layout'))
  87.                 {
  88.                     $this->setLayout($layout);
  89.                 }
  90.  
  91.                 // $item->params are the article params, $temp are the menu item params
  92.                 // Merge so that the menu item params take priority
  93.                 $item->params->merge($temp);
  94.             }
  95.             else
  96.             {
  97.                 // Current view is not a single article, so the article params take priority here
  98.                 // Merge the menu item params with the article params so that the article params take priority
  99.                 $temp->merge($item->params);
  100.                 $item->params $temp;
  101.  
  102.                 // Check for alternative layouts (since we are not in a single-article menu item)
  103.                 // Single-article menu item layout takes priority over alt layout for an article
  104.                 if ($layout $item->params->get('article_layout'))
  105.                 {
  106.                     $this->setLayout($layout);
  107.                 }
  108.             }
  109.         }
  110.         else
  111.         {
  112.             // Merge so that article params take priority
  113.             $temp->merge($item->params);
  114.             $item->params $temp;
  115.  
  116.             // Check for alternative layouts (since we are not in a single-article menu item)
  117.             // Single-article menu item layout takes priority over alt layout for an article
  118.             if ($layout $item->params->get('article_layout'))
  119.             {
  120.                 $this->setLayout($layout);
  121.             }
  122.         }
  123.  
  124.         $offset $this->state->get('list.offset');
  125.  
  126.         // Check the view access to the article (the model has already computed the values).
  127.         if ($item->params->get('access-view'!= true && (($item->params->get('show_noauth'!= true &&  $user->get('guest') )))
  128.         {
  129.             JError::raiseWarning(403JText::_('JERROR_ALERTNOAUTHOR'));
  130.             return;
  131.         }
  132.  
  133.         if ($item->params->get('show_intro''1'== '1')
  134.         {
  135.             $item->text $item->introtext.' '.$item->fulltext;
  136.         }
  137.         elseif ($item->fulltext)
  138.         {
  139.             $item->text $item->fulltext;
  140.         }
  141.         else
  142.         {
  143.             $item->text $item->introtext;
  144.         }
  145.  
  146.         $item->tags new JHelperTags;
  147.         $item->tags->getItemTags('com_content.article'$this->item->id);
  148.  
  149.         // Process the content plugins.
  150.  
  151.         JPluginHelper::importPlugin('content');
  152.         $dispatcher->trigger('onContentPrepare'array ('com_content.article'&$item&$this->params$offset));
  153.  
  154.         $item->event new stdClass;
  155.         $results $dispatcher->trigger('onContentAfterTitle'array('com_content.article'&$item&$this->params$offset));
  156.         $item->event->afterDisplayTitle trim(implode("\n"$results));
  157.  
  158.         $results $dispatcher->trigger('onContentBeforeDisplay'array('com_content.article'&$item&$this->params$offset));
  159.         $item->event->beforeDisplayContent trim(implode("\n"$results));
  160.  
  161.         $results $dispatcher->trigger('onContentAfterDisplay'array('com_content.article'&$item&$this->params$offset));
  162.         $item->event->afterDisplayContent trim(implode("\n"$results));
  163.  
  164.         // Increment the hit counter of the article.
  165.         if (!$this->params->get('intro_only'&& $offset == 0)
  166.         {
  167.             $model $this->getModel();
  168.             $model->hit();
  169.         }
  170.  
  171.         //Escape strings for HTML output
  172.         $this->pageclass_sfx htmlspecialchars($this->item->params->get('pageclass_sfx'));
  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.         {
  195.             $this->params->def('page_heading'$this->params->get('page_title'$menu->title));
  196.         }
  197.         else
  198.         {
  199.             $this->params->def('page_heading'JText::_('JGLOBAL_ARTICLES'));
  200.         }
  201.  
  202.         $title $this->params->get('page_title''');
  203.  
  204.         $id = (int) @$menu->query['id'];
  205.  
  206.         // if the menu item does not concern this article
  207.         if ($menu && ($menu->query['option'!= 'com_content' || $menu->query['view'!= 'article' || $id != $this->item->id))
  208.         {
  209.             // If this is not a single article menu item, set the page title to the article title
  210.             if ($this->item->title)
  211.             {
  212.                 $title $this->item->title;
  213.             }
  214.             $path array(array('title' => $this->item->title'link' => ''));
  215.             $category JCategories::getInstance('Content')->get($this->item->catid);
  216.  
  217.             while ($category && ($menu->query['option'!= 'com_content' || $menu->query['view'== 'article' || $id != $category->id&& $category->id 1)
  218.             {
  219.                 $path[array('title' => $category->title'link' => ContentHelperRoute::getCategoryRoute($category->id));
  220.                 $category $category->getParent();
  221.             }
  222.             $path array_reverse($path);
  223.  
  224.             foreach ($path as $item)
  225.             {
  226.                 $pathway->addItem($item['title']$item['link']);
  227.             }
  228.         }
  229.  
  230.         // Check for empty title and add site name if param is set
  231.         if (empty($title))
  232.         {
  233.             $title $app->getCfg('sitename');
  234.         }
  235.         elseif ($app->getCfg('sitename_pagetitles'0== 1)
  236.         {
  237.             $title JText::sprintf('JPAGETITLE'$app->getCfg('sitename')$title);
  238.         }
  239.         elseif ($app->getCfg('sitename_pagetitles'0== 2)
  240.         {
  241.             $title JText::sprintf('JPAGETITLE'$title$app->getCfg('sitename'));
  242.         }
  243.  
  244.         if (empty($title))
  245.         {
  246.             $title $this->item->title;
  247.         }
  248.         $this->document->setTitle($title);
  249.  
  250.         if ($this->item->metadesc)
  251.         {
  252.             $this->document->setDescription($this->item->metadesc);
  253.         }
  254.         elseif (!$this->item->metadesc && $this->params->get('menu-meta_description'))
  255.         {
  256.             $this->document->setDescription($this->params->get('menu-meta_description'));
  257.         }
  258.  
  259.         if ($this->item->metakey)
  260.         {
  261.             $this->document->setMetadata('keywords'$this->item->metakey);
  262.         }
  263.         elseif (!$this->item->metakey && $this->params->get('menu-meta_keywords'))
  264.         {
  265.             $this->document->setMetadata('keywords'$this->params->get('menu-meta_keywords'));
  266.         }
  267.  
  268.         if ($this->params->get('robots'))
  269.         {
  270.             $this->document->setMetadata('robots'$this->params->get('robots'));
  271.         }
  272.  
  273.         if ($app->getCfg('MetaAuthor'== '1')
  274.         {
  275.             $this->document->setMetaData('author'$this->item->author);
  276.         }
  277.  
  278.         $mdata $this->item->metadata->toArray();
  279.  
  280.         foreach ($mdata as $k => $v)
  281.         {
  282.             if ($v)
  283.             {
  284.                 $this->document->setMetadata($k$v);
  285.             }
  286.         }
  287.  
  288.         // If there is a pagebreak heading or title, add it to the page title
  289.         if (!empty($this->item->page_title))
  290.         {
  291.             $this->item->title $this->item->title ' - ' $this->item->page_title;
  292.             $this->document->setTitle($this->item->page_title ' - ' JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM'$this->state->get('list.offset'1));
  293.         }
  294.  
  295.         if ($this->print)
  296.         {
  297.             $this->document->setMetaData('robots''noindex, nofollow');
  298.         }
  299.     }
  300. }

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