PageRenderTime 72ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 0ms

/サイト/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

Large files files are truncated, but you can click here to view the full 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

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