annotate e2gallerypro/e2upload/Backend/Assets/getid3/module.archive.zip.php @ 28:118cb614cf18 judyates tip

judy bio.
author Robert McIntyre <rlm@mit.edu>
date Tue, 29 Dec 2015 16:26:18 -0800
parents 3f6b44aa6b35
children
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.archive.zip.php |
rlm@3 18 // | Module for analyzing pkZip files |
rlm@3 19 // | dependencies: NONE |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.archive.zip.php,v 1.4 2006/11/02 10:48:00 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_zip extends getid3_handler
rlm@3 27 {
rlm@3 28
rlm@3 29 public function Analyze() {
rlm@3 30
rlm@3 31 $getid3 = $this->getid3;
rlm@3 32
rlm@3 33 $getid3->info['zip'] = array ();
rlm@3 34 $info_zip = &$getid3->info['zip'];
rlm@3 35
rlm@3 36 $getid3->info['fileformat'] = 'zip';
rlm@3 37
rlm@3 38 $info_zip['encoding'] = 'ISO-8859-1';
rlm@3 39 $info_zip['files'] = array ();
rlm@3 40 $info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0;
rlm@3 41
rlm@3 42 $eocd_search_data = '';
rlm@3 43 $eocd_search_counter = 0;
rlm@3 44 while ($eocd_search_counter++ < 512) {
rlm@3 45
rlm@3 46 fseek($getid3->fp, -128 * $eocd_search_counter, SEEK_END);
rlm@3 47 $eocd_search_data = fread($getid3->fp, 128).$eocd_search_data;
rlm@3 48
rlm@3 49 if (strstr($eocd_search_data, 'PK'."\x05\x06")) {
rlm@3 50
rlm@3 51 $eocd_position = strpos($eocd_search_data, 'PK'."\x05\x06");
rlm@3 52 fseek($getid3->fp, (-128 * $eocd_search_counter) + $eocd_position, SEEK_END);
rlm@3 53 $info_zip['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
rlm@3 54
rlm@3 55 fseek($getid3->fp, $info_zip['end_central_directory']['directory_offset'], SEEK_SET);
rlm@3 56 $info_zip['entries_count'] = 0;
rlm@3 57 while ($central_directoryentry = $this->ZIPparseCentralDirectory($getid3->fp)) {
rlm@3 58 $info_zip['central_directory'][] = $central_directoryentry;
rlm@3 59 $info_zip['entries_count']++;
rlm@3 60 $info_zip['compressed_size'] += $central_directoryentry['compressed_size'];
rlm@3 61 $info_zip['uncompressed_size'] += $central_directoryentry['uncompressed_size'];
rlm@3 62
rlm@3 63 if ($central_directoryentry['uncompressed_size'] > 0) {
rlm@3 64 $info_zip['files'] = getid3_zip::array_merge_clobber($info_zip['files'], getid3_zip::CreateDeepArray($central_directoryentry['filename'], '/', $central_directoryentry['uncompressed_size']));
rlm@3 65 }
rlm@3 66 }
rlm@3 67
rlm@3 68 if ($info_zip['entries_count'] == 0) {
rlm@3 69 throw new getid3_exception('No Central Directory entries found (truncated file?)');
rlm@3 70 }
rlm@3 71
rlm@3 72 if (!empty($info_zip['end_central_directory']['comment'])) {
rlm@3 73 $info_zip['comments']['comment'][] = $info_zip['end_central_directory']['comment'];
rlm@3 74 }
rlm@3 75
rlm@3 76 if (isset($info_zip['central_directory'][0]['compression_method'])) {
rlm@3 77 $info_zip['compression_method'] = $info_zip['central_directory'][0]['compression_method'];
rlm@3 78 }
rlm@3 79 if (isset($info_zip['central_directory'][0]['flags']['compression_speed'])) {
rlm@3 80 $info_zip['compression_speed'] = $info_zip['central_directory'][0]['flags']['compression_speed'];
rlm@3 81 }
rlm@3 82 if (isset($info_zip['compression_method']) && ($info_zip['compression_method'] == 'store') && !isset($info_zip['compression_speed'])) {
rlm@3 83 $info_zip['compression_speed'] = 'store';
rlm@3 84 }
rlm@3 85
rlm@3 86 return true;
rlm@3 87 }
rlm@3 88 }
rlm@3 89
rlm@3 90 if ($this->getZIPentriesFilepointer()) {
rlm@3 91
rlm@3 92 // central directory couldn't be found and/or parsed
rlm@3 93 // scan through actual file data entries, recover as much as possible from probable trucated file
rlm@3 94 if (@$info_zip['compressed_size'] > ($getid3->info['filesize'] - 46 - 22)) {
rlm@3 95 throw new getid3_exception('Warning: Truncated file! - Total compressed file sizes ('.$info_zip['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($getid3->info['filesize'] - 46 - 22).' bytes)');
rlm@3 96 }
rlm@3 97 throw new getid3_exception('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete');
rlm@3 98 }
rlm@3 99
rlm@3 100 //throw new getid3_exception('Cannot find End Of Central Directory (truncated file?)');
rlm@3 101 }
rlm@3 102
rlm@3 103
rlm@3 104
rlm@3 105 private function getZIPHeaderFilepointerTopDown() {
rlm@3 106
rlm@3 107 // shortcut
rlm@3 108 $getid3 = $this->getid3;
rlm@3 109
rlm@3 110 $getid3->info['fileformat'] = 'zip';
rlm@3 111
rlm@3 112 $getid3->info['zip'] = array ();
rlm@3 113 $info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0;
rlm@3 114
rlm@3 115 rewind($getid3->fp);
rlm@3 116 while ($fileentry = $this->ZIPparseLocalFileHeader()) {
rlm@3 117 $info_zip['entries'][] = $fileentry;
rlm@3 118 $info_zip['entries_count']++;
rlm@3 119 }
rlm@3 120 if ($info_zip['entries_count'] == 0) {
rlm@3 121 throw new getid3_exception('No Local File Header entries found');
rlm@3 122 }
rlm@3 123
rlm@3 124 $info_zip['entries_count'] = 0;
rlm@3 125 while ($central_directoryentry = $this->ZIPparseCentralDirectory($getid3->fp)) {
rlm@3 126 $info_zip['central_directory'][] = $central_directoryentry;
rlm@3 127 $info_zip['entries_count']++;
rlm@3 128 $info_zip['compressed_size'] += $central_directoryentry['compressed_size'];
rlm@3 129 $info_zip['uncompressed_size'] += $central_directoryentry['uncompressed_size'];
rlm@3 130 }
rlm@3 131 if ($info_zip['entries_count'] == 0) {
rlm@3 132 throw new getid3_exception('No Central Directory entries found (truncated file?)');
rlm@3 133 }
rlm@3 134
rlm@3 135 if ($eocd = $this->ZIPparseEndOfCentralDirectory()) {
rlm@3 136 $info_zip['end_central_directory'] = $eocd;
rlm@3 137 } else {
rlm@3 138 throw new getid3_exception('No End Of Central Directory entry found (truncated file?)');
rlm@3 139 }
rlm@3 140
rlm@3 141 if (!@$info_zip['end_central_directory']['comment']) {
rlm@3 142 $info_zip['comments']['comment'][] = $info_zip['end_central_directory']['comment'];
rlm@3 143 }
rlm@3 144
rlm@3 145 return true;
rlm@3 146 }
rlm@3 147
rlm@3 148
rlm@3 149
rlm@3 150 private function getZIPentriesFilepointer() {
rlm@3 151
rlm@3 152 // shortcut
rlm@3 153 $getid3 = $this->getid3;
rlm@3 154
rlm@3 155 $getid3->info['zip'] = array ();
rlm@3 156 $info_zip['compressed_size'] = $info_zip['uncompressed_size'] = $info_zip['entries_count'] = 0;
rlm@3 157
rlm@3 158 rewind($getid3->fp);
rlm@3 159 while ($fileentry = $this->ZIPparseLocalFileHeader($getid3->fp)) {
rlm@3 160 $info_zip['entries'][] = $fileentry;
rlm@3 161 $info_zip['entries_count']++;
rlm@3 162 $info_zip['compressed_size'] += $fileentry['compressed_size'];
rlm@3 163 $info_zip['uncompressed_size'] += $fileentry['uncompressed_size'];
rlm@3 164 }
rlm@3 165 if ($info_zip['entries_count'] == 0) {
rlm@3 166 throw new getid3_exception('No Local File Header entries found');
rlm@3 167 }
rlm@3 168
rlm@3 169 return true;
rlm@3 170 }
rlm@3 171
rlm@3 172
rlm@3 173
rlm@3 174 private function ZIPparseLocalFileHeader() {
rlm@3 175
rlm@3 176 // shortcut
rlm@3 177 $getid3 = $this->getid3;
rlm@3 178
rlm@3 179 $local_file_header['offset'] = ftell($getid3->fp);
rlm@3 180
rlm@3 181 $zip_local_file_header = fread($getid3->fp, 30);
rlm@3 182
rlm@3 183 $local_file_header['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($zip_local_file_header, 0, 4));
rlm@3 184
rlm@3 185 // Invalid Local File Header Signature
rlm@3 186 if ($local_file_header['raw']['signature'] != 0x04034B50) {
rlm@3 187 fseek($getid3->fp, $local_file_header['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
rlm@3 188 return false;
rlm@3 189 }
rlm@3 190
rlm@3 191 getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['raw'], $zip_local_file_header, 4,
rlm@3 192 array (
rlm@3 193 'extract_version' => 2,
rlm@3 194 'general_flags' => 2,
rlm@3 195 'compression_method' => 2,
rlm@3 196 'last_mod_file_time' => 2,
rlm@3 197 'last_mod_file_date' => 2,
rlm@3 198 'crc_32' => 2,
rlm@3 199 'compressed_size' => 2,
rlm@3 200 'uncompressed_size' => 2,
rlm@3 201 'filename_length' => 2,
rlm@3 202 'extra_field_length' => 2
rlm@3 203 )
rlm@3 204 );
rlm@3 205
rlm@3 206 $local_file_header['extract_version'] = sprintf('%1.1f', $local_file_header['raw']['extract_version'] / 10);
rlm@3 207 $local_file_header['host_os'] = $this->ZIPversionOSLookup(($local_file_header['raw']['extract_version'] & 0xFF00) >> 8);
rlm@3 208 $local_file_header['compression_method'] = $this->ZIPcompressionMethodLookup($local_file_header['raw']['compression_method']);
rlm@3 209 $local_file_header['compressed_size'] = $local_file_header['raw']['compressed_size'];
rlm@3 210 $local_file_header['uncompressed_size'] = $local_file_header['raw']['uncompressed_size'];
rlm@3 211 $local_file_header['flags'] = $this->ZIPparseGeneralPurposeFlags($local_file_header['raw']['general_flags'], $local_file_header['raw']['compression_method']);
rlm@3 212 $local_file_header['last_modified_timestamp'] = $this->DOStime2UNIXtime($local_file_header['raw']['last_mod_file_date'], $local_file_header['raw']['last_mod_file_time']);
rlm@3 213
rlm@3 214 $filename_extra_field_length = $local_file_header['raw']['filename_length'] + $local_file_header['raw']['extra_field_length'];
rlm@3 215 if ($filename_extra_field_length > 0) {
rlm@3 216 $zip_local_file_header .= fread($getid3->fp, $filename_extra_field_length);
rlm@3 217
rlm@3 218 if ($local_file_header['raw']['filename_length'] > 0) {
rlm@3 219 $local_file_header['filename'] = substr($zip_local_file_header, 30, $local_file_header['raw']['filename_length']);
rlm@3 220 }
rlm@3 221 if ($local_file_header['raw']['extra_field_length'] > 0) {
rlm@3 222 $local_file_header['raw']['extra_field_data'] = substr($zip_local_file_header, 30 + $local_file_header['raw']['filename_length'], $local_file_header['raw']['extra_field_length']);
rlm@3 223 }
rlm@3 224 }
rlm@3 225
rlm@3 226 $local_file_header['data_offset'] = ftell($getid3->fp);
rlm@3 227 fseek($getid3->fp, $local_file_header['raw']['compressed_size'], SEEK_CUR);
rlm@3 228
rlm@3 229 if ($local_file_header['flags']['data_descriptor_used']) {
rlm@3 230 $data_descriptor = fread($getid3->fp, 12);
rlm@3 231
rlm@3 232 getid3_lib::ReadSequence('LittleEndian2Int', $local_file_header['data_descriptor'], $data_descriptor, 0,
rlm@3 233 array (
rlm@3 234 'crc_32' => 4,
rlm@3 235 'compressed_size' => 4,
rlm@3 236 'uncompressed_size' => 4
rlm@3 237 )
rlm@3 238 );
rlm@3 239 }
rlm@3 240
rlm@3 241 return $local_file_header;
rlm@3 242 }
rlm@3 243
rlm@3 244
rlm@3 245
rlm@3 246 private function ZIPparseCentralDirectory() {
rlm@3 247
rlm@3 248 // shortcut
rlm@3 249 $getid3 = $this->getid3;
rlm@3 250
rlm@3 251 $central_directory['offset'] = ftell($getid3->fp);
rlm@3 252
rlm@3 253 $zip_central_directory = fread($getid3->fp, 46);
rlm@3 254
rlm@3 255 $central_directory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($zip_central_directory, 0, 4));
rlm@3 256
rlm@3 257 // invalid Central Directory Signature
rlm@3 258 if ($central_directory['raw']['signature'] != 0x02014B50) {
rlm@3 259 fseek($getid3->fp, $central_directory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
rlm@3 260 return false;
rlm@3 261 }
rlm@3 262
rlm@3 263 getid3_lib::ReadSequence('LittleEndian2Int', $central_directory['raw'], $zip_central_directory, 4,
rlm@3 264 array (
rlm@3 265 'create_version' => 2,
rlm@3 266 'extract_version' => 2,
rlm@3 267 'general_flags' => 2,
rlm@3 268 'compression_method' => 2,
rlm@3 269 'last_mod_file_time' => 2,
rlm@3 270 'last_mod_file_date' => 2,
rlm@3 271 'crc_32' => 4,
rlm@3 272 'compressed_size' => 4,
rlm@3 273 'uncompressed_size' => 4,
rlm@3 274 'filename_length' => 2,
rlm@3 275 'extra_field_length' => 2,
rlm@3 276 'file_comment_length' => 2,
rlm@3 277 'disk_number_start' => 2,
rlm@3 278 'internal_file_attrib' => 2,
rlm@3 279 'external_file_attrib' => 4,
rlm@3 280 'local_header_offset' => 4
rlm@3 281 )
rlm@3 282 );
rlm@3 283
rlm@3 284 $central_directory['entry_offset'] = $central_directory['raw']['local_header_offset'];
rlm@3 285 $central_directory['create_version'] = sprintf('%1.1f', $central_directory['raw']['create_version'] / 10);
rlm@3 286 $central_directory['extract_version'] = sprintf('%1.1f', $central_directory['raw']['extract_version'] / 10);
rlm@3 287 $central_directory['host_os'] = $this->ZIPversionOSLookup(($central_directory['raw']['extract_version'] & 0xFF00) >> 8);
rlm@3 288 $central_directory['compression_method'] = $this->ZIPcompressionMethodLookup($central_directory['raw']['compression_method']);
rlm@3 289 $central_directory['compressed_size'] = $central_directory['raw']['compressed_size'];
rlm@3 290 $central_directory['uncompressed_size'] = $central_directory['raw']['uncompressed_size'];
rlm@3 291 $central_directory['flags'] = $this->ZIPparseGeneralPurposeFlags($central_directory['raw']['general_flags'], $central_directory['raw']['compression_method']);
rlm@3 292 $central_directory['last_modified_timestamp'] = $this->DOStime2UNIXtime($central_directory['raw']['last_mod_file_date'], $central_directory['raw']['last_mod_file_time']);
rlm@3 293
rlm@3 294 $filename_extra_field_comment_length = $central_directory['raw']['filename_length'] + $central_directory['raw']['extra_field_length'] + $central_directory['raw']['file_comment_length'];
rlm@3 295 if ($filename_extra_field_comment_length > 0) {
rlm@3 296 $filename_extra_field_comment = fread($getid3->fp, $filename_extra_field_comment_length);
rlm@3 297
rlm@3 298 if ($central_directory['raw']['filename_length'] > 0) {
rlm@3 299 $central_directory['filename']= substr($filename_extra_field_comment, 0, $central_directory['raw']['filename_length']);
rlm@3 300 }
rlm@3 301 if ($central_directory['raw']['extra_field_length'] > 0) {
rlm@3 302 $central_directory['raw']['extra_field_data'] = substr($filename_extra_field_comment, $central_directory['raw']['filename_length'], $central_directory['raw']['extra_field_length']);
rlm@3 303 }
rlm@3 304 if ($central_directory['raw']['file_comment_length'] > 0) {
rlm@3 305 $central_directory['file_comment'] = substr($filename_extra_field_comment, $central_directory['raw']['filename_length'] + $central_directory['raw']['extra_field_length'], $central_directory['raw']['file_comment_length']);
rlm@3 306 }
rlm@3 307 }
rlm@3 308
rlm@3 309 return $central_directory;
rlm@3 310 }
rlm@3 311
rlm@3 312
rlm@3 313
rlm@3 314 private function ZIPparseEndOfCentralDirectory() {
rlm@3 315
rlm@3 316 // shortcut
rlm@3 317 $getid3 = $this->getid3;
rlm@3 318
rlm@3 319 $end_of_central_directory['offset'] = ftell($getid3->fp);
rlm@3 320
rlm@3 321 $zip_end_of_central_directory = fread($getid3->fp, 22);
rlm@3 322
rlm@3 323 $end_of_central_directory['signature'] = getid3_lib::LittleEndian2Int(substr($zip_end_of_central_directory, 0, 4));
rlm@3 324
rlm@3 325 // invalid End Of Central Directory Signature
rlm@3 326 if ($end_of_central_directory['signature'] != 0x06054B50) {
rlm@3 327 fseek($getid3->fp, $end_of_central_directory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
rlm@3 328 return false;
rlm@3 329 }
rlm@3 330
rlm@3 331 getid3_lib::ReadSequence('LittleEndian2Int', $end_of_central_directory, $zip_end_of_central_directory, 4,
rlm@3 332 array (
rlm@3 333 'disk_number_current' => 2,
rlm@3 334 'disk_number_start_directory' => 2,
rlm@3 335 'directory_entries_this_disk' => 2,
rlm@3 336 'directory_entries_total' => 2,
rlm@3 337 'directory_size' => 4,
rlm@3 338 'directory_offset' => 4,
rlm@3 339 'comment_length' => 2
rlm@3 340 )
rlm@3 341 );
rlm@3 342
rlm@3 343 if ($end_of_central_directory['comment_length'] > 0) {
rlm@3 344 $end_of_central_directory['comment'] = fread($getid3->fp, $end_of_central_directory['comment_length']);
rlm@3 345 }
rlm@3 346
rlm@3 347 return $end_of_central_directory;
rlm@3 348 }
rlm@3 349
rlm@3 350
rlm@3 351
rlm@3 352 public static function ZIPparseGeneralPurposeFlags($flag_bytes, $compression_method) {
rlm@3 353
rlm@3 354 $parsed_flags['encrypted'] = (bool)($flag_bytes & 0x0001);
rlm@3 355
rlm@3 356 switch ($compression_method) {
rlm@3 357 case 6:
rlm@3 358 $parsed_flags['dictionary_size'] = (($flag_bytes & 0x0002) ? 8192 : 4096);
rlm@3 359 $parsed_flags['shannon_fano_trees'] = (($flag_bytes & 0x0004) ? 3 : 2);
rlm@3 360 break;
rlm@3 361
rlm@3 362 case 8:
rlm@3 363 case 9:
rlm@3 364 switch (($flag_bytes & 0x0006) >> 1) {
rlm@3 365 case 0:
rlm@3 366 $parsed_flags['compression_speed'] = 'normal';
rlm@3 367 break;
rlm@3 368 case 1:
rlm@3 369 $parsed_flags['compression_speed'] = 'maximum';
rlm@3 370 break;
rlm@3 371 case 2:
rlm@3 372 $parsed_flags['compression_speed'] = 'fast';
rlm@3 373 break;
rlm@3 374 case 3:
rlm@3 375 $parsed_flags['compression_speed'] = 'superfast';
rlm@3 376 break;
rlm@3 377 }
rlm@3 378 break;
rlm@3 379 }
rlm@3 380 $parsed_flags['data_descriptor_used'] = (bool)($flag_bytes & 0x0008);
rlm@3 381
rlm@3 382 return $parsed_flags;
rlm@3 383 }
rlm@3 384
rlm@3 385
rlm@3 386
rlm@3 387 public static function ZIPversionOSLookup($index) {
rlm@3 388
rlm@3 389 static $lookup = array (
rlm@3 390 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
rlm@3 391 1 => 'Amiga',
rlm@3 392 2 => 'OpenVMS',
rlm@3 393 3 => 'Unix',
rlm@3 394 4 => 'VM/CMS',
rlm@3 395 5 => 'Atari ST',
rlm@3 396 6 => 'OS/2 H.P.F.S.',
rlm@3 397 7 => 'Macintosh',
rlm@3 398 8 => 'Z-System',
rlm@3 399 9 => 'CP/M',
rlm@3 400 10 => 'Windows NTFS',
rlm@3 401 11 => 'MVS',
rlm@3 402 12 => 'VSE',
rlm@3 403 13 => 'Acorn Risc',
rlm@3 404 14 => 'VFAT',
rlm@3 405 15 => 'Alternate MVS',
rlm@3 406 16 => 'BeOS',
rlm@3 407 17 => 'Tandem'
rlm@3 408 );
rlm@3 409 return (isset($lookup[$index]) ? $lookup[$index] : '[unknown]');
rlm@3 410 }
rlm@3 411
rlm@3 412
rlm@3 413
rlm@3 414 public static function ZIPcompressionMethodLookup($index) {
rlm@3 415
rlm@3 416 static $lookup = array (
rlm@3 417 0 => 'store',
rlm@3 418 1 => 'shrink',
rlm@3 419 2 => 'reduce-1',
rlm@3 420 3 => 'reduce-2',
rlm@3 421 4 => 'reduce-3',
rlm@3 422 5 => 'reduce-4',
rlm@3 423 6 => 'implode',
rlm@3 424 7 => 'tokenize',
rlm@3 425 8 => 'deflate',
rlm@3 426 9 => 'deflate64',
rlm@3 427 10 => 'PKWARE Date Compression Library Imploding'
rlm@3 428 );
rlm@3 429 return (isset($lookup[$index]) ? $lookup[$index] : '[unknown]');
rlm@3 430 }
rlm@3 431
rlm@3 432
rlm@3 433
rlm@3 434 public static function DOStime2UNIXtime($DOSdate, $DOStime) {
rlm@3 435
rlm@3 436 /*
rlm@3 437 // wFatDate
rlm@3 438 // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
rlm@3 439 // Bits Contents
rlm@3 440 // 0-4 Day of the month (1-31)
rlm@3 441 // 5-8 Month (1 = January, 2 = February, and so on)
rlm@3 442 // 9-15 Year offset from 1980 (add 1980 to get actual year)
rlm@3 443
rlm@3 444 $UNIXday = ($DOSdate & 0x001F);
rlm@3 445 $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
rlm@3 446 $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
rlm@3 447
rlm@3 448 // wFatTime
rlm@3 449 // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
rlm@3 450 // Bits Contents
rlm@3 451 // 0-4 Second divided by 2
rlm@3 452 // 5-10 Minute (0-59)
rlm@3 453 // 11-15 Hour (0-23 on a 24-hour clock)
rlm@3 454
rlm@3 455 $UNIXsecond = ($DOStime & 0x001F) * 2;
rlm@3 456 $UNIXminute = (($DOStime & 0x07E0) >> 5);
rlm@3 457 $UNIXhour = (($DOStime & 0xF800) >> 11);
rlm@3 458
rlm@3 459 return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
rlm@3 460 */
rlm@3 461 return gmmktime(($DOStime & 0xF800) >> 11, ($DOStime & 0x07E0) >> 5, ($DOStime & 0x001F) * 2, ($DOSdate & 0x01E0) >> 5, $DOSdate & 0x001F, (($DOSdate & 0xFE00) >> 9) + 1980);
rlm@3 462 }
rlm@3 463
rlm@3 464
rlm@3 465
rlm@3 466 public static function array_merge_clobber($array1, $array2) {
rlm@3 467
rlm@3 468 // written by kcØhireability*com
rlm@3 469 // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
rlm@3 470
rlm@3 471 if (!is_array($array1) || !is_array($array2)) {
rlm@3 472 return false;
rlm@3 473 }
rlm@3 474
rlm@3 475 $newarray = $array1;
rlm@3 476 foreach ($array2 as $key => $val) {
rlm@3 477 if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
rlm@3 478 $newarray[$key] = getid3_zip::array_merge_clobber($newarray[$key], $val);
rlm@3 479 } else {
rlm@3 480 $newarray[$key] = $val;
rlm@3 481 }
rlm@3 482 }
rlm@3 483 return $newarray;
rlm@3 484 }
rlm@3 485
rlm@3 486
rlm@3 487
rlm@3 488 public static function CreateDeepArray($array_path, $separator, $value) {
rlm@3 489
rlm@3 490 // assigns $value to a nested array path:
rlm@3 491 // $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt')
rlm@3 492 // is the same as:
rlm@3 493 // $foo = array ('path'=>array('to'=>'array('my'=>array('file.txt'))));
rlm@3 494 // or
rlm@3 495 // $foo['path']['to']['my'] = 'file.txt';
rlm@3 496
rlm@3 497 while ($array_path{0} == $separator) {
rlm@3 498 $array_path = substr($array_path, 1);
rlm@3 499 }
rlm@3 500 if (($pos = strpos($array_path, $separator)) !== false) {
rlm@3 501 return array (substr($array_path, 0, $pos) => getid3_zip::CreateDeepArray(substr($array_path, $pos + 1), $separator, $value));
rlm@3 502 }
rlm@3 503
rlm@3 504 return array ($array_path => $value);
rlm@3 505 }
rlm@3 506
rlm@3 507 }
rlm@3 508
rlm@3 509
rlm@3 510 ?>