Beispiel #1
0
function sp_rebuild_schema($start, $end)
{
    global $tables, $wpdb;
    # prepare the one exception!
    $opTable = $wpdb->prefix . 'sfoptions';
    $opKey = 'option_id';
    $t = sp_get_option('installed_tables');
    for ($x = $start; $x < $end + 1; $x++) {
        if ($t[$x]) {
            # get list of indexes
            $data = $wpdb->get_results("SHOW INDEXES FROM {$t[$x]}");
            if ($data) {
                foreach ($data as $item) {
                    if ($item->Key_name != 'PRIMARY' && ($t[$x] != $opTable && $item->Key_name != $opKey)) {
                        # remove current index
                        spdb_query('ALTER TABLE ' . $t[$x] . " DROP INDEX {$item->Key_name}");
                    }
                }
            }
            # grab list of table actions
            $actions = $tables[$t[$x]];
            if ($actions) {
                foreach ($actions as $sql) {
                    # add back index
                    spdb_query($sql);
                }
            }
        }
    }
}
function sp_update_users_newposts()
{
    global $spThisUser;
    # Check the users checktime against the last post timestamp to see if we need to do this
    $checkTime = spdb_zone_mysql_checkdate($spThisUser->checktime);
    $postTime = sp_get_option('poststamp');
    if (strtotime($checkTime) > strtotime($postTime) && !isset($_GET['mark-read'])) {
        return;
    }
    # so there must have been a new post since the last page load for this user
    $newPostList = $spThisUser->newposts;
    if (empty($newPostList['topics'])) {
        # clean it up to be on the safe side
        unset($newPostList);
        $newPostList = array();
        $newPostList['topics'] = array();
        $newPostList['forums'] = array();
    }
    # create new holding array and new checktime (now)
    $addPostList = array();
    $addPostList['topics'] = array();
    $addPostList['forums'] = array();
    sp_set_server_timezone();
    $newCheckTime = sp_apply_timezone(time(), 'mysql');
    # Use the current checktime for any new posts since users session began
    $records = spdb_select('set', "SELECT DISTINCT topic_id, forum_id FROM " . SFPOSTS . "\n\t\t\t\t\t\t\t\t   WHERE post_status = 0 AND post_date > '" . $checkTime . "' AND user_id != " . $spThisUser->ID . "\n\t\t\t\t\t\t\t\t   ORDER BY post_id DESC LIMIT " . $spThisUser->unreadposts . ";", ARRAY_A);
    if ($records) {
        foreach ($records as $r) {
            if (sp_get_auth('view_forum', $r['forum_id']) && !in_array($r['topic_id'], $newPostList['topics'])) {
                $addPostList['topics'][] = $r['topic_id'];
                $addPostList['forums'][] = $r['forum_id'];
            }
        }
    }
    $addPostList = apply_filters('sph_new_post_list', $addPostList, $newPostList);
    # now merge the arrays and truncate if necessary
    $newPostList['topics'] = array_merge($addPostList['topics'], $newPostList['topics']);
    $newPostList['forums'] = array_merge($addPostList['forums'], $newPostList['forums']);
    if (count($newPostList['topics']) > $spThisUser->unreadposts) {
        array_splice($newPostList['topics'], $spThisUser->unreadposts);
        array_splice($newPostList['forums'], $spThisUser->unreadposts);
    }
    # update sfmembers - do it here to ensure both are updated together
    spdb_query("UPDATE " . SFMEMBERS . " SET newposts='" . serialize($newPostList) . "', checktime='" . $newCheckTime . "' WHERE user_id=" . $spThisUser->ID);
    $spThisUser->newpostlist = true;
    $spThisUser->checktime = $newCheckTime;
    $spThisUser->newposts = $newPostList;
}
function sp_admin_bar_do_uninstall()
{
    global $spGlobals;
    sp_delete_option('spAdminBar');
    sp_delete_option('spAkismet');
    # remove the auth
    if (!empty($spGlobals['auths_map']['bypass_akismet'])) {
        sp_delete_auth('bypass_akismet');
    }
    # remove our auto update stuff
    $up = sp_get_sfmeta('autoupdate', 'admin');
    if ($up) {
        sp_delete_sfmeta($up[0]['meta_id']);
    }
    # empty out the sfwaiting table
    spdb_query('TRUNCATE ' . SFWAITING);
}
function sp_test_table_create()
{
    # make sure we can create database tables
    $sql = '
		CREATE TABLE sfCheckCreate (
			id int(4) NOT NULL,
			item varchar(15) default NULL,
			PRIMARY KEY	 (id)
		) ' . spdb_charset();
    spdb_query($sql);
    $success = spdb_select('var', 'SHOW TABLES LIKE "sfCheckCreate"');
    if ($success == false) {
        return false;
    } else {
        spdb_query('DROP TABLE sfCheckCreate');
        return true;
    }
}
function sp_rebuild_topic_cache()
{
    $size = sp_get_option('topic_cache');
    if (!isset($size) || $size == 0) {
        sp_add_option('topic_cache', 200);
    }
    $sql = "SELECT DISTINCTROW forum_id, topic_id, post_id, post_status\n\t\t\tFROM " . SFPOSTS . "\n\t\t\tORDER BY post_id DESC\n\t\t\tLIMIT {$size}";
    $topics = spdb_select('set', $sql, ARRAY_N);
    if ($topics) {
        sp_add_sfmeta('topic_cache', 'new', $topics, true);
    }
    # Delete group level cache for good measure
    spdb_query("DELETE FROM " . SFCACHE . " WHERE cache_id LIKE '%*group'");
    return $topics;
}
function spa_update_specialrank($id)
{
    check_admin_referer('special-rank-update', 'special-rank-update');
    # save special forum ranks
    if (!empty($_POST['specialrankdesc'])) {
        $desc = $_POST['specialrankdesc'];
        $badge = $_POST['specialrankbadge'];
        $rank = sp_get_sfmeta('special_rank', false, $id);
        $rank[0]['meta_value']['badge'] = sp_filter_filename_save($badge[$id]);
        sp_update_sfmeta('special_rank', sp_filter_title_save(trim($desc[$id])), $rank[0]['meta_value'], $id, 1);
        if ($_POST['currentname'][$id] != $desc[$id]) {
            spdb_query("UPDATE " . SFSPECIALRANKS . "\n\t\t\t\t\t\tSET special_rank = '" . $desc[$id] . "'\n\t\t\t\t\t\tWHERE special_rank = '" . $_POST['currentname'][$id] . "'");
        }
    }
    do_action('sph_component_srank_update_save');
    $mess = spa_text('Special ranks updated');
    return $mess;
}
function sp_delete_notice($col, $data)
{
    $sql = 'DELETE FROM ' . SFNOTICES . ' WHERE ';
    if (is_numeric($data)) {
        $sql .= "{$col} = {$data}";
    } else {
        $sql .= "{$col} = '{$data}'";
    }
    spdb_query($sql);
}
global $spPaths;
$action = $_GET['action'];
if ($action == 'del_rank') {
    $key = sp_esc_int($_GET['key']);
    # remove the forum rank
    $sql = 'DELETE FROM ' . SFMETA . " WHERE meta_type='forum_rank' AND meta_id='{$key}'";
    spdb_query($sql);
}
if ($action == 'del_specialrank') {
    $key = sp_esc_int($_GET['key']);
    $specialRank = sp_get_sfmeta('special_rank', false, $key);
    # remove members rank first
    spdb_query('DELETE FROM ' . SFSPECIALRANKS . ' WHERE special_rank="' . $specialRank[0]['meta_key'] . '"');
    # remove the forum rank
    $sql = 'DELETE FROM ' . SFMETA . " WHERE meta_type='special_rank' AND meta_id='{$key}'";
    spdb_query($sql);
}
if ($action == 'show') {
    $key = sp_esc_int($_GET['key']);
    $specialRank = sp_get_sfmeta('special_rank', false, $key);
    $users = spdb_select('col', 'SELECT display_name
						  FROM ' . SFSPECIALRANKS . '
						  JOIN ' . SFMEMBERS . ' ON ' . SFSPECIALRANKS . '.user_id = ' . SFMEMBERS . '.user_id
						  WHERE special_rank = "' . $specialRank[0]['meta_key'] . '"
						  ORDER BY display_name');
    echo '<fieldset class="sfsubfieldset">';
    echo '<legend>' . spa_text('Special Rank Members') . '</legend>';
    if ($users) {
        echo '<ul class="memberlist">';
        for ($x = 0; $x < count($users); $x++) {
            echo '<li>' . sp_filter_name_display($users[$x]) . '</li>';
function sp_update_post_urls($old, $new)
{
    global $wpdb;
    if (empty($old) || empty($new)) {
        return;
    }
    $posts = spdb_table(SFPOSTS, 'post_content LIKE "%/' . esc_sql($wpdb->esc_like($old)) . '%"', '');
    if (!empty($posts)) {
        foreach ($posts as $p) {
            $pc = str_replace('/' . $old, '/' . $new, sp_filter_content_edit($p->post_content));
            $pc = sp_filter_content_save($pc, 'edit');
            spdb_query('UPDATE ' . SFPOSTS . " SET post_content = '{$pc}' WHERE post_id=" . $p->post_id);
        }
    }
}
function spa_update_parent_group($currentGroupId, $newGroupId, $forumParent)
{
    $forums = spdb_table(SFFORUMS, "group_id={$currentGroupId} AND parent={$forumParent}");
    if ($forums) {
        foreach ($forums as $forum) {
            # update the old group ID to new one
            $sql = 'UPDATE ' . SFFORUMS . " SET group_id={$newGroupId} WHERE forum_id={$forum->forum_id}";
            spdb_query($sql);
            if ($forum->children) {
                $childlist = array(unserialize($forum->children));
                if (count($childlist) > 0) {
                    spa_update_parent_group($currentGroupId, $newGroupId, $forum->forum_id);
                }
            }
        }
    }
}
Beispiel #11
0
 function insert()
 {
     if (empty($this->table) || empty($this->fields) || empty($this->data) || !is_array($this->data) || !is_array($this->fields)) {
         return false;
     }
     $table = $this->table;
     $values = array();
     foreach ($this->data as $val) {
         if (!is_numeric($val)) {
             $val = "'" . $val . "'";
         }
         $values[] = $val;
     }
     $sql = "INSERT INTO {$table} (" . implode(', ', $this->fields) . ') VALUES (' . implode(', ', $values) . ')';
     if ($this->show) {
         spdb_show_result($sql, $this->inspect);
     }
     $result = spdb_query($sql);
     return $result;
 }
Beispiel #12
0
function sp_rpx_create_wp_user($auth_info)
{
    $p = $auth_info['profile'];
    $rid = $p['identifier'];
    $provider_name = $p['providerName'];
    $username = $p['preferredUsername'];
    if (!$username || sp_rpx_username_taken($username)) {
        $username = sp_rpx_get_user_login_name($rid);
    }
    $last_name = null;
    $first_name = null;
    if (!empty($p['name'])) {
        $first_name = $p['name']['givenName'];
        $last_name = $p['name']['familyName'];
    }
    $email = '*****@*****.**';
    if (!empty($p['email'])) {
        $email = sp_filter_email_save($p['email']);
    }
    $userdata = array('user_pass' => wp_generate_password(), 'user_login' => $username, 'display_name' => sp_filter_name_save($p['displayName']), 'user_url' => $p['url'], 'user_email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, 'nickname' => $p['displayName']);
    # try to create new user
    $wpuid = wp_insert_user($userdata);
    if ($wpuid && !is_wp_error($wpuid)) {
        update_user_meta($wpuid, 'rpx_identifier', $rid);
        # remove temp email?
        if ($email == '*****@*****.**') {
            spdb_query('UPDATE ' . SFUSERS . " SET user_email='' WHERE ID={$wpuid}");
        }
    }
    return $wpuid;
}
function spa_check_warnings()
{
    global $spGlobals;
    # not perfect but we can use this call tyo perform any minor
    # cleanups that may be necessary... so
    # drop any existing temp members table...
    spdb_query('DROP TABLE IF EXISTS sftempmembers');
    $mess = '';
    # check if sp core, plugins or themes update available
    $update = false;
    $update_msg = '';
    $up = get_site_transient('update_plugins');
    if (!empty($up->response)) {
        foreach ($up->response as $plugin) {
            if ($plugin->slug == 'simple-press') {
                $msg = apply_filters('sph_core_update_notice', spa_text('There is a Simple:Press core update available.'));
                if (!empty($msg)) {
                    $update = true;
                    $update_msg .= $msg . '<br />';
                }
                break;
            }
        }
    }
    $up = get_site_transient('sp_update_plugins');
    if (!empty($up)) {
        $msg = apply_filters('sph_plugins_update_notice', spa_text('There is one or more Simple:Press plugin updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    $up = get_site_transient('sp_update_themes');
    if (!empty($up)) {
        $msg = apply_filters('sph_themes_update_notice', spa_text('There is one or more Simple:Press theme updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    if ($update) {
        if (is_main_site()) {
            $mess .= apply_filters('sph_updates_notice', spa_message($update_msg . '<a href="' . self_admin_url('update-core.php') . '">' . spa_text('Click here to view any updates.') . '</a>'));
        } else {
            $mess .= apply_filters('sph_updates_notice', spa_message(spa_text('There are some Simple:Press updates avaialable. You may want to notify the network site admin.')));
        }
    }
    # output warning if no SPF admins are defined
    $a = $spGlobals['forum-admins'];
    if (empty($a)) {
        $mess .= spa_message(spa_text('Warning - There are no SPF admins defined!	 All WP admins now have SP backend access'), 'error');
    }
    # Check if	desktop, tablet and mobile themes are selected and available
    $cur = sp_get_option('sp_current_theme');
    if (empty($cur)) {
        $mess .= spa_message(spa_text('No main theme has been selected and SP will be unable to display correctly. Please select a theme from the Themes panel'), 'error');
    } else {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/' . $cur['style']);
        $nooverlay = !empty($cur['color']) && !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/overlays/' . $cur['color'] . '.php');
        $nopoverlay = !empty($cur['color']) && !empty($cur['parent']) && !file_exists(SPTHEMEBASEDIR . $cur['parent'] . '/styles/overlays/' . $cur['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the theme CSS file and/or color Overlay file from the selected theme is missing'), 'error');
        }
    }
    $mobile = sp_get_option('sp_mobile_theme');
    if (!empty($mobile) && $mobile['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/' . $mobile['style']);
        $nooverlay = !empty($mobile['color']) && !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/overlays/' . $mobile['color'] . '.php');
        $nopoverlay = !empty($mobile['color']) && !empty($mobile['parent']) && !file_exists(SPTHEMEBASEDIR . $mobile['parent'] . '/styles/overlays/' . $mobile['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the mobile theme CSS file and/or color Overlay file from the selected mobile theme is missing'), 'error');
        }
    }
    $tablet = sp_get_option('sp_tablet_theme');
    if (!empty($tablet) && $tablet['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/' . $tablet['style']);
        $nooverlay = !empty($tablet['color']) && !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/overlays/' . $tablet['color'] . '.php');
        $nopoverlay = !empty($tablet['color']) && !empty($tablet['parent']) && !file_exists(SPTHEMEBASEDIR . $tablet['parent'] . '/styles/overlays/' . $tablet['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the tablet theme CSS file and/or color Overlay file from the selected tablet theme is missing'), 'error');
        }
    }
    # check for missing default members user group
    $value = sp_get_sfmeta('default usergroup', 'sfmembers');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for new members is undefined!	Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for missing default guest user group
    $value = sp_get_sfmeta('default usergroup', 'sfguests');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for guests is undefined!  Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for unreachable forums because of permissions
    $usergroups = spdb_table(SFUSERGROUPS);
    if ($usergroups) {
        $has_members = false;
        foreach ($usergroups as $usergroup) {
            $members = spdb_table(SFMEMBERSHIPS, "usergroup_id={$usergroup->usergroup_id}", 'row', '', '1');
            if ($members || $usergroup->usergroup_id == $value[0]['meta_value']) {
                $has_members = true;
                break;
            }
        }
        if (!$has_members) {
            $mess .= spa_message(spa_text('Warning - There are no usergroups that have members!	All forums may only be visible to SP admins'), 'error');
        }
    } else {
        $mess .= spa_message(spa_text('Warning - There are no usergroups defined!  All forums may only be visible to SP admins'), 'error');
    }
    $roles = sp_get_all_roles();
    if (!$roles) {
        $mess .= spa_message(spa_text('Warning - There are no permission sets defined!  All forums may only be visible to SP admins'), 'error');
    }
    # check if compatible with wp super cache
    if (function_exists('wp_cache_edit_rejected')) {
        global $cache_rejected_uri;
        $slug = '/' . sp_get_option('sfslug') . '/';
        if (isset($cache_rejected_uri)) {
            $found = false;
            foreach ($cache_rejected_uri as $value) {
                if ($value == $slug) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $string = spa_text('WP Super Cache is not properly configured to work with Simple:Press. Please visit your WP Super Cache settings page and in the accepted filenames & rejected URIs section for the pages not to be cached input field, add the following string');
                $string .= ':</p><p><em>' . $slug . '</em></p><p>';
                $string .= spa_text('Then, please clear your WP Super Cache cache to remove any cached Simple:Press pages');
                $string .= ':</p><p><em>' . spa_text('For more information please see this') . ' <a href="http://simple-press.com/documentation/codex/faq/troubleshooting/forum-displays-wrong-information/" target="_blank">' . spa_text('FAQ') . '</a></p><p>';
                $mess .= spa_message($string, 'error');
            }
        }
    }
    # check if compatible with w3 total cache (at leasst check for slug
    $f = WP_CONTENT_DIR . '/cache/config/master.php';
    if (file_exists($f) && is_readable($f)) {
        $c = file_get_contents($f);
        $c = substr($c, 13);
        $config = @unserialize($c);
        if (key_exists('pgcache.reject.uri', $config) && !empty($config['pgcache.reject.uri'])) {
            $found = false;
            $slug = '/' . sp_get_option('sfslug') . '/';
            foreach ($config['pgcache.reject.uri'] as $i) {
                if ($i == $slug) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $string = spa_text('W3 Total Cache is not properly configured to work with Simple:Press. Please visit your W3 Total Cache settings page and in the accepted filenames & rejected URIs in ALL sections, add the following string');
                $string .= ':</p><p><em>' . $slug . '</em></p><p>';
                $string .= spa_text('Then, please clear your W3 Total Cache cache to remove any cached Simple:Press pages');
                $string .= ':</p><p><em>' . spa_text('For more information please see this') . ' <a href="http://simple-press.com/documentation/codex/faq/troubleshooting/forum-displays-wrong-information/" target="_blank">' . spa_text('FAQ') . '</a></p><p>';
                $mess .= spa_message($string, 'error');
            }
        }
    }
    # check for server-side UTC timezone
    $tz = get_option('timezone_string');
    if (empty($tz)) {
        $tz = 'UTC ' . get_option('gmt_offset');
        $string = spa_text('You have set your server to use a UTC timezone setting');
        $string .= ':</p><p><em>' . $tz . '</em></p><p>';
        $string .= spa_text('UTC can give unpredictable results on forum post time stamps. Please select the city setting nearest to you in the WordPress - Settings - General admin page');
        $string .= ':</p><p><em>' . spa_text('For more information please see this') . ' <a href="http://simple-press.com/documentation/codex/faq/troubleshooting/why-do-my-new-posts-show-as-posted-minus-seconds-ago/" target="_blank">' . spa_text('FAQ') . '</a></p><p>';
        $mess .= spa_message($string, 'error');
    }
    if ($mess != '') {
        return $mess;
    }
}
function spa_save_housekeeping_data()
{
    check_admin_referer('forum-adminform_housekeeping', 'forum-adminform_housekeeping');
    $mess = '';
    if (isset($_POST['rebuild-fidx'])) {
        $forumid = $_POST['forum_id'];
        if (is_numeric($forumid)) {
            $topics = spdb_table(SFTOPICS, "forum_id={$forumid}");
            if ($topics) {
                include_once SF_PLUGIN_DIR . '/forum/database/sp-db-management.php';
                foreach ($topics as $topic) {
                    sp_build_post_index($topic->topic_id);
                }
                # after reubuilding post indexes, rebuild the forum indexes
                sp_build_forum_index($forumid);
                do_action('sph_toolbox_housekeeping_forum_index');
                $mess = spa_text('Forum indexes rebuilt');
            } else {
                $mess = spa_text('Forum index rebuild failed - no topics in selected forum');
            }
        } else {
            $mess = spa_text('Forum index rebuild failed - no forum selected');
        }
    }
    if (isset($_POST['transient-cleanup'])) {
        include_once SF_PLUGIN_DIR . '/forum/database/sp-db-management.php';
        sp_transient_cleanup();
        do_action('sph_toolbox_housekeeping_transient');
        $mess = spa_text('WP transients cleaned');
    }
    if (isset($_POST['clean-newposts'])) {
        $days = isset($_POST['sfdays']) ? max(sp_esc_int($_POST['sfdays']), 0) : 30;
        $users = spdb_select('col', "SELECT user_id FROM " . SFMEMBERS . " WHERE lastvisit < DATE_SUB(CURDATE(), INTERVAL " . $days . " DAY)");
        if ($users) {
            foreach ($users as $user) {
                spdb_query('UPDATE ' . SFMEMBERS . " SET newposts='a:1:{i:0;i:0;}' WHERE user_id={$user}");
            }
        }
        do_action('sph_toolbox_housekeeping_newpost');
        $mess = spa_text('New posts lists cleaned');
    }
    if (isset($_POST['postcount-cleanup'])) {
        spdb_query('UPDATE ' . SFMEMBERS . ' SET posts = (SELECT COUNT(*) FROM ' . SFPOSTS . ' WHERE ' . SFPOSTS . '.user_id = ' . SFMEMBERS . '.user_id)');
        # force stats to update
        do_action('sph_stats_cron');
        do_action('sph_toolbox_housekeeping_postcount');
        $mess = spa_text('User post counts calculated');
    }
    if (isset($_POST['reset-tabs'])) {
        # clear out current tabs
        $tabs = sp_get_sfmeta('profile', 'tabs');
        sp_delete_sfmeta($tabs[0]['meta_id']);
        # start adding new ones
        spa_new_profile_setup();
        do_action('sph_toolbox_housekeeping_profile_tabs');
        $mess = spa_text('Profile tabs reset');
    }
    if (isset($_POST['reset-auths'])) {
        sp_reset_auths();
        do_action('sph_toolbox_housekeeping_auths');
        $mess = spa_text('Auths caches cleaned');
    }
    if (isset($_POST['reset-plugin-data'])) {
        sp_reset_member_plugindata();
        do_action('sph_toolbox_housekeeping_plugindata');
        $mess = spa_text('Users Plugin Data reset');
    }
    if (isset($_POST['reset-combinedcss'])) {
        sp_clear_combined_css('all');
        sp_clear_combined_css('mobile');
        sp_clear_combined_css('tablet');
        do_action('sph_toolbox_housekeeping_ccombined_css');
        $mess = spa_text('Combined CSS cache file removed');
    }
    if (isset($_POST['reset-combinedjs'])) {
        sp_clear_combined_scripts('desktop');
        sp_clear_combined_scripts('mobile');
        sp_clear_combined_scripts('tablet');
        do_action('sph_toolbox_housekeeping_combined_js');
        $mess = spa_text('Combined scripts cache files removed');
    }
    if (isset($_POST['flushcache'])) {
        sp_flush_cache('all');
        do_action('sph_toolbox_housekeeping_flush_cache');
        $mess = spa_text('General cache flushed');
    }
    do_action('sph_toolbox_housekeeping_save');
    return $mess;
}
<?php

/*
Simple:Press
Remove a user notice in demand
$LastChangedDate: 2012-11-19 14:00:20 -0800 (Mon, 19 Nov 2012) $
$Rev: 9330 $
*/
if (preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
    die('Access denied - you cannot directly call this file');
}
sp_forum_api_support();
if (isset($_GET['notice'])) {
    $id = (int) $_GET['notice'];
    if ($id) {
        spdb_query('DELETE FROM ' . SFNOTICES . " WHERE notice_id={$id}");
    }
}
die;
function spa_deactivate_plugin()
{
    $uninstall = sp_get_option('sfuninstall');
    if ($uninstall) {
        # uninstall - remove all data
        # remove any admin capabilities
        $admins = spdb_table(SFMEMBERS, 'admin=1');
        foreach ($admins as $admin) {
            $user = new WP_User($admin->user_id);
            $user->remove_cap('SPF Manage Options');
            $user->remove_cap('SPF Manage Forums');
            $user->remove_cap('SPF Manage User Groups');
            $user->remove_cap('SPF Manage Permissions');
            $user->remove_cap('SPF Manage Tags');
            $user->remove_cap('SPF Manage Components');
            $user->remove_cap('SPF Manage Admins');
            $user->remove_cap('SPF Manage Profiles');
            $user->remove_cap('SPF Manage Users');
            $user->remove_cap('SPF Manage Toolbox');
            $user->remove_cap('SPF Manage Plugins');
            $user->remove_cap('SPF Manage Themes');
            $user->remove_cap('SPF Manage Integration');
            $user->remove_cap('SPF Manage Configuration');
            # no longer used but some may still have it
        }
        # remove any installed tables
        $tables = sp_get_option('installed_tables');
        if ($tables) {
            foreach ($tables as $table) {
                spdb_query("DROP TABLE IF EXISTS {$table}");
            }
        }
        # since we have removed our tables, need to turn off error logging to prevent onslaught of errors
        global $spGlobals;
        $spGlobals['record-errors'] = false;
        # Remove the Page record
        $sfpage = sp_get_option('sfpage');
        if (!empty($sfpage)) {
            spdb_query('DELETE FROM ' . SFWPPOSTS . ' WHERE ID=' . sp_get_option('sfpage'));
        }
        # remove widget data
        delete_option('widget_spf');
        delete_option('widget_sforum');
        # remove any wp options we might have set
        delete_option('sfInstallID');
        delete_option('sp_storage1');
        delete_option('sp_storage2');
        # Now remove user meta data
        $optionlist = array('sfadmin', 'location', 'msn', 'skype', 'icq', 'facebook', 'myspace', 'twitter', 'linkedin', 'youtube', 'googleplus', 'sfuse_quicktags', 'signature', 'sigimage');
        foreach ($optionlist as $option) {
            spdb_query('DELETE FROM ' . SFUSERMETA . " WHERE meta_key='{$option}';");
        }
        # send our uninstall action
        do_action('sph_uninstalled', $admins);
        # remove storage locations if so directed
        if (sp_get_option('removestorage')) {
            # let's remove our directories and storage
            global $spPaths;
            if (!empty($spPaths)) {
                foreach ($spPaths as $storage => $path) {
                    # lets not remove plugins and themes
                    if ($storage != 'plugins' && $storage != 'themes') {
                        sp_remove_dir(SF_STORE_DIR . '/' . $path);
                    }
                }
            }
            # remove the languages folder if it exists
            # note the sp-resources dire may not exist - but its our default. if user creates other parent dir for languages, we wont know about  it
            sp_remove_dir(SF_STORE_DIR . '/sp-resources/forum-language');
        }
    }
    # remove the combined css and js cache files
    sp_clear_combined_css('all');
    sp_clear_combined_css('mobile');
    sp_clear_combined_css('tablet');
    # remove cron jobs for deactivaton or uninstall
    wp_clear_scheduled_hook('spf_cron_pm');
    # left here for 5.0 who doesnt upgrade
    wp_clear_scheduled_hook('spf_cron_sitemap');
    # left here for 5.0 who doesnt upgrade
    wp_clear_scheduled_hook('sph_cron_user');
    wp_clear_scheduled_hook('sph_transient_cleanup_cron');
    wp_clear_scheduled_hook('sph_stats_cron');
    wp_clear_scheduled_hook('sph_news_cron');
    # send deactivated action
    if (!$uninstall) {
        do_action('sph_deactivated');
    }
}
function spa_save_usergroups_delete_usergroup()
{
    check_admin_referer('forum-adminform_usergroupdelete', 'forum-adminform_usergroupdelete');
    $usergroup_id = sp_esc_int($_POST['usergroup_id']);
    # dont allow updates to the default user groups
    $usergroup = spa_get_usergroups_row($usergroup_id);
    if ($usergroup->usergroup_locked) {
        $mess = spa_text('Sorry, the default User Groups cannot be deleted');
        return $mess;
    }
    # remove all memberships for this user group
    spdb_query("DELETE FROM " . SFMEMBERSHIPS . " WHERE usergroup_id=" . $usergroup_id);
    # remove any permission sets using this user group
    $permissions = spdb_table(SFPERMISSIONS, "usergroup_id={$usergroup_id}");
    if ($permissions) {
        foreach ($permissions as $permission) {
            spa_remove_permission_data($permission->permission_id);
        }
    }
    # remove any group default permissions using this user group
    spdb_query("DELETE FROM " . SFDEFPERMISSIONS . " WHERE usergroup_id=" . $usergroup_id);
    # remove the user group
    spdb_query("DELETE FROM " . SFMEMBERSHIPS . " WHERE usergroup_id=" . $usergroup_id);
    $success = spdb_query("DELETE FROM " . SFUSERGROUPS . " WHERE usergroup_id=" . $usergroup_id);
    if ($success == false) {
        $mess = spa_text('User group delete failed');
    } else {
        $mess = spa_text('User group deleted');
        # reset auths and memberships for everyone
        sp_reset_memberships();
        sp_reset_auths();
        do_action('sph_usergroup_del', $usergroup_id);
    }
    return $mess;
}
function sp_track_logout()
{
    global $current_user;
    sp_set_last_visited($current_user->ID);
    spdb_query("DELETE FROM " . SFTRACK . " WHERE trackuserid=" . $current_user->ID);
    # clear the users search cache
    sp_delete_cache('search');
}
function sp_UpdateProfile()
{
    global $spGlobals, $spThisUser;
    # make sure nonce is there
    check_admin_referer('forum-profile', 'forum-profile');
    $message = array();
    # dont update forum if its locked down
    if ($spGlobals['lockdown']) {
        $message['type'] = 'error';
        $message['text'] = sp_text('This forum is currently locked - access is read only - profile not updated');
        return $message;
    }
    # do we have a form to update?
    if (isset($_GET['form'])) {
        $thisForm = sp_esc_str($_GET['form']);
    } else {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid form');
        return $message;
    }
    # do we have an actual user to update?
    if (isset($_GET['userid'])) {
        $thisUser = sp_esc_int($_GET['userid']);
    } else {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid user');
        return $message;
    }
    # Check the user ID for current user of admin edit
    if ($thisUser != $spThisUser->ID && !$spThisUser->admin) {
        $message['type'] = 'error';
        $message['text'] = sp_text('Profile update aborted - no valid user');
        return $message;
    }
    if (isset($spThisUser->sp_change_pw) && $spThisUser->sp_change_pw) {
        $pass1 = $pass2 = '';
        if (isset($_POST['pass1'])) {
            $pass1 = $_POST['pass1'];
        }
        if (isset($_POST['pass2'])) {
            $pass2 = $_POST['pass2'];
        }
        if (empty($pass1) || empty($pass2) || $pass1 != $pass2) {
            $message['type'] = 'error';
            $message['text'] = sp_text('Cannot save profile until password has been changed');
            return $message;
        }
    }
    # form save filter
    $thisForm = apply_filters('sph_profile_save_thisForm', $thisForm);
    # valid save attempt, so lets process the save
    switch ($thisForm) {
        case 'show-memberships':
            # update memberships
            # any usergroup removals?
            if (isset($_POST['usergroup_leave'])) {
                foreach ($_POST['usergroup_leave'] as $membership) {
                    sp_remove_membership(sp_esc_str($membership), $thisUser);
                }
            }
            # any usergroup joins?
            if (isset($_POST['usergroup_join'])) {
                foreach ($_POST['usergroup_join'] as $membership) {
                    sp_add_membership(sp_esc_int($membership), $thisUser);
                }
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileMemberships', $message, $thisUser);
            # output update message
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Memberships updated');
            }
            break;
        case 'account-settings':
            # update account settings
            # check for password update
            $pass1 = $pass2 = '';
            if (isset($_POST['pass1'])) {
                $pass1 = $_POST['pass1'];
            }
            if (isset($_POST['pass2'])) {
                $pass2 = $_POST['pass2'];
            }
            if (!empty($pass1) || !empty($pass2)) {
                if ($pass1 != $pass2) {
                    $message['type'] = 'error';
                    $message['text'] = sp_text('Please enter the same password in the two password fields');
                    return $message;
                } else {
                    # update the password
                    $user = new stdClass();
                    $user->ID = (int) $thisUser;
                    $user->user_pass = $pass1;
                    wp_update_user(get_object_vars($user));
                    if (isset($spThisUser->sp_change_pw) && $spThisUser->sp_change_pw) {
                        delete_user_meta($spThisUser->ID, 'sp_change_pw');
                    }
                }
            }
            # now check the email is valid and unique
            $update = apply_filters('sph_ProfileUserEmailUpdate', true);
            if ($update) {
                $curEmail = sp_filter_email_save($_POST['curemail']);
                $email = sp_filter_email_save($_POST['email']);
                if ($email != $curEmail) {
                    if (empty($email)) {
                        $message['type'] = 'error';
                        $message['text'] = sp_text('Please enter a valid email address');
                        return $message;
                    } elseif (($owner_id = email_exists($email)) && $owner_id != $thisUser) {
                        $message['type'] = 'error';
                        $message['text'] = sp_text('The email address is already registered. Please choose another one');
                        return $message;
                    }
                    # save new email address
                    $sql = 'UPDATE ' . SFUSERS . " SET user_email='{$email}' WHERE ID=" . $thisUser;
                    spdb_query($sql);
                }
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileSettings', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Account settings updated');
            }
            break;
        case 'edit-profile':
            # update profile settings
            # validate any username change
            $update = apply_filters('sph_ProfileUserDisplayNameUpdate', true);
            if ($update) {
                $spProfile = sp_get_option('sfprofile');
                if ($spProfile['nameformat'] || $spThisUser->admin) {
                    $display_name = !empty($_POST['display_name']) ? trim($_POST['display_name']) : spdb_table(SFUSERS, "ID={$thisUser}", 'user_login');
                    $display_name = sp_filter_name_save($display_name);
                    # make sure display name isnt already used
                    if ($_POST['oldname'] != $display_name) {
                        $records = spdb_table(SFMEMBERS, "display_name='{$display_name}'");
                        if ($records) {
                            foreach ($records as $record) {
                                if ($record->user_id != $thisUser) {
                                    $message['type'] = 'error';
                                    $message['text'] = $display_name . ' ' . sp_text('is already in use - please choose a different display name');
                                    return $message;
                                }
                            }
                        }
                        # validate display name
                        $errors = new WP_Error();
                        $user = new stdClass();
                        $user->display_name = $display_name;
                        sp_validate_display_name($errors, true, $user);
                        if ($errors->get_error_codes()) {
                            $message['type'] = 'error';
                            $message['text'] = sp_text('The display name you have chosen is not allowed on this site');
                            return $message;
                        }
                        # now save the display name
                        sp_update_member_item($thisUser, 'display_name', $display_name);
                        # Update new users list with changed display name
                        sp_update_newuser_name(sp_filter_name_save($_POST['oldname']), $display_name);
                        # do we need to sync display name with wp?
                        $options = sp_get_member_item($thisUser, 'user_options');
                        if ($options['namesync']) {
                            spdb_query('UPDATE ' . SFUSERS . ' SET display_name="' . $display_name . '" WHERE ID=' . $thisUser);
                        }
                    }
                }
            }
            # save the url
            $update = apply_filters('sph_ProfileUserWebsiteUpdate', true);
            if ($update) {
                $url = sp_filter_url_save($_POST['website']);
                $sql = 'UPDATE ' . SFUSERS . ' SET user_url="' . $url . '" WHERE ID=' . $thisUser;
                spdb_query($sql);
            }
            # update first name, last name, location and biorgraphy
            $update = apply_filters('sph_ProfileUserFirstNameUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'first_name', sp_filter_name_save(trim($_POST['first_name'])));
            }
            $update = apply_filters('sph_ProfileUserLastNameUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'last_name', sp_filter_name_save(trim($_POST['last_name'])));
            }
            $update = apply_filters('sph_ProfileUserLocationUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'location', sp_filter_title_save(trim($_POST['location'])));
            }
            $update = apply_filters('sph_ProfileUserBiographyUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'description', sp_filter_save_kses($_POST['description']));
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileProfile', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Profile settings updated');
            }
            break;
        case 'edit-identities':
            # update identity settings
            # update the user identities
            $update = apply_filters('sph_ProfileUserAIMUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'aim', sp_filter_title_save(trim($_POST['aim'])));
            }
            $update = apply_filters('sph_ProfileUserYahooUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'yim', sp_filter_title_save(trim($_POST['yim'])));
            }
            $update = apply_filters('sph_ProfileUserGoogleUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'jabber', sp_filter_title_save(trim($_POST['jabber'])));
            }
            $update = apply_filters('sph_ProfileUserMSNUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'msn', sp_filter_title_save(trim($_POST['msn'])));
            }
            $update = apply_filters('sph_ProfileUserICQUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'icq', sp_filter_title_save(trim($_POST['icq'])));
            }
            $update = apply_filters('sph_ProfileUserSkypeUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'skype', sp_filter_title_save(trim($_POST['skype'])));
            }
            $update = apply_filters('sph_ProfileUserFacebookUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'facebook', sp_filter_title_save(trim($_POST['facebook'])));
            }
            $update = apply_filters('sph_ProfileUserMySpaceUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'myspace', sp_filter_title_save(trim($_POST['myspace'])));
            }
            $update = apply_filters('sph_ProfileUserTwitterUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'twitter', sp_filter_title_save(trim($_POST['twitter'])));
            }
            $update = apply_filters('sph_ProfileUserLinkedInUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'linkedin', sp_filter_title_save(trim($_POST['linkedin'])));
            }
            $update = apply_filters('sph_ProfileUserYouTubeUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'youtube', sp_filter_title_save(trim($_POST['youtube'])));
            }
            $update = apply_filters('sph_ProfileUserGooglePlusUpdate', true);
            if ($update) {
                update_user_meta($thisUser, 'googleplus', sp_filter_title_save(trim($_POST['googleplus'])));
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileIdentities', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Identities updated');
            }
            break;
        case 'avatar-upload':
            # upload avatar
            # did we get an avatar to upload?
            if (empty($_FILES['avatar-upload']['name'])) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar filename was empty');
                return $message;
            }
            # Verify the file extension
            global $spPaths;
            $uploaddir = SF_STORE_DIR . '/' . $spPaths['avatars'] . '/';
            $filename = basename($_FILES['avatar-upload']['name']);
            $path = pathinfo($filename);
            $ext = strtolower($path['extension']);
            if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, only JPG, JPEG, PNG, or GIF files are allowed');
                return $message;
            }
            # check image file mimetype
            $mimetype = 0;
            $mimetype = exif_imagetype($_FILES['avatar-upload']['tmp_name']);
            if (empty($mimetype) || $mimetype == 0 || $mimetype > 3) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file is an invalid format');
                return $message;
            }
            # make sure file extension and mime type actually match
            if ($mimetype == 1 && $ext != 'gif' || $mimetype == 2 && ($ext != 'jpg' && $ext != 'jpeg') || $mimetype == 3 && $ext != 'png') {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the file mime type does not match file extension');
                return $message;
            }
            # Clean up file name just in case
            $filename = date('U') . sp_filter_filename_save(basename($_FILES['avatar-upload']['name']));
            $uploadfile = $uploaddir . $filename;
            # check for existence
            if (file_exists($uploadfile)) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file already exists');
                return $message;
            }
            # check file size against limit if provided
            $spAvatars = sp_get_option('sfavatars');
            if ($_FILES['avatar-upload']['size'] > $spAvatars['sfavatarfilesize']) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file exceeds the maximum allowed size');
                return $message;
            }
            # valid avatar, so try moving the uploaded file to the avatar storage directory
            if (move_uploaded_file($_FILES['avatar-upload']['tmp_name'], $uploadfile)) {
                @chmod("{$uploadfile}", 0644);
                # do we need to resize?
                $sfavatars = sp_get_option('sfavatars');
                if ($sfavatars['sfavatarresize']) {
                    $editor = wp_get_image_editor($uploadfile);
                    if (is_wp_error($editor)) {
                        @unlink($uploadfile);
                        $message['type'] = 'error';
                        $message['text'] = sp_text('Sorry, there was a problem resizing the avatar');
                        return $message;
                    } else {
                        $editor->resize($sfavatars['sfavatarsize'], $sfavatars['sfavatarsize'], true);
                        $imageinfo = $editor->save($uploadfile);
                        $filename = $imageinfo['file'];
                    }
                }
                # update member avatar data
                $avatar = sp_get_member_item($thisUser, 'avatar');
                $avatar['uploaded'] = $filename;
                sp_update_member_item($thisUser, 'avatar', $avatar);
            } else {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, the avatar file could not be moved to the avatar storage location');
                return $message;
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarUpload', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Uploaded avatar updated');
            }
            break;
        case 'avatar-pool':
            # pool avatar
            # get pool avatar name
            $filename = sp_filter_filename_save($_POST['spPoolAvatar']);
            # error if no pool avatar provided
            if (empty($filename)) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Sorry, you must select a pool avatar before trying to save it');
                return $message;
            }
            # save the pool avatar
            $avatar = sp_get_member_item($thisUser, 'avatar');
            $avatar['pool'] = $filename;
            sp_update_member_item($thisUser, 'avatar', $avatar);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarPool', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Pool avatar updated');
            }
            break;
        case 'avatar-remote':
            # remote avatar
            # get remote avatar name
            $filename = sp_filter_url_save($_POST['spAvatarRemote']);
            $avatar = sp_get_member_item($thisUser, 'avatar');
            $avatar['remote'] = $filename;
            sp_update_member_item($thisUser, 'avatar', $avatar);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileAvatarRemote', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Remote avatar updated');
            }
            break;
        case 'edit-signature':
            # save signature
            # Check if maxmium links has been exceeded
            $numLinks = substr_count($_POST['postitem'], '</a>');
            $spFilters = sp_get_option('sffilters');
            if (!sp_get_auth('create_links', 'global', $thisUser) && $numLinks > 0 && !$spThisUser->admin) {
                $message['type'] = 'error';
                $message['text'] = sp_text('You are not allowed to put links in signatures');
                return $message;
            }
            if (sp_get_auth('create_links', 'global', $thisUser) && $spFilters['sfmaxlinks'] != 0 && $numLinks > $spFilters['sfmaxlinks'] && !$spThisUser->admin) {
                $message['type'] = 'error';
                $message['text'] = sp_text('Maximum number of allowed links exceeded in signature') . ': ' . $spFilters['sfmaxlinks'] . ' ' . sp_text('allowed');
                return $message;
            }
            //			$sig = esc_sql(sp_filter_save_kses(trim($_POST['postitem'])));
            $sig = sp_filter_content_save($_POST['postitem'], 'edit');
            sp_update_member_item($thisUser, 'signature', $sig);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileSignature', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Signature updated');
            }
            break;
        case 'edit-photos':
            # save photos
            $photos = array();
            $spProfileOptions = sp_get_option('sfprofile');
            for ($x = 0; $x < $spProfileOptions['photosmax']; $x++) {
                $photos[$x] = sp_filter_url_save($_POST['photo' . $x]);
            }
            update_user_meta($thisUser, 'photos', $photos);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfilePhotos', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Photos updated');
            }
            break;
        case 'edit-global-options':
            # save global options
            $options = sp_get_member_item($thisUser, 'user_options');
            $options['hidestatus'] = isset($_POST['hidestatus']) ? true : false;
            $update = apply_filters('sph_ProfileUserSyncNameUpdate', true);
            if ($update) {
                $options['namesync'] = isset($_POST['namesync']) ? true : false;
            }
            sp_update_member_item($thisUser, 'user_options', $options);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileGlobalOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Global options updated');
            }
            break;
        case 'edit-posting-options':
            # save posting options
            $update = apply_filters('sph_ProfileUserEditorUpdate', true);
            if ($update) {
                $options = sp_get_member_item($thisUser, 'user_options');
                if (isset($_POST['editor'])) {
                    $options['editor'] = sp_esc_int($_POST['editor']);
                }
                sp_update_member_item($thisUser, 'user_options', $options);
            }
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfilePostingOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Posting options updated');
            }
            break;
        case 'edit-display-options':
            # save display options
            $options = sp_get_member_item($thisUser, 'user_options');
            if (isset($_POST['timezone'])) {
                if (preg_match('/^UTC[+-]/', $_POST['timezone'])) {
                    # correct for manual UTC offets
                    $userOffset = preg_replace('/UTC\\+?/', '', $_POST['timezone']) * 3600;
                } else {
                    # get timezone offset for user
                    $date_time_zone_selected = new DateTimeZone(sp_esc_str($_POST['timezone']));
                    $userOffset = timezone_offset_get($date_time_zone_selected, date_create());
                }
                # get timezone offset for server based on wp settings
                $wptz = get_option('timezone_string');
                if (empty($wptz)) {
                    $serverOffset = get_option('gmt_offset');
                } else {
                    $date_time_zone_selected = new DateTimeZone($wptz);
                    $serverOffset = timezone_offset_get($date_time_zone_selected, date_create());
                }
                # calculate time offset between user and server
                $options['timezone'] = (int) round(($userOffset - $serverOffset) / 3600, 2);
                $options['timezone_string'] = sp_esc_str($_POST['timezone']);
            } else {
                $options['timezone'] = 0;
                $options['timezone_string'] = 'UTC';
            }
            if (isset($_POST['unreadposts'])) {
                $sfcontrols = sp_get_option('sfcontrols');
                $options['unreadposts'] = is_numeric($_POST['unreadposts']) ? max(min(sp_esc_int($_POST['unreadposts']), $sfcontrols['sfmaxunreadposts']), 0) : $sfcontrols['sfdefunreadposts'];
            }
            $options['topicASC'] = isset($_POST['topicASC']);
            $options['postDESC'] = isset($_POST['postDESC']);
            sp_update_member_item($thisUser, 'user_options', $options);
            # fire action for plugins
            $message = apply_filters('sph_UpdateProfileDisplayOptions', $message, $thisUser);
            # output profile save status
            if (empty($message)) {
                $message['type'] = 'success';
                $message['text'] = sp_text('Display options updated');
            }
            break;
        default:
            break;
    }
    # let plugins do their thing on success
    $message = apply_filters('sph_ProfileFormSave_' . $thisForm, $message, $thisUser, $thisForm);
    do_action('sph_UpdateProfile', $thisUser, $thisForm);
    # reset the plugin_data just in case
    sp_reset_member_plugindata($thisUser);
    # done saving - return the messages
    return $message;
}
Beispiel #20
0
function sp_perform_install($phase, $subphase = 0)
{
    global $current_user, $spVars;
    switch ($phase) {
        case 1:
            # create an array of installed tables to save for uninstall. plugins will add theirs to be sure we get good cleanup
            $tables = array();
            # sfauthcats table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFAUTHCATS . ' (
					authcat_id tinyint(4) NOT NULL auto_increment,
					authcat_name varchar(50) NOT NULL,
					authcat_slug varchar(50) NOT NULL,
					authcat_desc tinytext,
					PRIMARY KEY	 (authcat_id),
					KEY authcat_slug_idx (authcat_slug)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFAUTHCATS;
            # sfauths table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFAUTHS . " (\n\t\t\t\t\tauth_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tauth_name varchar(50) NOT NULL,\n\t\t\t\t\tauth_desc text,\n\t\t\t\t\tactive smallint(1) NOT NULL default '0',\n\t\t\t\t\tignored smallint(1) NOT NULL default '0',\n\t\t\t\t\tenabling smallint(1) NOT NULL default '0',\n\t\t\t\t\tadmin_negate smallint(1) NOT NULL default '0',\n\t\t\t\t\tauth_cat bigint(20) NOT NULL default '1',\n\t\t\t\t\twarning tinytext,\n\t\t\t\t\tPRIMARY KEY\t (auth_id),\n\t\t\t\t\tKEY auth_name_idx (auth_name)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFAUTHS;
            # the cache table (5.4.2)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFCACHE . " (\n\t\t\t\t\tcache_id varchar(40) NOT NULL DEFAULT '',\n\t\t\t\t\tcache_out bigint(6) DEFAULT NULL,\n\t\t\t\t\tcache mediumtext,\n\t\t\t\t\tPRIMARY KEY (cache_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFCACHE;
            # sfdefpermissions table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFDEFPERMISSIONS . " (\n\t\t\t\t\tpermission_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tgroup_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tpermission_role bigint(20) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (permission_id),\n\t\t\t\t\tKEY group_id_idx (group_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id),\n\t\t\t\t\tKEY permission_role_idx (permission_role)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFDEFPERMISSIONS;
            # error log table
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFERRORLOG . " (\n\t\t\t\t\tid bigint(20) NOT NULL auto_increment,\n\t\t\t\t\terror_date datetime NOT NULL,\n\t\t\t\t\terror_type varchar(10) NOT NULL,\n\t\t\t\t\terror_cat varchar(13) NOT NULL default 'spaErrOther',\n\t\t\t\t\tkeycheck varchar(45),\n\t\t\t\t\terror_count smallint(6),\n\t\t\t\t\terror_text text,\n\t\t\t\t\tPRIMARY KEY (id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFERRORLOG;
            # sfforums table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFFORUMS . " (\n\t\t\t\t\tforum_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tforum_name varchar(200) NOT NULL,\n\t\t\t\t\tgroup_id bigint(20) NOT NULL,\n\t\t\t\t\tforum_seq int(4) default NULL,\n\t\t\t\t\tforum_desc text default NULL,\n\t\t\t\t\tforum_status int(4) NOT NULL default '0',\n\t\t\t\t\tforum_disabled smallint(1) NOT NULL default '0',\n\t\t\t\t\tforum_slug varchar(200) NOT NULL,\n\t\t\t\t\tforum_rss text default NULL,\n\t\t\t\t\tforum_icon varchar(50) default NULL,\n\t\t\t\t\tforum_icon_new varchar(50) default NULL,\n\t\t\t\t\tforum_icon_locked varchar(50) default NULL,\n\t\t\t\t\ttopic_icon varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_new varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_locked varchar(50) default NULL,\n\t\t\t\t\ttopic_icon_pinned varchar(50) default NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tpost_id_held bigint(20) default NULL,\n\t\t\t\t\ttopic_count mediumint(8) default '0',\n\t\t\t\t\tpost_count mediumint(8) default '0',\n\t\t\t\t\tpost_count_held mediumint(8) default '0',\n\t\t\t\t\tforum_rss_private smallint(1) NOT NULL default '0',\n\t\t\t\t\tparent bigint(20) NOT NULL default '0',\n\t\t\t\t\tchildren text default NULL,\n\t\t\t\t\tforum_message text,\n\t\t\t\t\tkeywords varchar(256) default NULL,\n\t\t\t\t\tPRIMARY KEY\t (forum_id),\n\t\t\t\t\tKEY group_id_idx (group_id),\n\t\t\t\t\tKEY forum_slug_idx (forum_slug),\n\t\t\t\t\tKEY post_id_idx (post_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFFORUMS;
            # sfgroups table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFGROUPS . ' (
					group_id bigint(20) NOT NULL auto_increment,
					group_name text,
					group_seq int(4) default NULL,
					group_desc text,
					group_rss text,
					group_icon varchar(50) default NULL,
					group_message text,
					PRIMARY KEY	 (group_id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFGROUPS;
            # install log table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFLOG . ' (
					id bigint(20) NOT NULL auto_increment,
					user_id bigint(20) NOT NULL,
					install_date date NOT NULL,
					release_type varchar(20),
					version varchar(10) NOT NULL,
					build int(6) NOT NULL,
					PRIMARY KEY (id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFLOG;
            # install log section table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFLOGMETA . ' (
					id int(11) unsigned NOT NULL AUTO_INCREMENT,
					version varchar(10) DEFAULT NULL,
					log_data tinytext,
					PRIMARY KEY (id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFLOGMETA;
            # sfmembers table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMEMBERS . " (\n\t\t\t\t\tuser_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tdisplay_name varchar(100) default NULL,\n\t\t\t\t\tmoderator smallint(1) NOT NULL default '0',\n\t\t\t\t\tavatar longtext default NULL,\n\t\t\t\t\tsignature text default NULL,\n\t\t\t\t\tposts int(4) default NULL,\n\t\t\t\t\tlastvisit datetime default NULL,\n\t\t\t\t\tnewposts longtext,\n\t\t\t\t\tchecktime datetime default NULL,\n\t\t\t\t\tadmin smallint(1) NOT NULL default '0',\n\t\t\t\t\tfeedkey varchar(36) default NULL,\n\t\t\t\t\tadmin_options longtext default NULL,\n\t\t\t\t\tuser_options longtext default NULL,\n\t\t\t\t\tauths longtext default NULL,\n\t\t\t\t\tmemberships longtext default NULL,\n\t\t\t\t\tplugin_data longtext default NULL,\n\t\t\t\t\tPRIMARY KEY\t (user_id),\n\t\t\t\t\tKEY admin_idx (admin),\n\t\t\t\t\tKEY moderator_idx (moderator)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMEMBERS;
            # sfmemberships table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMEMBERSHIPS . " (\n\t\t\t\t\tmembership_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tuser_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (membership_id),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMEMBERSHIPS;
            # sfmeta table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFMETA . " (\n\t\t\t\t\tmeta_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tmeta_type varchar(20) NOT NULL,\n\t\t\t\t\tmeta_key varchar(100) default NULL,\n\t\t\t\t\tmeta_value longtext,\n\t\t\t\t\tautoload tinyint(2) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY (meta_id),\n\t\t\t\t\tKEY meta_type_idx (meta_type),\n\t\t\t\t\tKEY autoload_idx (autoload)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFMETA;
            # user notices table
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFNOTICES . " (\n\t\t\t\t\tnotice_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\tguest_email varchar(75) default NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tlink varchar(255) default NULL,\n\t\t\t\t\tlink_text varchar(200) default NULL,\n\t\t\t\t\tmessage varchar(255) NOT NULL default '',\n\t\t\t\t\texpires int(4) default NULL,\n\t\t\t\t\tPRIMARY KEY (notice_id),\n\t\t\t\t\tKEY user_id_idx (user_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFNOTICES;
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFOPTIONS . " (\n\t\t\t\t\toption_id bigint(20) unsigned NOT NULL auto_increment,\n\t\t\t\t\toption_name varchar(64) NOT NULL default '',\n\t\t\t\t\toption_value longtext NOT NULL,\n\t\t\t\t\tPRIMARY KEY (option_name),\n\t\t\t\t\tKEY option_id_idx (option_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFOPTIONS;
            # sfpermissions table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFPERMISSIONS . " (\n\t\t\t\t\tpermission_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tforum_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tusergroup_id bigint(20) unsigned NOT NULL default '0',\n\t\t\t\t\tpermission_role bigint(20) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (permission_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY usergroup_id_idx (usergroup_id),\n\t\t\t\t\tKEY permission_role_idx (permission_role)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFPERMISSIONS;
            # sfposts table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFPOSTS . " (\n\t\t\t\t\tpost_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tpost_content longtext,\n\t\t\t\t\tpost_date datetime NOT NULL,\n\t\t\t\t\ttopic_id bigint(20) NOT NULL,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tguest_name varchar(50) default NULL,\n\t\t\t\t\tguest_email varchar(75) default NULL,\n\t\t\t\t\tpost_status int(4) NOT NULL default '0',\n\t\t\t\t\tpost_pinned smallint(1) NOT NULL default '0',\n\t\t\t\t\tpost_index mediumint(8) default '0',\n\t\t\t\t\tpost_edit mediumtext,\n\t\t\t\t\tposter_ip varchar(39) NOT NULL default '0.0.0.0',\n\t\t\t\t\tcomment_id bigint(20) default NULL,\n\t\t\t\t\tsource smallint(1) NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (post_id),\n\t\t\t\t\tKEY topic_id_idx (topic_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY guest_name_idx (guest_name),\n\t\t\t\t\tKEY comment_id_idx (comment_id),\n\t\t\t\t\tKEY post_date_idx (post_date)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFPOSTS;
            # sfroles table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFROLES . " (\n\t\t\t\t\trole_id mediumint(8) unsigned NOT NULL auto_increment,\n\t\t\t\t\trole_name varchar(50) NOT NULL default '',\n\t\t\t\t\trole_desc varchar(150) NOT NULL default '',\n\t\t\t\t\trole_auths longtext NOT NULL,\n\t\t\t\t\tPRIMARY KEY\t (role_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFROLES;
            # special ranks (5.3.2)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFSPECIALRANKS . ' (
					id int(11) unsigned NOT NULL AUTO_INCREMENT,
					user_id bigint(20) default NULL,
					special_rank varchar(100),
					PRIMARY KEY (id),
					KEY user_id_idx (user_id),
					KEY special_rank_idx (special_rank)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFSPECIALRANKS;
            # sftopics table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFTOPICS . " (\n\t\t\t\t\ttopic_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\ttopic_name varchar(200) NOT NULL,\n\t\t\t\t\ttopic_date datetime NOT NULL,\n\t\t\t\t\ttopic_status int(4) NOT NULL default '0',\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tuser_id bigint(20) default NULL,\n\t\t\t\t\ttopic_pinned smallint(1) NOT NULL default '0',\n\t\t\t\t\ttopic_opened bigint(20) NOT NULL default '0',\n\t\t\t\t\ttopic_slug varchar(200) NOT NULL,\n\t\t\t\t\tpost_id bigint(20) default NULL,\n\t\t\t\t\tpost_id_held bigint(20) default NULL,\n\t\t\t\t\tpost_count mediumint(8) default '0',\n\t\t\t\t\tpost_count_held mediumint(8) default '0',\n\t\t\t\t\tPRIMARY KEY\t(topic_id),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY topic_slug_idx (topic_slug),\n\t\t\t\t\tKEY user_id_idx (user_id),\n\t\t\t\t\tKEY post_id_idx (post_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFTOPICS;
            # sftrack table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFTRACK . " (\n\t\t\t\t\tid bigint(20) NOT NULL auto_increment,\n\t\t\t\t\ttrackuserid bigint(20) default '0',\n\t\t\t\t\ttrackname varchar(50) NOT NULL,\n\t\t\t\t\ttrackdate datetime NOT NULL,\n\t\t\t\t\tforum_id bigint(20) default NULL,\n\t\t\t\t\ttopic_id bigint(20) default NULL,\n\t\t\t\t\tpageview varchar(50) NOT NULL,\n\t\t\t\t\tnotification varchar(1024) default NULL,\n\t\t\t\t\tdevice char(1) default 'D',\n\t\t\t\t\tdisplay varchar(255) default NULL,\n\t\t\t\t\tPRIMARY KEY\t (id),\n\t\t\t\t\tKEY trackuserid_idx (trackuserid),\n\t\t\t\t\tKEY forum_id_idx (forum_id),\n\t\t\t\t\tKEY topic_id_idx (topic_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFTRACK;
            # user activity (5.3.2 - in preparation)
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFUSERACTIVITY . ' (
					id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
					user_id bigint(20) NOT NULL,
					type_id smallint(4) NOT NULL,
					item_id bigint(20) NOT NULL,
					meta_id bigint(20) DEFAULT NULL,
					PRIMARY KEY (id),
					KEY type_id_idx (type_id),
					KEY user_id_idx (user_id)
				) ' . spdb_charset();
            spdb_query($sql);
            $tables[] = SFUSERACTIVITY;
            # sfusergroups table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFUSERGROUPS . " (\n\t\t\t\t\tusergroup_id bigint(20) NOT NULL auto_increment,\n\t\t\t\t\tusergroup_name text NOT NULL,\n\t\t\t\t\tusergroup_desc text default NULL,\n\t\t\t\t\tusergroup_badge varchar(50) default NULL,\n\t\t\t\t\tusergroup_join tinyint(4) unsigned NOT NULL default '0',\n\t\t\t\t\tusergroup_is_moderator tinyint(4) unsigned NOT NULL default '0',\n\t\t\t\t\tPRIMARY KEY\t (usergroup_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFUSERGROUPS;
            # sfwaiting table def
            $sql = '
				CREATE TABLE IF NOT EXISTS ' . SFWAITING . " (\n\t\t\t\t\ttopic_id bigint(20) NOT NULL,\n\t\t\t\t\tforum_id bigint(20) NOT NULL,\n\t\t\t\t\tpost_count int(4) NOT NULL,\n\t\t\t\t\tpost_id bigint(20) NOT NULL default '0',\n\t\t\t\t\tuser_id bigint(20) unsigned default '0',\n\t\t\t\t\tPRIMARY KEY\t (topic_id)\n\t\t\t\t) " . spdb_charset();
            spdb_query($sql);
            $tables[] = SFWAITING;
            # now save off installed tables
            sp_add_option('installed_tables', $tables);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Tables created') . '</h5>';
            break;
        case 2:
            # populate auths
            spa_setup_auth_cats();
            spa_setup_auths();
            # set up the default permissions/roles
            spa_setup_permissions();
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Permission data built') . '</h5>';
            break;
        case 3:
            # Create default 'Guest' user group data
            $guests = spa_create_usergroup_row('Guests', 'Default Usergroup for guests of the forum', '', '0', '0', false);
            # Create default 'Members' user group data
            $members = spa_create_usergroup_row('Members', 'Default Usergroup for registered users of the forum', '', '0', '0', false);
            # Create default 'Moderators' user group data
            $moderators = spa_create_usergroup_row('Moderators', 'Default Usergroup for moderators of the forum', '', '0', '1', false);
            # Create default user groups
            sp_add_sfmeta('default usergroup', 'sfguests', $guests);
            # default usergroup for guests
            sp_add_sfmeta('default usergroup', 'sfmembers', $members);
            # default usergroup for members
            sp_create_usergroup_meta($members);
            # create default usergroups for existing wp roles
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Usergroup data built') . '</h5>';
            break;
        case 4:
            $page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_author' => $current_user->ID, 'ping_status' => 'closed', 'comment_status' => 'closed', 'post_parent' => 0, 'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'post_content' => '', 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'post_title' => 'Forum', 'page_template' => 'default');
            $page_id = wp_insert_post($page_args);
            $page = spdb_table(SFWPPOSTS, "ID={$page_id}", 'row');
            sp_add_option('sfslug', $page->post_name);
            # Update the guid for the new page
            $guid = get_permalink($page_id);
            spdb_query('UPDATE ' . SFWPPOSTS . " SET guid='{$guid}' WHERE ID={$page_id}");
            sp_add_option('sfpage', $page_id);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Forum page created') . '</h5>';
            break;
        case 5:
            # Create Base Option Records (V1)
            sp_add_option('sfuninstall', false);
            sp_add_option('sfdates', get_option('date_format'));
            sp_add_option('sftimes', get_option('time_format'));
            sp_add_option('sfpermalink', get_permalink(sp_get_option('sfpage')));
            sp_add_option('sflockdown', false);
            $rankdata['posts'] = 2;
            $rankdata['usergroup'] = 'none';
            $rankdata['image'] = 'none';
            sp_add_sfmeta('forum_rank', 'New Member', $rankdata, 1);
            $rankdata['posts'] = 1000;
            $rankdata['usergroup'] = 'none';
            $rankdata['image'] = 'none';
            sp_add_sfmeta('forum_rank', 'Member', $rankdata, 1);
            $sfimage = array();
            $sfimage['enlarge'] = true;
            $sfimage['process'] = true;
            $sfimage['thumbsize'] = 100;
            $sfimage['style'] = 'left';
            $sfimage['constrain'] = true;
            $sfimage['forceclear'] = false;
            sp_add_option('sfimage', $sfimage);
            sp_add_option('sfbadwords', '');
            sp_add_option('sfreplacementwords', '');
            sp_add_option('sfeditormsg', '');
            $sfmail = array();
            $sfmail['sfmailsender'] = get_bloginfo('name');
            $admin_email = get_bloginfo('admin_email');
            $comp = explode('@', $admin_email);
            $sfmail['sfmailfrom'] = $comp[0];
            $sfmail['sfmaildomain'] = $comp[1];
            $sfmail['sfmailuse'] = true;
            sp_add_option('sfmail', $sfmail);
            $sfmail = array();
            $sfmail['sfusespfreg'] = true;
            $sfmail['sfnewusersubject'] = 'Welcome to %BLOGNAME%';
            $sfmail['sfnewusertext'] = 'Welcome %USERNAME% to %BLOGNAME% %NEWLINE%Please find below your login details: %NEWLINE%Username: %USERNAME% %NEWLINE%Password: %PASSWORD% %NEWLINE%%LOGINURL%';
            sp_add_option('sfnewusermail', $sfmail);
            $sfpostmsg = array();
            $sfpostmsg['sfpostmsgtext'] = '';
            $sfpostmsg['sfpostmsgtopic'] = false;
            $sfpostmsg['sfpostmsgpost'] = false;
            sp_add_option('sfpostmsg', $sfpostmsg);
            $sflogin = array();
            $sflogin['sfregmath'] = true;
            $sflogin['sfloginurl'] = sp_url();
            $sflogin['sflogouturl'] = sp_url();
            $sflogin['sfregisterurl'] = '';
            $sflogin['sfloginemailurl'] = esc_url(wp_login_url());
            $sflogin['sptimeout'] = 20;
            sp_add_option('sflogin', $sflogin);
            $sfadminsettings = array();
            $sfadminsettings['sfdashboardstats'] = true;
            $sfadminsettings['sfadminapprove'] = false;
            $sfadminsettings['sfmoderapprove'] = false;
            $sfadminsettings['editnotice'] = true;
            $sfadminsettings['movenotice'] = true;
            sp_add_option('sfadminsettings', $sfadminsettings);
            $sfauto = array();
            $sfauto['sfautoupdate'] = false;
            $sfauto['sfautotime'] = 300;
            sp_add_option('sfauto', $sfauto);
            $sffilters = array();
            $sffilters['sfnofollow'] = false;
            $sffilters['sftarget'] = true;
            $sffilters['sfurlchars'] = 40;
            $sffilters['sffilterpre'] = false;
            $sffilters['sfmaxlinks'] = 0;
            $sffilters['sfnolinksmsg'] = "<b>** you do not have permission to see this link **</b>";
            $sffilters['sfdupemember'] = 0;
            $sffilters['sfdupeguest'] = 0;
            $sffilters['sfmaxsmileys'] = 0;
            sp_add_option('sffilters', $sffilters);
            $sfseo = array();
            $sfseo['sfseo_overwrite'] = false;
            $sfseo['sfseo_blogname'] = false;
            $sfseo['sfseo_pagename'] = false;
            $sfseo['sfseo_homepage'] = true;
            $sfseo['sfseo_topic'] = true;
            $sfseo['sfseo_forum'] = true;
            $sfseo['sfseo_noforum'] = false;
            $sfseo['sfseo_page'] = true;
            $sfseo['sfseo_sep'] = '|';
            sp_add_option('sfseo', $sfseo);
            $sfsigimagesize = array();
            $sfsigimagesize['sfsigwidth'] = 0;
            $sfsigimagesize['sfsigheight'] = 0;
            sp_add_option('sfsigimagesize', $sfsigimagesize);
            # (V4.1.0)
            $sfmembersopt = array();
            $sfmembersopt['sfcheckformember'] = true;
            $sfmembersopt['sfsinglemembership'] = false;
            $sfmembersopt['sfhidestatus'] = true;
            sp_add_option('sfmemberopts', $sfmembersopt);
            $sfcontrols = array();
            $sfcontrols['showtopcount'] = 10;
            $sfcontrols['shownewcount'] = 10;
            $sfcontrols['sfdefunreadposts'] = 50;
            $sfcontrols['sfusersunread'] = false;
            $sfcontrols['sfmaxunreadposts'] = 50;
            sp_add_option('sfcontrols', $sfcontrols);
            $sfblock = array();
            $sfblock['blockadmin'] = false;
            $sfblock['blockprofile'] = false;
            $sfblock['blockroles'] = 'administrator';
            $sfblock['blockredirect'] = get_permalink(sp_get_option('sfpage'));
            sp_add_option('sfblockadmin', $sfblock);
            $sfmetatags = array();
            $sfmetatags['sfdescr'] = '';
            $sfmetatags['sfdescruse'] = 1;
            $sfmetatags['sfusekeywords'] = 2;
            $sfmetatags['sfkeywords'] = 'forum';
            sp_add_option('sfmetatags', $sfmetatags);
            # display array
            $sfdisplay = array();
            $sfdisplay['pagetitle']['notitle'] = false;
            $sfdisplay['pagetitle']['banner'] = '';
            $sfdisplay['forums']['singleforum'] = false;
            $sfdisplay['topics']['perpage'] = 12;
            $sfdisplay['topics']['sortnewtop'] = true;
            $sfdisplay['posts']['perpage'] = 20;
            $sfdisplay['posts']['sortdesc'] = false;
            sp_add_option('sfdisplay', $sfdisplay);
            sp_add_sfmeta('sort_order', 'forum', '', 1);
            sp_add_sfmeta('sort_order', 'topic', '', 1);
            # guest settings
            $sfguests = array();
            $sfguests['reqemail'] = true;
            $sfguests['storecookie'] = true;
            sp_add_option('sfguests', $sfguests);
            # profile management
            $sfprofile = array();
            $sfprofile['nameformat'] = true;
            $sfprofile['fixeddisplayformat'] = 0;
            $sfprofile['namelink'] = 2;
            $sfprofile['displaymode'] = 1;
            $sfprofile['displaypage'] = '';
            $sfprofile['displayquery'] = '';
            $sfprofile['formmode'] = 1;
            $sfprofile['formpage'] = '';
            $sfprofile['formquery'] = '';
            $sfprofile['photosmax'] = 0;
            $sfprofile['photoswidth'] = 0;
            $sfprofile['photosheight'] = 0;
            $sfprofile['firstvisit'] = true;
            $sfprofile['forcepw'] = false;
            sp_add_option('sfprofile', $sfprofile);
            # avatar options
            $sfavatars = array();
            $sfavatars['sfshowavatars'] = true;
            $sfavatars['sfavataruploads'] = true;
            $sfavatars['sfavatarpool'] = false;
            $sfavatars['sfavatarremote'] = false;
            $sfavatars['sfgmaxrating'] = 1;
            $sfavatars['sfavatarsize'] = 50;
            $sfavatars['sfavatarresize'] = true;
            $sfavatars['sfavatarresizequality'] = 90;
            $sfavatars['sfavatarfilesize'] = 10240;
            $sfavatars['sfavatarpriority'] = array(0, 2, 3, 1, 4, 5);
            # gravatar, upload, spf, wp, pool, remote
            sp_add_option('sfavatars', $sfavatars);
            # RSS stuff
            $sfrss = array();
            $sfrss['sfrsscount'] = 15;
            $sfrss['sfrsswords'] = 0;
            $sfrss['sfrsstopicname'] = false;
            $sfrss['sfrssfeedkey'] = true;
            sp_add_option('sfrss', $sfrss);
            sp_add_option('sffiltershortcodes', true);
            sp_add_option('sfwplistpages', true);
            # Script in footer
            sp_add_option('sfscriptfoot', false);
            # the_content filter options
            sp_add_option('sfinloop', false);
            sp_add_option('sfmultiplecontent', true);
            sp_add_option('sfwpheadbypass', false);
            sp_add_option('spwptexturize', false);
            sp_add_option('spheaderspace', 0);
            # auto update stuff in sfmeta
            $autoup = array('spjUserUpdate', 'sp_ahah=autoupdate&amp;sfnonce=' . wp_create_nonce('forum-ahah'));
            sp_add_sfmeta('autoupdate', 'user', $autoup, 1);
            # Set up unique key
            $uKey = substr(chr(rand(97, 122)) . md5(time()), 0, 10);
            sp_add_option('spukey', $uKey);
            # default theme
            $theme = array();
            $theme['theme'] = 'default';
            $theme['style'] = 'default.php';
            $theme['color'] = 'silver';
            sp_add_option('sp_current_theme', $theme);
            $theme = array();
            $theme['active'] = false;
            $theme['theme'] = 'default';
            $theme['style'] = 'default.php';
            $theme['color'] = 'silver';
            $theme['usetemplate'] = false;
            $theme['pagetemplate'] = '';
            $theme['notitle'] = true;
            sp_add_option('sp_mobile_theme', $theme);
            sp_add_option('sp_tablet_theme', $theme);
            sp_add_option('account-name', '');
            sp_add_option('display-name', '');
            sp_add_option('guest-name', '');
            # Create smileys Record
            sp_build_base_smileys();
            # set up daily transient clean up cron
            wp_schedule_event(time(), 'daily', 'sph_transient_cleanup_cron');
            # profile tabs
            spa_new_profile_setup();
            # build the list of moderators per forum
            sp_update_forum_moderators();
            # set up hourly stats generation
            sp_add_option('sp_stats_interval', 3600);
            wp_schedule_event(time(), 'hourly', 'sph_stats_cron');
            # set up weekly news processing
            wp_schedule_event(time(), 'sp_news_interval', 'sph_news_cron');
            sp_add_sfmeta('news', 'news', array('id' => -999.999, 'show' => 0, 'news' => esc_sql(spa_text('Latest Simple Press News will be shown here'))));
            # create initial last post time stamp
            sp_add_option('poststamp', current_time('mysql'));
            # setup mysql search sfmeta values (5.2.0)
            $s = array();
            $v = spdb_select('row', "SHOW VARIABLES LIKE 'ft_min_word_len'");
            empty($v->Value) ? $s['min'] = 4 : ($s['min'] = $v->Value);
            $v = spdb_select('row', "SHOW VARIABLES LIKE 'ft_max_word_len'");
            empty($v->Value) ? $s['max'] = 84 : ($s['max'] = $v->Value);
            sp_add_sfmeta('mysql', 'search', $s, true);
            # combined css and js cache fles
            sp_add_option('combinecss', false);
            sp_add_option('combinejs', false);
            sp_add_option('post_count_delete', false);
            $spError = array();
            $spError['spErrorLogOff'] = false;
            $spError['spNoticesOff'] = false;
            sp_update_option('spErrorOptions', $spError);
            # new posts/topic cached array
            sp_add_sfmeta('topic_cache', 'new', '', true);
            sp_add_option('topic_cache', 200);
            sp_add_option('floodcontrol', 10);
            sp_add_option('captcha-value', time());
            sp_add_option('editpostdays', 7);
            sp_create_inspectors();
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Default forum options created') . '</h5>';
            break;
        case 6:
            # Create sp-resources folder for the current install - does not include themes, plugins or languages
            $perms = fileperms(SF_STORE_DIR);
            $owners = stat(SF_STORE_DIR);
            if ($perms === false) {
                $perms = 0755;
            }
            $basepath = '';
            if (is_multisite()) {
                # construct multisite storage directory structure and create if necessary
                $basepath .= 'blogs.dir/' . SFBLOGID;
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                $basepath .= '/files';
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                $basepath .= '/';
            }
            $basepath .= 'sp-resources';
            if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
            }
            # hive off the basepath for later use - use wp options
            add_option('sp_storage1', SF_STORE_DIR . '/' . $basepath);
            # Did it get created?
            $success = true;
            if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                $success = false;
            }
            sp_add_option('spStorageInstall1', $success);
            # Is the ownership correct?
            $ownersgood = false;
            if ($success) {
                $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                    $ownersgood = true;
                } else {
                    @chown(SF_STORE_DIR . '/' . $basepath, $owners['uid']);
                    @chgrp(SF_STORE_DIR . '/' . $basepath, $owners['gid']);
                    $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                    if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                        $ownersgood = true;
                    }
                }
            }
            sp_add_option('spOwnersInstall1', $ownersgood);
            $basepath .= '/';
            $sfconfig = array();
            $sfconfig['avatars'] = $basepath . 'forum-avatars';
            $sfconfig['avatar-pool'] = $basepath . 'forum-avatar-pool';
            $sfconfig['smileys'] = $basepath . 'forum-smileys';
            $sfconfig['ranks'] = $basepath . 'forum-badges';
            $sfconfig['custom-icons'] = $basepath . 'forum-custom-icons';
            $sfconfig['cache'] = $basepath . 'forum-cache';
            # Create sp-resources folder and themes, plugins and languages folders
            # if not multisite, just add to sp-resource created above
            # if multisite try to use set up of main blog (id 1) or create in wp-content if main blog does not have SP installed
            global $wpdb;
            if (is_multisite()) {
                $basepath = 'sp-resources';
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    @mkdir(SF_STORE_DIR . '/' . $basepath, $perms);
                }
                # Did it get created?
                $success = true;
                if (!file_exists(SF_STORE_DIR . '/' . $basepath)) {
                    $success = false;
                }
                sp_add_option('spStorageInstall2', $success);
                # Is the ownership correct?
                $ownersgood = false;
                if ($success) {
                    $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                    if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                        $ownersgood = true;
                    } else {
                        @chown(SF_STORE_DIR . '/' . $basepath, $owners['uid']);
                        @chgrp(SF_STORE_DIR . '/' . $basepath, $owners['gid']);
                        $newowners = stat(SF_STORE_DIR . '/' . $basepath);
                        if ($newowners['uid'] == $owners['uid'] && $newowners['gid'] == $owners['gid']) {
                            $ownersgood = true;
                        }
                    }
                }
                sp_add_option('spOwnersInstall2', $ownersgood);
                add_option('sp_storage2', SF_STORE_DIR . '/' . $basepath);
                $basepath .= '/';
                if ($wpdb->blogid == 1) {
                    $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                    $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                    $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                    $sfconfig['plugins'] = $basepath . 'forum-plugins';
                    $sfconfig['themes'] = $basepath . 'forum-themes';
                } else {
                    $blog_prefix = $wpdb->get_blog_prefix(1);
                    $row = $wpdb->get_row("SELECT * FROM {$blog_prefix}sfoptions WHERE option_name 'sfconfig'");
                    if (is_object($row)) {
                        $mainConfig = unserialize($row->option_value);
                        $sfconfig['language-sp'] = $mainConfig['language-sp'];
                        $sfconfig['language-sp-plugins'] = $mainConfig['language-sp-plugins'];
                        $sfconfig['language-sp-themes'] = $mainConfig['language-sp-themes'];
                        $sfconfig['plugins'] = $mainConfig['plugins'];
                        $sfconfig['themes'] = $mainConfig['themes'];
                    } else {
                        $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                        $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                        $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                        $sfconfig['plugins'] = $basepath . 'forum-plugins';
                        $sfconfig['themes'] = $basepath . 'forum-themes';
                    }
                }
            } else {
                add_option('sp_storage2', get_option('sp_storage1'));
                sp_add_option('spStorageInstall2', true);
                sp_add_option('spOwnersInstall2', true);
                $sfconfig['language-sp'] = $basepath . 'forum-language/simple-press';
                $sfconfig['language-sp-plugins'] = $basepath . 'forum-language/sp-plugins';
                $sfconfig['language-sp-themes'] = $basepath . 'forum-language/sp-themes';
                $sfconfig['plugins'] = $basepath . 'forum-plugins';
                $sfconfig['themes'] = $basepath . 'forum-themes';
            }
            sp_add_option('sfconfig', $sfconfig);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            if ($success) {
                spa_etext('Storage location created') . '</h5>';
            } else {
                spa_etext('Storage location creation failed') . '</h5>';
            }
            break;
        case 7:
            # Move and extract zip install archives
            # first do stuff that could be in blogs.dir for multisite
            $successCopy1 = false;
            $successExtract1 = false;
            $zipfile = SF_PLUGIN_DIR . '/sp-startup/install/sp-resources-install-part1.zip';
            $extract_to = get_option('sp_storage1');
            # Copy the zip file
            if (@copy($zipfile, $extract_to . '/sp-resources-install-part1.zip')) {
                $successCopy1 = true;
                # Now try and unzip it
                require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
                $zipfile = $extract_to . '/sp-resources-install-part1.zip';
                $zipfile = str_replace('\\', '/', $zipfile);
                # sanitize for Win32 installs
                $zipfile = preg_replace('|/+|', '/', $zipfile);
                # remove any duplicate slash
                $extract_to = str_replace('\\', '/', $extract_to);
                # sanitize for Win32 installs
                $extract_to = preg_replace('|/+|', '/', $extract_to);
                # remove any duplicate slash
                $archive = new PclZip($zipfile);
                $archive->extract($extract_to);
                if ($archive->error_code == 0) {
                    $successExtract1 = true;
                    # Lets try and remove the zip as it seems to have worked
                    @unlink($zipfile);
                }
            }
            sp_add_option('spCopyZip1', $successCopy1);
            sp_add_option('spUnZip1', $successExtract1);
            # now do stuff that could should not be blogs.dir for multisite
            $successCopy2 = false;
            $successExtract2 = false;
            $zipfile = SF_PLUGIN_DIR . '/sp-startup/install/sp-resources-install-part2.zip';
            $extract_to = get_option('sp_storage2');
            # Copy the zip file
            if (@copy($zipfile, $extract_to . '/sp-resources-install-part2.zip')) {
                $successCopy2 = true;
                # Now try and unzip it
                require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
                $zipfile = $extract_to . '/sp-resources-install-part2.zip';
                $zipfile = str_replace('\\', '/', $zipfile);
                # sanitize for Win32 installs
                $zipfile = preg_replace('|/+|', '/', $zipfile);
                # remove any duplicate slash
                $extract_to = str_replace('\\', '/', $extract_to);
                # sanitize for Win32 installs
                $extract_to = preg_replace('|/+|', '/', $extract_to);
                # remove any duplicate slash
                $archive = new PclZip($zipfile);
                $archive->extract($extract_to);
                if ($archive->error_code == 0) {
                    $successExtract2 = true;
                    # Lets try and remove the zip as it seems to have worked
                    @unlink($zipfile);
                }
            }
            sp_add_option('spCopyZip2', $successCopy2);
            sp_add_option('spUnZip2', $successExtract2);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            if ($successCopy1 && $successExtract1 && $successCopy2 && $successExtract2) {
                spa_etext('Resources created') . '</h5>';
            } elseif (!$successCopy1 || !$successCopy2) {
                spa_etext('Resources file failed to copy') . '</h5>';
            } elseif (!$successExtract1 || !$successExtract2) {
                spa_etext('Resources file failed to unzip');
                echo ' - ' . $archive->error_string . '</h5>';
            }
            break;
        case 8:
            # CREATE MEMBERS TABLE ---------------------------
            sp_install_members_table($subphase);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            echo spa_text('Members data created for existing users') . ' ' . (($subphase - 1) * 200 + 1) . ' - ' . $subphase * 200 . '</h5>';
            break;
        case 9:
            # add our caps
            sp_add_caps();
            # grant spf capabilities to installer
            $user = new WP_User($current_user->ID);
            $user->add_cap('SPF Manage Options');
            $user->add_cap('SPF Manage Forums');
            $user->add_cap('SPF Manage User Groups');
            $user->add_cap('SPF Manage Permissions');
            $user->add_cap('SPF Manage Components');
            $user->add_cap('SPF Manage Admins');
            $user->add_cap('SPF Manage Users');
            $user->add_cap('SPF Manage Profiles');
            $user->add_cap('SPF Manage Toolbox');
            $user->add_cap('SPF Manage Plugins');
            $user->add_cap('SPF Manage Themes');
            $user->add_cap('SPF Manage Integration');
            sp_update_member_item($current_user->ID, 'admin', 1);
            # admin your option defaults
            $sfadminoptions = array();
            $sfadminoptions['sfnotify'] = false;
            $sfadminoptions['notify-edited'] = true;
            sp_update_member_item($current_user->ID, 'admin_options', $sfadminoptions);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Admin permission data built') . '</h5>';
            break;
        case 10:
            # UPDATE VERSION/BUILD NUMBERS -------------------------
            sp_log_event(SPRELEASE, SPVERSION, SPBUILD);
            # Lets update permalink and force a rewrite rules flush
            sp_update_permalink(true);
            echo '<h5>' . spa_text('Phase') . ' - ' . $phase . ' - ';
            spa_etext('Version number updated') . '</h5>';
            break;
        case 11:
            # REPORTS ERRORS IF COPY OR UNZIP FAILED ---------------
            $sCreate1 = sp_get_option('spStorageInstall1');
            $sCreate2 = sp_get_option('spStorageInstall2');
            $sOwners1 = sp_get_option('spOwnersInstall1');
            $sOwners2 = sp_get_option('spOwnersInstall2');
            $sCopy1 = sp_get_option('spCopyZip1');
            $sUnzip1 = sp_get_option('spUnZip1');
            $sCopy2 = sp_get_option('spCopyZip2');
            $sUnzip2 = sp_get_option('spUnZip2');
            if ($sCreate1 && $sCreate2 && $sCopy1 && $sUnzip1 && $sCopy2 && $sUnzip2 && $sOwners1 && $sOwners2) {
                echo '<h5>' . spa_text('The installation has been completed') . '</h5>';
            } else {
                $image = "<img src='" . SF_PLUGIN_URL . "/sp-startup/install/resources/images/important.png' alt='' style='float:left;padding: 5px 5px 20px 0;' />";
                echo '<h5>';
                spa_etext('YOU WILL NEED TO PERFORM THE FOLLOWING TASKS TO ALLOW SIMPLE:PRESS TO WORK CORRECTLY');
                echo '</h5><br />';
                if (!$sCreate1) {
                    echo $image . '<p style="margin-top:0">[';
                    spa_etext('Storage location part 1 creation failed');
                    echo '] - ';
                    echo spa_text('You will need to manually create a required a folder named') . ': ' . get_option('sp_storage1');
                    echo '</p>';
                } else {
                    if (!$sOwners1) {
                        echo $image . '<p>[';
                        spa_etext('Storage location part 1 ownership failed');
                        echo '] - ';
                        echo spa_text('We were unable to create your folders with the correct server ownership and these will need to be manually changed') . ': ' . get_option('sp_storage1');
                        echo '</p>';
                    }
                }
                if (!$sCreate2) {
                    echo $image . '<p>[';
                    spa_etext('Storage location part 2 creation failed');
                    echo '] - ';
                    echo spa_text('You will need to manually create a required a folder named') . ': ' . get_option('sp_storage2');
                    echo '</p>';
                } elseif (!$sOwners2) {
                    echo $image . '<p>[';
                    spa_etext('Storage location part 2 ownership failed');
                    echo '] - ';
                    echo spa_text('We were unable to create your folders with the correct server ownership and these will need to be manually changed') . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
                if (!$sCopy1) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 1 file failed to copy');
                    echo '] - ';
                    echo spa_text("You will need to manually copy and extract the file '/simple-press/sp-startup/install/sp-resources-install-part1.zip' to the new folder") . ': ' . get_option('sp_storage1');
                    echo '</p>';
                }
                if (!$sCopy2) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to copy');
                    echo '] - ';
                    echo spa_text("You will need to manually copy and extract the file '/simple-press/sp-startup/install/sp-resources-install-part2.zip' to the new folder") . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
                if (!$sUnzip1) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to unzip');
                    echo '] - ';
                    echo spa_text("You will need to manually unzip the file 'sp-resources-install-part1.zip' in the new folder") . ': ' . get_option('sp_storage1');
                    echo '</p>';
                }
                if (!$sUnzip2) {
                    echo $image . '<p>[';
                    spa_etext('Resources part 2 file failed to unzip');
                    echo '] - ';
                    echo spa_text("You will need to manually unzip the file 'sp-resources-install-part2.zip' in the new folder") . ': ' . get_option('sp_storage2');
                    echo '</p>';
                }
            }
            delete_option('sfInstallID');
            delete_option('sp_storage1');
            delete_option('sp_storage2');
            sp_delete_option('spStorageInstall1');
            sp_delete_option('spStorageInstall2');
            sp_delete_option('spOwnersInstall1');
            sp_delete_option('spOwnersInstall2');
            sp_delete_option('spCopyZip1');
            sp_delete_option('spCopyZip2');
            sp_delete_option('spUnZip1');
            sp_delete_option('spUnZip2');
            break;
    }
}
 function insert()
 {
     if (empty($this->table) || empty($this->fields) || empty($this->data) || !is_array($this->data) || !is_array($this->fields)) {
         return false;
     }
     $table = $this->table;
     $values = array();
     foreach ($this->data as $val) {
         # check if special @ - means numbers stored as string
         if (substr($val, 0, 1) == '@') {
             $val = "'" . substr($val, 1) . "'";
         } elseif (!is_numeric($val)) {
             $val = "'" . $val . "'";
         }
         $values[] = $val;
     }
     $sql = "INSERT INTO {$table} (" . implode(', ', $this->fields) . ') VALUES (' . implode(', ', $values) . ')';
     if ($this->show) {
         spdb_show_result($sql, $this->inspect);
     }
     $result = spdb_query($sql);
     return $result;
 }
