wp/wp-includes/SimplePie/src/Misc.php
changeset 22 8c2e4d02f4ef
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * SimplePie
       
     5  *
       
     6  * A PHP-Based RSS and Atom Feed Framework.
       
     7  * Takes the hard work out of managing a complete RSS/Atom solution.
       
     8  *
       
     9  * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
       
    10  * All rights reserved.
       
    11  *
       
    12  * Redistribution and use in source and binary forms, with or without modification, are
       
    13  * permitted provided that the following conditions are met:
       
    14  *
       
    15  * 	* Redistributions of source code must retain the above copyright notice, this list of
       
    16  * 	  conditions and the following disclaimer.
       
    17  *
       
    18  * 	* Redistributions in binary form must reproduce the above copyright notice, this list
       
    19  * 	  of conditions and the following disclaimer in the documentation and/or other materials
       
    20  * 	  provided with the distribution.
       
    21  *
       
    22  * 	* Neither the name of the SimplePie Team nor the names of its contributors may be used
       
    23  * 	  to endorse or promote products derived from this software without specific prior
       
    24  * 	  written permission.
       
    25  *
       
    26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
       
    27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
       
    28  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
       
    29  * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       
    30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
       
    31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
       
    33  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    34  * POSSIBILITY OF SUCH DAMAGE.
       
    35  *
       
    36  * @package SimplePie
       
    37  * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
       
    38  * @author Ryan Parman
       
    39  * @author Sam Sneddon
       
    40  * @author Ryan McCue
       
    41  * @link http://simplepie.org/ SimplePie
       
    42  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
       
    43  */
       
    44 
       
    45 namespace SimplePie;
       
    46 
       
    47 use SimplePie\XML\Declaration\Parser;
       
    48 
       
    49 /**
       
    50  * Miscellaneous utilities
       
    51  *
       
    52  * @package SimplePie
       
    53  */
       
    54 class Misc
       
    55 {
       
    56     private static $SIMPLEPIE_BUILD = null;
       
    57 
       
    58     public static function time_hms($seconds)
       
    59     {
       
    60         $time = '';
       
    61 
       
    62         $hours = floor($seconds / 3600);
       
    63         $remainder = $seconds % 3600;
       
    64         if ($hours > 0) {
       
    65             $time .= $hours.':';
       
    66         }
       
    67 
       
    68         $minutes = floor($remainder / 60);
       
    69         $seconds = $remainder % 60;
       
    70         if ($minutes < 10 && $hours > 0) {
       
    71             $minutes = '0' . $minutes;
       
    72         }
       
    73         if ($seconds < 10) {
       
    74             $seconds = '0' . $seconds;
       
    75         }
       
    76 
       
    77         $time .= $minutes.':';
       
    78         $time .= $seconds;
       
    79 
       
    80         return $time;
       
    81     }
       
    82 
       
    83     public static function absolutize_url($relative, $base)
       
    84     {
       
    85         $iri = \SimplePie\IRI::absolutize(new \SimplePie\IRI($base), $relative);
       
    86         if ($iri === false) {
       
    87             return false;
       
    88         }
       
    89         return $iri->get_uri();
       
    90     }
       
    91 
       
    92     /**
       
    93      * Get a HTML/XML element from a HTML string
       
    94      *
       
    95      * @deprecated since SimplePie 1.3, use DOMDocument instead (parsing HTML with regex is bad!)
       
    96      * @param string $realname Element name (including namespace prefix if applicable)
       
    97      * @param string $string HTML document
       
    98      * @return array
       
    99      */
       
   100     public static function get_element($realname, $string)
       
   101     {
       
   102         // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED);
       
   103 
       
   104         $return = [];
       
   105         $name = preg_quote($realname, '/');
       
   106         if (preg_match_all("/<($name)" . \SimplePie\SimplePie::PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
       
   107             for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++) {
       
   108                 $return[$i]['tag'] = $realname;
       
   109                 $return[$i]['full'] = $matches[$i][0][0];
       
   110                 $return[$i]['offset'] = $matches[$i][0][1];
       
   111                 if (strlen($matches[$i][3][0]) <= 2) {
       
   112                     $return[$i]['self_closing'] = true;
       
   113                 } else {
       
   114                     $return[$i]['self_closing'] = false;
       
   115                     $return[$i]['content'] = $matches[$i][4][0];
       
   116                 }
       
   117                 $return[$i]['attribs'] = [];
       
   118                 if (isset($matches[$i][2][0]) && preg_match_all('/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER)) {
       
   119                     for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++) {
       
   120                         if (count($attribs[$j]) === 2) {
       
   121                             $attribs[$j][2] = $attribs[$j][1];
       
   122                         }
       
   123                         $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = Misc::entities_decode(end($attribs[$j]));
       
   124                     }
       
   125                 }
       
   126             }
       
   127         }
       
   128         return $return;
       
   129     }
       
   130 
       
   131     public static function element_implode($element)
       
   132     {
       
   133         $full = "<$element[tag]";
       
   134         foreach ($element['attribs'] as $key => $value) {
       
   135             $key = strtolower($key);
       
   136             $full .= " $key=\"" . htmlspecialchars($value['data'], ENT_COMPAT, 'UTF-8') . '"';
       
   137         }
       
   138         if ($element['self_closing']) {
       
   139             $full .= ' />';
       
   140         } else {
       
   141             $full .= ">$element[content]</$element[tag]>";
       
   142         }
       
   143         return $full;
       
   144     }
       
   145 
       
   146     public static function error($message, $level, $file, $line)
       
   147     {
       
   148         if ((error_reporting() & $level) > 0) {
       
   149             switch ($level) {
       
   150                 case E_USER_ERROR:
       
   151                     $note = 'PHP Error';
       
   152                     break;
       
   153                 case E_USER_WARNING:
       
   154                     $note = 'PHP Warning';
       
   155                     break;
       
   156                 case E_USER_NOTICE:
       
   157                     $note = 'PHP Notice';
       
   158                     break;
       
   159                 default:
       
   160                     $note = 'Unknown Error';
       
   161                     break;
       
   162             }
       
   163 
       
   164             $log_error = true;
       
   165             if (!function_exists('error_log')) {
       
   166                 $log_error = false;
       
   167             }
       
   168 
       
   169             $log_file = @ini_get('error_log');
       
   170             if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file)) {
       
   171                 $log_error = false;
       
   172             }
       
   173 
       
   174             if ($log_error) {
       
   175                 @error_log("$note: $message in $file on line $line", 0);
       
   176             }
       
   177         }
       
   178 
       
   179         return $message;
       
   180     }
       
   181 
       
   182     public static function fix_protocol($url, $http = 1)
       
   183     {
       
   184         $url = Misc::normalize_url($url);
       
   185         $parsed = Misc::parse_url($url);
       
   186         if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https') {
       
   187             return Misc::fix_protocol(Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
       
   188         }
       
   189 
       
   190         if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url)) {
       
   191             return Misc::fix_protocol(Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
       
   192         }
       
   193 
       
   194         if ($http === 2 && $parsed['scheme'] !== '') {
       
   195             return "feed:$url";
       
   196         } elseif ($http === 3 && strtolower($parsed['scheme']) === 'http') {
       
   197             return substr_replace($url, 'podcast', 0, 4);
       
   198         } elseif ($http === 4 && strtolower($parsed['scheme']) === 'http') {
       
   199             return substr_replace($url, 'itpc', 0, 4);
       
   200         }
       
   201 
       
   202         return $url;
       
   203     }
       
   204 
       
   205     /**
       
   206      * @deprecated since SimplePie 1.8.0, use PHP native array_replace_recursive() instead.
       
   207      */
       
   208     public static function array_merge_recursive($array1, $array2)
       
   209     {
       
   210         foreach ($array2 as $key => $value) {
       
   211             if (is_array($value)) {
       
   212                 $array1[$key] = Misc::array_merge_recursive($array1[$key], $value);
       
   213             } else {
       
   214                 $array1[$key] = $value;
       
   215             }
       
   216         }
       
   217 
       
   218         return $array1;
       
   219     }
       
   220 
       
   221     public static function parse_url($url)
       
   222     {
       
   223         $iri = new \SimplePie\IRI($url);
       
   224         return [
       
   225             'scheme' => (string) $iri->scheme,
       
   226             'authority' => (string) $iri->authority,
       
   227             'path' => (string) $iri->path,
       
   228             'query' => (string) $iri->query,
       
   229             'fragment' => (string) $iri->fragment
       
   230         ];
       
   231     }
       
   232 
       
   233     public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
       
   234     {
       
   235         $iri = new \SimplePie\IRI('');
       
   236         $iri->scheme = $scheme;
       
   237         $iri->authority = $authority;
       
   238         $iri->path = $path;
       
   239         $iri->query = $query;
       
   240         $iri->fragment = $fragment;
       
   241         return $iri->get_uri();
       
   242     }
       
   243 
       
   244     public static function normalize_url($url)
       
   245     {
       
   246         $iri = new \SimplePie\IRI($url);
       
   247         return $iri->get_uri();
       
   248     }
       
   249 
       
   250     public static function percent_encoding_normalization($match)
       
   251     {
       
   252         $integer = hexdec($match[1]);
       
   253         if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E) {
       
   254             return chr($integer);
       
   255         }
       
   256 
       
   257         return strtoupper($match[0]);
       
   258     }
       
   259 
       
   260     /**
       
   261      * Converts a Windows-1252 encoded string to a UTF-8 encoded string
       
   262      *
       
   263      * @static
       
   264      * @param string $string Windows-1252 encoded string
       
   265      * @return string UTF-8 encoded string
       
   266      */
       
   267     public static function windows_1252_to_utf8($string)
       
   268     {
       
   269         static $convert_table = ["\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF"];
       
   270 
       
   271         return strtr($string, $convert_table);
       
   272     }
       
   273 
       
   274     /**
       
   275      * Change a string from one encoding to another
       
   276      *
       
   277      * @param string $data Raw data in $input encoding
       
   278      * @param string $input Encoding of $data
       
   279      * @param string $output Encoding you want
       
   280      * @return string|boolean False if we can't convert it
       
   281      */
       
   282     public static function change_encoding($data, $input, $output)
       
   283     {
       
   284         $input = Misc::encoding($input);
       
   285         $output = Misc::encoding($output);
       
   286 
       
   287         // We fail to fail on non US-ASCII bytes
       
   288         if ($input === 'US-ASCII') {
       
   289             static $non_ascii_octects = '';
       
   290             if (!$non_ascii_octects) {
       
   291                 for ($i = 0x80; $i <= 0xFF; $i++) {
       
   292                     $non_ascii_octects .= chr($i);
       
   293                 }
       
   294             }
       
   295             $data = substr($data, 0, strcspn($data, $non_ascii_octects));
       
   296         }
       
   297 
       
   298         // This is first, as behaviour of this is completely predictable
       
   299         if ($input === 'windows-1252' && $output === 'UTF-8') {
       
   300             return Misc::windows_1252_to_utf8($data);
       
   301         }
       
   302         // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
       
   303         elseif (function_exists('mb_convert_encoding') && ($return = Misc::change_encoding_mbstring($data, $input, $output))) {
       
   304             return $return;
       
   305         }
       
   306         // This is third, as behaviour of this varies with OS userland and PHP version
       
   307         elseif (function_exists('iconv') && ($return = Misc::change_encoding_iconv($data, $input, $output))) {
       
   308             return $return;
       
   309         }
       
   310         // This is last, as behaviour of this varies with OS userland and PHP version
       
   311         elseif (class_exists('\UConverter') && ($return = Misc::change_encoding_uconverter($data, $input, $output))) {
       
   312             return $return;
       
   313         }
       
   314 
       
   315         // If we can't do anything, just fail
       
   316         return false;
       
   317     }
       
   318 
       
   319     protected static function change_encoding_mbstring($data, $input, $output)
       
   320     {
       
   321         if ($input === 'windows-949') {
       
   322             $input = 'EUC-KR';
       
   323         }
       
   324         if ($output === 'windows-949') {
       
   325             $output = 'EUC-KR';
       
   326         }
       
   327         if ($input === 'Windows-31J') {
       
   328             $input = 'SJIS';
       
   329         }
       
   330         if ($output === 'Windows-31J') {
       
   331             $output = 'SJIS';
       
   332         }
       
   333 
       
   334         // Check that the encoding is supported
       
   335         if (!in_array($input, mb_list_encodings())) {
       
   336             return false;
       
   337         }
       
   338 
       
   339         if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80") {
       
   340             return false;
       
   341         }
       
   342 
       
   343         // Let's do some conversion
       
   344         if ($return = @mb_convert_encoding($data, $output, $input)) {
       
   345             return $return;
       
   346         }
       
   347 
       
   348         return false;
       
   349     }
       
   350 
       
   351     protected static function change_encoding_iconv($data, $input, $output)
       
   352     {
       
   353         return @iconv($input, $output, $data);
       
   354     }
       
   355 
       
   356     /**
       
   357      * @param string $data
       
   358      * @param string $input
       
   359      * @param string $output
       
   360      * @return string|false
       
   361      */
       
   362     protected static function change_encoding_uconverter($data, $input, $output)
       
   363     {
       
   364         return @\UConverter::transcode($data, $output, $input);
       
   365     }
       
   366 
       
   367     /**
       
   368      * Normalize an encoding name
       
   369      *
       
   370      * This is automatically generated by create.php
       
   371      *
       
   372      * To generate it, run `php create.php` on the command line, and copy the
       
   373      * output to replace this function.
       
   374      *
       
   375      * @param string $charset Character set to standardise
       
   376      * @return string Standardised name
       
   377      */
       
   378     public static function encoding($charset)
       
   379     {
       
   380         // Normalization from UTS #22
       
   381         switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset))) {
       
   382             case 'adobestandardencoding':
       
   383             case 'csadobestandardencoding':
       
   384                 return 'Adobe-Standard-Encoding';
       
   385 
       
   386             case 'adobesymbolencoding':
       
   387             case 'cshppsmath':
       
   388                 return 'Adobe-Symbol-Encoding';
       
   389 
       
   390             case 'ami1251':
       
   391             case 'amiga1251':
       
   392                 return 'Amiga-1251';
       
   393 
       
   394             case 'ansix31101983':
       
   395             case 'csat5001983':
       
   396             case 'csiso99naplps':
       
   397             case 'isoir99':
       
   398             case 'naplps':
       
   399                 return 'ANSI_X3.110-1983';
       
   400 
       
   401             case 'arabic7':
       
   402             case 'asmo449':
       
   403             case 'csiso89asmo449':
       
   404             case 'iso9036':
       
   405             case 'isoir89':
       
   406                 return 'ASMO_449';
       
   407 
       
   408             case 'big5':
       
   409             case 'csbig5':
       
   410                 return 'Big5';
       
   411 
       
   412             case 'big5hkscs':
       
   413                 return 'Big5-HKSCS';
       
   414 
       
   415             case 'bocu1':
       
   416             case 'csbocu1':
       
   417                 return 'BOCU-1';
       
   418 
       
   419             case 'brf':
       
   420             case 'csbrf':
       
   421                 return 'BRF';
       
   422 
       
   423             case 'bs4730':
       
   424             case 'csiso4unitedkingdom':
       
   425             case 'gb':
       
   426             case 'iso646gb':
       
   427             case 'isoir4':
       
   428             case 'uk':
       
   429                 return 'BS_4730';
       
   430 
       
   431             case 'bsviewdata':
       
   432             case 'csiso47bsviewdata':
       
   433             case 'isoir47':
       
   434                 return 'BS_viewdata';
       
   435 
       
   436             case 'cesu8':
       
   437             case 'cscesu8':
       
   438                 return 'CESU-8';
       
   439 
       
   440             case 'ca':
       
   441             case 'csa71':
       
   442             case 'csaz243419851':
       
   443             case 'csiso121canadian1':
       
   444             case 'iso646ca':
       
   445             case 'isoir121':
       
   446                 return 'CSA_Z243.4-1985-1';
       
   447 
       
   448             case 'csa72':
       
   449             case 'csaz243419852':
       
   450             case 'csiso122canadian2':
       
   451             case 'iso646ca2':
       
   452             case 'isoir122':
       
   453                 return 'CSA_Z243.4-1985-2';
       
   454 
       
   455             case 'csaz24341985gr':
       
   456             case 'csiso123csaz24341985gr':
       
   457             case 'isoir123':
       
   458                 return 'CSA_Z243.4-1985-gr';
       
   459 
       
   460             case 'csiso139csn369103':
       
   461             case 'csn369103':
       
   462             case 'isoir139':
       
   463                 return 'CSN_369103';
       
   464 
       
   465             case 'csdecmcs':
       
   466             case 'dec':
       
   467             case 'decmcs':
       
   468                 return 'DEC-MCS';
       
   469 
       
   470             case 'csiso21german':
       
   471             case 'de':
       
   472             case 'din66003':
       
   473             case 'iso646de':
       
   474             case 'isoir21':
       
   475                 return 'DIN_66003';
       
   476 
       
   477             case 'csdkus':
       
   478             case 'dkus':
       
   479                 return 'dk-us';
       
   480 
       
   481             case 'csiso646danish':
       
   482             case 'dk':
       
   483             case 'ds2089':
       
   484             case 'iso646dk':
       
   485                 return 'DS_2089';
       
   486 
       
   487             case 'csibmebcdicatde':
       
   488             case 'ebcdicatde':
       
   489                 return 'EBCDIC-AT-DE';
       
   490 
       
   491             case 'csebcdicatdea':
       
   492             case 'ebcdicatdea':
       
   493                 return 'EBCDIC-AT-DE-A';
       
   494 
       
   495             case 'csebcdiccafr':
       
   496             case 'ebcdiccafr':
       
   497                 return 'EBCDIC-CA-FR';
       
   498 
       
   499             case 'csebcdicdkno':
       
   500             case 'ebcdicdkno':
       
   501                 return 'EBCDIC-DK-NO';
       
   502 
       
   503             case 'csebcdicdknoa':
       
   504             case 'ebcdicdknoa':
       
   505                 return 'EBCDIC-DK-NO-A';
       
   506 
       
   507             case 'csebcdices':
       
   508             case 'ebcdices':
       
   509                 return 'EBCDIC-ES';
       
   510 
       
   511             case 'csebcdicesa':
       
   512             case 'ebcdicesa':
       
   513                 return 'EBCDIC-ES-A';
       
   514 
       
   515             case 'csebcdicess':
       
   516             case 'ebcdicess':
       
   517                 return 'EBCDIC-ES-S';
       
   518 
       
   519             case 'csebcdicfise':
       
   520             case 'ebcdicfise':
       
   521                 return 'EBCDIC-FI-SE';
       
   522 
       
   523             case 'csebcdicfisea':
       
   524             case 'ebcdicfisea':
       
   525                 return 'EBCDIC-FI-SE-A';
       
   526 
       
   527             case 'csebcdicfr':
       
   528             case 'ebcdicfr':
       
   529                 return 'EBCDIC-FR';
       
   530 
       
   531             case 'csebcdicit':
       
   532             case 'ebcdicit':
       
   533                 return 'EBCDIC-IT';
       
   534 
       
   535             case 'csebcdicpt':
       
   536             case 'ebcdicpt':
       
   537                 return 'EBCDIC-PT';
       
   538 
       
   539             case 'csebcdicuk':
       
   540             case 'ebcdicuk':
       
   541                 return 'EBCDIC-UK';
       
   542 
       
   543             case 'csebcdicus':
       
   544             case 'ebcdicus':
       
   545                 return 'EBCDIC-US';
       
   546 
       
   547             case 'csiso111ecmacyrillic':
       
   548             case 'ecmacyrillic':
       
   549             case 'isoir111':
       
   550             case 'koi8e':
       
   551                 return 'ECMA-cyrillic';
       
   552 
       
   553             case 'csiso17spanish':
       
   554             case 'es':
       
   555             case 'iso646es':
       
   556             case 'isoir17':
       
   557                 return 'ES';
       
   558 
       
   559             case 'csiso85spanish2':
       
   560             case 'es2':
       
   561             case 'iso646es2':
       
   562             case 'isoir85':
       
   563                 return 'ES2';
       
   564 
       
   565             case 'cseucpkdfmtjapanese':
       
   566             case 'eucjp':
       
   567             case 'extendedunixcodepackedformatforjapanese':
       
   568                 return 'EUC-JP';
       
   569 
       
   570             case 'cseucfixwidjapanese':
       
   571             case 'extendedunixcodefixedwidthforjapanese':
       
   572                 return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
       
   573 
       
   574             case 'gb18030':
       
   575                 return 'GB18030';
       
   576 
       
   577             case 'chinese':
       
   578             case 'cp936':
       
   579             case 'csgb2312':
       
   580             case 'csiso58gb231280':
       
   581             case 'gb2312':
       
   582             case 'gb231280':
       
   583             case 'gbk':
       
   584             case 'isoir58':
       
   585             case 'ms936':
       
   586             case 'windows936':
       
   587                 return 'GBK';
       
   588 
       
   589             case 'cn':
       
   590             case 'csiso57gb1988':
       
   591             case 'gb198880':
       
   592             case 'iso646cn':
       
   593             case 'isoir57':
       
   594                 return 'GB_1988-80';
       
   595 
       
   596             case 'csiso153gost1976874':
       
   597             case 'gost1976874':
       
   598             case 'isoir153':
       
   599             case 'stsev35888':
       
   600                 return 'GOST_19768-74';
       
   601 
       
   602             case 'csiso150':
       
   603             case 'csiso150greekccitt':
       
   604             case 'greekccitt':
       
   605             case 'isoir150':
       
   606                 return 'greek-ccitt';
       
   607 
       
   608             case 'csiso88greek7':
       
   609             case 'greek7':
       
   610             case 'isoir88':
       
   611                 return 'greek7';
       
   612 
       
   613             case 'csiso18greek7old':
       
   614             case 'greek7old':
       
   615             case 'isoir18':
       
   616                 return 'greek7-old';
       
   617 
       
   618             case 'cshpdesktop':
       
   619             case 'hpdesktop':
       
   620                 return 'HP-DeskTop';
       
   621 
       
   622             case 'cshplegal':
       
   623             case 'hplegal':
       
   624                 return 'HP-Legal';
       
   625 
       
   626             case 'cshpmath8':
       
   627             case 'hpmath8':
       
   628                 return 'HP-Math8';
       
   629 
       
   630             case 'cshppifont':
       
   631             case 'hppifont':
       
   632                 return 'HP-Pi-font';
       
   633 
       
   634             case 'cshproman8':
       
   635             case 'hproman8':
       
   636             case 'r8':
       
   637             case 'roman8':
       
   638                 return 'hp-roman8';
       
   639 
       
   640             case 'hzgb2312':
       
   641                 return 'HZ-GB-2312';
       
   642 
       
   643             case 'csibmsymbols':
       
   644             case 'ibmsymbols':
       
   645                 return 'IBM-Symbols';
       
   646 
       
   647             case 'csibmthai':
       
   648             case 'ibmthai':
       
   649                 return 'IBM-Thai';
       
   650 
       
   651             case 'cp37':
       
   652             case 'csibm37':
       
   653             case 'ebcdiccpca':
       
   654             case 'ebcdiccpnl':
       
   655             case 'ebcdiccpus':
       
   656             case 'ebcdiccpwt':
       
   657             case 'ibm37':
       
   658                 return 'IBM037';
       
   659 
       
   660             case 'cp38':
       
   661             case 'csibm38':
       
   662             case 'ebcdicint':
       
   663             case 'ibm38':
       
   664                 return 'IBM038';
       
   665 
       
   666             case 'cp273':
       
   667             case 'csibm273':
       
   668             case 'ibm273':
       
   669                 return 'IBM273';
       
   670 
       
   671             case 'cp274':
       
   672             case 'csibm274':
       
   673             case 'ebcdicbe':
       
   674             case 'ibm274':
       
   675                 return 'IBM274';
       
   676 
       
   677             case 'cp275':
       
   678             case 'csibm275':
       
   679             case 'ebcdicbr':
       
   680             case 'ibm275':
       
   681                 return 'IBM275';
       
   682 
       
   683             case 'csibm277':
       
   684             case 'ebcdiccpdk':
       
   685             case 'ebcdiccpno':
       
   686             case 'ibm277':
       
   687                 return 'IBM277';
       
   688 
       
   689             case 'cp278':
       
   690             case 'csibm278':
       
   691             case 'ebcdiccpfi':
       
   692             case 'ebcdiccpse':
       
   693             case 'ibm278':
       
   694                 return 'IBM278';
       
   695 
       
   696             case 'cp280':
       
   697             case 'csibm280':
       
   698             case 'ebcdiccpit':
       
   699             case 'ibm280':
       
   700                 return 'IBM280';
       
   701 
       
   702             case 'cp281':
       
   703             case 'csibm281':
       
   704             case 'ebcdicjpe':
       
   705             case 'ibm281':
       
   706                 return 'IBM281';
       
   707 
       
   708             case 'cp284':
       
   709             case 'csibm284':
       
   710             case 'ebcdiccpes':
       
   711             case 'ibm284':
       
   712                 return 'IBM284';
       
   713 
       
   714             case 'cp285':
       
   715             case 'csibm285':
       
   716             case 'ebcdiccpgb':
       
   717             case 'ibm285':
       
   718                 return 'IBM285';
       
   719 
       
   720             case 'cp290':
       
   721             case 'csibm290':
       
   722             case 'ebcdicjpkana':
       
   723             case 'ibm290':
       
   724                 return 'IBM290';
       
   725 
       
   726             case 'cp297':
       
   727             case 'csibm297':
       
   728             case 'ebcdiccpfr':
       
   729             case 'ibm297':
       
   730                 return 'IBM297';
       
   731 
       
   732             case 'cp420':
       
   733             case 'csibm420':
       
   734             case 'ebcdiccpar1':
       
   735             case 'ibm420':
       
   736                 return 'IBM420';
       
   737 
       
   738             case 'cp423':
       
   739             case 'csibm423':
       
   740             case 'ebcdiccpgr':
       
   741             case 'ibm423':
       
   742                 return 'IBM423';
       
   743 
       
   744             case 'cp424':
       
   745             case 'csibm424':
       
   746             case 'ebcdiccphe':
       
   747             case 'ibm424':
       
   748                 return 'IBM424';
       
   749 
       
   750             case '437':
       
   751             case 'cp437':
       
   752             case 'cspc8codepage437':
       
   753             case 'ibm437':
       
   754                 return 'IBM437';
       
   755 
       
   756             case 'cp500':
       
   757             case 'csibm500':
       
   758             case 'ebcdiccpbe':
       
   759             case 'ebcdiccpch':
       
   760             case 'ibm500':
       
   761                 return 'IBM500';
       
   762 
       
   763             case 'cp775':
       
   764             case 'cspc775baltic':
       
   765             case 'ibm775':
       
   766                 return 'IBM775';
       
   767 
       
   768             case '850':
       
   769             case 'cp850':
       
   770             case 'cspc850multilingual':
       
   771             case 'ibm850':
       
   772                 return 'IBM850';
       
   773 
       
   774             case '851':
       
   775             case 'cp851':
       
   776             case 'csibm851':
       
   777             case 'ibm851':
       
   778                 return 'IBM851';
       
   779 
       
   780             case '852':
       
   781             case 'cp852':
       
   782             case 'cspcp852':
       
   783             case 'ibm852':
       
   784                 return 'IBM852';
       
   785 
       
   786             case '855':
       
   787             case 'cp855':
       
   788             case 'csibm855':
       
   789             case 'ibm855':
       
   790                 return 'IBM855';
       
   791 
       
   792             case '857':
       
   793             case 'cp857':
       
   794             case 'csibm857':
       
   795             case 'ibm857':
       
   796                 return 'IBM857';
       
   797 
       
   798             case 'ccsid858':
       
   799             case 'cp858':
       
   800             case 'ibm858':
       
   801             case 'pcmultilingual850euro':
       
   802                 return 'IBM00858';
       
   803 
       
   804             case '860':
       
   805             case 'cp860':
       
   806             case 'csibm860':
       
   807             case 'ibm860':
       
   808                 return 'IBM860';
       
   809 
       
   810             case '861':
       
   811             case 'cp861':
       
   812             case 'cpis':
       
   813             case 'csibm861':
       
   814             case 'ibm861':
       
   815                 return 'IBM861';
       
   816 
       
   817             case '862':
       
   818             case 'cp862':
       
   819             case 'cspc862latinhebrew':
       
   820             case 'ibm862':
       
   821                 return 'IBM862';
       
   822 
       
   823             case '863':
       
   824             case 'cp863':
       
   825             case 'csibm863':
       
   826             case 'ibm863':
       
   827                 return 'IBM863';
       
   828 
       
   829             case 'cp864':
       
   830             case 'csibm864':
       
   831             case 'ibm864':
       
   832                 return 'IBM864';
       
   833 
       
   834             case '865':
       
   835             case 'cp865':
       
   836             case 'csibm865':
       
   837             case 'ibm865':
       
   838                 return 'IBM865';
       
   839 
       
   840             case '866':
       
   841             case 'cp866':
       
   842             case 'csibm866':
       
   843             case 'ibm866':
       
   844                 return 'IBM866';
       
   845 
       
   846             case 'cp868':
       
   847             case 'cpar':
       
   848             case 'csibm868':
       
   849             case 'ibm868':
       
   850                 return 'IBM868';
       
   851 
       
   852             case '869':
       
   853             case 'cp869':
       
   854             case 'cpgr':
       
   855             case 'csibm869':
       
   856             case 'ibm869':
       
   857                 return 'IBM869';
       
   858 
       
   859             case 'cp870':
       
   860             case 'csibm870':
       
   861             case 'ebcdiccproece':
       
   862             case 'ebcdiccpyu':
       
   863             case 'ibm870':
       
   864                 return 'IBM870';
       
   865 
       
   866             case 'cp871':
       
   867             case 'csibm871':
       
   868             case 'ebcdiccpis':
       
   869             case 'ibm871':
       
   870                 return 'IBM871';
       
   871 
       
   872             case 'cp880':
       
   873             case 'csibm880':
       
   874             case 'ebcdiccyrillic':
       
   875             case 'ibm880':
       
   876                 return 'IBM880';
       
   877 
       
   878             case 'cp891':
       
   879             case 'csibm891':
       
   880             case 'ibm891':
       
   881                 return 'IBM891';
       
   882 
       
   883             case 'cp903':
       
   884             case 'csibm903':
       
   885             case 'ibm903':
       
   886                 return 'IBM903';
       
   887 
       
   888             case '904':
       
   889             case 'cp904':
       
   890             case 'csibbm904':
       
   891             case 'ibm904':
       
   892                 return 'IBM904';
       
   893 
       
   894             case 'cp905':
       
   895             case 'csibm905':
       
   896             case 'ebcdiccptr':
       
   897             case 'ibm905':
       
   898                 return 'IBM905';
       
   899 
       
   900             case 'cp918':
       
   901             case 'csibm918':
       
   902             case 'ebcdiccpar2':
       
   903             case 'ibm918':
       
   904                 return 'IBM918';
       
   905 
       
   906             case 'ccsid924':
       
   907             case 'cp924':
       
   908             case 'ebcdiclatin9euro':
       
   909             case 'ibm924':
       
   910                 return 'IBM00924';
       
   911 
       
   912             case 'cp1026':
       
   913             case 'csibm1026':
       
   914             case 'ibm1026':
       
   915                 return 'IBM1026';
       
   916 
       
   917             case 'ibm1047':
       
   918                 return 'IBM1047';
       
   919 
       
   920             case 'ccsid1140':
       
   921             case 'cp1140':
       
   922             case 'ebcdicus37euro':
       
   923             case 'ibm1140':
       
   924                 return 'IBM01140';
       
   925 
       
   926             case 'ccsid1141':
       
   927             case 'cp1141':
       
   928             case 'ebcdicde273euro':
       
   929             case 'ibm1141':
       
   930                 return 'IBM01141';
       
   931 
       
   932             case 'ccsid1142':
       
   933             case 'cp1142':
       
   934             case 'ebcdicdk277euro':
       
   935             case 'ebcdicno277euro':
       
   936             case 'ibm1142':
       
   937                 return 'IBM01142';
       
   938 
       
   939             case 'ccsid1143':
       
   940             case 'cp1143':
       
   941             case 'ebcdicfi278euro':
       
   942             case 'ebcdicse278euro':
       
   943             case 'ibm1143':
       
   944                 return 'IBM01143';
       
   945 
       
   946             case 'ccsid1144':
       
   947             case 'cp1144':
       
   948             case 'ebcdicit280euro':
       
   949             case 'ibm1144':
       
   950                 return 'IBM01144';
       
   951 
       
   952             case 'ccsid1145':
       
   953             case 'cp1145':
       
   954             case 'ebcdices284euro':
       
   955             case 'ibm1145':
       
   956                 return 'IBM01145';
       
   957 
       
   958             case 'ccsid1146':
       
   959             case 'cp1146':
       
   960             case 'ebcdicgb285euro':
       
   961             case 'ibm1146':
       
   962                 return 'IBM01146';
       
   963 
       
   964             case 'ccsid1147':
       
   965             case 'cp1147':
       
   966             case 'ebcdicfr297euro':
       
   967             case 'ibm1147':
       
   968                 return 'IBM01147';
       
   969 
       
   970             case 'ccsid1148':
       
   971             case 'cp1148':
       
   972             case 'ebcdicinternational500euro':
       
   973             case 'ibm1148':
       
   974                 return 'IBM01148';
       
   975 
       
   976             case 'ccsid1149':
       
   977             case 'cp1149':
       
   978             case 'ebcdicis871euro':
       
   979             case 'ibm1149':
       
   980                 return 'IBM01149';
       
   981 
       
   982             case 'csiso143iecp271':
       
   983             case 'iecp271':
       
   984             case 'isoir143':
       
   985                 return 'IEC_P27-1';
       
   986 
       
   987             case 'csiso49inis':
       
   988             case 'inis':
       
   989             case 'isoir49':
       
   990                 return 'INIS';
       
   991 
       
   992             case 'csiso50inis8':
       
   993             case 'inis8':
       
   994             case 'isoir50':
       
   995                 return 'INIS-8';
       
   996 
       
   997             case 'csiso51iniscyrillic':
       
   998             case 'iniscyrillic':
       
   999             case 'isoir51':
       
  1000                 return 'INIS-cyrillic';
       
  1001 
       
  1002             case 'csinvariant':
       
  1003             case 'invariant':
       
  1004                 return 'INVARIANT';
       
  1005 
       
  1006             case 'iso2022cn':
       
  1007                 return 'ISO-2022-CN';
       
  1008 
       
  1009             case 'iso2022cnext':
       
  1010                 return 'ISO-2022-CN-EXT';
       
  1011 
       
  1012             case 'csiso2022jp':
       
  1013             case 'iso2022jp':
       
  1014                 return 'ISO-2022-JP';
       
  1015 
       
  1016             case 'csiso2022jp2':
       
  1017             case 'iso2022jp2':
       
  1018                 return 'ISO-2022-JP-2';
       
  1019 
       
  1020             case 'csiso2022kr':
       
  1021             case 'iso2022kr':
       
  1022                 return 'ISO-2022-KR';
       
  1023 
       
  1024             case 'cswindows30latin1':
       
  1025             case 'iso88591windows30latin1':
       
  1026                 return 'ISO-8859-1-Windows-3.0-Latin-1';
       
  1027 
       
  1028             case 'cswindows31latin1':
       
  1029             case 'iso88591windows31latin1':
       
  1030                 return 'ISO-8859-1-Windows-3.1-Latin-1';
       
  1031 
       
  1032             case 'csisolatin2':
       
  1033             case 'iso88592':
       
  1034             case 'iso885921987':
       
  1035             case 'isoir101':
       
  1036             case 'l2':
       
  1037             case 'latin2':
       
  1038                 return 'ISO-8859-2';
       
  1039 
       
  1040             case 'cswindows31latin2':
       
  1041             case 'iso88592windowslatin2':
       
  1042                 return 'ISO-8859-2-Windows-Latin-2';
       
  1043 
       
  1044             case 'csisolatin3':
       
  1045             case 'iso88593':
       
  1046             case 'iso885931988':
       
  1047             case 'isoir109':
       
  1048             case 'l3':
       
  1049             case 'latin3':
       
  1050                 return 'ISO-8859-3';
       
  1051 
       
  1052             case 'csisolatin4':
       
  1053             case 'iso88594':
       
  1054             case 'iso885941988':
       
  1055             case 'isoir110':
       
  1056             case 'l4':
       
  1057             case 'latin4':
       
  1058                 return 'ISO-8859-4';
       
  1059 
       
  1060             case 'csisolatincyrillic':
       
  1061             case 'cyrillic':
       
  1062             case 'iso88595':
       
  1063             case 'iso885951988':
       
  1064             case 'isoir144':
       
  1065                 return 'ISO-8859-5';
       
  1066 
       
  1067             case 'arabic':
       
  1068             case 'asmo708':
       
  1069             case 'csisolatinarabic':
       
  1070             case 'ecma114':
       
  1071             case 'iso88596':
       
  1072             case 'iso885961987':
       
  1073             case 'isoir127':
       
  1074                 return 'ISO-8859-6';
       
  1075 
       
  1076             case 'csiso88596e':
       
  1077             case 'iso88596e':
       
  1078                 return 'ISO-8859-6-E';
       
  1079 
       
  1080             case 'csiso88596i':
       
  1081             case 'iso88596i':
       
  1082                 return 'ISO-8859-6-I';
       
  1083 
       
  1084             case 'csisolatingreek':
       
  1085             case 'ecma118':
       
  1086             case 'elot928':
       
  1087             case 'greek':
       
  1088             case 'greek8':
       
  1089             case 'iso88597':
       
  1090             case 'iso885971987':
       
  1091             case 'isoir126':
       
  1092                 return 'ISO-8859-7';
       
  1093 
       
  1094             case 'csisolatinhebrew':
       
  1095             case 'hebrew':
       
  1096             case 'iso88598':
       
  1097             case 'iso885981988':
       
  1098             case 'isoir138':
       
  1099                 return 'ISO-8859-8';
       
  1100 
       
  1101             case 'csiso88598e':
       
  1102             case 'iso88598e':
       
  1103                 return 'ISO-8859-8-E';
       
  1104 
       
  1105             case 'csiso88598i':
       
  1106             case 'iso88598i':
       
  1107                 return 'ISO-8859-8-I';
       
  1108 
       
  1109             case 'cswindows31latin5':
       
  1110             case 'iso88599windowslatin5':
       
  1111                 return 'ISO-8859-9-Windows-Latin-5';
       
  1112 
       
  1113             case 'csisolatin6':
       
  1114             case 'iso885910':
       
  1115             case 'iso8859101992':
       
  1116             case 'isoir157':
       
  1117             case 'l6':
       
  1118             case 'latin6':
       
  1119                 return 'ISO-8859-10';
       
  1120 
       
  1121             case 'iso885913':
       
  1122                 return 'ISO-8859-13';
       
  1123 
       
  1124             case 'iso885914':
       
  1125             case 'iso8859141998':
       
  1126             case 'isoceltic':
       
  1127             case 'isoir199':
       
  1128             case 'l8':
       
  1129             case 'latin8':
       
  1130                 return 'ISO-8859-14';
       
  1131 
       
  1132             case 'iso885915':
       
  1133             case 'latin9':
       
  1134                 return 'ISO-8859-15';
       
  1135 
       
  1136             case 'iso885916':
       
  1137             case 'iso8859162001':
       
  1138             case 'isoir226':
       
  1139             case 'l10':
       
  1140             case 'latin10':
       
  1141                 return 'ISO-8859-16';
       
  1142 
       
  1143             case 'iso10646j1':
       
  1144                 return 'ISO-10646-J-1';
       
  1145 
       
  1146             case 'csunicode':
       
  1147             case 'iso10646ucs2':
       
  1148                 return 'ISO-10646-UCS-2';
       
  1149 
       
  1150             case 'csucs4':
       
  1151             case 'iso10646ucs4':
       
  1152                 return 'ISO-10646-UCS-4';
       
  1153 
       
  1154             case 'csunicodeascii':
       
  1155             case 'iso10646ucsbasic':
       
  1156                 return 'ISO-10646-UCS-Basic';
       
  1157 
       
  1158             case 'csunicodelatin1':
       
  1159             case 'iso10646':
       
  1160             case 'iso10646unicodelatin1':
       
  1161                 return 'ISO-10646-Unicode-Latin1';
       
  1162 
       
  1163             case 'csiso10646utf1':
       
  1164             case 'iso10646utf1':
       
  1165                 return 'ISO-10646-UTF-1';
       
  1166 
       
  1167             case 'csiso115481':
       
  1168             case 'iso115481':
       
  1169             case 'isotr115481':
       
  1170                 return 'ISO-11548-1';
       
  1171 
       
  1172             case 'csiso90':
       
  1173             case 'isoir90':
       
  1174                 return 'iso-ir-90';
       
  1175 
       
  1176             case 'csunicodeibm1261':
       
  1177             case 'isounicodeibm1261':
       
  1178                 return 'ISO-Unicode-IBM-1261';
       
  1179 
       
  1180             case 'csunicodeibm1264':
       
  1181             case 'isounicodeibm1264':
       
  1182                 return 'ISO-Unicode-IBM-1264';
       
  1183 
       
  1184             case 'csunicodeibm1265':
       
  1185             case 'isounicodeibm1265':
       
  1186                 return 'ISO-Unicode-IBM-1265';
       
  1187 
       
  1188             case 'csunicodeibm1268':
       
  1189             case 'isounicodeibm1268':
       
  1190                 return 'ISO-Unicode-IBM-1268';
       
  1191 
       
  1192             case 'csunicodeibm1276':
       
  1193             case 'isounicodeibm1276':
       
  1194                 return 'ISO-Unicode-IBM-1276';
       
  1195 
       
  1196             case 'csiso646basic1983':
       
  1197             case 'iso646basic1983':
       
  1198             case 'ref':
       
  1199                 return 'ISO_646.basic:1983';
       
  1200 
       
  1201             case 'csiso2intlrefversion':
       
  1202             case 'irv':
       
  1203             case 'iso646irv1983':
       
  1204             case 'isoir2':
       
  1205                 return 'ISO_646.irv:1983';
       
  1206 
       
  1207             case 'csiso2033':
       
  1208             case 'e13b':
       
  1209             case 'iso20331983':
       
  1210             case 'isoir98':
       
  1211                 return 'ISO_2033-1983';
       
  1212 
       
  1213             case 'csiso5427cyrillic':
       
  1214             case 'iso5427':
       
  1215             case 'isoir37':
       
  1216                 return 'ISO_5427';
       
  1217 
       
  1218             case 'iso5427cyrillic1981':
       
  1219             case 'iso54271981':
       
  1220             case 'isoir54':
       
  1221                 return 'ISO_5427:1981';
       
  1222 
       
  1223             case 'csiso5428greek':
       
  1224             case 'iso54281980':
       
  1225             case 'isoir55':
       
  1226                 return 'ISO_5428:1980';
       
  1227 
       
  1228             case 'csiso6937add':
       
  1229             case 'iso6937225':
       
  1230             case 'isoir152':
       
  1231                 return 'ISO_6937-2-25';
       
  1232 
       
  1233             case 'csisotextcomm':
       
  1234             case 'iso69372add':
       
  1235             case 'isoir142':
       
  1236                 return 'ISO_6937-2-add';
       
  1237 
       
  1238             case 'csiso8859supp':
       
  1239             case 'iso8859supp':
       
  1240             case 'isoir154':
       
  1241             case 'latin125':
       
  1242                 return 'ISO_8859-supp';
       
  1243 
       
  1244             case 'csiso10367box':
       
  1245             case 'iso10367box':
       
  1246             case 'isoir155':
       
  1247                 return 'ISO_10367-box';
       
  1248 
       
  1249             case 'csiso15italian':
       
  1250             case 'iso646it':
       
  1251             case 'isoir15':
       
  1252             case 'it':
       
  1253                 return 'IT';
       
  1254 
       
  1255             case 'csiso13jisc6220jp':
       
  1256             case 'isoir13':
       
  1257             case 'jisc62201969':
       
  1258             case 'jisc62201969jp':
       
  1259             case 'katakana':
       
  1260             case 'x2017':
       
  1261                 return 'JIS_C6220-1969-jp';
       
  1262 
       
  1263             case 'csiso14jisc6220ro':
       
  1264             case 'iso646jp':
       
  1265             case 'isoir14':
       
  1266             case 'jisc62201969ro':
       
  1267             case 'jp':
       
  1268                 return 'JIS_C6220-1969-ro';
       
  1269 
       
  1270             case 'csiso42jisc62261978':
       
  1271             case 'isoir42':
       
  1272             case 'jisc62261978':
       
  1273                 return 'JIS_C6226-1978';
       
  1274 
       
  1275             case 'csiso87jisx208':
       
  1276             case 'isoir87':
       
  1277             case 'jisc62261983':
       
  1278             case 'jisx2081983':
       
  1279             case 'x208':
       
  1280                 return 'JIS_C6226-1983';
       
  1281 
       
  1282             case 'csiso91jisc62291984a':
       
  1283             case 'isoir91':
       
  1284             case 'jisc62291984a':
       
  1285             case 'jpocra':
       
  1286                 return 'JIS_C6229-1984-a';
       
  1287 
       
  1288             case 'csiso92jisc62991984b':
       
  1289             case 'iso646jpocrb':
       
  1290             case 'isoir92':
       
  1291             case 'jisc62291984b':
       
  1292             case 'jpocrb':
       
  1293                 return 'JIS_C6229-1984-b';
       
  1294 
       
  1295             case 'csiso93jis62291984badd':
       
  1296             case 'isoir93':
       
  1297             case 'jisc62291984badd':
       
  1298             case 'jpocrbadd':
       
  1299                 return 'JIS_C6229-1984-b-add';
       
  1300 
       
  1301             case 'csiso94jis62291984hand':
       
  1302             case 'isoir94':
       
  1303             case 'jisc62291984hand':
       
  1304             case 'jpocrhand':
       
  1305                 return 'JIS_C6229-1984-hand';
       
  1306 
       
  1307             case 'csiso95jis62291984handadd':
       
  1308             case 'isoir95':
       
  1309             case 'jisc62291984handadd':
       
  1310             case 'jpocrhandadd':
       
  1311                 return 'JIS_C6229-1984-hand-add';
       
  1312 
       
  1313             case 'csiso96jisc62291984kana':
       
  1314             case 'isoir96':
       
  1315             case 'jisc62291984kana':
       
  1316                 return 'JIS_C6229-1984-kana';
       
  1317 
       
  1318             case 'csjisencoding':
       
  1319             case 'jisencoding':
       
  1320                 return 'JIS_Encoding';
       
  1321 
       
  1322             case 'cshalfwidthkatakana':
       
  1323             case 'jisx201':
       
  1324             case 'x201':
       
  1325                 return 'JIS_X0201';
       
  1326 
       
  1327             case 'csiso159jisx2121990':
       
  1328             case 'isoir159':
       
  1329             case 'jisx2121990':
       
  1330             case 'x212':
       
  1331                 return 'JIS_X0212-1990';
       
  1332 
       
  1333             case 'csiso141jusib1002':
       
  1334             case 'iso646yu':
       
  1335             case 'isoir141':
       
  1336             case 'js':
       
  1337             case 'jusib1002':
       
  1338             case 'yu':
       
  1339                 return 'JUS_I.B1.002';
       
  1340 
       
  1341             case 'csiso147macedonian':
       
  1342             case 'isoir147':
       
  1343             case 'jusib1003mac':
       
  1344             case 'macedonian':
       
  1345                 return 'JUS_I.B1.003-mac';
       
  1346 
       
  1347             case 'csiso146serbian':
       
  1348             case 'isoir146':
       
  1349             case 'jusib1003serb':
       
  1350             case 'serbian':
       
  1351                 return 'JUS_I.B1.003-serb';
       
  1352 
       
  1353             case 'koi7switched':
       
  1354                 return 'KOI7-switched';
       
  1355 
       
  1356             case 'cskoi8r':
       
  1357             case 'koi8r':
       
  1358                 return 'KOI8-R';
       
  1359 
       
  1360             case 'koi8u':
       
  1361                 return 'KOI8-U';
       
  1362 
       
  1363             case 'csksc5636':
       
  1364             case 'iso646kr':
       
  1365             case 'ksc5636':
       
  1366                 return 'KSC5636';
       
  1367 
       
  1368             case 'cskz1048':
       
  1369             case 'kz1048':
       
  1370             case 'rk1048':
       
  1371             case 'strk10482002':
       
  1372                 return 'KZ-1048';
       
  1373 
       
  1374             case 'csiso19latingreek':
       
  1375             case 'isoir19':
       
  1376             case 'latingreek':
       
  1377                 return 'latin-greek';
       
  1378 
       
  1379             case 'csiso27latingreek1':
       
  1380             case 'isoir27':
       
  1381             case 'latingreek1':
       
  1382                 return 'Latin-greek-1';
       
  1383 
       
  1384             case 'csiso158lap':
       
  1385             case 'isoir158':
       
  1386             case 'lap':
       
  1387             case 'latinlap':
       
  1388                 return 'latin-lap';
       
  1389 
       
  1390             case 'csmacintosh':
       
  1391             case 'mac':
       
  1392             case 'macintosh':
       
  1393                 return 'macintosh';
       
  1394 
       
  1395             case 'csmicrosoftpublishing':
       
  1396             case 'microsoftpublishing':
       
  1397                 return 'Microsoft-Publishing';
       
  1398 
       
  1399             case 'csmnem':
       
  1400             case 'mnem':
       
  1401                 return 'MNEM';
       
  1402 
       
  1403             case 'csmnemonic':
       
  1404             case 'mnemonic':
       
  1405                 return 'MNEMONIC';
       
  1406 
       
  1407             case 'csiso86hungarian':
       
  1408             case 'hu':
       
  1409             case 'iso646hu':
       
  1410             case 'isoir86':
       
  1411             case 'msz77953':
       
  1412                 return 'MSZ_7795.3';
       
  1413 
       
  1414             case 'csnatsdano':
       
  1415             case 'isoir91':
       
  1416             case 'natsdano':
       
  1417                 return 'NATS-DANO';
       
  1418 
       
  1419             case 'csnatsdanoadd':
       
  1420             case 'isoir92':
       
  1421             case 'natsdanoadd':
       
  1422                 return 'NATS-DANO-ADD';
       
  1423 
       
  1424             case 'csnatssefi':
       
  1425             case 'isoir81':
       
  1426             case 'natssefi':
       
  1427                 return 'NATS-SEFI';
       
  1428 
       
  1429             case 'csnatssefiadd':
       
  1430             case 'isoir82':
       
  1431             case 'natssefiadd':
       
  1432                 return 'NATS-SEFI-ADD';
       
  1433 
       
  1434             case 'csiso151cuba':
       
  1435             case 'cuba':
       
  1436             case 'iso646cu':
       
  1437             case 'isoir151':
       
  1438             case 'ncnc1081':
       
  1439                 return 'NC_NC00-10:81';
       
  1440 
       
  1441             case 'csiso69french':
       
  1442             case 'fr':
       
  1443             case 'iso646fr':
       
  1444             case 'isoir69':
       
  1445             case 'nfz62010':
       
  1446                 return 'NF_Z_62-010';
       
  1447 
       
  1448             case 'csiso25french':
       
  1449             case 'iso646fr1':
       
  1450             case 'isoir25':
       
  1451             case 'nfz620101973':
       
  1452                 return 'NF_Z_62-010_(1973)';
       
  1453 
       
  1454             case 'csiso60danishnorwegian':
       
  1455             case 'csiso60norwegian1':
       
  1456             case 'iso646no':
       
  1457             case 'isoir60':
       
  1458             case 'no':
       
  1459             case 'ns45511':
       
  1460                 return 'NS_4551-1';
       
  1461 
       
  1462             case 'csiso61norwegian2':
       
  1463             case 'iso646no2':
       
  1464             case 'isoir61':
       
  1465             case 'no2':
       
  1466             case 'ns45512':
       
  1467                 return 'NS_4551-2';
       
  1468 
       
  1469             case 'osdebcdicdf3irv':
       
  1470                 return 'OSD_EBCDIC_DF03_IRV';
       
  1471 
       
  1472             case 'osdebcdicdf41':
       
  1473                 return 'OSD_EBCDIC_DF04_1';
       
  1474 
       
  1475             case 'osdebcdicdf415':
       
  1476                 return 'OSD_EBCDIC_DF04_15';
       
  1477 
       
  1478             case 'cspc8danishnorwegian':
       
  1479             case 'pc8danishnorwegian':
       
  1480                 return 'PC8-Danish-Norwegian';
       
  1481 
       
  1482             case 'cspc8turkish':
       
  1483             case 'pc8turkish':
       
  1484                 return 'PC8-Turkish';
       
  1485 
       
  1486             case 'csiso16portuguese':
       
  1487             case 'iso646pt':
       
  1488             case 'isoir16':
       
  1489             case 'pt':
       
  1490                 return 'PT';
       
  1491 
       
  1492             case 'csiso84portuguese2':
       
  1493             case 'iso646pt2':
       
  1494             case 'isoir84':
       
  1495             case 'pt2':
       
  1496                 return 'PT2';
       
  1497 
       
  1498             case 'cp154':
       
  1499             case 'csptcp154':
       
  1500             case 'cyrillicasian':
       
  1501             case 'pt154':
       
  1502             case 'ptcp154':
       
  1503                 return 'PTCP154';
       
  1504 
       
  1505             case 'scsu':
       
  1506                 return 'SCSU';
       
  1507 
       
  1508             case 'csiso10swedish':
       
  1509             case 'fi':
       
  1510             case 'iso646fi':
       
  1511             case 'iso646se':
       
  1512             case 'isoir10':
       
  1513             case 'se':
       
  1514             case 'sen850200b':
       
  1515                 return 'SEN_850200_B';
       
  1516 
       
  1517             case 'csiso11swedishfornames':
       
  1518             case 'iso646se2':
       
  1519             case 'isoir11':
       
  1520             case 'se2':
       
  1521             case 'sen850200c':
       
  1522                 return 'SEN_850200_C';
       
  1523 
       
  1524             case 'csiso102t617bit':
       
  1525             case 'isoir102':
       
  1526             case 't617bit':
       
  1527                 return 'T.61-7bit';
       
  1528 
       
  1529             case 'csiso103t618bit':
       
  1530             case 'isoir103':
       
  1531             case 't61':
       
  1532             case 't618bit':
       
  1533                 return 'T.61-8bit';
       
  1534 
       
  1535             case 'csiso128t101g2':
       
  1536             case 'isoir128':
       
  1537             case 't101g2':
       
  1538                 return 'T.101-G2';
       
  1539 
       
  1540             case 'cstscii':
       
  1541             case 'tscii':
       
  1542                 return 'TSCII';
       
  1543 
       
  1544             case 'csunicode11':
       
  1545             case 'unicode11':
       
  1546                 return 'UNICODE-1-1';
       
  1547 
       
  1548             case 'csunicode11utf7':
       
  1549             case 'unicode11utf7':
       
  1550                 return 'UNICODE-1-1-UTF-7';
       
  1551 
       
  1552             case 'csunknown8bit':
       
  1553             case 'unknown8bit':
       
  1554                 return 'UNKNOWN-8BIT';
       
  1555 
       
  1556             case 'ansix341968':
       
  1557             case 'ansix341986':
       
  1558             case 'ascii':
       
  1559             case 'cp367':
       
  1560             case 'csascii':
       
  1561             case 'ibm367':
       
  1562             case 'iso646irv1991':
       
  1563             case 'iso646us':
       
  1564             case 'isoir6':
       
  1565             case 'us':
       
  1566             case 'usascii':
       
  1567                 return 'US-ASCII';
       
  1568 
       
  1569             case 'csusdk':
       
  1570             case 'usdk':
       
  1571                 return 'us-dk';
       
  1572 
       
  1573             case 'utf7':
       
  1574                 return 'UTF-7';
       
  1575 
       
  1576             case 'utf8':
       
  1577                 return 'UTF-8';
       
  1578 
       
  1579             case 'utf16':
       
  1580                 return 'UTF-16';
       
  1581 
       
  1582             case 'utf16be':
       
  1583                 return 'UTF-16BE';
       
  1584 
       
  1585             case 'utf16le':
       
  1586                 return 'UTF-16LE';
       
  1587 
       
  1588             case 'utf32':
       
  1589                 return 'UTF-32';
       
  1590 
       
  1591             case 'utf32be':
       
  1592                 return 'UTF-32BE';
       
  1593 
       
  1594             case 'utf32le':
       
  1595                 return 'UTF-32LE';
       
  1596 
       
  1597             case 'csventurainternational':
       
  1598             case 'venturainternational':
       
  1599                 return 'Ventura-International';
       
  1600 
       
  1601             case 'csventuramath':
       
  1602             case 'venturamath':
       
  1603                 return 'Ventura-Math';
       
  1604 
       
  1605             case 'csventuraus':
       
  1606             case 'venturaus':
       
  1607                 return 'Ventura-US';
       
  1608 
       
  1609             case 'csiso70videotexsupp1':
       
  1610             case 'isoir70':
       
  1611             case 'videotexsuppl':
       
  1612                 return 'videotex-suppl';
       
  1613 
       
  1614             case 'csviqr':
       
  1615             case 'viqr':
       
  1616                 return 'VIQR';
       
  1617 
       
  1618             case 'csviscii':
       
  1619             case 'viscii':
       
  1620                 return 'VISCII';
       
  1621 
       
  1622             case 'csshiftjis':
       
  1623             case 'cswindows31j':
       
  1624             case 'mskanji':
       
  1625             case 'shiftjis':
       
  1626             case 'windows31j':
       
  1627                 return 'Windows-31J';
       
  1628 
       
  1629             case 'iso885911':
       
  1630             case 'tis620':
       
  1631                 return 'windows-874';
       
  1632 
       
  1633             case 'cseuckr':
       
  1634             case 'csksc56011987':
       
  1635             case 'euckr':
       
  1636             case 'isoir149':
       
  1637             case 'korean':
       
  1638             case 'ksc5601':
       
  1639             case 'ksc56011987':
       
  1640             case 'ksc56011989':
       
  1641             case 'windows949':
       
  1642                 return 'windows-949';
       
  1643 
       
  1644             case 'windows1250':
       
  1645                 return 'windows-1250';
       
  1646 
       
  1647             case 'windows1251':
       
  1648                 return 'windows-1251';
       
  1649 
       
  1650             case 'cp819':
       
  1651             case 'csisolatin1':
       
  1652             case 'ibm819':
       
  1653             case 'iso88591':
       
  1654             case 'iso885911987':
       
  1655             case 'isoir100':
       
  1656             case 'l1':
       
  1657             case 'latin1':
       
  1658             case 'windows1252':
       
  1659                 return 'windows-1252';
       
  1660 
       
  1661             case 'windows1253':
       
  1662                 return 'windows-1253';
       
  1663 
       
  1664             case 'csisolatin5':
       
  1665             case 'iso88599':
       
  1666             case 'iso885991989':
       
  1667             case 'isoir148':
       
  1668             case 'l5':
       
  1669             case 'latin5':
       
  1670             case 'windows1254':
       
  1671                 return 'windows-1254';
       
  1672 
       
  1673             case 'windows1255':
       
  1674                 return 'windows-1255';
       
  1675 
       
  1676             case 'windows1256':
       
  1677                 return 'windows-1256';
       
  1678 
       
  1679             case 'windows1257':
       
  1680                 return 'windows-1257';
       
  1681 
       
  1682             case 'windows1258':
       
  1683                 return 'windows-1258';
       
  1684 
       
  1685             default:
       
  1686                 return $charset;
       
  1687         }
       
  1688     }
       
  1689 
       
  1690     public static function get_curl_version()
       
  1691     {
       
  1692         if (is_array($curl = curl_version())) {
       
  1693             $curl = $curl['version'];
       
  1694         } elseif (substr($curl, 0, 5) === 'curl/') {
       
  1695             $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
       
  1696         } elseif (substr($curl, 0, 8) === 'libcurl/') {
       
  1697             $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
       
  1698         } else {
       
  1699             $curl = 0;
       
  1700         }
       
  1701         return $curl;
       
  1702     }
       
  1703 
       
  1704     /**
       
  1705      * Strip HTML comments
       
  1706      *
       
  1707      * @param string $data Data to strip comments from
       
  1708      * @return string Comment stripped string
       
  1709      */
       
  1710     public static function strip_comments($data)
       
  1711     {
       
  1712         $output = '';
       
  1713         while (($start = strpos($data, '<!--')) !== false) {
       
  1714             $output .= substr($data, 0, $start);
       
  1715             if (($end = strpos($data, '-->', $start)) !== false) {
       
  1716                 $data = substr_replace($data, '', 0, $end + 3);
       
  1717             } else {
       
  1718                 $data = '';
       
  1719             }
       
  1720         }
       
  1721         return $output . $data;
       
  1722     }
       
  1723 
       
  1724     public static function parse_date($dt)
       
  1725     {
       
  1726         $parser = \SimplePie\Parse\Date::get();
       
  1727         return $parser->parse($dt);
       
  1728     }
       
  1729 
       
  1730     /**
       
  1731      * Decode HTML entities
       
  1732      *
       
  1733      * @deprecated since SimplePie 1.3, use DOMDocument instead
       
  1734      * @param string $data Input data
       
  1735      * @return string Output data
       
  1736      */
       
  1737     public static function entities_decode($data)
       
  1738     {
       
  1739         // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED);
       
  1740 
       
  1741         $decoder = new \SimplePie_Decode_HTML_Entities($data);
       
  1742         return $decoder->parse();
       
  1743     }
       
  1744 
       
  1745     /**
       
  1746      * Remove RFC822 comments
       
  1747      *
       
  1748      * @param string $data Data to strip comments from
       
  1749      * @return string Comment stripped string
       
  1750      */
       
  1751     public static function uncomment_rfc822($string)
       
  1752     {
       
  1753         $string = (string) $string;
       
  1754         $position = 0;
       
  1755         $length = strlen($string);
       
  1756         $depth = 0;
       
  1757 
       
  1758         $output = '';
       
  1759 
       
  1760         while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) {
       
  1761             $output .= substr($string, $position, $pos - $position);
       
  1762             $position = $pos + 1;
       
  1763             if ($string[$pos - 1] !== '\\') {
       
  1764                 $depth++;
       
  1765                 while ($depth && $position < $length) {
       
  1766                     $position += strcspn($string, '()', $position);
       
  1767                     if ($string[$position - 1] === '\\') {
       
  1768                         $position++;
       
  1769                         continue;
       
  1770                     } elseif (isset($string[$position])) {
       
  1771                         switch ($string[$position]) {
       
  1772                             case '(':
       
  1773                                 $depth++;
       
  1774                                 break;
       
  1775 
       
  1776                             case ')':
       
  1777                                 $depth--;
       
  1778                                 break;
       
  1779                         }
       
  1780                         $position++;
       
  1781                     } else {
       
  1782                         break;
       
  1783                     }
       
  1784                 }
       
  1785             } else {
       
  1786                 $output .= '(';
       
  1787             }
       
  1788         }
       
  1789         $output .= substr($string, $position);
       
  1790 
       
  1791         return $output;
       
  1792     }
       
  1793 
       
  1794     public static function parse_mime($mime)
       
  1795     {
       
  1796         if (($pos = strpos($mime, ';')) === false) {
       
  1797             return trim($mime);
       
  1798         }
       
  1799 
       
  1800         return trim(substr($mime, 0, $pos));
       
  1801     }
       
  1802 
       
  1803     public static function atom_03_construct_type($attribs)
       
  1804     {
       
  1805         if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode'])) === 'base64') {
       
  1806             $mode = \SimplePie\SimplePie::CONSTRUCT_BASE64;
       
  1807         } else {
       
  1808             $mode = \SimplePie\SimplePie::CONSTRUCT_NONE;
       
  1809         }
       
  1810         if (isset($attribs['']['type'])) {
       
  1811             switch (strtolower(trim($attribs['']['type']))) {
       
  1812                 case 'text':
       
  1813                 case 'text/plain':
       
  1814                     return \SimplePie\SimplePie::CONSTRUCT_TEXT | $mode;
       
  1815 
       
  1816                 case 'html':
       
  1817                 case 'text/html':
       
  1818                     return \SimplePie\SimplePie::CONSTRUCT_HTML | $mode;
       
  1819 
       
  1820                 case 'xhtml':
       
  1821                 case 'application/xhtml+xml':
       
  1822                     return \SimplePie\SimplePie::CONSTRUCT_XHTML | $mode;
       
  1823 
       
  1824                 default:
       
  1825                     return \SimplePie\SimplePie::CONSTRUCT_NONE | $mode;
       
  1826             }
       
  1827         }
       
  1828 
       
  1829         return \SimplePie\SimplePie::CONSTRUCT_TEXT | $mode;
       
  1830     }
       
  1831 
       
  1832     public static function atom_10_construct_type($attribs)
       
  1833     {
       
  1834         if (isset($attribs['']['type'])) {
       
  1835             switch (strtolower(trim($attribs['']['type']))) {
       
  1836                 case 'text':
       
  1837                     return \SimplePie\SimplePie::CONSTRUCT_TEXT;
       
  1838 
       
  1839                 case 'html':
       
  1840                     return \SimplePie\SimplePie::CONSTRUCT_HTML;
       
  1841 
       
  1842                 case 'xhtml':
       
  1843                     return \SimplePie\SimplePie::CONSTRUCT_XHTML;
       
  1844 
       
  1845                 default:
       
  1846                     return \SimplePie\SimplePie::CONSTRUCT_NONE;
       
  1847             }
       
  1848         }
       
  1849         return \SimplePie\SimplePie::CONSTRUCT_TEXT;
       
  1850     }
       
  1851 
       
  1852     public static function atom_10_content_construct_type($attribs)
       
  1853     {
       
  1854         if (isset($attribs['']['type'])) {
       
  1855             $type = strtolower(trim($attribs['']['type']));
       
  1856             switch ($type) {
       
  1857                 case 'text':
       
  1858                     return \SimplePie\SimplePie::CONSTRUCT_TEXT;
       
  1859 
       
  1860                 case 'html':
       
  1861                     return \SimplePie\SimplePie::CONSTRUCT_HTML;
       
  1862 
       
  1863                 case 'xhtml':
       
  1864                     return \SimplePie\SimplePie::CONSTRUCT_XHTML;
       
  1865             }
       
  1866             if (in_array(substr($type, -4), ['+xml', '/xml']) || substr($type, 0, 5) === 'text/') {
       
  1867                 return \SimplePie\SimplePie::CONSTRUCT_NONE;
       
  1868             } else {
       
  1869                 return \SimplePie\SimplePie::CONSTRUCT_BASE64;
       
  1870             }
       
  1871         }
       
  1872 
       
  1873         return \SimplePie\SimplePie::CONSTRUCT_TEXT;
       
  1874     }
       
  1875 
       
  1876     public static function is_isegment_nz_nc($string)
       
  1877     {
       
  1878         return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string);
       
  1879     }
       
  1880 
       
  1881     public static function space_separated_tokens($string)
       
  1882     {
       
  1883         $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
       
  1884         $string_length = strlen($string);
       
  1885 
       
  1886         $position = strspn($string, $space_characters);
       
  1887         $tokens = [];
       
  1888 
       
  1889         while ($position < $string_length) {
       
  1890             $len = strcspn($string, $space_characters, $position);
       
  1891             $tokens[] = substr($string, $position, $len);
       
  1892             $position += $len;
       
  1893             $position += strspn($string, $space_characters, $position);
       
  1894         }
       
  1895 
       
  1896         return $tokens;
       
  1897     }
       
  1898 
       
  1899     /**
       
  1900      * Converts a unicode codepoint to a UTF-8 character
       
  1901      *
       
  1902      * @static
       
  1903      * @param int $codepoint Unicode codepoint
       
  1904      * @return string UTF-8 character
       
  1905      */
       
  1906     public static function codepoint_to_utf8($codepoint)
       
  1907     {
       
  1908         $codepoint = (int) $codepoint;
       
  1909         if ($codepoint < 0) {
       
  1910             return false;
       
  1911         } elseif ($codepoint <= 0x7f) {
       
  1912             return chr($codepoint);
       
  1913         } elseif ($codepoint <= 0x7ff) {
       
  1914             return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
       
  1915         } elseif ($codepoint <= 0xffff) {
       
  1916             return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
       
  1917         } elseif ($codepoint <= 0x10ffff) {
       
  1918             return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
       
  1919         }
       
  1920 
       
  1921         // U+FFFD REPLACEMENT CHARACTER
       
  1922         return "\xEF\xBF\xBD";
       
  1923     }
       
  1924 
       
  1925     /**
       
  1926      * Similar to parse_str()
       
  1927      *
       
  1928      * Returns an associative array of name/value pairs, where the value is an
       
  1929      * array of values that have used the same name
       
  1930      *
       
  1931      * @static
       
  1932      * @param string $str The input string.
       
  1933      * @return array
       
  1934      */
       
  1935     public static function parse_str($str)
       
  1936     {
       
  1937         $return = [];
       
  1938         $str = explode('&', $str);
       
  1939 
       
  1940         foreach ($str as $section) {
       
  1941             if (strpos($section, '=') !== false) {
       
  1942                 [$name, $value] = explode('=', $section, 2);
       
  1943                 $return[urldecode($name)][] = urldecode($value);
       
  1944             } else {
       
  1945                 $return[urldecode($section)][] = null;
       
  1946             }
       
  1947         }
       
  1948 
       
  1949         return $return;
       
  1950     }
       
  1951 
       
  1952     /**
       
  1953      * Detect XML encoding, as per XML 1.0 Appendix F.1
       
  1954      *
       
  1955      * @todo Add support for EBCDIC
       
  1956      * @param string $data XML data
       
  1957      * @param \SimplePie\Registry $registry Class registry
       
  1958      * @return array Possible encodings
       
  1959      */
       
  1960     public static function xml_encoding($data, $registry)
       
  1961     {
       
  1962         // UTF-32 Big Endian BOM
       
  1963         if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") {
       
  1964             $encoding[] = 'UTF-32BE';
       
  1965         }
       
  1966         // UTF-32 Little Endian BOM
       
  1967         elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") {
       
  1968             $encoding[] = 'UTF-32LE';
       
  1969         }
       
  1970         // UTF-16 Big Endian BOM
       
  1971         elseif (substr($data, 0, 2) === "\xFE\xFF") {
       
  1972             $encoding[] = 'UTF-16BE';
       
  1973         }
       
  1974         // UTF-16 Little Endian BOM
       
  1975         elseif (substr($data, 0, 2) === "\xFF\xFE") {
       
  1976             $encoding[] = 'UTF-16LE';
       
  1977         }
       
  1978         // UTF-8 BOM
       
  1979         elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") {
       
  1980             $encoding[] = 'UTF-8';
       
  1981         }
       
  1982         // UTF-32 Big Endian Without BOM
       
  1983         elseif (substr($data, 0, 20) === "\x00\x00\x00\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C") {
       
  1984             if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E")) {
       
  1985                 $parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')]);
       
  1986                 if ($parser->parse()) {
       
  1987                     $encoding[] = $parser->encoding;
       
  1988                 }
       
  1989             }
       
  1990             $encoding[] = 'UTF-32BE';
       
  1991         }
       
  1992         // UTF-32 Little Endian Without BOM
       
  1993         elseif (substr($data, 0, 20) === "\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C\x00\x00\x00") {
       
  1994             if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00")) {
       
  1995                 $parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')]);
       
  1996                 if ($parser->parse()) {
       
  1997                     $encoding[] = $parser->encoding;
       
  1998                 }
       
  1999             }
       
  2000             $encoding[] = 'UTF-32LE';
       
  2001         }
       
  2002         // UTF-16 Big Endian Without BOM
       
  2003         elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C") {
       
  2004             if ($pos = strpos($data, "\x00\x3F\x00\x3E")) {
       
  2005                 $parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')]);
       
  2006                 if ($parser->parse()) {
       
  2007                     $encoding[] = $parser->encoding;
       
  2008                 }
       
  2009             }
       
  2010             $encoding[] = 'UTF-16BE';
       
  2011         }
       
  2012         // UTF-16 Little Endian Without BOM
       
  2013         elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00") {
       
  2014             if ($pos = strpos($data, "\x3F\x00\x3E\x00")) {
       
  2015                 $parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')]);
       
  2016                 if ($parser->parse()) {
       
  2017                     $encoding[] = $parser->encoding;
       
  2018                 }
       
  2019             }
       
  2020             $encoding[] = 'UTF-16LE';
       
  2021         }
       
  2022         // US-ASCII (or superset)
       
  2023         elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C") {
       
  2024             if ($pos = strpos($data, "\x3F\x3E")) {
       
  2025                 $parser = $registry->create(Parser::class, [substr($data, 5, $pos - 5)]);
       
  2026                 if ($parser->parse()) {
       
  2027                     $encoding[] = $parser->encoding;
       
  2028                 }
       
  2029             }
       
  2030             $encoding[] = 'UTF-8';
       
  2031         }
       
  2032         // Fallback to UTF-8
       
  2033         else {
       
  2034             $encoding[] = 'UTF-8';
       
  2035         }
       
  2036         return $encoding;
       
  2037     }
       
  2038 
       
  2039     public static function output_javascript()
       
  2040     {
       
  2041         if (function_exists('ob_gzhandler')) {
       
  2042             ob_start('ob_gzhandler');
       
  2043         }
       
  2044         header('Content-type: text/javascript; charset: UTF-8');
       
  2045         header('Cache-Control: must-revalidate');
       
  2046         header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
       
  2047 
       
  2048         $body = <<<END
       
  2049 function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
       
  2050 	if (placeholder != '') {
       
  2051 		document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
       
  2052 	}
       
  2053 	else {
       
  2054 		document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" src="'+link+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="true" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
       
  2055 	}
       
  2056 }
       
  2057 
       
  2058 function embed_flash(bgcolor, width, height, link, loop, type) {
       
  2059 	document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>');
       
  2060 }
       
  2061 
       
  2062 function embed_flv(width, height, link, placeholder, loop, player) {
       
  2063 	document.writeln('<embed src="'+player+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="'+width+'" height="'+height+'" wmode="transparent" flashvars="file='+link+'&autostart=false&repeat='+loop+'&showdigits=true&showfsbutton=false"></embed>');
       
  2064 }
       
  2065 
       
  2066 function embed_wmedia(width, height, link) {
       
  2067 	document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
       
  2068 }
       
  2069 END;
       
  2070         echo $body;
       
  2071     }
       
  2072 
       
  2073     /**
       
  2074      * Get the SimplePie build timestamp
       
  2075      *
       
  2076      * Uses the git index if it exists, otherwise uses the modification time
       
  2077      * of the newest file.
       
  2078      */
       
  2079     public static function get_build()
       
  2080     {
       
  2081         if (static::$SIMPLEPIE_BUILD !== null) {
       
  2082             return static::$SIMPLEPIE_BUILD;
       
  2083         }
       
  2084 
       
  2085         $root = dirname(__FILE__, 2);
       
  2086         if (file_exists($root . '/.git/index')) {
       
  2087             static::$SIMPLEPIE_BUILD = filemtime($root . '/.git/index');
       
  2088 
       
  2089             return static::$SIMPLEPIE_BUILD;
       
  2090         } elseif (file_exists($root . '/SimplePie')) {
       
  2091             $time = 0;
       
  2092             foreach (glob($root . '/SimplePie/*.php') as $file) {
       
  2093                 if (($mtime = filemtime($file)) > $time) {
       
  2094                     $time = $mtime;
       
  2095                 }
       
  2096             }
       
  2097             static::$SIMPLEPIE_BUILD = $time;
       
  2098 
       
  2099             return static::$SIMPLEPIE_BUILD;
       
  2100         } elseif (file_exists(dirname(__FILE__) . '/Core.php')) {
       
  2101             static::$SIMPLEPIE_BUILD = filemtime(dirname(__FILE__) . '/Core.php');
       
  2102 
       
  2103             return static::$SIMPLEPIE_BUILD;
       
  2104         }
       
  2105 
       
  2106         static::$SIMPLEPIE_BUILD = filemtime(__FILE__);
       
  2107 
       
  2108         return static::$SIMPLEPIE_BUILD;
       
  2109     }
       
  2110 
       
  2111     /**
       
  2112      * Get the default user agent string
       
  2113      *
       
  2114      * @return string
       
  2115      */
       
  2116     public static function get_default_useragent()
       
  2117     {
       
  2118         return \SimplePie\SimplePie::NAME . '/' . \SimplePie\SimplePie::VERSION . ' (Feed Parser; ' . \SimplePie\SimplePie::URL . '; Allow like Gecko) Build/' . static::get_build();
       
  2119     }
       
  2120 
       
  2121     /**
       
  2122      * Format debugging information
       
  2123      */
       
  2124     public static function debug(&$sp)
       
  2125     {
       
  2126         $info = 'SimplePie ' . \SimplePie\SimplePie::VERSION . ' Build ' . static::get_build() . "\n";
       
  2127         $info .= 'PHP ' . PHP_VERSION . "\n";
       
  2128         if ($sp->error() !== null) {
       
  2129             $info .= 'Error occurred: ' . $sp->error() . "\n";
       
  2130         } else {
       
  2131             $info .= "No error found.\n";
       
  2132         }
       
  2133         $info .= "Extensions:\n";
       
  2134         $extensions = ['pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml'];
       
  2135         foreach ($extensions as $ext) {
       
  2136             if (extension_loaded($ext)) {
       
  2137                 $info .= "    $ext loaded\n";
       
  2138                 switch ($ext) {
       
  2139                     case 'pcre':
       
  2140                         $info .= '      Version ' . PCRE_VERSION . "\n";
       
  2141                         break;
       
  2142                     case 'curl':
       
  2143                         $version = curl_version();
       
  2144                         $info .= '      Version ' . $version['version'] . "\n";
       
  2145                         break;
       
  2146                     case 'mbstring':
       
  2147                         $info .= '      Overloading: ' . mb_get_info('func_overload') . "\n";
       
  2148                         break;
       
  2149                     case 'iconv':
       
  2150                         $info .= '      Version ' . ICONV_VERSION . "\n";
       
  2151                         break;
       
  2152                     case 'xml':
       
  2153                         $info .= '      Version ' . LIBXML_DOTTED_VERSION . "\n";
       
  2154                         break;
       
  2155                 }
       
  2156             } else {
       
  2157                 $info .= "    $ext not loaded\n";
       
  2158             }
       
  2159         }
       
  2160         return $info;
       
  2161     }
       
  2162 
       
  2163     public static function silence_errors($num, $str)
       
  2164     {
       
  2165         // No-op
       
  2166     }
       
  2167 
       
  2168     /**
       
  2169      * Sanitize a URL by removing HTTP credentials.
       
  2170      * @param string $url the URL to sanitize.
       
  2171      * @return string the same URL without HTTP credentials.
       
  2172      */
       
  2173     public static function url_remove_credentials($url)
       
  2174     {
       
  2175         return preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url);
       
  2176     }
       
  2177 }
       
  2178 
       
  2179 class_alias('SimplePie\Misc', 'SimplePie_Misc', false);