function filesystem_dirlist($path, $include_hidden = true, $recursive = false) { if (is_file($path)) { $limit_file = basename($path); $path = dirname($path); } else { $limit_file = false; } if (!is_dir($path)) { return false; } $dir = @dir($path); if (!$dir) { return false; } $ret = array(); while (false !== ($entry = $dir->read())) { $struc = array(); $struc['name'] = $entry; if ('.' == $struc['name'] || '..' == $struc['name']) { continue; } if (!$include_hidden && '.' == $struc['name'][0]) { continue; } if ($limit_file && $struc['name'] != $limit_file) { continue; } $struc['type'] = is_dir($path . '/' . $entry) ? 'd' : 'f'; if ('d' == $struc['type']) { if ($recursive) { $struc['files'] = WOWSlider_Helpers::filesystem_dirlist($path . '/' . $struc['name'], $include_hidden, $recursive); } else { $struc['files'] = array(); } } $ret[$struc['name']] = $struc; } $dir->close(); unset($dir); return $ret; }
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_old_version() { $dir = WOWSLIDER_PLUGIN_PATH . 'sliders/'; if (is_dir($dir)) { require_once ABSPATH . 'wp-admin/includes/file.php'; if ($list = WOWSlider_Helpers::filesystem_dirlist($dir)) { foreach ($list as $item) { WOWSlider_Helpers::filesystem_move($source . $dir . $item['name'], wowslider_upload_dir() . $item['name']); } } WOWSlider_Helpers::filesystem_delete($dir, true); } }