|
| 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 | +// No direct access |
| 8 | +defined('_JEXEC') or die; |
| 9 | + |
| 10 | +jimport('joomla.application.component.view'); |
| 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 | +class ContentViewArticle extends ContentViewArticleDefault |
| 20 | +{ |
| 21 | + |
| 22 | + function display($tpl = null) |
| 23 | + { |
| 24 | + // Initialise variables. |
| 25 | + $app = JFactory::getApplication(); |
| 26 | + $user = JFactory::getUser(); |
| 27 | + $userId = $user->get('id'); |
| 28 | + $dispatcher = JDispatcher::getInstance(); |
| 29 | + |
| 30 | + $this->item = $this->get('Item'); |
| 31 | + /*##mygruz20130223191637 { |
| 32 | + It was: |
| 33 | + It became:*/ |
| 34 | + $this->item->title = '['.$this->item->title.']'; |
| 35 | + /*##mygruz20130223191637 } */ |
| 36 | + $this->print = JRequest::getBool('print'); |
| 37 | + $this->state = $this->get('State'); |
| 38 | + $this->user = $user; |
| 39 | + |
| 40 | + // Check for errors. |
| 41 | + if (count($errors = $this->get('Errors'))) { |
| 42 | + JError::raiseWarning(500, implode("\n", $errors)); |
| 43 | + |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + // Create a shortcut for $item. |
| 48 | + $item = &$this->item; |
| 49 | + |
| 50 | + // Add router helpers. |
| 51 | + $item->slug = $item->alias ? ($item->id.':'.$item->alias) : $item->id; |
| 52 | + $item->catslug = $item->category_alias ? ($item->catid.':'.$item->category_alias) : $item->catid; |
| 53 | + $item->parent_slug = $item->category_alias ? ($item->parent_id.':'.$item->parent_alias) : $item->parent_id; |
| 54 | + |
| 55 | + // TODO: Change based on shownoauth |
| 56 | + $item->readmore_link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug)); |
| 57 | + |
| 58 | + // Merge article params. If this is single-article view, menu params override article params |
| 59 | + // Otherwise, article params override menu item params |
| 60 | + $this->params = $this->state->get('params'); |
| 61 | + $active = $app->getMenu()->getActive(); |
| 62 | + $temp = clone ($this->params); |
| 63 | + |
| 64 | + // Check to see which parameters should take priority |
| 65 | + if ($active) { |
| 66 | + $currentLink = $active->link; |
| 67 | + // If the current view is the active item and an article view for this article, then the menu item params take priority |
| 68 | + if (strpos($currentLink, 'view=article') && (strpos($currentLink, '&id='.(string) $item->id))) { |
| 69 | + // $item->params are the article params, $temp are the menu item params |
| 70 | + // Merge so that the menu item params take priority |
| 71 | + $item->params->merge($temp); |
| 72 | + // Load layout from active query (in case it is an alternative menu item) |
| 73 | + if (isset($active->query['layout'])) { |
| 74 | + $this->setLayout($active->query['layout']); |
| 75 | + } |
| 76 | + } |
| 77 | + else { |
| 78 | + // Current view is not a single article, so the article params take priority here |
| 79 | + // Merge the menu item params with the article params so that the article params take priority |
| 80 | + $temp->merge($item->params); |
| 81 | + $item->params = $temp; |
| 82 | + |
| 83 | + // Check for alternative layouts (since we are not in a single-article menu item) |
| 84 | + // Single-article menu item layout takes priority over alt layout for an article |
| 85 | + if ($layout = $item->params->get('article_layout')) { |
| 86 | + $this->setLayout($layout); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + else { |
| 91 | + // Merge so that article params take priority |
| 92 | + $temp->merge($item->params); |
| 93 | + $item->params = $temp; |
| 94 | + // Check for alternative layouts (since we are not in a single-article menu item) |
| 95 | + // Single-article menu item layout takes priority over alt layout for an article |
| 96 | + if ($layout = $item->params->get('article_layout')) { |
| 97 | + $this->setLayout($layout); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + $offset = $this->state->get('list.offset'); |
| 102 | + |
| 103 | + // Check the view access to the article (the model has already computed the values). |
| 104 | + if ($item->params->get('access-view') != true && (($item->params->get('show_noauth') != true && $user->get('guest') ))) { |
| 105 | + |
| 106 | + JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); |
| 107 | + |
| 108 | + return; |
| 109 | + |
| 110 | + } |
| 111 | + |
| 112 | + if ($item->params->get('show_intro', '1')=='1') { |
| 113 | + $item->text = $item->introtext.' '.$item->fulltext; |
| 114 | + } |
| 115 | + elseif ($item->fulltext) { |
| 116 | + $item->text = $item->fulltext; |
| 117 | + } |
| 118 | + else { |
| 119 | + $item->text = $item->introtext; |
| 120 | + } |
| 121 | + $item->text = 'I\'m overriding a single function, display()'; |
| 122 | + // |
| 123 | + // Process the content plugins. |
| 124 | + // |
| 125 | + JPluginHelper::importPlugin('content'); |
| 126 | + $results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$item, &$this->params, $offset)); |
| 127 | + |
| 128 | + $item->event = new stdClass(); |
| 129 | + $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.article', &$item, &$this->params, $offset)); |
| 130 | + $item->event->afterDisplayTitle = trim(implode("\n", $results)); |
| 131 | + |
| 132 | + $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$this->params, $offset)); |
| 133 | + $item->event->beforeDisplayContent = trim(implode("\n", $results)); |
| 134 | + |
| 135 | + $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$this->params, $offset)); |
| 136 | + $item->event->afterDisplayContent = trim(implode("\n", $results)); |
| 137 | + |
| 138 | + // Increment the hit counter of the article. |
| 139 | + if (!$this->params->get('intro_only') && $offset == 0) { |
| 140 | + $model = $this->getModel(); |
| 141 | + $model->hit(); |
| 142 | + } |
| 143 | + |
| 144 | + //Escape strings for HTML output |
| 145 | + $this->pageclass_sfx = htmlspecialchars($this->item->params->get('pageclass_sfx')); |
| 146 | + |
| 147 | + $this->_prepareDocument(); |
| 148 | + if ( version_compare( JVERSION, '3.0', 'ge' ) ) { |
| 149 | + parent::display($tpl); |
| 150 | + } else { |
| 151 | + JView::display($tpl); |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments