Example #1
0
/**
* Delete Topics
*/
function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_topic')
{
    global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_log;
    $check_permission = $is_soft ? 'm_softdelete' : 'm_delete';
    if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array($check_permission))) {
        return;
    }
    $redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));
    $forum_id = $request->variable('f', 0);
    $s_hidden_fields = array('topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => $action, 'redirect' => $redirect);
    $success_msg = '';
    if (confirm_box(true)) {
        $success_msg = sizeof($topic_ids) == 1 ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
        $data = phpbb_get_topic_data($topic_ids);
        foreach ($data as $topic_id => $row) {
            if ($row['topic_moved_id']) {
                $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_DELETE_SHADOW_TOPIC', false, array('forum_id' => $row['forum_id'], 'topic_id' => $topic_id, $row['topic_title']));
            } else {
                // Only soft delete non-shadow topics
                if ($is_soft) {
                    /* @var $phpbb_content_visibility \phpbb\content_visibility */
                    $phpbb_content_visibility = $phpbb_container->get('content.visibility');
                    $return = $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), $soft_delete_reason);
                    if (!empty($return)) {
                        $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SOFTDELETE_TOPIC', false, array('forum_id' => $row['forum_id'], 'topic_id' => $topic_id, $row['topic_title'], $row['topic_first_poster_name'], $soft_delete_reason));
                    }
                } else {
                    $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_DELETE_TOPIC', false, array('forum_id' => $row['forum_id'], 'topic_id' => $topic_id, $row['topic_title'], $row['topic_first_poster_name'], $soft_delete_reason));
                }
            }
        }
        if (!$is_soft) {
            $return = delete_topics('topic_id', $topic_ids);
        }
    } else {
        global $template;
        $user->add_lang('posting');
        // If there are only shadow topics, we neither need a reason nor softdelete
        $sql = 'SELECT topic_id
			FROM ' . TOPICS_TABLE . '
			WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
				AND topic_moved_id = 0';
        $result = $db->sql_query_limit($sql, 1);
        $only_shadow = !$db->sql_fetchfield('topic_id');
        $db->sql_freeresult($result);
        $only_softdeleted = false;
        if (!$only_shadow && $auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) {
            // If there are only soft deleted topics, we display a message why the option is not available
            $sql = 'SELECT topic_id
				FROM ' . TOPICS_TABLE . '
				WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
					AND topic_visibility <> ' . ITEM_DELETED;
            $result = $db->sql_query_limit($sql, 1);
            $only_softdeleted = !$db->sql_fetchfield('topic_id');
            $db->sql_freeresult($result);
        }
        $template->assign_vars(array('S_SHADOW_TOPICS' => $only_shadow, 'S_SOFTDELETED' => $only_softdeleted, 'S_TOPIC_MODE' => true, 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id), 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id)));
        $l_confirm = sizeof($topic_ids) == 1 ? 'DELETE_TOPIC' : 'DELETE_TOPICS';
        if ($only_softdeleted) {
            $l_confirm .= '_PERMANENTLY';
            $s_hidden_fields['delete_permanent'] = '1';
        } else {
            if ($only_shadow || !$auth->acl_get('m_softdelete', $forum_id)) {
                $s_hidden_fields['delete_permanent'] = '1';
            }
        }
        confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html');
    }
    $topic_id = $request->variable('t', 0);
    if (!$request->is_set('quickmod', \phpbb\request\request_interface::REQUEST)) {
        $redirect = $request->variable('redirect', "index.{$phpEx}");
        $redirect = reapply_sid($redirect);
        $redirect_message = 'PAGE';
    } else {
        if ($is_soft && $topic_id) {
            $redirect = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 't=' . $topic_id);
            $redirect_message = 'TOPIC';
        } else {
            $redirect = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
            $redirect_message = 'FORUM';
        }
    }
    if (!$success_msg) {
        redirect($redirect);
    } else {
        meta_refresh(3, $redirect);
        trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
    }
}
Example #2
0
/**
* Prune function
*/
function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true)
{
    global $db, $phpbb_dispatcher;
    if (!is_array($forum_id)) {
        $forum_id = array($forum_id);
    }
    if (!sizeof($forum_id)) {
        return;
    }
    $sql_and = '';
    if (!($prune_flags & FORUM_FLAG_PRUNE_ANNOUNCE)) {
        $sql_and .= ' AND topic_type <> ' . POST_ANNOUNCE;
        $sql_and .= ' AND topic_type <> ' . POST_GLOBAL;
    }
    if (!($prune_flags & FORUM_FLAG_PRUNE_STICKY)) {
        $sql_and .= ' AND topic_type <> ' . POST_STICKY;
    }
    if ($prune_mode == 'posted') {
        $sql_and .= " AND topic_last_post_time < {$prune_date}";
    }
    if ($prune_mode == 'viewed') {
        $sql_and .= " AND topic_last_view_time < {$prune_date}";
    }
    if ($prune_mode == 'shadow') {
        $sql_and .= ' AND topic_status = ' . ITEM_MOVED . " AND topic_last_post_time < {$prune_date}";
    }
    /**
     * Use this event to modify the SQL that selects topics to be pruned
     *
     * @event core.prune_sql
     * @var string	forum_id		The forum id
     * @var string	prune_mode		The prune mode
     * @var string	prune_date		The prune date
     * @var int		prune_flags		The prune flags
     * @var bool		auto_sync		Whether or not to perform auto sync
     * @var string	sql_and			SQL text appended to where clause
     * @since 3.1.3-RC1
     */
    $vars = array('forum_id', 'prune_mode', 'prune_date', 'prune_flags', 'auto_sync', 'sql_and');
    extract($phpbb_dispatcher->trigger_event('core.prune_sql', compact($vars)));
    $sql = 'SELECT topic_id
		FROM ' . TOPICS_TABLE . '
		WHERE ' . $db->sql_in_set('forum_id', $forum_id) . "\n\t\t\tAND poll_start = 0\n\t\t\t{$sql_and}";
    $result = $db->sql_query($sql);
    $topic_list = array();
    while ($row = $db->sql_fetchrow($result)) {
        $topic_list[] = $row['topic_id'];
    }
    $db->sql_freeresult($result);
    if ($prune_flags & FORUM_FLAG_PRUNE_POLL) {
        $sql = 'SELECT topic_id
			FROM ' . TOPICS_TABLE . '
			WHERE ' . $db->sql_in_set('forum_id', $forum_id) . "\n\t\t\t\tAND poll_start > 0\n\t\t\t\tAND poll_last_vote < {$prune_date}\n\t\t\t\t{$sql_and}";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $topic_list[] = $row['topic_id'];
        }
        $db->sql_freeresult($result);
        $topic_list = array_unique($topic_list);
    }
    return delete_topics('topic_id', $topic_list, $auto_sync, false);
}
/**
* Prune function
*/
function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true)
{
    global $db;
    if (!is_array($forum_id)) {
        $forum_id = array($forum_id);
    }
    if (!sizeof($forum_id)) {
        return;
    }
    $sql_and = '';
    if (!($prune_flags & FORUM_FLAG_PRUNE_ANNOUNCE)) {
        $sql_and .= ' AND topic_type <> ' . POST_ANNOUNCE;
    }
    if (!($prune_flags & FORUM_FLAG_PRUNE_STICKY)) {
        $sql_and .= ' AND topic_type <> ' . POST_STICKY;
    }
    if ($prune_mode == 'posted') {
        $sql_and .= " AND topic_last_post_time < {$prune_date}";
    }
    if ($prune_mode == 'viewed') {
        $sql_and .= " AND topic_last_view_time < {$prune_date}";
    }
    $sql = 'SELECT topic_id
		FROM ' . TOPICS_TABLE . '
		WHERE ' . $db->sql_in_set('forum_id', $forum_id) . "\n\t\t\tAND poll_start = 0\n\t\t\t{$sql_and}";
    $result = $db->sql_query($sql);
    $topic_list = array();
    while ($row = $db->sql_fetchrow($result)) {
        $topic_list[] = $row['topic_id'];
    }
    $db->sql_freeresult($result);
    if ($prune_flags & FORUM_FLAG_PRUNE_POLL) {
        $sql = 'SELECT topic_id
			FROM ' . TOPICS_TABLE . '
			WHERE ' . $db->sql_in_set('forum_id', $forum_id) . "\n\t\t\t\tAND poll_start > 0\n\t\t\t\tAND poll_last_vote < {$prune_date}\n\t\t\t\t{$sql_and}";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $topic_list[] = $row['topic_id'];
        }
        $db->sql_freeresult($result);
        $topic_list = array_unique($topic_list);
    }
    return delete_topics('topic_id', $topic_list, $auto_sync, false);
}
Example #4
0
/**
* Delete Post
*/
function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '')
{
    global $db, $user, $auth, $phpbb_container;
    global $config, $phpEx, $phpbb_root_path;
    // Specify our post mode
    $post_mode = 'delete';
    if ($data['topic_first_post_id'] === $data['topic_last_post_id'] && $data['topic_posts_approved'] + $data['topic_posts_unapproved'] + $data['topic_posts_softdeleted'] == 1) {
        $post_mode = 'delete_topic';
    } else {
        if ($data['topic_first_post_id'] == $post_id) {
            $post_mode = 'delete_first_post';
        } else {
            if ($data['topic_last_post_id'] == $post_id) {
                $post_mode = 'delete_last_post';
            }
        }
    }
    $sql_data = array();
    $next_post_id = false;
    include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
    $db->sql_transaction('begin');
    // we must make sure to update forums that contain the shadow'd topic
    if ($post_mode == 'delete_topic') {
        $shadow_forum_ids = array();
        $sql = 'SELECT forum_id
			FROM ' . TOPICS_TABLE . '
			WHERE ' . $db->sql_in_set('topic_moved_id', $topic_id);
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if (!isset($shadow_forum_ids[(int) $row['forum_id']])) {
                $shadow_forum_ids[(int) $row['forum_id']] = 1;
            } else {
                $shadow_forum_ids[(int) $row['forum_id']]++;
            }
        }
        $db->sql_freeresult($result);
    }
    /* @var $phpbb_content_visibility \phpbb\content_visibility */
    $phpbb_content_visibility = $phpbb_container->get('content.visibility');
    // (Soft) delete the post
    if ($is_soft && $post_mode != 'delete_topic') {
        $phpbb_content_visibility->set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, $data['topic_first_post_id'] == $post_id, $data['topic_last_post_id'] == $post_id);
    } else {
        if (!$is_soft) {
            if (!delete_posts('post_id', array($post_id), false, false, false)) {
                // Try to delete topic, we may had an previous error causing inconsistency
                if ($post_mode == 'delete_topic') {
                    delete_topics('topic_id', array($topic_id), false);
                }
                trigger_error('ALREADY_DELETED');
            }
        }
    }
    $db->sql_transaction('commit');
    // Collect the necessary information for updating the tables
    $sql_data[FORUMS_TABLE] = $sql_data[TOPICS_TABLE] = '';
    switch ($post_mode) {
        case 'delete_topic':
            foreach ($shadow_forum_ids as $updated_forum => $topic_count) {
                // counting is fun! we only have to do sizeof($forum_ids) number of queries,
                // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum)
                $sql = 'UPDATE ' . FORUMS_TABLE . '
					SET forum_topics_approved = forum_topics_approved - ' . $topic_count . '
					WHERE forum_id = ' . $updated_forum;
                $db->sql_query($sql);
                update_post_information('forum', $updated_forum);
            }
            if ($is_soft) {
                $topic_row = array();
                $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason);
            } else {
                delete_topics('topic_id', array($topic_id), false);
                $phpbb_content_visibility->remove_topic_from_statistic($data, $sql_data);
                $update_sql = update_post_information('forum', $forum_id, true);
                if (sizeof($update_sql)) {
                    $sql_data[FORUMS_TABLE] .= $sql_data[FORUMS_TABLE] ? ', ' : '';
                    $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
                }
            }
            break;
        case 'delete_first_post':
            $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour
				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u\n\t\t\t\tWHERE p.topic_id = {$topic_id}\n\t\t\t\t\tAND p.poster_id = u.user_id\n\t\t\t\t\tAND p.post_visibility = " . ITEM_APPROVED . '
				ORDER BY p.post_time ASC, p.post_id ASC';
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$row) {
                // No approved post, so the first is a not-approved post (unapproved or soft deleted)
                $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour
					FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u\n\t\t\t\t\tWHERE p.topic_id = {$topic_id}\n\t\t\t\t\t\tAND p.poster_id = u.user_id\n\t\t\t\t\tORDER BY p.post_time ASC, p.post_id ASC";
                $result = $db->sql_query_limit($sql, 1);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
            }
            $next_post_id = (int) $row['post_id'];
            $sql_data[TOPICS_TABLE] = $db->sql_build_array('UPDATE', array('topic_poster' => (int) $row['poster_id'], 'topic_first_post_id' => (int) $row['post_id'], 'topic_first_poster_colour' => $row['user_colour'], 'topic_first_poster_name' => $row['poster_id'] == ANONYMOUS ? $row['post_username'] : $row['username'], 'topic_time' => (int) $row['post_time']));
            break;
        case 'delete_last_post':
            if (!$is_soft) {
                // Update last post information when hard deleting. Soft delete already did that by itself.
                $update_sql = update_post_information('forum', $forum_id, true);
                if (sizeof($update_sql)) {
                    $sql_data[FORUMS_TABLE] = ($sql_data[FORUMS_TABLE] ? $sql_data[FORUMS_TABLE] . ', ' : '') . implode(', ', $update_sql[$forum_id]);
                }
                $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE] ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_bumped = 0, topic_bumper = 0';
                $update_sql = update_post_information('topic', $topic_id, true);
                if (!empty($update_sql)) {
                    $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]);
                    $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]);
                }
            }
            if (!$next_post_id) {
                $sql = 'SELECT MAX(post_id) as last_post_id
					FROM ' . POSTS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\tAND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id);
                $result = $db->sql_query($sql);
                $next_post_id = (int) $db->sql_fetchfield('last_post_id');
                $db->sql_freeresult($result);
            }
            break;
        case 'delete':
            $sql = 'SELECT post_id
				FROM ' . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\tAND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id) . '
					AND post_time > ' . $data['post_time'] . '
				ORDER BY post_time ASC, post_id ASC';
            $result = $db->sql_query_limit($sql, 1);
            $next_post_id = (int) $db->sql_fetchfield('post_id');
            $db->sql_freeresult($result);
            break;
    }
    if ($post_mode == 'delete' || $post_mode == 'delete_last_post' || $post_mode == 'delete_first_post') {
        if (!$is_soft) {
            $phpbb_content_visibility->remove_post_from_statistic($data, $sql_data);
        }
        $sql = 'SELECT 1 AS has_attachments
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE topic_id = ' . $topic_id;
        $result = $db->sql_query_limit($sql, 1);
        $has_attachments = (int) $db->sql_fetchfield('has_attachments');
        $db->sql_freeresult($result);
        if (!$has_attachments) {
            $sql_data[TOPICS_TABLE] = ($sql_data[TOPICS_TABLE] ? $sql_data[TOPICS_TABLE] . ', ' : '') . 'topic_attachment = 0';
        }
    }
    $db->sql_transaction('begin');
    $where_sql = array(FORUMS_TABLE => "forum_id = {$forum_id}", TOPICS_TABLE => "topic_id = {$topic_id}", USERS_TABLE => 'user_id = ' . $data['poster_id']);
    foreach ($sql_data as $table => $update_sql) {
        if ($update_sql) {
            $db->sql_query("UPDATE {$table} SET {$update_sql} WHERE " . $where_sql[$table]);
        }
    }
    // Adjust posted info for this user by looking for a post by him/her within this topic...
    if ($post_mode != 'delete_topic' && $config['load_db_track'] && $data['poster_id'] != ANONYMOUS) {
        $sql = 'SELECT poster_id
			FROM ' . POSTS_TABLE . '
			WHERE topic_id = ' . $topic_id . '
				AND poster_id = ' . $data['poster_id'];
        $result = $db->sql_query_limit($sql, 1);
        $poster_id = (int) $db->sql_fetchfield('poster_id');
        $db->sql_freeresult($result);
        // The user is not having any more posts within this topic
        if (!$poster_id) {
            $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
				WHERE topic_id = ' . $topic_id . '
					AND user_id = ' . $data['poster_id'];
            $db->sql_query($sql);
        }
    }
    $db->sql_transaction('commit');
    if ($data['post_reported'] && $post_mode != 'delete_topic') {
        sync('topic_reported', 'topic_id', array($topic_id));
    }
    return $next_post_id;
}
/**
* Delete Post
*/
function delete_post($forum_id, $topic_id, $post_id, &$data)
{
    global $db, $user, $auth;
    global $config, $phpEx, $phpbb_root_path;
    // Specify our post mode
    $post_mode = 'delete';
    if ($data['topic_first_post_id'] === $data['topic_last_post_id'] && $data['topic_replies_real'] == 0) {
        $post_mode = 'delete_topic';
    } else {
        if ($data['topic_first_post_id'] == $post_id) {
            $post_mode = 'delete_first_post';
        } else {
            if ($data['topic_last_post_id'] == $post_id) {
                $post_mode = 'delete_last_post';
            }
        }
    }
    $sql_data = array();
    $next_post_id = false;
    include_once $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
    $db->sql_transaction('begin');
    // we must make sure to update forums that contain the shadow'd topic
    if ($post_mode == 'delete_topic') {
        $shadow_forum_ids = array();
        $sql = 'SELECT forum_id
			FROM ' . TOPICS_TABLE . '
			WHERE ' . $db->sql_in_set('topic_moved_id', $topic_id);
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if (!isset($shadow_forum_ids[(int) $row['forum_id']])) {
                $shadow_forum_ids[(int) $row['forum_id']] = 1;
            } else {
                $shadow_forum_ids[(int) $row['forum_id']]++;
            }
        }
        $db->sql_freeresult($result);
    }
    if (!delete_posts('post_id', array($post_id), false, false)) {
        // Try to delete topic, we may had an previous error causing inconsistency
        if ($post_mode == 'delete_topic') {
            delete_topics('topic_id', array($topic_id), false);
        }
        trigger_error('ALREADY_DELETED');
    }
    $db->sql_transaction('commit');
    // Collect the necessary information for updating the tables
    $sql_data[FORUMS_TABLE] = '';
    switch ($post_mode) {
        case 'delete_topic':
            foreach ($shadow_forum_ids as $updated_forum => $topic_count) {
                // counting is fun! we only have to do sizeof($forum_ids) number of queries,
                // even if the topic is moved back to where its shadow lives (we count how many times it is in a forum)
                $db->sql_query('UPDATE ' . FORUMS_TABLE . ' SET forum_topics_real = forum_topics_real - ' . $topic_count . ', forum_topics = forum_topics - ' . $topic_count . ' WHERE forum_id = ' . $updated_forum);
                update_post_information('forum', $updated_forum);
            }
            delete_topics('topic_id', array($topic_id), false);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_TABLE] .= 'forum_topics_real = forum_topics_real - 1';
                $sql_data[FORUMS_TABLE] .= $data['topic_approved'] ? ', forum_posts = forum_posts - 1, forum_topics = forum_topics - 1' : '';
            }
            $update_sql = update_post_information('forum', $forum_id, true);
            if (sizeof($update_sql)) {
                $sql_data[FORUMS_TABLE] .= $sql_data[FORUMS_TABLE] ? ', ' : '';
                $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
            }
            break;
        case 'delete_first_post':
            $sql = 'SELECT p.post_id, p.poster_id, p.post_time, p.post_username, u.username, u.user_colour
				FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u\n\t\t\t\tWHERE p.topic_id = {$topic_id}\n\t\t\t\t\tAND p.poster_id = u.user_id\n\t\t\t\tORDER BY p.post_time ASC";
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_TABLE] = $data['post_approved'] ? 'forum_posts = forum_posts - 1' : '';
            }
            $sql_data[TOPICS_TABLE] = 'topic_poster = ' . intval($row['poster_id']) . ', topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_colour = '" . $db->sql_escape($row['user_colour']) . "', topic_first_poster_name = '" . ($row['poster_id'] == ANONYMOUS ? $db->sql_escape($row['post_username']) : $db->sql_escape($row['username'])) . "', topic_time = " . (int) $row['post_time'];
            // Decrementing topic_replies here is fine because this case only happens if there is more than one post within the topic - basically removing one "reply"
            $sql_data[TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $next_post_id = (int) $row['post_id'];
            break;
        case 'delete_last_post':
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_TABLE] = $data['post_approved'] ? 'forum_posts = forum_posts - 1' : '';
            }
            $update_sql = update_post_information('forum', $forum_id, true);
            if (sizeof($update_sql)) {
                $sql_data[FORUMS_TABLE] .= $sql_data[FORUMS_TABLE] ? ', ' : '';
                $sql_data[FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
            }
            $sql_data[TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $update_sql = update_post_information('topic', $topic_id, true);
            if (sizeof($update_sql)) {
                $sql_data[TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]);
                $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]);
            } else {
                $sql = 'SELECT MAX(post_id) as last_post_id
					FROM ' . POSTS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id} " . (!$auth->acl_get('m_approve', $forum_id) ? 'AND post_approved = 1' : '');
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $next_post_id = (int) $row['last_post_id'];
            }
            break;
        case 'delete':
            $sql = 'SELECT post_id
				FROM ' . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$topic_id} " . (!$auth->acl_get('m_approve', $forum_id) ? 'AND post_approved = 1' : '') . '
					AND post_time > ' . $data['post_time'] . '
				ORDER BY post_time ASC';
            $result = $db->sql_query_limit($sql, 1);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_TABLE] = $data['post_approved'] ? 'forum_posts = forum_posts - 1' : '';
            }
            $sql_data[TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $next_post_id = (int) $row['post_id'];
            break;
    }
    if ($post_mode == 'delete' || $post_mode == 'delete_last_post' || $post_mode == 'delete_first_post') {
        $sql = 'SELECT 1 AS has_attachments
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE topic_id = ' . $topic_id;
        $result = $db->sql_query_limit($sql, 1);
        $has_attachments = (int) $db->sql_fetchfield('has_attachments');
        $db->sql_freeresult($result);
        if (!$has_attachments) {
            $sql_data[TOPICS_TABLE] .= ', topic_attachment = 0';
        }
    }
    //	$sql_data[USERS_TABLE] = ($data['post_postcount']) ? 'user_posts = user_posts - 1' : '';
    $db->sql_transaction('begin');
    $where_sql = array(FORUMS_TABLE => "forum_id = {$forum_id}", TOPICS_TABLE => "topic_id = {$topic_id}", USERS_TABLE => 'user_id = ' . $data['poster_id']);
    foreach ($sql_data as $table => $update_sql) {
        if ($update_sql) {
            $db->sql_query("UPDATE {$table} SET {$update_sql} WHERE " . $where_sql[$table]);
        }
    }
    // Adjust posted info for this user by looking for a post by him/her within this topic...
    if ($post_mode != 'delete_topic' && $config['load_db_track'] && $data['poster_id'] != ANONYMOUS) {
        $sql = 'SELECT poster_id
			FROM ' . POSTS_TABLE . '
			WHERE topic_id = ' . $topic_id . '
				AND poster_id = ' . $data['poster_id'];
        $result = $db->sql_query_limit($sql, 1);
        $poster_id = (int) $db->sql_fetchfield('poster_id');
        $db->sql_freeresult($result);
        // The user is not having any more posts within this topic
        if (!$poster_id) {
            $sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
				WHERE topic_id = ' . $topic_id . '
					AND user_id = ' . $data['poster_id'];
            $db->sql_query($sql);
        }
    }
    $db->sql_transaction('commit');
    if ($data['post_reported'] && $post_mode != 'delete_topic') {
        sync('topic_reported', 'topic_id', array($topic_id));
    }
    return $next_post_id;
}
function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync = true)
{
    global $_CLASS;
    $sql_forum = is_array($forum_id) ? ' IN (' . implode(',', $forum_id) . ')' : " = {$forum_id}";
    $sql_and = '';
    if (!($prune_flags & 4)) {
        $sql_and .= ' AND topic_type <> ' . POST_ANNOUNCE;
    }
    if (!($prune_flags & 8)) {
        $sql_and .= ' AND topic_type <> ' . POST_STICKY;
    }
    if ($prune_mode == 'posted') {
        $sql_and .= " AND topic_last_post_time < {$prune_date}";
    }
    if ($prune_mode == 'viewed') {
        $sql_and .= " AND topic_last_view_time < {$prune_date}";
    }
    $sql = 'SELECT topic_id
		FROM ' . TOPICS_TABLE . "\n\t\tWHERE forum_id {$sql_forum}\n\t\t\tAND poll_start = 0 \n\t\t\t{$sql_and}";
    $result = $_CLASS['core_db']->query($sql);
    $topic_list = array();
    while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
        $topic_list[] = $row['topic_id'];
    }
    $_CLASS['core_db']->free_result($result);
    if ($prune_flags & 2) {
        $sql = 'SELECT topic_id
			FROM ' . TOPICS_TABLE . "\n\t\t\tWHERE forum_id {$sql_forum} \n\t\t\t\tAND poll_start > 0 \n\t\t\t\tAND poll_last_vote < {$prune_date} \n\t\t\t\t{$sql_and}";
        $result = $_CLASS['core_db']->query($sql);
        while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
            $topic_list[] = $row['topic_id'];
        }
        $_CLASS['core_db']->free_result($result);
        $topic_list = array_unique($topic_list);
    }
    return delete_topics('topic_id', $topic_list, $auto_sync);
}
 function delete_empty_topics()
 {
     global $db;
     $this->check_topic_empty = array_unique($this->check_topic_empty);
     if (count($this->check_topic_empty) > 0) {
         //get list of topics that still have posts
         $sql = 'SELECT DISTINCT topic_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $this->check_topic_empty);
         $result = $db->sql_query($sql);
         $not_empty_topics = array();
         while ($row = $db->sql_fetchrow($result)) {
             $not_empty_topics[] = $row['topic_id'];
         }
         $db->sql_freeresult($result);
         //the difference are the topics which don't have posts anymore
         $empty_topics = array_diff($this->check_topic_empty, $not_empty_topics);
         if (count($empty_topics) > 0) {
             delete_topics('topic_id', $empty_topics);
             //no need to sync deleted topics anymore
             foreach ($empty_topics as $topic_id) {
                 unset($this->data['topic'][$topic_id]);
             }
         }
     }
 }
