function weaverx_get_default_settings()
 {
     // This function loads the settings for the default theme. None of the settings are saved, so this meets
     // the WP theme requirements of not touching the DB until the user clicks something.
     global $weaverx_opts_cache;
     $weaverx_opts_cache = array();
     $filename = apply_filters('weaverx_default_subtheme', get_template_directory() . WEAVERX_DEFAULT_THEME_FILE);
     if (!weaverx_f_exists($filename)) {
         return false;
     }
     $contents = weaverx_f_get_contents($filename);
     // use either real (pro) or file (standard) version of function
     if (empty($contents)) {
         return false;
     }
     if (substr($contents, 0, 10) != 'WXT-V01.00') {
         return false;
     }
     $restore = array();
     $restore = unserialize(substr($contents, 10));
     $opts = $restore['weaverx_base'];
     // fetch base opts
     foreach ($opts as $opt => $val) {
         $weaverx_opts_cache[$opt] = $val;
     }
 }
 function weaverx_cz_getdefaults()
 {
     $filename = apply_filters('weaverx_default_subtheme', get_template_directory() . WEAVERX_DEFAULT_THEME_FILE);
     if (!weaverx_f_exists($filename)) {
         return array();
     }
     $contents = weaverx_f_get_contents($filename);
     // use either real (pro) or file (standard) version of function
     if (empty($contents)) {
         return array();
     }
     if (substr($contents, 0, 10) != 'WXT-V01.00') {
         return array();
     }
     $restore = array();
     $restore = unserialize(substr($contents, 10));
     $ret = array();
     $opts = $restore['weaverx_base'];
     // fetch base opts
     foreach ($opts as $opt => $val) {
         $ret[$opt] = $val;
     }
     return $ret;
 }
 private static function _load_theme($wp_customize)
 {
     // Make sure we have a valid nonce.
     if (!wp_verify_nonce($_REQUEST['wvrx-upload-subtheme'], 'wvrx_select_subtheme')) {
         unset($_POST['wvrx-upload-subtheme']);
         unset($_REQUEST['wvrx-upload-subtheme']);
         weaverx_alert('invalid nonce upload');
         return;
     }
     unset($_POST['wvrx-upload-subtheme']);
     unset($_REQUEST['wvrx-upload-subtheme']);
     if (!isset($_POST['subtheme_picked'])) {
         weaverx_alert('Please select a subtheme to upload.');
         return;
     }
     $theme = weaverx_filter_textarea($_POST['subtheme_picked']);
     $filename = get_template_directory() . '/subthemes/' . $theme . '.wxt';
     if (!weaverx_f_exists($filename)) {
         weaverx_alert(__('Sorry, unable to upload the subtheme.', 'weaver-xtreme'));
         return false;
     }
     $contents = weaverx_f_get_contents($filename);
     // use either real (pro) or file (standard) version of function
     if (empty($contents)) {
         return false;
     }
     // Setup global vars.
     global $wp_customize;
     // upload theme from users computer
     // they've supplied and uploaded a file
     $ok = true;
     // no errors so far
     if (!self::reset_options($contents)) {
         return;
     }
     wp_redirect(home_url('/wp-admin/customize.php?return=%2Fwp-admin%2Fthemes.php%3Fpage%3DWeaverX'));
     //weaverx_alert( __('Weaver Xtreme uploaded subtheme ', 'weaver-xtreme' /*adm*/) . ucwords(str_replace('-',' ',$theme) ) );
 }
function weaverx_loadtheme()
{
    if (!(isset($_POST['uploadit']) && $_POST['uploadit'] == 'yes')) {
        return;
    }
    // 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.', 'weaver-xtreme') . "<br />";
        $ok = false;
    }
    if ($ok && $ext_check != 'wxt' && $ext_check != 'wxb') {
        $errors[] = __('Theme files must have <em>.wxt</em> or <em>.wxb</em> extension.', 'weaver-xtreme') . '<br />';
        $ok = false;
    }
    if ($ok) {
        if (!weaverx_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-xtreme') . '</em></strong><br />(' . __('Trying to use file', 'weaver-xtreme') . ' <em>' . $openname . '</em>)';
            $ok = false;
        }
    }
    if (!$ok) {
        echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">' . __('ERROR', 'weaver-xtreme') . '</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 = weaverx_f_get_contents($openname);
        if (!weaverx_ex_set_current_to_serialized_values($contents, 'weaverx_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 Xtreme theme file.', 'weaver-xtreme') . '</em></strong></p></div>';
        } else {
            weaverx_save_msg(__('Weaver Xtreme theme options reset to uploaded theme.', 'weaver-xtreme'));
        }
    }
}