Misc.php 51 KB

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