ReportedPosts.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <?php
  2. /**
  3. * Handles reported posts and moderation comments.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2014 Simple Machines and individual contributors
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('No direct access...');
  16. /**
  17. * Sets and call a function based on the given subaction.
  18. * It requires the moderate_forum permission.
  19. *
  20. * @uses ModerationCenter template.
  21. * @uses ModerationCenter language file.
  22. *
  23. */
  24. function ReportedPosts()
  25. {
  26. global $txt, $context, $scripturl, $user_info, $smcFunc;
  27. global $sourcedir;
  28. loadLanguage('ModerationCenter');
  29. loadTemplate('ReportedPosts');
  30. // We need this little rough gem.
  31. require_once($sourcedir . '/Subs-ReportedPosts.php');
  32. // Do we need to show a confirmation message?
  33. $context['report_post_action'] = !empty($_SESSION['rc_confirmation']) ? $_SESSION['rc_confirmation'] : array();
  34. unset($_SESSION['rc_confirmation']);
  35. // Set up the comforting bits...
  36. $context['page_title'] = $txt['mc_reported_posts'];
  37. // Put the open and closed options into tabs, because we can...
  38. $context[$context['moderation_menu_name']]['tab_data'] = array(
  39. 'title' => $txt['mc_reported_posts'],
  40. 'help' => '',
  41. 'description' => $txt['mc_reported_posts_desc'],
  42. );
  43. // This comes under the umbrella of moderating posts.
  44. if ($user_info['mod_cache']['bq'] == '0=1')
  45. isAllowedTo('moderate_forum');
  46. $sub_actions = array(
  47. 'show' => 'ShowReports',
  48. 'closed' => 'ShowClosedReports',
  49. 'handle' => 'HandleReport', // Deals with closing/opening reports.
  50. 'details' => 'ReportDetails', // Shows a single report and its comments.
  51. 'handlecomment' => 'HandleComment', // CRUD actions for moderator comments.
  52. 'editcomment' => 'EditComment',
  53. );
  54. // Go ahead and add your own sub-actions.
  55. call_integration_hook('integrate_reported_posts', array(&$sub_actions));
  56. // By default we call the open sub-action.
  57. if (isset($_REQUEST['sa']) && isset($sub_actions[$_REQUEST['sa']]))
  58. $context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
  59. else
  60. $context['sub_action'] = 'show';
  61. // Hi Ho Silver Away!
  62. $sub_actions[$context['sub_action']]();
  63. }
  64. /**
  65. * Shows all currently open reported posts.
  66. * It requires the moderate_forum permission.
  67. *
  68. * @uses ModerationCenter language file.
  69. *
  70. */
  71. function ShowReports()
  72. {
  73. global $context, $txt, $scripturl;
  74. // Showing closed or open ones? regardless, turn this to an integer for better handling.
  75. $context['view_closed'] = 0;
  76. // Call the right template.
  77. $context['sub_template'] = 'reported_posts';
  78. $context['start'] = (int) isset($_GET['start']) ? $_GET['start'] : 0;
  79. // Before anything, we need to know just how many reports do we have.
  80. $context['total_reports'] = countReports($context['view_closed']);
  81. // Just how many items are we showing per page?
  82. $context['reports_how_many'] = 10;
  83. // So, that means we can have pagination, yes?
  84. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=reports;sa=show', $context['start'], $context['total_reports'], $context['reports_how_many']);
  85. // Get the reports at once!
  86. $context['reports'] = getReports($context['view_closed']);
  87. // Are we closing multiple reports?
  88. if (isset($_POST['close']) && isset($_POST['close_selected']))
  89. {
  90. checkSession('post');
  91. validateToken('mod-report-close-all');
  92. // All the ones to update...
  93. $toClose = array();
  94. foreach ($_POST['close'] as $rid)
  95. $toClose[] = (int) $rid;
  96. if (!empty($toClose))
  97. updateReport('closed', 1, $toClose);
  98. // Set the confirmation message.
  99. $_SESSION['rc_confirmation'] = 'close_all';
  100. // Force a page refresh.
  101. redirectexit($scripturl . '?action=moderate;area=reports');
  102. }
  103. // Show a confirmation if the user wants to disregard a report.
  104. if (!$context['view_closed'])
  105. addInlineJavascript('
  106. $(\'.delete_message\').on(\'click\', function(){
  107. return confirm('. JavaScriptEscape($txt['mc_reportedp_delete_confirm']) .');
  108. });
  109. $(\'.report_ignore\').on(\'click\', function(){
  110. // Need to make sure to only show this when ignoring.
  111. if ($(this).data(\'ignore\') == \'1\'){
  112. return confirm('. JavaScriptEscape($txt['mc_reportedp_ignore_confirm']) .');
  113. }
  114. });', true);
  115. createToken('mod-report-close-all');
  116. createToken('mod-report-ignore', 'get');
  117. createToken('mod-report-closed', 'get');
  118. }
  119. function ShowClosedReports()
  120. {
  121. global $context, $txt, $scripturl;
  122. // Showing closed ones.
  123. $context['view_closed'] = 1;
  124. // Call the right template.
  125. $context['sub_template'] = 'reported_posts';
  126. $context['start'] = (int) isset($_GET['start']) ? $_GET['start'] : 0;
  127. // Before anything, we need to know just how many reports do we have.
  128. $context['total_reports'] = countReports($context['view_closed']);
  129. // Just how many items are we showing per page?
  130. $context['reports_how_many'] = 10;
  131. // So, that means we can have pagination, yes?
  132. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=reports;sa=closed', $context['start'], $context['total_reports'], $context['reports_how_many']);
  133. // Get the reports at once!
  134. $context['reports'] = getReports($context['view_closed']);
  135. // Show a confirmation if the user wants to disregard a report.
  136. addInlineJavascript('
  137. $(\'.delete_message\').on(\'click\', function(){
  138. return confirm('. JavaScriptEscape($txt['mc_reportedp_delete_confirm']) .');
  139. });
  140. $(\'.report_ignore\').on(\'click\', function(){
  141. // Need to make sure to only show this when ignoring.
  142. if ($(this).data(\'ignore\') == \'1\'){
  143. return confirm('. JavaScriptEscape($txt['mc_reportedp_ignore_confirm']) .');
  144. }
  145. });', true);
  146. createToken('mod-report-ignore', 'get');
  147. createToken('mod-report-closed', 'get');
  148. }
  149. function ReportDetails()
  150. {
  151. global $user_info, $context, $sourcedir, $scripturl, $txt;
  152. global $smcFunc;
  153. $report = array();
  154. $reportComments = array();
  155. // Have to at least give us something to work with.
  156. if (empty($_REQUEST['rid']))
  157. fatal_lang_error('mc_reportedp_none_found');
  158. // Integers only please
  159. $report_id = (int) $_REQUEST['rid'];
  160. // Get the report details.
  161. $report = getReportDetails($report_id);
  162. if(!$report)
  163. fatal_lang_error('mc_no_modreport_found');
  164. // Build the report data.
  165. $context['report'] = array(
  166. 'id' => $report['id_report'],
  167. 'topic_id' => $report['id_topic'],
  168. 'board_id' => $report['id_board'],
  169. 'message_id' => $report['id_msg'],
  170. 'message_href' => $scripturl . '?msg=' . $report['id_msg'],
  171. 'message_link' => '<a href="' . $scripturl . '?msg=' . $report['id_msg'] . '">' . $report['subject'] . '</a>',
  172. 'report_href' => $scripturl . '?action=moderate;area=reports;rid=' . $report['id_report'],
  173. 'author' => array(
  174. 'id' => $report['id_author'],
  175. 'name' => $report['author_name'],
  176. 'link' => $report['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $report['id_author'] . '">' . $report['author_name'] . '</a>' : $report['author_name'],
  177. 'href' => $scripturl . '?action=profile;u=' . $report['id_author'],
  178. ),
  179. 'comments' => array(),
  180. 'mod_comments' => array(),
  181. 'time_started' => timeformat($report['time_started']),
  182. 'last_updated' => timeformat($report['time_updated']),
  183. 'subject' => $report['subject'],
  184. 'body' => parse_bbc($report['body']),
  185. 'num_reports' => $report['num_reports'],
  186. 'closed' => $report['closed'],
  187. 'ignore' => $report['ignore_all']
  188. );
  189. $reportComments = getReportComments($report_id);
  190. if (!empty($reportComments))
  191. $context['report'] = array_merge($context['report'], $reportComments);
  192. // What have the other moderators done to this message?
  193. require_once($sourcedir . '/Modlog.php');
  194. require_once($sourcedir . '/Subs-List.php');
  195. loadLanguage('Modlog');
  196. // This is all the information from the moderation log.
  197. $listOptions = array(
  198. 'id' => 'moderation_actions_list',
  199. 'title' => $txt['mc_modreport_modactions'],
  200. 'items_per_page' => 15,
  201. 'no_items_label' => $txt['modlog_no_entries_found'],
  202. 'base_href' => $scripturl . '?action=moderate;area=reports;sa=details;rid=' . $context['report']['id'],
  203. 'default_sort_col' => 'time',
  204. 'get_items' => array(
  205. 'function' => 'list_getModLogEntries',
  206. 'params' => array(
  207. 'lm.id_topic = {int:id_topic}',
  208. array('id_topic' => $context['report']['topic_id']),
  209. 1,
  210. ),
  211. ),
  212. 'get_count' => array(
  213. 'function' => 'list_getModLogEntryCount',
  214. 'params' => array(
  215. 'lm.id_topic = {int:id_topic}',
  216. array('id_topic' => $context['report']['topic_id']),
  217. 1,
  218. ),
  219. ),
  220. // This assumes we are viewing by user.
  221. 'columns' => array(
  222. 'action' => array(
  223. 'header' => array(
  224. 'value' => $txt['modlog_action'],
  225. ),
  226. 'data' => array(
  227. 'db' => 'action_text',
  228. 'class' => 'smalltext',
  229. ),
  230. 'sort' => array(
  231. 'default' => 'lm.action',
  232. 'reverse' => 'lm.action DESC',
  233. ),
  234. ),
  235. 'time' => array(
  236. 'header' => array(
  237. 'value' => $txt['modlog_date'],
  238. ),
  239. 'data' => array(
  240. 'db' => 'time',
  241. 'class' => 'smalltext',
  242. ),
  243. 'sort' => array(
  244. 'default' => 'lm.log_time',
  245. 'reverse' => 'lm.log_time DESC',
  246. ),
  247. ),
  248. 'moderator' => array(
  249. 'header' => array(
  250. 'value' => $txt['modlog_member'],
  251. ),
  252. 'data' => array(
  253. 'db' => 'moderator_link',
  254. 'class' => 'smalltext',
  255. ),
  256. 'sort' => array(
  257. 'default' => 'mem.real_name',
  258. 'reverse' => 'mem.real_name DESC',
  259. ),
  260. ),
  261. 'position' => array(
  262. 'header' => array(
  263. 'value' => $txt['modlog_position'],
  264. ),
  265. 'data' => array(
  266. 'db' => 'position',
  267. 'class' => 'smalltext',
  268. ),
  269. 'sort' => array(
  270. 'default' => 'mg.group_name',
  271. 'reverse' => 'mg.group_name DESC',
  272. ),
  273. ),
  274. 'ip' => array(
  275. 'header' => array(
  276. 'value' => $txt['modlog_ip'],
  277. ),
  278. 'data' => array(
  279. 'db' => 'ip',
  280. 'class' => 'smalltext',
  281. ),
  282. 'sort' => array(
  283. 'default' => 'lm.ip',
  284. 'reverse' => 'lm.ip DESC',
  285. ),
  286. ),
  287. ),
  288. );
  289. // Create the watched user list.
  290. createList($listOptions);
  291. // Make sure to get the correct tab selected.
  292. if ($context['report']['closed'])
  293. $context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
  294. addInlineJavascript('
  295. $(\'.deleteModComment\').on(\'click\', function() {
  296. return confirm('. (JavaScriptEscape($txt['mc_reportedp_delete_confirm'])) .');
  297. });', true);
  298. // Finally we are done :P
  299. $context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']);
  300. $context['sub_template'] = 'viewmodreport';
  301. // We can ignore a report from this page too so show the confirmation on here as well.
  302. addInlineJavascript('
  303. $(\'.report_ignore\').on(\'click\', function(){
  304. // Need to make sure to only show this when ignoring.
  305. if ($(this).data(\'ignore\') == \'1\'){
  306. return confirm('. JavaScriptEscape($txt['mc_reportedp_ignore_confirm']) .');
  307. }
  308. });', true);
  309. createToken('mod-reportC-add');
  310. createToken('mod-reportC-delete', 'get');
  311. // We can "un-disregard" and close a report from here so add their respective tokens.
  312. createToken('mod-report-ignore', 'get');
  313. createToken('mod-report-closed', 'get');
  314. }
  315. function HandleComment()
  316. {
  317. global $smcFunc, $scripturl;
  318. // The report ID is a must.
  319. if (empty($_REQUEST['rid']))
  320. fatal_lang_error('mc_reportedp_none_found');
  321. // Integers only please.
  322. $report_id = (int) $_REQUEST['rid'];
  323. // If they are adding a comment then... add a comment.
  324. if (isset($_POST['add_comment']) && !empty($_POST['mod_comment']))
  325. {
  326. checkSession();
  327. validateToken('mod-reportC-add');
  328. $new_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
  329. saveModComment($report_id, array($report_id, $new_comment, time()));
  330. // Everything went better than expected!
  331. $_SESSION['rc_confirmation'] = 'message_saved';
  332. }
  333. // Deleting a comment?
  334. if (isset($_REQUEST['delete']) && isset($_REQUEST['mid']))
  335. {
  336. checkSession('get');
  337. validateToken('mod-reportC-delete', 'get');
  338. if (empty($_REQUEST['mid']))
  339. fatal_lang_error('mc_reportedp_comment_none_found');
  340. $comment_id = (int) $_REQUEST['mid'];
  341. deleteModComment($comment_id);
  342. // Tell them the message was deleted.
  343. $_SESSION['rc_confirmation'] = 'message_deleted';
  344. }
  345. //Redirect to prevent double submission.
  346. redirectexit($scripturl . '?action=moderate;area=reports;sa=details;rid=' . $report_id);
  347. }
  348. function EditComment()
  349. {
  350. global $smcFunc, $context, $txt, $scripturl;
  351. $comment = array();
  352. checkSession(isset($_REQUEST['save']) ? 'post' : 'get');
  353. // The report ID is a must.
  354. if (empty($_REQUEST['rid']))
  355. fatal_lang_error('mc_reportedp_none_found');
  356. if (empty($_REQUEST['mid']))
  357. fatal_lang_error('mc_reportedp_comment_none_found');
  358. // Integers only please.
  359. $context['report_id'] = (int) $_REQUEST['rid'];
  360. $context['comment_id'] = (int) $_REQUEST['mid'];
  361. $context['comment'] = getCommentModDetails($context['comment_id']);
  362. if (empty($context['comment']))
  363. fatal_lang_error('mc_reportedp_comment_none_found');
  364. // Set up the comforting bits...
  365. $context['page_title'] = $txt['mc_reported_posts'];
  366. $context['sub_template'] = 'edit_comment';
  367. if (isset($_REQUEST['save']) && isset($_POST['edit_comment']) && !empty($_POST['mod_comment']))
  368. {
  369. validateToken('mod-reportC-edit');
  370. $edited_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
  371. editModComment($context['comment_id'], $edited_comment);
  372. $_SESSION['rc_confirmation'] = 'message_edited';
  373. redirectexit($scripturl . '?action=moderate;area=reports;sa=details;rid=' . $context['report_id']);
  374. }
  375. createToken('mod-reportC-edit');
  376. }
  377. function HandleReport()
  378. {
  379. global $scripturl;
  380. checkSession('get');
  381. // We need to do something!
  382. if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed'])))
  383. fatal_lang_error('mc_reportedp_none_found');
  384. // What are we gonna do?
  385. $action = isset($_GET['ignore']) ? 'ignore' : 'closed';
  386. validateToken('mod-report-'. $action, 'get');
  387. // Are we disregarding or "un-disregarding"? "un-disregarding" thats a funny word!
  388. $value = (int) $_GET[$action];
  389. // Figuring out.
  390. $message = $action == 'ignore' ? ($value ? 'ignore' : 'unignore') : ($value ? 'close' : 'open');
  391. // Integers only please.
  392. $report_id = (int) $_REQUEST['rid'];
  393. // Update the DB entry
  394. updateReport($action, $value, $report_id);
  395. // So, time to show a confirmation message, lets do some trickery!
  396. $_SESSION['rc_confirmation'] = $message;
  397. // Done!
  398. redirectexit($scripturl . '?action=moderate;area=reports');
  399. }
  400. ?>