PageRenderTime 65ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/sites/all/modules/feedapi/parser_simplepie/simplepie.inc

https://github.com/jiva-technology/smcuk
PHP | 13316 lines | 11530 code | 588 blank | 1198 comment | 902 complexity | dae5016ecb0c5d5ed287b127ca50132f MD5 | raw file
Possible License(s): LGPL-2.1

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

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

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