PowerPress Podcasting plugin by Blubrry - Version 3.0

Version Description

  • Released on 2/10/2012
  • PowerPress now requires WordPress version 3.0 or newer.
  • New Meta Marks feature learn more
  • Media duration detection and verification now supports AAC .m4a audio and H.264 .mp4/.m4v video (in addition to mpeg3 .mp3). Media duration detection now requires PHP 5.0.5 or newer.
  • Added new 'Disable Warnings' option for Podcast Entry Box. Errors are still displayed.
  • Media verification (Verify button) no longer warns if mp3 Channel mode is mono.
  • Media verification (Verify button) now verifies that the media URL's content type is valid when detecting duration information.
  • Media verification (Verify button) now displays the link to the media upon error so user can test URL manually.
  • Media verification (Verify button) now includes a more readable message when URL returns 404 file not found.
  • Added new Feed Discovery option, Adds "feed discovery" links to your web site's headers allowing web browsers and feed readers to auto-detect your podcast feeds.
  • Removed iTunes update iTunes listing logic, it is pretty obvious Apple does not plan on restoring the ping which Apple took offline in February of 2011.
  • Added warning in settings that podcast feed is invalid until create at least one podcast episode.
  • Warning now displayed if a Media Embed is entered but no Media URL is present.
  • Removed third party JSON library, no longer needed for WP versions 2.9+.
  • Podcast Channels can now be associated with specific Custom Post Types of type 'post'.
  • Added option to upload/change HTML5 audio and video play icons. Video play icon must be 60 x 60 pixels in size. Audio play icon has no size restrictions.
  • Added link to WordPress Settings to PowerPress basic setings, This is to resolve the many complains we receive by new users who cannot find PowerPress settings menu.
  • Fixed bug with ID3 tag writing feature not functioning correctly. (Thanks Dave from School of Podcasting for reporting the problem)
  • Fixed bug detected latest versoin of iPad for displaying the HTML5 player.
  • Flow Player Classic now displays full screen button when playing video.
  • Romanian translation for v2.0.4+ added by Alexander Ovsov (Thanks Alexander!)
  • Italian translation for v2.0.4+ by Umberto (thanks Umberto!)
  • Fixed a number of PHP notice messages when in WP_DEBUG mode. (Thanks Jeremy Clarke for introducing us to the Debug Bar plugin!)
Download this release

Release Info

Developer amandato
Plugin Icon 128x128 PowerPress Podcasting plugin by Blubrry
Version 3.0
Comparing to
See all releases

Code changes from version 2.0.4 to 3.0

