PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/wackowiki/wackowiki-dev
PHP | 3009 lines | 2450 code | 117 blank | 442 comment | 358 complexity | 00ececdba44b9e6778d999858e953d59 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, LGPL-2.1

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-2016, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package SimplePie
  36. * @copyright 2004-2016 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  37. * @author Ryan Parman
  38. * @author Geoffrey Sneddon
  39. * @author Ryan McCue
  40. * @link http://simplepie.org/ SimplePie
  41. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  42. */
  43. /**
  44. * Manages all item-related data
  45. *
  46. * Used by {@see SimplePie::get_item()} and {@see SimplePie::get_items()}
  47. *
  48. * This class can be overloaded with {@see SimplePie::set_item_class()}
  49. *
  50. * @package SimplePie
  51. * @subpackage API
  52. */
  53. class SimplePie_Item
  54. {
  55. /**
  56. * Parent feed
  57. *
  58. * @access private
  59. * @var SimplePie
  60. */
  61. var $feed;
  62. /**
  63. * Raw data
  64. *
  65. * @access private
  66. * @var array
  67. */
  68. var $data = array();
  69. /**
  70. * Registry object
  71. *
  72. * @see set_registry
  73. * @var SimplePie_Registry
  74. */
  75. protected $registry;
  76. /**
  77. * Create a new item object
  78. *
  79. * This is usually used by {@see SimplePie::get_items} and
  80. * {@see SimplePie::get_item}. Avoid creating this manually.
  81. *
  82. * @param SimplePie $feed Parent feed
  83. * @param array $data Raw data
  84. */
  85. public function __construct($feed, $data)
  86. {
  87. $this->feed = $feed;
  88. $this->data = $data;
  89. }
  90. /**
  91. * Set the registry handler
  92. *
  93. * This is usually used by {@see SimplePie_Registry::create}
  94. *
  95. * @since 1.3
  96. * @param SimplePie_Registry $registry
  97. */
  98. public function set_registry(SimplePie_Registry $registry)
  99. {
  100. $this->registry = $registry;
  101. }
  102. /**
  103. * Get a string representation of the item
  104. *
  105. * @return string
  106. */
  107. public function __toString()
  108. {
  109. return md5(serialize($this->data));
  110. }
  111. /**
  112. * Remove items that link back to this before destroying this object
  113. */
  114. public function __destruct()
  115. {
  116. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  117. {
  118. unset($this->feed);
  119. }
  120. }
  121. /**
  122. * Get data for an item-level element
  123. *
  124. * This method allows you to get access to ANY element/attribute that is a
  125. * sub-element of the item/entry tag.
  126. *
  127. * See {@see SimplePie::get_feed_tags()} for a description of the return value
  128. *
  129. * @since 1.0
  130. * @see http://simplepie.org/wiki/faq/supported_xml_namespaces
  131. * @param string $namespace The URL of the XML namespace of the elements you're trying to access
  132. * @param string $tag Tag name
  133. * @return array
  134. */
  135. public function get_item_tags($namespace, $tag)
  136. {
  137. if (isset($this->data['child'][$namespace][$tag]))
  138. {
  139. return $this->data['child'][$namespace][$tag];
  140. }
  141. else
  142. {
  143. return null;
  144. }
  145. }
  146. /**
  147. * Get the base URL value from the parent feed
  148. *
  149. * Uses `<xml:base>`
  150. *
  151. * @param array $element
  152. * @return string
  153. */
  154. public function get_base($element = array())
  155. {
  156. return $this->feed->get_base($element);
  157. }
  158. /**
  159. * Sanitize feed data
  160. *
  161. * @access private
  162. * @see SimplePie::sanitize()
  163. * @param string $data Data to sanitize
  164. * @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
  165. * @param string $base Base URL to resolve URLs against
  166. * @return string Sanitized data
  167. */
  168. public function sanitize($data, $type, $base = '')
  169. {
  170. return $this->feed->sanitize($data, $type, $base);
  171. }
  172. /**
  173. * Get the parent feed
  174. *
  175. * Note: this may not work as you think for multifeeds!
  176. *
  177. * @link http://simplepie.org/faq/typical_multifeed_gotchas#missing_data_from_feed
  178. * @since 1.0
  179. * @return SimplePie
  180. */
  181. public function get_feed()
  182. {
  183. return $this->feed;
  184. }
  185. /**
  186. * Get the unique identifier for the item
  187. *
  188. * This is usually used when writing code to check for new items in a feed.
  189. *
  190. * Uses `<atom:id>`, `<guid>`, `<dc:identifier>` or the `about` attribute
  191. * for RDF. If none of these are supplied (or `$hash` is true), creates an
  192. * MD5 hash based on the permalink, title and content.
  193. *
  194. * @since Beta 2
  195. * @param boolean $hash Should we force using a hash instead of the supplied ID?
  196. * @param string|false $fn User-supplied function to generate an hash
  197. * @return string|null
  198. */
  199. public function get_id($hash = false, $fn = 'md5')
  200. {
  201. if (!$hash)
  202. {
  203. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  204. {
  205. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  206. }
  207. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  208. {
  209. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  210. }
  211. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  212. {
  213. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  214. }
  215. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  216. {
  217. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  218. }
  219. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  220. {
  221. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  222. }
  223. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  224. {
  225. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  226. }
  227. }
  228. if ($fn === false)
  229. {
  230. return null;
  231. }
  232. elseif (!is_callable($fn))
  233. {
  234. trigger_error('User-supplied function $fn must be callable', E_USER_WARNING);
  235. $fn = 'md5';
  236. }
  237. return call_user_func($fn,
  238. $this->get_permalink().$this->get_title().$this->get_content());
  239. }
  240. /**
  241. * Get the title of the item
  242. *
  243. * Uses `<atom:title>`, `<title>` or `<dc:title>`
  244. *
  245. * @since Beta 2 (previously called `get_item_title` since 0.8)
  246. * @return string|null
  247. */
  248. public function get_title()
  249. {
  250. if (!isset($this->data['title']))
  251. {
  252. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  253. {
  254. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  255. }
  256. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  257. {
  258. $this->data['title'] = $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  259. }
  260. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  261. {
  262. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  263. }
  264. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  265. {
  266. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  267. }
  268. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  269. {
  270. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  271. }
  272. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  273. {
  274. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  275. }
  276. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  277. {
  278. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  279. }
  280. else
  281. {
  282. $this->data['title'] = null;
  283. }
  284. }
  285. return $this->data['title'];
  286. }
  287. /**
  288. * Get the content for the item
  289. *
  290. * Prefers summaries over full content , but will return full content if a
  291. * summary does not exist.
  292. *
  293. * To prefer full content instead, use {@see get_content}
  294. *
  295. * Uses `<atom:summary>`, `<description>`, `<dc:description>` or
  296. * `<itunes:subtitle>`
  297. *
  298. * @since 0.8
  299. * @param boolean $description_only Should we avoid falling back to the content?
  300. * @return string|null
  301. */
  302. public function get_description($description_only = false)
  303. {
  304. if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary')) &&
  305. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  306. {
  307. return $return;
  308. }
  309. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary')) &&
  310. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  311. {
  312. return $return;
  313. }
  314. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description')) &&
  315. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($tags[0]))))
  316. {
  317. return $return;
  318. }
  319. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description')) &&
  320. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  321. {
  322. return $return;
  323. }
  324. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description')) &&
  325. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  326. {
  327. return $return;
  328. }
  329. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description')) &&
  330. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  331. {
  332. return $return;
  333. }
  334. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary')) &&
  335. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  336. {
  337. return $return;
  338. }
  339. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle')) &&
  340. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)))
  341. {
  342. return $return;
  343. }
  344. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description')) &&
  345. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)))
  346. {
  347. return $return;
  348. }
  349. elseif (!$description_only)
  350. {
  351. return $this->get_content(true);
  352. }
  353. else
  354. {
  355. return null;
  356. }
  357. }
  358. /**
  359. * Get the content for the item
  360. *
  361. * Prefers full content over summaries, but will return a summary if full
  362. * content does not exist.
  363. *
  364. * To prefer summaries instead, use {@see get_description}
  365. *
  366. * Uses `<atom:content>` or `<content:encoded>` (RSS 1.0 Content Module)
  367. *
  368. * @since 1.0
  369. * @param boolean $content_only Should we avoid falling back to the description?
  370. * @return string|null
  371. */
  372. public function get_content($content_only = false)
  373. {
  374. if (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content')) &&
  375. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  376. {
  377. return $return;
  378. }
  379. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content')) &&
  380. ($return = $this->sanitize($tags[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($tags[0]['attribs'])), $this->get_base($tags[0]))))
  381. {
  382. return $return;
  383. }
  384. elseif (($tags = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded')) &&
  385. ($return = $this->sanitize($tags[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($tags[0]))))
  386. {
  387. return $return;
  388. }
  389. elseif (!$content_only)
  390. {
  391. return $this->get_description(true);
  392. }
  393. else
  394. {
  395. return null;
  396. }
  397. }
  398. /**
  399. * Get the media:thumbnail of the item
  400. *
  401. * Uses `<media:thumbnail>`
  402. *
  403. *
  404. * @return array|null
  405. */
  406. public function get_thumbnail()
  407. {
  408. if (!isset($this->data['thumbnail']))
  409. {
  410. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  411. {
  412. $this->data['thumbnail'] = $return[0]['attribs'][''];
  413. }
  414. else
  415. {
  416. $this->data['thumbnail'] = null;
  417. }
  418. }
  419. return $this->data['thumbnail'];
  420. }
  421. /**
  422. * Get a category for the item
  423. *
  424. * @since Beta 3 (previously called `get_categories()` since Beta 2)
  425. * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
  426. * @return SimplePie_Category|null
  427. */
  428. public function get_category($key = 0)
  429. {
  430. $categories = $this->get_categories();
  431. if (isset($categories[$key]))
  432. {
  433. return $categories[$key];
  434. }
  435. else
  436. {
  437. return null;
  438. }
  439. }
  440. /**
  441. * Get all categories for the item
  442. *
  443. * Uses `<atom:category>`, `<category>` or `<dc:subject>`
  444. *
  445. * @since Beta 3
  446. * @return SimplePie_Category[]|null List of {@see SimplePie_Category} objects
  447. */
  448. public function get_categories()
  449. {
  450. $categories = array();
  451. $type = 'category';
  452. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, $type) as $category)
  453. {
  454. $term = null;
  455. $scheme = null;
  456. $label = null;
  457. if (isset($category['attribs']['']['term']))
  458. {
  459. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_HTML);
  460. }
  461. if (isset($category['attribs']['']['scheme']))
  462. {
  463. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_HTML);
  464. }
  465. if (isset($category['attribs']['']['label']))
  466. {
  467. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_HTML);
  468. }
  469. $categories[] = $this->registry->create('Category', array($term, $scheme, $label, $type));
  470. }
  471. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, $type) as $category)
  472. {
  473. // This is really the label, but keep this as the term also for BC.
  474. // Label will also work on retrieving because that falls back to term.
  475. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML);
  476. if (isset($category['attribs']['']['domain']))
  477. {
  478. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_HTML);
  479. }
  480. else
  481. {
  482. $scheme = null;
  483. }
  484. $categories[] = $this->registry->create('Category', array($term, $scheme, null, $type));
  485. }
  486. $type = 'subject';
  487. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, $type) as $category)
  488. {
  489. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type));
  490. }
  491. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, $type) as $category)
  492. {
  493. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type));
  494. }
  495. if (!empty($categories))
  496. {
  497. return array_unique($categories);
  498. }
  499. else
  500. {
  501. return null;
  502. }
  503. }
  504. /**
  505. * Get an author for the item
  506. *
  507. * @since Beta 2
  508. * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
  509. * @return SimplePie_Author|null
  510. */
  511. public function get_author($key = 0)
  512. {
  513. $authors = $this->get_authors();
  514. if (isset($authors[$key]))
  515. {
  516. return $authors[$key];
  517. }
  518. else
  519. {
  520. return null;
  521. }
  522. }
  523. /**
  524. * Get a contributor for the item
  525. *
  526. * @since 1.1
  527. * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
  528. * @return SimplePie_Author|null
  529. */
  530. public function get_contributor($key = 0)
  531. {
  532. $contributors = $this->get_contributors();
  533. if (isset($contributors[$key]))
  534. {
  535. return $contributors[$key];
  536. }
  537. else
  538. {
  539. return null;
  540. }
  541. }
  542. /**
  543. * Get all contributors for the item
  544. *
  545. * Uses `<atom:contributor>`
  546. *
  547. * @since 1.1
  548. * @return array|null List of {@see SimplePie_Author} objects
  549. */
  550. public function get_contributors()
  551. {
  552. $contributors = array();
  553. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  554. {
  555. $name = null;
  556. $uri = null;
  557. $email = null;
  558. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  559. {
  560. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  561. }
  562. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  563. {
  564. $uri = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  565. }
  566. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  567. {
  568. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  569. }
  570. if ($name !== null || $email !== null || $uri !== null)
  571. {
  572. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  573. }
  574. }
  575. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  576. {
  577. $name = null;
  578. $url = null;
  579. $email = null;
  580. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  581. {
  582. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  583. }
  584. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  585. {
  586. $url = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  587. }
  588. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  589. {
  590. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  591. }
  592. if ($name !== null || $email !== null || $url !== null)
  593. {
  594. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  595. }
  596. }
  597. if (!empty($contributors))
  598. {
  599. return array_unique($contributors);
  600. }
  601. else
  602. {
  603. return null;
  604. }
  605. }
  606. /**
  607. * Get all authors for the item
  608. *
  609. * Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
  610. *
  611. * @since Beta 2
  612. * @return array|null List of {@see SimplePie_Author} objects
  613. */
  614. public function get_authors()
  615. {
  616. $authors = array();
  617. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  618. {
  619. $name = null;
  620. $uri = null;
  621. $email = null;
  622. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  623. {
  624. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  625. }
  626. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  627. {
  628. $uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
  629. }
  630. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  631. {
  632. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  633. }
  634. if ($name !== null || $email !== null || $uri !== null)
  635. {
  636. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  637. }
  638. }
  639. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  640. {
  641. $name = null;
  642. $url = null;
  643. $email = null;
  644. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  645. {
  646. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  647. }
  648. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  649. {
  650. $url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
  651. }
  652. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  653. {
  654. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  655. }
  656. if ($name !== null || $email !== null || $url !== null)
  657. {
  658. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  659. }
  660. }
  661. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  662. {
  663. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_HTML)));
  664. }
  665. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  666. {
  667. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  668. }
  669. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  670. {
  671. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  672. }
  673. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  674. {
  675. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null));
  676. }
  677. if (!empty($authors))
  678. {
  679. return array_unique($authors);
  680. }
  681. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  682. {
  683. return $authors;
  684. }
  685. elseif ($authors = $this->feed->get_authors())
  686. {
  687. return $authors;
  688. }
  689. else
  690. {
  691. return null;
  692. }
  693. }
  694. /**
  695. * Get the copyright info for the item
  696. *
  697. * Uses `<atom:rights>` or `<dc:rights>`
  698. *
  699. * @since 1.1
  700. * @return string
  701. */
  702. public function get_copyright()
  703. {
  704. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  705. {
  706. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  707. }
  708. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  709. {
  710. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  711. }
  712. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  713. {
  714. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  715. }
  716. else
  717. {
  718. return null;
  719. }
  720. }
  721. /**
  722. * Get the posting date/time for the item
  723. *
  724. * Uses `<atom:published>`, `<atom:updated>`, `<atom:issued>`,
  725. * `<atom:modified>`, `<pubDate>` or `<dc:date>`
  726. *
  727. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  728. * {@see get_gmdate}
  729. *
  730. * @since Beta 2 (previously called `get_item_date` since 0.8)
  731. *
  732. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  733. * @return int|string|null
  734. */
  735. public function get_date($date_format = 'j F Y, g:i a')
  736. {
  737. if (!isset($this->data['date']))
  738. {
  739. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  740. {
  741. $this->data['date']['raw'] = $return[0]['data'];
  742. }
  743. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  744. {
  745. $this->data['date']['raw'] = $return[0]['data'];
  746. }
  747. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  748. {
  749. $this->data['date']['raw'] = $return[0]['data'];
  750. }
  751. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  752. {
  753. $this->data['date']['raw'] = $return[0]['data'];
  754. }
  755. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  756. {
  757. $this->data['date']['raw'] = $return[0]['data'];
  758. }
  759. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  760. {
  761. $this->data['date']['raw'] = $return[0]['data'];
  762. }
  763. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  764. {
  765. $this->data['date']['raw'] = $return[0]['data'];
  766. }
  767. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  768. {
  769. $this->data['date']['raw'] = $return[0]['data'];
  770. }
  771. if (!empty($this->data['date']['raw']))
  772. {
  773. $parser = $this->registry->call('Parse_Date', 'get');
  774. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  775. }
  776. else
  777. {
  778. $this->data['date'] = null;
  779. }
  780. }
  781. if ($this->data['date'])
  782. {
  783. $date_format = (string) $date_format;
  784. switch ($date_format)
  785. {
  786. case '':
  787. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  788. case 'U':
  789. return $this->data['date']['parsed'];
  790. default:
  791. return date($date_format, $this->data['date']['parsed']);
  792. }
  793. }
  794. else
  795. {
  796. return null;
  797. }
  798. }
  799. /**
  800. * Get the update date/time for the item
  801. *
  802. * Uses `<atom:updated>`
  803. *
  804. * Note: obeys PHP's timezone setting. To get a UTC date/time, use
  805. * {@see get_gmdate}
  806. *
  807. * @param string $date_format Supports any PHP date format from {@see http://php.net/date} (empty for the raw data)
  808. * @return int|string|null
  809. */
  810. public function get_updated_date($date_format = 'j F Y, g:i a')
  811. {
  812. if (!isset($this->data['updated']))
  813. {
  814. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  815. {
  816. $this->data['updated']['raw'] = $return[0]['data'];
  817. }
  818. if (!empty($this->data['updated']['raw']))
  819. {
  820. $parser = $this->registry->call('Parse_Date', 'get');
  821. $this->data['updated']['parsed'] = $parser->parse($this->data['updated']['raw']);
  822. }
  823. else
  824. {
  825. $this->data['updated'] = null;
  826. }
  827. }
  828. if ($this->data['updated'])
  829. {
  830. $date_format = (string) $date_format;
  831. switch ($date_format)
  832. {
  833. case '':
  834. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  835. case 'U':
  836. return $this->data['updated']['parsed'];
  837. default:
  838. return date($date_format, $this->data['updated']['parsed']);
  839. }
  840. }
  841. else
  842. {
  843. return null;
  844. }
  845. }
  846. /**
  847. * Get the localized posting date/time for the item
  848. *
  849. * Returns the date formatted in the localized language. To display in
  850. * languages other than the server's default, you need to change the locale
  851. * with {@link http://php.net/setlocale setlocale()}. The available
  852. * localizations depend on which ones are installed on your web server.
  853. *
  854. * @since 1.0
  855. *
  856. * @param string $date_format Supports any PHP date format from {@see http://php.net/strftime} (empty for the raw data)
  857. * @return int|string|null
  858. */
  859. public function get_local_date($date_format = '%c')
  860. {
  861. if (!$date_format)
  862. {
  863. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  864. }
  865. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  866. {
  867. return strftime($date_format, $date);
  868. }
  869. else
  870. {
  871. return null;
  872. }
  873. }
  874. /**
  875. * Get the posting date/time for the item (UTC time)
  876. *
  877. * @see get_date
  878. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  879. * @return int|string|null
  880. */
  881. public function get_gmdate($date_format = 'j F Y, g:i a')
  882. {
  883. $date = $this->get_date('U');
  884. if ($date === null)
  885. {
  886. return null;
  887. }
  888. return gmdate($date_format, $date);
  889. }
  890. /**
  891. * Get the update date/time for the item (UTC time)
  892. *
  893. * @see get_updated_date
  894. * @param string $date_format Supports any PHP date format from {@see http://php.net/date}
  895. * @return int|string|null
  896. */
  897. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  898. {
  899. $date = $this->get_updated_date('U');
  900. if ($date === null)
  901. {
  902. return null;
  903. }
  904. return gmdate($date_format, $date);
  905. }
  906. /**
  907. * Get the permalink for the item
  908. *
  909. * Returns the first link available with a relationship of "alternate".
  910. * Identical to {@see get_link()} with key 0
  911. *
  912. * @see get_link
  913. * @since 0.8
  914. * @return string|null Permalink URL
  915. */
  916. public function get_permalink()
  917. {
  918. $link = $this->get_link();
  919. $enclosure = $this->get_enclosure(0);
  920. if ($link !== null)
  921. {
  922. return $link;
  923. }
  924. elseif ($enclosure !== null)
  925. {
  926. return $enclosure->get_link();
  927. }
  928. else
  929. {
  930. return null;
  931. }
  932. }
  933. /**
  934. * Get a single link for the item
  935. *
  936. * @since Beta 3
  937. * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
  938. * @param string $rel The relationship of the link to return
  939. * @return string|null Link URL
  940. */
  941. public function get_link($key = 0, $rel = 'alternate')
  942. {
  943. $links = $this->get_links($rel);
  944. if ($links[$key] !== null)
  945. {
  946. return $links[$key];
  947. }
  948. else
  949. {
  950. return null;
  951. }
  952. }
  953. /**
  954. * Get all links for the item
  955. *
  956. * Uses `<atom:link>`, `<link>` or `<guid>`
  957. *
  958. * @since Beta 2
  959. * @param string $rel The relationship of links to return
  960. * @return array|null Links found for the item (strings)
  961. */
  962. public function get_links($rel = 'alternate')
  963. {
  964. if (!isset($this->data['links']))
  965. {
  966. $this->data['links'] = array();
  967. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  968. {
  969. if (isset($link['attribs']['']['href']))
  970. {
  971. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  972. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  973. }
  974. }
  975. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  976. {
  977. if (isset($link['attribs']['']['href']))
  978. {
  979. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  980. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  981. }
  982. }
  983. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  984. {
  985. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  986. }
  987. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  988. {
  989. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  990. }
  991. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  992. {
  993. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  994. }
  995. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  996. {
  997. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  998. {
  999. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  1000. }
  1001. }
  1002. $keys = array_keys($this->data['links']);
  1003. foreach ($keys as $key)
  1004. {
  1005. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  1006. {
  1007. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  1008. {
  1009. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  1010. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  1011. }
  1012. else
  1013. {
  1014. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  1015. }
  1016. }
  1017. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  1018. {
  1019. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  1020. }
  1021. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  1022. }
  1023. }
  1024. if (isset($this->data['links'][$rel]))
  1025. {
  1026. return $this->data['links'][$rel];
  1027. }
  1028. else
  1029. {
  1030. return null;
  1031. }
  1032. }
  1033. /**
  1034. * Get an enclosure from the item
  1035. *
  1036. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  1037. *
  1038. * @since Beta 2
  1039. * @todo Add ability to prefer one type of content over another (in a media group).
  1040. * @param int $key The enclosure that you want to return. Remember that arrays begin with 0, not 1
  1041. * @return SimplePie_Enclosure|null
  1042. */
  1043. public function get_enclosure($key = 0, $prefer = null)
  1044. {
  1045. $enclosures = $this->get_enclosures();
  1046. if (isset($enclosures[$key]))
  1047. {
  1048. return $enclosures[$key];
  1049. }
  1050. else
  1051. {
  1052. return null;
  1053. }
  1054. }
  1055. /**
  1056. * Get all available enclosures (podcasts, etc.)
  1057. *
  1058. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  1059. *
  1060. * At this point, we're pretty much assuming that all enclosures for an item
  1061. * are the same content. Anything else is too complicated to
  1062. * properly support.
  1063. *
  1064. * @since Beta 2
  1065. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  1066. * @todo If an element exists at a level, but its value is empty, we should fall back to the value from the parent (if it exists).
  1067. * @return SimplePie_Enclosure[]|null List of SimplePie_Enclosure items
  1068. */
  1069. public function get_enclosures()
  1070. {
  1071. if (!isset($this->data['enclosures']))
  1072. {
  1073. $this->data['enclosures'] = array();
  1074. // Elements
  1075. $captions_parent = null;
  1076. $categories_parent = null;
  1077. $copyrights_parent = null;
  1078. $credits_parent = null;
  1079. $description_parent = null;
  1080. $duration_parent = null;
  1081. $hashes_parent = null;
  1082. $keywords_parent = null;
  1083. $player_parent = null;
  1084. $ratings_parent = null;
  1085. $restrictions_parent = null;
  1086. $thumbnails_parent = null;
  1087. $title_parent = null;
  1088. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  1089. $parent = $this->get_feed();
  1090. // CAPTIONS
  1091. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1092. {
  1093. foreach ($captions as $caption)
  1094. {
  1095. $caption_type = null;
  1096. $caption_lang = null;
  1097. $caption_startTime = null;
  1098. $caption_endTime = null;
  1099. $caption_text = null;
  1100. if (isset($caption['attribs']['']['type']))
  1101. {
  1102. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1103. }
  1104. if (isset($caption['attribs']['']['lang']))
  1105. {
  1106. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1107. }
  1108. if (isset($caption['attribs']['']['start']))
  1109. {
  1110. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1111. }
  1112. if (isset($caption['attribs']['']['end']))
  1113. {
  1114. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1115. }
  1116. if (isset($caption['data']))
  1117. {
  1118. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1119. }
  1120. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1121. }
  1122. }
  1123. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  1124. {
  1125. foreach ($captions as $caption)
  1126. {
  1127. $caption_type = null;
  1128. $caption_lang = null;
  1129. $caption_startTime = null;
  1130. $caption_endTime = null;
  1131. $caption_text = null;
  1132. if (isset($caption['attribs']['']['type']))
  1133. {
  1134. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1135. }
  1136. if (isset($caption['attribs']['']['lang']))
  1137. {
  1138. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1139. }
  1140. if (isset($caption['attribs']['']['start']))
  1141. {
  1142. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  1143. }
  1144. if (isset($caption['attribs']['']['end']))
  1145. {
  1146. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  1147. }
  1148. if (isset($caption['data']))
  1149. {
  1150. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1151. }
  1152. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  1153. }
  1154. }
  1155. if (is_array($captions_parent))
  1156. {
  1157. $captions_parent = array_values(array_unique($captions_parent));
  1158. }
  1159. // CATEGORIES
  1160. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1161. {
  1162. $term = null;
  1163. $scheme = null;
  1164. $label = null;
  1165. if (isset($category['data']))
  1166. {
  1167. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1168. }
  1169. if (isset($category['attribs']['']['scheme']))
  1170. {
  1171. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1172. }
  1173. else
  1174. {
  1175. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1176. }
  1177. if (isset($category['attribs']['']['label']))
  1178. {
  1179. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1180. }
  1181. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1182. }
  1183. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  1184. {
  1185. $term = null;
  1186. $scheme = null;
  1187. $label = null;
  1188. if (isset($category['data']))
  1189. {
  1190. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1191. }
  1192. if (isset($category['attribs']['']['scheme']))
  1193. {
  1194. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1195. }
  1196. else
  1197. {
  1198. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  1199. }
  1200. if (isset($category['attribs']['']['label']))
  1201. {
  1202. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  1203. }
  1204. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1205. }
  1206. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  1207. {
  1208. $term = null;
  1209. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  1210. $label = null;
  1211. if (isset($category['attribs']['']['text']))
  1212. {
  1213. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1214. }
  1215. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1216. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  1217. {
  1218. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  1219. {
  1220. if (isset($subcategory['attribs']['']['text']))
  1221. {
  1222. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  1223. }
  1224. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  1225. }
  1226. }
  1227. }
  1228. if (is_array($categories_parent))
  1229. {
  1230. $categories_parent = array_values(array_unique($categories_parent));
  1231. }
  1232. // COPYRIGHT
  1233. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1234. {
  1235. $copyright_url = null;
  1236. $copyright_label = null;
  1237. if (isset($copyright[0]['attribs']['']['url']))
  1238. {
  1239. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1240. }
  1241. if (isset($copyright[0]['data']))
  1242. {
  1243. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1244. }
  1245. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1246. }
  1247. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  1248. {
  1249. $copyright_url = null;
  1250. $copyright_label = null;
  1251. if (isset($copyright[0]['attribs']['']['url']))
  1252. {
  1253. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  1254. }
  1255. if (isset($copyright[0]['data']))
  1256. {
  1257. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1258. }
  1259. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  1260. }
  1261. // CREDITS
  1262. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1263. {
  1264. foreach ($credits as $credit)
  1265. {
  1266. $credit_role = null;
  1267. $credit_scheme = null;
  1268. $credit_name = null;
  1269. if (isset($credit['attribs']['']['role']))
  1270. {
  1271. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1272. }
  1273. if (isset($credit['attribs']['']['scheme']))
  1274. {
  1275. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1276. }
  1277. else
  1278. {
  1279. $credit_scheme = 'urn:ebu';
  1280. }
  1281. if (isset($credit['data']))
  1282. {
  1283. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1284. }
  1285. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1286. }
  1287. }
  1288. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  1289. {
  1290. foreach ($credits as $credit)
  1291. {
  1292. $credit_role = null;
  1293. $credit_scheme = null;
  1294. $credit_name = null;
  1295. if (isset($credit['attribs']['']['role']))
  1296. {
  1297. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  1298. }
  1299. if (isset($credit['attribs']['']['scheme']))
  1300. {
  1301. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1302. }
  1303. else
  1304. {
  1305. $credit_scheme = 'urn:ebu';
  1306. }
  1307. if (isset($credit['data']))
  1308. {
  1309. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1310. }
  1311. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1312. }
  1313. }
  1314. if (is_array($credits_parent))
  1315. {
  1316. $credits_parent = array_values(array_unique($credits_parent));
  1317. }
  1318. // DESCRIPTION
  1319. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1320. {
  1321. if (isset($description_parent[0]['data']))
  1322. {
  1323. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1324. }
  1325. }
  1326. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1327. {
  1328. if (isset($description_parent[0]['data']))
  1329. {
  1330. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1331. }
  1332. }
  1333. // DURATION
  1334. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  1335. {
  1336. $seconds = null;
  1337. $minutes = null;
  1338. $hours = null;
  1339. if (isset($duration_parent[0]['data']))
  1340. {
  1341. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1342. if (sizeof($temp) > 0)
  1343. {
  1344. $seconds = (int) array_pop($temp);
  1345. }
  1346. if (sizeof($temp) > 0)
  1347. {
  1348. $minutes = (int) array_pop($temp);
  1349. $seconds += $minutes * 60;
  1350. }
  1351. if (sizeof($temp) > 0)
  1352. {
  1353. $hours = (int) array_pop($temp);
  1354. $seconds += $hours * 3600;
  1355. }
  1356. unset($temp);
  1357. $duration_parent = $seconds;
  1358. }
  1359. }
  1360. // HASHES
  1361. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1362. {
  1363. foreach ($hashes_iterator as $hash)
  1364. {
  1365. $value = null;
  1366. $algo = null;
  1367. if (isset($hash['data']))
  1368. {
  1369. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1370. }
  1371. if (isset($hash['attribs']['']['algo']))
  1372. {
  1373. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1374. }
  1375. else
  1376. {
  1377. $algo = 'md5';
  1378. }
  1379. $hashes_parent[] = $algo.':'.$value;
  1380. }
  1381. }
  1382. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1383. {
  1384. foreach ($hashes_iterator as $hash)
  1385. {
  1386. $value = null;
  1387. $algo = null;
  1388. if (isset($hash['data']))
  1389. {
  1390. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1391. }
  1392. if (isset($hash['attribs']['']['algo']))
  1393. {
  1394. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1395. }
  1396. else
  1397. {
  1398. $algo = 'md5';
  1399. }
  1400. $hashes_parent[] = $algo.':'.$value;
  1401. }
  1402. }
  1403. if (is_array($hashes_parent))
  1404. {
  1405. $hashes_parent = array_values(array_unique($hashes_parent));
  1406. }
  1407. // KEYWORDS
  1408. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1409. {
  1410. if (isset($keywords[0]['data']))
  1411. {
  1412. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1413. foreach ($temp as $word)
  1414. {
  1415. $keywords_parent[] = trim($word);
  1416. }
  1417. }
  1418. unset($temp);
  1419. }
  1420. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1421. {
  1422. if (isset($keywords[0]['data']))
  1423. {
  1424. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1425. foreach ($temp as $word)
  1426. {
  1427. $keywords_parent[] = trim($word);
  1428. }
  1429. }
  1430. unset($temp);
  1431. }
  1432. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1433. {
  1434. if (isset($keywords[0]['data']))
  1435. {
  1436. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1437. foreach ($temp as $word)
  1438. {
  1439. $keywords_parent[] = trim($word);
  1440. }
  1441. }
  1442. unset($temp);
  1443. }
  1444. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1445. {
  1446. if (isset($keywords[0]['data']))
  1447. {
  1448. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1449. foreach ($temp as $word)
  1450. {
  1451. $keywords_parent[] = trim($word);
  1452. }
  1453. }
  1454. unset($temp);
  1455. }
  1456. if (is_array($keywords_parent))
  1457. {
  1458. $keywords_parent = array_values(array_unique($keywords_parent));
  1459. }
  1460. // PLAYER
  1461. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1462. {
  1463. if (isset($player_parent[0]['attribs']['']['url']))
  1464. {
  1465. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1466. }
  1467. }
  1468. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1469. {
  1470. if (isset($player_parent[0]['attribs']['']['url']))
  1471. {
  1472. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1473. }
  1474. }
  1475. // RATINGS
  1476. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1477. {
  1478. foreach ($ratings as $rating)
  1479. {
  1480. $rating_scheme = null;
  1481. $rating_value = null;
  1482. if (isset($rating['attribs']['']['scheme']))
  1483. {
  1484. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1485. }
  1486. else
  1487. {
  1488. $rating_scheme = 'urn:simple';
  1489. }
  1490. if (isset($rating['data']))
  1491. {
  1492. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1493. }
  1494. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1495. }
  1496. }
  1497. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1498. {
  1499. foreach ($ratings as $rating)
  1500. {
  1501. $rating_scheme = 'urn:itunes';
  1502. $rating_value = null;
  1503. if (isset($rating['data']))
  1504. {
  1505. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1506. }
  1507. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1508. }
  1509. }
  1510. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1511. {
  1512. foreach ($ratings as $rating)
  1513. {
  1514. $rating_scheme = null;
  1515. $rating_value = null;
  1516. if (isset($rating['attribs']['']['scheme']))
  1517. {
  1518. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1519. }
  1520. else
  1521. {
  1522. $rating_scheme = 'urn:simple';
  1523. }
  1524. if (isset($rating['data']))
  1525. {
  1526. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1527. }
  1528. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1529. }
  1530. }
  1531. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1532. {
  1533. foreach ($ratings as $rating)
  1534. {
  1535. $rating_scheme = 'urn:itunes';
  1536. $rating_value = null;
  1537. if (isset($rating['data']))
  1538. {
  1539. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1540. }
  1541. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1542. }
  1543. }
  1544. if (is_array($ratings_parent))
  1545. {
  1546. $ratings_parent = array_values(array_unique($ratings_parent));
  1547. }
  1548. // RESTRICTIONS
  1549. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1550. {
  1551. foreach ($restrictions as $restriction)
  1552. {
  1553. $restriction_relationship = null;
  1554. $restriction_type = null;
  1555. $restriction_value = null;
  1556. if (isset($restric

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