Example #1
0
function delete_post($post_id, $topic_id)
{
    global $db, $pun_user;
    $result = $db->query('SELECT `id`, `poster`, `posted` FROM `' . $db->prefix . 'posts` WHERE `topic_id` = ' . $topic_id . ' ORDER BY `id` DESC LIMIT 2') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    list($last_id, $poster, ) = $db->fetch_row($result);
    list($second_last_id, $second_poster, $second_posted) = $db->fetch_row($result);
    // Delete the post
    $db->query('DELETE FROM `' . $db->prefix . 'posts` WHERE `id` = ' . $post_id) or error('Unable to delete post', __FILE__, __LINE__, $db->error());
    strip_search_index($post_id);
    include PUN_ROOT . 'lang/' . $pun_user['language'] . '/fileup.php';
    include_once PUN_ROOT . 'include/file_upload.php';
    delete_post_attachments($post_id);
    // Count number of replies in the topic
    $result = $db->query('SELECT COUNT(1) FROM `' . $db->prefix . 'posts` WHERE `topic_id`=' . $topic_id) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $db->error());
    $num_replies = $db->result($result, 0) - 1;
    // уменьшаем кол-во постов
    $db->query('UPDATE `' . $db->prefix . 'users` SET `num_posts` = `num_posts` - 1 WHERE `username` = "' . $db->escape($poster) . '" LIMIT 1');
    // If the message we deleted is the most recent in the topic (at the end of the topic)
    if ($last_id == $post_id) {
        // If there is a $second_last_id there is more than 1 reply to the topic
        if ($second_last_id) {
            $db->query('UPDATE `' . $db->prefix . 'topics` SET `last_post`=' . $second_posted . ', `last_post_id`=' . $second_last_id . ', `last_poster`=\'' . $db->escape($second_poster) . '\', `num_replies`=' . $num_replies . ' WHERE `id`=' . $topic_id) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
        } else {
            // We deleted the only reply, so now last_post/last_post_id/last_poster is posted/id/poster from the topic itself
            $db->query('UPDATE `' . $db->prefix . 'topics` SET `last_post`=posted, `last_post_id`=id, `last_poster`=poster, `num_replies`=' . $num_replies . ' WHERE `id`=' . $topic_id) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
        }
    } else {
        // Otherwise we just decrement the reply counter
        $db->query('UPDATE `' . $db->prefix . 'topics` SET `num_replies`=' . $num_replies . ' WHERE `id`=' . $topic_id) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
    }
}
Example #2
0
        // Delete any subscriptions
        $db->query('DELETE FROM ' . $db->prefix . 'subscriptions WHERE topic_id IN(' . $topics . ')') or error('Unable to delete subscriptions', __FILE__, __LINE__, $db->error());
        // Create a list of the post ID's in this topic and then strip the search index
        $result = $db->query('SELECT id FROM ' . $db->prefix . 'posts WHERE topic_id IN(' . $topics . ')') or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
        $post_ids = '';
        while ($row = $db->fetch_row($result)) {
            $post_ids .= $post_ids ? ',' . $row[0] : $row[0];
        }
        // We have to check that we actually have a list of post ID's since we could be deleting just a redirect topic
        if ($post_ids) {
            strip_search_index($post_ids);
        }
        // Delete attachments
        include PUN_ROOT . 'lang/' . $pun_user['language'] . '/fileup.php';
        include_once PUN_ROOT . 'include/file_upload.php';
        delete_post_attachments($post_ids);
        // Delete posts
        $db->query('DELETE FROM ' . $db->prefix . 'posts WHERE topic_id IN(' . $topics . ')') or error('Unable to delete posts', __FILE__, __LINE__, $db->error());
        update_forum($fid);
        redirect('viewforum.php?id=' . $fid, $lang_misc['Delete topics redirect']);
    }
    $page_title = pun_htmlspecialchars($pun_config['o_board_title']) . ' / ' . $lang_misc['Moderate'];
    require_once PUN_ROOT . 'header.php';
    echo '<div class="blockform">
<h2>' . $lang_misc['Delete topics'] . '</h2>
<div class="box">
<form method="post" action="moderate.php?fid=' . $fid . '">
<input type="hidden" name="topics" value="' . implode(',', array_map('intval', array_keys($topics))) . '" />
<div class="inform">
<fieldset>
<legend>' . $lang_misc['Confirm delete legend'] . '</legend>
Example #3
0
function prune($forum_id, $prune_sticky, $prune_date)
{
    global $db, $pun_user, $pun_config, $Poll;
    // for included files
    $extra_sql = $prune_date != -1 ? ' AND last_post<' . $prune_date : '';
    if (!$prune_sticky) {
        $extra_sql .= ' AND sticky=\'0\'';
    }
    // Fetch topics to prune
    $result = $db->query('SELECT `id` FROM `' . $db->prefix . 'topics` WHERE `forum_id`=' . $forum_id . $extra_sql) or error('Unable to fetch topics', __FILE__, __LINE__, $db->error());
    $topic_ids = null;
    while ($row = $db->fetch_row($result)) {
        $topic_ids .= ($topic_ids ? ',' : '') . $row[0];
    }
    if ($topic_ids) {
        // Fetch posts to prune
        $result = $db->query('SELECT `id` FROM `' . $db->prefix . 'posts` WHERE `topic_id` IN(' . $topic_ids . ')') or error('Unable to fetch posts', __FILE__, __LINE__, $db->error());
        $post_ids = null;
        while ($row = $db->fetch_row($result)) {
            $post_ids .= ($post_ids ? ',' : '') . $row[0];
        }
        if ($post_ids) {
            // hcs AJAX POLL MOD BEGIN
            include_once PUN_ROOT . 'include/poll/poll.inc.php';
            $Poll->deleteTopic($topic_ids);
            // hcs AJAX POLL MOD END
            // Delete topics
            $db->query('DELETE FROM ' . $db->prefix . 'topics WHERE id IN(' . $topic_ids . ')') or error('Unable to prune topics', __FILE__, __LINE__, $db->error());
            // Delete subscriptions
            $db->query('DELETE FROM ' . $db->prefix . 'subscriptions WHERE topic_id IN(' . $topic_ids . ')') or error('Unable to prune subscriptions', __FILE__, __LINE__, $db->error());
            // Delete posts
            $db->query('DELETE FROM ' . $db->prefix . 'posts WHERE id IN(' . $post_ids . ')') or error('Unable to prune posts', __FILE__, __LINE__, $db->error());
            // We removed a bunch of posts, so now we have to update the search index
            include_once PUN_ROOT . 'include/search_idx.php';
            strip_search_index($post_ids);
            // Delete attachments
            include PUN_ROOT . 'lang/' . $pun_user['language'] . '/fileup.php';
            include_once PUN_ROOT . 'include/file_upload.php';
            delete_post_attachments($post_ids);
        }
    }
}