SimplePie

SimplePie.

Defined (1)

The class is defined in the following location(s).

/wp-includes/class-simplepie.php  
  1. class SimplePie 
  2. /** 
  3. * @var array Raw data 
  4. * @access private 
  5. */ 
  6. public $data = array(); 
  7.  
  8. /** 
  9. * @var mixed Error string 
  10. * @access private 
  11. */ 
  12. public $error; 
  13.  
  14. /** 
  15. * @var object Instance of SimplePie_Sanitize (or other class) 
  16. * @see SimplePie::set_sanitize_class() 
  17. * @access private 
  18. */ 
  19. public $sanitize; 
  20.  
  21. /** 
  22. * @var string SimplePie Useragent 
  23. * @see SimplePie::set_useragent() 
  24. * @access private 
  25. */ 
  26. public $useragent = SIMPLEPIE_USERAGENT; 
  27.  
  28. /** 
  29. * @var string Feed URL 
  30. * @see SimplePie::set_feed_url() 
  31. * @access private 
  32. */ 
  33. public $feed_url; 
  34.  
  35. /** 
  36. * @var object Instance of SimplePie_File to use as a feed 
  37. * @see SimplePie::set_file() 
  38. * @access private 
  39. */ 
  40. public $file; 
  41.  
  42. /** 
  43. * @var string Raw feed data 
  44. * @see SimplePie::set_raw_data() 
  45. * @access private 
  46. */ 
  47. public $raw_data; 
  48.  
  49. /** 
  50. * @var int Timeout for fetching remote files 
  51. * @see SimplePie::set_timeout() 
  52. * @access private 
  53. */ 
  54. public $timeout = 10; 
  55.  
  56. /** 
  57. * @var bool Forces fsockopen() to be used for remote files instead 
  58. * of cURL, even if a new enough version is installed 
  59. * @see SimplePie::force_fsockopen() 
  60. * @access private 
  61. */ 
  62. public $force_fsockopen = false; 
  63.  
  64. /** 
  65. * @var bool Force the given data/URL to be treated as a feed no matter what 
  66. * it appears like 
  67. * @see SimplePie::force_feed() 
  68. * @access private 
  69. */ 
  70. public $force_feed = false; 
  71.  
  72. /** 
  73. * @var bool Enable/Disable Caching 
  74. * @see SimplePie::enable_cache() 
  75. * @access private 
  76. */ 
  77. public $cache = true; 
  78.  
  79. /** 
  80. * @var int Cache duration (in seconds) 
  81. * @see SimplePie::set_cache_duration() 
  82. * @access private 
  83. */ 
  84. public $cache_duration = 3600; 
  85.  
  86. /** 
  87. * @var int Auto-discovery cache duration (in seconds) 
  88. * @see SimplePie::set_autodiscovery_cache_duration() 
  89. * @access private 
  90. */ 
  91. public $autodiscovery_cache_duration = 604800; // 7 Days. 
  92.  
  93. /** 
  94. * @var string Cache location (relative to executing script) 
  95. * @see SimplePie::set_cache_location() 
  96. * @access private 
  97. */ 
  98. public $cache_location = './cache'; 
  99.  
  100. /** 
  101. * @var string Function that creates the cache filename 
  102. * @see SimplePie::set_cache_name_function() 
  103. * @access private 
  104. */ 
  105. public $cache_name_function = 'md5'; 
  106.  
  107. /** 
  108. * @var bool Reorder feed by date descending 
  109. * @see SimplePie::enable_order_by_date() 
  110. * @access private 
  111. */ 
  112. public $order_by_date = true; 
  113.  
  114. /** 
  115. * @var mixed Force input encoding to be set to the follow value 
  116. * (false, or anything type-cast to false, disables this feature) 
  117. * @see SimplePie::set_input_encoding() 
  118. * @access private 
  119. */ 
  120. public $input_encoding = false; 
  121.  
  122. /** 
  123. * @var int Feed Autodiscovery Level 
  124. * @see SimplePie::set_autodiscovery_level() 
  125. * @access private 
  126. */ 
  127. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL; 
  128.  
  129. /** 
  130. * Class registry object 
  131. * @var SimplePie_Registry 
  132. */ 
  133. public $registry; 
  134.  
  135. /** 
  136. * @var int Maximum number of feeds to check with autodiscovery 
  137. * @see SimplePie::set_max_checked_feeds() 
  138. * @access private 
  139. */ 
  140. public $max_checked_feeds = 10; 
  141.  
  142. /** 
  143. * @var array All the feeds found during the autodiscovery process 
  144. * @see SimplePie::get_all_discovered_feeds() 
  145. * @access private 
  146. */ 
  147. public $all_discovered_feeds = array(); 
  148.  
  149. /** 
  150. * @var string Web-accessible path to the handler_image.php file. 
  151. * @see SimplePie::set_image_handler() 
  152. * @access private 
  153. */ 
  154. public $image_handler = ''; 
  155.  
  156. /** 
  157. * @var array Stores the URLs when multiple feeds are being initialized. 
  158. * @see SimplePie::set_feed_url() 
  159. * @access private 
  160. */ 
  161. public $multifeed_url = array(); 
  162.  
  163. /** 
  164. * @var array Stores SimplePie objects when multiple feeds initialized. 
  165. * @access private 
  166. */ 
  167. public $multifeed_objects = array(); 
  168.  
  169. /** 
  170. * @var array Stores the get_object_vars() array for use with multifeeds. 
  171. * @see SimplePie::set_feed_url() 
  172. * @access private 
  173. */ 
  174. public $config_settings = null; 
  175.  
  176. /** 
  177. * @var integer Stores the number of items to return per-feed with multifeeds. 
  178. * @see SimplePie::set_item_limit() 
  179. * @access private 
  180. */ 
  181. public $item_limit = 0; 
  182.  
  183. /** 
  184. * @var array Stores the default attributes to be stripped by strip_attributes(). 
  185. * @see SimplePie::strip_attributes() 
  186. * @access private 
  187. */ 
  188. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'); 
  189.  
  190. /** 
  191. * @var array Stores the default tags to be stripped by strip_htmltags(). 
  192. * @see SimplePie::strip_htmltags() 
  193. * @access private 
  194. */ 
  195. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); 
  196.  
  197. /** 
  198. * The SimplePie class contains feed level data and options 
  199. * To use SimplePie, create the SimplePie object with no parameters. You can 
  200. * then set configuration options using the provided methods. After setting 
  201. * them, you must initialise the feed using $feed->init(). At that point the 
  202. * object's methods and properties will be available to you. 
  203. * Previously, it was possible to pass in the feed URL along with cache 
  204. * options directly into the constructor. This has been removed as of 1.3 as 
  205. * it caused a lot of confusion. 
  206. * @since 1.0 Preview Release 
  207. */ 
  208. public function __construct() 
  209. if (version_compare(PHP_VERSION, '5.2', '<')) 
  210. trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.'); 
  211. die(); 
  212.  
  213. // Other objects, instances created here so we can set options on them 
  214. $this->sanitize = new SimplePie_Sanitize(); 
  215. $this->registry = new SimplePie_Registry(); 
  216.  
  217. if (func_num_args() > 0) 
  218. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  219. 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); 
  220.  
  221. $args = func_get_args(); 
  222. switch (count($args)) { 
  223. case 3: 
  224. $this->set_cache_duration($args[2]); 
  225. case 2: 
  226. $this->set_cache_location($args[1]); 
  227. case 1: 
  228. $this->set_feed_url($args[0]); 
  229. $this->init(); 
  230.  
  231. /** 
  232. * Used for converting object to a string 
  233. */ 
  234. public function __toString() 
  235. return md5(serialize($this->data)); 
  236.  
  237. /** 
  238. * Remove items that link back to this before destroying this object 
  239. */ 
  240. public function __destruct() 
  241. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode')) 
  242. if (!empty($this->data['items'])) 
  243. foreach ($this->data['items'] as $item) 
  244. $item->__destruct(); 
  245. unset($item, $this->data['items']); 
  246. if (!empty($this->data['ordered_items'])) 
  247. foreach ($this->data['ordered_items'] as $item) 
  248. $item->__destruct(); 
  249. unset($item, $this->data['ordered_items']); 
  250.  
  251. /** 
  252. * Force the given data/URL to be treated as a feed 
  253. * This tells SimplePie to ignore the content-type provided by the server. 
  254. * Be careful when using this option, as it will also disable autodiscovery. 
  255. * @since 1.1 
  256. * @param bool $enable Force the given data/URL to be treated as a feed 
  257. */ 
  258. public function force_feed($enable = false) 
  259. $this->force_feed = (bool) $enable; 
  260.  
  261. /** 
  262. * Set the URL of the feed you want to parse 
  263. * This allows you to enter the URL of the feed you want to parse, or the 
  264. * website you want to try to use auto-discovery on. This takes priority 
  265. * over any set raw data. 
  266. * You can set multiple feeds to mash together by passing an array instead 
  267. * of a string for the $url. Remember that with each additional feed comes 
  268. * additional processing and resources. 
  269. * @since 1.0 Preview Release 
  270. * @see set_raw_data() 
  271. * @param string|array $url This is the URL (or array of URLs) that you want to parse. 
  272. */ 
  273. public function set_feed_url($url) 
  274. $this->multifeed_url = array(); 
  275. if (is_array($url)) 
  276. foreach ($url as $value) 
  277. $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1)); 
  278. else 
  279. $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1)); 
  280.  
  281. /** 
  282. * Set an instance of {@see SimplePie_File} to use as a feed 
  283. * @param SimplePie_File &$file 
  284. * @return bool True on success, false on failure 
  285. */ 
  286. public function set_file(&$file) 
  287. if ($file instanceof SimplePie_File) 
  288. $this->feed_url = $file->url; 
  289. $this->file =& $file; 
  290. return true; 
  291. return false; 
  292.  
  293. /** 
  294. * Set the raw XML data to parse 
  295. * Allows you to use a string of RSS/Atom data instead of a remote feed. 
  296. * If you have a feed available as a string in PHP, you can tell SimplePie 
  297. * to parse that data string instead of a remote feed. Any set feed URL 
  298. * takes precedence. 
  299. * @since 1.0 Beta 3 
  300. * @param string $data RSS or Atom data as a string. 
  301. * @see set_feed_url() 
  302. */ 
  303. public function set_raw_data($data) 
  304. $this->raw_data = $data; 
  305.  
  306. /** 
  307. * Set the the default timeout for fetching remote feeds 
  308. * This allows you to change the maximum time the feed's server to respond 
  309. * and send the feed back. 
  310. * @since 1.0 Beta 3 
  311. * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed. 
  312. */ 
  313. public function set_timeout($timeout = 10) 
  314. $this->timeout = (int) $timeout; 
  315.  
  316. /** 
  317. * Force SimplePie to use fsockopen() instead of cURL 
  318. * @since 1.0 Beta 3 
  319. * @param bool $enable Force fsockopen() to be used 
  320. */ 
  321. public function force_fsockopen($enable = false) 
  322. $this->force_fsockopen = (bool) $enable; 
  323.  
  324. /** 
  325. * Enable/disable caching in SimplePie. 
  326. * This option allows you to disable caching all-together in SimplePie. 
  327. * However, disabling the cache can lead to longer load times. 
  328. * @since 1.0 Preview Release 
  329. * @param bool $enable Enable caching 
  330. */ 
  331. public function enable_cache($enable = true) 
  332. $this->cache = (bool) $enable; 
  333.  
  334. /** 
  335. * Set the length of time (in seconds) that the contents of a feed will be 
  336. * cached 
  337. * @param int $seconds The feed content cache duration 
  338. */ 
  339. public function set_cache_duration($seconds = 3600) 
  340. $this->cache_duration = (int) $seconds; 
  341.  
  342. /** 
  343. * Set the length of time (in seconds) that the autodiscovered feed URL will 
  344. * be cached 
  345. * @param int $seconds The autodiscovered feed URL cache duration. 
  346. */ 
  347. public function set_autodiscovery_cache_duration($seconds = 604800) 
  348. $this->autodiscovery_cache_duration = (int) $seconds; 
  349.  
  350. /** 
  351. * Set the file system location where the cached files should be stored 
  352. * @param string $location The file system location. 
  353. */ 
  354. public function set_cache_location($location = './cache') 
  355. $this->cache_location = (string) $location; 
  356.  
  357. /** 
  358. * Set whether feed items should be sorted into reverse chronological order 
  359. * @param bool $enable Sort as reverse chronological order. 
  360. */ 
  361. public function enable_order_by_date($enable = true) 
  362. $this->order_by_date = (bool) $enable; 
  363.  
  364. /** 
  365. * Set the character encoding used to parse the feed 
  366. * This overrides the encoding reported by the feed, however it will fall 
  367. * back to the normal encoding detection if the override fails 
  368. * @param string $encoding Character encoding 
  369. */ 
  370. public function set_input_encoding($encoding = false) 
  371. if ($encoding) 
  372. $this->input_encoding = (string) $encoding; 
  373. else 
  374. $this->input_encoding = false; 
  375.  
  376. /** 
  377. * Set how much feed autodiscovery to do 
  378. * @see SIMPLEPIE_LOCATOR_NONE 
  379. * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY 
  380. * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION 
  381. * @see SIMPLEPIE_LOCATOR_LOCAL_BODY 
  382. * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION 
  383. * @see SIMPLEPIE_LOCATOR_REMOTE_BODY 
  384. * @see SIMPLEPIE_LOCATOR_ALL 
  385. * @param int $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator) 
  386. */ 
  387. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL) 
  388. $this->autodiscovery = (int) $level; 
  389.  
  390. /** 
  391. * Get the class registry 
  392. * Use this to override SimplePie's default classes 
  393. * @see SimplePie_Registry 
  394. * @return SimplePie_Registry 
  395. */ 
  396. public function &get_registry() 
  397. return $this->registry; 
  398.  
  399. /**#@+ 
  400. * Useful when you are overloading or extending SimplePie's default classes. 
  401. * @deprecated Use {@see get_registry()} instead 
  402. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation 
  403. * @param string $class Name of custom class 
  404. * @return boolean True on success, false otherwise 
  405. */ 
  406. /** 
  407. * Set which class SimplePie uses for caching 
  408. */ 
  409. public function set_cache_class($class = 'SimplePie_Cache') 
  410. return $this->registry->register('Cache', $class, true); 
  411.  
  412. /** 
  413. * Set which class SimplePie uses for auto-discovery 
  414. */ 
  415. public function set_locator_class($class = 'SimplePie_Locator') 
  416. return $this->registry->register('Locator', $class, true); 
  417.  
  418. /** 
  419. * Set which class SimplePie uses for XML parsing 
  420. */ 
  421. public function set_parser_class($class = 'SimplePie_Parser') 
  422. return $this->registry->register('Parser', $class, true); 
  423.  
  424. /** 
  425. * Set which class SimplePie uses for remote file fetching 
  426. */ 
  427. public function set_file_class($class = 'SimplePie_File') 
  428. return $this->registry->register('File', $class, true); 
  429.  
  430. /** 
  431. * Set which class SimplePie uses for data sanitization 
  432. */ 
  433. public function set_sanitize_class($class = 'SimplePie_Sanitize') 
  434. return $this->registry->register('Sanitize', $class, true); 
  435.  
  436. /** 
  437. * Set which class SimplePie uses for handling feed items 
  438. */ 
  439. public function set_item_class($class = 'SimplePie_Item') 
  440. return $this->registry->register('Item', $class, true); 
  441.  
  442. /** 
  443. * Set which class SimplePie uses for handling author data 
  444. */ 
  445. public function set_author_class($class = 'SimplePie_Author') 
  446. return $this->registry->register('Author', $class, true); 
  447.  
  448. /** 
  449. * Set which class SimplePie uses for handling category data 
  450. */ 
  451. public function set_category_class($class = 'SimplePie_Category') 
  452. return $this->registry->register('Category', $class, true); 
  453.  
  454. /** 
  455. * Set which class SimplePie uses for feed enclosures 
  456. */ 
  457. public function set_enclosure_class($class = 'SimplePie_Enclosure') 
  458. return $this->registry->register('Enclosure', $class, true); 
  459.  
  460. /** 
  461. * Set which class SimplePie uses for `<media:text>` captions 
  462. */ 
  463. public function set_caption_class($class = 'SimplePie_Caption') 
  464. return $this->registry->register('Caption', $class, true); 
  465.  
  466. /** 
  467. * Set which class SimplePie uses for `<media:copyright>` 
  468. */ 
  469. public function set_copyright_class($class = 'SimplePie_Copyright') 
  470. return $this->registry->register('Copyright', $class, true); 
  471.  
  472. /** 
  473. * Set which class SimplePie uses for `<media:credit>` 
  474. */ 
  475. public function set_credit_class($class = 'SimplePie_Credit') 
  476. return $this->registry->register('Credit', $class, true); 
  477.  
  478. /** 
  479. * Set which class SimplePie uses for `<media:rating>` 
  480. */ 
  481. public function set_rating_class($class = 'SimplePie_Rating') 
  482. return $this->registry->register('Rating', $class, true); 
  483.  
  484. /** 
  485. * Set which class SimplePie uses for `<media:restriction>` 
  486. */ 
  487. public function set_restriction_class($class = 'SimplePie_Restriction') 
  488. return $this->registry->register('Restriction', $class, true); 
  489.  
  490. /** 
  491. * Set which class SimplePie uses for content-type sniffing 
  492. */ 
  493. public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer') 
  494. return $this->registry->register('Content_Type_Sniffer', $class, true); 
  495.  
  496. /** 
  497. * Set which class SimplePie uses item sources 
  498. */ 
  499. public function set_source_class($class = 'SimplePie_Source') 
  500. return $this->registry->register('Source', $class, true); 
  501. /**#@-*/ 
  502.  
  503. /** 
  504. * Set the user agent string 
  505. * @param string $ua New user agent string. 
  506. */ 
  507. public function set_useragent($ua = SIMPLEPIE_USERAGENT) 
  508. $this->useragent = (string) $ua; 
  509.  
  510. /** 
  511. * Set callback function to create cache filename with 
  512. * @param mixed $function Callback function 
  513. */ 
  514. public function set_cache_name_function($function = 'md5') 
  515. if (is_callable($function)) 
  516. $this->cache_name_function = $function; 
  517.  
  518. /** 
  519. * Set options to make SP as fast as possible 
  520. * Forgoes a substantial amount of data sanitization in favor of speed. This 
  521. * turns SimplePie into a dumb parser of feeds. 
  522. * @param bool $set Whether to set them or not 
  523. */ 
  524. public function set_stupidly_fast($set = false) 
  525. if ($set) 
  526. $this->enable_order_by_date(false); 
  527. $this->remove_div(false); 
  528. $this->strip_comments(false); 
  529. $this->strip_htmltags(false); 
  530. $this->strip_attributes(false); 
  531. $this->set_image_handler(false); 
  532.  
  533. /** 
  534. * Set maximum number of feeds to check with autodiscovery 
  535. * @param int $max Maximum number of feeds to check 
  536. */ 
  537. public function set_max_checked_feeds($max = 10) 
  538. $this->max_checked_feeds = (int) $max; 
  539.  
  540. public function remove_div($enable = true) 
  541. $this->sanitize->remove_div($enable); 
  542.  
  543. public function strip_htmltags($tags = '', $encode = null) 
  544. if ($tags === '') 
  545. $tags = $this->strip_htmltags; 
  546. $this->sanitize->strip_htmltags($tags); 
  547. if ($encode !== null) 
  548. $this->sanitize->encode_instead_of_strip($tags); 
  549.  
  550. public function encode_instead_of_strip($enable = true) 
  551. $this->sanitize->encode_instead_of_strip($enable); 
  552.  
  553. public function strip_attributes($attribs = '') 
  554. if ($attribs === '') 
  555. $attribs = $this->strip_attributes; 
  556. $this->sanitize->strip_attributes($attribs); 
  557.  
  558. /** 
  559. * Set the output encoding 
  560. * Allows you to override SimplePie's output to match that of your webpage. 
  561. * This is useful for times when your webpages are not being served as 
  562. * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and 
  563. * is similar to {@see set_input_encoding()}. 
  564. * It should be noted, however, that not all character encodings can support 
  565. * all characters. If your page is being served as ISO-8859-1 and you try 
  566. * to display a Japanese feed, you'll likely see garbled characters. 
  567. * Because of this, it is highly recommended to ensure that your webpages 
  568. * are served as UTF-8. 
  569. * The number of supported character encodings depends on whether your web 
  570. * host supports {@link http://php.net/mbstring mbstring},  
  571. * {@link http://php.net/iconv iconv}, or both. See 
  572. * {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for 
  573. * more information. 
  574. * @param string $encoding 
  575. */ 
  576. public function set_output_encoding($encoding = 'UTF-8') 
  577. $this->sanitize->set_output_encoding($encoding); 
  578.  
  579. public function strip_comments($strip = false) 
  580. $this->sanitize->strip_comments($strip); 
  581.  
  582. /** 
  583. * Set element/attribute key/value pairs of HTML attributes 
  584. * containing URLs that need to be resolved relative to the feed 
  585. * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,  
  586. * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,  
  587. * |q|@cite 
  588. * @since 1.0 
  589. * @param array|null $element_attribute Element/attribute key/value pairs, null for default 
  590. */ 
  591. public function set_url_replacements($element_attribute = null) 
  592. $this->sanitize->set_url_replacements($element_attribute); 
  593.  
  594. /** 
  595. * Set the handler to enable the display of cached images. 
  596. * @param str $page Web-accessible path to the handler_image.php file. 
  597. * @param str $qs The query string that the value should be passed to. 
  598. */ 
  599. public function set_image_handler($page = false, $qs = 'i') 
  600. if ($page !== false) 
  601. $this->sanitize->set_image_handler($page . '?' . $qs . '='); 
  602. else 
  603. $this->image_handler = ''; 
  604.  
  605. /** 
  606. * Set the limit for items returned per-feed with multifeeds 
  607. * @param integer $limit The maximum number of items to return. 
  608. */ 
  609. public function set_item_limit($limit = 0) 
  610. $this->item_limit = (int) $limit; 
  611.  
  612. /** 
  613. * Initialize the feed object 
  614. * This is what makes everything happen. Period. This is where all of the 
  615. * configuration options get processed, feeds are fetched, cached, and 
  616. * parsed, and all of that other good stuff. 
  617. * @return boolean True if successful, false otherwise 
  618. */ 
  619. public function init() 
  620. // Check absolute bare minimum requirements. 
  621. if (!extension_loaded('xml') || !extension_loaded('pcre')) 
  622. return false; 
  623. // 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. 
  624. elseif (!extension_loaded('xmlreader')) 
  625. static $xml_is_sane = null; 
  626. if ($xml_is_sane === null) 
  627. $parser_check = xml_parser_create(); 
  628. xml_parse_into_struct($parser_check, '<foo>&</foo>', $values); 
  629. xml_parser_free($parser_check); 
  630. $xml_is_sane = isset($values[0]['value']); 
  631. if (!$xml_is_sane) 
  632. return false; 
  633.  
  634. if (method_exists($this->sanitize, 'set_registry')) 
  635. $this->sanitize->set_registry($this->registry); 
  636.  
  637. // Pass whatever was set with config options over to the sanitizer. 
  638. // Pass the classes in for legacy support; new classes should use the registry instead 
  639. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache')); 
  640. $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen); 
  641.  
  642. if (!empty($this->multifeed_url)) 
  643. $i = 0; 
  644. $success = 0; 
  645. $this->multifeed_objects = array(); 
  646. $this->error = array(); 
  647. foreach ($this->multifeed_url as $url) 
  648. $this->multifeed_objects[$i] = clone $this; 
  649. $this->multifeed_objects[$i]->set_feed_url($url); 
  650. $single_success = $this->multifeed_objects[$i]->init(); 
  651. $success |= $single_success; 
  652. if (!$single_success) 
  653. $this->error[$i] = $this->multifeed_objects[$i]->error(); 
  654. $i++; 
  655. return (bool) $success; 
  656. elseif ($this->feed_url === null && $this->raw_data === null) 
  657. return false; 
  658.  
  659. $this->error = null; 
  660. $this->data = array(); 
  661. $this->multifeed_objects = array(); 
  662. $cache = false; 
  663.  
  664. if ($this->feed_url !== null) 
  665. $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url)); 
  666.  
  667. // Decide whether to enable caching 
  668. if ($this->cache && $parsed_feed_url['scheme'] !== '') 
  669. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc')); 
  670.  
  671. // Fetch the data via SimplePie_File into $this->raw_data 
  672. if (($fetched = $this->fetch_data($cache)) === true) 
  673. return true; 
  674. elseif ($fetched === false) { 
  675. return false; 
  676.  
  677. list($headers, $sniffed) = $fetched; 
  678.  
  679. // Set up array of possible encodings 
  680. $encodings = array(); 
  681.  
  682. // First check to see if input has been overridden. 
  683. if ($this->input_encoding !== false) 
  684. $encodings[] = $this->input_encoding; 
  685.  
  686. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity'); 
  687. $text_types = array('text/xml', 'text/xml-external-parsed-entity'); 
  688.  
  689. // RFC 3023 (only applies to sniffed content) 
  690. if (isset($sniffed)) 
  691. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml') 
  692. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) 
  693. $encodings[] = strtoupper($charset[1]); 
  694. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry))); 
  695. $encodings[] = 'UTF-8'; 
  696. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') 
  697. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) 
  698. $encodings[] = $charset[1]; 
  699. $encodings[] = 'US-ASCII'; 
  700. // Text MIME-type default 
  701. elseif (substr($sniffed, 0, 5) === 'text/') 
  702. $encodings[] = 'US-ASCII'; 
  703.  
  704. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1 
  705. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry))); 
  706. $encodings[] = 'UTF-8'; 
  707. $encodings[] = 'ISO-8859-1'; 
  708.  
  709. // There's no point in trying an encoding twice 
  710. $encodings = array_unique($encodings); 
  711.  
  712. // Loop through each possible encoding, till we return something, or run out of possibilities 
  713. foreach ($encodings as $encoding) 
  714. // Change the encoding to UTF-8 (as we always use UTF-8 internally) 
  715. if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8'))) 
  716. // Create new parser 
  717. $parser = $this->registry->create('Parser'); 
  718.  
  719. // If it's parsed fine 
  720. if ($parser->parse($utf8_data, 'UTF-8')) 
  721. $this->data = $parser->get_data(); 
  722. if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE)) 
  723. $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed."; 
  724. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 
  725. return false; 
  726.  
  727. if (isset($headers)) 
  728. $this->data['headers'] = $headers; 
  729. $this->data['build'] = SIMPLEPIE_BUILD; 
  730.  
  731. // Cache the file if caching is enabled 
  732. if ($cache && !$cache->save($this)) 
  733. 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); 
  734. return true; 
  735.  
  736. if (isset($parser)) 
  737. // We have an error, just set SimplePie_Misc::error to it and quit 
  738. $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()); 
  739. else 
  740. $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.'; 
  741.  
  742. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 
  743.  
  744. return false; 
  745.  
  746. /** 
  747. * Fetch the data via SimplePie_File 
  748. * If the data is already cached, attempt to fetch it from there instead 
  749. * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache 
  750. * @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type 
  751. */ 
  752. protected function fetch_data(&$cache) 
  753. // If it's enabled, use the cache 
  754. if ($cache) 
  755. // Load the Cache 
  756. $this->data = $cache->load(); 
  757. if (!empty($this->data)) 
  758. // If the cache is for an outdated build of SimplePie 
  759. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD) 
  760. $cache->unlink(); 
  761. $this->data = array(); 
  762. // If we've hit a collision just rerun it with caching disabled 
  763. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url) 
  764. $cache = false; 
  765. $this->data = array(); 
  766. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL. 
  767. elseif (isset($this->data['feed_url'])) 
  768. // If the autodiscovery cache is still valid use it. 
  769. if ($cache->mtime() + $this->autodiscovery_cache_duration > time()) 
  770. // Do not need to do feed autodiscovery yet. 
  771. if ($this->data['feed_url'] !== $this->data['url']) 
  772. $this->set_feed_url($this->data['feed_url']); 
  773. return $this->init(); 
  774.  
  775. $cache->unlink(); 
  776. $this->data = array(); 
  777. // Check if the cache has been updated 
  778. elseif ($cache->mtime() + $this->cache_duration < time()) 
  779. // If we have last-modified and/or etag set 
  780. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag'])) 
  781. $headers = array( 
  782. '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',  
  783. ); 
  784. if (isset($this->data['headers']['last-modified'])) 
  785. $headers['if-modified-since'] = $this->data['headers']['last-modified']; 
  786. if (isset($this->data['headers']['etag'])) 
  787. $headers['if-none-match'] = $this->data['headers']['etag']; 
  788.   
  789. $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen)); 
  790.   
  791. if ($file->success) 
  792. if ($file->status_code === 304) 
  793. $cache->touch(); 
  794. return true; 
  795. else 
  796. unset($file); 
  797. // If the cache is still valid, just return true 
  798. else 
  799. $this->raw_data = false; 
  800. return true; 
  801. // If the cache is empty, delete it 
  802. else 
  803. $cache->unlink(); 
  804. $this->data = array(); 
  805. // 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. 
  806. if (!isset($file)) 
  807. if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url) 
  808. $file =& $this->file; 
  809. else 
  810. $headers = array( 
  811. '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',  
  812. ); 
  813. $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen)); 
  814. // If the file connection has an error, set SimplePie::error to that and quit 
  815. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) 
  816. $this->error = $file->error; 
  817. return !empty($this->data); 
  818.  
  819. if (!$this->force_feed) 
  820. // Check if the supplied URL is a feed, if it isn't, look for it. 
  821. $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds)); 
  822.  
  823. if (!$locate->is_feed($file)) 
  824. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched 
  825. unset($file); 
  826. try 
  827. if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))) 
  828. $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."; 
  829. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__)); 
  830. return false; 
  831. catch (SimplePie_Exception $e) 
  832. // This is usually because DOMDocument doesn't exist 
  833. $this->error = $e->getMessage(); 
  834. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine())); 
  835. return false; 
  836. if ($cache) 
  837. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD); 
  838. if (!$cache->save($this)) 
  839. 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); 
  840. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc')); 
  841. $this->feed_url = $file->url; 
  842. $locate = null; 
  843.  
  844. $this->raw_data = $file->body; 
  845.  
  846. $headers = $file->headers; 
  847. $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file)); 
  848. $sniffed = $sniffer->get_type(); 
  849.  
  850. return array($headers, $sniffed); 
  851.  
  852. /** 
  853. * Get the error message for the occurred error. 
  854. * @return string|array Error message, or array of messages for multifeeds 
  855. */ 
  856. public function error() 
  857. return $this->error; 
  858.  
  859. /** 
  860. * Get the raw XML 
  861. * This is the same as the old `$feed->enable_xml_dump(true)`, but returns 
  862. * the data instead of printing it. 
  863. * @return string|boolean Raw XML data, false if the cache is used 
  864. */ 
  865. public function get_raw_data() 
  866. return $this->raw_data; 
  867.  
  868. /** 
  869. * Get the character encoding used for output 
  870. * @since Preview Release 
  871. * @return string 
  872. */ 
  873. public function get_encoding() 
  874. return $this->sanitize->output_encoding; 
  875.  
  876. /** 
  877. * Send the content-type header with correct encoding 
  878. * This method ensures that the SimplePie-enabled page is being served with 
  879. * the correct {@link http://www.iana.org/assignments/media-types/ mime-type} 
  880. * and character encoding HTTP headers (character encoding determined by the 
  881. * {@see set_output_encoding} config option). 
  882. * This won't work properly if any content or whitespace has already been 
  883. * sent to the browser, because it relies on PHP's 
  884. * {@link http://php.net/header header()} function, and these are the 
  885. * circumstances under which the function works. 
  886. * Because it's setting these settings for the entire page (as is the nature 
  887. * of HTTP headers), this should only be used once per page (again, at the 
  888. * top). 
  889. * @param string $mime MIME type to serve the page as 
  890. */ 
  891. public function handle_content_type($mime = 'text/html') 
  892. if (!headers_sent()) 
  893. $header = "Content-type: $mime;"; 
  894. if ($this->get_encoding()) 
  895. $header .= ' charset=' . $this->get_encoding(); 
  896. else 
  897. $header .= ' charset=UTF-8'; 
  898. header($header); 
  899.  
  900. /** 
  901. * Get the type of the feed 
  902. * This returns a SIMPLEPIE_TYPE_* constant, which can be tested against 
  903. * using {@link http://php.net/language.operators.bitwise bitwise operators} 
  904. * @since 0.8 (usage changed to using constants in 1.0) 
  905. * @see SIMPLEPIE_TYPE_NONE Unknown. 
  906. * @see SIMPLEPIE_TYPE_RSS_090 RSS 0.90. 
  907. * @see SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape). 
  908. * @see SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland). 
  909. * @see SIMPLEPIE_TYPE_RSS_091 RSS 0.91. 
  910. * @see SIMPLEPIE_TYPE_RSS_092 RSS 0.92. 
  911. * @see SIMPLEPIE_TYPE_RSS_093 RSS 0.93. 
  912. * @see SIMPLEPIE_TYPE_RSS_094 RSS 0.94. 
  913. * @see SIMPLEPIE_TYPE_RSS_10 RSS 1.0. 
  914. * @see SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x. 
  915. * @see SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS. 
  916. * @see SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format). 
  917. * @see SIMPLEPIE_TYPE_RSS_ALL Any version of RSS. 
  918. * @see SIMPLEPIE_TYPE_ATOM_03 Atom 0.3. 
  919. * @see SIMPLEPIE_TYPE_ATOM_10 Atom 1.0. 
  920. * @see SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom. 
  921. * @see SIMPLEPIE_TYPE_ALL Any known/supported feed type. 
  922. * @return int SIMPLEPIE_TYPE_* constant 
  923. */ 
  924. public function get_type() 
  925. if (!isset($this->data['type'])) 
  926. $this->data['type'] = SIMPLEPIE_TYPE_ALL; 
  927. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'])) 
  928. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10; 
  929. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'])) 
  930. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03; 
  931. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'])) 
  932. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel']) 
  933. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image']) 
  934. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']) 
  935. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput'])) 
  936. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10; 
  937. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel']) 
  938. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image']) 
  939. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']) 
  940. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput'])) 
  941. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090; 
  942. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'])) 
  943. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL; 
  944. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) 
  945. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version'])) 
  946. case '0.91': 
  947. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091; 
  948. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) 
  949. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data'])) 
  950. case '0': 
  951. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE; 
  952. break; 
  953.  
  954. case '24': 
  955. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND; 
  956. break; 
  957. break; 
  958.  
  959. case '0.92': 
  960. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092; 
  961. break; 
  962.  
  963. case '0.93': 
  964. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093; 
  965. break; 
  966.  
  967. case '0.94': 
  968. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094; 
  969. break; 
  970.  
  971. case '2.0': 
  972. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20; 
  973. break; 
  974. else 
  975. $this->data['type'] = SIMPLEPIE_TYPE_NONE; 
  976. return $this->data['type']; 
  977.  
  978. /** 
  979. * Get the URL for the feed 
  980. * May or may not be different from the URL passed to {@see set_feed_url()},  
  981. * depending on whether auto-discovery was used. 
  982. * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.) 
  983. * @todo If we have a perm redirect we should return the new URL 
  984. * @todo When we make the above change, let's support <itunes:new-feed-url> as well 
  985. * @todo Also, |atom:link|@rel=self 
  986. * @return string|null 
  987. */ 
  988. public function subscribe_url() 
  989. if ($this->feed_url !== null) 
  990. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI); 
  991. else 
  992. return null; 
  993.  
  994. /** 
  995. * Get data for an feed-level element 
  996. * This method allows you to get access to ANY element/attribute that is a 
  997. * sub-element of the opening feed tag. 
  998. * The return value is an indexed array of elements matching the given 
  999. * namespace and tag name. Each element has `attribs`, `data` and `child` 
  1000. * subkeys. For `attribs` and `child`, these contain namespace subkeys. 
  1001. * `attribs` then has one level of associative name => value data (where 
  1002. * `value` is a string) after the namespace. `child` has tag-indexed keys 
  1003. * after the namespace, each member of which is an indexed array matching 
  1004. * this same format. 
  1005. * For example: 
  1006. * <pre> 
  1007. * // This is probably a bad example because we already support 
  1008. * // <media:content> natively, but it shows you how to parse through 
  1009. * // the nodes. 
  1010. * $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group'); 
  1011. * $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']; 
  1012. * $file = $content[0]['attribs']['']['url']; 
  1013. * echo $file; 
  1014. * </pre> 
  1015. * @since 1.0 
  1016. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces 
  1017. * @param string $namespace The URL of the XML namespace of the elements you're trying to access 
  1018. * @param string $tag Tag name 
  1019. * @return array 
  1020. */ 
  1021. public function get_feed_tags($namespace, $tag) 
  1022. $type = $this->get_type(); 
  1023. if ($type & SIMPLEPIE_TYPE_ATOM_10) 
  1024. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag])) 
  1025. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]; 
  1026. if ($type & SIMPLEPIE_TYPE_ATOM_03) 
  1027. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag])) 
  1028. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]; 
  1029. if ($type & SIMPLEPIE_TYPE_RSS_RDF) 
  1030. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag])) 
  1031. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]; 
  1032. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 
  1033. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag])) 
  1034. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]; 
  1035. return null; 
  1036.  
  1037. /** 
  1038. * Get data for an channel-level element 
  1039. * This method allows you to get access to ANY element/attribute in the 
  1040. * channel/header section of the feed. 
  1041. * See {@see SimplePie::get_feed_tags()} for a description of the return value 
  1042. * @since 1.0 
  1043. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces 
  1044. * @param string $namespace The URL of the XML namespace of the elements you're trying to access 
  1045. * @param string $tag Tag name 
  1046. * @return array 
  1047. */ 
  1048. public function get_channel_tags($namespace, $tag) 
  1049. $type = $this->get_type(); 
  1050. if ($type & SIMPLEPIE_TYPE_ATOM_ALL) 
  1051. if ($return = $this->get_feed_tags($namespace, $tag)) 
  1052. return $return; 
  1053. if ($type & SIMPLEPIE_TYPE_RSS_10) 
  1054. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel')) 
  1055. if (isset($channel[0]['child'][$namespace][$tag])) 
  1056. return $channel[0]['child'][$namespace][$tag]; 
  1057. if ($type & SIMPLEPIE_TYPE_RSS_090) 
  1058. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel')) 
  1059. if (isset($channel[0]['child'][$namespace][$tag])) 
  1060. return $channel[0]['child'][$namespace][$tag]; 
  1061. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 
  1062. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel')) 
  1063. if (isset($channel[0]['child'][$namespace][$tag])) 
  1064. return $channel[0]['child'][$namespace][$tag]; 
  1065. return null; 
  1066.  
  1067. /** 
  1068. * Get data for an channel-level element 
  1069. * This method allows you to get access to ANY element/attribute in the 
  1070. * image/logo section of the feed. 
  1071. * See {@see SimplePie::get_feed_tags()} for a description of the return value 
  1072. * @since 1.0 
  1073. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces 
  1074. * @param string $namespace The URL of the XML namespace of the elements you're trying to access 
  1075. * @param string $tag Tag name 
  1076. * @return array 
  1077. */ 
  1078. public function get_image_tags($namespace, $tag) 
  1079. $type = $this->get_type(); 
  1080. if ($type & SIMPLEPIE_TYPE_RSS_10) 
  1081. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image')) 
  1082. if (isset($image[0]['child'][$namespace][$tag])) 
  1083. return $image[0]['child'][$namespace][$tag]; 
  1084. if ($type & SIMPLEPIE_TYPE_RSS_090) 
  1085. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image')) 
  1086. if (isset($image[0]['child'][$namespace][$tag])) 
  1087. return $image[0]['child'][$namespace][$tag]; 
  1088. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION) 
  1089. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image')) 
  1090. if (isset($image[0]['child'][$namespace][$tag])) 
  1091. return $image[0]['child'][$namespace][$tag]; 
  1092. return null; 
  1093.  
  1094. /** 
  1095. * Get the base URL value from the feed 
  1096. * Uses `<xml:base>` if available, otherwise uses the first link in the 
  1097. * feed, or failing that, the URL of the feed itself. 
  1098. * @see get_link 
  1099. * @see subscribe_url 
  1100. * @param array $element 
  1101. * @return string 
  1102. */ 
  1103. public function get_base($element = array()) 
  1104. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) 
  1105. return $element['xml_base']; 
  1106. elseif ($this->get_link() !== null) 
  1107. return $this->get_link(); 
  1108. else 
  1109. return $this->subscribe_url(); 
  1110.  
  1111. /** 
  1112. * Sanitize feed data 
  1113. * @access private 
  1114. * @see SimplePie_Sanitize::sanitize() 
  1115. * @param string $data Data to sanitize 
  1116. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants 
  1117. * @param string $base Base URL to resolve URLs against 
  1118. * @return string Sanitized data 
  1119. */ 
  1120. public function sanitize($data, $type, $base = '') 
  1121. return $this->sanitize->sanitize($data, $type, $base); 
  1122.  
  1123. /** 
  1124. * Get the title of the feed 
  1125. * Uses `<atom:title>`, `<title>` or `<dc:title>` 
  1126. * @since 1.0 (previously called `get_feed_title` since 0.8) 
  1127. * @return string|null 
  1128. */ 
  1129. public function get_title() 
  1130. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title')) 
  1131. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1132. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title')) 
  1133. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1134. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 
  1135. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1136. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 
  1137. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1138. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 
  1139. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1140. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 
  1141. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1142. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 
  1143. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1144. else 
  1145. return null; 
  1146.  
  1147. /** 
  1148. * Get a category for the feed 
  1149. * @since Unknown 
  1150. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1 
  1151. * @return SimplePie_Category|null 
  1152. */ 
  1153. public function get_category($key = 0) 
  1154. $categories = $this->get_categories(); 
  1155. if (isset($categories[$key])) 
  1156. return $categories[$key]; 
  1157. else 
  1158. return null; 
  1159.  
  1160. /** 
  1161. * Get all categories for the feed 
  1162. * Uses `<atom:category>`, `<category>` or `<dc:subject>` 
  1163. * @since Unknown 
  1164. * @return array|null List of {@see SimplePie_Category} objects 
  1165. */ 
  1166. public function get_categories() 
  1167. $categories = array(); 
  1168.  
  1169. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category) 
  1170. $term = null; 
  1171. $scheme = null; 
  1172. $label = null; 
  1173. if (isset($category['attribs']['']['term'])) 
  1174. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1175. if (isset($category['attribs']['']['scheme'])) 
  1176. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1177. if (isset($category['attribs']['']['label'])) 
  1178. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1179. $categories[] = $this->registry->create('Category', array($term, $scheme, $label)); 
  1180. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category) 
  1181. // This is really the label, but keep this as the term also for BC. 
  1182. // Label will also work on retrieving because that falls back to term. 
  1183. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1184. if (isset($category['attribs']['']['domain'])) 
  1185. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1186. else 
  1187. $scheme = null; 
  1188. $categories[] = $this->registry->create('Category', array($term, $scheme, null)); 
  1189. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category) 
  1190. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1191. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category) 
  1192. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1193.  
  1194. if (!empty($categories)) 
  1195. return array_unique($categories); 
  1196. else 
  1197. return null; 
  1198.  
  1199. /** 
  1200. * Get an author for the feed 
  1201. * @since 1.1 
  1202. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1 
  1203. * @return SimplePie_Author|null 
  1204. */ 
  1205. public function get_author($key = 0) 
  1206. $authors = $this->get_authors(); 
  1207. if (isset($authors[$key])) 
  1208. return $authors[$key]; 
  1209. else 
  1210. return null; 
  1211.  
  1212. /** 
  1213. * Get all authors for the feed 
  1214. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>` 
  1215. * @since 1.1 
  1216. * @return array|null List of {@see SimplePie_Author} objects 
  1217. */ 
  1218. public function get_authors() 
  1219. $authors = array(); 
  1220. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author) 
  1221. $name = null; 
  1222. $uri = null; 
  1223. $email = null; 
  1224. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 
  1225. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1226. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 
  1227. $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])); 
  1228. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 
  1229. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1230. if ($name !== null || $email !== null || $uri !== null) 
  1231. $authors[] = $this->registry->create('Author', array($name, $uri, $email)); 
  1232. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author')) 
  1233. $name = null; 
  1234. $url = null; 
  1235. $email = null; 
  1236. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 
  1237. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1238. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 
  1239. $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])); 
  1240. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 
  1241. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1242. if ($name !== null || $email !== null || $url !== null) 
  1243. $authors[] = $this->registry->create('Author', array($name, $url, $email)); 
  1244. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) 
  1245. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1246. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) 
  1247. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1248. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) 
  1249. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); 
  1250.  
  1251. if (!empty($authors)) 
  1252. return array_unique($authors); 
  1253. else 
  1254. return null; 
  1255.  
  1256. /** 
  1257. * Get a contributor for the feed 
  1258. * @since 1.1 
  1259. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1 
  1260. * @return SimplePie_Author|null 
  1261. */ 
  1262. public function get_contributor($key = 0) 
  1263. $contributors = $this->get_contributors(); 
  1264. if (isset($contributors[$key])) 
  1265. return $contributors[$key]; 
  1266. else 
  1267. return null; 
  1268.  
  1269. /** 
  1270. * Get all contributors for the feed 
  1271. * Uses `<atom:contributor>` 
  1272. * @since 1.1 
  1273. * @return array|null List of {@see SimplePie_Author} objects 
  1274. */ 
  1275. public function get_contributors() 
  1276. $contributors = array(); 
  1277. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor) 
  1278. $name = null; 
  1279. $uri = null; 
  1280. $email = null; 
  1281. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) 
  1282. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1283. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) 
  1284. $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])); 
  1285. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) 
  1286. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1287. if ($name !== null || $email !== null || $uri !== null) 
  1288. $contributors[] = $this->registry->create('Author', array($name, $uri, $email)); 
  1289. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor) 
  1290. $name = null; 
  1291. $url = null; 
  1292. $email = null; 
  1293. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) 
  1294. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1295. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) 
  1296. $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])); 
  1297. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) 
  1298. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1299. if ($name !== null || $email !== null || $url !== null) 
  1300. $contributors[] = $this->registry->create('Author', array($name, $url, $email)); 
  1301.  
  1302. if (!empty($contributors)) 
  1303. return array_unique($contributors); 
  1304. else 
  1305. return null; 
  1306.  
  1307. /** 
  1308. * Get a single link for the feed 
  1309. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8) 
  1310. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1 
  1311. * @param string $rel The relationship of the link to return 
  1312. * @return string|null Link URL 
  1313. */ 
  1314. public function get_link($key = 0, $rel = 'alternate') 
  1315. $links = $this->get_links($rel); 
  1316. if (isset($links[$key])) 
  1317. return $links[$key]; 
  1318. else 
  1319. return null; 
  1320.  
  1321. /** 
  1322. * Get the permalink for the item 
  1323. * Returns the first link available with a relationship of "alternate". 
  1324. * Identical to {@see get_link()} with key 0 
  1325. * @see get_link 
  1326. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8) 
  1327. * @internal Added for parity between the parent-level and the item/entry-level. 
  1328. * @return string|null Link URL 
  1329. */ 
  1330. public function get_permalink() 
  1331. return $this->get_link(0); 
  1332.  
  1333. /** 
  1334. * Get all links for the feed 
  1335. * Uses `<atom:link>` or `<link>` 
  1336. * @since Beta 2 
  1337. * @param string $rel The relationship of links to return 
  1338. * @return array|null Links found for the feed (strings) 
  1339. */ 
  1340. public function get_links($rel = 'alternate') 
  1341. if (!isset($this->data['links'])) 
  1342. $this->data['links'] = array(); 
  1343. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link')) 
  1344. foreach ($links as $link) 
  1345. if (isset($link['attribs']['']['href'])) 
  1346. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 
  1347. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 
  1348. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link')) 
  1349. foreach ($links as $link) 
  1350. if (isset($link['attribs']['']['href'])) 
  1351. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate'; 
  1352. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link)); 
  1353.  
  1354. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 
  1355. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  1356. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 
  1357. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  1358. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 
  1359. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0])); 
  1360.  
  1361. $keys = array_keys($this->data['links']); 
  1362. foreach ($keys as $key) 
  1363. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key))) 
  1364. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key])) 
  1365. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]); 
  1366. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]; 
  1367. else 
  1368. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key]; 
  1369. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY) 
  1370. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key]; 
  1371. $this->data['links'][$key] = array_unique($this->data['links'][$key]); 
  1372.  
  1373. if (isset($this->data['links'][$rel])) 
  1374. return $this->data['links'][$rel]; 
  1375. else 
  1376. return null; 
  1377.  
  1378. public function get_all_discovered_feeds() 
  1379. return $this->all_discovered_feeds; 
  1380.  
  1381. /** 
  1382. * Get the content for the item 
  1383. * Uses `<atom:subtitle>`, `<atom:tagline>`, `<description>`,  
  1384. * `<dc:description>`, `<itunes:summary>` or `<itunes:subtitle>` 
  1385. * @since 1.0 (previously called `get_feed_description()` since 0.8) 
  1386. * @return string|null 
  1387. */ 
  1388. public function get_description() 
  1389. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle')) 
  1390. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1391. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline')) 
  1392. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1393. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) 
  1394. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1395. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) 
  1396. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); 
  1397. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) 
  1398. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  1399. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) 
  1400. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1401. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) 
  1402. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1403. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) 
  1404. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  1405. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) 
  1406. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); 
  1407. else 
  1408. return null; 
  1409.  
  1410. /** 
  1411. * Get the copyright info for the feed 
  1412. * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>` 
  1413. * @since 1.0 (previously called `get_feed_copyright()` since 0.8) 
  1414. * @return string|null 
  1415. */ 
  1416. public function get_copyright() 
  1417. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights')) 
  1418. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1419. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright')) 
  1420. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0])); 
  1421. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright')) 
  1422. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1423. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights')) 
  1424. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1425. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights')) 
  1426. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1427. else 
  1428. return null; 
  1429.  
  1430. /** 
  1431. * Get the language for the feed 
  1432. * Uses `<language>`, `<dc:language>`, or @xml_lang 
  1433. * @since 1.0 (previously called `get_feed_language()` since 0.8) 
  1434. * @return string|null 
  1435. */ 
  1436. public function get_language() 
  1437. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language')) 
  1438. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1439. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language')) 
  1440. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1441. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language')) 
  1442. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1443. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'])) 
  1444. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1445. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'])) 
  1446. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1447. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'])) 
  1448. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1449. elseif (isset($this->data['headers']['content-language'])) 
  1450. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1451. else 
  1452. return null; 
  1453.  
  1454. /** 
  1455. * Get the latitude coordinates for the item 
  1456. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications 
  1457. * Uses `<geo:lat>` or `<georss:point>` 
  1458. * @since 1.0 
  1459. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 
  1460. * @link http://www.georss.org/ GeoRSS 
  1461. * @return string|null 
  1462. */ 
  1463. public function get_latitude() 
  1464.  
  1465. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat')) 
  1466. return (float) $return[0]['data']; 
  1467. 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)) 
  1468. return (float) $match[1]; 
  1469. else 
  1470. return null; 
  1471.  
  1472. /** 
  1473. * Get the longitude coordinates for the feed 
  1474. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications 
  1475. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>` 
  1476. * @since 1.0 
  1477. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo 
  1478. * @link http://www.georss.org/ GeoRSS 
  1479. * @return string|null 
  1480. */ 
  1481. public function get_longitude() 
  1482. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long')) 
  1483. return (float) $return[0]['data']; 
  1484. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon')) 
  1485. return (float) $return[0]['data']; 
  1486. 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)) 
  1487. return (float) $match[2]; 
  1488. else 
  1489. return null; 
  1490.  
  1491. /** 
  1492. * Get the feed logo's title 
  1493. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title. 
  1494. * Uses `<image><title>` or `<image><dc:title>` 
  1495. * @return string|null 
  1496. */ 
  1497. public function get_image_title() 
  1498. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title')) 
  1499. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1500. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title')) 
  1501. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1502. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title')) 
  1503. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1504. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title')) 
  1505. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1506. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title')) 
  1507. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); 
  1508. else 
  1509. return null; 
  1510.  
  1511. /** 
  1512. * Get the feed logo's URL 
  1513. * RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to 
  1514. * have a "feed logo" URL. This points directly to the image itself. 
  1515. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,  
  1516. * `<image><title>` or `<image><dc:title>` 
  1517. * @return string|null 
  1518. */ 
  1519. public function get_image_url() 
  1520. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image')) 
  1521. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI); 
  1522. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo')) 
  1523. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1524. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon')) 
  1525. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1526. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url')) 
  1527. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1528. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url')) 
  1529. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1530. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 
  1531. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1532. else 
  1533. return null; 
  1534.  
  1535.  
  1536. /** 
  1537. * Get the feed logo's link 
  1538. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This 
  1539. * points to a human-readable page that the image should link to. 
  1540. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,  
  1541. * `<image><title>` or `<image><dc:title>` 
  1542. * @return string|null 
  1543. */ 
  1544. public function get_image_link() 
  1545. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link')) 
  1546. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1547. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link')) 
  1548. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1549. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link')) 
  1550. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); 
  1551. else 
  1552. return null; 
  1553.  
  1554. /** 
  1555. * Get the feed logo's link 
  1556. * RSS 2.0 feeds are allowed to have a "feed logo" width. 
  1557. * Uses `<image><width>` or defaults to 88.0 if no width is specified and 
  1558. * the feed is an RSS 2.0 feed. 
  1559. * @return int|float|null 
  1560. */ 
  1561. public function get_image_width() 
  1562. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width')) 
  1563. return round($return[0]['data']); 
  1564. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 
  1565. return 88.0; 
  1566. else 
  1567. return null; 
  1568.  
  1569. /** 
  1570. * Get the feed logo's height 
  1571. * RSS 2.0 feeds are allowed to have a "feed logo" height. 
  1572. * Uses `<image><height>` or defaults to 31.0 if no height is specified and 
  1573. * the feed is an RSS 2.0 feed. 
  1574. * @return int|float|null 
  1575. */ 
  1576. public function get_image_height() 
  1577. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height')) 
  1578. return round($return[0]['data']); 
  1579. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url')) 
  1580. return 31.0; 
  1581. else 
  1582. return null; 
  1583.  
  1584. /** 
  1585. * Get the number of items in the feed 
  1586. * This is well-suited for {@link http://php.net/for for()} loops with 
  1587. * {@see get_item()} 
  1588. * @param int $max Maximum value to return. 0 for no limit 
  1589. * @return int Number of items in the feed 
  1590. */ 
  1591. public function get_item_quantity($max = 0) 
  1592. $max = (int) $max; 
  1593. $qty = count($this->get_items()); 
  1594. if ($max === 0) 
  1595. return $qty; 
  1596. else 
  1597. return ($qty > $max) ? $max : $qty; 
  1598.  
  1599. /** 
  1600. * Get a single item from the feed 
  1601. * This is better suited for {@link http://php.net/for for()} loops, whereas 
  1602. * {@see get_items()} is better suited for 
  1603. * {@link http://php.net/foreach foreach()} loops. 
  1604. * @see get_item_quantity() 
  1605. * @since Beta 2 
  1606. * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1 
  1607. * @return SimplePie_Item|null 
  1608. */ 
  1609. public function get_item($key = 0) 
  1610. $items = $this->get_items(); 
  1611. if (isset($items[$key])) 
  1612. return $items[$key]; 
  1613. else 
  1614. return null; 
  1615.  
  1616. /** 
  1617. * Get all items from the feed 
  1618. * This is better suited for {@link http://php.net/for for()} loops, whereas 
  1619. * {@see get_items()} is better suited for 
  1620. * {@link http://php.net/foreach foreach()} loops. 
  1621. * @see get_item_quantity 
  1622. * @since Beta 2 
  1623. * @param int $start Index to start at 
  1624. * @param int $end Number of items to return. 0 for all items after `$start` 
  1625. * @return array|null List of {@see SimplePie_Item} objects 
  1626. */ 
  1627. public function get_items($start = 0, $end = 0) 
  1628. if (!isset($this->data['items'])) 
  1629. if (!empty($this->multifeed_objects)) 
  1630. $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit); 
  1631. else 
  1632. $this->data['items'] = array(); 
  1633. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry')) 
  1634. $keys = array_keys($items); 
  1635. foreach ($keys as $key) 
  1636. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  1637. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry')) 
  1638. $keys = array_keys($items); 
  1639. foreach ($keys as $key) 
  1640. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  1641. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item')) 
  1642. $keys = array_keys($items); 
  1643. foreach ($keys as $key) 
  1644. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  1645. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item')) 
  1646. $keys = array_keys($items); 
  1647. foreach ($keys as $key) 
  1648. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  1649. if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item')) 
  1650. $keys = array_keys($items); 
  1651. foreach ($keys as $key) 
  1652. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key])); 
  1653.  
  1654. if (!empty($this->data['items'])) 
  1655. // If we want to order it by date, check if all items have a date, and then sort it 
  1656. if ($this->order_by_date && empty($this->multifeed_objects)) 
  1657. if (!isset($this->data['ordered_items'])) 
  1658. $do_sort = true; 
  1659. foreach ($this->data['items'] as $item) 
  1660. if (!$item->get_date('U')) 
  1661. $do_sort = false; 
  1662. break; 
  1663. $item = null; 
  1664. $this->data['ordered_items'] = $this->data['items']; 
  1665. if ($do_sort) 
  1666. usort($this->data['ordered_items'], array(get_class($this), 'sort_items')); 
  1667. $items = $this->data['ordered_items']; 
  1668. else 
  1669. $items = $this->data['items']; 
  1670.  
  1671. // Slice the data as desired 
  1672. if ($end === 0) 
  1673. return array_slice($items, $start); 
  1674. else 
  1675. return array_slice($items, $start, $end); 
  1676. else 
  1677. return array(); 
  1678.  
  1679. /** 
  1680. * Set the favicon handler 
  1681. * @deprecated Use your own favicon handling instead 
  1682. */ 
  1683. public function set_favicon_handler($page = false, $qs = 'i') 
  1684. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  1685. trigger_error('Favicon handling has been removed, please use your own handling', $level); 
  1686. return false; 
  1687.  
  1688. /** 
  1689. * Get the favicon for the current feed 
  1690. * @deprecated Use your own favicon handling instead 
  1691. */ 
  1692. public function get_favicon() 
  1693. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  1694. trigger_error('Favicon handling has been removed, please use your own handling', $level); 
  1695.  
  1696. if (($url = $this->get_link()) !== null) 
  1697. return 'http://g.etfv.co/' . urlencode($url); 
  1698.  
  1699. return false; 
  1700.  
  1701. /** 
  1702. * Magic method handler 
  1703. * @param string $method Method name 
  1704. * @param array $args Arguments to the method 
  1705. * @return mixed 
  1706. */ 
  1707. public function __call($method, $args) 
  1708. if (strpos($method, 'subscribe_') === 0) 
  1709. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  1710. trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level); 
  1711. return ''; 
  1712. if ($method === 'enable_xml_dump') 
  1713. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; 
  1714. trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level); 
  1715. return false; 
  1716.  
  1717. $class = get_class($this); 
  1718. $trace = debug_backtrace(); 
  1719. $file = $trace[0]['file']; 
  1720. $line = $trace[0]['line']; 
  1721. trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR); 
  1722.  
  1723. /** 
  1724. * Sorting callback for items 
  1725. * @access private 
  1726. * @param SimplePie $a 
  1727. * @param SimplePie $b 
  1728. * @return boolean 
  1729. */ 
  1730. public static function sort_items($a, $b) 
  1731. return $a->get_date('U') <= $b->get_date('U'); 
  1732.  
  1733. /** 
  1734. * Merge items from several feeds into one 
  1735. * If you're merging multiple feeds together, they need to all have dates 
  1736. * for the items or else SimplePie will refuse to sort them. 
  1737. * @link http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date#if_feeds_require_separate_per-feed_settings 
  1738. * @param array $urls List of SimplePie feed objects to merge 
  1739. * @param int $start Starting item 
  1740. * @param int $end Number of items to return 
  1741. * @param int $limit Maximum number of items per feed 
  1742. * @return array 
  1743. */ 
  1744. public static function merge_items($urls, $start = 0, $end = 0, $limit = 0) 
  1745. if (is_array($urls) && sizeof($urls) > 0) 
  1746. $items = array(); 
  1747. foreach ($urls as $arg) 
  1748. if ($arg instanceof SimplePie) 
  1749. $items = array_merge($items, $arg->get_items(0, $limit)); 
  1750. else 
  1751. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING); 
  1752.  
  1753. $do_sort = true; 
  1754. foreach ($items as $item) 
  1755. if (!$item->get_date('U')) 
  1756. $do_sort = false; 
  1757. break; 
  1758. $item = null; 
  1759. if ($do_sort) 
  1760. usort($items, array(get_class($urls[0]), 'sort_items')); 
  1761.  
  1762. if ($end === 0) 
  1763. return array_slice($items, $start); 
  1764. else 
  1765. return array_slice($items, $start, $end); 
  1766. else 
  1767. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); 
  1768. return array();