PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

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