PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/SimplePie/Item.php

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