示例#1
0
文件: mcp_queue.php 项目: html/PI
/**
* Disapprove Post/Topic
*/
function disapprove_post($post_id_list, $id, $mode)
{
    global $db, $template, $user, $config;
    global $phpEx, $phpbb_root_path;
    if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) {
        trigger_error('NOT_AUTHORISED');
    }
    $redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode={$mode}");
    $reason = utf8_normalize_nfc(request_var('reason', '', true));
    $reason_id = request_var('reason_id', 0);
    $success_msg = $additional_msg = '';
    $s_hidden_fields = build_hidden_fields(array('i' => $id, 'mode' => $mode, 'post_id_list' => $post_id_list, 'action' => 'disapprove', 'redirect' => $redirect));
    $notify_poster = isset($_REQUEST['notify_poster']) ? true : false;
    $disapprove_reason = '';
    if ($reason_id) {
        $sql = 'SELECT reason_title, reason_description
			FROM ' . REPORTS_REASONS_TABLE . "\n\t\t\tWHERE reason_id = {$reason_id}";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$row || !$reason && strtolower($row['reason_title']) == 'other') {
            $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
            unset($_POST['confirm']);
        } else {
            // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
            $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'] : '';
            $disapprove_reason .= $reason ? "\n\n" . $reason : '';
            if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) {
                $disapprove_reason_lang = strtoupper($row['reason_title']);
            }
            $email_disapprove_reason = $disapprove_reason;
        }
    }
    $post_info = get_post_data($post_id_list, 'm_approve');
    if (confirm_box(true)) {
        // If Topic -> forum_topics_real -= 1
        // If Post -> topic_replies_real -= 1
        $num_disapproved = 0;
        $forum_topics_real = $topic_id_list = $forum_id_list = $topic_replies_real_sql = $post_disapprove_sql = $disapprove_log = array();
        foreach ($post_info as $post_id => $post_data) {
            $topic_id_list[$post_data['topic_id']] = 1;
            if ($post_data['forum_id']) {
                $forum_id_list[$post_data['forum_id']] = 1;
            }
            // Topic or Post. ;)
            /**
             * @todo this probably is a different method than the one used by delete_posts, does this cause counter inconsistency?
             */
            if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id) {
                if ($post_data['forum_id']) {
                    if (!isset($forum_topics_real[$post_data['forum_id']])) {
                        $forum_topics_real[$post_data['forum_id']] = 0;
                    }
                    $forum_topics_real[$post_data['forum_id']]++;
                    $num_disapproved++;
                }
                $disapprove_log[] = array('type' => 'topic', 'post_subject' => $post_data['post_subject'], 'forum_id' => $post_data['forum_id'], 'topic_id' => 0);
            } else {
                if (!isset($topic_replies_real_sql[$post_data['topic_id']])) {
                    $topic_replies_real_sql[$post_data['topic_id']] = 0;
                }
                $topic_replies_real_sql[$post_data['topic_id']]++;
                $disapprove_log[] = array('type' => 'post', 'post_subject' => $post_data['post_subject'], 'forum_id' => $post_data['forum_id'], 'topic_id' => $post_data['topic_id']);
            }
            $post_disapprove_sql[] = $post_id;
        }
        unset($post_data);
        if (sizeof($forum_topics_real)) {
            foreach ($forum_topics_real as $forum_id => $topics_real) {
                $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\t\t\t\tSET forum_topics_real = forum_topics_real - {$topics_real}\n\t\t\t\t\tWHERE forum_id = {$forum_id}";
                $db->sql_query($sql);
            }
        }
        if (sizeof($topic_replies_real_sql)) {
            foreach ($topic_replies_real_sql as $topic_id => $num_replies) {
                $sql = 'UPDATE ' . TOPICS_TABLE . "\n\t\t\t\t\tSET topic_replies_real = topic_replies_real - {$num_replies}\n\t\t\t\t\tWHERE topic_id = {$topic_id}";
                $db->sql_query($sql);
            }
        }
        if (sizeof($post_disapprove_sql)) {
            if (!function_exists('delete_posts')) {
                include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
            }
            // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
            delete_posts('post_id', $post_disapprove_sql);
            foreach ($disapprove_log as $log_data) {
                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);
            }
        }
        unset($post_disapprove_sql, $topic_replies_real_sql);
        update_post_information('topic', array_keys($topic_id_list));
        if (sizeof($forum_id_list)) {
            update_post_information('forum', array_keys($forum_id_list));
        }
        unset($topic_id_list, $forum_id_list);
        $messenger = new messenger();
        // Notify Poster?
        if ($notify_poster) {
            $lang_reasons = array();
            foreach ($post_info as $post_id => $post_data) {
                if ($post_data['poster_id'] == ANONYMOUS) {
                    continue;
                }
                if (isset($disapprove_reason_lang)) {
                    // Okay we need to get the reason from the posters language
                    if (!isset($lang_reasons[$post_data['user_lang']])) {
                        // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
                        $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
                        // Only load up the language pack if the language is different to the current one
                        if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) {
                            // Load up the language pack
                            $lang = array();
                            @(include $phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx);
                            // If we find the reason in this language pack use it
                            if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) {
                                $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
                            }
                            unset($lang);
                            // Free memory
                        }
                    }
                    $email_disapprove_reason = $lang_reasons[$post_data['user_lang']];
                    $email_disapprove_reason .= $reason ? "\n\n" . $reason : '';
                }
                $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';
                $messenger->template($email_template, $post_data['user_lang']);
                $messenger->to($post_data['user_email'], $post_data['username']);
                $messenger->im($post_data['user_jabber'], $post_data['username']);
                $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($post_data['username']), 'REASON' => htmlspecialchars_decode($email_disapprove_reason), 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])), 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title']))));
                $messenger->send($post_data['user_notify_type']);
            }
            unset($lang_reasons);
        }
        unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang);
        $messenger->save_queue();
        if (sizeof($forum_topics_real)) {
            $success_msg = $num_disapproved == 1 ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
        } else {
            $success_msg = sizeof($post_id_list) == 1 ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
        }
    } else {
        include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx;
        display_reasons($reason_id);
        $show_notify = false;
        foreach ($post_info as $post_data) {
            if ($post_data['poster_id'] == ANONYMOUS) {
                continue;
            } else {
                $show_notify = true;
                break;
            }
        }
        $template->assign_vars(array('S_NOTIFY_POSTER' => $show_notify, 'S_APPROVE' => false, 'REASON' => $reason, 'ADDITIONAL_MSG' => $additional_msg));
        confirm_box(false, 'DISAPPROVE_POST' . (sizeof($post_id_list) == 1 ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
    }
    $redirect = request_var('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        redirect($redirect);
    } else {
        meta_refresh(3, $redirect);
        trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"{$redirect}\">", '</a>'));
    }
}
示例#2
0
	{
		$sql = 'UPDATE ' . TOPICS_TABLE . '
			SET topic_reported = 1
			WHERE topic_id = ' . $report_data['topic_id'] . '
				OR topic_moved_id = ' . $report_data['topic_id'];
		$db->sql_query($sql);
	}

	meta_refresh(3, $redirect_url);

	$message = $user->lang['POST_REPORTED_SUCCESS'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
	trigger_error($message);
}

