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);
}
Example #2
0
function weaverii_uploadit()
{
    // upload theme from users computer
    // they've supplied and uploaded a file
    $ok = true;
    // no errors so far
    if (isset($_FILES['uploaded']['name'])) {
        $filename = $_FILES['uploaded']['name'];
    } else {
        $filename = "";
    }
    if (isset($_FILES['uploaded']['tmp_name'])) {
        $openname = $_FILES['uploaded']['tmp_name'];
    } else {
        $openname = "";
    }
    //Check the file extension
    $check_file = strtolower($filename);
    $pat = '.';
    // PHP version strict checking bug...
    $end = explode($pat, $check_file);
    $ext_check = end($end);
    if ($filename == "") {
        $errors[] = "You didn't select a file to upload.<br />";
        $ok = false;
    }
    if ($ok && $ext_check != 'w2t' && $ext_check != 'w2b') {
        $errors[] = "Theme files must have <em>.w2t</em> or <em>.w2b</em> extension.<br />";
        $ok = false;
    }
    if ($ok) {
        if (!weaverii_f_exists($openname)) {
            $errors[] = '<strong><em style="color:red;">' . weaverii_t_('Sorry, there was a problem uploading your file. You may need to check your folder permissions or other server settings.') . '</em></strong>' . "<br />(Trying to use file '{$openname}')";
            $ok = false;
        }
    }
    if (!$ok) {
        echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">ERROR</em></strong></p><p>';
        foreach ($errors as $error) {
            echo $error . '<br />';
        }
        echo '</p></div>';
    } else {
        // OK - read file and save to My Saved Theme
        // $handle has file handle to temp file.
        $contents = weaverii_f_get_contents($openname);
        if (!weaverii_set_current_to_serialized_values($contents, 'weaverii_uploadit:' . $openname)) {
            echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' . weaverii_t_('Sorry, there was a problem uploading your file. The file you picked was not a valid Weaver II theme file.') . '</em></strong></p></div>';
        } else {
            weaverii_save_msg(weaverii_t_("Weaver II theme options reset to uploaded theme."));
        }
    }
}
Example #3
0
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;
}