PageRenderTime 62ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/library/Simplepie/Feed.php

https://bitbucket.org/aukhanev/xdn-wordpress31
PHP | 2787 lines | 1909 code | 189 blank | 689 comment | 218 complexity | d32b589e88017991afc4aa63c5922794 MD5 | raw file
  1. <?php
  2. /**
  3. * Simplepie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-2011, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the Simplepie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package Simplepie
  36. * @version 1.2.1
  37. * @copyright 2004-2011 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  38. * @author Ryan Parman
  39. * @author Geoffrey Sneddon
  40. * @author Ryan McCue
  41. * @link http://simplepie.org/ Simplepie
  42. * @link http://simplepie.org/support/ Please submit all bug reports and feature requests to the Simplepie forums
  43. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  44. * @todo phpDoc comments
  45. */
  46. /* This is here for the constants. Remove in stand-alone version. */
  47. require_once(ABSPATH . WPINC . '/class-simplepie.php');
  48. /**
  49. * Simplepie
  50. *
  51. * @package Simplepie
  52. */
  53. class Simplepie_Feed {
  54. /**
  55. * @var array Raw data
  56. * @access private
  57. */
  58. var $data = array();
  59. /**
  60. * @var mixed Error string
  61. * @access private
  62. */
  63. var $error;
  64. /**
  65. * @var object Instance of Simplepie_Sanitize (or other class)
  66. * @see Simplepie::set_sanitize_class()
  67. * @access private
  68. */
  69. var $sanitize;
  70. /**
  71. * @var string Simplepie Useragent
  72. * @see Simplepie::set_useragent()
  73. * @access private
  74. */
  75. var $useragent = SIMPLEPIE_USERAGENT;
  76. /**
  77. * @var string Feed URL
  78. * @see Simplepie::set_feed_url()
  79. * @access private
  80. */
  81. var $feed_url;
  82. /**
  83. * @var object Instance of Simplepie_File to use as a feed
  84. * @see Simplepie::set_file()
  85. * @access private
  86. */
  87. var $file;
  88. /**
  89. * @var string Raw feed data
  90. * @see Simplepie::set_raw_data()
  91. * @access private
  92. */
  93. var $raw_data;
  94. /**
  95. * @var int Timeout for fetching remote files
  96. * @see Simplepie::set_timeout()
  97. * @access private
  98. */
  99. var $timeout = 10;
  100. /**
  101. * @var bool Forces fsockopen() to be used for remote files instead
  102. * of cURL, even if a new enough version is installed
  103. * @see Simplepie::force_fsockopen()
  104. * @access private
  105. */
  106. var $force_fsockopen = false;
  107. /**
  108. * @var bool Force the given data/URL to be treated as a feed no matter what
  109. * it appears like
  110. * @see Simplepie::force_feed()
  111. * @access private
  112. */
  113. var $force_feed = false;
  114. /**
  115. * @var bool Enable/Disable XML dump
  116. * @see Simplepie::enable_xml_dump()
  117. * @access private
  118. */
  119. var $xml_dump = false;
  120. /**
  121. * @var bool Enable/Disable Caching
  122. * @see Simplepie::enable_cache()
  123. * @access private
  124. */
  125. var $cache = true;
  126. /**
  127. * @var int Cache duration (in seconds)
  128. * @see Simplepie::set_cache_duration()
  129. * @access private
  130. */
  131. var $cache_duration = 3600;
  132. /**
  133. * @var int Auto-discovery cache duration (in seconds)
  134. * @see Simplepie::set_autodiscovery_cache_duration()
  135. * @access private
  136. */
  137. var $autodiscovery_cache_duration = 604800; // 7 Days.
  138. /**
  139. * @var string Cache location (relative to executing script)
  140. * @see Simplepie::set_cache_location()
  141. * @access private
  142. */
  143. var $cache_location = './cache';
  144. /**
  145. * @var string Function that creates the cache filename
  146. * @see Simplepie::set_cache_name_function()
  147. * @access private
  148. */
  149. var $cache_name_function = 'md5';
  150. /**
  151. * @var bool Reorder feed by date descending
  152. * @see Simplepie::enable_order_by_date()
  153. * @access private
  154. */
  155. var $order_by_date = true;
  156. /**
  157. * @var mixed Force input encoding to be set to the follow value
  158. * (false, or anything type-cast to false, disables this feature)
  159. * @see Simplepie::set_input_encoding()
  160. * @access private
  161. */
  162. var $input_encoding = false;
  163. /**
  164. * @var int Feed Autodiscovery Level
  165. * @see Simplepie::set_autodiscovery_level()
  166. * @access private
  167. */
  168. var $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  169. /**
  170. * @var string Class used for caching feeds
  171. * @see Simplepie::set_cache_class()
  172. * @access private
  173. */
  174. var $cache_class = 'Simplepie_Cache';
  175. /**
  176. * @var string Class used for locating feeds
  177. * @see Simplepie::set_locator_class()
  178. * @access private
  179. */
  180. var $locator_class = 'Simplepie_Locator';
  181. /**
  182. * @var string Class used for parsing feeds
  183. * @see Simplepie::set_parser_class()
  184. * @access private
  185. */
  186. var $parser_class = 'Simplepie_Parser';
  187. /**
  188. * @var string Class used for fetching feeds
  189. * @see Simplepie::set_file_class()
  190. * @access private
  191. */
  192. var $file_class = 'Simplepie_File';
  193. /**
  194. * @var string Class used for items
  195. * @see Simplepie::set_item_class()
  196. * @access private
  197. */
  198. var $item_class = 'Simplepie_Item';
  199. /**
  200. * @var string Class used for authors
  201. * @see Simplepie::set_author_class()
  202. * @access private
  203. */
  204. var $author_class = 'Simplepie_Author';
  205. /**
  206. * @var string Class used for categories
  207. * @see Simplepie::set_category_class()
  208. * @access private
  209. */
  210. var $category_class = 'Simplepie_Category';
  211. /**
  212. * @var string Class used for enclosures
  213. * @see Simplepie::set_enclosures_class()
  214. * @access private
  215. */
  216. var $enclosure_class = 'Simplepie_Enclosure';
  217. /**
  218. * @var string Class used for Media RSS <media:text> captions
  219. * @see Simplepie::set_caption_class()
  220. * @access private
  221. */
  222. var $caption_class = 'Simplepie_Caption';
  223. /**
  224. * @var string Class used for Media RSS <media:copyright>
  225. * @see Simplepie::set_copyright_class()
  226. * @access private
  227. */
  228. var $copyright_class = 'Simplepie_Copyright';
  229. /**
  230. * @var string Class used for Media RSS <media:credit>
  231. * @see Simplepie::set_credit_class()
  232. * @access private
  233. */
  234. var $credit_class = 'Simplepie_Credit';
  235. /**
  236. * @var string Class used for Media RSS <media:rating>
  237. * @see Simplepie::set_rating_class()
  238. * @access private
  239. */
  240. var $rating_class = 'Simplepie_Rating';
  241. /**
  242. * @var string Class used for Media RSS <media:restriction>
  243. * @see Simplepie::set_restriction_class()
  244. * @access private
  245. */
  246. var $restriction_class = 'Simplepie_Restriction';
  247. /**
  248. * @var string Class used for content-type sniffing
  249. * @see Simplepie::set_content_type_sniffer_class()
  250. * @access private
  251. */
  252. var $content_type_sniffer_class = 'Simplepie_Content_Type_Sniffer';
  253. /**
  254. * @var string Class used for item sources.
  255. * @see Simplepie::set_source_class()
  256. * @access private
  257. */
  258. var $source_class = 'Simplepie_Source';
  259. /**
  260. * @var mixed Set javascript query string parameter (false, or
  261. * anything type-cast to false, disables this feature)
  262. * @see Simplepie::set_javascript()
  263. * @access private
  264. */
  265. var $javascript = 'js';
  266. /**
  267. * @var int Maximum number of feeds to check with autodiscovery
  268. * @see Simplepie::set_max_checked_feeds()
  269. * @access private
  270. */
  271. var $max_checked_feeds = 10;
  272. /**
  273. * @var array All the feeds found during the autodiscovery process
  274. * @see Simplepie::get_all_discovered_feeds()
  275. * @access private
  276. */
  277. var $all_discovered_feeds = array();
  278. /**
  279. * @var string Web-accessible path to the handler_favicon.php file.
  280. * @see Simplepie::set_favicon_handler()
  281. * @access private
  282. */
  283. var $favicon_handler = '';
  284. /**
  285. * @var string Web-accessible path to the handler_image.php file.
  286. * @see Simplepie::set_image_handler()
  287. * @access private
  288. */
  289. var $image_handler = '';
  290. /**
  291. * @var array Stores the URLs when multiple feeds are being initialized.
  292. * @see Simplepie::set_feed_url()
  293. * @access private
  294. */
  295. var $multifeed_url = array();
  296. /**
  297. * @var array Stores Simplepie objects when multiple feeds initialized.
  298. * @access private
  299. */
  300. var $multifeed_objects = array();
  301. /**
  302. * @var array Stores the get_object_vars() array for use with multifeeds.
  303. * @see Simplepie::set_feed_url()
  304. * @access private
  305. */
  306. var $config_settings = null;
  307. /**
  308. * @var integer Stores the number of items to return per-feed with multifeeds.
  309. * @see Simplepie::set_item_limit()
  310. * @access private
  311. */
  312. var $item_limit = 0;
  313. /**
  314. * @var array Stores the default attributes to be stripped by strip_attributes().
  315. * @see Simplepie::strip_attributes()
  316. * @access private
  317. */
  318. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  319. /**
  320. * @var array Stores the default tags to be stripped by strip_htmltags().
  321. * @see Simplepie::strip_htmltags()
  322. * @access private
  323. */
  324. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  325. /**
  326. * The Simplepie class contains feed level data and options
  327. *
  328. * There are two ways that you can create a new Simplepie object. The first
  329. * is by passing a feed URL as a parameter to the Simplepie constructor
  330. * (as well as optionally setting the cache location and cache expiry). This
  331. * will initialise the whole feed with all of the default settings, and you
  332. * can begin accessing methods and properties immediately.
  333. *
  334. * The second way is to create the Simplepie object with no parameters
  335. * at all. This will enable you to set configuration options. After setting
  336. * them, you must initialise the feed using $feed->init(). At that point the
  337. * object's methods and properties will be available to you. This format is
  338. * what is used throughout this documentation.
  339. *
  340. * @access public
  341. * @since 1.0 Preview Release
  342. * @param string $feed_url This is the URL you want to parse.
  343. * @param string $cache_location This is where you want the cache to be stored.
  344. * @param int $cache_duration This is the number of seconds that you want to store the cache file for.
  345. */
  346. function Simplepie_Feed($feed_url = null, $cache_location = null, $cache_duration = null) {
  347. // Other objects, instances created here so we can set options on them
  348. $this->sanitize = new Simplepie_Sanitize;
  349. // Adapted for Mage Modules
  350. $this->_construct();
  351. // Set options if they're passed to the constructor
  352. if ($cache_location !== null)
  353. {
  354. $this->set_cache_location($cache_location);
  355. }
  356. if ($cache_duration !== null)
  357. {
  358. $this->set_cache_duration($cache_duration);
  359. }
  360. // Only init the script if we're passed a feed URL
  361. if ($feed_url !== null)
  362. {
  363. $this->set_feed_url($feed_url);
  364. $this->init();
  365. }
  366. }
  367. protected function _construct() {
  368. }
  369. /**
  370. * Used for converting object to a string
  371. */
  372. function __toString()
  373. {
  374. return md5(serialize($this->data));
  375. }
  376. /**
  377. * Remove items that link back to this before destroying this object
  378. */
  379. function __destruct()
  380. {
  381. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  382. {
  383. if (!empty($this->data['items']))
  384. {
  385. foreach ($this->data['items'] as $item)
  386. {
  387. $item->__destruct();
  388. }
  389. unset($item, $this->data['items']);
  390. }
  391. if (!empty($this->data['ordered_items']))
  392. {
  393. foreach ($this->data['ordered_items'] as $item)
  394. {
  395. $item->__destruct();
  396. }
  397. unset($item, $this->data['ordered_items']);
  398. }
  399. }
  400. }
  401. /**
  402. * Force the given data/URL to be treated as a feed no matter what it
  403. * appears like
  404. *
  405. * @access public
  406. * @since 1.1
  407. * @param bool $enable Force the given data/URL to be treated as a feed
  408. */
  409. function force_feed($enable = false)
  410. {
  411. $this->force_feed = (bool) $enable;
  412. }
  413. /**
  414. * This is the URL of the feed you want to parse.
  415. *
  416. * This allows you to enter the URL of the feed you want to parse, or the
  417. * website you want to try to use auto-discovery on. This takes priority
  418. * over any set raw data.
  419. *
  420. * You can set multiple feeds to mash together by passing an array instead
  421. * of a string for the $url. Remember that with each additional feed comes
  422. * additional processing and resources.
  423. *
  424. * @access public
  425. * @since 1.0 Preview Release
  426. * @param mixed $url This is the URL (or array of URLs) that you want to parse.
  427. * @see Simplepie::set_raw_data()
  428. */
  429. function set_feed_url($url)
  430. {
  431. if (is_array($url))
  432. {
  433. $this->multifeed_url = array();
  434. foreach ($url as $value)
  435. {
  436. $this->multifeed_url[] = Simplepie_Misc::fix_protocol($value, 1);
  437. }
  438. }
  439. else
  440. {
  441. $this->feed_url = Simplepie_Misc::fix_protocol($url, 1);
  442. }
  443. }
  444. /**
  445. * Provides an instance of Simplepie_File to use as a feed
  446. *
  447. * @access public
  448. * @param object &$file Instance of Simplepie_File (or subclass)
  449. * @return bool True on success, false on failure
  450. */
  451. function set_file(&$file)
  452. {
  453. if (is_a($file, 'Simplepie_File'))
  454. {
  455. $this->feed_url = $file->url;
  456. $this->file =& $file;
  457. return true;
  458. }
  459. return false;
  460. }
  461. /**
  462. * Allows you to use a string of RSS/Atom data instead of a remote feed.
  463. *
  464. * If you have a feed available as a string in PHP, you can tell Simplepie
  465. * to parse that data string instead of a remote feed. Any set feed URL
  466. * takes precedence.
  467. *
  468. * @access public
  469. * @since 1.0 Beta 3
  470. * @param string $data RSS or Atom data as a string.
  471. * @see Simplepie::set_feed_url()
  472. */
  473. function set_raw_data($data)
  474. {
  475. $this->raw_data = $data;
  476. }
  477. /**
  478. * Allows you to override the default timeout for fetching remote feeds.
  479. *
  480. * This allows you to change the maximum time the feed's server to respond
  481. * and send the feed back.
  482. *
  483. * @access public
  484. * @since 1.0 Beta 3
  485. * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
  486. */
  487. function set_timeout($timeout = 10)
  488. {
  489. $this->timeout = (int) $timeout;
  490. }
  491. /**
  492. * Forces Simplepie to use fsockopen() instead of the preferred cURL
  493. * functions.
  494. *
  495. * @access public
  496. * @since 1.0 Beta 3
  497. * @param bool $enable Force fsockopen() to be used
  498. */
  499. function force_fsockopen($enable = false)
  500. {
  501. $this->force_fsockopen = (bool) $enable;
  502. }
  503. /**
  504. * Outputs the raw XML content of the feed, after it has gone through
  505. * Simplepie's filters.
  506. *
  507. * Used only for debugging, this function will output the XML content as
  508. * text/xml. When Simplepie reads in a feed, it does a bit of cleaning up
  509. * before trying to parse it. Many parts of the feed are re-written in
  510. * memory, and in the end, you have a parsable feed. XML dump shows you the
  511. * actual XML that Simplepie tries to parse, which may or may not be very
  512. * different from the original feed.
  513. *
  514. * @access public
  515. * @since 1.0 Preview Release
  516. * @param bool $enable Enable XML dump
  517. */
  518. function enable_xml_dump($enable = false)
  519. {
  520. $this->xml_dump = (bool) $enable;
  521. }
  522. /**
  523. * Enables/disables caching in Simplepie.
  524. *
  525. * This option allows you to disable caching all-together in Simplepie.
  526. * However, disabling the cache can lead to longer load times.
  527. *
  528. * @access public
  529. * @since 1.0 Preview Release
  530. * @param bool $enable Enable caching
  531. */
  532. function enable_cache($enable = true)
  533. {
  534. $this->cache = (bool) $enable;
  535. }
  536. /**
  537. * Set the length of time (in seconds) that the contents of a feed
  538. * will be cached.
  539. *
  540. * @access public
  541. * @param int $seconds The feed content cache duration.
  542. */
  543. function set_cache_duration($seconds = 3600)
  544. {
  545. $this->cache_duration = (int) $seconds;
  546. }
  547. /**
  548. * Set the length of time (in seconds) that the autodiscovered feed
  549. * URL will be cached.
  550. *
  551. * @access public
  552. * @param int $seconds The autodiscovered feed URL cache duration.
  553. */
  554. function set_autodiscovery_cache_duration($seconds = 604800)
  555. {
  556. $this->autodiscovery_cache_duration = (int) $seconds;
  557. }
  558. /**
  559. * Set the file system location where the cached files should be stored.
  560. *
  561. * @access public
  562. * @param string $location The file system location.
  563. */
  564. function set_cache_location($location = './cache')
  565. {
  566. $this->cache_location = (string) $location;
  567. }
  568. /**
  569. * Determines whether feed items should be sorted into reverse chronological order.
  570. *
  571. * @access public
  572. * @param bool $enable Sort as reverse chronological order.
  573. */
  574. function enable_order_by_date($enable = true)
  575. {
  576. $this->order_by_date = (bool) $enable;
  577. }
  578. /**
  579. * Allows you to override the character encoding reported by the feed.
  580. *
  581. * @access public
  582. * @param string $encoding Character encoding.
  583. */
  584. function set_input_encoding($encoding = false)
  585. {
  586. if ($encoding)
  587. {
  588. $this->input_encoding = (string) $encoding;
  589. }
  590. else
  591. {
  592. $this->input_encoding = false;
  593. }
  594. }
  595. /**
  596. * Set how much feed autodiscovery to do
  597. *
  598. * @access public
  599. * @see SIMPLEPIE_LOCATOR_NONE
  600. * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
  601. * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
  602. * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
  603. * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
  604. * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
  605. * @see SIMPLEPIE_LOCATOR_ALL
  606. * @param int $level Feed Autodiscovery Level (level can be a
  607. * combination of the above constants, see bitwise OR operator)
  608. */
  609. function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  610. {
  611. $this->autodiscovery = (int) $level;
  612. }
  613. /**
  614. * Allows you to change which class Simplepie uses for caching.
  615. * Useful when you are overloading or extending Simplepie's default classes.
  616. *
  617. * @access public
  618. * @param string $class Name of custom class.
  619. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  620. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  621. */
  622. function set_cache_class($class = 'Simplepie_Cache')
  623. {
  624. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Cache'))
  625. {
  626. $this->cache_class = $class;
  627. return true;
  628. }
  629. return false;
  630. }
  631. /**
  632. * Allows you to change which class Simplepie uses for auto-discovery.
  633. * Useful when you are overloading or extending Simplepie's default classes.
  634. *
  635. * @access public
  636. * @param string $class Name of custom class.
  637. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  638. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  639. */
  640. function set_locator_class($class = 'Simplepie_Locator')
  641. {
  642. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Locator'))
  643. {
  644. $this->locator_class = $class;
  645. return true;
  646. }
  647. return false;
  648. }
  649. /**
  650. * Allows you to change which class Simplepie uses for XML parsing.
  651. * Useful when you are overloading or extending Simplepie's default classes.
  652. *
  653. * @access public
  654. * @param string $class Name of custom class.
  655. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  656. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  657. */
  658. function set_parser_class($class = 'Simplepie_Parser')
  659. {
  660. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Parser'))
  661. {
  662. $this->parser_class = $class;
  663. return true;
  664. }
  665. return false;
  666. }
  667. /**
  668. * Allows you to change which class Simplepie uses for remote file fetching.
  669. * Useful when you are overloading or extending Simplepie's default classes.
  670. *
  671. * @access public
  672. * @param string $class Name of custom class.
  673. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  674. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  675. */
  676. function set_file_class($class = 'Simplepie_File')
  677. {
  678. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_File'))
  679. {
  680. $this->file_class = $class;
  681. return true;
  682. }
  683. return false;
  684. }
  685. /**
  686. * Allows you to change which class Simplepie uses for data sanitization.
  687. * Useful when you are overloading or extending Simplepie's default classes.
  688. *
  689. * @access public
  690. * @param string $class Name of custom class.
  691. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  692. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  693. */
  694. function set_sanitize_class($class = 'Simplepie_Sanitize')
  695. {
  696. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Sanitize'))
  697. {
  698. $this->sanitize = new $class;
  699. return true;
  700. }
  701. return false;
  702. }
  703. /**
  704. * Allows you to change which class Simplepie uses for handling feed items.
  705. * Useful when you are overloading or extending Simplepie's default classes.
  706. *
  707. * @access public
  708. * @param string $class Name of custom class.
  709. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  710. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  711. */
  712. function set_item_class($class = 'Simplepie_Item')
  713. {
  714. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Item'))
  715. {
  716. $this->item_class = $class;
  717. return true;
  718. }
  719. return false;
  720. }
  721. /**
  722. * Allows you to change which class Simplepie uses for handling author data.
  723. * Useful when you are overloading or extending Simplepie's default classes.
  724. *
  725. * @access public
  726. * @param string $class Name of custom class.
  727. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  728. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  729. */
  730. function set_author_class($class = 'Simplepie_Author')
  731. {
  732. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Author'))
  733. {
  734. $this->author_class = $class;
  735. return true;
  736. }
  737. return false;
  738. }
  739. /**
  740. * Allows you to change which class Simplepie uses for handling category data.
  741. * Useful when you are overloading or extending Simplepie's default classes.
  742. *
  743. * @access public
  744. * @param string $class Name of custom class.
  745. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  746. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  747. */
  748. function set_category_class($class = 'Simplepie_Category')
  749. {
  750. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Category'))
  751. {
  752. $this->category_class = $class;
  753. return true;
  754. }
  755. return false;
  756. }
  757. /**
  758. * Allows you to change which class Simplepie uses for feed enclosures.
  759. * Useful when you are overloading or extending Simplepie's default classes.
  760. *
  761. * @access public
  762. * @param string $class Name of custom class.
  763. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  764. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  765. */
  766. function set_enclosure_class($class = 'Simplepie_Enclosure')
  767. {
  768. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Enclosure'))
  769. {
  770. $this->enclosure_class = $class;
  771. return true;
  772. }
  773. return false;
  774. }
  775. /**
  776. * Allows you to change which class Simplepie uses for <media:text> captions
  777. * Useful when you are overloading or extending Simplepie's default classes.
  778. *
  779. * @access public
  780. * @param string $class Name of custom class.
  781. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  782. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  783. */
  784. function set_caption_class($class = 'Simplepie_Caption')
  785. {
  786. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Caption'))
  787. {
  788. $this->caption_class = $class;
  789. return true;
  790. }
  791. return false;
  792. }
  793. /**
  794. * Allows you to change which class Simplepie uses for <media:copyright>
  795. * Useful when you are overloading or extending Simplepie's default classes.
  796. *
  797. * @access public
  798. * @param string $class Name of custom class.
  799. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  800. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  801. */
  802. function set_copyright_class($class = 'Simplepie_Copyright')
  803. {
  804. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Copyright'))
  805. {
  806. $this->copyright_class = $class;
  807. return true;
  808. }
  809. return false;
  810. }
  811. /**
  812. * Allows you to change which class Simplepie uses for <media:credit>
  813. * Useful when you are overloading or extending Simplepie's default classes.
  814. *
  815. * @access public
  816. * @param string $class Name of custom class.
  817. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  818. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  819. */
  820. function set_credit_class($class = 'Simplepie_Credit')
  821. {
  822. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Credit'))
  823. {
  824. $this->credit_class = $class;
  825. return true;
  826. }
  827. return false;
  828. }
  829. /**
  830. * Allows you to change which class Simplepie uses for <media:rating>
  831. * Useful when you are overloading or extending Simplepie's default classes.
  832. *
  833. * @access public
  834. * @param string $class Name of custom class.
  835. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  836. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  837. */
  838. function set_rating_class($class = 'Simplepie_Rating')
  839. {
  840. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Rating'))
  841. {
  842. $this->rating_class = $class;
  843. return true;
  844. }
  845. return false;
  846. }
  847. /**
  848. * Allows you to change which class Simplepie uses for <media:restriction>
  849. * Useful when you are overloading or extending Simplepie's default classes.
  850. *
  851. * @access public
  852. * @param string $class Name of custom class.
  853. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  854. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  855. */
  856. function set_restriction_class($class = 'Simplepie_Restriction')
  857. {
  858. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Restriction'))
  859. {
  860. $this->restriction_class = $class;
  861. return true;
  862. }
  863. return false;
  864. }
  865. /**
  866. * Allows you to change which class Simplepie uses for content-type sniffing.
  867. * Useful when you are overloading or extending Simplepie's default classes.
  868. *
  869. * @access public
  870. * @param string $class Name of custom class.
  871. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  872. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  873. */
  874. function set_content_type_sniffer_class($class = 'Simplepie_Content_Type_Sniffer')
  875. {
  876. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Content_Type_Sniffer'))
  877. {
  878. $this->content_type_sniffer_class = $class;
  879. return true;
  880. }
  881. return false;
  882. }
  883. /**
  884. * Allows you to change which class Simplepie uses item sources.
  885. * Useful when you are overloading or extending Simplepie's default classes.
  886. *
  887. * @access public
  888. * @param string $class Name of custom class.
  889. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  890. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  891. */
  892. function set_source_class($class = 'Simplepie_Source')
  893. {
  894. if (Simplepie_Misc::is_subclass_of($class, 'Simplepie_Source'))
  895. {
  896. $this->source_class = $class;
  897. return true;
  898. }
  899. return false;
  900. }
  901. /**
  902. * Allows you to override the default user agent string.
  903. *
  904. * @access public
  905. * @param string $ua New user agent string.
  906. */
  907. function set_useragent($ua = SIMPLEPIE_USERAGENT)
  908. {
  909. $this->useragent = (string) $ua;
  910. }
  911. /**
  912. * Set callback function to create cache filename with
  913. *
  914. * @access public
  915. * @param mixed $function Callback function
  916. */
  917. function set_cache_name_function($function = 'md5')
  918. {
  919. if (is_callable($function))
  920. {
  921. $this->cache_name_function = $function;
  922. }
  923. }
  924. /**
  925. * Set javascript query string parameter
  926. *
  927. * @access public
  928. * @param mixed $get Javascript query string parameter
  929. */
  930. function set_javascript($get = 'js')
  931. {
  932. if ($get)
  933. {
  934. $this->javascript = (string) $get;
  935. }
  936. else
  937. {
  938. $this->javascript = false;
  939. }
  940. }
  941. /**
  942. * Set options to make SP as fast as possible. Forgoes a
  943. * substantial amount of data sanitization in favor of speed.
  944. *
  945. * @access public
  946. * @param bool $set Whether to set them or not
  947. */
  948. function set_stupidly_fast($set = false)
  949. {
  950. if ($set)
  951. {
  952. $this->enable_order_by_date(false);
  953. $this->remove_div(false);
  954. $this->strip_comments(false);
  955. $this->strip_htmltags(false);
  956. $this->strip_attributes(false);
  957. $this->set_image_handler(false);
  958. }
  959. }
  960. /**
  961. * Set maximum number of feeds to check with autodiscovery
  962. *
  963. * @access public
  964. * @param int $max Maximum number of feeds to check
  965. */
  966. function set_max_checked_feeds($max = 10)
  967. {
  968. $this->max_checked_feeds = (int) $max;
  969. }
  970. function remove_div($enable = true)
  971. {
  972. $this->sanitize->remove_div($enable);
  973. }
  974. function strip_htmltags($tags = '', $encode = null)
  975. {
  976. if ($tags === '')
  977. {
  978. $tags = $this->strip_htmltags;
  979. }
  980. $this->sanitize->strip_htmltags($tags);
  981. if ($encode !== null)
  982. {
  983. $this->sanitize->encode_instead_of_strip($tags);
  984. }
  985. }
  986. function encode_instead_of_strip($enable = true)
  987. {
  988. $this->sanitize->encode_instead_of_strip($enable);
  989. }
  990. function strip_attributes($attribs = '')
  991. {
  992. if ($attribs === '')
  993. {
  994. $attribs = $this->strip_attributes;
  995. }
  996. $this->sanitize->strip_attributes($attribs);
  997. }
  998. function set_output_encoding($encoding = 'UTF-8')
  999. {
  1000. $this->sanitize->set_output_encoding($encoding);
  1001. }
  1002. function strip_comments($strip = false)
  1003. {
  1004. $this->sanitize->strip_comments($strip);
  1005. }
  1006. /**
  1007. * Set element/attribute key/value pairs of HTML attributes
  1008. * containing URLs that need to be resolved relative to the feed
  1009. *
  1010. * @access public
  1011. * @since 1.0
  1012. * @param array $element_attribute Element/attribute key/value pairs
  1013. */
  1014. function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite'))
  1015. {
  1016. $this->sanitize->set_url_replacements($element_attribute);
  1017. }
  1018. /**
  1019. * Set the handler to enable the display of cached favicons.
  1020. *
  1021. * @access public
  1022. * @param str $page Web-accessible path to the handler_favicon.php file.
  1023. * @param str $qs The query string that the value should be passed to.
  1024. */
  1025. function set_favicon_handler($page = false, $qs = 'i')
  1026. {
  1027. if ($page !== false)
  1028. {
  1029. $this->favicon_handler = $page . '?' . $qs . '=';
  1030. }
  1031. else
  1032. {
  1033. $this->favicon_handler = '';
  1034. }
  1035. }
  1036. /**
  1037. * Set the handler to enable the display of cached images.
  1038. *
  1039. * @access public
  1040. * @param str $page Web-accessible path to the handler_image.php file.
  1041. * @param str $qs The query string that the value should be passed to.
  1042. */
  1043. function set_image_handler($page = false, $qs = 'i')
  1044. {
  1045. if ($page !== false)
  1046. {
  1047. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  1048. }
  1049. else
  1050. {
  1051. $this->image_handler = '';
  1052. }
  1053. }
  1054. /**
  1055. * Set the limit for items returned per-feed with multifeeds.
  1056. *
  1057. * @access public
  1058. * @param integer $limit The maximum number of items to return.
  1059. */
  1060. function set_item_limit($limit = 0)
  1061. {
  1062. $this->item_limit = (int) $limit;
  1063. }
  1064. function init()
  1065. {
  1066. // Check absolute bare minimum requirements.
  1067. if ((function_exists('version_compare') && version_compare(PHP_VERSION, '4.3.0', '<')) || !extension_loaded('xml') || !extension_loaded('pcre'))
  1068. {
  1069. return false;
  1070. }
  1071. // 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.
  1072. elseif (!extension_loaded('xmlreader'))
  1073. {
  1074. static $xml_is_sane = null;
  1075. if ($xml_is_sane === null)
  1076. {
  1077. $parser_check = xml_parser_create();
  1078. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  1079. xml_parser_free($parser_check);
  1080. $xml_is_sane = isset($values[0]['value']);
  1081. }
  1082. if (!$xml_is_sane)
  1083. {
  1084. return false;
  1085. }
  1086. }
  1087. if (isset($_GET[$this->javascript]))
  1088. {
  1089. Simplepie_Misc::output_javascript();
  1090. exit;
  1091. }
  1092. // Pass whatever was set with config options over to the sanitizer.
  1093. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->cache_class);
  1094. $this->sanitize->pass_file_data($this->file_class, $this->timeout, $this->useragent, $this->force_fsockopen);
  1095. if ($this->feed_url !== null || $this->raw_data !== null)
  1096. {
  1097. $this->data = array();
  1098. $this->multifeed_objects = array();
  1099. $cache = false;
  1100. if ($this->feed_url !== null)
  1101. {
  1102. $parsed_feed_url = Simplepie_Misc::parse_url($this->feed_url);
  1103. // Decide whether to enable caching
  1104. if ($this->cache && $parsed_feed_url['scheme'] !== '')
  1105. {
  1106. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc');
  1107. }
  1108. // If it's enabled and we don't want an XML dump, use the cache
  1109. if ($cache && !$this->xml_dump)
  1110. {
  1111. // Load the Cache
  1112. $this->data = $cache->load();
  1113. if (!empty($this->data))
  1114. {
  1115. // If the cache is for an outdated build of Simplepie
  1116. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
  1117. {
  1118. $cache->unlink();
  1119. $this->data = array();
  1120. }
  1121. // If we've hit a collision just rerun it with caching disabled
  1122. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
  1123. {
  1124. $cache = false;
  1125. $this->data = array();
  1126. }
  1127. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
  1128. elseif (isset($this->data['feed_url']))
  1129. {
  1130. // If the autodiscovery cache is still valid use it.
  1131. if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
  1132. {
  1133. // Do not need to do feed autodiscovery yet.
  1134. if ($this->data['feed_url'] === $this->data['url'])
  1135. {
  1136. $cache->unlink();
  1137. $this->data = array();
  1138. }
  1139. else
  1140. {
  1141. $this->set_feed_url($this->data['feed_url']);
  1142. return $this->init();
  1143. }
  1144. }
  1145. }
  1146. // Check if the cache has been updated
  1147. elseif ($cache->mtime() + $this->cache_duration < time())
  1148. {
  1149. // If we have last-modified and/or etag set
  1150. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
  1151. {
  1152. $headers = array();
  1153. if (isset($this->data['headers']['last-modified']))
  1154. {
  1155. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  1156. }
  1157. if (isset($this->data['headers']['etag']))
  1158. {
  1159. $headers['if-none-match'] = '"' . $this->data['headers']['etag'] . '"';
  1160. }
  1161. $file = new $this->file_class($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);
  1162. if ($file->success)
  1163. {
  1164. if ($file->status_code === 304)
  1165. {
  1166. $cache->touch();
  1167. return true;
  1168. }
  1169. else
  1170. {
  1171. $headers = $file->headers;
  1172. }
  1173. }
  1174. else
  1175. {
  1176. unset($file);
  1177. }
  1178. }
  1179. }
  1180. // If the cache is still valid, just return true
  1181. else
  1182. {
  1183. return true;
  1184. }
  1185. }
  1186. // If the cache is empty, delete it
  1187. else
  1188. {
  1189. $cache->unlink();
  1190. $this->data = array();
  1191. }
  1192. }
  1193. // 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.
  1194. if (!isset($file))
  1195. {
  1196. if (is_a($this->file, 'Simplepie_File') && $this->file->url === $this->feed_url)
  1197. {
  1198. $file =& $this->file;
  1199. }
  1200. else
  1201. {
  1202. $file = new $this->file_class($this->feed_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);
  1203. }
  1204. }
  1205. // If the file connection has an error, set Simplepie::error to that and quit
  1206. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  1207. {
  1208. $this->error = $file->error;
  1209. if (!empty($this->data))
  1210. {
  1211. return true;
  1212. }
  1213. else
  1214. {
  1215. return false;
  1216. }
  1217. }
  1218. if (!$this->force_feed)
  1219. {
  1220. // Check if the supplied URL is a feed, if it isn't, look for it.
  1221. $locate = new $this->locator_class($file, $this->timeout, $this->useragent, $this->file_class, $this->max_checked_feeds, $this->content_type_sniffer_class);
  1222. if (!$locate->is_feed($file))
  1223. {
  1224. // We need to unset this so that if Simplepie::set_file() has been called that object is untouched
  1225. unset($file);
  1226. if ($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds))
  1227. {
  1228. if ($cache)
  1229. {
  1230. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  1231. if (!$cache->save($this))
  1232. {
  1233. 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);
  1234. }
  1235. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
  1236. }
  1237. $this->feed_url = $file->url;
  1238. }
  1239. else
  1240. {
  1241. $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.";
  1242. Simplepie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  1243. return false;
  1244. }
  1245. }
  1246. $locate = null;
  1247. }
  1248. $headers = $file->headers;
  1249. $data = $file->body;
  1250. $sniffer = new $this->content_type_sniffer_class($file);
  1251. $sniffed = $sniffer->get_type();
  1252. }
  1253. else
  1254. {
  1255. $data = $this->raw_data;
  1256. }
  1257. // Set up array of possible encodings
  1258. $encodings = array();
  1259. // First check to see if input has been overridden.
  1260. if ($this->input_encoding !== false)
  1261. {
  1262. $encodings[] = $this->input_encoding;
  1263. }
  1264. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  1265. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  1266. // RFC 3023 (only applies to sniffed content)
  1267. if (isset($sniffed))
  1268. {
  1269. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
  1270. {
  1271. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1272. {
  1273. $encodings[] = strtoupper($charset[1]);
  1274. }
  1275. $encodings = array_merge($encodings, Simplepie_Misc::xml_encoding($data));
  1276. $encodings[] = 'UTF-8';
  1277. }
  1278. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
  1279. {
  1280. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1281. {
  1282. $encodings[] = $charset[1];
  1283. }
  1284. $encodings[] = 'US-ASCII';
  1285. }
  1286. // Text MIME-type default
  1287. elseif (substr($sniffed, 0, 5) === 'text/')
  1288. {
  1289. $encodings[] = 'US-ASCII';
  1290. }
  1291. }
  1292. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
  1293. $encodings = array_merge($encodings, Simplepie_Misc::xml_encoding($data));
  1294. $encodings[] = 'UTF-8';
  1295. $encodings[] = 'ISO-8859-1';
  1296. // There's no point in trying an encoding twice
  1297. $encodings = array_unique($encodings);
  1298. // If we want the XML, just output that with the most likely encoding and quit
  1299. if ($this->xml_dump)
  1300. {
  1301. header('Content-type: text/xml; charset=' . $encodings[0]);
  1302. echo $data;
  1303. exit;
  1304. }
  1305. // Loop through each possible encoding, till we return something, or run out of possibilities
  1306. foreach ($encodings as $encoding)
  1307. {
  1308. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  1309. if ($utf8_data = Simplepie_Misc::change_encoding($data, $encoding, 'UTF-8'))
  1310. {
  1311. // Create new parser
  1312. $parser = new $this->parser_class();
  1313. // If it's parsed fine
  1314. if ($parser->parse($utf8_data, 'UTF-8'))
  1315. {
  1316. $this->data = $parser->get_data();
  1317. if ($this->get_type() & ~SIMPLEPIE_TYPE_NONE)
  1318. {
  1319. if (isset($headers))
  1320. {
  1321. $this->data['headers'] = $headers;
  1322. }
  1323. $this->data['build'] = SIMPLEPIE_BUILD;
  1324. // Cache the file if caching is enabled
  1325. if ($cache && !$cache->save($this))
  1326. {
  1327. 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);
  1328. }
  1329. return true;
  1330. }
  1331. else
  1332. {
  1333. $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
  1334. Simplepie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  1335. return false;
  1336. }
  1337. }
  1338. }
  1339. }
  1340. if (isset($parser))
  1341. {
  1342. // We have an error, just set Simplepie_Misc::error to it and quit
  1343. $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());
  1344. }
  1345. else
  1346. {
  1347. $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.';
  1348. }
  1349. Simplepie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  1350. return false;
  1351. }
  1352. elseif (!empty($this->multifeed_url))
  1353. {
  1354. $i = 0;
  1355. $success = 0;
  1356. $this->multifeed_objects = array();
  1357. foreach ($this->multifeed_url as $url)
  1358. {
  1359. if (SIMPLEPIE_PHP5)
  1360. {
  1361. // This keyword needs to defy coding standards for PHP4 compatibility
  1362. $this->multifeed_objects[$i] = clone($this);
  1363. }
  1364. else
  1365. {
  1366. $this->multifeed_objects[$i] = $this;
  1367. }
  1368. $this->multifeed_objects[$i]->set_feed_url($url);
  1369. $success |= $this->multifeed_objects[$i]->init();
  1370. $i++;
  1371. }
  1372. return (bool) $success;
  1373. }
  1374. else
  1375. {
  1376. return false;
  1377. }
  1378. }
  1379. /**
  1380. * Return the error message for the occured error
  1381. *
  1382. * @access public
  1383. * @return string Error message
  1384. */
  1385. function error()
  1386. {
  1387. return $this->error;
  1388. }
  1389. function get_encoding()
  1390. {
  1391. return $this->sanitize->output_encoding;
  1392. }
  1393. function handle_content_type($mime = 'text/html')
  1394. {
  1395. if (!headers_sent())
  1396. {
  1397. $header = "Content-type: $mime;";
  1398. if ($this->get_encoding())
  1399. {
  1400. $header .= ' charset=' . $this->get_encoding();
  1401. }
  1402. else
  1403. {
  1404. $header .= ' charset=UTF-8';
  1405. }
  1406. header($header);
  1407. }
  1408. }
  1409. function get_type()
  1410. {
  1411. if (!isset($this->data['type']))
  1412. {
  1413. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  1414. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
  1415. {
  1416. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  1417. }
  1418. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
  1419. {
  1420. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  1421. }
  1422. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
  1423. {
  1424. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  1425. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  1426. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  1427. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
  1428. {
  1429. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  1430. }
  1431. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  1432. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  1433. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  1434. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
  1435. {
  1436. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  1437. }
  1438. }
  1439. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
  1440. {
  1441. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  1442. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  1443. {
  1444. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  1445. {
  1446. case '0.91':
  1447. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  1448. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  1449. {
  1450. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  1451. {
  1452. case '0':
  1453. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  1454. break;
  1455. case '24':
  1456. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  1457. break;
  1458. }
  1459. }
  1460. break;
  1461. case '0.92':
  1462. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  1463. break;
  1464. case '0.93':
  1465. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  1466. break;
  1467. case '0.94':
  1468. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  1469. break;
  1470. case '2.0':
  1471. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  1472. break;
  1473. }
  1474. }
  1475. }
  1476. else
  1477. {
  1478. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  1479. }
  1480. }
  1481. return $this->data['type'];
  1482. }
  1483. /**
  1484. * Returns the URL for the favicon of the feed's website.
  1485. *
  1486. * @todo Cache atom:icon
  1487. * @access public
  1488. * @since 1.0
  1489. */
  1490. function get_favicon()
  1491. {
  1492. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  1493. {
  1494. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1495. }
  1496. elseif (($url = $this->get_link()) !== null && preg_match('/^http(s)?:\/\//i', $url))
  1497. {
  1498. $favicon = Simplepie_Misc::absolutize_url('/favicon.ico', $url);
  1499. if ($this->cache && $this->favicon_handler)
  1500. {
  1501. $favicon_filename = call_user_func($this->cache_name_function, $favicon);
  1502. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $favicon_filename, 'spi');
  1503. if ($cache->load())
  1504. {
  1505. return $this->sanitize($this->favicon_handler . $favicon_filename, SIMPLEPIE_CONSTRUCT_IRI);
  1506. }
  1507. else
  1508. {
  1509. $file = new $this->file_class($favicon, $this->timeout / 10, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
  1510. if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)) && strlen($file->body) > 0)
  1511. {
  1512. $sniffer = new $this->content_type_sniffer_class($file);
  1513. if (substr($sniffer->get_type(), 0, 6) === 'image/')
  1514. {
  1515. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  1516. {
  1517. return $this->sanitize($this->favicon_handler . $favicon_filename, SIMPLEPIE_CONSTRUCT_IRI);
  1518. }
  1519. else
  1520. {
  1521. trigger_error("$cache->name is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  1522. return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);
  1523. }
  1524. }
  1525. // not an image
  1526. else
  1527. {
  1528. return false;
  1529. }
  1530. }
  1531. }
  1532. }
  1533. else
  1534. {
  1535. return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);
  1536. }
  1537. }
  1538. return false;
  1539. }
  1540. /**
  1541. * @todo If we have a perm redirect we should return the new URL
  1542. * @todo When we make the above change, let's support <itunes:new-feed-url> as well
  1543. * @todo Also, |atom:link|@rel=self
  1544. */
  1545. function subscribe_url()
  1546. {
  1547. if ($this->feed_url !== null)
  1548. {
  1549. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
  1550. }
  1551. else
  1552. {
  1553. return null;
  1554. }
  1555. }
  1556. function subscribe_feed()
  1557. {
  1558. if ($this->feed_url !== null)
  1559. {
  1560. return $this->sanitize(Simplepie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);
  1561. }
  1562. else
  1563. {
  1564. return null;
  1565. }
  1566. }
  1567. function subscribe_outlook()
  1568. {
  1569. if ($this->feed_url !== null)
  1570. {
  1571. return $this->sanitize('outlook' . Simplepie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);
  1572. }
  1573. else
  1574. {
  1575. return null;
  1576. }
  1577. }
  1578. function subscribe_podcast()
  1579. {
  1580. if ($this->feed_url !== null)
  1581. {
  1582. return $this->sanitize(Simplepie_Misc::fix_protocol($this->feed_url, 3), SIMPLEPIE_CONSTRUCT_IRI);
  1583. }
  1584. else
  1585. {
  1586. return null;
  1587. }
  1588. }
  1589. function subscribe_itunes()
  1590. {
  1591. if ($this->feed_url !== null)
  1592. {
  1593. return $this->sanitize(Simplepie_Misc::fix_protocol($this->feed_url, 4), SIMPLEPIE_CONSTRUCT_IRI);
  1594. }
  1595. else
  1596. {
  1597. return null;
  1598. }
  1599. }
  1600. /**
  1601. * Creates the subscribe_* methods' return data
  1602. *
  1603. * @access private
  1604. * @param string $feed_url String to prefix to the feed URL
  1605. * @param string $site_url String to prefix to the site URL (and
  1606. * suffix to the feed URL)
  1607. * @return mixed URL if feed exists, false otherwise
  1608. */
  1609. function subscribe_service($feed_url, $site_url = null)
  1610. {
  1611. if ($this->subscribe_url())
  1612. {
  1613. $return = $feed_url . rawurlencode($this->feed_url);
  1614. if ($site_url !== null && $this->get_link() !== null)
  1615. {
  1616. $return .= $site_url . rawurlencode($this->get_link());
  1617. }
  1618. return $this->sanitize($return, SIMPLEPIE_CONSTRUCT_IRI);
  1619. }
  1620. else
  1621. {
  1622. return null;
  1623. }
  1624. }
  1625. function subscribe_aol()
  1626. {
  1627. return $this->subscribe_service('http://feeds.my.aol.com/add.jsp?url=');
  1628. }
  1629. function subscribe_bloglines()
  1630. {
  1631. return $this->subscribe_service('http://www.bloglines.com/sub/');
  1632. }
  1633. function subscribe_eskobo()
  1634. {
  1635. return $this->subscribe_service('http://www.eskobo.com/?AddToMyPage=');
  1636. }
  1637. function subscribe_feedfeeds()
  1638. {
  1639. return $this->subscribe_service('http://www.feedfeeds.com/add?feed=');
  1640. }
  1641. function subscribe_feedster()
  1642. {
  1643. return $this->subscribe_service('http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl=');
  1644. }
  1645. function subscribe_google()
  1646. {
  1647. return $this->subscribe_service('http://fusion.google.com/add?feedurl=');
  1648. }
  1649. function subscribe_gritwire()
  1650. {
  1651. return $this->subscribe_service('http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=');
  1652. }
  1653. function subscribe_msn()
  1654. {
  1655. return $this->subscribe_service('http://my.msn.com/addtomymsn.armx?id=rss&ut=', '&ru=');
  1656. }
  1657. function subscribe_netvibes()
  1658. {
  1659. return $this->subscribe_service('http://www.netvibes.com/subscribe.php?url=');
  1660. }
  1661. function subscribe_newsburst()
  1662. {
  1663. return $this->subscribe_service('http://www.newsburst.com/Source/?add=');
  1664. }
  1665. function subscribe_newsgator()
  1666. {
  1667. return $this->subscribe_service('http://www.newsgator.com/ngs/subscriber/subext.aspx?url=');
  1668. }
  1669. function subscribe_odeo()
  1670. {
  1671. return $this->subscribe_service('http://www.odeo.com/listen/subscribe?feed=');
  1672. }
  1673. function subscribe_podnova()
  1674. {
  1675. return $this->subscribe_service('http://www.podnova.com/index_your_podcasts.srf?action=add&url=');
  1676. }
  1677. function subscribe_rojo()
  1678. {
  1679. return $this->subscribe_service('http://www.rojo.com/add-subscription?resource=');
  1680. }
  1681. function subscribe_yahoo()
  1682. {
  1683. return $this->subscribe_service('http://add.my.yahoo.com/rss?url=');
  1684. }
  1685. function get_feed_tags($namespace, $tag)
  1686. {
  1687. $type = $this->get_type();
  1688. if ($type & SIMPLEPIE_TYPE_ATOM_10)
  1689. {
  1690. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
  1691. {
  1692. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  1693. }
  1694. }
  1695. if ($type & SIMPLEPIE_TYPE_ATOM_03)
  1696. {
  1697. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
  1698. {
  1699. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  1700. }
  1701. }
  1702. if ($type & SIMPLEPIE_TYPE_RSS_RDF)
  1703. {
  1704. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
  1705. {
  1706. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  1707. }
  1708. }
  1709. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1710. {
  1711. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
  1712. {
  1713. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
  1714. }
  1715. }
  1716. return null;
  1717. }
  1718. function get_channel_tags($namespace, $tag)
  1719. {
  1720. $type = $this->get_type();
  1721. if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
  1722. {
  1723. if ($return = $this->get_feed_tags($namespace, $tag))
  1724. {
  1725. return $return;
  1726. }
  1727. }
  1728. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1729. {
  1730. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
  1731. {
  1732. if (isset($channel[0]['child'][$namespace][$tag]))
  1733. {
  1734. return $channel[0]['child'][$namespace][$tag];
  1735. }
  1736. }
  1737. }
  1738. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1739. {
  1740. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
  1741. {
  1742. if (isset($channel[0]['child'][$namespace][$tag]))
  1743. {
  1744. return $channel[0]['child'][$namespace][$tag];
  1745. }
  1746. }
  1747. }
  1748. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1749. {
  1750. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
  1751. {
  1752. if (isset($channel[0]['child'][$namespace][$tag]))
  1753. {
  1754. return $channel[0]['child'][$namespace][$tag];
  1755. }
  1756. }
  1757. }
  1758. return null;
  1759. }
  1760. function get_image_tags($namespace, $tag)
  1761. {
  1762. $type = $this->get_type();
  1763. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1764. {
  1765. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
  1766. {
  1767. if (isset($image[0]['child'][$namespace][$tag]))
  1768. {
  1769. return $image[0]['child'][$namespace][$tag];
  1770. }
  1771. }
  1772. }
  1773. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1774. {
  1775. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
  1776. {
  1777. if (isset($image[0]['child'][$namespace][$tag]))
  1778. {
  1779. return $image[0]['child'][$namespace][$tag];
  1780. }
  1781. }
  1782. }
  1783. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1784. {
  1785. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
  1786. {
  1787. if (isset($image[0]['child'][$namespace][$tag]))
  1788. {
  1789. return $image[0]['child'][$namespace][$tag];
  1790. }
  1791. }
  1792. }
  1793. return null;
  1794. }
  1795. function get_base($element = array())
  1796. {
  1797. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
  1798. {
  1799. return $element['xml_base'];
  1800. }
  1801. elseif ($this->get_link() !== null)
  1802. {
  1803. return $this->get_link();
  1804. }
  1805. else
  1806. {
  1807. return $this->subscribe_url();
  1808. }
  1809. }
  1810. function sanitize($data, $type, $base = '')
  1811. {
  1812. return $this->sanitize->sanitize($data, $type, $base);
  1813. }
  1814. function get_title()
  1815. {
  1816. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  1817. {
  1818. return $this->sanitize($return[0]['data'], Simplepie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1819. }
  1820. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  1821. {
  1822. return $this->sanitize($return[0]['data'], Simplepie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  1823. }
  1824. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  1825. {
  1826. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1827. }
  1828. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  1829. {
  1830. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1831. }
  1832. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  1833. {
  1834. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1835. }
  1836. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  1837. {
  1838. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1839. }
  1840. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  1841. {
  1842. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1843. }
  1844. else
  1845. {
  1846. return null;
  1847. }
  1848. }
  1849. function get_category($key = 0)
  1850. {
  1851. $categories = $this->get_categories();
  1852. if (isset($categories[$key]))
  1853. {
  1854. return $categories[$key];
  1855. }
  1856. else
  1857. {
  1858. return null;
  1859. }
  1860. }
  1861. function get_categories()
  1862. {
  1863. $categories = array();
  1864. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  1865. {
  1866. $term = null;
  1867. $scheme = null;
  1868. $label = null;
  1869. if (isset($category['attribs']['']['term']))
  1870. {
  1871. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  1872. }
  1873. if (isset($category['attribs']['']['scheme']))
  1874. {
  1875. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1876. }
  1877. if (isset($category['attribs']['']['label']))
  1878. {
  1879. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1880. }
  1881. $categories[] = new $this->category_class($term, $scheme, $label);
  1882. }
  1883. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  1884. {
  1885. // This is really the label, but keep this as the term also for BC.
  1886. // Label will also work on retrieving because that falls back to term.
  1887. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1888. if (isset($category['attribs']['']['domain']))
  1889. {
  1890. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  1891. }
  1892. else
  1893. {
  1894. $scheme = null;
  1895. }
  1896. $categories[] = new $this->category_class($term, $scheme, null);
  1897. }
  1898. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  1899. {
  1900. $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1901. }
  1902. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  1903. {
  1904. $categories[] = new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1905. }
  1906. if (!empty($categories))
  1907. {
  1908. return Simplepie_Misc::array_unique($categories);
  1909. }
  1910. else
  1911. {
  1912. return null;
  1913. }
  1914. }
  1915. function get_author($key = 0)
  1916. {
  1917. $authors = $this->get_authors();
  1918. if (isset($authors[$key]))
  1919. {
  1920. return $authors[$key];
  1921. }
  1922. else
  1923. {
  1924. return null;
  1925. }
  1926. }
  1927. function get_authors()
  1928. {
  1929. $authors = array();
  1930. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  1931. {
  1932. $name = null;
  1933. $uri = null;
  1934. $email = null;
  1935. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  1936. {
  1937. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1938. }
  1939. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  1940. {
  1941. $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]));
  1942. }
  1943. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  1944. {
  1945. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1946. }
  1947. if ($name !== null || $email !== null || $uri !== null)
  1948. {
  1949. $authors[] = new $this->author_class($name, $uri, $email);
  1950. }
  1951. }
  1952. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  1953. {
  1954. $name = null;
  1955. $url = null;
  1956. $email = null;
  1957. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  1958. {
  1959. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1960. }
  1961. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  1962. {
  1963. $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]));
  1964. }
  1965. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  1966. {
  1967. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1968. }
  1969. if ($name !== null || $email !== null || $url !== null)
  1970. {
  1971. $authors[] = new $this->author_class($name, $url, $email);
  1972. }
  1973. }
  1974. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  1975. {
  1976. $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1977. }
  1978. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  1979. {
  1980. $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1981. }
  1982. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  1983. {
  1984. $authors[] = new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  1985. }
  1986. if (!empty($authors))
  1987. {
  1988. return Simplepie_Misc::array_unique($authors);
  1989. }
  1990. else
  1991. {
  1992. return null;
  1993. }
  1994. }
  1995. function get_contributor($key = 0)
  1996. {
  1997. $contributors = $this->get_contributors();
  1998. if (isset($contributors[$key]))
  1999. {
  2000. return $contributors[$key];
  2001. }
  2002. else
  2003. {
  2004. return null;
  2005. }
  2006. }
  2007. function get_contributors()
  2008. {
  2009. $contributors = array();
  2010. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  2011. {
  2012. $name = null;
  2013. $uri = null;
  2014. $email = null;
  2015. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2016. {
  2017. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2018. }
  2019. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2020. {
  2021. $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]));
  2022. }
  2023. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2024. {
  2025. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2026. }
  2027. if ($name !== null || $email !== null || $uri !== null)
  2028. {
  2029. $contributors[] = new $this->author_class($name, $uri, $email);
  2030. }
  2031. }
  2032. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  2033. {
  2034. $name = null;
  2035. $url = null;
  2036. $email = null;
  2037. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2038. {
  2039. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2040. }
  2041. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2042. {
  2043. $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]));
  2044. }
  2045. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2046. {
  2047. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2048. }
  2049. if ($name !== null || $email !== null || $url !== null)
  2050. {
  2051. $contributors[] = new $this->author_class($name, $url, $email);
  2052. }
  2053. }
  2054. if (!empty($contributors))
  2055. {
  2056. return Simplepie_Misc::array_unique($contributors);
  2057. }
  2058. else
  2059. {
  2060. return null;
  2061. }
  2062. }
  2063. function get_link($key = 0, $rel = 'alternate')
  2064. {
  2065. $links = $this->get_links($rel);
  2066. if (isset($links[$key]))
  2067. {
  2068. return $links[$key];
  2069. }
  2070. else
  2071. {
  2072. return null;
  2073. }
  2074. }
  2075. /**
  2076. * Added for parity between the parent-level and the item/entry-level.
  2077. */
  2078. function get_permalink()
  2079. {
  2080. return $this->get_link(0);
  2081. }
  2082. function get_links($rel = 'alternate')
  2083. {
  2084. if (!isset($this->data['links']))
  2085. {
  2086. $this->data['links'] = array();
  2087. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  2088. {
  2089. foreach ($links as $link)
  2090. {
  2091. if (isset($link['attribs']['']['href']))
  2092. {
  2093. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2094. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2095. }
  2096. }
  2097. }
  2098. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  2099. {
  2100. foreach ($links as $link)
  2101. {
  2102. if (isset($link['attribs']['']['href']))
  2103. {
  2104. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2105. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2106. }
  2107. }
  2108. }
  2109. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2110. {
  2111. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2112. }
  2113. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2114. {
  2115. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2116. }
  2117. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  2118. {
  2119. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2120. }
  2121. $keys = array_keys($this->data['links']);
  2122. foreach ($keys as $key)
  2123. {
  2124. if (Simplepie_Misc::is_isegment_nz_nc($key))
  2125. {
  2126. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  2127. {
  2128. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  2129. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  2130. }
  2131. else
  2132. {
  2133. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  2134. }
  2135. }
  2136. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  2137. {
  2138. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  2139. }
  2140. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  2141. }
  2142. }
  2143. if (isset($this->data['links'][$rel]))
  2144. {
  2145. return $this->data['links'][$rel];
  2146. }
  2147. else
  2148. {
  2149. return null;
  2150. }
  2151. }
  2152. function get_all_discovered_feeds()
  2153. {
  2154. return $this->all_discovered_feeds;
  2155. }
  2156. function get_description()
  2157. {
  2158. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  2159. {
  2160. return $this->sanitize($return[0]['data'], Simplepie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2161. }
  2162. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  2163. {
  2164. return $this->sanitize($return[0]['data'], Simplepie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2165. }
  2166. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  2167. {
  2168. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2169. }
  2170. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  2171. {
  2172. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2173. }
  2174. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  2175. {
  2176. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2177. }
  2178. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  2179. {
  2180. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2181. }
  2182. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  2183. {
  2184. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2185. }
  2186. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  2187. {
  2188. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2189. }
  2190. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  2191. {
  2192. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2193. }
  2194. else
  2195. {
  2196. return null;
  2197. }
  2198. }
  2199. function get_copyright()
  2200. {
  2201. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  2202. {
  2203. return $this->sanitize($return[0]['data'], Simplepie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2204. }
  2205. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  2206. {
  2207. return $this->sanitize($return[0]['data'], Simplepie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2208. }
  2209. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  2210. {
  2211. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2212. }
  2213. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  2214. {
  2215. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2216. }
  2217. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  2218. {
  2219. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2220. }
  2221. else
  2222. {
  2223. return null;
  2224. }
  2225. }
  2226. function get_language()
  2227. {
  2228. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  2229. {
  2230. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2231. }
  2232. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  2233. {
  2234. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2235. }
  2236. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  2237. {
  2238. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2239. }
  2240. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
  2241. {
  2242. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2243. }
  2244. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
  2245. {
  2246. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2247. }
  2248. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
  2249. {
  2250. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2251. }
  2252. elseif (isset($this->data['headers']['content-language']))
  2253. {
  2254. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
  2255. }
  2256. else
  2257. {
  2258. return null;
  2259. }
  2260. }
  2261. function get_latitude()
  2262. {
  2263. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  2264. {
  2265. return (float) $return[0]['data'];
  2266. }
  2267. 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))
  2268. {
  2269. return (float) $match[1];
  2270. }
  2271. else
  2272. {
  2273. return null;
  2274. }
  2275. }
  2276. function get_longitude()
  2277. {
  2278. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  2279. {
  2280. return (float) $return[0]['data'];
  2281. }
  2282. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  2283. {
  2284. return (float) $return[0]['data'];
  2285. }
  2286. 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))
  2287. {
  2288. return (float) $match[2];
  2289. }
  2290. else
  2291. {
  2292. return null;
  2293. }
  2294. }
  2295. function get_image_title()
  2296. {
  2297. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2298. {
  2299. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2300. }
  2301. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2302. {
  2303. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2304. }
  2305. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  2306. {
  2307. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2308. }
  2309. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2310. {
  2311. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2312. }
  2313. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2314. {
  2315. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2316. }
  2317. else
  2318. {
  2319. return null;
  2320. }
  2321. }
  2322. function get_image_url()
  2323. {
  2324. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  2325. {
  2326. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  2327. }
  2328. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  2329. {
  2330. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2331. }
  2332. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  2333. {
  2334. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2335. }
  2336. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
  2337. {
  2338. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2339. }
  2340. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
  2341. {
  2342. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2343. }
  2344. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2345. {
  2346. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2347. }
  2348. else
  2349. {
  2350. return null;
  2351. }
  2352. }
  2353. function get_image_link()
  2354. {
  2355. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2356. {
  2357. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2358. }
  2359. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2360. {
  2361. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2362. }
  2363. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  2364. {
  2365. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2366. }
  2367. else
  2368. {
  2369. return null;
  2370. }
  2371. }
  2372. function get_image_width()
  2373. {
  2374. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
  2375. {
  2376. return round($return[0]['data']);
  2377. }
  2378. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2379. {
  2380. return 88.0;
  2381. }
  2382. else
  2383. {
  2384. return null;
  2385. }
  2386. }
  2387. function get_image_height()
  2388. {
  2389. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
  2390. {
  2391. return round($return[0]['data']);
  2392. }
  2393. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2394. {
  2395. return 31.0;
  2396. }
  2397. else
  2398. {
  2399. return null;
  2400. }
  2401. }
  2402. function get_item_quantity($max = 0)
  2403. {
  2404. $max = (int) $max;
  2405. $qty = count($this->get_items());
  2406. if ($max === 0)
  2407. {
  2408. return $qty;
  2409. }
  2410. else
  2411. {
  2412. return ($qty > $max) ? $max : $qty;
  2413. }
  2414. }
  2415. function get_item($key = 0)
  2416. {
  2417. $items = $this->get_items();
  2418. if (isset($items[$key]))
  2419. {
  2420. return $items[$key];
  2421. }
  2422. else
  2423. {
  2424. return null;
  2425. }
  2426. }
  2427. function get_items($start = 0, $end = 0)
  2428. {
  2429. if (!isset($this->data['items']))
  2430. {
  2431. if (!empty($this->multifeed_objects))
  2432. {
  2433. $this->data['items'] = Simplepie_Feed::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
  2434. }
  2435. else
  2436. {
  2437. $this->data['items'] = array();
  2438. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
  2439. {
  2440. $keys = array_keys($items);
  2441. foreach ($keys as $key)
  2442. {
  2443. $this->data['items'][] = new $this->item_class($this, $items[$key]);
  2444. }
  2445. }
  2446. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
  2447. {
  2448. $keys = array_keys($items);
  2449. foreach ($keys as $key)
  2450. {
  2451. $this->data['items'][] = new $this->item_class($this, $items[$key]);
  2452. }
  2453. }
  2454. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
  2455. {
  2456. $keys = array_keys($items);
  2457. foreach ($keys as $key)
  2458. {
  2459. $this->data['items'][] = new $this->item_class($this, $items[$key]);
  2460. }
  2461. }
  2462. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
  2463. {
  2464. $keys = array_keys($items);
  2465. foreach ($keys as $key)
  2466. {
  2467. $this->data['items'][] = new $this->item_class($this, $items[$key]);
  2468. }
  2469. }
  2470. if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
  2471. {
  2472. $keys = array_keys($items);
  2473. foreach ($keys as $key)
  2474. {
  2475. $this->data['items'][] = new $this->item_class($this, $items[$key]);
  2476. }
  2477. }
  2478. }
  2479. }
  2480. if (!empty($this->data['items']))
  2481. {
  2482. // If we want to order it by date, check if all items have a date, and then sort it
  2483. if ($this->order_by_date && empty($this->multifeed_objects))
  2484. {
  2485. if (!isset($this->data['ordered_items']))
  2486. {
  2487. $do_sort = true;
  2488. foreach ($this->data['items'] as $item)
  2489. {
  2490. if (!$item->get_date('U'))
  2491. {
  2492. $do_sort = false;
  2493. break;
  2494. }
  2495. }
  2496. $item = null;
  2497. $this->data['ordered_items'] = $this->data['items'];
  2498. if ($do_sort)
  2499. {
  2500. usort($this->data['ordered_items'], array(&$this, 'sort_items'));
  2501. }
  2502. }
  2503. $items = $this->data['ordered_items'];
  2504. }
  2505. else
  2506. {
  2507. $items = $this->data['items'];
  2508. }
  2509. // Slice the data as desired
  2510. if ($end === 0)
  2511. {
  2512. return array_slice($items, $start);
  2513. }
  2514. else
  2515. {
  2516. return array_slice($items, $start, $end);
  2517. }
  2518. }
  2519. else
  2520. {
  2521. return array();
  2522. }
  2523. }
  2524. /**
  2525. * @static
  2526. */
  2527. function sort_items($a, $b)
  2528. {
  2529. return $a->get_date('U') <= $b->get_date('U');
  2530. }
  2531. /**
  2532. * @static
  2533. */
  2534. function merge_items($urls, $start = 0, $end = 0, $limit = 0)
  2535. {
  2536. if (is_array($urls) && sizeof($urls) > 0)
  2537. {
  2538. $items = array();
  2539. foreach ($urls as $arg)
  2540. {
  2541. if (is_a($arg, 'Simplepie_Feed'))
  2542. {
  2543. $items = array_merge($items, $arg->get_items(0, $limit));
  2544. }
  2545. else
  2546. {
  2547. trigger_error('Arguments must be Simplepie objects', E_USER_WARNING);
  2548. }
  2549. }
  2550. $do_sort = true;
  2551. foreach ($items as $item)
  2552. {
  2553. if (!$item->get_date('U'))
  2554. {
  2555. $do_sort = false;
  2556. break;
  2557. }
  2558. }
  2559. $item = null;
  2560. if ($do_sort)
  2561. {
  2562. usort($items, array('Simplepie_Feed', 'sort_items'));
  2563. }
  2564. if ($end === 0)
  2565. {
  2566. return array_slice($items, $start);
  2567. }
  2568. else
  2569. {
  2570. return array_slice($items, $start, $end);
  2571. }
  2572. }
  2573. else
  2574. {
  2575. trigger_error('Cannot merge zero Simplepie objects', E_USER_WARNING);
  2576. return array();
  2577. }
  2578. }
  2579. }
  2580. ?>