Advertisement
Guest User

Untitled

a guest
Jun 6th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.06 KB | None | 0 0
  1. <?php
  2. /**
  3. * Kunena Component
  4. * @package Kunena.Site
  5. * @subpackage Controllers
  6. *
  7. * @copyright (C) 2008 - 2012 Kunena Team. All rights reserved.
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  9. * @link http://www.kunena.org
  10. **/
  11. defined ( '_JEXEC' ) or die ();
  12.  
  13. require_once KPATH_SITE . '/lib/kunena.link.class.php';
  14.  
  15. /**
  16. * Kunena Topic Controller
  17. *
  18. * @since 2.0
  19. */
  20. class KunenaControllerTopic extends KunenaController {
  21. public function __construct($config = array()) {
  22. parent::__construct($config);
  23. $this->catid = JRequest::getInt('catid', 0);
  24. $this->return = JRequest::getInt('return', $this->catid);
  25. $this->id = JRequest::getInt('id', 0);
  26. $this->mesid = JRequest::getInt('mesid', 0);
  27. }
  28.  
  29. public function upload() {
  30. $upload = KunenaUpload::getInstance();
  31. $upload->ajaxUpload();
  32. }
  33.  
  34. public function post() {
  35. $this->id = JRequest::getInt('parentid', 0);
  36. $fields = array (
  37. 'catid' => $this->catid,
  38. 'name' => JRequest::getString ( 'authorname', $this->me->getName () ),
  39. 'email' => JRequest::getString ( 'email', null ),
  40. 'subject' => JRequest::getVar ( 'subject', null, 'POST', 'string', JREQUEST_ALLOWRAW ),
  41. 'message' => JRequest::getVar ( 'message', null, 'POST', 'string', JREQUEST_ALLOWRAW ),
  42. 'icon_id' => JRequest::getInt ( 'topic_emoticon', null ),
  43. 'anonymous' => JRequest::getInt ( 'anonymous', 0 ),
  44. 'poll_title' => JRequest::getString ( 'poll_title', '' ),
  45. 'poll_options' => JRequest::getVar('polloptionsID', array (), 'post', 'array'),
  46. 'poll_time_to_live' => JRequest::getString ( 'poll_time_to_live', 0 ),
  47. 'tags' => JRequest::getString ( 'tags', null ),
  48. 'mytags' => JRequest::getString ( 'mytags', null ),
  49. 'subscribe' => JRequest::getInt ( 'subscribeMe', 0 )
  50. );
  51. $this->app->setUserState('com_kunena.postfields', $fields);
  52.  
  53. if (! JRequest::checkToken ()) {
  54. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  55. $this->redirectBack ();
  56. }
  57.  
  58. $captcha = KunenaSpamRecaptcha::getInstance();
  59. if ($captcha->enabled()) {
  60. $success = $captcha->verify();
  61. if ( !$success ) {
  62. $this->app->enqueueMessage ( $captcha->getError(), 'error' );
  63. $this->redirectBack ();
  64. }
  65. }
  66.  
  67. if (!$this->id) {
  68. // Create topic
  69. $category = KunenaForumCategoryHelper::get($this->catid);
  70. if (!$category->authorise('topic.create')) {
  71. $this->app->enqueueMessage ( $category->getError(), 'notice' );
  72. $this->redirectBack ();
  73. }
  74. list ($topic, $message) = $category->newTopic($fields);
  75. } else {
  76. // Reply topic
  77. $parent = KunenaForumMessageHelper::get($this->id);
  78. if (!$parent->authorise('reply')) {
  79. $this->app->enqueueMessage ( $parent->getError(), 'notice' );
  80. $this->redirectBack ();
  81. }
  82. list ($topic, $message) = $parent->newReply($fields);
  83. $category = $topic->getCategory();
  84. }
  85.  
  86. // Flood protection
  87. if ($this->config->floodprotection && ! $this->me->isModerator($category)) {
  88. $timelimit = JFactory::getDate()->toUnix() - $this->config->floodprotection;
  89. $ip = $_SERVER ["REMOTE_ADDR"];
  90.  
  91. $db = JFactory::getDBO();
  92. $db->setQuery ( "SELECT COUNT(*) FROM #__kunena_messages WHERE ip={$db->Quote($ip)} AND time>{$db->quote($timelimit)}" );
  93. $count = $db->loadResult ();
  94. if (KunenaError::checkDatabaseError() || $count) {
  95. $this->app->enqueueMessage ( JText::sprintf ( 'COM_KUNENA_POST_TOPIC_FLOOD', $this->config->floodprotection) );
  96. $this->redirectBack ();
  97. }
  98. }
  99.  
  100. // Set topic icon if permitted
  101. if ($this->config->topicicons && isset($fields['icon_id']) && $topic->authorise('edit', null, false)) {
  102. $topic->icon_id = $fields['icon_id'];
  103. }
  104.  
  105. // Remove IP address
  106. // TODO: Add administrator tool to remove all tracked IP addresses (from the database)
  107. if (!$this->config->iptracking) {
  108. $message->ip = '';
  109. }
  110. // If requested: Make message to be anonymous
  111. if ($fields['anonymous'] && $message->getCategory()->allow_anonymous) {
  112. $message->makeAnonymous();
  113. }
  114.  
  115. // If configured: Hold posts from guests
  116. if ( !$this->me->userid && $this->config->hold_guest_posts) {
  117. $message->hold = 1;
  118. }
  119. // If configured: Hold posts from users
  120. if ( $this->me->userid && !$this->me->isModerator($category) && $this->me->posts < $this->config->hold_newusers_posts ) {
  121. $message->hold = 1;
  122. }
  123.  
  124. // Prevent user abort from this point in order to maintain data integrity.
  125. @ignore_user_abort(true);
  126.  
  127. // Upload new attachments
  128. foreach ($_FILES as $key=>$file) {
  129. $intkey = 0;
  130. if (preg_match('/\D*(\d+)/', $key, $matches))
  131. $intkey = (int)$matches[1];
  132. if ($file['error'] != UPLOAD_ERR_NO_FILE) $message->uploadAttachment($intkey, $key, $this->catid);
  133. }
  134.  
  135. // Activity integration
  136. $activity = KunenaFactory::getActivityIntegration();
  137. if ( $message->hold == 0 ) {
  138. if (!$topic->exists()) {
  139. $activity->onBeforePost($message);
  140. } else {
  141. $activity->onBeforeReply($message);
  142. }
  143. }
  144.  
  145. // Save message
  146. $success = $message->save ();
  147. if (! $success) {
  148. $this->app->enqueueMessage ( $message->getError (), 'error' );
  149. $this->redirectBack ();
  150. }
  151.  
  152. // Message has been sent, we can now clear saved form
  153. $this->app->setUserState('com_kunena.postfields', null);
  154.  
  155. // Display possible warnings (upload failed etc)
  156. foreach ( $message->getErrors () as $warning ) {
  157. $this->app->enqueueMessage ( $warning, 'notice' );
  158. }
  159.  
  160. // Create Poll
  161. $poll_title = $fields['poll_title'];
  162. $poll_options = $fields['poll_options'];
  163. if (! empty ( $poll_options ) && ! empty ( $poll_title )) {
  164. if ($topic->authorise('poll.create', null, false)) {
  165. $poll = $topic->getPoll();
  166. $poll->title = $poll_title;
  167. $poll->polltimetolive = $fields['poll_time_to_live'];
  168. $poll->setOptions($poll_options);
  169. if (!$poll->save()) {
  170. $this->app->enqueueMessage ( $poll->getError(), 'notice' );
  171. } else {
  172. $topic->poll_id = $poll->id;
  173. $topic->save();
  174. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POLL_CREATED' ) );
  175. }
  176. } else {
  177. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  178. }
  179. }
  180.  
  181. // Update Tags
  182. $this->updateTags($message->thread, $fields['tags'], $fields['mytags']);
  183.  
  184. $message->sendNotification();
  185.  
  186. //now try adding any new subscriptions if asked for by the poster
  187. $usertopic = $topic->getUserTopic();
  188. if ($fields['subscribe'] && !$usertopic->subscribed) {
  189. if ($topic->subscribe(1)) {
  190. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUBSCRIBED_TOPIC' ) );
  191.  
  192. // Activity integration
  193. $activity = KunenaFactory::getActivityIntegration();
  194. $activity->onAfterSubscribe($topic, 1);
  195. } else {
  196. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_NO_SUBSCRIBED_TOPIC' ) .' '. $topic->getError() );
  197. }
  198. }
  199.  
  200. if ($message->hold == 1) {
  201. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCES_REVIEW' ) );
  202. } else {
  203. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCESS_POSTED' ) );
  204. }
  205. $category = KunenaForumCategoryHelper::get($this->return);
  206. if ($message->authorise('read', null, false)) {
  207. $this->setRedirect ( $message->getUrl($category, false) );
  208. } elseif ($topic->authorise('read', null, false)) {
  209. $this->setRedirect ( $topic->getUrl($category, false) );
  210. } else {
  211. $this->setRedirect ( $category->getUrl(null, false) );
  212. }
  213. }
  214.  
  215. public function edit() {
  216. $this->id = JRequest::getInt('mesid', 0);
  217.  
  218. $message = KunenaForumMessageHelper::get($this->id);
  219. $topic = $message->getTopic();
  220. $fields = array (
  221. 'name' => JRequest::getString ( 'authorname', $message->name ),
  222. 'email' => JRequest::getString ( 'email', $message->email ),
  223. 'subject' => JRequest::getVar ( 'subject', $message->subject, 'POST', 'string', JREQUEST_ALLOWRAW ),
  224. 'message' => JRequest::getVar ( 'message', $message->message, 'POST', 'string', JREQUEST_ALLOWRAW ),
  225. 'modified_reason' => JRequest::getString ( 'modified_reason', $message->modified_reason ),
  226. 'icon_id' => JRequest::getInt ( 'topic_emoticon', $topic->icon_id ),
  227. 'anonymous' => JRequest::getInt ( 'anonymous', 0 ),
  228. 'poll_title' => JRequest::getString ( 'poll_title', null ),
  229. 'poll_options' => JRequest::getVar('polloptionsID', array (), 'post', 'array'),
  230. 'poll_time_to_live' => JRequest::getString ( 'poll_time_to_live', 0 ),
  231. 'tags' => JRequest::getString ( 'tags', null ),
  232. 'mytags' => JRequest::getString ( 'mytags', null )
  233. );
  234.  
  235. if (! JRequest::checkToken ()) {
  236. $this->app->setUserState('com_kunena.postfields', $fields);
  237. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  238. $this->redirectBack ();
  239. }
  240.  
  241. if (!$message->authorise('edit')) {
  242. $this->app->setUserState('com_kunena.postfields', $fields);
  243. $this->app->enqueueMessage ( $message->getError(), 'notice' );
  244. $this->redirectBack ();
  245. }
  246.  
  247. // Update message contents
  248. $message->edit ( $fields );
  249. // If requested: Make message to be anonymous
  250. if ($fields['anonymous'] && $message->getCategory()->allow_anonymous) {
  251. $message->makeAnonymous();
  252. }
  253.  
  254. // Mark attachments to be deleted
  255. $attachments = JRequest::getVar ( 'attachments', array(), 'post', 'array' );
  256. $attachkeeplist = JRequest::getVar ( 'attachment', array(), 'post', 'array' );
  257. $message->removeAttachment(array_keys(array_diff_key($attachments, $attachkeeplist)));
  258.  
  259. // Upload new attachments
  260. foreach ($_FILES as $key=>$file) {
  261. $intkey = 0;
  262. if (preg_match('/\D*(\d+)/', $key, $matches))
  263. $intkey = (int)$matches[1];
  264. if ($file['error'] != UPLOAD_ERR_NO_FILE) $message->uploadAttachment($intkey, $key, $this->catid);
  265. }
  266.  
  267. // Set topic icon if permitted
  268. if ($this->config->topicicons && isset($fields['icon_id']) && $topic->authorise('edit', null, false)) {
  269. $topic->icon_id = $fields['icon_id'];
  270. }
  271.  
  272. // Check if we are editing first post and update topic if we are!
  273. if ($topic->first_post_id == $message->id) {
  274. $topic->subject = $fields['subject'];
  275. }
  276.  
  277. // Activity integration
  278. $activity = KunenaFactory::getActivityIntegration();
  279. $activity->onBeforeEdit($message);
  280.  
  281. // Save message
  282. $success = $message->save ();
  283. if (! $success) {
  284. $this->app->setUserState('com_kunena.postfields', $fields);
  285. $this->app->enqueueMessage ( $message->getError (), 'error' );
  286. $this->redirectBack ();
  287. }
  288. // Display possible warnings (upload failed etc)
  289. foreach ( $message->getErrors () as $warning ) {
  290. $this->app->enqueueMessage ( $warning, 'notice' );
  291. }
  292.  
  293. $poll_title = $fields['poll_title'];
  294. if ($poll_title !== null) {
  295. // Save changes into poll
  296. $poll_options = $fields['poll_options'];
  297. $poll = $topic->getPoll();
  298. if (! empty ( $poll_options ) && ! empty ( $poll_title )) {
  299. $poll->title = $poll_title;
  300. $poll->polltimetolive = $fields['poll_time_to_live'];
  301. $poll->setOptions($poll_options);
  302. if (!$topic->poll_id) {
  303. // Create a new poll
  304. if (!$topic->authorise('poll.create')) {
  305. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  306. } elseif (!$poll->save()) {
  307. $this->app->enqueueMessage ( $poll->getError(), 'notice' );
  308. } else {
  309. $topic->poll_id = $poll->id;
  310. $topic->save();
  311. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POLL_CREATED' ) );
  312. }
  313. } else {
  314. // Edit existing poll
  315. if (!$topic->authorise('poll.edit')) {
  316. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  317. } elseif (!$poll->save()) {
  318. $this->app->enqueueMessage ( $poll->getError(), 'notice' );
  319. } else {
  320. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POLL_EDITED' ) );
  321. }
  322. }
  323. } elseif ($poll->exists() && $topic->authorise('poll.edit')) {
  324. // Delete poll
  325. if (!$topic->authorise('poll.delete')) {
  326. // Error: No permissions to delete poll
  327. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  328. } elseif (!$poll->delete()) {
  329. $this->app->enqueueMessage ( $poll->getError(), 'notice' );
  330. } else {
  331. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POLL_DELETED' ) );
  332. }
  333. }
  334. }
  335.  
  336. // Update Tags
  337. $this->updateTags($message->thread, $fields['tags'], $fields['mytags']);
  338.  
  339. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCESS_EDIT' ) );
  340. if ($message->hold == 1) {
  341. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_GEN_MODERATED' ) );
  342. }
  343. $this->app->redirect ( $message->getUrl($this->return, false ) );
  344. }
  345.  
  346. public function thankyou() {
  347. $type = JRequest::getString('task');
  348. $this->setThankyou($type);
  349.  
  350. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_THANKYOU_SUCCESS' ) );
  351. }
  352.  
  353. public function unthankyou() {
  354. $type = JRequest::getString('task');
  355. $this->setThankyou($type);
  356.  
  357. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_THANKYOU_REMOVED_SUCCESS' ) );
  358. }
  359.  
  360. protected function setThankyou($type){
  361. if (! JRequest::checkToken ('get')) {
  362. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  363. $this->redirectBack ();
  364. }
  365.  
  366. $message = KunenaForumMessageHelper::get($this->mesid);
  367. if (!$message->authorise($type)) {
  368. $this->app->enqueueMessage ( $message->getError() );
  369. $this->redirectBack ();
  370. }
  371.  
  372. $category = KunenaForumCategoryHelper::get($this->catid);
  373. $thankyou = KunenaForumMessageThankyouHelper::get($this->mesid);
  374. $activityIntegration = KunenaFactory::getActivityIntegration();
  375. if ( $type== 'thankyou') {
  376. if (!$thankyou->save ( $this->me )) {
  377. $this->app->enqueueMessage ( $thankyou->getError() );
  378. $this->redirectBack ();
  379. }
  380. $activityIntegration->onAfterThankyou($this->me->userid, $message->userid, $message);
  381. } else {
  382. $userid = JRequest::getInt('userid','0');
  383. if (!$thankyou->delete ( $userid )) {
  384. $this->app->enqueueMessage ( $thankyou->getError() );
  385. $this->redirectBack ();
  386. }
  387. $activityIntegration->onAfterUnThankyou($userid, $this->me->userid, $message);
  388. }
  389. $this->setRedirect($message->getUrl($category->exists() ? $category->id : $message->catid, false));
  390. }
  391.  
  392. public function subscribe() {
  393. if (! JRequest::checkToken ('get')) {
  394. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  395. $this->redirectBack ();
  396. }
  397.  
  398. $topic = KunenaForumTopicHelper::get($this->id);
  399. if ($topic->authorise('read') && $topic->subscribe(1)) {
  400. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUBSCRIBED_TOPIC' ) );
  401.  
  402. // Activity integration
  403. $activity = KunenaFactory::getActivityIntegration();
  404. $activity->onAfterSubscribe($topic, 1);
  405. } else {
  406. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_NO_SUBSCRIBED_TOPIC' ) .' '. $topic->getError(), 'notice' );
  407. }
  408. $this->redirectBack ();
  409. }
  410.  
  411. public function unsubscribe() {
  412. if (! JRequest::checkToken ('get')) {
  413. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  414. $this->redirectBack ();
  415. }
  416.  
  417. $topic = KunenaForumTopicHelper::get($this->id);
  418. if ($topic->authorise('read') && $topic->subscribe(0)) {
  419. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_UNSUBSCRIBED_TOPIC' ) );
  420.  
  421. // Activity integration
  422. $activity = KunenaFactory::getActivityIntegration();
  423. $activity->onAfterSubscribe($topic, 0);
  424. } else {
  425. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_NO_UNSUBSCRIBED_TOPIC' ) .' '. $topic->getError(), 'notice' );
  426. }
  427. $this->redirectBack ();
  428. }
  429.  
  430. public function favorite() {
  431. if (! JRequest::checkToken ('get')) {
  432. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  433. $this->redirectBack ();
  434. }
  435.  
  436. $topic = KunenaForumTopicHelper::get($this->id);
  437. if ($topic->authorise('read') && $topic->favorite(1)) {
  438. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_FAVORITED_TOPIC' ) );
  439.  
  440. // Activity integration
  441. $activity = KunenaFactory::getActivityIntegration();
  442. $activity->onAfterFavorite($topic, 1);
  443. } else {
  444. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_NO_FAVORITED_TOPIC' ) .' '. $topic->getError(), 'notice' );
  445. }
  446. $this->redirectBack ();
  447. }
  448.  
  449. public function unfavorite() {
  450. if (! JRequest::checkToken ('get')) {
  451. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  452. $this->redirectBack ();
  453. }
  454.  
  455. $topic = KunenaForumTopicHelper::get($this->id);
  456. if ($topic->authorise('read') && $topic->favorite(0)) {
  457. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_UNFAVORITED_TOPIC' ) );
  458.  
  459. // Activity integration
  460. $activity = KunenaFactory::getActivityIntegration();
  461. $activity->onAfterFavorite($topic, 0);
  462. } else {
  463. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_NO_UNFAVORITED_TOPIC' ) .' '. $topic->getError(), 'notice' );
  464. }
  465. $this->redirectBack ();
  466. }
  467.  
  468. public function sticky() {
  469. if (! JRequest::checkToken ('get')) {
  470. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  471. $this->redirectBack ();
  472. }
  473.  
  474. $topic = KunenaForumTopicHelper::get($this->id);
  475. if (!$topic->authorise('sticky')) {
  476. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  477. } elseif ($topic->sticky(1)) {
  478. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_STICKY_SET' ) );
  479.  
  480. // Activity integration
  481. $activity = KunenaFactory::getActivityIntegration();
  482. $activity->onAfterSticky($topic, 1);
  483. } else {
  484. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_STICKY_NOT_SET' ) );
  485. }
  486. $this->redirectBack ();
  487. }
  488.  
  489. public function unsticky() {
  490. if (! JRequest::checkToken ('get')) {
  491. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  492. $this->redirectBack ();
  493. }
  494.  
  495. $topic = KunenaForumTopicHelper::get($this->id);
  496. if (!$topic->authorise('sticky')) {
  497. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  498. } elseif ($topic->sticky(0)) {
  499. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_STICKY_UNSET' ) );
  500.  
  501. // Activity integration
  502. $activity = KunenaFactory::getActivityIntegration();
  503. $activity->onAfterSticky($topic, 0);
  504. } else {
  505. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_STICKY_NOT_UNSET' ) );
  506. }
  507. $this->redirectBack ();
  508. }
  509.  
  510. public function lock() {
  511. if (! JRequest::checkToken ('get')) {
  512. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  513. $this->redirectBack ();
  514. }
  515.  
  516. $topic = KunenaForumTopicHelper::get($this->id);
  517. if (!$topic->authorise('lock')) {
  518. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  519. } elseif ($topic->lock(1)) {
  520. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_LOCK_SET' ) );
  521.  
  522. // Activity integration
  523. $activity = KunenaFactory::getActivityIntegration();
  524. $activity->onAfterLock($topic, 1);
  525. } else {
  526. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_LOCK_NOT_SET' ) );
  527. }
  528. $this->redirectBack ();
  529. }
  530.  
  531. public function unlock() {
  532. if (! JRequest::checkToken ('get')) {
  533. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  534. $this->redirectBack ();
  535. }
  536.  
  537. $topic = KunenaForumTopicHelper::get($this->id);
  538. if (!$topic->authorise('lock')) {
  539. $this->app->enqueueMessage ( $topic->getError(), 'notice' );
  540. } elseif ($topic->lock(0)) {
  541. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_LOCK_UNSET' ) );
  542.  
  543. // Activity integration
  544. $activity = KunenaFactory::getActivityIntegration();
  545. $activity->onAfterLock($topic, 0);
  546. } else {
  547. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_LOCK_NOT_UNSET' ) );
  548. }
  549. $this->redirectBack ();
  550. }
  551.  
  552. public function delete() {
  553. if (! JRequest::checkToken ('get')) {
  554. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  555. $this->redirectBack ();
  556. }
  557.  
  558. if ($this->mesid) {
  559. // Delete message
  560. $target = KunenaForumMessageHelper::get($this->mesid);
  561. $hold = KunenaForum::DELETED;
  562. $msg = JText::_ ( 'COM_KUNENA_POST_SUCCESS_DELETE' );
  563. } else {
  564. // Delete topic
  565. $target = KunenaForumTopicHelper::get($this->id);
  566. $hold = KunenaForum::TOPIC_DELETED;
  567. $msg = JText::_ ( 'COM_KUNENA_TOPIC_SUCCESS_DELETE' );
  568. }
  569. if ($target->authorise('delete') && $target->publish($hold)) {
  570. $this->app->enqueueMessage ( $msg );
  571. } else {
  572. $this->app->enqueueMessage ( $target->getError(), 'notice' );
  573. }
  574. if (!$target->authorise('read')) {
  575. if ($target instanceof KunenaForumMessage && $target->getTopic()->authorise('read')) {
  576. $target = $target->getTopic();
  577. // TODO: need to get closest message
  578. $target = KunenaForumMessageHelper::get($target->last_post_id);
  579. } else {
  580. $target = $target->getCategory();
  581. }
  582. }
  583. $this->app->redirect ( $target->getUrl($this->return, false) );
  584. }
  585.  
  586. public function undelete() {
  587. if (! JRequest::checkToken ('get')) {
  588. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  589. $this->redirectBack ();
  590. }
  591.  
  592. if ($this->mesid) {
  593. // Undelete message
  594. $target = KunenaForumMessageHelper::get($this->mesid);
  595. $msg = JText::_ ( 'COM_KUNENA_POST_SUCCESS_UNDELETE' );
  596. } else {
  597. // Undelete topic
  598. $target = KunenaForumTopicHelper::get($this->id);
  599. $msg = JText::_ ( 'COM_KUNENA_TOPIC_SUCCESS_UNDELETE' );
  600. }
  601. if ($target->authorise('undelete') && $target->publish(KunenaForum::PUBLISHED)) {
  602. $this->app->enqueueMessage ( $msg );
  603. } else {
  604. $this->app->enqueueMessage ( $target->getError(), 'notice' );
  605. }
  606. $this->app->redirect ( $target->getUrl($this->return, false ) );
  607. }
  608.  
  609. public function permdelete() {
  610. if (! JRequest::checkToken ('get')) {
  611. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  612. $this->redirectBack ();
  613. }
  614.  
  615. if ($this->mesid) {
  616. // Delete message
  617. $target = KunenaForumMessageHelper::get($this->mesid);
  618. $topic = KunenaForumTopicHelper::get($target->getTopic());
  619. } else {
  620. // Delete topic
  621. $target = $topic = KunenaForumTopicHelper::get($this->id);
  622. }
  623. if ($target->authorise('permdelete') && $target->delete()) {
  624. if ($topic->exists()) {
  625. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCESS_DELETE' ) );
  626. $url = $topic->getUrl($this->return, false);
  627. } else {
  628. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_TOPIC_SUCCESS_DELETE' ) );
  629. $url = $topic->getCategory()->getUrl($this->return, false);
  630. }
  631. } else {
  632. $this->app->enqueueMessage ( $target->getError(), 'notice' );
  633. }
  634. $this->app->redirect ( $url );
  635. }
  636.  
  637. public function approve() {
  638. if (! JRequest::checkToken ('get')) {
  639. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  640. $this->redirectBack ();
  641. }
  642.  
  643. if ($this->mesid) {
  644. // Approve message
  645. $target = KunenaForumMessageHelper::get($this->mesid);
  646. } else {
  647. // Approve topic
  648. $target = KunenaForumTopicHelper::get($this->id);
  649. }
  650. if ($target->authorise('approve') && $target->publish(KunenaForum::PUBLISHED)) {
  651. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_MODERATE_APPROVE_SUCCESS' ) );
  652. $target->sendNotification();
  653. } else {
  654. $this->app->enqueueMessage ( $target->getError(), 'notice' );
  655. }
  656. $this->app->redirect ( $target->getUrl($this->return, false ) );
  657. }
  658.  
  659. public function move() {
  660. if (! JRequest::checkToken ()) {
  661. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  662. $this->redirectBack ();
  663. }
  664.  
  665. $topicId = JRequest::getInt('id', 0);
  666. $messageId = JRequest::getInt('mesid', 0);
  667. $targetTopic = JRequest::getInt ( 'targetid', JRequest::getInt ( 'targettopic', 0 ));
  668. $targetCategory = JRequest::getInt ( 'targetcategory', 0 );
  669.  
  670. if ($messageId) {
  671. $object = KunenaForumMessageHelper::get ( $messageId );
  672. $topic = $object->getTopic();
  673. } else {
  674. $object = KunenaForumTopicHelper::get ( $topicId );
  675. $topic = $object;
  676. }
  677. if ($targetTopic) {
  678. $target = KunenaForumTopicHelper::get( $targetTopic );
  679. } else {
  680. $target = KunenaForumCategoryHelper::get( $targetCategory );
  681. }
  682.  
  683. $error = null;
  684. if (!$object->authorise ( 'move' )) {
  685. $error = $object->getError();
  686. } elseif (!$target->authorise ( 'read' )) {
  687. $error = $target->getError();
  688. } else {
  689. $changesubject = JRequest::getBool ( 'changesubject', false );
  690. $subject = JRequest::getString ( 'subject', '' );
  691. $shadow = JRequest::getBool ( 'shadow', false );
  692. $topic_emoticon = JRequest::getInt ( 'topic_emoticon', null );
  693. if (!is_null($topic_emoticon)) $topic->icon_id = $topic_emoticon;
  694.  
  695. if ($object instanceof KunenaForumMessage) {
  696. $mode = JRequest::getWord ( 'mode', 'selected' );
  697. switch ($mode) {
  698. case 'newer':
  699. $ids = new JDate($object->time);
  700. break;
  701. case 'selected':
  702. default:
  703. $ids = $object->id;
  704. break;
  705. }
  706. } else {
  707. $ids = false;
  708. }
  709. $targetobject = $topic->move ( $target, $ids, $shadow, $subject, $changesubject );
  710. if (!$targetobject) {
  711. $error = $topic->getError();
  712. }
  713. }
  714. if ($error) {
  715. $this->app->enqueueMessage ( $error, 'notice' );
  716. } else {
  717. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCESS_MOVE' ) );
  718. }
  719. if ($targetobject) {
  720. $this->app->redirect ( $targetobject->getUrl($this->return, false, 'last' ) );
  721. } else {
  722. $this->app->redirect ( $topic->getUrl($this->return, false, 'first' ) );
  723. }
  724. }
  725.  
  726. function report() {
  727. if (! JRequest::checkToken ()) {
  728. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  729. $this->redirectBack ();
  730. }
  731.  
  732. if (!$this->me->exists() || $this->config->reportmsg == 0) {
  733. // Deny access if report feature has been disabled or user is guest
  734. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_NO_ACCESS' ), 'notice' );
  735. $this->redirectBack ();
  736. }
  737.  
  738. if (!$this->config->get('send_emails')) {
  739. // Emails have been disabled
  740. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_EMAIL_DISABLED' ), 'notice' );
  741. $this->redirectBack ();
  742. }
  743. jimport ( 'joomla.mail.helper' );
  744. if (! $this->config->getEmail() || ! JMailHelper::isEmailAddress ( $this->config->getEmail() )) {
  745. // Error: email address is invalid
  746. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_EMAIL_INVALID' ), 'error' );
  747. $this->redirectBack ();
  748. }
  749.  
  750. // Get target object for the report
  751. if ($this->mesid) {
  752. $message = $target = KunenaForumMessageHelper::get($this->mesid);
  753. $topic = $target->getTopic();
  754. } else {
  755. $topic = $target = KunenaForumTopicHelper::get($this->id);
  756. $message = KunenaForumMessageHelper::get($topic->first_post_id);
  757. }
  758. $messagetext = $message->message;
  759. $baduser = KunenaFactory::getUser($message->userid);
  760.  
  761. if (!$target->authorise('read')) {
  762. // Deny access if user cannot read target
  763. $this->app->enqueueMessage ( $target->getError(), 'notice' );
  764. $this->redirectBack ();
  765. }
  766. $category = $topic->getCategory();
  767.  
  768. $reason = JRequest::getString ( 'reason' );
  769. $text = JRequest::getString ( 'text' );
  770.  
  771. if (empty ( $reason ) && empty ( $text )) {
  772. // Do nothing: empty subject or reason is empty
  773. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_REPORT_FORG0T_SUB_MES' ) );
  774. $this->redirectBack ();
  775. } else {
  776. $acl = KunenaAccess::getInstance();
  777. $emailToList = $acl->getSubscribers($topic->category_id, $topic->id, false, true, false, $this->me->userid);
  778.  
  779. if (!empty ( $emailToList )) {
  780. $mailsender = JMailHelper::cleanAddress ( $this->config->board_title . ' ' . JText::_ ( 'COM_KUNENA_FORUM' ) . ': ' . $this->me->getName() );
  781. $mailsubject = "[" . $this->config->board_title . " " . JText::_ ( 'COM_KUNENA_FORUM' ) . "] " . JText::_ ( 'COM_KUNENA_REPORT_MSG' ) . ": ";
  782. if ($reason) {
  783. $mailsubject .= $reason;
  784. } else {
  785. $mailsubject .= $topic->subject;
  786. }
  787.  
  788. jimport ( 'joomla.environment.uri' );
  789. $msglink = JUri::getInstance()->toString(array('scheme', 'host', 'port')) . $target->getPermaUrl(null, false);
  790.  
  791. $mailmessage = "" . JText::_ ( 'COM_KUNENA_REPORT_RSENDER' ) . " {$this->me->username} ({$this->me->name})";
  792. $mailmessage .= "\n";
  793. $mailmessage .= "" . JText::_ ( 'COM_KUNENA_REPORT_RREASON' ) . " " . $reason;
  794. $mailmessage .= "\n";
  795. $mailmessage .= "" . JText::_ ( 'COM_KUNENA_REPORT_RMESSAGE' ) . " " . $text;
  796. $mailmessage .= "\n\n";
  797. $mailmessage .= "" . JText::_ ( 'COM_KUNENA_REPORT_POST_POSTER' ) . " {$baduser->username} ({$baduser->name})";
  798. $mailmessage .= "\n";
  799. $mailmessage .= "" . JText::_ ( 'COM_KUNENA_REPORT_POST_SUBJECT' ) . ": " . $topic->subject;
  800. $mailmessage .= "\n";
  801. $mailmessage .= "" . JText::_ ( 'COM_KUNENA_REPORT_POST_MESSAGE' ) . "\n-----\n" . KunenaHtmlParser::stripBBCode($messagetext, 0, false);
  802. $mailmessage .= "\n-----\n\n";
  803. $mailmessage .= "" . JText::_ ( 'COM_KUNENA_REPORT_POST_LINK' ) . " " . $msglink;
  804. $mailmessage = JMailHelper::cleanBody ( strtr ( $mailmessage, array ('&#32;' => '' ) ) );
  805.  
  806. foreach ( $emailToList as $emailTo ) {
  807. if (! $emailTo->email || ! JMailHelper::isEmailAddress ( $emailTo->email ))
  808. continue;
  809.  
  810. JUtility::sendMail ( $this->config->getEmail(), $mailsender, $emailTo->email, $mailsubject, $mailmessage );
  811. }
  812.  
  813. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_REPORT_SUCCESS' ) );
  814. } else {
  815. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_REPORT_NOT_SEND' ) );
  816. }
  817. }
  818. $this->app->redirect ( $target->getUrl($this->return, false) );
  819. }
  820.  
  821. protected function updateTags($topic, $globalTags, $userTags) {
  822. $topic = KunenaForumTopicHelper::get($topic);
  823. if ($userTags !== null) {
  824. $topic->setKeywords($userTags, $this->me->userid);
  825. }
  826. if ($globalTags !== null) {
  827. $topic->setKeywords($globalTags, false);
  828. }
  829. }
  830.  
  831. public function vote() {
  832. if (!JRequest::checkToken()) {
  833. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  834. $this->redirectBack ();
  835. }
  836.  
  837. $vote = JRequest::getInt('kpollradio', '');
  838. $id = JRequest::getInt ( 'id', 0 );
  839.  
  840. $topic = KunenaForumTopicHelper::get($id);
  841. $poll = $topic->getPoll();
  842. if (!$topic->authorise('poll.vote')) {
  843. $this->app->enqueueMessage ( $topic->getError(), 'error' );
  844. } elseif (!$this->config->pollallowvoteone || !$poll->getMyVotes()) {
  845. // Give a new vote
  846. $success = $poll->vote($vote);
  847. if ( !$success ) {
  848. $this->app->enqueueMessage ( $poll->getError(), 'error' );
  849. } else {
  850. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_TOPIC_VOTE_SUCCESS' ) );
  851. }
  852. } else {
  853. // Change existing vote
  854. $success = $poll->vote($vote, true);
  855. if ( !$success ) {
  856. $this->app->enqueueMessage ( $poll->getError(), 'error' );
  857. } else {
  858. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_TOPIC_VOTE_CHANGED_SUCCESS' ) );
  859. }
  860. }
  861. $this->app->redirect ( $topic->getUrl($this->return, false) );
  862. }
  863.  
  864. public function resetvotes() {
  865. if (!JRequest::checkToken('get')) {
  866. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  867. $this->redirectBack ();
  868. }
  869.  
  870. $pollid = JRequest::getInt ( 'pollid', 0 );
  871.  
  872. $topic = KunenaForumTopicHelper::get($this->id);
  873. $result = $topic->resetvotes($pollid);
  874.  
  875. $this->app->enqueueMessage ( JText::_ ( 'COM_KUNENA_TOPIC_VOTE_RESET_SUCCESS' ) );
  876. $this->app->redirect ( $topic->getUrl($this->return, false) );
  877. }
  878. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement