Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
mcp_queue.php
0001 <?php
0002 /**
0003 *
0004 * This file is part of the phpBB Forum Software package.
0005 *
0006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
0007 * @license GNU General Public License, version 2 (GPL-2.0)
0008 *
0009 * For full copyright and license information, please see
0010 * the docs/CREDITS.txt file.
0011 *
0012 */
0013
0014 /**
0015 * @ignore
0016 */
0017 if (!defined('IN_PHPBB'))
0018 {
0019 exit;
0020 }
0021
0022 /**
0023 * mcp_queue
0024 * Handling the moderation queue
0025 */
0026 class mcp_queue
0027 {
0028 var $p_master;
0029 var $u_action;
0030
0031 public function mcp_queue(&$p_master)
0032 {
0033 $this->p_master = &$p_master;
0034 }
0035
0036 public function main($id, $mode)
0037 {
0038 global $auth, $db, $user, $template, $cache, $request;
0039 global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container;
0040 global $phpbb_dispatcher;
0041
0042 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
0043
0044 $forum_id = request_var('f', 0);
0045 $start = request_var('start', 0);
0046
0047 $this->page_title = 'MCP_QUEUE';
0048
0049 switch ($action)
0050 {
0051 case 'approve':
0052 case 'restore':
0053 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
0054
0055 $post_id_list = $request->variable('post_id_list', array(0));
0056 $topic_id_list = $request->variable('topic_id_list', array(0));
0057
0058 if (!empty($post_id_list))
0059 {
0060 self::approve_posts($action, $post_id_list, 'queue', $mode);
0061 }
0062 else if (!empty($topic_id_list))
0063 {
0064 self::approve_topics($action, $topic_id_list, 'queue', $mode);
0065 }
0066 else
0067 {
0068 trigger_error('NO_POST_SELECTED');
0069 }
0070 break;
0071
0072 case 'delete':
0073 $post_id_list = $request->variable('post_id_list', array(0));
0074 $topic_id_list = $request->variable('topic_id_list', array(0));
0075
0076 if (!empty($post_id_list))
0077 {
0078 if (!function_exists('mcp_delete_post'))
0079 {
0080 global $phpbb_root_path, $phpEx;
0081 include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
0082 }
0083 mcp_delete_post($post_id_list, false, '', $action);
0084 }
0085 else if (!empty($topic_id_list))
0086 {
0087 if (!function_exists('mcp_delete_topic'))
0088 {
0089 global $phpbb_root_path, $phpEx;
0090 include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
0091 }
0092 mcp_delete_topic($topic_id_list, false, '', $action);
0093 }
0094 else
0095 {
0096 trigger_error('NO_POST_SELECTED');
0097 }
0098 break;
0099
0100 case 'disapprove':
0101 $post_id_list = $request->variable('post_id_list', array(0));
0102 $topic_id_list = $request->variable('topic_id_list', array(0));
0103
0104 if (!empty($topic_id_list) && $mode == 'deleted_topics')
0105 {
0106 if (!function_exists('mcp_delete_topics'))
0107 {
0108 global $phpbb_root_path, $phpEx;
0109 include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx);
0110 }
0111 mcp_delete_topic($topic_id_list, false, '', 'disapprove');
0112 return;
0113 }
0114
0115 if (!class_exists('messenger'))
0116 {
0117 include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
0118 }
0119
0120 if (!empty($topic_id_list))
0121 {
0122 $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : array(ITEM_UNAPPROVED, ITEM_REAPPROVE);
0123 $sql = 'SELECT post_id
0124 FROM ' . POSTS_TABLE . '
0125 WHERE ' . $db->sql_in_set('post_visibility', $post_visibility) . '
0126 AND ' . $db->sql_in_set('topic_id', $topic_id_list);
0127 $result = $db->sql_query($sql);
0128
0129 $post_id_list = array();
0130 while ($row = $db->sql_fetchrow($result))
0131 {
0132 $post_id_list[] = (int) $row['post_id'];
0133 }
0134 $db->sql_freeresult($result);
0135 }
0136
0137 if (!empty($post_id_list))
0138 {
0139 self::disapprove_posts($post_id_list, 'queue', $mode);
0140 }
0141 else
0142 {
0143 trigger_error('NO_POST_SELECTED');
0144 }
0145 break;
0146 }
0147
0148 switch ($mode)
0149 {
0150 case 'approve_details':
0151
0152 $this->tpl_name = 'mcp_post';
0153
0154 $user->add_lang(array('posting', 'viewtopic'));
0155
0156 $post_id = request_var('p', 0);
0157 $topic_id = request_var('t', 0);
0158
0159 $phpbb_notifications = $phpbb_container->get('notification_manager');
0160
0161 if ($topic_id)
0162 {
0163 $topic_info = phpbb_get_topic_data(array($topic_id), 'm_approve');
0164 if (isset($topic_info[$topic_id]['topic_first_post_id']))
0165 {
0166 $post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
0167
0168 $phpbb_notifications->mark_notifications_read('notification.type.topic_in_queue', $topic_id, $user->data['user_id']);
0169 }
0170 else
0171 {
0172 $topic_id = 0;
0173 }
0174 }
0175
0176 $phpbb_notifications->mark_notifications_read('notification.type.post_in_queue', $post_id, $user->data['user_id']);
0177
0178 $post_info = phpbb_get_post_data(array($post_id), 'm_approve', true);
0179
0180 if (!sizeof($post_info))
0181 {
0182 trigger_error('NO_POST_SELECTED');
0183 }
0184
0185 $post_info = $post_info[$post_id];
0186
0187 if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
0188 {
0189 $template->assign_vars(array(
0190 'S_TOPIC_REVIEW' => true,
0191 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'],
0192 'TOPIC_TITLE' => $post_info['topic_title'],
0193 ));
0194 }
0195
0196 $extensions = $attachments = $topic_tracking_info = array();
0197
0198 // Get topic tracking info
0199 if ($config['load_db_lastread'])
0200 {
0201 $tmp_topic_data = array($post_info['topic_id'] => $post_info);
0202 $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']));
0203 unset($tmp_topic_data);
0204 }
0205 else
0206 {
0207 $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
0208 }
0209
0210 $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
0211
0212 // Process message, leave it uncensored
0213 $parse_flags = ($post_info['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
0214 $message = generate_text_for_display($post_info['post_text'], $post_info['bbcode_uid'], $post_info['bbcode_bitfield'], $parse_flags, false);
0215
0216 if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
0217 {
0218 $extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
0219
0220 $sql = 'SELECT *
0221 FROM ' . ATTACHMENTS_TABLE . '
0222 WHERE post_msg_id = ' . $post_id . '
0223 AND in_message = 0
0224 ORDER BY filetime DESC, post_msg_id ASC';
0225 $result = $db->sql_query($sql);
0226
0227 while ($row = $db->sql_fetchrow($result))
0228 {
0229 $attachments[] = $row;
0230 }
0231 $db->sql_freeresult($result);
0232
0233 if (sizeof($attachments))
0234 {
0235 $update_count = array();
0236 parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
0237 }
0238
0239 // Display not already displayed Attachments for this post, we already parsed them. ;)
0240 if (!empty($attachments))
0241 {
0242 $template->assign_var('S_HAS_ATTACHMENTS', true);
0243
0244 foreach ($attachments as $attachment)
0245 {
0246 $template->assign_block_vars('attachment', array(
0247 'DISPLAY_ATTACHMENT' => $attachment,
0248 ));
0249 }
0250 }
0251 }
0252
0253 // Deleting information
0254 if ($post_info['post_visibility'] == ITEM_DELETED && $post_info['post_delete_user'])
0255 {
0256 // User having deleted the post also being the post author?
0257 if (!$post_info['post_delete_user'] || $post_info['post_delete_user'] == $post_info['poster_id'])
0258 {
0259 $display_username = get_username_string('full', $post_info['poster_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']);
0260 }
0261 else
0262 {
0263 $sql = 'SELECT u.user_id, u.username, u.user_colour
0264 FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
0265 WHERE p.post_id = ' . $post_info['post_id'] . '
0266 AND p.post_delete_user = u.user_id';
0267 $result = $db->sql_query($sql);
0268 $post_delete_userinfo = $db->sql_fetchrow($result);
0269 $db->sql_freeresult($result);
0270 $display_username = get_username_string('full', $post_info['post_delete_user'], $post_delete_userinfo['username'], $post_delete_userinfo['user_colour']);
0271 }
0272
0273 $l_deleted_by = $user->lang('DELETED_INFORMATION', $display_username, $user->format_date($post_info['post_delete_time'], false, true));
0274 }
0275 else
0276 {
0277 $l_deleted_by = '';
0278 }
0279
0280 $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']);
0281 $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']);
0282
0283 $template->assign_vars(array(
0284 'S_MCP_QUEUE' => true,
0285 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"),
0286 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
0287 'S_POST_REPORTED' => $post_info['post_reported'],
0288 'S_POST_UNAPPROVED' => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE,
0289 'S_POST_LOCKED' => $post_info['post_edit_locked'],
0290 'S_USER_NOTES' => true,
0291 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED),
0292 'DELETED_MESSAGE' => $l_deleted_by,
0293 'DELETE_REASON' => $post_info['post_delete_reason'],
0294
0295 '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']}") : '',
0296 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
0297 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
0298 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']),
0299 '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']) : '',
0300 'U_VIEW_POST' => $post_url,
0301 'U_VIEW_TOPIC' => $topic_url,
0302
0303 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
0304
0305 '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>'),
0306 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'),
0307 'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'),
0308 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
0309 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
0310 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
0311
0312 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0313 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0314 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0315 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
0316
0317 'POST_PREVIEW' => $message,
0318 'POST_SUBJECT' => $post_info['post_subject'],
0319 'POST_DATE' => $user->format_date($post_info['post_time']),
0320 'POST_IP' => $post_info['poster_ip'],
0321 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
0322 'POST_ID' => $post_info['post_id'],
0323 'S_FIRST_POST' => ($post_info['topic_first_post_id'] == $post_id),
0324
0325 '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' : '',
0326 ));
0327
0328 break;
0329
0330 case 'unapproved_topics':
0331 case 'unapproved_posts':
0332 case 'deleted_topics':
0333 case 'deleted_posts':
0334 $m_perm = 'm_approve';
0335 $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false;
0336 $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false;
0337 $visibility_const = (!$is_restore) ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED;
0338
0339 $user->add_lang(array('viewtopic', 'viewforum'));
0340
0341 $topic_id = $request->variable('t', 0);
0342 $forum_info = array();
0343 $pagination = $phpbb_container->get('pagination');
0344
0345 if ($topic_id)
0346 {
0347 $topic_info = phpbb_get_topic_data(array($topic_id));
0348
0349 if (!sizeof($topic_info))
0350 {
0351 trigger_error('TOPIC_NOT_EXIST');
0352 }
0353
0354 $topic_info = $topic_info[$topic_id];
0355 $forum_id = $topic_info['forum_id'];
0356 }
0357
0358 $forum_list_approve = get_forum_list($m_perm, false, true);
0359 $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
0360
0361 // Remove forums we cannot read
0362 foreach ($forum_list_approve as $k => $forum_data)
0363 {
0364 if (!isset($forum_list_read[$forum_data['forum_id']]))
0365 {
0366 unset($forum_list_approve[$k]);
0367 }
0368 }
0369 unset($forum_list_read);
0370
0371 if (!$forum_id)
0372 {
0373 $forum_list = array();
0374 foreach ($forum_list_approve as $row)
0375 {
0376 $forum_list[] = $row['forum_id'];
0377 }
0378
0379 if (!sizeof($forum_list))
0380 {
0381 trigger_error('NOT_MODERATOR');
0382 }
0383
0384 $sql = 'SELECT SUM(forum_topics_approved) as sum_forum_topics
0385 FROM ' . FORUMS_TABLE . '
0386 WHERE ' . $db->sql_in_set('forum_id', $forum_list);
0387 $result = $db->sql_query($sql);
0388 $forum_info['forum_topics_approved'] = (int) $db->sql_fetchfield('sum_forum_topics');
0389 $db->sql_freeresult($result);
0390 }
0391 else
0392 {
0393 $forum_info = phpbb_get_forum_data(array($forum_id), $m_perm);
0394
0395 if (!sizeof($forum_info))
0396 {
0397 trigger_error('NOT_MODERATOR');
0398 }
0399
0400 $forum_info = $forum_info[$forum_id];
0401 $forum_list = $forum_id;
0402 }
0403
0404 $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
0405 foreach ($forum_list_approve as $row)
0406 {
0407 $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat(' ', $row['padding']) . $row['forum_name'] . '</option>';
0408 }
0409
0410 $sort_days = $total = 0;
0411 $sort_key = $sort_dir = '';
0412 $sort_by_sql = $sort_order_sql = array();
0413 phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
0414
0415 $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total;
0416 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
0417
0418 $forum_names = array();
0419
0420 if (!$is_topics)
0421 {
0422 $sql = 'SELECT p.post_id
0423 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . '
0424 WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . '
0425 AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) . '
0426 ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
0427 ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
0428 AND t.topic_id = p.topic_id
0429 AND (t.topic_visibility <> p.post_visibility
0430 OR t.topic_delete_user = 0)
0431 $limit_time_sql
0432 ORDER BY $sort_order_sql";
0433
0434 /**
0435 * Alter sql query to get posts in queue to be accepted
0436 *
0437 * @event core.mcp_queue_get_posts_query_before
0438 * @var string sql Associative array with the query to be executed
0439 * @var array forum_list List of forums that contain the posts
0440 * @var int visibility_const Integer with one of the possible ITEM_* constant values
0441 * @var int topic_id If topic_id not equal to 0, the topic id to filter the posts to display
0442 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string)
0443 * @var string sort_order_sql String with the ORDER BY SQL code used in this query
0444 * @since 3.1.0-RC3
0445 */
0446 $vars = array(
0447 'sql',
0448 'forum_list',
0449 'visibility_const',
0450 'topic_id',
0451 'limit_time_sql',
0452 'sort_order_sql',
0453 );
0454 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_query_before', compact($vars)));
0455
0456 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
0457
0458 $i = 0;
0459 $post_ids = array();
0460 while ($row = $db->sql_fetchrow($result))
0461 {
0462 $post_ids[] = $row['post_id'];
0463 $row_num[$row['post_id']] = $i++;
0464 }
0465 $db->sql_freeresult($result);
0466
0467 if (sizeof($post_ids))
0468 {
0469 $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
0470 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
0471 WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
0472 AND t.topic_id = p.topic_id
0473 AND u.user_id = p.poster_id
0474 ORDER BY ' . $sort_order_sql;
0475 $result = $db->sql_query($sql);
0476
0477 $post_data = $rowset = array();
0478 while ($row = $db->sql_fetchrow($result))
0479 {
0480 $forum_names[] = $row['forum_id'];
0481 $post_data[$row['post_id']] = $row;
0482 }
0483 $db->sql_freeresult($result);
0484
0485 foreach ($post_ids as $post_id)
0486 {
0487 $rowset[] = $post_data[$post_id];
0488 }
0489 unset($post_data, $post_ids);
0490 }
0491 else
0492 {
0493 $rowset = array();
0494 }
0495 }
0496 else
0497 {
0498 $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
0499 FROM ' . TOPICS_TABLE . ' t
0500 WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
0501 AND ' . $db->sql_in_set('topic_visibility', $visibility_const) . "
0502 AND topic_delete_user <> 0
0503 $limit_time_sql
0504 ORDER BY $sort_order_sql";
0505
0506 /**
0507 * Alter sql query to get information on all topics in the list of forums provided.
0508 *
0509 * @event core.mcp_queue_get_posts_for_topics_query_before
0510 * @var string sql String with the query to be executed
0511 * @var array forum_list List of forums that contain the posts
0512 * @var int visibility_const Integer with one of the possible ITEM_* constant values
0513 * @var int topic_id topic_id in the page request
0514 * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string)
0515 * @var string sort_order_sql String with the ORDER BY SQL code used in this query
0516 * @since 3.1.0-RC3
0517 */
0518 $vars = array(
0519 'sql',
0520 'forum_list',
0521 'visibility_const',
0522 'topic_id',
0523 'limit_time_sql',
0524 'sort_order_sql',
0525 );
0526 extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_topics_query_before', compact($vars)));
0527
0528 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
0529
0530 $rowset = array();
0531 while ($row = $db->sql_fetchrow($result))
0532 {
0533 $forum_names[] = $row['forum_id'];
0534 $rowset[] = $row;
0535 }
0536 $db->sql_freeresult($result);
0537 }
0538
0539 if (sizeof($forum_names))
0540 {
0541 // Select the names for the forum_ids
0542 $sql = 'SELECT forum_id, forum_name
0543 FROM ' . FORUMS_TABLE . '
0544 WHERE ' . $db->sql_in_set('forum_id', $forum_names);
0545 $result = $db->sql_query($sql, 3600);
0546
0547 $forum_names = array();
0548 while ($row = $db->sql_fetchrow($result))
0549 {
0550 $forum_names[$row['forum_id']] = $row['forum_name'];
0551 }
0552 $db->sql_freeresult($result);
0553 }
0554
0555 foreach ($rowset as $row)
0556 {
0557 if (empty($row['post_username']))
0558 {
0559 $row['post_username'] = $row['username'] ?: $user->lang['GUEST'];
0560 }
0561
0562 $template->assign_block_vars('postrow', array(
0563 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
0564 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
0565 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''),
0566 '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']}" : '')),
0567
0568 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0569 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0570 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0571 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
0572
0573 'POST_ID' => $row['post_id'],
0574 'TOPIC_ID' => $row['topic_id'],
0575 'FORUM_NAME' => $forum_names[$row['forum_id']],
0576 'POST_SUBJECT' => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
0577 'TOPIC_TITLE' => $row['topic_title'],
0578 'POST_TIME' => $user->format_date($row['post_time']),
0579 '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']) : '',
0580 ));
0581 }
0582 unset($rowset, $forum_names);
0583
0584 $base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir";
0585 $pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start);
0586
0587 // Now display the page
0588 $template->assign_vars(array(
0589 'L_DISPLAY_ITEMS' => (!$is_topics) ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
0590 'L_EXPLAIN' => $user->lang['MCP_QUEUE_' . strtoupper($mode) . '_EXPLAIN'],
0591 'L_TITLE' => $user->lang['MCP_QUEUE_' . strtoupper($mode)],
0592 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
0593
0594 'S_FORUM_OPTIONS' => $forum_options,
0595 'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')),
0596 'S_TOPICS' => $is_topics,
0597 'S_RESTORE' => $is_restore,
0598
0599 'TOPIC_ID' => $topic_id,
0600 'TOTAL' => $user->lang(((!$is_topics) ? 'VIEW_TOPIC_POSTS' : 'VIEW_FORUM_TOPICS'), (int) $total),
0601 ));
0602
0603 $this->tpl_name = 'mcp_queue';
0604 break;
0605 }
0606 }
0607
0608 /**
0609 * Approve/Restore posts
0610 *
0611 * @param $action string Action we perform on the posts ('approve' or 'restore')
0612 * @param $post_id_list array IDs of the posts to approve/restore
0613 * @param $id mixed Category of the current active module
0614 * @param $mode string Active module
0615 * @return null
0616 */
0617 static public function approve_posts($action, $post_id_list, $id, $mode)
0618 {
0619 global $db, $template, $user, $config, $request, $phpbb_container;
0620 global $phpEx, $phpbb_root_path;
0621
0622 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
0623 {
0624 trigger_error('NOT_AUTHORISED');
0625 }
0626
0627 $redirect = $request->variable('redirect', build_url(array('quickmod')));
0628 $redirect = reapply_sid($redirect);
0629 $success_msg = $post_url = '';
0630 $approve_log = array();
0631 $num_topics = 0;
0632
0633 $s_hidden_fields = build_hidden_fields(array(
0634 'i' => $id,
0635 'mode' => $mode,
0636 'post_id_list' => $post_id_list,
0637 'action' => $action,
0638 'redirect' => $redirect,
0639 ));
0640
0641 $post_info = phpbb_get_post_data($post_id_list, 'm_approve');
0642
0643 if (confirm_box(true))
0644 {
0645 $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster']));
0646
0647 $topic_info = array();
0648
0649 // Group the posts by topic_id
0650 foreach ($post_info as $post_id => $post_data)
0651 {
0652 if ($post_data['post_visibility'] == ITEM_APPROVED)
0653 {
0654 continue;
0655 }
0656 $topic_id = (int) $post_data['topic_id'];
0657
0658 $topic_info[$topic_id]['posts'][] = (int) $post_id;
0659 $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id'];
0660
0661 // Refresh the first post, if the time or id is older then the current one
0662 if ($post_id <= $post_data['topic_first_post_id'] || $post_data['post_time'] <= $post_data['topic_time'])
0663 {
0664 $topic_info[$topic_id]['first_post'] = true;
0665 }
0666
0667 // Refresh the last post, if the time or id is newer then the current one
0668 if ($post_id >= $post_data['topic_last_post_id'] || $post_data['post_time'] >= $post_data['topic_last_post_time'])
0669 {
0670 $topic_info[$topic_id]['last_post'] = true;
0671 }
0672
0673 $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'];
0674
0675 $approve_log[] = array(
0676 'forum_id' => $post_data['forum_id'],
0677 'topic_id' => $post_data['topic_id'],
0678 'post_subject' => $post_data['post_subject'],
0679 );
0680 }
0681
0682 $phpbb_content_visibility = $phpbb_container->get('content.visibility');
0683 foreach ($topic_info as $topic_id => $topic_data)
0684 {
0685 $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']));
0686 }
0687
0688 foreach ($approve_log as $log_data)
0689 {
0690 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_POST_' . strtoupper($action) . 'D', $log_data['post_subject']);
0691 }
0692
0693 // Only send out the mails, when the posts are being approved
0694 if ($action == 'approve')
0695 {
0696 $phpbb_notifications = $phpbb_container->get('notification_manager');
0697
0698 // Handle notifications
0699 foreach ($post_info as $post_id => $post_data)
0700 {
0701 // A single topic approval may also happen here, so handle deleting the respective notification.
0702 if (!$post_data['topic_posts_approved'])
0703 {
0704 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']);
0705
0706 if ($post_data['post_visibility'] == ITEM_UNAPPROVED)
0707 {
0708 $phpbb_notifications->add_notifications(array('notification.type.topic'), $post_data);
0709 }
0710 if ($post_data['post_visibility'] != ITEM_APPROVED)
0711 {
0712 $num_topics++;
0713 }
0714 }
0715 else
0716 {
0717 // Only add notifications, if we are not reapproving post
0718 // When the topic was already approved, but was edited and
0719 // now needs re-approval, we don't want to notify the users
0720 // again.
0721 if ($post_data['post_visibility'] == ITEM_UNAPPROVED)
0722 {
0723 $phpbb_notifications->add_notifications(array(
0724 'notification.type.bookmark',
0725 'notification.type.post',
0726 ), $post_data);
0727 }
0728 }
0729 $phpbb_notifications->add_notifications(array('notification.type.quote'), $post_data);
0730 $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id);
0731
0732 $phpbb_notifications->mark_notifications_read(array(
0733 'notification.type.quote',
0734 'notification.type.bookmark',
0735 'notification.type.post',
0736 ), $post_data['post_id'], $user->data['user_id']);
0737
0738 // Notify Poster?
0739 if ($notify_poster)
0740 {
0741 if ($post_data['poster_id'] == ANONYMOUS)
0742 {
0743 continue;
0744 }
0745
0746 if (!$post_data['topic_posts_approved'])
0747 {
0748 $phpbb_notifications->add_notifications('notification.type.approve_topic', $post_data);
0749 }
0750 else
0751 {
0752 $phpbb_notifications->add_notifications('notification.type.approve_post', $post_data);
0753 }
0754 }
0755 }
0756 }
0757
0758 if ($num_topics >= 1)
0759 {
0760 $success_msg = ($num_topics == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS';
0761 }
0762 else
0763 {
0764 $success_msg = (sizeof($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS';
0765 }
0766
0767 meta_refresh(3, $redirect);
0768 $message = $user->lang[$success_msg];
0769
0770 if ($request->is_ajax())
0771 {
0772 $json_response = new \phpbb\json_response;
0773 $json_response->send(array(
0774 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
0775 'MESSAGE_TEXT' => $message,
0776 'REFRESH_DATA' => null,
0777 'visible' => true,
0778 ));
0779 }
0780 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
0781
0782 // If approving one post, also give links back to post...
0783 if (sizeof($post_info) == 1 && $post_url)
0784 {
0785 $message .= '<br /><br />' . $user->lang('RETURN_POST', '<a href="' . $post_url . '">', '</a>');
0786 }
0787 trigger_error($message);
0788 }
0789 else
0790 {
0791 $show_notify = false;
0792
0793 if ($action == 'approve')
0794 {
0795 foreach ($post_info as $post_data)
0796 {
0797 if (!$post_data['topic_posts_approved'])
0798 {
0799 $num_topics++;
0800 }
0801
0802 if (!$show_notify && $post_data['poster_id'] != ANONYMOUS)
0803 {
0804 $show_notify = true;
0805 }
0806 }
0807 }
0808
0809 $template->assign_vars(array(
0810 'S_NOTIFY_POSTER' => $show_notify,
0811 'S_' . strtoupper($action) => true,
0812 ));
0813
0814 // Create the confirm box message
0815 $action_msg = strtoupper($action);
0816 $num_posts = sizeof($post_id_list) - $num_topics;
0817 if ($num_topics > 0 && $num_posts <= 0)
0818 {
0819 $action_msg .= '_TOPIC' . (($num_topics == 1) ? '' : 'S');
0820 }
0821 else
0822 {
0823 $action_msg .= '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S');
0824 }
0825 confirm_box(false, $action_msg, $s_hidden_fields, 'mcp_approve.html');
0826 }
0827
0828 redirect($redirect);
0829 }
0830
0831 /**
0832 * Approve/Restore topics
0833 *
0834 * @param $action string Action we perform on the posts ('approve' or 'restore')
0835 * @param $topic_id_list array IDs of the topics to approve/restore
0836 * @param $id mixed Category of the current active module
0837 * @param $mode string Active module
0838 * @return null
0839 */
0840 static public function approve_topics($action, $topic_id_list, $id, $mode)
0841 {
0842 global $db, $template, $user, $config;
0843 global $phpEx, $phpbb_root_path, $request, $phpbb_container;
0844
0845 if (!phpbb_check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve')))
0846 {
0847 trigger_error('NOT_AUTHORISED');
0848 }
0849
0850 $redirect = $request->variable('redirect', build_url(array('quickmod')));
0851 $redirect = reapply_sid($redirect);
0852 $success_msg = $topic_url = '';
0853 $approve_log = array();
0854
0855 $s_hidden_fields = build_hidden_fields(array(
0856 'i' => $id,
0857 'mode' => $mode,
0858 'topic_id_list' => $topic_id_list,
0859 'action' => $action,
0860 'redirect' => $redirect,
0861 ));
0862
0863 $topic_info = phpbb_get_topic_data($topic_id_list, 'm_approve');
0864
0865 if (confirm_box(true))
0866 {
0867 $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false;
0868
0869 $phpbb_content_visibility = $phpbb_container->get('content.visibility');
0870 $first_post_ids = array();
0871
0872 foreach ($topic_info as $topic_id => $topic_data)
0873 {
0874 $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), '');
0875 $first_post_ids[$topic_id] = (int) $topic_data['topic_first_post_id'];
0876
0877 $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$topic_data['forum_id']}&t={$topic_id}");
0878
0879 $approve_log[] = array(
0880 'forum_id' => $topic_data['forum_id'],
0881 'topic_id' => $topic_data['topic_id'],
0882 'topic_title' => $topic_data['topic_title'],
0883 );
0884 }
0885
0886 if (sizeof($topic_info) >= 1)
0887 {
0888 $success_msg = (sizeof($topic_info) == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS';
0889 }
0890
0891 foreach ($approve_log as $log_data)
0892 {
0893 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_TOPIC_' . strtoupper($action) . 'D', $log_data['topic_title']);
0894 }
0895
0896 // Only send out the mails, when the posts are being approved
0897 if ($action == 'approve')
0898 {
0899 // Grab the first post text as it's needed for the quote notification.
0900 $sql = 'SELECT topic_id, post_text
0901 FROM ' . POSTS_TABLE . '
0902 WHERE ' . $db->sql_in_set('post_id', $first_post_ids);
0903 $result = $db->sql_query($sql);
0904
0905 while ($row = $db->sql_fetchrow($result))
0906 {
0907 $topic_info[$row['topic_id']]['post_text'] = $row['post_text'];
0908 }
0909 $db->sql_freeresult($result);
0910
0911 // Handle notifications
0912 $phpbb_notifications = $phpbb_container->get('notification_manager');
0913
0914 foreach ($topic_info as $topic_id => $topic_data)
0915 {
0916 $topic_data = array_merge($topic_data, array(
0917 'post_id' => $topic_data['topic_first_post_id'],
0918 'post_subject' => $topic_data['topic_title'],
0919 'post_time' => $topic_data['topic_time'],
0920 'poster_id' => $topic_data['topic_poster'],
0921 'post_username' => $topic_data['topic_first_poster_name'],
0922 ));
0923
0924 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $topic_id);
0925
0926 // Only add notifications, if we are not reapproving post
0927 // When the topic was already approved, but was edited and
0928 // now needs re-approval, we don't want to notify the users
0929 // again.
0930 if ($topic_data['topic_visibility'] == ITEM_UNAPPROVED)
0931 {
0932 $phpbb_notifications->add_notifications(array(
0933 'notification.type.quote',
0934 'notification.type.topic',
0935 ), $topic_data);
0936 }
0937
0938 $phpbb_notifications->mark_notifications_read('notification.type.quote', $topic_data['post_id'], $user->data['user_id']);
0939 $phpbb_notifications->mark_notifications_read('notification.type.topic', $topic_id, $user->data['user_id']);
0940
0941 if ($notify_poster)
0942 {
0943 $phpbb_notifications->add_notifications('notification.type.approve_topic', $topic_data);
0944 }
0945 }
0946 }
0947
0948 meta_refresh(3, $redirect);
0949 $message = $user->lang[$success_msg];
0950
0951 if ($request->is_ajax())
0952 {
0953 $json_response = new \phpbb\json_response;
0954 $json_response->send(array(
0955 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
0956 'MESSAGE_TEXT' => $message,
0957 'REFRESH_DATA' => null,
0958 'visible' => true,
0959 ));
0960 }
0961 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
0962
0963 // If approving one topic, also give links back to topic...
0964 if (sizeof($topic_info) == 1 && $topic_url)
0965 {
0966 $message .= '<br /><br />' . $user->lang('RETURN_TOPIC', '<a href="' . $topic_url . '">', '</a>');
0967 }
0968 trigger_error($message);
0969 }
0970 else
0971 {
0972 $show_notify = false;
0973
0974 if ($action == 'approve')
0975 {
0976 foreach ($topic_info as $topic_data)
0977 {
0978 if ($topic_data['topic_poster'] == ANONYMOUS)
0979 {
0980 continue;
0981 }
0982 else
0983 {
0984 $show_notify = true;
0985 break;
0986 }
0987 }
0988 }
0989
0990 $template->assign_vars(array(
0991 'S_NOTIFY_POSTER' => $show_notify,
0992 'S_' . strtoupper($action) => true,
0993 ));
0994
0995 confirm_box(false, strtoupper($action) . '_TOPIC' . ((sizeof($topic_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
0996 }
0997
0998 redirect($redirect);
0999 }
1000
1001 /**
1002 * Disapprove Post
1003 *
1004 * @param $post_id_list array IDs of the posts to disapprove/delete
1005 * @param $id mixed Category of the current active module
1006 * @param $mode string Active module
1007 * @return null
1008 */
1009 static public function disapprove_posts($post_id_list, $id, $mode)
1010 {
1011 global $db, $template, $user, $config, $phpbb_container;
1012 global $phpEx, $phpbb_root_path, $request;
1013
1014 if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
1015 {
1016 trigger_error('NOT_AUTHORISED');
1017 }
1018
1019 $redirect = $request->variable('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode");
1020 $redirect = reapply_sid($redirect);
1021 $reason = $request->variable('reason', '', true);
1022 $reason_id = $request->variable('reason_id', 0);
1023 $success_msg = $additional_msg = '';
1024
1025 $s_hidden_fields = build_hidden_fields(array(
1026 'i' => $id,
1027 'mode' => $mode,
1028 'post_id_list' => $post_id_list,
1029 'action' => 'disapprove',
1030 'redirect' => $redirect,
1031 ));
1032
1033 $notify_poster = $request->is_set('notify_poster');
1034 $disapprove_reason = '';
1035
1036 if ($reason_id)
1037 {
1038 $sql = 'SELECT reason_title, reason_description
1039 FROM ' . REPORTS_REASONS_TABLE . "
1040 WHERE reason_id = $reason_id";
1041 $result = $db->sql_query($sql);
1042 $row = $db->sql_fetchrow($result);
1043 $db->sql_freeresult($result);
1044
1045 if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
1046 {
1047 $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
1048
1049 $request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
1050 $request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST);
1051 $request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST);
1052 }
1053 else
1054 {
1055 // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
1056 $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']) : '';
1057 $disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
1058
1059 if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
1060 {
1061 $disapprove_reason_lang = strtoupper($row['reason_title']);
1062 }
1063 }
1064 }
1065
1066 $post_info = phpbb_get_post_data($post_id_list, 'm_approve');
1067
1068 $is_disapproving = false;
1069 foreach ($post_info as $post_id => $post_data)
1070 {
1071 if ($post_data['post_visibility'] == ITEM_DELETED)
1072 {
1073 continue;
1074 }
1075
1076 $is_disapproving = true;
1077 }
1078
1079 if (confirm_box(true))
1080 {
1081 $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
1082 $topic_posts_unapproved = $post_disapprove_list = $topic_information = array();
1083
1084 // Build a list of posts to be disapproved and get the related topics real replies count
1085 foreach ($post_info as $post_id => $post_data)
1086 {
1087 $post_disapprove_list[$post_id] = $post_data['topic_id'];
1088 if (!isset($topic_posts_unapproved[$post_data['topic_id']]))
1089 {
1090 $topic_information[$post_data['topic_id']] = $post_data;
1091 $topic_posts_unapproved[$post_data['topic_id']] = 0;
1092 }
1093 $topic_posts_unapproved[$post_data['topic_id']]++;
1094 }
1095
1096 // Now we build the log array
1097 foreach ($post_disapprove_list as $post_id => $topic_id)
1098 {
1099 // If the count of disapproved posts for the topic is equal
1100 // to the number of unapproved posts in the topic, and there are no different
1101 // posts, we disapprove the hole topic
1102 if ($topic_information[$topic_id]['topic_posts_approved'] == 0 &&
1103 $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
1104 $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id])
1105 {
1106 // Don't write the log more than once for every topic
1107 if (!isset($disapprove_log_topics[$topic_id]))
1108 {
1109 // Build disapproved topics log
1110 $disapprove_log_topics[$topic_id] = array(
1111 'type' => 'topic',
1112 'post_subject' => $post_info[$post_id]['topic_title'],
1113 'forum_id' => $post_info[$post_id]['forum_id'],
1114 'topic_id' => 0, // useless to log a topic id, as it will be deleted
1115 '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'],
1116 );
1117 }
1118 }
1119 else
1120 {
1121 // Build disapproved posts log
1122 $disapprove_log_posts[] = array(
1123 'type' => 'post',
1124 'post_subject' => $post_info[$post_id]['post_subject'],
1125 'forum_id' => $post_info[$post_id]['forum_id'],
1126 'topic_id' => $post_info[$post_id]['topic_id'],
1127 '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'],
1128 );
1129
1130 }
1131 }
1132
1133 // Get disapproved posts/topics counts separately
1134 $num_disapproved_topics = sizeof($disapprove_log_topics);
1135 $num_disapproved_posts = sizeof($disapprove_log_posts);
1136
1137 // Build the whole log
1138 $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
1139
1140 // Unset unneeded arrays
1141 unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
1142
1143 // Let's do the job - delete disapproved posts
1144 if (sizeof($post_disapprove_list))
1145 {
1146 if (!function_exists('delete_posts'))
1147 {
1148 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
1149 }
1150
1151 // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
1152 // Note: function delete_posts triggers related forums/topics sync,
1153 // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
1154 delete_posts('post_id', array_keys($post_disapprove_list));
1155
1156 foreach ($disapprove_log as $log_data)
1157 {
1158 if ($is_disapproving)
1159 {
1160 $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED';
1161 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $disapprove_reason, $log_data['post_username']);
1162 }
1163 else
1164 {
1165 $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST';
1166 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $log_data['post_username']);
1167 }
1168 }
1169 }
1170
1171 $phpbb_notifications = $phpbb_container->get('notification_manager');
1172
1173 $lang_reasons = array();
1174
1175 foreach ($post_info as $post_id => $post_data)
1176 {
1177 $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 &&
1178 $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 &&
1179 $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id];
1180
1181 $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id);
1182
1183 // Do we disapprove the whole topic? Remove potential notifications
1184 if ($disapprove_all_posts_in_topic)
1185 {
1186 $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']);
1187 }
1188
1189 // Notify Poster?
1190 if ($notify_poster)
1191 {
1192 if ($post_data['poster_id'] == ANONYMOUS)
1193 {
1194 continue;
1195 }
1196
1197 $post_data['disapprove_reason'] = '';
1198 if (isset($disapprove_reason_lang))
1199 {
1200 // Okay we need to get the reason from the posters language
1201 if (!isset($lang_reasons[$post_data['user_lang']]))
1202 {
1203 // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
1204 $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
1205
1206 // Only load up the language pack if the language is different to the current one
1207 if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
1208 {
1209 // Load up the language pack
1210 $lang = array();
1211 @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
1212
1213 // If we find the reason in this language pack use it
1214 if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
1215 {
1216 $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
1217 }
1218
1219 unset($lang); // Free memory
1220 }
1221 }
1222
1223 $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']];
1224 $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : '';
1225 }
1226
1227 if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1)
1228 {
1229 // If there is only 1 post when disapproving the topic,
1230 // we send the user a "disapprove topic" notification...
1231 $phpbb_notifications->add_notifications('notification.type.disapprove_topic', $post_data);
1232 }
1233 else
1234 {
1235 // ... otherwise there are multiple unapproved posts and
1236 // all of them are disapproved as posts.
1237 $phpbb_notifications->add_notifications('notification.type.disapprove_post', $post_data);
1238 }
1239 }
1240 }
1241
1242 unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang);
1243
1244 if ($num_disapproved_topics)
1245 {
1246 $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS';
1247 }
1248 else
1249 {
1250 $success_msg = ($num_disapproved_posts == 1) ? 'POST' : 'POSTS';
1251 }
1252
1253 if ($is_disapproving)
1254 {
1255 $success_msg .= '_DISAPPROVED_SUCCESS';
1256 }
1257 else
1258 {
1259 $success_msg .= '_DELETED_SUCCESS';
1260 }
1261
1262 // If we came from viewtopic, we try to go back to it.
1263 if (strpos($redirect, $phpbb_root_path . 'viewtopic.' . $phpEx) === 0)
1264 {
1265 if ($num_disapproved_topics == 0)
1266 {
1267 // So we need to remove the post id part from the Url
1268 $redirect = str_replace("&p={$post_id_list[0]}#p{$post_id_list[0]}", '', $redirect);
1269 }
1270 else
1271 {
1272 // However this is only possible if the topic still exists,
1273 // Otherwise we go back to the viewforum page
1274 $redirect = append_sid($phpbb_root_path . 'viewforum.' . $phpEx, 'f=' . $request->variable('f', 0));
1275 }
1276 }
1277
1278 meta_refresh(3, $redirect);
1279 $message = $user->lang[$success_msg];
1280
1281 if ($request->is_ajax())
1282 {
1283 $json_response = new \phpbb\json_response;
1284 $json_response->send(array(
1285 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
1286 'MESSAGE_TEXT' => $message,
1287 'REFRESH_DATA' => null,
1288 'visible' => false,
1289 ));
1290 }
1291 $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
1292 trigger_error($message);
1293 }
1294 else
1295 {
1296 if (!function_exists('display_reasons'))
1297 {
1298 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1299 }
1300
1301 $show_notify = false;
1302
1303 foreach ($post_info as $post_data)
1304 {
1305 if ($post_data['poster_id'] == ANONYMOUS)
1306 {
1307 continue;
1308 }
1309 else
1310 {
1311 $show_notify = true;
1312 break;
1313 }
1314 }
1315
1316 $l_confirm_msg = 'DISAPPROVE_POST';
1317 $confirm_template = 'mcp_approve.html';
1318 if ($is_disapproving)
1319 {
1320 display_reasons($reason_id);
1321 }
1322 else
1323 {
1324 $user->add_lang('posting');
1325
1326 $l_confirm_msg = 'DELETE_POST_PERMANENTLY';
1327 $confirm_template = 'confirm_delete_body.html';
1328 }
1329 $l_confirm_msg .= ((sizeof($post_id_list) == 1) ? '' : 'S');
1330
1331 $template->assign_vars(array(
1332 'S_NOTIFY_POSTER' => $show_notify,
1333 'S_APPROVE' => false,
1334 'REASON' => ($is_disapproving) ? $reason : '',
1335 'ADDITIONAL_MSG' => $additional_msg,
1336 ));
1337
1338 confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template);
1339 }
1340
1341 redirect($redirect);
1342 }
1343 }
1344