PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/SimplePie/Source.php

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