Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}