/library/XenForo/ControllerPublic/InlineMod/Thread.php

https://github.com/Vernice238/DTUI_201105 · PHP · 337 lines · 224 code · 44 blank · 69 comment · 26 complexity · 4f5981559e7edc442b651b099bad0e86 MD5 · raw file

  1. <?php
  2. /**
  3. * Inline moderation actions for threads
  4. *
  5. * @package XenForo_Thread
  6. */
  7. class XenForo_ControllerPublic_InlineMod_Thread extends XenForo_ControllerPublic_InlineMod_Abstract
  8. {
  9. /**
  10. * Key for inline mod data.
  11. *
  12. * @var string
  13. */
  14. public $inlineModKey = 'threads';
  15. /**
  16. * @return XenForo_Model_InlineMod_Thread
  17. */
  18. public function getInlineModTypeModel()
  19. {
  20. return $this->getModelFromCache('XenForo_Model_InlineMod_Thread');
  21. }
  22. /**
  23. * Thread deletion handler.
  24. *
  25. * @return XenForo_ControllerResponse_Abstract
  26. */
  27. public function actionDelete()
  28. {
  29. if ($this->isConfirmedPost())
  30. {
  31. $threadIds = $this->getInlineModIds(false);
  32. $hardDelete = $this->_input->filterSingle('hard_delete', XenForo_Input::STRING);
  33. $options = array(
  34. 'deleteType' => ($hardDelete ? 'hard' : 'soft'),
  35. 'reason' => $this->_input->filterSingle('reason', XenForo_Input::STRING)
  36. );
  37. $deleted = $this->_getInlineModThreadModel()->deleteThreads(
  38. $threadIds, $options, $errorPhraseKey
  39. );
  40. if (!$deleted)
  41. {
  42. throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
  43. }
  44. $this->clearCookie();
  45. return $this->responseRedirect(
  46. XenForo_ControllerResponse_Redirect::SUCCESS,
  47. $this->getDynamicRedirect(false, false)
  48. );
  49. }
  50. else // show confirmation dialog
  51. {
  52. $threadIds = $this->getInlineModIds();
  53. $handler = $this->_getInlineModThreadModel();
  54. if (!$handler->canDeleteThreads($threadIds, 'soft', $errorPhraseKey))
  55. {
  56. throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
  57. }
  58. $redirect = $this->getDynamicRedirect();
  59. if (!$threadIds)
  60. {
  61. return $this->responseRedirect(
  62. XenForo_ControllerResponse_Redirect::SUCCESS,
  63. $redirect
  64. );
  65. }
  66. $viewParams = array(
  67. 'threadIds' => $threadIds,
  68. 'threadCount' => count($threadIds),
  69. 'canHardDelete' => $handler->canDeleteThreads($threadIds, 'hard'),
  70. 'redirect' => $redirect,
  71. );
  72. return $this->responseView('XenForo_ViewPublic_InlineMod_Thread_Delete', 'inline_mod_thread_delete', $viewParams);
  73. }
  74. }
  75. /**
  76. * Undeletes the specified threads.
  77. *
  78. * @return XenForo_ControllerResponse_Abstract
  79. */
  80. public function actionUndelete()
  81. {
  82. return $this->executeInlineModAction('undeleteThreads');
  83. }
  84. /**
  85. * Approves the specified threads.
  86. *
  87. * @return XenForo_ControllerResponse_Abstract
  88. */
  89. public function actionApprove()
  90. {
  91. return $this->executeInlineModAction('approveThreads');
  92. }
  93. /**
  94. * Unapproves the specified threads.
  95. *
  96. * @return XenForo_ControllerResponse_Abstract
  97. */
  98. public function actionUnapprove()
  99. {
  100. return $this->executeInlineModAction('unapproveThreads');
  101. }
  102. /**
  103. * Lock the specified threads.
  104. *
  105. * @return XenForo_ControllerResponse_Abstract
  106. */
  107. public function actionLock()
  108. {
  109. return $this->executeInlineModAction('lockThreads');
  110. }
  111. /**
  112. * Unlock the specified threads.
  113. *
  114. * @return XenForo_ControllerResponse_Abstract
  115. */
  116. public function actionUnlock()
  117. {
  118. return $this->executeInlineModAction('unlockThreads');
  119. }
  120. /**
  121. * Stick the specified threads.
  122. *
  123. * @return XenForo_ControllerResponse_Abstract
  124. */
  125. public function actionStick()
  126. {
  127. return $this->executeInlineModAction('stickThreads');
  128. }
  129. /**
  130. * Unstick the specified threads.
  131. *
  132. * @return XenForo_ControllerResponse_Abstract
  133. */
  134. public function actionUnstick()
  135. {
  136. return $this->executeInlineModAction('unstickThreads');
  137. }
  138. /**
  139. * Thread move handler
  140. *
  141. * @return XenForo_ControllerResponse_Abstract
  142. */
  143. public function actionMove()
  144. {
  145. if ($this->isConfirmedPost())
  146. {
  147. $threadIds = $this->getInlineModIds(false);
  148. $input = $this->_input->filter(array(
  149. 'node_id' => XenForo_Input::UINT,
  150. 'create_redirect' => XenForo_Input::STRING,
  151. 'redirect_ttl_value' => XenForo_Input::UINT,
  152. 'redirect_ttl_unit' => XenForo_Input::STRING
  153. ));
  154. $viewableNodes = $this->getModelFromCache('XenForo_Model_Node')->getViewableNodeList();
  155. if (isset($viewableNodes[$input['node_id']]))
  156. {
  157. $targetNode = $viewableNodes[$input['node_id']];
  158. }
  159. else
  160. {
  161. return $this->responseNoPermission();
  162. }
  163. if ($input['create_redirect'] == 'permanent')
  164. {
  165. $options = array('redirect' => true, 'redirectExpiry' => 0);
  166. }
  167. else if ($input['create_redirect'] == 'expiring')
  168. {
  169. $expiryDate = strtotime('+' . $input['redirect_ttl_value'] . ' ' . $input['redirect_ttl_unit']);
  170. $options = array('redirect' => true, 'redirectExpiry' => $expiryDate);
  171. }
  172. else
  173. {
  174. $options = array('redirect' => false);
  175. }
  176. if (!$this->_getInlineModThreadModel()->moveThreads($threadIds, $input['node_id'], $options, $errorPhraseKey))
  177. {
  178. throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
  179. }
  180. $this->clearCookie();
  181. return $this->responseRedirect(
  182. XenForo_ControllerResponse_Redirect::SUCCESS,
  183. XenForo_Link::buildPublicLink('forums', $targetNode)
  184. );
  185. }
  186. else // show confirmation dialog
  187. {
  188. $threadIds = $this->getInlineModIds();
  189. $handler = $this->_getInlineModThreadModel();
  190. if (!$handler->canMoveThreads($threadIds, 0, $errorPhraseKey))
  191. {
  192. throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
  193. }
  194. $redirect = $this->getDynamicRedirect();
  195. if (!$threadIds)
  196. {
  197. return $this->responseRedirect(
  198. XenForo_ControllerResponse_Redirect::SUCCESS,
  199. $redirect
  200. );
  201. }
  202. $firstThread = $this->_getThreadModel()->getThreadById(reset($threadIds));
  203. $viewParams = array(
  204. 'threadIds' => $threadIds,
  205. 'threadCount' => count($threadIds),
  206. 'firstThread' => $firstThread,
  207. 'nodeOptions' => $this->getModelFromCache('XenForo_Model_Node')->getViewableNodeList(),
  208. 'redirect' => $redirect,
  209. );
  210. return $this->responseView('XenForo_ViewPublic_InlineMod_Thread_Move', 'inline_mod_thread_move', $viewParams);
  211. }
  212. }
  213. /**
  214. * Thread merge handler
  215. *
  216. * @return XenForo_ControllerResponse_Abstract
  217. */
  218. public function actionMerge()
  219. {
  220. if ($this->isConfirmedPost())
  221. {
  222. $threadIds = $this->getInlineModIds(false);
  223. $input = $this->_input->filter(array(
  224. 'target_thread_id' => XenForo_Input::UINT,
  225. 'create_redirect' => XenForo_Input::STRING,
  226. 'redirect_ttl_value' => XenForo_Input::UINT,
  227. 'redirect_ttl_unit' => XenForo_Input::STRING
  228. ));
  229. if ($input['create_redirect'] == 'permanent')
  230. {
  231. $options = array('redirect' => true, 'redirectExpiry' => 0);
  232. }
  233. else if ($input['create_redirect'] == 'expiring')
  234. {
  235. $expiryDate = strtotime('+' . $input['redirect_ttl_value'] . ' ' . $input['redirect_ttl_unit']);
  236. $options = array('redirect' => true, 'redirectExpiry' => $expiryDate);
  237. }
  238. else
  239. {
  240. $options = array('redirect' => false);
  241. }
  242. $targetThread = $this->_getInlineModThreadModel()->mergeThreads($threadIds, $input['target_thread_id'], $options, $errorPhraseKey);
  243. if (!$targetThread)
  244. {
  245. throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
  246. }
  247. $this->clearCookie();
  248. return $this->responseRedirect(
  249. XenForo_ControllerResponse_Redirect::SUCCESS,
  250. XenForo_Link::buildPublicLink('threads', $targetThread)
  251. );
  252. }
  253. else // show confirmation dialog
  254. {
  255. $threadIds = $this->getInlineModIds();
  256. $handler = $this->_getInlineModThreadModel();
  257. if (!$handler->canMergeThreads($threadIds, $errorPhraseKey))
  258. {
  259. throw $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
  260. }
  261. $redirect = $this->getDynamicRedirect();
  262. if (!$threadIds)
  263. {
  264. return $this->responseRedirect(
  265. XenForo_ControllerResponse_Redirect::SUCCESS,
  266. $redirect
  267. );
  268. }
  269. $threads = $this->_getThreadModel()->getThreadsByIds($threadIds);
  270. $viewParams = array(
  271. 'threadIds' => $threadIds,
  272. 'threadCount' => count($threadIds),
  273. 'threads' => $threads,
  274. 'redirect' => $redirect,
  275. );
  276. return $this->responseView('XenForo_ViewPublic_InlineMod_Thread_Merge', 'inline_mod_thread_merge', $viewParams);
  277. }
  278. }
  279. /**
  280. * @return XenForo_Model_InlineMod_Thread
  281. */
  282. public function _getInlineModThreadModel()
  283. {
  284. return $this->getModelFromCache('XenForo_Model_InlineMod_Thread');
  285. }
  286. /**
  287. * @return XenForo_Model_Thread
  288. */
  289. public function _getThreadModel()
  290. {
  291. return $this->getModelFromCache('XenForo_Model_Thread');
  292. }
  293. }