function weaverii_unpackzip($uploaded, $to_dir) { // upload theme from users computer // they've supplied and uploaded a file $ok = true; // no errors so far if (isset($_FILES[$uploaded]['name'])) { // uploaded_addon $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); $exp = explode('.', $check_file); // call by ref workaround $ext_check = end($exp); if (false && !weaverii_f_file_access_available()) { $errors[] = "Sorry - Weaver II 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 != 'zip') { $errors[] = "Uploaded files must have <em>.zip</em> extension.<br />"; $ok = false; } if ($ok) { if (!weaverii_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.</em></strong><br />' . "(Trying to use file '{$openname}')"; $ok = false; } } if ($ok) { // should be ready to go, but check out WP_Filesystem if (!WP_Filesystem()) { function weaveriiex_return_direct() { return 'direct'; } add_filter('filesystem_method', 'weaveriiex_return_direct'); $try2 = WP_Filesystem(); remove_filter('filesystem_method', 'weaveriiex_return_direct'); if (!$try2) { $errors[] = 'Sorry, there\'s a problem trying to use the WordPress unzip function. Please see the FAQ at weavertheme.com support for more information.'; $ok = false; } } } if ($ok) { // $openname has uploaded .zip file to use // $filename has name of file uploaded $is_error = unzip_file($openname, $to_dir); if (!is_wp_error($is_error)) { weaverii_save_msg('File ' . $filename . ' successfully uploaded and unpacked to: <br />' . $to_dir); @unlink($openname); // delete temp file... } else { $errors[] = "Sorry, unpacking the .zip you selected file failed. You may have a corrupt .zip file, or there many a file permissions problem on your WordPress installation."; $errors[] = $is_error->get_error_message(); $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>'; } return $ok; }
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.")); } } }
function weaverii_child_process_options() { if (!defined('WEAVERII_EXTRAS_ADMIN_HELPERS')) { require_once dirname(__FILE__) . '/includes/wtx-admin-page.php'; } // admin info if (weaverii_submitted('set_added_subtheme')) { // Set to selected addon - theme if (isset($_POST['wii_addon_name'])) { $name = $_POST['wii_addon_name']; $openname = weaverii_f_uploads_base_dir() . 'weaverii-subthemes/addon-subthemes/' . $name . '.w2t'; $contents = file_get_contents($openname); if (!weaverii_ex_set_current_to_serialized_values($contents, 'weaverii_uploadit:' . $openname)) { echo '<div id="message" class="updated fade"><p><strong><em style="color:red;">Sorry, there was a problem uploading your add on theme. The name you picked did not have a valid Weaver II theme file in the /wevaerii-subthemes/addon-subthemes directory.</em></strong></p></div>'; } else { weaverii_save_msg('Weaver II theme options reset to ' . ucwords(str_replace('-', ' ', $name)) . ' add-on subtheme.'); weaverii_setopt('wii_addon_name', $name); } } } else { if (weaverii_submitted('delete_added_subtheme')) { // Delete selected addon theme if (isset($_POST['wii_addon_name'])) { $name = $_POST['wii_addon_name']; @unlink(weaverii_f_uploads_base_dir() . 'weaverii-subthemes/addon-subthemes/' . $name . '.w2t'); @unlink(weaverii_f_uploads_base_dir() . 'weaverii-subthemes/addon-subthemes/' . $name . '.jpg'); weaverii_save_msg('Deleted ' . ucwords(str_replace('-', ' ', $name)) . ' add-on subtheme.'); } } else { if (weaverii_submitted('upload_addon') && isset($_POST['uploadaddon']) && $_POST['uploadaddon'] == 'yes') { // upload theme from users computer // they've supplied and uploaded a file $ok = weaverii_unpackzip('uploaded_addon', weaverii_f_uploads_base_dir() . 'weaverii-subthemes/addon-subthemes/'); } else { if (weaverii_submitted('upload_theme')) { // upload theme from users computer // they've supplied and uploaded a file if (isset($_FILES['uploaded_theme']['name'])) { // uploaded_theme $filename = $_FILES['uploaded_theme']['name']; } else { $filename = ""; } $to = weaverii_f_themes_dir(); if (strpos($filename, 'weaver-ii-pro-') === false && strpos($filename, 'weaver-ii-') === false) { ?> <div id="message" class="updated fade"><p><strong><em style="color:red;">ERROR</em></strong></p> <p>You did not select a Weaver II theme .zip file: "<?php echo $filename; ?> ". The theme file name must start with 'weaver-ii-' or 'weaver-ii-pro-'. Please use a file you downloaded from WeaverTheme.com.</p> </div> <?php return; } $ok = weaverii_unpackzip('uploaded_theme', $to); if ($ok) { weaverii_save_msg('Your Weaver II Theme has been successfully updated. Please click "Clear Messages" button right now to refresh the scrren and start using the updated version.'); } } } } } }
function weaverii_process_options_admin_standard() { if (weaverii_submitted('reset_weaverii')) { if (!current_user_can('edit_theme_options')) { return; } // delete everything! weaverii_save_msg(weaverii_t_('All Weaver II settings have been reset to the defaults.', 'weaver-ii')); delete_option(apply_filters('weaver_options', 'weaverii_settings')); global $weaverii_opts_cache; $weaverii_opts_cache = false; // clear the cache weaveriip_clear_opts(); weaverii_init_opts('reset_weaverii'); update_user_meta(get_current_user_id(), 'tgmpa_dismissed_notice', 0); // reset the dismiss on the plugin loader } if (weaverii_submitted('uploadtheme') && isset($_POST['uploadit']) && $_POST['uploadit'] == 'yes') { weaverii_uploadit(); } if (weaverii_submitted('check_weaver')) { // perform weaver check require_once 'check-theme.php'; // include check code now weaverii_perform_check(); } if (weaverii_submitted('weaver_hideopts')) { weaverii_save_msg(weaverii_t_('Now showing more/fewer options.', 'weaver-ii')); } }
function weaverii_process_options_themes() { if (weaverii_submitted('set_subtheme')) { // invoked from Weaver II Subhemes tab (this file) if (isset($_POST['wii_theme_picked'])) { $theme = weaverii_filter_textarea($_POST['wii_theme_picked']); if (weaverii_activate_subtheme($theme)) { weaverii_save_msg(weaverii_t_("Subtheme Selected: ") . $theme); } else { weaverii_save_msg(weaverii_t_("Invalid Subtheme file detected. Your installation of Weaver II may be broken.")); } } else { weaverii_save_msg(weaverii_t_("Please select a subtheme.")); } } if (weaverii_submitted('save_mytheme')) { // invoked from Save/Restore tab weaverii_save_msg(weaverii_t_("Current settings saved in WordPress database.")); weaverii_settings_db_backup(); return; } if (weaverii_submitted('restore_mytheme')) { // invoked from Save/Restore tab weaverii_settings_db_restore(); weaverii_save_msg(weaverii_t_("Current settings restored from WordPress database.")); return; } if (weaverii_submitted('hide_thumbs')) { $hide = weaverii_getopt('_wii_hide_theme_thumbs'); weaverii_setopt('_wii_hide_theme_thumbs', !$hide); } if (weaverii_submitted('save_options')) { echo '@@@@@@ SAVE OPTIONS @@@@@'; } }
function weaverii_process_options_admin_pro() { if (weaverii_submitted('backup_settings')) { $name = weaverii_savebackup(); if ($name !== false) { weaverii_save_msg(weaverii_t_('All current main and advanced options backed up in:') . ' "' . $name . '.w2b"'); } else { weaverii_save_msg(weaverii_t_('ERROR: Saving backup failed.')); } } if (weaverii_submitted('filesavetheme')) { $base = sanitize_file_name($_POST['savethemename']); if (weaverii_dev_mode()) { weaverii_setopt('wii_hide_old_weaver', 0); } $temp_url = weaverii_write_current_theme($base); if ($temp_url == '') { weaverii_save_msg(weaverii_t_('Invalid name supplied to save theme to file.')); } else { weaverii_save_msg(weaverii_t_("All current main and advanced options saved in ") . $temp_url); } } if (weaverii_submitted('restoretheme')) { $base = $_POST['wii_restorename']; $valid = validate_file($base); // make sure an ok file name $fn = weaverii_f_uploads_base_dir() . 'weaverii-subthemes/' . $base; if ($valid < 1 && weaverii_upload_theme($fn)) { $t = weaverii_getopt('wii_themename'); if ($t == '') { $t = weaverii_getopt('wii_subtheme'); } if ($t == '') { $t = 'Antique Ivory'; } /* did we save a theme? */ weaverii_setopt('wii_theme_filename', 'custom'); // we have a custom theme now... weaverii_save_msg(weaverii_t_("Weaver II theme restored from file: ") . $t); } else { weaverii_save_msg('<em style="color:red;">' . weaverii_t_('INVALID FILE NAME PROVIDED - Try Again') . "({$fn})" . '</em>'); } } if (weaverii_submitted('save_mobiletheme')) { weaverii_save_msg(weaverii_t_("Current settings saved in alternate Mobile View database entry.")); $weaverii_opts = get_option(apply_filters('weaver_options', 'weaverii_settings'), array()); $weaverii_opts['_wii_mobile_alt_theme'] = 'saved_mobile'; // force these two $weaverii_opts['_wii_sim_mobile'] = false; $weaverii_opts['_wii_inline_style'] = 'on'; weaverii_wpupdate_option('weaverii_settings_mobile', $weaverii_opts, 'save_mobiletheme'); $weaverii_pro_opts = get_option(apply_filters('weaver_options', 'weaverii_pro'), array()); weaverii_wpupdate_option('weaverii_pro_mobile', $weaverii_pro_opts, 'save_mobile_theme'); } if (weaverii_submitted('renametheme')) { $name = isset($_POST['wii_themename']) ? $_POST['wii_themename'] : ''; $desc = isset($_POST['wii_theme_description']) ? $_POST['wii_theme_description'] : ''; if ($name) { weaverii_setopt('wii_themename', $name); } if ($desc) { weaverii_setopt('wii_theme_description', $desc); } } if (weaverii_submitted('deletetheme')) { $myFile = isset($_POST['selectName']) ? $_POST['selectName'] : ''; $valid = validate_file($myFile); if ($valid < 1 && $myFile != "None") { weaverii_f_delete(weaverii_f_uploads_base_dir() . 'weaverii-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>'; } } }