PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/simplepie/library/SimplePie/Source.php

https://bitbucket.org/moodle/moodle
PHP | 577 lines | 474 code | 47 blank | 56 comment | 57 complexity | 618c89413ae3245d422dc77677f12916 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package SimplePie
  36. * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
  37. * @author Ryan Parman
  38. * @author Sam Sneddon
  39. * @author Ryan McCue
  40. * @link http://simplepie.org/ SimplePie
  41. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  42. */
  43. /**
  44. * Handles `<atom:source>`
  45. *
  46. * Used by {@see SimplePie_Item::get_source()}
  47. *
  48. * This class can be overloaded with {@see SimplePie::set_source_class()}
  49. *
  50. * @package SimplePie
  51. * @subpackage API
  52. */
  53. class SimplePie_Source
  54. {
  55. var $item;
  56. var $data = array();
  57. protected $registry;
  58. public function __construct($item, $data)
  59. {
  60. $this->item = $item;
  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. public function get_source_tags($namespace, $tag)
  72. {
  73. if (isset($this->data['child'][$namespace][$tag]))
  74. {
  75. return $this->data['child'][$namespace][$tag];
  76. }
  77. return null;
  78. }
  79. public function get_base($element = array())
  80. {
  81. return $this->item->get_base($element);
  82. }
  83. public function sanitize($data, $type, $base = '')
  84. {
  85. return $this->item->sanitize($data, $type, $base);
  86. }
  87. public function get_item()
  88. {
  89. return $this->item;
  90. }
  91. public function get_title()
  92. {
  93. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
  94. {
  95. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  96. }
  97. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
  98. {
  99. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  100. }
  101. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
  102. {
  103. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  104. }
  105. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
  106. {
  107. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  108. }
  109. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
  110. {
  111. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  112. }
  113. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
  114. {
  115. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  116. }
  117. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
  118. {
  119. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  120. }
  121. return null;
  122. }
  123. public function get_category($key = 0)
  124. {
  125. $categories = $this->get_categories();
  126. if (isset($categories[$key]))
  127. {
  128. return $categories[$key];
  129. }
  130. return null;
  131. }
  132. public function get_categories()
  133. {
  134. $categories = array();
  135. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
  136. {
  137. $term = null;
  138. $scheme = null;
  139. $label = null;
  140. if (isset($category['attribs']['']['term']))
  141. {
  142. $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
  143. }
  144. if (isset($category['attribs']['']['scheme']))
  145. {
  146. $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
  147. }
  148. if (isset($category['attribs']['']['label']))
  149. {
  150. $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
  151. }
  152. $categories[] = $this->registry->create('Category', array($term, $scheme, $label));
  153. }
  154. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
  155. {
  156. // This is really the label, but keep this as the term also for BC.
  157. // Label will also work on retrieving because that falls back to term.
  158. $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  159. if (isset($category['attribs']['']['domain']))
  160. {
  161. $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
  162. }
  163. else
  164. {
  165. $scheme = null;
  166. }
  167. $categories[] = $this->registry->create('Category', array($term, $scheme, null));
  168. }
  169. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
  170. {
  171. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  172. }
  173. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
  174. {
  175. $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  176. }
  177. if (!empty($categories))
  178. {
  179. return array_unique($categories);
  180. }
  181. return null;
  182. }
  183. public function get_author($key = 0)
  184. {
  185. $authors = $this->get_authors();
  186. if (isset($authors[$key]))
  187. {
  188. return $authors[$key];
  189. }
  190. return null;
  191. }
  192. public function get_authors()
  193. {
  194. $authors = array();
  195. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
  196. {
  197. $name = null;
  198. $uri = null;
  199. $email = null;
  200. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  201. {
  202. $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  203. }
  204. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  205. {
  206. $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]));
  207. }
  208. if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  209. {
  210. $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  211. }
  212. if ($name !== null || $email !== null || $uri !== null)
  213. {
  214. $authors[] = $this->registry->create('Author', array($name, $uri, $email));
  215. }
  216. }
  217. if ($author = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
  218. {
  219. $name = null;
  220. $url = null;
  221. $email = null;
  222. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  223. {
  224. $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  225. }
  226. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  227. {
  228. $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]));
  229. }
  230. if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  231. {
  232. $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  233. }
  234. if ($name !== null || $email !== null || $url !== null)
  235. {
  236. $authors[] = $this->registry->create('Author', array($name, $url, $email));
  237. }
  238. }
  239. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
  240. {
  241. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  242. }
  243. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
  244. {
  245. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  246. }
  247. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
  248. {
  249. $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
  250. }
  251. if (!empty($authors))
  252. {
  253. return array_unique($authors);
  254. }
  255. return null;
  256. }
  257. public function get_contributor($key = 0)
  258. {
  259. $contributors = $this->get_contributors();
  260. if (isset($contributors[$key]))
  261. {
  262. return $contributors[$key];
  263. }
  264. return null;
  265. }
  266. public function get_contributors()
  267. {
  268. $contributors = array();
  269. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'contributor') as $contributor)
  270. {
  271. $name = null;
  272. $uri = null;
  273. $email = null;
  274. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
  275. {
  276. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  277. }
  278. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
  279. {
  280. $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]));
  281. }
  282. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
  283. {
  284. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  285. }
  286. if ($name !== null || $email !== null || $uri !== null)
  287. {
  288. $contributors[] = $this->registry->create('Author', array($name, $uri, $email));
  289. }
  290. }
  291. foreach ((array) $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'contributor') as $contributor)
  292. {
  293. $name = null;
  294. $url = null;
  295. $email = null;
  296. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
  297. {
  298. $name = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  299. }
  300. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
  301. {
  302. $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]));
  303. }
  304. if (isset($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
  305. {
  306. $email = $this->sanitize($contributor['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  307. }
  308. if ($name !== null || $email !== null || $url !== null)
  309. {
  310. $contributors[] = $this->registry->create('Author', array($name, $url, $email));
  311. }
  312. }
  313. if (!empty($contributors))
  314. {
  315. return array_unique($contributors);
  316. }
  317. return null;
  318. }
  319. public function get_link($key = 0, $rel = 'alternate')
  320. {
  321. $links = $this->get_links($rel);
  322. if (isset($links[$key]))
  323. {
  324. return $links[$key];
  325. }
  326. return null;
  327. }
  328. /**
  329. * Added for parity between the parent-level and the item/entry-level.
  330. */
  331. public function get_permalink()
  332. {
  333. return $this->get_link(0);
  334. }
  335. public function get_links($rel = 'alternate')
  336. {
  337. if (!isset($this->data['links']))
  338. {
  339. $this->data['links'] = array();
  340. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'link'))
  341. {
  342. foreach ($links as $link)
  343. {
  344. if (isset($link['attribs']['']['href']))
  345. {
  346. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  347. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  348. }
  349. }
  350. }
  351. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'link'))
  352. {
  353. foreach ($links as $link)
  354. {
  355. if (isset($link['attribs']['']['href']))
  356. {
  357. $link_rel = (isset($link['attribs']['']['rel'])) ? $link['attribs']['']['rel'] : 'alternate';
  358. $this->data['links'][$link_rel][] = $this->sanitize($link['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($link));
  359. }
  360. }
  361. }
  362. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'link'))
  363. {
  364. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  365. }
  366. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'link'))
  367. {
  368. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  369. }
  370. if ($links = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'link'))
  371. {
  372. $this->data['links']['alternate'][] = $this->sanitize($links[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($links[0]));
  373. }
  374. $keys = array_keys($this->data['links']);
  375. foreach ($keys as $key)
  376. {
  377. if ($this->registry->call('Misc', 'is_isegment_nz_nc', array($key)))
  378. {
  379. if (isset($this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]))
  380. {
  381. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key]);
  382. $this->data['links'][$key] =& $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key];
  383. }
  384. else
  385. {
  386. $this->data['links'][SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY . $key] =& $this->data['links'][$key];
  387. }
  388. }
  389. elseif (substr($key, 0, 41) === SIMPLEPIE_IANA_LINK_RELATIONS_REGISTRY)
  390. {
  391. $this->data['links'][substr($key, 41)] =& $this->data['links'][$key];
  392. }
  393. $this->data['links'][$key] = array_unique($this->data['links'][$key]);
  394. }
  395. }
  396. if (isset($this->data['links'][$rel]))
  397. {
  398. return $this->data['links'][$rel];
  399. }
  400. return null;
  401. }
  402. public function get_description()
  403. {
  404. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'subtitle'))
  405. {
  406. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  407. }
  408. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'tagline'))
  409. {
  410. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  411. }
  412. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'description'))
  413. {
  414. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  415. }
  416. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'description'))
  417. {
  418. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  419. }
  420. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'description'))
  421. {
  422. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
  423. }
  424. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'description'))
  425. {
  426. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  427. }
  428. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'description'))
  429. {
  430. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  431. }
  432. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'summary'))
  433. {
  434. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  435. }
  436. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'subtitle'))
  437. {
  438. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
  439. }
  440. return null;
  441. }
  442. public function get_copyright()
  443. {
  444. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'rights'))
  445. {
  446. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  447. }
  448. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'copyright'))
  449. {
  450. return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
  451. }
  452. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'copyright'))
  453. {
  454. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  455. }
  456. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'rights'))
  457. {
  458. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  459. }
  460. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'rights'))
  461. {
  462. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  463. }
  464. return null;
  465. }
  466. public function get_language()
  467. {
  468. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'language'))
  469. {
  470. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  471. }
  472. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_11, 'language'))
  473. {
  474. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  475. }
  476. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_DC_10, 'language'))
  477. {
  478. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
  479. }
  480. elseif (isset($this->data['xml_lang']))
  481. {
  482. return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT);
  483. }
  484. return null;
  485. }
  486. public function get_latitude()
  487. {
  488. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lat'))
  489. {
  490. return (float) $return[0]['data'];
  491. }
  492. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  493. {
  494. return (float) $match[1];
  495. }
  496. return null;
  497. }
  498. public function get_longitude()
  499. {
  500. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'long'))
  501. {
  502. return (float) $return[0]['data'];
  503. }
  504. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_W3C_BASIC_GEO, 'lon'))
  505. {
  506. return (float) $return[0]['data'];
  507. }
  508. elseif (($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_GEORSS, 'point')) && preg_match('/^((?:-)?[0-9]+(?:\.[0-9]+)) ((?:-)?[0-9]+(?:\.[0-9]+))$/', trim($return[0]['data']), $match))
  509. {
  510. return (float) $match[2];
  511. }
  512. return null;
  513. }
  514. public function get_image_url()
  515. {
  516. if ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'image'))
  517. {
  518. return $this->sanitize($return[0]['attribs']['']['href'], SIMPLEPIE_CONSTRUCT_IRI);
  519. }
  520. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'logo'))
  521. {
  522. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  523. }
  524. elseif ($return = $this->get_source_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))
  525. {
  526. return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
  527. }
  528. return null;
  529. }
  530. }