PageRenderTime 53ms CodeModel.GetById 7ms RepoModel.GetById 0ms app.codeStats 1ms

/com_flexicontent_v2.x/admin/controllers/categories.php

http://flexicontent.googlecode.com/
PHP | 403 lines | 219 code | 47 blank | 137 comment | 39 complexity | 6a88a1825d2ca0451de812fff6b5fcd0 MD5 | raw file
Possible License(s): MIT, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @version 1.5 stable $Id: categories.php 1614 2013-01-04 03:57:15Z ggppdk $
  4. * @package Joomla
  5. * @subpackage FLEXIcontent
  6. * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr
  7. * @license GNU/GPL v2
  8. *
  9. * FLEXIcontent is a derivative work of the excellent QuickFAQ component
  10. * @copyright (C) 2008 Christoph Lukes
  11. * see www.schlu.net for more information
  12. *
  13. * FLEXIcontent is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. defined( '_JEXEC' ) or die( 'Restricted access' );
  19. jimport('joomla.application.component.controlleradmin');
  20. /**
  21. * FLEXIcontent Component Categories Controller
  22. *
  23. * @package Joomla
  24. * @subpackage FLEXIcontent
  25. * @since 1.0
  26. */
  27. class FlexicontentControllerCategories extends JControllerAdmin
  28. {
  29. /**
  30. * Constructor
  31. *
  32. * @since 1.0
  33. */
  34. function __construct()
  35. {
  36. if (FLEXI_J16GE) {
  37. $this->text_prefix = 'com_content';
  38. }
  39. parent::__construct();
  40. // Register Extra task
  41. $this->registerTask( 'add', 'edit' );
  42. $this->registerTask( 'apply', 'save' );
  43. $this->registerTask( 'saveandnew', 'save' );
  44. if (!FLEXI_J16GE) {
  45. $this->registerTask( 'accesspublic', 'access' );
  46. $this->registerTask( 'accessregistered', 'access' );
  47. $this->registerTask( 'accessspecial', 'access' );
  48. }
  49. $this->registerTask( 'params', 'params' );
  50. $this->registerTask( 'orderdown', 'orderdown' );
  51. $this->registerTask( 'orderup', 'orderup' );
  52. $this->registerTask( 'saveorder', 'saveorder' );
  53. }
  54. /**
  55. * Logic to save a category
  56. *
  57. * @access public
  58. * @return void
  59. * @since 1.0
  60. */
  61. function save()
  62. {
  63. // Check for request forgeries
  64. JRequest::checkToken() or jexit( 'Invalid Token' );
  65. parent::save();
  66. $cache = JFactory::getCache('com_flexicontent');
  67. $cache->clean();
  68. $catscache = JFactory::getCache('com_flexicontent_cats');
  69. $catscache->clean();
  70. }
  71. /**
  72. * Check in a record
  73. *
  74. * @since 1.5
  75. */
  76. function checkin()
  77. {
  78. $tbl = 'flexicontent_categories';
  79. $redirect_url = 'index.php?option=com_flexicontent&view=categories';
  80. flexicontent_db::checkin($tbl, $redirect_url, $this);
  81. return;// true;
  82. }
  83. /**
  84. * Logic to publish categories
  85. *
  86. * @access public
  87. * @return void
  88. * @since 1.0
  89. */
  90. function publish()
  91. {
  92. if (FLEXI_J16GE) parent::publish();
  93. else self::changestate(1);
  94. }
  95. /**
  96. * Logic to unpublish categories
  97. *
  98. * @access public
  99. * @return void
  100. * @since 1.0
  101. */
  102. function unpublish()
  103. {
  104. if (FLEXI_J16GE) parent::unpublish();
  105. else self::changestate(0);
  106. }
  107. /**
  108. * Logic to unpublish categories
  109. *
  110. * @access public
  111. * @return void
  112. * @since 1.0
  113. */
  114. function changestate($state=1)
  115. {
  116. // Check for request forgeries
  117. JRequest::checkToken() or jexit( 'Invalid Token' );
  118. $user = JFactory::getUser();
  119. if (FLEXI_J16GE) {
  120. $perms = FlexicontentHelperPerm::getPerm();
  121. $CanCats = $perms->CanCats;
  122. } else if (FLEXI_ACCESS) {
  123. $CanCats = ($user->gid < 25) ? FAccess::checkComponentAccess('com_flexicontent', 'categories', 'users', $user->gmid) : 1;
  124. } else {
  125. $CanCats = 1;
  126. }
  127. $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
  128. $msg = '';
  129. if (!is_array( $cid ) || count( $cid ) < 1)
  130. {
  131. // no category selected
  132. JError::raiseWarning(500, JText::_( $state ? 'FLEXI_SELECT_ITEM_PUBLISH' : 'FLEXI_SELECT_ITEM_UNPUBLISH' ) );
  133. }
  134. else if (!$CanCats)
  135. {
  136. // no access rights
  137. JError::raiseWarning(500, JText::_( 'FLEXI_ALERTNOTAUTH_TASK' ) );
  138. }
  139. else
  140. {
  141. // try to change state
  142. $model = $this->getModel('categories');
  143. if( !$model->publish($cid, $state) ) {
  144. JError::raiseWarning(500, $model->getError());
  145. $this->setRedirect( 'index.php?option=com_flexicontent&view=categories', $msg );
  146. return;
  147. }
  148. // set message
  149. $msg = $state ? JText::_( 'FLEXI_CATEGORY_PUBLISHED') : JText::_( 'FLEXI_CATEGORY_UNPUBLISHED' );
  150. // clean cache
  151. $cache = JFactory::getCache('com_flexicontent');
  152. $cache->clean();
  153. $catscache = JFactory::getCache('com_flexicontent_cats');
  154. $catscache->clean();
  155. }
  156. // redirect to categories management tab
  157. $this->setRedirect( 'index.php?option=com_flexicontent&view=categories', $msg );
  158. }
  159. /**
  160. * Logic to orderup a category
  161. *
  162. * @access public
  163. * @return void;
  164. * @since 1.0
  165. */
  166. function orderup()
  167. {
  168. // Check for request forgeries
  169. JRequest::checkToken() or jexit( 'Invalid Token' );
  170. $model = $this->getModel('categories');
  171. $model->move(-1);
  172. $cache = JFactory::getCache('com_flexicontent');
  173. $cache->clean();
  174. $catscache = JFactory::getCache('com_flexicontent_cats');
  175. $catscache->clean();
  176. $this->setRedirect( 'index.php?option=com_flexicontent&view=categories');
  177. }
  178. /**
  179. * Logic to orderdown a category
  180. *
  181. * @access public
  182. * @return void
  183. * @since 1.0
  184. */
  185. function orderdown()
  186. {
  187. // Check for request forgeries
  188. JRequest::checkToken() or jexit( 'Invalid Token' );
  189. $model = $this->getModel('categories');
  190. $model->move(1);
  191. $cache = JFactory::getCache('com_flexicontent');
  192. $cache->clean();
  193. $catscache = JFactory::getCache('com_flexicontent_cats');
  194. $catscache->clean();
  195. $this->setRedirect( 'index.php?option=com_flexicontent&view=categories');
  196. }
  197. /**
  198. * Logic to saver order of multiple categories at once
  199. *
  200. * @access public
  201. * @return void
  202. * @since 1.0
  203. */
  204. function saveorder()
  205. {
  206. // Check for request forgeries
  207. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  208. // Get the arrays from the Request
  209. $order = JRequest::getVar('order', null, 'post', 'array');
  210. $originalOrder = explode(',', JRequest::getString('original_order_values'));
  211. // Make sure something has changed
  212. if (!($order === $originalOrder)) {
  213. parent::saveorder();
  214. } else {
  215. // Nothing to reorder
  216. $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false), 'Nothing to reorder');
  217. }
  218. // clean cache
  219. $cache = JFactory::getCache('com_flexicontent');
  220. $cache->clean();
  221. $catscache = JFactory::getCache('com_flexicontent_cats');
  222. $catscache->clean();
  223. }
  224. /**
  225. * Logic to delete categories
  226. *
  227. * @access public
  228. * @return void
  229. * @since 1.0
  230. */
  231. function remove()
  232. {
  233. // Check for request forgeries
  234. JRequest::checkToken() or jexit( 'Invalid Token' );
  235. $user = JFactory::getUser();
  236. if (FLEXI_J16GE) {
  237. $perms = FlexicontentHelperPerm::getPerm();
  238. $CanCats = $perms->CanCats;
  239. } else if (FLEXI_ACCESS) {
  240. $CanCats = ($user->gid < 25) ? FAccess::checkComponentAccess('com_flexicontent', 'categories', 'users', $user->gmid) : 1;
  241. } else {
  242. $CanCats = 1;
  243. }
  244. $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
  245. $msg = '';
  246. if (!is_array( $cid ) || count( $cid ) < 1)
  247. {
  248. // no category selected
  249. JError::raiseWarning(500, JText::_( 'FLEXI_SELECT_ITEM_DELETE' ) );
  250. }
  251. else if (!$CanCats)
  252. {
  253. // no access rights
  254. JError::raiseWarning(500, JText::_( 'FLEXI_ALERTNOTAUTH_TASK' ) );
  255. }
  256. else
  257. {
  258. // try to delete the category and clean cache
  259. $model = $this->getModel('categories');
  260. $msg = $model->delete($cid);
  261. if (!$msg) {
  262. JError::raiseWarning(500, $model->getError());
  263. $this->setRedirect( 'index.php?option=com_flexicontent&view=categories', $msg );
  264. return;
  265. }
  266. // clean cache
  267. $cache = JFactory::getCache('com_flexicontent');
  268. $cache->clean();
  269. $catscache = JFactory::getCache('com_flexicontent_cats');
  270. $catscache->clean();
  271. }
  272. // redirect to categories management tab
  273. $this->setRedirect( 'index.php?option=com_flexicontent&view=categories', $msg );
  274. }
  275. /**
  276. * logic for cancel an action
  277. *
  278. * @access public
  279. * @return void
  280. * @since 1.0
  281. */
  282. function cancel()
  283. {
  284. // Check for request forgeries
  285. JRequest::checkToken() or jexit( 'Invalid Token' );
  286. $post = JRequest::get('post');
  287. $post = FLEXI_J16GE ? $post['jform'] : $post;
  288. JRequest::setVar('cid', $post['id']);
  289. $this->checkin();
  290. }
  291. /**
  292. * Logic to set the category access level
  293. *
  294. * @access public
  295. * @return void
  296. * @since 1.0
  297. */
  298. function access( )
  299. {
  300. // Check for request forgeries
  301. JRequest::checkToken() or jexit( 'Invalid Token' );
  302. $user = JFactory::getUser();
  303. $task = JRequest::getVar( 'task' );
  304. $model = $this->getModel('categories');
  305. $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
  306. $id = (int)$cid[0];
  307. // Get new category access
  308. if (FLEXI_J16GE) {
  309. $accesses = JRequest::getVar( 'access', array(0), 'post', 'array' );
  310. $access = $accesses[$id];
  311. } else {
  312. if ($task == 'accesspublic') {
  313. $access = 0;
  314. } elseif ($task == 'accessregistered') {
  315. $access = 1;
  316. } else {
  317. if (FLEXI_ACCESS) {
  318. $access = 3;
  319. } else {
  320. $access = 2;
  321. }
  322. }
  323. }
  324. // Check authorization for access setting task
  325. if (FLEXI_J16GE) {
  326. $is_authorised = $user->authorise('core.edit', 'com_content.category.'.$id);
  327. }else {
  328. $is_authorised = 1;
  329. }
  330. if (!$is_authorised) {
  331. // no access rights
  332. JError::raiseWarning(500, JText::_( 'FLEXI_ALERTNOTAUTH_TASK' ) );
  333. } else if(!$model->saveaccess( $id, $access )) {
  334. JError::raiseWarning(500, $model->getError());
  335. } else {
  336. $cache = JFactory::getCache('com_flexicontent');
  337. $cache->clean();
  338. $catscache = JFactory::getCache('com_flexicontent_cats');
  339. $catscache->clean();
  340. }
  341. $this->setRedirect('index.php?option=com_flexicontent&view=categories' );
  342. }
  343. /**
  344. * Override getModel function to return the customized categories
  345. *
  346. * @access public
  347. * @return void
  348. * @since 1.0
  349. */
  350. function getModel()
  351. {
  352. require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'categories.php');
  353. $model = new FlexicontentModelCategories();
  354. return $model;
  355. }
  356. }