17 function PrintHexBytes($string, $hex=
true, $spaces=
true, $htmlsafe=
true) {
19 for ($i = 0; $i < strlen($string); $i++) {
21 $returnstring .= str_pad(dechex(ord($string{$i})), 2,
'0', STR_PAD_LEFT);
23 $returnstring .=
' '.(ereg(
"[\x20-\x7E]", $string{$i}) ? $string{$i} :
'¤');
30 $returnstring = htmlentities($returnstring);
36 if (get_magic_quotes_gpc()) {
37 return stripslashes($text);
46 if ($floatnumber >= 1) {
47 $truncatednumber = floor($floatnumber);
48 } elseif ($floatnumber <= -1) {
49 $truncatednumber = ceil($floatnumber);
53 if ($truncatednumber <= 1073741824) {
54 $truncatednumber = (int) $truncatednumber;
56 return $truncatednumber;
62 $floatnum = (float) $floatnum;
67 if ($floatnum <= 1073741824) {
69 $floatnum = (int) $floatnum;
79 return ($numerator / $denominator);
85 if (strpos($binarypointnumber,
'.') ===
false) {
86 $binarypointnumber =
'0.'.$binarypointnumber;
87 } elseif ($binarypointnumber{0} ==
'.') {
88 $binarypointnumber =
'0'.$binarypointnumber;
91 while (($binarypointnumber{0} !=
'1') || (substr($binarypointnumber, 1, 1) !=
'.')) {
92 if (substr($binarypointnumber, 1, 1) ==
'.') {
94 $binarypointnumber = substr($binarypointnumber, 2, 1).
'.'.substr($binarypointnumber, 3);
96 $pointpos = strpos($binarypointnumber,
'.');
97 $exponent += ($pointpos - 1);
98 $binarypointnumber = str_replace(
'.',
'', $binarypointnumber);
99 $binarypointnumber = $binarypointnumber{0}.
'.'.substr($binarypointnumber, 1);
102 $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2,
'0', STR_PAD_RIGHT);
103 return array(
'normalized'=>$binarypointnumber,
'exponent'=>(
int) $exponent);
111 $floatpart = abs($floatvalue - $intpart);
112 $pointbitstring =
'';
113 while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) {
118 $binarypointnumber = decbin($intpart).
'.'.$pointbitstring;
119 return $binarypointnumber;
140 if ($floatvalue >= 0) {
146 $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary[
'exponent'];
147 $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits,
'0', STR_PAD_LEFT);
148 $fractionbitstring = str_pad(substr($normalizedbinary[
'normalized'], 2), $fractionbits,
'0', STR_PAD_RIGHT);
165 $signbit = $bitword{0};
167 switch (strlen($byteword) * 8) {
181 $exponentstring = substr($bitword, 1, 15);
182 $isnormalized = intval($bitword{16});
183 $fractionstring = substr($bitword, 17, 63);
186 $floatvalue = $exponent * $fraction;
187 if ($signbit ==
'1') {
197 $exponentstring = substr($bitword, 1, $exponentbits);
198 $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
202 if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) {
205 } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) {
206 if ($signbit ==
'1') {
207 $floatvalue =
'-infinity';
209 $floatvalue =
'+infinity';
211 } elseif (($exponent == 0) && ($fraction == 0)) {
212 if ($signbit ==
'1') {
217 $floatvalue = ($signbit ? 0 : -0);
218 } elseif (($exponent == 0) && ($fraction != 0)) {
221 if ($signbit ==
'1') {
224 } elseif ($exponent != 0) {
226 if ($signbit ==
'1') {
230 return (
float) $floatvalue;
236 $bytewordlen = strlen($byteword);
237 for ($i = 0; $i < $bytewordlen; $i++) {
239 $intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7);
241 $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
244 if ($signed && !$synchsafe) {
246 switch ($bytewordlen) {
251 $signmaskbit = 0x80 << (8 * ($bytewordlen - 1));
252 if ($intvalue & $signmaskbit) {
253 $intvalue = 0 - ($intvalue & ($signmaskbit - 1));
258 die(
'ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2Int()');
273 $bytewordlen = strlen($byteword);
274 for ($i = 0; $i < $bytewordlen; $i++) {
275 $binvalue .= str_pad(decbin(ord($byteword{$i})), 8,
'0', STR_PAD_LEFT);
285 $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
289 die(
'ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2String()');
291 $number = $number & (0x80 << (8 * ($minbytes - 1)));
293 while ($number != 0) {
294 $quotient = ($number / ($maskbyte + 1));
295 $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring;
296 $number = floor($quotient);
298 return str_pad($intstring, $minbytes,
"\x00", STR_PAD_LEFT);
303 while ($number >= 256) {
304 $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
305 $number = floor($number / 256);
309 for ($i = 0; $i < count($bytes); $i++) {
310 $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8,
'0', STR_PAD_LEFT)).$binstring;
319 if ($binstring{0} ==
'1') {
322 $binstring = substr($binstring, 1);
325 for ($i = 0; $i < strlen($binstring); $i++) {
326 $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
335 $binstringreversed = strrev($binstring);
336 for ($i = 0; $i < strlen($binstringreversed); $i += 8) {
345 while ($number > 0) {
347 $intstring = $intstring.chr($number & 127);
350 $intstring = $intstring.chr($number & 255);
354 return str_pad($intstring, $minbytes,
"\x00", STR_PAD_RIGHT);
361 if (!is_array($array1) || !is_array($array2)) {
365 foreach ($array2 as $key => $val) {
366 if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
369 $newarray[$key] = $val;
377 if (!is_array($array1) || !is_array($array2)) {
381 foreach ($array2 as $key => $val) {
382 if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
384 } elseif (!isset($newarray[$key])) {
385 $newarray[$key] = $val;
396 for ($i = 0; $i < $numextensions; $i++) {
397 $offset = strpos($reversedfilename,
'.', $offset + 1);
398 if ($offset ===
false) {
402 return strrev(substr($reversedfilename, 0, $offset));
409 $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60);
410 $contentminutes = floor($playtimeseconds / 60);
411 if ($contentseconds >= 60) {
412 $contentseconds -= 60;
415 return intval($contentminutes).
':'.str_pad($contentseconds, 2, 0, STR_PAD_LEFT);
421 static $image_type_to_mime_type = array();
422 if (empty($image_type_to_mime_type)) {
423 $image_type_to_mime_type[1] =
'image/gif';
424 $image_type_to_mime_type[2] =
'image/jpeg';
425 $image_type_to_mime_type[3] =
'image/png';
426 $image_type_to_mime_type[4] =
'application/x-shockwave-flash';
427 $image_type_to_mime_type[5] =
'image/psd';
428 $image_type_to_mime_type[6] =
'image/bmp';
429 $image_type_to_mime_type[7] =
'image/tiff';
430 $image_type_to_mime_type[8] =
'image/tiff';
435 $image_type_to_mime_type[13] =
'application/x-shockwave-flash';
436 $image_type_to_mime_type[14] =
'image/iff';
438 return (isset($image_type_to_mime_type[$imagetypeid]) ? $image_type_to_mime_type[$imagetypeid] :
'application/octet-stream');
472 while ($ArrayPath && ($ArrayPath{0} == $Separator)) {
473 $ArrayPath = substr($ArrayPath, 1);
475 if ((
$pos = strpos($ArrayPath, $Separator)) !==
false) {
478 $ReturnedArray[$ArrayPath] = $Value;
480 return $ReturnedArray;
486 foreach ($arraydata as $key => $value) {
487 if (!is_array($value)) {
488 if ($value > $maxvalue) {
494 return ($returnkey ? $maxkey : $maxvalue);
500 foreach ($arraydata as $key => $value) {
501 if (!is_array($value)) {
502 if ($value > $minvalue) {
508 return ($returnkey ? $minkey : $minvalue);
515 if (function_exists(
'md5_file')) {
519 if (GETID3_OS_ISWINDOWS) {
521 $RequiredFiles = array(
'cygwin1.dll',
'md5sum.exe');
522 foreach ($RequiredFiles as $required_file) {
523 if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
524 die(implode(
' and ', $RequiredFiles).
' are required in '.GETID3_HELPERAPPSDIR.
' for getid3_lib::md5_file() to function under Windows in PHP < v4.2.0');
527 $commandline = GETID3_HELPERAPPSDIR.
'md5sum.exe "'.str_replace(
'/', DIRECTORY_SEPARATOR,
$file).
'"';
528 if (ereg(
"^[\\]?([0-9a-f]{32})", strtolower(`$commandline`), $r)) {
536 if (ereg(
"^([0-9a-f]{32})[ \t\n\r]", `md5sum
"$file"`, $r)) {
548 if (function_exists(
'sha1_file')) {
554 if (GETID3_OS_ISWINDOWS) {
556 $RequiredFiles = array(
'cygwin1.dll',
'sha1sum.exe');
557 foreach ($RequiredFiles as $required_file) {
558 if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
559 die(implode(
' and ', $RequiredFiles).
' are required in '.GETID3_HELPERAPPSDIR.
' for getid3_lib::sha1_file() to function under Windows in PHP < v4.3.0');
562 $commandline = GETID3_HELPERAPPSDIR.
'sha1sum.exe "'.str_replace(
'/', DIRECTORY_SEPARATOR,
$file).
'"';
563 if (ereg(
"^sha1=([0-9a-f]{40})", strtolower(`$commandline`), $r)) {
569 $commandline =
'sha1sum '.escapeshellarg(
$file).
'';
570 if (ereg(
"^([0-9a-f]{40})[ \t\n\r]", strtolower(`$commandline`), $r)) {
584 switch ($algorithm) {
586 $hash_function =
'md5_file';
587 $unix_call =
'md5sum';
588 $windows_call =
'md5sum.exe';
593 $hash_function =
'sha1_file';
594 $unix_call =
'sha1sum';
595 $windows_call =
'sha1sum.exe';
600 die(
'Invalid algorithm ('.$algorithm.
') in getid3_lib::hash_data()');
603 $size = $end - $offset;
605 if (GETID3_OS_ISWINDOWS) {
609 if ($algorithm ==
'sha1') {
613 $RequiredFiles = array(
'cygwin1.dll',
'head.exe',
'tail.exe', $windows_call);
614 foreach ($RequiredFiles as $required_file) {
615 if (!is_readable(GETID3_HELPERAPPSDIR.$required_file)) {
620 $commandline = GETID3_HELPERAPPSDIR.
'head.exe -c '.$end.
' "'.escapeshellarg(str_replace(
'/', DIRECTORY_SEPARATOR,
$file)).
'" | ';
621 $commandline .= GETID3_HELPERAPPSDIR.
'tail.exe -c '.$size.
' | ';
622 $commandline .= GETID3_HELPERAPPSDIR.$windows_call;
626 $commandline =
'head -c'.$end.
' '.escapeshellarg(
$file).
' | ';
627 $commandline .=
'tail -c'.$size.
' | ';
628 $commandline .= $unix_call;
631 if ((
bool) ini_get(
'safe_mode')) {
632 $ThisFileInfo[
'warning'][] =
'PHP running in Safe Mode - backtick operator not available, using slower non-system-call '.$algorithm.
' algorithm';
635 return substr(`$commandline`, 0, $hash_length);
639 if (($data_filename = tempnam(
'*',
'getID3')) ===
false) {
648 if ($fp = @fopen(
$file,
'rb')) {
650 if ($fp_data = @fopen($data_filename,
'wb')) {
652 fseek($fp, $offset, SEEK_SET);
653 $byteslefttowrite = $end - $offset;
655 $byteswritten = fwrite($fp_data, $buffer, $byteslefttowrite);
656 $byteslefttowrite -= $byteswritten;
659 $result = getid3_lib::$hash_function($data_filename);
664 unlink($data_filename);
670 if ($charval < 128) {
672 $newcharstring = chr($charval);
673 } elseif ($charval < 2048) {
675 $newcharstring = chr(($charval >> 6) | 0xC0);
676 $newcharstring .= chr(($charval & 0x3F) | 0x80);
677 } elseif ($charval < 65536) {
679 $newcharstring = chr(($charval >> 12) | 0xE0);
680 $newcharstring .= chr(($charval >> 6) | 0xC0);
681 $newcharstring .= chr(($charval & 0x3F) | 0x80);
684 $newcharstring = chr(($charval >> 18) | 0xF0);
685 $newcharstring .= chr(($charval >> 12) | 0xC0);
686 $newcharstring .= chr(($charval >> 6) | 0xC0);
687 $newcharstring .= chr(($charval & 0x3F) | 0x80);
689 return $newcharstring;
694 if (function_exists(
'utf8_encode')) {
695 return utf8_encode($string);
700 $newcharstring .=
"\xEF\xBB\xBF";
702 for ($i = 0; $i < strlen($string); $i++) {
703 $charval = ord($string{$i});
706 return $newcharstring;
713 $newcharstring .=
"\xFE\xFF";
715 for ($i = 0; $i < strlen($string); $i++) {
716 $newcharstring .=
"\x00".$string{$i};
718 return $newcharstring;
725 $newcharstring .=
"\xFF\xFE";
727 for ($i = 0; $i < strlen($string); $i++) {
728 $newcharstring .= $string{$i}.
"\x00";
730 return $newcharstring;
740 if (function_exists(
'utf8_decode')) {
741 return utf8_decode($string);
746 $stringlength = strlen($string);
747 while ($offset < $stringlength) {
748 if ((ord($string{$offset}) | 0x07) == 0xF7) {
750 $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
751 ((ord($string{($offset + 1)}) & 0x3F) << 12) &
752 ((ord($string{($offset + 2)}) & 0x3F) << 6) &
753 (ord($string{($offset + 3)}) & 0x3F);
755 } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
757 $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
758 ((ord($string{($offset + 1)}) & 0x3F) << 6) &
759 (ord($string{($offset + 2)}) & 0x3F);
761 } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
763 $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
764 (ord($string{($offset + 1)}) & 0x3F);
766 } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
768 $charval = ord($string{$offset});
775 if ($charval !==
false) {
776 $newcharstring .= (($charval < 256) ? chr($charval) :
'?');
779 return $newcharstring;
786 $newcharstring .=
"\xFE\xFF";
789 $stringlength = strlen($string);
790 while ($offset < $stringlength) {
791 if ((ord($string{$offset}) | 0x07) == 0xF7) {
793 $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
794 ((ord($string{($offset + 1)}) & 0x3F) << 12) &
795 ((ord($string{($offset + 2)}) & 0x3F) << 6) &
796 (ord($string{($offset + 3)}) & 0x3F);
798 } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
800 $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
801 ((ord($string{($offset + 1)}) & 0x3F) << 6) &
802 (ord($string{($offset + 2)}) & 0x3F);
804 } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
806 $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
807 (ord($string{($offset + 1)}) & 0x3F);
809 } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
811 $charval = ord($string{$offset});
818 if ($charval !==
false) {
822 return $newcharstring;
829 $newcharstring .=
"\xFF\xFE";
832 $stringlength = strlen($string);
833 while ($offset < $stringlength) {
834 if ((ord($string{$offset}) | 0x07) == 0xF7) {
836 $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
837 ((ord($string{($offset + 1)}) & 0x3F) << 12) &
838 ((ord($string{($offset + 2)}) & 0x3F) << 6) &
839 (ord($string{($offset + 3)}) & 0x3F);
841 } elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
843 $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
844 ((ord($string{($offset + 1)}) & 0x3F) << 6) &
845 (ord($string{($offset + 2)}) & 0x3F);
847 } elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
849 $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
850 (ord($string{($offset + 1)}) & 0x3F);
852 } elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
854 $charval = ord($string{$offset});
861 if ($charval !==
false) {
865 return $newcharstring;
875 if (substr($string, 0, 2) ==
"\xFE\xFF") {
877 $string = substr($string, 2);
880 for ($i = 0; $i < strlen($string); $i += 2) {
884 return $newcharstring;
889 if (substr($string, 0, 2) ==
"\xFF\xFE") {
891 $string = substr($string, 2);
894 for ($i = 0; $i < strlen($string); $i += 2) {
898 return $newcharstring;
903 if (substr($string, 0, 2) ==
"\xFE\xFF") {
905 $string = substr($string, 2);
908 for ($i = 0; $i < strlen($string); $i += 2) {
910 $newcharstring .= (($charval < 256) ? chr($charval) :
'?');
912 return $newcharstring;
917 if (substr($string, 0, 2) ==
"\xFF\xFE") {
919 $string = substr($string, 2);
922 for ($i = 0; $i < strlen($string); $i += 2) {
924 $newcharstring .= (($charval < 256) ? chr($charval) :
'?');
926 return $newcharstring;
931 $bom = substr($string, 0, 2);
932 if ($bom ==
"\xFE\xFF") {
934 } elseif ($bom ==
"\xFF\xFE") {
942 $bom = substr($string, 0, 2);
943 if ($bom ==
"\xFE\xFF") {
945 } elseif ($bom ==
"\xFF\xFE") {
953 if ($in_charset == $out_charset) {
957 static $iconv_broken_or_unavailable = array();
958 if (is_null(@$iconv_broken_or_unavailable[$in_charset.
'_'.$out_charset])) {
959 $GETID3_ICONV_TEST_STRING =
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚„…†‡‰Š‹ŚŤŽŹ‘’“”•–—™š›śťžź ˇ˘Ł¤Ą¦§¨©Ş«¬®Ż°±˛ł´µ¶·¸ąş»Ľ˝ľżŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎĐŃŇÓÔŐÖ×ŘŮÚŰÜÝŢßŕáâăäĺćçčéęëěíîďđńňóôőö÷řůúűüýţ˙';
962 if (function_exists(
'iconv')) {
963 if (@iconv($in_charset,
'ISO-8859-1', @iconv(
'ISO-8859-1', $in_charset, $GETID3_ICONV_TEST_STRING)) == $GETID3_ICONV_TEST_STRING) {
964 if (@iconv($out_charset,
'ISO-8859-1', @iconv(
'ISO-8859-1', $out_charset, $GETID3_ICONV_TEST_STRING)) == $GETID3_ICONV_TEST_STRING) {
966 $iconv_broken_or_unavailable[$in_charset.
'_'.$out_charset] =
false;
970 $iconv_broken_or_unavailable[$in_charset.
'_'.$out_charset] =
true;
975 $iconv_broken_or_unavailable[$in_charset.
'_'.$out_charset] =
true;
979 $iconv_broken_or_unavailable[$in_charset.
'_'.$out_charset] =
true;
983 if ($iconv_broken_or_unavailable[$in_charset.
'_'.$out_charset]) {
984 static $ConversionFunctionList = array();
985 if (empty($ConversionFunctionList)) {
986 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-8'] =
'iconv_fallback_iso88591_utf8';
987 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-16'] =
'iconv_fallback_iso88591_utf16';
988 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-16BE'] =
'iconv_fallback_iso88591_utf16be';
989 $ConversionFunctionList[
'ISO-8859-1'][
'UTF-16LE'] =
'iconv_fallback_iso88591_utf16le';
990 $ConversionFunctionList[
'UTF-8'][
'ISO-8859-1'] =
'iconv_fallback_utf8_iso88591';
991 $ConversionFunctionList[
'UTF-8'][
'UTF-16'] =
'iconv_fallback_utf8_utf16';
992 $ConversionFunctionList[
'UTF-8'][
'UTF-16BE'] =
'iconv_fallback_utf8_utf16be';
993 $ConversionFunctionList[
'UTF-8'][
'UTF-16LE'] =
'iconv_fallback_utf8_utf16le';
994 $ConversionFunctionList[
'UTF-16'][
'ISO-8859-1'] =
'iconv_fallback_utf16_iso88591';
995 $ConversionFunctionList[
'UTF-16'][
'UTF-8'] =
'iconv_fallback_utf16_utf8';
996 $ConversionFunctionList[
'UTF-16LE'][
'ISO-8859-1'] =
'iconv_fallback_utf16le_iso88591';
997 $ConversionFunctionList[
'UTF-16LE'][
'UTF-8'] =
'iconv_fallback_utf16le_utf8';
998 $ConversionFunctionList[
'UTF-16BE'][
'ISO-8859-1'] =
'iconv_fallback_utf16be_iso88591';
999 $ConversionFunctionList[
'UTF-16BE'][
'UTF-8'] =
'iconv_fallback_utf16be_utf8';
1001 if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) {
1002 $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
1003 return getid3_lib::$ConversionFunction($string);
1005 die(
'PHP does not have iconv() support - cannot convert from '.$in_charset.
' to '.$out_charset);
1008 if ($converted_string = @iconv($in_charset, $out_charset.
'//TRANSLIT', $string)) {
1009 switch ($out_charset) {
1011 $converted_string = rtrim($converted_string,
"\x00");
1014 return $converted_string;
1035 case 'Windows-1251':
1039 case 'Windows-1252':
1054 $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
1058 $strlen = strlen($string);
1059 for ($i = 0; $i < $strlen; $i++) {
1060 $char_ord_val = ord($string{$i});
1062 if ($char_ord_val < 0x80) {
1063 $charval = $char_ord_val;
1064 } elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F) {
1065 $charval = (($char_ord_val & 0x07) << 18);
1066 $charval += ((ord($string{++$i}) & 0x3F) << 12);
1067 $charval += ((ord($string{++$i}) & 0x3F) << 6);
1068 $charval += (ord($string{++$i}) & 0x3F);
1069 } elseif ((($char_ord_val & 0xE0) >> 5) == 0x07) {
1070 $charval = (($char_ord_val & 0x0F) << 12);
1071 $charval += ((ord($string{++$i}) & 0x3F) << 6);
1072 $charval += (ord($string{++$i}) & 0x3F);
1073 } elseif ((($char_ord_val & 0xC0) >> 6) == 0x03) {
1074 $charval = (($char_ord_val & 0x1F) << 6);
1075 $charval += (ord($string{++$i}) & 0x3F);
1077 if (($charval >= 32) && ($charval <= 127)) {
1078 $HTMLstring .= chr($charval);
1080 $HTMLstring .=
'&#'.$charval.
';';
1086 for ($i = 0; $i < strlen($string); $i += 2) {
1088 if (($charval >= 32) && ($charval <= 127)) {
1089 $HTMLstring .= chr($charval);
1091 $HTMLstring .=
'&#'.$charval.
';';
1097 for ($i = 0; $i < strlen($string); $i += 2) {
1099 if (($charval >= 32) && ($charval <= 127)) {
1100 $HTMLstring .= chr($charval);
1102 $HTMLstring .=
'&#'.$charval.
';';
1108 $HTMLstring =
'ERROR: Character set "'.$charset.
'" not supported in MultiByteCharString2HTML()';
1117 static $RGADname = array();
1118 if (empty($RGADname)) {
1119 $RGADname[0] =
'not set';
1120 $RGADname[1] =
'Track Gain Adjustment';
1121 $RGADname[2] =
'Album Gain Adjustment';
1124 return (isset($RGADname[$namecode]) ? $RGADname[$namecode] :
'');
1129 static $RGADoriginator = array();
1130 if (empty($RGADoriginator)) {
1131 $RGADoriginator[0] =
'unspecified';
1132 $RGADoriginator[1] =
'pre-set by artist/producer/mastering engineer';
1133 $RGADoriginator[2] =
'set by user';
1134 $RGADoriginator[3] =
'determined automatically';
1137 return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] :
'');
1142 $adjustment = $rawadjustment / 10;
1143 if ($signbit == 1) {
1146 return (
float) $adjustment;
1151 if ($replaygain < 0) {
1156 $storedreplaygain = intval(round($replaygain * 10));
1157 $gainstring = str_pad(decbin($namecode), 3,
'0', STR_PAD_LEFT);
1158 $gainstring .= str_pad(decbin($originatorcode), 3,
'0', STR_PAD_LEFT);
1159 $gainstring .= $signbit;
1160 $gainstring .= str_pad(decbin($storedreplaygain), 9,
'0', STR_PAD_LEFT);
1166 return 20 * log10($amplitude);
1171 $GetDataImageSize =
false;
1172 if ($tempfilename = tempnam(
'*',
'getID3')) {
1173 if ($tmp = @fopen($tempfilename,
'wb')) {
1174 fwrite($tmp, $imgData);
1176 $GetDataImageSize = @GetImageSize($tempfilename);
1178 unlink($tempfilename);
1180 return $GetDataImageSize;
1184 static $ImageTypesLookup = array();
1185 if (empty($ImageTypesLookup)) {
1186 $ImageTypesLookup[1] =
'gif';
1187 $ImageTypesLookup[2] =
'jpeg';
1188 $ImageTypesLookup[3] =
'png';
1189 $ImageTypesLookup[4] =
'swf';
1190 $ImageTypesLookup[5] =
'psd';
1191 $ImageTypesLookup[6] =
'bmp';
1192 $ImageTypesLookup[7] =
'tiff (little-endian)';
1193 $ImageTypesLookup[8] =
'tiff (big-endian)';
1194 $ImageTypesLookup[9] =
'jpc';
1195 $ImageTypesLookup[10] =
'jp2';
1196 $ImageTypesLookup[11] =
'jpx';
1197 $ImageTypesLookup[12] =
'jb2';
1198 $ImageTypesLookup[13] =
'swc';
1199 $ImageTypesLookup[14] =
'iff';
1201 return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] :
'');
1207 if (!empty($ThisFileInfo[
'tags'])) {
1208 foreach ($ThisFileInfo[
'tags'] as $tagtype => $tagarray) {
1209 foreach ($tagarray as $tagname => $tagdata) {
1210 foreach ($tagdata as $key => $value) {
1211 if (!empty($value)) {
1212 if (empty($ThisFileInfo[
'comments'][$tagname])) {
1216 } elseif ($tagtype ==
'id3v1') {
1218 $newvaluelength = strlen(trim($value));
1219 foreach ($ThisFileInfo[
'comments'][$tagname] as $existingkey => $existingvalue) {
1220 $oldvaluelength = strlen(trim($existingvalue));
1221 if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
1229 $newvaluelength = strlen(trim($value));
1230 foreach ($ThisFileInfo[
'comments'][$tagname] as $existingkey => $existingvalue) {
1231 $oldvaluelength = strlen(trim($existingvalue));
1232 if (($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
1233 $ThisFileInfo[
'comments'][$tagname][$existingkey] = trim($value);
1239 if (empty($ThisFileInfo[
'comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo[
'comments'][$tagname])) {
1240 $ThisFileInfo[
'comments'][$tagname][] = trim($value);
1248 foreach ($ThisFileInfo[
'comments'] as $field => $values) {
1249 foreach ($values as $index => $value) {
1266 $keylength = strlen($key);
1267 $line_count = $end - $begin - 7;
1270 $fp = fopen(
$file,
'r');
1273 for ($i = 0; $i < ($begin + 3); $i++) {
1278 while (0 < $line_count--) {
1281 $line = ltrim(fgets($fp, 1024),
"\t ");
1292 @list($ThisKey, $ThisValue) = explode(
"\t", $line, 2);
1293 $cache[
$file][
$name][$ThisKey] = trim($ThisValue);
1302 global $GETID3_ERRORARRAY;
1308 $diemessage = basename($sourcefile).
' depends on '.
$filename.
', which has errors';
1311 $diemessage = basename($sourcefile).
' depends on '.
$filename.
', which is missing';
1313 if ($DieOnFailure) {
1316 $GETID3_ERRORARRAY[] = $diemessage;