PageRenderTime 64ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/common/libraries/plugin/getid3/getid3.lib.php

https://bitbucket.org/renaatdemuynck/chamilo
PHP | 1567 lines | 1313 code | 137 blank | 117 comment | 218 complexity | 465001bf220e89e981d0a5ec934db490 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at http://getid3.sourceforge.net //
  5. // or http://www.getid3.org //
  6. /////////////////////////////////////////////////////////////////
  7. // //
  8. // getid3.lib.php - part of getID3() //
  9. // See readme.txt for more details //
  10. // ///
  11. /////////////////////////////////////////////////////////////////
  12. class getid3_lib
  13. {
  14. function PrintHexBytes($string, $hex = true, $spaces = true, $htmlsafe = true)
  15. {
  16. $returnstring = '';
  17. for($i = 0; $i < strlen($string); $i ++)
  18. {
  19. if ($hex)
  20. {
  21. $returnstring .= str_pad(dechex(ord($string{$i})), 2, '0', STR_PAD_LEFT);
  22. }
  23. else
  24. {
  25. $returnstring .= ' ' . (ereg("[\x20-\x7E]", $string{$i}) ? $string{$i} : '�');
  26. }
  27. if ($spaces)
  28. {
  29. $returnstring .= ' ';
  30. }
  31. }
  32. if ($htmlsafe)
  33. {
  34. $returnstring = htmlentities($returnstring);
  35. }
  36. return $returnstring;
  37. }
  38. function SafeStripSlashes($text)
  39. {
  40. if (get_magic_quotes_gpc())
  41. {
  42. return stripslashes($text);
  43. }
  44. return $text;
  45. }
  46. function trunc($floatnumber)
  47. {
  48. // truncates a floating-point number at the decimal point
  49. // returns int (if possible, otherwise float)
  50. if ($floatnumber >= 1)
  51. {
  52. $truncatednumber = floor($floatnumber);
  53. }
  54. elseif ($floatnumber <= - 1)
  55. {
  56. $truncatednumber = ceil($floatnumber);
  57. }
  58. else
  59. {
  60. $truncatednumber = 0;
  61. }
  62. if ($truncatednumber <= 1073741824)
  63. { // 2^30
  64. $truncatednumber = (int) $truncatednumber;
  65. }
  66. return $truncatednumber;
  67. }
  68. function CastAsInt($floatnum)
  69. {
  70. // convert to float if not already
  71. $floatnum = (float) $floatnum;
  72. // convert a float to type int, only if possible
  73. if (getid3_lib :: trunc($floatnum) == $floatnum)
  74. {
  75. // it's not floating point
  76. if ($floatnum <= 2147483647)
  77. { // 2^31
  78. // it's within int range
  79. $floatnum = (int) $floatnum;
  80. }
  81. }
  82. return $floatnum;
  83. }
  84. function DecimalBinary2Float($binarynumerator)
  85. {
  86. $numerator = getid3_lib :: Bin2Dec($binarynumerator);
  87. $denominator = getid3_lib :: Bin2Dec('1' . str_repeat('0', strlen($binarynumerator)));
  88. return ($numerator / $denominator);
  89. }
  90. function NormalizeBinaryPoint($binarypointnumber, $maxbits = 52)
  91. {
  92. // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
  93. if (strpos($binarypointnumber, '.') === false)
  94. {
  95. $binarypointnumber = '0.' . $binarypointnumber;
  96. }
  97. elseif ($binarypointnumber{0} == '.')
  98. {
  99. $binarypointnumber = '0' . $binarypointnumber;
  100. }
  101. $exponent = 0;
  102. while (($binarypointnumber{0} != '1') || (substr($binarypointnumber, 1, 1) != '.'))
  103. {
  104. if (substr($binarypointnumber, 1, 1) == '.')
  105. {
  106. $exponent --;
  107. $binarypointnumber = substr($binarypointnumber, 2, 1) . '.' . substr($binarypointnumber, 3);
  108. }
  109. else
  110. {
  111. $pointpos = strpos($binarypointnumber, '.');
  112. $exponent += ($pointpos - 1);
  113. $binarypointnumber = str_replace('.', '', $binarypointnumber);
  114. $binarypointnumber = $binarypointnumber{0} . '.' . substr($binarypointnumber, 1);
  115. }
  116. }
  117. $binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT);
  118. return array('normalized' => $binarypointnumber, 'exponent' => (int) $exponent);
  119. }
  120. function Float2BinaryDecimal($floatvalue)
  121. {
  122. // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
  123. $maxbits = 128; // to how many bits of precision should the calculations be taken?
  124. $intpart = getid3_lib :: trunc($floatvalue);
  125. $floatpart = abs($floatvalue - $intpart);
  126. $pointbitstring = '';
  127. while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits))
  128. {
  129. $floatpart *= 2;
  130. $pointbitstring .= (string) getid3_lib :: trunc($floatpart);
  131. $floatpart -= getid3_lib :: trunc($floatpart);
  132. }
  133. $binarypointnumber = decbin($intpart) . '.' . $pointbitstring;
  134. return $binarypointnumber;
  135. }
  136. function Float2String($floatvalue, $bits)
  137. {
  138. // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
  139. switch ($bits)
  140. {
  141. case 32 :
  142. $exponentbits = 8;
  143. $fractionbits = 23;
  144. break;
  145. case 64 :
  146. $exponentbits = 11;
  147. $fractionbits = 52;
  148. break;
  149. default :
  150. return false;
  151. break;
  152. }
  153. if ($floatvalue >= 0)
  154. {
  155. $signbit = '0';
  156. }
  157. else
  158. {
  159. $signbit = '1';
  160. }
  161. $normalizedbinary = getid3_lib :: NormalizeBinaryPoint(getid3_lib :: Float2BinaryDecimal($floatvalue), $fractionbits);
  162. $biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent
  163. $exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT);
  164. $fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT);
  165. return getid3_lib :: BigEndian2String(getid3_lib :: Bin2Dec($signbit . $exponentbitstring . $fractionbitstring), $bits % 8, false);
  166. }
  167. function LittleEndian2Float($byteword)
  168. {
  169. return getid3_lib :: BigEndian2Float(strrev($byteword));
  170. }
  171. function BigEndian2Float($byteword)
  172. {
  173. // ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
  174. // http://www.psc.edu/general/software/packages/ieee/ieee.html
  175. // http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
  176. $bitword = getid3_lib :: BigEndian2Bin($byteword);
  177. if (! $bitword)
  178. {
  179. return 0;
  180. }
  181. $signbit = $bitword{0};
  182. switch (strlen($byteword) * 8)
  183. {
  184. case 32 :
  185. $exponentbits = 8;
  186. $fractionbits = 23;
  187. break;
  188. case 64 :
  189. $exponentbits = 11;
  190. $fractionbits = 52;
  191. break;
  192. case 80 :
  193. // 80-bit Apple SANE format
  194. // http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
  195. $exponentstring = substr($bitword, 1, 15);
  196. $isnormalized = intval($bitword{16});
  197. $fractionstring = substr($bitword, 17, 63);
  198. $exponent = pow(2, getid3_lib :: Bin2Dec($exponentstring) - 16383);
  199. $fraction = $isnormalized + getid3_lib :: DecimalBinary2Float($fractionstring);
  200. $floatvalue = $exponent * $fraction;
  201. if ($signbit == '1')
  202. {
  203. $floatvalue *= - 1;
  204. }
  205. return $floatvalue;
  206. break;
  207. default :
  208. return false;
  209. break;
  210. }
  211. $exponentstring = substr($bitword, 1, $exponentbits);
  212. $fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
  213. $exponent = getid3_lib :: Bin2Dec($exponentstring);
  214. $fraction = getid3_lib :: Bin2Dec($fractionstring);
  215. if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0))
  216. {
  217. // Not a Number
  218. $floatvalue = false;
  219. }
  220. elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0))
  221. {
  222. if ($signbit == '1')
  223. {
  224. $floatvalue = '-infinity';
  225. }
  226. else
  227. {
  228. $floatvalue = '+infinity';
  229. }
  230. }
  231. elseif (($exponent == 0) && ($fraction == 0))
  232. {
  233. if ($signbit == '1')
  234. {
  235. $floatvalue = - 0;
  236. }
  237. else
  238. {
  239. $floatvalue = 0;
  240. }
  241. $floatvalue = ($signbit ? 0 : - 0);
  242. }
  243. elseif (($exponent == 0) && ($fraction != 0))
  244. {
  245. // These are 'unnormalized' values
  246. $floatvalue = pow(2, (- 1 * (pow(2, $exponentbits - 1) - 2))) * getid3_lib :: DecimalBinary2Float($fractionstring);
  247. if ($signbit == '1')
  248. {
  249. $floatvalue *= - 1;
  250. }
  251. }
  252. elseif ($exponent != 0)
  253. {
  254. $floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + getid3_lib :: DecimalBinary2Float($fractionstring));
  255. if ($signbit == '1')
  256. {
  257. $floatvalue *= - 1;
  258. }
  259. }
  260. return (float) $floatvalue;
  261. }
  262. function BigEndian2Int($byteword, $synchsafe = false, $signed = false)
  263. {
  264. $intvalue = 0;
  265. $bytewordlen = strlen($byteword);
  266. for($i = 0; $i < $bytewordlen; $i ++)
  267. {
  268. if ($synchsafe)
  269. { // disregard MSB, effectively 7-bit bytes
  270. $intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7);
  271. }
  272. else
  273. {
  274. $intvalue += ord($byteword{$i}) * pow(256, ($bytewordlen - 1 - $i));
  275. }
  276. }
  277. if ($signed && ! $synchsafe)
  278. {
  279. // synchsafe ints are not allowed to be signed
  280. switch ($bytewordlen)
  281. {
  282. case 1 :
  283. case 2 :
  284. case 3 :
  285. case 4 :
  286. $signmaskbit = 0x80 << (8 * ($bytewordlen - 1));
  287. if ($intvalue & $signmaskbit)
  288. {
  289. $intvalue = 0 - ($intvalue & ($signmaskbit - 1));
  290. }
  291. break;
  292. default :
  293. die('ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2Int()');
  294. break;
  295. }
  296. }
  297. return getid3_lib :: CastAsInt($intvalue);
  298. }
  299. function LittleEndian2Int($byteword, $signed = false)
  300. {
  301. return getid3_lib :: BigEndian2Int(strrev($byteword), false, $signed);
  302. }
  303. function BigEndian2Bin($byteword)
  304. {
  305. $binvalue = '';
  306. $bytewordlen = strlen($byteword);
  307. for($i = 0; $i < $bytewordlen; $i ++)
  308. {
  309. $binvalue .= str_pad(decbin(ord($byteword{$i})), 8, '0', STR_PAD_LEFT);
  310. }
  311. return $binvalue;
  312. }
  313. function BigEndian2String($number, $minbytes = 1, $synchsafe = false, $signed = false)
  314. {
  315. if ($number < 0)
  316. {
  317. return false;
  318. }
  319. $maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
  320. $intstring = '';
  321. if ($signed)
  322. {
  323. if ($minbytes > 4)
  324. {
  325. die('ERROR: Cannot have signed integers larger than 32-bits in getid3_lib::BigEndian2String()');
  326. }
  327. $number = $number & (0x80 << (8 * ($minbytes - 1)));
  328. }
  329. while ($number != 0)
  330. {
  331. $quotient = ($number / ($maskbyte + 1));
  332. $intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)) . $intstring;
  333. $number = floor($quotient);
  334. }
  335. return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT);
  336. }
  337. function Dec2Bin($number)
  338. {
  339. while ($number >= 256)
  340. {
  341. $bytes[] = (($number / 256) - (floor($number / 256))) * 256;
  342. $number = floor($number / 256);
  343. }
  344. $bytes[] = $number;
  345. $binstring = '';
  346. for($i = 0; $i < count($bytes); $i ++)
  347. {
  348. $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)) . $binstring;
  349. }
  350. return $binstring;
  351. }
  352. function Bin2Dec($binstring, $signed = false)
  353. {
  354. $signmult = 1;
  355. if ($signed)
  356. {
  357. if ($binstring{0} == '1')
  358. {
  359. $signmult = - 1;
  360. }
  361. $binstring = substr($binstring, 1);
  362. }
  363. $decvalue = 0;
  364. for($i = 0; $i < strlen($binstring); $i ++)
  365. {
  366. $decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
  367. }
  368. return getid3_lib :: CastAsInt($decvalue * $signmult);
  369. }
  370. function Bin2String($binstring)
  371. {
  372. // return 'hi' for input of '0110100001101001'
  373. $string = '';
  374. $binstringreversed = strrev($binstring);
  375. for($i = 0; $i < strlen($binstringreversed); $i += 8)
  376. {
  377. $string = chr(getid3_lib :: Bin2Dec(strrev(substr($binstringreversed, $i, 8)))) . $string;
  378. }
  379. return $string;
  380. }
  381. function LittleEndian2String($number, $minbytes = 1, $synchsafe = false)
  382. {
  383. $intstring = '';
  384. while ($number > 0)
  385. {
  386. if ($synchsafe)
  387. {
  388. $intstring = $intstring . chr($number & 127);
  389. $number >>= 7;
  390. }
  391. else
  392. {
  393. $intstring = $intstring . chr($number & 255);
  394. $number >>= 8;
  395. }
  396. }
  397. return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
  398. }
  399. function array_merge_clobber($array1, $array2)
  400. {
  401. // written by kc�hireability*com
  402. // taken from http://www.php.net/manual/en/function.array-merge-recursive.php
  403. if (! is_array($array1) || ! is_array($array2))
  404. {
  405. return false;
  406. }
  407. $newarray = $array1;
  408. foreach ($array2 as $key => $val)
  409. {
  410. if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key]))
  411. {
  412. $newarray[$key] = getid3_lib :: array_merge_clobber($newarray[$key], $val);
  413. }
  414. else
  415. {
  416. $newarray[$key] = $val;
  417. }
  418. }
  419. return $newarray;
  420. }
  421. function array_merge_noclobber($array1, $array2)
  422. {
  423. if (! is_array($array1) || ! is_array($array2))
  424. {
  425. return false;
  426. }
  427. $newarray = $array1;
  428. foreach ($array2 as $key => $val)
  429. {
  430. if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key]))
  431. {
  432. $newarray[$key] = getid3_lib :: array_merge_noclobber($newarray[$key], $val);
  433. }
  434. elseif (! isset($newarray[$key]))
  435. {
  436. $newarray[$key] = $val;
  437. }
  438. }
  439. return $newarray;
  440. }
  441. function fileextension($filename, $numextensions = 1)
  442. {
  443. if (strstr($filename, '.'))
  444. {
  445. $reversedfilename = strrev($filename);
  446. $offset = 0;
  447. for($i = 0; $i < $numextensions; $i ++)
  448. {
  449. $offset = strpos($reversedfilename, '.', $offset + 1);
  450. if ($offset === false)
  451. {
  452. return '';
  453. }
  454. }
  455. return strrev(substr($reversedfilename, 0, $offset));
  456. }
  457. return '';
  458. }
  459. function PlaytimeString($playtimeseconds)
  460. {
  461. $sign = (($playtimeseconds < 0) ? '-' : '');
  462. $playtimeseconds = abs($playtimeseconds);
  463. $contentseconds = round((($playtimeseconds / 60) - floor($playtimeseconds / 60)) * 60);
  464. $contentminutes = floor($playtimeseconds / 60);
  465. if ($contentseconds >= 60)
  466. {
  467. $contentseconds -= 60;
  468. $contentminutes ++;
  469. }
  470. return $sign . intval($contentminutes) . ':' . str_pad($contentseconds, 2, 0, STR_PAD_LEFT);
  471. }
  472. function image_type_to_mime_type($imagetypeid)
  473. {
  474. // only available in PHP v4.3.0+
  475. static $image_type_to_mime_type = array();
  476. if (empty($image_type_to_mime_type))
  477. {
  478. $image_type_to_mime_type[1] = 'image/gif'; // GIF
  479. $image_type_to_mime_type[2] = 'image/jpeg'; // JPEG
  480. $image_type_to_mime_type[3] = 'image/png'; // PNG
  481. $image_type_to_mime_type[4] = 'application/x-shockwave-flash'; // Flash
  482. $image_type_to_mime_type[5] = 'image/psd'; // PSD
  483. $image_type_to_mime_type[6] = 'image/bmp'; // BMP
  484. $image_type_to_mime_type[7] = 'image/tiff'; // TIFF: little-endian (Intel)
  485. $image_type_to_mime_type[8] = 'image/tiff'; // TIFF: big-endian (Motorola)
  486. //$image_type_to_mime_type[9] = 'image/jpc'; // JPC
  487. //$image_type_to_mime_type[10] = 'image/jp2'; // JPC
  488. //$image_type_to_mime_type[11] = 'image/jpx'; // JPC
  489. //$image_type_to_mime_type[12] = 'image/jb2'; // JPC
  490. $image_type_to_mime_type[13] = 'application/x-shockwave-flash'; // Shockwave
  491. $image_type_to_mime_type[14] = 'image/iff'; // IFF
  492. }
  493. return (isset($image_type_to_mime_type[$imagetypeid]) ? $image_type_to_mime_type[$imagetypeid] : 'application/octet-stream');
  494. }
  495. function DateMac2Unix($macdate)
  496. {
  497. // Macintosh timestamp: seconds since 00:00h January 1, 1904
  498. // UNIX timestamp: seconds since 00:00h January 1, 1970
  499. return getid3_lib :: CastAsInt($macdate - 2082844800);
  500. }
  501. function FixedPoint8_8($rawdata)
  502. {
  503. return getid3_lib :: BigEndian2Int(substr($rawdata, 0, 1)) + (float) (getid3_lib :: BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
  504. }
  505. function FixedPoint16_16($rawdata)
  506. {
  507. return getid3_lib :: BigEndian2Int(substr($rawdata, 0, 2)) + (float) (getid3_lib :: BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
  508. }
  509. function FixedPoint2_30($rawdata)
  510. {
  511. $binarystring = getid3_lib :: BigEndian2Bin($rawdata);
  512. return getid3_lib :: Bin2Dec(substr($binarystring, 0, 2)) + (float) (getid3_lib :: Bin2Dec(substr($binarystring, 2, 30)) / 1073741824);
  513. }
  514. function CreateDeepArray($ArrayPath, $Separator, $Value)
  515. {
  516. // assigns $Value to a nested array path:
  517. // $foo = getid3_lib::CreateDeepArray('/path/to/my', '/', 'file.txt')
  518. // is the same as:
  519. // $foo = array('path'=>array('to'=>'array('my'=>array('file.txt'))));
  520. // or
  521. // $foo['path']['to']['my'] = 'file.txt';
  522. while ($ArrayPath && ($ArrayPath{0} == $Separator))
  523. {
  524. $ArrayPath = substr($ArrayPath, 1);
  525. }
  526. if (($pos = strpos($ArrayPath, $Separator)) !== false)
  527. {
  528. $ReturnedArray[substr($ArrayPath, 0, $pos)] = getid3_lib :: CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value);
  529. }
  530. else
  531. {
  532. $ReturnedArray[$ArrayPath] = $Value;
  533. }
  534. return $ReturnedArray;
  535. }
  536. function array_max($arraydata, $returnkey = false)
  537. {
  538. $maxvalue = false;
  539. $maxkey = false;
  540. foreach ($arraydata as $key => $value)
  541. {
  542. if (! is_array($value))
  543. {
  544. if ($value > $maxvalue)
  545. {
  546. $maxvalue = $value;
  547. $maxkey = $key;
  548. }
  549. }
  550. }
  551. return ($returnkey ? $maxkey : $maxvalue);
  552. }
  553. function array_min($arraydata, $returnkey = false)
  554. {
  555. $minvalue = false;
  556. $minkey = false;
  557. foreach ($arraydata as $key => $value)
  558. {
  559. if (! is_array($value))
  560. {
  561. if ($value > $minvalue)
  562. {
  563. $minvalue = $value;
  564. $minkey = $key;
  565. }
  566. }
  567. }
  568. return ($returnkey ? $minkey : $minvalue);
  569. }
  570. function md5_file($file)
  571. {
  572. // md5_file() exists in PHP 4.2.0+.
  573. if (function_exists('md5_file'))
  574. {
  575. return md5_file($file);
  576. }
  577. if (GETID3_OS_ISWINDOWS)
  578. {
  579. $RequiredFiles = array('cygwin1.dll', 'md5sum.exe');
  580. foreach ($RequiredFiles as $required_file)
  581. {
  582. if (! is_readable(GETID3_HELPERAPPSDIR . $required_file))
  583. {
  584. die(implode(' and ', $RequiredFiles) . ' are required in ' . GETID3_HELPERAPPSDIR . ' for getid3_lib::md5_file() to function under Windows in PHP < v4.2.0');
  585. }
  586. }
  587. $commandline = GETID3_HELPERAPPSDIR . 'md5sum.exe "' . str_replace('/', DIRECTORY_SEPARATOR, $file) . '"';
  588. if (ereg("^[\\]?([0-9a-f]{32})", strtolower(`$commandline`), $r))
  589. {
  590. return $r[1];
  591. }
  592. }
  593. else
  594. {
  595. // The following works under UNIX only
  596. $file = str_replace('`', '\\`', $file);
  597. if (ereg("^([0-9a-f]{32})[ \t\n\r]", `md5sum "$file"`, $r))
  598. {
  599. return $r[1];
  600. }
  601. }
  602. return false;
  603. }
  604. function sha1_file($file)
  605. {
  606. // sha1_file() exists in PHP 4.3.0+.
  607. if (function_exists('sha1_file'))
  608. {
  609. return sha1_file($file);
  610. }
  611. $file = str_replace('`', '\\`', $file);
  612. if (GETID3_OS_ISWINDOWS)
  613. {
  614. $RequiredFiles = array('cygwin1.dll', 'sha1sum.exe');
  615. foreach ($RequiredFiles as $required_file)
  616. {
  617. if (! is_readable(GETID3_HELPERAPPSDIR . $required_file))
  618. {
  619. die(implode(' and ', $RequiredFiles) . ' are required in ' . GETID3_HELPERAPPSDIR . ' for getid3_lib::sha1_file() to function under Windows in PHP < v4.3.0');
  620. }
  621. }
  622. $commandline = GETID3_HELPERAPPSDIR . 'sha1sum.exe "' . str_replace('/', DIRECTORY_SEPARATOR, $file) . '"';
  623. if (ereg("^sha1=([0-9a-f]{40})", strtolower(`$commandline`), $r))
  624. {
  625. return $r[1];
  626. }
  627. }
  628. else
  629. {
  630. $commandline = 'sha1sum ' . escapeshellarg($file) . '';
  631. if (ereg("^([0-9a-f]{40})[ \t\n\r]", strtolower(`$commandline`), $r))
  632. {
  633. return $r[1];
  634. }
  635. }
  636. return false;
  637. }
  638. // Allan Hansen <ah�artemis*dk>
  639. // getid3_lib::md5_data() - returns md5sum for a file from startuing position to absolute end position
  640. function hash_data($file, $offset, $end, $algorithm)
  641. {
  642. if ($end >= pow(2, 31))
  643. {
  644. return false;
  645. }
  646. switch ($algorithm)
  647. {
  648. case 'md5' :
  649. $hash_function = 'md5_file';
  650. $unix_call = 'md5sum';
  651. $windows_call = 'md5sum.exe';
  652. $hash_length = 32;
  653. break;
  654. case 'sha1' :
  655. $hash_function = 'sha1_file';
  656. $unix_call = 'sha1sum';
  657. $windows_call = 'sha1sum.exe';
  658. $hash_length = 40;
  659. break;
  660. default :
  661. die('Invalid algorithm (' . $algorithm . ') in getid3_lib::hash_data()');
  662. break;
  663. }
  664. $size = $end - $offset;
  665. while (true)
  666. {
  667. if (GETID3_OS_ISWINDOWS)
  668. {
  669. // It seems that sha1sum.exe for Windows only works on physical files, does not accept piped data
  670. // Fall back to create-temp-file method:
  671. if ($algorithm == 'sha1')
  672. {
  673. break;
  674. }
  675. $RequiredFiles = array('cygwin1.dll', 'head.exe', 'tail.exe', $windows_call);
  676. foreach ($RequiredFiles as $required_file)
  677. {
  678. if (! is_readable(GETID3_HELPERAPPSDIR . $required_file))
  679. {
  680. // helper apps not available - fall back to old method
  681. break;
  682. }
  683. }
  684. $commandline = GETID3_HELPERAPPSDIR . 'head.exe -c ' . $end . ' "' . escapeshellarg(str_replace('/', DIRECTORY_SEPARATOR, $file)) . '" | ';
  685. $commandline .= GETID3_HELPERAPPSDIR . 'tail.exe -c ' . $size . ' | ';
  686. $commandline .= GETID3_HELPERAPPSDIR . $windows_call;
  687. }
  688. else
  689. {
  690. $commandline = 'head -c' . $end . ' ' . escapeshellarg($file) . ' | ';
  691. $commandline .= 'tail -c' . $size . ' | ';
  692. $commandline .= $unix_call;
  693. }
  694. if ((bool) ini_get('safe_mode'))
  695. {
  696. $ThisFileInfo['warning'][] = 'PHP running in Safe Mode - backtick operator not available, using slower non-system-call ' . $algorithm . ' algorithm';
  697. break;
  698. }
  699. return substr(`$commandline`, 0, $hash_length);
  700. }
  701. // try to create a temporary file in the system temp directory - invalid dirname should force to system temp dir
  702. if (($data_filename = tempnam('*', 'getID3')) === false)
  703. {
  704. // can't find anywhere to create a temp file, just die
  705. return false;
  706. }
  707. // Init
  708. $result = false;
  709. // copy parts of file
  710. if ($fp = @fopen($file, 'rb'))
  711. {
  712. if ($fp_data = @fopen($data_filename, 'wb'))
  713. {
  714. fseek($fp, $offset, SEEK_SET);
  715. $byteslefttowrite = $end - $offset;
  716. while (($byteslefttowrite > 0) && ($buffer = fread($fp, GETID3_FREAD_BUFFER_SIZE)))
  717. {
  718. $byteswritten = fwrite($fp_data, $buffer, $byteslefttowrite);
  719. $byteslefttowrite -= $byteswritten;
  720. }
  721. fclose($fp_data);
  722. $result = getid3_lib :: $hash_function($data_filename);
  723. }
  724. fclose($fp);
  725. }
  726. unlink($data_filename);
  727. return $result;
  728. }
  729. function iconv_fallback_int_utf8($charval)
  730. {
  731. if ($charval < 128)
  732. {
  733. // 0bbbbbbb
  734. $newcharstring = chr($charval);
  735. }
  736. elseif ($charval < 2048)
  737. {
  738. // 110bbbbb 10bbbbbb
  739. $newcharstring = chr(($charval >> 6) | 0xC0);
  740. $newcharstring .= chr(($charval & 0x3F) | 0x80);
  741. }
  742. elseif ($charval < 65536)
  743. {
  744. // 1110bbbb 10bbbbbb 10bbbbbb
  745. $newcharstring = chr(($charval >> 12) | 0xE0);
  746. $newcharstring .= chr(($charval >> 6) | 0xC0);
  747. $newcharstring .= chr(($charval & 0x3F) | 0x80);
  748. }
  749. else
  750. {
  751. // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
  752. $newcharstring = chr(($charval >> 18) | 0xF0);
  753. $newcharstring .= chr(($charval >> 12) | 0xC0);
  754. $newcharstring .= chr(($charval >> 6) | 0xC0);
  755. $newcharstring .= chr(($charval & 0x3F) | 0x80);
  756. }
  757. return $newcharstring;
  758. }
  759. // ISO-8859-1 => UTF-8
  760. function iconv_fallback_iso88591_utf8($string, $bom = false)
  761. {
  762. if (function_exists('utf8_encode'))
  763. {
  764. return utf8_encode($string);
  765. }
  766. // utf8_encode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
  767. $newcharstring = '';
  768. if ($bom)
  769. {
  770. $newcharstring .= "\xEF\xBB\xBF";
  771. }
  772. for($i = 0; $i < strlen($string); $i ++)
  773. {
  774. $charval = ord($string{$i});
  775. $newcharstring .= getid3_lib :: iconv_fallback_int_utf8($charval);
  776. }
  777. return $newcharstring;
  778. }
  779. // ISO-8859-1 => UTF-16BE
  780. function iconv_fallback_iso88591_utf16be($string, $bom = false)
  781. {
  782. $newcharstring = '';
  783. if ($bom)
  784. {
  785. $newcharstring .= "\xFE\xFF";
  786. }
  787. for($i = 0; $i < strlen($string); $i ++)
  788. {
  789. $newcharstring .= "\x00" . $string{$i};
  790. }
  791. return $newcharstring;
  792. }
  793. // ISO-8859-1 => UTF-16LE
  794. function iconv_fallback_iso88591_utf16le($string, $bom = false)
  795. {
  796. $newcharstring = '';
  797. if ($bom)
  798. {
  799. $newcharstring .= "\xFF\xFE";
  800. }
  801. for($i = 0; $i < strlen($string); $i ++)
  802. {
  803. $newcharstring .= $string{$i} . "\x00";
  804. }
  805. return $newcharstring;
  806. }
  807. // ISO-8859-1 => UTF-16LE (BOM)
  808. function iconv_fallback_iso88591_utf16($string)
  809. {
  810. return getid3_lib :: iconv_fallback_iso88591_utf16le($string, true);
  811. }
  812. // UTF-8 => ISO-8859-1
  813. function iconv_fallback_utf8_iso88591($string)
  814. {
  815. if (function_exists('utf8_decode'))
  816. {
  817. return utf8_decode($string);
  818. }
  819. // utf8_decode() unavailable, use getID3()'s iconv_fallback() conversions (possibly PHP is compiled without XML support)
  820. $newcharstring = '';
  821. $offset = 0;
  822. $stringlength = strlen($string);
  823. while ($offset < $stringlength)
  824. {
  825. if ((ord($string{$offset}) | 0x07) == 0xF7)
  826. {
  827. // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
  828. $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & ((ord($string{($offset + 1)}) & 0x3F) << 12) & ((ord($string{($offset + 2)}) & 0x3F) << 6) & (ord($string{($offset + 3)}) & 0x3F);
  829. $offset += 4;
  830. }
  831. elseif ((ord($string{$offset}) | 0x0F) == 0xEF)
  832. {
  833. // 1110bbbb 10bbbbbb 10bbbbbb
  834. $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & ((ord($string{($offset + 1)}) & 0x3F) << 6) & (ord($string{($offset + 2)}) & 0x3F);
  835. $offset += 3;
  836. }
  837. elseif ((ord($string{$offset}) | 0x1F) == 0xDF)
  838. {
  839. // 110bbbbb 10bbbbbb
  840. $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & (ord($string{($offset + 1)}) & 0x3F);
  841. $offset += 2;
  842. }
  843. elseif ((ord($string{$offset}) | 0x7F) == 0x7F)
  844. {
  845. // 0bbbbbbb
  846. $charval = ord($string{$offset});
  847. $offset += 1;
  848. }
  849. else
  850. {
  851. // error? throw some kind of warning here?
  852. $charval = false;
  853. $offset += 1;
  854. }
  855. if ($charval !== false)
  856. {
  857. $newcharstring .= (($charval < 256) ? chr($charval) : '?');
  858. }
  859. }
  860. return $newcharstring;
  861. }
  862. // UTF-8 => UTF-16BE
  863. function iconv_fallback_utf8_utf16be($string, $bom = false)
  864. {
  865. $newcharstring = '';
  866. if ($bom)
  867. {
  868. $newcharstring .= "\xFE\xFF";
  869. }
  870. $offset = 0;
  871. $stringlength = strlen($string);
  872. while ($offset < $stringlength)
  873. {
  874. if ((ord($string{$offset}) | 0x07) == 0xF7)
  875. {
  876. // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
  877. $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & ((ord($string{($offset + 1)}) & 0x3F) << 12) & ((ord($string{($offset + 2)}) & 0x3F) << 6) & (ord($string{($offset + 3)}) & 0x3F);
  878. $offset += 4;
  879. }
  880. elseif ((ord($string{$offset}) | 0x0F) == 0xEF)
  881. {
  882. // 1110bbbb 10bbbbbb 10bbbbbb
  883. $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & ((ord($string{($offset + 1)}) & 0x3F) << 6) & (ord($string{($offset + 2)}) & 0x3F);
  884. $offset += 3;
  885. }
  886. elseif ((ord($string{$offset}) | 0x1F) == 0xDF)
  887. {
  888. // 110bbbbb 10bbbbbb
  889. $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & (ord($string{($offset + 1)}) & 0x3F);
  890. $offset += 2;
  891. }
  892. elseif ((ord($string{$offset}) | 0x7F) == 0x7F)
  893. {
  894. // 0bbbbbbb
  895. $charval = ord($string{$offset});
  896. $offset += 1;
  897. }
  898. else
  899. {
  900. // error? throw some kind of warning here?
  901. $charval = false;
  902. $offset += 1;
  903. }
  904. if ($charval !== false)
  905. {
  906. $newcharstring .= (($charval < 65536) ? getid3_lib :: BigEndian2String($charval, 2) : "\x00" . '?');
  907. }
  908. }
  909. return $newcharstring;
  910. }
  911. // UTF-8 => UTF-16LE
  912. function iconv_fallback_utf8_utf16le($string, $bom = false)
  913. {
  914. $newcharstring = '';
  915. if ($bom)
  916. {
  917. $newcharstring .= "\xFF\xFE";
  918. }
  919. $offset = 0;
  920. $stringlength = strlen($string);
  921. while ($offset < $stringlength)
  922. {
  923. if ((ord($string{$offset}) | 0x07) == 0xF7)
  924. {
  925. // 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
  926. $charval = ((ord($string{($offset + 0)}) & 0x07) << 18) & ((ord($string{($offset + 1)}) & 0x3F) << 12) & ((ord($string{($offset + 2)}) & 0x3F) << 6) & (ord($string{($offset + 3)}) & 0x3F);
  927. $offset += 4;
  928. }
  929. elseif ((ord($string{$offset}) | 0x0F) == 0xEF)
  930. {
  931. // 1110bbbb 10bbbbbb 10bbbbbb
  932. $charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) & ((ord($string{($offset + 1)}) & 0x3F) << 6) & (ord($string{($offset + 2)}) & 0x3F);
  933. $offset += 3;
  934. }
  935. elseif ((ord($string{$offset}) | 0x1F) == 0xDF)
  936. {
  937. // 110bbbbb 10bbbbbb
  938. $charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) & (ord($string{($offset + 1)}) & 0x3F);
  939. $offset += 2;
  940. }
  941. elseif ((ord($string{$offset}) | 0x7F) == 0x7F)
  942. {
  943. // 0bbbbbbb
  944. $charval = ord($string{$offset});
  945. $offset += 1;
  946. }
  947. else
  948. {
  949. // error? maybe throw some warning here?
  950. $charval = false;
  951. $offset += 1;
  952. }
  953. if ($charval !== false)
  954. {
  955. $newcharstring .= (($charval < 65536) ? getid3_lib :: LittleEndian2String($charval, 2) : '?' . "\x00");
  956. }
  957. }
  958. return $newcharstring;
  959. }
  960. // UTF-8 => UTF-16LE (BOM)
  961. function iconv_fallback_utf8_utf16($string)
  962. {
  963. return getid3_lib :: iconv_fallback_utf8_utf16le($string, true);
  964. }
  965. // UTF-16BE => UTF-8
  966. function iconv_fallback_utf16be_utf8($string)
  967. {
  968. if (substr($string, 0, 2) == "\xFE\xFF")
  969. {
  970. // strip BOM
  971. $string = substr($string, 2);
  972. }
  973. $newcharstring = '';
  974. for($i = 0; $i < strlen($string); $i += 2)
  975. {
  976. $charval = getid3_lib :: BigEndian2Int(substr($string, $i, 2));
  977. $newcharstring .= getid3_lib :: iconv_fallback_int_utf8($charval);
  978. }
  979. return $newcharstring;
  980. }
  981. // UTF-16LE => UTF-8
  982. function iconv_fallback_utf16le_utf8($string)
  983. {
  984. if (substr($string, 0, 2) == "\xFF\xFE")
  985. {
  986. // strip BOM
  987. $string = substr($string, 2);
  988. }
  989. $newcharstring = '';
  990. for($i = 0; $i < strlen($string); $i += 2)
  991. {
  992. $charval = getid3_lib :: LittleEndian2Int(substr($string, $i, 2));
  993. $newcharstring .= getid3_lib :: iconv_fallback_int_utf8($charval);
  994. }
  995. return $newcharstring;
  996. }
  997. // UTF-16BE => ISO-8859-1
  998. function iconv_fallback_utf16be_iso88591($string)
  999. {
  1000. if (substr($string, 0, 2) == "\xFE\xFF")
  1001. {
  1002. // strip BOM
  1003. $string = substr($string, 2);
  1004. }
  1005. $newcharstring = '';
  1006. for($i = 0; $i < strlen($string); $i += 2)
  1007. {
  1008. $charval = getid3_lib :: BigEndian2Int(substr($string, $i, 2));
  1009. $newcharstring .= (($charval < 256) ? chr($charval) : '?');
  1010. }
  1011. return $newcharstring;
  1012. }
  1013. // UTF-16LE => ISO-8859-1
  1014. function iconv_fallback_utf16le_iso88591($string)
  1015. {
  1016. if (substr($string, 0, 2) == "\xFF\xFE")
  1017. {
  1018. // strip BOM
  1019. $string = substr($string, 2);
  1020. }
  1021. $newcharstring = '';
  1022. for($i = 0; $i < strlen($string); $i += 2)
  1023. {
  1024. $charval = getid3_lib :: LittleEndian2Int(substr($string, $i, 2));
  1025. $newcharstring .= (($charval < 256) ? chr($charval) : '?');
  1026. }
  1027. return $newcharstring;
  1028. }
  1029. // UTF-16 (BOM) => ISO-8859-1
  1030. function iconv_fallback_utf16_iso88591($string)
  1031. {
  1032. $bom = substr($string, 0, 2);
  1033. if ($bom == "\xFE\xFF")
  1034. {
  1035. return getid3_lib :: iconv_fallback_utf16be_iso88591(substr($string, 2));
  1036. }
  1037. elseif ($bom == "\xFF\xFE")
  1038. {
  1039. return getid3_lib :: iconv_fallback_utf16le_iso88591(substr($string, 2));
  1040. }
  1041. return $string;
  1042. }
  1043. // UTF-16 (BOM) => UTF-8
  1044. function iconv_fallback_utf16_utf8($string)
  1045. {
  1046. $bom = substr($string, 0, 2);
  1047. if ($bom == "\xFE\xFF")
  1048. {
  1049. return getid3_lib :: iconv_fallback_utf16be_utf8(substr($string, 2));
  1050. }
  1051. elseif ($bom == "\xFF\xFE")
  1052. {
  1053. return getid3_lib :: iconv_fallback_utf16le_utf8(substr($string, 2));
  1054. }
  1055. return $string;
  1056. }
  1057. function iconv_fallback($in_charset, $out_charset, $string)
  1058. {
  1059. if ($in_charset == $out_charset)
  1060. {
  1061. return $string;
  1062. }
  1063. // iconv() availble
  1064. if (function_exists('iconv'))
  1065. {
  1066. if ($converted_string = @iconv($in_charset, $out_charset . '//TRANSLIT', $string))
  1067. {
  1068. switch ($out_charset)
  1069. {
  1070. case 'ISO-8859-1' :
  1071. $converted_string = rtrim($converted_string, "\x00");
  1072. break;
  1073. }
  1074. return $converted_string;
  1075. }
  1076. // iconv() may sometimes fail with "illegal character in input string" error message
  1077. // and return an empty string, but returning the unconverted string is more useful
  1078. return $string;
  1079. }
  1080. // iconv() not available
  1081. static $ConversionFunctionList = array();
  1082. if (empty($ConversionFunctionList))
  1083. {
  1084. $ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8';
  1085. $ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16';
  1086. $ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be';
  1087. $ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le';
  1088. $ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591';
  1089. $ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16';
  1090. $ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be';
  1091. $ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le';
  1092. $ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591';
  1093. $ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8';
  1094. $ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591';
  1095. $ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8';
  1096. $ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591';
  1097. $ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8';
  1098. }
  1099. if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)]))
  1100. {
  1101. $ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
  1102. return getid3_lib :: $ConversionFunction($string);
  1103. }
  1104. die('PHP does not have iconv() support - cannot convert from ' . $in_charset . ' to ' . $out_charset);
  1105. }
  1106. function MultiByteCharString2HTML($string, $charset = 'ISO-8859-1')
  1107. {
  1108. $HTMLstring = '';
  1109. switch ($charset)
  1110. {
  1111. case 'ISO-8859-1' :
  1112. case 'ISO8859-1' :
  1113. case 'ISO-8859-15' :
  1114. case 'ISO8859-15' :
  1115. case 'cp866' :
  1116. case 'ibm866' :
  1117. case '866' :
  1118. case 'cp1251' :
  1119. case 'Windows-1251' :
  1120. case 'win-1251' :
  1121. case '1251' :
  1122. case 'cp1252' :
  1123. case 'Windows-1252' :
  1124. case '1252' :
  1125. case 'KOI8-R' :
  1126. case 'koi8-ru' :
  1127. case 'koi8r' :
  1128. case 'BIG5' :
  1129. case '950' :
  1130. case 'GB2312' :
  1131. case '936' :
  1132. case 'BIG5-HKSCS' :
  1133. case 'Shift_JIS' :
  1134. case 'SJIS' :
  1135. case '932' :
  1136. case 'EUC-JP' :
  1137. case 'EUCJP' :
  1138. $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
  1139. break;
  1140. case 'UTF-8' :
  1141. $strlen = strlen($string);
  1142. for($i = 0; $i < $strlen; $i ++)
  1143. {
  1144. $char_ord_val = ord($string{$i});
  1145. $charval = 0;
  1146. if ($char_ord_val < 0x80)
  1147. {
  1148. $charval = $char_ord_val;
  1149. }
  1150. elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i + 3 < $strlen)
  1151. {
  1152. $charval = (($char_ord_val & 0x07) << 18);
  1153. $charval += ((ord($string{++ $i}) & 0x3F) << 12);
  1154. $charval += ((ord($string{++ $i}) & 0x3F) << 6);
  1155. $charval += (ord($string{++ $i}) & 0x3F);
  1156. }
  1157. elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i + 2 < $strlen)
  1158. {
  1159. $charval = (($char_ord_val & 0x0F) << 12);
  1160. $charval += ((ord($string{++ $i}) & 0x3F) << 6);
  1161. $charval += (ord($string{++ $i}) & 0x3F);
  1162. }
  1163. elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i + 1 < $strlen)
  1164. {
  1165. $charval = (($char_ord_val & 0x1F) << 6);
  1166. $charval += (ord($string{++ $i}) & 0x3F);
  1167. }
  1168. if (($charval >= 32) && ($charval <= 127))
  1169. {
  1170. $HTMLstring .= htmlentities(chr($charval));
  1171. }
  1172. else
  1173. {
  1174. $HTMLstring .= '&#' . $charval . ';';
  1175. }
  1176. }
  1177. break;
  1178. case 'UTF-16LE' :
  1179. for($i = 0; $i < strlen($string); $i += 2)
  1180. {
  1181. $charval = getid3_lib :: LittleEndian2Int(substr($string, $i, 2));
  1182. if (($charval >= 32) && ($charval <= 127))
  1183. {
  1184. $HTMLstring .= chr($charval);
  1185. }
  1186. else
  1187. {
  1188. $HTMLstring .= '&#' . $charval . ';';
  1189. }
  1190. }
  1191. break;
  1192. case 'UTF-16BE' :
  1193. for($i = 0; $i < strlen($string); $i += 2)
  1194. {
  1195. $charval = getid3_lib :: BigEndian2Int(substr($string, $i, 2));
  1196. if (($charval >= 32) && ($charval <= 127))
  1197. {
  1198. $HTMLstring .= chr($charval);
  1199. }
  1200. else
  1201. {
  1202. $HTMLstring .= '&#' . $charval . ';';
  1203. }
  1204. }
  1205. break;
  1206. default :
  1207. $HTMLstring = 'ERROR: Character set "' . $charset . '" not supported in MultiByteCharString2HTML()';
  1208. break;
  1209. }
  1210. return $HTMLstring;
  1211. }
  1212. function RGADnameLookup($namecode)
  1213. {
  1214. static $RGADname = array();
  1215. if (empty($RGADname))
  1216. {
  1217. $RGADname[0] = 'not set';
  1218. $RGADname[1] = 'Track Gain Adjustment';
  1219. $RGADname[2] = 'Album Gain Adjustment';
  1220. }
  1221. return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : '');
  1222. }
  1223. function RGADoriginatorLookup($originatorcode)
  1224. {
  1225. static $RGADoriginator = array();
  1226. if (empty($RGADoriginator))
  1227. {
  1228. $RGADoriginator[0] = 'unspecified';
  1229. $RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer';
  1230. $RGADoriginator[2] = 'set by user';
  1231. $RGADoriginator[3] = 'determined automatically';
  1232. }
  1233. return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : '');
  1234. }
  1235. function RGADadjustmentLookup($rawadjustment, $signbit)
  1236. {
  1237. $adjustment = $rawadjustment / 10;
  1238. if ($signbit == 1)
  1239. {
  1240. $adjustment *= - 1;
  1241. }
  1242. return (float) $adjustment;
  1243. }
  1244. function RGADgainString($namecode, $originatorcode, $replaygain)
  1245. {
  1246. if ($replaygain < 0)
  1247. {
  1248. $signbit = '1';
  1249. }
  1250. else
  1251. {
  1252. $signbit = '0';
  1253. }
  1254. $storedreplaygain = intval(round($replaygain * 10));
  1255. $gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT);
  1256. $gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT);
  1257. $gainstring .= $signbit;
  1258. $gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT);
  1259. return $gainstring;
  1260. }
  1261. function RGADamplitude2dB($amplitude)
  1262. {
  1263. return 20 * log10($amplitude);
  1264. }
  1265. function GetDataImageSize($imgData, &$imageinfo)
  1266. {
  1267. $GetDataImageSize = false;
  1268. if ($tempfilename = tempnam('*', 'getID3'))
  1269. {
  1270. if ($tmp = @fopen($tempfilename, 'wb'))
  1271. {
  1272. fwrite($tmp, $imgData);
  1273. fclose($tmp);
  1274. $GetDataImageSize = @GetImageSize($tempfilename, $imageinfo);
  1275. }
  1276. unlink($tempfilename);
  1277. }
  1278. return $GetDataImageSize;
  1279. }
  1280. function ImageTypesLookup($imagetypeid)
  1281. {
  1282. static $ImageTypesLookup = array();
  1283. if (empty($ImageTypesLookup))
  1284. {
  1285. $ImageTypesLookup[1] = 'gif';
  1286. $ImageTypesLookup[2] = 'jpeg';
  1287. $ImageTypesLookup[3] = 'png';
  1288. $ImageTypesLookup[4] = 'swf';
  1289. $ImageTypesLookup[5] = 'psd';
  1290. $ImageTypesLookup[6] = 'bmp';
  1291. $ImageTypesLookup[7] = 'tiff (little-endian)';
  1292. $ImageTypesLookup[8] = 'tiff (big-endian)';
  1293. $ImageTypesLookup[9] = 'jpc';
  1294. $ImageTypesLookup[10] = 'jp2';
  1295. $ImageTypesLookup[11] = 'jpx';
  1296. $ImageTypesLookup[12] = 'jb2';
  1297. $ImageTypesLookup[13] = 'swc';
  1298. $ImageTypesLookup[14] = 'iff';
  1299. }
  1300. return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : '');
  1301. }
  1302. function CopyTagsToComments(&$ThisFileInfo)
  1303. {
  1304. // Copy all entries from ['tags'] into common ['comments']
  1305. if (! empty($ThisFileInfo['tags']))
  1306. {
  1307. foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray)
  1308. {
  1309. foreach ($

Large files files are truncated, but you can click here to view the full file