Changeset 51901 for trunk/src/wp-includes/ID3/getid3.lib.php
- Timestamp:
- 10/10/2021 01:15:16 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ID3/getid3.lib.php
r51900 r51901 243 243 * ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic 244 244 * 245 * @link http s://web.archive.org/web/20120325162206/http://www.psc.edu/general/software/packages/ieee/ieee.php245 * @link http://www.psc.edu/general/software/packages/ieee/ieee.html 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 = NAN;297 $floatvalue = false; 298 298 } elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) { 299 299 if ($signbit == '1') { 300 $floatvalue = -INF;300 $floatvalue = '-infinity'; 301 301 } else { 302 $floatvalue = INF;302 $floatvalue = '+infinity'; 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/299432 trigger_error('TypeError: Dec2Bin(): Argument #1 ($number) must be numeric, '.gettype($number).' given', E_USER_WARNING);433 return '';434 }435 $bytes = array();436 430 while ($number >= 256) { 437 $bytes[] = ( int) (($number / 256) - (floor($number / 256))) * 256;431 $bytes[] = (($number / 256) - (floor($number / 256))) * 256; 438 432 $number = floor($number / 256); 439 433 } 440 $bytes[] = (int)$number;434 $bytes[] = $number; 441 435 $binstring = ''; 442 for each ($bytes as $i => $byte) {443 $binstring = (($i == count($bytes) - 1) ? decbin($byte ) : str_pad(decbin($byte), 8, '0', STR_PAD_LEFT)).$binstring;436 for ($i = 0; $i < count($bytes); $i++) { 437 $binstring = (($i == count($bytes) - 1) ? decbin($bytes[$i]) : str_pad(decbin($bytes[$i]), 8, '0', STR_PAD_LEFT)).$binstring; 444 438 } 445 439 return $binstring; … … 672 666 // $foo['path']['to']['my'] = 'file.txt'; 673 667 $ArrayPath = ltrim($ArrayPath, $Separator); 674 $ReturnedArray = array();675 668 if (($pos = strpos($ArrayPath, $Separator)) !== false) { 676 669 $ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value); … … 1546 1539 // Copy all entries from ['tags'] into common ['comments'] 1547 1540 if (!empty($ThisFileInfo['tags'])) { 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 } 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); 1563 1547 } 1564 1548 foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) { … … 1579 1563 break 2; 1580 1564 } 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 } 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; 1588 1571 } 1589 1572 } … … 1591 1574 } elseif (!is_array($value)) { 1592 1575 1593 $newvaluelength = strlen(trim($value)); 1594 $newvaluelengthMB = mb_strlen(trim($value)); 1576 $newvaluelength = strlen(trim($value)); 1595 1577 foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $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 } 1578 $oldvaluelength = strlen(trim($existingvalue)); 1605 1579 if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) { 1606 1580 $ThisFileInfo['comments'][$tagname][$existingkey] = trim($value); … … 1628 1602 1629 1603 // attempt to standardize spelling of returned keys 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 } 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]); 1640 1612 } 1641 1613 } … … 1763 1735 */ 1764 1736 public static function getFileSizeSyscall($path) { 1765 $commandline = null;1766 1737 $filesize = false; 1767 1738 … … 1825 1796 * @return string 1826 1797 */ 1827 public static function mb_basename($path, $suffix = '') {1798 public static function mb_basename($path, $suffix = null) { 1828 1799 $splited = preg_split('#/#', rtrim($path, '/ ')); 1829 1800 return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1);
Note: See TracChangeset
for help on using the changeset viewer.