PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/campsite/src/include/phorum/moderation.php

https://github.com/joechrysler/Campsite
PHP | 462 lines | 323 code | 78 blank | 61 comment | 52 complexity | 1c426da2e2da6d20fbd14c9e55a1d909 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // Copyright (C) 2006 Phorum Development Team //
  5. // http://www.phorum.org //
  6. // //
  7. // This program is free software. You can redistribute it and/or modify //
  8. // it under the terms of either the current Phorum License (viewable at //
  9. // phorum.org) or the Phorum License that was distributed with this file //
  10. // //
  11. // This program is distributed in the hope that it will be useful, //
  12. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  14. // //
  15. // You should have received a copy of the Phorum License //
  16. // along with this program. //
  17. ////////////////////////////////////////////////////////////////////////////////
  18. define('phorum_page','moderation');
  19. include_once("./common.php");
  20. include_once("./include/moderation_functions.php");
  21. include_once("./include/thread_info.php");
  22. include_once("./include/email_functions.php");
  23. if(!phorum_check_read_common()) {
  24. return;
  25. }
  26. $PHORUM["DATA"]["MODERATOR"] = phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES);
  27. $msgthd_id = (isset($_POST["thread"])) ? (int)$_POST["thread"] : (int)$PHORUM['args'][2];
  28. $mod_step = (isset($_POST["mod_step"])) ? (int)$_POST["mod_step"] : (int)$PHORUM['args'][1];
  29. if(empty($msgthd_id) || !phorum_user_access_allowed(PHORUM_USER_ALLOW_MODERATE_MESSAGES)) {
  30. phorum_return_to_list();
  31. }
  32. // If the user is not fully logged in, send him to the login page.
  33. // because moderation action can vary so much, the only safe bet is to send them
  34. // to the referrer if they are not fully logged in
  35. if(!$PHORUM["DATA"]["FULLY_LOGGEDIN"]){
  36. phorum_redirect_by_url(phorum_get_url(PHORUM_LOGIN_URL, "redir=".$_SERVER["HTTP_REFERER"]));
  37. exit();
  38. }
  39. $template="message";
  40. // set all our URL's
  41. phorum_build_common_urls();
  42. // make it possible to override this var in a hook
  43. $is_admin_user=$PHORUM["user"]["admin"];
  44. // a hook for doing stuff in moderation, i.e. logging moderator-actions
  45. phorum_hook("moderation",$mod_step);
  46. switch ($mod_step) {
  47. case PHORUM_DELETE_MESSAGE: // this is a message delete
  48. // check that they're an admin if they want to delete an announcement
  49. $message = phorum_db_get_message($msgthd_id);
  50. if ($message["sort"] == PHORUM_SORT_ANNOUNCEMENT && !$is_admin_user){
  51. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]["LANG"]["DeleteAnnouncementForbidden"];
  52. break;
  53. }
  54. $msg_ids=phorum_db_delete_message($msgthd_id, PHORUM_DELETE_MESSAGE);
  55. foreach($msg_ids as $id){
  56. $files=phorum_db_get_message_file_list($id);
  57. foreach($files as $file_id=>$data){
  58. phorum_db_file_delete($file_id);
  59. }
  60. }
  61. phorum_hook("delete", $msg_ids);
  62. $nummsgs=count($msg_ids);
  63. $PHORUM['DATA']['MESSAGE']=$nummsgs." ".$PHORUM["DATA"]['LANG']['MsgDeletedOk'];
  64. if(isset($PHORUM['args']["prepost"])) {
  65. $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
  66. } else {
  67. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  68. }
  69. break;
  70. case PHORUM_DELETE_TREE: // this is a message delete
  71. // check that they're an admin if they want to delete an announcement
  72. $message = phorum_db_get_message($msgthd_id);
  73. if ($message["sort"] == PHORUM_SORT_ANNOUNCEMENT && !$is_admin_user){
  74. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]["LANG"]["DeleteAnnouncementForbidden"];
  75. break;
  76. }
  77. // Delete the message and all its replies.
  78. $msg_ids=phorum_db_delete_message($msgthd_id, PHORUM_DELETE_TREE);
  79. // Cleanup the attachments for all deleted messages.
  80. foreach($msg_ids as $id){
  81. $files=phorum_db_get_message_file_list($id);
  82. foreach($files as $file_id=>$data){
  83. phorum_db_file_delete($file_id);
  84. }
  85. }
  86. // Check if we have moved threads to delete.
  87. // We unset the forum id, so phorum_db_get_messages()
  88. // will return messages with the same thread id in
  89. // other forums as well (those are the move notifications).
  90. $forum_id = $PHORUM["forum_id"];
  91. $PHORUM["forum_id"] = 0;
  92. $moved = phorum_db_get_messages($msgthd_id);
  93. $PHORUM["forum_id"] = $forum_id;
  94. foreach ($moved as $id => $data) {
  95. if (isset($data["meta"]["moved"])) {
  96. phorum_db_delete_message($id, PHORUM_DELETE_MESSAGE);
  97. }
  98. }
  99. // Run a hook for performing custom cleanup actions.
  100. phorum_hook("delete", $msg_ids);
  101. $nummsgs=count($msg_ids);
  102. $PHORUM['DATA']['MESSAGE']=$nummsgs." ".$PHORUM["DATA"]["LANG"]['MsgDeletedOk'];
  103. if(isset($PHORUM['args']["prepost"])) {
  104. $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
  105. } else {
  106. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  107. }
  108. break;
  109. case PHORUM_MOVE_THREAD: // this is the first step of a message move
  110. // check if the thread to move is an announcement thread
  111. $message = phorum_db_get_message($msgthd_id);
  112. if ($message["sort"] == PHORUM_SORT_ANNOUNCEMENT) {
  113. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]["LANG"]["MoveAnnouncementForbidden"];
  114. break;
  115. }
  116. $PHORUM['DATA']['URL']["ACTION"]=phorum_get_url(PHORUM_MODERATION_ACTION_URL);
  117. $PHORUM['DATA']["FORM"]["forum_id"]=$PHORUM["forum_id"];
  118. $PHORUM['DATA']["FORM"]["thread_id"]=$msgthd_id;
  119. $PHORUM['DATA']["FORM"]["mod_step"]=PHORUM_DO_THREAD_MOVE;
  120. // get all the forums the moderator may move to
  121. $PHORUM['DATA']["MoveForumsOption"]="";
  122. $forums=phorum_db_get_forums(0,-1,$PHORUM['vroot']);
  123. asort($forums);
  124. foreach($forums as $id=>$forum){
  125. if ($id == $PHORUM["forum_id"]) continue;
  126. // add && phorum_user_moderate_allowed($id) if the mod should only be able
  127. // to move to forums he also moderates
  128. if($forum["folder_flag"]==0){
  129. // it makes no sense to move to the forum we are in already
  130. if($forum['forum_id'] != $PHORUM['forum_id']) {
  131. $forum_data[strtolower($forum["name"])]=array("forum_id"=>$id, "name"=>$forum["name"]);
  132. }
  133. }
  134. }
  135. $PHORUM['DATA']['FRM']=1;
  136. $PHORUM['DATA']['FORUMS']=$forum_data;
  137. $output=true;
  138. $template="move_form";
  139. break;
  140. case PHORUM_DO_THREAD_MOVE: // this is the last step of a message move
  141. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['MsgMoveOk'];
  142. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  143. $message = phorum_db_get_message($msgthd_id);
  144. // find out if we have a notification-message already in this
  145. // target-forum for this thread ... it doesn't make sense to keep this
  146. // message any longer as the thread has reappeared on its original location
  147. $temp_forum_id=$PHORUM['forum_id'];
  148. $PHORUM['forum_id']=$_POST['moveto'];
  149. $check_messages=phorum_db_get_messages($msgthd_id);
  150. unset($check_messages['users']);
  151. // ok, we found exactly one message of this thread in the target forum
  152. if(is_array($check_messages) && count($check_messages) == 1) {
  153. // ... going to delete it
  154. $tmp_message=array_shift($check_messages);
  155. $retval=phorum_db_delete_message($tmp_message['message_id']);
  156. }
  157. $PHORUM['forum_id']=$temp_forum_id;
  158. // Move the thread to another forum.
  159. phorum_db_move_thread($msgthd_id, $_POST['moveto']);
  160. // Create a new message in place of the old one to notify
  161. // visitors that the thread was moved.
  162. if(isset($_POST['create_notification']) && $_POST['create_notification']) {
  163. $newmessage = $message;
  164. $newmessage['body']=" -- moved topic -- ";
  165. $newmessage['meta']=array('moved' => 1);
  166. $newmessage['sort']=PHORUM_SORT_DEFAULT;
  167. unset($newmessage['message_id']);
  168. phorum_db_post_message($newmessage);
  169. }
  170. phorum_hook("move_thread", $msgthd_id);
  171. break;
  172. case PHORUM_CLOSE_THREAD: // we have to close a thread
  173. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['ThreadClosedOk'];
  174. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  175. phorum_db_close_thread($msgthd_id);
  176. phorum_hook("close_thread", $msgthd_id);
  177. break;
  178. case PHORUM_REOPEN_THREAD: // we have to reopen a thread
  179. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['ThreadReopenedOk'];
  180. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  181. phorum_db_reopen_thread($msgthd_id);
  182. phorum_hook("reopen_thread", $msgthd_id);
  183. break;
  184. case PHORUM_APPROVE_MESSAGE: // approving a message
  185. $PHORUM['DATA']['MESSAGE']="1 ".$PHORUM["DATA"]['LANG']['MsgApprovedOk'];
  186. $old_message = phorum_db_get_message($msgthd_id);
  187. $newpost=array("status"=>PHORUM_STATUS_APPROVED);
  188. // setting the new status
  189. phorum_db_update_message($msgthd_id, $newpost);
  190. // updating the thread-info
  191. phorum_update_thread_info($old_message['thread']);
  192. // updating the forum-stats
  193. phorum_db_update_forum_stats(false, 1, $old_message["datestamp"]);
  194. if($old_message['status'] != PHORUM_STATUS_HIDDEN ) {
  195. phorum_email_notice($old_message);
  196. }
  197. if(isset($PHORUM['args']['old_forum']) && is_numeric($PHORUM['args']['old_forum']) && $PHORUM['folder_flag'] && $old_message['sort'] == PHORUM_SORT_ANNOUNCEMENT) {
  198. $PHORUM['forum_id']=(int)$PHORUM['args']['old_forum'];
  199. }
  200. if(isset($PHORUM['args']["prepost"])) {
  201. $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
  202. } else {
  203. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  204. }
  205. break;
  206. case PHORUM_APPROVE_MESSAGE_TREE: // approve a message and all answers to it
  207. $old_message = phorum_db_get_message($msgthd_id);
  208. $newpost=array("status"=>PHORUM_STATUS_APPROVED);
  209. $mids = phorum_db_get_messagetree($msgthd_id, $old_message["forum_id"]);
  210. // make an array from the string
  211. $mids_arr=explode(",",$mids);
  212. // count the entries for later use
  213. $num_approved=count($mids_arr);
  214. foreach($mids_arr as $key => $mid) {
  215. // setting the new status
  216. phorum_db_update_message($mid, $newpost);
  217. }
  218. // updating the thread-info
  219. phorum_update_thread_info($old_message['thread']);
  220. // updating the forum-stats
  221. phorum_db_update_forum_stats(false, "+$num_approved", $old_message["datestamp"]);
  222. if(isset($PHORUM['args']['old_forum']) && is_numeric($PHORUM['args']['old_forum']) && $PHORUM['folder_flag'] && $old_message['sort'] == PHORUM_SORT_ANNOUNCEMENT) {
  223. $PHORUM['forum_id']=(int)$PHORUM['args']['old_forum'];
  224. }
  225. $PHORUM['DATA']['MESSAGE']="$num_approved ".$PHORUM['DATA']['LANG']['MsgApprovedOk'];
  226. if(isset($PHORUM['args']["prepost"])) {
  227. $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
  228. } else {
  229. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  230. }
  231. break;
  232. case PHORUM_HIDE_POST: // hiding a message (and its replies)
  233. $old_message = phorum_db_get_message($msgthd_id);
  234. $newpost=array("status"=>PHORUM_STATUS_HIDDEN);
  235. $mids = phorum_db_get_messagetree($msgthd_id, $old_message["forum_id"]);
  236. // make an array from the string
  237. $mids_arr=explode(",",$mids);
  238. // count the entries for later use
  239. $num_hidden=count($mids_arr);
  240. foreach($mids_arr as $key => $mid) {
  241. // setting the new status
  242. phorum_db_update_message($mid, $newpost);
  243. }
  244. phorum_hook("hide", $msgthd_id);
  245. // updating the thread-info
  246. phorum_update_thread_info($old_message['thread']);
  247. // updating the forum-stats
  248. phorum_db_update_forum_stats(false, "-$num_hidden", $old_message["datestamp"]);
  249. $PHORUM['DATA']['MESSAGE']="$num_hidden ".$PHORUM['DATA']['LANG']['MsgHiddenOk'];
  250. if(isset($PHORUM['args']["prepost"])) {
  251. $PHORUM['DATA']["URL"]["REDIRECT"]=phorum_get_url(PHORUM_CONTROLCENTER_URL,"panel=".PHORUM_CC_UNAPPROVED);
  252. } else {
  253. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  254. }
  255. break;
  256. case PHORUM_MERGE_THREAD: // this is the first step of a thread merge
  257. $template="merge_form";
  258. $PHORUM['DATA']['URL']["ACTION"] = phorum_get_url(PHORUM_MODERATION_ACTION_URL);
  259. $PHORUM['DATA']["FORM"]["forum_id"] = $PHORUM["forum_id"];
  260. $PHORUM['DATA']["FORM"]["thread_id"] = $msgthd_id;
  261. $PHORUM['DATA']["FORM"]["mod_step"] = PHORUM_DO_THREAD_MERGE;
  262. // the moderator selects the target thread to merge to
  263. $merge_t1 = phorum_moderator_data_get('merge_t1');
  264. if( !$merge_t1 || $merge_t1==$msgthd_id ) {
  265. phorum_moderator_data_put('merge_t1', $msgthd_id);
  266. $PHORUM['DATA']["FORM"]["merge_none"] =true;
  267. }
  268. // the moderator selects the source thread to merge from
  269. else {
  270. $PHORUM['DATA']["FORM"]["merge_t1"] =$merge_t1;
  271. $message = phorum_db_get_message($merge_t1, "message_id", true);
  272. $PHORUM['DATA']["FORM"]["merge_subject1"] =htmlentities($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
  273. $message = phorum_db_get_message($msgthd_id);
  274. $PHORUM['DATA']["FORM"]["thread_subject"] =htmlentities($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
  275. }
  276. break;
  277. case PHORUM_DO_THREAD_MERGE: // this is the last step of a thread merge
  278. if( isset($_POST['thread1']) && $_POST['thread1']) {
  279. // Commit Thread Merge
  280. settype($_POST['thread1'], "int");
  281. settype($_POST['thread'], "int"); // Thread 2
  282. $PHORUM['DATA']['MESSAGE'] = $PHORUM["DATA"]['LANG']['MsgMergeOk'];
  283. $PHORUM['DATA']["URL"]["REDIRECT"] = $PHORUM["DATA"]["URL"]["TOP"];
  284. $PHORUM["reverse_threading"] = 0;
  285. // Get the target thread.
  286. $target =phorum_db_get_message($_POST['thread1'], "message_id", true);
  287. if (!$target) die("Can't retrieve target thread " . $_POST['thread1']);
  288. // Get all messages from the thread that we have to merge.
  289. $merge_messages=phorum_db_get_messages($_POST['thread']);
  290. unset($merge_messages['users']);
  291. // Create new messages in the target thread for
  292. // all messages that have to be merged.
  293. $msgid_translation=array();
  294. foreach($merge_messages as $msg)
  295. {
  296. $oldid=$msg['message_id'];
  297. $msg['thread'] = $target['thread']; // the thread we merge with
  298. $msg['forum_id'] = $target['forum_id']; // the forum_id of the new thread
  299. $msg['sort'] = $target['sort']; // the sort type of the new thread
  300. if($msg['message_id'] == $msg['thread']) {
  301. $msg['parent_id']=$target['thread'];
  302. } elseif(isset($msgid_translation[$msg['parent_id']])) {
  303. $msg['parent_id']=$msgid_translation[$msg['parent_id']];
  304. } else {
  305. $msg['parent_id']=$msg['thread'];
  306. }
  307. unset($msg['message_id']);
  308. unset($msg['modifystamp']);
  309. phorum_db_post_message($msg,true);
  310. // save the new message-id for later use
  311. $msgid_translation[$oldid]=$msg['message_id'];
  312. }
  313. // deleting messages which are now doubled
  314. phorum_db_delete_message($_POST['thread'], PHORUM_DELETE_TREE);
  315. // update message count / stats
  316. phorum_db_update_forum_stats(true);
  317. // change forum_id for the following calls to update the right forum
  318. $PHORUM["forum_id"] =$target['forum_id'];
  319. // update message count / stats
  320. phorum_update_thread_info($target['thread']);
  321. phorum_db_update_forum_stats(true);
  322. } else {
  323. // Cancel Thread Merge
  324. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['MsgMergeCancel'];
  325. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  326. }
  327. // unset temporary moderator_data
  328. phorum_moderator_data_remove('merge_t1');
  329. break;
  330. case PHORUM_SPLIT_THREAD: // this is the first step of a thread split
  331. $PHORUM['DATA']['URL']["ACTION"]=phorum_get_url(PHORUM_MODERATION_ACTION_URL);
  332. $PHORUM['DATA']["FORM"]["forum_id"]=$PHORUM["forum_id"];
  333. $message =phorum_db_get_message($msgthd_id);
  334. $PHORUM['DATA']["FORM"]["thread_id"]=$message["thread"];
  335. $PHORUM['DATA']["FORM"]["message_id"]=$msgthd_id;
  336. $PHORUM['DATA']["FORM"]["message_subject"]=htmlentities($message["subject"], ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
  337. $PHORUM['DATA']["FORM"]["mod_step"]=PHORUM_DO_THREAD_SPLIT;
  338. $template="split_form";
  339. break;
  340. case PHORUM_DO_THREAD_SPLIT: // this is the last step of a thread split
  341. $PHORUM['DATA']['MESSAGE']=$PHORUM["DATA"]['LANG']['MsgSplitOk'];
  342. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  343. settype($_POST['forum_id'], "int");
  344. settype($_POST['message'], "int");
  345. settype($_POST['thread'], "int");
  346. phorum_db_split_thread($_POST['message'],$_POST['forum_id']);
  347. // update message count / stats
  348. phorum_update_thread_info($_POST['thread']);
  349. phorum_update_thread_info($_POST['message']);
  350. phorum_db_update_forum_stats(true);
  351. break;
  352. default:
  353. if(!isset($PHORUM['DATA']['MESSAGE'])) $PHORUM['DATA']['MESSAGE']="";
  354. $PHORUM['DATA']["URL"]["REDIRECT"]=$PHORUM["DATA"]["URL"]["TOP"];
  355. }
  356. if(!isset($PHORUM['DATA']['BACKMSG'])) {
  357. $PHORUM['DATA']["BACKMSG"]=$PHORUM['DATA']["LANG"]["BackToList"];
  358. }
  359. include phorum_get_template("header");
  360. phorum_hook("after_header");
  361. include phorum_get_template($template);
  362. phorum_hook("before_footer");
  363. include phorum_get_template("footer");
  364. ?>