PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/SimplePie/Item.php

https://bitbucket.org/erickjones/aotopo
PHP | 2964 lines | 2414 code | 115 blank | 435 comment | 354 complexity | 104510e221fa08437aec008e633cdca7 MD5 | raw file
Possible License(s): LGPL-3.0

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

  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-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. {

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