function sp_render_queued_notification()
{
    global $spStatus, $spThisUser, $spIsForumAdmin;
    if (isset($spThisUser) && $spStatus == 'ok' && $spIsForumAdmin == false) {
        if (!empty($spThisUser->notification)) {
            $notification = $spThisUser->notification;
        } else {
            $notification = spdb_table(SFTRACK, 'id=' . $spThisUser->trackid, 'notification');
        }
        if ($notification) {
            # Remove it from sftrack
            spdb_query('UPDATE ' . SFTRACK . " SET notification='' WHERE id={$spThisUser->trackid}");
            # And pass it through to the js for display
            $notification = unserialize($notification);
            apply_filters('sph_queued_notification', $notification[1]);
            do_action('sph_message', $notification[0], esc_js($notification[1]));
        }
    }
}
Beispiel #23
0
function sp_tidy_install_log()
{
    $log = spdb_table(SFLOG, '', '', 'id DESC');
    $ver = 0;
    if ($log) {
        foreach ($log as $l) {
            if ($l->version != $ver) {
                $ver = $l->version;
            } else {
                spdb_query('DELETE FROM ' . SFLOG . ' WHERE id=' . $l->id);
            }
        }
    }
}
 function saveData()
 {
     global $spVars, $spGlobals;
     $this->abort = false;
     $this->newpost['action'] = $this->action;
     # make the entire class object available for modification before saving
     # warning:  note the passing by reference.  other end could wreak havoc
     do_action_ref_array('sph_new_post_pre_save', array(&$this));
     # Write the topic if needed
     if ($this->action == 'topic') {
         $this->newpost = apply_filters('sph_new_topic_pre_data_saved', $this->newpost);
         $spdb = new spdbComplex();
         $spdb->table = SFTOPICS;
         $spdb->fields = array('topic_name', 'topic_slug', 'topic_date', 'forum_id', 'topic_status', 'topic_pinned', 'user_id');
         $spdb->data = array($this->newpost['topicname'], $this->newpost['topicslug'], $this->newpost['postdate'], $this->newpost['forumid'], $this->newpost['topicstatus'], $this->newpost['topicpinned'], $this->newpost['userid']);
         $spdb = apply_filters('sph_new_topic_data', $spdb);
         $this->newpost['db'] = $spdb->insert();
         if ($this->newpost['db'] == true) {
             $this->newpost['topicid'] = $spVars['insertid'];
             $this->newpost = apply_filters('sph_new_topic_data_saved', $this->newpost);
         } else {
             $this->abort = true;
             $this->message = sp_text('Unable to save new topic record');
             return;
         }
         # failsafe: check the topic slug and if empty use the topic id
         if (empty($this->newpost['topicslug'])) {
             $this->newpost['topicslug'] = 'topic-' . $this->newpost['topicid'];
             spdb_query('UPDATE ' . SFTOPICS . " SET topic_slug='" . $this->newpost['topicslug'] . "' WHERE topic_id=" . $this->newpost['topicid']);
         }
     }
     # Write the post
     # Double check forum id is correct - it has been known for a topic to have just been moved!
     $this->newpost['forumid'] = spdb_table(SFTOPICS, 'topic_id=' . $this->newpost['topicid'], 'forum_id');
     # Get post count in topic to enable post index setting
     $index = spdb_count(SFPOSTS, 'topic_id = ' . $this->newpost['topicid']);
     $index++;
     $this->newpost['postindex'] = $index;
     # if topic lock set in post reply update topic (post only)
     if ($this->action == 'post' && $this->newpost['topicstatus']) {
         spdb_query('UPDATE ' . SFTOPICS . ' SET topic_status=1 WHERE topic_id=' . $this->newpost['topicid']);
     }
     $this->newpost = apply_filters('sph_new_post_pre_data_saved', $this->newpost);
     $spdb = new spdbComplex();
     $spdb->table = SFPOSTS;
     $spdb->fields = array('post_content', 'post_date', 'topic_id', 'forum_id', 'user_id', 'guest_name', 'guest_email', 'post_pinned', 'post_index', 'post_status', 'poster_ip', 'source');
     $spdb->data = array($this->newpost['postcontent'], $this->newpost['postdate'], $this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['userid'], $this->newpost['guestname'], $this->newpost['guestemail'], $this->newpost['postpinned'], $this->newpost['postindex'], $this->newpost['poststatus'], $this->newpost['posterip'], $this->newpost['source']);
     $spdb = apply_filters('sph_new_post_data', $spdb);
     $this->newpost['db'] = $spdb->insert();
     if ($this->newpost['db'] == true) {
         $this->newpost['postid'] = $spVars['insertid'];
         $this->newpost = apply_filters('sph_new_post_data_saved', $this->newpost);
     } else {
         $this->abort = true;
         $this->message = sp_text('Unable to save new post message');
         return;
     }
     # Update the timestamp of the last post
     sp_update_option('poststamp', $this->newpost['postdate']);
     $this->returnURL = sp_build_url($this->newpost['forumslug'], $this->newpost['topicslug'], 0, $this->newpost['postid']);
     if ($this->newpost['poststatus']) {
         $this->newpost['submsg'] .= ' - ' . sp_text('placed in moderation') . ' ';
     }
     # Now for all that post-save processing required
     if ($this->guest) {
         $sfguests = sp_get_option('sfguests');
         if ($sfguests['storecookie']) {
             sp_write_guest_cookie($this->newpost['guestname'], $this->newpost['guestemail']);
         }
     } else {
         $postcount = sp_get_member_item($this->newpost['userid'], 'posts');
         $postcount++;
         sp_update_member_item($this->newpost['userid'], 'posts', $postcount);
         # see if postcount qualifies member for new user group membership
         # get rankings information
         if (!$this->admin) {
             # ignore for admins as they dont belong to user groups
             global $spGlobals;
             if (!empty($spGlobals['forum_rank'])) {
                 $index = 0;
                 foreach ($spGlobals['forum_rank'] as $x => $info) {
                     $rankdata['title'][$index] = $x;
                     $rankdata['posts'][$index] = $info['posts'];
                     $rankdata['usergroup'][$index] = $info['usergroup'];
                     $index++;
                 }
                 # sort rankings
                 array_multisort($rankdata['posts'], SORT_ASC, $rankdata['title'], $rankdata['usergroup']);
                 # check for new ranking
                 for ($x = 0; $x < count($rankdata['posts']); $x++) {
                     if ($postcount <= $rankdata['posts'][$x] && !empty($rankdata['usergroup'][$x])) {
                         # if a user group is tied to forum rank add member to the user group
                         if ($rankdata['usergroup'][$x] != 'none') {
                             sp_add_membership($rankdata['usergroup'][$x], $this->newpost['userid']);
                         }
                         break;
                         # only update highest rank
                     }
                 }
             }
         }
     }
     # set new url for email
     $this->newpost['url'] = $this->returnURL;
     # allow plugins to add to post message
     $this->newpost['submsg'] = apply_filters('sph_post_message', $this->newpost['submsg'], $this->newpost);
     # add to or remove from admins new post queue
     if ($this->admin || $this->moderator) {
         # remove topic from waiting...
         sp_remove_from_waiting(false, $this->newpost['topicid']);
     } else {
         # add topic to waiting
         sp_add_to_waiting($this->newpost['topicid'], $this->newpost['forumid'], $this->newpost['postid'], $this->newpost['userid']);
     }
     # if a new post remove topic from the users new post list if in it
     if ($this->action == 'post') {
         sp_remove_users_newposts($this->newpost['topicid'], $this->newpost['userid']);
     }
     # do we need to approve any posts in moderation in this topic?
     if ($this->admin && $spGlobals['admin']['sfadminapprove'] || $this->moderator && $spGlobals['admin']['sfmoderapprove']) {
         sp_approve_post(true, 0, $this->newpost['topicid'], false, $this->newpost['forumid']);
     }
     # if post in moderatiuon then add entry to notices
     if ($this->newpost['poststatus'] != 0) {
         $nData = array();
         $nData['user_id'] = $this->newpost['userid'];
         $nData['guest_email'] = $this->newpost['guestemail'];
         $nData['post_id'] = $this->newpost['postid'];
         $nData['link'] = $this->newpost['url'];
         $nData['link_text'] = $this->newpost['topicname'];
         $nData['message'] = sp_text('Your post is awaiting moderation in the topic');
         $nData['expires'] = time() + 30 * 24 * 60 * 60;
         # 30 days; 24 hours; 60 mins; 60secs
         sp_add_notice($nData);
     }
     # Add this new item to the new tpic/post cache
     $meta = sp_get_sfmeta_key('topic_cache', 'new');
     $cacheSize = sp_get_option('topic_cache');
     $a = array();
     $a[LISTFORUM] = (int) $this->newpost['forumid'];
     $a[LISTTOPIC] = (int) $this->newpost['topicid'];
     $a[LISTPOST] = (int) $this->newpost['postid'];
     $a[LISTSTATUS] = (int) $this->newpost['poststatus'];
     if (isset($spGlobals['topic_cache']['new']) && !empty($spGlobals['topic_cache']['new'])) {
         array_unshift($spGlobals['topic_cache']['new'], $a);
         if (count($spGlobals['topic_cache']['new']) > $cacheSize) {
             array_pop($spGlobals['topic_cache']['new']);
         }
     }
     sp_update_sfmeta('topic_cache', 'new', $spGlobals['topic_cache']['new'], $meta, true);
     # remove group level caches to accommodate new post
     spdb_query('DELETE FROM ' . SFCACHE . " WHERE cache_id LIKE '%*group'");
     # save post in cache for flood control
     sp_add_cache('floodcontrol', time() + sp_get_option('floodcontrol'));
     # Update forum, topic and post index data
     sp_build_post_index($this->newpost['topicid']);
     sp_build_forum_index($this->newpost['forumid']);
     # send out email notifications
     sp_email_notifications($this->newpost);
     # one final filter - just in case
     do_action_ref_array('sph_post_new_completed', array(&$this));
     # and a final action hook
     do_action('sph_new_post', $this->newpost);
     do_action('sph_post_create', $this->newpost);
 }
