PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 2ms

/sites/all/libraries/simplepie/simplepie.compiled.php

https://bitbucket.org/micahw156/sites_blogrimage
PHP | 17768 lines | 13791 code | 806 blank | 3171 comment | 1093 complexity | b6088f03aac9d03ccc0cb912103496d8 MD5 | raw file
Possible License(s): GPL-2.0

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

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

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