Example #1
0
function sp_unapprove_post($postid = 0, $show = true)
{
    global $spVars, $spThisUser;
    if ($postid == 0) {
        return;
    }
    if (!sp_get_auth('moderate_posts', $spVars['forumid'])) {
        if ($show) {
            if (!is_user_logged_in()) {
                $msg = sp_text('Access denied - are you logged in?');
            } else {
                $msg = sp_text('Access denied - you do not have permission');
            }
            sp_notify(SPFAILURE, $msg);
        }
        return;
    }
    $success = spdb_query('UPDATE ' . SFPOSTS . " SET post_status=1 WHERE post_id={$postid}");
    if ($success == false) {
        if ($show) {
            sp_notify(SPFAILURE, sp_text('Post unapproval failed'));
        }
    } else {
        if ($show) {
            sp_notify(SPSUCCESS, sp_text('Post unapproved'));
        }
        # add to waiting list
        $post = spdb_select('row', 'SELECT * FROM ' . SFPOSTS . " WHERE post_id={$postid}");
        $topic = spdb_select('row', 'SELECT * FROM ' . SFTOPICS . " WHERE topic_id={$post->topic_id}");
        sp_add_to_waiting($post->topic_id, $post->forum_id, $post->post_id, $post->user_id);
        $nData = array();
        $nData['user_id'] = $post->user_id;
        $nData['guest_email'] = isset($post->guestemail) ? $post->guestemail : '';
        $nData['post_id'] = $post->post_id;
        $nData['link'] = sp_permalink_from_postid($post->post_id);
        $nData['link_text'] = $topic->topic_name;
        $nData['message'] = sp_text('Your post is awaiting moderation in the topic');
        $nData['expires'] = time() + 30 * 24 * 60 * 60;
        # 30 days; 24 hours; 60 mins; 60secs
        sp_add_notice($nData);
        # flush and rebuild topic cache
        sp_rebuild_topic_cache();
        sp_build_post_index($post->topic_id);
        sp_build_forum_index($post->forum_id);
        do_action('sph_post_unapproved', $post->post_id, $spThisUser->ID);
    }
}
function sp_determine_page($forumslug, $topicslug, $postid, $postindex)
{
    global $spGlobals;
    # establish paging count - can sometimes be out of scope so check
    $ppaged = $spGlobals['display']['posts']['perpage'];
    if (empty($ppaged) || $ppaged == 0) {
        $ppaged = 20;
    }
    # establish topic sort order
    $order = 'ASC';
    # default
    if ($spGlobals['display']['posts']['sortdesc']) {
        $order = 'DESC';
    }
    # global override
    # If we do not have the postindex then we have to go and get it
    if ($postindex == 0 || empty($postindex)) {
        $postindex = spdb_table(SFPOSTS, "post_id={$postid}", 'post_index');
        # In the remote possibility postindex is 0 or empty then...
        if ($postindex == 0 || empty($postindex)) {
            $forumrecord = spdb_table(SFFORUMS, "forum_slug='{$forumslug}'", 'row');
            $topicrecord = spdb_table(SFTOPICS, "topic_slug='{$topicslug}'", 'row');
            sp_build_post_index($topicrecord->topic_id);
            sp_build_forum_index($forumrecord->forum_id);
            $postindex = spdb_table(SFPOSTS, "post_id={$postid}", 'post_index');
        }
    }
    # Now we have what we need to do the math
    if ($order == 'ASC') {
        $page = $postindex / $ppaged;
        if (!is_int($page)) {
            $page = intval($page + 1);
        }
    } else {
        if (!isset($topicrecord)) {
            $topicrecord = spdb_table(SFTOPICS, "topic_slug='{$topicslug}'", 'row');
        }
        $page = $topicrecord->post_count - $postindex;
        $page = $page / $ppaged;
        $page = intval($page + 1);
    }
    return $page;
}
function sp_render_forum($content)
{
    global $spIsForum, $spContentLoaded, $spVars, $spGlobals, $spThisUser, $spStatus;
    # make sure we are at least in the html body before outputting any content
    if (!sp_get_option('sfwpheadbypass') && !did_action('wp_head')) {
        return '';
    }
    if ($spIsForum && !post_password_required(get_post(sp_get_option('sfpage')))) {
        # Limit forum display to within the wp loop?
        if (sp_get_option('sfinloop') && !in_the_loop()) {
            return $content;
        }
        # Has forum content already been loaded and are we limiting?
        if (!sp_get_option('sfmultiplecontent') && $spContentLoaded) {
            return $content;
        }
        $spContentLoaded = true;
        sp_set_server_timezone();
        # offer a way for forum display to be short circuited but always show for admins unless an upgrade
        $message = sp_abort_display_forum();
        $content .= $message;
        if (!empty($message) && (!$spThisUser->admin || $spStatus != 'ok')) {
            return $content;
        }
        # process query arg actions
        # check for edit operation. Need tp check for '_x' in case using mobile as buttin is an image
        if (isset($_POST['editpost']) || isset($_POST['editpost_x'])) {
            sp_save_edited_post();
        }
        if (isset($_POST['edittopic'])) {
            sp_save_edited_topic();
        }
        if (isset($_POST['ordertopicpins'])) {
            sp_promote_pinned_topic();
        }
        if (isset($_POST['makepostreassign'])) {
            sp_reassign_post();
        }
        if (isset($_POST['approvepost'])) {
            sp_approve_post(false, sp_esc_int($_POST['approvepost']), $spVars['topicid']);
        }
        if (isset($_POST['unapprovepost'])) {
            sp_unapprove_post(sp_esc_int($_POST['unapprovepost']));
        }
        if (isset($_POST['doqueue'])) {
            sp_remove_waiting_queue();
        }
        if (isset($_POST['notifyuser'])) {
            sp_post_notification(sp_esc_str($_POST['sp_notify_user']), sp_esc_str($_POST['message']), sp_esc_int($_POST['postid']));
        }
        # move a topic and redirect to that topic
        if (isset($_POST['maketopicmove'])) {
            if (empty($_POST['forumid'])) {
                sp_notify(1, sp_text('Destination forum not selected'));
                return;
            }
            sp_move_topic();
            $forumslug = spdb_table(SFFORUMS, 'forum_id=' . sp_esc_int(sp_esc_int($_POST['forumid'])), 'forum_slug');
            $topicslug = spdb_table(SFTOPICS, 'topic_id=' . sp_esc_int(sp_esc_int($_POST['currenttopicid'])), 'topic_slug');
            $returnURL = sp_build_url($forumslug, $topicslug, 0);
            sp_redirect($returnURL);
        }
        # move a post and redirect to the post
        if (isset($_POST['makepostmove1']) || isset($_POST['makepostmove2']) || isset($_POST['makepostmove3'])) {
            sp_move_post();
            if (isset($_POST['makepostmove1'])) {
                $returnURL = sp_permalink_from_postid(sp_esc_int($_POST['postid']));
                sp_redirect($returnURL);
            }
        }
        # cancel a post move
        if (isset($_POST['cancelpostmove'])) {
            $meta = sp_get_sfmeta('post_move', 'post_move');
            if ($meta) {
                $id = $meta[0]['meta_id'];
                sp_delete_sfmeta($id);
                unset($spGlobals['post_move']);
            }
        }
        # rebuild the forum and post indexes
        if (isset($_POST['rebuildforum']) || isset($_POST['rebuildtopic'])) {
            sp_build_post_index(sp_esc_int($_POST['topicid']), true);
            sp_build_forum_index(sp_esc_int($_POST['forumid']), false);
        }
        # Set display mode if topic view (for editing posts)
        if ($spVars['pageview'] == 'topic' && isset($_POST['postedit'])) {
            $spVars['displaymode'] = 'edit';
            $spVars['postedit'] = $_POST['postedit'];
        } else {
            $spVars['displaymode'] = 'posts';
        }
        # clean cache of timed our records
        sp_clean_cache();
        #--Scratch Pad Area---Please Leave Here---------
        #--End Scratch Pad Area-------------------------
        # let other plugins check for posted actions
        do_action('sph_setup_forum');
        # do we use output buffering?
        $ob = sp_get_option('sfuseob');
        if ($ob) {
            ob_start();
        }
        # set up some stuff before wp page content
        $content .= sp_display_banner();
        $content = apply_filters('sph_before_wp_page_content', $content);
        # run any other wp filters on page content but exclude ours
        if (!$ob) {
            remove_filter('the_content', 'sp_render_forum', 1);
            $content = apply_filters('the_content', $content);
            $content = wpautop($content);
            add_filter('the_content', 'sp_render_forum', 1);
        }
        # set up some stuff after wp page content
        $content = apply_filters('sph_after_wp_page_content', $content);
        $content .= '<div id="dialogcontainer" style="display:none;"></div>';
        $content .= sp_js_check();
        # echo any wp page content
        echo $content;
        # now add our content
        do_action('sph_before_template_processing');
        sp_process_template();
        do_action('sph_after_template_processing');
        # Return if using output buffering
        if ($ob) {
            $forum = ob_get_contents();
            ob_end_clean();
            return $forum;
        }
    }
    # not returning any content since we output it already unless password needed
    if (post_password_required(get_post(sp_get_option('sfpage')))) {
        return $content;
    }
}
 function saveData()
 {
     global $spVars, $spGlobals;
     $this->abort = false;
     $this->newpost['action'] = $this->action;
     # make the entire class object available for modification before saving
     # warning:  note the passing by reference.  other end could wreak havoc
     do_action_ref_array('sph_new_post_pre_save', array(&$this));
     # Write the topic if needed
     if ($this->action == 'topic') {
         $this->newpost = apply_filters('sph_new_topic_pre_data_saved', $this->newpost);
         $spdb = new spdbComplex();
         $spdb->table = SFTOPICS;
         $spdb->fields = array('topic_name', 'topic_slug', 'topic_date', 'forum_id', 'topic_status', 'topic_pinned', 'user_id');
         $spdb->data = array($this->newpost['topicname'], $this->newpost['topicslug'], $this->newpost['postdate'], $this->newpost['forumid'], $this->newpost['topicstatus'], $this->newpost['topicpinned'], $this->newpost['userid']);
         $spdb = apply_filters('sph_new_topic_data', $spdb);
         $this->newpost['db'] = $spdb->insert();
         if ($this->newpost['db'] == true) {
             $this->newpost['topicid'] = $spVars['insertid'];
             $this->newpost = apply_filters('sph_new_topic_data_saved', $this->newpost);
         } else {
             $this->abort = true;
             $this->message = sp_text('Unable to save new topic record');
             return;
         }
         # failsafe: check the topic slug and if empty use the topic id
         if (empty($this->newpost['topicslug'])) {
             $this->newpost['topicslug'] = 'topic-' . $this->newpost['topicid'];
             spdb_query('UPDATE ' . SFTOPICS . " SET topic_slug='" . $this->newpost['topicslug'] . "' WHERE topic_id=" . $this->newpost['topicid']);
         }
     }
     # Write the post
     # Double check forum id is correct - it has been known for a topic to have just been moved!
     $this->newpost['forumid'] = spdb_table(SFTOPICS, 'topic_id=' . $this->newpost['topicid'], 'forum_id');
     # Get post count in topic to enable post index setting
     $index = spdb_count(SFPOSTS, 'topic_id = ' . $this->newpost['topicid']);
     $index++;
     $this->newpost['postindex'] = $index;
     # if topic lock set in post reply update topic (post only)
     if ($this->action == 'post' && $this->newpost['topicstatus']) {
         spdb_query('UPDATE ' . SFTOPICS . ' SET topic_status=1 WHERE topic_id=' . $this->newpost['topicid']);
     }
     $this->newpost = apply_filters('sph_new_post_pre_data_saved', $this->newpost);
     $spdb = new spdbComplex();
     $spdb->table = SFPOSTS;
     $spdb->fields = array('post_content', 'post_date', 'topic_id', 'forum_id', 'user_id', 'guest_name', 'guest_email', 'post_pinned', 'post_index', 'post_status', 'poster_ip', 'source');
     $spdb->data = array($this->newpost['postcontent'], $this->newpost['postdate'], $this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['userid'], $this->newpost['guestname'], $this->newpost['guestemail'], $this->newpost['postpinned'], $this->newpost['postindex'], $this->newpost['poststatus'], $this->newpost['posterip'], $this->newpost['source']);
     $spdb = apply_filters('sph_new_post_data', $spdb);
     $this->newpost['db'] = $spdb->insert();
     if ($this->newpost['db'] == true) {
         $this->newpost['postid'] = $spVars['insertid'];
         $this->newpost = apply_filters('sph_new_post_data_saved', $this->newpost);
     } else {
         $this->abort = true;
         $this->message = sp_text('Unable to save new post message');
         return;
     }
     # Update the timestamp of the last post
     sp_update_option('poststamp', $this->newpost['postdate']);
     $this->returnURL = sp_build_url($this->newpost['forumslug'], $this->newpost['topicslug'], 0, $this->newpost['postid']);
     if ($this->newpost['poststatus']) {
         $this->newpost['submsg'] .= ' - ' . sp_text('placed in moderation') . ' ';
     }
     # Now for all that post-save processing required
     if ($this->guest) {
         $sfguests = sp_get_option('sfguests');
         if ($sfguests['storecookie']) {
             sp_write_guest_cookie($this->newpost['guestname'], $this->newpost['guestemail']);
         }
     } else {
         $postcount = sp_get_member_item($this->newpost['userid'], 'posts');
         $postcount++;
         sp_update_member_item($this->newpost['userid'], 'posts', $postcount);
         # see if postcount qualifies member for new user group membership
         # get rankings information
         if (!$this->admin) {
             # ignore for admins as they dont belong to user groups
             global $spGlobals;
             if (!empty($spGlobals['forum_rank'])) {
                 $index = 0;
                 foreach ($spGlobals['forum_rank'] as $x => $info) {
                     $rankdata['title'][$index] = $x;
                     $rankdata['posts'][$index] = $info['posts'];
                     $rankdata['usergroup'][$index] = $info['usergroup'];
                     $index++;
                 }
                 # sort rankings
                 array_multisort($rankdata['posts'], SORT_ASC, $rankdata['title'], $rankdata['usergroup']);
                 # check for new ranking
                 for ($x = 0; $x < count($rankdata['posts']); $x++) {
                     if ($postcount <= $rankdata['posts'][$x] && !empty($rankdata['usergroup'][$x])) {
                         # if a user group is tied to forum rank add member to the user group
                         if ($rankdata['usergroup'][$x] != 'none') {
                             sp_add_membership($rankdata['usergroup'][$x], $this->newpost['userid']);
                         }
                         break;
                         # only update highest rank
                     }
                 }
             }
         }
     }
     # set new url for email
     $this->newpost['url'] = $this->returnURL;
     # allow plugins to add to post message
     $this->newpost['submsg'] = apply_filters('sph_post_message', $this->newpost['submsg'], $this->newpost);
     # add to or remove from admins new post queue
     if ($this->admin || $this->moderator) {
         # remove topic from waiting...
         sp_remove_from_waiting(false, $this->newpost['topicid']);
     } else {
         # add topic to waiting
         sp_add_to_waiting($this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['postid'], $this->newpost['userid']);
     }
     # if a new post remove topic from the users new post list if in it
     if ($this->action == 'post') {
         sp_remove_users_newposts($this->newpost['topicid'], $this->newpost['userid']);
     }
     # do we need to approve any posts in moderation in this topic?
     if ($this->admin && $spGlobals['admin']['sfadminapprove'] || $this->moderator && $spGlobals['admin']['sfmoderapprove']) {
         sp_approve_post(true, 0, $this->newpost['topicid'], false, $this->newpost['forumid']);
     }
     # if post in moderatiuon then add entry to notices
     if ($this->newpost['poststatus'] != 0) {
         $nData = array();
         $nData['user_id'] = $this->newpost['userid'];
         $nData['guest_email'] = $this->newpost['guestemail'];
         $nData['post_id'] = $this->newpost['postid'];
         $nData['link'] = $this->newpost['url'];
         $nData['link_text'] = $this->newpost['topicname'];
         $nData['message'] = sp_text('Your post is awaiting moderation in the topic');
         $nData['expires'] = time() + 30 * 24 * 60 * 60;
         # 30 days; 24 hours; 60 mins; 60secs
         sp_add_notice($nData);
     }
     # Add this new item to the new tpic/post cache
     $meta = sp_get_sfmeta_key('topic_cache', 'new');
     $cacheSize = sp_get_option('topic_cache');
     $a = array();
     $a[LISTFORUM] = (int) $this->newpost['forumid'];
     $a[LISTTOPIC] = (int) $this->newpost['topicid'];
     $a[LISTPOST] = (int) $this->newpost['postid'];
     $a[LISTSTATUS] = (int) $this->newpost['poststatus'];
     if (isset($spGlobals['topic_cache']['new']) && !empty($spGlobals['topic_cache']['new'])) {
         array_unshift($spGlobals['topic_cache']['new'], $a);
         if (count($spGlobals['topic_cache']['new']) > $cacheSize) {
             array_pop($spGlobals['topic_cache']['new']);
         }
     }
     sp_update_sfmeta('topic_cache', 'new', $spGlobals['topic_cache']['new'], $meta, true);
     # remove group level caches to accommodate new post
     spdb_query('DELETE FROM ' . SFCACHE . " WHERE cache_id LIKE '%*group'");
     # save post in cache for flood control
     sp_add_cache('floodcontrol', time() + sp_get_option('floodcontrol'));
     # Update forum, topic and post index data
     sp_build_post_index($this->newpost['topicid']);
     sp_build_forum_index($this->newpost['forumid']);
     # send out email notifications
     sp_email_notifications($this->newpost);
     # one final filter - just in case
     do_action_ref_array('sph_post_new_completed', array(&$this));
     # and a final action hook
     do_action('sph_new_post', $this->newpost);
     do_action('sph_post_create', $this->newpost);
 }
