function wowslider_import($zip_file = false, $update = 0, $delete = true) { global $wp_filesystem; static $file = ''; if ($zip_file === 'file') { return $file; } $path = wowslider_upload_dir() . 'import/'; $status = true; if (!$zip_file) { $list = WOWSlider_Helpers::filesystem_dirlist($path); foreach ($list as $name => $v) { if ($v['type'] == 'f' && strtolower(substr($name, -4)) == '.zip') { $zip_file = $path . $name; $file = $name; break; } } if (!$zip_file) { return __('Files to import not found.', 'wowslider'); } } $path .= md5(microtime()) . '/'; @mkdir($path); add_filter('filesystem_method', create_function('', 'return "direct";')); WP_Filesystem(); $unzip = unzip_file($zip_file, $path); $install = $path . 'wowslider/install/'; if ($delete) { WOWSlider_Helpers::filesystem_delete($zip_file); } if (is_object($unzip)) { $status = __('Wrong .zip file.', 'wowslider'); } else { $status = wowslider_add(is_dir($install) ? $install : $path . 'import/', $update); $install = substr($install, 0, -8); if (is_dir($install) && WOWSlider_Helpers::is_new_plugin($install . 'wowslider.php')) { foreach (array('', 'data/') as $dir) { if ($list = WOWSlider_Helpers::filesystem_dirlist($install . $dir)) { foreach ($list as $item) { if ($item['type'] != 'f') { continue; } WOWSlider_Helpers::filesystem_copy($install . $dir . $item['name'], WOWSLIDER_PLUGIN_PATH . $dir . $item['name'], true); } } } } } WOWSlider_Helpers::filesystem_delete($path, true); return $status; }
function wowslider_add_new_from_plugins($source) { global $wp_filesystem; $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : ''; if (substr($source, -10) == 'wowslider/' && !in_array($action, array('update-selected', 'upgrade-plugin'))) { $message = $location = ''; $uploads = wp_upload_dir(); if (!$wp_filesystem || !is_object($wp_filesystem)) { WP_Filesystem(); } $file = $uploads['path'] . '/' . basename(substr($source, 0, -10)) . '.zip'; @$wp_filesystem->chmod($source, 0777, true); $source = WP_CONTENT_DIR . '/' . substr($source, strlen($wp_filesystem->wp_content_dir())); if (!is_dir($source . 'install/')) { $location = admin_url('admin.php?page=wowslider-add-new&error=1&message=' . urlencode(__('Wrong slider.', 'wowslider'))); $message = '<div id="message" class="error"><p>' . htmlspecialchars(__('Wrong slider.', 'wowslider')) . '</p></div>'; } else { if (($status = wowslider_add($source . 'install/')) !== true) { $location = admin_url('admin.php?page=wowslider-add-new&error=1&message=' . urlencode($status)); $message = '<div id="message" class="error"><p>' . htmlspecialchars($status) . '</p></div>'; } else { $location = admin_url('admin.php?page=wowslider-add-new&message=&slider=' . wowslider_add()); $message = '<div id="message" class="updated"><p>' . __('Slider added! To add it on the page use the shortcode:', 'wowslider') . ' <strong><code>[wowslider id="' . wowslider_add() . '"]</code></strong>. ' . str_replace('all sliders', '<a href="' . admin_url('admin.php?page=wowslider/admin.php') . '">all sliders</a>', __('See all sliders.', 'wowslider')) . '</p></div>'; } } if (WOWSlider_Helpers::is_new_plugin($source . 'wowslider.php')) { foreach (array('', 'data/') as $dir) { if ($list = WOWSlider_Helpers::filesystem_dirlist($source . $dir)) { foreach ($list as $item) { if ($item['type'] != 'f') { continue; } WOWSlider_Helpers::filesystem_copy($source . $dir . $item['name'], WOWSLIDER_PLUGIN_PATH . $dir . $item['name'], true); } } } } echo ' <script type="text/javascript"> //<![CDATA[ (function(){ var func = function(){ location.href = "' . $location . '"; }; if (typeof jQuery != "undefined") jQuery(document).ready(func); else { if (window.addEventListener) window.addEventListener("load", func, false); else if (window.attachEvent) window.attachEvent("onload", func); else setTimeout(func, 2500); } })(); //]]> </script> <noscript>' . $message . '</noscript>'; include ABSPATH . 'wp-admin/admin-footer.php'; if (file_exists($file)) { @unlink($file); } exit; } return $source; }
function wowslider_import($zip_file = false, $update = 0, $delete = true) { global $wp_filesystem; static $file = ''; if ($zip_file === 'file') { return $file; } if (!$wp_filesystem || !is_object($wp_filesystem)) { WP_Filesystem(); } $path = WOWSLIDER_PLUGIN_PATH . 'import/'; $status = true; if (!$zip_file) { $list = $wp_filesystem->dirlist($path); foreach ($list as $name => $v) { if ($v['type'] == 'f' && strtolower(substr($name, -4)) == '.zip') { $zip_file = $path . $name; $file = $name; break; } } if (!$zip_file) { return __('Files to import not found.', 'wowslider'); } } $path .= md5(microtime()) . '/'; $wp_filesystem->mkdir($path); $unzip = unzip_file($zip_file, $path); $install = $path . 'wowslider/install/'; if ($delete) { $wp_filesystem->delete($zip_file); } if (is_object($unzip)) { $status = __('Wrong .zip file.', 'wowslider'); } else { $status = wowslider_add(is_dir($install) ? $install : $path . 'import/', $update); $install = substr($install, 0, -8); if (is_dir($install)) { foreach (array('', 'data/') as $dir) { if ($list = $wp_filesystem->dirlist($install . $dir)) { foreach ($list as $item) { if ($item['type'] != 'f') { continue; } $wp_filesystem->copy($install . $dir . $item['name'], WOWSLIDER_PLUGIN_PATH . $dir . $item['name'], true); } } } } } $wp_filesystem->delete($path, true); return $status; }
function wowslider_add_new() { $tab = isset($_GET['tab']) && $_GET['tab'] == 'import' ? 'import' : 'upload'; $verif = isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'wowslider-add-new'); if (isset($_GET['message'])) { if (isset($_GET['error'])) { echo '<div id="message" class="error"><p>' . htmlspecialchars(urldecode($_GET['message'])) . '</p></div>'; } else { if (isset($_GET['slider'])) { if ($_GET['message']) { echo '<div id="message" class="updated"><p>' . str_replace('%s', '<strong>./import/' . htmlspecialchars(urldecode($_GET['message'])) . '</strong>', __('Slider imported from file %s! To add it on the page use the shortcode:', 'wowslider')) . ' <strong><code>[wowslider id="' . (int) $_GET['slider'] . '"]</code></strong></p></div>'; } else { echo '<div id="message" class="updated"><p>' . __('Slider added! To add it on the page use the shortcode:', 'wowslider') . ' <strong><code>[wowslider id="' . (int) $_GET['slider'] . '"]</code></strong></p></div>'; } } } } if ($tab == 'upload' && isset($_FILES['sliderzip']) && $verif) { $file = wp_handle_upload($_FILES['sliderzip'], array('test_form' => false, 'mimes' => array('zip' => 'application/zip'))); if (isset($file['error'])) { exit(wp_redirect(admin_url('admin.php?page=wowslider-add-new&error=1&message=' . urlencode($file['error'])))); } else { if (($status = wowslider_add($file['file'])) !== true) { exit(wp_redirect(admin_url('admin.php?page=wowslider-add-new&error=1&message=' . urlencode($status)))); } else { exit(wp_redirect(admin_url('admin.php?page=wowslider-add-new&message=&slider=' . wowslider_add()))); } } } else { if ($tab == 'import' && $verif) { if (($status = wowslider_import()) !== true) { exit(wp_redirect(admin_url('admin.php?page=wowslider-add-new&tab=import&error=1&message=' . urlencode($status)))); } else { exit(wp_redirect(admin_url('admin.php?page=wowslider-add-new&tab=import&message=' . urlencode(wowslider_import('file')) . '&slider=' . wowslider_add()))); } } } ?> <div class="wrap"> <div id="icon-wowslider" class="icon32"><br /></div> <h2><?php _e('Add New Slider', 'wowslider'); ?> </h2> <ul class="subsubsub"> <li><a href="<?php echo admin_url('admin.php?page=wowslider-add-new'); ?> "<?php if ($tab == 'upload') { echo ' class="current"'; } ?> ><?php _e('Upload', 'wowslider'); ?> </a> |</li> <li><a href="<?php echo admin_url('admin.php?page=wowslider-add-new&tab=import'); ?> "<?php if ($tab == 'import') { echo ' class="current"'; } ?> ><?php _e('Import from Folder', 'wowslider'); ?> </a></li> </ul><br class="clear" /> <? if ($tab == 'upload'): ?> <h4><?php _e('Add a slider in .zip format', 'wowslider'); ?> </h4> <p class="install-help"><?php echo str_replace('WOW Slider', '<a href="http://wowslider.com/" target="_blank">WOW Slider</a>', __('Create a slider with WOW Slider and upload it here.', 'wowslider')); ?> </p> <form method="post" enctype="multipart/form-data" action="<?php echo self_admin_url('admin.php?page=wowslider-add-new&noheader=1'); ?> "> <?php wp_nonce_field('wowslider-add-new'); ?> <label class="screen-reader-text" for="sliderzip"><?php _e('Slider zip file', 'wowslider'); ?> </label> <input type="file" id="sliderzip" name="sliderzip" /> <input type="submit" class="button" value="<?php esc_attr_e('Add Now', 'wowslider'); ?> " /> </form> <? else: ?> <h4><?php _e('Add a slider in .zip format from folder', 'wowslider'); ?> </h4> <p class="install-help"><?php echo str_replace('WOW Slider', '<a href="http://wowslider.com/" target="_blank">WOW Slider</a>', __('Create a slider with WOW Slider and copy to folder:', 'wowslider')); ?> "./wp-content/plugins/wow-slider-wordpress-image-slider-plugin/import/".</p> <br /> <form method="post" action="<?php echo self_admin_url('admin.php?page=wowslider-add-new&tab=import&noheader=1'); ?> "> <?php wp_nonce_field('wowslider-add-new'); ?> <input type="submit" class="button" value="<?php esc_attr_e('Import from Folder', 'wowslider'); ?> " /> </form> <? endif; ?> </div> <?php }