From 0d546bcc839dd11284417ac1ee69d0d390bc978e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Chapeaux?= Date: Fri, 29 Mar 2002 22:29:52 +0000 Subject: [PATCH] patch from Peter Listiak to get last modified date and time of the compressed file --- ChangeLog | 3 ++ libraries/zip.lib.php3 | 73 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index aec2cc843..e739584e4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,9 @@ $Source$ * tbl_change.php3: fixed bug #535984 - JS Error in tbl_change.php3. * tbl_replace.php3: fixed bug #536707 - undefined variables. * lang/italian.inc.php3: updated thanks to Pietro Danesi. + * libraries/zip.lib.php3: merged a patch from + Peter Listiak to get last modified date and + time of the compressed file. 2002-03-28 Marc Delisle * sql.php3, bug #535648: bookmarks can't be saved on the second server. diff --git a/libraries/zip.lib.php3 b/libraries/zip.lib.php3 index a8b40c9aa..a52f65b8e 100755 --- a/libraries/zip.lib.php3 +++ b/libraries/zip.lib.php3 @@ -9,10 +9,13 @@ * Based on : * * http://www.zend.com/codex.php3?id=535&single=1 - * By Eric Mueller (eric@themepark.com) + * By Eric Mueller * * http://www.zend.com/codex.php3?id=470&single=1 - * by Denis125 (webmaster@atlant.ru) + * by Denis125 + * + * a patch from Peter Listiak for last modified + * date and time of the compressed file * * Official ZIP file format: http://www.pkware.com/appnote.txt * @@ -50,22 +53,74 @@ class zipfile /** - * Adds "file" to archive + * Converts the date y/n/d and time h:m:s to a four byte DOS date and time + * format (date in high two bytes, time in low two bytes allowing magnitude + * comparison). * - * @param string file contents - * @param string name of the file in the archive (may contains the path) + * @param integer the current year + * @param integer the current month + * @param integer the current day + * @param integer the current hour + * @param integer the current minut + * @param integer the current second + * + * @return integer the current date in a four byte DOS format * * @access public */ - function addFile($data, $name) + function dosTime($year, $month, $day, $hour, $minute, $second) { + return ($year < 1980) + ? dosTime(1980, 1, 1, 0, 0, 0) + : (($year - 1980) << 25) | ($month << 21) | ($day << 16) | + ($hour << 11) | ($minute << 5) | ($second >> 1); + } // end of the 'dosTime()' method + + + /** + * Returns the Unix time $unixtime in DOS format, rounded up to the next + * two second boundary. + * + * @param integer the current timestamp + * + * @return integer the current date in a four byte DOS format + * + * @access public + * + * @see DOSTime() + */ + function unix2DosTime($unixtime = 0) { + $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); + + return $this->dosTime($timearray['year'], $timearray['mon'], $timearray['mday'], + $timearray['hours'], $timearray['minutes'], $timearray['seconds']); + } // end of the 'unix2DosTime()' method + + + /** + * Adds "file" to archive + * + * @param string file contents + * @param string name of the file in the archive (may contains the path) + * @param integer the current timestamp + * + * @access public + */ + function addFile($data, $name, $time = 0) { - $name = str_replace('\\', '/', $name); + $name = str_replace('\\', '/', $name); + + $dtime = dechex ($this->unix2DosTime($time)); + $hexdtime = '\x' . $dtime[6] . $dtime[7] + . '\x' . $dtime[4] . $dtime[5] + . '\x' . $dtime[2] . $dtime[3] + . '\x' . $dtime[0] . $dtime[1]; + eval('$hexdtime = "' . $hexdtime . '";'); $fr = "\x50\x4b\x03\x04"; $fr .= "\x14\x00"; // ver needed to extract $fr .= "\x00\x00"; // gen purpose bit flag $fr .= "\x08\x00"; // compression method - $fr .= "\x00\x00\x00\x00"; // last mod time and date + $fr .= $hexdtime; // last mod time and date // "local file header" segment $unc_len = strlen($data); @@ -99,7 +154,7 @@ class zipfile $cdrec .= "\x14\x00"; // version needed to extract $cdrec .= "\x00\x00"; // gen purpose bit flag $cdrec .= "\x08\x00"; // compression method - $cdrec .= "\x00\x00\x00\x00"; // last mod time & date + $cdrec .= $hexdtime; // last mod time & date $cdrec .= pack('V', $crc); // crc32 $cdrec .= pack('V', $c_len); // compressed filesize $cdrec .= pack('V', $unc_len); // uncompressed filesize