/wp-includes/class-simplepie.php

  1. <?php 
  2. if ( ! class_exists( 'SimplePie', false ) ) : 
  3.  
  4. // Load classes we will need. 
  5. require ABSPATH . WPINC . '/SimplePie/Misc.php'; 
  6. require ABSPATH . WPINC . '/SimplePie/Cache.php'; 
  7. require ABSPATH . WPINC . '/SimplePie/File.php'; 
  8. require ABSPATH . WPINC . '/SimplePie/Sanitize.php'; 
  9. require ABSPATH . WPINC . '/SimplePie/Registry.php'; 
  10. require ABSPATH . WPINC . '/SimplePie/IRI.php'; 
  11. require ABSPATH . WPINC . '/SimplePie/Locator.php'; 
  12. require ABSPATH . WPINC . '/SimplePie/Content/Type/Sniffer.php'; 
  13. require ABSPATH . WPINC . '/SimplePie/XML/Declaration/Parser.php'; 
  14. require ABSPATH . WPINC . '/SimplePie/Parser.php'; 
  15. require ABSPATH . WPINC . '/SimplePie/Item.php'; 
  16. require ABSPATH . WPINC . '/SimplePie/Parse/Date.php'; 
  17. require ABSPATH . WPINC . '/SimplePie/Author.php'; 
  18.  
  19. /** 
  20. * WordPress autoloader for SimplePie. 
  21. * 
  22. * @since 3.5.0 
  23. */ 
  24. function wp_simplepie_autoload( $class ) { 
  25. if ( 0 !== strpos( $class, 'SimplePie_' ) ) 
  26. return; 
  27.  
  28. $file = ABSPATH . WPINC . '/' . str_replace( '_', '/', $class ) . '.php'; 
  29. include( $file ); 
  30.  
  31. /** 
  32. * We autoload classes we may not need. 
  33. */ 
  34. spl_autoload_register( 'wp_simplepie_autoload' ); 
  35.  
  36. /** 
  37. * SimplePie 
  38. * 
  39. * A PHP-Based RSS and Atom Feed Framework. 
  40. * Takes the hard work out of managing a complete RSS/Atom solution. 
  41. * 
  42. * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors 
  43. * All rights reserved. 
  44. * 
  45. * Redistribution and use in source and binary forms, with or without modification, are 
  46. * permitted provided that the following conditions are met: 
  47. * 
  48. * * Redistributions of source code must retain the above copyright notice, this list of 
  49. * conditions and the following disclaimer. 
  50. * 
  51. * * Redistributions in binary form must reproduce the above copyright notice, this list 
  52. * of conditions and the following disclaimer in the documentation and/or other materials 
  53. * provided with the distribution. 
  54. * 
  55. * * Neither the name of the SimplePie Team nor the names of its contributors may be used 
  56. * to endorse or promote products derived from this software without specific prior 
  57. * written permission. 
  58. * 
  59. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 
  60. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
  61. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS 
  62. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  63. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  64. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
  65. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
  66. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
  67. * POSSIBILITY OF SUCH DAMAGE. 
  68. * 
  69. * @package SimplePie 
  70. * @version 1.3.1 
  71. * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue 
  72. * @author Ryan Parman 
  73. * @author Geoffrey Sneddon 
  74. * @author Ryan McCue 
  75. * @link http://simplepie.org/ SimplePie 
  76. * @license http://www.opensource.org/licenses/bsd-license.php BSD License 
  77. */ 
  78.  
  79. /** 
  80. * SimplePie Name 
  81. */ 
  82. define('SIMPLEPIE_NAME', 'SimplePie'); 
  83.  
  84. /** 
  85. * SimplePie Version 
  86. */ 
  87. define('SIMPLEPIE_VERSION', '1.3.1'); 
  88.  
  89. /** 
  90. * SimplePie Build 
  91. * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc) 
  92. */ 
  93. define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::get_build())); 
  94.  
  95. /** 
  96. * SimplePie Website URL 
  97. */ 
  98. define('SIMPLEPIE_URL', 'http://simplepie.org'); 
  99.  
  100. /** 
  101. * SimplePie Useragent 
  102. * @see SimplePie::set_useragent() 
  103. */ 
  104. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD); 
  105.  
  106. /** 
  107. * SimplePie Linkback 
  108. */ 
  109. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>'); 
  110.  
  111. /** 
  112. * No Autodiscovery 
  113. * @see SimplePie::set_autodiscovery_level() 
  114. */ 
  115. define('SIMPLEPIE_LOCATOR_NONE', 0); 
  116.  
  117. /** 
  118. * Feed Link Element Autodiscovery 
  119. * @see SimplePie::set_autodiscovery_level() 
  120. */ 
  121. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1); 
  122.  
  123. /** 
  124. * Local Feed Extension Autodiscovery 
  125. * @see SimplePie::set_autodiscovery_level() 
  126. */ 
  127. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2); 
  128.  
  129. /** 
  130. * Local Feed Body Autodiscovery 
  131. * @see SimplePie::set_autodiscovery_level() 
  132. */ 
  133. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4); 
  134.  
  135. /** 
  136. * Remote Feed Extension Autodiscovery 
  137. * @see SimplePie::set_autodiscovery_level() 
  138. */ 
  139. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8); 
  140.  
  141. /** 
  142. * Remote Feed Body Autodiscovery 
  143. * @see SimplePie::set_autodiscovery_level() 
  144. */ 
  145. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16); 
  146.  
  147. /** 
  148. * All Feed Autodiscovery 
  149. * @see SimplePie::set_autodiscovery_level() 
  150. */ 
  151. define('SIMPLEPIE_LOCATOR_ALL', 31); 
  152.  
  153. /** 
  154. * No known feed type 
  155. */ 
  156. define('SIMPLEPIE_TYPE_NONE', 0); 
  157.  
  158. /** 
  159. * RSS 0.90 
  160. */ 
  161. define('SIMPLEPIE_TYPE_RSS_090', 1); 
  162.  
  163. /** 
  164. * RSS 0.91 (Netscape) 
  165. */ 
  166. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2); 
  167.  
  168. /** 
  169. * RSS 0.91 (Userland) 
  170. */ 
  171. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4); 
  172.  
  173. /** 
  174. * RSS 0.91 (both Netscape and Userland) 
  175. */ 
  176. define('SIMPLEPIE_TYPE_RSS_091', 6); 
  177.  
  178. /** 
  179. * RSS 0.92 
  180. */ 
  181. define('SIMPLEPIE_TYPE_RSS_092', 8); 
  182.  
  183. /** 
  184. * RSS 0.93 
  185. */ 
  186. define('SIMPLEPIE_TYPE_RSS_093', 16); 
  187.  
  188. /** 
  189. * RSS 0.94 
  190. */ 
  191. define('SIMPLEPIE_TYPE_RSS_094', 32); 
  192.  
  193. /** 
  194. * RSS 1.0 
  195. */ 
  196. define('SIMPLEPIE_TYPE_RSS_10', 64); 
  197.  
  198. /** 
  199. * RSS 2.0 
  200. */ 
  201. define('SIMPLEPIE_TYPE_RSS_20', 128); 
  202.  
  203. /** 
  204. * RDF-based RSS 
  205. */ 
  206. define('SIMPLEPIE_TYPE_RSS_RDF', 65); 
  207.  
  208. /** 
  209. * Non-RDF-based RSS (truly intended as syndication format) 
  210. */ 
  211. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190); 
  212.  
  213. /** 
  214. * All RSS 
  215. */ 
  216. define('SIMPLEPIE_TYPE_RSS_ALL', 255); 
  217.  
  218. /** 
  219. * Atom 0.3 
  220. */ 
  221. define('SIMPLEPIE_TYPE_ATOM_03', 256); 
  222.  
  223. /** 
  224. * Atom 1.0 
  225. */ 
  226. define('SIMPLEPIE_TYPE_ATOM_10', 512); 
  227.  
  228. /** 
  229. * All Atom 
  230. */ 
  231. define('SIMPLEPIE_TYPE_ATOM_ALL', 768); 
  232.  
  233. /** 
  234. * All feed types 
  235. */ 
  236. define('SIMPLEPIE_TYPE_ALL', 1023); 
  237.  
  238. /** 
  239. * No construct 
  240. */ 
  241. define('SIMPLEPIE_CONSTRUCT_NONE', 0); 
  242.  
  243. /** 
  244. * Text construct 
  245. */ 
  246. define('SIMPLEPIE_CONSTRUCT_TEXT', 1); 
  247.  
  248. /** 
  249. * HTML construct 
  250. */ 
  251. define('SIMPLEPIE_CONSTRUCT_HTML', 2); 
  252.  
  253. /** 
  254. * XHTML construct 
  255. */ 
  256. define('SIMPLEPIE_CONSTRUCT_XHTML', 4); 
  257.  
  258. /** 
  259. * base64-encoded construct 
  260. */ 
  261. define('SIMPLEPIE_CONSTRUCT_BASE64', 8); 
  262.  
  263. /** 
  264. * IRI construct 
  265. */ 
  266. define('SIMPLEPIE_CONSTRUCT_IRI', 16); 
  267.  
  268. /** 
  269. * A construct that might be HTML 
  270. */ 
  271. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32); 
  272.  
  273. /** 
  274. * All constructs 
  275. */ 
  276. define('SIMPLEPIE_CONSTRUCT_ALL', 63); 
  277.  
  278. /** 
  279. * Don't change case 
  280. */ 
  281. define('SIMPLEPIE_SAME_CASE', 1); 
  282.  
  283. /** 
  284. * Change to lowercase 
  285. */ 
  286. define('SIMPLEPIE_LOWERCASE', 2); 
  287.  
  288. /** 
  289. * Change to uppercase 
  290. */ 
  291. define('SIMPLEPIE_UPPERCASE', 4); 
  292.  
  293. /** 
  294. * PCRE for HTML attributes 
  295. */ 
  296. 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]*'); 
  297.  
  298. /** 
  299. * PCRE for XML attributes 
  300. */ 
  301. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*'); 
  302.  
  303. /** 
  304. * XML Namespace 
  305. */ 
  306. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace'); 
  307.  
  308. /** 
  309. * Atom 1.0 Namespace 
  310. */ 
  311. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom'); 
  312.  
  313. /** 
  314. * Atom 0.3 Namespace 
  315. */ 
  316. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#'); 
  317.  
  318. /** 
  319. * RDF Namespace 
  320. */ 
  321. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); 
  322.  
  323. /** 
  324. * RSS 0.90 Namespace 
  325. */ 
  326. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/'); 
  327.  
  328. /** 
  329. * RSS 1.0 Namespace 
  330. */ 
  331. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/'); 
  332.  
  333. /** 
  334. * RSS 1.0 Content Module Namespace 
  335. */ 
  336. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/'); 
  337.  
  338. /** 
  339. * RSS 2.0 Namespace 
  340. * (Stupid, I know, but I'm certain it will confuse people less with support.) 
  341. */ 
  342. define('SIMPLEPIE_NAMESPACE_RSS_20', ''); 
  343.  
  344. /** 
  345. * DC 1.0 Namespace 
  346. */ 
  347. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/'); 
  348.  
  349. /** 
  350. * DC 1.1 Namespace 
  351. */ 
  352. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/'); 
  353.  
  354. /** 
  355. * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace 
  356. */ 
  357. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#'); 
  358.  
  359. /** 
  360. * GeoRSS Namespace 
  361. */ 
  362. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss'); 
  363.  
  364. /** 
  365. * Media RSS Namespace 
  366. */ 
  367. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/'); 
  368.  
  369. /** 
  370. * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec. 
  371. */ 
  372. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss'); 
  373.  
  374. /** 
  375. * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5. 
  376. */ 
  377. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss'); 
  378.  
  379. /** 
  380. * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace. 
  381. */ 
  382. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/'); 
  383.  
  384. /** 
  385. * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace. 
  386. */ 
  387. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss'); 
  388.  
  389. /** 
  390. * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL. 
  391. */ 
  392. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/'); 
  393.  
  394. /** 
  395. * iTunes RSS Namespace 
  396. */ 
  397. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd'); 
  398.  
  399. /** 
  400. * XHTML Namespace 
  401. */ 
  402. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml'); 
  403.  
  404. /** 
  405. * IANA Link Relations Registry 
  406. */ 
  407. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/'); 
  408.  
  409. /** 
  410. * No file source 
  411. */ 
  412. define('SIMPLEPIE_FILE_SOURCE_NONE', 0); 
  413.  
  414. /** 
  415. * Remote file source 
  416. */ 
  417. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1); 
  418.  
  419. /** 
  420. * Local file source 
  421. */ 
  422. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2); 
  423.  
  424. /** 
  425. * fsockopen() file source 
  426. */ 
  427. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4); 
  428.  
  429. /** 
  430. * cURL file source 
  431. */ 
  432. define('SIMPLEPIE_FILE_SOURCE_CURL', 8); 
  433.  
  434. /** 
  435. * file_get_contents() file source 
  436. */ 
  437. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16); 
  438.  
  439.  
  440.  
  441. /** 
  442. * SimplePie 
  443. * 
  444. * @package SimplePie 
  445. * @subpackage API 
  446. */ 
  447. class SimplePie 
  448. /** 
  449. * @var array Raw data 
  450. * @access private 
  451. */ 
  452. public $data = array(); 
  453.  
  454. /** 
  455. * @var mixed Error string 
  456. * @access private 
  457. */ 
  458. public $error; 
  459.  
  460. /** 
  461. * @var object Instance of SimplePie_Sanitize (or other class) 
  462. * @see SimplePie::set_sanitize_class() 
  463. * @access private 
  464. */ 
  465. public $sanitize; 
  466.  
  467. /** 
  468. * @var string SimplePie Useragent 
  469. * @see SimplePie::set_useragent() 
  470. * @access private 
  471. */ 
  472. public $useragent = SIMPLEPIE_USERAGENT; 
  473.  
  474. /** 
  475. * @var string Feed URL 
  476. * @see SimplePie::set_feed_url() 
  477. * @access private 
  478. */ 
  479. public $feed_url; 
  480.  
  481. /** 
  482. * @var object Instance of SimplePie_File to use as a feed 
  483. * @see SimplePie::set_file() 
  484. * @access private 
  485. */ 
  486. public $file; 
  487.  
  488. /** 
  489. * @var string Raw feed data 
  490. * @see SimplePie::set_raw_data() 
  491. * @access private 
  492. */ 
  493. public $raw_data; 
  494.  
  495. /** 
  496. * @var int Timeout for fetching remote files 
  497. * @see SimplePie::set_timeout() 
  498. * @access private 
  499. */ 
  500. public $timeout = 10; 
  501.  
  502. /** 
  503. * @var bool Forces fsockopen() to be used for remote files instead 
  504. * of cURL, even if a new enough version is installed 
  505. * @see SimplePie::force_fsockopen() 
  506. * @access private 
  507. */ 
  508. public $force_fsockopen = false; 
  509.  
  510. /** 
  511. * @var bool Force the given data/URL to be treated as a feed no matter what 
  512. * it appears like 
  513. * @see SimplePie::force_feed() 
  514. * @access private 
  515. */ 
  516. public $force_feed = false; 
  517.  
  518. /** 
  519. * @var bool Enable/Disable Caching 
  520. * @see SimplePie::enable_cache() 
  521. * @access private 
  522. */ 
  523. public $cache = true; 
  524.  
  525. /** 
  526. * @var int Cache duration (in seconds) 
  527. * @see SimplePie::set_cache_duration() 
  528. * @access private 
  529. */ 
  530. public $cache_duration = 3600; 
  531.  
  532. /** 
  533. * @var int Auto-discovery cache duration (in seconds) 
  534. * @see SimplePie::set_autodiscovery_cache_duration() 
  535. * @access private 
  536. */ 
  537. public $autodiscovery_cache_duration = 604800; // 7 Days. 
  538.  
  539. /** 
  540. * @var string Cache location (relative to executing script) 
  541. * @see SimplePie::set_cache_location() 
  542. * @access private 
  543. */ 
  544. public $cache_location = './cache'; 
  545.  
  546. /** 
  547. * @var string Function that creates the cache filename 
  548. * @see SimplePie::set_cache_name_function() 
  549. * @access private 
  550. */ 
  551. public $cache_name_function = 'md5'; 
  552.  
  553. /** 
  554. * @var bool Reorder feed by date descending 
  555. * @see SimplePie::enable_order_by_date() 
  556. * @access private 
  557. */ 
  558. public $order_by_date = true; 
  559.  
  560. /** 
  561. * @var mixed Force input encoding to be set to the follow value 
  562. * (false, or anything type-cast to false, disables this feature) 
  563. * @see SimplePie::set_input_encoding() 
  564. * @access private 
  565. */ 
  566. public $input_encoding = false; 
  567.  
  568. /** 
  569. * @var int Feed Autodiscovery Level 
  570. * @see SimplePie::set_autodiscovery_level() 
  571. * @access private 
  572. */ 
  573. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL; 
  574.  
  575. /** 
  576. * Class registry object 
  577. * 
  578. * @var SimplePie_Registry 
  579. */ 
  580. public $registry; 
  581.  
  582. /** 
  583. * @var int Maximum number of feeds to check with autodiscovery 
  584. * @see SimplePie::set_max_checked_feeds() 
  585. * @access private 
  586. */ 
  587. public $max_checked_feeds = 10; 
  588.  
  589. /** 
  590. * @var array All the feeds found during the autodiscovery process 
  591. * @see SimplePie::get_all_discovered_feeds() 
  592. * @access private 
  593. */ 
  594. public $all_discovered_feeds = array(); 
  595.  
  596. /** 
  597. * @var string Web-accessible path to the handler_image.php file. 
  598. * @see SimplePie::set_image_handler() 
  599. * @access private 
  600. */ 
  601. public $image_handler = ''; 
  602.  
  603. /** 
  604. * @var array Stores the URLs when multiple feeds are being initialized. 
  605. * @see SimplePie::set_feed_url() 
  606. * @access private 
  607. */ 
  608. public $multifeed_url = array(); 
  609.  
  610. /** 
  611. * @var array Stores SimplePie objects when multiple feeds initialized. 
  612. * @access private 
  613. */ 
  614. public $multifeed_objects = array(); 
  615.  
  616. /** 
  617. * @var array Stores the get_object_vars() array for use with multifeeds. 
  618. * @see SimplePie::set_feed_url() 
  619. * @access private 
  620. */ 
  621. public $config_settings = null; 
  622.  
  623. /** 
  624. * @var integer Stores the number of items to return per-feed with multifeeds. 
  625. * @see SimplePie::set_item_limit() 
  626. * @access private 
  627. */ 
  628. public $item_limit = 0; 
  629.  
  630. /** 
  631. * @var array Stores the default attributes to be stripped by strip_attributes(). 
  632. * @see SimplePie::strip_attributes() 
  633. * @access private 
  634. */ 
  635. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'); 
  636.  
  637. /** 
  638. * @var array Stores the default tags to be stripped by strip_htmltags(). 
  639. * @see SimplePie::strip_htmltags() 
  640. * @access private 
  641. */ 
  642. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); 
  643.  
  644. /** 
  645. * The SimplePie class contains feed level data and options 
  646. * 
  647. * To use SimplePie, create the SimplePie object with no parameters. You can 
  648. * then set configuration options using the provided methods. After setting 
  649. * them, you must initialise the feed using $feed->init(). At that point the 
  650. * object's methods and properties will be available to you. 
  651. * 
  652. * Previously, it was possible to pass in the feed URL along with cache 
  653. * options directly into the constructor. This has been removed as of 1.3 as 
  654. * it caused a lot of confusion. 
  655. * 
  656. * @since 1.0 Preview Release 
  657. */ 
  658. public function __construct() 
  659. if (version_compare(PHP_VERSION, '5.2', '<')) 
  660. trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.'); 
  661. die(); 
  662.  
  663. // Other objects, instances created here so we can set options on them 
  664. $this->sanitize = new SimplePie_Sanitize(); 
  665. $this->registry = new SimplePie_Registry(); 
  666.  
  667. if (func_num_args() > 0) 
  668. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  669. trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.', $level); 
  670.  
  671. $args = func_get_args(); 
  672. switch (count($args)) { 
  673. case 3: 
  674. $this->set_cache_duration($args[2]); 
  675. case 2: 
  676. $this->set_cache_location($args[1]); 
  677. case 1: 
  678. $this->set_feed_url($args[0]); 
  679. $this->init(); 
  680.  
  681. /** 
  682. * Used for converting object to a string 
  683. */ 
  684. public function __toString() 
  685. return md5(serialize($this->data)); 
  686.  
  687. /** 
  688. * Remove items that link back to this before destroying this object 
  689. */ 
  690. public function __destruct() 
  691. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) 
  692. if (!empty($this->data['items'])) 
  693. foreach ($this->data['items'] as $item) 
  694. $item->__destruct(); 
  695. unset($item, $this->data['items']); 
  696. if (!empty($this->data['ordered_items'])) 
  697. foreach ($this->data['ordered_items'] as $item) 
  698. $item->__destruct(); 
  699. unset($item, $this->data['ordered_items']); 
  700.  
  701. /** 
  702. * Force the given data/URL to be treated as a feed 
  703. * 
  704. * This tells SimplePie to ignore the content-type provided by the server. 
  705. * Be careful when using this option, as it will also disable autodiscovery. 
  706. * 
  707. * @since 1.1 
  708. * @param bool $enable Force the given data/URL to be treated as a feed 
  709. */ 
  710. public function force_feed($enable = false) 
  711. $this->force_feed = (bool) $enable; 
  712.  
  713. /** 
  714. * Set the URL of the feed you want to parse 
  715. * 
  716. * This allows you to enter the URL of the feed you want to parse, or the 
  717. * website you want to try to use auto-discovery on. This takes priority 
  718. * over any set raw data. 
  719. * 
  720. * You can set multiple feeds to mash together by passing an array instead 
  721. * of a string for the $url. Remember that with each additional feed comes 
  722. * additional processing and resources. 
  723. * 
  724. * @since 1.0 Preview Release 
  725. * @see set_raw_data() 
  726. * @param string|array $url This is the URL (or array of URLs) that you want to parse. 
  727. */ 
  728. public function set_feed_url($url) 
  729. $this->multifeed_url = array(); 
  730. if (is_array($url)) 
  731. foreach ($url as $value) 
  732. $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1)); 
  733. else 
  734. $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1)); 
  735.  
  736. /** 
  737. * Set an instance of {@see SimplePie_File} to use as a feed 
  738. * 
  739. * @param SimplePie_File &$file 
  740. * @return bool True on success, false on failure 
  741. */ 
  742. public function set_file(&$file) 
  743. if ($file instanceof SimplePie_File) 
  744. $this->feed_url = $file->url; 
  745. $this->file =& $file; 
  746. return true; 
  747. return false; 
  748.  
  749. /** 
  750. * Set the raw XML data to parse 
  751. * 
  752. * Allows you to use a string of RSS/Atom data instead of a remote feed. 
  753. * 
  754. * If you have a feed available as a string in PHP, you can tell SimplePie 
  755. * to parse that data string instead of a remote feed. Any set feed URL 
  756. * takes precedence. 
  757. * 
  758. * @since 1.0 Beta 3 
  759. * @param string $data RSS or Atom data as a string. 
  760. * @see set_feed_url() 
  761. */ 
  762. public function set_raw_data($data) 
  763. $this->raw_data = $data; 
  764.  
  765. /** 
  766. * Set the the default timeout for fetching remote feeds 
  767. * 
  768. * This allows you to change the maximum time the feed's server to respond 
  769. * and send the feed back. 
  770. * 
  771. * @since 1.0 Beta 3 
  772. * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed. 
  773. */ 
  774. public function set_timeout($timeout = 10) 
  775. $this->timeout = (int) $timeout; 
  776.  
  777. /** 
  778. * Force SimplePie to use fsockopen() instead of cURL 
  779. * 
  780. * @since 1.0 Beta 3 
  781. * @param bool $enable Force fsockopen() to be used 
  782. */ 
  783. public function force_fsockopen($enable = false) 
  784. $this->force_fsockopen = (bool) $enable; 
  785.  
  786. /** 
  787. * Enable/disable caching in SimplePie. 
  788. * 
  789. * This option allows you to disable caching all-together in SimplePie. 
  790. * However, disabling the cache can lead to longer load times. 
  791. * 
  792. * @since 1.0 Preview Release 
  793. * @param bool $enable Enable caching 
  794. */ 
  795. public function enable_cache($enable = true) 
  796. $this->cache = (bool) $enable; 
  797.  
  798. /** 
  799. * Set the length of time (in seconds) that the contents of a feed will be 
  800. * cached 
  801. * 
  802. * @param int $seconds The feed content cache duration 
  803. */ 
  804. public function set_cache_duration($seconds = 3600) 
  805. $this->cache_duration = (int) $seconds; 
  806.  
  807. /** 
  808. * Set the length of time (in seconds) that the autodiscovered feed URL will 
  809. * be cached 
  810. * 
  811. * @param int $seconds The autodiscovered feed URL cache duration. 
  812. */ 
  813. public function set_autodiscovery_cache_duration($seconds = 604800) 
  814. $this->autodiscovery_cache_duration = (int) $seconds; 
  815.  
  816. /** 
  817. * Set the file system location where the cached files should be stored 
  818. * 
  819. * @param string $location The file system location. 
  820. */ 
  821. public function set_cache_location($location = './cache') 
  822. $this->cache_location = (string) $location; 
  823.  
  824. /** 
  825. * Set whether feed items should be sorted into reverse chronological order 
  826. * 
  827. * @param bool $enable Sort as reverse chronological order. 
  828. */ 
  829. public function enable_order_by_date($enable = true) 
  830. $this->order_by_date = (bool) $enable; 
  831.  
  832. /** 
  833. * Set the character encoding used to parse the feed 
  834. * 
  835. * This overrides the encoding reported by the feed, however it will fall 
  836. * back to the normal encoding detection if the override fails 
  837. * 
  838. * @param string $encoding Character encoding 
  839. */ 
  840. public function set_input_encoding($encoding = false) 
  841. if ($encoding) 
  842. $this->input_encoding = (string) $encoding; 
  843. else 
  844. $this->input_encoding = false; 
  845.  
  846. /** 
  847. * Set how much feed autodiscovery to do 
  848. * 
  849. * @see SIMPLEPIE_LOCATOR_NONE 
  850. * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY 
  851. * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION 
  852. * @see SIMPLEPIE_LOCATOR_LOCAL_BODY 
  853. * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION 
  854. * @see SIMPLEPIE_LOCATOR_REMOTE_BODY 
  855. * @see SIMPLEPIE_LOCATOR_ALL 
  856. * @param int $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator) 
  857. */ 
  858. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL) 
  859. $this->autodiscovery = (int) $level; 
  860.  
  861. /** 
  862. * Get the class registry 
  863. * 
  864. * Use this to override SimplePie's default classes 
  865. * @see SimplePie_Registry 
  866. * @return SimplePie_Registry 
  867. */ 
  868. public function &get_registry() 
  869. return $this->registry; 
  870.  
  871. /**#@+ 
  872. * Useful when you are overloading or extending SimplePie's default classes. 
  873. * 
  874. * @deprecated Use {@see get_registry()} instead 
  875. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 
  876. * @param string $class Name of custom class 
  877. * @return boolean True on success, false otherwise 
  878. */ 
  879. /** 
  880. * Set which class SimplePie uses for caching 
  881. */ 
  882. public function set_cache_class($class = 'SimplePie_Cache') 
  883. return $this->registry->register('Cache', $class, true); 
  884.  
  885. /** 
  886. * Set which class SimplePie uses for auto-discovery 
  887. */ 
  888. public function set_locator_class($class = 'SimplePie_Locator') 
  889. return $this->registry->register('Locator', $class, true); 
  890.  
  891. /** 
  892. * Set which class SimplePie uses for XML parsing 
  893. */ 
  894. public function set_parser_class($class = 'SimplePie_Parser') 
  895. return $this->registry->register('Parser', $class, true); 
  896.  
  897. /** 
  898. * Set which class SimplePie uses for remote file fetching 
  899. */ 
  900. public function set_file_class($class = 'SimplePie_File') 
  901. return $this->registry->register('File', $class, true); 
  902.  
  903. /** 
  904. * Set which class SimplePie uses for data sanitization 
  905. */ 
  906. public function set_sanitize_class($class = 'SimplePie_Sanitize') 
  907. return $this->registry->register('Sanitize', $class, true); 
  908.  
  909. /** 
  910. * Set which class SimplePie uses for handling feed items 
  911. */ 
  912. public function set_item_class($class = 'SimplePie_Item') 
  913. return $this->registry->register('Item', $class, true); 
  914.  
  915. /** 
  916. * Set which class SimplePie uses for handling author data 
  917. */ 
  918. public function set_author_class($class = 'SimplePie_Author') 
  919. return $this->registry->register('Author', $class, true); 
  920.  
  921. /** 
  922. * Set which class SimplePie uses for handling category data 
  923. */ 
  924. public function set_category_class($class = 'SimplePie_Category') 
  925. return $this->registry->register('Category', $class, true); 
  926.  
  927. /** 
  928. * Set which class SimplePie uses for feed enclosures 
  929. */ 
  930. public function set_enclosure_class($class = 'SimplePie_Enclosure') 
  931. return $this->registry->register('Enclosure', $class, true); 
  932.  
  933. /** 
  934. * Set which class SimplePie uses for `<media:text>` captions 
  935. */ 
  936. public function set_caption_class($class = 'SimplePie_Caption') 
  937. return $this->registry->register('Caption', $class, true); 
  938.  
  939. /** 
  940. * Set which class SimplePie uses for `<media:copyright>` 
  941. */ 
  942. public function set_copyright_class($class = 'SimplePie_Copyright') 
  943. return $this->registry->register('Copyright', $class, true); 
  944.  
  945. /** 
  946. * Set which class SimplePie uses for `<media:credit>` 
  947. */ 
  948. public function set_credit_class($class = 'SimplePie_Credit') 
  949. return $this->registry->register('Credit', $class, true); 
  950.  
  951. /** 
  952. * Set which class SimplePie uses for `<media:rating>` 
  953. */ 
  954. public function set_rating_class($class = 'SimplePie_Rating') 
  955. return $this->registry->register('Rating', $class, true); 
  956.  
  957. /** 
  958. * Set which class SimplePie uses for `<media:restriction>` 
  959. */ 
  960. public function set_restriction_class($class = 'SimplePie_Restriction') 
  961. return $this->registry->register('Restriction', $class, true); 
  962.  
  963. /** 
  964. * Set which class SimplePie uses for content-type sniffing 
  965. */ 
  966. public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer') 
  967. return $this->registry->register('Content_Type_Sniffer', $class, true); 
  968.  
  969. /** 
  970. * Set which class SimplePie uses item sources 
  971. */ 
  972. public function set_source_class($class = 'SimplePie_Source') 
  973. return $this->registry->register('Source', $class, true); 
  974. /**#@-*/ 
  975.  
  976. /** 
  977. * Set the user agent string 
  978. * 
  979. * @param string $ua New user agent string. 
  980. */ 
  981. public function set_useragent($ua = SIMPLEPIE_USERAGENT) 
  982. $this->useragent = (string) $ua; 
  983.  
  984. /** 
  985. * Set callback function to create cache filename with 
  986. * 
  987. * @param mixed $function Callback function 
  988. */ 
  989. public function set_cache_name_function($function = 'md5') 
  990. if (is_callable($function)) 
  991. $this->cache_name_function = $function; 
  992.  
  993. /** 
  994. * Set options to make SP as fast as possible 
  995. * 
  996. * Forgoes a substantial amount of data sanitization in favor of speed. This 
  997. * turns SimplePie into a dumb parser of feeds. 
  998. * 
  999. * @param bool $set Whether to set them or not 
  1000. */ 
  1001. public function set_stupidly_fast($set = false) 
  1002. if ($set) 
  1003. $this->enable_order_by_date(false); 
  1004. $this->remove_div(false); 
  1005. $this->strip_comments(false); 
  1006. $this->strip_htmltags(false); 
  1007. $this->strip_attributes(false); 
  1008. $this->set_image_handler(false); 
  1009.  
  1010. /** 
  1011. * Set maximum number of feeds to check with autodiscovery 
  1012. * 
  1013. * @param int $max Maximum number of feeds to check 
  1014. */ 
  1015. public function set_max_checked_feeds($max = 10) 
  1016. $this->max_checked_feeds = (int) $max; 
  1017.  
  1018. public function remove_div($enable = true) 
  1019. $this->sanitize->remove_div($enable); 
  1020.  
  1021. public function strip_htmltags($tags = '', $encode = null) 
  1022. if ($tags === '') 
  1023. $tags = $this->strip_htmltags; 
  1024. $this->sanitize->strip_htmltags($tags); 
  1025. if ($encode !== null) 
  1026. $this->sanitize->encode_instead_of_strip($tags); 
  1027.  
  1028. public function encode_instead_of_strip($enable = true) 
  1029. $this->sanitize->encode_instead_of_strip($enable); 
  1030.  
  1031. public function strip_attributes($attribs = '') 
  1032. if ($attribs === '') 
  1033. $attribs = $this->strip_attributes; 
  1034. $this->sanitize->strip_attributes($attribs); 
  1035.  
  1036. /** 
  1037. * Set the output encoding 
  1038. * 
  1039. * Allows you to override SimplePie's output to match that of your webpage. 
  1040. * This is useful for times when your webpages are not being served as 
  1041. * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and 
  1042. * is similar to {@see set_input_encoding()}. 
  1043. * 
  1044. * It should be noted, however, that not all character encodings can support 
  1045. * all characters. If your page is being served as ISO-8859-1 and you try 
  1046. * to display a Japanese feed, you'll likely see garbled characters. 
  1047. * Because of this, it is highly recommended to ensure that your webpages 
  1048. * are served as UTF-8. 
  1049. * 
  1050. * The number of supported character encodings depends on whether your web 
  1051. * host supports {@link http://php.net/mbstring mbstring},  
  1052. * {@link http://php.net/iconv iconv}, or both. See 
  1053. * {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for 
  1054. * more information. 
  1055. * 
  1056. * @param string $encoding 
  1057. */ 
  1058. public function set_output_encoding($encoding = 'UTF-8') 
  1059. $this->sanitize->set_output_encoding($encoding); 
  1060.  
  1061. public function strip_comments($strip = false) 
  1062. $this->sanitize->strip_comments($strip); 
  1063.  
  1064. /** 
  1065. * Set element/attribute key/value pairs of HTML attributes 
  1066. * containing URLs that need to be resolved relative to the feed 
  1067. * 
  1068. * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,  
  1069. * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,  
  1070. * |q|@cite 
  1071. * 
  1072. * @since 1.0 
  1073. * @param array|null $element_attribute Element/attribute key/value pairs, null for default 
  1074. */ 
  1075. public function set_url_replacements($element_attribute = null) 
  1076. $this->sanitize->set_url_replacements($element_attribute); 
  1077.  
  1078. /** 
  1079. * Set the handler to enable the display of cached images. 
  1080. * 
  1081. * @param str $page Web-accessible path to the handler_image.php file. 
  1082. * @param str $qs The query string that the value should be passed to. 
  1083. */ 
  1084. public function set_image_handler($page = false, $qs = 'i') 
  1085. if ($page !== false) 
  1086. $this->sanitize->set_image_handler($page . '?' . $qs . '='); 
  1087. else 
  1088. $this->image_handler = ''; 
  1089.  
  1090. /** 
  1091. * Set the limit for items returned per-feed with multifeeds 
  1092. * 
  1093. * @param integer $limit The maximum number of items to return. 
  1094. */ 
  1095. public function set_item_limit($limit = 0) 
  1096. $this->item_limit = (int) $limit; 
  1097.  
  1098. /** 
  1099. * Initialize the feed object 
  1100. * 
  1101. * This is what makes everything happen. Period. This is where all of the 
  1102. * configuration options get processed, feeds are fetched, cached, and 
  1103. * parsed, and all of that other good stuff. 
  1104. * 
  1105. * @return boolean True if successful, false otherwise 
  1106. */ 
  1107. public function init() 
  1108. // Check absolute bare minimum requirements. 
  1109. if (!extension_loaded('xml') || !extension_loaded('pcre')) 
  1110. return false; 
  1111. // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader. 
  1112. elseif (!extension_loaded('xmlreader')) 
  1113. static $xml_is_sane = null; 
  1114. if ($xml_is_sane === null) 
  1115. $parser_check = xml_parser_create(); 
  1116. xml_parse_into_struct($parser_check, '<foo>&</foo>', $values); 
  1117. xml_parser_free($parser_check); 
  1118. $xml_is_sane = isset($values[0]['value']); 
  1119. if (!$xml_is_sane) 
  1120. return false; 
  1121.  
  1122. if (method_exists($this->sanitize, 'set_registry')) 
  1123. $this->sanitize->set_registry($this->registry); 
  1124.  
  1125. // Pass whatever was set with config options over to the sanitizer. 
  1126. // Pass the classes in for legacy support; new classes should use the registry instead 
  1127. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache')); 
  1128. $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen); 
  1129.  
  1130. if (!empty($this->multifeed_url)) 
  1131. $i = 0; 
  1132. $success = 0; 
  1133. $this->multifeed_objects = array(); 
  1134. $this->error = array(); 
  1135. foreach ($this->multifeed_url as $url) 
  1136. $this->multifeed_objects[$i] = clone $this; 
  1137. $this->multifeed_objects[$i]->set_feed_url($url); 
  1138. $single_success = $this->multifeed_objects[$i]->init(); 
  1139. $success |= $single_success; 
  1140. if (!$single_success) 
  1141. $this->error[$i] = $this->multifeed_objects[$i]->error(); 
  1142. $i++; 
  1143. return (bool) $success; 
  1144. elseif ($this->feed_url === null && $this->raw_data === null) 
  1145. return false; 
  1146.  
  1147. $this->error = null; 
  1148. $this->data = array(); 
  1149. $this->multifeed_objects = array(); 
  1150. $cache = false; 
  1151.  
  1152. if ($this->feed_url !== null) 
  1153. $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url)); 
  1154.  
  1155. // Decide whether to enable caching 
  1156. if ($this->cache && $parsed_feed_url['scheme'] !== '') 
  1157. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc')); 
  1158.  
  1159. // Fetch the data via SimplePie_File into $this->raw_data 
  1160. if (($fetched = $this->fetch_data($cache)) === true) 
  1161. return true; 
  1162. elseif ($fetched === false) { 
  1163. return false; 
  1164.  
  1165. list($headers, $sniffed) = $fetched; 
  1166.  
  1167. // Set up array of possible encodings 
  1168. $encodings = array(); 
  1169.  
  1170. // First check to see if input has been overridden. 
  1171. if ($this->input_encoding !== false) 
  1172. $encodings[] = $this->input_encoding; 
  1173.  
  1174. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity'); 
  1175. $text_types = array('text/xml', 'text/xml-external-parsed-entity'); 
  1176.  
  1177. // RFC 3023 (only applies to sniffed content) 
  1178. if (isset($sniffed)) 
  1179. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') 
  1180. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) 
  1181. $encodings[] = strtoupper($charset[1]); 
  1182. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry))); 
  1183. $encodings[] = 'UTF-8'; 
  1184. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') 
  1185. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) 
  1186. $encodings[] = $charset[1]; 
  1187. $encodings[] = 'US-ASCII'; 
  1188. // Text MIME-type default 
  1189. elseif (substr($sniffed, 0, 5) === 'text/') 
  1190. $encodings[] = 'US-ASCII'; 
  1191.  
  1192. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1 
  1193. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry))); 
  1194. $encodings[] = 'UTF-8'; 
  1195. $encodings[] = 'ISO-8859-1'; 
  1196.  
  1197. // There's no point in trying an encoding twice 
  1198. $encodings = array_unique($encodings); 
  1199.  
  1200. // Loop through each possible encoding, till we return something, or run out of possibilities 
  1201. foreach ($encodings as $encoding) 
  1202. // Change the encoding to UTF-8 (as we always use UTF-8 internally) 
  1203. if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8'))) 
  1204. // Create new parser 
  1205. $parser = $this->registry->create('Parser'); 
  1206.  
  1207. // If it's parsed fine 
  1208. if ($parser->parse($utf8_data, 'UTF-8')) 
  1209. $this->data = $parser->get_data(); 
  1210. if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) 
  1211. $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed."; 
  1212. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 
  1213. return false; 
  1214.  
  1215. if (isset($headers)) 
  1216. $this->data['headers'] = $headers; 
  1217. $this->data['build'] = SIMPLEPIE_BUILD; 
  1218.  
  1219. // Cache the file if caching is enabled 
  1220. if ($cache && !$cache->save($this)) 
  1221. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); 
  1222. return true; 
  1223.  
  1224. if (isset($parser)) 
  1225. // We have an error, just set SimplePie_Misc::error to it and quit 
  1226. $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column()); 
  1227. else 
  1228. $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.'; 
  1229.  
  1230. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 
  1231.  
  1232. return false; 
  1233.  
  1234. /** 
  1235. * Fetch the data via SimplePie_File 
  1236. * 
  1237. * If the data is already cached, attempt to fetch it from there instead 
  1238. * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache 
  1239. * @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type 
  1240. */ 
  1241. protected function fetch_data(&$cache) 
  1242. // If it's enabled, use the cache 
  1243. if ($cache) 
  1244. // Load the Cache 
  1245. $this->data = $cache->load(); 
  1246. if (!empty($this->data)) 
  1247. // If the cache is for an outdated build of SimplePie 
  1248. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) 
  1249. $cache->unlink(); 
  1250. $this->data = array(); 
  1251. // If we've hit a collision just rerun it with caching disabled 
  1252. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url) 
  1253. $cache = false; 
  1254. $this->data = array(); 
  1255. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL. 
  1256. elseif (isset($this->data['feed_url'])) 
  1257. // If the autodiscovery cache is still valid use it. 
  1258. if ($cache->mtime() + $this->autodiscovery_cache_duration > time()) 
  1259. // Do not need to do feed autodiscovery yet. 
  1260. if ($this->data['feed_url'] !== $this->data['url']) 
  1261. $this->set_feed_url($this->data['feed_url']); 
  1262. return $this->init(); 
  1263.  
  1264. $cache->unlink(); 
  1265. $this->data = array(); 
  1266. // Check if the cache has been updated 
  1267. elseif ($cache->mtime() + $this->cache_duration < time()) 
  1268. // If we have last-modified and/or etag set 
  1269. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) 
  1270. $headers = array( 
  1271. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',  
  1272. ); 
  1273. if (isset($this->data['headers']['last-modified'])) 
  1274. { 
  1275. $headers['if-modified-since'] = $this->data['headers']['last-modified']; 
  1276. } 
  1277. if (isset($this->data['headers']['etag'])) 
  1278. { 
  1279. $headers['if-none-match'] = $this->data['headers']['etag']; 
  1280. } 
  1281.   
  1282. $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen)); 
  1283.   
  1284. if ($file->success) 
  1285. { 
  1286. if ($file->status_code === 304) 
  1287. { 
  1288. $cache->touch(); 
  1289. return true; 
  1290. } 
  1291. } 
  1292. else 
  1293. { 
  1294. unset($file); 
  1295. } 
  1296. } 
  1297. } 
  1298. // If the cache is still valid, just return true 
  1299. else 
  1300. { 
  1301. $this->raw_data = false; 
  1302. return true; 
  1303. } 
  1304. } 
  1305. // If the cache is empty, delete it 
  1306. else 
  1307. { 
  1308. $cache->unlink(); 
  1309. $this->data = array(); 
  1310. } 
  1311. } 
  1312. // 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. 
  1313. if (!isset($file)) 
  1314. { 
  1315. if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url) 
  1316. { 
  1317. $file =& $this->file; 
  1318. } 
  1319. else 
  1320. { 
  1321. $headers = array( 
  1322. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',  
  1323. ); 
  1324. $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen)); 
  1325. // If the file connection has an error, set SimplePie::error to that and quit 
  1326. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) 
  1327. $this->error = $file->error; 
  1328. return !empty($this->data); 
  1329.  
  1330. if (!$this->force_feed) 
  1331. // Check if the supplied URL is a feed, if it isn't, look for it. 
  1332. $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds)); 
  1333.  
  1334. if (!$locate->is_feed($file)) 
  1335. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched 
  1336. unset($file); 
  1337. try 
  1338. if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) 
  1339. $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed."; 
  1340. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 
  1341. return false; 
  1342. catch (SimplePie_Exception $e) 
  1343. // This is usually because DOMDocument doesn't exist 
  1344. $this->error = $e->getMessage(); 
  1345. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine())); 
  1346. return false; 
  1347. if ($cache) 
  1348. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD); 
  1349. if (!$cache->save($this)) 
  1350. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); 
  1351. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc')); 
  1352. $this->feed_url = $file->url; 
  1353. $locate = null; 
  1354.  
  1355. $this->raw_data = $file->body; 
  1356.  
  1357. $headers = $file->headers; 
  1358. $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file)); 
  1359. $sniffed = $sniffer->get_type(); 
  1360.  
  1361. return array($headers, $sniffed); 
  1362.  
  1363. /** 
  1364. * Get the error message for the occurred error. 
  1365. * 
  1366. * @return string|array Error message, or array of messages for multifeeds 
  1367. */ 
  1368. public function error() 
  1369. return $this->error; 
  1370.  
  1371. /** 
  1372. * Get the raw XML 
  1373. * 
  1374. * This is the same as the old `$feed->enable_xml_dump(true)`, but returns 
  1375. * the data instead of printing it. 
  1376. * 
  1377. * @return string|boolean Raw XML data, false if the cache is used 
  1378. */ 
  1379. public function get_raw_data() 
  1380. return $this->raw_data; 
  1381.  
  1382. /** 
  1383. * Get the character encoding used for output 
  1384. * 
  1385. * @since Preview Release 
  1386. * @return string 
  1387. */ 
  1388. public function get_encoding() 
  1389. return $this->sanitize->output_encoding; 
  1390.  
  1391. /** 
  1392. * Send the content-type header with correct encoding 
  1393. * 
  1394. * This method ensures that the SimplePie-enabled page is being served with 
  1395. * the correct {@link http://www.iana.org/assignments/media-types/ mime-type} 
  1396. * and character encoding HTTP headers (character encoding determined by the 
  1397. * {@see set_output_encoding} config option). 
  1398. * 
  1399. * This won't work properly if any content or whitespace has already been 
  1400. * sent to the browser, because it relies on PHP's 
  1401. * {@link http://php.net/header header()} function, and these are the 
  1402. * circumstances under which the function works. 
  1403. * 
  1404. * Because it's setting these settings for the entire page (as is the nature 
  1405. * of HTTP headers), this should only be used once per page (again, at the 
  1406. * top). 
  1407. * 
  1408. * @param string $mime MIME type to serve the page as 
  1409. */ 
  1410. public function handle_content_type($mime = 'text/html') 
  1411. if (!headers_sent()) 
  1412. $header = "Content-type: $mime;"; 
  1413. if ($this->get_encoding()) 
  1414. $header .= ' charset=' . $this->get_encoding(); 
  1415. else 
  1416. $header .= ' charset=UTF-8'; 
  1417. header($header); 
  1418.  
  1419. /** 
  1420. * Get the type of the feed 
  1421. * 
  1422. * This returns a SIMPLEPIE_TYPE_* constant, which can be tested against 
  1423. * using {@link http://php.net/language.operators.bitwise bitwise operators} 
  1424. * 
  1425. * @since 0.8 (usage changed to using constants in 1.0) 
  1426. * @see SIMPLEPIE_TYPE_NONE Unknown. 
  1427. * @see SIMPLEPIE_TYPE_RSS_090 RSS 0.90. 
  1428. * @see SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape). 
  1429. * @see SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland). 
  1430. * @see SIMPLEPIE_TYPE_RSS_091 RSS 0.91. 
  1431. * @see SIMPLEPIE_TYPE_RSS_092 RSS 0.92. 
  1432. * @see SIMPLEPIE_TYPE_RSS_093 RSS 0.93. 
  1433. * @see SIMPLEPIE_TYPE_RSS_094 RSS 0.94. 
  1434. * @see SIMPLEPIE_TYPE_RSS_10 RSS 1.0. 
  1435. * @see SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x. 
  1436. * @see SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS. 
  1437. * @see SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format). 
  1438. * @see SIMPLEPIE_TYPE_RSS_ALL Any version of RSS. 
  1439. * @see SIMPLEPIE_TYPE_ATOM_03 Atom 0.3. 
  1440. * @see SIMPLEPIE_TYPE_ATOM_10 Atom 1.0. 
  1441. * @see SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom. 
  1442. * @see SIMPLEPIE_TYPE_ALL Any known/supported feed type. 
  1443. * @return int SIMPLEPIE_TYPE_* constant 
  1444. */ 
  1445. public function get_type() 
  1446. if (!isset($this->data['type'])) 
  1447. $this->data['type'] = SIMPLEPIE_TYPE_ALL; 
  1448. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) 
  1449. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10; 
  1450. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) 
  1451. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03; 
  1452. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) 
  1453. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel']) 
  1454. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image']) 
  1455. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']) 
  1456. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput'])) 
  1457. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10; 
  1458. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel']) 
  1459. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image']) 
  1460. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']) 
  1461. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput'])) 
  1462. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090; 
  1463. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) 
  1464. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL; 
  1465. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) 
  1466. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) 
  1467. case '0.91': 
  1468. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091; 
  1469. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) 
  1470. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) 
  1471. case '0': 
  1472. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE; 
  1473. break; 
  1474.  
  1475. case '24': 
  1476. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND; 
  1477. break; 
  1478. break; 
  1479.  
  1480. case '0.92': 
  1481. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092; 
  1482. break; 
  1483.  
  1484. case '0.93': 
  1485. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093; 
  1486. break; 
  1487.  
  1488. case '0.94': 
  1489. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094; 
  1490. break; 
  1491.  
  1492. case '2.0': 
  1493. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20; 
  1494. break; 
  1495. else 
  1496. $this->data['type'] = SIMPLEPIE_TYPE_NONE; 
  1497. return $this->data['type']; 
  1498.  
  1499. /** 
  1500. * Get the URL for the feed 
  1501. * 
  1502. * May or may not be different from the URL passed to {@see set_feed_url()},  
  1503. * depending on whether auto-discovery was used. 
  1504. * 
  1505. * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.) 
  1506. * @todo If we have a perm redirect we should return the new URL 
  1507. * @todo When we make the above change, let's support <itunes:new-feed-url> as well 
  1508. * @todo Also, |atom:link|@rel=self 
  1509. * @return string|null 
  1510. */ 
  1511. public function subscribe_url() 
  1512. if ($this->feed_url !== null) 
  1513. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI); 
  1514. else 
  1515. return null; 
  1516.  
  1517. /** 
  1518. * Get data for an feed-level element 
  1519. * 
  1520. * This method allows you to get access to ANY element/attribute that is a 
  1521. * sub-element of the opening feed tag. 
  1522. * 
  1523. * The return value is an indexed array of elements matching the given 
  1524. * namespace and tag name. Each element has `attribs`, `data` and `child` 
  1525. * subkeys. For `attribs` and `child`, these contain namespace subkeys. 
  1526. * `attribs` then has one level of associative name => value data (where 
  1527. * `value` is a string) after the namespace. `child` has tag-indexed keys 
  1528. * after the namespace, each member of which is an indexed array matching 
  1529. * this same format. 
  1530. * 
  1531. * For example: 
  1532. * <pre> 
  1533. * // This is probably a bad example because we already support 
  1534. * // <media:content> natively, but it shows you how to parse through 
  1535. * // the nodes. 
  1536. * $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group'); 
  1537. * $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']; 
  1538. * $file = $content[0]['attribs']['']['url']; 
  1539. * echo $file; 
  1540. * </pre> 
  1541. * 
  1542. * @since 1.0 
  1543. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces 
  1544. * @param string $namespace The URL of the XML namespace of the elements you're trying to access 
  1545. * @param string $tag Tag name 
  1546. * @return array 
  1547. */ 
  1548. public function get_feed_tags($namespace, $tag) 
  1549. $type = $this->get_type(); 
  1550. if ($type & SIMPLEPIE_TYPE_ATOM_10) 
  1551. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag])) 
  1552. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]; 
  1553. if ($type & SIMPLEPIE_TYPE_ATOM_03) 
  1554. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag])) 
  1555. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]; 
  1556. if ($type & SIMPLEPIE_TYPE_RSS_RDF) 
  1557. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag])) 
  1558. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]; 
  1559. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 
  1560. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag])) 
  1561. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]; 
  1562. return null; 
  1563.  
  1564. /** 
  1565. * Get data for an channel-level element 
  1566. * 
  1567. * This method allows you to get access to ANY element/attribute in the 
  1568. * channel/header section of the feed. 
  1569. * 
  1570. * See {@see SimplePie::get_feed_tags()} for a description of the return value 
  1571. * 
  1572. * @since 1.0 
  1573. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces 
  1574. * @param string $namespace The URL of the XML namespace of the elements you're trying to access 
  1575. * @param string $tag Tag name 
  1576. * @return array 
  1577. */ 
  1578. public function get_channel_tags($namespace, $tag) 
  1579. $type = $this->get_type(); 
  1580. if ($type & SIMPLEPIE_TYPE_ATOM_ALL) 
  1581. if ($return = $this->get_feed_tags($namespace, $tag)) 
  1582. return $return; 
  1583. if ($type & SIMPLEPIE_TYPE_RSS_10) 
  1584. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel')) 
  1585. if (isset($channel[0]['child'][$namespace][$tag])) 
  1586. return $channel[0]['child'][$namespace][$tag]; 
  1587. if ($type & SIMPLEPIE_TYPE_RSS_090) 
  1588. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel')) 
  1589. if (isset($channel[0]['child'][$namespace][$tag])) 
  1590. return $channel[0]['child'][$namespace][$tag]; 
  1591. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 
  1592. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel')) 
  1593. if (isset($channel[0]['child'][$namespace][$tag])) 
  1594. return $channel[0]['child'][$namespace][$tag]; 
  1595. return null; 
  1596.  
  1597. /** 
  1598. * Get data for an channel-level element 
  1599. * 
  1600. * This method allows you to get access to ANY element/attribute in the 
  1601. * image/logo section of the feed. 
  1602. * 
  1603. * See {@see SimplePie::get_feed_tags()} for a description of the return value 
  1604. * 
  1605. * @since 1.0 
  1606. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces 
  1607. * @param string $namespace The URL of the XML namespace of the elements you're trying to access 
  1608. * @param string $tag Tag name 
  1609. * @return array 
  1610. */ 
  1611. public function get_image_tags($namespace, $tag) 
  1612. $type = $this->get_type(); 
  1613. if ($type & SIMPLEPIE_TYPE_RSS_10) 
  1614. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image')) 
  1615. if (isset($image[0]['child'][$namespace][$tag])) 
  1616. return $image[0]['child'][$namespace][$tag]; 
  1617. if ($type & SIMPLEPIE_TYPE_RSS_090) 
  1618. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image')) 
  1619. if (isset($image[0]['child'][$namespace][$tag])) 
  1620. return $image[0]['child'][$namespace][$tag]; 
  1621. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 
  1622. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image')) 
  1623. if (isset($image[0]['child'][$namespace][$tag])) 
  1624. return $image[0]['child'][$namespace][$tag]; 
  1625. return null; 
  1626.  
  1627. /** 
  1628. * Get the base URL value from the feed 
  1629. * 
  1630. * Uses `<xml:base>` if available, otherwise uses the first link in the 
  1631. * feed, or failing that, the URL of the feed itself. 
  1632. * 
  1633. * @see get_link 
  1634. * @see subscribe_url 
  1635. * 
  1636. * @param array $element 
  1637. * @return string 
  1638. */ 
  1639. public function get_base($element = array()) 
  1640. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) 
  1641. return $element['xml_base']; 
  1642. elseif ($this->get_link() !== null) 
  1643. return $this->get_link(); 
  1644. else 
  1645. return $this->subscribe_url(); 
  1646.  
  1647. /** 
  1648. * Sanitize feed data 
  1649. * 
  1650. * @access private 
  1651. * @see SimplePie_Sanitize::sanitize() 
  1652. * @param string $data Data to sanitize 
  1653. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants 
  1654. * @param string $base Base URL to resolve URLs against 
  1655. * @return string Sanitized data 
  1656. */ 
  1657. public function sanitize($data, $type, $base = '') 
  1658. return $this->sanitize->sanitize($data, $type, $base); 
  1659.  
  1660. /** 
  1661. * Get the title of the feed 
  1662. * 
  1663. * Uses `<atom:title>`, `<title>` or `<dc:title>` 
  1664. * 
  1665. * @since 1.0 (previously called `get_feed_title` since 0.8) 
  1666. * @return string|null 
  1667. */ 
  1668. public function get_title() 
  1669. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 
  1670. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1671. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 
  1672. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1673. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 
  1674. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1675. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 
  1676. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1677. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 
  1678. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1679. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 
  1680. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1681. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 
  1682. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1683. else 
  1684. return null; 
  1685.  
  1686. /** 
  1687. * Get a category for the feed 
  1688. * 
  1689. * @since Unknown 
  1690. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1 
  1691. * @return SimplePie_Category|null 
  1692. */ 
  1693. public function get_category($key = 0) 
  1694. $categories = $this->get_categories(); 
  1695. if (isset($categories[$key])) 
  1696. return $categories[$key]; 
  1697. else 
  1698. return null; 
  1699.  
  1700. /** 
  1701. * Get all categories for the feed 
  1702. * 
  1703. * Uses `<atom:category>`, `<category>` or `<dc:subject>` 
  1704. * 
  1705. * @since Unknown 
  1706. * @return array|null List of {@see SimplePie_Category} objects 
  1707. */ 
  1708. public function get_categories() 
  1709. $categories = array(); 
  1710.  
  1711. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 
  1712. $term = null; 
  1713. $scheme = null; 
  1714. $label = null; 
  1715. if (isset($category['attribs']['']['term'])) 
  1716. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1717. if (isset($category['attribs']['']['scheme'])) 
  1718. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1719. if (isset($category['attribs']['']['label'])) 
  1720. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1721. $categories[] = $this->registry->create('Category', array($term, $scheme, $label)); 
  1722. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) 
  1723. // This is really the label, but keep this as the term also for BC. 
  1724. // Label will also work on retrieving because that falls back to term. 
  1725. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1726. if (isset($category['attribs']['']['domain'])) 
  1727. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1728. else 
  1729. $scheme = null; 
  1730. $categories[] = $this->registry->create('Category', array($term, $scheme, null)); 
  1731. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 
  1732. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1733. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 
  1734. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1735.  
  1736. if (!empty($categories)) 
  1737. return array_unique($categories); 
  1738. else 
  1739. return null; 
  1740.  
  1741. /** 
  1742. * Get an author for the feed 
  1743. * 
  1744. * @since 1.1 
  1745. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1 
  1746. * @return SimplePie_Author|null 
  1747. */ 
  1748. public function get_author($key = 0) 
  1749. $authors = $this->get_authors(); 
  1750. if (isset($authors[$key])) 
  1751. return $authors[$key]; 
  1752. else 
  1753. return null; 
  1754.  
  1755. /** 
  1756. * Get all authors for the feed 
  1757. * 
  1758. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>` 
  1759. * 
  1760. * @since 1.1 
  1761. * @return array|null List of {@see SimplePie_Author} objects 
  1762. */ 
  1763. public function get_authors() 
  1764. $authors = array(); 
  1765. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) 
  1766. $name = null; 
  1767. $uri = null; 
  1768. $email = null; 
  1769. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 
  1770. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1771. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 
  1772. $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])); 
  1773. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 
  1774. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1775. if ($name !== null || $email !== null || $uri !== null) 
  1776. $authors[] = $this->registry->create('Author', array($name, $uri, $email)); 
  1777. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) 
  1778. $name = null; 
  1779. $url = null; 
  1780. $email = null; 
  1781. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 
  1782. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1783. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 
  1784. $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])); 
  1785. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 
  1786. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1787. if ($name !== null || $email !== null || $url !== null) 
  1788. $authors[] = $this->registry->create('Author', array($name, $url, $email)); 
  1789. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) 
  1790. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1791. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) 
  1792. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1793. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) 
  1794. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1795.  
  1796. if (!empty($authors)) 
  1797. return array_unique($authors); 
  1798. else 
  1799. return null; 
  1800.  
  1801. /** 
  1802. * Get a contributor for the feed 
  1803. * 
  1804. * @since 1.1 
  1805. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1 
  1806. * @return SimplePie_Author|null 
  1807. */ 
  1808. public function get_contributor($key = 0) 
  1809. $contributors = $this->get_contributors(); 
  1810. if (isset($contributors[$key])) 
  1811. return $contributors[$key]; 
  1812. else 
  1813. return null; 
  1814.  
  1815. /** 
  1816. * Get all contributors for the feed 
  1817. * 
  1818. * Uses `<atom:contributor>` 
  1819. * 
  1820. * @since 1.1 
  1821. * @return array|null List of {@see SimplePie_Author} objects 
  1822. */ 
  1823. public function get_contributors() 
  1824. $contributors = array(); 
  1825. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) 
  1826. $name = null; 
  1827. $uri = null; 
  1828. $email = null; 
  1829. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 
  1830. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1831. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 
  1832. $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])); 
  1833. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 
  1834. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1835. if ($name !== null || $email !== null || $uri !== null) 
  1836. $contributors[] = $this->registry->create('Author', array($name, $uri, $email)); 
  1837. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) 
  1838. $name = null; 
  1839. $url = null; 
  1840. $email = null; 
  1841. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 
  1842. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1843. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 
  1844. $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])); 
  1845. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 
  1846. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1847. if ($name !== null || $email !== null || $url !== null) 
  1848. $contributors[] = $this->registry->create('Author', array($name, $url, $email)); 
  1849.  
  1850. if (!empty($contributors)) 
  1851. return array_unique($contributors); 
  1852. else 
  1853. return null; 
  1854.  
  1855. /** 
  1856. * Get a single link for the feed 
  1857. * 
  1858. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8) 
  1859. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1 
  1860. * @param string $rel The relationship of the link to return 
  1861. * @return string|null Link URL 
  1862. */ 
  1863. public function get_link($key = 0, $rel = 'alternate') 
  1864. $links = $this->get_links($rel); 
  1865. if (isset($links[$key])) 
  1866. return $links[$key]; 
  1867. else 
  1868. return null; 
  1869.  
  1870. /** 
  1871. * Get the permalink for the item 
  1872. * 
  1873. * Returns the first link available with a relationship of "alternate". 
  1874. * Identical to {@see get_link()} with key 0 
  1875. * 
  1876. * @see get_link 
  1877. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8) 
  1878. * @internal Added for parity between the parent-level and the item/entry-level. 
  1879. * @return string|null Link URL 
  1880. */ 
  1881. public function get_permalink() 
  1882. return $this->get_link(0); 
  1883.  
  1884. /** 
  1885. * Get all links for the feed 
  1886. * 
  1887. * Uses `<atom:link>` or `<link>` 
  1888. * 
  1889. * @since Beta 2 
  1890. * @param string $rel The relationship of links to return 
  1891. * @return array|null Links found for the feed (strings) 
  1892. */ 
  1893. public function get_links($rel = 'alternate') 
  1894. if (!isset($this->data['links'])) 
  1895. $this->data['links'] = array(); 
  1896. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) 
  1897. foreach ($links as $link) 
  1898. if (isset($link['attribs']['']['href'])) 
  1899. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 
  1900. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 
  1901. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) 
  1902. foreach ($links as $link) 
  1903. if (isset($link['attribs']['']['href'])) 
  1904. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 
  1905. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 
  1906.  
  1907. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 
  1908. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  1909. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 
  1910. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  1911. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 
  1912. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  1913.  
  1914. $keys = array_keys($this->data['links']); 
  1915. foreach ($keys as $key) 
  1916. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) 
  1917. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 
  1918. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 
  1919. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 
  1920. else 
  1921. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 
  1922. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 
  1923. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 
  1924. $this->data['links'][$key] = array_unique($this->data['links'][$key]); 
  1925.  
  1926. if (isset($this->data['links'][$rel])) 
  1927. return $this->data['links'][$rel]; 
  1928. else 
  1929. return null; 
  1930.  
  1931. public function get_all_discovered_feeds() 
  1932. return $this->all_discovered_feeds; 
  1933.  
  1934. /** 
  1935. * Get the content for the item 
  1936. * 
  1937. * Uses `<atom:subtitle>`, `<atom:tagline>`, `<description>`,  
  1938. * `<dc:description>`, `<itunes:summary>` or `<itunes:subtitle>` 
  1939. * 
  1940. * @since 1.0 (previously called `get_feed_description()` since 0.8) 
  1941. * @return string|null 
  1942. */ 
  1943. public function get_description() 
  1944. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) 
  1945. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1946. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) 
  1947. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1948. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 
  1949. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1950. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 
  1951. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1952. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) 
  1953. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  1954. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 
  1955. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1956. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 
  1957. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1958. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 
  1959. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  1960. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 
  1961. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  1962. else 
  1963. return null; 
  1964.  
  1965. /** 
  1966. * Get the copyright info for the feed 
  1967. * 
  1968. * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>` 
  1969. * 
  1970. * @since 1.0 (previously called `get_feed_copyright()` since 0.8) 
  1971. * @return string|null 
  1972. */ 
  1973. public function get_copyright() 
  1974. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) 
  1975. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1976. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) 
  1977. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1978. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) 
  1979. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1980. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) 
  1981. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1982. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) 
  1983. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1984. else 
  1985. return null; 
  1986.  
  1987. /** 
  1988. * Get the language for the feed 
  1989. * 
  1990. * Uses `<language>`, `<dc:language>`, or @xml_lang 
  1991. * 
  1992. * @since 1.0 (previously called `get_feed_language()` since 0.8) 
  1993. * @return string|null 
  1994. */ 
  1995. public function get_language() 
  1996. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) 
  1997. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1998. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) 
  1999. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2000. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) 
  2001. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2002. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) 
  2003. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2004. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) 
  2005. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2006. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) 
  2007. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2008. elseif (isset($this->data['headers']['content-language'])) 
  2009. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2010. else 
  2011. return null; 
  2012.  
  2013. /** 
  2014. * Get the latitude coordinates for the item 
  2015. * 
  2016. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications 
  2017. * 
  2018. * Uses `<geo:lat>` or `<georss:point>` 
  2019. * 
  2020. * @since 1.0 
  2021. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 
  2022. * @link http://www.georss.org/ GeoRSS 
  2023. * @return string|null 
  2024. */ 
  2025. public function get_latitude() 
  2026.  
  2027. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) 
  2028. return (float) $return[0]['data']; 
  2029. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 
  2030. return (float) $match[1]; 
  2031. else 
  2032. return null; 
  2033.  
  2034. /** 
  2035. * Get the longitude coordinates for the feed 
  2036. * 
  2037. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications 
  2038. * 
  2039. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>` 
  2040. * 
  2041. * @since 1.0 
  2042. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 
  2043. * @link http://www.georss.org/ GeoRSS 
  2044. * @return string|null 
  2045. */ 
  2046. public function get_longitude() 
  2047. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) 
  2048. return (float) $return[0]['data']; 
  2049. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) 
  2050. return (float) $return[0]['data']; 
  2051. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match)) 
  2052. return (float) $match[2]; 
  2053. else 
  2054. return null; 
  2055.  
  2056. /** 
  2057. * Get the feed logo's title 
  2058. * 
  2059. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title. 
  2060. * 
  2061. * Uses `<image><title>` or `<image><dc:title>` 
  2062. * 
  2063. * @return string|null 
  2064. */ 
  2065. public function get_image_title() 
  2066. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 
  2067. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2068. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 
  2069. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2070. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 
  2071. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2072. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 
  2073. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2074. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 
  2075. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  2076. else 
  2077. return null; 
  2078.  
  2079. /** 
  2080. * Get the feed logo's URL 
  2081. * 
  2082. * RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to 
  2083. * have a "feed logo" URL. This points directly to the image itself. 
  2084. * 
  2085. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,  
  2086. * `<image><title>` or `<image><dc:title>` 
  2087. * 
  2088. * @return string|null 
  2089. */ 
  2090. public function get_image_url() 
  2091. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) 
  2092. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); 
  2093. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) 
  2094. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2095. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) 
  2096. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2097. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) 
  2098. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2099. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) 
  2100. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2101. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 
  2102. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2103. else 
  2104. return null; 
  2105.  
  2106.  
  2107. /** 
  2108. * Get the feed logo's link 
  2109. * 
  2110. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This 
  2111. * points to a human-readable page that the image should link to. 
  2112. * 
  2113. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,  
  2114. * `<image><title>` or `<image><dc:title>` 
  2115. * 
  2116. * @return string|null 
  2117. */ 
  2118. public function get_image_link() 
  2119. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 
  2120. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2121. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 
  2122. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2123. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 
  2124. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  2125. else 
  2126. return null; 
  2127.  
  2128. /** 
  2129. * Get the feed logo's link 
  2130. * 
  2131. * RSS 2.0 feeds are allowed to have a "feed logo" width. 
  2132. * 
  2133. * Uses `<image><width>` or defaults to 88.0 if no width is specified and 
  2134. * the feed is an RSS 2.0 feed. 
  2135. * 
  2136. * @return int|float|null 
  2137. */ 
  2138. public function get_image_width() 
  2139. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width')) 
  2140. return round($return[0]['data']); 
  2141. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 
  2142. return 88.0; 
  2143. else 
  2144. return null; 
  2145.  
  2146. /** 
  2147. * Get the feed logo's height 
  2148. * 
  2149. * RSS 2.0 feeds are allowed to have a "feed logo" height. 
  2150. * 
  2151. * Uses `<image><height>` or defaults to 31.0 if no height is specified and 
  2152. * the feed is an RSS 2.0 feed. 
  2153. * 
  2154. * @return int|float|null 
  2155. */ 
  2156. public function get_image_height() 
  2157. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height')) 
  2158. return round($return[0]['data']); 
  2159. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 
  2160. return 31.0; 
  2161. else 
  2162. return null; 
  2163.  
  2164. /** 
  2165. * Get the number of items in the feed 
  2166. * 
  2167. * This is well-suited for {@link http://php.net/for for()} loops with 
  2168. * {@see get_item()} 
  2169. * 
  2170. * @param int $max Maximum value to return. 0 for no limit 
  2171. * @return int Number of items in the feed 
  2172. */ 
  2173. public function get_item_quantity($max = 0) 
  2174. $max = (int) $max; 
  2175. $qty = count($this->get_items()); 
  2176. if ($max === 0) 
  2177. return $qty; 
  2178. else 
  2179. return ($qty > $max) ? $max : $qty; 
  2180.  
  2181. /** 
  2182. * Get a single item from the feed 
  2183. * 
  2184. * This is better suited for {@link http://php.net/for for()} loops, whereas 
  2185. * {@see get_items()} is better suited for 
  2186. * {@link http://php.net/foreach foreach()} loops. 
  2187. * 
  2188. * @see get_item_quantity() 
  2189. * @since Beta 2 
  2190. * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1 
  2191. * @return SimplePie_Item|null 
  2192. */ 
  2193. public function get_item($key = 0) 
  2194. $items = $this->get_items(); 
  2195. if (isset($items[$key])) 
  2196. return $items[$key]; 
  2197. else 
  2198. return null; 
  2199.  
  2200. /** 
  2201. * Get all items from the feed 
  2202. * 
  2203. * This is better suited for {@link http://php.net/for for()} loops, whereas 
  2204. * {@see get_items()} is better suited for 
  2205. * {@link http://php.net/foreach foreach()} loops. 
  2206. * 
  2207. * @see get_item_quantity 
  2208. * @since Beta 2 
  2209. * @param int $start Index to start at 
  2210. * @param int $end Number of items to return. 0 for all items after `$start` 
  2211. * @return array|null List of {@see SimplePie_Item} objects 
  2212. */ 
  2213. public function get_items($start = 0, $end = 0) 
  2214. if (!isset($this->data['items'])) 
  2215. if (!empty($this->multifeed_objects)) 
  2216. $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); 
  2217. else 
  2218. $this->data['items'] = array(); 
  2219. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) 
  2220. $keys = array_keys($items); 
  2221. foreach ($keys as $key) 
  2222. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  2223. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) 
  2224. $keys = array_keys($items); 
  2225. foreach ($keys as $key) 
  2226. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  2227. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) 
  2228. $keys = array_keys($items); 
  2229. foreach ($keys as $key) 
  2230. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  2231. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) 
  2232. $keys = array_keys($items); 
  2233. foreach ($keys as $key) 
  2234. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  2235. if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item')) 
  2236. $keys = array_keys($items); 
  2237. foreach ($keys as $key) 
  2238. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  2239.  
  2240. if (!empty($this->data['items'])) 
  2241. // If we want to order it by date, check if all items have a date, and then sort it 
  2242. if ($this->order_by_date && empty($this->multifeed_objects)) 
  2243. if (!isset($this->data['ordered_items'])) 
  2244. $do_sort = true; 
  2245. foreach ($this->data['items'] as $item) 
  2246. if (!$item->get_date('U')) 
  2247. $do_sort = false; 
  2248. break; 
  2249. $item = null; 
  2250. $this->data['ordered_items'] = $this->data['items']; 
  2251. if ($do_sort) 
  2252. usort($this->data['ordered_items'], array(get_class($this), 'sort_items')); 
  2253. $items = $this->data['ordered_items']; 
  2254. else 
  2255. $items = $this->data['items']; 
  2256.  
  2257. // Slice the data as desired 
  2258. if ($end === 0) 
  2259. return array_slice($items, $start); 
  2260. else 
  2261. return array_slice($items, $start, $end); 
  2262. else 
  2263. return array(); 
  2264.  
  2265. /** 
  2266. * Set the favicon handler 
  2267. * 
  2268. * @deprecated Use your own favicon handling instead 
  2269. */ 
  2270. public function set_favicon_handler($page = false, $qs = 'i') 
  2271. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  2272. trigger_error('Favicon handling has been removed, please use your own handling', $level); 
  2273. return false; 
  2274.  
  2275. /** 
  2276. * Get the favicon for the current feed 
  2277. * 
  2278. * @deprecated Use your own favicon handling instead 
  2279. */ 
  2280. public function get_favicon() 
  2281. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  2282. trigger_error('Favicon handling has been removed, please use your own handling', $level); 
  2283.  
  2284. if (($url = $this->get_link()) !== null) 
  2285. return 'http://g.etfv.co/' . urlencode($url); 
  2286.  
  2287. return false; 
  2288.  
  2289. /** 
  2290. * Magic method handler 
  2291. * 
  2292. * @param string $method Method name 
  2293. * @param array $args Arguments to the method 
  2294. * @return mixed 
  2295. */ 
  2296. public function __call($method, $args) 
  2297. if (strpos($method, 'subscribe_') === 0) 
  2298. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  2299. trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level); 
  2300. return ''; 
  2301. if ($method === 'enable_xml_dump') 
  2302. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  2303. trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level); 
  2304. return false; 
  2305.  
  2306. $class = get_class($this); 
  2307. $trace = debug_backtrace(); 
  2308. $file = $trace[0]['file']; 
  2309. $line = $trace[0]['line']; 
  2310. trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR); 
  2311.  
  2312. /** 
  2313. * Sorting callback for items 
  2314. * 
  2315. * @access private 
  2316. * @param SimplePie $a 
  2317. * @param SimplePie $b 
  2318. * @return boolean 
  2319. */ 
  2320. public static function sort_items($a, $b) 
  2321. return $a->get_date('U') <= $b->get_date('U'); 
  2322.  
  2323. /** 
  2324. * Merge items from several feeds into one 
  2325. * 
  2326. * If you're merging multiple feeds together, they need to all have dates 
  2327. * for the items or else SimplePie will refuse to sort them. 
  2328. * 
  2329. * @link http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date#if_feeds_require_separate_per-feed_settings 
  2330. * @param array $urls List of SimplePie feed objects to merge 
  2331. * @param int $start Starting item 
  2332. * @param int $end Number of items to return 
  2333. * @param int $limit Maximum number of items per feed 
  2334. * @return array 
  2335. */ 
  2336. public static function merge_items($urls, $start = 0, $end = 0, $limit = 0) 
  2337. if (is_array($urls) && sizeof($urls) > 0) 
  2338. $items = array(); 
  2339. foreach ($urls as $arg) 
  2340. if ($arg instanceof SimplePie) 
  2341. $items = array_merge($items, $arg->get_items(0, $limit)); 
  2342. else 
  2343. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING); 
  2344.  
  2345. $do_sort = true; 
  2346. foreach ($items as $item) 
  2347. if (!$item->get_date('U')) 
  2348. $do_sort = false; 
  2349. break; 
  2350. $item = null; 
  2351. if ($do_sort) 
  2352. usort($items, array(get_class($urls[0]), 'sort_items')); 
  2353.  
  2354. if ($end === 0) 
  2355. return array_slice($items, $start); 
  2356. else 
  2357. return array_slice($items, $start, $end); 
  2358. else 
  2359. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); 
  2360. return array(); 
  2361. endif; 
.