PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/libraries/simplepie/library/SimplePie/Item.php

https://bitbucket.org/fivefilters/full-text-rss
PHP | 2989 lines | 2432 code | 116 blank | 441 comment | 358 complexity | 940118005b5064bc091d9496f092cde3 MD5 | raw file

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

  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-2016, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package SimplePie
  36. * @copyright 2004-2016 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  37. * @author Ryan Parman
  38. * @author Geoffrey Sneddon
  39. * @author Ryan McCue
  40. * @link http://simplepie.org/ SimplePie
  41. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  42. */
  43. /**
  44. * Manages all item-related data
  45. *
  46. * Used by {@see SimplePie::get_item()} and {@see SimplePie::get_items()}
  47. *
  48. * This class can be overloaded with {@see SimplePie::set_item_class()}
  49. *
  50. * @package SimplePie
  51. * @subpackage API
  52. */
  53. class SimplePie_Item
  54. {
  55. /**
  56. * Parent feed
  57. *
  58. * @access private
  59. * @var SimplePie
  60. */
  61. var $feed;
  62. /**
  63. * Raw data
  64. *
  65. * @access private
  66. * @var array
  67. */
  68. var $data = array();
  69. /**
  70. * Registry object
  71. *
  72. * @see set_registry
  73. * @var SimplePie_Registry
  74. */
  75. protected $registry;
  76. /**
  77. * Create a new item object
  78. *
  79. * This is usually used by {@see SimplePie::get_items} and
  80. * {@see SimplePie::get_item}. Avoid creating this manually.
  81. *
  82. * @param SimplePie $feed Parent feed
  83. * @param array $data Raw data
  84. */
  85. public function __construct($feed, $data)
  86. {
  87. $this->feed = $feed;
  88. $this->data = $data;
  89. }
  90. /**
  91. * Set the registry handler
  92. *
  93. * This is usually used by {@see SimplePie_Registry::create}
  94. *
  95. * @since 1.3
  96. * @param SimplePie_Registry $registry
  97. */
  98. public function set_registry(SimplePie_Registry $registry)
  99. {
  100. $this->registry = $registry;
  101. }
  102. /**
  103. * Get a string representation of the item
  104. *
  105. * @return string
  106. */
  107. public function __toString()
  108. {
  109. return md5(serialize($this->data));
  110. }
  111. /**
  112. * Remove items that link back to this before destroying this object
  113. */
  114. public function __destruct()
  115. {
  116. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  117. {
  118. unset($this->feed);
  119. }
  120. }
  121. /**
  122. * Get data for an item-level element
  123. *
  124. * This method allows you to get access to ANY element/attribute that is a
  125. * sub-element of the item/entry tag.
  126. *
  127. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  128. *
  129. * @since 1.0
  130. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  131. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  132. * @param string $tag Tag name
  133. * @return array
  134. */
  135. public function get_item_tags($namespace, $tag)
  136. {
  137. if (isset($this->data['child'][$namespace][$tag]))
  138. {
  139. return $this->data['child'][$namespace][$tag];
  140. }
  141. else
  142. {
  143. return null;
  144. }
  145. }
  146. /**
  147. * Get the base URL value from the parent feed
  148. *
  149. * Uses `<xml:base>`
  150. *
  151. * @param array $element
  152. * @return string
  153. */
  154. public function get_base($element = array())
  155. {
  156. return $this->feed->get_base($element);
  157. }
  158. /**
  159. * Sanitize feed data
  160. *
  161. * @access private
  162. * @see SimplePie::sanitize()
  163. * @param string $data Data to sanitize
  164. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
  165. * @param string $base Base URL to resolve URLs against
  166. * @return string Sanitized data
  167. */
  168. public function sanitize($data, $type, $base = '')
  169. {
  170. return $this->feed->sanitize($data, $type, $base);
  171. }
  172. /**
  173. * Get the parent feed
  174. *
  175. * Note: this may not work as you think for multifeeds!
  176. *
  177. * @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed
  178. * @since 1.0
  179. * @return SimplePie
  180. */
  181. public function get_feed()
  182. {
  183. return $this->feed;
  184. }
  185. /**
  186. * Get the unique identifier for the item
  187. *
  188. * This is usually used when writing code to check for new items in a feed.
  189. *
  190. * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute
  191. * for RDF. If none of these are supplied (or `$hash` is true), creates an
  192. * MD5 hash based on the permalink, title and content.
  193. *
  194. * @since Beta 2
  195. * @param boolean $hash Should we force using a hash instead of the supplied ID?
  196. * @return string
  197. */
  198. public function get_id($hash = false, $fn = '')
  199. {
  200. if (!$hash)
  201. {
  202. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  203. {
  204. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  205. }
  206. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  207. {
  208. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  209. }
  210. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  211. {
  212. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  213. }
  214. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  215. {
  216. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  217. }
  218. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  219. {
  220. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  221. }
  222. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  223. {
  224. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  225. }
  226. }
  227. if ($fn === '' || !is_callable($fn)) $fn = 'md5';
  228. return call_user_func($fn,
  229. $this->get_permalink().$this->get_title().$this->get_content());
  230. }
  231. /**
  232. * Get the title of the item
  233. *
  234. * Uses `<atom:title>`, `<title>` or `<dc:title>`
  235. *
  236. * @since Beta 2 (previously called `get_item_title` since 0.8)
  237. * @return string|null
  238. */
  239. public function get_title()
  240. {
  241. if (!isset($this->data['title']))
  242. {
  243. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  244. {
  245. $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]));
  246. }
  247. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  248. {
  249. $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]));
  250. }
  251. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  252. {
  253. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  254. }
  255. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  256. {
  257. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  258. }
  259. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  260. {
  261. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  262. }
  263. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  264. {
  265. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  266. }
  267. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  268. {
  269. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  270. }
  271. else
  272. {
  273. $this->data['title'] = null;
  274. }
  275. }
  276. return $this->data['title'];
  277. }
  278. /**
  279. * Get the content for the item
  280. *
  281. * Prefers summaries over full content , but will return full content if a
  282. * summary does not exist.
  283. *
  284. * To prefer full content instead, use {@see get_content}
  285. *
  286. * Uses `<atom:summary>`, `<description>`, `<dc:description>` or
  287. * `<itunes:subtitle>`
  288. *
  289. * @since 0.8
  290. * @param boolean $description_only Should we avoid falling back to the content?
  291. * @return string|null
  292. */
  293. public function get_description($description_only = false)
  294. {
  295. if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) &&
  296. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  297. {
  298. return $return;
  299. }
  300. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) &&
  301. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  302. {
  303. return $return;
  304. }
  305. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) &&
  306. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($tags[0]))))
  307. {
  308. return $return;
  309. }
  310. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) &&
  311. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  312. {
  313. return $return;
  314. }
  315. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) &&
  316. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  317. {
  318. return $return;
  319. }
  320. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) &&
  321. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  322. {
  323. return $return;
  324. }
  325. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) &&
  326. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  327. {
  328. return $return;
  329. }
  330. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) &&
  331. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  332. {
  333. return $return;
  334. }
  335. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) &&
  336. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)))
  337. {
  338. return $return;
  339. }
  340. elseif (!$description_only)
  341. {
  342. return $this->get_content(true);
  343. }
  344. else
  345. {
  346. return null;
  347. }
  348. }
  349. /**
  350. * Get the content for the item
  351. *
  352. * Prefers full content over summaries, but will return a summary if full
  353. * content does not exist.
  354. *
  355. * To prefer summaries instead, use {@see get_description}
  356. *
  357. * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
  358. *
  359. * @since 1.0
  360. * @param boolean $content_only Should we avoid falling back to the description?
  361. * @return string|null
  362. */
  363. public function get_content($content_only = false)
  364. {
  365. if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) &&
  366. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  367. {
  368. return $return;
  369. }
  370. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) &&
  371. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  372. {
  373. return $return;
  374. }
  375. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) &&
  376. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  377. {
  378. return $return;
  379. }
  380. elseif (!$content_only)
  381. {
  382. return $this->get_description(true);
  383. }
  384. else
  385. {
  386. return null;
  387. }
  388. }
  389. /**
  390. * Get the media:thumbnail of the item
  391. *
  392. * Uses `<media:thumbnail>`
  393. *
  394. *
  395. * @return array|null
  396. */
  397. public function get_thumbnail()
  398. {
  399. if (!isset($this->data['thumbnail']))
  400. {
  401. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  402. {
  403. $this->data['thumbnail'] = $return[0]['attribs'][''];
  404. }
  405. else
  406. {
  407. $this->data['thumbnail'] = null;
  408. }
  409. }
  410. return $this->data['thumbnail'];
  411. }
  412. /**
  413. * Get a category for the item
  414. *
  415. * @since Beta 3 (previously called `get_categories()` since Beta 2)
  416. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
  417. * @return SimplePie_Category|null
  418. */
  419. public function get_category($key = 0)
  420. {
  421. $categories = $this->get_categories();
  422. if (isset($categories[$key]))
  423. {
  424. return $categories[$key];
  425. }
  426. else
  427. {
  428. return null;
  429. }
  430. }
  431. /**
  432. * Get all categories for the item
  433. *
  434. * Uses `<atom:category>`, `<category>` or `<dc:subject>`
  435. *
  436. * @since Beta 3
  437. * @return SimplePie_Category[]|null List of {@see SimplePie_Category} objects
  438. */
  439. public function get_categories()
  440. {
  441. $categories = array();
  442. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  443. {
  444. $term = null;
  445. $scheme = null;
  446. $label = null;
  447. if (isset($category['attribs']['']['term']))
  448. {
  449. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_HTML);
  450. }
  451. if (isset($category['attribs']['']['scheme']))
  452. {
  453. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_HTML);
  454. }
  455. if (isset($category['attribs']['']['label']))
  456. {
  457. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_HTML);
  458. }
  459. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  460. }
  461. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  462. {
  463. // This is really the label, but keep this as the term also for BC.
  464. // Label will also work on retrieving because that falls back to term.
  465. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML);
  466. if (isset($category['attribs']['']['domain']))
  467. {
  468. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_HTML);
  469. }
  470. else
  471. {
  472. $scheme = null;
  473. }
  474. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  475. }
  476. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  477. {
  478. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  479. }
  480. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  481. {
  482. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  483. }
  484. if (!empty($categories))
  485. {
  486. return array_unique($categories);
  487. }
  488. else
  489. {
  490. return null;
  491. }
  492. }
  493. /**
  494. * Get an author for the item
  495. *
  496. * @since Beta 2
  497. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
  498. * @return SimplePie_Author|null
  499. */
  500. public function get_author($key = 0)
  501. {
  502. $authors = $this->get_authors();
  503. if (isset($authors[$key]))
  504. {
  505. return $authors[$key];
  506. }
  507. else
  508. {
  509. return null;
  510. }
  511. }
  512. /**
  513. * Get a contributor for the item
  514. *
  515. * @since 1.1
  516. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
  517. * @return SimplePie_Author|null
  518. */
  519. public function get_contributor($key = 0)
  520. {
  521. $contributors = $this->get_contributors();
  522. if (isset($contributors[$key]))
  523. {
  524. return $contributors[$key];
  525. }
  526. else
  527. {
  528. return null;
  529. }
  530. }
  531. /**
  532. * Get all contributors for the item
  533. *
  534. * Uses `<atom:contributor>`
  535. *
  536. * @since 1.1
  537. * @return array|null List of {@see SimplePie_Author} objects
  538. */
  539. public function get_contributors()
  540. {
  541. $contributors = array();
  542. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  543. {
  544. $name = null;
  545. $uri = null;
  546. $email = null;
  547. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  548. {
  549. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  550. }
  551. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  552. {
  553. $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]));
  554. }
  555. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  556. {
  557. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  558. }
  559. if ($name !== null || $email !== null || $uri !== null)
  560. {
  561. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  562. }
  563. }
  564. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  565. {
  566. $name = null;
  567. $url = null;
  568. $email = null;
  569. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  570. {
  571. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  572. }
  573. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  574. {
  575. $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]));
  576. }
  577. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  578. {
  579. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  580. }
  581. if ($name !== null || $email !== null || $url !== null)
  582. {
  583. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  584. }
  585. }
  586. if (!empty($contributors))
  587. {
  588. return array_unique($contributors);
  589. }
  590. else
  591. {
  592. return null;
  593. }
  594. }
  595. /**
  596. * Get all authors for the item
  597. *
  598. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
  599. *
  600. * @since Beta 2
  601. * @return array|null List of {@see SimplePie_Author} objects
  602. */
  603. public function get_authors()
  604. {
  605. $authors = array();
  606. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  607. {
  608. $name = null;
  609. $uri = null;
  610. $email = null;
  611. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  612. {
  613. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  614. }
  615. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  616. {
  617. $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]));
  618. }
  619. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  620. {
  621. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  622. }
  623. if ($name !== null || $email !== null || $uri !== null)
  624. {
  625. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  626. }
  627. }
  628. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  629. {
  630. $name = null;
  631. $url = null;
  632. $email = null;
  633. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  634. {
  635. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  636. }
  637. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  638. {
  639. $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]));
  640. }
  641. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  642. {
  643. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  644. }
  645. if ($name !== null || $email !== null || $url !== null)
  646. {
  647. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  648. }
  649. }
  650. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  651. {
  652. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)));
  653. }
  654. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  655. {
  656. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  657. }
  658. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  659. {
  660. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  661. }
  662. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  663. {
  664. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  665. }
  666. if (!empty($authors))
  667. {
  668. return array_unique($authors);
  669. }
  670. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  671. {
  672. return $authors;
  673. }
  674. elseif ($authors = $this->feed->get_authors())
  675. {
  676. return $authors;
  677. }
  678. else
  679. {
  680. return null;
  681. }
  682. }
  683. /**
  684. * Get the copyright info for the item
  685. *
  686. * Uses `<atom:rights>` or `<dc:rights>`
  687. *
  688. * @since 1.1
  689. * @return string
  690. */
  691. public function get_copyright()
  692. {
  693. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  694. {
  695. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  696. }
  697. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  698. {
  699. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  700. }
  701. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  702. {
  703. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  704. }
  705. else
  706. {
  707. return null;
  708. }
  709. }
  710. /**
  711. * Get the posting date/time for the item
  712. *
  713. * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`,
  714. * `<atom:modified>`, `<pubDate>` or `<dc:date>`
  715. *
  716. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  717. * {@see get_gmdate}
  718. *
  719. * @since Beta 2 (previously called `get_item_date` since 0.8)
  720. *
  721. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  722. * @return int|string|null
  723. */
  724. public function get_date($date_format = 'j F Y, g:i a')
  725. {
  726. if (!isset($this->data['date']))
  727. {
  728. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  729. {
  730. $this->data['date']['raw'] = $return[0]['data'];
  731. }
  732. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  733. {
  734. $this->data['date']['raw'] = $return[0]['data'];
  735. }
  736. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  737. {
  738. $this->data['date']['raw'] = $return[0]['data'];
  739. }
  740. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  741. {
  742. $this->data['date']['raw'] = $return[0]['data'];
  743. }
  744. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  745. {
  746. $this->data['date']['raw'] = $return[0]['data'];
  747. }
  748. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  749. {
  750. $this->data['date']['raw'] = $return[0]['data'];
  751. }
  752. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  753. {
  754. $this->data['date']['raw'] = $return[0]['data'];
  755. }
  756. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  757. {
  758. $this->data['date']['raw'] = $return[0]['data'];
  759. }
  760. if (!empty($this->data['date']['raw']))
  761. {
  762. $parser = $this->registry->call('Parse_Date', 'get');
  763. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  764. }
  765. else
  766. {
  767. $this->data['date'] = null;
  768. }
  769. }
  770. if ($this->data['date'])
  771. {
  772. $date_format = (string) $date_format;
  773. switch ($date_format)
  774. {
  775. case '':
  776. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  777. case 'U':
  778. return $this->data['date']['parsed'];
  779. default:
  780. return date($date_format, $this->data['date']['parsed']);
  781. }
  782. }
  783. else
  784. {
  785. return null;
  786. }
  787. }
  788. /**
  789. * Get the update date/time for the item
  790. *
  791. * Uses `<atom:updated>`
  792. *
  793. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  794. * {@see get_gmdate}
  795. *
  796. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  797. * @return int|string|null
  798. */
  799. public function get_updated_date($date_format = 'j F Y, g:i a')
  800. {
  801. if (!isset($this->data['updated']))
  802. {
  803. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  804. {
  805. $this->data['updated']['raw'] = $return[0]['data'];
  806. }
  807. if (!empty($this->data['updated']['raw']))
  808. {
  809. $parser = $this->registry->call('Parse_Date', 'get');
  810. $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']);
  811. }
  812. else
  813. {
  814. $this->data['updated'] = null;
  815. }
  816. }
  817. if ($this->data['updated'])
  818. {
  819. $date_format = (string) $date_format;
  820. switch ($date_format)
  821. {
  822. case '':
  823. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  824. case 'U':
  825. return $this->data['updated']['parsed'];
  826. default:
  827. return date($date_format, $this->data['updated']['parsed']);
  828. }
  829. }
  830. else
  831. {
  832. return null;
  833. }
  834. }
  835. /**
  836. * Get the localized posting date/time for the item
  837. *
  838. * Returns the date formatted in the localized language. To display in
  839. * languages other than the server's default, you need to change the locale
  840. * with {@link http://php.net/setlocale setlocale()}. The available
  841. * localizations depend on which ones are installed on your web server.
  842. *
  843. * @since 1.0
  844. *
  845. * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data)
  846. * @return int|string|null
  847. */
  848. public function get_local_date($date_format = '%c')
  849. {
  850. if (!$date_format)
  851. {
  852. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  853. }
  854. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  855. {
  856. return strftime($date_format, $date);
  857. }
  858. else
  859. {
  860. return null;
  861. }
  862. }
  863. /**
  864. * Get the posting date/time for the item (UTC time)
  865. *
  866. * @see get_date
  867. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  868. * @return int|string|null
  869. */
  870. public function get_gmdate($date_format = 'j F Y, g:i a')
  871. {
  872. $date = $this->get_date('U');
  873. if ($date === null)
  874. {
  875. return null;
  876. }
  877. return gmdate($date_format, $date);
  878. }
  879. /**
  880. * Get the update date/time for the item (UTC time)
  881. *
  882. * @see get_updated_date
  883. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  884. * @return int|string|null
  885. */
  886. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  887. {
  888. $date = $this->get_updated_date('U');
  889. if ($date === null)
  890. {
  891. return null;
  892. }
  893. return gmdate($date_format, $date);
  894. }
  895. /**
  896. * Get the permalink for the item
  897. *
  898. * Returns the first link available with a relationship of "alternate".
  899. * Identical to {@see get_link()} with key 0
  900. *
  901. * @see get_link
  902. * @since 0.8
  903. * @return string|null Permalink URL
  904. */
  905. public function get_permalink()
  906. {
  907. $link = $this->get_link();
  908. $enclosure = $this->get_enclosure(0);
  909. if ($link !== null)
  910. {
  911. return $link;
  912. }
  913. elseif ($enclosure !== null)
  914. {
  915. return $enclosure->get_link();
  916. }
  917. else
  918. {
  919. return null;
  920. }
  921. }
  922. /**
  923. * Get a single link for the item
  924. *
  925. * @since Beta 3
  926. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
  927. * @param string $rel The relationship of the link to return
  928. * @return string|null Link URL
  929. */
  930. public function get_link($key = 0, $rel = 'alternate')
  931. {
  932. $links = $this->get_links($rel);
  933. if ($links[$key] !== null)
  934. {
  935. return $links[$key];
  936. }
  937. else
  938. {
  939. return null;
  940. }
  941. }
  942. /**
  943. * Get all links for the item
  944. *
  945. * Uses `<atom:link>`, `<link>` or `<guid>`
  946. *
  947. * @since Beta 2
  948. * @param string $rel The relationship of links to return
  949. * @return array|null Links found for the item (strings)
  950. */
  951. public function get_links($rel = 'alternate')
  952. {
  953. if (!isset($this->data['links']))
  954. {
  955. $this->data['links'] = array();
  956. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  957. {
  958. if (isset($link['attribs']['']['href']))
  959. {
  960. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  961. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  962. }
  963. }
  964. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  965. {
  966. if (isset($link['attribs']['']['href']))
  967. {
  968. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  969. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  970. }
  971. }
  972. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  973. {
  974. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  975. }
  976. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  977. {
  978. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  979. }
  980. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  981. {
  982. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  983. }
  984. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  985. {
  986. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  987. {
  988. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  989. }
  990. }
  991. $keys = array_keys($this->data['links']);
  992. foreach ($keys as $key)
  993. {
  994. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  995. {
  996. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  997. {
  998. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  999. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  1000. }
  1001. else
  1002. {
  1003. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  1004. }
  1005. }
  1006. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  1007. {
  1008. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  1009. }
  1010. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  1011. }
  1012. }
  1013. if (isset($this->data['links'][$rel]))
  1014. {
  1015. return $this->data['links'][$rel];
  1016. }
  1017. else
  1018. {
  1019. return null;
  1020. }
  1021. }
  1022. /**
  1023. * Get an enclosure from the item
  1024. *
  1025. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  1026. *
  1027. * @since Beta 2
  1028. * @todo Add ability to prefer one type of content over another (in a media group).
  1029. * @param int $key The enclosure that you want to return. Remember that arrays begin with 0, not 1
  1030. * @return SimplePie_Enclosure|null
  1031. */
  1032. public function get_enclosure($key = 0, $prefer = null)
  1033. {
  1034. $enclosures = $this->get_enclosures();
  1035. if (isset($enclosures[$key]))
  1036. {
  1037. return $enclosures[$key];
  1038. }
  1039. else
  1040. {
  1041. return null;
  1042. }
  1043. }
  1044. /**
  1045. * Get all available enclosures (podcasts, etc.)
  1046. *
  1047. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  1048. *
  1049. * At this point, we're pretty much assuming that all enclosures for an item
  1050. * are the same content. Anything else is too complicated to
  1051. * properly support.
  1052. *
  1053. * @since Beta 2
  1054. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  1055. * @todo If an element exists at a level, but its value is empty, we should fall back to the value from the parent (if it exists).
  1056. * @return SimplePie_Enclosure[]|null List of SimplePie_Enclosure items
  1057. */
  1058. public function get_enclosures()
  1059. {
  1060. if (!isset($this->data['enclosures']))
  1061. {
  1062. $this->data['enclosures'] = array();
  1063. // Elements
  1064. $captions_parent = null;
  1065. $categories_parent = null;
  1066. $copyrights_parent = null;
  1067. $credits_parent = null;
  1068. $description_parent = null;
  1069. $duration_parent = null;
  1070. $hashes_parent = null;
  1071. $keywords_parent = null;
  1072. $player_parent = null;
  1073. $ratings_parent = null;
  1074. $restrictions_parent = null;
  1075. $thumbnails_parent = null;
  1076. $title_parent = null;
  1077. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  1078. $parent = $this->get_feed();
  1079. // CAPTIONS
  1080. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1081. {
  1082. foreach ($captions as $caption)
  1083. {
  1084. $caption_type = null;
  1085. $caption_lang = null;
  1086. $caption_startTime = null;
  1087. $caption_endTime = null;
  1088. $caption_text = null;
  1089. if (isset($caption['attribs']['']['type']))
  1090. {
  1091. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1092. }
  1093. if (isset($caption['attribs']['']['lang']))
  1094. {
  1095. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1096. }
  1097. if (isset($caption['attribs']['']['start']))
  1098. {
  1099. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1100. }
  1101. if (isset($caption['attribs']['']['end']))
  1102. {
  1103. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1104. }
  1105. if (isset($caption['data']))
  1106. {
  1107. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1108. }
  1109. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1110. }
  1111. }
  1112. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1113. {
  1114. foreach ($captions as $caption)
  1115. {
  1116. $caption_type = null;
  1117. $caption_lang = null;
  1118. $caption_startTime = null;
  1119. $caption_endTime = null;
  1120. $caption_text = null;
  1121. if (isset($caption['attribs']['']['type']))
  1122. {
  1123. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1124. }
  1125. if (isset($caption['attribs']['']['lang']))
  1126. {
  1127. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1128. }
  1129. if (isset($caption['attribs']['']['start']))
  1130. {
  1131. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1132. }
  1133. if (isset($caption['attribs']['']['end']))
  1134. {
  1135. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1136. }
  1137. if (isset($caption['data']))
  1138. {
  1139. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1140. }
  1141. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1142. }
  1143. }
  1144. if (is_array($captions_parent))
  1145. {
  1146. $captions_parent = array_values(array_unique($captions_parent));
  1147. }
  1148. // CATEGORIES
  1149. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1150. {
  1151. $term = null;
  1152. $scheme = null;
  1153. $label = null;
  1154. if (isset($category['data']))
  1155. {
  1156. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1157. }
  1158. if (isset($category['attribs']['']['scheme']))
  1159. {
  1160. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1161. }
  1162. else
  1163. {
  1164. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1165. }
  1166. if (isset($category['attribs']['']['label']))
  1167. {
  1168. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1169. }
  1170. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1171. }
  1172. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1173. {
  1174. $term = null;
  1175. $scheme = null;
  1176. $label = null;
  1177. if (isset($category['data']))
  1178. {
  1179. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1180. }
  1181. if (isset($category['attribs']['']['scheme']))
  1182. {
  1183. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1184. }
  1185. else
  1186. {
  1187. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1188. }
  1189. if (isset($category['attribs']['']['label']))
  1190. {
  1191. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1192. }
  1193. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1194. }
  1195. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  1196. {
  1197. $term = null;
  1198. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  1199. $label = null;
  1200. if (isset($category['attribs']['']['text']))
  1201. {
  1202. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1203. }
  1204. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1205. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  1206. {
  1207. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  1208. {
  1209. if (isset($subcategory['attribs']['']['text']))
  1210. {
  1211. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1212. }
  1213. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1214. }
  1215. }
  1216. }
  1217. if (is_array($categories_parent))
  1218. {
  1219. $categories_parent = array_values(array_unique($categories_parent));
  1220. }
  1221. // COPYRIGHT
  1222. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1223. {
  1224. $copyright_url = null;
  1225. $copyright_label = null;
  1226. if (isset($copyright[0]['attribs']['']['url']))
  1227. {
  1228. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1229. }
  1230. if (isset($copyright[0]['data']))
  1231. {
  1232. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1233. }
  1234. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1235. }
  1236. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1237. {
  1238. $copyright_url = null;
  1239. $copyright_label = null;
  1240. if (isset($copyright[0]['attribs']['']['url']))
  1241. {
  1242. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1243. }
  1244. if (isset($copyright[0]['data']))
  1245. {
  1246. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1247. }
  1248. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1249. }
  1250. // CREDITS
  1251. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1252. {
  1253. foreach ($credits as $credit)
  1254. {
  1255. $credit_role = null;
  1256. $credit_scheme = null;
  1257. $credit_name = null;
  1258. if (isset($credit['attribs']['']['role']))
  1259. {
  1260. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1261. }
  1262. if (isset($credit['attribs']['']['scheme']))
  1263. {
  1264. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1265. }
  1266. else
  1267. {
  1268. $credit_scheme = 'urn:ebu';
  1269. }
  1270. if (isset($credit['data']))
  1271. {
  1272. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1273. }
  1274. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1275. }
  1276. }
  1277. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1278. {
  1279. foreach ($credits as $credit)
  1280. {
  1281. $credit_role = null;
  1282. $credit_scheme = null;
  1283. $credit_name = null;
  1284. if (isset($credit['attribs']['']['role']))
  1285. {
  1286. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1287. }
  1288. if (isset($credit['attribs']['']['scheme']))
  1289. {
  1290. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1291. }
  1292. else
  1293. {
  1294. $credit_scheme = 'urn:ebu';
  1295. }
  1296. if (isset($credit['data']))
  1297. {
  1298. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1299. }
  1300. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1301. }
  1302. }
  1303. if (is_array($credits_parent))
  1304. {
  1305. $credits_parent = array_values(array_unique($credits_parent));
  1306. }
  1307. // DESCRIPTION
  1308. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1309. {
  1310. if (isset($description_parent[0]['data']))
  1311. {
  1312. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1313. }
  1314. }
  1315. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1316. {
  1317. if (isset($description_parent[0]['data']))
  1318. {
  1319. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1320. }
  1321. }
  1322. // DURATION
  1323. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  1324. {
  1325. $seconds = null;
  1326. $minutes = null;
  1327. $hours = null;
  1328. if (isset($duration_parent[0]['data']))
  1329. {
  1330. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1331. if (sizeof($temp) > 0)
  1332. {
  1333. $seconds = (int) array_pop($temp);
  1334. }
  1335. if (sizeof($temp) > 0)
  1336. {
  1337. $minutes = (int) array_pop($temp);
  1338. $seconds += $minutes * 60;
  1339. }
  1340. if (sizeof($temp) > 0)
  1341. {
  1342. $hours = (int) array_pop($temp);
  1343. $seconds += $hours * 3600;
  1344. }
  1345. unset($temp);
  1346. $duration_parent = $seconds;
  1347. }
  1348. }
  1349. // HASHES
  1350. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1351. {
  1352. foreach ($hashes_iterator as $hash)
  1353. {
  1354. $value = null;
  1355. $algo = null;
  1356. if (isset($hash['data']))
  1357. {
  1358. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1359. }
  1360. if (isset($hash['attribs']['']['algo']))
  1361. {
  1362. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1363. }
  1364. else
  1365. {
  1366. $algo = 'md5';
  1367. }
  1368. $hashes_parent[] = $algo.':'.$value;
  1369. }
  1370. }
  1371. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1372. {
  1373. foreach ($hashes_iterator as $hash)
  1374. {
  1375. $value = null;
  1376. $algo = null;
  1377. if (isset($hash['data']))
  1378. {
  1379. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1380. }
  1381. if (isset($hash['attribs']['']['algo']))
  1382. {
  1383. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1384. }
  1385. else
  1386. {
  1387. $algo = 'md5';
  1388. }
  1389. $hashes_parent[] = $algo.':'.$value;
  1390. }
  1391. }
  1392. if (is_array($hashes_parent))
  1393. {
  1394. $hashes_parent = array_values(array_unique($hashes_parent));
  1395. }
  1396. // KEYWORDS
  1397. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1398. {
  1399. if (isset($keywords[0]['data']))
  1400. {
  1401. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1402. foreach ($temp as $word)
  1403. {
  1404. $keywords_parent[] = trim($word);
  1405. }
  1406. }
  1407. unset($temp);
  1408. }
  1409. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1410. {
  1411. if (isset($keywords[0]['data']))
  1412. {
  1413. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1414. foreach ($temp as $word)
  1415. {
  1416. $keywords_parent[] = trim($word);
  1417. }
  1418. }
  1419. unset($temp);
  1420. }
  1421. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1422. {
  1423. if (isset($keywords[0]['data']))
  1424. {
  1425. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1426. foreach ($temp as $word)
  1427. {
  1428. $keywords_parent[] = trim($word);
  1429. }
  1430. }
  1431. unset($temp);
  1432. }
  1433. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1434. {
  1435. if (isset($keywords[0]['data']))
  1436. {
  1437. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1438. foreach ($temp as $word)
  1439. {
  1440. $keywords_parent[] = trim($word);
  1441. }
  1442. }
  1443. unset($temp);
  1444. }
  1445. if (is_array($keywords_parent))
  1446. {
  1447. $keywords_parent = array_values(array_unique($keywords_parent));
  1448. }
  1449. // PLAYER
  1450. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1451. {
  1452. if (isset($player_parent[0]['attribs']['']['url']))
  1453. {
  1454. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1455. }
  1456. }
  1457. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1458. {
  1459. if (isset($player_parent[0]['attribs']['']['url']))
  1460. {
  1461. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1462. }
  1463. }
  1464. // RATINGS
  1465. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1466. {
  1467. foreach ($ratings as $rating)
  1468. {
  1469. $rating_scheme = null;
  1470. $rating_value = null;
  1471. if (isset($rating['attribs']['']['scheme']))
  1472. {
  1473. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1474. }
  1475. else
  1476. {
  1477. $rating_scheme = 'urn:simple';
  1478. }
  1479. if (isset($rating['data']))
  1480. {
  1481. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1482. }
  1483. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1484. }
  1485. }
  1486. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1487. {
  1488. foreach ($ratings as $rating)
  1489. {
  1490. $rating_scheme = 'urn:itunes';
  1491. $rating_value = null;
  1492. if (isset($rating['data']))
  1493. {
  1494. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1495. }
  1496. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1497. }
  1498. }
  1499. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1500. {
  1501. foreach ($ratings as $rating)
  1502. {
  1503. $rating_scheme = null;
  1504. $rating_value = null;
  1505. if (isset($rating['attribs']['']['scheme']))
  1506. {
  1507. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1508. }
  1509. else
  1510. {
  1511. $rating_scheme = 'urn:simple';
  1512. }
  1513. if (isset($rating['data']))
  1514. {
  1515. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1516. }
  1517. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1518. }
  1519. }
  1520. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1521. {
  1522. foreach ($ratings as $rating)
  1523. {
  1524. $rating_scheme = 'urn:itunes';
  1525. $rating_value = null;
  1526. if (isset($rating['data']))
  1527. {
  1528. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1529. }
  1530. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1531. }
  1532. }
  1533. if (is_array($ratings_parent))
  1534. {
  1535. $ratings_parent = array_values(array_unique($ratings_parent));
  1536. }
  1537. // RESTRICTIONS
  1538. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1539. {
  1540. foreach ($restrictions as $restriction)
  1541. {
  1542. $restriction_relationship = null;
  1543. $restriction_type = null;
  1544. $restriction_value = null;
  1545. if (isset($restriction['attribs']['']['relationship']))
  1546. {
  1547. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1548. }
  1549. if (isset($restriction['attribs']['']['type']))
  1550. {
  1551. $restriction_type =

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