PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/SimplePie/Item.php

http://github.com/simplepie/simplepie
PHP | 1957 lines | 1777 code | 78 blank | 102 comment | 236 complexity | bff1d8ef4e656d020a24bb21a76f2e9e MD5 | raw file
Possible License(s): 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-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-dev
  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. */
  53. class SimplePie_Item
  54. {
  55. var $feed;
  56. var $data = array();
  57. protected $registry;
  58. public function __construct($feed, $data)
  59. {
  60. $this->feed = $feed;
  61. $this->data = $data;
  62. }
  63. public function set_registry(SimplePie_Registry &$registry)
  64. {
  65. $this->registry = &$registry;
  66. }
  67. public function __toString()
  68. {
  69. return md5(serialize($this->data));
  70. }
  71. /**
  72. * Remove items that link back to this before destroying this object
  73. */
  74. public function __destruct()
  75. {
  76. if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
  77. {
  78. unset($this->feed);
  79. }
  80. }
  81. public function get_item_tags($namespace, $tag)
  82. {
  83. if (isset($this->data['child'][$namespace][$tag]))
  84. {
  85. return $this->data['child'][$namespace][$tag];
  86. }
  87. else
  88. {
  89. return null;
  90. }
  91. }
  92. public function get_base($element = array())
  93. {
  94. return $this->feed->get_base($element);
  95. }
  96. public function sanitize($data, $type, $base = '')
  97. {
  98. return $this->feed->sanitize($data, $type, $base);
  99. }
  100. public function get_feed()
  101. {
  102. return $this->feed;
  103. }
  104. public function get_id($hash = false)
  105. {
  106. if (!$hash)
  107. {
  108. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'id'))
  109. {
  110. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  111. }
  112. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'id'))
  113. {
  114. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  115. }
  116. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  117. {
  118. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  119. }
  120. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'identifier'))
  121. {
  122. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  123. }
  124. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'identifier'))
  125. {
  126. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  127. }
  128. elseif (isset($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about']))
  129. {
  130. return $this->sanitize($this->data['attribs'][SIMPLEPIE_NAMESPACE_RDF]['about'], SIMPLEPIE_CONSTRUCT_TEXT);
  131. }
  132. elseif (($return = $this->get_permalink()) !== null)
  133. {
  134. return $return;
  135. }
  136. elseif (($return = $this->get_title()) !== null)
  137. {
  138. return $return;
  139. }
  140. }
  141. if ($this->get_permalink() !== null || $this->get_title() !== null)
  142. {
  143. return md5($this->get_permalink() . $this->get_title());
  144. }
  145. else
  146. {
  147. return md5(serialize($this->data));
  148. }
  149. }
  150. public function get_title()
  151. {
  152. if (!isset($this->data['title']))
  153. {
  154. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  155. {
  156. $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]));
  157. }
  158. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  159. {
  160. $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]));
  161. }
  162. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  163. {
  164. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  165. }
  166. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  167. {
  168. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  169. }
  170. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  171. {
  172. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  173. }
  174. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  175. {
  176. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  177. }
  178. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  179. {
  180. $this->data['title'] = $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  181. }
  182. else
  183. {
  184. $this->data['title'] = null;
  185. }
  186. }
  187. return $this->data['title'];
  188. }
  189. public function get_description($description_only = false)
  190. {
  191. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'summary'))
  192. {
  193. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  194. }
  195. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'summary'))
  196. {
  197. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  198. }
  199. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  200. {
  201. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  202. }
  203. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  204. {
  205. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  206. }
  207. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  208. {
  209. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  210. }
  211. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  212. {
  213. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  214. }
  215. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  216. {
  217. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  218. }
  219. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  220. {
  221. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  222. }
  223. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  224. {
  225. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML);
  226. }
  227. elseif (!$description_only)
  228. {
  229. return $this->get_content(true);
  230. }
  231. else
  232. {
  233. return null;
  234. }
  235. }
  236. public function get_content($content_only = false)
  237. {
  238. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'content'))
  239. {
  240. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_content_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  241. }
  242. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'content'))
  243. {
  244. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  245. }
  246. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10_MODULES_CONTENT, 'encoded'))
  247. {
  248. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  249. }
  250. elseif (!$content_only)
  251. {
  252. return $this->get_description(true);
  253. }
  254. else
  255. {
  256. return null;
  257. }
  258. }
  259. public function get_category($key = 0)
  260. {
  261. $categories = $this->get_categories();
  262. if (isset($categories[$key]))
  263. {
  264. return $categories[$key];
  265. }
  266. else
  267. {
  268. return null;
  269. }
  270. }
  271. public function get_categories()
  272. {
  273. $categories = array();
  274. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  275. {
  276. $term = null;
  277. $scheme = null;
  278. $label = null;
  279. if (isset($category['attribs']['']['term']))
  280. {
  281. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  282. }
  283. if (isset($category['attribs']['']['scheme']))
  284. {
  285. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  286. }
  287. if (isset($category['attribs']['']['label']))
  288. {
  289. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  290. }
  291. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  292. }
  293. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  294. {
  295. // This is really the label, but keep this as the term also for BC.
  296. // Label will also work on retrieving because that falls back to term.
  297. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  298. if (isset($category['attribs']['']['domain']))
  299. {
  300. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  301. }
  302. else
  303. {
  304. $scheme = null;
  305. }
  306. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  307. }
  308. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  309. {
  310. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  311. }
  312. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  313. {
  314. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  315. }
  316. if (!empty($categories))
  317. {
  318. return $this->registry->call('Misc', 'array_unique', array($categories));
  319. }
  320. else
  321. {
  322. return null;
  323. }
  324. }
  325. public function get_author($key = 0)
  326. {
  327. $authors = $this->get_authors();
  328. if (isset($authors[$key]))
  329. {
  330. return $authors[$key];
  331. }
  332. else
  333. {
  334. return null;
  335. }
  336. }
  337. public function get_contributor($key = 0)
  338. {
  339. $contributors = $this->get_contributors();
  340. if (isset($contributors[$key]))
  341. {
  342. return $contributors[$key];
  343. }
  344. else
  345. {
  346. return null;
  347. }
  348. }
  349. public function get_contributors()
  350. {
  351. $contributors = array();
  352. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  353. {
  354. $name = null;
  355. $uri = null;
  356. $email = null;
  357. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  358. {
  359. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  360. }
  361. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  362. {
  363. $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]));
  364. }
  365. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  366. {
  367. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  368. }
  369. if ($name !== null || $email !== null || $uri !== null)
  370. {
  371. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  372. }
  373. }
  374. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  375. {
  376. $name = null;
  377. $url = null;
  378. $email = null;
  379. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  380. {
  381. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  382. }
  383. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  384. {
  385. $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]));
  386. }
  387. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  388. {
  389. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  390. }
  391. if ($name !== null || $email !== null || $url !== null)
  392. {
  393. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  394. }
  395. }
  396. if (!empty($contributors))
  397. {
  398. return $this->registry->call('Misc', 'array_unique', array($contributors));
  399. }
  400. else
  401. {
  402. return null;
  403. }
  404. }
  405. public function get_authors()
  406. {
  407. $authors = array();
  408. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  409. {
  410. $name = null;
  411. $uri = null;
  412. $email = null;
  413. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  414. {
  415. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  416. }
  417. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  418. {
  419. $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]));
  420. }
  421. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  422. {
  423. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  424. }
  425. if ($name !== null || $email !== null || $uri !== null)
  426. {
  427. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  428. }
  429. }
  430. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  431. {
  432. $name = null;
  433. $url = null;
  434. $email = null;
  435. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  436. {
  437. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  438. }
  439. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  440. {
  441. $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]));
  442. }
  443. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  444. {
  445. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  446. }
  447. if ($name !== null || $email !== null || $url !== null)
  448. {
  449. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  450. }
  451. }
  452. if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author'))
  453. {
  454. $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT)));
  455. }
  456. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  457. {
  458. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  459. }
  460. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  461. {
  462. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  463. }
  464. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  465. {
  466. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  467. }
  468. if (!empty($authors))
  469. {
  470. return $this->registry->call('Misc', 'array_unique', array($authors));
  471. }
  472. elseif (($source = $this->get_source()) && ($authors = $source->get_authors()))
  473. {
  474. return $authors;
  475. }
  476. elseif ($authors = $this->feed->get_authors())
  477. {
  478. return $authors;
  479. }
  480. else
  481. {
  482. return null;
  483. }
  484. }
  485. public function get_copyright()
  486. {
  487. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  488. {
  489. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  490. }
  491. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  492. {
  493. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  494. }
  495. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  496. {
  497. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  498. }
  499. else
  500. {
  501. return null;
  502. }
  503. }
  504. public function get_date($date_format = 'j F Y, g:i a')
  505. {
  506. if (!isset($this->data['date']))
  507. {
  508. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'published'))
  509. {
  510. $this->data['date']['raw'] = $return[0]['data'];
  511. }
  512. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  513. {
  514. $this->data['date']['raw'] = $return[0]['data'];
  515. }
  516. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'issued'))
  517. {
  518. $this->data['date']['raw'] = $return[0]['data'];
  519. }
  520. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'created'))
  521. {
  522. $this->data['date']['raw'] = $return[0]['data'];
  523. }
  524. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'modified'))
  525. {
  526. $this->data['date']['raw'] = $return[0]['data'];
  527. }
  528. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'pubDate'))
  529. {
  530. $this->data['date']['raw'] = $return[0]['data'];
  531. }
  532. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'date'))
  533. {
  534. $this->data['date']['raw'] = $return[0]['data'];
  535. }
  536. elseif ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'date'))
  537. {
  538. $this->data['date']['raw'] = $return[0]['data'];
  539. }
  540. if (!empty($this->data['date']['raw']))
  541. {
  542. $parser = $this->registry->call('Parse_Date', 'get');
  543. $this->data['date']['parsed'] = $parser->parse($this->data['date']['raw']);
  544. }
  545. else
  546. {
  547. $this->data['date'] = null;
  548. }
  549. }
  550. if ($this->data['date'])
  551. {
  552. $date_format = (string) $date_format;
  553. switch ($date_format)
  554. {
  555. case '':
  556. return $this->sanitize($this->data['date']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  557. case 'U':
  558. return $this->data['date']['parsed'];
  559. default:
  560. return date($date_format, $this->data['date']['parsed']);
  561. }
  562. }
  563. else
  564. {
  565. return null;
  566. }
  567. }
  568. public function get_updated_date($date_format = 'j F Y, g:i a')
  569. {
  570. if (!isset($this->data['updated']))
  571. {
  572. if ($return = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'updated'))
  573. {
  574. $this->data['updated']['raw'] = $return[0]['data'];
  575. }
  576. if (!empty($this->data['updated']['raw']))
  577. {
  578. $parser = $this->registry->call('Parse_Date', 'get');
  579. $this->data['updated']['parsed'] = $parser->parse($this->data['date']['raw']);
  580. }
  581. else
  582. {
  583. $this->data['updated'] = null;
  584. }
  585. }
  586. if ($this->data['updated'])
  587. {
  588. $date_format = (string) $date_format;
  589. switch ($date_format)
  590. {
  591. case '':
  592. return $this->sanitize($this->data['updated']['raw'], SIMPLEPIE_CONSTRUCT_TEXT);
  593. case 'U':
  594. return $this->data['updated']['parsed'];
  595. default:
  596. return date($date_format, $this->data['updated']['parsed']);
  597. }
  598. }
  599. else
  600. {
  601. return null;
  602. }
  603. }
  604. public function get_local_date($date_format = '%c')
  605. {
  606. if (!$date_format)
  607. {
  608. return $this->sanitize($this->get_date(''), SIMPLEPIE_CONSTRUCT_TEXT);
  609. }
  610. elseif (($date = $this->get_date('U')) !== null && $date !== false)
  611. {
  612. return strftime($date_format, $date);
  613. }
  614. else
  615. {
  616. return null;
  617. }
  618. }
  619. public function get_gmdate($date_format = 'j F Y, g:i a')
  620. {
  621. $date = $this->get_date('U');
  622. if ($date === null)
  623. {
  624. return null;
  625. }
  626. return gmdate($date_format, $date);
  627. }
  628. public function get_updated_gmdate($date_format = 'j F Y, g:i a')
  629. {
  630. $date = $this->get_updated_date('U');
  631. if ($date === null)
  632. {
  633. return null;
  634. }
  635. return gmdate($date_format, $date);
  636. }
  637. public function get_permalink()
  638. {
  639. $link = $this->get_link();
  640. $enclosure = $this->get_enclosure(0);
  641. if ($link !== null)
  642. {
  643. return $link;
  644. }
  645. elseif ($enclosure !== null)
  646. {
  647. return $enclosure->get_link();
  648. }
  649. else
  650. {
  651. return null;
  652. }
  653. }
  654. public function get_link($key = 0, $rel = 'alternate')
  655. {
  656. $links = $this->get_links($rel);
  657. if ($links[$key] !== null)
  658. {
  659. return $links[$key];
  660. }
  661. else
  662. {
  663. return null;
  664. }
  665. }
  666. public function get_links($rel = 'alternate')
  667. {
  668. if (!isset($this->data['links']))
  669. {
  670. $this->data['links'] = array();
  671. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link') as $link)
  672. {
  673. if (isset($link['attribs']['']['href']))
  674. {
  675. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  676. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  677. }
  678. }
  679. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link') as $link)
  680. {
  681. if (isset($link['attribs']['']['href']))
  682. {
  683. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  684. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  685. }
  686. }
  687. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  688. {
  689. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  690. }
  691. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  692. {
  693. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  694. }
  695. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  696. {
  697. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  698. }
  699. if ($links = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'guid'))
  700. {
  701. if (!isset($links[0]['attribs']['']['isPermaLink']) || strtolower(trim($links[0]['attribs']['']['isPermaLink'])) === 'true')
  702. {
  703. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  704. }
  705. }
  706. $keys = array_keys($this->data['links']);
  707. foreach ($keys as $key)
  708. {
  709. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  710. {
  711. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  712. {
  713. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  714. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  715. }
  716. else
  717. {
  718. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  719. }
  720. }
  721. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  722. {
  723. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  724. }
  725. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  726. }
  727. }
  728. if (isset($this->data['links'][$rel]))
  729. {
  730. return $this->data['links'][$rel];
  731. }
  732. else
  733. {
  734. return null;
  735. }
  736. }
  737. /**
  738. * @todo Add ability to prefer one type of content over another (in a media group).
  739. */
  740. public function get_enclosure($key = 0, $prefer = null)
  741. {
  742. $enclosures = $this->get_enclosures();
  743. if (isset($enclosures[$key]))
  744. {
  745. return $enclosures[$key];
  746. }
  747. else
  748. {
  749. return null;
  750. }
  751. }
  752. /**
  753. * Grabs all available enclosures (podcasts, etc.)
  754. *
  755. * Supports the <enclosure> RSS tag, as well as Media RSS and iTunes RSS.
  756. *
  757. * At this point, we're pretty much assuming that all enclosures for an item are the same content. Anything else is too complicated to properly support.
  758. *
  759. * @todo Add support for end-user defined sorting of enclosures by type/handler (so we can prefer the faster-loading FLV over MP4).
  760. * @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).
  761. */
  762. public function get_enclosures()
  763. {
  764. if (!isset($this->data['enclosures']))
  765. {
  766. $this->data['enclosures'] = array();
  767. // Elements
  768. $captions_parent = null;
  769. $categories_parent = null;
  770. $copyrights_parent = null;
  771. $credits_parent = null;
  772. $description_parent = null;
  773. $duration_parent = null;
  774. $hashes_parent = null;
  775. $keywords_parent = null;
  776. $player_parent = null;
  777. $ratings_parent = null;
  778. $restrictions_parent = null;
  779. $thumbnails_parent = null;
  780. $title_parent = null;
  781. // Let's do the channel and item-level ones first, and just re-use them if we need to.
  782. $parent = $this->get_feed();
  783. // CAPTIONS
  784. if ($captions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  785. {
  786. foreach ($captions as $caption)
  787. {
  788. $caption_type = null;
  789. $caption_lang = null;
  790. $caption_startTime = null;
  791. $caption_endTime = null;
  792. $caption_text = null;
  793. if (isset($caption['attribs']['']['type']))
  794. {
  795. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  796. }
  797. if (isset($caption['attribs']['']['lang']))
  798. {
  799. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  800. }
  801. if (isset($caption['attribs']['']['start']))
  802. {
  803. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  804. }
  805. if (isset($caption['attribs']['']['end']))
  806. {
  807. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  808. }
  809. if (isset($caption['data']))
  810. {
  811. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  812. }
  813. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  814. }
  815. }
  816. elseif ($captions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'text'))
  817. {
  818. foreach ($captions as $caption)
  819. {
  820. $caption_type = null;
  821. $caption_lang = null;
  822. $caption_startTime = null;
  823. $caption_endTime = null;
  824. $caption_text = null;
  825. if (isset($caption['attribs']['']['type']))
  826. {
  827. $caption_type = $this->sanitize($caption['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  828. }
  829. if (isset($caption['attribs']['']['lang']))
  830. {
  831. $caption_lang = $this->sanitize($caption['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  832. }
  833. if (isset($caption['attribs']['']['start']))
  834. {
  835. $caption_startTime = $this->sanitize($caption['attribs']['']['start'], SIMPLEPIE_CONSTRUCT_TEXT);
  836. }
  837. if (isset($caption['attribs']['']['end']))
  838. {
  839. $caption_endTime = $this->sanitize($caption['attribs']['']['end'], SIMPLEPIE_CONSTRUCT_TEXT);
  840. }
  841. if (isset($caption['data']))
  842. {
  843. $caption_text = $this->sanitize($caption['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  844. }
  845. $captions_parent[] = $this->registry->create('Caption', array($caption_type, $caption_lang, $caption_startTime, $caption_endTime, $caption_text));
  846. }
  847. }
  848. if (is_array($captions_parent))
  849. {
  850. $captions_parent = array_values($this->registry->call('Misc', 'array_unique', array($captions_parent)));
  851. }
  852. // CATEGORIES
  853. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  854. {
  855. $term = null;
  856. $scheme = null;
  857. $label = null;
  858. if (isset($category['data']))
  859. {
  860. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  861. }
  862. if (isset($category['attribs']['']['scheme']))
  863. {
  864. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  865. }
  866. else
  867. {
  868. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  869. }
  870. if (isset($category['attribs']['']['label']))
  871. {
  872. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  873. }
  874. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  875. }
  876. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'category') as $category)
  877. {
  878. $term = null;
  879. $scheme = null;
  880. $label = null;
  881. if (isset($category['data']))
  882. {
  883. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  884. }
  885. if (isset($category['attribs']['']['scheme']))
  886. {
  887. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  888. }
  889. else
  890. {
  891. $scheme = 'http://search.yahoo.com/mrss/category_schema';
  892. }
  893. if (isset($category['attribs']['']['label']))
  894. {
  895. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  896. }
  897. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  898. }
  899. foreach ((array) $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'category') as $category)
  900. {
  901. $term = null;
  902. $scheme = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
  903. $label = null;
  904. if (isset($category['attribs']['']['text']))
  905. {
  906. $label = $this->sanitize($category['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  907. }
  908. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  909. if (isset($category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category']))
  910. {
  911. foreach ((array) $category['child'][SIMPLEPIE_NAMESPACE_ITUNES]['category'] as $subcategory)
  912. {
  913. if (isset($subcategory['attribs']['']['text']))
  914. {
  915. $label = $this->sanitize($subcategory['attribs']['']['text'], SIMPLEPIE_CONSTRUCT_TEXT);
  916. }
  917. $categories_parent[] = $this->registry->create('Category', array($term, $scheme, $label));
  918. }
  919. }
  920. }
  921. if (is_array($categories_parent))
  922. {
  923. $categories_parent = array_values($this->registry->call('Misc', 'array_unique', array($categories_parent)));
  924. }
  925. // COPYRIGHT
  926. if ($copyright = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  927. {
  928. $copyright_url = null;
  929. $copyright_label = null;
  930. if (isset($copyright[0]['attribs']['']['url']))
  931. {
  932. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  933. }
  934. if (isset($copyright[0]['data']))
  935. {
  936. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  937. }
  938. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  939. }
  940. elseif ($copyright = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'copyright'))
  941. {
  942. $copyright_url = null;
  943. $copyright_label = null;
  944. if (isset($copyright[0]['attribs']['']['url']))
  945. {
  946. $copyright_url = $this->sanitize($copyright[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_TEXT);
  947. }
  948. if (isset($copyright[0]['data']))
  949. {
  950. $copyright_label = $this->sanitize($copyright[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  951. }
  952. $copyrights_parent = $this->registry->create('Copyright', array($copyright_url, $copyright_label));
  953. }
  954. // CREDITS
  955. if ($credits = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  956. {
  957. foreach ($credits as $credit)
  958. {
  959. $credit_role = null;
  960. $credit_scheme = null;
  961. $credit_name = null;
  962. if (isset($credit['attribs']['']['role']))
  963. {
  964. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  965. }
  966. if (isset($credit['attribs']['']['scheme']))
  967. {
  968. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  969. }
  970. else
  971. {
  972. $credit_scheme = 'urn:ebu';
  973. }
  974. if (isset($credit['data']))
  975. {
  976. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  977. }
  978. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  979. }
  980. }
  981. elseif ($credits = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'credit'))
  982. {
  983. foreach ($credits as $credit)
  984. {
  985. $credit_role = null;
  986. $credit_scheme = null;
  987. $credit_name = null;
  988. if (isset($credit['attribs']['']['role']))
  989. {
  990. $credit_role = $this->sanitize($credit['attribs']['']['role'], SIMPLEPIE_CONSTRUCT_TEXT);
  991. }
  992. if (isset($credit['attribs']['']['scheme']))
  993. {
  994. $credit_scheme = $this->sanitize($credit['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  995. }
  996. else
  997. {
  998. $credit_scheme = 'urn:ebu';
  999. }
  1000. if (isset($credit['data']))
  1001. {
  1002. $credit_name = $this->sanitize($credit['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1003. }
  1004. $credits_parent[] = $this->registry->create('Credit', array($credit_role, $credit_scheme, $credit_name));
  1005. }
  1006. }
  1007. if (is_array($credits_parent))
  1008. {
  1009. $credits_parent = array_values($this->registry->call('Misc', 'array_unique', array($credits_parent)));
  1010. }
  1011. // DESCRIPTION
  1012. if ($description_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1013. {
  1014. if (isset($description_parent[0]['data']))
  1015. {
  1016. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1017. }
  1018. }
  1019. elseif ($description_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'description'))
  1020. {
  1021. if (isset($description_parent[0]['data']))
  1022. {
  1023. $description_parent = $this->sanitize($description_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1024. }
  1025. }
  1026. // DURATION
  1027. if ($duration_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'duration'))
  1028. {
  1029. $seconds = null;
  1030. $minutes = null;
  1031. $hours = null;
  1032. if (isset($duration_parent[0]['data']))
  1033. {
  1034. $temp = explode(':', $this->sanitize($duration_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1035. if (sizeof($temp) > 0)
  1036. {
  1037. $seconds = (int) array_pop($temp);
  1038. }
  1039. if (sizeof($temp) > 0)
  1040. {
  1041. $minutes = (int) array_pop($temp);
  1042. $seconds += $minutes * 60;
  1043. }
  1044. if (sizeof($temp) > 0)
  1045. {
  1046. $hours = (int) array_pop($temp);
  1047. $seconds += $hours * 3600;
  1048. }
  1049. unset($temp);
  1050. $duration_parent = $seconds;
  1051. }
  1052. }
  1053. // HASHES
  1054. if ($hashes_iterator = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1055. {
  1056. foreach ($hashes_iterator as $hash)
  1057. {
  1058. $value = null;
  1059. $algo = null;
  1060. if (isset($hash['data']))
  1061. {
  1062. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1063. }
  1064. if (isset($hash['attribs']['']['algo']))
  1065. {
  1066. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1067. }
  1068. else
  1069. {
  1070. $algo = 'md5';
  1071. }
  1072. $hashes_parent[] = $algo.':'.$value;
  1073. }
  1074. }
  1075. elseif ($hashes_iterator = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'hash'))
  1076. {
  1077. foreach ($hashes_iterator as $hash)
  1078. {
  1079. $value = null;
  1080. $algo = null;
  1081. if (isset($hash['data']))
  1082. {
  1083. $value = $this->sanitize($hash['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1084. }
  1085. if (isset($hash['attribs']['']['algo']))
  1086. {
  1087. $algo = $this->sanitize($hash['attribs']['']['algo'], SIMPLEPIE_CONSTRUCT_TEXT);
  1088. }
  1089. else
  1090. {
  1091. $algo = 'md5';
  1092. }
  1093. $hashes_parent[] = $algo.':'.$value;
  1094. }
  1095. }
  1096. if (is_array($hashes_parent))
  1097. {
  1098. $hashes_parent = array_values($this->registry->call('Misc', 'array_unique', array($hashes_parent)));
  1099. }
  1100. // KEYWORDS
  1101. if ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1102. {
  1103. if (isset($keywords[0]['data']))
  1104. {
  1105. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1106. foreach ($temp as $word)
  1107. {
  1108. $keywords_parent[] = trim($word);
  1109. }
  1110. }
  1111. unset($temp);
  1112. }
  1113. elseif ($keywords = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1114. {
  1115. if (isset($keywords[0]['data']))
  1116. {
  1117. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1118. foreach ($temp as $word)
  1119. {
  1120. $keywords_parent[] = trim($word);
  1121. }
  1122. }
  1123. unset($temp);
  1124. }
  1125. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'keywords'))
  1126. {
  1127. if (isset($keywords[0]['data']))
  1128. {
  1129. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1130. foreach ($temp as $word)
  1131. {
  1132. $keywords_parent[] = trim($word);
  1133. }
  1134. }
  1135. unset($temp);
  1136. }
  1137. elseif ($keywords = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'keywords'))
  1138. {
  1139. if (isset($keywords[0]['data']))
  1140. {
  1141. $temp = explode(',', $this->sanitize($keywords[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT));
  1142. foreach ($temp as $word)
  1143. {
  1144. $keywords_parent[] = trim($word);
  1145. }
  1146. }
  1147. unset($temp);
  1148. }
  1149. if (is_array($keywords_parent))
  1150. {
  1151. $keywords_parent = array_values($this->registry->call('Misc', 'array_unique', array($keywords_parent)));
  1152. }
  1153. // PLAYER
  1154. if ($player_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1155. {
  1156. if (isset($player_parent[0]['attribs']['']['url']))
  1157. {
  1158. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1159. }
  1160. }
  1161. elseif ($player_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'player'))
  1162. {
  1163. if (isset($player_parent[0]['attribs']['']['url']))
  1164. {
  1165. $player_parent = $this->sanitize($player_parent[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1166. }
  1167. }
  1168. // RATINGS
  1169. if ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1170. {
  1171. foreach ($ratings as $rating)
  1172. {
  1173. $rating_scheme = null;
  1174. $rating_value = null;
  1175. if (isset($rating['attribs']['']['scheme']))
  1176. {
  1177. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1178. }
  1179. else
  1180. {
  1181. $rating_scheme = 'urn:simple';
  1182. }
  1183. if (isset($rating['data']))
  1184. {
  1185. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1186. }
  1187. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1188. }
  1189. }
  1190. elseif ($ratings = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1191. {
  1192. foreach ($ratings as $rating)
  1193. {
  1194. $rating_scheme = 'urn:itunes';
  1195. $rating_value = null;
  1196. if (isset($rating['data']))
  1197. {
  1198. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1199. }
  1200. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1201. }
  1202. }
  1203. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'rating'))
  1204. {
  1205. foreach ($ratings as $rating)
  1206. {
  1207. $rating_scheme = null;
  1208. $rating_value = null;
  1209. if (isset($rating['attribs']['']['scheme']))
  1210. {
  1211. $rating_scheme = $this->sanitize($rating['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  1212. }
  1213. else
  1214. {
  1215. $rating_scheme = 'urn:simple';
  1216. }
  1217. if (isset($rating['data']))
  1218. {
  1219. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1220. }
  1221. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1222. }
  1223. }
  1224. elseif ($ratings = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'explicit'))
  1225. {
  1226. foreach ($ratings as $rating)
  1227. {
  1228. $rating_scheme = 'urn:itunes';
  1229. $rating_value = null;
  1230. if (isset($rating['data']))
  1231. {
  1232. $rating_value = $this->sanitize($rating['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1233. }
  1234. $ratings_parent[] = $this->registry->create('Rating', array($rating_scheme, $rating_value));
  1235. }
  1236. }
  1237. if (is_array($ratings_parent))
  1238. {
  1239. $ratings_parent = array_values($this->registry->call('Misc', 'array_unique', array($ratings_parent)));
  1240. }
  1241. // RESTRICTIONS
  1242. if ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1243. {
  1244. foreach ($restrictions as $restriction)
  1245. {
  1246. $restriction_relationship = null;
  1247. $restriction_type = null;
  1248. $restriction_value = null;
  1249. if (isset($restriction['attribs']['']['relationship']))
  1250. {
  1251. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1252. }
  1253. if (isset($restriction['attribs']['']['type']))
  1254. {
  1255. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1256. }
  1257. if (isset($restriction['data']))
  1258. {
  1259. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1260. }
  1261. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1262. }
  1263. }
  1264. elseif ($restrictions = $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1265. {
  1266. foreach ($restrictions as $restriction)
  1267. {
  1268. $restriction_relationship = 'allow';
  1269. $restriction_type = null;
  1270. $restriction_value = 'itunes';
  1271. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1272. {
  1273. $restriction_relationship = 'deny';
  1274. }
  1275. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1276. }
  1277. }
  1278. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'restriction'))
  1279. {
  1280. foreach ($restrictions as $restriction)
  1281. {
  1282. $restriction_relationship = null;
  1283. $restriction_type = null;
  1284. $restriction_value = null;
  1285. if (isset($restriction['attribs']['']['relationship']))
  1286. {
  1287. $restriction_relationship = $this->sanitize($restriction['attribs']['']['relationship'], SIMPLEPIE_CONSTRUCT_TEXT);
  1288. }
  1289. if (isset($restriction['attribs']['']['type']))
  1290. {
  1291. $restriction_type = $this->sanitize($restriction['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1292. }
  1293. if (isset($restriction['data']))
  1294. {
  1295. $restriction_value = $this->sanitize($restriction['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1296. }
  1297. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1298. }
  1299. }
  1300. elseif ($restrictions = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'block'))
  1301. {
  1302. foreach ($restrictions as $restriction)
  1303. {
  1304. $restriction_relationship = 'allow';
  1305. $restriction_type = null;
  1306. $restriction_value = 'itunes';
  1307. if (isset($restriction['data']) && strtolower($restriction['data']) === 'yes')
  1308. {
  1309. $restriction_relationship = 'deny';
  1310. }
  1311. $restrictions_parent[] = $this->registry->create('Restriction', array($restriction_relationship, $restriction_type, $restriction_value));
  1312. }
  1313. }
  1314. if (is_array($restrictions_parent))
  1315. {
  1316. $restrictions_parent = array_values($this->registry->call('Misc', 'array_unique', array($restrictions_parent)));
  1317. }
  1318. // THUMBNAILS
  1319. if ($thumbnails = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1320. {
  1321. foreach ($thumbnails as $thumbnail)
  1322. {
  1323. if (isset($thumbnail['attribs']['']['url']))
  1324. {
  1325. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1326. }
  1327. }
  1328. }
  1329. elseif ($thumbnails = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'thumbnail'))
  1330. {
  1331. foreach ($thumbnails as $thumbnail)
  1332. {
  1333. if (isset($thumbnail['attribs']['']['url']))
  1334. {
  1335. $thumbnails_parent[] = $this->sanitize($thumbnail['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1336. }
  1337. }
  1338. }
  1339. // TITLES
  1340. if ($title_parent = $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1341. {
  1342. if (isset($title_parent[0]['data']))
  1343. {
  1344. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1345. }
  1346. }
  1347. elseif ($title_parent = $parent->get_channel_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'title'))
  1348. {
  1349. if (isset($title_parent[0]['data']))
  1350. {
  1351. $title_parent = $this->sanitize($title_parent[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  1352. }
  1353. }
  1354. // Clear the memory
  1355. unset($parent);
  1356. // Attributes
  1357. $bitrate = null;
  1358. $channels = null;
  1359. $duration = null;
  1360. $expression = null;
  1361. $framerate = null;
  1362. $height = null;
  1363. $javascript = null;
  1364. $lang = null;
  1365. $length = null;
  1366. $medium = null;
  1367. $samplingrate = null;
  1368. $type = null;
  1369. $url = null;
  1370. $width = null;
  1371. // Elements
  1372. $captions = null;
  1373. $categories = null;
  1374. $copyrights = null;
  1375. $credits = null;
  1376. $description = null;
  1377. $hashes = null;
  1378. $keywords = null;
  1379. $player = null;
  1380. $ratings = null;
  1381. $restrictions = null;
  1382. $thumbnails = null;
  1383. $title = null;
  1384. // If we have media:group tags, loop through them.
  1385. foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group') as $group)
  1386. {
  1387. if(isset($group['child']) && isset($group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content']))
  1388. {
  1389. // If we have media:content tags, loop through them.
  1390. foreach ((array) $group['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'] as $content)
  1391. {
  1392. if (isset($content['attribs']['']['url']))
  1393. {
  1394. // Attributes
  1395. $bitrate = null;
  1396. $channels = null;
  1397. $duration = null;
  1398. $expression = null;
  1399. $framerate = null;
  1400. $height = null;
  1401. $javascript = null;
  1402. $lang = null;
  1403. $length = null;
  1404. $medium = null;
  1405. $samplingrate = null;
  1406. $type = null;
  1407. $url = null;
  1408. $width = null;
  1409. // Elements
  1410. $captions = null;
  1411. $categories = null;
  1412. $copyrights = null;
  1413. $credits = null;
  1414. $description = null;
  1415. $hashes = null;
  1416. $keywords = null;
  1417. $player = null;
  1418. $ratings = null;
  1419. $restrictions = null;
  1420. $thumbnails = null;
  1421. $title = null;
  1422. // Start checking the attributes of media:content
  1423. if (isset($content['attribs']['']['bitrate']))
  1424. {
  1425. $bitrate = $this->sanitize($content['attribs']['']['bitrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1426. }
  1427. if (isset($content['attribs']['']['channels']))
  1428. {
  1429. $channels = $this->sanitize($content['attribs']['']['channels'], SIMPLEPIE_CONSTRUCT_TEXT);
  1430. }
  1431. if (isset($content['attribs']['']['duration']))
  1432. {
  1433. $duration = $this->sanitize($content['attribs']['']['duration'], SIMPLEPIE_CONSTRUCT_TEXT);
  1434. }
  1435. else
  1436. {
  1437. $duration = $duration_parent;
  1438. }
  1439. if (isset($content['attribs']['']['expression']))
  1440. {
  1441. $expression = $this->sanitize($content['attribs']['']['expression'], SIMPLEPIE_CONSTRUCT_TEXT);
  1442. }
  1443. if (isset($content['attribs']['']['framerate']))
  1444. {
  1445. $framerate = $this->sanitize($content['attribs']['']['framerate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1446. }
  1447. if (isset($content['attribs']['']['height']))
  1448. {
  1449. $height = $this->sanitize($content['attribs']['']['height'], SIMPLEPIE_CONSTRUCT_TEXT);
  1450. }
  1451. if (isset($content['attribs']['']['lang']))
  1452. {
  1453. $lang = $this->sanitize($content['attribs']['']['lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  1454. }
  1455. if (isset($content['attribs']['']['fileSize']))
  1456. {
  1457. $length = ceil($content['attribs']['']['fileSize']);
  1458. }
  1459. if (isset($content['attribs']['']['medium']))
  1460. {
  1461. $medium = $this->sanitize($content['attribs']['']['medium'], SIMPLEPIE_CONSTRUCT_TEXT);
  1462. }
  1463. if (isset($content['attribs']['']['samplingrate']))
  1464. {
  1465. $samplingrate = $this->sanitize($content['attribs']['']['samplingrate'], SIMPLEPIE_CONSTRUCT_TEXT);
  1466. }
  1467. if (isset($content['attribs']['']['type']))
  1468. {
  1469. $type = $this->sanitize($content['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT);
  1470. }
  1471. if (isset($content['attribs']['']['width']))
  1472. {
  1473. $width = $this->sanitize($content['attribs']['']['width'], SIMPLEPIE_CONSTRUCT_TEXT);
  1474. }
  1475. $url = $this->sanitize($content['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI);
  1476. // Checking the other optional media: elements. Pr…

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