function weaverii_ex_set_current_to_serialized_values($contents)
{
    global $weaverii_opts_cache;
    // need to mess with the cache
    if (substr($contents, 0, 10) == 'W2T-V01.00') {
        $type = 'theme';
    } else {
        if (substr($contents, 0, 10) == 'W2B-V01.00') {
            $type = 'backup';
        } else {
            return weaverii_f_fail(weaverii_t_("Wrong theme file format version"));
        }
    }
    /* simple check for one of ours */
    $restore = array();
    $restore = unserialize(substr($contents, 10));
    if (!$restore) {
        return weaverii_f_fail("Unserialize failed - file likely corrupt.");
    }
    $version = weaverii_getopt('wii_version_id');
    // get something to force load
    if ($type == 'theme') {
        // need to clear some settings
        // first, pickup the per-site settings that aren't theme related...
        $new_cache = array();
        foreach ($weaverii_opts_cache as $key => $val) {
            if ($key[0] == '_') {
                // these are non-theme specific settings
                $new_cache[$key] = $val;
            }
            // keep
        }
        $opts = $restore['weaverii_base'];
        // fetch base opts
        weaverii_delete_all_options();
        foreach ($opts as $key => $val) {
            if ($key[0] != '_') {
                weaverii_setopt($key, $val, false);
            }
            // overwrite with saved theme values
        }
        foreach ($new_cache as $key => $val) {
            // set the values we need to keep
            weaverii_setopt($key, $val, false);
        }
    } else {
        if ($type == 'backup') {
            weaverii_delete_all_options();
            $opts = $restore['weaverii_base'];
            // fetch base opts
            foreach ($opts as $key => $val) {
                weaverii_setopt($key, $val, false);
                // overwrite with saved values
            }
            global $weaverii_pro_opts;
            $weaverii_pro_opts = false;
            $weaverii_pro_opts = $restore['weaverii_pro'];
            weaverii_wpupdate_option('weaverii_pro', $weaverii_pro_opts);
        }
    }
    weaverii_setopt('wii_version_id', $version);
    // keep version, force save of db
    weaverii_save_opts('loading theme');
    // OK, now we've saved the options, update them in the DB
    return true;
}
function weaverii_activate_subtheme($theme)
{
    /* load settings for specified theme */
    global $weaverii_opts_cache;
    /* build the filename - theme files stored in /wp-content/themes/weaverii/subthemes/
    
    	Important: the following code assumes that any of the pre-defined theme files won't have
    	and end-of-line character in them, which should be true. A user could muck about with the
    	files, and possibly break this assumption. This assumption is necessary because the WP
    	theme rules allow file(), but not file_get_contents(). Other than that, the following code
    	is really the same as the 'theme' section of weaverii_upload_theme() in the pro library
    	*/
    $filename = get_template_directory() . '/subthemes/' . $theme . '.w2t';
    $contents = weaverii_f_get_contents($filename);
    // use either real (pro) or file (standard) version of function
    if (empty($contents)) {
        return false;
    }
    if (substr($contents, 0, 10) != 'W2T-V01.00') {
        return false;
    }
    $restore = array();
    $restore = unserialize(substr($contents, 10));
    if (!$restore) {
        return false;
    }
    $version = weaverii_getopt('wii_version_id');
    // get something to force load
    // need to clear some settings
    // first, pickup the per-site settings that aren't theme related...
    $new_cache = array();
    foreach ($weaverii_opts_cache as $key => $val) {
        if ($key[0] == '_') {
            // these are non-theme specific settings
            $new_cache[$key] = $weaverii_opts_cache[$key];
            // clear
        }
    }
    $opts = $restore['weaverii_base'];
    // fetch base opts
    weaverii_delete_all_options();
    foreach ($new_cache as $key => $val) {
        // set the values we need to keep
        weaverii_setopt($key, $new_cache[$key], false);
    }
    foreach ($opts as $key => $val) {
        if ($key[0] == '_') {
            continue;
        }
        // should be here
        weaverii_setopt($key, $val, false);
        // overwrite with saved theme values
    }
    weaverii_setopt('wii_version_id', WEAVERII_VERSION, false);
    weaverii_setopt('wii_theme_filename', $theme, false);
    weaverii_setopt('wii_style_version', 1, false);
    weaverii_setopt('wii_last_option', 'WeaverII');
    // assume always ok if from file
    weaverii_save_opts('set subtheme');
    // OK, now we've saved the options, update them in the DB
    return true;
}
function weaverii_pro_update_options($id)
{
    global $weaverii_pro_opts;
    if (!$weaverii_pro_opts) {
        $weaverii_pro_opts = get_option(apply_filters('weaver_options', 'weaverii_pro'), array());
    }
    weaverii_wpupdate_option('weaverii_pro', $weaverii_pro_opts, 'pro_update_options');
    weaverii_save_opts('weaverii_pro');
    // need to re-write the stylesheet
}
Exemple #4
0
function weaverii_admin_page_process_options()
{
    /* Process all options - called upon entry to options forms */
    // Most options are handled by the SAPI filter.
    settings_errors('weaverii_settings');
    // display results from SAPI save settings
    global $weaverii_opts_cache;
    weaverii_process_options_themes();
    // >>>> Weaver II Themes Tab
    do_action('weaverii_child_process_options');
    // let the child theme do something
    weaverii_process_options_admin_standard();
    // setting from admin page
    /* this tab has the most individual forms and submit commands */
    weaverii_process_options_admin_pro();
    /* ====================================================== */
    weaverii_save_opts('Weaver II Admin');
    /* FINALLY - SAVE ALL OPTIONS AND UPDATE CURRENT CSS FILE */
}