ReportedPosts.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. 'disregard' => 'DisregardReport',
  42. 'details' => 'ReportDetails', // Shows a single report and its comments.
  43. 'handlecomment' => 'AddComment', // CRUD actions for moderator comments.
  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;
  66. // Put the open and closed options into tabs, because we can...
  67. $context[$context['moderation_menu_name']]['tab_data'] = array(
  68. 'title' => $txt['mc_reported_posts'],
  69. 'help' => '',
  70. 'description' => $txt['mc_reported_posts_desc'],
  71. );
  72. // Showing closed ones?
  73. $context['view_closed'] = isset($_GET['closed']);
  74. $context['sub_template'] = 'reported_posts';
  75. $context['reports'] = getReports($context['view_closed']);
  76. }
  77. function ReportDetails()
  78. {
  79. global $user_info, $context, $sourcedir, $scripturl, $txt;
  80. global $smcFunc;
  81. // Have to at least give us something to work with.
  82. if (empty($_REQUEST['report']))
  83. fatal_lang_error('mc_no_modreport_specified');
  84. // Integers only please
  85. $_REQUEST['report'] = (int) $_REQUEST['report'];
  86. // Get the report details.
  87. $report = getReportDetails($_REQUEST['report']);
  88. if(!$report)
  89. fatal_lang_error('mc_no_modreport_found');
  90. // If they are adding a comment then... add a comment.
  91. if (isset($_POST['add_comment']) && !empty($_POST['mod_comment']))
  92. {
  93. checkSession();
  94. $newComment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
  95. // In it goes.
  96. if (!empty($newComment))
  97. {
  98. $smcFunc['db_insert']('',
  99. '{db_prefix}log_comments',
  100. array(
  101. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  102. 'id_notice' => 'int', 'body' => 'string', 'log_time' => 'int',
  103. ),
  104. array(
  105. $user_info['id'], $user_info['name'], 'reportc', '',
  106. $_REQUEST['report'], $newComment, time(),
  107. ),
  108. array('id_comment')
  109. );
  110. $last_comment = $smcFunc['db_insert_id']('{db_prefix}log_comments', 'id_comment');
  111. // And get ready to notify people.
  112. $smcFunc['db_insert']('insert',
  113. '{db_prefix}background_tasks',
  114. array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
  115. array('$sourcedir/tasks/MsgReportReply-Notify.php', 'MsgReportReply_Notify_Background', serialize(array(
  116. 'report_id' => $_REQUEST['report'],
  117. 'comment_id' => $last_comment,
  118. 'msg_id' => $row['id_msg'],
  119. 'topic_id' => $row['id_topic'],
  120. 'board_id' => $row['id_board'],
  121. 'sender_id' => $user_info['id'],
  122. 'sender_name' => $user_info['name'],
  123. 'time' => time(),
  124. )), 0),
  125. array('id_task')
  126. );
  127. // Redirect to prevent double submission.
  128. redirectexit($scripturl . '?action=moderate;area=reports;report=' . $_REQUEST['report']);
  129. }
  130. }
  131. $context['report'] = array(
  132. 'id' => $row['id_report'],
  133. 'topic_id' => $row['id_topic'],
  134. 'board_id' => $row['id_board'],
  135. 'message_id' => $row['id_msg'],
  136. 'message_href' => $scripturl . '?msg=' . $row['id_msg'],
  137. 'message_link' => '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
  138. 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
  139. 'author' => array(
  140. 'id' => $row['id_author'],
  141. 'name' => $row['author_name'],
  142. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  143. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  144. ),
  145. 'comments' => array(),
  146. 'mod_comments' => array(),
  147. 'time_started' => timeformat($row['time_started']),
  148. 'last_updated' => timeformat($row['time_updated']),
  149. 'subject' => $row['subject'],
  150. 'body' => parse_bbc($row['body']),
  151. 'num_reports' => $row['num_reports'],
  152. 'closed' => $row['closed'],
  153. 'ignore' => $row['ignore_all']
  154. );
  155. // So what bad things do the reporters have to say about it?
  156. $request = $smcFunc['db_query']('', '
  157. SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, lrc.member_ip,
  158. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lrc.membername) AS reporter
  159. FROM {db_prefix}log_reported_comments AS lrc
  160. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
  161. WHERE lrc.id_report = {int:id_report}',
  162. array(
  163. 'id_report' => $context['report']['id'],
  164. )
  165. );
  166. while ($row = $smcFunc['db_fetch_assoc']($request))
  167. {
  168. $context['report']['comments'][] = array(
  169. 'id' => $row['id_comment'],
  170. 'message' => strtr($row['comment'], array("\n" => '<br>')),
  171. 'time' => timeformat($row['time_sent']),
  172. 'member' => array(
  173. 'id' => $row['id_member'],
  174. 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
  175. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
  176. 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  177. 'ip' => !empty($row['member_ip']) && allowedTo('moderate_forum') ? '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['member_ip'] . '">' . $row['member_ip'] . '</a>' : '',
  178. ),
  179. );
  180. }
  181. $smcFunc['db_free_result']($request);
  182. // Hang about old chap, any comments from moderators on this one?
  183. $request = $smcFunc['db_query']('', '
  184. SELECT lc.id_comment, lc.id_notice, lc.log_time, lc.body,
  185. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS moderator
  186. FROM {db_prefix}log_comments AS lc
  187. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  188. WHERE lc.id_notice = {int:id_report}
  189. AND lc.comment_type = {literal:reportc}',
  190. array(
  191. 'id_report' => $context['report']['id'],
  192. )
  193. );
  194. while ($row = $smcFunc['db_fetch_assoc']($request))
  195. {
  196. $context['report']['mod_comments'][] = array(
  197. 'id' => $row['id_comment'],
  198. 'message' => parse_bbc($row['body']),
  199. 'time' => timeformat($row['log_time']),
  200. 'can_edit' => allowedTo('admin_forum') || (($user_info['id'] == $row['id_member']) && allowedTo('moderate_forum')),
  201. 'member' => array(
  202. 'id' => $row['id_member'],
  203. 'name' => $row['moderator'],
  204. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['moderator'] . '</a>' : $row['moderator'],
  205. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  206. ),
  207. );
  208. }
  209. $smcFunc['db_free_result']($request);
  210. // What have the other moderators done to this message?
  211. require_once($sourcedir . '/Modlog.php');
  212. require_once($sourcedir . '/Subs-List.php');
  213. loadLanguage('Modlog');
  214. // This is all the information from the moderation log.
  215. $listOptions = array(
  216. 'id' => 'moderation_actions_list',
  217. 'title' => $txt['mc_modreport_modactions'],
  218. 'items_per_page' => 15,
  219. 'no_items_label' => $txt['modlog_no_entries_found'],
  220. 'base_href' => $scripturl . '?action=moderate;area=reports;report=' . $context['report']['id'],
  221. 'default_sort_col' => 'time',
  222. 'get_items' => array(
  223. 'function' => 'list_getModLogEntries',
  224. 'params' => array(
  225. 'lm.id_topic = {int:id_topic}',
  226. array('id_topic' => $context['report']['topic_id']),
  227. 1,
  228. ),
  229. ),
  230. 'get_count' => array(
  231. 'function' => 'list_getModLogEntryCount',
  232. 'params' => array(
  233. 'lm.id_topic = {int:id_topic}',
  234. array('id_topic' => $context['report']['topic_id']),
  235. 1,
  236. ),
  237. ),
  238. // This assumes we are viewing by user.
  239. 'columns' => array(
  240. 'action' => array(
  241. 'header' => array(
  242. 'value' => $txt['modlog_action'],
  243. ),
  244. 'data' => array(
  245. 'db' => 'action_text',
  246. 'class' => 'smalltext',
  247. ),
  248. 'sort' => array(
  249. 'default' => 'lm.action',
  250. 'reverse' => 'lm.action DESC',
  251. ),
  252. ),
  253. 'time' => array(
  254. 'header' => array(
  255. 'value' => $txt['modlog_date'],
  256. ),
  257. 'data' => array(
  258. 'db' => 'time',
  259. 'class' => 'smalltext',
  260. ),
  261. 'sort' => array(
  262. 'default' => 'lm.log_time',
  263. 'reverse' => 'lm.log_time DESC',
  264. ),
  265. ),
  266. 'moderator' => array(
  267. 'header' => array(
  268. 'value' => $txt['modlog_member'],
  269. ),
  270. 'data' => array(
  271. 'db' => 'moderator_link',
  272. 'class' => 'smalltext',
  273. ),
  274. 'sort' => array(
  275. 'default' => 'mem.real_name',
  276. 'reverse' => 'mem.real_name DESC',
  277. ),
  278. ),
  279. 'position' => array(
  280. 'header' => array(
  281. 'value' => $txt['modlog_position'],
  282. ),
  283. 'data' => array(
  284. 'db' => 'position',
  285. 'class' => 'smalltext',
  286. ),
  287. 'sort' => array(
  288. 'default' => 'mg.group_name',
  289. 'reverse' => 'mg.group_name DESC',
  290. ),
  291. ),
  292. 'ip' => array(
  293. 'header' => array(
  294. 'value' => $txt['modlog_ip'],
  295. ),
  296. 'data' => array(
  297. 'db' => 'ip',
  298. 'class' => 'smalltext',
  299. ),
  300. 'sort' => array(
  301. 'default' => 'lm.ip',
  302. 'reverse' => 'lm.ip DESC',
  303. ),
  304. ),
  305. ),
  306. );
  307. // Create the watched user list.
  308. createList($listOptions);
  309. // Make sure to get the correct tab selected.
  310. if ($context['report']['closed'])
  311. $context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
  312. // Finally we are done :P
  313. $context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']);
  314. $context['sub_template'] = 'viewmodreport';
  315. }
  316. ?>