diff --git a/inc/ZipLib.class.php b/inc/ZipLib.class.php index cb1a26e751255a93ea3d9aadb0b5a7de18ea7bea..a1d266673bc51f594995b5da2b3d786f9bc1dcc4 100644 --- a/inc/ZipLib.class.php +++ b/inc/ZipLib.class.php @@ -53,6 +53,34 @@ class ZipLib return $ret; } + /** + * Zips recursively the $folder directory, from the $basedir directory + */ + function Compress($folder, $basedir=null, $parent=null) + { + $full_path = $basedir."/".$parent.$folder; + $zip_path = $parent.$folder; + if ($zip_path) { + $zip_path .= "/"; + $this->add_dir($zip_path); + } + $dir = new DirectoryIterator($full_path); + foreach($dir as $file) { + if(!$file->isDot()) { + $filename = $file->getFilename(); + if($file->isDir()) { + $this->Compress($filename, $basedir, $zip_path); + } else { + $content = join('', file($full_path.'/'.$filename)); + $this->add_File($content, $zip_path.$filename); + } + } + } + } + + /** + * Returns the Zip file + */ function get_file() { $data = implode('', $this -> datasec); @@ -85,6 +113,9 @@ class ZipLib $this -> dirs[] = $name; } + /** + * Add a file named $name from a string $data + */ function add_File($data, $name, $compact = 1) { $name = str_replace('\\', '/', $name); @@ -138,6 +169,9 @@ class ZipLib ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); } + /** + * Extract a zip file $zn to the $to directory + */ function Extract ( $zn, $to, $index = Array(-1) ) { if(!@is_dir($to)) $this->_mkdir($to); @@ -147,7 +181,7 @@ class ZipLib $pos_entry = $cdir['offset']; if(!is_array($index)){ $index = array($index); } - for($i=0; $index[$i];$i++){ + for($i=0; isset($index[$i]);$i++){ if(intval($index[$i])!=$index[$i]||$index[$i]>$cdir['entries']) return(-1); } @@ -166,7 +200,7 @@ class ZipLib return $stat; } - function ReadFileHeader($zip) + function ReadFileHeader($zip, $header) { $binary_data = fread($zip, 30); $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data); @@ -176,9 +210,11 @@ class ZipLib $header['extra'] = fread($zip, $data['extra_len']); } else { $header['extra'] = ''; } - $header['compression'] = $data['compression'];$header['size'] = $data['size']; - $header['compressed_size'] = $data['compressed_size']; - $header['crc'] = $data['crc']; $header['flag'] = $data['flag']; + $header['compression'] = $data['compression']; + foreach (array('size','compressed_size','crc') as $hd) { // On ODT files, these headers are 0. Keep the previous value. + if ($data[$hd] != 0) $header[$hd] = $data[$hd]; + } + $header['flag'] = $data['flag']; $header['mdate'] = $data['mdate'];$header['mtime'] = $data['mtime']; if ($header['mdate'] && $header['mtime']){ @@ -258,7 +294,7 @@ class ZipLib function ExtractFile($header,$to,$zip) { - $header = $this->readfileheader($zip); + $header = $this->readfileheader($zip, $header); if(substr($to,-1)!="/") $to.="/"; if(substr($header['filename'],-1)=="/") @@ -276,7 +312,7 @@ class ZipLib // } if (!$this->_mkdir($to.dirname($header['filename']))) return (-1); //--CS - if (!($header['external']==0x41FF0010)&&!($header['external']==16)) + if (!array_key_exists("external", $header) || (!($header['external']==0x41FF0010)&&!($header['external']==16))) { if ($header['compression']==0) {