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

/lib/simplepie/library/SimplePie/Item.php

http://github.com/moodle/moodle
PHP | 2966 lines | 2387 code | 137 blank | 442 comment | 358 complexity | d1f1baec6c51693a30c2d661b4b15403 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause

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

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