From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/libraries/Zip.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 666327d5c..9101eecb4 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -27,7 +39,7 @@ * @package CodeIgniter * @subpackage Libraries * @category Encryption - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/zip.html */ class CI_Zip { -- cgit v1.2.3-24-g4f1b From 29130086c3b8df146c8c599f5ba47038efa10faf Mon Sep 17 00:00:00 2001 From: Thomas Traub Date: Fri, 4 Nov 2011 14:16:43 +0100 Subject: Add file exists check to prevent stat failed error warnings in the log These occur when creating .zips by passing data and creating an artificial fs structure inside the .zip --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 9101eecb4..8e4357051 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -100,7 +100,7 @@ class CI_Zip { function _get_mod_time($dir) { // filemtime() will return false, but it does raise an error. - $date = (@filemtime($dir)) ? filemtime($dir) : getdate($this->now); + $date = (file_exists($dir) && @filemtime($dir)) ? filemtime($dir) : getdate($this->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']; -- cgit v1.2.3-24-g4f1b From 98f85b177d6ebf6dbc3a2ec8313ef738eca2fbf2 Mon Sep 17 00:00:00 2001 From: Thomas Traub Date: Mon, 5 Dec 2011 14:58:29 +0100 Subject: Took out the now unnecessary error suppression --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 8e4357051..ef6c3e530 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -99,8 +99,8 @@ class CI_Zip { */ function _get_mod_time($dir) { - // filemtime() will return false, but it does raise an error. - $date = (file_exists($dir) && @filemtime($dir)) ? filemtime($dir) : getdate($this->now); + // filemtime() may return false, but raises an error for non-existing files + $date = (file_exists($dir) && filemtime($dir)) ? filemtime($dir) : getdate($this->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']; -- cgit v1.2.3-24-g4f1b From 7fcfbda4cd72d4198c9b45ac13bcbd47bf067b81 Mon Sep 17 00:00:00 2001 From: Thomas Traub Date: Mon, 5 Dec 2011 17:08:50 +0100 Subject: Update system/libraries/Zip.php --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index ef6c3e530..2fc30e469 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -100,7 +100,7 @@ class CI_Zip { function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files - $date = (file_exists($dir) && filemtime($dir)) ? filemtime($dir) : getdate($this->now); + $date = (file_exists($dir) && $filemtime = filemtime($dir)) ? $filemtime : getdate($this->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']; -- cgit v1.2.3-24-g4f1b From dba657efda6e057dc0c741dc449937c8ba5a029a Mon Sep 17 00:00:00 2001 From: Thomas Traub Date: Tue, 6 Dec 2011 06:30:37 +0100 Subject: Update system/libraries/Zip.php --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2fc30e469..52f1bc3d0 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -100,8 +100,8 @@ class CI_Zip { function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files - $date = (file_exists($dir) && $filemtime = filemtime($dir)) ? $filemtime : getdate($this->now); - + $date = (file_exists($dir)) ? filemtime($dir): getdate($this->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']; -- cgit v1.2.3-24-g4f1b 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 From b9535c80cc389952912f456f2c68665398b71494 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Dec 2011 16:21:17 +0200 Subject: Update with suggestions from gaker & dixy --- system/libraries/Zip.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 3c66c6b3a..7a97914c0 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -97,7 +97,7 @@ class CI_Zip { * @param string path to file * @return array filemtime/filemdate */ - private function _get_mod_time($dir) + protected function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files $date = (file_exists($dir)) ? filemtime($dir): getdate($this->now); @@ -115,11 +115,11 @@ class CI_Zip { /** * Add Directory * - * @access private + * @access protected * @param string the directory name * @return void */ - private function _add_dir($dir, $file_mtime, $file_mdate) + protected function _add_dir($dir, $file_mtime, $file_mdate) { $dir = str_replace("\\", "/", $dir); @@ -194,12 +194,12 @@ class CI_Zip { /** * Add Data to Zip * - * @access private + * @access protected * @param string the file name/path * @param string the data to be encoded * @return void */ - private function _add_data($filepath, $data, $file_mtime, $file_mdate) + protected function _add_data($filepath, $data, $file_mtime, $file_mdate) { $filepath = str_replace("\\", "/", $filepath); @@ -288,6 +288,8 @@ class CI_Zip { */ public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { + $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; + if ( ! $fp = @opendir($path)) { return FALSE; @@ -425,6 +427,7 @@ class CI_Zip { $this->entries = 0; $this->file_num = 0; $this->offset = 0; + return $this; } } -- cgit v1.2.3-24-g4f1b From b1f3f57c65083904fe899753043419a25b073898 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Dec 2011 02:38:39 +0200 Subject: Remove access lines from method descriptions --- system/libraries/Zip.php | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 7a97914c0..d60b99462 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -68,7 +68,6 @@ class CI_Zip { * * Lets you add a virtual directory into which you can place files. * - * @access public * @param mixed the directory name. Can be string or array * @return void */ @@ -115,7 +114,6 @@ class CI_Zip { /** * Add Directory * - * @access protected * @param string the directory name * @return void */ @@ -167,7 +165,6 @@ class CI_Zip { * in the filename it will be placed within a directory. Make * sure you use add_dir() first to create the folder. * - * @access public * @param mixed * @param string * @return void @@ -194,7 +191,6 @@ class CI_Zip { /** * Add Data to Zip * - * @access protected * @param string the file name/path * @param string the data to be encoded * @return void @@ -248,7 +244,6 @@ class CI_Zip { /** * Read the contents of a file and add it to the zip * - * @access public * @return bool */ public function read_file($path, $preserve_filepath = FALSE) @@ -282,7 +277,6 @@ class CI_Zip { * sub-folders) and creates a zip based on it. Whatever directory structure * is in the original file path will be recreated in the zip file. * - * @access public * @param string path to source * @return bool */ @@ -336,7 +330,6 @@ class CI_Zip { /** * Get the Zip file * - * @access public * @return binary string */ public function get_zip() @@ -363,7 +356,6 @@ class CI_Zip { * * Lets you write a file * - * @access public * @param string the file name * @return bool */ @@ -387,7 +379,6 @@ class CI_Zip { /** * Download * - * @access public * @param string the file name * @param string the data to be encoded * @return bool @@ -417,7 +408,6 @@ class CI_Zip { * Lets you clear current zip data. Useful if you need to create * multiple zips with different data. * - * @access public * @return void */ public function clear_data() -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 52f1bc3d0..50e84920e 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From cfbd15b6d052c1cb93fb5fa08e35fa7d3c6c7751 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 8 Jan 2012 06:41:41 +0200 Subject: Some more misc. stuff --- system/libraries/Zip.php | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index d60b99462..2ed79f0e3 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -51,13 +51,9 @@ class CI_Zip { public $offset = 0; public $now; - /** - * Constructor - */ public function __construct() { - log_message('debug', "Zip Compression Class Initialized"); - + log_message('debug', 'Zip Compression Class Initialized'); $this->now = time(); } @@ -75,13 +71,12 @@ class CI_Zip { { foreach ((array)$directory as $dir) { - if ( ! preg_match("|.+/$|", $dir)) + if ( ! preg_match('|.+/$|', $dir)) { $dir .= '/'; } $dir_time = $this->_get_mod_time($dir); - $this->_add_dir($dir, $dir_time['file_mtime'], $dir_time['file_mdate']); } } @@ -101,12 +96,10 @@ class CI_Zip { // filemtime() may return false, but raises an error for non-existing files $date = (file_exists($dir)) ? filemtime($dir): getdate($this->now); - $time = array( + return 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; } // -------------------------------------------------------------------- @@ -197,13 +190,11 @@ class CI_Zip { */ protected function _add_data($filepath, $data, $file_mtime, $file_mdate) { - $filepath = str_replace("\\", "/", $filepath); + $filepath = str_replace('\\', '/', $filepath); $uncompressed_size = strlen($data); $crc32 = crc32($data); - - $gzdata = gzcompress($data); - $gzdata = substr($gzdata, 2, -4); + $gzdata = substr(gzcompress($data), 2, -4); $compressed_size = strlen($gzdata); $this->zipdata .= @@ -255,16 +246,16 @@ class CI_Zip { if (FALSE !== ($data = file_get_contents($path))) { - $name = str_replace("\\", "/", $path); - + $name = str_replace('\\', '/', $path); if ($preserve_filepath === FALSE) { - $name = preg_replace("|.*/(.+)|", "\\1", $name); + $name = preg_replace('|.*/(.+)|', '\\1', $name); } $this->add_data($name, $data); return TRUE; } + return FALSE; } @@ -282,7 +273,7 @@ class CI_Zip { */ public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { - $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; + $path = rtrim($path, '/\\').'/'; if ( ! $fp = @opendir($path)) { @@ -304,14 +295,13 @@ class CI_Zip { if (@is_dir($path.$file)) { - $this->read_dir($path.$file."/", $preserve_filepath, $root_path); + $this->read_dir($path.$file.'/', $preserve_filepath, $root_path); } else { if (FALSE !== ($data = file_get_contents($path.$file))) { - $name = str_replace("\\", "/", $path); - + $name = str_replace('\\', '/', $path); if ($preserve_filepath === FALSE) { $name = str_replace($root_path, '', $name); @@ -335,7 +325,7 @@ class CI_Zip { public function get_zip() { // Is there any data to return? - if ($this->entries == 0) + if ($this->entries === 0) { return FALSE; } @@ -392,9 +382,7 @@ class CI_Zip { $CI =& get_instance(); $CI->load->helper('download'); - $get_zip = $this->get_zip(); - $zip_content =& $get_zip; force_download($filename, $zip_content); -- cgit v1.2.3-24-g4f1b From e34f1a75ca78825bcf96c4344e01de412f6113bf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 10 Jan 2012 22:41:52 +0200 Subject: Some quotes --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2ed79f0e3..dbcdb2d97 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -112,7 +112,7 @@ class CI_Zip { */ protected function _add_dir($dir, $file_mtime, $file_mdate) { - $dir = str_replace("\\", "/", $dir); + $dir = str_replace('\\', '/', $dir); $this->zipdata .= "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00" @@ -375,7 +375,7 @@ class CI_Zip { */ public function download($filename = 'backup.zip') { - if ( ! preg_match("|.+?\.zip$|", $filename)) + if ( ! preg_match('|.+?\.zip$|', $filename)) { $filename .= '.zip'; } -- cgit v1.2.3-24-g4f1b From 16d806605993305efe9c264b3ae8383ec92ae5ae Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 20 Jan 2012 13:26:49 +0200 Subject: Some more cleaning --- system/libraries/Zip.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index dbcdb2d97..85a0b5ce9 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Zip Compression Class * @@ -265,7 +263,7 @@ class CI_Zip { * Read a directory and add it to the zip. * * This function recursively reads a folder and everything it contains (including - * sub-folders) and creates a zip based on it. Whatever directory structure + * sub-folders) and creates a zip based on it. Whatever directory structure * is in the original file path will be recreated in the zip file. * * @param string path to source @@ -297,18 +295,14 @@ class CI_Zip { { $this->read_dir($path.$file.'/', $preserve_filepath, $root_path); } - else + elseif (FALSE !== ($data = file_get_contents($path.$file))) { - if (FALSE !== ($data = file_get_contents($path.$file))) + $name = str_replace('\\', '/', $path); + if ($preserve_filepath === FALSE) { - $name = str_replace('\\', '/', $path); - if ($preserve_filepath === FALSE) - { - $name = str_replace($root_path, '', $name); - } - - $this->add_data($name.$file, $data); + $name = str_replace($root_path, '', $name); } + $this->add_data($name.$file, $data); } } @@ -320,7 +314,7 @@ class CI_Zip { /** * Get the Zip file * - * @return binary string + * @return string (binary encoded) */ public function get_zip() { @@ -393,10 +387,10 @@ class CI_Zip { /** * Initialize Data * - * Lets you clear current zip data. Useful if you need to create + * Lets you clear current zip data. Useful if you need to create * multiple zips with different data. * - * @return void + * @return object */ public function clear_data() { -- cgit v1.2.3-24-g4f1b From 1841e6b472820deb2dfe4d43c675211eeabbd057 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 24 Jan 2012 15:30:01 +0200 Subject: Revert a space in the license agreement :) --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 85a0b5ce9..e7c55de1b 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -9,7 +9,7 @@ * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is + * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it -- cgit v1.2.3-24-g4f1b From 6c308b7482375baa4982cce26219cecd20bafdc0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 2 Feb 2012 22:03:53 +0200 Subject: Fix some comment blocks --- system/libraries/Zip.php | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e7c55de1b..174d18a67 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -67,7 +67,7 @@ class CI_Zip { */ public function add_dir($directory) { - foreach ((array)$directory as $dir) + foreach ( (array) $directory as $dir) { if ( ! preg_match('|.+/$|', $dir)) { @@ -82,17 +82,17 @@ class CI_Zip { // -------------------------------------------------------------------- /** - * Get file/directory modification time + * Get file/directory modification time * - * If this is a newly created file/dir, we will set the time to 'now' + * If this is a newly created file/dir, we will set the time to 'now' * - * @param string path to file - * @return array filemtime/filemdate + * @param string path to file + * @return array filemtime/filemdate */ protected function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files - $date = (file_exists($dir)) ? filemtime($dir): getdate($this->now); + $date = file_exists($dir) ? filemtime($dir) : getdate($this->now); return array( 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, @@ -106,6 +106,8 @@ class CI_Zip { * Add Directory * * @param string the directory name + * @param int + * @param int * @return void */ protected function _add_dir($dir, $file_mtime, $file_mdate) @@ -184,6 +186,8 @@ class CI_Zip { * * @param string the file name/path * @param string the data to be encoded + * @param int + * @param int * @return void */ protected function _add_data($filepath, $data, $file_mtime, $file_mdate) @@ -233,6 +237,8 @@ class CI_Zip { /** * Read the contents of a file and add it to the zip * + * @param string + * @param bool * @return bool */ public function read_file($path, $preserve_filepath = FALSE) @@ -267,12 +273,13 @@ class CI_Zip { * is in the original file path will be recreated in the zip file. * * @param string path to source + * @param bool + * @param bool * @return bool */ public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { $path = rtrim($path, '/\\').'/'; - if ( ! $fp = @opendir($path)) { return FALSE; @@ -306,6 +313,8 @@ class CI_Zip { } } + closedir($fp); + return TRUE; } @@ -314,7 +323,7 @@ class CI_Zip { /** * Get the Zip file * - * @return string (binary encoded) + * @return string (binary encoded) */ public function get_zip() { @@ -325,12 +334,12 @@ class CI_Zip { } 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 + .$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 } // -------------------------------------------------------------------- @@ -364,7 +373,6 @@ class CI_Zip { * Download * * @param string the file name - * @param string the data to be encoded * @return bool */ public function download($filename = 'backup.zip') -- cgit v1.2.3-24-g4f1b From 0b5a4867af78838f3c7e2726e469f904e15976f1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 29 Feb 2012 23:44:00 +0200 Subject: Minor clean-up --- system/libraries/Zip.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 174d18a67..f2f5f2e5d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -155,7 +155,7 @@ class CI_Zip { * Add Data to Zip * * Lets you add files to the archive. If the path is included - * in the filename it will be placed within a directory. Make + * in the filename it will be placed within a directory. Make * sure you use add_dir() first to create the folder. * * @param mixed @@ -314,7 +314,6 @@ class CI_Zip { } closedir($fp); - return TRUE; } @@ -373,7 +372,7 @@ class CI_Zip { * Download * * @param string the file name - * @return bool + * @return void */ public function download($filename = 'backup.zip') { -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 50e84920e..e33eb4e5a 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 0336dc228c84695ec75fc8dccedac354d1556de9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Mar 2012 15:34:28 +0200 Subject: Remove EOF newline --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index aa838eeca..c9810fab9 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -412,4 +412,4 @@ class CI_Zip { } /* End of file Zip.php */ -/* Location: ./system/libraries/Zip.php */ +/* Location: ./system/libraries/Zip.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From e684bdac2d6282e3b9a5c57e1006d5ed1664f647 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 13:47:29 +0300 Subject: Clear some spaces and fix some inconsistencies in the Zip library and system/helpers/ files --- system/libraries/Zip.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e33eb4e5a..12f3a5e59 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']; -- cgit v1.2.3-24-g4f1b From c8175be96157bb97374b1d9bb1be91c7b97bd640 Mon Sep 17 00:00:00 2001 From: tschechniker Date: Wed, 4 Apr 2012 14:47:30 +0300 Subject: Added Windows path compatibility to function read_dir --- system/libraries/Zip.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e91e2a2ff..2ec7befd3 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -279,7 +279,7 @@ class CI_Zip { */ public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) { - $path = rtrim($path, '/\\').'/'; + $path = rtrim($path, '/\\').DIRECTORY_SEPARATOR; if ( ! $fp = @opendir($path)) { return FALSE; @@ -288,7 +288,7 @@ class CI_Zip { // Set the original directory root for child dir's to use as relative if ($root_path === NULL) { - $root_path = dirname($path).'/'; + $root_path = dirname($path).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) @@ -300,11 +300,12 @@ class CI_Zip { if (@is_dir($path.$file)) { - $this->read_dir($path.$file.'/', $preserve_filepath, $root_path); + $this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path); } elseif (FALSE !== ($data = file_get_contents($path.$file))) { - $name = str_replace('\\', '/', $path); + $name = str_replace("\\", DIRECTORY_SEPARATOR, $path); + $name = str_replace("/", DIRECTORY_SEPARATOR, $path); if ($preserve_filepath === FALSE) { $name = str_replace($root_path, '', $name); -- cgit v1.2.3-24-g4f1b From 9664cc9fbb9b7f10776e9ad76ba7b27de5c2cda4 Mon Sep 17 00:00:00 2001 From: Tobias Tschech Date: Wed, 4 Apr 2012 15:22:33 +0300 Subject: Update system/libraries/Zip.php --- system/libraries/Zip.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2ec7befd3..80438546b 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -304,8 +304,7 @@ class CI_Zip { } elseif (FALSE !== ($data = file_get_contents($path.$file))) { - $name = str_replace("\\", DIRECTORY_SEPARATOR, $path); - $name = str_replace("/", DIRECTORY_SEPARATOR, $path); + $name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path); if ($preserve_filepath === FALSE) { $name = str_replace($root_path, '', $name); -- cgit v1.2.3-24-g4f1b From 86611db279c17cf9b3d6ad8732a1c840cb833148 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Fri, 27 Apr 2012 10:06:25 -0400 Subject: Fixed Cart, Migration, Parser and Zip libraries --- system/libraries/Zip.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 80438546b..86d0787b2 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -42,13 +42,53 @@ */ class CI_Zip { + /** + * Zip data in string form + * + * @var string + */ public $zipdata = ''; + + /** + * Zip data for a directory in string form + * + * @var string + */ public $directory = ''; + + /** + * Number of files/folder in zip file + * + * @var int + */ public $entries = 0; + + /** + * Number of files in zip + * + * @var int + */ public $file_num = 0; + + /** + * relative offset of local header + * + * @var int + */ public $offset = 0; + + /** + * Reference to time at init + * + * @var int + */ public $now; + /** + * Initialize zip compression class + * + * @return void + */ public function __construct() { $this->now = time(); -- cgit v1.2.3-24-g4f1b From 5645479c622eb36cf9869797896dc0921568c4a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 14:32:19 +0300 Subject: Clean up the libraries --- system/libraries/Zip.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 86d0787b2..e0dc637ad 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -48,35 +48,35 @@ class CI_Zip { * @var string */ public $zipdata = ''; - + /** * Zip data for a directory in string form * * @var string */ public $directory = ''; - + /** * Number of files/folder in zip file * * @var int */ public $entries = 0; - + /** * Number of files in zip * * @var int */ public $file_num = 0; - + /** * relative offset of local header * * @var int */ public $offset = 0; - + /** * Reference to time at init * @@ -87,7 +87,7 @@ class CI_Zip { /** * Initialize zip compression class * - * @return void + * @return void */ public function __construct() { -- cgit v1.2.3-24-g4f1b From 95b2f4fa070f34084c78ccc68e67ecca51f40adf Mon Sep 17 00:00:00 2001 From: vkeranov Date: Sat, 16 Jun 2012 20:37:11 +0300 Subject: Really important space fix :) --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e0dc637ad..5c4c257f8 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -40,7 +40,7 @@ * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/zip.html */ -class CI_Zip { +class CI_Zip { /** * Zip data in string form -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/libraries/Zip.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 5c4c257f8..9ecd0de9f 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -1,4 +1,4 @@ - Date: Mon, 17 Dec 2012 10:48:02 +0200 Subject: Fix 2073 --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 9ecd0de9f..5eb33d29c 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -133,7 +133,7 @@ class CI_Zip { protected function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files - $date = file_exists($dir) ? filemtime($dir) : getdate($this->now); + $date = file_exists($dir) ? @filemtime($dir) : getdate($this->now); return array( 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, -- cgit v1.2.3-24-g4f1b From 4296a65693504736b5e65bee5b163fa08cacb563 Mon Sep 17 00:00:00 2001 From: Andrew Podner Date: Mon, 17 Dec 2012 07:51:15 -0500 Subject: update for Issue #2064 (changed docblocks which return $this or only call a method that returns $this to @return CI_DB_class_name) --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 9ecd0de9f..77cc45b38 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -438,7 +438,7 @@ class CI_Zip { * Lets you clear current zip data. Useful if you need to create * multiple zips with different data. * - * @return object + * @return CI_Zip */ public function clear_data() { -- cgit v1.2.3-24-g4f1b From 80500afbd188600212ca913a7bac073009feac73 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Jan 2013 08:16:53 +0200 Subject: [ci skip] Happy new year --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 740e99c72..6608f050e 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 88f41dff43e8e787ab553d86715aca130abf9e51 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 23 Sep 2013 15:24:43 +0300 Subject: [ci skip] Update Zip library docblocks --- system/libraries/Zip.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 6608f050e..2ce457844 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -103,12 +103,12 @@ class CI_Zip { * * Lets you add a virtual directory into which you can place files. * - * @param mixed the directory name. Can be string or array + * @param mixed $directory the directory name. Can be string or array * @return void */ public function add_dir($directory) { - foreach ( (array) $directory as $dir) + foreach ((array) $directory as $dir) { if ( ! preg_match('|.+/$|', $dir)) { @@ -127,7 +127,7 @@ class CI_Zip { * * If this is a newly created file/dir, we will set the time to 'now' * - * @param string path to file + * @param string $dir path to file * @return array filemtime/filemdate */ protected function _get_mod_time($dir) @@ -146,9 +146,9 @@ class CI_Zip { /** * Add Directory * - * @param string the directory name - * @param int - * @param int + * @param string $dir the directory name + * @param int $file_mtime + * @param int $file_mdate * @return void */ protected function _add_dir($dir, $file_mtime, $file_mdate) @@ -199,8 +199,8 @@ class CI_Zip { * in the filename it will be placed within a directory. Make * sure you use add_dir() first to create the folder. * - * @param mixed - * @param string + * @param mixed $filepath A single filepath or an array of file => data pairs + * @param string $data Single file contents * @return void */ public function add_data($filepath, $data = NULL) @@ -225,10 +225,10 @@ class CI_Zip { /** * Add Data to Zip * - * @param string the file name/path - * @param string the data to be encoded - * @param int - * @param int + * @param string $filepath the file name/path + * @param string $data the data to be encoded + * @param int $file_mtime + * @param int $file_mdate * @return void */ protected function _add_data($filepath, $data, $file_mtime, $file_mdate) @@ -278,8 +278,8 @@ class CI_Zip { /** * Read the contents of a file and add it to the zip * - * @param string - * @param bool + * @param string $path + * @param bool $preserve_filepath * @return bool */ public function read_file($path, $preserve_filepath = FALSE) @@ -313,9 +313,9 @@ class CI_Zip { * sub-folders) and creates a zip based on it. Whatever directory structure * is in the original file path will be recreated in the zip file. * - * @param string path to source - * @param bool - * @param bool + * @param string $path path to source directory + * @param bool $preserve_filepath + * @param string $root_path * @return bool */ public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL) @@ -389,7 +389,7 @@ class CI_Zip { * * Lets you write a file * - * @param string the file name + * @param string $filepath the file name * @return bool */ public function archive($filepath) @@ -412,7 +412,7 @@ class CI_Zip { /** * Download * - * @param string the file name + * @param string $filename the file name * @return void */ public function download($filename = 'backup.zip') -- cgit v1.2.3-24-g4f1b From a20ec975e653f501cca8e1cf57a9ea244417990f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 15:23:10 +0200 Subject: Add ability for changing the original file path/name in CI_Zip::read_file() Supersedes PR #884 --- system/libraries/Zip.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2ce457844..229b1ecbc 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -279,22 +279,25 @@ class CI_Zip { * Read the contents of a file and add it to the zip * * @param string $path - * @param bool $preserve_filepath + * @param bool $archive_filepath * @return bool */ - public function read_file($path, $preserve_filepath = FALSE) + public function read_file($path, $archive_filepath = FALSE) { - if ( ! file_exists($path)) - { - return FALSE; - } - - if (FALSE !== ($data = file_get_contents($path))) + if (file_exists($path) && FALSE !== ($data = file_get_contents($path))) { - $name = str_replace('\\', '/', $path); - if ($preserve_filepath === FALSE) + if (is_string($archive_filepath)) { - $name = preg_replace('|.*/(.+)|', '\\1', $name); + $name = str_replace('\\', '/', $archive_filepath); + } + else + { + $name = str_replace('\\', '/', $path); + + if ($preserve_filepath === FALSE) + { + $name = preg_replace('|.*/(.+)|', '\\1', $name); + } } $this->add_data($name, $data); -- cgit v1.2.3-24-g4f1b From 119d8a7547e155edaaa53682b9247cd7e80d8c9d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Jan 2014 15:27:53 +0200 Subject: Optimize get_instance() calls/assignments --- system/libraries/Zip.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 229b1ecbc..250ee02cd 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -425,8 +425,7 @@ class CI_Zip { $filename .= '.zip'; } - $CI =& get_instance(); - $CI->load->helper('download'); + get_instance()->load->helper('download'); $get_zip = $this->get_zip(); $zip_content =& $get_zip; -- cgit v1.2.3-24-g4f1b From d8b1ad31cf7ee205ddf3cf396b1d1bfa45af49fa Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Jan 2014 17:42:52 +0200 Subject: Fix #2822: Incorrect usage of fwrite() We only used to check (and not always) if the return value of fwrite() is boolean FALSE, while it is possible that the otherwise returned bytecount is less than the length of data that we're trying to write. This allowed incomplete writes over network streams and possibly a few other edge cases. --- system/libraries/Zip.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 250ee02cd..b10b0bb0f 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -403,11 +403,19 @@ class CI_Zip { } flock($fp, LOCK_EX); - fwrite($fp, $this->get_zip()); + + for ($written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) + { + if (($result = fwrite($fp, substr($data, $written))) === FALSE) + { + break; + } + } + flock($fp, LOCK_UN); fclose($fp); - return TRUE; + return is_int($result); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From aa9a4f7e59143a3a187e415e646c966aaf786380 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Jan 2014 12:05:51 +0200 Subject: Fix #2844 --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index b10b0bb0f..58f06455c 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -294,7 +294,7 @@ class CI_Zip { { $name = str_replace('\\', '/', $path); - if ($preserve_filepath === FALSE) + if ($archive_filepath === FALSE) { $name = preg_replace('|.*/(.+)|', '\\1', $name); } -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 58f06455c..40b661abc 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 382b51383c84fbb7f861fcd87b0b71b35c9f2869 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 26 Feb 2014 18:41:59 +0200 Subject: Don't use error suppression on is_dir(), file_exists() --- system/libraries/Zip.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 40b661abc..43abfba42 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -133,12 +133,12 @@ class CI_Zip { protected function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files - $date = file_exists($dir) ? @filemtime($dir) : getdate($this->now); + $date = file_exists($dir) ? filemtime($dir) : getdate($this->now); return array( - 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, - 'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday'] - ); + 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, + 'file_mdate' => (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday'] + ); } // -------------------------------------------------------------------- @@ -342,7 +342,7 @@ class CI_Zip { continue; } - if (@is_dir($path.$file)) + if (is_dir($path.$file)) { $this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path); } @@ -353,6 +353,7 @@ class CI_Zip { { $name = str_replace($root_path, '', $name); } + $this->add_data($name.$file, $data); } } -- cgit v1.2.3-24-g4f1b From 7cf682abf46bcaa112b63c500a884ba25c0dd8b3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 13 Mar 2014 14:55:45 +0200 Subject: Partially revert PR #2190 The core shouldn't depend on constants that are not defined by itself --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 43abfba42..c634b1133 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -398,7 +398,7 @@ class CI_Zip { */ public function archive($filepath) { - if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE))) + if ( ! ($fp = @fopen($filepath, 'w+b'))) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 00421bf248f5b9270166f0057d3e493899057e81 Mon Sep 17 00:00:00 2001 From: Ahmad Anbar Date: Fri, 14 Mar 2014 16:49:47 +0200 Subject: Fixed filemtime --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index c634b1133..ab30a9019 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -133,7 +133,7 @@ class CI_Zip { protected function _get_mod_time($dir) { // filemtime() may return false, but raises an error for non-existing files - $date = file_exists($dir) ? filemtime($dir) : getdate($this->now); + $date = file_exists($dir) ? getdate(filemtime($dir)) : getdate($this->now); return array( 'file_mtime' => ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2, -- cgit v1.2.3-24-g4f1b From 1f5090acda137edb29cc649d85c7ef1b75b8f59f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 3 Jun 2014 15:40:30 +0300 Subject: Fix a potential undefined variable error --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index ab30a9019..62a84ae75 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -405,7 +405,7 @@ class CI_Zip { flock($fp, LOCK_EX); - for ($written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) + for ($result = $written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) { if (($result = fwrite($fp, substr($data, $written))) === FALSE) { -- cgit v1.2.3-24-g4f1b From bdb96ca1b1dbfc1791172fd169d7751cbc4d7d55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Oct 2014 00:13:31 +0200 Subject: [ci skip] Switch to MIT license; close #3293 --- system/libraries/Zip.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 62a84ae75..434229471 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -4,24 +4,35 @@ * * An open source application development framework for PHP 5.2.4 or newer * - * NOTICE OF LICENSE + * This content is released under the MIT License (MIT) * - * Licensed under the Open Software License version 3.0 + * Copyright (c) 2014, British Columbia Institute of Technology * - * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is - * also available through the world wide web at this URL: - * http://opensource.org/licenses/OSL-3.0 - * If you did not receive a copy of the license and are unable to obtain it - * through the world wide web, please send an email to - * licensing@ellislab.com so we can send you a copy immediately. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * @package CodeIgniter - * @author EllisLab Dev Team + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @package CodeIgniter + * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 1.0 + * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://opensource.org/licenses/MIT MIT License + * @link http://codeigniter.com + * @since Version 1.0.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From f678e63bd823fa712e9fbb28c259fcbedc30aa45 Mon Sep 17 00:00:00 2001 From: garrettair Date: Tue, 18 Nov 2014 17:09:31 -0600 Subject: Exposed the arguments to gzcompress by adding public variables to the Zip library. --- system/libraries/Zip.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 434229471..5208c9149 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -95,6 +95,19 @@ class CI_Zip { * @var int */ public $now; + + /** + * The level of compression. 0 to 9, 9 being the highest level of + * compression. + * @var int + */ + public $compression_level = 6; + + /** + * Which encoding to use. One of the ZLIB_ENCODING_* constants. + * @var int + */ + public $compression_encoding = ZLIB_ENCODING_DEFLATE; /** * Initialize zip compression class @@ -248,7 +261,7 @@ class CI_Zip { $uncompressed_size = strlen($data); $crc32 = crc32($data); - $gzdata = substr(gzcompress($data), 2, -4); + $gzdata = substr(gzcompress($data, $this->compression_level, $this->compression_encoding), 2, -4); $compressed_size = strlen($gzdata); $this->zipdata .= -- cgit v1.2.3-24-g4f1b From 309d7012a737f140076cabbe8873dc39f25331b2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Dec 2014 11:47:26 +0200 Subject: Zip library changes related to PR #3341 - Drop compression_encoding option, it requires PHP 5.4. - Change default compression_level to 2 as this was previously the hard-coded default. - Improve on the doc changes made in the PR. --- system/libraries/Zip.php | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 5208c9149..2f6ab8b68 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -95,19 +95,15 @@ class CI_Zip { * @var int */ public $now; - - /** - * The level of compression. 0 to 9, 9 being the highest level of - * compression. - * @var int - */ - public $compression_level = 6; - - /** - * Which encoding to use. One of the ZLIB_ENCODING_* constants. - * @var int - */ - public $compression_encoding = ZLIB_ENCODING_DEFLATE; + + /** + * The level of compression + * + * Ranges from 0 to 9, with 9 being the highest level. + * + * @var int + */ + public $compression_level = 2; /** * Initialize zip compression class @@ -261,7 +257,7 @@ class CI_Zip { $uncompressed_size = strlen($data); $crc32 = crc32($data); - $gzdata = substr(gzcompress($data, $this->compression_level, $this->compression_encoding), 2, -4); + $gzdata = substr(gzcompress($data, $this->compression_level), 2, -4); $compressed_size = strlen($gzdata); $this->zipdata .= -- cgit v1.2.3-24-g4f1b From fe9309d22c1b088f5363954d6dac013c8c955894 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Jan 2015 17:48:58 +0200 Subject: Bulk (mostly documentation) update - Remove PHP version from license notices - Bump year number in copyright notices - Recommend PHP 5.4 or newer to be used - Tell Travis-CI to test on PHP 5.3.0 instead of the latest 5.3 version Related: #3450 --- system/libraries/Zip.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 2f6ab8b68..cee5d8d76 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -2,11 +2,11 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.2.4 or newer + * An open source application development framework for PHP * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014, British Columbia Institute of Technology + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 @@ -59,35 +59,35 @@ class CI_Zip { * * @var string */ - public $zipdata = ''; + public $zipdata = ''; /** * Zip data for a directory in string form * * @var string */ - public $directory = ''; + public $directory = ''; /** * Number of files/folder in zip file * * @var int */ - public $entries = 0; + public $entries = 0; /** * Number of files in zip * * @var int */ - public $file_num = 0; + public $file_num = 0; /** * relative offset of local header * * @var int */ - public $offset = 0; + public $offset = 0; /** * Reference to time at init @@ -473,11 +473,11 @@ class CI_Zip { */ public function clear_data() { - $this->zipdata = ''; - $this->directory = ''; - $this->entries = 0; - $this->file_num = 0; - $this->offset = 0; + $this->zipdata = ''; + $this->directory = ''; + $this->entries = 0; + $this->file_num = 0; + $this->offset = 0; return $this; } -- cgit v1.2.3-24-g4f1b From 90726b8c769ea75aec34814ddfa91655d488e6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 12:39:22 +0200 Subject: [ci skip] Change some log messages' level 'Class Loaded' type of messages flood log files when log_threshold is set to 2 (debug). They're now logged as 'info' level. This is manually applying PR #1528, which was created to do the same thing, but became outdated. --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index cee5d8d76..555e9aedf 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -113,7 +113,7 @@ class CI_Zip { public function __construct() { $this->now = time(); - log_message('debug', 'Zip Compression Class Initialized'); + log_message('info', 'Zip Compression Class Initialized'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4cbe463b4c442e0e2dae2f43565e77f7ac5ecb86 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 21 Jan 2015 22:56:22 +0100 Subject: Remove closing blocks at end of PHP files --- system/libraries/Zip.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 555e9aedf..f2f17148b 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -482,6 +482,3 @@ class CI_Zip { } } - -/* End of file Zip.php */ -/* Location: ./system/libraries/Zip.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b7a8fbb9588ce4603e9c8fa16072a186e70b8bdb Mon Sep 17 00:00:00 2001 From: Kyle Gadd Date: Fri, 3 Apr 2015 17:37:44 -0600 Subject: Matched root_path's slashes with the name being replaced --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index f2f17148b..3e98ac568 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -352,7 +352,7 @@ class CI_Zip { // Set the original directory root for child dir's to use as relative if ($root_path === NULL) { - $root_path = dirname($path).DIRECTORY_SEPARATOR; + $root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)).DIRECTORY_SEPARATOR; } while (FALSE !== ($file = readdir($fp))) -- cgit v1.2.3-24-g4f1b From 125ef4751080a2118cb203357d77687699e3eb25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:33:00 +0200 Subject: [ci skip] Bump year to 2016 --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 3e98ac568..e3d63e802 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology + * Copyright (c) 2014 - 2016, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From bd202c91b0e9cf0a8c93bcaa71df9574f5909346 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:50:18 +0200 Subject: [ci skip] Update codeigniter.com links to https --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e3d63e802..d412ebf34 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License - * @link http://codeigniter.com + * @link https://codeigniter.com * @since Version 1.0.0 * @filesource */ @@ -50,7 +50,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Encryption * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/libraries/zip.html + * @link https://codeigniter.com/user_guide/libraries/zip.html */ class CI_Zip { -- cgit v1.2.3-24-g4f1b From 1924e879b165fb119847a49a7a5eab2f28295fa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:55:34 +0200 Subject: [ci skip] Update ellislab.com links to https too --- system/libraries/Zip.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index d412ebf34..140ad7212 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com -- cgit v1.2.3-24-g4f1b From 4e2cdec6ff4b4af5f994be4c348ad3b9a9a2942f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 28 Oct 2016 14:19:08 +0300 Subject: Improve byte-safety --- system/libraries/Zip.php | 74 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 13 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 140ad7212..25315c92e 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -105,6 +105,13 @@ class CI_Zip { */ public $compression_level = 2; + /** + * mbstring.func_override flag + * + * @var bool + */ + protected static $func_override; + /** * Initialize zip compression class * @@ -112,6 +119,8 @@ class CI_Zip { */ public function __construct() { + isset(self::$func_override) OR self::$func_override = (extension_loaded('mbstring') && ini_get('mbstring.func_override')); + $this->now = time(); log_message('info', 'Zip Compression Class Initialized'); } @@ -182,7 +191,7 @@ class CI_Zip { .pack('V', 0) // crc32 .pack('V', 0) // compressed filesize .pack('V', 0) // uncompressed filesize - .pack('v', strlen($dir)) // length of pathname + .pack('v', self::strlen($dir)) // length of pathname .pack('v', 0) // extra field length .$dir // below is "data descriptor" segment @@ -197,7 +206,7 @@ class CI_Zip { .pack('V',0) // crc32 .pack('V',0) // compressed filesize .pack('V',0) // uncompressed filesize - .pack('v', strlen($dir)) // length of pathname + .pack('v', self::strlen($dir)) // length of pathname .pack('v', 0) // extra field length .pack('v', 0) // file comment length .pack('v', 0) // disk number start @@ -206,7 +215,7 @@ class CI_Zip { .pack('V', $this->offset) // relative offset of local header .$dir; - $this->offset = strlen($this->zipdata); + $this->offset = self::strlen($this->zipdata); $this->entries++; } @@ -255,10 +264,10 @@ class CI_Zip { { $filepath = str_replace('\\', '/', $filepath); - $uncompressed_size = strlen($data); + $uncompressed_size = self::strlen($data); $crc32 = crc32($data); - $gzdata = substr(gzcompress($data, $this->compression_level), 2, -4); - $compressed_size = strlen($gzdata); + $gzdata = self::substr(gzcompress($data, $this->compression_level), 2, -4); + $compressed_size = self::strlen($gzdata); $this->zipdata .= "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00" @@ -267,7 +276,7 @@ class CI_Zip { .pack('V', $crc32) .pack('V', $compressed_size) .pack('V', $uncompressed_size) - .pack('v', strlen($filepath)) // length of filename + .pack('v', self::strlen($filepath)) // length of filename .pack('v', 0) // extra field length .$filepath .$gzdata; // "file data" segment @@ -279,7 +288,7 @@ class CI_Zip { .pack('V', $crc32) .pack('V', $compressed_size) .pack('V', $uncompressed_size) - .pack('v', strlen($filepath)) // length of filename + .pack('v', self::strlen($filepath)) // length of filename .pack('v', 0) // extra field length .pack('v', 0) // file comment length .pack('v', 0) // disk number start @@ -288,7 +297,7 @@ class CI_Zip { .pack('V', $this->offset) // relative offset of local header .$filepath; - $this->offset = strlen($this->zipdata); + $this->offset = self::strlen($this->zipdata); $this->entries++; $this->file_num++; } @@ -401,8 +410,8 @@ class CI_Zip { .$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 + .pack('V', self::strlen($this->directory)) // size of central dir + .pack('V', self::strlen($this->zipdata)) // offset to start of central dir ."\x00\x00"; // .zip file comment length } @@ -425,9 +434,9 @@ class CI_Zip { flock($fp, LOCK_EX); - for ($result = $written = 0, $data = $this->get_zip(), $length = strlen($data); $written < $length; $written += $result) + for ($result = $written = 0, $data = $this->get_zip(), $length = self::strlen($data); $written < $length; $written += $result) { - if (($result = fwrite($fp, substr($data, $written))) === FALSE) + if (($result = fwrite($fp, self::substr($data, $written))) === FALSE) { break; } @@ -481,4 +490,43 @@ class CI_Zip { return $this; } + // -------------------------------------------------------------------- + + /** + * Byte-safe strlen() + * + * @param string $str + * @return int + */ + protected static function strlen($str) + { + return (self::$func_override) + ? mb_strlen($str, '8bit') + : strlen($str); + } + + // -------------------------------------------------------------------- + + /** + * Byte-safe substr() + * + * @param string $str + * @param int $start + * @param int $length + * @return string + */ + protected static function substr($str, $start, $length = NULL) + { + if (self::$func_override) + { + // mb_substr($str, $start, null, '8bit') returns an empty + // string on PHP 5.3 + isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start); + return mb_substr($str, $start, $length, '8bit'); + } + + return isset($length) + ? substr($str, $start, $length) + : substr($str, $start); + } } -- cgit v1.2.3-24-g4f1b From da60e9bc66ec90970fbd2dfd08b0a6e66b9f5f5f Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/libraries/Zip.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 25315c92e..46f6c145d 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From c0c74d5201c171cd6d0cdc2133e63077ebe1a407 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jan 2017 15:26:35 +0200 Subject: More byte-safety --- system/libraries/Zip.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/libraries/Zip.php') diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 46f6c145d..2c71e1fbe 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -106,11 +106,11 @@ class CI_Zip { public $compression_level = 2; /** - * mbstring.func_override flag + * mbstring.func_overload flag * * @var bool */ - protected static $func_override; + protected static $func_overload; /** * Initialize zip compression class @@ -119,7 +119,7 @@ class CI_Zip { */ public function __construct() { - isset(self::$func_override) OR self::$func_override = (extension_loaded('mbstring') && ini_get('mbstring.func_override')); + isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); $this->now = time(); log_message('info', 'Zip Compression Class Initialized'); @@ -500,7 +500,7 @@ class CI_Zip { */ protected static function strlen($str) { - return (self::$func_override) + return (self::$func_overload) ? mb_strlen($str, '8bit') : strlen($str); } @@ -517,7 +517,7 @@ class CI_Zip { */ protected static function substr($str, $start, $length = NULL) { - if (self::$func_override) + if (self::$func_overload) { // mb_substr($str, $start, null, '8bit') returns an empty // string on PHP 5.3 -- cgit v1.2.3-24-g4f1b