function delete_post($mode, $post_id, $topic_id, $forum_id, &$data)
{
    global $config, $_CLASS;
    // Specify our post mode
    $post_mode = $data['topic_first_post_id'] == $data['topic_last_post_id'] ? 'delete_topic' : ($data['topic_first_post_id'] == $post_id ? 'delete_first_post' : ($data['topic_last_post_id'] == $post_id ? 'delete_last_post' : 'delete'));
    $sql_data = array();
    $next_post_id = 0;
    $_CLASS['core_db']->transaction();
    if (!delete_posts('post_id', array($post_id), false)) {
        // Try to delete topic, we may had an previous error causing inconsistency
        /*
        if ($post_mode = 'delete_topic')
        {
        	delete_topics('topic_id', array($topic_id), false);
        }
        */
        trigger_error('ALREADY_DELETED');
    }
    $_CLASS['core_db']->transaction('commit');
    // Collect the necessary informations for updating the tables
    $sql_data[FORUMS_FORUMS_TABLE] = '';
    switch ($post_mode) {
        case 'delete_topic':
            delete_topics('topic_id', array($topic_id), false);
            set_config('num_topics', $config['num_topics'] - 1, true);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics_real = forum_topics_real - 1';
                $sql_data[FORUMS_FORUMS_TABLE] .= $data['topic_approved'] ? ', forum_topics = forum_topics - 1' : '';
                $sql_data[FORUMS_FORUMS_TABLE] .= ', ';
            }
            $sql_data[FORUMS_FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id));
            $sql_data[FORUMS_TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            break;
        case 'delete_first_post':
            $sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username 
				FROM ' . FORUMS_POSTS_TABLE . ' p, ' . FORUMS_USERS_TABLE . " u\n\t\t\t\tWHERE p.topic_id = {$topic_id} \n\t\t\t\t\tAND p.poster_id = u.user_id \n\t\t\t\tORDER BY p.post_time ASC";
            $result = $_CLASS['core_db']->query_limit($sql, 1);
            $row = $_CLASS['core_db']->fetch_row_assoc($result);
            $_CLASS['core_db']->free_result($result);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
            }
            $sql_data[FORUMS_TOPICS_TABLE] = 'topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_name = '" . ($row['poster_id'] == ANONYMOUS ? $_CLASS['core_db']->sql_escape($row['post_username']) : $_CLASS['core_db']->sql_escape($row['username'])) . "'";
            $sql_data[FORUMS_TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $next_post_id = (int) $row['post_id'];
            break;
        case 'delete_last_post':
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
            }
            $sql_data[FORUMS_FORUMS_TABLE] .= $sql_data[FORUMS_FORUMS_TABLE] ? ', ' : '';
            $sql_data[FORUMS_FORUMS_TABLE] .= implode(', ', update_last_post_information('forum', $forum_id));
            $sql_data[FORUMS_TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $update = update_last_post_information('topic', $topic_id);
            if (sizeof($update)) {
                $sql_data[FORUMS_TOPICS_TABLE] .= ', ' . implode(', ', $update);
                $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update[0]);
            } else {
                $sql = 'SELECT MAX(post_id) as last_post_id
					FROM ' . FORUMS_POSTS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id} " . (!$_CLASS['auth']->acl_get('m_approve') ? 'AND post_approved = 1' : '');
                $result = $_CLASS['core_db']->query($sql);
                $row = $_CLASS['core_db']->fetch_row_assoc($result);
                $_CLASS['core_db']->free_result($result);
                $next_post_id = (int) $row['last_post_id'];
            }
            break;
        case 'delete':
            $sql = 'SELECT post_id
				FROM ' . FORUMS_POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$topic_id} " . (!$_CLASS['auth']->acl_get('m_approve') ? 'AND post_approved = 1' : '') . '
					AND post_time > ' . $data['post_time'] . '
				ORDER BY post_time ASC';
            $result = $_CLASS['core_db']->query_limit($sql, 1);
            $row = $_CLASS['core_db']->fetch_row_assoc($result);
            $_CLASS['core_db']->free_result($result);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
            }
            $sql_data[FORUMS_TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $next_post_id = (int) $row['post_id'];
    }
    $sql_data[USERS_TABLE] = $_CLASS['auth']->acl_get('f_postcount', $forum_id) ? 'user_posts = user_posts - 1' : '';
    set_config('num_posts', $config['num_posts'] - 1, true);
    $_CLASS['core_db']->transaction();
    $where_sql = array(FORUMS_FORUMS_TABLE => "forum_id = {$forum_id}", FORUMS_TOPICS_TABLE => "topic_id = {$topic_id}", USERS_TABLE => 'user_id = ' . $data['poster_id']);
    foreach ($sql_data as $table => $update_sql) {
        if ($update_sql) {
            $_CLASS['core_db']->query("UPDATE {$table} SET {$update_sql} WHERE " . $where_sql[$table]);
        }
    }
    $_CLASS['core_db']->transaction('commit');
    return $next_post_id;
}
Example #9
0
/**
* Delete Topics
*/
function mcp_delete_topic($topic_ids)
{
    global $auth, $user, $db, $phpEx, $phpbb_root_path;
    if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_delete'))) {
        return;
    }
    $redirect = request_var('redirect', $user->data['session_page']);
    $s_hidden_fields = build_hidden_fields(array('topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'delete_topic', 'redirect' => $redirect));
    $success_msg = '';
    if (confirm_box(true)) {
        $success_msg = sizeof($topic_ids) == 1 ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
        $data = get_topic_data($topic_ids);
        foreach ($data as $topic_id => $row) {
            add_log('mod', $forum_id, 0, 'LOG_TOPIC_DELETED', $row['topic_title']);
        }
        $return = delete_topics('topic_id', $topic_ids, true);
        /**
         * @todo Adjust total post count (mcp_delete_topic)
         */
    } else {
        confirm_box(false, sizeof($topic_ids) == 1 ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
    }
    $redirect = request_var('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        redirect($redirect);
    } else {
        $redirect_url = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
        meta_refresh(3, $redirect_url);
        trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
    }
}
Example #10
0
/**
* Delete Topics
*/
function mcp_delete_topic($topic_ids)
{
    global $auth, $user, $db, $phpEx, $phpbb_root_path;
    if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete'))) {
        return;
    }
    $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
    $forum_id = request_var('f', 0);
    $s_hidden_fields = build_hidden_fields(array('topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'delete_topic', 'redirect' => $redirect));
    $success_msg = '';
    if (confirm_box(true)) {
        $success_msg = sizeof($topic_ids) == 1 ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
        $data = get_topic_data($topic_ids);
        foreach ($data as $topic_id => $row) {
            if ($row['topic_moved_id']) {
                add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']);
            } else {
                add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
            }
        }
        $return = delete_topics('topic_id', $topic_ids);
    } else {
        confirm_box(false, sizeof($topic_ids) == 1 ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
    }
    if (!isset($_REQUEST['quickmod'])) {
        $redirect = request_var('redirect', "index.{$phpEx}");
        $redirect = reapply_sid($redirect);
        $redirect_message = 'PAGE';
    } else {
        $redirect = append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $forum_id);
        $redirect_message = 'FORUM';
    }
    if (!$success_msg) {
        redirect($redirect);
    } else {
        meta_refresh(3, $redirect);
        trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
    }
}
/**
* Delete Post
*/
function delete_post($forum_id, $topic_id, $post_id, &$data)
{
    global $_CLASS, $config;
    // Specify our post mode
    $post_mode = $data['topic_first_post_id'] == $data['topic_last_post_id'] ? 'delete_topic' : ($data['topic_first_post_id'] == $post_id ? 'delete_first_post' : ($data['topic_last_post_id'] == $post_id ? 'delete_last_post' : 'delete'));
    $sql_data = array();
    $next_post_id = 0;
    require_once SITE_FILE_ROOT . 'includes/forums/functions_admin.php';
    $_CLASS['core_db']->transaction();
    if (!delete_posts('post_id', array($post_id), false, false)) {
        // Try to delete topic, we may had an previous error causing inconsistency
        if ($post_mode == 'delete_topic') {
            delete_topics('topic_id', array($topic_id), false);
        }
        trigger_error('ALREADY_DELETED');
    }
    $_CLASS['core_db']->transaction('commit');
    // Collect the necessary information for updating the tables
    $sql_data[FORUMS_FORUMS_TABLE] = '';
    switch ($post_mode) {
        case 'delete_topic':
            delete_topics('topic_id', array($topic_id), false);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] .= 'forum_posts = forum_posts - 1, forum_topics_real = forum_topics_real - 1';
                $sql_data[FORUMS_FORUMS_TABLE] .= $data['topic_approved'] ? ', forum_topics = forum_topics - 1' : '';
            }
            $update_sql = update_post_information('forum', $forum_id, true);
            if (sizeof($update_sql)) {
                $sql_data[FORUMS_FORUMS_TABLE] .= $sql_data[FORUMS_FORUMS_TABLE] ? ', ' : '';
                $sql_data[FORUMS_FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
            }
            break;
        case 'delete_first_post':
            $sql = 'SELECT p.post_id, p.poster_id, p.post_username, u.username
				FROM ' . FORUMS_POSTS_TABLE . ' p, ' . CORE_USERS_TABLE . " u\r\n\t\t\t\tWHERE p.topic_id = {$topic_id}\r\n\t\t\t\t\tAND p.poster_id = u.user_id\r\n\t\t\t\tORDER BY p.post_time ASC";
            $result = $_CLASS['core_db']->query_limit($sql, 1);
            $row = $_CLASS['core_db']->fetch_row_assoc($result);
            $_CLASS['core_db']->free_result($result);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
            }
            $sql_data[FORUMS_TOPICS_TABLE] = 'topic_first_post_id = ' . intval($row['post_id']) . ", topic_first_poster_name = '" . ($row['poster_id'] == ANONYMOUS ? $_CLASS['core_db']->escape($row['post_username']) : $_CLASS['core_db']->escape($row['username'])) . "'";
            $sql_data[FORUMS_TOPICS_TABLE] .= ', topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $next_post_id = (int) $row['post_id'];
            break;
        case 'delete_last_post':
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
            }
            $update_sql = update_post_information('forum', $forum_id, true);
            if (sizeof($update_sql)) {
                $sql_data[FORUMS_FORUMS_TABLE] .= $sql_data[FORUMS_FORUMS_TABLE] ? ', ' : '';
                $sql_data[FORUMS_FORUMS_TABLE] .= implode(', ', $update_sql[$forum_id]);
            }
            $sql_data[FORUMS_TOPICS_TABLE] = 'topic_bumped = 0, topic_bumper = 0, topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $update_sql = update_post_information('topic', $topic_id, true);
            if (sizeof($update_sql)) {
                $sql_data[FORUMS_TOPICS_TABLE] .= ', ' . implode(', ', $update_sql[$topic_id]);
                $next_post_id = (int) str_replace('topic_last_post_id = ', '', $update_sql[$topic_id][0]);
            } else {
                $sql = 'SELECT MAX(post_id) as last_post_id
					FROM ' . FORUMS_POSTS_TABLE . "\r\n\t\t\t\t\tWHERE topic_id = {$topic_id} " . (!$_CLASS['forums_auth']->acl_get('m_approve', $forum_id) ? 'AND post_approved = 1' : '');
                $result = $_CLASS['core_db']->query($sql);
                $row = $_CLASS['core_db']->fetch_row_assoc($result);
                $_CLASS['core_db']->free_result($result);
                $next_post_id = (int) $row['last_post_id'];
            }
            break;
        case 'delete':
            $sql = 'SELECT post_id
				FROM ' . FORUMS_POSTS_TABLE . "\r\n\t\t\t\tWHERE topic_id = {$topic_id} " . (!$_CLASS['forums_auth']->acl_get('m_approve', $forum_id) ? 'AND post_approved = 1' : '') . '
					AND post_time > ' . $data['post_time'] . '
				ORDER BY post_time ASC';
            $result = $_CLASS['core_db']->query_limit($sql, 1);
            $row = $_CLASS['core_db']->fetch_row_assoc($result);
            $_CLASS['core_db']->free_result($result);
            if ($data['topic_type'] != POST_GLOBAL) {
                $sql_data[FORUMS_FORUMS_TABLE] = 'forum_posts = forum_posts - 1';
            }
            $sql_data[FORUMS_TOPICS_TABLE] = 'topic_replies_real = topic_replies_real - 1' . ($data['post_approved'] ? ', topic_replies = topic_replies - 1' : '');
            $next_post_id = (int) $row['post_id'];
            break;
    }
    //$sql_data[CORE_USERS_TABLE] = ($_CLASS['forums_auth']->acl_get('f_postcount', $forum_id)) ? 'user_posts = user_posts - 1' : '';
    $_CLASS['core_db']->transaction();
    $where_sql = array(FORUMS_FORUMS_TABLE => "forum_id = {$forum_id}", FORUMS_TOPICS_TABLE => "topic_id = {$topic_id}", CORE_USERS_TABLE => 'user_id = ' . $data['poster_id']);
    foreach ($sql_data as $table => $update_sql) {
        if ($update_sql) {
            $_CLASS['core_db']->query("UPDATE {$table} SET {$update_sql} WHERE " . $where_sql[$table]);
        }
    }
    unset($sql_data);
    $_CLASS['core_db']->transaction('commit');
    // Adjust posted info for this user by looking for a post by him/her within this topic...
    /*
    if ($post_mode != 'delete_topic' && $config['load_db_track'] && $_CLASS['core_user']->is_user)
    {
    	$sql = 'SELECT poster_id
    		FROM ' . POSTS_TABLE . '
    		WHERE topic_id = ' . $topic_id . '
    			AND poster_id = ' . $_CLASS['core_user']->data['user_id'];
    	$result = $_CLASS['core_db']->query_limit($sql, 1);
    	$poster_id = (int) $db->sql_fetchfield('poster_id');
    	$_CLASS['core_db']->free_result($result);
    
    	// The user is not having any more posts within this topic
    	if (!$poster_id)
    	{
    		$sql = 'DELETE FROM ' . TOPICS_POSTED_TABLE . '
    			WHERE topic_id = ' . $topic_id . '
    				AND user_id = ' . $_CLASS['core_user']->data['user_id'];
    		$_CLASS['core_db']->query($sql);
    	}
    }
    */
    if ($data['post_reported'] && $post_mode != 'delete_topic') {
        sync('topic_reported', 'topic_id', array($topic_id));
    }
    return $next_post_id;
}
Example #12
0
    /**
     * Delete this contribution
     */
    public function delete()
    {
        // Delete Revisions
        $revision = new titania_revision($this);
        $sql = 'SELECT * FROM ' . TITANIA_REVISIONS_TABLE . '
			WHERE contrib_id = ' . $this->contrib_id;
        $result = phpbb::$db->sql_query($sql);
        while ($row = phpbb::$db->sql_fetchrow($result)) {
            $revision->__set_array($row);
            $revision->delete();
        }
        phpbb::$db->sql_freeresult($result);
        // Delete Support/Discussion/Queue Discussion Topics
        $topic = new titania_topic();
        $sql = 'SELECT * FROM ' . TITANIA_TOPICS_TABLE . '
			WHERE ' . phpbb::$db->sql_in_set('topic_type', array(TITANIA_SUPPORT, TITANIA_QUEUE_DISCUSSION)) . '
				AND parent_id = ' . $this->contrib_id;
        $result = phpbb::$db->sql_query($sql);
        while ($row = phpbb::$db->sql_fetchrow($result)) {
            $topic->__set_array($row);
            $topic->delete();
        }
        phpbb::$db->sql_freeresult($result);
        // Change the status to new (handles resetting counts)
        $this->change_status(TITANIA_CONTRIB_NEW);
        // Remove any attention items
        $sql = 'DELETE FROM ' . TITANIA_ATTENTION_TABLE . '
			WHERE attention_object_type = ' . TITANIA_CONTRIB . '
				AND attention_object_id = ' . $this->contrib_id;
        phpbb::$db->sql_query($sql);
        // Delete the release topic
        if ($this->contrib_release_topic_id) {
            phpbb::_include('functions_admin', 'delete_topics');
            delete_topics('topic_id', $this->contrib_release_topic_id);
        }
        // Delete from categories
        $this->update_category_count('-');
        $sql = ' DELETE FROM ' . TITANIA_CONTRIB_IN_CATEGORIES_TABLE . '
			WHERE contrib_id = ' . $this->contrib_id;
        phpbb::$db->sql_query($sql);
        repository::trigger_cron($this->config);
        // Self delete
        parent::delete();
    }
