function sp_cron_remove_users()
{
    require_once ABSPATH . 'wp-admin/includes/user.php';
    # make sure auto removal is enabled
    $sfuser = sp_get_option('sfuserremoval');
    if ($sfuser['sfuserremove']) {
        # see if removing users with no posts
        if ($sfuser['sfusernoposts']) {
            $users = spdb_select('set', 'SELECT ' . SFUSERS . '.ID FROM ' . SFUSERS . '
										JOIN ' . SFMEMBERS . ' on ' . SFUSERS . '.ID = ' . SFMEMBERS . '.user_id
										LEFT JOIN ' . SFWPPOSTS . ' ON ' . SFUSERS . '.ID = ' . SFWPPOSTS . '.post_author
										WHERE user_registered < DATE_SUB(NOW(), INTERVAL ' . $sfuser['sfuserperiod'] . ' DAY)
										AND post_author IS NULL
										AND posts < 1');
            if ($users) {
                foreach ($users as $user) {
                    wp_delete_user($user->ID);
                }
            }
        }
        # see if removing inactive users
        if ($sfuser['sfuserinactive']) {
            $users = spdb_table(SFMEMBERS, 'lastvisit < DATE_SUB(NOW(), INTERVAL ' . $sfuser['sfuserperiod'] . ' DAY)');
            if ($users) {
                foreach ($users as $user) {
                    wp_delete_user($user->user_id);
                }
            }
        }
    } else {
        wp_clear_scheduled_hook('sph_cron_user');
    }
    do_action('sph_remove_users_cron');
}
function spa_get_log_data()
{
    $sflog = array();
    $sql = '
		SELECT install_date, release_type, version, build, display_name
		FROM ' . SFLOG . '
		JOIN ' . SFMEMBERS . ' ON ' . SFLOG . '.user_id=' . SFMEMBERS . '.user_id
		ORDER BY id DESC;';
    $sflog = spdb_select('set', $sql, ARRAY_A);
    return $sflog;
}
Example #3
0
function sp_rebuild_table_list()
{
    global $tables;
    sp_delete_option('installed_tables');
    $t = array();
    foreach ($tables as $table => $data) {
        $found = spdb_select('var', "SHOW TABLES LIKE '{$table}'");
        if ($found) {
            $t[] = $table;
        }
    }
    sp_add_option('installed_tables', $t);
}
function sp_update_users_newposts()
{
    global $spThisUser;
    # Check the users checktime against the last post timestamp to see if we need to do this
    $checkTime = spdb_zone_mysql_checkdate($spThisUser->checktime);
    $postTime = sp_get_option('poststamp');
    if (strtotime($checkTime) > strtotime($postTime) && !isset($_GET['mark-read'])) {
        return;
    }
    # so there must have been a new post since the last page load for this user
    $newPostList = $spThisUser->newposts;
    if (empty($newPostList['topics'])) {
        # clean it up to be on the safe side
        unset($newPostList);
        $newPostList = array();
        $newPostList['topics'] = array();
        $newPostList['forums'] = array();
    }
    # create new holding array and new checktime (now)
    $addPostList = array();
    $addPostList['topics'] = array();
    $addPostList['forums'] = array();
    sp_set_server_timezone();
    $newCheckTime = sp_apply_timezone(time(), 'mysql');
    # Use the current checktime for any new posts since users session began
    $records = spdb_select('set', "SELECT DISTINCT topic_id, forum_id FROM " . SFPOSTS . "\n\t\t\t\t\t\t\t\t   WHERE post_status = 0 AND post_date > '" . $checkTime . "' AND user_id != " . $spThisUser->ID . "\n\t\t\t\t\t\t\t\t   ORDER BY post_id DESC LIMIT " . $spThisUser->unreadposts . ";", ARRAY_A);
    if ($records) {
        foreach ($records as $r) {
            if (sp_get_auth('view_forum', $r['forum_id']) && !in_array($r['topic_id'], $newPostList['topics'])) {
                $addPostList['topics'][] = $r['topic_id'];
                $addPostList['forums'][] = $r['forum_id'];
            }
        }
    }
    $addPostList = apply_filters('sph_new_post_list', $addPostList, $newPostList);
    # now merge the arrays and truncate if necessary
    $newPostList['topics'] = array_merge($addPostList['topics'], $newPostList['topics']);
    $newPostList['forums'] = array_merge($addPostList['forums'], $newPostList['forums']);
    if (count($newPostList['topics']) > $spThisUser->unreadposts) {
        array_splice($newPostList['topics'], $spThisUser->unreadposts);
        array_splice($newPostList['forums'], $spThisUser->unreadposts);
    }
    # update sfmembers - do it here to ensure both are updated together
    spdb_query("UPDATE " . SFMEMBERS . " SET newposts='" . serialize($newPostList) . "', checktime='" . $newCheckTime . "' WHERE user_id=" . $spThisUser->ID);
    $spThisUser->newpostlist = true;
    $spThisUser->checktime = $newCheckTime;
    $spThisUser->newposts = $newPostList;
}
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;
}
function sp_rebuild_topic_cache()
{
    $size = sp_get_option('topic_cache');
    if (!isset($size) || $size == 0) {
        sp_add_option('topic_cache', 200);
    }
    $sql = "SELECT DISTINCTROW forum_id, topic_id, post_id, post_status\n\t\t\tFROM " . SFPOSTS . "\n\t\t\tORDER BY post_id DESC\n\t\t\tLIMIT {$size}";
    $topics = spdb_select('set', $sql, ARRAY_N);
    if ($topics) {
        sp_add_sfmeta('topic_cache', 'new', $topics, true);
    }
    # Delete group level cache for good measure
    spdb_query("DELETE FROM " . SFCACHE . " WHERE cache_id LIKE '%*group'");
    return $topics;
}
    function sp_topicview_query($topicid = 0, $cPage = 1, $forumid = 0)
    {
        global $spGlobals, $spThisUser, $spVars;
        # do we have a valid topic id
        if ($topicid == 0) {
            $this->topicViewStatus = 'no data';
            return;
        } else {
            $WHERE = SFTOPICS . '.topic_id=' . $topicid;
        }
        # default to no access
        $this->topicViewStatus = 'no access';
        # some setup vars
        $startlimit = 0;
        $lastpage = 0;
        # how many posts per page?
        $ppaged = $spGlobals['display']['posts']['perpage'];
        if (!$ppaged) {
            $ppaged = 10;
        }
        # setup where we are in the post list (paging)
        if ($cPage != 1) {
            $startlimit = ($cPage - 1) * $ppaged;
        }
        $LIMIT = $startlimit . ', ' . $ppaged;
        # Set up order by
        $setSort = false;
        $reverse = false;
        $setSort = $spGlobals['display']['posts']['sortdesc'];
        if (isset($spGlobals['sort_order']['topic'])) {
            $reverse = array_search($topicid, (array) $spGlobals['sort_order']['topic']) !== false ? true : false;
        }
        if (isset($spThisUser->postDESC) && $spThisUser->postDESC) {
            $reverse = !$reverse;
        }
        if ($setSort xor $reverse) {
            $ORDER = 'post_pinned DESC, ' . SFPOSTS . ".post_id DESC";
        } else {
            $ORDER = 'post_pinned DESC, ' . SFPOSTS . ".post_id ASC";
        }
        # add newpost/sfwaiting support for admins
        $waitCheck = ', NULL AS new_post';
        if ($spThisUser->admin || $spThisUser->moderator) {
            $waitCheck = ', ' . SFWAITING . '.post_count AS new_post';
        }
        # Discover if this topic is in users new post list
        $maybeNewPost = false;
        if ($spThisUser->member && sp_is_in_users_newposts($topicid)) {
            $maybeNewPost = true;
        }
        # retrieve topic and post records
        $spdb = new spdbComplex();
        $spdb->table = SFTOPICS;
        $spdb->found_rows = true;
        $spdb->fields = 'group_id, ' . SFTOPICS . '.topic_id, ' . SFTOPICS . '.forum_id, topic_name, topic_slug, topic_status, topic_pinned, topic_icon, topic_opened, ' . SFTOPICS . '.post_count, forum_name, forum_slug, forum_status,
							  forum_disabled, forum_rss_private, ' . SFPOSTS . '.post_id, ' . spdb_zone_datetime('post_date') . ', ' . SFPOSTS . '.user_id, ' . SFTOPICS . '.user_id AS topic_starter,
							  guest_name, guest_email, post_status, post_pinned, post_index, post_edit, poster_ip, source, post_content' . $waitCheck;
        $spdb->join = array(SFPOSTS . ' ON ' . SFTOPICS . '.topic_id=' . SFPOSTS . '.topic_id', SFFORUMS . ' ON ' . SFTOPICS . '.forum_id=' . SFFORUMS . '.forum_id');
        if ($spThisUser->admin || $spThisUser->moderator) {
            $spdb->left_join = array(SFWAITING . ' ON ' . SFPOSTS . '.post_id=' . SFWAITING . '.post_id');
        }
        $spdb->where = $WHERE;
        $spdb->orderby = $ORDER;
        $spdb->limits = $LIMIT;
        $spdb = apply_filters('sph_topicview_query', $spdb, $this);
        if (!empty($spThisUser->inspect['q_spTopicView'])) {
            $spdb->inspect = 'spTopicView';
            $spdb->show = true;
        }
        $records = $spdb->select();
        $t = array();
        if ($records) {
            $tidx = $topicid;
            $pidx = 0;
            $r = current($records);
            if (sp_get_auth('view_forum', $r->forum_id)) {
                $this->topicViewStatus = 'data';
                # construct the parent topic object
                $t[$tidx] = new stdClass();
                $t[$tidx]->topic_id = $r->topic_id;
                $t[$tidx]->forum_id = $r->forum_id;
                $t[$tidx]->group_id = $r->group_id;
                $t[$tidx]->forum_name = sp_filter_title_display($r->forum_name);
                $t[$tidx]->topic_name = sp_filter_title_display($r->topic_name);
                $t[$tidx]->topic_slug = $r->topic_slug;
                $t[$tidx]->topic_opened = $r->topic_opened;
                $t[$tidx]->forum_status = $r->forum_status;
                $t[$tidx]->topic_pinned = $r->topic_pinned;
                $t[$tidx]->forum_disabled = $r->forum_disabled;
                $t[$tidx]->forum_slug = $r->forum_slug;
                $t[$tidx]->forum_rss_private = $r->forum_rss_private;
                $t[$tidx]->topic_permalink = sp_build_url($r->forum_slug, $r->topic_slug, 1, 0);
                $t[$tidx]->topic_status = $r->topic_status;
                $t[$tidx]->topic_icon = sanitize_file_name($r->topic_icon);
                $t[$tidx]->rss = '';
                $t[$tidx]->editmode = 0;
                $t[$tidx]->tools_flag = 1;
                $t[$tidx]->display_page = $this->topicPage;
                $t[$tidx]->posts_per_page = $ppaged;
                $t[$tidx]->unread = 0;
                # user calc_rows and nor post_count as - for example - some posts may be hiodden by choice.
                $t[$tidx]->post_count = spdb_select('var', 'SELECT FOUND_ROWS()');
                # Can the user create new topics or should we lock the forum?
                $t[$tidx]->start_topics = sp_get_auth('start_topics', $r->forum_id);
                $t[$tidx]->reply_topics = sp_get_auth('reply_topics', $r->forum_id);
                $t[$tidx]->reply_own_topics = sp_get_auth('reply_own_topics', $r->forum_id);
                # grab topic start info
                $t[$tidx]->topic_starter = $r->topic_starter;
                $totalPages = $r->post_count / $ppaged;
                if (!is_int($totalPages)) {
                    $totalPages = intval($totalPages) + 1;
                }
                $t[$tidx]->total_pages = $totalPages;
                if ($setSort xor $reverse) {
                    if ($cPage == 1) {
                        $lastpage = true;
                    }
                } else {
                    if ($cPage == $totalPages) {
                        $lastpage = true;
                    }
                }
                $t[$tidx]->last_page = $lastpage;
                $t[$tidx] = apply_filters('sph_topicview_topic_record', $t[$tidx], $r);
                reset($records);
                unset($r);
                # now loop through the post records
                $newPostFlag = false;
                $firstPostPage = 1;
                $pinned = 0;
                # define post id and post user id arrays for plugins to use in combined filter
                $p = array();
                $u = array();
                foreach ($records as $r) {
                    $pidx = $r->post_id;
                    $p[] = $pidx;
                    # prepare for user object
                    $cUser = $spThisUser->ID == $r->user_id;
                    $cSmall = !$cUser;
                    $t[$tidx]->posts[$pidx] = new stdClass();
                    $t[$tidx]->posts[$pidx]->post_id = $r->post_id;
                    $t[$tidx]->posts[$pidx]->post_date = $r->post_date;
                    $t[$tidx]->posts[$pidx]->user_id = $r->user_id;
                    $t[$tidx]->posts[$pidx]->guest_name = sp_filter_name_display($r->guest_name);
                    $t[$tidx]->posts[$pidx]->guest_email = sp_filter_email_display($r->guest_email);
                    $t[$tidx]->posts[$pidx]->post_status = $r->post_status;
                    $t[$tidx]->posts[$pidx]->post_pinned = $r->post_pinned;
                    $t[$tidx]->posts[$pidx]->post_index = $r->post_index;
                    $t[$tidx]->posts[$pidx]->poster_ip = $r->poster_ip;
                    $t[$tidx]->posts[$pidx]->source = $r->source;
                    $t[$tidx]->posts[$pidx]->post_permalink = sp_build_url($r->forum_slug, $r->topic_slug, $cPage, $r->post_id);
                    $t[$tidx]->posts[$pidx]->edits = '';
                    $t[$tidx]->posts[$pidx]->last_post = 0;
                    $t[$tidx]->posts[$pidx]->last_post_on_page = 0;
                    $t[$tidx]->posts[$pidx]->first_post_on_page = $firstPostPage;
                    $t[$tidx]->posts[$pidx]->editmode = 0;
                    $t[$tidx]->posts[$pidx]->post_content = sp_filter_content_display($r->post_content);
                    $t[$tidx]->posts[$pidx]->first_pinned = 0;
                    $t[$tidx]->posts[$pidx]->last_pinned = 0;
                    $t[$tidx]->posts[$pidx]->postUser = new stdClass();
                    $t[$tidx]->posts[$pidx]->postUser = clone sp_get_user($r->user_id, $cUser, $cSmall);
                    # populate the user guest name and email in case the poster is a guest
                    if ($r->user_id == 0) {
                        $t[$tidx]->posts[$pidx]->postUser->guest_name = $t[$tidx]->posts[$pidx]->guest_name;
                        $t[$tidx]->posts[$pidx]->postUser->guest_email = $t[$tidx]->posts[$pidx]->guest_email;
                        $t[$tidx]->posts[$pidx]->postUser->display_name = $t[$tidx]->posts[$pidx]->guest_name;
                        $t[$tidx]->posts[$pidx]->postUser->ip = $t[$tidx]->posts[$pidx]->poster_ip;
                    }
                    # pinned status
                    if ($firstPostPage == 1 && $r->post_pinned) {
                        $t[$tidx]->posts[$pidx]->first_pinned = true;
                        $pinned = $pidx;
                    }
                    if ($firstPostPage == 0 && $pinned > 0 && $r->post_pinned == false) {
                        $t[$tidx]->posts[$pinned]->last_pinned = true;
                    } elseif ($r->post_pinned) {
                        $pinned = $pidx;
                    }
                    $firstPostPage = 0;
                    # Is this a new post for the current user?
                    if ($spThisUser->guest) {
                        $newPostFlag = false;
                    } else {
                        if ($maybeNewPost && strtotime($r->post_date) > strtotime($spThisUser->lastvisit)) {
                            $newPostFlag = true;
                        }
                        if (isset($r->new_post)) {
                            $newPostFlag = true;
                        }
                    }
                    $t[$tidx]->posts[$pidx]->new_post = $newPostFlag;
                    # do we need to hide an admin post?
                    if (!sp_get_auth('view_admin_posts', $r->forum_id) && sp_is_forum_admin($r->user_id)) {
                        $adminview = sp_get_sfmeta('adminview', 'message');
                        if ($adminview) {
                            $t[$tidx]->posts[$pidx]->post_content = '<div class="spMessage">';
                            $t[$tidx]->posts[$pidx]->post_content .= sp_filter_text_display($adminview[0]['meta_value']);
                            $t[$tidx]->posts[$pidx]->post_content .= '</div>';
                        } else {
                            $t[$tidx]->posts[$pidx]->post_content = '';
                        }
                    }
                    # do we need to hide an others posts?
                    if (sp_get_auth('view_own_admin_posts', $r->forum_id) && !sp_is_forum_admin($r->user_id) && !sp_is_forum_mod($r->user_id) && $spThisUser->ID != $r->user_id) {
                        $userview = sp_get_sfmeta('userview', 'message');
                        if ($userview) {
                            $t[$tidx]->posts[$pidx]->post_content = '<div class="spMessage">';
                            $t[$tidx]->posts[$pidx]->post_content .= sp_filter_text_display($userview[0]['meta_value']);
                            $t[$tidx]->posts[$pidx]->post_content .= '</div>';
                        } else {
                            $t[$tidx]->posts[$pidx]->post_content = '';
                        }
                    }
                    # Is this post to be edited?
                    if ($spVars['displaymode'] == 'edit' && $spVars['postedit'] == $r->post_id) {
                        $t[$tidx]->editmode = 1;
                        $t[$tidx]->editpost_id = $r->post_id;
                        $t[$tidx]->editpost_content = sp_filter_content_edit($r->post_content);
                        $t[$tidx]->posts[$pidx]->editmode = 1;
                    }
                    # Add edit history
                    if (!empty($r->post_edit) && is_serialized($r->post_edit)) {
                        $edits = unserialize($r->post_edit);
                        $eidx = 0;
                        foreach ($edits as $e) {
                            $t[$tidx]->posts[$pidx]->edits[$eidx] = new stdClass();
                            $t[$tidx]->posts[$pidx]->edits[$eidx]->by = $e['by'];
                            $t[$tidx]->posts[$pidx]->edits[$eidx]->at = $e['at'];
                            $eidx++;
                        }
                    }
                    if (!in_array($r->user_id, $u)) {
                        $u[] = $r->user_id;
                    }
                    $t[$tidx]->posts[$pidx] = apply_filters('sph_topicview_post_records', $t[$tidx]->posts[$pidx], $r);
                }
                # index of post IDs with position in listing
                $t[$tidx]->post_keys = $p;
                $t[$tidx]->posts[$pidx]->last_post = $lastpage;
                $t[$tidx]->posts[$pidx]->last_post_on_page = 1;
                # save last post on page id
                $t[$tidx]->last_post_id = $r->post_id;
                # allow plugins to add more data to combined topic/post data structure
                $t[$tidx] = apply_filters('sph_topicview_combined_data', $t[$tidx], $p, $u);
                unset($records);
            } else {
                # check for view forum lists but not topic lists
                if (sp_can_view($r->forum_id, 'forum-title')) {
                    $this->topicViewStatus = 'sneak peek';
                }
            }
        }
        return $t;
    }
}
if ($action == 'del_specialrank') {
    $key = sp_esc_int($_GET['key']);
    $specialRank = sp_get_sfmeta('special_rank', false, $key);
    # remove members rank first
    spdb_query('DELETE FROM ' . SFSPECIALRANKS . ' WHERE special_rank="' . $specialRank[0]['meta_key'] . '"');
    # remove the forum rank
    $sql = 'DELETE FROM ' . SFMETA . " WHERE meta_type='special_rank' AND meta_id='{$key}'";
    spdb_query($sql);
}
if ($action == 'show') {
    $key = sp_esc_int($_GET['key']);
    $specialRank = sp_get_sfmeta('special_rank', false, $key);
    $users = spdb_select('col', 'SELECT display_name
						  FROM ' . SFSPECIALRANKS . '
						  JOIN ' . SFMEMBERS . ' ON ' . SFSPECIALRANKS . '.user_id = ' . SFMEMBERS . '.user_id
						  WHERE special_rank = "' . $specialRank[0]['meta_key'] . '"
						  ORDER BY display_name');
    echo '<fieldset class="sfsubfieldset">';
    echo '<legend>' . spa_text('Special Rank Members') . '</legend>';
    if ($users) {
        echo '<ul class="memberlist">';
        for ($x = 0; $x < count($users); $x++) {
            echo '<li>' . sp_filter_name_display($users[$x]) . '</li>';
        }
        echo '</ul>';
    } else {
        spa_etext('No users with this special rank');
    }
    echo '</fieldset>';
}
    function sp_listview_populate_newposts($topicIds)
    {
        global $spThisUser;
        $newList = array();
        # First filter topics by those in the users new post list
        $newTopicIds = array();
        foreach ($topicIds as $topic) {
            if (sp_is_in_users_newposts($topic)) {
                $newTopicIds[] = $topic;
            }
        }
        if ($newTopicIds) {
            # construct the query - need to add in sfwaiting for admins
            $where = SFPOSTS . '.topic_id IN (' . implode(',', $newTopicIds) . ') AND (post_date > "' . spdb_zone_mysql_checkdate($spThisUser->lastvisit) . '")';
            if ($spThisUser->admin || $spThisUser->moderator) {
                $wPosts = spdb_select('col', 'SELECT post_id FROM ' . SFWAITING);
                if ($wPosts) {
                    $where .= ' OR (' . SFPOSTS . '.post_id IN (' . implode(",", $wPosts) . '))';
                }
            }
            $spdb = new spdbComplex();
            $spdb->table = SFPOSTS;
            $spdb->fields = SFPOSTS . '.topic_id, ' . SFPOSTS . '.post_id, post_index, ' . spdb_zone_datetime('post_date') . ',
									guest_name, ' . SFPOSTS . '.user_id, display_name, post_count-post_index+1 AS new_post_count';
            $spdb->left_join = array(SFMEMBERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFPOSTS . '.user_id');
            $spdb->join = array(SFTOPICS . ' ON ' . SFPOSTS . '.topic_id = ' . SFTOPICS . '.topic_id');
            $spdb->where = $where;
            $spdb->orderby = 'topic_id, post_id';
            $spdb = apply_filters('sph_listview_newposts_query', $spdb, $this);
            $postrecords = $spdb->select();
            if ($postrecords) {
                $cTopic = 0;
                foreach ($postrecords as $p) {
                    if ($p->topic_id != $cTopic) {
                        $cTopic = $p->topic_id;
                        $newList[$cTopic] = new stdClass();
                        $newList[$cTopic]->topic_id = $cTopic;
                        $newList[$cTopic]->new_post_count = $p->new_post_count;
                        $newList[$cTopic]->new_post_post_id = $p->post_id;
                        $newList[$cTopic]->new_post_post_index = $p->post_index;
                        $newList[$cTopic]->new_post_post_date = $p->post_date;
                        $newList[$cTopic]->new_post_user_id = $p->user_id;
                        $newList[$cTopic]->new_post_display_name = sp_filter_name_display($p->display_name);
                        $newList[$cTopic]->new_post_guest_name = sp_filter_name_display($p->guest_name);
                    }
                }
            }
        }
        return $newList;
    }
function sp_is_online($userid)
{
    global $session_online;
    if (!$userid) {
        return false;
    }
    if (!isset($session_online)) {
        $session_online = spdb_select('col', "SELECT trackuserid FROM " . SFTRACK);
    }
    if (in_array($userid, $session_online)) {
        return true;
    }
    return false;
}
function sp_UserGroupList($args = '', $titleLabel = '', $userGroup = 0)
{
    if (!$userGroup) {
        return;
    }
    $defs = array('tagClass' => 'spUserGroupList', 'pTitleClass' => 'spUserGroupListTitle', 'spanClass' => 'spUserGroupListList', 'link_names' => 1, 'postCount' => 1, 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_UserGroupList_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $tagClass = esc_attr($tagClass);
    $pTitleClass = esc_attr($pTitleClass);
    $spanClass = esc_attr($spanClass);
    $link_names = (int) $link_names;
    $postCount = (int) $postCount;
    $echo = (int) $echo;
    $userGroup = (int) $userGroup;
    $get = (int) $get;
    if (!empty($titleLabel)) {
        $titleLabel = sp_filter_title_display($titleLabel);
    }
    # get user group member list
    $sql = "SELECT " . SFMEMBERSHIPS . ".user_id, display_name, posts\n\t\t\tFROM " . SFMEMBERSHIPS . "\n\t\t\tJOIN " . SFMEMBERS . " ON " . SFMEMBERS . ".user_id = " . SFMEMBERSHIPS . ".user_id\n\t\t\tWHERE " . SFMEMBERSHIPS . ".usergroup_id=" . $userGroup . "\n\t\t\tORDER BY display_name";
    $members = spdb_select('set', $sql);
    if ($get) {
        return $members;
    }
    # render the members list
    $out = "<div class='{$tagClass}'>";
    $out .= "<p class='{$pTitleClass}'><span class='{$pTitleClass}'>{$titleLabel}</span>";
    if ($members) {
        $first = true;
        $out .= "<span class='{$spanClass}'>";
        foreach ($members as $member) {
            $comma = !$first ? ', ' : '';
            if ($member->posts < 0) {
                $member->posts = 0;
            }
            $userPosts = $postCount ? ': ' . $member->posts : '';
            $out .= sp_build_name_display($member->user_id, $comma . sp_filter_name_display($member->display_name) . $userPosts);
            $first = false;
        }
        $out .= '</span>';
    }
    $out .= '</p>';
    # finish it up
    $out .= "</div>\n";
    $out = apply_filters('sph_UserGroupList', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
Example #12
0
function sp_rpx_get_wpuid_by_identifier($identifier)
{
    $sql = 'SELECT user_id FROM ' . SFUSERMETA . " WHERE meta_key = 'rpx_identifier' AND meta_value = '{$identifier}'";
    $r = spdb_select('var', $sql);
    if ($r) {
        return $r;
    } else {
        return null;
    }
}
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;
}
function sp_test_table_create()
{
    # make sure we can create database tables
    $sql = '
		CREATE TABLE sfCheckCreate (
			id int(4) NOT NULL,
			item varchar(15) default NULL,
			PRIMARY KEY	 (id)
		) ' . spdb_charset();
    spdb_query($sql);
    $success = spdb_select('var', 'SHOW TABLES LIKE "sfCheckCreate"');
    if ($success == false) {
        return false;
    } else {
        spdb_query('DROP TABLE sfCheckCreate');
        return true;
    }
}
$LastChangedDate: 2013-03-02 17:15:32 +0000 (Sat, 02 Mar 2013) $
$Rev: 9944 $
*/
if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
    die('Access denied - you cannot directly call this file');
}
spa_admin_ahah_support();
check_admin_referer('forum-adminform_mapusers', 'forum-adminform_mapusers');
global $wp_roles;
$startSQL = sp_esc_int($_GET['startNum']);
$batchSQL = sp_esc_int($_GET['batchNum']);
$where = ' WHERE admin=0';
if ($_GET['ignoremods']) {
    $where .= ' AND moderator=0';
}
$users = spdb_select('col', 'SELECT user_id FROM ' . SFMEMBERS . $where . ' ORDER BY user_id LIMIT ' . $startSQL . ', ' . $batchSQL);
if ($users) {
    $value = sp_get_sfmeta('default usergroup', 'sfmembers');
    $defaultUG = $value[0]['meta_value'];
    foreach ($users as $thisUser) {
        if ($_GET['mapoption'] == 2) {
            spdb_query('DELETE FROM ' . SFMEMBERSHIPS . ' WHERE user_id=' . $thisUser);
        }
        $user = new WP_User($thisUser);
        if (!empty($user->roles) && is_array($user->roles)) {
            foreach ($user->roles as $role) {
                $value = sp_get_sfmeta('default usergroup', $role);
                if (!empty($value)) {
                    $ug = $value[0]['meta_value'];
                } else {
                    $ug = $defaultUG;
function spa_get_members_info($userid)
{
    $data = sp_get_member_row($userid);
    if (empty($data)) {
        return '';
    }
    $first = spdb_select('row', '
			SELECT ' . SFPOSTS . '.forum_id, forum_name, forum_slug, ' . SFPOSTS . '.topic_id, topic_name, topic_slug, post_date
			FROM ' . SFPOSTS . '
			JOIN ' . SFTOPICS . ' ON ' . SFTOPICS . '.topic_id = ' . SFPOSTS . '.topic_id
			JOIN ' . SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFPOSTS . '.forum_id
			WHERE ' . SFPOSTS . ".user_id={$userid}\n\t\t\tORDER BY post_date ASC\n\t\t\tLIMIT 1");
    if ($first) {
        $url = '<a href="' . sp_build_url($first->forum_slug, $first->topic_slug, 1, 0) . '">' . sp_filter_title_display($first->topic_name) . '</a>';
        $data['first'] = sp_filter_title_display($first->forum_name) . '<br />' . $url . '<br />' . sp_date('d', $first->post_date);
    } else {
        $data['first'] = spa_text('No Posts');
    }
    $last = spdb_select('row', '
			SELECT ' . SFPOSTS . '.forum_id, forum_name, forum_slug, ' . SFPOSTS . '.topic_id, topic_name, topic_slug, post_date
			FROM ' . SFPOSTS . '
			JOIN ' . SFTOPICS . ' ON ' . SFTOPICS . '.topic_id = ' . SFPOSTS . '.topic_id
			JOIN ' . SFFORUMS . ' ON ' . SFFORUMS . '.forum_id = ' . SFPOSTS . '.forum_id
			WHERE ' . SFPOSTS . ".user_id={$userid}\n\t\t\tORDER BY post_date DESC\n\t\t\tLIMIT 1");
    if ($last) {
        $url = '<a href="' . sp_build_url($last->forum_slug, $last->topic_slug, 1, 0) . '">' . sp_filter_title_display($last->topic_name) . '</a>';
        $data['last'] = sp_filter_title_display($last->forum_name) . '<br />' . $url . '<br />' . sp_date('d', $last->post_date);
    } else {
        $data['last'] = spa_text('No posts');
    }
    if ($data['admin']) {
        $user_memberships = 'Admin';
        $status = 'Admin';
        $start = 0;
    } else {
        if ($data['moderator']) {
            $status = 'Moderator';
            $start = 1;
        } else {
            $status = 'User';
            $start = 1;
        }
    }
    $memberships = spdb_table(SFMEMBERSHIPS, "user_id={$userid}", '', '', '', ARRAY_A);
    if ($memberships) {
        foreach ($memberships as $membership) {
            $name = spdb_table(SFUSERGROUPS, 'usergroup_id=' . $membership['usergroup_id'], 'usergroup_name');
            if ($start) {
                $user_memberships = $name;
                $start = 0;
            } else {
                $user_memberships .= ', ' . $name;
            }
        }
    } else {
        if ($start) {
            $user_memberships = 'No Memberships';
        }
    }
    $data['memberships'] = $user_memberships;
    $rank = sp_get_user_forum_rank($status, $userid, $data['posts']);
    $data['rank'] = $rank[0]['name'];
    $user = get_userdata($userid);
    $data['login'] = $user->user_login;
    return $data;
}
function spa_permissions_edit_permission_form($role_id)
{
    global $spGlobals;
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery('#rolerow-<?php 
    echo $role_id;
    ?>
').addClass('inForm');
    	spjAjaxForm('sfroleedit<?php 
    echo $role_id;
    ?>
', 'sfreloadpb');
    	jQuery(function(jQuery){vtip();})
    });
</script>
<?php 
    # Get correct tooltips file
    $lang = spa_get_language_code();
    if (empty($lang)) {
        $lang = 'en';
    }
    $ttpath = SPHELP . 'admin/tooltips/admin-permissions-tips-' . $lang . '.php';
    if (file_exists($ttpath) == false) {
        $ttpath = SPHELP . 'admin/tooltips/admin-permissions-tips-en.php';
    }
    if (file_exists($ttpath)) {
        include_once $ttpath;
    }
    $role = spa_get_role_row($role_id);
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=permissions-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=editperm';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfroleedit<?php 
    echo $role->role_id;
    ?>
" name="sfroleedit<?php 
    echo $role->role_id;
    ?>
">
<?php 
    echo sp_create_nonce('forum-adminform_roleedit');
    spa_paint_open_tab(spa_text('Permissions') . ' - ' . spa_text('Manage Permissions'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Edit Permission'), 'true', 'edit-master-permission-set');
    ?>
					<input type="hidden" name="role_id" value="<?php 
    echo $role->role_id;
    ?>
" />
<?php 
    spa_paint_input(spa_text('Permission Set Name'), 'role_name', sp_filter_title_display($role->role_name), false, true);
    spa_paint_input(spa_text('Permission Set Description'), 'role_desc', sp_filter_title_display($role->role_desc), false, true);
    ?>
					<br /><p><strong><?php 
    spa_etext("Permission Set Actions");
    ?>
:</strong></p>
<?php 
    echo '<p><img src="' . SFADMINIMAGES . 'sp_GuestPerm.png" alt="" width="16" height="16" align="top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon will be ignored for Guest Users') . '</small><br />';
    echo '<img src="' . SFADMINIMAGES . 'sp_GlobalPerm.png" alt="" width="16" height="16" align="top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon require enabling to use') . '</small><br />';
    echo '<img src="' . SFADMINIMAGES . 'sp_Warning.png" alt="" width="16" height="16" align="top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon should be used with great care') . '</small></p>';
    sp_build_site_auths_cache();
    $sql = 'SELECT auth_id, auth_name, auth_cat, authcat_name, warning FROM ' . SFAUTHS . '
							JOIN ' . SFAUTHCATS . ' ON ' . SFAUTHS . '.auth_cat = ' . SFAUTHCATS . '.authcat_id
							WHERE active = 1
							ORDER BY auth_cat, auth_id';
    $authlist = spdb_select('set', $sql);
    $role_auths = maybe_unserialize($role->role_auths);
    $firstitem = true;
    $category = '';
    ?>
       				<!-- OPEN OUTER CONTAINER DIV -->
					<div class="outershell" style="width: 100%;">
<?php 
    foreach ($authlist as $a) {
        if ($category != $a->authcat_name) {
            $category = $a->authcat_name;
            if (!$firstitem) {
                ?>
								<!-- CLOSE DOWN THE ENDS -->
								</table></div>
<?php 
            }
            ?>
							<!-- OPEN NEW INNER DIV -->
							<div class="innershell">
							<!-- NEW INNER DETAIL TABLE -->
							<table width="100%" border="0">
							<tr><td colspan="2" class="permhead"><?php 
            spa_etext($category);
            ?>
</td></tr>
<?php 
            $firstitem = false;
        }
        $auth_id = $a->auth_id;
        $auth_name = $a->auth_name;
        $authWarn = empty($a->warning) ? false : true;
        $warn = $authWarn ? ' permwarning' : '';
        $tip = $authWarn ? " class='vtip permwarning' title='" . esc_js(spa_text($a->warning)) . "'" : '';
        $button = 'b-' . $auth_id;
        $checked = '';
        if (isset($role_auths[$auth_id]) && $role_auths[$auth_id]) {
            $checked = ' checked="checked"';
        }
        if ($spGlobals['auths'][$auth_id]->ignored || $spGlobals['auths'][$auth_id]->enabling || $authWarn) {
            $span = '';
        } else {
            $span = ' colspan="2" ';
        }
        ?>
						<tr<?php 
        echo $tip;
        ?>
>
							<td class="permentry<?php 
        echo $warn;
        ?>
">

								<label for="sfR<?php 
        echo $role->role_id . $button;
        ?>
" class="sflabel">
								<img align="top" style="float: right; border: 0pt none ; margin: -4px 5px 0px 3px; padding: 0;" class="vtip" title="<?php 
        echo $tooltips[$auth_name];
        ?>
" src="<?php 
        echo SFADMINIMAGES;
        ?>
sp_Information.png" alt="" />
								<?php 
        spa_etext($spGlobals['auths'][$auth_id]->auth_desc);
        ?>
</label>
								<input type="checkbox" name="<?php 
        echo $button;
        ?>
" id="sfR<?php 
        echo $role->role_id . $button;
        ?>
"<?php 
        echo $checked;
        ?>
  />
								<?php 
        if ($span == '') {
            ?>
									<td align="center" class="permentry" width="32px">
<?php 
        }
        if ($span == '') {
            if ($spGlobals['auths'][$auth_id]->enabling) {
                echo '<img src="' . SFADMINIMAGES . 'sp_GlobalPerm.png" alt="" width="16" height="16" title="' . spa_text('Requires Enabling') . '" />';
            }
            if ($spGlobals['auths'][$auth_id]->ignored) {
                echo '<img src="' . SFADMINIMAGES . 'sp_GuestPerm.png" alt="" width="16" height="16" title="' . spa_text('Ignored for Guests') . '" />';
            }
            if ($authWarn) {
                echo '<img src="' . SFADMINIMAGES . 'sp_Warning.png" alt="" width="16" height="16" title="' . spa_text('Use with Caution') . '" />';
            }
            echo '</td>';
        } else {
            ?>
									</td><td class="permentry" width="32px"></td>
<?php 
        }
        ?>
						</tr>
<?php 
    }
    ?>
					<!-- END CONTAINER DIV -->
					</table></div><div class="clearboth"></div>
					</div>
<?php 
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_perm_edit_perm_panel');
    spa_paint_close_container();
    ?>
		<div class="sfform-submit-bar">
		<input type="submit" class="button-primary" id="sfpermedit<?php 
    echo $role->role_id;
    ?>
" name="sfpermedit<?php 
    echo $role->role_id;
    ?>
" value="<?php 
    spa_etext('Update Permission');
    ?>
" />
		<input type="button" class="button-primary" onclick="javascript:jQuery('#perm-<?php 
    echo $role->role_id;
    ?>
').html('');jQuery('#rolerow-<?php 
    echo $role_id;
    ?>
').removeClass('inForm');" id="sfpermedit<?php 
    echo $role->role_id;
    ?>
" name="editpermcancel<?php 
    echo $role->role_id;
    ?>
" value="<?php 
    spa_etext('Cancel');
    ?>
" />
		</div>
		</form>
	<?php 
    spa_paint_close_tab();
    ?>

	<div class="sfform-panel-spacer"></div>
<?php 
}
 function sp_searchview_query($searchType, $searchInclude)
 {
     global $spVars, $spThisUser;
     # some defaults
     $useLimit = true;
     $TABLE = '';
     $JOIN = '';
     $FIELDS = SFPOSTS . '.topic_id';
     $WHERE = '';
     $ORDERBY = SFPOSTS . '.topic_id DESC';
     # (WHERE) Post content search criteria
     if ($searchType == 1 || $searchType == 2 || $searchType == 3) {
         $useLimit = false;
         # Standard forum search
         if ($searchInclude == 1) {
             # Include = 1 - posts
             $WHERE = $this->searchTerm;
             $TABLE = SFPOSTS;
         } elseif ($searchInclude == 2) {
             # Include = 2 - titles
             $WHERE = $this->searchTerm;
             $TABLE = SFTOPICS;
             $FIELDS = SFTOPICS . '.topic_id';
             $ORDERBY = SFTOPICS . '.topic_id DESC';
         } elseif ($searchInclude == 3) {
             # Include = 3 - posts and titles
             $WHERE = $this->searchTerm;
             $TABLE = SFPOSTS;
             $JOIN = array(SFTOPICS . ' ON ' . SFPOSTS . '.topic_id = ' . SFTOPICS . '.topic_id');
         } else {
             # Plugns can set an alternate TABLE and MATCH statement based on the 'Include' parameter
             $TABLE = apply_filters('sph_search_type_table', SFTOPICS, $searchType, $searchInclude);
             $WHERE = apply_filters('sph_search_include_where', '', $this->searchTerm, $searchType, $searchInclude);
         }
     } elseif ($searchType == 4) {
         # Member 'posted in'
         $WHERE = "user_id={$this->searchTerm}";
         $TABLE = SFPOSTS;
     } elseif ($searchType == 5) {
         # Member 'started'
         $WHERE = "user_id={$this->searchTerm} AND post_index=1";
         $TABLE = SFPOSTS;
     } else {
         # Plugns can set an alternate TABLE and WHERE clause based on the 'Type' parameter
         $TABLE = apply_filters('sph_search_type_table', SFTOPICS, $searchType, $searchInclude);
         $WHERE = apply_filters('sph_search_type_where', '', $this->searchTerm, $searchType, $searchInclude);
     }
     # check if the WHERE clause is empty - probably comes from a legacy url
     if (empty($WHERE)) {
         sp_notify(1, sp_text('Unable to complete this search request'));
         return;
     }
     # Query
     $spdb = new spdbComplex();
     $spdb->table = $TABLE;
     $spdb->fields = $FIELDS;
     if (!empty($JOIN)) {
         $spdb->join = $JOIN;
     }
     $spdb->distinct = true;
     $spdb->found_rows = true;
     $spdb->where = $WHERE . ' AND ' . $TABLE . '.' . $this->forumWhere;
     $spdb->orderby = $ORDERBY;
     if ($useLimit) {
         $spdb->limits = $this->limit;
     }
     # Plugins can alter the final SQL
     $spdb = apply_filters('sph_search_query', $spdb, $this->searchTerm, $searchType, $searchInclude, $this);
     if (!empty($spThisUser->inspect['q_spSearchView'])) {
         $spdb->inspect = 'q_spSearchView';
         $spdb->show = true;
     }
     $records = $spdb->select('col');
     $spVars['searchresults'] = spdb_select('var', 'SELECT FOUND_ROWS()');
     $this->searchCount = $spVars['searchresults'];
     $this->searchInclude = $searchInclude;
     $this->searchType = $searchType;
     return $records;
 }
#
#	CORE
# 	Loaded by core - globally required by back end/admin for all pages
#
# ==========================================================================================
global $wpdb, $spPaths, $spMobile, $spDevice;
if (!defined('SFBLOGID')) {
    define('SFBLOGID', $wpdb->blogid);
}
# Charset
if (!defined('SFCHARSET')) {
    define('SFCHARSET', get_bloginfo('charset'));
}
# Storage Locations
if (is_multisite() && !get_site_option('ms_files_rewriting')) {
    $sp_install_version = spdb_select('var', 'SELECT version FROM ' . SFLOG . ' LIMIT 1');
    if (empty($sp_install_version) || $sp_install_version < 5.6) {
        if (!defined('SF_STORE_DIR')) {
            define('SF_STORE_DIR', WP_CONTENT_DIR);
        }
        if (!defined('SF_STORE_URL')) {
            define('SF_STORE_URL', content_url());
        }
    } else {
        $uploads = sp_get_upload_info();
        if (!defined('SF_STORE_DIR')) {
            define('SF_STORE_DIR', $uploads['basedir']);
        }
        if (!defined('SF_STORE_URL')) {
            define('SF_STORE_URL', $uploads['baseurl']);
        }
Example #20
0
function sp_perform_install($phase, $subphase = 0)
{
    global $current_user, $spVars;
    switch ($phase) {
        case 1:
            # create an array of installed tables to save for uninstall. plugins will add theirs to be sure we get good cleanup
            $tables = array();
            # sfauthcats table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFAUTHCATS . ' (
					authcat_id tinyint(4) NOT NULL auto_increment,
					authcat_name varchar(50) NOT NULL,
					authcat_slug varchar(50) NOT NULL,
					authcat_desc tinytext,
					PRIMARY KEY	 (authcat_id),
					KEY authcat_slug_idx (authcat_slug)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFAUTHCATS;
            # sfauths table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFAUTHS . " (\n\t\t\t\t\tauth_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tauth_name varchar(50) NOT NULL,\n\t\t\t\t\tauth_desc text,\n\t\t\t\t\tactive smallint(1) NOT NULL default '0',\n\t\t\t\t\tignored smallint(1) NOT NULL default '0',\n\t\t\t\t\tenabling smallint(1) NOT NULL default '0',\n\t\t\t\t\tadmin_negate smallint(1) NOT NULL default '0',\n\t\t\t\t\tauth_cat bigint(20) NOT NULL default '1',\n\t\t\t\t\twarning tinytext,\n\t\t\t\t\tPRIMARY KEY\t (auth_id),\n\t\t\t\t\tKEY auth_name_idx (auth_name)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFAUTHS;
            # the cache table (5.4.2)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFCACHE . " (\n\t\t\t\t\tcache_id varchar(40) NOT NULL DEFAULT '',\n\t\t\t\t\tcache_out bigint(6) DEFAULT NULL,\n\t\t\t\t\tcache mediumtext,\n\t\t\t\t\tPRIMARY KEY (cache_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFCACHE;
            # sfdefpermissions table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFDEFPERMISSIONS . " (\n\t\t\t\t\tpermission_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tgroup_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tpermission_role bigint(20) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (permission_id),\n\t\t\t\t\tKEY group_id_idx (group_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id),\n\t\t\t\t\tKEY permission_role_idx (permission_role)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFDEFPERMISSIONS;
            # error log table
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFERRORLOG . " (\n\t\t\t\t\tid bigint(20) NOT NULL auto_increment,\n\t\t\t\t\terror_date datetime NOT NULL,\n\t\t\t\t\terror_type varchar(10) NOT NULL,\n\t\t\t\t\terror_cat varchar(13) NOT NULL default 'spaErrOther',\n\t\t\t\t\tkeycheck varchar(45),\n\t\t\t\t\terror_count smallint(6),\n\t\t\t\t\terror_text text,\n\t\t\t\t\tPRIMARY KEY (id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFERRORLOG;
            # sfforums table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFFORUMS . " (\n\t\t\t\t\tforum_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tforum_name varchar(200) NOT NULL,\n\t\t\t\t\tgroup_id bigint(20) NOT NULL,\n\t\t\t\t\tforum_seq int(4) default NULL,\n\t\t\t\t\tforum_desc text default NULL,\n\t\t\t\t\tforum_status int(4) NOT NULL default '0',\n\t\t\t\t\tforum_disabled smallint(1) NOT NULL default '0',\n\t\t\t\t\tforum_slug varchar(200) NOT NULL,\n\t\t\t\t\tforum_rss text default NULL,\n\t\t\t\t\tforum_icon varchar(50) default NULL,\n\t\t\t\t\tforum_icon_new varchar(50) default NULL,\n\t\t\t\t\tforum_icon_locked varchar(50) default NULL,\n\t\t\t\t\ttopic_icon varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_new varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_locked varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_pinned varchar(50) default NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tpost_id_held bigint(20) default NULL,\n\t\t\t\t\ttopic_count mediumint(8) default '0',\n\t\t\t\t\tpost_count mediumint(8) default '0',\n\t\t\t\t\tpost_count_held mediumint(8) default '0',\n\t\t\t\t\tforum_rss_private smallint(1) NOT NULL default '0',\n\t\t\t\t\tparent bigint(20) NOT NULL default '0',\n\t\t\t\t\tchildren text default NULL,\n\t\t\t\t\tforum_message text,\n\t\t\t\t\tkeywords varchar(256) default NULL,\n\t\t\t\t\tPRIMARY KEY\t (forum_id),\n\t\t\t\t\tKEY group_id_idx (group_id),\n\t\t\t\t\tKEY forum_slug_idx (forum_slug),\n\t\t\t\t\tKEY post_id_idx (post_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFFORUMS;
            # sfgroups table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFGROUPS . ' (
					group_id bigint(20) NOT NULL auto_increment,
					group_name text,
					group_seq int(4) default NULL,
					group_desc text,
					group_rss text,
					group_icon varchar(50) default NULL,
					group_message text,
					PRIMARY KEY	 (group_id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFGROUPS;
            # install log table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFLOG . ' (
					id bigint(20) NOT NULL auto_increment,
					user_id bigint(20) NOT NULL,
					install_date date NOT NULL,
					release_type varchar(20),
					version varchar(10) NOT NULL,
					build int(6) NOT NULL,
					PRIMARY KEY (id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFLOG;
            # install log section table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFLOGMETA . ' (
					id int(11) unsigned NOT NULL AUTO_INCREMENT,
					version varchar(10) DEFAULT NULL,
					log_data tinytext,
					PRIMARY KEY (id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFLOGMETA;
            # sfmembers table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMEMBERS . " (\n\t\t\t\t\tuser_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tdisplay_name varchar(100) default NULL,\n\t\t\t\t\tmoderator smallint(1) NOT NULL default '0',\n\t\t\t\t\tavatar longtext default NULL,\n\t\t\t\t\tsignature text default NULL,\n\t\t\t\t\tposts int(4) default NULL,\n\t\t\t\t\tlastvisit datetime default NULL,\n\t\t\t\t\tnewposts longtext,\n\t\t\t\t\tchecktime datetime default NULL,\n\t\t\t\t\tadmin smallint(1) NOT NULL default '0',\n\t\t\t\t\tfeedkey varchar(36) default NULL,\n\t\t\t\t\tadmin_options longtext default NULL,\n\t\t\t\t\tuser_options longtext default NULL,\n\t\t\t\t\tauths longtext default NULL,\n\t\t\t\t\tmemberships longtext default NULL,\n\t\t\t\t\tplugin_data longtext default NULL,\n\t\t\t\t\tPRIMARY KEY\t (user_id),\n\t\t\t\t\tKEY admin_idx (admin),\n\t\t\t\t\tKEY moderator_idx (moderator)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMEMBERS;
            # sfmemberships table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMEMBERSHIPS . " (\n\t\t\t\t\tmembership_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tuser_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (membership_id),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMEMBERSHIPS;
            # sfmeta table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMETA . " (\n\t\t\t\t\tmeta_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tmeta_type varchar(20) NOT NULL,\n\t\t\t\t\tmeta_key varchar(100) default NULL,\n\t\t\t\t\tmeta_value longtext,\n\t\t\t\t\tautoload tinyint(2) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY (meta_id),\n\t\t\t\t\tKEY meta_type_idx (meta_type),\n\t\t\t\t\tKEY autoload_idx (autoload)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMETA;
            # user notices table
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFNOTICES . " (\n\t\t\t\t\tnotice_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\tguest_email varchar(75) default NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tlink varchar(255) default NULL,\n\t\t\t\t\tlink_text varchar(200) default NULL,\n\t\t\t\t\tmessage varchar(255) NOT NULL default '',\n\t\t\t\t\texpires int(4) default NULL,\n\t\t\t\t\tPRIMARY KEY (notice_id),\n\t\t\t\t\tKEY user_id_idx (user_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFNOTICES;
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFOPTIONS . " (\n\t\t\t\t\toption_id bigint(20) unsigned NOT NULL auto_increment,\n\t\t\t\t\toption_name varchar(64) NOT NULL default '',\n\t\t\t\t\toption_value longtext NOT NULL,\n\t\t\t\t\tPRIMARY KEY (option_name),\n\t\t\t\t\tKEY option_id_idx (option_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFOPTIONS;
            # sfpermissions table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFPERMISSIONS . " (\n\t\t\t\t\tpermission_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tforum_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tpermission_role bigint(20) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (permission_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id),\n\t\t\t\t\tKEY permission_role_idx (permission_role)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFPERMISSIONS;
            # sfposts table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFPOSTS . " (\n\t\t\t\t\tpost_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tpost_content longtext,\n\t\t\t\t\tpost_date datetime NOT NULL,\n\t\t\t\t\ttopic_id bigint(20) NOT NULL,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tguest_name varchar(50) default NULL,\n\t\t\t\t\tguest_email varchar(75) default NULL,\n\t\t\t\t\tpost_status int(4) NOT NULL default '0',\n\t\t\t\t\tpost_pinned smallint(1) NOT NULL default '0',\n\t\t\t\t\tpost_index mediumint(8) default '0',\n\t\t\t\t\tpost_edit mediumtext,\n\t\t\t\t\tposter_ip varchar(39) NOT NULL default '0.0.0.0',\n\t\t\t\t\tcomment_id bigint(20) default NULL,\n\t\t\t\t\tsource smallint(1) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (post_id),\n\t\t\t\t\tKEY topic_id_idx (topic_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY guest_name_idx (guest_name),\n\t\t\t\t\tKEY comment_id_idx (comment_id),\n\t\t\t\t\tKEY post_date_idx (post_date)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFPOSTS;
            # sfroles table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFROLES . " (\n\t\t\t\t\trole_id mediumint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t\trole_name varchar(50) NOT NULL default '',\n\t\t\t\t\trole_desc varchar(150) NOT NULL default '',\n\t\t\t\t\trole_auths longtext NOT NULL,\n\t\t\t\t\tPRIMARY KEY\t (role_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFROLES;
            # special ranks (5.3.2)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFSPECIALRANKS . ' (
					id int(11) unsigned NOT NULL AUTO_INCREMENT,
					user_id bigint(20) default NULL,
					special_rank varchar(100),
					PRIMARY KEY (id),
					KEY user_id_idx (user_id),
					KEY special_rank_idx (special_rank)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFSPECIALRANKS;
            # sftopics table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFTOPICS . " (\n\t\t\t\t\ttopic_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\ttopic_name varchar(200) NOT NULL,\n\t\t\t\t\ttopic_date datetime NOT NULL,\n\t\t\t\t\ttopic_status int(4) NOT NULL default '0',\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\ttopic_pinned smallint(1) NOT NULL default '0',\n\t\t\t\t\ttopic_opened bigint(20) NOT NULL default '0',\n\t\t\t\t\ttopic_slug varchar(200) NOT NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tpost_id_held bigint(20) default NULL,\n\t\t\t\t\tpost_count mediumint(8) default '0',\n\t\t\t\t\tpost_count_held mediumint(8) default '0',\n\t\t\t\t\tPRIMARY KEY\t(topic_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY topic_slug_idx (topic_slug),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY post_id_idx (post_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFTOPICS;
            # sftrack table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFTRACK . " (\n\t\t\t\t\tid bigint(20) NOT NULL auto_increment,\n\t\t\t\t\ttrackuserid bigint(20) default '0',\n\t\t\t\t\ttrackname varchar(50) NOT NULL,\n\t\t\t\t\ttrackdate datetime NOT NULL,\n\t\t\t\t\tforum_id bigint(20) default NULL,\n\t\t\t\t\ttopic_id bigint(20) default NULL,\n\t\t\t\t\tpageview varchar(50) NOT NULL,\n\t\t\t\t\tnotification varchar(1024) default NULL,\n\t\t\t\t\tdevice char(1) default 'D',\n\t\t\t\t\tdisplay varchar(255) default NULL,\n\t\t\t\t\tPRIMARY KEY\t (id),\n\t\t\t\t\tKEY trackuserid_idx (trackuserid),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY topic_id_idx (topic_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFTRACK;
            # user activity (5.3.2 - in preparation)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFUSERACTIVITY . ' (
					id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
					user_id bigint(20) NOT NULL,
					type_id smallint(4) NOT NULL,
					item_id bigint(20) NOT NULL,
					meta_id bigint(20) DEFAULT NULL,
					PRIMARY KEY (id),
					KEY type_id_idx (type_id),
					KEY user_id_idx (user_id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFUSERACTIVITY;
            # sfusergroups table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFUSERGROUPS . " (\n\t\t\t\t\tusergroup_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tusergroup_name text NOT NULL,\n\t\t\t\t\tusergroup_desc text default NULL,\n\t\t\t\t\tusergroup_badge varchar(50) default NULL,\n\t\t\t\t\tusergroup_join tinyint(4) unsigned NOT NULL default '0',\n\t\t\t\t\tusergroup_is_moderator tinyint(4) unsigned NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (usergroup_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFUSERGROUPS;
            # sfwaiting table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFWAITING . " (\n\t\t\t\t\ttopic_id bigint(20) NOT NULL,\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tpost_count int(4) NOT NULL,\n\t\t\t\t\tpost_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tuser_id bigint(20) unsigned default '0',\n\t\t\t\t\tPRIMARY KEY\t (topic_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFWAITING;
            # now save off installed tables
            sp_add_option('installed_tables', $tables);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Tables created') . '</h5>';
            break;
        case 2:
            # populate auths
            spa_setup_auth_cats();
            spa_setup_auths();
            # set up the default permissions/roles
            spa_setup_permissions();
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Permission data built') . '</h5>';
            break;
        case 3:
            # Create default 'Guest' user group data
            $guests = spa_create_usergroup_row('Guests', 'Default Usergroup for guests of the forum', '', '0', '0', false);
            # Create default 'Members' user group data
            $members = spa_create_usergroup_row('Members', 'Default Usergroup for registered users of the forum', '', '0', '0', false);
            # Create default 'Moderators' user group data
            $moderators = spa_create_usergroup_row('Moderators', 'Default Usergroup for moderators of the forum', '', '0', '1', false);
            # Create default user groups
            sp_add_sfmeta('default usergroup', 'sfguests', $guests);
            # default usergroup for guests
            sp_add_sfmeta('default usergroup', 'sfmembers', $members);
            # default usergroup for members
            sp_create_usergroup_meta($members);
            # create default usergroups for existing wp roles
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Usergroup data built') . '</h5>';
            break;
        case 4:
            $page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => $current_user->ID, 'ping_status' => 'closed', 'comment_status' => 'closed', 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'post_content' => '', 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'post_title' => 'Forum', 'page_template' => 'default');
            $page_id = wp_insert_post($page_args);
            $page = spdb_table(SFWPPOSTS, "ID={$page_id}", 'row');
            sp_add_option('sfslug', $page->post_name);
            # Update the guid for the new page
            $guid = get_permalink($page_id);
            spdb_query('UPDATE ' . SFWPPOSTS . " SET guid='{$guid}' WHERE ID={$page_id}");
            sp_add_option('sfpage', $page_id);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Forum page created') . '</h5>';
            break;
        case 5:
            # Create Base Option Records (V1)
            sp_add_option('sfuninstall', false);
            sp_add_option('sfdates', get_option('date_format'));
            sp_add_option('sftimes', get_option('time_format'));
            sp_add_option('sfpermalink', get_permalink(sp_get_option('sfpage')));
            sp_add_option('sflockdown', false);
            $rankdata['posts'] = 2;
            $rankdata['usergroup'] = 'none';
            $rankdata['image'] = 'none';
            sp_add_sfmeta('forum_rank', 'New Member', $rankdata, 1);
            $rankdata['posts'] = 1000;
            $rankdata['usergroup'] = 'none';
            $rankdata['image'] = 'none';
            sp_add_sfmeta('forum_rank', 'Member', $rankdata, 1);
            $sfimage = array();
            $sfimage['enlarge'] = true;
            $sfimage['process'] = true;
            $sfimage['thumbsize'] = 100;
            $sfimage['style'] = 'left';
            $sfimage['constrain'] = true;
            $sfimage['forceclear'] = false;
            sp_add_option('sfimage', $sfimage);
            sp_add_option('sfbadwords', '');
            sp_add_option('sfreplacementwords', '');
            sp_add_option('sfeditormsg', '');
            $sfmail = array();
            $sfmail['sfmailsender'] = get_bloginfo('name');
            $admin_email = get_bloginfo('admin_email');
            $comp = explode('@', $admin_email);
            $sfmail['sfmailfrom'] = $comp[0];
            $sfmail['sfmaildomain'] = $comp[1];
            $sfmail['sfmailuse'] = true;
            sp_add_option('sfmail', $sfmail);
            $sfmail = array();
            $sfmail['sfusespfreg'] = true;
            $sfmail['sfnewusersubject'] = 'Welcome to %BLOGNAME%';
            $sfmail['sfnewusertext'] = 'Welcome %USERNAME% to %BLOGNAME% %NEWLINE%Please find below your login details: %NEWLINE%Username: %USERNAME% %NEWLINE%Password: %PASSWORD% %NEWLINE%%LOGINURL%';
            sp_add_option('sfnewusermail', $sfmail);
            $sfpostmsg = array();
            $sfpostmsg['sfpostmsgtext'] = '';
            $sfpostmsg['sfpostmsgtopic'] = false;
            $sfpostmsg['sfpostmsgpost'] = false;
            sp_add_option('sfpostmsg', $sfpostmsg);
            $sflogin = array();
            $sflogin['sfregmath'] = true;
            $sflogin['sfloginurl'] = sp_url();
            $sflogin['sflogouturl'] = sp_url();
            $sflogin['sfregisterurl'] = '';
            $sflogin['sfloginemailurl'] = esc_url(wp_login_url());
            $sflogin['sptimeout'] = 20;
            sp_add_option('sflogin', $sflogin);
            $sfadminsettings = array();
            $sfadminsettings['sfdashboardstats'] = true;
            $sfadminsettings['sfadminapprove'] = false;
            $sfadminsettings['sfmoderapprove'] = false;
            $sfadminsettings['editnotice'] = true;
            $sfadminsettings['movenotice'] = true;
            sp_add_option('sfadminsettings', $sfadminsettings);
            $sfauto = array();
            $sfauto['sfautoupdate'] = false;
            $sfauto['sfautotime'] = 300;
            sp_add_option('sfauto', $sfauto);
            $sffilters = array();
            $sffilters['sfnofollow'] = false;
            $sffilters['sftarget'] = true;
            $sffilters['sfurlchars'] = 40;
            $sffilters['sffilterpre'] = false;
            $sffilters['sfmaxlinks'] = 0;
            $sffilters['sfnolinksmsg'] = "<b>** you do not have permission to see this link **</b>";
            $sffilters['sfdupemember'] = 0;
            $sffilters['sfdupeguest'] = 0;
            $sffilters['sfmaxsmileys'] = 0;
            sp_add_option('sffilters', $sffilters);
            $sfseo = array();
            $sfseo['sfseo_overwrite'] = false;
            $sfseo['sfseo_blogname'] = false;
            $sfseo['sfseo_pagename'] = false;
            $sfseo['sfseo_homepage'] = true;
            $sfseo['sfseo_topic'] = true;
            $sfseo['sfseo_forum'] = true;
            $sfseo['sfseo_noforum'] = false;
            $sfseo['sfseo_page'] = true;
            $sfseo['sfseo_sep'] = '|';
            sp_add_option('sfseo', $sfseo);
            $sfsigimagesize = array();
            $sfsigimagesize['sfsigwidth'] = 0;
            $sfsigimagesize['sfsigheight'] = 0;
            sp_add_option('sfsigimagesize', $sfsigimagesize);
            # (V4.1.0)
            $sfmembersopt = array();
            $sfmembersopt['sfcheckformember'] = true;
            $sfmembersopt['sfsinglemembership'] = false;
            $sfmembersopt['sfhidestatus'] = true;
            sp_add_option('sfmemberopts', $sfmembersopt);
            $sfcontrols = array();
            $sfcontrols['showtopcount'] = 10;
            $sfcontrols['shownewcount'] = 10;
            $sfcontrols['sfdefunreadposts'] = 50;
            $sfcontrols['sfusersunread'] = false;
            $sfcontrols['sfmaxunreadposts'] = 50;
            sp_add_option('sfcontrols', $sfcontrols);
            $sfblock = array();
            $sfblock['blockadmin'] = false;
            $sfblock['blockprofile'] = false;
            $sfblock['blockroles'] = 'administrator';
            $sfblock['blockredirect'] = get_permalink(sp_get_option('sfpage'));
            sp_add_option('sfblockadmin', $sfblock);
            $sfmetatags = array();
            $sfmetatags['sfdescr'] = '';
            $sfmetatags['sfdescruse'] = 1;
            $sfmetatags['sfusekeywords'] = 2;
            $sfmetatags['sfkeywords'] = 'forum';
            sp_add_option('sfmetatags', $sfmetatags);
            # display array
            $sfdisplay = array();
            $sfdisplay['pagetitle']['notitle'] = false;
            $sfdisplay['pagetitle']['banner'] = '';
            $sfdisplay['forums']['singleforum'] = false;
            $sfdisplay['topics']['perpage'] = 12;
            $sfdisplay['topics']['sortnewtop'] = true;
            $sfdisplay['posts']['perpage'] = 20;
            $sfdisplay['posts']['sortdesc'] = false;
            sp_add_option('sfdisplay', $sfdisplay);
            sp_add_sfmeta('sort_order', 'forum', '', 1);
            sp_add_sfmeta('sort_order', 'topic', '', 1);
            # guest settings
            $sfguests = array();
            $sfguests['reqemail'] = true;
            $sfguests['storecookie'] = true;
            sp_add_option('sfguests', $sfguests);
            # profile management
            $sfprofile = array();
            $sfprofile['nameformat'] = true;
            $sfprofile['fixeddisplayformat'] = 0;
            $sfprofile['namelink'] = 2;
            $sfprofile['displaymode'] = 1;
            $sfprofile['displaypage'] = '';
            $sfprofile['displayquery'] = '';
            $sfprofile['formmode'] = 1;
            $sfprofile['formpage'] = '';
            $sfprofile['formquery'] = '';
            $sfprofile['photosmax'] = 0;
            $sfprofile['photoswidth'] = 0;
            $sfprofile['photosheight'] = 0;
            $sfprofile['firstvisit'] = true;
            $sfprofile['forcepw'] = false;
            sp_add_option('sfprofile', $sfprofile);
            # avatar options
            $sfavatars = array();
            $sfavatars['sfshowavatars'] = true;
            $sfavatars['sfavataruploads'] = true;
            $sfavatars['sfavatarpool'] = false;
            $sfavatars['sfavatarremote'] = false;
            $sfavatars['sfgmaxrating'] = 1;
            $sfavatars['sfavatarsize'] = 50;
            $sfavatars['sfavatarresize'] = true;
            $sfavatars['sfavatarresizequality'] = 90;
            $sfavatars['sfavatarfilesize'] = 10240;
            $sfavatars['sfavatarpriority'] = array(0, 2, 3, 1, 4, 5);
            # gravatar, upload, spf, wp, pool, remote
            sp_add_option('sfavatars', $sfavatars);
            # RSS stuff
            $sfrss = array();
            $sfrss['sfrsscount'] = 15;
            $sfrss['sfrsswords'] = 0;
            $sfrss['sfrsstopicname'] = false;
            $sfrss['sfrssfeedkey'] = true;
            sp_add_option('sfrss', $sfrss);
            sp_add_option('sffiltershortcodes', true);
            sp_add_option('sfwplistpages', true);
            # Script in footer
            sp_add_option('sfscriptfoot', false);
            # the_content filter options
            sp_add_option('sfinloop', false);
            sp_add_option('sfmultiplecontent', true);
            sp_add_option('sfwpheadbypass', false);
            sp_add_option('spwptexturize', false);
            sp_add_option('spheaderspace', 0);
            # auto update stuff in sfmeta
            $autoup = array('spjUserUpdate', 'sp_ahah=autoupdate&amp;sfnonce=' . wp_create_nonce('forum-ahah'));
            sp_add_sfmeta('autoupdate', 'user', $autoup, 1);
            # Set up unique key
            $uKey = substr(chr(rand(97, 122)) . md5(time()), 0, 10);
            sp_add_option('spukey', $uKey);
            # default theme
            $theme = array();
            $theme['theme'] = 'default';
            $theme['style'] = 'default.php';
            $theme['color'] = 'silver';
            sp_add_option('sp_current_theme', $theme);
            $theme = array();
            $theme['active'] = false;
            $theme['theme'] = 'default';
            $theme['style'] = 'default.php';
            $theme['color'] = 'silver';
            $theme['usetemplate'] = false;
            $theme['pagetemplate'] = '';
            $theme['notitle'] = true;
            sp_add_option('sp_mobile_theme', $theme);
            sp_add_option('sp_tablet_theme', $theme);
            sp_add_option('account-name', '');
            sp_add_option('display-name', '');
            sp_add_option('guest-name', '');
            # Create smileys Record
            sp_build_base_smileys();
            # set up daily transient clean up cron
            wp_schedule_event(time(), 'daily', 'sph_transient_cleanup_cron');
            # profile tabs
            spa_new_profile_setup();
            # build the list of moderators per forum
            sp_update_forum_moderators();
            # set up hourly stats generation
            sp_add_option('sp_stats_interval', 3600);
            wp_schedule_event(time(), 'hourly', 'sph_stats_cron');
            # set up weekly news processing
            wp_schedule_event(time(), 'sp_news_interval', 'sph_news_cron');
            sp_add_sfmeta('news', 'news', array('id' => -999.999, 'show' => 0, 'news' => esc_sql(spa_text('Latest Simple Press News will be shown here'))));
            # create initial last post time stamp
            sp_add_option('poststamp', current_time('mysql'));
            # setup mysql search sfmeta values (5.2.0)
            $s = array();
            $v = spdb_select('row', "SHOW VARIABLES LIKE 'ft_min_word_len'");
            empty($v->Value) ? $s['min'] = 4 : ($s['min'] = $v->Value);
            $v = spdb_select('row', "SHOW VARIABLES LIKE 'ft_max_word_len'");
            empty($v->Value) ? $s['max'] = 84 : ($s['max'] = $v->Value);
            sp_add_sfmeta('mysql', 'search', $s, true);
            # combined css and js cache fles
            sp_add_option('combinecss', false);
            sp_add_option('combinejs', false);
            sp_add_option('post_count_delete', false);
            $spError = array();
            $spError['spErrorLogOff'] = false;
            $spError['spNoticesOff'] = false;
            sp_update_option('spErrorOptions', $spError);
            # new posts/topic cached array
            sp_add_sfmeta('topic_cache', 'new', '', true);
            sp_add_option('topic_cache', 200);
            sp_add_option('floodcontrol', 10);
            sp_add_option('captcha-value', time());
            sp_add_option('editpostdays', 7);
            sp_create_inspectors();
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Default forum options created') . '</h5>';
            break;
        case 6:
            # Create sp-resources folder for the current install - does not include themes, plugins or languages
            $perms = fileperms(SF_STORE_DIR);
            $owners = stat(SF_STORE_DIR);
            if ($perms === false) {
                $perms = 0755;
            }
            $basepath = '';
            if (is_multisite()) {
                # construct multisite storage directory structure and create if necessary
                $basepath .= 'blogs.dir/' . SFBLOGID;
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                $basepath .= '/files';
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                $basepath .= '/';
            }
            $basepath .= 'sp-resources';
            if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
            }
            # hive off the basepath for later use - use wp options
            add_option('sp_storage1', SF_STORE_DIR . '/' . $basepath);
            # Did it get created?
            $success = true;
            if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                $success = false;
            }
            sp_add_option('spStorageInstall1', $success);
            # Is the ownership correct?
            $ownersgood = false;
            if ($success) {
                $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                    $ownersgood = true;
                } else {
                    @chown(SF_STORE_DIR . '/' . $basepath, $owners['uid']);
                    @chgrp(SF_STORE_DIR . '/' . $basepath, $owners['gid']);
                    $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                    if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                        $ownersgood = true;
                    }
                }
            }
            sp_add_option('spOwnersInstall1', $ownersgood);
            $basepath .= '/';
            $sfconfig = array();
            $sfconfig['avatars'] = $basepath . 'forum-avatars';
            $sfconfig['avatar-pool'] = $basepath . 'forum-avatar-pool';
            $sfconfig['smileys'] = $basepath . 'forum-smileys';
            $sfconfig['ranks'] = $basepath . 'forum-badges';
            $sfconfig['custom-icons'] = $basepath . 'forum-custom-icons';
            $sfconfig['cache'] = $basepath . 'forum-cache';
            # Create sp-resources folder and themes, plugins and languages folders
            # if not multisite, just add to sp-resource created above
            # if multisite try to use set up of main blog (id 1) or create in wp-content if main blog does not have SP installed
            global $wpdb;
            if (is_multisite()) {
                $basepath = 'sp-resources';
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                # Did it get created?
                $success = true;
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    $success = false;
                }
                sp_add_option('spStorageInstall2', $success);
                # Is the ownership correct?
                $ownersgood = false;
                if ($success) {
                    $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                    if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                        $ownersgood = true;
                    } else {
                        @chown(SF_STORE_DIR . '/' . $basepath, $owners['uid']);
                        @chgrp(SF_STORE_DIR . '/' . $basepath, $owners['gid']);
                        $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                        if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                            $ownersgood = true;
                        }
                    }
                }
                sp_add_option('spOwnersInstall2', $ownersgood);
                add_option('sp_storage2', SF_STORE_DIR . '/' . $basepath);
                $basepath .= '/';
                if ($wpdb->blogid == 1) {
                    $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                    $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                    $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                    $sfconfig['plugins'] = $basepath . 'forum-plugins';
                    $sfconfig['themes'] = $basepath . 'forum-themes';
                } else {
                    $blog_prefix = $wpdb->get_blog_prefix(1);
                    $row = $wpdb->get_row("SELECT * FROM {$blog_prefix}sfoptions WHERE option_name 'sfconfig'");
                    if (is_object($row)) {
                        $mainConfig = unserialize($row->option_value);
                        $sfconfig['language-sp'] = $mainConfig['language-sp'];
                        $sfconfig['language-sp-plugins'] = $mainConfig['language-sp-plugins'];
                        $sfconfig['language-sp-themes'] = $mainConfig['language-sp-themes'];
                        $sfconfig['plugins'] = $mainConfig['plugins'];
                        $sfconfig['themes'] = $mainConfig['themes'];
                    } else {
                        $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                        $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                        $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                        $sfconfig['plugins'] = $basepath . 'forum-plugins';
                        $sfconfig['themes'] = $basepath . 'forum-themes';
                    }
                }
            } else {
                add_option('sp_storage2', get_option('sp_storage1'));
                sp_add_option('spStorageInstall2', true);
                sp_add_option('spOwnersInstall2', true);
                $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                $sfconfig['plugins'] = $basepath . 'forum-plugins';
                $sfconfig['themes'] = $basepath . 'forum-themes';
            }
            sp_add_option('sfconfig', $sfconfig);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            if ($success) {
                spa_etext('Storage location created') . '</h5>';
            } else {
                spa_etext('Storage location creation failed') . '</h5>';
            }
            break;
        case 7:
            # Move and extract zip install archives
            # first do stuff that could be in blogs.dir for multisite
            $successCopy1 = false;
            $successExtract1 = false;
            $zipfile = SF_PLUGIN_DIR . '/sp-startup/install/sp-resources-install-part1.zip';
            $extract_to = get_option('sp_storage1');
            # Copy the zip file
            if (@copy($zipfile, $extract_to . '/sp-resources-install-part1.zip')) {
                $successCopy1 = true;
                # Now try and unzip it
                require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
                $zipfile = $extract_to . '/sp-resources-install-part1.zip';
                $zipfile = str_replace('\\', '/', $zipfile);
                # sanitize for Win32 installs
                $zipfile = preg_replace('|/+|', '/', $zipfile);
                # remove any duplicate slash
                $extract_to = str_replace('\\', '/', $extract_to);
                # sanitize for Win32 installs
                $extract_to = preg_replace('|/+|', '/', $extract_to);
                # remove any duplicate slash
                $archive = new PclZip($zipfile);
                $archive->extract($extract_to);
                if ($archive->error_code == 0) {
                    $successExtract1 = true;
                    # Lets try and remove the zip as it seems to have worked
                    @unlink($zipfile);
                }
            }
            sp_add_option('spCopyZip1', $successCopy1);
            sp_add_option('spUnZip1', $successExtract1);
            # now do stuff that could should not be blogs.dir for multisite
            $successCopy2 = false;
            $successExtract2 = false;
            $zipfile = SF_PLUGIN_DIR . '/sp-startup/install/sp-resources-install-part2.zip';
            $extract_to = get_option('sp_storage2');
            # Copy the zip file
            if (@copy($zipfile, $extract_to . '/sp-resources-install-part2.zip')) {
                $successCopy2 = true;
                # Now try and unzip it
                require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
                $zipfile = $extract_to . '/sp-resources-install-part2.zip';
                $zipfile = str_replace('\\', '/', $zipfile);
                # sanitize for Win32 installs
                $zipfile = preg_replace('|/+|', '/', $zipfile);
                # remove any duplicate slash
                $extract_to = str_replace('\\', '/', $extract_to);
                # sanitize for Win32 installs
                $extract_to = preg_replace('|/+|', '/', $extract_to);
                # remove any duplicate slash
                $archive = new PclZip($zipfile);
                $archive->extract($extract_to);
                if ($archive->error_code == 0) {
                    $successExtract2 = true;
                    # Lets try and remove the zip as it seems to have worked
                    @unlink($zipfile);
                }
            }
            sp_add_option('spCopyZip2', $successCopy2);
            sp_add_option('spUnZip2', $successExtract2);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            if ($successCopy1 && $successExtract1 && $successCopy2 && $successExtract2) {
                spa_etext('Resources created') . '</h5>';
            } elseif (!$successCopy1 || !$successCopy2) {
                spa_etext('Resources file failed to copy') . '</h5>';
            } elseif (!$successExtract1 || !$successExtract2) {
                spa_etext('Resources file failed to unzip');
                echo ' - ' . $archive->error_string . '</h5>';
            }
            break;
        case 8:
            # CREATE MEMBERS TABLE ---------------------------
            sp_install_members_table($subphase);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            echo spa_text('Members data created for existing users') . ' ' . (($subphase - 1) * 200 + 1) . ' - ' . $subphase * 200 . '</h5>';
            break;
        case 9:
            # add our caps
            sp_add_caps();
            # grant spf capabilities to installer
            $user = new WP_User($current_user->ID);
            $user->add_cap('SPF Manage Options');
            $user->add_cap('SPF Manage Forums');
            $user->add_cap('SPF Manage User Groups');
            $user->add_cap('SPF Manage Permissions');
            $user->add_cap('SPF Manage Components');
            $user->add_cap('SPF Manage Admins');
            $user->add_cap('SPF Manage Users');
            $user->add_cap('SPF Manage Profiles');
            $user->add_cap('SPF Manage Toolbox');
            $user->add_cap('SPF Manage Plugins');
            $user->add_cap('SPF Manage Themes');
            $user->add_cap('SPF Manage Integration');
            sp_update_member_item($current_user->ID, 'admin', 1);
            # admin your option defaults
            $sfadminoptions = array();
            $sfadminoptions['sfnotify'] = false;
            $sfadminoptions['notify-edited'] = true;
            sp_update_member_item($current_user->ID, 'admin_options', $sfadminoptions);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Admin permission data built') . '</h5>';
            break;
        case 10:
            # UPDATE VERSION/BUILD NUMBERS -------------------------
            sp_log_event(SPRELEASE, SPVERSION, SPBUILD);
            # Lets update permalink and force a rewrite rules flush
            sp_update_permalink(true);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Version number updated') . '</h5>';
            break;
        case 11:
            # REPORTS ERRORS IF COPY OR UNZIP FAILED ---------------
            $sCreate1 = sp_get_option('spStorageInstall1');
            $sCreate2 = sp_get_option('spStorageInstall2');
            $sOwners1 = sp_get_option('spOwnersInstall1');
            $sOwners2 = sp_get_option('spOwnersInstall2');
            $sCopy1 = sp_get_option('spCopyZip1');
            $sUnzip1 = sp_get_option('spUnZip1');
            $sCopy2 = sp_get_option('spCopyZip2');
            $sUnzip2 = sp_get_option('spUnZip2');
            if ($sCreate1 && $sCreate2 && $sCopy1 && $sUnzip1 && $sCopy2 && $sUnzip2 && $sOwners1 && $sOwners2) {
                echo '<h5>' . spa_text('The installation has been completed') . '</h5>';
            } else {
                $image = "<img src='" . SF_PLUGIN_URL . "/sp-startup/install/resources/images/important.png' alt='' style='float:left;padding: 5px 5px 20px 0;' />";
                echo '<h5>';
                spa_etext('YOU WILL NEED TO PERFORM THE FOLLOWING TASKS TO ALLOW SIMPLE:PRESS TO WORK CORRECTLY');
                echo '</h5><br />';
                if (!$sCreate1) {
                    echo $image . '<p style="margin-top:0">[';
                    spa_etext('Storage location part 1 creation failed');
                    echo '] - ';
                    echo spa_text('You will need to manually create a required a folder named') . ': ' . get_option('sp_storage1');
                    echo '</p>';
                } else {
                    if (!$sOwners1) {
                        echo $image . '<p>[';
                        spa_etext('Storage location part 1 ownership failed');
                        echo '] - ';
                        echo spa_text('We were unable to create your folders with the correct server ownership and these will need to be manually changed') . ': ' . get_option('sp_storage1');
                        echo '</p>';
                    }
                }
                if (!$sCreate2) {
                    echo $image . '<p>[';
                    spa_etext('Storage location part 2 creation failed');
                    echo '] - ';
                    echo spa_text('You will need to manually create a required a folder named') . ': ' . get_option('sp_storage2');
                    echo '</p>';
                } elseif (!$sOwners2) {
                    echo $image . '<p>[';
                    spa_etext('Storage location part 2 ownership failed');
                    echo '] - ';
                    echo spa_text('We were unable to create your folders with the correct server ownership and these will need to be manually changed') . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
                if (!$sCopy1) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 1 file failed to copy');
                    echo '] - ';
                    echo spa_text("You will need to manually copy and extract the file '/simple-press/sp-startup/install/sp-resources-install-part1.zip' to the new folder") . ': ' . get_option('sp_storage1');
                    echo '</p>';
                }
                if (!$sCopy2) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to copy');
                    echo '] - ';
                    echo spa_text("You will need to manually copy and extract the file '/simple-press/sp-startup/install/sp-resources-install-part2.zip' to the new folder") . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
                if (!$sUnzip1) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to unzip');
                    echo '] - ';
                    echo spa_text("You will need to manually unzip the file 'sp-resources-install-part1.zip' in the new folder") . ': ' . get_option('sp_storage1');
                    echo '</p>';
                }
                if (!$sUnzip2) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to unzip');
                    echo '] - ';
                    echo spa_text("You will need to manually unzip the file 'sp-resources-install-part2.zip' in the new folder") . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
            }
            delete_option('sfInstallID');
            delete_option('sp_storage1');
            delete_option('sp_storage2');
            sp_delete_option('spStorageInstall1');
            sp_delete_option('spStorageInstall2');
            sp_delete_option('spOwnersInstall1');
            sp_delete_option('spOwnersInstall2');
            sp_delete_option('spCopyZip1');
            sp_delete_option('spCopyZip2');
            sp_delete_option('spUnZip1');
            sp_delete_option('spUnZip2');
            break;
    }
}
function sp_get_slugs_from_postid($postid)
{
    if (!$postid) {
        return '';
    }
    return spdb_select('row', 'SELECT forum_slug, topic_slug, post_index
			 FROM ' . SFPOSTS . '
			 JOIN ' . SFFORUMS . ' ON ' . SFPOSTS . '.forum_id = ' . SFFORUMS . '.forum_id
			 JOIN ' . SFTOPICS . ' ON ' . SFPOSTS . '.topic_id = ' . SFTOPICS . '.topic_id
			 WHERE ' . SFPOSTS . ".post_id={$postid}");
}
$Rev: 11507 $
*/
if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
    die('Access denied - you cannot directly call this file');
}
sp_forum_api_support();
$forumid = sp_esc_int($_GET['forum']);
if (empty($forumid)) {
    die;
}
$userid = sp_esc_int($_GET['userid']);
if (empty($forumid)) {
    die;
}
$sql = "SELECT auth_id, auth_name, auth_cat, authcat_name FROM " . SFAUTHS . "\n\t\tJOIN " . SFAUTHCATS . " ON " . SFAUTHS . ".auth_cat = " . SFAUTHCATS . ".authcat_id\n\t\tWHERE active = 1\n\t\tORDER BY auth_cat, auth_id";
$authlist = spdb_select('set', $sql);
global $spGlobals;
$curcol = 1;
$category = '';
foreach ($authlist as $a) {
    $auth_id = $a->auth_id;
    $auth_name = $a->auth_name;
    if ($category != $a->authcat_name) {
        $category = $a->authcat_name;
        $curcol = 1;
        echo '<div class="spAuthCat">' . spa_text($category) . '</div>';
    }
    echo '<div class="spColumnSection">';
    if (sp_get_auth($auth_name, $forumid, $userid)) {
        echo '<img src="' . sp_find_icon(SPTHEMEICONSURL, 'sp_PermissionYes.png') . '" />&nbsp;&nbsp;' . spa_text($spGlobals['auths'][$auth_id]->auth_desc);
    } else {
 function select($type = 'set', $resulttype = OBJECT)
 {
     if (empty($this->table)) {
         return '';
     }
     $table = $this->table;
     $found_rows = empty($this->found_rows) ? '' : ' SQL_CALC_FOUND_ROWS';
     $distinct = empty($this->distinct) ? '' : ' DISTINCT';
     $where = empty($this->where) ? '' : " WHERE {$this->where}";
     $limits = empty($this->limits) ? '' : " LIMIT {$this->limits}";
     $fields = empty($this->fields) ? ' *' : " {$this->fields}";
     $join = '';
     if (!empty($this->join)) {
         if (is_array($this->join)) {
             foreach ($this->join as $j) {
                 $join .= " JOIN {$j}";
             }
         } else {
             $join = " JOIN {$this->join}";
         }
     }
     $left_join = '';
     if (!empty($this->left_join)) {
         if (is_array($this->left_join)) {
             foreach ($this->left_join as $j) {
                 $left_join .= " LEFT JOIN {$j}";
             }
         } else {
             $left_join = " LEFT JOIN {$this->left_join}";
         }
     }
     $right_join = '';
     if (!empty($this->right_join)) {
         if (is_array($this->right_join)) {
             foreach ($this->right_join as $j) {
                 $right_join .= " RIGHT JOIN {$j}";
             }
         } else {
             $right_join = " RIGHT JOIN {$this->right_join}";
         }
     }
     $groupby = '';
     if (!empty($this->groupby)) {
         if (is_array($this->groupby)) {
             $groupby = ' GROUP BY';
             foreach ($this->groupby as $i => $g) {
                 $groupby = $i == 0 ? ' ' : ', ';
                 $groupby .= $g;
             }
         } else {
             $groupby = " GROUP BY {$this->groupby}";
         }
     }
     $orderby = '';
     if (!empty($this->orderby)) {
         if (is_array($this->orderby)) {
             $orderby = ' ORDER BY';
             foreach ($this->orderby as $i => $o) {
                 $orderby = $i == 0 ? ' ' : ', ';
                 $orderby .= $o;
             }
         } else {
             $orderby = " ORDER BY {$this->orderby}";
         }
     }
     $sql = "SELECT {$found_rows}{$distinct}{$fields} FROM {$table}{$join}{$left_join}{$right_join}{$where}{$groupby}{$orderby}{$limits}";
     if ($this->show) {
         spdb_show_result($sql, $this->inspect);
     }
     $records = spdb_select($type, $sql, $resulttype);
     return $records;
 }
function sp_get_login_display_name($login_name)
{
    return spdb_select('var', 'SELECT ' . SFMEMBERS . '.display_name
			 FROM ' . SFMEMBERS . '
			 JOIN ' . SFUSERS . ' ON ' . SFUSERS . '.ID = ' . SFMEMBERS . ".user_id\n\t\t\t WHERE user_login='******'");
}
Example #25
0
function sp_fix_shortened_links()
{
    $postCount = spdb_count(SFPOSTS);
    $limit = 1000;
    for ($offset = 0; $offset < $postCount; $offset += $limit) {
        $posts = spdb_select('set', 'SELECT post_id, post_content FROM ' . SFPOSTS . " ORDER BY post_id ASC LIMIT {$offset}, {$limit}");
        foreach ($posts as $post) {
            /*
                Matches would be:
                0 = The entire string
                1 = The link in the <a> tag
                2 = The rest of the parameters in the <a> tag (nofollow, target, etc.)
                3 = The part after the 5 periods
            
                So then we want to replace 0 with 1 for each result
            
                We are assuming that the links have 5 consecutive periods
            */
            $postContent = stripslashes($post->post_content);
            preg_match_all("/<a href=\"(.*?)\"(.*?)\\.\\.\\.\\.\\.(.*?)<\\/a>/is", $postContent, $linkMatches);
            if (!empty($linkMatches[0])) {
                foreach ($linkMatches[0] as $index => $stringMatch) {
                    $postContent = str_replace($stringMatch, $linkMatches[1][$index], $postContent);
                }
                $postContent = esc_sql($postContent);
                spdb_query('UPDATE ' . SFPOSTS . " SET post_content = '{$postContent}' WHERE post_id = {$post->post_id}");
            }
        }
    }
}
function spa_get_query_max($msbox, $uid, $filter)
{
    global $wpdb;
    $like = '';
    if ($filter != '') {
        $like = " WHERE display_name LIKE '%" . esc_sql($wpdb->esc_like($filter)) . "%'";
    }
    $max = spdb_select('var', '
		SELECT COUNT(*) AS user_count
		FROM sftempmembers' . $like);
    if (!$max) {
        $max = 0;
    }
    return $max;
}
function spa_permissions_add_permission_form()
{
    ?>
<script type="text/javascript">
    jQuery(document).ready(function() {
    	spjAjaxForm('sfrolenew', 'sfreloadpb');
    });
</script>
<?php 
    # Get correct tooltips file
    $lang = spa_get_language_code();
    if (empty($lang)) {
        $lang = 'en';
    }
    $ttpath = SPHELP . 'admin/tooltips/admin-permissions-tips-' . $lang . '.php';
    if (file_exists($ttpath) == false) {
        $ttpath = SPHELP . 'admin/tooltips/admin-permissions-tips-en.php';
    }
    if (file_exists($ttpath)) {
        include_once $ttpath;
    }
    global $spGlobals;
    spa_paint_options_init();
    $ahahURL = SFHOMEURL . 'index.php?sp_ahah=permissions-loader&amp;sfnonce=' . wp_create_nonce('forum-ahah') . '&amp;saveform=addperm';
    ?>
	<form action="<?php 
    echo $ahahURL;
    ?>
" method="post" id="sfrolenew" name="sfrolenew">
<?php 
    echo sp_create_nonce('forum-adminform_rolenew');
    spa_paint_open_tab(spa_text('Permissions') . " - " . spa_text('Add New Permission'), true);
    spa_paint_open_panel();
    spa_paint_open_fieldset(spa_text('Add New Permission'), 'true', 'create-new-permission-set');
    spa_paint_input(spa_text('Permission Set Name'), "role_name", '', false, true);
    spa_paint_input(spa_text('Permission Set Description'), "role_desc", '', false, true);
    spa_paint_select_start(spa_text('Clone Existing Permission Set'), 'role', 'role');
    spa_display_permission_select('', false);
    spa_paint_select_end('<small>(' . spa_text('Select an existing Permission Set to Clone.  Any settings below will be ignored.') . ')</small>');
    ?>
					<br /><p><strong><?php 
    spa_etext('Permission Set Actions');
    ?>
:</strong></p>
<?php 
    echo '<p><img src="' . SFADMINIMAGES . 'sp_GuestPerm.png" alt="" style="width:16px;height:16px;vertical-align:top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon will be ignored for Guest Users') . '</small>';
    echo '&nbsp;&nbsp;&nbsp;<img src="' . SFADMINIMAGES . 'sp_GlobalPerm.png" alt="" style="width:16px;height:16px;vertical-align:top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon require enabling to use') . '</small>';
    echo '&nbsp;&nbsp;&nbsp;<img src="' . SFADMINIMAGES . 'sp_Warning.png" alt="" style="width:16px;height:16px;vertical-align:top" />';
    echo '<small>&nbsp;' . spa_text('Note: Action settings displaying this icon should be used with great care') . '</small></p>';
    sp_build_site_auths_cache();
    $sql = 'SELECT auth_id, auth_name, auth_cat, authcat_name, warning FROM ' . SFAUTHS . '
							JOIN ' . SFAUTHCATS . ' ON ' . SFAUTHS . '.auth_cat = ' . SFAUTHCATS . '.authcat_id
							WHERE active = 1
							ORDER BY auth_cat, auth_id';
    $authlist = spdb_select('set', $sql);
    $firstitem = true;
    $category = '';
    ?>
					<!-- OPEN OUTER CONTAINER DIV -->
					<div class="outershell" style="width: 100%;">
<?php 
    foreach ($authlist as $a) {
        if ($category != $a->authcat_name) {
            $category = $a->authcat_name;
            if (!$firstitem) {
                ?>
								<!-- CLOSE DOWN THE ENDS -->
								</table></div>
<?php 
            }
            ?>
							<!-- OPEN NEW INNER DIV -->
							<div class="innershell">
							<!-- NEW INNER DETAIL TABLE -->
							<table style="width:100%;border:0">
							<tr><td colspan="2" class="permhead"><?php 
            spa_etext($category);
            ?>
</td></tr>
<?php 
            $firstitem = false;
        }
        $auth_id = $a->auth_id;
        $auth_name = $a->auth_name;
        $authWarn = empty($a->warning) ? false : true;
        $warn = $authWarn ? " permwarning" : '';
        $tip = $authWarn ? " class='permwarning' title='" . esc_js(spa_text($a->warning)) . "'" : '';
        $button = 'b-' . $auth_id;
        if ($spGlobals['auths'][$auth_id]->ignored || $spGlobals['auths'][$auth_id]->enabling || $authWarn) {
            $span = '';
        } else {
            $span = ' colspan="2" ';
        }
        ?>
							<tr<?php 
        echo $tip;
        ?>
>
								<td class="permentry<?php 
        echo $warn;
        ?>
">

								<input type="checkbox" name="<?php 
        echo $button;
        ?>
" id="sf<?php 
        echo $button;
        ?>
"  />
								<label for="sf<?php 
        echo $button;
        ?>
" class="sflabel">
								<img style="text-align:top;float: right; border: 0pt none ; margin: -4px 5px 0px 3px; padding: 0;" class="" title="<?php 
        echo $tooltips[$auth_name];
        ?>
" src="<?php 
        echo SFADMINIMAGES;
        ?>
sp_Information.png" alt="" />
								<?php 
        spa_etext($spGlobals['auths'][$auth_id]->auth_desc);
        ?>
</label>
								<?php 
        if ($span == '') {
            ?>
									<td style="text-align:center;width:32px" class="permentry">
<?php 
        }
        if ($span == '') {
            if ($spGlobals['auths'][$auth_id]->enabling) {
                echo '<img src="' . SFADMINIMAGES . 'sp_GlobalPerm.png" alt="" style="width:16px;height:16px" title="' . spa_text('Requires Enabling') . '" />';
            }
            if ($spGlobals['auths'][$auth_id]->ignored) {
                echo '<img src="' . SFADMINIMAGES . 'sp_GuestPerm.png" alt="" style="width:16px;height:16px" title="' . spa_text('Ignored for Guests') . '" />';
            }
            if ($authWarn) {
                echo '<img src="' . SFADMINIMAGES . 'sp_Warning.png" alt="" style="width:16px;height:16px" title="' . spa_text('Use with Caution') . '" />';
            }
            echo '</td>';
        } else {
            ?>
								    </td><td class="permentry" style="width:32px"></td>
                                <?php 
        }
        ?>
							</tr>
                        <?php 
    }
    ?>
					<!-- END CONTAINER DIV -->
					</table></div><div class="clearboth"></div>
					</div>
<?php 
    spa_paint_close_fieldset();
    spa_paint_close_panel();
    do_action('sph_perm_add_perm_panel');
    spa_paint_close_container();
    ?>
	<div class="sfform-submit-bar">
	<input type="submit" class="button-primary" id="saveit" name="saveit" value="<?php 
    spa_etext('Create New Permission');
    ?>
" />
	</div>
	<?php 
    spa_paint_close_tab();
    ?>
	</form>
	<div class="sfform-panel-spacer"></div>
<?php 
}
Example #28
0
function sp_get_special_rank($userid, $rank = '')
{
    $userid = (int) $userid;
    $where = ' WHERE user_id=' . $userid;
    if ($rank != '') {
        $where .= ' AND special_rank="' . $rank . '"';
    }
    return spdb_select('col', 'SELECT special_rank FROM ' . SFSPECIALRANKS . $where);
}
function spa_setup_auth_cats()
{
    global $spVars;
    # have the auths tables been created?
    $auths = spdb_select('var', "SHOW TABLES LIKE '" . SFAUTHS . "'");
    # default auths
    sp_create_auth_cat(spa_text('General'), spa_text('auth category for general auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='use_pm'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='rate_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='watch'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='subscribe'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='report_posts'");
    }
    # viewing auths
    sp_create_auth_cat(spa_text('Viewing'), spa_text('auth category for viewing auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_forum'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_forum_lists'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_forum_topic_lists'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_admin_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_own_admin_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_email'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_profiles'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_members_list'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_links'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_online_activity'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='download_attachments'");
    }
    # creating auths
    sp_create_auth_cat(spa_text('Creating'), spa_text('auth category for creating auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='start_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='reply_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_flood_control'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='reply_own_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='use_spoilers'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='use_signatures'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='create_links'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='create_linked_topics'");
    }
    # editing auths
    sp_create_auth_cat(spa_text('Editing'), spa_text('auth category for editing auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_own_topic_titles'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_any_topic_titles'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_own_posts_forever'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_own_posts_reply'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_any_post'");
    }
    # deleting auths
    sp_create_auth_cat(spa_text('Deleting'), spa_text('auth category for deleting auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='delete_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='delete_own_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='delete_any_post'");
    }
    # moderation auths
    sp_create_auth_cat(spa_text('Moderation'), spa_text('auth category for moderation auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_math_question'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_moderation'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_moderation_once'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='moderate_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_captcha'");
    }
    # tools auths
    sp_create_auth_cat(spa_text('Tools'), spa_text('auth category for tools auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='pin_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='move_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='move_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='lock_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='pin_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='reassign_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='break_linked_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_tags'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='change_topic_status'");
    }
    # uploading auths
    sp_create_auth_cat(spa_text('Uploading'), spa_text('auth category for uploading auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_avatars'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_images'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_media'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_files'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_signatures'");
    }
}
Example #30
0
function sp_remove_waiting_queue()
{
    $rows = spdb_select('col', 'SELECT topic_id FROM ' . SFWAITING);
    if ($rows) {
        $queued = array();
        foreach ($rows as $row) {
            $queued[] = $row;
        }
        foreach ($queued as $topic) {
            sp_remove_from_waiting(true, $topic);
        }
    }
}