ReportedPosts.php 8.8 KB

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