PageRenderTime 66ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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 = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1552. }
  1553. if (isset($restriction['data']))
  1554. {
  1555. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1556. }
  1557. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1558. }
  1559. }
  1560. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1561. {
  1562. foreach ($restrictions as $restriction)
  1563. {
  1564. $restriction_relationship = 'allow';
  1565. $restriction_type = null;
  1566. $restriction_value = 'itunes';
  1567. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1568. {
  1569. $restriction_relationship = 'deny';
  1570. }
  1571. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1572. }
  1573. }
  1574. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1575. {
  1576. foreach ($restrictions as $restriction)
  1577. {
  1578. $restriction_relationship = null;
  1579. $restriction_type = null;
  1580. $restriction_value = null;
  1581. if (isset($restriction['attribs']['']['relationship']))
  1582. {
  1583. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1584. }
  1585. if (isset($restriction['attribs']['']['type']))
  1586. {
  1587. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1588. }
  1589. if (isset($restriction['data']))
  1590. {
  1591. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1592. }
  1593. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1594. }
  1595. }
  1596. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1597. {
  1598. foreach ($restrictions as $restriction)
  1599. {
  1600. $restriction_relationship = 'allow';
  1601. $restriction_type = null;
  1602. $restriction_value = 'itunes';
  1603. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1604. {
  1605. $restriction_relationship = 'deny';
  1606. }
  1607. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1608. }
  1609. }
  1610. if (is_array($restrictions_parent))
  1611. {
  1612. $restrictions_parent = array_values(array_unique($restrictions_parent));
  1613. }
  1614. else
  1615. {
  1616. $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
  1617. }
  1618. // THUMBNAILS
  1619. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1620. {
  1621. foreach ($thumbnails as $thumbnail)
  1622. {
  1623. if (isset($thumbnail['attribs']['']['url']))
  1624. {
  1625. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1626. }
  1627. }
  1628. }
  1629. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1630. {
  1631. foreach ($thumbnails as $thumbnail)
  1632. {
  1633. if (isset($thumbnail['attribs']['']['url']))
  1634. {
  1635. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1636. }
  1637. }
  1638. }
  1639. // TITLES
  1640. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1641. {
  1642. if (isset($title_parent[0]['data']))
  1643. {
  1644. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1645. }
  1646. }
  1647. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1648. {
  1649. if (isset($title_parent[0]['data']))
  1650. {
  1651. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1652. }
  1653. }
  1654. // Clear the memory
  1655. unset($parent);
  1656. // Attributes
  1657. $bitrate = null;
  1658. $channels = null;
  1659. $duration = null;
  1660. $expression = null;
  1661. $framerate = null;
  1662. $height = null;
  1663. $javascript = null;
  1664. $lang = null;
  1665. $length = null;
  1666. $medium = null;
  1667. $samplingrate = null;
  1668. $type = null;
  1669. $url = null;
  1670. $width = null;
  1671. // Elements
  1672. $captions = null;
  1673. $categories = null;
  1674. $copyrights = null;
  1675. $credits = null;
  1676. $description = null;
  1677. $hashes = null;
  1678. $keywords = null;
  1679. $player = null;
  1680. $ratings = null;
  1681. $restrictions = null;
  1682. $thumbnails = null;
  1683. $title = null;
  1684. // If we have media:group tags, loop through them.
  1685. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  1686. {
  1687. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  1688. {
  1689. // If we have media:content tags, loop through them.
  1690. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  1691. {
  1692. if (isset($content['attribs']['']['url']))
  1693. {
  1694. // Attributes
  1695. $bitrate = null;
  1696. $channels = null;
  1697. $duration = null;
  1698. $expression = null;
  1699. $framerate = null;
  1700. $height = null;
  1701. $javascript = null;
  1702. $lang = null;
  1703. $length = null;
  1704. $medium = null;
  1705. $samplingrate = null;
  1706. $type = null;
  1707. $url = null;
  1708. $width = null;
  1709. // Elements
  1710. $captions = null;
  1711. $categories = null;
  1712. $copyrights = null;
  1713. $credits = null;
  1714. $description = null;
  1715. $hashes = null;
  1716. $keywords = null;
  1717. $player = null;
  1718. $ratings = null;
  1719. $restrictions = null;
  1720. $thumbnails = null;
  1721. $title = null;
  1722. // Start checking the attributes of media:content
  1723. if (isset($content['attribs']['']['bitrate']))
  1724. {
  1725. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1726. }
  1727. if (isset($content['attribs']['']['channels']))
  1728. {
  1729. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  1730. }
  1731. if (isset($content['attribs']['']['duration']))
  1732. {
  1733. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  1734. }
  1735. else
  1736. {
  1737. $duration = $duration_parent;
  1738. }
  1739. if (isset($content['attribs']['']['expression']))
  1740. {
  1741. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  1742. }
  1743. if (isset($content['attribs']['']['framerate']))
  1744. {
  1745. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1746. }
  1747. if (isset($content['attribs']['']['height']))
  1748. {
  1749. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  1750. }
  1751. if (isset($content['attribs']['']['lang']))
  1752. {
  1753. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1754. }
  1755. if (isset($content['attribs']['']['fileSize']))
  1756. {
  1757. $length = ceil($content['attribs']['']['fileSize']);
  1758. }
  1759. if (isset($content['attribs']['']['medium']))
  1760. {
  1761. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  1762. }
  1763. if (isset($content['attribs']['']['samplingrate']))
  1764. {
  1765. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1766. }
  1767. if (isset($content['attribs']['']['type']))
  1768. {
  1769. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1770. }
  1771. if (isset($content['attribs']['']['width']))
  1772. {
  1773. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  1774. }
  1775. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1776. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  1777. // CAPTIONS
  1778. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  1779. {
  1780. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  1781. {
  1782. $caption_type = null;
  1783. $caption_lang = null;
  1784. $caption_startTime = null;
  1785. $caption_endTime = null;
  1786. $caption_text = null;
  1787. if (isset($caption['attribs']['']['type']))
  1788. {
  1789. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1790. }
  1791. if (isset($caption['attribs']['']['lang']))
  1792. {
  1793. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1794. }
  1795. if (isset($caption['attribs']['']['start']))
  1796. {
  1797. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1798. }
  1799. if (isset($caption['attribs']['']['end']))
  1800. {
  1801. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1802. }
  1803. if (isset($caption['data']))
  1804. {
  1805. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1806. }
  1807. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1808. }
  1809. if (is_array($captions))
  1810. {
  1811. $captions = array_values(array_unique($captions));
  1812. }
  1813. }
  1814. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  1815. {
  1816. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  1817. {
  1818. $caption_type = null;
  1819. $caption_lang = null;
  1820. $caption_startTime = null;
  1821. $caption_endTime = null;
  1822. $caption_text = null;
  1823. if (isset($caption['attribs']['']['type']))
  1824. {
  1825. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1826. }
  1827. if (isset($caption['attribs']['']['lang']))
  1828. {
  1829. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1830. }
  1831. if (isset($caption['attribs']['']['start']))
  1832. {
  1833. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1834. }
  1835. if (isset($caption['attribs']['']['end']))
  1836. {
  1837. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1838. }
  1839. if (isset($caption['data']))
  1840. {
  1841. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1842. }
  1843. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1844. }
  1845. if (is_array($captions))
  1846. {
  1847. $captions = array_values(array_unique($captions));
  1848. }
  1849. }
  1850. else
  1851. {
  1852. $captions = $captions_parent;
  1853. }
  1854. // CATEGORIES
  1855. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  1856. {
  1857. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  1858. {
  1859. $term = null;
  1860. $scheme = null;
  1861. $label = null;
  1862. if (isset($category['data']))
  1863. {
  1864. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1865. }
  1866. if (isset($category['attribs']['']['scheme']))
  1867. {
  1868. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1869. }
  1870. else
  1871. {
  1872. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1873. }
  1874. if (isset($category['attribs']['']['label']))
  1875. {
  1876. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1877. }
  1878. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1879. }
  1880. }
  1881. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  1882. {
  1883. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  1884. {
  1885. $term = null;
  1886. $scheme = null;
  1887. $label = null;
  1888. if (isset($category['data']))
  1889. {
  1890. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1891. }
  1892. if (isset($category['attribs']['']['scheme']))
  1893. {
  1894. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1895. }
  1896. else
  1897. {
  1898. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1899. }
  1900. if (isset($category['attribs']['']['label']))
  1901. {
  1902. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1903. }
  1904. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1905. }
  1906. }
  1907. if (is_array($categories) && is_array($categories_parent))
  1908. {
  1909. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  1910. }
  1911. elseif (is_array($categories))
  1912. {
  1913. $categories = array_values(array_unique($categories));
  1914. }
  1915. elseif (is_array($categories_parent))
  1916. {
  1917. $categories = array_values(array_unique($categories_parent));
  1918. }
  1919. // COPYRIGHTS
  1920. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  1921. {
  1922. $copyright_url = null;
  1923. $copyright_label = null;
  1924. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  1925. {
  1926. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1927. }
  1928. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  1929. {
  1930. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1931. }
  1932. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1933. }
  1934. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  1935. {
  1936. $copyright_url = null;
  1937. $copyright_label = null;
  1938. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  1939. {
  1940. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1941. }
  1942. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  1943. {
  1944. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1945. }
  1946. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1947. }
  1948. else
  1949. {
  1950. $copyrights = $copyrights_parent;
  1951. }
  1952. // CREDITS
  1953. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  1954. {
  1955. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  1956. {
  1957. $credit_role = null;
  1958. $credit_scheme = null;
  1959. $credit_name = null;
  1960. if (isset($credit['attribs']['']['role']))
  1961. {
  1962. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1963. }
  1964. if (isset($credit['attribs']['']['scheme']))
  1965. {
  1966. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1967. }
  1968. else
  1969. {
  1970. $credit_scheme = 'urn:ebu';
  1971. }
  1972. if (isset($credit['data']))
  1973. {
  1974. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1975. }
  1976. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1977. }
  1978. if (is_array($credits))
  1979. {
  1980. $credits = array_values(array_unique($credits));
  1981. }
  1982. }
  1983. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  1984. {
  1985. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  1986. {
  1987. $credit_role = null;
  1988. $credit_scheme = null;
  1989. $credit_name = null;
  1990. if (isset($credit['attribs']['']['role']))
  1991. {
  1992. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1993. }
  1994. if (isset($credit['attribs']['']['scheme']))
  1995. {
  1996. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1997. }
  1998. else
  1999. {
  2000. $credit_scheme = 'urn:ebu';
  2001. }
  2002. if (isset($credit['data']))
  2003. {
  2004. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2005. }
  2006. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  2007. }
  2008. if (is_array($credits))
  2009. {
  2010. $credits = array_values(array_unique($credits));
  2011. }
  2012. }
  2013. else
  2014. {
  2015. $credits = $credits_parent;
  2016. }
  2017. // DESCRIPTION
  2018. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  2019. {
  2020. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2021. }
  2022. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  2023. {
  2024. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2025. }
  2026. else
  2027. {
  2028. $description = $description_parent;
  2029. }
  2030. // HASHES
  2031. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2032. {
  2033. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2034. {
  2035. $value = null;
  2036. $algo = null;
  2037. if (isset($hash['data']))
  2038. {
  2039. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2040. }
  2041. if (isset($hash['attribs']['']['algo']))
  2042. {
  2043. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2044. }
  2045. else
  2046. {
  2047. $algo = 'md5';
  2048. }
  2049. $hashes[] = $algo.':'.$value;
  2050. }
  2051. if (is_array($hashes))
  2052. {
  2053. $hashes = array_values(array_unique($hashes));
  2054. }
  2055. }
  2056. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2057. {
  2058. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2059. {
  2060. $value = null;
  2061. $algo = null;
  2062. if (isset($hash['data']))
  2063. {
  2064. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2065. }
  2066. if (isset($hash['attribs']['']['algo']))
  2067. {
  2068. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2069. }
  2070. else
  2071. {
  2072. $algo = 'md5';
  2073. }
  2074. $hashes[] = $algo.':'.$value;
  2075. }
  2076. if (is_array($hashes))
  2077. {
  2078. $hashes = array_values(array_unique($hashes));
  2079. }
  2080. }
  2081. else
  2082. {
  2083. $hashes = $hashes_parent;
  2084. }
  2085. // KEYWORDS
  2086. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2087. {
  2088. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2089. {
  2090. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2091. foreach ($temp as $word)
  2092. {
  2093. $keywords[] = trim($word);
  2094. }
  2095. unset($temp);
  2096. }
  2097. if (is_array($keywords))
  2098. {
  2099. $keywords = array_values(array_unique($keywords));
  2100. }
  2101. }
  2102. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2103. {
  2104. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2105. {
  2106. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2107. foreach ($temp as $word)
  2108. {
  2109. $keywords[] = trim($word);
  2110. }
  2111. unset($temp);
  2112. }
  2113. if (is_array($keywords))
  2114. {
  2115. $keywords = array_values(array_unique($keywords));
  2116. }
  2117. }
  2118. else
  2119. {
  2120. $keywords = $keywords_parent;
  2121. }
  2122. // PLAYER
  2123. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2124. {
  2125. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2126. }
  2127. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2128. {
  2129. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2130. }
  2131. else
  2132. {
  2133. $player = $player_parent;
  2134. }
  2135. // RATINGS
  2136. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2137. {
  2138. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2139. {
  2140. $rating_scheme = null;
  2141. $rating_value = null;
  2142. if (isset($rating['attribs']['']['scheme']))
  2143. {
  2144. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2145. }
  2146. else
  2147. {
  2148. $rating_scheme = 'urn:simple';
  2149. }
  2150. if (isset($rating['data']))
  2151. {
  2152. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2153. }
  2154. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2155. }
  2156. if (is_array($ratings))
  2157. {
  2158. $ratings = array_values(array_unique($ratings));
  2159. }
  2160. }
  2161. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2162. {
  2163. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2164. {
  2165. $rating_scheme = null;
  2166. $rating_value = null;
  2167. if (isset($rating['attribs']['']['scheme']))
  2168. {
  2169. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2170. }
  2171. else
  2172. {
  2173. $rating_scheme = 'urn:simple';
  2174. }
  2175. if (isset($rating['data']))
  2176. {
  2177. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2178. }
  2179. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2180. }
  2181. if (is_array($ratings))
  2182. {
  2183. $ratings = array_values(array_unique($ratings));
  2184. }
  2185. }
  2186. else
  2187. {
  2188. $ratings = $ratings_parent;
  2189. }
  2190. // RESTRICTIONS
  2191. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2192. {
  2193. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2194. {
  2195. $restriction_relationship = null;
  2196. $restriction_type = null;
  2197. $restriction_value = null;
  2198. if (isset($restriction['attribs']['']['relationship']))
  2199. {
  2200. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2201. }
  2202. if (isset($restriction['attribs']['']['type']))
  2203. {
  2204. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2205. }
  2206. if (isset($restriction['data']))
  2207. {
  2208. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2209. }
  2210. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2211. }
  2212. if (is_array($restrictions))
  2213. {
  2214. $restrictions = array_values(array_unique($restrictions));
  2215. }
  2216. }
  2217. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2218. {
  2219. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2220. {
  2221. $restriction_relationship = null;
  2222. $restriction_type = null;
  2223. $restriction_value = null;
  2224. if (isset($restriction['attribs']['']['relationship']))
  2225. {
  2226. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2227. }
  2228. if (isset($restriction['attribs']['']['type']))
  2229. {
  2230. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2231. }
  2232. if (isset($restriction['data']))
  2233. {
  2234. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2235. }
  2236. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2237. }
  2238. if (is_array($restrictions))
  2239. {
  2240. $restrictions = array_values(array_unique($restrictions));
  2241. }
  2242. }
  2243. else
  2244. {
  2245. $restrictions = $restrictions_parent;
  2246. }
  2247. // THUMBNAILS
  2248. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2249. {
  2250. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2251. {
  2252. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2253. }
  2254. if (is_array($thumbnails))
  2255. {
  2256. $thumbnails = array_values(array_unique($thumbnails));
  2257. }
  2258. }
  2259. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2260. {
  2261. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2262. {
  2263. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2264. }
  2265. if (is_array($thumbnails))
  2266. {
  2267. $thumbnails = array_values(array_unique($thumbnails));
  2268. }
  2269. }
  2270. else
  2271. {
  2272. $thumbnails = $thumbnails_parent;
  2273. }
  2274. // TITLES
  2275. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2276. {
  2277. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2278. }
  2279. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2280. {
  2281. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2282. }
  2283. else
  2284. {
  2285. $title = $title_parent;
  2286. }
  2287. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  2288. }
  2289. }
  2290. }
  2291. }
  2292. // If we have standalone media:content tags, loop through them.
  2293. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  2294. {
  2295. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  2296. {
  2297. if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2298. {
  2299. // Attributes
  2300. $bitrate = null;
  2301. $channels = null;
  2302. $duration = null;
  2303. $expression = null;
  2304. $framerate = null;
  2305. $height = null;
  2306. $javascript = null;
  2307. $lang = null;
  2308. $length = null;
  2309. $medium = null;
  2310. $samplingrate = null;
  2311. $type = null;
  2312. $url = null;
  2313. $width = null;
  2314. // Elements
  2315. $captions = null;
  2316. $categories = null;
  2317. $copyrights = null;
  2318. $credits = null;
  2319. $description = null;
  2320. $hashes = null;
  2321. $keywords = null;
  2322. $player = null;
  2323. $ratings = null;
  2324. $restrictions = null;
  2325. $thumbnails = null;
  2326. $title = null;
  2327. // Start checking the attributes of media:content
  2328. if (isset($content['attribs']['']['bitrate']))
  2329. {
  2330. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2331. }
  2332. if (isset($content['attribs']['']['channels']))
  2333. {
  2334. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  2335. }
  2336. if (isset($content['attribs']['']['duration']))
  2337. {
  2338. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  2339. }
  2340. else
  2341. {
  2342. $duration = $duration_parent;
  2343. }
  2344. if (isset($content['attribs']['']['expression']))
  2345. {
  2346. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  2347. }
  2348. if (isset($content['attribs']['']['framerate']))
  2349. {
  2350. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2351. }
  2352. if (isset($content['attribs']['']['height']))
  2353. {
  2354. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  2355. }
  2356. if (isset($content['attribs']['']['lang']))
  2357. {
  2358. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2359. }
  2360. if (isset($content['attribs']['']['fileSize']))
  2361. {
  2362. $length = ceil($content['attribs']['']['fileSize']);
  2363. }
  2364. if (isset($content['attribs']['']['medium']))
  2365. {
  2366. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  2367. }
  2368. if (isset($content['attribs']['']['samplingrate']))
  2369. {
  2370. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2371. }
  2372. if (isset($content['attribs']['']['type']))
  2373. {
  2374. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2375. }
  2376. if (isset($content['attribs']['']['width']))
  2377. {
  2378. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  2379. }
  2380. if (isset($content['attribs']['']['url']))
  2381. {
  2382. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2383. }
  2384. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  2385. // CAPTIONS
  2386. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  2387. {
  2388. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  2389. {
  2390. $caption_type = null;
  2391. $caption_lang = null;
  2392. $caption_startTime = null;
  2393. $caption_endTime = null;
  2394. $caption_text = null;
  2395. if (isset($caption['attribs']['']['type']))
  2396. {
  2397. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2398. }
  2399. if (isset($caption['attribs']['']['lang']))
  2400. {
  2401. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2402. }
  2403. if (isset($caption['attribs']['']['start']))
  2404. {
  2405. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  2406. }
  2407. if (isset($caption['attribs']['']['end']))
  2408. {
  2409. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  2410. }
  2411. if (isset($caption['data']))
  2412. {
  2413. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2414. }
  2415. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  2416. }
  2417. if (is_array($captions))
  2418. {
  2419. $captions = array_values(array_unique($captions));
  2420. }
  2421. }
  2422. else
  2423. {
  2424. $captions = $captions_parent;
  2425. }
  2426. // CATEGORIES
  2427. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  2428. {
  2429. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  2430. {
  2431. $term = null;
  2432. $scheme = null;
  2433. $label = null;
  2434. if (isset($category['data']))
  2435. {
  2436. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2437. }
  2438. if (isset($category['attribs']['']['scheme']))
  2439. {
  2440. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2441. }
  2442. else
  2443. {
  2444. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  2445. }
  2446. if (isset($category['attribs']['']['label']))
  2447. {
  2448. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2449. }
  2450. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  2451. }
  2452. }
  2453. if (is_array($categories) && is_array($categories_parent))
  2454. {
  2455. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  2456. }
  2457. elseif (is_array($categories))
  2458. {
  2459. $categories = array_values(array_unique($categories));
  2460. }
  2461. elseif (is_array($categories_parent))
  2462. {
  2463. $categories = array_values(array_unique($categories_parent));
  2464. }
  2465. else
  2466. {
  2467. $categories = null;
  2468. }
  2469. // COPYRIGHTS
  2470. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  2471. {
  2472. $copyright_url = null;
  2473. $copyright_label = null;
  2474. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  2475. {
  2476. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  2477. }
  2478. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  2479. {
  2480. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2481. }
  2482. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  2483. }
  2484. else
  2485. {
  2486. $copyrights = $copyrights_parent;
  2487. }
  2488. // CREDITS
  2489. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  2490. {
  2491. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  2492. {
  2493. $credit_role = null;
  2494. $credit_scheme = null;
  2495. $credit_name = null;
  2496. if (isset($credit['attribs']['']['role']))
  2497. {
  2498. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  2499. }
  2500. if (isset($credit['attribs']['']['scheme']))
  2501. {
  2502. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2503. }
  2504. else
  2505. {
  2506. $credit_scheme = 'urn:ebu';
  2507. }
  2508. if (isset($credit['data']))
  2509. {
  2510. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2511. }
  2512. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  2513. }
  2514. if (is_array($credits))
  2515. {
  2516. $credits = array_values(array_unique($credits));
  2517. }
  2518. }
  2519. else
  2520. {
  2521. $credits = $credits_parent;
  2522. }
  2523. // DESCRIPTION
  2524. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  2525. {
  2526. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2527. }
  2528. else
  2529. {
  2530. $description = $description_parent;
  2531. }
  2532. // HASHES
  2533. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2534. {
  2535. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2536. {
  2537. $value = null;
  2538. $algo = null;
  2539. if (isset($hash['data']))
  2540. {
  2541. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2542. }
  2543. if (isset($hash['attribs']['']['algo']))
  2544. {
  2545. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2546. }
  2547. else
  2548. {
  2549. $algo = 'md5';
  2550. }
  2551. $hashes[] = $algo.':'.$value;
  2552. }
  2553. if (is_array($hashes))
  2554. {
  2555. $hashes = array_values(array_unique($hashes));
  2556. }
  2557. }
  2558. else
  2559. {
  2560. $hashes = $hashes_parent;
  2561. }
  2562. // KEYWORDS
  2563. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2564. {
  2565. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2566. {
  2567. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2568. foreach ($temp as $word)
  2569. {
  2570. $keywords[] = trim($word);
  2571. }
  2572. unset($temp);
  2573. }
  2574. if (is_array($keywords))
  2575. {
  2576. $keywords = array_values(array_unique($keywords));
  2577. }
  2578. }
  2579. else
  2580. {
  2581. $keywords = $keywords_parent;
  2582. }
  2583. // PLAYER
  2584. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2585. {
  2586. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'])) {
  2587. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2588. }
  2589. }
  2590. else
  2591. {
  2592. $player = $player_parent;
  2593. }
  2594. // RATINGS
  2595. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2596. {
  2597. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2598. {
  2599. $rating_scheme = null;
  2600. $rating_value = null;
  2601. if (isset($rating['attribs']['']['scheme']))
  2602. {
  2603. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2604. }
  2605. else
  2606. {
  2607. $rating_scheme = 'urn:simple';
  2608. }
  2609. if (isset($rating['data']))
  2610. {
  2611. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2612. }
  2613. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2614. }
  2615. if (is_array($ratings))
  2616. {
  2617. $ratings = array_values(array_unique($ratings));
  2618. }
  2619. }
  2620. else
  2621. {
  2622. $ratings = $ratings_parent;
  2623. }
  2624. // RESTRICTIONS
  2625. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2626. {
  2627. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2628. {
  2629. $restriction_relationship = null;
  2630. $restriction_type = null;
  2631. $restriction_value = null;
  2632. if (isset($restriction['attribs']['']['relationship']))
  2633. {
  2634. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2635. }
  2636. if (isset($restriction['attribs']['']['type']))
  2637. {
  2638. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2639. }
  2640. if (isset($restriction['data']))
  2641. {
  2642. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2643. }
  2644. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2645. }
  2646. if (is_array($restrictions))
  2647. {
  2648. $restrictions = array_values(array_unique($restrictions));
  2649. }
  2650. }
  2651. else
  2652. {
  2653. $restrictions = $restrictions_parent;
  2654. }
  2655. // THUMBNAILS
  2656. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2657. {
  2658. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2659. {
  2660. if (isset($thumbnail['attribs']['']['url'])) {
  2661. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2662. }
  2663. }
  2664. if (is_array($thumbnails))
  2665. {
  2666. $thumbnails = array_values(array_unique($thumbnails));
  2667. }
  2668. }
  2669. else
  2670. {
  2671. $thumbnails = $thumbnails_parent;
  2672. }
  2673. // TITLES
  2674. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2675. {
  2676. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2677. }
  2678. else
  2679. {
  2680. $title = $title_parent;
  2681. }
  2682. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions, $categories, $channels, $copyrights, $credits, $description, $duration, $expression, $framerate, $hashes, $height, $keywords, $lang, $medium, $player, $ratings, $restrictions, $samplingrate, $thumbnails, $title, $width));
  2683. }
  2684. }
  2685. }
  2686. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  2687. {
  2688. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  2689. {
  2690. // Attributes
  2691. $bitrate = null;
  2692. $channels = null;
  2693. $duration = null;
  2694. $expression = null;
  2695. $framerate = null;
  2696. $height = null;
  2697. $javascript = null;
  2698. $lang = null;
  2699. $length = null;
  2700. $medium = null;
  2701. $samplingrate = null;
  2702. $type = null;
  2703. $url = null;
  2704. $width = null;
  2705. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2706. if (isset($link['attribs']['']['type']))
  2707. {
  2708. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2709. }
  2710. if (isset($link['attribs']['']['length']))
  2711. {
  2712. $length = ceil($link['attribs']['']['length']);
  2713. }
  2714. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2715. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2716. }
  2717. }
  2718. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  2719. {
  2720. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  2721. {
  2722. // Attributes
  2723. $bitrate = null;
  2724. $channels = null;
  2725. $duration = null;
  2726. $expression = null;
  2727. $framerate = null;
  2728. $height = null;
  2729. $javascript = null;
  2730. $lang = null;
  2731. $length = null;
  2732. $medium = null;
  2733. $samplingrate = null;
  2734. $type = null;
  2735. $url = null;
  2736. $width = null;
  2737. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2738. if (isset($link['attribs']['']['type']))
  2739. {
  2740. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2741. }
  2742. if (isset($link['attribs']['']['length']))
  2743. {
  2744. $length = ceil($link['attribs']['']['length']);
  2745. }
  2746. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2747. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2748. }
  2749. }
  2750. if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
  2751. {
  2752. if (isset($enclosure[0]['attribs']['']['url']))
  2753. {
  2754. // Attributes
  2755. $bitrate = null;
  2756. $channels = null;
  2757. $duration = null;
  2758. $expression = null;
  2759. $framerate = null;
  2760. $height = null;
  2761. $javascript = null;
  2762. $lang = null;
  2763. $length = null;
  2764. $medium = null;
  2765. $samplingrate = null;
  2766. $type = null;
  2767. $url = null;
  2768. $width = null;
  2769. $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  2770. if (isset($enclosure[0]['attribs']['']['type']))
  2771. {
  2772. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2773. }
  2774. if (isset($enclosure[0]['attribs']['']['length']))
  2775. {
  2776. $length = ceil($enclosure[0]['attribs']['']['length']);
  2777. }
  2778. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2779. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2780. }
  2781. }
  2782. if (sizeof($this->data['enclosures']) === 0 && ($url || $type || $length || $bitrate || $captions_parent || $categories_parent || $channels || $copyrights_parent || $credits_parent || $description_parent || $duration_parent || $expression || $framerate || $hashes_parent || $height || $keywords_parent || $lang || $medium || $player_parent || $ratings_parent || $restrictions_parent || $samplingrate || $thumbnails_parent || $title_parent || $width))
  2783. {
  2784. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2785. $this->data['enclosures'][] = $this->registry->create('Enclosure', array($url, $type, $length, null, $bitrate, $captions_parent, $categories_parent, $channels, $copyrights_parent, $credits_parent, $description_parent, $duration_parent, $expression, $framerate, $hashes_parent, $height, $keywords_parent, $lang, $medium, $player_parent, $ratings_parent, $restrictions_parent, $samplingrate, $thumbnails_parent, $title_parent, $width));
  2786. }
  2787. $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
  2788. }
  2789. if (!empty($this->data['enclosures']))
  2790. {
  2791. return $this->data['enclosures'];
  2792. }
  2793. else
  2794. {
  2795. return null;
  2796. }
  2797. }
  2798. /**
  2799. * Get the latitude coordinates for the item
  2800. *
  2801. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2802. *
  2803. * Uses `<geo:lat>` or `<georss:point>`
  2804. *
  2805. * @since 1.0
  2806. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2807. * @link http://www.georss.org/ GeoRSS
  2808. * @return string|null
  2809. */
  2810. public function get_latitude()
  2811. {
  2812. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  2813. {
  2814. return (float) $return[0]['data'];
  2815. }
  2816. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2817. {
  2818. return (float) $match[1];
  2819. }
  2820. else
  2821. {
  2822. return null;
  2823. }
  2824. }
  2825. /**
  2826. * Get the longitude coordinates for the item
  2827. *
  2828. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2829. *
  2830. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
  2831. *
  2832. * @since 1.0
  2833. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2834. * @link http://www.georss.org/ GeoRSS
  2835. * @return string|null
  2836. */
  2837. public function get_longitude()
  2838. {
  2839. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  2840. {
  2841. return (float) $return[0]['data'];
  2842. }
  2843. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  2844. {
  2845. return (float) $return[0]['data'];
  2846. }
  2847. elseif (($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  2848. {
  2849. return (float) $match[2];
  2850. }
  2851. else
  2852. {
  2853. return null;
  2854. }
  2855. }
  2856. /**
  2857. * Get the `<atom:source>` for the item
  2858. *
  2859. * @since 1.1
  2860. * @return SimplePie_Source|null
  2861. */
  2862. public function get_source()
  2863. {
  2864. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  2865. {
  2866. return $this->registry->create('Source', array($this, $return[0]));
  2867. }
  2868. else
  2869. {
  2870. return null;
  2871. }
  2872. }
  2873. }