PageRenderTime 63ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 2ms

/libraries/simplepie/simplepie.php

https://bitbucket.org/biojazzard/joomla-eboracast
PHP | 15007 lines | 11793 code | 1089 blank | 2125 comment | 1153 complexity | 49b81064bcec2659085fdcee46215a23 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, MIT, BSD-3-Clause

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

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

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