PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 3ms

/lib/simplepie/simplepie.class.php

https://bitbucket.org/ngmares/moodle
PHP | 14538 lines | 11496 code | 1022 blank | 2020 comment | 1074 complexity | a3779241186efe0fe666f139a541cd3e MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-3.0, Apache-2.0, BSD-3-Clause

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

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