PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

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