Changeset 52254 for trunk/src/wp-includes/ID3/getid3.lib.php
- Timestamp:
- 11/26/2021 03:04:10 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ID3/getid3.lib.php
r51901 r52254 243 243 * ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic 244 244 * 245 * @link http ://www.psc.edu/general/software/packages/ieee/ieee.html245 * @link https://web.archive.org/web/20120325162206/http://www.psc.edu/general/software/packages/ieee/ieee.php 246 246 * @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html 247 247 * … … 295 295 if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) { 296 296 // Not a Number 297 $floatvalue = false;297 $floatvalue = NAN; 298 298 } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { 299 299 if ($signbit == '1') { 300 $floatvalue = '-infinity';300 $floatvalue = -INF; 301 301 } else { 302 $floatvalue = '+infinity';302 $floatvalue = INF; 303 303 } 304 304 } elseif (($exponent == 0) && ($fraction == 0)) { … … 428 428 */ 429 429 public static function Dec2Bin($number) { 430 if (!is_numeric($number)) { 431 // https://github.com/JamesHeinrich/getID3/issues/299 432 trigger_error('TypeError: Dec2Bin(): Argument #1 ($number) must be numeric, '.gettype($number).' given', E_USER_WARNING); 433 return ''; 434 } 435 $bytes = array(); 430 436 while ($number >= 256) { 431 $bytes[] = ( ($number / 256) - (floor($number / 256))) * 256;437 $bytes[] = (int) (($number / 256) - (floor($number / 256))) * 256; 432 438 $number = floor($number / 256); 433 439 } 434 $bytes[] = $number;440 $bytes[] = (int) $number; 435 441 $binstring = ''; 436 for ($i = 0; $i < count($bytes); $i++) {437 $binstring = (($i == count($bytes) - 1) ? decbin($byte s[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring;442 foreach ($bytes as $i => $byte) { 443 $binstring = (($i == count($bytes) - 1) ? decbin($byte) : str_pad(decbin($byte), 8, '0', STR_PAD_LEFT)).$binstring; 438 444 } 439 445 return $binstring; … … 666 672 // $foo['path']['to']['my'] = 'file.txt'; 667 673 $ArrayPath = ltrim($ArrayPath, $Separator); 674 $ReturnedArray = array(); 668 675 if (($pos = strpos($ArrayPath, $Separator)) !== false) { 669 676 $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); … … 1539 1546 // Copy all entries from ['tags'] into common ['comments'] 1540 1547 if (!empty($ThisFileInfo['tags'])) { 1541 if (isset($ThisFileInfo['tags']['id3v1'])) { 1542 // bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings 1543 $ID3v1 = $ThisFileInfo['tags']['id3v1']; 1544 unset($ThisFileInfo['tags']['id3v1']); 1545 $ThisFileInfo['tags']['id3v1'] = $ID3v1; 1546 unset($ID3v1); 1548 1549 // Some tag types can only support limited character sets and may contain data in non-standard encoding (usually ID3v1) 1550 // and/or poorly-transliterated tag values that are also in tag formats that do support full-range character sets 1551 // To make the output more user-friendly, process the potentially-problematic tag formats last to enhance the chance that 1552 // the first entries in [comments] are the most correct and the "bad" ones (if any) come later. 1553 // https://github.com/JamesHeinrich/getID3/issues/338 1554 $processLastTagTypes = array('id3v1','riff'); 1555 foreach ($processLastTagTypes as $processLastTagType) { 1556 if (isset($ThisFileInfo['tags'][$processLastTagType])) { 1557 // bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings 1558 $temp = $ThisFileInfo['tags'][$processLastTagType]; 1559 unset($ThisFileInfo['tags'][$processLastTagType]); 1560 $ThisFileInfo['tags'][$processLastTagType] = $temp; 1561 unset($temp); 1562 } 1547 1563 } 1548 1564 foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) { … … 1563 1579 break 2; 1564 1580 } 1565 } 1566 if (function_exists('mb_convert_encoding')) { 1567 if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) { 1568 // value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1. 1569 // As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character 1570 break 2; 1581 1582 if (function_exists('mb_convert_encoding')) { 1583 if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) { 1584 // value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1. 1585 // As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character 1586 break 2; 1587 } 1571 1588 } 1572 1589 } … … 1574 1591 } elseif (!is_array($value)) { 1575 1592 1576 $newvaluelength = strlen(trim($value)); 1593 $newvaluelength = strlen(trim($value)); 1594 $newvaluelengthMB = mb_strlen(trim($value)); 1577 1595 foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) { 1578 $oldvaluelength = strlen(trim($existingvalue)); 1596 $oldvaluelength = strlen(trim($existingvalue)); 1597 $oldvaluelengthMB = mb_strlen(trim($existingvalue)); 1598 if (($newvaluelengthMB == $oldvaluelengthMB) && ($existingvalue == getid3_lib::iconv_fallback('UTF-8', 'ASCII', $value))) { 1599 // https://github.com/JamesHeinrich/getID3/issues/338 1600 // check for tags containing extended characters that may have been forced into limited-character storage (e.g. UTF8 values into ASCII) 1601 // which will usually display unrepresentable characters as "?" 1602 $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); 1603 break; 1604 } 1579 1605 if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) { 1580 1606 $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); … … 1602 1628 1603 1629 // attempt to standardize spelling of returned keys 1604 $StandardizeFieldNames = array( 1605 'tracknumber' => 'track_number', 1606 'track' => 'track_number', 1607 ); 1608 foreach ($StandardizeFieldNames as $badkey => $goodkey) { 1609 if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) { 1610 $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey]; 1611 unset($ThisFileInfo['comments'][$badkey]); 1630 if (!empty($ThisFileInfo['comments'])) { 1631 $StandardizeFieldNames = array( 1632 'tracknumber' => 'track_number', 1633 'track' => 'track_number', 1634 ); 1635 foreach ($StandardizeFieldNames as $badkey => $goodkey) { 1636 if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) { 1637 $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey]; 1638 unset($ThisFileInfo['comments'][$badkey]); 1639 } 1612 1640 } 1613 1641 } … … 1735 1763 */ 1736 1764 public static function getFileSizeSyscall($path) { 1765 $commandline = null; 1737 1766 $filesize = false; 1738 1767 … … 1796 1825 * @return string 1797 1826 */ 1798 public static function mb_basename($path, $suffix = null) {1827 public static function mb_basename($path, $suffix = '') { 1799 1828 $splited = preg_split('#/#', rtrim($path, '/ ')); 1800 1829 return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1);
Note: See TracChangeset
for help on using the changeset viewer.