Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 454 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| close_report | |
0.00% |
0 / 148 |
|
0.00% |
0 / 1 |
2162 | |||
| mcp_reports | |
0.00% |
0 / 304 |
|
0.00% |
0 / 2 |
5112 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| main | |
0.00% |
0 / 303 |
|
0.00% |
0 / 1 |
4970 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * @ignore |
| 16 | */ |
| 17 | if (!defined('IN_PHPBB')) |
| 18 | { |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * mcp_reports |
| 24 | * Handling the reports queue |
| 25 | */ |
| 26 | class mcp_reports |
| 27 | { |
| 28 | var $p_master; |
| 29 | var $u_action; |
| 30 | |
| 31 | function __construct($p_master) |
| 32 | { |
| 33 | $this->p_master = $p_master; |
| 34 | } |
| 35 | |
| 36 | function main($id, $mode) |
| 37 | { |
| 38 | global $auth, $db, $user, $template, $request; |
| 39 | global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container, $phpbb_dispatcher; |
| 40 | |
| 41 | include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); |
| 42 | |
| 43 | $forum_id = $request->variable('f', 0); |
| 44 | $start = $request->variable('start', 0); |
| 45 | |
| 46 | $this->page_title = 'MCP_REPORTS'; |
| 47 | |
| 48 | switch ($action) |
| 49 | { |
| 50 | case 'close': |
| 51 | case 'delete': |
| 52 | $report_id_list = $request->variable('report_id_list', array(0)); |
| 53 | |
| 54 | if (!count($report_id_list)) |
| 55 | { |
| 56 | trigger_error('NO_REPORT_SELECTED'); |
| 57 | } |
| 58 | |
| 59 | close_report($report_id_list, $mode, $action); |
| 60 | |
| 61 | break; |
| 62 | } |
| 63 | |
| 64 | switch ($mode) |
| 65 | { |
| 66 | case 'report_details': |
| 67 | |
| 68 | $user->add_lang(array('posting', 'viewforum', 'viewtopic')); |
| 69 | |
| 70 | $post_id = $request->variable('p', 0); |
| 71 | |
| 72 | // closed reports are accessed by report id |
| 73 | $report_id = $request->variable('r', 0); |
| 74 | |
| 75 | $sql_ary = array( |
| 76 | 'SELECT' => 'r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, r.reported_post_text, r.reported_post_uid, r.reported_post_bitfield, r.reported_post_enable_magic_url, r.reported_post_enable_smilies, r.reported_post_enable_bbcode, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour', |
| 77 | |
| 78 | 'FROM' => array( |
| 79 | REPORTS_TABLE => 'r', |
| 80 | REPORTS_REASONS_TABLE => 'rr', |
| 81 | USERS_TABLE => 'u', |
| 82 | ), |
| 83 | |
| 84 | 'WHERE' => (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . ' |
| 85 | AND rr.reason_id = r.reason_id |
| 86 | AND r.user_id = u.user_id |
| 87 | AND r.pm_id = 0', |
| 88 | |
| 89 | 'ORDER_BY' => 'report_closed ASC', |
| 90 | ); |
| 91 | |
| 92 | /** |
| 93 | * Allow changing the query to obtain the user-submitted report. |
| 94 | * |
| 95 | * @event core.mcp_reports_report_details_query_before |
| 96 | * @var array sql_ary The array in the format of the query builder with the query |
| 97 | * @var int forum_id The forum_id, the number in the f GET parameter |
| 98 | * @var int post_id The post_id of the report being viewed (if 0, it is meaningless) |
| 99 | * @var int report_id The report_id of the report being viewed |
| 100 | * @since 3.1.5-RC1 |
| 101 | */ |
| 102 | $vars = array( |
| 103 | 'sql_ary', |
| 104 | 'forum_id', |
| 105 | 'post_id', |
| 106 | 'report_id', |
| 107 | ); |
| 108 | extract($phpbb_dispatcher->trigger_event('core.mcp_reports_report_details_query_before', compact($vars))); |
| 109 | |
| 110 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 111 | $result = $db->sql_query_limit($sql, 1); |
| 112 | $report = $db->sql_fetchrow($result); |
| 113 | $db->sql_freeresult($result); |
| 114 | |
| 115 | /** |
| 116 | * Allow changing the data obtained from the user-submitted report. |
| 117 | * |
| 118 | * @event core.mcp_reports_report_details_query_after |
| 119 | * @var array sql_ary The array in the format of the query builder with the query that had been executted |
| 120 | * @var int forum_id The forum_id, the number in the f GET parameter |
| 121 | * @var int post_id The post_id of the report being viewed (if 0, it is meaningless) |
| 122 | * @var int report_id The report_id of the report being viewed |
| 123 | * @var array report The query's resulting row. |
| 124 | * @since 3.1.5-RC1 |
| 125 | */ |
| 126 | $vars = array( |
| 127 | 'sql_ary', |
| 128 | 'forum_id', |
| 129 | 'post_id', |
| 130 | 'report_id', |
| 131 | 'report', |
| 132 | ); |
| 133 | extract($phpbb_dispatcher->trigger_event('core.mcp_reports_report_details_query_after', compact($vars))); |
| 134 | |
| 135 | if (!$report) |
| 136 | { |
| 137 | trigger_error('NO_REPORT'); |
| 138 | } |
| 139 | |
| 140 | /* @var $phpbb_notifications \phpbb\notification\manager */ |
| 141 | $phpbb_notifications = $phpbb_container->get('notification_manager'); |
| 142 | |
| 143 | $phpbb_notifications->mark_notifications('report_post', $post_id, $user->data['user_id']); |
| 144 | |
| 145 | if (!$report_id && $report['report_closed']) |
| 146 | { |
| 147 | trigger_error('REPORT_CLOSED'); |
| 148 | } |
| 149 | |
| 150 | $post_id = $report['post_id']; |
| 151 | $report_id = $report['report_id']; |
| 152 | |
| 153 | $parse_post_flags = $report['reported_post_enable_bbcode'] ? OPTION_FLAG_BBCODE : 0; |
| 154 | $parse_post_flags += $report['reported_post_enable_smilies'] ? OPTION_FLAG_SMILIES : 0; |
| 155 | $parse_post_flags += $report['reported_post_enable_magic_url'] ? OPTION_FLAG_LINKS : 0; |
| 156 | |
| 157 | $post_info = phpbb_get_post_data(array($post_id), 'm_report', true); |
| 158 | |
| 159 | if (!count($post_info)) |
| 160 | { |
| 161 | trigger_error('NO_REPORT_SELECTED'); |
| 162 | } |
| 163 | |
| 164 | $post_info = $post_info[$post_id]; |
| 165 | |
| 166 | $reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']); |
| 167 | if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])])) |
| 168 | { |
| 169 | $reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]; |
| 170 | $reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]; |
| 171 | } |
| 172 | |
| 173 | if (topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false)) |
| 174 | { |
| 175 | $template->assign_vars(array( |
| 176 | 'S_TOPIC_REVIEW' => true, |
| 177 | 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'], |
| 178 | 'TOPIC_TITLE' => $post_info['topic_title'], |
| 179 | 'REPORTED_POST_ID' => $post_id, |
| 180 | )); |
| 181 | } |
| 182 | |
| 183 | $attachments = array(); |
| 184 | // Get topic tracking info |
| 185 | if ($config['load_db_lastread']) |
| 186 | { |
| 187 | $tmp_topic_data = array($post_info['topic_id'] => $post_info); |
| 188 | $topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time'])); |
| 189 | unset($tmp_topic_data); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']); |
| 194 | } |
| 195 | |
| 196 | $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false; |
| 197 | $message = generate_text_for_display( |
| 198 | $report['reported_post_text'], |
| 199 | $report['reported_post_uid'], |
| 200 | $report['reported_post_bitfield'], |
| 201 | $parse_post_flags, |
| 202 | false |
| 203 | ); |
| 204 | |
| 205 | $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text'])); |
| 206 | |
| 207 | if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) |
| 208 | { |
| 209 | $sql = 'SELECT * |
| 210 | FROM ' . ATTACHMENTS_TABLE . ' |
| 211 | WHERE post_msg_id = ' . $post_id . ' |
| 212 | AND in_message = 0 |
| 213 | AND filetime <= ' . (int) $report['report_time'] . ' |
| 214 | ORDER BY filetime DESC'; |
| 215 | $result = $db->sql_query($sql); |
| 216 | |
| 217 | while ($row = $db->sql_fetchrow($result)) |
| 218 | { |
| 219 | $attachments[] = $row; |
| 220 | } |
| 221 | $db->sql_freeresult($result); |
| 222 | |
| 223 | if (count($attachments)) |
| 224 | { |
| 225 | $update_count = array(); |
| 226 | parse_attachments($post_info['forum_id'], $message, $attachments, $update_count); |
| 227 | } |
| 228 | |
| 229 | // Display not already displayed Attachments for this post, we already parsed them. ;) |
| 230 | if (!empty($attachments)) |
| 231 | { |
| 232 | $template->assign_var('S_HAS_ATTACHMENTS', true); |
| 233 | |
| 234 | foreach ($attachments as $attachment) |
| 235 | { |
| 236 | $template->assign_block_vars('attachment', array( |
| 237 | 'DISPLAY_ATTACHMENT' => $attachment) |
| 238 | ); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // parse signature |
| 244 | $parse_flags = ($post_info['user_sig_bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES; |
| 245 | $post_info['user_sig'] = generate_text_for_display($post_info['user_sig'], $post_info['user_sig_bbcode_uid'], $post_info['user_sig_bbcode_bitfield'], $parse_flags, true); |
| 246 | |
| 247 | $topic_id = (int) $post_info['topic_id']; |
| 248 | |
| 249 | // So it can be sent through the event below. |
| 250 | $report_template = array( |
| 251 | 'S_MCP_REPORT' => true, |
| 252 | 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&p=' . $post_id), |
| 253 | 'S_CAN_APPROVE' => $auth->acl_get('m_approve', $post_info['forum_id']), |
| 254 | 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), |
| 255 | 'S_POST_REPORTED' => $post_info['post_reported'], |
| 256 | 'S_POST_UNAPPROVED' => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE, |
| 257 | 'S_POST_LOCKED' => $post_info['post_edit_locked'], |
| 258 | 'S_REPORT_CLOSED' => $report['report_closed'], |
| 259 | 'S_USER_NOTES' => true, |
| 260 | |
| 261 | 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&p={$post_info['post_id']}") : '', |
| 262 | 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&p=' . $post_id), |
| 263 | 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&p=' . $post_id), |
| 264 | 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&p=' . $post_id), |
| 265 | 'U_MCP_REPORTER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $report['user_id']), |
| 266 | 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']), |
| 267 | 'U_MCP_WARN_REPORTER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $report['user_id']) : '', |
| 268 | 'U_MCP_WARN_USER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $post_info['user_id']) : '', |
| 269 | 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $post_info['forum_id']), |
| 270 | 'U_VIEW_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $post_info['post_id'] . '#p' . $post_info['post_id']), |
| 271 | 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $post_info['topic_id']), |
| 272 | |
| 273 | 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']), |
| 274 | 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), |
| 275 | 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']), |
| 276 | |
| 277 | 'RETURN_REPORTS' => sprintf($user->lang['RETURN_REPORTS'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports' . (($post_info['post_reported']) ? '&mode=reports' : '&mode=reports_closed') . '&start=' . $start . '&f=' . $post_info['forum_id']) . '">', '</a>'), |
| 278 | 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), |
| 279 | 'REPORT_DATE' => $user->format_date($report['report_time']), |
| 280 | 'REPORT_ID' => $report_id, |
| 281 | 'REPORT_REASON_TITLE' => $reason['title'], |
| 282 | 'REPORT_REASON_DESCRIPTION' => $reason['description'], |
| 283 | 'REPORT_TEXT' => $report['report_text'], |
| 284 | |
| 285 | 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), |
| 286 | 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), |
| 287 | 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), |
| 288 | 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), |
| 289 | |
| 290 | 'REPORTER_FULL' => get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']), |
| 291 | 'REPORTER_COLOUR' => get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']), |
| 292 | 'REPORTER_NAME' => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']), |
| 293 | 'U_VIEW_REPORTER_PROFILE' => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']), |
| 294 | |
| 295 | 'POST_PREVIEW' => $message, |
| 296 | 'POST_SUBJECT' => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'], |
| 297 | 'POST_DATE' => $user->format_date($post_info['post_time']), |
| 298 | 'POST_IP' => $post_info['poster_ip'], |
| 299 | 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && $request->variable('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '', |
| 300 | 'POST_ID' => $post_info['post_id'], |
| 301 | 'SIGNATURE' => $post_info['user_sig'], |
| 302 | |
| 303 | 'U_LOOKUP_IP' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? $this->u_action . '&r=' . $report_id . '&p=' . $post_id . '&lookup=' . $post_info['poster_ip'] . '#ip' : '', |
| 304 | ); |
| 305 | |
| 306 | /** |
| 307 | * Event to add/modify MCP report details template data. |
| 308 | * |
| 309 | * @event core.mcp_report_template_data |
| 310 | * @var int forum_id The forum_id, the number in the f GET parameter |
| 311 | * @var int topic_id The topic_id of the report being viewed |
| 312 | * @var int post_id The post_id of the report being viewed (if 0, it is meaningless) |
| 313 | * @var int report_id The report_id of the report being viewed |
| 314 | * @var array report Array with the report data |
| 315 | * @var array report_template Array with the report template data |
| 316 | * @var array post_info Array with the reported post data |
| 317 | * @since 3.2.5-RC1 |
| 318 | */ |
| 319 | $vars = array( |
| 320 | 'forum_id', |
| 321 | 'topic_id', |
| 322 | 'post_id', |
| 323 | 'report_id', |
| 324 | 'report', |
| 325 | 'report_template', |
| 326 | 'post_info', |
| 327 | ); |
| 328 | extract($phpbb_dispatcher->trigger_event('core.mcp_report_template_data', compact($vars))); |
| 329 | |
| 330 | $template->assign_vars($report_template); |
| 331 | |
| 332 | $this->tpl_name = 'mcp_post'; |
| 333 | |
| 334 | break; |
| 335 | |
| 336 | case 'reports': |
| 337 | case 'reports_closed': |
| 338 | $topic_id = $request->variable('t', 0); |
| 339 | |
| 340 | if ($request->is_set_post('t')) |
| 341 | { |
| 342 | $topic_id = $request->variable('t', 0, false, \phpbb\request\request_interface::POST); |
| 343 | } |
| 344 | |
| 345 | $forum_list_reports = get_forum_list('m_report', false, true); |
| 346 | $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs |
| 347 | |
| 348 | // Remove forums we cannot read |
| 349 | foreach ($forum_list_reports as $k => $forum_data) |
| 350 | { |
| 351 | if (!isset($forum_list_read[$forum_data['forum_id']])) |
| 352 | { |
| 353 | unset($forum_list_reports[$k]); |
| 354 | } |
| 355 | } |
| 356 | unset($forum_list_read); |
| 357 | |
| 358 | if ($topic_id) |
| 359 | { |
| 360 | $topic_info = phpbb_get_topic_data(array($topic_id)); |
| 361 | |
| 362 | if (!count($topic_info)) |
| 363 | { |
| 364 | trigger_error('TOPIC_NOT_EXIST'); |
| 365 | } |
| 366 | |
| 367 | if ($forum_id != $topic_info[$topic_id]['forum_id']) |
| 368 | { |
| 369 | $topic_id = 0; |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | $topic_info = $topic_info[$topic_id]; |
| 374 | $forum_id = (int) $topic_info['forum_id']; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | $forum_list = array(); |
| 379 | |
| 380 | if (!$forum_id) |
| 381 | { |
| 382 | foreach ($forum_list_reports as $row) |
| 383 | { |
| 384 | $forum_list[] = $row['forum_id']; |
| 385 | } |
| 386 | |
| 387 | if (!count($forum_list)) |
| 388 | { |
| 389 | trigger_error('NOT_MODERATOR'); |
| 390 | } |
| 391 | } |
| 392 | else |
| 393 | { |
| 394 | $forum_info = phpbb_get_forum_data(array($forum_id), 'm_report'); |
| 395 | |
| 396 | if (!count($forum_info)) |
| 397 | { |
| 398 | trigger_error('NOT_MODERATOR'); |
| 399 | } |
| 400 | |
| 401 | $forum_list = array($forum_id); |
| 402 | } |
| 403 | |
| 404 | /* @var $pagination \phpbb\pagination */ |
| 405 | $pagination = $phpbb_container->get('pagination'); |
| 406 | $forum_list[] = 0; |
| 407 | $forum_data = array(); |
| 408 | |
| 409 | $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>'; |
| 410 | foreach ($forum_list_reports as $row) |
| 411 | { |
| 412 | $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat(' ', $row['padding']) . truncate_string($row['forum_name'], 30, 255, false, $user->lang('ELLIPSIS')) . '</option>'; |
| 413 | $forum_data[$row['forum_id']] = $row; |
| 414 | } |
| 415 | unset($forum_list_reports); |
| 416 | |
| 417 | $sort_days = $total = 0; |
| 418 | $sort_key = $sort_dir = ''; |
| 419 | $sort_by_sql = $sort_order_sql = array(); |
| 420 | phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); |
| 421 | |
| 422 | $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : ''; |
| 423 | |
| 424 | if ($mode == 'reports') |
| 425 | { |
| 426 | $report_state = 'AND p.post_reported = 1 AND r.report_closed = 0'; |
| 427 | } |
| 428 | else |
| 429 | { |
| 430 | $report_state = 'AND r.report_closed = 1'; |
| 431 | } |
| 432 | |
| 433 | $sql = 'SELECT r.report_id |
| 434 | FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . REPORTS_TABLE . ' r ' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . (($sort_order_sql[0] == 'r') ? ', ' . USERS_TABLE . ' ru' : '') . ' |
| 435 | WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . " |
| 436 | $report_state |
| 437 | AND r.post_id = p.post_id |
| 438 | " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' |
| 439 | ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . ' |
| 440 | ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " |
| 441 | AND t.topic_id = p.topic_id |
| 442 | AND r.pm_id = 0 |
| 443 | $limit_time_sql |
| 444 | ORDER BY $sort_order_sql"; |
| 445 | |
| 446 | /** |
| 447 | * Alter sql query to get report id of all reports for requested forum and topic or just forum |
| 448 | * |
| 449 | * @event core.mcp_reports_get_reports_query_before |
| 450 | * @var string sql String with the query to be executed |
| 451 | * @var array forum_list List of forums that contain the posts |
| 452 | * @var int topic_id topic_id in the page request |
| 453 | * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) |
| 454 | * @var string sort_order_sql String with the ORDER BY SQL code used in this query |
| 455 | * @since 3.1.0-RC4 |
| 456 | */ |
| 457 | $vars = array( |
| 458 | 'sql', |
| 459 | 'forum_list', |
| 460 | 'topic_id', |
| 461 | 'limit_time_sql', |
| 462 | 'sort_order_sql', |
| 463 | ); |
| 464 | extract($phpbb_dispatcher->trigger_event('core.mcp_reports_get_reports_query_before', compact($vars))); |
| 465 | |
| 466 | $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); |
| 467 | |
| 468 | $i = 0; |
| 469 | $report_ids = array(); |
| 470 | while ($row = $db->sql_fetchrow($result)) |
| 471 | { |
| 472 | $report_ids[] = $row['report_id']; |
| 473 | $row_num[$row['report_id']] = $i++; |
| 474 | } |
| 475 | $db->sql_freeresult($result); |
| 476 | |
| 477 | if (count($report_ids)) |
| 478 | { |
| 479 | $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, p.post_id, p.post_subject, p.post_username, p.poster_id, p.post_time, p.post_attachment, u.username, u.username_clean, u.user_colour, r.user_id as reporter_id, ru.username as reporter_name, ru.user_colour as reporter_colour, r.report_time, r.report_id |
| 480 | FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru |
| 481 | WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . ' |
| 482 | AND t.topic_id = p.topic_id |
| 483 | AND r.post_id = p.post_id |
| 484 | AND u.user_id = p.poster_id |
| 485 | AND ru.user_id = r.user_id |
| 486 | AND r.pm_id = 0 |
| 487 | ORDER BY ' . $sort_order_sql; |
| 488 | |
| 489 | /** |
| 490 | * Alter sql query to get reports data for requested forum and topic or just forum |
| 491 | * |
| 492 | * @event core.mcp_reports_modify_reports_data_sql |
| 493 | * @var string sql String with the query to be executed |
| 494 | * @var array forum_list List of forums that contain the posts |
| 495 | * @var int topic_id topic_id in the page request |
| 496 | * @var string sort_order_sql String with the ORDER BY SQL code used in this query |
| 497 | * @since 3.3.5-RC1 |
| 498 | */ |
| 499 | $vars = [ |
| 500 | 'sql', |
| 501 | 'forum_list', |
| 502 | 'topic_id', |
| 503 | 'sort_order_sql', |
| 504 | ]; |
| 505 | extract($phpbb_dispatcher->trigger_event('core.mcp_reports_modify_reports_data_sql', compact($vars))); |
| 506 | |
| 507 | $result = $db->sql_query($sql); |
| 508 | |
| 509 | while ($row = $db->sql_fetchrow($result)) |
| 510 | { |
| 511 | $post_row = [ |
| 512 | 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']), |
| 513 | 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . '#p' . $row['post_id'], |
| 514 | 'U_VIEW_DETAILS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=reports&start=$start&mode=report_details&r={$row['report_id']}"), |
| 515 | |
| 516 | 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
| 517 | 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
| 518 | 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
| 519 | 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), |
| 520 | |
| 521 | 'REPORTER_FULL' => get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), |
| 522 | 'REPORTER_COLOUR' => get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), |
| 523 | 'REPORTER' => get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), |
| 524 | 'U_REPORTER' => get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']), |
| 525 | |
| 526 | 'FORUM_NAME' => $forum_data[$row['forum_id']]['forum_name'], |
| 527 | 'POST_ID' => $row['post_id'], |
| 528 | 'POST_SUBJECT' => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'], |
| 529 | 'POST_TIME' => $user->format_date($row['post_time']), |
| 530 | 'REPORT_ID' => $row['report_id'], |
| 531 | 'REPORT_TIME' => $user->format_date($row['report_time']), |
| 532 | 'TOPIC_TITLE' => $row['topic_title'], |
| 533 | 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', |
| 534 | ]; |
| 535 | |
| 536 | /** |
| 537 | * Alter posts template block for MCP reports |
| 538 | * |
| 539 | * @event core.mcp_reports_modify_post_row |
| 540 | * @var string mode Post report mode |
| 541 | * @var array forum_data Array containing forum data |
| 542 | * @var array post_row Template block array of the post |
| 543 | * @var array row Array with original post and report data |
| 544 | * @var int start Start item of this page |
| 545 | * @var int topic_id topic_id in the page request |
| 546 | * @since 3.3.5-RC1 |
| 547 | */ |
| 548 | $vars = [ |
| 549 | 'mode', |
| 550 | 'forum_data', |
| 551 | 'post_row', |
| 552 | 'row', |
| 553 | 'start', |
| 554 | 'topic_id', |
| 555 | ]; |
| 556 | extract($phpbb_dispatcher->trigger_event('core.mcp_reports_modify_post_row', compact($vars))); |
| 557 | |
| 558 | $template->assign_block_vars('postrow', $post_row); |
| 559 | } |
| 560 | $db->sql_freeresult($result); |
| 561 | unset($report_ids, $row); |
| 562 | } |
| 563 | |
| 564 | $base_url = $this->u_action . "&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; |
| 565 | $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); |
| 566 | |
| 567 | // Now display the page |
| 568 | $template->assign_vars(array( |
| 569 | 'L_EXPLAIN' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'], |
| 570 | 'L_TITLE' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN'] : $user->lang['MCP_REPORTS_CLOSED'], |
| 571 | 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '', |
| 572 | |
| 573 | 'S_MCP_ACTION' => $this->u_action, |
| 574 | 'S_FORUM_OPTIONS' => $forum_options, |
| 575 | 'S_CLOSED' => ($mode == 'reports_closed') ? true : false, |
| 576 | |
| 577 | 'TOPIC_ID' => $topic_id, |
| 578 | 'TOTAL' => $total, |
| 579 | 'TOTAL_REPORTS' => $user->lang('LIST_REPORTS', (int) $total), |
| 580 | ) |
| 581 | ); |
| 582 | |
| 583 | $this->tpl_name = 'mcp_reports'; |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * Closes a report |
| 591 | */ |
| 592 | function close_report($report_id_list, $mode, $action, $pm = false) |
| 593 | { |
| 594 | global $db, $user, $auth, $phpbb_log, $request; |
| 595 | global $phpEx, $phpbb_root_path, $phpbb_container; |
| 596 | |
| 597 | $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 '; |
| 598 | $id_column = ($pm) ? 'pm_id' : 'post_id'; |
| 599 | $module = ($pm) ? 'pm_reports' : 'reports'; |
| 600 | $pm_prefix = ($pm) ? 'PM_' : ''; |
| 601 | |
| 602 | $sql = "SELECT r.$id_column |
| 603 | FROM " . REPORTS_TABLE . ' r |
| 604 | WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . $pm_where; |
| 605 | $result = $db->sql_query($sql); |
| 606 | |
| 607 | $post_id_list = array(); |
| 608 | while ($row = $db->sql_fetchrow($result)) |
| 609 | { |
| 610 | $post_id_list[] = $row[$id_column]; |
| 611 | } |
| 612 | $db->sql_freeresult($result); |
| 613 | $post_id_list = array_unique($post_id_list); |
| 614 | |
| 615 | if ($pm) |
| 616 | { |
| 617 | if (!$auth->acl_getf_global('m_report')) |
| 618 | { |
| 619 | send_status_line(403, 'Forbidden'); |
| 620 | trigger_error('NOT_AUTHORISED'); |
| 621 | } |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report'))) |
| 626 | { |
| 627 | send_status_line(403, 'Forbidden'); |
| 628 | trigger_error('NOT_AUTHORISED'); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | if ($action == 'delete' && strpos($user->data['session_page'], 'mode=report_details') !== false) |
| 633 | { |
| 634 | $redirect = $request->variable('redirect', build_url(array('mode', 'r', 'quickmod')) . '&mode=reports'); |
| 635 | } |
| 636 | else if ($action == 'delete' && strpos($user->data['session_page'], 'mode=pm_report_details') !== false) |
| 637 | { |
| 638 | $redirect = $request->variable('redirect', build_url(array('mode', 'r', 'quickmod')) . '&mode=pm_reports'); |
| 639 | } |
| 640 | else if ($action == 'close' && !$request->variable('r', 0)) |
| 641 | { |
| 642 | $redirect = $request->variable('redirect', build_url(array('mode', 'p', 'quickmod')) . '&mode=' . $module); |
| 643 | } |
| 644 | else |
| 645 | { |
| 646 | $redirect = $request->variable('redirect', build_url(array('quickmod'))); |
| 647 | } |
| 648 | $success_msg = ''; |
| 649 | $forum_ids = array(); |
| 650 | $topic_ids = array(); |
| 651 | |
| 652 | $s_hidden_fields = build_hidden_fields(array( |
| 653 | 'i' => $module, |
| 654 | 'mode' => $mode, |
| 655 | 'report_id_list' => $report_id_list, |
| 656 | 'action' => $action, |
| 657 | 'redirect' => $redirect) |
| 658 | ); |
| 659 | |
| 660 | if (confirm_box(true)) |
| 661 | { |
| 662 | $post_info = ($pm) ? phpbb_get_pm_data($post_id_list) : phpbb_get_post_data($post_id_list, 'm_report'); |
| 663 | |
| 664 | $sql = "SELECT r.report_id, r.$id_column, r.report_closed, r.user_id, r.user_notify, u.username, u.username_clean, u.user_email, u.user_lang |
| 665 | FROM " . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u |
| 666 | WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . ' |
| 667 | ' . (($action == 'close') ? 'AND r.report_closed = 0' : '') . ' |
| 668 | AND r.user_id = u.user_id' . $pm_where; |
| 669 | $result = $db->sql_query($sql); |
| 670 | |
| 671 | $reports = $close_report_posts = $close_report_topics = $notify_reporters = $report_id_list = array(); |
| 672 | while ($report = $db->sql_fetchrow($result)) |
| 673 | { |
| 674 | $reports[$report['report_id']] = $report; |
| 675 | $report_id_list[] = $report['report_id']; |
| 676 | |
| 677 | if (!$report['report_closed']) |
| 678 | { |
| 679 | $close_report_posts[] = $report[$id_column]; |
| 680 | |
| 681 | if (!$pm) |
| 682 | { |
| 683 | $close_report_topics[] = $post_info[$report['post_id']]['topic_id']; |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | if ($report['user_notify'] && !$report['report_closed']) |
| 688 | { |
| 689 | $notify_reporters[$report['report_id']] = &$reports[$report['report_id']]; |
| 690 | } |
| 691 | } |
| 692 | $db->sql_freeresult($result); |
| 693 | |
| 694 | if (count($reports)) |
| 695 | { |
| 696 | $close_report_posts = array_unique($close_report_posts); |
| 697 | $close_report_topics = array_unique($close_report_topics); |
| 698 | |
| 699 | if (!$pm && count($close_report_posts)) |
| 700 | { |
| 701 | // Get a list of topics that still contain reported posts |
| 702 | $sql = 'SELECT DISTINCT topic_id |
| 703 | FROM ' . POSTS_TABLE . ' |
| 704 | WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . ' |
| 705 | AND post_reported = 1 |
| 706 | AND ' . $db->sql_in_set('post_id', $close_report_posts, true); |
| 707 | $result = $db->sql_query($sql); |
| 708 | |
| 709 | $keep_report_topics = array(); |
| 710 | while ($row = $db->sql_fetchrow($result)) |
| 711 | { |
| 712 | $keep_report_topics[] = $row['topic_id']; |
| 713 | } |
| 714 | $db->sql_freeresult($result); |
| 715 | |
| 716 | $close_report_topics = array_diff($close_report_topics, $keep_report_topics); |
| 717 | unset($keep_report_topics); |
| 718 | } |
| 719 | |
| 720 | $db->sql_transaction('begin'); |
| 721 | |
| 722 | if ($action == 'close') |
| 723 | { |
| 724 | $sql = 'UPDATE ' . REPORTS_TABLE . ' |
| 725 | SET report_closed = 1 |
| 726 | WHERE ' . $db->sql_in_set('report_id', $report_id_list); |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | $sql = 'DELETE FROM ' . REPORTS_TABLE . ' |
| 731 | WHERE ' . $db->sql_in_set('report_id', $report_id_list); |
| 732 | } |
| 733 | $db->sql_query($sql); |
| 734 | |
| 735 | if (count($close_report_posts)) |
| 736 | { |
| 737 | if ($pm) |
| 738 | { |
| 739 | $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' |
| 740 | SET message_reported = 0 |
| 741 | WHERE ' . $db->sql_in_set('msg_id', $close_report_posts); |
| 742 | $db->sql_query($sql); |
| 743 | |
| 744 | if ($action == 'delete') |
| 745 | { |
| 746 | delete_pm(ANONYMOUS, $close_report_posts, PRIVMSGS_INBOX); |
| 747 | } |
| 748 | } |
| 749 | else |
| 750 | { |
| 751 | $sql = 'UPDATE ' . POSTS_TABLE . ' |
| 752 | SET post_reported = 0 |
| 753 | WHERE ' . $db->sql_in_set('post_id', $close_report_posts); |
| 754 | $db->sql_query($sql); |
| 755 | |
| 756 | if (count($close_report_topics)) |
| 757 | { |
| 758 | $sql = 'UPDATE ' . TOPICS_TABLE . ' |
| 759 | SET topic_reported = 0 |
| 760 | WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . ' |
| 761 | OR ' . $db->sql_in_set('topic_moved_id', $close_report_topics); |
| 762 | $db->sql_query($sql); |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | $db->sql_transaction('commit'); |
| 768 | } |
| 769 | unset($close_report_posts, $close_report_topics); |
| 770 | |
| 771 | /* @var $phpbb_notifications \phpbb\notification\manager */ |
| 772 | $phpbb_notifications = $phpbb_container->get('notification_manager'); |
| 773 | |
| 774 | foreach ($reports as $report) |
| 775 | { |
| 776 | if ($pm) |
| 777 | { |
| 778 | $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_PM_REPORT_' . strtoupper($action) . 'D', false, array( |
| 779 | 'forum_id' => 0, |
| 780 | 'topic_id' => 0, |
| 781 | $post_info[$report['pm_id']]['message_subject'] |
| 782 | )); |
| 783 | $phpbb_notifications->delete_notifications('notification.type.report_pm', $report['pm_id']); |
| 784 | } |
| 785 | else |
| 786 | { |
| 787 | $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_REPORT_' . strtoupper($action) . 'D', false, array( |
| 788 | 'forum_id' => $post_info[$report['post_id']]['forum_id'], |
| 789 | 'topic_id' => $post_info[$report['post_id']]['topic_id'], |
| 790 | 'post_id' => $report['post_id'], |
| 791 | $post_info[$report['post_id']]['post_subject'] |
| 792 | )); |
| 793 | $phpbb_notifications->delete_notifications('notification.type.report_post', $report['post_id']); |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | // Notify reporters |
| 798 | if (count($notify_reporters)) |
| 799 | { |
| 800 | foreach ($notify_reporters as $report_id => $reporter) |
| 801 | { |
| 802 | if ($reporter['user_id'] == ANONYMOUS) |
| 803 | { |
| 804 | continue; |
| 805 | } |
| 806 | |
| 807 | $post_id = $reporter[$id_column]; |
| 808 | |
| 809 | if ($pm) |
| 810 | { |
| 811 | $phpbb_notifications->add_notifications('notification.type.report_pm_closed', array_merge($post_info[$post_id], array( |
| 812 | 'reporter' => $reporter['user_id'], |
| 813 | 'closer_id' => $user->data['user_id'], |
| 814 | 'from_user_id' => $post_info[$post_id]['author_id'], |
| 815 | ))); |
| 816 | } |
| 817 | else |
| 818 | { |
| 819 | $phpbb_notifications->add_notifications('notification.type.report_post_closed', array_merge($post_info[$post_id], array( |
| 820 | 'reporter' => $reporter['user_id'], |
| 821 | 'closer_id' => $user->data['user_id'], |
| 822 | ))); |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | if (!$pm) |
| 828 | { |
| 829 | foreach ($post_info as $post) |
| 830 | { |
| 831 | $forum_ids[$post['forum_id']] = $post['forum_id']; |
| 832 | $topic_ids[$post['topic_id']] = $post['topic_id']; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | unset($notify_reporters, $post_info, $reports); |
| 837 | |
| 838 | $success_msg = (count($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS'; |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | confirm_box(false, $user->lang[strtoupper($action) . "_{$pm_prefix}REPORT" . ((count($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields); |
| 843 | } |
| 844 | |
| 845 | $redirect = $request->variable('redirect', "index.$phpEx"); |
| 846 | $redirect = reapply_sid($redirect); |
| 847 | |
| 848 | if (!$success_msg) |
| 849 | { |
| 850 | redirect($redirect); |
| 851 | } |
| 852 | else |
| 853 | { |
| 854 | meta_refresh(3, $redirect); |
| 855 | |
| 856 | $return_forum = ''; |
| 857 | $return_topic = ''; |
| 858 | |
| 859 | if (!$pm) |
| 860 | { |
| 861 | if (count($forum_ids) === 1) |
| 862 | { |
| 863 | $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />'; |
| 864 | } |
| 865 | |
| 866 | if (count($topic_ids) === 1) |
| 867 | { |
| 868 | $return_topic = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . current($topic_ids)) . '">', '</a>') . '<br /><br />'; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_forum . $return_topic . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>')); |
| 873 | } |
| 874 | } |