PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/SimplePie/Source.php

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