// Generate the reasons
display_reasons($reason_id);

$template->assign_vars(array(
	'REPORT_TEXT'		=> $report_text,
	'S_REPORT_ACTION'	=> append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id),

	'S_NOTIFY'			=> $user_notify,
	'S_CAN_NOTIFY'		=> ($user->data['is_registered']) ? true : false)
);

generate_forum_nav($forum_data);

// Start output of page
page_header($user->lang['REPORT_POST']);

$template->set_filenames(array(
示例#3
0
/**
* Disapprove Post/Topic
*/
function disapprove_post($post_id_list, $mode)
{
    global $db, $template, $user, $config;
    global $phpEx, $phpbb_root_path;
    if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_approve'))) {
        trigger_error('NOT_AUTHORIZED');
    }
    $redirect = request_var('redirect', build_url(array('t', 'mode')) . '&amp;mode=unapproved_topics');
    $reason = request_var('reason', '', true);
    $reason_id = request_var('reason_id', 0);
    $success_msg = $additional_msg = '';
    $s_hidden_fields = build_hidden_fields(array('i' => 'queue', 'mode' => $mode, 'post_id_list' => $post_id_list, 'f' => $forum_id, 'action' => 'disapprove', 'redirect' => $redirect));
    $notify_poster = isset($_REQUEST['notify_poster']) ? true : false;
    $disapprove_reason = '';
    if ($reason_id) {
        $sql = 'SELECT reason_title, reason_description
			FROM ' . REPORTS_REASONS_TABLE . "\n\t\t\tWHERE reason_id = {$reason_id}";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$row || !$reason && $row['reason_title'] == 'other') {
            $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
            unset($_POST['confirm']);
        } else {
            // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
            $disapprove_reason = $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'] : '';
            $disapprove_reason .= $reason ? "\n\n" . $reason : '';
        }
    }
    if (confirm_box(true)) {
        $post_info = get_post_data($post_id_list, 'm_approve');
        // If Topic -> forum_topics_real -= 1
        // If Post -> topic_replies_real -= 1
        $forum_topics_real = 0;
        $topic_replies_real_sql = $post_disapprove_sql = $topic_id_list = array();
        foreach ($post_info as $post_id => $post_data) {
            $topic_id_list[$post_data['topic_id']] = 1;
            // Topic or Post. ;)
            if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id) {
                if ($post_data['forum_id']) {
                    $forum_topics_real++;
                }
            } else {
                if (!isset($topic_replies_real_sql[$post_data['topic_id']])) {
                    $topic_replies_real_sql[$post_data['topic_id']] = 1;
                } else {
                    $topic_replies_real_sql[$post_data['topic_id']]++;
                }
            }
            $post_disapprove_sql[] = $post_id;
        }
        if ($forum_topics_real) {
            $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\t\t\tSET forum_topics_real = forum_topics_real - {$forum_topics_real}\n\t\t\t\tWHERE forum_id = {$forum_id}";
            $db->sql_query($sql);
        }
        if (sizeof($topic_replies_real_sql)) {
            foreach ($topic_replies_real_sql as $topic_id => $num_replies) {
                $sql = 'UPDATE ' . TOPICS_TABLE . "\n\t\t\t\t\tSET topic_replies_real = topic_replies_real - {$num_replies}\n\t\t\t\t\tWHERE topic_id = {$topic_id}";
                $db->sql_query($sql);
            }
        }
        if (sizeof($post_disapprove_sql)) {
            if (!function_exists('delete_posts')) {
                include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
            }
            // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
            delete_posts('post_id', $post_disapprove_sql);
        }
        unset($post_disapprove_sql, $topic_replies_real_sql);
        update_post_information('topic', array_keys($topic_id_list));
        update_post_information('forum', $forum_id);
        unset($topic_id_list);
        $messenger = new messenger();
        // Notify Poster?
        if ($notify_poster) {
            $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
            foreach ($post_info as $post_id => $post_data) {
                if ($post_data['poster_id'] == ANONYMOUS) {
                    continue;
                }
                $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';
                $messenger->template($email_template, $post_data['user_lang']);
                $messenger->replyto($config['board_email']);
                $messenger->to($post_data['user_email'], $post_data['username']);
                $messenger->im($post_data['user_jabber'], $post_data['username']);
                $messenger->assign_vars(array('EMAIL_SIG' => $email_sig, 'SITENAME' => $config['sitename'], 'USERNAME' => html_entity_decode($post_data['username']), 'REASON' => html_entity_decode($disapprove_reason), 'POST_SUBJECT' => html_entity_decode(censor_text($post_data['post_subject'])), 'TOPIC_TITLE' => html_entity_decode(censor_text($post_data['topic_title']))));
                $messenger->send($post_data['user_notify_type']);
                $messenger->reset();
            }
            $messenger->save_queue();
        }
        unset($post_info, $disapprove_reason);
        if ($forum_topics_real) {
            $success_msg = $forum_topics_real == 1 ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
        } else {
            $success_msg = sizeof($post_id_list) == 1 ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
        }
    } else {
        include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx;
        display_reasons($reason_id);
        $template->assign_vars(array('S_NOTIFY_POSTER' => true, 'S_APPROVE' => false, 'REASON' => $reason, 'ADDITIONAL_MSG' => $additional_msg));
        confirm_box(false, 'DISAPPROVE_POST' . (sizeof($post_id_list) == 1 ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
    }
    $redirect = request_var('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        redirect($redirect);
    } else {
        meta_refresh(3, $redirect);
        trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], "<a href=\"{$redirect}\">", '</a>'));
    }
}
示例#4
0
    /**
     * Disapprove Post
     *
     * @param $post_id_list	array	IDs of the posts to disapprove/delete
     * @param $id			mixed	Category of the current active module
     * @param $mode			string	Active module
     * @return null
     */
    public static function disapprove_posts($post_id_list, $id, $mode)
    {
        global $db, $template, $user, $config, $phpbb_container, $phpbb_dispatcher;
        global $phpEx, $phpbb_root_path, $request;
        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('t', 'mode', 'quickmod')) . "&amp;mode={$mode}");
        $redirect = reapply_sid($redirect);
        $reason = $request->variable('reason', '', true);
        $reason_id = $request->variable('reason_id', 0);
        $success_msg = $additional_msg = '';
        $s_hidden_fields = build_hidden_fields(array('i' => $id, 'mode' => $mode, 'post_id_list' => $post_id_list, 'action' => 'disapprove', 'redirect' => $redirect));
        $notify_poster = $request->is_set('notify_poster');
        $disapprove_reason = '';
        if ($reason_id) {
            $sql = 'SELECT reason_title, reason_description
				FROM ' . REPORTS_REASONS_TABLE . "\n\t\t\t\tWHERE reason_id = {$reason_id}";
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$row || !$reason && strtolower($row['reason_title']) == 'other') {
                $additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
                $request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
                $request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST);
                $request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST);
            } else {
                // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
                $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'] : '';
                $disapprove_reason .= $reason ? "\n\n" . $reason : '';
                if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) {
                    $disapprove_reason_lang = strtoupper($row['reason_title']);
                }
            }
        }
        $post_info = phpbb_get_post_data($post_id_list, 'm_approve');
        $is_disapproving = false;
        foreach ($post_info as $post_id => $post_data) {
            if ($post_data['post_visibility'] == ITEM_DELETED) {
                continue;
            }
            $is_disapproving = true;
        }
        if (confirm_box(true)) {
            $disapprove_log = $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) {
                $post_disapprove_list[$post_id] = $post_data['topic_id'];
                if (!isset($topic_posts_unapproved[$post_data['topic_id']])) {
                    $topic_information[$post_data['topic_id']] = $post_data;
                    $topic_posts_unapproved[$post_data['topic_id']] = 0;
                }
                $topic_posts_unapproved[$post_data['topic_id']]++;
            }
            // Now we build the log array
            foreach ($post_disapprove_list as $post_id => $topic_id) {
                // If the count of disapproved posts for the topic is equal
                // to the number of unapproved posts in the topic, and there are no different
                // posts, we disapprove the hole topic
                if ($topic_information[$topic_id]['topic_posts_approved'] == 0 && $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_id]) {
                    // Don't write the log more than once for every topic
                    if (!isset($disapprove_log_topics[$topic_id])) {
                        // Build disapproved topics log
                        $disapprove_log_topics[$topic_id] = array('type' => 'topic', 'post_subject' => $post_info[$post_id]['topic_title'], 'forum_id' => $post_info[$post_id]['forum_id'], 'topic_id' => 0, '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']);
                    }
                } else {
                    // Build disapproved posts log
                    $disapprove_log_posts[] = array('type' => 'post', 'post_subject' => $post_info[$post_id]['post_subject'], 'forum_id' => $post_info[$post_id]['forum_id'], 'topic_id' => $post_info[$post_id]['topic_id'], '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']);
                }
            }
            // Get disapproved posts/topics counts separately
            $num_disapproved_topics = sizeof($disapprove_log_topics);
            $num_disapproved_posts = sizeof($disapprove_log_posts);
            // Build the whole log
            $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
            // Unset unneeded arrays
            unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
            // Let's do the job - delete disapproved posts
            if (sizeof($post_disapprove_list)) {
                if (!function_exists('delete_posts')) {
                    include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
                }
                // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
                // Note: function delete_posts triggers related forums/topics sync,
                // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
                delete_posts('post_id', array_keys($post_disapprove_list));
                foreach ($disapprove_log as $log_data) {
                    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, $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_notifications = $phpbb_container->get('notification_manager');
            $lang_reasons = array();
            foreach ($post_info as $post_id => $post_data) {
                $disapprove_all_posts_in_topic = $topic_information[$topic_id]['topic_posts_approved'] == 0 && $topic_information[$topic_id]['topic_posts_softdeleted'] == 0 && $topic_information[$topic_id]['topic_posts_unapproved'] == $topic_posts_unapproved[$topic_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('notification.type.topic_in_queue', $post_data['topic_id']);
                }
                // Notify Poster?
                if ($notify_poster) {
                    if ($post_data['poster_id'] == ANONYMOUS) {
                        continue;
                    }
                    $post_data['disapprove_reason'] = '';
                    if (isset($disapprove_reason_lang)) {
                        // Okay we need to get the reason from the posters language
                        if (!isset($lang_reasons[$post_data['user_lang']])) {
                            // Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
                            $lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
                            // Only load up the language pack if the language is different to the current one
                            if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx)) {
                                // Load up the language pack
                                $lang = array();
                                @(include $phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
                                // If we find the reason in this language pack use it
                                if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang])) {
                                    $lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
                                }
                                unset($lang);
                                // Free memory
                            }
                        }
                        $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']];
                        $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('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('notification.type.disapprove_post', $post_data);
                    }
                }
            }
            if ($num_disapproved_topics) {
                $success_msg = $num_disapproved_topics == 1 ? 'TOPIC' : 'TOPICS';
            } else {
                $success_msg = $num_disapproved_posts == 1 ? 'POST' : 'POSTS';
            }
            if ($is_disapproving) {
                $success_msg .= '_DISAPPROVED_SUCCESS';
            } else {
                $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("&amp;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];
            if ($request->is_ajax()) {
                $json_response = new \phpbb\json_response();
                $json_response->send(array('MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $message, 'REFRESH_DATA' => null, 'visible' => false));
            }
            $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
            trigger_error($message);
        } else {
            if (!function_exists('display_reasons')) {
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
            }
            $show_notify = false;
            foreach ($post_info as $post_data) {
                if ($post_data['poster_id'] == ANONYMOUS) {
                    continue;
                } else {
                    $show_notify = true;
                    break;
                }
            }
            $l_confirm_msg = 'DISAPPROVE_POST';
            $confirm_template = 'mcp_approve.html';
            if ($is_disapproving) {
                display_reasons($reason_id);
            } else {
                $user->add_lang('posting');
                $l_confirm_msg = 'DELETE_POST_PERMANENTLY';
                $confirm_template = 'confirm_delete_body.html';
            }
            $l_confirm_msg .= sizeof($post_id_list) == 1 ? '' : 'S';
            $template->assign_vars(array('S_NOTIFY_POSTER' => $show_notify, 'S_APPROVE' => false, 'REASON' => $is_disapproving ? $reason : '', 'ADDITIONAL_MSG' => $additional_msg));
            confirm_box(false, $l_confirm_msg, $s_hidden_fields, $confirm_template);
        }
        redirect($redirect);
    }
/**
* Disapprove Post/Topic
*/
function disapprove_post($post_id_list, $mode)
{
    global $_CLASS, $_CORE_CONFIG, $config;
    $forum_id = request_var('f', 0);
    if (!check_ids($post_id_list, FORUMS_POSTS_TABLE, 'post_id', 'm_approve')) {
        trigger_error('NOT_AUTHORIZED');
    }
    $redirect = request_var('redirect', $_CLASS['core_user']->data['session_page']);
    $reason = request_var('reason', '', true);
    $reason_id = request_var('reason_id', 0);
    $success_msg = $additional_msg = '';
    $s_hidden_fields = build_hidden_fields(array('i' => 'queue', 'f' => $forum_id, 'mode' => $mode, 'post_id_list' => $post_id_list, 'mode' => 'disapprove', 'redirect' => $redirect));
    $notify_poster = isset($_REQUEST['notify_poster']);
    $disapprove_reason = '';
    if ($reason_id) {
        $sql = 'SELECT reason_title, reason_description
			FROM ' . FORUMS_REPORTS_REASONS_TABLE . " \n\t\t\tWHERE reason_id = {$reason_id}";
        $result = $_CLASS['core_db']->query($sql);
        $row = $_CLASS['core_db']->fetch_row_assoc($result);
        $_CLASS['core_db']->free_result($result);
        if (!$row || !$reason && $row['reason_name'] === 'other') {
            $additional_msg = $_CLASS['core_user']->lang['NO_REASON_DISAPPROVAL'];
            unset($_POST['confirm']);
        } else {
            $disapprove_reason = $row['reason_title'] != 'other' ? isset($_CLASS['core_user']->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]) ? $_CLASS['core_user']->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description'] : '';
            $disapprove_reason .= $reason ? "\n\n" . $reason : '';
            unset($reason);
        }
    }
    require_once SITE_FILE_ROOT . 'includes/forums/functions_display.php';
    $reason = display_reasons($reason_id);
    $_CLASS['core_template']->assign_array(array('S_NOTIFY_POSTER' => true, 'S_APPROVE' => false, 'REASON' => $reason, 'ADDITIONAL_MSG' => $additional_msg));
    if (display_confirmation($_CLASS['core_user']->get_lang('DISAPPROVE_POST' . (sizeof($post_id_list) == 1 ? '' : 'S')), $s_hidden_fields, 'modules/forums/mcp_approve.html')) {
        $post_info = get_post_data($post_id_list, 'm_approve');
        // If Topic -> forum_topics_real -= 1
        // If Post -> topic_replies_real -= 1
        $forum_topics_real = 0;
        $topic_replies_real_sql = $post_disapprove_sql = $topic_id_list = array();
        foreach ($post_info as $post_id => $post_data) {
            $topic_id_list[$post_data['topic_id']] = 1;
            // Topic or Post. ;)
            if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id) {
                if ($post_data['forum_id']) {
                    $forum_topics_real++;
                }
            } else {
                if (!isset($topic_replies_real_sql[$post_data['topic_id']])) {
                    $topic_replies_real_sql[$post_data['topic_id']] = 1;
                } else {
                    $topic_replies_real_sql[$post_data['topic_id']]++;
                }
            }
            $post_disapprove_sql[] = $post_id;
        }
        if ($forum_topics_real) {
            $sql = 'UPDATE ' . FORUMS_FORUMS_TABLE . "\n\t\t\t\tSET forum_topics_real = forum_topics_real - {$forum_topics_real}\n\t\t\t\tWHERE forum_id = {$forum_id}";
            $_CLASS['core_db']->query($sql);
        }
        if (!empty($topic_replies_real_sql)) {
            foreach ($topic_replies_real_sql as $topic_id => $num_replies) {
                $sql = 'UPDATE ' . FORUMS_TOPICS_TABLE . "\n\t\t\t\t\tSET topic_replies_real = topic_replies_real - {$num_replies}\n\t\t\t\t\tWHERE topic_id = {$topic_id}";
                $_CLASS['core_db']->query($sql);
            }
        }
        if (sizeof($post_disapprove_sql)) {
            if (!function_exists('delete_posts')) {
                require_once SITE_FILE_ROOT . 'includes/forums/functions_admin.php';
            }
            // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
            delete_posts('post_id', $post_disapprove_sql);
        }
        unset($post_disapprove_sql, $topic_replies_real_sql);
        update_post_information('topic', array_keys($topic_id_list));
        update_post_information('forum', $forum_id);
        unset($topic_id_list);
        // Notify Poster?
        if ($notify_poster) {
            require_once SITE_FILE_ROOT . 'includes/mailer.php';
            $mailer = new core_mailer();
            foreach ($post_info as $post_id => $post_data) {
                if ($post_data['poster_id'] == ANONYMOUS) {
                    continue;
                }
                $post_data['post_subject'] = censor_text($post_data['post_subject'], true);
                $post_data['topic_title'] = censor_text($post_data['topic_title'], true);
                if ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) {
                    $email_template = 'topic_disapproved.txt';
                    $subject = 'Topic Disapproved - ' . $post_data['topic_title'];
                } else {
                    $email_template = 'post_disapproved.txt';
                    $subject = 'Post Disapproved - ' . $post_data['post_subject'];
                }
                $mailer->to($post_data['user_email'], $post_data['username']);
                //$mailer->reply_to($_CORE_CONFIG['email']['site_email']);
                $mailer->subject($subject);
                //$messenger->im($post_data['user_jabber'], $post_data['username']);
                $_CLASS['core_template']->assign_array(array('SITENAME' => $_CORE_CONFIG['global']['site_name'], 'USERNAME' => $post_data['username'], 'REASON' => stripslashes($disapprove_reason), 'POST_SUBJECT' => $post_data['post_subject'], 'TOPIC_TITLE' => $post_data['topic_title']));
                $mailer->message = trim($_CLASS['core_template']->display('email/forums/' . $email_template, true));
                $mailer->send();
            }
        }
        unset($post_info, $disapprove_reason);
        if ($forum_topics_real) {
            $success_msg = $forum_topics_real == 1 ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
        } else {
            $success_msg = sizeof($post_id_list) == 1 ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
        }
    }
    $redirect = request_var('redirect', generate_link('forums'));
    if (!$success_msg) {
        redirect($redirect);
    } else {
        $_CLASS['core_display']->meta_refresh(3, generate_link("forums&amp;file=viewforum&amp;f={$forum_id}"));
        trigger_error($_CLASS['core_user']->lang[$success_msg] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_FORUM'], '<a href="' . generate_link('forums&amp;file=viewforum&amp;f=' . $forum_id) . '">', '</a>'));
    }
}
示例#6
0
 /**
  * Disapprove action.
  *
  * @return null
  */
 protected function disapprove()
 {
     if (!$this->attention->is_open() || $this->attention->is_report()) {
         redirect($this->helper->route('phpbb.titania.manage.attention'));
     }
     $disapprove_reason = $this->request->variable('disapprove_reason', 0);
     $disapprove_explain = $this->request->variable('disapprove_explain', '', true);
     $result = false;
     if (confirm_box(true)) {
         $result = $this->attention->disapprove($disapprove_reason, $disapprove_explain);
     }
     if (!$result || $result === 'reason_empty') {
         if ($result) {
             $this->template->assign_var('ADDITIONAL_MSG', $this->user->lang['NO_REASON_DISAPPROVAL']);
             // Make sure we can reuse the confirm box
             $this->request->overwrite('confirm_key', null, \phpbb\request\request_interface::REQUEST);
             $this->request->overwrite('confirm_key', null, \phpbb\request\request_interface::POST);
             $this->request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
         }
         \phpbb::_include('functions_display', 'display_reasons');
         display_reasons($disapprove_reason);
         confirm_box(false, 'DISAPPROVE_ITEM', build_hidden_fields(array('disapprove' => true)), 'manage/disapprove_body.html');
     }
     redirect($this->helper->route('phpbb.titania.manage.attention'));
 }