From 0ea392937fd9e0a135e16cc7a645e4068f456f5d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 25 Dec 2011 18:48:46 +0200 Subject: Improve the Zip library --- system/libraries/Zip.php | 70 +++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 52f1bc3d0..3c66c6b3a 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,13 +1,13 @@ -now); - - $time['file_mtime'] = ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2; - $time['file_mdate'] = (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday']; + + $time = array( + 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, + 'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday'] + ); return $time; } @@ -117,7 +119,7 @@ class CI_Zip { * @param string the directory name * @return void */ - function _add_dir($dir, $file_mtime, $file_mdate) + private function _add_dir($dir, $file_mtime, $file_mdate) { $dir = str_replace("\\", "/", $dir); @@ -170,21 +172,19 @@ class CI_Zip { * @param string * @return void */ - function add_data($filepath, $data = NULL) + public function add_data($filepath, $data = NULL) { if (is_array($filepath)) { foreach ($filepath as $path => $data) { $file_data = $this->_get_mod_time($path); - $this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } else { $file_data = $this->_get_mod_time($filepath); - $this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']); } } @@ -199,7 +199,7 @@ class CI_Zip { * @param string the data to be encoded * @return void */ - function _add_data($filepath, $data, $file_mtime, $file_mdate) + private function _add_data($filepath, $data, $file_mtime, $file_mdate) { $filepath = str_replace("\\", "/", $filepath); @@ -251,7 +251,7 @@ class CI_Zip { * @access public * @return bool */ - function read_file($path, $preserve_filepath = FALSE) + public function read_file($path, $preserve_filepath = FALSE) { if ( ! file_exists($path)) { @@ -286,7 +286,7 @@ class CI_Zip { * @param string path to source * @return bool */ - function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) + public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { if ( ! $fp = @opendir($path)) { @@ -301,7 +301,7 @@ class CI_Zip { while (FALSE !== ($file = readdir($fp))) { - if (substr($file, 0, 1) == '.') + if ($file[0] === '.') { continue; } @@ -337,7 +337,7 @@ class CI_Zip { * @access public * @return binary string */ - function get_zip() + public function get_zip() { // Is there any data to return? if ($this->entries == 0) @@ -345,15 +345,13 @@ class CI_Zip { return FALSE; } - $zip_data = $this->zipdata; - $zip_data .= $this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00"; - $zip_data .= pack('v', $this->entries); // total # of entries "on this disk" - $zip_data .= pack('v', $this->entries); // total # of entries overall - $zip_data .= pack('V', strlen($this->directory)); // size of central dir - $zip_data .= pack('V', strlen($this->zipdata)); // offset to start of central dir - $zip_data .= "\x00\x00"; // .zip file comment length - - return $zip_data; + return $this->zipdata + . $this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00" + . pack('v', $this->entries) // total # of entries "on this disk" + . pack('v', $this->entries) // total # of entries overall + . pack('V', strlen($this->directory)) // size of central dir + . pack('V', strlen($this->zipdata)) // offset to start of central dir + . "\x00\x00"; // .zip file comment length } // -------------------------------------------------------------------- @@ -367,7 +365,7 @@ class CI_Zip { * @param string the file name * @return bool */ - function archive($filepath) + public function archive($filepath) { if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) { @@ -392,7 +390,7 @@ class CI_Zip { * @param string the data to be encoded * @return bool */ - function download($filename = 'backup.zip') + public function download($filename = 'backup.zip') { if ( ! preg_match("|.+?\.zip$|", $filename)) { @@ -420,7 +418,7 @@ class CI_Zip { * @access public * @return void */ - function clear_data() + public function clear_data() { $this->zipdata = ''; $this->directory = ''; @@ -432,4 +430,4 @@ class CI_Zip { } /* End of file Zip.php */ -/* Location: ./system/libraries/Zip.php */ \ No newline at end of file +/* Location: ./system/libraries/Zip.php */ -- cgit v1.2.3-24-g4f1b