PageRenderTime 91ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 2ms

/sites/all/modules/activitystream/activitystream_feed/simplepie.inc

https://github.com/jiva-technology/smcuk
PHP | 13269 lines | 11493 code | 585 blank | 1191 comment | 874 complexity | bbb6c1c21dce3ccfd35747c34f9f4c8d MD5 | raw file
Possible License(s): LGPL-2.1

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

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

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