diff options
Diffstat (limited to 'phpBB/includes/mcp/mcp_queue.php')
-rw-r--r-- | phpBB/includes/mcp/mcp_queue.php | 425 |
1 files changed, 326 insertions, 99 deletions
diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index a46c4bd499..bf93593c74 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -1,9 +1,13 @@ <?php /** * -* @package mcp -* @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -18,7 +22,6 @@ if (!defined('IN_PHPBB')) /** * mcp_queue * Handling the moderation queue -* @package mcp */ class mcp_queue { @@ -32,13 +35,14 @@ class mcp_queue public function main($id, $mode) { - global $auth, $db, $user, $template, $cache, $request; + global $auth, $db, $user, $template, $request; global $config, $phpbb_root_path, $phpEx, $action, $phpbb_container; + global $phpbb_dispatcher; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); - $forum_id = request_var('f', 0); - $start = request_var('start', 0); + $forum_id = $request->variable('f', 0); + $start = $request->variable('start', 0); $this->page_title = 'MCP_QUEUE'; @@ -68,6 +72,7 @@ class mcp_queue case 'delete': $post_id_list = $request->variable('post_id_list', array(0)); $topic_id_list = $request->variable('topic_id_list', array(0)); + $delete_reason = $request->variable('delete_reason', '', true); if (!empty($post_id_list)) { @@ -76,7 +81,7 @@ class mcp_queue global $phpbb_root_path, $phpEx; include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); } - mcp_delete_post($post_id_list, false, '', $action); + mcp_delete_post($post_id_list, false, $delete_reason, $action); } else if (!empty($topic_id_list)) { @@ -85,7 +90,7 @@ class mcp_queue global $phpbb_root_path, $phpEx; include($phpbb_root_path . 'includes/mcp/mcp_main.' . $phpEx); } - mcp_delete_topic($topic_id_list, false, '', $action); + mcp_delete_topic($topic_id_list, false, $delete_reason, $action); } else { @@ -115,10 +120,10 @@ class mcp_queue if (!empty($topic_id_list)) { - $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : ITEM_UNAPPROVED; + $post_visibility = ($mode == 'deleted_topics') ? ITEM_DELETED : array(ITEM_UNAPPROVED, ITEM_REAPPROVE); $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' - WHERE post_visibility = ' . $post_visibility . ' + WHERE ' . $db->sql_in_set('post_visibility', $post_visibility) . ' AND ' . $db->sql_in_set('topic_id', $topic_id_list); $result = $db->sql_query($sql); @@ -149,19 +154,20 @@ class mcp_queue $user->add_lang(array('posting', 'viewtopic')); - $post_id = request_var('p', 0); - $topic_id = request_var('t', 0); + $post_id = $request->variable('p', 0); + $topic_id = $request->variable('t', 0); + /* @var $phpbb_notifications \phpbb\notification\manager */ $phpbb_notifications = $phpbb_container->get('notification_manager'); if ($topic_id) { - $topic_info = get_topic_data(array($topic_id), 'm_approve'); + $topic_info = phpbb_get_topic_data(array($topic_id), 'm_approve'); if (isset($topic_info[$topic_id]['topic_first_post_id'])) { $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; - $phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications('topic_in_queue', $topic_id, $user->data['user_id']); } else { @@ -169,9 +175,9 @@ class mcp_queue } } - $phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']); + $phpbb_notifications->mark_notifications('post_in_queue', $post_id, $user->data['user_id']); - $post_info = get_post_data(array($post_id), 'm_approve', true); + $post_info = phpbb_get_post_data(array($post_id), 'm_approve', true); if (!sizeof($post_info)) { @@ -189,7 +195,7 @@ class mcp_queue )); } - $extensions = $attachments = $topic_tracking_info = array(); + $attachments = $topic_tracking_info = array(); // Get topic tracking info if ($config['load_db_lastread']) @@ -211,8 +217,6 @@ class mcp_queue if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) { - $extensions = $cache->obtain_attach_extensions($post_info['forum_id']); - $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . ' WHERE post_msg_id = ' . $post_id . ' @@ -279,9 +283,10 @@ class mcp_queue $template->assign_vars(array( 'S_MCP_QUEUE' => true, 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"), + 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], - 'S_POST_UNAPPROVED' => ($post_info['post_visibility'] == ITEM_UNAPPROVED), + 'S_POST_UNAPPROVED' => $post_info['post_visibility'] == ITEM_UNAPPROVED || $post_info['post_visibility'] == ITEM_REAPPROVE, 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, 'S_POST_DELETED' => ($post_info['post_visibility'] == ITEM_DELETED), @@ -298,7 +303,6 @@ class mcp_queue 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), - '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>'), 'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . $post_url . '">', '</a>'), 'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '<a href="' . $topic_url . '">', '</a>'), @@ -315,7 +319,7 @@ class mcp_queue 'POST_SUBJECT' => $post_info['post_subject'], 'POST_DATE' => $user->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], - 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '', + 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && $request->variable('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '', 'POST_ID' => $post_info['post_id'], 'S_FIRST_POST' => ($post_info['topic_first_post_id'] == $post_id), @@ -331,17 +335,19 @@ class mcp_queue $m_perm = 'm_approve'; $is_topics = ($mode == 'unapproved_topics' || $mode == 'deleted_topics') ? true : false; $is_restore = ($mode == 'deleted_posts' || $mode == 'deleted_topics') ? true : false; - $visibility_const = (!$is_restore) ? ITEM_UNAPPROVED : ITEM_DELETED; + $visibility_const = (!$is_restore) ? array(ITEM_UNAPPROVED, ITEM_REAPPROVE) : ITEM_DELETED; $user->add_lang(array('viewtopic', 'viewforum')); $topic_id = $request->variable('t', 0); $forum_info = array(); + + /* @var $pagination \phpbb\pagination */ $pagination = $phpbb_container->get('pagination'); if ($topic_id) { - $topic_info = get_topic_data(array($topic_id)); + $topic_info = phpbb_get_topic_data(array($topic_id)); if (!sizeof($topic_info)) { @@ -387,29 +393,27 @@ class mcp_queue } else { - $forum_info = get_forum_data(array($forum_id), $m_perm); + $forum_info = phpbb_get_forum_data(array($forum_id), $m_perm); if (!sizeof($forum_info)) { trigger_error('NOT_MODERATOR'); } - $forum_info = $forum_info[$forum_id]; $forum_list = $forum_id; } $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>'; foreach ($forum_list_approve as $row) { - $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat(' ', $row['padding']) . $row['forum_name'] . '</option>'; + $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>'; } $sort_days = $total = 0; $sort_key = $sort_dir = ''; $sort_by_sql = $sort_order_sql = array(); - mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); + phpbb_mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id); - $forum_topics = ($total == -1) ? $forum_info['forum_topics_approved'] : $total; $limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : ''; $forum_names = array(); @@ -419,7 +423,7 @@ class mcp_queue $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . ' WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . ' - AND p.post_visibility = ' . $visibility_const . ' + AND ' . $db->sql_in_set('p.post_visibility', $visibility_const) . ' ' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . ' ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . " AND t.topic_id = p.topic_id @@ -427,6 +431,29 @@ class mcp_queue OR t.topic_delete_user = 0) $limit_time_sql ORDER BY $sort_order_sql"; + + /** + * Alter sql query to get posts in queue to be accepted + * + * @event core.mcp_queue_get_posts_query_before + * @var string sql Associative array with the query to be executed + * @var array forum_list List of forums that contain the posts + * @var int visibility_const Integer with one of the possible ITEM_* constant values + * @var int topic_id If topic_id not equal to 0, the topic id to filter the posts to display + * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) + * @var string sort_order_sql String with the ORDER BY SQL code used in this query + * @since 3.1.0-RC3 + */ + $vars = array( + 'sql', + 'forum_list', + 'visibility_const', + 'topic_id', + 'limit_time_sql', + 'sort_order_sql', + ); + extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_query_before', compact($vars))); + $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $i = 0; @@ -472,10 +499,33 @@ class mcp_queue $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 FROM ' . TOPICS_TABLE . ' t WHERE ' . $db->sql_in_set('forum_id', $forum_list) . ' - AND topic_visibility = ' . $visibility_const . " + AND ' . $db->sql_in_set('topic_visibility', $visibility_const) . " AND topic_delete_user <> 0 $limit_time_sql ORDER BY $sort_order_sql"; + + /** + * Alter sql query to get information on all topics in the list of forums provided. + * + * @event core.mcp_queue_get_posts_for_topics_query_before + * @var string sql String with the query to be executed + * @var array forum_list List of forums that contain the posts + * @var int visibility_const Integer with one of the possible ITEM_* constant values + * @var int topic_id topic_id in the page request + * @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string) + * @var string sort_order_sql String with the ORDER BY SQL code used in this query + * @since 3.1.0-RC3 + */ + $vars = array( + 'sql', + 'forum_list', + 'visibility_const', + 'topic_id', + 'limit_time_sql', + 'sort_order_sql', + ); + extract($phpbb_dispatcher->trigger_event('core.mcp_queue_get_posts_for_topics_query_before', compact($vars))); + $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start); $rowset = array(); @@ -567,18 +617,19 @@ class mcp_queue */ static public function approve_posts($action, $post_id_list, $id, $mode) { - global $db, $template, $user, $config, $request, $phpbb_container; - global $phpEx, $phpbb_root_path; + global $template, $user, $request, $phpbb_container, $phpbb_dispatcher; + global $phpEx, $phpbb_root_path, $phpbb_log; - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { trigger_error('NOT_AUTHORISED'); } $redirect = $request->variable('redirect', build_url(array('quickmod'))); $redirect = reapply_sid($redirect); - $success_msg = $post_url = ''; + $post_url = ''; $approve_log = array(); + $num_topics = 0; $s_hidden_fields = build_hidden_fields(array( 'i' => $id, @@ -588,7 +639,7 @@ class mcp_queue 'redirect' => $redirect, )); - $post_info = get_post_data($post_id_list, 'm_approve'); + $post_info = phpbb_get_post_data($post_id_list, 'm_approve'); if (confirm_box(true)) { @@ -625,29 +676,32 @@ class mcp_queue $approve_log[] = array( 'forum_id' => $post_data['forum_id'], 'topic_id' => $post_data['topic_id'], + 'post_id' => $post_id, 'post_subject' => $post_data['post_subject'], ); } + /* @var $phpbb_content_visibility \phpbb\content_visibility */ $phpbb_content_visibility = $phpbb_container->get('content.visibility'); foreach ($topic_info as $topic_id => $topic_data) { $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'])); } - if (sizeof($post_info) >= 1) - { - $success_msg = (sizeof($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS'; - } - foreach ($approve_log as $log_data) { - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_POST_' . strtoupper($action) . 'D', $log_data['post_subject']); + $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_POST_' . strtoupper($action) . 'D', false, array( + 'forum_id' => $log_data['forum_id'], + 'topic_id' => $log_data['topic_id'], + 'post_id' => $log_data['post_id'], + $log_data['post_subject'] + )); } // Only send out the mails, when the posts are being approved if ($action == 'approve') { + /* @var $phpbb_notifications \phpbb\notification\manager */ $phpbb_notifications = $phpbb_container->get('notification_manager'); // Handle notifications @@ -656,20 +710,38 @@ class mcp_queue // A single topic approval may also happen here, so handle deleting the respective notification. if (!$post_data['topic_posts_approved']) { - $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']); + + if ($post_data['post_visibility'] == ITEM_UNAPPROVED) + { + $phpbb_notifications->add_notifications(array('notification.type.topic'), $post_data); + } + if ($post_data['post_visibility'] != ITEM_APPROVED) + { + $num_topics++; + } + } + else + { + // Only add notifications, if we are not reapproving post + // When the topic was already approved, but was edited and + // now needs re-approval, we don't want to notify the users + // again. + if ($post_data['post_visibility'] == ITEM_UNAPPROVED) + { + $phpbb_notifications->add_notifications(array( + 'notification.type.bookmark', + 'notification.type.post', + ), $post_data); + } } - $phpbb_notifications->delete_notifications('post_in_queue', $post_id); - - $phpbb_notifications->add_notifications(array( - 'quote', - 'bookmark', - 'post', - ), $post_data); - - $phpbb_notifications->mark_notifications_read(array( - 'quote', - 'bookmark', - 'post', + $phpbb_notifications->add_notifications(array('notification.type.quote'), $post_data); + $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id); + + $phpbb_notifications->mark_notifications(array( + 'notification.type.quote', + 'notification.type.bookmark', + 'notification.type.post', ), $post_data['post_id'], $user->data['user_id']); // Notify Poster? @@ -680,11 +752,51 @@ class mcp_queue continue; } - $phpbb_notifications->add_notifications('approve_post', $post_data); + if (!$post_data['topic_posts_approved']) + { + $phpbb_notifications->add_notifications('notification.type.approve_topic', $post_data); + } + else + { + $phpbb_notifications->add_notifications('notification.type.approve_post', $post_data); + } } } } + if ($num_topics >= 1) + { + $success_msg = ($num_topics == 1) ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; + } + else + { + $success_msg = (sizeof($post_info) == 1) ? 'POST_' . strtoupper($action) . 'D_SUCCESS' : 'POSTS_' . strtoupper($action) . 'D_SUCCESS'; + } + + /** + * Perform additional actions during post(s) approval + * + * @event core.approve_posts_after + * @var string action Variable containing the action we perform on the posts ('approve' or 'restore') + * @var array post_info Array containing info for all posts being approved + * @var array topic_info Array containing info for all parent topics of the posts + * @var int num_topics Variable containing number of topics + * @var bool notify_poster Variable telling if the post should be notified or not + * @var string success_msg Variable containing the language key for the success message + * @var string redirect Variable containing the redirect url + * @since 3.1.4-RC1 + */ + $vars = array( + 'action', + 'post_info', + 'topic_info', + 'num_topics', + 'notify_poster', + 'success_msg', + 'redirect', + ); + extract($phpbb_dispatcher->trigger_event('core.approve_posts_after', compact($vars))); + meta_refresh(3, $redirect); $message = $user->lang[$success_msg]; @@ -715,14 +827,14 @@ class mcp_queue { foreach ($post_info as $post_data) { - if ($post_data['poster_id'] == ANONYMOUS) + if (!$post_data['topic_posts_approved']) { - continue; + $num_topics++; } - else + + if (!$show_notify && $post_data['poster_id'] != ANONYMOUS) { $show_notify = true; - break; } } } @@ -732,7 +844,18 @@ class mcp_queue 'S_' . strtoupper($action) => true, )); - confirm_box(false, strtoupper($action) . '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); + // Create the confirm box message + $action_msg = strtoupper($action); + $num_posts = sizeof($post_id_list) - $num_topics; + if ($num_topics > 0 && $num_posts <= 0) + { + $action_msg .= '_TOPIC' . (($num_topics == 1) ? '' : 'S'); + } + else + { + $action_msg .= '_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'); + } + confirm_box(false, $action_msg, $s_hidden_fields, 'mcp_approve.html'); } redirect($redirect); @@ -749,10 +872,10 @@ class mcp_queue */ static public function approve_topics($action, $topic_id_list, $id, $mode) { - global $db, $template, $user, $config; - global $phpEx, $phpbb_root_path, $request, $phpbb_container; + global $db, $template, $user, $phpbb_log; + global $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_dispatcher; - if (!check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) + if (!phpbb_check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) { trigger_error('NOT_AUTHORISED'); } @@ -770,12 +893,13 @@ class mcp_queue 'redirect' => $redirect, )); - $topic_info = get_topic_data($topic_id_list, 'm_approve'); + $topic_info = phpbb_get_topic_data($topic_id_list, 'm_approve'); if (confirm_box(true)) { $notify_poster = ($action == 'approve' && isset($_REQUEST['notify_poster'])) ? true : false; + /* @var $phpbb_content_visibility \phpbb\content_visibility */ $phpbb_content_visibility = $phpbb_container->get('content.visibility'); $first_post_ids = array(); @@ -800,7 +924,11 @@ class mcp_queue foreach ($approve_log as $log_data) { - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_TOPIC_' . strtoupper($action) . 'D', $log_data['topic_title']); + $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_TOPIC_' . strtoupper($action) . 'D', false, array( + 'forum_id' => $log_data['forum_id'], + 'topic_id' => $log_data['topic_id'], + $log_data['topic_title'] + )); } // Only send out the mails, when the posts are being approved @@ -819,6 +947,7 @@ class mcp_queue $db->sql_freeresult($result); // Handle notifications + /* @var $phpbb_notifications \phpbb\notification\manager */ $phpbb_notifications = $phpbb_container->get('notification_manager'); foreach ($topic_info as $topic_id => $topic_data) @@ -828,25 +957,55 @@ class mcp_queue 'post_subject' => $topic_data['topic_title'], 'post_time' => $topic_data['topic_time'], 'poster_id' => $topic_data['topic_poster'], - 'username' => $topic_data['topic_first_poster_name'], + 'post_username' => $topic_data['topic_first_poster_name'], )); - $phpbb_notifications->delete_notifications('topic_in_queue', $topic_id); - $phpbb_notifications->add_notifications(array( - 'quote', - 'topic', - ), $topic_data); + $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $topic_id); - $phpbb_notifications->mark_notifications_read('quote', $topic_data['post_id'], $user->data['user_id']); - $phpbb_notifications->mark_notifications_read('topic', $topic_id, $user->data['user_id']); + // Only add notifications, if we are not reapproving post + // When the topic was already approved, but was edited and + // now needs re-approval, we don't want to notify the users + // again. + if ($topic_data['topic_visibility'] == ITEM_UNAPPROVED) + { + $phpbb_notifications->add_notifications(array( + 'notification.type.quote', + 'notification.type.topic', + ), $topic_data); + } + + $phpbb_notifications->mark_notifications('quote', $topic_data['post_id'], $user->data['user_id']); + $phpbb_notifications->mark_notifications('topic', $topic_id, $user->data['user_id']); if ($notify_poster) { - $phpbb_notifications->add_notifications('approve_topic', $topic_data); + $phpbb_notifications->add_notifications('notification.type.approve_topic', $topic_data); } } } + /** + * Perform additional actions during topics(s) approval + * + * @event core.approve_topics_after + * @var string action Variable containing the action we perform on the posts ('approve' or 'restore') + * @var mixed topic_info Array containing info for all topics being approved + * @var array first_post_ids Array containing ids of all first posts + * @var bool notify_poster Variable telling if the poster should be notified or not + * @var string success_msg Variable containing the language key for the success message + * @var string redirect Variable containing the redirect url + * @since 3.1.4-RC1 + */ + $vars = array( + 'action', + 'topic_info', + 'first_post_ids', + 'notify_poster', + 'success_msg', + 'redirect', + ); + extract($phpbb_dispatcher->trigger_event('core.approve_topics_after', compact($vars))); + meta_refresh(3, $redirect); $message = $user->lang[$success_msg]; @@ -910,10 +1069,10 @@ class mcp_queue */ static public function disapprove_posts($post_id_list, $id, $mode) { - global $db, $template, $user, $config, $phpbb_container; - global $phpEx, $phpbb_root_path, $request; + global $db, $template, $user, $phpbb_container, $phpbb_dispatcher; + global $phpEx, $phpbb_root_path, $request, $phpbb_log; - if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) + if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { trigger_error('NOT_AUTHORISED'); } @@ -922,7 +1081,7 @@ class mcp_queue $redirect = reapply_sid($redirect); $reason = $request->variable('reason', '', true); $reason_id = $request->variable('reason_id', 0); - $success_msg = $additional_msg = ''; + $additional_msg = ''; $s_hidden_fields = build_hidden_fields(array( 'i' => $id, @@ -965,7 +1124,7 @@ class mcp_queue } } - $post_info = get_post_data($post_id_list, 'm_approve'); + $post_info = phpbb_get_post_data($post_id_list, 'm_approve'); $is_disapproving = false; foreach ($post_info as $post_id => $post_data) @@ -980,12 +1139,17 @@ class mcp_queue if (confirm_box(true)) { - $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array(); + $disapprove_log_topics = $disapprove_log_posts = array(); $topic_posts_unapproved = $post_disapprove_list = $topic_information = array(); // Build a list of posts to be disapproved and get the related topics real replies count foreach ($post_info as $post_id => $post_data) { + if ($mode === 'unapproved_topics' && $post_data['post_visibility'] == ITEM_APPROVED) + { + continue; + } + $post_disapprove_list[$post_id] = $post_data['topic_id']; if (!isset($topic_posts_unapproved[$post_data['topic_id']])) { @@ -995,6 +1159,12 @@ class mcp_queue $topic_posts_unapproved[$post_data['topic_id']]++; } + // Do not try to disapprove if no posts are selected + if (empty($post_disapprove_list)) + { + trigger_error('NO_POST_SELECTED'); + } + // Now we build the log array foreach ($post_disapprove_list as $post_id => $topic_id) { @@ -1060,16 +1230,28 @@ class mcp_queue if ($is_disapproving) { $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED'; - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $disapprove_reason); + $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array( + 'forum_id' => $log_data['forum_id'], + 'topic_id' => $log_data['topic_id'], + $log_data['post_subject'], + $disapprove_reason, + $log_data['post_username'] + )); } else { $l_log_message = ($log_data['type'] == 'topic') ? 'LOG_DELETE_TOPIC' : 'LOG_DELETE_POST'; - add_log('mod', $log_data['forum_id'], $log_data['topic_id'], $l_log_message, $log_data['post_subject'], $log_data['post_username']); + $phpbb_log->add('mod', $user->data['user_id'], $user->ip, $l_log_message, false, array( + 'forum_id' => $log_data['forum_id'], + 'topic_id' => $log_data['topic_id'], + $log_data['post_subject'], + $log_data['post_username'] + )); } } } + /* @var $phpbb_notifications \phpbb\notification\manager */ $phpbb_notifications = $phpbb_container->get('notification_manager'); $lang_reasons = array(); @@ -1080,12 +1262,12 @@ class mcp_queue $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]; - $phpbb_notifications->delete_notifications('post_in_queue', $post_id); + $phpbb_notifications->delete_notifications('notification.type.post_in_queue', $post_id); // Do we disapprove the whole topic? Remove potential notifications if ($disapprove_all_posts_in_topic) { - $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + $phpbb_notifications->delete_notifications('notification.type.topic_in_queue', $post_data['topic_id']); } // Notify Poster? @@ -1096,7 +1278,7 @@ class mcp_queue continue; } - $post_data['disapprove_reason'] = ''; + $post_data['disapprove_reason'] = $disapprove_reason; if (isset($disapprove_reason_lang)) { // Okay we need to get the reason from the posters language @@ -1126,25 +1308,21 @@ class mcp_queue $post_data['disapprove_reason'] .= ($reason) ? "\n\n" . $reason : ''; } - if ($disapprove_all_posts_in_topic && $topic_information[$topic_id]['topic_posts_unapproved'] == 1) { // If there is only 1 post when disapproving the topic, // we send the user a "disapprove topic" notification... - $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + $phpbb_notifications->add_notifications('notification.type.disapprove_topic', $post_data); } else { // ... otherwise there are multiple unapproved posts and // all of them are disapproved as posts. - $phpbb_notifications->add_notifications('disapprove_post', $post_data); + $phpbb_notifications->add_notifications('notification.type.disapprove_post', $post_data); } } } - unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang); - - if ($num_disapproved_topics) { $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC' : 'TOPICS'; @@ -1163,6 +1341,60 @@ class mcp_queue $success_msg .= '_DELETED_SUCCESS'; } + // If we came from viewtopic, we try to go back to it. + if (strpos($redirect, $phpbb_root_path . 'viewtopic.' . $phpEx) === 0) + { + if ($num_disapproved_topics == 0) + { + // So we need to remove the post id part from the Url + $redirect = str_replace("&p={$post_id_list[0]}#p{$post_id_list[0]}", '', $redirect); + } + else + { + // However this is only possible if the topic still exists, + // Otherwise we go back to the viewforum page + $redirect = append_sid($phpbb_root_path . 'viewforum.' . $phpEx, 'f=' . $request->variable('f', 0)); + } + } + + /** + * Perform additional actions during post(s) disapproval + * + * @event core.disapprove_posts_after + * @var array post_info Array containing info for all posts being disapproved + * @var array topic_information Array containing information for the topics + * @var array topic_posts_unapproved Array containing list of topic ids and the count of disapproved posts in them + * @var array post_disapprove_list Array containing list of posts and their topic id + * @var int num_disapproved_topics Variable containing the number of disapproved topics + * @var int num_disapproved_posts Variable containing the number of disapproved posts + * @var array lang_reasons Array containing the language keys for reasons + * @var string disapprove_reason Variable containing the language key for the success message + * @var string disapprove_reason_lang Variable containing the language key for the success message + * @var bool is_disapproving Variable telling if anything is going to be disapproved + * @var bool notify_poster Variable telling if the post should be notified or not + * @var string success_msg Variable containing the language key for the success message + * @var string redirect Variable containing the redirect url + * @since 3.1.4-RC1 + */ + $vars = array( + 'post_info', + 'topic_information', + 'topic_posts_unapproved', + 'post_disapprove_list', + 'num_disapproved_topics', + 'num_disapproved_posts', + 'lang_reasons', + 'disapprove_reason', + 'disapprove_reason_lang', + 'is_disapproving', + 'notify_poster', + 'success_msg', + 'redirect', + ); + extract($phpbb_dispatcher->trigger_event('core.disapprove_posts_after', compact($vars))); + + unset($lang_reasons, $post_info, $disapprove_reason, $disapprove_reason_lang); + meta_refresh(3, $redirect); $message = $user->lang[$success_msg]; @@ -1181,11 +1413,6 @@ class mcp_queue } else { - if (!function_exists('display_reasons')) - { - include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - } - $show_notify = false; foreach ($post_info as $post_data) @@ -1205,7 +1432,7 @@ class mcp_queue $confirm_template = 'mcp_approve.html'; if ($is_disapproving) { - display_reasons($reason_id); + $phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id); } else { |