function sp_admin_bar_do_upgrade_check()
{
    if (!sp_is_plugin_active('admin-bar/sp-admin-bar-plugin.php')) {
        return;
    }
    $options = sp_get_option('spAdminBar');
    $db = $options['dbversion'];
    if (empty($db)) {
        $db = 0;
    }
    # quick bail check
    if ($db == SPABDBVERSION) {
        return;
    }
    # apply upgrades as needed
    if ($db < 1) {
        # empty since plugin did not used db on initial release
    }
    if ($db < 2) {
        # set autoload flag to true for autoupdates
        $meta = sp_get_sfmeta('autoupdate', 'admin');
        if (!empty($meta[0])) {
            sp_update_sfmeta('autoupdate', 'admin', $meta[0]['meta_value'], $meta[0]['meta_id'], 1);
        }
    }
    if ($db < 3) {
        # permission for bypassing akismet checks
        sp_add_auth('bypass_akismet', __('Can bypass akismet check on posts', 'spab'), 1, 0, 0, 0, 3);
        sp_activate_auth('bypass_akismet');
    }
    # save data
    $options['dbversion'] = SPABDBVERSION;
    sp_update_option('spAdminBar', $options);
}
function sp_admin_bar_admin_options_save()
{
    $options = '';
    $options['dashboardposts'] = isset($_POST['dashboardposts']);
    sp_update_option('spAdminBar', $options);
    sp_update_option('spAkismet', sp_esc_int($_POST['spAkismet']));
    return __('Admin bar options updated!', 'spab');
}
function sp_captcha_admin_options_save()
{
    $captcha = array();
    $captcha['registration'] = isset($_POST['registration']);
    sp_update_option('spCaptcha', $captcha);
    do_action('sph_captcha_uploads_save');
    return __('Captcha options updated!', 'sp-cap');
}
function sp_captcha_do_install()
{
    $captcha = sp_get_option('spCaptcha');
    if (empty($captcha)) {
        $captcha['registration'] = true;
        $captcha['dbversion'] = SPCAPTCHADBVERSION;
        sp_update_option('spCaptcha', $captcha);
    }
    # add a new permission into the auths table
    sp_add_auth('bypass_captcha', __('Can bypass the post captcha check', 'sp-cap'), 1, 0, 0, 0, 6);
    sp_activate_auth('bypass_captcha');
}
function spa_save_admins_global_options_data()
{
    check_admin_referer('global-admin_options', 'global-admin_options');
    # admin settings group
    $sfadminsettings = array();
    $sfadminsettings['sfdashboardstats'] = isset($_POST['sfdashboardstats']);
    $sfadminsettings['sfadminapprove'] = isset($_POST['sfadminapprove']);
    $sfadminsettings['sfmoderapprove'] = isset($_POST['sfmoderapprove']);
    $sfadminsettings['editnotice'] = isset($_POST['editnotice']);
    $sfadminsettings['movenotice'] = isset($_POST['movenotice']);
    sp_update_option('sfadminsettings', $sfadminsettings);
    do_action('sph_admin_global_options_save');
    $mess = spa_text('Admin global options updated');
    return $mess;
}
function sp_featured_do_install()
{
    $options = sp_get_option('featured');
    if (empty($options)) {
        $options['dbversion'] = SPFEATUREDDBVERSION;
        sp_update_option('featured', $options);
    }
    # set up our sfmeta if needed
    $check = sp_get_sfmeta('featured', 'topics');
    if (empty($check)) {
        sp_add_sfmeta('featured', 'topics', array(), true);
    }
    $check = sp_get_sfmeta('featured', 'posts');
    if (empty($check)) {
        sp_add_sfmeta('featured', 'posts', array(), true);
    }
}
function sp_admin_bar_do_install()
{
    global $spThisUser;
    $oldOptions = sp_get_option('sfadminsettings');
    $newOptions = sp_get_option('spAdminBar');
    if (!isset($oldOptions['sfqueue']) && empty($newOptions)) {
        $newOptions = array();
        $newOptions['dashboardposts'] = false;
        $newOptions['dbversion'] = SPABDBVERSION;
        sp_add_option('spAdminBar', $newOptions);
        $options = sp_get_member_item($spThisUser->ID, 'admin_options');
        $options['sfadminbar'] = true;
        sp_update_member_item($spThisUser->ID, 'admin_options', $options);
    } else {
        if (empty($newOptions)) {
            $newOptions = array();
            $newOptions['dashboardposts'] = $oldOptions['sfdashboardposts'];
            $newOptions['dbversion'] = SPABDBVERSION;
            sp_add_option('spAdminBar', $newOptions);
            $options = sp_get_member_item($spThisUser->ID, 'admin_options');
            $options['sfadminbar'] = true;
            sp_update_member_item($spThisUser->ID, 'admin_options', $options);
            unset($oldOptions['sfqueue']);
            unset($oldOptions['sfmodasadmin']);
            unset($oldOptions['sfshowmodposts']);
            unset($oldOptions['sfbaronly']);
            unset($oldOptions['sfdashboardposts']);
            sp_update_option('sfadminsettings', $oldOptions);
        }
    }
    # permission for bypassing akismet checks
    sp_add_auth('bypass_akismet', __('Can bypass akismet check on posts', 'spab'), 1, 0, 0, 0, 3);
    sp_activate_auth('bypass_akismet');
    # create new Akismet setting
    $akismet = sp_get_option('spAkismet');
    if (empty($akismet)) {
        sp_add_option('spAkismet', 1);
    }
    # get auto update running
    $autoup = array('spabupdate', 'sp_ahah=admin-bar-update&amp;target=newposts');
    sp_add_sfmeta('autoupdate', 'admin', $autoup, 1);
}
function sp_featured_do_upgrade_check()
{
    if (!sp_is_plugin_active('featured/sp-featured-plugin.php')) {
        return;
    }
    $options = sp_get_option('featured');
    $db = $options['dbversion'];
    if (empty($db)) {
        $db = 0;
    }
    # quick bail check
    if ($db == SPFEATUREDDBVERSION) {
        return;
    }
    # apply upgrades as needed
    # db version upgrades
    # save data
    $options['dbversion'] = SPFEATUREDDBVERSION;
    sp_update_option('featured', $options);
}
function sp_cron_generate_stats()
{
    $counts = sp_get_stats_counts();
    sp_update_option('spForumStats', $counts);
    $stats = sp_get_membership_stats();
    sp_update_option('spMembershipStats', $stats);
    $spControls = sp_get_option('sfcontrols');
    $topPosters = sp_get_top_poster_stats((int) $spControls['showtopcount']);
    sp_update_option('spPosterStats', $topPosters);
    $mods = sp_get_moderator_stats();
    sp_update_option('spModStats', $mods);
    $admins = sp_get_admin_stats();
    sp_update_option('spAdminStats', $admins);
    do_action('sph_stats_cron_run');
}
function spa_permalink_changed($old, $new)
{
    global $wp_rewrite;
    if (empty($new)) {
        $perm = user_trailingslashit(SFSITEURL) . '?page_id=' . sp_get_option('sfpage');
        sp_update_option('sfpermalink', $perm);
    } else {
        $perm = user_trailingslashit(SFSITEURL . sp_get_option('sfslug'));
        sp_update_option('sfpermalink', $perm);
        $wp_rewrite->flush_rules();
    }
    sp_update_permalink();
}
 function saveData()
 {
     global $spVars, $spGlobals;
     $this->abort = false;
     $this->newpost['action'] = $this->action;
     # make the entire class object available for modification before saving
     # warning:  note the passing by reference.  other end could wreak havoc
     do_action_ref_array('sph_new_post_pre_save', array(&$this));
     # Write the topic if needed
     if ($this->action == 'topic') {
         $this->newpost = apply_filters('sph_new_topic_pre_data_saved', $this->newpost);
         $spdb = new spdbComplex();
         $spdb->table = SFTOPICS;
         $spdb->fields = array('topic_name', 'topic_slug', 'topic_date', 'forum_id', 'topic_status', 'topic_pinned', 'user_id');
         $spdb->data = array($this->newpost['topicname'], $this->newpost['topicslug'], $this->newpost['postdate'], $this->newpost['forumid'], $this->newpost['topicstatus'], $this->newpost['topicpinned'], $this->newpost['userid']);
         $spdb = apply_filters('sph_new_topic_data', $spdb);
         $this->newpost['db'] = $spdb->insert();
         if ($this->newpost['db'] == true) {
             $this->newpost['topicid'] = $spVars['insertid'];
             $this->newpost = apply_filters('sph_new_topic_data_saved', $this->newpost);
         } else {
             $this->abort = true;
             $this->message = sp_text('Unable to save new topic record');
             return;
         }
         # failsafe: check the topic slug and if empty use the topic id
         if (empty($this->newpost['topicslug'])) {
             $this->newpost['topicslug'] = 'topic-' . $this->newpost['topicid'];
             spdb_query('UPDATE ' . SFTOPICS . " SET topic_slug='" . $this->newpost['topicslug'] . "' WHERE topic_id=" . $this->newpost['topicid']);
         }
     }
     # Write the post
     # Double check forum id is correct - it has been known for a topic to have just been moved!
     $this->newpost['forumid'] = spdb_table(SFTOPICS, 'topic_id=' . $this->newpost['topicid'], 'forum_id');
     # Get post count in topic to enable post index setting
     $index = spdb_count(SFPOSTS, 'topic_id = ' . $this->newpost['topicid']);
     $index++;
     $this->newpost['postindex'] = $index;
     # if topic lock set in post reply update topic (post only)
     if ($this->action == 'post' && $this->newpost['topicstatus']) {
         spdb_query('UPDATE ' . SFTOPICS . ' SET topic_status=1 WHERE topic_id=' . $this->newpost['topicid']);
     }
     $this->newpost = apply_filters('sph_new_post_pre_data_saved', $this->newpost);
     $spdb = new spdbComplex();
     $spdb->table = SFPOSTS;
     $spdb->fields = array('post_content', 'post_date', 'topic_id', 'forum_id', 'user_id', 'guest_name', 'guest_email', 'post_pinned', 'post_index', 'post_status', 'poster_ip', 'source');
     $spdb->data = array($this->newpost['postcontent'], $this->newpost['postdate'], $this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['userid'], $this->newpost['guestname'], $this->newpost['guestemail'], $this->newpost['postpinned'], $this->newpost['postindex'], $this->newpost['poststatus'], $this->newpost['posterip'], $this->newpost['source']);
     $spdb = apply_filters('sph_new_post_data', $spdb);
     $this->newpost['db'] = $spdb->insert();
     if ($this->newpost['db'] == true) {
         $this->newpost['postid'] = $spVars['insertid'];
         $this->newpost = apply_filters('sph_new_post_data_saved', $this->newpost);
     } else {
         $this->abort = true;
         $this->message = sp_text('Unable to save new post message');
         return;
     }
     # Update the timestamp of the last post
     sp_update_option('poststamp', $this->newpost['postdate']);
     $this->returnURL = sp_build_url($this->newpost['forumslug'], $this->newpost['topicslug'], 0, $this->newpost['postid']);
     if ($this->newpost['poststatus']) {
         $this->newpost['submsg'] .= ' - ' . sp_text('placed in moderation') . ' ';
     }
     # Now for all that post-save processing required
     if ($this->guest) {
         $sfguests = sp_get_option('sfguests');
         if ($sfguests['storecookie']) {
             sp_write_guest_cookie($this->newpost['guestname'], $this->newpost['guestemail']);
         }
     } else {
         $postcount = sp_get_member_item($this->newpost['userid'], 'posts');
         $postcount++;
         sp_update_member_item($this->newpost['userid'], 'posts', $postcount);
         # see if postcount qualifies member for new user group membership
         # get rankings information
         if (!$this->admin) {
             # ignore for admins as they dont belong to user groups
             global $spGlobals;
             if (!empty($spGlobals['forum_rank'])) {
                 $index = 0;
                 foreach ($spGlobals['forum_rank'] as $x => $info) {
                     $rankdata['title'][$index] = $x;
                     $rankdata['posts'][$index] = $info['posts'];
                     $rankdata['usergroup'][$index] = $info['usergroup'];
                     $index++;
                 }
                 # sort rankings
                 array_multisort($rankdata['posts'], SORT_ASC, $rankdata['title'], $rankdata['usergroup']);
                 # check for new ranking
                 for ($x = 0; $x < count($rankdata['posts']); $x++) {
                     if ($postcount <= $rankdata['posts'][$x] && !empty($rankdata['usergroup'][$x])) {
                         # if a user group is tied to forum rank add member to the user group
                         if ($rankdata['usergroup'][$x] != 'none') {
                             sp_add_membership($rankdata['usergroup'][$x], $this->newpost['userid']);
                         }
                         break;
                         # only update highest rank
                     }
                 }
             }
         }
     }
     # set new url for email
     $this->newpost['url'] = $this->returnURL;
     # allow plugins to add to post message
     $this->newpost['submsg'] = apply_filters('sph_post_message', $this->newpost['submsg'], $this->newpost);
     # add to or remove from admins new post queue
     if ($this->admin || $this->moderator) {
         # remove topic from waiting...
         sp_remove_from_waiting(false, $this->newpost['topicid']);
     } else {
         # add topic to waiting
         sp_add_to_waiting($this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['postid'], $this->newpost['userid']);
     }
     # if a new post remove topic from the users new post list if in it
     if ($this->action == 'post') {
         sp_remove_users_newposts($this->newpost['topicid'], $this->newpost['userid']);
     }
     # do we need to approve any posts in moderation in this topic?
     if ($this->admin && $spGlobals['admin']['sfadminapprove'] || $this->moderator && $spGlobals['admin']['sfmoderapprove']) {
         sp_approve_post(true, 0, $this->newpost['topicid'], false, $this->newpost['forumid']);
     }
     # if post in moderatiuon then add entry to notices
     if ($this->newpost['poststatus'] != 0) {
         $nData = array();
         $nData['user_id'] = $this->newpost['userid'];
         $nData['guest_email'] = $this->newpost['guestemail'];
         $nData['post_id'] = $this->newpost['postid'];
         $nData['link'] = $this->newpost['url'];
         $nData['link_text'] = $this->newpost['topicname'];
         $nData['message'] = sp_text('Your post is awaiting moderation in the topic');
         $nData['expires'] = time() + 30 * 24 * 60 * 60;
         # 30 days; 24 hours; 60 mins; 60secs
         sp_add_notice($nData);
     }
     # Add this new item to the new tpic/post cache
     $meta = sp_get_sfmeta_key('topic_cache', 'new');
     $cacheSize = sp_get_option('topic_cache');
     $a = array();
     $a[LISTFORUM] = (int) $this->newpost['forumid'];
     $a[LISTTOPIC] = (int) $this->newpost['topicid'];
     $a[LISTPOST] = (int) $this->newpost['postid'];
     $a[LISTSTATUS] = (int) $this->newpost['poststatus'];
     if (isset($spGlobals['topic_cache']['new']) && !empty($spGlobals['topic_cache']['new'])) {
         array_unshift($spGlobals['topic_cache']['new'], $a);
         if (count($spGlobals['topic_cache']['new']) > $cacheSize) {
             array_pop($spGlobals['topic_cache']['new']);
         }
     }
     sp_update_sfmeta('topic_cache', 'new', $spGlobals['topic_cache']['new'], $meta, true);
     # remove group level caches to accommodate new post
     spdb_query('DELETE FROM ' . SFCACHE . " WHERE cache_id LIKE '%*group'");
     # save post in cache for flood control
     sp_add_cache('floodcontrol', time() + sp_get_option('floodcontrol'));
     # Update forum, topic and post index data
     sp_build_post_index($this->newpost['topicid']);
     sp_build_forum_index($this->newpost['forumid']);
     # send out email notifications
     sp_email_notifications($this->newpost);
     # one final filter - just in case
     do_action_ref_array('sph_post_new_completed', array(&$this));
     # and a final action hook
     do_action('sph_new_post', $this->newpost);
     do_action('sph_post_create', $this->newpost);
 }
