PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/SimplePie/Misc.php

http://github.com/simplepie/simplepie
PHP | 2377 lines | 2308 code | 9 blank | 60 comment | 17 complexity | 60001e60534d5117deb24b8beb79af8e MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file