summaryrefslogtreecommitdiff
path: root/inc/ZipLib.class.php
diff options
context:
space:
mode:
authorGuy Brand <gb@unistra.fr>2015-08-10 10:03:27 +0200
committerGuy Brand <gb@unistra.fr>2015-08-10 10:03:27 +0200
commit53a57d16b9c741bb44099fd93bf79efa06796341 (patch)
tree24a90a50afe9325926c8ebaa2ed90f9fa093e5b9 /inc/ZipLib.class.php
parentcf6e6645c31a9f185cef3fb9452fb188882ede47 (diff)
parenta060d9973e7c1d5051f2cc426937881826e4972e (diff)
downloadrpg-53a57d16b9c741bb44099fd93bf79efa06796341.tar.gz
rpg-53a57d16b9c741bb44099fd93bf79efa06796341.tar.bz2
Merge branch master into stable
Diffstat (limited to 'inc/ZipLib.class.php')
-rw-r--r--inc/ZipLib.class.php82
1 files changed, 77 insertions, 5 deletions
diff --git a/inc/ZipLib.class.php b/inc/ZipLib.class.php
index 918d38579..1358ca45e 100644
--- a/inc/ZipLib.class.php
+++ b/inc/ZipLib.class.php
@@ -6,6 +6,7 @@
* @link http://forum.maxg.info
*
* Modified for Dokuwiki
+ * @deprecated 2015-05-15 - use splitbrain\PHPArchive\Zip instead
* @author Christopher Smith <chris@jalakai.co.uk>
*/
class ZipLib {
@@ -16,6 +17,10 @@ class ZipLib {
var $old_offset = 0;
var $dirs = Array(".");
+ /**
+ * @param string $zip_name filename path to file
+ * @return array|int
+ */
function get_List($zip_name) {
$zip = @fopen($zip_name, 'rb');
if(!$zip) return(0);
@@ -24,10 +29,12 @@ class ZipLib {
@rewind($zip);
@fseek($zip, $centd['offset']);
+ $ret = array();
for ($i=0; $i<$centd['entries']; $i++) {
$header = $this->ReadCentralFileHeaders($zip);
$header['index'] = $i;
+ $info = array();
$info['filename'] = $header['filename'];
$info['stored_filename'] = $header['stored_filename'];
$info['size'] = $header['size'];
@@ -45,9 +52,15 @@ class ZipLib {
return $ret;
}
+ /**
+ * @param array $files array filled with array(string filename, string data)
+ * @param bool $compact
+ * @return array
+ */
function Add($files,$compact) {
if(!is_array($files[0])) $files=Array($files);
+ $ret = array();
for($i=0;$files[$i];$i++){
$fn = $files[$i];
if(!in_Array(dirname($fn[0]),$this->dirs))
@@ -60,6 +73,10 @@ class ZipLib {
/**
* Zips recursively the $folder directory, from the $basedir directory
+ *
+ * @param string $folder filename path to file
+ * @param string|null $basedir
+ * @param string|null $parent
*/
function Compress($folder, $basedir=null, $parent=null) {
$full_path = $basedir."/".$parent.$folder;
@@ -70,6 +87,7 @@ class ZipLib {
}
$dir = new DirectoryIterator($full_path);
foreach($dir as $file) {
+ /** @var DirectoryIterator $file */
if(!$file->isDot()) {
$filename = $file->getFilename();
if($file->isDir()) {
@@ -84,6 +102,8 @@ class ZipLib {
/**
* Returns the Zip file
+ *
+ * @return string
*/
function get_file() {
$data = implode('', $this -> datasec);
@@ -94,6 +114,9 @@ class ZipLib {
pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00";
}
+ /**
+ * @param string $name the name of the directory
+ */
function add_dir($name) {
$name = str_replace("\\", "/", $name);
$fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
@@ -117,8 +140,13 @@ class ZipLib {
/**
* Add a file named $name from a string $data
+ *
+ * @param string $data
+ * @param string $name filename
+ * @param bool $compact
+ * @return bool
*/
- function add_File($data, $name, $compact = 1) {
+ function add_File($data, $name, $compact = true) {
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->DosTime());
@@ -166,6 +194,9 @@ class ZipLib {
return true;
}
+ /**
+ * @return int
+ */
function DosTime() {
$timearray = getdate();
if ($timearray['year'] < 1980) {
@@ -186,10 +217,14 @@ class ZipLib {
/**
* Extract a zip file $zn to the $to directory
+ *
+ * @param string $zn filename
+ * @param string $to filename path to file
+ * @param array $index
+ * @return array|int
*/
function Extract ( $zn, $to, $index = Array(-1) ) {
if(!@is_dir($to)) $this->_mkdir($to);
- $ok = 0;
$zip = @fopen($zn,'rb');
if(!$zip) return(-1);
$cdir = $this->ReadCentralDir($zip,$zn);
@@ -203,6 +238,7 @@ class ZipLib {
return(-1);
}
+ $stat = array();
for ($i=0; $i<$cdir['entries']; $i++) {
@fseek($zip, $pos_entry);
$header = $this->ReadCentralFileHeaders($zip);
@@ -218,6 +254,11 @@ class ZipLib {
return $stat;
}
+ /**
+ * @param resource $zip
+ * @param array $header
+ * @return array
+ */
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);
@@ -254,6 +295,10 @@ class ZipLib {
return $header;
}
+ /**
+ * @param resource $zip
+ * @return array
+ */
function ReadCentralFileHeaders($zip){
$binary_data = fread($zip, 46);
$header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);
@@ -295,6 +340,11 @@ class ZipLib {
return $header;
}
+ /**
+ * @param resource $zip
+ * @param string $zip_name filename path to file
+ * @return array
+ */
function ReadCentralDir($zip,$zip_name) {
$size = filesize($zip_name);
if ($size < 277){
@@ -320,6 +370,7 @@ class ZipLib {
$data=unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size',
fread($zip, 18));
+ $centd = array();
if ($data['comment_size'] != 0){
$centd['comment'] = fread($zip, $data['comment_size']);
} else {
@@ -334,6 +385,12 @@ class ZipLib {
return $centd;
}
+ /**
+ * @param array $header
+ * @param string $to filename path to file
+ * @param resource $zip
+ * @return bool|int
+ */
function ExtractFile($header,$to,$zip) {
$header = $this->readfileheader($zip, $header);
@@ -414,14 +471,20 @@ class ZipLib {
* centralize mkdir calls and use dokuwiki io functions
*
* @author Christopher Smith <chris@jalakai.co.uk>
+ *
+ * @param string $d filename path to file
+ * @return bool|int|string
*/
function _mkdir($d) {
return io_mkdir_p($d);
}
-
+ /**
+ * @param string $zn
+ * @param string $name
+ * @return null|string
+ */
function ExtractStr($zn, $name) {
- $ok = 0;
$zip = @fopen($zn,'rb');
if(!$zip) return(null);
$cdir = $this->ReadCentralDir($zip,$zn);
@@ -445,8 +508,13 @@ class ZipLib {
return null;
}
+ /**
+ * @param array $header
+ * @param resource $zip
+ * @return null|string
+ */
function ExtractStrFile($header,$zip) {
- $hdr = $this->readfileheader($zip);
+ $hdr = $this->readfileheader($zip, $header);
$binary_data = '';
if (!($header['external']==0x41FF0010) && !($header['external']==16)) {
if ($header['compression']==0) {
@@ -484,6 +552,10 @@ class ZipLib {
return null;
}
+ /**
+ * @param string $val
+ * @return int|string
+ */
function _ret_bytes($val) {
$val = trim($val);
$last = $val{strlen($val)-1};