PageRenderTime 115ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wp-security-scan/simplepie.inc

https://bitbucket.org/openfarmtech/weblog-content
PHP | 12658 lines | 11712 code | 462 blank | 484 comment | 917 complexity | 60bc13a3f05eb9cf0c5c87564413081c MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.0, LGPL-3.0, BSD-3-Clause, GPL-3.0, LGPL-2.1, AGPL-3.0, CC-BY-SA-3.0
  1. <?php
  2. define('SIMPLEPIE_NAME', 'SimplePie');
  3. define('SIMPLEPIE_VERSION', '1.1.3');
  4. define('SIMPLEPIE_BUILD', 20081219);
  5. define('SIMPLEPIE_URL', 'http://simplepie.org');
  6. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
  7. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
  8. define('SIMPLEPIE_LOCATOR_NONE', 0);
  9. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
  10. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
  11. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
  12. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
  13. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
  14. define('SIMPLEPIE_LOCATOR_ALL', 31);
  15. define('SIMPLEPIE_TYPE_NONE', 0);
  16. define('SIMPLEPIE_TYPE_RSS_090', 1);
  17. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
  18. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
  19. define('SIMPLEPIE_TYPE_RSS_091', 6);
  20. define('SIMPLEPIE_TYPE_RSS_092', 8);
  21. define('SIMPLEPIE_TYPE_RSS_093', 16);
  22. define('SIMPLEPIE_TYPE_RSS_094', 32);
  23. define('SIMPLEPIE_TYPE_RSS_10', 64);
  24. define('SIMPLEPIE_TYPE_RSS_20', 128);
  25. define('SIMPLEPIE_TYPE_RSS_RDF', 65);
  26. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
  27. define('SIMPLEPIE_TYPE_RSS_ALL', 255);
  28. define('SIMPLEPIE_TYPE_ATOM_03', 256);
  29. define('SIMPLEPIE_TYPE_ATOM_10', 512);
  30. define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
  31. define('SIMPLEPIE_TYPE_ALL', 1023);
  32. define('SIMPLEPIE_CONSTRUCT_NONE', 0);
  33. define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
  34. define('SIMPLEPIE_CONSTRUCT_HTML', 2);
  35. define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
  36. define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
  37. define('SIMPLEPIE_CONSTRUCT_IRI', 16);
  38. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
  39. define('SIMPLEPIE_CONSTRUCT_ALL', 63);
  40. define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\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]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*');
  41. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
  42. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
  43. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
  44. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
  45. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  46. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
  47. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
  48. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
  49. define('SIMPLEPIE_NAMESPACE_RSS_20', '');
  50. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
  51. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
  52. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
  53. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
  54. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
  55. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
  56. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  57. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
  58. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
  59. define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>='));
  60. define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
  61. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
  62. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
  63. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
  64. define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
  65. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
  66. class SimplePie
  67. {
  68. var $data = array();
  69. var $error;
  70. var $sanitize;
  71. var $useragent = SIMPLEPIE_USERAGENT;
  72. var $feed_url;
  73. var $file;
  74. var $raw_data;
  75. var $timeout = 10;
  76. var $force_fsockopen = false;
  77. var $force_feed = false;
  78. var $xml_dump = false;
  79. var $cache = true;
  80. var $cache_duration = 3600;
  81. var $autodiscovery_cache_duration = 604800; // 7 Days.
  82. var $cache_location = './cache';
  83. var $cache_name_function = 'md5';
  84. var $order_by_date = true;
  85. var $input_encoding = false;
  86. var $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  87. var $cache_class = 'SimplePie_Cache';
  88. var $locator_class = 'SimplePie_Locator';
  89. var $parser_class = 'SimplePie_Parser';
  90. var $file_class = 'SimplePie_File';
  91. var $item_class = 'SimplePie_Item';
  92. var $author_class = 'SimplePie_Author';
  93. var $category_class = 'SimplePie_Category';
  94. var $enclosure_class = 'SimplePie_Enclosure';
  95. var $caption_class = 'SimplePie_Caption';
  96. var $copyright_class = 'SimplePie_Copyright';
  97. var $credit_class = 'SimplePie_Credit';
  98. var $rating_class = 'SimplePie_Rating';
  99. var $restriction_class = 'SimplePie_Restriction';
  100. var $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
  101. var $source_class = 'SimplePie_Source';
  102. var $javascript = 'js';
  103. var $max_checked_feeds = 10;
  104. var $favicon_handler = '';
  105. var $image_handler = '';
  106. var $multifeed_url = array();
  107. var $multifeed_objects = array();
  108. var $config_settings = null;
  109. var $item_limit = 0;
  110. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  111. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  112. function SimplePie($feed_url = null, $cache_location = null, $cache_duration = null)
  113. {
  114. $this->sanitize =& new SimplePie_Sanitize;
  115. if ($cache_location !== null)
  116. {
  117. $this->set_cache_location($cache_location);
  118. }
  119. if ($cache_duration !== null)
  120. {
  121. $this->set_cache_duration($cache_duration);
  122. }
  123. if ($feed_url !== null)
  124. {
  125. $this->set_feed_url($feed_url);
  126. $this->init();
  127. }
  128. }
  129. function __toString()
  130. {
  131. return md5(serialize($this->data));
  132. }
  133. function __destruct()
  134. {
  135. if (!empty($this->data['items']))
  136. {
  137. foreach ($this->data['items'] as $item)
  138. {
  139. $item->__destruct();
  140. }
  141. unset($this->data['items']);
  142. }
  143. if (!empty($this->data['ordered_items']))
  144. {
  145. foreach ($this->data['ordered_items'] as $item)
  146. {
  147. $item->__destruct();
  148. }
  149. unset($this->data['ordered_items']);
  150. }
  151. }
  152. function force_feed($enable = false)
  153. {
  154. $this->force_feed = (bool) $enable;
  155. }
  156. function set_feed_url($url)
  157. {
  158. if (is_array($url))
  159. {
  160. $this->multifeed_url = array();
  161. foreach ($url as $value)
  162. {
  163. $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1);
  164. }
  165. }
  166. else
  167. {
  168. $this->feed_url = SimplePie_Misc::fix_protocol($url, 1);
  169. }
  170. }
  171. function set_file(&$file)
  172. {
  173. if (is_a($file, 'SimplePie_File'))
  174. {
  175. $this->feed_url = $file->url;
  176. $this->file =& $file;
  177. return true;
  178. }
  179. return false;
  180. }
  181. function set_raw_data($data)
  182. {
  183. $this->raw_data = $data;
  184. }
  185. function set_timeout($timeout = 10)
  186. {
  187. $this->timeout = (int) $timeout;
  188. }
  189. function force_fsockopen($enable = false)
  190. {
  191. $this->force_fsockopen = (bool) $enable;
  192. }
  193. function enable_xml_dump($enable = false)
  194. {
  195. $this->xml_dump = (bool) $enable;
  196. }
  197. function enable_cache($enable = true)
  198. {
  199. $this->cache = (bool) $enable;
  200. }
  201. function set_cache_duration($seconds = 3600)
  202. {
  203. $this->cache_duration = (int) $seconds;
  204. }
  205. function set_autodiscovery_cache_duration($seconds = 604800)
  206. {
  207. $this->autodiscovery_cache_duration = (int) $seconds;
  208. }
  209. function set_cache_location($location = './cache')
  210. {
  211. $this->cache_location = (string) $location;
  212. }
  213. function enable_order_by_date($enable = true)
  214. {
  215. $this->order_by_date = (bool) $enable;
  216. }
  217. function set_input_encoding($encoding = false)
  218. {
  219. if ($encoding)
  220. {
  221. $this->input_encoding = (string) $encoding;
  222. }
  223. else
  224. {
  225. $this->input_encoding = false;
  226. }
  227. }
  228. function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  229. {
  230. $this->autodiscovery = (int) $level;
  231. }
  232. function set_cache_class($class = 'SimplePie_Cache')
  233. {
  234. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Cache'))
  235. {
  236. $this->cache_class = $class;
  237. return true;
  238. }
  239. return false;
  240. }
  241. function set_locator_class($class = 'SimplePie_Locator')
  242. {
  243. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Locator'))
  244. {
  245. $this->locator_class = $class;
  246. return true;
  247. }
  248. return false;
  249. }
  250. function set_parser_class($class = 'SimplePie_Parser')
  251. {
  252. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Parser'))
  253. {
  254. $this->parser_class = $class;
  255. return true;
  256. }
  257. return false;
  258. }
  259. function set_file_class($class = 'SimplePie_File')
  260. {
  261. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_File'))
  262. {
  263. $this->file_class = $class;
  264. return true;
  265. }
  266. return false;
  267. }
  268. function set_sanitize_class($class = 'SimplePie_Sanitize')
  269. {
  270. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Sanitize'))
  271. {
  272. $this->sanitize =& new $class;
  273. return true;
  274. }
  275. return false;
  276. }
  277. function set_item_class($class = 'SimplePie_Item')
  278. {
  279. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Item'))
  280. {
  281. $this->item_class = $class;
  282. return true;
  283. }
  284. return false;
  285. }
  286. function set_author_class($class = 'SimplePie_Author')
  287. {
  288. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Author'))
  289. {
  290. $this->author_class = $class;
  291. return true;
  292. }
  293. return false;
  294. }
  295. function set_category_class($class = 'SimplePie_Category')
  296. {
  297. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Category'))
  298. {
  299. $this->category_class = $class;
  300. return true;
  301. }
  302. return false;
  303. }
  304. function set_enclosure_class($class = 'SimplePie_Enclosure')
  305. {
  306. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Enclosure'))
  307. {
  308. $this->enclosure_class = $class;
  309. return true;
  310. }
  311. return false;
  312. }
  313. function set_caption_class($class = 'SimplePie_Caption')
  314. {
  315. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Caption'))
  316. {
  317. $this->caption_class = $class;
  318. return true;
  319. }
  320. return false;
  321. }
  322. function set_copyright_class($class = 'SimplePie_Copyright')
  323. {
  324. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Copyright'))
  325. {
  326. $this->copyright_class = $class;
  327. return true;
  328. }
  329. return false;
  330. }
  331. function set_credit_class($class = 'SimplePie_Credit')
  332. {
  333. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Credit'))
  334. {
  335. $this->credit_class = $class;
  336. return true;
  337. }
  338. return false;
  339. }
  340. function set_rating_class($class = 'SimplePie_Rating')
  341. {
  342. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Rating'))
  343. {
  344. $this->rating_class = $class;
  345. return true;
  346. }
  347. return false;
  348. }
  349. function set_restriction_class($class = 'SimplePie_Restriction')
  350. {
  351. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Restriction'))
  352. {
  353. $this->restriction_class = $class;
  354. return true;
  355. }
  356. return false;
  357. }
  358. function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
  359. {
  360. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Content_Type_Sniffer'))
  361. {
  362. $this->content_type_sniffer_class = $class;
  363. return true;
  364. }
  365. return false;
  366. }
  367. function set_source_class($class = 'SimplePie_Source')
  368. {
  369. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Source'))
  370. {
  371. $this->source_class = $class;
  372. return true;
  373. }
  374. return false;
  375. }
  376. function set_useragent($ua = SIMPLEPIE_USERAGENT)
  377. {
  378. $this->useragent = (string) $ua;
  379. }
  380. function set_cache_name_function($function = 'md5')
  381. {
  382. if (is_callable($function))
  383. {
  384. $this->cache_name_function = $function;
  385. }
  386. }
  387. function set_javascript($get = 'js')
  388. {
  389. if ($get)
  390. {
  391. $this->javascript = (string) $get;
  392. }
  393. else
  394. {
  395. $this->javascript = false;
  396. }
  397. }
  398. function set_stupidly_fast($set = false)
  399. {
  400. if ($set)
  401. {
  402. $this->enable_order_by_date(false);
  403. $this->remove_div(false);
  404. $this->strip_comments(false);
  405. $this->strip_htmltags(false);
  406. $this->strip_attributes(false);
  407. $this->set_image_handler(false);
  408. }
  409. }
  410. function set_max_checked_feeds($max = 10)
  411. {
  412. $this->max_checked_feeds = (int) $max;
  413. }
  414. function remove_div($enable = true)
  415. {
  416. $this->sanitize->remove_div($enable);
  417. }
  418. function strip_htmltags($tags = '', $encode = null)
  419. {
  420. if ($tags === '')
  421. {
  422. $tags = $this->strip_htmltags;
  423. }
  424. $this->sanitize->strip_htmltags($tags);
  425. if ($encode !== null)
  426. {
  427. $this->sanitize->encode_instead_of_strip($tags);
  428. }
  429. }
  430. function encode_instead_of_strip($enable = true)
  431. {
  432. $this->sanitize->encode_instead_of_strip($enable);
  433. }
  434. function strip_attributes($attribs = '')
  435. {
  436. if ($attribs === '')
  437. {
  438. $attribs = $this->strip_attributes;
  439. }
  440. $this->sanitize->strip_attributes($attribs);
  441. }
  442. function set_output_encoding($encoding = 'UTF-8')
  443. {
  444. $this->sanitize->set_output_encoding($encoding);
  445. }
  446. function strip_comments($strip = false)
  447. {
  448. $this->sanitize->strip_comments($strip);
  449. }
  450. function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite'))
  451. {
  452. $this->sanitize->set_url_replacements($element_attribute);
  453. }
  454. function set_favicon_handler($page = false, $qs = 'i')
  455. {
  456. if ($page != false)
  457. {
  458. $this->favicon_handler = $page . '?' . $qs . '=';
  459. }
  460. else
  461. {
  462. $this->favicon_handler = '';
  463. }
  464. }
  465. function set_image_handler($page = false, $qs = 'i')
  466. {
  467. if ($page != false)
  468. {
  469. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  470. }
  471. else
  472. {
  473. $this->image_handler = '';
  474. }
  475. }
  476. function set_item_limit($limit = 0)
  477. {
  478. $this->item_limit = (int) $limit;
  479. }
  480. function init()
  481. {
  482. if ((function_exists('version_compare') && version_compare(PHP_VERSION, '4.3.0', '<')) || !extension_loaded('xml') || !extension_loaded('pcre'))
  483. {
  484. return false;
  485. }
  486. if (isset($_GET[$this->javascript]))
  487. {
  488. if (function_exists('ob_gzhandler'))
  489. {
  490. ob_start('ob_gzhandler');
  491. }
  492. header('Content-type: text/javascript; charset: UTF-8');
  493. header('Cache-Control: must-revalidate');
  494. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  495. ?>
  496. function embed_odeo(link) {
  497. document.writeln('<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed>');
  498. }
  499. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
  500. if (placeholder != '') {
  501. 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>');
  502. }
  503. else {
  504. 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>');
  505. }
  506. }
  507. function embed_flash(bgcolor, width, height, link, loop, type) {
  508. 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>');
  509. }
  510. function embed_flv(width, height, link, placeholder, loop, player) {
  511. 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>');
  512. }
  513. function embed_wmedia(width, height, link) {
  514. document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
  515. }
  516. <?php
  517. exit;
  518. }
  519. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->cache_class);
  520. $this->sanitize->pass_file_data($this->file_class, $this->timeout, $this->useragent, $this->force_fsockopen);
  521. if ($this->feed_url !== null || $this->raw_data !== null)
  522. {
  523. $this->data = array();
  524. $this->multifeed_objects = array();
  525. $cache = false;
  526. if ($this->feed_url !== null)
  527. {
  528. $parsed_feed_url = SimplePie_Misc::parse_url($this->feed_url);
  529. if ($this->cache && $parsed_feed_url['scheme'] !== '')
  530. {
  531. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc');
  532. }
  533. if ($cache && !$this->xml_dump)
  534. {
  535. $this->data = $cache->load();
  536. if (!empty($this->data))
  537. {
  538. if (!isset($this->data['build']) || $this->data['build'] != SIMPLEPIE_BUILD)
  539. {
  540. $cache->unlink();
  541. $this->data = array();
  542. }
  543. elseif (isset($this->data['url']) && $this->data['url'] != $this->feed_url)
  544. {
  545. $cache = false;
  546. $this->data = array();
  547. }
  548. elseif (isset($this->data['feed_url']))
  549. {
  550. if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
  551. {
  552. if ($this->data['feed_url'] == $this->data['url'])
  553. {
  554. $cache->unlink();
  555. $this->data = array();
  556. }
  557. else
  558. {
  559. $this->set_feed_url($this->data['feed_url']);
  560. return $this->init();
  561. }
  562. }
  563. }
  564. // Check if the cache has been updated
  565. elseif ($cache->mtime() + $this->cache_duration < time())
  566. {
  567. // If we have last-modified and/or etag set
  568. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
  569. {
  570. $headers = array();
  571. if (isset($this->data['headers']['last-modified']))
  572. {
  573. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  574. }
  575. if (isset($this->data['headers']['etag']))
  576. {
  577. $headers['if-none-match'] = '"' . $this->data['headers']['etag'] . '"';
  578. }
  579. $file =& new $this->file_class($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);
  580. if ($file->success)
  581. {
  582. if ($file->status_code == 304)
  583. {
  584. $cache->touch();
  585. return true;
  586. }
  587. else
  588. {
  589. $headers = $file->headers;
  590. }
  591. }
  592. else
  593. {
  594. unset($file);
  595. }
  596. }
  597. }
  598. // If the cache is still valid, just return true
  599. else
  600. {
  601. return true;
  602. }
  603. }
  604. // If the cache is empty, delete it
  605. else
  606. {
  607. $cache->unlink();
  608. $this->data = array();
  609. }
  610. }
  611. // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.
  612. if (!isset($file))
  613. {
  614. if (is_a($this->file, 'SimplePie_File') && $this->file->url == $this->feed_url)
  615. {
  616. $file =& $this->file;
  617. }
  618. else
  619. {
  620. $file =& new $this->file_class($this->feed_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);
  621. }
  622. }
  623. // If the file connection has an error, set SimplePie::error to that and quit
  624. if (!$file->success)
  625. {
  626. $this->error = $file->error;
  627. if (!empty($this->data))
  628. {
  629. return true;
  630. }
  631. else
  632. {
  633. return false;
  634. }
  635. }
  636. if (!$this->force_feed)
  637. {
  638. // Check if the supplied URL is a feed, if it isn't, look for it.
  639. $locate =& new $this->locator_class($file, $this->timeout, $this->useragent, $this->file_class, $this->max_checked_feeds, $this->content_type_sniffer_class);
  640. if (!$locate->is_feed($file))
  641. {
  642. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
  643. unset($file);
  644. if ($file = $locate->find($this->autodiscovery))
  645. {
  646. if ($cache)
  647. {
  648. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  649. if (!$cache->save($this))
  650. {
  651. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  652. }
  653. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
  654. }
  655. $this->feed_url = $file->url;
  656. }
  657. else
  658. {
  659. $this->error = "A feed could not be found at $this->feed_url";
  660. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  661. return false;
  662. }
  663. }
  664. $locate = null;
  665. }
  666. $headers = $file->headers;
  667. $data = $file->body;
  668. $sniffer = new $this->content_type_sniffer_class($file);
  669. $sniffed = $sniffer->get_type();
  670. }
  671. else
  672. {
  673. $data = $this->raw_data;
  674. }
  675. // Set up array of possible encodings
  676. $encodings = array();
  677. // First check to see if input has been overridden.
  678. if ($this->input_encoding !== false)
  679. {
  680. $encodings[] = $this->input_encoding;
  681. }
  682. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  683. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  684. // RFC 3023 (only applies to sniffed content)
  685. if (isset($sniffed))
  686. {
  687. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
  688. {
  689. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  690. {
  691. $encodings[] = strtoupper($charset[1]);
  692. }
  693. $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
  694. $encodings[] = 'UTF-8';
  695. }
  696. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
  697. {
  698. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  699. {
  700. $encodings[] = $charset[1];
  701. }
  702. $encodings[] = 'US-ASCII';
  703. }
  704. // Text MIME-type default
  705. elseif (substr($sniffed, 0, 5) === 'text/')
  706. {
  707. $encodings[] = 'US-ASCII';
  708. }
  709. }
  710. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
  711. $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
  712. $encodings[] = 'UTF-8';
  713. $encodings[] = 'ISO-8859-1';
  714. // There's no point in trying an encoding twice
  715. $encodings = array_unique($encodings);
  716. // If we want the XML, just output that with the most likely encoding and quit
  717. if ($this->xml_dump)
  718. {
  719. header('Content-type: text/xml; charset=' . $encodings[0]);
  720. echo $data;
  721. exit;
  722. }
  723. // Loop through each possible encoding, till we return something, or run out of possibilities
  724. foreach ($encodings as $encoding)
  725. {
  726. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  727. if ($utf8_data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8'))
  728. {
  729. // Create new parser
  730. $parser =& new $this->parser_class();
  731. // If it's parsed fine
  732. if ($parser->parse($utf8_data, 'UTF-8'))
  733. {
  734. $this->data = $parser->get_data();
  735. if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE)
  736. {
  737. if (isset($headers))
  738. {
  739. $this->data['headers'] = $headers;
  740. }
  741. $this->data['build'] = SIMPLEPIE_BUILD;
  742. // Cache the file if caching is enabled
  743. if ($cache && !$cache->save($this))
  744. {
  745. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  746. }
  747. return true;
  748. }
  749. else
  750. {
  751. $this->error = "A feed could not be found at $this->feed_url";
  752. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  753. return false;
  754. }
  755. }
  756. }
  757. }
  758. // We have an error, just set SimplePie::error to it and quit
  759. $this->error = sprintf('XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
  760. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  761. return false;
  762. }
  763. elseif (!empty($this->multifeed_url))
  764. {
  765. $i = 0;
  766. $success = 0;
  767. $this->multifeed_objects = array();
  768. foreach ($this->multifeed_url as $url)
  769. {
  770. if (SIMPLEPIE_PHP5)
  771. {
  772. // This keyword needs to defy coding standards for PHP4 compatibility
  773. $this->multifeed_objects[$i] = clone($this);
  774. }
  775. else
  776. {
  777. $this->multifeed_objects[$i] = $this;
  778. }
  779. $this->multifeed_objects[$i]->set_feed_url($url);
  780. $success |= $this->multifeed_objects[$i]->init();
  781. $i++;
  782. }
  783. return (bool) $success;
  784. }
  785. else
  786. {
  787. return false;
  788. }
  789. }
  790. /**
  791. * Return the error message for the occured error
  792. *
  793. * @access public
  794. * @return string Error message
  795. */
  796. function error()
  797. {
  798. return $this->error;
  799. }
  800. function get_encoding()
  801. {
  802. return $this->sanitize->output_encoding;
  803. }
  804. function handle_content_type($mime = 'text/html')
  805. {
  806. if (!headers_sent())
  807. {
  808. $header = "Content-type: $mime;";
  809. if ($this->get_encoding())
  810. {
  811. $header .= ' charset=' . $this->get_encoding();
  812. }
  813. else
  814. {
  815. $header .= ' charset=UTF-8';
  816. }
  817. header($header);
  818. }
  819. }
  820. function get_type()
  821. {
  822. if (!isset($this->data['type']))
  823. {
  824. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  825. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
  826. {
  827. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  828. }
  829. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
  830. {
  831. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  832. }
  833. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
  834. {
  835. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  836. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  837. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  838. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
  839. {
  840. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  841. }
  842. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  843. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  844. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  845. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
  846. {
  847. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  848. }
  849. }
  850. elseif (isset($this->data['child']['']['rss']))
  851. {
  852. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  853. if (isset($this->data['child']['']['rss'][0]['attribs']['']['version']))
  854. {
  855. switch (trim($this->data['child']['']['rss'][0]['attribs']['']['version']))
  856. {
  857. case '0.91':
  858. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  859. if (isset($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data']))
  860. {
  861. switch (trim($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data']))
  862. {
  863. case '0':
  864. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  865. break;
  866. case '24':
  867. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  868. break;
  869. }
  870. }
  871. break;
  872. case '0.92':
  873. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  874. break;
  875. case '0.93':
  876. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  877. break;
  878. case '0.94':
  879. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  880. break;
  881. case '2.0':
  882. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  883. break;
  884. }
  885. }
  886. }
  887. else
  888. {
  889. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  890. }
  891. }
  892. return $this->data['type'];
  893. }
  894. /**
  895. * Returns the URL for the favicon of the feed's website.
  896. *
  897. * @todo Cache atom:icon
  898. * @access public
  899. * @since 1.0
  900. */
  901. function get_favicon()
  902. {
  903. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  904. {
  905. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  906. }
  907. elseif (($url = $this->get_link()) !== null && preg_match('/^http(s)?:\/\//i', $url))
  908. {
  909. $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $url);
  910. if ($this->cache && $this->favicon_handler)
  911. {
  912. $favicon_filename = call_user_func($this->cache_name_function, $favicon);
  913. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $favicon_filename, 'spi');
  914. if ($cache->load())
  915. {
  916. return $this->sanitize($this->favicon_handler . $favicon_filename, SIMPLEPIE_CONSTRUCT_IRI);
  917. }
  918. else
  919. {
  920. $file =& new $this->file_class($favicon, $this->timeout / 10, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
  921. if ($file->success && ($file->status_code == 200 || ($file->status_code > 206 && $file->status_code < 300)) && strlen($file->body) > 0)
  922. {
  923. $sniffer = new $this->content_type_sniffer_class($file);
  924. if (substr($sniffer->get_type(), 0, 6) === 'image/')
  925. {
  926. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  927. {
  928. return $this->sanitize($this->favicon_handler . $favicon_filename, SIMPLEPIE_CONSTRUCT_IRI);
  929. }
  930. else
  931. {
  932. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  933. return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);
  934. }
  935. }
  936. }
  937. }
  938. }
  939. else
  940. {
  941. return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);
  942. }
  943. }
  944. return false;
  945. }
  946. /**
  947. * @todo If we have a perm redirect we should return the new URL
  948. * @todo When we make the above change, let's support <itunes:new-feed-url> as well
  949. * @todo Also, |atom:link|@rel=self
  950. */
  951. function subscribe_url()
  952. {
  953. if ($this->feed_url !== null)
  954. {
  955. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
  956. }
  957. else
  958. {
  959. return null;
  960. }
  961. }
  962. function subscribe_feed()
  963. {
  964. if ($this->feed_url !== null)
  965. {
  966. return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);
  967. }
  968. else
  969. {
  970. return null;
  971. }
  972. }
  973. function subscribe_outlook()
  974. {
  975. if ($this->feed_url !== null)
  976. {
  977. return 'outlook' . $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);
  978. }
  979. else
  980. {
  981. return null;
  982. }
  983. }
  984. function subscribe_podcast()
  985. {
  986. if ($this->feed_url !== null)
  987. {
  988. return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 3), SIMPLEPIE_CONSTRUCT_IRI);
  989. }
  990. else
  991. {
  992. return null;
  993. }
  994. }
  995. function subscribe_itunes()
  996. {
  997. if ($this->feed_url !== null)
  998. {
  999. return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 4), SIMPLEPIE_CONSTRUCT_IRI);
  1000. }
  1001. else
  1002. {
  1003. return null;
  1004. }
  1005. }
  1006. /**
  1007. * Creates the subscribe_* methods' return data
  1008. *
  1009. * @access private
  1010. * @param string $feed_url String to prefix to the feed URL
  1011. * @param string $site_url String to prefix to the site URL (and
  1012. * suffix to the feed URL)
  1013. * @return mixed URL if feed exists, false otherwise
  1014. */
  1015. function subscribe_service($feed_url, $site_url = null)
  1016. {
  1017. if ($this->subscribe_url())
  1018. {
  1019. $return = $this->sanitize($feed_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->feed_url);
  1020. if ($site_url !== null && $this->get_link() !== null)
  1021. {
  1022. $return .= $this->sanitize($site_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_link());
  1023. }
  1024. return $return;
  1025. }
  1026. else
  1027. {
  1028. return null;
  1029. }
  1030. }
  1031. function subscribe_aol()
  1032. {
  1033. return $this->subscribe_service('http://feeds.my.aol.com/add.jsp?url=');
  1034. }
  1035. function subscribe_bloglines()
  1036. {
  1037. return urldecode($this->subscribe_service('http://www.bloglines.com/sub/'));
  1038. }
  1039. function subscribe_eskobo()
  1040. {
  1041. return $this->subscribe_service('http://www.eskobo.com/?AddToMyPage=');
  1042. }
  1043. function subscribe_feedfeeds()
  1044. {
  1045. return $this->subscribe_service('http://www.feedfeeds.com/add?feed=');
  1046. }
  1047. function subscribe_feedster()
  1048. {
  1049. return $this->subscribe_service('http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl=');
  1050. }
  1051. function subscribe_google()
  1052. {
  1053. return $this->subscribe_service('http://fusion.google.com/add?feedurl=');
  1054. }
  1055. function subscribe_gritwire()
  1056. {
  1057. return $this->subscribe_service('http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=');
  1058. }
  1059. function subscribe_msn()
  1060. {
  1061. return $this->subscribe_service('http://my.msn.com/addtomymsn.armx?id=rss&ut=', '&ru=');
  1062. }
  1063. function subscribe_netvibes()
  1064. {
  1065. return $this->subscribe_service('http://www.netvibes.com/subscribe.php?url=');
  1066. }
  1067. function subscribe_newsburst()
  1068. {
  1069. return $this->subscribe_service('http://www.newsburst.com/Source/?add=');
  1070. }
  1071. function subscribe_newsgator()
  1072. {
  1073. return $this->subscribe_service('http://www.newsgator.com/ngs/subscriber/subext.aspx?url=');
  1074. }
  1075. function subscribe_odeo()
  1076. {
  1077. return $this->subscribe_service('http://www.odeo.com/listen/subscribe?feed=');
  1078. }
  1079. function subscribe_podnova()
  1080. {
  1081. return $this->subscribe_service('http://www.podnova.com/index_your_podcasts.srf?action=add&url=');
  1082. }
  1083. function subscribe_rojo()
  1084. {
  1085. return $this->subscribe_service('http://www.rojo.com/add-subscription?resource=');
  1086. }
  1087. function subscribe_yahoo()
  1088. {
  1089. return $this->subscribe_service('http://add.my.yahoo.com/rss?url=');
  1090. }
  1091. function get_feed_tags($namespace, $tag)
  1092. {
  1093. $type = $this->get_type();
  1094. if ($type & SIMPLEPIE_TYPE_ATOM_10)
  1095. {
  1096. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
  1097. {
  1098. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  1099. }
  1100. }
  1101. if ($type & SIMPLEPIE_TYPE_ATOM_03)
  1102. {
  1103. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
  1104. {
  1105. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  1106. }
  1107. }
  1108. if ($type & SIMPLEPIE_TYPE_RSS_RDF)
  1109. {
  1110. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
  1111. {
  1112. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  1113. }
  1114. }
  1115. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1116. {
  1117. if (isset($this->data['child']['']['rss'][0]['child'][$namespace][$tag]))
  1118. {
  1119. return $this->data['child']['']['rss'][0]['child'][$namespace][$tag];
  1120. }
  1121. }
  1122. return null;
  1123. }
  1124. function get_channel_tags($namespace, $tag)
  1125. {
  1126. $type = $this->get_type();
  1127. if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
  1128. {
  1129. if ($return = $this->get_feed_tags($namespace, $tag))
  1130. {
  1131. return $return;
  1132. }
  1133. }
  1134. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1135. {
  1136. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
  1137. {
  1138. if (isset($channel[0]['child'][$namespace][$tag]))
  1139. {
  1140. return $channel[0]['child'][$namespace][$tag];
  1141. }
  1142. }
  1143. }
  1144. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1145. {
  1146. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
  1147. {
  1148. if (isset($channel[0]['child'][$namespace][$tag]))
  1149. {
  1150. return $channel[0]['child'][$namespace][$tag];
  1151. }
  1152. }
  1153. }
  1154. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1155. {
  1156. if ($channel = $this->get_feed_tags('', 'channel'))
  1157. {
  1158. if (isset($channel[0]['child'][$namespace][$tag]))
  1159. {
  1160. return $channel[0]['child'][$namespace][$tag];
  1161. }
  1162. }
  1163. }
  1164. return null;
  1165. }
  1166. function get_image_tags($namespace, $tag)
  1167. {
  1168. $type = $this->get_type();
  1169. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1170. {
  1171. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
  1172. {
  1173. if (isset($image[0]['child'][$namespace][$tag]))
  1174. {
  1175. return $image[0]['child'][$namespace][$tag];
  1176. }
  1177. }
  1178. }
  1179. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1180. {
  1181. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
  1182. {
  1183. if (isset($image[0]['child'][$namespace][$tag]))
  1184. {
  1185. return $image[0]['child'][$namespace][$tag];
  1186. }
  1187. }
  1188. }
  1189. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1190. {
  1191. if ($image = $this->get_channel_tags('', 'image'))
  1192. {
  1193. if (isset($image[0]['child'][$namespace][$tag]))
  1194. {
  1195. return $image[0]['child'][$namespace][$tag];
  1196. }
  1197. }
  1198. }
  1199. return null;
  1200. }
  1201. function get_base($element = array())
  1202. {
  1203. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
  1204. {
  1205. return $element['xml_base'];
  1206. }
  1207. elseif ($this->get_link() !== null)
  1208. {
  1209. return $this->get_link();
  1210. }
  1211. else
  1212. {
  1213. return $this->subscribe_url();
  1214. }
  1215. }
  1216. function sanitize($data, $type, $base = '')
  1217. {
  1218. return $this->sanitize->sanitize($data, $type, $base);
  1219. }
  1220. function get_title()
  1221. {
  1222. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  1223. {
  1224. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1225. }
  1226. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  1227. {
  1228. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1229. }
  1230. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  1231. {
  1232. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1233. }
  1234. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  1235. {
  1236. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1237. }
  1238. elseif ($return = $this->get_channel_tags('', 'title'))
  1239. {
  1240. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1241. }
  1242. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  1243. {
  1244. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1245. }
  1246. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  1247. {
  1248. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1249. }
  1250. else
  1251. {
  1252. return null;
  1253. }
  1254. }
  1255. function get_category($key = 0)
  1256. {
  1257. $categories = $this->get_categories();
  1258. if (isset($categories[$key]))
  1259. {
  1260. return $categories[$key];
  1261. }
  1262. else
  1263. {
  1264. return null;
  1265. }
  1266. }
  1267. function get_categories()
  1268. {
  1269. $categories = array();
  1270. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  1271. {
  1272. $term = null;
  1273. $scheme = null;
  1274. $label = null;
  1275. if (isset($category['attribs']['']['term']))
  1276. {
  1277. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  1278. }
  1279. if (isset($category['attribs']['']['scheme']))
  1280. {
  1281. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1282. }
  1283. if (isset($category['attribs']['']['label']))
  1284. {
  1285. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1286. }
  1287. $categories[] =& new $this->category_class($term, $scheme, $label);
  1288. }
  1289. foreach ((array) $this->get_channel_tags('', 'category') as $category)
  1290. {
  1291. $categories[] =& new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1292. }
  1293. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  1294. {
  1295. $categories[] =& new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1296. }
  1297. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  1298. {
  1299. $categories[] =& new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1300. }
  1301. if (!empty($categories))
  1302. {
  1303. return SimplePie_Misc::array_unique($categories);
  1304. }
  1305. else
  1306. {
  1307. return null;
  1308. }
  1309. }
  1310. function get_author($key = 0)
  1311. {
  1312. $authors = $this->get_authors();
  1313. if (isset($authors[$key]))
  1314. {
  1315. return $authors[$key];
  1316. }
  1317. else
  1318. {
  1319. return null;
  1320. }
  1321. }
  1322. function get_authors()
  1323. {
  1324. $authors = array();
  1325. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  1326. {
  1327. $name = null;
  1328. $uri = null;
  1329. $email = null;
  1330. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  1331. {
  1332. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1333. }
  1334. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  1335. {
  1336. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  1337. }
  1338. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  1339. {
  1340. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1341. }
  1342. if ($name !== null || $email !== null || $uri !== null)
  1343. {
  1344. $authors[] =& new $this->author_class($name, $uri, $email);
  1345. }
  1346. }
  1347. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  1348. {
  1349. $name = null;
  1350. $url = null;
  1351. $email = null;
  1352. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  1353. {
  1354. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1355. }
  1356. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  1357. {
  1358. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  1359. }
  1360. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  1361. {
  1362. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1363. }
  1364. if ($name !== null || $email !== null || $url !== null)
  1365. {
  1366. $authors[] =& new $this->author_class($name, $url, $email);
  1367. }
  1368. }
  1369. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  1370. {
  1371. $authors[] =& new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1372. }
  1373. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  1374. {
  1375. $authors[] =& new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1376. }
  1377. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  1378. {
  1379. $authors[] =& new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1380. }
  1381. if (!empty($authors))
  1382. {
  1383. return SimplePie_Misc::array_unique($authors);
  1384. }
  1385. else
  1386. {
  1387. return null;
  1388. }
  1389. }
  1390. function get_contributor($key = 0)
  1391. {
  1392. $contributors = $this->get_contributors();
  1393. if (isset($contributors[$key]))
  1394. {
  1395. return $contributors[$key];
  1396. }
  1397. else
  1398. {
  1399. return null;
  1400. }
  1401. }
  1402. function get_contributors()
  1403. {
  1404. $contributors = array();
  1405. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  1406. {
  1407. $name = null;
  1408. $uri = null;
  1409. $email = null;
  1410. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  1411. {
  1412. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1413. }
  1414. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  1415. {
  1416. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  1417. }
  1418. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  1419. {
  1420. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1421. }
  1422. if ($name !== null || $email !== null || $uri !== null)
  1423. {
  1424. $contributors[] =& new $this->author_class($name, $uri, $email);
  1425. }
  1426. }
  1427. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  1428. {
  1429. $name = null;
  1430. $url = null;
  1431. $email = null;
  1432. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  1433. {
  1434. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1435. }
  1436. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  1437. {
  1438. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  1439. }
  1440. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  1441. {
  1442. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1443. }
  1444. if ($name !== null || $email !== null || $url !== null)
  1445. {
  1446. $contributors[] =& new $this->author_class($name, $url, $email);
  1447. }
  1448. }
  1449. if (!empty($contributors))
  1450. {
  1451. return SimplePie_Misc::array_unique($contributors);
  1452. }
  1453. else
  1454. {
  1455. return null;
  1456. }
  1457. }
  1458. function get_link($key = 0, $rel = 'alternate')
  1459. {
  1460. $links = $this->get_links($rel);
  1461. if (isset($links[$key]))
  1462. {
  1463. return $links[$key];
  1464. }
  1465. else
  1466. {
  1467. return null;
  1468. }
  1469. }
  1470. /**
  1471. * Added for parity between the parent-level and the item/entry-level.
  1472. */
  1473. function get_permalink()
  1474. {
  1475. return $this->get_link(0);
  1476. }
  1477. function get_links($rel = 'alternate')
  1478. {
  1479. if (!isset($this->data['links']))
  1480. {
  1481. $this->data['links'] = array();
  1482. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  1483. {
  1484. foreach ($links as $link)
  1485. {
  1486. if (isset($link['attribs']['']['href']))
  1487. {
  1488. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  1489. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  1490. }
  1491. }
  1492. }
  1493. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  1494. {
  1495. foreach ($links as $link)
  1496. {
  1497. if (isset($link['attribs']['']['href']))
  1498. {
  1499. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  1500. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  1501. }
  1502. }
  1503. }
  1504. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  1505. {
  1506. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  1507. }
  1508. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  1509. {
  1510. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  1511. }
  1512. if ($links = $this->get_channel_tags('', 'link'))
  1513. {
  1514. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  1515. }
  1516. $keys = array_keys($this->data['links']);
  1517. foreach ($keys as $key)
  1518. {
  1519. if (SimplePie_Misc::is_isegment_nz_nc($key))
  1520. {
  1521. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  1522. {
  1523. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  1524. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  1525. }
  1526. else
  1527. {
  1528. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  1529. }
  1530. }
  1531. elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  1532. {
  1533. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  1534. }
  1535. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  1536. }
  1537. }
  1538. if (isset($this->data['links'][$rel]))
  1539. {
  1540. return $this->data['links'][$rel];
  1541. }
  1542. else
  1543. {
  1544. return null;
  1545. }
  1546. }
  1547. function get_description()
  1548. {
  1549. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  1550. {
  1551. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1552. }
  1553. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  1554. {
  1555. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1556. }
  1557. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  1558. {
  1559. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1560. }
  1561. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  1562. {
  1563. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1564. }
  1565. elseif ($return = $this->get_channel_tags('', 'description'))
  1566. {
  1567. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1568. }
  1569. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  1570. {
  1571. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1572. }
  1573. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  1574. {
  1575. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1576. }
  1577. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  1578. {
  1579. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1580. }
  1581. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  1582. {
  1583. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  1584. }
  1585. else
  1586. {
  1587. return null;
  1588. }
  1589. }
  1590. function get_copyright()
  1591. {
  1592. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  1593. {
  1594. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1595. }
  1596. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  1597. {
  1598. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1599. }
  1600. elseif ($return = $this->get_channel_tags('', 'copyright'))
  1601. {
  1602. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1603. }
  1604. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  1605. {
  1606. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1607. }
  1608. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  1609. {
  1610. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1611. }
  1612. else
  1613. {
  1614. return null;
  1615. }
  1616. }
  1617. function get_language()
  1618. {
  1619. if ($return = $this->get_channel_tags('', 'language'))
  1620. {
  1621. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1622. }
  1623. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  1624. {
  1625. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1626. }
  1627. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  1628. {
  1629. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1630. }
  1631. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
  1632. {
  1633. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1634. }
  1635. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
  1636. {
  1637. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1638. }
  1639. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
  1640. {
  1641. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1642. }
  1643. elseif (isset($this->data['headers']['content-language']))
  1644. {
  1645. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
  1646. }
  1647. else
  1648. {
  1649. return null;
  1650. }
  1651. }
  1652. function get_latitude()
  1653. {
  1654. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  1655. {
  1656. return (float) $return[0]['data'];
  1657. }
  1658. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  1659. {
  1660. return (float) $match[1];
  1661. }
  1662. else
  1663. {
  1664. return null;
  1665. }
  1666. }
  1667. function get_longitude()
  1668. {
  1669. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  1670. {
  1671. return (float) $return[0]['data'];
  1672. }
  1673. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  1674. {
  1675. return (float) $return[0]['data'];
  1676. }
  1677. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  1678. {
  1679. return (float) $match[2];
  1680. }
  1681. else
  1682. {
  1683. return null;
  1684. }
  1685. }
  1686. function get_image_title()
  1687. {
  1688. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  1689. {
  1690. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1691. }
  1692. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  1693. {
  1694. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1695. }
  1696. elseif ($return = $this->get_image_tags('', 'title'))
  1697. {
  1698. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1699. }
  1700. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  1701. {
  1702. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1703. }
  1704. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  1705. {
  1706. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1707. }
  1708. else
  1709. {
  1710. return null;
  1711. }
  1712. }
  1713. function get_image_url()
  1714. {
  1715. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  1716. {
  1717. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  1718. }
  1719. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  1720. {
  1721. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1722. }
  1723. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  1724. {
  1725. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1726. }
  1727. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
  1728. {
  1729. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1730. }
  1731. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
  1732. {
  1733. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1734. }
  1735. elseif ($return = $this->get_image_tags('', 'url'))
  1736. {
  1737. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1738. }
  1739. else
  1740. {
  1741. return null;
  1742. }
  1743. }
  1744. function get_image_link()
  1745. {
  1746. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  1747. {
  1748. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1749. }
  1750. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  1751. {
  1752. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1753. }
  1754. elseif ($return = $this->get_image_tags('', 'link'))
  1755. {
  1756. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1757. }
  1758. else
  1759. {
  1760. return null;
  1761. }
  1762. }
  1763. function get_image_width()
  1764. {
  1765. if ($return = $this->get_image_tags('', 'width'))
  1766. {
  1767. return round($return[0]['data']);
  1768. }
  1769. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags('', 'url'))
  1770. {
  1771. return 88.0;
  1772. }
  1773. else
  1774. {
  1775. return null;
  1776. }
  1777. }
  1778. function get_image_height()
  1779. {
  1780. if ($return = $this->get_image_tags('', 'height'))
  1781. {
  1782. return round($return[0]['data']);
  1783. }
  1784. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags('', 'url'))
  1785. {
  1786. return 31.0;
  1787. }
  1788. else
  1789. {
  1790. return null;
  1791. }
  1792. }
  1793. function get_item_quantity($max = 0)
  1794. {
  1795. $qty = count($this->get_items());
  1796. if ($max == 0)
  1797. {
  1798. return $qty;
  1799. }
  1800. else
  1801. {
  1802. return ($qty > $max) ? $max : $qty;
  1803. }
  1804. }
  1805. function get_item($key = 0)
  1806. {
  1807. $items = $this->get_items();
  1808. if (isset($items[$key]))
  1809. {
  1810. return $items[$key];
  1811. }
  1812. else
  1813. {
  1814. return null;
  1815. }
  1816. }
  1817. function get_items($start = 0, $end = 0)
  1818. {
  1819. if (!empty($this->multifeed_objects))
  1820. {
  1821. return SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
  1822. }
  1823. elseif (!isset($this->data['items']))
  1824. {
  1825. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
  1826. {
  1827. $keys = array_keys($items);
  1828. foreach ($keys as $key)
  1829. {
  1830. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  1831. }
  1832. }
  1833. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
  1834. {
  1835. $keys = array_keys($items);
  1836. foreach ($keys as $key)
  1837. {
  1838. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  1839. }
  1840. }
  1841. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
  1842. {
  1843. $keys = array_keys($items);
  1844. foreach ($keys as $key)
  1845. {
  1846. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  1847. }
  1848. }
  1849. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
  1850. {
  1851. $keys = array_keys($items);
  1852. foreach ($keys as $key)
  1853. {
  1854. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  1855. }
  1856. }
  1857. if ($items = $this->get_channel_tags('', 'item'))
  1858. {
  1859. $keys = array_keys($items);
  1860. foreach ($keys as $key)
  1861. {
  1862. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  1863. }
  1864. }
  1865. }
  1866. if (!empty($this->data['items']))
  1867. {
  1868. // If we want to order it by date, check if all items have a date, and then sort it
  1869. if ($this->order_by_date)
  1870. {
  1871. if (!isset($this->data['ordered_items']))
  1872. {
  1873. $do_sort = true;
  1874. foreach ($this->data['items'] as $item)
  1875. {
  1876. if (!$item->get_date('U'))
  1877. {
  1878. $do_sort = false;
  1879. break;
  1880. }
  1881. }
  1882. $item = null;
  1883. $this->data['ordered_items'] = $this->data['items'];
  1884. if ($do_sort)
  1885. {
  1886. usort($this->data['ordered_items'], array(&$this, 'sort_items'));
  1887. }
  1888. }
  1889. $items = $this->data['ordered_items'];
  1890. }
  1891. else
  1892. {
  1893. $items = $this->data['items'];
  1894. }
  1895. // Slice the data as desired
  1896. if ($end == 0)
  1897. {
  1898. return array_slice($items, $start);
  1899. }
  1900. else
  1901. {
  1902. return array_slice($items, $start, $end);
  1903. }
  1904. }
  1905. else
  1906. {
  1907. return array();
  1908. }
  1909. }
  1910. function sort_items($a, $b)
  1911. {
  1912. return $a->get_date('U') <= $b->get_date('U');
  1913. }
  1914. function merge_items($urls, $start = 0, $end = 0, $limit = 0)
  1915. {
  1916. if (is_array($urls) && sizeof($urls) > 0)
  1917. {
  1918. $items = array();
  1919. foreach ($urls as $arg)
  1920. {
  1921. if (is_a($arg, 'SimplePie'))
  1922. {
  1923. $items = array_merge($items, $arg->get_items(0, $limit));
  1924. }
  1925. else
  1926. {
  1927. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
  1928. }
  1929. }
  1930. $do_sort = true;
  1931. foreach ($items as $item)
  1932. {
  1933. if (!$item->get_date('U'))
  1934. {
  1935. $do_sort = false;
  1936. break;
  1937. }
  1938. }
  1939. $item = null;
  1940. if ($do_sort)
  1941. {
  1942. usort($items, array('SimplePie', 'sort_items'));
  1943. }
  1944. if ($end == 0)
  1945. {
  1946. return array_slice($items, $start);
  1947. }
  1948. else
  1949. {
  1950. return array_slice($items, $start, $end);
  1951. }
  1952. }
  1953. else
  1954. {
  1955. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
  1956. return array();
  1957. }
  1958. }
  1959. }
  1960. class SimplePie_Item
  1961. {
  1962. var $feed;
  1963. var $data = array();
  1964. function SimplePie_Item($feed, $data)
  1965. {
  1966. $this->feed = $feed;
  1967. $this->data = $data;
  1968. }
  1969. function __toString()
  1970. {
  1971. return md5(serialize($this->data));
  1972. }
  1973. /**
  1974. * Remove items that link back to this before destroying this object
  1975. */
  1976. function __destruct()
  1977. {
  1978. unset($this->feed);
  1979. }
  1980. function get_item_tags($namespace, $tag)
  1981. {
  1982. if (isset($this->data['child'][$namespace][$tag]))
  1983. {
  1984. return $this->data['child'][$namespace][$tag];
  1985. }
  1986. else
  1987. {
  1988. return null;
  1989. }
  1990. }
  1991. function get_base($element = array())
  1992. {
  1993. return $this->feed->get_base($element);
  1994. }
  1995. function sanitize($data, $type, $base = '')
  1996. {
  1997. return $this->feed->sanitize($data, $type, $base);
  1998. }
  1999. function get_feed()
  2000. {
  2001. return $this->feed;
  2002. }
  2003. function get_id($hash = false)
  2004. {
  2005. if (!$hash)
  2006. {
  2007. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  2008. {
  2009. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2010. }
  2011. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  2012. {
  2013. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2014. }
  2015. elseif ($return = $this->get_item_tags('', 'guid'))
  2016. {
  2017. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2018. }
  2019. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  2020. {
  2021. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2022. }
  2023. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  2024. {
  2025. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2026. }
  2027. elseif (($return = $this->get_permalink()) !== null)
  2028. {
  2029. return $return;
  2030. }
  2031. elseif (($return = $this->get_title()) !== null)
  2032. {
  2033. return $return;
  2034. }
  2035. }
  2036. if ($this->get_permalink() !== null || $this->get_title() !== null)
  2037. {
  2038. return md5($this->get_permalink() . $this->get_title());
  2039. }
  2040. else
  2041. {
  2042. return md5(serialize($this->data));
  2043. }
  2044. }
  2045. function get_title()
  2046. {
  2047. if (!isset($this->data['title']))
  2048. {
  2049. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  2050. {
  2051. $this->data['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2052. }
  2053. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  2054. {
  2055. $this->data['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2056. }
  2057. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2058. {
  2059. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2060. }
  2061. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2062. {
  2063. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2064. }
  2065. elseif ($return = $this->get_item_tags('', 'title'))
  2066. {
  2067. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2068. }
  2069. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2070. {
  2071. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2072. }
  2073. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2074. {
  2075. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2076. }
  2077. else
  2078. {
  2079. $this->data['title'] = null;
  2080. }
  2081. }
  2082. return $this->data['title'];
  2083. }
  2084. function get_description($description_only = false)
  2085. {
  2086. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
  2087. {
  2088. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2089. }
  2090. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
  2091. {
  2092. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2093. }
  2094. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  2095. {
  2096. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2097. }
  2098. elseif ($return = $this->get_item_tags('', 'description'))
  2099. {
  2100. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2101. }
  2102. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  2103. {
  2104. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2105. }
  2106. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  2107. {
  2108. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2109. }
  2110. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  2111. {
  2112. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2113. }
  2114. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  2115. {
  2116. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2117. }
  2118. elseif (!$description_only)
  2119. {
  2120. return $this->get_content(true);
  2121. }
  2122. else
  2123. {
  2124. return null;
  2125. }
  2126. }
  2127. function get_content($content_only = false)
  2128. {
  2129. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
  2130. {
  2131. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_content_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2132. }
  2133. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
  2134. {
  2135. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2136. }
  2137. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
  2138. {
  2139. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2140. }
  2141. elseif (!$content_only)
  2142. {
  2143. return $this->get_description(true);
  2144. }
  2145. else
  2146. {
  2147. return null;
  2148. }
  2149. }
  2150. function get_category($key = 0)
  2151. {
  2152. $categories = $this->get_categories();
  2153. if (isset($categories[$key]))
  2154. {
  2155. return $categories[$key];
  2156. }
  2157. else
  2158. {
  2159. return null;
  2160. }
  2161. }
  2162. function get_categories()
  2163. {
  2164. $categories = array();
  2165. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  2166. {
  2167. $term = null;
  2168. $scheme = null;
  2169. $label = null;
  2170. if (isset($category['attribs']['']['term']))
  2171. {
  2172. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  2173. }
  2174. if (isset($category['attribs']['']['scheme']))
  2175. {
  2176. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2177. }
  2178. if (isset($category['attribs']['']['label']))
  2179. {
  2180. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2181. }
  2182. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  2183. }
  2184. foreach ((array) $this->get_item_tags('', 'category') as $category)
  2185. {
  2186. $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2187. }
  2188. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  2189. {
  2190. $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2191. }
  2192. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  2193. {
  2194. $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2195. }
  2196. if (!empty($categories))
  2197. {
  2198. return SimplePie_Misc::array_unique($categories);
  2199. }
  2200. else
  2201. {
  2202. return null;
  2203. }
  2204. }
  2205. function get_author($key = 0)
  2206. {
  2207. $authors = $this->get_authors();
  2208. if (isset($authors[$key]))
  2209. {
  2210. return $authors[$key];
  2211. }
  2212. else
  2213. {
  2214. return null;
  2215. }
  2216. }
  2217. function get_contributor($key = 0)
  2218. {
  2219. $contributors = $this->get_contributors();
  2220. if (isset($contributors[$key]))
  2221. {
  2222. return $contributors[$key];
  2223. }
  2224. else
  2225. {
  2226. return null;
  2227. }
  2228. }
  2229. function get_contributors()
  2230. {
  2231. $contributors = array();
  2232. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  2233. {
  2234. $name = null;
  2235. $uri = null;
  2236. $email = null;
  2237. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2238. {
  2239. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2240. }
  2241. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2242. {
  2243. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2244. }
  2245. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2246. {
  2247. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2248. }
  2249. if ($name !== null || $email !== null || $uri !== null)
  2250. {
  2251. $contributors[] =& new $this->feed->author_class($name, $uri, $email);
  2252. }
  2253. }
  2254. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  2255. {
  2256. $name = null;
  2257. $url = null;
  2258. $email = null;
  2259. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2260. {
  2261. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2262. }
  2263. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2264. {
  2265. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2266. }
  2267. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2268. {
  2269. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2270. }
  2271. if ($name !== null || $email !== null || $url !== null)
  2272. {
  2273. $contributors[] =& new $this->feed->author_class($name, $url, $email);
  2274. }
  2275. }
  2276. if (!empty($contributors))
  2277. {
  2278. return SimplePie_Misc::array_unique($contributors);
  2279. }
  2280. else
  2281. {
  2282. return null;
  2283. }
  2284. }
  2285. /**
  2286. * @todo Atom inheritance (item author, source author, feed author)
  2287. */
  2288. function get_authors()
  2289. {
  2290. $authors = array();
  2291. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  2292. {
  2293. $name = null;
  2294. $uri = null;
  2295. $email = null;
  2296. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2297. {
  2298. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2299. }
  2300. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2301. {
  2302. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2303. }
  2304. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2305. {
  2306. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2307. }
  2308. if ($name !== null || $email !== null || $uri !== null)
  2309. {
  2310. $authors[] =& new $this->feed->author_class($name, $uri, $email);
  2311. }
  2312. }
  2313. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  2314. {
  2315. $name = null;
  2316. $url = null;
  2317. $email = null;
  2318. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2319. {
  2320. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2321. }
  2322. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2323. {
  2324. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2325. }
  2326. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2327. {
  2328. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2329. }
  2330. if ($name !== null || $email !== null || $url !== null)
  2331. {
  2332. $authors[] =& new $this->feed->author_class($name, $url, $email);
  2333. }
  2334. }
  2335. if ($author = $this->get_item_tags('', 'author'))
  2336. {
  2337. $authors[] =& new $this->feed->author_class(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2338. }
  2339. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  2340. {
  2341. $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2342. }
  2343. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  2344. {
  2345. $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2346. }
  2347. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  2348. {
  2349. $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2350. }
  2351. if (!empty($authors))
  2352. {
  2353. return SimplePie_Misc::array_unique($authors);
  2354. }
  2355. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  2356. {
  2357. return $authors;
  2358. }
  2359. elseif ($authors = $this->feed->get_authors())
  2360. {
  2361. return $authors;
  2362. }
  2363. else
  2364. {
  2365. return null;
  2366. }
  2367. }
  2368. function get_copyright()
  2369. {
  2370. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  2371. {
  2372. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2373. }
  2374. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  2375. {
  2376. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2377. }
  2378. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  2379. {
  2380. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2381. }
  2382. else
  2383. {
  2384. return null;
  2385. }
  2386. }
  2387. function get_date($date_format = 'j F Y, g:i a')
  2388. {
  2389. if (!isset($this->data['date']))
  2390. {
  2391. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  2392. {
  2393. $this->data['date']['raw'] = $return[0]['data'];
  2394. }
  2395. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  2396. {
  2397. $this->data['date']['raw'] = $return[0]['data'];
  2398. }
  2399. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  2400. {
  2401. $this->data['date']['raw'] = $return[0]['data'];
  2402. }
  2403. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  2404. {
  2405. $this->data['date']['raw'] = $return[0]['data'];
  2406. }
  2407. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  2408. {
  2409. $this->data['date']['raw'] = $return[0]['data'];
  2410. }
  2411. elseif ($return = $this->get_item_tags('', 'pubDate'))
  2412. {
  2413. $this->data['date']['raw'] = $return[0]['data'];
  2414. }
  2415. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  2416. {
  2417. $this->data['date']['raw'] = $return[0]['data'];
  2418. }
  2419. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  2420. {
  2421. $this->data['date']['raw'] = $return[0]['data'];
  2422. }
  2423. if (!empty($this->data['date']['raw']))
  2424. {
  2425. $parser = SimplePie_Parse_Date::get();
  2426. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  2427. }
  2428. else
  2429. {
  2430. $this->data['date'] = null;
  2431. }
  2432. }
  2433. if ($this->data['date'])
  2434. {
  2435. $date_format = (string) $date_format;
  2436. switch ($date_format)
  2437. {
  2438. case '':
  2439. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  2440. case 'U':
  2441. return $this->data['date']['parsed'];
  2442. default:
  2443. return date($date_format, $this->data['date']['parsed']);
  2444. }
  2445. }
  2446. else
  2447. {
  2448. return null;
  2449. }
  2450. }
  2451. function get_local_date($date_format = '%c')
  2452. {
  2453. if (!$date_format)
  2454. {
  2455. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  2456. }
  2457. elseif (($date = $this->get_date('U')) !== null)
  2458. {
  2459. return strftime($date_format, $date);
  2460. }
  2461. else
  2462. {
  2463. return null;
  2464. }
  2465. }
  2466. function get_permalink()
  2467. {
  2468. $link = $this->get_link();
  2469. $enclosure = $this->get_enclosure(0);
  2470. if ($link !== null)
  2471. {
  2472. return $link;
  2473. }
  2474. elseif ($enclosure !== null)
  2475. {
  2476. return $enclosure->get_link();
  2477. }
  2478. else
  2479. {
  2480. return null;
  2481. }
  2482. }
  2483. function get_link($key = 0, $rel = 'alternate')
  2484. {
  2485. $links = $this->get_links($rel);
  2486. if ($links[$key] !== null)
  2487. {
  2488. return $links[$key];
  2489. }
  2490. else
  2491. {
  2492. return null;
  2493. }
  2494. }
  2495. function get_links($rel = 'alternate')
  2496. {
  2497. if (!isset($this->data['links']))
  2498. {
  2499. $this->data['links'] = array();
  2500. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  2501. {
  2502. if (isset($link['attribs']['']['href']))
  2503. {
  2504. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2505. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2506. }
  2507. }
  2508. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  2509. {
  2510. if (isset($link['attribs']['']['href']))
  2511. {
  2512. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2513. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2514. }
  2515. }
  2516. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2517. {
  2518. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2519. }
  2520. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2521. {
  2522. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2523. }
  2524. if ($links = $this->get_item_tags('', 'link'))
  2525. {
  2526. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2527. }
  2528. if ($links = $this->get_item_tags('', 'guid'))
  2529. {
  2530. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) == 'true')
  2531. {
  2532. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2533. }
  2534. }
  2535. $keys = array_keys($this->data['links']);
  2536. foreach ($keys as $key)
  2537. {
  2538. if (SimplePie_Misc::is_isegment_nz_nc($key))
  2539. {
  2540. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  2541. {
  2542. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  2543. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  2544. }
  2545. else
  2546. {
  2547. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  2548. }
  2549. }
  2550. elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  2551. {
  2552. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  2553. }
  2554. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  2555. }
  2556. }
  2557. if (isset($this->data['links'][$rel]))
  2558. {
  2559. return $this->data['links'][$rel];
  2560. }
  2561. else
  2562. {
  2563. return null;
  2564. }
  2565. }
  2566. /**
  2567. * @todo Add ability to prefer one type of content over another (in a media group).
  2568. */
  2569. function get_enclosure($key = 0, $prefer = null)
  2570. {
  2571. $enclosures = $this->get_enclosures();
  2572. if (isset($enclosures[$key]))
  2573. {
  2574. return $enclosures[$key];
  2575. }
  2576. else
  2577. {
  2578. return null;
  2579. }
  2580. }
  2581. /**
  2582. * Grabs all available enclosures (podcasts, etc.)
  2583. *
  2584. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  2585. *
  2586. * At this point, we're pretty much assuming that all enclosures for an item are the same content. Anything else is too complicated to properly support.
  2587. *
  2588. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  2589. * @todo If an element exists at a level, but it's value is empty, we should fall back to the value from the parent (if it exists).
  2590. */
  2591. function get_enclosures()
  2592. {
  2593. if (!isset($this->data['enclosures']))
  2594. {
  2595. $this->data['enclosures'] = array();
  2596. // Elements
  2597. $captions_parent = null;
  2598. $categories_parent = null;
  2599. $copyrights_parent = null;
  2600. $credits_parent = null;
  2601. $description_parent = null;
  2602. $duration_parent = null;
  2603. $hashes_parent = null;
  2604. $keywords_parent = null;
  2605. $player_parent = null;
  2606. $ratings_parent = null;
  2607. $restrictions_parent = null;
  2608. $thumbnails_parent = null;
  2609. $title_parent = null;
  2610. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  2611. $parent = $this->get_feed();
  2612. // CAPTIONS
  2613. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  2614. {
  2615. foreach ($captions as $caption)
  2616. {
  2617. $caption_type = null;
  2618. $caption_lang = null;
  2619. $caption_startTime = null;
  2620. $caption_endTime = null;
  2621. $caption_text = null;
  2622. if (isset($caption['attribs']['']['type']))
  2623. {
  2624. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2625. }
  2626. if (isset($caption['attribs']['']['lang']))
  2627. {
  2628. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2629. }
  2630. if (isset($caption['attribs']['']['start']))
  2631. {
  2632. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  2633. }
  2634. if (isset($caption['attribs']['']['end']))
  2635. {
  2636. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  2637. }
  2638. if (isset($caption['data']))
  2639. {
  2640. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2641. }
  2642. $captions_parent[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  2643. }
  2644. }
  2645. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  2646. {
  2647. foreach ($captions as $caption)
  2648. {
  2649. $caption_type = null;
  2650. $caption_lang = null;
  2651. $caption_startTime = null;
  2652. $caption_endTime = null;
  2653. $caption_text = null;
  2654. if (isset($caption['attribs']['']['type']))
  2655. {
  2656. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2657. }
  2658. if (isset($caption['attribs']['']['lang']))
  2659. {
  2660. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2661. }
  2662. if (isset($caption['attribs']['']['start']))
  2663. {
  2664. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  2665. }
  2666. if (isset($caption['attribs']['']['end']))
  2667. {
  2668. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  2669. }
  2670. if (isset($caption['data']))
  2671. {
  2672. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2673. }
  2674. $captions_parent[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  2675. }
  2676. }
  2677. if (is_array($captions_parent))
  2678. {
  2679. $captions_parent = array_values(SimplePie_Misc::array_unique($captions_parent));
  2680. }
  2681. // CATEGORIES
  2682. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  2683. {
  2684. $term = null;
  2685. $scheme = null;
  2686. $label = null;
  2687. if (isset($category['data']))
  2688. {
  2689. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2690. }
  2691. if (isset($category['attribs']['']['scheme']))
  2692. {
  2693. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2694. }
  2695. else
  2696. {
  2697. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  2698. }
  2699. if (isset($category['attribs']['']['label']))
  2700. {
  2701. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2702. }
  2703. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  2704. }
  2705. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  2706. {
  2707. $term = null;
  2708. $scheme = null;
  2709. $label = null;
  2710. if (isset($category['data']))
  2711. {
  2712. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2713. }
  2714. if (isset($category['attribs']['']['scheme']))
  2715. {
  2716. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2717. }
  2718. else
  2719. {
  2720. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  2721. }
  2722. if (isset($category['attribs']['']['label']))
  2723. {
  2724. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2725. }
  2726. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  2727. }
  2728. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  2729. {
  2730. $term = null;
  2731. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  2732. $label = null;
  2733. if (isset($category['attribs']['']['text']))
  2734. {
  2735. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  2736. }
  2737. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  2738. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  2739. {
  2740. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  2741. {
  2742. if (isset($subcategory['attribs']['']['text']))
  2743. {
  2744. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  2745. }
  2746. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  2747. }
  2748. }
  2749. }
  2750. if (is_array($categories_parent))
  2751. {
  2752. $categories_parent = array_values(SimplePie_Misc::array_unique($categories_parent));
  2753. }
  2754. // COPYRIGHT
  2755. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  2756. {
  2757. $copyright_url = null;
  2758. $copyright_label = null;
  2759. if (isset($copyright[0]['attribs']['']['url']))
  2760. {
  2761. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  2762. }
  2763. if (isset($copyright[0]['data']))
  2764. {
  2765. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2766. }
  2767. $copyrights_parent =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  2768. }
  2769. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  2770. {
  2771. $copyright_url = null;
  2772. $copyright_label = null;
  2773. if (isset($copyright[0]['attribs']['']['url']))
  2774. {
  2775. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  2776. }
  2777. if (isset($copyright[0]['data']))
  2778. {
  2779. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2780. }
  2781. $copyrights_parent =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  2782. }
  2783. // CREDITS
  2784. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  2785. {
  2786. foreach ($credits as $credit)
  2787. {
  2788. $credit_role = null;
  2789. $credit_scheme = null;
  2790. $credit_name = null;
  2791. if (isset($credit['attribs']['']['role']))
  2792. {
  2793. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  2794. }
  2795. if (isset($credit['attribs']['']['scheme']))
  2796. {
  2797. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2798. }
  2799. else
  2800. {
  2801. $credit_scheme = 'urn:ebu';
  2802. }
  2803. if (isset($credit['data']))
  2804. {
  2805. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2806. }
  2807. $credits_parent[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  2808. }
  2809. }
  2810. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  2811. {
  2812. foreach ($credits as $credit)
  2813. {
  2814. $credit_role = null;
  2815. $credit_scheme = null;
  2816. $credit_name = null;
  2817. if (isset($credit['attribs']['']['role']))
  2818. {
  2819. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  2820. }
  2821. if (isset($credit['attribs']['']['scheme']))
  2822. {
  2823. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2824. }
  2825. else
  2826. {
  2827. $credit_scheme = 'urn:ebu';
  2828. }
  2829. if (isset($credit['data']))
  2830. {
  2831. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2832. }
  2833. $credits_parent[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  2834. }
  2835. }
  2836. if (is_array($credits_parent))
  2837. {
  2838. $credits_parent = array_values(SimplePie_Misc::array_unique($credits_parent));
  2839. }
  2840. // DESCRIPTION
  2841. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  2842. {
  2843. if (isset($description_parent[0]['data']))
  2844. {
  2845. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2846. }
  2847. }
  2848. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  2849. {
  2850. if (isset($description_parent[0]['data']))
  2851. {
  2852. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2853. }
  2854. }
  2855. // DURATION
  2856. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  2857. {
  2858. $seconds = null;
  2859. $minutes = null;
  2860. $hours = null;
  2861. if (isset($duration_parent[0]['data']))
  2862. {
  2863. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2864. if (sizeof($temp) > 0)
  2865. {
  2866. (int) $seconds = array_pop($temp);
  2867. }
  2868. if (sizeof($temp) > 0)
  2869. {
  2870. (int) $minutes = array_pop($temp);
  2871. $seconds += $minutes * 60;
  2872. }
  2873. if (sizeof($temp) > 0)
  2874. {
  2875. (int) $hours = array_pop($temp);
  2876. $seconds += $hours * 3600;
  2877. }
  2878. unset($temp);
  2879. $duration_parent = $seconds;
  2880. }
  2881. }
  2882. // HASHES
  2883. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  2884. {
  2885. foreach ($hashes_iterator as $hash)
  2886. {
  2887. $value = null;
  2888. $algo = null;
  2889. if (isset($hash['data']))
  2890. {
  2891. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2892. }
  2893. if (isset($hash['attribs']['']['algo']))
  2894. {
  2895. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2896. }
  2897. else
  2898. {
  2899. $algo = 'md5';
  2900. }
  2901. $hashes_parent[] = $algo.':'.$value;
  2902. }
  2903. }
  2904. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  2905. {
  2906. foreach ($hashes_iterator as $hash)
  2907. {
  2908. $value = null;
  2909. $algo = null;
  2910. if (isset($hash['data']))
  2911. {
  2912. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2913. }
  2914. if (isset($hash['attribs']['']['algo']))
  2915. {
  2916. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2917. }
  2918. else
  2919. {
  2920. $algo = 'md5';
  2921. }
  2922. $hashes_parent[] = $algo.':'.$value;
  2923. }
  2924. }
  2925. if (is_array($hashes_parent))
  2926. {
  2927. $hashes_parent = array_values(SimplePie_Misc::array_unique($hashes_parent));
  2928. }
  2929. // KEYWORDS
  2930. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  2931. {
  2932. if (isset($keywords[0]['data']))
  2933. {
  2934. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2935. foreach ($temp as $word)
  2936. {
  2937. $keywords_parent[] = trim($word);
  2938. }
  2939. }
  2940. unset($temp);
  2941. }
  2942. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  2943. {
  2944. if (isset($keywords[0]['data']))
  2945. {
  2946. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2947. foreach ($temp as $word)
  2948. {
  2949. $keywords_parent[] = trim($word);
  2950. }
  2951. }
  2952. unset($temp);
  2953. }
  2954. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  2955. {
  2956. if (isset($keywords[0]['data']))
  2957. {
  2958. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2959. foreach ($temp as $word)
  2960. {
  2961. $keywords_parent[] = trim($word);
  2962. }
  2963. }
  2964. unset($temp);
  2965. }
  2966. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  2967. {
  2968. if (isset($keywords[0]['data']))
  2969. {
  2970. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2971. foreach ($temp as $word)
  2972. {
  2973. $keywords_parent[] = trim($word);
  2974. }
  2975. }
  2976. unset($temp);
  2977. }
  2978. if (is_array($keywords_parent))
  2979. {
  2980. $keywords_parent = array_values(SimplePie_Misc::array_unique($keywords_parent));
  2981. }
  2982. // PLAYER
  2983. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  2984. {
  2985. if (isset($player_parent[0]['attribs']['']['url']))
  2986. {
  2987. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2988. }
  2989. }
  2990. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  2991. {
  2992. if (isset($player_parent[0]['attribs']['']['url']))
  2993. {
  2994. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2995. }
  2996. }
  2997. // RATINGS
  2998. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  2999. {
  3000. foreach ($ratings as $rating)
  3001. {
  3002. $rating_scheme = null;
  3003. $rating_value = null;
  3004. if (isset($rating['attribs']['']['scheme']))
  3005. {
  3006. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3007. }
  3008. else
  3009. {
  3010. $rating_scheme = 'urn:simple';
  3011. }
  3012. if (isset($rating['data']))
  3013. {
  3014. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3015. }
  3016. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3017. }
  3018. }
  3019. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  3020. {
  3021. foreach ($ratings as $rating)
  3022. {
  3023. $rating_scheme = 'urn:itunes';
  3024. $rating_value = null;
  3025. if (isset($rating['data']))
  3026. {
  3027. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3028. }
  3029. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3030. }
  3031. }
  3032. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  3033. {
  3034. foreach ($ratings as $rating)
  3035. {
  3036. $rating_scheme = null;
  3037. $rating_value = null;
  3038. if (isset($rating['attribs']['']['scheme']))
  3039. {
  3040. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3041. }
  3042. else
  3043. {
  3044. $rating_scheme = 'urn:simple';
  3045. }
  3046. if (isset($rating['data']))
  3047. {
  3048. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3049. }
  3050. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3051. }
  3052. }
  3053. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  3054. {
  3055. foreach ($ratings as $rating)
  3056. {
  3057. $rating_scheme = 'urn:itunes';
  3058. $rating_value = null;
  3059. if (isset($rating['data']))
  3060. {
  3061. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3062. }
  3063. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3064. }
  3065. }
  3066. if (is_array($ratings_parent))
  3067. {
  3068. $ratings_parent = array_values(SimplePie_Misc::array_unique($ratings_parent));
  3069. }
  3070. // RESTRICTIONS
  3071. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  3072. {
  3073. foreach ($restrictions as $restriction)
  3074. {
  3075. $restriction_relationship = null;
  3076. $restriction_type = null;
  3077. $restriction_value = null;
  3078. if (isset($restriction['attribs']['']['relationship']))
  3079. {
  3080. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  3081. }
  3082. if (isset($restriction['attribs']['']['type']))
  3083. {
  3084. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3085. }
  3086. if (isset($restriction['data']))
  3087. {
  3088. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3089. }
  3090. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3091. }
  3092. }
  3093. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  3094. {
  3095. foreach ($restrictions as $restriction)
  3096. {
  3097. $restriction_relationship = 'allow';
  3098. $restriction_type = null;
  3099. $restriction_value = 'itunes';
  3100. if (isset($restriction['data']) && strtolower($restriction['data']) == 'yes')
  3101. {
  3102. $restriction_relationship = 'deny';
  3103. }
  3104. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3105. }
  3106. }
  3107. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  3108. {
  3109. foreach ($restrictions as $restriction)
  3110. {
  3111. $restriction_relationship = null;
  3112. $restriction_type = null;
  3113. $restriction_value = null;
  3114. if (isset($restriction['attribs']['']['relationship']))
  3115. {
  3116. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  3117. }
  3118. if (isset($restriction['attribs']['']['type']))
  3119. {
  3120. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3121. }
  3122. if (isset($restriction['data']))
  3123. {
  3124. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3125. }
  3126. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3127. }
  3128. }
  3129. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  3130. {
  3131. foreach ($restrictions as $restriction)
  3132. {
  3133. $restriction_relationship = 'allow';
  3134. $restriction_type = null;
  3135. $restriction_value = 'itunes';
  3136. if (isset($restriction['data']) && strtolower($restriction['data']) == 'yes')
  3137. {
  3138. $restriction_relationship = 'deny';
  3139. }
  3140. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3141. }
  3142. }
  3143. if (is_array($restrictions_parent))
  3144. {
  3145. $restrictions_parent = array_values(SimplePie_Misc::array_unique($restrictions_parent));
  3146. }
  3147. // THUMBNAILS
  3148. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  3149. {
  3150. foreach ($thumbnails as $thumbnail)
  3151. {
  3152. if (isset($thumbnail['attribs']['']['url']))
  3153. {
  3154. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3155. }
  3156. }
  3157. }
  3158. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  3159. {
  3160. foreach ($thumbnails as $thumbnail)
  3161. {
  3162. if (isset($thumbnail['attribs']['']['url']))
  3163. {
  3164. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3165. }
  3166. }
  3167. }
  3168. // TITLES
  3169. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  3170. {
  3171. if (isset($title_parent[0]['data']))
  3172. {
  3173. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3174. }
  3175. }
  3176. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  3177. {
  3178. if (isset($title_parent[0]['data']))
  3179. {
  3180. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3181. }
  3182. }
  3183. // Clear the memory
  3184. unset($parent);
  3185. // Attributes
  3186. $bitrate = null;
  3187. $channels = null;
  3188. $duration = null;
  3189. $expression = null;
  3190. $framerate = null;
  3191. $height = null;
  3192. $javascript = null;
  3193. $lang = null;
  3194. $length = null;
  3195. $medium = null;
  3196. $samplingrate = null;
  3197. $type = null;
  3198. $url = null;
  3199. $width = null;
  3200. // Elements
  3201. $captions = null;
  3202. $categories = null;
  3203. $copyrights = null;
  3204. $credits = null;
  3205. $description = null;
  3206. $hashes = null;
  3207. $keywords = null;
  3208. $player = null;
  3209. $ratings = null;
  3210. $restrictions = null;
  3211. $thumbnails = null;
  3212. $title = null;
  3213. // If we have media:group tags, loop through them.
  3214. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  3215. {
  3216. // If we have media:content tags, loop through them.
  3217. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  3218. {
  3219. if (isset($content['attribs']['']['url']))
  3220. {
  3221. // Attributes
  3222. $bitrate = null;
  3223. $channels = null;
  3224. $duration = null;
  3225. $expression = null;
  3226. $framerate = null;
  3227. $height = null;
  3228. $javascript = null;
  3229. $lang = null;
  3230. $length = null;
  3231. $medium = null;
  3232. $samplingrate = null;
  3233. $type = null;
  3234. $url = null;
  3235. $width = null;
  3236. // Elements
  3237. $captions = null;
  3238. $categories = null;
  3239. $copyrights = null;
  3240. $credits = null;
  3241. $description = null;
  3242. $hashes = null;
  3243. $keywords = null;
  3244. $player = null;
  3245. $ratings = null;
  3246. $restrictions = null;
  3247. $thumbnails = null;
  3248. $title = null;
  3249. // Start checking the attributes of media:content
  3250. if (isset($content['attribs']['']['bitrate']))
  3251. {
  3252. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  3253. }
  3254. if (isset($content['attribs']['']['channels']))
  3255. {
  3256. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  3257. }
  3258. if (isset($content['attribs']['']['duration']))
  3259. {
  3260. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  3261. }
  3262. else
  3263. {
  3264. $duration = $duration_parent;
  3265. }
  3266. if (isset($content['attribs']['']['expression']))
  3267. {
  3268. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  3269. }
  3270. if (isset($content['attribs']['']['framerate']))
  3271. {
  3272. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  3273. }
  3274. if (isset($content['attribs']['']['height']))
  3275. {
  3276. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  3277. }
  3278. if (isset($content['attribs']['']['lang']))
  3279. {
  3280. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  3281. }
  3282. if (isset($content['attribs']['']['fileSize']))
  3283. {
  3284. $length = ceil($content['attribs']['']['fileSize']);
  3285. }
  3286. if (isset($content['attribs']['']['medium']))
  3287. {
  3288. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  3289. }
  3290. if (isset($content['attribs']['']['samplingrate']))
  3291. {
  3292. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  3293. }
  3294. if (isset($content['attribs']['']['type']))
  3295. {
  3296. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3297. }
  3298. if (isset($content['attribs']['']['width']))
  3299. {
  3300. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  3301. }
  3302. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3303. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  3304. // CAPTIONS
  3305. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  3306. {
  3307. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  3308. {
  3309. $caption_type = null;
  3310. $caption_lang = null;
  3311. $caption_startTime = null;
  3312. $caption_endTime = null;
  3313. $caption_text = null;
  3314. if (isset($caption['attribs']['']['type']))
  3315. {
  3316. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3317. }
  3318. if (isset($caption['attribs']['']['lang']))
  3319. {
  3320. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  3321. }
  3322. if (isset($caption['attribs']['']['start']))
  3323. {
  3324. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  3325. }
  3326. if (isset($caption['attribs']['']['end']))
  3327. {
  3328. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  3329. }
  3330. if (isset($caption['data']))
  3331. {
  3332. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3333. }
  3334. $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  3335. }
  3336. if (is_array($captions))
  3337. {
  3338. $captions = array_values(SimplePie_Misc::array_unique($captions));
  3339. }
  3340. }
  3341. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  3342. {
  3343. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  3344. {
  3345. $caption_type = null;
  3346. $caption_lang = null;
  3347. $caption_startTime = null;
  3348. $caption_endTime = null;
  3349. $caption_text = null;
  3350. if (isset($caption['attribs']['']['type']))
  3351. {
  3352. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3353. }
  3354. if (isset($caption['attribs']['']['lang']))
  3355. {
  3356. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  3357. }
  3358. if (isset($caption['attribs']['']['start']))
  3359. {
  3360. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  3361. }
  3362. if (isset($caption['attribs']['']['end']))
  3363. {
  3364. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  3365. }
  3366. if (isset($caption['data']))
  3367. {
  3368. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3369. }
  3370. $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  3371. }
  3372. if (is_array($captions))
  3373. {
  3374. $captions = array_values(SimplePie_Misc::array_unique($captions));
  3375. }
  3376. }
  3377. else
  3378. {
  3379. $captions = $captions_parent;
  3380. }
  3381. // CATEGORIES
  3382. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  3383. {
  3384. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  3385. {
  3386. $term = null;
  3387. $scheme = null;
  3388. $label = null;
  3389. if (isset($category['data']))
  3390. {
  3391. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3392. }
  3393. if (isset($category['attribs']['']['scheme']))
  3394. {
  3395. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3396. }
  3397. else
  3398. {
  3399. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  3400. }
  3401. if (isset($category['attribs']['']['label']))
  3402. {
  3403. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  3404. }
  3405. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  3406. }
  3407. }
  3408. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  3409. {
  3410. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  3411. {
  3412. $term = null;
  3413. $scheme = null;
  3414. $label = null;
  3415. if (isset($category['data']))
  3416. {
  3417. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3418. }
  3419. if (isset($category['attribs']['']['scheme']))
  3420. {
  3421. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3422. }
  3423. else
  3424. {
  3425. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  3426. }
  3427. if (isset($category['attribs']['']['label']))
  3428. {
  3429. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  3430. }
  3431. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  3432. }
  3433. }
  3434. if (is_array($categories) && is_array($categories_parent))
  3435. {
  3436. $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent)));
  3437. }
  3438. elseif (is_array($categories))
  3439. {
  3440. $categories = array_values(SimplePie_Misc::array_unique($categories));
  3441. }
  3442. elseif (is_array($categories_parent))
  3443. {
  3444. $categories = array_values(SimplePie_Misc::array_unique($categories_parent));
  3445. }
  3446. // COPYRIGHTS
  3447. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  3448. {
  3449. $copyright_url = null;
  3450. $copyright_label = null;
  3451. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  3452. {
  3453. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  3454. }
  3455. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  3456. {
  3457. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3458. }
  3459. $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  3460. }
  3461. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  3462. {
  3463. $copyright_url = null;
  3464. $copyright_label = null;
  3465. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  3466. {
  3467. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  3468. }
  3469. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  3470. {
  3471. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3472. }
  3473. $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  3474. }
  3475. else
  3476. {
  3477. $copyrights = $copyrights_parent;
  3478. }
  3479. // CREDITS
  3480. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  3481. {
  3482. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  3483. {
  3484. $credit_role = null;
  3485. $credit_scheme = null;
  3486. $credit_name = null;
  3487. if (isset($credit['attribs']['']['role']))
  3488. {
  3489. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  3490. }
  3491. if (isset($credit['attribs']['']['scheme']))
  3492. {
  3493. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3494. }
  3495. else
  3496. {
  3497. $credit_scheme = 'urn:ebu';
  3498. }
  3499. if (isset($credit['data']))
  3500. {
  3501. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3502. }
  3503. $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  3504. }
  3505. if (is_array($credits))
  3506. {
  3507. $credits = array_values(SimplePie_Misc::array_unique($credits));
  3508. }
  3509. }
  3510. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  3511. {
  3512. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  3513. {
  3514. $credit_role = null;
  3515. $credit_scheme = null;
  3516. $credit_name = null;
  3517. if (isset($credit['attribs']['']['role']))
  3518. {
  3519. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  3520. }
  3521. if (isset($credit['attribs']['']['scheme']))
  3522. {
  3523. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3524. }
  3525. else
  3526. {
  3527. $credit_scheme = 'urn:ebu';
  3528. }
  3529. if (isset($credit['data']))
  3530. {
  3531. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3532. }
  3533. $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  3534. }
  3535. if (is_array($credits))
  3536. {
  3537. $credits = array_values(SimplePie_Misc::array_unique($credits));
  3538. }
  3539. }
  3540. else
  3541. {
  3542. $credits = $credits_parent;
  3543. }
  3544. // DESCRIPTION
  3545. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  3546. {
  3547. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3548. }
  3549. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  3550. {
  3551. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3552. }
  3553. else
  3554. {
  3555. $description = $description_parent;
  3556. }
  3557. // HASHES
  3558. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  3559. {
  3560. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  3561. {
  3562. $value = null;
  3563. $algo = null;
  3564. if (isset($hash['data']))
  3565. {
  3566. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3567. }
  3568. if (isset($hash['attribs']['']['algo']))
  3569. {
  3570. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  3571. }
  3572. else
  3573. {
  3574. $algo = 'md5';
  3575. }
  3576. $hashes[] = $algo.':'.$value;
  3577. }
  3578. if (is_array($hashes))
  3579. {
  3580. $hashes = array_values(SimplePie_Misc::array_unique($hashes));
  3581. }
  3582. }
  3583. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  3584. {
  3585. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  3586. {
  3587. $value = null;
  3588. $algo = null;
  3589. if (isset($hash['data']))
  3590. {
  3591. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3592. }
  3593. if (isset($hash['attribs']['']['algo']))
  3594. {
  3595. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  3596. }
  3597. else
  3598. {
  3599. $algo = 'md5';
  3600. }
  3601. $hashes[] = $algo.':'.$value;
  3602. }
  3603. if (is_array($hashes))
  3604. {
  3605. $hashes = array_values(SimplePie_Misc::array_unique($hashes));
  3606. }
  3607. }
  3608. else
  3609. {
  3610. $hashes = $hashes_parent;
  3611. }
  3612. // KEYWORDS
  3613. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  3614. {
  3615. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  3616. {
  3617. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3618. foreach ($temp as $word)
  3619. {
  3620. $keywords[] = trim($word);
  3621. }
  3622. unset($temp);
  3623. }
  3624. if (is_array($keywords))
  3625. {
  3626. $keywords = array_values(SimplePie_Misc::array_unique($keywords));
  3627. }
  3628. }
  3629. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  3630. {
  3631. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  3632. {
  3633. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3634. foreach ($temp as $word)
  3635. {
  3636. $keywords[] = trim($word);
  3637. }
  3638. unset($temp);
  3639. }
  3640. if (is_array($keywords))
  3641. {
  3642. $keywords = array_values(SimplePie_Misc::array_unique($keywords));
  3643. }
  3644. }
  3645. else
  3646. {
  3647. $keywords = $keywords_parent;
  3648. }
  3649. // PLAYER
  3650. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  3651. {
  3652. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3653. }
  3654. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  3655. {
  3656. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3657. }
  3658. else
  3659. {
  3660. $player = $player_parent;
  3661. }
  3662. // RATINGS
  3663. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  3664. {
  3665. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  3666. {
  3667. $rating_scheme = null;
  3668. $rating_value = null;
  3669. if (isset($rating['attribs']['']['scheme']))
  3670. {
  3671. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3672. }
  3673. else
  3674. {
  3675. $rating_scheme = 'urn:simple';
  3676. }
  3677. if (isset($rating['data']))
  3678. {
  3679. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3680. }
  3681. $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3682. }
  3683. if (is_array($ratings))
  3684. {
  3685. $ratings = array_values(SimplePie_Misc::array_unique($ratings));
  3686. }
  3687. }
  3688. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  3689. {
  3690. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  3691. {
  3692. $rating_scheme = null;
  3693. $rating_value = null;
  3694. if (isset($rating['attribs']['']['scheme']))
  3695. {
  3696. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3697. }
  3698. else
  3699. {
  3700. $rating_scheme = 'urn:simple';
  3701. }
  3702. if (isset($rating['data']))
  3703. {
  3704. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3705. }
  3706. $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3707. }
  3708. if (is_array($ratings))
  3709. {
  3710. $ratings = array_values(SimplePie_Misc::array_unique($ratings));
  3711. }
  3712. }
  3713. else
  3714. {
  3715. $ratings = $ratings_parent;
  3716. }
  3717. // RESTRICTIONS
  3718. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  3719. {
  3720. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  3721. {
  3722. $restriction_relationship = null;
  3723. $restriction_type = null;
  3724. $restriction_value = null;
  3725. if (isset($restriction['attribs']['']['relationship']))
  3726. {
  3727. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  3728. }
  3729. if (isset($restriction['attribs']['']['type']))
  3730. {
  3731. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3732. }
  3733. if (isset($restriction['data']))
  3734. {
  3735. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3736. }
  3737. $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3738. }
  3739. if (is_array($restrictions))
  3740. {
  3741. $restrictions = array_values(SimplePie_Misc::array_unique($restrictions));
  3742. }
  3743. }
  3744. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  3745. {
  3746. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  3747. {
  3748. $restriction_relationship = null;
  3749. $restriction_type = null;
  3750. $restriction_value = null;
  3751. if (isset($restriction['attribs']['']['relationship']))
  3752. {
  3753. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  3754. }
  3755. if (isset($restriction['attribs']['']['type']))
  3756. {
  3757. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3758. }
  3759. if (isset($restriction['data']))
  3760. {
  3761. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3762. }
  3763. $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3764. }
  3765. if (is_array($restrictions))
  3766. {
  3767. $restrictions = array_values(SimplePie_Misc::array_unique($restrictions));
  3768. }
  3769. }
  3770. else
  3771. {
  3772. $restrictions = $restrictions_parent;
  3773. }
  3774. // THUMBNAILS
  3775. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  3776. {
  3777. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  3778. {
  3779. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3780. }
  3781. if (is_array($thumbnails))
  3782. {
  3783. $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails));
  3784. }
  3785. }
  3786. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  3787. {
  3788. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  3789. {
  3790. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3791. }
  3792. if (is_array($thumbnails))
  3793. {
  3794. $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails));
  3795. }
  3796. }
  3797. else
  3798. {
  3799. $thumbnails = $thumbnails_parent;
  3800. }
  3801. // TITLES
  3802. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  3803. {
  3804. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3805. }
  3806. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  3807. {
  3808. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3809. }
  3810. else
  3811. {
  3812. $title = $title_parent;
  3813. }
  3814. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width);
  3815. }
  3816. }
  3817. }
  3818. // If we have standalone media:content tags, loop through them.
  3819. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  3820. {
  3821. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  3822. {
  3823. if (isset($content['attribs']['']['url']))
  3824. {
  3825. // Attributes
  3826. $bitrate = null;
  3827. $channels = null;
  3828. $duration = null;
  3829. $expression = null;
  3830. $framerate = null;
  3831. $height = null;
  3832. $javascript = null;
  3833. $lang = null;
  3834. $length = null;
  3835. $medium = null;
  3836. $samplingrate = null;
  3837. $type = null;
  3838. $url = null;
  3839. $width = null;
  3840. // Elements
  3841. $captions = null;
  3842. $categories = null;
  3843. $copyrights = null;
  3844. $credits = null;
  3845. $description = null;
  3846. $hashes = null;
  3847. $keywords = null;
  3848. $player = null;
  3849. $ratings = null;
  3850. $restrictions = null;
  3851. $thumbnails = null;
  3852. $title = null;
  3853. // Start checking the attributes of media:content
  3854. if (isset($content['attribs']['']['bitrate']))
  3855. {
  3856. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  3857. }
  3858. if (isset($content['attribs']['']['channels']))
  3859. {
  3860. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  3861. }
  3862. if (isset($content['attribs']['']['duration']))
  3863. {
  3864. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  3865. }
  3866. else
  3867. {
  3868. $duration = $duration_parent;
  3869. }
  3870. if (isset($content['attribs']['']['expression']))
  3871. {
  3872. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  3873. }
  3874. if (isset($content['attribs']['']['framerate']))
  3875. {
  3876. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  3877. }
  3878. if (isset($content['attribs']['']['height']))
  3879. {
  3880. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  3881. }
  3882. if (isset($content['attribs']['']['lang']))
  3883. {
  3884. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  3885. }
  3886. if (isset($content['attribs']['']['fileSize']))
  3887. {
  3888. $length = ceil($content['attribs']['']['fileSize']);
  3889. }
  3890. if (isset($content['attribs']['']['medium']))
  3891. {
  3892. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  3893. }
  3894. if (isset($content['attribs']['']['samplingrate']))
  3895. {
  3896. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  3897. }
  3898. if (isset($content['attribs']['']['type']))
  3899. {
  3900. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3901. }
  3902. if (isset($content['attribs']['']['width']))
  3903. {
  3904. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  3905. }
  3906. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3907. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  3908. // CAPTIONS
  3909. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  3910. {
  3911. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  3912. {
  3913. $caption_type = null;
  3914. $caption_lang = null;
  3915. $caption_startTime = null;
  3916. $caption_endTime = null;
  3917. $caption_text = null;
  3918. if (isset($caption['attribs']['']['type']))
  3919. {
  3920. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3921. }
  3922. if (isset($caption['attribs']['']['lang']))
  3923. {
  3924. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  3925. }
  3926. if (isset($caption['attribs']['']['start']))
  3927. {
  3928. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  3929. }
  3930. if (isset($caption['attribs']['']['end']))
  3931. {
  3932. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  3933. }
  3934. if (isset($caption['data']))
  3935. {
  3936. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3937. }
  3938. $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  3939. }
  3940. if (is_array($captions))
  3941. {
  3942. $captions = array_values(SimplePie_Misc::array_unique($captions));
  3943. }
  3944. }
  3945. else
  3946. {
  3947. $captions = $captions_parent;
  3948. }
  3949. // CATEGORIES
  3950. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  3951. {
  3952. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  3953. {
  3954. $term = null;
  3955. $scheme = null;
  3956. $label = null;
  3957. if (isset($category['data']))
  3958. {
  3959. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3960. }
  3961. if (isset($category['attribs']['']['scheme']))
  3962. {
  3963. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3964. }
  3965. else
  3966. {
  3967. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  3968. }
  3969. if (isset($category['attribs']['']['label']))
  3970. {
  3971. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  3972. }
  3973. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  3974. }
  3975. }
  3976. if (is_array($categories) && is_array($categories_parent))
  3977. {
  3978. $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent)));
  3979. }
  3980. elseif (is_array($categories))
  3981. {
  3982. $categories = array_values(SimplePie_Misc::array_unique($categories));
  3983. }
  3984. elseif (is_array($categories_parent))
  3985. {
  3986. $categories = array_values(SimplePie_Misc::array_unique($categories_parent));
  3987. }
  3988. else
  3989. {
  3990. $categories = null;
  3991. }
  3992. // COPYRIGHTS
  3993. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  3994. {
  3995. $copyright_url = null;
  3996. $copyright_label = null;
  3997. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  3998. {
  3999. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  4000. }
  4001. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  4002. {
  4003. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4004. }
  4005. $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  4006. }
  4007. else
  4008. {
  4009. $copyrights = $copyrights_parent;
  4010. }
  4011. // CREDITS
  4012. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  4013. {
  4014. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  4015. {
  4016. $credit_role = null;
  4017. $credit_scheme = null;
  4018. $credit_name = null;
  4019. if (isset($credit['attribs']['']['role']))
  4020. {
  4021. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  4022. }
  4023. if (isset($credit['attribs']['']['scheme']))
  4024. {
  4025. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4026. }
  4027. else
  4028. {
  4029. $credit_scheme = 'urn:ebu';
  4030. }
  4031. if (isset($credit['data']))
  4032. {
  4033. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4034. }
  4035. $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  4036. }
  4037. if (is_array($credits))
  4038. {
  4039. $credits = array_values(SimplePie_Misc::array_unique($credits));
  4040. }
  4041. }
  4042. else
  4043. {
  4044. $credits = $credits_parent;
  4045. }
  4046. // DESCRIPTION
  4047. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  4048. {
  4049. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4050. }
  4051. else
  4052. {
  4053. $description = $description_parent;
  4054. }
  4055. // HASHES
  4056. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  4057. {
  4058. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  4059. {
  4060. $value = null;
  4061. $algo = null;
  4062. if (isset($hash['data']))
  4063. {
  4064. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4065. }
  4066. if (isset($hash['attribs']['']['algo']))
  4067. {
  4068. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  4069. }
  4070. else
  4071. {
  4072. $algo = 'md5';
  4073. }
  4074. $hashes[] = $algo.':'.$value;
  4075. }
  4076. if (is_array($hashes))
  4077. {
  4078. $hashes = array_values(SimplePie_Misc::array_unique($hashes));
  4079. }
  4080. }
  4081. else
  4082. {
  4083. $hashes = $hashes_parent;
  4084. }
  4085. // KEYWORDS
  4086. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  4087. {
  4088. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  4089. {
  4090. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  4091. foreach ($temp as $word)
  4092. {
  4093. $keywords[] = trim($word);
  4094. }
  4095. unset($temp);
  4096. }
  4097. if (is_array($keywords))
  4098. {
  4099. $keywords = array_values(SimplePie_Misc::array_unique($keywords));
  4100. }
  4101. }
  4102. else
  4103. {
  4104. $keywords = $keywords_parent;
  4105. }
  4106. // PLAYER
  4107. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  4108. {
  4109. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4110. }
  4111. else
  4112. {
  4113. $player = $player_parent;
  4114. }
  4115. // RATINGS
  4116. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  4117. {
  4118. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  4119. {
  4120. $rating_scheme = null;
  4121. $rating_value = null;
  4122. if (isset($rating['attribs']['']['scheme']))
  4123. {
  4124. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4125. }
  4126. else
  4127. {
  4128. $rating_scheme = 'urn:simple';
  4129. }
  4130. if (isset($rating['data']))
  4131. {
  4132. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4133. }
  4134. $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  4135. }
  4136. if (is_array($ratings))
  4137. {
  4138. $ratings = array_values(SimplePie_Misc::array_unique($ratings));
  4139. }
  4140. }
  4141. else
  4142. {
  4143. $ratings = $ratings_parent;
  4144. }
  4145. // RESTRICTIONS
  4146. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  4147. {
  4148. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  4149. {
  4150. $restriction_relationship = null;
  4151. $restriction_type = null;
  4152. $restriction_value = null;
  4153. if (isset($restriction['attribs']['']['relationship']))
  4154. {
  4155. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  4156. }
  4157. if (isset($restriction['attribs']['']['type']))
  4158. {
  4159. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4160. }
  4161. if (isset($restriction['data']))
  4162. {
  4163. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4164. }
  4165. $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  4166. }
  4167. if (is_array($restrictions))
  4168. {
  4169. $restrictions = array_values(SimplePie_Misc::array_unique($restrictions));
  4170. }
  4171. }
  4172. else
  4173. {
  4174. $restrictions = $restrictions_parent;
  4175. }
  4176. // THUMBNAILS
  4177. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  4178. {
  4179. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  4180. {
  4181. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4182. }
  4183. if (is_array($thumbnails))
  4184. {
  4185. $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails));
  4186. }
  4187. }
  4188. else
  4189. {
  4190. $thumbnails = $thumbnails_parent;
  4191. }
  4192. // TITLES
  4193. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  4194. {
  4195. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4196. }
  4197. else
  4198. {
  4199. $title = $title_parent;
  4200. }
  4201. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width);
  4202. }
  4203. }
  4204. }
  4205. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  4206. {
  4207. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] == 'enclosure')
  4208. {
  4209. // Attributes
  4210. $bitrate = null;
  4211. $channels = null;
  4212. $duration = null;
  4213. $expression = null;
  4214. $framerate = null;
  4215. $height = null;
  4216. $javascript = null;
  4217. $lang = null;
  4218. $length = null;
  4219. $medium = null;
  4220. $samplingrate = null;
  4221. $type = null;
  4222. $url = null;
  4223. $width = null;
  4224. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  4225. if (isset($link['attribs']['']['type']))
  4226. {
  4227. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4228. }
  4229. if (isset($link['attribs']['']['length']))
  4230. {
  4231. $length = ceil($link['attribs']['']['length']);
  4232. }
  4233. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  4234. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  4235. }
  4236. }
  4237. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  4238. {
  4239. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] == 'enclosure')
  4240. {
  4241. // Attributes
  4242. $bitrate = null;
  4243. $channels = null;
  4244. $duration = null;
  4245. $expression = null;
  4246. $framerate = null;
  4247. $height = null;
  4248. $javascript = null;
  4249. $lang = null;
  4250. $length = null;
  4251. $medium = null;
  4252. $samplingrate = null;
  4253. $type = null;
  4254. $url = null;
  4255. $width = null;
  4256. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  4257. if (isset($link['attribs']['']['type']))
  4258. {
  4259. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4260. }
  4261. if (isset($link['attribs']['']['length']))
  4262. {
  4263. $length = ceil($link['attribs']['']['length']);
  4264. }
  4265. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  4266. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  4267. }
  4268. }
  4269. if ($enclosure = $this->get_item_tags('', 'enclosure'))
  4270. {
  4271. if (isset($enclosure[0]['attribs']['']['url']))
  4272. {
  4273. // Attributes
  4274. $bitrate = null;
  4275. $channels = null;
  4276. $duration = null;
  4277. $expression = null;
  4278. $framerate = null;
  4279. $height = null;
  4280. $javascript = null;
  4281. $lang = null;
  4282. $length = null;
  4283. $medium = null;
  4284. $samplingrate = null;
  4285. $type = null;
  4286. $url = null;
  4287. $width = null;
  4288. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  4289. if (isset($enclosure[0]['attribs']['']['type']))
  4290. {
  4291. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4292. }
  4293. if (isset($enclosure[0]['attribs']['']['length']))
  4294. {
  4295. $length = ceil($enclosure[0]['attribs']['']['length']);
  4296. }
  4297. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  4298. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  4299. }
  4300. }
  4301. if (sizeof($this->data['enclosures']) == 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width))
  4302. {
  4303. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  4304. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  4305. }
  4306. $this->data['enclosures'] = array_values(SimplePie_Misc::array_unique($this->data['enclosures']));
  4307. }
  4308. if (!empty($this->data['enclosures']))
  4309. {
  4310. return $this->data['enclosures'];
  4311. }
  4312. else
  4313. {
  4314. return null;
  4315. }
  4316. }
  4317. function get_latitude()
  4318. {
  4319. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  4320. {
  4321. return (float) $return[0]['data'];
  4322. }
  4323. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  4324. {
  4325. return (float) $match[1];
  4326. }
  4327. else
  4328. {
  4329. return null;
  4330. }
  4331. }
  4332. function get_longitude()
  4333. {
  4334. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  4335. {
  4336. return (float) $return[0]['data'];
  4337. }
  4338. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  4339. {
  4340. return (float) $return[0]['data'];
  4341. }
  4342. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  4343. {
  4344. return (float) $match[2];
  4345. }
  4346. else
  4347. {
  4348. return null;
  4349. }
  4350. }
  4351. function get_source()
  4352. {
  4353. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  4354. {
  4355. return new $this->feed->source_class($this, $return[0]);
  4356. }
  4357. else
  4358. {
  4359. return null;
  4360. }
  4361. }
  4362. /**
  4363. * Creates the add_to_* methods' return data
  4364. *
  4365. * @access private
  4366. * @param string $item_url String to prefix to the item permalink
  4367. * @param string $title_url String to prefix to the item title
  4368. * (and suffix to the item permalink)
  4369. * @return mixed URL if feed exists, false otherwise
  4370. */
  4371. function add_to_service($item_url, $title_url = null, $summary_url = null)
  4372. {
  4373. if ($this->get_permalink() !== null)
  4374. {
  4375. $return = $this->sanitize($item_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_permalink());
  4376. if ($title_url !== null && $this->get_title() !== null)
  4377. {
  4378. $return .= $this->sanitize($title_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_title());
  4379. }
  4380. if ($summary_url !== null && $this->get_description() !== null)
  4381. {
  4382. $return .= $this->sanitize($summary_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_description());
  4383. }
  4384. return $return;
  4385. }
  4386. else
  4387. {
  4388. return null;
  4389. }
  4390. }
  4391. function add_to_blinklist()
  4392. {
  4393. return $this->add_to_service('http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=', '&Title=');
  4394. }
  4395. function add_to_blogmarks()
  4396. {
  4397. return $this->add_to_service('http://blogmarks.net/my/new.php?mini=1&simple=1&url=', '&title=');
  4398. }
  4399. function add_to_delicious()
  4400. {
  4401. return $this->add_to_service('http://del.icio.us/post/?v=4&url=', '&title=');
  4402. }
  4403. function add_to_digg()
  4404. {
  4405. return $this->add_to_service('http://digg.com/submit?url=', '&title=', '&bodytext=');
  4406. }
  4407. function add_to_furl()
  4408. {
  4409. return $this->add_to_service('http://www.furl.net/storeIt.jsp?u=', '&t=');
  4410. }
  4411. function add_to_magnolia()
  4412. {
  4413. return $this->add_to_service('http://ma.gnolia.com/bookmarklet/add?url=', '&title=');
  4414. }
  4415. function add_to_myweb20()
  4416. {
  4417. return $this->add_to_service('http://myweb2.search.yahoo.com/myresults/bookmarklet?u=', '&t=');
  4418. }
  4419. function add_to_newsvine()
  4420. {
  4421. return $this->add_to_service('http://www.newsvine.com/_wine/save?u=', '&h=');
  4422. }
  4423. function add_to_reddit()
  4424. {
  4425. return $this->add_to_service('http://reddit.com/submit?url=', '&title=');
  4426. }
  4427. function add_to_segnalo()
  4428. {
  4429. return $this->add_to_service('http://segnalo.com/post.html.php?url=', '&title=');
  4430. }
  4431. function add_to_simpy()
  4432. {
  4433. return $this->add_to_service('http://www.simpy.com/simpy/LinkAdd.do?href=', '&title=');
  4434. }
  4435. function add_to_spurl()
  4436. {
  4437. return $this->add_to_service('http://www.spurl.net/spurl.php?v=3&url=', '&title=');
  4438. }
  4439. function add_to_wists()
  4440. {
  4441. return $this->add_to_service('http://wists.com/r.php?c=&r=', '&title=');
  4442. }
  4443. function search_technorati()
  4444. {
  4445. return $this->add_to_service('http://www.technorati.com/search/');
  4446. }
  4447. }
  4448. class SimplePie_Source
  4449. {
  4450. var $item;
  4451. var $data = array();
  4452. function SimplePie_Source($item, $data)
  4453. {
  4454. $this->item = $item;
  4455. $this->data = $data;
  4456. }
  4457. function __toString()
  4458. {
  4459. return md5(serialize($this->data));
  4460. }
  4461. /**
  4462. * Remove items that link back to this before destroying this object
  4463. */
  4464. function __destruct()
  4465. {
  4466. unset($this->item);
  4467. }
  4468. function get_source_tags($namespace, $tag)
  4469. {
  4470. if (isset($this->data['child'][$namespace][$tag]))
  4471. {
  4472. return $this->data['child'][$namespace][$tag];
  4473. }
  4474. else
  4475. {
  4476. return null;
  4477. }
  4478. }
  4479. function get_base($element = array())
  4480. {
  4481. return $this->item->get_base($element);
  4482. }
  4483. function sanitize($data, $type, $base = '')
  4484. {
  4485. return $this->item->sanitize($data, $type, $base);
  4486. }
  4487. function get_item()
  4488. {
  4489. return $this->item;
  4490. }
  4491. function get_title()
  4492. {
  4493. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  4494. {
  4495. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  4496. }
  4497. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  4498. {
  4499. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  4500. }
  4501. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  4502. {
  4503. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4504. }
  4505. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  4506. {
  4507. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4508. }
  4509. elseif ($return = $this->get_source_tags('', 'title'))
  4510. {
  4511. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4512. }
  4513. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  4514. {
  4515. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4516. }
  4517. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  4518. {
  4519. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4520. }
  4521. else
  4522. {
  4523. return null;
  4524. }
  4525. }
  4526. function get_category($key = 0)
  4527. {
  4528. $categories = $this->get_categories();
  4529. if (isset($categories[$key]))
  4530. {
  4531. return $categories[$key];
  4532. }
  4533. else
  4534. {
  4535. return null;
  4536. }
  4537. }
  4538. function get_categories()
  4539. {
  4540. $categories = array();
  4541. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  4542. {
  4543. $term = null;
  4544. $scheme = null;
  4545. $label = null;
  4546. if (isset($category['attribs']['']['term']))
  4547. {
  4548. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  4549. }
  4550. if (isset($category['attribs']['']['scheme']))
  4551. {
  4552. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4553. }
  4554. if (isset($category['attribs']['']['label']))
  4555. {
  4556. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  4557. }
  4558. $categories[] =& new $this->item->feed->category_class($term, $scheme, $label);
  4559. }
  4560. foreach ((array) $this->get_source_tags('', 'category') as $category)
  4561. {
  4562. $categories[] =& new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  4563. }
  4564. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  4565. {
  4566. $categories[] =& new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  4567. }
  4568. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  4569. {
  4570. $categories[] =& new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  4571. }
  4572. if (!empty($categories))
  4573. {
  4574. return SimplePie_Misc::array_unique($categories);
  4575. }
  4576. else
  4577. {
  4578. return null;
  4579. }
  4580. }
  4581. function get_author($key = 0)
  4582. {
  4583. $authors = $this->get_authors();
  4584. if (isset($authors[$key]))
  4585. {
  4586. return $authors[$key];
  4587. }
  4588. else
  4589. {
  4590. return null;
  4591. }
  4592. }
  4593. function get_authors()
  4594. {
  4595. $authors = array();
  4596. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  4597. {
  4598. $name = null;
  4599. $uri = null;
  4600. $email = null;
  4601. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  4602. {
  4603. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4604. }
  4605. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  4606. {
  4607. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  4608. }
  4609. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  4610. {
  4611. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4612. }
  4613. if ($name !== null || $email !== null || $uri !== null)
  4614. {
  4615. $authors[] =& new $this->item->feed->author_class($name, $uri, $email);
  4616. }
  4617. }
  4618. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  4619. {
  4620. $name = null;
  4621. $url = null;
  4622. $email = null;
  4623. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  4624. {
  4625. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4626. }
  4627. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  4628. {
  4629. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  4630. }
  4631. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  4632. {
  4633. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4634. }
  4635. if ($name !== null || $email !== null || $url !== null)
  4636. {
  4637. $authors[] =& new $this->item->feed->author_class($name, $url, $email);
  4638. }
  4639. }
  4640. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  4641. {
  4642. $authors[] =& new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  4643. }
  4644. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  4645. {
  4646. $authors[] =& new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  4647. }
  4648. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  4649. {
  4650. $authors[] =& new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  4651. }
  4652. if (!empty($authors))
  4653. {
  4654. return SimplePie_Misc::array_unique($authors);
  4655. }
  4656. else
  4657. {
  4658. return null;
  4659. }
  4660. }
  4661. function get_contributor($key = 0)
  4662. {
  4663. $contributors = $this->get_contributors();
  4664. if (isset($contributors[$key]))
  4665. {
  4666. return $contributors[$key];
  4667. }
  4668. else
  4669. {
  4670. return null;
  4671. }
  4672. }
  4673. function get_contributors()
  4674. {
  4675. $contributors = array();
  4676. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  4677. {
  4678. $name = null;
  4679. $uri = null;
  4680. $email = null;
  4681. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  4682. {
  4683. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4684. }
  4685. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  4686. {
  4687. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  4688. }
  4689. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  4690. {
  4691. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4692. }
  4693. if ($name !== null || $email !== null || $uri !== null)
  4694. {
  4695. $contributors[] =& new $this->item->feed->author_class($name, $uri, $email);
  4696. }
  4697. }
  4698. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  4699. {
  4700. $name = null;
  4701. $url = null;
  4702. $email = null;
  4703. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  4704. {
  4705. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4706. }
  4707. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  4708. {
  4709. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  4710. }
  4711. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  4712. {
  4713. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4714. }
  4715. if ($name !== null || $email !== null || $url !== null)
  4716. {
  4717. $contributors[] =& new $this->item->feed->author_class($name, $url, $email);
  4718. }
  4719. }
  4720. if (!empty($contributors))
  4721. {
  4722. return SimplePie_Misc::array_unique($contributors);
  4723. }
  4724. else
  4725. {
  4726. return null;
  4727. }
  4728. }
  4729. function get_link($key = 0, $rel = 'alternate')
  4730. {
  4731. $links = $this->get_links($rel);
  4732. if (isset($links[$key]))
  4733. {
  4734. return $links[$key];
  4735. }
  4736. else
  4737. {
  4738. return null;
  4739. }
  4740. }
  4741. /**
  4742. * Added for parity between the parent-level and the item/entry-level.
  4743. */
  4744. function get_permalink()
  4745. {
  4746. return $this->get_link(0);
  4747. }
  4748. function get_links($rel = 'alternate')
  4749. {
  4750. if (!isset($this->data['links']))
  4751. {
  4752. $this->data['links'] = array();
  4753. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  4754. {
  4755. foreach ($links as $link)
  4756. {
  4757. if (isset($link['attribs']['']['href']))
  4758. {
  4759. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  4760. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  4761. }
  4762. }
  4763. }
  4764. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  4765. {
  4766. foreach ($links as $link)
  4767. {
  4768. if (isset($link['attribs']['']['href']))
  4769. {
  4770. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  4771. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  4772. }
  4773. }
  4774. }
  4775. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  4776. {
  4777. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  4778. }
  4779. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  4780. {
  4781. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  4782. }
  4783. if ($links = $this->get_source_tags('', 'link'))
  4784. {
  4785. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  4786. }
  4787. $keys = array_keys($this->data['links']);
  4788. foreach ($keys as $key)
  4789. {
  4790. if (SimplePie_Misc::is_isegment_nz_nc($key))
  4791. {
  4792. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  4793. {
  4794. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  4795. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  4796. }
  4797. else
  4798. {
  4799. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  4800. }
  4801. }
  4802. elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  4803. {
  4804. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  4805. }
  4806. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  4807. }
  4808. }
  4809. if (isset($this->data['links'][$rel]))
  4810. {
  4811. return $this->data['links'][$rel];
  4812. }
  4813. else
  4814. {
  4815. return null;
  4816. }
  4817. }
  4818. function get_description()
  4819. {
  4820. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  4821. {
  4822. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  4823. }
  4824. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  4825. {
  4826. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  4827. }
  4828. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  4829. {
  4830. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4831. }
  4832. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  4833. {
  4834. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4835. }
  4836. elseif ($return = $this->get_source_tags('', 'description'))
  4837. {
  4838. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4839. }
  4840. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  4841. {
  4842. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4843. }
  4844. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  4845. {
  4846. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4847. }
  4848. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  4849. {
  4850. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4851. }
  4852. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  4853. {
  4854. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4855. }
  4856. else
  4857. {
  4858. return null;
  4859. }
  4860. }
  4861. function get_copyright()
  4862. {
  4863. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  4864. {
  4865. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  4866. }
  4867. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  4868. {
  4869. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  4870. }
  4871. elseif ($return = $this->get_source_tags('', 'copyright'))
  4872. {
  4873. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4874. }
  4875. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  4876. {
  4877. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4878. }
  4879. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  4880. {
  4881. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4882. }
  4883. else
  4884. {
  4885. return null;
  4886. }
  4887. }
  4888. function get_language()
  4889. {
  4890. if ($return = $this->get_source_tags('', 'language'))
  4891. {
  4892. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4893. }
  4894. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  4895. {
  4896. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4897. }
  4898. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  4899. {
  4900. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4901. }
  4902. elseif (isset($this->data['xml_lang']))
  4903. {
  4904. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  4905. }
  4906. else
  4907. {
  4908. return null;
  4909. }
  4910. }
  4911. function get_latitude()
  4912. {
  4913. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  4914. {
  4915. return (float) $return[0]['data'];
  4916. }
  4917. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  4918. {
  4919. return (float) $match[1];
  4920. }
  4921. else
  4922. {
  4923. return null;
  4924. }
  4925. }
  4926. function get_longitude()
  4927. {
  4928. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  4929. {
  4930. return (float) $return[0]['data'];
  4931. }
  4932. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  4933. {
  4934. return (float) $return[0]['data'];
  4935. }
  4936. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  4937. {
  4938. return (float) $match[2];
  4939. }
  4940. else
  4941. {
  4942. return null;
  4943. }
  4944. }
  4945. function get_image_url()
  4946. {
  4947. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  4948. {
  4949. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  4950. }
  4951. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  4952. {
  4953. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  4954. }
  4955. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  4956. {
  4957. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  4958. }
  4959. else
  4960. {
  4961. return null;
  4962. }
  4963. }
  4964. }
  4965. class SimplePie_Author
  4966. {
  4967. var $name;
  4968. var $link;
  4969. var $email;
  4970. // Constructor, used to input the data
  4971. function SimplePie_Author($name = null, $link = null, $email = null)
  4972. {
  4973. $this->name = $name;
  4974. $this->link = $link;
  4975. $this->email = $email;
  4976. }
  4977. function __toString()
  4978. {
  4979. // There is no $this->data here
  4980. return md5(serialize($this));
  4981. }
  4982. function get_name()
  4983. {
  4984. if ($this->name !== null)
  4985. {
  4986. return $this->name;
  4987. }
  4988. else
  4989. {
  4990. return null;
  4991. }
  4992. }
  4993. function get_link()
  4994. {
  4995. if ($this->link !== null)
  4996. {
  4997. return $this->link;
  4998. }
  4999. else
  5000. {
  5001. return null;
  5002. }
  5003. }
  5004. function get_email()
  5005. {
  5006. if ($this->email !== null)
  5007. {
  5008. return $this->email;
  5009. }
  5010. else
  5011. {
  5012. return null;
  5013. }
  5014. }
  5015. }
  5016. class SimplePie_Category
  5017. {
  5018. var $term;
  5019. var $scheme;
  5020. var $label;
  5021. // Constructor, used to input the data
  5022. function SimplePie_Category($term = null, $scheme = null, $label = null)
  5023. {
  5024. $this->term = $term;
  5025. $this->scheme = $scheme;
  5026. $this->label = $label;
  5027. }
  5028. function __toString()
  5029. {
  5030. // There is no $this->data here
  5031. return md5(serialize($this));
  5032. }
  5033. function get_term()
  5034. {
  5035. if ($this->term !== null)
  5036. {
  5037. return $this->term;
  5038. }
  5039. else
  5040. {
  5041. return null;
  5042. }
  5043. }
  5044. function get_scheme()
  5045. {
  5046. if ($this->scheme !== null)
  5047. {
  5048. return $this->scheme;
  5049. }
  5050. else
  5051. {
  5052. return null;
  5053. }
  5054. }
  5055. function get_label()
  5056. {
  5057. if ($this->label !== null)
  5058. {
  5059. return $this->label;
  5060. }
  5061. else
  5062. {
  5063. return $this->get_term();
  5064. }
  5065. }
  5066. }
  5067. class SimplePie_Enclosure
  5068. {
  5069. var $bitrate;
  5070. var $captions;
  5071. var $categories;
  5072. var $channels;
  5073. var $copyright;
  5074. var $credits;
  5075. var $description;
  5076. var $duration;
  5077. var $expression;
  5078. var $framerate;
  5079. var $handler;
  5080. var $hashes;
  5081. var $height;
  5082. var $javascript;
  5083. var $keywords;
  5084. var $lang;
  5085. var $length;
  5086. var $link;
  5087. var $medium;
  5088. var $player;
  5089. var $ratings;
  5090. var $restrictions;
  5091. var $samplingrate;
  5092. var $thumbnails;
  5093. var $title;
  5094. var $type;
  5095. var $width;
  5096. // Constructor, used to input the data
  5097. function SimplePie_Enclosure($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null)
  5098. {
  5099. $this->bitrate = $bitrate;
  5100. $this->captions = $captions;
  5101. $this->categories = $categories;
  5102. $this->channels = $channels;
  5103. $this->copyright = $copyright;
  5104. $this->credits = $credits;
  5105. $this->description = $description;
  5106. $this->duration = $duration;
  5107. $this->expression = $expression;
  5108. $this->framerate = $framerate;
  5109. $this->hashes = $hashes;
  5110. $this->height = $height;
  5111. $this->javascript = $javascript;
  5112. $this->keywords = $keywords;
  5113. $this->lang = $lang;
  5114. $this->length = $length;
  5115. $this->link = $link;
  5116. $this->medium = $medium;
  5117. $this->player = $player;
  5118. $this->ratings = $ratings;
  5119. $this->restrictions = $restrictions;
  5120. $this->samplingrate = $samplingrate;
  5121. $this->thumbnails = $thumbnails;
  5122. $this->title = $title;
  5123. $this->type = $type;
  5124. $this->width = $width;
  5125. if (class_exists('idna_convert'))
  5126. {
  5127. $idn =& new idna_convert;
  5128. $parsed = SimplePie_Misc::parse_url($link);
  5129. $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  5130. }
  5131. $this->handler = $this->get_handler(); // Needs to load last
  5132. }
  5133. function __toString()
  5134. {
  5135. // There is no $this->data here
  5136. return md5(serialize($this));
  5137. }
  5138. function get_bitrate()
  5139. {
  5140. if ($this->bitrate !== null)
  5141. {
  5142. return $this->bitrate;
  5143. }
  5144. else
  5145. {
  5146. return null;
  5147. }
  5148. }
  5149. function get_caption($key = 0)
  5150. {
  5151. $captions = $this->get_captions();
  5152. if (isset($captions[$key]))
  5153. {
  5154. return $captions[$key];
  5155. }
  5156. else
  5157. {
  5158. return null;
  5159. }
  5160. }
  5161. function get_captions()
  5162. {
  5163. if ($this->captions !== null)
  5164. {
  5165. return $this->captions;
  5166. }
  5167. else
  5168. {
  5169. return null;
  5170. }
  5171. }
  5172. function get_category($key = 0)
  5173. {
  5174. $categories = $this->get_categories();
  5175. if (isset($categories[$key]))
  5176. {
  5177. return $categories[$key];
  5178. }
  5179. else
  5180. {
  5181. return null;
  5182. }
  5183. }
  5184. function get_categories()
  5185. {
  5186. if ($this->categories !== null)
  5187. {
  5188. return $this->categories;
  5189. }
  5190. else
  5191. {
  5192. return null;
  5193. }
  5194. }
  5195. function get_channels()
  5196. {
  5197. if ($this->channels !== null)
  5198. {
  5199. return $this->channels;
  5200. }
  5201. else
  5202. {
  5203. return null;
  5204. }
  5205. }
  5206. function get_copyright()
  5207. {
  5208. if ($this->copyright !== null)
  5209. {
  5210. return $this->copyright;
  5211. }
  5212. else
  5213. {
  5214. return null;
  5215. }
  5216. }
  5217. function get_credit($key = 0)
  5218. {
  5219. $credits = $this->get_credits();
  5220. if (isset($credits[$key]))
  5221. {
  5222. return $credits[$key];
  5223. }
  5224. else
  5225. {
  5226. return null;
  5227. }
  5228. }
  5229. function get_credits()
  5230. {
  5231. if ($this->credits !== null)
  5232. {
  5233. return $this->credits;
  5234. }
  5235. else
  5236. {
  5237. return null;
  5238. }
  5239. }
  5240. function get_description()
  5241. {
  5242. if ($this->description !== null)
  5243. {
  5244. return $this->description;
  5245. }
  5246. else
  5247. {
  5248. return null;
  5249. }
  5250. }
  5251. function get_duration($convert = false)
  5252. {
  5253. if ($this->duration !== null)
  5254. {
  5255. if ($convert)
  5256. {
  5257. $time = SimplePie_Misc::time_hms($this->duration);
  5258. return $time;
  5259. }
  5260. else
  5261. {
  5262. return $this->duration;
  5263. }
  5264. }
  5265. else
  5266. {
  5267. return null;
  5268. }
  5269. }
  5270. function get_expression()
  5271. {
  5272. if ($this->expression !== null)
  5273. {
  5274. return $this->expression;
  5275. }
  5276. else
  5277. {
  5278. return 'full';
  5279. }
  5280. }
  5281. function get_extension()
  5282. {
  5283. if ($this->link !== null)
  5284. {
  5285. $url = SimplePie_Misc::parse_url($this->link);
  5286. if ($url['path'] !== '')
  5287. {
  5288. return pathinfo($url['path'], PATHINFO_EXTENSION);
  5289. }
  5290. }
  5291. return null;
  5292. }
  5293. function get_framerate()
  5294. {
  5295. if ($this->framerate !== null)
  5296. {
  5297. return $this->framerate;
  5298. }
  5299. else
  5300. {
  5301. return null;
  5302. }
  5303. }
  5304. function get_handler()
  5305. {
  5306. return $this->get_real_type(true);
  5307. }
  5308. function get_hash($key = 0)
  5309. {
  5310. $hashes = $this->get_hashes();
  5311. if (isset($hashes[$key]))
  5312. {
  5313. return $hashes[$key];
  5314. }
  5315. else
  5316. {
  5317. return null;
  5318. }
  5319. }
  5320. function get_hashes()
  5321. {
  5322. if ($this->hashes !== null)
  5323. {
  5324. return $this->hashes;
  5325. }
  5326. else
  5327. {
  5328. return null;
  5329. }
  5330. }
  5331. function get_height()
  5332. {
  5333. if ($this->height !== null)
  5334. {
  5335. return $this->height;
  5336. }
  5337. else
  5338. {
  5339. return null;
  5340. }
  5341. }
  5342. function get_language()
  5343. {
  5344. if ($this->lang !== null)
  5345. {
  5346. return $this->lang;
  5347. }
  5348. else
  5349. {
  5350. return null;
  5351. }
  5352. }
  5353. function get_keyword($key = 0)
  5354. {
  5355. $keywords = $this->get_keywords();
  5356. if (isset($keywords[$key]))
  5357. {
  5358. return $keywords[$key];
  5359. }
  5360. else
  5361. {
  5362. return null;
  5363. }
  5364. }
  5365. function get_keywords()
  5366. {
  5367. if ($this->keywords !== null)
  5368. {
  5369. return $this->keywords;
  5370. }
  5371. else
  5372. {
  5373. return null;
  5374. }
  5375. }
  5376. function get_length()
  5377. {
  5378. if ($this->length !== null)
  5379. {
  5380. return $this->length;
  5381. }
  5382. else
  5383. {
  5384. return null;
  5385. }
  5386. }
  5387. function get_link()
  5388. {
  5389. if ($this->link !== null)
  5390. {
  5391. return urldecode($this->link);
  5392. }
  5393. else
  5394. {
  5395. return null;
  5396. }
  5397. }
  5398. function get_medium()
  5399. {
  5400. if ($this->medium !== null)
  5401. {
  5402. return $this->medium;
  5403. }
  5404. else
  5405. {
  5406. return null;
  5407. }
  5408. }
  5409. function get_player()
  5410. {
  5411. if ($this->player !== null)
  5412. {
  5413. return $this->player;
  5414. }
  5415. else
  5416. {
  5417. return null;
  5418. }
  5419. }
  5420. function get_rating($key = 0)
  5421. {
  5422. $ratings = $this->get_ratings();
  5423. if (isset($ratings[$key]))
  5424. {
  5425. return $ratings[$key];
  5426. }
  5427. else
  5428. {
  5429. return null;
  5430. }
  5431. }
  5432. function get_ratings()
  5433. {
  5434. if ($this->ratings !== null)
  5435. {
  5436. return $this->ratings;
  5437. }
  5438. else
  5439. {
  5440. return null;
  5441. }
  5442. }
  5443. function get_restriction($key = 0)
  5444. {
  5445. $restrictions = $this->get_restrictions();
  5446. if (isset($restrictions[$key]))
  5447. {
  5448. return $restrictions[$key];
  5449. }
  5450. else
  5451. {
  5452. return null;
  5453. }
  5454. }
  5455. function get_restrictions()
  5456. {
  5457. if ($this->restrictions !== null)
  5458. {
  5459. return $this->restrictions;
  5460. }
  5461. else
  5462. {
  5463. return null;
  5464. }
  5465. }
  5466. function get_sampling_rate()
  5467. {
  5468. if ($this->samplingrate !== null)
  5469. {
  5470. return $this->samplingrate;
  5471. }
  5472. else
  5473. {
  5474. return null;
  5475. }
  5476. }
  5477. function get_size()
  5478. {
  5479. $length = $this->get_length();
  5480. if ($length !== null)
  5481. {
  5482. return round($length/1048576, 2);
  5483. }
  5484. else
  5485. {
  5486. return null;
  5487. }
  5488. }
  5489. function get_thumbnail($key = 0)
  5490. {
  5491. $thumbnails = $this->get_thumbnails();
  5492. if (isset($thumbnails[$key]))
  5493. {
  5494. return $thumbnails[$key];
  5495. }
  5496. else
  5497. {
  5498. return null;
  5499. }
  5500. }
  5501. function get_thumbnails()
  5502. {
  5503. if ($this->thumbnails !== null)
  5504. {
  5505. return $this->thumbnails;
  5506. }
  5507. else
  5508. {
  5509. return null;
  5510. }
  5511. }
  5512. function get_title()
  5513. {
  5514. if ($this->title !== null)
  5515. {
  5516. return $this->title;
  5517. }
  5518. else
  5519. {
  5520. return null;
  5521. }
  5522. }
  5523. function get_type()
  5524. {
  5525. if ($this->type !== null)
  5526. {
  5527. return $this->type;
  5528. }
  5529. else
  5530. {
  5531. return null;
  5532. }
  5533. }
  5534. function get_width()
  5535. {
  5536. if ($this->width !== null)
  5537. {
  5538. return $this->width;
  5539. }
  5540. else
  5541. {
  5542. return null;
  5543. }
  5544. }
  5545. function native_embed($options='')
  5546. {
  5547. return $this->embed($options, true);
  5548. }
  5549. /**
  5550. * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
  5551. */
  5552. function embed($options = '', $native = false)
  5553. {
  5554. // Set up defaults
  5555. $audio = '';
  5556. $video = '';
  5557. $alt = '';
  5558. $altclass = '';
  5559. $loop = 'false';
  5560. $width = 'auto';
  5561. $height = 'auto';
  5562. $bgcolor = '#ffffff';
  5563. $mediaplayer = '';
  5564. $widescreen = false;
  5565. $handler = $this->get_handler();
  5566. $type = $this->get_real_type();
  5567. // Process options and reassign values as necessary
  5568. if (is_array($options))
  5569. {
  5570. extract($options);
  5571. }
  5572. else
  5573. {
  5574. $options = explode(',', $options);
  5575. foreach($options as $option)
  5576. {
  5577. $opt = explode(':', $option, 2);
  5578. if (isset($opt[0], $opt[1]))
  5579. {
  5580. $opt[0] = trim($opt[0]);
  5581. $opt[1] = trim($opt[1]);
  5582. switch ($opt[0])
  5583. {
  5584. case 'audio':
  5585. $audio = $opt[1];
  5586. break;
  5587. case 'video':
  5588. $video = $opt[1];
  5589. break;
  5590. case 'alt':
  5591. $alt = $opt[1];
  5592. break;
  5593. case 'altclass':
  5594. $altclass = $opt[1];
  5595. break;
  5596. case 'loop':
  5597. $loop = $opt[1];
  5598. break;
  5599. case 'width':
  5600. $width = $opt[1];
  5601. break;
  5602. case 'height':
  5603. $height = $opt[1];
  5604. break;
  5605. case 'bgcolor':
  5606. $bgcolor = $opt[1];
  5607. break;
  5608. case 'mediaplayer':
  5609. $mediaplayer = $opt[1];
  5610. break;
  5611. case 'widescreen':
  5612. $widescreen = $opt[1];
  5613. break;
  5614. }
  5615. }
  5616. }
  5617. }
  5618. $mime = explode('/', $type, 2);
  5619. $mime = $mime[0];
  5620. // Process values for 'auto'
  5621. if ($width == 'auto')
  5622. {
  5623. if ($mime == 'video')
  5624. {
  5625. if ($height == 'auto')
  5626. {
  5627. $width = 480;
  5628. }
  5629. elseif ($widescreen)
  5630. {
  5631. $width = round((intval($height)/9)*16);
  5632. }
  5633. else
  5634. {
  5635. $width = round((intval($height)/3)*4);
  5636. }
  5637. }
  5638. else
  5639. {
  5640. $width = '100%';
  5641. }
  5642. }
  5643. if ($height == 'auto')
  5644. {
  5645. if ($mime == 'audio')
  5646. {
  5647. $height = 0;
  5648. }
  5649. elseif ($mime == 'video')
  5650. {
  5651. if ($width == 'auto')
  5652. {
  5653. if ($widescreen)
  5654. {
  5655. $height = 270;
  5656. }
  5657. else
  5658. {
  5659. $height = 360;
  5660. }
  5661. }
  5662. elseif ($widescreen)
  5663. {
  5664. $height = round((intval($width)/16)*9);
  5665. }
  5666. else
  5667. {
  5668. $height = round((intval($width)/4)*3);
  5669. }
  5670. }
  5671. else
  5672. {
  5673. $height = 376;
  5674. }
  5675. }
  5676. elseif ($mime == 'audio')
  5677. {
  5678. $height = 0;
  5679. }
  5680. // Set proper placeholder value
  5681. if ($mime == 'audio')
  5682. {
  5683. $placeholder = $audio;
  5684. }
  5685. elseif ($mime == 'video')
  5686. {
  5687. $placeholder = $video;
  5688. }
  5689. $embed = '';
  5690. // Make sure the JS library is included
  5691. if (!$native)
  5692. {
  5693. static $javascript_outputted = null;
  5694. if (!$javascript_outputted && $this->javascript)
  5695. {
  5696. $embed .= '<script type="text/javascript" src="?' . htmlspecialchars($this->javascript) . '"></script>';
  5697. $javascript_outputted = true;
  5698. }
  5699. }
  5700. // Odeo Feed MP3's
  5701. if ($handler == 'odeo')
  5702. {
  5703. if ($native)
  5704. {
  5705. $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://adobe.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url=' . $this->get_link() . '"></embed>';
  5706. }
  5707. else
  5708. {
  5709. $embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>';
  5710. }
  5711. }
  5712. // Flash
  5713. elseif ($handler == 'flash')
  5714. {
  5715. if ($native)
  5716. {
  5717. $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
  5718. }
  5719. else
  5720. {
  5721. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  5722. }
  5723. }
  5724. // Flash Media Player file types.
  5725. // Preferred handler for MP3 file types.
  5726. elseif ($handler == 'fmedia' || ($handler == 'mp3' && $mediaplayer != ''))
  5727. {
  5728. $height += 20;
  5729. if ($native)
  5730. {
  5731. $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>";
  5732. }
  5733. else
  5734. {
  5735. $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
  5736. }
  5737. }
  5738. // QuickTime 7 file types. Need to test with QuickTime 6.
  5739. // Only handle MP3's if the Flash Media Player is not present.
  5740. elseif ($handler == 'quicktime' || ($handler == 'mp3' && $mediaplayer == ''))
  5741. {
  5742. $height += 16;
  5743. if ($native)
  5744. {
  5745. if ($placeholder != ""){
  5746. $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
  5747. }
  5748. else {
  5749. $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
  5750. }
  5751. }
  5752. else
  5753. {
  5754. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  5755. }
  5756. }
  5757. // Windows Media
  5758. elseif ($handler == 'wmedia')
  5759. {
  5760. $height += 45;
  5761. if ($native)
  5762. {
  5763. $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>";
  5764. }
  5765. else
  5766. {
  5767. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  5768. }
  5769. }
  5770. // Everything else
  5771. else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  5772. return $embed;
  5773. }
  5774. function get_real_type($find_handler = false)
  5775. {
  5776. // If it's Odeo, let's get it out of the way.
  5777. if (substr(strtolower($this->get_link()), 0, 15) == 'http://odeo.com')
  5778. {
  5779. return 'odeo';
  5780. }
  5781. // Mime-types by handler.
  5782. $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
  5783. $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
  5784. $types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime
  5785. $types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media
  5786. $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
  5787. if ($this->get_type() !== null)
  5788. {
  5789. $type = strtolower($this->type);
  5790. }
  5791. else
  5792. {
  5793. $type = null;
  5794. }
  5795. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  5796. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
  5797. {
  5798. switch (strtolower($this->get_extension()))
  5799. {
  5800. // Audio mime-types
  5801. case 'aac':
  5802. case 'adts':
  5803. $type = 'audio/acc';
  5804. break;
  5805. case 'aif':
  5806. case 'aifc':
  5807. case 'aiff':
  5808. case 'cdda':
  5809. $type = 'audio/aiff';
  5810. break;
  5811. case 'bwf':
  5812. $type = 'audio/wav';
  5813. break;
  5814. case 'kar':
  5815. case 'mid':
  5816. case 'midi':
  5817. case 'smf':
  5818. $type = 'audio/midi';
  5819. break;
  5820. case 'm4a':
  5821. $type = 'audio/x-m4a';
  5822. break;
  5823. case 'mp3':
  5824. case 'swa':
  5825. $type = 'audio/mp3';
  5826. break;
  5827. case 'wav':
  5828. $type = 'audio/wav';
  5829. break;
  5830. case 'wax':
  5831. $type = 'audio/x-ms-wax';
  5832. break;
  5833. case 'wma':
  5834. $type = 'audio/x-ms-wma';
  5835. break;
  5836. // Video mime-types
  5837. case '3gp':
  5838. case '3gpp':
  5839. $type = 'video/3gpp';
  5840. break;
  5841. case '3g2':
  5842. case '3gp2':
  5843. $type = 'video/3gpp2';
  5844. break;
  5845. case 'asf':
  5846. $type = 'video/x-ms-asf';
  5847. break;
  5848. case 'flv':
  5849. $type = 'video/x-flv';
  5850. break;
  5851. case 'm1a':
  5852. case 'm1s':
  5853. case 'm1v':
  5854. case 'm15':
  5855. case 'm75':
  5856. case 'mp2':
  5857. case 'mpa':
  5858. case 'mpeg':
  5859. case 'mpg':
  5860. case 'mpm':
  5861. case 'mpv':
  5862. $type = 'video/mpeg';
  5863. break;
  5864. case 'm4v':
  5865. $type = 'video/x-m4v';
  5866. break;
  5867. case 'mov':
  5868. case 'qt':
  5869. $type = 'video/quicktime';
  5870. break;
  5871. case 'mp4':
  5872. case 'mpg4':
  5873. $type = 'video/mp4';
  5874. break;
  5875. case 'sdv':
  5876. $type = 'video/sd-video';
  5877. break;
  5878. case 'wm':
  5879. $type = 'video/x-ms-wm';
  5880. break;
  5881. case 'wmv':
  5882. $type = 'video/x-ms-wmv';
  5883. break;
  5884. case 'wvx':
  5885. $type = 'video/x-ms-wvx';
  5886. break;
  5887. // Flash mime-types
  5888. case 'spl':
  5889. $type = 'application/futuresplash';
  5890. break;
  5891. case 'swf':
  5892. $type = 'application/x-shockwave-flash';
  5893. break;
  5894. }
  5895. }
  5896. if ($find_handler)
  5897. {
  5898. if (in_array($type, $types_flash))
  5899. {
  5900. return 'flash';
  5901. }
  5902. elseif (in_array($type, $types_fmedia))
  5903. {
  5904. return 'fmedia';
  5905. }
  5906. elseif (in_array($type, $types_quicktime))
  5907. {
  5908. return 'quicktime';
  5909. }
  5910. elseif (in_array($type, $types_wmedia))
  5911. {
  5912. return 'wmedia';
  5913. }
  5914. elseif (in_array($type, $types_mp3))
  5915. {
  5916. return 'mp3';
  5917. }
  5918. else
  5919. {
  5920. return null;
  5921. }
  5922. }
  5923. else
  5924. {
  5925. return $type;
  5926. }
  5927. }
  5928. }
  5929. class SimplePie_Caption
  5930. {
  5931. var $type;
  5932. var $lang;
  5933. var $startTime;
  5934. var $endTime;
  5935. var $text;
  5936. // Constructor, used to input the data
  5937. function SimplePie_Caption($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
  5938. {
  5939. $this->type = $type;
  5940. $this->lang = $lang;
  5941. $this->startTime = $startTime;
  5942. $this->endTime = $endTime;
  5943. $this->text = $text;
  5944. }
  5945. function __toString()
  5946. {
  5947. // There is no $this->data here
  5948. return md5(serialize($this));
  5949. }
  5950. function get_endtime()
  5951. {
  5952. if ($this->endTime !== null)
  5953. {
  5954. return $this->endTime;
  5955. }
  5956. else
  5957. {
  5958. return null;
  5959. }
  5960. }
  5961. function get_language()
  5962. {
  5963. if ($this->lang !== null)
  5964. {
  5965. return $this->lang;
  5966. }
  5967. else
  5968. {
  5969. return null;
  5970. }
  5971. }
  5972. function get_starttime()
  5973. {
  5974. if ($this->startTime !== null)
  5975. {
  5976. return $this->startTime;
  5977. }
  5978. else
  5979. {
  5980. return null;
  5981. }
  5982. }
  5983. function get_text()
  5984. {
  5985. if ($this->text !== null)
  5986. {
  5987. return $this->text;
  5988. }
  5989. else
  5990. {
  5991. return null;
  5992. }
  5993. }
  5994. function get_type()
  5995. {
  5996. if ($this->type !== null)
  5997. {
  5998. return $this->type;
  5999. }
  6000. else
  6001. {
  6002. return null;
  6003. }
  6004. }
  6005. }
  6006. class SimplePie_Credit
  6007. {
  6008. var $role;
  6009. var $scheme;
  6010. var $name;
  6011. // Constructor, used to input the data
  6012. function SimplePie_Credit($role = null, $scheme = null, $name = null)
  6013. {
  6014. $this->role = $role;
  6015. $this->scheme = $scheme;
  6016. $this->name = $name;
  6017. }
  6018. function __toString()
  6019. {
  6020. // There is no $this->data here
  6021. return md5(serialize($this));
  6022. }
  6023. function get_role()
  6024. {
  6025. if ($this->role !== null)
  6026. {
  6027. return $this->role;
  6028. }
  6029. else
  6030. {
  6031. return null;
  6032. }
  6033. }
  6034. function get_scheme()
  6035. {
  6036. if ($this->scheme !== null)
  6037. {
  6038. return $this->scheme;
  6039. }
  6040. else
  6041. {
  6042. return null;
  6043. }
  6044. }
  6045. function get_name()
  6046. {
  6047. if ($this->name !== null)
  6048. {
  6049. return $this->name;
  6050. }
  6051. else
  6052. {
  6053. return null;
  6054. }
  6055. }
  6056. }
  6057. class SimplePie_Copyright
  6058. {
  6059. var $url;
  6060. var $label;
  6061. // Constructor, used to input the data
  6062. function SimplePie_Copyright($url = null, $label = null)
  6063. {
  6064. $this->url = $url;
  6065. $this->label = $label;
  6066. }
  6067. function __toString()
  6068. {
  6069. // There is no $this->data here
  6070. return md5(serialize($this));
  6071. }
  6072. function get_url()
  6073. {
  6074. if ($this->url !== null)
  6075. {
  6076. return $this->url;
  6077. }
  6078. else
  6079. {
  6080. return null;
  6081. }
  6082. }
  6083. function get_attribution()
  6084. {
  6085. if ($this->label !== null)
  6086. {
  6087. return $this->label;
  6088. }
  6089. else
  6090. {
  6091. return null;
  6092. }
  6093. }
  6094. }
  6095. class SimplePie_Rating
  6096. {
  6097. var $scheme;
  6098. var $value;
  6099. // Constructor, used to input the data
  6100. function SimplePie_Rating($scheme = null, $value = null)
  6101. {
  6102. $this->scheme = $scheme;
  6103. $this->value = $value;
  6104. }
  6105. function __toString()
  6106. {
  6107. // There is no $this->data here
  6108. return md5(serialize($this));
  6109. }
  6110. function get_scheme()
  6111. {
  6112. if ($this->scheme !== null)
  6113. {
  6114. return $this->scheme;
  6115. }
  6116. else
  6117. {
  6118. return null;
  6119. }
  6120. }
  6121. function get_value()
  6122. {
  6123. if ($this->value !== null)
  6124. {
  6125. return $this->value;
  6126. }
  6127. else
  6128. {
  6129. return null;
  6130. }
  6131. }
  6132. }
  6133. class SimplePie_Restriction
  6134. {
  6135. var $relationship;
  6136. var $type;
  6137. var $value;
  6138. // Constructor, used to input the data
  6139. function SimplePie_Restriction($relationship = null, $type = null, $value = null)
  6140. {
  6141. $this->relationship = $relationship;
  6142. $this->type = $type;
  6143. $this->value = $value;
  6144. }
  6145. function __toString()
  6146. {
  6147. // There is no $this->data here
  6148. return md5(serialize($this));
  6149. }
  6150. function get_relationship()
  6151. {
  6152. if ($this->relationship !== null)
  6153. {
  6154. return $this->relationship;
  6155. }
  6156. else
  6157. {
  6158. return null;
  6159. }
  6160. }
  6161. function get_type()
  6162. {
  6163. if ($this->type !== null)
  6164. {
  6165. return $this->type;
  6166. }
  6167. else
  6168. {
  6169. return null;
  6170. }
  6171. }
  6172. function get_value()
  6173. {
  6174. if ($this->value !== null)
  6175. {
  6176. return $this->value;
  6177. }
  6178. else
  6179. {
  6180. return null;
  6181. }
  6182. }
  6183. }
  6184. /**
  6185. * @todo Move to properly supporting RFC2616 (HTTP/1.1)
  6186. */
  6187. class SimplePie_File
  6188. {
  6189. var $url;
  6190. var $useragent;
  6191. var $success = true;
  6192. var $headers = array();
  6193. var $body;
  6194. var $status_code;
  6195. var $redirects = 0;
  6196. var $error;
  6197. var $method = SIMPLEPIE_FILE_SOURCE_NONE;
  6198. function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
  6199. {
  6200. if (class_exists('idna_convert'))
  6201. {
  6202. $idn =& new idna_convert;
  6203. $parsed = SimplePie_Misc::parse_url($url);
  6204. $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  6205. }
  6206. $this->url = $url;
  6207. $this->useragent = $useragent;
  6208. if (preg_match('/^http(s)?:\/\//i', $url))
  6209. {
  6210. if ($useragent === null)
  6211. {
  6212. $useragent = ini_get('user_agent');
  6213. $this->useragent = $useragent;
  6214. }
  6215. if (!is_array($headers))
  6216. {
  6217. $headers = array();
  6218. }
  6219. if (!$force_fsockopen && function_exists('curl_exec'))
  6220. {
  6221. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
  6222. $fp = curl_init();
  6223. $headers2 = array();
  6224. foreach ($headers as $key => $value)
  6225. {
  6226. $headers2[] = "$key: $value";
  6227. }
  6228. if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
  6229. {
  6230. curl_setopt($fp, CURLOPT_ENCODING, '');
  6231. }
  6232. curl_setopt($fp, CURLOPT_URL, $url);
  6233. curl_setopt($fp, CURLOPT_HEADER, 1);
  6234. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  6235. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  6236. curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
  6237. curl_setopt($fp, CURLOPT_REFERER, $url);
  6238. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  6239. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  6240. if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
  6241. {
  6242. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  6243. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  6244. }
  6245. $this->headers = curl_exec($fp);
  6246. if (curl_errno($fp) == 23 || curl_errno($fp) == 61)
  6247. {
  6248. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  6249. $this->headers = curl_exec($fp);
  6250. }
  6251. if (curl_errno($fp))
  6252. {
  6253. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  6254. $this->success = false;
  6255. }
  6256. else
  6257. {
  6258. $info = curl_getinfo($fp);
  6259. curl_close($fp);
  6260. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
  6261. $this->headers = array_pop($this->headers);
  6262. $parser =& new SimplePie_HTTP_Parser($this->headers);
  6263. if ($parser->parse())
  6264. {
  6265. $this->headers = $parser->headers;
  6266. $this->body = $parser->body;
  6267. $this->status_code = $parser->status_code;
  6268. if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  6269. {
  6270. $this->redirects++;
  6271. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  6272. return $this->SimplePie_File($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  6273. }
  6274. }
  6275. }
  6276. }
  6277. else
  6278. {
  6279. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
  6280. $url_parts = parse_url($url);
  6281. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
  6282. {
  6283. $url_parts['host'] = "ssl://$url_parts[host]";
  6284. $url_parts['port'] = 443;
  6285. }
  6286. if (!isset($url_parts['port']))
  6287. {
  6288. $url_parts['port'] = 80;
  6289. }
  6290. $fp = @fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
  6291. if (!$fp)
  6292. {
  6293. $this->error = 'fsockopen error: ' . $errstr;
  6294. $this->success = false;
  6295. }
  6296. else
  6297. {
  6298. stream_set_timeout($fp, $timeout);
  6299. if (isset($url_parts['path']))
  6300. {
  6301. if (isset($url_parts['query']))
  6302. {
  6303. $get = "$url_parts[path]?$url_parts[query]";
  6304. }
  6305. else
  6306. {
  6307. $get = $url_parts['path'];
  6308. }
  6309. }
  6310. else
  6311. {
  6312. $get = '/';
  6313. }
  6314. $out = "GET $get HTTP/1.0\r\n";
  6315. $out .= "Host: $url_parts[host]\r\n";
  6316. $out .= "User-Agent: $useragent\r\n";
  6317. if (extension_loaded('zlib'))
  6318. {
  6319. $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
  6320. }
  6321. if (isset($url_parts['user']) && isset($url_parts['pass']))
  6322. {
  6323. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  6324. }
  6325. foreach ($headers as $key => $value)
  6326. {
  6327. $out .= "$key: $value\r\n";
  6328. }
  6329. $out .= "Connection: Close\r\n\r\n";
  6330. fwrite($fp, $out);
  6331. $info = stream_get_meta_data($fp);
  6332. $this->headers = '';
  6333. while (!$info['eof'] && !$info['timed_out'])
  6334. {
  6335. $this->headers .= fread($fp, 1160);
  6336. $info = stream_get_meta_data($fp);
  6337. }
  6338. if (!$info['timed_out'])
  6339. {
  6340. $parser =& new SimplePie_HTTP_Parser($this->headers);
  6341. if ($parser->parse())
  6342. {
  6343. $this->headers = $parser->headers;
  6344. $this->body = $parser->body;
  6345. $this->status_code = $parser->status_code;
  6346. if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  6347. {
  6348. $this->redirects++;
  6349. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  6350. return $this->SimplePie_File($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  6351. }
  6352. if (isset($this->headers['content-encoding']))
  6353. {
  6354. // Hey, we act dumb elsewhere, so let's do that here too
  6355. switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
  6356. {
  6357. case 'gzip':
  6358. case 'x-gzip':
  6359. $decoder = new SimplePie_gzdecode($this->body);
  6360. if (!$decoder->parse())
  6361. {
  6362. $this->error = 'Unable to decode HTTP "gzip" stream';
  6363. $this->success = false;
  6364. }
  6365. else
  6366. {
  6367. $this->body = $decoder->data;
  6368. }
  6369. break;
  6370. case 'deflate':
  6371. if (($body = gzuncompress($this->body)) === false)
  6372. {
  6373. if (($body = gzinflate($this->body)) === false)
  6374. {
  6375. $this->error = 'Unable to decode HTTP "deflate" stream';
  6376. $this->success = false;
  6377. }
  6378. }
  6379. $this->body = $body;
  6380. break;
  6381. default:
  6382. $this->error = 'Unknown content coding';
  6383. $this->success = false;
  6384. }
  6385. }
  6386. }
  6387. }
  6388. else
  6389. {
  6390. $this->error = 'fsocket timed out';
  6391. $this->success = false;
  6392. }
  6393. fclose($fp);
  6394. }
  6395. }
  6396. }
  6397. else
  6398. {
  6399. $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
  6400. if (!$this->body = file_get_contents($url))
  6401. {
  6402. $this->error = 'file_get_contents could not read the file';
  6403. $this->success = false;
  6404. }
  6405. }
  6406. }
  6407. }
  6408. /**
  6409. * HTTP Response Parser
  6410. *
  6411. * @package SimplePie
  6412. */
  6413. class SimplePie_HTTP_Parser
  6414. {
  6415. /**
  6416. * HTTP Version
  6417. *
  6418. * @access public
  6419. * @var float
  6420. */
  6421. var $http_version = 0.0;
  6422. /**
  6423. * Status code
  6424. *
  6425. * @access public
  6426. * @var int
  6427. */
  6428. var $status_code = 0;
  6429. /**
  6430. * Reason phrase
  6431. *
  6432. * @access public
  6433. * @var string
  6434. */
  6435. var $reason = '';
  6436. /**
  6437. * Key/value pairs of the headers
  6438. *
  6439. * @access public
  6440. * @var array
  6441. */
  6442. var $headers = array();
  6443. /**
  6444. * Body of the response
  6445. *
  6446. * @access public
  6447. * @var string
  6448. */
  6449. var $body = '';
  6450. /**
  6451. * Current state of the state machine
  6452. *
  6453. * @access private
  6454. * @var string
  6455. */
  6456. var $state = 'http_version';
  6457. /**
  6458. * Input data
  6459. *
  6460. * @access private
  6461. * @var string
  6462. */
  6463. var $data = '';
  6464. /**
  6465. * Input data length (to avoid calling strlen() everytime this is needed)
  6466. *
  6467. * @access private
  6468. * @var int
  6469. */
  6470. var $data_length = 0;
  6471. /**
  6472. * Current position of the pointer
  6473. *
  6474. * @var int
  6475. * @access private
  6476. */
  6477. var $position = 0;
  6478. /**
  6479. * Name of the hedaer currently being parsed
  6480. *
  6481. * @access private
  6482. * @var string
  6483. */
  6484. var $name = '';
  6485. /**
  6486. * Value of the hedaer currently being parsed
  6487. *
  6488. * @access private
  6489. * @var string
  6490. */
  6491. var $value = '';
  6492. /**
  6493. * Create an instance of the class with the input data
  6494. *
  6495. * @access public
  6496. * @param string $data Input data
  6497. */
  6498. function SimplePie_HTTP_Parser($data)
  6499. {
  6500. $this->data = $data;
  6501. $this->data_length = strlen($this->data);
  6502. }
  6503. /**
  6504. * Parse the input data
  6505. *
  6506. * @access public
  6507. * @return bool true on success, false on failure
  6508. */
  6509. function parse()
  6510. {
  6511. while ($this->state && $this->state !== 'emit' && $this->has_data())
  6512. {
  6513. $state = $this->state;
  6514. $this->$state();
  6515. }
  6516. $this->data = '';
  6517. if ($this->state === 'emit' || $this->state === 'body')
  6518. {
  6519. return true;
  6520. }
  6521. else
  6522. {
  6523. $this->http_version = '';
  6524. $this->status_code = '';
  6525. $this->reason = '';
  6526. $this->headers = array();
  6527. $this->body = '';
  6528. return false;
  6529. }
  6530. }
  6531. /**
  6532. * Check whether there is data beyond the pointer
  6533. *
  6534. * @access private
  6535. * @return bool true if there is further data, false if not
  6536. */
  6537. function has_data()
  6538. {
  6539. return (bool) ($this->position < $this->data_length);
  6540. }
  6541. /**
  6542. * See if the next character is LWS
  6543. *
  6544. * @access private
  6545. * @return bool true if the next character is LWS, false if not
  6546. */
  6547. function is_linear_whitespace()
  6548. {
  6549. return (bool) ($this->data[$this->position] === "\x09"
  6550. || $this->data[$this->position] === "\x20"
  6551. || ($this->data[$this->position] === "\x0A"
  6552. && isset($this->data[$this->position + 1])
  6553. && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
  6554. }
  6555. /**
  6556. * Parse the HTTP version
  6557. *
  6558. * @access private
  6559. */
  6560. function http_version()
  6561. {
  6562. if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
  6563. {
  6564. $len = strspn($this->data, '0123456789.', 5);
  6565. $this->http_version = substr($this->data, 5, $len);
  6566. $this->position += 5 + $len;
  6567. if (substr_count($this->http_version, '.') <= 1)
  6568. {
  6569. $this->http_version = (float) $this->http_version;
  6570. $this->position += strspn($this->data, "\x09\x20", $this->position);
  6571. $this->state = 'status';
  6572. }
  6573. else
  6574. {
  6575. $this->state = false;
  6576. }
  6577. }
  6578. else
  6579. {
  6580. $this->state = false;
  6581. }
  6582. }
  6583. /**
  6584. * Parse the status code
  6585. *
  6586. * @access private
  6587. */
  6588. function status()
  6589. {
  6590. if ($len = strspn($this->data, '0123456789', $this->position))
  6591. {
  6592. $this->status_code = (int) substr($this->data, $this->position, $len);
  6593. $this->position += $len;
  6594. $this->state = 'reason';
  6595. }
  6596. else
  6597. {
  6598. $this->state = false;
  6599. }
  6600. }
  6601. /**
  6602. * Parse the reason phrase
  6603. *
  6604. * @access private
  6605. */
  6606. function reason()
  6607. {
  6608. $len = strcspn($this->data, "\x0A", $this->position);
  6609. $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
  6610. $this->position += $len + 1;
  6611. $this->state = 'new_line';
  6612. }
  6613. /**
  6614. * Deal with a new line, shifting data around as needed
  6615. *
  6616. * @access private
  6617. */
  6618. function new_line()
  6619. {
  6620. $this->value = trim($this->value, "\x0D\x20");
  6621. if ($this->name !== '' && $this->value !== '')
  6622. {
  6623. $this->name = strtolower($this->name);
  6624. if (isset($this->headers[$this->name]))
  6625. {
  6626. $this->headers[$this->name] .= ', ' . $this->value;
  6627. }
  6628. else
  6629. {
  6630. $this->headers[$this->name] = $this->value;
  6631. }
  6632. }
  6633. $this->name = '';
  6634. $this->value = '';
  6635. if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
  6636. {
  6637. $this->position += 2;
  6638. $this->state = 'body';
  6639. }
  6640. elseif ($this->data[$this->position] === "\x0A")
  6641. {
  6642. $this->position++;
  6643. $this->state = 'body';
  6644. }
  6645. else
  6646. {
  6647. $this->state = 'name';
  6648. }
  6649. }
  6650. /**
  6651. * Parse a header name
  6652. *
  6653. * @access private
  6654. */
  6655. function name()
  6656. {
  6657. $len = strcspn($this->data, "\x0A:", $this->position);
  6658. if (isset($this->data[$this->position + $len]))
  6659. {
  6660. if ($this->data[$this->position + $len] === "\x0A")
  6661. {
  6662. $this->position += $len;
  6663. $this->state = 'new_line';
  6664. }
  6665. else
  6666. {
  6667. $this->name = substr($this->data, $this->position, $len);
  6668. $this->position += $len + 1;
  6669. $this->state = 'value';
  6670. }
  6671. }
  6672. else
  6673. {
  6674. $this->state = false;
  6675. }
  6676. }
  6677. /**
  6678. * Parse LWS, replacing consecutive LWS characters with a single space
  6679. *
  6680. * @access private
  6681. */
  6682. function linear_whitespace()
  6683. {
  6684. do
  6685. {
  6686. if (substr($this->data, $this->position, 2) === "\x0D\x0A")
  6687. {
  6688. $this->position += 2;
  6689. }
  6690. elseif ($this->data[$this->position] === "\x0A")
  6691. {
  6692. $this->position++;
  6693. }
  6694. $this->position += strspn($this->data, "\x09\x20", $this->position);
  6695. } while ($this->has_data() && $this->is_linear_whitespace());
  6696. $this->value .= "\x20";
  6697. }
  6698. /**
  6699. * See what state to move to while within non-quoted header values
  6700. *
  6701. * @access private
  6702. */
  6703. function value()
  6704. {
  6705. if ($this->is_linear_whitespace())
  6706. {
  6707. $this->linear_whitespace();
  6708. }
  6709. else
  6710. {
  6711. switch ($this->data[$this->position])
  6712. {
  6713. case '"':
  6714. $this->position++;
  6715. $this->state = 'quote';
  6716. break;
  6717. case "\x0A":
  6718. $this->position++;
  6719. $this->state = 'new_line';
  6720. break;
  6721. default:
  6722. $this->state = 'value_char';
  6723. break;
  6724. }
  6725. }
  6726. }
  6727. /**
  6728. * Parse a header value while outside quotes
  6729. *
  6730. * @access private
  6731. */
  6732. function value_char()
  6733. {
  6734. $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
  6735. $this->value .= substr($this->data, $this->position, $len);
  6736. $this->position += $len;
  6737. $this->state = 'value';
  6738. }
  6739. /**
  6740. * See what state to move to while within quoted header values
  6741. *
  6742. * @access private
  6743. */
  6744. function quote()
  6745. {
  6746. if ($this->is_linear_whitespace())
  6747. {
  6748. $this->linear_whitespace();
  6749. }
  6750. else
  6751. {
  6752. switch ($this->data[$this->position])
  6753. {
  6754. case '"':
  6755. $this->position++;
  6756. $this->state = 'value';
  6757. break;
  6758. case "\x0A":
  6759. $this->position++;
  6760. $this->state = 'new_line';
  6761. break;
  6762. case '\\':
  6763. $this->position++;
  6764. $this->state = 'quote_escaped';
  6765. break;
  6766. default:
  6767. $this->state = 'quote_char';
  6768. break;
  6769. }
  6770. }
  6771. }
  6772. /**
  6773. * Parse a header value while within quotes
  6774. *
  6775. * @access private
  6776. */
  6777. function quote_char()
  6778. {
  6779. $len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
  6780. $this->value .= substr($this->data, $this->position, $len);
  6781. $this->position += $len;
  6782. $this->state = 'value';
  6783. }
  6784. /**
  6785. * Parse an escaped character within quotes
  6786. *
  6787. * @access private
  6788. */
  6789. function quote_escaped()
  6790. {
  6791. $this->value .= $this->data[$this->position];
  6792. $this->position++;
  6793. $this->state = 'quote';
  6794. }
  6795. /**
  6796. * Parse the body
  6797. *
  6798. * @access private
  6799. */
  6800. function body()
  6801. {
  6802. $this->body = substr($this->data, $this->position);
  6803. $this->state = 'emit';
  6804. }
  6805. }
  6806. /**
  6807. * gzdecode
  6808. *
  6809. * @package SimplePie
  6810. */
  6811. class SimplePie_gzdecode
  6812. {
  6813. /**
  6814. * Compressed data
  6815. *
  6816. * @access private
  6817. * @see gzdecode::$data
  6818. */
  6819. var $compressed_data;
  6820. /**
  6821. * Size of compressed data
  6822. *
  6823. * @access private
  6824. */
  6825. var $compressed_size;
  6826. /**
  6827. * Minimum size of a valid gzip string
  6828. *
  6829. * @access private
  6830. */
  6831. var $min_compressed_size = 18;
  6832. /**
  6833. * Current position of pointer
  6834. *
  6835. * @access private
  6836. */
  6837. var $position = 0;
  6838. /**
  6839. * Flags (FLG)
  6840. *
  6841. * @access private
  6842. */
  6843. var $flags;
  6844. /**
  6845. * Uncompressed data
  6846. *
  6847. * @access public
  6848. * @see gzdecode::$compressed_data
  6849. */
  6850. var $data;
  6851. /**
  6852. * Modified time
  6853. *
  6854. * @access public
  6855. */
  6856. var $MTIME;
  6857. /**
  6858. * Extra Flags
  6859. *
  6860. * @access public
  6861. */
  6862. var $XFL;
  6863. /**
  6864. * Operating System
  6865. *
  6866. * @access public
  6867. */
  6868. var $OS;
  6869. /**
  6870. * Subfield ID 1
  6871. *
  6872. * @access public
  6873. * @see gzdecode::$extra_field
  6874. * @see gzdecode::$SI2
  6875. */
  6876. var $SI1;
  6877. /**
  6878. * Subfield ID 2
  6879. *
  6880. * @access public
  6881. * @see gzdecode::$extra_field
  6882. * @see gzdecode::$SI1
  6883. */
  6884. var $SI2;
  6885. /**
  6886. * Extra field content
  6887. *
  6888. * @access public
  6889. * @see gzdecode::$SI1
  6890. * @see gzdecode::$SI2
  6891. */
  6892. var $extra_field;
  6893. /**
  6894. * Original filename
  6895. *
  6896. * @access public
  6897. */
  6898. var $filename;
  6899. /**
  6900. * Human readable comment
  6901. *
  6902. * @access public
  6903. */
  6904. var $comment;
  6905. /**
  6906. * Don't allow anything to be set
  6907. *
  6908. * @access public
  6909. */
  6910. function __set($name, $value)
  6911. {
  6912. trigger_error("Cannot write property $name", E_USER_ERROR);
  6913. }
  6914. /**
  6915. * Set the compressed string and related properties
  6916. *
  6917. * @access public
  6918. */
  6919. function SimplePie_gzdecode($data)
  6920. {
  6921. $this->compressed_data = $data;
  6922. $this->compressed_size = strlen($data);
  6923. }
  6924. /**
  6925. * Decode the GZIP stream
  6926. *
  6927. * @access public
  6928. */
  6929. function parse()
  6930. {
  6931. if ($this->compressed_size >= $this->min_compressed_size)
  6932. {
  6933. // Check ID1, ID2, and CM
  6934. if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
  6935. {
  6936. return false;
  6937. }
  6938. // Get the FLG (FLaGs)
  6939. $this->flags = ord($this->compressed_data[3]);
  6940. // FLG bits above (1 << 4) are reserved
  6941. if ($this->flags > 0x1F)
  6942. {
  6943. return false;
  6944. }
  6945. // Advance the pointer after the above
  6946. $this->position += 4;
  6947. // MTIME
  6948. $mtime = substr($this->compressed_data, $this->position, 4);
  6949. // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
  6950. if (current(unpack('S', "\x00\x01")) === 1)
  6951. {
  6952. $mtime = strrev($mtime);
  6953. }
  6954. $this->MTIME = current(unpack('l', $mtime));
  6955. $this->position += 4;
  6956. // Get the XFL (eXtra FLags)
  6957. $this->XFL = ord($this->compressed_data[$this->position++]);
  6958. // Get the OS (Operating System)
  6959. $this->OS = ord($this->compressed_data[$this->position++]);
  6960. // Parse the FEXTRA
  6961. if ($this->flags & 4)
  6962. {
  6963. // Read subfield IDs
  6964. $this->SI1 = $this->compressed_data[$this->position++];
  6965. $this->SI2 = $this->compressed_data[$this->position++];
  6966. // SI2 set to zero is reserved for future use
  6967. if ($this->SI2 === "\x00")
  6968. {
  6969. return false;
  6970. }
  6971. // Get the length of the extra field
  6972. $len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  6973. $position += 2;
  6974. // Check the length of the string is still valid
  6975. $this->min_compressed_size += $len + 4;
  6976. if ($this->compressed_size >= $this->min_compressed_size)
  6977. {
  6978. // Set the extra field to the given data
  6979. $this->extra_field = substr($this->compressed_data, $this->position, $len);
  6980. $this->position += $len;
  6981. }
  6982. else
  6983. {
  6984. return false;
  6985. }
  6986. }
  6987. // Parse the FNAME
  6988. if ($this->flags & 8)
  6989. {
  6990. // Get the length of the filename
  6991. $len = strspn($this->compressed_data, "\x00", $this->position);
  6992. // Check the length of the string is still valid
  6993. $this->min_compressed_size += $len + 1;
  6994. if ($this->compressed_size >= $this->min_compressed_size)
  6995. {
  6996. // Set the original filename to the given string
  6997. $this->filename = substr($this->compressed_data, $this->position, $len);
  6998. $this->position += $len + 1;
  6999. }
  7000. else
  7001. {
  7002. return false;
  7003. }
  7004. }
  7005. // Parse the FCOMMENT
  7006. if ($this->flags & 16)
  7007. {
  7008. // Get the length of the comment
  7009. $len = strspn($this->compressed_data, "\x00", $this->position);
  7010. // Check the length of the string is still valid
  7011. $this->min_compressed_size += $len + 1;
  7012. if ($this->compressed_size >= $this->min_compressed_size)
  7013. {
  7014. // Set the original comment to the given string
  7015. $this->comment = substr($this->compressed_data, $this->position, $len);
  7016. $this->position += $len + 1;
  7017. }
  7018. else
  7019. {
  7020. return false;
  7021. }
  7022. }
  7023. // Parse the FHCRC
  7024. if ($this->flags & 2)
  7025. {
  7026. // Check the length of the string is still valid
  7027. $this->min_compressed_size += $len + 2;
  7028. if ($this->compressed_size >= $this->min_compressed_size)
  7029. {
  7030. // Read the CRC
  7031. $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  7032. // Check the CRC matches
  7033. if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
  7034. {
  7035. $this->position += 2;
  7036. }
  7037. else
  7038. {
  7039. return false;
  7040. }
  7041. }
  7042. else
  7043. {
  7044. return false;
  7045. }
  7046. }
  7047. // Decompress the actual data
  7048. if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
  7049. {
  7050. return false;
  7051. }
  7052. else
  7053. {
  7054. $this->position = $this->compressed_size - 8;
  7055. }
  7056. // Check CRC of data
  7057. $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  7058. $this->position += 4;
  7059. /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
  7060. {
  7061. return false;
  7062. }*/
  7063. // Check ISIZE of data
  7064. $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  7065. $this->position += 4;
  7066. if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
  7067. {
  7068. return false;
  7069. }
  7070. // Wow, against all odds, we've actually got a valid gzip string
  7071. return true;
  7072. }
  7073. else
  7074. {
  7075. return false;
  7076. }
  7077. }
  7078. }
  7079. class SimplePie_Cache
  7080. {
  7081. /**
  7082. * Don't call the constructor. Please.
  7083. *
  7084. * @access private
  7085. */
  7086. function SimplePie_Cache()
  7087. {
  7088. trigger_error('Please call SimplePie_Cache::create() instead of the constructor', E_USER_ERROR);
  7089. }
  7090. /**
  7091. * Create a new SimplePie_Cache object
  7092. *
  7093. * @static
  7094. * @access public
  7095. */
  7096. function create($location, $filename, $extension)
  7097. {
  7098. return new SimplePie_Cache_File($location, $filename, $extension);
  7099. }
  7100. }
  7101. class SimplePie_Cache_File
  7102. {
  7103. var $location;
  7104. var $filename;
  7105. var $extension;
  7106. var $name;
  7107. function SimplePie_Cache_File($location, $filename, $extension)
  7108. {
  7109. $this->location = $location;
  7110. $this->filename = rawurlencode($filename);
  7111. $this->extension = rawurlencode($extension);
  7112. $this->name = "$location/$this->filename.$this->extension";
  7113. }
  7114. function save($data)
  7115. {
  7116. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  7117. {
  7118. if (is_a($data, 'SimplePie'))
  7119. {
  7120. $data = $data->data;
  7121. }
  7122. $data = serialize($data);
  7123. if (function_exists('file_put_contents'))
  7124. {
  7125. return (bool) file_put_contents($this->name, $data);
  7126. }
  7127. else
  7128. {
  7129. $fp = fopen($this->name, 'wb');
  7130. if ($fp)
  7131. {
  7132. fwrite($fp, $data);
  7133. fclose($fp);
  7134. return true;
  7135. }
  7136. }
  7137. }
  7138. return false;
  7139. }
  7140. function load()
  7141. {
  7142. if (file_exists($this->name) && is_readable($this->name))
  7143. {
  7144. return unserialize(file_get_contents($this->name));
  7145. }
  7146. return false;
  7147. }
  7148. function mtime()
  7149. {
  7150. if (file_exists($this->name))
  7151. {
  7152. return filemtime($this->name);
  7153. }
  7154. return false;
  7155. }
  7156. function touch()
  7157. {
  7158. if (file_exists($this->name))
  7159. {
  7160. return touch($this->name);
  7161. }
  7162. return false;
  7163. }
  7164. function unlink()
  7165. {
  7166. if (file_exists($this->name))
  7167. {
  7168. return unlink($this->name);
  7169. }
  7170. return false;
  7171. }
  7172. }
  7173. class SimplePie_Misc
  7174. {
  7175. function time_hms($seconds)
  7176. {
  7177. $time = '';
  7178. $hours = floor($seconds / 3600);
  7179. $remainder = $seconds % 3600;
  7180. if ($hours > 0)
  7181. {
  7182. $time .= $hours.':';
  7183. }
  7184. $minutes = floor($remainder / 60);
  7185. $seconds = $remainder % 60;
  7186. if ($minutes < 10 && $hours > 0)
  7187. {
  7188. $minutes = '0' . $minutes;
  7189. }
  7190. if ($seconds < 10)
  7191. {
  7192. $seconds = '0' . $seconds;
  7193. }
  7194. $time .= $minutes.':';
  7195. $time .= $seconds;
  7196. return $time;
  7197. }
  7198. function absolutize_url($relative, $base)
  7199. {
  7200. if ($relative !== '')
  7201. {
  7202. $relative = SimplePie_Misc::parse_url($relative);
  7203. if ($relative['scheme'] !== '')
  7204. {
  7205. $target = $relative;
  7206. }
  7207. elseif ($base !== '')
  7208. {
  7209. $base = SimplePie_Misc::parse_url($base);
  7210. $target = SimplePie_Misc::parse_url('');
  7211. if ($relative['authority'] !== '')
  7212. {
  7213. $target = $relative;
  7214. $target['scheme'] = $base['scheme'];
  7215. }
  7216. else
  7217. {
  7218. $target['scheme'] = $base['scheme'];
  7219. $target['authority'] = $base['authority'];
  7220. if ($relative['path'] !== '')
  7221. {
  7222. if (strpos($relative['path'], '/') === 0)
  7223. {
  7224. $target['path'] = $relative['path'];
  7225. }
  7226. elseif ($base['authority'] !== '' && $base['path'] === '')
  7227. {
  7228. $target['path'] = '/' . $relative['path'];
  7229. }
  7230. elseif (($last_segment = strrpos($base['path'], '/')) !== false)
  7231. {
  7232. $target['path'] = substr($base['path'], 0, $last_segment + 1) . $relative['path'];
  7233. }
  7234. else
  7235. {
  7236. $target['path'] = $relative['path'];
  7237. }
  7238. $target['query'] = $relative['query'];
  7239. }
  7240. else
  7241. {
  7242. $target['path'] = $base['path'];
  7243. if ($relative['query'] !== '')
  7244. {
  7245. $target['query'] = $relative['query'];
  7246. }
  7247. elseif ($base['query'] !== '')
  7248. {
  7249. $target['query'] = $base['query'];
  7250. }
  7251. }
  7252. }
  7253. $target['fragment'] = $relative['fragment'];
  7254. }
  7255. else
  7256. {
  7257. // No base URL, just return the relative URL
  7258. $target = $relative;
  7259. }
  7260. $return = SimplePie_Misc::compress_parse_url($target['scheme'], $target['authority'], $target['path'], $target['query'], $target['fragment']);
  7261. }
  7262. else
  7263. {
  7264. $return = $base;
  7265. }
  7266. $return = SimplePie_Misc::normalize_url($return);
  7267. return $return;
  7268. }
  7269. function remove_dot_segments($input)
  7270. {
  7271. $output = '';
  7272. while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input == '.' || $input == '..')
  7273. {
  7274. // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
  7275. if (strpos($input, '../') === 0)
  7276. {
  7277. $input = substr($input, 3);
  7278. }
  7279. elseif (strpos($input, './') === 0)
  7280. {
  7281. $input = substr($input, 2);
  7282. }
  7283. // B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
  7284. elseif (strpos($input, '/./') === 0)
  7285. {
  7286. $input = substr_replace($input, '/', 0, 3);
  7287. }
  7288. elseif ($input == '/.')
  7289. {
  7290. $input = '/';
  7291. }
  7292. // C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
  7293. elseif (strpos($input, '/../') === 0)
  7294. {
  7295. $input = substr_replace($input, '/', 0, 4);
  7296. $output = substr_replace($output, '', strrpos($output, '/'));
  7297. }
  7298. elseif ($input == '/..')
  7299. {
  7300. $input = '/';
  7301. $output = substr_replace($output, '', strrpos($output, '/'));
  7302. }
  7303. // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
  7304. elseif ($input == '.' || $input == '..')
  7305. {
  7306. $input = '';
  7307. }
  7308. // E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
  7309. elseif (($pos = strpos($input, '/', 1)) !== false)
  7310. {
  7311. $output .= substr($input, 0, $pos);
  7312. $input = substr_replace($input, '', 0, $pos);
  7313. }
  7314. else
  7315. {
  7316. $output .= $input;
  7317. $input = '';
  7318. }
  7319. }
  7320. return $output . $input;
  7321. }
  7322. function get_element($realname, $string)
  7323. {
  7324. $return = array();
  7325. $name = preg_quote($realname, '/');
  7326. if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
  7327. {
  7328. for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
  7329. {
  7330. $return[$i]['tag'] = $realname;
  7331. $return[$i]['full'] = $matches[$i][0][0];
  7332. $return[$i]['offset'] = $matches[$i][0][1];
  7333. if (strlen($matches[$i][3][0]) <= 2)
  7334. {
  7335. $return[$i]['self_closing'] = true;
  7336. }
  7337. else
  7338. {
  7339. $return[$i]['self_closing'] = false;
  7340. $return[$i]['content'] = $matches[$i][4][0];
  7341. }
  7342. $return[$i]['attribs'] = array();
  7343. 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))
  7344. {
  7345. for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
  7346. {
  7347. if (count($attribs[$j]) == 2)
  7348. {
  7349. $attribs[$j][2] = $attribs[$j][1];
  7350. }
  7351. $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
  7352. }
  7353. }
  7354. }
  7355. }
  7356. return $return;
  7357. }
  7358. function element_implode($element)
  7359. {
  7360. $full = "<$element[tag]";
  7361. foreach ($element['attribs'] as $key => $value)
  7362. {
  7363. $key = strtolower($key);
  7364. $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
  7365. }
  7366. if ($element['self_closing'])
  7367. {
  7368. $full .= ' />';
  7369. }
  7370. else
  7371. {
  7372. $full .= ">$element[content]</$element[tag]>";
  7373. }
  7374. return $full;
  7375. }
  7376. function error($message, $level, $file, $line)
  7377. {
  7378. switch ($level)
  7379. {
  7380. case E_USER_ERROR:
  7381. $note = 'PHP Error';
  7382. break;
  7383. case E_USER_WARNING:
  7384. $note = 'PHP Warning';
  7385. break;
  7386. case E_USER_NOTICE:
  7387. $note = 'PHP Notice';
  7388. break;
  7389. default:
  7390. $note = 'Unknown Error';
  7391. break;
  7392. }
  7393. error_log("$note: $message in $file on line $line", 0);
  7394. return $message;
  7395. }
  7396. /**
  7397. * If a file has been cached, retrieve and display it.
  7398. *
  7399. * This is most useful for caching images (get_favicon(), etc.),
  7400. * however it works for all cached files. This WILL NOT display ANY
  7401. * file/image/page/whatever, but rather only display what has already
  7402. * been cached by SimplePie.
  7403. *
  7404. * @access public
  7405. * @see SimplePie::get_favicon()
  7406. * @param str $identifier_url URL that is used to identify the content.
  7407. * This may or may not be the actual URL of the live content.
  7408. * @param str $cache_location Location of SimplePie's cache. Defaults
  7409. * to './cache'.
  7410. * @param str $cache_extension The file extension that the file was
  7411. * cached with. Defaults to 'spc'.
  7412. * @param str $cache_class Name of the cache-handling class being used
  7413. * in SimplePie. Defaults to 'SimplePie_Cache', and should be left
  7414. * as-is unless you've overloaded the class.
  7415. * @param str $cache_name_function Obsolete. Exists for backwards
  7416. * compatibility reasons only.
  7417. */
  7418. function display_cached_file($identifier_url, $cache_location = './cache', $cache_extension = 'spc', $cache_class = 'SimplePie_Cache', $cache_name_function = 'md5')
  7419. {
  7420. $cache = call_user_func(array($cache_class, 'create'), $cache_location, $identifier_url, $cache_extension);
  7421. if ($file = $cache->load())
  7422. {
  7423. if (isset($file['headers']['content-type']))
  7424. {
  7425. header('Content-type:' . $file['headers']['content-type']);
  7426. }
  7427. else
  7428. {
  7429. header('Content-type: application/octet-stream');
  7430. }
  7431. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  7432. echo $file['body'];
  7433. exit;
  7434. }
  7435. die('Cached file for ' . $identifier_url . ' cannot be found.');
  7436. }
  7437. function fix_protocol($url, $http = 1)
  7438. {
  7439. $url = SimplePie_Misc::normalize_url($url);
  7440. $parsed = SimplePie_Misc::parse_url($url);
  7441. if ($parsed['scheme'] !== '' && $parsed['scheme'] != 'http' && $parsed['scheme'] != 'https')
  7442. {
  7443. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
  7444. }
  7445. if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
  7446. {
  7447. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
  7448. }
  7449. if ($http == 2 && $parsed['scheme'] !== '')
  7450. {
  7451. return "feed:$url";
  7452. }
  7453. elseif ($http == 3 && strtolower($parsed['scheme']) == 'http')
  7454. {
  7455. return substr_replace($url, 'podcast', 0, 4);
  7456. }
  7457. elseif ($http == 4 && strtolower($parsed['scheme']) == 'http')
  7458. {
  7459. return substr_replace($url, 'itpc', 0, 4);
  7460. }
  7461. else
  7462. {
  7463. return $url;
  7464. }
  7465. }
  7466. function parse_url($url)
  7467. {
  7468. static $cache = array();
  7469. if (isset($cache[$url]))
  7470. {
  7471. return $cache[$url];
  7472. }
  7473. elseif (preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $url, $match))
  7474. {
  7475. for ($i = count($match); $i <= 9; $i++)
  7476. {
  7477. $match[$i] = '';
  7478. }
  7479. return $cache[$url] = array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]);
  7480. }
  7481. else
  7482. {
  7483. return $cache[$url] = array('scheme' => '', 'authority' => '', 'path' => '', 'query' => '', 'fragment' => '');
  7484. }
  7485. }
  7486. function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
  7487. {
  7488. $return = '';
  7489. if ($scheme !== '')
  7490. {
  7491. $return .= "$scheme:";
  7492. }
  7493. if ($authority !== '')
  7494. {
  7495. $return .= "//$authority";
  7496. }
  7497. if ($path !== '')
  7498. {
  7499. $return .= $path;
  7500. }
  7501. if ($query !== '')
  7502. {
  7503. $return .= "?$query";
  7504. }
  7505. if ($fragment !== '')
  7506. {
  7507. $return .= "#$fragment";
  7508. }
  7509. return $return;
  7510. }
  7511. function normalize_url($url)
  7512. {
  7513. $url = preg_replace_callback('/%([0-9A-Fa-f]{2})/', array('SimplePie_Misc', 'percent_encoding_normalization'), $url);
  7514. $url = SimplePie_Misc::parse_url($url);
  7515. $url['scheme'] = strtolower($url['scheme']);
  7516. if ($url['authority'] !== '')
  7517. {
  7518. $url['authority'] = strtolower($url['authority']);
  7519. $url['path'] = SimplePie_Misc::remove_dot_segments($url['path']);
  7520. }
  7521. return SimplePie_Misc::compress_parse_url($url['scheme'], $url['authority'], $url['path'], $url['query'], $url['fragment']);
  7522. }
  7523. function percent_encoding_normalization($match)
  7524. {
  7525. $integer = hexdec($match[1]);
  7526. if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer == 0x2D || $integer == 0x2E || $integer == 0x5F || $integer == 0x7E)
  7527. {
  7528. return chr($integer);
  7529. }
  7530. else
  7531. {
  7532. return strtoupper($match[0]);
  7533. }
  7534. }
  7535. /**
  7536. * Remove bad UTF-8 bytes
  7537. *
  7538. * PCRE Pattern to locate bad bytes in a UTF-8 string comes from W3C
  7539. * FAQ: Multilingual Forms (modified to include full ASCII range)
  7540. *
  7541. * @author Geoffrey Sneddon
  7542. * @see http://www.w3.org/International/questions/qa-forms-utf-8
  7543. * @param string $str String to remove bad UTF-8 bytes from
  7544. * @return string UTF-8 string
  7545. */
  7546. function utf8_bad_replace($str)
  7547. {
  7548. if (function_exists('iconv') && ($return = @iconv('UTF-8', 'UTF-8//IGNORE', $str)))
  7549. {
  7550. return $return;
  7551. }
  7552. elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($str, 'UTF-8', 'UTF-8')))
  7553. {
  7554. return $return;
  7555. }
  7556. elseif (preg_match_all('/(?:[\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})+/', $str, $matches))
  7557. {
  7558. return implode("\xEF\xBF\xBD", $matches[0]);
  7559. }
  7560. elseif ($str !== '')
  7561. {
  7562. return "\xEF\xBF\xBD";
  7563. }
  7564. else
  7565. {
  7566. return '';
  7567. }
  7568. }
  7569. /**
  7570. * Converts a Windows-1252 encoded string to a UTF-8 encoded string
  7571. *
  7572. * @static
  7573. * @access public
  7574. * @param string $string Windows-1252 encoded string
  7575. * @return string UTF-8 encoded string
  7576. */
  7577. function windows_1252_to_utf8($string)
  7578. {
  7579. 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");
  7580. return strtr($string, $convert_table);
  7581. }
  7582. function change_encoding($data, $input, $output)
  7583. {
  7584. $input = SimplePie_Misc::encoding($input);
  7585. $output = SimplePie_Misc::encoding($output);
  7586. // We fail to fail on non US-ASCII bytes
  7587. if ($input === 'US-ASCII')
  7588. {
  7589. static $non_ascii_octects = '';
  7590. if (!$non_ascii_octects)
  7591. {
  7592. for ($i = 0x80; $i <= 0xFF; $i++)
  7593. {
  7594. $non_ascii_octects .= chr($i);
  7595. }
  7596. }
  7597. $data = substr($data, 0, strcspn($data, $non_ascii_octects));
  7598. }
  7599. // This is first, as behaviour of this is completely predictable
  7600. if ($input === 'Windows-1252' && $output === 'UTF-8')
  7601. {
  7602. return SimplePie_Misc::windows_1252_to_utf8($data);
  7603. }
  7604. // This is second, as behaviour of this varies only with PHP version
  7605. elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($data, $output, $input)))
  7606. {
  7607. return $return;
  7608. }
  7609. // This is last, as behaviour of this varies with OS userland and PHP version
  7610. elseif (function_exists('iconv') && ($return = @iconv($input, $output, $data)))
  7611. {
  7612. return $return;
  7613. }
  7614. // If we can't do anything, just fail
  7615. else
  7616. {
  7617. return false;
  7618. }
  7619. }
  7620. function encoding($charset)
  7621. {
  7622. /* Character sets are case-insensitive, and also need some further
  7623. normalization in the real world (though we'll return them in the form given
  7624. in their registration). */
  7625. switch (strtolower(preg_replace('/[\x09-\x0D\x20-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]/', '', $charset)))
  7626. {
  7627. case 'adobestandardencoding':
  7628. case 'csadobestandardencoding':
  7629. return 'Adobe-Standard-Encoding';
  7630. case 'adobesymbolencoding':
  7631. case 'cshppsmath':
  7632. return 'Adobe-Symbol-Encoding';
  7633. case 'ami1251':
  7634. case 'ami1251':
  7635. case 'amiga1251':
  7636. case 'amiga1251':
  7637. return 'Amiga-1251';
  7638. case 'ansix31101983':
  7639. case 'csat5001983':
  7640. case 'csiso99naplps':
  7641. case 'isoir99':
  7642. case 'naplps':
  7643. return 'ANSI_X3.110-1983';
  7644. case 'arabic7':
  7645. case 'asmo449':
  7646. case 'csiso89asmo449':
  7647. case 'isoir89':
  7648. case 'iso9036':
  7649. return 'ASMO_449';
  7650. case 'big5':
  7651. case 'csbig5':
  7652. case 'xxbig5':
  7653. return 'Big5';
  7654. case 'big5hkscs':
  7655. return 'Big5-HKSCS';
  7656. case 'bocu1':
  7657. case 'csbocu1':
  7658. return 'BOCU-1';
  7659. case 'brf':
  7660. case 'csbrf':
  7661. return 'BRF';
  7662. case 'bs4730':
  7663. case 'csiso4unitedkingdom':
  7664. case 'gb':
  7665. case 'isoir4':
  7666. case 'iso646gb':
  7667. case 'uk':
  7668. return 'BS_4730';
  7669. case 'bsviewdata':
  7670. case 'csiso47bsviewdata':
  7671. case 'isoir47':
  7672. return 'BS_viewdata';
  7673. case 'cesu8':
  7674. case 'cscesu8':
  7675. return 'CESU-8';
  7676. case 'ca':
  7677. case 'csa71':
  7678. case 'csaz243419851':
  7679. case 'csiso121canadian1':
  7680. case 'isoir121':
  7681. case 'iso646ca':
  7682. return 'CSA_Z243.4-1985-1';
  7683. case 'csa72':
  7684. case 'csaz243419852':
  7685. case 'csiso122canadian2':
  7686. case 'isoir122':
  7687. case 'iso646ca2':
  7688. return 'CSA_Z243.4-1985-2';
  7689. case 'csaz24341985gr':
  7690. case 'csiso123csaz24341985gr':
  7691. case 'isoir123':
  7692. return 'CSA_Z243.4-1985-gr';
  7693. case 'csiso139csn369103':
  7694. case 'csn369103':
  7695. case 'isoir139':
  7696. return 'CSN_369103';
  7697. case 'csdecmcs':
  7698. case 'dec':
  7699. case 'decmcs':
  7700. return 'DEC-MCS';
  7701. case 'csiso21german':
  7702. case 'de':
  7703. case 'din66003':
  7704. case 'isoir21':
  7705. case 'iso646de':
  7706. return 'DIN_66003';
  7707. case 'csdkus':
  7708. case 'dkus':
  7709. return 'dk-us';
  7710. case 'csiso646danish':
  7711. case 'dk':
  7712. case 'ds2089':
  7713. case 'ds2089':
  7714. case 'iso646dk':
  7715. return 'DS_2089';
  7716. case 'csibmebcdicatde':
  7717. case 'ebcdicatde':
  7718. return 'EBCDIC-AT-DE';
  7719. case 'csebcdicatdea':
  7720. case 'ebcdicatdea':
  7721. return 'EBCDIC-AT-DE-A';
  7722. case 'csebcdiccafr':
  7723. case 'ebcdiccafr':
  7724. return 'EBCDIC-CA-FR';
  7725. case 'csebcdicdkno':
  7726. case 'ebcdicdkno':
  7727. return 'EBCDIC-DK-NO';
  7728. case 'csebcdicdknoa':
  7729. case 'ebcdicdknoa':
  7730. return 'EBCDIC-DK-NO-A';
  7731. case 'csebcdices':
  7732. case 'ebcdices':
  7733. return 'EBCDIC-ES';
  7734. case 'csebcdicesa':
  7735. case 'ebcdicesa':
  7736. return 'EBCDIC-ES-A';
  7737. case 'csebcdicess':
  7738. case 'ebcdicess':
  7739. return 'EBCDIC-ES-S';
  7740. case 'csebcdicfise':
  7741. case 'ebcdicfise':
  7742. return 'EBCDIC-FI-SE';
  7743. case 'csebcdicfisea':
  7744. case 'ebcdicfisea':
  7745. return 'EBCDIC-FI-SE-A';
  7746. case 'csebcdicfr':
  7747. case 'ebcdicfr':
  7748. return 'EBCDIC-FR';
  7749. case 'csebcdicit':
  7750. case 'ebcdicit':
  7751. return 'EBCDIC-IT';
  7752. case 'csebcdicpt':
  7753. case 'ebcdicpt':
  7754. return 'EBCDIC-PT';
  7755. case 'csebcdicuk':
  7756. case 'ebcdicuk':
  7757. return 'EBCDIC-UK';
  7758. case 'csebcdicus':
  7759. case 'ebcdicus':
  7760. return 'EBCDIC-US';
  7761. case 'csiso111ecmacyrillic':
  7762. case 'ecmacyrillic':
  7763. case 'isoir111':
  7764. case 'koi8e':
  7765. return 'ECMA-cyrillic';
  7766. case 'csiso17spanish':
  7767. case 'es':
  7768. case 'isoir17':
  7769. case 'iso646es':
  7770. return 'ES';
  7771. case 'csiso85spanish2':
  7772. case 'es2':
  7773. case 'isoir85':
  7774. case 'iso646es2':
  7775. return 'ES2';
  7776. case 'cseucfixwidjapanese':
  7777. case 'extendedunixcodefixedwidthforjapanese':
  7778. return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
  7779. case 'cseucpkdfmtjapanese':
  7780. case 'eucjp':
  7781. case 'extendedunixcodepackedformatforjapanese':
  7782. return 'Extended_UNIX_Code_Packed_Format_for_Japanese';
  7783. case 'gb18030':
  7784. return 'GB18030';
  7785. case 'cp936':
  7786. case 'gbk':
  7787. case 'ms936':
  7788. case 'windows936':
  7789. case 'csgb2312':
  7790. case 'gb2312':
  7791. case 'chinese':
  7792. case 'csiso58gb231280':
  7793. case 'gb231280':
  7794. case 'isoir58':
  7795. return 'GBK';
  7796. case 'cn':
  7797. case 'csiso57gb1988':
  7798. case 'gb198880':
  7799. case 'isoir57':
  7800. case 'iso646cn':
  7801. return 'GB_1988-80';
  7802. case 'csiso153gost1976874':
  7803. case 'gost1976874':
  7804. case 'isoir153':
  7805. case 'stsev35888':
  7806. return 'GOST_19768-74';
  7807. case 'csiso150':
  7808. case 'csiso150greekccitt':
  7809. case 'greekccitt':
  7810. case 'isoir150':
  7811. return 'greek-ccitt';
  7812. case 'csiso88greek7':
  7813. case 'greek7':
  7814. case 'isoir88':
  7815. return 'greek7';
  7816. case 'csiso18greek7old':
  7817. case 'greek7old':
  7818. case 'isoir18':
  7819. return 'greek7-old';
  7820. case 'cshpdesktop':
  7821. case 'hpdesktop':
  7822. return 'HP-DeskTop';
  7823. case 'cshplegal':
  7824. case 'hplegal':
  7825. return 'HP-Legal';
  7826. case 'cshpmath8':
  7827. case 'hpmath8':
  7828. return 'HP-Math8';
  7829. case 'cshppifont':
  7830. case 'hppifont':
  7831. return 'HP-Pi-font';
  7832. case 'cshproman8':
  7833. case 'hproman8':
  7834. case 'r8':
  7835. case 'roman8':
  7836. return 'hp-roman8';
  7837. case 'hzgb2312':
  7838. return 'HZ-GB-2312';
  7839. case 'csibmsymbols':
  7840. case 'ibmsymbols':
  7841. return 'IBM-Symbols';
  7842. case 'csibmthai':
  7843. case 'ibmthai':
  7844. return 'IBM-Thai';
  7845. case 'ccsid00858':
  7846. case 'cp00858':
  7847. case 'ibm00858':
  7848. case 'pcmultilingual850euro':
  7849. return 'IBM00858';
  7850. case 'ccsid00924':
  7851. case 'cp00924':
  7852. case 'ebcdiclatin9euro':
  7853. case 'ibm00924':
  7854. return 'IBM00924';
  7855. case 'ccsid01140':
  7856. case 'cp01140':
  7857. case 'ebcdicus37euro':
  7858. case 'ibm01140':
  7859. return 'IBM01140';
  7860. case 'ccsid01141':
  7861. case 'cp01141':
  7862. case 'ebcdicde273euro':
  7863. case 'ibm01141':
  7864. return 'IBM01141';
  7865. case 'ccsid01142':
  7866. case 'cp01142':
  7867. case 'ebcdicdk277euro':
  7868. case 'ebcdicno277euro':
  7869. case 'ibm01142':
  7870. return 'IBM01142';
  7871. case 'ccsid01143':
  7872. case 'cp01143':
  7873. case 'ebcdicfi278euro':
  7874. case 'ebcdicse278euro':
  7875. case 'ibm01143':
  7876. return 'IBM01143';
  7877. case 'ccsid01144':
  7878. case 'cp01144':
  7879. case 'ebcdicit280euro':
  7880. case 'ibm01144':
  7881. return 'IBM01144';
  7882. case 'ccsid01145':
  7883. case 'cp01145':
  7884. case 'ebcdices284euro':
  7885. case 'ibm01145':
  7886. return 'IBM01145';
  7887. case 'ccsid01146':
  7888. case 'cp01146':
  7889. case 'ebcdicgb285euro':
  7890. case 'ibm01146':
  7891. return 'IBM01146';
  7892. case 'ccsid01147':
  7893. case 'cp01147':
  7894. case 'ebcdicfr297euro':
  7895. case 'ibm01147':
  7896. return 'IBM01147';
  7897. case 'ccsid01148':
  7898. case 'cp01148':
  7899. case 'ebcdicinternational500euro':
  7900. case 'ibm01148':
  7901. return 'IBM01148';
  7902. case 'ccsid01149':
  7903. case 'cp01149':
  7904. case 'ebcdicis871euro':
  7905. case 'ibm01149':
  7906. return 'IBM01149';
  7907. case 'cp037':
  7908. case 'csibm037':
  7909. case 'ebcdiccpca':
  7910. case 'ebcdiccpnl':
  7911. case 'ebcdiccpus':
  7912. case 'ebcdiccpwt':
  7913. case 'ibm037':
  7914. return 'IBM037';
  7915. case 'cp038':
  7916. case 'csibm038':
  7917. case 'ebcdicint':
  7918. case 'ibm038':
  7919. return 'IBM038';
  7920. case 'cp273':
  7921. case 'csibm273':
  7922. case 'ibm273':
  7923. return 'IBM273';
  7924. case 'cp274':
  7925. case 'csibm274':
  7926. case 'ebcdicbe':
  7927. case 'ibm274':
  7928. return 'IBM274';
  7929. case 'cp275':
  7930. case 'csibm275':
  7931. case 'ebcdicbr':
  7932. case 'ibm275':
  7933. return 'IBM275';
  7934. case 'csibm277':
  7935. case 'ebcdiccpdk':
  7936. case 'ebcdiccpno':
  7937. case 'ibm277':
  7938. return 'IBM277';
  7939. case 'cp278':
  7940. case 'csibm278':
  7941. case 'ebcdiccpfi':
  7942. case 'ebcdiccpse':
  7943. case 'ibm278':
  7944. return 'IBM278';
  7945. case 'cp280':
  7946. case 'csibm280':
  7947. case 'ebcdiccpit':
  7948. case 'ibm280':
  7949. return 'IBM280';
  7950. case 'cp281':
  7951. case 'csibm281':
  7952. case 'ebcdicjpe':
  7953. case 'ibm281':
  7954. return 'IBM281';
  7955. case 'cp284':
  7956. case 'csibm284':
  7957. case 'ebcdiccpes':
  7958. case 'ibm284':
  7959. return 'IBM284';
  7960. case 'cp285':
  7961. case 'csibm285':
  7962. case 'ebcdiccpgb':
  7963. case 'ibm285':
  7964. return 'IBM285';
  7965. case 'cp290':
  7966. case 'csibm290':
  7967. case 'ebcdicjpkana':
  7968. case 'ibm290':
  7969. return 'IBM290';
  7970. case 'cp297':
  7971. case 'csibm297':
  7972. case 'ebcdiccpfr':
  7973. case 'ibm297':
  7974. return 'IBM297';
  7975. case 'cp420':
  7976. case 'csibm420':
  7977. case 'ebcdiccpar1':
  7978. case 'ibm420':
  7979. return 'IBM420';
  7980. case 'cp423':
  7981. case 'csibm423':
  7982. case 'ebcdiccpgr':
  7983. case 'ibm423':
  7984. return 'IBM423';
  7985. case 'cp424':
  7986. case 'csibm424':
  7987. case 'ebcdiccphe':
  7988. case 'ibm424':
  7989. return 'IBM424';
  7990. case '437':
  7991. case 'cp437':
  7992. case 'cspc8codepage437':
  7993. case 'ibm437':
  7994. return 'IBM437';
  7995. case 'cp500':
  7996. case 'csibm500':
  7997. case 'ebcdiccpbe':
  7998. case 'ebcdiccpch':
  7999. case 'ibm500':
  8000. return 'IBM500';
  8001. case 'cp775':
  8002. case 'cspc775baltic':
  8003. case 'ibm775':
  8004. return 'IBM775';
  8005. case '850':
  8006. case 'cp850':
  8007. case 'cspc850multilingual':
  8008. case 'ibm850':
  8009. return 'IBM850';
  8010. case '851':
  8011. case 'cp851':
  8012. case 'csibm851':
  8013. case 'ibm851':
  8014. return 'IBM851';
  8015. case '852':
  8016. case 'cp852':
  8017. case 'cspcp852':
  8018. case 'ibm852':
  8019. return 'IBM852';
  8020. case '855':
  8021. case 'cp855':
  8022. case 'csibm855':
  8023. case 'ibm855':
  8024. return 'IBM855';
  8025. case '857':
  8026. case 'cp857':
  8027. case 'csibm857':
  8028. case 'ibm857':
  8029. return 'IBM857';
  8030. case '860':
  8031. case 'cp860':
  8032. case 'csibm860':
  8033. case 'ibm860':
  8034. return 'IBM860';
  8035. case '861':
  8036. case 'cpis':
  8037. case 'cp861':
  8038. case 'csibm861':
  8039. case 'ibm861':
  8040. return 'IBM861';
  8041. case '862':
  8042. case 'cp862':
  8043. case 'cspc862latinhebrew':
  8044. case 'ibm862':
  8045. return 'IBM862';
  8046. case '863':
  8047. case 'cp863':
  8048. case 'csibm863':
  8049. case 'ibm863':
  8050. return 'IBM863';
  8051. case 'cp864':
  8052. case 'csibm864':
  8053. case 'ibm864':
  8054. return 'IBM864';
  8055. case '865':
  8056. case 'cp865':
  8057. case 'csibm865':
  8058. case 'ibm865':
  8059. return 'IBM865';
  8060. case '866':
  8061. case 'cp866':
  8062. case 'csibm866':
  8063. case 'ibm866':
  8064. return 'IBM866';
  8065. case 'cpar':
  8066. case 'cp868':
  8067. case 'csibm868':
  8068. case 'ibm868':
  8069. return 'IBM868';
  8070. case '869':
  8071. case 'cpgr':
  8072. case 'cp869':
  8073. case 'csibm869':
  8074. case 'ibm869':
  8075. return 'IBM869';
  8076. case 'cp870':
  8077. case 'csibm870':
  8078. case 'ebcdiccproece':
  8079. case 'ebcdiccpyu':
  8080. case 'ibm870':
  8081. return 'IBM870';
  8082. case 'cp871':
  8083. case 'csibm871':
  8084. case 'ebcdiccpis':
  8085. case 'ibm871':
  8086. return 'IBM871';
  8087. case 'cp880':
  8088. case 'csibm880':
  8089. case 'ebcdiccyrillic':
  8090. case 'ibm880':
  8091. return 'IBM880';
  8092. case 'cp891':
  8093. case 'csibm891':
  8094. case 'ibm891':
  8095. return 'IBM891';
  8096. case 'cp903':
  8097. case 'csibm903':
  8098. case 'ibm903':
  8099. return 'IBM903';
  8100. case '904':
  8101. case 'cp904':
  8102. case 'csibbm904':
  8103. case 'ibm904':
  8104. return 'IBM904';
  8105. case 'cp905':
  8106. case 'csibm905':
  8107. case 'ebcdiccptr':
  8108. case 'ibm905':
  8109. return 'IBM905';
  8110. case 'cp918':
  8111. case 'csibm918':
  8112. case 'ebcdiccpar2':
  8113. case 'ibm918':
  8114. return 'IBM918';
  8115. case 'cp1026':
  8116. case 'csibm1026':
  8117. case 'ibm1026':
  8118. return 'IBM1026';
  8119. case 'ibm1047':
  8120. case 'ibm1047':
  8121. return 'IBM1047';
  8122. case 'csiso143iecp271':
  8123. case 'iecp271':
  8124. case 'isoir143':
  8125. return 'IEC_P27-1';
  8126. case 'csiso49inis':
  8127. case 'inis':
  8128. case 'isoir49':
  8129. return 'INIS';
  8130. case 'csiso50inis8':
  8131. case 'inis8':
  8132. case 'isoir50':
  8133. return 'INIS-8';
  8134. case 'csiso51iniscyrillic':
  8135. case 'iniscyrillic':
  8136. case 'isoir51':
  8137. return 'INIS-cyrillic';
  8138. case 'csinvariant':
  8139. case 'invariant':
  8140. return 'INVARIANT';
  8141. case 'iso2022cn':
  8142. return 'ISO-2022-CN';
  8143. case 'iso2022cnext':
  8144. return 'ISO-2022-CN-EXT';
  8145. case 'csiso2022jp':
  8146. case 'iso2022jp':
  8147. return 'ISO-2022-JP';
  8148. case 'csiso2022jp2':
  8149. case 'iso2022jp2':
  8150. return 'ISO-2022-JP-2';
  8151. case 'csiso2022kr':
  8152. case 'iso2022kr':
  8153. return 'ISO-2022-KR';
  8154. case 'cswindows30latin1':
  8155. case 'iso88591windows30latin1':
  8156. return 'ISO-8859-1-Windows-3.0-Latin-1';
  8157. case 'cswindows31latin1':
  8158. case 'iso88591windows31latin1':
  8159. return 'ISO-8859-1-Windows-3.1-Latin-1';
  8160. case 'csisolatin2':
  8161. case 'iso88592':
  8162. case 'isoir101':
  8163. case 'iso88592':
  8164. case 'iso885921987':
  8165. case 'l2':
  8166. case 'latin2':
  8167. return 'ISO-8859-2';
  8168. case 'cswindows31latin2':
  8169. case 'iso88592windowslatin2':
  8170. return 'ISO-8859-2-Windows-Latin-2';
  8171. case 'csisolatin3':
  8172. case 'iso88593':
  8173. case 'isoir109':
  8174. case 'iso88593':
  8175. case 'iso885931988':
  8176. case 'l3':
  8177. case 'latin3':
  8178. return 'ISO-8859-3';
  8179. case 'csisolatin4':
  8180. case 'iso88594':
  8181. case 'isoir110':
  8182. case 'iso88594':
  8183. case 'iso885941988':
  8184. case 'l4':
  8185. case 'latin4':
  8186. return 'ISO-8859-4';
  8187. case 'csisolatincyrillic':
  8188. case 'cyrillic':
  8189. case 'iso88595':
  8190. case 'isoir144':
  8191. case 'iso88595':
  8192. case 'iso885951988':
  8193. return 'ISO-8859-5';
  8194. case 'arabic':
  8195. case 'asmo708':
  8196. case 'csisolatinarabic':
  8197. case 'ecma114':
  8198. case 'iso88596':
  8199. case 'isoir127':
  8200. case 'iso88596':
  8201. case 'iso885961987':
  8202. return 'ISO-8859-6';
  8203. case 'csiso88596e':
  8204. case 'iso88596e':
  8205. case 'iso88596e':
  8206. return 'ISO-8859-6-E';
  8207. case 'csiso88596i':
  8208. case 'iso88596i':
  8209. case 'iso88596i':
  8210. return 'ISO-8859-6-I';
  8211. case 'csisolatingreek':
  8212. case 'ecma118':
  8213. case 'elot928':
  8214. case 'greek':
  8215. case 'greek8':
  8216. case 'iso88597':
  8217. case 'isoir126':
  8218. case 'iso88597':
  8219. case 'iso885971987':
  8220. return 'ISO-8859-7';
  8221. case 'csisolatinhebrew':
  8222. case 'hebrew':
  8223. case 'iso88598':
  8224. case 'isoir138':
  8225. case 'iso88598':
  8226. case 'iso885981988':
  8227. return 'ISO-8859-8';
  8228. case 'csiso88598e':
  8229. case 'iso88598e':
  8230. case 'iso88598e':
  8231. return 'ISO-8859-8-E';
  8232. case 'csiso88598i':
  8233. case 'iso88598i':
  8234. case 'iso88598i':
  8235. return 'ISO-8859-8-I';
  8236. case 'cswindows31latin5':
  8237. case 'iso88599windowslatin5':
  8238. return 'ISO-8859-9-Windows-Latin-5';
  8239. case 'csisolatin6':
  8240. case 'iso885910':
  8241. case 'isoir157':
  8242. case 'iso8859101992':
  8243. case 'l6':
  8244. case 'latin6':
  8245. return 'ISO-8859-10';
  8246. case 'iso885913':
  8247. return 'ISO-8859-13';
  8248. case 'iso885914':
  8249. case 'isoceltic':
  8250. case 'isoir199':
  8251. case 'iso885914':
  8252. case 'iso8859141998':
  8253. case 'l8':
  8254. case 'latin8':
  8255. return 'ISO-8859-14';
  8256. case 'iso885915':
  8257. case 'iso885915':
  8258. case 'latin9':
  8259. return 'ISO-8859-15';
  8260. case 'iso885916':
  8261. case 'isoir226':
  8262. case 'iso885916':
  8263. case 'iso8859162001':
  8264. case 'l10':
  8265. case 'latin10':
  8266. return 'ISO-8859-16';
  8267. case 'iso10646j1':
  8268. return 'ISO-10646-J-1';
  8269. case 'csunicode':
  8270. case 'iso10646ucs2':
  8271. return 'ISO-10646-UCS-2';
  8272. case 'csucs4':
  8273. case 'iso10646ucs4':
  8274. return 'ISO-10646-UCS-4';
  8275. case 'csunicodeascii':
  8276. case 'iso10646ucsbasic':
  8277. return 'ISO-10646-UCS-Basic';
  8278. case 'csunicodelatin1':
  8279. case 'iso10646':
  8280. case 'iso10646unicodelatin1':
  8281. return 'ISO-10646-Unicode-Latin1';
  8282. case 'csiso10646utf1':
  8283. case 'iso10646utf1':
  8284. return 'ISO-10646-UTF-1';
  8285. case 'csiso115481':
  8286. case 'iso115481':
  8287. case 'iso115481':
  8288. case 'isotr115481':
  8289. return 'ISO-11548-1';
  8290. case 'csiso90':
  8291. case 'isoir90':
  8292. return 'iso-ir-90';
  8293. case 'csunicodeibm1261':
  8294. case 'isounicodeibm1261':
  8295. return 'ISO-Unicode-IBM-1261';
  8296. case 'csunicodeibm1264':
  8297. case 'isounicodeibm1264':
  8298. return 'ISO-Unicode-IBM-1264';
  8299. case 'csunicodeibm1265':
  8300. case 'isounicodeibm1265':
  8301. return 'ISO-Unicode-IBM-1265';
  8302. case 'csunicodeibm1268':
  8303. case 'isounicodeibm1268':
  8304. return 'ISO-Unicode-IBM-1268';
  8305. case 'csunicodeibm1276':
  8306. case 'isounicodeibm1276':
  8307. return 'ISO-Unicode-IBM-1276';
  8308. case 'csiso646basic1983':
  8309. case 'iso646basic1983':
  8310. case 'ref':
  8311. return 'ISO_646.basic:1983';
  8312. case 'csiso2intlrefversion':
  8313. case 'irv':
  8314. case 'isoir2':
  8315. case 'iso646irv1983':
  8316. return 'ISO_646.irv:1983';
  8317. case 'csiso2033':
  8318. case 'e13b':
  8319. case 'isoir98':
  8320. case 'iso20331983':
  8321. return 'ISO_2033-1983';
  8322. case 'csiso5427cyrillic':
  8323. case 'isoir37':
  8324. case 'iso5427':
  8325. return 'ISO_5427';
  8326. case 'isoir54':
  8327. case 'iso5427cyrillic1981':
  8328. case 'iso54271981':
  8329. return 'ISO_5427:1981';
  8330. case 'csiso5428greek':
  8331. case 'isoir55':
  8332. case 'iso54281980':
  8333. return 'ISO_5428:1980';
  8334. case 'csiso6937add':
  8335. case 'isoir152':
  8336. case 'iso6937225':
  8337. return 'ISO_6937-2-25';
  8338. case 'csisotextcomm':
  8339. case 'isoir142':
  8340. case 'iso69372add':
  8341. return 'ISO_6937-2-add';
  8342. case 'csiso8859supp':
  8343. case 'isoir154':
  8344. case 'iso8859supp':
  8345. case 'latin125':
  8346. return 'ISO_8859-supp';
  8347. case 'csiso10367box':
  8348. case 'isoir155':
  8349. case 'iso10367box':
  8350. return 'ISO_10367-box';
  8351. case 'csiso15italian':
  8352. case 'isoir15':
  8353. case 'iso646it':
  8354. case 'it':
  8355. return 'IT';
  8356. case 'csiso13jisc6220jp':
  8357. case 'isoir13':
  8358. case 'jisc62201969':
  8359. case 'jisc62201969jp':
  8360. case 'katakana':
  8361. case 'x02017':
  8362. return 'JIS_C6220-1969-jp';
  8363. case 'csiso14jisc6220ro':
  8364. case 'isoir14':
  8365. case 'iso646jp':
  8366. case 'jisc62201969ro':
  8367. case 'jp':
  8368. return 'JIS_C6220-1969-ro';
  8369. case 'csiso42jisc62261978':
  8370. case 'isoir42':
  8371. case 'jisc62261978':
  8372. return 'JIS_C6226-1978';
  8373. case 'csiso87jisx0208':
  8374. case 'isoir87':
  8375. case 'jisc62261983':
  8376. case 'jisx02081983':
  8377. case 'x0208':
  8378. return 'JIS_C6226-1983';
  8379. case 'csiso91jisc62291984a':
  8380. case 'isoir91':
  8381. case 'jisc62291984a':
  8382. case 'jpocra':
  8383. return 'JIS_C6229-1984-a';
  8384. case 'csiso92jisc62991984b':
  8385. case 'isoir92':
  8386. case 'iso646jpocrb':
  8387. case 'jisc62291984b':
  8388. case 'jpocrb':
  8389. return 'JIS_C6229-1984-b';
  8390. case 'csiso93jis62291984badd':
  8391. case 'isoir93':
  8392. case 'jisc62291984badd':
  8393. case 'jpocrbadd':
  8394. return 'JIS_C6229-1984-b-add';
  8395. case 'csiso94jis62291984hand':
  8396. case 'isoir94':
  8397. case 'jisc62291984hand':
  8398. case 'jpocrhand':
  8399. return 'JIS_C6229-1984-hand';
  8400. case 'csiso95jis62291984handadd':
  8401. case 'isoir95':
  8402. case 'jisc62291984handadd':
  8403. case 'jpocrhandadd':
  8404. return 'JIS_C6229-1984-hand-add';
  8405. case 'csiso96jisc62291984kana':
  8406. case 'isoir96':
  8407. case 'jisc62291984kana':
  8408. return 'JIS_C6229-1984-kana';
  8409. case 'csjisencoding':
  8410. case 'jisencoding':
  8411. return 'JIS_Encoding';
  8412. case 'cshalfwidthkatakana':
  8413. case 'jisx0201':
  8414. case 'x0201':
  8415. return 'JIS_X0201';
  8416. case 'csiso159jisx02121990':
  8417. case 'isoir159':
  8418. case 'jisx02121990':
  8419. case 'x0212':
  8420. return 'JIS_X0212-1990';
  8421. case 'csiso141jusib1002':
  8422. case 'isoir141':
  8423. case 'iso646yu':
  8424. case 'js':
  8425. case 'jusib1002':
  8426. case 'yu':
  8427. return 'JUS_I.B1.002';
  8428. case 'csiso147macedonian':
  8429. case 'isoir147':
  8430. case 'jusib1003mac':
  8431. case 'macedonian':
  8432. return 'JUS_I.B1.003-mac';
  8433. case 'csiso146serbian':
  8434. case 'isoir146':
  8435. case 'jusib1003serb':
  8436. case 'serbian':
  8437. return 'JUS_I.B1.003-serb';
  8438. case 'koi7switched':
  8439. return 'KOI7-switched';
  8440. case 'cskoi8r':
  8441. case 'koi8r':
  8442. return 'KOI8-R';
  8443. case 'koi8u':
  8444. return 'KOI8-U';
  8445. case 'csksc5636':
  8446. case 'iso646kr':
  8447. case 'ksc5636':
  8448. return 'KSC5636';
  8449. case 'cskz1048':
  8450. case 'kz1048':
  8451. case 'rk1048':
  8452. case 'strk10482002':
  8453. return 'KZ-1048';
  8454. case 'csiso19latingreek':
  8455. case 'isoir19':
  8456. case 'latingreek':
  8457. return 'latin-greek';
  8458. case 'csiso27latingreek1':
  8459. case 'isoir27':
  8460. case 'latingreek1':
  8461. return 'Latin-greek-1';
  8462. case 'csiso158lap':
  8463. case 'isoir158':
  8464. case 'lap':
  8465. case 'latinlap':
  8466. return 'latin-lap';
  8467. case 'csmacintosh':
  8468. case 'mac':
  8469. case 'macintosh':
  8470. return 'macintosh';
  8471. case 'csmicrosoftpublishing':
  8472. case 'microsoftpublishing':
  8473. return 'Microsoft-Publishing';
  8474. case 'csmnem':
  8475. case 'mnem':
  8476. return 'MNEM';
  8477. case 'csmnemonic':
  8478. case 'mnemonic':
  8479. return 'MNEMONIC';
  8480. case 'csiso86hungarian':
  8481. case 'hu':
  8482. case 'isoir86':
  8483. case 'iso646hu':
  8484. case 'msz77953':
  8485. return 'MSZ_7795.3';
  8486. case 'csnatsdano':
  8487. case 'isoir91':
  8488. case 'natsdano':
  8489. return 'NATS-DANO';
  8490. case 'csnatsdanoadd':
  8491. case 'isoir92':
  8492. case 'natsdanoadd':
  8493. return 'NATS-DANO-ADD';
  8494. case 'csnatssefi':
  8495. case 'isoir81':
  8496. case 'natssefi':
  8497. return 'NATS-SEFI';
  8498. case 'csnatssefiadd':
  8499. case 'isoir82':
  8500. case 'natssefiadd':
  8501. return 'NATS-SEFI-ADD';
  8502. case 'csiso151cuba':
  8503. case 'cuba':
  8504. case 'isoir151':
  8505. case 'iso646cu':
  8506. case 'ncnc001081':
  8507. return 'NC_NC00-10:81';
  8508. case 'csiso69french':
  8509. case 'fr':
  8510. case 'isoir69':
  8511. case 'iso646fr':
  8512. case 'nfz62010':
  8513. return 'NF_Z_62-010';
  8514. case 'csiso25french':
  8515. case 'isoir25':
  8516. case 'iso646fr1':
  8517. case 'nfz620101973':
  8518. return 'NF_Z_62-010_(1973)';
  8519. case 'csiso60danishnorwegian':
  8520. case 'csiso60norwegian1':
  8521. case 'isoir60':
  8522. case 'iso646no':
  8523. case 'no':
  8524. case 'ns45511':
  8525. return 'NS_4551-1';
  8526. case 'csiso61norwegian2':
  8527. case 'isoir61':
  8528. case 'iso646no2':
  8529. case 'no2':
  8530. case 'ns45512':
  8531. return 'NS_4551-2';
  8532. case 'osdebcdicdf03irv':
  8533. return 'OSD_EBCDIC_DF03_IRV';
  8534. case 'osdebcdicdf041':
  8535. return 'OSD_EBCDIC_DF04_1';
  8536. case 'osdebcdicdf0415':
  8537. return 'OSD_EBCDIC_DF04_15';
  8538. case 'cspc8danishnorwegian':
  8539. case 'pc8danishnorwegian':
  8540. return 'PC8-Danish-Norwegian';
  8541. case 'cspc8turkish':
  8542. case 'pc8turkish':
  8543. return 'PC8-Turkish';
  8544. case 'csiso16portuguese':
  8545. case 'isoir16':
  8546. case 'iso646pt':
  8547. case 'pt':
  8548. return 'PT';
  8549. case 'csiso84portuguese2':
  8550. case 'isoir84':
  8551. case 'iso646pt2':
  8552. case 'pt2':
  8553. return 'PT2';
  8554. case 'cp154':
  8555. case 'csptcp154':
  8556. case 'cyrillicasian':
  8557. case 'pt154':
  8558. case 'ptcp154':
  8559. return 'PTCP154';
  8560. case 'scsu':
  8561. return 'SCSU';
  8562. case 'csiso10swedish':
  8563. case 'fi':
  8564. case 'isoir10':
  8565. case 'iso646fi':
  8566. case 'iso646se':
  8567. case 'se':
  8568. case 'sen850200b':
  8569. return 'SEN_850200_B';
  8570. case 'csiso11swedishfornames':
  8571. case 'isoir11':
  8572. case 'iso646se2':
  8573. case 'se2':
  8574. case 'sen850200c':
  8575. return 'SEN_850200_C';
  8576. case 'csshiftjis':
  8577. case 'mskanji':
  8578. case 'shiftjis':
  8579. return 'Shift_JIS';
  8580. case 'csiso102t617bit':
  8581. case 'isoir102':
  8582. case 't617bit':
  8583. return 'T.61-7bit';
  8584. case 'csiso103t618bit':
  8585. case 'isoir103':
  8586. case 't61':
  8587. case 't618bit':
  8588. return 'T.61-8bit';
  8589. case 'csiso128t101g2':
  8590. case 'isoir128':
  8591. case 't101g2':
  8592. return 'T.101-G2';
  8593. case 'cstscii':
  8594. case 'tscii':
  8595. return 'TSCII';
  8596. case 'csunicode11':
  8597. case 'unicode11':
  8598. return 'UNICODE-1-1';
  8599. case 'csunicode11utf7':
  8600. case 'unicode11utf7':
  8601. return 'UNICODE-1-1-UTF-7';
  8602. case 'csunknown8bit':
  8603. case 'unknown8bit':
  8604. return 'UNKNOWN-8BIT';
  8605. case 'ansix341968':
  8606. case 'ansix341986':
  8607. case 'ascii':
  8608. case 'cp367':
  8609. case 'csascii':
  8610. case 'ibm367':
  8611. case 'isoir6':
  8612. case 'iso646us':
  8613. case 'iso646irv1991':
  8614. case 'us':
  8615. case 'usascii':
  8616. return 'US-ASCII';
  8617. case 'csusdk':
  8618. case 'usdk':
  8619. return 'us-dk';
  8620. case 'utf7':
  8621. return 'UTF-7';
  8622. case 'utf8':
  8623. return 'UTF-8';
  8624. case 'utf16':
  8625. return 'UTF-16';
  8626. case 'utf16be':
  8627. return 'UTF-16BE';
  8628. case 'utf16le':
  8629. return 'UTF-16LE';
  8630. case 'utf32':
  8631. return 'UTF-32';
  8632. case 'utf32be':
  8633. return 'UTF-32BE';
  8634. case 'utf32le':
  8635. return 'UTF-32LE';
  8636. case 'csventurainternational':
  8637. case 'venturainternational':
  8638. return 'Ventura-International';
  8639. case 'csventuramath':
  8640. case 'venturamath':
  8641. return 'Ventura-Math';
  8642. case 'csventuraus':
  8643. case 'venturaus':
  8644. return 'Ventura-US';
  8645. case 'csiso70videotexsupp1':
  8646. case 'isoir70':
  8647. case 'videotexsuppl':
  8648. return 'videotex-suppl';
  8649. case 'csviqr':
  8650. case 'viqr':
  8651. return 'VIQR';
  8652. case 'csviscii':
  8653. case 'viscii':
  8654. return 'VISCII';
  8655. case 'cswindows31j':
  8656. case 'windows31j':
  8657. return 'Windows-31J';
  8658. case 'iso885911':
  8659. case 'tis620':
  8660. return 'Windows-874';
  8661. case 'cseuckr':
  8662. case 'euckr':
  8663. case 'windows949':
  8664. case 'csksc56011987':
  8665. case 'isoir149':
  8666. case 'korean':
  8667. case 'ksc5601':
  8668. case 'ksc56011987':
  8669. case 'ksc56011989':
  8670. return 'Windows-949';
  8671. case 'windows1250':
  8672. return 'windows-1250';
  8673. case 'windows1251':
  8674. return 'windows-1251';
  8675. case 'cp819':
  8676. case 'csisolatin1':
  8677. case 'ibm819':
  8678. case 'iso88591':
  8679. case 'isoir100':
  8680. case 'iso885911987':
  8681. case 'l1':
  8682. case 'latin1':
  8683. case 'windows1252':
  8684. return 'Windows-1252';
  8685. case 'windows1252':
  8686. return 'windows-1252';
  8687. case 'windows1253':
  8688. return 'windows-1253';
  8689. case 'csisolatin5':
  8690. case 'iso88599':
  8691. case 'isoir148':
  8692. case 'iso885991989':
  8693. case 'l5':
  8694. case 'latin5':
  8695. case 'windows1254':
  8696. return 'Windows-1254';
  8697. case 'windows1254':
  8698. return 'windows-1254';
  8699. case 'windows1255':
  8700. return 'windows-1255';
  8701. case 'windows1256':
  8702. return 'windows-1256';
  8703. case 'windows1257':
  8704. return 'windows-1257';
  8705. case 'windows1258':
  8706. return 'windows-1258';
  8707. default:
  8708. return $charset;
  8709. }
  8710. }
  8711. function get_curl_version()
  8712. {
  8713. if (is_array($curl = curl_version()))
  8714. {
  8715. $curl = $curl['version'];
  8716. }
  8717. elseif (substr($curl, 0, 5) == 'curl/')
  8718. {
  8719. $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
  8720. }
  8721. elseif (substr($curl, 0, 8) == 'libcurl/')
  8722. {
  8723. $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
  8724. }
  8725. else
  8726. {
  8727. $curl = 0;
  8728. }
  8729. return $curl;
  8730. }
  8731. function is_subclass_of($class1, $class2)
  8732. {
  8733. if (func_num_args() != 2)
  8734. {
  8735. trigger_error('Wrong parameter count for SimplePie_Misc::is_subclass_of()', E_USER_WARNING);
  8736. }
  8737. elseif (version_compare(PHP_VERSION, '5.0.3', '>=') || is_object($class1))
  8738. {
  8739. return is_subclass_of($class1, $class2);
  8740. }
  8741. elseif (is_string($class1) && is_string($class2))
  8742. {
  8743. if (class_exists($class1))
  8744. {
  8745. if (class_exists($class2))
  8746. {
  8747. $class2 = strtolower($class2);
  8748. while ($class1 = strtolower(get_parent_class($class1)))
  8749. {
  8750. if ($class1 == $class2)
  8751. {
  8752. return true;
  8753. }
  8754. }
  8755. }
  8756. }
  8757. else
  8758. {
  8759. trigger_error('Unknown class passed as parameter', E_USER_WARNNG);
  8760. }
  8761. }
  8762. return false;
  8763. }
  8764. /**
  8765. * Strip HTML comments
  8766. *
  8767. * @access public
  8768. * @param string $data Data to strip comments from
  8769. * @return string Comment stripped string
  8770. */
  8771. function strip_comments($data)
  8772. {
  8773. $output = '';
  8774. while (($start = strpos($data, '<!--')) !== false)
  8775. {
  8776. $output .= substr($data, 0, $start);
  8777. if (($end = strpos($data, '-->', $start)) !== false)
  8778. {
  8779. $data = substr_replace($data, '', 0, $end + 3);
  8780. }
  8781. else
  8782. {
  8783. $data = '';
  8784. }
  8785. }
  8786. return $output . $data;
  8787. }
  8788. function parse_date($dt)
  8789. {
  8790. $parser = SimplePie_Parse_Date::get();
  8791. return $parser->parse($dt);
  8792. }
  8793. /**
  8794. * Decode HTML entities
  8795. *
  8796. * @static
  8797. * @access public
  8798. * @param string $data Input data
  8799. * @return string Output data
  8800. */
  8801. function entities_decode($data)
  8802. {
  8803. $decoder = new SimplePie_Decode_HTML_Entities($data);
  8804. return $decoder->parse();
  8805. }
  8806. /**
  8807. * Remove RFC822 comments
  8808. *
  8809. * @access public
  8810. * @param string $data Data to strip comments from
  8811. * @return string Comment stripped string
  8812. */
  8813. function uncomment_rfc822($string)
  8814. {
  8815. $string = (string) $string;
  8816. $position = 0;
  8817. $length = strlen($string);
  8818. $depth = 0;
  8819. $output = '';
  8820. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  8821. {
  8822. $output .= substr($string, $position, $pos - $position);
  8823. $position = $pos + 1;
  8824. if ($string[$pos - 1] !== '\\')
  8825. {
  8826. $depth++;
  8827. while ($depth && $position < $length)
  8828. {
  8829. $position += strcspn($string, '()', $position);
  8830. if ($string[$position - 1] === '\\')
  8831. {
  8832. $position++;
  8833. continue;
  8834. }
  8835. elseif (isset($string[$position]))
  8836. {
  8837. switch ($string[$position])
  8838. {
  8839. case '(':
  8840. $depth++;
  8841. break;
  8842. case ')':
  8843. $depth--;
  8844. break;
  8845. }
  8846. $position++;
  8847. }
  8848. else
  8849. {
  8850. break;
  8851. }
  8852. }
  8853. }
  8854. else
  8855. {
  8856. $output .= '(';
  8857. }
  8858. }
  8859. $output .= substr($string, $position);
  8860. return $output;
  8861. }
  8862. function parse_mime($mime)
  8863. {
  8864. if (($pos = strpos($mime, ';')) === false)
  8865. {
  8866. return trim($mime);
  8867. }
  8868. else
  8869. {
  8870. return trim(substr($mime, 0, $pos));
  8871. }
  8872. }
  8873. function htmlspecialchars_decode($string, $quote_style)
  8874. {
  8875. if (function_exists('htmlspecialchars_decode'))
  8876. {
  8877. return htmlspecialchars_decode($string, $quote_style);
  8878. }
  8879. else
  8880. {
  8881. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
  8882. }
  8883. }
  8884. function atom_03_construct_type($attribs)
  8885. {
  8886. if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) == 'base64'))
  8887. {
  8888. $mode = SIMPLEPIE_CONSTRUCT_BASE64;
  8889. }
  8890. else
  8891. {
  8892. $mode = SIMPLEPIE_CONSTRUCT_NONE;
  8893. }
  8894. if (isset($attribs['']['type']))
  8895. {
  8896. switch (strtolower(trim($attribs['']['type'])))
  8897. {
  8898. case 'text':
  8899. case 'text/plain':
  8900. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  8901. case 'html':
  8902. case 'text/html':
  8903. return SIMPLEPIE_CONSTRUCT_HTML | $mode;
  8904. case 'xhtml':
  8905. case 'application/xhtml+xml':
  8906. return SIMPLEPIE_CONSTRUCT_XHTML | $mode;
  8907. default:
  8908. return SIMPLEPIE_CONSTRUCT_NONE | $mode;
  8909. }
  8910. }
  8911. else
  8912. {
  8913. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  8914. }
  8915. }
  8916. function atom_10_construct_type($attribs)
  8917. {
  8918. if (isset($attribs['']['type']))
  8919. {
  8920. switch (strtolower(trim($attribs['']['type'])))
  8921. {
  8922. case 'text':
  8923. return SIMPLEPIE_CONSTRUCT_TEXT;
  8924. case 'html':
  8925. return SIMPLEPIE_CONSTRUCT_HTML;
  8926. case 'xhtml':
  8927. return SIMPLEPIE_CONSTRUCT_XHTML;
  8928. default:
  8929. return SIMPLEPIE_CONSTRUCT_NONE;
  8930. }
  8931. }
  8932. return SIMPLEPIE_CONSTRUCT_TEXT;
  8933. }
  8934. function atom_10_content_construct_type($attribs)
  8935. {
  8936. if (isset($attribs['']['type']))
  8937. {
  8938. $type = strtolower(trim($attribs['']['type']));
  8939. switch ($type)
  8940. {
  8941. case 'text':
  8942. return SIMPLEPIE_CONSTRUCT_TEXT;
  8943. case 'html':
  8944. return SIMPLEPIE_CONSTRUCT_HTML;
  8945. case 'xhtml':
  8946. return SIMPLEPIE_CONSTRUCT_XHTML;
  8947. }
  8948. if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) == 'text/')
  8949. {
  8950. return SIMPLEPIE_CONSTRUCT_NONE;
  8951. }
  8952. else
  8953. {
  8954. return SIMPLEPIE_CONSTRUCT_BASE64;
  8955. }
  8956. }
  8957. else
  8958. {
  8959. return SIMPLEPIE_CONSTRUCT_TEXT;
  8960. }
  8961. }
  8962. function is_isegment_nz_nc($string)
  8963. {
  8964. 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);
  8965. }
  8966. function space_seperated_tokens($string)
  8967. {
  8968. $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
  8969. $string_length = strlen($string);
  8970. $position = strspn($string, $space_characters);
  8971. $tokens = array();
  8972. while ($position < $string_length)
  8973. {
  8974. $len = strcspn($string, $space_characters, $position);
  8975. $tokens[] = substr($string, $position, $len);
  8976. $position += $len;
  8977. $position += strspn($string, $space_characters, $position);
  8978. }
  8979. return $tokens;
  8980. }
  8981. function array_unique($array)
  8982. {
  8983. if (version_compare(PHP_VERSION, '5.2', '>='))
  8984. {
  8985. return array_unique($array);
  8986. }
  8987. else
  8988. {
  8989. $array = (array) $array;
  8990. $new_array = array();
  8991. $new_array_strings = array();
  8992. foreach ($array as $key => $value)
  8993. {
  8994. if (is_object($value))
  8995. {
  8996. if (method_exists($value, '__toString'))
  8997. {
  8998. $cmp = $value->__toString();
  8999. }
  9000. else
  9001. {
  9002. trigger_error('Object of class ' . get_class($value) . ' could not be converted to string', E_USER_ERROR);
  9003. }
  9004. }
  9005. elseif (is_array($value))
  9006. {
  9007. $cmp = (string) reset($value);
  9008. }
  9009. else
  9010. {
  9011. $cmp = (string) $value;
  9012. }
  9013. if (!in_array($cmp, $new_array_strings))
  9014. {
  9015. $new_array[$key] = $value;
  9016. $new_array_strings[] = $cmp;
  9017. }
  9018. }
  9019. return $new_array;
  9020. }
  9021. }
  9022. /**
  9023. * Converts a unicode codepoint to a UTF-8 character
  9024. *
  9025. * @static
  9026. * @access public
  9027. * @param int $codepoint Unicode codepoint
  9028. * @return string UTF-8 character
  9029. */
  9030. function codepoint_to_utf8($codepoint)
  9031. {
  9032. static $cache = array();
  9033. $codepoint = (int) $codepoint;
  9034. if (isset($cache[$codepoint]))
  9035. {
  9036. return $cache[$codepoint];
  9037. }
  9038. elseif ($codepoint < 0)
  9039. {
  9040. return $cache[$codepoint] = false;
  9041. }
  9042. else if ($codepoint <= 0x7f)
  9043. {
  9044. return $cache[$codepoint] = chr($codepoint);
  9045. }
  9046. else if ($codepoint <= 0x7ff)
  9047. {
  9048. return $cache[$codepoint] = chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
  9049. }
  9050. else if ($codepoint <= 0xffff)
  9051. {
  9052. return $cache[$codepoint] = chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9053. }
  9054. else if ($codepoint <= 0x10ffff)
  9055. {
  9056. return $cache[$codepoint] = chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9057. }
  9058. else
  9059. {
  9060. // U+FFFD REPLACEMENT CHARACTER
  9061. return $cache[$codepoint] = "\xEF\xBF\xBD";
  9062. }
  9063. }
  9064. /**
  9065. * Re-implementation of PHP 5's stripos()
  9066. *
  9067. * Returns the numeric position of the first occurrence of needle in the
  9068. * haystack string.
  9069. *
  9070. * @static
  9071. * @access string
  9072. * @param object $haystack
  9073. * @param string $needle Note that the needle may be a string of one or more
  9074. * characters. If needle is not a string, it is converted to an integer
  9075. * and applied as the ordinal value of a character.
  9076. * @param int $offset The optional offset parameter allows you to specify which
  9077. * character in haystack to start searching. The position returned is still
  9078. * relative to the beginning of haystack.
  9079. * @return bool If needle is not found, stripos() will return boolean false.
  9080. */
  9081. function stripos($haystack, $needle, $offset = 0)
  9082. {
  9083. if (function_exists('stripos'))
  9084. {
  9085. return stripos($haystack, $needle, $offset);
  9086. }
  9087. else
  9088. {
  9089. if (is_string($needle))
  9090. {
  9091. $needle = strtolower($needle);
  9092. }
  9093. elseif (is_int($needle) || is_bool($needle) || is_double($needle))
  9094. {
  9095. $needle = strtolower(chr($needle));
  9096. }
  9097. else
  9098. {
  9099. trigger_error('needle is not a string or an integer', E_USER_WARNING);
  9100. return false;
  9101. }
  9102. return strpos(strtolower($haystack), $needle, $offset);
  9103. }
  9104. }
  9105. /**
  9106. * Similar to parse_str()
  9107. *
  9108. * Returns an associative array of name/value pairs, where the value is an
  9109. * array of values that have used the same name
  9110. *
  9111. * @static
  9112. * @access string
  9113. * @param string $str The input string.
  9114. * @return array
  9115. */
  9116. function parse_str($str)
  9117. {
  9118. $return = array();
  9119. $str = explode('&', $str);
  9120. foreach ($str as $section)
  9121. {
  9122. if (strpos($section, '=') !== false)
  9123. {
  9124. list($name, $value) = explode('=', $section, 2);
  9125. $return[urldecode($name)][] = urldecode($value);
  9126. }
  9127. else
  9128. {
  9129. $return[urldecode($section)][] = null;
  9130. }
  9131. }
  9132. return $return;
  9133. }
  9134. /**
  9135. * Detect XML encoding, as per XML 1.0 Appendix F.1
  9136. *
  9137. * @todo Add support for EBCDIC
  9138. * @param string $data XML data
  9139. * @return array Possible encodings
  9140. */
  9141. function xml_encoding($data)
  9142. {
  9143. // UTF-32 Big Endian BOM
  9144. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  9145. {
  9146. $encoding[] = 'UTF-32BE';
  9147. }
  9148. // UTF-32 Little Endian BOM
  9149. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  9150. {
  9151. $encoding[] = 'UTF-32LE';
  9152. }
  9153. // UTF-16 Big Endian BOM
  9154. elseif (substr($data, 0, 2) === "\xFE\xFF")
  9155. {
  9156. $encoding[] = 'UTF-16BE';
  9157. }
  9158. // UTF-16 Little Endian BOM
  9159. elseif (substr($data, 0, 2) === "\xFF\xFE")
  9160. {
  9161. $encoding[] = 'UTF-16LE';
  9162. }
  9163. // UTF-8 BOM
  9164. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  9165. {
  9166. $encoding[] = 'UTF-8';
  9167. }
  9168. // UTF-32 Big Endian Without BOM
  9169. 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")
  9170. {
  9171. if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
  9172. {
  9173. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8'));
  9174. if ($parser->parse())
  9175. {
  9176. $encoding[] = $parser->encoding;
  9177. }
  9178. }
  9179. $encoding[] = 'UTF-32BE';
  9180. }
  9181. // UTF-32 Little Endian Without BOM
  9182. 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")
  9183. {
  9184. if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
  9185. {
  9186. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8'));
  9187. if ($parser->parse())
  9188. {
  9189. $encoding[] = $parser->encoding;
  9190. }
  9191. }
  9192. $encoding[] = 'UTF-32LE';
  9193. }
  9194. // UTF-16 Big Endian Without BOM
  9195. elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
  9196. {
  9197. if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
  9198. {
  9199. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8'));
  9200. if ($parser->parse())
  9201. {
  9202. $encoding[] = $parser->encoding;
  9203. }
  9204. }
  9205. $encoding[] = 'UTF-16BE';
  9206. }
  9207. // UTF-16 Little Endian Without BOM
  9208. elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00")
  9209. {
  9210. if ($pos = strpos($data, "\x3F\x00\x3E\x00"))
  9211. {
  9212. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8'));
  9213. if ($parser->parse())
  9214. {
  9215. $encoding[] = $parser->encoding;
  9216. }
  9217. }
  9218. $encoding[] = 'UTF-16LE';
  9219. }
  9220. // US-ASCII (or superset)
  9221. elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C")
  9222. {
  9223. if ($pos = strpos($data, "\x3F\x3E"))
  9224. {
  9225. $parser = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5));
  9226. if ($parser->parse())
  9227. {
  9228. $encoding[] = $parser->encoding;
  9229. }
  9230. }
  9231. $encoding[] = 'UTF-8';
  9232. }
  9233. // Fallback to UTF-8
  9234. else
  9235. {
  9236. $encoding[] = 'UTF-8';
  9237. }
  9238. return $encoding;
  9239. }
  9240. }
  9241. /**
  9242. * Decode HTML Entities
  9243. *
  9244. * This implements HTML5 as of revision 967 (2007-06-28)
  9245. *
  9246. * @package SimplePie
  9247. */
  9248. class SimplePie_Decode_HTML_Entities
  9249. {
  9250. /**
  9251. * Data to be parsed
  9252. *
  9253. * @access private
  9254. * @var string
  9255. */
  9256. var $data = '';
  9257. /**
  9258. * Currently consumed bytes
  9259. *
  9260. * @access private
  9261. * @var string
  9262. */
  9263. var $consumed = '';
  9264. /**
  9265. * Position of the current byte being parsed
  9266. *
  9267. * @access private
  9268. * @var int
  9269. */
  9270. var $position = 0;
  9271. /**
  9272. * Create an instance of the class with the input data
  9273. *
  9274. * @access public
  9275. * @param string $data Input data
  9276. */
  9277. function SimplePie_Decode_HTML_Entities($data)
  9278. {
  9279. $this->data = $data;
  9280. }
  9281. /**
  9282. * Parse the input data
  9283. *
  9284. * @access public
  9285. * @return string Output data
  9286. */
  9287. function parse()
  9288. {
  9289. while (($this->position = strpos($this->data, '&', $this->position)) !== false)
  9290. {
  9291. $this->consume();
  9292. $this->entity();
  9293. $this->consumed = '';
  9294. }
  9295. return $this->data;
  9296. }
  9297. /**
  9298. * Consume the next byte
  9299. *
  9300. * @access private
  9301. * @return mixed The next byte, or false, if there is no more data
  9302. */
  9303. function consume()
  9304. {
  9305. if (isset($this->data[$this->position]))
  9306. {
  9307. $this->consumed .= $this->data[$this->position];
  9308. return $this->data[$this->position++];
  9309. }
  9310. else
  9311. {
  9312. $this->consumed = false;
  9313. return false;
  9314. }
  9315. }
  9316. /**
  9317. * Consume a range of characters
  9318. *
  9319. * @access private
  9320. * @param string $chars Characters to consume
  9321. * @return mixed A series of characters that match the range, or false
  9322. */
  9323. function consume_range($chars)
  9324. {
  9325. if ($len = strspn($this->data, $chars, $this->position))
  9326. {
  9327. $data = substr($this->data, $this->position, $len);
  9328. $this->consumed .= $data;
  9329. $this->position += $len;
  9330. return $data;
  9331. }
  9332. else
  9333. {
  9334. $this->consumed = false;
  9335. return false;
  9336. }
  9337. }
  9338. /**
  9339. * Unconsume one byte
  9340. *
  9341. * @access private
  9342. */
  9343. function unconsume()
  9344. {
  9345. $this->consumed = substr($this->consumed, 0, -1);
  9346. $this->position--;
  9347. }
  9348. /**
  9349. * Decode an entity
  9350. *
  9351. * @access private
  9352. */
  9353. function entity()
  9354. {
  9355. switch ($this->consume())
  9356. {
  9357. case "\x09":
  9358. case "\x0A":
  9359. case "\x0B":
  9360. case "\x0B":
  9361. case "\x0C":
  9362. case "\x20":
  9363. case "\x3C":
  9364. case "\x26":
  9365. case false:
  9366. break;
  9367. case "\x23":
  9368. switch ($this->consume())
  9369. {
  9370. case "\x78":
  9371. case "\x58":
  9372. $range = '0123456789ABCDEFabcdef';
  9373. $hex = true;
  9374. break;
  9375. default:
  9376. $range = '0123456789';
  9377. $hex = false;
  9378. $this->unconsume();
  9379. break;
  9380. }
  9381. if ($codepoint = $this->consume_range($range))
  9382. {
  9383. static $windows_1252_specials = array(0x0D => "\x0A", 0x80 => "\xE2\x82\xAC", 0x81 => "\xEF\xBF\xBD", 0x82 => "\xE2\x80\x9A", 0x83 => "\xC6\x92", 0x84 => "\xE2\x80\x9E", 0x85 => "\xE2\x80\xA6", 0x86 => "\xE2\x80\xA0", 0x87 => "\xE2\x80\xA1", 0x88 => "\xCB\x86", 0x89 => "\xE2\x80\xB0", 0x8A => "\xC5\xA0", 0x8B => "\xE2\x80\xB9", 0x8C => "\xC5\x92", 0x8D => "\xEF\xBF\xBD", 0x8E => "\xC5\xBD", 0x8F => "\xEF\xBF\xBD", 0x90 => "\xEF\xBF\xBD", 0x91 => "\xE2\x80\x98", 0x92 => "\xE2\x80\x99", 0x93 => "\xE2\x80\x9C", 0x94 => "\xE2\x80\x9D", 0x95 => "\xE2\x80\xA2", 0x96 => "\xE2\x80\x93", 0x97 => "\xE2\x80\x94", 0x98 => "\xCB\x9C", 0x99 => "\xE2\x84\xA2", 0x9A => "\xC5\xA1", 0x9B => "\xE2\x80\xBA", 0x9C => "\xC5\x93", 0x9D => "\xEF\xBF\xBD", 0x9E => "\xC5\xBE", 0x9F => "\xC5\xB8");
  9384. if ($hex)
  9385. {
  9386. $codepoint = hexdec($codepoint);
  9387. }
  9388. else
  9389. {
  9390. $codepoint = intval($codepoint);
  9391. }
  9392. if (isset($windows_1252_specials[$codepoint]))
  9393. {
  9394. $replacement = $windows_1252_specials[$codepoint];
  9395. }
  9396. else
  9397. {
  9398. $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
  9399. }
  9400. if ($this->consume() != ';')
  9401. {
  9402. $this->unconsume();
  9403. }
  9404. $consumed_length = strlen($this->consumed);
  9405. $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
  9406. $this->position += strlen($replacement) - $consumed_length;
  9407. }
  9408. break;
  9409. default:
  9410. static $entities = array('Aacute' => "\xC3\x81", 'aacute' => "\xC3\xA1", 'Aacute;' => "\xC3\x81", 'aacute;' => "\xC3\xA1", 'Acirc' => "\xC3\x82", 'acirc' => "\xC3\xA2", 'Acirc;' => "\xC3\x82", 'acirc;' => "\xC3\xA2", 'acute' => "\xC2\xB4", 'acute;' => "\xC2\xB4", 'AElig' => "\xC3\x86", 'aelig' => "\xC3\xA6", 'AElig;' => "\xC3\x86", 'aelig;' => "\xC3\xA6", 'Agrave' => "\xC3\x80", 'agrave' => "\xC3\xA0", 'Agrave;' => "\xC3\x80", 'agrave;' => "\xC3\xA0", 'alefsym;' => "\xE2\x84\xB5", 'Alpha;' => "\xCE\x91", 'alpha;' => "\xCE\xB1", 'AMP' => "\x26", 'amp' => "\x26", 'AMP;' => "\x26", 'amp;' => "\x26", 'and;' => "\xE2\x88\xA7", 'ang;' => "\xE2\x88\xA0", 'apos;' => "\x27", 'Aring' => "\xC3\x85", 'aring' => "\xC3\xA5", 'Aring;' => "\xC3\x85", 'aring;' => "\xC3\xA5", 'asymp;' => "\xE2\x89\x88", 'Atilde' => "\xC3\x83", 'atilde' => "\xC3\xA3", 'Atilde;' => "\xC3\x83", 'atilde;' => "\xC3\xA3", 'Auml' => "\xC3\x84", 'auml' => "\xC3\xA4", 'Auml;' => "\xC3\x84", 'auml;' => "\xC3\xA4", 'bdquo;' => "\xE2\x80\x9E", 'Beta;' => "\xCE\x92", 'beta;' => "\xCE\xB2", 'brvbar' => "\xC2\xA6", 'brvbar;' => "\xC2\xA6", 'bull;' => "\xE2\x80\xA2", 'cap;' => "\xE2\x88\xA9", 'Ccedil' => "\xC3\x87", 'ccedil' => "\xC3\xA7", 'Ccedil;' => "\xC3\x87", 'ccedil;' => "\xC3\xA7", 'cedil' => "\xC2\xB8", 'cedil;' => "\xC2\xB8", 'cent' => "\xC2\xA2", 'cent;' => "\xC2\xA2", 'Chi;' => "\xCE\xA7", 'chi;' => "\xCF\x87", 'circ;' => "\xCB\x86", 'clubs;' => "\xE2\x99\xA3", 'cong;' => "\xE2\x89\x85", 'COPY' => "\xC2\xA9", 'copy' => "\xC2\xA9", 'COPY;' => "\xC2\xA9", 'copy;' => "\xC2\xA9", 'crarr;' => "\xE2\x86\xB5", 'cup;' => "\xE2\x88\xAA", 'curren' => "\xC2\xA4", 'curren;' => "\xC2\xA4", 'Dagger;' => "\xE2\x80\xA1", 'dagger;' => "\xE2\x80\xA0", 'dArr;' => "\xE2\x87\x93", 'darr;' => "\xE2\x86\x93", 'deg' => "\xC2\xB0", 'deg;' => "\xC2\xB0", 'Delta;' => "\xCE\x94", 'delta;' => "\xCE\xB4", 'diams;' => "\xE2\x99\xA6", 'divide' => "\xC3\xB7", 'divide;' => "\xC3\xB7", 'Eacute' => "\xC3\x89", 'eacute' => "\xC3\xA9", 'Eacute;' => "\xC3\x89", 'eacute;' => "\xC3\xA9", 'Ecirc' => "\xC3\x8A", 'ecirc' => "\xC3\xAA", 'Ecirc;' => "\xC3\x8A", 'ecirc;' => "\xC3\xAA", 'Egrave' => "\xC3\x88", 'egrave' => "\xC3\xA8", 'Egrave;' => "\xC3\x88", 'egrave;' => "\xC3\xA8", 'empty;' => "\xE2\x88\x85", 'emsp;' => "\xE2\x80\x83", 'ensp;' => "\xE2\x80\x82", 'Epsilon;' => "\xCE\x95", 'epsilon;' => "\xCE\xB5", 'equiv;' => "\xE2\x89\xA1", 'Eta;' => "\xCE\x97", 'eta;' => "\xCE\xB7", 'ETH' => "\xC3\x90", 'eth' => "\xC3\xB0", 'ETH;' => "\xC3\x90", 'eth;' => "\xC3\xB0", 'Euml' => "\xC3\x8B", 'euml' => "\xC3\xAB", 'Euml;' => "\xC3\x8B", 'euml;' => "\xC3\xAB", 'euro;' => "\xE2\x82\xAC", 'exist;' => "\xE2\x88\x83", 'fnof;' => "\xC6\x92", 'forall;' => "\xE2\x88\x80", 'frac12' => "\xC2\xBD", 'frac12;' => "\xC2\xBD", 'frac14' => "\xC2\xBC", 'frac14;' => "\xC2\xBC", 'frac34' => "\xC2\xBE", 'frac34;' => "\xC2\xBE", 'frasl;' => "\xE2\x81\x84", 'Gamma;' => "\xCE\x93", 'gamma;' => "\xCE\xB3", 'ge;' => "\xE2\x89\xA5", 'GT' => "\x3E", 'gt' => "\x3E", 'GT;' => "\x3E", 'gt;' => "\x3E", 'hArr;' => "\xE2\x87\x94", 'harr;' => "\xE2\x86\x94", 'hearts;' => "\xE2\x99\xA5", 'hellip;' => "\xE2\x80\xA6", 'Iacute' => "\xC3\x8D", 'iacute' => "\xC3\xAD", 'Iacute;' => "\xC3\x8D", 'iacute;' => "\xC3\xAD", 'Icirc' => "\xC3\x8E", 'icirc' => "\xC3\xAE", 'Icirc;' => "\xC3\x8E", 'icirc;' => "\xC3\xAE", 'iexcl' => "\xC2\xA1", 'iexcl;' => "\xC2\xA1", 'Igrave' => "\xC3\x8C", 'igrave' => "\xC3\xAC", 'Igrave;' => "\xC3\x8C", 'igrave;' => "\xC3\xAC", 'image;' => "\xE2\x84\x91", 'infin;' => "\xE2\x88\x9E", 'int;' => "\xE2\x88\xAB", 'Iota;' => "\xCE\x99", 'iota;' => "\xCE\xB9", 'iquest' => "\xC2\xBF", 'iquest;' => "\xC2\xBF", 'isin;' => "\xE2\x88\x88", 'Iuml' => "\xC3\x8F", 'iuml' => "\xC3\xAF", 'Iuml;' => "\xC3\x8F", 'iuml;' => "\xC3\xAF", 'Kappa;' => "\xCE\x9A", 'kappa;' => "\xCE\xBA", 'Lambda;' => "\xCE\x9B", 'lambda;' => "\xCE\xBB", 'lang;' => "\xE3\x80\x88", 'laquo' => "\xC2\xAB", 'laquo;' => "\xC2\xAB", 'lArr;' => "\xE2\x87\x90", 'larr;' => "\xE2\x86\x90", 'lceil;' => "\xE2\x8C\x88", 'ldquo;' => "\xE2\x80\x9C", 'le;' => "\xE2\x89\xA4", 'lfloor;' => "\xE2\x8C\x8A", 'lowast;' => "\xE2\x88\x97", 'loz;' => "\xE2\x97\x8A", 'lrm;' => "\xE2\x80\x8E", 'lsaquo;' => "\xE2\x80\xB9", 'lsquo;' => "\xE2\x80\x98", 'LT' => "\x3C", 'lt' => "\x3C", 'LT;' => "\x3C", 'lt;' => "\x3C", 'macr' => "\xC2\xAF", 'macr;' => "\xC2\xAF", 'mdash;' => "\xE2\x80\x94", 'micro' => "\xC2\xB5", 'micro;' => "\xC2\xB5", 'middot' => "\xC2\xB7", 'middot;' => "\xC2\xB7", 'minus;' => "\xE2\x88\x92", 'Mu;' => "\xCE\x9C", 'mu;' => "\xCE\xBC", 'nabla;' => "\xE2\x88\x87", 'nbsp' => "\xC2\xA0", 'nbsp;' => "\xC2\xA0", 'ndash;' => "\xE2\x80\x93", 'ne;' => "\xE2\x89\xA0", 'ni;' => "\xE2\x88\x8B", 'not' => "\xC2\xAC", 'not;' => "\xC2\xAC", 'notin;' => "\xE2\x88\x89", 'nsub;' => "\xE2\x8A\x84", 'Ntilde' => "\xC3\x91", 'ntilde' => "\xC3\xB1", 'Ntilde;' => "\xC3\x91", 'ntilde;' => "\xC3\xB1", 'Nu;' => "\xCE\x9D", 'nu;' => "\xCE\xBD", 'Oacute' => "\xC3\x93", 'oacute' => "\xC3\xB3", 'Oacute;' => "\xC3\x93", 'oacute;' => "\xC3\xB3", 'Ocirc' => "\xC3\x94", 'ocirc' => "\xC3\xB4", 'Ocirc;' => "\xC3\x94", 'ocirc;' => "\xC3\xB4", 'OElig;' => "\xC5\x92", 'oelig;' => "\xC5\x93", 'Ograve' => "\xC3\x92", 'ograve' => "\xC3\xB2", 'Ograve;' => "\xC3\x92", 'ograve;' => "\xC3\xB2", 'oline;' => "\xE2\x80\xBE", 'Omega;' => "\xCE\xA9", 'omega;' => "\xCF\x89", 'Omicron;' => "\xCE\x9F", 'omicron;' => "\xCE\xBF", 'oplus;' => "\xE2\x8A\x95", 'or;' => "\xE2\x88\xA8", 'ordf' => "\xC2\xAA", 'ordf;' => "\xC2\xAA", 'ordm' => "\xC2\xBA", 'ordm;' => "\xC2\xBA", 'Oslash' => "\xC3\x98", 'oslash' => "\xC3\xB8", 'Oslash;' => "\xC3\x98", 'oslash;' => "\xC3\xB8", 'Otilde' => "\xC3\x95", 'otilde' => "\xC3\xB5", 'Otilde;' => "\xC3\x95", 'otilde;' => "\xC3\xB5", 'otimes;' => "\xE2\x8A\x97", 'Ouml' => "\xC3\x96", 'ouml' => "\xC3\xB6", 'Ouml;' => "\xC3\x96", 'ouml;' => "\xC3\xB6", 'para' => "\xC2\xB6", 'para;' => "\xC2\xB6", 'part;' => "\xE2\x88\x82", 'permil;' => "\xE2\x80\xB0", 'perp;' => "\xE2\x8A\xA5", 'Phi;' => "\xCE\xA6", 'phi;' => "\xCF\x86", 'Pi;' => "\xCE\xA0", 'pi;' => "\xCF\x80", 'piv;' => "\xCF\x96", 'plusmn' => "\xC2\xB1", 'plusmn;' => "\xC2\xB1", 'pound' => "\xC2\xA3", 'pound;' => "\xC2\xA3", 'Prime;' => "\xE2\x80\xB3", 'prime;' => "\xE2\x80\xB2", 'prod;' => "\xE2\x88\x8F", 'prop;' => "\xE2\x88\x9D", 'Psi;' => "\xCE\xA8", 'psi;' => "\xCF\x88", 'QUOT' => "\x22", 'quot' => "\x22", 'QUOT;' => "\x22", 'quot;' => "\x22", 'radic;' => "\xE2\x88\x9A", 'rang;' => "\xE3\x80\x89", 'raquo' => "\xC2\xBB", 'raquo;' => "\xC2\xBB", 'rArr;' => "\xE2\x87\x92", 'rarr;' => "\xE2\x86\x92", 'rceil;' => "\xE2\x8C\x89", 'rdquo;' => "\xE2\x80\x9D", 'real;' => "\xE2\x84\x9C", 'REG' => "\xC2\xAE", 'reg' => "\xC2\xAE", 'REG;' => "\xC2\xAE", 'reg;' => "\xC2\xAE", 'rfloor;' => "\xE2\x8C\x8B", 'Rho;' => "\xCE\xA1", 'rho;' => "\xCF\x81", 'rlm;' => "\xE2\x80\x8F", 'rsaquo;' => "\xE2\x80\xBA", 'rsquo;' => "\xE2\x80\x99", 'sbquo;' => "\xE2\x80\x9A", 'Scaron;' => "\xC5\xA0", 'scaron;' => "\xC5\xA1", 'sdot;' => "\xE2\x8B\x85", 'sect' => "\xC2\xA7", 'sect;' => "\xC2\xA7", 'shy' => "\xC2\xAD", 'shy;' => "\xC2\xAD", 'Sigma;' => "\xCE\xA3", 'sigma;' => "\xCF\x83", 'sigmaf;' => "\xCF\x82", 'sim;' => "\xE2\x88\xBC", 'spades;' => "\xE2\x99\xA0", 'sub;' => "\xE2\x8A\x82", 'sube;' => "\xE2\x8A\x86", 'sum;' => "\xE2\x88\x91", 'sup;' => "\xE2\x8A\x83", 'sup1' => "\xC2\xB9", 'sup1;' => "\xC2\xB9", 'sup2' => "\xC2\xB2", 'sup2;' => "\xC2\xB2", 'sup3' => "\xC2\xB3", 'sup3;' => "\xC2\xB3", 'supe;' => "\xE2\x8A\x87", 'szlig' => "\xC3\x9F", 'szlig;' => "\xC3\x9F", 'Tau;' => "\xCE\xA4", 'tau;' => "\xCF\x84", 'there4;' => "\xE2\x88\xB4", 'Theta;' => "\xCE\x98", 'theta;' => "\xCE\xB8", 'thetasym;' => "\xCF\x91", 'thinsp;' => "\xE2\x80\x89", 'THORN' => "\xC3\x9E", 'thorn' => "\xC3\xBE", 'THORN;' => "\xC3\x9E", 'thorn;' => "\xC3\xBE", 'tilde;' => "\xCB\x9C", 'times' => "\xC3\x97", 'times;' => "\xC3\x97", 'TRADE;' => "\xE2\x84\xA2", 'trade;' => "\xE2\x84\xA2", 'Uacute' => "\xC3\x9A", 'uacute' => "\xC3\xBA", 'Uacute;' => "\xC3\x9A", 'uacute;' => "\xC3\xBA", 'uArr;' => "\xE2\x87\x91", 'uarr;' => "\xE2\x86\x91", 'Ucirc' => "\xC3\x9B", 'ucirc' => "\xC3\xBB", 'Ucirc;' => "\xC3\x9B", 'ucirc;' => "\xC3\xBB", 'Ugrave' => "\xC3\x99", 'ugrave' => "\xC3\xB9", 'Ugrave;' => "\xC3\x99", 'ugrave;' => "\xC3\xB9", 'uml' => "\xC2\xA8", 'uml;' => "\xC2\xA8", 'upsih;' => "\xCF\x92", 'Upsilon;' => "\xCE\xA5", 'upsilon;' => "\xCF\x85", 'Uuml' => "\xC3\x9C", 'uuml' => "\xC3\xBC", 'Uuml;' => "\xC3\x9C", 'uuml;' => "\xC3\xBC", 'weierp;' => "\xE2\x84\x98", 'Xi;' => "\xCE\x9E", 'xi;' => "\xCE\xBE", 'Yacute' => "\xC3\x9D", 'yacute' => "\xC3\xBD", 'Yacute;' => "\xC3\x9D", 'yacute;' => "\xC3\xBD", 'yen' => "\xC2\xA5", 'yen;' => "\xC2\xA5", 'yuml' => "\xC3\xBF", 'Yuml;' => "\xC5\xB8", 'yuml;' => "\xC3\xBF", 'Zeta;' => "\xCE\x96", 'zeta;' => "\xCE\xB6", 'zwj;' => "\xE2\x80\x8D", 'zwnj;' => "\xE2\x80\x8C");
  9411. for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++)
  9412. {
  9413. $consumed = substr($this->consumed, 1);
  9414. if (isset($entities[$consumed]))
  9415. {
  9416. $match = $consumed;
  9417. }
  9418. }
  9419. if ($match !== null)
  9420. {
  9421. $this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
  9422. $this->position += strlen($entities[$match]) - strlen($consumed) - 1;
  9423. }
  9424. break;
  9425. }
  9426. }
  9427. }
  9428. /**
  9429. * Date Parser
  9430. *
  9431. * @package SimplePie
  9432. */
  9433. class SimplePie_Parse_Date
  9434. {
  9435. /**
  9436. * Input data
  9437. *
  9438. * @access protected
  9439. * @var string
  9440. */
  9441. var $date;
  9442. /**
  9443. * List of days, calendar day name => ordinal day number in the week
  9444. *
  9445. * @access protected
  9446. * @var array
  9447. */
  9448. var $day = array(
  9449. // English
  9450. 'mon' => 1,
  9451. 'monday' => 1,
  9452. 'tue' => 2,
  9453. 'tuesday' => 2,
  9454. 'wed' => 3,
  9455. 'wednesday' => 3,
  9456. 'thu' => 4,
  9457. 'thursday' => 4,
  9458. 'fri' => 5,
  9459. 'friday' => 5,
  9460. 'sat' => 6,
  9461. 'saturday' => 6,
  9462. 'sun' => 7,
  9463. 'sunday' => 7,
  9464. // Dutch
  9465. 'maandag' => 1,
  9466. 'dinsdag' => 2,
  9467. 'woensdag' => 3,
  9468. 'donderdag' => 4,
  9469. 'vrijdag' => 5,
  9470. 'zaterdag' => 6,
  9471. 'zondag' => 7,
  9472. // French
  9473. 'lundi' => 1,
  9474. 'mardi' => 2,
  9475. 'mercredi' => 3,
  9476. 'jeudi' => 4,
  9477. 'vendredi' => 5,
  9478. 'samedi' => 6,
  9479. 'dimanche' => 7,
  9480. // German
  9481. 'montag' => 1,
  9482. 'dienstag' => 2,
  9483. 'mittwoch' => 3,
  9484. 'donnerstag' => 4,
  9485. 'freitag' => 5,
  9486. 'samstag' => 6,
  9487. 'sonnabend' => 6,
  9488. 'sonntag' => 7,
  9489. // Italian
  9490. 'lunedì' => 1,
  9491. 'martedì' => 2,
  9492. 'mercoledì' => 3,
  9493. 'giovedì' => 4,
  9494. 'venerdì' => 5,
  9495. 'sabato' => 6,
  9496. 'domenica' => 7,
  9497. // Spanish
  9498. 'lunes' => 1,
  9499. 'martes' => 2,
  9500. 'miércoles' => 3,
  9501. 'jueves' => 4,
  9502. 'viernes' => 5,
  9503. 'sábado' => 6,
  9504. 'domingo' => 7,
  9505. // Finnish
  9506. 'maanantai' => 1,
  9507. 'tiistai' => 2,
  9508. 'keskiviikko' => 3,
  9509. 'torstai' => 4,
  9510. 'perjantai' => 5,
  9511. 'lauantai' => 6,
  9512. 'sunnuntai' => 7,
  9513. // Hungarian
  9514. 'hétf?' => 1,
  9515. 'kedd' => 2,
  9516. 'szerda' => 3,
  9517. 'csütörtok' => 4,
  9518. 'péntek' => 5,
  9519. 'szombat' => 6,
  9520. 'vasárnap' => 7,
  9521. // Greek
  9522. '???' => 1,
  9523. '???' => 2,
  9524. '???' => 3,
  9525. '???' => 4,
  9526. '???' => 5,
  9527. '???' => 6,
  9528. '???' => 7,
  9529. );
  9530. /**
  9531. * List of months, calendar month name => calendar month number
  9532. *
  9533. * @access protected
  9534. * @var array
  9535. */
  9536. var $month = array(
  9537. // English
  9538. 'jan' => 1,
  9539. 'january' => 1,
  9540. 'feb' => 2,
  9541. 'february' => 2,
  9542. 'mar' => 3,
  9543. 'march' => 3,
  9544. 'apr' => 4,
  9545. 'april' => 4,
  9546. 'may' => 5,
  9547. // No long form of May
  9548. 'jun' => 6,
  9549. 'june' => 6,
  9550. 'jul' => 7,
  9551. 'july' => 7,
  9552. 'aug' => 8,
  9553. 'august' => 8,
  9554. 'sep' => 9,
  9555. 'september' => 8,
  9556. 'oct' => 10,
  9557. 'october' => 10,
  9558. 'nov' => 11,
  9559. 'november' => 11,
  9560. 'dec' => 12,
  9561. 'december' => 12,
  9562. // Dutch
  9563. 'januari' => 1,
  9564. 'februari' => 2,
  9565. 'maart' => 3,
  9566. 'april' => 4,
  9567. 'mei' => 5,
  9568. 'juni' => 6,
  9569. 'juli' => 7,
  9570. 'augustus' => 8,
  9571. 'september' => 9,
  9572. 'oktober' => 10,
  9573. 'november' => 11,
  9574. 'december' => 12,
  9575. // French
  9576. 'janvier' => 1,
  9577. 'février' => 2,
  9578. 'mars' => 3,
  9579. 'avril' => 4,
  9580. 'mai' => 5,
  9581. 'juin' => 6,
  9582. 'juillet' => 7,
  9583. 'août' => 8,
  9584. 'septembre' => 9,
  9585. 'octobre' => 10,
  9586. 'novembre' => 11,
  9587. 'décembre' => 12,
  9588. // German
  9589. 'januar' => 1,
  9590. 'februar' => 2,
  9591. 'märz' => 3,
  9592. 'april' => 4,
  9593. 'mai' => 5,
  9594. 'juni' => 6,
  9595. 'juli' => 7,
  9596. 'august' => 8,
  9597. 'september' => 9,
  9598. 'oktober' => 10,
  9599. 'november' => 11,
  9600. 'dezember' => 12,
  9601. // Italian
  9602. 'gennaio' => 1,
  9603. 'febbraio' => 2,
  9604. 'marzo' => 3,
  9605. 'aprile' => 4,
  9606. 'maggio' => 5,
  9607. 'giugno' => 6,
  9608. 'luglio' => 7,
  9609. 'agosto' => 8,
  9610. 'settembre' => 9,
  9611. 'ottobre' => 10,
  9612. 'novembre' => 11,
  9613. 'dicembre' => 12,
  9614. // Spanish
  9615. 'enero' => 1,
  9616. 'febrero' => 2,
  9617. 'marzo' => 3,
  9618. 'abril' => 4,
  9619. 'mayo' => 5,
  9620. 'junio' => 6,
  9621. 'julio' => 7,
  9622. 'agosto' => 8,
  9623. 'septiembre' => 9,
  9624. 'setiembre' => 9,
  9625. 'octubre' => 10,
  9626. 'noviembre' => 11,
  9627. 'diciembre' => 12,
  9628. // Finnish
  9629. 'tammikuu' => 1,
  9630. 'helmikuu' => 2,
  9631. 'maaliskuu' => 3,
  9632. 'huhtikuu' => 4,
  9633. 'toukokuu' => 5,
  9634. 'kesäkuu' => 6,
  9635. 'heinäkuu' => 7,
  9636. 'elokuu' => 8,
  9637. 'suuskuu' => 9,
  9638. 'lokakuu' => 10,
  9639. 'marras' => 11,
  9640. 'joulukuu' => 12,
  9641. // Hungarian
  9642. 'január' => 1,
  9643. 'február' => 2,
  9644. 'március' => 3,
  9645. 'április' => 4,
  9646. 'május' => 5,
  9647. 'június' => 6,
  9648. 'július' => 7,
  9649. 'augusztus' => 8,
  9650. 'szeptember' => 9,
  9651. 'október' => 10,
  9652. 'november' => 11,
  9653. 'december' => 12,
  9654. // Greek
  9655. '???' => 1,
  9656. '???' => 2,
  9657. '???' => 3,
  9658. '???' => 3,
  9659. '???' => 4,
  9660. '???' => 5,
  9661. '???' => 5,
  9662. '???' => 5,
  9663. '????' => 6,
  9664. '???' => 6,
  9665. '????' => 7,
  9666. '???' => 7,
  9667. '???' => 8,
  9668. '???' => 8,
  9669. '???' => 9,
  9670. '???' => 10,
  9671. '???' => 11,
  9672. '???' => 12,
  9673. );
  9674. /**
  9675. * List of timezones, abbreviation => offset from UTC
  9676. *
  9677. * @access protected
  9678. * @var array
  9679. */
  9680. var $timezone = array(
  9681. 'ACDT' => 37800,
  9682. 'ACIT' => 28800,
  9683. 'ACST' => 34200,
  9684. 'ACT' => -18000,
  9685. 'ACWDT' => 35100,
  9686. 'ACWST' => 31500,
  9687. 'AEDT' => 39600,
  9688. 'AEST' => 36000,
  9689. 'AFT' => 16200,
  9690. 'AKDT' => -28800,
  9691. 'AKST' => -32400,
  9692. 'AMDT' => 18000,
  9693. 'AMT' => -14400,
  9694. 'ANAST' => 46800,
  9695. 'ANAT' => 43200,
  9696. 'ART' => -10800,
  9697. 'AZOST' => -3600,
  9698. 'AZST' => 18000,
  9699. 'AZT' => 14400,
  9700. 'BIOT' => 21600,
  9701. 'BIT' => -43200,
  9702. 'BOT' => -14400,
  9703. 'BRST' => -7200,
  9704. 'BRT' => -10800,
  9705. 'BST' => 3600,
  9706. 'BTT' => 21600,
  9707. 'CAST' => 18000,
  9708. 'CAT' => 7200,
  9709. 'CCT' => 23400,
  9710. 'CDT' => -18000,
  9711. 'CEDT' => 7200,
  9712. 'CET' => 3600,
  9713. 'CGST' => -7200,
  9714. 'CGT' => -10800,
  9715. 'CHADT' => 49500,
  9716. 'CHAST' => 45900,
  9717. 'CIST' => -28800,
  9718. 'CKT' => -36000,
  9719. 'CLDT' => -10800,
  9720. 'CLST' => -14400,
  9721. 'COT' => -18000,
  9722. 'CST' => -21600,
  9723. 'CVT' => -3600,
  9724. 'CXT' => 25200,
  9725. 'DAVT' => 25200,
  9726. 'DTAT' => 36000,
  9727. 'EADT' => -18000,
  9728. 'EAST' => -21600,
  9729. 'EAT' => 10800,
  9730. 'ECT' => -18000,
  9731. 'EDT' => -14400,
  9732. 'EEST' => 10800,
  9733. 'EET' => 7200,
  9734. 'EGT' => -3600,
  9735. 'EKST' => 21600,
  9736. 'EST' => -18000,
  9737. 'FJT' => 43200,
  9738. 'FKDT' => -10800,
  9739. 'FKST' => -14400,
  9740. 'FNT' => -7200,
  9741. 'GALT' => -21600,
  9742. 'GEDT' => 14400,
  9743. 'GEST' => 10800,
  9744. 'GFT' => -10800,
  9745. 'GILT' => 43200,
  9746. 'GIT' => -32400,
  9747. 'GST' => 14400,
  9748. 'GST' => -7200,
  9749. 'GYT' => -14400,
  9750. 'HAA' => -10800,
  9751. 'HAC' => -18000,
  9752. 'HADT' => -32400,
  9753. 'HAE' => -14400,
  9754. 'HAP' => -25200,
  9755. 'HAR' => -21600,
  9756. 'HAST' => -36000,
  9757. 'HAT' => -9000,
  9758. 'HAY' => -28800,
  9759. 'HKST' => 28800,
  9760. 'HMT' => 18000,
  9761. 'HNA' => -14400,
  9762. 'HNC' => -21600,
  9763. 'HNE' => -18000,
  9764. 'HNP' => -28800,
  9765. 'HNR' => -25200,
  9766. 'HNT' => -12600,
  9767. 'HNY' => -32400,
  9768. 'IRDT' => 16200,
  9769. 'IRKST' => 32400,
  9770. 'IRKT' => 28800,
  9771. 'IRST' => 12600,
  9772. 'JFDT' => -10800,
  9773. 'JFST' => -14400,
  9774. 'JST' => 32400,
  9775. 'KGST' => 21600,
  9776. 'KGT' => 18000,
  9777. 'KOST' => 39600,
  9778. 'KOVST' => 28800,
  9779. 'KOVT' => 25200,
  9780. 'KRAST' => 28800,
  9781. 'KRAT' => 25200,
  9782. 'KST' => 32400,
  9783. 'LHDT' => 39600,
  9784. 'LHST' => 37800,
  9785. 'LINT' => 50400,
  9786. 'LKT' => 21600,
  9787. 'MAGST' => 43200,
  9788. 'MAGT' => 39600,
  9789. 'MAWT' => 21600,
  9790. 'MDT' => -21600,
  9791. 'MESZ' => 7200,
  9792. 'MEZ' => 3600,
  9793. 'MHT' => 43200,
  9794. 'MIT' => -34200,
  9795. 'MNST' => 32400,
  9796. 'MSDT' => 14400,
  9797. 'MSST' => 10800,
  9798. 'MST' => -25200,
  9799. 'MUT' => 14400,
  9800. 'MVT' => 18000,
  9801. 'MYT' => 28800,
  9802. 'NCT' => 39600,
  9803. 'NDT' => -9000,
  9804. 'NFT' => 41400,
  9805. 'NMIT' => 36000,
  9806. 'NOVST' => 25200,
  9807. 'NOVT' => 21600,
  9808. 'NPT' => 20700,
  9809. 'NRT' => 43200,
  9810. 'NST' => -12600,
  9811. 'NUT' => -39600,
  9812. 'NZDT' => 46800,
  9813. 'NZST' => 43200,
  9814. 'OMSST' => 25200,
  9815. 'OMST' => 21600,
  9816. 'PDT' => -25200,
  9817. 'PET' => -18000,
  9818. 'PETST' => 46800,
  9819. 'PETT' => 43200,
  9820. 'PGT' => 36000,
  9821. 'PHOT' => 46800,
  9822. 'PHT' => 28800,
  9823. 'PKT' => 18000,
  9824. 'PMDT' => -7200,
  9825. 'PMST' => -10800,
  9826. 'PONT' => 39600,
  9827. 'PST' => -28800,
  9828. 'PWT' => 32400,
  9829. 'PYST' => -10800,
  9830. 'PYT' => -14400,
  9831. 'RET' => 14400,
  9832. 'ROTT' => -10800,
  9833. 'SAMST' => 18000,
  9834. 'SAMT' => 14400,
  9835. 'SAST' => 7200,
  9836. 'SBT' => 39600,
  9837. 'SCDT' => 46800,
  9838. 'SCST' => 43200,
  9839. 'SCT' => 14400,
  9840. 'SEST' => 3600,
  9841. 'SGT' => 28800,
  9842. 'SIT' => 28800,
  9843. 'SRT' => -10800,
  9844. 'SST' => -39600,
  9845. 'SYST' => 10800,
  9846. 'SYT' => 7200,
  9847. 'TFT' => 18000,
  9848. 'THAT' => -36000,
  9849. 'TJT' => 18000,
  9850. 'TKT' => -36000,
  9851. 'TMT' => 18000,
  9852. 'TOT' => 46800,
  9853. 'TPT' => 32400,
  9854. 'TRUT' => 36000,
  9855. 'TVT' => 43200,
  9856. 'TWT' => 28800,
  9857. 'UYST' => -7200,
  9858. 'UYT' => -10800,
  9859. 'UZT' => 18000,
  9860. 'VET' => -14400,
  9861. 'VLAST' => 39600,
  9862. 'VLAT' => 36000,
  9863. 'VOST' => 21600,
  9864. 'VUT' => 39600,
  9865. 'WAST' => 7200,
  9866. 'WAT' => 3600,
  9867. 'WDT' => 32400,
  9868. 'WEST' => 3600,
  9869. 'WFT' => 43200,
  9870. 'WIB' => 25200,
  9871. 'WIT' => 32400,
  9872. 'WITA' => 28800,
  9873. 'WKST' => 18000,
  9874. 'WST' => 28800,
  9875. 'YAKST' => 36000,
  9876. 'YAKT' => 32400,
  9877. 'YAPT' => 36000,
  9878. 'YEKST' => 21600,
  9879. 'YEKT' => 18000,
  9880. );
  9881. /**
  9882. * Cached PCRE for SimplePie_Parse_Date::$day
  9883. *
  9884. * @access protected
  9885. * @var string
  9886. */
  9887. var $day_pcre;
  9888. /**
  9889. * Cached PCRE for SimplePie_Parse_Date::$month
  9890. *
  9891. * @access protected
  9892. * @var string
  9893. */
  9894. var $month_pcre;
  9895. /**
  9896. * Array of user-added callback methods
  9897. *
  9898. * @access private
  9899. * @var array
  9900. */
  9901. var $built_in = array();
  9902. /**
  9903. * Array of user-added callback methods
  9904. *
  9905. * @access private
  9906. * @var array
  9907. */
  9908. var $user = array();
  9909. /**
  9910. * Create new SimplePie_Parse_Date object, and set self::day_pcre,
  9911. * self::month_pcre, and self::built_in
  9912. *
  9913. * @access private
  9914. */
  9915. function SimplePie_Parse_Date()
  9916. {
  9917. $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
  9918. $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
  9919. static $cache;
  9920. if (!isset($cache[get_class($this)]))
  9921. {
  9922. if (extension_loaded('Reflection'))
  9923. {
  9924. $class = new ReflectionClass(get_class($this));
  9925. $methods = $class->getMethods();
  9926. $all_methods = array();
  9927. foreach ($methods as $method)
  9928. {
  9929. $all_methods[] = $method->getName();
  9930. }
  9931. }
  9932. else
  9933. {
  9934. $all_methods = get_class_methods($this);
  9935. }
  9936. foreach ($all_methods as $method)
  9937. {
  9938. if (strtolower(substr($method, 0, 5)) === 'date_')
  9939. {
  9940. $cache[get_class($this)][] = $method;
  9941. }
  9942. }
  9943. }
  9944. foreach ($cache[get_class($this)] as $method)
  9945. {
  9946. $this->built_in[] = $method;
  9947. }
  9948. }
  9949. /**
  9950. * Get the object
  9951. *
  9952. * @access public
  9953. */
  9954. function get()
  9955. {
  9956. static $object;
  9957. if (!$object)
  9958. {
  9959. $object = new SimplePie_Parse_Date;
  9960. }
  9961. return $object;
  9962. }
  9963. /**
  9964. * Parse a date
  9965. *
  9966. * @final
  9967. * @access public
  9968. * @param string $date Date to parse
  9969. * @return int Timestamp corresponding to date string, or false on failure
  9970. */
  9971. function parse($date)
  9972. {
  9973. foreach ($this->user as $method)
  9974. {
  9975. if (($returned = call_user_func($method, $date)) !== false)
  9976. {
  9977. return $returned;
  9978. }
  9979. }
  9980. foreach ($this->built_in as $method)
  9981. {
  9982. if (($returned = call_user_func(array(&$this, $method), $date)) !== false)
  9983. {
  9984. return $returned;
  9985. }
  9986. }
  9987. return false;
  9988. }
  9989. /**
  9990. * Add a callback method to parse a date
  9991. *
  9992. * @final
  9993. * @access public
  9994. * @param callback $callback
  9995. */
  9996. function add_callback($callback)
  9997. {
  9998. if (is_callable($callback))
  9999. {
  10000. $this->user[] = $callback;
  10001. }
  10002. else
  10003. {
  10004. trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
  10005. }
  10006. }
  10007. /**
  10008. * Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
  10009. * well as allowing any of upper or lower case "T", horizontal tabs, or
  10010. * spaces to be used as the time seperator (including more than one))
  10011. *
  10012. * @access protected
  10013. * @return int Timestamp
  10014. */
  10015. function date_w3cdtf($date)
  10016. {
  10017. static $pcre;
  10018. if (!$pcre)
  10019. {
  10020. $year = '([0-9]{4})';
  10021. $month = $day = $hour = $minute = $second = '([0-9]{2})';
  10022. $decimal = '([0-9]*)';
  10023. $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
  10024. $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
  10025. }
  10026. if (preg_match($pcre, $date, $match))
  10027. {
  10028. /*
  10029. Capturing subpatterns:
  10030. 1: Year
  10031. 2: Month
  10032. 3: Day
  10033. 4: Hour
  10034. 5: Minute
  10035. 6: Second
  10036. 7: Decimal fraction of a second
  10037. 8: Zulu
  10038. 9: Timezone ±
  10039. 10: Timezone hours
  10040. 11: Timezone minutes
  10041. */
  10042. // Fill in empty matches
  10043. for ($i = count($match); $i <= 3; $i++)
  10044. {
  10045. $match[$i] = '1';
  10046. }
  10047. for ($i = count($match); $i <= 7; $i++)
  10048. {
  10049. $match[$i] = '0';
  10050. }
  10051. // Numeric timezone
  10052. if (isset($match[9]) && $match[9] !== '')
  10053. {
  10054. $timezone = $match[10] * 3600;
  10055. $timezone += $match[11] * 60;
  10056. if ($match[9] === '-')
  10057. {
  10058. $timezone = 0 - $timezone;
  10059. }
  10060. }
  10061. else
  10062. {
  10063. $timezone = 0;
  10064. }
  10065. // Convert the number of seconds to an integer, taking decimals into account
  10066. $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
  10067. return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
  10068. }
  10069. else
  10070. {
  10071. return false;
  10072. }
  10073. }
  10074. /**
  10075. * Remove RFC822 comments
  10076. *
  10077. * @access protected
  10078. * @param string $data Data to strip comments from
  10079. * @return string Comment stripped string
  10080. */
  10081. function remove_rfc2822_comments($string)
  10082. {
  10083. $string = (string) $string;
  10084. $position = 0;
  10085. $length = strlen($string);
  10086. $depth = 0;
  10087. $output = '';
  10088. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  10089. {
  10090. $output .= substr($string, $position, $pos - $position);
  10091. $position = $pos + 1;
  10092. if ($string[$pos - 1] !== '\\')
  10093. {
  10094. $depth++;
  10095. while ($depth && $position < $length)
  10096. {
  10097. $position += strcspn($string, '()', $position);
  10098. if ($string[$position - 1] === '\\')
  10099. {
  10100. $position++;
  10101. continue;
  10102. }
  10103. elseif (isset($string[$position]))
  10104. {
  10105. switch ($string[$position])
  10106. {
  10107. case '(':
  10108. $depth++;
  10109. break;
  10110. case ')':
  10111. $depth--;
  10112. break;
  10113. }
  10114. $position++;
  10115. }
  10116. else
  10117. {
  10118. break;
  10119. }
  10120. }
  10121. }
  10122. else
  10123. {
  10124. $output .= '(';
  10125. }
  10126. }
  10127. $output .= substr($string, $position);
  10128. return $output;
  10129. }
  10130. /**
  10131. * Parse RFC2822's date format
  10132. *
  10133. * @access protected
  10134. * @return int Timestamp
  10135. */
  10136. function date_rfc2822($date)
  10137. {
  10138. static $pcre;
  10139. if (!$pcre)
  10140. {
  10141. $wsp = '[\x09\x20]';
  10142. $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
  10143. $optional_fws = $fws . '?';
  10144. $day_name = $this->day_pcre;
  10145. $month = $this->month_pcre;
  10146. $day = '([0-9]{1,2})';
  10147. $hour = $minute = $second = '([0-9]{2})';
  10148. $year = '([0-9]{2,4})';
  10149. $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
  10150. $character_zone = '([A-Z]{1,5})';
  10151. $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
  10152. $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
  10153. }
  10154. if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
  10155. {
  10156. /*
  10157. Capturing subpatterns:
  10158. 1: Day name
  10159. 2: Day
  10160. 3: Month
  10161. 4: Year
  10162. 5: Hour
  10163. 6: Minute
  10164. 7: Second
  10165. 8: Timezone ±
  10166. 9: Timezone hours
  10167. 10: Timezone minutes
  10168. 11: Alphabetic timezone
  10169. */
  10170. // Find the month number
  10171. $month = $this->month[strtolower($match[3])];
  10172. // Numeric timezone
  10173. if ($match[8] !== '')
  10174. {
  10175. $timezone = $match[9] * 3600;
  10176. $timezone += $match[10] * 60;
  10177. if ($match[8] === '-')
  10178. {
  10179. $timezone = 0 - $timezone;
  10180. }
  10181. }
  10182. // Character timezone
  10183. elseif (isset($this->timezone[strtoupper($match[11])]))
  10184. {
  10185. $timezone = $this->timezone[strtoupper($match[11])];
  10186. }
  10187. // Assume everything else to be -0000
  10188. else
  10189. {
  10190. $timezone = 0;
  10191. }
  10192. // Deal with 2/3 digit years
  10193. if ($match[4] < 50)
  10194. {
  10195. $match[4] += 2000;
  10196. }
  10197. elseif ($match[4] < 1000)
  10198. {
  10199. $match[4] += 1900;
  10200. }
  10201. // Second is optional, if it is empty set it to zero
  10202. if ($match[7] !== '')
  10203. {
  10204. $second = $match[7];
  10205. }
  10206. else
  10207. {
  10208. $second = 0;
  10209. }
  10210. return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
  10211. }
  10212. else
  10213. {
  10214. return false;
  10215. }
  10216. }
  10217. /**
  10218. * Parse RFC850's date format
  10219. *
  10220. * @access protected
  10221. * @return int Timestamp
  10222. */
  10223. function date_rfc850($date)
  10224. {
  10225. static $pcre;
  10226. if (!$pcre)
  10227. {
  10228. $space = '[\x09\x20]+';
  10229. $day_name = $this->day_pcre;
  10230. $month = $this->month_pcre;
  10231. $day = '([0-9]{1,2})';
  10232. $year = $hour = $minute = $second = '([0-9]{2})';
  10233. $zone = '([A-Z]{1,5})';
  10234. $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
  10235. }
  10236. if (preg_match($pcre, $date, $match))
  10237. {
  10238. /*
  10239. Capturing subpatterns:
  10240. 1: Day name
  10241. 2: Day
  10242. 3: Month
  10243. 4: Year
  10244. 5: Hour
  10245. 6: Minute
  10246. 7: Second
  10247. 8: Timezone
  10248. */
  10249. // Month
  10250. $month = $this->month[strtolower($match[3])];
  10251. // Character timezone
  10252. if (isset($this->timezone[strtoupper($match[8])]))
  10253. {
  10254. $timezone = $this->timezone[strtoupper($match[8])];
  10255. }
  10256. // Assume everything else to be -0000
  10257. else
  10258. {
  10259. $timezone = 0;
  10260. }
  10261. // Deal with 2 digit year
  10262. if ($match[4] < 50)
  10263. {
  10264. $match[4] += 2000;
  10265. }
  10266. else
  10267. {
  10268. $match[4] += 1900;
  10269. }
  10270. return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
  10271. }
  10272. else
  10273. {
  10274. return false;
  10275. }
  10276. }
  10277. /**
  10278. * Parse C99's asctime()'s date format
  10279. *
  10280. * @access protected
  10281. * @return int Timestamp
  10282. */
  10283. function date_asctime($date)
  10284. {
  10285. static $pcre;
  10286. if (!$pcre)
  10287. {
  10288. $space = '[\x09\x20]+';
  10289. $wday_name = $this->day_pcre;
  10290. $mon_name = $this->month_pcre;
  10291. $day = '([0-9]{1,2})';
  10292. $hour = $sec = $min = '([0-9]{2})';
  10293. $year = '([0-9]{4})';
  10294. $terminator = '\x0A?\x00?';
  10295. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
  10296. }
  10297. if (preg_match($pcre, $date, $match))
  10298. {
  10299. /*
  10300. Capturing subpatterns:
  10301. 1: Day name
  10302. 2: Month
  10303. 3: Day
  10304. 4: Hour
  10305. 5: Minute
  10306. 6: Second
  10307. 7: Year
  10308. */
  10309. $month = $this->month[strtolower($match[2])];
  10310. return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
  10311. }
  10312. else
  10313. {
  10314. return false;
  10315. }
  10316. }
  10317. /**
  10318. * Parse dates using strtotime()
  10319. *
  10320. * @access protected
  10321. * @return int Timestamp
  10322. */
  10323. function date_strtotime($date)
  10324. {
  10325. $strtotime = strtotime($date);
  10326. if ($strtotime === -1 || $strtotime === false)
  10327. {
  10328. return false;
  10329. }
  10330. else
  10331. {
  10332. return $strtotime;
  10333. }
  10334. }
  10335. }
  10336. /**
  10337. * Content-type sniffing
  10338. *
  10339. * @package SimplePie
  10340. */
  10341. class SimplePie_Content_Type_Sniffer
  10342. {
  10343. /**
  10344. * File object
  10345. *
  10346. * @var SimplePie_File
  10347. * @access private
  10348. */
  10349. var $file;
  10350. /**
  10351. * Create an instance of the class with the input file
  10352. *
  10353. * @access public
  10354. * @param SimplePie_Content_Type_Sniffer $file Input file
  10355. */
  10356. function SimplePie_Content_Type_Sniffer($file)
  10357. {
  10358. $this->file = $file;
  10359. }
  10360. /**
  10361. * Get the Content-Type of the specified file
  10362. *
  10363. * @access public
  10364. * @return string Actual Content-Type
  10365. */
  10366. function get_type()
  10367. {
  10368. if (isset($this->file->headers['content-type']))
  10369. {
  10370. if (!isset($this->file->headers['content-encoding'])
  10371. && ($this->file->headers['content-type'] === 'text/plain'
  10372. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  10373. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'))
  10374. {
  10375. return $this->text_or_binary();
  10376. }
  10377. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
  10378. {
  10379. $official = substr($this->file->headers['content-type'], 0, $pos);
  10380. }
  10381. else
  10382. {
  10383. $official = $this->file->headers['content-type'];
  10384. }
  10385. $official = strtolower($official);
  10386. if ($official === 'unknown/unknown'
  10387. || $official === 'application/unknown')
  10388. {
  10389. return $this->unknown();
  10390. }
  10391. elseif (substr($official, -4) === '+xml'
  10392. || $official === 'text/xml'
  10393. || $official === 'application/xml')
  10394. {
  10395. return $official;
  10396. }
  10397. elseif (substr($official, 0, 6) === 'image/')
  10398. {
  10399. if ($return = $this->image())
  10400. {
  10401. return $return;
  10402. }
  10403. else
  10404. {
  10405. return $official;
  10406. }
  10407. }
  10408. elseif ($official === 'text/html')
  10409. {
  10410. return $this->feed_or_html();
  10411. }
  10412. else
  10413. {
  10414. return $official;
  10415. }
  10416. }
  10417. else
  10418. {
  10419. return $this->unknown();
  10420. }
  10421. }
  10422. /**
  10423. * Sniff text or binary
  10424. *
  10425. * @access private
  10426. * @return string Actual Content-Type
  10427. */
  10428. function text_or_binary()
  10429. {
  10430. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  10431. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  10432. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  10433. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
  10434. {
  10435. return 'text/plain';
  10436. }
  10437. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
  10438. {
  10439. return 'application/octect-stream';
  10440. }
  10441. else
  10442. {
  10443. return 'text/plain';
  10444. }
  10445. }
  10446. /**
  10447. * Sniff unknown
  10448. *
  10449. * @access private
  10450. * @return string Actual Content-Type
  10451. */
  10452. function unknown()
  10453. {
  10454. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  10455. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  10456. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  10457. || strtolower(substr($this->file->body, $ws, 7)) === '<script')
  10458. {
  10459. return 'text/html';
  10460. }
  10461. elseif (substr($this->file->body, 0, 5) === '%PDF-')
  10462. {
  10463. return 'application/pdf';
  10464. }
  10465. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
  10466. {
  10467. return 'application/postscript';
  10468. }
  10469. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  10470. || substr($this->file->body, 0, 6) === 'GIF89a')
  10471. {
  10472. return 'image/gif';
  10473. }
  10474. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  10475. {
  10476. return 'image/png';
  10477. }
  10478. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  10479. {
  10480. return 'image/jpeg';
  10481. }
  10482. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  10483. {
  10484. return 'image/bmp';
  10485. }
  10486. else
  10487. {
  10488. return $this->text_or_binary();
  10489. }
  10490. }
  10491. /**
  10492. * Sniff images
  10493. *
  10494. * @access private
  10495. * @return string Actual Content-Type
  10496. */
  10497. function image()
  10498. {
  10499. if (substr($this->file->body, 0, 6) === 'GIF87a'
  10500. || substr($this->file->body, 0, 6) === 'GIF89a')
  10501. {
  10502. return 'image/gif';
  10503. }
  10504. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  10505. {
  10506. return 'image/png';
  10507. }
  10508. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  10509. {
  10510. return 'image/jpeg';
  10511. }
  10512. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  10513. {
  10514. return 'image/bmp';
  10515. }
  10516. else
  10517. {
  10518. return false;
  10519. }
  10520. }
  10521. /**
  10522. * Sniff HTML
  10523. *
  10524. * @access private
  10525. * @return string Actual Content-Type
  10526. */
  10527. function feed_or_html()
  10528. {
  10529. $len = strlen($this->file->body);
  10530. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
  10531. while ($pos < $len)
  10532. {
  10533. switch ($this->file->body[$pos])
  10534. {
  10535. case "\x09":
  10536. case "\x0A":
  10537. case "\x0D":
  10538. case "\x20":
  10539. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  10540. continue 2;
  10541. case '<':
  10542. $pos++;
  10543. break;
  10544. default:
  10545. return 'text/html';
  10546. }
  10547. if (substr($this->file->body, $pos, 3) === '!--')
  10548. {
  10549. $pos += 3;
  10550. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
  10551. {
  10552. $pos += 3;
  10553. }
  10554. else
  10555. {
  10556. return 'text/html';
  10557. }
  10558. }
  10559. elseif (substr($this->file->body, $pos, 1) === '!')
  10560. {
  10561. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
  10562. {
  10563. $pos++;
  10564. }
  10565. else
  10566. {
  10567. return 'text/html';
  10568. }
  10569. }
  10570. elseif (substr($this->file->body, $pos, 1) === '?')
  10571. {
  10572. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
  10573. {
  10574. $pos += 2;
  10575. }
  10576. else
  10577. {
  10578. return 'text/html';
  10579. }
  10580. }
  10581. elseif (substr($this->file->body, $pos, 3) === 'rss'
  10582. || substr($this->file->body, $pos, 7) === 'rdf:RDF')
  10583. {
  10584. return 'application/rss+xml';
  10585. }
  10586. elseif (substr($this->file->body, $pos, 4) === 'feed')
  10587. {
  10588. return 'application/atom+xml';
  10589. }
  10590. else
  10591. {
  10592. return 'text/html';
  10593. }
  10594. }
  10595. return 'text/html';
  10596. }
  10597. }
  10598. /**
  10599. * Parses the XML Declaration
  10600. *
  10601. * @package SimplePie
  10602. */
  10603. class SimplePie_XML_Declaration_Parser
  10604. {
  10605. /**
  10606. * XML Version
  10607. *
  10608. * @access public
  10609. * @var string
  10610. */
  10611. var $version = '1.0';
  10612. /**
  10613. * Encoding
  10614. *
  10615. * @access public
  10616. * @var string
  10617. */
  10618. var $encoding = 'UTF-8';
  10619. /**
  10620. * Standalone
  10621. *
  10622. * @access public
  10623. * @var bool
  10624. */
  10625. var $standalone = false;
  10626. /**
  10627. * Current state of the state machine
  10628. *
  10629. * @access private
  10630. * @var string
  10631. */
  10632. var $state = 'before_version_name';
  10633. /**
  10634. * Input data
  10635. *
  10636. * @access private
  10637. * @var string
  10638. */
  10639. var $data = '';
  10640. /**
  10641. * Input data length (to avoid calling strlen() everytime this is needed)
  10642. *
  10643. * @access private
  10644. * @var int
  10645. */
  10646. var $data_length = 0;
  10647. /**
  10648. * Current position of the pointer
  10649. *
  10650. * @var int
  10651. * @access private
  10652. */
  10653. var $position = 0;
  10654. /**
  10655. * Create an instance of the class with the input data
  10656. *
  10657. * @access public
  10658. * @param string $data Input data
  10659. */
  10660. function SimplePie_XML_Declaration_Parser($data)
  10661. {
  10662. $this->data = $data;
  10663. $this->data_length = strlen($this->data);
  10664. }
  10665. /**
  10666. * Parse the input data
  10667. *
  10668. * @access public
  10669. * @return bool true on success, false on failure
  10670. */
  10671. function parse()
  10672. {
  10673. while ($this->state && $this->state !== 'emit' && $this->has_data())
  10674. {
  10675. $state = $this->state;
  10676. $this->$state();
  10677. }
  10678. $this->data = '';
  10679. if ($this->state === 'emit')
  10680. {
  10681. return true;
  10682. }
  10683. else
  10684. {
  10685. $this->version = '';
  10686. $this->encoding = '';
  10687. $this->standalone = '';
  10688. return false;
  10689. }
  10690. }
  10691. /**
  10692. * Check whether there is data beyond the pointer
  10693. *
  10694. * @access private
  10695. * @return bool true if there is further data, false if not
  10696. */
  10697. function has_data()
  10698. {
  10699. return (bool) ($this->position < $this->data_length);
  10700. }
  10701. /**
  10702. * Advance past any whitespace
  10703. *
  10704. * @return int Number of whitespace characters passed
  10705. */
  10706. function skip_whitespace()
  10707. {
  10708. $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
  10709. $this->position += $whitespace;
  10710. return $whitespace;
  10711. }
  10712. /**
  10713. * Read value
  10714. */
  10715. function get_value()
  10716. {
  10717. $quote = substr($this->data, $this->position, 1);
  10718. if ($quote === '"' || $quote === "'")
  10719. {
  10720. $this->position++;
  10721. $len = strcspn($this->data, $quote, $this->position);
  10722. if ($this->has_data())
  10723. {
  10724. $value = substr($this->data, $this->position, $len);
  10725. $this->position += $len + 1;
  10726. return $value;
  10727. }
  10728. }
  10729. return false;
  10730. }
  10731. function before_version_name()
  10732. {
  10733. if ($this->skip_whitespace())
  10734. {
  10735. $this->state = 'version_name';
  10736. }
  10737. else
  10738. {
  10739. $this->state = false;
  10740. }
  10741. }
  10742. function version_name()
  10743. {
  10744. if (substr($this->data, $this->position, 7) === 'version')
  10745. {
  10746. $this->position += 7;
  10747. $this->skip_whitespace();
  10748. $this->state = 'version_equals';
  10749. }
  10750. else
  10751. {
  10752. $this->state = false;
  10753. }
  10754. }
  10755. function version_equals()
  10756. {
  10757. if (substr($this->data, $this->position, 1) === '=')
  10758. {
  10759. $this->position++;
  10760. $this->skip_whitespace();
  10761. $this->state = 'version_value';
  10762. }
  10763. else
  10764. {
  10765. $this->state = false;
  10766. }
  10767. }
  10768. function version_value()
  10769. {
  10770. if ($this->version = $this->get_value())
  10771. {
  10772. $this->skip_whitespace();
  10773. if ($this->has_data())
  10774. {
  10775. $this->state = 'encoding_name';
  10776. }
  10777. else
  10778. {
  10779. $this->state = 'emit';
  10780. }
  10781. }
  10782. else
  10783. {
  10784. $this->state = 'standalone_name';
  10785. }
  10786. }
  10787. function encoding_name()
  10788. {
  10789. if (substr($this->data, $this->position, 8) === 'encoding')
  10790. {
  10791. $this->position += 8;
  10792. $this->skip_whitespace();
  10793. $this->state = 'encoding_equals';
  10794. }
  10795. else
  10796. {
  10797. $this->state = false;
  10798. }
  10799. }
  10800. function encoding_equals()
  10801. {
  10802. if (substr($this->data, $this->position, 1) === '=')
  10803. {
  10804. $this->position++;
  10805. $this->skip_whitespace();
  10806. $this->state = 'encoding_value';
  10807. }
  10808. else
  10809. {
  10810. $this->state = false;
  10811. }
  10812. }
  10813. function encoding_value()
  10814. {
  10815. if ($this->encoding = $this->get_value())
  10816. {
  10817. $this->skip_whitespace();
  10818. if ($this->has_data())
  10819. {
  10820. $this->state = 'standalone_name';
  10821. }
  10822. else
  10823. {
  10824. $this->state = 'emit';
  10825. }
  10826. }
  10827. else
  10828. {
  10829. $this->state = false;
  10830. }
  10831. }
  10832. function standalone_name()
  10833. {
  10834. if (substr($this->data, $this->position, 10) === 'standalone')
  10835. {
  10836. $this->position += 10;
  10837. $this->skip_whitespace();
  10838. $this->state = 'standalone_equals';
  10839. }
  10840. else
  10841. {
  10842. $this->state = false;
  10843. }
  10844. }
  10845. function standalone_equals()
  10846. {
  10847. if (substr($this->data, $this->position, 1) === '=')
  10848. {
  10849. $this->position++;
  10850. $this->skip_whitespace();
  10851. $this->state = 'standalone_value';
  10852. }
  10853. else
  10854. {
  10855. $this->state = false;
  10856. }
  10857. }
  10858. function standalone_value()
  10859. {
  10860. if ($standalone = $this->get_value())
  10861. {
  10862. switch ($standalone)
  10863. {
  10864. case 'yes':
  10865. $this->standalone = true;
  10866. break;
  10867. case 'no':
  10868. $this->standalone = false;
  10869. break;
  10870. default:
  10871. $this->state = false;
  10872. return;
  10873. }
  10874. $this->skip_whitespace();
  10875. if ($this->has_data())
  10876. {
  10877. $this->state = false;
  10878. }
  10879. else
  10880. {
  10881. $this->state = 'emit';
  10882. }
  10883. }
  10884. else
  10885. {
  10886. $this->state = false;
  10887. }
  10888. }
  10889. }
  10890. class SimplePie_Locator
  10891. {
  10892. var $useragent;
  10893. var $timeout;
  10894. var $file;
  10895. var $local = array();
  10896. var $elsewhere = array();
  10897. var $file_class = 'SimplePie_File';
  10898. var $cached_entities = array();
  10899. var $http_base;
  10900. var $base;
  10901. var $base_location = 0;
  10902. var $checked_feeds = 0;
  10903. var $max_checked_feeds = 10;
  10904. var $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
  10905. function SimplePie_Locator(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File', $max_checked_feeds = 10, $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer')
  10906. {
  10907. $this->file =& $file;
  10908. $this->file_class = $file_class;
  10909. $this->useragent = $useragent;
  10910. $this->timeout = $timeout;
  10911. $this->max_checked_feeds = $max_checked_feeds;
  10912. $this->content_type_sniffer_class = $content_type_sniffer_class;
  10913. }
  10914. function find($type = SIMPLEPIE_LOCATOR_ALL)
  10915. {
  10916. if ($this->is_feed($this->file))
  10917. {
  10918. return $this->file;
  10919. }
  10920. if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  10921. {
  10922. $sniffer = new $this->content_type_sniffer_class($this->file);
  10923. if ($sniffer->get_type() !== 'text/html')
  10924. {
  10925. return null;
  10926. }
  10927. }
  10928. if ($type & ~SIMPLEPIE_LOCATOR_NONE)
  10929. {
  10930. $this->get_base();
  10931. }
  10932. if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
  10933. {
  10934. return $working;
  10935. }
  10936. if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
  10937. {
  10938. if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
  10939. {
  10940. return $working;
  10941. }
  10942. if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
  10943. {
  10944. return $working;
  10945. }
  10946. if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
  10947. {
  10948. return $working;
  10949. }
  10950. if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
  10951. {
  10952. return $working;
  10953. }
  10954. }
  10955. return null;
  10956. }
  10957. function is_feed(&$file)
  10958. {
  10959. if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  10960. {
  10961. $sniffer = new $this->content_type_sniffer_class($file);
  10962. $sniffed = $sniffer->get_type();
  10963. if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml')))
  10964. {
  10965. return true;
  10966. }
  10967. else
  10968. {
  10969. return false;
  10970. }
  10971. }
  10972. elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
  10973. {
  10974. return true;
  10975. }
  10976. else
  10977. {
  10978. return false;
  10979. }
  10980. }
  10981. function get_base()
  10982. {
  10983. $this->http_base = $this->file->url;
  10984. $this->base = $this->http_base;
  10985. $elements = SimplePie_Misc::get_element('base', $this->file->body);
  10986. foreach ($elements as $element)
  10987. {
  10988. if ($element['attribs']['href']['data'] !== '')
  10989. {
  10990. $this->base = SimplePie_Misc::absolutize_url(trim($element['attribs']['href']['data']), $this->http_base);
  10991. $this->base_location = $element['offset'];
  10992. break;
  10993. }
  10994. }
  10995. }
  10996. function autodiscovery()
  10997. {
  10998. $links = array_merge(SimplePie_Misc::get_element('link', $this->file->body), SimplePie_Misc::get_element('a', $this->file->body), SimplePie_Misc::get_element('area', $this->file->body));
  10999. $done = array();
  11000. foreach ($links as $link)
  11001. {
  11002. if ($this->checked_feeds == $this->max_checked_feeds)
  11003. {
  11004. break;
  11005. }
  11006. if (isset($link['attribs']['href']['data']) && isset($link['attribs']['rel']['data']))
  11007. {
  11008. $rel = array_unique(SimplePie_Misc::space_seperated_tokens(strtolower($link['attribs']['rel']['data'])));
  11009. if ($this->base_location < $link['offset'])
  11010. {
  11011. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base);
  11012. }
  11013. else
  11014. {
  11015. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base);
  11016. }
  11017. if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !empty($link['attribs']['type']['data']) && in_array(strtolower(SimplePie_Misc::parse_mime($link['attribs']['type']['data'])), array('application/rss+xml', 'application/atom+xml'))))
  11018. {
  11019. $this->checked_feeds++;
  11020. $feed =& new $this->file_class($href, $this->timeout, 5, null, $this->useragent);
  11021. if ($this->is_feed($feed))
  11022. {
  11023. return $feed;
  11024. }
  11025. }
  11026. $done[] = $href;
  11027. }
  11028. }
  11029. return null;
  11030. }
  11031. function get_links()
  11032. {
  11033. $links = SimplePie_Misc::get_element('a', $this->file->body);
  11034. foreach ($links as $link)
  11035. {
  11036. if (isset($link['attribs']['href']['data']))
  11037. {
  11038. $href = trim($link['attribs']['href']['data']);
  11039. $parsed = SimplePie_Misc::parse_url($href);
  11040. if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme']))
  11041. {
  11042. if ($this->base_location < $link['offset'])
  11043. {
  11044. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base);
  11045. }
  11046. else
  11047. {
  11048. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base);
  11049. }
  11050. $current = SimplePie_Misc::parse_url($this->file->url);
  11051. if ($parsed['authority'] === '' || $parsed['authority'] == $current['authority'])
  11052. {
  11053. $this->local[] = $href;
  11054. }
  11055. else
  11056. {
  11057. $this->elsewhere[] = $href;
  11058. }
  11059. }
  11060. }
  11061. }
  11062. $this->local = array_unique($this->local);
  11063. $this->elsewhere = array_unique($this->elsewhere);
  11064. if (!empty($this->local) || !empty($this->elsewhere))
  11065. {
  11066. return true;
  11067. }
  11068. return null;
  11069. }
  11070. function extension(&$array)
  11071. {
  11072. foreach ($array as $key => $value)
  11073. {
  11074. if ($this->checked_feeds == $this->max_checked_feeds)
  11075. {
  11076. break;
  11077. }
  11078. if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
  11079. {
  11080. $this->checked_feeds++;
  11081. $feed =& new $this->file_class($value, $this->timeout, 5, null, $this->useragent);
  11082. if ($this->is_feed($feed))
  11083. {
  11084. return $feed;
  11085. }
  11086. else
  11087. {
  11088. unset($array[$key]);
  11089. }
  11090. }
  11091. }
  11092. return null;
  11093. }
  11094. function body(&$array)
  11095. {
  11096. foreach ($array as $key => $value)
  11097. {
  11098. if ($this->checked_feeds == $this->max_checked_feeds)
  11099. {
  11100. break;
  11101. }
  11102. if (preg_match('/(rss|rdf|atom|xml)/i', $value))
  11103. {
  11104. $this->checked_feeds++;
  11105. $feed =& new $this->file_class($value, $this->timeout, 5, null, $this->useragent);
  11106. if ($this->is_feed($feed))
  11107. {
  11108. return $feed;
  11109. }
  11110. else
  11111. {
  11112. unset($array[$key]);
  11113. }
  11114. }
  11115. }
  11116. return null;
  11117. }
  11118. }
  11119. class SimplePie_Parser
  11120. {
  11121. var $error_code;
  11122. var $error_string;
  11123. var $current_line;
  11124. var $current_column;
  11125. var $current_byte;
  11126. var $separator = ' ';
  11127. var $feed = false;
  11128. var $namespace = array('');
  11129. var $element = array('');
  11130. var $xml_base = array('');
  11131. var $xml_base_explicit = array(false);
  11132. var $xml_lang = array('');
  11133. var $data = array();
  11134. var $datas = array(array());
  11135. var $current_xhtml_construct = -1;
  11136. var $encoding;
  11137. function parse(&$data, $encoding)
  11138. {
  11139. // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
  11140. if (strtoupper($encoding) == 'US-ASCII')
  11141. {
  11142. $this->encoding = 'UTF-8';
  11143. }
  11144. else
  11145. {
  11146. $this->encoding = $encoding;
  11147. }
  11148. // Strip BOM:
  11149. // UTF-32 Big Endian BOM
  11150. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  11151. {
  11152. $data = substr($data, 4);
  11153. }
  11154. // UTF-32 Little Endian BOM
  11155. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  11156. {
  11157. $data = substr($data, 4);
  11158. }
  11159. // UTF-16 Big Endian BOM
  11160. elseif (substr($data, 0, 2) === "\xFE\xFF")
  11161. {
  11162. $data = substr($data, 2);
  11163. }
  11164. // UTF-16 Little Endian BOM
  11165. elseif (substr($data, 0, 2) === "\xFF\xFE")
  11166. {
  11167. $data = substr($data, 2);
  11168. }
  11169. // UTF-8 BOM
  11170. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  11171. {
  11172. $data = substr($data, 3);
  11173. }
  11174. if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
  11175. {
  11176. $declaration = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5));
  11177. if ($declaration->parse())
  11178. {
  11179. $data = substr($data, $pos + 2);
  11180. $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
  11181. }
  11182. else
  11183. {
  11184. $this->error_string = 'SimplePie bug! Please report this!';
  11185. return false;
  11186. }
  11187. }
  11188. // Work around libxml bug
  11189. $data = str_replace('&lt;', '&#60;', $data);
  11190. $data = str_replace('&gt;', '&#62;', $data);
  11191. $data = str_replace('&amp;', '&#38;', $data);
  11192. $data = str_replace('&apos;', '&#39;', $data);
  11193. $data = str_replace('&quot;', '&#34;', $data);
  11194. $return = true;
  11195. // Create the parser
  11196. $xml = xml_parser_create_ns($this->encoding, $this->separator);
  11197. xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
  11198. xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
  11199. xml_set_object($xml, $this);
  11200. xml_set_character_data_handler($xml, 'cdata');
  11201. xml_set_element_handler($xml, 'tag_open', 'tag_close');
  11202. // Parse!
  11203. if (!xml_parse($xml, $data, true))
  11204. {
  11205. $this->error_code = xml_get_error_code($xml);
  11206. $this->error_string = xml_error_string($this->error_code);
  11207. $return = false;
  11208. }
  11209. $this->current_line = xml_get_current_line_number($xml);
  11210. $this->current_column = xml_get_current_column_number($xml);
  11211. $this->current_byte = xml_get_current_byte_index($xml);
  11212. xml_parser_free($xml);
  11213. return $return;
  11214. }
  11215. function get_error_code()
  11216. {
  11217. return $this->error_code;
  11218. }
  11219. function get_error_string()
  11220. {
  11221. return $this->error_string;
  11222. }
  11223. function get_current_line()
  11224. {
  11225. return $this->current_line;
  11226. }
  11227. function get_current_column()
  11228. {
  11229. return $this->current_column;
  11230. }
  11231. function get_current_byte()
  11232. {
  11233. return $this->current_byte;
  11234. }
  11235. function get_data()
  11236. {
  11237. return $this->data;
  11238. }
  11239. function tag_open($parser, $tag, $attributes)
  11240. {
  11241. if ($this->feed === 0)
  11242. {
  11243. return;
  11244. }
  11245. elseif ($this->feed == false)
  11246. {
  11247. if (in_array($tag, array(
  11248. SIMPLEPIE_NAMESPACE_ATOM_10 . $this->separator . 'feed',
  11249. SIMPLEPIE_NAMESPACE_ATOM_03 . $this->separator . 'feed',
  11250. 'rss',
  11251. SIMPLEPIE_NAMESPACE_RDF . $this->separator . 'RDF'
  11252. )))
  11253. {
  11254. $this->feed = 1;
  11255. }
  11256. }
  11257. else
  11258. {
  11259. $this->feed++;
  11260. }
  11261. list($this->namespace[], $this->element[]) = $this->split_ns($tag);
  11262. $attribs = array();
  11263. foreach ($attributes as $name => $value)
  11264. {
  11265. list($attrib_namespace, $attribute) = $this->split_ns($name);
  11266. $attribs[$attrib_namespace][$attribute] = $value;
  11267. }
  11268. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base']))
  11269. {
  11270. $this->xml_base[] = SimplePie_Misc::absolutize_url($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base));
  11271. $this->xml_base_explicit[] = true;
  11272. }
  11273. else
  11274. {
  11275. $this->xml_base[] = end($this->xml_base);
  11276. $this->xml_base_explicit[] = end($this->xml_base_explicit);
  11277. }
  11278. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang']))
  11279. {
  11280. $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
  11281. }
  11282. else
  11283. {
  11284. $this->xml_lang[] = end($this->xml_lang);
  11285. }
  11286. if ($this->current_xhtml_construct >= 0)
  11287. {
  11288. $this->current_xhtml_construct++;
  11289. if (end($this->namespace) == SIMPLEPIE_NAMESPACE_XHTML)
  11290. {
  11291. $this->data['data'] .= '<' . end($this->element);
  11292. if (isset($attribs['']))
  11293. {
  11294. foreach ($attribs[''] as $name => $value)
  11295. {
  11296. $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
  11297. }
  11298. }
  11299. $this->data['data'] .= '>';
  11300. }
  11301. }
  11302. else
  11303. {
  11304. $this->datas[] =& $this->data;
  11305. $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
  11306. $this->data = array('data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang));
  11307. if ((end($this->namespace) == SIMPLEPIE_NAMESPACE_ATOM_03 && in_array(end($this->element), array('title', 'tagline', 'copyright', 'info', 'summary', 'content')) && isset($attribs['']['mode']) && $attribs['']['mode'] == 'xml')
  11308. || (end($this->namespace) == SIMPLEPIE_NAMESPACE_ATOM_10 && in_array(end($this->element), array('rights', 'subtitle', 'summary', 'info', 'title', 'content')) && isset($attribs['']['type']) && $attribs['']['type'] == 'xhtml'))
  11309. {
  11310. $this->current_xhtml_construct = 0;
  11311. }
  11312. }
  11313. }
  11314. function cdata($parser, $cdata)
  11315. {
  11316. if ($this->current_xhtml_construct >= 0)
  11317. {
  11318. $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
  11319. }
  11320. elseif ($this->feed > 1)
  11321. {
  11322. $this->data['data'] .= $cdata;
  11323. }
  11324. }
  11325. function tag_close($parser, $tag)
  11326. {
  11327. if (!$this->feed)
  11328. {
  11329. return;
  11330. }
  11331. if ($this->current_xhtml_construct >= 0)
  11332. {
  11333. $this->current_xhtml_construct--;
  11334. if (end($this->namespace) == SIMPLEPIE_NAMESPACE_XHTML && !in_array(end($this->element), array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param')))
  11335. {
  11336. $this->data['data'] .= '</' . end($this->element) . '>';
  11337. }
  11338. }
  11339. if ($this->current_xhtml_construct == -1)
  11340. {
  11341. $this->data =& $this->datas[$this->feed];
  11342. array_pop($this->datas);
  11343. }
  11344. array_pop($this->element);
  11345. array_pop($this->namespace);
  11346. array_pop($this->xml_base);
  11347. array_pop($this->xml_base_explicit);
  11348. array_pop($this->xml_lang);
  11349. $this->feed--;
  11350. }
  11351. function split_ns($string)
  11352. {
  11353. static $cache = array();
  11354. if (!isset($cache[$string]))
  11355. {
  11356. if ($pos = strpos($string, $this->separator))
  11357. {
  11358. static $separator_length;
  11359. if (!$separator_length)
  11360. {
  11361. $separator_length = strlen($this->separator);
  11362. }
  11363. $namespace = substr($string, 0, $pos);
  11364. $local_name = substr($string, $pos + $separator_length);
  11365. if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES)
  11366. {
  11367. $namespace = SIMPLEPIE_NAMESPACE_ITUNES;
  11368. }
  11369. // Normalize the Media RSS namespaces
  11370. if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG)
  11371. {
  11372. $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
  11373. }
  11374. $cache[$string] = array($namespace, $local_name);
  11375. }
  11376. else
  11377. {
  11378. $cache[$string] = array('', $string);
  11379. }
  11380. }
  11381. return $cache[$string];
  11382. }
  11383. }
  11384. /**
  11385. * @todo Move to using an actual HTML parser (this will allow tags to be properly stripped, and to switch between HTML and XHTML), this will also make it easier to shorten a string while preserving HTML tags
  11386. */
  11387. class SimplePie_Sanitize
  11388. {
  11389. // Private vars
  11390. var $base;
  11391. // Options
  11392. var $remove_div = true;
  11393. var $image_handler = '';
  11394. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  11395. var $encode_instead_of_strip = false;
  11396. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  11397. var $strip_comments = false;
  11398. var $output_encoding = 'UTF-8';
  11399. var $enable_cache = true;
  11400. var $cache_location = './cache';
  11401. var $cache_name_function = 'md5';
  11402. var $cache_class = 'SimplePie_Cache';
  11403. var $file_class = 'SimplePie_File';
  11404. var $timeout = 10;
  11405. var $useragent = '';
  11406. var $force_fsockopen = false;
  11407. var $replace_url_attributes = array(
  11408. 'a' => 'href',
  11409. 'area' => 'href',
  11410. 'blockquote' => 'cite',
  11411. 'del' => 'cite',
  11412. 'form' => 'action',
  11413. 'img' => array('longdesc', 'src'),
  11414. 'input' => 'src',
  11415. 'ins' => 'cite',
  11416. 'q' => 'cite'
  11417. );
  11418. function remove_div($enable = true)
  11419. {
  11420. $this->remove_div = (bool) $enable;
  11421. }
  11422. function set_image_handler($page = false)
  11423. {
  11424. if ($page)
  11425. {
  11426. $this->image_handler = (string) $page;
  11427. }
  11428. else
  11429. {
  11430. $this->image_handler = false;
  11431. }
  11432. }
  11433. function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
  11434. {
  11435. if (isset($enable_cache))
  11436. {
  11437. $this->enable_cache = (bool) $enable_cache;
  11438. }
  11439. if ($cache_location)
  11440. {
  11441. $this->cache_location = (string) $cache_location;
  11442. }
  11443. if ($cache_name_function)
  11444. {
  11445. $this->cache_name_function = (string) $cache_name_function;
  11446. }
  11447. if ($cache_class)
  11448. {
  11449. $this->cache_class = (string) $cache_class;
  11450. }
  11451. }
  11452. function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
  11453. {
  11454. if ($file_class)
  11455. {
  11456. $this->file_class = (string) $file_class;
  11457. }
  11458. if ($timeout)
  11459. {
  11460. $this->timeout = (string) $timeout;
  11461. }
  11462. if ($useragent)
  11463. {
  11464. $this->useragent = (string) $useragent;
  11465. }
  11466. if ($force_fsockopen)
  11467. {
  11468. $this->force_fsockopen = (string) $force_fsockopen;
  11469. }
  11470. }
  11471. function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
  11472. {
  11473. if ($tags)
  11474. {
  11475. if (is_array($tags))
  11476. {
  11477. $this->strip_htmltags = $tags;
  11478. }
  11479. else
  11480. {
  11481. $this->strip_htmltags = explode(',', $tags);
  11482. }
  11483. }
  11484. else
  11485. {
  11486. $this->strip_htmltags = false;
  11487. }
  11488. }
  11489. function encode_instead_of_strip($encode = false)
  11490. {
  11491. $this->encode_instead_of_strip = (bool) $encode;
  11492. }
  11493. function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
  11494. {
  11495. if ($attribs)
  11496. {
  11497. if (is_array($attribs))
  11498. {
  11499. $this->strip_attributes = $attribs;
  11500. }
  11501. else
  11502. {
  11503. $this->strip_attributes = explode(',', $attribs);
  11504. }
  11505. }
  11506. else
  11507. {
  11508. $this->strip_attributes = false;
  11509. }
  11510. }
  11511. function strip_comments($strip = false)
  11512. {
  11513. $this->strip_comments = (bool) $strip;
  11514. }
  11515. function set_output_encoding($encoding = 'UTF-8')
  11516. {
  11517. $this->output_encoding = (string) $encoding;
  11518. }
  11519. /**
  11520. * Set element/attribute key/value pairs of HTML attributes
  11521. * containing URLs that need to be resolved relative to the feed
  11522. *
  11523. * @access public
  11524. * @since 1.0
  11525. * @param array $element_attribute Element/attribute key/value pairs
  11526. */
  11527. function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite'))
  11528. {
  11529. $this->replace_url_attributes = (array) $element_attribute;
  11530. }
  11531. function sanitize($data, $type, $base = '')
  11532. {
  11533. $data = trim($data);
  11534. if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
  11535. {
  11536. if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
  11537. {
  11538. if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data))
  11539. {
  11540. $type |= SIMPLEPIE_CONSTRUCT_HTML;
  11541. }
  11542. else
  11543. {
  11544. $type |= SIMPLEPIE_CONSTRUCT_TEXT;
  11545. }
  11546. }
  11547. if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
  11548. {
  11549. $data = base64_decode($data);
  11550. }
  11551. if ($type & SIMPLEPIE_CONSTRUCT_XHTML)
  11552. {
  11553. if ($this->remove_div)
  11554. {
  11555. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
  11556. $data = preg_replace('/<\/div>$/', '', $data);
  11557. }
  11558. else
  11559. {
  11560. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
  11561. }
  11562. }
  11563. if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
  11564. {
  11565. // Strip comments
  11566. if ($this->strip_comments)
  11567. {
  11568. $data = SimplePie_Misc::strip_comments($data);
  11569. }
  11570. // Strip out HTML tags and attributes that might cause various security problems.
  11571. // Based on recommendations by Mark Pilgrim at:
  11572. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  11573. if ($this->strip_htmltags)
  11574. {
  11575. foreach ($this->strip_htmltags as $tag)
  11576. {
  11577. $pcre = "/<($tag)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$tag" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\/)?>)/siU';
  11578. while (preg_match($pcre, $data))
  11579. {
  11580. $data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data);
  11581. }
  11582. }
  11583. }
  11584. if ($this->strip_attributes)
  11585. {
  11586. foreach ($this->strip_attributes as $attrib)
  11587. {
  11588. $data = preg_replace('/(<[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*)' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . trim($attrib) . '(?:\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>/', '\1\2\3>', $data);
  11589. }
  11590. }
  11591. // Replace relative URLs
  11592. $this->base = $base;
  11593. foreach ($this->replace_url_attributes as $element => $attributes)
  11594. {
  11595. $data = $this->replace_urls($data, $element, $attributes);
  11596. }
  11597. // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
  11598. if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
  11599. {
  11600. $images = SimplePie_Misc::get_element('img', $data);
  11601. foreach ($images as $img)
  11602. {
  11603. if (isset($img['attribs']['src']['data']))
  11604. {
  11605. $image_url = call_user_func($this->cache_name_function, $img['attribs']['src']['data']);
  11606. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $image_url, 'spi');
  11607. if ($cache->load())
  11608. {
  11609. $img['attribs']['src']['data'] = $this->image_handler . $image_url;
  11610. $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
  11611. }
  11612. else
  11613. {
  11614. $file =& new $this->file_class($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
  11615. $headers = $file->headers;
  11616. if ($file->success && ($file->status_code == 200 || ($file->status_code > 206 && $file->status_code < 300)))
  11617. {
  11618. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  11619. {
  11620. $img['attribs']['src']['data'] = $this->image_handler . $image_url;
  11621. $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
  11622. }
  11623. else
  11624. {
  11625. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  11626. }
  11627. }
  11628. }
  11629. }
  11630. }
  11631. }
  11632. // Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data
  11633. $data = trim($data);
  11634. }
  11635. if ($type & SIMPLEPIE_CONSTRUCT_IRI)
  11636. {
  11637. $data = SimplePie_Misc::absolutize_url($data, $base);
  11638. }
  11639. if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
  11640. {
  11641. $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
  11642. }
  11643. if ($this->output_encoding != 'UTF-8')
  11644. {
  11645. $data = SimplePie_Misc::change_encoding($data, 'UTF-8', $this->output_encoding);
  11646. }
  11647. }
  11648. return $data;
  11649. }
  11650. function replace_urls($data, $tag, $attributes)
  11651. {
  11652. if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
  11653. {
  11654. $elements = SimplePie_Misc::get_element($tag, $data);
  11655. foreach ($elements as $element)
  11656. {
  11657. if (is_array($attributes))
  11658. {
  11659. foreach ($attributes as $attribute)
  11660. {
  11661. if (isset($element['attribs'][$attribute]['data']))
  11662. {
  11663. $element['attribs'][$attribute]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attribute]['data'], $this->base);
  11664. $new_element = SimplePie_Misc::element_implode($element);
  11665. $data = str_replace($element['full'], $new_element, $data);
  11666. $element['full'] = $new_element;
  11667. }
  11668. }
  11669. }
  11670. elseif (isset($element['attribs'][$attributes]['data']))
  11671. {
  11672. $element['attribs'][$attributes]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attributes]['data'], $this->base);
  11673. $data = str_replace($element['full'], SimplePie_Misc::element_implode($element), $data);
  11674. }
  11675. }
  11676. }
  11677. return $data;
  11678. }
  11679. function do_strip_htmltags($match)
  11680. {
  11681. if ($this->encode_instead_of_strip)
  11682. {
  11683. if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  11684. {
  11685. $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
  11686. $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
  11687. return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
  11688. }
  11689. else
  11690. {
  11691. return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
  11692. }
  11693. }
  11694. elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  11695. {
  11696. return $match[4];
  11697. }
  11698. else
  11699. {
  11700. return '';
  11701. }
  11702. }
  11703. }
  11704. ?>