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