PageRenderTime 158ms CodeModel.GetById 71ms app.highlight 4ms RepoModel.GetById 56ms app.codeStats 0ms

/components/com_weblinks/controllers/weblink.php

https://github.com/joebushi/joomla
PHP | 105 lines | 53 code | 16 blank | 36 comment | 6 complexity | 56f16b23ca71033ba423ac19a5e43c9e 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.controllerform');
 12
 13/**
 14 * @package		Joomla.Site
 15 * @subpackage	com_weblinks
 16 */
 17class WeblinksControllerWeblink extends JControllerForm
 18{
 19	protected $_context = 'com_weblinks.edit.weblink';
 20	/**
 21	 * Constructor
 22	 */
 23	public function __construct($config = array())
 24	{
 25		parent::__construct($config);
 26
 27		$this->registerTask('apply',		'save');
 28		$this->registerTask('save2new',		'save');
 29		$this->registerTask('save2copy',	'save');
 30	}
 31	protected $_view_item = 'form';
 32
 33	protected $_view_list = 'categories';
 34
 35	/**
 36	 * Method to get a model object, loading it if required.
 37	 *
 38	 * @param	string	The model name. Optional.
 39	 * @param	string	The class prefix. Optional.
 40	 * @param	array	Configuration array for model. Optional.
 41	 * @return	object	The model.
 42	 * @since	1.5
 43	 */
 44	public function &getModel($name = 'form', $prefix = '', $config = array())
 45	{
 46		$model = parent::getModel($name, $prefix, $config);
 47		return $model;
 48	}
 49
 50	/**
 51	 * Go to a weblink
 52	 */
 53	public function go()
 54	{
 55		// Get the ID from the request
 56		$id		= JRequest::getInt('id');
 57
 58		// Get the model, requiring published items
 59		$modelLink	= &$this->getModel('Weblink', '', array('ignore_request' => true));
 60		$modelLink->setState('filter.published', 1);
 61
 62		// Get the item
 63		$link	= &$modelLink->getItem($id);
 64
 65		// Make sure the item was found.
 66		if (empty($link)) {
 67			return JError::raiseWarning(404, JText::_('Weblinks_Error_Weblink_not_found'));
 68		}
 69
 70		// Check whether item access level allows access.
 71		$user	= &JFactory::getUser();
 72		$groups	= $user->authorisedLevels();
 73		if (!in_array($link->access, $groups)) {
 74			return JError::raiseError(403, JText::_("ALERTNOTAUTH"));
 75		}
 76
 77		// Check whether category access level allows access.
 78		$modelCat = &$this->getModel('Category', 'WeblinksModel', array('ignore_request' => true));
 79		$modelCat->setState('filter.published', 1);
 80
 81		// Get the category
 82		$category = &$modelCat->getCategory($link->catid);
 83
 84		// Make sure the category was found.
 85		if (empty($category)) {
 86			return JError::raiseWarning(404, JText::_('Weblinks_Error_Weblink_not_found'));
 87		}
 88
 89		// Check whether item access level allows access.
 90		if (!in_array($category->access, $groups)) {
 91			return JError::raiseError(403, JText::_("ALERTNOTAUTH"));
 92		}
 93
 94		// Redirect to the URL
 95		// TODO: Probably should check for a valid http link
 96		if ($link->url)
 97		{
 98			$modelLink->hit($id);
 99			JFactory::getApplication()->redirect($link->url);
100		}
101		else {
102			return JError::raiseWarning(404, JText::_('Weblinks_Error_Weblink_url_invalid'));
103		}
104	}
105}