3rdparty/JSON.php DELETED
@@ -1,806 +0,0 @@
1
- <?php
2
- /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
-
4
- /**
5
- * Converts to and from JSON format.
6
- *
7
- * JSON (JavaScript Object Notation) is a lightweight data-interchange
8
- * format. It is easy for humans to read and write. It is easy for machines
9
- * to parse and generate. It is based on a subset of the JavaScript
10
- * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
11
- * This feature can also be found in Python. JSON is a text format that is
12
- * completely language independent but uses conventions that are familiar
13
- * to programmers of the C-family of languages, including C, C++, C#, Java,
14
- * JavaScript, Perl, TCL, and many others. These properties make JSON an
15
- * ideal data-interchange language.
16
- *
17
- * This package provides a simple encoder and decoder for JSON notation. It
18
- * is intended for use with client-side Javascript applications that make
19
- * use of HTTPRequest to perform server communication functions - data can
20
- * be encoded into JSON notation for use in a client-side javascript, or
21
- * decoded from incoming Javascript requests. JSON format is native to
22
- * Javascript, and can be directly eval()'ed with no further parsing
23
- * overhead
24
- *
25
- * All strings should be in ASCII or UTF-8 format!
26
- *
27
- * LICENSE: Redistribution and use in source and binary forms, with or
28
- * without modification, are permitted provided that the following
29
- * conditions are met: Redistributions of source code must retain the
30
- * above copyright notice, this list of conditions and the following
31
- * disclaimer. Redistributions in binary form must reproduce the above
32
- * copyright notice, this list of conditions and the following disclaimer
33
- * in the documentation and/or other materials provided with the
34
- * distribution.
35
- *
36
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
37
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
38
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
39
- * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
40
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
41
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
42
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
45
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
46
- * DAMAGE.
47
- *
48
- * @category
49
- * @package Services_JSON
50
- * @author Michal Migurski <mike-json@teczno.com>
51
- * @author Matt Knapp <mdknapp[at]gmail[dot]com>
52
- * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
53
- * @copyright 2005 Michal Migurski
54
- * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
55
- * @license http://www.opensource.org/licenses/bsd-license.php
56
- * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
57
- */
58
-
59
- /**
60
- * Marker constant for Services_JSON::decode(), used to flag stack state
61
- */
62
- define('SERVICES_JSON_SLICE', 1);
63
-
64
- /**
65
- * Marker constant for Services_JSON::decode(), used to flag stack state
66
- */
67
- define('SERVICES_JSON_IN_STR', 2);
68
-
69
- /**
70
- * Marker constant for Services_JSON::decode(), used to flag stack state
71
- */
72
- define('SERVICES_JSON_IN_ARR', 3);
73
-
74
- /**
75
- * Marker constant for Services_JSON::decode(), used to flag stack state
76
- */
77
- define('SERVICES_JSON_IN_OBJ', 4);
78
-
79
- /**
80
- * Marker constant for Services_JSON::decode(), used to flag stack state
81
- */
82
- define('SERVICES_JSON_IN_CMT', 5);
83
-
84
- /**
85
- * Behavior switch for Services_JSON::decode()
86
- */
87
- define('SERVICES_JSON_LOOSE_TYPE', 16);
88
-
89
- /**
90
- * Behavior switch for Services_JSON::decode()
91
- */
92
- define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
93
-
94
- /**
95
- * Converts to and from JSON format.
96
- *
97
- * Brief example of use:
98
- *
99
- * <code>
100
- * // create a new instance of Services_JSON
101
- * $json = new Services_JSON();
102
- *
103
- * // convert a complexe value to JSON notation, and send it to the browser
104
- * $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
105
- * $output = $json->encode($value);
106
- *
107
- * print($output);
108
- * // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
109
- *
110
- * // accept incoming POST data, assumed to be in JSON notation
111
- * $input = file_get_contents('php://input', 1000000);
112
- * $value = $json->decode($input);
113
- * </code>
114
- */
115
- class Services_JSON
116
- {
117
- /**
118
- * constructs a new JSON instance
119
- *
120
- * @param int $use object behavior flags; combine with boolean-OR
121
- *
122
- * possible values:
123
- * - SERVICES_JSON_LOOSE_TYPE: loose typing.
124
- * "{...}" syntax creates associative arrays
125
- * instead of objects in decode().
126
- * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
127
- * Values which can't be encoded (e.g. resources)
128
- * appear as NULL instead of throwing errors.
129
- * By default, a deeply-nested resource will
130
- * bubble up with an error, so all return values
131
- * from encode() should be checked with isError()
132
- */
133
- function Services_JSON($use = 0)
134
- {
135
- $this->use = $use;
136
- }
137
-
138
- /**
139
- * convert a string from one UTF-16 char to one UTF-8 char
140
- *
141
- * Normally should be handled by mb_convert_encoding, but
142
- * provides a slower PHP-only method for installations
143
- * that lack the multibye string extension.
144
- *
145
- * @param string $utf16 UTF-16 character
146
- * @return string UTF-8 character
147
- * @access private
148
- */
149
- function utf162utf8($utf16)
150
- {
151
- // oh please oh please oh please oh please oh please
152
- if(function_exists('mb_convert_encoding')) {
153
- return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
154
- }
155
-
156
- $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
157
-
158
- switch(true) {
159
- case ((0x7F & $bytes) == $bytes):
160
- // this case should never be reached, because we are in ASCII range
161
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
162
- return chr(0x7F & $bytes);
163
-
164
- case (0x07FF & $bytes) == $bytes:
165
- // return a 2-byte UTF-8 character
166
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
167
- return chr(0xC0 | (($bytes >> 6) & 0x1F))
168
- . chr(0x80 | ($bytes & 0x3F));
169
-
170
- case (0xFFFF & $bytes) == $bytes:
171
- // return a 3-byte UTF-8 character
172
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
173
- return chr(0xE0 | (($bytes >> 12) & 0x0F))
174
- . chr(0x80 | (($bytes >> 6) & 0x3F))
175
- . chr(0x80 | ($bytes & 0x3F));
176
- }
177
-
178
- // ignoring UTF-32 for now, sorry
179
- return '';
180
- }
181
-
182
- /**
183
- * convert a string from one UTF-8 char to one UTF-16 char
184
- *
185
- * Normally should be handled by mb_convert_encoding, but
186
- * provides a slower PHP-only method for installations
187
- * that lack the multibye string extension.
188
- *
189
- * @param string $utf8 UTF-8 character
190
- * @return string UTF-16 character
191
- * @access private
192
- */
193
- function utf82utf16($utf8)
194
- {
195
- // oh please oh please oh please oh please oh please
196
- if(function_exists('mb_convert_encoding')) {
197
- return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
198
- }
199
-
200
- switch(strlen($utf8)) {
201
- case 1:
202
- // this case should never be reached, because we are in ASCII range
203
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
204
- return $utf8;
205
-
206
- case 2:
207
- // return a UTF-16 character from a 2-byte UTF-8 char
208
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
209
- return chr(0x07 & (ord($utf8{0}) >> 2))
210
- . chr((0xC0 & (ord($utf8{0}) << 6))
211
- | (0x3F & ord($utf8{1})));
212
-
213
- case 3:
214
- // return a UTF-16 character from a 3-byte UTF-8 char
215
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
216
- return chr((0xF0 & (ord($utf8{0}) << 4))
217
- | (0x0F & (ord($utf8{1}) >> 2)))
218
- . chr((0xC0 & (ord($utf8{1}) << 6))
219
- | (0x7F & ord($utf8{2})));
220
- }
221
-
222
- // ignoring UTF-32 for now, sorry
223
- return '';
224
- }
225
-
226
- /**
227
- * encodes an arbitrary variable into JSON format
228
- *
229
- * @param mixed $var any number, boolean, string, array, or object to be encoded.
230
- * see argument 1 to Services_JSON() above for array-parsing behavior.
231
- * if var is a strng, note that encode() always expects it
232
- * to be in ASCII or UTF-8 format!
233
- *
234
- * @return mixed JSON string representation of input var or an error if a problem occurs
235
- * @access public
236
- */
237
- function encode($var)
238
- {
239
- switch (gettype($var)) {
240
- case 'boolean':
241
- return $var ? 'true' : 'false';
242
-
243
- case 'NULL':
244
- return 'null';
245
-
246
- case 'integer':
247
- return (int) $var;
248
-
249
- case 'double':
250
- case 'float':
251
- return (float) $var;
252
-
253
- case 'string':
254
- // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
255
- $ascii = '';
256
- $strlen_var = strlen($var);
257
-
258
- /*
259
- * Iterate over every character in the string,
260
- * escaping with a slash or encoding to UTF-8 where necessary
261
- */
262
- for ($c = 0; $c < $strlen_var; ++$c) {
263
-
264
- $ord_var_c = ord($var{$c});
265
-
266
- switch (true) {
267
- case $ord_var_c == 0x08:
268
- $ascii .= '\b';
269
- break;
270
- case $ord_var_c == 0x09:
271
- $ascii .= '\t';
272
- break;
273
- case $ord_var_c == 0x0A:
274
- $ascii .= '\n';
275
- break;
276
- case $ord_var_c == 0x0C:
277
- $ascii .= '\f';
278
- break;
279
- case $ord_var_c == 0x0D:
280
- $ascii .= '\r';
281
- break;
282
-
283
- case $ord_var_c == 0x22:
284
- case $ord_var_c == 0x2F:
285
- case $ord_var_c == 0x5C:
286
- // double quote, slash, slosh
287
- $ascii .= '\\'.$var{$c};
288
- break;
289
-
290
- case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
291
- // characters U-00000000 - U-0000007F (same as ASCII)
292
- $ascii .= $var{$c};
293
- break;
294
-
295
- case (($ord_var_c & 0xE0) == 0xC0):
296
- // characters U-00000080 - U-000007FF, mask 110XXXXX
297
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
298
- $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
299
- $c += 1;
300
- $utf16 = $this->utf82utf16($char);
301
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
302
- break;
303
-
304
- case (($ord_var_c & 0xF0) == 0xE0):
305
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
306
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
307
- $char = pack('C*', $ord_var_c,
308
- ord($var{$c + 1}),
309
- ord($var{$c + 2}));
310
- $c += 2;
311
- $utf16 = $this->utf82utf16($char);
312
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
313
- break;
314
-
315
- case (($ord_var_c & 0xF8) == 0xF0):
316
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
317
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
318
- $char = pack('C*', $ord_var_c,
319
- ord($var{$c + 1}),
320
- ord($var{$c + 2}),
321
- ord($var{$c + 3}));
322
- $c += 3;
323
- $utf16 = $this->utf82utf16($char);
324
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
325
- break;
326
-
327
- case (($ord_var_c & 0xFC) == 0xF8):
328
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
329
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
330
- $char = pack('C*', $ord_var_c,
331
- ord($var{$c + 1}),
332
- ord($var{$c + 2}),
333
- ord($var{$c + 3}),
334
- ord($var{$c + 4}));
335
- $c += 4;
336
- $utf16 = $this->utf82utf16($char);
337
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
338
- break;
339
-
340
- case (($ord_var_c & 0xFE) == 0xFC):
341
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
342
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
343
- $char = pack('C*', $ord_var_c,
344
- ord($var{$c + 1}),
345
- ord($var{$c + 2}),
346
- ord($var{$c + 3}),
347
- ord($var{$c + 4}),
348
- ord($var{$c + 5}));
349
- $c += 5;
350
- $utf16 = $this->utf82utf16($char);
351
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
352
- break;
353
- }
354
- }
355
-
356
- return '"'.$ascii.'"';
357
-
358
- case 'array':
359
- /*
360
- * As per JSON spec if any array key is not an integer
361
- * we must treat the the whole array as an object. We
362
- * also try to catch a sparsely populated associative
363
- * array with numeric keys here because some JS engines
364
- * will create an array with empty indexes up to
365
- * max_index which can cause memory issues and because
366
- * the keys, which may be relevant, will be remapped
367
- * otherwise.
368
- *
369
- * As per the ECMA and JSON specification an object may
370
- * have any string as a property. Unfortunately due to
371
- * a hole in the ECMA specification if the key is a
372
- * ECMA reserved word or starts with a digit the
373
- * parameter is only accessible using ECMAScript's
374
- * bracket notation.
375
- */
376
-
377
- // treat as a JSON object
378
- if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
379
- $properties = array_map(array($this, 'name_value'),
380
- array_keys($var),
381
- array_values($var));
382
-
383
- foreach($properties as $property) {
384
- if(Services_JSON::isError($property)) {
385
- return $property;
386
- }
387
- }
388
-
389
- return '{' . join(',', $properties) . '}';
390
- }
391
-
392
- // treat it like a regular array
393
- $elements = array_map(array($this, 'encode'), $var);
394
-
395
- foreach($elements as $element) {
396
- if(Services_JSON::isError($element)) {
397
- return $element;
398
- }
399
- }
400
-
401
- return '[' . join(',', $elements) . ']';
402
-
403
- case 'object':
404
- $vars = get_object_vars($var);
405
-
406
- $properties = array_map(array($this, 'name_value'),
407
- array_keys($vars),
408
- array_values($vars));
409
-
410
- foreach($properties as $property) {
411
- if(Services_JSON::isError($property)) {
412
- return $property;
413
- }
414
- }
415
-
416
- return '{' . join(',', $properties) . '}';
417
-
418
- default:
419
- return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
420
- ? 'null'
421
- : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
422
- }
423
- }
424
-
425
- /**
426
- * array-walking function for use in generating JSON-formatted name-value pairs
427
- *
428
- * @param string $name name of key to use
429
- * @param mixed $value reference to an array element to be encoded
430
- *
431
- * @return string JSON-formatted name-value pair, like '"name":value'
432
- * @access private
433
- */
434
- function name_value($name, $value)
435
- {
436
- $encoded_value = $this->encode($value);
437
-
438
- if(Services_JSON::isError($encoded_value)) {
439
- return $encoded_value;
440
- }
441
-
442
- return $this->encode(strval($name)) . ':' . $encoded_value;
443
- }
444
-
445
- /**
446
- * reduce a string by removing leading and trailing comments and whitespace
447
- *
448
- * @param $str string string value to strip of comments and whitespace
449
- *
450
- * @return string string value stripped of comments and whitespace
451
- * @access private
452
- */
453
- function reduce_string($str)
454
- {
455
- $str = preg_replace(array(
456
-
457
- // eliminate single line comments in '// ...' form
458
- '#^\s*//(.+)$#m',
459
-
460
- // eliminate multi-line comments in '/* ... */' form, at start of string
461
- '#^\s*/\*(.+)\*/#Us',
462
-
463
- // eliminate multi-line comments in '/* ... */' form, at end of string
464
- '#/\*(.+)\*/\s*$#Us'
465
-
466
- ), '', $str);
467
-
468
- // eliminate extraneous space
469
- return trim($str);
470
- }
471
-
472
- /**
473
- * decodes a JSON string into appropriate variable
474
- *
475
- * @param string $str JSON-formatted string
476
- *
477
- * @return mixed number, boolean, string, array, or object
478
- * corresponding to given JSON input string.
479
- * See argument 1 to Services_JSON() above for object-output behavior.
480
- * Note that decode() always returns strings
481
- * in ASCII or UTF-8 format!
482
- * @access public
483
- */
484
- function decode($str)
485
- {
486
- $str = $this->reduce_string($str);
487
-
488
- switch (strtolower($str)) {
489
- case 'true':
490
- return true;
491
-
492
- case 'false':
493
- return false;
494
-
495
- case 'null':
496
- return null;
497
-
498
- default:
499
- $m = array();
500
-
501
- if (is_numeric($str)) {
502
- // Lookie-loo, it's a number
503
-
504
- // This would work on its own, but I'm trying to be
505
- // good about returning integers where appropriate:
506
- // return (float)$str;
507
-
508
- // Return float or int, as appropriate
509
- return ((float)$str == (integer)$str)
510
- ? (integer)$str
511
- : (float)$str;
512
-
513
- } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
514
- // STRINGS RETURNED IN UTF-8 FORMAT
515
- $delim = substr($str, 0, 1);
516
- $chrs = substr($str, 1, -1);
517
- $utf8 = '';
518
- $strlen_chrs = strlen($chrs);
519
-
520
- for ($c = 0; $c < $strlen_chrs; ++$c) {
521
-
522
- $substr_chrs_c_2 = substr($chrs, $c, 2);
523
- $ord_chrs_c = ord($chrs{$c});
524
-
525
- switch (true) {
526
- case $substr_chrs_c_2 == '\b':
527
- $utf8 .= chr(0x08);
528
- ++$c;
529
- break;
530
- case $substr_chrs_c_2 == '\t':
531
- $utf8 .= chr(0x09);
532
- ++$c;
533
- break;
534
- case $substr_chrs_c_2 == '\n':
535
- $utf8 .= chr(0x0A);
536
- ++$c;
537
- break;
538
- case $substr_chrs_c_2 == '\f':
539
- $utf8 .= chr(0x0C);
540
- ++$c;
541
- break;
542
- case $substr_chrs_c_2 == '\r':
543
- $utf8 .= chr(0x0D);
544
- ++$c;
545
- break;
546
-
547
- case $substr_chrs_c_2 == '\\"':
548
- case $substr_chrs_c_2 == '\\\'':
549
- case $substr_chrs_c_2 == '\\\\':
550
- case $substr_chrs_c_2 == '\\/':
551
- if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
552
- ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
553
- $utf8 .= $chrs{++$c};
554
- }
555
- break;
556
-
557
- case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
558
- // single, escaped unicode character
559
- $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
560
- . chr(hexdec(substr($chrs, ($c + 4), 2)));
561
- $utf8 .= $this->utf162utf8($utf16);
562
- $c += 5;
563
- break;
564
-
565
- case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
566
- $utf8 .= $chrs{$c};
567
- break;
568
-
569
- case ($ord_chrs_c & 0xE0) == 0xC0:
570
- // characters U-00000080 - U-000007FF, mask 110XXXXX
571
- //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
572
- $utf8 .= substr($chrs, $c, 2);
573
- ++$c;
574
- break;
575
-
576
- case ($ord_chrs_c & 0xF0) == 0xE0:
577
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
578
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
579
- $utf8 .= substr($chrs, $c, 3);
580
- $c += 2;
581
- break;
582
-
583
- case ($ord_chrs_c & 0xF8) == 0xF0:
584
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
585
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
586
- $utf8 .= substr($chrs, $c, 4);
587
- $c += 3;
588
- break;
589
-
590
- case ($ord_chrs_c & 0xFC) == 0xF8:
591
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
592
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
593
- $utf8 .= substr($chrs, $c, 5);
594
- $c += 4;
595
- break;
596
-
597
- case ($ord_chrs_c & 0xFE) == 0xFC:
598
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
599
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
600
- $utf8 .= substr($chrs, $c, 6);
601
- $c += 5;
602
- break;
603
-
604
- }
605
-
606
- }
607
-
608
- return $utf8;
609
-
610
- } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
611
- // array, or object notation
612
-
613
- if ($str{0} == '[') {
614
- $stk = array(SERVICES_JSON_IN_ARR);
615
- $arr = array();
616
- } else {
617
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
618
- $stk = array(SERVICES_JSON_IN_OBJ);
619
- $obj = array();
620
- } else {
621
- $stk = array(SERVICES_JSON_IN_OBJ);
622
- $obj = new stdClass();
623
- }
624
- }
625
-
626
- array_push($stk, array('what' => SERVICES_JSON_SLICE,
627
- 'where' => 0,
628
- 'delim' => false));
629
-
630
- $chrs = substr($str, 1, -1);
631
- $chrs = $this->reduce_string($chrs);
632
-
633
- if ($chrs == '') {
634
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
635
- return $arr;
636
-
637
- } else {
638
- return $obj;
639
-
640
- }
641
- }
642
-
643
- //print("\nparsing {$chrs}\n");
644
-
645
- $strlen_chrs = strlen($chrs);
646
-
647
- for ($c = 0; $c <= $strlen_chrs; ++$c) {
648
-
649
- $top = end($stk);
650
- $substr_chrs_c_2 = substr($chrs, $c, 2);
651
-
652
- if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
653
- // found a comma that is not inside a string, array, etc.,
654
- // OR we've reached the end of the character list
655
- $slice = substr($chrs, $top['where'], ($c - $top['where']));
656
- array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
657
- //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
658
-
659
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
660
- // we are in an array, so just push an element onto the stack
661
- array_push($arr, $this->decode($slice));
662
-
663
- } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
664
- // we are in an object, so figure
665
- // out the property name and set an
666
- // element in an associative array,
667
- // for now
668
- $parts = array();
669
-
670
- if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
671
- // "name":value pair
672
- $key = $this->decode($parts[1]);
673
- $val = $this->decode($parts[2]);
674
-
675
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
676
- $obj[$key] = $val;
677
- } else {
678
- $obj->$key = $val;
679
- }
680
- } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
681
- // name:value pair, where name is unquoted
682
- $key = $parts[1];
683
- $val = $this->decode($parts[2]);
684
-
685
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
686
- $obj[$key] = $val;
687
- } else {
688
- $obj->$key = $val;
689
- }
690
- }
691
-
692
- }
693
-
694
- } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
695
- // found a quote, and we are not inside a string
696
- array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
697
- //print("Found start of string at {$c}\n");
698
-
699
- } elseif (($chrs{$c} == $top['delim']) &&
700
- ($top['what'] == SERVICES_JSON_IN_STR) &&
701
- ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
702
- // found a quote, we're in a string, and it's not escaped
703
- // we know that it's not escaped becase there is _not_ an
704
- // odd number of backslashes at the end of the string so far
705
- array_pop($stk);
706
- //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
707
-
708
- } elseif (($chrs{$c} == '[') &&
709
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
710
- // found a left-bracket, and we are in an array, object, or slice
711
- array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
712
- //print("Found start of array at {$c}\n");
713
-
714
- } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
715
- // found a right-bracket, and we're in an array
716
- array_pop($stk);
717
- //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
718
-
719
- } elseif (($chrs{$c} == '{') &&
720
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
721
- // found a left-brace, and we are in an array, object, or slice
722
- array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
723
- //print("Found start of object at {$c}\n");
724
-
725
- } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
726
- // found a right-brace, and we're in an object
727
- array_pop($stk);
728
- //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
729
-
730
- } elseif (($substr_chrs_c_2 == '/*') &&
731
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
732
- // found a comment start, and we are in an array, object, or slice
733
- array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
734
- $c++;
735
- //print("Found start of comment at {$c}\n");
736
-
737
- } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
738
- // found a comment end, and we're in one now
739
- array_pop($stk);
740
- $c++;
741
-
742
- for ($i = $top['where']; $i <= $c; ++$i)
743
- $chrs = substr_replace($chrs, ' ', $i, 1);
744
-
745
- //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
746
-
747
- }
748
-
749
- }
750
-
751
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
752
- return $arr;
753
-
754
- } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
755
- return $obj;
756
-
757
- }
758
-
759
- }
760
- }
761
- }
762
-
763
- /**
764
- * @todo Ultimately, this should just call PEAR::isError()
765
- */
766
- function isError($data, $code = null)
767
- {
768
- if (class_exists('pear')) {
769
- return PEAR::isError($data, $code);
770
- } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
771
- is_subclass_of($data, 'services_json_error'))) {
772
- return true;
773
- }
774
-
775
- return false;
776
- }
777
- }
778
-
779
- if (class_exists('PEAR_Error')) {
780
-
781
- class Services_JSON_Error extends PEAR_Error
782
- {
783
- function Services_JSON_Error($message = 'unknown error', $code = null,
784
- $mode = null, $options = null, $userinfo = null)
785
- {
786
- parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
787
- }
788
- }
789
-
790
- } else {
791
-
792
- /**
793
- * @todo Ultimately, this class shall be descended from PEAR_Error
794
- */
795
- class Services_JSON_Error
796
- {
797
- function Services_JSON_Error($message = 'unknown error', $code = null,
798
- $mode = null, $options = null, $userinfo = null)
799
- {
800
-
801
- }
802
- }
803
-
804
- }
805
-
806
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
getid3/getid3.lib.php CHANGED
@@ -14,33 +14,28 @@
14
  class getid3_lib
