Dodany przez: mrmarkos, 22:19 29-06-2012

Nowy Pobierz
  1. <?php
  2. /**
  3.  * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  4.  * @license             GNU General Public License version 2 or later; see LICENSE.txt
  5.  */
  6.  
  7. defined('_JEXEC') or die;
  8.  
  9. /**
  10.  * HTML Article View class for the Content component
  11.  *
  12.  * @package             Joomla.Site
  13.  * @subpackage  com_content
  14.  * @since               1.5
  15.  */
  16. class ContentViewArticle extends JViewLegacy
  17. {
  18.         protected $item;
  19.         protected $params;
  20.         protected $print;
  21.         protected $state;
  22.         protected $user;
  23.  
  24.         function display($tpl = null)
  25.         {
  26.                 // Initialise variables.
  27.                 $app            = JFactory::getApplication();
  28.                 $user           = JFactory::getUser();
  29.                 $userId         = $user->get('id');
  30.                 $dispatcher     = JDispatcher::getInstance();
  31.  
  32.                 $this->item             = $this->get('Item');
  33.                 $this->print    = JRequest::getBool('print');
  34.                 $this->state    = $this->get('State');
  35.                 $this->user             = $user;
  36.  
  37.                 // Check for errors.
  38.                 if (count($errors = $this->get('Errors'))) {
  39.                         JError::raiseWarning(500, implode("\n", $errors));
  40.  
  41.                         return false;
  42.                 }
  43.  
  44.                 // Create a shortcut for $item.
  45.                 $item = &$this->item;
  46.  
  47.                 // Add router helpers.
  48.                 $item->slug                     = $item->alias ? ($item->id.':'.$item->alias) : $item->id;
  49.                 $item->catslug          = $item->category_alias ? ($item->catid.':'.$item->category_alias) : $item->catid;
  50.                 $item->parent_slug      = $item->category_alias ? ($item->parent_id.':'.$item->parent_alias) : $item->parent_id;
  51.  
  52.                 // TODO: Change based on shownoauth
  53.                 $item->readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
  54.  
  55.                 // Merge article params. If this is single-article view, menu params override article params
  56.                 // Otherwise, article params override menu item params
  57.                 $this->params   = $this->state->get('params');
  58.                 $active = $app->getMenu()->getActive();
  59.                 $temp   = clone ($this->params);
  60.  
  61.                 // Check to see which parameters should take priority
  62.                 if ($active) {
  63.                         $currentLink = $active->link;
  64.                         // If the current view is the active item and an article view for this article, then the menu item params take priority
  65.                         if (strpos($currentLink, 'view=article') && (strpos($currentLink, '&id='.(string) $item->id))) {
  66.                                 // $item->params are the article params, $temp are the menu item params
  67.                                 // Merge so that the menu item params take priority
  68.                                 $item->params->merge($temp);
  69.                                 // Load layout from active query (in case it is an alternative menu item)
  70.                                 if (isset($active->query['layout'])) {
  71.                                         $this->setLayout($active->query['layout']);
  72.                                 }
  73.                         }
  74.                         else {
  75.                                 // Current view is not a single article, so the article params take priority here
  76.                                 // Merge the menu item params with the article params so that the article params take priority
  77.                                 $temp->merge($item->params);
  78.                                 $item->params = $temp;
  79.  
  80.                                 // Check for alternative layouts (since we are not in a single-article menu item)
  81.                                 // Single-article menu item layout takes priority over alt layout for an article
  82.                                 if ($layout = $item->params->get('article_layout')) {
  83.                                         $this->setLayout($layout);
  84.                                 }
  85.                         }
  86.                 }
  87.                 else {
  88.                         // Merge so that article params take priority
  89.                         $temp->merge($item->params);
  90.                         $item->params = $temp;
  91.                         // Check for alternative layouts (since we are not in a single-article menu item)
  92.                         // Single-article menu item layout takes priority over alt layout for an article
  93.                         if ($layout = $item->params->get('article_layout')) {
  94.                                 $this->setLayout($layout);
  95.                         }
  96.                 }
  97.  
  98.                 $offset = $this->state->get('list.offset');
  99.  
  100.                 // Check the view access to the article (the model has already computed the values).
  101.                 if ($item->params->get('access-view') != true && (($item->params->get('show_noauth') != true &&  $user->get('guest') ))) {
  102.  
  103.                                                 JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR'));
  104.  
  105.                                 return;
  106.  
  107.                 }
  108.  
  109.                 if ($item->params->get('show_intro', '1')=='1') {
  110.                         $item->text = $item->introtext.' '.$item->fulltext;
  111.                 }
  112.                 elseif ($item->fulltext) {
  113.                         $item->text = $item->fulltext;
  114.                 }
  115.                 else  {
  116.                         $item->text = $item->introtext;
  117.                 }
  118.  
  119.                 //
  120.                 // Process the content plugins.
  121.                 //
  122.                 JPluginHelper::importPlugin('content');
  123.                 $results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$item, &$this->params, $offset));
  124.  
  125.                 $item->event = new stdClass();
  126.                 $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$this->params, $offset));
  127.                 $item->event->afterDisplayTitle = trim(implode("\n", $results));
  128.  
  129.                 $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$this->params, $offset));
  130.                 $item->event->beforeDisplayContent = trim(implode("\n", $results));
  131.  
  132.                 $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$this->params, $offset));
  133.                 $item->event->afterDisplayContent = trim(implode("\n", $results));
  134.  
  135.                 // Increment the hit counter of the article.
  136.                 if (!$this->params->get('intro_only') && $offset == 0) {
  137.                         $model = $this->getModel();
  138.                         $model->hit();
  139.                 }
  140.  
  141.                 //Escape strings for HTML output
  142.                 $this->pageclass_sfx = htmlspecialchars($this->item->params->get('pageclass_sfx'));
  143.  
  144.                 $this->_prepareDocument();
  145.  
  146.                 parent::display($tpl);
  147.         }
  148.  
  149.         /**
  150.          * Prepares the document
  151.          */
  152.         protected function _prepareDocument()
  153.         {
  154.                 $app    = JFactory::getApplication();
  155.                 $menus  = $app->getMenu();
  156.                 $pathway = $app->getPathway();
  157.                 $title = null;
  158.  
  159.                 // Because the application sets a default page title,
  160.                 // we need to get it from the menu item itself
  161.                 $menu = $menus->getActive();
  162.                 if ($menu)
  163.                 {
  164.                         $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
  165.                 }
  166.                 else
  167.                 {
  168.                         $this->params->def('page_heading', JText::_('JGLOBAL_ARTICLES'));
  169.                 }
  170.  
  171.                 $title = $this->params->get('page_title', '');
  172.  
  173.                 $id = (int) @$menu->query['id'];
  174.  
  175.                 // if the menu item does not concern this article
  176.                 if ($menu && ($menu->query['option'] != 'com_content' || $menu->query['view'] != 'article' || $id != $this->item->id))
  177.                 {
  178.                         // If this is not a single article menu item, set the page title to the article title
  179.                         if ($this->item->title) {
  180.                                 $title = $this->item->title;
  181.                         }
  182.                         $path = array(array('title' => $this->item->title, 'link' => ''));
  183.                         $category = JCategories::getInstance('Content')->get($this->item->catid);
  184.                         while ($category && ($menu->query['option'] != 'com_content' || $menu->query['view'] == 'article' || $id != $category->id) && $category->id > 1)
  185.                         {
  186.                                 $path[] = array('title' => $category->title, 'link' => ContentHelperRoute::getCategoryRoute($category->id));
  187.                                 $category = $category->getParent();
  188.                         }
  189.                         $path = array_reverse($path);
  190.                         foreach($path as $item)
  191.                         {
  192.                                 $pathway->addItem($item['title'], $item['link']);
  193.                         }
  194.                 }
  195.  
  196.                 // Check for empty title and add site name if param is set
  197.                 if (empty($title)) {
  198.                         $title = $app->getCfg('sitename');
  199.                 }
  200.                 elseif ($app->getCfg('sitename_pagetitles', 0) == 1) {
  201.                         $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
  202.                 }
  203.                 elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
  204.                         $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
  205.                 }
  206.                 if (empty($title)) {
  207.                         $title = $this->item->title;
  208.                 }
  209.                 $this->document->setTitle($title);
  210.  
  211.                 if ($this->item->metadesc)
  212.                 {
  213.                         $this->document->setDescription($this->item->metadesc);
  214.                 }
  215.                 elseif (!$this->item->metadesc && $this->params->get('menu-meta_description'))
  216.                 {
  217.                         $this->document->setDescription($this->params->get('menu-meta_description'));
  218.                 }
  219.  
  220.                 if ($this->item->metakey)
  221.                 {
  222.                         $this->document->setMetadata('keywords', $this->item->metakey);
  223.                 }
  224.                 elseif (!$this->item->metakey && $this->params->get('menu-meta_keywords'))
  225.                 {
  226.                         $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
  227.                 }
  228.  
  229.                 if ($this->params->get('robots'))
  230.                 {
  231.                         $this->document->setMetadata('robots', $this->params->get('robots'));
  232.                 }
  233.  
  234.                 if ($app->getCfg('MetaAuthor') == '1')
  235.                 {
  236.                         $this->document->setMetaData('author', $this->item->author);
  237.                 }
  238.  
  239.                 $mdata = $this->item->metadata->toArray();
  240.                 foreach ($mdata as $k => $v)
  241.                 {
  242.                         if ($v)
  243.                         {
  244.                                 $this->document->setMetadata($k, $v);
  245.                         }
  246.                 }
  247.  
  248.                 // If there is a pagebreak heading or title, add it to the page title
  249.                 if (!empty($this->item->page_title))
  250.                 {
  251.                         $this->item->title = $this->item->title . ' - ' . $this->item->page_title;
  252.                         $this->document->setTitle($this->item->page_title . ' - ' . JText::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $this->state->get('list.offset') + 1));
  253.                 }
  254.  
  255.                 if ($this->print)
  256.                 {
  257.                         $this->document->setMetaData('robots', 'noindex, nofollow');
  258.                 }
  259.         }
  260. }

Źródło:

Ostatnie wpisy

Linki

Funkcje