PageRenderTime 59ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/サイト/wp/wp-includes/class-simplepie.php

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