Make WordPress Core


Ignore:
Timestamp:
07/31/2017 07:49:31 PM (9 years ago)
Author:
wonderboymusic
Message:

Media: update the getID3 library to version 1.9.14 to avoid fatal errors in PHP7.

Props MyThemeShop for the initial patch.
Fixes #41496.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ID3/getid3.lib.php

    r32979 r41196  
    294294        }
    295295
     296        public static function LittleEndian2Bin($byteword) {
     297                return self::BigEndian2Bin(strrev($byteword));
     298        }
    296299
    297300        public static function BigEndian2Bin($byteword) {
     
    413416                }
    414417                return $newarray;
     418        }
     419
     420        public static function flipped_array_merge_noclobber($array1, $array2) {
     421                if (!is_array($array1) || !is_array($array2)) {
     422                        return false;
     423                }
     424                # naturally, this only works non-recursively
     425                $newarray = array_flip($array1);
     426                foreach (array_flip($array2) as $key => $val) {
     427                        if (!isset($newarray[$key])) {
     428                                $newarray[$key] = count($newarray);
     429                        }
     430                }
     431                return array_flip($newarray);
    415432        }
    416433
     
    947964                }
    948965
     966                // mb_convert_encoding() availble
     967                if (function_exists('mb_convert_encoding')) {
     968                        if ($converted_string = @mb_convert_encoding($string, $out_charset, $in_charset)) {
     969                                switch ($out_charset) {
     970                                        case 'ISO-8859-1':
     971                                                $converted_string = rtrim($converted_string, "\x00");
     972                                                break;
     973                                }
     974                                return $converted_string;
     975                        }
     976                        return $string;
     977                }
    949978                // iconv() availble
    950                 if (function_exists('iconv')) {
     979                else if (function_exists('iconv')) {
    951980                        if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) {
    952981                                switch ($out_charset) {
     
    964993
    965994
    966                 // iconv() not available
     995                // neither mb_convert_encoding or iconv() is available
    967996                static $ConversionFunctionList = array();
    968997                if (empty($ConversionFunctionList)) {
     
    9861015                        return self::$ConversionFunction($string);
    9871016                }
    988                 throw new Exception('PHP does not have iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
     1017                throw new Exception('PHP does not has mb_convert_encoding() or iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
    9891018        }
    9901019
     
    10071036                $HTMLstring = '';
    10081037
    1009                 switch ($charset) {
     1038                switch (strtolower($charset)) {
    10101039                        case '1251':
    10111040                        case '1252':
     
    10141043                        case '936':
    10151044                        case '950':
    1016                         case 'BIG5':
    1017                         case 'BIG5-HKSCS':
     1045                        case 'big5':
     1046                        case 'big5-hkscs':
    10181047                        case 'cp1251':
    10191048                        case 'cp1252':
    10201049                        case 'cp866':
    1021                         case 'EUC-JP':
    1022                         case 'EUCJP':
    1023                         case 'GB2312':
     1050                        case 'euc-jp':
     1051                        case 'eucjp':
     1052                        case 'gb2312':
    10241053                        case 'ibm866':
    1025                         case 'ISO-8859-1':
    1026                         case 'ISO-8859-15':
    1027                         case 'ISO8859-1':
    1028                         case 'ISO8859-15':
    1029                         case 'KOI8-R':
     1054                        case 'iso-8859-1':
     1055                        case 'iso-8859-15':
     1056                        case 'iso8859-1':
     1057                        case 'iso8859-15':
     1058                        case 'koi8-r':
    10301059                        case 'koi8-ru':
    10311060                        case 'koi8r':
    1032                         case 'Shift_JIS':
    1033                         case 'SJIS':
     1061                        case 'shift_jis':
     1062                        case 'sjis':
    10341063                        case 'win-1251':
    1035                         case 'Windows-1251':
    1036                         case 'Windows-1252':
     1064                        case 'windows-1251':
     1065                        case 'windows-1252':
    10371066                                $HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
    10381067                                break;
    10391068
    1040                         case 'UTF-8':
     1069                        case 'utf-8':
    10411070                                $strlen = strlen($string);
    10421071                                for ($i = 0; $i < $strlen; $i++) {
     
    10661095                                break;
    10671096
    1068                         case 'UTF-16LE':
     1097                        case 'utf-16le':
    10691098                                for ($i = 0; $i < strlen($string); $i += 2) {
    10701099                                        $charval = self::LittleEndian2Int(substr($string, $i, 2));
     
    10771106                                break;
    10781107
    1079                         case 'UTF-16BE':
     1108                        case 'utf-16be':
    10801109                                for ($i = 0; $i < strlen($string); $i += 2) {
    10811110                                        $charval = self::BigEndian2Int(substr($string, $i, 2));
     
    11541183                static $tempdir = '';
    11551184                if (empty($tempdir)) {
     1185                        if (function_exists('sys_get_temp_dir')) {
     1186                                $tempdir = sys_get_temp_dir(); // https://github.com/JamesHeinrich/getID3/issues/52
     1187                        }
     1188
    11561189                        // yes this is ugly, feel free to suggest a better way
    1157                         require_once(dirname(__FILE__).'/getid3.php');
    1158                         $getid3_temp = new getID3();
    1159                         $tempdir = $getid3_temp->tempdir;
    1160                         unset($getid3_temp);
     1190                        if (include_once(dirname(__FILE__).'/getid3.php')) {
     1191                                if ($getid3_temp = new getID3()) {
     1192                                        if ($getid3_temp_tempdir = $getid3_temp->tempdir) {
     1193                                                $tempdir = $getid3_temp_tempdir;
     1194                                        }
     1195                                        unset($getid3_temp, $getid3_temp_tempdir);
     1196                                }
     1197                        }
    11611198                }
    11621199                $GetDataImageSize = false;
     
    11661203                                fclose($tmp);
    11671204                                $GetDataImageSize = @getimagesize($tempfilename, $imageinfo);
     1205                                if (($GetDataImageSize === false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) {
     1206                                        return false;
     1207                                }
    11681208                                $GetDataImageSize['height'] = $GetDataImageSize[0];
    11691209                                $GetDataImageSize['width']  = $GetDataImageSize[1];
     
    12381278                                                        if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
    12391279                                                                $value = (is_string($value) ? trim($value) : $value);
    1240                                                                 if (!is_numeric($key)) {
     1280                                                                if (!is_int($key) && !ctype_digit($key)) {
    12411281                                                                        $ThisFileInfo['comments'][$tagname][$key] = $value;
    12421282                                                                } else {
    1243                                                                         $ThisFileInfo['comments'][$tagname][]     = $value;
     1283                                                                        if (isset($ThisFileInfo['comments'][$tagname])) {
     1284                                                                                $ThisFileInfo['comments'][$tagname] = array($value);
     1285                                                                        } else {
     1286                                                                                $ThisFileInfo['comments'][$tagname][] = $value;
     1287                                                                        }
    12441288                                                                }
    12451289                                                        }
    12461290                                                }
    12471291                                        }
     1292                                }
     1293                        }
     1294
     1295                        // attempt to standardize spelling of returned keys
     1296                        $StandardizeFieldNames = array(
     1297                                'tracknumber' => 'track_number',
     1298                                'track'       => 'track_number',
     1299                        );
     1300                        foreach ($StandardizeFieldNames as $badkey => $goodkey) {
     1301                                if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) {
     1302                                        $ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey];
     1303                                        unset($ThisFileInfo['comments'][$badkey]);
    12481304                                }
    12491305                        }
Note: See TracChangeset for help on using the changeset viewer.