function spa_save_global_data()
{
    global $wp_roles;
    check_admin_referer('forum-adminform_global', 'forum-adminform_global');
    $mess = spa_text('Options updated');
    spa_update_check_option('sflockdown');
    # auto update
    $sfauto = '';
    $sfauto['sfautoupdate'] = isset($_POST['sfautoupdate']);
    $sfauto['sfautotime'] = sp_esc_int($_POST['sfautotime']);
    if (empty($sfauto['sfautotime']) || $sfauto['sfautotime'] == 0) {
        $sfauto['sfautotime'] = 300;
    }
    sp_update_option('sfauto', $sfauto);
    $sfrss = array();
    $sfrss['sfrsscount'] = sp_esc_int($_POST['sfrsscount']);
    $sfrss['sfrsswords'] = sp_esc_int($_POST['sfrsswords']);
    $sfrss['sfrssfeedkey'] = isset($_POST['sfrssfeedkey']);
    $sfrss['sfrsstopicname'] = isset($_POST['sfrsstopicname']);
    sp_update_option('sfrss', $sfrss);
    $sfblock = array();
    $sfblock['blockadmin'] = isset($_POST['blockadmin']);
    $sfblock['blockprofile'] = isset($_POST['blockprofile']);
    $sfblock['blockredirect'] = sp_filter_save_cleanurl($_POST['blockredirect']);
    if ($sfblock['blockadmin']) {
        $sfblock['blockroles'] = array();
        $roles = array_keys($wp_roles->role_names);
        if ($roles) {
            foreach ($roles as $index => $role) {
                $sfblock['blockroles'][$role] = isset($_POST['role-' . $index]);
            }
            # always allow admin
            $sfblock['blockroles']['administrator'] = true;
        }
    }
    sp_update_option('sfblockadmin', $sfblock);
    sp_update_option('speditor', sp_esc_int($_POST['editor']));
    $spError = array();
    $spError['spErrorLogOff'] = isset($_POST['errorlog']);
    $spError['spNoticesOff'] = isset($_POST['notices']);
    sp_update_option('spErrorOptions', $spError);
    $old = sp_get_option('combinecss');
    sp_update_option('combinecss', isset($_POST['combinecss']));
    if (!$old && isset($_POST['combinecss'])) {
        sp_clear_combined_css('all');
        sp_clear_combined_css('mobile');
        sp_clear_combined_css('tablet');
    }
    $old = sp_get_option('combinejs');
    sp_update_option('combinejs', isset($_POST['combinejs']));
    if (!$old && isset($_POST['combinejs'])) {
        sp_clear_combined_scripts();
    }
    sp_update_option('topic_cache', sp_esc_int($_POST['topiccache']));
    sp_update_option('floodcontrol', max(sp_esc_int($_POST['floodcontrol']), 0));
    do_action('sph_option_global_save');
    return $mess;
}
function sp_response($section, $die = true, $status = 'success', $error = '')
{
    global $wpdb;
    $response = array('status' => '', 'type' => '', 'section' => '', 'response' => '', 'error' => '');
    # log the build section and status in the response
    echo "Build upgrade section {$section} executing.  Status: {$status} <br />";
    if ($status == 'error' && !empty($error)) {
        echo "Error: {$error} <br />";
    }
    # build the response
    $response['status'] = $status;
    $response['type'] = 'upgrade';
    $response['section'] = $section;
    $response['error'] = $error;
    $response['response'] = ob_get_contents();
    # save as log meta data if table exists! (Need to check if installed yet sadly)
    $go = $wpdb->get_var("SHOW TABLES LIKE '" . SFLOGMETA . "'");
    if ($go) {
        $sql = '
			INSERT INTO ' . SFLOGMETA . " (version, log_data)\n\t\t\tVALUES (\n\t\t\t'" . SPVERSION . "',\n\t\t\t'" . serialize($response) . "')";
        spdb_query($sql);
    }
    ob_end_clean();
    # send the response (mark with tags so we can extract only the response)
    echo '%%%marker%%%';
    print json_encode($response);
    echo '%%%marker%%%';
    # and if this is the last update in build finish off...
    if (SPBUILD == $section) {
        # let plugins know
        do_action('sph_upgrade_done', SPBUILD);
        # Finished Upgrades ===============================================================================
        sp_log_event(SPRELEASE, SPVERSION, SPBUILD);
        sp_update_permalink(true);
        delete_option('sfInstallID');
        # use wp option table
        # and some final cleanuop tasks
        sp_reset_auths();
        sp_clear_combined_css('all');
        sp_clear_combined_css('mobile');
        sp_clear_combined_css('tablet');
        sp_clear_combined_scripts('desktop');
        sp_clear_combined_scripts('mobile');
        sp_clear_combined_scripts('tablet');
        sp_flush_cache('all');
        sp_reset_member_plugindata();
    }
    if ($die) {
        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');
    }
}
예제 #4
0
function spa_save_housekeeping_data()
{
    check_admin_referer('forum-adminform_housekeeping', 'forum-adminform_housekeeping');
    $mess = '';
    if (isset($_POST['rebuild-fidx'])) {
        $forumid = $_POST['forum_id'];
        if (is_numeric($forumid)) {
            $topics = spdb_table(SFTOPICS, "forum_id={$forumid}");
            if ($topics) {
                include_once SF_PLUGIN_DIR . '/forum/database/sp-db-management.php';
                foreach ($topics as $topic) {
                    sp_build_post_index($topic->topic_id);
                }
                # after reubuilding post indexes, rebuild the forum indexes
                sp_build_forum_index($forumid);
                do_action('sph_toolbox_housekeeping_forum_index');
                $mess = spa_text('Forum indexes rebuilt');
            } else {
                $mess = spa_text('Forum index rebuild failed - no topics in selected forum');
            }
        } else {
            $mess = spa_text('Forum index rebuild failed - no forum selected');
        }
    }
    if (isset($_POST['transient-cleanup'])) {
        include_once SF_PLUGIN_DIR . '/forum/database/sp-db-management.php';
        sp_transient_cleanup();
        do_action('sph_toolbox_housekeeping_transient');
        $mess = spa_text('WP transients cleaned');
    }
    if (isset($_POST['clean-newposts'])) {
        $days = isset($_POST['sfdays']) ? max(sp_esc_int($_POST['sfdays']), 0) : 30;
        $users = spdb_select('col', "SELECT user_id FROM " . SFMEMBERS . " WHERE lastvisit < DATE_SUB(CURDATE(), INTERVAL " . $days . " DAY)");
        if ($users) {
            foreach ($users as $user) {
                spdb_query('UPDATE ' . SFMEMBERS . " SET newposts='a:1:{i:0;i:0;}' WHERE user_id={$user}");
            }
        }
        do_action('sph_toolbox_housekeeping_newpost');
        $mess = spa_text('New posts lists cleaned');
    }
    if (isset($_POST['postcount-cleanup'])) {
        spdb_query('UPDATE ' . SFMEMBERS . ' SET posts = (SELECT COUNT(*) FROM ' . SFPOSTS . ' WHERE ' . SFPOSTS . '.user_id = ' . SFMEMBERS . '.user_id)');
        # force stats to update
        do_action('sph_stats_cron');
        do_action('sph_toolbox_housekeeping_postcount');
        $mess = spa_text('User post counts calculated');
    }
    if (isset($_POST['reset-tabs'])) {
        # clear out current tabs
        $tabs = sp_get_sfmeta('profile', 'tabs');
        sp_delete_sfmeta($tabs[0]['meta_id']);
        # start adding new ones
        spa_new_profile_setup();
        do_action('sph_toolbox_housekeeping_profile_tabs');
        $mess = spa_text('Profile tabs reset');
    }
    if (isset($_POST['reset-auths'])) {
        sp_reset_auths();
        do_action('sph_toolbox_housekeeping_auths');
        $mess = spa_text('Auths caches cleaned');
    }
    if (isset($_POST['reset-plugin-data'])) {
        sp_reset_member_plugindata();
        do_action('sph_toolbox_housekeeping_plugindata');
        $mess = spa_text('Users Plugin Data reset');
    }
    if (isset($_POST['reset-combinedcss'])) {
        sp_clear_combined_css('all');
        sp_clear_combined_css('mobile');
        sp_clear_combined_css('tablet');
        do_action('sph_toolbox_housekeeping_ccombined_css');
        $mess = spa_text('Combined CSS cache file removed');
    }
    if (isset($_POST['reset-combinedjs'])) {
        sp_clear_combined_scripts('desktop');
        sp_clear_combined_scripts('mobile');
        sp_clear_combined_scripts('tablet');
        do_action('sph_toolbox_housekeeping_combined_js');
        $mess = spa_text('Combined scripts cache files removed');
    }
    if (isset($_POST['flushcache'])) {
        sp_flush_cache('all');
        do_action('sph_toolbox_housekeeping_flush_cache');
        $mess = spa_text('General cache flushed');
    }
    do_action('sph_toolbox_housekeeping_save');
    return $mess;
}
function spa_save_theme_tablet_data()
{
    check_admin_referer('forum-adminform_themes', 'forum-adminform_themes');
    $tabletTheme = sp_get_option('sp_tablet_theme');
    $curTheme = sp_get_option('sp_current_theme');
    $tablet = array();
    $active = isset($_POST['active']);
    if ($active && $tabletTheme['active']) {
        $theme = isset($_POST['theme']) ? sp_esc_str($_POST['theme']) : $tabletTheme['theme'];
        $style = isset($_POST['style']) ? sp_esc_str($_POST['style']) : $tabletTheme['style'];
        $color = isset($_POST['color-' . $theme]) ? sp_esc_str($_POST['color-' . $theme]) : '';
        $parent = isset($_POST['parent']) ? sp_esc_str($_POST['parent']) : $tabletTheme['parent'];
        $pagetemplate = isset($_POST['pagetemplate']) ? sp_esc_str($_POST['pagetemplate']) : $tabletTheme['pagetemplate'];
        if (isset($_POST['pagetemplate'])) {
            $usetemplate = isset($_POST['usetemplate']);
            $notitle = isset($_POST['notitle']);
        } else {
            $usetemplate = $tabletTheme['usetemplate'];
            $notitle = $tabletTheme['notitle'];
        }
        if (empty($theme) || empty($style)) {
            return spa_text('No data changed');
        }
        if (empty($color)) {
            $color = sp_esc_str($_POST['default-color']);
        }
        $tablet['active'] = true;
        $tablet['theme'] = $theme;
        $tablet['style'] = $style;
        $tablet['color'] = $color;
        $tablet['parent'] = $parent;
        $tablet['usetemplate'] = $usetemplate;
        $tablet['pagetemplate'] = $pagetemplate;
        $tablet['notitle'] = $notitle;
    } else {
        $tablet = array();
        $tablet['active'] = $active;
        $tablet['theme'] = $curTheme['theme'];
        $tablet['style'] = $curTheme['style'];
        $tablet['color'] = $curTheme['color'];
        $tablet['parent'] = $curTheme['parent'];
        $tablet['usetemplate'] = false;
        $tablet['pagetemplate'] = spdb_table(SFWPPOSTMETA, "meta_key='_wp_page_template' AND post_id=" . sp_get_option('sfpage'), 'meta_value');
        $tablet['notitle'] = true;
    }
    $icons = 'images';
    if (!empty($tablet['color'])) {
        $f = SPTHEMEBASEDIR . $tablet['theme'] . '/styles/overlays/' . $tablet['color'] . '.php';
        $icons = sp_esc_str(sp_get_overlay_image_path($f));
    }
    $tablet['icons'] = $icons;
    sp_update_option('sp_tablet_theme', $tablet);
    # clean out the combined css file
    sp_clear_combined_css('tablet');
    # theme activation action
    do_action('sph_activate_tablet_theme', $tablet);
    do_action('sph_activate_tablet_theme_' . $tablet['theme'], $tablet);
    return spa_text('Mobile Tablet theme activated/updated');
}
function sp_go_network_upgrade($current_version, $current_build)
{
    global $current_user;
    ?>
	<div class="wrap"><br />
		<div class="updated">
		<img class="stayleft" src="<?php 
    echo SFCOMMONIMAGES;
    ?>
sp-mini-logo.png" alt="" title="" />
		<h3><?php 
    spa_etext('Simple:Press is upgrading the Network.');
    ?>
</h3>
		</div><br />
		<div class="wrap sfatag">
			<div class="imessage" id="imagezone"></div>
		</div><br />
		<div class="pbar" id="progressbar"></div><br />
		<div class="wrap sfatag">
			<div class="zmessage" id="errorzone"></div>
			<div id="finishzone"></div><br />
		</div><br />
		<div id="debug">
			</p><b>Please copy the details below and include them on any support forum question you may have:</b><br /><br /></p>
		</div>
	</div>
<?php 
    # get list of network sites
    $sites = wp_get_sites();
    # loop through all blogs and upgrade ones with active simple:press
    foreach ($sites as $site) {
        # switch to network site and see if simple:press is active
        switch_to_blog($site['blog_id']);
        global $wpdb;
        $installed = spdb_select('set', 'SELECT option_id FROM ' . $wpdb->prefix . "sfoptions WHERE option_name='sfversion'");
        if ($installed) {
            $phpfile = SFHOMEURL . 'index.php?sp_ahah=upgrade&sfnonce=' . wp_create_nonce('forum-ahah') . '&sfnetworkid=' . $site['blog_id'];
            $image = SFCOMMONIMAGES . 'working.gif';
            $targetbuild = SPBUILD;
            update_option('sfInstallID', $current_user->ID);
            # use wp option table
            # save the build info
            $out = spa_text('Upgrading Network Site ID') . ': ' . $site['blog_id'] . '<br />';
            sp_update_option('sfStartUpgrade', $current_build);
            # upgrade the network site
            $messages = esc_js(spa_text('Go to Forum Admin')) . '@' . esc_js(spa_text('Upgrade is in progress - please wait')) . '@' . esc_js(spa_text('Upgrade Completed')) . '@' . esc_js(spa_text('Upgrade Aborted')) . '@' . esc_js(spa_text('Go to Forum'));
            $out .= '<script type="text/javascript">' . "\n";
            $out .= 'spjPerformUpgrade("' . $phpfile . '", "' . $current_build . '", "' . $targetbuild . '", "' . $current_build . '", "' . $image . '", "' . $messages . '", "' . sp_url() . '");' . "\n";
            $out .= '</script>' . "\n";
            echo $out;
            # clear any combined css/js cached files
            sp_clear_combined_css('all');
            sp_clear_combined_css('mobile');
            sp_clear_combined_css('tablet');
            sp_clear_combined_scripts('desktop');
            sp_clear_combined_scripts('mobile');
            sp_clear_combined_scripts('tablet');
        }
        restore_current_blog();
    }
}
예제 #7
0
# Start of Upgrade Routines - 5.3.2 ============================================================
$section = 10628;
if ($build < $section) {
    # add category of error to error log
    spdb_query('TRUNCATE ' . SFERRORLOG);
    spdb_query('ALTER TABLE ' . SFERRORLOG . " ADD (error_cat varchar(13) NOT NULL default 'spaErrOther')");
    spdb_query('ALTER TABLE ' . SFERRORLOG . ' ADD (keycheck varchar(45))');
    sp_response($section);
}
$section = 10633;
if ($build < $section) {
    # create cache storage location
    sp_create_cache_location();
    sp_clear_combined_css('all');
    sp_clear_combined_css('mobile');
    sp_clear_combined_css('tablet');
    sp_clear_combined_scripts();
    sp_response($section);
}
$section = 10693;
if ($build < $section) {
    # add count of error to error log
    spdb_query('ALTER TABLE ' . SFERRORLOG . ' ADD (error_count tinyint)');
    sp_response($section);
}
$section = 10707;
if ($build < $section) {
    # force rebuild of auths cache since users global auths may be wrong
    sp_reset_auths();
    sp_response($section);
}
function sp_barebones_options_save_custom()
{
    if (isset($_POST['commit-reset'])) {
        include_once SPBBADMIN . 'sp-barebones-activate.php';
        sp_barebones_setup(false);
        $msg = spa_text('Settings returned to default');
    }
    if (isset($_POST['commit-save']) || isset($_POST['commit-test'])) {
        $files = array();
        if (isset($_POST['commit-save'])) {
            $files[] = SF_STORE_DIR . '/' . 'sp-custom-settings/sp-barebones-custom-settings.php';
            $files[] = SF_STORE_DIR . '/' . 'sp-custom-settings/sp-barebones-test-settings.php';
            $msg = spa_text('Site custom settings updated');
        } else {
            $files[] = SF_STORE_DIR . '/' . 'sp-custom-settings/sp-barebones-test-settings.php';
            $msg = spa_text('Test custom settings updated');
        }
        foreach ($files as $file) {
            $C1 = empty($_POST['C1']) ? '#' : $_POST['C1'];
            $C2 = empty($_POST['C2']) ? '#' : $_POST['C2'];
            $C3 = empty($_POST['C3']) ? '#' : $_POST['C3'];
            $C4 = empty($_POST['C4']) ? '#' : $_POST['C4'];
            $C5 = empty($_POST['C5']) ? '#' : $_POST['C5'];
            $C6 = empty($_POST['C6']) ? '#' : $_POST['C6'];
            $C7 = empty($_POST['C7']) ? '#' : $_POST['C7'];
            $C8 = empty($_POST['C8']) ? '#' : $_POST['C8'];
            $C9 = empty($_POST['C9']) ? '#' : $_POST['C9'];
            $C10 = empty($_POST['C10']) ? '#' : $_POST['C10'];
            $C11 = empty($_POST['C11']) ? '#' : $_POST['C11'];
            $FN = empty($_POST['FN']) ? 'Tahoma' : $_POST['FN'];
            $F1 = empty($_POST['F1']) ? '100' : $_POST['F1'];
            if (is_writeable($file)) {
                $ops = "<?php\n";
                $ops .= "\$ops = array(\n";
                $ops .= "'C1' => '" . $C1 . "',\n";
                $ops .= "'C2' => '" . $C2 . "',\n";
                $ops .= "'C3' => '" . $C3 . "',\n";
                $ops .= "'C4' => '" . $C4 . "',\n";
                $ops .= "'C5' => '" . $C5 . "',\n";
                $ops .= "'C6' => '" . $C6 . "',\n";
                $ops .= "'C7' => '" . $C7 . "',\n";
                $ops .= "'C8' => '" . $C8 . "',\n";
                $ops .= "'C9' => '" . $C9 . "',\n";
                $ops .= "'C10' => '" . $C10 . "',\n";
                $ops .= "'C11' => '" . $C11 . "',\n";
                $ops .= "'FN' => '" . $FN . "',\n";
                $ops .= "'F1' => '" . $F1 . "',\n";
                $ops .= ");\n?>";
                $f = fopen($file, 'w');
                if ($f !== false) {
                    fwrite($f, $ops);
                    fclose($f);
                } else {
                    $msg = spa_text('Unable to save theme file');
                }
            } else {
                $msg = spa_text('Theme file is not writable!');
            }
        }
    }
    # need to clear combined css cache for changes to take effect
    sp_clear_combined_css('all');
    sp_clear_combined_css('mobile');
    sp_clear_combined_css('tablet');
    echo $msg;
}