Example #12
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_rebuild_user_auths($userid)
{
    global $spGlobals;
    $user_auths = array();
    $user_auths['global'] = array();
    if (sp_is_forum_admin($userid)) {
        # forum admins get full auths
        $forums = spdb_table(SFFORUMS);
        if ($forums) {
            foreach ($forums as $forum) {
                foreach ($spGlobals['auths_map'] as $auth) {
                    if ($spGlobals['auths'][$auth]->admin_negate) {
                        $user_auths[$forum->forum_id][$auth] = 0;
                        $user_auths['global'][$auth] = 0;
                    } else {
                        $user_auths[$forum->forum_id][$auth] = 1;
                        $user_auths['global'][$auth] = 1;
                    }
                }
            }
        }
    } else {
        $memberships = sp_get_user_memberships($userid);
        if (empty($memberships)) {
            $value = sp_get_sfmeta('default usergroup', 'sfguests');
            $memberships[0]['usergroup_id'] = $value[0]['meta_value'];
        }
        # no memberships means no permissions
        if (empty($memberships)) {
            return;
        }
        # get the roles
        $roles_data = spdb_table(SFROLES, 0);
        foreach ($roles_data as $role) {
            $roles[$role->role_id] = unserialize($role->role_auths);
        }
        # now build auths for user
        foreach ($memberships as $membership) {
            # get the permissions for the membership
            $permissions = spdb_table(SFPERMISSIONS, 'usergroup_id=' . $membership['usergroup_id']);
            if ($permissions) {
                foreach ($permissions as $permission) {
                    if (!isset($user_auths[$permission->forum_id])) {
                        $user_auths[$permission->forum_id] = $roles[$permission->permission_role];
                    } else {
                        foreach (array_keys($roles[$permission->permission_role]) as $auth_id) {
                            if (!isset($user_auths[$permission->forum_id][$auth_id])) {
                                $user_auths[$permission->forum_id][$auth_id] = $roles[$permission->permission_role][$auth_id];
                            } else {
                                $user_auths[$permission->forum_id][$auth_id] |= $roles[$permission->permission_role][$auth_id];
                            }
                        }
                    }
                    foreach ($roles[$permission->permission_role] as $auth_id => $auth) {
                        if (empty($user_auths['global'][$auth_id])) {
                            $user_auths['global'][$auth_id] = $auth;
                        } else {
                            $user_auths['global'][$auth_id] |= $auth;
                        }
                    }
                }
            }
        }
    }
    # now save the user auths
    if (!empty($user_auths)) {
        if (!empty($userid)) {
            sp_update_member_item($userid, 'auths', $user_auths);
        } else {
            sp_update_option('sf_guest_auths', $user_auths);
        }
    }
    return $user_auths;
}
function sp_update_recent_members()
{
    $newuserlist = sp_get_option('spRecentMembers');
    if (is_array($newuserlist)) {
        for ($x = 0; $x < count($newuserlist); $x++) {
            $newuserlist[$x]['name'] = sp_get_member_item($newuserlist[$x]['id'], 'display_name');
        }
    }
    sp_update_option('spRecentMembers', $newuserlist);
}
Example #15
0
function sp_create_forum_image_location()
{
    # storage location
    $basepath = '';
    $perms = fileperms(SF_STORE_DIR);
    $owners = stat(SF_STORE_DIR);
    if ($perms === false) {
        $perms = 0755;
    }
    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);
    }
    if (file_exists(SF_STORE_DIR . '/' . $basepath)) {
        # Is the ownership correct?
        $newowners = stat(SF_STORE_DIR . '/' . $basepath);
        if ($newowners['uid'] != $owners['uid'] || $newowners['gid'] != $owners['gid']) {
            @chown(SF_STORE_DIR . '/' . $basepath, $owners['uid']);
            @chgrp(SF_STORE_DIR . '/' . $basepath, $owners['gid']);
        }
    }
    $newpath = SF_STORE_DIR . '/' . $basepath . '/forum-feature-images';
    if (!file_exists($newpath)) {
        $sfconfig = sp_get_option('sfconfig');
        $sfconfig['forum-images'] = $basepath . '/forum-feature-images';
        sp_update_option('sfconfig', $sfconfig);
        @mkdir($newpath, $perms);
    }
}
function spa_save_inspector_data()
{
    global $spThisUser;
    check_admin_referer('forum-adminform_inspector', 'forum-adminform_inspector');
    $mess = spa_text('Options Updated');
    $i = $spThisUser->ID;
    $ins = array();
    $ins = sp_get_option('spInspect');
    $ins[$i]['con_spVars'] = isset($_POST['con_spVars']);
    $ins[$i]['con_spGlobals'] = isset($_POST['con_spGlobals']);
    $ins[$i]['con_spThisUser'] = isset($_POST['con_spThisUser']);
    $ins[$i]['con_spDevice'] = isset($_POST['con_spDevice']);
    $ins[$i]['gv_spGroupView'] = isset($_POST['gv_spGroupView']);
    $ins[$i]['gv_spThisGroup'] = isset($_POST['gv_spThisGroup']);
    $ins[$i]['gv_spThisForum'] = isset($_POST['gv_spThisForum']);
    $ins[$i]['gv_spThisForumSubs'] = isset($_POST['gv_spThisForumSubs']);
    $ins[$i]['q_spGroupView'] = isset($_POST['q_spGroupView']);
    $ins[$i]['q_spGroupViewStats'] = isset($_POST['q_spGroupViewStats']);
    $ins[$i]['fv_spForumView'] = isset($_POST['fv_spForumView']);
    $ins[$i]['fv_spThisForum'] = isset($_POST['fv_spThisForum']);
    $ins[$i]['fv_spThisForumSubs'] = isset($_POST['fv_spThisForumSubs']);
    $ins[$i]['fv_spThisSubForum'] = isset($_POST['fv_spThisSubForum']);
    $ins[$i]['fv_spThisTopic'] = isset($_POST['fv_spThisTopic']);
    $ins[$i]['q_spForumView'] = isset($_POST['q_spForumView']);
    $ins[$i]['q_spForumViewStats'] = isset($_POST['q_spForumViewStats']);
    $ins[$i]['tv_spTopicView'] = isset($_POST['tv_spTopicView']);
    $ins[$i]['tv_spThisTopic'] = isset($_POST['tv_spThisTopic']);
    $ins[$i]['tv_spThisPost'] = isset($_POST['tv_spThisPost']);
    $ins[$i]['tv_spThisPostUser'] = isset($_POST['tv_spThisPostUser']);
    $ins[$i]['q_spTopicView'] = isset($_POST['q_spTopicView']);
    $ins[$i]['mv_spMembersList'] = isset($_POST['mv_spMembersList']);
    $ins[$i]['mv_spThisMemberGroup'] = isset($_POST['mv_spThisMemberGroup']);
    $ins[$i]['mv_spThisMember'] = isset($_POST['mv_spThisMember']);
    $ins[$i]['q_spMembersView'] = isset($_POST['q_spMembersView']);
    $ins[$i]['tlv_spTopicListView'] = isset($_POST['tlv_spTopicListView']);
    $ins[$i]['tlv_spThisListTopic'] = isset($_POST['tlv_spThisListTopic']);
    $ins[$i]['q_spTopicListView'] = isset($_POST['q_spTopicListView']);
    $ins[$i]['q_spTopicListViewNew'] = isset($_POST['q_spTopicListViewNew']);
    $ins[$i]['q_spTopicListViewFirst'] = isset($_POST['q_spTopicListViewFirst']);
    $ins[$i]['plv_spPostListView'] = isset($_POST['plv_spPostListView']);
    $ins[$i]['plv_spThisListPost'] = isset($_POST['plv_spThisListPost']);
    $ins[$i]['q_spPostListView'] = isset($_POST['q_spPostListView']);
    $ins[$i]['q_spSearchView'] = isset($_POST['q_spSearchView']);
    $ins[$i]['pro_spProfileUser'] = isset($_POST['pro_spProfileUser']);
    sp_update_option('spInspect', $ins);
    do_action('sph_toolbox_inspector_save');
    return $mess;
}
function spa_save_theme_tablet_data()
{
    check_admin_referer('forum-adminform_themes', 'forum-adminform_themes');
    $tabletTheme = sp_get_option('sp_tablet_theme');
    $curTheme = sp_get_option('sp_current_theme');
    $tablet = array();
    $active = isset($_POST['active']);
    if ($active && $tabletTheme['active']) {
        $theme = isset($_POST['theme']) ? sp_esc_str($_POST['theme']) : $tabletTheme['theme'];
        $style = isset($_POST['style']) ? sp_esc_str($_POST['style']) : $tabletTheme['style'];
        $color = isset($_POST['color-' . $theme]) ? sp_esc_str($_POST['color-' . $theme]) : '';
        $parent = isset($_POST['parent']) ? sp_esc_str($_POST['parent']) : $tabletTheme['parent'];
        $pagetemplate = isset($_POST['pagetemplate']) ? sp_esc_str($_POST['pagetemplate']) : $tabletTheme['pagetemplate'];
        if (isset($_POST['pagetemplate'])) {
            $usetemplate = isset($_POST['usetemplate']);
            $notitle = isset($_POST['notitle']);
        } else {
            $usetemplate = $tabletTheme['usetemplate'];
            $notitle = $tabletTheme['notitle'];
        }
        if (empty($theme) || empty($style)) {
            return spa_text('No data changed');
        }
        if (empty($color)) {
            $color = sp_esc_str($_POST['default-color']);
        }
        $tablet['active'] = true;
        $tablet['theme'] = $theme;
        $tablet['style'] = $style;
        $tablet['color'] = $color;
        $tablet['parent'] = $parent;
        $tablet['usetemplate'] = $usetemplate;
        $tablet['pagetemplate'] = $pagetemplate;
        $tablet['notitle'] = $notitle;
    } else {
        $tablet = array();
        $tablet['active'] = $active;
        $tablet['theme'] = $curTheme['theme'];
        $tablet['style'] = $curTheme['style'];
        $tablet['color'] = $curTheme['color'];
        $tablet['parent'] = $curTheme['parent'];
        $tablet['usetemplate'] = false;
        $tablet['pagetemplate'] = spdb_table(SFWPPOSTMETA, "meta_key='_wp_page_template' AND post_id=" . sp_get_option('sfpage'), 'meta_value');
        $tablet['notitle'] = true;
    }
    $icons = 'images';
    if (!empty($tablet['color'])) {
        $f = SPTHEMEBASEDIR . $tablet['theme'] . '/styles/overlays/' . $tablet['color'] . '.php';
        $icons = sp_esc_str(sp_get_overlay_image_path($f));
    }
    $tablet['icons'] = $icons;
    sp_update_option('sp_tablet_theme', $tablet);
    # clean out the combined css file
    sp_clear_combined_css('tablet');
    # theme activation action
    do_action('sph_activate_tablet_theme', $tablet);
    do_action('sph_activate_tablet_theme_' . $tablet['theme'], $tablet);
    return spa_text('Mobile Tablet theme activated/updated');
}
function sp_go_network_upgrade($current_version, $current_build)
{
    global $current_user;
    ?>
	<div class="wrap"><br />
		<div class="updated">
		<img class="stayleft" src="<?php 
    echo SFCOMMONIMAGES;
    ?>
sp-mini-logo.png" alt="" title="" />
		<h3><?php 
    spa_etext('Simple:Press is upgrading the Network.');
    ?>
</h3>
		</div><br />
		<div class="wrap sfatag">
			<div class="imessage" id="imagezone"></div>
		</div><br />
		<div class="pbar" id="progressbar"></div><br />
		<div class="wrap sfatag">
			<div class="zmessage" id="errorzone"></div>
			<div id="finishzone"></div><br />
		</div><br />
		<div id="debug">
			</p><b>Please copy the details below and include them on any support forum question you may have:</b><br /><br /></p>
		</div>
	</div>
<?php 
    # get list of network sites
    $sites = wp_get_sites();
    # loop through all blogs and upgrade ones with active simple:press
    foreach ($sites as $site) {
        # switch to network site and see if simple:press is active
        switch_to_blog($site['blog_id']);
        global $wpdb;
        $installed = spdb_select('set', 'SELECT option_id FROM ' . $wpdb->prefix . "sfoptions WHERE option_name='sfversion'");
        if ($installed) {
            $phpfile = SFHOMEURL . 'index.php?sp_ahah=upgrade&sfnonce=' . wp_create_nonce('forum-ahah') . '&sfnetworkid=' . $site['blog_id'];
            $image = SFCOMMONIMAGES . 'working.gif';
            $targetbuild = SPBUILD;
            update_option('sfInstallID', $current_user->ID);
            # use wp option table
            # save the build info
            $out = spa_text('Upgrading Network Site ID') . ': ' . $site['blog_id'] . '<br />';
            sp_update_option('sfStartUpgrade', $current_build);
            # upgrade the network site
            $messages = esc_js(spa_text('Go to Forum Admin')) . '@' . esc_js(spa_text('Upgrade is in progress - please wait')) . '@' . esc_js(spa_text('Upgrade Completed')) . '@' . esc_js(spa_text('Upgrade Aborted')) . '@' . esc_js(spa_text('Go to Forum'));
            $out .= '<script type="text/javascript">' . "\n";
            $out .= 'spjPerformUpgrade("' . $phpfile . '", "' . $current_build . '", "' . $targetbuild . '", "' . $current_build . '", "' . $image . '", "' . $messages . '", "' . sp_url() . '");' . "\n";
            $out .= '</script>' . "\n";
            echo $out;
            # clear any combined css/js cached files
            sp_clear_combined_css('all');
            sp_clear_combined_css('mobile');
            sp_clear_combined_css('tablet');
            sp_clear_combined_scripts('desktop');
            sp_clear_combined_scripts('mobile');
            sp_clear_combined_scripts('tablet');
        }
        restore_current_blog();
    }
}
function spa_save_usergroups_map_settings()
{
    global $wp_roles;
    check_admin_referer('forum-adminform_mapusers', 'forum-adminform_mapusers');
    # save default usergroups
    sp_add_sfmeta('default usergroup', 'sfguests', sp_esc_int($_POST['sfguestsgroup']));
    # default usergroup for guests
    sp_add_sfmeta('default usergroup', 'sfmembers', sp_esc_int($_POST['sfdefgroup']));
    # default usergroup for members
    # check for changes in wp role usergroup assignments
    if (isset($_POST['sfrole'])) {
        $roles = array_keys($wp_roles->role_names);
        foreach ($_POST['sfrole'] as $index => $role) {
            if ($_POST['sfoldrole'][$index] != $role) {
                sp_add_sfmeta('default usergroup', $roles[$index], sp_esc_int($role));
            }
        }
    }
    $sfmemberopts = sp_get_option('sfmemberopts');
    $sfmemberopts['sfsinglemembership'] = isset($_POST['sfsinglemembership']);
    sp_update_option('sfmemberopts', $sfmemberopts);
    $mess = spa_text('User mapping settings saved');
    do_action('sph_option_map_settings_save');
    return $mess;
}
 function __construct($ident = 0, $current = false, $small = false)
 {
     global $spStatus, $spGlobals;
     $id = 0;
     if (is_numeric($ident)) {
         $w = "ID={$ident}";
     } else {
         if ($ident != false) {
             $w = "user_login='******'";
         }
     }
     if ($ident) {
         # Users data
         $d = spdb_table(SFUSERS, $w, 'row');
         if ($d) {
             $this->ID = $d->ID;
             $id = $d->ID;
         }
     }
     $includeList = spUser_build_filter_list();
     if ($id) {
         # Others
         $this->member = true;
         $this->guest = 0;
         $this->guest_name = '';
         $this->guest_email = '';
         $this->offmember = false;
         $this->usertype = 'User';
         # Users data
         foreach ($d as $key => $item) {
             if (array_key_exists($key, $includeList)) {
                 $this->{$key} = $item;
             }
         }
         $this->user_registered = sp_member_registration_to_server_tz($this->user_registered);
         # usermeta data
         $d = spdb_table(SFUSERMETA, "user_id={$id}");
         if ($d) {
             foreach ($d as $m) {
                 $t = $m->meta_key;
                 if (array_key_exists($t, $includeList)) {
                     $this->{$t} = maybe_unserialize($m->meta_value);
                 }
             }
         }
         # If awaiting installation then dive out now to avoid errors
         if ($spStatus == 'Install') {
             return;
         }
         # sfmembers data
         $d = spdb_table(SFMEMBERS, "user_id={$id}", 'row');
         #check for ghost user
         if (empty($d)) {
             #create the member
             sp_create_member_data($id);
             $d = spdb_table(SFMEMBERS, "user_id={$id}", 'row');
         }
         if ($d) {
             foreach ($d as $key => $item) {
                 if ($key == 'admin_options' && !empty($item)) {
                     $opts = unserialize($item);
                     foreach ($opts as $opt => $set) {
                         $this->{$opt} = $set;
                     }
                 } else {
                     if ($key == 'user_options' && !empty($item)) {
                         $opts = unserialize($item);
                         foreach ($opts as $opt => $set) {
                             $this->{$opt} = $set;
                         }
                     } else {
                         if ($key == 'lastvisit') {
                             $this->lastvisit = $item;
                         } else {
                             $this->{$key} = maybe_unserialize($item);
                         }
                     }
                 }
             }
         }
         # Check for new post list size
         if (!isset($this->unreadposts) || empty($this->unreadposts)) {
             $controls = sp_get_option('sfcontrols');
             $this->unreadposts = empty($controls['sfunreadposts']) ? 50 : $controls['sfunreadposts'];
         }
         # usertype for moderators
         if ($this->moderator) {
             $this->usertype = 'Moderator';
         }
         # check for super admins and make admin a moderator as well
         if ($this->admin || is_multisite() && is_super_admin($id)) {
             $this->admin = true;
             $this->moderator = true;
             $this->usertype = 'Admin';
             $ins = sp_get_option('spInspect');
             if (!empty($ins) && array_key_exists($id, $ins)) {
                 $this->inspect = $ins[$id];
             } else {
                 $this->inspect = '';
             }
         }
         # plugins can add iterms for members...
         if (!$small) {
             do_action_ref_array('sph_user_class_member', array(&$this));
         } else {
             do_action_ref_array('sph_user_class_member_small', array(&$this));
         }
     } else {
         # some basics for guests
         $this->ID = 0;
         $this->guest = true;
         $this->member = 0;
         $this->admin = false;
         $this->moderator = false;
         $this->display_name = 'guest';
         $this->guest_name = '';
         $this->guest_email = '';
         $this->usertype = 'Guest';
         $this->offmember = sp_check_unlogged_user();
         $this->timezone = 0;
         $this->timezone_string = '';
         $this->posts = 0;
         $this->avatar = '';
         $this->user_email = '';
         $this->auths = sp_get_option('sf_guest_auths');
         $this->memberships = sp_get_option('sf_guest_memberships');
         # plugins can add iterms for guests...
         if (!$small) {
             do_action_ref_array('sph_user_class_guest', array(&$this));
         } else {
             do_action_ref_array('sph_user_class_guest_small', array(&$this));
         }
     }
     # Only perform this last section if forum is operational
     if ($spStatus == 'ok') {
         # Ranking
         $this->rank = sp_get_user_forum_rank($this->usertype, $id, $this->posts);
         $this->special_rank = $this->member ? sp_get_user_special_ranks($id) : array();
         # if no memberships rebuild them and save
         if (empty($this->memberships)) {
             $memberships = array();
             if (!empty($id)) {
                 if (!$this->admin) {
                     # get the usergroup memberships for the user and save in sfmembers table
                     $memberships = sp_get_user_memberships($id);
                     sp_update_member_item($id, 'memberships', $memberships);
                 }
             } else {
                 # user is a guest or unassigned member so get the global permissions from the guest usergroup and save as option
                 $value = sp_get_sfmeta('default usergroup', 'sfguests');
                 $memberships[] = spdb_table(SFUSERGROUPS, 'usergroup_id=' . $value[0]['meta_value'], 'row', '', '', ARRAY_A);
                 sp_update_option('sf_guest_memberships', $memberships);
             }
             # put in the data
             $this->memberships = $memberships;
         }
         # if no auths rebuild them and save
         if (empty($this->auths)) {
             $this->auths = sp_rebuild_user_auths($id);
         }
     }
     $this->ip = sp_get_ip();
     $this->trackid = -1;
     # Things to do if user is current user
     if ($current) {
         # Set up editor type
         $spGlobals['editor'] = 0;
         # for a user...
         if ($this->member && !empty($this->editor)) {
             $spGlobals['editor'] = $this->editor;
         }
         # and if not defined or is for a guest...
         if ($spGlobals['editor'] == 0) {
             $defeditor = sp_get_option('speditor');
             if (!empty($defeditor)) {
                 $spGlobals['editor'] = $defeditor;
             }
         }
         # final check to ensure selected editor type is indeed available
         if ($spGlobals['editor'] == 0 || $spGlobals['editor'] == 1 && !defined('RICHTEXT') || $spGlobals['editor'] == 2 && !defined('HTML') || $spGlobals['editor'] == 3 && !defined('BBCODE')) {
             $spGlobals['editor'] = PLAINTEXT;
             if (defined('BBCODE')) {
                 $spGlobals['editor'] = BBCODE;
             }
             if (defined('HTML')) {
                 $spGlobals['editor'] = HTML;
             }
             if (defined('RICHTEXT')) {
                 $spGlobals['editor'] = RICHTEXT;
             }
         }
         # Grab any notices present
         if ($this->guest && !empty($this->guest_email)) {
             $this->user_notices = spdb_table(SFNOTICES, "guest_email='" . $this->guest_email . "'", '', $order = 'notice_id');
         } elseif ($this->member && !empty($this->user_email)) {
             $this->user_notices = spdb_table(SFNOTICES, "user_id=" . $this->ID, '', $order = 'notice_id');
         }
         # plugins can add iterms for the current user (so no small allowed here)
         do_action_ref_array('sph_current_user_class', array(&$this));
     }
     # Finally filter the data for display
     foreach ($includeList as $item => $filter) {
         if (property_exists($this, $item)) {
             $this->{$item} = spUser_filter_item($this->{$item}, $filter);
         }
     }
     # allow plugins to add items to user class - regardless small or otherwise, current or otherwise
     do_action_ref_array('sph_user_class', array(&$this));
 }
