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