Ejemplo n.º 1
0
function weaver_upload_theme($filename)
{
    if (!weaver_f_exists($filename)) {
        return weaver_f_fail("Can't open {$filename}");
    }
    /* can't open */
    if (!weaver_f_file_access_available()) {
        // try an alternative approach - use the allowed file()
        $contents = implode('', file($filename));
    } else {
        $contents = weaver_f_get_contents($filename);
    }
    if (!$contents) {
        return weaver_f_fail("Can't open {$filename}");
    }
    return weaver_set_current_to_serialized_values($contents);
}
Ejemplo n.º 2
0
function weaver_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);
    $ext_check = end(explode('.', $check_file));
    if (!weaver_f_file_access_available()) {
        $errors[] = "Sorry - Weaver unable to access files.<br />";
        $ok = false;
    }
    if ($filename == "") {
        $errors[] = "You didn't select a file to upload.<br />";
        $ok = false;
    }
    if ($ok && $ext_check != 'wvr' && $ext_check != 'wvb') {
        $errors[] = "Theme files must have <em>.wvr</em> or <em>.wvb</em> extension.<br />";
        $ok = false;
    }
    if ($ok) {
        if (!weaver_f_exists($openname)) {
            $errors[] = '<strong><em style="color:red;">' . __('Sorry, there was a problem uploading your file. You may need to check your folder permissions or other server settings.', WEAVER_TRANSADMIN) . '</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 = weaver_f_get_contents($openname);
        if (!weaver_set_current_to_serialized_values($contents, 'weaver_uploadit:' . $openname)) {
            echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' . __('Sorry, there was a problem uploading your file. The file you picked was not a valid Weaver theme file.', WEAVER_TRANSADMIN) . '</em></strong></p></div>';
        } else {
            $t = weaver_getopt('ttw_subtheme');
            if ($t == '') {
                $t = 'Wheat';
            }
            /* did we save a theme? */
            weaver_save_msg(__("Weaver theme options reset to uploaded theme, saved as: ", WEAVER_TRANSADMIN) . $t);
        }
    }
}