ReportedPosts.php 14 KB

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