PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 1ms

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