function spa_save_forums_merge()
{
    check_admin_referer('forum-adminform_mergeforums', 'forum-adminform_mergeforums');
    $source = $target = 0;
    if (isset($_POST['source'])) {
        $source = (int) $_POST['source'];
    }
    if (isset($_POST['target'])) {
        $target = (int) $_POST['target'];
    }
    if (empty($source) || empty($target) || $source == $target) {
        return spa_text('Selections invalid');
    }
    $sourceForum = spdb_table(SFFORUMS, "forum_id={$source}", 'row');
    $targetForum = spdb_table(SFFORUMS, "forum_id={$target}", 'row');
    # 1 - Move sub-forums
    if (!empty($sourceForum->children)) {
        spdb_query("UPDATE " . SFFORUMS . " SET parent={$target} WHERE parent={$source}");
    }
    # 2 - Change forum ids in requirted tables
    spdb_query("UPDATE " . SFTOPICS . " SET forum_id={$target} WHERE forum_id={$source}");
    spdb_query("UPDATE " . SFPOSTS . " SET forum_id={$target} WHERE forum_id={$source}");
    spdb_query("UPDATE " . SFTRACK . " SET forum_id={$target} WHERE forum_id={$source}");
    spdb_query("UPDATE " . SFWAITING . " SET forum_id={$target} WHERE forum_id={$source}");
    # 3 - Delete forum id rows in following tables
    spdb_query("DELETE FROM " . SFPERMISSIONS . " WHERE forum_id={$source}");
    # 4 - Run clean up operations
    sp_reset_memberships();
    sp_reset_auths();
    sp_update_post_urls($sourceForum->forum_slug, $targetForum->forum_slug);
    sp_build_forum_index($target);
    # 5 - Delete the old forum record
    spdb_query("DELETE FROM " . SFFORUMS . " WHERE forum_id={$source}");
    spa_clean_forum_children();
    spa_resequence_forums($targetForum->group_id, 0);
    # 6 - Update Sitemap
    do_action('sm_rebuild');
    # 7 - Update Stats
    do_action('sph_stats_cron');
    # 8 - Let plugins in on the secret
    do_action('sph_merge_forums', $source, $target);
    # clear out group cache tpo enable change_user
    sp_flush_cache('group');
    $mess = spa_text('Forum Merge Completed');
    return $mess;
}
function spa_save_housekeeping_data()
{
    check_admin_referer('forum-adminform_housekeeping', 'forum-adminform_housekeeping');
    $mess = '';
    if (isset($_POST['rebuild-fidx'])) {
        $forumid = $_POST['forum_id'];
        if (is_numeric($forumid)) {
            $topics = spdb_table(SFTOPICS, "forum_id={$forumid}");
            if ($topics) {
                include_once SF_PLUGIN_DIR . '/forum/database/sp-db-management.php';
                foreach ($topics as $topic) {
                    sp_build_post_index($topic->topic_id);
                }
                # after reubuilding post indexes, rebuild the forum indexes
                sp_build_forum_index($forumid);
                do_action('sph_toolbox_housekeeping_forum_index');
                $mess = spa_text('Forum indexes rebuilt');
            } else {
                $mess = spa_text('Forum index rebuild failed - no topics in selected forum');
            }
        } else {
            $mess = spa_text('Forum index rebuild failed - no forum selected');
        }
    }
    if (isset($_POST['transient-cleanup'])) {
        include_once SF_PLUGIN_DIR . '/forum/database/sp-db-management.php';
        sp_transient_cleanup();
        do_action('sph_toolbox_housekeeping_transient');
        $mess = spa_text('WP transients cleaned');
    }
    if (isset($_POST['clean-newposts'])) {
        $days = isset($_POST['sfdays']) ? max(sp_esc_int($_POST['sfdays']), 0) : 30;
        $users = spdb_select('col', "SELECT user_id FROM " . SFMEMBERS . " WHERE lastvisit < DATE_SUB(CURDATE(), INTERVAL " . $days . " DAY)");
        if ($users) {
            foreach ($users as $user) {
                spdb_query('UPDATE ' . SFMEMBERS . " SET newposts='a:1:{i:0;i:0;}' WHERE user_id={$user}");
            }
        }
        do_action('sph_toolbox_housekeeping_newpost');
        $mess = spa_text('New posts lists cleaned');
    }
    if (isset($_POST['postcount-cleanup'])) {
        spdb_query('UPDATE ' . SFMEMBERS . ' SET posts = (SELECT COUNT(*) FROM ' . SFPOSTS . ' WHERE ' . SFPOSTS . '.user_id = ' . SFMEMBERS . '.user_id)');
        # force stats to update
        do_action('sph_stats_cron');
        do_action('sph_toolbox_housekeeping_postcount');
        $mess = spa_text('User post counts calculated');
    }
    if (isset($_POST['reset-tabs'])) {
        # clear out current tabs
        $tabs = sp_get_sfmeta('profile', 'tabs');
        sp_delete_sfmeta($tabs[0]['meta_id']);
        # start adding new ones
        spa_new_profile_setup();
        do_action('sph_toolbox_housekeeping_profile_tabs');
        $mess = spa_text('Profile tabs reset');
    }
    if (isset($_POST['reset-auths'])) {
        sp_reset_auths();
        do_action('sph_toolbox_housekeeping_auths');
        $mess = spa_text('Auths caches cleaned');
    }
    if (isset($_POST['reset-plugin-data'])) {
        sp_reset_member_plugindata();
        do_action('sph_toolbox_housekeeping_plugindata');
        $mess = spa_text('Users Plugin Data reset');
    }
    if (isset($_POST['reset-combinedcss'])) {
        sp_clear_combined_css('all');
        sp_clear_combined_css('mobile');
        sp_clear_combined_css('tablet');
        do_action('sph_toolbox_housekeeping_ccombined_css');
        $mess = spa_text('Combined CSS cache file removed');
    }
    if (isset($_POST['reset-combinedjs'])) {
        sp_clear_combined_scripts('desktop');
        sp_clear_combined_scripts('mobile');
        sp_clear_combined_scripts('tablet');
        do_action('sph_toolbox_housekeeping_combined_js');
        $mess = spa_text('Combined scripts cache files removed');
    }
    if (isset($_POST['flushcache'])) {
        sp_flush_cache('all');
        do_action('sph_toolbox_housekeeping_flush_cache');
        $mess = spa_text('General cache flushed');
    }
    do_action('sph_toolbox_housekeeping_save');
    return $mess;
}
Example #7
0
function sp_delete_member_data($userid, $blog_id = '', $delete_option = 'spguest', $reassign = 0)
{
    if (!$userid) {
        return '';
    }
    global $wpdb;
    # if removing user from network site, make sure sp installed on that network site
    if (!empty($blog_id)) {
        $optionstable = $wpdb->get_var("SHOW TABLES LIKE '" . $wpdb->prefix . "sfoptions'");
        if (empty($optionstable)) {
            return;
        }
    }
    # let plugins clean up from member removal first
    do_action('sph_member_deleted', $userid);
    # remove member from core
    $option = isset($_POST['sp_delete_option']) ? sp_esc_str($_POST['sp_delete_option']) : $delete_option;
    switch ($option) {
        case 'spreassign':
            $newuser = isset($_POST['sp_reassign_user']) ? sp_esc_int($_POST['sp_reassign_user']) : $reassign;
            # Set poster ID to the new user id
            $wpdb->query('UPDATE ' . $wpdb->prefix . "sfposts SET user_id={$newuser} WHERE user_id={$userid}");
            $wpdb->query('UPDATE ' . $wpdb->prefix . "sftopics SET user_id={$newuser} WHERE user_id={$userid}");
            break;
        case 'spdelete':
            # need to get topics for user posts to see if topic will be empty after deleting posts
            $topics = spdb_select('set', 'SELECT DISTINCT topic_id, forum_id FROM ' . SFPOSTS . " WHERE user_id={$userid}");
            # delete all the user posts
            spdb_query('DELETE FROM ' . SFPOSTS . " WHERE user_id={$userid}");
            # if any topics are now empty of posts, lets remove the topic and update the forum
            if (!empty($topics)) {
                foreach ($topics as $topic) {
                    $posts = spdb_table(SFPOSTS, "topic_id={$topic->topic_id}");
                    if (empty($posts)) {
                        spdb_query('DELETE FROM ' . SFTOPICS . " WHERE topic_id={$topic->topic_id}");
                    } else {
                        sp_build_post_index($topic->topic_id);
                    }
                    sp_build_forum_index($topic->forum_id);
                }
            }
            break;
        case 'spguest':
        default:
            # get users email address
            $user_email = sp_filter_email_save($wpdb->get_var('SELECT user_email from ' . $wpdb->prefix . "users WHERE ID={$userid}"));
            # get the users display name from members table
            $display_name = $wpdb->get_var('SELECT display_name FROM ' . $wpdb->prefix . "sfmembers WHERE user_id = {$userid}");
            $display_name = sp_filter_name_save(maybe_unserialize($display_name));
            # Set user name and email to guest name and meail in all of their posts
            $wpdb->query('UPDATE ' . $wpdb->prefix . "sfposts SET user_id=0, guest_name='{$display_name}', guest_email='{$user_email}' WHERE user_id={$userid}");
            $wpdb->query('UPDATE ' . $wpdb->prefix . "sftopics SET user_id=0 WHERE user_id={$userid}");
    }
    # flush and rebuild topic cache
    sp_rebuild_topic_cache();
    # remove from various core tables
    $wpdb->query('DELETE FROM ' . $wpdb->prefix . "sfmembers WHERE user_id={$userid}");
    $wpdb->query('DELETE FROM ' . $wpdb->prefix . "sfmemberships WHERE user_id={$userid}");
    $wpdb->query('DELETE FROM ' . $wpdb->prefix . "sfspecialranks WHERE user_id={$userid}");
    $wpdb->query('DELETE FROM ' . $wpdb->prefix . "sftrack WHERE trackuserid={$userid}");
    $wpdb->query('DELETE FROM ' . $wpdb->prefix . "sfnotices WHERE user_id={$userid}");
    $wpdb->query('DELETE FROM ' . $wpdb->prefix . "sfuseractivity WHERE user_id={$userid}");
    $wpdb->query('DELETE FROM ' . $wpdb->prefix . "sfwaiting WHERE user_id={$userid}");
    # eemove from recent members list if present
    sp_remove_newuser($userid);
    # check if forum moderator list needs updating
    sp_update_forum_moderators();
}