PageRenderTime 55ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 3ms

/wp-includes/class-simplepie.php

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

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