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