Microweber\Utils\Unzip::old_____extract PHP Метод

old_____extract() публичный Метод

public old_____extract ( $zip_file, $target_dir = null, $preserve_filepath = true )
    public function old_____extract($zip_file, $target_dir = null, $preserve_filepath = true)
    {
        $this->_zip_file = $zip_file;
        $this->_target_dir = $target_dir ? $target_dir : dirname($this->_zip_file);
        if (function_exists('zip_open')) {
            $is_any = $this->native_unzip($zip_file, $target_dir, $preserve_filepath);
            if (!empty($is_any)) {
                return $is_any;
            }
        }
        if (function_exists('gzinflate')) {
            if (!($files = $this->_list_files())) {
                $this->set_error('ZIP folder was empty.');
                return false;
            }
            $file_locations = array();
            foreach ($files as $file => $trash) {
                $dirname = pathinfo($file, PATHINFO_DIRNAME);
                $extension = pathinfo($file, PATHINFO_EXTENSION);
                $dirname = str_replace('\\/', '/', $dirname);
                $folders = explode('/', $dirname);
                $out_dn = $this->_target_dir . '/' . $dirname;
                $out_dn = str_replace('\\/', '/', $out_dn);
                // Skip stuff in stupid folders
                if (in_array(current($folders), $this->_skip_dirs)) {
                    continue;
                }
                // Skip any files that are not allowed
                if (is_array($this->_allow_extensions) && $extension && !in_array($extension, $this->_allow_extensions)) {
                    continue;
                }
                if (!is_dir($out_dn) && $preserve_filepath) {
                    $str = '';
                    foreach ($folders as $folder) {
                        $str = $str ? $str . '/' . $folder : $folder;
                        if (!is_dir($this->_target_dir . '/' . $str)) {
                            $this->set_debug('Creating folder: ' . $this->_target_dir . '/' . $str);
                            if (!@mkdir_recursive($this->_target_dir . '/' . $str)) {
                                $this->set_error('Desitnation path is not writable.');
                                return false;
                            }
                            // Apply chmod if configured to do so
                            $this->apply_chmod && chmod($this->_target_dir . '/' . $str, $this->apply_chmod);
                        }
                    }
                }
                if (substr($file, -1, 1) == '/') {
                    continue;
                }
                $file_locations[] = $file_location = $this->_target_dir . '/' . ($preserve_filepath ? $file : basename($file));
                $this->_extract_file($file, $file_location, $this->underscore_case);
                // Skip stuff in stupid folders
                if (in_array(current($folders), $this->_skip_dirs)) {
                    continue;
                }
                // Skip any files that are not allowed
                if (is_array($this->_allow_extensions) && $extension && !in_array($extension, $this->_allow_extensions)) {
                    continue;
                }
                if (!is_dir($out_dn) && $preserve_filepath) {
                    $str = '';
                    foreach ($folders as $folder) {
                        $str = $str ? $str . '/' . $folder : $folder;
                        if (!is_dir($this->_target_dir . '/' . $str)) {
                            $this->set_debug('Creating folder: ' . $this->_target_dir . '/' . $str);
                            if (!@mkdir_recursive($this->_target_dir . '/' . $str)) {
                                $this->set_error('Desitnation path is not writable.');
                                $resp = array('error' => 'Error with the unzip! Desitnation path is not writable.');
                                return $resp;
                                return false;
                            }
                            // Apply chmod if configured to do so
                            $this->apply_chmod && chmod($this->_target_dir . '/' . $str, $this->apply_chmod);
                        }
                    }
                }
                if (substr($file, -1, 1) == '/') {
                    continue;
                }
                $file_locations[] = $file_location = $this->_target_dir . '/' . ($preserve_filepath ? $file : basename($file));
                $this->_extract_file($file, $file_location, $this->underscore_case);
            }
            return $file_locations;
        }
        $resp = array('error' => 'There was an error with the unzip');
        return $resp;
    }