Misc.php 51 KB

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