PageRenderTime 57ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_redirect/controllers/links.php

https://github.com/joebushi/joomla
PHP | 162 lines | 94 code | 21 blank | 47 comment | 19 complexity | 77f9432825cd2caec47d3723bf64dafa MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla.Administrator
  5. * @subpackage com_redirect
  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. defined('_JEXEC') or die('Invalid Request.');
  10. jimport('joomla.application.component.controller');
  11. /**
  12. * Redirect link list controller class.
  13. *
  14. * @package Joomla.Administrator
  15. * @subpackage com_redirect
  16. * @since 1.6
  17. */
  18. class RedirectControllerLinks extends JController
  19. {
  20. /**
  21. * Constructor.
  22. *
  23. * @param array An optional associative array of configuration settings.
  24. * @see JController
  25. */
  26. public function __construct($config = array())
  27. {
  28. parent::__construct($config);
  29. $this->registerTask('unpublish', 'publish');
  30. $this->registerTask('archive', 'publish');
  31. $this->registerTask('trash', 'publish');
  32. }
  33. /**
  34. * Display is not supported by this class.
  35. */
  36. public function display()
  37. {
  38. }
  39. /**
  40. * Proxy for getModel.
  41. */
  42. public function &getModel($name = 'Link', $prefix = 'RedirectModel')
  43. {
  44. $model = parent::getModel($name, $prefix, array('ignore_request' => true));
  45. return $model;
  46. }
  47. /**
  48. * Method to remove a record.
  49. */
  50. public function delete()
  51. {
  52. // Check for request forgeries.
  53. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  54. // Initialise variables.
  55. $ids = JRequest::getVar('cid', array(), '', 'array');
  56. if (empty($ids)) {
  57. JError::raiseWarning(500, JText::_('JError_No_items_selected'));
  58. }
  59. else {
  60. // Get the model.
  61. $model = $this->getModel();
  62. // Remove the items.
  63. if (!$model->delete($ids)) {
  64. JError::raiseWarning(500, $model->getError());
  65. }
  66. else {
  67. $this->setMessage(JText::sprintf('JController_N_Items_deleted', count($ids)));
  68. }
  69. }
  70. $this->setRedirect('index.php?option=com_redirect&view=links');
  71. }
  72. /**
  73. * Method to change the state of a list of records.
  74. */
  75. public function publish()
  76. {
  77. // Check for request forgeries.
  78. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  79. // Initialise variables.
  80. $ids = JRequest::getVar('cid', array(), '', 'array');
  81. $values = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2);
  82. $task = $this->getTask();
  83. $value = JArrayHelper::getValue($values, $task, 0, 'int');
  84. if (empty($ids)) {
  85. JError::raiseWarning(500, JText::_('JError_No_items_selected'));
  86. }
  87. else
  88. {
  89. // Get the model.
  90. $model = $this->getModel();
  91. // Change the state of the records.
  92. if (!$model->publish($ids, $value)) {
  93. JError::raiseWarning(500, $model->getError());
  94. }
  95. else
  96. {
  97. if ($value == 1) {
  98. $text = 'JSuccess_N_Items_published';
  99. }
  100. else if ($value == 0) {
  101. $text = 'JSuccess_N_Items_unpublished';
  102. }
  103. else if ($value == -1) {
  104. $text = 'JSuccess_N_Items_archived';
  105. }
  106. else {
  107. $text = 'JSuccess_N_Items_trashed';
  108. }
  109. $this->setMessage(JText::sprintf($text, count($ids)));
  110. }
  111. }
  112. $this->setRedirect('index.php?option=com_redirect&view=links');
  113. }
  114. /**
  115. * Method to remove a record.
  116. */
  117. public function activate()
  118. {
  119. // Check for request forgeries.
  120. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  121. // Initialise variables.
  122. $ids = JRequest::getVar('cid', array(), '', 'array');
  123. $newUrl = JRequest::getString('new_url');
  124. $comment = JRequest::getString('comment');
  125. if (empty($ids)) {
  126. JError::raiseWarning(500, JText::_('JError_No_items_selected'));
  127. }
  128. else {
  129. // Get the model.
  130. $model = $this->getModel();
  131. // Remove the items.
  132. if (!$model->activate($ids, $newUrl, $comment)) {
  133. JError::raiseWarning(500, $model->getError());
  134. }
  135. else {
  136. $this->setMessage(JText::sprintf('Redir_N_Items_updated', count($ids)));
  137. }
  138. }
  139. $this->setRedirect('index.php?option=com_redirect&view=links');
  140. }
  141. }