PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_easyblog/controllers/category.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 394 lines | 276 code | 81 blank | 37 comment | 26 complexity | 82f1389393f41bb8918f4734882fa201 MD5 | raw file
  1. <?php
  2. /**
  3. * @package EasyBlog
  4. * @copyright Copyright (C) 2010 Stack Ideas Private Limited. All rights reserved.
  5. * @license GNU/GPL, see LICENSE.php
  6. * EasyBlog is free software. This version may have been modified pursuant
  7. * to the GNU General Public License, and as distributed it includes or
  8. * is derivative of works licensed under the GNU General Public License or
  9. * other free or open source software licenses.
  10. * See COPYRIGHT.php for copyright notices and details.
  11. */
  12. defined('_JEXEC') or die('Restricted access');
  13. jimport('joomla.application.component.controller');
  14. class EasyBlogControllerCategory extends EasyBlogController
  15. {
  16. function __construct()
  17. {
  18. // @task: Check for acl rules.
  19. $this->checkAccess( 'category' );
  20. parent::__construct();
  21. $this->registerTask( 'add' , 'edit' );
  22. $this->registerTask( 'publish' , 'publish' );
  23. // In Joomla 3.0, it seems like we need to explicitly set unpublish
  24. $this->registerTask( 'unpublish' , 'unpublish' );
  25. $this->registerTask( 'orderup' , 'orderup' );
  26. $this->registerTask( 'orderdown' , 'orderdown' );
  27. }
  28. function hi()
  29. {
  30. var_dump( 'hi' );exit;
  31. }
  32. function orderdown()
  33. {
  34. // Check for request forgeries
  35. JRequest::checkToken() or jexit( 'Invalid Token' );
  36. EasyBlogControllerCategory::orderCategory(1);
  37. }
  38. function orderup()
  39. {
  40. // Check for request forgeries
  41. JRequest::checkToken() or jexit( 'Invalid Token' );
  42. EasyBlogControllerCategory::orderCategory(-1);
  43. }
  44. function orderCategory( $direction )
  45. {
  46. // Check for request forgeries
  47. JRequest::checkToken() or jexit( 'Invalid Token' );
  48. // @task: Check for acl rules.
  49. $this->checkAccess( 'category' );
  50. $mainframe = JFactory::getApplication();
  51. // Initialize variables
  52. $db = EasyBlogHelper::db();
  53. $cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
  54. if (isset( $cid[0] ))
  55. {
  56. $row = EasyBlogHelper::getTable('Category', 'Table');
  57. $row->load( (int) $cid[0] );
  58. $row->move($direction);
  59. }
  60. $mainframe->redirect( 'index.php?option=com_easyblog&view=categories');
  61. exit;
  62. }
  63. function saveOrder()
  64. {
  65. // Check for request forgeries
  66. JRequest::checkToken() or jexit( 'Invalid Token' );
  67. // @task: Check for acl rules.
  68. $this->checkAccess( 'category' );
  69. $mainframe = JFactory::getApplication();
  70. $row = EasyBlogHelper::getTable('Category', 'Table');
  71. $row->rebuildOrdering();
  72. $message = JText::_('COM_EASYBLOG_CATEGORIES_ORDERING_SAVED');
  73. $type = 'message';
  74. $mainframe->redirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  75. exit;
  76. }
  77. function save()
  78. {
  79. // Check for request forgeries
  80. JRequest::checkToken() or jexit( 'Invalid Token' );
  81. // @task: Check for acl rules.
  82. $this->checkAccess( 'category' );
  83. $mainframe = JFactory::getApplication();
  84. $message = '';
  85. $type = 'message';
  86. if( JRequest::getMethod() == 'POST' )
  87. {
  88. $post = JRequest::get( 'post' );
  89. if(empty($post['title']))
  90. {
  91. $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_CATEGORIES_INVALID_CATEGORY'), 'error');
  92. $url = 'index.php?option=com_easyblog&view=category';
  93. $mainframe->redirect(JRoute::_($url, false));
  94. return;
  95. }
  96. $category = EasyBlogHelper::getTable( 'Category', 'Table' );
  97. $user = JFactory::getUser();
  98. if( !isset( $post['created_by'] ) || empty( $post['created_by'] ) )
  99. {
  100. $post['created_by'] = $user->id;
  101. }
  102. $post['description'] = JRequest::getVar( 'description' , '' , 'REQUEST' , 'none' , JREQUEST_ALLOWHTML );
  103. $catId = JRequest::getVar( 'catid' , '' );
  104. $isNew = (empty($catId)) ? true : false;
  105. if( !empty( $catId ) )
  106. {
  107. $category->load( $catId );
  108. }
  109. $category->bind( $post );
  110. if (!$category->store())
  111. {
  112. JError::raiseError(500, $category->getError() );
  113. }
  114. else
  115. {
  116. //save the category acl
  117. $category->deleteACL();
  118. if($category->private == CATEGORY_PRIVACY_ACL)
  119. {
  120. $category->saveACL( $post );
  121. }
  122. // AlphaUserPoints
  123. // since 1.2
  124. if ( $isNew && EasyBlogHelper::isAUPEnabled() )
  125. {
  126. AlphaUserPointsHelper::newpoints( 'plgaup_easyblog_add_category', '', 'easyblog_add_category_' . $category->id, JText::sprintf('AUP NEW CATEGORY CREATED', $post['title']) );
  127. }
  128. $file = JRequest::getVar( 'Filedata', '', 'files', 'array' );
  129. if(! empty($file['name']))
  130. {
  131. $newAvatar = EasyBlogHelper::uploadCategoryAvatar($category, true);
  132. $category->avatar = $newAvatar;
  133. $category->store(); //now update the avatar.
  134. }
  135. $message = JText::_( 'COM_EASYBLOG_CATEGORIES_SAVED_SUCCESS' );
  136. }
  137. }
  138. else
  139. {
  140. $message = JText::_('COM_EASYBLOG_INVALID_REQUEST');
  141. $type = 'error';
  142. }
  143. // Redirect to new form once again if necessary
  144. $saveNew = JRequest::getInt( 'savenew' , 0 );
  145. if( $saveNew )
  146. {
  147. $mainframe->redirect( 'index.php?option=com_easyblog&view=category' , $message , $type );
  148. $mainframe->close();
  149. }
  150. $mainframe->redirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  151. }
  152. function cancel()
  153. {
  154. // @task: Check for acl rules.
  155. $this->checkAccess( 'category' );
  156. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' );
  157. return;
  158. }
  159. function edit()
  160. {
  161. // @task: Check for acl rules.
  162. $this->checkAccess( 'category' );
  163. $catId = JRequest::getInt( 'catid' );
  164. if( $catId )
  165. {
  166. $catId = '&catid=' . $catId;
  167. }
  168. else
  169. {
  170. $catId = '';
  171. }
  172. $this->setRedirect( 'index.php?option=com_easyblog&view=category' . $catId );
  173. }
  174. function remove()
  175. {
  176. // Check for request forgeries
  177. JRequest::checkToken() or jexit( 'Invalid Token' );
  178. // @task: Check for acl rules.
  179. $this->checkAccess( 'category' );
  180. $categories = JRequest::getVar( 'cid' , '' , 'POST' );
  181. $message = '';
  182. $type = 'info';
  183. if( empty( $categories ) )
  184. {
  185. $message = JText::_('COM_EASYBLOG_CATEGORIES_INVALID_CATEGORY');
  186. $type = 'error';
  187. }
  188. else
  189. {
  190. $table = EasyBlogHelper::getTable( 'Category' , 'Table' );
  191. foreach( $categories as $category )
  192. {
  193. $table->load( $category );
  194. if($table->getPostCount())
  195. {
  196. $message = JText::sprintf('COM_EASYBLOG_CATEGORIES_DELETE_ERROR_POST_NOT_EMPTY', $table->title);
  197. $type = 'error';
  198. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  199. return;
  200. }
  201. if($table->getChildCount())
  202. {
  203. $message = JText::sprintf('COM_EASYBLOG_CATEGORIES_DELETE_ERROR_CHILD_NOT_EMPTY', $table->title);
  204. $type = 'error';
  205. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  206. return;
  207. }
  208. if( !$table->delete() )
  209. {
  210. $message = JText::_( 'COM_EASYBLOG_CATEGORIES_DELETE_ERROR' );
  211. $type = 'error';
  212. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  213. return;
  214. }
  215. else
  216. {
  217. // AlphaUserPoints
  218. // since 1.2
  219. if ( EasyBlogHelper::isAUPEnabled() )
  220. {
  221. $aupid = AlphaUserPointsHelper::getAnyUserReferreID( $table->created_by );
  222. AlphaUserPointsHelper::newpoints( 'plgaup_easyblog_delete_category', $aupid, '', JText::sprintf('AUP CATEGORY DELETED', $table->title) );
  223. }
  224. }
  225. }
  226. $message = JText::_('COM_EASYBLOG_CATEGORIES_DELETE_SUCCESS');
  227. }
  228. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  229. }
  230. public function publish()
  231. {
  232. // Check for request forgeries
  233. JRequest::checkToken() or jexit( 'Invalid Token' );
  234. // @task: Check for acl rules.
  235. $this->checkAccess( 'category' );
  236. $categories = JRequest::getVar( 'cid' , array(0) , 'POST' );
  237. $message = '';
  238. $type = 'message';
  239. if( count( $categories ) <= 0 )
  240. {
  241. $message = JText::_('COM_EASYBLOG_CATEGORIES_INVALID_CATEGORY');
  242. $type = 'error';
  243. }
  244. else
  245. {
  246. $model = $this->getModel( 'Categories' );
  247. if( $model->publish( $categories , 1 ) )
  248. {
  249. $message = JText::_('COM_EASYBLOG_CATEGORIES_PUBLISHED_SUCCESS');
  250. }
  251. else
  252. {
  253. $message = JText::_('COM_EASYBLOG_CATEGORIES_PUBLISHED_ERROR');
  254. $type = 'error';
  255. }
  256. }
  257. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  258. }
  259. public function unpublish()
  260. {
  261. // Check for request forgeries
  262. JRequest::checkToken() or jexit( 'Invalid Token' );
  263. // @task: Check for acl rules.
  264. $this->checkAccess( 'category' );
  265. $categories = JRequest::getVar( 'cid' , array(0) , 'POST' );
  266. $message = '';
  267. $type = 'message';
  268. if( count( $categories ) <= 0 )
  269. {
  270. $message = JText::_('COM_EASYBLOG_CATEGORIES_INVALID_CATEGORY');
  271. $type = 'error';
  272. }
  273. else
  274. {
  275. $model = $this->getModel( 'Categories' );
  276. if( $model->publish( $categories , 0 ) )
  277. {
  278. $message = JText::_('COM_EASYBLOG_CATEGORIES_UNPUBLISHED_SUCCESS');
  279. }
  280. else
  281. {
  282. $message = JText::_('COM_EASYBLOG_CATEGORIES_UNPUBLISHED_ERROR');
  283. $type = 'error';
  284. }
  285. }
  286. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  287. }
  288. function makeDefault()
  289. {
  290. $cid = JRequest::getVar( 'cid' );
  291. $message = '';
  292. $type = 'message';
  293. // @task: Check for acl rules.
  294. $this->checkAccess( 'category' );
  295. if( empty( $cid ) )
  296. {
  297. $message = JText::_('COM_EASYBLOG_CATEGORIES_INVALID_CATEGORY');
  298. $type = 'error';
  299. }
  300. else
  301. {
  302. //reset the other prevous defaulted category.
  303. $model = $this->getModel( 'Categories' );
  304. $model->resetDefault();
  305. $category = EasyBlogHelper::getTable( 'Category' );
  306. $category->load( $cid );
  307. $category->default = ( $category->default == '0' ) ? '1' : '0' ;
  308. $category->store();
  309. $message = JText::_('COM_EASYBLOG_CATEGORIES_MARKED_AS_DEFAULT');
  310. }
  311. $this->setRedirect( 'index.php?option=com_easyblog&view=categories' , $message , $type );
  312. }
  313. }