2
0

ReportedPosts.php 14 KB

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