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