PageRenderTime 72ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 1ms

/vtlib/thirdparty/parser/feed/simplepie.inc

https://bitbucket.org/jhunsinfotech/blue-blues
PHP | 13675 lines | 11719 code | 627 blank | 1329 comment | 918 complexity | 13c2cfe92db9b0170972ecf34c824c87 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0

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

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

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