[ Index ] |
PHP Cross Reference of phpBB-3.1.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 mcp_queue(&$p_master) 32 { 33 $this->p_master = &$p_master; 34 } 35 36 public function main($id, $mode) 37 { 38 global $auth, $db, $user, $template, $cache, $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_var('f', 0); 45 $start = request_var('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_topics')) 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_var('p', 0); 158 $topic_id = request_var('t', 0); 159 160 $phpbb_notifications = $phpbb_container->get('notification_manager'); 161 162 if ($topic_id) 163 { 164 $topic_info = phpbb_get_topic_data(array($topic_id), 'm_approve'); 165 if (isset($topic_info[$topic_id]['topic_first_post_id'])) 166 { 167 $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; 168 169 $phpbb_notifications->mark_notifications_read('notification.type.topic_in_queue', $topic_id, $user->data['user_id']); 170 } 171 else 172 { 173 $topic_id = 0; 174 } 175 } 176 177 $phpbb_notifications->mark_notifications_read('notification.type.post_in_queue', $post_id, $user->data['user_id']); 178 179 $post_info = phpbb_get_post_data(array($post_id), 'm_approve', true); 180 181 if (!sizeof($post_info)) 182 { 183 trigger_error('NO_POST_SELECTED'); 184 } 185 186 $post_info = $post_info[$post_id]; 187 188 if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false)) 189 { 190 $template->assign_vars(array( 191 'S_TOPIC_REVIEW' => true, 192 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'], 193 'TOPIC_TITLE' => $post_info['topic_title'], 194 )); 195 } 196 197 $extensions = $attachments = $topic_tracking_info = array(); 198 199 // Get topic tracking info 200 if ($config['load_db_lastread']) 201 { 202 $tmp_topic_data = array($post_info['topic_id'] => $post_info); 203 $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'])); 204 unset($tmp_topic_data); 205 } 206 else 207 { 208 $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']); 209 } 210 211 $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false; 212 213 // Process message, leave it uncensored 214 $parse_flags = ($post_info['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES; 215 $message = generate_text_for_display($post_info['post_text'], $post_info['bbcode_uid'], $post_info['bbcode_bitfield'], $parse_flags, false); 216 217 if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) 218 { 219 $extensions = $cache->obtain_attach_extensions($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 (sizeof($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", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']); 282 $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']); 283 284 $template->assign_vars(array( 285 'S_MCP_QUEUE' => true, 286 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_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&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '', 298 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id), 299 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&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_var('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&f=' . $post_info['forum_id'] . '&p=' . $post_id . '&lookup=' . $post_info['poster_ip']) . '#ip' : '', 328 )); 329 330 break; 331 332 case 'unapproved_topics': 333 case 'unapproved_posts': 334 case 'deleted_topics': 335 case 'deleted_posts': 336 $m_perm = 'm_approve'; 337 $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false; 338 $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false; 339 $visibility_const = (!$is_restore) ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED; 340 341 $user->add_lang(array('viewtopic', 'viewforum')); 342 343 $topic_id = $request->variable('t', 0); 344 $forum_info = array(); 345 $pagination = $phpbb_container->get('pagination'); 346 347 if ($topic_id) 348 { 349 $topic_info = phpbb_get_topic_data(array($topic_id)); 350 351 if (!sizeof($topic_info)) 352 { 353 trigger_error('TOPIC_NOT_EXIST'); 354 } 355 356 $topic_info = $topic_info[$topic_id]; 357 $forum_id = $topic_info['forum_id']; 358 } 359 360 $forum_list_approve = get_forum_list($m_perm, false, true); 361 $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs 362 363 // Remove forums we cannot read 364 foreach ($forum_list_approve as $k => $forum_data) 365 { 366 if (!isset($forum_list_read[$forum_data['forum_id']])) 367 { 368 unset($forum_list_approve[$k]); 369 } 370 } 371 unset($forum_list_read); 372 373 if (!$forum_id) 374 { 375 $forum_list = array(); 376 foreach ($forum_list_approve as $row) 377 { 378 $forum_list[] = $row['forum_id']; 379 } 380 381 if (!sizeof($forum_list)) 382 { 383 trigger_error('NOT_MODERATOR'); 384 } 385 386 $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics 387 FROM ' . FORUMS_TABLE . ' 388 WHERE ' . $db->sql_in_set('forum_id', $forum_list); 389 $result = $db->sql_query($sql); 390 $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics'); 391 $db->sql_freeresult($result); 392 } 393 else 394 { 395 $forum_info = phpbb_get_forum_data(array($forum_id), $m_perm); 396 397 if (!sizeof($forum_info)) 398 { 399 trigger_error('NOT_MODERATOR'); 400 } 401 402 $forum_info = $forum_info[$forum_id]; 403 $forum_list = $forum_id; 404 } 405 406 $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>'; 407 foreach ($forum_list_approve as $row) 408 { 409 $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>'; 410 } 411 412 $sort_days = $total = 0; 413 $sort_key = $sort_dir = ''; 414 $sort_by_sql = $sort_order_sql = array(); 415 phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); 416 417 $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; 418 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; 419 420 $forum_names = array(); 421 422 if (!$is_topics) 423 { 424 $sql = 'SELECT p.post_id 425 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . ' 426 WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . ' 427 AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) . ' 428 ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' 429 ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " 430 AND t.topic_id = p.topic_id 431 AND (t.topic_visibility <> p.post_visibility 432 OR t.topic_delete_user = 0) 433 $limit_time_sql 434 ORDER BY $sort_order_sql"; 435 436 /** 437 * Alter sql query to get posts in queue to be accepted 438 * 439 * @event core.mcp_queue_get_posts_query_before 440 * @var string sql Associative array with the query to be executed 441 * @var array forum_list List of forums that contain the posts 442 * @var int visibility_const Integer with one of the possible ITEM_* constant values 443 * @var int topic_id If topic_id not equal to 0, the topic id to filter the posts to display 444 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) 445 * @var string sort_order_sql String with the ORDER BY SQL code used in this query 446 * @since 3.1.0-RC3 447 */ 448 $vars = array( 449 'sql', 450 'forum_list', 451 'visibility_const', 452 'topic_id', 453 'limit_time_sql', 454 'sort_order_sql', 455 ); 456 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_query_before', compact($vars))); 457 458 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); 459 460 $i = 0; 461 $post_ids = array(); 462 while ($row = $db->sql_fetchrow($result)) 463 { 464 $post_ids[] = $row['post_id']; 465 $row_num[$row['post_id']] = $i++; 466 } 467 $db->sql_freeresult($result); 468 469 if (sizeof($post_ids)) 470 { 471 $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 472 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u 473 WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . ' 474 AND t.topic_id = p.topic_id 475 AND u.user_id = p.poster_id 476 ORDER BY ' . $sort_order_sql; 477 $result = $db->sql_query($sql); 478 479 $post_data = $rowset = array(); 480 while ($row = $db->sql_fetchrow($result)) 481 { 482 $forum_names[] = $row['forum_id']; 483 $post_data[$row['post_id']] = $row; 484 } 485 $db->sql_freeresult($result); 486 487 foreach ($post_ids as $post_id) 488 { 489 $rowset[] = $post_data[$post_id]; 490 } 491 unset($post_data, $post_ids); 492 } 493 else 494 { 495 $rowset = array(); 496 } 497 } 498 else 499 { 500 $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 501 FROM ' . TOPICS_TABLE . ' t 502 WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' 503 AND ' . $db->sql_in_set('topic_visibility', $visibility_const) . " 504 AND topic_delete_user <> 0 505 $limit_time_sql 506 ORDER BY $sort_order_sql"; 507 508 /** 509 * Alter sql query to get information on all topics in the list of forums provided. 510 * 511 * @event core.mcp_queue_get_posts_for_topics_query_before 512 * @var string sql String with the query to be executed 513 * @var array forum_list List of forums that contain the posts 514 * @var int visibility_const Integer with one of the possible ITEM_* constant values 515 * @var int topic_id topic_id in the page request 516 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) 517 * @var string sort_order_sql String with the ORDER BY SQL code used in this query 518 * @since 3.1.0-RC3 519 */ 520 $vars = array( 521 'sql', 522 'forum_list', 523 'visibility_const', 524 'topic_id', 525 'limit_time_sql', 526 'sort_order_sql', 527 ); 528 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_topics_query_before', compact($vars))); 529 530 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); 531 532 $rowset = array(); 533 while ($row = $db->sql_fetchrow($result)) 534 { 535 $forum_names[] = $row['forum_id']; 536 $rowset[] = $row; 537 } 538 $db->sql_freeresult($result); 539 } 540 541 if (sizeof($forum_names)) 542 { 543 // Select the names for the forum_ids 544 $sql = 'SELECT forum_id, forum_name 545 FROM ' . FORUMS_TABLE . ' 546 WHERE ' . $db->sql_in_set('forum_id', $forum_names); 547 $result = $db->sql_query($sql, 3600); 548 549 $forum_names = array(); 550 while ($row = $db->sql_fetchrow($result)) 551 { 552 $forum_names[$row['forum_id']] = $row['forum_name']; 553 } 554 $db->sql_freeresult($result); 555 } 556 557 foreach ($rowset as $row) 558 { 559 if (empty($row['post_username'])) 560 { 561 $row['post_username'] = $row['username'] ?: $user->lang['GUEST']; 562 } 563 564 $template->assign_block_vars('postrow', array( 565 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']), 566 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']), 567 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''), 568 'U_VIEW_DETAILS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&start=$start&mode=approve_details&f={$row['forum_id']}&p={$row['post_id']}" . (($mode == 'unapproved_topics') ? "&t={$row['topic_id']}" : '')), 569 570 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 571 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 572 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 573 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']), 574 575 'POST_ID' => $row['post_id'], 576 'TOPIC_ID' => $row['topic_id'], 577 'FORUM_NAME' => $forum_names[$row['forum_id']], 578 'POST_SUBJECT' => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 579 'TOPIC_TITLE' => $row['topic_title'], 580 'POST_TIME' => $user->format_date($row['post_time']), 581 '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']) : '', 582 )); 583 } 584 unset($rowset, $forum_names); 585 586 $base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; 587 $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); 588 589 // Now display the page 590 $template->assign_vars(array( 591 'L_DISPLAY_ITEMS' => (!$is_topics) ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], 592 'L_EXPLAIN' => $user->lang['MCP_QUEUE_' . strtoupper($mode) . '_EXPLAIN'], 593 'L_TITLE' => $user->lang['MCP_QUEUE_' . strtoupper($mode)], 594 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '', 595 596 'S_FORUM_OPTIONS' => $forum_options, 597 'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')), 598 'S_TOPICS' => $is_topics, 599 'S_RESTORE' => $is_restore, 600 601 'TOPIC_ID' => $topic_id, 602 'TOTAL' => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total), 603 )); 604 605 $this->tpl_name = 'mcp_queue'; 606 break; 607 } 608 } 609 610 /** 611 * Approve/Restore posts 612 * 613 * @param $action string Action we perform on the posts ('approve' or 'restore') 614 * @param $post_id_list array IDs of the posts to approve/restore 615 * @param $id mixed Category of the current active module 616 * @param $mode string Active module 617 * @return null 618 */ 619 static public function approve_posts($action, $post_id_list, $id, $mode) 620 { 621 global $db, $template, $user, $config, $request, $phpbb_container, $phpbb_dispatcher; 622 global $phpEx, $phpbb_root_path; 623 624 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) 625 { 626 trigger_error('NOT_AUTHORISED'); 627 } 628 629 $redirect = $request->variable('redirect', build_url(array('quickmod'))); 630 $redirect = reapply_sid($redirect); 631 $success_msg = $post_url = ''; 632 $approve_log = array(); 633 $num_topics = 0; 634 635 $s_hidden_fields = build_hidden_fields(array( 636 'i' => $id, 637 'mode' => $mode, 638 'post_id_list' => $post_id_list, 639 'action' => $action, 640 'redirect' => $redirect, 641 )); 642 643 $post_info = phpbb_get_post_data($post_id_list, 'm_approve'); 644 645 if (confirm_box(true)) 646 { 647 $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])); 648 649 $topic_info = array(); 650 651 // Group the posts by topic_id 652 foreach ($post_info as $post_id => $post_data) 653 { 654 if ($post_data['post_visibility'] == ITEM_APPROVED) 655 { 656 continue; 657 } 658 $topic_id = (int) $post_data['topic_id']; 659 660 $topic_info[$topic_id]['posts'][] = (int) $post_id; 661 $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id']; 662 663 // Refresh the first post, if the time or id is older then the current one 664 if ($post_id <= $post_data['topic_first_post_id'] || $post_data['post_time'] <= $post_data['topic_time']) 665 { 666 $topic_info[$topic_id]['first_post'] = true; 667 } 668 669 // Refresh the last post, if the time or id is newer then the current one 670 if ($post_id >= $post_data['topic_last_post_id'] || $post_data['post_time'] >= $post_data['topic_last_post_time']) 671 { 672 $topic_info[$topic_id]['last_post'] = true; 673 } 674 675 $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id']; 676 677 $approve_log[] = array( 678 'forum_id' => $post_data['forum_id'], 679 'topic_id' => $post_data['topic_id'], 680 'post_subject' => $post_data['post_subject'], 681 ); 682 } 683 684 $phpbb_content_visibility = $phpbb_container->get('content.visibility'); 685 foreach ($topic_info as $topic_id => $topic_data) 686 { 687 $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'])); 688 } 689 690 foreach ($approve_log as $log_data) 691 { 692 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_POST_' . strtoupper($action) . 'D', $log_data['post_subject']); 693 } 694 695 // Only send out the mails, when the posts are being approved 696 if ($action == 'approve') 697 { 698 $phpbb_notifications = $phpbb_container->get('notification_manager'); 699 700 // Handle notifications 701 foreach ($post_info as $post_id => $post_data) 702 { 703 // A single topic approval may also happen here, so handle deleting the respective notification. 704 if (!$post_data['topic_posts_approved']) 705 { 706 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']); 707 708 if ($post_data['post_visibility'] == ITEM_UNAPPROVED) 709 { 710 $phpbb_notifications->add_notifications(array('notification.type.topic'), $post_data); 711 } 712 if ($post_data['post_visibility'] != ITEM_APPROVED) 713 { 714 $num_topics++; 715 } 716 } 717 else 718 { 719 // Only add notifications, if we are not reapproving post 720 // When the topic was already approved, but was edited and 721 // now needs re-approval, we don't want to notify the users 722 // again. 723 if ($post_data['post_visibility'] == ITEM_UNAPPROVED) 724 { 725 $phpbb_notifications->add_notifications(array( 726 'notification.type.bookmark', 727 'notification.type.post', 728 ), $post_data); 729 } 730 } 731 $phpbb_notifications->add_notifications(array('notification.type.quote'), $post_data); 732 $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id); 733 734 $phpbb_notifications->mark_notifications_read(array( 735 'notification.type.quote', 736 'notification.type.bookmark', 737 'notification.type.post', 738 ), $post_data['post_id'], $user->data['user_id']); 739 740 // Notify Poster? 741 if ($notify_poster) 742 { 743 if ($post_data['poster_id'] == ANONYMOUS) 744 { 745 continue; 746 } 747 748 if (!$post_data['topic_posts_approved']) 749 { 750 $phpbb_notifications->add_notifications('notification.type.approve_topic', $post_data); 751 } 752 else 753 { 754 $phpbb_notifications->add_notifications('notification.type.approve_post', $post_data); 755 } 756 } 757 } 758 } 759 760 if ($num_topics >= 1) 761 { 762 $success_msg = ($num_topics == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; 763 } 764 else 765 { 766 $success_msg = (sizeof($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS'; 767 } 768 769 /** 770 * Perform additional actions during post(s) approval 771 * 772 * @event core.approve_posts_after 773 * @var string action Variable containing the action we perform on the posts ('approve' or 'restore') 774 * @var array post_info Array containing info for all posts being approved 775 * @var array topic_info Array containing info for all parent topics of the posts 776 * @var int num_topics Variable containing number of topics 777 * @var bool notify_poster Variable telling if the post should be notified or not 778 * @var string success_msg Variable containing the language key for the success message 779 * @var string redirect Variable containing the redirect url 780 * @since 3.1.4-RC1 781 */ 782 $vars = array( 783 'action', 784 'post_info', 785 'topic_info', 786 'num_topics', 787 'notify_poster', 788 'success_msg', 789 'redirect', 790 ); 791 extract($phpbb_dispatcher->trigger_event('core.approve_posts_after', compact($vars))); 792 793 meta_refresh(3, $redirect); 794 $message = $user->lang[$success_msg]; 795 796 if ($request->is_ajax()) 797 { 798 $json_response = new \phpbb\json_response; 799 $json_response->send(array( 800 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 801 'MESSAGE_TEXT' => $message, 802 'REFRESH_DATA' => null, 803 'visible' => true, 804 )); 805 } 806 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>'); 807 808 // If approving one post, also give links back to post... 809 if (sizeof($post_info) == 1 && $post_url) 810 { 811 $message .= '<br /><br />' . $user->lang('RETURN_POST', '<a href="' . $post_url . '">', '</a>'); 812 } 813 trigger_error($message); 814 } 815 else 816 { 817 $show_notify = false; 818 819 if ($action == 'approve') 820 { 821 foreach ($post_info as $post_data) 822 { 823 if (!$post_data['topic_posts_approved']) 824 { 825 $num_topics++; 826 } 827 828 if (!$show_notify && $post_data['poster_id'] != ANONYMOUS) 829 { 830 $show_notify = true; 831 } 832 } 833 } 834 835 $template->assign_vars(array( 836 'S_NOTIFY_POSTER' => $show_notify, 837 'S_' . strtoupper($action) => true, 838 )); 839 840 // Create the confirm box message 841 $action_msg = strtoupper($action); 842 $num_posts = sizeof($post_id_list) - $num_topics; 843 if ($num_topics > 0 && $num_posts <= 0) 844 { 845 $action_msg .= '_TOPIC' . (($num_topics == 1) ? '' : 'S'); 846 } 847 else 848 { 849 $action_msg .= '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'); 850 } 851 confirm_box(false, $action_msg, $s_hidden_fields, 'mcp_approve.html'); 852 } 853 854 redirect($redirect); 855 } 856 857 /** 858 * Approve/Restore topics 859 * 860 * @param $action string Action we perform on the posts ('approve' or 'restore') 861 * @param $topic_id_list array IDs of the topics to approve/restore 862 * @param $id mixed Category of the current active module 863 * @param $mode string Active module 864 * @return null 865 */ 866 static public function approve_topics($action, $topic_id_list, $id, $mode) 867 { 868 global $db, $template, $user, $config; 869 global $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_dispatcher; 870 871 if (!phpbb_check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) 872 { 873 trigger_error('NOT_AUTHORISED'); 874 } 875 876 $redirect = $request->variable('redirect', build_url(array('quickmod'))); 877 $redirect = reapply_sid($redirect); 878 $success_msg = $topic_url = ''; 879 $approve_log = array(); 880 881 $s_hidden_fields = build_hidden_fields(array( 882 'i' => $id, 883 'mode' => $mode, 884 'topic_id_list' => $topic_id_list, 885 'action' => $action, 886 'redirect' => $redirect, 887 )); 888 889 $topic_info = phpbb_get_topic_data($topic_id_list, 'm_approve'); 890 891 if (confirm_box(true)) 892 { 893 $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; 894 895 $phpbb_content_visibility = $phpbb_container->get('content.visibility'); 896 $first_post_ids = array(); 897 898 foreach ($topic_info as $topic_id => $topic_data) 899 { 900 $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); 901 $first_post_ids[$topic_id] = (int) $topic_data['topic_first_post_id']; 902 903 $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}"); 904 905 $approve_log[] = array( 906 'forum_id' => $topic_data['forum_id'], 907 'topic_id' => $topic_data['topic_id'], 908 'topic_title' => $topic_data['topic_title'], 909 ); 910 } 911 912 if (sizeof($topic_info) >= 1) 913 { 914 $success_msg = (sizeof($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; 915 } 916 917 foreach ($approve_log as $log_data) 918 { 919 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_TOPIC_' . strtoupper($action) . 'D', $log_data['topic_title']); 920 } 921 922 // Only send out the mails, when the posts are being approved 923 if ($action == 'approve') 924 { 925 // Grab the first post text as it's needed for the quote notification. 926 $sql = 'SELECT topic_id, post_text 927 FROM ' . POSTS_TABLE . ' 928 WHERE ' . $db->sql_in_set('post_id', $first_post_ids); 929 $result = $db->sql_query($sql); 930 931 while ($row = $db->sql_fetchrow($result)) 932 { 933 $topic_info[$row['topic_id']]['post_text'] = $row['post_text']; 934 } 935 $db->sql_freeresult($result); 936 937 // Handle notifications 938 $phpbb_notifications = $phpbb_container->get('notification_manager'); 939 940 foreach ($topic_info as $topic_id => $topic_data) 941 { 942 $topic_data = array_merge($topic_data, array( 943 'post_id' => $topic_data['topic_first_post_id'], 944 'post_subject' => $topic_data['topic_title'], 945 'post_time' => $topic_data['topic_time'], 946 'poster_id' => $topic_data['topic_poster'], 947 'post_username' => $topic_data['topic_first_poster_name'], 948 )); 949 950 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $topic_id); 951 952 // Only add notifications, if we are not reapproving post 953 // When the topic was already approved, but was edited and 954 // now needs re-approval, we don't want to notify the users 955 // again. 956 if ($topic_data['topic_visibility'] == ITEM_UNAPPROVED) 957 { 958 $phpbb_notifications->add_notifications(array( 959 'notification.type.quote', 960 'notification.type.topic', 961 ), $topic_data); 962 } 963 964 $phpbb_notifications->mark_notifications_read('notification.type.quote', $topic_data['post_id'], $user->data['user_id']); 965 $phpbb_notifications->mark_notifications_read('notification.type.topic', $topic_id, $user->data['user_id']); 966 967 if ($notify_poster) 968 { 969 $phpbb_notifications->add_notifications('notification.type.approve_topic', $topic_data); 970 } 971 } 972 } 973 974 /** 975 * Perform additional actions during topics(s) approval 976 * 977 * @event core.approve_topics_after 978 * @var string action Variable containing the action we perform on the posts ('approve' or 'restore') 979 * @var mixed topic_info Array containing info for all topics being approved 980 * @var array first_post_ids Array containing ids of all first posts 981 * @var bool notify_poster Variable telling if the poster should be notified or not 982 * @var string success_msg Variable containing the language key for the success message 983 * @var string redirect Variable containing the redirect url 984 * @since 3.1.4-RC1 985 */ 986 $vars = array( 987 'action', 988 'topic_info', 989 'first_post_ids', 990 'notify_poster', 991 'success_msg', 992 'redirect', 993 ); 994 extract($phpbb_dispatcher->trigger_event('core.approve_topics_after', compact($vars))); 995 996 meta_refresh(3, $redirect); 997 $message = $user->lang[$success_msg]; 998 999 if ($request->is_ajax()) 1000 { 1001 $json_response = new \phpbb\json_response; 1002 $json_response->send(array( 1003 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 1004 'MESSAGE_TEXT' => $message, 1005 'REFRESH_DATA' => null, 1006 'visible' => true, 1007 )); 1008 } 1009 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>'); 1010 1011 // If approving one topic, also give links back to topic... 1012 if (sizeof($topic_info) == 1 && $topic_url) 1013 { 1014 $message .= '<br /><br />' . $user->lang('RETURN_TOPIC', '<a href="' . $topic_url . '">', '</a>'); 1015 } 1016 trigger_error($message); 1017 } 1018 else 1019 { 1020 $show_notify = false; 1021 1022 if ($action == 'approve') 1023 { 1024 foreach ($topic_info as $topic_data) 1025 { 1026 if ($topic_data['topic_poster'] == ANONYMOUS) 1027 { 1028 continue; 1029 } 1030 else 1031 { 1032 $show_notify = true; 1033 break; 1034 } 1035 } 1036 } 1037 1038 $template->assign_vars(array( 1039 'S_NOTIFY_POSTER' => $show_notify, 1040 'S_' . strtoupper($action) => true, 1041 )); 1042 1043 confirm_box(false, strtoupper($action) . '_TOPIC' . ((sizeof($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); 1044 } 1045 1046 redirect($redirect); 1047 } 1048 1049 /** 1050 * Disapprove Post 1051 * 1052 * @param $post_id_list array IDs of the posts to disapprove/delete 1053 * @param $id mixed Category of the current active module 1054 * @param $mode string Active module 1055 * @return null 1056 */ 1057 static public function disapprove_posts($post_id_list, $id, $mode) 1058 { 1059 global $db, $template, $user, $config, $phpbb_container, $phpbb_dispatcher; 1060 global $phpEx, $phpbb_root_path, $request; 1061 1062 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) 1063 { 1064 trigger_error('NOT_AUTHORISED'); 1065 } 1066 1067 $redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode"); 1068 $redirect = reapply_sid($redirect); 1069 $reason = $request->variable('reason', '', true); 1070 $reason_id = $request->variable('reason_id', 0); 1071 $success_msg = $additional_msg = ''; 1072 1073 $s_hidden_fields = build_hidden_fields(array( 1074 'i' => $id, 1075 'mode' => $mode, 1076 'post_id_list' => $post_id_list, 1077 'action' => 'disapprove', 1078 'redirect' => $redirect, 1079 )); 1080 1081 $notify_poster = $request->is_set('notify_poster'); 1082 $disapprove_reason = ''; 1083 1084 if ($reason_id) 1085 { 1086 $sql = 'SELECT reason_title, reason_description 1087 FROM ' . REPORTS_REASONS_TABLE . " 1088 WHERE reason_id = $reason_id"; 1089 $result = $db->sql_query($sql); 1090 $row = $db->sql_fetchrow($result); 1091 $db->sql_freeresult($result); 1092 1093 if (!$row || (!$reason && strtolower($row['reason_title']) == 'other')) 1094 { 1095 $additional_msg = $user->lang['NO_REASON_DISAPPROVAL']; 1096 1097 $request->overwrite('confirm', null, \phpbb\request\request_interface::POST); 1098 $request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST); 1099 $request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST); 1100 } 1101 else 1102 { 1103 // If the reason is defined within the language file, we will use the localized version, else just use the database entry... 1104 $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']) : ''; 1105 $disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; 1106 1107 if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) 1108 { 1109 $disapprove_reason_lang = strtoupper($row['reason_title']); 1110 } 1111 } 1112 } 1113 1114 $post_info = phpbb_get_post_data($post_id_list, 'm_approve'); 1115 1116 $is_disapproving = false; 1117 foreach ($post_info as $post_id => $post_data) 1118 { 1119 if ($post_data['post_visibility'] == ITEM_DELETED) 1120 { 1121 continue; 1122 } 1123 1124 $is_disapproving = true; 1125 } 1126 1127 if (confirm_box(true)) 1128 { 1129 $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); 1130 $topic_posts_unapproved = $post_disapprove_list = $topic_information = array(); 1131 1132 // Build a list of posts to be disapproved and get the related topics real replies count 1133 foreach ($post_info as $post_id => $post_data) 1134 { 1135 if ($mode === 'unapproved_topics' && $post_data['post_visibility'] == ITEM_APPROVED) 1136 { 1137 continue; 1138 } 1139 1140 $post_disapprove_list[$post_id] = $post_data['topic_id']; 1141 if (!isset($topic_posts_unapproved[$post_data['topic_id']])) 1142 { 1143 $topic_information[$post_data['topic_id']] = $post_data; 1144 $topic_posts_unapproved[$post_data['topic_id']] = 0; 1145 } 1146 $topic_posts_unapproved[$post_data['topic_id']]++; 1147 } 1148 1149 // Do not try to disapprove if no posts are selected 1150 if (empty($post_disapprove_list)) 1151 { 1152 trigger_error('NO_POST_SELECTED'); 1153 } 1154 1155 // Now we build the log array 1156 foreach ($post_disapprove_list as $post_id => $topic_id) 1157 { 1158 // If the count of disapproved posts for the topic is equal 1159 // to the number of unapproved posts in the topic, and there are no different 1160 // posts, we disapprove the hole topic 1161 if ($topic_information[$topic_id]['topic_posts_approved'] == 0 && 1162 $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && 1163 $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]) 1164 { 1165 // Don't write the log more than once for every topic 1166 if (!isset($disapprove_log_topics[$topic_id])) 1167 { 1168 // Build disapproved topics log 1169 $disapprove_log_topics[$topic_id] = array( 1170 'type' => 'topic', 1171 'post_subject' => $post_info[$post_id]['topic_title'], 1172 'forum_id' => $post_info[$post_id]['forum_id'], 1173 'topic_id' => 0, // useless to log a topic id, as it will be deleted 1174 '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'], 1175 ); 1176 } 1177 } 1178 else 1179 { 1180 // Build disapproved posts log 1181 $disapprove_log_posts[] = array( 1182 'type' => 'post', 1183 'post_subject' => $post_info[$post_id]['post_subject'], 1184 'forum_id' => $post_info[$post_id]['forum_id'], 1185 'topic_id' => $post_info[$post_id]['topic_id'], 1186 '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'], 1187 ); 1188 1189 } 1190 } 1191 1192 // Get disapproved posts/topics counts separately 1193 $num_disapproved_topics = sizeof($disapprove_log_topics); 1194 $num_disapproved_posts = sizeof($disapprove_log_posts); 1195 1196 // Build the whole log 1197 $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts); 1198 1199 // Unset unneeded arrays 1200 unset($post_data, $disapprove_log_topics, $disapprove_log_posts); 1201 1202 // Let's do the job - delete disapproved posts 1203 if (sizeof($post_disapprove_list)) 1204 { 1205 if (!function_exists('delete_posts')) 1206 { 1207 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); 1208 } 1209 1210 // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts 1211 // Note: function delete_posts triggers related forums/topics sync, 1212 // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually 1213 delete_posts('post_id', array_keys($post_disapprove_list)); 1214 1215 foreach ($disapprove_log as $log_data) 1216 { 1217 if ($is_disapproving) 1218 { 1219 $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED'; 1220 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $disapprove_reason, $log_data['post_username']); 1221 } 1222 else 1223 { 1224 $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST'; 1225 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $log_data['post_username']); 1226 } 1227 } 1228 } 1229 1230 $phpbb_notifications = $phpbb_container->get('notification_manager'); 1231 1232 $lang_reasons = array(); 1233 1234 foreach ($post_info as $post_id => $post_data) 1235 { 1236 $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 && 1237 $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && 1238 $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]; 1239 1240 $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id); 1241 1242 // Do we disapprove the whole topic? Remove potential notifications 1243 if ($disapprove_all_posts_in_topic) 1244 { 1245 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']); 1246 } 1247 1248 // Notify Poster? 1249 if ($notify_poster) 1250 { 1251 if ($post_data['poster_id'] == ANONYMOUS) 1252 { 1253 continue; 1254 } 1255 1256 $post_data['disapprove_reason'] = $disapprove_reason; 1257 if (isset($disapprove_reason_lang)) 1258 { 1259 // Okay we need to get the reason from the posters language 1260 if (!isset($lang_reasons[$post_data['user_lang']])) 1261 { 1262 // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity. 1263 $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; 1264 1265 // Only load up the language pack if the language is different to the current one 1266 if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) 1267 { 1268 // Load up the language pack 1269 $lang = array(); 1270 @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx); 1271 1272 // If we find the reason in this language pack use it 1273 if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) 1274 { 1275 $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]; 1276 } 1277 1278 unset($lang); // Free memory 1279 } 1280 } 1281 1282 $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; 1283 $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; 1284 } 1285 1286 if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1) 1287 { 1288 // If there is only 1 post when disapproving the topic, 1289 // we send the user a "disapprove topic" notification... 1290 $phpbb_notifications->add_notifications('notification.type.disapprove_topic', $post_data); 1291 } 1292 else 1293 { 1294 // ... otherwise there are multiple unapproved posts and 1295 // all of them are disapproved as posts. 1296 $phpbb_notifications->add_notifications('notification.type.disapprove_post', $post_data); 1297 } 1298 } 1299 } 1300 1301 if ($num_disapproved_topics) 1302 { 1303 $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS'; 1304 } 1305 else 1306 { 1307 $success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS'; 1308 } 1309 1310 if ($is_disapproving) 1311 { 1312 $success_msg .= '_DISAPPROVED_SUCCESS'; 1313 } 1314 else 1315 { 1316 $success_msg .= '_DELETED_SUCCESS'; 1317 } 1318 1319 // If we came from viewtopic, we try to go back to it. 1320 if (strpos($redirect, $phpbb_root_path . 'viewtopic.' . $phpEx) === 0) 1321 { 1322 if ($num_disapproved_topics == 0) 1323 { 1324 // So we need to remove the post id part from the Url 1325 $redirect = str_replace("&p={$post_id_list[0]}#p{$post_id_list[0]}", '', $redirect); 1326 } 1327 else 1328 { 1329 // However this is only possible if the topic still exists, 1330 // Otherwise we go back to the viewforum page 1331 $redirect = append_sid($phpbb_root_path . 'viewforum.' . $phpEx, 'f=' . $request->variable('f', 0)); 1332 } 1333 } 1334 1335 /** 1336 * Perform additional actions during post(s) disapproval 1337 * 1338 * @event core.disapprove_posts_after 1339 * @var array post_info Array containing info for all posts being disapproved 1340 * @var array topic_information Array containing information for the topics 1341 * @var array topic_posts_unapproved Array containing list of topic ids and the count of disapproved posts in them 1342 * @var array post_disapprove_list Array containing list of posts and their topic id 1343 * @var int num_disapproved_topics Variable containing the number of disapproved topics 1344 * @var int num_disapproved_posts Variable containing the number of disapproved posts 1345 * @var array lang_reasons Array containing the language keys for reasons 1346 * @var string disapprove_reason Variable containing the language key for the success message 1347 * @var string disapprove_reason_lang Variable containing the language key for the success message 1348 * @var bool is_disapproving Variable telling if anything is going to be disapproved 1349 * @var bool notify_poster Variable telling if the post should be notified or not 1350 * @var string success_msg Variable containing the language key for the success message 1351 * @var string redirect Variable containing the redirect url 1352 * @since 3.1.4-RC1 1353 */ 1354 $vars = array( 1355 'post_info', 1356 'topic_information', 1357 'topic_posts_unapproved', 1358 'post_disapprove_list', 1359 'num_disapproved_topics', 1360 'num_disapproved_posts', 1361 'lang_reasons', 1362 'disapprove_reason', 1363 'disapprove_reason_lang', 1364 'is_disapproving', 1365 'notify_poster', 1366 'success_msg', 1367 'redirect', 1368 ); 1369 extract($phpbb_dispatcher->trigger_event('core.disapprove_posts_after', compact($vars))); 1370 1371 unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang); 1372 1373 meta_refresh(3, $redirect); 1374 $message = $user->lang[$success_msg]; 1375 1376 if ($request->is_ajax()) 1377 { 1378 $json_response = new \phpbb\json_response; 1379 $json_response->send(array( 1380 'MESSAGE_TITLE' => $user->lang['INFORMATION'], 1381 'MESSAGE_TEXT' => $message, 1382 'REFRESH_DATA' => null, 1383 'visible' => false, 1384 )); 1385 } 1386 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>'); 1387 trigger_error($message); 1388 } 1389 else 1390 { 1391 if (!function_exists('display_reasons')) 1392 { 1393 include($phpbb_root_path . 'includes/functions_display.' . $phpEx); 1394 } 1395 1396 $show_notify = false; 1397 1398 foreach ($post_info as $post_data) 1399 { 1400 if ($post_data['poster_id'] == ANONYMOUS) 1401 { 1402 continue; 1403 } 1404 else 1405 { 1406 $show_notify = true; 1407 break; 1408 } 1409 } 1410 1411 $l_confirm_msg = 'DISAPPROVE_POST'; 1412 $confirm_template = 'mcp_approve.html'; 1413 if ($is_disapproving) 1414 { 1415 display_reasons($reason_id); 1416 } 1417 else 1418 { 1419 $user->add_lang('posting'); 1420 1421 $l_confirm_msg = 'DELETE_POST_PERMANENTLY'; 1422 $confirm_template = 'confirm_delete_body.html'; 1423 } 1424 $l_confirm_msg .= ((sizeof($post_id_list) == 1) ? '' : 'S'); 1425 1426 $template->assign_vars(array( 1427 'S_NOTIFY_POSTER' => $show_notify, 1428 'S_APPROVE' => false, 1429 'REASON' => ($is_disapproving) ? $reason : '', 1430 'ADDITIONAL_MSG' => $additional_msg, 1431 )); 1432 1433 confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template); 1434 } 1435 1436 redirect($redirect); 1437 } 1438 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |