PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 1ms

/plugins/feed/simplepie.inc.php

https://github.com/Dratone/EveBB
PHP | 10529 lines | 8933 code | 498 blank | 1098 comment | 744 complexity | 277ccfe63c40c1e89aa5d29bb2e3c6c0 MD5 | raw file
Possible License(s): GPL-2.0

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

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