PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_content/views/article/view.html.php

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