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

/wp-includes/library/Simplepie/Item.php

https://bitbucket.org/aukhanev/xdn-wordpress31
PHP | 2674 lines | 2423 code | 117 blank | 134 comment | 352 complexity | 19f838b71bb58c580cd221a1acbfd96d MD5 | raw file

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

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