PageRenderTime 58ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/modules/mod_jw_srfr/simplepie.inc

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

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