PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/contentmanager/code/trunk/administrator/components/com_contentmanager/controllers/splashes.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 261 lines | 141 code | 44 blank | 76 comment | 20 complexity | d9d9c92a26d6b1b0f6c4c5a62878180d MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: splashes.php 39 2009-05-21 07:32:36Z eddieajau $
  4. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  5. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  6. * @link http://www.theartofjoomla.com
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. jimport('joomla.application.component.controller');
  11. /**
  12. * @package TAOJ.ContentManager
  13. * @subpackage com_contentmanager
  14. */
  15. class ContentManagerControllerSplashes extends JController
  16. {
  17. /**
  18. * Constructor
  19. */
  20. function __construct()
  21. {
  22. parent::__construct();
  23. $this->registerTask('save2copy', 'save');
  24. $this->registerTask('save2new', 'save');
  25. $this->registerTask('apply', 'save');
  26. $this->registerTask('unpublish', 'publish');
  27. $this->registerTask('trash', 'publish');
  28. $this->registerTask('orderup', 'ordering');
  29. $this->registerTask('orderdown', 'ordering');
  30. }
  31. /**
  32. * Display the view
  33. */
  34. function display()
  35. {
  36. }
  37. /**
  38. * Proxy for getModel
  39. */
  40. function &getModel()
  41. {
  42. return parent::getModel('Splash', '', array('ignore_request' => true));
  43. }
  44. /**
  45. * Method to edit a object
  46. *
  47. * Sets object ID in the session from the request, checks the item out, and then redirects to the edit page.
  48. *
  49. * @access public
  50. * @return void
  51. */
  52. function edit()
  53. {
  54. $cid = JRequest::getVar('cid', array(), '', 'array');
  55. $id = JRequest::getInt('id', @$cid[0]);
  56. $session = &JFactory::getSession();
  57. $session->set('contentmanager.splash.id', $id);
  58. // Checkout item
  59. $model = $this->getModel();
  60. if ($id) {
  61. $model->checkout($id);
  62. }
  63. $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=splash&layout=edit', false));
  64. }
  65. /**
  66. * Method to cancel an edit
  67. *
  68. * Checks the item in, sets item ID in the session to null, and then redirects to the list page.
  69. *
  70. * @access public
  71. * @return void
  72. */
  73. function cancel()
  74. {
  75. // Checkin item if checked out
  76. $session = &JFactory::getSession();
  77. if ($id = (int) $session->get('contentmanager.splash.id')) {
  78. $model = $this->getModel();
  79. $model->checkin($id);
  80. }
  81. // Clear the session of the item
  82. $session->set('contentmanager.splash.id', null);
  83. $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=splashes', false));
  84. }
  85. /**
  86. * Save the record
  87. */
  88. function save()
  89. {
  90. // Check for request forgeries.
  91. JRequest::checkToken();
  92. // Get posted form variables.
  93. $values = JRequest::getVar('jxform', array(), 'post', 'array');
  94. // Get the id of the item out of the session.
  95. $session = &JFactory::getSession();
  96. $id = (int) $session->get('contentmanager.splash.id');
  97. $values['id'] = $id;
  98. // Get the extensions model and set the post request in its state.
  99. $model = &$this->getModel();
  100. $post = JRequest::get('post');
  101. $model->setState('request', $post);
  102. // Get the form model object and validate it.
  103. $form = &$model->getForm('model');
  104. $form->filter($values);
  105. $result = $form->validate($values);
  106. if (JError::isError($result)) {
  107. JError::raiseError(500, $result->message);
  108. }
  109. // Handle ancillary controls
  110. $values['params'] = JArrayHelper::getValue($post, 'jxformparams', array(), 'array');
  111. $values['media'] = JArrayHelper::getValue($post, 'jxformmedia', array(), 'array');
  112. $result = $model->save($values);
  113. $msg = JError::isError($result) ? $result->message : 'Saved';
  114. if ($this->_task == 'apply') {
  115. $session->set('seftools.redirect.id', $model->getState('id'));
  116. $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=splash&layout=edit', false), JText::_($msg));
  117. }
  118. else if ($this->_task == 'save2new') {
  119. $session->set('contentmanager.splash.id', null);
  120. $model->checkin($id);
  121. $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=splash&layout=edit', false), JText::_($msg));
  122. }
  123. else {
  124. $session->set('contentmanager.splash.id', null);
  125. $model->checkin($id);
  126. $this->setRedirect(JRoute::_('index.php?option=com_contentmanager&view=splashes', false), JText::_($msg));
  127. }
  128. }
  129. /**
  130. * Removes an item
  131. */
  132. function delete()
  133. {
  134. // Check for request forgeries
  135. JRequest::checkToken() or die('Invalid Token');
  136. // Get items to remove from the request.
  137. $cid = JRequest::getVar('cid', array(), '', 'array');
  138. if (!is_array($cid) || count($cid) < 1) {
  139. JError::raiseWarning(500, JText::_('Select an item to delete'));
  140. }
  141. else {
  142. // Get the model.
  143. $model = $this->getModel();
  144. // Make sure the item ids are integers
  145. jimport('joomla.utilities.arrayhelper');
  146. JArrayHelper::toInteger($cid);
  147. // Remove the items.
  148. if (!$model->delete($cid)) {
  149. JError::raiseWarning(500, $model->getError());
  150. }
  151. }
  152. $this->setRedirect('index.php?option=com_contentmanager&view=splashes');
  153. }
  154. /**
  155. * Method to publish a list of taxa
  156. *
  157. * @access public
  158. * @return void
  159. * @since 1.0
  160. */
  161. function publish()
  162. {
  163. // Check for request forgeries
  164. JRequest::checkToken() or die('Invalid Token');
  165. // Get items to publish from the request.
  166. $cid = JRequest::getVar('cid', array(), '', 'array');
  167. $values = array('publish' => 1, 'unpublish' => 0, 'trash' => -2);
  168. $task = $this->getTask();
  169. $value = JArrayHelper::getValue($values, $task, 0, 'int');
  170. if (!is_array($cid) || count($cid) < 1) {
  171. JError::raiseWarning(500, JText::_('Select an item to publish'));
  172. }
  173. else {
  174. // Get the model.
  175. $model = $this->getModel();
  176. // Make sure the item ids are integers
  177. JArrayHelper::toInteger($cid);
  178. // Publish the items.
  179. if (!$model->publish($cid, $value)) {
  180. JError::raiseWarning(500, $model->getError());
  181. }
  182. }
  183. $this->setRedirect('index.php?option=com_contentmanager&view=splashes');
  184. }
  185. /**
  186. * Changes the order of an item
  187. */
  188. function ordering()
  189. {
  190. // Check for request forgeries
  191. JRequest::checkToken() or die('Invalid Token');
  192. $cid = JRequest::getVar('cid', null, 'post', 'array');
  193. $inc = $this->getTask() == 'orderup' ? -1 : +1;
  194. $model = & $this->getModel();
  195. $model->ordering($cid, $inc);
  196. $this->setRedirect('index.php?option=com_contentmanager&view=splashes');
  197. }
  198. /**
  199. * Change or increment the access
  200. */
  201. function access()
  202. {
  203. // Check for request forgeries
  204. JRequest::checkToken() or die('Invalid Token');
  205. $cid = JRequest::getVar('cid', null, 'post', 'array');
  206. $level = JRequest::getVar('level', null, 'post');
  207. $model = & $this->getModel();
  208. $result = $model->access($cid, $level);
  209. if (JError::isError($result)) {
  210. $this->setMessage($result->getMessage());
  211. }
  212. else {
  213. $this->setMessage(JText::sprintf('Items updated', $result));
  214. }
  215. $this->setRedirect('index.php?option=com_contentmanager&view=splashes');
  216. }
  217. }