| Total Complexity | 140 |
| Total Lines | 1024 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like getid3 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use getid3, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class getid3 |
||
| 25 | { |
||
| 26 | //// Settings Section - do NOT modify this file - change setting after newing getid3! |
||
| 27 | |||
| 28 | // Encoding |
||
| 29 | public $encoding = 'ISO-8859-1'; // CASE SENSITIVE! - i.e. (must be supported by iconv() - see http://www.gnu.org/software/libiconv/). Examples: ISO-8859-1 UTF-8 UTF-16 UTF-16BE. |
||
| 30 | public $encoding_id3v1 = 'ISO-8859-1'; // Override SPECIFICATION encoding for broken ID3v1 tags caused by bad tag programs. Examples: 'EUC-CN' for "Chinese MP3s" and 'CP1251' for "Cyrillic". |
||
| 31 | public $encoding_id3v2 = 'ISO-8859-1'; // Override ISO-8859-1 encoding for broken ID3v2 tags caused by BRAINDEAD tag programs that writes system codepage as 'ISO-8859-1' instead of UTF-8. |
||
| 32 | |||
| 33 | // Tags - disable for speed |
||
| 34 | public $option_tag_id3v1 = true; // Read and process ID3v1 tags. |
||
| 35 | public $option_tag_id3v2 = true; // Read and process ID3v2 tags. |
||
| 36 | public $option_tag_lyrics3 = true; // Read and process Lyrics3 tags. |
||
| 37 | public $option_tag_apetag = true; // Read and process APE tags. |
||
| 38 | |||
| 39 | // Misc calucations - disable for speed |
||
| 40 | public $option_analyze = true; // Analyze file - disable if you only need to detect file format. |
||
| 41 | public $option_accurate_results = true; // Disable to greatly speed up parsing of some file formats at the cost of accuracy. |
||
| 42 | public $option_tags_process = true; // Copy tags to root key 'tags' and 'comments' and encode to $this->encoding. |
||
| 43 | public $option_tags_images = false; // Scan tags for binary image data - ID3v2 and vorbiscomments only. |
||
| 44 | public $option_extra_info = true; // Calculate/return additional info such as bitrate, channelmode etc. |
||
| 45 | public $option_max_2gb_check = false; // Check whether file is larger than 2 Gb and thus not supported by PHP. |
||
| 46 | |||
| 47 | // Misc data hashes - slow - require hash module |
||
| 48 | public $option_md5_data = false; // Get MD5 sum of data part - slow. |
||
| 49 | public $option_md5_data_source = false; // Use MD5 of source file if available - only FLAC, MAC, OptimFROG and Wavpack4. |
||
| 50 | public $option_sha1_data = false; // Get SHA1 sum of data part - slow. |
||
| 51 | |||
| 52 | // Public variables |
||
| 53 | public $filename; // Filename of file being analysed. |
||
| 54 | public $fp; // Filepointer to file being analysed. |
||
| 55 | public $info; // Result array. |
||
| 56 | |||
| 57 | // Protected variables |
||
| 58 | protected $include_path; // getid3 include path. |
||
| 59 | protected $warnings = []; |
||
| 60 | protected $iconv_present; |
||
| 61 | |||
| 62 | // Class constants |
||
| 63 | const VERSION = '2.0.0b4'; |
||
| 64 | const FREAD_BUFFER_SIZE = 16384; // Read buffer size in bytes. |
||
| 65 | const ICONV_TEST_STRING = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~�������������������������������� �����������������������������������������������������������������������������������������������'; |
||
| 66 | |||
| 67 | // Constructor - check PHP enviroment and load library. |
||
| 68 | public function __construct() |
||
| 69 | { |
||
| 70 | // Static varibles - no need to recalc every time we new getid3. |
||
| 71 | static $include_path; |
||
| 72 | static $iconv_present; |
||
| 73 | |||
| 74 | static $initialized; |
||
| 75 | if ($initialized) { |
||
| 76 | // Import static variables |
||
| 77 | $this->include_path = $include_path; |
||
| 78 | $this->iconv_present = $iconv_present; |
||
| 79 | |||
| 80 | // Run init checks only on first instance. |
||
| 81 | return; |
||
| 82 | } |
||
| 83 | |||
| 84 | // Get include_path |
||
| 85 | $this->include_path = $include_path = dirname(__FILE__) . '/'; |
||
| 86 | |||
| 87 | // Check for presence of iconv() and make sure it works (simpel test only). |
||
| 88 | if (function_exists('iconv') && @iconv('UTF-16LE', 'ISO-8859-1', @iconv('ISO-8859-1', 'UTF-16LE', getid3::ICONV_TEST_STRING)) == getid3::ICONV_TEST_STRING) { |
||
|
|
|||
| 89 | $this->iconv_present = $iconv_present = true; |
||
| 90 | } // iconv() not present - load replacement module. |
||
| 91 | else { |
||
| 92 | $this->include_module('lib.iconv_replacement'); |
||
| 93 | $this->iconv_present = $iconv_present = false; |
||
| 94 | } |
||
| 95 | |||
| 96 | // Require magic_quotes_runtime off |
||
| 97 | if (get_magic_quotes_runtime()) { |
||
| 98 | throw new getid3_exception('magic_quotes_runtime must be disabled before running getID3(). Surround getid3 block by set_magic_quotes_runtime(0) and set_magic_quotes_runtime(1).'); |
||
| 99 | } |
||
| 100 | |||
| 101 | // Check memory limit. |
||
| 102 | $memory_limit = ini_get('memory_limit'); |
||
| 103 | if (eregi('([0-9]+)M', $memory_limit, $matches)) { |
||
| 104 | // could be stored as "16M" rather than 16777216 for example |
||
| 105 | $memory_limit = $matches[1] * 1048576; |
||
| 106 | } |
||
| 107 | if ($memory_limit <= 0) { |
||
| 108 | // Should not happen. |
||
| 109 | } elseif ($memory_limit <= 4194304) { |
||
| 110 | $this->warning('[SERIOUS] PHP has less than 4 Mb available memory and will very likely run out. Increase memory_limit in php.ini.'); |
||
| 111 | } elseif ($memory_limit <= 12582912) { |
||
| 112 | $this->warning('PHP has less than 12 Mb available memory and might run out if all modules are loaded. Increase memory_limit in php.ini if needed.'); |
||
| 113 | } |
||
| 114 | |||
| 115 | // Check safe_mode off |
||
| 116 | if ((bool)ini_get('safe_mode')) { |
||
| 117 | $this->warning('Safe mode is on, shorten support disabled, md5data/sha1data for ogg vorbis disabled, ogg vorbis/flac tag writing disabled.'); |
||
| 118 | } |
||
| 119 | |||
| 120 | $initialized = true; |
||
| 121 | } |
||
| 122 | |||
| 123 | // Analyze file by name |
||
| 124 | public function Analyze($filename) |
||
| 125 | { |
||
| 126 | // Init and save values |
||
| 127 | $this->filename = $filename; |
||
| 128 | $this->warnings = []; |
||
| 129 | |||
| 130 | // Init result array and set parameters |
||
| 131 | $this->info = []; |
||
| 132 | $this->info['GETID3_VERSION'] = getid3::VERSION; |
||
| 133 | |||
| 134 | // Remote files not supported |
||
| 135 | if (preg_match('/^(ht|f)tp:\/\//', $filename)) { |
||
| 136 | throw new getid3_exception('Remote files are not supported - please copy the file locally first.'); |
||
| 137 | } |
||
| 138 | |||
| 139 | // Open local file |
||
| 140 | if (!$this->fp = @fopen($filename, 'rb')) { |
||
| 141 | throw new getid3_exception('Could not open file "' . $filename . '"'); |
||
| 142 | } |
||
| 143 | |||
| 144 | // Set filesize related parameters |
||
| 145 | $this->info['filesize'] = filesize($filename); |
||
| 146 | $this->info['avdataoffset'] = 0; |
||
| 147 | $this->info['avdataend'] = $this->info['filesize']; |
||
| 148 | |||
| 149 | // Option_max_2gb_check |
||
| 150 | if ($this->option_max_2gb_check) { |
||
| 151 | // PHP doesn't support integers larger than 31-bit (~2GB) |
||
| 152 | // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize |
||
| 153 | // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer |
||
| 154 | fseek($this->fp, 0, SEEK_END); |
||
| 155 | if (((0 != $this->info['filesize']) && (0 == ftell($this->fp))) |
||
| 156 | || ($this->info['filesize'] < 0) |
||
| 157 | || (ftell($this->fp) < 0)) { |
||
| 158 | unset($this->info['filesize']); |
||
| 159 | fclose($this->fp); |
||
| 160 | throw new getid3_exception('File is most likely larger than 2GB and is not supported by PHP.'); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | // ID3v2 detection (NOT parsing) done to make fileformat easier. |
||
| 165 | if (!$this->option_tag_id3v2) { |
||
| 166 | fseek($this->fp, 0, SEEK_SET); |
||
| 167 | $header = fread($this->fp, 10); |
||
| 168 | if ('ID3' == substr($header, 0, 3) && 10 == strlen($header)) { |
||
| 169 | $this->info['id3v2']['header'] = true; |
||
| 170 | $this->info['id3v2']['majorversion'] = ord($header{3}); |
||
| 171 | $this->info['id3v2']['minorversion'] = ord($header{4}); |
||
| 172 | $this->info['avdataoffset'] += getid3_lib::BigEndian2Int(substr($header, 6, 4), 1) + 10; // length of ID3v2 tag in 10-byte header doesn't include 10-byte header length |
||
| 173 | } |
||
| 174 | } |
||
| 175 | |||
| 176 | // Handle tags |
||
| 177 | foreach (['id3v2', 'id3v1', 'apetag', 'lyrics3'] as $tag_name) { |
||
| 178 | $option_tag = 'option_tag_' . $tag_name; |
||
| 179 | if ($this->$option_tag) { |
||
| 180 | $this->include_module('tag.' . $tag_name); |
||
| 181 | try { |
||
| 182 | $tag_class = 'getid3_' . $tag_name; |
||
| 183 | $tag = new $tag_class($this); |
||
| 184 | $tag->Analyze(); |
||
| 185 | } catch (getid3_exception $e) { |
||
| 186 | throw $e; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | //// Determine file format by magic bytes in file header. |
||
| 192 | |||
| 193 | // Read 32 kb file data |
||
| 194 | fseek($this->fp, $this->info['avdataoffset'], SEEK_SET); |
||
| 195 | $filedata = fread($this->fp, 32774); |
||
| 196 | |||
| 197 | // Get huge FileFormatArray |
||
| 198 | $file_format_array = getid3::GetFileFormatArray(); |
||
| 199 | |||
| 200 | // Identify file format - loop through $format_info and detect with reg expr |
||
| 201 | foreach ($file_format_array as $name => $info) { |
||
| 202 | if (preg_match('/' . $info['pattern'] . '/s', $filedata)) { // The /s switch on preg_match() forces preg_match() NOT to treat newline (0x0A) characters as special chars but do a binary match |
||
| 203 | |||
| 204 | // Format detected but not supported |
||
| 205 | if (!@$info['module'] || !@$info['group']) { |
||
| 206 | fclose($this->fp); |
||
| 207 | $this->info['fileformat'] = $name; |
||
| 208 | $this->info['mime_type'] = $info['mime_type']; |
||
| 209 | $this->warning('Format only detected. Parsing not available yet.'); |
||
| 210 | $this->info['warning'] = $this->warnings; |
||
| 211 | return $this->info; |
||
| 212 | } |
||
| 213 | |||
| 214 | $determined_format = $info; // copy $info deleted by foreach() |
||
| 215 | continue; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | // Unable to determine file format |
||
| 220 | if (!@$determined_format) { |
||
| 221 | // Too many mp3 encoders on the market put gabage in front of mpeg files |
||
| 222 | // use assume format on these if format detection failed |
||
| 223 | if (preg_match('/\.mp[123a]$/i', $filename)) { |
||
| 224 | $determined_format = $file_format_array['mp3']; |
||
| 225 | } else { |
||
| 226 | fclose($this->fp); |
||
| 227 | throw new getid3_exception('Unable to determine file format'); |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | // Free memory |
||
| 232 | unset($file_format_array); |
||
| 233 | |||
| 234 | // Check for illegal ID3 tags |
||
| 235 | if (@$determined_format['fail_id3'] && (@$this->info['id3v1'] || @$this->info['id3v2'])) { |
||
| 236 | if ('ERROR' === $determined_format['fail_id3']) { |
||
| 237 | fclose($this->fp); |
||
| 238 | throw new getid3_exception('ID3 tags not allowed on this file type.'); |
||
| 239 | } elseif ('WARNING' === $determined_format['fail_id3']) { |
||
| 240 | @$this->info['id3v1'] and $this->warning('ID3v1 tags not allowed on this file type.'); |
||
| 241 | @$this->info['id3v2'] and $this->warning('ID3v2 tags not allowed on this file type.'); |
||
| 242 | } |
||
| 243 | } |
||
| 244 | |||
| 245 | // Check for illegal APE tags |
||
| 246 | if (@$determined_format['fail_ape'] && @$this->info['tags']['ape']) { |
||
| 247 | if ('ERROR' === $determined_format['fail_ape']) { |
||
| 248 | fclose($this->fp); |
||
| 249 | throw new getid3_exception('APE tags not allowed on this file type.'); |
||
| 250 | } elseif ('WARNING' === $determined_format['fail_ape']) { |
||
| 251 | $this->warning('APE tags not allowed on this file type.'); |
||
| 252 | } |
||
| 253 | } |
||
| 254 | |||
| 255 | // Set mime type |
||
| 256 | $this->info['mime_type'] = $determined_format['mime_type']; |
||
| 257 | |||
| 258 | // Calc module file name |
||
| 259 | $determined_format['include'] = 'module.' . $determined_format['group'] . '.' . $determined_format['module'] . '.php'; |
||
| 260 | |||
| 261 | // Supported format signature pattern detected, but module deleted. |
||
| 262 | if (!file_exists($this->include_path . $determined_format['include'])) { |
||
| 263 | fclose($this->fp); |
||
| 264 | throw new getid3_exception('Format not supported, module, ' . $determined_format['include'] . ', was removed.'); |
||
| 265 | } |
||
| 266 | |||
| 267 | // Include module |
||
| 268 | $this->include_module($determined_format['group'] . '.' . $determined_format['module']); |
||
| 269 | |||
| 270 | // Instantiate module class and analyze |
||
| 271 | $class_name = 'getid3_' . $determined_format['module']; |
||
| 272 | if (!class_exists($class_name)) { |
||
| 273 | throw new getid3_exception('Format not supported, module, ' . $determined_format['include'] . ', is corrupt.'); |
||
| 274 | } |
||
| 275 | $class = new $class_name($this); |
||
| 276 | |||
| 277 | try { |
||
| 278 | $this->option_analyze and $class->Analyze(); |
||
| 279 | } catch (getid3_exception $e) { |
||
| 280 | throw $e; |
||
| 281 | } catch (Exception $e) { |
||
| 282 | throw new getid3_exception('Corrupt file.'); |
||
| 283 | } |
||
| 284 | |||
| 285 | // Close file |
||
| 286 | fclose($this->fp); |
||
| 287 | |||
| 288 | // Optional - Process all tags - copy to 'tags' and convert charsets |
||
| 289 | if ($this->option_tags_process) { |
||
| 290 | $this->HandleAllTags(); |
||
| 291 | } |
||
| 292 | |||
| 293 | //// Optional - perform more calculations |
||
| 294 | if ($this->option_extra_info) { |
||
| 295 | // Set channelmode on audio |
||
| 296 | if ('1' == @$this->info['audio']['channels']) { |
||
| 297 | $this->info['audio']['channelmode'] = 'mono'; |
||
| 298 | } elseif ('2' == @$this->info['audio']['channels']) { |
||
| 299 | $this->info['audio']['channelmode'] = 'stereo'; |
||
| 300 | } |
||
| 301 | |||
| 302 | // Calculate combined bitrate - audio + video |
||
| 303 | $combined_bitrate = 0; |
||
| 304 | $combined_bitrate += (isset($this->info['audio']['bitrate']) ? $this->info['audio']['bitrate'] : 0); |
||
| 305 | $combined_bitrate += (isset($this->info['video']['bitrate']) ? $this->info['video']['bitrate'] : 0); |
||
| 306 | if (($combined_bitrate > 0) && empty($this->info['bitrate'])) { |
||
| 307 | $this->info['bitrate'] = $combined_bitrate; |
||
| 308 | } |
||
| 309 | if (!isset($this->info['playtime_seconds']) && !empty($this->info['bitrate'])) { |
||
| 310 | $this->info['playtime_seconds'] = (($this->info['avdataend'] - $this->info['avdataoffset']) * 8) / $this->info['bitrate']; |
||
| 311 | } |
||
| 312 | |||
| 313 | // Set playtime string |
||
| 314 | if (!empty($this->info['playtime_seconds']) && empty($this->info['playtime_string'])) { |
||
| 315 | $this->info['playtime_string'] = floor(round($this->info['playtime_seconds']) / 60) . ':' . str_pad(floor(round($this->info['playtime_seconds']) % 60), 2, 0, STR_PAD_LEFT);; |
||
| 316 | } |
||
| 317 | |||
| 318 | // CalculateCompressionRatioVideo() { |
||
| 319 | if (@$this->info['video'] && @$this->info['video']['resolution_x'] && @$this->info['video']['resolution_y'] && @$this->info['video']['bits_per_sample']) { |
||
| 320 | // From static image formats |
||
| 321 | if (in_array($this->info['video']['dataformat'], ['bmp', 'gif', 'jpeg', 'jpg', 'png', 'tiff'])) { |
||
| 322 | $frame_rate = 1; |
||
| 323 | $bitrate_compressed = $this->info['filesize'] * 8; |
||
| 324 | } // From video formats |
||
| 325 | else { |
||
| 326 | $frame_rate = @$this->info['video']['frame_rate']; |
||
| 327 | $bitrate_compressed = @$this->info['video']['bitrate']; |
||
| 328 | } |
||
| 329 | |||
| 330 | if ($frame_rate && $bitrate_compressed) { |
||
| 331 | $this->info['video']['compression_ratio'] = $bitrate_compressed / ($this->info['video']['resolution_x'] * $this->info['video']['resolution_y'] * $this->info['video']['bits_per_sample'] * $frame_rate); |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | // CalculateCompressionRatioAudio() { |
||
| 336 | if (@$this->info['audio']['bitrate'] && @$this->info['audio']['channels'] && @$this->info['audio']['sample_rate']) { |
||
| 337 | $this->info['audio']['compression_ratio'] = $this->info['audio']['bitrate'] / ($this->info['audio']['channels'] * $this->info['audio']['sample_rate'] * (@$this->info['audio']['bits_per_sample'] ? $this->info['audio']['bits_per_sample'] : 16)); |
||
| 338 | } |
||
| 339 | |||
| 340 | if (@$this->info['audio']['streams']) { |
||
| 341 | foreach ($this->info['audio']['streams'] as $stream_number => $stream_data) { |
||
| 342 | if (@$stream_data['bitrate'] && @$stream_data['channels'] && @$stream_data['sample_rate']) { |
||
| 343 | $this->info['audio']['streams'][$stream_number]['compression_ratio'] = $stream_data['bitrate'] / ($stream_data['channels'] * $stream_data['sample_rate'] * (@$stream_data['bits_per_sample'] ? $stream_data['bits_per_sample'] : 16)); |
||
| 344 | } |
||
| 345 | } |
||
| 346 | } |
||
| 347 | |||
| 348 | // CalculateReplayGain() { |
||
| 349 | if (@$this->info['replay_gain']) { |
||
| 350 | if (!@$this->info['replay_gain']['reference_volume']) { |
||
| 351 | $this->info['replay_gain']['reference_volume'] = 89; |
||
| 352 | } |
||
| 353 | if (isset($this->info['replay_gain']['track']['adjustment'])) { |
||
| 354 | $this->info['replay_gain']['track']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['track']['adjustment']; |
||
| 355 | } |
||
| 356 | if (isset($this->info['replay_gain']['album']['adjustment'])) { |
||
| 357 | $this->info['replay_gain']['album']['volume'] = $this->info['replay_gain']['reference_volume'] - $this->info['replay_gain']['album']['adjustment']; |
||
| 358 | } |
||
| 359 | |||
| 360 | if (isset($this->info['replay_gain']['track']['peak'])) { |
||
| 361 | $this->info['replay_gain']['track']['max_noclip_gain'] = 0 - 20 * log10($this->info['replay_gain']['track']['peak']); |
||
| 362 | } |
||
| 363 | if (isset($this->info['replay_gain']['album']['peak'])) { |
||
| 364 | $this->info['replay_gain']['album']['max_noclip_gain'] = 0 - 20 * log10($this->info['replay_gain']['album']['peak']); |
||
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 368 | // ProcessAudioStreams() { |
||
| 369 | if (@!$this->info['audio']['streams'] && (@$this->info['audio']['bitrate'] || @$this->info['audio']['channels'] || @$this->info['audio']['sample_rate'])) { |
||
| 370 | foreach ($this->info['audio'] as $key => $value) { |
||
| 371 | if ('streams' != $key) { |
||
| 372 | $this->info['audio']['streams'][0][$key] = $value; |
||
| 373 | } |
||
| 374 | } |
||
| 375 | } |
||
| 376 | } |
||
| 377 | |||
| 378 | // Get the md5/sha1sum of the audio/video portion of the file - without ID3/APE/Lyrics3/etc header/footer tags. |
||
| 379 | if ($this->option_md5_data || $this->option_sha1_data) { |
||
| 380 | // Load data-hash library if needed |
||
| 381 | $this->include_module('lib.data_hash'); |
||
| 382 | |||
| 383 | if ($this->option_sha1_data) { |
||
| 384 | new getid3_lib_data_hash($this, 'sha1'); |
||
| 385 | } |
||
| 386 | |||
| 387 | if ($this->option_md5_data) { |
||
| 388 | // no md5_data_source or option disabled -- md5_data_source supported by FLAC, MAC, OptimFROG, Wavpack4 |
||
| 389 | if (!$this->option_md5_data_source || !@$this->info['md5_data_source']) { |
||
| 390 | new getid3_lib_data_hash($this, 'md5'); |
||
| 391 | } // copy md5_data_source to md5_data if option set to true |
||
| 392 | elseif ($this->option_md5_data_source && @$this->info['md5_data_source']) { |
||
| 393 | $this->info['md5_data'] = $this->info['md5_data_source']; |
||
| 394 | } |
||
| 395 | } |
||
| 396 | } |
||
| 397 | |||
| 398 | // Set warnings |
||
| 399 | if ($this->warnings) { |
||
| 400 | $this->info['warning'] = $this->warnings; |
||
| 401 | } |
||
| 402 | |||
| 403 | // Return result |
||
| 404 | return $this->info; |
||
| 405 | } |
||
| 406 | |||
| 407 | // Return array of warnings |
||
| 408 | public function warnings() |
||
| 409 | { |
||
| 410 | return $this->warnings; |
||
| 411 | } |
||
| 412 | |||
| 413 | // Add warning(s) to $this->warnings[] |
||
| 414 | public function warning($message) |
||
| 415 | { |
||
| 416 | if (is_array($message)) { |
||
| 417 | $this->warnings = array_merge($this->warnings, $message); |
||
| 418 | } else { |
||
| 419 | $this->warnings[] = $message; |
||
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | // Clear all warnings when cloning |
||
| 424 | public function __clone() |
||
| 425 | { |
||
| 426 | $this->warnings = []; |
||
| 427 | |||
| 428 | // Copy info array, otherwise it will be a reference. |
||
| 429 | $temp = $this->info; |
||
| 430 | unset($this->info); |
||
| 431 | $this->info = $temp; |
||
| 432 | } |
||
| 433 | |||
| 434 | // Convert string between charsets -- iconv() wrapper |
||
| 435 | public function iconv($in_charset, $out_charset, $string, $drop01 = false) |
||
| 436 | { |
||
| 437 | if ($drop01 && ("\x00" === $string || "\x01" === $string)) { |
||
| 438 | return ''; |
||
| 439 | } |
||
| 440 | |||
| 441 | if (!$this->iconv_present) { |
||
| 442 | return getid3_iconv_replacement::iconv($in_charset, $out_charset, $string); |
||
| 443 | } |
||
| 444 | |||
| 445 | // iconv() present |
||
| 446 | if ($result = @iconv($in_charset, $out_charset . '//TRANSLIT', $string)) { |
||
| 447 | if ('ISO-8859-1' == $out_charset) { |
||
| 448 | return rtrim($result, "\x00"); |
||
| 449 | } |
||
| 450 | return $result; |
||
| 451 | } |
||
| 452 | |||
| 453 | $this->warning('iconv() was unable to convert the string: "' . $string . '" from ' . $in_charset . ' to ' . $out_charset); |
||
| 454 | return $string; |
||
| 455 | } |
||
| 456 | |||
| 457 | public function include_module($name) |
||
| 458 | { |
||
| 459 | if (!file_exists($this->include_path . 'module.' . $name . '.php')) { |
||
| 460 | throw new getid3_exception('Required module.' . $name . '.php is missing.'); |
||
| 461 | } |
||
| 462 | |||
| 463 | include_once($this->include_path . 'module.' . $name . '.php'); |
||
| 464 | } |
||
| 465 | |||
| 466 | public function include_module_optional($name) |
||
| 467 | { |
||
| 468 | if (!file_exists($this->include_path . 'module.' . $name . '.php')) { |
||
| 469 | return; |
||
| 470 | } |
||
| 471 | |||
| 472 | include_once($this->include_path . 'module.' . $name . '.php'); |
||
| 473 | return true; |
||
| 474 | } |
||
| 475 | |||
| 476 | // Return array containing information about all supported formats |
||
| 477 | public static function GetFileFormatArray() |
||
| 939 | } |
||
| 940 | |||
| 941 | // Recursive over array - converts array to $encoding charset from $this->encoding |
||
| 942 | public function CharConvert(&$array, $encoding) |
||
| 943 | { |
||
| 944 | // Identical encoding - end here |
||
| 945 | if ($encoding == $this->encoding) { |
||
| 946 | return; |
||
| 947 | } |
||
| 948 | |||
| 949 | // Loop thru array |
||
| 950 | foreach ($array as $key => $value) { |
||
| 951 | // Go recursive |
||
| 952 | if (is_array($value)) { |
||
| 953 | $this->CharConvert($array[$key], $encoding); |
||
| 954 | } // Convert string |
||
| 955 | elseif (is_string($value)) { |
||
| 956 | $array[$key] = $this->iconv($encoding, $this->encoding, $value); |
||
| 957 | } |
||
| 958 | } |
||
| 959 | } |
||
| 960 | |||
| 961 | // Convert and copy tags |
||
| 962 | protected function HandleAllTags() |
||
| 1048 | } |
||
| 1049 | } |
||
| 1050 | |||
| 1051 | abstract class getid3_handler |
||
| 1052 | { |
||
| 1053 | |||
| 1054 | protected $getid3; // pointer |
||
| 1459 |