function spa_check_warnings()
{
    global $spGlobals;
    # not perfect but we can use this call tyo perform any minor
    # cleanups that may be necessary... so
    # drop any existing temp members table...
    spdb_query('DROP TABLE IF EXISTS sftempmembers');
    $mess = '';
    # check if sp core, plugins or themes update available
    $update = false;
    $update_msg = '';
    $up = get_site_transient('update_plugins');
    if (!empty($up->response)) {
        foreach ($up->response as $plugin) {
            if ($plugin->slug == 'simple-press') {
                $msg = apply_filters('sph_core_update_notice', spa_text('There is a Simple:Press core update available.'));
                if (!empty($msg)) {
                    $update = true;
                    $update_msg .= $msg . '<br />';
                }
                break;
            }
        }
    }
    $up = get_site_transient('sp_update_plugins');
    if (!empty($up)) {
        $msg = apply_filters('sph_plugins_update_notice', spa_text('There is one or more Simple:Press plugin updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    $up = get_site_transient('sp_update_themes');
    if (!empty($up)) {
        $msg = apply_filters('sph_themes_update_notice', spa_text('There is one or more Simple:Press theme updates available'));
        if (!empty($msg)) {
            $update = true;
            $update_msg .= $msg . '<br />';
        }
    }
    if ($update) {
        if (is_main_site()) {
            $mess .= apply_filters('sph_updates_notice', spa_message($update_msg . '<a href="' . self_admin_url('update-core.php') . '">' . spa_text('Click here to view any updates.') . '</a>'));
        } else {
            $mess .= apply_filters('sph_updates_notice', spa_message(spa_text('There are some Simple:Press updates avaialable. You may want to notify the network site admin.')));
        }
    }
    # output warning if no SPF admins are defined
    $a = $spGlobals['forum-admins'];
    if (empty($a)) {
        $mess .= spa_message(spa_text('Warning - There are no SPF admins defined!	 All WP admins now have SP backend access'), 'error');
    }
    # Check if	desktop, tablet and mobile themes are selected and available
    $cur = sp_get_option('sp_current_theme');
    if (empty($cur)) {
        $mess .= spa_message(spa_text('No main theme has been selected and SP will be unable to display correctly. Please select a theme from the Themes panel'), 'error');
    } else {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/' . $cur['style']);
        $nooverlay = !empty($cur['color']) && !file_exists(SPTHEMEBASEDIR . $cur['theme'] . '/styles/overlays/' . $cur['color'] . '.php');
        $nopoverlay = !empty($cur['color']) && !empty($cur['parent']) && !file_exists(SPTHEMEBASEDIR . $cur['parent'] . '/styles/overlays/' . $cur['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the theme CSS file and/or color Overlay file from the selected theme is missing'), 'error');
        }
    }
    $mobile = sp_get_option('sp_mobile_theme');
    if (!empty($mobile) && $mobile['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/' . $mobile['style']);
        $nooverlay = !empty($mobile['color']) && !file_exists(SPTHEMEBASEDIR . $mobile['theme'] . '/styles/overlays/' . $mobile['color'] . '.php');
        $nopoverlay = !empty($mobile['color']) && !empty($mobile['parent']) && !file_exists(SPTHEMEBASEDIR . $mobile['parent'] . '/styles/overlays/' . $mobile['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the mobile theme CSS file and/or color Overlay file from the selected mobile theme is missing'), 'error');
        }
    }
    $tablet = sp_get_option('sp_tablet_theme');
    if (!empty($tablet) && $tablet['active']) {
        $nostylesheet = !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/' . $tablet['style']);
        $nooverlay = !empty($tablet['color']) && !file_exists(SPTHEMEBASEDIR . $tablet['theme'] . '/styles/overlays/' . $tablet['color'] . '.php');
        $nopoverlay = !empty($tablet['color']) && !empty($tablet['parent']) && !file_exists(SPTHEMEBASEDIR . $tablet['parent'] . '/styles/overlays/' . $tablet['color'] . '.php');
        if ($nostylesheet || $nooverlay && $nopoverlay) {
            $mess .= spa_message(spa_text('Either the tablet theme CSS file and/or color Overlay file from the selected tablet theme is missing'), 'error');
        }
    }
    # check for missing default members user group
    $value = sp_get_sfmeta('default usergroup', 'sfmembers');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for new members is undefined!	Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for missing default guest user group
    $value = sp_get_sfmeta('default usergroup', 'sfguests');
    $ugid = spdb_table(SFUSERGROUPS, "usergroup_id={$value[0]['meta_value']}", 'usergroup_id');
    if (empty($ugid)) {
        $mess .= spa_message(spa_text('Warning - The default user group for guests is undefined!  Please visit the SP usergroups admin page, map users to usergroups tab and set the default user group'), 'error');
    }
    # check for unreachable forums because of permissions
    $done = 0;
    $usergroups = spdb_table(SFUSERGROUPS);
    if ($usergroups) {
        $has_members = false;
        foreach ($usergroups as $usergroup) {
            $members = spdb_table(SFMEMBERSHIPS, "usergroup_id={$usergroup->usergroup_id}", 'row', '', '1');
            if ($members || $usergroup->usergroup_id == $value[0]['meta_value']) {
                $has_members = true;
                break;
            }
        }
        if (!$has_members) {
            $mess .= spa_message(spa_text('Warning - There are no usergroups that have members!	All forums may only be visible to SP admins'), 'error');
            $done = 1;
        }
    } else {
        $mess .= spa_message(spa_text('Warning - There are no usergroups defined!  All forums may only be visible to SP admins'), 'error');
        $done = 1;
    }
    $roles = sp_get_all_roles();
    if (!$roles) {
        $mess .= spa_message(spa_text('Warning - There are no permission sets defined!  All forums may only be visible to SP admins'), 'error');
        $done = 1;
    }
    # check if compatible with wp super cache
    if (function_exists('wp_cache_edit_rejected')) {
        global $cache_rejected_uri;
        $slug = '/' . sp_get_option('sfslug') . '/';
        if (isset($cache_rejected_uri)) {
            $found = false;
            foreach ($cache_rejected_uri as $value) {
                if ($value == $slug) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                $string = spa_text('WP Super Cache is not properly configured to work with Simple:Press. Please visit your WP Super Cache settings page and in the accepted filenames & rejected URIs section for the pages not to be cached input field, add the following string');
                $string .= ':<br /><br />' . $slug . '<br /><br />';
                $string .= spa_text('Then, please clear your WP Super Cache cache to remove any cached Simple:Press pages');
                $mess .= spa_message($string, 'error');
            }
        }
    }
    if ($mess != '') {
        return $mess;
    }
}
function spa_prepare_msbox_list($msbox, $uid)
{
    # drop any existing temp table tp start afresh
    spdb_query('DROP TABLE IF EXISTS sftempmembers');
    switch ($msbox) {
        case 'usergroup_add':
            $records = spdb_query('CREATE TABLE sftempmembers AS
				SELECT DISTINCT ' . SFMEMBERS . '.user_id, ' . SFMEMBERS . '.display_name
				FROM ' . SFMEMBERSHIPS . '
				RIGHT JOIN ' . SFMEMBERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFMEMBERSHIPS . '.user_id
				WHERE (usergroup_id != ' . $uid . ' AND admin = 0) OR (' . SFMEMBERSHIPS . '.user_id IS NULL AND admin = 0)
				ORDER BY display_name');
            break;
        case 'usergroup_del':
            $records = spdb_query('CREATE TABLE sftempmembers AS
				SELECT DISTINCT ' . SFMEMBERS . '.user_id, ' . SFMEMBERS . '.display_name
				FROM ' . SFMEMBERSHIPS . '
				JOIN ' . SFMEMBERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFMEMBERSHIPS . '.user_id
				WHERE ' . SFMEMBERSHIPS . '.usergroup_id=' . $uid . '
				ORDER BY display_name');
            break;
        case 'rank_add':
            $specialRank = sp_get_sfmeta('special_rank', false, $uid);
            $rank = $specialRank[0]['meta_key'];
            $records = spdb_query('CREATE TABLE sftempmembers AS
				SELECT DISTINCT ' . SFMEMBERS . '.user_id, ' . SFMEMBERS . '.display_name
				FROM ' . SFSPECIALRANKS . '
				RIGHT JOIN ' . SFMEMBERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFSPECIALRANKS . '.user_id
				WHERE (special_rank != "' . $rank . '") OR (' . SFSPECIALRANKS . '.user_id IS NULL)
				ORDER BY display_name');
            break;
        case 'rank_del':
            $specialRank = sp_get_sfmeta('special_rank', false, $uid);
            $rank = $specialRank[0]['meta_key'];
            $records = spdb_query('CREATE TABLE sftempmembers AS
				SELECT DISTINCT ' . SFMEMBERS . '.user_id, ' . SFMEMBERS . '.display_name
				FROM ' . SFSPECIALRANKS . '
				RIGHT JOIN ' . SFMEMBERS . ' ON ' . SFMEMBERS . '.user_id = ' . SFSPECIALRANKS . '.user_id
				WHERE (special_rank = "' . $rank . '")
				ORDER BY display_name');
            break;
        case 'admin_add':
            $records = spdb_query('CREATE TABLE sftempmembers AS
				SELECT ' . SFMEMBERS . '.user_id, display_name
				FROM ' . SFMEMBERS . '
				WHERE admin=0
				ORDER BY display_name');
            break;
    }
}
function sp_delete_auth_cat($id_or_name)
{
    # if its not id, lets get the id for easy removal of auth cat from auths
    if (!is_numeric($id_or_name)) {
        $slug = sp_create_slug($id_or_name, true, SFAUTHCATS, 'authcat_slug');
        $id_or_name = spdb_table(SFAUTHCATS, 'authcat_slug="' . $slug . '"', 'authcat_id');
    }
    # now lets delete the auth cat
    $success = spdb_query('DELETE FROM ' . SFAUTHCATS . " WHERE authcat_id={$id_or_name}");
    # if successful, need to remove that cat from the auths and replace with default
    if ($success) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat=0 WHERE authcat_id={$id_or_name}");
    }
    return $success;
}
Beispiel #28
0
function sp_delete_special_rank($userid, $rank = '')
{
    $userid = (int) $userid;
    $where = ' WHERE user_id=' . $userid;
    if ($rank != '') {
        $where .= ' AND special_rank="' . $rank . '"';
    }
    spdb_query('DELETE FROM ' . SFSPECIALRANKS . $where);
}
function spa_setup_auth_cats()
{
    global $spVars;
    # have the auths tables been created?
    $auths = spdb_select('var', "SHOW TABLES LIKE '" . SFAUTHS . "'");
    # default auths
    sp_create_auth_cat(spa_text('General'), spa_text('auth category for general auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='use_pm'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='rate_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='watch'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='subscribe'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='report_posts'");
    }
    # viewing auths
    sp_create_auth_cat(spa_text('Viewing'), spa_text('auth category for viewing auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_forum'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_forum_lists'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_forum_topic_lists'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_admin_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_own_admin_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_email'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_profiles'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_members_list'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_links'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='view_online_activity'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='download_attachments'");
    }
    # creating auths
    sp_create_auth_cat(spa_text('Creating'), spa_text('auth category for creating auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='start_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='reply_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_flood_control'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='reply_own_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='use_spoilers'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='use_signatures'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='create_links'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='create_linked_topics'");
    }
    # editing auths
    sp_create_auth_cat(spa_text('Editing'), spa_text('auth category for editing auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_own_topic_titles'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_any_topic_titles'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_own_posts_forever'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_own_posts_reply'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_any_post'");
    }
    # deleting auths
    sp_create_auth_cat(spa_text('Deleting'), spa_text('auth category for deleting auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='delete_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='delete_own_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='delete_any_post'");
    }
    # moderation auths
    sp_create_auth_cat(spa_text('Moderation'), spa_text('auth category for moderation auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_math_question'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_moderation'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_moderation_once'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='moderate_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='bypass_captcha'");
    }
    # tools auths
    sp_create_auth_cat(spa_text('Tools'), spa_text('auth category for tools auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='pin_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='move_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='move_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='lock_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='pin_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='reassign_posts'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='break_linked_topics'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='edit_tags'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='change_topic_status'");
    }
    # uploading auths
    sp_create_auth_cat(spa_text('Uploading'), spa_text('auth category for uploading auths'));
    $auth_cat = $spVars['insertid'];
    if ($auths) {
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_avatars'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_images'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_media'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_files'");
        spdb_query('UPDATE ' . SFAUTHS . " SET auth_cat={$auth_cat} WHERE auth_name='upload_signatures'");
    }
}
Beispiel #30
0
function sp_build_forum_index($forumid, $returnmsg = false)
{
    if (!$forumid) {
        return '';
    }
    # get the topic count for this forum
    $topiccount = spdb_count(SFTOPICS, "forum_id={$forumid}");
    # get the post count and post count held
    $postcount = spdb_sum(SFTOPICS, 'post_count', "forum_id={$forumid}");
    $postcountheld = spdb_sum(SFTOPICS, 'post_count_held', "forum_id={$forumid}");
    # get the last post id and last post held id that appeared in a topic within this forum
    $postid = spdb_table(SFPOSTS, "forum_id={$forumid}", 'post_id', 'post_id DESC', '1');
    $postidheld = spdb_table(SFPOSTS, "forum_id={$forumid} AND post_status=0", 'post_id', 'post_id DESC', '1');
    if (!$topiccount) {
        $topiccount = 0;
    }
    if (!$postcount) {
        $postcount = 0;
    }
    if (!isset($postid)) {
        $postid = 'NULL';
    }
    if (!$postcountheld) {
        $postcountheld = 0;
    }
    if (!isset($postidheld)) {
        $postidheld = 'NULL';
    }
    # update forum record
    spdb_query('UPDATE ' . SFFORUMS . " SET\n\t\t\t\tpost_id={$postid},\n\t\t\t\tpost_id_held={$postidheld},\n\t\t\t\tpost_count={$postcount},\n\t\t\t\tpost_count_held={$postcountheld},\n\t\t\t\ttopic_count={$topiccount}\n\t\t\t\tWHERE forum_id={$forumid}");
    if ($returnmsg) {
        sp_notify(SPSUCCESS, sp_text('Verification complete'));
    }
}