[ Index ] |
PHP Cross Reference of phpBB-3.3.12-deutsch |
[Summary view] [Print] [Text view]
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_queue 24 * Handling the moderation queue 25 */ 26 class mcp_queue 27 { 28 var $p_master; 29 var $u_action; 30 31 public function __construct($p_master) 32 { 33 $this->p_master = $p_master; 34 } 35 36 public function main($id, $mode) 37 { 38 global $auth, $db, $user, $template, $request; 39 global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container; 40 global $phpbb_dispatcher; 41 42 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); 43 44 $forum_id = $request->variable('f', 0); 45 $start = $request->variable('start', 0); 46 47 $this->page_title = 'MCP_QUEUE'; 48 49 switch ($action) 50 { 51 case 'approve': 52 case 'restore': 53 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); 54 55 $post_id_list = $request->variable('post_id_list', array(0)); 56 $topic_id_list = $request->variable('topic_id_list', array(0)); 57 58 if (!empty($post_id_list)) 59 { 60 self::approve_posts($action, $post_id_list, 'queue', $mode); 61 } 62 else if (!empty($topic_id_list)) 63 { 64 self::approve_topics($action, $topic_id_list, 'queue', $mode); 65 } 66 else 67 { 68 trigger_error('NO_POST_SELECTED'); 69 } 70 break; 71 72 case 'delete': 73 $post_id_list = $request->variable('post_id_list', array(0)); 74 $topic_id_list = $request->variable('topic_id_list', array(0)); 75 $delete_reason = $request->variable('delete_reason', '', true); 76 77 if (!empty($post_id_list)) 78 { 79 if (!function_exists('mcp_delete_post')) 80 { 81 global $phpbb_root_path, $phpEx; 82 include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); 83 } 84 mcp_delete_post($post_id_list, false, $delete_reason, $action); 85 } 86 else if (!empty($topic_id_list)) 87 { 88 if (!function_exists('mcp_delete_topic')) 89 { 90 global $phpbb_root_path, $phpEx; 91 include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); 92 } 93 mcp_delete_topic($topic_id_list, false, $delete_reason, $action); 94 } 95 else 96 { 97 trigger_error('NO_POST_SELECTED'); 98 } 99 break; 100 101 case 'disapprove': 102 $post_id_list = $request->variable('post_id_list', array(0)); 103 $topic_id_list = $request->variable('topic_id_list', array(0)); 104 105 if (!empty($topic_id_list) && $mode == 'deleted_topics') 106 { 107 if (!function_exists('mcp_delete_topic')) 108 { 109 global $phpbb_root_path, $phpEx; 110 include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); 111 } 112 mcp_delete_topic($topic_id_list, false, '', 'disapprove'); 113 return; 114 } 115 116 if (!class_exists('messenger')) 117 { 118 include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); 119 } 120 121 if (!empty($topic_id_list)) 122 { 123 $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : array(ITEM_UNAPPROVED, ITEM_REAPPROVE); 124 $sql = 'SELECT post_id 125 FROM ' . POSTS_TABLE . ' 126 WHERE ' . $db->sql_in_set('post_visibility', $post_visibility) . ' 127 AND ' . $db->sql_in_set('topic_id', $topic_id_list); 128 $result = $db->sql_query($sql); 129 130 $post_id_list = array(); 131 while ($row = $db->sql_fetchrow($result)) 132 { 133 $post_id_list[] = (int) $row['post_id']; 134 } 135 $db->sql_freeresult($result); 136 } 137 138 if (!empty($post_id_list)) 139 { 140 self::disapprove_posts($post_id_list, 'queue', $mode); 141 } 142 else 143 { 144 trigger_error('NO_POST_SELECTED'); 145 } 146 break; 147 } 148 149 switch ($mode) 150 { 151 case 'approve_details': 152 153 $this->tpl_name = 'mcp_post'; 154 155 $user->add_lang(array('posting', 'viewtopic')); 156 157 $post_id = $request->variable('p', 0); 158 $topic_id = $request->variable('t', 0); 159 $topic_info = []; 160 161 /* @var $phpbb_notifications \phpbb\notification\manager */ 162 $phpbb_notifications = $phpbb_container->get('notification_manager'); 163 164 if ($topic_id) 165 { 166 $topic_info = phpbb_get_topic_data(array($topic_id), 'm_approve'); 167 if (isset($topic_info[$topic_id]['topic_first_post_id'])) 168 { 169 $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; 170 171 $phpbb_notifications->mark_notifications('topic_in_queue', $topic_id, $user->data['user_id']); 172 } 173 else 174 { 175 $topic_id = 0; 176 } 177 } 178 179 $phpbb_notifications->mark_notifications('post_in_queue', $post_id, $user->data['user_id']); 180 181 $post_info = phpbb_get_post_data(array($post_id), 'm_approve', true); 182 183 if (!count($post_info)) 184 { 185 trigger_error('NO_POST_SELECTED'); 186 } 187 188 $post_info = $post_info[$post_id]; 189 190 if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false)) 191 { 192 $template->assign_vars(array( 193 'S_TOPIC_REVIEW' => true, 194 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'], 195 'TOPIC_TITLE' => $post_info['topic_title'], 196 )); 197 } 198 199 $attachments = $topic_tracking_info = array(); 200 201 // Get topic tracking info 202 if ($config['load_db_lastread']) 203 { 204 $tmp_topic_data = array($post_info['topic_id'] => $post_info); 205 $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'])); 206 unset($tmp_topic_data); 207 } 208 else 209 { 210 $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']); 211 } 212 213 $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false; 214 215 // Process message, leave it uncensored 216 $parse_flags = ($post_info['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES; 217 $message = generate_text_for_display($post_info['post_text'], $post_info['bbcode_uid'], $post_info['bbcode_bitfield'], $parse_flags, false); 218 219 if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) 220 { 221 $sql = 'SELECT * 222 FROM ' . ATTACHMENTS_TABLE . ' 223 WHERE post_msg_id = ' . $post_id . ' 224 AND in_message = 0 225 ORDER BY filetime DESC, post_msg_id ASC'; 226 $result = $db->sql_query($sql); 227 228 while ($row = $db->sql_fetchrow($result)) 229 { 230 $attachments[] = $row; 231 } 232 $db->sql_freeresult($result); 233 234 if (count($attachments)) 235 { 236 $update_count = array(); 237 parse_attachments($post_info['forum_id'], $message, $attachments, $update_count); 238 } 239 240 // Display not already displayed Attachments for this post, we already parsed them. ;) 241 if (!empty($attachments)) 242 { 243 $template->assign_var('S_HAS_ATTACHMENTS', true); 244 245 foreach ($attachments as $attachment) 246 { 247 $template->assign_block_vars('attachment', array( 248 'DISPLAY_ATTACHMENT' => $attachment, 249 )); 250 } 251 } 252 } 253 254 // Deleting information 255 if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user']) 256 { 257 // User having deleted the post also being the post author? 258 if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id']) 259 { 260 $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']); 261 } 262 else 263 { 264 $sql = 'SELECT u.user_id, u.username, u.user_colour 265 FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u 266 WHERE p.post_id = ' . $post_info['post_id'] . ' 267 AND p.post_delete_user = u.user_id'; 268 $result = $db->sql_query($sql); 269 $post_delete_userinfo = $db->sql_fetchrow($result); 270 $db->sql_freeresult($result); 271 $display_username = get_username_string('full', $post_info['post_delete_user'], $post_delete_userinfo['username'], $post_delete_userinfo['user_colour']); 272 } 273 274 $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true)); 275 } 276 else 277 { 278 $l_deleted_by = ''; 279 } 280 281 $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $post_info['post_id'] . '#p' . $post_info['post_id']); 282 $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $post_info['topic_id']); 283 284 $post_data = array( 285 'S_MCP_QUEUE' => true, 286 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id"), 287 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 288 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 289 'S_POST_REPORTED' => $post_info['post_reported'], 290 'S_POST_UNAPPROVED' => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE, 291 'S_POST_LOCKED' => $post_info['post_edit_locked'], 292 'S_USER_NOTES' => true, 293 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED), 294 'DELETED_MESSAGE' => $l_deleted_by, 295 'DELETE_REASON' => $post_info['post_delete_reason'], 296 297 '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']}") : '', 298 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&p=' . $post_id), 299 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&p=' . $post_id), 300 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']), 301 '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']) : '', 302 'U_VIEW_POST' => $post_url, 303 'U_VIEW_TOPIC' => $topic_url, 304 305 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), 306 307 'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue' . (($topic_id) ? '&mode=unapproved_topics' : '&mode=unapproved_posts')) . '&start=' . $start . '">', '</a>'), 308 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'), 309 'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'), 310 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), 311 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']), 312 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']), 313 314 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 315 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 316 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 317 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 318 319 'POST_PREVIEW' => $message, 320 'POST_SUBJECT' => $post_info['post_subject'], 321 'POST_DATE' => $user->format_date($post_info['post_time']), 322 'POST_IP' => $post_info['poster_ip'], 323 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && $request->variable('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '', 324 'POST_ID' => $post_info['post_id'], 325 'S_FIRST_POST' => ($post_info['topic_first_post_id'] == $post_id), 326 327 'U_LOOKUP_IP' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&p=' . $post_id . '&lookup=' . $post_info['poster_ip']) . '#ip' : '', 328 ); 329 330 /** 331 * Alter post awaiting approval template before it is rendered 332 * 333 * @event core.mcp_queue_approve_details_template 334 * @var int post_id Post ID 335 * @var int topic_id Topic ID 336 * @var array topic_info Topic data 337 * @var array post_info Post data 338 * @var array post_data Post template data 339 * @var string message Post message 340 * @var string post_url Post URL 341 * @var string topic_url Topic URL 342 * @since 3.2.2-RC1 343 */ 344 $vars = array( 345 'post_id', 346 'topic_id', 347 'topic_info', 348 'post_info', 349 'post_data', 350 'message', 351 'post_url', 352 'topic_url', 353 ); 354 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_approve_details_template', compact($vars))); 355 356 $template->assign_vars($post_data); 357 358 break; 359 360 case 'unapproved_topics': 361 case 'unapproved_posts': 362 case 'deleted_topics': 363 case 'deleted_posts': 364 $m_perm = 'm_approve'; 365 $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false; 366 $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false; 367 $visibility_const = (!$is_restore) ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED; 368 369 $user->add_lang(array('viewtopic', 'viewforum')); 370 371 $topic_id = $request->variable('t', 0); 372 $forum_info = array(); 373 374 // If 'sort' is set, "Go" was pressed which is located behind the forums <select> box 375 // Then, unset the topic id so it does not override the forum id 376 $topic_id = $request->is_set_post('sort') ? 0 : $topic_id; 377 378 if ($topic_id) 379 { 380 $topic_info = phpbb_get_topic_data(array($topic_id)); 381 382 if (!count($topic_info)) 383 { 384 trigger_error('TOPIC_NOT_EXIST'); 385 } 386 387 $topic_info = $topic_info[$topic_id]; 388 $forum_id = $topic_info['forum_id']; 389 } 390 391 $forum_list_approve = get_forum_list($m_perm, false, true); 392 $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs 393 394 // Remove forums we cannot read 395 foreach ($forum_list_approve as $k => $forum_data) 396 { 397 if (!isset($forum_list_read[$forum_data['forum_id']])) 398 { 399 unset($forum_list_approve[$k]); 400 } 401 } 402 unset($forum_list_read); 403 404 if (!$forum_id) 405 { 406 $forum_list = array(); 407 foreach ($forum_list_approve as $row) 408 { 409 $forum_list[] = $row['forum_id']; 410 } 411 412 if (!count($forum_list)) 413 { 414 trigger_error('NOT_MODERATOR'); 415 } 416 417 $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics 418 FROM ' . FORUMS_TABLE . ' 419 WHERE ' . $db->sql_in_set('forum_id', $forum_list); 420 $result = $db->sql_query($sql); 421 $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics'); 422 $db->sql_freeresult($result); 423 } 424 else 425 { 426 $forum_info = phpbb_get_forum_data(array($forum_id), $m_perm); 427 428 if (!count($forum_info)) 429 { 430 trigger_error('NOT_MODERATOR'); 431 } 432 433 $forum_list = $forum_id; 434 } 435 436 $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>'; 437 foreach ($forum_list_approve as $row) 438 { 439 $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>'; 440 } 441 442 $sort_days = $total = 0; 443 $sort_key = $sort_dir = ''; 444 $sort_by_sql = $sort_order_sql = array(); 445 phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); 446 447 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; 448 449 $forum_names = array(); 450 451 if (!$is_topics) 452 { 453 $sql = 'SELECT p.post_id 454 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . ' 455 WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . ' 456 AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) . ' 457 ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' 458 ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " 459 AND t.topic_id = p.topic_id 460 AND (t.topic_visibility <> p.post_visibility 461 OR t.topic_delete_user = 0) 462 $limit_time_sql 463 ORDER BY $sort_order_sql"; 464 465 /** 466 * Alter sql query to get posts in queue to be accepted 467 * 468 * @event core.mcp_queue_get_posts_query_before 469 * @var string sql Associative array with the query to be executed 470 * @var array forum_list List of forums that contain the posts 471 * @var int visibility_const Integer with one of the possible ITEM_* constant values 472 * @var int topic_id If topic_id not equal to 0, the topic id to filter the posts to display 473 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) 474 * @var string sort_order_sql String with the ORDER BY SQL code used in this query 475 * @since 3.1.0-RC3 476 */ 477 $vars = array( 478 'sql', 479 'forum_list', 480 'visibility_const', 481 'topic_id', 482 'limit_time_sql', 483 'sort_order_sql', 484 ); 485 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_query_before', compact($vars))); 486 487 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); 488 489 $i = 0; 490 $post_ids = array(); 491 while ($row = $db->sql_fetchrow($result)) 492 { 493 $post_ids[] = $row['post_id']; 494 $row_num[$row['post_id']] = $i++; 495 } 496 $db->sql_freeresult($result); 497 498 if (count($post_ids)) 499 { 500 $sql = 'SELECT t.topic_id, t.topic_title, t.forum_id, 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 501 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u 502 WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' 503 AND t.topic_id = p.topic_id 504 AND u.user_id = p.poster_id 505 ORDER BY ' . $sort_order_sql; 506 507 /** 508 * Alter sql query to get information on all posts in queue 509 * 510 * @event core.mcp_queue_get_posts_for_posts_query_before 511 * @var string sql String with the query to be executed 512 * @var array forum_list List of forums that contain the posts 513 * @var int visibility_const Integer with one of the possible ITEM_* constant values 514 * @var int topic_id topic_id in the page request 515 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) 516 * @var string sort_order_sql String with the ORDER BY SQL code used in this query 517 * @since 3.2.3-RC2 518 */ 519 $vars = array( 520 'sql', 521 'forum_list', 522 'visibility_const', 523 'topic_id', 524 'limit_time_sql', 525 'sort_order_sql', 526 ); 527 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_posts_query_before', compact($vars))); 528 529 $result = $db->sql_query($sql); 530 531 $post_data = $rowset = array(); 532 while ($row = $db->sql_fetchrow($result)) 533 { 534 $forum_names[] = $row['forum_id']; 535 $post_data[$row['post_id']] = $row; 536 } 537 $db->sql_freeresult($result); 538 539 foreach ($post_ids as $post_id) 540 { 541 $rowset[] = $post_data[$post_id]; 542 } 543 unset($post_data, $post_ids); 544 } 545 else 546 { 547 $rowset = array(); 548 } 549 } 550 else 551 { 552 $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_attachment AS post_attachment, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour 553 FROM ' . TOPICS_TABLE . ' t 554 WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' 555 AND ' . $db->sql_in_set('topic_visibility', $visibility_const) . " 556 AND topic_delete_user <> 0 557 $limit_time_sql 558 ORDER BY $sort_order_sql"; 559 560 /** 561 * Alter sql query to get information on all topics in the list of forums provided. 562 * 563 * @event core.mcp_queue_get_posts_for_topics_query_before 564 * @var string sql String with the query to be executed 565 * @var array forum_list List of forums that contain the posts 566 * @var int visibility_const Integer with one of the possible ITEM_* constant values 567 * @var int topic_id topic_id in the page request 568 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) 569 * @var string sort_order_sql String with the ORDER BY SQL code used in this query 570 * @since 3.1.0-RC3 571 */ 572 $vars = array( 573 'sql', 574 'forum_list', 575 'visibility_const', 576 'topic_id', 577 'limit_time_sql', 578 'sort_order_sql', 579 ); 580 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_topics_query_before', compact($vars))); 581 582 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); 583 584 $rowset = array(); 585 while ($row = $db->sql_fetchrow($result)) 586 { 587 $forum_names[] = $row['forum_id']; 588 $rowset[] = $row; 589 } 590 $db->sql_freeresult($result); 591 } 592 593 if (count($forum_names)) 594 { 595 // Select the names for the forum_ids 596 $sql = 'SELECT forum_id, forum_name 597 FROM ' . FORUMS_TABLE . ' 598 WHERE ' . $db->sql_in_set('forum_id', $forum_names); 599 $result = $db->sql_query($sql, 3600); 600 601 $forum_names = array(); 602 while ($row = $db->sql_fetchrow($result)) 603 { 604 $forum_names[$row['forum_id']] = $row['forum_name']; 605 } 606 $db->sql_freeresult($result); 607 } 608 609 foreach ($rowset as $row) 610 { 611 if (empty($row['post_username'])) 612 { 613 $row['post_username'] = $row['username'] ?: $user->lang['GUEST']; 614 } 615 616 $post_row = array( 617 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $row['topic_id']), 618 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']), 619 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''), 620 'U_VIEW_DETAILS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&start=$start&mode=approve_details&p={$row['post_id']}" . (($mode == 'unapproved_topics') ? "&t={$row['topic_id']}" : '')), 621 622 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 623 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 624 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 625 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 626 627 'POST_ID' => $row['post_id'], 628 'TOPIC_ID' => $row['topic_id'], 629 'FORUM_NAME' => $forum_names[$row['forum_id']], 630 'POST_SUBJECT' => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 631 'TOPIC_TITLE' => $row['topic_title'], 632 'POST_TIME' => $user->format_date($row['post_time']), 633 'S_HAS_ATTACHMENTS' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment'], 634 ); 635 636 /** 637 * Alter sql query to get information on all topics in the list of forums provided. 638 * 639 * @event core.mcp_queue_get_posts_modify_post_row 640 * @var array post_row Template variables for current post 641 * @var array row Post data 642 * @var array forum_names Forum names 643 * @since 3.2.3-RC2 644 */ 645 $vars = array( 646 'post_row', 647 'row', 648 'forum_names', 649 ); 650 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_modify_post_row', compact($vars))); 651 652 $template->assign_block_vars('postrow', $post_row); 653 } 654 unset($rowset, $forum_names); 655 656 /* @var \phpbb\pagination $pagination */ 657 $pagination = $phpbb_container->get('pagination'); 658 659 $base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; 660 $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); 661 662 // Now display the page 663 $template->assign_vars(array( 664 'L_DISPLAY_ITEMS' => (!$is_topics) ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], 665 'L_EXPLAIN' => $user->lang['MCP_QUEUE_' . strtoupper($mode) . '_EXPLAIN'], 666 'L_TITLE' => $user->lang['MCP_QUEUE_' . strtoupper($mode)], 667 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '', 668 669 'S_FORUM_OPTIONS' => $forum_options, 670 'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')), 671 'S_TOPICS' => $is_topics, 672 'S_RESTORE' => $is_restore, 673 674 'TOPIC_ID' => $topic_id, 675 'TOTAL' => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total), 676 )); 677 678 $this->tpl_name = 'mcp_queue'; 679 break; 680 } 681 } 682 683 /** 684 * Approve/Restore posts 685 * 686 * @param $action string Action we perform on the posts ('approve' or 'restore') 687 * @param $post_id_list array IDs of the posts to approve/restore 688 * @param $id mixed Category of the current active module 689 * @param $mode string Active module 690 * @return null 691 */ 692 static public function approve_posts($action, $post_id_list, $id, $mode) 693 { 694 global $template, $user, $request, $phpbb_container, $phpbb_dispatcher; 695 global $phpEx, $phpbb_root_path, $phpbb_log; 696 697 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) 698 { 699 send_status_line(403, 'Forbidden'); 700 trigger_error('NOT_AUTHORISED'); 701 } 702 703 $redirect = $request->variable('redirect', build_url(array('quickmod'))); 704 $redirect = reapply_sid($redirect); 705 $post_url = ''; 706 $approve_log = array(); 707 $num_topics = 0; 708 709 $s_hidden_fields = build_hidden_fields(array( 710 'i' => $id, 711 'mode' => $mode, 712 'post_id_list' => $post_id_list, 713 'action' => $action, 714 'redirect' => $redirect, 715 )); 716 717 $post_info = phpbb_get_post_data($post_id_list, 'm_approve'); 718 719 if (confirm_box(true)) 720 { 721 $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])); 722 723 $topic_info = array(); 724 725 // Group the posts by topic_id 726 foreach ($post_info as $post_id => $post_data) 727 { 728 if ($post_data['post_visibility'] == ITEM_APPROVED) 729 { 730 continue; 731 } 732 $topic_id = (int) $post_data['topic_id']; 733 734 $topic_info[$topic_id]['posts'][] = (int) $post_id; 735 $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id']; 736 737 // Refresh the first post, if the time or id is older then the current one 738 if ($post_id <= $post_data['topic_first_post_id'] || $post_data['post_time'] <= $post_data['topic_time']) 739 { 740 $topic_info[$topic_id]['first_post'] = true; 741 } 742 743 // Refresh the last post, if the time or id is newer then the current one 744 if ($post_id >= $post_data['topic_last_post_id'] || $post_data['post_time'] >= $post_data['topic_last_post_time']) 745 { 746 $topic_info[$topic_id]['last_post'] = true; 747 } 748 749 $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p={$post_data['post_id']}") . '#p' . $post_data['post_id']; 750 751 $approve_log[] = array( 752 'forum_id' => $post_data['forum_id'], 753 'topic_id' => $post_data['topic_id'], 754 'post_id' => $post_id, 755 'post_subject' => $post_data['post_subject'], 756 ); 757 } 758 759 /* @var $phpbb_content_visibility \phpbb\content_visibility */ 760 $phpbb_content_visibility = $phpbb_container->get('content.visibility'); 761 foreach ($topic_info as $topic_id => $topic_data) 762 { 763 $phpbb_content_visibility->set_post_visibility(ITEM_APPROVED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '', isset($topic_data['first_post']), isset($topic_data['last_post'])); 764 } 765 766 foreach ($approve_log as $log_data) 767 { 768 $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_POST_' . strtoupper($action) . 'D', false, array( 769 'forum_id' => $log_data['forum_id'], 770 'topic_id' => $log_data['topic_id'], 771 'post_id' => $log_data['post_id'], 772 $log_data['post_subject'] 773 )); 774 } 775 776 // Only send out the mails, when the posts are being approved 777 if ($action == 'approve') 778 { 779 /* @var $phpbb_notifications \phpbb\notification\manager */ 780 $phpbb_notifications = $phpbb_container->get('notification_manager'); 781 782 // Handle notifications 783 foreach ($post_info as $post_id => $post_data) 784 { 785 // A single topic approval may also happen here, so handle deleting the respective notification. 786 if (!$post_data['topic_posts_approved']) 787 { 788 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']); 789 790 if ($post_data['post_visibility'] == ITEM_UNAPPROVED) 791 { 792 $phpbb_notifications->add_notifications(array('notification.type.topic'), $post_data); 793 } 794 if ($post_data['post_visibility'] != ITEM_APPROVED) 795 { 796 $num_topics++; 797 } 798 } 799 else 800 { 801 // Only add notifications, if we are not reapproving post 802 // When the topic was already approved, but was edited and 803 // now needs re-approval, we don't want to notify the users 804 // again. 805 if ($post_data['post_visibility'] == ITEM_UNAPPROVED) 806 { 807 $phpbb_notifications->add_notifications(array( 808 'notification.type.bookmark', 809 'notification.type.post', 810 ), $post_data); 811 } 812 } 813 $phpbb_notifications->add_notifications(array('notification.type.quote'), $post_data); 814 $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id); 815 816 $phpbb_notifications->mark_notifications(array( 817 'notification.type.quote', 818 'notification.type.bookmark', 819 'notification.type.post', 820 ), $post_data['post_id'], $user->data['user_id']); 821 822 // Notify Poster? 823 if ($notify_poster) 824 { 825 if ($post_data['poster_id'] == ANONYMOUS) 826 { 827 continue; 828 } 829 830 if (!$post_data['topic_posts_approved']) 831 { 832 $phpbb_notifications->add_notifications('notification.type.approve_topic', $post_data); 833 } 834 else 835 { 836 $phpbb_notifications->add_notifications('notification.type.approve_post', $post_data); 837 } 838 } 839 } 840 } 841 842 if ($num_topics >= 1) 843 { 844 $success_msg = ($num_topics == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; 845 } 846 else 847 { 848 $success_msg = (count($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS'; 849 } 850 851 /** 852 * Perform additional actions during post(s) approval 853 * 854 * @event core.approve_posts_after 855 * @var string action Variable containing the action we perform on the posts ('approve' or 'restore') 856 * @var array post_info Array containing info for all posts being approved 857 * @var array topic_info Array containing info for all parent topics of the posts 858 * @var int num_topics Variable containing number of topics 859 * @var bool notify_poster Variable telling if the post should be notified or not 860 * @var string success_msg Variable containing the language key for the success message 861 * @var string redirect Variable containing the redirect url 862 * @since 3.1.4-RC1 863 */ 864 $vars = array( 865 'action', 866 'post_info', 867 'topic_info', 868 'num_topics', 869 'notify_poster', 870 'success_msg', 871 'redirect', 872 ); 873 extract($phpbb_dispatcher->trigger_event('core.approve_posts_after', compact($vars))); 874 875 meta_refresh(3, $redirect); 876 $message = $user->lang[$success_msg]; 877 878 if ($request->is_ajax()) 879 { 880 $json_response = new \phpbb\json_response; 881 $json_response->send(array( 882 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 883 'MESSAGE_TEXT' => $message, 884 'REFRESH_DATA' => null, 885 'visible' => true, 886 )); 887 } 888 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>'); 889 890 // If approving one post, also give links back to post... 891 if (count($post_info) == 1 && $post_url) 892 { 893 $message .= '<br /><br />' . $user->lang('RETURN_POST', '<a href="' . $post_url . '">', '</a>'); 894 } 895 trigger_error($message); 896 } 897 else 898 { 899 $show_notify = false; 900 901 if ($action == 'approve') 902 { 903 foreach ($post_info as $post_data) 904 { 905 if (!$post_data['topic_posts_approved']) 906 { 907 $num_topics++; 908 } 909 910 if (!$show_notify && $post_data['poster_id'] != ANONYMOUS) 911 { 912 $show_notify = true; 913 } 914 } 915 } 916 917 $template->assign_vars(array( 918 'S_NOTIFY_POSTER' => $show_notify, 919 'S_' . strtoupper($action) => true, 920 )); 921 922 // Create the confirm box message 923 $action_msg = strtoupper($action); 924 $num_posts = count($post_id_list) - $num_topics; 925 if ($num_topics > 0 && $num_posts <= 0) 926 { 927 $action_msg .= '_TOPIC' . (($num_topics == 1) ? '' : 'S'); 928 } 929 else 930 { 931 $action_msg .= '_POST' . ((count($post_id_list) == 1) ? '' : 'S'); 932 } 933 confirm_box(false, $action_msg, $s_hidden_fields, 'mcp_approve.html'); 934 } 935 936 redirect($redirect); 937 } 938 939 /** 940 * Approve/Restore topics 941 * 942 * @param $action string Action we perform on the posts ('approve' or 'restore') 943 * @param $topic_id_list array IDs of the topics to approve/restore 944 * @param $id mixed Category of the current active module 945 * @param $mode string Active module 946 * @return null 947 */ 948 static public function approve_topics($action, $topic_id_list, $id, $mode) 949 { 950 global $db, $template, $user, $phpbb_log; 951 global $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_dispatcher; 952 953 if (!phpbb_check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) 954 { 955 send_status_line(403, 'Forbidden'); 956 trigger_error('NOT_AUTHORISED'); 957 } 958 959 $redirect = $request->variable('redirect', build_url(array('quickmod'))); 960 $redirect = reapply_sid($redirect); 961 $success_msg = $topic_url = ''; 962 $approve_log = array(); 963 964 $s_hidden_fields = build_hidden_fields(array( 965 'i' => $id, 966 'mode' => $mode, 967 'topic_id_list' => $topic_id_list, 968 'action' => $action, 969 'redirect' => $redirect, 970 )); 971 972 $topic_info = phpbb_get_topic_data($topic_id_list, 'm_approve'); 973 974 if (confirm_box(true)) 975 { 976 $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; 977 978 /* @var $phpbb_content_visibility \phpbb\content_visibility */ 979 $phpbb_content_visibility = $phpbb_container->get('content.visibility'); 980 $first_post_ids = array(); 981 982 foreach ($topic_info as $topic_id => $topic_data) 983 { 984 $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); 985 $first_post_ids[$topic_id] = (int) $topic_data['topic_first_post_id']; 986 987 $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$topic_id}"); 988 989 $approve_log[] = array( 990 'forum_id' => $topic_data['forum_id'], 991 'topic_id' => $topic_data['topic_id'], 992 'topic_title' => $topic_data['topic_title'], 993 ); 994 } 995 996 if (count($topic_info) >= 1) 997 { 998 $success_msg = (count($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; 999 } 1000 1001 foreach ($approve_log as $log_data) 1002 { 1003 $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_TOPIC_' . strtoupper($action) . 'D', false, array( 1004 'forum_id' => $log_data['forum_id'], 1005 'topic_id' => $log_data['topic_id'], 1006 $log_data['topic_title'] 1007 )); 1008 } 1009 1010 // Only send out the mails, when the posts are being approved 1011 if ($action == 'approve') 1012 { 1013 // Grab the first post text as it's needed for the quote notification. 1014 $sql = 'SELECT topic_id, post_text 1015 FROM ' . POSTS_TABLE . ' 1016 WHERE ' . $db->sql_in_set('post_id', $first_post_ids); 1017 $result = $db->sql_query($sql); 1018 1019 while ($row = $db->sql_fetchrow($result)) 1020 { 1021 $topic_info[$row['topic_id']]['post_text'] = $row['post_text']; 1022 } 1023 $db->sql_freeresult($result); 1024 1025 // Handle notifications 1026 /* @var $phpbb_notifications \phpbb\notification\manager */ 1027 $phpbb_notifications = $phpbb_container->get('notification_manager'); 1028 1029 foreach ($topic_info as $topic_id => $topic_data) 1030 { 1031 $topic_data = array_merge($topic_data, array( 1032 'post_id' => $topic_data['topic_first_post_id'], 1033 'post_subject' => $topic_data['topic_title'], 1034 'post_time' => $topic_data['topic_time'], 1035 'poster_id' => $topic_data['topic_poster'], 1036 'post_username' => $topic_data['topic_first_poster_name'], 1037 )); 1038 1039 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $topic_id); 1040 1041 // Only add notifications, if we are not reapproving post 1042 // When the topic was already approved, but was edited and 1043 // now needs re-approval, we don't want to notify the users 1044 // again. 1045 if ($topic_data['topic_visibility'] == ITEM_UNAPPROVED) 1046 { 1047 $phpbb_notifications->add_notifications(array( 1048 'notification.type.quote', 1049 'notification.type.topic', 1050 ), $topic_data); 1051 } 1052 1053 $phpbb_notifications->mark_notifications('quote', $topic_data['post_id'], $user->data['user_id']); 1054 $phpbb_notifications->mark_notifications('topic', $topic_id, $user->data['user_id']); 1055 1056 if ($notify_poster) 1057 { 1058 $phpbb_notifications->add_notifications('notification.type.approve_topic', $topic_data); 1059 } 1060 } 1061 } 1062 1063 /** 1064 * Perform additional actions during topics(s) approval 1065 * 1066 * @event core.approve_topics_after 1067 * @var string action Variable containing the action we perform on the posts ('approve' or 'restore') 1068 * @var mixed topic_info Array containing info for all topics being approved 1069 * @var array first_post_ids Array containing ids of all first posts 1070 * @var bool notify_poster Variable telling if the poster should be notified or not 1071 * @var string success_msg Variable containing the language key for the success message 1072 * @var string redirect Variable containing the redirect url 1073 * @since 3.1.4-RC1 1074 */ 1075 $vars = array( 1076 'action', 1077 'topic_info', 1078 'first_post_ids', 1079 'notify_poster', 1080 'success_msg', 1081 'redirect', 1082 ); 1083 extract($phpbb_dispatcher->trigger_event('core.approve_topics_after', compact($vars))); 1084 1085 meta_refresh(3, $redirect); 1086 $message = $user->lang[$success_msg]; 1087 1088 if ($request->is_ajax()) 1089 { 1090 $json_response = new \phpbb\json_response; 1091 $json_response->send(array( 1092 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 1093 'MESSAGE_TEXT' => $message, 1094 'REFRESH_DATA' => null, 1095 'visible' => true, 1096 )); 1097 } 1098 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>'); 1099 1100 // If approving one topic, also give links back to topic... 1101 if (count($topic_info) == 1 && $topic_url) 1102 { 1103 $message .= '<br /><br />' . $user->lang('RETURN_TOPIC', '<a href="' . $topic_url . '">', '</a>'); 1104 } 1105 trigger_error($message); 1106 } 1107 else 1108 { 1109 $show_notify = false; 1110 1111 if ($action == 'approve') 1112 { 1113 foreach ($topic_info as $topic_data) 1114 { 1115 if ($topic_data['topic_poster'] == ANONYMOUS) 1116 { 1117 continue; 1118 } 1119 else 1120 { 1121 $show_notify = true; 1122 break; 1123 } 1124 } 1125 } 1126 1127 $template->assign_vars(array( 1128 'S_NOTIFY_POSTER' => $show_notify, 1129 'S_' . strtoupper($action) => true, 1130 )); 1131 1132 confirm_box(false, strtoupper($action) . '_TOPIC' . ((count($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); 1133 } 1134 1135 redirect($redirect); 1136 } 1137 1138 /** 1139 * Disapprove Post 1140 * 1141 * @param $post_id_list array IDs of the posts to disapprove/delete 1142 * @param $id mixed Category of the current active module 1143 * @param $mode string Active module 1144 * @return null 1145 */ 1146 static public function disapprove_posts($post_id_list, $id, $mode) 1147 { 1148 global $db, $template, $user, $phpbb_container, $phpbb_dispatcher; 1149 global $phpEx, $phpbb_root_path, $request, $phpbb_log; 1150 1151 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) 1152 { 1153 send_status_line(403, 'Forbidden'); 1154 trigger_error('NOT_AUTHORISED'); 1155 } 1156 1157 $redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); 1158 $redirect = reapply_sid($redirect); 1159 $reason = $request->variable('reason', '', true); 1160 $reason_id = $request->variable('reason_id', 0); 1161 $additional_msg = ''; 1162 1163 $s_hidden_fields = build_hidden_fields(array( 1164 'i' => $id, 1165 'mode' => $mode, 1166 'post_id_list' => $post_id_list, 1167 'action' => 'disapprove', 1168 'redirect' => $redirect, 1169 )); 1170 1171 $notify_poster = $request->is_set('notify_poster'); 1172 $disapprove_reason = ''; 1173 1174 if ($reason_id) 1175 { 1176 $sql = 'SELECT reason_title, reason_description 1177 FROM ' . REPORTS_REASONS_TABLE . " 1178 WHERE reason_id = $reason_id"; 1179 $result = $db->sql_query($sql); 1180 $row = $db->sql_fetchrow($result); 1181 $db->sql_freeresult($result); 1182 1183 if (!$row || (!$reason && strtolower($row['reason_title']) == 'other')) 1184 { 1185 $additional_msg = $user->lang['NO_REASON_DISAPPROVAL']; 1186 1187 $request->overwrite('confirm', null, \phpbb\request\request_interface::POST); 1188 $request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST); 1189 $request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST); 1190 } 1191 else 1192 { 1193 // If the reason is defined within the language file, we will use the localized version, else just use the database entry... 1194 $disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : ''; 1195 $disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; 1196 1197 if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) 1198 { 1199 $disapprove_reason_lang = strtoupper($row['reason_title']); 1200 } 1201 } 1202 } 1203 1204 $post_info = phpbb_get_post_data($post_id_list, 'm_approve'); 1205 1206 $is_disapproving = false; 1207 foreach ($post_info as $post_id => $post_data) 1208 { 1209 if ($post_data['post_visibility'] == ITEM_DELETED) 1210 { 1211 continue; 1212 } 1213 1214 $is_disapproving = true; 1215 } 1216 1217 if (confirm_box(true)) 1218 { 1219 $disapprove_log_topics = $disapprove_log_posts = array(); 1220 $topic_posts_unapproved = $post_disapprove_list = $topic_information = array(); 1221 1222 // Build a list of posts to be disapproved and get the related topics real replies count 1223 foreach ($post_info as $post_id => $post_data) 1224 { 1225 if ($mode === 'unapproved_topics' && $post_data['post_visibility'] == ITEM_APPROVED) 1226 { 1227 continue; 1228 } 1229 1230 $post_disapprove_list[$post_id] = $post_data['topic_id']; 1231 if (!isset($topic_posts_unapproved[$post_data['topic_id']])) 1232 { 1233 $topic_information[$post_data['topic_id']] = $post_data; 1234 $topic_posts_unapproved[$post_data['topic_id']] = 0; 1235 } 1236 $topic_posts_unapproved[$post_data['topic_id']]++; 1237 } 1238 1239 // Do not try to disapprove if no posts are selected 1240 if (empty($post_disapprove_list)) 1241 { 1242 trigger_error('NO_POST_SELECTED'); 1243 } 1244 1245 // Now we build the log array 1246 foreach ($post_disapprove_list as $post_id => $topic_id) 1247 { 1248 // If the count of disapproved posts for the topic is equal 1249 // to the number of unapproved posts in the topic, and there are no different 1250 // posts, we disapprove the hole topic 1251 if ($topic_information[$topic_id]['topic_posts_approved'] == 0 && 1252 $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && 1253 $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]) 1254 { 1255 // Don't write the log more than once for every topic 1256 if (!isset($disapprove_log_topics[$topic_id])) 1257 { 1258 // Build disapproved topics log 1259 $disapprove_log_topics[$topic_id] = array( 1260 'type' => 'topic', 1261 'post_subject' => $post_info[$post_id]['topic_title'], 1262 'forum_id' => $post_info[$post_id]['forum_id'], 1263 'topic_id' => 0, // useless to log a topic id, as it will be deleted 1264 'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'], 1265 ); 1266 } 1267 } 1268 else 1269 { 1270 // Build disapproved posts log 1271 $disapprove_log_posts[] = array( 1272 'type' => 'post', 1273 'post_subject' => $post_info[$post_id]['post_subject'], 1274 'forum_id' => $post_info[$post_id]['forum_id'], 1275 'topic_id' => $post_info[$post_id]['topic_id'], 1276 'post_username' => ($post_info[$post_id]['poster_id'] == ANONYMOUS && !empty($post_info[$post_id]['post_username'])) ? $post_info[$post_id]['post_username'] : $post_info[$post_id]['username'], 1277 ); 1278 1279 } 1280 } 1281 1282 // Get disapproved posts/topics counts separately 1283 $num_disapproved_topics = count($disapprove_log_topics); 1284 $num_disapproved_posts = count($disapprove_log_posts); 1285 1286 // Build the whole log 1287 $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts); 1288 1289 // Unset unneeded arrays 1290 unset($post_data, $disapprove_log_topics, $disapprove_log_posts); 1291 1292 // Let's do the job - delete disapproved posts 1293 if (count($post_disapprove_list)) 1294 { 1295 if (!function_exists('delete_posts')) 1296 { 1297 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); 1298 } 1299 1300 // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts 1301 // Note: function delete_posts triggers related forums/topics sync, 1302 // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually 1303 delete_posts('post_id', array_keys($post_disapprove_list)); 1304 1305 foreach ($disapprove_log as $log_data) 1306 { 1307 if ($is_disapproving) 1308 { 1309 $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED'; 1310 $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array( 1311 'forum_id' => $log_data['forum_id'], 1312 'topic_id' => $log_data['topic_id'], 1313 $log_data['post_subject'], 1314 $disapprove_reason, 1315 $log_data['post_username'] 1316 )); 1317 } 1318 else 1319 { 1320 $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST'; 1321 $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array( 1322 'forum_id' => $log_data['forum_id'], 1323 'topic_id' => $log_data['topic_id'], 1324 $log_data['post_subject'], 1325 $log_data['post_username'] 1326 )); 1327 } 1328 } 1329 } 1330 1331 /* @var $phpbb_notifications \phpbb\notification\manager */ 1332 $phpbb_notifications = $phpbb_container->get('notification_manager'); 1333 1334 $lang_reasons = array(); 1335 1336 foreach ($post_info as $post_id => $post_data) 1337 { 1338 $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 && 1339 $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && 1340 $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]; 1341 1342 $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id); 1343 1344 // Do we disapprove the whole topic? Remove potential notifications 1345 if ($disapprove_all_posts_in_topic) 1346 { 1347 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']); 1348 } 1349 1350 // Notify Poster? 1351 if ($notify_poster) 1352 { 1353 if ($post_data['poster_id'] == ANONYMOUS) 1354 { 1355 continue; 1356 } 1357 1358 $post_data['disapprove_reason'] = $disapprove_reason; 1359 if (isset($disapprove_reason_lang)) 1360 { 1361 // Okay we need to get the reason from the posters language 1362 if (!isset($lang_reasons[$post_data['user_lang']])) 1363 { 1364 // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity. 1365 $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; 1366 1367 // Only load up the language pack if the language is different to the current one 1368 if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) 1369 { 1370 // Load up the language pack 1371 $lang = array(); 1372 @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx); 1373 1374 // If we find the reason in this language pack use it 1375 if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) 1376 { 1377 $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; 1378 } 1379 1380 unset($lang); // Free memory 1381 } 1382 } 1383 1384 $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; 1385 $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; 1386 } 1387 1388 if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1) 1389 { 1390 // If there is only 1 post when disapproving the topic, 1391 // we send the user a "disapprove topic" notification... 1392 $phpbb_notifications->add_notifications('notification.type.disapprove_topic', $post_data); 1393 } 1394 else 1395 { 1396 // ... otherwise there are multiple unapproved posts and 1397 // all of them are disapproved as posts. 1398 $phpbb_notifications->add_notifications('notification.type.disapprove_post', $post_data); 1399 } 1400 } 1401 } 1402 1403 if ($num_disapproved_topics) 1404 { 1405 $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS'; 1406 } 1407 else 1408 { 1409 $success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS'; 1410 } 1411 1412 if ($is_disapproving) 1413 { 1414 $success_msg .= '_DISAPPROVED_SUCCESS'; 1415 } 1416 else 1417 { 1418 $success_msg .= '_DELETED_SUCCESS'; 1419 } 1420 1421 // If we came from viewtopic, we try to go back to it. 1422 if (strpos($redirect, $phpbb_root_path . 'viewtopic.' . $phpEx) === 0) 1423 { 1424 if ($num_disapproved_topics == 0) 1425 { 1426 // So we need to remove the post id part from the Url 1427 $redirect = str_replace("&p={$post_id_list[0]}#p{$post_id_list[0]}", '', $redirect); 1428 } 1429 else 1430 { 1431 // However this is only possible if the topic still exists, 1432 // Otherwise we go back to the viewforum page 1433 $redirect = append_sid($phpbb_root_path . 'viewforum.' . $phpEx, 'f=' . $post_data['forum_id']); 1434 } 1435 } 1436 1437 $disapprove_reason_lang = $disapprove_reason_lang ?? ''; 1438 1439 /** 1440 * Perform additional actions during post(s) disapproval 1441 * 1442 * @event core.disapprove_posts_after 1443 * @var array post_info Array containing info for all posts being disapproved 1444 * @var array topic_information Array containing information for the topics 1445 * @var array topic_posts_unapproved Array containing list of topic ids and the count of disapproved posts in them 1446 * @var array post_disapprove_list Array containing list of posts and their topic id 1447 * @var int num_disapproved_topics Variable containing the number of disapproved topics 1448 * @var int num_disapproved_posts Variable containing the number of disapproved posts 1449 * @var array lang_reasons Array containing the language keys for reasons 1450 * @var string disapprove_reason Variable containing the language key for the success message 1451 * @var string disapprove_reason_lang Variable containing the language key for the success message 1452 * @var bool is_disapproving Variable telling if anything is going to be disapproved 1453 * @var bool notify_poster Variable telling if the post should be notified or not 1454 * @var string success_msg Variable containing the language key for the success message 1455 * @var string redirect Variable containing the redirect url 1456 * @since 3.1.4-RC1 1457 */ 1458 $vars = array( 1459 'post_info', 1460 'topic_information', 1461 'topic_posts_unapproved', 1462 'post_disapprove_list', 1463 'num_disapproved_topics', 1464 'num_disapproved_posts', 1465 'lang_reasons', 1466 'disapprove_reason', 1467 'disapprove_reason_lang', 1468 'is_disapproving', 1469 'notify_poster', 1470 'success_msg', 1471 'redirect', 1472 ); 1473 extract($phpbb_dispatcher->trigger_event('core.disapprove_posts_after', compact($vars))); 1474 1475 unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang); 1476 1477 meta_refresh(3, $redirect); 1478 $message = $user->lang[$success_msg]; 1479 1480 if ($request->is_ajax()) 1481 { 1482 $json_response = new \phpbb\json_response; 1483 $json_response->send(array( 1484 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 1485 'MESSAGE_TEXT' => $message, 1486 'REFRESH_DATA' => null, 1487 'visible' => false, 1488 )); 1489 } 1490 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>'); 1491 trigger_error($message); 1492 } 1493 else 1494 { 1495 $show_notify = false; 1496 1497 foreach ($post_info as $post_data) 1498 { 1499 if ($post_data['poster_id'] == ANONYMOUS) 1500 { 1501 continue; 1502 } 1503 else 1504 { 1505 $show_notify = true; 1506 break; 1507 } 1508 } 1509 1510 $l_confirm_msg = 'DISAPPROVE_POST'; 1511 $confirm_template = 'mcp_approve.html'; 1512 if ($is_disapproving) 1513 { 1514 $phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id); 1515 } 1516 else 1517 { 1518 $user->add_lang('posting'); 1519 1520 $l_confirm_msg = 'DELETE_POST_PERMANENTLY'; 1521 $confirm_template = 'confirm_delete_body.html'; 1522 } 1523 $l_confirm_msg .= ((count($post_id_list) == 1) ? '' : 'S'); 1524 1525 $template->assign_vars(array( 1526 'S_NOTIFY_POSTER' => $show_notify, 1527 'S_APPROVE' => false, 1528 'REASON' => ($is_disapproving) ? $reason : '', 1529 'ADDITIONAL_MSG' => $additional_msg, 1530 )); 1531 1532 confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template); 1533 } 1534 1535 redirect($redirect); 1536 } 1537 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jun 23 12:25:44 2024 | Cross-referenced by PHPXref 0.7.1 |