PageRenderTime 113ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/jiva-technology/smcuk
PHP | 13316 lines | 11530 code | 588 blank | 1198 comment | 902 complexity | dae5016ecb0c5d5ed287b127ca50132f MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-2008, Ryan Parman and Geoffrey Sneddon
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package SimplePie
  36. * @version 1.1.1
  37. * @copyright 2004-2008 Ryan Parman, Geoffrey Sneddon
  38. * @author Ryan Parman
  39. * @author Geoffrey Sneddon
  40. * @link http://simplepie.org/ SimplePie
  41. * @link http://simplepie.org/support/ Please submit all bug reports and feature requests to the SimplePie forums
  42. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  43. * @todo phpDoc comments
  44. */
  45. /**
  46. * SimplePie Name
  47. */
  48. define('SIMPLEPIE_NAME', 'SimplePie');
  49. /**
  50. * SimplePie Version
  51. */
  52. define('SIMPLEPIE_VERSION', '1.1.1');
  53. /**
  54. * SimplePie Build
  55. * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::parse_date() only every load of simplepie.inc)
  56. */
  57. define('SIMPLEPIE_BUILD', 20080315205903);
  58. //define('SIMPLEPIE_BUILD', gmdate('YmdHis', SimplePie_Misc::parse_date(substr('$Date: 2008-03-15 15:28:23 -0700 (Sat, 15 Mar 2008) $', 7, 25)) ? SimplePie_Misc::parse_date(substr('$Date: 2008-03-15 15:28:23 -0700 (Sat, 15 Mar 2008) $', 7, 25)) : filemtime(__FILE__)));
  59. /**
  60. * SimplePie Website URL
  61. */
  62. define('SIMPLEPIE_URL', 'http://simplepie.org');
  63. /**
  64. * SimplePie Useragent
  65. * @see SimplePie::set_useragent()
  66. */
  67. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
  68. /**
  69. * SimplePie Linkback
  70. */
  71. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
  72. /**
  73. * No Autodiscovery
  74. * @see SimplePie::set_autodiscovery_level()
  75. */
  76. define('SIMPLEPIE_LOCATOR_NONE', 0);
  77. /**
  78. * Feed Link Element Autodiscovery
  79. * @see SimplePie::set_autodiscovery_level()
  80. */
  81. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
  82. /**
  83. * Local Feed Extension Autodiscovery
  84. * @see SimplePie::set_autodiscovery_level()
  85. */
  86. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
  87. /**
  88. * Local Feed Body Autodiscovery
  89. * @see SimplePie::set_autodiscovery_level()
  90. */
  91. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
  92. /**
  93. * Remote Feed Extension Autodiscovery
  94. * @see SimplePie::set_autodiscovery_level()
  95. */
  96. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
  97. /**
  98. * Remote Feed Body Autodiscovery
  99. * @see SimplePie::set_autodiscovery_level()
  100. */
  101. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
  102. /**
  103. * All Feed Autodiscovery
  104. * @see SimplePie::set_autodiscovery_level()
  105. */
  106. define('SIMPLEPIE_LOCATOR_ALL', 31);
  107. /**
  108. * No known feed type
  109. */
  110. define('SIMPLEPIE_TYPE_NONE', 0);
  111. /**
  112. * RSS 0.90
  113. */
  114. define('SIMPLEPIE_TYPE_RSS_090', 1);
  115. /**
  116. * RSS 0.91 (Netscape)
  117. */
  118. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
  119. /**
  120. * RSS 0.91 (Userland)
  121. */
  122. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
  123. /**
  124. * RSS 0.91 (both Netscape and Userland)
  125. */
  126. define('SIMPLEPIE_TYPE_RSS_091', 6);
  127. /**
  128. * RSS 0.92
  129. */
  130. define('SIMPLEPIE_TYPE_RSS_092', 8);
  131. /**
  132. * RSS 0.93
  133. */
  134. define('SIMPLEPIE_TYPE_RSS_093', 16);
  135. /**
  136. * RSS 0.94
  137. */
  138. define('SIMPLEPIE_TYPE_RSS_094', 32);
  139. /**
  140. * RSS 1.0
  141. */
  142. define('SIMPLEPIE_TYPE_RSS_10', 64);
  143. /**
  144. * RSS 2.0
  145. */
  146. define('SIMPLEPIE_TYPE_RSS_20', 128);
  147. /**
  148. * RDF-based RSS
  149. */
  150. define('SIMPLEPIE_TYPE_RSS_RDF', 65);
  151. /**
  152. * Non-RDF-based RSS (truly intended as syndication format)
  153. */
  154. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
  155. /**
  156. * All RSS
  157. */
  158. define('SIMPLEPIE_TYPE_RSS_ALL', 255);
  159. /**
  160. * Atom 0.3
  161. */
  162. define('SIMPLEPIE_TYPE_ATOM_03', 256);
  163. /**
  164. * Atom 1.0
  165. */
  166. define('SIMPLEPIE_TYPE_ATOM_10', 512);
  167. /**
  168. * All Atom
  169. */
  170. define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
  171. /**
  172. * All feed types
  173. */
  174. define('SIMPLEPIE_TYPE_ALL', 1023);
  175. /**
  176. * No construct
  177. */
  178. define('SIMPLEPIE_CONSTRUCT_NONE', 0);
  179. /**
  180. * Text construct
  181. */
  182. define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
  183. /**
  184. * HTML construct
  185. */
  186. define('SIMPLEPIE_CONSTRUCT_HTML', 2);
  187. /**
  188. * XHTML construct
  189. */
  190. define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
  191. /**
  192. * base64-encoded construct
  193. */
  194. define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
  195. /**
  196. * IRI construct
  197. */
  198. define('SIMPLEPIE_CONSTRUCT_IRI', 16);
  199. /**
  200. * A construct that might be HTML
  201. */
  202. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
  203. /**
  204. * All constructs
  205. */
  206. define('SIMPLEPIE_CONSTRUCT_ALL', 63);
  207. /**
  208. * PCRE for HTML attributes
  209. */
  210. define('SIMPLEPIE_PCRE_HTML_ATTRIBUTE', '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*');
  211. /**
  212. * PCRE for XML attributes
  213. */
  214. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
  215. /**
  216. * XML Namespace
  217. */
  218. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
  219. /**
  220. * Atom 1.0 Namespace
  221. */
  222. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
  223. /**
  224. * Atom 0.3 Namespace
  225. */
  226. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
  227. /**
  228. * RDF Namespace
  229. */
  230. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  231. /**
  232. * RSS 0.90 Namespace
  233. */
  234. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
  235. /**
  236. * RSS 1.0 Namespace
  237. */
  238. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
  239. /**
  240. * RSS 1.0 Content Module Namespace
  241. */
  242. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
  243. /**
  244. * DC 1.0 Namespace
  245. */
  246. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
  247. /**
  248. * DC 1.1 Namespace
  249. */
  250. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
  251. /**
  252. * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
  253. */
  254. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
  255. /**
  256. * GeoRSS Namespace
  257. */
  258. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
  259. /**
  260. * Media RSS Namespace
  261. */
  262. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
  263. /**
  264. * Wrong Media RSS Namespace
  265. */
  266. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
  267. /**
  268. * iTunes RSS Namespace
  269. */
  270. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  271. /**
  272. * XHTML Namespace
  273. */
  274. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
  275. /**
  276. * IANA Link Relations Registry
  277. */
  278. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
  279. /**
  280. * Whether we're running on PHP5
  281. */
  282. define('SIMPLEPIE_PHP5', version_compare(PHP_VERSION, '5.0.0', '>='));
  283. /**
  284. * No file source
  285. */
  286. define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
  287. /**
  288. * Remote file source
  289. */
  290. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
  291. /**
  292. * Local file source
  293. */
  294. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
  295. /**
  296. * fsockopen() file source
  297. */
  298. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
  299. /**
  300. * cURL file source
  301. */
  302. define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
  303. /**
  304. * file_get_contents() file source
  305. */
  306. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
  307. /**
  308. * SimplePie
  309. *
  310. * @package SimplePie
  311. * @version "Razzleberry"
  312. * @copyright 2004-2007 Ryan Parman, Geoffrey Sneddon
  313. * @author Ryan Parman
  314. * @author Geoffrey Sneddon
  315. * @todo Option for type of fetching (cache, not modified header, fetch, etc.)
  316. */
  317. class SimplePie
  318. {
  319. /**
  320. * @var array Raw data
  321. * @access private
  322. */
  323. var $data = array();
  324. /**
  325. * @var mixed Error string
  326. * @access private
  327. */
  328. var $error;
  329. /**
  330. * @var object Instance of SimplePie_Sanitize (or other class)
  331. * @see SimplePie::set_sanitize_class()
  332. * @access private
  333. */
  334. var $sanitize;
  335. /**
  336. * @var string SimplePie Useragent
  337. * @see SimplePie::set_useragent()
  338. * @access private
  339. */
  340. var $useragent = SIMPLEPIE_USERAGENT;
  341. /**
  342. * @var string Feed URL
  343. * @see SimplePie::set_feed_url()
  344. * @access private
  345. */
  346. var $feed_url;
  347. /**
  348. * @var object Instance of SimplePie_File to use as a feed
  349. * @see SimplePie::set_file()
  350. * @access private
  351. */
  352. var $file;
  353. /**
  354. * @var string Raw feed data
  355. * @see SimplePie::set_raw_data()
  356. * @access private
  357. */
  358. var $raw_data;
  359. /**
  360. * @var int Timeout for fetching remote files
  361. * @see SimplePie::set_timeout()
  362. * @access private
  363. */
  364. var $timeout = 10;
  365. /**
  366. * @var bool Forces fsockopen() to be used for remote files instead
  367. * of cURL, even if a new enough version is installed
  368. * @see SimplePie::force_fsockopen()
  369. * @access private
  370. */
  371. var $force_fsockopen = false;
  372. /**
  373. * @var bool Force the given data/URL to be treated as a feed no matter what
  374. * it appears like
  375. * @see SimplePie::force_feed()
  376. * @access private
  377. */
  378. var $force_feed = false;
  379. /**
  380. * @var bool Enable/Disable XML dump
  381. * @see SimplePie::enable_xml_dump()
  382. * @access private
  383. */
  384. var $xml_dump = false;
  385. /**
  386. * @var bool Enable/Disable Caching
  387. * @see SimplePie::enable_cache()
  388. * @access private
  389. */
  390. var $cache = true;
  391. /**
  392. * @var int Cache duration (in seconds)
  393. * @see SimplePie::set_cache_duration()
  394. * @access private
  395. */
  396. var $cache_duration = 3600;
  397. /**
  398. * @var int Auto-discovery cache duration (in seconds)
  399. * @see SimplePie::set_autodiscovery_cache_duration()
  400. * @access private
  401. */
  402. var $autodiscovery_cache_duration = 604800; // 7 Days.
  403. /**
  404. * @var string Cache location (relative to executing script)
  405. * @see SimplePie::set_cache_location()
  406. * @access private
  407. */
  408. var $cache_location = './cache';
  409. /**
  410. * @var string Function that creates the cache filename
  411. * @see SimplePie::set_cache_name_function()
  412. * @access private
  413. */
  414. var $cache_name_function = 'md5';
  415. /**
  416. * @var bool Reorder feed by date descending
  417. * @see SimplePie::enable_order_by_date()
  418. * @access private
  419. */
  420. var $order_by_date = true;
  421. /**
  422. * @var mixed Force input encoding to be set to the follow value
  423. * (false, or anything type-cast to false, disables this feature)
  424. * @see SimplePie::set_input_encoding()
  425. * @access private
  426. */
  427. var $input_encoding = false;
  428. /**
  429. * @var int Feed Autodiscovery Level
  430. * @see SimplePie::set_autodiscovery_level()
  431. * @access private
  432. */
  433. var $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  434. /**
  435. * @var string Class used for caching feeds
  436. * @see SimplePie::set_cache_class()
  437. * @access private
  438. */
  439. var $cache_class = 'SimplePie_Cache';
  440. /**
  441. * @var string Class used for locating feeds
  442. * @see SimplePie::set_locator_class()
  443. * @access private
  444. */
  445. var $locator_class = 'SimplePie_Locator';
  446. /**
  447. * @var string Class used for parsing feeds
  448. * @see SimplePie::set_parser_class()
  449. * @access private
  450. */
  451. var $parser_class = 'SimplePie_Parser';
  452. /**
  453. * @var string Class used for fetching feeds
  454. * @see SimplePie::set_file_class()
  455. * @access private
  456. */
  457. var $file_class = 'SimplePie_File';
  458. /**
  459. * @var string Class used for items
  460. * @see SimplePie::set_item_class()
  461. * @access private
  462. */
  463. var $item_class = 'SimplePie_Item';
  464. /**
  465. * @var string Class used for authors
  466. * @see SimplePie::set_author_class()
  467. * @access private
  468. */
  469. var $author_class = 'SimplePie_Author';
  470. /**
  471. * @var string Class used for categories
  472. * @see SimplePie::set_category_class()
  473. * @access private
  474. */
  475. var $category_class = 'SimplePie_Category';
  476. /**
  477. * @var string Class used for enclosures
  478. * @see SimplePie::set_enclosures_class()
  479. * @access private
  480. */
  481. var $enclosure_class = 'SimplePie_Enclosure';
  482. /**
  483. * @var string Class used for Media RSS <media:text> captions
  484. * @see SimplePie::set_caption_class()
  485. * @access private
  486. */
  487. var $caption_class = 'SimplePie_Caption';
  488. /**
  489. * @var string Class used for Media RSS <media:copyright>
  490. * @see SimplePie::set_copyright_class()
  491. * @access private
  492. */
  493. var $copyright_class = 'SimplePie_Copyright';
  494. /**
  495. * @var string Class used for Media RSS <media:credit>
  496. * @see SimplePie::set_credit_class()
  497. * @access private
  498. */
  499. var $credit_class = 'SimplePie_Credit';
  500. /**
  501. * @var string Class used for Media RSS <media:rating>
  502. * @see SimplePie::set_rating_class()
  503. * @access private
  504. */
  505. var $rating_class = 'SimplePie_Rating';
  506. /**
  507. * @var string Class used for Media RSS <media:restriction>
  508. * @see SimplePie::set_restriction_class()
  509. * @access private
  510. */
  511. var $restriction_class = 'SimplePie_Restriction';
  512. /**
  513. * @var string Class used for content-type sniffing
  514. * @see SimplePie::set_content_type_sniffer_class()
  515. * @access private
  516. */
  517. var $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
  518. /**
  519. * @var string Class used for item sources.
  520. * @see SimplePie::set_source_class()
  521. * @access private
  522. */
  523. var $source_class = 'SimplePie_Source';
  524. /**
  525. * @var mixed Set javascript query string parameter (false, or
  526. * anything type-cast to false, disables this feature)
  527. * @see SimplePie::set_javascript()
  528. * @access private
  529. */
  530. var $javascript = 'js';
  531. /**
  532. * @var int Maximum number of feeds to check with autodiscovery
  533. * @see SimplePie::set_max_checked_feeds()
  534. * @access private
  535. */
  536. var $max_checked_feeds = 10;
  537. /**
  538. * @var string Web-accessible path to the handler_favicon.php file.
  539. * @see SimplePie::set_favicon_handler()
  540. * @access private
  541. */
  542. var $favicon_handler = '';
  543. /**
  544. * @var string Web-accessible path to the handler_image.php file.
  545. * @see SimplePie::set_image_handler()
  546. * @access private
  547. */
  548. var $image_handler = '';
  549. /**
  550. * @var array Stores the URLs when multiple feeds are being initialized.
  551. * @see SimplePie::set_feed_url()
  552. * @access private
  553. */
  554. var $multifeed_url = array();
  555. /**
  556. * @var array Stores SimplePie objects when multiple feeds initialized.
  557. * @access private
  558. */
  559. var $multifeed_objects = array();
  560. /**
  561. * @var array Stores the get_object_vars() array for use with multifeeds.
  562. * @see SimplePie::set_feed_url()
  563. * @access private
  564. */
  565. var $config_settings = null;
  566. /**
  567. * @var integer Stores the number of items to return per-feed with multifeeds.
  568. * @see SimplePie::set_item_limit()
  569. * @access private
  570. */
  571. var $item_limit = 0;
  572. /**
  573. * @var array Stores the default attributes to be stripped by strip_attributes().
  574. * @see SimplePie::strip_attributes()
  575. * @access private
  576. */
  577. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  578. /**
  579. * @var array Stores the default tags to be stripped by strip_htmltags().
  580. * @see SimplePie::strip_htmltags()
  581. * @access private
  582. */
  583. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  584. /**
  585. * The SimplePie class contains feed level data and options
  586. *
  587. * There are two ways that you can create a new SimplePie object. The first
  588. * is by passing a feed URL as a parameter to the SimplePie constructor
  589. * (as well as optionally setting the cache location and cache expiry). This
  590. * will initialise the whole feed with all of the default settings, and you
  591. * can begin accessing methods and properties immediately.
  592. *
  593. * The second way is to create the SimplePie object with no parameters
  594. * at all. This will enable you to set configuration options. After setting
  595. * them, you must initialise the feed using $feed->init(). At that point the
  596. * object's methods and properties will be available to you. This format is
  597. * what is used throughout this documentation.
  598. *
  599. * @access public
  600. * @since 1.0 Preview Release
  601. * @param string $feed_url This is the URL you want to parse.
  602. * @param string $cache_location This is where you want the cache to be stored.
  603. * @param int $cache_duration This is the number of seconds that you want to store the cache file for.
  604. */
  605. function SimplePie($feed_url = null, $cache_location = null, $cache_duration = null)
  606. {
  607. // Other objects, instances created here so we can set options on them
  608. $this->sanitize =& new SimplePie_Sanitize;
  609. // Set options if they're passed to the constructor
  610. if ($cache_location !== null)
  611. {
  612. $this->set_cache_location($cache_location);
  613. }
  614. if ($cache_duration !== null)
  615. {
  616. $this->set_cache_duration($cache_duration);
  617. }
  618. // Only init the script if we're passed a feed URL
  619. if ($feed_url !== null)
  620. {
  621. $this->set_feed_url($feed_url);
  622. $this->init();
  623. }
  624. }
  625. /**
  626. * Used for converting object to a string
  627. */
  628. function __toString()
  629. {
  630. return md5(serialize($this->data));
  631. }
  632. /**
  633. * Remove items that link back to this before destroying this object
  634. */
  635. function __destruct()
  636. {
  637. if (!empty($this->data['items']))
  638. {
  639. foreach ($this->data['items'] as $item)
  640. {
  641. $item->__destruct();
  642. }
  643. unset($this->data['items']);
  644. }
  645. if (!empty($this->data['ordered_items']))
  646. {
  647. foreach ($this->data['ordered_items'] as $item)
  648. {
  649. $item->__destruct();
  650. }
  651. unset($this->data['ordered_items']);
  652. }
  653. }
  654. /**
  655. * Force the given data/URL to be treated as a feed no matter what it
  656. * appears like
  657. *
  658. * @access public
  659. * @since 1.1
  660. * @param bool $enable Force the given data/URL to be treated as a feed
  661. */
  662. function force_feed($enable = false)
  663. {
  664. $this->force_feed = (bool) $enable;
  665. }
  666. /**
  667. * This is the URL of the feed you want to parse.
  668. *
  669. * This allows you to enter the URL of the feed you want to parse, or the
  670. * website you want to try to use auto-discovery on. This takes priority
  671. * over any set raw data.
  672. *
  673. * You can set multiple feeds to mash together by passing an array instead
  674. * of a string for the $url. Remember that with each additional feed comes
  675. * additional processing and resources.
  676. *
  677. * @access public
  678. * @since 1.0 Preview Release
  679. * @param mixed $url This is the URL (or array of URLs) that you want to parse.
  680. * @see SimplePie::set_raw_data()
  681. */
  682. function set_feed_url($url)
  683. {
  684. if (is_array($url))
  685. {
  686. $this->multifeed_url = array();
  687. foreach ($url as $value)
  688. {
  689. $this->multifeed_url[] = SimplePie_Misc::fix_protocol($value, 1);
  690. }
  691. }
  692. else
  693. {
  694. $this->feed_url = SimplePie_Misc::fix_protocol($url, 1);
  695. }
  696. }
  697. /**
  698. * Provides an instance of SimplePie_File to use as a feed
  699. *
  700. * @access public
  701. * @param object &$file Instance of SimplePie_File (or subclass)
  702. * @return bool True on success, false on failure
  703. */
  704. function set_file(&$file)
  705. {
  706. if (is_a($file, 'SimplePie_File'))
  707. {
  708. $this->feed_url = $file->url;
  709. $this->file =& $file;
  710. return true;
  711. }
  712. return false;
  713. }
  714. /**
  715. * Allows you to use a string of RSS/Atom data instead of a remote feed.
  716. *
  717. * If you have a feed available as a string in PHP, you can tell SimplePie
  718. * to parse that data string instead of a remote feed. Any set feed URL
  719. * takes precedence.
  720. *
  721. * @access public
  722. * @since 1.0 Beta 3
  723. * @param string $data RSS or Atom data as a string.
  724. * @see SimplePie::set_feed_url()
  725. */
  726. function set_raw_data($data)
  727. {
  728. $this->raw_data = $data;
  729. }
  730. /**
  731. * Allows you to override the default timeout for fetching remote feeds.
  732. *
  733. * This allows you to change the maximum time the feed's server to respond
  734. * and send the feed back.
  735. *
  736. * @access public
  737. * @since 1.0 Beta 3
  738. * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
  739. */
  740. function set_timeout($timeout = 10)
  741. {
  742. $this->timeout = (int) $timeout;
  743. }
  744. /**
  745. * Forces SimplePie to use fsockopen() instead of the preferred cURL
  746. * functions.
  747. *
  748. * @access public
  749. * @since 1.0 Beta 3
  750. * @param bool $enable Force fsockopen() to be used
  751. */
  752. function force_fsockopen($enable = false)
  753. {
  754. $this->force_fsockopen = (bool) $enable;
  755. }
  756. /**
  757. * Outputs the raw XML content of the feed, after it has gone through
  758. * SimplePie's filters.
  759. *
  760. * Used only for debugging, this function will output the XML content as
  761. * text/xml. When SimplePie reads in a feed, it does a bit of cleaning up
  762. * before trying to parse it. Many parts of the feed are re-written in
  763. * memory, and in the end, you have a parsable feed. XML dump shows you the
  764. * actual XML that SimplePie tries to parse, which may or may not be very
  765. * different from the original feed.
  766. *
  767. * @access public
  768. * @since 1.0 Preview Release
  769. * @param bool $enable Enable XML dump
  770. */
  771. function enable_xml_dump($enable = false)
  772. {
  773. $this->xml_dump = (bool) $enable;
  774. }
  775. /**
  776. * Enables/disables caching in SimplePie.
  777. *
  778. * This option allows you to disable caching all-together in SimplePie.
  779. * However, disabling the cache can lead to longer load times.
  780. *
  781. * @access public
  782. * @since 1.0 Preview Release
  783. * @param bool $enable Enable caching
  784. */
  785. function enable_cache($enable = true)
  786. {
  787. $this->cache = (bool) $enable;
  788. }
  789. /**
  790. * Set the length of time (in seconds) that the contents of a feed
  791. * will be cached.
  792. *
  793. * @access public
  794. * @param int $seconds The feed content cache duration.
  795. */
  796. function set_cache_duration($seconds = 3600)
  797. {
  798. $this->cache_duration = (int) $seconds;
  799. }
  800. /**
  801. * Set the length of time (in seconds) that the autodiscovered feed
  802. * URL will be cached.
  803. *
  804. * @access public
  805. * @param int $seconds The autodiscovered feed URL cache duration.
  806. */
  807. function set_autodiscovery_cache_duration($seconds = 604800)
  808. {
  809. $this->autodiscovery_cache_duration = (int) $seconds;
  810. }
  811. /**
  812. * Set the file system location where the cached files should be stored.
  813. *
  814. * @access public
  815. * @param string $location The file system location.
  816. */
  817. function set_cache_location($location = './cache')
  818. {
  819. $this->cache_location = (string) $location;
  820. }
  821. /**
  822. * Determines whether feed items should be sorted into reverse chronological order.
  823. *
  824. * @access public
  825. * @param bool $enable Sort as reverse chronological order.
  826. */
  827. function enable_order_by_date($enable = true)
  828. {
  829. $this->order_by_date = (bool) $enable;
  830. }
  831. /**
  832. * Allows you to override the character encoding reported by the feed.
  833. *
  834. * @access public
  835. * @param string $encoding Character encoding.
  836. */
  837. function set_input_encoding($encoding = false)
  838. {
  839. if ($encoding)
  840. {
  841. $this->input_encoding = (string) $encoding;
  842. }
  843. else
  844. {
  845. $this->input_encoding = false;
  846. }
  847. }
  848. /**
  849. * Set how much feed autodiscovery to do
  850. *
  851. * @access public
  852. * @see SIMPLEPIE_LOCATOR_NONE
  853. * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
  854. * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
  855. * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
  856. * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
  857. * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
  858. * @see SIMPLEPIE_LOCATOR_ALL
  859. * @param int $level Feed Autodiscovery Level (level can be a
  860. * combination of the above constants, see bitwise OR operator)
  861. */
  862. function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  863. {
  864. $this->autodiscovery = (int) $level;
  865. }
  866. /**
  867. * Allows you to change which class SimplePie uses for caching.
  868. * Useful when you are overloading or extending SimplePie's default classes.
  869. *
  870. * @access public
  871. * @param string $class Name of custom class.
  872. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  873. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  874. */
  875. function set_cache_class($class = 'SimplePie_Cache')
  876. {
  877. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Cache'))
  878. {
  879. $this->cache_class = $class;
  880. return true;
  881. }
  882. return false;
  883. }
  884. /**
  885. * Allows you to change which class SimplePie uses for auto-discovery.
  886. * Useful when you are overloading or extending SimplePie's default classes.
  887. *
  888. * @access public
  889. * @param string $class Name of custom class.
  890. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  891. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  892. */
  893. function set_locator_class($class = 'SimplePie_Locator')
  894. {
  895. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Locator'))
  896. {
  897. $this->locator_class = $class;
  898. return true;
  899. }
  900. return false;
  901. }
  902. /**
  903. * Allows you to change which class SimplePie uses for XML parsing.
  904. * Useful when you are overloading or extending SimplePie's default classes.
  905. *
  906. * @access public
  907. * @param string $class Name of custom class.
  908. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  909. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  910. */
  911. function set_parser_class($class = 'SimplePie_Parser')
  912. {
  913. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Parser'))
  914. {
  915. $this->parser_class = $class;
  916. return true;
  917. }
  918. return false;
  919. }
  920. /**
  921. * Allows you to change which class SimplePie uses for remote file fetching.
  922. * Useful when you are overloading or extending SimplePie's default classes.
  923. *
  924. * @access public
  925. * @param string $class Name of custom class.
  926. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  927. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  928. */
  929. function set_file_class($class = 'SimplePie_File')
  930. {
  931. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_File'))
  932. {
  933. $this->file_class = $class;
  934. return true;
  935. }
  936. return false;
  937. }
  938. /**
  939. * Allows you to change which class SimplePie uses for data sanitization.
  940. * Useful when you are overloading or extending SimplePie's default classes.
  941. *
  942. * @access public
  943. * @param string $class Name of custom class.
  944. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  945. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  946. */
  947. function set_sanitize_class($class = 'SimplePie_Sanitize')
  948. {
  949. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Sanitize'))
  950. {
  951. $this->sanitize =& new $class;
  952. return true;
  953. }
  954. return false;
  955. }
  956. /**
  957. * Allows you to change which class SimplePie uses for handling feed items.
  958. * Useful when you are overloading or extending SimplePie's default classes.
  959. *
  960. * @access public
  961. * @param string $class Name of custom class.
  962. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  963. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  964. */
  965. function set_item_class($class = 'SimplePie_Item')
  966. {
  967. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Item'))
  968. {
  969. $this->item_class = $class;
  970. return true;
  971. }
  972. return false;
  973. }
  974. /**
  975. * Allows you to change which class SimplePie uses for handling author data.
  976. * Useful when you are overloading or extending SimplePie's default classes.
  977. *
  978. * @access public
  979. * @param string $class Name of custom class.
  980. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  981. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  982. */
  983. function set_author_class($class = 'SimplePie_Author')
  984. {
  985. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Author'))
  986. {
  987. $this->author_class = $class;
  988. return true;
  989. }
  990. return false;
  991. }
  992. /**
  993. * Allows you to change which class SimplePie uses for handling category data.
  994. * Useful when you are overloading or extending SimplePie's default classes.
  995. *
  996. * @access public
  997. * @param string $class Name of custom class.
  998. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  999. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1000. */
  1001. function set_category_class($class = 'SimplePie_Category')
  1002. {
  1003. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Category'))
  1004. {
  1005. $this->category_class = $class;
  1006. return true;
  1007. }
  1008. return false;
  1009. }
  1010. /**
  1011. * Allows you to change which class SimplePie uses for feed enclosures.
  1012. * Useful when you are overloading or extending SimplePie's default classes.
  1013. *
  1014. * @access public
  1015. * @param string $class Name of custom class.
  1016. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1017. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1018. */
  1019. function set_enclosure_class($class = 'SimplePie_Enclosure')
  1020. {
  1021. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Enclosure'))
  1022. {
  1023. $this->enclosure_class = $class;
  1024. return true;
  1025. }
  1026. return false;
  1027. }
  1028. /**
  1029. * Allows you to change which class SimplePie uses for <media:text> captions
  1030. * Useful when you are overloading or extending SimplePie's default classes.
  1031. *
  1032. * @access public
  1033. * @param string $class Name of custom class.
  1034. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1035. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1036. */
  1037. function set_caption_class($class = 'SimplePie_Caption')
  1038. {
  1039. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Caption'))
  1040. {
  1041. $this->caption_class = $class;
  1042. return true;
  1043. }
  1044. return false;
  1045. }
  1046. /**
  1047. * Allows you to change which class SimplePie uses for <media:copyright>
  1048. * Useful when you are overloading or extending SimplePie's default classes.
  1049. *
  1050. * @access public
  1051. * @param string $class Name of custom class.
  1052. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1053. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1054. */
  1055. function set_copyright_class($class = 'SimplePie_Copyright')
  1056. {
  1057. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Copyright'))
  1058. {
  1059. $this->copyright_class = $class;
  1060. return true;
  1061. }
  1062. return false;
  1063. }
  1064. /**
  1065. * Allows you to change which class SimplePie uses for <media:credit>
  1066. * Useful when you are overloading or extending SimplePie's default classes.
  1067. *
  1068. * @access public
  1069. * @param string $class Name of custom class.
  1070. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1071. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1072. */
  1073. function set_credit_class($class = 'SimplePie_Credit')
  1074. {
  1075. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Credit'))
  1076. {
  1077. $this->credit_class = $class;
  1078. return true;
  1079. }
  1080. return false;
  1081. }
  1082. /**
  1083. * Allows you to change which class SimplePie uses for <media:rating>
  1084. * Useful when you are overloading or extending SimplePie's default classes.
  1085. *
  1086. * @access public
  1087. * @param string $class Name of custom class.
  1088. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1089. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1090. */
  1091. function set_rating_class($class = 'SimplePie_Rating')
  1092. {
  1093. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Rating'))
  1094. {
  1095. $this->rating_class = $class;
  1096. return true;
  1097. }
  1098. return false;
  1099. }
  1100. /**
  1101. * Allows you to change which class SimplePie uses for <media:restriction>
  1102. * Useful when you are overloading or extending SimplePie's default classes.
  1103. *
  1104. * @access public
  1105. * @param string $class Name of custom class.
  1106. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1107. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1108. */
  1109. function set_restriction_class($class = 'SimplePie_Restriction')
  1110. {
  1111. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Restriction'))
  1112. {
  1113. $this->restriction_class = $class;
  1114. return true;
  1115. }
  1116. return false;
  1117. }
  1118. /**
  1119. * Allows you to change which class SimplePie uses for content-type sniffing.
  1120. * Useful when you are overloading or extending SimplePie's default classes.
  1121. *
  1122. * @access public
  1123. * @param string $class Name of custom class.
  1124. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1125. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1126. */
  1127. function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
  1128. {
  1129. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Content_Type_Sniffer'))
  1130. {
  1131. $this->content_type_sniffer_class = $class;
  1132. return true;
  1133. }
  1134. return false;
  1135. }
  1136. /**
  1137. * Allows you to change which class SimplePie uses item sources.
  1138. * Useful when you are overloading or extending SimplePie's default classes.
  1139. *
  1140. * @access public
  1141. * @param string $class Name of custom class.
  1142. * @link http://php.net/manual/en/keyword.extends.php PHP4 extends documentation
  1143. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  1144. */
  1145. function set_source_class($class = 'SimplePie_Source')
  1146. {
  1147. if (SimplePie_Misc::is_subclass_of($class, 'SimplePie_Source'))
  1148. {
  1149. $this->source_class = $class;
  1150. return true;
  1151. }
  1152. return false;
  1153. }
  1154. /**
  1155. * Allows you to override the default user agent string.
  1156. *
  1157. * @access public
  1158. * @param string $ua New user agent string.
  1159. */
  1160. function set_useragent($ua = SIMPLEPIE_USERAGENT)
  1161. {
  1162. $this->useragent = (string) $ua;
  1163. }
  1164. /**
  1165. * Set callback function to create cache filename with
  1166. *
  1167. * @access public
  1168. * @param mixed $function Callback function
  1169. */
  1170. function set_cache_name_function($function = 'md5')
  1171. {
  1172. if (is_callable($function))
  1173. {
  1174. $this->cache_name_function = $function;
  1175. }
  1176. }
  1177. /**
  1178. * Set javascript query string parameter
  1179. *
  1180. * @access public
  1181. * @param mixed $get Javascript query string parameter
  1182. */
  1183. function set_javascript($get = 'js')
  1184. {
  1185. if ($get)
  1186. {
  1187. $this->javascript = (string) $get;
  1188. }
  1189. else
  1190. {
  1191. $this->javascript = false;
  1192. }
  1193. }
  1194. /**
  1195. * Set options to make SP as fast as possible. Forgoes a
  1196. * substantial amount of data sanitization in favor of speed.
  1197. *
  1198. * @access public
  1199. * @param bool $set Whether to set them or not
  1200. */
  1201. function set_stupidly_fast($set = false)
  1202. {
  1203. if ($set)
  1204. {
  1205. $this->enable_order_by_date(false);
  1206. $this->remove_div(false);
  1207. $this->strip_comments(false);
  1208. $this->strip_htmltags(false);
  1209. $this->strip_attributes(false);
  1210. $this->set_image_handler(false);
  1211. }
  1212. }
  1213. /**
  1214. * Set maximum number of feeds to check with autodiscovery
  1215. *
  1216. * @access public
  1217. * @param int $max Maximum number of feeds to check
  1218. */
  1219. function set_max_checked_feeds($max = 10)
  1220. {
  1221. $this->max_checked_feeds = (int) $max;
  1222. }
  1223. function remove_div($enable = true)
  1224. {
  1225. $this->sanitize->remove_div($enable);
  1226. }
  1227. function strip_htmltags($tags = '', $encode = null)
  1228. {
  1229. if ($tags === '')
  1230. {
  1231. $tags = $this->strip_htmltags;
  1232. }
  1233. $this->sanitize->strip_htmltags($tags);
  1234. if ($encode !== null)
  1235. {
  1236. $this->sanitize->encode_instead_of_strip($tags);
  1237. }
  1238. }
  1239. function encode_instead_of_strip($enable = true)
  1240. {
  1241. $this->sanitize->encode_instead_of_strip($enable);
  1242. }
  1243. function strip_attributes($attribs = '')
  1244. {
  1245. if ($attribs === '')
  1246. {
  1247. $attribs = $this->strip_attributes;
  1248. }
  1249. $this->sanitize->strip_attributes($attribs);
  1250. }
  1251. function set_output_encoding($encoding = 'UTF-8')
  1252. {
  1253. $this->sanitize->set_output_encoding($encoding);
  1254. }
  1255. function strip_comments($strip = false)
  1256. {
  1257. $this->sanitize->strip_comments($strip);
  1258. }
  1259. /**
  1260. * Set element/attribute key/value pairs of HTML attributes
  1261. * containing URLs that need to be resolved relative to the feed
  1262. *
  1263. * @access public
  1264. * @since 1.0
  1265. * @param array $element_attribute Element/attribute key/value pairs
  1266. */
  1267. function set_url_replacements($element_attribute = array('a' => 'href', 'area' => 'href', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', 'img' => array('longdesc', 'src'), 'input' => 'src', 'ins' => 'cite', 'q' => 'cite'))
  1268. {
  1269. $this->sanitize->set_url_replacements($element_attribute);
  1270. }
  1271. /**
  1272. * Set the handler to enable the display of cached favicons.
  1273. *
  1274. * @access public
  1275. * @param str $page Web-accessible path to the handler_favicon.php file.
  1276. * @param str $qs The query string that the value should be passed to.
  1277. */
  1278. function set_favicon_handler($page = false, $qs = 'i')
  1279. {
  1280. if ($page != false)
  1281. {
  1282. $this->favicon_handler = $page . '?' . $qs . '=';
  1283. }
  1284. else
  1285. {
  1286. $this->favicon_handler = '';
  1287. }
  1288. }
  1289. /**
  1290. * Set the handler to enable the display of cached images.
  1291. *
  1292. * @access public
  1293. * @param str $page Web-accessible path to the handler_image.php file.
  1294. * @param str $qs The query string that the value should be passed to.
  1295. */
  1296. function set_image_handler($page = false, $qs = 'i')
  1297. {
  1298. if ($page != false)
  1299. {
  1300. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  1301. }
  1302. else
  1303. {
  1304. $this->image_handler = '';
  1305. }
  1306. }
  1307. /**
  1308. * Set the limit for items returned per-feed with multifeeds.
  1309. *
  1310. * @access public
  1311. * @param integer $limit The maximum number of items to return.
  1312. */
  1313. function set_item_limit($limit = 0)
  1314. {
  1315. $this->item_limit = (int) $limit;
  1316. }
  1317. function init()
  1318. {
  1319. if ((function_exists('version_compare') && version_compare(PHP_VERSION, '4.3.0', '<')) || !extension_loaded('xml') || !extension_loaded('pcre'))
  1320. {
  1321. return false;
  1322. }
  1323. if (isset($_GET[$this->javascript]))
  1324. {
  1325. if (function_exists('ob_gzhandler'))
  1326. {
  1327. ob_start('ob_gzhandler');
  1328. }
  1329. header('Content-type: text/javascript; charset: UTF-8');
  1330. header('Cache-Control: must-revalidate');
  1331. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  1332. ?>
  1333. function embed_odeo(link) {
  1334. document.writeln('<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed>');
  1335. }
  1336. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
  1337. if (placeholder != '') {
  1338. document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
  1339. }
  1340. else {
  1341. document.writeln('<embed type="'+type+'" style="cursor:hand; cursor:pointer;" src="'+link+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="true" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed>');
  1342. }
  1343. }
  1344. function embed_flash(bgcolor, width, height, link, loop, type) {
  1345. document.writeln('<embed src="'+link+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed>');
  1346. }
  1347. function embed_flv(width, height, link, placeholder, loop, player) {
  1348. document.writeln('<embed src="'+player+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="'+width+'" height="'+height+'" wmode="transparent" flashvars="file='+link+'&autostart=false&repeat='+loop+'&showdigits=true&showfsbutton=false"></embed>');
  1349. }
  1350. function embed_wmedia(width, height, link) {
  1351. document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
  1352. }
  1353. <?php
  1354. exit;
  1355. }
  1356. // Pass whatever was set with config options over to the sanitizer.
  1357. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->cache_class);
  1358. $this->sanitize->pass_file_data($this->file_class, $this->timeout, $this->useragent, $this->force_fsockopen);
  1359. if ($this->feed_url !== null || $this->raw_data !== null)
  1360. {
  1361. $this->data = array();
  1362. $this->multifeed_objects = array();
  1363. $cache = false;
  1364. if ($this->feed_url !== null)
  1365. {
  1366. $parsed_feed_url = SimplePie_Misc::parse_url($this->feed_url);
  1367. // Decide whether to enable caching
  1368. if ($this->cache && $parsed_feed_url['scheme'] !== '')
  1369. {
  1370. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc');
  1371. }
  1372. // If it's enabled and we don't want an XML dump, use the cache
  1373. if ($cache && !$this->xml_dump)
  1374. {
  1375. // Load the Cache
  1376. $this->data = $cache->load();
  1377. if (!empty($this->data))
  1378. {
  1379. // If the cache is for an outdated build of SimplePie
  1380. if (!isset($this->data['build']) || $this->data['build'] != SIMPLEPIE_BUILD)
  1381. {
  1382. $cache->unlink();
  1383. $this->data = array();
  1384. }
  1385. // If we've hit a collision just rerun it with caching disabled
  1386. elseif (isset($this->data['url']) && $this->data['url'] != $this->feed_url)
  1387. {
  1388. $cache = false;
  1389. $this->data = array();
  1390. }
  1391. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
  1392. elseif (isset($this->data['feed_url']))
  1393. {
  1394. // If the autodiscovery cache is still valid use it.
  1395. if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
  1396. {
  1397. // Do not need to do feed autodiscovery yet.
  1398. if ($this->data['feed_url'] == $this->data['url'])
  1399. {
  1400. $cache->unlink();
  1401. $this->data = array();
  1402. }
  1403. else
  1404. {
  1405. $this->set_feed_url($this->data['feed_url']);
  1406. return $this->init();
  1407. }
  1408. }
  1409. }
  1410. // Check if the cache has been updated
  1411. elseif ($cache->mtime() + $this->cache_duration < time())
  1412. {
  1413. // If we have last-modified and/or etag set
  1414. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
  1415. {
  1416. $headers = array();
  1417. if (isset($this->data['headers']['last-modified']))
  1418. {
  1419. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  1420. }
  1421. if (isset($this->data['headers']['etag']))
  1422. {
  1423. $headers['if-none-match'] = '"' . $this->data['headers']['etag'] . '"';
  1424. }
  1425. $file =& new $this->file_class($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);
  1426. if ($file->success)
  1427. {
  1428. if ($file->status_code == 304)
  1429. {
  1430. $cache->touch();
  1431. return true;
  1432. }
  1433. else
  1434. {
  1435. $headers = $file->headers;
  1436. }
  1437. }
  1438. else
  1439. {
  1440. unset($file);
  1441. }
  1442. }
  1443. }
  1444. // If the cache is still valid, just return true
  1445. else
  1446. {
  1447. return true;
  1448. }
  1449. }
  1450. // If the cache is empty, delete it
  1451. else
  1452. {
  1453. $cache->unlink();
  1454. $this->data = array();
  1455. }
  1456. }
  1457. // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.
  1458. if (!isset($file))
  1459. {
  1460. if (is_a($this->file, 'SimplePie_File') && $this->file->url == $this->feed_url)
  1461. {
  1462. $file =& $this->file;
  1463. }
  1464. else
  1465. {
  1466. $file =& new $this->file_class($this->feed_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);
  1467. }
  1468. }
  1469. // If the file connection has an error, set SimplePie::error to that and quit
  1470. if (!$file->success)
  1471. {
  1472. $this->error = $file->error;
  1473. if (!empty($this->data))
  1474. {
  1475. return true;
  1476. }
  1477. else
  1478. {
  1479. return false;
  1480. }
  1481. }
  1482. if (!$this->force_feed)
  1483. {
  1484. // Check if the supplied URL is a feed, if it isn't, look for it.
  1485. $locate =& new $this->locator_class($file, $this->timeout, $this->useragent, $this->file_class, $this->max_checked_feeds, $this->content_type_sniffer_class);
  1486. if (!$locate->is_feed($file))
  1487. {
  1488. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
  1489. unset($file);
  1490. if ($file = $locate->find($this->autodiscovery))
  1491. {
  1492. if ($cache)
  1493. {
  1494. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  1495. if (!$cache->save($this))
  1496. {
  1497. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  1498. }
  1499. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
  1500. }
  1501. $this->feed_url = $file->url;
  1502. }
  1503. else
  1504. {
  1505. $this->error = "A feed could not be found at $this->feed_url";
  1506. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  1507. return false;
  1508. }
  1509. }
  1510. $locate = null;
  1511. }
  1512. $headers = $file->headers;
  1513. $data = $file->body;
  1514. $sniffer = new $this->content_type_sniffer_class($file);
  1515. $sniffed = $sniffer->get_type();
  1516. }
  1517. else
  1518. {
  1519. $data = $this->raw_data;
  1520. }
  1521. // Set up array of possible encodings
  1522. $encodings = array();
  1523. // First check to see if input has been overridden.
  1524. if ($this->input_encoding !== false)
  1525. {
  1526. $encodings[] = $this->input_encoding;
  1527. }
  1528. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  1529. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  1530. // RFC 3023 (only applies to sniffed content)
  1531. if (isset($sniffed))
  1532. {
  1533. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
  1534. {
  1535. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1536. {
  1537. $encodings[] = strtoupper($charset[1]);
  1538. }
  1539. $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
  1540. $encodings[] = 'UTF-8';
  1541. }
  1542. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
  1543. {
  1544. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1545. {
  1546. $encodings[] = $charset[1];
  1547. }
  1548. $encodings[] = 'US-ASCII';
  1549. }
  1550. // Text MIME-type default
  1551. elseif (substr($sniffed, 0, 5) === 'text/')
  1552. {
  1553. $encodings[] = 'US-ASCII';
  1554. }
  1555. }
  1556. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
  1557. $encodings = array_merge($encodings, SimplePie_Misc::xml_encoding($data));
  1558. $encodings[] = 'UTF-8';
  1559. $encodings[] = 'ISO-8859-1';
  1560. // There's no point in trying an encoding twice
  1561. $encodings = array_unique($encodings);
  1562. // If we want the XML, just output that with the most likely encoding and quit
  1563. if ($this->xml_dump)
  1564. {
  1565. header('Content-type: text/xml; charset=' . $encodings[0]);
  1566. echo $data;
  1567. exit;
  1568. }
  1569. // Loop through each possible encoding, till we return something, or run out of possibilities
  1570. foreach ($encodings as $encoding)
  1571. {
  1572. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  1573. $utf8_data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8');
  1574. // Create new parser
  1575. $parser =& new $this->parser_class();
  1576. // If it's parsed fine
  1577. if ($parser->parse($utf8_data, 'UTF-8'))
  1578. {
  1579. $this->data = $parser->get_data();
  1580. if (isset($this->data['child']))
  1581. {
  1582. if (isset($headers))
  1583. {
  1584. $this->data['headers'] = $headers;
  1585. }
  1586. $this->data['build'] = SIMPLEPIE_BUILD;
  1587. // Cache the file if caching is enabled
  1588. if ($cache && !$cache->save($this))
  1589. {
  1590. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  1591. }
  1592. return true;
  1593. }
  1594. else
  1595. {
  1596. $this->error = "A feed could not be found at $this->feed_url";
  1597. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  1598. return false;
  1599. }
  1600. }
  1601. }
  1602. // We have an error, just set SimplePie::error to it and quit
  1603. $this->error = sprintf('XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
  1604. SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
  1605. return false;
  1606. }
  1607. elseif (!empty($this->multifeed_url))
  1608. {
  1609. $i = 0;
  1610. $success = 0;
  1611. $this->multifeed_objects = array();
  1612. foreach ($this->multifeed_url as $url)
  1613. {
  1614. if (SIMPLEPIE_PHP5)
  1615. {
  1616. // This keyword needs to defy coding standards for PHP4 compatibility
  1617. $this->multifeed_objects[$i] = clone($this);
  1618. }
  1619. else
  1620. {
  1621. $this->multifeed_objects[$i] = $this;
  1622. }
  1623. $this->multifeed_objects[$i]->set_feed_url($url);
  1624. $success |= $this->multifeed_objects[$i]->init();
  1625. $i++;
  1626. }
  1627. return (bool) $success;
  1628. }
  1629. else
  1630. {
  1631. return false;
  1632. }
  1633. }
  1634. /**
  1635. * Return the error message for the occured error
  1636. *
  1637. * @access public
  1638. * @return string Error message
  1639. */
  1640. function error()
  1641. {
  1642. return $this->error;
  1643. }
  1644. function get_encoding()
  1645. {
  1646. return $this->sanitize->output_encoding;
  1647. }
  1648. function handle_content_type($mime = 'text/html')
  1649. {
  1650. if (!headers_sent())
  1651. {
  1652. $header = "Content-type: $mime;";
  1653. if ($this->get_encoding())
  1654. {
  1655. $header .= ' charset=' . $this->get_encoding();
  1656. }
  1657. else
  1658. {
  1659. $header .= ' charset=UTF-8';
  1660. }
  1661. header($header);
  1662. }
  1663. }
  1664. function get_type()
  1665. {
  1666. if (!isset($this->data['type']))
  1667. {
  1668. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  1669. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
  1670. {
  1671. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  1672. }
  1673. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
  1674. {
  1675. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  1676. }
  1677. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
  1678. {
  1679. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  1680. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  1681. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  1682. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
  1683. {
  1684. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  1685. }
  1686. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  1687. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  1688. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  1689. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
  1690. {
  1691. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  1692. }
  1693. }
  1694. elseif (isset($this->data['child']['']['rss']))
  1695. {
  1696. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  1697. if (isset($this->data['child']['']['rss'][0]['attribs']['']['version']))
  1698. {
  1699. switch (trim($this->data['child']['']['rss'][0]['attribs']['']['version']))
  1700. {
  1701. case '0.91':
  1702. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  1703. if (isset($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data']))
  1704. {
  1705. switch (trim($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data']))
  1706. {
  1707. case '0':
  1708. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  1709. break;
  1710. case '24':
  1711. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  1712. break;
  1713. }
  1714. }
  1715. break;
  1716. case '0.92':
  1717. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  1718. break;
  1719. case '0.93':
  1720. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  1721. break;
  1722. case '0.94':
  1723. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  1724. break;
  1725. case '2.0':
  1726. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  1727. break;
  1728. }
  1729. }
  1730. }
  1731. else
  1732. {
  1733. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  1734. }
  1735. }
  1736. return $this->data['type'];
  1737. }
  1738. /**
  1739. * Returns the URL for the favicon of the feed's website.
  1740. *
  1741. * @todo Cache atom:icon
  1742. * @access public
  1743. * @since 1.0
  1744. */
  1745. function get_favicon()
  1746. {
  1747. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  1748. {
  1749. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  1750. }
  1751. elseif (($url = $this->get_link()) !== null && preg_match('/^http(s)?:\/\//i', $url))
  1752. {
  1753. $favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $url);
  1754. if ($this->cache && $this->favicon_handler)
  1755. {
  1756. $favicon_filename = call_user_func($this->cache_name_function, $favicon);
  1757. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $favicon_filename, 'spi');
  1758. if ($cache->load())
  1759. {
  1760. return $this->sanitize($this->favicon_handler . $favicon_filename, SIMPLEPIE_CONSTRUCT_IRI);
  1761. }
  1762. else
  1763. {
  1764. $file =& new $this->file_class($favicon, $this->timeout / 10, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
  1765. if ($file->success && ($file->status_code == 200 || ($file->status_code > 206 && $file->status_code < 300)) && strlen($file->body) > 0)
  1766. {
  1767. $sniffer = new $this->content_type_sniffer_class($file);
  1768. if (substr($sniffer->get_type(), 0, 6) === 'image/')
  1769. {
  1770. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  1771. {
  1772. return $this->sanitize($this->favicon_handler . $favicon_filename, SIMPLEPIE_CONSTRUCT_IRI);
  1773. }
  1774. else
  1775. {
  1776. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  1777. return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);
  1778. }
  1779. }
  1780. }
  1781. }
  1782. }
  1783. else
  1784. {
  1785. return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);
  1786. }
  1787. }
  1788. return false;
  1789. }
  1790. /**
  1791. * @todo If we have a perm redirect we should return the new URL
  1792. * @todo When we make the above change, let's support <itunes:new-feed-url> as well
  1793. * @todo Also, |atom:link|@rel=self
  1794. */
  1795. function subscribe_url()
  1796. {
  1797. if ($this->feed_url !== null)
  1798. {
  1799. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
  1800. }
  1801. else
  1802. {
  1803. return null;
  1804. }
  1805. }
  1806. function subscribe_feed()
  1807. {
  1808. if ($this->feed_url !== null)
  1809. {
  1810. return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);
  1811. }
  1812. else
  1813. {
  1814. return null;
  1815. }
  1816. }
  1817. function subscribe_outlook()
  1818. {
  1819. if ($this->feed_url !== null)
  1820. {
  1821. return 'outlook' . $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);
  1822. }
  1823. else
  1824. {
  1825. return null;
  1826. }
  1827. }
  1828. function subscribe_podcast()
  1829. {
  1830. if ($this->feed_url !== null)
  1831. {
  1832. return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 3), SIMPLEPIE_CONSTRUCT_IRI);
  1833. }
  1834. else
  1835. {
  1836. return null;
  1837. }
  1838. }
  1839. function subscribe_itunes()
  1840. {
  1841. if ($this->feed_url !== null)
  1842. {
  1843. return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 4), SIMPLEPIE_CONSTRUCT_IRI);
  1844. }
  1845. else
  1846. {
  1847. return null;
  1848. }
  1849. }
  1850. /**
  1851. * Creates the subscribe_* methods' return data
  1852. *
  1853. * @access private
  1854. * @param string $feed_url String to prefix to the feed URL
  1855. * @param string $site_url String to prefix to the site URL (and
  1856. * suffix to the feed URL)
  1857. * @return mixed URL if feed exists, false otherwise
  1858. */
  1859. function subscribe_service($feed_url, $site_url = null)
  1860. {
  1861. if ($this->subscribe_url())
  1862. {
  1863. $return = $this->sanitize($feed_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->feed_url);
  1864. if ($site_url !== null && $this->get_link() !== null)
  1865. {
  1866. $return .= $this->sanitize($site_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_link());
  1867. }
  1868. return $return;
  1869. }
  1870. else
  1871. {
  1872. return null;
  1873. }
  1874. }
  1875. function subscribe_aol()
  1876. {
  1877. return $this->subscribe_service('http://feeds.my.aol.com/add.jsp?url=');
  1878. }
  1879. function subscribe_bloglines()
  1880. {
  1881. return urldecode($this->subscribe_service('http://www.bloglines.com/sub/'));
  1882. }
  1883. function subscribe_eskobo()
  1884. {
  1885. return $this->subscribe_service('http://www.eskobo.com/?AddToMyPage=');
  1886. }
  1887. function subscribe_feedfeeds()
  1888. {
  1889. return $this->subscribe_service('http://www.feedfeeds.com/add?feed=');
  1890. }
  1891. function subscribe_feedster()
  1892. {
  1893. return $this->subscribe_service('http://www.feedster.com/myfeedster.php?action=addrss&confirm=no&rssurl=');
  1894. }
  1895. function subscribe_google()
  1896. {
  1897. return $this->subscribe_service('http://fusion.google.com/add?feedurl=');
  1898. }
  1899. function subscribe_gritwire()
  1900. {
  1901. return $this->subscribe_service('http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=');
  1902. }
  1903. function subscribe_msn()
  1904. {
  1905. return $this->subscribe_service('http://my.msn.com/addtomymsn.armx?id=rss&ut=', '&ru=');
  1906. }
  1907. function subscribe_netvibes()
  1908. {
  1909. return $this->subscribe_service('http://www.netvibes.com/subscribe.php?url=');
  1910. }
  1911. function subscribe_newsburst()
  1912. {
  1913. return $this->subscribe_service('http://www.newsburst.com/Source/?add=');
  1914. }
  1915. function subscribe_newsgator()
  1916. {
  1917. return $this->subscribe_service('http://www.newsgator.com/ngs/subscriber/subext.aspx?url=');
  1918. }
  1919. function subscribe_odeo()
  1920. {
  1921. return $this->subscribe_service('http://www.odeo.com/listen/subscribe?feed=');
  1922. }
  1923. function subscribe_podnova()
  1924. {
  1925. return $this->subscribe_service('http://www.podnova.com/index_your_podcasts.srf?action=add&url=');
  1926. }
  1927. function subscribe_rojo()
  1928. {
  1929. return $this->subscribe_service('http://www.rojo.com/add-subscription?resource=');
  1930. }
  1931. function subscribe_yahoo()
  1932. {
  1933. return $this->subscribe_service('http://add.my.yahoo.com/rss?url=');
  1934. }
  1935. function get_feed_tags($namespace, $tag)
  1936. {
  1937. $type = $this->get_type();
  1938. if ($type & SIMPLEPIE_TYPE_ATOM_10)
  1939. {
  1940. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
  1941. {
  1942. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  1943. }
  1944. }
  1945. if ($type & SIMPLEPIE_TYPE_ATOM_03)
  1946. {
  1947. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
  1948. {
  1949. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  1950. }
  1951. }
  1952. if ($type & SIMPLEPIE_TYPE_RSS_RDF)
  1953. {
  1954. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
  1955. {
  1956. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  1957. }
  1958. }
  1959. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1960. {
  1961. if (isset($this->data['child']['']['rss'][0]['child'][$namespace][$tag]))
  1962. {
  1963. return $this->data['child']['']['rss'][0]['child'][$namespace][$tag];
  1964. }
  1965. }
  1966. return null;
  1967. }
  1968. function get_channel_tags($namespace, $tag)
  1969. {
  1970. $type = $this->get_type();
  1971. if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
  1972. {
  1973. if ($return = $this->get_feed_tags($namespace, $tag))
  1974. {
  1975. return $return;
  1976. }
  1977. }
  1978. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1979. {
  1980. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
  1981. {
  1982. if (isset($channel[0]['child'][$namespace][$tag]))
  1983. {
  1984. return $channel[0]['child'][$namespace][$tag];
  1985. }
  1986. }
  1987. }
  1988. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1989. {
  1990. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
  1991. {
  1992. if (isset($channel[0]['child'][$namespace][$tag]))
  1993. {
  1994. return $channel[0]['child'][$namespace][$tag];
  1995. }
  1996. }
  1997. }
  1998. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1999. {
  2000. if ($channel = $this->get_feed_tags('', 'channel'))
  2001. {
  2002. if (isset($channel[0]['child'][$namespace][$tag]))
  2003. {
  2004. return $channel[0]['child'][$namespace][$tag];
  2005. }
  2006. }
  2007. }
  2008. return null;
  2009. }
  2010. function get_image_tags($namespace, $tag)
  2011. {
  2012. $type = $this->get_type();
  2013. if ($type & SIMPLEPIE_TYPE_RSS_10)
  2014. {
  2015. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
  2016. {
  2017. if (isset($image[0]['child'][$namespace][$tag]))
  2018. {
  2019. return $image[0]['child'][$namespace][$tag];
  2020. }
  2021. }
  2022. }
  2023. if ($type & SIMPLEPIE_TYPE_RSS_090)
  2024. {
  2025. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
  2026. {
  2027. if (isset($image[0]['child'][$namespace][$tag]))
  2028. {
  2029. return $image[0]['child'][$namespace][$tag];
  2030. }
  2031. }
  2032. }
  2033. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  2034. {
  2035. if ($image = $this->get_channel_tags('', 'image'))
  2036. {
  2037. if (isset($image[0]['child'][$namespace][$tag]))
  2038. {
  2039. return $image[0]['child'][$namespace][$tag];
  2040. }
  2041. }
  2042. }
  2043. return null;
  2044. }
  2045. function get_base($element = array())
  2046. {
  2047. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
  2048. {
  2049. return $element['xml_base'];
  2050. }
  2051. elseif ($this->get_link() !== null)
  2052. {
  2053. return $this->get_link();
  2054. }
  2055. else
  2056. {
  2057. return $this->subscribe_url();
  2058. }
  2059. }
  2060. function sanitize($data, $type, $base = '')
  2061. {
  2062. return $this->sanitize->sanitize($data, $type, $base);
  2063. }
  2064. function get_title()
  2065. {
  2066. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  2067. {
  2068. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2069. }
  2070. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  2071. {
  2072. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2073. }
  2074. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2075. {
  2076. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2077. }
  2078. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2079. {
  2080. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2081. }
  2082. elseif ($return = $this->get_channel_tags('', 'title'))
  2083. {
  2084. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2085. }
  2086. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2087. {
  2088. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2089. }
  2090. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2091. {
  2092. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2093. }
  2094. else
  2095. {
  2096. return null;
  2097. }
  2098. }
  2099. function get_category($key = 0)
  2100. {
  2101. $categories = $this->get_categories();
  2102. if (isset($categories[$key]))
  2103. {
  2104. return $categories[$key];
  2105. }
  2106. else
  2107. {
  2108. return null;
  2109. }
  2110. }
  2111. function get_categories()
  2112. {
  2113. $categories = array();
  2114. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  2115. {
  2116. $term = null;
  2117. $scheme = null;
  2118. $label = null;
  2119. if (isset($category['attribs']['']['term']))
  2120. {
  2121. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  2122. }
  2123. if (isset($category['attribs']['']['scheme']))
  2124. {
  2125. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2126. }
  2127. if (isset($category['attribs']['']['label']))
  2128. {
  2129. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2130. }
  2131. $categories[] =& new $this->category_class($term, $scheme, $label);
  2132. }
  2133. foreach ((array) $this->get_channel_tags('', 'category') as $category)
  2134. {
  2135. $categories[] =& new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2136. }
  2137. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  2138. {
  2139. $categories[] =& new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2140. }
  2141. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  2142. {
  2143. $categories[] =& new $this->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2144. }
  2145. if (!empty($categories))
  2146. {
  2147. return SimplePie_Misc::array_unique($categories);
  2148. }
  2149. else
  2150. {
  2151. return null;
  2152. }
  2153. }
  2154. function get_author($key = 0)
  2155. {
  2156. $authors = $this->get_authors();
  2157. if (isset($authors[$key]))
  2158. {
  2159. return $authors[$key];
  2160. }
  2161. else
  2162. {
  2163. return null;
  2164. }
  2165. }
  2166. function get_authors()
  2167. {
  2168. $authors = array();
  2169. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  2170. {
  2171. $name = null;
  2172. $uri = null;
  2173. $email = null;
  2174. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2175. {
  2176. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2177. }
  2178. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2179. {
  2180. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2181. }
  2182. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2183. {
  2184. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2185. }
  2186. if ($name !== null || $email !== null || $uri !== null)
  2187. {
  2188. $authors[] =& new $this->author_class($name, $uri, $email);
  2189. }
  2190. }
  2191. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  2192. {
  2193. $name = null;
  2194. $url = null;
  2195. $email = null;
  2196. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2197. {
  2198. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2199. }
  2200. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2201. {
  2202. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2203. }
  2204. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2205. {
  2206. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2207. }
  2208. if ($name !== null || $email !== null || $url !== null)
  2209. {
  2210. $authors[] =& new $this->author_class($name, $url, $email);
  2211. }
  2212. }
  2213. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  2214. {
  2215. $authors[] =& new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2216. }
  2217. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  2218. {
  2219. $authors[] =& new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2220. }
  2221. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  2222. {
  2223. $authors[] =& new $this->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  2224. }
  2225. if (!empty($authors))
  2226. {
  2227. return SimplePie_Misc::array_unique($authors);
  2228. }
  2229. else
  2230. {
  2231. return null;
  2232. }
  2233. }
  2234. function get_contributor($key = 0)
  2235. {
  2236. $contributors = $this->get_contributors();
  2237. if (isset($contributors[$key]))
  2238. {
  2239. return $contributors[$key];
  2240. }
  2241. else
  2242. {
  2243. return null;
  2244. }
  2245. }
  2246. function get_contributors()
  2247. {
  2248. $contributors = array();
  2249. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  2250. {
  2251. $name = null;
  2252. $uri = null;
  2253. $email = null;
  2254. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2255. {
  2256. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2257. }
  2258. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2259. {
  2260. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  2261. }
  2262. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2263. {
  2264. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2265. }
  2266. if ($name !== null || $email !== null || $uri !== null)
  2267. {
  2268. $contributors[] =& new $this->author_class($name, $uri, $email);
  2269. }
  2270. }
  2271. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  2272. {
  2273. $name = null;
  2274. $url = null;
  2275. $email = null;
  2276. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2277. {
  2278. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2279. }
  2280. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2281. {
  2282. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  2283. }
  2284. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2285. {
  2286. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2287. }
  2288. if ($name !== null || $email !== null || $url !== null)
  2289. {
  2290. $contributors[] =& new $this->author_class($name, $url, $email);
  2291. }
  2292. }
  2293. if (!empty($contributors))
  2294. {
  2295. return SimplePie_Misc::array_unique($contributors);
  2296. }
  2297. else
  2298. {
  2299. return null;
  2300. }
  2301. }
  2302. function get_link($key = 0, $rel = 'alternate')
  2303. {
  2304. $links = $this->get_links($rel);
  2305. if (isset($links[$key]))
  2306. {
  2307. return $links[$key];
  2308. }
  2309. else
  2310. {
  2311. return null;
  2312. }
  2313. }
  2314. /**
  2315. * Added for parity between the parent-level and the item/entry-level.
  2316. */
  2317. function get_permalink()
  2318. {
  2319. return $this->get_link(0);
  2320. }
  2321. function get_links($rel = 'alternate')
  2322. {
  2323. if (!isset($this->data['links']))
  2324. {
  2325. $this->data['links'] = array();
  2326. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  2327. {
  2328. foreach ($links as $link)
  2329. {
  2330. if (isset($link['attribs']['']['href']))
  2331. {
  2332. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2333. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2334. }
  2335. }
  2336. }
  2337. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  2338. {
  2339. foreach ($links as $link)
  2340. {
  2341. if (isset($link['attribs']['']['href']))
  2342. {
  2343. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2344. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2345. }
  2346. }
  2347. }
  2348. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2349. {
  2350. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2351. }
  2352. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2353. {
  2354. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2355. }
  2356. if ($links = $this->get_channel_tags('', 'link'))
  2357. {
  2358. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2359. }
  2360. $keys = array_keys($this->data['links']);
  2361. foreach ($keys as $key)
  2362. {
  2363. if (SimplePie_Misc::is_isegment_nz_nc($key))
  2364. {
  2365. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  2366. {
  2367. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  2368. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  2369. }
  2370. else
  2371. {
  2372. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  2373. }
  2374. }
  2375. elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  2376. {
  2377. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  2378. }
  2379. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  2380. }
  2381. }
  2382. if (isset($this->data['links'][$rel]))
  2383. {
  2384. return $this->data['links'][$rel];
  2385. }
  2386. else
  2387. {
  2388. return null;
  2389. }
  2390. }
  2391. function get_description()
  2392. {
  2393. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  2394. {
  2395. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2396. }
  2397. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  2398. {
  2399. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2400. }
  2401. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  2402. {
  2403. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2404. }
  2405. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  2406. {
  2407. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2408. }
  2409. elseif ($return = $this->get_channel_tags('', 'description'))
  2410. {
  2411. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2412. }
  2413. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  2414. {
  2415. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2416. }
  2417. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  2418. {
  2419. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2420. }
  2421. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  2422. {
  2423. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2424. }
  2425. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  2426. {
  2427. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2428. }
  2429. else
  2430. {
  2431. return null;
  2432. }
  2433. }
  2434. function get_copyright()
  2435. {
  2436. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  2437. {
  2438. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2439. }
  2440. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  2441. {
  2442. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2443. }
  2444. elseif ($return = $this->get_channel_tags('', 'copyright'))
  2445. {
  2446. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2447. }
  2448. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  2449. {
  2450. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2451. }
  2452. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  2453. {
  2454. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2455. }
  2456. else
  2457. {
  2458. return null;
  2459. }
  2460. }
  2461. function get_language()
  2462. {
  2463. if ($return = $this->get_channel_tags('', 'language'))
  2464. {
  2465. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2466. }
  2467. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  2468. {
  2469. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2470. }
  2471. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  2472. {
  2473. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2474. }
  2475. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
  2476. {
  2477. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2478. }
  2479. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
  2480. {
  2481. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2482. }
  2483. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
  2484. {
  2485. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2486. }
  2487. elseif (isset($this->data['headers']['content-language']))
  2488. {
  2489. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
  2490. }
  2491. else
  2492. {
  2493. return null;
  2494. }
  2495. }
  2496. function get_latitude()
  2497. {
  2498. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  2499. {
  2500. return (float) $return[0]['data'];
  2501. }
  2502. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  2503. {
  2504. return (float) $match[1];
  2505. }
  2506. else
  2507. {
  2508. return null;
  2509. }
  2510. }
  2511. function get_longitude()
  2512. {
  2513. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  2514. {
  2515. return (float) $return[0]['data'];
  2516. }
  2517. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  2518. {
  2519. return (float) $return[0]['data'];
  2520. }
  2521. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  2522. {
  2523. return (float) $match[2];
  2524. }
  2525. else
  2526. {
  2527. return null;
  2528. }
  2529. }
  2530. function get_image_title()
  2531. {
  2532. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2533. {
  2534. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2535. }
  2536. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2537. {
  2538. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2539. }
  2540. elseif ($return = $this->get_image_tags('', 'title'))
  2541. {
  2542. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2543. }
  2544. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2545. {
  2546. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2547. }
  2548. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2549. {
  2550. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2551. }
  2552. else
  2553. {
  2554. return null;
  2555. }
  2556. }
  2557. function get_image_url()
  2558. {
  2559. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  2560. {
  2561. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  2562. }
  2563. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  2564. {
  2565. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2566. }
  2567. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  2568. {
  2569. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2570. }
  2571. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
  2572. {
  2573. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2574. }
  2575. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
  2576. {
  2577. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2578. }
  2579. elseif ($return = $this->get_image_tags('', 'url'))
  2580. {
  2581. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2582. }
  2583. else
  2584. {
  2585. return null;
  2586. }
  2587. }
  2588. function get_image_link()
  2589. {
  2590. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2591. {
  2592. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2593. }
  2594. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2595. {
  2596. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2597. }
  2598. elseif ($return = $this->get_image_tags('', 'link'))
  2599. {
  2600. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2601. }
  2602. else
  2603. {
  2604. return null;
  2605. }
  2606. }
  2607. function get_image_width()
  2608. {
  2609. if ($return = $this->get_image_tags('', 'width'))
  2610. {
  2611. return round($return[0]['data']);
  2612. }
  2613. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags('', 'url'))
  2614. {
  2615. return 88.0;
  2616. }
  2617. else
  2618. {
  2619. return null;
  2620. }
  2621. }
  2622. function get_image_height()
  2623. {
  2624. if ($return = $this->get_image_tags('', 'height'))
  2625. {
  2626. return round($return[0]['data']);
  2627. }
  2628. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags('', 'url'))
  2629. {
  2630. return 31.0;
  2631. }
  2632. else
  2633. {
  2634. return null;
  2635. }
  2636. }
  2637. function get_item_quantity($max = 0)
  2638. {
  2639. $qty = count($this->get_items());
  2640. if ($max == 0)
  2641. {
  2642. return $qty;
  2643. }
  2644. else
  2645. {
  2646. return ($qty > $max) ? $max : $qty;
  2647. }
  2648. }
  2649. function get_item($key = 0)
  2650. {
  2651. $items = $this->get_items();
  2652. if (isset($items[$key]))
  2653. {
  2654. return $items[$key];
  2655. }
  2656. else
  2657. {
  2658. return null;
  2659. }
  2660. }
  2661. function get_items($start = 0, $end = 0)
  2662. {
  2663. if (!empty($this->multifeed_objects))
  2664. {
  2665. return SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
  2666. }
  2667. elseif (!isset($this->data['items']))
  2668. {
  2669. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
  2670. {
  2671. $keys = array_keys($items);
  2672. foreach ($keys as $key)
  2673. {
  2674. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  2675. }
  2676. }
  2677. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
  2678. {
  2679. $keys = array_keys($items);
  2680. foreach ($keys as $key)
  2681. {
  2682. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  2683. }
  2684. }
  2685. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
  2686. {
  2687. $keys = array_keys($items);
  2688. foreach ($keys as $key)
  2689. {
  2690. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  2691. }
  2692. }
  2693. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
  2694. {
  2695. $keys = array_keys($items);
  2696. foreach ($keys as $key)
  2697. {
  2698. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  2699. }
  2700. }
  2701. if ($items = $this->get_channel_tags('', 'item'))
  2702. {
  2703. $keys = array_keys($items);
  2704. foreach ($keys as $key)
  2705. {
  2706. $this->data['items'][] =& new $this->item_class($this, $items[$key]);
  2707. }
  2708. }
  2709. }
  2710. if (!empty($this->data['items']))
  2711. {
  2712. // If we want to order it by date, check if all items have a date, and then sort it
  2713. if ($this->order_by_date)
  2714. {
  2715. if (!isset($this->data['ordered_items']))
  2716. {
  2717. $do_sort = true;
  2718. foreach ($this->data['items'] as $item)
  2719. {
  2720. if (!$item->get_date('U'))
  2721. {
  2722. $do_sort = false;
  2723. break;
  2724. }
  2725. }
  2726. $item = null;
  2727. $this->data['ordered_items'] = $this->data['items'];
  2728. if ($do_sort)
  2729. {
  2730. usort($this->data['ordered_items'], array(&$this, 'sort_items'));
  2731. }
  2732. }
  2733. $items = $this->data['ordered_items'];
  2734. }
  2735. else
  2736. {
  2737. $items = $this->data['items'];
  2738. }
  2739. // Slice the data as desired
  2740. if ($end == 0)
  2741. {
  2742. return array_slice($items, $start);
  2743. }
  2744. else
  2745. {
  2746. return array_slice($items, $start, $end);
  2747. }
  2748. }
  2749. else
  2750. {
  2751. return array();
  2752. }
  2753. }
  2754. function sort_items($a, $b)
  2755. {
  2756. return $a->get_date('U') <= $b->get_date('U');
  2757. }
  2758. function merge_items($urls, $start = 0, $end = 0, $limit = 0)
  2759. {
  2760. if (is_array($urls) && sizeof($urls) > 0)
  2761. {
  2762. $items = array();
  2763. foreach ($urls as $arg)
  2764. {
  2765. if (is_a($arg, 'SimplePie'))
  2766. {
  2767. $items = array_merge($items, $arg->get_items(0, $limit));
  2768. }
  2769. else
  2770. {
  2771. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
  2772. }
  2773. }
  2774. $do_sort = true;
  2775. foreach ($items as $item)
  2776. {
  2777. if (!$item->get_date('U'))
  2778. {
  2779. $do_sort = false;
  2780. break;
  2781. }
  2782. }
  2783. $item = null;
  2784. if ($do_sort)
  2785. {
  2786. usort($items, array('SimplePie', 'sort_items'));
  2787. }
  2788. if ($end == 0)
  2789. {
  2790. return array_slice($items, $start);
  2791. }
  2792. else
  2793. {
  2794. return array_slice($items, $start, $end);
  2795. }
  2796. }
  2797. else
  2798. {
  2799. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
  2800. return array();
  2801. }
  2802. }
  2803. }
  2804. class SimplePie_Item
  2805. {
  2806. var $feed;
  2807. var $data = array();
  2808. function SimplePie_Item($feed, $data)
  2809. {
  2810. $this->feed = $feed;
  2811. $this->data = $data;
  2812. }
  2813. function __toString()
  2814. {
  2815. return md5(serialize($this->data));
  2816. }
  2817. /**
  2818. * Remove items that link back to this before destroying this object
  2819. */
  2820. function __destruct()
  2821. {
  2822. unset($this->feed);
  2823. }
  2824. function get_item_tags($namespace, $tag)
  2825. {
  2826. if (isset($this->data['child'][$namespace][$tag]))
  2827. {
  2828. return $this->data['child'][$namespace][$tag];
  2829. }
  2830. else
  2831. {
  2832. return null;
  2833. }
  2834. }
  2835. function get_base($element = array())
  2836. {
  2837. return $this->feed->get_base($element);
  2838. }
  2839. function sanitize($data, $type, $base = '')
  2840. {
  2841. return $this->feed->sanitize($data, $type, $base);
  2842. }
  2843. function get_feed()
  2844. {
  2845. return $this->feed;
  2846. }
  2847. function get_id($hash = false)
  2848. {
  2849. if (!$hash)
  2850. {
  2851. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  2852. {
  2853. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2854. }
  2855. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  2856. {
  2857. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2858. }
  2859. elseif ($return = $this->get_item_tags('', 'guid'))
  2860. {
  2861. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2862. }
  2863. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  2864. {
  2865. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2866. }
  2867. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  2868. {
  2869. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2870. }
  2871. elseif (($return = $this->get_permalink()) !== null)
  2872. {
  2873. return $return;
  2874. }
  2875. elseif (($return = $this->get_title()) !== null)
  2876. {
  2877. return $return;
  2878. }
  2879. }
  2880. if ($this->get_permalink() !== null || $this->get_title() !== null)
  2881. {
  2882. return md5($this->get_permalink() . $this->get_title());
  2883. }
  2884. else
  2885. {
  2886. return md5(serialize($this->data));
  2887. }
  2888. }
  2889. function get_title()
  2890. {
  2891. if (!isset($this->data['title']))
  2892. {
  2893. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  2894. {
  2895. $this->data['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2896. }
  2897. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  2898. {
  2899. $this->data['title'] = $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2900. }
  2901. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2902. {
  2903. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2904. }
  2905. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2906. {
  2907. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2908. }
  2909. elseif ($return = $this->get_item_tags('', 'title'))
  2910. {
  2911. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2912. }
  2913. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2914. {
  2915. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2916. }
  2917. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2918. {
  2919. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2920. }
  2921. else
  2922. {
  2923. $this->data['title'] = null;
  2924. }
  2925. }
  2926. return $this->data['title'];
  2927. }
  2928. function get_description($description_only = false)
  2929. {
  2930. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
  2931. {
  2932. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2933. }
  2934. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
  2935. {
  2936. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2937. }
  2938. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  2939. {
  2940. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2941. }
  2942. elseif ($return = $this->get_item_tags('', 'description'))
  2943. {
  2944. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2945. }
  2946. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  2947. {
  2948. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2949. }
  2950. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  2951. {
  2952. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2953. }
  2954. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  2955. {
  2956. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2957. }
  2958. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  2959. {
  2960. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2961. }
  2962. elseif (!$description_only)
  2963. {
  2964. return $this->get_content(true);
  2965. }
  2966. else
  2967. {
  2968. return null;
  2969. }
  2970. }
  2971. function get_content($content_only = false)
  2972. {
  2973. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
  2974. {
  2975. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_content_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2976. }
  2977. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
  2978. {
  2979. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  2980. }
  2981. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
  2982. {
  2983. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2984. }
  2985. elseif (!$content_only)
  2986. {
  2987. return $this->get_description(true);
  2988. }
  2989. else
  2990. {
  2991. return null;
  2992. }
  2993. }
  2994. function get_category($key = 0)
  2995. {
  2996. $categories = $this->get_categories();
  2997. if (isset($categories[$key]))
  2998. {
  2999. return $categories[$key];
  3000. }
  3001. else
  3002. {
  3003. return null;
  3004. }
  3005. }
  3006. function get_categories()
  3007. {
  3008. $categories = array();
  3009. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  3010. {
  3011. $term = null;
  3012. $scheme = null;
  3013. $label = null;
  3014. if (isset($category['attribs']['']['term']))
  3015. {
  3016. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  3017. }
  3018. if (isset($category['attribs']['']['scheme']))
  3019. {
  3020. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3021. }
  3022. if (isset($category['attribs']['']['label']))
  3023. {
  3024. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  3025. }
  3026. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  3027. }
  3028. foreach ((array) $this->get_item_tags('', 'category') as $category)
  3029. {
  3030. $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  3031. }
  3032. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  3033. {
  3034. $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  3035. }
  3036. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  3037. {
  3038. $categories[] =& new $this->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  3039. }
  3040. if (!empty($categories))
  3041. {
  3042. return SimplePie_Misc::array_unique($categories);
  3043. }
  3044. else
  3045. {
  3046. return null;
  3047. }
  3048. }
  3049. function get_author($key = 0)
  3050. {
  3051. $authors = $this->get_authors();
  3052. if (isset($authors[$key]))
  3053. {
  3054. return $authors[$key];
  3055. }
  3056. else
  3057. {
  3058. return null;
  3059. }
  3060. }
  3061. function get_contributor($key = 0)
  3062. {
  3063. $contributors = $this->get_contributors();
  3064. if (isset($contributors[$key]))
  3065. {
  3066. return $contributors[$key];
  3067. }
  3068. else
  3069. {
  3070. return null;
  3071. }
  3072. }
  3073. function get_contributors()
  3074. {
  3075. $contributors = array();
  3076. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  3077. {
  3078. $name = null;
  3079. $uri = null;
  3080. $email = null;
  3081. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  3082. {
  3083. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3084. }
  3085. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  3086. {
  3087. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  3088. }
  3089. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  3090. {
  3091. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3092. }
  3093. if ($name !== null || $email !== null || $uri !== null)
  3094. {
  3095. $contributors[] =& new $this->feed->author_class($name, $uri, $email);
  3096. }
  3097. }
  3098. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  3099. {
  3100. $name = null;
  3101. $url = null;
  3102. $email = null;
  3103. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  3104. {
  3105. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3106. }
  3107. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  3108. {
  3109. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  3110. }
  3111. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  3112. {
  3113. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3114. }
  3115. if ($name !== null || $email !== null || $url !== null)
  3116. {
  3117. $contributors[] =& new $this->feed->author_class($name, $url, $email);
  3118. }
  3119. }
  3120. if (!empty($contributors))
  3121. {
  3122. return SimplePie_Misc::array_unique($contributors);
  3123. }
  3124. else
  3125. {
  3126. return null;
  3127. }
  3128. }
  3129. /**
  3130. * @todo Atom inheritance (item author, source author, feed author)
  3131. */
  3132. function get_authors()
  3133. {
  3134. $authors = array();
  3135. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  3136. {
  3137. $name = null;
  3138. $uri = null;
  3139. $email = null;
  3140. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  3141. {
  3142. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3143. }
  3144. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  3145. {
  3146. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  3147. }
  3148. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  3149. {
  3150. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3151. }
  3152. if ($name !== null || $email !== null || $uri !== null)
  3153. {
  3154. $authors[] =& new $this->feed->author_class($name, $uri, $email);
  3155. }
  3156. }
  3157. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  3158. {
  3159. $name = null;
  3160. $url = null;
  3161. $email = null;
  3162. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  3163. {
  3164. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3165. }
  3166. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  3167. {
  3168. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  3169. }
  3170. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  3171. {
  3172. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3173. }
  3174. if ($name !== null || $email !== null || $url !== null)
  3175. {
  3176. $authors[] =& new $this->feed->author_class($name, $url, $email);
  3177. }
  3178. }
  3179. if ($author = $this->get_item_tags('', 'author'))
  3180. {
  3181. $authors[] =& new $this->feed->author_class(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3182. }
  3183. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  3184. {
  3185. $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  3186. }
  3187. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  3188. {
  3189. $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  3190. }
  3191. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  3192. {
  3193. $authors[] =& new $this->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  3194. }
  3195. if (!empty($authors))
  3196. {
  3197. return SimplePie_Misc::array_unique($authors);
  3198. }
  3199. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  3200. {
  3201. return $authors;
  3202. }
  3203. elseif ($authors = $this->feed->get_authors())
  3204. {
  3205. return $authors;
  3206. }
  3207. else
  3208. {
  3209. return null;
  3210. }
  3211. }
  3212. function get_copyright()
  3213. {
  3214. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  3215. {
  3216. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  3217. }
  3218. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  3219. {
  3220. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3221. }
  3222. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  3223. {
  3224. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3225. }
  3226. else
  3227. {
  3228. return null;
  3229. }
  3230. }
  3231. function get_date($date_format = 'j F Y, g:i a')
  3232. {
  3233. if (!isset($this->data['date']))
  3234. {
  3235. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  3236. {
  3237. $this->data['date']['raw'] = $return[0]['data'];
  3238. }
  3239. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  3240. {
  3241. $this->data['date']['raw'] = $return[0]['data'];
  3242. }
  3243. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  3244. {
  3245. $this->data['date']['raw'] = $return[0]['data'];
  3246. }
  3247. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  3248. {
  3249. $this->data['date']['raw'] = $return[0]['data'];
  3250. }
  3251. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  3252. {
  3253. $this->data['date']['raw'] = $return[0]['data'];
  3254. }
  3255. elseif ($return = $this->get_item_tags('', 'pubDate'))
  3256. {
  3257. $this->data['date']['raw'] = $return[0]['data'];
  3258. }
  3259. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  3260. {
  3261. $this->data['date']['raw'] = $return[0]['data'];
  3262. }
  3263. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  3264. {
  3265. $this->data['date']['raw'] = $return[0]['data'];
  3266. }
  3267. if (!empty($this->data['date']['raw']))
  3268. {
  3269. $parser = SimplePie_Parse_Date::get();
  3270. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  3271. }
  3272. else
  3273. {
  3274. $this->data['date'] = null;
  3275. }
  3276. }
  3277. if ($this->data['date'])
  3278. {
  3279. $date_format = (string) $date_format;
  3280. switch ($date_format)
  3281. {
  3282. case '':
  3283. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  3284. case 'U':
  3285. return $this->data['date']['parsed'];
  3286. default:
  3287. return date($date_format, $this->data['date']['parsed']);
  3288. }
  3289. }
  3290. else
  3291. {
  3292. return null;
  3293. }
  3294. }
  3295. function get_local_date($date_format = '%c')
  3296. {
  3297. if (!$date_format)
  3298. {
  3299. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  3300. }
  3301. elseif (($date = $this->get_date('U')) !== null)
  3302. {
  3303. return strftime($date_format, $date);
  3304. }
  3305. else
  3306. {
  3307. return null;
  3308. }
  3309. }
  3310. function get_permalink()
  3311. {
  3312. $link = $this->get_link();
  3313. $enclosure = $this->get_enclosure(0);
  3314. if ($link !== null)
  3315. {
  3316. return $link;
  3317. }
  3318. elseif ($enclosure !== null)
  3319. {
  3320. return $enclosure->get_link();
  3321. }
  3322. else
  3323. {
  3324. return null;
  3325. }
  3326. }
  3327. function get_link($key = 0, $rel = 'alternate')
  3328. {
  3329. $links = $this->get_links($rel);
  3330. if ($links[$key] !== null)
  3331. {
  3332. return $links[$key];
  3333. }
  3334. else
  3335. {
  3336. return null;
  3337. }
  3338. }
  3339. function get_links($rel = 'alternate')
  3340. {
  3341. if (!isset($this->data['links']))
  3342. {
  3343. $this->data['links'] = array();
  3344. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  3345. {
  3346. if (isset($link['attribs']['']['href']))
  3347. {
  3348. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  3349. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  3350. }
  3351. }
  3352. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  3353. {
  3354. if (isset($link['attribs']['']['href']))
  3355. {
  3356. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  3357. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  3358. }
  3359. }
  3360. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  3361. {
  3362. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  3363. }
  3364. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  3365. {
  3366. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  3367. }
  3368. if ($links = $this->get_item_tags('', 'link'))
  3369. {
  3370. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  3371. }
  3372. if ($links = $this->get_item_tags('', 'guid'))
  3373. {
  3374. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) == 'true')
  3375. {
  3376. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  3377. }
  3378. }
  3379. $keys = array_keys($this->data['links']);
  3380. foreach ($keys as $key)
  3381. {
  3382. if (SimplePie_Misc::is_isegment_nz_nc($key))
  3383. {
  3384. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  3385. {
  3386. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  3387. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  3388. }
  3389. else
  3390. {
  3391. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  3392. }
  3393. }
  3394. elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  3395. {
  3396. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  3397. }
  3398. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  3399. }
  3400. }
  3401. if (isset($this->data['links'][$rel]))
  3402. {
  3403. return $this->data['links'][$rel];
  3404. }
  3405. else
  3406. {
  3407. return null;
  3408. }
  3409. }
  3410. /**
  3411. * @todo Add ability to prefer one type of content over another (in a media group).
  3412. */
  3413. function get_enclosure($key = 0, $prefer = null)
  3414. {
  3415. $enclosures = $this->get_enclosures();
  3416. if (isset($enclosures[$key]))
  3417. {
  3418. return $enclosures[$key];
  3419. }
  3420. else
  3421. {
  3422. return null;
  3423. }
  3424. }
  3425. /**
  3426. * Grabs all available enclosures (podcasts, etc.)
  3427. *
  3428. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  3429. *
  3430. * At this point, we're pretty much assuming that all enclosures for an item are the same content. Anything else is too complicated to properly support.
  3431. *
  3432. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  3433. * @todo If an element exists at a level, but it's value is empty, we should fall back to the value from the parent (if it exists).
  3434. */
  3435. function get_enclosures()
  3436. {
  3437. if (!isset($this->data['enclosures']))
  3438. {
  3439. $this->data['enclosures'] = array();
  3440. // Elements
  3441. $captions_parent = null;
  3442. $categories_parent = null;
  3443. $copyrights_parent = null;
  3444. $credits_parent = null;
  3445. $description_parent = null;
  3446. $duration_parent = null;
  3447. $hashes_parent = null;
  3448. $keywords_parent = null;
  3449. $player_parent = null;
  3450. $ratings_parent = null;
  3451. $restrictions_parent = null;
  3452. $thumbnails_parent = null;
  3453. $title_parent = null;
  3454. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  3455. $parent = $this->get_feed();
  3456. // CAPTIONS
  3457. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  3458. {
  3459. foreach ($captions as $caption)
  3460. {
  3461. $caption_type = null;
  3462. $caption_lang = null;
  3463. $caption_startTime = null;
  3464. $caption_endTime = null;
  3465. $caption_text = null;
  3466. if (isset($caption['attribs']['']['type']))
  3467. {
  3468. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3469. }
  3470. if (isset($caption['attribs']['']['lang']))
  3471. {
  3472. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  3473. }
  3474. if (isset($caption['attribs']['']['start']))
  3475. {
  3476. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  3477. }
  3478. if (isset($caption['attribs']['']['end']))
  3479. {
  3480. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  3481. }
  3482. if (isset($caption['data']))
  3483. {
  3484. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3485. }
  3486. $captions_parent[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  3487. }
  3488. }
  3489. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  3490. {
  3491. foreach ($captions as $caption)
  3492. {
  3493. $caption_type = null;
  3494. $caption_lang = null;
  3495. $caption_startTime = null;
  3496. $caption_endTime = null;
  3497. $caption_text = null;
  3498. if (isset($caption['attribs']['']['type']))
  3499. {
  3500. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3501. }
  3502. if (isset($caption['attribs']['']['lang']))
  3503. {
  3504. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  3505. }
  3506. if (isset($caption['attribs']['']['start']))
  3507. {
  3508. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  3509. }
  3510. if (isset($caption['attribs']['']['end']))
  3511. {
  3512. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  3513. }
  3514. if (isset($caption['data']))
  3515. {
  3516. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3517. }
  3518. $captions_parent[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  3519. }
  3520. }
  3521. if (is_array($captions_parent))
  3522. {
  3523. $captions_parent = array_values(SimplePie_Misc::array_unique($captions_parent));
  3524. }
  3525. // CATEGORIES
  3526. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  3527. {
  3528. $term = null;
  3529. $scheme = null;
  3530. $label = null;
  3531. if (isset($category['data']))
  3532. {
  3533. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3534. }
  3535. if (isset($category['attribs']['']['scheme']))
  3536. {
  3537. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3538. }
  3539. else
  3540. {
  3541. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  3542. }
  3543. if (isset($category['attribs']['']['label']))
  3544. {
  3545. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  3546. }
  3547. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  3548. }
  3549. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  3550. {
  3551. $term = null;
  3552. $scheme = null;
  3553. $label = null;
  3554. if (isset($category['data']))
  3555. {
  3556. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3557. }
  3558. if (isset($category['attribs']['']['scheme']))
  3559. {
  3560. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3561. }
  3562. else
  3563. {
  3564. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  3565. }
  3566. if (isset($category['attribs']['']['label']))
  3567. {
  3568. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  3569. }
  3570. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  3571. }
  3572. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  3573. {
  3574. $term = null;
  3575. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  3576. $label = null;
  3577. if (isset($category['attribs']['']['text']))
  3578. {
  3579. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  3580. }
  3581. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  3582. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  3583. {
  3584. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  3585. {
  3586. if (isset($subcategory['attribs']['']['text']))
  3587. {
  3588. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  3589. }
  3590. $categories_parent[] =& new $this->feed->category_class($term, $scheme, $label);
  3591. }
  3592. }
  3593. }
  3594. if (is_array($categories_parent))
  3595. {
  3596. $categories_parent = array_values(SimplePie_Misc::array_unique($categories_parent));
  3597. }
  3598. // COPYRIGHT
  3599. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  3600. {
  3601. $copyright_url = null;
  3602. $copyright_label = null;
  3603. if (isset($copyright[0]['attribs']['']['url']))
  3604. {
  3605. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  3606. }
  3607. if (isset($copyright[0]['data']))
  3608. {
  3609. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3610. }
  3611. $copyrights_parent =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  3612. }
  3613. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  3614. {
  3615. $copyright_url = null;
  3616. $copyright_label = null;
  3617. if (isset($copyright[0]['attribs']['']['url']))
  3618. {
  3619. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  3620. }
  3621. if (isset($copyright[0]['data']))
  3622. {
  3623. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3624. }
  3625. $copyrights_parent =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  3626. }
  3627. // CREDITS
  3628. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  3629. {
  3630. foreach ($credits as $credit)
  3631. {
  3632. $credit_role = null;
  3633. $credit_scheme = null;
  3634. $credit_name = null;
  3635. if (isset($credit['attribs']['']['role']))
  3636. {
  3637. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  3638. }
  3639. if (isset($credit['attribs']['']['scheme']))
  3640. {
  3641. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3642. }
  3643. else
  3644. {
  3645. $credit_scheme = 'urn:ebu';
  3646. }
  3647. if (isset($credit['data']))
  3648. {
  3649. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3650. }
  3651. $credits_parent[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  3652. }
  3653. }
  3654. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  3655. {
  3656. foreach ($credits as $credit)
  3657. {
  3658. $credit_role = null;
  3659. $credit_scheme = null;
  3660. $credit_name = null;
  3661. if (isset($credit['attribs']['']['role']))
  3662. {
  3663. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  3664. }
  3665. if (isset($credit['attribs']['']['scheme']))
  3666. {
  3667. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3668. }
  3669. else
  3670. {
  3671. $credit_scheme = 'urn:ebu';
  3672. }
  3673. if (isset($credit['data']))
  3674. {
  3675. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3676. }
  3677. $credits_parent[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  3678. }
  3679. }
  3680. if (is_array($credits_parent))
  3681. {
  3682. $credits_parent = array_values(SimplePie_Misc::array_unique($credits_parent));
  3683. }
  3684. // DESCRIPTION
  3685. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  3686. {
  3687. if (isset($description_parent[0]['data']))
  3688. {
  3689. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3690. }
  3691. }
  3692. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  3693. {
  3694. if (isset($description_parent[0]['data']))
  3695. {
  3696. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3697. }
  3698. }
  3699. // DURATION
  3700. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  3701. {
  3702. $seconds = null;
  3703. $minutes = null;
  3704. $hours = null;
  3705. if (isset($duration_parent[0]['data']))
  3706. {
  3707. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3708. if (sizeof($temp) > 0)
  3709. {
  3710. (int) $seconds = array_pop($temp);
  3711. }
  3712. if (sizeof($temp) > 0)
  3713. {
  3714. (int) $minutes = array_pop($temp);
  3715. $seconds += $minutes * 60;
  3716. }
  3717. if (sizeof($temp) > 0)
  3718. {
  3719. (int) $hours = array_pop($temp);
  3720. $seconds += $hours * 3600;
  3721. }
  3722. unset($temp);
  3723. $duration_parent = $seconds;
  3724. }
  3725. }
  3726. // HASHES
  3727. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  3728. {
  3729. foreach ($hashes_iterator as $hash)
  3730. {
  3731. $value = null;
  3732. $algo = null;
  3733. if (isset($hash['data']))
  3734. {
  3735. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3736. }
  3737. if (isset($hash['attribs']['']['algo']))
  3738. {
  3739. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  3740. }
  3741. else
  3742. {
  3743. $algo = 'md5';
  3744. }
  3745. $hashes_parent[] = $algo.':'.$value;
  3746. }
  3747. }
  3748. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  3749. {
  3750. foreach ($hashes_iterator as $hash)
  3751. {
  3752. $value = null;
  3753. $algo = null;
  3754. if (isset($hash['data']))
  3755. {
  3756. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3757. }
  3758. if (isset($hash['attribs']['']['algo']))
  3759. {
  3760. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  3761. }
  3762. else
  3763. {
  3764. $algo = 'md5';
  3765. }
  3766. $hashes_parent[] = $algo.':'.$value;
  3767. }
  3768. }
  3769. if (is_array($hashes_parent))
  3770. {
  3771. $hashes_parent = array_values(SimplePie_Misc::array_unique($hashes_parent));
  3772. }
  3773. // KEYWORDS
  3774. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  3775. {
  3776. if (isset($keywords[0]['data']))
  3777. {
  3778. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3779. foreach ($temp as $word)
  3780. {
  3781. $keywords_parent[] = trim($word);
  3782. }
  3783. }
  3784. unset($temp);
  3785. }
  3786. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  3787. {
  3788. if (isset($keywords[0]['data']))
  3789. {
  3790. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3791. foreach ($temp as $word)
  3792. {
  3793. $keywords_parent[] = trim($word);
  3794. }
  3795. }
  3796. unset($temp);
  3797. }
  3798. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  3799. {
  3800. if (isset($keywords[0]['data']))
  3801. {
  3802. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3803. foreach ($temp as $word)
  3804. {
  3805. $keywords_parent[] = trim($word);
  3806. }
  3807. }
  3808. unset($temp);
  3809. }
  3810. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  3811. {
  3812. if (isset($keywords[0]['data']))
  3813. {
  3814. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  3815. foreach ($temp as $word)
  3816. {
  3817. $keywords_parent[] = trim($word);
  3818. }
  3819. }
  3820. unset($temp);
  3821. }
  3822. if (is_array($keywords_parent))
  3823. {
  3824. $keywords_parent = array_values(SimplePie_Misc::array_unique($keywords_parent));
  3825. }
  3826. // PLAYER
  3827. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  3828. {
  3829. if (isset($player_parent[0]['attribs']['']['url']))
  3830. {
  3831. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3832. }
  3833. }
  3834. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  3835. {
  3836. if (isset($player_parent[0]['attribs']['']['url']))
  3837. {
  3838. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3839. }
  3840. }
  3841. // RATINGS
  3842. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  3843. {
  3844. foreach ($ratings as $rating)
  3845. {
  3846. $rating_scheme = null;
  3847. $rating_value = null;
  3848. if (isset($rating['attribs']['']['scheme']))
  3849. {
  3850. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3851. }
  3852. else
  3853. {
  3854. $rating_scheme = 'urn:simple';
  3855. }
  3856. if (isset($rating['data']))
  3857. {
  3858. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3859. }
  3860. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3861. }
  3862. }
  3863. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  3864. {
  3865. foreach ($ratings as $rating)
  3866. {
  3867. $rating_scheme = 'urn:itunes';
  3868. $rating_value = null;
  3869. if (isset($rating['data']))
  3870. {
  3871. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3872. }
  3873. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3874. }
  3875. }
  3876. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  3877. {
  3878. foreach ($ratings as $rating)
  3879. {
  3880. $rating_scheme = null;
  3881. $rating_value = null;
  3882. if (isset($rating['attribs']['']['scheme']))
  3883. {
  3884. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  3885. }
  3886. else
  3887. {
  3888. $rating_scheme = 'urn:simple';
  3889. }
  3890. if (isset($rating['data']))
  3891. {
  3892. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3893. }
  3894. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3895. }
  3896. }
  3897. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  3898. {
  3899. foreach ($ratings as $rating)
  3900. {
  3901. $rating_scheme = 'urn:itunes';
  3902. $rating_value = null;
  3903. if (isset($rating['data']))
  3904. {
  3905. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3906. }
  3907. $ratings_parent[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  3908. }
  3909. }
  3910. if (is_array($ratings_parent))
  3911. {
  3912. $ratings_parent = array_values(SimplePie_Misc::array_unique($ratings_parent));
  3913. }
  3914. // RESTRICTIONS
  3915. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  3916. {
  3917. foreach ($restrictions as $restriction)
  3918. {
  3919. $restriction_relationship = null;
  3920. $restriction_type = null;
  3921. $restriction_value = null;
  3922. if (isset($restriction['attribs']['']['relationship']))
  3923. {
  3924. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  3925. }
  3926. if (isset($restriction['attribs']['']['type']))
  3927. {
  3928. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3929. }
  3930. if (isset($restriction['data']))
  3931. {
  3932. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3933. }
  3934. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3935. }
  3936. }
  3937. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  3938. {
  3939. foreach ($restrictions as $restriction)
  3940. {
  3941. $restriction_relationship = 'allow';
  3942. $restriction_type = null;
  3943. $restriction_value = 'itunes';
  3944. if (isset($restriction['data']) && strtolower($restriction['data']) == 'yes')
  3945. {
  3946. $restriction_relationship = 'deny';
  3947. }
  3948. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3949. }
  3950. }
  3951. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  3952. {
  3953. foreach ($restrictions as $restriction)
  3954. {
  3955. $restriction_relationship = null;
  3956. $restriction_type = null;
  3957. $restriction_value = null;
  3958. if (isset($restriction['attribs']['']['relationship']))
  3959. {
  3960. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  3961. }
  3962. if (isset($restriction['attribs']['']['type']))
  3963. {
  3964. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  3965. }
  3966. if (isset($restriction['data']))
  3967. {
  3968. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  3969. }
  3970. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3971. }
  3972. }
  3973. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  3974. {
  3975. foreach ($restrictions as $restriction)
  3976. {
  3977. $restriction_relationship = 'allow';
  3978. $restriction_type = null;
  3979. $restriction_value = 'itunes';
  3980. if (isset($restriction['data']) && strtolower($restriction['data']) == 'yes')
  3981. {
  3982. $restriction_relationship = 'deny';
  3983. }
  3984. $restrictions_parent[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  3985. }
  3986. }
  3987. if (is_array($restrictions_parent))
  3988. {
  3989. $restrictions_parent = array_values(SimplePie_Misc::array_unique($restrictions_parent));
  3990. }
  3991. // THUMBNAILS
  3992. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  3993. {
  3994. foreach ($thumbnails as $thumbnail)
  3995. {
  3996. if (isset($thumbnail['attribs']['']['url']))
  3997. {
  3998. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  3999. }
  4000. }
  4001. }
  4002. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  4003. {
  4004. foreach ($thumbnails as $thumbnail)
  4005. {
  4006. if (isset($thumbnail['attribs']['']['url']))
  4007. {
  4008. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4009. }
  4010. }
  4011. }
  4012. // TITLES
  4013. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  4014. {
  4015. if (isset($title_parent[0]['data']))
  4016. {
  4017. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4018. }
  4019. }
  4020. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  4021. {
  4022. if (isset($title_parent[0]['data']))
  4023. {
  4024. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4025. }
  4026. }
  4027. // Clear the memory
  4028. unset($parent);
  4029. // Attributes
  4030. $bitrate = null;
  4031. $channels = null;
  4032. $duration = null;
  4033. $expression = null;
  4034. $framerate = null;
  4035. $height = null;
  4036. $javascript = null;
  4037. $lang = null;
  4038. $length = null;
  4039. $medium = null;
  4040. $samplingrate = null;
  4041. $type = null;
  4042. $url = null;
  4043. $width = null;
  4044. // Elements
  4045. $captions = null;
  4046. $categories = null;
  4047. $copyrights = null;
  4048. $credits = null;
  4049. $description = null;
  4050. $hashes = null;
  4051. $keywords = null;
  4052. $player = null;
  4053. $ratings = null;
  4054. $restrictions = null;
  4055. $thumbnails = null;
  4056. $title = null;
  4057. // If we have media:group tags, loop through them.
  4058. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  4059. {
  4060. // If we have media:content tags, loop through them.
  4061. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  4062. {
  4063. if (isset($content['attribs']['']['url']))
  4064. {
  4065. // Attributes
  4066. $bitrate = null;
  4067. $channels = null;
  4068. $duration = null;
  4069. $expression = null;
  4070. $framerate = null;
  4071. $height = null;
  4072. $javascript = null;
  4073. $lang = null;
  4074. $length = null;
  4075. $medium = null;
  4076. $samplingrate = null;
  4077. $type = null;
  4078. $url = null;
  4079. $width = null;
  4080. // Elements
  4081. $captions = null;
  4082. $categories = null;
  4083. $copyrights = null;
  4084. $credits = null;
  4085. $description = null;
  4086. $hashes = null;
  4087. $keywords = null;
  4088. $player = null;
  4089. $ratings = null;
  4090. $restrictions = null;
  4091. $thumbnails = null;
  4092. $title = null;
  4093. // Start checking the attributes of media:content
  4094. if (isset($content['attribs']['']['bitrate']))
  4095. {
  4096. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  4097. }
  4098. if (isset($content['attribs']['']['channels']))
  4099. {
  4100. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  4101. }
  4102. if (isset($content['attribs']['']['duration']))
  4103. {
  4104. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  4105. }
  4106. else
  4107. {
  4108. $duration = $duration_parent;
  4109. }
  4110. if (isset($content['attribs']['']['expression']))
  4111. {
  4112. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  4113. }
  4114. if (isset($content['attribs']['']['framerate']))
  4115. {
  4116. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  4117. }
  4118. if (isset($content['attribs']['']['height']))
  4119. {
  4120. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  4121. }
  4122. if (isset($content['attribs']['']['lang']))
  4123. {
  4124. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  4125. }
  4126. if (isset($content['attribs']['']['fileSize']))
  4127. {
  4128. $length = ceil($content['attribs']['']['fileSize']);
  4129. }
  4130. if (isset($content['attribs']['']['medium']))
  4131. {
  4132. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  4133. }
  4134. if (isset($content['attribs']['']['samplingrate']))
  4135. {
  4136. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  4137. }
  4138. if (isset($content['attribs']['']['type']))
  4139. {
  4140. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4141. }
  4142. if (isset($content['attribs']['']['width']))
  4143. {
  4144. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  4145. }
  4146. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4147. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  4148. // CAPTIONS
  4149. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  4150. {
  4151. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  4152. {
  4153. $caption_type = null;
  4154. $caption_lang = null;
  4155. $caption_startTime = null;
  4156. $caption_endTime = null;
  4157. $caption_text = null;
  4158. if (isset($caption['attribs']['']['type']))
  4159. {
  4160. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4161. }
  4162. if (isset($caption['attribs']['']['lang']))
  4163. {
  4164. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  4165. }
  4166. if (isset($caption['attribs']['']['start']))
  4167. {
  4168. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  4169. }
  4170. if (isset($caption['attribs']['']['end']))
  4171. {
  4172. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  4173. }
  4174. if (isset($caption['data']))
  4175. {
  4176. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4177. }
  4178. $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  4179. }
  4180. if (is_array($captions))
  4181. {
  4182. $captions = array_values(SimplePie_Misc::array_unique($captions));
  4183. }
  4184. }
  4185. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  4186. {
  4187. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  4188. {
  4189. $caption_type = null;
  4190. $caption_lang = null;
  4191. $caption_startTime = null;
  4192. $caption_endTime = null;
  4193. $caption_text = null;
  4194. if (isset($caption['attribs']['']['type']))
  4195. {
  4196. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4197. }
  4198. if (isset($caption['attribs']['']['lang']))
  4199. {
  4200. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  4201. }
  4202. if (isset($caption['attribs']['']['start']))
  4203. {
  4204. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  4205. }
  4206. if (isset($caption['attribs']['']['end']))
  4207. {
  4208. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  4209. }
  4210. if (isset($caption['data']))
  4211. {
  4212. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4213. }
  4214. $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  4215. }
  4216. if (is_array($captions))
  4217. {
  4218. $captions = array_values(SimplePie_Misc::array_unique($captions));
  4219. }
  4220. }
  4221. else
  4222. {
  4223. $captions = $captions_parent;
  4224. }
  4225. // CATEGORIES
  4226. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  4227. {
  4228. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  4229. {
  4230. $term = null;
  4231. $scheme = null;
  4232. $label = null;
  4233. if (isset($category['data']))
  4234. {
  4235. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4236. }
  4237. if (isset($category['attribs']['']['scheme']))
  4238. {
  4239. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4240. }
  4241. else
  4242. {
  4243. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  4244. }
  4245. if (isset($category['attribs']['']['label']))
  4246. {
  4247. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  4248. }
  4249. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  4250. }
  4251. }
  4252. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  4253. {
  4254. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  4255. {
  4256. $term = null;
  4257. $scheme = null;
  4258. $label = null;
  4259. if (isset($category['data']))
  4260. {
  4261. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4262. }
  4263. if (isset($category['attribs']['']['scheme']))
  4264. {
  4265. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4266. }
  4267. else
  4268. {
  4269. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  4270. }
  4271. if (isset($category['attribs']['']['label']))
  4272. {
  4273. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  4274. }
  4275. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  4276. }
  4277. }
  4278. if (is_array($categories) && is_array($categories_parent))
  4279. {
  4280. $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent)));
  4281. }
  4282. elseif (is_array($categories))
  4283. {
  4284. $categories = array_values(SimplePie_Misc::array_unique($categories));
  4285. }
  4286. elseif (is_array($categories_parent))
  4287. {
  4288. $categories = array_values(SimplePie_Misc::array_unique($categories_parent));
  4289. }
  4290. // COPYRIGHTS
  4291. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  4292. {
  4293. $copyright_url = null;
  4294. $copyright_label = null;
  4295. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  4296. {
  4297. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  4298. }
  4299. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  4300. {
  4301. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4302. }
  4303. $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  4304. }
  4305. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  4306. {
  4307. $copyright_url = null;
  4308. $copyright_label = null;
  4309. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  4310. {
  4311. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  4312. }
  4313. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  4314. {
  4315. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4316. }
  4317. $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  4318. }
  4319. else
  4320. {
  4321. $copyrights = $copyrights_parent;
  4322. }
  4323. // CREDITS
  4324. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  4325. {
  4326. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  4327. {
  4328. $credit_role = null;
  4329. $credit_scheme = null;
  4330. $credit_name = null;
  4331. if (isset($credit['attribs']['']['role']))
  4332. {
  4333. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  4334. }
  4335. if (isset($credit['attribs']['']['scheme']))
  4336. {
  4337. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4338. }
  4339. else
  4340. {
  4341. $credit_scheme = 'urn:ebu';
  4342. }
  4343. if (isset($credit['data']))
  4344. {
  4345. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4346. }
  4347. $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  4348. }
  4349. if (is_array($credits))
  4350. {
  4351. $credits = array_values(SimplePie_Misc::array_unique($credits));
  4352. }
  4353. }
  4354. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  4355. {
  4356. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  4357. {
  4358. $credit_role = null;
  4359. $credit_scheme = null;
  4360. $credit_name = null;
  4361. if (isset($credit['attribs']['']['role']))
  4362. {
  4363. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  4364. }
  4365. if (isset($credit['attribs']['']['scheme']))
  4366. {
  4367. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4368. }
  4369. else
  4370. {
  4371. $credit_scheme = 'urn:ebu';
  4372. }
  4373. if (isset($credit['data']))
  4374. {
  4375. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4376. }
  4377. $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  4378. }
  4379. if (is_array($credits))
  4380. {
  4381. $credits = array_values(SimplePie_Misc::array_unique($credits));
  4382. }
  4383. }
  4384. else
  4385. {
  4386. $credits = $credits_parent;
  4387. }
  4388. // DESCRIPTION
  4389. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  4390. {
  4391. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4392. }
  4393. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  4394. {
  4395. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4396. }
  4397. else
  4398. {
  4399. $description = $description_parent;
  4400. }
  4401. // HASHES
  4402. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  4403. {
  4404. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  4405. {
  4406. $value = null;
  4407. $algo = null;
  4408. if (isset($hash['data']))
  4409. {
  4410. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4411. }
  4412. if (isset($hash['attribs']['']['algo']))
  4413. {
  4414. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  4415. }
  4416. else
  4417. {
  4418. $algo = 'md5';
  4419. }
  4420. $hashes[] = $algo.':'.$value;
  4421. }
  4422. if (is_array($hashes))
  4423. {
  4424. $hashes = array_values(SimplePie_Misc::array_unique($hashes));
  4425. }
  4426. }
  4427. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  4428. {
  4429. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  4430. {
  4431. $value = null;
  4432. $algo = null;
  4433. if (isset($hash['data']))
  4434. {
  4435. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4436. }
  4437. if (isset($hash['attribs']['']['algo']))
  4438. {
  4439. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  4440. }
  4441. else
  4442. {
  4443. $algo = 'md5';
  4444. }
  4445. $hashes[] = $algo.':'.$value;
  4446. }
  4447. if (is_array($hashes))
  4448. {
  4449. $hashes = array_values(SimplePie_Misc::array_unique($hashes));
  4450. }
  4451. }
  4452. else
  4453. {
  4454. $hashes = $hashes_parent;
  4455. }
  4456. // KEYWORDS
  4457. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  4458. {
  4459. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  4460. {
  4461. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  4462. foreach ($temp as $word)
  4463. {
  4464. $keywords[] = trim($word);
  4465. }
  4466. unset($temp);
  4467. }
  4468. if (is_array($keywords))
  4469. {
  4470. $keywords = array_values(SimplePie_Misc::array_unique($keywords));
  4471. }
  4472. }
  4473. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  4474. {
  4475. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  4476. {
  4477. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  4478. foreach ($temp as $word)
  4479. {
  4480. $keywords[] = trim($word);
  4481. }
  4482. unset($temp);
  4483. }
  4484. if (is_array($keywords))
  4485. {
  4486. $keywords = array_values(SimplePie_Misc::array_unique($keywords));
  4487. }
  4488. }
  4489. else
  4490. {
  4491. $keywords = $keywords_parent;
  4492. }
  4493. // PLAYER
  4494. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  4495. {
  4496. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4497. }
  4498. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  4499. {
  4500. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4501. }
  4502. else
  4503. {
  4504. $player = $player_parent;
  4505. }
  4506. // RATINGS
  4507. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  4508. {
  4509. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  4510. {
  4511. $rating_scheme = null;
  4512. $rating_value = null;
  4513. if (isset($rating['attribs']['']['scheme']))
  4514. {
  4515. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4516. }
  4517. else
  4518. {
  4519. $rating_scheme = 'urn:simple';
  4520. }
  4521. if (isset($rating['data']))
  4522. {
  4523. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4524. }
  4525. $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  4526. }
  4527. if (is_array($ratings))
  4528. {
  4529. $ratings = array_values(SimplePie_Misc::array_unique($ratings));
  4530. }
  4531. }
  4532. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  4533. {
  4534. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  4535. {
  4536. $rating_scheme = null;
  4537. $rating_value = null;
  4538. if (isset($rating['attribs']['']['scheme']))
  4539. {
  4540. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4541. }
  4542. else
  4543. {
  4544. $rating_scheme = 'urn:simple';
  4545. }
  4546. if (isset($rating['data']))
  4547. {
  4548. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4549. }
  4550. $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  4551. }
  4552. if (is_array($ratings))
  4553. {
  4554. $ratings = array_values(SimplePie_Misc::array_unique($ratings));
  4555. }
  4556. }
  4557. else
  4558. {
  4559. $ratings = $ratings_parent;
  4560. }
  4561. // RESTRICTIONS
  4562. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  4563. {
  4564. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  4565. {
  4566. $restriction_relationship = null;
  4567. $restriction_type = null;
  4568. $restriction_value = null;
  4569. if (isset($restriction['attribs']['']['relationship']))
  4570. {
  4571. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  4572. }
  4573. if (isset($restriction['attribs']['']['type']))
  4574. {
  4575. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4576. }
  4577. if (isset($restriction['data']))
  4578. {
  4579. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4580. }
  4581. $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  4582. }
  4583. if (is_array($restrictions))
  4584. {
  4585. $restrictions = array_values(SimplePie_Misc::array_unique($restrictions));
  4586. }
  4587. }
  4588. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  4589. {
  4590. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  4591. {
  4592. $restriction_relationship = null;
  4593. $restriction_type = null;
  4594. $restriction_value = null;
  4595. if (isset($restriction['attribs']['']['relationship']))
  4596. {
  4597. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  4598. }
  4599. if (isset($restriction['attribs']['']['type']))
  4600. {
  4601. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4602. }
  4603. if (isset($restriction['data']))
  4604. {
  4605. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4606. }
  4607. $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  4608. }
  4609. if (is_array($restrictions))
  4610. {
  4611. $restrictions = array_values(SimplePie_Misc::array_unique($restrictions));
  4612. }
  4613. }
  4614. else
  4615. {
  4616. $restrictions = $restrictions_parent;
  4617. }
  4618. // THUMBNAILS
  4619. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  4620. {
  4621. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  4622. {
  4623. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4624. }
  4625. if (is_array($thumbnails))
  4626. {
  4627. $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails));
  4628. }
  4629. }
  4630. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  4631. {
  4632. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  4633. {
  4634. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4635. }
  4636. if (is_array($thumbnails))
  4637. {
  4638. $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails));
  4639. }
  4640. }
  4641. else
  4642. {
  4643. $thumbnails = $thumbnails_parent;
  4644. }
  4645. // TITLES
  4646. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  4647. {
  4648. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4649. }
  4650. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  4651. {
  4652. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4653. }
  4654. else
  4655. {
  4656. $title = $title_parent;
  4657. }
  4658. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width);
  4659. }
  4660. }
  4661. }
  4662. // If we have standalone media:content tags, loop through them.
  4663. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  4664. {
  4665. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  4666. {
  4667. if (isset($content['attribs']['']['url']))
  4668. {
  4669. // Attributes
  4670. $bitrate = null;
  4671. $channels = null;
  4672. $duration = null;
  4673. $expression = null;
  4674. $framerate = null;
  4675. $height = null;
  4676. $javascript = null;
  4677. $lang = null;
  4678. $length = null;
  4679. $medium = null;
  4680. $samplingrate = null;
  4681. $type = null;
  4682. $url = null;
  4683. $width = null;
  4684. // Elements
  4685. $captions = null;
  4686. $categories = null;
  4687. $copyrights = null;
  4688. $credits = null;
  4689. $description = null;
  4690. $hashes = null;
  4691. $keywords = null;
  4692. $player = null;
  4693. $ratings = null;
  4694. $restrictions = null;
  4695. $thumbnails = null;
  4696. $title = null;
  4697. // Start checking the attributes of media:content
  4698. if (isset($content['attribs']['']['bitrate']))
  4699. {
  4700. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  4701. }
  4702. if (isset($content['attribs']['']['channels']))
  4703. {
  4704. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  4705. }
  4706. if (isset($content['attribs']['']['duration']))
  4707. {
  4708. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  4709. }
  4710. else
  4711. {
  4712. $duration = $duration_parent;
  4713. }
  4714. if (isset($content['attribs']['']['expression']))
  4715. {
  4716. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  4717. }
  4718. if (isset($content['attribs']['']['framerate']))
  4719. {
  4720. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  4721. }
  4722. if (isset($content['attribs']['']['height']))
  4723. {
  4724. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  4725. }
  4726. if (isset($content['attribs']['']['lang']))
  4727. {
  4728. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  4729. }
  4730. if (isset($content['attribs']['']['fileSize']))
  4731. {
  4732. $length = ceil($content['attribs']['']['fileSize']);
  4733. }
  4734. if (isset($content['attribs']['']['medium']))
  4735. {
  4736. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  4737. }
  4738. if (isset($content['attribs']['']['samplingrate']))
  4739. {
  4740. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  4741. }
  4742. if (isset($content['attribs']['']['type']))
  4743. {
  4744. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4745. }
  4746. if (isset($content['attribs']['']['width']))
  4747. {
  4748. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  4749. }
  4750. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4751. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  4752. // CAPTIONS
  4753. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  4754. {
  4755. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  4756. {
  4757. $caption_type = null;
  4758. $caption_lang = null;
  4759. $caption_startTime = null;
  4760. $caption_endTime = null;
  4761. $caption_text = null;
  4762. if (isset($caption['attribs']['']['type']))
  4763. {
  4764. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  4765. }
  4766. if (isset($caption['attribs']['']['lang']))
  4767. {
  4768. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  4769. }
  4770. if (isset($caption['attribs']['']['start']))
  4771. {
  4772. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  4773. }
  4774. if (isset($caption['attribs']['']['end']))
  4775. {
  4776. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  4777. }
  4778. if (isset($caption['data']))
  4779. {
  4780. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4781. }
  4782. $captions[] =& new $this->feed->caption_class($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text);
  4783. }
  4784. if (is_array($captions))
  4785. {
  4786. $captions = array_values(SimplePie_Misc::array_unique($captions));
  4787. }
  4788. }
  4789. else
  4790. {
  4791. $captions = $captions_parent;
  4792. }
  4793. // CATEGORIES
  4794. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  4795. {
  4796. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  4797. {
  4798. $term = null;
  4799. $scheme = null;
  4800. $label = null;
  4801. if (isset($category['data']))
  4802. {
  4803. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4804. }
  4805. if (isset($category['attribs']['']['scheme']))
  4806. {
  4807. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4808. }
  4809. else
  4810. {
  4811. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  4812. }
  4813. if (isset($category['attribs']['']['label']))
  4814. {
  4815. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  4816. }
  4817. $categories[] =& new $this->feed->category_class($term, $scheme, $label);
  4818. }
  4819. }
  4820. if (is_array($categories) && is_array($categories_parent))
  4821. {
  4822. $categories = array_values(SimplePie_Misc::array_unique(array_merge($categories, $categories_parent)));
  4823. }
  4824. elseif (is_array($categories))
  4825. {
  4826. $categories = array_values(SimplePie_Misc::array_unique($categories));
  4827. }
  4828. elseif (is_array($categories_parent))
  4829. {
  4830. $categories = array_values(SimplePie_Misc::array_unique($categories_parent));
  4831. }
  4832. else
  4833. {
  4834. $categories = null;
  4835. }
  4836. // COPYRIGHTS
  4837. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  4838. {
  4839. $copyright_url = null;
  4840. $copyright_label = null;
  4841. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  4842. {
  4843. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  4844. }
  4845. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  4846. {
  4847. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4848. }
  4849. $copyrights =& new $this->feed->copyright_class($copyright_url, $copyright_label);
  4850. }
  4851. else
  4852. {
  4853. $copyrights = $copyrights_parent;
  4854. }
  4855. // CREDITS
  4856. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  4857. {
  4858. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  4859. {
  4860. $credit_role = null;
  4861. $credit_scheme = null;
  4862. $credit_name = null;
  4863. if (isset($credit['attribs']['']['role']))
  4864. {
  4865. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  4866. }
  4867. if (isset($credit['attribs']['']['scheme']))
  4868. {
  4869. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4870. }
  4871. else
  4872. {
  4873. $credit_scheme = 'urn:ebu';
  4874. }
  4875. if (isset($credit['data']))
  4876. {
  4877. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4878. }
  4879. $credits[] =& new $this->feed->credit_class($credit_role, $credit_scheme, $credit_name);
  4880. }
  4881. if (is_array($credits))
  4882. {
  4883. $credits = array_values(SimplePie_Misc::array_unique($credits));
  4884. }
  4885. }
  4886. else
  4887. {
  4888. $credits = $credits_parent;
  4889. }
  4890. // DESCRIPTION
  4891. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  4892. {
  4893. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4894. }
  4895. else
  4896. {
  4897. $description = $description_parent;
  4898. }
  4899. // HASHES
  4900. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  4901. {
  4902. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  4903. {
  4904. $value = null;
  4905. $algo = null;
  4906. if (isset($hash['data']))
  4907. {
  4908. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4909. }
  4910. if (isset($hash['attribs']['']['algo']))
  4911. {
  4912. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  4913. }
  4914. else
  4915. {
  4916. $algo = 'md5';
  4917. }
  4918. $hashes[] = $algo.':'.$value;
  4919. }
  4920. if (is_array($hashes))
  4921. {
  4922. $hashes = array_values(SimplePie_Misc::array_unique($hashes));
  4923. }
  4924. }
  4925. else
  4926. {
  4927. $hashes = $hashes_parent;
  4928. }
  4929. // KEYWORDS
  4930. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  4931. {
  4932. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  4933. {
  4934. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  4935. foreach ($temp as $word)
  4936. {
  4937. $keywords[] = trim($word);
  4938. }
  4939. unset($temp);
  4940. }
  4941. if (is_array($keywords))
  4942. {
  4943. $keywords = array_values(SimplePie_Misc::array_unique($keywords));
  4944. }
  4945. }
  4946. else
  4947. {
  4948. $keywords = $keywords_parent;
  4949. }
  4950. // PLAYER
  4951. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  4952. {
  4953. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  4954. }
  4955. else
  4956. {
  4957. $player = $player_parent;
  4958. }
  4959. // RATINGS
  4960. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  4961. {
  4962. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  4963. {
  4964. $rating_scheme = null;
  4965. $rating_value = null;
  4966. if (isset($rating['attribs']['']['scheme']))
  4967. {
  4968. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4969. }
  4970. else
  4971. {
  4972. $rating_scheme = 'urn:simple';
  4973. }
  4974. if (isset($rating['data']))
  4975. {
  4976. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4977. }
  4978. $ratings[] =& new $this->feed->rating_class($rating_scheme, $rating_value);
  4979. }
  4980. if (is_array($ratings))
  4981. {
  4982. $ratings = array_values(SimplePie_Misc::array_unique($ratings));
  4983. }
  4984. }
  4985. else
  4986. {
  4987. $ratings = $ratings_parent;
  4988. }
  4989. // RESTRICTIONS
  4990. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  4991. {
  4992. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  4993. {
  4994. $restriction_relationship = null;
  4995. $restriction_type = null;
  4996. $restriction_value = null;
  4997. if (isset($restriction['attribs']['']['relationship']))
  4998. {
  4999. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  5000. }
  5001. if (isset($restriction['attribs']['']['type']))
  5002. {
  5003. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5004. }
  5005. if (isset($restriction['data']))
  5006. {
  5007. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5008. }
  5009. $restrictions[] =& new $this->feed->restriction_class($restriction_relationship, $restriction_type, $restriction_value);
  5010. }
  5011. if (is_array($restrictions))
  5012. {
  5013. $restrictions = array_values(SimplePie_Misc::array_unique($restrictions));
  5014. }
  5015. }
  5016. else
  5017. {
  5018. $restrictions = $restrictions_parent;
  5019. }
  5020. // THUMBNAILS
  5021. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  5022. {
  5023. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  5024. {
  5025. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5026. }
  5027. if (is_array($thumbnails))
  5028. {
  5029. $thumbnails = array_values(SimplePie_Misc::array_unique($thumbnails));
  5030. }
  5031. }
  5032. else
  5033. {
  5034. $thumbnails = $thumbnails_parent;
  5035. }
  5036. // TITLES
  5037. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  5038. {
  5039. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5040. }
  5041. else
  5042. {
  5043. $title = $title_parent;
  5044. }
  5045. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width);
  5046. }
  5047. }
  5048. }
  5049. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  5050. {
  5051. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] == 'enclosure')
  5052. {
  5053. // Attributes
  5054. $bitrate = null;
  5055. $channels = null;
  5056. $duration = null;
  5057. $expression = null;
  5058. $framerate = null;
  5059. $height = null;
  5060. $javascript = null;
  5061. $lang = null;
  5062. $length = null;
  5063. $medium = null;
  5064. $samplingrate = null;
  5065. $type = null;
  5066. $url = null;
  5067. $width = null;
  5068. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5069. if (isset($link['attribs']['']['type']))
  5070. {
  5071. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5072. }
  5073. if (isset($link['attribs']['']['length']))
  5074. {
  5075. $length = ceil($link['attribs']['']['length']);
  5076. }
  5077. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  5078. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  5079. }
  5080. }
  5081. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  5082. {
  5083. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] == 'enclosure')
  5084. {
  5085. // Attributes
  5086. $bitrate = null;
  5087. $channels = null;
  5088. $duration = null;
  5089. $expression = null;
  5090. $framerate = null;
  5091. $height = null;
  5092. $javascript = null;
  5093. $lang = null;
  5094. $length = null;
  5095. $medium = null;
  5096. $samplingrate = null;
  5097. $type = null;
  5098. $url = null;
  5099. $width = null;
  5100. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5101. if (isset($link['attribs']['']['type']))
  5102. {
  5103. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5104. }
  5105. if (isset($link['attribs']['']['length']))
  5106. {
  5107. $length = ceil($link['attribs']['']['length']);
  5108. }
  5109. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  5110. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  5111. }
  5112. }
  5113. if ($enclosure = $this->get_item_tags('', 'enclosure'))
  5114. {
  5115. if (isset($enclosure[0]['attribs']['']['url']))
  5116. {
  5117. // Attributes
  5118. $bitrate = null;
  5119. $channels = null;
  5120. $duration = null;
  5121. $expression = null;
  5122. $framerate = null;
  5123. $height = null;
  5124. $javascript = null;
  5125. $lang = null;
  5126. $length = null;
  5127. $medium = null;
  5128. $samplingrate = null;
  5129. $type = null;
  5130. $url = null;
  5131. $width = null;
  5132. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  5133. if (isset($enclosure[0]['attribs']['']['type']))
  5134. {
  5135. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5136. }
  5137. if (isset($enclosure[0]['attribs']['']['length']))
  5138. {
  5139. $length = ceil($enclosure[0]['attribs']['']['length']);
  5140. }
  5141. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  5142. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  5143. }
  5144. }
  5145. if (sizeof($this->data['enclosures']) == 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width))
  5146. {
  5147. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  5148. $this->data['enclosures'][] =& new $this->feed->enclosure_class($url, $type, $length, $this->feed->javascript, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width);
  5149. }
  5150. $this->data['enclosures'] = array_values(SimplePie_Misc::array_unique($this->data['enclosures']));
  5151. }
  5152. if (!empty($this->data['enclosures']))
  5153. {
  5154. return $this->data['enclosures'];
  5155. }
  5156. else
  5157. {
  5158. return null;
  5159. }
  5160. }
  5161. function get_latitude()
  5162. {
  5163. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  5164. {
  5165. return (float) $return[0]['data'];
  5166. }
  5167. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  5168. {
  5169. return (float) $match[1];
  5170. }
  5171. else
  5172. {
  5173. return null;
  5174. }
  5175. }
  5176. function get_longitude()
  5177. {
  5178. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  5179. {
  5180. return (float) $return[0]['data'];
  5181. }
  5182. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  5183. {
  5184. return (float) $return[0]['data'];
  5185. }
  5186. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  5187. {
  5188. return (float) $match[2];
  5189. }
  5190. else
  5191. {
  5192. return null;
  5193. }
  5194. }
  5195. function get_source()
  5196. {
  5197. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  5198. {
  5199. return new $this->feed->source_class($this, $return[0]);
  5200. }
  5201. else
  5202. {
  5203. return null;
  5204. }
  5205. }
  5206. /**
  5207. * Creates the add_to_* methods' return data
  5208. *
  5209. * @access private
  5210. * @param string $item_url String to prefix to the item permalink
  5211. * @param string $title_url String to prefix to the item title
  5212. * (and suffix to the item permalink)
  5213. * @return mixed URL if feed exists, false otherwise
  5214. */
  5215. function add_to_service($item_url, $title_url = null, $summary_url = null)
  5216. {
  5217. if ($this->get_permalink() !== null)
  5218. {
  5219. $return = $this->sanitize($item_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_permalink());
  5220. if ($title_url !== null && $this->get_title() !== null)
  5221. {
  5222. $return .= $this->sanitize($title_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_title());
  5223. }
  5224. if ($summary_url !== null && $this->get_description() !== null)
  5225. {
  5226. $return .= $this->sanitize($summary_url, SIMPLEPIE_CONSTRUCT_IRI) . rawurlencode($this->get_description());
  5227. }
  5228. return $return;
  5229. }
  5230. else
  5231. {
  5232. return null;
  5233. }
  5234. }
  5235. function add_to_blinklist()
  5236. {
  5237. return $this->add_to_service('http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url=', '&Title=');
  5238. }
  5239. function add_to_blogmarks()
  5240. {
  5241. return $this->add_to_service('http://blogmarks.net/my/new.php?mini=1&simple=1&url=', '&title=');
  5242. }
  5243. function add_to_delicious()
  5244. {
  5245. return $this->add_to_service('http://del.icio.us/post/?v=4&url=', '&title=');
  5246. }
  5247. function add_to_digg()
  5248. {
  5249. return $this->add_to_service('http://digg.com/submit?url=', '&title=', '&bodytext=');
  5250. }
  5251. function add_to_furl()
  5252. {
  5253. return $this->add_to_service('http://www.furl.net/storeIt.jsp?u=', '&t=');
  5254. }
  5255. function add_to_magnolia()
  5256. {
  5257. return $this->add_to_service('http://ma.gnolia.com/bookmarklet/add?url=', '&title=');
  5258. }
  5259. function add_to_myweb20()
  5260. {
  5261. return $this->add_to_service('http://myweb2.search.yahoo.com/myresults/bookmarklet?u=', '&t=');
  5262. }
  5263. function add_to_newsvine()
  5264. {
  5265. return $this->add_to_service('http://www.newsvine.com/_wine/save?u=', '&h=');
  5266. }
  5267. function add_to_reddit()
  5268. {
  5269. return $this->add_to_service('http://reddit.com/submit?url=', '&title=');
  5270. }
  5271. function add_to_segnalo()
  5272. {
  5273. return $this->add_to_service('http://segnalo.com/post.html.php?url=', '&title=');
  5274. }
  5275. function add_to_simpy()
  5276. {
  5277. return $this->add_to_service('http://www.simpy.com/simpy/LinkAdd.do?href=', '&title=');
  5278. }
  5279. function add_to_spurl()
  5280. {
  5281. return $this->add_to_service('http://www.spurl.net/spurl.php?v=3&url=', '&title=');
  5282. }
  5283. function add_to_wists()
  5284. {
  5285. return $this->add_to_service('http://wists.com/r.php?c=&r=', '&title=');
  5286. }
  5287. function search_technorati()
  5288. {
  5289. return $this->add_to_service('http://www.technorati.com/search/');
  5290. }
  5291. }
  5292. class SimplePie_Source
  5293. {
  5294. var $item;
  5295. var $data = array();
  5296. function SimplePie_Source($item, $data)
  5297. {
  5298. $this->item = $item;
  5299. $this->data = $data;
  5300. }
  5301. function __toString()
  5302. {
  5303. return md5(serialize($this->data));
  5304. }
  5305. /**
  5306. * Remove items that link back to this before destroying this object
  5307. */
  5308. function __destruct()
  5309. {
  5310. unset($this->item);
  5311. }
  5312. function get_source_tags($namespace, $tag)
  5313. {
  5314. if (isset($this->data['child'][$namespace][$tag]))
  5315. {
  5316. return $this->data['child'][$namespace][$tag];
  5317. }
  5318. else
  5319. {
  5320. return null;
  5321. }
  5322. }
  5323. function get_base($element = array())
  5324. {
  5325. return $this->item->get_base($element);
  5326. }
  5327. function sanitize($data, $type, $base = '')
  5328. {
  5329. return $this->item->sanitize($data, $type, $base);
  5330. }
  5331. function get_item()
  5332. {
  5333. return $this->item;
  5334. }
  5335. function get_title()
  5336. {
  5337. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  5338. {
  5339. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  5340. }
  5341. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  5342. {
  5343. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  5344. }
  5345. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  5346. {
  5347. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5348. }
  5349. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  5350. {
  5351. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5352. }
  5353. elseif ($return = $this->get_source_tags('', 'title'))
  5354. {
  5355. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5356. }
  5357. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  5358. {
  5359. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5360. }
  5361. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  5362. {
  5363. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5364. }
  5365. else
  5366. {
  5367. return null;
  5368. }
  5369. }
  5370. function get_category($key = 0)
  5371. {
  5372. $categories = $this->get_categories();
  5373. if (isset($categories[$key]))
  5374. {
  5375. return $categories[$key];
  5376. }
  5377. else
  5378. {
  5379. return null;
  5380. }
  5381. }
  5382. function get_categories()
  5383. {
  5384. $categories = array();
  5385. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  5386. {
  5387. $term = null;
  5388. $scheme = null;
  5389. $label = null;
  5390. if (isset($category['attribs']['']['term']))
  5391. {
  5392. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  5393. }
  5394. if (isset($category['attribs']['']['scheme']))
  5395. {
  5396. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5397. }
  5398. if (isset($category['attribs']['']['label']))
  5399. {
  5400. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5401. }
  5402. $categories[] =& new $this->item->feed->category_class($term, $scheme, $label);
  5403. }
  5404. foreach ((array) $this->get_source_tags('', 'category') as $category)
  5405. {
  5406. $categories[] =& new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  5407. }
  5408. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  5409. {
  5410. $categories[] =& new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  5411. }
  5412. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  5413. {
  5414. $categories[] =& new $this->item->feed->category_class($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  5415. }
  5416. if (!empty($categories))
  5417. {
  5418. return SimplePie_Misc::array_unique($categories);
  5419. }
  5420. else
  5421. {
  5422. return null;
  5423. }
  5424. }
  5425. function get_author($key = 0)
  5426. {
  5427. $authors = $this->get_authors();
  5428. if (isset($authors[$key]))
  5429. {
  5430. return $authors[$key];
  5431. }
  5432. else
  5433. {
  5434. return null;
  5435. }
  5436. }
  5437. function get_authors()
  5438. {
  5439. $authors = array();
  5440. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  5441. {
  5442. $name = null;
  5443. $uri = null;
  5444. $email = null;
  5445. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  5446. {
  5447. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5448. }
  5449. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  5450. {
  5451. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  5452. }
  5453. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  5454. {
  5455. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5456. }
  5457. if ($name !== null || $email !== null || $uri !== null)
  5458. {
  5459. $authors[] =& new $this->item->feed->author_class($name, $uri, $email);
  5460. }
  5461. }
  5462. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  5463. {
  5464. $name = null;
  5465. $url = null;
  5466. $email = null;
  5467. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  5468. {
  5469. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5470. }
  5471. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  5472. {
  5473. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  5474. }
  5475. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  5476. {
  5477. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5478. }
  5479. if ($name !== null || $email !== null || $url !== null)
  5480. {
  5481. $authors[] =& new $this->item->feed->author_class($name, $url, $email);
  5482. }
  5483. }
  5484. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  5485. {
  5486. $authors[] =& new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  5487. }
  5488. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  5489. {
  5490. $authors[] =& new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  5491. }
  5492. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  5493. {
  5494. $authors[] =& new $this->item->feed->author_class($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null);
  5495. }
  5496. if (!empty($authors))
  5497. {
  5498. return SimplePie_Misc::array_unique($authors);
  5499. }
  5500. else
  5501. {
  5502. return null;
  5503. }
  5504. }
  5505. function get_contributor($key = 0)
  5506. {
  5507. $contributors = $this->get_contributors();
  5508. if (isset($contributors[$key]))
  5509. {
  5510. return $contributors[$key];
  5511. }
  5512. else
  5513. {
  5514. return null;
  5515. }
  5516. }
  5517. function get_contributors()
  5518. {
  5519. $contributors = array();
  5520. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  5521. {
  5522. $name = null;
  5523. $uri = null;
  5524. $email = null;
  5525. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  5526. {
  5527. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5528. }
  5529. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  5530. {
  5531. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  5532. }
  5533. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  5534. {
  5535. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5536. }
  5537. if ($name !== null || $email !== null || $uri !== null)
  5538. {
  5539. $contributors[] =& new $this->item->feed->author_class($name, $uri, $email);
  5540. }
  5541. }
  5542. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  5543. {
  5544. $name = null;
  5545. $url = null;
  5546. $email = null;
  5547. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  5548. {
  5549. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5550. }
  5551. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  5552. {
  5553. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  5554. }
  5555. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  5556. {
  5557. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5558. }
  5559. if ($name !== null || $email !== null || $url !== null)
  5560. {
  5561. $contributors[] =& new $this->item->feed->author_class($name, $url, $email);
  5562. }
  5563. }
  5564. if (!empty($contributors))
  5565. {
  5566. return SimplePie_Misc::array_unique($contributors);
  5567. }
  5568. else
  5569. {
  5570. return null;
  5571. }
  5572. }
  5573. function get_link($key = 0, $rel = 'alternate')
  5574. {
  5575. $links = $this->get_links($rel);
  5576. if (isset($links[$key]))
  5577. {
  5578. return $links[$key];
  5579. }
  5580. else
  5581. {
  5582. return null;
  5583. }
  5584. }
  5585. /**
  5586. * Added for parity between the parent-level and the item/entry-level.
  5587. */
  5588. function get_permalink()
  5589. {
  5590. return $this->get_link(0);
  5591. }
  5592. function get_links($rel = 'alternate')
  5593. {
  5594. if (!isset($this->data['links']))
  5595. {
  5596. $this->data['links'] = array();
  5597. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  5598. {
  5599. foreach ($links as $link)
  5600. {
  5601. if (isset($link['attribs']['']['href']))
  5602. {
  5603. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  5604. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5605. }
  5606. }
  5607. }
  5608. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  5609. {
  5610. foreach ($links as $link)
  5611. {
  5612. if (isset($link['attribs']['']['href']))
  5613. {
  5614. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  5615. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5616. }
  5617. }
  5618. }
  5619. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  5620. {
  5621. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5622. }
  5623. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  5624. {
  5625. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5626. }
  5627. if ($links = $this->get_source_tags('', 'link'))
  5628. {
  5629. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5630. }
  5631. $keys = array_keys($this->data['links']);
  5632. foreach ($keys as $key)
  5633. {
  5634. if (SimplePie_Misc::is_isegment_nz_nc($key))
  5635. {
  5636. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  5637. {
  5638. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  5639. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  5640. }
  5641. else
  5642. {
  5643. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  5644. }
  5645. }
  5646. elseif (substr($key, 0, 41) == SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  5647. {
  5648. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  5649. }
  5650. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  5651. }
  5652. }
  5653. if (isset($this->data['links'][$rel]))
  5654. {
  5655. return $this->data['links'][$rel];
  5656. }
  5657. else
  5658. {
  5659. return null;
  5660. }
  5661. }
  5662. function get_description()
  5663. {
  5664. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  5665. {
  5666. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  5667. }
  5668. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  5669. {
  5670. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  5671. }
  5672. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  5673. {
  5674. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5675. }
  5676. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  5677. {
  5678. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5679. }
  5680. elseif ($return = $this->get_source_tags('', 'description'))
  5681. {
  5682. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  5683. }
  5684. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  5685. {
  5686. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5687. }
  5688. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  5689. {
  5690. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5691. }
  5692. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  5693. {
  5694. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5695. }
  5696. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  5697. {
  5698. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  5699. }
  5700. else
  5701. {
  5702. return null;
  5703. }
  5704. }
  5705. function get_copyright()
  5706. {
  5707. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  5708. {
  5709. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_10_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  5710. }
  5711. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  5712. {
  5713. return $this->sanitize($return[0]['data'], SimplePie_Misc::atom_03_construct_type($return[0]['attribs']), $this->get_base($return[0]));
  5714. }
  5715. elseif ($return = $this->get_source_tags('', 'copyright'))
  5716. {
  5717. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5718. }
  5719. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  5720. {
  5721. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5722. }
  5723. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  5724. {
  5725. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5726. }
  5727. else
  5728. {
  5729. return null;
  5730. }
  5731. }
  5732. function get_language()
  5733. {
  5734. if ($return = $this->get_source_tags('', 'language'))
  5735. {
  5736. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5737. }
  5738. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  5739. {
  5740. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5741. }
  5742. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  5743. {
  5744. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5745. }
  5746. elseif (isset($this->data['xml_lang']))
  5747. {
  5748. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5749. }
  5750. else
  5751. {
  5752. return null;
  5753. }
  5754. }
  5755. function get_latitude()
  5756. {
  5757. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  5758. {
  5759. return (float) $return[0]['data'];
  5760. }
  5761. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  5762. {
  5763. return (float) $match[1];
  5764. }
  5765. else
  5766. {
  5767. return null;
  5768. }
  5769. }
  5770. function get_longitude()
  5771. {
  5772. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  5773. {
  5774. return (float) $return[0]['data'];
  5775. }
  5776. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  5777. {
  5778. return (float) $return[0]['data'];
  5779. }
  5780. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', $return[0]['data'], $match))
  5781. {
  5782. return (float) $match[2];
  5783. }
  5784. else
  5785. {
  5786. return null;
  5787. }
  5788. }
  5789. function get_image_url()
  5790. {
  5791. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  5792. {
  5793. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  5794. }
  5795. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  5796. {
  5797. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  5798. }
  5799. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  5800. {
  5801. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  5802. }
  5803. else
  5804. {
  5805. return null;
  5806. }
  5807. }
  5808. }
  5809. class SimplePie_Author
  5810. {
  5811. var $name;
  5812. var $link;
  5813. var $email;
  5814. // Constructor, used to input the data
  5815. function SimplePie_Author($name = null, $link = null, $email = null)
  5816. {
  5817. $this->name = $name;
  5818. $this->link = $link;
  5819. $this->email = $email;
  5820. }
  5821. function __toString()
  5822. {
  5823. // There is no $this->data here
  5824. return md5(serialize($this));
  5825. }
  5826. function get_name()
  5827. {
  5828. if ($this->name !== null)
  5829. {
  5830. return $this->name;
  5831. }
  5832. else
  5833. {
  5834. return null;
  5835. }
  5836. }
  5837. function get_link()
  5838. {
  5839. if ($this->link !== null)
  5840. {
  5841. return $this->link;
  5842. }
  5843. else
  5844. {
  5845. return null;
  5846. }
  5847. }
  5848. function get_email()
  5849. {
  5850. if ($this->email !== null)
  5851. {
  5852. return $this->email;
  5853. }
  5854. else
  5855. {
  5856. return null;
  5857. }
  5858. }
  5859. }
  5860. class SimplePie_Category
  5861. {
  5862. var $term;
  5863. var $scheme;
  5864. var $label;
  5865. // Constructor, used to input the data
  5866. function SimplePie_Category($term = null, $scheme = null, $label = null)
  5867. {
  5868. $this->term = $term;
  5869. $this->scheme = $scheme;
  5870. $this->label = $label;
  5871. }
  5872. function __toString()
  5873. {
  5874. // There is no $this->data here
  5875. return md5(serialize($this));
  5876. }
  5877. function get_term()
  5878. {
  5879. if ($this->term !== null)
  5880. {
  5881. return $this->term;
  5882. }
  5883. else
  5884. {
  5885. return null;
  5886. }
  5887. }
  5888. function get_scheme()
  5889. {
  5890. if ($this->scheme !== null)
  5891. {
  5892. return $this->scheme;
  5893. }
  5894. else
  5895. {
  5896. return null;
  5897. }
  5898. }
  5899. function get_label()
  5900. {
  5901. if ($this->label !== null)
  5902. {
  5903. return $this->label;
  5904. }
  5905. else
  5906. {
  5907. return $this->get_term();
  5908. }
  5909. }
  5910. }
  5911. class SimplePie_Enclosure
  5912. {
  5913. var $bitrate;
  5914. var $captions;
  5915. var $categories;
  5916. var $channels;
  5917. var $copyright;
  5918. var $credits;
  5919. var $description;
  5920. var $duration;
  5921. var $expression;
  5922. var $framerate;
  5923. var $handler;
  5924. var $hashes;
  5925. var $height;
  5926. var $javascript;
  5927. var $keywords;
  5928. var $lang;
  5929. var $length;
  5930. var $link;
  5931. var $medium;
  5932. var $player;
  5933. var $ratings;
  5934. var $restrictions;
  5935. var $samplingrate;
  5936. var $thumbnails;
  5937. var $title;
  5938. var $type;
  5939. var $width;
  5940. // Constructor, used to input the data
  5941. function SimplePie_Enclosure($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null)
  5942. {
  5943. $this->bitrate = $bitrate;
  5944. $this->captions = $captions;
  5945. $this->categories = $categories;
  5946. $this->channels = $channels;
  5947. $this->copyright = $copyright;
  5948. $this->credits = $credits;
  5949. $this->description = $description;
  5950. $this->duration = $duration;
  5951. $this->expression = $expression;
  5952. $this->framerate = $framerate;
  5953. $this->hashes = $hashes;
  5954. $this->height = $height;
  5955. $this->javascript = $javascript;
  5956. $this->keywords = $keywords;
  5957. $this->lang = $lang;
  5958. $this->length = $length;
  5959. $this->link = $link;
  5960. $this->medium = $medium;
  5961. $this->player = $player;
  5962. $this->ratings = $ratings;
  5963. $this->restrictions = $restrictions;
  5964. $this->samplingrate = $samplingrate;
  5965. $this->thumbnails = $thumbnails;
  5966. $this->title = $title;
  5967. $this->type = $type;
  5968. $this->width = $width;
  5969. if (class_exists('idna_convert'))
  5970. {
  5971. $idn =& new idna_convert;
  5972. $parsed = SimplePie_Misc::parse_url($link);
  5973. $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  5974. }
  5975. $this->handler = $this->get_handler(); // Needs to load last
  5976. }
  5977. function __toString()
  5978. {
  5979. // There is no $this->data here
  5980. return md5(serialize($this));
  5981. }
  5982. function get_bitrate()
  5983. {
  5984. if ($this->bitrate !== null)
  5985. {
  5986. return $this->bitrate;
  5987. }
  5988. else
  5989. {
  5990. return null;
  5991. }
  5992. }
  5993. function get_caption($key = 0)
  5994. {
  5995. $captions = $this->get_captions();
  5996. if (isset($captions[$key]))
  5997. {
  5998. return $captions[$key];
  5999. }
  6000. else
  6001. {
  6002. return null;
  6003. }
  6004. }
  6005. function get_captions()
  6006. {
  6007. if ($this->captions !== null)
  6008. {
  6009. return $this->captions;
  6010. }
  6011. else
  6012. {
  6013. return null;
  6014. }
  6015. }
  6016. function get_category($key = 0)
  6017. {
  6018. $categories = $this->get_categories();
  6019. if (isset($categories[$key]))
  6020. {
  6021. return $categories[$key];
  6022. }
  6023. else
  6024. {
  6025. return null;
  6026. }
  6027. }
  6028. function get_categories()
  6029. {
  6030. if ($this->categories !== null)
  6031. {
  6032. return $this->categories;
  6033. }
  6034. else
  6035. {
  6036. return null;
  6037. }
  6038. }
  6039. function get_channels()
  6040. {
  6041. if ($this->channels !== null)
  6042. {
  6043. return $this->channels;
  6044. }
  6045. else
  6046. {
  6047. return null;
  6048. }
  6049. }
  6050. function get_copyright()
  6051. {
  6052. if ($this->copyright !== null)
  6053. {
  6054. return $this->copyright;
  6055. }
  6056. else
  6057. {
  6058. return null;
  6059. }
  6060. }
  6061. function get_credit($key = 0)
  6062. {
  6063. $credits = $this->get_credits();
  6064. if (isset($credits[$key]))
  6065. {
  6066. return $credits[$key];
  6067. }
  6068. else
  6069. {
  6070. return null;
  6071. }
  6072. }
  6073. function get_credits()
  6074. {
  6075. if ($this->credits !== null)
  6076. {
  6077. return $this->credits;
  6078. }
  6079. else
  6080. {
  6081. return null;
  6082. }
  6083. }
  6084. function get_description()
  6085. {
  6086. if ($this->description !== null)
  6087. {
  6088. return $this->description;
  6089. }
  6090. else
  6091. {
  6092. return null;
  6093. }
  6094. }
  6095. function get_duration($convert = false)
  6096. {
  6097. if ($this->duration !== null)
  6098. {
  6099. if ($convert)
  6100. {
  6101. $time = SimplePie_Misc::time_hms($this->duration);
  6102. return $time;
  6103. }
  6104. else
  6105. {
  6106. return $this->duration;
  6107. }
  6108. }
  6109. else
  6110. {
  6111. return null;
  6112. }
  6113. }
  6114. function get_expression()
  6115. {
  6116. if ($this->expression !== null)
  6117. {
  6118. return $this->expression;
  6119. }
  6120. else
  6121. {
  6122. return 'full';
  6123. }
  6124. }
  6125. function get_extension()
  6126. {
  6127. if ($this->link !== null)
  6128. {
  6129. $url = SimplePie_Misc::parse_url($this->link);
  6130. if ($url['path'] !== '')
  6131. {
  6132. return pathinfo($url['path'], PATHINFO_EXTENSION);
  6133. }
  6134. }
  6135. return null;
  6136. }
  6137. function get_framerate()
  6138. {
  6139. if ($this->framerate !== null)
  6140. {
  6141. return $this->framerate;
  6142. }
  6143. else
  6144. {
  6145. return null;
  6146. }
  6147. }
  6148. function get_handler()
  6149. {
  6150. return $this->get_real_type(true);
  6151. }
  6152. function get_hash($key = 0)
  6153. {
  6154. $hashes = $this->get_hashes();
  6155. if (isset($hashes[$key]))
  6156. {
  6157. return $hashes[$key];
  6158. }
  6159. else
  6160. {
  6161. return null;
  6162. }
  6163. }
  6164. function get_hashes()
  6165. {
  6166. if ($this->hashes !== null)
  6167. {
  6168. return $this->hashes;
  6169. }
  6170. else
  6171. {
  6172. return null;
  6173. }
  6174. }
  6175. function get_height()
  6176. {
  6177. if ($this->height !== null)
  6178. {
  6179. return $this->height;
  6180. }
  6181. else
  6182. {
  6183. return null;
  6184. }
  6185. }
  6186. function get_language()
  6187. {
  6188. if ($this->lang !== null)
  6189. {
  6190. return $this->lang;
  6191. }
  6192. else
  6193. {
  6194. return null;
  6195. }
  6196. }
  6197. function get_keyword($key = 0)
  6198. {
  6199. $keywords = $this->get_keywords();
  6200. if (isset($keywords[$key]))
  6201. {
  6202. return $keywords[$key];
  6203. }
  6204. else
  6205. {
  6206. return null;
  6207. }
  6208. }
  6209. function get_keywords()
  6210. {
  6211. if ($this->keywords !== null)
  6212. {
  6213. return $this->keywords;
  6214. }
  6215. else
  6216. {
  6217. return null;
  6218. }
  6219. }
  6220. function get_length()
  6221. {
  6222. if ($this->length !== null)
  6223. {
  6224. return $this->length;
  6225. }
  6226. else
  6227. {
  6228. return null;
  6229. }
  6230. }
  6231. function get_link()
  6232. {
  6233. if ($this->link !== null)
  6234. {
  6235. return urldecode($this->link);
  6236. }
  6237. else
  6238. {
  6239. return null;
  6240. }
  6241. }
  6242. function get_medium()
  6243. {
  6244. if ($this->medium !== null)
  6245. {
  6246. return $this->medium;
  6247. }
  6248. else
  6249. {
  6250. return null;
  6251. }
  6252. }
  6253. function get_player()
  6254. {
  6255. if ($this->player !== null)
  6256. {
  6257. return $this->player;
  6258. }
  6259. else
  6260. {
  6261. return null;
  6262. }
  6263. }
  6264. function get_rating($key = 0)
  6265. {
  6266. $ratings = $this->get_ratings();
  6267. if (isset($ratings[$key]))
  6268. {
  6269. return $ratings[$key];
  6270. }
  6271. else
  6272. {
  6273. return null;
  6274. }
  6275. }
  6276. function get_ratings()
  6277. {
  6278. if ($this->ratings !== null)
  6279. {
  6280. return $this->ratings;
  6281. }
  6282. else
  6283. {
  6284. return null;
  6285. }
  6286. }
  6287. function get_restriction($key = 0)
  6288. {
  6289. $restrictions = $this->get_restrictions();
  6290. if (isset($restrictions[$key]))
  6291. {
  6292. return $restrictions[$key];
  6293. }
  6294. else
  6295. {
  6296. return null;
  6297. }
  6298. }
  6299. function get_restrictions()
  6300. {
  6301. if ($this->restrictions !== null)
  6302. {
  6303. return $this->restrictions;
  6304. }
  6305. else
  6306. {
  6307. return null;
  6308. }
  6309. }
  6310. function get_sampling_rate()
  6311. {
  6312. if ($this->samplingrate !== null)
  6313. {
  6314. return $this->samplingrate;
  6315. }
  6316. else
  6317. {
  6318. return null;
  6319. }
  6320. }
  6321. function get_size()
  6322. {
  6323. $length = $this->get_length();
  6324. if ($length !== null)
  6325. {
  6326. return round($length/1048576, 2);
  6327. }
  6328. else
  6329. {
  6330. return null;
  6331. }
  6332. }
  6333. function get_thumbnail($key = 0)
  6334. {
  6335. $thumbnails = $this->get_thumbnails();
  6336. if (isset($thumbnails[$key]))
  6337. {
  6338. return $thumbnails[$key];
  6339. }
  6340. else
  6341. {
  6342. return null;
  6343. }
  6344. }
  6345. function get_thumbnails()
  6346. {
  6347. if ($this->thumbnails !== null)
  6348. {
  6349. return $this->thumbnails;
  6350. }
  6351. else
  6352. {
  6353. return null;
  6354. }
  6355. }
  6356. function get_title()
  6357. {
  6358. if ($this->title !== null)
  6359. {
  6360. return $this->title;
  6361. }
  6362. else
  6363. {
  6364. return null;
  6365. }
  6366. }
  6367. function get_type()
  6368. {
  6369. if ($this->type !== null)
  6370. {
  6371. return $this->type;
  6372. }
  6373. else
  6374. {
  6375. return null;
  6376. }
  6377. }
  6378. function get_width()
  6379. {
  6380. if ($this->width !== null)
  6381. {
  6382. return $this->width;
  6383. }
  6384. else
  6385. {
  6386. return null;
  6387. }
  6388. }
  6389. function native_embed($options='')
  6390. {
  6391. return $this->embed($options, true);
  6392. }
  6393. /**
  6394. * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
  6395. */
  6396. function embed($options = '', $native = false)
  6397. {
  6398. // Set up defaults
  6399. $audio = '';
  6400. $video = '';
  6401. $alt = '';
  6402. $altclass = '';
  6403. $loop = 'false';
  6404. $width = 'auto';
  6405. $height = 'auto';
  6406. $bgcolor = '#ffffff';
  6407. $mediaplayer = '';
  6408. $widescreen = false;
  6409. $handler = $this->get_handler();
  6410. $type = $this->get_real_type();
  6411. // Process options and reassign values as necessary
  6412. if (is_array($options))
  6413. {
  6414. extract($options);
  6415. }
  6416. else
  6417. {
  6418. $options = explode(',', $options);
  6419. foreach($options as $option)
  6420. {
  6421. $opt = explode(':', $option, 2);
  6422. if (isset($opt[0], $opt[1]))
  6423. {
  6424. $opt[0] = trim($opt[0]);
  6425. $opt[1] = trim($opt[1]);
  6426. switch ($opt[0])
  6427. {
  6428. case 'audio':
  6429. $audio = $opt[1];
  6430. break;
  6431. case 'video':
  6432. $video = $opt[1];
  6433. break;
  6434. case 'alt':
  6435. $alt = $opt[1];
  6436. break;
  6437. case 'altclass':
  6438. $altclass = $opt[1];
  6439. break;
  6440. case 'loop':
  6441. $loop = $opt[1];
  6442. break;
  6443. case 'width':
  6444. $width = $opt[1];
  6445. break;
  6446. case 'height':
  6447. $height = $opt[1];
  6448. break;
  6449. case 'bgcolor':
  6450. $bgcolor = $opt[1];
  6451. break;
  6452. case 'mediaplayer':
  6453. $mediaplayer = $opt[1];
  6454. break;
  6455. case 'widescreen':
  6456. $widescreen = $opt[1];
  6457. break;
  6458. }
  6459. }
  6460. }
  6461. }
  6462. $mime = explode('/', $type, 2);
  6463. $mime = $mime[0];
  6464. // Process values for 'auto'
  6465. if ($width == 'auto')
  6466. {
  6467. if ($mime == 'video')
  6468. {
  6469. if ($height == 'auto')
  6470. {
  6471. $width = 480;
  6472. }
  6473. elseif ($widescreen)
  6474. {
  6475. $width = round((intval($height)/9)*16);
  6476. }
  6477. else
  6478. {
  6479. $width = round((intval($height)/3)*4);
  6480. }
  6481. }
  6482. else
  6483. {
  6484. $width = '100%';
  6485. }
  6486. }
  6487. if ($height == 'auto')
  6488. {
  6489. if ($mime == 'audio')
  6490. {
  6491. $height = 0;
  6492. }
  6493. elseif ($mime == 'video')
  6494. {
  6495. if ($width == 'auto')
  6496. {
  6497. if ($widescreen)
  6498. {
  6499. $height = 270;
  6500. }
  6501. else
  6502. {
  6503. $height = 360;
  6504. }
  6505. }
  6506. elseif ($widescreen)
  6507. {
  6508. $height = round((intval($width)/16)*9);
  6509. }
  6510. else
  6511. {
  6512. $height = round((intval($width)/4)*3);
  6513. }
  6514. }
  6515. else
  6516. {
  6517. $height = 376;
  6518. }
  6519. }
  6520. elseif ($mime == 'audio')
  6521. {
  6522. $height = 0;
  6523. }
  6524. // Set proper placeholder value
  6525. if ($mime == 'audio')
  6526. {
  6527. $placeholder = $audio;
  6528. }
  6529. elseif ($mime == 'video')
  6530. {
  6531. $placeholder = $video;
  6532. }
  6533. $embed = '';
  6534. // Make sure the JS library is included
  6535. if (!$native)
  6536. {
  6537. static $javascript_outputted = null;
  6538. if (!$javascript_outputted && $this->javascript)
  6539. {
  6540. $embed .= '<script type="text/javascript" src="?' . htmlspecialchars($this->javascript) . '"></script>';
  6541. $javascript_outputted = true;
  6542. }
  6543. }
  6544. // Odeo Feed MP3's
  6545. if ($handler == 'odeo')
  6546. {
  6547. if ($native)
  6548. {
  6549. $embed .= '<embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://adobe.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=' . $this->get_link() . '"></embed>';
  6550. }
  6551. else
  6552. {
  6553. $embed .= '<script type="text/javascript">embed_odeo("' . $this->get_link() . '");</script>';
  6554. }
  6555. }
  6556. // Flash
  6557. elseif ($handler == 'flash')
  6558. {
  6559. if ($native)
  6560. {
  6561. $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>";
  6562. }
  6563. else
  6564. {
  6565. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  6566. }
  6567. }
  6568. // Flash Media Player file types.
  6569. // Preferred handler for MP3 file types.
  6570. elseif ($handler == 'fmedia' || ($handler == 'mp3' && $mediaplayer != ''))
  6571. {
  6572. $height += 20;
  6573. if ($native)
  6574. {
  6575. $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>";
  6576. }
  6577. else
  6578. {
  6579. $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
  6580. }
  6581. }
  6582. // QuickTime 7 file types. Need to test with QuickTime 6.
  6583. // Only handle MP3's if the Flash Media Player is not present.
  6584. elseif ($handler == 'quicktime' || ($handler == 'mp3' && $mediaplayer == ''))
  6585. {
  6586. $height += 16;
  6587. if ($native)
  6588. {
  6589. if ($placeholder != ""){
  6590. $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
  6591. }
  6592. else {
  6593. $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>";
  6594. }
  6595. }
  6596. else
  6597. {
  6598. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  6599. }
  6600. }
  6601. // Windows Media
  6602. elseif ($handler == 'wmedia')
  6603. {
  6604. $height += 45;
  6605. if ($native)
  6606. {
  6607. $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>";
  6608. }
  6609. else
  6610. {
  6611. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  6612. }
  6613. }
  6614. // Everything else
  6615. else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  6616. return $embed;
  6617. }
  6618. function get_real_type($find_handler = false)
  6619. {
  6620. // If it's Odeo, let's get it out of the way.
  6621. if (substr(strtolower($this->get_link()), 0, 15) == 'http://odeo.com')
  6622. {
  6623. return 'odeo';
  6624. }
  6625. // Mime-types by handler.
  6626. $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
  6627. $types_fmedia = array('video/flv', 'video/x-flv'); // Flash Media Player
  6628. $types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime
  6629. $types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media
  6630. $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
  6631. if ($this->get_type() !== null)
  6632. {
  6633. $type = strtolower($this->type);
  6634. }
  6635. else
  6636. {
  6637. $type = null;
  6638. }
  6639. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  6640. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
  6641. {
  6642. switch (strtolower($this->get_extension()))
  6643. {
  6644. // Audio mime-types
  6645. case 'aac':
  6646. case 'adts':
  6647. $type = 'audio/acc';
  6648. break;
  6649. case 'aif':
  6650. case 'aifc':
  6651. case 'aiff':
  6652. case 'cdda':
  6653. $type = 'audio/aiff';
  6654. break;
  6655. case 'bwf':
  6656. $type = 'audio/wav';
  6657. break;
  6658. case 'kar':
  6659. case 'mid':
  6660. case 'midi':
  6661. case 'smf':
  6662. $type = 'audio/midi';
  6663. break;
  6664. case 'm4a':
  6665. $type = 'audio/x-m4a';
  6666. break;
  6667. case 'mp3':
  6668. case 'swa':
  6669. $type = 'audio/mp3';
  6670. break;
  6671. case 'wav':
  6672. $type = 'audio/wav';
  6673. break;
  6674. case 'wax':
  6675. $type = 'audio/x-ms-wax';
  6676. break;
  6677. case 'wma':
  6678. $type = 'audio/x-ms-wma';
  6679. break;
  6680. // Video mime-types
  6681. case '3gp':
  6682. case '3gpp':
  6683. $type = 'video/3gpp';
  6684. break;
  6685. case '3g2':
  6686. case '3gp2':
  6687. $type = 'video/3gpp2';
  6688. break;
  6689. case 'asf':
  6690. $type = 'video/x-ms-asf';
  6691. break;
  6692. case 'flv':
  6693. $type = 'video/x-flv';
  6694. break;
  6695. case 'm1a':
  6696. case 'm1s':
  6697. case 'm1v':
  6698. case 'm15':
  6699. case 'm75':
  6700. case 'mp2':
  6701. case 'mpa':
  6702. case 'mpeg':
  6703. case 'mpg':
  6704. case 'mpm':
  6705. case 'mpv':
  6706. $type = 'video/mpeg';
  6707. break;
  6708. case 'm4v':
  6709. $type = 'video/x-m4v';
  6710. break;
  6711. case 'mov':
  6712. case 'qt':
  6713. $type = 'video/quicktime';
  6714. break;
  6715. case 'mp4':
  6716. case 'mpg4':
  6717. $type = 'video/mp4';
  6718. break;
  6719. case 'sdv':
  6720. $type = 'video/sd-video';
  6721. break;
  6722. case 'wm':
  6723. $type = 'video/x-ms-wm';
  6724. break;
  6725. case 'wmv':
  6726. $type = 'video/x-ms-wmv';
  6727. break;
  6728. case 'wvx':
  6729. $type = 'video/x-ms-wvx';
  6730. break;
  6731. // Flash mime-types
  6732. case 'spl':
  6733. $type = 'application/futuresplash';
  6734. break;
  6735. case 'swf':
  6736. $type = 'application/x-shockwave-flash';
  6737. break;
  6738. }
  6739. }
  6740. if ($find_handler)
  6741. {
  6742. if (in_array($type, $types_flash))
  6743. {
  6744. return 'flash';
  6745. }
  6746. elseif (in_array($type, $types_fmedia))
  6747. {
  6748. return 'fmedia';
  6749. }
  6750. elseif (in_array($type, $types_quicktime))
  6751. {
  6752. return 'quicktime';
  6753. }
  6754. elseif (in_array($type, $types_wmedia))
  6755. {
  6756. return 'wmedia';
  6757. }
  6758. elseif (in_array($type, $types_mp3))
  6759. {
  6760. return 'mp3';
  6761. }
  6762. else
  6763. {
  6764. return null;
  6765. }
  6766. }
  6767. else
  6768. {
  6769. return $type;
  6770. }
  6771. }
  6772. }
  6773. class SimplePie_Caption
  6774. {
  6775. var $type;
  6776. var $lang;
  6777. var $startTime;
  6778. var $endTime;
  6779. var $text;
  6780. // Constructor, used to input the data
  6781. function SimplePie_Caption($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
  6782. {
  6783. $this->type = $type;
  6784. $this->lang = $lang;
  6785. $this->startTime = $startTime;
  6786. $this->endTime = $endTime;
  6787. $this->text = $text;
  6788. }
  6789. function __toString()
  6790. {
  6791. // There is no $this->data here
  6792. return md5(serialize($this));
  6793. }
  6794. function get_endtime()
  6795. {
  6796. if ($this->endTime !== null)
  6797. {
  6798. return $this->endTime;
  6799. }
  6800. else
  6801. {
  6802. return null;
  6803. }
  6804. }
  6805. function get_language()
  6806. {
  6807. if ($this->lang !== null)
  6808. {
  6809. return $this->lang;
  6810. }
  6811. else
  6812. {
  6813. return null;
  6814. }
  6815. }
  6816. function get_starttime()
  6817. {
  6818. if ($this->startTime !== null)
  6819. {
  6820. return $this->startTime;
  6821. }
  6822. else
  6823. {
  6824. return null;
  6825. }
  6826. }
  6827. function get_text()
  6828. {
  6829. if ($this->text !== null)
  6830. {
  6831. return $this->text;
  6832. }
  6833. else
  6834. {
  6835. return null;
  6836. }
  6837. }
  6838. function get_type()
  6839. {
  6840. if ($this->type !== null)
  6841. {
  6842. return $this->type;
  6843. }
  6844. else
  6845. {
  6846. return null;
  6847. }
  6848. }
  6849. }
  6850. class SimplePie_Credit
  6851. {
  6852. var $role;
  6853. var $scheme;
  6854. var $name;
  6855. // Constructor, used to input the data
  6856. function SimplePie_Credit($role = null, $scheme = null, $name = null)
  6857. {
  6858. $this->role = $role;
  6859. $this->scheme = $scheme;
  6860. $this->name = $name;
  6861. }
  6862. function __toString()
  6863. {
  6864. // There is no $this->data here
  6865. return md5(serialize($this));
  6866. }
  6867. function get_role()
  6868. {
  6869. if ($this->role !== null)
  6870. {
  6871. return $this->role;
  6872. }
  6873. else
  6874. {
  6875. return null;
  6876. }
  6877. }
  6878. function get_scheme()
  6879. {
  6880. if ($this->scheme !== null)
  6881. {
  6882. return $this->scheme;
  6883. }
  6884. else
  6885. {
  6886. return null;
  6887. }
  6888. }
  6889. function get_name()
  6890. {
  6891. if ($this->name !== null)
  6892. {
  6893. return $this->name;
  6894. }
  6895. else
  6896. {
  6897. return null;
  6898. }
  6899. }
  6900. }
  6901. class SimplePie_Copyright
  6902. {
  6903. var $url;
  6904. var $label;
  6905. // Constructor, used to input the data
  6906. function SimplePie_Copyright($url = null, $label = null)
  6907. {
  6908. $this->url = $url;
  6909. $this->label = $label;
  6910. }
  6911. function __toString()
  6912. {
  6913. // There is no $this->data here
  6914. return md5(serialize($this));
  6915. }
  6916. function get_url()
  6917. {
  6918. if ($this->url !== null)
  6919. {
  6920. return $this->url;
  6921. }
  6922. else
  6923. {
  6924. return null;
  6925. }
  6926. }
  6927. function get_attribution()
  6928. {
  6929. if ($this->label !== null)
  6930. {
  6931. return $this->label;
  6932. }
  6933. else
  6934. {
  6935. return null;
  6936. }
  6937. }
  6938. }
  6939. class SimplePie_Rating
  6940. {
  6941. var $scheme;
  6942. var $value;
  6943. // Constructor, used to input the data
  6944. function SimplePie_Rating($scheme = null, $value = null)
  6945. {
  6946. $this->scheme = $scheme;
  6947. $this->value = $value;
  6948. }
  6949. function __toString()
  6950. {
  6951. // There is no $this->data here
  6952. return md5(serialize($this));
  6953. }
  6954. function get_scheme()
  6955. {
  6956. if ($this->scheme !== null)
  6957. {
  6958. return $this->scheme;
  6959. }
  6960. else
  6961. {
  6962. return null;
  6963. }
  6964. }
  6965. function get_value()
  6966. {
  6967. if ($this->value !== null)
  6968. {
  6969. return $this->value;
  6970. }
  6971. else
  6972. {
  6973. return null;
  6974. }
  6975. }
  6976. }
  6977. class SimplePie_Restriction
  6978. {
  6979. var $relationship;
  6980. var $type;
  6981. var $value;
  6982. // Constructor, used to input the data
  6983. function SimplePie_Restriction($relationship = null, $type = null, $value = null)
  6984. {
  6985. $this->relationship = $relationship;
  6986. $this->type = $type;
  6987. $this->value = $value;
  6988. }
  6989. function __toString()
  6990. {
  6991. // There is no $this->data here
  6992. return md5(serialize($this));
  6993. }
  6994. function get_relationship()
  6995. {
  6996. if ($this->relationship !== null)
  6997. {
  6998. return $this->relationship;
  6999. }
  7000. else
  7001. {
  7002. return null;
  7003. }
  7004. }
  7005. function get_type()
  7006. {
  7007. if ($this->type !== null)
  7008. {
  7009. return $this->type;
  7010. }
  7011. else
  7012. {
  7013. return null;
  7014. }
  7015. }
  7016. function get_value()
  7017. {
  7018. if ($this->value !== null)
  7019. {
  7020. return $this->value;
  7021. }
  7022. else
  7023. {
  7024. return null;
  7025. }
  7026. }
  7027. }
  7028. /**
  7029. * @todo Move to properly supporting RFC2616 (HTTP/1.1)
  7030. */
  7031. class SimplePie_File
  7032. {
  7033. var $url;
  7034. var $useragent;
  7035. var $success = true;
  7036. var $headers = array();
  7037. var $body;
  7038. var $status_code;
  7039. var $redirects = 0;
  7040. var $error;
  7041. var $method = SIMPLEPIE_FILE_SOURCE_NONE;
  7042. function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
  7043. {
  7044. if (class_exists('idna_convert'))
  7045. {
  7046. $idn =& new idna_convert;
  7047. $parsed = SimplePie_Misc::parse_url($url);
  7048. $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  7049. }
  7050. $this->url = $url;
  7051. $this->useragent = $useragent;
  7052. if (preg_match('/^http(s)?:\/\//i', $url))
  7053. {
  7054. if ($useragent === null)
  7055. {
  7056. $useragent = ini_get('user_agent');
  7057. $this->useragent = $useragent;
  7058. }
  7059. if (!is_array($headers))
  7060. {
  7061. $headers = array();
  7062. }
  7063. if (!$force_fsockopen && function_exists('curl_exec'))
  7064. {
  7065. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
  7066. $fp = curl_init();
  7067. $headers2 = array();
  7068. foreach ($headers as $key => $value)
  7069. {
  7070. $headers2[] = "$key: $value";
  7071. }
  7072. if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
  7073. {
  7074. curl_setopt($fp, CURLOPT_ENCODING, '');
  7075. }
  7076. curl_setopt($fp, CURLOPT_URL, $url);
  7077. curl_setopt($fp, CURLOPT_HEADER, 1);
  7078. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  7079. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  7080. curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
  7081. curl_setopt($fp, CURLOPT_REFERER, $url);
  7082. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  7083. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  7084. if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
  7085. {
  7086. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  7087. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  7088. }
  7089. $this->headers = curl_exec($fp);
  7090. if (curl_errno($fp) == 23 || curl_errno($fp) == 61)
  7091. {
  7092. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  7093. $this->headers = curl_exec($fp);
  7094. }
  7095. if (curl_errno($fp))
  7096. {
  7097. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  7098. $this->success = false;
  7099. }
  7100. else
  7101. {
  7102. $info = curl_getinfo($fp);
  7103. curl_close($fp);
  7104. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
  7105. $this->headers = array_pop($this->headers);
  7106. $parser =& new SimplePie_HTTP_Parser($this->headers);
  7107. if ($parser->parse())
  7108. {
  7109. $this->headers = $parser->headers;
  7110. $this->body = $parser->body;
  7111. $this->status_code = $parser->status_code;
  7112. if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  7113. {
  7114. $this->redirects++;
  7115. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  7116. return $this->SimplePie_File($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  7117. }
  7118. }
  7119. }
  7120. }
  7121. else
  7122. {
  7123. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
  7124. $url_parts = parse_url($url);
  7125. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
  7126. {
  7127. $url_parts['host'] = "ssl://$url_parts[host]";
  7128. $url_parts['port'] = 443;
  7129. }
  7130. if (!isset($url_parts['port']))
  7131. {
  7132. $url_parts['port'] = 80;
  7133. }
  7134. $fp = @fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
  7135. if (!$fp)
  7136. {
  7137. $this->error = 'fsockopen error: ' . $errstr;
  7138. $this->success = false;
  7139. }
  7140. else
  7141. {
  7142. stream_set_timeout($fp, $timeout);
  7143. if (isset($url_parts['path']))
  7144. {
  7145. if (isset($url_parts['query']))
  7146. {
  7147. $get = "$url_parts[path]?$url_parts[query]";
  7148. }
  7149. else
  7150. {
  7151. $get = $url_parts['path'];
  7152. }
  7153. }
  7154. else
  7155. {
  7156. $get = '/';
  7157. }
  7158. $out = "GET $get HTTP/1.0\r\n";
  7159. $out .= "Host: $url_parts[host]\r\n";
  7160. $out .= "User-Agent: $useragent\r\n";
  7161. if (function_exists('gzinflate'))
  7162. {
  7163. $out .= "Accept-Encoding: gzip,deflate\r\n";
  7164. }
  7165. if (isset($url_parts['user']) && isset($url_parts['pass']))
  7166. {
  7167. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  7168. }
  7169. foreach ($headers as $key => $value)
  7170. {
  7171. $out .= "$key: $value\r\n";
  7172. }
  7173. $out .= "Connection: Close\r\n\r\n";
  7174. fwrite($fp, $out);
  7175. $info = stream_get_meta_data($fp);
  7176. $this->headers = '';
  7177. while (!$info['eof'] && !$info['timed_out'])
  7178. {
  7179. $this->headers .= fread($fp, 1160);
  7180. $info = stream_get_meta_data($fp);
  7181. }
  7182. if (!$info['timed_out'])
  7183. {
  7184. $parser =& new SimplePie_HTTP_Parser($this->headers);
  7185. if ($parser->parse())
  7186. {
  7187. $this->headers = $parser->headers;
  7188. $this->body = $parser->body;
  7189. $this->status_code = $parser->status_code;
  7190. if (($this->status_code == 300 || $this->status_code == 301 || $this->status_code == 302 || $this->status_code == 303 || $this->status_code == 307 || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  7191. {
  7192. $this->redirects++;
  7193. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  7194. return $this->SimplePie_File($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  7195. }
  7196. if (isset($this->headers['content-encoding']) && ($this->headers['content-encoding'] == 'gzip' || $this->headers['content-encoding'] == 'deflate'))
  7197. {
  7198. if (substr($this->body, 0, 8) == "\x1f\x8b\x08\x00\x00\x00\x00\x00")
  7199. {
  7200. $this->body = substr($this->body, 10);
  7201. }
  7202. $this->body = gzinflate($this->body);
  7203. }
  7204. }
  7205. }
  7206. else
  7207. {
  7208. $this->error = 'fsocket timed out';
  7209. $this->success = false;
  7210. }
  7211. fclose($fp);
  7212. }
  7213. }
  7214. }
  7215. else
  7216. {
  7217. $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
  7218. if (!$this->body = file_get_contents($url))
  7219. {
  7220. $this->error = 'file_get_contents could not read the file';
  7221. $this->success = false;
  7222. }
  7223. }
  7224. }
  7225. }
  7226. /**
  7227. * HTTP Response Parser
  7228. *
  7229. * @package SimplePie
  7230. */
  7231. class SimplePie_HTTP_Parser
  7232. {
  7233. /**
  7234. * HTTP Version
  7235. *
  7236. * @access public
  7237. * @var float
  7238. */
  7239. var $http_version = 0.0;
  7240. /**
  7241. * Status code
  7242. *
  7243. * @access public
  7244. * @var int
  7245. */
  7246. var $status_code = 0;
  7247. /**
  7248. * Reason phrase
  7249. *
  7250. * @access public
  7251. * @var string
  7252. */
  7253. var $reason = '';
  7254. /**
  7255. * Key/value pairs of the headers
  7256. *
  7257. * @access public
  7258. * @var array
  7259. */
  7260. var $headers = array();
  7261. /**
  7262. * Body of the response
  7263. *
  7264. * @access public
  7265. * @var string
  7266. */
  7267. var $body = '';
  7268. /**
  7269. * Current state of the state machine
  7270. *
  7271. * @access private
  7272. * @var string
  7273. */
  7274. var $state = 'http_version';
  7275. /**
  7276. * Input data
  7277. *
  7278. * @access private
  7279. * @var string
  7280. */
  7281. var $data = '';
  7282. /**
  7283. * Input data length (to avoid calling strlen() everytime this is needed)
  7284. *
  7285. * @access private
  7286. * @var int
  7287. */
  7288. var $data_length = 0;
  7289. /**
  7290. * Current position of the pointer
  7291. *
  7292. * @var int
  7293. * @access private
  7294. */
  7295. var $position = 0;
  7296. /**
  7297. * Name of the hedaer currently being parsed
  7298. *
  7299. * @access private
  7300. * @var string
  7301. */
  7302. var $name = '';
  7303. /**
  7304. * Value of the hedaer currently being parsed
  7305. *
  7306. * @access private
  7307. * @var string
  7308. */
  7309. var $value = '';
  7310. /**
  7311. * Create an instance of the class with the input data
  7312. *
  7313. * @access public
  7314. * @param string $data Input data
  7315. */
  7316. function SimplePie_HTTP_Parser($data)
  7317. {
  7318. $this->data = $data;
  7319. $this->data_length = strlen($this->data);
  7320. }
  7321. /**
  7322. * Parse the input data
  7323. *
  7324. * @access public
  7325. * @return bool true on success, false on failure
  7326. */
  7327. function parse()
  7328. {
  7329. while ($this->state && $this->state !== 'emit' && $this->has_data())
  7330. {
  7331. $state = $this->state;
  7332. $this->$state();
  7333. }
  7334. $this->data = '';
  7335. if ($this->state === 'emit' || $this->state === 'body')
  7336. {
  7337. return true;
  7338. }
  7339. else
  7340. {
  7341. $this->http_version = '';
  7342. $this->status_code = '';
  7343. $this->reason = '';
  7344. $this->headers = array();
  7345. $this->body = '';
  7346. return false;
  7347. }
  7348. }
  7349. /**
  7350. * Check whether there is data beyond the pointer
  7351. *
  7352. * @access private
  7353. * @return bool true if there is further data, false if not
  7354. */
  7355. function has_data()
  7356. {
  7357. return (bool) ($this->position < $this->data_length);
  7358. }
  7359. /**
  7360. * See if the next character is LWS
  7361. *
  7362. * @access private
  7363. * @return bool true if the next character is LWS, false if not
  7364. */
  7365. function is_linear_whitespace()
  7366. {
  7367. return (bool) ($this->data[$this->position] === "\x09"
  7368. || $this->data[$this->position] === "\x20"
  7369. || ($this->data[$this->position] === "\x0A"
  7370. && isset($this->data[$this->position + 1])
  7371. && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
  7372. }
  7373. /**
  7374. * Parse the HTTP version
  7375. *
  7376. * @access private
  7377. */
  7378. function http_version()
  7379. {
  7380. if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
  7381. {
  7382. $len = strspn($this->data, '0123456789.', 5);
  7383. $this->http_version = substr($this->data, 5, $len);
  7384. $this->position += 5 + $len;
  7385. if (substr_count($this->http_version, '.') <= 1)
  7386. {
  7387. $this->http_version = (float) $this->http_version;
  7388. $this->position += strspn($this->data, "\x09\x20", $this->position);
  7389. $this->state = 'status';
  7390. }
  7391. else
  7392. {
  7393. $this->state = false;
  7394. }
  7395. }
  7396. else
  7397. {
  7398. $this->state = false;
  7399. }
  7400. }
  7401. /**
  7402. * Parse the status code
  7403. *
  7404. * @access private
  7405. */
  7406. function status()
  7407. {
  7408. if ($len = strspn($this->data, '0123456789', $this->position))
  7409. {
  7410. $this->status_code = (int) substr($this->data, $this->position, $len);
  7411. $this->position += $len;
  7412. $this->state = 'reason';
  7413. }
  7414. else
  7415. {
  7416. $this->state = false;
  7417. }
  7418. }
  7419. /**
  7420. * Parse the reason phrase
  7421. *
  7422. * @access private
  7423. */
  7424. function reason()
  7425. {
  7426. $len = strcspn($this->data, "\x0A", $this->position);
  7427. $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
  7428. $this->position += $len + 1;
  7429. $this->state = 'new_line';
  7430. }
  7431. /**
  7432. * Deal with a new line, shifting data around as needed
  7433. *
  7434. * @access private
  7435. */
  7436. function new_line()
  7437. {
  7438. $this->value = trim($this->value, "\x0D\x20");
  7439. if ($this->name !== '' && $this->value !== '')
  7440. {
  7441. $this->name = strtolower($this->name);
  7442. if (isset($this->headers[$this->name]))
  7443. {
  7444. $this->headers[$this->name] .= ', ' . $this->value;
  7445. }
  7446. else
  7447. {
  7448. $this->headers[$this->name] = $this->value;
  7449. }
  7450. }
  7451. $this->name = '';
  7452. $this->value = '';
  7453. if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
  7454. {
  7455. $this->position += 2;
  7456. $this->state = 'body';
  7457. }
  7458. elseif ($this->data[$this->position] === "\x0A")
  7459. {
  7460. $this->position++;
  7461. $this->state = 'body';
  7462. }
  7463. else
  7464. {
  7465. $this->state = 'name';
  7466. }
  7467. }
  7468. /**
  7469. * Parse a header name
  7470. *
  7471. * @access private
  7472. */
  7473. function name()
  7474. {
  7475. $len = strcspn($this->data, "\x0A:", $this->position);
  7476. if (isset($this->data[$this->position + $len]))
  7477. {
  7478. if ($this->data[$this->position + $len] === "\x0A")
  7479. {
  7480. $this->position += $len;
  7481. $this->state = 'new_line';
  7482. }
  7483. else
  7484. {
  7485. $this->name = substr($this->data, $this->position, $len);
  7486. $this->position += $len + 1;
  7487. $this->state = 'value';
  7488. }
  7489. }
  7490. else
  7491. {
  7492. $this->state = false;
  7493. }
  7494. }
  7495. /**
  7496. * Parse LWS, replacing consecutive LWS characters with a single space
  7497. *
  7498. * @access private
  7499. */
  7500. function linear_whitespace()
  7501. {
  7502. do
  7503. {
  7504. if (substr($this->data, $this->position, 2) === "\x0D\x0A")
  7505. {
  7506. $this->position += 2;
  7507. }
  7508. elseif ($this->data[$this->position] === "\x0A")
  7509. {
  7510. $this->position++;
  7511. }
  7512. $this->position += strspn($this->data, "\x09\x20", $this->position);
  7513. } while ($this->has_data() && $this->is_linear_whitespace());
  7514. $this->value .= "\x20";
  7515. }
  7516. /**
  7517. * See what state to move to while within non-quoted header values
  7518. *
  7519. * @access private
  7520. */
  7521. function value()
  7522. {
  7523. if ($this->is_linear_whitespace())
  7524. {
  7525. $this->linear_whitespace();
  7526. }
  7527. else
  7528. {
  7529. switch ($this->data[$this->position])
  7530. {
  7531. case '"':
  7532. $this->position++;
  7533. $this->state = 'quote';
  7534. break;
  7535. case "\x0A":
  7536. $this->position++;
  7537. $this->state = 'new_line';
  7538. break;
  7539. default:
  7540. $this->state = 'value_char';
  7541. break;
  7542. }
  7543. }
  7544. }
  7545. /**
  7546. * Parse a header value while outside quotes
  7547. *
  7548. * @access private
  7549. */
  7550. function value_char()
  7551. {
  7552. $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
  7553. $this->value .= substr($this->data, $this->position, $len);
  7554. $this->position += $len;
  7555. $this->state = 'value';
  7556. }
  7557. /**
  7558. * See what state to move to while within quoted header values
  7559. *
  7560. * @access private
  7561. */
  7562. function quote()
  7563. {
  7564. if ($this->is_linear_whitespace())
  7565. {
  7566. $this->linear_whitespace();
  7567. }
  7568. else
  7569. {
  7570. switch ($this->data[$this->position])
  7571. {
  7572. case '"':
  7573. $this->position++;
  7574. $this->state = 'value';
  7575. break;
  7576. case "\x0A":
  7577. $this->position++;
  7578. $this->state = 'new_line';
  7579. break;
  7580. case '\\':
  7581. $this->position++;
  7582. $this->state = 'quote_escaped';
  7583. break;
  7584. default:
  7585. $this->state = 'quote_char';
  7586. break;
  7587. }
  7588. }
  7589. }
  7590. /**
  7591. * Parse a header value while within quotes
  7592. *
  7593. * @access private
  7594. */
  7595. function quote_char()
  7596. {
  7597. $len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
  7598. $this->value .= substr($this->data, $this->position, $len);
  7599. $this->position += $len;
  7600. $this->state = 'value';
  7601. }
  7602. /**
  7603. * Parse an escaped character within quotes
  7604. *
  7605. * @access private
  7606. */
  7607. function quote_escaped()
  7608. {
  7609. $this->value .= $this->data[$this->position];
  7610. $this->position++;
  7611. $this->state = 'quote';
  7612. }
  7613. /**
  7614. * Parse the body
  7615. *
  7616. * @access private
  7617. */
  7618. function body()
  7619. {
  7620. $this->body = substr($this->data, $this->position);
  7621. $this->state = 'emit';
  7622. }
  7623. }
  7624. class SimplePie_Cache
  7625. {
  7626. /**
  7627. * Don't call the constructor. Please.
  7628. *
  7629. * @access private
  7630. */
  7631. function SimplePie_Cache()
  7632. {
  7633. trigger_error('Please call SimplePie_Cache::create() instead of the constructor', E_USER_ERROR);
  7634. }
  7635. /**
  7636. * Create a new SimplePie_Cache object
  7637. *
  7638. * @static
  7639. * @access public
  7640. */
  7641. function create($location, $filename, $extension)
  7642. {
  7643. return new SimplePie_Cache_File($location, $filename, $extension);
  7644. }
  7645. }
  7646. class SimplePie_Cache_File
  7647. {
  7648. var $location;
  7649. var $filename;
  7650. var $extension;
  7651. var $name;
  7652. function SimplePie_Cache_File($location, $filename, $extension)
  7653. {
  7654. $this->location = $location;
  7655. $this->filename = rawurlencode($filename);
  7656. $this->extension = rawurlencode($extension);
  7657. $this->name = "$location/$this->filename.$this->extension";
  7658. }
  7659. function save($data)
  7660. {
  7661. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  7662. {
  7663. if (is_a($data, 'SimplePie'))
  7664. {
  7665. $data = $data->data;
  7666. }
  7667. $data = serialize($data);
  7668. if (function_exists('file_put_contents'))
  7669. {
  7670. return (bool) file_put_contents($this->name, $data);
  7671. }
  7672. else
  7673. {
  7674. $fp = fopen($this->name, 'wb');
  7675. if ($fp)
  7676. {
  7677. fwrite($fp, $data);
  7678. fclose($fp);
  7679. return true;
  7680. }
  7681. }
  7682. }
  7683. return false;
  7684. }
  7685. function load()
  7686. {
  7687. if (file_exists($this->name) && is_readable($this->name))
  7688. {
  7689. return unserialize(file_get_contents($this->name));
  7690. }
  7691. return false;
  7692. }
  7693. function mtime()
  7694. {
  7695. if (file_exists($this->name))
  7696. {
  7697. return filemtime($this->name);
  7698. }
  7699. return false;
  7700. }
  7701. function touch()
  7702. {
  7703. if (file_exists($this->name))
  7704. {
  7705. return touch($this->name);
  7706. }
  7707. return false;
  7708. }
  7709. function unlink()
  7710. {
  7711. if (file_exists($this->name))
  7712. {
  7713. return unlink($this->name);
  7714. }
  7715. return false;
  7716. }
  7717. }
  7718. class SimplePie_Misc
  7719. {
  7720. function time_hms($seconds)
  7721. {
  7722. $time = '';
  7723. $hours = floor($seconds / 3600);
  7724. $remainder = $seconds % 3600;
  7725. if ($hours > 0)
  7726. {
  7727. $time .= $hours.':';
  7728. }
  7729. $minutes = floor($remainder / 60);
  7730. $seconds = $remainder % 60;
  7731. if ($minutes < 10 && $hours > 0)
  7732. {
  7733. $minutes = '0' . $minutes;
  7734. }
  7735. if ($seconds < 10)
  7736. {
  7737. $seconds = '0' . $seconds;
  7738. }
  7739. $time .= $minutes.':';
  7740. $time .= $seconds;
  7741. return $time;
  7742. }
  7743. function absolutize_url($relative, $base)
  7744. {
  7745. if ($relative !== '')
  7746. {
  7747. $relative = SimplePie_Misc::parse_url($relative);
  7748. if ($relative['scheme'] !== '')
  7749. {
  7750. $target = $relative;
  7751. }
  7752. elseif ($base !== '')
  7753. {
  7754. $base = SimplePie_Misc::parse_url($base);
  7755. $target = SimplePie_Misc::parse_url('');
  7756. if ($relative['authority'] !== '')
  7757. {
  7758. $target = $relative;
  7759. $target['scheme'] = $base['scheme'];
  7760. }
  7761. else
  7762. {
  7763. $target['scheme'] = $base['scheme'];
  7764. $target['authority'] = $base['authority'];
  7765. if ($relative['path'] !== '')
  7766. {
  7767. if (strpos($relative['path'], '/') === 0)
  7768. {
  7769. $target['path'] = $relative['path'];
  7770. }
  7771. elseif ($base['authority'] !== '' && $base['path'] === '')
  7772. {
  7773. $target['path'] = '/' . $relative['path'];
  7774. }
  7775. elseif (($last_segment = strrpos($base['path'], '/')) !== false)
  7776. {
  7777. $target['path'] = substr($base['path'], 0, $last_segment + 1) . $relative['path'];
  7778. }
  7779. else
  7780. {
  7781. $target['path'] = $relative['path'];
  7782. }
  7783. $target['query'] = $relative['query'];
  7784. }
  7785. else
  7786. {
  7787. $target['path'] = $base['path'];
  7788. if ($relative['query'] !== '')
  7789. {
  7790. $target['query'] = $relative['query'];
  7791. }
  7792. elseif ($base['query'] !== '')
  7793. {
  7794. $target['query'] = $base['query'];
  7795. }
  7796. }
  7797. }
  7798. $target['fragment'] = $relative['fragment'];
  7799. }
  7800. else
  7801. {
  7802. // No base URL, just return the relative URL
  7803. $target = $relative;
  7804. }
  7805. $return = SimplePie_Misc::compress_parse_url($target['scheme'], $target['authority'], $target['path'], $target['query'], $target['fragment']);
  7806. }
  7807. else
  7808. {
  7809. $return = $base;
  7810. }
  7811. $return = SimplePie_Misc::normalize_url($return);
  7812. return $return;
  7813. }
  7814. function remove_dot_segments($input)
  7815. {
  7816. $output = '';
  7817. while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input == '.' || $input == '..')
  7818. {
  7819. // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
  7820. if (strpos($input, '../') === 0)
  7821. {
  7822. $input = substr($input, 3);
  7823. }
  7824. elseif (strpos($input, './') === 0)
  7825. {
  7826. $input = substr($input, 2);
  7827. }
  7828. // B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
  7829. elseif (strpos($input, '/./') === 0)
  7830. {
  7831. $input = substr_replace($input, '/', 0, 3);
  7832. }
  7833. elseif ($input == '/.')
  7834. {
  7835. $input = '/';
  7836. }
  7837. // C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
  7838. elseif (strpos($input, '/../') === 0)
  7839. {
  7840. $input = substr_replace($input, '/', 0, 4);
  7841. $output = substr_replace($output, '', strrpos($output, '/'));
  7842. }
  7843. elseif ($input == '/..')
  7844. {
  7845. $input = '/';
  7846. $output = substr_replace($output, '', strrpos($output, '/'));
  7847. }
  7848. // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
  7849. elseif ($input == '.' || $input == '..')
  7850. {
  7851. $input = '';
  7852. }
  7853. // E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
  7854. elseif (($pos = strpos($input, '/', 1)) !== false)
  7855. {
  7856. $output .= substr($input, 0, $pos);
  7857. $input = substr_replace($input, '', 0, $pos);
  7858. }
  7859. else
  7860. {
  7861. $output .= $input;
  7862. $input = '';
  7863. }
  7864. }
  7865. return $output . $input;
  7866. }
  7867. function get_element($realname, $string)
  7868. {
  7869. $return = array();
  7870. $name = preg_quote($realname, '/');
  7871. if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
  7872. {
  7873. for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
  7874. {
  7875. $return[$i]['tag'] = $realname;
  7876. $return[$i]['full'] = $matches[$i][0][0];
  7877. $return[$i]['offset'] = $matches[$i][0][1];
  7878. if (strlen($matches[$i][3][0]) <= 2)
  7879. {
  7880. $return[$i]['self_closing'] = true;
  7881. }
  7882. else
  7883. {
  7884. $return[$i]['self_closing'] = false;
  7885. $return[$i]['content'] = $matches[$i][4][0];
  7886. }
  7887. $return[$i]['attribs'] = array();
  7888. if (isset($matches[$i][2][0]) && preg_match_all('/[\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]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER))
  7889. {
  7890. for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
  7891. {
  7892. if (count($attribs[$j]) == 2)
  7893. {
  7894. $attribs[$j][2] = $attribs[$j][1];
  7895. }
  7896. $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
  7897. }
  7898. }
  7899. }
  7900. }
  7901. return $return;
  7902. }
  7903. function element_implode($element)
  7904. {
  7905. $full = "<$element[tag]";
  7906. foreach ($element['attribs'] as $key => $value)
  7907. {
  7908. $key = strtolower($key);
  7909. $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
  7910. }
  7911. if ($element['self_closing'])
  7912. {
  7913. $full .= ' />';
  7914. }
  7915. else
  7916. {
  7917. $full .= ">$element[content]</$element[tag]>";
  7918. }
  7919. return $full;
  7920. }
  7921. function error($message, $level, $file, $line)
  7922. {
  7923. switch ($level)
  7924. {
  7925. case E_USER_ERROR:
  7926. $note = 'PHP Error';
  7927. break;
  7928. case E_USER_WARNING:
  7929. $note = 'PHP Warning';
  7930. break;
  7931. case E_USER_NOTICE:
  7932. $note = 'PHP Notice';
  7933. break;
  7934. default:
  7935. $note = 'Unknown Error';
  7936. break;
  7937. }
  7938. error_log("$note: $message in $file on line $line", 0);
  7939. return $message;
  7940. }
  7941. /**
  7942. * If a file has been cached, retrieve and display it.
  7943. *
  7944. * This is most useful for caching images (get_favicon(), etc.),
  7945. * however it works for all cached files. This WILL NOT display ANY
  7946. * file/image/page/whatever, but rather only display what has already
  7947. * been cached by SimplePie.
  7948. *
  7949. * @access public
  7950. * @see SimplePie::get_favicon()
  7951. * @param str $identifier_url URL that is used to identify the content.
  7952. * This may or may not be the actual URL of the live content.
  7953. * @param str $cache_location Location of SimplePie's cache. Defaults
  7954. * to './cache'.
  7955. * @param str $cache_extension The file extension that the file was
  7956. * cached with. Defaults to 'spc'.
  7957. * @param str $cache_class Name of the cache-handling class being used
  7958. * in SimplePie. Defaults to 'SimplePie_Cache', and should be left
  7959. * as-is unless you've overloaded the class.
  7960. * @param str $cache_name_function Obsolete. Exists for backwards
  7961. * compatibility reasons only.
  7962. */
  7963. function display_cached_file($identifier_url, $cache_location = './cache', $cache_extension = 'spc', $cache_class = 'SimplePie_Cache', $cache_name_function = 'md5')
  7964. {
  7965. $cache = call_user_func(array($cache_class, 'create'), $cache_location, $identifier_url, $cache_extension);
  7966. if ($file = $cache->load())
  7967. {
  7968. if (isset($file['headers']['content-type']))
  7969. {
  7970. header('Content-type:' . $file['headers']['content-type']);
  7971. }
  7972. else
  7973. {
  7974. header('Content-type: application/octet-stream');
  7975. }
  7976. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  7977. echo $file['body'];
  7978. exit;
  7979. }
  7980. die('Cached file for ' . $identifier_url . ' cannot be found.');
  7981. }
  7982. function fix_protocol($url, $http = 1)
  7983. {
  7984. $url = SimplePie_Misc::normalize_url($url);
  7985. $parsed = SimplePie_Misc::parse_url($url);
  7986. if ($parsed['scheme'] !== '' && $parsed['scheme'] != 'http' && $parsed['scheme'] != 'https')
  7987. {
  7988. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
  7989. }
  7990. if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
  7991. {
  7992. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
  7993. }
  7994. if ($http == 2 && $parsed['scheme'] !== '')
  7995. {
  7996. return "feed:$url";
  7997. }
  7998. elseif ($http == 3 && strtolower($parsed['scheme']) == 'http')
  7999. {
  8000. return substr_replace($url, 'podcast', 0, 4);
  8001. }
  8002. elseif ($http == 4 && strtolower($parsed['scheme']) == 'http')
  8003. {
  8004. return substr_replace($url, 'itpc', 0, 4);
  8005. }
  8006. else
  8007. {
  8008. return $url;
  8009. }
  8010. }
  8011. function parse_url($url)
  8012. {
  8013. static $cache = array();
  8014. if (isset($cache[$url]))
  8015. {
  8016. return $cache[$url];
  8017. }
  8018. elseif (preg_match('/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $url, $match))
  8019. {
  8020. for ($i = count($match); $i <= 9; $i++)
  8021. {
  8022. $match[$i] = '';
  8023. }
  8024. return $cache[$url] = array('scheme' => $match[2], 'authority' => $match[4], 'path' => $match[5], 'query' => $match[7], 'fragment' => $match[9]);
  8025. }
  8026. else
  8027. {
  8028. return $cache[$url] = array('scheme' => '', 'authority' => '', 'path' => '', 'query' => '', 'fragment' => '');
  8029. }
  8030. }
  8031. function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
  8032. {
  8033. $return = '';
  8034. if ($scheme !== '')
  8035. {
  8036. $return .= "$scheme:";
  8037. }
  8038. if ($authority !== '')
  8039. {
  8040. $return .= "//$authority";
  8041. }
  8042. if ($path !== '')
  8043. {
  8044. $return .= $path;
  8045. }
  8046. if ($query !== '')
  8047. {
  8048. $return .= "?$query";
  8049. }
  8050. if ($fragment !== '')
  8051. {
  8052. $return .= "#$fragment";
  8053. }
  8054. return $return;
  8055. }
  8056. function normalize_url($url)
  8057. {
  8058. $url = preg_replace_callback('/%([0-9A-Fa-f]{2})/', array('SimplePie_Misc', 'percent_encoding_normalization'), $url);
  8059. $url = SimplePie_Misc::parse_url($url);
  8060. $url['scheme'] = strtolower($url['scheme']);
  8061. if ($url['authority'] !== '')
  8062. {
  8063. $url['authority'] = strtolower($url['authority']);
  8064. $url['path'] = SimplePie_Misc::remove_dot_segments($url['path']);
  8065. }
  8066. return SimplePie_Misc::compress_parse_url($url['scheme'], $url['authority'], $url['path'], $url['query'], $url['fragment']);
  8067. }
  8068. function percent_encoding_normalization($match)
  8069. {
  8070. $integer = hexdec($match[1]);
  8071. if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer == 0x2D || $integer == 0x2E || $integer == 0x5F || $integer == 0x7E)
  8072. {
  8073. return chr($integer);
  8074. }
  8075. else
  8076. {
  8077. return strtoupper($match[0]);
  8078. }
  8079. }
  8080. /**
  8081. * Remove bad UTF-8 bytes
  8082. *
  8083. * PCRE Pattern to locate bad bytes in a UTF-8 string comes from W3C
  8084. * FAQ: Multilingual Forms (modified to include full ASCII range)
  8085. *
  8086. * @author Geoffrey Sneddon
  8087. * @see http://www.w3.org/International/questions/qa-forms-utf-8
  8088. * @param string $str String to remove bad UTF-8 bytes from
  8089. * @return string UTF-8 string
  8090. */
  8091. function utf8_bad_replace($str)
  8092. {
  8093. if (function_exists('iconv') && ($return = @iconv('UTF-8', 'UTF-8//IGNORE', $str)))
  8094. {
  8095. return $return;
  8096. }
  8097. elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($str, 'UTF-8', 'UTF-8')))
  8098. {
  8099. return $return;
  8100. }
  8101. elseif (preg_match_all('/(?:[\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})+/', $str, $matches))
  8102. {
  8103. return implode("\xEF\xBF\xBD", $matches[0]);
  8104. }
  8105. elseif ($str !== '')
  8106. {
  8107. return "\xEF\xBF\xBD";
  8108. }
  8109. else
  8110. {
  8111. return '';
  8112. }
  8113. }
  8114. /**
  8115. * Converts a Windows-1252 encoded string to a UTF-8 encoded string
  8116. *
  8117. * @static
  8118. * @access public
  8119. * @param string $string Windows-1252 encoded string
  8120. * @return string UTF-8 encoded string
  8121. */
  8122. function windows_1252_to_utf8($string)
  8123. {
  8124. static $convert_table = array("\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF");
  8125. return strtr($string, $convert_table);
  8126. }
  8127. function change_encoding($data, $input, $output)
  8128. {
  8129. $input = SimplePie_Misc::encoding($input);
  8130. $output = SimplePie_Misc::encoding($output);
  8131. // We fail to fail on non US-ASCII bytes
  8132. if ($input === 'US-ASCII')
  8133. {
  8134. static $non_ascii_octects = '';
  8135. if (!$non_ascii_octects)
  8136. {
  8137. for ($i = 0x80; $i <= 0xFF; $i++)
  8138. {
  8139. $non_ascii_octects .= chr($i);
  8140. }
  8141. }
  8142. $data = substr($data, 0, strcspn($data, $non_ascii_octects));
  8143. }
  8144. if (function_exists('iconv') && ($return = @iconv($input, $output, $data)))
  8145. {
  8146. return $return;
  8147. }
  8148. elseif (function_exists('mb_convert_encoding') && ($return = @mb_convert_encoding($data, $output, $input)))
  8149. {
  8150. return $return;
  8151. }
  8152. elseif ($input == 'windows-1252' && $output == 'UTF-8')
  8153. {
  8154. return SimplePie_Misc::windows_1252_to_utf8($data);
  8155. }
  8156. elseif ($input == 'UTF-8' && $output == 'windows-1252')
  8157. {
  8158. return utf8_decode($data);
  8159. }
  8160. return $data;
  8161. }
  8162. function encoding($encoding)
  8163. {
  8164. // Character sets are case-insensitive (though we'll return them in the form given in their registration)
  8165. switch (strtoupper($encoding))
  8166. {
  8167. case 'ANSI_X3.110-1983':
  8168. case 'CSA_T500-1983':
  8169. case 'CSISO99NAPLPS':
  8170. case 'ISO-IR-99':
  8171. case 'NAPLPS':
  8172. return 'ANSI_X3.110-1983';
  8173. case 'ARABIC7':
  8174. case 'ASMO_449':
  8175. case 'CSISO89ASMO449':
  8176. case 'ISO-IR-89':
  8177. case 'ISO_9036':
  8178. return 'ASMO_449';
  8179. case 'ADOBE-STANDARD-ENCODING':
  8180. case 'CSADOBESTANDARDENCODING':
  8181. return 'Adobe-Standard-Encoding';
  8182. case 'ADOBE-SYMBOL-ENCODING':
  8183. case 'CSHPPSMATH':
  8184. return 'Adobe-Symbol-Encoding';
  8185. case 'AMI-1251':
  8186. case 'AMI1251':
  8187. case 'AMIGA-1251':
  8188. case 'AMIGA1251':
  8189. return 'Amiga-1251';
  8190. case 'BOCU-1':
  8191. case 'CSBOCU-1':
  8192. return 'BOCU-1';
  8193. case 'BRF':
  8194. case 'CSBRF':
  8195. return 'BRF';
  8196. case 'BS_4730':
  8197. case 'CSISO4UNITEDKINGDOM':
  8198. case 'GB':
  8199. case 'ISO-IR-4':
  8200. case 'ISO646-GB':
  8201. case 'UK':
  8202. return 'BS_4730';
  8203. case 'BS_VIEWDATA':
  8204. case 'CSISO47BSVIEWDATA':
  8205. case 'ISO-IR-47':
  8206. return 'BS_viewdata';
  8207. case 'BIG5':
  8208. case 'CSBIG5':
  8209. return 'Big5';
  8210. case 'BIG5-HKSCS':
  8211. return 'Big5-HKSCS';
  8212. case 'CESU-8':
  8213. case 'CSCESU-8':
  8214. return 'CESU-8';
  8215. case 'CA':
  8216. case 'CSA7-1':
  8217. case 'CSA_Z243.4-1985-1':
  8218. case 'CSISO121CANADIAN1':
  8219. case 'ISO-IR-121':
  8220. case 'ISO646-CA':
  8221. return 'CSA_Z243.4-1985-1';
  8222. case 'CSA7-2':
  8223. case 'CSA_Z243.4-1985-2':
  8224. case 'CSISO122CANADIAN2':
  8225. case 'ISO-IR-122':
  8226. case 'ISO646-CA2':
  8227. return 'CSA_Z243.4-1985-2';
  8228. case 'CSA_Z243.4-1985-GR':
  8229. case 'CSISO123CSAZ24341985GR':
  8230. case 'ISO-IR-123':
  8231. return 'CSA_Z243.4-1985-gr';
  8232. case 'CSISO139CSN369103':
  8233. case 'CSN_369103':
  8234. case 'ISO-IR-139':
  8235. return 'CSN_369103';
  8236. case 'CSDECMCS':
  8237. case 'DEC':
  8238. case 'DEC-MCS':
  8239. return 'DEC-MCS';
  8240. case 'CSISO21GERMAN':
  8241. case 'DE':
  8242. case 'DIN_66003':
  8243. case 'ISO-IR-21':
  8244. case 'ISO646-DE':
  8245. return 'DIN_66003';
  8246. case 'CSISO646DANISH':
  8247. case 'DK':
  8248. case 'DS2089':
  8249. case 'DS_2089':
  8250. case 'ISO646-DK':
  8251. return 'DS_2089';
  8252. case 'CSIBMEBCDICATDE':
  8253. case 'EBCDIC-AT-DE':
  8254. return 'EBCDIC-AT-DE';
  8255. case 'CSEBCDICATDEA':
  8256. case 'EBCDIC-AT-DE-A':
  8257. return 'EBCDIC-AT-DE-A';
  8258. case 'CSEBCDICCAFR':
  8259. case 'EBCDIC-CA-FR':
  8260. return 'EBCDIC-CA-FR';
  8261. case 'CSEBCDICDKNO':
  8262. case 'EBCDIC-DK-NO':
  8263. return 'EBCDIC-DK-NO';
  8264. case 'CSEBCDICDKNOA':
  8265. case 'EBCDIC-DK-NO-A':
  8266. return 'EBCDIC-DK-NO-A';
  8267. case 'CSEBCDICES':
  8268. case 'EBCDIC-ES':
  8269. return 'EBCDIC-ES';
  8270. case 'CSEBCDICESA':
  8271. case 'EBCDIC-ES-A':
  8272. return 'EBCDIC-ES-A';
  8273. case 'CSEBCDICESS':
  8274. case 'EBCDIC-ES-S':
  8275. return 'EBCDIC-ES-S';
  8276. case 'CSEBCDICFISE':
  8277. case 'EBCDIC-FI-SE':
  8278. return 'EBCDIC-FI-SE';
  8279. case 'CSEBCDICFISEA':
  8280. case 'EBCDIC-FI-SE-A':
  8281. return 'EBCDIC-FI-SE-A';
  8282. case 'CSEBCDICFR':
  8283. case 'EBCDIC-FR':
  8284. return 'EBCDIC-FR';
  8285. case 'CSEBCDICIT':
  8286. case 'EBCDIC-IT':
  8287. return 'EBCDIC-IT';
  8288. case 'CSEBCDICPT':
  8289. case 'EBCDIC-PT':
  8290. return 'EBCDIC-PT';
  8291. case 'CSEBCDICUK':
  8292. case 'EBCDIC-UK':
  8293. return 'EBCDIC-UK';
  8294. case 'CSEBCDICUS':
  8295. case 'EBCDIC-US':
  8296. return 'EBCDIC-US';
  8297. case 'CSISO111ECMACYRILLIC':
  8298. case 'ECMA-CYRILLIC':
  8299. case 'ISO-IR-111':
  8300. case 'KOI8-E':
  8301. return 'ECMA-cyrillic';
  8302. case 'CSISO17SPANISH':
  8303. case 'ES':
  8304. case 'ISO-IR-17':
  8305. case 'ISO646-ES':
  8306. return 'ES';
  8307. case 'CSISO85SPANISH2':
  8308. case 'ES2':
  8309. case 'ISO-IR-85':
  8310. case 'ISO646-ES2':
  8311. return 'ES2';
  8312. case 'CSEUCPKDFMTJAPANESE':
  8313. case 'EUC-JP':
  8314. case 'EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE':
  8315. return 'EUC-JP';
  8316. case 'CSEUCKR':
  8317. case 'EUC-KR':
  8318. return 'EUC-KR';
  8319. case 'CSEUCFIXWIDJAPANESE':
  8320. case 'EXTENDED_UNIX_CODE_FIXED_WIDTH_FOR_JAPANESE':
  8321. return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
  8322. case 'GB18030':
  8323. return 'GB18030';
  8324. case 'CSGB2312':
  8325. case 'GB2312':
  8326. return 'GB2312';
  8327. case 'CP936':
  8328. case 'GBK':
  8329. case 'MS936':
  8330. case 'WINDOWS-936':
  8331. return 'GBK';
  8332. case 'CN':
  8333. case 'CSISO57GB1988':
  8334. case 'GB_1988-80':
  8335. case 'ISO-IR-57':
  8336. case 'ISO646-CN':
  8337. return 'GB_1988-80';
  8338. case 'CHINESE':
  8339. case 'CSISO58GB231280':
  8340. case 'GB_2312-80':
  8341. case 'ISO-IR-58':
  8342. return 'GB_2312-80';
  8343. case 'CSISO153GOST1976874':
  8344. case 'GOST_19768-74':
  8345. case 'ISO-IR-153':
  8346. case 'ST_SEV_358-88':
  8347. return 'GOST_19768-74';
  8348. case 'CSHPDESKTOP':
  8349. case 'HP-DESKTOP':
  8350. return 'HP-DeskTop';
  8351. case 'CSHPLEGAL':
  8352. case 'HP-LEGAL':
  8353. return 'HP-Legal';
  8354. case 'CSHPMATH8':
  8355. case 'HP-MATH8':
  8356. return 'HP-Math8';
  8357. case 'CSHPPIFONT':
  8358. case 'HP-PI-FONT':
  8359. return 'HP-Pi-font';
  8360. case 'HZ-GB-2312':
  8361. return 'HZ-GB-2312';
  8362. case 'CSIBMSYMBOLS':
  8363. case 'IBM-SYMBOLS':
  8364. return 'IBM-Symbols';
  8365. case 'CSIBMTHAI':
  8366. case 'IBM-THAI':
  8367. return 'IBM-Thai';
  8368. case 'CCSID00858':
  8369. case 'CP00858':
  8370. case 'IBM00858':
  8371. case 'PC-MULTILINGUAL-850+EURO':
  8372. return 'IBM00858';
  8373. case 'CCSID00924':
  8374. case 'CP00924':
  8375. case 'EBCDIC-LATIN9--EURO':
  8376. case 'IBM00924':
  8377. return 'IBM00924';
  8378. case 'CCSID01140':
  8379. case 'CP01140':
  8380. case 'EBCDIC-US-37+EURO':
  8381. case 'IBM01140':
  8382. return 'IBM01140';
  8383. case 'CCSID01141':
  8384. case 'CP01141':
  8385. case 'EBCDIC-DE-273+EURO':
  8386. case 'IBM01141':
  8387. return 'IBM01141';
  8388. case 'CCSID01142':
  8389. case 'CP01142':
  8390. case 'EBCDIC-DK-277+EURO':
  8391. case 'EBCDIC-NO-277+EURO':
  8392. case 'IBM01142':
  8393. return 'IBM01142';
  8394. case 'CCSID01143':
  8395. case 'CP01143':
  8396. case 'EBCDIC-FI-278+EURO':
  8397. case 'EBCDIC-SE-278+EURO':
  8398. case 'IBM01143':
  8399. return 'IBM01143';
  8400. case 'CCSID01144':
  8401. case 'CP01144':
  8402. case 'EBCDIC-IT-280+EURO':
  8403. case 'IBM01144':
  8404. return 'IBM01144';
  8405. case 'CCSID01145':
  8406. case 'CP01145':
  8407. case 'EBCDIC-ES-284+EURO':
  8408. case 'IBM01145':
  8409. return 'IBM01145';
  8410. case 'CCSID01146':
  8411. case 'CP01146':
  8412. case 'EBCDIC-GB-285+EURO':
  8413. case 'IBM01146':
  8414. return 'IBM01146';
  8415. case 'CCSID01147':
  8416. case 'CP01147':
  8417. case 'EBCDIC-FR-297+EURO':
  8418. case 'IBM01147':
  8419. return 'IBM01147';
  8420. case 'CCSID01148':
  8421. case 'CP01148':
  8422. case 'EBCDIC-INTERNATIONAL-500+EURO':
  8423. case 'IBM01148':
  8424. return 'IBM01148';
  8425. case 'CCSID01149':
  8426. case 'CP01149':
  8427. case 'EBCDIC-IS-871+EURO':
  8428. case 'IBM01149':
  8429. return 'IBM01149';
  8430. case 'CP037':
  8431. case 'CSIBM037':
  8432. case 'EBCDIC-CP-CA':
  8433. case 'EBCDIC-CP-NL':
  8434. case 'EBCDIC-CP-US':
  8435. case 'EBCDIC-CP-WT':
  8436. case 'IBM037':
  8437. return 'IBM037';
  8438. case 'CP038':
  8439. case 'CSIBM038':
  8440. case 'EBCDIC-INT':
  8441. case 'IBM038':
  8442. return 'IBM038';
  8443. case 'CP1026':
  8444. case 'CSIBM1026':
  8445. case 'IBM1026':
  8446. return 'IBM1026';
  8447. case 'IBM-1047':
  8448. case 'IBM1047':
  8449. return 'IBM1047';
  8450. case 'CP273':
  8451. case 'CSIBM273':
  8452. case 'IBM273':
  8453. return 'IBM273';
  8454. case 'CP274':
  8455. case 'CSIBM274':
  8456. case 'EBCDIC-BE':
  8457. case 'IBM274':
  8458. return 'IBM274';
  8459. case 'CP275':
  8460. case 'CSIBM275':
  8461. case 'EBCDIC-BR':
  8462. case 'IBM275':
  8463. return 'IBM275';
  8464. case 'CSIBM277':
  8465. case 'EBCDIC-CP-DK':
  8466. case 'EBCDIC-CP-NO':
  8467. case 'IBM277':
  8468. return 'IBM277';
  8469. case 'CP278':
  8470. case 'CSIBM278':
  8471. case 'EBCDIC-CP-FI':
  8472. case 'EBCDIC-CP-SE':
  8473. case 'IBM278':
  8474. return 'IBM278';
  8475. case 'CP280':
  8476. case 'CSIBM280':
  8477. case 'EBCDIC-CP-IT':
  8478. case 'IBM280':
  8479. return 'IBM280';
  8480. case 'CP281':
  8481. case 'CSIBM281':
  8482. case 'EBCDIC-JP-E':
  8483. case 'IBM281':
  8484. return 'IBM281';
  8485. case 'CP284':
  8486. case 'CSIBM284':
  8487. case 'EBCDIC-CP-ES':
  8488. case 'IBM284':
  8489. return 'IBM284';
  8490. case 'CP285':
  8491. case 'CSIBM285':
  8492. case 'EBCDIC-CP-GB':
  8493. case 'IBM285':
  8494. return 'IBM285';
  8495. case 'CP290':
  8496. case 'CSIBM290':
  8497. case 'EBCDIC-JP-KANA':
  8498. case 'IBM290':
  8499. return 'IBM290';
  8500. case 'CP297':
  8501. case 'CSIBM297':
  8502. case 'EBCDIC-CP-FR':
  8503. case 'IBM297':
  8504. return 'IBM297';
  8505. case 'CP420':
  8506. case 'CSIBM420':
  8507. case 'EBCDIC-CP-AR1':
  8508. case 'IBM420':
  8509. return 'IBM420';
  8510. case 'CP423':
  8511. case 'CSIBM423':
  8512. case 'EBCDIC-CP-GR':
  8513. case 'IBM423':
  8514. return 'IBM423';
  8515. case 'CP424':
  8516. case 'CSIBM424':
  8517. case 'EBCDIC-CP-HE':
  8518. case 'IBM424':
  8519. return 'IBM424';
  8520. case '437':
  8521. case 'CP437':
  8522. case 'CSPC8CODEPAGE437':
  8523. case 'IBM437':
  8524. return 'IBM437';
  8525. case 'CP500':
  8526. case 'CSIBM500':
  8527. case 'EBCDIC-CP-BE':
  8528. case 'EBCDIC-CP-CH':
  8529. case 'IBM500':
  8530. return 'IBM500';
  8531. case 'CP775':
  8532. case 'CSPC775BALTIC':
  8533. case 'IBM775':
  8534. return 'IBM775';
  8535. case '850':
  8536. case 'CP850':
  8537. case 'CSPC850MULTILINGUAL':
  8538. case 'IBM850':
  8539. return 'IBM850';
  8540. case '851':
  8541. case 'CP851':
  8542. case 'CSIBM851':
  8543. case 'IBM851':
  8544. return 'IBM851';
  8545. case '852':
  8546. case 'CP852':
  8547. case 'CSPCP852':
  8548. case 'IBM852':
  8549. return 'IBM852';
  8550. case '855':
  8551. case 'CP855':
  8552. case 'CSIBM855':
  8553. case 'IBM855':
  8554. return 'IBM855';
  8555. case '857':
  8556. case 'CP857':
  8557. case 'CSIBM857':
  8558. case 'IBM857':
  8559. return 'IBM857';
  8560. case '860':
  8561. case 'CP860':
  8562. case 'CSIBM860':
  8563. case 'IBM860':
  8564. return 'IBM860';
  8565. case '861':
  8566. case 'CP-IS':
  8567. case 'CP861':
  8568. case 'CSIBM861':
  8569. case 'IBM861':
  8570. return 'IBM861';
  8571. case '862':
  8572. case 'CP862':
  8573. case 'CSPC862LATINHEBREW':
  8574. case 'IBM862':
  8575. return 'IBM862';
  8576. case '863':
  8577. case 'CP863':
  8578. case 'CSIBM863':
  8579. case 'IBM863':
  8580. return 'IBM863';
  8581. case 'CP864':
  8582. case 'CSIBM864':
  8583. case 'IBM864':
  8584. return 'IBM864';
  8585. case '865':
  8586. case 'CP865':
  8587. case 'CSIBM865':
  8588. case 'IBM865':
  8589. return 'IBM865';
  8590. case '866':
  8591. case 'CP866':
  8592. case 'CSIBM866':
  8593. case 'IBM866':
  8594. return 'IBM866';
  8595. case 'CP-AR':
  8596. case 'CP868':
  8597. case 'CSIBM868':
  8598. case 'IBM868':
  8599. return 'IBM868';
  8600. case '869':
  8601. case 'CP-GR':
  8602. case 'CP869':
  8603. case 'CSIBM869':
  8604. case 'IBM869':
  8605. return 'IBM869';
  8606. case 'CP870':
  8607. case 'CSIBM870':
  8608. case 'EBCDIC-CP-ROECE':
  8609. case 'EBCDIC-CP-YU':
  8610. case 'IBM870':
  8611. return 'IBM870';
  8612. case 'CP871':
  8613. case 'CSIBM871':
  8614. case 'EBCDIC-CP-IS':
  8615. case 'IBM871':
  8616. return 'IBM871';
  8617. case 'CP880':
  8618. case 'CSIBM880':
  8619. case 'EBCDIC-CYRILLIC':
  8620. case 'IBM880':
  8621. return 'IBM880';
  8622. case 'CP891':
  8623. case 'CSIBM891':
  8624. case 'IBM891':
  8625. return 'IBM891';
  8626. case 'CP903':
  8627. case 'CSIBM903':
  8628. case 'IBM903':
  8629. return 'IBM903';
  8630. case '904':
  8631. case 'CP904':
  8632. case 'CSIBBM904':
  8633. case 'IBM904':
  8634. return 'IBM904';
  8635. case 'CP905':
  8636. case 'CSIBM905':
  8637. case 'EBCDIC-CP-TR':
  8638. case 'IBM905':
  8639. return 'IBM905';
  8640. case 'CP918':
  8641. case 'CSIBM918':
  8642. case 'EBCDIC-CP-AR2':
  8643. case 'IBM918':
  8644. return 'IBM918';
  8645. case 'CSISO143IECP271':
  8646. case 'IEC_P27-1':
  8647. case 'ISO-IR-143':
  8648. return 'IEC_P27-1';
  8649. case 'CSISO49INIS':
  8650. case 'INIS':
  8651. case 'ISO-IR-49':
  8652. return 'INIS';
  8653. case 'CSISO50INIS8':
  8654. case 'INIS-8':
  8655. case 'ISO-IR-50':
  8656. return 'INIS-8';
  8657. case 'CSISO51INISCYRILLIC':
  8658. case 'INIS-CYRILLIC':
  8659. case 'ISO-IR-51':
  8660. return 'INIS-cyrillic';
  8661. case 'CSINVARIANT':
  8662. case 'INVARIANT':
  8663. return 'INVARIANT';
  8664. case 'ISO-10646-J-1':
  8665. return 'ISO-10646-J-1';
  8666. case 'CSUNICODE':
  8667. case 'ISO-10646-UCS-2':
  8668. return 'ISO-10646-UCS-2';
  8669. case 'CSUCS4':
  8670. case 'ISO-10646-UCS-4':
  8671. return 'ISO-10646-UCS-4';
  8672. case 'CSUNICODEASCII':
  8673. case 'ISO-10646-UCS-BASIC':
  8674. return 'ISO-10646-UCS-Basic';
  8675. case 'CSISO10646UTF1':
  8676. case 'ISO-10646-UTF-1':
  8677. return 'ISO-10646-UTF-1';
  8678. case 'CSUNICODELATIN1':
  8679. case 'ISO-10646':
  8680. case 'ISO-10646-UNICODE-LATIN1':
  8681. return 'ISO-10646-Unicode-Latin1';
  8682. case 'CSISO115481':
  8683. case 'ISO-11548-1':
  8684. case 'ISO_11548-1':
  8685. case 'ISO_TR_11548-1':
  8686. return 'ISO-11548-1';
  8687. case 'ISO-2022-CN':
  8688. return 'ISO-2022-CN';
  8689. case 'ISO-2022-CN-EXT':
  8690. return 'ISO-2022-CN-EXT';
  8691. case 'CSISO2022JP':
  8692. case 'ISO-2022-JP':
  8693. return 'ISO-2022-JP';
  8694. case 'CSISO2022JP2':
  8695. case 'ISO-2022-JP-2':
  8696. return 'ISO-2022-JP-2';
  8697. case 'CSISO2022KR':
  8698. case 'ISO-2022-KR':
  8699. return 'ISO-2022-KR';
  8700. case 'CSWINDOWS30LATIN1':
  8701. case 'ISO-8859-1-WINDOWS-3.0-LATIN-1':
  8702. return 'ISO-8859-1-Windows-3.0-Latin-1';
  8703. case 'CSWINDOWS31LATIN1':
  8704. case 'ISO-8859-1-WINDOWS-3.1-LATIN-1':
  8705. return 'ISO-8859-1-Windows-3.1-Latin-1';
  8706. case 'CSISOLATIN6':
  8707. case 'ISO-8859-10':
  8708. case 'ISO-IR-157':
  8709. case 'ISO_8859-10:1992':
  8710. case 'L6':
  8711. case 'LATIN6':
  8712. return 'ISO-8859-10';
  8713. case 'ISO-8859-13':
  8714. return 'ISO-8859-13';
  8715. case 'ISO-8859-14':
  8716. case 'ISO-CELTIC':
  8717. case 'ISO-IR-199':
  8718. case 'ISO_8859-14':
  8719. case 'ISO_8859-14:1998':
  8720. case 'L8':
  8721. case 'LATIN8':
  8722. return 'ISO-8859-14';
  8723. case 'ISO-8859-15':
  8724. case 'ISO_8859-15':
  8725. case 'LATIN-9':
  8726. return 'ISO-8859-15';
  8727. case 'ISO-8859-16':
  8728. case 'ISO-IR-226':
  8729. case 'ISO_8859-16':
  8730. case 'ISO_8859-16:2001':
  8731. case 'L10':
  8732. case 'LATIN10':
  8733. return 'ISO-8859-16';
  8734. case 'CSISOLATIN2':
  8735. case 'ISO-8859-2':
  8736. case 'ISO-IR-101':
  8737. case 'ISO_8859-2':
  8738. case 'ISO_8859-2:1987':
  8739. case 'L2':
  8740. case 'LATIN2':
  8741. return 'ISO-8859-2';
  8742. case 'CSWINDOWS31LATIN2':
  8743. case 'ISO-8859-2-WINDOWS-LATIN-2':
  8744. return 'ISO-8859-2-Windows-Latin-2';
  8745. case 'CSISOLATIN3':
  8746. case 'ISO-8859-3':
  8747. case 'ISO-IR-109':
  8748. case 'ISO_8859-3':
  8749. case 'ISO_8859-3:1988':
  8750. case 'L3':
  8751. case 'LATIN3':
  8752. return 'ISO-8859-3';
  8753. case 'CSISOLATIN4':
  8754. case 'ISO-8859-4':
  8755. case 'ISO-IR-110':
  8756. case 'ISO_8859-4':
  8757. case 'ISO_8859-4:1988':
  8758. case 'L4':
  8759. case 'LATIN4':
  8760. return 'ISO-8859-4';
  8761. case 'CSISOLATINCYRILLIC':
  8762. case 'CYRILLIC':
  8763. case 'ISO-8859-5':
  8764. case 'ISO-IR-144':
  8765. case 'ISO_8859-5':
  8766. case 'ISO_8859-5:1988':
  8767. return 'ISO-8859-5';
  8768. case 'ARABIC':
  8769. case 'ASMO-708':
  8770. case 'CSISOLATINARABIC':
  8771. case 'ECMA-114':
  8772. case 'ISO-8859-6':
  8773. case 'ISO-IR-127':
  8774. case 'ISO_8859-6':
  8775. case 'ISO_8859-6:1987':
  8776. return 'ISO-8859-6';
  8777. case 'CSISO88596E':
  8778. case 'ISO-8859-6-E':
  8779. case 'ISO_8859-6-E':
  8780. return 'ISO-8859-6-E';
  8781. case 'CSISO88596I':
  8782. case 'ISO-8859-6-I':
  8783. case 'ISO_8859-6-I':
  8784. return 'ISO-8859-6-I';
  8785. case 'CSISOLATINGREEK':
  8786. case 'ECMA-118':
  8787. case 'ELOT_928':
  8788. case 'GREEK':
  8789. case 'GREEK8':
  8790. case 'ISO-8859-7':
  8791. case 'ISO-IR-126':
  8792. case 'ISO_8859-7':
  8793. case 'ISO_8859-7:1987':
  8794. return 'ISO-8859-7';
  8795. case 'CSISOLATINHEBREW':
  8796. case 'HEBREW':
  8797. case 'ISO-8859-8':
  8798. case 'ISO-IR-138':
  8799. case 'ISO_8859-8':
  8800. case 'ISO_8859-8:1988':
  8801. return 'ISO-8859-8';
  8802. case 'CSISO88598E':
  8803. case 'ISO-8859-8-E':
  8804. case 'ISO_8859-8-E':
  8805. return 'ISO-8859-8-E';
  8806. case 'CSISO88598I':
  8807. case 'ISO-8859-8-I':
  8808. case 'ISO_8859-8-I':
  8809. return 'ISO-8859-8-I';
  8810. case 'CSISOLATIN5':
  8811. case 'ISO-8859-9':
  8812. case 'ISO-IR-148':
  8813. case 'ISO_8859-9':
  8814. case 'ISO_8859-9:1989':
  8815. case 'L5':
  8816. case 'LATIN5':
  8817. return 'ISO-8859-9';
  8818. case 'CSWINDOWS31LATIN5':
  8819. case 'ISO-8859-9-WINDOWS-LATIN-5':
  8820. return 'ISO-8859-9-Windows-Latin-5';
  8821. case 'CSUNICODEIBM1261':
  8822. case 'ISO-UNICODE-IBM-1261':
  8823. return 'ISO-Unicode-IBM-1261';
  8824. case 'CSUNICODEIBM1264':
  8825. case 'ISO-UNICODE-IBM-1264':
  8826. return 'ISO-Unicode-IBM-1264';
  8827. case 'CSUNICODEIBM1265':
  8828. case 'ISO-UNICODE-IBM-1265':
  8829. return 'ISO-Unicode-IBM-1265';
  8830. case 'CSUNICODEIBM1268':
  8831. case 'ISO-UNICODE-IBM-1268':
  8832. return 'ISO-Unicode-IBM-1268';
  8833. case 'CSUNICODEIBM1276':
  8834. case 'ISO-UNICODE-IBM-1276':
  8835. return 'ISO-Unicode-IBM-1276';
  8836. case 'CSISO10367BOX':
  8837. case 'ISO-IR-155':
  8838. case 'ISO_10367-BOX':
  8839. return 'ISO_10367-box';
  8840. case 'CSISO2033':
  8841. case 'E13B':
  8842. case 'ISO-IR-98':
  8843. case 'ISO_2033-1983':
  8844. return 'ISO_2033-1983';
  8845. case 'CSISO5427CYRILLIC':
  8846. case 'ISO-IR-37':
  8847. case 'ISO_5427':
  8848. return 'ISO_5427';
  8849. case 'ISO-IR-54':
  8850. case 'ISO5427CYRILLIC1981':
  8851. case 'ISO_5427:1981':
  8852. return 'ISO_5427:1981';
  8853. case 'CSISO5428GREEK':
  8854. case 'ISO-IR-55':
  8855. case 'ISO_5428:1980':
  8856. return 'ISO_5428:1980';
  8857. case 'CSISO646BASIC1983':
  8858. case 'ISO_646.BASIC:1983':
  8859. case 'REF':
  8860. return 'ISO_646.basic:1983';
  8861. case 'CSISO2INTLREFVERSION':
  8862. case 'IRV':
  8863. case 'ISO-IR-2':
  8864. case 'ISO_646.IRV:1983':
  8865. return 'ISO_646.irv:1983';
  8866. case 'CSISO6937ADD':
  8867. case 'ISO-IR-152':
  8868. case 'ISO_6937-2-25':
  8869. return 'ISO_6937-2-25';
  8870. case 'CSISOTEXTCOMM':
  8871. case 'ISO-IR-142':
  8872. case 'ISO_6937-2-ADD':
  8873. return 'ISO_6937-2-add';
  8874. case 'CSISO8859SUPP':
  8875. case 'ISO-IR-154':
  8876. case 'ISO_8859-SUPP':
  8877. case 'LATIN1-2-5':
  8878. return 'ISO_8859-supp';
  8879. case 'CSISO15ITALIAN':
  8880. case 'ISO-IR-15':
  8881. case 'ISO646-IT':
  8882. case 'IT':
  8883. return 'IT';
  8884. case 'CSISO13JISC6220JP':
  8885. case 'ISO-IR-13':
  8886. case 'JIS_C6220-1969':
  8887. case 'JIS_C6220-1969-JP':
  8888. case 'KATAKANA':
  8889. case 'X0201-7':
  8890. return 'JIS_C6220-1969-jp';
  8891. case 'CSISO14JISC6220RO':
  8892. case 'ISO-IR-14':
  8893. case 'ISO646-JP':
  8894. case 'JIS_C6220-1969-RO':
  8895. case 'JP':
  8896. return 'JIS_C6220-1969-ro';
  8897. case 'CSISO42JISC62261978':
  8898. case 'ISO-IR-42':
  8899. case 'JIS_C6226-1978':
  8900. return 'JIS_C6226-1978';
  8901. case 'CSISO87JISX0208':
  8902. case 'ISO-IR-87':
  8903. case 'JIS_C6226-1983':
  8904. case 'JIS_X0208-1983':
  8905. case 'X0208':
  8906. return 'JIS_C6226-1983';
  8907. case 'CSISO91JISC62291984A':
  8908. case 'ISO-IR-91':
  8909. case 'JIS_C6229-1984-A':
  8910. case 'JP-OCR-A':
  8911. return 'JIS_C6229-1984-a';
  8912. case 'CSISO92JISC62991984B':
  8913. case 'ISO-IR-92':
  8914. case 'ISO646-JP-OCR-B':
  8915. case 'JIS_C6229-1984-B':
  8916. case 'JP-OCR-B':
  8917. return 'JIS_C6229-1984-b';
  8918. case 'CSISO93JIS62291984BADD':
  8919. case 'ISO-IR-93':
  8920. case 'JIS_C6229-1984-B-ADD':
  8921. case 'JP-OCR-B-ADD':
  8922. return 'JIS_C6229-1984-b-add';
  8923. case 'CSISO94JIS62291984HAND':
  8924. case 'ISO-IR-94':
  8925. case 'JIS_C6229-1984-HAND':
  8926. case 'JP-OCR-HAND':
  8927. return 'JIS_C6229-1984-hand';
  8928. case 'CSISO95JIS62291984HANDADD':
  8929. case 'ISO-IR-95':
  8930. case 'JIS_C6229-1984-HAND-ADD':
  8931. case 'JP-OCR-HAND-ADD':
  8932. return 'JIS_C6229-1984-hand-add';
  8933. case 'CSISO96JISC62291984KANA':
  8934. case 'ISO-IR-96':
  8935. case 'JIS_C6229-1984-KANA':
  8936. return 'JIS_C6229-1984-kana';
  8937. case 'CSJISENCODING':
  8938. case 'JIS_ENCODING':
  8939. return 'JIS_Encoding';
  8940. case 'CSHALFWIDTHKATAKANA':
  8941. case 'JIS_X0201':
  8942. case 'X0201':
  8943. return 'JIS_X0201';
  8944. case 'CSISO159JISX02121990':
  8945. case 'ISO-IR-159':
  8946. case 'JIS_X0212-1990':
  8947. case 'X0212':
  8948. return 'JIS_X0212-1990';
  8949. case 'CSISO141JUSIB1002':
  8950. case 'ISO-IR-141':
  8951. case 'ISO646-YU':
  8952. case 'JS':
  8953. case 'JUS_I.B1.002':
  8954. case 'YU':
  8955. return 'JUS_I.B1.002';
  8956. case 'CSISO147MACEDONIAN':
  8957. case 'ISO-IR-147':
  8958. case 'JUS_I.B1.003-MAC':
  8959. case 'MACEDONIAN':
  8960. return 'JUS_I.B1.003-mac';
  8961. case 'CSISO146SERBIAN':
  8962. case 'ISO-IR-146':
  8963. case 'JUS_I.B1.003-SERB':
  8964. case 'SERBIAN':
  8965. return 'JUS_I.B1.003-serb';
  8966. case 'KOI7-SWITCHED':
  8967. return 'KOI7-switched';
  8968. case 'CSKOI8R':
  8969. case 'KOI8-R':
  8970. return 'KOI8-R';
  8971. case 'KOI8-U':
  8972. return 'KOI8-U';
  8973. case 'CSKSC5636':
  8974. case 'ISO646-KR':
  8975. case 'KSC5636':
  8976. return 'KSC5636';
  8977. case 'CSKSC56011987':
  8978. case 'ISO-IR-149':
  8979. case 'KOREAN':
  8980. case 'KSC_5601':
  8981. case 'KS_C_5601-1987':
  8982. case 'KS_C_5601-1989':
  8983. return 'KS_C_5601-1987';
  8984. case 'CSKZ1048':
  8985. case 'KZ-1048':
  8986. case 'RK1048':
  8987. case 'STRK1048-2002':
  8988. return 'KZ-1048';
  8989. case 'CSISO27LATINGREEK1':
  8990. case 'ISO-IR-27':
  8991. case 'LATIN-GREEK-1':
  8992. return 'Latin-greek-1';
  8993. case 'CSMNEM':
  8994. case 'MNEM':
  8995. return 'MNEM';
  8996. case 'CSMNEMONIC':
  8997. case 'MNEMONIC':
  8998. return 'MNEMONIC';
  8999. case 'CSISO86HUNGARIAN':
  9000. case 'HU':
  9001. case 'ISO-IR-86':
  9002. case 'ISO646-HU':
  9003. case 'MSZ_7795.3':
  9004. return 'MSZ_7795.3';
  9005. case 'CSMICROSOFTPUBLISHING':
  9006. case 'MICROSOFT-PUBLISHING':
  9007. return 'Microsoft-Publishing';
  9008. case 'CSNATSDANO':
  9009. case 'ISO-IR-9-1':
  9010. case 'NATS-DANO':
  9011. return 'NATS-DANO';
  9012. case 'CSNATSDANOADD':
  9013. case 'ISO-IR-9-2':
  9014. case 'NATS-DANO-ADD':
  9015. return 'NATS-DANO-ADD';
  9016. case 'CSNATSSEFI':
  9017. case 'ISO-IR-8-1':
  9018. case 'NATS-SEFI':
  9019. return 'NATS-SEFI';
  9020. case 'CSNATSSEFIADD':
  9021. case 'ISO-IR-8-2':
  9022. case 'NATS-SEFI-ADD':
  9023. return 'NATS-SEFI-ADD';
  9024. case 'CSISO151CUBA':
  9025. case 'CUBA':
  9026. case 'ISO-IR-151':
  9027. case 'ISO646-CU':
  9028. case 'NC_NC00-10:81':
  9029. return 'NC_NC00-10:81';
  9030. case 'CSISO69FRENCH':
  9031. case 'FR':
  9032. case 'ISO-IR-69':
  9033. case 'ISO646-FR':
  9034. case 'NF_Z_62-010':
  9035. return 'NF_Z_62-010';
  9036. case 'CSISO25FRENCH':
  9037. case 'ISO-IR-25':
  9038. case 'ISO646-FR1':
  9039. case 'NF_Z_62-010_(1973)':
  9040. return 'NF_Z_62-010_(1973)';
  9041. case 'CSISO60DANISHNORWEGIAN':
  9042. case 'CSISO60NORWEGIAN1':
  9043. case 'ISO-IR-60':
  9044. case 'ISO646-NO':
  9045. case 'NO':
  9046. case 'NS_4551-1':
  9047. return 'NS_4551-1';
  9048. case 'CSISO61NORWEGIAN2':
  9049. case 'ISO-IR-61':
  9050. case 'ISO646-NO2':
  9051. case 'NO2':
  9052. case 'NS_4551-2':
  9053. return 'NS_4551-2';
  9054. case 'OSD_EBCDIC_DF03_IRV':
  9055. return 'OSD_EBCDIC_DF03_IRV';
  9056. case 'OSD_EBCDIC_DF04_1':
  9057. return 'OSD_EBCDIC_DF04_1';
  9058. case 'OSD_EBCDIC_DF04_15':
  9059. return 'OSD_EBCDIC_DF04_15';
  9060. case 'CSPC8DANISHNORWEGIAN':
  9061. case 'PC8-DANISH-NORWEGIAN':
  9062. return 'PC8-Danish-Norwegian';
  9063. case 'CSPC8TURKISH':
  9064. case 'PC8-TURKISH':
  9065. return 'PC8-Turkish';
  9066. case 'CSISO16PORTUGUESE':
  9067. case 'ISO-IR-16':
  9068. case 'ISO646-PT':
  9069. case 'PT':
  9070. return 'PT';
  9071. case 'CSISO84PORTUGUESE2':
  9072. case 'ISO-IR-84':
  9073. case 'ISO646-PT2':
  9074. case 'PT2':
  9075. return 'PT2';
  9076. case 'CP154':
  9077. case 'CSPTCP154':
  9078. case 'CYRILLIC-ASIAN':
  9079. case 'PT154':
  9080. case 'PTCP154':
  9081. return 'PTCP154';
  9082. case 'SCSU':
  9083. return 'SCSU';
  9084. case 'CSISO10SWEDISH':
  9085. case 'FI':
  9086. case 'ISO-IR-10':
  9087. case 'ISO646-FI':
  9088. case 'ISO646-SE':
  9089. case 'SE':
  9090. case 'SEN_850200_B':
  9091. return 'SEN_850200_B';
  9092. case 'CSISO11SWEDISHFORNAMES':
  9093. case 'ISO-IR-11':
  9094. case 'ISO646-SE2':
  9095. case 'SE2':
  9096. case 'SEN_850200_C':
  9097. return 'SEN_850200_C';
  9098. case 'CSSHIFTJIS':
  9099. case 'MS_KANJI':
  9100. case 'SHIFT_JIS':
  9101. return 'Shift_JIS';
  9102. case 'CSISO128T101G2':
  9103. case 'ISO-IR-128':
  9104. case 'T.101-G2':
  9105. return 'T.101-G2';
  9106. case 'CSISO102T617BIT':
  9107. case 'ISO-IR-102':
  9108. case 'T.61-7BIT':
  9109. return 'T.61-7bit';
  9110. case 'CSISO103T618BIT':
  9111. case 'ISO-IR-103':
  9112. case 'T.61':
  9113. case 'T.61-8BIT':
  9114. return 'T.61-8bit';
  9115. case 'CSTSCII':
  9116. case 'TSCII':
  9117. return 'TSCII';
  9118. case 'CSUNICODE11':
  9119. case 'UNICODE-1-1':
  9120. return 'UNICODE-1-1';
  9121. case 'CSUNICODE11UTF7':
  9122. case 'UNICODE-1-1-UTF-7':
  9123. return 'UNICODE-1-1-UTF-7';
  9124. case 'CSUNKNOWN8BIT':
  9125. case 'UNKNOWN-8BIT':
  9126. return 'UNKNOWN-8BIT';
  9127. case 'ANSI':
  9128. case 'ANSI_X3.4-1968':
  9129. case 'ANSI_X3.4-1986':
  9130. case 'ASCII':
  9131. case 'CP367':
  9132. case 'CSASCII':
  9133. case 'IBM367':
  9134. case 'ISO-IR-6':
  9135. case 'ISO646-US':
  9136. case 'ISO_646.IRV:1991':
  9137. case 'US':
  9138. case 'US-ASCII':
  9139. return 'US-ASCII';
  9140. case 'UTF-16':
  9141. return 'UTF-16';
  9142. case 'UTF-16BE':
  9143. return 'UTF-16BE';
  9144. case 'UTF-16LE':
  9145. return 'UTF-16LE';
  9146. case 'UTF-32':
  9147. return 'UTF-32';
  9148. case 'UTF-32BE':
  9149. return 'UTF-32BE';
  9150. case 'UTF-32LE':
  9151. return 'UTF-32LE';
  9152. case 'UTF-7':
  9153. return 'UTF-7';
  9154. case 'UTF-8':
  9155. return 'UTF-8';
  9156. case 'CSVIQR':
  9157. case 'VIQR':
  9158. return 'VIQR';
  9159. case 'CSVISCII':
  9160. case 'VISCII':
  9161. return 'VISCII';
  9162. case 'CSVENTURAINTERNATIONAL':
  9163. case 'VENTURA-INTERNATIONAL':
  9164. return 'Ventura-International';
  9165. case 'CSVENTURAMATH':
  9166. case 'VENTURA-MATH':
  9167. return 'Ventura-Math';
  9168. case 'CSVENTURAUS':
  9169. case 'VENTURA-US':
  9170. return 'Ventura-US';
  9171. case 'CSWINDOWS31J':
  9172. case 'WINDOWS-31J':
  9173. return 'Windows-31J';
  9174. case 'CSDKUS':
  9175. case 'DK-US':
  9176. return 'dk-us';
  9177. case 'CSISO150':
  9178. case 'CSISO150GREEKCCITT':
  9179. case 'GREEK-CCITT':
  9180. case 'ISO-IR-150':
  9181. return 'greek-ccitt';
  9182. case 'CSISO88GREEK7':
  9183. case 'GREEK7':
  9184. case 'ISO-IR-88':
  9185. return 'greek7';
  9186. case 'CSISO18GREEK7OLD':
  9187. case 'GREEK7-OLD':
  9188. case 'ISO-IR-18':
  9189. return 'greek7-old';
  9190. case 'CSHPROMAN8':
  9191. case 'HP-ROMAN8':
  9192. case 'R8':
  9193. case 'ROMAN8':
  9194. return 'hp-roman8';
  9195. case 'CSISO90':
  9196. case 'ISO-IR-90':
  9197. return 'iso-ir-90';
  9198. case 'CSISO19LATINGREEK':
  9199. case 'ISO-IR-19':
  9200. case 'LATIN-GREEK':
  9201. return 'latin-greek';
  9202. case 'CSISO158LAP':
  9203. case 'ISO-IR-158':
  9204. case 'LAP':
  9205. case 'LATIN-LAP':
  9206. return 'latin-lap';
  9207. case 'CSMACINTOSH':
  9208. case 'MAC':
  9209. case 'MACINTOSH':
  9210. return 'macintosh';
  9211. case 'CSUSDK':
  9212. case 'US-DK':
  9213. return 'us-dk';
  9214. case 'CSISO70VIDEOTEXSUPP1':
  9215. case 'ISO-IR-70':
  9216. case 'VIDEOTEX-SUPPL':
  9217. return 'videotex-suppl';
  9218. case 'WINDOWS-1250':
  9219. return 'windows-1250';
  9220. case 'WINDOWS-1251':
  9221. return 'windows-1251';
  9222. case 'CP819':
  9223. case 'CSISOLATIN1':
  9224. case 'IBM819':
  9225. case 'ISO-8859-1':
  9226. case 'ISO-IR-100':
  9227. case 'ISO_8859-1':
  9228. case 'ISO_8859-1:1987':
  9229. case 'L1':
  9230. case 'LATIN1':
  9231. case 'WINDOWS-1252':
  9232. return 'windows-1252';
  9233. case 'WINDOWS-1253':
  9234. return 'windows-1253';
  9235. case 'WINDOWS-1254':
  9236. return 'windows-1254';
  9237. case 'WINDOWS-1255':
  9238. return 'windows-1255';
  9239. case 'WINDOWS-1256':
  9240. return 'windows-1256';
  9241. case 'WINDOWS-1257':
  9242. return 'windows-1257';
  9243. case 'WINDOWS-1258':
  9244. return 'windows-1258';
  9245. default:
  9246. return $encoding;
  9247. }
  9248. }
  9249. function get_curl_version()
  9250. {
  9251. if (is_array($curl = curl_version()))
  9252. {
  9253. $curl = $curl['version'];
  9254. }
  9255. elseif (substr($curl, 0, 5) == 'curl/')
  9256. {
  9257. $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
  9258. }
  9259. elseif (substr($curl, 0, 8) == 'libcurl/')
  9260. {
  9261. $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
  9262. }
  9263. else
  9264. {
  9265. $curl = 0;
  9266. }
  9267. return $curl;
  9268. }
  9269. function is_subclass_of($class1, $class2)
  9270. {
  9271. if (func_num_args() != 2)
  9272. {
  9273. trigger_error('Wrong parameter count for SimplePie_Misc::is_subclass_of()', E_USER_WARNING);
  9274. }
  9275. elseif (version_compare(PHP_VERSION, '5.0.3', '>=') || is_object($class1))
  9276. {
  9277. return is_subclass_of($class1, $class2);
  9278. }
  9279. elseif (is_string($class1) && is_string($class2))
  9280. {
  9281. if (class_exists($class1))
  9282. {
  9283. if (class_exists($class2))
  9284. {
  9285. $class2 = strtolower($class2);
  9286. while ($class1 = strtolower(get_parent_class($class1)))
  9287. {
  9288. if ($class1 == $class2)
  9289. {
  9290. return true;
  9291. }
  9292. }
  9293. }
  9294. }
  9295. else
  9296. {
  9297. trigger_error('Unknown class passed as parameter', E_USER_WARNNG);
  9298. }
  9299. }
  9300. return false;
  9301. }
  9302. /**
  9303. * Strip HTML comments
  9304. *
  9305. * @access public
  9306. * @param string $data Data to strip comments from
  9307. * @return string Comment stripped string
  9308. */
  9309. function strip_comments($data)
  9310. {
  9311. $output = '';
  9312. while (($start = strpos($data, '<!--')) !== false)
  9313. {
  9314. $output .= substr($data, 0, $start);
  9315. if (($end = strpos($data, '-->', $start)) !== false)
  9316. {
  9317. $data = substr_replace($data, '', 0, $end + 3);
  9318. }
  9319. else
  9320. {
  9321. $data = '';
  9322. }
  9323. }
  9324. return $output . $data;
  9325. }
  9326. function parse_date($dt)
  9327. {
  9328. $parser = SimplePie_Parse_Date::get();
  9329. return $parser->parse($dt);
  9330. }
  9331. /**
  9332. * Decode HTML entities
  9333. *
  9334. * @static
  9335. * @access public
  9336. * @param string $data Input data
  9337. * @return string Output data
  9338. */
  9339. function entities_decode($data)
  9340. {
  9341. $decoder = new SimplePie_Decode_HTML_Entities($data);
  9342. return $decoder->parse();
  9343. }
  9344. /**
  9345. * Remove RFC822 comments
  9346. *
  9347. * @access public
  9348. * @param string $data Data to strip comments from
  9349. * @return string Comment stripped string
  9350. */
  9351. function uncomment_rfc822($string)
  9352. {
  9353. $string = (string) $string;
  9354. $position = 0;
  9355. $length = strlen($string);
  9356. $depth = 0;
  9357. $output = '';
  9358. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  9359. {
  9360. $output .= substr($string, $position, $pos - $position);
  9361. $position = $pos + 1;
  9362. if ($string[$pos - 1] !== '\\')
  9363. {
  9364. $depth++;
  9365. while ($depth && $position < $length)
  9366. {
  9367. $position += strcspn($string, '()', $position);
  9368. if ($string[$position - 1] === '\\')
  9369. {
  9370. $position++;
  9371. continue;
  9372. }
  9373. elseif (isset($string[$position]))
  9374. {
  9375. switch ($string[$position])
  9376. {
  9377. case '(':
  9378. $depth++;
  9379. break;
  9380. case ')':
  9381. $depth--;
  9382. break;
  9383. }
  9384. $position++;
  9385. }
  9386. else
  9387. {
  9388. break;
  9389. }
  9390. }
  9391. }
  9392. else
  9393. {
  9394. $output .= '(';
  9395. }
  9396. }
  9397. $output .= substr($string, $position);
  9398. return $output;
  9399. }
  9400. function parse_mime($mime)
  9401. {
  9402. if (($pos = strpos($mime, ';')) === false)
  9403. {
  9404. return trim($mime);
  9405. }
  9406. else
  9407. {
  9408. return trim(substr($mime, 0, $pos));
  9409. }
  9410. }
  9411. function htmlspecialchars_decode($string, $quote_style)
  9412. {
  9413. if (function_exists('htmlspecialchars_decode'))
  9414. {
  9415. return htmlspecialchars_decode($string, $quote_style);
  9416. }
  9417. else
  9418. {
  9419. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
  9420. }
  9421. }
  9422. function atom_03_construct_type($attribs)
  9423. {
  9424. if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) == 'base64'))
  9425. {
  9426. $mode = SIMPLEPIE_CONSTRUCT_BASE64;
  9427. }
  9428. else
  9429. {
  9430. $mode = SIMPLEPIE_CONSTRUCT_NONE;
  9431. }
  9432. if (isset($attribs['']['type']))
  9433. {
  9434. switch (strtolower(trim($attribs['']['type'])))
  9435. {
  9436. case 'text':
  9437. case 'text/plain':
  9438. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  9439. case 'html':
  9440. case 'text/html':
  9441. return SIMPLEPIE_CONSTRUCT_HTML | $mode;
  9442. case 'xhtml':
  9443. case 'application/xhtml+xml':
  9444. return SIMPLEPIE_CONSTRUCT_XHTML | $mode;
  9445. default:
  9446. return SIMPLEPIE_CONSTRUCT_NONE | $mode;
  9447. }
  9448. }
  9449. else
  9450. {
  9451. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  9452. }
  9453. }
  9454. function atom_10_construct_type($attribs)
  9455. {
  9456. if (isset($attribs['']['type']))
  9457. {
  9458. switch (strtolower(trim($attribs['']['type'])))
  9459. {
  9460. case 'text':
  9461. return SIMPLEPIE_CONSTRUCT_TEXT;
  9462. case 'html':
  9463. return SIMPLEPIE_CONSTRUCT_HTML;
  9464. case 'xhtml':
  9465. return SIMPLEPIE_CONSTRUCT_XHTML;
  9466. default:
  9467. return SIMPLEPIE_CONSTRUCT_NONE;
  9468. }
  9469. }
  9470. return SIMPLEPIE_CONSTRUCT_TEXT;
  9471. }
  9472. function atom_10_content_construct_type($attribs)
  9473. {
  9474. if (isset($attribs['']['type']))
  9475. {
  9476. $type = strtolower(trim($attribs['']['type']));
  9477. switch ($type)
  9478. {
  9479. case 'text':
  9480. return SIMPLEPIE_CONSTRUCT_TEXT;
  9481. case 'html':
  9482. return SIMPLEPIE_CONSTRUCT_HTML;
  9483. case 'xhtml':
  9484. return SIMPLEPIE_CONSTRUCT_XHTML;
  9485. }
  9486. if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) == 'text/')
  9487. {
  9488. return SIMPLEPIE_CONSTRUCT_NONE;
  9489. }
  9490. else
  9491. {
  9492. return SIMPLEPIE_CONSTRUCT_BASE64;
  9493. }
  9494. }
  9495. else
  9496. {
  9497. return SIMPLEPIE_CONSTRUCT_TEXT;
  9498. }
  9499. }
  9500. function is_isegment_nz_nc($string)
  9501. {
  9502. return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string);
  9503. }
  9504. function space_seperated_tokens($string)
  9505. {
  9506. $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
  9507. $string_length = strlen($string);
  9508. $position = strspn($string, $space_characters);
  9509. $tokens = array();
  9510. while ($position < $string_length)
  9511. {
  9512. $len = strcspn($string, $space_characters, $position);
  9513. $tokens[] = substr($string, $position, $len);
  9514. $position += $len;
  9515. $position += strspn($string, $space_characters, $position);
  9516. }
  9517. return $tokens;
  9518. }
  9519. function array_unique($array)
  9520. {
  9521. if (version_compare(PHP_VERSION, '5.2', '>='))
  9522. {
  9523. return array_unique($array);
  9524. }
  9525. else
  9526. {
  9527. $array = (array) $array;
  9528. $new_array = array();
  9529. $new_array_strings = array();
  9530. foreach ($array as $key => $value)
  9531. {
  9532. if (is_object($value))
  9533. {
  9534. if (method_exists($value, '__toString'))
  9535. {
  9536. $cmp = $value->__toString();
  9537. }
  9538. else
  9539. {
  9540. trigger_error('Object of class ' . get_class($value) . ' could not be converted to string', E_USER_ERROR);
  9541. }
  9542. }
  9543. elseif (is_array($value))
  9544. {
  9545. $cmp = (string) reset($value);
  9546. }
  9547. else
  9548. {
  9549. $cmp = (string) $value;
  9550. }
  9551. if (!in_array($cmp, $new_array_strings))
  9552. {
  9553. $new_array[$key] = $value;
  9554. $new_array_strings[] = $cmp;
  9555. }
  9556. }
  9557. return $new_array;
  9558. }
  9559. }
  9560. /**
  9561. * Converts a unicode codepoint to a UTF-8 character
  9562. *
  9563. * @static
  9564. * @access public
  9565. * @param int $codepoint Unicode codepoint
  9566. * @return string UTF-8 character
  9567. */
  9568. function codepoint_to_utf8($codepoint)
  9569. {
  9570. static $cache = array();
  9571. $codepoint = (int) $codepoint;
  9572. if (isset($cache[$codepoint]))
  9573. {
  9574. return $cache[$codepoint];
  9575. }
  9576. elseif ($codepoint < 0)
  9577. {
  9578. return $cache[$codepoint] = false;
  9579. }
  9580. else if ($codepoint <= 0x7f)
  9581. {
  9582. return $cache[$codepoint] = chr($codepoint);
  9583. }
  9584. else if ($codepoint <= 0x7ff)
  9585. {
  9586. return $cache[$codepoint] = chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
  9587. }
  9588. else if ($codepoint <= 0xffff)
  9589. {
  9590. return $cache[$codepoint] = chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9591. }
  9592. else if ($codepoint <= 0x10ffff)
  9593. {
  9594. return $cache[$codepoint] = chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  9595. }
  9596. else
  9597. {
  9598. // U+FFFD REPLACEMENT CHARACTER
  9599. return $cache[$codepoint] = "\xEF\xBF\xBD";
  9600. }
  9601. }
  9602. /**
  9603. * Re-implementation of PHP 5's stripos()
  9604. *
  9605. * Returns the numeric position of the first occurrence of needle in the
  9606. * haystack string.
  9607. *
  9608. * @static
  9609. * @access string
  9610. * @param object $haystack
  9611. * @param string $needle Note that the needle may be a string of one or more
  9612. * characters. If needle is not a string, it is converted to an integer
  9613. * and applied as the ordinal value of a character.
  9614. * @param int $offset The optional offset parameter allows you to specify which
  9615. * character in haystack to start searching. The position returned is still
  9616. * relative to the beginning of haystack.
  9617. * @return bool If needle is not found, stripos() will return boolean false.
  9618. */
  9619. function stripos($haystack, $needle, $offset = 0)
  9620. {
  9621. if (function_exists('stripos'))
  9622. {
  9623. return stripos($haystack, $needle, $offset);
  9624. }
  9625. else
  9626. {
  9627. if (is_string($needle))
  9628. {
  9629. $needle = strtolower($needle);
  9630. }
  9631. elseif (is_int($needle) || is_bool($needle) || is_double($needle))
  9632. {
  9633. $needle = strtolower(chr($needle));
  9634. }
  9635. else
  9636. {
  9637. trigger_error('needle is not a string or an integer', E_USER_WARNING);
  9638. return false;
  9639. }
  9640. return strpos(strtolower($haystack), $needle, $offset);
  9641. }
  9642. }
  9643. /**
  9644. * Similar to parse_str()
  9645. *
  9646. * Returns an associative array of name/value pairs, where the value is an
  9647. * array of values that have used the same name
  9648. *
  9649. * @static
  9650. * @access string
  9651. * @param string $str The input string.
  9652. * @return array
  9653. */
  9654. function parse_str($str)
  9655. {
  9656. $return = array();
  9657. $str = explode('&', $str);
  9658. foreach ($str as $section)
  9659. {
  9660. if (strpos($section, '=') !== false)
  9661. {
  9662. list($name, $value) = explode('=', $section, 2);
  9663. $return[urldecode($name)][] = urldecode($value);
  9664. }
  9665. else
  9666. {
  9667. $return[urldecode($section)][] = null;
  9668. }
  9669. }
  9670. return $return;
  9671. }
  9672. /**
  9673. * Detect XML encoding, as per XML 1.0 Appendix F.1
  9674. *
  9675. * @todo Add support for EBCDIC
  9676. * @param string $data XML data
  9677. * @return array Possible encodings
  9678. */
  9679. function xml_encoding($data)
  9680. {
  9681. // UTF-32 Big Endian BOM
  9682. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  9683. {
  9684. $encoding[] = 'UTF-32BE';
  9685. }
  9686. // UTF-32 Little Endian BOM
  9687. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  9688. {
  9689. $encoding[] = 'UTF-32LE';
  9690. }
  9691. // UTF-16 Big Endian BOM
  9692. elseif (substr($data, 0, 2) === "\xFE\xFF")
  9693. {
  9694. $encoding[] = 'UTF-16BE';
  9695. }
  9696. // UTF-16 Little Endian BOM
  9697. elseif (substr($data, 0, 2) === "\xFF\xFE")
  9698. {
  9699. $encoding[] = 'UTF-16LE';
  9700. }
  9701. // UTF-8 BOM
  9702. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  9703. {
  9704. $encoding[] = 'UTF-8';
  9705. }
  9706. // UTF-32 Big Endian Without BOM
  9707. elseif (substr($data, 0, 20) === "\x00\x00\x00\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C")
  9708. {
  9709. if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
  9710. {
  9711. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8'));
  9712. if ($parser->parse())
  9713. {
  9714. $encoding[] = $parser->encoding;
  9715. }
  9716. }
  9717. $encoding[] = 'UTF-32BE';
  9718. }
  9719. // UTF-32 Little Endian Without BOM
  9720. elseif (substr($data, 0, 20) === "\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C\x00\x00\x00")
  9721. {
  9722. if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
  9723. {
  9724. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8'));
  9725. if ($parser->parse())
  9726. {
  9727. $encoding[] = $parser->encoding;
  9728. }
  9729. }
  9730. $encoding[] = 'UTF-32LE';
  9731. }
  9732. // UTF-16 Big Endian Without BOM
  9733. elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
  9734. {
  9735. if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
  9736. {
  9737. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8'));
  9738. if ($parser->parse())
  9739. {
  9740. $encoding[] = $parser->encoding;
  9741. }
  9742. }
  9743. $encoding[] = 'UTF-16BE';
  9744. }
  9745. // UTF-16 Little Endian Without BOM
  9746. elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00")
  9747. {
  9748. if ($pos = strpos($data, "\x3F\x00\x3E\x00"))
  9749. {
  9750. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8'));
  9751. if ($parser->parse())
  9752. {
  9753. $encoding[] = $parser->encoding;
  9754. }
  9755. }
  9756. $encoding[] = 'UTF-16LE';
  9757. }
  9758. // US-ASCII (or superset)
  9759. elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C")
  9760. {
  9761. if ($pos = strpos($data, "\x3F\x3E"))
  9762. {
  9763. $parser = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5));
  9764. if ($parser->parse())
  9765. {
  9766. $encoding[] = $parser->encoding;
  9767. }
  9768. }
  9769. $encoding[] = 'UTF-8';
  9770. }
  9771. // Fallback to UTF-8
  9772. else
  9773. {
  9774. $encoding[] = 'UTF-8';
  9775. }
  9776. return $encoding;
  9777. }
  9778. }
  9779. /**
  9780. * Decode HTML Entities
  9781. *
  9782. * This implements HTML5 as of revision 967 (2007-06-28)
  9783. *
  9784. * @package SimplePie
  9785. */
  9786. class SimplePie_Decode_HTML_Entities
  9787. {
  9788. /**
  9789. * Data to be parsed
  9790. *
  9791. * @access private
  9792. * @var string
  9793. */
  9794. var $data = '';
  9795. /**
  9796. * Currently consumed bytes
  9797. *
  9798. * @access private
  9799. * @var string
  9800. */
  9801. var $consumed = '';
  9802. /**
  9803. * Position of the current byte being parsed
  9804. *
  9805. * @access private
  9806. * @var int
  9807. */
  9808. var $position = 0;
  9809. /**
  9810. * Create an instance of the class with the input data
  9811. *
  9812. * @access public
  9813. * @param string $data Input data
  9814. */
  9815. function SimplePie_Decode_HTML_Entities($data)
  9816. {
  9817. $this->data = $data;
  9818. }
  9819. /**
  9820. * Parse the input data
  9821. *
  9822. * @access public
  9823. * @return string Output data
  9824. */
  9825. function parse()
  9826. {
  9827. while (($this->position = strpos($this->data, '&', $this->position)) !== false)
  9828. {
  9829. $this->consume();
  9830. $this->entity();
  9831. $this->consumed = '';
  9832. }
  9833. return $this->data;
  9834. }
  9835. /**
  9836. * Consume the next byte
  9837. *
  9838. * @access private
  9839. * @return mixed The next byte, or false, if there is no more data
  9840. */
  9841. function consume()
  9842. {
  9843. if (isset($this->data[$this->position]))
  9844. {
  9845. $this->consumed .= $this->data[$this->position];
  9846. return $this->data[$this->position++];
  9847. }
  9848. else
  9849. {
  9850. $this->consumed = false;
  9851. return false;
  9852. }
  9853. }
  9854. /**
  9855. * Consume a range of characters
  9856. *
  9857. * @access private
  9858. * @param string $chars Characters to consume
  9859. * @return mixed A series of characters that match the range, or false
  9860. */
  9861. function consume_range($chars)
  9862. {
  9863. if ($len = strspn($this->data, $chars, $this->position))
  9864. {
  9865. $data = substr($this->data, $this->position, $len);
  9866. $this->consumed .= $data;
  9867. $this->position += $len;
  9868. return $data;
  9869. }
  9870. else
  9871. {
  9872. $this->consumed = false;
  9873. return false;
  9874. }
  9875. }
  9876. /**
  9877. * Unconsume one byte
  9878. *
  9879. * @access private
  9880. */
  9881. function unconsume()
  9882. {
  9883. $this->consumed = substr($this->consumed, 0, -1);
  9884. $this->position--;
  9885. }
  9886. /**
  9887. * Decode an entity
  9888. *
  9889. * @access private
  9890. */
  9891. function entity()
  9892. {
  9893. switch ($this->consume())
  9894. {
  9895. case "\x09":
  9896. case "\x0A":
  9897. case "\x0B":
  9898. case "\x0B":
  9899. case "\x0C":
  9900. case "\x20":
  9901. case "\x3C":
  9902. case "\x26":
  9903. case false:
  9904. break;
  9905. case "\x23":
  9906. switch ($this->consume())
  9907. {
  9908. case "\x78":
  9909. case "\x58":
  9910. $range = '0123456789ABCDEFabcdef';
  9911. $hex = true;
  9912. break;
  9913. default:
  9914. $range = '0123456789';
  9915. $hex = false;
  9916. $this->unconsume();
  9917. break;
  9918. }
  9919. if ($codepoint = $this->consume_range($range))
  9920. {
  9921. static $windows_1252_specials = array(0x0D => "\x0A", 0x80 => "\xE2\x82\xAC", 0x81 => "\xEF\xBF\xBD", 0x82 => "\xE2\x80\x9A", 0x83 => "\xC6\x92", 0x84 => "\xE2\x80\x9E", 0x85 => "\xE2\x80\xA6", 0x86 => "\xE2\x80\xA0", 0x87 => "\xE2\x80\xA1", 0x88 => "\xCB\x86", 0x89 => "\xE2\x80\xB0", 0x8A => "\xC5\xA0", 0x8B => "\xE2\x80\xB9", 0x8C => "\xC5\x92", 0x8D => "\xEF\xBF\xBD", 0x8E => "\xC5\xBD", 0x8F => "\xEF\xBF\xBD", 0x90 => "\xEF\xBF\xBD", 0x91 => "\xE2\x80\x98", 0x92 => "\xE2\x80\x99", 0x93 => "\xE2\x80\x9C", 0x94 => "\xE2\x80\x9D", 0x95 => "\xE2\x80\xA2", 0x96 => "\xE2\x80\x93", 0x97 => "\xE2\x80\x94", 0x98 => "\xCB\x9C", 0x99 => "\xE2\x84\xA2", 0x9A => "\xC5\xA1", 0x9B => "\xE2\x80\xBA", 0x9C => "\xC5\x93", 0x9D => "\xEF\xBF\xBD", 0x9E => "\xC5\xBE", 0x9F => "\xC5\xB8");
  9922. if ($hex)
  9923. {
  9924. $codepoint = hexdec($codepoint);
  9925. }
  9926. else
  9927. {
  9928. $codepoint = intval($codepoint);
  9929. }
  9930. if (isset($windows_1252_specials[$codepoint]))
  9931. {
  9932. $replacement = $windows_1252_specials[$codepoint];
  9933. }
  9934. else
  9935. {
  9936. $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
  9937. }
  9938. if ($this->consume() != ';')
  9939. {
  9940. $this->unconsume();
  9941. }
  9942. $consumed_length = strlen($this->consumed);
  9943. $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
  9944. $this->position += strlen($replacement) - $consumed_length;
  9945. }
  9946. break;
  9947. default:
  9948. static $entities = array('Aacute' => "\xC3\x81", 'aacute' => "\xC3\xA1", 'Aacute;' => "\xC3\x81", 'aacute;' => "\xC3\xA1", 'Acirc' => "\xC3\x82", 'acirc' => "\xC3\xA2", 'Acirc;' => "\xC3\x82", 'acirc;' => "\xC3\xA2", 'acute' => "\xC2\xB4", 'acute;' => "\xC2\xB4", 'AElig' => "\xC3\x86", 'aelig' => "\xC3\xA6", 'AElig;' => "\xC3\x86", 'aelig;' => "\xC3\xA6", 'Agrave' => "\xC3\x80", 'agrave' => "\xC3\xA0", 'Agrave;' => "\xC3\x80", 'agrave;' => "\xC3\xA0", 'alefsym;' => "\xE2\x84\xB5", 'Alpha;' => "\xCE\x91", 'alpha;' => "\xCE\xB1", 'AMP' => "\x26", 'amp' => "\x26", 'AMP;' => "\x26", 'amp;' => "\x26", 'and;' => "\xE2\x88\xA7", 'ang;' => "\xE2\x88\xA0", 'apos;' => "\x27", 'Aring' => "\xC3\x85", 'aring' => "\xC3\xA5", 'Aring;' => "\xC3\x85", 'aring;' => "\xC3\xA5", 'asymp;' => "\xE2\x89\x88", 'Atilde' => "\xC3\x83", 'atilde' => "\xC3\xA3", 'Atilde;' => "\xC3\x83", 'atilde;' => "\xC3\xA3", 'Auml' => "\xC3\x84", 'auml' => "\xC3\xA4", 'Auml;' => "\xC3\x84", 'auml;' => "\xC3\xA4", 'bdquo;' => "\xE2\x80\x9E", 'Beta;' => "\xCE\x92", 'beta;' => "\xCE\xB2", 'brvbar' => "\xC2\xA6", 'brvbar;' => "\xC2\xA6", 'bull;' => "\xE2\x80\xA2", 'cap;' => "\xE2\x88\xA9", 'Ccedil' => "\xC3\x87", 'ccedil' => "\xC3\xA7", 'Ccedil;' => "\xC3\x87", 'ccedil;' => "\xC3\xA7", 'cedil' => "\xC2\xB8", 'cedil;' => "\xC2\xB8", 'cent' => "\xC2\xA2", 'cent;' => "\xC2\xA2", 'Chi;' => "\xCE\xA7", 'chi;' => "\xCF\x87", 'circ;' => "\xCB\x86", 'clubs;' => "\xE2\x99\xA3", 'cong;' => "\xE2\x89\x85", 'COPY' => "\xC2\xA9", 'copy' => "\xC2\xA9", 'COPY;' => "\xC2\xA9", 'copy;' => "\xC2\xA9", 'crarr;' => "\xE2\x86\xB5", 'cup;' => "\xE2\x88\xAA", 'curren' => "\xC2\xA4", 'curren;' => "\xC2\xA4", 'Dagger;' => "\xE2\x80\xA1", 'dagger;' => "\xE2\x80\xA0", 'dArr;' => "\xE2\x87\x93", 'darr;' => "\xE2\x86\x93", 'deg' => "\xC2\xB0", 'deg;' => "\xC2\xB0", 'Delta;' => "\xCE\x94", 'delta;' => "\xCE\xB4", 'diams;' => "\xE2\x99\xA6", 'divide' => "\xC3\xB7", 'divide;' => "\xC3\xB7", 'Eacute' => "\xC3\x89", 'eacute' => "\xC3\xA9", 'Eacute;' => "\xC3\x89", 'eacute;' => "\xC3\xA9", 'Ecirc' => "\xC3\x8A", 'ecirc' => "\xC3\xAA", 'Ecirc;' => "\xC3\x8A", 'ecirc;' => "\xC3\xAA", 'Egrave' => "\xC3\x88", 'egrave' => "\xC3\xA8", 'Egrave;' => "\xC3\x88", 'egrave;' => "\xC3\xA8", 'empty;' => "\xE2\x88\x85", 'emsp;' => "\xE2\x80\x83", 'ensp;' => "\xE2\x80\x82", 'Epsilon;' => "\xCE\x95", 'epsilon;' => "\xCE\xB5", 'equiv;' => "\xE2\x89\xA1", 'Eta;' => "\xCE\x97", 'eta;' => "\xCE\xB7", 'ETH' => "\xC3\x90", 'eth' => "\xC3\xB0", 'ETH;' => "\xC3\x90", 'eth;' => "\xC3\xB0", 'Euml' => "\xC3\x8B", 'euml' => "\xC3\xAB", 'Euml;' => "\xC3\x8B", 'euml;' => "\xC3\xAB", 'euro;' => "\xE2\x82\xAC", 'exist;' => "\xE2\x88\x83", 'fnof;' => "\xC6\x92", 'forall;' => "\xE2\x88\x80", 'frac12' => "\xC2\xBD", 'frac12;' => "\xC2\xBD", 'frac14' => "\xC2\xBC", 'frac14;' => "\xC2\xBC", 'frac34' => "\xC2\xBE", 'frac34;' => "\xC2\xBE", 'frasl;' => "\xE2\x81\x84", 'Gamma;' => "\xCE\x93", 'gamma;' => "\xCE\xB3", 'ge;' => "\xE2\x89\xA5", 'GT' => "\x3E", 'gt' => "\x3E", 'GT;' => "\x3E", 'gt;' => "\x3E", 'hArr;' => "\xE2\x87\x94", 'harr;' => "\xE2\x86\x94", 'hearts;' => "\xE2\x99\xA5", 'hellip;' => "\xE2\x80\xA6", 'Iacute' => "\xC3\x8D", 'iacute' => "\xC3\xAD", 'Iacute;' => "\xC3\x8D", 'iacute;' => "\xC3\xAD", 'Icirc' => "\xC3\x8E", 'icirc' => "\xC3\xAE", 'Icirc;' => "\xC3\x8E", 'icirc;' => "\xC3\xAE", 'iexcl' => "\xC2\xA1", 'iexcl;' => "\xC2\xA1", 'Igrave' => "\xC3\x8C", 'igrave' => "\xC3\xAC", 'Igrave;' => "\xC3\x8C", 'igrave;' => "\xC3\xAC", 'image;' => "\xE2\x84\x91", 'infin;' => "\xE2\x88\x9E", 'int;' => "\xE2\x88\xAB", 'Iota;' => "\xCE\x99", 'iota;' => "\xCE\xB9", 'iquest' => "\xC2\xBF", 'iquest;' => "\xC2\xBF", 'isin;' => "\xE2\x88\x88", 'Iuml' => "\xC3\x8F", 'iuml' => "\xC3\xAF", 'Iuml;' => "\xC3\x8F", 'iuml;' => "\xC3\xAF", 'Kappa;' => "\xCE\x9A", 'kappa;' => "\xCE\xBA", 'Lambda;' => "\xCE\x9B", 'lambda;' => "\xCE\xBB", 'lang;' => "\xE3\x80\x88", 'laquo' => "\xC2\xAB", 'laquo;' => "\xC2\xAB", 'lArr;' => "\xE2\x87\x90", 'larr;' => "\xE2\x86\x90", 'lceil;' => "\xE2\x8C\x88", 'ldquo;' => "\xE2\x80\x9C", 'le;' => "\xE2\x89\xA4", 'lfloor;' => "\xE2\x8C\x8A", 'lowast;' => "\xE2\x88\x97", 'loz;' => "\xE2\x97\x8A", 'lrm;' => "\xE2\x80\x8E", 'lsaquo;' => "\xE2\x80\xB9", 'lsquo;' => "\xE2\x80\x98", 'LT' => "\x3C", 'lt' => "\x3C", 'LT;' => "\x3C", 'lt;' => "\x3C", 'macr' => "\xC2\xAF", 'macr;' => "\xC2\xAF", 'mdash;' => "\xE2\x80\x94", 'micro' => "\xC2\xB5", 'micro;' => "\xC2\xB5", 'middot' => "\xC2\xB7", 'middot;' => "\xC2\xB7", 'minus;' => "\xE2\x88\x92", 'Mu;' => "\xCE\x9C", 'mu;' => "\xCE\xBC", 'nabla;' => "\xE2\x88\x87", 'nbsp' => "\xC2\xA0", 'nbsp;' => "\xC2\xA0", 'ndash;' => "\xE2\x80\x93", 'ne;' => "\xE2\x89\xA0", 'ni;' => "\xE2\x88\x8B", 'not' => "\xC2\xAC", 'not;' => "\xC2\xAC", 'notin;' => "\xE2\x88\x89", 'nsub;' => "\xE2\x8A\x84", 'Ntilde' => "\xC3\x91", 'ntilde' => "\xC3\xB1", 'Ntilde;' => "\xC3\x91", 'ntilde;' => "\xC3\xB1", 'Nu;' => "\xCE\x9D", 'nu;' => "\xCE\xBD", 'Oacute' => "\xC3\x93", 'oacute' => "\xC3\xB3", 'Oacute;' => "\xC3\x93", 'oacute;' => "\xC3\xB3", 'Ocirc' => "\xC3\x94", 'ocirc' => "\xC3\xB4", 'Ocirc;' => "\xC3\x94", 'ocirc;' => "\xC3\xB4", 'OElig;' => "\xC5\x92", 'oelig;' => "\xC5\x93", 'Ograve' => "\xC3\x92", 'ograve' => "\xC3\xB2", 'Ograve;' => "\xC3\x92", 'ograve;' => "\xC3\xB2", 'oline;' => "\xE2\x80\xBE", 'Omega;' => "\xCE\xA9", 'omega;' => "\xCF\x89", 'Omicron;' => "\xCE\x9F", 'omicron;' => "\xCE\xBF", 'oplus;' => "\xE2\x8A\x95", 'or;' => "\xE2\x88\xA8", 'ordf' => "\xC2\xAA", 'ordf;' => "\xC2\xAA", 'ordm' => "\xC2\xBA", 'ordm;' => "\xC2\xBA", 'Oslash' => "\xC3\x98", 'oslash' => "\xC3\xB8", 'Oslash;' => "\xC3\x98", 'oslash;' => "\xC3\xB8", 'Otilde' => "\xC3\x95", 'otilde' => "\xC3\xB5", 'Otilde;' => "\xC3\x95", 'otilde;' => "\xC3\xB5", 'otimes;' => "\xE2\x8A\x97", 'Ouml' => "\xC3\x96", 'ouml' => "\xC3\xB6", 'Ouml;' => "\xC3\x96", 'ouml;' => "\xC3\xB6", 'para' => "\xC2\xB6", 'para;' => "\xC2\xB6", 'part;' => "\xE2\x88\x82", 'permil;' => "\xE2\x80\xB0", 'perp;' => "\xE2\x8A\xA5", 'Phi;' => "\xCE\xA6", 'phi;' => "\xCF\x86", 'Pi;' => "\xCE\xA0", 'pi;' => "\xCF\x80", 'piv;' => "\xCF\x96", 'plusmn' => "\xC2\xB1", 'plusmn;' => "\xC2\xB1", 'pound' => "\xC2\xA3", 'pound;' => "\xC2\xA3", 'Prime;' => "\xE2\x80\xB3", 'prime;' => "\xE2\x80\xB2", 'prod;' => "\xE2\x88\x8F", 'prop;' => "\xE2\x88\x9D", 'Psi;' => "\xCE\xA8", 'psi;' => "\xCF\x88", 'QUOT' => "\x22", 'quot' => "\x22", 'QUOT;' => "\x22", 'quot;' => "\x22", 'radic;' => "\xE2\x88\x9A", 'rang;' => "\xE3\x80\x89", 'raquo' => "\xC2\xBB", 'raquo;' => "\xC2\xBB", 'rArr;' => "\xE2\x87\x92", 'rarr;' => "\xE2\x86\x92", 'rceil;' => "\xE2\x8C\x89", 'rdquo;' => "\xE2\x80\x9D", 'real;' => "\xE2\x84\x9C", 'REG' => "\xC2\xAE", 'reg' => "\xC2\xAE", 'REG;' => "\xC2\xAE", 'reg;' => "\xC2\xAE", 'rfloor;' => "\xE2\x8C\x8B", 'Rho;' => "\xCE\xA1", 'rho;' => "\xCF\x81", 'rlm;' => "\xE2\x80\x8F", 'rsaquo;' => "\xE2\x80\xBA", 'rsquo;' => "\xE2\x80\x99", 'sbquo;' => "\xE2\x80\x9A", 'Scaron;' => "\xC5\xA0", 'scaron;' => "\xC5\xA1", 'sdot;' => "\xE2\x8B\x85", 'sect' => "\xC2\xA7", 'sect;' => "\xC2\xA7", 'shy' => "\xC2\xAD", 'shy;' => "\xC2\xAD", 'Sigma;' => "\xCE\xA3", 'sigma;' => "\xCF\x83", 'sigmaf;' => "\xCF\x82", 'sim;' => "\xE2\x88\xBC", 'spades;' => "\xE2\x99\xA0", 'sub;' => "\xE2\x8A\x82", 'sube;' => "\xE2\x8A\x86", 'sum;' => "\xE2\x88\x91", 'sup;' => "\xE2\x8A\x83", 'sup1' => "\xC2\xB9", 'sup1;' => "\xC2\xB9", 'sup2' => "\xC2\xB2", 'sup2;' => "\xC2\xB2", 'sup3' => "\xC2\xB3", 'sup3;' => "\xC2\xB3", 'supe;' => "\xE2\x8A\x87", 'szlig' => "\xC3\x9F", 'szlig;' => "\xC3\x9F", 'Tau;' => "\xCE\xA4", 'tau;' => "\xCF\x84", 'there4;' => "\xE2\x88\xB4", 'Theta;' => "\xCE\x98", 'theta;' => "\xCE\xB8", 'thetasym;' => "\xCF\x91", 'thinsp;' => "\xE2\x80\x89", 'THORN' => "\xC3\x9E", 'thorn' => "\xC3\xBE", 'THORN;' => "\xC3\x9E", 'thorn;' => "\xC3\xBE", 'tilde;' => "\xCB\x9C", 'times' => "\xC3\x97", 'times;' => "\xC3\x97", 'TRADE;' => "\xE2\x84\xA2", 'trade;' => "\xE2\x84\xA2", 'Uacute' => "\xC3\x9A", 'uacute' => "\xC3\xBA", 'Uacute;' => "\xC3\x9A", 'uacute;' => "\xC3\xBA", 'uArr;' => "\xE2\x87\x91", 'uarr;' => "\xE2\x86\x91", 'Ucirc' => "\xC3\x9B", 'ucirc' => "\xC3\xBB", 'Ucirc;' => "\xC3\x9B", 'ucirc;' => "\xC3\xBB", 'Ugrave' => "\xC3\x99", 'ugrave' => "\xC3\xB9", 'Ugrave;' => "\xC3\x99", 'ugrave;' => "\xC3\xB9", 'uml' => "\xC2\xA8", 'uml;' => "\xC2\xA8", 'upsih;' => "\xCF\x92", 'Upsilon;' => "\xCE\xA5", 'upsilon;' => "\xCF\x85", 'Uuml' => "\xC3\x9C", 'uuml' => "\xC3\xBC", 'Uuml;' => "\xC3\x9C", 'uuml;' => "\xC3\xBC", 'weierp;' => "\xE2\x84\x98", 'Xi;' => "\xCE\x9E", 'xi;' => "\xCE\xBE", 'Yacute' => "\xC3\x9D", 'yacute' => "\xC3\xBD", 'Yacute;' => "\xC3\x9D", 'yacute;' => "\xC3\xBD", 'yen' => "\xC2\xA5", 'yen;' => "\xC2\xA5", 'yuml' => "\xC3\xBF", 'Yuml;' => "\xC5\xB8", 'yuml;' => "\xC3\xBF", 'Zeta;' => "\xCE\x96", 'zeta;' => "\xCE\xB6", 'zwj;' => "\xE2\x80\x8D", 'zwnj;' => "\xE2\x80\x8C");
  9949. for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++)
  9950. {
  9951. $consumed = substr($this->consumed, 1);
  9952. if (isset($entities[$consumed]))
  9953. {
  9954. $match = $consumed;
  9955. }
  9956. }
  9957. if ($match !== null)
  9958. {
  9959. $this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
  9960. $this->position += strlen($entities[$match]) - strlen($consumed) - 1;
  9961. }
  9962. break;
  9963. }
  9964. }
  9965. }
  9966. /**
  9967. * Date Parser
  9968. *
  9969. * @package SimplePie
  9970. */
  9971. class SimplePie_Parse_Date
  9972. {
  9973. /**
  9974. * Input data
  9975. *
  9976. * @access protected
  9977. * @var string
  9978. */
  9979. var $date;
  9980. /**
  9981. * List of days, calendar day name => ordinal day number in the week
  9982. *
  9983. * @access protected
  9984. * @var array
  9985. */
  9986. var $day = array(
  9987. // English
  9988. 'mon' => 1,
  9989. 'monday' => 1,
  9990. 'tue' => 2,
  9991. 'tuesday' => 2,
  9992. 'wed' => 3,
  9993. 'wednesday' => 3,
  9994. 'thu' => 4,
  9995. 'thursday' => 4,
  9996. 'fri' => 5,
  9997. 'friday' => 5,
  9998. 'sat' => 6,
  9999. 'saturday' => 6,
  10000. 'sun' => 7,
  10001. 'sunday' => 7,
  10002. // Dutch
  10003. 'maandag' => 1,
  10004. 'dinsdag' => 2,
  10005. 'woensdag' => 3,
  10006. 'donderdag' => 4,
  10007. 'vrijdag' => 5,
  10008. 'zaterdag' => 6,
  10009. 'zondag' => 7,
  10010. // French
  10011. 'lundi' => 1,
  10012. 'mardi' => 2,
  10013. 'mercredi' => 3,
  10014. 'jeudi' => 4,
  10015. 'vendredi' => 5,
  10016. 'samedi' => 6,
  10017. 'dimanche' => 7,
  10018. // German
  10019. 'montag' => 1,
  10020. 'dienstag' => 2,
  10021. 'mittwoch' => 3,
  10022. 'donnerstag' => 4,
  10023. 'freitag' => 5,
  10024. 'samstag' => 6,
  10025. 'sonnabend' => 6,
  10026. 'sonntag' => 7,
  10027. // Italian
  10028. 'lunedì' => 1,
  10029. 'martedì' => 2,
  10030. 'mercoledì' => 3,
  10031. 'giovedì' => 4,
  10032. 'venerdì' => 5,
  10033. 'sabato' => 6,
  10034. 'domenica' => 7,
  10035. // Spanish
  10036. 'lunes' => 1,
  10037. 'martes' => 2,
  10038. 'miércoles' => 3,
  10039. 'jueves' => 4,
  10040. 'viernes' => 5,
  10041. 'sábado' => 6,
  10042. 'domingo' => 7,
  10043. // Finnish
  10044. 'maanantai' => 1,
  10045. 'tiistai' => 2,
  10046. 'keskiviikko' => 3,
  10047. 'torstai' => 4,
  10048. 'perjantai' => 5,
  10049. 'lauantai' => 6,
  10050. 'sunnuntai' => 7,
  10051. // Hungarian
  10052. 'hétfő' => 1,
  10053. 'kedd' => 2,
  10054. 'szerda' => 3,
  10055. 'csütörtok' => 4,
  10056. 'péntek' => 5,
  10057. 'szombat' => 6,
  10058. 'vasárnap' => 7,
  10059. // Greek
  10060. 'Δευ' => 1,
  10061. 'Τρι' => 2,
  10062. 'Τετ' => 3,
  10063. 'Πεμ' => 4,
  10064. 'Παρ' => 5,
  10065. 'Σαβ' => 6,
  10066. 'Κυρ' => 7,
  10067. );
  10068. /**
  10069. * List of months, calendar month name => calendar month number
  10070. *
  10071. * @access protected
  10072. * @var array
  10073. */
  10074. var $month = array(
  10075. // English
  10076. 'jan' => 1,
  10077. 'january' => 1,
  10078. 'feb' => 2,
  10079. 'february' => 2,
  10080. 'mar' => 3,
  10081. 'march' => 3,
  10082. 'apr' => 4,
  10083. 'april' => 4,
  10084. 'may' => 5,
  10085. // No long form of May
  10086. 'jun' => 6,
  10087. 'june' => 6,
  10088. 'jul' => 7,
  10089. 'july' => 7,
  10090. 'aug' => 8,
  10091. 'august' => 8,
  10092. 'sep' => 9,
  10093. 'september' => 8,
  10094. 'oct' => 10,
  10095. 'october' => 10,
  10096. 'nov' => 11,
  10097. 'november' => 11,
  10098. 'dec' => 12,
  10099. 'december' => 12,
  10100. // Dutch
  10101. 'januari' => 1,
  10102. 'februari' => 2,
  10103. 'maart' => 3,
  10104. 'april' => 4,
  10105. 'mei' => 5,
  10106. 'juni' => 6,
  10107. 'juli' => 7,
  10108. 'augustus' => 8,
  10109. 'september' => 9,
  10110. 'oktober' => 10,
  10111. 'november' => 11,
  10112. 'december' => 12,
  10113. // French
  10114. 'janvier' => 1,
  10115. 'février' => 2,
  10116. 'mars' => 3,
  10117. 'avril' => 4,
  10118. 'mai' => 5,
  10119. 'juin' => 6,
  10120. 'juillet' => 7,
  10121. 'août' => 8,
  10122. 'septembre' => 9,
  10123. 'octobre' => 10,
  10124. 'novembre' => 11,
  10125. 'décembre' => 12,
  10126. // German
  10127. 'januar' => 1,
  10128. 'februar' => 2,
  10129. 'märz' => 3,
  10130. 'april' => 4,
  10131. 'mai' => 5,
  10132. 'juni' => 6,
  10133. 'juli' => 7,
  10134. 'august' => 8,
  10135. 'september' => 9,
  10136. 'oktober' => 10,
  10137. 'november' => 11,
  10138. 'dezember' => 12,
  10139. // Italian
  10140. 'gennaio' => 1,
  10141. 'febbraio' => 2,
  10142. 'marzo' => 3,
  10143. 'aprile' => 4,
  10144. 'maggio' => 5,
  10145. 'giugno' => 6,
  10146. 'luglio' => 7,
  10147. 'agosto' => 8,
  10148. 'settembre' => 9,
  10149. 'ottobre' => 10,
  10150. 'novembre' => 11,
  10151. 'dicembre' => 12,
  10152. // Spanish
  10153. 'enero' => 1,
  10154. 'febrero' => 2,
  10155. 'marzo' => 3,
  10156. 'abril' => 4,
  10157. 'mayo' => 5,
  10158. 'junio' => 6,
  10159. 'julio' => 7,
  10160. 'agosto' => 8,
  10161. 'septiembre' => 9,
  10162. 'setiembre' => 9,
  10163. 'octubre' => 10,
  10164. 'noviembre' => 11,
  10165. 'diciembre' => 12,
  10166. // Finnish
  10167. 'tammikuu' => 1,
  10168. 'helmikuu' => 2,
  10169. 'maaliskuu' => 3,
  10170. 'huhtikuu' => 4,
  10171. 'toukokuu' => 5,
  10172. 'kesäkuu' => 6,
  10173. 'heinäkuu' => 7,
  10174. 'elokuu' => 8,
  10175. 'suuskuu' => 9,
  10176. 'lokakuu' => 10,
  10177. 'marras' => 11,
  10178. 'joulukuu' => 12,
  10179. // Hungarian
  10180. 'január' => 1,
  10181. 'február' => 2,
  10182. 'március' => 3,
  10183. 'április' => 4,
  10184. 'május' => 5,
  10185. 'június' => 6,
  10186. 'július' => 7,
  10187. 'augusztus' => 8,
  10188. 'szeptember' => 9,
  10189. 'október' => 10,
  10190. 'november' => 11,
  10191. 'december' => 12,
  10192. // Greek
  10193. 'Ιαν' => 1,
  10194. 'Φεβ' => 2,
  10195. 'Μάώ' => 3,
  10196. 'Μαώ' => 3,
  10197. 'Απρ' => 4,
  10198. 'Μάι' => 5,
  10199. 'Μαϊ' => 5,
  10200. 'Μαι' => 5,
  10201. 'Ιούν' => 6,
  10202. 'Ιον' => 6,
  10203. 'Ιούλ' => 7,
  10204. 'Ιολ' => 7,
  10205. 'Αύγ' => 8,
  10206. 'Αυγ' => 8,
  10207. 'Σεπ' => 9,
  10208. 'Οκτ' => 10,
  10209. 'Νοέ' => 11,
  10210. 'Δεκ' => 12,
  10211. );
  10212. /**
  10213. * List of timezones, abbreviation => offset from UTC
  10214. *
  10215. * @access protected
  10216. * @var array
  10217. */
  10218. var $timezone = array(
  10219. 'ACDT' => 37800,
  10220. 'ACIT' => 28800,
  10221. 'ACST' => 34200,
  10222. 'ACT' => -18000,
  10223. 'ACWDT' => 35100,
  10224. 'ACWST' => 31500,
  10225. 'AEDT' => 39600,
  10226. 'AEST' => 36000,
  10227. 'AFT' => 16200,
  10228. 'AKDT' => -28800,
  10229. 'AKST' => -32400,
  10230. 'AMDT' => 18000,
  10231. 'AMT' => -14400,
  10232. 'ANAST' => 46800,
  10233. 'ANAT' => 43200,
  10234. 'ART' => -10800,
  10235. 'AZOST' => -3600,
  10236. 'AZST' => 18000,
  10237. 'AZT' => 14400,
  10238. 'BIOT' => 21600,
  10239. 'BIT' => -43200,
  10240. 'BOT' => -14400,
  10241. 'BRST' => -7200,
  10242. 'BRT' => -10800,
  10243. 'BST' => 3600,
  10244. 'BTT' => 21600,
  10245. 'CAST' => 18000,
  10246. 'CAT' => 7200,
  10247. 'CCT' => 23400,
  10248. 'CDT' => -18000,
  10249. 'CEDT' => 7200,
  10250. 'CET' => 3600,
  10251. 'CGST' => -7200,
  10252. 'CGT' => -10800,
  10253. 'CHADT' => 49500,
  10254. 'CHAST' => 45900,
  10255. 'CIST' => -28800,
  10256. 'CKT' => -36000,
  10257. 'CLDT' => -10800,
  10258. 'CLST' => -14400,
  10259. 'COT' => -18000,
  10260. 'CST' => -21600,
  10261. 'CVT' => -3600,
  10262. 'CXT' => 25200,
  10263. 'DAVT' => 25200,
  10264. 'DTAT' => 36000,
  10265. 'EADT' => -18000,
  10266. 'EAST' => -21600,
  10267. 'EAT' => 10800,
  10268. 'ECT' => -18000,
  10269. 'EDT' => -14400,
  10270. 'EEST' => 10800,
  10271. 'EET' => 7200,
  10272. 'EGT' => -3600,
  10273. 'EKST' => 21600,
  10274. 'EST' => -18000,
  10275. 'FJT' => 43200,
  10276. 'FKDT' => -10800,
  10277. 'FKST' => -14400,
  10278. 'FNT' => -7200,
  10279. 'GALT' => -21600,
  10280. 'GEDT' => 14400,
  10281. 'GEST' => 10800,
  10282. 'GFT' => -10800,
  10283. 'GILT' => 43200,
  10284. 'GIT' => -32400,
  10285. 'GST' => 14400,
  10286. 'GST' => -7200,
  10287. 'GYT' => -14400,
  10288. 'HAA' => -10800,
  10289. 'HAC' => -18000,
  10290. 'HADT' => -32400,
  10291. 'HAE' => -14400,
  10292. 'HAP' => -25200,
  10293. 'HAR' => -21600,
  10294. 'HAST' => -36000,
  10295. 'HAT' => -9000,
  10296. 'HAY' => -28800,
  10297. 'HKST' => 28800,
  10298. 'HMT' => 18000,
  10299. 'HNA' => -14400,
  10300. 'HNC' => -21600,
  10301. 'HNE' => -18000,
  10302. 'HNP' => -28800,
  10303. 'HNR' => -25200,
  10304. 'HNT' => -12600,
  10305. 'HNY' => -32400,
  10306. 'IRDT' => 16200,
  10307. 'IRKST' => 32400,
  10308. 'IRKT' => 28800,
  10309. 'IRST' => 12600,
  10310. 'JFDT' => -10800,
  10311. 'JFST' => -14400,
  10312. 'JST' => 32400,
  10313. 'KGST' => 21600,
  10314. 'KGT' => 18000,
  10315. 'KOST' => 39600,
  10316. 'KOVST' => 28800,
  10317. 'KOVT' => 25200,
  10318. 'KRAST' => 28800,
  10319. 'KRAT' => 25200,
  10320. 'KST' => 32400,
  10321. 'LHDT' => 39600,
  10322. 'LHST' => 37800,
  10323. 'LINT' => 50400,
  10324. 'LKT' => 21600,
  10325. 'MAGST' => 43200,
  10326. 'MAGT' => 39600,
  10327. 'MAWT' => 21600,
  10328. 'MDT' => -21600,
  10329. 'MESZ' => 7200,
  10330. 'MEZ' => 3600,
  10331. 'MHT' => 43200,
  10332. 'MIT' => -34200,
  10333. 'MNST' => 32400,
  10334. 'MSDT' => 14400,
  10335. 'MSST' => 10800,
  10336. 'MST' => -25200,
  10337. 'MUT' => 14400,
  10338. 'MVT' => 18000,
  10339. 'MYT' => 28800,
  10340. 'NCT' => 39600,
  10341. 'NDT' => -9000,
  10342. 'NFT' => 41400,
  10343. 'NMIT' => 36000,
  10344. 'NOVST' => 25200,
  10345. 'NOVT' => 21600,
  10346. 'NPT' => 20700,
  10347. 'NRT' => 43200,
  10348. 'NST' => -12600,
  10349. 'NUT' => -39600,
  10350. 'NZDT' => 46800,
  10351. 'NZST' => 43200,
  10352. 'OMSST' => 25200,
  10353. 'OMST' => 21600,
  10354. 'PDT' => -25200,
  10355. 'PET' => -18000,
  10356. 'PETST' => 46800,
  10357. 'PETT' => 43200,
  10358. 'PGT' => 36000,
  10359. 'PHOT' => 46800,
  10360. 'PHT' => 28800,
  10361. 'PKT' => 18000,
  10362. 'PMDT' => -7200,
  10363. 'PMST' => -10800,
  10364. 'PONT' => 39600,
  10365. 'PST' => -28800,
  10366. 'PWT' => 32400,
  10367. 'PYST' => -10800,
  10368. 'PYT' => -14400,
  10369. 'RET' => 14400,
  10370. 'ROTT' => -10800,
  10371. 'SAMST' => 18000,
  10372. 'SAMT' => 14400,
  10373. 'SAST' => 7200,
  10374. 'SBT' => 39600,
  10375. 'SCDT' => 46800,
  10376. 'SCST' => 43200,
  10377. 'SCT' => 14400,
  10378. 'SEST' => 3600,
  10379. 'SGT' => 28800,
  10380. 'SIT' => 28800,
  10381. 'SRT' => -10800,
  10382. 'SST' => -39600,
  10383. 'SYST' => 10800,
  10384. 'SYT' => 7200,
  10385. 'TFT' => 18000,
  10386. 'THAT' => -36000,
  10387. 'TJT' => 18000,
  10388. 'TKT' => -36000,
  10389. 'TMT' => 18000,
  10390. 'TOT' => 46800,
  10391. 'TPT' => 32400,
  10392. 'TRUT' => 36000,
  10393. 'TVT' => 43200,
  10394. 'TWT' => 28800,
  10395. 'UYST' => -7200,
  10396. 'UYT' => -10800,
  10397. 'UZT' => 18000,
  10398. 'VET' => -14400,
  10399. 'VLAST' => 39600,
  10400. 'VLAT' => 36000,
  10401. 'VOST' => 21600,
  10402. 'VUT' => 39600,
  10403. 'WAST' => 7200,
  10404. 'WAT' => 3600,
  10405. 'WDT' => 32400,
  10406. 'WEST' => 3600,
  10407. 'WFT' => 43200,
  10408. 'WIB' => 25200,
  10409. 'WIT' => 32400,
  10410. 'WITA' => 28800,
  10411. 'WKST' => 18000,
  10412. 'WST' => 28800,
  10413. 'YAKST' => 36000,
  10414. 'YAKT' => 32400,
  10415. 'YAPT' => 36000,
  10416. 'YEKST' => 21600,
  10417. 'YEKT' => 18000,
  10418. );
  10419. /**
  10420. * Cached PCRE for SimplePie_Parse_Date::$day
  10421. *
  10422. * @access protected
  10423. * @var string
  10424. */
  10425. var $day_pcre;
  10426. /**
  10427. * Cached PCRE for SimplePie_Parse_Date::$month
  10428. *
  10429. * @access protected
  10430. * @var string
  10431. */
  10432. var $month_pcre;
  10433. /**
  10434. * Array of user-added callback methods
  10435. *
  10436. * @access private
  10437. * @var array
  10438. */
  10439. var $built_in = array();
  10440. /**
  10441. * Array of user-added callback methods
  10442. *
  10443. * @access private
  10444. * @var array
  10445. */
  10446. var $user = array();
  10447. /**
  10448. * Create new SimplePie_Parse_Date object, and set self::day_pcre,
  10449. * self::month_pcre, and self::built_in
  10450. *
  10451. * @access private
  10452. */
  10453. function SimplePie_Parse_Date()
  10454. {
  10455. $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
  10456. $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
  10457. static $cache;
  10458. if (!isset($cache[get_class($this)]))
  10459. {
  10460. if (extension_loaded('Reflection'))
  10461. {
  10462. $class = new ReflectionClass(get_class($this));
  10463. $methods = $class->getMethods();
  10464. $all_methods = array();
  10465. foreach ($methods as $method)
  10466. {
  10467. $all_methods[] = $method->getName();
  10468. }
  10469. }
  10470. else
  10471. {
  10472. $all_methods = get_class_methods($this);
  10473. }
  10474. foreach ($all_methods as $method)
  10475. {
  10476. if (strtolower(substr($method, 0, 5)) === 'date_')
  10477. {
  10478. $cache[get_class($this)][] = $method;
  10479. }
  10480. }
  10481. }
  10482. foreach ($cache[get_class($this)] as $method)
  10483. {
  10484. $this->built_in[] = $method;
  10485. }
  10486. }
  10487. /**
  10488. * Get the object
  10489. *
  10490. * @access public
  10491. */
  10492. function get()
  10493. {
  10494. static $object;
  10495. if (!$object)
  10496. {
  10497. $object = new SimplePie_Parse_Date;
  10498. }
  10499. return $object;
  10500. }
  10501. /**
  10502. * Parse a date
  10503. *
  10504. * @final
  10505. * @access public
  10506. * @param string $date Date to parse
  10507. * @return int Timestamp corresponding to date string, or false on failure
  10508. */
  10509. function parse($date)
  10510. {
  10511. foreach ($this->user as $method)
  10512. {
  10513. if (($returned = call_user_func($method, $date)) !== false)
  10514. {
  10515. return $returned;
  10516. }
  10517. }
  10518. foreach ($this->built_in as $method)
  10519. {
  10520. if (($returned = call_user_func(array(&$this, $method), $date)) !== false)
  10521. {
  10522. return $returned;
  10523. }
  10524. }
  10525. return false;
  10526. }
  10527. /**
  10528. * Add a callback method to parse a date
  10529. *
  10530. * @final
  10531. * @access public
  10532. * @param callback $callback
  10533. */
  10534. function add_callback($callback)
  10535. {
  10536. if (is_callable($callback))
  10537. {
  10538. $this->user[] = $callback;
  10539. }
  10540. else
  10541. {
  10542. trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
  10543. }
  10544. }
  10545. /**
  10546. * Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
  10547. * well as allowing any of upper or lower case "T", horizontal tabs, or
  10548. * spaces to be used as the time seperator (including more than one))
  10549. *
  10550. * @access protected
  10551. * @return int Timestamp
  10552. */
  10553. function date_w3cdtf($date)
  10554. {
  10555. static $pcre;
  10556. if (!$pcre)
  10557. {
  10558. $year = '([0-9]{4})';
  10559. $month = $day = $hour = $minute = $second = '([0-9]{2})';
  10560. $decimal = '([0-9]*)';
  10561. $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
  10562. $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
  10563. }
  10564. if (preg_match($pcre, $date, $match))
  10565. {
  10566. /*
  10567. Capturing subpatterns:
  10568. 1: Year
  10569. 2: Month
  10570. 3: Day
  10571. 4: Hour
  10572. 5: Minute
  10573. 6: Second
  10574. 7: Decimal fraction of a second
  10575. 8: Zulu
  10576. 9: Timezone ±
  10577. 10: Timezone hours
  10578. 11: Timezone minutes
  10579. */
  10580. // Fill in empty matches
  10581. for ($i = count($match); $i <= 3; $i++)
  10582. {
  10583. $match[$i] = '1';
  10584. }
  10585. for ($i = count($match); $i <= 7; $i++)
  10586. {
  10587. $match[$i] = '0';
  10588. }
  10589. // Numeric timezone
  10590. if (isset($match[9]) && $match[9] !== '')
  10591. {
  10592. $timezone = $match[10] * 3600;
  10593. $timezone += $match[11] * 60;
  10594. if ($match[9] === '-')
  10595. {
  10596. $timezone = 0 - $timezone;
  10597. }
  10598. }
  10599. else
  10600. {
  10601. $timezone = 0;
  10602. }
  10603. // Convert the number of seconds to an integer, taking decimals into account
  10604. $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
  10605. return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
  10606. }
  10607. else
  10608. {
  10609. return false;
  10610. }
  10611. }
  10612. /**
  10613. * Remove RFC822 comments
  10614. *
  10615. * @access protected
  10616. * @param string $data Data to strip comments from
  10617. * @return string Comment stripped string
  10618. */
  10619. function remove_rfc2822_comments($string)
  10620. {
  10621. $string = (string) $string;
  10622. $position = 0;
  10623. $length = strlen($string);
  10624. $depth = 0;
  10625. $output = '';
  10626. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  10627. {
  10628. $output .= substr($string, $position, $pos - $position);
  10629. $position = $pos + 1;
  10630. if ($string[$pos - 1] !== '\\')
  10631. {
  10632. $depth++;
  10633. while ($depth && $position < $length)
  10634. {
  10635. $position += strcspn($string, '()', $position);
  10636. if ($string[$position - 1] === '\\')
  10637. {
  10638. $position++;
  10639. continue;
  10640. }
  10641. elseif (isset($string[$position]))
  10642. {
  10643. switch ($string[$position])
  10644. {
  10645. case '(':
  10646. $depth++;
  10647. break;
  10648. case ')':
  10649. $depth--;
  10650. break;
  10651. }
  10652. $position++;
  10653. }
  10654. else
  10655. {
  10656. break;
  10657. }
  10658. }
  10659. }
  10660. else
  10661. {
  10662. $output .= '(';
  10663. }
  10664. }
  10665. $output .= substr($string, $position);
  10666. return $output;
  10667. }
  10668. /**
  10669. * Parse RFC2822's date format
  10670. *
  10671. * @access protected
  10672. * @return int Timestamp
  10673. */
  10674. function date_rfc2822($date)
  10675. {
  10676. static $pcre;
  10677. if (!$pcre)
  10678. {
  10679. $wsp = '[\x09\x20]';
  10680. $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
  10681. $optional_fws = $fws . '?';
  10682. $day_name = $this->day_pcre;
  10683. $month = $this->month_pcre;
  10684. $day = '([0-9]{1,2})';
  10685. $hour = $minute = $second = '([0-9]{2})';
  10686. $year = '([0-9]{2,4})';
  10687. $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
  10688. $character_zone = '([A-Z]{1,5})';
  10689. $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
  10690. $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
  10691. }
  10692. if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
  10693. {
  10694. /*
  10695. Capturing subpatterns:
  10696. 1: Day name
  10697. 2: Day
  10698. 3: Month
  10699. 4: Year
  10700. 5: Hour
  10701. 6: Minute
  10702. 7: Second
  10703. 8: Timezone ±
  10704. 9: Timezone hours
  10705. 10: Timezone minutes
  10706. 11: Alphabetic timezone
  10707. */
  10708. // Find the month number
  10709. $month = $this->month[strtolower($match[3])];
  10710. // Numeric timezone
  10711. if ($match[8] !== '')
  10712. {
  10713. $timezone = $match[9] * 3600;
  10714. $timezone += $match[10] * 60;
  10715. if ($match[8] === '-')
  10716. {
  10717. $timezone = 0 - $timezone;
  10718. }
  10719. }
  10720. // Character timezone
  10721. elseif (isset($this->timezone[strtoupper($match[11])]))
  10722. {
  10723. $timezone = $this->timezone[strtoupper($match[11])];
  10724. }
  10725. // Assume everything else to be -0000
  10726. else
  10727. {
  10728. $timezone = 0;
  10729. }
  10730. // Deal with 2/3 digit years
  10731. if ($match[4] < 50)
  10732. {
  10733. $match[4] += 2000;
  10734. }
  10735. elseif ($match[4] < 1000)
  10736. {
  10737. $match[4] += 1900;
  10738. }
  10739. // Second is optional, if it is empty set it to zero
  10740. if ($match[7] !== '')
  10741. {
  10742. $second = $match[7];
  10743. }
  10744. else
  10745. {
  10746. $second = 0;
  10747. }
  10748. return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
  10749. }
  10750. else
  10751. {
  10752. return false;
  10753. }
  10754. }
  10755. /**
  10756. * Parse RFC850's date format
  10757. *
  10758. * @access protected
  10759. * @return int Timestamp
  10760. */
  10761. function date_rfc850($date)
  10762. {
  10763. static $pcre;
  10764. if (!$pcre)
  10765. {
  10766. $space = '[\x09\x20]+';
  10767. $day_name = $this->day_pcre;
  10768. $month = $this->month_pcre;
  10769. $day = '([0-9]{1,2})';
  10770. $year = $hour = $minute = $second = '([0-9]{2})';
  10771. $zone = '([A-Z]{1,5})';
  10772. $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
  10773. }
  10774. if (preg_match($pcre, $date, $match))
  10775. {
  10776. /*
  10777. Capturing subpatterns:
  10778. 1: Day name
  10779. 2: Day
  10780. 3: Month
  10781. 4: Year
  10782. 5: Hour
  10783. 6: Minute
  10784. 7: Second
  10785. 8: Timezone
  10786. */
  10787. // Month
  10788. $month = $this->month[strtolower($match[3])];
  10789. // Character timezone
  10790. if (isset($this->timezone[strtoupper($match[8])]))
  10791. {
  10792. $timezone = $this->timezone[strtoupper($match[8])];
  10793. }
  10794. // Assume everything else to be -0000
  10795. else
  10796. {
  10797. $timezone = 0;
  10798. }
  10799. // Deal with 2 digit year
  10800. if ($match[4] < 50)
  10801. {
  10802. $match[4] += 2000;
  10803. }
  10804. else
  10805. {
  10806. $match[4] += 1900;
  10807. }
  10808. return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
  10809. }
  10810. else
  10811. {
  10812. return false;
  10813. }
  10814. }
  10815. /**
  10816. * Parse C99's asctime()'s date format
  10817. *
  10818. * @access protected
  10819. * @return int Timestamp
  10820. */
  10821. function date_asctime($date)
  10822. {
  10823. static $pcre;
  10824. if (!$pcre)
  10825. {
  10826. $space = '[\x09\x20]+';
  10827. $wday_name = $this->day_pcre;
  10828. $mon_name = $this->month_pcre;
  10829. $day = '([0-9]{1,2})';
  10830. $hour = $sec = $min = '([0-9]{2})';
  10831. $year = '([0-9]{4})';
  10832. $terminator = '\x0A?\x00?';
  10833. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
  10834. }
  10835. if (preg_match($pcre, $date, $match))
  10836. {
  10837. /*
  10838. Capturing subpatterns:
  10839. 1: Day name
  10840. 2: Month
  10841. 3: Day
  10842. 4: Hour
  10843. 5: Minute
  10844. 6: Second
  10845. 7: Year
  10846. */
  10847. $month = $this->month[strtolower($match[2])];
  10848. return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
  10849. }
  10850. else
  10851. {
  10852. return false;
  10853. }
  10854. }
  10855. /**
  10856. * Parse dates using strtotime()
  10857. *
  10858. * @access protected
  10859. * @return int Timestamp
  10860. */
  10861. function date_strtotime($date)
  10862. {
  10863. $strtotime = strtotime($date);
  10864. if ($strtotime === -1 || $strtotime === false)
  10865. {
  10866. return false;
  10867. }
  10868. else
  10869. {
  10870. return $strtotime;
  10871. }
  10872. }
  10873. }
  10874. /**
  10875. * Content-type sniffing
  10876. *
  10877. * @package SimplePie
  10878. */
  10879. class SimplePie_Content_Type_Sniffer
  10880. {
  10881. /**
  10882. * File object
  10883. *
  10884. * @var SimplePie_File
  10885. * @access private
  10886. */
  10887. var $file;
  10888. /**
  10889. * Create an instance of the class with the input file
  10890. *
  10891. * @access public
  10892. * @param SimplePie_Content_Type_Sniffer $file Input file
  10893. */
  10894. function SimplePie_Content_Type_Sniffer($file)
  10895. {
  10896. $this->file = $file;
  10897. }
  10898. /**
  10899. * Get the Content-Type of the specified file
  10900. *
  10901. * @access public
  10902. * @return string Actual Content-Type
  10903. */
  10904. function get_type()
  10905. {
  10906. if (isset($this->file->headers['content-type']))
  10907. {
  10908. if (!isset($this->file->headers['content-encoding'])
  10909. && ($this->file->headers['content-type'] === 'text/plain'
  10910. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  10911. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'))
  10912. {
  10913. return $this->text_or_binary();
  10914. }
  10915. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
  10916. {
  10917. $official = substr($this->file->headers['content-type'], 0, $pos);
  10918. }
  10919. else
  10920. {
  10921. $official = $this->file->headers['content-type'];
  10922. }
  10923. $official = strtolower($official);
  10924. if ($official === 'unknown/unknown'
  10925. || $official === 'application/unknown')
  10926. {
  10927. return $this->unknown();
  10928. }
  10929. elseif (substr($official, -4) === '+xml'
  10930. || $official === 'text/xml'
  10931. || $official === 'application/xml')
  10932. {
  10933. return $official;
  10934. }
  10935. elseif (substr($official, 0, 6) === 'image/')
  10936. {
  10937. if ($return = $this->image())
  10938. {
  10939. return $return;
  10940. }
  10941. else
  10942. {
  10943. return $official;
  10944. }
  10945. }
  10946. elseif ($official === 'text/html')
  10947. {
  10948. return $this->feed_or_html();
  10949. }
  10950. else
  10951. {
  10952. return $official;
  10953. }
  10954. }
  10955. else
  10956. {
  10957. return $this->unknown();
  10958. }
  10959. }
  10960. /**
  10961. * Sniff text or binary
  10962. *
  10963. * @access private
  10964. * @return string Actual Content-Type
  10965. */
  10966. function text_or_binary()
  10967. {
  10968. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  10969. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  10970. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  10971. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
  10972. {
  10973. return 'text/plain';
  10974. }
  10975. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
  10976. {
  10977. return 'application/octect-stream';
  10978. }
  10979. else
  10980. {
  10981. return 'text/plain';
  10982. }
  10983. }
  10984. /**
  10985. * Sniff unknown
  10986. *
  10987. * @access private
  10988. * @return string Actual Content-Type
  10989. */
  10990. function unknown()
  10991. {
  10992. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  10993. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  10994. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  10995. || strtolower(substr($this->file->body, $ws, 7)) === '<script')
  10996. {
  10997. return 'text/html';
  10998. }
  10999. elseif (substr($this->file->body, 0, 5) === '%PDF-')
  11000. {
  11001. return 'application/pdf';
  11002. }
  11003. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
  11004. {
  11005. return 'application/postscript';
  11006. }
  11007. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  11008. || substr($this->file->body, 0, 6) === 'GIF89a')
  11009. {
  11010. return 'image/gif';
  11011. }
  11012. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  11013. {
  11014. return 'image/png';
  11015. }
  11016. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  11017. {
  11018. return 'image/jpeg';
  11019. }
  11020. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  11021. {
  11022. return 'image/bmp';
  11023. }
  11024. else
  11025. {
  11026. return $this->text_or_binary();
  11027. }
  11028. }
  11029. /**
  11030. * Sniff images
  11031. *
  11032. * @access private
  11033. * @return string Actual Content-Type
  11034. */
  11035. function image()
  11036. {
  11037. if (substr($this->file->body, 0, 6) === 'GIF87a'
  11038. || substr($this->file->body, 0, 6) === 'GIF89a')
  11039. {
  11040. return 'image/gif';
  11041. }
  11042. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  11043. {
  11044. return 'image/png';
  11045. }
  11046. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  11047. {
  11048. return 'image/jpeg';
  11049. }
  11050. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  11051. {
  11052. return 'image/bmp';
  11053. }
  11054. else
  11055. {
  11056. return false;
  11057. }
  11058. }
  11059. /**
  11060. * Sniff HTML
  11061. *
  11062. * @access private
  11063. * @return string Actual Content-Type
  11064. */
  11065. function feed_or_html()
  11066. {
  11067. $len = strlen($this->file->body);
  11068. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
  11069. while ($pos < $len)
  11070. {
  11071. switch ($this->file->body[$pos])
  11072. {
  11073. case "\x09":
  11074. case "\x0A":
  11075. case "\x0D":
  11076. case "\x20":
  11077. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  11078. continue 2;
  11079. case '<':
  11080. $pos++;
  11081. break;
  11082. default:
  11083. return 'text/html';
  11084. }
  11085. if (substr($this->file->body, $pos, 3) === '!--')
  11086. {
  11087. $pos += 3;
  11088. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
  11089. {
  11090. $pos += 3;
  11091. }
  11092. else
  11093. {
  11094. return 'text/html';
  11095. }
  11096. }
  11097. elseif (substr($this->file->body, $pos, 1) === '!')
  11098. {
  11099. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
  11100. {
  11101. $pos++;
  11102. }
  11103. else
  11104. {
  11105. return 'text/html';
  11106. }
  11107. }
  11108. elseif (substr($this->file->body, $pos, 1) === '?')
  11109. {
  11110. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
  11111. {
  11112. $pos += 2;
  11113. }
  11114. else
  11115. {
  11116. return 'text/html';
  11117. }
  11118. }
  11119. elseif (substr($this->file->body, $pos, 3) === 'rss'
  11120. || substr($this->file->body, $pos, 7) === 'rdf:RDF')
  11121. {
  11122. return 'application/rss+xml';
  11123. }
  11124. elseif (substr($this->file->body, $pos, 4) === 'feed')
  11125. {
  11126. return 'application/atom+xml';
  11127. }
  11128. else
  11129. {
  11130. return 'text/html';
  11131. }
  11132. }
  11133. return 'text/html';
  11134. }
  11135. }
  11136. /**
  11137. * Parses the XML Declaration
  11138. *
  11139. * @package SimplePie
  11140. */
  11141. class SimplePie_XML_Declaration_Parser
  11142. {
  11143. /**
  11144. * XML Version
  11145. *
  11146. * @access public
  11147. * @var string
  11148. */
  11149. var $version = '1.0';
  11150. /**
  11151. * Encoding
  11152. *
  11153. * @access public
  11154. * @var string
  11155. */
  11156. var $encoding = 'UTF-8';
  11157. /**
  11158. * Standalone
  11159. *
  11160. * @access public
  11161. * @var bool
  11162. */
  11163. var $standalone = false;
  11164. /**
  11165. * Current state of the state machine
  11166. *
  11167. * @access private
  11168. * @var string
  11169. */
  11170. var $state = 'before_version_name';
  11171. /**
  11172. * Input data
  11173. *
  11174. * @access private
  11175. * @var string
  11176. */
  11177. var $data = '';
  11178. /**
  11179. * Input data length (to avoid calling strlen() everytime this is needed)
  11180. *
  11181. * @access private
  11182. * @var int
  11183. */
  11184. var $data_length = 0;
  11185. /**
  11186. * Current position of the pointer
  11187. *
  11188. * @var int
  11189. * @access private
  11190. */
  11191. var $position = 0;
  11192. /**
  11193. * Create an instance of the class with the input data
  11194. *
  11195. * @access public
  11196. * @param string $data Input data
  11197. */
  11198. function SimplePie_XML_Declaration_Parser($data)
  11199. {
  11200. $this->data = $data;
  11201. $this->data_length = strlen($this->data);
  11202. }
  11203. /**
  11204. * Parse the input data
  11205. *
  11206. * @access public
  11207. * @return bool true on success, false on failure
  11208. */
  11209. function parse()
  11210. {
  11211. while ($this->state && $this->state !== 'emit' && $this->has_data())
  11212. {
  11213. $state = $this->state;
  11214. $this->$state();
  11215. }
  11216. $this->data = '';
  11217. if ($this->state === 'emit')
  11218. {
  11219. return true;
  11220. }
  11221. else
  11222. {
  11223. $this->version = '';
  11224. $this->encoding = '';
  11225. $this->standalone = '';
  11226. return false;
  11227. }
  11228. }
  11229. /**
  11230. * Check whether there is data beyond the pointer
  11231. *
  11232. * @access private
  11233. * @return bool true if there is further data, false if not
  11234. */
  11235. function has_data()
  11236. {
  11237. return (bool) ($this->position < $this->data_length);
  11238. }
  11239. /**
  11240. * Advance past any whitespace
  11241. *
  11242. * @return int Number of whitespace characters passed
  11243. */
  11244. function skip_whitespace()
  11245. {
  11246. $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
  11247. $this->position += $whitespace;
  11248. return $whitespace;
  11249. }
  11250. /**
  11251. * Read value
  11252. */
  11253. function get_value()
  11254. {
  11255. $quote = substr($this->data, $this->position, 1);
  11256. if ($quote === '"' || $quote === "'")
  11257. {
  11258. $this->position++;
  11259. $len = strcspn($this->data, $quote, $this->position);
  11260. if ($this->has_data())
  11261. {
  11262. $value = substr($this->data, $this->position, $len);
  11263. $this->position += $len + 1;
  11264. return $value;
  11265. }
  11266. }
  11267. return false;
  11268. }
  11269. function before_version_name()
  11270. {
  11271. if ($this->skip_whitespace())
  11272. {
  11273. $this->state = 'version_name';
  11274. }
  11275. else
  11276. {
  11277. $this->state = false;
  11278. }
  11279. }
  11280. function version_name()
  11281. {
  11282. if (substr($this->data, $this->position, 7) === 'version')
  11283. {
  11284. $this->position += 7;
  11285. $this->skip_whitespace();
  11286. $this->state = 'version_equals';
  11287. }
  11288. else
  11289. {
  11290. $this->state = false;
  11291. }
  11292. }
  11293. function version_equals()
  11294. {
  11295. if (substr($this->data, $this->position, 1) === '=')
  11296. {
  11297. $this->position++;
  11298. $this->skip_whitespace();
  11299. $this->state = 'version_value';
  11300. }
  11301. else
  11302. {
  11303. $this->state = false;
  11304. }
  11305. }
  11306. function version_value()
  11307. {
  11308. if ($this->version = $this->get_value())
  11309. {
  11310. $this->skip_whitespace();
  11311. if ($this->has_data())
  11312. {
  11313. $this->state = 'encoding_name';
  11314. }
  11315. else
  11316. {
  11317. $this->state = 'emit';
  11318. }
  11319. }
  11320. else
  11321. {
  11322. $this->state = 'standalone_name';
  11323. }
  11324. }
  11325. function encoding_name()
  11326. {
  11327. if (substr($this->data, $this->position, 8) === 'encoding')
  11328. {
  11329. $this->position += 8;
  11330. $this->skip_whitespace();
  11331. $this->state = 'encoding_equals';
  11332. }
  11333. else
  11334. {
  11335. $this->state = false;
  11336. }
  11337. }
  11338. function encoding_equals()
  11339. {
  11340. if (substr($this->data, $this->position, 1) === '=')
  11341. {
  11342. $this->position++;
  11343. $this->skip_whitespace();
  11344. $this->state = 'encoding_value';
  11345. }
  11346. else
  11347. {
  11348. $this->state = false;
  11349. }
  11350. }
  11351. function encoding_value()
  11352. {
  11353. if ($this->encoding = $this->get_value())
  11354. {
  11355. $this->skip_whitespace();
  11356. if ($this->has_data())
  11357. {
  11358. $this->state = 'standalone_name';
  11359. }
  11360. else
  11361. {
  11362. $this->state = 'emit';
  11363. }
  11364. }
  11365. else
  11366. {
  11367. $this->state = false;
  11368. }
  11369. }
  11370. function standalone_name()
  11371. {
  11372. if (substr($this->data, $this->position, 10) === 'standalone')
  11373. {
  11374. $this->position += 10;
  11375. $this->skip_whitespace();
  11376. $this->state = 'standalone_equals';
  11377. }
  11378. else
  11379. {
  11380. $this->state = false;
  11381. }
  11382. }
  11383. function standalone_equals()
  11384. {
  11385. if (substr($this->data, $this->position, 1) === '=')
  11386. {
  11387. $this->position++;
  11388. $this->skip_whitespace();
  11389. $this->state = 'standalone_value';
  11390. }
  11391. else
  11392. {
  11393. $this->state = false;
  11394. }
  11395. }
  11396. function standalone_value()
  11397. {
  11398. if ($standalone = $this->get_value())
  11399. {
  11400. switch ($standalone)
  11401. {
  11402. case 'yes':
  11403. $this->standalone = true;
  11404. break;
  11405. case 'no':
  11406. $this->standalone = false;
  11407. break;
  11408. default:
  11409. $this->state = false;
  11410. return;
  11411. }
  11412. $this->skip_whitespace();
  11413. if ($this->has_data())
  11414. {
  11415. $this->state = false;
  11416. }
  11417. else
  11418. {
  11419. $this->state = 'emit';
  11420. }
  11421. }
  11422. else
  11423. {
  11424. $this->state = false;
  11425. }
  11426. }
  11427. }
  11428. class SimplePie_Locator
  11429. {
  11430. var $useragent;
  11431. var $timeout;
  11432. var $file;
  11433. var $local = array();
  11434. var $elsewhere = array();
  11435. var $file_class = 'SimplePie_File';
  11436. var $cached_entities = array();
  11437. var $http_base;
  11438. var $base;
  11439. var $base_location = 0;
  11440. var $checked_feeds = 0;
  11441. var $max_checked_feeds = 10;
  11442. var $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer';
  11443. function SimplePie_Locator(&$file, $timeout = 10, $useragent = null, $file_class = 'SimplePie_File', $max_checked_feeds = 10, $content_type_sniffer_class = 'SimplePie_Content_Type_Sniffer')
  11444. {
  11445. $this->file =& $file;
  11446. $this->file_class = $file_class;
  11447. $this->useragent = $useragent;
  11448. $this->timeout = $timeout;
  11449. $this->max_checked_feeds = $max_checked_feeds;
  11450. $this->content_type_sniffer_class = $content_type_sniffer_class;
  11451. }
  11452. function find($type = SIMPLEPIE_LOCATOR_ALL)
  11453. {
  11454. if ($this->is_feed($this->file))
  11455. {
  11456. return $this->file;
  11457. }
  11458. if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  11459. {
  11460. $sniffer = new $this->content_type_sniffer_class($this->file);
  11461. if ($sniffer->get_type() !== 'text/html')
  11462. {
  11463. return null;
  11464. }
  11465. }
  11466. if ($type & ~SIMPLEPIE_LOCATOR_NONE)
  11467. {
  11468. $this->get_base();
  11469. }
  11470. if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
  11471. {
  11472. return $working;
  11473. }
  11474. if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
  11475. {
  11476. if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
  11477. {
  11478. return $working;
  11479. }
  11480. if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
  11481. {
  11482. return $working;
  11483. }
  11484. if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
  11485. {
  11486. return $working;
  11487. }
  11488. if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
  11489. {
  11490. return $working;
  11491. }
  11492. }
  11493. return null;
  11494. }
  11495. function is_feed(&$file)
  11496. {
  11497. if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  11498. {
  11499. $sniffer = new $this->content_type_sniffer_class($file);
  11500. $sniffed = $sniffer->get_type();
  11501. if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'application/atom+xml', 'text/xml', 'application/xml', 'text/plain')))
  11502. {
  11503. return true;
  11504. }
  11505. else
  11506. {
  11507. return false;
  11508. }
  11509. }
  11510. elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
  11511. {
  11512. return true;
  11513. }
  11514. else
  11515. {
  11516. return false;
  11517. }
  11518. }
  11519. function get_base()
  11520. {
  11521. $this->http_base = $this->file->url;
  11522. $this->base = $this->http_base;
  11523. $elements = SimplePie_Misc::get_element('base', $this->file->body);
  11524. foreach ($elements as $element)
  11525. {
  11526. if ($element['attribs']['href']['data'] !== '')
  11527. {
  11528. $this->base = SimplePie_Misc::absolutize_url(trim($element['attribs']['href']['data']), $this->http_base);
  11529. $this->base_location = $element['offset'];
  11530. break;
  11531. }
  11532. }
  11533. }
  11534. function autodiscovery()
  11535. {
  11536. $links = array_merge(SimplePie_Misc::get_element('link', $this->file->body), SimplePie_Misc::get_element('a', $this->file->body), SimplePie_Misc::get_element('area', $this->file->body));
  11537. $done = array();
  11538. foreach ($links as $link)
  11539. {
  11540. if ($this->checked_feeds == $this->max_checked_feeds)
  11541. {
  11542. break;
  11543. }
  11544. if (isset($link['attribs']['href']['data']) && isset($link['attribs']['rel']['data']))
  11545. {
  11546. $rel = array_unique(SimplePie_Misc::space_seperated_tokens(strtolower($link['attribs']['rel']['data'])));
  11547. if ($this->base_location < $link['offset'])
  11548. {
  11549. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base);
  11550. }
  11551. else
  11552. {
  11553. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base);
  11554. }
  11555. if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !empty($link['attribs']['type']['data']) && in_array(strtolower(SimplePie_Misc::parse_mime($link['attribs']['type']['data'])), array('application/rss+xml', 'application/atom+xml'))))
  11556. {
  11557. $this->checked_feeds++;
  11558. $feed =& new $this->file_class($href, $this->timeout, 5, null, $this->useragent);
  11559. if ($this->is_feed($feed))
  11560. {
  11561. return $feed;
  11562. }
  11563. }
  11564. $done[] = $href;
  11565. }
  11566. }
  11567. return null;
  11568. }
  11569. function get_links()
  11570. {
  11571. $links = SimplePie_Misc::get_element('a', $this->file->body);
  11572. foreach ($links as $link)
  11573. {
  11574. if (isset($link['attribs']['href']['data']))
  11575. {
  11576. $href = trim($link['attribs']['href']['data']);
  11577. $parsed = SimplePie_Misc::parse_url($href);
  11578. if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme']))
  11579. {
  11580. if ($this->base_location < $link['offset'])
  11581. {
  11582. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->base);
  11583. }
  11584. else
  11585. {
  11586. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['href']['data']), $this->http_base);
  11587. }
  11588. $current = SimplePie_Misc::parse_url($this->file->url);
  11589. if ($parsed['authority'] === '' || $parsed['authority'] == $current['authority'])
  11590. {
  11591. $this->local[] = $href;
  11592. }
  11593. else
  11594. {
  11595. $this->elsewhere[] = $href;
  11596. }
  11597. }
  11598. }
  11599. }
  11600. $this->local = array_unique($this->local);
  11601. $this->elsewhere = array_unique($this->elsewhere);
  11602. if (!empty($this->local) || !empty($this->elsewhere))
  11603. {
  11604. return true;
  11605. }
  11606. return null;
  11607. }
  11608. function extension(&$array)
  11609. {
  11610. foreach ($array as $key => $value)
  11611. {
  11612. if ($this->checked_feeds == $this->max_checked_feeds)
  11613. {
  11614. break;
  11615. }
  11616. if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
  11617. {
  11618. $this->checked_feeds++;
  11619. $feed =& new $this->file_class($value, $this->timeout, 5, null, $this->useragent);
  11620. if ($this->is_feed($feed))
  11621. {
  11622. return $feed;
  11623. }
  11624. else
  11625. {
  11626. unset($array[$key]);
  11627. }
  11628. }
  11629. }
  11630. return null;
  11631. }
  11632. function body(&$array)
  11633. {
  11634. foreach ($array as $key => $value)
  11635. {
  11636. if ($this->checked_feeds == $this->max_checked_feeds)
  11637. {
  11638. break;
  11639. }
  11640. if (preg_match('/(rss|rdf|atom|xml)/i', $value))
  11641. {
  11642. $this->checked_feeds++;
  11643. $feed =& new $this->file_class($value, $this->timeout, 5, null, $this->useragent);
  11644. if ($this->is_feed($feed))
  11645. {
  11646. return $feed;
  11647. }
  11648. else
  11649. {
  11650. unset($array[$key]);
  11651. }
  11652. }
  11653. }
  11654. return null;
  11655. }
  11656. }
  11657. class SimplePie_Parser
  11658. {
  11659. var $error_code;
  11660. var $error_string;
  11661. var $current_line;
  11662. var $current_column;
  11663. var $current_byte;
  11664. var $separator = ' ';
  11665. var $feed = false;
  11666. var $namespace = array('');
  11667. var $element = array('');
  11668. var $xml_base = array('');
  11669. var $xml_base_explicit = array(false);
  11670. var $xml_lang = array('');
  11671. var $data = array();
  11672. var $datas = array(array());
  11673. var $current_xhtml_construct = -1;
  11674. var $encoding;
  11675. function parse(&$data, $encoding)
  11676. {
  11677. // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
  11678. if (strtoupper($encoding) == 'US-ASCII')
  11679. {
  11680. $this->encoding = 'UTF-8';
  11681. }
  11682. else
  11683. {
  11684. $this->encoding = $encoding;
  11685. }
  11686. // Strip BOM:
  11687. // UTF-32 Big Endian BOM
  11688. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  11689. {
  11690. $data = substr($data, 4);
  11691. }
  11692. // UTF-32 Little Endian BOM
  11693. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  11694. {
  11695. $data = substr($data, 4);
  11696. }
  11697. // UTF-16 Big Endian BOM
  11698. elseif (substr($data, 0, 2) === "\xFE\xFF")
  11699. {
  11700. $data = substr($data, 2);
  11701. }
  11702. // UTF-16 Little Endian BOM
  11703. elseif (substr($data, 0, 2) === "\xFF\xFE")
  11704. {
  11705. $data = substr($data, 2);
  11706. }
  11707. // UTF-8 BOM
  11708. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  11709. {
  11710. $data = substr($data, 3);
  11711. }
  11712. if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
  11713. {
  11714. $declaration = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5));
  11715. if ($declaration->parse())
  11716. {
  11717. $data = substr($data, $pos + 2);
  11718. $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
  11719. }
  11720. else
  11721. {
  11722. $this->error_string = 'SimplePie bug! Please report this!';
  11723. return false;
  11724. }
  11725. }
  11726. $return = true;
  11727. // Create the parser
  11728. $xml = xml_parser_create_ns($this->encoding, $this->separator);
  11729. xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
  11730. xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
  11731. xml_set_object($xml, $this);
  11732. xml_set_character_data_handler($xml, 'cdata');
  11733. xml_set_element_handler($xml, 'tag_open', 'tag_close');
  11734. // Parse!
  11735. if (!xml_parse($xml, $data, true))
  11736. {
  11737. $this->error_code = xml_get_error_code($xml);
  11738. $this->error_string = xml_error_string($this->error_code);
  11739. $return = false;
  11740. }
  11741. $this->current_line = xml_get_current_line_number($xml);
  11742. $this->current_column = xml_get_current_column_number($xml);
  11743. $this->current_byte = xml_get_current_byte_index($xml);
  11744. xml_parser_free($xml);
  11745. return $return;
  11746. }
  11747. function get_error_code()
  11748. {
  11749. return $this->error_code;
  11750. }
  11751. function get_error_string()
  11752. {
  11753. return $this->error_string;
  11754. }
  11755. function get_current_line()
  11756. {
  11757. return $this->current_line;
  11758. }
  11759. function get_current_column()
  11760. {
  11761. return $this->current_column;
  11762. }
  11763. function get_current_byte()
  11764. {
  11765. return $this->current_byte;
  11766. }
  11767. function get_data()
  11768. {
  11769. return $this->data;
  11770. }
  11771. function tag_open($parser, $tag, $attributes)
  11772. {
  11773. if ($this->feed === 0)
  11774. {
  11775. return;
  11776. }
  11777. elseif ($this->feed == false)
  11778. {
  11779. if (in_array($tag, array(
  11780. SIMPLEPIE_NAMESPACE_ATOM_10 . $this->separator . 'feed',
  11781. SIMPLEPIE_NAMESPACE_ATOM_03 . $this->separator . 'feed',
  11782. 'rss',
  11783. SIMPLEPIE_NAMESPACE_RDF . $this->separator . 'RDF'
  11784. )))
  11785. {
  11786. $this->feed = 1;
  11787. }
  11788. }
  11789. else
  11790. {
  11791. $this->feed++;
  11792. }
  11793. list($this->namespace[], $this->element[]) = $this->split_ns($tag);
  11794. $attribs = array();
  11795. foreach ($attributes as $name => $value)
  11796. {
  11797. list($attrib_namespace, $attribute) = $this->split_ns($name);
  11798. $attribs[$attrib_namespace][$attribute] = $value;
  11799. }
  11800. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base']))
  11801. {
  11802. $this->xml_base[] = SimplePie_Misc::absolutize_url($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base));
  11803. $this->xml_base_explicit[] = true;
  11804. }
  11805. else
  11806. {
  11807. $this->xml_base[] = end($this->xml_base);
  11808. $this->xml_base_explicit[] = end($this->xml_base_explicit);
  11809. }
  11810. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang']))
  11811. {
  11812. $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
  11813. }
  11814. else
  11815. {
  11816. $this->xml_lang[] = end($this->xml_lang);
  11817. }
  11818. if ($this->current_xhtml_construct >= 0)
  11819. {
  11820. $this->current_xhtml_construct++;
  11821. if (end($this->namespace) == SIMPLEPIE_NAMESPACE_XHTML)
  11822. {
  11823. $this->data['data'] .= '<' . end($this->element);
  11824. if (isset($attribs['']))
  11825. {
  11826. foreach ($attribs[''] as $name => $value)
  11827. {
  11828. $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
  11829. }
  11830. }
  11831. $this->data['data'] .= '>';
  11832. }
  11833. }
  11834. else
  11835. {
  11836. $this->datas[] =& $this->data;
  11837. $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
  11838. $this->data = array('data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang));
  11839. if ((end($this->namespace) == SIMPLEPIE_NAMESPACE_ATOM_03 && in_array(end($this->element), array('title', 'tagline', 'copyright', 'info', 'summary', 'content')) && isset($attribs['']['mode']) && $attribs['']['mode'] == 'xml')
  11840. || (end($this->namespace) == SIMPLEPIE_NAMESPACE_ATOM_10 && in_array(end($this->element), array('rights', 'subtitle', 'summary', 'info', 'title', 'content')) && isset($attribs['']['type']) && $attribs['']['type'] == 'xhtml'))
  11841. {
  11842. $this->current_xhtml_construct = 0;
  11843. }
  11844. }
  11845. }
  11846. function cdata($parser, $cdata)
  11847. {
  11848. if ($this->current_xhtml_construct >= 0)
  11849. {
  11850. $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
  11851. }
  11852. elseif ($this->feed > 1)
  11853. {
  11854. $this->data['data'] .= $cdata;
  11855. }
  11856. }
  11857. function tag_close($parser, $tag)
  11858. {
  11859. if (!$this->feed)
  11860. {
  11861. return;
  11862. }
  11863. if ($this->current_xhtml_construct >= 0)
  11864. {
  11865. $this->current_xhtml_construct--;
  11866. if (end($this->namespace) == SIMPLEPIE_NAMESPACE_XHTML && !in_array(end($this->element), array('area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param')))
  11867. {
  11868. $this->data['data'] .= '</' . end($this->element) . '>';
  11869. }
  11870. }
  11871. if ($this->current_xhtml_construct == -1)
  11872. {
  11873. $this->data =& $this->datas[$this->feed];
  11874. array_pop($this->datas);
  11875. }
  11876. array_pop($this->element);
  11877. array_pop($this->namespace);
  11878. array_pop($this->xml_base);
  11879. array_pop($this->xml_base_explicit);
  11880. array_pop($this->xml_lang);
  11881. $this->feed--;
  11882. }
  11883. function split_ns($string)
  11884. {
  11885. static $cache = array();
  11886. if (!isset($cache[$string]))
  11887. {
  11888. if ($pos = strpos($string, $this->separator))
  11889. {
  11890. static $separator_length;
  11891. if (!$separator_length)
  11892. {
  11893. $separator_length = strlen($this->separator);
  11894. }
  11895. $namespace = substr($string, 0, $pos);
  11896. $local_name = substr($string, $pos + $separator_length);
  11897. if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES)
  11898. {
  11899. $namespace = SIMPLEPIE_NAMESPACE_ITUNES;
  11900. }
  11901. // Normalize the Media RSS namespaces
  11902. if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG)
  11903. {
  11904. $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
  11905. }
  11906. $cache[$string] = array($namespace, $local_name);
  11907. }
  11908. else
  11909. {
  11910. $cache[$string] = array('', $string);
  11911. }
  11912. }
  11913. return $cache[$string];
  11914. }
  11915. }
  11916. /**
  11917. * @todo Move to using an actual HTML parser (this will allow tags to be properly stripped, and to switch between HTML and XHTML), this will also make it easier to shorten a string while preserving HTML tags
  11918. */
  11919. class SimplePie_Sanitize
  11920. {
  11921. // Private vars
  11922. var $base;
  11923. // Options
  11924. var $remove_div = true;
  11925. var $image_handler = '';
  11926. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  11927. var $encode_instead_of_strip = false;
  11928. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  11929. var $strip_comments = false;
  11930. var $output_encoding = 'UTF-8';
  11931. var $enable_cache = true;
  11932. var $cache_location = './cache';
  11933. var $cache_name_function = 'md5';
  11934. var $cache_class = 'SimplePie_Cache';
  11935. var $file_class = 'SimplePie_File';
  11936. var $timeout = 10;
  11937. var $useragent = '';
  11938. var $force_fsockopen = false;
  11939. var $replace_url_attributes = array(
  11940. 'a' => 'href',
  11941. 'area' => 'href',
  11942. 'blockquote' => 'cite',
  11943. 'del' => 'cite',
  11944. 'form' => 'action',
  11945. 'img' => array('longdesc', 'src'),
  11946. 'input' => 'src',
  11947. 'ins' => 'cite',
  11948. 'q' => 'cite'
  11949. );
  11950. function remove_div($enable = true)
  11951. {
  11952. $this->remove_div = (bool) $enable;
  11953. }
  11954. function set_image_handler($page = false)
  11955. {
  11956. if ($page)
  11957. {
  11958. $this->image_handler = (string) $page;
  11959. }
  11960. else
  11961. {
  11962. $this->image_handler = false;
  11963. }
  11964. }
  11965. function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
  11966. {
  11967. if (isset($enable_cache))
  11968. {
  11969. $this->enable_cache = (bool) $enable_cache;
  11970. }
  11971. if ($cache_location)
  11972. {
  11973. $this->cache_location = (string) $cache_location;
  11974. }
  11975. if ($cache_name_function)
  11976. {
  11977. $this->cache_name_function = (string) $cache_name_function;
  11978. }
  11979. if ($cache_class)
  11980. {
  11981. $this->cache_class = (string) $cache_class;
  11982. }
  11983. }
  11984. function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
  11985. {
  11986. if ($file_class)
  11987. {
  11988. $this->file_class = (string) $file_class;
  11989. }
  11990. if ($timeout)
  11991. {
  11992. $this->timeout = (string) $timeout;
  11993. }
  11994. if ($useragent)
  11995. {
  11996. $this->useragent = (string) $useragent;
  11997. }
  11998. if ($force_fsockopen)
  11999. {
  12000. $this->force_fsockopen = (string) $force_fsockopen;
  12001. }
  12002. }
  12003. function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
  12004. {
  12005. if ($tags)
  12006. {
  12007. if (is_array($tags))
  12008. {
  12009. $this->strip_htmltags = $tags;
  12010. }
  12011. else
  12012. {
  12013. $this->strip_htmltags = explode(',', $tags);
  12014. }
  12015. }
  12016. else
  12017. {
  12018. $this->strip_htmltags = false;
  12019. }
  12020. }
  12021. function encode_instead_of_strip($encode = false)
  12022. {
  12023. $this->encode_instead_of_strip = (bool) $encode;
  12024. }
  12025. function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
  12026. {
  12027. if ($attribs)
  12028. {
  12029. if (is_array($attribs))
  12030. {
  12031. $this->strip_attributes = $attribs;
  12032. }
  12033. else
  12034. {
  12035. $this->strip_attributes = explode(',', $attribs);
  12036. }
  12037. }
  12038. else
  12039. {
  12040. $this->strip_attributes = false;
  12041. }
  12042. }
  12043. function strip_comments($strip = false)
  12044. {
  12045. $this->strip_comments = (bool) $strip;
  12046. }
  12047. function set_output_encoding($encoding = 'UTF-8')
  12048. {
  12049. $this->output_encoding = (string) $encoding;
  12050. }
  12051. /**
  12052. * Set element/attribute key/value pairs of HTML attributes
  12053. * containing URLs that need to be resolved relative to the feed
  12054. *
  12055. * @access public
  12056. * @since 1.0
  12057. * @param array $element_attribute Element/attribute key/value pairs
  12058. */
  12059. 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'))
  12060. {
  12061. $this->replace_url_attributes = (array) $element_attribute;
  12062. }
  12063. function sanitize($data, $type, $base = '')
  12064. {
  12065. $data = trim($data);
  12066. if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
  12067. {
  12068. if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
  12069. {
  12070. if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>)/', $data))
  12071. {
  12072. $type |= SIMPLEPIE_CONSTRUCT_HTML;
  12073. }
  12074. else
  12075. {
  12076. $type |= SIMPLEPIE_CONSTRUCT_TEXT;
  12077. }
  12078. }
  12079. if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
  12080. {
  12081. $data = base64_decode($data);
  12082. }
  12083. if ($type & SIMPLEPIE_CONSTRUCT_XHTML)
  12084. {
  12085. if ($this->remove_div)
  12086. {
  12087. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
  12088. $data = preg_replace('/<\/div>$/', '', $data);
  12089. }
  12090. else
  12091. {
  12092. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
  12093. }
  12094. }
  12095. if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
  12096. {
  12097. // Strip comments
  12098. if ($this->strip_comments)
  12099. {
  12100. $data = SimplePie_Misc::strip_comments($data);
  12101. }
  12102. // Strip out HTML tags and attributes that might cause various security problems.
  12103. // Based on recommendations by Mark Pilgrim at:
  12104. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  12105. if ($this->strip_htmltags)
  12106. {
  12107. foreach ($this->strip_htmltags as $tag)
  12108. {
  12109. $pcre = "/<($tag)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$tag" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>|(\/)?>)/siU';
  12110. while (preg_match($pcre, $data))
  12111. {
  12112. $data = preg_replace_callback($pcre, array(&$this, 'do_strip_htmltags'), $data);
  12113. }
  12114. }
  12115. }
  12116. if ($this->strip_attributes)
  12117. {
  12118. foreach ($this->strip_attributes as $attrib)
  12119. {
  12120. $data = preg_replace('/(<[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*)' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . trim($attrib) . '(?:\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?' . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . '>/', '\1\2\3>', $data);
  12121. }
  12122. }
  12123. // Replace relative URLs
  12124. $this->base = $base;
  12125. foreach ($this->replace_url_attributes as $element => $attributes)
  12126. {
  12127. $data = $this->replace_urls($data, $element, $attributes);
  12128. }
  12129. // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
  12130. if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
  12131. {
  12132. $images = SimplePie_Misc::get_element('img', $data);
  12133. foreach ($images as $img)
  12134. {
  12135. if (isset($img['attribs']['src']['data']))
  12136. {
  12137. $image_url = call_user_func($this->cache_name_function, $img['attribs']['src']['data']);
  12138. $cache = call_user_func(array($this->cache_class, 'create'), $this->cache_location, $image_url, 'spi');
  12139. if ($cache->load())
  12140. {
  12141. $img['attribs']['src']['data'] = $this->image_handler . $image_url;
  12142. $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
  12143. }
  12144. else
  12145. {
  12146. $file =& new $this->file_class($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);
  12147. $headers = $file->headers;
  12148. if ($file->success && ($file->status_code == 200 || ($file->status_code > 206 && $file->status_code < 300)))
  12149. {
  12150. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  12151. {
  12152. $img['attribs']['src']['data'] = $this->image_handler . $image_url;
  12153. $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
  12154. }
  12155. else
  12156. {
  12157. trigger_error("$cache->name is not writeable", E_USER_WARNING);
  12158. }
  12159. }
  12160. }
  12161. }
  12162. }
  12163. }
  12164. // Having (possibly) taken stuff out, there may now be whitespace at the beginning/end of the data
  12165. $data = trim($data);
  12166. }
  12167. if ($type & SIMPLEPIE_CONSTRUCT_IRI)
  12168. {
  12169. $data = SimplePie_Misc::absolutize_url($data, $base);
  12170. }
  12171. if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
  12172. {
  12173. $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
  12174. }
  12175. if ($this->output_encoding != 'UTF-8')
  12176. {
  12177. $data = SimplePie_Misc::change_encoding($data, 'UTF-8', $this->output_encoding);
  12178. }
  12179. }
  12180. return $data;
  12181. }
  12182. function replace_urls($data, $tag, $attributes)
  12183. {
  12184. if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
  12185. {
  12186. $elements = SimplePie_Misc::get_element($tag, $data);
  12187. foreach ($elements as $element)
  12188. {
  12189. if (is_array($attributes))
  12190. {
  12191. foreach ($attributes as $attribute)
  12192. {
  12193. if (isset($element['attribs'][$attribute]['data']))
  12194. {
  12195. $element['attribs'][$attribute]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attribute]['data'], $this->base);
  12196. $new_element = SimplePie_Misc::element_implode($element);
  12197. $data = str_replace($element['full'], $new_element, $data);
  12198. $element['full'] = $new_element;
  12199. }
  12200. }
  12201. }
  12202. elseif (isset($element['attribs'][$attributes]['data']))
  12203. {
  12204. $element['attribs'][$attributes]['data'] = SimplePie_Misc::absolutize_url($element['attribs'][$attributes]['data'], $this->base);
  12205. $data = str_replace($element['full'], SimplePie_Misc::element_implode($element), $data);
  12206. }
  12207. }
  12208. }
  12209. return $data;
  12210. }
  12211. function do_strip_htmltags($match)
  12212. {
  12213. if ($this->encode_instead_of_strip)
  12214. {
  12215. if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  12216. {
  12217. $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
  12218. $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
  12219. return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
  12220. }
  12221. else
  12222. {
  12223. return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
  12224. }
  12225. }
  12226. elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  12227. {
  12228. return $match[4];
  12229. }
  12230. else
  12231. {
  12232. return '';
  12233. }
  12234. }
  12235. }
  12236. ?>