Ignore:
Timestamp:
Jul 7, 2009, 10:27:37 PM (15 years ago)
Author:
vdigital
Message:

Change: getid3 upgraded to -> 1.7.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/charlies_content/getid3/getid3/module.misc.iso.php

    r3318 r3544  
    11<?php
    2 // +----------------------------------------------------------------------+
    3 // | PHP version 5                                                        |
    4 // +----------------------------------------------------------------------+
    5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
    6 // +----------------------------------------------------------------------+
    7 // | This source file is subject to version 2 of the GPL license,         |
    8 // | that is bundled with this package in the file license.txt and is     |
    9 // | available through the world-wide-web at the following url:           |
    10 // | http://www.gnu.org/copyleft/gpl.html                                 |
    11 // +----------------------------------------------------------------------+
    12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
    13 // +----------------------------------------------------------------------+
    14 // | Authors: James Heinrich <infoØgetid3*org>                            |
    15 // |          Allan Hansen <ahØartemis*dk>                                |
    16 // +----------------------------------------------------------------------+
    17 // | module.misc.iso.php                                                  |
    18 // | Module for analyzing ISO files                                       |
    19 // | dependencies: NONE                                                   |
    20 // +----------------------------------------------------------------------+
    21 //
    22 // $Id$
    23 
    24 
    25 
    26 class getid3_iso extends getid3_handler
     2/////////////////////////////////////////////////////////////////
     3/// getID3() by James Heinrich <info@getid3.org>               //
     4//  available at http://getid3.sourceforge.net                 //
     5//            or http://www.getid3.org                         //
     6/////////////////////////////////////////////////////////////////
     7// See readme.txt for more details                             //
     8/////////////////////////////////////////////////////////////////
     9//                                                             //
     10// module.misc.iso.php                                         //
     11// module for analyzing ISO files                              //
     12// dependencies: NONE                                          //
     13//                                                            ///
     14/////////////////////////////////////////////////////////////////
     15
     16
     17class getid3_iso
    2718{
    2819
    29     public function Analyze() {
    30        
    31         $getid3 = $this->getid3;
    32        
    33         $getid3->info['fileformat'] = 'iso';
    34 
    35         for ($i = 16; $i <= 19; $i++) {
    36             fseek($getid3->fp, 2048 * $i, SEEK_SET);
    37             $iso_header = fread($getid3->fp, 2048);
    38             if (substr($iso_header, 1, 5) == 'CD001') {
    39                 switch (ord($iso_header{0})) {
    40                     case 1:
    41                         $getid3->info['iso']['primary_volume_descriptor']['offset'] = 2048 * $i;
    42                         $this->ParsePrimaryVolumeDescriptor($iso_header);
    43                         break;
    44 
    45                     case 2:
    46                         $getid3->info['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i;
    47                         $this->ParseSupplementaryVolumeDescriptor($iso_header);
    48                         break;
    49 
    50                     default:
    51                         // skip
    52                         break;
    53                 }
    54             }
    55         }
    56 
    57         $this->ParsePathTable();
    58 
    59         $getid3->info['iso']['files'] = array ();
    60         foreach ($getid3->info['iso']['path_table']['directories'] as $directory_num => $directory_data) {
    61             $getid3->info['iso']['directories'][$directory_num] = $this->ParseDirectoryRecord($directory_data);
    62         }
    63 
    64         return true;
    65     }
    66 
    67 
    68 
    69     private function ParsePrimaryVolumeDescriptor(&$iso_header) {
    70        
    71         $getid3 = $this->getid3;
    72        
    73         // ISO integer values are stored *BOTH* Little-Endian AND Big-Endian format!!
    74         // ie 12345 == 0x3039  is stored as $39 $30 $30 $39 in a 4-byte field
    75 
    76         $getid3->info['iso']['primary_volume_descriptor']['raw'] = array ();
    77         $info_iso_primaryVD     = &$getid3->info['iso']['primary_volume_descriptor'];
    78         $info_iso_primaryVD_raw = &$info_iso_primaryVD['raw'];
    79 
    80         $info_iso_primaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($iso_header,    0, 1));
    81         $info_iso_primaryVD_raw['standard_identifier']    = substr($iso_header,    1, 5);
    82         if ($info_iso_primaryVD_raw['standard_identifier'] != 'CD001') {
    83             throw new getid3_exception('Expected "CD001" at offset ('.($info_iso_primaryVD['offset'] + 1).'), found "'.$info_iso_primaryVD_raw['standard_identifier'].'" instead');
    84         }
    85        
    86         getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_primaryVD_raw, $iso_header, 6,
    87             array (
    88                 'volume_descriptor_version'     => 1,
    89                 'IGNORE-unused_1'               => 1,
    90                 'system_identifier'             => -32,     // string
    91                 'volume_identifier'             => -32,     // string
    92                 'IGNORE-unused_2'               => 8,
    93                 'volume_space_size'             => 4,
    94                 'IGNORE-1'                      => 4,
    95                 'IGNORE-unused_3'               => 32,
    96                 'volume_set_size'               => 2,
    97                 'IGNORE-2'                      => 2,
    98                 'volume_sequence_number'        => 2,
    99                 'IGNORE-3'                      => 2,
    100                 'logical_block_size'            => 2,
    101                 'IGNORE-4'                      => 2,
    102                 'path_table_size'               => 4,
    103                 'IGNORE-5'                      => 4,
    104                 'path_table_l_location'         => 2,
    105                 'IGNORE-6'                      => 2,
    106                 'path_table_l_opt_location'     => 2,
    107                 'IGNORE-7'                      => 2,
    108                 'path_table_m_location'         => 2,
    109                 'IGNORE-8'                      => 2,
    110                 'path_table_m_opt_location'     => 2,
    111                 'IGNORE-9'                      => 2,
    112                 'root_directory_record'         => -34,     // string
    113                 'volume_set_identifier'         => -128,    // string
    114                 'publisher_identifier'          => -128,    // string
    115                 'data_preparer_identifier'      => -128,    // string
    116                 'application_identifier'        => -128,    // string
    117                 'copyright_file_identifier'     => -37,     // string
    118                 'abstract_file_identifier'      => -37,     // string
    119                 'bibliographic_file_identifier' => -37,     // string
    120                 'volume_creation_date_time'     => -17,     // string
    121                 'volume_modification_date_time' => -17,     // string
    122                 'volume_expiration_date_time'   => -17,     // string
    123                 'volume_effective_date_time'    => -17,     // string
    124                 'file_structure_version'        => 1,
    125                 'IGNORE-unused_4'               => 1,
    126                 'application_data'              => -512     // string
    127             )
    128         );
    129 
    130         $info_iso_primaryVD['system_identifier']             = trim($info_iso_primaryVD_raw['system_identifier']);
    131         $info_iso_primaryVD['volume_identifier']             = trim($info_iso_primaryVD_raw['volume_identifier']);
    132         $info_iso_primaryVD['volume_set_identifier']         = trim($info_iso_primaryVD_raw['volume_set_identifier']);
    133         $info_iso_primaryVD['publisher_identifier']          = trim($info_iso_primaryVD_raw['publisher_identifier']);
    134         $info_iso_primaryVD['data_preparer_identifier']      = trim($info_iso_primaryVD_raw['data_preparer_identifier']);
    135         $info_iso_primaryVD['application_identifier']        = trim($info_iso_primaryVD_raw['application_identifier']);
    136         $info_iso_primaryVD['copyright_file_identifier']     = trim($info_iso_primaryVD_raw['copyright_file_identifier']);
    137         $info_iso_primaryVD['abstract_file_identifier']      = trim($info_iso_primaryVD_raw['abstract_file_identifier']);
    138         $info_iso_primaryVD['bibliographic_file_identifier'] = trim($info_iso_primaryVD_raw['bibliographic_file_identifier']);
    139        
    140         $info_iso_primaryVD['volume_creation_date_time']     = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_creation_date_time']);
    141         $info_iso_primaryVD['volume_modification_date_time'] = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_modification_date_time']);
    142         $info_iso_primaryVD['volume_expiration_date_time']   = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_expiration_date_time']);
    143         $info_iso_primaryVD['volume_effective_date_time']    = getid3_iso::ISOtimeText2UNIXtime($info_iso_primaryVD_raw['volume_effective_date_time']);
    144 
    145         if (($info_iso_primaryVD_raw['volume_space_size'] * 2048) > $getid3->info['filesize']) {
    146             throw new getid3_exception('Volume Space Size ('.($info_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$getid3->info['filesize'].' bytes) (truncated file?)');
    147         }
    148 
    149         return true;
    150     }
    151 
    152 
    153 
    154     private function ParseSupplementaryVolumeDescriptor(&$iso_header) {
    155        
    156         $getid3 = $this->getid3;
    157        
    158         // ISO integer values are stored Both-Endian format!!
    159         // ie 12345 == 0x3039  is stored as $39 $30 $30 $39 in a 4-byte field
    160 
    161         $getid3->info['iso']['supplementary_volume_descriptor']['raw'] = array ();
    162         $info_iso_supplementaryVD     = &$getid3->info['iso']['supplementary_volume_descriptor'];
    163         $info_iso_supplementaryVD_raw = &$info_iso_supplementaryVD['raw'];
    164 
    165         $info_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($iso_header, 0, 1));
    166         $info_iso_supplementaryVD_raw['standard_identifier']    = substr($iso_header, 1, 5);
    167         if ($info_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') {
    168             throw new getid3_exception('Expected "CD001" at offset ('.($info_iso_supplementaryVD['offset'] + 1).'), found "'.$info_iso_supplementaryVD_raw['standard_identifier'].'" instead');
    169         }
    170 
    171         getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_supplementaryVD_raw, $iso_header, 6,
    172             array (
    173                 'volume_descriptor_version'     => 1,
    174                 'IGNORE-unused_1'               => -1,
    175                 'system_identifier'             => -32,
    176                 'volume_identifier'             => -32,
    177                 'IGNORE-unused_2'               => -8,
    178                 'volume_space_size'             => 4,
    179                 'IGNORE-1'                      => 4,
    180                 'IGNORE-unused_3'               => -32,
    181                 'volume_set_size'               => 2,
    182                 'IGNORE-2'                      => 2,
    183                 'volume_sequence_number'        => 2,
    184                 'IGNORE-3'                      => 2,
    185                 'logical_block_size'            => 2,
    186                 'IGNORE-4'                      => 2,
    187                 'path_table_size'               => 4,
    188                 'IGNORE-5'                      => 4,
    189                 'path_table_l_location'         => 2,
    190                 'IGNORE-6'                      => 2,
    191                 'path_table_l_opt_location'     => 2,
    192                 'IGNORE-7'                      => 2,
    193                 'path_table_m_location'         => 2,
    194                 'IGNORE-8'                      => 2,
    195                 'path_table_m_opt_location'     => 2,
    196                 'IGNORE-9'                      => 2,
    197                 'root_directory_record'         => -34,
    198                 'volume_set_identifier'         => -128,
    199                 'publisher_identifier'          => -128,
    200                 'data_preparer_identifier'      => -128,
    201                 'application_identifier'        => -128,
    202                 'copyright_file_identifier'     => -37,
    203                 'abstract_file_identifier'      => -37,
    204                 'bibliographic_file_identifier' => -37,
    205                 'volume_creation_date_time'     => -17,
    206                 'volume_modification_date_time' => -17,
    207                 'volume_expiration_date_time'   => -17,
    208                 'volume_effective_date_time'    => -17,
    209                 'file_structure_version'        => 1,
    210                 'IGNORE-unused_4'               => 1,
    211                 'application_data'              => -512
    212             )
    213         );
    214 
    215         $info_iso_supplementaryVD['system_identifier']              = trim($info_iso_supplementaryVD_raw['system_identifier']);
    216         $info_iso_supplementaryVD['volume_identifier']              = trim($info_iso_supplementaryVD_raw['volume_identifier']);
    217         $info_iso_supplementaryVD['volume_set_identifier']          = trim($info_iso_supplementaryVD_raw['volume_set_identifier']);
    218         $info_iso_supplementaryVD['publisher_identifier']           = trim($info_iso_supplementaryVD_raw['publisher_identifier']);
    219         $info_iso_supplementaryVD['data_preparer_identifier']       = trim($info_iso_supplementaryVD_raw['data_preparer_identifier']);
    220         $info_iso_supplementaryVD['application_identifier']         = trim($info_iso_supplementaryVD_raw['application_identifier']);
    221         $info_iso_supplementaryVD['copyright_file_identifier']      = trim($info_iso_supplementaryVD_raw['copyright_file_identifier']);
    222         $info_iso_supplementaryVD['abstract_file_identifier']       = trim($info_iso_supplementaryVD_raw['abstract_file_identifier']);
    223         $info_iso_supplementaryVD['bibliographic_file_identifier']  = trim($info_iso_supplementaryVD_raw['bibliographic_file_identifier']);
    224        
    225         $info_iso_supplementaryVD['volume_creation_date_time']      = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_creation_date_time']);
    226         $info_iso_supplementaryVD['volume_modification_date_time']  = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_modification_date_time']);
    227         $info_iso_supplementaryVD['volume_expiration_date_time']    = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_expiration_date_time']);
    228         $info_iso_supplementaryVD['volume_effective_date_time']     = getid3_iso::ISOtimeText2UNIXtime($info_iso_supplementaryVD_raw['volume_effective_date_time']);
    229 
    230         if (($info_iso_supplementaryVD_raw['volume_space_size'] * $info_iso_supplementaryVD_raw['logical_block_size']) > $getid3->info['filesize']) {
    231             throw new getid3_exception('Volume Space Size ('.($info_iso_supplementaryVD_raw['volume_space_size'] * $info_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$getid3->info['filesize'].' bytes) (truncated file?)');
    232         }
    233 
    234         return true;
    235     }
    236 
    237 
    238 
    239     private function ParsePathTable() {
    240        
    241         $getid3 = $this->getid3;
    242        
    243         if (!isset($getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) {
    244             return false;
    245         }
    246         if (isset($getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) {
    247             $path_table_location = $getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'];
    248             $path_table_size     = $getid3->info['iso']['supplementary_volume_descriptor']['raw']['path_table_size'];
    249             $text_encoding       = 'UTF-16BE'; // Big-Endian Unicode
    250         }
    251         else {
    252             $path_table_location = $getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'];
    253             $path_table_size     = $getid3->info['iso']['primary_volume_descriptor']['raw']['path_table_size'];
    254             $text_encoding       = 'ISO-8859-1'; // Latin-1
    255         }
    256 
    257         if (($path_table_location * 2048) > $getid3->info['filesize']) {
    258             throw new getid3_exception('Path Table Location specifies an offset ('.($path_table_location * 2048).') beyond the end-of-file ('.$getid3->info['filesize'].')');
    259         }
    260 
    261         $getid3->info['iso']['path_table']['offset'] = $path_table_location * 2048;
    262         fseek($getid3->fp, $getid3->info['iso']['path_table']['offset'], SEEK_SET);
    263         $getid3->info['iso']['path_table']['raw'] = fread($getid3->fp, $path_table_size);
    264 
    265         $offset = 0;
    266         $pathcounter = 1;
    267         while ($offset < $path_table_size) {
    268            
    269             $getid3->info['iso']['path_table']['directories'][$pathcounter] = array ();
    270             $info_iso_pathtable_directories_current = &$getid3->info['iso']['path_table']['directories'][$pathcounter];
    271 
    272             getid3_lib::ReadSequence('LittleEndian2Int', $info_iso_pathtable_directories_current, $getid3->info['iso']['path_table']['raw'], $offset,
    273                 array (
    274                        'length'           => 1,
    275                     'extended_length'  => 1,
    276                     'location_logical' => 4,
    277                     'parent_directory' => 2,
    278                 )
    279             );
    280            
    281             $info_iso_pathtable_directories_current['name'] = substr($getid3->info['iso']['path_table']['raw'], $offset+8, $info_iso_pathtable_directories_current['length']);
    282            
    283             $offset += 8 + $info_iso_pathtable_directories_current['length'] + ($info_iso_pathtable_directories_current['length'] % 2);
    284 
    285             $info_iso_pathtable_directories_current['name_ascii'] = $getid3->iconv($text_encoding, $getid3->encoding, $info_iso_pathtable_directories_current['name'], true);
    286 
    287             $info_iso_pathtable_directories_current['location_bytes'] = $info_iso_pathtable_directories_current['location_logical'] * 2048;
    288             if ($pathcounter == 1) {
    289                 $info_iso_pathtable_directories_current['full_path'] = '/';
    290             }
    291             else {
    292                 $info_iso_pathtable_directories_current['full_path'] = $getid3->info['iso']['path_table']['directories'][$info_iso_pathtable_directories_current['parent_directory']]['full_path'].$info_iso_pathtable_directories_current['name_ascii'].'/';
    293             }
    294             $full_path_array[] = $info_iso_pathtable_directories_current['full_path'];
    295 
    296             $pathcounter++;
    297         }
    298 
    299         return true;
    300     }
    301 
    302 
    303 
    304     private function ParseDirectoryRecord($directory_data) {
    305        
    306         $getid3 = $this->getid3;
    307        
    308         $text_encoding = isset($getid3->info['iso']['supplementary_volume_descriptor']) ? 'UTF-16BE' : 'ISO-8859-1';
    309 
    310         fseek($getid3->fp, $directory_data['location_bytes'], SEEK_SET);
    311         $directory_record_data = fread($getid3->fp, 1);
    312        
    313         while (ord($directory_record_data{0}) > 33) {
    314 
    315             $directory_record_data .= fread($getid3->fp, ord($directory_record_data{0}) - 1);
    316            
    317             $this_directory_record = array ();
    318             $this_directory_record['raw'] = array ();
    319             $this_directory_record_raw = &$this_directory_record['raw'];
    320            
    321             getid3_lib::ReadSequence('LittleEndian2Int', $this_directory_record_raw, $directory_record_data, 0,
    322                 array (
    323                     'length'                    => 1,
    324                     'extended_attribute_length' => 1,
    325                     'offset_logical'            => 4,
    326                     'IGNORE-1'                  => 4,
    327                     'filesize'                  => 4,
    328                     'IGNORE-2'                  => 4,
    329                     'recording_date_time'       => -7,
    330                     'file_flags'                => 1,
    331                     'file_unit_size'            => 1,
    332                     'interleave_gap_size'       => 1,
    333                     'volume_sequence_number'    => 2,
    334                     'IGNORE-3'                  => 2,
    335                     'file_identifier_length'    => 1,
    336                 )
    337             );
    338 
    339             $this_directory_record_raw['file_identifier'] = substr($directory_record_data, 33, $this_directory_record_raw['file_identifier_length']);
    340            
    341             $this_directory_record['file_identifier_ascii']     = $getid3->iconv($text_encoding, $getid3->encoding, $this_directory_record_raw['file_identifier'], true);
    342             $this_directory_record['filesize']                  = $this_directory_record_raw['filesize'];
    343             $this_directory_record['offset_bytes']              = $this_directory_record_raw['offset_logical'] * 2048;
    344             $this_directory_record['file_flags']['hidden']      = (bool)($this_directory_record_raw['file_flags'] & 0x01);
    345             $this_directory_record['file_flags']['directory']   = (bool)($this_directory_record_raw['file_flags'] & 0x02);
    346             $this_directory_record['file_flags']['associated']  = (bool)($this_directory_record_raw['file_flags'] & 0x04);
    347             $this_directory_record['file_flags']['extended']    = (bool)($this_directory_record_raw['file_flags'] & 0x08);
    348             $this_directory_record['file_flags']['permissions'] = (bool)($this_directory_record_raw['file_flags'] & 0x10);
    349             $this_directory_record['file_flags']['multiple']    = (bool)($this_directory_record_raw['file_flags'] & 0x80);
    350             $this_directory_record['recording_timestamp']       = getid3_iso::ISOtime2UNIXtime($this_directory_record_raw['recording_date_time']);
    351 
    352             if ($this_directory_record['file_flags']['directory']) {
    353                 $this_directory_record['filename'] = $directory_data['full_path'];
    354             }
    355             else {
    356                 $this_directory_record['filename'] = $directory_data['full_path'].getid3_iso::ISOstripFilenameVersion($this_directory_record['file_identifier_ascii']);
    357                 $getid3->info['iso']['files'] = getid3_iso::array_merge_clobber($getid3->info['iso']['files'], getid3_iso::CreateDeepArray($this_directory_record['filename'], '/', $this_directory_record['filesize']));
    358             }
    359            
    360             $directory_record[]    = $this_directory_record;
    361             $directory_record_data = fread($getid3->fp, 1);
    362         }
    363        
    364         return $directory_record;
    365     }
    366 
    367 
    368 
    369     public static function ISOstripFilenameVersion($iso_filename) {
    370 
    371         // convert 'filename.ext;1' to 'filename.ext'
    372         if (!strstr($iso_filename, ';')) {
    373             return $iso_filename;
    374         }
    375         return substr($iso_filename, 0, strpos($iso_filename, ';'));
    376     }
    377 
    378 
    379 
    380     public static function ISOtimeText2UNIXtime($iso_time) {
    381 
    382         if (!(int)substr($iso_time, 0, 4)) {
    383             return false;
    384         }
    385        
    386         return gmmktime((int)substr($iso_time, 8, 2), (int)substr($iso_time, 10, 2), (int)substr($iso_time, 12, 2), (int)substr($iso_time, 4, 2), (int)substr($iso_time, 6, 2), (int)substr($iso_time, 0, 4));
    387     }
    388    
    389    
    390 
    391     public static function ISOtime2UNIXtime($iso_time) {
    392    
    393         // Represented by seven bytes:
    394         // 1: Number of years since 1900
    395         // 2: Month of the year from 1 to 12
    396         // 3: Day of the Month from 1 to 31
    397         // 4: Hour of the day from 0 to 23
    398         // 5: Minute of the hour from 0 to 59
    399         // 6: second of the minute from 0 to 59
    400         // 7: Offset from Greenwich Mean Time in number of 15 minute intervals from -48 (West) to +52 (East)
    401 
    402         return gmmktime(ord($iso_time[3]), ord($iso_time[4]), ord($iso_time[5]), ord($iso_time[1]), ord($iso_time[2]), ord($iso_time[0]) + 1900);
    403     }
    404 
    405 
    406 
    407     public static function array_merge_clobber($array1, $array2) {
    408 
    409         // written by kcØhireability*com
    410         // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
    411        
    412         if (!is_array($array1) || !is_array($array2)) {
    413             return false;
    414         }
    415        
    416         $newarray = $array1;
    417         foreach ($array2 as $key => $val) {
    418             if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
    419                 $newarray[$key] = getid3_iso::array_merge_clobber($newarray[$key], $val);
    420             } else {
    421                 $newarray[$key] = $val;
    422             }
    423         }
    424         return $newarray;
    425     }
    426    
    427    
    428    
    429     public static function CreateDeepArray($array_path, $separator, $value) {
    430 
    431         // assigns $value to a nested array path:
    432         //   $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt')
    433         // is the same as:
    434         //   $foo = array ('path'=>array('to'=>'array('my'=>array('file.txt'))));
    435         // or
    436         //   $foo['path']['to']['my'] = 'file.txt';
    437        
    438         while ($array_path{0} == $separator) {
    439             $array_path = substr($array_path, 1);
    440         }
    441         if (($pos = strpos($array_path, $separator)) !== false) {
    442             return array (substr($array_path, 0, $pos) => getid3_iso::CreateDeepArray(substr($array_path, $pos + 1), $separator, $value));
    443         }
    444        
    445         return array ($array_path => $value);
    446     }
     20        function getid3_iso($fd, &$ThisFileInfo) {
     21                $ThisFileInfo['fileformat'] = 'iso';
     22
     23                for ($i = 16; $i <= 19; $i++) {
     24                        fseek($fd, 2048 * $i, SEEK_SET);
     25                        $ISOheader = fread($fd, 2048);
     26                        if (substr($ISOheader, 1, 5) == 'CD001') {
     27                                switch (ord($ISOheader{0})) {
     28                                        case 1:
     29                                                $ThisFileInfo['iso']['primary_volume_descriptor']['offset'] = 2048 * $i;
     30                                                $this->ParsePrimaryVolumeDescriptor($ISOheader, $ThisFileInfo);
     31                                                break;
     32
     33                                        case 2:
     34                                                $ThisFileInfo['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i;
     35                                                $this->ParseSupplementaryVolumeDescriptor($ISOheader, $ThisFileInfo);
     36                                                break;
     37
     38                                        default:
     39                                                // skip
     40                                                break;
     41                                }
     42                        }
     43                }
     44
     45                $this->ParsePathTable($fd, $ThisFileInfo);
     46
     47                $ThisFileInfo['iso']['files'] = array();
     48                foreach ($ThisFileInfo['iso']['path_table']['directories'] as $directorynum => $directorydata) {
     49
     50                        $ThisFileInfo['iso']['directories'][$directorynum] = $this->ParseDirectoryRecord($fd, $directorydata, $ThisFileInfo);
     51
     52                }
     53
     54                return true;
     55
     56        }
     57
     58
     59        function ParsePrimaryVolumeDescriptor(&$ISOheader, &$ThisFileInfo) {
     60                // ISO integer values are stored *BOTH* Little-Endian AND Big-Endian format!!
     61                // ie 12345 == 0x3039  is stored as $39 $30 $30 $39 in a 4-byte field
     62
     63                // shortcuts
     64                $ThisFileInfo['iso']['primary_volume_descriptor']['raw'] = array();
     65                $thisfile_iso_primaryVD     = &$ThisFileInfo['iso']['primary_volume_descriptor'];
     66                $thisfile_iso_primaryVD_raw = &$thisfile_iso_primaryVD['raw'];
     67
     68                $thisfile_iso_primaryVD_raw['volume_descriptor_type']         = getid3_lib::LittleEndian2Int(substr($ISOheader,    0, 1));
     69                $thisfile_iso_primaryVD_raw['standard_identifier']            =                  substr($ISOheader,    1, 5);
     70                if ($thisfile_iso_primaryVD_raw['standard_identifier'] != 'CD001') {
     71                        $ThisFileInfo['error'][] = 'Expected "CD001" at offset ('.($thisfile_iso_primaryVD['offset'] + 1).'), found "'.$thisfile_iso_primaryVD_raw['standard_identifier'].'" instead';
     72                        unset($ThisFileInfo['fileformat']);
     73                        unset($ThisFileInfo['iso']);
     74                        return false;
     75                }
     76
     77
     78                $thisfile_iso_primaryVD_raw['volume_descriptor_version']     = getid3_lib::LittleEndian2Int(substr($ISOheader,    6, 1));
     79                //$thisfile_iso_primaryVD_raw['unused_1']                      =                              substr($ISOheader,    7, 1);
     80                $thisfile_iso_primaryVD_raw['system_identifier']             =                              substr($ISOheader,    8, 32);
     81                $thisfile_iso_primaryVD_raw['volume_identifier']             =                              substr($ISOheader,   40, 32);
     82                //$thisfile_iso_primaryVD_raw['unused_2']                      =                              substr($ISOheader,   72, 8);
     83                $thisfile_iso_primaryVD_raw['volume_space_size']             = getid3_lib::LittleEndian2Int(substr($ISOheader,   80, 4));
     84                //$thisfile_iso_primaryVD_raw['unused_3']                      =                              substr($ISOheader,   88, 32);
     85                $thisfile_iso_primaryVD_raw['volume_set_size']               = getid3_lib::LittleEndian2Int(substr($ISOheader,  120, 2));
     86                $thisfile_iso_primaryVD_raw['volume_sequence_number']        = getid3_lib::LittleEndian2Int(substr($ISOheader,  124, 2));
     87                $thisfile_iso_primaryVD_raw['logical_block_size']            = getid3_lib::LittleEndian2Int(substr($ISOheader,  128, 2));
     88                $thisfile_iso_primaryVD_raw['path_table_size']               = getid3_lib::LittleEndian2Int(substr($ISOheader,  132, 4));
     89                $thisfile_iso_primaryVD_raw['path_table_l_location']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  140, 2));
     90                $thisfile_iso_primaryVD_raw['path_table_l_opt_location']     = getid3_lib::LittleEndian2Int(substr($ISOheader,  144, 2));
     91                $thisfile_iso_primaryVD_raw['path_table_m_location']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  148, 2));
     92                $thisfile_iso_primaryVD_raw['path_table_m_opt_location']     = getid3_lib::LittleEndian2Int(substr($ISOheader,  152, 2));
     93                $thisfile_iso_primaryVD_raw['root_directory_record']         =                              substr($ISOheader,  156, 34);
     94                $thisfile_iso_primaryVD_raw['volume_set_identifier']         =                              substr($ISOheader,  190, 128);
     95                $thisfile_iso_primaryVD_raw['publisher_identifier']          =                              substr($ISOheader,  318, 128);
     96                $thisfile_iso_primaryVD_raw['data_preparer_identifier']      =                              substr($ISOheader,  446, 128);
     97                $thisfile_iso_primaryVD_raw['application_identifier']        =                              substr($ISOheader,  574, 128);
     98                $thisfile_iso_primaryVD_raw['copyright_file_identifier']     =                              substr($ISOheader,  702, 37);
     99                $thisfile_iso_primaryVD_raw['abstract_file_identifier']      =                              substr($ISOheader,  739, 37);
     100                $thisfile_iso_primaryVD_raw['bibliographic_file_identifier'] =                              substr($ISOheader,  776, 37);
     101                $thisfile_iso_primaryVD_raw['volume_creation_date_time']     =                              substr($ISOheader,  813, 17);
     102                $thisfile_iso_primaryVD_raw['volume_modification_date_time'] =                              substr($ISOheader,  830, 17);
     103                $thisfile_iso_primaryVD_raw['volume_expiration_date_time']   =                              substr($ISOheader,  847, 17);
     104                $thisfile_iso_primaryVD_raw['volume_effective_date_time']    =                              substr($ISOheader,  864, 17);
     105                $thisfile_iso_primaryVD_raw['file_structure_version']        = getid3_lib::LittleEndian2Int(substr($ISOheader,  881, 1));
     106                //$thisfile_iso_primaryVD_raw['unused_4']                      = getid3_lib::LittleEndian2Int(substr($ISOheader,  882, 1));
     107                $thisfile_iso_primaryVD_raw['application_data']              =                              substr($ISOheader,  883, 512);
     108                //$thisfile_iso_primaryVD_raw['unused_5']                      =                              substr($ISOheader, 1395, 653);
     109
     110                $thisfile_iso_primaryVD['system_identifier']             = trim($thisfile_iso_primaryVD_raw['system_identifier']);
     111                $thisfile_iso_primaryVD['volume_identifier']             = trim($thisfile_iso_primaryVD_raw['volume_identifier']);
     112                $thisfile_iso_primaryVD['volume_set_identifier']         = trim($thisfile_iso_primaryVD_raw['volume_set_identifier']);
     113                $thisfile_iso_primaryVD['publisher_identifier']          = trim($thisfile_iso_primaryVD_raw['publisher_identifier']);
     114                $thisfile_iso_primaryVD['data_preparer_identifier']      = trim($thisfile_iso_primaryVD_raw['data_preparer_identifier']);
     115                $thisfile_iso_primaryVD['application_identifier']        = trim($thisfile_iso_primaryVD_raw['application_identifier']);
     116                $thisfile_iso_primaryVD['copyright_file_identifier']     = trim($thisfile_iso_primaryVD_raw['copyright_file_identifier']);
     117                $thisfile_iso_primaryVD['abstract_file_identifier']      = trim($thisfile_iso_primaryVD_raw['abstract_file_identifier']);
     118                $thisfile_iso_primaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_primaryVD_raw['bibliographic_file_identifier']);
     119                $thisfile_iso_primaryVD['volume_creation_date_time']     = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_creation_date_time']);
     120                $thisfile_iso_primaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_modification_date_time']);
     121                $thisfile_iso_primaryVD['volume_expiration_date_time']   = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_expiration_date_time']);
     122                $thisfile_iso_primaryVD['volume_effective_date_time']    = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_effective_date_time']);
     123
     124                if (($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048) > $ThisFileInfo['filesize']) {
     125                        $ThisFileInfo['error'][] = 'Volume Space Size ('.($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$ThisFileInfo['filesize'].' bytes) (truncated file?)';
     126                }
     127
     128                return true;
     129        }
     130
     131
     132        function ParseSupplementaryVolumeDescriptor(&$ISOheader, &$ThisFileInfo) {
     133                // ISO integer values are stored Both-Endian format!!
     134                // ie 12345 == 0x3039  is stored as $39 $30 $30 $39 in a 4-byte field
     135
     136                // shortcuts
     137                $ThisFileInfo['iso']['supplementary_volume_descriptor']['raw'] = array();
     138                $thisfile_iso_supplementaryVD     = &$ThisFileInfo['iso']['supplementary_volume_descriptor'];
     139                $thisfile_iso_supplementaryVD_raw = &$thisfile_iso_supplementaryVD['raw'];
     140
     141                $thisfile_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader,    0, 1));
     142                $thisfile_iso_supplementaryVD_raw['standard_identifier']    =                  substr($ISOheader,    1, 5);
     143                if ($thisfile_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') {
     144                        $ThisFileInfo['error'][] = 'Expected "CD001" at offset ('.($thisfile_iso_supplementaryVD['offset'] + 1).'), found "'.$thisfile_iso_supplementaryVD_raw['standard_identifier'].'" instead';
     145                        unset($ThisFileInfo['fileformat']);
     146                        unset($ThisFileInfo['iso']);
     147                        return false;
     148                }
     149
     150                $thisfile_iso_supplementaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader,    6, 1));
     151                //$thisfile_iso_supplementaryVD_raw['unused_1']                  =                              substr($ISOheader,    7, 1);
     152                $thisfile_iso_supplementaryVD_raw['system_identifier']         =                              substr($ISOheader,    8, 32);
     153                $thisfile_iso_supplementaryVD_raw['volume_identifier']         =                              substr($ISOheader,   40, 32);
     154                //$thisfile_iso_supplementaryVD_raw['unused_2']                  =                              substr($ISOheader,   72, 8);
     155                $thisfile_iso_supplementaryVD_raw['volume_space_size']         = getid3_lib::LittleEndian2Int(substr($ISOheader,   80, 4));
     156                if ($thisfile_iso_supplementaryVD_raw['volume_space_size'] == 0) {
     157                        // Supplementary Volume Descriptor not used
     158                        //unset($thisfile_iso_supplementaryVD);
     159                        //return false;
     160                }
     161
     162                //$thisfile_iso_supplementaryVD_raw['unused_3']                       =                              substr($ISOheader,   88, 32);
     163                $thisfile_iso_supplementaryVD_raw['volume_set_size']                = getid3_lib::LittleEndian2Int(substr($ISOheader,  120, 2));
     164                $thisfile_iso_supplementaryVD_raw['volume_sequence_number']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  124, 2));
     165                $thisfile_iso_supplementaryVD_raw['logical_block_size']             = getid3_lib::LittleEndian2Int(substr($ISOheader,  128, 2));
     166                $thisfile_iso_supplementaryVD_raw['path_table_size']                = getid3_lib::LittleEndian2Int(substr($ISOheader,  132, 4));
     167                $thisfile_iso_supplementaryVD_raw['path_table_l_location']          = getid3_lib::LittleEndian2Int(substr($ISOheader,  140, 2));
     168                $thisfile_iso_supplementaryVD_raw['path_table_l_opt_location']      = getid3_lib::LittleEndian2Int(substr($ISOheader,  144, 2));
     169                $thisfile_iso_supplementaryVD_raw['path_table_m_location']          = getid3_lib::LittleEndian2Int(substr($ISOheader,  148, 2));
     170                $thisfile_iso_supplementaryVD_raw['path_table_m_opt_location']      = getid3_lib::LittleEndian2Int(substr($ISOheader,  152, 2));
     171                $thisfile_iso_supplementaryVD_raw['root_directory_record']          =                              substr($ISOheader,  156, 34);
     172                $thisfile_iso_supplementaryVD_raw['volume_set_identifier']          =                              substr($ISOheader,  190, 128);
     173                $thisfile_iso_supplementaryVD_raw['publisher_identifier']           =                              substr($ISOheader,  318, 128);
     174                $thisfile_iso_supplementaryVD_raw['data_preparer_identifier']       =                              substr($ISOheader,  446, 128);
     175                $thisfile_iso_supplementaryVD_raw['application_identifier']         =                              substr($ISOheader,  574, 128);
     176                $thisfile_iso_supplementaryVD_raw['copyright_file_identifier']      =                              substr($ISOheader,  702, 37);
     177                $thisfile_iso_supplementaryVD_raw['abstract_file_identifier']       =                              substr($ISOheader,  739, 37);
     178                $thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier']  =                              substr($ISOheader,  776, 37);
     179                $thisfile_iso_supplementaryVD_raw['volume_creation_date_time']      =                              substr($ISOheader,  813, 17);
     180                $thisfile_iso_supplementaryVD_raw['volume_modification_date_time']  =                              substr($ISOheader,  830, 17);
     181                $thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']    =                              substr($ISOheader,  847, 17);
     182                $thisfile_iso_supplementaryVD_raw['volume_effective_date_time']     =                              substr($ISOheader,  864, 17);
     183                $thisfile_iso_supplementaryVD_raw['file_structure_version']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  881, 1));
     184                //$thisfile_iso_supplementaryVD_raw['unused_4']                       = getid3_lib::LittleEndian2Int(substr($ISOheader,  882, 1));
     185                $thisfile_iso_supplementaryVD_raw['application_data']               =                              substr($ISOheader,  883, 512);
     186                //$thisfile_iso_supplementaryVD_raw['unused_5']                       =                              substr($ISOheader, 1395, 653);
     187
     188                $thisfile_iso_supplementaryVD['system_identifier']              = trim($thisfile_iso_supplementaryVD_raw['system_identifier']);
     189                $thisfile_iso_supplementaryVD['volume_identifier']              = trim($thisfile_iso_supplementaryVD_raw['volume_identifier']);
     190                $thisfile_iso_supplementaryVD['volume_set_identifier']          = trim($thisfile_iso_supplementaryVD_raw['volume_set_identifier']);
     191                $thisfile_iso_supplementaryVD['publisher_identifier']           = trim($thisfile_iso_supplementaryVD_raw['publisher_identifier']);
     192                $thisfile_iso_supplementaryVD['data_preparer_identifier']       = trim($thisfile_iso_supplementaryVD_raw['data_preparer_identifier']);
     193                $thisfile_iso_supplementaryVD['application_identifier']         = trim($thisfile_iso_supplementaryVD_raw['application_identifier']);
     194                $thisfile_iso_supplementaryVD['copyright_file_identifier']      = trim($thisfile_iso_supplementaryVD_raw['copyright_file_identifier']);
     195                $thisfile_iso_supplementaryVD['abstract_file_identifier']       = trim($thisfile_iso_supplementaryVD_raw['abstract_file_identifier']);
     196                $thisfile_iso_supplementaryVD['bibliographic_file_identifier']  = trim($thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier']);
     197                $thisfile_iso_supplementaryVD['volume_creation_date_time']      = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_creation_date_time']);
     198                $thisfile_iso_supplementaryVD['volume_modification_date_time']  = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_modification_date_time']);
     199                $thisfile_iso_supplementaryVD['volume_expiration_date_time']    = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']);
     200                $thisfile_iso_supplementaryVD['volume_effective_date_time']     = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_effective_date_time']);
     201
     202                if (($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']) > $ThisFileInfo['filesize']) {
     203                        $ThisFileInfo['error'][] = 'Volume Space Size ('.($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$ThisFileInfo['filesize'].' bytes) (truncated file?)';
     204                }
     205
     206                return true;
     207        }
     208
     209
     210        function ParsePathTable($fd, &$ThisFileInfo) {
     211                if (!isset($ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($ThisFileInfo['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) {
     212                        return false;
     213                }
     214                if (isset($ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) {
     215                        $PathTableLocation = $ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'];
     216                        $PathTableSize     = $ThisFileInfo['iso']['supplementary_volume_descriptor']['raw']['path_table_size'];
     217                        $TextEncoding      = 'UTF-16BE'; // Big-Endian Unicode
     218                } else {
     219                        $PathTableLocation = $ThisFileInfo['iso']['primary_volume_descriptor']['raw']['path_table_l_location'];
     220                        $PathTableSize     = $ThisFileInfo['iso']['primary_volume_descriptor']['raw']['path_table_size'];
     221                        $TextEncoding      = 'ISO-8859-1'; // Latin-1
     222                }
     223
     224                if (($PathTableLocation * 2048) > $ThisFileInfo['filesize']) {
     225                        $ThisFileInfo['error'][] = 'Path Table Location specifies an offset ('.($PathTableLocation * 2048).') beyond the end-of-file ('.$ThisFileInfo['filesize'].')';
     226                        return false;
     227                }
     228
     229                $ThisFileInfo['iso']['path_table']['offset'] = $PathTableLocation * 2048;
     230                fseek($fd, $ThisFileInfo['iso']['path_table']['offset'], SEEK_SET);
     231                $ThisFileInfo['iso']['path_table']['raw'] = fread($fd, $PathTableSize);
     232
     233                $offset = 0;
     234                $pathcounter = 1;
     235                while ($offset < $PathTableSize) {
     236                        // shortcut
     237                        $ThisFileInfo['iso']['path_table']['directories'][$pathcounter] = array();
     238                        $thisfile_iso_pathtable_directories_current = &$ThisFileInfo['iso']['path_table']['directories'][$pathcounter];
     239
     240                        $thisfile_iso_pathtable_directories_current['length']           = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 1));
     241                        $offset += 1;
     242                        $thisfile_iso_pathtable_directories_current['extended_length']  = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 1));
     243                        $offset += 1;
     244                        $thisfile_iso_pathtable_directories_current['location_logical'] = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 4));
     245                        $offset += 4;
     246                        $thisfile_iso_pathtable_directories_current['parent_directory'] = getid3_lib::LittleEndian2Int(substr($ThisFileInfo['iso']['path_table']['raw'], $offset, 2));
     247                        $offset += 2;
     248                        $thisfile_iso_pathtable_directories_current['name']             =                  substr($ThisFileInfo['iso']['path_table']['raw'], $offset, $thisfile_iso_pathtable_directories_current['length']);
     249                        $offset += $thisfile_iso_pathtable_directories_current['length'] + ($thisfile_iso_pathtable_directories_current['length'] % 2);
     250
     251                        $thisfile_iso_pathtable_directories_current['name_ascii']       = getid3_lib::iconv_fallback($TextEncoding, $ThisFileInfo['encoding'], $thisfile_iso_pathtable_directories_current['name']);
     252
     253                        $thisfile_iso_pathtable_directories_current['location_bytes'] = $thisfile_iso_pathtable_directories_current['location_logical'] * 2048;
     254                        if ($pathcounter == 1) {
     255                                $thisfile_iso_pathtable_directories_current['full_path'] = '/';
     256                        } else {
     257                                $thisfile_iso_pathtable_directories_current['full_path'] = $ThisFileInfo['iso']['path_table']['directories'][$thisfile_iso_pathtable_directories_current['parent_directory']]['full_path'].$thisfile_iso_pathtable_directories_current['name_ascii'].'/';
     258                        }
     259                        $FullPathArray[] = $thisfile_iso_pathtable_directories_current['full_path'];
     260
     261                        $pathcounter++;
     262                }
     263
     264                return true;
     265        }
     266
     267
     268        function ParseDirectoryRecord(&$fd, $directorydata, &$ThisFileInfo) {
     269                if (isset($ThisFileInfo['iso']['supplementary_volume_descriptor'])) {
     270                        $TextEncoding = 'UTF-16BE';   // Big-Endian Unicode
     271                } else {
     272                        $TextEncoding = 'ISO-8859-1'; // Latin-1
     273                }
     274
     275                fseek($fd, $directorydata['location_bytes'], SEEK_SET);
     276                $DirectoryRecordData = fread($fd, 1);
     277
     278                while (ord($DirectoryRecordData{0}) > 33) {
     279
     280                        $DirectoryRecordData .= fread($fd, ord($DirectoryRecordData{0}) - 1);
     281
     282                        $ThisDirectoryRecord['raw']['length']                    = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData,  0, 1));
     283                        $ThisDirectoryRecord['raw']['extended_attribute_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData,  1, 1));
     284                        $ThisDirectoryRecord['raw']['offset_logical']            = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData,  2, 4));
     285                        $ThisDirectoryRecord['raw']['filesize']                  = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 10, 4));
     286                        $ThisDirectoryRecord['raw']['recording_date_time']       =                  substr($DirectoryRecordData, 18, 7);
     287                        $ThisDirectoryRecord['raw']['file_flags']                = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 25, 1));
     288                        $ThisDirectoryRecord['raw']['file_unit_size']            = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 26, 1));
     289                        $ThisDirectoryRecord['raw']['interleave_gap_size']       = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 27, 1));
     290                        $ThisDirectoryRecord['raw']['volume_sequence_number']    = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 28, 2));
     291                        $ThisDirectoryRecord['raw']['file_identifier_length']    = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 32, 1));
     292                        $ThisDirectoryRecord['raw']['file_identifier']           =                  substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']);
     293
     294                        $ThisDirectoryRecord['file_identifier_ascii']            = getid3_lib::iconv_fallback($TextEncoding, $ThisFileInfo['encoding'], $ThisDirectoryRecord['raw']['file_identifier']);
     295
     296                        $ThisDirectoryRecord['filesize']                  = $ThisDirectoryRecord['raw']['filesize'];
     297                        $ThisDirectoryRecord['offset_bytes']              = $ThisDirectoryRecord['raw']['offset_logical'] * 2048;
     298                        $ThisDirectoryRecord['file_flags']['hidden']      = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x01);
     299                        $ThisDirectoryRecord['file_flags']['directory']   = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x02);
     300                        $ThisDirectoryRecord['file_flags']['associated']  = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x04);
     301                        $ThisDirectoryRecord['file_flags']['extended']    = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x08);
     302                        $ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10);
     303                        $ThisDirectoryRecord['file_flags']['multiple']    = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80);
     304                        $ThisDirectoryRecord['recording_timestamp']       = $this->ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']);
     305
     306                        if ($ThisDirectoryRecord['file_flags']['directory']) {
     307                                $ThisDirectoryRecord['filename'] = $directorydata['full_path'];
     308                        } else {
     309                                $ThisDirectoryRecord['filename'] = $directorydata['full_path'].$this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']);
     310                                $ThisFileInfo['iso']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize']));
     311                        }
     312
     313                        $DirectoryRecord[] = $ThisDirectoryRecord;
     314                        $DirectoryRecordData = fread($fd, 1);
     315                }
     316
     317                return $DirectoryRecord;
     318        }
     319
     320        function ISOstripFilenameVersion($ISOfilename) {
     321                // convert 'filename.ext;1' to 'filename.ext'
     322                if (!strstr($ISOfilename, ';')) {
     323                        return $ISOfilename;
     324                } else {
     325                        return substr($ISOfilename, 0, strpos($ISOfilename, ';'));
     326                }
     327        }
     328
     329        function ISOtimeText2UNIXtime($ISOtime) {
     330
     331                $UNIXyear   = (int) substr($ISOtime,  0, 4);
     332                $UNIXmonth  = (int) substr($ISOtime,  4, 2);
     333                $UNIXday    = (int) substr($ISOtime,  6, 2);
     334                $UNIXhour   = (int) substr($ISOtime,  8, 2);
     335                $UNIXminute = (int) substr($ISOtime, 10, 2);
     336                $UNIXsecond = (int) substr($ISOtime, 12, 2);
     337
     338                if (!$UNIXyear) {
     339                        return false;
     340                }
     341                return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
     342        }
     343
     344        function ISOtime2UNIXtime($ISOtime) {
     345                // Represented by seven bytes:
     346                // 1: Number of years since 1900
     347                // 2: Month of the year from 1 to 12
     348                // 3: Day of the Month from 1 to 31
     349                // 4: Hour of the day from 0 to 23
     350                // 5: Minute of the hour from 0 to 59
     351                // 6: second of the minute from 0 to 59
     352                // 7: Offset from Greenwich Mean Time in number of 15 minute intervals from -48 (West) to +52 (East)
     353
     354                $UNIXyear   = ord($ISOtime{0}) + 1900;
     355                $UNIXmonth  = ord($ISOtime{1});
     356                $UNIXday    = ord($ISOtime{2});
     357                $UNIXhour   = ord($ISOtime{3});
     358                $UNIXminute = ord($ISOtime{4});
     359                $UNIXsecond = ord($ISOtime{5});
     360                $GMToffset  = $this->TwosCompliment2Decimal(ord($ISOtime{5}));
     361
     362                return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
     363        }
     364
     365        function TwosCompliment2Decimal($BinaryValue) {
     366                // http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html
     367                // First check if the number is negative or positive by looking at the sign bit.
     368                // If it is positive, simply convert it to decimal.
     369                // If it is negative, make it positive by inverting the bits and adding one.
     370                // Then, convert the result to decimal.
     371                // The negative of this number is the value of the original binary.
     372
     373                if ($BinaryValue & 0x80) {
     374
     375                        // negative number
     376                        return (0 - ((~$BinaryValue & 0xFF) + 1));
     377                } else {
     378                        // positive number
     379                        return $BinaryValue;
     380                }
     381        }
     382
    447383
    448384}
Note: See TracChangeset for help on using the changeset viewer.