ReportedPosts.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. // Set up the comforting bits...
  33. $context['page_title'] = $txt['mc_reported_posts'];
  34. $context['sub_template'] = 'reported_posts';
  35. // This comes under the umbrella of moderating posts.
  36. if ($user_info['mod_cache']['bq'] == '0=1')
  37. isAllowedTo('moderate_forum');
  38. $sub_actions = array(
  39. 'show' => 'ShowReports', // Both open and closed reports
  40. 'handle' => 'HandleReport', // Deals with closing/opening reports.
  41. 'details' => 'ReportDetails', // Shows a single report and its comments.
  42. 'handlecomment' => 'HandleComment', // CRUD actions for moderator comments.
  43. 'editcomment' => 'EditComment',
  44. );
  45. // Go ahead and add your own sub-actions.
  46. call_integration_hook('integrate_reported_posts', array(&$sub_actions));
  47. // By default we call the open sub-action.
  48. if (isset($_REQUEST['sa']) && isset($sub_actions[$_REQUEST['sa']]))
  49. $context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES);
  50. else
  51. $context['sub_action'] = 'show';
  52. // Call the function!
  53. $sub_actions[$context['sub_action']]();
  54. }
  55. /**
  56. * Shows all open or closed reported posts.
  57. * It requires the moderate_forum permission.
  58. *
  59. * @uses ModerationCenter template.
  60. * @uses ModerationCenter language file.
  61. *
  62. */
  63. function ShowReports()
  64. {
  65. global $context, $txt, $scripturl;
  66. // Showing closed or open ones? regardless, turn this to an integer for better handling.
  67. $context['view_closed'] = (int) isset($_GET['closed']);
  68. // Put the open and closed options into tabs, because we can...
  69. $context[$context['moderation_menu_name']]['tab_data'] = array(
  70. 'title' => $txt['mc_reported_posts'],
  71. 'help' => '',
  72. 'description' => $txt['mc_reported_posts_desc'],
  73. 'tabs' => array(
  74. 'show' => array($txt['mc_reportedp_active']),
  75. 'show;closed' => array($txt['mc_reportedp_closed']),
  76. ),
  77. );
  78. // Call the right template.
  79. $context['sub_template'] = 'reported_posts';
  80. $context['start'] = (int) isset($_GET['start']) ? $_GET['start'] : 0;
  81. // Before anything, we need to know just how many reports do we have.
  82. $context['total_reports'] = countReports($context['view_closed']);
  83. // Just how many items are we showing per page?
  84. $context['reports_how_many'] = 10;
  85. // So, that means we can have pagination, yes?
  86. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=reports;sa=show' . ($context['view_closed'] ? ';closed' : ''), $context['start'], $context['total_reports'], $context['reports_how_many']);
  87. // Get the reports at once!
  88. $context['reports'] = getReports($context['view_closed']);
  89. // Show a confirmation if the user wants to disregard a report.
  90. if (!$context['view_closed'])
  91. addInlineJavascript('
  92. $(\'.report_ignore\').on(\'click\', function(){
  93. // Need to make sure to only show this when ignoring.
  94. if ($(this).data(\'ignore\') == \'1\'){
  95. return confirm('. JavaScriptEscape($txt['mc_reportedp_ignore_confirm']) .');
  96. }
  97. });', true);
  98. }
  99. function ReportDetails()
  100. {
  101. global $user_info, $context, $sourcedir, $scripturl, $txt;
  102. global $smcFunc;
  103. $report = array();
  104. $reportComments = array();
  105. // Have to at least give us something to work with.
  106. if (empty($_REQUEST['rid']))
  107. fatal_lang_error('mc_reportedp_none_found');
  108. // Integers only please
  109. $report_id = (int) $_REQUEST['rid'];
  110. // Get the report details.
  111. $report = getReportDetails($report_id);
  112. if(!$report)
  113. fatal_lang_error('mc_no_modreport_found');
  114. // Build the report data.
  115. $context['report'] = array(
  116. 'id' => $report['id_report'],
  117. 'topic_id' => $report['id_topic'],
  118. 'board_id' => $report['id_board'],
  119. 'message_id' => $report['id_msg'],
  120. 'message_href' => $scripturl . '?msg=' . $report['id_msg'],
  121. 'message_link' => '<a href="' . $scripturl . '?msg=' . $report['id_msg'] . '">' . $report['subject'] . '</a>',
  122. 'report_href' => $scripturl . '?action=moderate;area=reports;rid=' . $report['id_report'],
  123. 'author' => array(
  124. 'id' => $report['id_author'],
  125. 'name' => $report['author_name'],
  126. 'link' => $report['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $report['id_author'] . '">' . $report['author_name'] . '</a>' : $report['author_name'],
  127. 'href' => $scripturl . '?action=profile;u=' . $report['id_author'],
  128. ),
  129. 'comments' => array(),
  130. 'mod_comments' => array(),
  131. 'time_started' => timeformat($report['time_started']),
  132. 'last_updated' => timeformat($report['time_updated']),
  133. 'subject' => $report['subject'],
  134. 'body' => parse_bbc($report['body']),
  135. 'num_reports' => $report['num_reports'],
  136. 'closed' => $report['closed'],
  137. 'ignore' => $report['ignore_all']
  138. );
  139. $reportComments = getReportComments($report_id);
  140. if (!empty($reportComments))
  141. $context['report'] = array_merge($context['report'], $reportComments);
  142. // What have the other moderators done to this message?
  143. require_once($sourcedir . '/Modlog.php');
  144. require_once($sourcedir . '/Subs-List.php');
  145. loadLanguage('Modlog');
  146. // This is all the information from the moderation log.
  147. $listOptions = array(
  148. 'id' => 'moderation_actions_list',
  149. 'title' => $txt['mc_modreport_modactions'],
  150. 'items_per_page' => 15,
  151. 'no_items_label' => $txt['modlog_no_entries_found'],
  152. 'base_href' => $scripturl . '?action=moderate;area=reports;sa=details;rid=' . $context['report']['id'],
  153. 'default_sort_col' => 'time',
  154. 'get_items' => array(
  155. 'function' => 'list_getModLogEntries',
  156. 'params' => array(
  157. 'lm.id_topic = {int:id_topic}',
  158. array('id_topic' => $context['report']['topic_id']),
  159. 1,
  160. ),
  161. ),
  162. 'get_count' => array(
  163. 'function' => 'list_getModLogEntryCount',
  164. 'params' => array(
  165. 'lm.id_topic = {int:id_topic}',
  166. array('id_topic' => $context['report']['topic_id']),
  167. 1,
  168. ),
  169. ),
  170. // This assumes we are viewing by user.
  171. 'columns' => array(
  172. 'action' => array(
  173. 'header' => array(
  174. 'value' => $txt['modlog_action'],
  175. ),
  176. 'data' => array(
  177. 'db' => 'action_text',
  178. 'class' => 'smalltext',
  179. ),
  180. 'sort' => array(
  181. 'default' => 'lm.action',
  182. 'reverse' => 'lm.action DESC',
  183. ),
  184. ),
  185. 'time' => array(
  186. 'header' => array(
  187. 'value' => $txt['modlog_date'],
  188. ),
  189. 'data' => array(
  190. 'db' => 'time',
  191. 'class' => 'smalltext',
  192. ),
  193. 'sort' => array(
  194. 'default' => 'lm.log_time',
  195. 'reverse' => 'lm.log_time DESC',
  196. ),
  197. ),
  198. 'moderator' => array(
  199. 'header' => array(
  200. 'value' => $txt['modlog_member'],
  201. ),
  202. 'data' => array(
  203. 'db' => 'moderator_link',
  204. 'class' => 'smalltext',
  205. ),
  206. 'sort' => array(
  207. 'default' => 'mem.real_name',
  208. 'reverse' => 'mem.real_name DESC',
  209. ),
  210. ),
  211. 'position' => array(
  212. 'header' => array(
  213. 'value' => $txt['modlog_position'],
  214. ),
  215. 'data' => array(
  216. 'db' => 'position',
  217. 'class' => 'smalltext',
  218. ),
  219. 'sort' => array(
  220. 'default' => 'mg.group_name',
  221. 'reverse' => 'mg.group_name DESC',
  222. ),
  223. ),
  224. 'ip' => array(
  225. 'header' => array(
  226. 'value' => $txt['modlog_ip'],
  227. ),
  228. 'data' => array(
  229. 'db' => 'ip',
  230. 'class' => 'smalltext',
  231. ),
  232. 'sort' => array(
  233. 'default' => 'lm.ip',
  234. 'reverse' => 'lm.ip DESC',
  235. ),
  236. ),
  237. ),
  238. );
  239. // Create the watched user list.
  240. createList($listOptions);
  241. // Make sure to get the correct tab selected.
  242. if ($context['report']['closed'])
  243. $context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
  244. addInlineJavascript('
  245. $(\'.deleteModComment\').on(\'click\', function() {
  246. return confirm('. (JavaScriptEscape($txt['mc_reportedp_delete_confirm'])) .');
  247. });', true);
  248. // Finally we are done :P
  249. $context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']);
  250. $context['sub_template'] = 'viewmodreport';
  251. }
  252. function HandleComment()
  253. {
  254. global $smcFunc, $scripturl;
  255. // The report ID is a must.
  256. if (empty($_REQUEST['rid']))
  257. fatal_lang_error('mc_reportedp_none_found');
  258. // Integers only please.
  259. $report_id = (int) $_REQUEST['rid'];
  260. // If they are adding a comment then... add a comment.
  261. if (isset($_POST['add_comment']) && !empty($_POST['mod_comment']))
  262. {
  263. checkSession();
  264. $new_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
  265. saveModComment($report_id, array($report_id, $new_comment, time()));
  266. }
  267. // Deleting a comment?
  268. if (isset($_REQUEST['delete']) && isset($_REQUEST['mid']))
  269. {
  270. if (empty($_REQUEST['mid']))
  271. fatal_lang_error('mc_reportedp_comment_none_found');
  272. $comment_id = (int) $_REQUEST['mid'];
  273. deleteModComment($comment_id);
  274. }
  275. //Redirect to prevent double submission.
  276. redirectexit($scripturl . '?action=moderate;area=reports;sa=details;rid=' . $report_id);
  277. }
  278. function EditComment()
  279. {
  280. global $smcFunc, $context, $txt, $scripturl;
  281. $comment = array();
  282. // The report ID is a must.
  283. if (empty($_REQUEST['rid']))
  284. fatal_lang_error('mc_reportedp_none_found');
  285. if (empty($_REQUEST['mid']))
  286. fatal_lang_error('mc_reportedp_comment_none_found');
  287. // Integers only please.
  288. $context['report_id'] = (int) $_REQUEST['rid'];
  289. $context['comment_id'] = (int) $_REQUEST['mid'];
  290. $context['comment'] = getCommentModDetails($context['comment_id']);
  291. if (empty($context['comment']))
  292. fatal_lang_error('mc_reportedp_comment_none_found');
  293. // Set up the comforting bits...
  294. $context['page_title'] = $txt['mc_reported_posts'];
  295. $context['sub_template'] = 'edit_comment';
  296. if (isset($_REQUEST['save']) && isset($_POST['edit_comment']) && !empty($_POST['mod_comment']))
  297. {
  298. $edited_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
  299. editModComment($context['comment_id'], $edited_comment);
  300. redirectexit($scripturl . '?action=moderate;area=reports;sa=details;rid=' . $context['report_id']);
  301. }
  302. }
  303. function HandleReport()
  304. {
  305. global $scripturl;
  306. checkSession('get');
  307. // We need to do something!
  308. if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed'])))
  309. fatal_lang_error('mc_reportedp_none_found');
  310. // Integers only please.
  311. $report_id = (int) $_REQUEST['rid'];
  312. // What are we gonna do?
  313. $action = isset($_GET['ignore']) ? 'ignore' : 'closed';
  314. // Are we disregarding or "un-disregarding"? "un-disregarding" thats a funny word!
  315. $value = (int) $_GET[$action];
  316. // Update the DB entry
  317. updateReport($action, $value, $report_id);
  318. // Done!
  319. redirectexit($scripturl . '?action=moderate;area=reports');
  320. }
  321. ?>