예제 #1
0
function weaver_admin_page_process_options()
{
    /* Process all options - called upon entry to options forms */
    // echo("WEAVER-SETTINGS:"); var_dump($weaver_main_settings);
    // echo "POST-weaver-settings:" ; var_dump($_POST['weaver_main_settings']);
    // echo "POST-FULL:" ; var_dump($_POST);
    settings_errors();
    // display results from SAPI save settings
    /* ================ Weaver Upgrade 2020 Weaver buttons ================== */
    if (weaver_submitted('hide_import_old_weaver')) {
        weaver_setopt('wvr_hide_if_are_oldWeaver_opts', true);
        weaver_save_msg(__('Hide 2010 Weaver Notice', WEAVER_TRANSADMIN));
    }
    if (weaver_submitted('import_old_weaver')) {
        weaver_import_2010_weaver();
        weaver_save_msg(__("Previously existing settngs imported.", WEAVER_TRANSADMIN));
    }
    /* ================ Weaver Themes Tab ================== */
    if (weaver_submitted('setsubtheme') || weaver_submitted('setsubtheme2')) {
        /* seems like Mozilla doesn't like 2 sets of select inputs on same page, so we make up 2 ids/names to use */
        if (isset($_POST['setsubtheme'])) {
            $pID = 'ttw_subtheme';
        } else {
            $pID = 'ttw_subtheme2';
        }
        $cur_subtheme = weaver_filter_textarea($_POST[$pID]);
        /* must have been set to get here */
        if ($cur_subtheme == '') {
            $cur_subtheme = 'Wheat';
        }
        /* but just in case */
        /* now, I set all values for theme */
        weaver_activate_subtheme($cur_subtheme);
        $t = weaver_getopt('ttw_subtheme');
        if ($t == '') {
            $t = 'Wheat';
        }
        /* did we save a theme? */
        weaver_save_msg(__("Weaver current sub-theme set to: ", WEAVER_TRANSADMIN) . $t);
    }
    /* ================ Weaver FTP File Access ================== */
    if (weaver_submitted('ftp_save_form')) {
        if (isset($_POST['ftp_hostnamex'])) {
            weaver_setopt('ftp_hostname', trim(weaver_filter_textarea($_POST['ftp_hostnamex'])));
        }
        if (isset($_POST['ftp_usernamex'])) {
            weaver_setopt('ftp_username', trim(weaver_filter_textarea($_POST['ftp_usernamex'])));
        }
        if (isset($_POST['ftp_passwordx'])) {
            weaver_setopt('ftp_password', weaver_encrypt(trim($_POST['ftp_passwordx'])));
        }
        if (isset($_POST['ftp_hide_check_messagex'])) {
            weaver_setopt('ftp_hide_check_message', true);
        } else {
            weaver_setopt('ftp_hide_check_message', false);
        }
        weaver_save_msg(__('FTP File Access Form Settings Saved.', WEAVER_TRANSADMIN));
    }
    /* ================ Weaver Main Options Tab ================== */
    /* Weaver Main and Advanced Options processed in validation callbacks */
    /* ================ Weaver Advanced Options Tab ================== */
    /* SAPI settings are handled in the Main Options Tab section above */
    if (weaver_submitted('reset_weaver')) {
        // delete everything!
        weaver_save_msg(__('All Weaver settings have been reset to the defaults.', WEAVER_TRANS));
        delete_option('weaver_main_settings');
        delete_option('weaver_advanced_settings');
        weaver_load_cache();
        // be sure cache has something valid in it
        weaver_init_opts('reset_weaver');
    }
    /* ================ Weaver Save/Restore Themes Tab ================== */
    /* this tab has the most individual forms and submit commands */
    if (weaver_submitted('changethemename')) {
        if (isset($_POST['newthemename'])) {
            $new_name = sanitize_user($_POST['newthemename']);
            weaver_setopt('ttw_themename', $new_name);
            echo '<div id="message" class="updated fade"><p><strong>Theme name changed to ' . $new_name . '</strong></p></div>';
        }
        global $weaver_dev;
        if ($weaver_dev) {
            // used to save a theme for distribution/inclusion in dynamic theme db
            if (isset($_POST['newthemeimage'])) {
                weaver_setopt('ttw_theme_image', $_POST['newthemeimage']);
            }
            if (isset($_POST['newthemedesc'])) {
                weaver_setopt('ttw_theme_description', $_POST['newthemedesc']);
            }
        }
    }
    if (weaver_submitted('savemytheme')) {
        if (weaver_savemytheme()) {
            weaver_save_msg(__('All current main and advanced options backed up in <em>My Saved Theme</em>.', WEAVER_TRANSADMIN));
        } else {
            weaver_save_msg(__('ERROR: Saving <em>My Saved Theme</em> failed.', WEAVER_TRANSADMIN));
        }
    }
    if (weaver_submitted('backup_settings')) {
        $name = weaver_savebackup();
        if ($name !== false) {
            weaver_save_msg(__('All current main and advanced options backed up in:', WEAVER_TRANSADMIN) . ' "' . $name . '.wvb"');
        } else {
            weaver_save_msg(__('ERROR: Saving backup failed.', WEAVER_TRANSADMIN));
        }
    }
    if (weaver_submitted('filesavetheme')) {
        $base = strtolower(sanitize_file_name($_POST['savethemename']));
        $temp_url = weaver_write_current_theme($base);
        if ($temp_url == '') {
            weaver_save_msg(__('Invalid name supplied to save theme to file.', WEAVER_TRANSADMIN));
        } else {
            weaver_save_msg(__("All current main and advanced options saved in ", WEAVER_TRANSADMIN) . $temp_url);
        }
    }
    if (weaver_submitted('uploadtheme') && isset($_POST['uploadit']) && $_POST['uploadit'] == 'yes') {
        weaver_uploadit();
    }
    if (weaver_submitted('restoretheme')) {
        $base = $_POST['ttw_restorename'];
        $valid = validate_file($base);
        // make sure an ok file name
        $fn = weaver_f_uploads_base_dir() . 'weaver-subthemes/' . $base;
        if ($valid < 1 && weaver_upload_theme($fn)) {
            $t = weaver_getopt('ttw_subtheme');
            if ($t == '') {
                $t = 'Wheat';
            }
            /* did we save a theme? */
            weaver_save_msg(__("Weaver theme restored from file, saved as: ", WEAVER_TRANSADMIN) . $t);
        } else {
            weaver_save_msg('<em style="color:red;">' . __('INVALID FILE NAME PROVIDED - Try Again', WEAVER_TRANSADMIN) . "({$fn})" . '</em>');
        }
    }
    if (weaver_submitted('deletetheme')) {
        $myFile = $_POST['selectName'];
        $valid = validate_file($myFile);
        if ($valid < 1 && $myFile != "None") {
            weaver_f_delete(weaver_f_uploads_base_dir() . 'weaver-subthemes/' . $myFile);
            echo '<div style="background-color: rgb(255, 251, 204);" id="message" class="updated fade"><p>File: <strong>' . $myFile . '</strong> has been deleted.</p></div>';
        } else {
            echo '<div style="background-color: rgb(255, 251, 204);" id="message" class="updated fade"><p>File: <strong>' . $myFile . '</strong> invalid file name, not deleted.</p></div>';
        }
    }
    /* ====================================================== */
    if (weaver_submitted('wvrx_save_extension')) {
        /* for theme extensions */
        do_action('wvrx_save_extension');
    }
    if (weaver_submitted('wvrx_plus_save_plus')) {
        do_action('wvrx_plus_save_plus');
    }
    // All plus submit buttons...
    weaver_save_opts('Weaver Admin');
    /* FINALLY - SAVE ALL OPTIONS AND UPDATE CURRENT CSS FILE */
}
예제 #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);
        }
    }
}