function mcp_delete_topic($topic_ids)
{
    global $_CLASS;
    if (!check_ids($topic_ids, FORUMS_TOPICS_TABLE, 'topic_id', 'm_delete')) {
        return;
    }
    $redirect = get_variable('redirect', 'POST', $_CLASS['core_user']->data['session_url']);
    $hidden_fields = generate_hidden_fields(array('topic_id_list' => $topic_ids, 'mode' => 'delete_topic', 'redirect' => $redirect));
    $success_msg = '';
    $message = $_CLASS['core_user']->get_lang(count($topic_ids) === 1 ? 'DELETE_TOPIC' : 'DELETE_TOPICS');
    if (display_confirmation($message, $hidden_fields)) {
        $success_msg = count($topic_ids) === 1 ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS';
        $data = get_topic_data($topic_ids);
        foreach ($data as $topic_id => $row) {
            add_log('mod', $row['forum_id'], 0, 'LOG_TOPIC_DELETED', $row['topic_title']);
        }
        $return = delete_topics('topic_id', $topic_ids, true);
    }
    $redirect = generate_link($redirect);
    if (!$success_msg) {
        redirect($redirect);
    } else {
        $_CLASS['core_display']->meta_refresh(3, $redirect);
        trigger_error($_CLASS['core_user']->lang[$success_msg] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>'));
    }
}
Example #14
0
 /**
  * Perform the right actions
  * @param Array $error An array that will be filled with error messages that might occure
  * @return void
  */
 function run_tool(&$error)
 {
     global $db, $user;
     $user->add_lang('ucp');
     if (!check_form_key('orphaned_posts')) {
         $error[] = 'FORM_INVALID';
         return;
     }
     $mode = request_var('mode', '');
     switch ($mode) {
         case 'empty_topics':
         case 'orphaned_shadows':
             $topic_ids = request_var('topics', array(0 => 0));
             if (!sizeof($topic_ids)) {
                 trigger_error('NO_TOPICS_SELECTED');
             }
             if (!function_exists('delete_topics')) {
                 include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
             }
             $return = delete_topics('topic_id', $topic_ids);
             trigger_error(sprintf($user->lang['TOPICS_DELETED'], $return['topics']));
             break;
         case 'forum_orphaned_posts':
             // No break
         // No break
         case 'orphaned_posts':
             if (isset($_POST['reassign'])) {
                 $post_map = request_var('posts', array(0 => 0));
                 foreach ($post_map as $post_id => $topic_id) {
                     if ($topic_id == 0) {
                         unset($post_map[$post_id]);
                     }
                 }
                 if (!sizeof($post_map)) {
                     trigger_error('NO_TOPIC_IDS');
                 }
                 // Make sure the specified topic IDs exist
                 $topic_ids = array_values($post_map);
                 $sql = 'SELECT topic_id, forum_id FROM ' . TOPICS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
                 $result = $db->sql_query($sql);
                 $existing_topics = array();
                 while ($row = $db->sql_fetchrow($result)) {
                     $existing_topics[] = (int) $row['topic_id'];
                 }
                 $db->sql_freeresult($result);
                 $missing_topics = array_diff($topic_ids, $existing_topics);
                 if (sizeof($missing_topics)) {
                     trigger_error(sprintf($user->lang['NONEXISTENT_TOPIC_IDS'], implode(', ', $missing_topics)));
                 }
                 // Update the topics with their new IDs
                 foreach ($post_map as $post_id => $topic_id) {
                     $sql = 'SELECT forum_id FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . (int) $topic_id . '';
                     $result = $db->sql_query_limit($sql, 1);
                     $forum_id = (int) $db->sql_fetchfield('forum_id');
                     $db->sql_freeresult($result);
                     $sql = 'UPDATE ' . POSTS_TABLE . ' SET topic_id = ' . (int) $topic_id . ', forum_id = ' . (int) $forum_id . ' WHERE post_id = ' . (int) $post_id;
                     $db->sql_query($sql);
                 }
                 trigger_error(sprintf($user->lang['POSTS_REASSIGNED'], sizeof($post_map)));
             } else {
                 if (isset($_POST['delete'])) {
                     $post_ids = request_var('posts_del', array(0 => 0));
                     if (!sizeof($post_ids)) {
                         trigger_error('NO_POSTS_SELECTED');
                     }
                     if (!function_exists('delete_posts')) {
                         include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
                     }
                     $return = delete_posts('post_id', $post_ids);
                     trigger_error(sprintf($user->lang['POSTS_DELETED'], $return));
                 } else {
                     trigger_error('NO_MODE');
                 }
             }
             break;
         default:
             trigger_error('NO_MODE');
             break;
     }
 }
Example #15
0
 function delete()
 {
     if (!$this->topic_id) {
         trigger_error('NO_TOPIC', E_USER_ERROR);
     }
     $ret = delete_topics('topic_id', $this->topic_id);
     // remove references to the deleted topic so calls to submit() will create a
     // new topic instead of trying to update the topich which does not exist anymore
     $this->topic_id = NULL;
     foreach ($this->posts as $post) {
         $post->topic_id = NULL;
         $post->post_id = NULL;
     }
     return $ret;
 }