15
  {
16
 
17
- function PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true) {
18
  $returnstring = '';
19
  for ($i = 0; $i < strlen($string); $i++) {
20
  if ($hex) {
21
  $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT);
22
  } else {
23
- $returnstring .= ' '.(ereg("[\x20-\x7E]", $string{$i}) ? $string{$i} : '�');
24
  }
25
  if ($spaces) {
26
  $returnstring .= ' ';
27
  }
28
  }
29
- if ($htmlsafe) {
30
- $returnstring = htmlentities($returnstring);
 
 
 
31
  }
32
  return $returnstring;
33
  }
34
 
35
- function SafeStripSlashes($text) {
36
- if (get_magic_quotes_gpc()) {
37
- return stripslashes($text);
38
- }
39
- return $text;
40
- }
41
-
42
-
43
- function trunc($floatnumber) {
44
  // truncates a floating-point number at the decimal point
45
  // returns int (if possible, otherwise float)
46
  if ($floatnumber >= 1) {
@@ -50,21 +45,30 @@ class getid3_lib
50
  } else {
51
  $truncatednumber = 0;
52
  }
53
- if ($truncatednumber <= 1073741824) { // 2^30
54
  $truncatednumber = (int) $truncatednumber;
55
  }
56
  return $truncatednumber;
57
  }
