PageRenderTime 39ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://github.com/moodle/moodle
PHP | 2966 lines | 2387 code | 137 blank | 442 comment | 358 complexity | d1f1baec6c51693a30c2d661b4b15403 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-2016, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package SimplePie
  36. * @copyright 2004-2016 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  37. * @author Ryan Parman
  38. * @author Geoffrey Sneddon
  39. * @author Ryan McCue
  40. * @link http://simplepie.org/ SimplePie
  41. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  42. */
  43. /**
  44. * Manages all item-related data
  45. *
  46. * Used by {@see SimplePie::get_item()} and {@see SimplePie::get_items()}
  47. *
  48. * This class can be overloaded with {@see SimplePie::set_item_class()}
  49. *
  50. * @package SimplePie
  51. * @subpackage API
  52. */
  53. class SimplePie_Item
  54. {
  55. /**
  56. * Parent feed
  57. *
  58. * @access private
  59. * @var SimplePie
  60. */
  61. var $feed;
  62. /**
  63. * Raw data
  64. *
  65. * @access private
  66. * @var array
  67. */
  68. var $data = array();
  69. /**
  70. * Registry object
  71. *
  72. * @see set_registry
  73. * @var SimplePie_Registry
  74. */
  75. protected $registry;
  76. /**
  77. * Create a new item object
  78. *
  79. * This is usually used by {@see SimplePie::get_items} and
  80. * {@see SimplePie::get_item}. Avoid creating this manually.
  81. *
  82. * @param SimplePie $feed Parent feed
  83. * @param array $data Raw data
  84. */
  85. public function __construct($feed, $data)
  86. {
  87. $this->feed = $feed;
  88. $this->data = $data;
  89. }
  90. /**
  91. * Set the registry handler
  92. *
  93. * This is usually used by {@see SimplePie_Registry::create}
  94. *
  95. * @since 1.3
  96. * @param SimplePie_Registry $registry
  97. */
  98. public function set_registry(SimplePie_Registry $registry)
  99. {
  100. $this->registry = $registry;
  101. }
  102. /**
  103. * Get a string representation of the item
  104. *
  105. * @return string
  106. */
  107. public function __toString()
  108. {
  109. return md5(serialize($this->data));
  110. }
  111. /**
  112. * Remove items that link back to this before destroying this object
  113. */
  114. public function __destruct()
  115. {
  116. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  117. {
  118. unset($this->feed);
  119. }
  120. }
  121. /**
  122. * Get data for an item-level element
  123. *
  124. * This method allows you to get access to ANY element/attribute that is a
  125. * sub-element of the item/entry tag.
  126. *
  127. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  128. *
  129. * @since 1.0
  130. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  131. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  132. * @param string $tag Tag name
  133. * @return array
  134. */
  135. public function get_item_tags($namespace, $tag)
  136. {
  137. if (isset($this->data['child'][$namespace][$tag]))
  138. {
  139. return $this->data['child'][$namespace][$tag];
  140. }
  141. return null;
  142. }
  143. /**
  144. * Get the base URL value from the parent feed
  145. *
  146. * Uses `<xml:base>`
  147. *
  148. * @param array $element
  149. * @return string
  150. */
  151. public function get_base($element = array())
  152. {
  153. return $this->feed->get_base($element);
  154. }
  155. /**
  156. * Sanitize feed data
  157. *
  158. * @access private
  159. * @see SimplePie::sanitize()
  160. * @param string $data Data to sanitize
  161. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
  162. * @param string $base Base URL to resolve URLs against
  163. * @return string Sanitized data
  164. */
  165. public function sanitize($data, $type, $base = '')
  166. {
  167. return $this->feed->sanitize($data, $type, $base);
  168. }
  169. /**
  170. * Get the parent feed
  171. *
  172. * Note: this may not work as you think for multifeeds!
  173. *
  174. * @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed
  175. * @since 1.0
  176. * @return SimplePie
  177. */
  178. public function get_feed()
  179. {
  180. return $this->feed;
  181. }
  182. /**
  183. * Get the unique identifier for the item
  184. *
  185. * This is usually used when writing code to check for new items in a feed.
  186. *
  187. * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute
  188. * for RDF. If none of these are supplied (or `$hash` is true), creates an
  189. * MD5 hash based on the permalink, title and content.
  190. *
  191. * @since Beta 2
  192. * @param boolean $hash Should we force using a hash instead of the supplied ID?
  193. * @param string|false $fn User-supplied function to generate an hash
  194. * @return string|null
  195. */
  196. public function get_id($hash = false, $fn = 'md5')
  197. {
  198. if (!$hash)
  199. {
  200. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  201. {
  202. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  203. }
  204. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  205. {
  206. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  207. }
  208. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  209. {
  210. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  211. }
  212. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  213. {
  214. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  215. }
  216. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  217. {
  218. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  219. }
  220. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  221. {
  222. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  223. }
  224. }
  225. if ($fn === false)
  226. {
  227. return null;
  228. }
  229. elseif (!is_callable($fn))
  230. {
  231. trigger_error('User-supplied function $fn must be callable', E_USER_WARNING);
  232. $fn = 'md5';
  233. }
  234. return call_user_func($fn,
  235. $this->get_permalink().$this->get_title().$this->get_content());
  236. }
  237. /**
  238. * Get the title of the item
  239. *
  240. * Uses `<atom:title>`, `<title>` or `<dc:title>`
  241. *
  242. * @since Beta 2 (previously called `get_item_title` since 0.8)
  243. * @return string|null
  244. */
  245. public function get_title()
  246. {
  247. if (!isset($this->data['title']))
  248. {
  249. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  250. {
  251. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  252. }
  253. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  254. {
  255. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  256. }
  257. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  258. {
  259. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  260. }
  261. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  262. {
  263. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  264. }
  265. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  266. {
  267. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  268. }
  269. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  270. {
  271. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  272. }
  273. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  274. {
  275. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  276. }
  277. else
  278. {
  279. $this->data['title'] = null;
  280. }
  281. }
  282. return $this->data['title'];
  283. }
  284. /**
  285. * Get the content for the item
  286. *
  287. * Prefers summaries over full content , but will return full content if a
  288. * summary does not exist.
  289. *
  290. * To prefer full content instead, use {@see get_content}
  291. *
  292. * Uses `<atom:summary>`, `<description>`, `<dc:description>` or
  293. * `<itunes:subtitle>`
  294. *
  295. * @since 0.8
  296. * @param boolean $description_only Should we avoid falling back to the content?
  297. * @return string|null
  298. */
  299. public function get_description($description_only = false)
  300. {
  301. if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) &&
  302. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  303. {
  304. return $return;
  305. }
  306. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) &&
  307. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  308. {
  309. return $return;
  310. }
  311. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) &&
  312. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($tags[0]))))
  313. {
  314. return $return;
  315. }
  316. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) &&
  317. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  318. {
  319. return $return;
  320. }
  321. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) &&
  322. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  323. {
  324. return $return;
  325. }
  326. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) &&
  327. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  328. {
  329. return $return;
  330. }
  331. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) &&
  332. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  333. {
  334. return $return;
  335. }
  336. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) &&
  337. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  338. {
  339. return $return;
  340. }
  341. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) &&
  342. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)))
  343. {
  344. return $return;
  345. }
  346. elseif (!$description_only)
  347. {
  348. return $this->get_content(true);
  349. }
  350. return null;
  351. }
  352. /**
  353. * Get the content for the item
  354. *
  355. * Prefers full content over summaries, but will return a summary if full
  356. * content does not exist.
  357. *
  358. * To prefer summaries instead, use {@see get_description}
  359. *
  360. * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
  361. *
  362. * @since 1.0
  363. * @param boolean $content_only Should we avoid falling back to the description?
  364. * @return string|null
  365. */
  366. public function get_content($content_only = false)
  367. {
  368. if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) &&
  369. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  370. {
  371. return $return;
  372. }
  373. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) &&
  374. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  375. {
  376. return $return;
  377. }
  378. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) &&
  379. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  380. {
  381. return $return;
  382. }
  383. elseif (!$content_only)
  384. {
  385. return $this->get_description(true);
  386. }
  387. return null;
  388. }
  389. /**
  390. * Get the media:thumbnail of the item
  391. *
  392. * Uses `<media:thumbnail>`
  393. *
  394. *
  395. * @return array|null
  396. */
  397. public function get_thumbnail()
  398. {
  399. if (!isset($this->data['thumbnail']))
  400. {
  401. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  402. {
  403. $this->data['thumbnail'] = $return[0]['attribs'][''];
  404. }
  405. else
  406. {
  407. $this->data['thumbnail'] = null;
  408. }
  409. }
  410. return $this->data['thumbnail'];
  411. }
  412. /**
  413. * Get a category for the item
  414. *
  415. * @since Beta 3 (previously called `get_categories()` since Beta 2)
  416. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
  417. * @return SimplePie_Category|null
  418. */
  419. public function get_category($key = 0)
  420. {
  421. $categories = $this->get_categories();
  422. if (isset($categories[$key]))
  423. {
  424. return $categories[$key];
  425. }
  426. return null;
  427. }
  428. /**
  429. * Get all categories for the item
  430. *
  431. * Uses `<atom:category>`, `<category>` or `<dc:subject>`
  432. *
  433. * @since Beta 3
  434. * @return SimplePie_Category[]|null List of {@see SimplePie_Category} objects
  435. */
  436. public function get_categories()
  437. {
  438. $categories = array();
  439. $type = 'category';
  440. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, $type) as $category)
  441. {
  442. $term = null;
  443. $scheme = null;
  444. $label = null;
  445. if (isset($category['attribs']['']['term']))
  446. {
  447. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  448. }
  449. if (isset($category['attribs']['']['scheme']))
  450. {
  451. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  452. }
  453. if (isset($category['attribs']['']['label']))
  454. {
  455. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  456. }
  457. $categories[] = $this->registry->create('Category', array($term, $scheme, $label, $type));
  458. }
  459. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, $type) as $category)
  460. {
  461. // This is really the label, but keep this as the term also for BC.
  462. // Label will also work on retrieving because that falls back to term.
  463. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  464. if (isset($category['attribs']['']['domain']))
  465. {
  466. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  467. }
  468. else
  469. {
  470. $scheme = null;
  471. }
  472. $categories[] = $this->registry->create('Category', array($term, $scheme, null, $type));
  473. }
  474. $type = 'subject';
  475. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, $type) as $category)
  476. {
  477. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type));
  478. }
  479. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, $type) as $category)
  480. {
  481. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type));
  482. }
  483. if (!empty($categories))
  484. {
  485. return array_unique($categories);
  486. }
  487. return null;
  488. }
  489. /**
  490. * Get an author for the item
  491. *
  492. * @since Beta 2
  493. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
  494. * @return SimplePie_Author|null
  495. */
  496. public function get_author($key = 0)
  497. {
  498. $authors = $this->get_authors();
  499. if (isset($authors[$key]))
  500. {
  501. return $authors[$key];
  502. }
  503. return null;
  504. }
  505. /**
  506. * Get a contributor for the item
  507. *
  508. * @since 1.1
  509. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
  510. * @return SimplePie_Author|null
  511. */
  512. public function get_contributor($key = 0)
  513. {
  514. $contributors = $this->get_contributors();
  515. if (isset($contributors[$key]))
  516. {
  517. return $contributors[$key];
  518. }
  519. return null;
  520. }
  521. /**
  522. * Get all contributors for the item
  523. *
  524. * Uses `<atom:contributor>`
  525. *
  526. * @since 1.1
  527. * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects
  528. */
  529. public function get_contributors()
  530. {
  531. $contributors = array();
  532. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  533. {
  534. $name = null;
  535. $uri = null;
  536. $email = null;
  537. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  538. {
  539. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  540. }
  541. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  542. {
  543. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  544. }
  545. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  546. {
  547. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  548. }
  549. if ($name !== null || $email !== null || $uri !== null)
  550. {
  551. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  552. }
  553. }
  554. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  555. {
  556. $name = null;
  557. $url = null;
  558. $email = null;
  559. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  560. {
  561. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  562. }
  563. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  564. {
  565. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  566. }
  567. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  568. {
  569. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  570. }
  571. if ($name !== null || $email !== null || $url !== null)
  572. {
  573. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  574. }
  575. }
  576. if (!empty($contributors))
  577. {
  578. return array_unique($contributors);
  579. }
  580. return null;
  581. }
  582. /**
  583. * Get all authors for the item
  584. *
  585. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
  586. *
  587. * @since Beta 2
  588. * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects
  589. */
  590. public function get_authors()
  591. {
  592. $authors = array();
  593. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  594. {
  595. $name = null;
  596. $uri = null;
  597. $email = null;
  598. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  599. {
  600. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  601. }
  602. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  603. {
  604. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  605. }
  606. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  607. {
  608. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  609. }
  610. if ($name !== null || $email !== null || $uri !== null)
  611. {
  612. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  613. }
  614. }
  615. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  616. {
  617. $name = null;
  618. $url = null;
  619. $email = null;
  620. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  621. {
  622. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  623. }
  624. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  625. {
  626. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  627. }
  628. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  629. {
  630. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  631. }
  632. if ($name !== null || $email !== null || $url !== null)
  633. {
  634. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  635. }
  636. }
  637. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  638. {
  639. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
  640. }
  641. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  642. {
  643. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  644. }
  645. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  646. {
  647. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  648. }
  649. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  650. {
  651. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  652. }
  653. if (!empty($authors))
  654. {
  655. return array_unique($authors);
  656. }
  657. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  658. {
  659. return $authors;
  660. }
  661. elseif ($authors = $this->feed->get_authors())
  662. {
  663. return $authors;
  664. }
  665. return null;
  666. }
  667. /**
  668. * Get the copyright info for the item
  669. *
  670. * Uses `<atom:rights>` or `<dc:rights>`
  671. *
  672. * @since 1.1
  673. * @return string
  674. */
  675. public function get_copyright()
  676. {
  677. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  678. {
  679. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  680. }
  681. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  682. {
  683. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  684. }
  685. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  686. {
  687. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  688. }
  689. return null;
  690. }
  691. /**
  692. * Get the posting date/time for the item
  693. *
  694. * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`,
  695. * `<atom:modified>`, `<pubDate>` or `<dc:date>`
  696. *
  697. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  698. * {@see get_gmdate}
  699. *
  700. * @since Beta 2 (previously called `get_item_date` since 0.8)
  701. *
  702. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  703. * @return int|string|null
  704. */
  705. public function get_date($date_format = 'j F Y, g:i a')
  706. {
  707. if (!isset($this->data['date']))
  708. {
  709. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  710. {
  711. $this->data['date']['raw'] = $return[0]['data'];
  712. }
  713. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  714. {
  715. $this->data['date']['raw'] = $return[0]['data'];
  716. }
  717. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  718. {
  719. $this->data['date']['raw'] = $return[0]['data'];
  720. }
  721. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  722. {
  723. $this->data['date']['raw'] = $return[0]['data'];
  724. }
  725. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  726. {
  727. $this->data['date']['raw'] = $return[0]['data'];
  728. }
  729. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  730. {
  731. $this->data['date']['raw'] = $return[0]['data'];
  732. }
  733. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  734. {
  735. $this->data['date']['raw'] = $return[0]['data'];
  736. }
  737. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  738. {
  739. $this->data['date']['raw'] = $return[0]['data'];
  740. }
  741. if (!empty($this->data['date']['raw']))
  742. {
  743. $parser = $this->registry->call('Parse_Date', 'get');
  744. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  745. }
  746. else
  747. {
  748. $this->data['date'] = null;
  749. }
  750. }
  751. if ($this->data['date'])
  752. {
  753. $date_format = (string) $date_format;
  754. switch ($date_format)
  755. {
  756. case '':
  757. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  758. case 'U':
  759. return $this->data['date']['parsed'];
  760. default:
  761. return date($date_format, $this->data['date']['parsed']);
  762. }
  763. }
  764. return null;
  765. }
  766. /**
  767. * Get the update date/time for the item
  768. *
  769. * Uses `<atom:updated>`
  770. *
  771. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  772. * {@see get_gmdate}
  773. *
  774. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  775. * @return int|string|null
  776. */
  777. public function get_updated_date($date_format = 'j F Y, g:i a')
  778. {
  779. if (!isset($this->data['updated']))
  780. {
  781. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  782. {
  783. $this->data['updated']['raw'] = $return[0]['data'];
  784. }
  785. if (!empty($this->data['updated']['raw']))
  786. {
  787. $parser = $this->registry->call('Parse_Date', 'get');
  788. $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']);
  789. }
  790. else
  791. {
  792. $this->data['updated'] = null;
  793. }
  794. }
  795. if ($this->data['updated'])
  796. {
  797. $date_format = (string) $date_format;
  798. switch ($date_format)
  799. {
  800. case '':
  801. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  802. case 'U':
  803. return $this->data['updated']['parsed'];
  804. default:
  805. return date($date_format, $this->data['updated']['parsed']);
  806. }
  807. }
  808. return null;
  809. }
  810. /**
  811. * Get the localized posting date/time for the item
  812. *
  813. * Returns the date formatted in the localized language. To display in
  814. * languages other than the server's default, you need to change the locale
  815. * with {@link http://php.net/setlocale setlocale()}. The available
  816. * localizations depend on which ones are installed on your web server.
  817. *
  818. * @since 1.0
  819. *
  820. * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data)
  821. * @return int|string|null
  822. */
  823. public function get_local_date($date_format = '%c')
  824. {
  825. if (!$date_format)
  826. {
  827. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  828. }
  829. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  830. {
  831. return strftime($date_format, $date);
  832. }
  833. return null;
  834. }
  835. /**
  836. * Get the posting date/time for the item (UTC time)
  837. *
  838. * @see get_date
  839. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  840. * @return int|string|null
  841. */
  842. public function get_gmdate($date_format = 'j F Y, g:i a')
  843. {
  844. $date = $this->get_date('U');
  845. if ($date === null)
  846. {
  847. return null;
  848. }
  849. return gmdate($date_format, $date);
  850. }
  851. /**
  852. * Get the update date/time for the item (UTC time)
  853. *
  854. * @see get_updated_date
  855. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  856. * @return int|string|null
  857. */
  858. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  859. {
  860. $date = $this->get_updated_date('U');
  861. if ($date === null)
  862. {
  863. return null;
  864. }
  865. return gmdate($date_format, $date);
  866. }
  867. /**
  868. * Get the permalink for the item
  869. *
  870. * Returns the first link available with a relationship of "alternate".
  871. * Identical to {@see get_link()} with key 0
  872. *
  873. * @see get_link
  874. * @since 0.8
  875. * @return string|null Permalink URL
  876. */
  877. public function get_permalink()
  878. {
  879. $link = $this->get_link();
  880. $enclosure = $this->get_enclosure(0);
  881. if ($link !== null)
  882. {
  883. return $link;
  884. }
  885. elseif ($enclosure !== null)
  886. {
  887. return $enclosure->get_link();
  888. }
  889. return null;
  890. }
  891. /**
  892. * Get a single link for the item
  893. *
  894. * @since Beta 3
  895. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
  896. * @param string $rel The relationship of the link to return
  897. * @return string|null Link URL
  898. */
  899. public function get_link($key = 0, $rel = 'alternate')
  900. {
  901. $links = $this->get_links($rel);
  902. if ($links[$key] !== null)
  903. {
  904. return $links[$key];
  905. }
  906. return null;
  907. }
  908. /**
  909. * Get all links for the item
  910. *
  911. * Uses `<atom:link>`, `<link>` or `<guid>`
  912. *
  913. * @since Beta 2
  914. * @param string $rel The relationship of links to return
  915. * @return array|null Links found for the item (strings)
  916. */
  917. public function get_links($rel = 'alternate')
  918. {
  919. if (!isset($this->data['links']))
  920. {
  921. $this->data['links'] = array();
  922. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  923. {
  924. if (isset($link['attribs']['']['href']))
  925. {
  926. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  927. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  928. }
  929. }
  930. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  931. {
  932. if (isset($link['attribs']['']['href']))
  933. {
  934. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  935. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  936. }
  937. }
  938. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  939. {
  940. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  941. }
  942. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  943. {
  944. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  945. }
  946. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  947. {
  948. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  949. }
  950. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  951. {
  952. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  953. {
  954. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  955. }
  956. }
  957. $keys = array_keys($this->data['links']);
  958. foreach ($keys as $key)
  959. {
  960. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  961. {
  962. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  963. {
  964. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  965. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  966. }
  967. else
  968. {
  969. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  970. }
  971. }
  972. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  973. {
  974. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  975. }
  976. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  977. }
  978. }
  979. if (isset($this->data['links'][$rel]))
  980. {
  981. return $this->data['links'][$rel];
  982. }
  983. return null;
  984. }
  985. /**
  986. * Get an enclosure from the item
  987. *
  988. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  989. *
  990. * @since Beta 2
  991. * @todo Add ability to prefer one type of content over another (in a media group).
  992. * @param int $key The enclosure that you want to return. Remember that arrays begin with 0, not 1
  993. * @return SimplePie_Enclosure|null
  994. */
  995. public function get_enclosure($key = 0, $prefer = null)
  996. {
  997. $enclosures = $this->get_enclosures();
  998. if (isset($enclosures[$key]))
  999. {
  1000. return $enclosures[$key];
  1001. }
  1002. return null;
  1003. }
  1004. /**
  1005. * Get all available enclosures (podcasts, etc.)
  1006. *
  1007. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  1008. *
  1009. * At this point, we're pretty much assuming that all enclosures for an item
  1010. * are the same content. Anything else is too complicated to
  1011. * properly support.
  1012. *
  1013. * @since Beta 2
  1014. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  1015. * @todo If an element exists at a level, but its value is empty, we should fall back to the value from the parent (if it exists).
  1016. * @return SimplePie_Enclosure[]|null List of SimplePie_Enclosure items
  1017. */
  1018. public function get_enclosures()
  1019. {
  1020. if (!isset($this->data['enclosures']))
  1021. {
  1022. $this->data['enclosures'] = array();
  1023. // Elements
  1024. $captions_parent = null;
  1025. $categories_parent = null;
  1026. $copyrights_parent = null;
  1027. $credits_parent = null;
  1028. $description_parent = null;
  1029. $duration_parent = null;
  1030. $hashes_parent = null;
  1031. $keywords_parent = null;
  1032. $player_parent = null;
  1033. $ratings_parent = null;
  1034. $restrictions_parent = null;
  1035. $thumbnails_parent = null;
  1036. $title_parent = null;
  1037. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  1038. $parent = $this->get_feed();
  1039. // CAPTIONS
  1040. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1041. {
  1042. foreach ($captions as $caption)
  1043. {
  1044. $caption_type = null;
  1045. $caption_lang = null;
  1046. $caption_startTime = null;
  1047. $caption_endTime = null;
  1048. $caption_text = null;
  1049. if (isset($caption['attribs']['']['type']))
  1050. {
  1051. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1052. }
  1053. if (isset($caption['attribs']['']['lang']))
  1054. {
  1055. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1056. }
  1057. if (isset($caption['attribs']['']['start']))
  1058. {
  1059. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1060. }
  1061. if (isset($caption['attribs']['']['end']))
  1062. {
  1063. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1064. }
  1065. if (isset($caption['data']))
  1066. {
  1067. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1068. }
  1069. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1070. }
  1071. }
  1072. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1073. {
  1074. foreach ($captions as $caption)
  1075. {
  1076. $caption_type = null;
  1077. $caption_lang = null;
  1078. $caption_startTime = null;
  1079. $caption_endTime = null;
  1080. $caption_text = null;
  1081. if (isset($caption['attribs']['']['type']))
  1082. {
  1083. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1084. }
  1085. if (isset($caption['attribs']['']['lang']))
  1086. {
  1087. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1088. }
  1089. if (isset($caption['attribs']['']['start']))
  1090. {
  1091. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1092. }
  1093. if (isset($caption['attribs']['']['end']))
  1094. {
  1095. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1096. }
  1097. if (isset($caption['data']))
  1098. {
  1099. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1100. }
  1101. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1102. }
  1103. }
  1104. if (is_array($captions_parent))
  1105. {
  1106. $captions_parent = array_values(array_unique($captions_parent));
  1107. }
  1108. // CATEGORIES
  1109. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1110. {
  1111. $term = null;
  1112. $scheme = null;
  1113. $label = null;
  1114. if (isset($category['data']))
  1115. {
  1116. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1117. }
  1118. if (isset($category['attribs']['']['scheme']))
  1119. {
  1120. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1121. }
  1122. else
  1123. {
  1124. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1125. }
  1126. if (isset($category['attribs']['']['label']))
  1127. {
  1128. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1129. }
  1130. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1131. }
  1132. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1133. {
  1134. $term = null;
  1135. $scheme = null;
  1136. $label = null;
  1137. if (isset($category['data']))
  1138. {
  1139. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1140. }
  1141. if (isset($category['attribs']['']['scheme']))
  1142. {
  1143. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1144. }
  1145. else
  1146. {
  1147. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1148. }
  1149. if (isset($category['attribs']['']['label']))
  1150. {
  1151. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1152. }
  1153. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1154. }
  1155. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  1156. {
  1157. $term = null;
  1158. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  1159. $label = null;
  1160. if (isset($category['attribs']['']['text']))
  1161. {
  1162. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1163. }
  1164. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1165. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  1166. {
  1167. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  1168. {
  1169. if (isset($subcategory['attribs']['']['text']))
  1170. {
  1171. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1172. }
  1173. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1174. }
  1175. }
  1176. }
  1177. if (is_array($categories_parent))
  1178. {
  1179. $categories_parent = array_values(array_unique($categories_parent));
  1180. }
  1181. // COPYRIGHT
  1182. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1183. {
  1184. $copyright_url = null;
  1185. $copyright_label = null;
  1186. if (isset($copyright[0]['attribs']['']['url']))
  1187. {
  1188. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1189. }
  1190. if (isset($copyright[0]['data']))
  1191. {
  1192. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1193. }
  1194. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1195. }
  1196. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1197. {
  1198. $copyright_url = null;
  1199. $copyright_label = null;
  1200. if (isset($copyright[0]['attribs']['']['url']))
  1201. {
  1202. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1203. }
  1204. if (isset($copyright[0]['data']))
  1205. {
  1206. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1207. }
  1208. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1209. }
  1210. // CREDITS
  1211. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1212. {
  1213. foreach ($credits as $credit)
  1214. {
  1215. $credit_role = null;
  1216. $credit_scheme = null;
  1217. $credit_name = null;
  1218. if (isset($credit['attribs']['']['role']))
  1219. {
  1220. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1221. }
  1222. if (isset($credit['attribs']['']['scheme']))
  1223. {
  1224. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1225. }
  1226. else
  1227. {
  1228. $credit_scheme = 'urn:ebu';
  1229. }
  1230. if (isset($credit['data']))
  1231. {
  1232. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1233. }
  1234. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1235. }
  1236. }
  1237. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1238. {
  1239. foreach ($credits as $credit)
  1240. {
  1241. $credit_role = null;
  1242. $credit_scheme = null;
  1243. $credit_name = null;
  1244. if (isset($credit['attribs']['']['role']))
  1245. {
  1246. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1247. }
  1248. if (isset($credit['attribs']['']['scheme']))
  1249. {
  1250. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1251. }
  1252. else
  1253. {
  1254. $credit_scheme = 'urn:ebu';
  1255. }
  1256. if (isset($credit['data']))
  1257. {
  1258. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1259. }
  1260. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1261. }
  1262. }
  1263. if (is_array($credits_parent))
  1264. {
  1265. $credits_parent = array_values(array_unique($credits_parent));
  1266. }
  1267. // DESCRIPTION
  1268. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1269. {
  1270. if (isset($description_parent[0]['data']))
  1271. {
  1272. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1273. }
  1274. }
  1275. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1276. {
  1277. if (isset($description_parent[0]['data']))
  1278. {
  1279. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1280. }
  1281. }
  1282. // DURATION
  1283. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  1284. {
  1285. $seconds = null;
  1286. $minutes = null;
  1287. $hours = null;
  1288. if (isset($duration_parent[0]['data']))
  1289. {
  1290. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1291. if (sizeof($temp) > 0)
  1292. {
  1293. $seconds = (int) array_pop($temp);
  1294. }
  1295. if (sizeof($temp) > 0)
  1296. {
  1297. $minutes = (int) array_pop($temp);
  1298. $seconds += $minutes * 60;
  1299. }
  1300. if (sizeof($temp) > 0)
  1301. {
  1302. $hours = (int) array_pop($temp);
  1303. $seconds += $hours * 3600;
  1304. }
  1305. unset($temp);
  1306. $duration_parent = $seconds;
  1307. }
  1308. }
  1309. // HASHES
  1310. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1311. {
  1312. foreach ($hashes_iterator as $hash)
  1313. {
  1314. $value = null;
  1315. $algo = null;
  1316. if (isset($hash['data']))
  1317. {
  1318. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1319. }
  1320. if (isset($hash['attribs']['']['algo']))
  1321. {
  1322. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1323. }
  1324. else
  1325. {
  1326. $algo = 'md5';
  1327. }
  1328. $hashes_parent[] = $algo.':'.$value;
  1329. }
  1330. }
  1331. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1332. {
  1333. foreach ($hashes_iterator as $hash)
  1334. {
  1335. $value = null;
  1336. $algo = null;
  1337. if (isset($hash['data']))
  1338. {
  1339. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1340. }
  1341. if (isset($hash['attribs']['']['algo']))
  1342. {
  1343. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1344. }
  1345. else
  1346. {
  1347. $algo = 'md5';
  1348. }
  1349. $hashes_parent[] = $algo.':'.$value;
  1350. }
  1351. }
  1352. if (is_array($hashes_parent))
  1353. {
  1354. $hashes_parent = array_values(array_unique($hashes_parent));
  1355. }
  1356. // KEYWORDS
  1357. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1358. {
  1359. if (isset($keywords[0]['data']))
  1360. {
  1361. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1362. foreach ($temp as $word)
  1363. {
  1364. $keywords_parent[] = trim($word);
  1365. }
  1366. }
  1367. unset($temp);
  1368. }
  1369. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1370. {
  1371. if (isset($keywords[0]['data']))
  1372. {
  1373. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1374. foreach ($temp as $word)
  1375. {
  1376. $keywords_parent[] = trim($word);
  1377. }
  1378. }
  1379. unset($temp);
  1380. }
  1381. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1382. {
  1383. if (isset($keywords[0]['data']))
  1384. {
  1385. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1386. foreach ($temp as $word)
  1387. {
  1388. $keywords_parent[] = trim($word);
  1389. }
  1390. }
  1391. unset($temp);
  1392. }
  1393. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1394. {
  1395. if (isset($keywords[0]['data']))
  1396. {
  1397. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1398. foreach ($temp as $word)
  1399. {
  1400. $keywords_parent[] = trim($word);
  1401. }
  1402. }
  1403. unset($temp);
  1404. }
  1405. if (is_array($keywords_parent))
  1406. {
  1407. $keywords_parent = array_values(array_unique($keywords_parent));
  1408. }
  1409. // PLAYER
  1410. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1411. {
  1412. if (isset($player_parent[0]['attribs']['']['url']))
  1413. {
  1414. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1415. }
  1416. }
  1417. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1418. {
  1419. if (isset($player_parent[0]['attribs']['']['url']))
  1420. {
  1421. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1422. }
  1423. }
  1424. // RATINGS
  1425. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1426. {
  1427. foreach ($ratings as $rating)
  1428. {
  1429. $rating_scheme = null;
  1430. $rating_value = null;
  1431. if (isset($rating['attribs']['']['scheme']))
  1432. {
  1433. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1434. }
  1435. else
  1436. {
  1437. $rating_scheme = 'urn:simple';
  1438. }
  1439. if (isset($rating['data']))
  1440. {
  1441. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1442. }
  1443. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1444. }
  1445. }
  1446. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1447. {
  1448. foreach ($ratings as $rating)
  1449. {
  1450. $rating_scheme = 'urn:itunes';
  1451. $rating_value = null;
  1452. if (isset($rating['data']))
  1453. {
  1454. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1455. }
  1456. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1457. }
  1458. }
  1459. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1460. {
  1461. foreach ($ratings as $rating)
  1462. {
  1463. $rating_scheme = null;
  1464. $rating_value = null;
  1465. if (isset($rating['attribs']['']['scheme']))
  1466. {
  1467. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1468. }
  1469. else
  1470. {
  1471. $rating_scheme = 'urn:simple';
  1472. }
  1473. if (isset($rating['data']))
  1474. {
  1475. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1476. }
  1477. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1478. }
  1479. }
  1480. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1481. {
  1482. foreach ($ratings as $rating)
  1483. {
  1484. $rating_scheme = 'urn:itunes';
  1485. $rating_value = null;
  1486. if (isset($rating['data']))
  1487. {
  1488. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1489. }
  1490. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1491. }
  1492. }
  1493. if (is_array($ratings_parent))
  1494. {
  1495. $ratings_parent = array_values(array_unique($ratings_parent));
  1496. }
  1497. // RESTRICTIONS
  1498. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1499. {
  1500. foreach ($restrictions as $restriction)
  1501. {
  1502. $restriction_relationship = null;
  1503. $restriction_type = null;
  1504. $restriction_value = null;
  1505. if (isset($restriction['attribs']['']['relationship']))
  1506. {
  1507. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1508. }
  1509. if (isset($restriction['attribs']['']['type']))
  1510. {
  1511. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1512. }
  1513. if (isset($restriction['data']))
  1514. {
  1515. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1516. }
  1517. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1518. }
  1519. }
  1520. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1521. {
  1522. foreach ($restrictions as $restriction)
  1523. {
  1524. $restriction_relationship = 'allow';
  1525. $restriction_type = null;
  1526. $restriction_value = 'itunes';
  1527. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1528. {
  1529. $restriction_relationship = 'deny';
  1530. }
  1531. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1532. }
  1533. }
  1534. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1535. {
  1536. foreach ($restrictions as $restriction)
  1537. {
  1538. $restriction_relationship = null;
  1539. $restriction_type = null;
  1540. $restriction_value = null;
  1541. if (isset($restriction['attribs']['']['relationship']))
  1542. {
  1543. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1544. }
  1545. if (isset($restriction['attribs']['']['type']))
  1546. {
  1547. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1548. }
  1549. if (isset($restriction['data']))
  1550. {
  1551. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1552. }
  1553. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1554. }
  1555. }
  1556. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1557. {
  1558. foreach ($restrictions as $restriction)
  1559. {
  1560. $restriction_relationship = 'allow';
  1561. $restriction_type = null;
  1562. $restriction_value = 'itunes';
  1563. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1564. {
  1565. $restriction_relationship = 'deny';
  1566. }
  1567. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1568. }
  1569. }
  1570. if (is_array($restrictions_parent))
  1571. {
  1572. $restrictions_parent = array_values(array_unique($restrictions_parent));
  1573. }
  1574. else
  1575. {
  1576. $restrictions_parent = array(new SimplePie_Restriction('allow', null, 'default'));
  1577. }
  1578. // THUMBNAILS
  1579. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1580. {
  1581. foreach ($thumbnails as $thumbnail)
  1582. {
  1583. if (isset($thumbnail['attribs']['']['url']))
  1584. {
  1585. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1586. }
  1587. }
  1588. }
  1589. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1590. {
  1591. foreach ($thumbnails as $thumbnail)
  1592. {
  1593. if (isset($thumbnail['attribs']['']['url']))
  1594. {
  1595. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1596. }
  1597. }
  1598. }
  1599. // TITLES
  1600. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1601. {
  1602. if (isset($title_parent[0]['data']))
  1603. {
  1604. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1605. }
  1606. }
  1607. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1608. {
  1609. if (isset($title_parent[0]['data']))
  1610. {
  1611. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1612. }
  1613. }
  1614. // Clear the memory
  1615. unset($parent);
  1616. // Attributes
  1617. $bitrate = null;
  1618. $channels = null;
  1619. $duration = null;
  1620. $expression = null;
  1621. $framerate = null;
  1622. $height = null;
  1623. $javascript = null;
  1624. $lang = null;
  1625. $length = null;
  1626. $medium = null;
  1627. $samplingrate = null;
  1628. $type = null;
  1629. $url = null;
  1630. $width = null;
  1631. // Elements
  1632. $captions = null;
  1633. $categories = null;
  1634. $copyrights = null;
  1635. $credits = null;
  1636. $description = null;
  1637. $hashes = null;
  1638. $keywords = null;
  1639. $player = null;
  1640. $ratings = null;
  1641. $restrictions = null;
  1642. $thumbnails = null;
  1643. $title = null;
  1644. // If we have media:group tags, loop through them.
  1645. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  1646. {
  1647. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  1648. {
  1649. // If we have media:content tags, loop through them.
  1650. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  1651. {
  1652. if (isset($content['attribs']['']['url']))
  1653. {
  1654. // Attributes
  1655. $bitrate = null;
  1656. $channels = null;
  1657. $duration = null;
  1658. $expression = null;
  1659. $framerate = null;
  1660. $height = null;
  1661. $javascript = null;
  1662. $lang = null;
  1663. $length = null;
  1664. $medium = null;
  1665. $samplingrate = null;
  1666. $type = null;
  1667. $url = null;
  1668. $width = null;
  1669. // Elements
  1670. $captions = null;
  1671. $categories = null;
  1672. $copyrights = null;
  1673. $credits = null;
  1674. $description = null;
  1675. $hashes = null;
  1676. $keywords = null;
  1677. $player = null;
  1678. $ratings = null;
  1679. $restrictions = null;
  1680. $thumbnails = null;
  1681. $title = null;
  1682. // Start checking the attributes of media:content
  1683. if (isset($content['attribs']['']['bitrate']))
  1684. {
  1685. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1686. }
  1687. if (isset($content['attribs']['']['channels']))
  1688. {
  1689. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  1690. }
  1691. if (isset($content['attribs']['']['duration']))
  1692. {
  1693. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  1694. }
  1695. else
  1696. {
  1697. $duration = $duration_parent;
  1698. }
  1699. if (isset($content['attribs']['']['expression']))
  1700. {
  1701. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  1702. }
  1703. if (isset($content['attribs']['']['framerate']))
  1704. {
  1705. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1706. }
  1707. if (isset($content['attribs']['']['height']))
  1708. {
  1709. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  1710. }
  1711. if (isset($content['attribs']['']['lang']))
  1712. {
  1713. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1714. }
  1715. if (isset($content['attribs']['']['fileSize']))
  1716. {
  1717. $length = ceil($content['attribs']['']['fileSize']);
  1718. }
  1719. if (isset($content['attribs']['']['medium']))
  1720. {
  1721. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  1722. }
  1723. if (isset($content['attribs']['']['samplingrate']))
  1724. {
  1725. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1726. }
  1727. if (isset($content['attribs']['']['type']))
  1728. {
  1729. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1730. }
  1731. if (isset($content['attribs']['']['width']))
  1732. {
  1733. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  1734. }
  1735. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1736. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  1737. // CAPTIONS
  1738. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  1739. {
  1740. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  1741. {
  1742. $caption_type = null;
  1743. $caption_lang = null;
  1744. $caption_startTime = null;
  1745. $caption_endTime = null;
  1746. $caption_text = null;
  1747. if (isset($caption['attribs']['']['type']))
  1748. {
  1749. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1750. }
  1751. if (isset($caption['attribs']['']['lang']))
  1752. {
  1753. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1754. }
  1755. if (isset($caption['attribs']['']['start']))
  1756. {
  1757. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1758. }
  1759. if (isset($caption['attribs']['']['end']))
  1760. {
  1761. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1762. }
  1763. if (isset($caption['data']))
  1764. {
  1765. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1766. }
  1767. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1768. }
  1769. if (is_array($captions))
  1770. {
  1771. $captions = array_values(array_unique($captions));
  1772. }
  1773. }
  1774. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  1775. {
  1776. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  1777. {
  1778. $caption_type = null;
  1779. $caption_lang = null;
  1780. $caption_startTime = null;
  1781. $caption_endTime = null;
  1782. $caption_text = null;
  1783. if (isset($caption['attribs']['']['type']))
  1784. {
  1785. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1786. }
  1787. if (isset($caption['attribs']['']['lang']))
  1788. {
  1789. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1790. }
  1791. if (isset($caption['attribs']['']['start']))
  1792. {
  1793. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1794. }
  1795. if (isset($caption['attribs']['']['end']))
  1796. {
  1797. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1798. }
  1799. if (isset($caption['data']))
  1800. {
  1801. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1802. }
  1803. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1804. }
  1805. if (is_array($captions))
  1806. {
  1807. $captions = array_values(array_unique($captions));
  1808. }
  1809. }
  1810. else
  1811. {
  1812. $captions = $captions_parent;
  1813. }
  1814. // CATEGORIES
  1815. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  1816. {
  1817. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  1818. {
  1819. $term = null;
  1820. $scheme = null;
  1821. $label = null;
  1822. if (isset($category['data']))
  1823. {
  1824. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1825. }
  1826. if (isset($category['attribs']['']['scheme']))
  1827. {
  1828. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1829. }
  1830. else
  1831. {
  1832. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1833. }
  1834. if (isset($category['attribs']['']['label']))
  1835. {
  1836. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1837. }
  1838. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1839. }
  1840. }
  1841. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  1842. {
  1843. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  1844. {
  1845. $term = null;
  1846. $scheme = null;
  1847. $label = null;
  1848. if (isset($category['data']))
  1849. {
  1850. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1851. }
  1852. if (isset($category['attribs']['']['scheme']))
  1853. {
  1854. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1855. }
  1856. else
  1857. {
  1858. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1859. }
  1860. if (isset($category['attribs']['']['label']))
  1861. {
  1862. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1863. }
  1864. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  1865. }
  1866. }
  1867. if (is_array($categories) && is_array($categories_parent))
  1868. {
  1869. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  1870. }
  1871. elseif (is_array($categories))
  1872. {
  1873. $categories = array_values(array_unique($categories));
  1874. }
  1875. elseif (is_array($categories_parent))
  1876. {
  1877. $categories = array_values(array_unique($categories_parent));
  1878. }
  1879. // COPYRIGHTS
  1880. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  1881. {
  1882. $copyright_url = null;
  1883. $copyright_label = null;
  1884. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  1885. {
  1886. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1887. }
  1888. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  1889. {
  1890. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1891. }
  1892. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1893. }
  1894. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  1895. {
  1896. $copyright_url = null;
  1897. $copyright_label = null;
  1898. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  1899. {
  1900. $copyright_url = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1901. }
  1902. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  1903. {
  1904. $copyright_label = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1905. }
  1906. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1907. }
  1908. else
  1909. {
  1910. $copyrights = $copyrights_parent;
  1911. }
  1912. // CREDITS
  1913. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  1914. {
  1915. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  1916. {
  1917. $credit_role = null;
  1918. $credit_scheme = null;
  1919. $credit_name = null;
  1920. if (isset($credit['attribs']['']['role']))
  1921. {
  1922. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1923. }
  1924. if (isset($credit['attribs']['']['scheme']))
  1925. {
  1926. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1927. }
  1928. else
  1929. {
  1930. $credit_scheme = 'urn:ebu';
  1931. }
  1932. if (isset($credit['data']))
  1933. {
  1934. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1935. }
  1936. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1937. }
  1938. if (is_array($credits))
  1939. {
  1940. $credits = array_values(array_unique($credits));
  1941. }
  1942. }
  1943. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  1944. {
  1945. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  1946. {
  1947. $credit_role = null;
  1948. $credit_scheme = null;
  1949. $credit_name = null;
  1950. if (isset($credit['attribs']['']['role']))
  1951. {
  1952. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1953. }
  1954. if (isset($credit['attribs']['']['scheme']))
  1955. {
  1956. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1957. }
  1958. else
  1959. {
  1960. $credit_scheme = 'urn:ebu';
  1961. }
  1962. if (isset($credit['data']))
  1963. {
  1964. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1965. }
  1966. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1967. }
  1968. if (is_array($credits))
  1969. {
  1970. $credits = array_values(array_unique($credits));
  1971. }
  1972. }
  1973. else
  1974. {
  1975. $credits = $credits_parent;
  1976. }
  1977. // DESCRIPTION
  1978. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  1979. {
  1980. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1981. }
  1982. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  1983. {
  1984. $description = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1985. }
  1986. else
  1987. {
  1988. $description = $description_parent;
  1989. }
  1990. // HASHES
  1991. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  1992. {
  1993. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  1994. {
  1995. $value = null;
  1996. $algo = null;
  1997. if (isset($hash['data']))
  1998. {
  1999. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2000. }
  2001. if (isset($hash['attribs']['']['algo']))
  2002. {
  2003. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2004. }
  2005. else
  2006. {
  2007. $algo = 'md5';
  2008. }
  2009. $hashes[] = $algo.':'.$value;
  2010. }
  2011. if (is_array($hashes))
  2012. {
  2013. $hashes = array_values(array_unique($hashes));
  2014. }
  2015. }
  2016. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2017. {
  2018. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2019. {
  2020. $value = null;
  2021. $algo = null;
  2022. if (isset($hash['data']))
  2023. {
  2024. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2025. }
  2026. if (isset($hash['attribs']['']['algo']))
  2027. {
  2028. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2029. }
  2030. else
  2031. {
  2032. $algo = 'md5';
  2033. }
  2034. $hashes[] = $algo.':'.$value;
  2035. }
  2036. if (is_array($hashes))
  2037. {
  2038. $hashes = array_values(array_unique($hashes));
  2039. }
  2040. }
  2041. else
  2042. {
  2043. $hashes = $hashes_parent;
  2044. }
  2045. // KEYWORDS
  2046. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2047. {
  2048. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2049. {
  2050. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2051. foreach ($temp as $word)
  2052. {
  2053. $keywords[] = trim($word);
  2054. }
  2055. unset($temp);
  2056. }
  2057. if (is_array($keywords))
  2058. {
  2059. $keywords = array_values(array_unique($keywords));
  2060. }
  2061. }
  2062. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2063. {
  2064. if (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2065. {
  2066. $temp = explode(',', $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2067. foreach ($temp as $word)
  2068. {
  2069. $keywords[] = trim($word);
  2070. }
  2071. unset($temp);
  2072. }
  2073. if (is_array($keywords))
  2074. {
  2075. $keywords = array_values(array_unique($keywords));
  2076. }
  2077. }
  2078. else
  2079. {
  2080. $keywords = $keywords_parent;
  2081. }
  2082. // PLAYER
  2083. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2084. {
  2085. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2086. }
  2087. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2088. {
  2089. $player = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2090. }
  2091. else
  2092. {
  2093. $player = $player_parent;
  2094. }
  2095. // RATINGS
  2096. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2097. {
  2098. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2099. {
  2100. $rating_scheme = null;
  2101. $rating_value = null;
  2102. if (isset($rating['attribs']['']['scheme']))
  2103. {
  2104. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2105. }
  2106. else
  2107. {
  2108. $rating_scheme = 'urn:simple';
  2109. }
  2110. if (isset($rating['data']))
  2111. {
  2112. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2113. }
  2114. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2115. }
  2116. if (is_array($ratings))
  2117. {
  2118. $ratings = array_values(array_unique($ratings));
  2119. }
  2120. }
  2121. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2122. {
  2123. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2124. {
  2125. $rating_scheme = null;
  2126. $rating_value = null;
  2127. if (isset($rating['attribs']['']['scheme']))
  2128. {
  2129. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2130. }
  2131. else
  2132. {
  2133. $rating_scheme = 'urn:simple';
  2134. }
  2135. if (isset($rating['data']))
  2136. {
  2137. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2138. }
  2139. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2140. }
  2141. if (is_array($ratings))
  2142. {
  2143. $ratings = array_values(array_unique($ratings));
  2144. }
  2145. }
  2146. else
  2147. {
  2148. $ratings = $ratings_parent;
  2149. }
  2150. // RESTRICTIONS
  2151. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2152. {
  2153. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2154. {
  2155. $restriction_relationship = null;
  2156. $restriction_type = null;
  2157. $restriction_value = null;
  2158. if (isset($restriction['attribs']['']['relationship']))
  2159. {
  2160. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2161. }
  2162. if (isset($restriction['attribs']['']['type']))
  2163. {
  2164. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2165. }
  2166. if (isset($restriction['data']))
  2167. {
  2168. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2169. }
  2170. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2171. }
  2172. if (is_array($restrictions))
  2173. {
  2174. $restrictions = array_values(array_unique($restrictions));
  2175. }
  2176. }
  2177. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2178. {
  2179. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2180. {
  2181. $restriction_relationship = null;
  2182. $restriction_type = null;
  2183. $restriction_value = null;
  2184. if (isset($restriction['attribs']['']['relationship']))
  2185. {
  2186. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2187. }
  2188. if (isset($restriction['attribs']['']['type']))
  2189. {
  2190. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2191. }
  2192. if (isset($restriction['data']))
  2193. {
  2194. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2195. }
  2196. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2197. }
  2198. if (is_array($restrictions))
  2199. {
  2200. $restrictions = array_values(array_unique($restrictions));
  2201. }
  2202. }
  2203. else
  2204. {
  2205. $restrictions = $restrictions_parent;
  2206. }
  2207. // THUMBNAILS
  2208. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2209. {
  2210. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2211. {
  2212. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2213. }
  2214. if (is_array($thumbnails))
  2215. {
  2216. $thumbnails = array_values(array_unique($thumbnails));
  2217. }
  2218. }
  2219. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2220. {
  2221. foreach ($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2222. {
  2223. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2224. }
  2225. if (is_array($thumbnails))
  2226. {
  2227. $thumbnails = array_values(array_unique($thumbnails));
  2228. }
  2229. }
  2230. else
  2231. {
  2232. $thumbnails = $thumbnails_parent;
  2233. }
  2234. // TITLES
  2235. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2236. {
  2237. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2238. }
  2239. elseif (isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2240. {
  2241. $title = $this->sanitize($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2242. }
  2243. else
  2244. {
  2245. $title = $title_parent;
  2246. }
  2247. $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));
  2248. }
  2249. }
  2250. }
  2251. }
  2252. // If we have standalone media:content tags, loop through them.
  2253. if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  2254. {
  2255. foreach ((array) $this->data['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  2256. {
  2257. if (isset($content['attribs']['']['url']) || isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2258. {
  2259. // Attributes
  2260. $bitrate = null;
  2261. $channels = null;
  2262. $duration = null;
  2263. $expression = null;
  2264. $framerate = null;
  2265. $height = null;
  2266. $javascript = null;
  2267. $lang = null;
  2268. $length = null;
  2269. $medium = null;
  2270. $samplingrate = null;
  2271. $type = null;
  2272. $url = null;
  2273. $width = null;
  2274. // Elements
  2275. $captions = null;
  2276. $categories = null;
  2277. $copyrights = null;
  2278. $credits = null;
  2279. $description = null;
  2280. $hashes = null;
  2281. $keywords = null;
  2282. $player = null;
  2283. $ratings = null;
  2284. $restrictions = null;
  2285. $thumbnails = null;
  2286. $title = null;
  2287. // Start checking the attributes of media:content
  2288. if (isset($content['attribs']['']['bitrate']))
  2289. {
  2290. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2291. }
  2292. if (isset($content['attribs']['']['channels']))
  2293. {
  2294. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  2295. }
  2296. if (isset($content['attribs']['']['duration']))
  2297. {
  2298. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  2299. }
  2300. else
  2301. {
  2302. $duration = $duration_parent;
  2303. }
  2304. if (isset($content['attribs']['']['expression']))
  2305. {
  2306. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  2307. }
  2308. if (isset($content['attribs']['']['framerate']))
  2309. {
  2310. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2311. }
  2312. if (isset($content['attribs']['']['height']))
  2313. {
  2314. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  2315. }
  2316. if (isset($content['attribs']['']['lang']))
  2317. {
  2318. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2319. }
  2320. if (isset($content['attribs']['']['fileSize']))
  2321. {
  2322. $length = ceil($content['attribs']['']['fileSize']);
  2323. }
  2324. if (isset($content['attribs']['']['medium']))
  2325. {
  2326. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  2327. }
  2328. if (isset($content['attribs']['']['samplingrate']))
  2329. {
  2330. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  2331. }
  2332. if (isset($content['attribs']['']['type']))
  2333. {
  2334. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2335. }
  2336. if (isset($content['attribs']['']['width']))
  2337. {
  2338. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  2339. }
  2340. if (isset($content['attribs']['']['url']))
  2341. {
  2342. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2343. }
  2344. // Checking the other optional media: elements. Priority: media:content, media:group, item, channel
  2345. // CAPTIONS
  2346. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text']))
  2347. {
  2348. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['text'] as $caption)
  2349. {
  2350. $caption_type = null;
  2351. $caption_lang = null;
  2352. $caption_startTime = null;
  2353. $caption_endTime = null;
  2354. $caption_text = null;
  2355. if (isset($caption['attribs']['']['type']))
  2356. {
  2357. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2358. }
  2359. if (isset($caption['attribs']['']['lang']))
  2360. {
  2361. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  2362. }
  2363. if (isset($caption['attribs']['']['start']))
  2364. {
  2365. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  2366. }
  2367. if (isset($caption['attribs']['']['end']))
  2368. {
  2369. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  2370. }
  2371. if (isset($caption['data']))
  2372. {
  2373. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2374. }
  2375. $captions[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  2376. }
  2377. if (is_array($captions))
  2378. {
  2379. $captions = array_values(array_unique($captions));
  2380. }
  2381. }
  2382. else
  2383. {
  2384. $captions = $captions_parent;
  2385. }
  2386. // CATEGORIES
  2387. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category']))
  2388. {
  2389. foreach ((array) $content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['category'] as $category)
  2390. {
  2391. $term = null;
  2392. $scheme = null;
  2393. $label = null;
  2394. if (isset($category['data']))
  2395. {
  2396. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2397. }
  2398. if (isset($category['attribs']['']['scheme']))
  2399. {
  2400. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2401. }
  2402. else
  2403. {
  2404. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  2405. }
  2406. if (isset($category['attribs']['']['label']))
  2407. {
  2408. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  2409. }
  2410. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  2411. }
  2412. }
  2413. if (is_array($categories) && is_array($categories_parent))
  2414. {
  2415. $categories = array_values(array_unique(array_merge($categories, $categories_parent)));
  2416. }
  2417. elseif (is_array($categories))
  2418. {
  2419. $categories = array_values(array_unique($categories));
  2420. }
  2421. elseif (is_array($categories_parent))
  2422. {
  2423. $categories = array_values(array_unique($categories_parent));
  2424. }
  2425. else
  2426. {
  2427. $categories = null;
  2428. }
  2429. // COPYRIGHTS
  2430. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright']))
  2431. {
  2432. $copyright_url = null;
  2433. $copyright_label = null;
  2434. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url']))
  2435. {
  2436. $copyright_url = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  2437. }
  2438. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data']))
  2439. {
  2440. $copyright_label = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['copyright'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2441. }
  2442. $copyrights = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  2443. }
  2444. else
  2445. {
  2446. $copyrights = $copyrights_parent;
  2447. }
  2448. // CREDITS
  2449. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit']))
  2450. {
  2451. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['credit'] as $credit)
  2452. {
  2453. $credit_role = null;
  2454. $credit_scheme = null;
  2455. $credit_name = null;
  2456. if (isset($credit['attribs']['']['role']))
  2457. {
  2458. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  2459. }
  2460. if (isset($credit['attribs']['']['scheme']))
  2461. {
  2462. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2463. }
  2464. else
  2465. {
  2466. $credit_scheme = 'urn:ebu';
  2467. }
  2468. if (isset($credit['data']))
  2469. {
  2470. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2471. }
  2472. $credits[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  2473. }
  2474. if (is_array($credits))
  2475. {
  2476. $credits = array_values(array_unique($credits));
  2477. }
  2478. }
  2479. else
  2480. {
  2481. $credits = $credits_parent;
  2482. }
  2483. // DESCRIPTION
  2484. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description']))
  2485. {
  2486. $description = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['description'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2487. }
  2488. else
  2489. {
  2490. $description = $description_parent;
  2491. }
  2492. // HASHES
  2493. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash']))
  2494. {
  2495. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['hash'] as $hash)
  2496. {
  2497. $value = null;
  2498. $algo = null;
  2499. if (isset($hash['data']))
  2500. {
  2501. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2502. }
  2503. if (isset($hash['attribs']['']['algo']))
  2504. {
  2505. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  2506. }
  2507. else
  2508. {
  2509. $algo = 'md5';
  2510. }
  2511. $hashes[] = $algo.':'.$value;
  2512. }
  2513. if (is_array($hashes))
  2514. {
  2515. $hashes = array_values(array_unique($hashes));
  2516. }
  2517. }
  2518. else
  2519. {
  2520. $hashes = $hashes_parent;
  2521. }
  2522. // KEYWORDS
  2523. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords']))
  2524. {
  2525. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data']))
  2526. {
  2527. $temp = explode(',', $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['keywords'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  2528. foreach ($temp as $word)
  2529. {
  2530. $keywords[] = trim($word);
  2531. }
  2532. unset($temp);
  2533. }
  2534. if (is_array($keywords))
  2535. {
  2536. $keywords = array_values(array_unique($keywords));
  2537. }
  2538. }
  2539. else
  2540. {
  2541. $keywords = $keywords_parent;
  2542. }
  2543. // PLAYER
  2544. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player']))
  2545. {
  2546. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'])) {
  2547. $player = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['player'][0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2548. }
  2549. }
  2550. else
  2551. {
  2552. $player = $player_parent;
  2553. }
  2554. // RATINGS
  2555. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating']))
  2556. {
  2557. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['rating'] as $rating)
  2558. {
  2559. $rating_scheme = null;
  2560. $rating_value = null;
  2561. if (isset($rating['attribs']['']['scheme']))
  2562. {
  2563. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  2564. }
  2565. else
  2566. {
  2567. $rating_scheme = 'urn:simple';
  2568. }
  2569. if (isset($rating['data']))
  2570. {
  2571. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2572. }
  2573. $ratings[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  2574. }
  2575. if (is_array($ratings))
  2576. {
  2577. $ratings = array_values(array_unique($ratings));
  2578. }
  2579. }
  2580. else
  2581. {
  2582. $ratings = $ratings_parent;
  2583. }
  2584. // RESTRICTIONS
  2585. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction']))
  2586. {
  2587. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['restriction'] as $restriction)
  2588. {
  2589. $restriction_relationship = null;
  2590. $restriction_type = null;
  2591. $restriction_value = null;
  2592. if (isset($restriction['attribs']['']['relationship']))
  2593. {
  2594. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  2595. }
  2596. if (isset($restriction['attribs']['']['type']))
  2597. {
  2598. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2599. }
  2600. if (isset($restriction['data']))
  2601. {
  2602. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2603. }
  2604. $restrictions[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  2605. }
  2606. if (is_array($restrictions))
  2607. {
  2608. $restrictions = array_values(array_unique($restrictions));
  2609. }
  2610. }
  2611. else
  2612. {
  2613. $restrictions = $restrictions_parent;
  2614. }
  2615. // THUMBNAILS
  2616. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail']))
  2617. {
  2618. foreach ($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['thumbnail'] as $thumbnail)
  2619. {
  2620. if (isset($thumbnail['attribs']['']['url'])) {
  2621. $thumbnails[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  2622. }
  2623. }
  2624. if (is_array($thumbnails))
  2625. {
  2626. $thumbnails = array_values(array_unique($thumbnails));
  2627. }
  2628. }
  2629. else
  2630. {
  2631. $thumbnails = $thumbnails_parent;
  2632. }
  2633. // TITLES
  2634. if (isset($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title']))
  2635. {
  2636. $title = $this->sanitize($content['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['title'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  2637. }
  2638. else
  2639. {
  2640. $title = $title_parent;
  2641. }
  2642. $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));
  2643. }
  2644. }
  2645. }
  2646. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  2647. {
  2648. if (isset($link['attribs']['']['href']) && !empty($link['attribs']['']['rel']) && $link['attribs']['']['rel'] === 'enclosure')
  2649. {
  2650. // Attributes
  2651. $bitrate = null;
  2652. $channels = null;
  2653. $duration = null;
  2654. $expression = null;
  2655. $framerate = null;
  2656. $height = null;
  2657. $javascript = null;
  2658. $lang = null;
  2659. $length = null;
  2660. $medium = null;
  2661. $samplingrate = null;
  2662. $type = null;
  2663. $url = null;
  2664. $width = null;
  2665. $url = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  2666. if (isset($link['attribs']['']['type']))
  2667. {
  2668. $type = $this->sanitize($link['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2669. }
  2670. if (isset($link['attribs']['']['length']))
  2671. {
  2672. $length = ceil($link['attribs']['']['length']);
  2673. }
  2674. if (isset($link['attribs']['']['title']))
  2675. {
  2676. $title = $this->sanitize($link['attribs']['']['title'], SIMPLEPIE_CONSTRUCT_TEXT);
  2677. }
  2678. else
  2679. {
  2680. $title = $title_parent;
  2681. }
  2682. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2683. $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, $width));
  2684. }
  2685. }
  2686. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, '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. if ($enclosure = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'enclosure'))
  2719. {
  2720. if (isset($enclosure[0]['attribs']['']['url']))
  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($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0]));
  2738. if (isset($enclosure[0]['attribs']['']['type']))
  2739. {
  2740. $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  2741. }
  2742. if (isset($enclosure[0]['attribs']['']['length']))
  2743. {
  2744. $length = ceil($enclosure[0]['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 (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))
  2751. {
  2752. // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor
  2753. $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));
  2754. }
  2755. $this->data['enclosures'] = array_values(array_unique($this->data['enclosures']));
  2756. }
  2757. if (!empty($this->data['enclosures']))
  2758. {
  2759. return $this->data['enclosures'];
  2760. }
  2761. return null;
  2762. }
  2763. /**
  2764. * Get the latitude coordinates for the item
  2765. *
  2766. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2767. *
  2768. * Uses `<geo:lat>` or `<georss:point>`
  2769. *
  2770. * @since 1.0
  2771. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2772. * @link http://www.georss.org/ GeoRSS
  2773. * @return string|null
  2774. */
  2775. public function get_latitude()
  2776. {
  2777. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  2778. {
  2779. return (float) $return[0]['data'];
  2780. }
  2781. 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))
  2782. {
  2783. return (float) $match[1];
  2784. }
  2785. return null;
  2786. }
  2787. /**
  2788. * Get the longitude coordinates for the item
  2789. *
  2790. * Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications
  2791. *
  2792. * Uses `<geo:long>`, `<geo:lon>` or `<georss:point>`
  2793. *
  2794. * @since 1.0
  2795. * @link http://www.w3.org/2003/01/geo/ W3C WGS84 Basic Geo
  2796. * @link http://www.georss.org/ GeoRSS
  2797. * @return string|null
  2798. */
  2799. public function get_longitude()
  2800. {
  2801. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  2802. {
  2803. return (float) $return[0]['data'];
  2804. }
  2805. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  2806. {
  2807. return (float) $return[0]['data'];
  2808. }
  2809. 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))
  2810. {
  2811. return (float) $match[2];
  2812. }
  2813. return null;
  2814. }
  2815. /**
  2816. * Get the `<atom:source>` for the item
  2817. *
  2818. * @since 1.1
  2819. * @return SimplePie_Source|null
  2820. */
  2821. public function get_source()
  2822. {
  2823. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'source'))
  2824. {
  2825. return $this->registry->create('Source', array($this, $return[0]));
  2826. }
  2827. return null;
  2828. }
  2829. }