function sp_setup_globals()
{
    global $spGlobals, $current_user, $spBootCache, $spMeta, $spDevice;
    if ($spBootCache['globals'] == true) {
        return;
    }
    # Main admin options
    $spGlobals['admin'] = sp_get_option('sfadminsettings');
    $spGlobals['lockdown'] = sp_get_option('sflockdown');
    $spGlobals['editor'] = 0;
    # Display array
    $spGlobals['display'] = sp_get_option('sfdisplay');
    # Current theme data
    $spGlobals['theme'] = sp_get_current_sp_theme();
    # if mobile device then force integrated editor toolbar to on
    if ($spDevice == 'mobile' || $spDevice == 'tablet') {
        $spGlobals['display']['editor']['toolbar'] = true;
        if ($spDevice == 'mobile') {
            $spGlobals['mobile-display'] = sp_get_option('sp_mobile_theme');
        } else {
            $spGlobals['mobile-display'] = sp_get_option('sp_tablet_theme');
        }
    }
    # Load up sfmeta
    $spMeta = spdb_table(SFMETA, 'autoload=1');
    if (!empty($spMeta)) {
        foreach ($spMeta as $s) {
            if (!empty($s)) {
                $spGlobals[$s->meta_type][$s->meta_key] = maybe_unserialize($s->meta_value);
            }
        }
    }
    # create topic/post cache if found to be missing!
    if (!isset($spGlobals['topic_cache']['new']) || empty($spGlobals['topic_cache']['new'])) {
        $spGlobals['topic_cache']['new'] = sp_rebuild_topic_cache();
    }
    # Pre-define a few others
    $spGlobals['canonicalurl'] = false;
    # set up array of disabled forums
    $spGlobals['disabled_forums'] = spdb_select('col', 'SELECT forum_id FROM ' . SFFORUMS . ' WHERE forum_disabled=1', ARRAY_A);
    $spBootCache['globals'] = true;
}
Example #2
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);
    }
}
Example #3
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();
}