PageRenderTime 63ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/wacko/lib/SimplePie/library/SimplePie/Item.php

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