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