function spa_save_email_data()
{
    check_admin_referer('forum-adminform_email', 'forum-adminform_email');
    $mess = spa_text('Options updated');
    # Save Email Options
    # Thanks to Andrew Hamilton for these routines (mail-from plugion)
    # Remove any illegal characters and convert to lowercase both the user name and domain name
    $domain_input_errors = array('http://', 'https://', 'ftp://', 'www.');
    $domainname = strtolower(sp_filter_title_save(trim($_POST['sfmaildomain'])));
    $domainname = str_replace($domain_input_errors, '', $domainname);
    $domainname = preg_replace('/[^0-9a-z\\-\\.]/i', '', $domainname);
    $illegal_chars_username = array('(', ')', '<', '>', ',', ';', ':', '\\', '"', '[', ']', '@', ' ');
    $username = strtolower(sp_filter_name_save(trim($_POST['sfmailfrom'])));
    $username = str_replace($illegal_chars_username, '', $username);
    $sfmail = array();
    $sfmail['sfmailsender'] = sp_filter_name_save(trim($_POST['sfmailsender']));
    $sfmail['sfmailfrom'] = $username;
    $sfmail['sfmaildomain'] = $domainname;
    $sfmail['sfmailuse'] = isset($_POST['sfmailuse']);
    sp_update_option('sfmail', $sfmail);
    # Save new user mail options
    $sfmail = array();
    $sfmail['sfusespfreg'] = isset($_POST['sfusespfreg']);
    $sfmail['sfnewusersubject'] = sp_filter_title_save(trim($_POST['sfnewusersubject']));
    $sfmail['sfnewusertext'] = sp_filter_title_save(trim($_POST['sfnewusertext']));
    sp_update_option('sfnewusermail', $sfmail);
    do_action('sph_option_email_save');
    return $mess;
}
function spdb_show_result($sql)
{
    vshow($sql);
    sp_update_option('a-show-query', $sql);
    return;
}
function spa_save_integration_language_data()
{
    check_admin_referer('forum-adminform_language', 'forum-adminform_language');
    $spLang = sp_get_option('spLang');
    if (isset($_POST['spLang'])) {
        $spLang['spLang'] = $_POST['spLang'];
    }
    $spLang['spRTL'] = isset($_POST['spRTL']);
    sp_update_option('spLang', $spLang);
    $mess = spa_text('Translation settings updated');
    return $mess;
}
function spa_save_forums_global_rss()
{
    check_admin_referer('forum-adminform_globalrss', 'forum-adminform_globalrss');
    # update the globla rss replacement url
    sp_update_option('sfallRSSurl', sp_filter_save_cleanurl($_POST['sfallrssurl']));
    $mess = spa_text('Global RSS settings updated');
    do_action('sph_forum_global_rss');
    # clear out group cache tpo enable change_user
    sp_flush_cache('group');
    return $mess;
}
function spa_save_messages_data()
{
    check_admin_referer('forum-adminform_messages', 'forum-adminform_messages');
    # custom message for editor
    $sfpostmsg = array();
    $sfpostmsg['sfpostmsgtext'] = sp_filter_text_save(trim($_POST['sfpostmsgtext']));
    $sfpostmsg['sfpostmsgtopic'] = isset($_POST['sfpostmsgtopic']);
    $sfpostmsg['sfpostmsgpost'] = isset($_POST['sfpostmsgpost']);
    sp_update_option('sfpostmsg', $sfpostmsg);
    sp_update_option('sfeditormsg', sp_filter_text_save(trim($_POST['sfeditormsg'])));
    # if set update, otherwise its empty, so remove
    if ($_POST['sfsneakpeek'] != '') {
        sp_add_sfmeta('sneakpeek', 'message', sp_filter_text_save(trim($_POST['sfsneakpeek'])));
    } else {
        $msg = sp_get_sfmeta('sneakpeek', 'message');
        if (!empty($msg)) {
            sp_delete_sfmeta($msg[0]['meta_id']);
        }
    }
    $sflogin = array();
    $sflogin = sp_get_option('sflogin');
    $sflogin['sfsneakredirect'] = sp_filter_save_cleanurl($_POST['sfsneakredirect']);
    sp_update_option('sflogin', $sflogin);
    # if set update, otherwise its empty, so remove
    if ($_POST['sfadminview'] != '') {
        sp_add_sfmeta('adminview', 'message', sp_filter_text_save(trim($_POST['sfadminview'])));
    } else {
        $msg = sp_get_sfmeta('adminview', 'message');
        if (!empty($msg)) {
            sp_delete_sfmeta($msg[0]['meta_id']);
        }
    }
    # if set update, otherwise its empty, so remove
    if ($_POST['sfuserview'] != '') {
        sp_add_sfmeta('userview', 'message', sp_filter_text_save(trim($_POST['sfuserview'])));
    } else {
        $msg = sp_get_sfmeta('userview', 'message');
        if (!empty($msg)) {
            sp_delete_sfmeta($msg[0]['meta_id']);
        }
    }
    do_action('sph_component_messages_save');
    $mess = spa_text('Custom messages updated');
    return $mess;
}
function sp_update_permalink($autoflush = false)
{
    global $wp_rewrite;
    $slug = sp_get_option('sfslug');
    if ($slug) {
        $sfperm = sp_get_option('sfpermalink');
        # go for whole row to ensure it is cached
        $pageslug = basename($slug);
        $page = spdb_table(SFWPPOSTS, "post_name='{$pageslug}' AND post_status='publish' AND post_type='page'", 'row');
        if ($page) {
            sp_update_option('sfpage', $page->ID);
            # get scheme for front end
            # get_permalink() returns scheme for existing page so adjust to front
            $perm = get_permalink($page->ID);
            $scheme = parse_url(get_option('siteurl'), PHP_URL_SCHEME);
            # get front end scheme
            $perm = set_url_scheme($perm, $scheme);
            # update permalink with proper front end scheme
            if (get_option('page_on_front') == $page->ID && get_option('show_on_front') == 'page') {
                $perm = rtrim($perm, '/');
                if ($wp_rewrite->using_permalinks()) {
                    $perm .= '/' . $slug;
                } else {
                    $perm .= '/?page_id=' . $page->ID;
                }
            }
            # only update it if base permalink has been changed
            if ($sfperm != $perm) {
                sp_update_option('sfpermalink', $perm);
                $sfperm = $perm;
                $autoflush = true;
            }
        }
    }
    if ($autoflush) {
        $wp_rewrite->flush_rules();
    }
    return $sfperm;
}
Example #27
0
function sp_combine_plugin_script_files()
{
    global $sp_plugin_scripts, $skip_combine_js, $spDevice;
    if (isset($skip_combine_js)) {
        return null;
    }
    # Don't run twice
    $skip_combine_js = true;
    # check for standard theme or mobile
    if ($spDevice == 'mobile') {
        $option = 'sp_js_concat_mobile';
    } else {
        if ($spDevice == 'tablet') {
            $option = 'sp_js_concat_tablet';
        } else {
            $option = 'sp_js_concat';
        }
    }
    $js_concat = sp_get_option($option);
    if (!is_array($js_concat)) {
        $js_concat = array();
    }
    # save copy of styles in case of failure writing
    $saved_scripts = clone $sp_plugin_scripts;
    $js_files_modify = array();
    $js_files = array();
    $js_extra = array();
    if (is_array($sp_plugin_scripts->queue)) {
        # is there anything in the queue?
        $sp_plugin_scripts->all_deps($sp_plugin_scripts->queue);
        # preparing the queue taking dependencies into account
        foreach ($js_concat as $js => $value) {
            # going through all the already found js files, checking that they are still required
            if (!in_array(substr($js, 3), $sp_plugin_scripts->to_do) && substr($js, 0, 3) == 'js-') {
                # if the js is not queued, rewrite the file
                $js_place = $value['type'];
                $js_files_modify[$js_place] = true;
                unset($js_concat[$js]);
            }
        }
        $dep = array();
        foreach ($sp_plugin_scripts->to_do as $js) {
            $js_src = $sp_plugin_scripts->registered[$js]->src;
            $js_place = $sp_plugin_scripts->registered[$js]->extra;
            if (is_array($js_place) && isset($js_place['group'])) {
                $js_place = $spDevice . '-footer';
            } else {
                $js_place = $spDevice . '-header';
            }
            # grab any wp js files as dependencies and then ignore for enqueueing with our plugin scripts
            if (strpos($js_src, 'wp-includes') !== false || strpos($js_src, 'wp-admin') !== false) {
                $dep[] = $js;
                continue;
            }
            if ((!(strpos($js_src, get_bloginfo('url')) === false) || substr($js_src, 0, 1) === '/' || substr($js_src, 0, 1) === '.') && substr($js_src, strrpos($js_src, '.'), 3) == '.js') {
                #the js is hosted localy AND a .js file
                if (!is_array($js_files) || !array_key_exists($js_place, $js_files)) {
                    $js_files[$js_place] = array();
                }
                if (strpos($js_src, get_bloginfo('url')) === false) {
                    $js_relative_url = substr($js_src, 1);
                } else {
                    $js_relative_url = substr($js_src, strlen(get_bloginfo('url')) + 1);
                }
                if (strpos($js_relative_url, '?')) {
                    $js_relative_url = substr($js_relative_url, 0, strpos($js_relative_url, '?'));
                }
                #removing parameters
                $js_m_time = null;
                @($js_m_time = filemtime($js_relative_url));
                # getting the mofified time of the js file. extracting the file's dir
                if ($js_m_time) {
                    # only add the file if it's accessible
                    array_push($js_files[$js_place], $js_relative_url);
                    if (!file_exists(SP_COMBINED_CACHE_DIR . SP_COMBINED_SCRIPTS_BASE_NAME . $js_place . '.js') || isset($js_concat['js-' . $js]) && ($js_m_time != $js_concat['js-' . $js]['modified'] || $js_concat['js-' . $js]['type'] != $js_place) || !isset($js_concat['js-' . $js])) {
                        # js file is first identified
                        $js_files_modify[$js_place] = true;
                        # the combined file containing this place js should be changed
                        if (isset($js_concat['js-' . $js]) && $js_concat['js-' . $js]['type'] != $js_place) {
                            # if the place type changed - rewrite both js files
                            $tmp = $js_concat['js-' . $js]['type'];
                            $js_files_modify[$tmp] = true;
                        }
                        if (isset($js_concat['js-' . $js]) || !is_array($js_concat['js-' . $js])) {
                            $js_concat['js-' . $js] = array();
                        }
                        $js_concat['js-' . $js]['modified'] = $js_m_time;
                        # write the new modified date
                        $js_concat['js-' . $js]['type'] = $js_place;
                    }
                    if (is_array($sp_plugin_scripts->registered[$js]->extra) && isset($sp_plugin_scripts->registered[$js]->extra['data'])) {
                        $js_extra[$js_relative_url] = $sp_plugin_scripts->registered[$js]->extra['data'];
                    }
                    $sp_plugin_scripts->remove($js);
                    # removes the js file from the queue
                    array_shift($sp_plugin_scripts->to_do);
                }
            }
        }
    }
    foreach ($js_files_modify as $key => $value) {
        $combined_file = fopen(SP_COMBINED_CACHE_DIR . SP_COMBINED_SCRIPTS_BASE_NAME . $key . '.js', 'w');
        if ($combined_file) {
            $js_content = '';
            if (is_array($js_files[$key])) {
                foreach ($js_files[$key] as $js_src) {
                    $source_file = fopen($js_src, 'r');
                    if ($source_file === false) {
                        return;
                    }
                    # do we need to localize the script?
                    if (isset($js_extra[$js_src])) {
                        $js_content .= "\n" . $js_extra[$js_src] . "\n";
                    }
                    $js_content .= "\n" . fread($source_file, filesize($js_src)) . "\n";
                    fclose($source_file);
                }
            }
            if (!isset($js_concat['ver'][$key . '-js'])) {
                $js_concat['ver'][$key . '-js'] = 0;
            }
            $js_concat['ver'][$key . '-js']++;
            fwrite($combined_file, $js_content);
            fclose($combined_file);
        } else {
            # couldnt open file for writing so revert back to enqueueing all the scripts
            if (!empty($saved_scripts)) {
                foreach ($saved_scripts->queue as $handle) {
                    $plugin_footer = is_array($saved_scripts->registered[$handle]->extra) && $saved_scripts->registered[$handle]->extra['group'] == 1 ? true : false;
                    wp_enqueue_script($handle, $saved_scripts->registered[$handle]->src, $saved_scripts->registered[$handle]->deps, false, $plugin_footer);
                }
            }
            return;
            # enqueued through wp now so bail
        }
    }
    # enqueue the combined js files with dependencies
    foreach ($js_files as $key => $value) {
        # enqueue the combined js files
        wp_enqueue_script(SP_COMBINED_SCRIPTS_BASE_NAME . $key, SP_COMBINED_CACHE_URL . SP_COMBINED_SCRIPTS_BASE_NAME . $key . '.js', $dep, $js_concat['ver'][$key . '-js'], strpos($js_concat['ver'][$key . '-js'], 'footer') !== false);
    }
    sp_update_option($option, $js_concat);
}
function sp_OnlineStats($args = '', $mostLabel = '', $currentLabel = '', $browsingLabel = '', $guestLabel = '')
{
    $defs = array('pMostClass' => 'spMostOnline', 'pCurrentClass' => 'spCurrentOnline', 'pBrowsingClass' => 'spCurrentBrowsing', 'link_names' => 1, 'usersOnly' => 0, 'echo' => 1, 'get' => 0);
    $a = wp_parse_args($args, $defs);
    $a = apply_filters('sph_OnlineStats_args', $a);
    extract($a, EXTR_SKIP);
    # sanitize before use
    $pMostClass = esc_attr($pMostClass);
    $pCurrentClass = esc_attr($pCurrentClass);
    $pBrowsingClass = esc_attr($pBrowsingClass);
    $link_names = (int) $link_names;
    $usersOnly = (int) $usersOnly;
    $echo = (int) $echo;
    $get = (int) $get;
    if (!empty($mostLabel)) {
        $mostLabel = sp_filter_title_display($mostLabel);
    }
    if (!empty($currentLabel)) {
        $currentLabel = sp_filter_title_display($currentLabel);
    }
    if (!empty($browsingLabel)) {
        $browsingLabel = sp_filter_title_display($browsingLabel);
    }
    if (!empty($guestLabel)) {
        $guestLabel = sp_filter_title_display($guestLabel);
    }
    # grab most online stat and update if new most
    $max = sp_get_option('spMostOnline');
    $online = spdb_count(SFTRACK);
    if ($online > $max) {
        $max = $online;
        sp_update_option('spMostOnline', $max);
    }
    $members = sp_get_members_online();
    if ($get) {
        $getData = new stdClass();
        $getData->max = $max;
        $getData->members = $members;
        return $getData;
    }
    # render the max online stats
    $out = "<p class='{$pMostClass}'><span>{$mostLabel}</span>{$max}</p>";
    # render the current online stats
    $browse = '';
    $out .= "<p class='{$pCurrentClass}'><span>{$currentLabel}</span>";
    # members online
    if ($members) {
        global $spThisUser, $spVars;
        $firstOnline = true;
        $firstBrowsing = true;
        $spMemberOpts = sp_get_option('sfmemberopts');
        foreach ($members as $user) {
            $userOpts = unserialize($user->user_options);
            if (!isset($userOpts['hidestatus'])) {
                $userOpts['hidestatus'] = false;
            }
            if ($spThisUser->admin || !$spMemberOpts['sfhidestatus'] || !$userOpts['hidestatus']) {
                if (!$firstOnline) {
                    $out .= ', ';
                }
                $out .= "<span class='spOnlineUser " . $user->display . "'>";
                $out .= sp_build_name_display($user->trackuserid, sp_filter_name_display($user->display_name), $link_names);
                $out .= '</span>';
                $firstOnline = false;
                # Set up the members browsing curent item list while here
                # Check that pageview is  set as this might be called from outside of the forum
                if (!empty($spVars['pageview'])) {
                    if ($spVars['pageview'] == 'forum' && $user->forum_id == $spVars['forumid'] || $spVars['pageview'] == 'topic' && $user->topic_id == $spVars['topicid']) {
                        if (!$firstBrowsing) {
                            $browse .= ', ';
                        }
                        $browse .= "<span class='spOnlineUser " . $user->display . "'>";
                        $browse .= sp_build_name_display($user->trackuserid, sp_filter_name_display($user->display_name), $link_names);
                        $browse .= '</span>';
                        $firstBrowsing = false;
                    }
                }
            }
        }
    }
    # guests online
    if (!$usersOnly && $online && $online > count($members)) {
        $guests = $online - count($members);
        $out .= "<br />{$guests} <span class='spOnlineUser spType-Guest'>{$guestLabel}</span>";
    }
    $out .= '</p>';
    # Members and guests browsing
    $out .= "<p class='{$pBrowsingClass}'>";
    $guestBrowsing = sp_guests_browsing();
    if ($browse || $guestBrowsing) {
        $out .= "<span>{$browsingLabel}</span>";
    }
    if ($browse) {
        $out .= $browse;
    }
    if (!$usersOnly && $guestBrowsing != 0) {
        $out .= "<br />{$guestBrowsing} <span class='spOnlineUser spType-Guest'>{$guestLabel}</span>";
    }
    $out .= "</p>\n";
    # finish it up
    $out = apply_filters('sph_OnlineStats', $out, $a);
    if ($echo) {
        echo $out;
    } else {
        return $out;
    }
}
function spa_new_profile_setup()
{
    # set up tabs and menus
    sp_profile_add_tab(spa_text('Profile'));
    sp_profile_add_menu(spa_text('Profile'), spa_text('Overview'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-overview.php');
    sp_profile_add_menu(spa_text('Profile'), spa_text('Edit Profile'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-profile.php');
    sp_profile_add_menu(spa_text('Profile'), spa_text('Edit Identities'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-identities.php');
    sp_profile_add_menu(spa_text('Profile'), spa_text('Edit Avatar'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-avatar.php');
    sp_profile_add_menu(spa_text('Profile'), spa_text('Edit Signature'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-signature.php', 0, 1, 'use_signatures');
    sp_profile_add_menu(spa_text('Profile'), spa_text('Edit Photos'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-photos.php');
    sp_profile_add_menu(spa_text('Profile'), spa_text('Account Settings'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-account.php');
    sp_profile_add_tab(spa_text('Options'));
    sp_profile_add_menu(spa_text('Options'), spa_text('Edit Global Options'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-global-options.php');
    sp_profile_add_menu(spa_text('Options'), spa_text('Edit Posting Options'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-posting-options.php');
    sp_profile_add_menu(spa_text('Options'), spa_text('Edit Display Options'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-display-options.php');
    sp_profile_add_tab(spa_text('Usergroups'));
    sp_profile_add_menu(spa_text('Usergroups'), spa_text('Show Memberships'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-memberships.php');
    sp_profile_add_tab(spa_text('Permissions'));
    sp_profile_add_menu(spa_text('Permissions'), spa_text('Show Permissions'), SF_PLUGIN_DIR . '/forum/profile/forms/sp-form-permissions.php');
    # overview message
    $spProfile = sp_get_option('sfprofile');
    if (empty($spProfile['sfprofiletext'])) {
        $spProfile['sfprofiletext'] = 'Welcome to the User Profile Overview Panel. From here you can view and update your profile and options as well as view your Usergroup Memberships and Permissions.';
        sp_update_option('sfprofile', $spProfile);
    }
}
function sp_create_inspectors()
{
    $ins = array();
    $ins[$i] = array('con_spVars' => 0, 'con_spGlobals' => 0, 'con_spThisUser' => 0, 'con_spDevice' => 0, 'gv_spGroupView' => 0, 'gv_spThisGroup' => 0, 'gv_spThisForum' => 0, 'gv_spThisForumSubs' => 0, 'fv_spForumView' => 0, 'fv_spThisForum' => 0, 'fv_spThisForumSubs' => 0, 'fv_spThisSubForum' => 0, 'fv_spThisTopic' => 0, 'tv_spTopicView' => 0, 'tv_spThisTopic' => 0, 'tv_spThisPost' => 0, 'tv_spThisPostUser' => 0, 'mv_spMembersList' => 0, 'mv_spThisMemberGroup' => 0, 'mv_spThisMember' => 0, 'tlv_spTopicListView' => 0, 'tlv_spThisListTopic' => 0, 'plv_spPostListView' => 0, 'plv_spThisListPost' => 0, 'pro_spProfileUser' => 0, 'q_spGroupView' => 0, 'q_spGroupViewStats' => 0, 'q_spForumView' => 0, 'q_spForumViewStats' => 0, 'q_spTopicView' => 0, 'q_spMembersView' => 0, 'q_spTopicListView' => 0, 'q_spTopicListViewNew' => 0, 'q_spTopicListViewFirst' => 0, 'q_spPostListView' => 0, 'q_spSearchView' => 0);
    sp_update_option('spInspect', $ins);
}