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