PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/joebushi/joomla
PHP | 140 lines | 83 code | 23 blank | 34 comment | 13 complexity | a3c0cc04a3eb624cb5740877a9037b8f MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * version $Id$
  4. * @package Joomla
  5. * @subpackage Newsfeeds
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. *
  9. */
  10. // Check to ensure this file is included in Joomla!
  11. defined('_JEXEC') or die;
  12. jimport('joomla.application.component.view');
  13. /**
  14. * HTML View class for the Newsfeeds component
  15. *
  16. * @package Joomla.Site
  17. * @subpackage com_newsfeeds
  18. * @since 1.0
  19. */
  20. class NewsfeedsViewCategory extends JView
  21. {
  22. protected $state;
  23. protected $items;
  24. protected $category;
  25. protected $categories;
  26. protected $pagination;
  27. function display($tpl = null)
  28. {
  29. $app = &JFactory::getApplication();
  30. $params = &$app->getParams();
  31. // Get some data from the models
  32. $state = &$this->get('State');
  33. $items = &$this->get('Items');
  34. $category = &$this->get('Category');
  35. $categories = &$this->get('Categories');
  36. $pagination = &$this->get('Pagination');
  37. // Check for errors.
  38. if (count($errors = $this->get('Errors'))) {
  39. JError::raiseError(500, implode("\n", $errors));
  40. return false;
  41. }
  42. // Validate the category.
  43. // Make sure the category was found.
  44. if (empty($category)) {
  45. return JError::raiseWarning(404, JText::_('Newfeeds_Error_Category_not_found'));
  46. }
  47. // Check whether category access level allows access.
  48. $user = &JFactory::getUser();
  49. $groups = $user->authorisedLevels();
  50. if (!in_array($category->access, $groups)) {
  51. return JError::raiseError(403, JText::_("ALERTNOTAUTH"));
  52. }
  53. // Prepare the data.
  54. // Compute the active category slug.
  55. $category->slug = $category->alias ? ($category->id.':'.$category->alias) : $category->id;
  56. // Prepare category description (runs content plugins)
  57. // TODO: only use if the description is displayed
  58. $category->description = JHtml::_('content.prepare', $category->description);
  59. // Compute the newsfeed slug.
  60. for ($i = 0, $n = count($items); $i < $n; $i++)
  61. {
  62. $item = &$items[$i];
  63. $item->slug = $item->alias ? ($item->id.':'.$item->alias) : $item->id;
  64. }
  65. // Compute the categories (list) slug.
  66. for ($i = 0, $n = count($categories); $i < $n; $i++)
  67. {
  68. $item = &$categories[$i];
  69. $item->slug = $item->alias ? ($item->id.':'.$item->alias) : $item->id;
  70. }
  71. $this->assignRef('state', $state);
  72. $this->assignRef('items', $items);
  73. $this->assignRef('category', $category);
  74. $this->assignRef('categories', $categories);
  75. $this->assignRef('params', $params);
  76. $this->assignRef('pagination', $pagination);
  77. $this->_prepareDocument();
  78. parent::display($tpl);
  79. }
  80. /**
  81. * Prepares the document
  82. */
  83. protected function _prepareDocument()
  84. {
  85. $app = &JFactory::getApplication();
  86. $menus = &JSite::getMenu();
  87. $pathway = &$app->getPathway();
  88. // Because the application sets a default page title,
  89. // we need to get it from the menu item itself
  90. if ($menu = $menus->getActive())
  91. {
  92. $menuParams = new JParameter($menu->params);
  93. if ($title = $menuParams->get('jpage_title')) {
  94. $this->document->setTitle($title);
  95. }
  96. else {
  97. $this->document->setTitle(JText::_('News_Feeds'));
  98. }
  99. // Set breadcrumbs.
  100. if ($menu->query['view'] != 'category') {
  101. $pathway->addItem($this->category->title, '');
  102. }
  103. }
  104. else {
  105. $this->document->setTitle(JText::_('News_Feeds'));
  106. }
  107. // Add alternate feed link
  108. if ($this->params->get('show_feed_link', 1) == 1)
  109. {
  110. $link = '&view=category&id='.$this->category->slug.'&format=feed&limitstart=';
  111. $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
  112. $this->document->addHeadLink(JRoute::_($link.'&type=rss'), 'alternate', 'rel', $attribs);
  113. $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
  114. $this->document->addHeadLink(JRoute::_($link.'&type=atom'), 'alternate', 'rel', $attribs);
  115. }
  116. }
  117. }