function akismet_admin()
{
    global $mybb, $db, $page, $lang;
    if ($page->active_action != "akismet") {
        return;
    }
    $page->add_breadcrumb_item($lang->akismet);
    if ($mybb->input['delete_all'] && $mybb->request_method == "post") {
        // User clicked no
        if ($mybb->input['no']) {
            admin_redirect("index.php?module=forum-akismet");
        }
        if ($mybb->request_method == "post") {
            // Delete the template
            $db->delete_query("posts", "visible = '-4'");
            // Log admin action
            log_admin_action();
            flash_message($lang->success_deleted_spam, 'success');
            admin_redirect("index.php?module=forum-akismet");
        } else {
            $page->output_confirm_action("index.php?module=forum-akismet&delete_all=1", $lang->confirm_spam_deletion);
        }
    }
    if ($mybb->input['unmark'] && $mybb->request_method == "post") {
        $unmark = $mybb->input['akismet'];
        if (empty($unmark)) {
            flash_message($lang->error_unmark, 'error');
            admin_redirect("index.php?module=forum-akismet");
        }
        $posts_in = '';
        $comma = '';
        foreach ($unmark as $key => $val) {
            $posts_in .= $comma . intval($key);
            $comma = ',';
        }
        $query = $db->simple_select("posts", "pid, tid", "pid IN ({$posts_in}) AND replyto = '0'");
        while ($post = $db->fetch_array($query)) {
            $threadp[] = $post['tid'];
        }
        if (!is_array($threadp)) {
            $threadp = array();
        }
        $thread_list = implode(',', $threadp);
        $query = $db->query("\r\n\t\t\tSELECT p.tid, f.usepostcounts, p.uid, p.fid, p.dateline, p.replyto, t.lastpost, t.lastposter, t.lastposteruid, t.subject\r\n\t\t\tFROM " . TABLE_PREFIX . "posts p\r\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\r\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forums f ON (f.fid=p.fid)\r\n\t\t\tWHERE p.pid IN ({$posts_in}) AND p.visible = '-4'\r\n\t\t");
        while ($post = $db->fetch_array($query)) {
            // Fetch the last post for this forum
            $query2 = $db->query("\r\n\t\t\t\tSELECT tid, lastpost, lastposter, lastposteruid, subject\r\n\t\t\t\tFROM " . TABLE_PREFIX . "threads\r\n\t\t\t\tWHERE fid='{$post['fid']}' AND visible='1' AND closed NOT LIKE 'moved|%'\r\n\t\t\t\tORDER BY lastpost DESC\r\n\t\t\t\tLIMIT 0, 1\r\n\t\t\t");
            $lastpost = $db->fetch_array($query2);
            if ($post['lastpost'] > $lastpost['lastpost']) {
                $lastpost['lastpost'] = $post['lastpost'];
                $lastpost['lastposter'] = $post['lastposter'];
                $lastpost['lastposteruid'] = $post['lastposteruid'];
                $lastpost['subject'] = $post['subject'];
                $lastpost['tid'] = $post['tid'];
            }
            $update_count = array("lastpost" => intval($lastpost['lastpost']), "lastposter" => $db->escape_string($lastpost['lastposter']), "lastposteruid" => intval($lastpost['lastposteruid']), "lastposttid" => intval($lastpost['tid']), "lastpostsubject" => $db->escape_string($lastpost['subject']));
            $db->update_query("forums", $update_count, "fid='{$post['fid']}'");
            $query2 = $db->query("\r\n\t\t\t\tSELECT u.uid, u.username, p.username AS postusername, p.dateline\r\n\t\t\t\tFROM " . TABLE_PREFIX . "posts p\r\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=p.uid)\r\n\t\t\t\tWHERE p.tid='{$post['tid']}' AND p.visible='1' OR p.pid = '{$post['pid']}'\r\n\t\t\t\tORDER BY p.dateline DESC\r\n\t\t\t\tLIMIT 1");
            $lastpost = $db->fetch_array($query2);
            $query2 = $db->query("\r\n\t\t\t\tSELECT u.uid, u.username, p.username AS postusername, p.dateline\r\n\t\t\t\tFROM " . TABLE_PREFIX . "posts p\r\n\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "users u ON (u.uid=p.uid)\r\n\t\t\t\tWHERE p.tid='{$post['tid']}'\r\n\t\t\t\tORDER BY p.dateline ASC\r\n\t\t\t\tLIMIT 0,1\r\n\t\t\t");
            $firstpost = $db->fetch_array($query2);
            if (!$firstpost['username']) {
                $firstpost['username'] = $firstpost['postusername'];
            }
            if (!$lastpost['username']) {
                $lastpost['username'] = $lastpost['postusername'];
            }
            if (!$lastpost['dateline']) {
                $lastpost['username'] = $firstpost['username'];
                $lastpost['uid'] = $firstpost['uid'];
                $lastpost['dateline'] = $firstpost['dateline'];
            }
            $lastpost['username'] = $db->escape_string($lastpost['username']);
            $firstpost['username'] = $db->escape_string($firstpost['username']);
            $query2 = $db->simple_select("users", "akismetstopped", "uid='{$post['uid']}'");
            $akismetstopped = $db->fetch_field($query2, "akismetstopped") - 1;
            if ($akismetstopped < 0) {
                $akismetstopped = 0;
            }
            $db->update_query("users", array('akismetstopped' => $akismetstopped), "uid='{$post['uid']}'");
            $update_array = array('username' => $firstpost['username'], 'uid' => intval($firstpost['uid']), 'lastpost' => intval($lastpost['dateline']), 'lastposter' => $lastpost['username'], 'lastposteruid' => intval($lastpost['uid']));
            $db->update_query("threads", $update_array, "tid='{$post['tid']}'");
            if ($post['usepostcounts'] != 0) {
                $db->write_query("UPDATE " . TABLE_PREFIX . "users SET postnum=postnum+1 WHERE uid = '{$post['uid']}'");
            }
            $newthreads = $newreplies = 0;
            if ($post['replyto'] == 0) {
                ++$newthreads;
            } else {
                ++$newreplies;
            }
            update_thread_counters($post['tid'], array('replies' => '+' . $newreplies));
            update_forum_counters($post['fid'], array('threads' => '+' . $newthreads, 'posts' => '+1'));
        }
        $approve = array("visible" => 1);
        if ($thread_list) {
            $db->update_query("threads", $approve, "tid IN ({$thread_list})");
        }
        $db->update_query("posts", $approve, "pid IN ({$posts_in})");
        // Log admin action
        log_admin_action();
        flash_message($lang->success_unmarked, 'success');
        admin_redirect("index.php?module=forum-akismet");
    }
    if ($mybb->input['delete'] && $mybb->request_method == "post") {
        $deletepost = $mybb->input['akismet'];
        if (empty($deletepost)) {
            flash_message($lang->error_deletepost, 'error');
            admin_redirect("index.php?module=forum-akismet");
        }
        $posts_in = '';
        $comma = '';
        foreach ($deletepost as $key => $val) {
            $posts_in .= $comma . intval($key);
            $comma = ',';
        }
        $query = $db->simple_select("posts", "pid, tid", "pid IN ({$posts_in}) AND replyto = '0'");
        while ($post = $db->fetch_array($query)) {
            $threadp[$post['pid']] = $post['tid'];
        }
        if (!is_array($threadp)) {
            $threadp = array();
        }
        require_once MYBB_ROOT . "inc/functions_upload.php";
        foreach ($deletepost as $pid => $val) {
            if (array_key_exists($pid, $threadp)) {
                $db->delete_query("posts", "pid IN ({$posts_in})");
                $db->delete_query("attachments", "pid IN ({$posts_in})");
                // Get thread info
                $query = $db->simple_select("threads", "poll", "tid='" . $threadp[$pid] . "'");
                $poll = $db->fetch_field($query, 'poll');
                // Delete threads, redirects, favorites, polls, and poll votes
                $db->delete_query("threads", "tid='" . $threadp[$pid] . "'");
                $db->delete_query("threads", "closed='moved|" . $threadp[$pid] . "'");
                $db->delete_query("threadsubscriptions", "tid='" . $threadp[$pid] . "'");
                $db->delete_query("polls", "tid='" . $threadp[$pid] . "'");
                $db->delete_query("pollvotes", "pid='{$poll}'");
            }
            // Remove attachments
            remove_attachments($pid);
            // Delete the post
            $db->delete_query("posts", "pid='{$pid}'");
        }
        // Log admin action
        log_admin_action();
        flash_message($lang->success_spam_deleted, 'success');
        admin_redirect("index.php?module=forum-akismet");
    }
    if (!$mybb->input['action']) {
        require MYBB_ROOT . "inc/class_parser.php";
        $parser = new postParser();
        $page->output_header($lang->akismet);
        $form = new Form("index.php?module=forum-akismet", "post");
        $table = new Table();
        $table->construct_header($form->generate_check_box("checkall", 1, '', array('class' => 'checkall')), array('width' => '5%'));
        $table->construct_header("Title / Username / Post", array('class' => 'align_center'));
        $mybb->input['page'] = intval($mybb->input['page']);
        if ($mybb->input['page'] > 0) {
            $start = $mybb->input['page'] * 20;
        } else {
            $start = 0;
        }
        $query = $db->simple_select("posts", "COUNT(pid) as spam", "visible = '-4'");
        $total_rows = $db->fetch_field($query, 'spam');
        if ($start > $total_rows) {
            $start = $total_rows - 20;
        }
        if ($start < 0) {
            $start = 0;
        }
        $query = $db->simple_select("posts", "*", "visible = '-4'", array('limit_start' => $start, 'limit' => '20', 'order_by' => 'dateline', 'order_dir' => 'desc'));
        while ($post = $db->fetch_array($query)) {
            if ($post['uid'] != 0) {
                $username = "******"../" . str_replace("{uid}", $post['uid'], PROFILE_URL) . "\" target=\"_blank\">" . format_name($post['username'], $post['usergroup'], $post['displaygroup']) . "</a>";
            } else {
                $username = $post['username'];
            }
            $table->construct_cell($form->generate_check_box("akismet[{$post['pid']}]", 1, ''));
            $table->construct_cell("<span style=\"float: right;\">{$lang->username} {$username}</span> <span style=\"float: left;\">{$lang->title}: " . htmlspecialchars_uni($post['subject']) . " <strong>(" . my_date($mybb->settings['dateformat'], $post['dateline']) . ", " . my_date($mybb->settings['timeformat'], $post['dateline']) . ")</strong></span>");
            $table->construct_row();
            $parser_options = array("allow_html" => 0, "allow_mycode" => 0, "allow_smilies" => 0, "allow_imgcode" => 0, "me_username" => $post['username'], "filter_badwords" => 1);
            $post['message'] = $parser->parse_message($post['message'], $parser_options);
            $table->construct_cell($post['message'], array("colspan" => 2));
            $table->construct_row();
        }
        $num_rows = $table->num_rows();
        if ($num_rows == 0) {
            $table->construct_cell($lang->no_spam_found, array("class" => "align_center", "colspan" => 2));
            $table->construct_row();
        }
        $table->output($lang->detected_spam_messages);
        echo "<br />" . draw_admin_pagination($mybb->input['page'], 20, $total_rows, "index.php?module=forum-akismet&amp;page={page}");
        $buttons[] = $form->generate_submit_button($lang->unmark_selected, array('name' => 'unmark'));
        $buttons[] = $form->generate_submit_button($lang->deleted_selected, array('name' => 'delete'));
        if ($num_rows > 0) {
            $buttons[] = $form->generate_submit_button($lang->delete_all, array('name' => 'delete_all', 'onclick' => "return confirm('{$lang->confirm_spam_deletion}');"));
        }
        $form->output_submit_wrapper($buttons);
        $form->end();
        $page->output_footer();
    }
    exit;
}
예제 #2
0
/**
 * Provides a function to entirely delete a user's posts, and find the threads attached to them
 *
 * @param integer The uid of the user
 * @param int A UNIX timestamp to delete posts that are older
 * @return array An array of threads to delete, threads/forums to recount
 */
function delete_user_posts($uid, $date)
{
    global $db;
    $uid = (int) $uid;
    // Build an array of posts to delete
    $postcache = array();
    $query = $db->simple_select("posts", "pid", "uid = '" . $uid . "' AND dateline < '" . $date . "'");
    while ($post = $db->fetch_array($query)) {
        $postcache[] = $post['pid'];
    }
    if (!$db->num_rows($query)) {
        return false;
    } elseif (!empty($postcache)) {
        // Let's start deleting posts
        $user_posts = implode(",", $postcache);
        $query = $db->query("\n\t\t\tSELECT p.pid, p.visible, f.usepostcounts, t.tid AS thread, t.firstpost, t.fid AS forum\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forums f ON (f.fid=p.fid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tWHERE p.pid IN ({$user_posts})\n\t\t");
        $post_count = 0;
        // Collect the post number to deduct from the user's postcount
        $thread_list = array();
        $forum_list = array();
        $delete_thread_list = array();
        if (!$db->num_rows($query)) {
            return false;
        } else {
            while ($post = $db->fetch_array($query)) {
                if ($post['usepostcounts'] != 0 && $post['visible'] != 0) {
                    ++$post_count;
                }
                if ($post['pid'] == $post['firstpost']) {
                    $delete_thread_list[] = $post['thread'];
                }
                if (!in_array($post['thread'], $thread_list) && !in_array($post['thread'], $delete_thread_list)) {
                    $thread_list[] = $post['thread'];
                    // Threads that have been affected by this action, that aren't marked to be deleted
                }
                if (!in_array($post['forum'], $forum_list)) {
                    $forum_list[] = $post['forum'];
                    // Forums that have been affected, too
                }
                // Remove the attachments to this post, then delete the post
                remove_attachments($post['pid']);
                $db->delete_query("posts", "pid = '" . $post['pid'] . "'");
                $db->delete_query("pollvotes", "pid = '" . $post['pid'] . "'");
                // Delete pollvotes attached to this post
            }
            $db->update_query("users", array("postnum" => "postnum-" . $post_count . ""), "uid='" . $uid . "'", 1, true);
            $to_return = array('to_delete' => $delete_thread_list, 'thread_update' => $thread_list, 'forum_update' => $forum_list);
            return $to_return;
        }
    }
}
예제 #3
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     /* Check the request ID */
     if (!isset($_REQUEST['id']) || !$_REQUEST['id'] || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($_REQUEST['id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Make sure the we are trying to post into a forum */
     if (!($forum['row_type'] & FORUM)) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTMODNONFORUM'), 'content', FALSE);
         return $action->execute($request);
     }
     /**
      * Check for moderating permission
      */
     if (!is_moderator($request['user']->getInfoArray(), $forum)) {
         no_perms_error($request);
         return TRUE;
     }
     if (!isset($_REQUEST['action']) || $_REQUEST['action'] == '') {
         $action = new K4InformationAction(new K4LanguageElement('L_NEEDSELECTACTION'), 'content', TRUE);
         return $action->execute($request);
     }
     if (!isset($_REQUEST['topics']) || $_REQUEST['topics'] == '') {
         $action = new K4InformationAction(new K4LanguageElement('L_NEESSELECTTOPICS'), 'content', TRUE);
         return $action->execute($request);
     }
     $topics = explode("|", $_REQUEST['topics']);
     if (!is_array($topics) || count($topics) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_NEESSELECTTOPICS'), 'content', TRUE);
         return $action->execute($request);
     }
     $query_extra = '';
     $i = 0;
     foreach ($topics as $id) {
         $query_extra .= $i == 0 ? ' ' : ' OR ';
         $query_extra .= 'post_id = ' . intval($id);
         $query_reply_extra .= $i == 0 ? ' ' : ' OR ';
         $query_reply_extra .= 'parent_id=' . intval($id);
         $i++;
     }
     $request['template']->setVisibility('check_checkboxes', TRUE);
     switch ($_REQUEST['action']) {
         /**
          * Lock topics
          */
         case 'lock':
             if ($request['user']->get('perms') < get_map('closed', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET post_locked = 1 WHERE (" . $query_extra . ")");
             k4_bread_crumbs($request['template'], $request['dba'], 'L_LOCKTOPICS', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_LOCKEDTOPICS'), 'content', TRUE, referer(), 3);
             return $action->execute($request);
             break;
             /**
              * Stick topics
              */
         /**
          * Stick topics
          */
         case 'stick':
             if ($request['user']->get('perms') < get_map('sticky', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET post_type = " . TOPIC_STICKY . ", post_expire = 0 WHERE (" . $query_extra . ")");
             k4_bread_crumbs($request['template'], $request['dba'], 'L_STICKTOPICS', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_STUCKTOPICS'), 'content', TRUE, referer(), 3);
             return $action->execute($request);
             break;
             /**
              * Announce topics
              */
         /**
          * Announce topics
          */
         case 'announce':
             if ($request['user']->get('perms') < get_map('announce', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET post_type = " . TOPIC_ANNOUNCE . ", post_expire = 0 WHERE (" . $query_extra . ")");
             k4_bread_crumbs($request['template'], $request['dba'], 'L_ANNOUNCETOPICS', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_ANNOUNCEDTOPICS'), 'content', TRUE, referer(), 3);
             return $action->execute($request);
             break;
             /**
              * Feature topics
              */
         /**
          * Feature topics
          */
         case 'feature':
             if ($request['user']->get('perms') < get_map('feature', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET is_feature = 1, post_expire = 0 WHERE (" . $query_extra . ")");
             k4_bread_crumbs($request['template'], $request['dba'], 'L_FEATURETOPICS', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_FEATUREDTOPICS'), 'content', TRUE, referer(), 3);
             return $action->execute($request);
             break;
             /**
              * Remove any special formatting on topics
              */
         /**
          * Remove any special formatting on topics
          */
         case 'normal':
             if ($request['user']->get('perms') < get_map('normalize', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET is_feature = 0, display = 1, queue = 0, post_type = " . TOPIC_NORMAL . ", post_expire = 0, post_locked = 0 WHERE (" . $query_extra . ")");
             k4_bread_crumbs($request['template'], $request['dba'], 'L_SETASNORMALTOPICS', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_NORMALIZEDTOPICS'), 'content', TRUE, referer(), 3);
             return $action->execute($request);
             break;
             /**
              * Insert the topics into the moderator's queue for checking
              */
         /**
          * Insert the topics into the moderator's queue for checking
          */
         case 'queue':
             if ($request['user']->get('perms') < get_map('queue', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET queue = 1 WHERE (" . $query_extra . ")");
             k4_bread_crumbs($request['template'], $request['dba'], 'L_QUEUETOPICS', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_QUEUEDTOPICS'), 'content', TRUE, referer(), 3);
             return $action->execute($request);
             break;
             /**
              * Subscribe to all of the selected topics
              */
         /**
          * Subscribe to all of the selected topics
          */
         case 'subscribe':
             foreach ($topics as $post_id) {
                 $is_subscribed = $request['dba']->getRow("SELECT * FROM " . K4SUBSCRIPTIONS . " WHERE user_id = " . intval($request['user']->get('id')) . " AND post_id = " . intval($post_id));
                 if (!is_array($is_subscribed) || empty($is_subscribed)) {
                     $subscribe = $request['dba']->prepareStatement("INSERT INTO " . K4SUBSCRIPTIONS . " (user_id,user_name,post_id,forum_id,email,category_id) VALUES (?,?,?,?,?,?)");
                     $subscribe->setInt(1, $request['user']->get('id'));
                     $subscribe->setString(2, $request['user']->get('name'));
                     $subscribe->setInt(3, $post_id);
                     $subscribe->setInt(4, $forum['forum_id']);
                     $subscribe->setString(5, $request['user']->get('email'));
                     $subscribe->setInt(6, $forum['category_id']);
                     $subscribe->executeUpdate();
                 }
             }
             k4_bread_crumbs($request['template'], $request['dba'], 'L_SUBSCRIPTION', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_SUBSCRIBEDTOPICS'), 'content', TRUE, referer(), 3);
             return $action->execute($request);
             break;
             /**
              * Add selected topics to the queue to be deleted
              */
         /**
          * Add selected topics to the queue to be deleted
          */
         case 'delete':
             if ($request['user']->get('perms') < get_map('delete', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             $delete_topic = FALSE;
             if ($forum['forum_id'] == GARBAGE_BIN && $post['row_type'] & TOPIC) {
                 $delete_topic = TRUE;
             }
             $users = array();
             // find the users for topics first
             $t = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND ({$query_extra}) AND forum_id=" . intval($forum['forum_id']));
             while ($t->next()) {
                 $temp = $t->current();
                 $users[$temp['poster_id']] = isset($users[$temp['poster_id']]) ? $users[$temp['poster_id']] + 1 : 1;
                 // remove ratings
                 if ($temp['rating'] > 0 && $delete_topic) {
                     $request['dba']->executeUpdate("DELETE FROM " . K4RATINGS . " WHERE post_id = " . intval($temp['post_id']));
                 }
                 // remove attachments
                 if ($temp['attachments'] > 0 && $delete_topic) {
                     remove_attachments($request, $temp, FALSE);
                 }
                 // remove bad post reports
                 $request['dba']->executeUpdate("DELETE FROM " . K4BADPOSTREPORTS . " WHERE post_id = " . intval($temp['post_id']));
             }
             $num_topics = $t->numrows();
             $num_topics = $forum['topics'] < $num_topics ? $forum['topics'] : $num_topics;
             $t->free();
             // find them for replies
             $r = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE row_type=" . REPLY . " AND ({$query_reply_extra}) AND forum_id=" . intval($forum['forum_id']));
             while ($r->next()) {
                 $temp = $r->current();
                 $users[$temp['poster_id']] = isset($users[$temp['poster_id']]) ? $users[$temp['poster_id']] + 1 : 1;
                 // remove attachments
                 if ($temp['attachments'] > 0) {
                     remove_attachments($request, $temp, FALSE);
                 }
                 // remove bad post reports
                 $request['dba']->executeUpdate("DELETE FROM " . K4BADPOSTREPORTS . " WHERE post_id = " . intval($temp['post_id']));
             }
             $num_replies = $r->numrows();
             $num_replies = $forum['replies'] < $num_replies ? $forum['replies'] : $num_replies;
             $r->free();
             if ($delete_topic) {
                 // loop through the users and change their post counts
                 foreach ($users as $id => $postcount) {
                     $request['dba']->executeUpdate("UPDATE " . K4USERINFO . " SET num_posts = num_posts-{$postcount} WHERE user_id = {$id}");
                 }
                 // Remove everything
                 $request['dba']->executeUpdate("DELETE FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND (" . $query_extra . ")");
                 $request['dba']->executeUpdate("DELETE FROM " . K4POSTS . " WHERE row_type=" . REPLY . " AND (" . $query_reply_extra . ")");
             } else {
                 // Move everything
                 $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET forum_id=" . GARBAGE_BIN . " WHERE row_type=" . TOPIC . " AND (" . $query_extra . ")");
                 $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET forum_id=" . GARBAGE_BIN . " WHERE row_type=" . REPLY . " AND (" . $query_reply_extra . ")");
             }
             /* Get that last post in this forum that's not part of/from one of these topics */
             $no_post = array('created' => 0, 'name' => '', 'poster_name' => '', 'post_id' => 0, 'poster_id' => 0, 'posticon' => '');
             $lastpost_created = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE (" . str_replace('=', '<>', $query_extra) . ") AND forum_id=" . intval($forum['forum_id']) . " ORDER BY created DESC LIMIT 1");
             $lastpost_created = !$lastpost_created || !is_array($lastpost_created) || empty($lastpost_created) ? $no_post : $lastpost_created;
             /**
              * Update the forum and the datastore
              */
             $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET topics=topics-?,posts=posts-?,replies=replies-?,post_id=?,post_created=?,post_name=?,post_uname=?,post_uid=?,post_posticon=? WHERE forum_id=?");
             $datastore_update = $request['dba']->prepareStatement("UPDATE " . K4DATASTORE . " SET data=? WHERE varname=?");
             /* Set the forum values */
             $forum_update->setInt(1, $num_topics);
             $forum_update->setInt(2, $num_replies + $num_topics);
             $forum_update->setInt(3, $num_replies);
             $forum_update->setInt(4, $lastpost_created['post_id']);
             $forum_update->setInt(5, $lastpost_created['created']);
             $forum_update->setString(6, $lastpost_created['name']);
             $forum_update->setString(7, $lastpost_created['poster_name']);
             $forum_update->setInt(8, $lastpost_created['poster_id']);
             $forum_update->setString(9, $lastpost_created['posticon']);
             $forum_update->setInt(10, $forum['forum_id']);
             /* Execute the forum and datastore update queries */
             $forum_update->executeUpdate();
             if (!$delete_topic) {
                 // update the garbage bin forum
                 $newpost_created = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE forum_id=" . GARBAGE_BIN . " ORDER BY created DESC LIMIT 1");
                 $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET posts=posts+?,replies=replies+?,topics=topics+?,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? WHERE forum_id=?");
                 $forum_update->setInt(1, $num_replies + $num_topics);
                 $forum_update->setInt(2, $num_replies);
                 $forum_update->setInt(3, $num_topics);
                 $forum_update->setInt(4, $newpost_created['created']);
                 $forum_update->setString(5, $newpost_created['name']);
                 $forum_update->setString(6, $newpost_created['poster_name']);
                 $forum_update->setInt(7, $newpost_created['post_id']);
                 $forum_update->setInt(8, $newpost_created['poster_id']);
                 $forum_update->setString(9, $newpost_created['posticon']);
                 $forum_update->setInt(10, GARBAGE_BIN);
                 $forum_update->executeUpdate();
             } else {
                 // update the datastore
                 $datastore = $_DATASTORE['forumstats'];
                 $datastore['num_topics'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE is_draft = 0 AND queue = 0 AND display = 1 AND row_type=" . TOPIC);
                 $datastore['num_replies'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . REPLY);
                 $datastore_update->setString(1, serialize($datastore));
                 $datastore_update->setString(2, 'forumstats');
                 $datastore_update->executeUpdate();
             }
             reset_cache('datastore');
             k4_bread_crumbs($request['template'], $request['dba'], 'L_DELETETOPICS', $forum);
             $action = new K4InformationAction(new K4LanguageElement('L_DELETEDTOPICS'), 'content', TRUE, referer(), 5);
             return $action->execute($request);
             break;
             /**
              * Move/copy topics to a destination forum
              */
         /**
          * Move/copy topics to a destination forum
          */
         case 'move':
             if ($request['user']->get('perms') < get_map('move', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 no_perms_error($request);
                 return TRUE;
             }
             if (count($topics) <= 0) {
                 k4_bread_crumbs($request['template'], $request['dba'], 'L_MOVETOPICS', $forum);
                 $action = new K4InformationAction(new K4LanguageElement('L_NEEDSELECTTOPIC'), 'content', FALSE);
                 return $action->execute($request);
             }
             /* Get the topics */
             $result = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND is_draft=0 AND queue = 0 AND display = 1 AND forum_id = " . intval($forum['forum_id']) . " AND (" . $query_extra . ") ORDER BY created DESC");
             /* Apply the topics iterator */
             $it =& new TopicsIterator($request['dba'], $request['user'], $result, $request['template']->getVar('IMG_DIR'), $forum);
             $request['template']->setList('topics', $it);
             $request['template']->setVar('topics', $_REQUEST['topics']);
             $request['template']->setVar('forum_id', $forum['forum_id']);
             $request['template']->setVar('modpanel', 1);
             k4_bread_crumbs($request['template'], $request['dba'], 'L_MOVETOPICS', $forum);
             $request['template']->setFile('content', 'move_topics.html');
             break;
             /* Invalid action has been taken */
         /* Invalid action has been taken */
         default:
             k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
             $action = new K4InformationAction(new K4LanguageElement('L_NEEDSELECTACTION'), 'content', FALSE);
             return $action->execute($request);
             break;
     }
     return TRUE;
 }
예제 #4
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_USERGROUPS;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     if (!isset($_REQUEST['id']) || !$_REQUEST['id'] || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Get our topic */
     $topic = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['id']));
     if (!$topic || !is_array($topic) || empty($topic)) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($topic['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Make sure the we are trying to delete from a forum */
     if (!($forum['row_type'] & FORUM)) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTDELFROMNONFORUM'), 'content', FALSE);
         return $action->execute($request);
     }
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_DELETETOPIC', $forum);
     /* Are we dealing with a topic or a poll? */
     $type = $topic['is_poll'] == 1 ? 'polls' : 'topics';
     /* Does this person have permission to remove this topic? */
     if ($topic['poster_id'] == $request['user']->get('id')) {
         if (get_map($type, 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             no_perms_error($request);
             return TRUE;
         }
     } else {
         if (get_map('other_' . $type, 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             no_perms_error($request);
             return TRUE;
         }
     }
     if (!is_moderator($request['user']->getInfoArray(), $forum)) {
         no_perms_error($request);
         return TRUE;
     }
     /**
      * Remove the topic and all of its replies
      */
     /* Remove the topic and all replies from the information table */
     remove_item($topic['post_id'], 'post_id');
     // delete this topics attachments
     remove_attachments($request, $topic);
     // delete any possible moved topic redirectors
     $request['dba']->executeUpdate("DELETE FROM " . K4POSTS . " WHERE moved_new_post_id = " . intval($topic['post_id']));
     reset_cache('datastore');
     reset_cache('email_queue');
     /* Redirect the user */
     $action = new K4InformationAction(new K4LanguageElement('L_DELETEDTOPIC', $topic['name'], $forum['name']), 'content', FALSE, 'viewforum.php?f=' . $forum['forum_id'], 3);
     return $action->execute($request);
 }
예제 #5
0
 /**
  * Delete a specific post
  *
  * @param int $pid Post ID
  * @return boolean
  */
 function delete_post($pid)
 {
     global $db, $cache, $plugins;
     $pid = $plugins->run_hooks("class_moderation_delete_post_start", $pid);
     // Get pid, uid, fid, tid, visibility, forum post count status of post
     $pid = (int) $pid;
     $query = $db->query("\n\t\t\tSELECT p.pid, p.uid, p.fid, p.tid, p.visible, t.visible as threadvisible\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tWHERE p.pid='{$pid}'\n\t\t");
     $post = $db->fetch_array($query);
     if (!$post) {
         return false;
     }
     $forum = get_forum($post['fid']);
     // If post counts enabled in this forum and it hasn't already been unapproved, remove 1
     if ($forum['usepostcounts'] != 0 && $post['visible'] != -1 && $post['visible'] != 0 && $post['threadvisible'] != 0 && $post['threadvisible'] != -1) {
         update_user_counters($post['uid'], array('postnum' => "-1"));
     }
     if (!function_exists("remove_attachments")) {
         require MYBB_ROOT . "inc/functions_upload.php";
     }
     // Remove attachments
     remove_attachments($pid);
     // Delete the post
     $db->delete_query("posts", "pid='{$pid}'");
     // Remove any reports attached to this post
     $db->delete_query("reportedcontent", "id='{$pid}' AND (type = 'post' OR type = '')");
     // Update unapproved post count
     if ($post['visible'] == 0) {
         $update_array = array("unapprovedposts" => "-1");
     } elseif ($post['visible'] == -1) {
         $update_array = array("deletedposts" => "-1");
     } else {
         $update_array = array("replies" => "-1");
     }
     $plugins->run_hooks("class_moderation_delete_post", $post['pid']);
     update_thread_counters($post['tid'], $update_array);
     update_last_post($post['tid']);
     // Update unapproved post count
     if ($post['visible'] == 0 && $post['threadvisible'] != -1 || $post['threadvisible'] == 0) {
         $update_array = array("unapprovedposts" => "-1");
     } elseif ($post['visible'] == -1 || $post['threadvisible'] == -1) {
         $update_array = array("deletedposts" => "-1");
     } else {
         $update_array = array("posts" => "-1");
     }
     update_forum_counters($post['fid'], $update_array);
     update_forum_lastpost($post['fid']);
     return true;
 }
예제 #6
0
 /**
  * Delete a specific post
  *
  * @param int Post ID
  * @return boolean true
  */
 function delete_post($pid)
 {
     global $db, $cache, $plugins;
     $pid = $plugins->run_hooks("class_moderation_delete_post_start", $pid);
     // Get pid, uid, fid, tid, visibility, forum post count status of post
     $pid = intval($pid);
     $query = $db->query("\n\t\t\tSELECT p.pid, p.uid, p.fid, p.tid, p.visible, f.usepostcounts, t.visible as threadvisible\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid=p.tid)\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forums f ON (f.fid=p.fid)\n\t\t\tWHERE p.pid='{$pid}'\n\t\t");
     $post = $db->fetch_array($query);
     // If post counts enabled in this forum and it hasn't already been unapproved, remove 1
     if ($post['usepostcounts'] != 0 && $post['visible'] != 0 && $post['threadvisible'] != 0) {
         $db->update_query("users", array("postnum" => "postnum-1"), "uid='{$post['uid']}'", 1, true);
     }
     if (!function_exists("remove_attachments")) {
         require MYBB_ROOT . "inc/functions_upload.php";
     }
     // Remove attachments
     remove_attachments($pid);
     // Delete the post
     $db->delete_query("posts", "pid='{$pid}'");
     // Remove any reports attached to this post
     $db->delete_query("reportedposts", "pid='{$pid}'");
     $num_unapproved_posts = $num_approved_posts = 0;
     // Update unapproved post count
     if ($post['visible'] == 0 || $post['threadvisible'] == 0) {
         ++$num_unapproved_posts;
     } else {
         ++$num_approved_posts;
     }
     $plugins->run_hooks("class_moderation_delete_post", $post['pid']);
     // Update stats
     $update_array = array("replies" => "-{$num_approved_posts}", "unapprovedposts" => "-{$num_unapproved_posts}");
     update_thread_counters($post['tid'], $update_array);
     // Update stats
     $update_array = array("posts" => "-{$num_approved_posts}", "unapprovedposts" => "-{$num_unapproved_posts}");
     update_forum_counters($post['fid'], $update_array);
     return true;
 }
예제 #7
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_USERGROUPS;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     if (!isset($_REQUEST['id']) || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Get our topic */
     $post = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['id']));
     if (!$post || !is_array($post) || empty($post)) {
         $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($post['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $delete_topic = FALSE;
     if ($forum['forum_id'] == GARBAGE_BIN && $this->row_type & TOPIC) {
         $delete_topic = TRUE;
     }
     /* Make sure the we are trying to delete from a forum */
     if (!($forum['row_type'] & FORUM)) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTDELFROMNONFORUM'), 'content', FALSE);
         return $action->execute($request);
     }
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], $this->row_type & REPLY ? 'L_DELETEREPLY' : 'L_DELETETOPIC', $post, $forum);
     $maps_var = $this->row_type & TOPIC ? 'topics' : 'replies';
     /* Does this person have permission to remove this post? */
     if ($post['poster_id'] == $request['user']->get('id')) {
         if (get_map($maps_var, 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             no_perms_error($request);
             return TRUE;
         }
     } else {
         if (get_map('other_' . $maps_var, 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             no_perms_error($request);
             return TRUE;
         }
     }
     $user_usergroups = $request['user']->get('usergroups') != '' ? explode('|', $request['user']->get('usergroups')) : array();
     $forum_usergroups = $forum['moderating_groups'] != '' ? explode('|', $forum['moderating_groups']) : array();
     if (!is_moderator($request['user']->getInfoArray(), $forum)) {
         no_perms_error($request);
         return TRUE;
     }
     /* Begin the SQL transaction */
     $request['dba']->beginTransaction();
     /**
      * Should we update the topic?
      */
     if ($this->row_type & REPLY) {
         $topic_last_reply = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id <> " . intval($post['post_id']) . " AND parent_id=" . intval($post['parent_id']) . " ORDER BY created DESC LIMIT 1");
         $topic_update = $request['dba']->prepareStatement("UPDATE " . K4POSTS . " SET lastpost_created=?,lastpost_uname=?,lastpost_uid=?,lastpost_id=?,num_replies=? WHERE post_id=?");
         $topic_update->setInt(1, $topic_last_reply['created']);
         $topic_update->setString(2, $topic_last_reply['poster_name']);
         $topic_update->setInt(3, $topic_last_reply['poster_id']);
         $topic_update->setInt(4, $topic_last_reply['post_id']);
         $topic_update->setInt(5, intval($request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE parent_id=" . intval($post['parent_id'])) - 1));
         // use this to make sure we get the right count
         $topic_update->setInt(6, $post['parent_id']);
         $topic_update->executeUpdate();
     }
     /**
      * Remove any bad post reports, get a count of replies, change
      * user post counts and remove attachments! WOAH!
      */
     $num_replies_to_remove = 1;
     if ($this->row_type & REPLY) {
         $request['dba']->executeUpdate("DELETE FROM " . K4BADPOSTREPORTS . " WHERE post_id = " . intval($post['post_id']));
     } else {
         $posts = $request['dba']->executeQuery("SELECT post_id,poster_id,attachments FROM " . K4POSTS . " WHERE ( (parent_id=" . intval($post['post_id']) . " AND row_type=" . REPLY . ") OR (post_id=" . intval($post['post_id']) . " AND row_type=" . TOPIC . ") )");
         $num_replies_to_remove = intval($posts->numrows() - 1);
         while ($posts->next()) {
             $p = $posts->current();
             // remove bad post report
             $request['dba']->executeUpdate("DELETE FROM " . K4BADPOSTREPORTS . " WHERE post_id = " . intval($p['post_id']));
             // change user post count
             if ($delete_topic || $this->row_type & REPLY) {
                 $request['dba']->executeUpdate("UPDATE " . K4USERINFO . " SET num_posts=num_posts-1 WHERE user_id=" . intval($p['poster_id']));
             }
             if ($p['attachments'] > 0) {
                 remove_attachments($request, $p, FALSE);
             }
         }
     }
     /**
      * Delete/Move the post 
      */
     if ($delete_topic || $this->row_type & REPLY) {
         $request['dba']->executeUpdate("DELETE FROM " . K4POSTS . " WHERE post_id = " . intval($post['post_id']));
         // change or remove replies
         if ($this->row_type & REPLY) {
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET row_order=row_order-1 WHERE row_order>" . intval($post['row_order']) . " AND post_id=" . intval($post['forum_id']));
         } else {
             $request['dba']->executeUpdate("DELETE FROM " . K4POSTS . " WHERE parent_id=" . intval($post['post_id']));
             $request['dba']->executeUpdate("DELETE FROM " . K4RATINGS . " WHERE post_id = " . intval($post['post_id']));
         }
     } else {
         /* Move this topic and its replies to the garbage bin */
         if ($this->row_type & TOPIC) {
             // parent_id is left as the current forum id
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET forum_id=" . GARBAGE_BIN . " WHERE ( (parent_id=" . intval($post['post_id']) . " AND row_type=" . REPLY . ") OR post_id=" . intval($post['post_id']) . ")");
             // update the garbage bin
             $newpost_created = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE forum_id=" . GARBAGE_BIN . " ORDER BY created DESC LIMIT 1");
             $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET posts=posts+?,replies=replies+?,topics=topics+?,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? WHERE forum_id=?");
             $forum_update->setInt(1, $this->row_type & REPLY ? $num_replies_to_remove : $num_replies_to_remove + 1);
             $forum_update->setInt(2, $num_replies_to_remove);
             $forum_update->setInt(3, $this->row_type & REPLY ? 0 : 1);
             $forum_update->setInt(4, $newpost_created['created']);
             $forum_update->setString(5, $newpost_created['name']);
             $forum_update->setString(6, $newpost_created['poster_name']);
             $forum_update->setInt(7, $newpost_created['post_id']);
             $forum_update->setInt(8, $newpost_created['poster_id']);
             $forum_update->setString(9, $newpost_created['posticon']);
             $forum_update->setInt(10, GARBAGE_BIN);
             $forum_update->executeUpdate();
         }
     }
     /* Get that last post in this forum that's not part of/from this topic */
     $lastpost_created = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE forum_id=" . intval($post['forum_id']) . " ORDER BY created DESC LIMIT 1");
     if (!is_array($lastpost_created) || empty($lastpost_created)) {
         $lastpost_created = array('created' => 0, 'name' => '', 'poster_name' => '', 'post_id' => 0, 'poster_id' => 0, 'posticon' => '');
     }
     /**
      * Update the forum and the datastore
      */
     $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET posts=posts-?,replies=replies-?,topics=topics-?,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? WHERE forum_id=?");
     /* Set the forum values */
     $forum_update->setInt(1, $this->row_type & REPLY ? $num_replies_to_remove : $num_replies_to_remove + 1);
     $forum_update->setInt(2, $num_replies_to_remove);
     $forum_update->setInt(3, $this->row_type & REPLY ? 0 : 1);
     $forum_update->setInt(4, $lastpost_created['created']);
     $forum_update->setString(5, $lastpost_created['name']);
     $forum_update->setString(6, $lastpost_created['poster_name']);
     $forum_update->setInt(7, $lastpost_created['post_id']);
     $forum_update->setInt(8, $lastpost_created['poster_id']);
     $forum_update->setString(9, $lastpost_created['posticon']);
     $forum_update->setInt(10, $forum['forum_id']);
     $forum_update->executeUpdate();
     /* Set the datastore values */
     if ($delete_topic || $this->row_type & REPLY) {
         $datastore_update = $request['dba']->prepareStatement("UPDATE " . K4DATASTORE . " SET data=? WHERE varname=?");
         $datastore = $_DATASTORE['forumstats'];
         $datastore['num_replies'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . REPLY);
         $datastore['num_topics'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . TOPIC);
         $datastore_update->setString(1, serialize($datastore));
         $datastore_update->setString(2, 'forumstats');
         /* Execute datastore update query */
         $datastore_update->executeUpdate();
         // Update the datastore cache
         reset_cache('datastore');
     }
     $request['dba']->commitTransaction();
     /* Redirect the user */
     $action = new K4InformationAction(new K4LanguageElement($this->row_type & REPLY ? 'L_DELETEDREPLY' : 'L_DELETEDTOPIC', $post['name']), 'content', FALSE, $this->row_type & REPLY ? 'viewtopic.php?id=' . $post['parent_id'] : 'viewforum.php?f=' . $post['forum_id'], 3);
     return $action->execute($request);
 }
예제 #8
0
 /**
  * Delete a specific post
  *
  * @param int Post ID
  * @return boolean true
  */
 function delete_post($pid)
 {
     global $db, $cache, $plugins;
     $plugins->run_hooks_by_ref("class_moderation_delete_post_start", $pid);
     // Get pid, uid, fid, tid, visibility, forum post count status of post
     $pid = intval($pid);
     $query = $db->query("\n\t\t\tSELECT p.pid, p.uid, p.fid, p.tid, p.visible, f.usepostcounts\n\t\t\tFROM " . TABLE_PREFIX . "posts p\n\t\t\tLEFT JOIN " . TABLE_PREFIX . "forums f ON (f.fid=p.fid)\n\t\t\tWHERE p.pid='{$pid}'\n\t\t");
     $post = $db->fetch_array($query);
     // If post counts enabled in this forum and it hasn't already been unapproved, remove 1
     if ($post['usepostcounts'] != 0 && $post['visible'] != 0) {
         $db->write_query("UPDATE " . TABLE_PREFIX . "users SET postnum=postnum-1 WHERE uid='" . $post['uid'] . "'");
     }
     // Remove attachments
     remove_attachments($pid);
     // Delete the post
     $db->delete_query("posts", "pid='{$pid}'");
     // Remove any reports attached to this post
     $db->delete_query("reportedposts", "pid='{$pid}'");
     $num_unapproved_posts = $num_approved_posts = 0;
     // Update unapproved post count
     if ($post['visible'] == 0) {
         ++$num_unapproved_posts;
     } else {
         ++$num_approved_posts;
     }
     $plugins->run_hooks("class_moderation_delete_post", $post['pid']);
     // Update stats
     $update_array = array("replies" => "-{$num_approved_posts}", "unapprovedposts" => "-{$num_unapproved_posts}");
     update_thread_counters($post['tid'], $update_array);
     // Update stats
     $update_array = array("posts" => "-{$num_approved_posts}", "unapprovedposts" => "-{$num_unapproved_posts}");
     update_forum_counters($post['fid'], $update_array);
     return true;
 }