PageRenderTime 68ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 3ms

/concrete/libraries/3rdparty/simplepie.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 17768 lines | 14010 code | 754 blank | 3004 comment | 1010 complexity | a29a41693f4d51c686c3776265d0b549 MD5 | raw file
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Please note: This file is automatically generated by a build script. The
  9. * full original source is always available from http://simplepie.org/
  10. *
  11. * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without modification, are
  15. * permitted provided that the following conditions are met:
  16. *
  17. * * Redistributions of source code must retain the above copyright notice, this list of
  18. * conditions and the following disclaimer.
  19. *
  20. * * Redistributions in binary form must reproduce the above copyright notice, this list
  21. * of conditions and the following disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  25. * to endorse or promote products derived from this software without specific prior
  26. * written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  30. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  31. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  33. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  35. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * @package SimplePie
  39. * @version 1.3.1
  40. * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  41. * @author Ryan Parman
  42. * @author Geoffrey Sneddon
  43. * @author Ryan McCue
  44. * @link http://simplepie.org/ SimplePie
  45. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  46. */
  47. /**
  48. * SimplePie Name
  49. */
  50. define('SIMPLEPIE_NAME', 'SimplePie');
  51. /**
  52. * SimplePie Version
  53. */
  54. define('SIMPLEPIE_VERSION', '1.3.1');
  55. /**
  56. * SimplePie Build
  57. * @todo Hardcode for release (there's no need to have to call SimplePie_Misc::get_build() only every load of simplepie.inc)
  58. */
  59. define('SIMPLEPIE_BUILD', '20130712202041');
  60. /**
  61. * SimplePie Website URL
  62. */
  63. define('SIMPLEPIE_URL', 'http://simplepie.org');
  64. /**
  65. * SimplePie Useragent
  66. * @see SimplePie::set_useragent()
  67. */
  68. define('SIMPLEPIE_USERAGENT', SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION . ' (Feed Parser; ' . SIMPLEPIE_URL . '; Allow like Gecko) Build/' . SIMPLEPIE_BUILD);
  69. /**
  70. * SimplePie Linkback
  71. */
  72. define('SIMPLEPIE_LINKBACK', '<a href="' . SIMPLEPIE_URL . '" title="' . SIMPLEPIE_NAME . ' ' . SIMPLEPIE_VERSION . '">' . SIMPLEPIE_NAME . '</a>');
  73. /**
  74. * No Autodiscovery
  75. * @see SimplePie::set_autodiscovery_level()
  76. */
  77. define('SIMPLEPIE_LOCATOR_NONE', 0);
  78. /**
  79. * Feed Link Element Autodiscovery
  80. * @see SimplePie::set_autodiscovery_level()
  81. */
  82. define('SIMPLEPIE_LOCATOR_AUTODISCOVERY', 1);
  83. /**
  84. * Local Feed Extension Autodiscovery
  85. * @see SimplePie::set_autodiscovery_level()
  86. */
  87. define('SIMPLEPIE_LOCATOR_LOCAL_EXTENSION', 2);
  88. /**
  89. * Local Feed Body Autodiscovery
  90. * @see SimplePie::set_autodiscovery_level()
  91. */
  92. define('SIMPLEPIE_LOCATOR_LOCAL_BODY', 4);
  93. /**
  94. * Remote Feed Extension Autodiscovery
  95. * @see SimplePie::set_autodiscovery_level()
  96. */
  97. define('SIMPLEPIE_LOCATOR_REMOTE_EXTENSION', 8);
  98. /**
  99. * Remote Feed Body Autodiscovery
  100. * @see SimplePie::set_autodiscovery_level()
  101. */
  102. define('SIMPLEPIE_LOCATOR_REMOTE_BODY', 16);
  103. /**
  104. * All Feed Autodiscovery
  105. * @see SimplePie::set_autodiscovery_level()
  106. */
  107. define('SIMPLEPIE_LOCATOR_ALL', 31);
  108. /**
  109. * No known feed type
  110. */
  111. define('SIMPLEPIE_TYPE_NONE', 0);
  112. /**
  113. * RSS 0.90
  114. */
  115. define('SIMPLEPIE_TYPE_RSS_090', 1);
  116. /**
  117. * RSS 0.91 (Netscape)
  118. */
  119. define('SIMPLEPIE_TYPE_RSS_091_NETSCAPE', 2);
  120. /**
  121. * RSS 0.91 (Userland)
  122. */
  123. define('SIMPLEPIE_TYPE_RSS_091_USERLAND', 4);
  124. /**
  125. * RSS 0.91 (both Netscape and Userland)
  126. */
  127. define('SIMPLEPIE_TYPE_RSS_091', 6);
  128. /**
  129. * RSS 0.92
  130. */
  131. define('SIMPLEPIE_TYPE_RSS_092', 8);
  132. /**
  133. * RSS 0.93
  134. */
  135. define('SIMPLEPIE_TYPE_RSS_093', 16);
  136. /**
  137. * RSS 0.94
  138. */
  139. define('SIMPLEPIE_TYPE_RSS_094', 32);
  140. /**
  141. * RSS 1.0
  142. */
  143. define('SIMPLEPIE_TYPE_RSS_10', 64);
  144. /**
  145. * RSS 2.0
  146. */
  147. define('SIMPLEPIE_TYPE_RSS_20', 128);
  148. /**
  149. * RDF-based RSS
  150. */
  151. define('SIMPLEPIE_TYPE_RSS_RDF', 65);
  152. /**
  153. * Non-RDF-based RSS (truly intended as syndication format)
  154. */
  155. define('SIMPLEPIE_TYPE_RSS_SYNDICATION', 190);
  156. /**
  157. * All RSS
  158. */
  159. define('SIMPLEPIE_TYPE_RSS_ALL', 255);
  160. /**
  161. * Atom 0.3
  162. */
  163. define('SIMPLEPIE_TYPE_ATOM_03', 256);
  164. /**
  165. * Atom 1.0
  166. */
  167. define('SIMPLEPIE_TYPE_ATOM_10', 512);
  168. /**
  169. * All Atom
  170. */
  171. define('SIMPLEPIE_TYPE_ATOM_ALL', 768);
  172. /**
  173. * All feed types
  174. */
  175. define('SIMPLEPIE_TYPE_ALL', 1023);
  176. /**
  177. * No construct
  178. */
  179. define('SIMPLEPIE_CONSTRUCT_NONE', 0);
  180. /**
  181. * Text construct
  182. */
  183. define('SIMPLEPIE_CONSTRUCT_TEXT', 1);
  184. /**
  185. * HTML construct
  186. */
  187. define('SIMPLEPIE_CONSTRUCT_HTML', 2);
  188. /**
  189. * XHTML construct
  190. */
  191. define('SIMPLEPIE_CONSTRUCT_XHTML', 4);
  192. /**
  193. * base64-encoded construct
  194. */
  195. define('SIMPLEPIE_CONSTRUCT_BASE64', 8);
  196. /**
  197. * IRI construct
  198. */
  199. define('SIMPLEPIE_CONSTRUCT_IRI', 16);
  200. /**
  201. * A construct that might be HTML
  202. */
  203. define('SIMPLEPIE_CONSTRUCT_MAYBE_HTML', 32);
  204. /**
  205. * All constructs
  206. */
  207. define('SIMPLEPIE_CONSTRUCT_ALL', 63);
  208. /**
  209. * Don't change case
  210. */
  211. define('SIMPLEPIE_SAME_CASE', 1);
  212. /**
  213. * Change to lowercase
  214. */
  215. define('SIMPLEPIE_LOWERCASE', 2);
  216. /**
  217. * Change to uppercase
  218. */
  219. define('SIMPLEPIE_UPPERCASE', 4);
  220. /**
  221. * PCRE for HTML attributes
  222. */
  223. 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]*');
  224. /**
  225. * PCRE for XML attributes
  226. */
  227. define('SIMPLEPIE_PCRE_XML_ATTRIBUTE', '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*');
  228. /**
  229. * XML Namespace
  230. */
  231. define('SIMPLEPIE_NAMESPACE_XML', 'http://www.w3.org/XML/1998/namespace');
  232. /**
  233. * Atom 1.0 Namespace
  234. */
  235. define('SIMPLEPIE_NAMESPACE_ATOM_10', 'http://www.w3.org/2005/Atom');
  236. /**
  237. * Atom 0.3 Namespace
  238. */
  239. define('SIMPLEPIE_NAMESPACE_ATOM_03', 'http://purl.org/atom/ns#');
  240. /**
  241. * RDF Namespace
  242. */
  243. define('SIMPLEPIE_NAMESPACE_RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
  244. /**
  245. * RSS 0.90 Namespace
  246. */
  247. define('SIMPLEPIE_NAMESPACE_RSS_090', 'http://my.netscape.com/rdf/simple/0.9/');
  248. /**
  249. * RSS 1.0 Namespace
  250. */
  251. define('SIMPLEPIE_NAMESPACE_RSS_10', 'http://purl.org/rss/1.0/');
  252. /**
  253. * RSS 1.0 Content Module Namespace
  254. */
  255. define('SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT', 'http://purl.org/rss/1.0/modules/content/');
  256. /**
  257. * RSS 2.0 Namespace
  258. * (Stupid, I know, but I'm certain it will confuse people less with support.)
  259. */
  260. define('SIMPLEPIE_NAMESPACE_RSS_20', '');
  261. /**
  262. * DC 1.0 Namespace
  263. */
  264. define('SIMPLEPIE_NAMESPACE_DC_10', 'http://purl.org/dc/elements/1.0/');
  265. /**
  266. * DC 1.1 Namespace
  267. */
  268. define('SIMPLEPIE_NAMESPACE_DC_11', 'http://purl.org/dc/elements/1.1/');
  269. /**
  270. * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace
  271. */
  272. define('SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
  273. /**
  274. * GeoRSS Namespace
  275. */
  276. define('SIMPLEPIE_NAMESPACE_GEORSS', 'http://www.georss.org/georss');
  277. /**
  278. * Media RSS Namespace
  279. */
  280. define('SIMPLEPIE_NAMESPACE_MEDIARSS', 'http://search.yahoo.com/mrss/');
  281. /**
  282. * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec.
  283. */
  284. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG', 'http://search.yahoo.com/mrss');
  285. /**
  286. * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5.
  287. */
  288. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2', 'http://video.search.yahoo.com/mrss');
  289. /**
  290. * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace.
  291. */
  292. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3', 'http://video.search.yahoo.com/mrss/');
  293. /**
  294. * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace.
  295. */
  296. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4', 'http://www.rssboard.org/media-rss');
  297. /**
  298. * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL.
  299. */
  300. define('SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5', 'http://www.rssboard.org/media-rss/');
  301. /**
  302. * iTunes RSS Namespace
  303. */
  304. define('SIMPLEPIE_NAMESPACE_ITUNES', 'http://www.itunes.com/dtds/podcast-1.0.dtd');
  305. /**
  306. * XHTML Namespace
  307. */
  308. define('SIMPLEPIE_NAMESPACE_XHTML', 'http://www.w3.org/1999/xhtml');
  309. /**
  310. * IANA Link Relations Registry
  311. */
  312. define('SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY', 'http://www.iana.org/assignments/relation/');
  313. /**
  314. * No file source
  315. */
  316. define('SIMPLEPIE_FILE_SOURCE_NONE', 0);
  317. /**
  318. * Remote file source
  319. */
  320. define('SIMPLEPIE_FILE_SOURCE_REMOTE', 1);
  321. /**
  322. * Local file source
  323. */
  324. define('SIMPLEPIE_FILE_SOURCE_LOCAL', 2);
  325. /**
  326. * fsockopen() file source
  327. */
  328. define('SIMPLEPIE_FILE_SOURCE_FSOCKOPEN', 4);
  329. /**
  330. * cURL file source
  331. */
  332. define('SIMPLEPIE_FILE_SOURCE_CURL', 8);
  333. /**
  334. * file_get_contents() file source
  335. */
  336. define('SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS', 16);
  337. /**
  338. * SimplePie
  339. *
  340. * @package SimplePie
  341. * @subpackage API
  342. */
  343. class SimplePie
  344. {
  345. /**
  346. * @var array Raw data
  347. * @access private
  348. */
  349. public $data = array();
  350. /**
  351. * @var mixed Error string
  352. * @access private
  353. */
  354. public $error;
  355. /**
  356. * @var object Instance of SimplePie_Sanitize (or other class)
  357. * @see SimplePie::set_sanitize_class()
  358. * @access private
  359. */
  360. public $sanitize;
  361. /**
  362. * @var string SimplePie Useragent
  363. * @see SimplePie::set_useragent()
  364. * @access private
  365. */
  366. public $useragent = SIMPLEPIE_USERAGENT;
  367. /**
  368. * @var string Feed URL
  369. * @see SimplePie::set_feed_url()
  370. * @access private
  371. */
  372. public $feed_url;
  373. /**
  374. * @var object Instance of SimplePie_File to use as a feed
  375. * @see SimplePie::set_file()
  376. * @access private
  377. */
  378. public $file;
  379. /**
  380. * @var string Raw feed data
  381. * @see SimplePie::set_raw_data()
  382. * @access private
  383. */
  384. public $raw_data;
  385. /**
  386. * @var int Timeout for fetching remote files
  387. * @see SimplePie::set_timeout()
  388. * @access private
  389. */
  390. public $timeout = 10;
  391. /**
  392. * @var bool Forces fsockopen() to be used for remote files instead
  393. * of cURL, even if a new enough version is installed
  394. * @see SimplePie::force_fsockopen()
  395. * @access private
  396. */
  397. public $force_fsockopen = false;
  398. /**
  399. * @var bool Force the given data/URL to be treated as a feed no matter what
  400. * it appears like
  401. * @see SimplePie::force_feed()
  402. * @access private
  403. */
  404. public $force_feed = false;
  405. /**
  406. * @var bool Enable/Disable Caching
  407. * @see SimplePie::enable_cache()
  408. * @access private
  409. */
  410. public $cache = true;
  411. /**
  412. * @var int Cache duration (in seconds)
  413. * @see SimplePie::set_cache_duration()
  414. * @access private
  415. */
  416. public $cache_duration = 3600;
  417. /**
  418. * @var int Auto-discovery cache duration (in seconds)
  419. * @see SimplePie::set_autodiscovery_cache_duration()
  420. * @access private
  421. */
  422. public $autodiscovery_cache_duration = 604800; // 7 Days.
  423. /**
  424. * @var string Cache location (relative to executing script)
  425. * @see SimplePie::set_cache_location()
  426. * @access private
  427. */
  428. public $cache_location = './cache';
  429. /**
  430. * @var string Function that creates the cache filename
  431. * @see SimplePie::set_cache_name_function()
  432. * @access private
  433. */
  434. public $cache_name_function = 'md5';
  435. /**
  436. * @var bool Reorder feed by date descending
  437. * @see SimplePie::enable_order_by_date()
  438. * @access private
  439. */
  440. public $order_by_date = true;
  441. /**
  442. * @var mixed Force input encoding to be set to the follow value
  443. * (false, or anything type-cast to false, disables this feature)
  444. * @see SimplePie::set_input_encoding()
  445. * @access private
  446. */
  447. public $input_encoding = false;
  448. /**
  449. * @var int Feed Autodiscovery Level
  450. * @see SimplePie::set_autodiscovery_level()
  451. * @access private
  452. */
  453. public $autodiscovery = SIMPLEPIE_LOCATOR_ALL;
  454. /**
  455. * Class registry object
  456. *
  457. * @var SimplePie_Registry
  458. */
  459. public $registry;
  460. /**
  461. * @var int Maximum number of feeds to check with autodiscovery
  462. * @see SimplePie::set_max_checked_feeds()
  463. * @access private
  464. */
  465. public $max_checked_feeds = 10;
  466. /**
  467. * @var array All the feeds found during the autodiscovery process
  468. * @see SimplePie::get_all_discovered_feeds()
  469. * @access private
  470. */
  471. public $all_discovered_feeds = array();
  472. /**
  473. * @var string Web-accessible path to the handler_image.php file.
  474. * @see SimplePie::set_image_handler()
  475. * @access private
  476. */
  477. public $image_handler = '';
  478. /**
  479. * @var array Stores the URLs when multiple feeds are being initialized.
  480. * @see SimplePie::set_feed_url()
  481. * @access private
  482. */
  483. public $multifeed_url = array();
  484. /**
  485. * @var array Stores SimplePie objects when multiple feeds initialized.
  486. * @access private
  487. */
  488. public $multifeed_objects = array();
  489. /**
  490. * @var array Stores the get_object_vars() array for use with multifeeds.
  491. * @see SimplePie::set_feed_url()
  492. * @access private
  493. */
  494. public $config_settings = null;
  495. /**
  496. * @var integer Stores the number of items to return per-feed with multifeeds.
  497. * @see SimplePie::set_item_limit()
  498. * @access private
  499. */
  500. public $item_limit = 0;
  501. /**
  502. * @var array Stores the default attributes to be stripped by strip_attributes().
  503. * @see SimplePie::strip_attributes()
  504. * @access private
  505. */
  506. public $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  507. /**
  508. * @var array Stores the default tags to be stripped by strip_htmltags().
  509. * @see SimplePie::strip_htmltags()
  510. * @access private
  511. */
  512. public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  513. /**
  514. * The SimplePie class contains feed level data and options
  515. *
  516. * To use SimplePie, create the SimplePie object with no parameters. You can
  517. * then set configuration options using the provided methods. After setting
  518. * them, you must initialise the feed using $feed->init(). At that point the
  519. * object's methods and properties will be available to you.
  520. *
  521. * Previously, it was possible to pass in the feed URL along with cache
  522. * options directly into the constructor. This has been removed as of 1.3 as
  523. * it caused a lot of confusion.
  524. *
  525. * @since 1.0 Preview Release
  526. */
  527. public function __construct()
  528. {
  529. if (version_compare(PHP_VERSION, '5.2', '<'))
  530. {
  531. trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
  532. die();
  533. }
  534. // Other objects, instances created here so we can set options on them
  535. $this->sanitize = new SimplePie_Sanitize();
  536. $this->registry = new SimplePie_Registry();
  537. if (func_num_args() > 0)
  538. {
  539. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  540. trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.', $level);
  541. $args = func_get_args();
  542. switch (count($args)) {
  543. case 3:
  544. $this->set_cache_duration($args[2]);
  545. case 2:
  546. $this->set_cache_location($args[1]);
  547. case 1:
  548. $this->set_feed_url($args[0]);
  549. $this->init();
  550. }
  551. }
  552. }
  553. /**
  554. * Used for converting object to a string
  555. */
  556. public function __toString()
  557. {
  558. return md5(serialize($this->data));
  559. }
  560. /**
  561. * Remove items that link back to this before destroying this object
  562. */
  563. public function __destruct()
  564. {
  565. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  566. {
  567. if (!empty($this->data['items']))
  568. {
  569. foreach ($this->data['items'] as $item)
  570. {
  571. $item->__destruct();
  572. }
  573. unset($item, $this->data['items']);
  574. }
  575. if (!empty($this->data['ordered_items']))
  576. {
  577. foreach ($this->data['ordered_items'] as $item)
  578. {
  579. $item->__destruct();
  580. }
  581. unset($item, $this->data['ordered_items']);
  582. }
  583. }
  584. }
  585. /**
  586. * Force the given data/URL to be treated as a feed
  587. *
  588. * This tells SimplePie to ignore the content-type provided by the server.
  589. * Be careful when using this option, as it will also disable autodiscovery.
  590. *
  591. * @since 1.1
  592. * @param bool $enable Force the given data/URL to be treated as a feed
  593. */
  594. public function force_feed($enable = false)
  595. {
  596. $this->force_feed = (bool) $enable;
  597. }
  598. /**
  599. * Set the URL of the feed you want to parse
  600. *
  601. * This allows you to enter the URL of the feed you want to parse, or the
  602. * website you want to try to use auto-discovery on. This takes priority
  603. * over any set raw data.
  604. *
  605. * You can set multiple feeds to mash together by passing an array instead
  606. * of a string for the $url. Remember that with each additional feed comes
  607. * additional processing and resources.
  608. *
  609. * @since 1.0 Preview Release
  610. * @see set_raw_data()
  611. * @param string|array $url This is the URL (or array of URLs) that you want to parse.
  612. */
  613. public function set_feed_url($url)
  614. {
  615. $this->multifeed_url = array();
  616. if (is_array($url))
  617. {
  618. foreach ($url as $value)
  619. {
  620. $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', array($value, 1));
  621. }
  622. }
  623. else
  624. {
  625. $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
  626. }
  627. }
  628. /**
  629. * Set an instance of {@see SimplePie_File} to use as a feed
  630. *
  631. * @param SimplePie_File &$file
  632. * @return bool True on success, false on failure
  633. */
  634. public function set_file(&$file)
  635. {
  636. if ($file instanceof SimplePie_File)
  637. {
  638. $this->feed_url = $file->url;
  639. $this->file =& $file;
  640. return true;
  641. }
  642. return false;
  643. }
  644. /**
  645. * Set the raw XML data to parse
  646. *
  647. * Allows you to use a string of RSS/Atom data instead of a remote feed.
  648. *
  649. * If you have a feed available as a string in PHP, you can tell SimplePie
  650. * to parse that data string instead of a remote feed. Any set feed URL
  651. * takes precedence.
  652. *
  653. * @since 1.0 Beta 3
  654. * @param string $data RSS or Atom data as a string.
  655. * @see set_feed_url()
  656. */
  657. public function set_raw_data($data)
  658. {
  659. $this->raw_data = $data;
  660. }
  661. /**
  662. * Set the the default timeout for fetching remote feeds
  663. *
  664. * This allows you to change the maximum time the feed's server to respond
  665. * and send the feed back.
  666. *
  667. * @since 1.0 Beta 3
  668. * @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
  669. */
  670. public function set_timeout($timeout = 10)
  671. {
  672. $this->timeout = (int) $timeout;
  673. }
  674. /**
  675. * Force SimplePie to use fsockopen() instead of cURL
  676. *
  677. * @since 1.0 Beta 3
  678. * @param bool $enable Force fsockopen() to be used
  679. */
  680. public function force_fsockopen($enable = false)
  681. {
  682. $this->force_fsockopen = (bool) $enable;
  683. }
  684. /**
  685. * Enable/disable caching in SimplePie.
  686. *
  687. * This option allows you to disable caching all-together in SimplePie.
  688. * However, disabling the cache can lead to longer load times.
  689. *
  690. * @since 1.0 Preview Release
  691. * @param bool $enable Enable caching
  692. */
  693. public function enable_cache($enable = true)
  694. {
  695. $this->cache = (bool) $enable;
  696. }
  697. /**
  698. * Set the length of time (in seconds) that the contents of a feed will be
  699. * cached
  700. *
  701. * @param int $seconds The feed content cache duration
  702. */
  703. public function set_cache_duration($seconds = 3600)
  704. {
  705. $this->cache_duration = (int) $seconds;
  706. }
  707. /**
  708. * Set the length of time (in seconds) that the autodiscovered feed URL will
  709. * be cached
  710. *
  711. * @param int $seconds The autodiscovered feed URL cache duration.
  712. */
  713. public function set_autodiscovery_cache_duration($seconds = 604800)
  714. {
  715. $this->autodiscovery_cache_duration = (int) $seconds;
  716. }
  717. /**
  718. * Set the file system location where the cached files should be stored
  719. *
  720. * @param string $location The file system location.
  721. */
  722. public function set_cache_location($location = './cache')
  723. {
  724. $this->cache_location = (string) $location;
  725. }
  726. /**
  727. * Set whether feed items should be sorted into reverse chronological order
  728. *
  729. * @param bool $enable Sort as reverse chronological order.
  730. */
  731. public function enable_order_by_date($enable = true)
  732. {
  733. $this->order_by_date = (bool) $enable;
  734. }
  735. /**
  736. * Set the character encoding used to parse the feed
  737. *
  738. * This overrides the encoding reported by the feed, however it will fall
  739. * back to the normal encoding detection if the override fails
  740. *
  741. * @param string $encoding Character encoding
  742. */
  743. public function set_input_encoding($encoding = false)
  744. {
  745. if ($encoding)
  746. {
  747. $this->input_encoding = (string) $encoding;
  748. }
  749. else
  750. {
  751. $this->input_encoding = false;
  752. }
  753. }
  754. /**
  755. * Set how much feed autodiscovery to do
  756. *
  757. * @see SIMPLEPIE_LOCATOR_NONE
  758. * @see SIMPLEPIE_LOCATOR_AUTODISCOVERY
  759. * @see SIMPLEPIE_LOCATOR_LOCAL_EXTENSION
  760. * @see SIMPLEPIE_LOCATOR_LOCAL_BODY
  761. * @see SIMPLEPIE_LOCATOR_REMOTE_EXTENSION
  762. * @see SIMPLEPIE_LOCATOR_REMOTE_BODY
  763. * @see SIMPLEPIE_LOCATOR_ALL
  764. * @param int $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator)
  765. */
  766. public function set_autodiscovery_level($level = SIMPLEPIE_LOCATOR_ALL)
  767. {
  768. $this->autodiscovery = (int) $level;
  769. }
  770. /**
  771. * Get the class registry
  772. *
  773. * Use this to override SimplePie's default classes
  774. * @see SimplePie_Registry
  775. * @return SimplePie_Registry
  776. */
  777. public function &get_registry()
  778. {
  779. return $this->registry;
  780. }
  781. /**#@+
  782. * Useful when you are overloading or extending SimplePie's default classes.
  783. *
  784. * @deprecated Use {@see get_registry()} instead
  785. * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation
  786. * @param string $class Name of custom class
  787. * @return boolean True on success, false otherwise
  788. */
  789. /**
  790. * Set which class SimplePie uses for caching
  791. */
  792. public function set_cache_class($class = 'SimplePie_Cache')
  793. {
  794. return $this->registry->register('Cache', $class, true);
  795. }
  796. /**
  797. * Set which class SimplePie uses for auto-discovery
  798. */
  799. public function set_locator_class($class = 'SimplePie_Locator')
  800. {
  801. return $this->registry->register('Locator', $class, true);
  802. }
  803. /**
  804. * Set which class SimplePie uses for XML parsing
  805. */
  806. public function set_parser_class($class = 'SimplePie_Parser')
  807. {
  808. return $this->registry->register('Parser', $class, true);
  809. }
  810. /**
  811. * Set which class SimplePie uses for remote file fetching
  812. */
  813. public function set_file_class($class = 'SimplePie_File')
  814. {
  815. return $this->registry->register('File', $class, true);
  816. }
  817. /**
  818. * Set which class SimplePie uses for data sanitization
  819. */
  820. public function set_sanitize_class($class = 'SimplePie_Sanitize')
  821. {
  822. return $this->registry->register('Sanitize', $class, true);
  823. }
  824. /**
  825. * Set which class SimplePie uses for handling feed items
  826. */
  827. public function set_item_class($class = 'SimplePie_Item')
  828. {
  829. return $this->registry->register('Item', $class, true);
  830. }
  831. /**
  832. * Set which class SimplePie uses for handling author data
  833. */
  834. public function set_author_class($class = 'SimplePie_Author')
  835. {
  836. return $this->registry->register('Author', $class, true);
  837. }
  838. /**
  839. * Set which class SimplePie uses for handling category data
  840. */
  841. public function set_category_class($class = 'SimplePie_Category')
  842. {
  843. return $this->registry->register('Category', $class, true);
  844. }
  845. /**
  846. * Set which class SimplePie uses for feed enclosures
  847. */
  848. public function set_enclosure_class($class = 'SimplePie_Enclosure')
  849. {
  850. return $this->registry->register('Enclosure', $class, true);
  851. }
  852. /**
  853. * Set which class SimplePie uses for `<media:text>` captions
  854. */
  855. public function set_caption_class($class = 'SimplePie_Caption')
  856. {
  857. return $this->registry->register('Caption', $class, true);
  858. }
  859. /**
  860. * Set which class SimplePie uses for `<media:copyright>`
  861. */
  862. public function set_copyright_class($class = 'SimplePie_Copyright')
  863. {
  864. return $this->registry->register('Copyright', $class, true);
  865. }
  866. /**
  867. * Set which class SimplePie uses for `<media:credit>`
  868. */
  869. public function set_credit_class($class = 'SimplePie_Credit')
  870. {
  871. return $this->registry->register('Credit', $class, true);
  872. }
  873. /**
  874. * Set which class SimplePie uses for `<media:rating>`
  875. */
  876. public function set_rating_class($class = 'SimplePie_Rating')
  877. {
  878. return $this->registry->register('Rating', $class, true);
  879. }
  880. /**
  881. * Set which class SimplePie uses for `<media:restriction>`
  882. */
  883. public function set_restriction_class($class = 'SimplePie_Restriction')
  884. {
  885. return $this->registry->register('Restriction', $class, true);
  886. }
  887. /**
  888. * Set which class SimplePie uses for content-type sniffing
  889. */
  890. public function set_content_type_sniffer_class($class = 'SimplePie_Content_Type_Sniffer')
  891. {
  892. return $this->registry->register('Content_Type_Sniffer', $class, true);
  893. }
  894. /**
  895. * Set which class SimplePie uses item sources
  896. */
  897. public function set_source_class($class = 'SimplePie_Source')
  898. {
  899. return $this->registry->register('Source', $class, true);
  900. }
  901. /**#@-*/
  902. /**
  903. * Set the user agent string
  904. *
  905. * @param string $ua New user agent string.
  906. */
  907. public function set_useragent($ua = SIMPLEPIE_USERAGENT)
  908. {
  909. $this->useragent = (string) $ua;
  910. }
  911. /**
  912. * Set callback function to create cache filename with
  913. *
  914. * @param mixed $function Callback function
  915. */
  916. public function set_cache_name_function($function = 'md5')
  917. {
  918. if (is_callable($function))
  919. {
  920. $this->cache_name_function = $function;
  921. }
  922. }
  923. /**
  924. * Set options to make SP as fast as possible
  925. *
  926. * Forgoes a substantial amount of data sanitization in favor of speed. This
  927. * turns SimplePie into a dumb parser of feeds.
  928. *
  929. * @param bool $set Whether to set them or not
  930. */
  931. public function set_stupidly_fast($set = false)
  932. {
  933. if ($set)
  934. {
  935. $this->enable_order_by_date(false);
  936. $this->remove_div(false);
  937. $this->strip_comments(false);
  938. $this->strip_htmltags(false);
  939. $this->strip_attributes(false);
  940. $this->set_image_handler(false);
  941. }
  942. }
  943. /**
  944. * Set maximum number of feeds to check with autodiscovery
  945. *
  946. * @param int $max Maximum number of feeds to check
  947. */
  948. public function set_max_checked_feeds($max = 10)
  949. {
  950. $this->max_checked_feeds = (int) $max;
  951. }
  952. public function remove_div($enable = true)
  953. {
  954. $this->sanitize->remove_div($enable);
  955. }
  956. public function strip_htmltags($tags = '', $encode = null)
  957. {
  958. if ($tags === '')
  959. {
  960. $tags = $this->strip_htmltags;
  961. }
  962. $this->sanitize->strip_htmltags($tags);
  963. if ($encode !== null)
  964. {
  965. $this->sanitize->encode_instead_of_strip($tags);
  966. }
  967. }
  968. public function encode_instead_of_strip($enable = true)
  969. {
  970. $this->sanitize->encode_instead_of_strip($enable);
  971. }
  972. public function strip_attributes($attribs = '')
  973. {
  974. if ($attribs === '')
  975. {
  976. $attribs = $this->strip_attributes;
  977. }
  978. $this->sanitize->strip_attributes($attribs);
  979. }
  980. /**
  981. * Set the output encoding
  982. *
  983. * Allows you to override SimplePie's output to match that of your webpage.
  984. * This is useful for times when your webpages are not being served as
  985. * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and
  986. * is similar to {@see set_input_encoding()}.
  987. *
  988. * It should be noted, however, that not all character encodings can support
  989. * all characters. If your page is being served as ISO-8859-1 and you try
  990. * to display a Japanese feed, you'll likely see garbled characters.
  991. * Because of this, it is highly recommended to ensure that your webpages
  992. * are served as UTF-8.
  993. *
  994. * The number of supported character encodings depends on whether your web
  995. * host supports {@link http://php.net/mbstring mbstring},
  996. * {@link http://php.net/iconv iconv}, or both. See
  997. * {@link http://simplepie.org/wiki/faq/Supported_Character_Encodings} for
  998. * more information.
  999. *
  1000. * @param string $encoding
  1001. */
  1002. public function set_output_encoding($encoding = 'UTF-8')
  1003. {
  1004. $this->sanitize->set_output_encoding($encoding);
  1005. }
  1006. public function strip_comments($strip = false)
  1007. {
  1008. $this->sanitize->strip_comments($strip);
  1009. }
  1010. /**
  1011. * Set element/attribute key/value pairs of HTML attributes
  1012. * containing URLs that need to be resolved relative to the feed
  1013. *
  1014. * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
  1015. * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
  1016. * |q|@cite
  1017. *
  1018. * @since 1.0
  1019. * @param array|null $element_attribute Element/attribute key/value pairs, null for default
  1020. */
  1021. public function set_url_replacements($element_attribute = null)
  1022. {
  1023. $this->sanitize->set_url_replacements($element_attribute);
  1024. }
  1025. /**
  1026. * Set the handler to enable the display of cached images.
  1027. *
  1028. * @param str $page Web-accessible path to the handler_image.php file.
  1029. * @param str $qs The query string that the value should be passed to.
  1030. */
  1031. public function set_image_handler($page = false, $qs = 'i')
  1032. {
  1033. if ($page !== false)
  1034. {
  1035. $this->sanitize->set_image_handler($page . '?' . $qs . '=');
  1036. }
  1037. else
  1038. {
  1039. $this->image_handler = '';
  1040. }
  1041. }
  1042. /**
  1043. * Set the limit for items returned per-feed with multifeeds
  1044. *
  1045. * @param integer $limit The maximum number of items to return.
  1046. */
  1047. public function set_item_limit($limit = 0)
  1048. {
  1049. $this->item_limit = (int) $limit;
  1050. }
  1051. /**
  1052. * Initialize the feed object
  1053. *
  1054. * This is what makes everything happen. Period. This is where all of the
  1055. * configuration options get processed, feeds are fetched, cached, and
  1056. * parsed, and all of that other good stuff.
  1057. *
  1058. * @return boolean True if successful, false otherwise
  1059. */
  1060. public function init()
  1061. {
  1062. // Check absolute bare minimum requirements.
  1063. if (!extension_loaded('xml') || !extension_loaded('pcre'))
  1064. {
  1065. return false;
  1066. }
  1067. // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.
  1068. elseif (!extension_loaded('xmlreader'))
  1069. {
  1070. static $xml_is_sane = null;
  1071. if ($xml_is_sane === null)
  1072. {
  1073. $parser_check = xml_parser_create();
  1074. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  1075. xml_parser_free($parser_check);
  1076. $xml_is_sane = isset($values[0]['value']);
  1077. }
  1078. if (!$xml_is_sane)
  1079. {
  1080. return false;
  1081. }
  1082. }
  1083. if (method_exists($this->sanitize, 'set_registry'))
  1084. {
  1085. $this->sanitize->set_registry($this->registry);
  1086. }
  1087. // Pass whatever was set with config options over to the sanitizer.
  1088. // Pass the classes in for legacy support; new classes should use the registry instead
  1089. $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
  1090. $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
  1091. if (!empty($this->multifeed_url))
  1092. {
  1093. $i = 0;
  1094. $success = 0;
  1095. $this->multifeed_objects = array();
  1096. $this->error = array();
  1097. foreach ($this->multifeed_url as $url)
  1098. {
  1099. $this->multifeed_objects[$i] = clone $this;
  1100. $this->multifeed_objects[$i]->set_feed_url($url);
  1101. $single_success = $this->multifeed_objects[$i]->init();
  1102. $success |= $single_success;
  1103. if (!$single_success)
  1104. {
  1105. $this->error[$i] = $this->multifeed_objects[$i]->error();
  1106. }
  1107. $i++;
  1108. }
  1109. return (bool) $success;
  1110. }
  1111. elseif ($this->feed_url === null && $this->raw_data === null)
  1112. {
  1113. return false;
  1114. }
  1115. $this->error = null;
  1116. $this->data = array();
  1117. $this->multifeed_objects = array();
  1118. $cache = false;
  1119. if ($this->feed_url !== null)
  1120. {
  1121. $parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));
  1122. // Decide whether to enable caching
  1123. if ($this->cache && $parsed_feed_url['scheme'] !== '')
  1124. {
  1125. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
  1126. }
  1127. // Fetch the data via SimplePie_File into $this->raw_data
  1128. if (($fetched = $this->fetch_data($cache)) === true)
  1129. {
  1130. return true;
  1131. }
  1132. elseif ($fetched === false) {
  1133. return false;
  1134. }
  1135. list($headers, $sniffed) = $fetched;
  1136. }
  1137. // Set up array of possible encodings
  1138. $encodings = array();
  1139. // First check to see if input has been overridden.
  1140. if ($this->input_encoding !== false)
  1141. {
  1142. $encodings[] = $this->input_encoding;
  1143. }
  1144. $application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
  1145. $text_types = array('text/xml', 'text/xml-external-parsed-entity');
  1146. // RFC 3023 (only applies to sniffed content)
  1147. if (isset($sniffed))
  1148. {
  1149. if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
  1150. {
  1151. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1152. {
  1153. $encodings[] = strtoupper($charset[1]);
  1154. }
  1155. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  1156. $encodings[] = 'UTF-8';
  1157. }
  1158. elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
  1159. {
  1160. if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
  1161. {
  1162. $encodings[] = $charset[1];
  1163. }
  1164. $encodings[] = 'US-ASCII';
  1165. }
  1166. // Text MIME-type default
  1167. elseif (substr($sniffed, 0, 5) === 'text/')
  1168. {
  1169. $encodings[] = 'US-ASCII';
  1170. }
  1171. }
  1172. // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
  1173. $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
  1174. $encodings[] = 'UTF-8';
  1175. $encodings[] = 'ISO-8859-1';
  1176. // There's no point in trying an encoding twice
  1177. $encodings = array_unique($encodings);
  1178. // Loop through each possible encoding, till we return something, or run out of possibilities
  1179. foreach ($encodings as $encoding)
  1180. {
  1181. // Change the encoding to UTF-8 (as we always use UTF-8 internally)
  1182. if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
  1183. {
  1184. // Create new parser
  1185. $parser = $this->registry->create('Parser');
  1186. // If it's parsed fine
  1187. if ($parser->parse($utf8_data, 'UTF-8'))
  1188. {
  1189. $this->data = $parser->get_data();
  1190. if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
  1191. {
  1192. $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
  1193. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  1194. return false;
  1195. }
  1196. if (isset($headers))
  1197. {
  1198. $this->data['headers'] = $headers;
  1199. }
  1200. $this->data['build'] = SIMPLEPIE_BUILD;
  1201. // Cache the file if caching is enabled
  1202. if ($cache && !$cache->save($this))
  1203. {
  1204. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  1205. }
  1206. return true;
  1207. }
  1208. }
  1209. }
  1210. if (isset($parser))
  1211. {
  1212. // We have an error, just set SimplePie_Misc::error to it and quit
  1213. $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
  1214. }
  1215. else
  1216. {
  1217. $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
  1218. }
  1219. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  1220. return false;
  1221. }
  1222. /**
  1223. * Fetch the data via SimplePie_File
  1224. *
  1225. * If the data is already cached, attempt to fetch it from there instead
  1226. * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache
  1227. * @return array|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type
  1228. */
  1229. protected function fetch_data(&$cache)
  1230. {
  1231. // If it's enabled, use the cache
  1232. if ($cache)
  1233. {
  1234. // Load the Cache
  1235. $this->data = $cache->load();
  1236. if (!empty($this->data))
  1237. {
  1238. // If the cache is for an outdated build of SimplePie
  1239. if (!isset($this->data['build']) || $this->data['build'] !== SIMPLEPIE_BUILD)
  1240. {
  1241. $cache->unlink();
  1242. $this->data = array();
  1243. }
  1244. // If we've hit a collision just rerun it with caching disabled
  1245. elseif (isset($this->data['url']) && $this->data['url'] !== $this->feed_url)
  1246. {
  1247. $cache = false;
  1248. $this->data = array();
  1249. }
  1250. // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.
  1251. elseif (isset($this->data['feed_url']))
  1252. {
  1253. // If the autodiscovery cache is still valid use it.
  1254. if ($cache->mtime() + $this->autodiscovery_cache_duration > time())
  1255. {
  1256. // Do not need to do feed autodiscovery yet.
  1257. if ($this->data['feed_url'] !== $this->data['url'])
  1258. {
  1259. $this->set_feed_url($this->data['feed_url']);
  1260. return $this->init();
  1261. }
  1262. $cache->unlink();
  1263. $this->data = array();
  1264. }
  1265. }
  1266. // Check if the cache has been updated
  1267. elseif ($cache->mtime() + $this->cache_duration < time())
  1268. {
  1269. // If we have last-modified and/or etag set
  1270. if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
  1271. {
  1272. $headers = array(
  1273. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
  1274. );
  1275. if (isset($this->data['headers']['last-modified']))
  1276. {
  1277. $headers['if-modified-since'] = $this->data['headers']['last-modified'];
  1278. }
  1279. if (isset($this->data['headers']['etag']))
  1280. {
  1281. $headers['if-none-match'] = $this->data['headers']['etag'];
  1282. }
  1283. $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
  1284. if ($file->success)
  1285. {
  1286. if ($file->status_code === 304)
  1287. {
  1288. $cache->touch();
  1289. return true;
  1290. }
  1291. }
  1292. else
  1293. {
  1294. unset($file);
  1295. }
  1296. }
  1297. }
  1298. // If the cache is still valid, just return true
  1299. else
  1300. {
  1301. $this->raw_data = false;
  1302. return true;
  1303. }
  1304. }
  1305. // If the cache is empty, delete it
  1306. else
  1307. {
  1308. $cache->unlink();
  1309. $this->data = array();
  1310. }
  1311. }
  1312. // 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.
  1313. if (!isset($file))
  1314. {
  1315. if ($this->file instanceof SimplePie_File && $this->file->url === $this->feed_url)
  1316. {
  1317. $file =& $this->file;
  1318. }
  1319. else
  1320. {
  1321. $headers = array(
  1322. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
  1323. );
  1324. $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
  1325. }
  1326. }
  1327. // If the file connection has an error, set SimplePie::error to that and quit
  1328. if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  1329. {
  1330. $this->error = $file->error;
  1331. return !empty($this->data);
  1332. }
  1333. if (!$this->force_feed)
  1334. {
  1335. // Check if the supplied URL is a feed, if it isn't, look for it.
  1336. $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
  1337. if (!$locate->is_feed($file))
  1338. {
  1339. // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
  1340. unset($file);
  1341. try
  1342. {
  1343. if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
  1344. {
  1345. $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
  1346. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
  1347. return false;
  1348. }
  1349. }
  1350. catch (SimplePie_Exception $e)
  1351. {
  1352. // This is usually because DOMDocument doesn't exist
  1353. $this->error = $e->getMessage();
  1354. $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()));
  1355. return false;
  1356. }
  1357. if ($cache)
  1358. {
  1359. $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD);
  1360. if (!$cache->save($this))
  1361. {
  1362. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  1363. }
  1364. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
  1365. }
  1366. $this->feed_url = $file->url;
  1367. }
  1368. $locate = null;
  1369. }
  1370. $this->raw_data = $file->body;
  1371. $headers = $file->headers;
  1372. $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
  1373. $sniffed = $sniffer->get_type();
  1374. return array($headers, $sniffed);
  1375. }
  1376. /**
  1377. * Get the error message for the occured error
  1378. *
  1379. * @return string|array Error message, or array of messages for multifeeds
  1380. */
  1381. public function error()
  1382. {
  1383. return $this->error;
  1384. }
  1385. /**
  1386. * Get the raw XML
  1387. *
  1388. * This is the same as the old `$feed->enable_xml_dump(true)`, but returns
  1389. * the data instead of printing it.
  1390. *
  1391. * @return string|boolean Raw XML data, false if the cache is used
  1392. */
  1393. public function get_raw_data()
  1394. {
  1395. return $this->raw_data;
  1396. }
  1397. /**
  1398. * Get the character encoding used for output
  1399. *
  1400. * @since Preview Release
  1401. * @return string
  1402. */
  1403. public function get_encoding()
  1404. {
  1405. return $this->sanitize->output_encoding;
  1406. }
  1407. /**
  1408. * Send the content-type header with correct encoding
  1409. *
  1410. * This method ensures that the SimplePie-enabled page is being served with
  1411. * the correct {@link http://www.iana.org/assignments/media-types/ mime-type}
  1412. * and character encoding HTTP headers (character encoding determined by the
  1413. * {@see set_output_encoding} config option).
  1414. *
  1415. * This won't work properly if any content or whitespace has already been
  1416. * sent to the browser, because it relies on PHP's
  1417. * {@link http://php.net/header header()} function, and these are the
  1418. * circumstances under which the function works.
  1419. *
  1420. * Because it's setting these settings for the entire page (as is the nature
  1421. * of HTTP headers), this should only be used once per page (again, at the
  1422. * top).
  1423. *
  1424. * @param string $mime MIME type to serve the page as
  1425. */
  1426. public function handle_content_type($mime = 'text/html')
  1427. {
  1428. if (!headers_sent())
  1429. {
  1430. $header = "Content-type: $mime;";
  1431. if ($this->get_encoding())
  1432. {
  1433. $header .= ' charset=' . $this->get_encoding();
  1434. }
  1435. else
  1436. {
  1437. $header .= ' charset=UTF-8';
  1438. }
  1439. header($header);
  1440. }
  1441. }
  1442. /**
  1443. * Get the type of the feed
  1444. *
  1445. * This returns a SIMPLEPIE_TYPE_* constant, which can be tested against
  1446. * using {@link http://php.net/language.operators.bitwise bitwise operators}
  1447. *
  1448. * @since 0.8 (usage changed to using constants in 1.0)
  1449. * @see SIMPLEPIE_TYPE_NONE Unknown.
  1450. * @see SIMPLEPIE_TYPE_RSS_090 RSS 0.90.
  1451. * @see SIMPLEPIE_TYPE_RSS_091_NETSCAPE RSS 0.91 (Netscape).
  1452. * @see SIMPLEPIE_TYPE_RSS_091_USERLAND RSS 0.91 (Userland).
  1453. * @see SIMPLEPIE_TYPE_RSS_091 RSS 0.91.
  1454. * @see SIMPLEPIE_TYPE_RSS_092 RSS 0.92.
  1455. * @see SIMPLEPIE_TYPE_RSS_093 RSS 0.93.
  1456. * @see SIMPLEPIE_TYPE_RSS_094 RSS 0.94.
  1457. * @see SIMPLEPIE_TYPE_RSS_10 RSS 1.0.
  1458. * @see SIMPLEPIE_TYPE_RSS_20 RSS 2.0.x.
  1459. * @see SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS.
  1460. * @see SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format).
  1461. * @see SIMPLEPIE_TYPE_RSS_ALL Any version of RSS.
  1462. * @see SIMPLEPIE_TYPE_ATOM_03 Atom 0.3.
  1463. * @see SIMPLEPIE_TYPE_ATOM_10 Atom 1.0.
  1464. * @see SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom.
  1465. * @see SIMPLEPIE_TYPE_ALL Any known/supported feed type.
  1466. * @return int SIMPLEPIE_TYPE_* constant
  1467. */
  1468. public function get_type()
  1469. {
  1470. if (!isset($this->data['type']))
  1471. {
  1472. $this->data['type'] = SIMPLEPIE_TYPE_ALL;
  1473. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))
  1474. {
  1475. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;
  1476. }
  1477. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))
  1478. {
  1479. $this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;
  1480. }
  1481. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))
  1482. {
  1483. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])
  1484. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])
  1485. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])
  1486. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))
  1487. {
  1488. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;
  1489. }
  1490. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])
  1491. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])
  1492. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])
  1493. || isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))
  1494. {
  1495. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;
  1496. }
  1497. }
  1498. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss']))
  1499. {
  1500. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;
  1501. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  1502. {
  1503. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['attribs']['']['version']))
  1504. {
  1505. case '0.91':
  1506. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;
  1507. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  1508. {
  1509. switch (trim($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['skiphours']['hour'][0]['data']))
  1510. {
  1511. case '0':
  1512. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;
  1513. break;
  1514. case '24':
  1515. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;
  1516. break;
  1517. }
  1518. }
  1519. break;
  1520. case '0.92':
  1521. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;
  1522. break;
  1523. case '0.93':
  1524. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;
  1525. break;
  1526. case '0.94':
  1527. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;
  1528. break;
  1529. case '2.0':
  1530. $this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;
  1531. break;
  1532. }
  1533. }
  1534. }
  1535. else
  1536. {
  1537. $this->data['type'] = SIMPLEPIE_TYPE_NONE;
  1538. }
  1539. }
  1540. return $this->data['type'];
  1541. }
  1542. /**
  1543. * Get the URL for the feed
  1544. *
  1545. * May or may not be different from the URL passed to {@see set_feed_url()},
  1546. * depending on whether auto-discovery was used.
  1547. *
  1548. * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
  1549. * @todo If we have a perm redirect we should return the new URL
  1550. * @todo When we make the above change, let's support <itunes:new-feed-url> as well
  1551. * @todo Also, |atom:link|@rel=self
  1552. * @return string|null
  1553. */
  1554. public function subscribe_url()
  1555. {
  1556. if ($this->feed_url !== null)
  1557. {
  1558. return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
  1559. }
  1560. else
  1561. {
  1562. return null;
  1563. }
  1564. }
  1565. /**
  1566. * Get data for an feed-level element
  1567. *
  1568. * This method allows you to get access to ANY element/attribute that is a
  1569. * sub-element of the opening feed tag.
  1570. *
  1571. * The return value is an indexed array of elements matching the given
  1572. * namespace and tag name. Each element has `attribs`, `data` and `child`
  1573. * subkeys. For `attribs` and `child`, these contain namespace subkeys.
  1574. * `attribs` then has one level of associative name => value data (where
  1575. * `value` is a string) after the namespace. `child` has tag-indexed keys
  1576. * after the namespace, each member of which is an indexed array matching
  1577. * this same format.
  1578. *
  1579. * For example:
  1580. * <pre>
  1581. * // This is probably a bad example because we already support
  1582. * // <media:content> natively, but it shows you how to parse through
  1583. * // the nodes.
  1584. * $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group');
  1585. * $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'];
  1586. * $file = $content[0]['attribs']['']['url'];
  1587. * echo $file;
  1588. * </pre>
  1589. *
  1590. * @since 1.0
  1591. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  1592. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  1593. * @param string $tag Tag name
  1594. * @return array
  1595. */
  1596. public function get_feed_tags($namespace, $tag)
  1597. {
  1598. $type = $this->get_type();
  1599. if ($type & SIMPLEPIE_TYPE_ATOM_10)
  1600. {
  1601. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
  1602. {
  1603. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
  1604. }
  1605. }
  1606. if ($type & SIMPLEPIE_TYPE_ATOM_03)
  1607. {
  1608. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
  1609. {
  1610. return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
  1611. }
  1612. }
  1613. if ($type & SIMPLEPIE_TYPE_RSS_RDF)
  1614. {
  1615. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
  1616. {
  1617. return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
  1618. }
  1619. }
  1620. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1621. {
  1622. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
  1623. {
  1624. return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag];
  1625. }
  1626. }
  1627. return null;
  1628. }
  1629. /**
  1630. * Get data for an channel-level element
  1631. *
  1632. * This method allows you to get access to ANY element/attribute in the
  1633. * channel/header section of the feed.
  1634. *
  1635. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  1636. *
  1637. * @since 1.0
  1638. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  1639. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  1640. * @param string $tag Tag name
  1641. * @return array
  1642. */
  1643. public function get_channel_tags($namespace, $tag)
  1644. {
  1645. $type = $this->get_type();
  1646. if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
  1647. {
  1648. if ($return = $this->get_feed_tags($namespace, $tag))
  1649. {
  1650. return $return;
  1651. }
  1652. }
  1653. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1654. {
  1655. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
  1656. {
  1657. if (isset($channel[0]['child'][$namespace][$tag]))
  1658. {
  1659. return $channel[0]['child'][$namespace][$tag];
  1660. }
  1661. }
  1662. }
  1663. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1664. {
  1665. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
  1666. {
  1667. if (isset($channel[0]['child'][$namespace][$tag]))
  1668. {
  1669. return $channel[0]['child'][$namespace][$tag];
  1670. }
  1671. }
  1672. }
  1673. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1674. {
  1675. if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
  1676. {
  1677. if (isset($channel[0]['child'][$namespace][$tag]))
  1678. {
  1679. return $channel[0]['child'][$namespace][$tag];
  1680. }
  1681. }
  1682. }
  1683. return null;
  1684. }
  1685. /**
  1686. * Get data for an channel-level element
  1687. *
  1688. * This method allows you to get access to ANY element/attribute in the
  1689. * image/logo section of the feed.
  1690. *
  1691. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  1692. *
  1693. * @since 1.0
  1694. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  1695. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  1696. * @param string $tag Tag name
  1697. * @return array
  1698. */
  1699. public function get_image_tags($namespace, $tag)
  1700. {
  1701. $type = $this->get_type();
  1702. if ($type & SIMPLEPIE_TYPE_RSS_10)
  1703. {
  1704. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
  1705. {
  1706. if (isset($image[0]['child'][$namespace][$tag]))
  1707. {
  1708. return $image[0]['child'][$namespace][$tag];
  1709. }
  1710. }
  1711. }
  1712. if ($type & SIMPLEPIE_TYPE_RSS_090)
  1713. {
  1714. if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
  1715. {
  1716. if (isset($image[0]['child'][$namespace][$tag]))
  1717. {
  1718. return $image[0]['child'][$namespace][$tag];
  1719. }
  1720. }
  1721. }
  1722. if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
  1723. {
  1724. if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
  1725. {
  1726. if (isset($image[0]['child'][$namespace][$tag]))
  1727. {
  1728. return $image[0]['child'][$namespace][$tag];
  1729. }
  1730. }
  1731. }
  1732. return null;
  1733. }
  1734. /**
  1735. * Get the base URL value from the feed
  1736. *
  1737. * Uses `<xml:base>` if available, otherwise uses the first link in the
  1738. * feed, or failing that, the URL of the feed itself.
  1739. *
  1740. * @see get_link
  1741. * @see subscribe_url
  1742. *
  1743. * @param array $element
  1744. * @return string
  1745. */
  1746. public function get_base($element = array())
  1747. {
  1748. if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
  1749. {
  1750. return $element['xml_base'];
  1751. }
  1752. elseif ($this->get_link() !== null)
  1753. {
  1754. return $this->get_link();
  1755. }
  1756. else
  1757. {
  1758. return $this->subscribe_url();
  1759. }
  1760. }
  1761. /**
  1762. * Sanitize feed data
  1763. *
  1764. * @access private
  1765. * @see SimplePie_Sanitize::sanitize()
  1766. * @param string $data Data to sanitize
  1767. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
  1768. * @param string $base Base URL to resolve URLs against
  1769. * @return string Sanitized data
  1770. */
  1771. public function sanitize($data, $type, $base = '')
  1772. {
  1773. return $this->sanitize->sanitize($data, $type, $base);
  1774. }
  1775. /**
  1776. * Get the title of the feed
  1777. *
  1778. * Uses `<atom:title>`, `<title>` or `<dc:title>`
  1779. *
  1780. * @since 1.0 (previously called `get_feed_title` since 0.8)
  1781. * @return string|null
  1782. */
  1783. public function get_title()
  1784. {
  1785. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  1786. {
  1787. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1788. }
  1789. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  1790. {
  1791. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  1792. }
  1793. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  1794. {
  1795. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1796. }
  1797. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  1798. {
  1799. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1800. }
  1801. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  1802. {
  1803. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  1804. }
  1805. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  1806. {
  1807. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1808. }
  1809. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  1810. {
  1811. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1812. }
  1813. else
  1814. {
  1815. return null;
  1816. }
  1817. }
  1818. /**
  1819. * Get a category for the feed
  1820. *
  1821. * @since Unknown
  1822. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
  1823. * @return SimplePie_Category|null
  1824. */
  1825. public function get_category($key = 0)
  1826. {
  1827. $categories = $this->get_categories();
  1828. if (isset($categories[$key]))
  1829. {
  1830. return $categories[$key];
  1831. }
  1832. else
  1833. {
  1834. return null;
  1835. }
  1836. }
  1837. /**
  1838. * Get all categories for the feed
  1839. *
  1840. * Uses `<atom:category>`, `<category>` or `<dc:subject>`
  1841. *
  1842. * @since Unknown
  1843. * @return array|null List of {@see SimplePie_Category} objects
  1844. */
  1845. public function get_categories()
  1846. {
  1847. $categories = array();
  1848. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  1849. {
  1850. $term = null;
  1851. $scheme = null;
  1852. $label = null;
  1853. if (isset($category['attribs']['']['term']))
  1854. {
  1855. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  1856. }
  1857. if (isset($category['attribs']['']['scheme']))
  1858. {
  1859. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1860. }
  1861. if (isset($category['attribs']['']['label']))
  1862. {
  1863. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1864. }
  1865. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1866. }
  1867. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  1868. {
  1869. // This is really the label, but keep this as the term also for BC.
  1870. // Label will also work on retrieving because that falls back to term.
  1871. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1872. if (isset($category['attribs']['']['domain']))
  1873. {
  1874. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  1875. }
  1876. else
  1877. {
  1878. $scheme = null;
  1879. }
  1880. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  1881. }
  1882. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  1883. {
  1884. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1885. }
  1886. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  1887. {
  1888. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1889. }
  1890. if (!empty($categories))
  1891. {
  1892. return array_unique($categories);
  1893. }
  1894. else
  1895. {
  1896. return null;
  1897. }
  1898. }
  1899. /**
  1900. * Get an author for the feed
  1901. *
  1902. * @since 1.1
  1903. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
  1904. * @return SimplePie_Author|null
  1905. */
  1906. public function get_author($key = 0)
  1907. {
  1908. $authors = $this->get_authors();
  1909. if (isset($authors[$key]))
  1910. {
  1911. return $authors[$key];
  1912. }
  1913. else
  1914. {
  1915. return null;
  1916. }
  1917. }
  1918. /**
  1919. * Get all authors for the feed
  1920. *
  1921. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
  1922. *
  1923. * @since 1.1
  1924. * @return array|null List of {@see SimplePie_Author} objects
  1925. */
  1926. public function get_authors()
  1927. {
  1928. $authors = array();
  1929. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  1930. {
  1931. $name = null;
  1932. $uri = null;
  1933. $email = null;
  1934. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  1935. {
  1936. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1937. }
  1938. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  1939. {
  1940. $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]));
  1941. }
  1942. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  1943. {
  1944. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1945. }
  1946. if ($name !== null || $email !== null || $uri !== null)
  1947. {
  1948. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  1949. }
  1950. }
  1951. if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  1952. {
  1953. $name = null;
  1954. $url = null;
  1955. $email = null;
  1956. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  1957. {
  1958. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1959. }
  1960. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  1961. {
  1962. $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]));
  1963. }
  1964. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  1965. {
  1966. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1967. }
  1968. if ($name !== null || $email !== null || $url !== null)
  1969. {
  1970. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  1971. }
  1972. }
  1973. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  1974. {
  1975. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1976. }
  1977. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  1978. {
  1979. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1980. }
  1981. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  1982. {
  1983. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  1984. }
  1985. if (!empty($authors))
  1986. {
  1987. return array_unique($authors);
  1988. }
  1989. else
  1990. {
  1991. return null;
  1992. }
  1993. }
  1994. /**
  1995. * Get a contributor for the feed
  1996. *
  1997. * @since 1.1
  1998. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
  1999. * @return SimplePie_Author|null
  2000. */
  2001. public function get_contributor($key = 0)
  2002. {
  2003. $contributors = $this->get_contributors();
  2004. if (isset($contributors[$key]))
  2005. {
  2006. return $contributors[$key];
  2007. }
  2008. else
  2009. {
  2010. return null;
  2011. }
  2012. }
  2013. /**
  2014. * Get all contributors for the feed
  2015. *
  2016. * Uses `<atom:contributor>`
  2017. *
  2018. * @since 1.1
  2019. * @return array|null List of {@see SimplePie_Author} objects
  2020. */
  2021. public function get_contributors()
  2022. {
  2023. $contributors = array();
  2024. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  2025. {
  2026. $name = null;
  2027. $uri = null;
  2028. $email = null;
  2029. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  2030. {
  2031. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2032. }
  2033. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  2034. {
  2035. $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]));
  2036. }
  2037. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  2038. {
  2039. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2040. }
  2041. if ($name !== null || $email !== null || $uri !== null)
  2042. {
  2043. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  2044. }
  2045. }
  2046. foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  2047. {
  2048. $name = null;
  2049. $url = null;
  2050. $email = null;
  2051. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  2052. {
  2053. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2054. }
  2055. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  2056. {
  2057. $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]));
  2058. }
  2059. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  2060. {
  2061. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2062. }
  2063. if ($name !== null || $email !== null || $url !== null)
  2064. {
  2065. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  2066. }
  2067. }
  2068. if (!empty($contributors))
  2069. {
  2070. return array_unique($contributors);
  2071. }
  2072. else
  2073. {
  2074. return null;
  2075. }
  2076. }
  2077. /**
  2078. * Get a single link for the feed
  2079. *
  2080. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
  2081. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
  2082. * @param string $rel The relationship of the link to return
  2083. * @return string|null Link URL
  2084. */
  2085. public function get_link($key = 0, $rel = 'alternate')
  2086. {
  2087. $links = $this->get_links($rel);
  2088. if (isset($links[$key]))
  2089. {
  2090. return $links[$key];
  2091. }
  2092. else
  2093. {
  2094. return null;
  2095. }
  2096. }
  2097. /**
  2098. * Get the permalink for the item
  2099. *
  2100. * Returns the first link available with a relationship of "alternate".
  2101. * Identical to {@see get_link()} with key 0
  2102. *
  2103. * @see get_link
  2104. * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
  2105. * @internal Added for parity between the parent-level and the item/entry-level.
  2106. * @return string|null Link URL
  2107. */
  2108. public function get_permalink()
  2109. {
  2110. return $this->get_link(0);
  2111. }
  2112. /**
  2113. * Get all links for the feed
  2114. *
  2115. * Uses `<atom:link>` or `<link>`
  2116. *
  2117. * @since Beta 2
  2118. * @param string $rel The relationship of links to return
  2119. * @return array|null Links found for the feed (strings)
  2120. */
  2121. public function get_links($rel = 'alternate')
  2122. {
  2123. if (!isset($this->data['links']))
  2124. {
  2125. $this->data['links'] = array();
  2126. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  2127. {
  2128. foreach ($links as $link)
  2129. {
  2130. if (isset($link['attribs']['']['href']))
  2131. {
  2132. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2133. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2134. }
  2135. }
  2136. }
  2137. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  2138. {
  2139. foreach ($links as $link)
  2140. {
  2141. if (isset($link['attribs']['']['href']))
  2142. {
  2143. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  2144. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2145. }
  2146. }
  2147. }
  2148. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2149. {
  2150. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2151. }
  2152. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2153. {
  2154. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2155. }
  2156. if ($links = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  2157. {
  2158. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  2159. }
  2160. $keys = array_keys($this->data['links']);
  2161. foreach ($keys as $key)
  2162. {
  2163. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  2164. {
  2165. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  2166. {
  2167. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  2168. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  2169. }
  2170. else
  2171. {
  2172. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  2173. }
  2174. }
  2175. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  2176. {
  2177. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  2178. }
  2179. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  2180. }
  2181. }
  2182. if (isset($this->data['links'][$rel]))
  2183. {
  2184. return $this->data['links'][$rel];
  2185. }
  2186. else
  2187. {
  2188. return null;
  2189. }
  2190. }
  2191. public function get_all_discovered_feeds()
  2192. {
  2193. return $this->all_discovered_feeds;
  2194. }
  2195. /**
  2196. * Get the content for the item
  2197. *
  2198. * Uses `<atom:subtitle>`, `<atom:tagline>`, `<description>`,
  2199. * `<dc:description>`, `<itunes:summary>` or `<itunes:subtitle>`
  2200. *
  2201. * @since 1.0 (previously called `get_feed_description()` since 0.8)
  2202. * @return string|null
  2203. */
  2204. public function get_description()
  2205. {
  2206. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  2207. {
  2208. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2209. }
  2210. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  2211. {
  2212. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2213. }
  2214. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  2215. {
  2216. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2217. }
  2218. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  2219. {
  2220. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  2221. }
  2222. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  2223. {
  2224. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2225. }
  2226. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  2227. {
  2228. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2229. }
  2230. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  2231. {
  2232. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2233. }
  2234. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  2235. {
  2236. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2237. }
  2238. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  2239. {
  2240. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  2241. }
  2242. else
  2243. {
  2244. return null;
  2245. }
  2246. }
  2247. /**
  2248. * Get the copyright info for the feed
  2249. *
  2250. * Uses `<atom:rights>`, `<atom:copyright>` or `<dc:rights>`
  2251. *
  2252. * @since 1.0 (previously called `get_feed_copyright()` since 0.8)
  2253. * @return string|null
  2254. */
  2255. public function get_copyright()
  2256. {
  2257. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  2258. {
  2259. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2260. }
  2261. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  2262. {
  2263. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  2264. }
  2265. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  2266. {
  2267. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2268. }
  2269. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  2270. {
  2271. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2272. }
  2273. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  2274. {
  2275. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2276. }
  2277. else
  2278. {
  2279. return null;
  2280. }
  2281. }
  2282. /**
  2283. * Get the language for the feed
  2284. *
  2285. * Uses `<language>`, `<dc:language>`, or @xml_lang
  2286. *
  2287. * @since 1.0 (previously called `get_feed_language()` since 0.8)
  2288. * @return string|null
  2289. */
  2290. public function get_language()
  2291. {
  2292. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  2293. {
  2294. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2295. }
  2296. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  2297. {
  2298. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2299. }
  2300. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  2301. {
  2302. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2303. }
  2304. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang']))
  2305. {
  2306. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2307. }
  2308. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang']))
  2309. {
  2310. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2311. }
  2312. elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang']))
  2313. {
  2314. return $this->sanitize($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2315. }
  2316. elseif (isset($this->data['headers']['content-language']))
  2317. {
  2318. return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
  2319. }
  2320. else
  2321. {
  2322. return null;
  2323. }
  2324. }
  2325. /**
  2326. * Get the latitude coordinates for the item
  2327. *
  2328. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2329. *
  2330. * Uses `<geo:lat>` or `<georss:point>`
  2331. *
  2332. * @since 1.0
  2333. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2334. * @link http://www.georss.org/ GeoRSS
  2335. * @return string|null
  2336. */
  2337. public function get_latitude()
  2338. {
  2339. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  2340. {
  2341. return (float) $return[0]['data'];
  2342. }
  2343. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2344. {
  2345. return (float) $match[1];
  2346. }
  2347. else
  2348. {
  2349. return null;
  2350. }
  2351. }
  2352. /**
  2353. * Get the longitude coordinates for the feed
  2354. *
  2355. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2356. *
  2357. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
  2358. *
  2359. * @since 1.0
  2360. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2361. * @link http://www.georss.org/ GeoRSS
  2362. * @return string|null
  2363. */
  2364. public function get_longitude()
  2365. {
  2366. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  2367. {
  2368. return (float) $return[0]['data'];
  2369. }
  2370. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  2371. {
  2372. return (float) $return[0]['data'];
  2373. }
  2374. elseif (($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2375. {
  2376. return (float) $match[2];
  2377. }
  2378. else
  2379. {
  2380. return null;
  2381. }
  2382. }
  2383. /**
  2384. * Get the feed logo's title
  2385. *
  2386. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title.
  2387. *
  2388. * Uses `<image><title>` or `<image><dc:title>`
  2389. *
  2390. * @return string|null
  2391. */
  2392. public function get_image_title()
  2393. {
  2394. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  2395. {
  2396. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2397. }
  2398. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  2399. {
  2400. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2401. }
  2402. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  2403. {
  2404. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2405. }
  2406. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  2407. {
  2408. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2409. }
  2410. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  2411. {
  2412. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2413. }
  2414. else
  2415. {
  2416. return null;
  2417. }
  2418. }
  2419. /**
  2420. * Get the feed logo's URL
  2421. *
  2422. * RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to
  2423. * have a "feed logo" URL. This points directly to the image itself.
  2424. *
  2425. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
  2426. * `<image><title>` or `<image><dc:title>`
  2427. *
  2428. * @return string|null
  2429. */
  2430. public function get_image_url()
  2431. {
  2432. if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  2433. {
  2434. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  2435. }
  2436. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  2437. {
  2438. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2439. }
  2440. elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  2441. {
  2442. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2443. }
  2444. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'url'))
  2445. {
  2446. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2447. }
  2448. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'url'))
  2449. {
  2450. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2451. }
  2452. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2453. {
  2454. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2455. }
  2456. else
  2457. {
  2458. return null;
  2459. }
  2460. }
  2461. /**
  2462. * Get the feed logo's link
  2463. *
  2464. * RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This
  2465. * points to a human-readable page that the image should link to.
  2466. *
  2467. * Uses `<itunes:image>`, `<atom:logo>`, `<atom:icon>`,
  2468. * `<image><title>` or `<image><dc:title>`
  2469. *
  2470. * @return string|null
  2471. */
  2472. public function get_image_link()
  2473. {
  2474. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  2475. {
  2476. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2477. }
  2478. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  2479. {
  2480. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2481. }
  2482. elseif ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  2483. {
  2484. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  2485. }
  2486. else
  2487. {
  2488. return null;
  2489. }
  2490. }
  2491. /**
  2492. * Get the feed logo's link
  2493. *
  2494. * RSS 2.0 feeds are allowed to have a "feed logo" width.
  2495. *
  2496. * Uses `<image><width>` or defaults to 88.0 if no width is specified and
  2497. * the feed is an RSS 2.0 feed.
  2498. *
  2499. * @return int|float|null
  2500. */
  2501. public function get_image_width()
  2502. {
  2503. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'width'))
  2504. {
  2505. return round($return[0]['data']);
  2506. }
  2507. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2508. {
  2509. return 88.0;
  2510. }
  2511. else
  2512. {
  2513. return null;
  2514. }
  2515. }
  2516. /**
  2517. * Get the feed logo's height
  2518. *
  2519. * RSS 2.0 feeds are allowed to have a "feed logo" height.
  2520. *
  2521. * Uses `<image><height>` or defaults to 31.0 if no height is specified and
  2522. * the feed is an RSS 2.0 feed.
  2523. *
  2524. * @return int|float|null
  2525. */
  2526. public function get_image_height()
  2527. {
  2528. if ($return = $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'height'))
  2529. {
  2530. return round($return[0]['data']);
  2531. }
  2532. elseif ($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION && $this->get_image_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'url'))
  2533. {
  2534. return 31.0;
  2535. }
  2536. else
  2537. {
  2538. return null;
  2539. }
  2540. }
  2541. /**
  2542. * Get the number of items in the feed
  2543. *
  2544. * This is well-suited for {@link http://php.net/for for()} loops with
  2545. * {@see get_item()}
  2546. *
  2547. * @param int $max Maximum value to return. 0 for no limit
  2548. * @return int Number of items in the feed
  2549. */
  2550. public function get_item_quantity($max = 0)
  2551. {
  2552. $max = (int) $max;
  2553. $qty = count($this->get_items());
  2554. if ($max === 0)
  2555. {
  2556. return $qty;
  2557. }
  2558. else
  2559. {
  2560. return ($qty > $max) ? $max : $qty;
  2561. }
  2562. }
  2563. /**
  2564. * Get a single item from the feed
  2565. *
  2566. * This is better suited for {@link http://php.net/for for()} loops, whereas
  2567. * {@see get_items()} is better suited for
  2568. * {@link http://php.net/foreach foreach()} loops.
  2569. *
  2570. * @see get_item_quantity()
  2571. * @since Beta 2
  2572. * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1
  2573. * @return SimplePie_Item|null
  2574. */
  2575. public function get_item($key = 0)
  2576. {
  2577. $items = $this->get_items();
  2578. if (isset($items[$key]))
  2579. {
  2580. return $items[$key];
  2581. }
  2582. else
  2583. {
  2584. return null;
  2585. }
  2586. }
  2587. /**
  2588. * Get all items from the feed
  2589. *
  2590. * This is better suited for {@link http://php.net/for for()} loops, whereas
  2591. * {@see get_items()} is better suited for
  2592. * {@link http://php.net/foreach foreach()} loops.
  2593. *
  2594. * @see get_item_quantity
  2595. * @since Beta 2
  2596. * @param int $start Index to start at
  2597. * @param int $end Number of items to return. 0 for all items after `$start`
  2598. * @return array|null List of {@see SimplePie_Item} objects
  2599. */
  2600. public function get_items($start = 0, $end = 0)
  2601. {
  2602. if (!isset($this->data['items']))
  2603. {
  2604. if (!empty($this->multifeed_objects))
  2605. {
  2606. $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
  2607. }
  2608. else
  2609. {
  2610. $this->data['items'] = array();
  2611. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
  2612. {
  2613. $keys = array_keys($items);
  2614. foreach ($keys as $key)
  2615. {
  2616. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2617. }
  2618. }
  2619. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
  2620. {
  2621. $keys = array_keys($items);
  2622. foreach ($keys as $key)
  2623. {
  2624. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2625. }
  2626. }
  2627. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
  2628. {
  2629. $keys = array_keys($items);
  2630. foreach ($keys as $key)
  2631. {
  2632. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2633. }
  2634. }
  2635. if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
  2636. {
  2637. $keys = array_keys($items);
  2638. foreach ($keys as $key)
  2639. {
  2640. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2641. }
  2642. }
  2643. if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
  2644. {
  2645. $keys = array_keys($items);
  2646. foreach ($keys as $key)
  2647. {
  2648. $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
  2649. }
  2650. }
  2651. }
  2652. }
  2653. if (!empty($this->data['items']))
  2654. {
  2655. // If we want to order it by date, check if all items have a date, and then sort it
  2656. if ($this->order_by_date && empty($this->multifeed_objects))
  2657. {
  2658. if (!isset($this->data['ordered_items']))
  2659. {
  2660. $do_sort = true;
  2661. foreach ($this->data['items'] as $item)
  2662. {
  2663. if (!$item->get_date('U'))
  2664. {
  2665. $do_sort = false;
  2666. break;
  2667. }
  2668. }
  2669. $item = null;
  2670. $this->data['ordered_items'] = $this->data['items'];
  2671. if ($do_sort)
  2672. {
  2673. usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
  2674. }
  2675. }
  2676. $items = $this->data['ordered_items'];
  2677. }
  2678. else
  2679. {
  2680. $items = $this->data['items'];
  2681. }
  2682. // Slice the data as desired
  2683. if ($end === 0)
  2684. {
  2685. return array_slice($items, $start);
  2686. }
  2687. else
  2688. {
  2689. return array_slice($items, $start, $end);
  2690. }
  2691. }
  2692. else
  2693. {
  2694. return array();
  2695. }
  2696. }
  2697. /**
  2698. * Set the favicon handler
  2699. *
  2700. * @deprecated Use your own favicon handling instead
  2701. */
  2702. public function set_favicon_handler($page = false, $qs = 'i')
  2703. {
  2704. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2705. trigger_error('Favicon handling has been removed, please use your own handling', $level);
  2706. return false;
  2707. }
  2708. /**
  2709. * Get the favicon for the current feed
  2710. *
  2711. * @deprecated Use your own favicon handling instead
  2712. */
  2713. public function get_favicon()
  2714. {
  2715. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2716. trigger_error('Favicon handling has been removed, please use your own handling', $level);
  2717. if (($url = $this->get_link()) !== null)
  2718. {
  2719. return 'http://g.etfv.co/' . urlencode($url);
  2720. }
  2721. return false;
  2722. }
  2723. /**
  2724. * Magic method handler
  2725. *
  2726. * @param string $method Method name
  2727. * @param array $args Arguments to the method
  2728. * @return mixed
  2729. */
  2730. public function __call($method, $args)
  2731. {
  2732. if (strpos($method, 'subscribe_') === 0)
  2733. {
  2734. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2735. trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level);
  2736. return '';
  2737. }
  2738. if ($method === 'enable_xml_dump')
  2739. {
  2740. $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
  2741. trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level);
  2742. return false;
  2743. }
  2744. $class = get_class($this);
  2745. $trace = debug_backtrace();
  2746. $file = $trace[0]['file'];
  2747. $line = $trace[0]['line'];
  2748. trigger_error("Call to undefined method $class::$method() in $file on line $line", E_USER_ERROR);
  2749. }
  2750. /**
  2751. * Sorting callback for items
  2752. *
  2753. * @access private
  2754. * @param SimplePie $a
  2755. * @param SimplePie $b
  2756. * @return boolean
  2757. */
  2758. public static function sort_items($a, $b)
  2759. {
  2760. return $a->get_date('U') <= $b->get_date('U');
  2761. }
  2762. /**
  2763. * Merge items from several feeds into one
  2764. *
  2765. * If you're merging multiple feeds together, they need to all have dates
  2766. * for the items or else SimplePie will refuse to sort them.
  2767. *
  2768. * @link http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date#if_feeds_require_separate_per-feed_settings
  2769. * @param array $urls List of SimplePie feed objects to merge
  2770. * @param int $start Starting item
  2771. * @param int $end Number of items to return
  2772. * @param int $limit Maximum number of items per feed
  2773. * @return array
  2774. */
  2775. public static function merge_items($urls, $start = 0, $end = 0, $limit = 0)
  2776. {
  2777. if (is_array($urls) && sizeof($urls) > 0)
  2778. {
  2779. $items = array();
  2780. foreach ($urls as $arg)
  2781. {
  2782. if ($arg instanceof SimplePie)
  2783. {
  2784. $items = array_merge($items, $arg->get_items(0, $limit));
  2785. }
  2786. else
  2787. {
  2788. trigger_error('Arguments must be SimplePie objects', E_USER_WARNING);
  2789. }
  2790. }
  2791. $do_sort = true;
  2792. foreach ($items as $item)
  2793. {
  2794. if (!$item->get_date('U'))
  2795. {
  2796. $do_sort = false;
  2797. break;
  2798. }
  2799. }
  2800. $item = null;
  2801. if ($do_sort)
  2802. {
  2803. usort($items, array(get_class($urls[0]), 'sort_items'));
  2804. }
  2805. if ($end === 0)
  2806. {
  2807. return array_slice($items, $start);
  2808. }
  2809. else
  2810. {
  2811. return array_slice($items, $start, $end);
  2812. }
  2813. }
  2814. else
  2815. {
  2816. trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
  2817. return array();
  2818. }
  2819. }
  2820. }
  2821. /**
  2822. * Decode 'gzip' encoded HTTP data
  2823. *
  2824. * @package SimplePie
  2825. * @subpackage HTTP
  2826. * @link http://www.gzip.org/format.txt
  2827. */
  2828. class SimplePie_gzdecode
  2829. {
  2830. /**
  2831. * Compressed data
  2832. *
  2833. * @access private
  2834. * @var string
  2835. * @see gzdecode::$data
  2836. */
  2837. var $compressed_data;
  2838. /**
  2839. * Size of compressed data
  2840. *
  2841. * @access private
  2842. * @var int
  2843. */
  2844. var $compressed_size;
  2845. /**
  2846. * Minimum size of a valid gzip string
  2847. *
  2848. * @access private
  2849. * @var int
  2850. */
  2851. var $min_compressed_size = 18;
  2852. /**
  2853. * Current position of pointer
  2854. *
  2855. * @access private
  2856. * @var int
  2857. */
  2858. var $position = 0;
  2859. /**
  2860. * Flags (FLG)
  2861. *
  2862. * @access private
  2863. * @var int
  2864. */
  2865. var $flags;
  2866. /**
  2867. * Uncompressed data
  2868. *
  2869. * @access public
  2870. * @see gzdecode::$compressed_data
  2871. * @var string
  2872. */
  2873. var $data;
  2874. /**
  2875. * Modified time
  2876. *
  2877. * @access public
  2878. * @var int
  2879. */
  2880. var $MTIME;
  2881. /**
  2882. * Extra Flags
  2883. *
  2884. * @access public
  2885. * @var int
  2886. */
  2887. var $XFL;
  2888. /**
  2889. * Operating System
  2890. *
  2891. * @access public
  2892. * @var int
  2893. */
  2894. var $OS;
  2895. /**
  2896. * Subfield ID 1
  2897. *
  2898. * @access public
  2899. * @see gzdecode::$extra_field
  2900. * @see gzdecode::$SI2
  2901. * @var string
  2902. */
  2903. var $SI1;
  2904. /**
  2905. * Subfield ID 2
  2906. *
  2907. * @access public
  2908. * @see gzdecode::$extra_field
  2909. * @see gzdecode::$SI1
  2910. * @var string
  2911. */
  2912. var $SI2;
  2913. /**
  2914. * Extra field content
  2915. *
  2916. * @access public
  2917. * @see gzdecode::$SI1
  2918. * @see gzdecode::$SI2
  2919. * @var string
  2920. */
  2921. var $extra_field;
  2922. /**
  2923. * Original filename
  2924. *
  2925. * @access public
  2926. * @var string
  2927. */
  2928. var $filename;
  2929. /**
  2930. * Human readable comment
  2931. *
  2932. * @access public
  2933. * @var string
  2934. */
  2935. var $comment;
  2936. /**
  2937. * Don't allow anything to be set
  2938. *
  2939. * @param string $name
  2940. * @param mixed $value
  2941. */
  2942. public function __set($name, $value)
  2943. {
  2944. trigger_error("Cannot write property $name", E_USER_ERROR);
  2945. }
  2946. /**
  2947. * Set the compressed string and related properties
  2948. *
  2949. * @param string $data
  2950. */
  2951. public function __construct($data)
  2952. {
  2953. $this->compressed_data = $data;
  2954. $this->compressed_size = strlen($data);
  2955. }
  2956. /**
  2957. * Decode the GZIP stream
  2958. *
  2959. * @return bool Successfulness
  2960. */
  2961. public function parse()
  2962. {
  2963. if ($this->compressed_size >= $this->min_compressed_size)
  2964. {
  2965. // Check ID1, ID2, and CM
  2966. if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08")
  2967. {
  2968. return false;
  2969. }
  2970. // Get the FLG (FLaGs)
  2971. $this->flags = ord($this->compressed_data[3]);
  2972. // FLG bits above (1 << 4) are reserved
  2973. if ($this->flags > 0x1F)
  2974. {
  2975. return false;
  2976. }
  2977. // Advance the pointer after the above
  2978. $this->position += 4;
  2979. // MTIME
  2980. $mtime = substr($this->compressed_data, $this->position, 4);
  2981. // Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
  2982. if (current(unpack('S', "\x00\x01")) === 1)
  2983. {
  2984. $mtime = strrev($mtime);
  2985. }
  2986. $this->MTIME = current(unpack('l', $mtime));
  2987. $this->position += 4;
  2988. // Get the XFL (eXtra FLags)
  2989. $this->XFL = ord($this->compressed_data[$this->position++]);
  2990. // Get the OS (Operating System)
  2991. $this->OS = ord($this->compressed_data[$this->position++]);
  2992. // Parse the FEXTRA
  2993. if ($this->flags & 4)
  2994. {
  2995. // Read subfield IDs
  2996. $this->SI1 = $this->compressed_data[$this->position++];
  2997. $this->SI2 = $this->compressed_data[$this->position++];
  2998. // SI2 set to zero is reserved for future use
  2999. if ($this->SI2 === "\x00")
  3000. {
  3001. return false;
  3002. }
  3003. // Get the length of the extra field
  3004. $len = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  3005. $this->position += 2;
  3006. // Check the length of the string is still valid
  3007. $this->min_compressed_size += $len + 4;
  3008. if ($this->compressed_size >= $this->min_compressed_size)
  3009. {
  3010. // Set the extra field to the given data
  3011. $this->extra_field = substr($this->compressed_data, $this->position, $len);
  3012. $this->position += $len;
  3013. }
  3014. else
  3015. {
  3016. return false;
  3017. }
  3018. }
  3019. // Parse the FNAME
  3020. if ($this->flags & 8)
  3021. {
  3022. // Get the length of the filename
  3023. $len = strcspn($this->compressed_data, "\x00", $this->position);
  3024. // Check the length of the string is still valid
  3025. $this->min_compressed_size += $len + 1;
  3026. if ($this->compressed_size >= $this->min_compressed_size)
  3027. {
  3028. // Set the original filename to the given string
  3029. $this->filename = substr($this->compressed_data, $this->position, $len);
  3030. $this->position += $len + 1;
  3031. }
  3032. else
  3033. {
  3034. return false;
  3035. }
  3036. }
  3037. // Parse the FCOMMENT
  3038. if ($this->flags & 16)
  3039. {
  3040. // Get the length of the comment
  3041. $len = strcspn($this->compressed_data, "\x00", $this->position);
  3042. // Check the length of the string is still valid
  3043. $this->min_compressed_size += $len + 1;
  3044. if ($this->compressed_size >= $this->min_compressed_size)
  3045. {
  3046. // Set the original comment to the given string
  3047. $this->comment = substr($this->compressed_data, $this->position, $len);
  3048. $this->position += $len + 1;
  3049. }
  3050. else
  3051. {
  3052. return false;
  3053. }
  3054. }
  3055. // Parse the FHCRC
  3056. if ($this->flags & 2)
  3057. {
  3058. // Check the length of the string is still valid
  3059. $this->min_compressed_size += $len + 2;
  3060. if ($this->compressed_size >= $this->min_compressed_size)
  3061. {
  3062. // Read the CRC
  3063. $crc = current(unpack('v', substr($this->compressed_data, $this->position, 2)));
  3064. // Check the CRC matches
  3065. if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc)
  3066. {
  3067. $this->position += 2;
  3068. }
  3069. else
  3070. {
  3071. return false;
  3072. }
  3073. }
  3074. else
  3075. {
  3076. return false;
  3077. }
  3078. }
  3079. // Decompress the actual data
  3080. if (($this->data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false)
  3081. {
  3082. return false;
  3083. }
  3084. else
  3085. {
  3086. $this->position = $this->compressed_size - 8;
  3087. }
  3088. // Check CRC of data
  3089. $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  3090. $this->position += 4;
  3091. /*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
  3092. {
  3093. return false;
  3094. }*/
  3095. // Check ISIZE of data
  3096. $isize = current(unpack('V', substr($this->compressed_data, $this->position, 4)));
  3097. $this->position += 4;
  3098. if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize))
  3099. {
  3100. return false;
  3101. }
  3102. // Wow, against all odds, we've actually got a valid gzip string
  3103. return true;
  3104. }
  3105. else
  3106. {
  3107. return false;
  3108. }
  3109. }
  3110. }
  3111. /**
  3112. * Used for data cleanup and post-processing
  3113. *
  3114. *
  3115. * This class can be overloaded with {@see SimplePie::set_sanitize_class()}
  3116. *
  3117. * @package SimplePie
  3118. * @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
  3119. */
  3120. class SimplePie_Sanitize
  3121. {
  3122. // Private vars
  3123. var $base;
  3124. // Options
  3125. var $remove_div = true;
  3126. var $image_handler = '';
  3127. var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  3128. var $encode_instead_of_strip = false;
  3129. var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
  3130. var $strip_comments = false;
  3131. var $output_encoding = 'UTF-8';
  3132. var $enable_cache = true;
  3133. var $cache_location = './cache';
  3134. var $cache_name_function = 'md5';
  3135. var $timeout = 10;
  3136. var $useragent = '';
  3137. var $force_fsockopen = false;
  3138. var $replace_url_attributes = null;
  3139. public function __construct()
  3140. {
  3141. // Set defaults
  3142. $this->set_url_replacements(null);
  3143. }
  3144. public function remove_div($enable = true)
  3145. {
  3146. $this->remove_div = (bool) $enable;
  3147. }
  3148. public function set_image_handler($page = false)
  3149. {
  3150. if ($page)
  3151. {
  3152. $this->image_handler = (string) $page;
  3153. }
  3154. else
  3155. {
  3156. $this->image_handler = false;
  3157. }
  3158. }
  3159. public function set_registry(SimplePie_Registry $registry)
  3160. {
  3161. $this->registry = $registry;
  3162. }
  3163. public function pass_cache_data($enable_cache = true, $cache_location = './cache', $cache_name_function = 'md5', $cache_class = 'SimplePie_Cache')
  3164. {
  3165. if (isset($enable_cache))
  3166. {
  3167. $this->enable_cache = (bool) $enable_cache;
  3168. }
  3169. if ($cache_location)
  3170. {
  3171. $this->cache_location = (string) $cache_location;
  3172. }
  3173. if ($cache_name_function)
  3174. {
  3175. $this->cache_name_function = (string) $cache_name_function;
  3176. }
  3177. }
  3178. public function pass_file_data($file_class = 'SimplePie_File', $timeout = 10, $useragent = '', $force_fsockopen = false)
  3179. {
  3180. if ($timeout)
  3181. {
  3182. $this->timeout = (string) $timeout;
  3183. }
  3184. if ($useragent)
  3185. {
  3186. $this->useragent = (string) $useragent;
  3187. }
  3188. if ($force_fsockopen)
  3189. {
  3190. $this->force_fsockopen = (string) $force_fsockopen;
  3191. }
  3192. }
  3193. public function strip_htmltags($tags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
  3194. {
  3195. if ($tags)
  3196. {
  3197. if (is_array($tags))
  3198. {
  3199. $this->strip_htmltags = $tags;
  3200. }
  3201. else
  3202. {
  3203. $this->strip_htmltags = explode(',', $tags);
  3204. }
  3205. }
  3206. else
  3207. {
  3208. $this->strip_htmltags = false;
  3209. }
  3210. }
  3211. public function encode_instead_of_strip($encode = false)
  3212. {
  3213. $this->encode_instead_of_strip = (bool) $encode;
  3214. }
  3215. public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
  3216. {
  3217. if ($attribs)
  3218. {
  3219. if (is_array($attribs))
  3220. {
  3221. $this->strip_attributes = $attribs;
  3222. }
  3223. else
  3224. {
  3225. $this->strip_attributes = explode(',', $attribs);
  3226. }
  3227. }
  3228. else
  3229. {
  3230. $this->strip_attributes = false;
  3231. }
  3232. }
  3233. public function strip_comments($strip = false)
  3234. {
  3235. $this->strip_comments = (bool) $strip;
  3236. }
  3237. public function set_output_encoding($encoding = 'UTF-8')
  3238. {
  3239. $this->output_encoding = (string) $encoding;
  3240. }
  3241. /**
  3242. * Set element/attribute key/value pairs of HTML attributes
  3243. * containing URLs that need to be resolved relative to the feed
  3244. *
  3245. * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
  3246. * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite,
  3247. * |q|@cite
  3248. *
  3249. * @since 1.0
  3250. * @param array|null $element_attribute Element/attribute key/value pairs, null for default
  3251. */
  3252. public function set_url_replacements($element_attribute = null)
  3253. {
  3254. if ($element_attribute === null)
  3255. {
  3256. $element_attribute = array(
  3257. 'a' => 'href',
  3258. 'area' => 'href',
  3259. 'blockquote' => 'cite',
  3260. 'del' => 'cite',
  3261. 'form' => 'action',
  3262. 'img' => array(
  3263. 'longdesc',
  3264. 'src'
  3265. ),
  3266. 'input' => 'src',
  3267. 'ins' => 'cite',
  3268. 'q' => 'cite'
  3269. );
  3270. }
  3271. $this->replace_url_attributes = (array) $element_attribute;
  3272. }
  3273. public function sanitize($data, $type, $base = '')
  3274. {
  3275. $data = trim($data);
  3276. if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI)
  3277. {
  3278. if ($type & SIMPLEPIE_CONSTRUCT_MAYBE_HTML)
  3279. {
  3280. 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))
  3281. {
  3282. $type |= SIMPLEPIE_CONSTRUCT_HTML;
  3283. }
  3284. else
  3285. {
  3286. $type |= SIMPLEPIE_CONSTRUCT_TEXT;
  3287. }
  3288. }
  3289. if ($type & SIMPLEPIE_CONSTRUCT_BASE64)
  3290. {
  3291. $data = base64_decode($data);
  3292. }
  3293. if ($type & (SIMPLEPIE_CONSTRUCT_HTML | SIMPLEPIE_CONSTRUCT_XHTML))
  3294. {
  3295. $document = new DOMDocument();
  3296. $document->encoding = 'UTF-8';
  3297. $data = $this->preprocess($data, $type);
  3298. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  3299. $document->loadHTML($data);
  3300. restore_error_handler();
  3301. // Strip comments
  3302. if ($this->strip_comments)
  3303. {
  3304. $xpath = new DOMXPath($document);
  3305. $comments = $xpath->query('//comment()');
  3306. foreach ($comments as $comment)
  3307. {
  3308. $comment->parentNode->removeChild($comment);
  3309. }
  3310. }
  3311. // Strip out HTML tags and attributes that might cause various security problems.
  3312. // Based on recommendations by Mark Pilgrim at:
  3313. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  3314. if ($this->strip_htmltags)
  3315. {
  3316. foreach ($this->strip_htmltags as $tag)
  3317. {
  3318. $this->strip_tag($tag, $document, $type);
  3319. }
  3320. }
  3321. if ($this->strip_attributes)
  3322. {
  3323. foreach ($this->strip_attributes as $attrib)
  3324. {
  3325. $this->strip_attr($attrib, $document);
  3326. }
  3327. }
  3328. // Replace relative URLs
  3329. $this->base = $base;
  3330. foreach ($this->replace_url_attributes as $element => $attributes)
  3331. {
  3332. $this->replace_urls($document, $element, $attributes);
  3333. }
  3334. // If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
  3335. if (isset($this->image_handler) && ((string) $this->image_handler) !== '' && $this->enable_cache)
  3336. {
  3337. $images = $document->getElementsByTagName('img');
  3338. foreach ($images as $img)
  3339. {
  3340. if ($img->hasAttribute('src'))
  3341. {
  3342. $image_url = call_user_func($this->cache_name_function, $img->getAttribute('src'));
  3343. $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, $image_url, 'spi'));
  3344. if ($cache->load())
  3345. {
  3346. $img->setAttribute('src', $this->image_handler . $image_url);
  3347. }
  3348. else
  3349. {
  3350. $file = $this->registry->create('File', array($img['attribs']['src']['data'], $this->timeout, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen));
  3351. $headers = $file->headers;
  3352. if ($file->success && ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300)))
  3353. {
  3354. if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))
  3355. {
  3356. $img->setAttribute('src', $this->image_handler . $image_url);
  3357. }
  3358. else
  3359. {
  3360. trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
  3361. }
  3362. }
  3363. }
  3364. }
  3365. }
  3366. }
  3367. // Remove the DOCTYPE
  3368. // Seems to cause segfaulting if we don't do this
  3369. if ($document->firstChild instanceof DOMDocumentType)
  3370. {
  3371. $document->removeChild($document->firstChild);
  3372. }
  3373. // Move everything from the body to the root
  3374. $real_body = $document->getElementsByTagName('body')->item(0)->childNodes->item(0);
  3375. $document->replaceChild($real_body, $document->firstChild);
  3376. // Finally, convert to a HTML string
  3377. $data = trim($document->saveHTML());
  3378. if ($this->remove_div)
  3379. {
  3380. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '', $data);
  3381. $data = preg_replace('/<\/div>$/', '', $data);
  3382. }
  3383. else
  3384. {
  3385. $data = preg_replace('/^<div' . SIMPLEPIE_PCRE_XML_ATTRIBUTE . '>/', '<div>', $data);
  3386. }
  3387. }
  3388. if ($type & SIMPLEPIE_CONSTRUCT_IRI)
  3389. {
  3390. $absolute = $this->registry->call('Misc', 'absolutize_url', array($data, $base));
  3391. if ($absolute !== false)
  3392. {
  3393. $data = $absolute;
  3394. }
  3395. }
  3396. if ($type & (SIMPLEPIE_CONSTRUCT_TEXT | SIMPLEPIE_CONSTRUCT_IRI))
  3397. {
  3398. $data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
  3399. }
  3400. if ($this->output_encoding !== 'UTF-8')
  3401. {
  3402. $data = $this->registry->call('Misc', 'change_encoding', array($data, 'UTF-8', $this->output_encoding));
  3403. }
  3404. }
  3405. return $data;
  3406. }
  3407. protected function preprocess($html, $type)
  3408. {
  3409. $ret = '';
  3410. if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML)
  3411. {
  3412. // Atom XHTML constructs are wrapped with a div by default
  3413. // Note: No protection if $html contains a stray </div>!
  3414. $html = '<div>' . $html . '</div>';
  3415. $ret .= '<!DOCTYPE html>';
  3416. $content_type = 'text/html';
  3417. }
  3418. else
  3419. {
  3420. $ret .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  3421. $content_type = 'application/xhtml+xml';
  3422. }
  3423. $ret .= '<html><head>';
  3424. $ret .= '<meta http-equiv="Content-Type" content="' . $content_type . '; charset=utf-8" />';
  3425. $ret .= '</head><body>' . $html . '</body></html>';
  3426. return $ret;
  3427. }
  3428. public function replace_urls($document, $tag, $attributes)
  3429. {
  3430. if (!is_array($attributes))
  3431. {
  3432. $attributes = array($attributes);
  3433. }
  3434. if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags))
  3435. {
  3436. $elements = $document->getElementsByTagName($tag);
  3437. foreach ($elements as $element)
  3438. {
  3439. foreach ($attributes as $attribute)
  3440. {
  3441. if ($element->hasAttribute($attribute))
  3442. {
  3443. $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
  3444. if ($value !== false)
  3445. {
  3446. $element->setAttribute($attribute, $value);
  3447. }
  3448. }
  3449. }
  3450. }
  3451. }
  3452. }
  3453. public function do_strip_htmltags($match)
  3454. {
  3455. if ($this->encode_instead_of_strip)
  3456. {
  3457. if (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  3458. {
  3459. $match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
  3460. $match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
  3461. return "&lt;$match[1]$match[2]&gt;$match[3]&lt;/$match[1]&gt;";
  3462. }
  3463. else
  3464. {
  3465. return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
  3466. }
  3467. }
  3468. elseif (isset($match[4]) && !in_array(strtolower($match[1]), array('script', 'style')))
  3469. {
  3470. return $match[4];
  3471. }
  3472. else
  3473. {
  3474. return '';
  3475. }
  3476. }
  3477. protected function strip_tag($tag, $document, $type)
  3478. {
  3479. $xpath = new DOMXPath($document);
  3480. $elements = $xpath->query('body//' . $tag);
  3481. if ($this->encode_instead_of_strip)
  3482. {
  3483. foreach ($elements as $element)
  3484. {
  3485. $fragment = $document->createDocumentFragment();
  3486. // For elements which aren't script or style, include the tag itself
  3487. if (!in_array($tag, array('script', 'style')))
  3488. {
  3489. $text = '<' . $tag;
  3490. if ($element->hasAttributes())
  3491. {
  3492. $attrs = array();
  3493. foreach ($element->attributes as $name => $attr)
  3494. {
  3495. $value = $attr->value;
  3496. // In XHTML, empty values should never exist, so we repeat the value
  3497. if (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_XHTML))
  3498. {
  3499. $value = $name;
  3500. }
  3501. // For HTML, empty is fine
  3502. elseif (empty($value) && ($type & SIMPLEPIE_CONSTRUCT_HTML))
  3503. {
  3504. $attrs[] = $name;
  3505. continue;
  3506. }
  3507. // Standard attribute text
  3508. $attrs[] = $name . '="' . $attr->value . '"';
  3509. }
  3510. $text .= ' ' . implode(' ', $attrs);
  3511. }
  3512. $text .= '>';
  3513. $fragment->appendChild(new DOMText($text));
  3514. }
  3515. $number = $element->childNodes->length;
  3516. for ($i = $number; $i > 0; $i--)
  3517. {
  3518. $child = $element->childNodes->item(0);
  3519. $fragment->appendChild($child);
  3520. }
  3521. if (!in_array($tag, array('script', 'style')))
  3522. {
  3523. $fragment->appendChild(new DOMText('</' . $tag . '>'));
  3524. }
  3525. $element->parentNode->replaceChild($fragment, $element);
  3526. }
  3527. return;
  3528. }
  3529. elseif (in_array($tag, array('script', 'style')))
  3530. {
  3531. foreach ($elements as $element)
  3532. {
  3533. $element->parentNode->removeChild($element);
  3534. }
  3535. return;
  3536. }
  3537. else
  3538. {
  3539. foreach ($elements as $element)
  3540. {
  3541. $fragment = $document->createDocumentFragment();
  3542. $number = $element->childNodes->length;
  3543. for ($i = $number; $i > 0; $i--)
  3544. {
  3545. $child = $element->childNodes->item(0);
  3546. $fragment->appendChild($child);
  3547. }
  3548. $element->parentNode->replaceChild($fragment, $element);
  3549. }
  3550. }
  3551. }
  3552. protected function strip_attr($attrib, $document)
  3553. {
  3554. $xpath = new DOMXPath($document);
  3555. $elements = $xpath->query('//*[@' . $attrib . ']');
  3556. foreach ($elements as $element)
  3557. {
  3558. $element->removeAttribute($attrib);
  3559. }
  3560. }
  3561. }
  3562. /**
  3563. * General SimplePie exception class
  3564. *
  3565. * @package SimplePie
  3566. */
  3567. class SimplePie_Exception extends Exception
  3568. {
  3569. }
  3570. /**
  3571. * Used for fetching remote files and reading local files
  3572. *
  3573. * Supports HTTP 1.0 via cURL or fsockopen, with spotty HTTP 1.1 support
  3574. *
  3575. * This class can be overloaded with {@see SimplePie::set_file_class()}
  3576. *
  3577. * @package SimplePie
  3578. * @subpackage HTTP
  3579. * @todo Move to properly supporting RFC2616 (HTTP/1.1)
  3580. */
  3581. class SimplePie_File
  3582. {
  3583. var $url;
  3584. var $useragent;
  3585. var $success = true;
  3586. var $headers = array();
  3587. var $body;
  3588. var $status_code;
  3589. var $redirects = 0;
  3590. var $error;
  3591. var $method = SIMPLEPIE_FILE_SOURCE_NONE;
  3592. public function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
  3593. {
  3594. if (class_exists('idna_convert'))
  3595. {
  3596. $idn = new idna_convert();
  3597. $parsed = SimplePie_Misc::parse_url($url);
  3598. $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  3599. }
  3600. $this->url = $url;
  3601. $this->useragent = $useragent;
  3602. if (preg_match('/^http(s)?:\/\//i', $url))
  3603. {
  3604. if ($useragent === null)
  3605. {
  3606. $useragent = ini_get('user_agent');
  3607. $this->useragent = $useragent;
  3608. }
  3609. if (!is_array($headers))
  3610. {
  3611. $headers = array();
  3612. }
  3613. if (!$force_fsockopen && function_exists('curl_exec'))
  3614. {
  3615. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_CURL;
  3616. $fp = curl_init();
  3617. $headers2 = array();
  3618. foreach ($headers as $key => $value)
  3619. {
  3620. $headers2[] = "$key: $value";
  3621. }
  3622. if (version_compare(SimplePie_Misc::get_curl_version(), '7.10.5', '>='))
  3623. {
  3624. curl_setopt($fp, CURLOPT_ENCODING, '');
  3625. }
  3626. curl_setopt($fp, CURLOPT_URL, $url);
  3627. curl_setopt($fp, CURLOPT_HEADER, 1);
  3628. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  3629. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  3630. curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
  3631. curl_setopt($fp, CURLOPT_REFERER, $url);
  3632. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  3633. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  3634. if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>='))
  3635. {
  3636. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  3637. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  3638. }
  3639. $this->headers = curl_exec($fp);
  3640. if (curl_errno($fp) === 23 || curl_errno($fp) === 61)
  3641. {
  3642. curl_setopt($fp, CURLOPT_ENCODING, 'none');
  3643. $this->headers = curl_exec($fp);
  3644. }
  3645. if (curl_errno($fp))
  3646. {
  3647. $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
  3648. $this->success = false;
  3649. }
  3650. else
  3651. {
  3652. $info = curl_getinfo($fp);
  3653. curl_close($fp);
  3654. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1);
  3655. $this->headers = array_pop($this->headers);
  3656. $parser = new SimplePie_HTTP_Parser($this->headers);
  3657. if ($parser->parse())
  3658. {
  3659. $this->headers = $parser->headers;
  3660. $this->body = $parser->body;
  3661. $this->status_code = $parser->status_code;
  3662. if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  3663. {
  3664. $this->redirects++;
  3665. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  3666. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  3667. }
  3668. }
  3669. }
  3670. }
  3671. else
  3672. {
  3673. $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE | SIMPLEPIE_FILE_SOURCE_FSOCKOPEN;
  3674. $url_parts = parse_url($url);
  3675. $socket_host = $url_parts['host'];
  3676. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https')
  3677. {
  3678. $socket_host = "ssl://$url_parts[host]";
  3679. $url_parts['port'] = 443;
  3680. }
  3681. if (!isset($url_parts['port']))
  3682. {
  3683. $url_parts['port'] = 80;
  3684. }
  3685. $fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
  3686. if (!$fp)
  3687. {
  3688. $this->error = 'fsockopen error: ' . $errstr;
  3689. $this->success = false;
  3690. }
  3691. else
  3692. {
  3693. stream_set_timeout($fp, $timeout);
  3694. if (isset($url_parts['path']))
  3695. {
  3696. if (isset($url_parts['query']))
  3697. {
  3698. $get = "$url_parts[path]?$url_parts[query]";
  3699. }
  3700. else
  3701. {
  3702. $get = $url_parts['path'];
  3703. }
  3704. }
  3705. else
  3706. {
  3707. $get = '/';
  3708. }
  3709. $out = "GET $get HTTP/1.1\r\n";
  3710. $out .= "Host: $url_parts[host]\r\n";
  3711. $out .= "User-Agent: $useragent\r\n";
  3712. if (extension_loaded('zlib'))
  3713. {
  3714. $out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
  3715. }
  3716. if (isset($url_parts['user']) && isset($url_parts['pass']))
  3717. {
  3718. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  3719. }
  3720. foreach ($headers as $key => $value)
  3721. {
  3722. $out .= "$key: $value\r\n";
  3723. }
  3724. $out .= "Connection: Close\r\n\r\n";
  3725. fwrite($fp, $out);
  3726. $info = stream_get_meta_data($fp);
  3727. $this->headers = '';
  3728. while (!$info['eof'] && !$info['timed_out'])
  3729. {
  3730. $this->headers .= fread($fp, 1160);
  3731. $info = stream_get_meta_data($fp);
  3732. }
  3733. if (!$info['timed_out'])
  3734. {
  3735. $parser = new SimplePie_HTTP_Parser($this->headers);
  3736. if ($parser->parse())
  3737. {
  3738. $this->headers = $parser->headers;
  3739. $this->body = $parser->body;
  3740. $this->status_code = $parser->status_code;
  3741. if ((in_array($this->status_code, array(300, 301, 302, 303, 307)) || $this->status_code > 307 && $this->status_code < 400) && isset($this->headers['location']) && $this->redirects < $redirects)
  3742. {
  3743. $this->redirects++;
  3744. $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url);
  3745. return $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
  3746. }
  3747. if (isset($this->headers['content-encoding']))
  3748. {
  3749. // Hey, we act dumb elsewhere, so let's do that here too
  3750. switch (strtolower(trim($this->headers['content-encoding'], "\x09\x0A\x0D\x20")))
  3751. {
  3752. case 'gzip':
  3753. case 'x-gzip':
  3754. $decoder = new SimplePie_gzdecode($this->body);
  3755. if (!$decoder->parse())
  3756. {
  3757. $this->error = 'Unable to decode HTTP "gzip" stream';
  3758. $this->success = false;
  3759. }
  3760. else
  3761. {
  3762. $this->body = $decoder->data;
  3763. }
  3764. break;
  3765. case 'deflate':
  3766. if (($decompressed = gzinflate($this->body)) !== false)
  3767. {
  3768. $this->body = $decompressed;
  3769. }
  3770. else if (($decompressed = gzuncompress($this->body)) !== false)
  3771. {
  3772. $this->body = $decompressed;
  3773. }
  3774. else if (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false)
  3775. {
  3776. $this->body = $decompressed;
  3777. }
  3778. else
  3779. {
  3780. $this->error = 'Unable to decode HTTP "deflate" stream';
  3781. $this->success = false;
  3782. }
  3783. break;
  3784. default:
  3785. $this->error = 'Unknown content coding';
  3786. $this->success = false;
  3787. }
  3788. }
  3789. }
  3790. }
  3791. else
  3792. {
  3793. $this->error = 'fsocket timed out';
  3794. $this->success = false;
  3795. }
  3796. fclose($fp);
  3797. }
  3798. }
  3799. }
  3800. else
  3801. {
  3802. $this->method = SIMPLEPIE_FILE_SOURCE_LOCAL | SIMPLEPIE_FILE_SOURCE_FILE_GET_CONTENTS;
  3803. if (!$this->body = file_get_contents($url))
  3804. {
  3805. $this->error = 'file_get_contents could not read the file';
  3806. $this->success = false;
  3807. }
  3808. }
  3809. }
  3810. }
  3811. /**
  3812. * HTTP Response Parser
  3813. *
  3814. * @package SimplePie
  3815. * @subpackage HTTP
  3816. */
  3817. class SimplePie_HTTP_Parser
  3818. {
  3819. /**
  3820. * HTTP Version
  3821. *
  3822. * @var float
  3823. */
  3824. public $http_version = 0.0;
  3825. /**
  3826. * Status code
  3827. *
  3828. * @var int
  3829. */
  3830. public $status_code = 0;
  3831. /**
  3832. * Reason phrase
  3833. *
  3834. * @var string
  3835. */
  3836. public $reason = '';
  3837. /**
  3838. * Key/value pairs of the headers
  3839. *
  3840. * @var array
  3841. */
  3842. public $headers = array();
  3843. /**
  3844. * Body of the response
  3845. *
  3846. * @var string
  3847. */
  3848. public $body = '';
  3849. /**
  3850. * Current state of the state machine
  3851. *
  3852. * @var string
  3853. */
  3854. protected $state = 'http_version';
  3855. /**
  3856. * Input data
  3857. *
  3858. * @var string
  3859. */
  3860. protected $data = '';
  3861. /**
  3862. * Input data length (to avoid calling strlen() everytime this is needed)
  3863. *
  3864. * @var int
  3865. */
  3866. protected $data_length = 0;
  3867. /**
  3868. * Current position of the pointer
  3869. *
  3870. * @var int
  3871. */
  3872. protected $position = 0;
  3873. /**
  3874. * Name of the hedaer currently being parsed
  3875. *
  3876. * @var string
  3877. */
  3878. protected $name = '';
  3879. /**
  3880. * Value of the hedaer currently being parsed
  3881. *
  3882. * @var string
  3883. */
  3884. protected $value = '';
  3885. /**
  3886. * Create an instance of the class with the input data
  3887. *
  3888. * @param string $data Input data
  3889. */
  3890. public function __construct($data)
  3891. {
  3892. $this->data = $data;
  3893. $this->data_length = strlen($this->data);
  3894. }
  3895. /**
  3896. * Parse the input data
  3897. *
  3898. * @return bool true on success, false on failure
  3899. */
  3900. public function parse()
  3901. {
  3902. while ($this->state && $this->state !== 'emit' && $this->has_data())
  3903. {
  3904. $state = $this->state;
  3905. $this->$state();
  3906. }
  3907. $this->data = '';
  3908. if ($this->state === 'emit' || $this->state === 'body')
  3909. {
  3910. return true;
  3911. }
  3912. else
  3913. {
  3914. $this->http_version = '';
  3915. $this->status_code = '';
  3916. $this->reason = '';
  3917. $this->headers = array();
  3918. $this->body = '';
  3919. return false;
  3920. }
  3921. }
  3922. /**
  3923. * Check whether there is data beyond the pointer
  3924. *
  3925. * @return bool true if there is further data, false if not
  3926. */
  3927. protected function has_data()
  3928. {
  3929. return (bool) ($this->position < $this->data_length);
  3930. }
  3931. /**
  3932. * See if the next character is LWS
  3933. *
  3934. * @return bool true if the next character is LWS, false if not
  3935. */
  3936. protected function is_linear_whitespace()
  3937. {
  3938. return (bool) ($this->data[$this->position] === "\x09"
  3939. || $this->data[$this->position] === "\x20"
  3940. || ($this->data[$this->position] === "\x0A"
  3941. && isset($this->data[$this->position + 1])
  3942. && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
  3943. }
  3944. /**
  3945. * Parse the HTTP version
  3946. */
  3947. protected function http_version()
  3948. {
  3949. if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
  3950. {
  3951. $len = strspn($this->data, '0123456789.', 5);
  3952. $this->http_version = substr($this->data, 5, $len);
  3953. $this->position += 5 + $len;
  3954. if (substr_count($this->http_version, '.') <= 1)
  3955. {
  3956. $this->http_version = (float) $this->http_version;
  3957. $this->position += strspn($this->data, "\x09\x20", $this->position);
  3958. $this->state = 'status';
  3959. }
  3960. else
  3961. {
  3962. $this->state = false;
  3963. }
  3964. }
  3965. else
  3966. {
  3967. $this->state = false;
  3968. }
  3969. }
  3970. /**
  3971. * Parse the status code
  3972. */
  3973. protected function status()
  3974. {
  3975. if ($len = strspn($this->data, '0123456789', $this->position))
  3976. {
  3977. $this->status_code = (int) substr($this->data, $this->position, $len);
  3978. $this->position += $len;
  3979. $this->state = 'reason';
  3980. }
  3981. else
  3982. {
  3983. $this->state = false;
  3984. }
  3985. }
  3986. /**
  3987. * Parse the reason phrase
  3988. */
  3989. protected function reason()
  3990. {
  3991. $len = strcspn($this->data, "\x0A", $this->position);
  3992. $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
  3993. $this->position += $len + 1;
  3994. $this->state = 'new_line';
  3995. }
  3996. /**
  3997. * Deal with a new line, shifting data around as needed
  3998. */
  3999. protected function new_line()
  4000. {
  4001. $this->value = trim($this->value, "\x0D\x20");
  4002. if ($this->name !== '' && $this->value !== '')
  4003. {
  4004. $this->name = strtolower($this->name);
  4005. // We should only use the last Content-Type header. c.f. issue #1
  4006. if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
  4007. {
  4008. $this->headers[$this->name] .= ', ' . $this->value;
  4009. }
  4010. else
  4011. {
  4012. $this->headers[$this->name] = $this->value;
  4013. }
  4014. }
  4015. $this->name = '';
  4016. $this->value = '';
  4017. if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
  4018. {
  4019. $this->position += 2;
  4020. $this->state = 'body';
  4021. }
  4022. elseif ($this->data[$this->position] === "\x0A")
  4023. {
  4024. $this->position++;
  4025. $this->state = 'body';
  4026. }
  4027. else
  4028. {
  4029. $this->state = 'name';
  4030. }
  4031. }
  4032. /**
  4033. * Parse a header name
  4034. */
  4035. protected function name()
  4036. {
  4037. $len = strcspn($this->data, "\x0A:", $this->position);
  4038. if (isset($this->data[$this->position + $len]))
  4039. {
  4040. if ($this->data[$this->position + $len] === "\x0A")
  4041. {
  4042. $this->position += $len;
  4043. $this->state = 'new_line';
  4044. }
  4045. else
  4046. {
  4047. $this->name = substr($this->data, $this->position, $len);
  4048. $this->position += $len + 1;
  4049. $this->state = 'value';
  4050. }
  4051. }
  4052. else
  4053. {
  4054. $this->state = false;
  4055. }
  4056. }
  4057. /**
  4058. * Parse LWS, replacing consecutive LWS characters with a single space
  4059. */
  4060. protected function linear_whitespace()
  4061. {
  4062. do
  4063. {
  4064. if (substr($this->data, $this->position, 2) === "\x0D\x0A")
  4065. {
  4066. $this->position += 2;
  4067. }
  4068. elseif ($this->data[$this->position] === "\x0A")
  4069. {
  4070. $this->position++;
  4071. }
  4072. $this->position += strspn($this->data, "\x09\x20", $this->position);
  4073. } while ($this->has_data() && $this->is_linear_whitespace());
  4074. $this->value .= "\x20";
  4075. }
  4076. /**
  4077. * See what state to move to while within non-quoted header values
  4078. */
  4079. protected function value()
  4080. {
  4081. if ($this->is_linear_whitespace())
  4082. {
  4083. $this->linear_whitespace();
  4084. }
  4085. else
  4086. {
  4087. switch ($this->data[$this->position])
  4088. {
  4089. case '"':
  4090. // Workaround for ETags: we have to include the quotes as
  4091. // part of the tag.
  4092. if (strtolower($this->name) === 'etag')
  4093. {
  4094. $this->value .= '"';
  4095. $this->position++;
  4096. $this->state = 'value_char';
  4097. break;
  4098. }
  4099. $this->position++;
  4100. $this->state = 'quote';
  4101. break;
  4102. case "\x0A":
  4103. $this->position++;
  4104. $this->state = 'new_line';
  4105. break;
  4106. default:
  4107. $this->state = 'value_char';
  4108. break;
  4109. }
  4110. }
  4111. }
  4112. /**
  4113. * Parse a header value while outside quotes
  4114. */
  4115. protected function value_char()
  4116. {
  4117. $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
  4118. $this->value .= substr($this->data, $this->position, $len);
  4119. $this->position += $len;
  4120. $this->state = 'value';
  4121. }
  4122. /**
  4123. * See what state to move to while within quoted header values
  4124. */
  4125. protected function quote()
  4126. {
  4127. if ($this->is_linear_whitespace())
  4128. {
  4129. $this->linear_whitespace();
  4130. }
  4131. else
  4132. {
  4133. switch ($this->data[$this->position])
  4134. {
  4135. case '"':
  4136. $this->position++;
  4137. $this->state = 'value';
  4138. break;
  4139. case "\x0A":
  4140. $this->position++;
  4141. $this->state = 'new_line';
  4142. break;
  4143. case '\\':
  4144. $this->position++;
  4145. $this->state = 'quote_escaped';
  4146. break;
  4147. default:
  4148. $this->state = 'quote_char';
  4149. break;
  4150. }
  4151. }
  4152. }
  4153. /**
  4154. * Parse a header value while within quotes
  4155. */
  4156. protected function quote_char()
  4157. {
  4158. $len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
  4159. $this->value .= substr($this->data, $this->position, $len);
  4160. $this->position += $len;
  4161. $this->state = 'value';
  4162. }
  4163. /**
  4164. * Parse an escaped character within quotes
  4165. */
  4166. protected function quote_escaped()
  4167. {
  4168. $this->value .= $this->data[$this->position];
  4169. $this->position++;
  4170. $this->state = 'quote';
  4171. }
  4172. /**
  4173. * Parse the body
  4174. */
  4175. protected function body()
  4176. {
  4177. $this->body = substr($this->data, $this->position);
  4178. if (!empty($this->headers['transfer-encoding']))
  4179. {
  4180. unset($this->headers['transfer-encoding']);
  4181. $this->state = 'chunked';
  4182. }
  4183. else
  4184. {
  4185. $this->state = 'emit';
  4186. }
  4187. }
  4188. /**
  4189. * Parsed a "Transfer-Encoding: chunked" body
  4190. */
  4191. protected function chunked()
  4192. {
  4193. if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body)))
  4194. {
  4195. $this->state = 'emit';
  4196. return;
  4197. }
  4198. $decoded = '';
  4199. $encoded = $this->body;
  4200. while (true)
  4201. {
  4202. $is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
  4203. if (!$is_chunked)
  4204. {
  4205. // Looks like it's not chunked after all
  4206. $this->state = 'emit';
  4207. return;
  4208. }
  4209. $length = hexdec(trim($matches[1]));
  4210. if ($length === 0)
  4211. {
  4212. // Ignore trailer headers
  4213. $this->state = 'emit';
  4214. $this->body = $decoded;
  4215. return;
  4216. }
  4217. $chunk_length = strlen($matches[0]);
  4218. $decoded .= $part = substr($encoded, $chunk_length, $length);
  4219. $encoded = substr($encoded, $chunk_length + $length + 2);
  4220. if (trim($encoded) === '0' || empty($encoded))
  4221. {
  4222. $this->state = 'emit';
  4223. $this->body = $decoded;
  4224. return;
  4225. }
  4226. }
  4227. }
  4228. }
  4229. /**
  4230. * Handles `<media:restriction>` as defined in Media RSS
  4231. *
  4232. * Used by {@see SimplePie_Enclosure::get_restriction()} and {@see SimplePie_Enclosure::get_restrictions()}
  4233. *
  4234. * This class can be overloaded with {@see SimplePie::set_restriction_class()}
  4235. *
  4236. * @package SimplePie
  4237. * @subpackage API
  4238. */
  4239. class SimplePie_Restriction
  4240. {
  4241. /**
  4242. * Relationship ('allow'/'deny')
  4243. *
  4244. * @var string
  4245. * @see get_relationship()
  4246. */
  4247. var $relationship;
  4248. /**
  4249. * Type of restriction
  4250. *
  4251. * @var string
  4252. * @see get_type()
  4253. */
  4254. var $type;
  4255. /**
  4256. * Restricted values
  4257. *
  4258. * @var string
  4259. * @see get_value()
  4260. */
  4261. var $value;
  4262. /**
  4263. * Constructor, used to input the data
  4264. *
  4265. * For documentation on all the parameters, see the corresponding
  4266. * properties and their accessors
  4267. */
  4268. public function __construct($relationship = null, $type = null, $value = null)
  4269. {
  4270. $this->relationship = $relationship;
  4271. $this->type = $type;
  4272. $this->value = $value;
  4273. }
  4274. /**
  4275. * String-ified version
  4276. *
  4277. * @return string
  4278. */
  4279. public function __toString()
  4280. {
  4281. // There is no $this->data here
  4282. return md5(serialize($this));
  4283. }
  4284. /**
  4285. * Get the relationship
  4286. *
  4287. * @return string|null Either 'allow' or 'deny'
  4288. */
  4289. public function get_relationship()
  4290. {
  4291. if ($this->relationship !== null)
  4292. {
  4293. return $this->relationship;
  4294. }
  4295. else
  4296. {
  4297. return null;
  4298. }
  4299. }
  4300. /**
  4301. * Get the type
  4302. *
  4303. * @return string|null
  4304. */
  4305. public function get_type()
  4306. {
  4307. if ($this->type !== null)
  4308. {
  4309. return $this->type;
  4310. }
  4311. else
  4312. {
  4313. return null;
  4314. }
  4315. }
  4316. /**
  4317. * Get the list of restricted things
  4318. *
  4319. * @return string|null
  4320. */
  4321. public function get_value()
  4322. {
  4323. if ($this->value !== null)
  4324. {
  4325. return $this->value;
  4326. }
  4327. else
  4328. {
  4329. return null;
  4330. }
  4331. }
  4332. }
  4333. /**
  4334. * Manages all item-related data
  4335. *
  4336. * Used by {@see SimplePie::get_item()} and {@see SimplePie::get_items()}
  4337. *
  4338. * This class can be overloaded with {@see SimplePie::set_item_class()}
  4339. *
  4340. * @package SimplePie
  4341. * @subpackage API
  4342. */
  4343. class SimplePie_Item
  4344. {
  4345. /**
  4346. * Parent feed
  4347. *
  4348. * @access private
  4349. * @var SimplePie
  4350. */
  4351. var $feed;
  4352. /**
  4353. * Raw data
  4354. *
  4355. * @access private
  4356. * @var array
  4357. */
  4358. var $data = array();
  4359. /**
  4360. * Registry object
  4361. *
  4362. * @see set_registry
  4363. * @var SimplePie_Registry
  4364. */
  4365. protected $registry;
  4366. /**
  4367. * Create a new item object
  4368. *
  4369. * This is usually used by {@see SimplePie::get_items} and
  4370. * {@see SimplePie::get_item}. Avoid creating this manually.
  4371. *
  4372. * @param SimplePie $feed Parent feed
  4373. * @param array $data Raw data
  4374. */
  4375. public function __construct($feed, $data)
  4376. {
  4377. $this->feed = $feed;
  4378. $this->data = $data;
  4379. }
  4380. /**
  4381. * Set the registry handler
  4382. *
  4383. * This is usually used by {@see SimplePie_Registry::create}
  4384. *
  4385. * @since 1.3
  4386. * @param SimplePie_Registry $registry
  4387. */
  4388. public function set_registry(SimplePie_Registry $registry)
  4389. {
  4390. $this->registry = $registry;
  4391. }
  4392. /**
  4393. * Get a string representation of the item
  4394. *
  4395. * @return string
  4396. */
  4397. public function __toString()
  4398. {
  4399. return md5(serialize($this->data));
  4400. }
  4401. /**
  4402. * Remove items that link back to this before destroying this object
  4403. */
  4404. public function __destruct()
  4405. {
  4406. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  4407. {
  4408. unset($this->feed);
  4409. }
  4410. }
  4411. /**
  4412. * Get data for an item-level element
  4413. *
  4414. * This method allows you to get access to ANY element/attribute that is a
  4415. * sub-element of the item/entry tag.
  4416. *
  4417. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  4418. *
  4419. * @since 1.0
  4420. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  4421. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  4422. * @param string $tag Tag name
  4423. * @return array
  4424. */
  4425. public function get_item_tags($namespace, $tag)
  4426. {
  4427. if (isset($this->data['child'][$namespace][$tag]))
  4428. {
  4429. return $this->data['child'][$namespace][$tag];
  4430. }
  4431. else
  4432. {
  4433. return null;
  4434. }
  4435. }
  4436. /**
  4437. * Get the base URL value from the parent feed
  4438. *
  4439. * Uses `<xml:base>`
  4440. *
  4441. * @param array $element
  4442. * @return string
  4443. */
  4444. public function get_base($element = array())
  4445. {
  4446. return $this->feed->get_base($element);
  4447. }
  4448. /**
  4449. * Sanitize feed data
  4450. *
  4451. * @access private
  4452. * @see SimplePie::sanitize()
  4453. * @param string $data Data to sanitize
  4454. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
  4455. * @param string $base Base URL to resolve URLs against
  4456. * @return string Sanitized data
  4457. */
  4458. public function sanitize($data, $type, $base = '')
  4459. {
  4460. return $this->feed->sanitize($data, $type, $base);
  4461. }
  4462. /**
  4463. * Get the parent feed
  4464. *
  4465. * Note: this may not work as you think for multifeeds!
  4466. *
  4467. * @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed
  4468. * @since 1.0
  4469. * @return SimplePie
  4470. */
  4471. public function get_feed()
  4472. {
  4473. return $this->feed;
  4474. }
  4475. /**
  4476. * Get the unique identifier for the item
  4477. *
  4478. * This is usually used when writing code to check for new items in a feed.
  4479. *
  4480. * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute
  4481. * for RDF. If none of these are supplied (or `$hash` is true), creates an
  4482. * MD5 hash based on the permalink and title. If either of those are not
  4483. * supplied, creates a hash based on the full feed data.
  4484. *
  4485. * @since Beta 2
  4486. * @param boolean $hash Should we force using a hash instead of the supplied ID?
  4487. * @return string
  4488. */
  4489. public function get_id($hash = false)
  4490. {
  4491. if (!$hash)
  4492. {
  4493. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  4494. {
  4495. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4496. }
  4497. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  4498. {
  4499. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4500. }
  4501. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  4502. {
  4503. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4504. }
  4505. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  4506. {
  4507. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4508. }
  4509. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  4510. {
  4511. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4512. }
  4513. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  4514. {
  4515. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  4516. }
  4517. elseif (($return = $this->get_permalink()) !== null)
  4518. {
  4519. return $return;
  4520. }
  4521. elseif (($return = $this->get_title()) !== null)
  4522. {
  4523. return $return;
  4524. }
  4525. }
  4526. if ($this->get_permalink() !== null || $this->get_title() !== null)
  4527. {
  4528. return md5($this->get_permalink() . $this->get_title());
  4529. }
  4530. else
  4531. {
  4532. return md5(serialize($this->data));
  4533. }
  4534. }
  4535. /**
  4536. * Get the title of the item
  4537. *
  4538. * Uses `<atom:title>`, `<title>` or `<dc:title>`
  4539. *
  4540. * @since Beta 2 (previously called `get_item_title` since 0.8)
  4541. * @return string|null
  4542. */
  4543. public function get_title()
  4544. {
  4545. if (!isset($this->data['title']))
  4546. {
  4547. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  4548. {
  4549. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4550. }
  4551. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  4552. {
  4553. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4554. }
  4555. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  4556. {
  4557. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4558. }
  4559. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  4560. {
  4561. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4562. }
  4563. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  4564. {
  4565. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4566. }
  4567. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  4568. {
  4569. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4570. }
  4571. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  4572. {
  4573. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4574. }
  4575. else
  4576. {
  4577. $this->data['title'] = null;
  4578. }
  4579. }
  4580. return $this->data['title'];
  4581. }
  4582. /**
  4583. * Get the content for the item
  4584. *
  4585. * Prefers summaries over full content , but will return full content if a
  4586. * summary does not exist.
  4587. *
  4588. * To prefer full content instead, use {@see get_content}
  4589. *
  4590. * Uses `<atom:summary>`, `<description>`, `<dc:description>` or
  4591. * `<itunes:subtitle>`
  4592. *
  4593. * @since 0.8
  4594. * @param boolean $description_only Should we avoid falling back to the content?
  4595. * @return string|null
  4596. */
  4597. public function get_description($description_only = false)
  4598. {
  4599. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
  4600. {
  4601. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4602. }
  4603. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
  4604. {
  4605. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4606. }
  4607. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  4608. {
  4609. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  4610. }
  4611. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  4612. {
  4613. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4614. }
  4615. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  4616. {
  4617. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4618. }
  4619. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  4620. {
  4621. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4622. }
  4623. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  4624. {
  4625. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4626. }
  4627. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  4628. {
  4629. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4630. }
  4631. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  4632. {
  4633. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  4634. }
  4635. elseif (!$description_only)
  4636. {
  4637. return $this->get_content(true);
  4638. }
  4639. else
  4640. {
  4641. return null;
  4642. }
  4643. }
  4644. /**
  4645. * Get the content for the item
  4646. *
  4647. * Prefers full content over summaries, but will return a summary if full
  4648. * content does not exist.
  4649. *
  4650. * To prefer summaries instead, use {@see get_description}
  4651. *
  4652. * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
  4653. *
  4654. * @since 1.0
  4655. * @param boolean $content_only Should we avoid falling back to the description?
  4656. * @return string|null
  4657. */
  4658. public function get_content($content_only = false)
  4659. {
  4660. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
  4661. {
  4662. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4663. }
  4664. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
  4665. {
  4666. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4667. }
  4668. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
  4669. {
  4670. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  4671. }
  4672. elseif (!$content_only)
  4673. {
  4674. return $this->get_description(true);
  4675. }
  4676. else
  4677. {
  4678. return null;
  4679. }
  4680. }
  4681. /**
  4682. * Get a category for the item
  4683. *
  4684. * @since Beta 3 (previously called `get_categories()` since Beta 2)
  4685. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
  4686. * @return SimplePie_Category|null
  4687. */
  4688. public function get_category($key = 0)
  4689. {
  4690. $categories = $this->get_categories();
  4691. if (isset($categories[$key]))
  4692. {
  4693. return $categories[$key];
  4694. }
  4695. else
  4696. {
  4697. return null;
  4698. }
  4699. }
  4700. /**
  4701. * Get all categories for the item
  4702. *
  4703. * Uses `<atom:category>`, `<category>` or `<dc:subject>`
  4704. *
  4705. * @since Beta 3
  4706. * @return array|null List of {@see SimplePie_Category} objects
  4707. */
  4708. public function get_categories()
  4709. {
  4710. $categories = array();
  4711. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  4712. {
  4713. $term = null;
  4714. $scheme = null;
  4715. $label = null;
  4716. if (isset($category['attribs']['']['term']))
  4717. {
  4718. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  4719. }
  4720. if (isset($category['attribs']['']['scheme']))
  4721. {
  4722. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  4723. }
  4724. if (isset($category['attribs']['']['label']))
  4725. {
  4726. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  4727. }
  4728. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  4729. }
  4730. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  4731. {
  4732. // This is really the label, but keep this as the term also for BC.
  4733. // Label will also work on retrieving because that falls back to term.
  4734. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4735. if (isset($category['attribs']['']['domain']))
  4736. {
  4737. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  4738. }
  4739. else
  4740. {
  4741. $scheme = null;
  4742. }
  4743. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  4744. }
  4745. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  4746. {
  4747. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4748. }
  4749. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  4750. {
  4751. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4752. }
  4753. if (!empty($categories))
  4754. {
  4755. return array_unique($categories);
  4756. }
  4757. else
  4758. {
  4759. return null;
  4760. }
  4761. }
  4762. /**
  4763. * Get an author for the item
  4764. *
  4765. * @since Beta 2
  4766. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
  4767. * @return SimplePie_Author|null
  4768. */
  4769. public function get_author($key = 0)
  4770. {
  4771. $authors = $this->get_authors();
  4772. if (isset($authors[$key]))
  4773. {
  4774. return $authors[$key];
  4775. }
  4776. else
  4777. {
  4778. return null;
  4779. }
  4780. }
  4781. /**
  4782. * Get a contributor for the item
  4783. *
  4784. * @since 1.1
  4785. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
  4786. * @return SimplePie_Author|null
  4787. */
  4788. public function get_contributor($key = 0)
  4789. {
  4790. $contributors = $this->get_contributors();
  4791. if (isset($contributors[$key]))
  4792. {
  4793. return $contributors[$key];
  4794. }
  4795. else
  4796. {
  4797. return null;
  4798. }
  4799. }
  4800. /**
  4801. * Get all contributors for the item
  4802. *
  4803. * Uses `<atom:contributor>`
  4804. *
  4805. * @since 1.1
  4806. * @return array|null List of {@see SimplePie_Author} objects
  4807. */
  4808. public function get_contributors()
  4809. {
  4810. $contributors = array();
  4811. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  4812. {
  4813. $name = null;
  4814. $uri = null;
  4815. $email = null;
  4816. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  4817. {
  4818. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4819. }
  4820. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  4821. {
  4822. $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]));
  4823. }
  4824. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  4825. {
  4826. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4827. }
  4828. if ($name !== null || $email !== null || $uri !== null)
  4829. {
  4830. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  4831. }
  4832. }
  4833. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  4834. {
  4835. $name = null;
  4836. $url = null;
  4837. $email = null;
  4838. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  4839. {
  4840. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4841. }
  4842. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  4843. {
  4844. $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]));
  4845. }
  4846. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  4847. {
  4848. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4849. }
  4850. if ($name !== null || $email !== null || $url !== null)
  4851. {
  4852. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  4853. }
  4854. }
  4855. if (!empty($contributors))
  4856. {
  4857. return array_unique($contributors);
  4858. }
  4859. else
  4860. {
  4861. return null;
  4862. }
  4863. }
  4864. /**
  4865. * Get all authors for the item
  4866. *
  4867. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
  4868. *
  4869. * @since Beta 2
  4870. * @return array|null List of {@see SimplePie_Author} objects
  4871. */
  4872. public function get_authors()
  4873. {
  4874. $authors = array();
  4875. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  4876. {
  4877. $name = null;
  4878. $uri = null;
  4879. $email = null;
  4880. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  4881. {
  4882. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4883. }
  4884. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  4885. {
  4886. $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]));
  4887. }
  4888. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  4889. {
  4890. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4891. }
  4892. if ($name !== null || $email !== null || $uri !== null)
  4893. {
  4894. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  4895. }
  4896. }
  4897. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  4898. {
  4899. $name = null;
  4900. $url = null;
  4901. $email = null;
  4902. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  4903. {
  4904. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4905. }
  4906. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  4907. {
  4908. $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]));
  4909. }
  4910. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  4911. {
  4912. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4913. }
  4914. if ($name !== null || $email !== null || $url !== null)
  4915. {
  4916. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  4917. }
  4918. }
  4919. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  4920. {
  4921. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
  4922. }
  4923. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  4924. {
  4925. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4926. }
  4927. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  4928. {
  4929. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4930. }
  4931. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  4932. {
  4933. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  4934. }
  4935. if (!empty($authors))
  4936. {
  4937. return array_unique($authors);
  4938. }
  4939. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  4940. {
  4941. return $authors;
  4942. }
  4943. elseif ($authors = $this->feed->get_authors())
  4944. {
  4945. return $authors;
  4946. }
  4947. else
  4948. {
  4949. return null;
  4950. }
  4951. }
  4952. /**
  4953. * Get the copyright info for the item
  4954. *
  4955. * Uses `<atom:rights>` or `<dc:rights>`
  4956. *
  4957. * @since 1.1
  4958. * @return string
  4959. */
  4960. public function get_copyright()
  4961. {
  4962. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  4963. {
  4964. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  4965. }
  4966. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  4967. {
  4968. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4969. }
  4970. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  4971. {
  4972. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  4973. }
  4974. else
  4975. {
  4976. return null;
  4977. }
  4978. }
  4979. /**
  4980. * Get the posting date/time for the item
  4981. *
  4982. * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`,
  4983. * `<atom:modified>`, `<pubDate>` or `<dc:date>`
  4984. *
  4985. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  4986. * {@see get_gmdate}
  4987. *
  4988. * @since Beta 2 (previously called `get_item_date` since 0.8)
  4989. *
  4990. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  4991. * @return int|string|null
  4992. */
  4993. public function get_date($date_format = 'j F Y, g:i a')
  4994. {
  4995. if (!isset($this->data['date']))
  4996. {
  4997. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  4998. {
  4999. $this->data['date']['raw'] = $return[0]['data'];
  5000. }
  5001. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  5002. {
  5003. $this->data['date']['raw'] = $return[0]['data'];
  5004. }
  5005. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  5006. {
  5007. $this->data['date']['raw'] = $return[0]['data'];
  5008. }
  5009. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  5010. {
  5011. $this->data['date']['raw'] = $return[0]['data'];
  5012. }
  5013. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  5014. {
  5015. $this->data['date']['raw'] = $return[0]['data'];
  5016. }
  5017. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  5018. {
  5019. $this->data['date']['raw'] = $return[0]['data'];
  5020. }
  5021. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  5022. {
  5023. $this->data['date']['raw'] = $return[0]['data'];
  5024. }
  5025. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  5026. {
  5027. $this->data['date']['raw'] = $return[0]['data'];
  5028. }
  5029. if (!empty($this->data['date']['raw']))
  5030. {
  5031. $parser = $this->registry->call('Parse_Date', 'get');
  5032. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  5033. }
  5034. else
  5035. {
  5036. $this->data['date'] = null;
  5037. }
  5038. }
  5039. if ($this->data['date'])
  5040. {
  5041. $date_format = (string) $date_format;
  5042. switch ($date_format)
  5043. {
  5044. case '':
  5045. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  5046. case 'U':
  5047. return $this->data['date']['parsed'];
  5048. default:
  5049. return date($date_format, $this->data['date']['parsed']);
  5050. }
  5051. }
  5052. else
  5053. {
  5054. return null;
  5055. }
  5056. }
  5057. /**
  5058. * Get the update date/time for the item
  5059. *
  5060. * Uses `<atom:updated>`
  5061. *
  5062. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  5063. * {@see get_gmdate}
  5064. *
  5065. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  5066. * @return int|string|null
  5067. */
  5068. public function get_updated_date($date_format = 'j F Y, g:i a')
  5069. {
  5070. if (!isset($this->data['updated']))
  5071. {
  5072. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  5073. {
  5074. $this->data['updated']['raw'] = $return[0]['data'];
  5075. }
  5076. if (!empty($this->data['updated']['raw']))
  5077. {
  5078. $parser = $this->registry->call('Parse_Date', 'get');
  5079. $this->data['updated']['parsed'] = $parser->parse($this->data['date']['raw']);
  5080. }
  5081. else
  5082. {
  5083. $this->data['updated'] = null;
  5084. }
  5085. }
  5086. if ($this->data['updated'])
  5087. {
  5088. $date_format = (string) $date_format;
  5089. switch ($date_format)
  5090. {
  5091. case '':
  5092. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  5093. case 'U':
  5094. return $this->data['updated']['parsed'];
  5095. default:
  5096. return date($date_format, $this->data['updated']['parsed']);
  5097. }
  5098. }
  5099. else
  5100. {
  5101. return null;
  5102. }
  5103. }
  5104. /**
  5105. * Get the localized posting date/time for the item
  5106. *
  5107. * Returns the date formatted in the localized language. To display in
  5108. * languages other than the server's default, you need to change the locale
  5109. * with {@link http://php.net/setlocale setlocale()}. The available
  5110. * localizations depend on which ones are installed on your web server.
  5111. *
  5112. * @since 1.0
  5113. *
  5114. * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data)
  5115. * @return int|string|null
  5116. */
  5117. public function get_local_date($date_format = '%c')
  5118. {
  5119. if (!$date_format)
  5120. {
  5121. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  5122. }
  5123. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  5124. {
  5125. return strftime($date_format, $date);
  5126. }
  5127. else
  5128. {
  5129. return null;
  5130. }
  5131. }
  5132. /**
  5133. * Get the posting date/time for the item (UTC time)
  5134. *
  5135. * @see get_date
  5136. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  5137. * @return int|string|null
  5138. */
  5139. public function get_gmdate($date_format = 'j F Y, g:i a')
  5140. {
  5141. $date = $this->get_date('U');
  5142. if ($date === null)
  5143. {
  5144. return null;
  5145. }
  5146. return gmdate($date_format, $date);
  5147. }
  5148. /**
  5149. * Get the update date/time for the item (UTC time)
  5150. *
  5151. * @see get_updated_date
  5152. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  5153. * @return int|string|null
  5154. */
  5155. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  5156. {
  5157. $date = $this->get_updated_date('U');
  5158. if ($date === null)
  5159. {
  5160. return null;
  5161. }
  5162. return gmdate($date_format, $date);
  5163. }
  5164. /**
  5165. * Get the permalink for the item
  5166. *
  5167. * Returns the first link available with a relationship of "alternate".
  5168. * Identical to {@see get_link()} with key 0
  5169. *
  5170. * @see get_link
  5171. * @since 0.8
  5172. * @return string|null Permalink URL
  5173. */
  5174. public function get_permalink()
  5175. {
  5176. $link = $this->get_link();
  5177. $enclosure = $this->get_enclosure(0);
  5178. if ($link !== null)
  5179. {
  5180. return $link;
  5181. }
  5182. elseif ($enclosure !== null)
  5183. {
  5184. return $enclosure->get_link();
  5185. }
  5186. else
  5187. {
  5188. return null;
  5189. }
  5190. }
  5191. /**
  5192. * Get a single link for the item
  5193. *
  5194. * @since Beta 3
  5195. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
  5196. * @param string $rel The relationship of the link to return
  5197. * @return string|null Link URL
  5198. */
  5199. public function get_link($key = 0, $rel = 'alternate')
  5200. {
  5201. $links = $this->get_links($rel);
  5202. if ($links[$key] !== null)
  5203. {
  5204. return $links[$key];
  5205. }
  5206. else
  5207. {
  5208. return null;
  5209. }
  5210. }
  5211. /**
  5212. * Get all links for the item
  5213. *
  5214. * Uses `<atom:link>`, `<link>` or `<guid>`
  5215. *
  5216. * @since Beta 2
  5217. * @param string $rel The relationship of links to return
  5218. * @return array|null Links found for the item (strings)
  5219. */
  5220. public function get_links($rel = 'alternate')
  5221. {
  5222. if (!isset($this->data['links']))
  5223. {
  5224. $this->data['links'] = array();
  5225. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  5226. {
  5227. if (isset($link['attribs']['']['href']))
  5228. {
  5229. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  5230. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5231. }
  5232. }
  5233. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  5234. {
  5235. if (isset($link['attribs']['']['href']))
  5236. {
  5237. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  5238. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  5239. }
  5240. }
  5241. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  5242. {
  5243. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5244. }
  5245. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  5246. {
  5247. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5248. }
  5249. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  5250. {
  5251. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5252. }
  5253. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  5254. {
  5255. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  5256. {
  5257. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  5258. }
  5259. }
  5260. $keys = array_keys($this->data['links']);
  5261. foreach ($keys as $key)
  5262. {
  5263. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  5264. {
  5265. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  5266. {
  5267. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  5268. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  5269. }
  5270. else
  5271. {
  5272. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  5273. }
  5274. }
  5275. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  5276. {
  5277. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  5278. }
  5279. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  5280. }
  5281. }
  5282. if (isset($this->data['links'][$rel]))
  5283. {
  5284. return $this->data['links'][$rel];
  5285. }
  5286. else
  5287. {
  5288. return null;
  5289. }
  5290. }
  5291. /**
  5292. * Get an enclosure from the item
  5293. *
  5294. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  5295. *
  5296. * @since Beta 2
  5297. * @todo Add ability to prefer one type of content over another (in a media group).
  5298. * @param int $key The enclosure that you want to return. Remember that arrays begin with 0, not 1
  5299. * @return SimplePie_Enclosure|null
  5300. */
  5301. public function get_enclosure($key = 0, $prefer = null)
  5302. {
  5303. $enclosures = $this->get_enclosures();
  5304. if (isset($enclosures[$key]))
  5305. {
  5306. return $enclosures[$key];
  5307. }
  5308. else
  5309. {
  5310. return null;
  5311. }
  5312. }
  5313. /**
  5314. * Get all available enclosures (podcasts, etc.)
  5315. *
  5316. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  5317. *
  5318. * At this point, we're pretty much assuming that all enclosures for an item
  5319. * are the same content. Anything else is too complicated to
  5320. * properly support.
  5321. *
  5322. * @since Beta 2
  5323. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  5324. * @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).
  5325. * @return array|null List of SimplePie_Enclosure items
  5326. */
  5327. public function get_enclosures()
  5328. {
  5329. if (!isset($this->data['enclosures']))
  5330. {
  5331. $this->data['enclosures'] = array();
  5332. // Elements
  5333. $captions_parent = null;
  5334. $categories_parent = null;
  5335. $copyrights_parent = null;
  5336. $credits_parent = null;
  5337. $description_parent = null;
  5338. $duration_parent = null;
  5339. $hashes_parent = null;
  5340. $keywords_parent = null;
  5341. $player_parent = null;
  5342. $ratings_parent = null;
  5343. $restrictions_parent = null;
  5344. $thumbnails_parent = null;
  5345. $title_parent = null;
  5346. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  5347. $parent = $this->get_feed();
  5348. // CAPTIONS
  5349. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  5350. {
  5351. foreach ($captions as $caption)
  5352. {
  5353. $caption_type = null;
  5354. $caption_lang = null;
  5355. $caption_startTime = null;
  5356. $caption_endTime = null;
  5357. $caption_text = null;
  5358. if (isset($caption['attribs']['']['type']))
  5359. {
  5360. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5361. }
  5362. if (isset($caption['attribs']['']['lang']))
  5363. {
  5364. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5365. }
  5366. if (isset($caption['attribs']['']['start']))
  5367. {
  5368. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  5369. }
  5370. if (isset($caption['attribs']['']['end']))
  5371. {
  5372. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  5373. }
  5374. if (isset($caption['data']))
  5375. {
  5376. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5377. }
  5378. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  5379. }
  5380. }
  5381. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  5382. {
  5383. foreach ($captions as $caption)
  5384. {
  5385. $caption_type = null;
  5386. $caption_lang = null;
  5387. $caption_startTime = null;
  5388. $caption_endTime = null;
  5389. $caption_text = null;
  5390. if (isset($caption['attribs']['']['type']))
  5391. {
  5392. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5393. }
  5394. if (isset($caption['attribs']['']['lang']))
  5395. {
  5396. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  5397. }
  5398. if (isset($caption['attribs']['']['start']))
  5399. {
  5400. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  5401. }
  5402. if (isset($caption['attribs']['']['end']))
  5403. {
  5404. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  5405. }
  5406. if (isset($caption['data']))
  5407. {
  5408. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5409. }
  5410. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  5411. }
  5412. }
  5413. if (is_array($captions_parent))
  5414. {
  5415. $captions_parent = array_values(array_unique($captions_parent));
  5416. }
  5417. // CATEGORIES
  5418. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  5419. {
  5420. $term = null;
  5421. $scheme = null;
  5422. $label = null;
  5423. if (isset($category['data']))
  5424. {
  5425. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5426. }
  5427. if (isset($category['attribs']['']['scheme']))
  5428. {
  5429. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5430. }
  5431. else
  5432. {
  5433. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  5434. }
  5435. if (isset($category['attribs']['']['label']))
  5436. {
  5437. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5438. }
  5439. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5440. }
  5441. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  5442. {
  5443. $term = null;
  5444. $scheme = null;
  5445. $label = null;
  5446. if (isset($category['data']))
  5447. {
  5448. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5449. }
  5450. if (isset($category['attribs']['']['scheme']))
  5451. {
  5452. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5453. }
  5454. else
  5455. {
  5456. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  5457. }
  5458. if (isset($category['attribs']['']['label']))
  5459. {
  5460. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  5461. }
  5462. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5463. }
  5464. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  5465. {
  5466. $term = null;
  5467. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  5468. $label = null;
  5469. if (isset($category['attribs']['']['text']))
  5470. {
  5471. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  5472. }
  5473. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5474. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  5475. {
  5476. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  5477. {
  5478. if (isset($subcategory['attribs']['']['text']))
  5479. {
  5480. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  5481. }
  5482. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  5483. }
  5484. }
  5485. }
  5486. if (is_array($categories_parent))
  5487. {
  5488. $categories_parent = array_values(array_unique($categories_parent));
  5489. }
  5490. // COPYRIGHT
  5491. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  5492. {
  5493. $copyright_url = null;
  5494. $copyright_label = null;
  5495. if (isset($copyright[0]['attribs']['']['url']))
  5496. {
  5497. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  5498. }
  5499. if (isset($copyright[0]['data']))
  5500. {
  5501. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5502. }
  5503. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  5504. }
  5505. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  5506. {
  5507. $copyright_url = null;
  5508. $copyright_label = null;
  5509. if (isset($copyright[0]['attribs']['']['url']))
  5510. {
  5511. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  5512. }
  5513. if (isset($copyright[0]['data']))
  5514. {
  5515. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5516. }
  5517. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  5518. }
  5519. // CREDITS
  5520. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  5521. {
  5522. foreach ($credits as $credit)
  5523. {
  5524. $credit_role = null;
  5525. $credit_scheme = null;
  5526. $credit_name = null;
  5527. if (isset($credit['attribs']['']['role']))
  5528. {
  5529. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  5530. }
  5531. if (isset($credit['attribs']['']['scheme']))
  5532. {
  5533. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5534. }
  5535. else
  5536. {
  5537. $credit_scheme = 'urn:ebu';
  5538. }
  5539. if (isset($credit['data']))
  5540. {
  5541. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5542. }
  5543. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  5544. }
  5545. }
  5546. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  5547. {
  5548. foreach ($credits as $credit)
  5549. {
  5550. $credit_role = null;
  5551. $credit_scheme = null;
  5552. $credit_name = null;
  5553. if (isset($credit['attribs']['']['role']))
  5554. {
  5555. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  5556. }
  5557. if (isset($credit['attribs']['']['scheme']))
  5558. {
  5559. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5560. }
  5561. else
  5562. {
  5563. $credit_scheme = 'urn:ebu';
  5564. }
  5565. if (isset($credit['data']))
  5566. {
  5567. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5568. }
  5569. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  5570. }
  5571. }
  5572. if (is_array($credits_parent))
  5573. {
  5574. $credits_parent = array_values(array_unique($credits_parent));
  5575. }
  5576. // DESCRIPTION
  5577. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  5578. {
  5579. if (isset($description_parent[0]['data']))
  5580. {
  5581. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5582. }
  5583. }
  5584. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  5585. {
  5586. if (isset($description_parent[0]['data']))
  5587. {
  5588. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5589. }
  5590. }
  5591. // DURATION
  5592. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  5593. {
  5594. $seconds = null;
  5595. $minutes = null;
  5596. $hours = null;
  5597. if (isset($duration_parent[0]['data']))
  5598. {
  5599. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5600. if (sizeof($temp) > 0)
  5601. {
  5602. $seconds = (int) array_pop($temp);
  5603. }
  5604. if (sizeof($temp) > 0)
  5605. {
  5606. $minutes = (int) array_pop($temp);
  5607. $seconds += $minutes * 60;
  5608. }
  5609. if (sizeof($temp) > 0)
  5610. {
  5611. $hours = (int) array_pop($temp);
  5612. $seconds += $hours * 3600;
  5613. }
  5614. unset($temp);
  5615. $duration_parent = $seconds;
  5616. }
  5617. }
  5618. // HASHES
  5619. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  5620. {
  5621. foreach ($hashes_iterator as $hash)
  5622. {
  5623. $value = null;
  5624. $algo = null;
  5625. if (isset($hash['data']))
  5626. {
  5627. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5628. }
  5629. if (isset($hash['attribs']['']['algo']))
  5630. {
  5631. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  5632. }
  5633. else
  5634. {
  5635. $algo = 'md5';
  5636. }
  5637. $hashes_parent[] = $algo.':'.$value;
  5638. }
  5639. }
  5640. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  5641. {
  5642. foreach ($hashes_iterator as $hash)
  5643. {
  5644. $value = null;
  5645. $algo = null;
  5646. if (isset($hash['data']))
  5647. {
  5648. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5649. }
  5650. if (isset($hash['attribs']['']['algo']))
  5651. {
  5652. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  5653. }
  5654. else
  5655. {
  5656. $algo = 'md5';
  5657. }
  5658. $hashes_parent[] = $algo.':'.$value;
  5659. }
  5660. }
  5661. if (is_array($hashes_parent))
  5662. {
  5663. $hashes_parent = array_values(array_unique($hashes_parent));
  5664. }
  5665. // KEYWORDS
  5666. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  5667. {
  5668. if (isset($keywords[0]['data']))
  5669. {
  5670. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5671. foreach ($temp as $word)
  5672. {
  5673. $keywords_parent[] = trim($word);
  5674. }
  5675. }
  5676. unset($temp);
  5677. }
  5678. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  5679. {
  5680. if (isset($keywords[0]['data']))
  5681. {
  5682. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5683. foreach ($temp as $word)
  5684. {
  5685. $keywords_parent[] = trim($word);
  5686. }
  5687. }
  5688. unset($temp);
  5689. }
  5690. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  5691. {
  5692. if (isset($keywords[0]['data']))
  5693. {
  5694. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5695. foreach ($temp as $word)
  5696. {
  5697. $keywords_parent[] = trim($word);
  5698. }
  5699. }
  5700. unset($temp);
  5701. }
  5702. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  5703. {
  5704. if (isset($keywords[0]['data']))
  5705. {
  5706. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  5707. foreach ($temp as $word)
  5708. {
  5709. $keywords_parent[] = trim($word);
  5710. }
  5711. }
  5712. unset($temp);
  5713. }
  5714. if (is_array($keywords_parent))
  5715. {
  5716. $keywords_parent = array_values(array_unique($keywords_parent));
  5717. }
  5718. // PLAYER
  5719. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  5720. {
  5721. if (isset($player_parent[0]['attribs']['']['url']))
  5722. {
  5723. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5724. }
  5725. }
  5726. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  5727. {
  5728. if (isset($player_parent[0]['attribs']['']['url']))
  5729. {
  5730. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5731. }
  5732. }
  5733. // RATINGS
  5734. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  5735. {
  5736. foreach ($ratings as $rating)
  5737. {
  5738. $rating_scheme = null;
  5739. $rating_value = null;
  5740. if (isset($rating['attribs']['']['scheme']))
  5741. {
  5742. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5743. }
  5744. else
  5745. {
  5746. $rating_scheme = 'urn:simple';
  5747. }
  5748. if (isset($rating['data']))
  5749. {
  5750. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5751. }
  5752. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5753. }
  5754. }
  5755. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  5756. {
  5757. foreach ($ratings as $rating)
  5758. {
  5759. $rating_scheme = 'urn:itunes';
  5760. $rating_value = null;
  5761. if (isset($rating['data']))
  5762. {
  5763. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5764. }
  5765. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5766. }
  5767. }
  5768. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  5769. {
  5770. foreach ($ratings as $rating)
  5771. {
  5772. $rating_scheme = null;
  5773. $rating_value = null;
  5774. if (isset($rating['attribs']['']['scheme']))
  5775. {
  5776. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  5777. }
  5778. else
  5779. {
  5780. $rating_scheme = 'urn:simple';
  5781. }
  5782. if (isset($rating['data']))
  5783. {
  5784. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5785. }
  5786. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5787. }
  5788. }
  5789. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  5790. {
  5791. foreach ($ratings as $rating)
  5792. {
  5793. $rating_scheme = 'urn:itunes';
  5794. $rating_value = null;
  5795. if (isset($rating['data']))
  5796. {
  5797. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5798. }
  5799. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  5800. }
  5801. }
  5802. if (is_array($ratings_parent))
  5803. {
  5804. $ratings_parent = array_values(array_unique($ratings_parent));
  5805. }
  5806. // RESTRICTIONS
  5807. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  5808. {
  5809. foreach ($restrictions as $restriction)
  5810. {
  5811. $restriction_relationship = null;
  5812. $restriction_type = null;
  5813. $restriction_value = null;
  5814. if (isset($restriction['attribs']['']['relationship']))
  5815. {
  5816. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  5817. }
  5818. if (isset($restriction['attribs']['']['type']))
  5819. {
  5820. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5821. }
  5822. if (isset($restriction['data']))
  5823. {
  5824. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5825. }
  5826. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5827. }
  5828. }
  5829. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  5830. {
  5831. foreach ($restrictions as $restriction)
  5832. {
  5833. $restriction_relationship = 'allow';
  5834. $restriction_type = null;
  5835. $restriction_value = 'itunes';
  5836. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  5837. {
  5838. $restriction_relationship = 'deny';
  5839. }
  5840. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5841. }
  5842. }
  5843. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  5844. {
  5845. foreach ($restrictions as $restriction)
  5846. {
  5847. $restriction_relationship = null;
  5848. $restriction_type = null;
  5849. $restriction_value = null;
  5850. if (isset($restriction['attribs']['']['relationship']))
  5851. {
  5852. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  5853. }
  5854. if (isset($restriction['attribs']['']['type']))
  5855. {
  5856. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  5857. }
  5858. if (isset($restriction['data']))
  5859. {
  5860. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5861. }
  5862. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5863. }
  5864. }
  5865. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  5866. {
  5867. foreach ($restrictions as $restriction)
  5868. {
  5869. $restriction_relationship = 'allow';
  5870. $restriction_type = null;
  5871. $restriction_value = 'itunes';
  5872. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  5873. {
  5874. $restriction_relationship = 'deny';
  5875. }
  5876. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  5877. }
  5878. }
  5879. if (is_array($restrictions_parent))
  5880. {
  5881. $restrictions_parent = array_values(array_unique($restrictions_parent));
  5882. }
  5883. else
  5884. {
  5885. $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
  5886. }
  5887. // THUMBNAILS
  5888. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  5889. {
  5890. foreach ($thumbnails as $thumbnail)
  5891. {
  5892. if (isset($thumbnail['attribs']['']['url']))
  5893. {
  5894. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5895. }
  5896. }
  5897. }
  5898. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  5899. {
  5900. foreach ($thumbnails as $thumbnail)
  5901. {
  5902. if (isset($thumbnail['attribs']['']['url']))
  5903. {
  5904. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  5905. }
  5906. }
  5907. }
  5908. // TITLES
  5909. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  5910. {
  5911. if (isset($title_parent[0]['data']))
  5912. {
  5913. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5914. }
  5915. }
  5916. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  5917. {
  5918. if (isset($title_parent[0]['data']))
  5919. {
  5920. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  5921. }
  5922. }
  5923. // Clear the memory
  5924. unset($parent);
  5925. // Attributes
  5926. $bitrate = null;
  5927. $channels = null;
  5928. $duration = null;
  5929. $expression = null;
  5930. $framerate = null;
  5931. $height = null;
  5932. $javascript = null;
  5933. $lang = null;
  5934. $length = null;
  5935. $medium = null;
  5936. $samplingrate = null;
  5937. $type = null;
  5938. $url = null;
  5939. $width = null;
  5940. // Elements
  5941. $captions = null;
  5942. $categories = null;
  5943. $copyrights = null;
  5944. $credits = null;
  5945. $description = null;
  5946. $hashes = null;
  5947. $keywords = null;
  5948. $player = null;
  5949. $ratings = null;
  5950. $restrictions = null;
  5951. $thumbnails = null;
  5952. $title = null;
  5953. // If we have media:group tags, loop through them.
  5954. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  5955. {
  5956. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  5957. {
  5958. // If we have media:content tags, loop through them.
  5959. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  5960. {
  5961. if (isset($content['attribs']['']['url']))
  5962. {
  5963. // Attributes
  5964. $bitrate = null;
  5965. $channels = null;
  5966. $duration = null;
  5967. $expression = null;
  5968. $framerate = null;
  5969. $height = null;
  5970. $javascript = null;
  5971. $lang = null;
  5972. $length = null;
  5973. $medium = null;
  5974. $samplingrate = null;
  5975. $type = null;
  5976. $url = null;
  5977. $width = null;
  5978. // Elements
  5979. $captions = null;
  5980. $categories = null;
  5981. $copyrights = null;
  5982. $credits = null;
  5983. $description = null;
  5984. $hashes = null;
  5985. $keywords = null;
  5986. $player = null;
  5987. $ratings = null;
  5988. $restrictions = null;
  5989. $thumbnails = null;
  5990. $title = null;
  5991. // Start checking the attributes of media:content
  5992. if (isset($content['attribs']['']['bitrate']))
  5993. {
  5994. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  5995. }
  5996. if (isset($content['attribs']['']['channels']))
  5997. {
  5998. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  5999. }
  6000. if (isset($content['attribs']['']['duration']))
  6001. {
  6002. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  6003. }
  6004. else
  6005. {
  6006. $duration = $duration_parent;
  6007. }
  6008. if (isset($content['attribs']['']['expression']))
  6009. {
  6010. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  6011. }
  6012. if (isset($content['attribs']['']['framerate']))
  6013. {
  6014. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6015. }
  6016. if (isset($content['attribs']['']['height']))
  6017. {
  6018. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  6019. }
  6020. if (isset($content['attribs']['']['lang']))
  6021. {
  6022. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6023. }
  6024. if (isset($content['attribs']['']['fileSize']))
  6025. {
  6026. $length = ceil($content['attribs']['']['fileSize']);
  6027. }
  6028. if (isset($content['attribs']['']['medium']))
  6029. {
  6030. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  6031. }
  6032. if (isset($content['attribs']['']['samplingrate']))
  6033. {
  6034. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6035. }
  6036. if (isset($content['attribs']['']['type']))
  6037. {
  6038. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6039. }
  6040. if (isset($content['attribs']['']['width']))
  6041. {
  6042. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  6043. }
  6044. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6045. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  6046. // CAPTIONS
  6047. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  6048. {
  6049. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  6050. {
  6051. $caption_type = null;
  6052. $caption_lang = null;
  6053. $caption_startTime = null;
  6054. $caption_endTime = null;
  6055. $caption_text = null;
  6056. if (isset($caption['attribs']['']['type']))
  6057. {
  6058. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6059. }
  6060. if (isset($caption['attribs']['']['lang']))
  6061. {
  6062. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6063. }
  6064. if (isset($caption['attribs']['']['start']))
  6065. {
  6066. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6067. }
  6068. if (isset($caption['attribs']['']['end']))
  6069. {
  6070. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6071. }
  6072. if (isset($caption['data']))
  6073. {
  6074. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6075. }
  6076. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6077. }
  6078. if (is_array($captions))
  6079. {
  6080. $captions = array_values(array_unique($captions));
  6081. }
  6082. }
  6083. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  6084. {
  6085. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  6086. {
  6087. $caption_type = null;
  6088. $caption_lang = null;
  6089. $caption_startTime = null;
  6090. $caption_endTime = null;
  6091. $caption_text = null;
  6092. if (isset($caption['attribs']['']['type']))
  6093. {
  6094. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6095. }
  6096. if (isset($caption['attribs']['']['lang']))
  6097. {
  6098. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6099. }
  6100. if (isset($caption['attribs']['']['start']))
  6101. {
  6102. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6103. }
  6104. if (isset($caption['attribs']['']['end']))
  6105. {
  6106. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6107. }
  6108. if (isset($caption['data']))
  6109. {
  6110. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6111. }
  6112. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6113. }
  6114. if (is_array($captions))
  6115. {
  6116. $captions = array_values(array_unique($captions));
  6117. }
  6118. }
  6119. else
  6120. {
  6121. $captions = $captions_parent;
  6122. }
  6123. // CATEGORIES
  6124. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  6125. {
  6126. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  6127. {
  6128. $term = null;
  6129. $scheme = null;
  6130. $label = null;
  6131. if (isset($category['data']))
  6132. {
  6133. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6134. }
  6135. if (isset($category['attribs']['']['scheme']))
  6136. {
  6137. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6138. }
  6139. else
  6140. {
  6141. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6142. }
  6143. if (isset($category['attribs']['']['label']))
  6144. {
  6145. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6146. }
  6147. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  6148. }
  6149. }
  6150. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  6151. {
  6152. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  6153. {
  6154. $term = null;
  6155. $scheme = null;
  6156. $label = null;
  6157. if (isset($category['data']))
  6158. {
  6159. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6160. }
  6161. if (isset($category['attribs']['']['scheme']))
  6162. {
  6163. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6164. }
  6165. else
  6166. {
  6167. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6168. }
  6169. if (isset($category['attribs']['']['label']))
  6170. {
  6171. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6172. }
  6173. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  6174. }
  6175. }
  6176. if (is_array($categories) && is_array($categories_parent))
  6177. {
  6178. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  6179. }
  6180. elseif (is_array($categories))
  6181. {
  6182. $categories = array_values(array_unique($categories));
  6183. }
  6184. elseif (is_array($categories_parent))
  6185. {
  6186. $categories = array_values(array_unique($categories_parent));
  6187. }
  6188. // COPYRIGHTS
  6189. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  6190. {
  6191. $copyright_url = null;
  6192. $copyright_label = null;
  6193. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  6194. {
  6195. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6196. }
  6197. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  6198. {
  6199. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6200. }
  6201. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6202. }
  6203. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  6204. {
  6205. $copyright_url = null;
  6206. $copyright_label = null;
  6207. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  6208. {
  6209. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6210. }
  6211. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  6212. {
  6213. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6214. }
  6215. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6216. }
  6217. else
  6218. {
  6219. $copyrights = $copyrights_parent;
  6220. }
  6221. // CREDITS
  6222. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  6223. {
  6224. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  6225. {
  6226. $credit_role = null;
  6227. $credit_scheme = null;
  6228. $credit_name = null;
  6229. if (isset($credit['attribs']['']['role']))
  6230. {
  6231. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6232. }
  6233. if (isset($credit['attribs']['']['scheme']))
  6234. {
  6235. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6236. }
  6237. else
  6238. {
  6239. $credit_scheme = 'urn:ebu';
  6240. }
  6241. if (isset($credit['data']))
  6242. {
  6243. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6244. }
  6245. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6246. }
  6247. if (is_array($credits))
  6248. {
  6249. $credits = array_values(array_unique($credits));
  6250. }
  6251. }
  6252. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  6253. {
  6254. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  6255. {
  6256. $credit_role = null;
  6257. $credit_scheme = null;
  6258. $credit_name = null;
  6259. if (isset($credit['attribs']['']['role']))
  6260. {
  6261. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6262. }
  6263. if (isset($credit['attribs']['']['scheme']))
  6264. {
  6265. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6266. }
  6267. else
  6268. {
  6269. $credit_scheme = 'urn:ebu';
  6270. }
  6271. if (isset($credit['data']))
  6272. {
  6273. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6274. }
  6275. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6276. }
  6277. if (is_array($credits))
  6278. {
  6279. $credits = array_values(array_unique($credits));
  6280. }
  6281. }
  6282. else
  6283. {
  6284. $credits = $credits_parent;
  6285. }
  6286. // DESCRIPTION
  6287. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  6288. {
  6289. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6290. }
  6291. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  6292. {
  6293. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6294. }
  6295. else
  6296. {
  6297. $description = $description_parent;
  6298. }
  6299. // HASHES
  6300. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  6301. {
  6302. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  6303. {
  6304. $value = null;
  6305. $algo = null;
  6306. if (isset($hash['data']))
  6307. {
  6308. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6309. }
  6310. if (isset($hash['attribs']['']['algo']))
  6311. {
  6312. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6313. }
  6314. else
  6315. {
  6316. $algo = 'md5';
  6317. }
  6318. $hashes[] = $algo.':'.$value;
  6319. }
  6320. if (is_array($hashes))
  6321. {
  6322. $hashes = array_values(array_unique($hashes));
  6323. }
  6324. }
  6325. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  6326. {
  6327. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  6328. {
  6329. $value = null;
  6330. $algo = null;
  6331. if (isset($hash['data']))
  6332. {
  6333. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6334. }
  6335. if (isset($hash['attribs']['']['algo']))
  6336. {
  6337. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6338. }
  6339. else
  6340. {
  6341. $algo = 'md5';
  6342. }
  6343. $hashes[] = $algo.':'.$value;
  6344. }
  6345. if (is_array($hashes))
  6346. {
  6347. $hashes = array_values(array_unique($hashes));
  6348. }
  6349. }
  6350. else
  6351. {
  6352. $hashes = $hashes_parent;
  6353. }
  6354. // KEYWORDS
  6355. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  6356. {
  6357. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  6358. {
  6359. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6360. foreach ($temp as $word)
  6361. {
  6362. $keywords[] = trim($word);
  6363. }
  6364. unset($temp);
  6365. }
  6366. if (is_array($keywords))
  6367. {
  6368. $keywords = array_values(array_unique($keywords));
  6369. }
  6370. }
  6371. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  6372. {
  6373. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  6374. {
  6375. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6376. foreach ($temp as $word)
  6377. {
  6378. $keywords[] = trim($word);
  6379. }
  6380. unset($temp);
  6381. }
  6382. if (is_array($keywords))
  6383. {
  6384. $keywords = array_values(array_unique($keywords));
  6385. }
  6386. }
  6387. else
  6388. {
  6389. $keywords = $keywords_parent;
  6390. }
  6391. // PLAYER
  6392. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  6393. {
  6394. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6395. }
  6396. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  6397. {
  6398. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6399. }
  6400. else
  6401. {
  6402. $player = $player_parent;
  6403. }
  6404. // RATINGS
  6405. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  6406. {
  6407. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  6408. {
  6409. $rating_scheme = null;
  6410. $rating_value = null;
  6411. if (isset($rating['attribs']['']['scheme']))
  6412. {
  6413. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6414. }
  6415. else
  6416. {
  6417. $rating_scheme = 'urn:simple';
  6418. }
  6419. if (isset($rating['data']))
  6420. {
  6421. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6422. }
  6423. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6424. }
  6425. if (is_array($ratings))
  6426. {
  6427. $ratings = array_values(array_unique($ratings));
  6428. }
  6429. }
  6430. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  6431. {
  6432. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  6433. {
  6434. $rating_scheme = null;
  6435. $rating_value = null;
  6436. if (isset($rating['attribs']['']['scheme']))
  6437. {
  6438. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6439. }
  6440. else
  6441. {
  6442. $rating_scheme = 'urn:simple';
  6443. }
  6444. if (isset($rating['data']))
  6445. {
  6446. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6447. }
  6448. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6449. }
  6450. if (is_array($ratings))
  6451. {
  6452. $ratings = array_values(array_unique($ratings));
  6453. }
  6454. }
  6455. else
  6456. {
  6457. $ratings = $ratings_parent;
  6458. }
  6459. // RESTRICTIONS
  6460. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  6461. {
  6462. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  6463. {
  6464. $restriction_relationship = null;
  6465. $restriction_type = null;
  6466. $restriction_value = null;
  6467. if (isset($restriction['attribs']['']['relationship']))
  6468. {
  6469. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6470. }
  6471. if (isset($restriction['attribs']['']['type']))
  6472. {
  6473. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6474. }
  6475. if (isset($restriction['data']))
  6476. {
  6477. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6478. }
  6479. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6480. }
  6481. if (is_array($restrictions))
  6482. {
  6483. $restrictions = array_values(array_unique($restrictions));
  6484. }
  6485. }
  6486. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  6487. {
  6488. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  6489. {
  6490. $restriction_relationship = null;
  6491. $restriction_type = null;
  6492. $restriction_value = null;
  6493. if (isset($restriction['attribs']['']['relationship']))
  6494. {
  6495. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6496. }
  6497. if (isset($restriction['attribs']['']['type']))
  6498. {
  6499. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6500. }
  6501. if (isset($restriction['data']))
  6502. {
  6503. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6504. }
  6505. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6506. }
  6507. if (is_array($restrictions))
  6508. {
  6509. $restrictions = array_values(array_unique($restrictions));
  6510. }
  6511. }
  6512. else
  6513. {
  6514. $restrictions = $restrictions_parent;
  6515. }
  6516. // THUMBNAILS
  6517. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  6518. {
  6519. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  6520. {
  6521. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6522. }
  6523. if (is_array($thumbnails))
  6524. {
  6525. $thumbnails = array_values(array_unique($thumbnails));
  6526. }
  6527. }
  6528. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  6529. {
  6530. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  6531. {
  6532. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6533. }
  6534. if (is_array($thumbnails))
  6535. {
  6536. $thumbnails = array_values(array_unique($thumbnails));
  6537. }
  6538. }
  6539. else
  6540. {
  6541. $thumbnails = $thumbnails_parent;
  6542. }
  6543. // TITLES
  6544. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  6545. {
  6546. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6547. }
  6548. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  6549. {
  6550. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6551. }
  6552. else
  6553. {
  6554. $title = $title_parent;
  6555. }
  6556. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  6557. }
  6558. }
  6559. }
  6560. }
  6561. // If we have standalone media:content tags, loop through them.
  6562. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  6563. {
  6564. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  6565. {
  6566. if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  6567. {
  6568. // Attributes
  6569. $bitrate = null;
  6570. $channels = null;
  6571. $duration = null;
  6572. $expression = null;
  6573. $framerate = null;
  6574. $height = null;
  6575. $javascript = null;
  6576. $lang = null;
  6577. $length = null;
  6578. $medium = null;
  6579. $samplingrate = null;
  6580. $type = null;
  6581. $url = null;
  6582. $width = null;
  6583. // Elements
  6584. $captions = null;
  6585. $categories = null;
  6586. $copyrights = null;
  6587. $credits = null;
  6588. $description = null;
  6589. $hashes = null;
  6590. $keywords = null;
  6591. $player = null;
  6592. $ratings = null;
  6593. $restrictions = null;
  6594. $thumbnails = null;
  6595. $title = null;
  6596. // Start checking the attributes of media:content
  6597. if (isset($content['attribs']['']['bitrate']))
  6598. {
  6599. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6600. }
  6601. if (isset($content['attribs']['']['channels']))
  6602. {
  6603. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  6604. }
  6605. if (isset($content['attribs']['']['duration']))
  6606. {
  6607. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  6608. }
  6609. else
  6610. {
  6611. $duration = $duration_parent;
  6612. }
  6613. if (isset($content['attribs']['']['expression']))
  6614. {
  6615. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  6616. }
  6617. if (isset($content['attribs']['']['framerate']))
  6618. {
  6619. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6620. }
  6621. if (isset($content['attribs']['']['height']))
  6622. {
  6623. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  6624. }
  6625. if (isset($content['attribs']['']['lang']))
  6626. {
  6627. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6628. }
  6629. if (isset($content['attribs']['']['fileSize']))
  6630. {
  6631. $length = ceil($content['attribs']['']['fileSize']);
  6632. }
  6633. if (isset($content['attribs']['']['medium']))
  6634. {
  6635. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  6636. }
  6637. if (isset($content['attribs']['']['samplingrate']))
  6638. {
  6639. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  6640. }
  6641. if (isset($content['attribs']['']['type']))
  6642. {
  6643. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6644. }
  6645. if (isset($content['attribs']['']['width']))
  6646. {
  6647. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  6648. }
  6649. if (isset($content['attribs']['']['url']))
  6650. {
  6651. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6652. }
  6653. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  6654. // CAPTIONS
  6655. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  6656. {
  6657. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  6658. {
  6659. $caption_type = null;
  6660. $caption_lang = null;
  6661. $caption_startTime = null;
  6662. $caption_endTime = null;
  6663. $caption_text = null;
  6664. if (isset($caption['attribs']['']['type']))
  6665. {
  6666. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6667. }
  6668. if (isset($caption['attribs']['']['lang']))
  6669. {
  6670. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  6671. }
  6672. if (isset($caption['attribs']['']['start']))
  6673. {
  6674. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  6675. }
  6676. if (isset($caption['attribs']['']['end']))
  6677. {
  6678. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  6679. }
  6680. if (isset($caption['data']))
  6681. {
  6682. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6683. }
  6684. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  6685. }
  6686. if (is_array($captions))
  6687. {
  6688. $captions = array_values(array_unique($captions));
  6689. }
  6690. }
  6691. else
  6692. {
  6693. $captions = $captions_parent;
  6694. }
  6695. // CATEGORIES
  6696. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  6697. {
  6698. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  6699. {
  6700. $term = null;
  6701. $scheme = null;
  6702. $label = null;
  6703. if (isset($category['data']))
  6704. {
  6705. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6706. }
  6707. if (isset($category['attribs']['']['scheme']))
  6708. {
  6709. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6710. }
  6711. else
  6712. {
  6713. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  6714. }
  6715. if (isset($category['attribs']['']['label']))
  6716. {
  6717. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  6718. }
  6719. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  6720. }
  6721. }
  6722. if (is_array($categories) && is_array($categories_parent))
  6723. {
  6724. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  6725. }
  6726. elseif (is_array($categories))
  6727. {
  6728. $categories = array_values(array_unique($categories));
  6729. }
  6730. elseif (is_array($categories_parent))
  6731. {
  6732. $categories = array_values(array_unique($categories_parent));
  6733. }
  6734. else
  6735. {
  6736. $categories = null;
  6737. }
  6738. // COPYRIGHTS
  6739. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  6740. {
  6741. $copyright_url = null;
  6742. $copyright_label = null;
  6743. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  6744. {
  6745. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  6746. }
  6747. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  6748. {
  6749. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6750. }
  6751. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  6752. }
  6753. else
  6754. {
  6755. $copyrights = $copyrights_parent;
  6756. }
  6757. // CREDITS
  6758. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  6759. {
  6760. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  6761. {
  6762. $credit_role = null;
  6763. $credit_scheme = null;
  6764. $credit_name = null;
  6765. if (isset($credit['attribs']['']['role']))
  6766. {
  6767. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  6768. }
  6769. if (isset($credit['attribs']['']['scheme']))
  6770. {
  6771. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6772. }
  6773. else
  6774. {
  6775. $credit_scheme = 'urn:ebu';
  6776. }
  6777. if (isset($credit['data']))
  6778. {
  6779. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6780. }
  6781. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  6782. }
  6783. if (is_array($credits))
  6784. {
  6785. $credits = array_values(array_unique($credits));
  6786. }
  6787. }
  6788. else
  6789. {
  6790. $credits = $credits_parent;
  6791. }
  6792. // DESCRIPTION
  6793. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  6794. {
  6795. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6796. }
  6797. else
  6798. {
  6799. $description = $description_parent;
  6800. }
  6801. // HASHES
  6802. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  6803. {
  6804. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  6805. {
  6806. $value = null;
  6807. $algo = null;
  6808. if (isset($hash['data']))
  6809. {
  6810. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6811. }
  6812. if (isset($hash['attribs']['']['algo']))
  6813. {
  6814. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  6815. }
  6816. else
  6817. {
  6818. $algo = 'md5';
  6819. }
  6820. $hashes[] = $algo.':'.$value;
  6821. }
  6822. if (is_array($hashes))
  6823. {
  6824. $hashes = array_values(array_unique($hashes));
  6825. }
  6826. }
  6827. else
  6828. {
  6829. $hashes = $hashes_parent;
  6830. }
  6831. // KEYWORDS
  6832. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  6833. {
  6834. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  6835. {
  6836. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  6837. foreach ($temp as $word)
  6838. {
  6839. $keywords[] = trim($word);
  6840. }
  6841. unset($temp);
  6842. }
  6843. if (is_array($keywords))
  6844. {
  6845. $keywords = array_values(array_unique($keywords));
  6846. }
  6847. }
  6848. else
  6849. {
  6850. $keywords = $keywords_parent;
  6851. }
  6852. // PLAYER
  6853. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  6854. {
  6855. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6856. }
  6857. else
  6858. {
  6859. $player = $player_parent;
  6860. }
  6861. // RATINGS
  6862. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  6863. {
  6864. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  6865. {
  6866. $rating_scheme = null;
  6867. $rating_value = null;
  6868. if (isset($rating['attribs']['']['scheme']))
  6869. {
  6870. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  6871. }
  6872. else
  6873. {
  6874. $rating_scheme = 'urn:simple';
  6875. }
  6876. if (isset($rating['data']))
  6877. {
  6878. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6879. }
  6880. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  6881. }
  6882. if (is_array($ratings))
  6883. {
  6884. $ratings = array_values(array_unique($ratings));
  6885. }
  6886. }
  6887. else
  6888. {
  6889. $ratings = $ratings_parent;
  6890. }
  6891. // RESTRICTIONS
  6892. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  6893. {
  6894. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  6895. {
  6896. $restriction_relationship = null;
  6897. $restriction_type = null;
  6898. $restriction_value = null;
  6899. if (isset($restriction['attribs']['']['relationship']))
  6900. {
  6901. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  6902. }
  6903. if (isset($restriction['attribs']['']['type']))
  6904. {
  6905. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6906. }
  6907. if (isset($restriction['data']))
  6908. {
  6909. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6910. }
  6911. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  6912. }
  6913. if (is_array($restrictions))
  6914. {
  6915. $restrictions = array_values(array_unique($restrictions));
  6916. }
  6917. }
  6918. else
  6919. {
  6920. $restrictions = $restrictions_parent;
  6921. }
  6922. // THUMBNAILS
  6923. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  6924. {
  6925. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  6926. {
  6927. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  6928. }
  6929. if (is_array($thumbnails))
  6930. {
  6931. $thumbnails = array_values(array_unique($thumbnails));
  6932. }
  6933. }
  6934. else
  6935. {
  6936. $thumbnails = $thumbnails_parent;
  6937. }
  6938. // TITLES
  6939. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  6940. {
  6941. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  6942. }
  6943. else
  6944. {
  6945. $title = $title_parent;
  6946. }
  6947. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  6948. }
  6949. }
  6950. }
  6951. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  6952. {
  6953. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  6954. {
  6955. // Attributes
  6956. $bitrate = null;
  6957. $channels = null;
  6958. $duration = null;
  6959. $expression = null;
  6960. $framerate = null;
  6961. $height = null;
  6962. $javascript = null;
  6963. $lang = null;
  6964. $length = null;
  6965. $medium = null;
  6966. $samplingrate = null;
  6967. $type = null;
  6968. $url = null;
  6969. $width = null;
  6970. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  6971. if (isset($link['attribs']['']['type']))
  6972. {
  6973. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  6974. }
  6975. if (isset($link['attribs']['']['length']))
  6976. {
  6977. $length = ceil($link['attribs']['']['length']);
  6978. }
  6979. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  6980. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $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));
  6981. }
  6982. }
  6983. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  6984. {
  6985. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  6986. {
  6987. // Attributes
  6988. $bitrate = null;
  6989. $channels = null;
  6990. $duration = null;
  6991. $expression = null;
  6992. $framerate = null;
  6993. $height = null;
  6994. $javascript = null;
  6995. $lang = null;
  6996. $length = null;
  6997. $medium = null;
  6998. $samplingrate = null;
  6999. $type = null;
  7000. $url = null;
  7001. $width = null;
  7002. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  7003. if (isset($link['attribs']['']['type']))
  7004. {
  7005. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7006. }
  7007. if (isset($link['attribs']['']['length']))
  7008. {
  7009. $length = ceil($link['attribs']['']['length']);
  7010. }
  7011. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  7012. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $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));
  7013. }
  7014. }
  7015. if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
  7016. {
  7017. if (isset($enclosure[0]['attribs']['']['url']))
  7018. {
  7019. // Attributes
  7020. $bitrate = null;
  7021. $channels = null;
  7022. $duration = null;
  7023. $expression = null;
  7024. $framerate = null;
  7025. $height = null;
  7026. $javascript = null;
  7027. $lang = null;
  7028. $length = null;
  7029. $medium = null;
  7030. $samplingrate = null;
  7031. $type = null;
  7032. $url = null;
  7033. $width = null;
  7034. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  7035. if (isset($enclosure[0]['attribs']['']['type']))
  7036. {
  7037. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  7038. }
  7039. if (isset($enclosure[0]['attribs']['']['length']))
  7040. {
  7041. $length = ceil($enclosure[0]['attribs']['']['length']);
  7042. }
  7043. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  7044. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $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));
  7045. }
  7046. }
  7047. 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))
  7048. {
  7049. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  7050. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $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));
  7051. }
  7052. $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
  7053. }
  7054. if (!empty($this->data['enclosures']))
  7055. {
  7056. return $this->data['enclosures'];
  7057. }
  7058. else
  7059. {
  7060. return null;
  7061. }
  7062. }
  7063. /**
  7064. * Get the latitude coordinates for the item
  7065. *
  7066. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  7067. *
  7068. * Uses `<geo:lat>` or `<georss:point>`
  7069. *
  7070. * @since 1.0
  7071. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  7072. * @link http://www.georss.org/ GeoRSS
  7073. * @return string|null
  7074. */
  7075. public function get_latitude()
  7076. {
  7077. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  7078. {
  7079. return (float) $return[0]['data'];
  7080. }
  7081. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  7082. {
  7083. return (float) $match[1];
  7084. }
  7085. else
  7086. {
  7087. return null;
  7088. }
  7089. }
  7090. /**
  7091. * Get the longitude coordinates for the item
  7092. *
  7093. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  7094. *
  7095. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
  7096. *
  7097. * @since 1.0
  7098. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  7099. * @link http://www.georss.org/ GeoRSS
  7100. * @return string|null
  7101. */
  7102. public function get_longitude()
  7103. {
  7104. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  7105. {
  7106. return (float) $return[0]['data'];
  7107. }
  7108. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  7109. {
  7110. return (float) $return[0]['data'];
  7111. }
  7112. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  7113. {
  7114. return (float) $match[2];
  7115. }
  7116. else
  7117. {
  7118. return null;
  7119. }
  7120. }
  7121. /**
  7122. * Get the `<atom:source>` for the item
  7123. *
  7124. * @since 1.1
  7125. * @return SimplePie_Source|null
  7126. */
  7127. public function get_source()
  7128. {
  7129. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  7130. {
  7131. return $this->registry->create('Source', array($this, $return[0]));
  7132. }
  7133. else
  7134. {
  7135. return null;
  7136. }
  7137. }
  7138. }
  7139. /**
  7140. * Manages `<media:copyright>` copyright tags as defined in Media RSS
  7141. *
  7142. * Used by {@see SimplePie_Enclosure::get_copyright()}
  7143. *
  7144. * This class can be overloaded with {@see SimplePie::set_copyright_class()}
  7145. *
  7146. * @package SimplePie
  7147. * @subpackage API
  7148. */
  7149. class SimplePie_Copyright
  7150. {
  7151. /**
  7152. * Copyright URL
  7153. *
  7154. * @var string
  7155. * @see get_url()
  7156. */
  7157. var $url;
  7158. /**
  7159. * Attribution
  7160. *
  7161. * @var string
  7162. * @see get_attribution()
  7163. */
  7164. var $label;
  7165. /**
  7166. * Constructor, used to input the data
  7167. *
  7168. * For documentation on all the parameters, see the corresponding
  7169. * properties and their accessors
  7170. */
  7171. public function __construct($url = null, $label = null)
  7172. {
  7173. $this->url = $url;
  7174. $this->label = $label;
  7175. }
  7176. /**
  7177. * String-ified version
  7178. *
  7179. * @return string
  7180. */
  7181. public function __toString()
  7182. {
  7183. // There is no $this->data here
  7184. return md5(serialize($this));
  7185. }
  7186. /**
  7187. * Get the copyright URL
  7188. *
  7189. * @return string|null URL to copyright information
  7190. */
  7191. public function get_url()
  7192. {
  7193. if ($this->url !== null)
  7194. {
  7195. return $this->url;
  7196. }
  7197. else
  7198. {
  7199. return null;
  7200. }
  7201. }
  7202. /**
  7203. * Get the attribution text
  7204. *
  7205. * @return string|null
  7206. */
  7207. public function get_attribution()
  7208. {
  7209. if ($this->label !== null)
  7210. {
  7211. return $this->label;
  7212. }
  7213. else
  7214. {
  7215. return null;
  7216. }
  7217. }
  7218. }
  7219. /**
  7220. * Manages all category-related data
  7221. *
  7222. * Used by {@see SimplePie_Item::get_category()} and {@see SimplePie_Item::get_categories()}
  7223. *
  7224. * This class can be overloaded with {@see SimplePie::set_category_class()}
  7225. *
  7226. * @package SimplePie
  7227. * @subpackage API
  7228. */
  7229. class SimplePie_Category
  7230. {
  7231. /**
  7232. * Category identifier
  7233. *
  7234. * @var string
  7235. * @see get_term
  7236. */
  7237. var $term;
  7238. /**
  7239. * Categorization scheme identifier
  7240. *
  7241. * @var string
  7242. * @see get_scheme()
  7243. */
  7244. var $scheme;
  7245. /**
  7246. * Human readable label
  7247. *
  7248. * @var string
  7249. * @see get_label()
  7250. */
  7251. var $label;
  7252. /**
  7253. * Constructor, used to input the data
  7254. *
  7255. * @param string $term
  7256. * @param string $scheme
  7257. * @param string $label
  7258. */
  7259. public function __construct($term = null, $scheme = null, $label = null)
  7260. {
  7261. $this->term = $term;
  7262. $this->scheme = $scheme;
  7263. $this->label = $label;
  7264. }
  7265. /**
  7266. * String-ified version
  7267. *
  7268. * @return string
  7269. */
  7270. public function __toString()
  7271. {
  7272. // There is no $this->data here
  7273. return md5(serialize($this));
  7274. }
  7275. /**
  7276. * Get the category identifier
  7277. *
  7278. * @return string|null
  7279. */
  7280. public function get_term()
  7281. {
  7282. if ($this->term !== null)
  7283. {
  7284. return $this->term;
  7285. }
  7286. else
  7287. {
  7288. return null;
  7289. }
  7290. }
  7291. /**
  7292. * Get the categorization scheme identifier
  7293. *
  7294. * @return string|null
  7295. */
  7296. public function get_scheme()
  7297. {
  7298. if ($this->scheme !== null)
  7299. {
  7300. return $this->scheme;
  7301. }
  7302. else
  7303. {
  7304. return null;
  7305. }
  7306. }
  7307. /**
  7308. * Get the human readable label
  7309. *
  7310. * @return string|null
  7311. */
  7312. public function get_label()
  7313. {
  7314. if ($this->label !== null)
  7315. {
  7316. return $this->label;
  7317. }
  7318. else
  7319. {
  7320. return $this->get_term();
  7321. }
  7322. }
  7323. }
  7324. /**
  7325. * Handles creating objects and calling methods
  7326. *
  7327. * Access this via {@see SimplePie::get_registry()}
  7328. *
  7329. * @package SimplePie
  7330. */
  7331. class SimplePie_Registry
  7332. {
  7333. /**
  7334. * Default class mapping
  7335. *
  7336. * Overriding classes *must* subclass these.
  7337. *
  7338. * @var array
  7339. */
  7340. protected $default = array(
  7341. 'Cache' => 'SimplePie_Cache',
  7342. 'Locator' => 'SimplePie_Locator',
  7343. 'Parser' => 'SimplePie_Parser',
  7344. 'File' => 'SimplePie_File',
  7345. 'Sanitize' => 'SimplePie_Sanitize',
  7346. 'Item' => 'SimplePie_Item',
  7347. 'Author' => 'SimplePie_Author',
  7348. 'Category' => 'SimplePie_Category',
  7349. 'Enclosure' => 'SimplePie_Enclosure',
  7350. 'Caption' => 'SimplePie_Caption',
  7351. 'Copyright' => 'SimplePie_Copyright',
  7352. 'Credit' => 'SimplePie_Credit',
  7353. 'Rating' => 'SimplePie_Rating',
  7354. 'Restriction' => 'SimplePie_Restriction',
  7355. 'Content_Type_Sniffer' => 'SimplePie_Content_Type_Sniffer',
  7356. 'Source' => 'SimplePie_Source',
  7357. 'Misc' => 'SimplePie_Misc',
  7358. 'XML_Declaration_Parser' => 'SimplePie_XML_Declaration_Parser',
  7359. 'Parse_Date' => 'SimplePie_Parse_Date',
  7360. );
  7361. /**
  7362. * Class mapping
  7363. *
  7364. * @see register()
  7365. * @var array
  7366. */
  7367. protected $classes = array();
  7368. /**
  7369. * Legacy classes
  7370. *
  7371. * @see register()
  7372. * @var array
  7373. */
  7374. protected $legacy = array();
  7375. /**
  7376. * Constructor
  7377. *
  7378. * No-op
  7379. */
  7380. public function __construct() { }
  7381. /**
  7382. * Register a class
  7383. *
  7384. * @param string $type See {@see $default} for names
  7385. * @param string $class Class name, must subclass the corresponding default
  7386. * @param bool $legacy Whether to enable legacy support for this class
  7387. * @return bool Successfulness
  7388. */
  7389. public function register($type, $class, $legacy = false)
  7390. {
  7391. if (!is_subclass_of($class, $this->default[$type]))
  7392. {
  7393. return false;
  7394. }
  7395. $this->classes[$type] = $class;
  7396. if ($legacy)
  7397. {
  7398. $this->legacy[] = $class;
  7399. }
  7400. return true;
  7401. }
  7402. /**
  7403. * Get the class registered for a type
  7404. *
  7405. * Where possible, use {@see create()} or {@see call()} instead
  7406. *
  7407. * @param string $type
  7408. * @return string|null
  7409. */
  7410. public function get_class($type)
  7411. {
  7412. if (!empty($this->classes[$type]))
  7413. {
  7414. return $this->classes[$type];
  7415. }
  7416. if (!empty($this->default[$type]))
  7417. {
  7418. return $this->default[$type];
  7419. }
  7420. return null;
  7421. }
  7422. /**
  7423. * Create a new instance of a given type
  7424. *
  7425. * @param string $type
  7426. * @param array $parameters Parameters to pass to the constructor
  7427. * @return object Instance of class
  7428. */
  7429. public function &create($type, $parameters = array())
  7430. {
  7431. $class = $this->get_class($type);
  7432. if (in_array($class, $this->legacy))
  7433. {
  7434. switch ($type)
  7435. {
  7436. case 'locator':
  7437. // Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
  7438. // Specified: file, timeout, useragent, max_checked_feeds
  7439. $replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
  7440. array_splice($parameters, 3, 1, $replacement);
  7441. break;
  7442. }
  7443. }
  7444. if (!method_exists($class, '__construct'))
  7445. {
  7446. $instance = new $class;
  7447. }
  7448. else
  7449. {
  7450. $reflector = new ReflectionClass($class);
  7451. $instance = $reflector->newInstanceArgs($parameters);
  7452. }
  7453. if (method_exists($instance, 'set_registry'))
  7454. {
  7455. $instance->set_registry($this);
  7456. }
  7457. return $instance;
  7458. }
  7459. /**
  7460. * Call a static method for a type
  7461. *
  7462. * @param string $type
  7463. * @param string $method
  7464. * @param array $parameters
  7465. * @return mixed
  7466. */
  7467. public function &call($type, $method, $parameters = array())
  7468. {
  7469. $class = $this->get_class($type);
  7470. if (in_array($class, $this->legacy))
  7471. {
  7472. switch ($type)
  7473. {
  7474. case 'Cache':
  7475. // For backwards compatibility with old non-static
  7476. // Cache::create() methods
  7477. if ($method === 'get_handler')
  7478. {
  7479. $result = @call_user_func_array(array($class, 'create'), $parameters);
  7480. return $result;
  7481. }
  7482. break;
  7483. }
  7484. }
  7485. $result = call_user_func_array(array($class, $method), $parameters);
  7486. return $result;
  7487. }
  7488. }
  7489. /**
  7490. * IRI parser/serialiser/normaliser
  7491. *
  7492. * @package SimplePie
  7493. * @subpackage HTTP
  7494. * @author Geoffrey Sneddon
  7495. * @author Steve Minutillo
  7496. * @author Ryan McCue
  7497. * @copyright 2007-2012 Geoffrey Sneddon, Steve Minutillo, Ryan McCue
  7498. * @license http://www.opensource.org/licenses/bsd-license.php
  7499. */
  7500. class SimplePie_IRI
  7501. {
  7502. /**
  7503. * Scheme
  7504. *
  7505. * @var string
  7506. */
  7507. protected $scheme = null;
  7508. /**
  7509. * User Information
  7510. *
  7511. * @var string
  7512. */
  7513. protected $iuserinfo = null;
  7514. /**
  7515. * ihost
  7516. *
  7517. * @var string
  7518. */
  7519. protected $ihost = null;
  7520. /**
  7521. * Port
  7522. *
  7523. * @var string
  7524. */
  7525. protected $port = null;
  7526. /**
  7527. * ipath
  7528. *
  7529. * @var string
  7530. */
  7531. protected $ipath = '';
  7532. /**
  7533. * iquery
  7534. *
  7535. * @var string
  7536. */
  7537. protected $iquery = null;
  7538. /**
  7539. * ifragment
  7540. *
  7541. * @var string
  7542. */
  7543. protected $ifragment = null;
  7544. /**
  7545. * Normalization database
  7546. *
  7547. * Each key is the scheme, each value is an array with each key as the IRI
  7548. * part and value as the default value for that part.
  7549. */
  7550. protected $normalization = array(
  7551. 'acap' => array(
  7552. 'port' => 674
  7553. ),
  7554. 'dict' => array(
  7555. 'port' => 2628
  7556. ),
  7557. 'file' => array(
  7558. 'ihost' => 'localhost'
  7559. ),
  7560. 'http' => array(
  7561. 'port' => 80,
  7562. 'ipath' => '/'
  7563. ),
  7564. 'https' => array(
  7565. 'port' => 443,
  7566. 'ipath' => '/'
  7567. ),
  7568. );
  7569. /**
  7570. * Return the entire IRI when you try and read the object as a string
  7571. *
  7572. * @return string
  7573. */
  7574. public function __toString()
  7575. {
  7576. return $this->get_iri();
  7577. }
  7578. /**
  7579. * Overload __set() to provide access via properties
  7580. *
  7581. * @param string $name Property name
  7582. * @param mixed $value Property value
  7583. */
  7584. public function __set($name, $value)
  7585. {
  7586. if (method_exists($this, 'set_' . $name))
  7587. {
  7588. call_user_func(array($this, 'set_' . $name), $value);
  7589. }
  7590. elseif (
  7591. $name === 'iauthority'
  7592. || $name === 'iuserinfo'
  7593. || $name === 'ihost'
  7594. || $name === 'ipath'
  7595. || $name === 'iquery'
  7596. || $name === 'ifragment'
  7597. )
  7598. {
  7599. call_user_func(array($this, 'set_' . substr($name, 1)), $value);
  7600. }
  7601. }
  7602. /**
  7603. * Overload __get() to provide access via properties
  7604. *
  7605. * @param string $name Property name
  7606. * @return mixed
  7607. */
  7608. public function __get($name)
  7609. {
  7610. // isset() returns false for null, we don't want to do that
  7611. // Also why we use array_key_exists below instead of isset()
  7612. $props = get_object_vars($this);
  7613. if (
  7614. $name === 'iri' ||
  7615. $name === 'uri' ||
  7616. $name === 'iauthority' ||
  7617. $name === 'authority'
  7618. )
  7619. {
  7620. $return = $this->{"get_$name"}();
  7621. }
  7622. elseif (array_key_exists($name, $props))
  7623. {
  7624. $return = $this->$name;
  7625. }
  7626. // host -> ihost
  7627. elseif (($prop = 'i' . $name) && array_key_exists($prop, $props))
  7628. {
  7629. $name = $prop;
  7630. $return = $this->$prop;
  7631. }
  7632. // ischeme -> scheme
  7633. elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props))
  7634. {
  7635. $name = $prop;
  7636. $return = $this->$prop;
  7637. }
  7638. else
  7639. {
  7640. trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
  7641. $return = null;
  7642. }
  7643. if ($return === null && isset($this->normalization[$this->scheme][$name]))
  7644. {
  7645. return $this->normalization[$this->scheme][$name];
  7646. }
  7647. else
  7648. {
  7649. return $return;
  7650. }
  7651. }
  7652. /**
  7653. * Overload __isset() to provide access via properties
  7654. *
  7655. * @param string $name Property name
  7656. * @return bool
  7657. */
  7658. public function __isset($name)
  7659. {
  7660. if (method_exists($this, 'get_' . $name) || isset($this->$name))
  7661. {
  7662. return true;
  7663. }
  7664. else
  7665. {
  7666. return false;
  7667. }
  7668. }
  7669. /**
  7670. * Overload __unset() to provide access via properties
  7671. *
  7672. * @param string $name Property name
  7673. */
  7674. public function __unset($name)
  7675. {
  7676. if (method_exists($this, 'set_' . $name))
  7677. {
  7678. call_user_func(array($this, 'set_' . $name), '');
  7679. }
  7680. }
  7681. /**
  7682. * Create a new IRI object, from a specified string
  7683. *
  7684. * @param string $iri
  7685. */
  7686. public function __construct($iri = null)
  7687. {
  7688. $this->set_iri($iri);
  7689. }
  7690. /**
  7691. * Create a new IRI object by resolving a relative IRI
  7692. *
  7693. * Returns false if $base is not absolute, otherwise an IRI.
  7694. *
  7695. * @param IRI|string $base (Absolute) Base IRI
  7696. * @param IRI|string $relative Relative IRI
  7697. * @return IRI|false
  7698. */
  7699. public static function absolutize($base, $relative)
  7700. {
  7701. if (!($relative instanceof SimplePie_IRI))
  7702. {
  7703. $relative = new SimplePie_IRI($relative);
  7704. }
  7705. if (!$relative->is_valid())
  7706. {
  7707. return false;
  7708. }
  7709. elseif ($relative->scheme !== null)
  7710. {
  7711. return clone $relative;
  7712. }
  7713. else
  7714. {
  7715. if (!($base instanceof SimplePie_IRI))
  7716. {
  7717. $base = new SimplePie_IRI($base);
  7718. }
  7719. if ($base->scheme !== null && $base->is_valid())
  7720. {
  7721. if ($relative->get_iri() !== '')
  7722. {
  7723. if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null)
  7724. {
  7725. $target = clone $relative;
  7726. $target->scheme = $base->scheme;
  7727. }
  7728. else
  7729. {
  7730. $target = new SimplePie_IRI;
  7731. $target->scheme = $base->scheme;
  7732. $target->iuserinfo = $base->iuserinfo;
  7733. $target->ihost = $base->ihost;
  7734. $target->port = $base->port;
  7735. if ($relative->ipath !== '')
  7736. {
  7737. if ($relative->ipath[0] === '/')
  7738. {
  7739. $target->ipath = $relative->ipath;
  7740. }
  7741. elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '')
  7742. {
  7743. $target->ipath = '/' . $relative->ipath;
  7744. }
  7745. elseif (($last_segment = strrpos($base->ipath, '/')) !== false)
  7746. {
  7747. $target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
  7748. }
  7749. else
  7750. {
  7751. $target->ipath = $relative->ipath;
  7752. }
  7753. $target->ipath = $target->remove_dot_segments($target->ipath);
  7754. $target->iquery = $relative->iquery;
  7755. }
  7756. else
  7757. {
  7758. $target->ipath = $base->ipath;
  7759. if ($relative->iquery !== null)
  7760. {
  7761. $target->iquery = $relative->iquery;
  7762. }
  7763. elseif ($base->iquery !== null)
  7764. {
  7765. $target->iquery = $base->iquery;
  7766. }
  7767. }
  7768. $target->ifragment = $relative->ifragment;
  7769. }
  7770. }
  7771. else
  7772. {
  7773. $target = clone $base;
  7774. $target->ifragment = null;
  7775. }
  7776. $target->scheme_normalization();
  7777. return $target;
  7778. }
  7779. else
  7780. {
  7781. return false;
  7782. }
  7783. }
  7784. }
  7785. /**
  7786. * Parse an IRI into scheme/authority/path/query/fragment segments
  7787. *
  7788. * @param string $iri
  7789. * @return array
  7790. */
  7791. protected function parse_iri($iri)
  7792. {
  7793. $iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
  7794. if (preg_match('/^((?P<scheme>[^:\/?#]+):)?(\/\/(?P<authority>[^\/?#]*))?(?P<path>[^?#]*)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$/', $iri, $match))
  7795. {
  7796. if ($match[1] === '')
  7797. {
  7798. $match['scheme'] = null;
  7799. }
  7800. if (!isset($match[3]) || $match[3] === '')
  7801. {
  7802. $match['authority'] = null;
  7803. }
  7804. if (!isset($match[5]))
  7805. {
  7806. $match['path'] = '';
  7807. }
  7808. if (!isset($match[6]) || $match[6] === '')
  7809. {
  7810. $match['query'] = null;
  7811. }
  7812. if (!isset($match[8]) || $match[8] === '')
  7813. {
  7814. $match['fragment'] = null;
  7815. }
  7816. return $match;
  7817. }
  7818. else
  7819. {
  7820. // This can occur when a paragraph is accidentally parsed as a URI
  7821. return false;
  7822. }
  7823. }
  7824. /**
  7825. * Remove dot segments from a path
  7826. *
  7827. * @param string $input
  7828. * @return string
  7829. */
  7830. protected function remove_dot_segments($input)
  7831. {
  7832. $output = '';
  7833. while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
  7834. {
  7835. // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
  7836. if (strpos($input, '../') === 0)
  7837. {
  7838. $input = substr($input, 3);
  7839. }
  7840. elseif (strpos($input, './') === 0)
  7841. {
  7842. $input = substr($input, 2);
  7843. }
  7844. // 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,
  7845. elseif (strpos($input, '/./') === 0)
  7846. {
  7847. $input = substr($input, 2);
  7848. }
  7849. elseif ($input === '/.')
  7850. {
  7851. $input = '/';
  7852. }
  7853. // 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,
  7854. elseif (strpos($input, '/../') === 0)
  7855. {
  7856. $input = substr($input, 3);
  7857. $output = substr_replace($output, '', strrpos($output, '/'));
  7858. }
  7859. elseif ($input === '/..')
  7860. {
  7861. $input = '/';
  7862. $output = substr_replace($output, '', strrpos($output, '/'));
  7863. }
  7864. // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
  7865. elseif ($input === '.' || $input === '..')
  7866. {
  7867. $input = '';
  7868. }
  7869. // 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
  7870. elseif (($pos = strpos($input, '/', 1)) !== false)
  7871. {
  7872. $output .= substr($input, 0, $pos);
  7873. $input = substr_replace($input, '', 0, $pos);
  7874. }
  7875. else
  7876. {
  7877. $output .= $input;
  7878. $input = '';
  7879. }
  7880. }
  7881. return $output . $input;
  7882. }
  7883. /**
  7884. * Replace invalid character with percent encoding
  7885. *
  7886. * @param string $string Input string
  7887. * @param string $extra_chars Valid characters not in iunreserved or
  7888. * iprivate (this is ASCII-only)
  7889. * @param bool $iprivate Allow iprivate
  7890. * @return string
  7891. */
  7892. protected function replace_invalid_with_pct_encoding($string, $extra_chars, $iprivate = false)
  7893. {
  7894. // Normalize as many pct-encoded sections as possible
  7895. $string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', array($this, 'remove_iunreserved_percent_encoded'), $string);
  7896. // Replace invalid percent characters
  7897. $string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
  7898. // Add unreserved and % to $extra_chars (the latter is safe because all
  7899. // pct-encoded sections are now valid).
  7900. $extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
  7901. // Now replace any bytes that aren't allowed with their pct-encoded versions
  7902. $position = 0;
  7903. $strlen = strlen($string);
  7904. while (($position += strspn($string, $extra_chars, $position)) < $strlen)
  7905. {
  7906. $value = ord($string[$position]);
  7907. // Start position
  7908. $start = $position;
  7909. // By default we are valid
  7910. $valid = true;
  7911. // No one byte sequences are valid due to the while.
  7912. // Two byte sequence:
  7913. if (($value & 0xE0) === 0xC0)
  7914. {
  7915. $character = ($value & 0x1F) << 6;
  7916. $length = 2;
  7917. $remaining = 1;
  7918. }
  7919. // Three byte sequence:
  7920. elseif (($value & 0xF0) === 0xE0)
  7921. {
  7922. $character = ($value & 0x0F) << 12;
  7923. $length = 3;
  7924. $remaining = 2;
  7925. }
  7926. // Four byte sequence:
  7927. elseif (($value & 0xF8) === 0xF0)
  7928. {
  7929. $character = ($value & 0x07) << 18;
  7930. $length = 4;
  7931. $remaining = 3;
  7932. }
  7933. // Invalid byte:
  7934. else
  7935. {
  7936. $valid = false;
  7937. $length = 1;
  7938. $remaining = 0;
  7939. }
  7940. if ($remaining)
  7941. {
  7942. if ($position + $length <= $strlen)
  7943. {
  7944. for ($position++; $remaining; $position++)
  7945. {
  7946. $value = ord($string[$position]);
  7947. // Check that the byte is valid, then add it to the character:
  7948. if (($value & 0xC0) === 0x80)
  7949. {
  7950. $character |= ($value & 0x3F) << (--$remaining * 6);
  7951. }
  7952. // If it is invalid, count the sequence as invalid and reprocess the current byte:
  7953. else
  7954. {
  7955. $valid = false;
  7956. $position--;
  7957. break;
  7958. }
  7959. }
  7960. }
  7961. else
  7962. {
  7963. $position = $strlen - 1;
  7964. $valid = false;
  7965. }
  7966. }
  7967. // Percent encode anything invalid or not in ucschar
  7968. if (
  7969. // Invalid sequences
  7970. !$valid
  7971. // Non-shortest form sequences are invalid
  7972. || $length > 1 && $character <= 0x7F
  7973. || $length > 2 && $character <= 0x7FF
  7974. || $length > 3 && $character <= 0xFFFF
  7975. // Outside of range of ucschar codepoints
  7976. // Noncharacters
  7977. || ($character & 0xFFFE) === 0xFFFE
  7978. || $character >= 0xFDD0 && $character <= 0xFDEF
  7979. || (
  7980. // Everything else not in ucschar
  7981. $character > 0xD7FF && $character < 0xF900
  7982. || $character < 0xA0
  7983. || $character > 0xEFFFD
  7984. )
  7985. && (
  7986. // Everything not in iprivate, if it applies
  7987. !$iprivate
  7988. || $character < 0xE000
  7989. || $character > 0x10FFFD
  7990. )
  7991. )
  7992. {
  7993. // If we were a character, pretend we weren't, but rather an error.
  7994. if ($valid)
  7995. $position--;
  7996. for ($j = $start; $j <= $position; $j++)
  7997. {
  7998. $string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
  7999. $j += 2;
  8000. $position += 2;
  8001. $strlen += 2;
  8002. }
  8003. }
  8004. }
  8005. return $string;
  8006. }
  8007. /**
  8008. * Callback function for preg_replace_callback.
  8009. *
  8010. * Removes sequences of percent encoded bytes that represent UTF-8
  8011. * encoded characters in iunreserved
  8012. *
  8013. * @param array $match PCRE match
  8014. * @return string Replacement
  8015. */
  8016. protected function remove_iunreserved_percent_encoded($match)
  8017. {
  8018. // As we just have valid percent encoded sequences we can just explode
  8019. // and ignore the first member of the returned array (an empty string).
  8020. $bytes = explode('%', $match[0]);
  8021. // Initialize the new string (this is what will be returned) and that
  8022. // there are no bytes remaining in the current sequence (unsurprising
  8023. // at the first byte!).
  8024. $string = '';
  8025. $remaining = 0;
  8026. // Loop over each and every byte, and set $value to its value
  8027. for ($i = 1, $len = count($bytes); $i < $len; $i++)
  8028. {
  8029. $value = hexdec($bytes[$i]);
  8030. // If we're the first byte of sequence:
  8031. if (!$remaining)
  8032. {
  8033. // Start position
  8034. $start = $i;
  8035. // By default we are valid
  8036. $valid = true;
  8037. // One byte sequence:
  8038. if ($value <= 0x7F)
  8039. {
  8040. $character = $value;
  8041. $length = 1;
  8042. }
  8043. // Two byte sequence:
  8044. elseif (($value & 0xE0) === 0xC0)
  8045. {
  8046. $character = ($value & 0x1F) << 6;
  8047. $length = 2;
  8048. $remaining = 1;
  8049. }
  8050. // Three byte sequence:
  8051. elseif (($value & 0xF0) === 0xE0)
  8052. {
  8053. $character = ($value & 0x0F) << 12;
  8054. $length = 3;
  8055. $remaining = 2;
  8056. }
  8057. // Four byte sequence:
  8058. elseif (($value & 0xF8) === 0xF0)
  8059. {
  8060. $character = ($value & 0x07) << 18;
  8061. $length = 4;
  8062. $remaining = 3;
  8063. }
  8064. // Invalid byte:
  8065. else
  8066. {
  8067. $valid = false;
  8068. $remaining = 0;
  8069. }
  8070. }
  8071. // Continuation byte:
  8072. else
  8073. {
  8074. // Check that the byte is valid, then add it to the character:
  8075. if (($value & 0xC0) === 0x80)
  8076. {
  8077. $remaining--;
  8078. $character |= ($value & 0x3F) << ($remaining * 6);
  8079. }
  8080. // If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
  8081. else
  8082. {
  8083. $valid = false;
  8084. $remaining = 0;
  8085. $i--;
  8086. }
  8087. }
  8088. // If we've reached the end of the current byte sequence, append it to Unicode::$data
  8089. if (!$remaining)
  8090. {
  8091. // Percent encode anything invalid or not in iunreserved
  8092. if (
  8093. // Invalid sequences
  8094. !$valid
  8095. // Non-shortest form sequences are invalid
  8096. || $length > 1 && $character <= 0x7F
  8097. || $length > 2 && $character <= 0x7FF
  8098. || $length > 3 && $character <= 0xFFFF
  8099. // Outside of range of iunreserved codepoints
  8100. || $character < 0x2D
  8101. || $character > 0xEFFFD
  8102. // Noncharacters
  8103. || ($character & 0xFFFE) === 0xFFFE
  8104. || $character >= 0xFDD0 && $character <= 0xFDEF
  8105. // Everything else not in iunreserved (this is all BMP)
  8106. || $character === 0x2F
  8107. || $character > 0x39 && $character < 0x41
  8108. || $character > 0x5A && $character < 0x61
  8109. || $character > 0x7A && $character < 0x7E
  8110. || $character > 0x7E && $character < 0xA0
  8111. || $character > 0xD7FF && $character < 0xF900
  8112. )
  8113. {
  8114. for ($j = $start; $j <= $i; $j++)
  8115. {
  8116. $string .= '%' . strtoupper($bytes[$j]);
  8117. }
  8118. }
  8119. else
  8120. {
  8121. for ($j = $start; $j <= $i; $j++)
  8122. {
  8123. $string .= chr(hexdec($bytes[$j]));
  8124. }
  8125. }
  8126. }
  8127. }
  8128. // If we have any bytes left over they are invalid (i.e., we are
  8129. // mid-way through a multi-byte sequence)
  8130. if ($remaining)
  8131. {
  8132. for ($j = $start; $j < $len; $j++)
  8133. {
  8134. $string .= '%' . strtoupper($bytes[$j]);
  8135. }
  8136. }
  8137. return $string;
  8138. }
  8139. protected function scheme_normalization()
  8140. {
  8141. if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo'])
  8142. {
  8143. $this->iuserinfo = null;
  8144. }
  8145. if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost'])
  8146. {
  8147. $this->ihost = null;
  8148. }
  8149. if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port'])
  8150. {
  8151. $this->port = null;
  8152. }
  8153. if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath'])
  8154. {
  8155. $this->ipath = '';
  8156. }
  8157. if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery'])
  8158. {
  8159. $this->iquery = null;
  8160. }
  8161. if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment'])
  8162. {
  8163. $this->ifragment = null;
  8164. }
  8165. }
  8166. /**
  8167. * Check if the object represents a valid IRI. This needs to be done on each
  8168. * call as some things change depending on another part of the IRI.
  8169. *
  8170. * @return bool
  8171. */
  8172. public function is_valid()
  8173. {
  8174. $isauthority = $this->iuserinfo !== null || $this->ihost !== null || $this->port !== null;
  8175. if ($this->ipath !== '' &&
  8176. (
  8177. $isauthority && (
  8178. $this->ipath[0] !== '/' ||
  8179. substr($this->ipath, 0, 2) === '//'
  8180. ) ||
  8181. (
  8182. $this->scheme === null &&
  8183. !$isauthority &&
  8184. strpos($this->ipath, ':') !== false &&
  8185. (strpos($this->ipath, '/') === false ? true : strpos($this->ipath, ':') < strpos($this->ipath, '/'))
  8186. )
  8187. )
  8188. )
  8189. {
  8190. return false;
  8191. }
  8192. return true;
  8193. }
  8194. /**
  8195. * Set the entire IRI. Returns true on success, false on failure (if there
  8196. * are any invalid characters).
  8197. *
  8198. * @param string $iri
  8199. * @return bool
  8200. */
  8201. public function set_iri($iri)
  8202. {
  8203. static $cache;
  8204. if (!$cache)
  8205. {
  8206. $cache = array();
  8207. }
  8208. if ($iri === null)
  8209. {
  8210. return true;
  8211. }
  8212. elseif (isset($cache[$iri]))
  8213. {
  8214. list($this->scheme,
  8215. $this->iuserinfo,
  8216. $this->ihost,
  8217. $this->port,
  8218. $this->ipath,
  8219. $this->iquery,
  8220. $this->ifragment,
  8221. $return) = $cache[$iri];
  8222. return $return;
  8223. }
  8224. else
  8225. {
  8226. $parsed = $this->parse_iri((string) $iri);
  8227. if (!$parsed)
  8228. {
  8229. return false;
  8230. }
  8231. $return = $this->set_scheme($parsed['scheme'])
  8232. && $this->set_authority($parsed['authority'])
  8233. && $this->set_path($parsed['path'])
  8234. && $this->set_query($parsed['query'])
  8235. && $this->set_fragment($parsed['fragment']);
  8236. $cache[$iri] = array($this->scheme,
  8237. $this->iuserinfo,
  8238. $this->ihost,
  8239. $this->port,
  8240. $this->ipath,
  8241. $this->iquery,
  8242. $this->ifragment,
  8243. $return);
  8244. return $return;
  8245. }
  8246. }
  8247. /**
  8248. * Set the scheme. Returns true on success, false on failure (if there are
  8249. * any invalid characters).
  8250. *
  8251. * @param string $scheme
  8252. * @return bool
  8253. */
  8254. public function set_scheme($scheme)
  8255. {
  8256. if ($scheme === null)
  8257. {
  8258. $this->scheme = null;
  8259. }
  8260. elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme))
  8261. {
  8262. $this->scheme = null;
  8263. return false;
  8264. }
  8265. else
  8266. {
  8267. $this->scheme = strtolower($scheme);
  8268. }
  8269. return true;
  8270. }
  8271. /**
  8272. * Set the authority. Returns true on success, false on failure (if there are
  8273. * any invalid characters).
  8274. *
  8275. * @param string $authority
  8276. * @return bool
  8277. */
  8278. public function set_authority($authority)
  8279. {
  8280. static $cache;
  8281. if (!$cache)
  8282. $cache = array();
  8283. if ($authority === null)
  8284. {
  8285. $this->iuserinfo = null;
  8286. $this->ihost = null;
  8287. $this->port = null;
  8288. return true;
  8289. }
  8290. elseif (isset($cache[$authority]))
  8291. {
  8292. list($this->iuserinfo,
  8293. $this->ihost,
  8294. $this->port,
  8295. $return) = $cache[$authority];
  8296. return $return;
  8297. }
  8298. else
  8299. {
  8300. $remaining = $authority;
  8301. if (($iuserinfo_end = strrpos($remaining, '@')) !== false)
  8302. {
  8303. $iuserinfo = substr($remaining, 0, $iuserinfo_end);
  8304. $remaining = substr($remaining, $iuserinfo_end + 1);
  8305. }
  8306. else
  8307. {
  8308. $iuserinfo = null;
  8309. }
  8310. if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false)
  8311. {
  8312. if (($port = substr($remaining, $port_start + 1)) === false)
  8313. {
  8314. $port = null;
  8315. }
  8316. $remaining = substr($remaining, 0, $port_start);
  8317. }
  8318. else
  8319. {
  8320. $port = null;
  8321. }
  8322. $return = $this->set_userinfo($iuserinfo) &&
  8323. $this->set_host($remaining) &&
  8324. $this->set_port($port);
  8325. $cache[$authority] = array($this->iuserinfo,
  8326. $this->ihost,
  8327. $this->port,
  8328. $return);
  8329. return $return;
  8330. }
  8331. }
  8332. /**
  8333. * Set the iuserinfo.
  8334. *
  8335. * @param string $iuserinfo
  8336. * @return bool
  8337. */
  8338. public function set_userinfo($iuserinfo)
  8339. {
  8340. if ($iuserinfo === null)
  8341. {
  8342. $this->iuserinfo = null;
  8343. }
  8344. else
  8345. {
  8346. $this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
  8347. $this->scheme_normalization();
  8348. }
  8349. return true;
  8350. }
  8351. /**
  8352. * Set the ihost. Returns true on success, false on failure (if there are
  8353. * any invalid characters).
  8354. *
  8355. * @param string $ihost
  8356. * @return bool
  8357. */
  8358. public function set_host($ihost)
  8359. {
  8360. if ($ihost === null)
  8361. {
  8362. $this->ihost = null;
  8363. return true;
  8364. }
  8365. elseif (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']')
  8366. {
  8367. if (SimplePie_Net_IPv6::check_ipv6(substr($ihost, 1, -1)))
  8368. {
  8369. $this->ihost = '[' . SimplePie_Net_IPv6::compress(substr($ihost, 1, -1)) . ']';
  8370. }
  8371. else
  8372. {
  8373. $this->ihost = null;
  8374. return false;
  8375. }
  8376. }
  8377. else
  8378. {
  8379. $ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;=');
  8380. // Lowercase, but ignore pct-encoded sections (as they should
  8381. // remain uppercase). This must be done after the previous step
  8382. // as that can add unescaped characters.
  8383. $position = 0;
  8384. $strlen = strlen($ihost);
  8385. while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen)
  8386. {
  8387. if ($ihost[$position] === '%')
  8388. {
  8389. $position += 3;
  8390. }
  8391. else
  8392. {
  8393. $ihost[$position] = strtolower($ihost[$position]);
  8394. $position++;
  8395. }
  8396. }
  8397. $this->ihost = $ihost;
  8398. }
  8399. $this->scheme_normalization();
  8400. return true;
  8401. }
  8402. /**
  8403. * Set the port. Returns true on success, false on failure (if there are
  8404. * any invalid characters).
  8405. *
  8406. * @param string $port
  8407. * @return bool
  8408. */
  8409. public function set_port($port)
  8410. {
  8411. if ($port === null)
  8412. {
  8413. $this->port = null;
  8414. return true;
  8415. }
  8416. elseif (strspn($port, '0123456789') === strlen($port))
  8417. {
  8418. $this->port = (int) $port;
  8419. $this->scheme_normalization();
  8420. return true;
  8421. }
  8422. else
  8423. {
  8424. $this->port = null;
  8425. return false;
  8426. }
  8427. }
  8428. /**
  8429. * Set the ipath.
  8430. *
  8431. * @param string $ipath
  8432. * @return bool
  8433. */
  8434. public function set_path($ipath)
  8435. {
  8436. static $cache;
  8437. if (!$cache)
  8438. {
  8439. $cache = array();
  8440. }
  8441. $ipath = (string) $ipath;
  8442. if (isset($cache[$ipath]))
  8443. {
  8444. $this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
  8445. }
  8446. else
  8447. {
  8448. $valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
  8449. $removed = $this->remove_dot_segments($valid);
  8450. $cache[$ipath] = array($valid, $removed);
  8451. $this->ipath = ($this->scheme !== null) ? $removed : $valid;
  8452. }
  8453. $this->scheme_normalization();
  8454. return true;
  8455. }
  8456. /**
  8457. * Set the iquery.
  8458. *
  8459. * @param string $iquery
  8460. * @return bool
  8461. */
  8462. public function set_query($iquery)
  8463. {
  8464. if ($iquery === null)
  8465. {
  8466. $this->iquery = null;
  8467. }
  8468. else
  8469. {
  8470. $this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
  8471. $this->scheme_normalization();
  8472. }
  8473. return true;
  8474. }
  8475. /**
  8476. * Set the ifragment.
  8477. *
  8478. * @param string $ifragment
  8479. * @return bool
  8480. */
  8481. public function set_fragment($ifragment)
  8482. {
  8483. if ($ifragment === null)
  8484. {
  8485. $this->ifragment = null;
  8486. }
  8487. else
  8488. {
  8489. $this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
  8490. $this->scheme_normalization();
  8491. }
  8492. return true;
  8493. }
  8494. /**
  8495. * Convert an IRI to a URI (or parts thereof)
  8496. *
  8497. * @return string
  8498. */
  8499. public function to_uri($string)
  8500. {
  8501. static $non_ascii;
  8502. if (!$non_ascii)
  8503. {
  8504. $non_ascii = implode('', range("\x80", "\xFF"));
  8505. }
  8506. $position = 0;
  8507. $strlen = strlen($string);
  8508. while (($position += strcspn($string, $non_ascii, $position)) < $strlen)
  8509. {
  8510. $string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
  8511. $position += 3;
  8512. $strlen += 2;
  8513. }
  8514. return $string;
  8515. }
  8516. /**
  8517. * Get the complete IRI
  8518. *
  8519. * @return string
  8520. */
  8521. public function get_iri()
  8522. {
  8523. if (!$this->is_valid())
  8524. {
  8525. return false;
  8526. }
  8527. $iri = '';
  8528. if ($this->scheme !== null)
  8529. {
  8530. $iri .= $this->scheme . ':';
  8531. }
  8532. if (($iauthority = $this->get_iauthority()) !== null)
  8533. {
  8534. $iri .= '//' . $iauthority;
  8535. }
  8536. if ($this->ipath !== '')
  8537. {
  8538. $iri .= $this->ipath;
  8539. }
  8540. elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '')
  8541. {
  8542. $iri .= $this->normalization[$this->scheme]['ipath'];
  8543. }
  8544. if ($this->iquery !== null)
  8545. {
  8546. $iri .= '?' . $this->iquery;
  8547. }
  8548. if ($this->ifragment !== null)
  8549. {
  8550. $iri .= '#' . $this->ifragment;
  8551. }
  8552. return $iri;
  8553. }
  8554. /**
  8555. * Get the complete URI
  8556. *
  8557. * @return string
  8558. */
  8559. public function get_uri()
  8560. {
  8561. return $this->to_uri($this->get_iri());
  8562. }
  8563. /**
  8564. * Get the complete iauthority
  8565. *
  8566. * @return string
  8567. */
  8568. protected function get_iauthority()
  8569. {
  8570. if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null)
  8571. {
  8572. $iauthority = '';
  8573. if ($this->iuserinfo !== null)
  8574. {
  8575. $iauthority .= $this->iuserinfo . '@';
  8576. }
  8577. if ($this->ihost !== null)
  8578. {
  8579. $iauthority .= $this->ihost;
  8580. }
  8581. if ($this->port !== null)
  8582. {
  8583. $iauthority .= ':' . $this->port;
  8584. }
  8585. return $iauthority;
  8586. }
  8587. else
  8588. {
  8589. return null;
  8590. }
  8591. }
  8592. /**
  8593. * Get the complete authority
  8594. *
  8595. * @return string
  8596. */
  8597. protected function get_authority()
  8598. {
  8599. $iauthority = $this->get_iauthority();
  8600. if (is_string($iauthority))
  8601. return $this->to_uri($iauthority);
  8602. else
  8603. return $iauthority;
  8604. }
  8605. }
  8606. /**
  8607. * Handles `<media:rating>` or `<itunes:explicit>` tags as defined in Media RSS and iTunes RSS respectively
  8608. *
  8609. * Used by {@see SimplePie_Enclosure::get_rating()} and {@see SimplePie_Enclosure::get_ratings()}
  8610. *
  8611. * This class can be overloaded with {@see SimplePie::set_rating_class()}
  8612. *
  8613. * @package SimplePie
  8614. * @subpackage API
  8615. */
  8616. class SimplePie_Rating
  8617. {
  8618. /**
  8619. * Rating scheme
  8620. *
  8621. * @var string
  8622. * @see get_scheme()
  8623. */
  8624. var $scheme;
  8625. /**
  8626. * Rating value
  8627. *
  8628. * @var string
  8629. * @see get_value()
  8630. */
  8631. var $value;
  8632. /**
  8633. * Constructor, used to input the data
  8634. *
  8635. * For documentation on all the parameters, see the corresponding
  8636. * properties and their accessors
  8637. */
  8638. public function __construct($scheme = null, $value = null)
  8639. {
  8640. $this->scheme = $scheme;
  8641. $this->value = $value;
  8642. }
  8643. /**
  8644. * String-ified version
  8645. *
  8646. * @return string
  8647. */
  8648. public function __toString()
  8649. {
  8650. // There is no $this->data here
  8651. return md5(serialize($this));
  8652. }
  8653. /**
  8654. * Get the organizational scheme for the rating
  8655. *
  8656. * @return string|null
  8657. */
  8658. public function get_scheme()
  8659. {
  8660. if ($this->scheme !== null)
  8661. {
  8662. return $this->scheme;
  8663. }
  8664. else
  8665. {
  8666. return null;
  8667. }
  8668. }
  8669. /**
  8670. * Get the value of the rating
  8671. *
  8672. * @return string|null
  8673. */
  8674. public function get_value()
  8675. {
  8676. if ($this->value !== null)
  8677. {
  8678. return $this->value;
  8679. }
  8680. else
  8681. {
  8682. return null;
  8683. }
  8684. }
  8685. }
  8686. /**
  8687. * Handles everything related to enclosures (including Media RSS and iTunes RSS)
  8688. *
  8689. * Used by {@see SimplePie_Item::get_enclosure()} and {@see SimplePie_Item::get_enclosures()}
  8690. *
  8691. * This class can be overloaded with {@see SimplePie::set_enclosure_class()}
  8692. *
  8693. * @package SimplePie
  8694. * @subpackage API
  8695. */
  8696. class SimplePie_Enclosure
  8697. {
  8698. /**
  8699. * @var string
  8700. * @see get_bitrate()
  8701. */
  8702. var $bitrate;
  8703. /**
  8704. * @var array
  8705. * @see get_captions()
  8706. */
  8707. var $captions;
  8708. /**
  8709. * @var array
  8710. * @see get_categories()
  8711. */
  8712. var $categories;
  8713. /**
  8714. * @var int
  8715. * @see get_channels()
  8716. */
  8717. var $channels;
  8718. /**
  8719. * @var SimplePie_Copyright
  8720. * @see get_copyright()
  8721. */
  8722. var $copyright;
  8723. /**
  8724. * @var array
  8725. * @see get_credits()
  8726. */
  8727. var $credits;
  8728. /**
  8729. * @var string
  8730. * @see get_description()
  8731. */
  8732. var $description;
  8733. /**
  8734. * @var int
  8735. * @see get_duration()
  8736. */
  8737. var $duration;
  8738. /**
  8739. * @var string
  8740. * @see get_expression()
  8741. */
  8742. var $expression;
  8743. /**
  8744. * @var string
  8745. * @see get_framerate()
  8746. */
  8747. var $framerate;
  8748. /**
  8749. * @var string
  8750. * @see get_handler()
  8751. */
  8752. var $handler;
  8753. /**
  8754. * @var array
  8755. * @see get_hashes()
  8756. */
  8757. var $hashes;
  8758. /**
  8759. * @var string
  8760. * @see get_height()
  8761. */
  8762. var $height;
  8763. /**
  8764. * @deprecated
  8765. * @var null
  8766. */
  8767. var $javascript;
  8768. /**
  8769. * @var array
  8770. * @see get_keywords()
  8771. */
  8772. var $keywords;
  8773. /**
  8774. * @var string
  8775. * @see get_language()
  8776. */
  8777. var $lang;
  8778. /**
  8779. * @var string
  8780. * @see get_length()
  8781. */
  8782. var $length;
  8783. /**
  8784. * @var string
  8785. * @see get_link()
  8786. */
  8787. var $link;
  8788. /**
  8789. * @var string
  8790. * @see get_medium()
  8791. */
  8792. var $medium;
  8793. /**
  8794. * @var string
  8795. * @see get_player()
  8796. */
  8797. var $player;
  8798. /**
  8799. * @var array
  8800. * @see get_ratings()
  8801. */
  8802. var $ratings;
  8803. /**
  8804. * @var array
  8805. * @see get_restrictions()
  8806. */
  8807. var $restrictions;
  8808. /**
  8809. * @var string
  8810. * @see get_sampling_rate()
  8811. */
  8812. var $samplingrate;
  8813. /**
  8814. * @var array
  8815. * @see get_thumbnails()
  8816. */
  8817. var $thumbnails;
  8818. /**
  8819. * @var string
  8820. * @see get_title()
  8821. */
  8822. var $title;
  8823. /**
  8824. * @var string
  8825. * @see get_type()
  8826. */
  8827. var $type;
  8828. /**
  8829. * @var string
  8830. * @see get_width()
  8831. */
  8832. var $width;
  8833. /**
  8834. * Constructor, used to input the data
  8835. *
  8836. * For documentation on all the parameters, see the corresponding
  8837. * properties and their accessors
  8838. *
  8839. * @uses idna_convert If available, this will convert an IDN
  8840. */
  8841. public function __construct($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)
  8842. {
  8843. $this->bitrate = $bitrate;
  8844. $this->captions = $captions;
  8845. $this->categories = $categories;
  8846. $this->channels = $channels;
  8847. $this->copyright = $copyright;
  8848. $this->credits = $credits;
  8849. $this->description = $description;
  8850. $this->duration = $duration;
  8851. $this->expression = $expression;
  8852. $this->framerate = $framerate;
  8853. $this->hashes = $hashes;
  8854. $this->height = $height;
  8855. $this->keywords = $keywords;
  8856. $this->lang = $lang;
  8857. $this->length = $length;
  8858. $this->link = $link;
  8859. $this->medium = $medium;
  8860. $this->player = $player;
  8861. $this->ratings = $ratings;
  8862. $this->restrictions = $restrictions;
  8863. $this->samplingrate = $samplingrate;
  8864. $this->thumbnails = $thumbnails;
  8865. $this->title = $title;
  8866. $this->type = $type;
  8867. $this->width = $width;
  8868. if (class_exists('idna_convert'))
  8869. {
  8870. $idn = new idna_convert();
  8871. $parsed = SimplePie_Misc::parse_url($link);
  8872. $this->link = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']);
  8873. }
  8874. $this->handler = $this->get_handler(); // Needs to load last
  8875. }
  8876. /**
  8877. * String-ified version
  8878. *
  8879. * @return string
  8880. */
  8881. public function __toString()
  8882. {
  8883. // There is no $this->data here
  8884. return md5(serialize($this));
  8885. }
  8886. /**
  8887. * Get the bitrate
  8888. *
  8889. * @return string|null
  8890. */
  8891. public function get_bitrate()
  8892. {
  8893. if ($this->bitrate !== null)
  8894. {
  8895. return $this->bitrate;
  8896. }
  8897. else
  8898. {
  8899. return null;
  8900. }
  8901. }
  8902. /**
  8903. * Get a single caption
  8904. *
  8905. * @param int $key
  8906. * @return SimplePie_Caption|null
  8907. */
  8908. public function get_caption($key = 0)
  8909. {
  8910. $captions = $this->get_captions();
  8911. if (isset($captions[$key]))
  8912. {
  8913. return $captions[$key];
  8914. }
  8915. else
  8916. {
  8917. return null;
  8918. }
  8919. }
  8920. /**
  8921. * Get all captions
  8922. *
  8923. * @return array|null Array of {@see SimplePie_Caption} objects
  8924. */
  8925. public function get_captions()
  8926. {
  8927. if ($this->captions !== null)
  8928. {
  8929. return $this->captions;
  8930. }
  8931. else
  8932. {
  8933. return null;
  8934. }
  8935. }
  8936. /**
  8937. * Get a single category
  8938. *
  8939. * @param int $key
  8940. * @return SimplePie_Category|null
  8941. */
  8942. public function get_category($key = 0)
  8943. {
  8944. $categories = $this->get_categories();
  8945. if (isset($categories[$key]))
  8946. {
  8947. return $categories[$key];
  8948. }
  8949. else
  8950. {
  8951. return null;
  8952. }
  8953. }
  8954. /**
  8955. * Get all categories
  8956. *
  8957. * @return array|null Array of {@see SimplePie_Category} objects
  8958. */
  8959. public function get_categories()
  8960. {
  8961. if ($this->categories !== null)
  8962. {
  8963. return $this->categories;
  8964. }
  8965. else
  8966. {
  8967. return null;
  8968. }
  8969. }
  8970. /**
  8971. * Get the number of audio channels
  8972. *
  8973. * @return int|null
  8974. */
  8975. public function get_channels()
  8976. {
  8977. if ($this->channels !== null)
  8978. {
  8979. return $this->channels;
  8980. }
  8981. else
  8982. {
  8983. return null;
  8984. }
  8985. }
  8986. /**
  8987. * Get the copyright information
  8988. *
  8989. * @return SimplePie_Copyright|null
  8990. */
  8991. public function get_copyright()
  8992. {
  8993. if ($this->copyright !== null)
  8994. {
  8995. return $this->copyright;
  8996. }
  8997. else
  8998. {
  8999. return null;
  9000. }
  9001. }
  9002. /**
  9003. * Get a single credit
  9004. *
  9005. * @param int $key
  9006. * @return SimplePie_Credit|null
  9007. */
  9008. public function get_credit($key = 0)
  9009. {
  9010. $credits = $this->get_credits();
  9011. if (isset($credits[$key]))
  9012. {
  9013. return $credits[$key];
  9014. }
  9015. else
  9016. {
  9017. return null;
  9018. }
  9019. }
  9020. /**
  9021. * Get all credits
  9022. *
  9023. * @return array|null Array of {@see SimplePie_Credit} objects
  9024. */
  9025. public function get_credits()
  9026. {
  9027. if ($this->credits !== null)
  9028. {
  9029. return $this->credits;
  9030. }
  9031. else
  9032. {
  9033. return null;
  9034. }
  9035. }
  9036. /**
  9037. * Get the description of the enclosure
  9038. *
  9039. * @return string|null
  9040. */
  9041. public function get_description()
  9042. {
  9043. if ($this->description !== null)
  9044. {
  9045. return $this->description;
  9046. }
  9047. else
  9048. {
  9049. return null;
  9050. }
  9051. }
  9052. /**
  9053. * Get the duration of the enclosure
  9054. *
  9055. * @param string $convert Convert seconds into hh:mm:ss
  9056. * @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
  9057. */
  9058. public function get_duration($convert = false)
  9059. {
  9060. if ($this->duration !== null)
  9061. {
  9062. if ($convert)
  9063. {
  9064. $time = SimplePie_Misc::time_hms($this->duration);
  9065. return $time;
  9066. }
  9067. else
  9068. {
  9069. return $this->duration;
  9070. }
  9071. }
  9072. else
  9073. {
  9074. return null;
  9075. }
  9076. }
  9077. /**
  9078. * Get the expression
  9079. *
  9080. * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
  9081. */
  9082. public function get_expression()
  9083. {
  9084. if ($this->expression !== null)
  9085. {
  9086. return $this->expression;
  9087. }
  9088. else
  9089. {
  9090. return 'full';
  9091. }
  9092. }
  9093. /**
  9094. * Get the file extension
  9095. *
  9096. * @return string|null
  9097. */
  9098. public function get_extension()
  9099. {
  9100. if ($this->link !== null)
  9101. {
  9102. $url = SimplePie_Misc::parse_url($this->link);
  9103. if ($url['path'] !== '')
  9104. {
  9105. return pathinfo($url['path'], PATHINFO_EXTENSION);
  9106. }
  9107. }
  9108. return null;
  9109. }
  9110. /**
  9111. * Get the framerate (in frames-per-second)
  9112. *
  9113. * @return string|null
  9114. */
  9115. public function get_framerate()
  9116. {
  9117. if ($this->framerate !== null)
  9118. {
  9119. return $this->framerate;
  9120. }
  9121. else
  9122. {
  9123. return null;
  9124. }
  9125. }
  9126. /**
  9127. * Get the preferred handler
  9128. *
  9129. * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
  9130. */
  9131. public function get_handler()
  9132. {
  9133. return $this->get_real_type(true);
  9134. }
  9135. /**
  9136. * Get a single hash
  9137. *
  9138. * @link http://www.rssboard.org/media-rss#media-hash
  9139. * @param int $key
  9140. * @return string|null Hash as per `media:hash`, prefixed with "$algo:"
  9141. */
  9142. public function get_hash($key = 0)
  9143. {
  9144. $hashes = $this->get_hashes();
  9145. if (isset($hashes[$key]))
  9146. {
  9147. return $hashes[$key];
  9148. }
  9149. else
  9150. {
  9151. return null;
  9152. }
  9153. }
  9154. /**
  9155. * Get all credits
  9156. *
  9157. * @return array|null Array of strings, see {@see get_hash()}
  9158. */
  9159. public function get_hashes()
  9160. {
  9161. if ($this->hashes !== null)
  9162. {
  9163. return $this->hashes;
  9164. }
  9165. else
  9166. {
  9167. return null;
  9168. }
  9169. }
  9170. /**
  9171. * Get the height
  9172. *
  9173. * @return string|null
  9174. */
  9175. public function get_height()
  9176. {
  9177. if ($this->height !== null)
  9178. {
  9179. return $this->height;
  9180. }
  9181. else
  9182. {
  9183. return null;
  9184. }
  9185. }
  9186. /**
  9187. * Get the language
  9188. *
  9189. * @link http://tools.ietf.org/html/rfc3066
  9190. * @return string|null Language code as per RFC 3066
  9191. */
  9192. public function get_language()
  9193. {
  9194. if ($this->lang !== null)
  9195. {
  9196. return $this->lang;
  9197. }
  9198. else
  9199. {
  9200. return null;
  9201. }
  9202. }
  9203. /**
  9204. * Get a single keyword
  9205. *
  9206. * @param int $key
  9207. * @return string|null
  9208. */
  9209. public function get_keyword($key = 0)
  9210. {
  9211. $keywords = $this->get_keywords();
  9212. if (isset($keywords[$key]))
  9213. {
  9214. return $keywords[$key];
  9215. }
  9216. else
  9217. {
  9218. return null;
  9219. }
  9220. }
  9221. /**
  9222. * Get all keywords
  9223. *
  9224. * @return array|null Array of strings
  9225. */
  9226. public function get_keywords()
  9227. {
  9228. if ($this->keywords !== null)
  9229. {
  9230. return $this->keywords;
  9231. }
  9232. else
  9233. {
  9234. return null;
  9235. }
  9236. }
  9237. /**
  9238. * Get length
  9239. *
  9240. * @return float Length in bytes
  9241. */
  9242. public function get_length()
  9243. {
  9244. if ($this->length !== null)
  9245. {
  9246. return $this->length;
  9247. }
  9248. else
  9249. {
  9250. return null;
  9251. }
  9252. }
  9253. /**
  9254. * Get the URL
  9255. *
  9256. * @return string|null
  9257. */
  9258. public function get_link()
  9259. {
  9260. if ($this->link !== null)
  9261. {
  9262. return urldecode($this->link);
  9263. }
  9264. else
  9265. {
  9266. return null;
  9267. }
  9268. }
  9269. /**
  9270. * Get the medium
  9271. *
  9272. * @link http://www.rssboard.org/media-rss#media-content
  9273. * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable'
  9274. */
  9275. public function get_medium()
  9276. {
  9277. if ($this->medium !== null)
  9278. {
  9279. return $this->medium;
  9280. }
  9281. else
  9282. {
  9283. return null;
  9284. }
  9285. }
  9286. /**
  9287. * Get the player URL
  9288. *
  9289. * Typically the same as {@see get_permalink()}
  9290. * @return string|null Player URL
  9291. */
  9292. public function get_player()
  9293. {
  9294. if ($this->player !== null)
  9295. {
  9296. return $this->player;
  9297. }
  9298. else
  9299. {
  9300. return null;
  9301. }
  9302. }
  9303. /**
  9304. * Get a single rating
  9305. *
  9306. * @param int $key
  9307. * @return SimplePie_Rating|null
  9308. */
  9309. public function get_rating($key = 0)
  9310. {
  9311. $ratings = $this->get_ratings();
  9312. if (isset($ratings[$key]))
  9313. {
  9314. return $ratings[$key];
  9315. }
  9316. else
  9317. {
  9318. return null;
  9319. }
  9320. }
  9321. /**
  9322. * Get all ratings
  9323. *
  9324. * @return array|null Array of {@see SimplePie_Rating} objects
  9325. */
  9326. public function get_ratings()
  9327. {
  9328. if ($this->ratings !== null)
  9329. {
  9330. return $this->ratings;
  9331. }
  9332. else
  9333. {
  9334. return null;
  9335. }
  9336. }
  9337. /**
  9338. * Get a single restriction
  9339. *
  9340. * @param int $key
  9341. * @return SimplePie_Restriction|null
  9342. */
  9343. public function get_restriction($key = 0)
  9344. {
  9345. $restrictions = $this->get_restrictions();
  9346. if (isset($restrictions[$key]))
  9347. {
  9348. return $restrictions[$key];
  9349. }
  9350. else
  9351. {
  9352. return null;
  9353. }
  9354. }
  9355. /**
  9356. * Get all restrictions
  9357. *
  9358. * @return array|null Array of {@see SimplePie_Restriction} objects
  9359. */
  9360. public function get_restrictions()
  9361. {
  9362. if ($this->restrictions !== null)
  9363. {
  9364. return $this->restrictions;
  9365. }
  9366. else
  9367. {
  9368. return null;
  9369. }
  9370. }
  9371. /**
  9372. * Get the sampling rate (in kHz)
  9373. *
  9374. * @return string|null
  9375. */
  9376. public function get_sampling_rate()
  9377. {
  9378. if ($this->samplingrate !== null)
  9379. {
  9380. return $this->samplingrate;
  9381. }
  9382. else
  9383. {
  9384. return null;
  9385. }
  9386. }
  9387. /**
  9388. * Get the file size (in MiB)
  9389. *
  9390. * @return float|null File size in mebibytes (1048 bytes)
  9391. */
  9392. public function get_size()
  9393. {
  9394. $length = $this->get_length();
  9395. if ($length !== null)
  9396. {
  9397. return round($length/1048576, 2);
  9398. }
  9399. else
  9400. {
  9401. return null;
  9402. }
  9403. }
  9404. /**
  9405. * Get a single thumbnail
  9406. *
  9407. * @param int $key
  9408. * @return string|null Thumbnail URL
  9409. */
  9410. public function get_thumbnail($key = 0)
  9411. {
  9412. $thumbnails = $this->get_thumbnails();
  9413. if (isset($thumbnails[$key]))
  9414. {
  9415. return $thumbnails[$key];
  9416. }
  9417. else
  9418. {
  9419. return null;
  9420. }
  9421. }
  9422. /**
  9423. * Get all thumbnails
  9424. *
  9425. * @return array|null Array of thumbnail URLs
  9426. */
  9427. public function get_thumbnails()
  9428. {
  9429. if ($this->thumbnails !== null)
  9430. {
  9431. return $this->thumbnails;
  9432. }
  9433. else
  9434. {
  9435. return null;
  9436. }
  9437. }
  9438. /**
  9439. * Get the title
  9440. *
  9441. * @return string|null
  9442. */
  9443. public function get_title()
  9444. {
  9445. if ($this->title !== null)
  9446. {
  9447. return $this->title;
  9448. }
  9449. else
  9450. {
  9451. return null;
  9452. }
  9453. }
  9454. /**
  9455. * Get mimetype of the enclosure
  9456. *
  9457. * @see get_real_type()
  9458. * @return string|null MIME type
  9459. */
  9460. public function get_type()
  9461. {
  9462. if ($this->type !== null)
  9463. {
  9464. return $this->type;
  9465. }
  9466. else
  9467. {
  9468. return null;
  9469. }
  9470. }
  9471. /**
  9472. * Get the width
  9473. *
  9474. * @return string|null
  9475. */
  9476. public function get_width()
  9477. {
  9478. if ($this->width !== null)
  9479. {
  9480. return $this->width;
  9481. }
  9482. else
  9483. {
  9484. return null;
  9485. }
  9486. }
  9487. /**
  9488. * Embed the enclosure using `<embed>`
  9489. *
  9490. * @deprecated Use the second parameter to {@see embed} instead
  9491. *
  9492. * @param array|string $options See first paramter to {@see embed}
  9493. * @return string HTML string to output
  9494. */
  9495. public function native_embed($options='')
  9496. {
  9497. return $this->embed($options, true);
  9498. }
  9499. /**
  9500. * Embed the enclosure using Javascript
  9501. *
  9502. * `$options` is an array or comma-separated key:value string, with the
  9503. * following properties:
  9504. *
  9505. * - `alt` (string): Alternate content for when an end-user does not have
  9506. * the appropriate handler installed or when a file type is
  9507. * unsupported. Can be any text or HTML. Defaults to blank.
  9508. * - `altclass` (string): If a file type is unsupported, the end-user will
  9509. * see the alt text (above) linked directly to the content. That link
  9510. * will have this value as its class name. Defaults to blank.
  9511. * - `audio` (string): This is an image that should be used as a
  9512. * placeholder for audio files before they're loaded (QuickTime-only).
  9513. * Can be any relative or absolute URL. Defaults to blank.
  9514. * - `bgcolor` (string): The background color for the media, if not
  9515. * already transparent. Defaults to `#ffffff`.
  9516. * - `height` (integer): The height of the embedded media. Accepts any
  9517. * numeric pixel value (such as `360`) or `auto`. Defaults to `auto`,
  9518. * and it is recommended that you use this default.
  9519. * - `loop` (boolean): Do you want the media to loop when its done?
  9520. * Defaults to `false`.
  9521. * - `mediaplayer` (string): The location of the included
  9522. * `mediaplayer.swf` file. This allows for the playback of Flash Video
  9523. * (`.flv`) files, and is the default handler for non-Odeo MP3's.
  9524. * Defaults to blank.
  9525. * - `video` (string): This is an image that should be used as a
  9526. * placeholder for video files before they're loaded (QuickTime-only).
  9527. * Can be any relative or absolute URL. Defaults to blank.
  9528. * - `width` (integer): The width of the embedded media. Accepts any
  9529. * numeric pixel value (such as `480`) or `auto`. Defaults to `auto`,
  9530. * and it is recommended that you use this default.
  9531. * - `widescreen` (boolean): Is the enclosure widescreen or standard?
  9532. * This applies only to video enclosures, and will automatically resize
  9533. * the content appropriately. Defaults to `false`, implying 4:3 mode.
  9534. *
  9535. * Note: Non-widescreen (4:3) mode with `width` and `height` set to `auto`
  9536. * will default to 480x360 video resolution. Widescreen (16:9) mode with
  9537. * `width` and `height` set to `auto` will default to 480x270 video resolution.
  9538. *
  9539. * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'.
  9540. * @param array|string $options Comma-separated key:value list, or array
  9541. * @param bool $native Use `<embed>`
  9542. * @return string HTML string to output
  9543. */
  9544. public function embed($options = '', $native = false)
  9545. {
  9546. // Set up defaults
  9547. $audio = '';
  9548. $video = '';
  9549. $alt = '';
  9550. $altclass = '';
  9551. $loop = 'false';
  9552. $width = 'auto';
  9553. $height = 'auto';
  9554. $bgcolor = '#ffffff';
  9555. $mediaplayer = '';
  9556. $widescreen = false;
  9557. $handler = $this->get_handler();
  9558. $type = $this->get_real_type();
  9559. // Process options and reassign values as necessary
  9560. if (is_array($options))
  9561. {
  9562. extract($options);
  9563. }
  9564. else
  9565. {
  9566. $options = explode(',', $options);
  9567. foreach($options as $option)
  9568. {
  9569. $opt = explode(':', $option, 2);
  9570. if (isset($opt[0], $opt[1]))
  9571. {
  9572. $opt[0] = trim($opt[0]);
  9573. $opt[1] = trim($opt[1]);
  9574. switch ($opt[0])
  9575. {
  9576. case 'audio':
  9577. $audio = $opt[1];
  9578. break;
  9579. case 'video':
  9580. $video = $opt[1];
  9581. break;
  9582. case 'alt':
  9583. $alt = $opt[1];
  9584. break;
  9585. case 'altclass':
  9586. $altclass = $opt[1];
  9587. break;
  9588. case 'loop':
  9589. $loop = $opt[1];
  9590. break;
  9591. case 'width':
  9592. $width = $opt[1];
  9593. break;
  9594. case 'height':
  9595. $height = $opt[1];
  9596. break;
  9597. case 'bgcolor':
  9598. $bgcolor = $opt[1];
  9599. break;
  9600. case 'mediaplayer':
  9601. $mediaplayer = $opt[1];
  9602. break;
  9603. case 'widescreen':
  9604. $widescreen = $opt[1];
  9605. break;
  9606. }
  9607. }
  9608. }
  9609. }
  9610. $mime = explode('/', $type, 2);
  9611. $mime = $mime[0];
  9612. // Process values for 'auto'
  9613. if ($width === 'auto')
  9614. {
  9615. if ($mime === 'video')
  9616. {
  9617. if ($height === 'auto')
  9618. {
  9619. $width = 480;
  9620. }
  9621. elseif ($widescreen)
  9622. {
  9623. $width = round((intval($height)/9)*16);
  9624. }
  9625. else
  9626. {
  9627. $width = round((intval($height)/3)*4);
  9628. }
  9629. }
  9630. else
  9631. {
  9632. $width = '100%';
  9633. }
  9634. }
  9635. if ($height === 'auto')
  9636. {
  9637. if ($mime === 'audio')
  9638. {
  9639. $height = 0;
  9640. }
  9641. elseif ($mime === 'video')
  9642. {
  9643. if ($width === 'auto')
  9644. {
  9645. if ($widescreen)
  9646. {
  9647. $height = 270;
  9648. }
  9649. else
  9650. {
  9651. $height = 360;
  9652. }
  9653. }
  9654. elseif ($widescreen)
  9655. {
  9656. $height = round((intval($width)/16)*9);
  9657. }
  9658. else
  9659. {
  9660. $height = round((intval($width)/4)*3);
  9661. }
  9662. }
  9663. else
  9664. {
  9665. $height = 376;
  9666. }
  9667. }
  9668. elseif ($mime === 'audio')
  9669. {
  9670. $height = 0;
  9671. }
  9672. // Set proper placeholder value
  9673. if ($mime === 'audio')
  9674. {
  9675. $placeholder = $audio;
  9676. }
  9677. elseif ($mime === 'video')
  9678. {
  9679. $placeholder = $video;
  9680. }
  9681. $embed = '';
  9682. // Flash
  9683. if ($handler === 'flash')
  9684. {
  9685. if ($native)
  9686. {
  9687. $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>";
  9688. }
  9689. else
  9690. {
  9691. $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>";
  9692. }
  9693. }
  9694. // Flash Media Player file types.
  9695. // Preferred handler for MP3 file types.
  9696. elseif ($handler === 'fmedia' || ($handler === 'mp3' && $mediaplayer !== ''))
  9697. {
  9698. $height += 20;
  9699. if ($native)
  9700. {
  9701. $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>";
  9702. }
  9703. else
  9704. {
  9705. $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>";
  9706. }
  9707. }
  9708. // QuickTime 7 file types. Need to test with QuickTime 6.
  9709. // Only handle MP3's if the Flash Media Player is not present.
  9710. elseif ($handler === 'quicktime' || ($handler === 'mp3' && $mediaplayer === ''))
  9711. {
  9712. $height += 16;
  9713. if ($native)
  9714. {
  9715. if ($placeholder !== '')
  9716. {
  9717. $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>";
  9718. }
  9719. else
  9720. {
  9721. $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>";
  9722. }
  9723. }
  9724. else
  9725. {
  9726. $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>";
  9727. }
  9728. }
  9729. // Windows Media
  9730. elseif ($handler === 'wmedia')
  9731. {
  9732. $height += 45;
  9733. if ($native)
  9734. {
  9735. $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>";
  9736. }
  9737. else
  9738. {
  9739. $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>";
  9740. }
  9741. }
  9742. // Everything else
  9743. else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>';
  9744. return $embed;
  9745. }
  9746. /**
  9747. * Get the real media type
  9748. *
  9749. * Often, feeds lie to us, necessitating a bit of deeper inspection. This
  9750. * converts types to their canonical representations based on the file
  9751. * extension
  9752. *
  9753. * @see get_type()
  9754. * @param bool $find_handler Internal use only, use {@see get_handler()} instead
  9755. * @return string MIME type
  9756. */
  9757. public function get_real_type($find_handler = false)
  9758. {
  9759. // Mime-types by handler.
  9760. $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash
  9761. $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player
  9762. $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
  9763. $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
  9764. $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3
  9765. if ($this->get_type() !== null)
  9766. {
  9767. $type = strtolower($this->type);
  9768. }
  9769. else
  9770. {
  9771. $type = null;
  9772. }
  9773. // If we encounter an unsupported mime-type, check the file extension and guess intelligently.
  9774. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3)))
  9775. {
  9776. switch (strtolower($this->get_extension()))
  9777. {
  9778. // Audio mime-types
  9779. case 'aac':
  9780. case 'adts':
  9781. $type = 'audio/acc';
  9782. break;
  9783. case 'aif':
  9784. case 'aifc':
  9785. case 'aiff':
  9786. case 'cdda':
  9787. $type = 'audio/aiff';
  9788. break;
  9789. case 'bwf':
  9790. $type = 'audio/wav';
  9791. break;
  9792. case 'kar':
  9793. case 'mid':
  9794. case 'midi':
  9795. case 'smf':
  9796. $type = 'audio/midi';
  9797. break;
  9798. case 'm4a':
  9799. $type = 'audio/x-m4a';
  9800. break;
  9801. case 'mp3':
  9802. case 'swa':
  9803. $type = 'audio/mp3';
  9804. break;
  9805. case 'wav':
  9806. $type = 'audio/wav';
  9807. break;
  9808. case 'wax':
  9809. $type = 'audio/x-ms-wax';
  9810. break;
  9811. case 'wma':
  9812. $type = 'audio/x-ms-wma';
  9813. break;
  9814. // Video mime-types
  9815. case '3gp':
  9816. case '3gpp':
  9817. $type = 'video/3gpp';
  9818. break;
  9819. case '3g2':
  9820. case '3gp2':
  9821. $type = 'video/3gpp2';
  9822. break;
  9823. case 'asf':
  9824. $type = 'video/x-ms-asf';
  9825. break;
  9826. case 'flv':
  9827. $type = 'video/x-flv';
  9828. break;
  9829. case 'm1a':
  9830. case 'm1s':
  9831. case 'm1v':
  9832. case 'm15':
  9833. case 'm75':
  9834. case 'mp2':
  9835. case 'mpa':
  9836. case 'mpeg':
  9837. case 'mpg':
  9838. case 'mpm':
  9839. case 'mpv':
  9840. $type = 'video/mpeg';
  9841. break;
  9842. case 'm4v':
  9843. $type = 'video/x-m4v';
  9844. break;
  9845. case 'mov':
  9846. case 'qt':
  9847. $type = 'video/quicktime';
  9848. break;
  9849. case 'mp4':
  9850. case 'mpg4':
  9851. $type = 'video/mp4';
  9852. break;
  9853. case 'sdv':
  9854. $type = 'video/sd-video';
  9855. break;
  9856. case 'wm':
  9857. $type = 'video/x-ms-wm';
  9858. break;
  9859. case 'wmv':
  9860. $type = 'video/x-ms-wmv';
  9861. break;
  9862. case 'wvx':
  9863. $type = 'video/x-ms-wvx';
  9864. break;
  9865. // Flash mime-types
  9866. case 'spl':
  9867. $type = 'application/futuresplash';
  9868. break;
  9869. case 'swf':
  9870. $type = 'application/x-shockwave-flash';
  9871. break;
  9872. }
  9873. }
  9874. if ($find_handler)
  9875. {
  9876. if (in_array($type, $types_flash))
  9877. {
  9878. return 'flash';
  9879. }
  9880. elseif (in_array($type, $types_fmedia))
  9881. {
  9882. return 'fmedia';
  9883. }
  9884. elseif (in_array($type, $types_quicktime))
  9885. {
  9886. return 'quicktime';
  9887. }
  9888. elseif (in_array($type, $types_wmedia))
  9889. {
  9890. return 'wmedia';
  9891. }
  9892. elseif (in_array($type, $types_mp3))
  9893. {
  9894. return 'mp3';
  9895. }
  9896. else
  9897. {
  9898. return null;
  9899. }
  9900. }
  9901. else
  9902. {
  9903. return $type;
  9904. }
  9905. }
  9906. }
  9907. /**
  9908. * Class to validate and to work with IPv6 addresses.
  9909. *
  9910. * @package SimplePie
  9911. * @subpackage HTTP
  9912. * @copyright 2003-2005 The PHP Group
  9913. * @license http://www.opensource.org/licenses/bsd-license.php
  9914. * @link http://pear.php.net/package/Net_IPv6
  9915. * @author Alexander Merz <alexander.merz@web.de>
  9916. * @author elfrink at introweb dot nl
  9917. * @author Josh Peck <jmp at joshpeck dot org>
  9918. * @author Geoffrey Sneddon <geoffers@gmail.com>
  9919. */
  9920. class SimplePie_Net_IPv6
  9921. {
  9922. /**
  9923. * Uncompresses an IPv6 address
  9924. *
  9925. * RFC 4291 allows you to compress concecutive zero pieces in an address to
  9926. * '::'. This method expects a valid IPv6 address and expands the '::' to
  9927. * the required number of zero pieces.
  9928. *
  9929. * Example: FF01::101 -> FF01:0:0:0:0:0:0:101
  9930. * ::1 -> 0:0:0:0:0:0:0:1
  9931. *
  9932. * @author Alexander Merz <alexander.merz@web.de>
  9933. * @author elfrink at introweb dot nl
  9934. * @author Josh Peck <jmp at joshpeck dot org>
  9935. * @copyright 2003-2005 The PHP Group
  9936. * @license http://www.opensource.org/licenses/bsd-license.php
  9937. * @param string $ip An IPv6 address
  9938. * @return string The uncompressed IPv6 address
  9939. */
  9940. public static function uncompress($ip)
  9941. {
  9942. $c1 = -1;
  9943. $c2 = -1;
  9944. if (substr_count($ip, '::') === 1)
  9945. {
  9946. list($ip1, $ip2) = explode('::', $ip);
  9947. if ($ip1 === '')
  9948. {
  9949. $c1 = -1;
  9950. }
  9951. else
  9952. {
  9953. $c1 = substr_count($ip1, ':');
  9954. }
  9955. if ($ip2 === '')
  9956. {
  9957. $c2 = -1;
  9958. }
  9959. else
  9960. {
  9961. $c2 = substr_count($ip2, ':');
  9962. }
  9963. if (strpos($ip2, '.') !== false)
  9964. {
  9965. $c2++;
  9966. }
  9967. // ::
  9968. if ($c1 === -1 && $c2 === -1)
  9969. {
  9970. $ip = '0:0:0:0:0:0:0:0';
  9971. }
  9972. // ::xxx
  9973. else if ($c1 === -1)
  9974. {
  9975. $fill = str_repeat('0:', 7 - $c2);
  9976. $ip = str_replace('::', $fill, $ip);
  9977. }
  9978. // xxx::
  9979. else if ($c2 === -1)
  9980. {
  9981. $fill = str_repeat(':0', 7 - $c1);
  9982. $ip = str_replace('::', $fill, $ip);
  9983. }
  9984. // xxx::xxx
  9985. else
  9986. {
  9987. $fill = ':' . str_repeat('0:', 6 - $c2 - $c1);
  9988. $ip = str_replace('::', $fill, $ip);
  9989. }
  9990. }
  9991. return $ip;
  9992. }
  9993. /**
  9994. * Compresses an IPv6 address
  9995. *
  9996. * RFC 4291 allows you to compress concecutive zero pieces in an address to
  9997. * '::'. This method expects a valid IPv6 address and compresses consecutive
  9998. * zero pieces to '::'.
  9999. *
  10000. * Example: FF01:0:0:0:0:0:0:101 -> FF01::101
  10001. * 0:0:0:0:0:0:0:1 -> ::1
  10002. *
  10003. * @see uncompress()
  10004. * @param string $ip An IPv6 address
  10005. * @return string The compressed IPv6 address
  10006. */
  10007. public static function compress($ip)
  10008. {
  10009. // Prepare the IP to be compressed
  10010. $ip = self::uncompress($ip);
  10011. $ip_parts = self::split_v6_v4($ip);
  10012. // Replace all leading zeros
  10013. $ip_parts[0] = preg_replace('/(^|:)0+([0-9])/', '\1\2', $ip_parts[0]);
  10014. // Find bunches of zeros
  10015. if (preg_match_all('/(?:^|:)(?:0(?::|$))+/', $ip_parts[0], $matches, PREG_OFFSET_CAPTURE))
  10016. {
  10017. $max = 0;
  10018. $pos = null;
  10019. foreach ($matches[0] as $match)
  10020. {
  10021. if (strlen($match[0]) > $max)
  10022. {
  10023. $max = strlen($match[0]);
  10024. $pos = $match[1];
  10025. }
  10026. }
  10027. $ip_parts[0] = substr_replace($ip_parts[0], '::', $pos, $max);
  10028. }
  10029. if ($ip_parts[1] !== '')
  10030. {
  10031. return implode(':', $ip_parts);
  10032. }
  10033. else
  10034. {
  10035. return $ip_parts[0];
  10036. }
  10037. }
  10038. /**
  10039. * Splits an IPv6 address into the IPv6 and IPv4 representation parts
  10040. *
  10041. * RFC 4291 allows you to represent the last two parts of an IPv6 address
  10042. * using the standard IPv4 representation
  10043. *
  10044. * Example: 0:0:0:0:0:0:13.1.68.3
  10045. * 0:0:0:0:0:FFFF:129.144.52.38
  10046. *
  10047. * @param string $ip An IPv6 address
  10048. * @return array [0] contains the IPv6 represented part, and [1] the IPv4 represented part
  10049. */
  10050. private static function split_v6_v4($ip)
  10051. {
  10052. if (strpos($ip, '.') !== false)
  10053. {
  10054. $pos = strrpos($ip, ':');
  10055. $ipv6_part = substr($ip, 0, $pos);
  10056. $ipv4_part = substr($ip, $pos + 1);
  10057. return array($ipv6_part, $ipv4_part);
  10058. }
  10059. else
  10060. {
  10061. return array($ip, '');
  10062. }
  10063. }
  10064. /**
  10065. * Checks an IPv6 address
  10066. *
  10067. * Checks if the given IP is a valid IPv6 address
  10068. *
  10069. * @param string $ip An IPv6 address
  10070. * @return bool true if $ip is a valid IPv6 address
  10071. */
  10072. public static function check_ipv6($ip)
  10073. {
  10074. $ip = self::uncompress($ip);
  10075. list($ipv6, $ipv4) = self::split_v6_v4($ip);
  10076. $ipv6 = explode(':', $ipv6);
  10077. $ipv4 = explode('.', $ipv4);
  10078. if (count($ipv6) === 8 && count($ipv4) === 1 || count($ipv6) === 6 && count($ipv4) === 4)
  10079. {
  10080. foreach ($ipv6 as $ipv6_part)
  10081. {
  10082. // The section can't be empty
  10083. if ($ipv6_part === '')
  10084. return false;
  10085. // Nor can it be over four characters
  10086. if (strlen($ipv6_part) > 4)
  10087. return false;
  10088. // Remove leading zeros (this is safe because of the above)
  10089. $ipv6_part = ltrim($ipv6_part, '0');
  10090. if ($ipv6_part === '')
  10091. $ipv6_part = '0';
  10092. // Check the value is valid
  10093. $value = hexdec($ipv6_part);
  10094. if (dechex($value) !== strtolower($ipv6_part) || $value < 0 || $value > 0xFFFF)
  10095. return false;
  10096. }
  10097. if (count($ipv4) === 4)
  10098. {
  10099. foreach ($ipv4 as $ipv4_part)
  10100. {
  10101. $value = (int) $ipv4_part;
  10102. if ((string) $value !== $ipv4_part || $value < 0 || $value > 0xFF)
  10103. return false;
  10104. }
  10105. }
  10106. return true;
  10107. }
  10108. else
  10109. {
  10110. return false;
  10111. }
  10112. }
  10113. /**
  10114. * Checks if the given IP is a valid IPv6 address
  10115. *
  10116. * @codeCoverageIgnore
  10117. * @deprecated Use {@see SimplePie_Net_IPv6::check_ipv6()} instead
  10118. * @see check_ipv6
  10119. * @param string $ip An IPv6 address
  10120. * @return bool true if $ip is a valid IPv6 address
  10121. */
  10122. public static function checkIPv6($ip)
  10123. {
  10124. return self::check_ipv6($ip);
  10125. }
  10126. }
  10127. /**
  10128. * Handles `<media:credit>` as defined in Media RSS
  10129. *
  10130. * Used by {@see SimplePie_Enclosure::get_credit()} and {@see SimplePie_Enclosure::get_credits()}
  10131. *
  10132. * This class can be overloaded with {@see SimplePie::set_credit_class()}
  10133. *
  10134. * @package SimplePie
  10135. * @subpackage API
  10136. */
  10137. class SimplePie_Credit
  10138. {
  10139. /**
  10140. * Credited role
  10141. *
  10142. * @var string
  10143. * @see get_role()
  10144. */
  10145. var $role;
  10146. /**
  10147. * Organizational scheme
  10148. *
  10149. * @var string
  10150. * @see get_scheme()
  10151. */
  10152. var $scheme;
  10153. /**
  10154. * Credited name
  10155. *
  10156. * @var string
  10157. * @see get_name()
  10158. */
  10159. var $name;
  10160. /**
  10161. * Constructor, used to input the data
  10162. *
  10163. * For documentation on all the parameters, see the corresponding
  10164. * properties and their accessors
  10165. */
  10166. public function __construct($role = null, $scheme = null, $name = null)
  10167. {
  10168. $this->role = $role;
  10169. $this->scheme = $scheme;
  10170. $this->name = $name;
  10171. }
  10172. /**
  10173. * String-ified version
  10174. *
  10175. * @return string
  10176. */
  10177. public function __toString()
  10178. {
  10179. // There is no $this->data here
  10180. return md5(serialize($this));
  10181. }
  10182. /**
  10183. * Get the role of the person receiving credit
  10184. *
  10185. * @return string|null
  10186. */
  10187. public function get_role()
  10188. {
  10189. if ($this->role !== null)
  10190. {
  10191. return $this->role;
  10192. }
  10193. else
  10194. {
  10195. return null;
  10196. }
  10197. }
  10198. /**
  10199. * Get the organizational scheme
  10200. *
  10201. * @return string|null
  10202. */
  10203. public function get_scheme()
  10204. {
  10205. if ($this->scheme !== null)
  10206. {
  10207. return $this->scheme;
  10208. }
  10209. else
  10210. {
  10211. return null;
  10212. }
  10213. }
  10214. /**
  10215. * Get the credited person/entity's name
  10216. *
  10217. * @return string|null
  10218. */
  10219. public function get_name()
  10220. {
  10221. if ($this->name !== null)
  10222. {
  10223. return $this->name;
  10224. }
  10225. else
  10226. {
  10227. return null;
  10228. }
  10229. }
  10230. }
  10231. /**
  10232. * Used to create cache objects
  10233. *
  10234. * This class can be overloaded with {@see SimplePie::set_cache_class()},
  10235. * although the preferred way is to create your own handler
  10236. * via {@see register()}
  10237. *
  10238. * @package SimplePie
  10239. * @subpackage Caching
  10240. */
  10241. class SimplePie_Cache
  10242. {
  10243. /**
  10244. * Cache handler classes
  10245. *
  10246. * These receive 3 parameters to their constructor, as documented in
  10247. * {@see register()}
  10248. * @var array
  10249. */
  10250. protected static $handlers = array(
  10251. 'mysql' => 'SimplePie_Cache_MySQL',
  10252. 'memcache' => 'SimplePie_Cache_Memcache',
  10253. );
  10254. /**
  10255. * Don't call the constructor. Please.
  10256. */
  10257. private function __construct() { }
  10258. /**
  10259. * Create a new SimplePie_Cache object
  10260. *
  10261. * @param string $location URL location (scheme is used to determine handler)
  10262. * @param string $filename Unique identifier for cache object
  10263. * @param string $extension 'spi' or 'spc'
  10264. * @return SimplePie_Cache_Base Type of object depends on scheme of `$location`
  10265. */
  10266. public static function get_handler($location, $filename, $extension)
  10267. {
  10268. $type = explode(':', $location, 2);
  10269. $type = $type[0];
  10270. if (!empty(self::$handlers[$type]))
  10271. {
  10272. $class = self::$handlers[$type];
  10273. return new $class($location, $filename, $extension);
  10274. }
  10275. return new SimplePie_Cache_File($location, $filename, $extension);
  10276. }
  10277. /**
  10278. * Create a new SimplePie_Cache object
  10279. *
  10280. * @deprecated Use {@see get_handler} instead
  10281. */
  10282. public function create($location, $filename, $extension)
  10283. {
  10284. trigger_error('Cache::create() has been replaced with Cache::get_handler(). Switch to the registry system to use this.', E_USER_DEPRECATED);
  10285. return self::get_handler($location, $filename, $extension);
  10286. }
  10287. /**
  10288. * Register a handler
  10289. *
  10290. * @param string $type DSN type to register for
  10291. * @param string $class Name of handler class. Must implement SimplePie_Cache_Base
  10292. */
  10293. public static function register($type, $class)
  10294. {
  10295. self::$handlers[$type] = $class;
  10296. }
  10297. /**
  10298. * Parse a URL into an array
  10299. *
  10300. * @param string $url
  10301. * @return array
  10302. */
  10303. public static function parse_URL($url)
  10304. {
  10305. $params = parse_url($url);
  10306. $params['extras'] = array();
  10307. if (isset($params['query']))
  10308. {
  10309. parse_str($params['query'], $params['extras']);
  10310. }
  10311. return $params;
  10312. }
  10313. }
  10314. /**
  10315. * Manages all author-related data
  10316. *
  10317. * Used by {@see SimplePie_Item::get_author()} and {@see SimplePie::get_authors()}
  10318. *
  10319. * This class can be overloaded with {@see SimplePie::set_author_class()}
  10320. *
  10321. * @package SimplePie
  10322. * @subpackage API
  10323. */
  10324. class SimplePie_Author
  10325. {
  10326. /**
  10327. * Author's name
  10328. *
  10329. * @var string
  10330. * @see get_name()
  10331. */
  10332. var $name;
  10333. /**
  10334. * Author's link
  10335. *
  10336. * @var string
  10337. * @see get_link()
  10338. */
  10339. var $link;
  10340. /**
  10341. * Author's email address
  10342. *
  10343. * @var string
  10344. * @see get_email()
  10345. */
  10346. var $email;
  10347. /**
  10348. * Constructor, used to input the data
  10349. *
  10350. * @param string $name
  10351. * @param string $link
  10352. * @param string $email
  10353. */
  10354. public function __construct($name = null, $link = null, $email = null)
  10355. {
  10356. $this->name = $name;
  10357. $this->link = $link;
  10358. $this->email = $email;
  10359. }
  10360. /**
  10361. * String-ified version
  10362. *
  10363. * @return string
  10364. */
  10365. public function __toString()
  10366. {
  10367. // There is no $this->data here
  10368. return md5(serialize($this));
  10369. }
  10370. /**
  10371. * Author's name
  10372. *
  10373. * @return string|null
  10374. */
  10375. public function get_name()
  10376. {
  10377. if ($this->name !== null)
  10378. {
  10379. return $this->name;
  10380. }
  10381. else
  10382. {
  10383. return null;
  10384. }
  10385. }
  10386. /**
  10387. * Author's link
  10388. *
  10389. * @return string|null
  10390. */
  10391. public function get_link()
  10392. {
  10393. if ($this->link !== null)
  10394. {
  10395. return $this->link;
  10396. }
  10397. else
  10398. {
  10399. return null;
  10400. }
  10401. }
  10402. /**
  10403. * Author's email address
  10404. *
  10405. * @return string|null
  10406. */
  10407. public function get_email()
  10408. {
  10409. if ($this->email !== null)
  10410. {
  10411. return $this->email;
  10412. }
  10413. else
  10414. {
  10415. return null;
  10416. }
  10417. }
  10418. }
  10419. /**
  10420. * Miscellanous utilities
  10421. *
  10422. * @package SimplePie
  10423. */
  10424. class SimplePie_Misc
  10425. {
  10426. public static function time_hms($seconds)
  10427. {
  10428. $time = '';
  10429. $hours = floor($seconds / 3600);
  10430. $remainder = $seconds % 3600;
  10431. if ($hours > 0)
  10432. {
  10433. $time .= $hours.':';
  10434. }
  10435. $minutes = floor($remainder / 60);
  10436. $seconds = $remainder % 60;
  10437. if ($minutes < 10 && $hours > 0)
  10438. {
  10439. $minutes = '0' . $minutes;
  10440. }
  10441. if ($seconds < 10)
  10442. {
  10443. $seconds = '0' . $seconds;
  10444. }
  10445. $time .= $minutes.':';
  10446. $time .= $seconds;
  10447. return $time;
  10448. }
  10449. public static function absolutize_url($relative, $base)
  10450. {
  10451. $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
  10452. if ($iri === false)
  10453. {
  10454. return false;
  10455. }
  10456. return $iri->get_uri();
  10457. }
  10458. /**
  10459. * Get a HTML/XML element from a HTML string
  10460. *
  10461. * @deprecated Use DOMDocument instead (parsing HTML with regex is bad!)
  10462. * @param string $realname Element name (including namespace prefix if applicable)
  10463. * @param string $string HTML document
  10464. * @return array
  10465. */
  10466. public static function get_element($realname, $string)
  10467. {
  10468. $return = array();
  10469. $name = preg_quote($realname, '/');
  10470. if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
  10471. {
  10472. for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
  10473. {
  10474. $return[$i]['tag'] = $realname;
  10475. $return[$i]['full'] = $matches[$i][0][0];
  10476. $return[$i]['offset'] = $matches[$i][0][1];
  10477. if (strlen($matches[$i][3][0]) <= 2)
  10478. {
  10479. $return[$i]['self_closing'] = true;
  10480. }
  10481. else
  10482. {
  10483. $return[$i]['self_closing'] = false;
  10484. $return[$i]['content'] = $matches[$i][4][0];
  10485. }
  10486. $return[$i]['attribs'] = array();
  10487. 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))
  10488. {
  10489. for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
  10490. {
  10491. if (count($attribs[$j]) === 2)
  10492. {
  10493. $attribs[$j][2] = $attribs[$j][1];
  10494. }
  10495. $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
  10496. }
  10497. }
  10498. }
  10499. }
  10500. return $return;
  10501. }
  10502. public static function element_implode($element)
  10503. {
  10504. $full = "<$element[tag]";
  10505. foreach ($element['attribs'] as $key => $value)
  10506. {
  10507. $key = strtolower($key);
  10508. $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
  10509. }
  10510. if ($element['self_closing'])
  10511. {
  10512. $full .= ' />';
  10513. }
  10514. else
  10515. {
  10516. $full .= ">$element[content]</$element[tag]>";
  10517. }
  10518. return $full;
  10519. }
  10520. public static function error($message, $level, $file, $line)
  10521. {
  10522. if ((ini_get('error_reporting') & $level) > 0)
  10523. {
  10524. switch ($level)
  10525. {
  10526. case E_USER_ERROR:
  10527. $note = 'PHP Error';
  10528. break;
  10529. case E_USER_WARNING:
  10530. $note = 'PHP Warning';
  10531. break;
  10532. case E_USER_NOTICE:
  10533. $note = 'PHP Notice';
  10534. break;
  10535. default:
  10536. $note = 'Unknown Error';
  10537. break;
  10538. }
  10539. $log_error = true;
  10540. if (!function_exists('error_log'))
  10541. {
  10542. $log_error = false;
  10543. }
  10544. $log_file = @ini_get('error_log');
  10545. if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file))
  10546. {
  10547. $log_error = false;
  10548. }
  10549. if ($log_error)
  10550. {
  10551. @error_log("$note: $message in $file on line $line", 0);
  10552. }
  10553. }
  10554. return $message;
  10555. }
  10556. public static function fix_protocol($url, $http = 1)
  10557. {
  10558. $url = SimplePie_Misc::normalize_url($url);
  10559. $parsed = SimplePie_Misc::parse_url($url);
  10560. if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https')
  10561. {
  10562. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
  10563. }
  10564. if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
  10565. {
  10566. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
  10567. }
  10568. if ($http === 2 && $parsed['scheme'] !== '')
  10569. {
  10570. return "feed:$url";
  10571. }
  10572. elseif ($http === 3 && strtolower($parsed['scheme']) === 'http')
  10573. {
  10574. return substr_replace($url, 'podcast', 0, 4);
  10575. }
  10576. elseif ($http === 4 && strtolower($parsed['scheme']) === 'http')
  10577. {
  10578. return substr_replace($url, 'itpc', 0, 4);
  10579. }
  10580. else
  10581. {
  10582. return $url;
  10583. }
  10584. }
  10585. public static function parse_url($url)
  10586. {
  10587. $iri = new SimplePie_IRI($url);
  10588. return array(
  10589. 'scheme' => (string) $iri->scheme,
  10590. 'authority' => (string) $iri->authority,
  10591. 'path' => (string) $iri->path,
  10592. 'query' => (string) $iri->query,
  10593. 'fragment' => (string) $iri->fragment
  10594. );
  10595. }
  10596. public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
  10597. {
  10598. $iri = new SimplePie_IRI('');
  10599. $iri->scheme = $scheme;
  10600. $iri->authority = $authority;
  10601. $iri->path = $path;
  10602. $iri->query = $query;
  10603. $iri->fragment = $fragment;
  10604. return $iri->get_uri();
  10605. }
  10606. public static function normalize_url($url)
  10607. {
  10608. $iri = new SimplePie_IRI($url);
  10609. return $iri->get_uri();
  10610. }
  10611. public static function percent_encoding_normalization($match)
  10612. {
  10613. $integer = hexdec($match[1]);
  10614. if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E)
  10615. {
  10616. return chr($integer);
  10617. }
  10618. else
  10619. {
  10620. return strtoupper($match[0]);
  10621. }
  10622. }
  10623. /**
  10624. * Converts a Windows-1252 encoded string to a UTF-8 encoded string
  10625. *
  10626. * @static
  10627. * @param string $string Windows-1252 encoded string
  10628. * @return string UTF-8 encoded string
  10629. */
  10630. public static function windows_1252_to_utf8($string)
  10631. {
  10632. 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");
  10633. return strtr($string, $convert_table);
  10634. }
  10635. /**
  10636. * Change a string from one encoding to another
  10637. *
  10638. * @param string $data Raw data in $input encoding
  10639. * @param string $input Encoding of $data
  10640. * @param string $output Encoding you want
  10641. * @return string|boolean False if we can't convert it
  10642. */
  10643. public static function change_encoding($data, $input, $output)
  10644. {
  10645. $input = SimplePie_Misc::encoding($input);
  10646. $output = SimplePie_Misc::encoding($output);
  10647. // We fail to fail on non US-ASCII bytes
  10648. if ($input === 'US-ASCII')
  10649. {
  10650. static $non_ascii_octects = '';
  10651. if (!$non_ascii_octects)
  10652. {
  10653. for ($i = 0x80; $i <= 0xFF; $i++)
  10654. {
  10655. $non_ascii_octects .= chr($i);
  10656. }
  10657. }
  10658. $data = substr($data, 0, strcspn($data, $non_ascii_octects));
  10659. }
  10660. // This is first, as behaviour of this is completely predictable
  10661. if ($input === 'windows-1252' && $output === 'UTF-8')
  10662. {
  10663. return SimplePie_Misc::windows_1252_to_utf8($data);
  10664. }
  10665. // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
  10666. elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
  10667. {
  10668. return $return;
  10669. }
  10670. // This is last, as behaviour of this varies with OS userland and PHP version
  10671. elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
  10672. {
  10673. return $return;
  10674. }
  10675. // If we can't do anything, just fail
  10676. else
  10677. {
  10678. return false;
  10679. }
  10680. }
  10681. protected static function change_encoding_mbstring($data, $input, $output)
  10682. {
  10683. if ($input === 'windows-949')
  10684. {
  10685. $input = 'EUC-KR';
  10686. }
  10687. if ($output === 'windows-949')
  10688. {
  10689. $output = 'EUC-KR';
  10690. }
  10691. if ($input === 'Windows-31J')
  10692. {
  10693. $input = 'SJIS';
  10694. }
  10695. if ($output === 'Windows-31J')
  10696. {
  10697. $output = 'SJIS';
  10698. }
  10699. // Check that the encoding is supported
  10700. if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80")
  10701. {
  10702. return false;
  10703. }
  10704. if (!in_array($input, mb_list_encodings()))
  10705. {
  10706. return false;
  10707. }
  10708. // Let's do some conversion
  10709. if ($return = @mb_convert_encoding($data, $output, $input))
  10710. {
  10711. return $return;
  10712. }
  10713. return false;
  10714. }
  10715. protected static function change_encoding_iconv($data, $input, $output)
  10716. {
  10717. return @iconv($input, $output, $data);
  10718. }
  10719. /**
  10720. * Normalize an encoding name
  10721. *
  10722. * This is automatically generated by create.php
  10723. *
  10724. * To generate it, run `php create.php` on the command line, and copy the
  10725. * output to replace this function.
  10726. *
  10727. * @param string $charset Character set to standardise
  10728. * @return string Standardised name
  10729. */
  10730. public static function encoding($charset)
  10731. {
  10732. // Normalization from UTS #22
  10733. switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset)))
  10734. {
  10735. case 'adobestandardencoding':
  10736. case 'csadobestandardencoding':
  10737. return 'Adobe-Standard-Encoding';
  10738. case 'adobesymbolencoding':
  10739. case 'cshppsmath':
  10740. return 'Adobe-Symbol-Encoding';
  10741. case 'ami1251':
  10742. case 'amiga1251':
  10743. return 'Amiga-1251';
  10744. case 'ansix31101983':
  10745. case 'csat5001983':
  10746. case 'csiso99naplps':
  10747. case 'isoir99':
  10748. case 'naplps':
  10749. return 'ANSI_X3.110-1983';
  10750. case 'arabic7':
  10751. case 'asmo449':
  10752. case 'csiso89asmo449':
  10753. case 'iso9036':
  10754. case 'isoir89':
  10755. return 'ASMO_449';
  10756. case 'big5':
  10757. case 'csbig5':
  10758. return 'Big5';
  10759. case 'big5hkscs':
  10760. return 'Big5-HKSCS';
  10761. case 'bocu1':
  10762. case 'csbocu1':
  10763. return 'BOCU-1';
  10764. case 'brf':
  10765. case 'csbrf':
  10766. return 'BRF';
  10767. case 'bs4730':
  10768. case 'csiso4unitedkingdom':
  10769. case 'gb':
  10770. case 'iso646gb':
  10771. case 'isoir4':
  10772. case 'uk':
  10773. return 'BS_4730';
  10774. case 'bsviewdata':
  10775. case 'csiso47bsviewdata':
  10776. case 'isoir47':
  10777. return 'BS_viewdata';
  10778. case 'cesu8':
  10779. case 'cscesu8':
  10780. return 'CESU-8';
  10781. case 'ca':
  10782. case 'csa71':
  10783. case 'csaz243419851':
  10784. case 'csiso121canadian1':
  10785. case 'iso646ca':
  10786. case 'isoir121':
  10787. return 'CSA_Z243.4-1985-1';
  10788. case 'csa72':
  10789. case 'csaz243419852':
  10790. case 'csiso122canadian2':
  10791. case 'iso646ca2':
  10792. case 'isoir122':
  10793. return 'CSA_Z243.4-1985-2';
  10794. case 'csaz24341985gr':
  10795. case 'csiso123csaz24341985gr':
  10796. case 'isoir123':
  10797. return 'CSA_Z243.4-1985-gr';
  10798. case 'csiso139csn369103':
  10799. case 'csn369103':
  10800. case 'isoir139':
  10801. return 'CSN_369103';
  10802. case 'csdecmcs':
  10803. case 'dec':
  10804. case 'decmcs':
  10805. return 'DEC-MCS';
  10806. case 'csiso21german':
  10807. case 'de':
  10808. case 'din66003':
  10809. case 'iso646de':
  10810. case 'isoir21':
  10811. return 'DIN_66003';
  10812. case 'csdkus':
  10813. case 'dkus':
  10814. return 'dk-us';
  10815. case 'csiso646danish':
  10816. case 'dk':
  10817. case 'ds2089':
  10818. case 'iso646dk':
  10819. return 'DS_2089';
  10820. case 'csibmebcdicatde':
  10821. case 'ebcdicatde':
  10822. return 'EBCDIC-AT-DE';
  10823. case 'csebcdicatdea':
  10824. case 'ebcdicatdea':
  10825. return 'EBCDIC-AT-DE-A';
  10826. case 'csebcdiccafr':
  10827. case 'ebcdiccafr':
  10828. return 'EBCDIC-CA-FR';
  10829. case 'csebcdicdkno':
  10830. case 'ebcdicdkno':
  10831. return 'EBCDIC-DK-NO';
  10832. case 'csebcdicdknoa':
  10833. case 'ebcdicdknoa':
  10834. return 'EBCDIC-DK-NO-A';
  10835. case 'csebcdices':
  10836. case 'ebcdices':
  10837. return 'EBCDIC-ES';
  10838. case 'csebcdicesa':
  10839. case 'ebcdicesa':
  10840. return 'EBCDIC-ES-A';
  10841. case 'csebcdicess':
  10842. case 'ebcdicess':
  10843. return 'EBCDIC-ES-S';
  10844. case 'csebcdicfise':
  10845. case 'ebcdicfise':
  10846. return 'EBCDIC-FI-SE';
  10847. case 'csebcdicfisea':
  10848. case 'ebcdicfisea':
  10849. return 'EBCDIC-FI-SE-A';
  10850. case 'csebcdicfr':
  10851. case 'ebcdicfr':
  10852. return 'EBCDIC-FR';
  10853. case 'csebcdicit':
  10854. case 'ebcdicit':
  10855. return 'EBCDIC-IT';
  10856. case 'csebcdicpt':
  10857. case 'ebcdicpt':
  10858. return 'EBCDIC-PT';
  10859. case 'csebcdicuk':
  10860. case 'ebcdicuk':
  10861. return 'EBCDIC-UK';
  10862. case 'csebcdicus':
  10863. case 'ebcdicus':
  10864. return 'EBCDIC-US';
  10865. case 'csiso111ecmacyrillic':
  10866. case 'ecmacyrillic':
  10867. case 'isoir111':
  10868. case 'koi8e':
  10869. return 'ECMA-cyrillic';
  10870. case 'csiso17spanish':
  10871. case 'es':
  10872. case 'iso646es':
  10873. case 'isoir17':
  10874. return 'ES';
  10875. case 'csiso85spanish2':
  10876. case 'es2':
  10877. case 'iso646es2':
  10878. case 'isoir85':
  10879. return 'ES2';
  10880. case 'cseucpkdfmtjapanese':
  10881. case 'eucjp':
  10882. case 'extendedunixcodepackedformatforjapanese':
  10883. return 'EUC-JP';
  10884. case 'cseucfixwidjapanese':
  10885. case 'extendedunixcodefixedwidthforjapanese':
  10886. return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
  10887. case 'gb18030':
  10888. return 'GB18030';
  10889. case 'chinese':
  10890. case 'cp936':
  10891. case 'csgb2312':
  10892. case 'csiso58gb231280':
  10893. case 'gb2312':
  10894. case 'gb231280':
  10895. case 'gbk':
  10896. case 'isoir58':
  10897. case 'ms936':
  10898. case 'windows936':
  10899. return 'GBK';
  10900. case 'cn':
  10901. case 'csiso57gb1988':
  10902. case 'gb198880':
  10903. case 'iso646cn':
  10904. case 'isoir57':
  10905. return 'GB_1988-80';
  10906. case 'csiso153gost1976874':
  10907. case 'gost1976874':
  10908. case 'isoir153':
  10909. case 'stsev35888':
  10910. return 'GOST_19768-74';
  10911. case 'csiso150':
  10912. case 'csiso150greekccitt':
  10913. case 'greekccitt':
  10914. case 'isoir150':
  10915. return 'greek-ccitt';
  10916. case 'csiso88greek7':
  10917. case 'greek7':
  10918. case 'isoir88':
  10919. return 'greek7';
  10920. case 'csiso18greek7old':
  10921. case 'greek7old':
  10922. case 'isoir18':
  10923. return 'greek7-old';
  10924. case 'cshpdesktop':
  10925. case 'hpdesktop':
  10926. return 'HP-DeskTop';
  10927. case 'cshplegal':
  10928. case 'hplegal':
  10929. return 'HP-Legal';
  10930. case 'cshpmath8':
  10931. case 'hpmath8':
  10932. return 'HP-Math8';
  10933. case 'cshppifont':
  10934. case 'hppifont':
  10935. return 'HP-Pi-font';
  10936. case 'cshproman8':
  10937. case 'hproman8':
  10938. case 'r8':
  10939. case 'roman8':
  10940. return 'hp-roman8';
  10941. case 'hzgb2312':
  10942. return 'HZ-GB-2312';
  10943. case 'csibmsymbols':
  10944. case 'ibmsymbols':
  10945. return 'IBM-Symbols';
  10946. case 'csibmthai':
  10947. case 'ibmthai':
  10948. return 'IBM-Thai';
  10949. case 'cp37':
  10950. case 'csibm37':
  10951. case 'ebcdiccpca':
  10952. case 'ebcdiccpnl':
  10953. case 'ebcdiccpus':
  10954. case 'ebcdiccpwt':
  10955. case 'ibm37':
  10956. return 'IBM037';
  10957. case 'cp38':
  10958. case 'csibm38':
  10959. case 'ebcdicint':
  10960. case 'ibm38':
  10961. return 'IBM038';
  10962. case 'cp273':
  10963. case 'csibm273':
  10964. case 'ibm273':
  10965. return 'IBM273';
  10966. case 'cp274':
  10967. case 'csibm274':
  10968. case 'ebcdicbe':
  10969. case 'ibm274':
  10970. return 'IBM274';
  10971. case 'cp275':
  10972. case 'csibm275':
  10973. case 'ebcdicbr':
  10974. case 'ibm275':
  10975. return 'IBM275';
  10976. case 'csibm277':
  10977. case 'ebcdiccpdk':
  10978. case 'ebcdiccpno':
  10979. case 'ibm277':
  10980. return 'IBM277';
  10981. case 'cp278':
  10982. case 'csibm278':
  10983. case 'ebcdiccpfi':
  10984. case 'ebcdiccpse':
  10985. case 'ibm278':
  10986. return 'IBM278';
  10987. case 'cp280':
  10988. case 'csibm280':
  10989. case 'ebcdiccpit':
  10990. case 'ibm280':
  10991. return 'IBM280';
  10992. case 'cp281':
  10993. case 'csibm281':
  10994. case 'ebcdicjpe':
  10995. case 'ibm281':
  10996. return 'IBM281';
  10997. case 'cp284':
  10998. case 'csibm284':
  10999. case 'ebcdiccpes':
  11000. case 'ibm284':
  11001. return 'IBM284';
  11002. case 'cp285':
  11003. case 'csibm285':
  11004. case 'ebcdiccpgb':
  11005. case 'ibm285':
  11006. return 'IBM285';
  11007. case 'cp290':
  11008. case 'csibm290':
  11009. case 'ebcdicjpkana':
  11010. case 'ibm290':
  11011. return 'IBM290';
  11012. case 'cp297':
  11013. case 'csibm297':
  11014. case 'ebcdiccpfr':
  11015. case 'ibm297':
  11016. return 'IBM297';
  11017. case 'cp420':
  11018. case 'csibm420':
  11019. case 'ebcdiccpar1':
  11020. case 'ibm420':
  11021. return 'IBM420';
  11022. case 'cp423':
  11023. case 'csibm423':
  11024. case 'ebcdiccpgr':
  11025. case 'ibm423':
  11026. return 'IBM423';
  11027. case 'cp424':
  11028. case 'csibm424':
  11029. case 'ebcdiccphe':
  11030. case 'ibm424':
  11031. return 'IBM424';
  11032. case '437':
  11033. case 'cp437':
  11034. case 'cspc8codepage437':
  11035. case 'ibm437':
  11036. return 'IBM437';
  11037. case 'cp500':
  11038. case 'csibm500':
  11039. case 'ebcdiccpbe':
  11040. case 'ebcdiccpch':
  11041. case 'ibm500':
  11042. return 'IBM500';
  11043. case 'cp775':
  11044. case 'cspc775baltic':
  11045. case 'ibm775':
  11046. return 'IBM775';
  11047. case '850':
  11048. case 'cp850':
  11049. case 'cspc850multilingual':
  11050. case 'ibm850':
  11051. return 'IBM850';
  11052. case '851':
  11053. case 'cp851':
  11054. case 'csibm851':
  11055. case 'ibm851':
  11056. return 'IBM851';
  11057. case '852':
  11058. case 'cp852':
  11059. case 'cspcp852':
  11060. case 'ibm852':
  11061. return 'IBM852';
  11062. case '855':
  11063. case 'cp855':
  11064. case 'csibm855':
  11065. case 'ibm855':
  11066. return 'IBM855';
  11067. case '857':
  11068. case 'cp857':
  11069. case 'csibm857':
  11070. case 'ibm857':
  11071. return 'IBM857';
  11072. case 'ccsid858':
  11073. case 'cp858':
  11074. case 'ibm858':
  11075. case 'pcmultilingual850euro':
  11076. return 'IBM00858';
  11077. case '860':
  11078. case 'cp860':
  11079. case 'csibm860':
  11080. case 'ibm860':
  11081. return 'IBM860';
  11082. case '861':
  11083. case 'cp861':
  11084. case 'cpis':
  11085. case 'csibm861':
  11086. case 'ibm861':
  11087. return 'IBM861';
  11088. case '862':
  11089. case 'cp862':
  11090. case 'cspc862latinhebrew':
  11091. case 'ibm862':
  11092. return 'IBM862';
  11093. case '863':
  11094. case 'cp863':
  11095. case 'csibm863':
  11096. case 'ibm863':
  11097. return 'IBM863';
  11098. case 'cp864':
  11099. case 'csibm864':
  11100. case 'ibm864':
  11101. return 'IBM864';
  11102. case '865':
  11103. case 'cp865':
  11104. case 'csibm865':
  11105. case 'ibm865':
  11106. return 'IBM865';
  11107. case '866':
  11108. case 'cp866':
  11109. case 'csibm866':
  11110. case 'ibm866':
  11111. return 'IBM866';
  11112. case 'cp868':
  11113. case 'cpar':
  11114. case 'csibm868':
  11115. case 'ibm868':
  11116. return 'IBM868';
  11117. case '869':
  11118. case 'cp869':
  11119. case 'cpgr':
  11120. case 'csibm869':
  11121. case 'ibm869':
  11122. return 'IBM869';
  11123. case 'cp870':
  11124. case 'csibm870':
  11125. case 'ebcdiccproece':
  11126. case 'ebcdiccpyu':
  11127. case 'ibm870':
  11128. return 'IBM870';
  11129. case 'cp871':
  11130. case 'csibm871':
  11131. case 'ebcdiccpis':
  11132. case 'ibm871':
  11133. return 'IBM871';
  11134. case 'cp880':
  11135. case 'csibm880':
  11136. case 'ebcdiccyrillic':
  11137. case 'ibm880':
  11138. return 'IBM880';
  11139. case 'cp891':
  11140. case 'csibm891':
  11141. case 'ibm891':
  11142. return 'IBM891';
  11143. case 'cp903':
  11144. case 'csibm903':
  11145. case 'ibm903':
  11146. return 'IBM903';
  11147. case '904':
  11148. case 'cp904':
  11149. case 'csibbm904':
  11150. case 'ibm904':
  11151. return 'IBM904';
  11152. case 'cp905':
  11153. case 'csibm905':
  11154. case 'ebcdiccptr':
  11155. case 'ibm905':
  11156. return 'IBM905';
  11157. case 'cp918':
  11158. case 'csibm918':
  11159. case 'ebcdiccpar2':
  11160. case 'ibm918':
  11161. return 'IBM918';
  11162. case 'ccsid924':
  11163. case 'cp924':
  11164. case 'ebcdiclatin9euro':
  11165. case 'ibm924':
  11166. return 'IBM00924';
  11167. case 'cp1026':
  11168. case 'csibm1026':
  11169. case 'ibm1026':
  11170. return 'IBM1026';
  11171. case 'ibm1047':
  11172. return 'IBM1047';
  11173. case 'ccsid1140':
  11174. case 'cp1140':
  11175. case 'ebcdicus37euro':
  11176. case 'ibm1140':
  11177. return 'IBM01140';
  11178. case 'ccsid1141':
  11179. case 'cp1141':
  11180. case 'ebcdicde273euro':
  11181. case 'ibm1141':
  11182. return 'IBM01141';
  11183. case 'ccsid1142':
  11184. case 'cp1142':
  11185. case 'ebcdicdk277euro':
  11186. case 'ebcdicno277euro':
  11187. case 'ibm1142':
  11188. return 'IBM01142';
  11189. case 'ccsid1143':
  11190. case 'cp1143':
  11191. case 'ebcdicfi278euro':
  11192. case 'ebcdicse278euro':
  11193. case 'ibm1143':
  11194. return 'IBM01143';
  11195. case 'ccsid1144':
  11196. case 'cp1144':
  11197. case 'ebcdicit280euro':
  11198. case 'ibm1144':
  11199. return 'IBM01144';
  11200. case 'ccsid1145':
  11201. case 'cp1145':
  11202. case 'ebcdices284euro':
  11203. case 'ibm1145':
  11204. return 'IBM01145';
  11205. case 'ccsid1146':
  11206. case 'cp1146':
  11207. case 'ebcdicgb285euro':
  11208. case 'ibm1146':
  11209. return 'IBM01146';
  11210. case 'ccsid1147':
  11211. case 'cp1147':
  11212. case 'ebcdicfr297euro':
  11213. case 'ibm1147':
  11214. return 'IBM01147';
  11215. case 'ccsid1148':
  11216. case 'cp1148':
  11217. case 'ebcdicinternational500euro':
  11218. case 'ibm1148':
  11219. return 'IBM01148';
  11220. case 'ccsid1149':
  11221. case 'cp1149':
  11222. case 'ebcdicis871euro':
  11223. case 'ibm1149':
  11224. return 'IBM01149';
  11225. case 'csiso143iecp271':
  11226. case 'iecp271':
  11227. case 'isoir143':
  11228. return 'IEC_P27-1';
  11229. case 'csiso49inis':
  11230. case 'inis':
  11231. case 'isoir49':
  11232. return 'INIS';
  11233. case 'csiso50inis8':
  11234. case 'inis8':
  11235. case 'isoir50':
  11236. return 'INIS-8';
  11237. case 'csiso51iniscyrillic':
  11238. case 'iniscyrillic':
  11239. case 'isoir51':
  11240. return 'INIS-cyrillic';
  11241. case 'csinvariant':
  11242. case 'invariant':
  11243. return 'INVARIANT';
  11244. case 'iso2022cn':
  11245. return 'ISO-2022-CN';
  11246. case 'iso2022cnext':
  11247. return 'ISO-2022-CN-EXT';
  11248. case 'csiso2022jp':
  11249. case 'iso2022jp':
  11250. return 'ISO-2022-JP';
  11251. case 'csiso2022jp2':
  11252. case 'iso2022jp2':
  11253. return 'ISO-2022-JP-2';
  11254. case 'csiso2022kr':
  11255. case 'iso2022kr':
  11256. return 'ISO-2022-KR';
  11257. case 'cswindows30latin1':
  11258. case 'iso88591windows30latin1':
  11259. return 'ISO-8859-1-Windows-3.0-Latin-1';
  11260. case 'cswindows31latin1':
  11261. case 'iso88591windows31latin1':
  11262. return 'ISO-8859-1-Windows-3.1-Latin-1';
  11263. case 'csisolatin2':
  11264. case 'iso88592':
  11265. case 'iso885921987':
  11266. case 'isoir101':
  11267. case 'l2':
  11268. case 'latin2':
  11269. return 'ISO-8859-2';
  11270. case 'cswindows31latin2':
  11271. case 'iso88592windowslatin2':
  11272. return 'ISO-8859-2-Windows-Latin-2';
  11273. case 'csisolatin3':
  11274. case 'iso88593':
  11275. case 'iso885931988':
  11276. case 'isoir109':
  11277. case 'l3':
  11278. case 'latin3':
  11279. return 'ISO-8859-3';
  11280. case 'csisolatin4':
  11281. case 'iso88594':
  11282. case 'iso885941988':
  11283. case 'isoir110':
  11284. case 'l4':
  11285. case 'latin4':
  11286. return 'ISO-8859-4';
  11287. case 'csisolatincyrillic':
  11288. case 'cyrillic':
  11289. case 'iso88595':
  11290. case 'iso885951988':
  11291. case 'isoir144':
  11292. return 'ISO-8859-5';
  11293. case 'arabic':
  11294. case 'asmo708':
  11295. case 'csisolatinarabic':
  11296. case 'ecma114':
  11297. case 'iso88596':
  11298. case 'iso885961987':
  11299. case 'isoir127':
  11300. return 'ISO-8859-6';
  11301. case 'csiso88596e':
  11302. case 'iso88596e':
  11303. return 'ISO-8859-6-E';
  11304. case 'csiso88596i':
  11305. case 'iso88596i':
  11306. return 'ISO-8859-6-I';
  11307. case 'csisolatingreek':
  11308. case 'ecma118':
  11309. case 'elot928':
  11310. case 'greek':
  11311. case 'greek8':
  11312. case 'iso88597':
  11313. case 'iso885971987':
  11314. case 'isoir126':
  11315. return 'ISO-8859-7';
  11316. case 'csisolatinhebrew':
  11317. case 'hebrew':
  11318. case 'iso88598':
  11319. case 'iso885981988':
  11320. case 'isoir138':
  11321. return 'ISO-8859-8';
  11322. case 'csiso88598e':
  11323. case 'iso88598e':
  11324. return 'ISO-8859-8-E';
  11325. case 'csiso88598i':
  11326. case 'iso88598i':
  11327. return 'ISO-8859-8-I';
  11328. case 'cswindows31latin5':
  11329. case 'iso88599windowslatin5':
  11330. return 'ISO-8859-9-Windows-Latin-5';
  11331. case 'csisolatin6':
  11332. case 'iso885910':
  11333. case 'iso8859101992':
  11334. case 'isoir157':
  11335. case 'l6':
  11336. case 'latin6':
  11337. return 'ISO-8859-10';
  11338. case 'iso885913':
  11339. return 'ISO-8859-13';
  11340. case 'iso885914':
  11341. case 'iso8859141998':
  11342. case 'isoceltic':
  11343. case 'isoir199':
  11344. case 'l8':
  11345. case 'latin8':
  11346. return 'ISO-8859-14';
  11347. case 'iso885915':
  11348. case 'latin9':
  11349. return 'ISO-8859-15';
  11350. case 'iso885916':
  11351. case 'iso8859162001':
  11352. case 'isoir226':
  11353. case 'l10':
  11354. case 'latin10':
  11355. return 'ISO-8859-16';
  11356. case 'iso10646j1':
  11357. return 'ISO-10646-J-1';
  11358. case 'csunicode':
  11359. case 'iso10646ucs2':
  11360. return 'ISO-10646-UCS-2';
  11361. case 'csucs4':
  11362. case 'iso10646ucs4':
  11363. return 'ISO-10646-UCS-4';
  11364. case 'csunicodeascii':
  11365. case 'iso10646ucsbasic':
  11366. return 'ISO-10646-UCS-Basic';
  11367. case 'csunicodelatin1':
  11368. case 'iso10646':
  11369. case 'iso10646unicodelatin1':
  11370. return 'ISO-10646-Unicode-Latin1';
  11371. case 'csiso10646utf1':
  11372. case 'iso10646utf1':
  11373. return 'ISO-10646-UTF-1';
  11374. case 'csiso115481':
  11375. case 'iso115481':
  11376. case 'isotr115481':
  11377. return 'ISO-11548-1';
  11378. case 'csiso90':
  11379. case 'isoir90':
  11380. return 'iso-ir-90';
  11381. case 'csunicodeibm1261':
  11382. case 'isounicodeibm1261':
  11383. return 'ISO-Unicode-IBM-1261';
  11384. case 'csunicodeibm1264':
  11385. case 'isounicodeibm1264':
  11386. return 'ISO-Unicode-IBM-1264';
  11387. case 'csunicodeibm1265':
  11388. case 'isounicodeibm1265':
  11389. return 'ISO-Unicode-IBM-1265';
  11390. case 'csunicodeibm1268':
  11391. case 'isounicodeibm1268':
  11392. return 'ISO-Unicode-IBM-1268';
  11393. case 'csunicodeibm1276':
  11394. case 'isounicodeibm1276':
  11395. return 'ISO-Unicode-IBM-1276';
  11396. case 'csiso646basic1983':
  11397. case 'iso646basic1983':
  11398. case 'ref':
  11399. return 'ISO_646.basic:1983';
  11400. case 'csiso2intlrefversion':
  11401. case 'irv':
  11402. case 'iso646irv1983':
  11403. case 'isoir2':
  11404. return 'ISO_646.irv:1983';
  11405. case 'csiso2033':
  11406. case 'e13b':
  11407. case 'iso20331983':
  11408. case 'isoir98':
  11409. return 'ISO_2033-1983';
  11410. case 'csiso5427cyrillic':
  11411. case 'iso5427':
  11412. case 'isoir37':
  11413. return 'ISO_5427';
  11414. case 'iso5427cyrillic1981':
  11415. case 'iso54271981':
  11416. case 'isoir54':
  11417. return 'ISO_5427:1981';
  11418. case 'csiso5428greek':
  11419. case 'iso54281980':
  11420. case 'isoir55':
  11421. return 'ISO_5428:1980';
  11422. case 'csiso6937add':
  11423. case 'iso6937225':
  11424. case 'isoir152':
  11425. return 'ISO_6937-2-25';
  11426. case 'csisotextcomm':
  11427. case 'iso69372add':
  11428. case 'isoir142':
  11429. return 'ISO_6937-2-add';
  11430. case 'csiso8859supp':
  11431. case 'iso8859supp':
  11432. case 'isoir154':
  11433. case 'latin125':
  11434. return 'ISO_8859-supp';
  11435. case 'csiso10367box':
  11436. case 'iso10367box':
  11437. case 'isoir155':
  11438. return 'ISO_10367-box';
  11439. case 'csiso15italian':
  11440. case 'iso646it':
  11441. case 'isoir15':
  11442. case 'it':
  11443. return 'IT';
  11444. case 'csiso13jisc6220jp':
  11445. case 'isoir13':
  11446. case 'jisc62201969':
  11447. case 'jisc62201969jp':
  11448. case 'katakana':
  11449. case 'x2017':
  11450. return 'JIS_C6220-1969-jp';
  11451. case 'csiso14jisc6220ro':
  11452. case 'iso646jp':
  11453. case 'isoir14':
  11454. case 'jisc62201969ro':
  11455. case 'jp':
  11456. return 'JIS_C6220-1969-ro';
  11457. case 'csiso42jisc62261978':
  11458. case 'isoir42':
  11459. case 'jisc62261978':
  11460. return 'JIS_C6226-1978';
  11461. case 'csiso87jisx208':
  11462. case 'isoir87':
  11463. case 'jisc62261983':
  11464. case 'jisx2081983':
  11465. case 'x208':
  11466. return 'JIS_C6226-1983';
  11467. case 'csiso91jisc62291984a':
  11468. case 'isoir91':
  11469. case 'jisc62291984a':
  11470. case 'jpocra':
  11471. return 'JIS_C6229-1984-a';
  11472. case 'csiso92jisc62991984b':
  11473. case 'iso646jpocrb':
  11474. case 'isoir92':
  11475. case 'jisc62291984b':
  11476. case 'jpocrb':
  11477. return 'JIS_C6229-1984-b';
  11478. case 'csiso93jis62291984badd':
  11479. case 'isoir93':
  11480. case 'jisc62291984badd':
  11481. case 'jpocrbadd':
  11482. return 'JIS_C6229-1984-b-add';
  11483. case 'csiso94jis62291984hand':
  11484. case 'isoir94':
  11485. case 'jisc62291984hand':
  11486. case 'jpocrhand':
  11487. return 'JIS_C6229-1984-hand';
  11488. case 'csiso95jis62291984handadd':
  11489. case 'isoir95':
  11490. case 'jisc62291984handadd':
  11491. case 'jpocrhandadd':
  11492. return 'JIS_C6229-1984-hand-add';
  11493. case 'csiso96jisc62291984kana':
  11494. case 'isoir96':
  11495. case 'jisc62291984kana':
  11496. return 'JIS_C6229-1984-kana';
  11497. case 'csjisencoding':
  11498. case 'jisencoding':
  11499. return 'JIS_Encoding';
  11500. case 'cshalfwidthkatakana':
  11501. case 'jisx201':
  11502. case 'x201':
  11503. return 'JIS_X0201';
  11504. case 'csiso159jisx2121990':
  11505. case 'isoir159':
  11506. case 'jisx2121990':
  11507. case 'x212':
  11508. return 'JIS_X0212-1990';
  11509. case 'csiso141jusib1002':
  11510. case 'iso646yu':
  11511. case 'isoir141':
  11512. case 'js':
  11513. case 'jusib1002':
  11514. case 'yu':
  11515. return 'JUS_I.B1.002';
  11516. case 'csiso147macedonian':
  11517. case 'isoir147':
  11518. case 'jusib1003mac':
  11519. case 'macedonian':
  11520. return 'JUS_I.B1.003-mac';
  11521. case 'csiso146serbian':
  11522. case 'isoir146':
  11523. case 'jusib1003serb':
  11524. case 'serbian':
  11525. return 'JUS_I.B1.003-serb';
  11526. case 'koi7switched':
  11527. return 'KOI7-switched';
  11528. case 'cskoi8r':
  11529. case 'koi8r':
  11530. return 'KOI8-R';
  11531. case 'koi8u':
  11532. return 'KOI8-U';
  11533. case 'csksc5636':
  11534. case 'iso646kr':
  11535. case 'ksc5636':
  11536. return 'KSC5636';
  11537. case 'cskz1048':
  11538. case 'kz1048':
  11539. case 'rk1048':
  11540. case 'strk10482002':
  11541. return 'KZ-1048';
  11542. case 'csiso19latingreek':
  11543. case 'isoir19':
  11544. case 'latingreek':
  11545. return 'latin-greek';
  11546. case 'csiso27latingreek1':
  11547. case 'isoir27':
  11548. case 'latingreek1':
  11549. return 'Latin-greek-1';
  11550. case 'csiso158lap':
  11551. case 'isoir158':
  11552. case 'lap':
  11553. case 'latinlap':
  11554. return 'latin-lap';
  11555. case 'csmacintosh':
  11556. case 'mac':
  11557. case 'macintosh':
  11558. return 'macintosh';
  11559. case 'csmicrosoftpublishing':
  11560. case 'microsoftpublishing':
  11561. return 'Microsoft-Publishing';
  11562. case 'csmnem':
  11563. case 'mnem':
  11564. return 'MNEM';
  11565. case 'csmnemonic':
  11566. case 'mnemonic':
  11567. return 'MNEMONIC';
  11568. case 'csiso86hungarian':
  11569. case 'hu':
  11570. case 'iso646hu':
  11571. case 'isoir86':
  11572. case 'msz77953':
  11573. return 'MSZ_7795.3';
  11574. case 'csnatsdano':
  11575. case 'isoir91':
  11576. case 'natsdano':
  11577. return 'NATS-DANO';
  11578. case 'csnatsdanoadd':
  11579. case 'isoir92':
  11580. case 'natsdanoadd':
  11581. return 'NATS-DANO-ADD';
  11582. case 'csnatssefi':
  11583. case 'isoir81':
  11584. case 'natssefi':
  11585. return 'NATS-SEFI';
  11586. case 'csnatssefiadd':
  11587. case 'isoir82':
  11588. case 'natssefiadd':
  11589. return 'NATS-SEFI-ADD';
  11590. case 'csiso151cuba':
  11591. case 'cuba':
  11592. case 'iso646cu':
  11593. case 'isoir151':
  11594. case 'ncnc1081':
  11595. return 'NC_NC00-10:81';
  11596. case 'csiso69french':
  11597. case 'fr':
  11598. case 'iso646fr':
  11599. case 'isoir69':
  11600. case 'nfz62010':
  11601. return 'NF_Z_62-010';
  11602. case 'csiso25french':
  11603. case 'iso646fr1':
  11604. case 'isoir25':
  11605. case 'nfz620101973':
  11606. return 'NF_Z_62-010_(1973)';
  11607. case 'csiso60danishnorwegian':
  11608. case 'csiso60norwegian1':
  11609. case 'iso646no':
  11610. case 'isoir60':
  11611. case 'no':
  11612. case 'ns45511':
  11613. return 'NS_4551-1';
  11614. case 'csiso61norwegian2':
  11615. case 'iso646no2':
  11616. case 'isoir61':
  11617. case 'no2':
  11618. case 'ns45512':
  11619. return 'NS_4551-2';
  11620. case 'osdebcdicdf3irv':
  11621. return 'OSD_EBCDIC_DF03_IRV';
  11622. case 'osdebcdicdf41':
  11623. return 'OSD_EBCDIC_DF04_1';
  11624. case 'osdebcdicdf415':
  11625. return 'OSD_EBCDIC_DF04_15';
  11626. case 'cspc8danishnorwegian':
  11627. case 'pc8danishnorwegian':
  11628. return 'PC8-Danish-Norwegian';
  11629. case 'cspc8turkish':
  11630. case 'pc8turkish':
  11631. return 'PC8-Turkish';
  11632. case 'csiso16portuguese':
  11633. case 'iso646pt':
  11634. case 'isoir16':
  11635. case 'pt':
  11636. return 'PT';
  11637. case 'csiso84portuguese2':
  11638. case 'iso646pt2':
  11639. case 'isoir84':
  11640. case 'pt2':
  11641. return 'PT2';
  11642. case 'cp154':
  11643. case 'csptcp154':
  11644. case 'cyrillicasian':
  11645. case 'pt154':
  11646. case 'ptcp154':
  11647. return 'PTCP154';
  11648. case 'scsu':
  11649. return 'SCSU';
  11650. case 'csiso10swedish':
  11651. case 'fi':
  11652. case 'iso646fi':
  11653. case 'iso646se':
  11654. case 'isoir10':
  11655. case 'se':
  11656. case 'sen850200b':
  11657. return 'SEN_850200_B';
  11658. case 'csiso11swedishfornames':
  11659. case 'iso646se2':
  11660. case 'isoir11':
  11661. case 'se2':
  11662. case 'sen850200c':
  11663. return 'SEN_850200_C';
  11664. case 'csiso102t617bit':
  11665. case 'isoir102':
  11666. case 't617bit':
  11667. return 'T.61-7bit';
  11668. case 'csiso103t618bit':
  11669. case 'isoir103':
  11670. case 't61':
  11671. case 't618bit':
  11672. return 'T.61-8bit';
  11673. case 'csiso128t101g2':
  11674. case 'isoir128':
  11675. case 't101g2':
  11676. return 'T.101-G2';
  11677. case 'cstscii':
  11678. case 'tscii':
  11679. return 'TSCII';
  11680. case 'csunicode11':
  11681. case 'unicode11':
  11682. return 'UNICODE-1-1';
  11683. case 'csunicode11utf7':
  11684. case 'unicode11utf7':
  11685. return 'UNICODE-1-1-UTF-7';
  11686. case 'csunknown8bit':
  11687. case 'unknown8bit':
  11688. return 'UNKNOWN-8BIT';
  11689. case 'ansix341968':
  11690. case 'ansix341986':
  11691. case 'ascii':
  11692. case 'cp367':
  11693. case 'csascii':
  11694. case 'ibm367':
  11695. case 'iso646irv1991':
  11696. case 'iso646us':
  11697. case 'isoir6':
  11698. case 'us':
  11699. case 'usascii':
  11700. return 'US-ASCII';
  11701. case 'csusdk':
  11702. case 'usdk':
  11703. return 'us-dk';
  11704. case 'utf7':
  11705. return 'UTF-7';
  11706. case 'utf8':
  11707. return 'UTF-8';
  11708. case 'utf16':
  11709. return 'UTF-16';
  11710. case 'utf16be':
  11711. return 'UTF-16BE';
  11712. case 'utf16le':
  11713. return 'UTF-16LE';
  11714. case 'utf32':
  11715. return 'UTF-32';
  11716. case 'utf32be':
  11717. return 'UTF-32BE';
  11718. case 'utf32le':
  11719. return 'UTF-32LE';
  11720. case 'csventurainternational':
  11721. case 'venturainternational':
  11722. return 'Ventura-International';
  11723. case 'csventuramath':
  11724. case 'venturamath':
  11725. return 'Ventura-Math';
  11726. case 'csventuraus':
  11727. case 'venturaus':
  11728. return 'Ventura-US';
  11729. case 'csiso70videotexsupp1':
  11730. case 'isoir70':
  11731. case 'videotexsuppl':
  11732. return 'videotex-suppl';
  11733. case 'csviqr':
  11734. case 'viqr':
  11735. return 'VIQR';
  11736. case 'csviscii':
  11737. case 'viscii':
  11738. return 'VISCII';
  11739. case 'csshiftjis':
  11740. case 'cswindows31j':
  11741. case 'mskanji':
  11742. case 'shiftjis':
  11743. case 'windows31j':
  11744. return 'Windows-31J';
  11745. case 'iso885911':
  11746. case 'tis620':
  11747. return 'windows-874';
  11748. case 'cseuckr':
  11749. case 'csksc56011987':
  11750. case 'euckr':
  11751. case 'isoir149':
  11752. case 'korean':
  11753. case 'ksc5601':
  11754. case 'ksc56011987':
  11755. case 'ksc56011989':
  11756. case 'windows949':
  11757. return 'windows-949';
  11758. case 'windows1250':
  11759. return 'windows-1250';
  11760. case 'windows1251':
  11761. return 'windows-1251';
  11762. case 'cp819':
  11763. case 'csisolatin1':
  11764. case 'ibm819':
  11765. case 'iso88591':
  11766. case 'iso885911987':
  11767. case 'isoir100':
  11768. case 'l1':
  11769. case 'latin1':
  11770. case 'windows1252':
  11771. return 'windows-1252';
  11772. case 'windows1253':
  11773. return 'windows-1253';
  11774. case 'csisolatin5':
  11775. case 'iso88599':
  11776. case 'iso885991989':
  11777. case 'isoir148':
  11778. case 'l5':
  11779. case 'latin5':
  11780. case 'windows1254':
  11781. return 'windows-1254';
  11782. case 'windows1255':
  11783. return 'windows-1255';
  11784. case 'windows1256':
  11785. return 'windows-1256';
  11786. case 'windows1257':
  11787. return 'windows-1257';
  11788. case 'windows1258':
  11789. return 'windows-1258';
  11790. default:
  11791. return $charset;
  11792. }
  11793. }
  11794. public static function get_curl_version()
  11795. {
  11796. if (is_array($curl = curl_version()))
  11797. {
  11798. $curl = $curl['version'];
  11799. }
  11800. elseif (substr($curl, 0, 5) === 'curl/')
  11801. {
  11802. $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
  11803. }
  11804. elseif (substr($curl, 0, 8) === 'libcurl/')
  11805. {
  11806. $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
  11807. }
  11808. else
  11809. {
  11810. $curl = 0;
  11811. }
  11812. return $curl;
  11813. }
  11814. /**
  11815. * Strip HTML comments
  11816. *
  11817. * @param string $data Data to strip comments from
  11818. * @return string Comment stripped string
  11819. */
  11820. public static function strip_comments($data)
  11821. {
  11822. $output = '';
  11823. while (($start = strpos($data, '<!--')) !== false)
  11824. {
  11825. $output .= substr($data, 0, $start);
  11826. if (($end = strpos($data, '-->', $start)) !== false)
  11827. {
  11828. $data = substr_replace($data, '', 0, $end + 3);
  11829. }
  11830. else
  11831. {
  11832. $data = '';
  11833. }
  11834. }
  11835. return $output . $data;
  11836. }
  11837. public static function parse_date($dt)
  11838. {
  11839. $parser = SimplePie_Parse_Date::get();
  11840. return $parser->parse($dt);
  11841. }
  11842. /**
  11843. * Decode HTML entities
  11844. *
  11845. * @deprecated Use DOMDocument instead
  11846. * @param string $data Input data
  11847. * @return string Output data
  11848. */
  11849. public static function entities_decode($data)
  11850. {
  11851. $decoder = new SimplePie_Decode_HTML_Entities($data);
  11852. return $decoder->parse();
  11853. }
  11854. /**
  11855. * Remove RFC822 comments
  11856. *
  11857. * @param string $data Data to strip comments from
  11858. * @return string Comment stripped string
  11859. */
  11860. public static function uncomment_rfc822($string)
  11861. {
  11862. $string = (string) $string;
  11863. $position = 0;
  11864. $length = strlen($string);
  11865. $depth = 0;
  11866. $output = '';
  11867. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  11868. {
  11869. $output .= substr($string, $position, $pos - $position);
  11870. $position = $pos + 1;
  11871. if ($string[$pos - 1] !== '\\')
  11872. {
  11873. $depth++;
  11874. while ($depth && $position < $length)
  11875. {
  11876. $position += strcspn($string, '()', $position);
  11877. if ($string[$position - 1] === '\\')
  11878. {
  11879. $position++;
  11880. continue;
  11881. }
  11882. elseif (isset($string[$position]))
  11883. {
  11884. switch ($string[$position])
  11885. {
  11886. case '(':
  11887. $depth++;
  11888. break;
  11889. case ')':
  11890. $depth--;
  11891. break;
  11892. }
  11893. $position++;
  11894. }
  11895. else
  11896. {
  11897. break;
  11898. }
  11899. }
  11900. }
  11901. else
  11902. {
  11903. $output .= '(';
  11904. }
  11905. }
  11906. $output .= substr($string, $position);
  11907. return $output;
  11908. }
  11909. public static function parse_mime($mime)
  11910. {
  11911. if (($pos = strpos($mime, ';')) === false)
  11912. {
  11913. return trim($mime);
  11914. }
  11915. else
  11916. {
  11917. return trim(substr($mime, 0, $pos));
  11918. }
  11919. }
  11920. public static function atom_03_construct_type($attribs)
  11921. {
  11922. if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64'))
  11923. {
  11924. $mode = SIMPLEPIE_CONSTRUCT_BASE64;
  11925. }
  11926. else
  11927. {
  11928. $mode = SIMPLEPIE_CONSTRUCT_NONE;
  11929. }
  11930. if (isset($attribs['']['type']))
  11931. {
  11932. switch (strtolower(trim($attribs['']['type'])))
  11933. {
  11934. case 'text':
  11935. case 'text/plain':
  11936. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  11937. case 'html':
  11938. case 'text/html':
  11939. return SIMPLEPIE_CONSTRUCT_HTML | $mode;
  11940. case 'xhtml':
  11941. case 'application/xhtml+xml':
  11942. return SIMPLEPIE_CONSTRUCT_XHTML | $mode;
  11943. default:
  11944. return SIMPLEPIE_CONSTRUCT_NONE | $mode;
  11945. }
  11946. }
  11947. else
  11948. {
  11949. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  11950. }
  11951. }
  11952. public static function atom_10_construct_type($attribs)
  11953. {
  11954. if (isset($attribs['']['type']))
  11955. {
  11956. switch (strtolower(trim($attribs['']['type'])))
  11957. {
  11958. case 'text':
  11959. return SIMPLEPIE_CONSTRUCT_TEXT;
  11960. case 'html':
  11961. return SIMPLEPIE_CONSTRUCT_HTML;
  11962. case 'xhtml':
  11963. return SIMPLEPIE_CONSTRUCT_XHTML;
  11964. default:
  11965. return SIMPLEPIE_CONSTRUCT_NONE;
  11966. }
  11967. }
  11968. return SIMPLEPIE_CONSTRUCT_TEXT;
  11969. }
  11970. public static function atom_10_content_construct_type($attribs)
  11971. {
  11972. if (isset($attribs['']['type']))
  11973. {
  11974. $type = strtolower(trim($attribs['']['type']));
  11975. switch ($type)
  11976. {
  11977. case 'text':
  11978. return SIMPLEPIE_CONSTRUCT_TEXT;
  11979. case 'html':
  11980. return SIMPLEPIE_CONSTRUCT_HTML;
  11981. case 'xhtml':
  11982. return SIMPLEPIE_CONSTRUCT_XHTML;
  11983. }
  11984. if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/')
  11985. {
  11986. return SIMPLEPIE_CONSTRUCT_NONE;
  11987. }
  11988. else
  11989. {
  11990. return SIMPLEPIE_CONSTRUCT_BASE64;
  11991. }
  11992. }
  11993. else
  11994. {
  11995. return SIMPLEPIE_CONSTRUCT_TEXT;
  11996. }
  11997. }
  11998. public static function is_isegment_nz_nc($string)
  11999. {
  12000. 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);
  12001. }
  12002. public static function space_seperated_tokens($string)
  12003. {
  12004. $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
  12005. $string_length = strlen($string);
  12006. $position = strspn($string, $space_characters);
  12007. $tokens = array();
  12008. while ($position < $string_length)
  12009. {
  12010. $len = strcspn($string, $space_characters, $position);
  12011. $tokens[] = substr($string, $position, $len);
  12012. $position += $len;
  12013. $position += strspn($string, $space_characters, $position);
  12014. }
  12015. return $tokens;
  12016. }
  12017. /**
  12018. * Converts a unicode codepoint to a UTF-8 character
  12019. *
  12020. * @static
  12021. * @param int $codepoint Unicode codepoint
  12022. * @return string UTF-8 character
  12023. */
  12024. public static function codepoint_to_utf8($codepoint)
  12025. {
  12026. $codepoint = (int) $codepoint;
  12027. if ($codepoint < 0)
  12028. {
  12029. return false;
  12030. }
  12031. else if ($codepoint <= 0x7f)
  12032. {
  12033. return chr($codepoint);
  12034. }
  12035. else if ($codepoint <= 0x7ff)
  12036. {
  12037. return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
  12038. }
  12039. else if ($codepoint <= 0xffff)
  12040. {
  12041. return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  12042. }
  12043. else if ($codepoint <= 0x10ffff)
  12044. {
  12045. return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  12046. }
  12047. else
  12048. {
  12049. // U+FFFD REPLACEMENT CHARACTER
  12050. return "\xEF\xBF\xBD";
  12051. }
  12052. }
  12053. /**
  12054. * Similar to parse_str()
  12055. *
  12056. * Returns an associative array of name/value pairs, where the value is an
  12057. * array of values that have used the same name
  12058. *
  12059. * @static
  12060. * @param string $str The input string.
  12061. * @return array
  12062. */
  12063. public static function parse_str($str)
  12064. {
  12065. $return = array();
  12066. $str = explode('&', $str);
  12067. foreach ($str as $section)
  12068. {
  12069. if (strpos($section, '=') !== false)
  12070. {
  12071. list($name, $value) = explode('=', $section, 2);
  12072. $return[urldecode($name)][] = urldecode($value);
  12073. }
  12074. else
  12075. {
  12076. $return[urldecode($section)][] = null;
  12077. }
  12078. }
  12079. return $return;
  12080. }
  12081. /**
  12082. * Detect XML encoding, as per XML 1.0 Appendix F.1
  12083. *
  12084. * @todo Add support for EBCDIC
  12085. * @param string $data XML data
  12086. * @param SimplePie_Registry $registry Class registry
  12087. * @return array Possible encodings
  12088. */
  12089. public static function xml_encoding($data, $registry)
  12090. {
  12091. // UTF-32 Big Endian BOM
  12092. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  12093. {
  12094. $encoding[] = 'UTF-32BE';
  12095. }
  12096. // UTF-32 Little Endian BOM
  12097. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  12098. {
  12099. $encoding[] = 'UTF-32LE';
  12100. }
  12101. // UTF-16 Big Endian BOM
  12102. elseif (substr($data, 0, 2) === "\xFE\xFF")
  12103. {
  12104. $encoding[] = 'UTF-16BE';
  12105. }
  12106. // UTF-16 Little Endian BOM
  12107. elseif (substr($data, 0, 2) === "\xFF\xFE")
  12108. {
  12109. $encoding[] = 'UTF-16LE';
  12110. }
  12111. // UTF-8 BOM
  12112. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  12113. {
  12114. $encoding[] = 'UTF-8';
  12115. }
  12116. // UTF-32 Big Endian Without BOM
  12117. 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")
  12118. {
  12119. if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
  12120. {
  12121. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')));
  12122. if ($parser->parse())
  12123. {
  12124. $encoding[] = $parser->encoding;
  12125. }
  12126. }
  12127. $encoding[] = 'UTF-32BE';
  12128. }
  12129. // UTF-32 Little Endian Without BOM
  12130. 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")
  12131. {
  12132. if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
  12133. {
  12134. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')));
  12135. if ($parser->parse())
  12136. {
  12137. $encoding[] = $parser->encoding;
  12138. }
  12139. }
  12140. $encoding[] = 'UTF-32LE';
  12141. }
  12142. // UTF-16 Big Endian Without BOM
  12143. elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
  12144. {
  12145. if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
  12146. {
  12147. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')));
  12148. if ($parser->parse())
  12149. {
  12150. $encoding[] = $parser->encoding;
  12151. }
  12152. }
  12153. $encoding[] = 'UTF-16BE';
  12154. }
  12155. // UTF-16 Little Endian Without BOM
  12156. elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00")
  12157. {
  12158. if ($pos = strpos($data, "\x3F\x00\x3E\x00"))
  12159. {
  12160. $parser = $registry->create('XML_Declaration_Parser', array(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')));
  12161. if ($parser->parse())
  12162. {
  12163. $encoding[] = $parser->encoding;
  12164. }
  12165. }
  12166. $encoding[] = 'UTF-16LE';
  12167. }
  12168. // US-ASCII (or superset)
  12169. elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C")
  12170. {
  12171. if ($pos = strpos($data, "\x3F\x3E"))
  12172. {
  12173. $parser = $registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  12174. if ($parser->parse())
  12175. {
  12176. $encoding[] = $parser->encoding;
  12177. }
  12178. }
  12179. $encoding[] = 'UTF-8';
  12180. }
  12181. // Fallback to UTF-8
  12182. else
  12183. {
  12184. $encoding[] = 'UTF-8';
  12185. }
  12186. return $encoding;
  12187. }
  12188. public static function output_javascript()
  12189. {
  12190. if (function_exists('ob_gzhandler'))
  12191. {
  12192. ob_start('ob_gzhandler');
  12193. }
  12194. header('Content-type: text/javascript; charset: UTF-8');
  12195. header('Cache-Control: must-revalidate');
  12196. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
  12197. ?>
  12198. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
  12199. if (placeholder != '') {
  12200. 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>');
  12201. }
  12202. else {
  12203. 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>');
  12204. }
  12205. }
  12206. function embed_flash(bgcolor, width, height, link, loop, type) {
  12207. 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>');
  12208. }
  12209. function embed_flv(width, height, link, placeholder, loop, player) {
  12210. 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>');
  12211. }
  12212. function embed_wmedia(width, height, link) {
  12213. document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
  12214. }
  12215. <?php
  12216. }
  12217. /**
  12218. * Get the SimplePie build timestamp
  12219. *
  12220. * Uses the git index if it exists, otherwise uses the modification time
  12221. * of the newest file.
  12222. */
  12223. public static function get_build()
  12224. {
  12225. $root = dirname(dirname(__FILE__));
  12226. if (file_exists($root . '/.git/index'))
  12227. {
  12228. return filemtime($root . '/.git/index');
  12229. }
  12230. elseif (file_exists($root . '/SimplePie'))
  12231. {
  12232. $time = 0;
  12233. foreach (glob($root . '/SimplePie/*.php') as $file)
  12234. {
  12235. if (($mtime = filemtime($file)) > $time)
  12236. {
  12237. $time = $mtime;
  12238. }
  12239. }
  12240. return $time;
  12241. }
  12242. elseif (file_exists(dirname(__FILE__) . '/Core.php'))
  12243. {
  12244. return filemtime(dirname(__FILE__) . '/Core.php');
  12245. }
  12246. else
  12247. {
  12248. return filemtime(__FILE__);
  12249. }
  12250. }
  12251. /**
  12252. * Format debugging information
  12253. */
  12254. public static function debug(&$sp)
  12255. {
  12256. $info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
  12257. $info .= 'PHP ' . PHP_VERSION . "\n";
  12258. if ($sp->error() !== null)
  12259. {
  12260. $info .= 'Error occurred: ' . $sp->error() . "\n";
  12261. }
  12262. else
  12263. {
  12264. $info .= "No error found.\n";
  12265. }
  12266. $info .= "Extensions:\n";
  12267. $extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
  12268. foreach ($extensions as $ext)
  12269. {
  12270. if (extension_loaded($ext))
  12271. {
  12272. $info .= " $ext loaded\n";
  12273. switch ($ext)
  12274. {
  12275. case 'pcre':
  12276. $info .= ' Version ' . PCRE_VERSION . "\n";
  12277. break;
  12278. case 'curl':
  12279. $version = curl_version();
  12280. $info .= ' Version ' . $version['version'] . "\n";
  12281. break;
  12282. case 'mbstring':
  12283. $info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
  12284. break;
  12285. case 'iconv':
  12286. $info .= ' Version ' . ICONV_VERSION . "\n";
  12287. break;
  12288. case 'xml':
  12289. $info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
  12290. break;
  12291. }
  12292. }
  12293. else
  12294. {
  12295. $info .= " $ext not loaded\n";
  12296. }
  12297. }
  12298. return $info;
  12299. }
  12300. public static function silence_errors($num, $str)
  12301. {
  12302. // No-op
  12303. }
  12304. }
  12305. /**
  12306. * Date Parser
  12307. *
  12308. * @package SimplePie
  12309. * @subpackage Parsing
  12310. */
  12311. class SimplePie_Parse_Date
  12312. {
  12313. /**
  12314. * Input data
  12315. *
  12316. * @access protected
  12317. * @var string
  12318. */
  12319. var $date;
  12320. /**
  12321. * List of days, calendar day name => ordinal day number in the week
  12322. *
  12323. * @access protected
  12324. * @var array
  12325. */
  12326. var $day = array(
  12327. // English
  12328. 'mon' => 1,
  12329. 'monday' => 1,
  12330. 'tue' => 2,
  12331. 'tuesday' => 2,
  12332. 'wed' => 3,
  12333. 'wednesday' => 3,
  12334. 'thu' => 4,
  12335. 'thursday' => 4,
  12336. 'fri' => 5,
  12337. 'friday' => 5,
  12338. 'sat' => 6,
  12339. 'saturday' => 6,
  12340. 'sun' => 7,
  12341. 'sunday' => 7,
  12342. // Dutch
  12343. 'maandag' => 1,
  12344. 'dinsdag' => 2,
  12345. 'woensdag' => 3,
  12346. 'donderdag' => 4,
  12347. 'vrijdag' => 5,
  12348. 'zaterdag' => 6,
  12349. 'zondag' => 7,
  12350. // French
  12351. 'lundi' => 1,
  12352. 'mardi' => 2,
  12353. 'mercredi' => 3,
  12354. 'jeudi' => 4,
  12355. 'vendredi' => 5,
  12356. 'samedi' => 6,
  12357. 'dimanche' => 7,
  12358. // German
  12359. 'montag' => 1,
  12360. 'dienstag' => 2,
  12361. 'mittwoch' => 3,
  12362. 'donnerstag' => 4,
  12363. 'freitag' => 5,
  12364. 'samstag' => 6,
  12365. 'sonnabend' => 6,
  12366. 'sonntag' => 7,
  12367. // Italian
  12368. 'lunedì' => 1,
  12369. 'martedì' => 2,
  12370. 'mercoledì' => 3,
  12371. 'giovedì' => 4,
  12372. 'venerdì' => 5,
  12373. 'sabato' => 6,
  12374. 'domenica' => 7,
  12375. // Spanish
  12376. 'lunes' => 1,
  12377. 'martes' => 2,
  12378. 'miércoles' => 3,
  12379. 'jueves' => 4,
  12380. 'viernes' => 5,
  12381. 'sábado' => 6,
  12382. 'domingo' => 7,
  12383. // Finnish
  12384. 'maanantai' => 1,
  12385. 'tiistai' => 2,
  12386. 'keskiviikko' => 3,
  12387. 'torstai' => 4,
  12388. 'perjantai' => 5,
  12389. 'lauantai' => 6,
  12390. 'sunnuntai' => 7,
  12391. // Hungarian
  12392. 'hétfő' => 1,
  12393. 'kedd' => 2,
  12394. 'szerda' => 3,
  12395. 'csütörtok' => 4,
  12396. 'péntek' => 5,
  12397. 'szombat' => 6,
  12398. 'vasárnap' => 7,
  12399. // Greek
  12400. 'Δευ' => 1,
  12401. 'Τρι' => 2,
  12402. 'Τετ' => 3,
  12403. 'Πεμ' => 4,
  12404. 'Παρ' => 5,
  12405. 'Σαβ' => 6,
  12406. 'Κυρ' => 7,
  12407. );
  12408. /**
  12409. * List of months, calendar month name => calendar month number
  12410. *
  12411. * @access protected
  12412. * @var array
  12413. */
  12414. var $month = array(
  12415. // English
  12416. 'jan' => 1,
  12417. 'january' => 1,
  12418. 'feb' => 2,
  12419. 'february' => 2,
  12420. 'mar' => 3,
  12421. 'march' => 3,
  12422. 'apr' => 4,
  12423. 'april' => 4,
  12424. 'may' => 5,
  12425. // No long form of May
  12426. 'jun' => 6,
  12427. 'june' => 6,
  12428. 'jul' => 7,
  12429. 'july' => 7,
  12430. 'aug' => 8,
  12431. 'august' => 8,
  12432. 'sep' => 9,
  12433. 'september' => 8,
  12434. 'oct' => 10,
  12435. 'october' => 10,
  12436. 'nov' => 11,
  12437. 'november' => 11,
  12438. 'dec' => 12,
  12439. 'december' => 12,
  12440. // Dutch
  12441. 'januari' => 1,
  12442. 'februari' => 2,
  12443. 'maart' => 3,
  12444. 'april' => 4,
  12445. 'mei' => 5,
  12446. 'juni' => 6,
  12447. 'juli' => 7,
  12448. 'augustus' => 8,
  12449. 'september' => 9,
  12450. 'oktober' => 10,
  12451. 'november' => 11,
  12452. 'december' => 12,
  12453. // French
  12454. 'janvier' => 1,
  12455. 'février' => 2,
  12456. 'mars' => 3,
  12457. 'avril' => 4,
  12458. 'mai' => 5,
  12459. 'juin' => 6,
  12460. 'juillet' => 7,
  12461. 'août' => 8,
  12462. 'septembre' => 9,
  12463. 'octobre' => 10,
  12464. 'novembre' => 11,
  12465. 'décembre' => 12,
  12466. // German
  12467. 'januar' => 1,
  12468. 'februar' => 2,
  12469. 'märz' => 3,
  12470. 'april' => 4,
  12471. 'mai' => 5,
  12472. 'juni' => 6,
  12473. 'juli' => 7,
  12474. 'august' => 8,
  12475. 'september' => 9,
  12476. 'oktober' => 10,
  12477. 'november' => 11,
  12478. 'dezember' => 12,
  12479. // Italian
  12480. 'gennaio' => 1,
  12481. 'febbraio' => 2,
  12482. 'marzo' => 3,
  12483. 'aprile' => 4,
  12484. 'maggio' => 5,
  12485. 'giugno' => 6,
  12486. 'luglio' => 7,
  12487. 'agosto' => 8,
  12488. 'settembre' => 9,
  12489. 'ottobre' => 10,
  12490. 'novembre' => 11,
  12491. 'dicembre' => 12,
  12492. // Spanish
  12493. 'enero' => 1,
  12494. 'febrero' => 2,
  12495. 'marzo' => 3,
  12496. 'abril' => 4,
  12497. 'mayo' => 5,
  12498. 'junio' => 6,
  12499. 'julio' => 7,
  12500. 'agosto' => 8,
  12501. 'septiembre' => 9,
  12502. 'setiembre' => 9,
  12503. 'octubre' => 10,
  12504. 'noviembre' => 11,
  12505. 'diciembre' => 12,
  12506. // Finnish
  12507. 'tammikuu' => 1,
  12508. 'helmikuu' => 2,
  12509. 'maaliskuu' => 3,
  12510. 'huhtikuu' => 4,
  12511. 'toukokuu' => 5,
  12512. 'kesäkuu' => 6,
  12513. 'heinäkuu' => 7,
  12514. 'elokuu' => 8,
  12515. 'suuskuu' => 9,
  12516. 'lokakuu' => 10,
  12517. 'marras' => 11,
  12518. 'joulukuu' => 12,
  12519. // Hungarian
  12520. 'január' => 1,
  12521. 'február' => 2,
  12522. 'március' => 3,
  12523. 'április' => 4,
  12524. 'május' => 5,
  12525. 'június' => 6,
  12526. 'július' => 7,
  12527. 'augusztus' => 8,
  12528. 'szeptember' => 9,
  12529. 'október' => 10,
  12530. 'november' => 11,
  12531. 'december' => 12,
  12532. // Greek
  12533. 'Ιαν' => 1,
  12534. 'Φεβ' => 2,
  12535. 'Μάώ' => 3,
  12536. 'Μαώ' => 3,
  12537. 'Απρ' => 4,
  12538. 'Μάι' => 5,
  12539. 'Μαϊ' => 5,
  12540. 'Μαι' => 5,
  12541. 'Ιούν' => 6,
  12542. 'Ιον' => 6,
  12543. 'Ιούλ' => 7,
  12544. 'Ιολ' => 7,
  12545. 'Αύγ' => 8,
  12546. 'Αυγ' => 8,
  12547. 'Σεπ' => 9,
  12548. 'Οκτ' => 10,
  12549. 'Νοέ' => 11,
  12550. 'Δεκ' => 12,
  12551. );
  12552. /**
  12553. * List of timezones, abbreviation => offset from UTC
  12554. *
  12555. * @access protected
  12556. * @var array
  12557. */
  12558. var $timezone = array(
  12559. 'ACDT' => 37800,
  12560. 'ACIT' => 28800,
  12561. 'ACST' => 34200,
  12562. 'ACT' => -18000,
  12563. 'ACWDT' => 35100,
  12564. 'ACWST' => 31500,
  12565. 'AEDT' => 39600,
  12566. 'AEST' => 36000,
  12567. 'AFT' => 16200,
  12568. 'AKDT' => -28800,
  12569. 'AKST' => -32400,
  12570. 'AMDT' => 18000,
  12571. 'AMT' => -14400,
  12572. 'ANAST' => 46800,
  12573. 'ANAT' => 43200,
  12574. 'ART' => -10800,
  12575. 'AZOST' => -3600,
  12576. 'AZST' => 18000,
  12577. 'AZT' => 14400,
  12578. 'BIOT' => 21600,
  12579. 'BIT' => -43200,
  12580. 'BOT' => -14400,
  12581. 'BRST' => -7200,
  12582. 'BRT' => -10800,
  12583. 'BST' => 3600,
  12584. 'BTT' => 21600,
  12585. 'CAST' => 18000,
  12586. 'CAT' => 7200,
  12587. 'CCT' => 23400,
  12588. 'CDT' => -18000,
  12589. 'CEDT' => 7200,
  12590. 'CET' => 3600,
  12591. 'CGST' => -7200,
  12592. 'CGT' => -10800,
  12593. 'CHADT' => 49500,
  12594. 'CHAST' => 45900,
  12595. 'CIST' => -28800,
  12596. 'CKT' => -36000,
  12597. 'CLDT' => -10800,
  12598. 'CLST' => -14400,
  12599. 'COT' => -18000,
  12600. 'CST' => -21600,
  12601. 'CVT' => -3600,
  12602. 'CXT' => 25200,
  12603. 'DAVT' => 25200,
  12604. 'DTAT' => 36000,
  12605. 'EADT' => -18000,
  12606. 'EAST' => -21600,
  12607. 'EAT' => 10800,
  12608. 'ECT' => -18000,
  12609. 'EDT' => -14400,
  12610. 'EEST' => 10800,
  12611. 'EET' => 7200,
  12612. 'EGT' => -3600,
  12613. 'EKST' => 21600,
  12614. 'EST' => -18000,
  12615. 'FJT' => 43200,
  12616. 'FKDT' => -10800,
  12617. 'FKST' => -14400,
  12618. 'FNT' => -7200,
  12619. 'GALT' => -21600,
  12620. 'GEDT' => 14400,
  12621. 'GEST' => 10800,
  12622. 'GFT' => -10800,
  12623. 'GILT' => 43200,
  12624. 'GIT' => -32400,
  12625. 'GST' => 14400,
  12626. 'GST' => -7200,
  12627. 'GYT' => -14400,
  12628. 'HAA' => -10800,
  12629. 'HAC' => -18000,
  12630. 'HADT' => -32400,
  12631. 'HAE' => -14400,
  12632. 'HAP' => -25200,
  12633. 'HAR' => -21600,
  12634. 'HAST' => -36000,
  12635. 'HAT' => -9000,
  12636. 'HAY' => -28800,
  12637. 'HKST' => 28800,
  12638. 'HMT' => 18000,
  12639. 'HNA' => -14400,
  12640. 'HNC' => -21600,
  12641. 'HNE' => -18000,
  12642. 'HNP' => -28800,
  12643. 'HNR' => -25200,
  12644. 'HNT' => -12600,
  12645. 'HNY' => -32400,
  12646. 'IRDT' => 16200,
  12647. 'IRKST' => 32400,
  12648. 'IRKT' => 28800,
  12649. 'IRST' => 12600,
  12650. 'JFDT' => -10800,
  12651. 'JFST' => -14400,
  12652. 'JST' => 32400,
  12653. 'KGST' => 21600,
  12654. 'KGT' => 18000,
  12655. 'KOST' => 39600,
  12656. 'KOVST' => 28800,
  12657. 'KOVT' => 25200,
  12658. 'KRAST' => 28800,
  12659. 'KRAT' => 25200,
  12660. 'KST' => 32400,
  12661. 'LHDT' => 39600,
  12662. 'LHST' => 37800,
  12663. 'LINT' => 50400,
  12664. 'LKT' => 21600,
  12665. 'MAGST' => 43200,
  12666. 'MAGT' => 39600,
  12667. 'MAWT' => 21600,
  12668. 'MDT' => -21600,
  12669. 'MESZ' => 7200,
  12670. 'MEZ' => 3600,
  12671. 'MHT' => 43200,
  12672. 'MIT' => -34200,
  12673. 'MNST' => 32400,
  12674. 'MSDT' => 14400,
  12675. 'MSST' => 10800,
  12676. 'MST' => -25200,
  12677. 'MUT' => 14400,
  12678. 'MVT' => 18000,
  12679. 'MYT' => 28800,
  12680. 'NCT' => 39600,
  12681. 'NDT' => -9000,
  12682. 'NFT' => 41400,
  12683. 'NMIT' => 36000,
  12684. 'NOVST' => 25200,
  12685. 'NOVT' => 21600,
  12686. 'NPT' => 20700,
  12687. 'NRT' => 43200,
  12688. 'NST' => -12600,
  12689. 'NUT' => -39600,
  12690. 'NZDT' => 46800,
  12691. 'NZST' => 43200,
  12692. 'OMSST' => 25200,
  12693. 'OMST' => 21600,
  12694. 'PDT' => -25200,
  12695. 'PET' => -18000,
  12696. 'PETST' => 46800,
  12697. 'PETT' => 43200,
  12698. 'PGT' => 36000,
  12699. 'PHOT' => 46800,
  12700. 'PHT' => 28800,
  12701. 'PKT' => 18000,
  12702. 'PMDT' => -7200,
  12703. 'PMST' => -10800,
  12704. 'PONT' => 39600,
  12705. 'PST' => -28800,
  12706. 'PWT' => 32400,
  12707. 'PYST' => -10800,
  12708. 'PYT' => -14400,
  12709. 'RET' => 14400,
  12710. 'ROTT' => -10800,
  12711. 'SAMST' => 18000,
  12712. 'SAMT' => 14400,
  12713. 'SAST' => 7200,
  12714. 'SBT' => 39600,
  12715. 'SCDT' => 46800,
  12716. 'SCST' => 43200,
  12717. 'SCT' => 14400,
  12718. 'SEST' => 3600,
  12719. 'SGT' => 28800,
  12720. 'SIT' => 28800,
  12721. 'SRT' => -10800,
  12722. 'SST' => -39600,
  12723. 'SYST' => 10800,
  12724. 'SYT' => 7200,
  12725. 'TFT' => 18000,
  12726. 'THAT' => -36000,
  12727. 'TJT' => 18000,
  12728. 'TKT' => -36000,
  12729. 'TMT' => 18000,
  12730. 'TOT' => 46800,
  12731. 'TPT' => 32400,
  12732. 'TRUT' => 36000,
  12733. 'TVT' => 43200,
  12734. 'TWT' => 28800,
  12735. 'UYST' => -7200,
  12736. 'UYT' => -10800,
  12737. 'UZT' => 18000,
  12738. 'VET' => -14400,
  12739. 'VLAST' => 39600,
  12740. 'VLAT' => 36000,
  12741. 'VOST' => 21600,
  12742. 'VUT' => 39600,
  12743. 'WAST' => 7200,
  12744. 'WAT' => 3600,
  12745. 'WDT' => 32400,
  12746. 'WEST' => 3600,
  12747. 'WFT' => 43200,
  12748. 'WIB' => 25200,
  12749. 'WIT' => 32400,
  12750. 'WITA' => 28800,
  12751. 'WKST' => 18000,
  12752. 'WST' => 28800,
  12753. 'YAKST' => 36000,
  12754. 'YAKT' => 32400,
  12755. 'YAPT' => 36000,
  12756. 'YEKST' => 21600,
  12757. 'YEKT' => 18000,
  12758. );
  12759. /**
  12760. * Cached PCRE for SimplePie_Parse_Date::$day
  12761. *
  12762. * @access protected
  12763. * @var string
  12764. */
  12765. var $day_pcre;
  12766. /**
  12767. * Cached PCRE for SimplePie_Parse_Date::$month
  12768. *
  12769. * @access protected
  12770. * @var string
  12771. */
  12772. var $month_pcre;
  12773. /**
  12774. * Array of user-added callback methods
  12775. *
  12776. * @access private
  12777. * @var array
  12778. */
  12779. var $built_in = array();
  12780. /**
  12781. * Array of user-added callback methods
  12782. *
  12783. * @access private
  12784. * @var array
  12785. */
  12786. var $user = array();
  12787. /**
  12788. * Create new SimplePie_Parse_Date object, and set self::day_pcre,
  12789. * self::month_pcre, and self::built_in
  12790. *
  12791. * @access private
  12792. */
  12793. public function __construct()
  12794. {
  12795. $this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
  12796. $this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
  12797. static $cache;
  12798. if (!isset($cache[get_class($this)]))
  12799. {
  12800. $all_methods = get_class_methods($this);
  12801. foreach ($all_methods as $method)
  12802. {
  12803. if (strtolower(substr($method, 0, 5)) === 'date_')
  12804. {
  12805. $cache[get_class($this)][] = $method;
  12806. }
  12807. }
  12808. }
  12809. foreach ($cache[get_class($this)] as $method)
  12810. {
  12811. $this->built_in[] = $method;
  12812. }
  12813. }
  12814. /**
  12815. * Get the object
  12816. *
  12817. * @access public
  12818. */
  12819. public static function get()
  12820. {
  12821. static $object;
  12822. if (!$object)
  12823. {
  12824. $object = new SimplePie_Parse_Date;
  12825. }
  12826. return $object;
  12827. }
  12828. /**
  12829. * Parse a date
  12830. *
  12831. * @final
  12832. * @access public
  12833. * @param string $date Date to parse
  12834. * @return int Timestamp corresponding to date string, or false on failure
  12835. */
  12836. public function parse($date)
  12837. {
  12838. foreach ($this->user as $method)
  12839. {
  12840. if (($returned = call_user_func($method, $date)) !== false)
  12841. {
  12842. return $returned;
  12843. }
  12844. }
  12845. foreach ($this->built_in as $method)
  12846. {
  12847. if (($returned = call_user_func(array($this, $method), $date)) !== false)
  12848. {
  12849. return $returned;
  12850. }
  12851. }
  12852. return false;
  12853. }
  12854. /**
  12855. * Add a callback method to parse a date
  12856. *
  12857. * @final
  12858. * @access public
  12859. * @param callback $callback
  12860. */
  12861. public function add_callback($callback)
  12862. {
  12863. if (is_callable($callback))
  12864. {
  12865. $this->user[] = $callback;
  12866. }
  12867. else
  12868. {
  12869. trigger_error('User-supplied function must be a valid callback', E_USER_WARNING);
  12870. }
  12871. }
  12872. /**
  12873. * Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
  12874. * well as allowing any of upper or lower case "T", horizontal tabs, or
  12875. * spaces to be used as the time seperator (including more than one))
  12876. *
  12877. * @access protected
  12878. * @return int Timestamp
  12879. */
  12880. public function date_w3cdtf($date)
  12881. {
  12882. static $pcre;
  12883. if (!$pcre)
  12884. {
  12885. $year = '([0-9]{4})';
  12886. $month = $day = $hour = $minute = $second = '([0-9]{2})';
  12887. $decimal = '([0-9]*)';
  12888. $zone = '(?:(Z)|([+\-])([0-9]{1,2}):?([0-9]{1,2}))';
  12889. $pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\x09\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
  12890. }
  12891. if (preg_match($pcre, $date, $match))
  12892. {
  12893. /*
  12894. Capturing subpatterns:
  12895. 1: Year
  12896. 2: Month
  12897. 3: Day
  12898. 4: Hour
  12899. 5: Minute
  12900. 6: Second
  12901. 7: Decimal fraction of a second
  12902. 8: Zulu
  12903. 9: Timezone ±
  12904. 10: Timezone hours
  12905. 11: Timezone minutes
  12906. */
  12907. // Fill in empty matches
  12908. for ($i = count($match); $i <= 3; $i++)
  12909. {
  12910. $match[$i] = '1';
  12911. }
  12912. for ($i = count($match); $i <= 7; $i++)
  12913. {
  12914. $match[$i] = '0';
  12915. }
  12916. // Numeric timezone
  12917. if (isset($match[9]) && $match[9] !== '')
  12918. {
  12919. $timezone = $match[10] * 3600;
  12920. $timezone += $match[11] * 60;
  12921. if ($match[9] === '-')
  12922. {
  12923. $timezone = 0 - $timezone;
  12924. }
  12925. }
  12926. else
  12927. {
  12928. $timezone = 0;
  12929. }
  12930. // Convert the number of seconds to an integer, taking decimals into account
  12931. $second = round($match[6] + $match[7] / pow(10, strlen($match[7])));
  12932. return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
  12933. }
  12934. else
  12935. {
  12936. return false;
  12937. }
  12938. }
  12939. /**
  12940. * Remove RFC822 comments
  12941. *
  12942. * @access protected
  12943. * @param string $data Data to strip comments from
  12944. * @return string Comment stripped string
  12945. */
  12946. public function remove_rfc2822_comments($string)
  12947. {
  12948. $string = (string) $string;
  12949. $position = 0;
  12950. $length = strlen($string);
  12951. $depth = 0;
  12952. $output = '';
  12953. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  12954. {
  12955. $output .= substr($string, $position, $pos - $position);
  12956. $position = $pos + 1;
  12957. if ($string[$pos - 1] !== '\\')
  12958. {
  12959. $depth++;
  12960. while ($depth && $position < $length)
  12961. {
  12962. $position += strcspn($string, '()', $position);
  12963. if ($string[$position - 1] === '\\')
  12964. {
  12965. $position++;
  12966. continue;
  12967. }
  12968. elseif (isset($string[$position]))
  12969. {
  12970. switch ($string[$position])
  12971. {
  12972. case '(':
  12973. $depth++;
  12974. break;
  12975. case ')':
  12976. $depth--;
  12977. break;
  12978. }
  12979. $position++;
  12980. }
  12981. else
  12982. {
  12983. break;
  12984. }
  12985. }
  12986. }
  12987. else
  12988. {
  12989. $output .= '(';
  12990. }
  12991. }
  12992. $output .= substr($string, $position);
  12993. return $output;
  12994. }
  12995. /**
  12996. * Parse RFC2822's date format
  12997. *
  12998. * @access protected
  12999. * @return int Timestamp
  13000. */
  13001. public function date_rfc2822($date)
  13002. {
  13003. static $pcre;
  13004. if (!$pcre)
  13005. {
  13006. $wsp = '[\x09\x20]';
  13007. $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
  13008. $optional_fws = $fws . '?';
  13009. $day_name = $this->day_pcre;
  13010. $month = $this->month_pcre;
  13011. $day = '([0-9]{1,2})';
  13012. $hour = $minute = $second = '([0-9]{2})';
  13013. $year = '([0-9]{2,4})';
  13014. $num_zone = '([+\-])([0-9]{2})([0-9]{2})';
  13015. $character_zone = '([A-Z]{1,5})';
  13016. $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
  13017. $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';
  13018. }
  13019. if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
  13020. {
  13021. /*
  13022. Capturing subpatterns:
  13023. 1: Day name
  13024. 2: Day
  13025. 3: Month
  13026. 4: Year
  13027. 5: Hour
  13028. 6: Minute
  13029. 7: Second
  13030. 8: Timezone ±
  13031. 9: Timezone hours
  13032. 10: Timezone minutes
  13033. 11: Alphabetic timezone
  13034. */
  13035. // Find the month number
  13036. $month = $this->month[strtolower($match[3])];
  13037. // Numeric timezone
  13038. if ($match[8] !== '')
  13039. {
  13040. $timezone = $match[9] * 3600;
  13041. $timezone += $match[10] * 60;
  13042. if ($match[8] === '-')
  13043. {
  13044. $timezone = 0 - $timezone;
  13045. }
  13046. }
  13047. // Character timezone
  13048. elseif (isset($this->timezone[strtoupper($match[11])]))
  13049. {
  13050. $timezone = $this->timezone[strtoupper($match[11])];
  13051. }
  13052. // Assume everything else to be -0000
  13053. else
  13054. {
  13055. $timezone = 0;
  13056. }
  13057. // Deal with 2/3 digit years
  13058. if ($match[4] < 50)
  13059. {
  13060. $match[4] += 2000;
  13061. }
  13062. elseif ($match[4] < 1000)
  13063. {
  13064. $match[4] += 1900;
  13065. }
  13066. // Second is optional, if it is empty set it to zero
  13067. if ($match[7] !== '')
  13068. {
  13069. $second = $match[7];
  13070. }
  13071. else
  13072. {
  13073. $second = 0;
  13074. }
  13075. return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
  13076. }
  13077. else
  13078. {
  13079. return false;
  13080. }
  13081. }
  13082. /**
  13083. * Parse RFC850's date format
  13084. *
  13085. * @access protected
  13086. * @return int Timestamp
  13087. */
  13088. public function date_rfc850($date)
  13089. {
  13090. static $pcre;
  13091. if (!$pcre)
  13092. {
  13093. $space = '[\x09\x20]+';
  13094. $day_name = $this->day_pcre;
  13095. $month = $this->month_pcre;
  13096. $day = '([0-9]{1,2})';
  13097. $year = $hour = $minute = $second = '([0-9]{2})';
  13098. $zone = '([A-Z]{1,5})';
  13099. $pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
  13100. }
  13101. if (preg_match($pcre, $date, $match))
  13102. {
  13103. /*
  13104. Capturing subpatterns:
  13105. 1: Day name
  13106. 2: Day
  13107. 3: Month
  13108. 4: Year
  13109. 5: Hour
  13110. 6: Minute
  13111. 7: Second
  13112. 8: Timezone
  13113. */
  13114. // Month
  13115. $month = $this->month[strtolower($match[3])];
  13116. // Character timezone
  13117. if (isset($this->timezone[strtoupper($match[8])]))
  13118. {
  13119. $timezone = $this->timezone[strtoupper($match[8])];
  13120. }
  13121. // Assume everything else to be -0000
  13122. else
  13123. {
  13124. $timezone = 0;
  13125. }
  13126. // Deal with 2 digit year
  13127. if ($match[4] < 50)
  13128. {
  13129. $match[4] += 2000;
  13130. }
  13131. else
  13132. {
  13133. $match[4] += 1900;
  13134. }
  13135. return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
  13136. }
  13137. else
  13138. {
  13139. return false;
  13140. }
  13141. }
  13142. /**
  13143. * Parse C99's asctime()'s date format
  13144. *
  13145. * @access protected
  13146. * @return int Timestamp
  13147. */
  13148. public function date_asctime($date)
  13149. {
  13150. static $pcre;
  13151. if (!$pcre)
  13152. {
  13153. $space = '[\x09\x20]+';
  13154. $wday_name = $this->day_pcre;
  13155. $mon_name = $this->month_pcre;
  13156. $day = '([0-9]{1,2})';
  13157. $hour = $sec = $min = '([0-9]{2})';
  13158. $year = '([0-9]{4})';
  13159. $terminator = '\x0A?\x00?';
  13160. $pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
  13161. }
  13162. if (preg_match($pcre, $date, $match))
  13163. {
  13164. /*
  13165. Capturing subpatterns:
  13166. 1: Day name
  13167. 2: Month
  13168. 3: Day
  13169. 4: Hour
  13170. 5: Minute
  13171. 6: Second
  13172. 7: Year
  13173. */
  13174. $month = $this->month[strtolower($match[2])];
  13175. return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]);
  13176. }
  13177. else
  13178. {
  13179. return false;
  13180. }
  13181. }
  13182. /**
  13183. * Parse dates using strtotime()
  13184. *
  13185. * @access protected
  13186. * @return int Timestamp
  13187. */
  13188. public function date_strtotime($date)
  13189. {
  13190. $strtotime = strtotime($date);
  13191. if ($strtotime === -1 || $strtotime === false)
  13192. {
  13193. return false;
  13194. }
  13195. else
  13196. {
  13197. return $strtotime;
  13198. }
  13199. }
  13200. }
  13201. /**
  13202. * Handles `<atom:source>`
  13203. *
  13204. * Used by {@see SimplePie_Item::get_source()}
  13205. *
  13206. * This class can be overloaded with {@see SimplePie::set_source_class()}
  13207. *
  13208. * @package SimplePie
  13209. * @subpackage API
  13210. */
  13211. class SimplePie_Source
  13212. {
  13213. var $item;
  13214. var $data = array();
  13215. protected $registry;
  13216. public function __construct($item, $data)
  13217. {
  13218. $this->item = $item;
  13219. $this->data = $data;
  13220. }
  13221. public function set_registry(SimplePie_Registry $registry)
  13222. {
  13223. $this->registry = $registry;
  13224. }
  13225. public function __toString()
  13226. {
  13227. return md5(serialize($this->data));
  13228. }
  13229. public function get_source_tags($namespace, $tag)
  13230. {
  13231. if (isset($this->data['child'][$namespace][$tag]))
  13232. {
  13233. return $this->data['child'][$namespace][$tag];
  13234. }
  13235. else
  13236. {
  13237. return null;
  13238. }
  13239. }
  13240. public function get_base($element = array())
  13241. {
  13242. return $this->item->get_base($element);
  13243. }
  13244. public function sanitize($data, $type, $base = '')
  13245. {
  13246. return $this->item->sanitize($data, $type, $base);
  13247. }
  13248. public function get_item()
  13249. {
  13250. return $this->item;
  13251. }
  13252. public function get_title()
  13253. {
  13254. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  13255. {
  13256. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  13257. }
  13258. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  13259. {
  13260. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  13261. }
  13262. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  13263. {
  13264. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  13265. }
  13266. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  13267. {
  13268. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  13269. }
  13270. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  13271. {
  13272. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  13273. }
  13274. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  13275. {
  13276. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13277. }
  13278. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  13279. {
  13280. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13281. }
  13282. else
  13283. {
  13284. return null;
  13285. }
  13286. }
  13287. public function get_category($key = 0)
  13288. {
  13289. $categories = $this->get_categories();
  13290. if (isset($categories[$key]))
  13291. {
  13292. return $categories[$key];
  13293. }
  13294. else
  13295. {
  13296. return null;
  13297. }
  13298. }
  13299. public function get_categories()
  13300. {
  13301. $categories = array();
  13302. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  13303. {
  13304. $term = null;
  13305. $scheme = null;
  13306. $label = null;
  13307. if (isset($category['attribs']['']['term']))
  13308. {
  13309. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  13310. }
  13311. if (isset($category['attribs']['']['scheme']))
  13312. {
  13313. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  13314. }
  13315. if (isset($category['attribs']['']['label']))
  13316. {
  13317. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  13318. }
  13319. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  13320. }
  13321. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  13322. {
  13323. // This is really the label, but keep this as the term also for BC.
  13324. // Label will also work on retrieving because that falls back to term.
  13325. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13326. if (isset($category['attribs']['']['domain']))
  13327. {
  13328. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  13329. }
  13330. else
  13331. {
  13332. $scheme = null;
  13333. }
  13334. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  13335. }
  13336. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  13337. {
  13338. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  13339. }
  13340. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  13341. {
  13342. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  13343. }
  13344. if (!empty($categories))
  13345. {
  13346. return array_unique($categories);
  13347. }
  13348. else
  13349. {
  13350. return null;
  13351. }
  13352. }
  13353. public function get_author($key = 0)
  13354. {
  13355. $authors = $this->get_authors();
  13356. if (isset($authors[$key]))
  13357. {
  13358. return $authors[$key];
  13359. }
  13360. else
  13361. {
  13362. return null;
  13363. }
  13364. }
  13365. public function get_authors()
  13366. {
  13367. $authors = array();
  13368. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  13369. {
  13370. $name = null;
  13371. $uri = null;
  13372. $email = null;
  13373. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  13374. {
  13375. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13376. }
  13377. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  13378. {
  13379. $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]));
  13380. }
  13381. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  13382. {
  13383. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13384. }
  13385. if ($name !== null || $email !== null || $uri !== null)
  13386. {
  13387. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  13388. }
  13389. }
  13390. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  13391. {
  13392. $name = null;
  13393. $url = null;
  13394. $email = null;
  13395. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  13396. {
  13397. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13398. }
  13399. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  13400. {
  13401. $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]));
  13402. }
  13403. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  13404. {
  13405. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13406. }
  13407. if ($name !== null || $email !== null || $url !== null)
  13408. {
  13409. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  13410. }
  13411. }
  13412. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  13413. {
  13414. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  13415. }
  13416. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  13417. {
  13418. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  13419. }
  13420. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  13421. {
  13422. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  13423. }
  13424. if (!empty($authors))
  13425. {
  13426. return array_unique($authors);
  13427. }
  13428. else
  13429. {
  13430. return null;
  13431. }
  13432. }
  13433. public function get_contributor($key = 0)
  13434. {
  13435. $contributors = $this->get_contributors();
  13436. if (isset($contributors[$key]))
  13437. {
  13438. return $contributors[$key];
  13439. }
  13440. else
  13441. {
  13442. return null;
  13443. }
  13444. }
  13445. public function get_contributors()
  13446. {
  13447. $contributors = array();
  13448. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  13449. {
  13450. $name = null;
  13451. $uri = null;
  13452. $email = null;
  13453. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  13454. {
  13455. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13456. }
  13457. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  13458. {
  13459. $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]));
  13460. }
  13461. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  13462. {
  13463. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13464. }
  13465. if ($name !== null || $email !== null || $uri !== null)
  13466. {
  13467. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  13468. }
  13469. }
  13470. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  13471. {
  13472. $name = null;
  13473. $url = null;
  13474. $email = null;
  13475. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  13476. {
  13477. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13478. }
  13479. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  13480. {
  13481. $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]));
  13482. }
  13483. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  13484. {
  13485. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13486. }
  13487. if ($name !== null || $email !== null || $url !== null)
  13488. {
  13489. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  13490. }
  13491. }
  13492. if (!empty($contributors))
  13493. {
  13494. return array_unique($contributors);
  13495. }
  13496. else
  13497. {
  13498. return null;
  13499. }
  13500. }
  13501. public function get_link($key = 0, $rel = 'alternate')
  13502. {
  13503. $links = $this->get_links($rel);
  13504. if (isset($links[$key]))
  13505. {
  13506. return $links[$key];
  13507. }
  13508. else
  13509. {
  13510. return null;
  13511. }
  13512. }
  13513. /**
  13514. * Added for parity between the parent-level and the item/entry-level.
  13515. */
  13516. public function get_permalink()
  13517. {
  13518. return $this->get_link(0);
  13519. }
  13520. public function get_links($rel = 'alternate')
  13521. {
  13522. if (!isset($this->data['links']))
  13523. {
  13524. $this->data['links'] = array();
  13525. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  13526. {
  13527. foreach ($links as $link)
  13528. {
  13529. if (isset($link['attribs']['']['href']))
  13530. {
  13531. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  13532. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  13533. }
  13534. }
  13535. }
  13536. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  13537. {
  13538. foreach ($links as $link)
  13539. {
  13540. if (isset($link['attribs']['']['href']))
  13541. {
  13542. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  13543. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  13544. }
  13545. }
  13546. }
  13547. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  13548. {
  13549. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  13550. }
  13551. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  13552. {
  13553. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  13554. }
  13555. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  13556. {
  13557. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  13558. }
  13559. $keys = array_keys($this->data['links']);
  13560. foreach ($keys as $key)
  13561. {
  13562. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  13563. {
  13564. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  13565. {
  13566. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  13567. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  13568. }
  13569. else
  13570. {
  13571. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  13572. }
  13573. }
  13574. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  13575. {
  13576. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  13577. }
  13578. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  13579. }
  13580. }
  13581. if (isset($this->data['links'][$rel]))
  13582. {
  13583. return $this->data['links'][$rel];
  13584. }
  13585. else
  13586. {
  13587. return null;
  13588. }
  13589. }
  13590. public function get_description()
  13591. {
  13592. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  13593. {
  13594. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  13595. }
  13596. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  13597. {
  13598. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  13599. }
  13600. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  13601. {
  13602. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  13603. }
  13604. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  13605. {
  13606. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  13607. }
  13608. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  13609. {
  13610. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  13611. }
  13612. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  13613. {
  13614. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13615. }
  13616. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  13617. {
  13618. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13619. }
  13620. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  13621. {
  13622. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  13623. }
  13624. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  13625. {
  13626. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  13627. }
  13628. else
  13629. {
  13630. return null;
  13631. }
  13632. }
  13633. public function get_copyright()
  13634. {
  13635. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  13636. {
  13637. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  13638. }
  13639. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  13640. {
  13641. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  13642. }
  13643. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  13644. {
  13645. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13646. }
  13647. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  13648. {
  13649. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13650. }
  13651. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  13652. {
  13653. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13654. }
  13655. else
  13656. {
  13657. return null;
  13658. }
  13659. }
  13660. public function get_language()
  13661. {
  13662. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  13663. {
  13664. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13665. }
  13666. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  13667. {
  13668. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13669. }
  13670. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  13671. {
  13672. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  13673. }
  13674. elseif (isset($this->data['xml_lang']))
  13675. {
  13676. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  13677. }
  13678. else
  13679. {
  13680. return null;
  13681. }
  13682. }
  13683. public function get_latitude()
  13684. {
  13685. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  13686. {
  13687. return (float) $return[0]['data'];
  13688. }
  13689. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  13690. {
  13691. return (float) $match[1];
  13692. }
  13693. else
  13694. {
  13695. return null;
  13696. }
  13697. }
  13698. public function get_longitude()
  13699. {
  13700. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  13701. {
  13702. return (float) $return[0]['data'];
  13703. }
  13704. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  13705. {
  13706. return (float) $return[0]['data'];
  13707. }
  13708. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  13709. {
  13710. return (float) $match[2];
  13711. }
  13712. else
  13713. {
  13714. return null;
  13715. }
  13716. }
  13717. public function get_image_url()
  13718. {
  13719. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  13720. {
  13721. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  13722. }
  13723. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  13724. {
  13725. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  13726. }
  13727. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  13728. {
  13729. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  13730. }
  13731. else
  13732. {
  13733. return null;
  13734. }
  13735. }
  13736. }
  13737. /**
  13738. * Parses XML into something sane
  13739. *
  13740. *
  13741. * This class can be overloaded with {@see SimplePie::set_parser_class()}
  13742. *
  13743. * @package SimplePie
  13744. * @subpackage Parsing
  13745. */
  13746. class SimplePie_Parser
  13747. {
  13748. var $error_code;
  13749. var $error_string;
  13750. var $current_line;
  13751. var $current_column;
  13752. var $current_byte;
  13753. var $separator = ' ';
  13754. var $namespace = array('');
  13755. var $element = array('');
  13756. var $xml_base = array('');
  13757. var $xml_base_explicit = array(false);
  13758. var $xml_lang = array('');
  13759. var $data = array();
  13760. var $datas = array(array());
  13761. var $current_xhtml_construct = -1;
  13762. var $encoding;
  13763. protected $registry;
  13764. public function set_registry(SimplePie_Registry $registry)
  13765. {
  13766. $this->registry = $registry;
  13767. }
  13768. public function parse(&$data, $encoding)
  13769. {
  13770. // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
  13771. if (strtoupper($encoding) === 'US-ASCII')
  13772. {
  13773. $this->encoding = 'UTF-8';
  13774. }
  13775. else
  13776. {
  13777. $this->encoding = $encoding;
  13778. }
  13779. // Strip BOM:
  13780. // UTF-32 Big Endian BOM
  13781. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  13782. {
  13783. $data = substr($data, 4);
  13784. }
  13785. // UTF-32 Little Endian BOM
  13786. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  13787. {
  13788. $data = substr($data, 4);
  13789. }
  13790. // UTF-16 Big Endian BOM
  13791. elseif (substr($data, 0, 2) === "\xFE\xFF")
  13792. {
  13793. $data = substr($data, 2);
  13794. }
  13795. // UTF-16 Little Endian BOM
  13796. elseif (substr($data, 0, 2) === "\xFF\xFE")
  13797. {
  13798. $data = substr($data, 2);
  13799. }
  13800. // UTF-8 BOM
  13801. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  13802. {
  13803. $data = substr($data, 3);
  13804. }
  13805. if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
  13806. {
  13807. $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
  13808. if ($declaration->parse())
  13809. {
  13810. $data = substr($data, $pos + 2);
  13811. $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
  13812. }
  13813. else
  13814. {
  13815. $this->error_string = 'SimplePie bug! Please report this!';
  13816. return false;
  13817. }
  13818. }
  13819. $return = true;
  13820. static $xml_is_sane = null;
  13821. if ($xml_is_sane === null)
  13822. {
  13823. $parser_check = xml_parser_create();
  13824. xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
  13825. xml_parser_free($parser_check);
  13826. $xml_is_sane = isset($values[0]['value']);
  13827. }
  13828. // Create the parser
  13829. if ($xml_is_sane)
  13830. {
  13831. $xml = xml_parser_create_ns($this->encoding, $this->separator);
  13832. xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
  13833. xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
  13834. xml_set_object($xml, $this);
  13835. xml_set_character_data_handler($xml, 'cdata');
  13836. xml_set_element_handler($xml, 'tag_open', 'tag_close');
  13837. // Parse!
  13838. if (!xml_parse($xml, $data, true))
  13839. {
  13840. $this->error_code = xml_get_error_code($xml);
  13841. $this->error_string = xml_error_string($this->error_code);
  13842. $return = false;
  13843. }
  13844. $this->current_line = xml_get_current_line_number($xml);
  13845. $this->current_column = xml_get_current_column_number($xml);
  13846. $this->current_byte = xml_get_current_byte_index($xml);
  13847. xml_parser_free($xml);
  13848. return $return;
  13849. }
  13850. else
  13851. {
  13852. libxml_clear_errors();
  13853. $xml = new XMLReader();
  13854. $xml->xml($data);
  13855. while (@$xml->read())
  13856. {
  13857. switch ($xml->nodeType)
  13858. {
  13859. case constant('XMLReader::END_ELEMENT'):
  13860. if ($xml->namespaceURI !== '')
  13861. {
  13862. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  13863. }
  13864. else
  13865. {
  13866. $tagName = $xml->localName;
  13867. }
  13868. $this->tag_close(null, $tagName);
  13869. break;
  13870. case constant('XMLReader::ELEMENT'):
  13871. $empty = $xml->isEmptyElement;
  13872. if ($xml->namespaceURI !== '')
  13873. {
  13874. $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
  13875. }
  13876. else
  13877. {
  13878. $tagName = $xml->localName;
  13879. }
  13880. $attributes = array();
  13881. while ($xml->moveToNextAttribute())
  13882. {
  13883. if ($xml->namespaceURI !== '')
  13884. {
  13885. $attrName = $xml->namespaceURI . $this->separator . $xml->localName;
  13886. }
  13887. else
  13888. {
  13889. $attrName = $xml->localName;
  13890. }
  13891. $attributes[$attrName] = $xml->value;
  13892. }
  13893. $this->tag_open(null, $tagName, $attributes);
  13894. if ($empty)
  13895. {
  13896. $this->tag_close(null, $tagName);
  13897. }
  13898. break;
  13899. case constant('XMLReader::TEXT'):
  13900. case constant('XMLReader::CDATA'):
  13901. $this->cdata(null, $xml->value);
  13902. break;
  13903. }
  13904. }
  13905. if ($error = libxml_get_last_error())
  13906. {
  13907. $this->error_code = $error->code;
  13908. $this->error_string = $error->message;
  13909. $this->current_line = $error->line;
  13910. $this->current_column = $error->column;
  13911. return false;
  13912. }
  13913. else
  13914. {
  13915. return true;
  13916. }
  13917. }
  13918. }
  13919. public function get_error_code()
  13920. {
  13921. return $this->error_code;
  13922. }
  13923. public function get_error_string()
  13924. {
  13925. return $this->error_string;
  13926. }
  13927. public function get_current_line()
  13928. {
  13929. return $this->current_line;
  13930. }
  13931. public function get_current_column()
  13932. {
  13933. return $this->current_column;
  13934. }
  13935. public function get_current_byte()
  13936. {
  13937. return $this->current_byte;
  13938. }
  13939. public function get_data()
  13940. {
  13941. return $this->data;
  13942. }
  13943. public function tag_open($parser, $tag, $attributes)
  13944. {
  13945. list($this->namespace[], $this->element[]) = $this->split_ns($tag);
  13946. $attribs = array();
  13947. foreach ($attributes as $name => $value)
  13948. {
  13949. list($attrib_namespace, $attribute) = $this->split_ns($name);
  13950. $attribs[$attrib_namespace][$attribute] = $value;
  13951. }
  13952. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['base']))
  13953. {
  13954. $base = $this->registry->call('Misc', 'absolutize_url', array($attribs[SIMPLEPIE_NAMESPACE_XML]['base'], end($this->xml_base)));
  13955. if ($base !== false)
  13956. {
  13957. $this->xml_base[] = $base;
  13958. $this->xml_base_explicit[] = true;
  13959. }
  13960. }
  13961. else
  13962. {
  13963. $this->xml_base[] = end($this->xml_base);
  13964. $this->xml_base_explicit[] = end($this->xml_base_explicit);
  13965. }
  13966. if (isset($attribs[SIMPLEPIE_NAMESPACE_XML]['lang']))
  13967. {
  13968. $this->xml_lang[] = $attribs[SIMPLEPIE_NAMESPACE_XML]['lang'];
  13969. }
  13970. else
  13971. {
  13972. $this->xml_lang[] = end($this->xml_lang);
  13973. }
  13974. if ($this->current_xhtml_construct >= 0)
  13975. {
  13976. $this->current_xhtml_construct++;
  13977. if (end($this->namespace) === SIMPLEPIE_NAMESPACE_XHTML)
  13978. {
  13979. $this->data['data'] .= '<' . end($this->element);
  13980. if (isset($attribs['']))
  13981. {
  13982. foreach ($attribs[''] as $name => $value)
  13983. {
  13984. $this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
  13985. }
  13986. }
  13987. $this->data['data'] .= '>';
  13988. }
  13989. }
  13990. else
  13991. {
  13992. $this->datas[] =& $this->data;
  13993. $this->data =& $this->data['child'][end($this->namespace)][end($this->element)][];
  13994. $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));
  13995. 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')
  13996. || (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')
  13997. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_20 && in_array(end($this->element), array('title')))
  13998. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_090 && in_array(end($this->element), array('title')))
  13999. || (end($this->namespace) === SIMPLEPIE_NAMESPACE_RSS_10 && in_array(end($this->element), array('title'))))
  14000. {
  14001. $this->current_xhtml_construct = 0;
  14002. }
  14003. }
  14004. }
  14005. public function cdata($parser, $cdata)
  14006. {
  14007. if ($this->current_xhtml_construct >= 0)
  14008. {
  14009. $this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
  14010. }
  14011. else
  14012. {
  14013. $this->data['data'] .= $cdata;
  14014. }
  14015. }
  14016. public function tag_close($parser, $tag)
  14017. {
  14018. if ($this->current_xhtml_construct >= 0)
  14019. {
  14020. $this->current_xhtml_construct--;
  14021. 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')))
  14022. {
  14023. $this->data['data'] .= '</' . end($this->element) . '>';
  14024. }
  14025. }
  14026. if ($this->current_xhtml_construct === -1)
  14027. {
  14028. $this->data =& $this->datas[count($this->datas) - 1];
  14029. array_pop($this->datas);
  14030. }
  14031. array_pop($this->element);
  14032. array_pop($this->namespace);
  14033. array_pop($this->xml_base);
  14034. array_pop($this->xml_base_explicit);
  14035. array_pop($this->xml_lang);
  14036. }
  14037. public function split_ns($string)
  14038. {
  14039. static $cache = array();
  14040. if (!isset($cache[$string]))
  14041. {
  14042. if ($pos = strpos($string, $this->separator))
  14043. {
  14044. static $separator_length;
  14045. if (!$separator_length)
  14046. {
  14047. $separator_length = strlen($this->separator);
  14048. }
  14049. $namespace = substr($string, 0, $pos);
  14050. $local_name = substr($string, $pos + $separator_length);
  14051. if (strtolower($namespace) === SIMPLEPIE_NAMESPACE_ITUNES)
  14052. {
  14053. $namespace = SIMPLEPIE_NAMESPACE_ITUNES;
  14054. }
  14055. // Normalize the Media RSS namespaces
  14056. if ($namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG ||
  14057. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG2 ||
  14058. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG3 ||
  14059. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG4 ||
  14060. $namespace === SIMPLEPIE_NAMESPACE_MEDIARSS_WRONG5 )
  14061. {
  14062. $namespace = SIMPLEPIE_NAMESPACE_MEDIARSS;
  14063. }
  14064. $cache[$string] = array($namespace, $local_name);
  14065. }
  14066. else
  14067. {
  14068. $cache[$string] = array('', $string);
  14069. }
  14070. }
  14071. return $cache[$string];
  14072. }
  14073. }
  14074. /**
  14075. * Content-type sniffing
  14076. *
  14077. * Based on the rules in http://tools.ietf.org/html/draft-abarth-mime-sniff-06
  14078. *
  14079. * This is used since we can't always trust Content-Type headers, and is based
  14080. * upon the HTML5 parsing rules.
  14081. *
  14082. *
  14083. * This class can be overloaded with {@see SimplePie::set_content_type_sniffer_class()}
  14084. *
  14085. * @package SimplePie
  14086. * @subpackage HTTP
  14087. */
  14088. class SimplePie_Content_Type_Sniffer
  14089. {
  14090. /**
  14091. * File object
  14092. *
  14093. * @var SimplePie_File
  14094. */
  14095. var $file;
  14096. /**
  14097. * Create an instance of the class with the input file
  14098. *
  14099. * @param SimplePie_Content_Type_Sniffer $file Input file
  14100. */
  14101. public function __construct($file)
  14102. {
  14103. $this->file = $file;
  14104. }
  14105. /**
  14106. * Get the Content-Type of the specified file
  14107. *
  14108. * @return string Actual Content-Type
  14109. */
  14110. public function get_type()
  14111. {
  14112. if (isset($this->file->headers['content-type']))
  14113. {
  14114. if (!isset($this->file->headers['content-encoding'])
  14115. && ($this->file->headers['content-type'] === 'text/plain'
  14116. || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
  14117. || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
  14118. || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8'))
  14119. {
  14120. return $this->text_or_binary();
  14121. }
  14122. if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
  14123. {
  14124. $official = substr($this->file->headers['content-type'], 0, $pos);
  14125. }
  14126. else
  14127. {
  14128. $official = $this->file->headers['content-type'];
  14129. }
  14130. $official = trim(strtolower($official));
  14131. if ($official === 'unknown/unknown'
  14132. || $official === 'application/unknown')
  14133. {
  14134. return $this->unknown();
  14135. }
  14136. elseif (substr($official, -4) === '+xml'
  14137. || $official === 'text/xml'
  14138. || $official === 'application/xml')
  14139. {
  14140. return $official;
  14141. }
  14142. elseif (substr($official, 0, 6) === 'image/')
  14143. {
  14144. if ($return = $this->image())
  14145. {
  14146. return $return;
  14147. }
  14148. else
  14149. {
  14150. return $official;
  14151. }
  14152. }
  14153. elseif ($official === 'text/html')
  14154. {
  14155. return $this->feed_or_html();
  14156. }
  14157. else
  14158. {
  14159. return $official;
  14160. }
  14161. }
  14162. else
  14163. {
  14164. return $this->unknown();
  14165. }
  14166. }
  14167. /**
  14168. * Sniff text or binary
  14169. *
  14170. * @return string Actual Content-Type
  14171. */
  14172. public function text_or_binary()
  14173. {
  14174. if (substr($this->file->body, 0, 2) === "\xFE\xFF"
  14175. || substr($this->file->body, 0, 2) === "\xFF\xFE"
  14176. || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
  14177. || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF")
  14178. {
  14179. return 'text/plain';
  14180. }
  14181. elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
  14182. {
  14183. return 'application/octect-stream';
  14184. }
  14185. else
  14186. {
  14187. return 'text/plain';
  14188. }
  14189. }
  14190. /**
  14191. * Sniff unknown
  14192. *
  14193. * @return string Actual Content-Type
  14194. */
  14195. public function unknown()
  14196. {
  14197. $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
  14198. if (strtolower(substr($this->file->body, $ws, 14)) === '<!doctype html'
  14199. || strtolower(substr($this->file->body, $ws, 5)) === '<html'
  14200. || strtolower(substr($this->file->body, $ws, 7)) === '<script')
  14201. {
  14202. return 'text/html';
  14203. }
  14204. elseif (substr($this->file->body, 0, 5) === '%PDF-')
  14205. {
  14206. return 'application/pdf';
  14207. }
  14208. elseif (substr($this->file->body, 0, 11) === '%!PS-Adobe-')
  14209. {
  14210. return 'application/postscript';
  14211. }
  14212. elseif (substr($this->file->body, 0, 6) === 'GIF87a'
  14213. || substr($this->file->body, 0, 6) === 'GIF89a')
  14214. {
  14215. return 'image/gif';
  14216. }
  14217. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  14218. {
  14219. return 'image/png';
  14220. }
  14221. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  14222. {
  14223. return 'image/jpeg';
  14224. }
  14225. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  14226. {
  14227. return 'image/bmp';
  14228. }
  14229. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  14230. {
  14231. return 'image/vnd.microsoft.icon';
  14232. }
  14233. else
  14234. {
  14235. return $this->text_or_binary();
  14236. }
  14237. }
  14238. /**
  14239. * Sniff images
  14240. *
  14241. * @return string Actual Content-Type
  14242. */
  14243. public function image()
  14244. {
  14245. if (substr($this->file->body, 0, 6) === 'GIF87a'
  14246. || substr($this->file->body, 0, 6) === 'GIF89a')
  14247. {
  14248. return 'image/gif';
  14249. }
  14250. elseif (substr($this->file->body, 0, 8) === "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
  14251. {
  14252. return 'image/png';
  14253. }
  14254. elseif (substr($this->file->body, 0, 3) === "\xFF\xD8\xFF")
  14255. {
  14256. return 'image/jpeg';
  14257. }
  14258. elseif (substr($this->file->body, 0, 2) === "\x42\x4D")
  14259. {
  14260. return 'image/bmp';
  14261. }
  14262. elseif (substr($this->file->body, 0, 4) === "\x00\x00\x01\x00")
  14263. {
  14264. return 'image/vnd.microsoft.icon';
  14265. }
  14266. else
  14267. {
  14268. return false;
  14269. }
  14270. }
  14271. /**
  14272. * Sniff HTML
  14273. *
  14274. * @return string Actual Content-Type
  14275. */
  14276. public function feed_or_html()
  14277. {
  14278. $len = strlen($this->file->body);
  14279. $pos = strspn($this->file->body, "\x09\x0A\x0D\x20");
  14280. while ($pos < $len)
  14281. {
  14282. switch ($this->file->body[$pos])
  14283. {
  14284. case "\x09":
  14285. case "\x0A":
  14286. case "\x0D":
  14287. case "\x20":
  14288. $pos += strspn($this->file->body, "\x09\x0A\x0D\x20", $pos);
  14289. continue 2;
  14290. case '<':
  14291. $pos++;
  14292. break;
  14293. default:
  14294. return 'text/html';
  14295. }
  14296. if (substr($this->file->body, $pos, 3) === '!--')
  14297. {
  14298. $pos += 3;
  14299. if ($pos < $len && ($pos = strpos($this->file->body, '-->', $pos)) !== false)
  14300. {
  14301. $pos += 3;
  14302. }
  14303. else
  14304. {
  14305. return 'text/html';
  14306. }
  14307. }
  14308. elseif (substr($this->file->body, $pos, 1) === '!')
  14309. {
  14310. if ($pos < $len && ($pos = strpos($this->file->body, '>', $pos)) !== false)
  14311. {
  14312. $pos++;
  14313. }
  14314. else
  14315. {
  14316. return 'text/html';
  14317. }
  14318. }
  14319. elseif (substr($this->file->body, $pos, 1) === '?')
  14320. {
  14321. if ($pos < $len && ($pos = strpos($this->file->body, '?>', $pos)) !== false)
  14322. {
  14323. $pos += 2;
  14324. }
  14325. else
  14326. {
  14327. return 'text/html';
  14328. }
  14329. }
  14330. elseif (substr($this->file->body, $pos, 3) === 'rss'
  14331. || substr($this->file->body, $pos, 7) === 'rdf:RDF')
  14332. {
  14333. return 'application/rss+xml';
  14334. }
  14335. elseif (substr($this->file->body, $pos, 4) === 'feed')
  14336. {
  14337. return 'application/atom+xml';
  14338. }
  14339. else
  14340. {
  14341. return 'text/html';
  14342. }
  14343. }
  14344. return 'text/html';
  14345. }
  14346. }
  14347. /**
  14348. * Handles `<media:text>` captions as defined in Media RSS.
  14349. *
  14350. * Used by {@see SimplePie_Enclosure::get_caption()} and {@see SimplePie_Enclosure::get_captions()}
  14351. *
  14352. * This class can be overloaded with {@see SimplePie::set_caption_class()}
  14353. *
  14354. * @package SimplePie
  14355. * @subpackage API
  14356. */
  14357. class SimplePie_Caption
  14358. {
  14359. /**
  14360. * Content type
  14361. *
  14362. * @var string
  14363. * @see get_type()
  14364. */
  14365. var $type;
  14366. /**
  14367. * Language
  14368. *
  14369. * @var string
  14370. * @see get_language()
  14371. */
  14372. var $lang;
  14373. /**
  14374. * Start time
  14375. *
  14376. * @var string
  14377. * @see get_starttime()
  14378. */
  14379. var $startTime;
  14380. /**
  14381. * End time
  14382. *
  14383. * @var string
  14384. * @see get_endtime()
  14385. */
  14386. var $endTime;
  14387. /**
  14388. * Caption text
  14389. *
  14390. * @var string
  14391. * @see get_text()
  14392. */
  14393. var $text;
  14394. /**
  14395. * Constructor, used to input the data
  14396. *
  14397. * For documentation on all the parameters, see the corresponding
  14398. * properties and their accessors
  14399. */
  14400. public function __construct($type = null, $lang = null, $startTime = null, $endTime = null, $text = null)
  14401. {
  14402. $this->type = $type;
  14403. $this->lang = $lang;
  14404. $this->startTime = $startTime;
  14405. $this->endTime = $endTime;
  14406. $this->text = $text;
  14407. }
  14408. /**
  14409. * String-ified version
  14410. *
  14411. * @return string
  14412. */
  14413. public function __toString()
  14414. {
  14415. // There is no $this->data here
  14416. return md5(serialize($this));
  14417. }
  14418. /**
  14419. * Get the end time
  14420. *
  14421. * @return string|null Time in the format 'hh:mm:ss.SSS'
  14422. */
  14423. public function get_endtime()
  14424. {
  14425. if ($this->endTime !== null)
  14426. {
  14427. return $this->endTime;
  14428. }
  14429. else
  14430. {
  14431. return null;
  14432. }
  14433. }
  14434. /**
  14435. * Get the language
  14436. *
  14437. * @link http://tools.ietf.org/html/rfc3066
  14438. * @return string|null Language code as per RFC 3066
  14439. */
  14440. public function get_language()
  14441. {
  14442. if ($this->lang !== null)
  14443. {
  14444. return $this->lang;
  14445. }
  14446. else
  14447. {
  14448. return null;
  14449. }
  14450. }
  14451. /**
  14452. * Get the start time
  14453. *
  14454. * @return string|null Time in the format 'hh:mm:ss.SSS'
  14455. */
  14456. public function get_starttime()
  14457. {
  14458. if ($this->startTime !== null)
  14459. {
  14460. return $this->startTime;
  14461. }
  14462. else
  14463. {
  14464. return null;
  14465. }
  14466. }
  14467. /**
  14468. * Get the text of the caption
  14469. *
  14470. * @return string|null
  14471. */
  14472. public function get_text()
  14473. {
  14474. if ($this->text !== null)
  14475. {
  14476. return $this->text;
  14477. }
  14478. else
  14479. {
  14480. return null;
  14481. }
  14482. }
  14483. /**
  14484. * Get the content type (not MIME type)
  14485. *
  14486. * @return string|null Either 'text' or 'html'
  14487. */
  14488. public function get_type()
  14489. {
  14490. if ($this->type !== null)
  14491. {
  14492. return $this->type;
  14493. }
  14494. else
  14495. {
  14496. return null;
  14497. }
  14498. }
  14499. }
  14500. /**
  14501. * Decode HTML Entities
  14502. *
  14503. * This implements HTML5 as of revision 967 (2007-06-28)
  14504. *
  14505. * @deprecated Use DOMDocument instead!
  14506. * @package SimplePie
  14507. */
  14508. class SimplePie_Decode_HTML_Entities
  14509. {
  14510. /**
  14511. * Data to be parsed
  14512. *
  14513. * @access private
  14514. * @var string
  14515. */
  14516. var $data = '';
  14517. /**
  14518. * Currently consumed bytes
  14519. *
  14520. * @access private
  14521. * @var string
  14522. */
  14523. var $consumed = '';
  14524. /**
  14525. * Position of the current byte being parsed
  14526. *
  14527. * @access private
  14528. * @var int
  14529. */
  14530. var $position = 0;
  14531. /**
  14532. * Create an instance of the class with the input data
  14533. *
  14534. * @access public
  14535. * @param string $data Input data
  14536. */
  14537. public function __construct($data)
  14538. {
  14539. $this->data = $data;
  14540. }
  14541. /**
  14542. * Parse the input data
  14543. *
  14544. * @access public
  14545. * @return string Output data
  14546. */
  14547. public function parse()
  14548. {
  14549. while (($this->position = strpos($this->data, '&', $this->position)) !== false)
  14550. {
  14551. $this->consume();
  14552. $this->entity();
  14553. $this->consumed = '';
  14554. }
  14555. return $this->data;
  14556. }
  14557. /**
  14558. * Consume the next byte
  14559. *
  14560. * @access private
  14561. * @return mixed The next byte, or false, if there is no more data
  14562. */
  14563. public function consume()
  14564. {
  14565. if (isset($this->data[$this->position]))
  14566. {
  14567. $this->consumed .= $this->data[$this->position];
  14568. return $this->data[$this->position++];
  14569. }
  14570. else
  14571. {
  14572. return false;
  14573. }
  14574. }
  14575. /**
  14576. * Consume a range of characters
  14577. *
  14578. * @access private
  14579. * @param string $chars Characters to consume
  14580. * @return mixed A series of characters that match the range, or false
  14581. */
  14582. public function consume_range($chars)
  14583. {
  14584. if ($len = strspn($this->data, $chars, $this->position))
  14585. {
  14586. $data = substr($this->data, $this->position, $len);
  14587. $this->consumed .= $data;
  14588. $this->position += $len;
  14589. return $data;
  14590. }
  14591. else
  14592. {
  14593. return false;
  14594. }
  14595. }
  14596. /**
  14597. * Unconsume one byte
  14598. *
  14599. * @access private
  14600. */
  14601. public function unconsume()
  14602. {
  14603. $this->consumed = substr($this->consumed, 0, -1);
  14604. $this->position--;
  14605. }
  14606. /**
  14607. * Decode an entity
  14608. *
  14609. * @access private
  14610. */
  14611. public function entity()
  14612. {
  14613. switch ($this->consume())
  14614. {
  14615. case "\x09":
  14616. case "\x0A":
  14617. case "\x0B":
  14618. case "\x0B":
  14619. case "\x0C":
  14620. case "\x20":
  14621. case "\x3C":
  14622. case "\x26":
  14623. case false:
  14624. break;
  14625. case "\x23":
  14626. switch ($this->consume())
  14627. {
  14628. case "\x78":
  14629. case "\x58":
  14630. $range = '0123456789ABCDEFabcdef';
  14631. $hex = true;
  14632. break;
  14633. default:
  14634. $range = '0123456789';
  14635. $hex = false;
  14636. $this->unconsume();
  14637. break;
  14638. }
  14639. if ($codepoint = $this->consume_range($range))
  14640. {
  14641. 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");
  14642. if ($hex)
  14643. {
  14644. $codepoint = hexdec($codepoint);
  14645. }
  14646. else
  14647. {
  14648. $codepoint = intval($codepoint);
  14649. }
  14650. if (isset($windows_1252_specials[$codepoint]))
  14651. {
  14652. $replacement = $windows_1252_specials[$codepoint];
  14653. }
  14654. else
  14655. {
  14656. $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
  14657. }
  14658. if (!in_array($this->consume(), array(';', false), true))
  14659. {
  14660. $this->unconsume();
  14661. }
  14662. $consumed_length = strlen($this->consumed);
  14663. $this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
  14664. $this->position += strlen($replacement) - $consumed_length;
  14665. }
  14666. break;
  14667. default:
  14668. static $entities = array(
  14669. 'Aacute' => "\xC3\x81",
  14670. 'aacute' => "\xC3\xA1",
  14671. 'Aacute;' => "\xC3\x81",
  14672. 'aacute;' => "\xC3\xA1",
  14673. 'Acirc' => "\xC3\x82",
  14674. 'acirc' => "\xC3\xA2",
  14675. 'Acirc;' => "\xC3\x82",
  14676. 'acirc;' => "\xC3\xA2",
  14677. 'acute' => "\xC2\xB4",
  14678. 'acute;' => "\xC2\xB4",
  14679. 'AElig' => "\xC3\x86",
  14680. 'aelig' => "\xC3\xA6",
  14681. 'AElig;' => "\xC3\x86",
  14682. 'aelig;' => "\xC3\xA6",
  14683. 'Agrave' => "\xC3\x80",
  14684. 'agrave' => "\xC3\xA0",
  14685. 'Agrave;' => "\xC3\x80",
  14686. 'agrave;' => "\xC3\xA0",
  14687. 'alefsym;' => "\xE2\x84\xB5",
  14688. 'Alpha;' => "\xCE\x91",
  14689. 'alpha;' => "\xCE\xB1",
  14690. 'AMP' => "\x26",
  14691. 'amp' => "\x26",
  14692. 'AMP;' => "\x26",
  14693. 'amp;' => "\x26",
  14694. 'and;' => "\xE2\x88\xA7",
  14695. 'ang;' => "\xE2\x88\xA0",
  14696. 'apos;' => "\x27",
  14697. 'Aring' => "\xC3\x85",
  14698. 'aring' => "\xC3\xA5",
  14699. 'Aring;' => "\xC3\x85",
  14700. 'aring;' => "\xC3\xA5",
  14701. 'asymp;' => "\xE2\x89\x88",
  14702. 'Atilde' => "\xC3\x83",
  14703. 'atilde' => "\xC3\xA3",
  14704. 'Atilde;' => "\xC3\x83",
  14705. 'atilde;' => "\xC3\xA3",
  14706. 'Auml' => "\xC3\x84",
  14707. 'auml' => "\xC3\xA4",
  14708. 'Auml;' => "\xC3\x84",
  14709. 'auml;' => "\xC3\xA4",
  14710. 'bdquo;' => "\xE2\x80\x9E",
  14711. 'Beta;' => "\xCE\x92",
  14712. 'beta;' => "\xCE\xB2",
  14713. 'brvbar' => "\xC2\xA6",
  14714. 'brvbar;' => "\xC2\xA6",
  14715. 'bull;' => "\xE2\x80\xA2",
  14716. 'cap;' => "\xE2\x88\xA9",
  14717. 'Ccedil' => "\xC3\x87",
  14718. 'ccedil' => "\xC3\xA7",
  14719. 'Ccedil;' => "\xC3\x87",
  14720. 'ccedil;' => "\xC3\xA7",
  14721. 'cedil' => "\xC2\xB8",
  14722. 'cedil;' => "\xC2\xB8",
  14723. 'cent' => "\xC2\xA2",
  14724. 'cent;' => "\xC2\xA2",
  14725. 'Chi;' => "\xCE\xA7",
  14726. 'chi;' => "\xCF\x87",
  14727. 'circ;' => "\xCB\x86",
  14728. 'clubs;' => "\xE2\x99\xA3",
  14729. 'cong;' => "\xE2\x89\x85",
  14730. 'COPY' => "\xC2\xA9",
  14731. 'copy' => "\xC2\xA9",
  14732. 'COPY;' => "\xC2\xA9",
  14733. 'copy;' => "\xC2\xA9",
  14734. 'crarr;' => "\xE2\x86\xB5",
  14735. 'cup;' => "\xE2\x88\xAA",
  14736. 'curren' => "\xC2\xA4",
  14737. 'curren;' => "\xC2\xA4",
  14738. 'Dagger;' => "\xE2\x80\xA1",
  14739. 'dagger;' => "\xE2\x80\xA0",
  14740. 'dArr;' => "\xE2\x87\x93",
  14741. 'darr;' => "\xE2\x86\x93",
  14742. 'deg' => "\xC2\xB0",
  14743. 'deg;' => "\xC2\xB0",
  14744. 'Delta;' => "\xCE\x94",
  14745. 'delta;' => "\xCE\xB4",
  14746. 'diams;' => "\xE2\x99\xA6",
  14747. 'divide' => "\xC3\xB7",
  14748. 'divide;' => "\xC3\xB7",
  14749. 'Eacute' => "\xC3\x89",
  14750. 'eacute' => "\xC3\xA9",
  14751. 'Eacute;' => "\xC3\x89",
  14752. 'eacute;' => "\xC3\xA9",
  14753. 'Ecirc' => "\xC3\x8A",
  14754. 'ecirc' => "\xC3\xAA",
  14755. 'Ecirc;' => "\xC3\x8A",
  14756. 'ecirc;' => "\xC3\xAA",
  14757. 'Egrave' => "\xC3\x88",
  14758. 'egrave' => "\xC3\xA8",
  14759. 'Egrave;' => "\xC3\x88",
  14760. 'egrave;' => "\xC3\xA8",
  14761. 'empty;' => "\xE2\x88\x85",
  14762. 'emsp;' => "\xE2\x80\x83",
  14763. 'ensp;' => "\xE2\x80\x82",
  14764. 'Epsilon;' => "\xCE\x95",
  14765. 'epsilon;' => "\xCE\xB5",
  14766. 'equiv;' => "\xE2\x89\xA1",
  14767. 'Eta;' => "\xCE\x97",
  14768. 'eta;' => "\xCE\xB7",
  14769. 'ETH' => "\xC3\x90",
  14770. 'eth' => "\xC3\xB0",
  14771. 'ETH;' => "\xC3\x90",
  14772. 'eth;' => "\xC3\xB0",
  14773. 'Euml' => "\xC3\x8B",
  14774. 'euml' => "\xC3\xAB",
  14775. 'Euml;' => "\xC3\x8B",
  14776. 'euml;' => "\xC3\xAB",
  14777. 'euro;' => "\xE2\x82\xAC",
  14778. 'exist;' => "\xE2\x88\x83",
  14779. 'fnof;' => "\xC6\x92",
  14780. 'forall;' => "\xE2\x88\x80",
  14781. 'frac12' => "\xC2\xBD",
  14782. 'frac12;' => "\xC2\xBD",
  14783. 'frac14' => "\xC2\xBC",
  14784. 'frac14;' => "\xC2\xBC",
  14785. 'frac34' => "\xC2\xBE",
  14786. 'frac34;' => "\xC2\xBE",
  14787. 'frasl;' => "\xE2\x81\x84",
  14788. 'Gamma;' => "\xCE\x93",
  14789. 'gamma;' => "\xCE\xB3",
  14790. 'ge;' => "\xE2\x89\xA5",
  14791. 'GT' => "\x3E",
  14792. 'gt' => "\x3E",
  14793. 'GT;' => "\x3E",
  14794. 'gt;' => "\x3E",
  14795. 'hArr;' => "\xE2\x87\x94",
  14796. 'harr;' => "\xE2\x86\x94",
  14797. 'hearts;' => "\xE2\x99\xA5",
  14798. 'hellip;' => "\xE2\x80\xA6",
  14799. 'Iacute' => "\xC3\x8D",
  14800. 'iacute' => "\xC3\xAD",
  14801. 'Iacute;' => "\xC3\x8D",
  14802. 'iacute;' => "\xC3\xAD",
  14803. 'Icirc' => "\xC3\x8E",
  14804. 'icirc' => "\xC3\xAE",
  14805. 'Icirc;' => "\xC3\x8E",
  14806. 'icirc;' => "\xC3\xAE",
  14807. 'iexcl' => "\xC2\xA1",
  14808. 'iexcl;' => "\xC2\xA1",
  14809. 'Igrave' => "\xC3\x8C",
  14810. 'igrave' => "\xC3\xAC",
  14811. 'Igrave;' => "\xC3\x8C",
  14812. 'igrave;' => "\xC3\xAC",
  14813. 'image;' => "\xE2\x84\x91",
  14814. 'infin;' => "\xE2\x88\x9E",
  14815. 'int;' => "\xE2\x88\xAB",
  14816. 'Iota;' => "\xCE\x99",
  14817. 'iota;' => "\xCE\xB9",
  14818. 'iquest' => "\xC2\xBF",
  14819. 'iquest;' => "\xC2\xBF",
  14820. 'isin;' => "\xE2\x88\x88",
  14821. 'Iuml' => "\xC3\x8F",
  14822. 'iuml' => "\xC3\xAF",
  14823. 'Iuml;' => "\xC3\x8F",
  14824. 'iuml;' => "\xC3\xAF",
  14825. 'Kappa;' => "\xCE\x9A",
  14826. 'kappa;' => "\xCE\xBA",
  14827. 'Lambda;' => "\xCE\x9B",
  14828. 'lambda;' => "\xCE\xBB",
  14829. 'lang;' => "\xE3\x80\x88",
  14830. 'laquo' => "\xC2\xAB",
  14831. 'laquo;' => "\xC2\xAB",
  14832. 'lArr;' => "\xE2\x87\x90",
  14833. 'larr;' => "\xE2\x86\x90",
  14834. 'lceil;' => "\xE2\x8C\x88",
  14835. 'ldquo;' => "\xE2\x80\x9C",
  14836. 'le;' => "\xE2\x89\xA4",
  14837. 'lfloor;' => "\xE2\x8C\x8A",
  14838. 'lowast;' => "\xE2\x88\x97",
  14839. 'loz;' => "\xE2\x97\x8A",
  14840. 'lrm;' => "\xE2\x80\x8E",
  14841. 'lsaquo;' => "\xE2\x80\xB9",
  14842. 'lsquo;' => "\xE2\x80\x98",
  14843. 'LT' => "\x3C",
  14844. 'lt' => "\x3C",
  14845. 'LT;' => "\x3C",
  14846. 'lt;' => "\x3C",
  14847. 'macr' => "\xC2\xAF",
  14848. 'macr;' => "\xC2\xAF",
  14849. 'mdash;' => "\xE2\x80\x94",
  14850. 'micro' => "\xC2\xB5",
  14851. 'micro;' => "\xC2\xB5",
  14852. 'middot' => "\xC2\xB7",
  14853. 'middot;' => "\xC2\xB7",
  14854. 'minus;' => "\xE2\x88\x92",
  14855. 'Mu;' => "\xCE\x9C",
  14856. 'mu;' => "\xCE\xBC",
  14857. 'nabla;' => "\xE2\x88\x87",
  14858. 'nbsp' => "\xC2\xA0",
  14859. 'nbsp;' => "\xC2\xA0",
  14860. 'ndash;' => "\xE2\x80\x93",
  14861. 'ne;' => "\xE2\x89\xA0",
  14862. 'ni;' => "\xE2\x88\x8B",
  14863. 'not' => "\xC2\xAC",
  14864. 'not;' => "\xC2\xAC",
  14865. 'notin;' => "\xE2\x88\x89",
  14866. 'nsub;' => "\xE2\x8A\x84",
  14867. 'Ntilde' => "\xC3\x91",
  14868. 'ntilde' => "\xC3\xB1",
  14869. 'Ntilde;' => "\xC3\x91",
  14870. 'ntilde;' => "\xC3\xB1",
  14871. 'Nu;' => "\xCE\x9D",
  14872. 'nu;' => "\xCE\xBD",
  14873. 'Oacute' => "\xC3\x93",
  14874. 'oacute' => "\xC3\xB3",
  14875. 'Oacute;' => "\xC3\x93",
  14876. 'oacute;' => "\xC3\xB3",
  14877. 'Ocirc' => "\xC3\x94",
  14878. 'ocirc' => "\xC3\xB4",
  14879. 'Ocirc;' => "\xC3\x94",
  14880. 'ocirc;' => "\xC3\xB4",
  14881. 'OElig;' => "\xC5\x92",
  14882. 'oelig;' => "\xC5\x93",
  14883. 'Ograve' => "\xC3\x92",
  14884. 'ograve' => "\xC3\xB2",
  14885. 'Ograve;' => "\xC3\x92",
  14886. 'ograve;' => "\xC3\xB2",
  14887. 'oline;' => "\xE2\x80\xBE",
  14888. 'Omega;' => "\xCE\xA9",
  14889. 'omega;' => "\xCF\x89",
  14890. 'Omicron;' => "\xCE\x9F",
  14891. 'omicron;' => "\xCE\xBF",
  14892. 'oplus;' => "\xE2\x8A\x95",
  14893. 'or;' => "\xE2\x88\xA8",
  14894. 'ordf' => "\xC2\xAA",
  14895. 'ordf;' => "\xC2\xAA",
  14896. 'ordm' => "\xC2\xBA",
  14897. 'ordm;' => "\xC2\xBA",
  14898. 'Oslash' => "\xC3\x98",
  14899. 'oslash' => "\xC3\xB8",
  14900. 'Oslash;' => "\xC3\x98",
  14901. 'oslash;' => "\xC3\xB8",
  14902. 'Otilde' => "\xC3\x95",
  14903. 'otilde' => "\xC3\xB5",
  14904. 'Otilde;' => "\xC3\x95",
  14905. 'otilde;' => "\xC3\xB5",
  14906. 'otimes;' => "\xE2\x8A\x97",
  14907. 'Ouml' => "\xC3\x96",
  14908. 'ouml' => "\xC3\xB6",
  14909. 'Ouml;' => "\xC3\x96",
  14910. 'ouml;' => "\xC3\xB6",
  14911. 'para' => "\xC2\xB6",
  14912. 'para;' => "\xC2\xB6",
  14913. 'part;' => "\xE2\x88\x82",
  14914. 'permil;' => "\xE2\x80\xB0",
  14915. 'perp;' => "\xE2\x8A\xA5",
  14916. 'Phi;' => "\xCE\xA6",
  14917. 'phi;' => "\xCF\x86",
  14918. 'Pi;' => "\xCE\xA0",
  14919. 'pi;' => "\xCF\x80",
  14920. 'piv;' => "\xCF\x96",
  14921. 'plusmn' => "\xC2\xB1",
  14922. 'plusmn;' => "\xC2\xB1",
  14923. 'pound' => "\xC2\xA3",
  14924. 'pound;' => "\xC2\xA3",
  14925. 'Prime;' => "\xE2\x80\xB3",
  14926. 'prime;' => "\xE2\x80\xB2",
  14927. 'prod;' => "\xE2\x88\x8F",
  14928. 'prop;' => "\xE2\x88\x9D",
  14929. 'Psi;' => "\xCE\xA8",
  14930. 'psi;' => "\xCF\x88",
  14931. 'QUOT' => "\x22",
  14932. 'quot' => "\x22",
  14933. 'QUOT;' => "\x22",
  14934. 'quot;' => "\x22",
  14935. 'radic;' => "\xE2\x88\x9A",
  14936. 'rang;' => "\xE3\x80\x89",
  14937. 'raquo' => "\xC2\xBB",
  14938. 'raquo;' => "\xC2\xBB",
  14939. 'rArr;' => "\xE2\x87\x92",
  14940. 'rarr;' => "\xE2\x86\x92",
  14941. 'rceil;' => "\xE2\x8C\x89",
  14942. 'rdquo;' => "\xE2\x80\x9D",
  14943. 'real;' => "\xE2\x84\x9C",
  14944. 'REG' => "\xC2\xAE",
  14945. 'reg' => "\xC2\xAE",
  14946. 'REG;' => "\xC2\xAE",
  14947. 'reg;' => "\xC2\xAE",
  14948. 'rfloor;' => "\xE2\x8C\x8B",
  14949. 'Rho;' => "\xCE\xA1",
  14950. 'rho;' => "\xCF\x81",
  14951. 'rlm;' => "\xE2\x80\x8F",
  14952. 'rsaquo;' => "\xE2\x80\xBA",
  14953. 'rsquo;' => "\xE2\x80\x99",
  14954. 'sbquo;' => "\xE2\x80\x9A",
  14955. 'Scaron;' => "\xC5\xA0",
  14956. 'scaron;' => "\xC5\xA1",
  14957. 'sdot;' => "\xE2\x8B\x85",
  14958. 'sect' => "\xC2\xA7",
  14959. 'sect;' => "\xC2\xA7",
  14960. 'shy' => "\xC2\xAD",
  14961. 'shy;' => "\xC2\xAD",
  14962. 'Sigma;' => "\xCE\xA3",
  14963. 'sigma;' => "\xCF\x83",
  14964. 'sigmaf;' => "\xCF\x82",
  14965. 'sim;' => "\xE2\x88\xBC",
  14966. 'spades;' => "\xE2\x99\xA0",
  14967. 'sub;' => "\xE2\x8A\x82",
  14968. 'sube;' => "\xE2\x8A\x86",
  14969. 'sum;' => "\xE2\x88\x91",
  14970. 'sup;' => "\xE2\x8A\x83",
  14971. 'sup1' => "\xC2\xB9",
  14972. 'sup1;' => "\xC2\xB9",
  14973. 'sup2' => "\xC2\xB2",
  14974. 'sup2;' => "\xC2\xB2",
  14975. 'sup3' => "\xC2\xB3",
  14976. 'sup3;' => "\xC2\xB3",
  14977. 'supe;' => "\xE2\x8A\x87",
  14978. 'szlig' => "\xC3\x9F",
  14979. 'szlig;' => "\xC3\x9F",
  14980. 'Tau;' => "\xCE\xA4",
  14981. 'tau;' => "\xCF\x84",
  14982. 'there4;' => "\xE2\x88\xB4",
  14983. 'Theta;' => "\xCE\x98",
  14984. 'theta;' => "\xCE\xB8",
  14985. 'thetasym;' => "\xCF\x91",
  14986. 'thinsp;' => "\xE2\x80\x89",
  14987. 'THORN' => "\xC3\x9E",
  14988. 'thorn' => "\xC3\xBE",
  14989. 'THORN;' => "\xC3\x9E",
  14990. 'thorn;' => "\xC3\xBE",
  14991. 'tilde;' => "\xCB\x9C",
  14992. 'times' => "\xC3\x97",
  14993. 'times;' => "\xC3\x97",
  14994. 'TRADE;' => "\xE2\x84\xA2",
  14995. 'trade;' => "\xE2\x84\xA2",
  14996. 'Uacute' => "\xC3\x9A",
  14997. 'uacute' => "\xC3\xBA",
  14998. 'Uacute;' => "\xC3\x9A",
  14999. 'uacute;' => "\xC3\xBA",
  15000. 'uArr;' => "\xE2\x87\x91",
  15001. 'uarr;' => "\xE2\x86\x91",
  15002. 'Ucirc' => "\xC3\x9B",
  15003. 'ucirc' => "\xC3\xBB",
  15004. 'Ucirc;' => "\xC3\x9B",
  15005. 'ucirc;' => "\xC3\xBB",
  15006. 'Ugrave' => "\xC3\x99",
  15007. 'ugrave' => "\xC3\xB9",
  15008. 'Ugrave;' => "\xC3\x99",
  15009. 'ugrave;' => "\xC3\xB9",
  15010. 'uml' => "\xC2\xA8",
  15011. 'uml;' => "\xC2\xA8",
  15012. 'upsih;' => "\xCF\x92",
  15013. 'Upsilon;' => "\xCE\xA5",
  15014. 'upsilon;' => "\xCF\x85",
  15015. 'Uuml' => "\xC3\x9C",
  15016. 'uuml' => "\xC3\xBC",
  15017. 'Uuml;' => "\xC3\x9C",
  15018. 'uuml;' => "\xC3\xBC",
  15019. 'weierp;' => "\xE2\x84\x98",
  15020. 'Xi;' => "\xCE\x9E",
  15021. 'xi;' => "\xCE\xBE",
  15022. 'Yacute' => "\xC3\x9D",
  15023. 'yacute' => "\xC3\xBD",
  15024. 'Yacute;' => "\xC3\x9D",
  15025. 'yacute;' => "\xC3\xBD",
  15026. 'yen' => "\xC2\xA5",
  15027. 'yen;' => "\xC2\xA5",
  15028. 'yuml' => "\xC3\xBF",
  15029. 'Yuml;' => "\xC5\xB8",
  15030. 'yuml;' => "\xC3\xBF",
  15031. 'Zeta;' => "\xCE\x96",
  15032. 'zeta;' => "\xCE\xB6",
  15033. 'zwj;' => "\xE2\x80\x8D",
  15034. 'zwnj;' => "\xE2\x80\x8C"
  15035. );
  15036. for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++)
  15037. {
  15038. $consumed = substr($this->consumed, 1);
  15039. if (isset($entities[$consumed]))
  15040. {
  15041. $match = $consumed;
  15042. }
  15043. }
  15044. if ($match !== null)
  15045. {
  15046. $this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
  15047. $this->position += strlen($entities[$match]) - strlen($consumed) - 1;
  15048. }
  15049. break;
  15050. }
  15051. }
  15052. }
  15053. /**
  15054. * SimplePie class.
  15055. *
  15056. * Class for backward compatibility.
  15057. *
  15058. * @deprecated Use {@see SimplePie} directly
  15059. * @package SimplePie
  15060. * @subpackage API
  15061. */
  15062. class SimplePie_Core extends SimplePie
  15063. {
  15064. }
  15065. /**
  15066. * Used for feed auto-discovery
  15067. *
  15068. *
  15069. * This class can be overloaded with {@see SimplePie::set_locator_class()}
  15070. *
  15071. * @package SimplePie
  15072. */
  15073. class SimplePie_Locator
  15074. {
  15075. var $useragent;
  15076. var $timeout;
  15077. var $file;
  15078. var $local = array();
  15079. var $elsewhere = array();
  15080. var $cached_entities = array();
  15081. var $http_base;
  15082. var $base;
  15083. var $base_location = 0;
  15084. var $checked_feeds = 0;
  15085. var $max_checked_feeds = 10;
  15086. protected $registry;
  15087. public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10)
  15088. {
  15089. $this->file = $file;
  15090. $this->useragent = $useragent;
  15091. $this->timeout = $timeout;
  15092. $this->max_checked_feeds = $max_checked_feeds;
  15093. if (class_exists('DOMDocument'))
  15094. {
  15095. $this->dom = new DOMDocument();
  15096. set_error_handler(array('SimplePie_Misc', 'silence_errors'));
  15097. $this->dom->loadHTML($this->file->body);
  15098. restore_error_handler();
  15099. }
  15100. else
  15101. {
  15102. $this->dom = null;
  15103. }
  15104. }
  15105. public function set_registry(SimplePie_Registry $registry)
  15106. {
  15107. $this->registry = $registry;
  15108. }
  15109. public function find($type = SIMPLEPIE_LOCATOR_ALL, &$working)
  15110. {
  15111. if ($this->is_feed($this->file))
  15112. {
  15113. return $this->file;
  15114. }
  15115. if ($this->file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  15116. {
  15117. $sniffer = $this->registry->create('Content_Type_Sniffer', array($this->file));
  15118. if ($sniffer->get_type() !== 'text/html')
  15119. {
  15120. return null;
  15121. }
  15122. }
  15123. if ($type & ~SIMPLEPIE_LOCATOR_NONE)
  15124. {
  15125. $this->get_base();
  15126. }
  15127. if ($type & SIMPLEPIE_LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery())
  15128. {
  15129. return $working[0];
  15130. }
  15131. if ($type & (SIMPLEPIE_LOCATOR_LOCAL_EXTENSION | SIMPLEPIE_LOCATOR_LOCAL_BODY | SIMPLEPIE_LOCATOR_REMOTE_EXTENSION | SIMPLEPIE_LOCATOR_REMOTE_BODY) && $this->get_links())
  15132. {
  15133. if ($type & SIMPLEPIE_LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local))
  15134. {
  15135. return $working;
  15136. }
  15137. if ($type & SIMPLEPIE_LOCATOR_LOCAL_BODY && $working = $this->body($this->local))
  15138. {
  15139. return $working;
  15140. }
  15141. if ($type & SIMPLEPIE_LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere))
  15142. {
  15143. return $working;
  15144. }
  15145. if ($type & SIMPLEPIE_LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere))
  15146. {
  15147. return $working;
  15148. }
  15149. }
  15150. return null;
  15151. }
  15152. public function is_feed($file)
  15153. {
  15154. if ($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE)
  15155. {
  15156. $sniffer = $this->registry->create('Content_Type_Sniffer', array($file));
  15157. $sniffed = $sniffer->get_type();
  15158. if (in_array($sniffed, array('application/rss+xml', 'application/rdf+xml', 'text/rdf', 'application/atom+xml', 'text/xml', 'application/xml')))
  15159. {
  15160. return true;
  15161. }
  15162. else
  15163. {
  15164. return false;
  15165. }
  15166. }
  15167. elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL)
  15168. {
  15169. return true;
  15170. }
  15171. else
  15172. {
  15173. return false;
  15174. }
  15175. }
  15176. public function get_base()
  15177. {
  15178. if ($this->dom === null)
  15179. {
  15180. throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
  15181. }
  15182. $this->http_base = $this->file->url;
  15183. $this->base = $this->http_base;
  15184. $elements = $this->dom->getElementsByTagName('base');
  15185. foreach ($elements as $element)
  15186. {
  15187. if ($element->hasAttribute('href'))
  15188. {
  15189. $base = $this->registry->call('Misc', 'absolutize_url', array(trim($element->getAttribute('href')), $this->http_base));
  15190. if ($base === false)
  15191. {
  15192. continue;
  15193. }
  15194. $this->base = $base;
  15195. $this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
  15196. break;
  15197. }
  15198. }
  15199. }
  15200. public function autodiscovery()
  15201. {
  15202. $done = array();
  15203. $feeds = array();
  15204. $feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
  15205. $feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
  15206. $feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
  15207. if (!empty($feeds))
  15208. {
  15209. return array_values($feeds);
  15210. }
  15211. else
  15212. {
  15213. return null;
  15214. }
  15215. }
  15216. protected function search_elements_by_tag($name, &$done, $feeds)
  15217. {
  15218. if ($this->dom === null)
  15219. {
  15220. throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
  15221. }
  15222. $links = $this->dom->getElementsByTagName($name);
  15223. foreach ($links as $link)
  15224. {
  15225. if ($this->checked_feeds === $this->max_checked_feeds)
  15226. {
  15227. break;
  15228. }
  15229. if ($link->hasAttribute('href') && $link->hasAttribute('rel'))
  15230. {
  15231. $rel = array_unique($this->registry->call('Misc', 'space_seperated_tokens', array(strtolower($link->getAttribute('rel')))));
  15232. $line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
  15233. if ($this->base_location < $line)
  15234. {
  15235. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  15236. }
  15237. else
  15238. {
  15239. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  15240. }
  15241. if ($href === false)
  15242. {
  15243. continue;
  15244. }
  15245. if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call('Misc', 'parse_mime', array($link->getAttribute('type')))), array('application/rss+xml', 'application/atom+xml'))) && !isset($feeds[$href]))
  15246. {
  15247. $this->checked_feeds++;
  15248. $headers = array(
  15249. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
  15250. );
  15251. $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent));
  15252. if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
  15253. {
  15254. $feeds[$href] = $feed;
  15255. }
  15256. }
  15257. $done[] = $href;
  15258. }
  15259. }
  15260. return $feeds;
  15261. }
  15262. public function get_links()
  15263. {
  15264. if ($this->dom === null)
  15265. {
  15266. throw new SimplePie_Exception('DOMDocument not found, unable to use locator');
  15267. }
  15268. $links = $this->dom->getElementsByTagName('a');
  15269. foreach ($links as $link)
  15270. {
  15271. if ($link->hasAttribute('href'))
  15272. {
  15273. $href = trim($link->getAttribute('href'));
  15274. $parsed = $this->registry->call('Misc', 'parse_url', array($href));
  15275. if ($parsed['scheme'] === '' || preg_match('/^(http(s)|feed)?$/i', $parsed['scheme']))
  15276. {
  15277. if ($this->base_location < $link->getLineNo())
  15278. {
  15279. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->base));
  15280. }
  15281. else
  15282. {
  15283. $href = $this->registry->call('Misc', 'absolutize_url', array(trim($link->getAttribute('href')), $this->http_base));
  15284. }
  15285. if ($href === false)
  15286. {
  15287. continue;
  15288. }
  15289. $current = $this->registry->call('Misc', 'parse_url', array($this->file->url));
  15290. if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority'])
  15291. {
  15292. $this->local[] = $href;
  15293. }
  15294. else
  15295. {
  15296. $this->elsewhere[] = $href;
  15297. }
  15298. }
  15299. }
  15300. }
  15301. $this->local = array_unique($this->local);
  15302. $this->elsewhere = array_unique($this->elsewhere);
  15303. if (!empty($this->local) || !empty($this->elsewhere))
  15304. {
  15305. return true;
  15306. }
  15307. return null;
  15308. }
  15309. public function extension(&$array)
  15310. {
  15311. foreach ($array as $key => $value)
  15312. {
  15313. if ($this->checked_feeds === $this->max_checked_feeds)
  15314. {
  15315. break;
  15316. }
  15317. if (in_array(strtolower(strrchr($value, '.')), array('.rss', '.rdf', '.atom', '.xml')))
  15318. {
  15319. $this->checked_feeds++;
  15320. $headers = array(
  15321. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
  15322. );
  15323. $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent));
  15324. if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
  15325. {
  15326. return $feed;
  15327. }
  15328. else
  15329. {
  15330. unset($array[$key]);
  15331. }
  15332. }
  15333. }
  15334. return null;
  15335. }
  15336. public function body(&$array)
  15337. {
  15338. foreach ($array as $key => $value)
  15339. {
  15340. if ($this->checked_feeds === $this->max_checked_feeds)
  15341. {
  15342. break;
  15343. }
  15344. if (preg_match('/(rss|rdf|atom|xml)/i', $value))
  15345. {
  15346. $this->checked_feeds++;
  15347. $headers = array(
  15348. 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1',
  15349. );
  15350. $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent));
  15351. if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed))
  15352. {
  15353. return $feed;
  15354. }
  15355. else
  15356. {
  15357. unset($array[$key]);
  15358. }
  15359. }
  15360. }
  15361. return null;
  15362. }
  15363. }
  15364. /**
  15365. * Caches data to the filesystem
  15366. *
  15367. * @package SimplePie
  15368. * @subpackage Caching
  15369. */
  15370. class SimplePie_Cache_File implements SimplePie_Cache_Base
  15371. {
  15372. /**
  15373. * Location string
  15374. *
  15375. * @see SimplePie::$cache_location
  15376. * @var string
  15377. */
  15378. protected $location;
  15379. /**
  15380. * Filename
  15381. *
  15382. * @var string
  15383. */
  15384. protected $filename;
  15385. /**
  15386. * File extension
  15387. *
  15388. * @var string
  15389. */
  15390. protected $extension;
  15391. /**
  15392. * File path
  15393. *
  15394. * @var string
  15395. */
  15396. protected $name;
  15397. /**
  15398. * Create a new cache object
  15399. *
  15400. * @param string $location Location string (from SimplePie::$cache_location)
  15401. * @param string $name Unique ID for the cache
  15402. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  15403. */
  15404. public function __construct($location, $name, $type)
  15405. {
  15406. $this->location = $location;
  15407. $this->filename = $name;
  15408. $this->extension = $type;
  15409. $this->name = "$this->location/$this->filename.$this->extension";
  15410. }
  15411. /**
  15412. * Save data to the cache
  15413. *
  15414. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  15415. * @return bool Successfulness
  15416. */
  15417. public function save($data)
  15418. {
  15419. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  15420. {
  15421. if ($data instanceof SimplePie)
  15422. {
  15423. $data = $data->data;
  15424. }
  15425. $data = serialize($data);
  15426. return (bool) file_put_contents($this->name, $data);
  15427. }
  15428. return false;
  15429. }
  15430. /**
  15431. * Retrieve the data saved to the cache
  15432. *
  15433. * @return array Data for SimplePie::$data
  15434. */
  15435. public function load()
  15436. {
  15437. if (file_exists($this->name) && is_readable($this->name))
  15438. {
  15439. return unserialize(file_get_contents($this->name));
  15440. }
  15441. return false;
  15442. }
  15443. /**
  15444. * Retrieve the last modified time for the cache
  15445. *
  15446. * @return int Timestamp
  15447. */
  15448. public function mtime()
  15449. {
  15450. if (file_exists($this->name))
  15451. {
  15452. return filemtime($this->name);
  15453. }
  15454. return false;
  15455. }
  15456. /**
  15457. * Set the last modified time to the current time
  15458. *
  15459. * @return bool Success status
  15460. */
  15461. public function touch()
  15462. {
  15463. if (file_exists($this->name))
  15464. {
  15465. return touch($this->name);
  15466. }
  15467. return false;
  15468. }
  15469. /**
  15470. * Remove the cache
  15471. *
  15472. * @return bool Success status
  15473. */
  15474. public function unlink()
  15475. {
  15476. if (file_exists($this->name))
  15477. {
  15478. return unlink($this->name);
  15479. }
  15480. return false;
  15481. }
  15482. }
  15483. /**
  15484. * Base class for database-based caches
  15485. *
  15486. * @package SimplePie
  15487. * @subpackage Caching
  15488. */
  15489. abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base
  15490. {
  15491. /**
  15492. * Helper for database conversion
  15493. *
  15494. * Converts a given {@see SimplePie} object into data to be stored
  15495. *
  15496. * @param SimplePie $data
  15497. * @return array First item is the serialized data for storage, second item is the unique ID for this item
  15498. */
  15499. protected static function prepare_simplepie_object_for_cache($data)
  15500. {
  15501. $items = $data->get_items();
  15502. $items_by_id = array();
  15503. if (!empty($items))
  15504. {
  15505. foreach ($items as $item)
  15506. {
  15507. $items_by_id[$item->get_id()] = $item;
  15508. }
  15509. if (count($items_by_id) !== count($items))
  15510. {
  15511. $items_by_id = array();
  15512. foreach ($items as $item)
  15513. {
  15514. $items_by_id[$item->get_id(true)] = $item;
  15515. }
  15516. }
  15517. if (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  15518. {
  15519. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  15520. }
  15521. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  15522. {
  15523. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  15524. }
  15525. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  15526. {
  15527. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  15528. }
  15529. elseif (isset($data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0]))
  15530. {
  15531. $channel =& $data->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_20]['channel'][0];
  15532. }
  15533. else
  15534. {
  15535. $channel = null;
  15536. }
  15537. if ($channel !== null)
  15538. {
  15539. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']))
  15540. {
  15541. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry']);
  15542. }
  15543. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']))
  15544. {
  15545. unset($channel['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['entry']);
  15546. }
  15547. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']))
  15548. {
  15549. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item']);
  15550. }
  15551. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']))
  15552. {
  15553. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item']);
  15554. }
  15555. if (isset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']))
  15556. {
  15557. unset($channel['child'][SIMPLEPIE_NAMESPACE_RSS_20]['item']);
  15558. }
  15559. }
  15560. if (isset($data->data['items']))
  15561. {
  15562. unset($data->data['items']);
  15563. }
  15564. if (isset($data->data['ordered_items']))
  15565. {
  15566. unset($data->data['ordered_items']);
  15567. }
  15568. }
  15569. return array(serialize($data->data), $items_by_id);
  15570. }
  15571. }
  15572. /**
  15573. * Caches data to a MySQL database
  15574. *
  15575. * Registered for URLs with the "mysql" protocol
  15576. *
  15577. * For example, `mysql://root:password@localhost:3306/mydb?prefix=sp_` will
  15578. * connect to the `mydb` database on `localhost` on port 3306, with the user
  15579. * `root` and the password `password`. All tables will be prefixed with `sp_`
  15580. *
  15581. * @package SimplePie
  15582. * @subpackage Caching
  15583. */
  15584. class SimplePie_Cache_MySQL extends SimplePie_Cache_DB
  15585. {
  15586. /**
  15587. * PDO instance
  15588. *
  15589. * @var PDO
  15590. */
  15591. protected $mysql;
  15592. /**
  15593. * Options
  15594. *
  15595. * @var array
  15596. */
  15597. protected $options;
  15598. /**
  15599. * Cache ID
  15600. *
  15601. * @var string
  15602. */
  15603. protected $id;
  15604. /**
  15605. * Create a new cache object
  15606. *
  15607. * @param string $location Location string (from SimplePie::$cache_location)
  15608. * @param string $name Unique ID for the cache
  15609. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  15610. */
  15611. public function __construct($location, $name, $type)
  15612. {
  15613. $this->options = array(
  15614. 'user' => null,
  15615. 'pass' => null,
  15616. 'host' => '127.0.0.1',
  15617. 'port' => '3306',
  15618. 'path' => '',
  15619. 'extras' => array(
  15620. 'prefix' => '',
  15621. ),
  15622. );
  15623. $this->options = array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location));
  15624. // Path is prefixed with a "/"
  15625. $this->options['dbname'] = substr($this->options['path'], 1);
  15626. try
  15627. {
  15628. $this->mysql = new PDO("mysql:dbname={$this->options['dbname']};host={$this->options['host']};port={$this->options['port']}", $this->options['user'], $this->options['pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
  15629. }
  15630. catch (PDOException $e)
  15631. {
  15632. $this->mysql = null;
  15633. return;
  15634. }
  15635. $this->id = $name . $type;
  15636. if (!$query = $this->mysql->query('SHOW TABLES'))
  15637. {
  15638. $this->mysql = null;
  15639. return;
  15640. }
  15641. $db = array();
  15642. while ($row = $query->fetchColumn())
  15643. {
  15644. $db[] = $row;
  15645. }
  15646. if (!in_array($this->options['extras']['prefix'] . 'cache_data', $db))
  15647. {
  15648. $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
  15649. if ($query === false)
  15650. {
  15651. $this->mysql = null;
  15652. }
  15653. }
  15654. if (!in_array($this->options['extras']['prefix'] . 'items', $db))
  15655. {
  15656. $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` TEXT CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
  15657. if ($query === false)
  15658. {
  15659. $this->mysql = null;
  15660. }
  15661. }
  15662. }
  15663. /**
  15664. * Save data to the cache
  15665. *
  15666. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  15667. * @return bool Successfulness
  15668. */
  15669. public function save($data)
  15670. {
  15671. if ($this->mysql === null)
  15672. {
  15673. return false;
  15674. }
  15675. if ($data instanceof SimplePie)
  15676. {
  15677. $data = clone $data;
  15678. $prepared = self::prepare_simplepie_object_for_cache($data);
  15679. $query = $this->mysql->prepare('SELECT COUNT(*) FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  15680. $query->bindValue(':feed', $this->id);
  15681. if ($query->execute())
  15682. {
  15683. if ($query->fetchColumn() > 0)
  15684. {
  15685. $items = count($prepared[1]);
  15686. if ($items)
  15687. {
  15688. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = :items, `data` = :data, `mtime` = :time WHERE `id` = :feed';
  15689. $query = $this->mysql->prepare($sql);
  15690. $query->bindValue(':items', $items);
  15691. }
  15692. else
  15693. {
  15694. $sql = 'UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `data` = :data, `mtime` = :time WHERE `id` = :feed';
  15695. $query = $this->mysql->prepare($sql);
  15696. }
  15697. $query->bindValue(':data', $prepared[0]);
  15698. $query->bindValue(':time', time());
  15699. $query->bindValue(':feed', $this->id);
  15700. if (!$query->execute())
  15701. {
  15702. return false;
  15703. }
  15704. }
  15705. else
  15706. {
  15707. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:feed, :count, :data, :time)');
  15708. $query->bindValue(':feed', $this->id);
  15709. $query->bindValue(':count', count($prepared[1]));
  15710. $query->bindValue(':data', $prepared[0]);
  15711. $query->bindValue(':time', time());
  15712. if (!$query->execute())
  15713. {
  15714. return false;
  15715. }
  15716. }
  15717. $ids = array_keys($prepared[1]);
  15718. if (!empty($ids))
  15719. {
  15720. foreach ($ids as $id)
  15721. {
  15722. $database_ids[] = $this->mysql->quote($id);
  15723. }
  15724. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `id` = ' . implode(' OR `id` = ', $database_ids) . ' AND `feed_id` = :feed');
  15725. $query->bindValue(':feed', $this->id);
  15726. if ($query->execute())
  15727. {
  15728. $existing_ids = array();
  15729. while ($row = $query->fetchColumn())
  15730. {
  15731. $existing_ids[] = $row;
  15732. }
  15733. $new_ids = array_diff($ids, $existing_ids);
  15734. foreach ($new_ids as $new_id)
  15735. {
  15736. if (!($date = $prepared[1][$new_id]->get_date('U')))
  15737. {
  15738. $date = time();
  15739. }
  15740. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'items` (`feed_id`, `id`, `data`, `posted`) VALUES(:feed, :id, :data, :date)');
  15741. $query->bindValue(':feed', $this->id);
  15742. $query->bindValue(':id', $new_id);
  15743. $query->bindValue(':data', serialize($prepared[1][$new_id]->data));
  15744. $query->bindValue(':date', $date);
  15745. if (!$query->execute())
  15746. {
  15747. return false;
  15748. }
  15749. }
  15750. return true;
  15751. }
  15752. }
  15753. else
  15754. {
  15755. return true;
  15756. }
  15757. }
  15758. }
  15759. else
  15760. {
  15761. $query = $this->mysql->prepare('SELECT `id` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :feed');
  15762. $query->bindValue(':feed', $this->id);
  15763. if ($query->execute())
  15764. {
  15765. if ($query->rowCount() > 0)
  15766. {
  15767. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `items` = 0, `data` = :data, `mtime` = :time WHERE `id` = :feed');
  15768. $query->bindValue(':data', serialize($data));
  15769. $query->bindValue(':time', time());
  15770. $query->bindValue(':feed', $this->id);
  15771. if ($this->execute())
  15772. {
  15773. return true;
  15774. }
  15775. }
  15776. else
  15777. {
  15778. $query = $this->mysql->prepare('INSERT INTO `' . $this->options['extras']['prefix'] . 'cache_data` (`id`, `items`, `data`, `mtime`) VALUES(:id, 0, :data, :time)');
  15779. $query->bindValue(':id', $this->id);
  15780. $query->bindValue(':data', serialize($data));
  15781. $query->bindValue(':time', time());
  15782. if ($query->execute())
  15783. {
  15784. return true;
  15785. }
  15786. }
  15787. }
  15788. }
  15789. return false;
  15790. }
  15791. /**
  15792. * Retrieve the data saved to the cache
  15793. *
  15794. * @return array Data for SimplePie::$data
  15795. */
  15796. public function load()
  15797. {
  15798. if ($this->mysql === null)
  15799. {
  15800. return false;
  15801. }
  15802. $query = $this->mysql->prepare('SELECT `items`, `data` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  15803. $query->bindValue(':id', $this->id);
  15804. if ($query->execute() && ($row = $query->fetch()))
  15805. {
  15806. $data = unserialize($row[1]);
  15807. if (isset($this->options['items'][0]))
  15808. {
  15809. $items = (int) $this->options['items'][0];
  15810. }
  15811. else
  15812. {
  15813. $items = (int) $row[0];
  15814. }
  15815. if ($items !== 0)
  15816. {
  15817. if (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]))
  15818. {
  15819. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0];
  15820. }
  15821. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]))
  15822. {
  15823. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0];
  15824. }
  15825. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]))
  15826. {
  15827. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0];
  15828. }
  15829. elseif (isset($data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]))
  15830. {
  15831. $feed =& $data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0];
  15832. }
  15833. else
  15834. {
  15835. $feed = null;
  15836. }
  15837. if ($feed !== null)
  15838. {
  15839. $sql = 'SELECT `data` FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :feed ORDER BY `posted` DESC';
  15840. if ($items > 0)
  15841. {
  15842. $sql .= ' LIMIT ' . $items;
  15843. }
  15844. $query = $this->mysql->prepare($sql);
  15845. $query->bindValue(':feed', $this->id);
  15846. if ($query->execute())
  15847. {
  15848. while ($row = $query->fetchColumn())
  15849. {
  15850. $feed['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
  15851. }
  15852. }
  15853. else
  15854. {
  15855. return false;
  15856. }
  15857. }
  15858. }
  15859. return $data;
  15860. }
  15861. return false;
  15862. }
  15863. /**
  15864. * Retrieve the last modified time for the cache
  15865. *
  15866. * @return int Timestamp
  15867. */
  15868. public function mtime()
  15869. {
  15870. if ($this->mysql === null)
  15871. {
  15872. return false;
  15873. }
  15874. $query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  15875. $query->bindValue(':id', $this->id);
  15876. if ($query->execute() && ($time = $query->fetchColumn()))
  15877. {
  15878. return $time;
  15879. }
  15880. else
  15881. {
  15882. return false;
  15883. }
  15884. }
  15885. /**
  15886. * Set the last modified time to the current time
  15887. *
  15888. * @return bool Success status
  15889. */
  15890. public function touch()
  15891. {
  15892. if ($this->mysql === null)
  15893. {
  15894. return false;
  15895. }
  15896. $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id');
  15897. $query->bindValue(':time', time());
  15898. $query->bindValue(':id', $this->id);
  15899. if ($query->execute() && $query->rowCount() > 0)
  15900. {
  15901. return true;
  15902. }
  15903. else
  15904. {
  15905. return false;
  15906. }
  15907. }
  15908. /**
  15909. * Remove the cache
  15910. *
  15911. * @return bool Success status
  15912. */
  15913. public function unlink()
  15914. {
  15915. if ($this->mysql === null)
  15916. {
  15917. return false;
  15918. }
  15919. $query = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
  15920. $query->bindValue(':id', $this->id);
  15921. $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id');
  15922. $query2->bindValue(':id', $this->id);
  15923. if ($query->execute() && $query2->execute())
  15924. {
  15925. return true;
  15926. }
  15927. else
  15928. {
  15929. return false;
  15930. }
  15931. }
  15932. }
  15933. /**
  15934. * Base for cache objects
  15935. *
  15936. * Classes to be used with {@see SimplePie_Cache::register()} are expected
  15937. * to implement this interface.
  15938. *
  15939. * @package SimplePie
  15940. * @subpackage Caching
  15941. */
  15942. interface SimplePie_Cache_Base
  15943. {
  15944. /**
  15945. * Feed cache type
  15946. *
  15947. * @var string
  15948. */
  15949. const TYPE_FEED = 'spc';
  15950. /**
  15951. * Image cache type
  15952. *
  15953. * @var string
  15954. */
  15955. const TYPE_IMAGE = 'spi';
  15956. /**
  15957. * Create a new cache object
  15958. *
  15959. * @param string $location Location string (from SimplePie::$cache_location)
  15960. * @param string $name Unique ID for the cache
  15961. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  15962. */
  15963. public function __construct($location, $name, $type);
  15964. /**
  15965. * Save data to the cache
  15966. *
  15967. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  15968. * @return bool Successfulness
  15969. */
  15970. public function save($data);
  15971. /**
  15972. * Retrieve the data saved to the cache
  15973. *
  15974. * @return array Data for SimplePie::$data
  15975. */
  15976. public function load();
  15977. /**
  15978. * Retrieve the last modified time for the cache
  15979. *
  15980. * @return int Timestamp
  15981. */
  15982. public function mtime();
  15983. /**
  15984. * Set the last modified time to the current time
  15985. *
  15986. * @return bool Success status
  15987. */
  15988. public function touch();
  15989. /**
  15990. * Remove the cache
  15991. *
  15992. * @return bool Success status
  15993. */
  15994. public function unlink();
  15995. }
  15996. /**
  15997. * Caches data to memcache
  15998. *
  15999. * Registered for URLs with the "memcache" protocol
  16000. *
  16001. * For example, `memcache://localhost:11211/?timeout=3600&prefix=sp_` will
  16002. * connect to memcache on `localhost` on port 11211. All tables will be
  16003. * prefixed with `sp_` and data will expire after 3600 seconds
  16004. *
  16005. * @package SimplePie
  16006. * @subpackage Caching
  16007. * @uses Memcache
  16008. */
  16009. class SimplePie_Cache_Memcache implements SimplePie_Cache_Base
  16010. {
  16011. /**
  16012. * Memcache instance
  16013. *
  16014. * @var Memcache
  16015. */
  16016. protected $cache;
  16017. /**
  16018. * Options
  16019. *
  16020. * @var array
  16021. */
  16022. protected $options;
  16023. /**
  16024. * Cache name
  16025. *
  16026. * @var string
  16027. */
  16028. protected $name;
  16029. /**
  16030. * Create a new cache object
  16031. *
  16032. * @param string $location Location string (from SimplePie::$cache_location)
  16033. * @param string $name Unique ID for the cache
  16034. * @param string $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
  16035. */
  16036. public function __construct($location, $name, $type)
  16037. {
  16038. $this->options = array(
  16039. 'host' => '127.0.0.1',
  16040. 'port' => 11211,
  16041. 'extras' => array(
  16042. 'timeout' => 3600, // one hour
  16043. 'prefix' => 'simplepie_',
  16044. ),
  16045. );
  16046. $parsed = SimplePie_Cache::parse_URL($location);
  16047. $this->options['host'] = empty($parsed['host']) ? $this->options['host'] : $parsed['host'];
  16048. $this->options['port'] = empty($parsed['port']) ? $this->options['port'] : $parsed['port'];
  16049. $this->options['extras'] = array_merge($this->options['extras'], $parsed['extras']);
  16050. $this->name = $this->options['extras']['prefix'] . md5("$name:$type");
  16051. $this->cache = new Memcache();
  16052. $this->cache->addServer($this->options['host'], (int) $this->options['port']);
  16053. }
  16054. /**
  16055. * Save data to the cache
  16056. *
  16057. * @param array|SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
  16058. * @return bool Successfulness
  16059. */
  16060. public function save($data)
  16061. {
  16062. if ($data instanceof SimplePie)
  16063. {
  16064. $data = $data->data;
  16065. }
  16066. return $this->cache->set($this->name, serialize($data), MEMCACHE_COMPRESSED, (int) $this->options['extras']['timeout']);
  16067. }
  16068. /**
  16069. * Retrieve the data saved to the cache
  16070. *
  16071. * @return array Data for SimplePie::$data
  16072. */
  16073. public function load()
  16074. {
  16075. $data = $this->cache->get($this->name);
  16076. if ($data !== false)
  16077. {
  16078. return unserialize($data);
  16079. }
  16080. return false;
  16081. }
  16082. /**
  16083. * Retrieve the last modified time for the cache
  16084. *
  16085. * @return int Timestamp
  16086. */
  16087. public function mtime()
  16088. {
  16089. $data = $this->cache->get($this->name);
  16090. if ($data !== false)
  16091. {
  16092. // essentially ignore the mtime because Memcache expires on it's own
  16093. return time();
  16094. }
  16095. return false;
  16096. }
  16097. /**
  16098. * Set the last modified time to the current time
  16099. *
  16100. * @return bool Success status
  16101. */
  16102. public function touch()
  16103. {
  16104. $data = $this->cache->get($this->name);
  16105. if ($data !== false)
  16106. {
  16107. return $this->cache->set($this->name, $data, MEMCACHE_COMPRESSED, (int) $this->duration);
  16108. }
  16109. return false;
  16110. }
  16111. /**
  16112. * Remove the cache
  16113. *
  16114. * @return bool Success status
  16115. */
  16116. public function unlink()
  16117. {
  16118. return $this->cache->delete($this->name, 0);
  16119. }
  16120. }
  16121. /**
  16122. * Parses the XML Declaration
  16123. *
  16124. * @package SimplePie
  16125. * @subpackage Parsing
  16126. */
  16127. class SimplePie_XML_Declaration_Parser
  16128. {
  16129. /**
  16130. * XML Version
  16131. *
  16132. * @access public
  16133. * @var string
  16134. */
  16135. var $version = '1.0';
  16136. /**
  16137. * Encoding
  16138. *
  16139. * @access public
  16140. * @var string
  16141. */
  16142. var $encoding = 'UTF-8';
  16143. /**
  16144. * Standalone
  16145. *
  16146. * @access public
  16147. * @var bool
  16148. */
  16149. var $standalone = false;
  16150. /**
  16151. * Current state of the state machine
  16152. *
  16153. * @access private
  16154. * @var string
  16155. */
  16156. var $state = 'before_version_name';
  16157. /**
  16158. * Input data
  16159. *
  16160. * @access private
  16161. * @var string
  16162. */
  16163. var $data = '';
  16164. /**
  16165. * Input data length (to avoid calling strlen() everytime this is needed)
  16166. *
  16167. * @access private
  16168. * @var int
  16169. */
  16170. var $data_length = 0;
  16171. /**
  16172. * Current position of the pointer
  16173. *
  16174. * @var int
  16175. * @access private
  16176. */
  16177. var $position = 0;
  16178. /**
  16179. * Create an instance of the class with the input data
  16180. *
  16181. * @access public
  16182. * @param string $data Input data
  16183. */
  16184. public function __construct($data)
  16185. {
  16186. $this->data = $data;
  16187. $this->data_length = strlen($this->data);
  16188. }
  16189. /**
  16190. * Parse the input data
  16191. *
  16192. * @access public
  16193. * @return bool true on success, false on failure
  16194. */
  16195. public function parse()
  16196. {
  16197. while ($this->state && $this->state !== 'emit' && $this->has_data())
  16198. {
  16199. $state = $this->state;
  16200. $this->$state();
  16201. }
  16202. $this->data = '';
  16203. if ($this->state === 'emit')
  16204. {
  16205. return true;
  16206. }
  16207. else
  16208. {
  16209. $this->version = '';
  16210. $this->encoding = '';
  16211. $this->standalone = '';
  16212. return false;
  16213. }
  16214. }
  16215. /**
  16216. * Check whether there is data beyond the pointer
  16217. *
  16218. * @access private
  16219. * @return bool true if there is further data, false if not
  16220. */
  16221. public function has_data()
  16222. {
  16223. return (bool) ($this->position < $this->data_length);
  16224. }
  16225. /**
  16226. * Advance past any whitespace
  16227. *
  16228. * @return int Number of whitespace characters passed
  16229. */
  16230. public function skip_whitespace()
  16231. {
  16232. $whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
  16233. $this->position += $whitespace;
  16234. return $whitespace;
  16235. }
  16236. /**
  16237. * Read value
  16238. */
  16239. public function get_value()
  16240. {
  16241. $quote = substr($this->data, $this->position, 1);
  16242. if ($quote === '"' || $quote === "'")
  16243. {
  16244. $this->position++;
  16245. $len = strcspn($this->data, $quote, $this->position);
  16246. if ($this->has_data())
  16247. {
  16248. $value = substr($this->data, $this->position, $len);
  16249. $this->position += $len + 1;
  16250. return $value;
  16251. }
  16252. }
  16253. return false;
  16254. }
  16255. public function before_version_name()
  16256. {
  16257. if ($this->skip_whitespace())
  16258. {
  16259. $this->state = 'version_name';
  16260. }
  16261. else
  16262. {
  16263. $this->state = false;
  16264. }
  16265. }
  16266. public function version_name()
  16267. {
  16268. if (substr($this->data, $this->position, 7) === 'version')
  16269. {
  16270. $this->position += 7;
  16271. $this->skip_whitespace();
  16272. $this->state = 'version_equals';
  16273. }
  16274. else
  16275. {
  16276. $this->state = false;
  16277. }
  16278. }
  16279. public function version_equals()
  16280. {
  16281. if (substr($this->data, $this->position, 1) === '=')
  16282. {
  16283. $this->position++;
  16284. $this->skip_whitespace();
  16285. $this->state = 'version_value';
  16286. }
  16287. else
  16288. {
  16289. $this->state = false;
  16290. }
  16291. }
  16292. public function version_value()
  16293. {
  16294. if ($this->version = $this->get_value())
  16295. {
  16296. $this->skip_whitespace();
  16297. if ($this->has_data())
  16298. {
  16299. $this->state = 'encoding_name';
  16300. }
  16301. else
  16302. {
  16303. $this->state = 'emit';
  16304. }
  16305. }
  16306. else
  16307. {
  16308. $this->state = false;
  16309. }
  16310. }
  16311. public function encoding_name()
  16312. {
  16313. if (substr($this->data, $this->position, 8) === 'encoding')
  16314. {
  16315. $this->position += 8;
  16316. $this->skip_whitespace();
  16317. $this->state = 'encoding_equals';
  16318. }
  16319. else
  16320. {
  16321. $this->state = 'standalone_name';
  16322. }
  16323. }
  16324. public function encoding_equals()
  16325. {
  16326. if (substr($this->data, $this->position, 1) === '=')
  16327. {
  16328. $this->position++;
  16329. $this->skip_whitespace();
  16330. $this->state = 'encoding_value';
  16331. }
  16332. else
  16333. {
  16334. $this->state = false;
  16335. }
  16336. }
  16337. public function encoding_value()
  16338. {
  16339. if ($this->encoding = $this->get_value())
  16340. {
  16341. $this->skip_whitespace();
  16342. if ($this->has_data())
  16343. {
  16344. $this->state = 'standalone_name';
  16345. }
  16346. else
  16347. {
  16348. $this->state = 'emit';
  16349. }
  16350. }
  16351. else
  16352. {
  16353. $this->state = false;
  16354. }
  16355. }
  16356. public function standalone_name()
  16357. {
  16358. if (substr($this->data, $this->position, 10) === 'standalone')
  16359. {
  16360. $this->position += 10;
  16361. $this->skip_whitespace();
  16362. $this->state = 'standalone_equals';
  16363. }
  16364. else
  16365. {
  16366. $this->state = false;
  16367. }
  16368. }
  16369. public function standalone_equals()
  16370. {
  16371. if (substr($this->data, $this->position, 1) === '=')
  16372. {
  16373. $this->position++;
  16374. $this->skip_whitespace();
  16375. $this->state = 'standalone_value';
  16376. }
  16377. else
  16378. {
  16379. $this->state = false;
  16380. }
  16381. }
  16382. public function standalone_value()
  16383. {
  16384. if ($standalone = $this->get_value())
  16385. {
  16386. switch ($standalone)
  16387. {
  16388. case 'yes':
  16389. $this->standalone = true;
  16390. break;
  16391. case 'no':
  16392. $this->standalone = false;
  16393. break;
  16394. default:
  16395. $this->state = false;
  16396. return;
  16397. }
  16398. $this->skip_whitespace();
  16399. if ($this->has_data())
  16400. {
  16401. $this->state = false;
  16402. }
  16403. else
  16404. {
  16405. $this->state = 'emit';
  16406. }
  16407. }
  16408. else
  16409. {
  16410. $this->state = false;
  16411. }
  16412. }
  16413. }