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_update_mods($from, $to) { /* update theme_mods_$from to theme_mods_$to, return true if changed Values of interest: 'header_image' : full http:// path to header image. e.g. "http://wii.me/wp-content/themes/weaver/images/headers/mum.jpg" 'random-uploaded-image' : set if true, not set otherwise (if set, header_image set to '') 'background_image': full path to bg image. e.g. "http://wii.me/wp-content/uploads/2011/10/Kokopell1-82x150.png" 'background_repeat': repeat string e.g., "repeat" 'background_position_x': indicates left, center, right 'background_attachment': indicates scroll/fixed 'background_color': color !! need to do this once only. */ $changed = false; if (($from_mods = get_option("theme_mods_{$from}")) !== false) { // some old mods exist to change $to_mods = get_option("theme_mods_{$to}"); // get current values if ($to_mods === false) { // the to doesn't exist, so we might not do anything if ($from == WEAVER_SLUG) { // we're converting from old weaver, so we need to do this $to_mods = array(); } else { // there's nothing to do (e.g., Weaver II Pro not installed) return false; } } $changed = true; $header = isset($from_mods['header_image']) ? $from_mods['header_image'] : false; if ($header !== false) { // need to see if a default header, or custom. $newpath = str_replace($from, $to, $header); // change to current theme if a default image if (weaverii_f_exists(untrailingslashit(ABSPATH) . parse_url($newpath, PHP_URL_PATH))) { $to_mods['header_image'] = $newpath; } // can still find the image, so use it } if (isset($from_mods['random-uploaded-image'])) { $to_mods['random-uploaded-image'] = $from_mods['random-uploaded-image']; } if (isset($from_mods['background_image'])) { $to_mods['background_image'] = $from_mods['background_image']; } if (isset($from_mods['background_repeat'])) { $to_mods['background_repeat'] = $from_mods['background_repeat']; } if (isset($from_mods['background_position_x'])) { $to_mods['background_position_x'] = $from_mods['background_position_x']; } if (isset($from_mods['background_attachment'])) { $to_mods['background_attachment'] = $from_mods['background_attachment']; } if (isset($from_mods['background_color'])) { $to_mods['background_color'] = $from_mods['background_color']; } } if ($changed) { update_option("theme_mods_{$to}", $to_mods); } return $changed; }
function weaverii_use_inline_css($css_file) { return weaverii_getopt_checked('_wii_inline_style') || !weaverii_f_file_access_available() || !weaverii_f_exists($css_file) || weaverii_dev_mode(); }
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); }