PageRenderTime 62ms CodeModel.GetById 22ms 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

Large files files are truncated, but you can click here to view the full file

  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->g

Large files files are truncated, but you can click here to view the full file