コード例 #1
0
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;
}
コード例 #2
0
function weaverii_upload_theme($filename)
{
    if (!weaverii_f_exists($filename)) {
        return weaverii_f_fail("Can't open {$filename}");
    }
    /* can't open */
    $contents = weaverii_f_get_contents($filename);
    if (!$contents) {
        return weaverii_f_fail("Can't open {$filename}");
    }
    return weaverii_set_current_to_serialized_values($contents);
}