6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
21 * Handling the moderation queue
29 function mcp_queue(&$p_master)
31 $this->p_master = &$p_master;
34 function main($id, $mode)
36 global $auth, $db, $user, $template, $cache;
37 global $config, $phpbb_root_path, $phpEx, $action;
39 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
41 $forum_id = request_var('f', 0);
42 $start = request_var('start', 0);
44 $this->page_title = 'MCP_QUEUE';
50 include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
52 $post_id_list = request_var('post_id_list', array(0));
54 if (!sizeof($post_id_list))
56 trigger_error('NO_POST_SELECTED');
59 if ($action == 'approve')
61 approve_post($post_id_list, 'queue', $mode);
65 disapprove_post($post_id_list, 'queue', $mode);
73 case 'approve_details':
75 $this->tpl_name = 'mcp_post';
77 $user->add_lang(array('posting', 'viewtopic'));
79 $post_id = request_var('p', 0);
80 $topic_id = request_var('t', 0);
84 $topic_info = get_topic_data(array($topic_id), 'm_approve');
85 if (isset($topic_info[$topic_id]['topic_first_post_id']))
87 $post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
95 $post_info = get_post_data(array($post_id), 'm_approve', true);
97 if (!sizeof($post_info))
99 trigger_error('NO_POST_SELECTED');
102 $post_info = $post_info[$post_id];
104 if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
106 $template->assign_vars(array(
107 'S_TOPIC_REVIEW' => true,
108 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'],
109 'TOPIC_TITLE' => $post_info['topic_title'])
113 $extensions = $attachments = $topic_tracking_info = array();
115 // Get topic tracking info
116 if ($config['load_db_lastread'])
118 $tmp_topic_data = array($post_info['topic_id'] => $post_info);
119 $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']));
120 unset($tmp_topic_data);
124 $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
127 $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
129 // Process message, leave it uncensored
130 $message = $post_info['post_text'];
132 if ($post_info['bbcode_bitfield'])
134 include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
135 $bbcode = new bbcode($post_info['bbcode_bitfield']);
136 $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
139 $message = bbcode_nl2br($message);
140 $message = smiley_text($message);
142 if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
144 $extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
147 FROM ' . ATTACHMENTS_TABLE . '
148 WHERE post_msg_id = ' . $post_id . '
150 ORDER BY filetime DESC, post_msg_id ASC';
151 $result = $db->sql_query($sql);
153 while ($row = $db->sql_fetchrow($result))
155 $attachments[] = $row;
157 $db->sql_freeresult($result);
159 if (sizeof($attachments))
161 $update_count = array();
162 parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
165 // Display not already displayed Attachments for this post, we already parsed them. ;)
166 if (!empty($attachments))
168 $template->assign_var('S_HAS_ATTACHMENTS', true);
170 foreach ($attachments as $attachment)
172 $template->assign_block_vars('attachment', array(
173 'DISPLAY_ATTACHMENT' => $attachment)
179 $post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']);
180 $topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']);
182 $template->assign_vars(array(
183 'S_MCP_QUEUE' => true,
184 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"),
185 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
186 'S_POST_REPORTED' => $post_info['post_reported'],
187 'S_POST_UNAPPROVED' => !$post_info['post_approved'],
188 'S_POST_LOCKED' => $post_info['post_edit_locked'],
189 'S_USER_NOTES' => true,
191 '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']}") : '',
192 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
193 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
194 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']),
195 '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']) : '',
196 'U_VIEW_POST' => $post_url,
197 'U_VIEW_TOPIC' => $topic_url,
199 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
201 '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>'),
202 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'),
203 'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'),
204 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
205 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
206 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
208 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
209 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
210 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
211 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
213 'POST_PREVIEW' => $message,
214 'POST_SUBJECT' => $post_info['post_subject'],
215 'POST_DATE' => $user->format_date($post_info['post_time']),
216 'POST_IP' => $post_info['poster_ip'],
217 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
218 'POST_ID' => $post_info['post_id'],
219 'S_FIRST_POST' => ($post_info['topic_first_post_id'] == $post_id),
221 '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' : '',
226 case 'unapproved_topics':
227 case 'unapproved_posts':
228 $user->add_lang(array('viewtopic', 'viewforum'));
230 $topic_id = request_var('t', 0);
231 $forum_info = array();
235 $topic_info = get_topic_data(array($topic_id));
237 if (!sizeof($topic_info))
239 trigger_error('TOPIC_NOT_EXIST');
242 $topic_info = $topic_info[$topic_id];
243 $forum_id = $topic_info['forum_id'];
246 $forum_list_approve = get_forum_list('m_approve', false, true);
247 $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
249 // Remove forums we cannot read
250 foreach ($forum_list_approve as $k => $forum_data)
252 if (!isset($forum_list_read[$forum_data['forum_id']]))
254 unset($forum_list_approve[$k]);
257 unset($forum_list_read);
261 $forum_list = array();
262 foreach ($forum_list_approve as $row)
264 $forum_list[] = $row['forum_id'];
267 if (!sizeof($forum_list))
269 trigger_error('NOT_MODERATOR');
272 $global_id = $forum_list[0];
274 $forum_list = implode(', ', $forum_list);
276 $sql = 'SELECT SUM(forum_topics) as sum_forum_topics
277 FROM ' . FORUMS_TABLE . "
278 WHERE forum_id IN (0, $forum_list)";
279 $result = $db->sql_query($sql);
280 $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
281 $db->sql_freeresult($result);
285 $forum_info = get_forum_data(array($forum_id), 'm_approve');
287 if (!sizeof($forum_info))
289 trigger_error('NOT_MODERATOR');
292 $forum_info = $forum_info[$forum_id];
293 $forum_list = $forum_id;
294 $global_id = $forum_id;
297 $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
298 foreach ($forum_list_approve as $row)
300 $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat(' ', $row['padding']) . $row['forum_name'] . '</option>';
303 $sort_days = $total = 0;
304 $sort_key = $sort_dir = '';
305 $sort_by_sql = $sort_order_sql = array();
306 mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
308 $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
309 $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';
311 $forum_names = array();
313 if ($mode == 'unapproved_posts')
315 $sql = 'SELECT p.post_id
316 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . "
317 WHERE p.forum_id IN (0, $forum_list)
318 AND p.post_approved = 0
319 " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
320 ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
321 AND t.topic_id = p.topic_id
322 AND t.topic_first_post_id <> p.post_id
324 ORDER BY $sort_order_sql";
325 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
329 while ($row = $db->sql_fetchrow($result))
331 $post_ids[] = $row['post_id'];
332 $row_num[$row['post_id']] = $i++;
334 $db->sql_freeresult($result);
336 if (sizeof($post_ids))
338 $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, u.username, u.username_clean, u.user_colour
339 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
340 WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
341 AND t.topic_id = p.topic_id
342 AND u.user_id = p.poster_id
343 ORDER BY ' . $sort_order_sql;
344 $result = $db->sql_query($sql);
346 $post_data = $rowset = array();
347 while ($row = $db->sql_fetchrow($result))
349 if ($row['forum_id'])
351 $forum_names[] = $row['forum_id'];
353 $post_data[$row['post_id']] = $row;
355 $db->sql_freeresult($result);
357 foreach ($post_ids as $post_id)
359 $rowset[] = $post_data[$post_id];
361 unset($post_data, $post_ids);
370 $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_first_poster_name AS username, t.topic_first_poster_colour AS user_colour
371 FROM ' . TOPICS_TABLE . " t
372 WHERE forum_id IN (0, $forum_list)
373 AND topic_approved = 0
375 ORDER BY $sort_order_sql";
376 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
379 while ($row = $db->sql_fetchrow($result))
381 if ($row['forum_id'])
383 $forum_names[] = $row['forum_id'];
387 $db->sql_freeresult($result);
390 if (sizeof($forum_names))
392 // Select the names for the forum_ids
393 $sql = 'SELECT forum_id, forum_name
394 FROM ' . FORUMS_TABLE . '
395 WHERE ' . $db->sql_in_set('forum_id', $forum_names);
396 $result = $db->sql_query($sql, 3600);
398 $forum_names = array();
399 while ($row = $db->sql_fetchrow($result))
401 $forum_names[$row['forum_id']] = $row['forum_name'];
403 $db->sql_freeresult($result);
406 foreach ($rowset as $row)
408 $global_topic = ($row['forum_id']) ? false : true;
411 $row['forum_id'] = $global_id;
414 if (empty($row['post_username']))
416 $row['post_username'] = $user->lang['GUEST'];
419 $template->assign_block_vars('postrow', array(
420 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
421 'U_VIEWFORUM' => (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
422 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''),
423 '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']}" : '')),
425 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
426 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
427 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
428 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
430 'POST_ID' => $row['post_id'],
431 'FORUM_NAME' => (!$global_topic) ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'],
432 'POST_SUBJECT' => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
433 'TOPIC_TITLE' => $row['topic_title'],
434 'POST_TIME' => $user->format_date($row['post_time']))
437 unset($rowset, $forum_names);
439 // Now display the page
440 $template->assign_vars(array(
441 'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
442 'L_EXPLAIN' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'],
443 'L_TITLE' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'],
444 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
446 'S_FORUM_OPTIONS' => $forum_options,
447 'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')),
448 'S_TOPICS' => ($mode == 'unapproved_posts') ? false : true,
450 'PAGINATION' => generate_pagination($this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir", $total, $config['topics_per_page'], $start),
451 'PAGE_NUMBER' => on_page($total, $config['topics_per_page'], $start),
452 'TOPIC_ID' => $topic_id,
453 'TOTAL' => ($total == 1) ? (($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POST'] : $user->lang['VIEW_FORUM_TOPIC']) : sprintf((($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POSTS'] : $user->lang['VIEW_FORUM_TOPICS']), $total),
456 $this->tpl_name = 'mcp_queue';
465 function approve_post($post_id_list, $id, $mode)
467 global $db, $template, $user, $config;
468 global $phpEx, $phpbb_root_path;
470 if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
472 trigger_error('NOT_AUTHORISED');
475 $redirect = request_var('redirect', build_url(array('quickmod')));
478 $s_hidden_fields = build_hidden_fields(array(
481 'post_id_list' => $post_id_list,
482 'action' => 'approve',
483 'redirect' => $redirect)
486 $post_info = get_post_data($post_id_list, 'm_approve');
488 if (confirm_box(true))
490 $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
492 // If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
493 // If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
495 $total_topics = $total_posts = 0;
496 $topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
497 $user_posts_sql = $post_approved_list = array();
499 foreach ($post_info as $post_id => $post_data)
501 if ($post_data['post_approved'])
503 $post_approved_list[] = $post_id;
507 $topic_id_list[$post_data['topic_id']] = 1;
509 if ($post_data['forum_id'])
511 $forum_id_list[$post_data['forum_id']] = 1;
514 // User post update (we do not care about topic or post, since user posts are strictly connected to posts)
515 // But we care about forums where post counts get not increased. ;)
516 if ($post_data['post_postcount'])
518 $user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1;
522 if ($post_data['topic_first_post_id'] == $post_id)
524 if ($post_data['forum_id'])
528 $topic_approve_sql[] = $post_data['topic_id'];
530 $approve_log[] = array(
532 'post_subject' => $post_data['post_subject'],
533 'forum_id' => $post_data['forum_id'],
534 'topic_id' => $post_data['topic_id'],
539 $approve_log[] = array(
541 'post_subject' => $post_data['post_subject'],
542 'forum_id' => $post_data['forum_id'],
543 'topic_id' => $post_data['topic_id'],
547 if ($post_data['forum_id'])
551 // Increment by topic_replies if we approve a topic...
552 // This works because we do not adjust the topic_replies when re-approving a topic after an edit.
553 if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies'])
555 $total_posts += $post_data['topic_replies'];
559 $post_approve_sql[] = $post_id;
562 $post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
563 for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
565 unset($post_info[$post_approved_list[$i]]);
568 if (sizeof($topic_approve_sql))
570 $sql = 'UPDATE ' . TOPICS_TABLE . '
571 SET topic_approved = 1
572 WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
573 $db->sql_query($sql);
576 if (sizeof($post_approve_sql))
578 $sql = 'UPDATE ' . POSTS_TABLE . '
579 SET post_approved = 1
580 WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
581 $db->sql_query($sql);
584 unset($topic_approve_sql, $post_approve_sql);
586 foreach ($approve_log as $log_data)
588 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']);
591 if (sizeof($user_posts_sql))
593 // Try to minimize the query count by merging users with the same post count additions
594 $user_posts_update = array();
596 foreach ($user_posts_sql as $user_id => $user_posts)
598 $user_posts_update[$user_posts][] = $user_id;
601 foreach ($user_posts_update as $user_posts => $user_id_ary)
603 $sql = 'UPDATE ' . USERS_TABLE . '
604 SET user_posts = user_posts + ' . $user_posts . '
605 WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
606 $db->sql_query($sql);
612 set_config_count('num_topics', $total_topics, true);
617 set_config_count('num_posts', $total_posts, true);
620 sync('topic', 'topic_id', array_keys($topic_id_list), true);
621 sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
622 unset($topic_id_list, $forum_id_list);
624 $messenger = new messenger();
629 foreach ($post_info as $post_id => $post_data)
631 if ($post_data['poster_id'] == ANONYMOUS)
636 $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved';
638 $messenger->template($email_template, $post_data['user_lang']);
640 $messenger->to($post_data['user_email'], $post_data['username']);
641 $messenger->im($post_data['user_jabber'], $post_data['username']);
643 $messenger->assign_vars(array(
644 'USERNAME' => htmlspecialchars_decode($post_data['username']),
645 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
646 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])),
648 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0",
649 'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id")
652 $messenger->send($post_data['user_notify_type']);
656 $messenger->save_queue();
658 // Send out normal user notifications
659 $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
661 foreach ($post_info as $post_id => $post_data)
663 if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
665 // Forum Notifications
666 user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
670 // Topic Notifications
671 user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
675 if (sizeof($post_id_list) == 1)
677 $post_data = $post_info[$post_id_list[0]];
678 $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'];
684 $success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS';
688 $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
693 $show_notify = false;
695 if ($config['email_enable'] || $config['jab_enable'])
697 foreach ($post_info as $post_data)
699 if ($post_data['poster_id'] == ANONYMOUS)
711 $template->assign_vars(array(
712 'S_NOTIFY_POSTER' => $show_notify,
716 confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
719 $redirect = request_var('redirect', "index.$phpEx");
720 $redirect = reapply_sid($redirect);
728 meta_refresh(3, $redirect);
730 // If approving one post, also give links back to post...
732 if (sizeof($post_id_list) == 1 && !empty($post_url))
734 $add_message = '<br /><br />' . sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>');
737 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>') . $add_message);
742 * Disapprove Post/Topic
744 function disapprove_post($post_id_list, $id, $mode)
746 global $db, $template, $user, $config;
747 global $phpEx, $phpbb_root_path;
749 if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
751 trigger_error('NOT_AUTHORISED');
754 $redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode");
755 $reason = utf8_normalize_nfc(request_var('reason', '', true));
756 $reason_id = request_var('reason_id', 0);
757 $success_msg = $additional_msg = '';
759 $s_hidden_fields = build_hidden_fields(array(
762 'post_id_list' => $post_id_list,
763 'action' => 'disapprove',
764 'redirect' => $redirect)
767 $notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
768 $disapprove_reason = '';
772 $sql = 'SELECT reason_title, reason_description
773 FROM ' . REPORTS_REASONS_TABLE . "
774 WHERE reason_id = $reason_id";
775 $result = $db->sql_query($sql);
776 $row = $db->sql_fetchrow($result);
777 $db->sql_freeresult($result);
779 if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
781 $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
782 unset($_REQUEST['confirm_key']);
783 unset($_POST['confirm_key']);
784 unset($_POST['confirm']);
788 // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
789 $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']) : '';
790 $disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
792 if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
794 $disapprove_reason_lang = strtoupper($row['reason_title']);
797 $email_disapprove_reason = $disapprove_reason;
801 $post_info = get_post_data($post_id_list, 'm_approve');
803 if (confirm_box(true))
805 $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
806 $topic_replies_real = $post_disapprove_list = array();
808 // Build a list of posts to be unapproved and get the related topics real replies count
809 foreach ($post_info as $post_id => $post_data)
811 $post_disapprove_list[$post_id] = $post_data['topic_id'];
812 if (!isset($topic_replies_real[$post_data['topic_id']]))
814 $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real'];
818 // Now we build the log array
819 foreach ($post_disapprove_list as $post_id => $topic_id)
821 // If the count of disapproved posts for the topic is greater
822 // than topic's real replies count, the whole topic is disapproved/deleted
823 if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id])
825 // Don't write the log more than once for every topic
826 if (!isset($disapprove_log_topics[$topic_id]))
828 // Build disapproved topics log
829 $disapprove_log_topics[$topic_id] = array(
831 'post_subject' => $post_info[$post_id]['topic_title'],
832 'forum_id' => $post_info[$post_id]['forum_id'],
833 'topic_id' => 0, // useless to log a topic id, as it will be deleted
839 // Build disapproved posts log
840 $disapprove_log_posts[] = array(
842 'post_subject' => $post_info[$post_id]['post_subject'],
843 'forum_id' => $post_info[$post_id]['forum_id'],
844 'topic_id' => $post_info[$post_id]['topic_id'],
850 // Get disapproved posts/topics counts separately
851 $num_disapproved_topics = sizeof($disapprove_log_topics);
852 $num_disapproved_posts = sizeof($disapprove_log_posts);
854 // Build the whole log
855 $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
857 // Unset unneeded arrays
858 unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
860 // Let's do the job - delete disapproved posts
861 if (sizeof($post_disapprove_list))
863 if (!function_exists('delete_posts'))
865 include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
868 // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
869 // Note: function delete_posts triggers related forums/topics sync,
870 // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
871 delete_posts('post_id', array_keys($post_disapprove_list));
873 foreach ($disapprove_log as $log_data)
875 add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason);
879 $messenger = new messenger();
884 $lang_reasons = array();
886 foreach ($post_info as $post_id => $post_data)
888 if ($post_data['poster_id'] == ANONYMOUS)
893 if (isset($disapprove_reason_lang))
895 // Okay we need to get the reason from the posters language
896 if (!isset($lang_reasons[$post_data['user_lang']]))
898 // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
899 $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
901 // Only load up the language pack if the language is different to the current one
902 if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
904 // Load up the language pack
906 @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
908 // If we find the reason in this language pack use it
909 if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
911 $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
914 unset($lang); // Free memory
918 $email_disapprove_reason = $lang_reasons[$post_data['user_lang']];
919 $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
922 $email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved';
924 $messenger->template($email_template, $post_data['user_lang']);
926 $messenger->to($post_data['user_email'], $post_data['username']);
927 $messenger->im($post_data['user_jabber'], $post_data['username']);
929 $messenger->assign_vars(array(
930 'USERNAME' => htmlspecialchars_decode($post_data['username']),
931 'REASON' => htmlspecialchars_decode($email_disapprove_reason),
932 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
933 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])))
936 $messenger->send($post_data['user_notify_type']);
939 unset($lang_reasons);
941 unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang);
943 $messenger->save_queue();
945 if ($num_disapproved_topics)
947 $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
951 $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
956 include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
958 display_reasons($reason_id);
960 $show_notify = false;
962 foreach ($post_info as $post_data)
964 if ($post_data['poster_id'] == ANONYMOUS)
975 $template->assign_vars(array(
976 'S_NOTIFY_POSTER' => $show_notify,
977 'S_APPROVE' => false,
979 'ADDITIONAL_MSG' => $additional_msg)
982 confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
985 $redirect = request_var('redirect', "index.$phpEx");
986 $redirect = reapply_sid($redirect);
994 meta_refresh(3, $redirect);
995 trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));