18 public static function PrintHexBytes($string, $hex=
true, $spaces=
true, $htmlencoding=
'UTF-8') {
20 for (
$i = 0;
$i < strlen($string);
$i++) {
22 $returnstring .= str_pad(dechex(ord($string{
$i})), 2,
'0', STR_PAD_LEFT);
24 $returnstring .=
' '.(preg_match(
"#[\x20-\x7E]#", $string{
$i}) ? $string{
$i} :
'ยค');
30 if (!empty($htmlencoding)) {
31 if ($htmlencoding ===
true) {
32 $htmlencoding =
'UTF-8';
34 $returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding);
39 public static function trunc($floatnumber) {
42 if ($floatnumber >= 1) {
43 $truncatednumber = floor($floatnumber);
44 } elseif ($floatnumber <= -1) {
45 $truncatednumber = ceil($floatnumber);
49 if (self::intValueSupported($truncatednumber)) {
50 $truncatednumber = (int) $truncatednumber;
52 return $truncatednumber;
56 public static function safe_inc(&$variable, $increment=1) {
57 if (isset($variable)) {
58 $variable += $increment;
60 $variable = $increment;
67 $floatnum = (float) $floatnum;
70 if (self::trunc($floatnum) == $floatnum) {
72 if (self::intValueSupported($floatnum)) {
74 $floatnum = (int) $floatnum;
82 static $hasINT64 = null;
83 if ($hasINT64 === null) {
84 $hasINT64 = is_int(pow(2, 31));
85 if (!$hasINT64 && !
defined(
'PHP_INT_MIN')) {
86 define(
'PHP_INT_MIN', ~PHP_INT_MAX);
90 if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
97 list($numerator, $denominator) = explode(
'/', $fraction);
98 return $numerator / ($denominator ? $denominator : 1);
103 $numerator = self::Bin2Dec($binarynumerator);
104 $denominator = self::Bin2Dec(
'1'.str_repeat(
'0', strlen($binarynumerator)));
105 return ($numerator / $denominator);
111 if (strpos($binarypointnumber,
'.') ===
false) {
112 $binarypointnumber =
'0.'.$binarypointnumber;
113 } elseif ($binarypointnumber{0} ==
'.') {
114 $binarypointnumber =
'0'.$binarypointnumber;
117 while (($binarypointnumber{0} !=
'1') || (substr($binarypointnumber, 1, 1) !=
'.')) {
118 if (substr($binarypointnumber, 1, 1) ==
'.') {
120 $binarypointnumber = substr($binarypointnumber, 2, 1).
'.'.substr($binarypointnumber, 3);
122 $pointpos = strpos($binarypointnumber,
'.');
123 $exponent += ($pointpos - 1);
124 $binarypointnumber = str_replace(
'.',
'', $binarypointnumber);
125 $binarypointnumber = $binarypointnumber{0}.
'.'.substr($binarypointnumber, 1);
128 $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2,
'0', STR_PAD_RIGHT);
129 return array(
'normalized'=>$binarypointnumber,
'exponent'=>(
int) $exponent);
136 $intpart = self::trunc($floatvalue);
137 $floatpart = abs($floatvalue - $intpart);
138 $pointbitstring =
'';
139 while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) {
141 $pointbitstring .= (
string) self::trunc($floatpart);
142 $floatpart -= self::trunc($floatpart);
144 $binarypointnumber = decbin($intpart).
'.'.$pointbitstring;
145 return $binarypointnumber;
166 if ($floatvalue >= 0) {
171 $normalizedbinary = self::NormalizeBinaryPoint(self::Float2BinaryDecimal($floatvalue), $fractionbits);
172 $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary[
'exponent'];
173 $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits,
'0', STR_PAD_LEFT);
174 $fractionbitstring = str_pad(substr($normalizedbinary[
'normalized'], 2), $fractionbits,
'0', STR_PAD_RIGHT);
176 return self::BigEndian2String(self::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8,
false);
181 return self::BigEndian2Float(strrev($byteword));
190 $bitword = self::BigEndian2Bin($byteword);
194 $signbit = $bitword{0};
196 switch (strlen($byteword) * 8) {
210 $exponentstring = substr($bitword, 1, 15);
211 $isnormalized = intval($bitword{16});
212 $fractionstring = substr($bitword, 17, 63);
213 $exponent = pow(2, self::Bin2Dec($exponentstring) - 16383);
214 $fraction = $isnormalized + self::DecimalBinary2Float($fractionstring);
215 $floatvalue = $exponent * $fraction;
216 if ($signbit ==
'1') {
226 $exponentstring = substr($bitword, 1, $exponentbits);
227 $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
228 $exponent = self::Bin2Dec($exponentstring);
229 $fraction = self::Bin2Dec($fractionstring);
231 if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) {
234 } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) {
235 if ($signbit ==
'1') {
236 $floatvalue =
'-infinity';
238 $floatvalue =
'+infinity';
240 } elseif (($exponent == 0) && ($fraction == 0)) {
241 if ($signbit ==
'1') {
246 $floatvalue = ($signbit ? 0 : -0);
247 } elseif (($exponent == 0) && ($fraction != 0)) {
249 $floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring);
250 if ($signbit ==
'1') {
253 } elseif ($exponent != 0) {
254 $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + self::DecimalBinary2Float($fractionstring));
255 if ($signbit ==
'1') {
259 return (
float) $floatvalue;
263 public static function BigEndian2Int($byteword, $synchsafe=
false, $signed=
false) {
265 $bytewordlen = strlen($byteword);
266 if ($bytewordlen == 0) {
269 for (
$i = 0;
$i < $bytewordlen;
$i++) {
272 $intvalue += (ord($byteword{
$i}) & 0x7F) * pow(2, ($bytewordlen - 1 -
$i) * 7);
274 $intvalue += ord($byteword{
$i}) * pow(256, ($bytewordlen - 1 -
$i));
277 if ($signed && !$synchsafe) {
279 if ($bytewordlen <= PHP_INT_SIZE) {
280 $signMaskBit = 0x80 << (8 * ($bytewordlen - 1));
281 if ($intvalue & $signMaskBit) {
282 $intvalue = 0 - ($intvalue & ($signMaskBit - 1));
285 throw new Exception(
'ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).
'-bits ('.strlen($byteword).
') in self::BigEndian2Int()');
288 return self::CastAsInt($intvalue);
293 return self::BigEndian2Int(strrev($byteword),
false, $signed);
299 $bytewordlen = strlen($byteword);
300 for (
$i = 0;
$i < $bytewordlen;
$i++) {
301 $binvalue .= str_pad(decbin(ord($byteword{
$i})), 8,
'0', STR_PAD_LEFT);
307 public static function BigEndian2String($number, $minbytes=1, $synchsafe=
false, $signed=
false) {
309 throw new Exception(
'ERROR: self::BigEndian2String() does not support negative numbers');
311 $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
314 if ($minbytes > PHP_INT_SIZE) {
315 throw new Exception(
'ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).
'-bits in self::BigEndian2String()');
317 $number = $number & (0x80 << (8 * ($minbytes - 1)));
319 while ($number != 0) {
320 $quotient = ($number / ($maskbyte + 1));
321 $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring;
322 $number = floor($quotient);
324 return str_pad($intstring, $minbytes,
"\x00", STR_PAD_LEFT);
329 while ($number >= 256) {
330 $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
331 $number = floor($number / 256);
335 for (
$i = 0;
$i < count($bytes);
$i++) {
336 $binstring = ((
$i == count($bytes) - 1) ? decbin($bytes[
$i]) : str_pad(decbin($bytes[$i]), 8,
'0', STR_PAD_LEFT)).$binstring;
342 public static function Bin2Dec($binstring, $signed=
false) {
345 if ($binstring{0} ==
'1') {
348 $binstring = substr($binstring, 1);
351 for (
$i = 0;
$i < strlen($binstring);
$i++) {
352 $decvalue += ((int) substr($binstring, strlen($binstring) -
$i - 1, 1)) * pow(2,
$i);
354 return self::CastAsInt($decvalue * $signmult);
361 $binstringreversed = strrev($binstring);
362 for (
$i = 0;
$i < strlen($binstringreversed);
$i += 8) {
363 $string = chr(self::Bin2Dec(strrev(substr($binstringreversed,
$i, 8)))).$string;
371 while ($number > 0) {
373 $intstring = $intstring.chr($number & 127);
376 $intstring = $intstring.chr($number & 255);
380 return str_pad($intstring, $minbytes,
"\x00", STR_PAD_RIGHT);
387 if (!is_array($array1) || !is_array($array2)) {
391 foreach ($array2 as
$key => $val) {
392 if (is_array($val) && isset($newarray[
$key]) && is_array($newarray[$key])) {
393 $newarray[
$key] = self::array_merge_clobber($newarray[$key], $val);
395 $newarray[
$key] = $val;
403 if (!is_array($array1) || !is_array($array2)) {
407 foreach ($array2 as
$key => $val) {
408 if (is_array($val) && isset($newarray[
$key]) && is_array($newarray[$key])) {
409 $newarray[
$key] = self::array_merge_noclobber($newarray[$key], $val);
410 } elseif (!isset($newarray[$key])) {
411 $newarray[
$key] = $val;
418 if (!is_array($array1) || !is_array($array2)) {
421 # naturally, this only works non-recursively 422 $newarray = array_flip($array1);
423 foreach (array_flip($array2) as
$key => $val) {
424 if (!isset($newarray[
$key])) {
425 $newarray[
$key] = count($newarray);
428 return array_flip($newarray);
434 foreach ($theArray as
$key => $value) {
435 if (is_array($value)) {
436 self::ksort_recursive($theArray[
$key]);
446 for (
$i = 0;
$i < $numextensions;
$i++) {
447 $offset = strpos($reversedfilename,
'.', $offset + 1);
448 if ($offset ===
false) {
452 return strrev(substr($reversedfilename, 0, $offset));
459 $sign = (($seconds < 0) ?
'-' :
'');
460 $seconds = round(abs($seconds));
461 $H = (int) floor( $seconds / 3600);
462 $M = (int) floor(($seconds - (3600 * $H) ) / 60);
463 $S = (int) round( $seconds - (3600 * $H) - (60 * $M) );
464 return $sign.($H ? $H.
':' :
'').($H ? str_pad($M, 2,
'0', STR_PAD_LEFT) : intval($M)).
':'.str_pad($S, 2, 0, STR_PAD_LEFT);
471 return self::CastAsInt($macdate - 2082844800);
476 return self::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (self::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
481 return self::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (self::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
486 $binarystring = self::BigEndian2Bin($rawdata);
487 return self::Bin2Dec(substr($binarystring, 0, 2)) + (float) (self::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30));
498 $ArrayPath = ltrim($ArrayPath, $Separator);
499 if (($pos = strpos($ArrayPath, $Separator)) !==
false) {
500 $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value);
502 $ReturnedArray[$ArrayPath] = $Value;
504 return $ReturnedArray;
507 public static function array_max($arraydata, $returnkey=
false) {
510 foreach ($arraydata as
$key => $value) {
511 if (!is_array($value)) {
512 if ($value > $maxvalue) {
518 return ($returnkey ? $maxkey : $maxvalue);
521 public static function array_min($arraydata, $returnkey=
false) {
524 foreach ($arraydata as
$key => $value) {
525 if (!is_array($value)) {
526 if ($value > $minvalue) {
532 return ($returnkey ? $minkey : $minvalue);
536 if (function_exists(
'simplexml_load_string') && function_exists(
'libxml_disable_entity_loader')) {
539 $loader = libxml_disable_entity_loader(
true);
540 $XMLobject = simplexml_load_string($XMLstring,
'SimpleXMLElement', LIBXML_NOENT);
541 $return = self::SimpleXMLelement2array($XMLobject);
542 libxml_disable_entity_loader(
$loader);
549 if (!is_object($XMLobject) && !is_array($XMLobject)) {
552 $XMLarray = (is_object($XMLobject) ? get_object_vars($XMLobject) : $XMLobject);
553 foreach ($XMLarray as
$key => $value) {
554 $XMLarray[
$key] = self::SimpleXMLelement2array($value);
563 static $tempdir =
'';
564 if (!self::intValueSupported(
$end)) {
567 switch ($algorithm) {
569 $hash_function =
'md5_file';
570 $unix_call =
'md5sum';
571 $windows_call =
'md5sum.exe';
576 $hash_function =
'sha1_file';
577 $unix_call =
'sha1sum';
578 $windows_call =
'sha1sum.exe';
583 throw new Exception(
'Invalid algorithm ('.$algorithm.
') in self::hash_data()');
588 if (GETID3_OS_ISWINDOWS) {
592 if ($algorithm ==
'sha1') {
596 $RequiredFiles =
array(
'cygwin1.dll',
'head.exe',
'tail.exe', $windows_call);
597 foreach ($RequiredFiles as $required_file) {
598 if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
603 $commandline = GETID3_HELPERAPPSDIR.
'head.exe -c '.
$end.
' '.escapeshellarg(str_replace(
'/', DIRECTORY_SEPARATOR,
$file)).
' | ';
604 $commandline .= GETID3_HELPERAPPSDIR.
'tail.exe -c '.
$size.
' | ';
605 $commandline .= GETID3_HELPERAPPSDIR.$windows_call;
609 $commandline =
'head -c'.$end.
' '.escapeshellarg(
$file).
' | ';
610 $commandline .=
'tail -c'.$size.
' | ';
611 $commandline .= $unix_call;
614 if (preg_match(
'#(1|ON)#i', ini_get(
'safe_mode'))) {
618 return substr(`$commandline`, 0, $hash_length);
621 if (empty($tempdir)) {
623 require_once(dirname(__FILE__).
'/getid3.php');
624 $getid3_temp =
new getID3();
625 $tempdir = $getid3_temp->tempdir;
629 if (($data_filename = tempnam($tempdir,
'gI3')) ===
false) {
639 self::CopyFileParts(
$file, $data_filename, $offset,
$end - $offset);
640 $result = $hash_function($data_filename);
642 throw new Exception(
'self::CopyFileParts() failed in getid_lib::hash_data(): '.$e->getMessage());
644 unlink($data_filename);
648 public static function CopyFileParts($filename_source, $filename_dest, $offset, $length) {
649 if (!self::intValueSupported($offset + $length)) {
650 throw new Exception(
'cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).
'GB limit');
652 if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source,
'rb'))) {
653 if (($fp_dest = fopen($filename_dest,
'wb'))) {
654 if (fseek($fp_src, $offset) == 0) {
655 $byteslefttowrite = $length;
657 $byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
658 $byteslefttowrite -= $byteswritten;
662 throw new Exception(
'failed to seek to offset '.$offset.
' in '.$filename_source);
666 throw new Exception(
'failed to create file for writing '.$filename_dest);
670 throw new Exception(
'failed to open file for reading '.$filename_source);
676 if ($charval < 128) {
678 $newcharstring = chr($charval);
679 } elseif ($charval < 2048) {
681 $newcharstring = chr(($charval >> 6) | 0xC0);
682 $newcharstring .= chr(($charval & 0x3F) | 0x80);
683 } elseif ($charval < 65536) {
685 $newcharstring = chr(($charval >> 12) | 0xE0);
686 $newcharstring .= chr(($charval >> 6) | 0xC0);
687 $newcharstring .= chr(($charval & 0x3F) | 0x80);
690 $newcharstring = chr(($charval >> 18) | 0xF0);
691 $newcharstring .= chr(($charval >> 12) | 0xC0);
692 $newcharstring .= chr(($charval >> 6) | 0xC0);
693 $newcharstring .= chr(($charval & 0x3F) | 0x80);
695 return $newcharstring;
700 if (function_exists(
'utf8_encode')) {
701 return utf8_encode($string);
706 $newcharstring .=
"\xEF\xBB\xBF";
708 for (
$i = 0;
$i < strlen($string);
$i++) {
709 $charval = ord($string{
$i});
710 $newcharstring .= self::iconv_fallback_int_utf8($charval);
712 return $newcharstring;
719 $newcharstring .=
"\xFE\xFF";
721 for (
$i = 0;
$i < strlen($string);
$i++) {
722 $newcharstring .=
"\x00".$string{
$i};
724 return $newcharstring;
731 $newcharstring .=
"\xFF\xFE";
733 for (
$i = 0;
$i < strlen($string);
$i++) {
734 $newcharstring .= $string{
$i}.
"\x00";
736 return $newcharstring;
741 return self::iconv_fallback_iso88591_utf16le($string,
true);
746 if (function_exists(
'utf8_decode')) {
747 return utf8_decode($string);
752 $stringlength = strlen($string);
753 while ($offset < $stringlength) {
754 if ((ord($string{$offset}) | 0x07) == 0xF7) {
756 $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
757 ((ord($string{($offset + 1)}) & 0x3F) << 12) &
758 ((ord($string{($offset + 2)}) & 0x3F) << 6) &
759 (ord($string{($offset + 3)}) & 0x3F);
761 } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
763 $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
764 ((ord($string{($offset + 1)}) & 0x3F) << 6) &
765 (ord($string{($offset + 2)}) & 0x3F);
767 } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
769 $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
770 (ord($string{($offset + 1)}) & 0x3F);
772 } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
774 $charval = ord($string{$offset});
781 if ($charval !==
false) {
782 $newcharstring .= (($charval < 256) ? chr($charval) :
'?');
785 return $newcharstring;
792 $newcharstring .=
"\xFE\xFF";
795 $stringlength = strlen($string);
796 while ($offset < $stringlength) {
797 if ((ord($string{$offset}) | 0x07) == 0xF7) {
799 $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
800 ((ord($string{($offset + 1)}) & 0x3F) << 12) &
801 ((ord($string{($offset + 2)}) & 0x3F) << 6) &
802 (ord($string{($offset + 3)}) & 0x3F);
804 } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
806 $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
807 ((ord($string{($offset + 1)}) & 0x3F) << 6) &
808 (ord($string{($offset + 2)}) & 0x3F);
810 } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
812 $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
813 (ord($string{($offset + 1)}) & 0x3F);
815 } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
817 $charval = ord($string{$offset});
824 if ($charval !==
false) {
825 $newcharstring .= (($charval < 65536) ? self::BigEndian2String($charval, 2) :
"\x00".
'?');
828 return $newcharstring;
835 $newcharstring .=
"\xFF\xFE";
838 $stringlength = strlen($string);
839 while ($offset < $stringlength) {
840 if ((ord($string{$offset}) | 0x07) == 0xF7) {
842 $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
843 ((ord($string{($offset + 1)}) & 0x3F) << 12) &
844 ((ord($string{($offset + 2)}) & 0x3F) << 6) &
845 (ord($string{($offset + 3)}) & 0x3F);
847 } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
849 $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
850 ((ord($string{($offset + 1)}) & 0x3F) << 6) &
851 (ord($string{($offset + 2)}) & 0x3F);
853 } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
855 $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
856 (ord($string{($offset + 1)}) & 0x3F);
858 } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
860 $charval = ord($string{$offset});
867 if ($charval !==
false) {
868 $newcharstring .= (($charval < 65536) ? self::LittleEndian2String($charval, 2) :
'?'.
"\x00");
871 return $newcharstring;
876 return self::iconv_fallback_utf8_utf16le($string,
true);
881 if (substr($string, 0, 2) ==
"\xFE\xFF") {
883 $string = substr($string, 2);
886 for (
$i = 0;
$i < strlen($string);
$i += 2) {
887 $charval = self::BigEndian2Int(substr($string,
$i, 2));
888 $newcharstring .= self::iconv_fallback_int_utf8($charval);
890 return $newcharstring;
895 if (substr($string, 0, 2) ==
"\xFF\xFE") {
897 $string = substr($string, 2);
900 for (
$i = 0;
$i < strlen($string);
$i += 2) {
901 $charval = self::LittleEndian2Int(substr($string,
$i, 2));
902 $newcharstring .= self::iconv_fallback_int_utf8($charval);
904 return $newcharstring;
909 if (substr($string, 0, 2) ==
"\xFE\xFF") {
911 $string = substr($string, 2);
914 for (
$i = 0;
$i < strlen($string);
$i += 2) {
915 $charval = self::BigEndian2Int(substr($string,
$i, 2));
916 $newcharstring .= (($charval < 256) ? chr($charval) :
'?');
918 return $newcharstring;
923 if (substr($string, 0, 2) ==
"\xFF\xFE") {
925 $string = substr($string, 2);
928 for (
$i = 0;
$i < strlen($string);
$i += 2) {
929 $charval = self::LittleEndian2Int(substr($string,
$i, 2));
930 $newcharstring .= (($charval < 256) ? chr($charval) :
'?');
932 return $newcharstring;
937 $bom = substr($string, 0, 2);
938 if ($bom ==
"\xFE\xFF") {
939 return self::iconv_fallback_utf16be_iso88591(substr($string, 2));
940 } elseif ($bom ==
"\xFF\xFE") {
941 return self::iconv_fallback_utf16le_iso88591(substr($string, 2));
948 $bom = substr($string, 0, 2);
949 if ($bom ==
"\xFE\xFF") {
950 return self::iconv_fallback_utf16be_utf8(substr($string, 2));
951 } elseif ($bom ==
"\xFF\xFE") {
952 return self::iconv_fallback_utf16le_utf8(substr($string, 2));
959 if ($in_charset == $out_charset) {
964 if (function_exists(
'mb_convert_encoding')) {
965 if ($converted_string = @mb_convert_encoding($string, $out_charset, $in_charset)) {
966 switch ($out_charset) {
968 $converted_string = rtrim($converted_string,
"\x00");
971 return $converted_string;
976 else if (function_exists(
'iconv')) {
977 if ($converted_string = @iconv($in_charset, $out_charset.
'//TRANSLIT', $string)) {
978 switch ($out_charset) {
980 $converted_string = rtrim($converted_string,
"\x00");
983 return $converted_string;
993 static $ConversionFunctionList =
array();
994 if (empty($ConversionFunctionList)) {
995 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-8'] =
'iconv_fallback_iso88591_utf8';
996 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-16'] =
'iconv_fallback_iso88591_utf16';
997 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-16BE'] =
'iconv_fallback_iso88591_utf16be';
998 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-16LE'] =
'iconv_fallback_iso88591_utf16le';
999 $ConversionFunctionList[
'UTF-8'][
'ISO-8859-1'] =
'iconv_fallback_utf8_iso88591';
1000 $ConversionFunctionList[
'UTF-8'][
'UTF-16'] =
'iconv_fallback_utf8_utf16';
1001 $ConversionFunctionList[
'UTF-8'][
'UTF-16BE'] =
'iconv_fallback_utf8_utf16be';
1002 $ConversionFunctionList[
'UTF-8'][
'UTF-16LE'] =
'iconv_fallback_utf8_utf16le';
1003 $ConversionFunctionList[
'UTF-16'][
'ISO-8859-1'] =
'iconv_fallback_utf16_iso88591';
1004 $ConversionFunctionList[
'UTF-16'][
'UTF-8'] =
'iconv_fallback_utf16_utf8';
1005 $ConversionFunctionList[
'UTF-16LE'][
'ISO-8859-1'] =
'iconv_fallback_utf16le_iso88591';
1006 $ConversionFunctionList[
'UTF-16LE'][
'UTF-8'] =
'iconv_fallback_utf16le_utf8';
1007 $ConversionFunctionList[
'UTF-16BE'][
'ISO-8859-1'] =
'iconv_fallback_utf16be_iso88591';
1008 $ConversionFunctionList[
'UTF-16BE'][
'UTF-8'] =
'iconv_fallback_utf16be_utf8';
1010 if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) {
1011 $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
1012 return self::$ConversionFunction($string);
1014 throw new Exception(
'PHP does not has mb_convert_encoding() or iconv() support - cannot convert from '.$in_charset.
' to '.$out_charset);
1018 if (is_string(
$data)) {
1019 return self::MultiByteCharString2HTML(
$data, $charset);
1020 } elseif (is_array(
$data)) {
1021 $return_data =
array();
1023 $return_data[
$key] = self::recursiveMultiByteCharString2HTML($value, $charset);
1025 return $return_data;
1032 $string = (
string) $string;
1035 switch (strtolower($charset)) {
1061 case 'windows-1251':
1062 case 'windows-1252':
1063 $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
1067 $strlen = strlen($string);
1068 for (
$i = 0;
$i < $strlen;
$i++) {
1069 $char_ord_val = ord($string{
$i});
1071 if ($char_ord_val < 0x80) {
1072 $charval = $char_ord_val;
1073 } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F &&
$i+3 < $strlen) {
1074 $charval = (($char_ord_val & 0x07) << 18);
1075 $charval += ((ord($string{++
$i}) & 0x3F) << 12);
1076 $charval += ((ord($string{++
$i}) & 0x3F) << 6);
1077 $charval += (ord($string{++
$i}) & 0x3F);
1078 } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 &&
$i+2 < $strlen) {
1079 $charval = (($char_ord_val & 0x0F) << 12);
1080 $charval += ((ord($string{++
$i}) & 0x3F) << 6);
1081 $charval += (ord($string{++
$i}) & 0x3F);
1082 } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 &&
$i+1 < $strlen) {
1083 $charval = (($char_ord_val & 0x1F) << 6);
1084 $charval += (ord($string{++
$i}) & 0x3F);
1086 if (($charval >= 32) && ($charval <= 127)) {
1087 $HTMLstring .= htmlentities(chr($charval));
1089 $HTMLstring .=
'&#'.$charval.
';';
1095 for (
$i = 0;
$i < strlen($string);
$i += 2) {
1096 $charval = self::LittleEndian2Int(substr($string,
$i, 2));
1097 if (($charval >= 32) && ($charval <= 127)) {
1098 $HTMLstring .= chr($charval);
1100 $HTMLstring .=
'&#'.$charval.
';';
1106 for (
$i = 0;
$i < strlen($string);
$i += 2) {
1107 $charval = self::BigEndian2Int(substr($string,
$i, 2));
1108 if (($charval >= 32) && ($charval <= 127)) {
1109 $HTMLstring .= chr($charval);
1111 $HTMLstring .=
'&#'.$charval.
';';
1117 $HTMLstring =
'ERROR: Character set "'.$charset.
'" not supported in MultiByteCharString2HTML()';
1126 static $RGADname =
array();
1127 if (empty($RGADname)) {
1128 $RGADname[0] =
'not set';
1129 $RGADname[1] =
'Track Gain Adjustment';
1130 $RGADname[2] =
'Album Gain Adjustment';
1133 return (isset($RGADname[$namecode]) ? $RGADname[$namecode] :
'');
1138 static $RGADoriginator =
array();
1139 if (empty($RGADoriginator)) {
1140 $RGADoriginator[0] =
'unspecified';
1141 $RGADoriginator[1] =
'pre-set by artist/producer/mastering engineer';
1142 $RGADoriginator[2] =
'set by user';
1143 $RGADoriginator[3] =
'determined automatically';
1146 return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] :
'');
1151 $adjustment = $rawadjustment / 10;
1152 if ($signbit == 1) {
1155 return (
float) $adjustment;
1160 if ($replaygain < 0) {
1165 $storedreplaygain = intval(round($replaygain * 10));
1166 $gainstring = str_pad(decbin($namecode), 3,
'0', STR_PAD_LEFT);
1167 $gainstring .= str_pad(decbin($originatorcode), 3,
'0', STR_PAD_LEFT);
1168 $gainstring .= $signbit;
1169 $gainstring .= str_pad(decbin($storedreplaygain), 9,
'0', STR_PAD_LEFT);
1175 return 20 * log10($amplitude);
1180 static $tempdir =
'';
1181 if (empty($tempdir)) {
1182 if (function_exists(
'sys_get_temp_dir')) {
1183 $tempdir = sys_get_temp_dir();
1187 if (include_once(dirname(__FILE__).
'/getid3.php')) {
1188 if ($getid3_temp =
new getID3()) {
1189 if ($getid3_temp_tempdir = $getid3_temp->tempdir) {
1190 $tempdir = $getid3_temp_tempdir;
1192 unset($getid3_temp, $getid3_temp_tempdir);
1196 $GetDataImageSize =
false;
1197 if ($tempfilename = tempnam($tempdir,
'gI3')) {
1198 if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename,
'wb'))) {
1199 fwrite($tmp, $imgData);
1201 $GetDataImageSize = @getimagesize($tempfilename, $imageinfo);
1202 if (($GetDataImageSize ===
false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) {
1205 $GetDataImageSize[
'height'] = $GetDataImageSize[0];
1206 $GetDataImageSize[
'width'] = $GetDataImageSize[1];
1208 unlink($tempfilename);
1210 return $GetDataImageSize;
1215 return str_replace(
array(
'image/',
'x-',
'jpeg'),
array(
'',
'',
'jpg'), $mime_type);
1219 static $ImageTypesLookup =
array();
1220 if (empty($ImageTypesLookup)) {
1221 $ImageTypesLookup[1] =
'gif';
1222 $ImageTypesLookup[2] =
'jpeg';
1223 $ImageTypesLookup[3] =
'png';
1224 $ImageTypesLookup[4] =
'swf';
1225 $ImageTypesLookup[5] =
'psd';
1226 $ImageTypesLookup[6] =
'bmp';
1227 $ImageTypesLookup[7] =
'tiff (little-endian)';
1228 $ImageTypesLookup[8] =
'tiff (big-endian)';
1229 $ImageTypesLookup[9] =
'jpc';
1230 $ImageTypesLookup[10] =
'jp2';
1231 $ImageTypesLookup[11] =
'jpx';
1232 $ImageTypesLookup[12] =
'jb2';
1233 $ImageTypesLookup[13] =
'swc';
1234 $ImageTypesLookup[14] =
'iff';
1236 return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] :
'');
1242 if (!empty($ThisFileInfo[
'tags'])) {
1243 foreach ($ThisFileInfo[
'tags'] as $tagtype => $tagarray) {
1244 foreach ($tagarray as $tagname => $tagdata) {
1245 foreach ($tagdata as
$key => $value) {
1246 if (!empty($value)) {
1247 if (empty($ThisFileInfo[
'comments'][$tagname])) {
1251 } elseif ($tagtype ==
'id3v1') {
1253 $newvaluelength = strlen(trim($value));
1254 foreach ($ThisFileInfo[
'comments'][$tagname] as $existingkey => $existingvalue) {
1255 $oldvaluelength = strlen(trim($existingvalue));
1256 if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
1262 } elseif (!is_array($value)) {
1264 $newvaluelength = strlen(trim($value));
1265 foreach ($ThisFileInfo[
'comments'][$tagname] as $existingkey => $existingvalue) {
1266 $oldvaluelength = strlen(trim($existingvalue));
1267 if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
1268 $ThisFileInfo[
'comments'][$tagname][$existingkey] = trim($value);
1275 if (is_array($value) || empty($ThisFileInfo[
'comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo[
'comments'][$tagname])) {
1276 $value = (is_string($value) ? trim($value) : $value);
1277 if (!is_int(
$key) && !ctype_digit(
$key)) {
1278 $ThisFileInfo[
'comments'][$tagname][
$key] = $value;
1280 if (isset($ThisFileInfo[
'comments'][$tagname])) {
1281 $ThisFileInfo[
'comments'][$tagname] =
array($value);
1283 $ThisFileInfo[
'comments'][$tagname][] = $value;
1293 $StandardizeFieldNames =
array(
1294 'tracknumber' =>
'track_number',
1295 'track' =>
'track_number',
1297 foreach ($StandardizeFieldNames as $badkey => $goodkey) {
1298 if (array_key_exists($badkey, $ThisFileInfo[
'comments']) && !array_key_exists($goodkey, $ThisFileInfo[
'comments'])) {
1299 $ThisFileInfo[
'comments'][$goodkey] = $ThisFileInfo[
'comments'][$badkey];
1300 unset($ThisFileInfo[
'comments'][$badkey]);
1305 if (!empty($ThisFileInfo[
'comments'])) {
1306 foreach ($ThisFileInfo[
'comments'] as $field => $values) {
1307 if ($field ==
'picture') {
1312 foreach ($values as
$index => $value) {
1313 if (is_array($value)) {
1314 $ThisFileInfo[
'comments_html'][$field][
$index] = $value;
1316 $ThisFileInfo[
'comments_html'][$field][
$index] = str_replace(
'�',
'', self::MultiByteCharString2HTML($value, $ThisFileInfo[
'encoding']));
1332 return (isset($cache[
$file][$name][
$key]) ? $cache[
$file][$name][$key] :
'');
1336 $keylength = strlen(
$key);
1337 $line_count =
$end - $begin - 7;
1340 $fp = fopen(
$file,
'r');
1343 for (
$i = 0;
$i < ($begin + 3);
$i++) {
1348 while (0 < $line_count--) {
1351 $line = ltrim(fgets($fp, 1024),
"\t ");
1362 $explodedLine = explode(
"\t", $line, 2);
1363 $ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] :
'');
1364 $ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] :
'');
1365 $cache[
$file][
$name][$ThisKey] = trim($ThisValue);
1370 return (isset($cache[
$file][$name][
$key]) ? $cache[
$file][$name][$key] :
'');
1374 global $GETID3_ERRORARRAY;
1380 $diemessage = basename($sourcefile).
' depends on '.
$filename.
', which has errors';
1383 $diemessage = basename($sourcefile).
' depends on '.
$filename.
', which is missing';
1385 if ($DieOnFailure) {
1388 $GETID3_ERRORARRAY[] = $diemessage;
1394 return trim($string,
"\x00");
1400 if (GETID3_OS_ISWINDOWS) {
1401 if (class_exists(
'COM')) {
1402 $filesystem =
new COM(
'Scripting.FileSystemObject');
1404 $filesize =
$file->Size();
1405 unset($filesystem,
$file);
1407 $commandline =
'for %I in ('.escapeshellarg(
$path).
') do @echo %~zI';
1410 $commandline =
'ls -l '.escapeshellarg(
$path).
' | awk \'{print $5}\'';
1412 if (isset($commandline)) {
1413 $output = trim(`$commandline`);
1429 $splited = preg_split(
'#/#', rtrim(
$path,
'/ '));
1430 return substr(basename(
'X'.$splited[count($splited) - 1], $suffix), 1);
static iconv_fallback_utf8_iso88591($string)
static iconv_fallback_iso88591_utf16le($string, $bom=false)
static iconv_fallback_utf8_utf16le($string, $bom=false)
static safe_inc(&$variable, $increment=1)
static CopyTagsToComments(&$ThisFileInfo)
static fileextension($filename, $numextensions=1)
static iconv_fallback_utf16_iso88591($string)
static ImageExtFromMime($mime_type)
static flipped_array_merge_noclobber($array1, $array2)
static EmbeddedLookup($key, $begin, $end, $file, $name)
static iconv_fallback_utf16be_utf8($string)
static DecimalizeFraction($fraction)
static RGADnameLookup($namecode)
static iconv_fallback_utf8_utf16be($string, $bom=false)
static CopyFileParts($filename_source, $filename_dest, $offset, $length)
static RGADoriginatorLookup($originatorcode)
static intValueSupported($num)
static Float2BinaryDecimal($floatvalue)
static iconv_fallback_utf8_utf16($string)
static iconv_fallback_utf16le_iso88591($string)
static Bin2Dec($binstring, $signed=false)
static iconv_fallback($in_charset, $out_charset, $string)
static Float2String($floatvalue, $bits)
static BigEndian2Bin($byteword)
static LittleEndian2Int($byteword, $signed=false)
static iconv_fallback_iso88591_utf16($string)
static NormalizeBinaryPoint($binarypointnumber, $maxbits=52)
static IncludeDependency($filename, $sourcefile, $DieOnFailure=false)
static ImageTypesLookup($imagetypeid)
static iconv_fallback_utf16_utf8($string)
static RGADamplitude2dB($amplitude)
static getFileSizeSyscall($path)
static iconv_fallback_utf16le_utf8($string)
static BigEndian2Float($byteword)
static RGADgainString($namecode, $originatorcode, $replaygain)
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
static RGADadjustmentLookup($rawadjustment, $signbit)
static XML2array($XMLstring)
static PlaytimeString($seconds)
static trunc($floatnumber)
static trimNullByte($string)
static DateMac2Unix($macdate)
static iconv_fallback_utf16be_iso88591($string)
static CastAsInt($floatnum)
static Bin2String($binstring)
static ksort_recursive(&$theArray)
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
static DecimalBinary2Float($binarynumerator)
static FixedPoint2_30($rawdata)
static GetDataImageSize($imgData, &$imageinfo=array())
static SimpleXMLelement2array($XMLobject)
Create styles array
The data for the language used.
static hash_data($file, $offset, $end, $algorithm)
static LittleEndian2Float($byteword)
static MultiByteCharString2HTML($string, $charset='ISO-8859-1')
static iconv_fallback_iso88591_utf16be($string, $bom=false)
static array_merge_clobber($array1, $array2)
static iconv_fallback_int_utf8($charval)
getID3() by James Heinrich info@getid3.org //
static recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1')
static FixedPoint8_8($rawdata)
static iconv_fallback_iso88591_utf8($string, $bom=false)
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
static LittleEndian2String($number, $minbytes=1, $synchsafe=false)
static mb_basename($path, $suffix=null)
Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268)
static BigEndian2Int($byteword, $synchsafe=false, $signed=false)
static array_max($arraydata, $returnkey=false)
static array_min($arraydata, $returnkey=false)
static CreateDeepArray($ArrayPath, $Separator, $Value)
static FixedPoint16_16($rawdata)
static array_merge_noclobber($array1, $array2)
static BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false)