58
 
59
 
60
- function CastAsInt($floatnum) {
 
 
 
 
 
 
 
 
 
61
  // convert to float if not already
62
  $floatnum = (float) $floatnum;
63
 
64
  // convert a float to type int, only if possible
65
  if (getid3_lib::trunc($floatnum) == $floatnum) {
66
  // it's not floating point
67
- if ($floatnum <= 1073741824) { // 2^30
68
  // it's within int range
69
  $floatnum = (int) $floatnum;
70
  }
@@ -72,15 +76,36 @@ class getid3_lib
72
  return $floatnum;
73
  }
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
- function DecimalBinary2Float($binarynumerator) {
77
  $numerator = getid3_lib::Bin2Dec($binarynumerator);
78
  $denominator = getid3_lib::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator)));
79
  return ($numerator / $denominator);
80
  }
81
 
82
 
83
- function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) {
84
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
85
  if (strpos($binarypointnumber, '.') === false) {
86
  $binarypointnumber = '0.'.$binarypointnumber;
@@ -104,7 +129,7 @@ class getid3_lib
104
  }
105
 
106
 
107
- function Float2BinaryDecimal($floatvalue) {
108
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
109
  $maxbits = 128; // to how many bits of precision should the calculations be taken?
110
  $intpart = getid3_lib::trunc($floatvalue);
@@ -120,7 +145,7 @@ class getid3_lib
120
  }
121
 
122
 
123
- function Float2String($floatvalue, $bits) {
124
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
125
  switch ($bits) {
126
  case 32:
@@ -151,20 +176,20 @@ class getid3_lib
151
  }
152
 
153
 
154
- function LittleEndian2Float($byteword) {
155
  return getid3_lib::BigEndian2Float(strrev($byteword));
156
  }
157
 
158
 
159
- function BigEndian2Float($byteword) {
160
  // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
161
  // http://www.psc.edu/general/software/packages/ieee/ieee.html
162
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
163
 
164
  $bitword = getid3_lib::BigEndian2Bin($byteword);
165
  if (!$bitword) {
166
- return 0;
167
- }
168
  $signbit = $bitword{0};
169
 
170
  switch (strlen($byteword) * 8) {
@@ -234,44 +259,42 @@ class getid3_lib
234
  }
235
 
236
 
237
- function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {
238
  $intvalue = 0;
239
  $bytewordlen = strlen($byteword);
 
 
 
240
  for ($i = 0; $i < $bytewordlen; $i++) {
241
  if ($synchsafe) { // disregard MSB, effectively 7-bit bytes
242
- $intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7);
 
243
  } else {
244
  $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
245
  }
246
  }
247
  if ($signed && !$synchsafe) {
248
  // synchsafe ints are not allowed to be signed
249
- switch ($bytewordlen) {
250
- case 1:
251
- case 2:
252
- case 3:
253
- case 4:
254
- $signmaskbit = 0x80 << (8 * ($bytewordlen - 1));
255
- if ($intvalue & $signmaskbit) {
256
- $intvalue = 0 - ($intvalue & ($signmaskbit - 1));
257
- }
258
- break;
259
-
260
- default:
261
- die('ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2Int()');
262
- break;
263
  }
264
  }
265
  return getid3_lib::CastAsInt($intvalue);
266
  }
267
 
268
 
269
- function LittleEndian2Int($byteword, $signed=false) {
270
  return getid3_lib::BigEndian2Int(strrev($byteword), false, $signed);
271
  }
272
 
273
 
274
- function BigEndian2Bin($byteword) {
275
  $binvalue = '';
276
  $bytewordlen = strlen($byteword);
277
  for ($i = 0; $i < $bytewordlen; $i++) {
@@ -281,15 +304,15 @@ class getid3_lib
281
  }
282
 
283
 
284
- function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) {
285
  if ($number < 0) {
286
- return false;
287
  }
288
  $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
289
  $intstring = '';
290
  if ($signed) {
291
- if ($minbytes > 4) {
292
- die('ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2String()');
293
  }
294
  $number = $number & (0x80 << (8 * ($minbytes - 1)));
295
  }
@@ -302,7 +325,7 @@ class getid3_lib
302
  }
303
 
304
 
305
- function Dec2Bin($number) {
306
  while ($number >= 256) {
307
  $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
308
  $number = floor($number / 256);
@@ -316,7 +339,7 @@ class getid3_lib
316
  }
317
 
318
 
319
- function Bin2Dec($binstring, $signed=false) {
320
  $signmult = 1;
321
  if ($signed) {
322
  if ($binstring{0} == '1') {
@@ -332,7 +355,7 @@ class getid3_lib
332
  }
333
 
334
 
335
- function Bin2String($binstring) {
336
  // return 'hi' for input of '0110100001101001'
337
  $string = '';
338
  $binstringreversed = strrev($binstring);
@@ -343,7 +366,7 @@ class getid3_lib
343
  }
344
 
345
 
346
- function LittleEndian2String($number, $minbytes=1, $synchsafe=false) {
347
  $intstring = '';
348
  while ($number > 0) {
349
  if ($synchsafe) {
@@ -358,7 +381,7 @@ class getid3_lib
358
  }
359
 
360
 
361
- function array_merge_clobber($array1, $array2) {
362
  // written by kc�hireability*com
363
  // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
364
  if (!is_array($array1) || !is_array($array2)) {
@@ -376,7 +399,7 @@ class getid3_lib
376
  }
377
 
378
 
379
- function array_merge_noclobber($array1, $array2) {
380
  if (!is_array($array1) || !is_array($array2)) {
381
  return false;
382
  }
@@ -392,7 +415,17 @@ class getid3_lib
392
  }
393
 
394
 
395
- function fileextension($filename, $numextensions=1) {
 
 
 
 
 
 
 
 
 
 
396
  if (strstr($filename, '.')) {
397
  $reversedfilename = strrev($filename);
398
  $offset = 0;
@@ -408,66 +441,40 @@ class getid3_lib
408
  }
409
 
410
 
411
- function PlaytimeString($playtimeseconds) {
412
- $sign = (($playtimeseconds < 0) ? '-' : '');
413
- $playtimeseconds = abs($playtimeseconds);
414
- $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60);
415
- $contentminutes = floor($playtimeseconds / 60);
416
- if ($contentseconds >= 60) {
417
- $contentseconds -= 60;
418
- $contentminutes++;
419
- }
420
- return $sign.intval($contentminutes).':'.str_pad($contentseconds, 2, 0, STR_PAD_LEFT);
421
  }
422
 
423
 
424
- function image_type_to_mime_type($imagetypeid) {
425
- // only available in PHP v4.3.0+
426
- static $image_type_to_mime_type = array();
427
- if (empty($image_type_to_mime_type)) {
428
- $image_type_to_mime_type[1] = 'image/gif'; // GIF
429
- $image_type_to_mime_type[2] = 'image/jpeg'; // JPEG
430
- $image_type_to_mime_type[3] = 'image/png'; // PNG
431
- $image_type_to_mime_type[4] = 'application/x-shockwave-flash'; // Flash
432
- $image_type_to_mime_type[5] = 'image/psd'; // PSD
433
- $image_type_to_mime_type[6] = 'image/bmp'; // BMP
434
- $image_type_to_mime_type[7] = 'image/tiff'; // TIFF: little-endian (Intel)
435
- $image_type_to_mime_type[8] = 'image/tiff'; // TIFF: big-endian (Motorola)
436
- //$image_type_to_mime_type[9] = 'image/jpc'; // JPC
437
- //$image_type_to_mime_type[10] = 'image/jp2'; // JPC
438
- //$image_type_to_mime_type[11] = 'image/jpx'; // JPC
439
- //$image_type_to_mime_type[12] = 'image/jb2'; // JPC
440
- $image_type_to_mime_type[13] = 'application/x-shockwave-flash'; // Shockwave
441
- $image_type_to_mime_type[14] = 'image/iff'; // IFF
442
- }
443
- return (isset($image_type_to_mime_type[$imagetypeid]) ? $image_type_to_mime_type[$imagetypeid] : 'application/octet-stream');
444
- }
445
-
446
-
447
- function DateMac2Unix($macdate) {
448
  // Macintosh timestamp: seconds since 00:00h January 1, 1904
449
  // UNIX timestamp: seconds since 00:00h January 1, 1970
450
  return getid3_lib::CastAsInt($macdate - 2082844800);
451
  }
452
 
453
 
454
- function FixedPoint8_8($rawdata) {
455
  return getid3_lib::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
456
  }
457
 
458
 
459
- function FixedPoint16_16($rawdata) {
460
  return getid3_lib::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (getid3_lib::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
461
  }
462
 
463
 
464
- function FixedPoint2_30($rawdata) {
465
  $binarystring = getid3_lib::BigEndian2Bin($rawdata);
466
- return getid3_lib::Bin2Dec(substr($binarystring, 0, 2)) + (float) (getid3_lib::Bin2Dec(substr($binarystring, 2, 30)) / 1073741824);
467
  }
468
 
469
 
470
- function CreateDeepArray($ArrayPath, $Separator, $Value) {
471
  // assigns $Value to a nested array path:
472
  // $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt')
473
  // is the same as:
@@ -485,7 +492,7 @@ class getid3_lib
485
  return $ReturnedArray;
486
  }
487
 
488
- function array_max($arraydata, $returnkey=false) {
489
  $maxvalue = false;
490
  $maxkey = false;
491
  foreach ($arraydata as $key => $value) {
@@ -499,7 +506,7 @@ class getid3_lib
499
  return ($returnkey ? $maxkey : $maxvalue);
500
  }
501
 
502
- function array_min($arraydata, $returnkey=false) {
503
  $minvalue = false;
504
  $minkey = false;
505
  foreach ($arraydata as $key => $value) {
@@ -513,79 +520,35 @@ class getid3_lib
513
  return ($returnkey ? $minkey : $minvalue);
514
  }
515
 
516
-
517
- function md5_file($file) {
518
-
519
- // md5_file() exists in PHP 4.2.0+.
520
- if (function_exists('md5_file')) {
521
- return md5_file($file);
522
- }
523
-
524
- if (GETID3_OS_ISWINDOWS) {
525
-
526
- $RequiredFiles = array('cygwin1.dll', 'md5sum.exe');
527
- foreach ($RequiredFiles as $required_file) {
528
- if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
529
- die(implode(' and ', $RequiredFiles).' are required in '.GETID3_HELPERAPPSDIR.' for getid3_lib::md5_file() to function under Windows in PHP < v4.2.0');
530
- }
531
  }
532
- $commandline = GETID3_HELPERAPPSDIR.'md5sum.exe "'.str_replace('/', DIRECTORY_SEPARATOR, $file).'"';
533
- if (ereg("^[\\]?([0-9a-f]{32})", strtolower(`$commandline`), $r)) {
534
- return $r[1];
535
- }
536
-
537
- } else {
538
-
539
- // The following works under UNIX only
540
- $file = str_replace('`', '\\`', $file);
541
- if (ereg("^([0-9a-f]{32})[ \t\n\r]", `md5sum "$file"`, $r)) {
542
- return $r[1];
543
- }
544
-
545
  }
546
  return false;
547
  }
548
 
549
-
550
- function sha1_file($file) {
551
-
552
- // sha1_file() exists in PHP 4.3.0+.
553
- if (function_exists('sha1_file')) {
554
- return sha1_file($file);
555
  }
556
-
557
- $file = str_replace('`', '\\`', $file);
558
-
559
- if (GETID3_OS_ISWINDOWS) {
560
-
561
- $RequiredFiles = array('cygwin1.dll', 'sha1sum.exe');
562
- foreach ($RequiredFiles as $required_file) {
563
- if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
564
- die(implode(' and ', $RequiredFiles).' are required in '.GETID3_HELPERAPPSDIR.' for getid3_lib::sha1_file() to function under Windows in PHP < v4.3.0');
565
- }
566
- }
567
- $commandline = GETID3_HELPERAPPSDIR.'sha1sum.exe "'.str_replace('/', DIRECTORY_SEPARATOR, $file).'"';
568
- if (ereg("^sha1=([0-9a-f]{40})", strtolower(`$commandline`), $r)) {
569
- return $r[1];
570
- }
571
-
572
- } else {
573
-
574
- $commandline = 'sha1sum '.escapeshellarg($file).'';
575
- if (ereg("^([0-9a-f]{40})[ \t\n\r]", strtolower(`$commandline`), $r)) {
576
- return $r[1];
577
- }
578
-
579
  }
580
-
581
- return false;
582
  }
583
 
584
 
585
  // Allan Hansen <ah�artemis*dk>
586
  // getid3_lib::md5_data() - returns md5sum for a file from startuing position to absolute end position
587
- function hash_data($file, $offset, $end, $algorithm) {
588
-
 
 
 
589
  switch ($algorithm) {
590
  case 'md5':
591
  $hash_function = 'md5_file';
@@ -602,7 +565,7 @@ class getid3_lib
602
  break;
603
 
604
  default:
605
- die('Invalid algorithm ('.$algorithm.') in getid3_lib::hash_data()');
606
  break;
607
  }
608
  $size = $end - $offset;
@@ -633,16 +596,23 @@ class getid3_lib
633
  $commandline .= $unix_call;
634
 
635
  }
636
- if ((bool) ini_get('safe_mode')) {
637
- $ThisFileInfo['warning'][] = 'PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.' algorithm';
638
  break;
639
  }
640
  return substr(`$commandline`, 0, $hash_length);
641
  }
642
 
 
 
 
 
 
 
 
643
  // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
644
- if (($data_filename = tempnam('*', 'getID3')) === false) {
645
- // can't find anywhere to create a temp file, just die
646
  return false;
647
  }
648
 
@@ -650,52 +620,68 @@ class getid3_lib
650
  $result = false;
651
 
652
  // copy parts of file
653
- if ($fp = @fopen($file, 'rb')) {
654
-
655
- if ($fp_data = @fopen($data_filename, 'wb')) {
656
-
657
- fseek($fp, $offset, SEEK_SET);
658
- $byteslefttowrite = $end - $offset;
659
- while (($byteslefttowrite > 0) && ($buffer = fread($fp, GETID3_FREAD_BUFFER_SIZE))) {
660
- $byteswritten = fwrite($fp_data, $buffer, $byteslefttowrite);
661
- $byteslefttowrite -= $byteswritten;
662
- }
663
- fclose($fp_data);
664
- $result = getid3_lib::$hash_function($data_filename);
665
-
666
- }
667
- fclose($fp);
668
  }
669
  unlink($data_filename);
670
  return $result;
671
  }
672
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
673
 
674
- function iconv_fallback_int_utf8($charval) {
675
  if ($charval < 128) {
676
  // 0bbbbbbb
677
  $newcharstring = chr($charval);
678
  } elseif ($charval < 2048) {
679
  // 110bbbbb 10bbbbbb
680
- $newcharstring = chr(($charval >> 6) | 0xC0);
681
  $newcharstring .= chr(($charval & 0x3F) | 0x80);
682
  } elseif ($charval < 65536) {
683
  // 1110bbbb 10bbbbbb 10bbbbbb
684
- $newcharstring = chr(($charval >> 12) | 0xE0);
685
- $newcharstring .= chr(($charval >> 6) | 0xC0);
686
  $newcharstring .= chr(($charval & 0x3F) | 0x80);
687
  } else {
688
  // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
689
- $newcharstring = chr(($charval >> 18) | 0xF0);
690
- $newcharstring .= chr(($charval >> 12) | 0xC0);
691
- $newcharstring .= chr(($charval >> 6) | 0xC0);
692
  $newcharstring .= chr(($charval & 0x3F) | 0x80);
693
  }
694
  return $newcharstring;
695
  }
696
 
697
  // ISO-8859-1 => UTF-8
698
- function iconv_fallback_iso88591_utf8($string, $bom=false) {
699
  if (function_exists('utf8_encode')) {
700
  return utf8_encode($string);
701
  }
@@ -712,7 +698,7 @@ class getid3_lib
712
  }
713
 
714
  // ISO-8859-1 => UTF-16BE
715
- function iconv_fallback_iso88591_utf16be($string, $bom=false) {
716
  $newcharstring = '';
717
  if ($bom) {
718
  $newcharstring .= "\xFE\xFF";
@@ -724,7 +710,7 @@ class getid3_lib
724
  }
725
 
726
  // ISO-8859-1 => UTF-16LE
727
- function iconv_fallback_iso88591_utf16le($string, $bom=false) {
728
  $newcharstring = '';
729
  if ($bom) {
730
  $newcharstring .= "\xFF\xFE";
@@ -736,12 +722,12 @@ class getid3_lib
736
  }
737
 
738
  // ISO-8859-1 => UTF-16LE (BOM)
739
- function iconv_fallback_iso88591_utf16($string) {
740
  return getid3_lib::iconv_fallback_iso88591_utf16le($string, true);
741
  }
742
 
743
  // UTF-8 => ISO-8859-1
744
- function iconv_fallback_utf8_iso88591($string) {
745
  if (function_exists('utf8_decode')) {
746
  return utf8_decode($string);
747
  }
@@ -753,20 +739,20 @@ class getid3_lib
753
  if ((ord($string{$offset}) | 0x07) == 0xF7) {
754
  // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
755
  $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
756
- ((ord($string{($offset + 1)}) & 0x3F) << 12) &
757
- ((ord($string{($offset + 2)}) & 0x3F) << 6) &
758
- (ord($string{($offset + 3)}) & 0x3F);
759
  $offset += 4;
760
  } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
761
  // 1110bbbb 10bbbbbb 10bbbbbb
762
  $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
763
- ((ord($string{($offset + 1)}) & 0x3F) << 6) &
764
- (ord($string{($offset + 2)}) & 0x3F);
765
  $offset += 3;
766
  } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
767
  // 110bbbbb 10bbbbbb
768
  $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
769
- (ord($string{($offset + 1)}) & 0x3F);
770
  $offset += 2;
771
  } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
772
  // 0bbbbbbb
@@ -785,7 +771,7 @@ class getid3_lib
785
  }
786
 
787
  // UTF-8 => UTF-16BE
788
- function iconv_fallback_utf8_utf16be($string, $bom=false) {
789
  $newcharstring = '';
790
  if ($bom) {
791
  $newcharstring .= "\xFE\xFF";
@@ -796,20 +782,20 @@ class getid3_lib
796
  if ((ord($string{$offset}) | 0x07) == 0xF7) {
797
  // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
798
  $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
799
- ((ord($string{($offset + 1)}) & 0x3F) << 12) &
800
- ((ord($string{($offset + 2)}) & 0x3F) << 6) &
801
- (ord($string{($offset + 3)}) & 0x3F);
802
  $offset += 4;
803
  } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
804
  // 1110bbbb 10bbbbbb 10bbbbbb
805
  $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
806
- ((ord($string{($offset + 1)}) & 0x3F) << 6) &
807
- (ord($string{($offset + 2)}) & 0x3F);
808
  $offset += 3;
809
  } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
810
  // 110bbbbb 10bbbbbb
811
  $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
812
- (ord($string{($offset + 1)}) & 0x3F);
813
  $offset += 2;
814
  } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
815
  // 0bbbbbbb
@@ -828,7 +814,7 @@ class getid3_lib
828
  }
829
 
830
  // UTF-8 => UTF-16LE
831
- function iconv_fallback_utf8_utf16le($string, $bom=false) {
832
  $newcharstring = '';
833
  if ($bom) {
834
  $newcharstring .= "\xFF\xFE";
@@ -839,20 +825,20 @@ class getid3_lib
839
  if ((ord($string{$offset}) | 0x07) == 0xF7) {
840
  // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
841
  $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
842
- ((ord($string{($offset + 1)}) & 0x3F) << 12) &
843
- ((ord($string{($offset + 2)}) & 0x3F) << 6) &
844
- (ord($string{($offset + 3)}) & 0x3F);
845
  $offset += 4;
846
  } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
847
  // 1110bbbb 10bbbbbb 10bbbbbb
848
  $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
849
- ((ord($string{($offset + 1)}) & 0x3F) << 6) &
850
- (ord($string{($offset + 2)}) & 0x3F);
851
  $offset += 3;
852
  } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
853
  // 110bbbbb 10bbbbbb
854
  $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
855
- (ord($string{($offset + 1)}) & 0x3F);
856
  $offset += 2;
857
  } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
858
  // 0bbbbbbb
@@ -871,12 +857,12 @@ class getid3_lib
871
  }
872
 
873
  // UTF-8 => UTF-16LE (BOM)
874
- function iconv_fallback_utf8_utf16($string) {
875
  return getid3_lib::iconv_fallback_utf8_utf16le($string, true);
876
  }
877
 
878
  // UTF-16BE => UTF-8
879
- function iconv_fallback_utf16be_utf8($string) {
880
  if (substr($string, 0, 2) == "\xFE\xFF") {
881
  // strip BOM
882
  $string = substr($string, 2);
@@ -890,7 +876,7 @@ class getid3_lib
890
  }
891
 
892
  // UTF-16LE => UTF-8
893
- function iconv_fallback_utf16le_utf8($string) {
894
  if (substr($string, 0, 2) == "\xFF\xFE") {
895
  // strip BOM
896
  $string = substr($string, 2);
@@ -904,7 +890,7 @@ class getid3_lib
904
  }
905
 
906
  // UTF-16BE => ISO-8859-1
907
- function iconv_fallback_utf16be_iso88591($string) {
908
  if (substr($string, 0, 2) == "\xFE\xFF") {
909
  // strip BOM
910
  $string = substr($string, 2);
@@ -918,7 +904,7 @@ class getid3_lib
918
  }
919
 
920
  // UTF-16LE => ISO-8859-1
921
- function iconv_fallback_utf16le_iso88591($string) {
922
  if (substr($string, 0, 2) == "\xFF\xFE") {
923
  // strip BOM
924
  $string = substr($string, 2);
@@ -932,7 +918,7 @@ class getid3_lib
932
  }
933
 
934
  // UTF-16 (BOM) => ISO-8859-1
935
- function iconv_fallback_utf16_iso88591($string) {
936
  $bom = substr($string, 0, 2);
937
  if ($bom == "\xFE\xFF") {
938
  return getid3_lib::iconv_fallback_utf16be_iso88591(substr($string, 2));
@@ -943,7 +929,7 @@ class getid3_lib
943
  }
944
 
945
  // UTF-16 (BOM) => UTF-8
946
- function iconv_fallback_utf16_utf8($string) {
947
  $bom = substr($string, 0, 2);
948
  if ($bom == "\xFE\xFF") {
949
  return getid3_lib::iconv_fallback_utf16be_utf8(substr($string, 2));
@@ -953,7 +939,7 @@ class getid3_lib
953
  return $string;
954
  }
955
 
956
- function iconv_fallback($in_charset, $out_charset, $string) {
957
 
958
  if ($in_charset == $out_charset) {
959
  return $string;
@@ -961,23 +947,22 @@ class getid3_lib
961
 
962
  // iconv() availble
963
  if (function_exists('iconv')) {
 
 
 
 
 
 
 
 
964
 
965
- if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) {
966
- switch ($out_charset) {
967
- case 'ISO-8859-1':
968
- $converted_string = rtrim($converted_string, "\x00");
969
- break;
970
- }
971
- return $converted_string;
972
- }
973
-
974
- // iconv() may sometimes fail with "illegal character in input string" error message
975
- // and return an empty string, but returning the unconverted string is more useful
976
- return $string;
977
- }
978
 
979
 
980
- // iconv() not available
981
  static $ConversionFunctionList = array();
982
  if (empty($ConversionFunctionList)) {
983
  $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8';
@@ -999,41 +984,42 @@ class getid3_lib
999
  $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
1000
  return getid3_lib::$ConversionFunction($string);
1001
  }
1002
- die('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
1003
  }
1004
 
1005
 
1006
- function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
 
1007
  $HTMLstring = '';
1008
 
1009
  switch ($charset) {
1010
- case 'ISO-8859-1':
1011
- case 'ISO8859-1':
1012
- case 'ISO-8859-15':
1013
- case 'ISO8859-15':
1014
- case 'cp866':
1015
- case 'ibm866':
1016
  case '866':
 
 
 
 
 
1017
  case 'cp1251':
1018
- case 'Windows-1251':
1019
- case 'win-1251':
1020
- case '1251':
1021
  case 'cp1252':
1022
- case 'Windows-1252':
1023
- case '1252':
 
 
 
 
 
 
 
1024
  case 'KOI8-R':
1025
  case 'koi8-ru':
1026
  case 'koi8r':
1027
- case 'BIG5':
1028
- case '950':
1029
- case 'GB2312':
1030
- case '936':
1031
- case 'BIG5-HKSCS':
1032
  case 'Shift_JIS':
1033
  case 'SJIS':
1034
- case '932':
1035
- case 'EUC-JP':
1036
- case 'EUCJP':
1037
  $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
1038
  break;
1039
 
@@ -1058,7 +1044,7 @@ class getid3_lib
1058
  $charval += (ord($string{++$i}) & 0x3F);
1059
  }
1060
  if (($charval >= 32) && ($charval <= 127)) {
1061
- $HTMLstring .= chr($charval);
1062
  } else {
1063
  $HTMLstring .= '&#'.$charval.';';
1064
  }
@@ -1096,7 +1082,7 @@ class getid3_lib
1096
 
1097
 
1098
 
1099
- function RGADnameLookup($namecode) {
1100
  static $RGADname = array();
1101
  if (empty($RGADname)) {
1102
  $RGADname[0] = 'not set';
@@ -1108,7 +1094,7 @@ class getid3_lib
1108
  }
1109
 
1110
 
1111
- function RGADoriginatorLookup($originatorcode) {
1112
  static $RGADoriginator = array();
1113
  if (empty($RGADoriginator)) {
1114
  $RGADoriginator[0] = 'unspecified';
@@ -1121,7 +1107,7 @@ class getid3_lib
1121
  }
1122
 
1123
 
1124
- function RGADadjustmentLookup($rawadjustment, $signbit) {
1125
  $adjustment = $rawadjustment / 10;
1126
  if ($signbit == 1) {
1127
  $adjustment *= -1;
@@ -1130,7 +1116,7 @@ class getid3_lib
1130
  }
1131
 
1132
 
1133
- function RGADgainString($namecode, $originatorcode, $replaygain) {
1134
  if ($replaygain < 0) {
1135
  $signbit = '1';
1136
  } else {
@@ -1145,25 +1131,33 @@ class getid3_lib
1145
  return $gainstring;
1146
  }
1147
 
1148
- function RGADamplitude2dB($amplitude) {
1149
  return 20 * log10($amplitude);
1150
  }
1151
 
1152
 
1153
- function GetDataImageSize($imgData) {
 
 
 
 
 
 
 
 
1154
  $GetDataImageSize = false;
1155
- if ($tempfilename = tempnam('*', 'getID3')) {
1156
- if ($tmp = @fopen($tempfilename, 'wb')) {
1157
  fwrite($tmp, $imgData);
1158
  fclose($tmp);
1159
- $GetDataImageSize = @GetImageSize($tempfilename);
1160
  }
1161
  unlink($tempfilename);
1162
  }
1163
  return $GetDataImageSize;
1164
  }
1165
 
1166
- function ImageTypesLookup($imagetypeid) {
1167
  static $ImageTypesLookup = array();
1168
  if (empty($ImageTypesLookup)) {
1169
  $ImageTypesLookup[1] = 'gif';
@@ -1184,7 +1178,7 @@ class getid3_lib
1184
  return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : '');
1185
  }
1186
 
1187
- function CopyTagsToComments(&$ThisFileInfo) {
1188
 
1189
  // Copy all entries from ['tags'] into common ['comments']
1190
  if (!empty($ThisFileInfo['tags'])) {
@@ -1207,7 +1201,7 @@ class getid3_lib
1207
  }
1208
  }
1209
 
1210
- } else {
1211
 
1212
  $newvaluelength = strlen(trim($value));
1213
  foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
@@ -1219,8 +1213,9 @@ class getid3_lib
1219
  }
1220
 
1221
  }
1222
- if (empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
1223
- $ThisFileInfo['comments'][$tagname][] = trim($value);
 
1224
  }
1225
  }
1226
  }
@@ -1228,21 +1223,31 @@ class getid3_lib
1228
  }
1229
 
1230
  // Copy to ['comments_html']
1231
- foreach ($ThisFileInfo['comments'] as $field => $values) {
1232
- foreach ($values as $index => $value) {
1233
- $ThisFileInfo['comments_html'][$field][$index] = str_replace('&#0;', '', getid3_lib::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
1234
- }
1235
- }
 
 
 
 
 
 
 
 
 
1236
  }
 
1237
  }
1238
 
1239
 
1240
- function EmbeddedLookup($key, $begin, $end, $file, $name) {
1241
 
1242
  // Cached
1243
  static $cache;
1244
  if (isset($cache[$file][$name])) {
1245
- return @$cache[$file][$name][$key];
1246
  }
1247
 
1248
  // Init
@@ -1272,20 +1277,22 @@ class getid3_lib
1272
 
1273
  // METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
1274
  //$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
1275
- @list($ThisKey, $ThisValue) = explode("\t", $line, 2);
 
 
1276
  $cache[$file][$name][$ThisKey] = trim($ThisValue);
1277
  }
1278
 
1279
  // Close and return
1280
  fclose($fp);
1281
- return @$cache[$file][$name][$key];
1282
  }
1283
 
1284
- function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) {
1285
  global $GETID3_ERRORARRAY;
1286
 
1287
  if (file_exists($filename)) {
1288
- if (@include_once($filename)) {
1289
  return true;
1290
  } else {
1291
  $diemessage = basename($sourcefile).' depends on '.$filename.', which has errors';
@@ -1294,13 +1301,17 @@ class getid3_lib
1294
  $diemessage = basename($sourcefile).' depends on '.$filename.', which is missing';
1295
  }
1296
  if ($DieOnFailure) {
1297
- die($diemessage);
1298
  } else {
1299
  $GETID3_ERRORARRAY[] = $diemessage;
1300
  }
1301
  return false;
1302
  }
1303
 
 
 
 
 
1304
  }
1305
 
1306
  ?>
14
  class getid3_lib
15
  {
16
 
17
+ static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8') {
18
  $returnstring = '';
19
  for ($i = 0; $i < strlen($string); $i++) {
20
  if ($hex) {
21
  $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT);
22
  } else {
23
+ $returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string{$i}) ? $string{$i} : '�');
24
  }
25
  if ($spaces) {
26
  $returnstring .= ' ';
27
  }
28
  }
29
+ if (!empty($htmlencoding)) {
30
+ if ($htmlencoding === true) {
31
+ $htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean
32
+ }
33
+ $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding);
34
  }
35
  return $returnstring;
36
  }
37
 
38
+ static function trunc($floatnumber) {
 
 
 
 
 
 
 
 
39
  // truncates a floating-point number at the decimal point
40
  // returns int (if possible, otherwise float)
41
  if ($floatnumber >= 1) {
45
  } else {
46
  $truncatednumber = 0;
47
  }
48
+ if (getid3_lib::intValueSupported($truncatednumber)) {
49
  $truncatednumber = (int) $truncatednumber;
50
  }
51
  return $truncatednumber;
52
  }
53
 
54
 
55
+ static function safe_inc(&$variable, $increment=1) {
56
+ if (isset($variable)) {
57
+ $variable += $increment;
58
+ } else {
59
+ $variable = $increment;
60
+ }
61
+ return true;
62
+ }
63
+
64
+ static function CastAsInt($floatnum) {
65
  // convert to float if not already
66
  $floatnum = (float) $floatnum;
67
 
68
  // convert a float to type int, only if possible
69
  if (getid3_lib::trunc($floatnum) == $floatnum) {
70
  // it's not floating point
71
+ if (getid3_lib::intValueSupported($floatnum)) {
72
  // it's within int range
73
  $floatnum = (int) $floatnum;
74
  }
76
  return $floatnum;
77
  }
78
 
79
+ public static function intValueSupported($num) {
80
+ // check if integers are 64-bit
81
+ static $hasINT64 = null;
82
+ if ($hasINT64 === null) { // 10x faster than is_null()
83
+ $hasINT64 = is_int(pow(2, 31)); // 32-bit int are limited to (2^31)-1
84
+ if (!$hasINT64 && !defined('PHP_INT_MIN')) {
85
+ define('PHP_INT_MIN', ~PHP_INT_MAX);
86
+ }
87
+ }
88
+ // if integers are 64-bit - no other check required
89
+ if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
90
+ return true;
91
+ }
92
+ return false;
93
+ }
94
+
95
+ static function DecimalizeFraction($fraction) {
96
+ list($numerator, $denominator) = explode('/', $fraction);
97
+ return $numerator / ($denominator ? $denominator : 1);
98
+ }
99
+
100
 
101
+ static function DecimalBinary2Float($binarynumerator) {
102
  $numerator = getid3_lib::Bin2Dec($binarynumerator);
103
  $denominator = getid3_lib::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator)));
104
  return ($numerator / $denominator);
105
  }
106
 
107
 
108
+ static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) {
109
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
110
  if (strpos($binarypointnumber, '.') === false) {
111
  $binarypointnumber = '0.'.$binarypointnumber;
129
  }
130
 
131
 
132
+ static function Float2BinaryDecimal($floatvalue) {
133
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
134
  $maxbits = 128; // to how many bits of precision should the calculations be taken?
135
  $intpart = getid3_lib::trunc($floatvalue);
145
  }
146
 
147
 
148
+ static function Float2String($floatvalue, $bits) {
149
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
150
  switch ($bits) {
151
  case 32:
176
  }
177
 
178
 
179
+ static function LittleEndian2Float($byteword) {
180
  return getid3_lib::BigEndian2Float(strrev($byteword));
181
  }
182
 
183
 
184
+ static function BigEndian2Float($byteword) {
185
  // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
186
  // http://www.psc.edu/general/software/packages/ieee/ieee.html
187
  // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
188
 
189
  $bitword = getid3_lib::BigEndian2Bin($byteword);
190
  if (!$bitword) {
191
+ return 0;
192
+ }
193
  $signbit = $bitword{0};
194
 
195
  switch (strlen($byteword) * 8) {
259
  }
260
 
261
 
262
+ static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {
263
  $intvalue = 0;
264
  $bytewordlen = strlen($byteword);
265
+ if ($bytewordlen == 0) {
266
+ return false;
267
+ }
268
  for ($i = 0; $i < $bytewordlen; $i++) {
269
  if ($synchsafe) { // disregard MSB, effectively 7-bit bytes
270
+ //$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems
271
+ $intvalue += (ord($byteword{$i}) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7);
272
  } else {
273
  $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
274
  }
275
  }
276
  if ($signed && !$synchsafe) {
277
  // synchsafe ints are not allowed to be signed
278
+ if ($bytewordlen <= PHP_INT_SIZE) {
279
+ $signMaskBit = 0x80 << (8 * ($bytewordlen - 1));
280
+ if ($intvalue & $signMaskBit) {
281
+ $intvalue = 0 - ($intvalue & ($signMaskBit - 1));
282
+ }
283
+ } else {
284
+ throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in getid3_lib::BigEndian2Int()');
285
+ break;
 
 
 
 
 
 
286
  }
287
  }
288
  return getid3_lib::CastAsInt($intvalue);
289
  }
290
 
291
 
292
+ static function LittleEndian2Int($byteword, $signed=false) {
293
  return getid3_lib::BigEndian2Int(strrev($byteword), false, $signed);
294
  }
295
 
296
 
297
+ static function BigEndian2Bin($byteword) {
298
  $binvalue = '';
299
  $bytewordlen = strlen($byteword);
300
  for ($i = 0; $i < $bytewordlen; $i++) {
304
  }
305
 
306
 
307
+ static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) {
308
  if ($number < 0) {
309
+ throw new Exception('ERROR: getid3_lib::BigEndian2String() does not support negative numbers');
310
  }
311
  $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
312
  $intstring = '';
313
  if ($signed) {
314
+ if ($minbytes > PHP_INT_SIZE) {
315
+ throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in getid3_lib::BigEndian2String()');
316
  }
317
  $number = $number & (0x80 << (8 * ($minbytes - 1)));
318
  }
325
  }
326
 
327
 
328
+ static function Dec2Bin($number) {
329
  while ($number >= 256) {
330
  $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
331
  $number = floor($number / 256);
339
  }