PageRenderTime 72ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/simplepie/simplepie_060803.inc

https://github.com/komagata/plnet
PHP | 4471 lines | 3802 code | 307 blank | 362 comment | 619 complexity | 6ebb26fb8e7581b0d788a2c60cf3e934 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /****************************************************
  3. SIMPLEPIE
  4. A PHP-Based RSS and Atom Feed Framework
  5. Takes the hard work out of managing a complete RSS/Atom solution.
  6. Version: "Lemon Meringue"
  7. Updated: 3 August 2006
  8. Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon
  9. http://simplepie.org
  10. *****************************************************
  11. LICENSE:
  12. GNU Lesser General Public License 2.1 (LGPL)
  13. http://creativecommons.org/licenses/LGPL/2.1/
  14. *****************************************************
  15. Please submit all bug reports and feature requests to the SimplePie forums.
  16. http://simplepie.org/support/
  17. ****************************************************/
  18. class SimplePie
  19. {
  20. // SimplePie Info
  21. var $name = 'SimplePie';
  22. var $version = 'Lemon Meringue';
  23. var $build = '20060803';
  24. var $url = 'http://simplepie.org/';
  25. var $useragent;
  26. var $linkback;
  27. // Other objects, instances created here so we can set options on them
  28. var $sanitize;
  29. // Options
  30. var $rss_url;
  31. var $xml_dump = false;
  32. var $enable_cache = true;
  33. var $max_minutes = 60;
  34. var $cache_location = './cache';
  35. var $order_by_date = true;
  36. // Misc. variables
  37. var $data;
  38. var $error;
  39. function SimplePie($feed_url = null, $cache_location = null, $cache_max_minutes = null)
  40. {
  41. $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build;
  42. $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>';
  43. // Other objects, instances created here so we can set options on them
  44. $this->sanitize = new SimplePie_Sanitize;
  45. // Parse the feed, if we get the data sent directly here
  46. if (!is_null($feed_url)) {
  47. $this->feed_url($feed_url);
  48. }
  49. if (!is_null($cache_location)) {
  50. $this->cache_location($cache_location);
  51. }
  52. if (!is_null($cache_max_minutes)) {
  53. $this->cache_max_minutes($cache_max_minutes);
  54. }
  55. // If we've passed an xmldump variable in the URL, snap into XMLdump mode
  56. if (isset($_GET['xmldump'])) {
  57. $this->enable_xmldump(true);
  58. }
  59. if (!is_null($feed_url)) {
  60. return $this->init();
  61. }
  62. }
  63. function feed_url($url)
  64. {
  65. $this->rss_url = SimplePie_Misc::fix_protocol($url, 1);
  66. }
  67. function enable_xmldump($enable = false)
  68. {
  69. $this->xml_dump = (bool) $enable;
  70. }
  71. function enable_caching($enable = true)
  72. {
  73. $this->enable_cache = (bool) $enable;
  74. }
  75. function cache_max_minutes($minutes = 60)
  76. {
  77. $this->max_minutes = (float) $minutes;
  78. }
  79. function cache_location($location = './cache')
  80. {
  81. $this->cache_location = (string) $location;
  82. }
  83. function order_by_date($enable = true)
  84. {
  85. $this->order_by_date = (bool) $enable;
  86. }
  87. function bypass_image_hotlink($get = 'i')
  88. {
  89. $this->sanitize->bypass_image_hotlink($get);
  90. }
  91. function bypass_image_hotlink_page($page = false)
  92. {
  93. $this->sanitize->bypass_image_hotlink_page($page);
  94. }
  95. function replace_headers($enable = false)
  96. {
  97. $this->sanitize->replace_headers($enable);
  98. }
  99. function remove_div($enable = true)
  100. {
  101. $this->sanitize->remove_div($enable);
  102. }
  103. function strip_ads($enable = true)
  104. {
  105. $this->sanitize->strip_ads($enable);
  106. }
  107. function strip_htmltags($tags = array('blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null)
  108. {
  109. $this->sanitize->strip_htmltags($tags);
  110. if (!is_null($encode))
  111. {
  112. $this->sanitize->encode_instead_of_strip($tags);
  113. }
  114. }
  115. function encode_instead_of_strip($enable = true)
  116. {
  117. $this->sanitize->encode_instead_of_strip($enable);
  118. }
  119. function strip_attributes($attribs = array('class', 'id', 'style', 'onclick', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
  120. {
  121. $this->sanitize->strip_attributes($attribs);
  122. }
  123. function init()
  124. {
  125. if ($this->sanitize->bypass_image_hotlink && !empty($_GET[$this->sanitize->bypass_image_hotlink]))
  126. {
  127. if (get_magic_quotes_gpc())
  128. {
  129. $_GET[$this->sanitize->bypass_image_hotlink] = stripslashes($_GET[$this->sanitize->bypass_image_hotlink]);
  130. }
  131. SimplePie_Misc::display_file($_GET[$this->sanitize->bypass_image_hotlink], 10, $this->useragent);
  132. }
  133. if (isset($_GET['js']))
  134. {
  135. $embed = <<<EOT
  136. function embed_odeo(link) {document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="440" height="80" align="middle"><param name="movie" value="http://odeo.com/flash/audio_player_fullsize.swf" /><param name="allowScriptAccess" value="any" /><param name="quality" value="high"><param name="wmode" value="transparent"><param name="flashvars" value="valid_sample_rate=true&external_url='+link+'" /><embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed></object>');}
  137. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {document.writeln('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" style="cursor:hand; cursor:pointer;" type="'+type+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'"><param name="href" value="'+link+'" /><param name="src" value="'+placeholder+'" /><param name="autoplay" value="false" /><param name="target" value="myself" /><param name="controller" value="false" /><param name="loop" value="'+loop+'" /><param name="scale" value="aspect" /><param name="bgcolor" value="'+bgcolor+'"><embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>');}
  138. function embed_flash(bgcolor, width, height, link, loop, type) {document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'"><param name="movie" value="'+link+'"><param name="quality" value="high"><param name="loop" value="'+loop+'"><param name="bgcolor" value="'+bgcolor+'"><embed src="'+link+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed></object>');}
  139. function embed_wmedia(width, height, link) {document.writeln('<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" type="application/x-oleobject" width="'+width+'" height="'+height+'" standby="Loading Windows Media Player..."><param name="FileName" value="'+link+'"><param name="autosize" value="true"><param name="ShowControls" value="true"><param name="ShowStatusBar" value="false"><param name="ShowDisplay" value="false"><param name="autostart" value="false"><embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed></object>');}
  140. EOT;
  141. ob_start('ob_gzhandler');
  142. header('Content-type: text/javascript; charset: UTF-8');
  143. header('Cache-Control: must-revalidate');
  144. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
  145. echo $embed;
  146. exit;
  147. }
  148. if (!empty($this->rss_url))
  149. {
  150. $this->data = array();
  151. if ($this->enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url))
  152. {
  153. $cache = new SimplePie_Cache($this->cache_location, sha1($this->rss_url), 'spc');
  154. }
  155. else
  156. {
  157. $cache = false;
  158. }
  159. if ($cache && !$this->xml_dump)
  160. {
  161. $this->data = $cache->load();
  162. if (!empty($this->data))
  163. {
  164. if (!empty($this->data['feed_url']))
  165. {
  166. $this->rss_url = $this->data['feed_url'];
  167. return $this->init();
  168. }
  169. else if ($cache->mtime() + $this->max_minutes * 60 < time())
  170. {
  171. if (!empty($this->data['last-modified']) || !empty($this->data['etag']))
  172. {
  173. $headers = array();
  174. if (!empty($this->data['last-modified']))
  175. {
  176. $headers['if-modified-since'] = $this->data['last-modified'];
  177. }
  178. if (!empty($this->data['etag']))
  179. {
  180. $headers['if-none-match'] = $this->data['etag'];
  181. }
  182. $file = new SimplePie_File($this->rss_url, 1, 5, $headers, $this->useragent);
  183. if ($file->success)
  184. {
  185. $headers = $file->headers();
  186. if ($headers['status']['code'] == 304)
  187. {
  188. $cache->touch();
  189. return true;
  190. }
  191. }
  192. unset($file);
  193. }
  194. else
  195. {
  196. $cache->unlink();
  197. }
  198. }
  199. else
  200. {
  201. return true;
  202. }
  203. }
  204. else
  205. {
  206. $cache->unlink();
  207. }
  208. }
  209. $this->data = array();
  210. if (!isset($file))
  211. {
  212. $file = new SimplePie_File($this->rss_url, 10, 5, null, $this->useragent);
  213. }
  214. if (!$file->success)
  215. {
  216. return false;
  217. }
  218. if (!SimplePie_Locator::is_feed($file))
  219. {
  220. $locate = new SimplePie_Locator($file);
  221. $feed = $locate->find();
  222. if ($feed)
  223. {
  224. if ($cache && !$cache->save(array('feed_url' => $feed)))
  225. {
  226. $this->error = "$cache->name is not writeable";
  227. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  228. }
  229. $this->rss_url = $feed;
  230. return $this->init();
  231. }
  232. else
  233. {
  234. $this->error = "A feed could not be found at $this->rss_url";
  235. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  236. return false;
  237. }
  238. }
  239. $headers = $file->headers();
  240. $data = trim($file->body());
  241. $file->close();
  242. unset($file);
  243. // First try HTTP headers
  244. if (!empty($headers['content-type']) && preg_match('/charset=(.*)/i', $headers['content-type'], $charset))
  245. {
  246. $encoding = SimplePie_Misc::encoding($charset[1]);
  247. }
  248. // Then prolog, if at the very start of the document
  249. else if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\s*=\s*["|\'](.*)["|\']/Ui', $prolog[1], $encoding))
  250. {
  251. $encoding = SimplePie_Misc::encoding($encoding[1]);
  252. }
  253. // UTF-32 Big Endian BOM
  254. else if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
  255. {
  256. $encoding = SimplePie_Misc::encoding('UTF-32be');
  257. }
  258. // UTF-32 Little Endian BOM
  259. else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
  260. {
  261. $encoding = SimplePie_Misc::encoding('UTF-32');
  262. }
  263. // UTF-16 Big Endian BOM
  264. else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
  265. {
  266. $encoding = SimplePie_Misc::encoding('UTF-16be');
  267. }
  268. // UTF-16 Little Endian BOM
  269. else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
  270. {
  271. $encoding = SimplePie_Misc::encoding('UTF-16le');
  272. }
  273. // UTF-8 BOM
  274. else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
  275. {
  276. $encoding = SimplePie_Misc::encoding('UTF-8');
  277. }
  278. // Fallback to the default
  279. else
  280. {
  281. $encoding = SimplePie_Misc::encoding(null);
  282. }
  283. if (function_exists('iconv') && $encoding['use_iconv'] && iconv($encoding['encoding'], 'UTF-8//TRANSLIT', $data))
  284. {
  285. $data = iconv($encoding['encoding'], 'UTF-8//TRANSLIT', $data);
  286. $encoding['encoding'] = 'UTF-8';
  287. }
  288. else if (function_exists('iconv') && $encoding['use_iconv'] && iconv($encoding['encoding'], 'UTF-8', $data))
  289. {
  290. $data = iconv($encoding['encoding'], 'UTF-8', $data);
  291. $encoding['encoding'] = 'UTF-8';
  292. }
  293. else if (function_exists('mb_convert_encoding') && $encoding['use_mbstring'])
  294. {
  295. $data = mb_convert_encoding($data, 'UTF-8', $encoding['encoding']);
  296. $encoding['encoding'] = 'UTF-8';
  297. }
  298. else if ($encoding['encoding'] == 'ISO-8859-1')
  299. {
  300. $data = utf8_encode($data);
  301. $encoding['encoding'] = 'UTF-8';
  302. }
  303. else
  304. {
  305. $encoding['encoding'] = 'UTF-8';
  306. }
  307. $data = new SimplePie_Parser($data, 'UTF-8', $this->xml_dump);
  308. if ($this->xml_dump)
  309. {
  310. header('Content-type: text/xml; charset=UTF-8');
  311. echo $data->data;
  312. exit;
  313. }
  314. else if (!$data->error_code)
  315. {
  316. $this->sanitize->parse_data_array($data->data);
  317. unset($data);
  318. $this->data['feedinfo'] = $this->sanitize->feedinfo;
  319. $this->data['info'] = $this->sanitize->info;
  320. $this->data['items'] = $this->sanitize->items;
  321. unset($this->sanitize);
  322. $this->data['feedinfo']['encoding'] = 'UTF-8';
  323. if (!empty($headers['last-modified']))
  324. {
  325. $this->data['last-modified'] = $headers['last-modified'];
  326. }
  327. if (!empty($headers['etag']))
  328. {
  329. $this->data['etag'] = $headers['etag'];
  330. }
  331. if ($this->order_by_date && !empty($this->data['items']))
  332. {
  333. $do_sort = true;
  334. foreach ($this->data['items'] as $item)
  335. {
  336. if (!isset($item->date))
  337. {
  338. $do_sort = false;
  339. break;
  340. }
  341. }
  342. if ($do_sort)
  343. {
  344. usort($this->data['items'], create_function('$a,$b', 'if ($a->date == $b->date) return 0; return ($a->date < $b->date) ? 1 : -1;'));
  345. }
  346. }
  347. if ($cache && !$cache->save($this->data))
  348. {
  349. $this->error = "$cache->name is not writeable";
  350. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  351. }
  352. return true;
  353. }
  354. else
  355. {
  356. $this->error = "XML error: $data->error_string at line $data->current_line, column $data->current_column";
  357. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  358. return false;
  359. }
  360. }
  361. }
  362. function get_encoding()
  363. {
  364. if (!empty($this->data['feedinfo']['encoding']))
  365. {
  366. return $this->data['feedinfo']['encoding'];
  367. }
  368. else
  369. {
  370. return false;
  371. }
  372. }
  373. function handle_content_type($mime='text/html')
  374. {
  375. if (!headers_sent())
  376. {
  377. $header = "Content-type: $mime;";
  378. if ($this->get_encoding())
  379. {
  380. $header .= ' charset=' . $this->get_encoding();
  381. }
  382. else
  383. {
  384. $header .= ' charset=UTF-8';
  385. }
  386. header($header);
  387. }
  388. }
  389. function get_type()
  390. {
  391. if (!empty($this->data['feedinfo']['type']))
  392. {
  393. return $this->data['feedinfo']['type'];
  394. }
  395. else
  396. {
  397. return false;
  398. }
  399. }
  400. function get_version()
  401. {
  402. if (!empty($this->data['feedinfo']['version']))
  403. {
  404. return $this->data['feedinfo']['version'];
  405. }
  406. else
  407. {
  408. return false;
  409. }
  410. }
  411. function subscribe_url()
  412. {
  413. if (!empty($this->rss_url))
  414. {
  415. return $this->rss_url;
  416. }
  417. else
  418. {
  419. return false;
  420. }
  421. }
  422. function subscribe_feed()
  423. {
  424. if (!empty($this->rss_url))
  425. {
  426. return SimplePie_Misc::fix_protocol($this->rss_url, 2);
  427. }
  428. else
  429. {
  430. return false;
  431. }
  432. }
  433. function subscribe_outlook()
  434. {
  435. if (!empty($this->rss_url))
  436. {
  437. return 'outlook' . SimplePie_Misc::fix_protocol($this->rss_url, 2);
  438. }
  439. else
  440. {
  441. return false;
  442. }
  443. }
  444. function subscribe_podcast()
  445. {
  446. if (!empty($this->rss_url))
  447. {
  448. return SimplePie_Misc::fix_protocol($this->rss_url, 3);
  449. }
  450. else
  451. {
  452. return false;
  453. }
  454. }
  455. function subscribe_aol()
  456. {
  457. if ($this->subscribe_url())
  458. {
  459. return 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url());
  460. }
  461. else
  462. {
  463. return false;
  464. }
  465. }
  466. function subscribe_bloglines()
  467. {
  468. if ($this->subscribe_url())
  469. {
  470. return 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url());
  471. }
  472. else
  473. {
  474. return false;
  475. }
  476. }
  477. function subscribe_eskobo()
  478. {
  479. if ($this->subscribe_url())
  480. {
  481. return 'http://www.eskobo.com/?AddToMyPage=' . rawurlencode($this->subscribe_url());
  482. }
  483. else
  484. {
  485. return false;
  486. }
  487. }
  488. function subscribe_feedfeeds()
  489. {
  490. if ($this->subscribe_url())
  491. {
  492. return 'http://www.feedfeeds.com/add?feed=' . rawurlencode($this->subscribe_url());
  493. }
  494. else
  495. {
  496. return false;
  497. }
  498. }
  499. function subscribe_feedlounge()
  500. {
  501. if ($this->subscribe_url())
  502. {
  503. return 'http://my.feedlounge.com/external/subscribe?url=' . rawurlencode($this->subscribe_url());
  504. }
  505. else
  506. {
  507. return false;
  508. }
  509. }
  510. function subscribe_feedster()
  511. {
  512. if ($this->subscribe_url())
  513. {
  514. return 'http://www.feedster.com/myfeedster.php?action=addrss&amp;confirm=no&amp;rssurl=' . rawurlencode($this->subscribe_url());
  515. }
  516. else
  517. {
  518. return false;
  519. }
  520. }
  521. function subscribe_google()
  522. {
  523. if ($this->subscribe_url())
  524. {
  525. return 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url());
  526. }
  527. else
  528. {
  529. return false;
  530. }
  531. }
  532. function subscribe_gritwire()
  533. {
  534. if ($this->subscribe_url())
  535. {
  536. return 'http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=' . rawurlencode($this->subscribe_url());
  537. }
  538. else
  539. {
  540. return false;
  541. }
  542. }
  543. function subscribe_msn()
  544. {
  545. if ($this->subscribe_url())
  546. {
  547. $url = 'http://my.msn.com/addtomymsn.armx?id=rss&amp;ut=' . rawurlencode($this->subscribe_url());
  548. if ($this->get_feed_link())
  549. {
  550. $url .= '&amp;ru=' . rawurlencode($this->get_feed_link());
  551. }
  552. return $url;
  553. }
  554. else
  555. {
  556. return false;
  557. }
  558. }
  559. function subscribe_netvibes()
  560. {
  561. if ($this->subscribe_url())
  562. {
  563. return 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url());
  564. }
  565. else
  566. {
  567. return false;
  568. }
  569. }
  570. function subscribe_newsburst()
  571. {
  572. if ($this->subscribe_url())
  573. {
  574. return 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url());
  575. }
  576. else
  577. {
  578. return false;
  579. }
  580. }
  581. function subscribe_newsgator()
  582. {
  583. if ($this->subscribe_url())
  584. {
  585. return 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url());
  586. }
  587. else
  588. {
  589. return false;
  590. }
  591. }
  592. function subscribe_odeo()
  593. {
  594. if ($this->subscribe_url())
  595. {
  596. return 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url());
  597. }
  598. else
  599. {
  600. return false;
  601. }
  602. }
  603. function subscribe_pluck()
  604. {
  605. if ($this->subscribe_url())
  606. {
  607. return 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&amp;a=' . rawurlencode($this->subscribe_url());
  608. }
  609. else
  610. {
  611. return false;
  612. }
  613. }
  614. function subscribe_podnova()
  615. {
  616. if ($this->subscribe_url())
  617. {
  618. return 'http://www.podnova.com/index_your_podcasts.srf?action=add&amp;url=' . rawurlencode($this->subscribe_url());
  619. }
  620. else
  621. {
  622. return false;
  623. }
  624. }
  625. function subscribe_rojo()
  626. {
  627. if ($this->subscribe_url())
  628. {
  629. return 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url());
  630. }
  631. else
  632. {
  633. return false;
  634. }
  635. }
  636. function subscribe_yahoo()
  637. {
  638. if ($this->subscribe_url())
  639. {
  640. return 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url());
  641. }
  642. else
  643. {
  644. return false;
  645. }
  646. }
  647. function get_feed_title()
  648. {
  649. if (!empty($this->data['info']['title']))
  650. {
  651. return $this->data['info']['title'];
  652. }
  653. else
  654. {
  655. return false;
  656. }
  657. }
  658. function get_feed_link()
  659. {
  660. if (!empty($this->data['info']['link']['alternate'][0]))
  661. {
  662. return $this->data['info']['link']['alternate'][0];
  663. }
  664. else
  665. {
  666. return false;
  667. }
  668. }
  669. function get_feed_links()
  670. {
  671. if (!empty($this->data['info']['link']))
  672. {
  673. return $this->data['info']['link'];
  674. }
  675. else
  676. {
  677. return false;
  678. }
  679. }
  680. function get_feed_description()
  681. {
  682. if (!empty($this->data['info']['description']))
  683. {
  684. return $this->data['info']['description'];
  685. }
  686. else if (!empty($this->data['info']['dc:description']))
  687. {
  688. return $this->data['info']['dc:description'];
  689. }
  690. else if (!empty($this->data['info']['tagline']))
  691. {
  692. return $this->data['info']['tagline'];
  693. }
  694. else if (!empty($this->data['info']['subtitle']))
  695. {
  696. return $this->data['info']['subtitle'];
  697. }
  698. else
  699. {
  700. return false;
  701. }
  702. }
  703. function get_feed_copyright()
  704. {
  705. if (!empty($this->data['info']['copyright']))
  706. {
  707. return $this->data['info']['copyright'];
  708. }
  709. else
  710. {
  711. return false;
  712. }
  713. }
  714. function get_feed_language()
  715. {
  716. if (!empty($this->data['info']['language']))
  717. {
  718. return $this->data['info']['language'];
  719. }
  720. else if (!empty($this->data['info']['xml:lang']))
  721. {
  722. return $this->data['info']['xml:lang'];
  723. }
  724. else
  725. {
  726. return false;
  727. }
  728. }
  729. function get_image_exist()
  730. {
  731. if (!empty($this->data['info']['image']['url']) || !empty($this->data['info']['image']['logo']))
  732. {
  733. return true;
  734. }
  735. else
  736. {
  737. return false;
  738. }
  739. }
  740. function get_image_title()
  741. {
  742. if (!empty($this->data['info']['image']['title']))
  743. {
  744. return $this->data['info']['image']['title'];
  745. }
  746. else
  747. {
  748. return false;
  749. }
  750. }
  751. function get_image_url()
  752. {
  753. if (!empty($this->data['info']['image']['url']))
  754. {
  755. return $this->data['info']['image']['url'];
  756. }
  757. else if (!empty($this->data['info']['image']['logo']))
  758. {
  759. return $this->data['info']['image']['logo'];
  760. }
  761. else
  762. {
  763. return false;
  764. }
  765. }
  766. function get_image_link()
  767. {
  768. if (!empty($this->data['info']['image']['link']))
  769. {
  770. return $this->data['info']['image']['link'];
  771. }
  772. else
  773. {
  774. return false;
  775. }
  776. }
  777. function get_image_width()
  778. {
  779. if (!empty($this->data['info']['image']['width']))
  780. {
  781. return $this->data['info']['image']['width'];
  782. }
  783. else
  784. {
  785. return false;
  786. }
  787. }
  788. function get_image_height()
  789. {
  790. if (!empty($this->data['info']['image']['height']))
  791. {
  792. return $this->data['info']['image']['height'];
  793. }
  794. else
  795. {
  796. return false;
  797. }
  798. }
  799. function get_item_quantity($max = 0)
  800. {
  801. if (!empty($this->data['items']))
  802. {
  803. $qty = sizeof($this->data['items']);
  804. }
  805. else
  806. {
  807. $qty = 0;
  808. }
  809. if ($max == 0)
  810. {
  811. return $qty;
  812. }
  813. else
  814. {
  815. return ($qty > $max) ? $max : $qty;
  816. }
  817. }
  818. function get_item($key)
  819. {
  820. if (!empty($this->data['items'][$key]))
  821. {
  822. return $this->data['items'][$key];
  823. }
  824. else
  825. {
  826. return false;
  827. }
  828. }
  829. function get_items($start = 0, $end = 0)
  830. {
  831. if ($end == 0)
  832. {
  833. return array_slice($this->data['items'], $start);
  834. }
  835. else
  836. {
  837. return array_slice($this->data['items'], $start, $end);
  838. }
  839. }
  840. }
  841. class SimplePie_Item
  842. {
  843. var $data;
  844. function SimplePie_Item($data)
  845. {
  846. $this->data =& $data;
  847. }
  848. function get_id()
  849. {
  850. if (!empty($this->data['guid']['data']))
  851. {
  852. return $this->data['guid']['data'];
  853. }
  854. else if (!empty($this->data['id']))
  855. {
  856. return $this->data['id'];
  857. }
  858. else
  859. {
  860. return false;
  861. }
  862. }
  863. function get_title()
  864. {
  865. if (!empty($this->data['title']))
  866. {
  867. return $this->data['title'];
  868. }
  869. else if (!empty($this->data['dc:title']))
  870. {
  871. return $this->data['dc:title'];
  872. }
  873. else
  874. {
  875. return false;
  876. }
  877. }
  878. function get_description()
  879. {
  880. if (!empty($this->data['content']))
  881. {
  882. return $this->data['content'];
  883. }
  884. else if (!empty($this->data['encoded']))
  885. {
  886. return $this->data['encoded'];
  887. }
  888. else if (!empty($this->data['summary']))
  889. {
  890. return $this->data['summary'];
  891. }
  892. else if (!empty($this->data['description']))
  893. {
  894. return $this->data['description'];
  895. }
  896. else if (!empty($this->data['dc:description']))
  897. {
  898. return $this->data['dc:description'];
  899. }
  900. else if (!empty($this->data['longdesc']))
  901. {
  902. return $this->data['longdesc'];
  903. }
  904. else
  905. {
  906. return false;
  907. }
  908. }
  909. function get_category($key = null)
  910. {
  911. if (is_null($key))
  912. {
  913. return $this->get_categories();
  914. }
  915. else
  916. {
  917. $categories = $this->get_categories();
  918. if (!empty($categories[$key]))
  919. {
  920. return $categories[$key];
  921. }
  922. else
  923. {
  924. return false;
  925. }
  926. }
  927. }
  928. function get_categories()
  929. {
  930. $categories = array();
  931. if (!empty($this->data['category']))
  932. {
  933. $categories = array_merge($categories, $this->data['category']);
  934. }
  935. if (!empty($this->data['subject']))
  936. {
  937. $categories = array_merge($categories, $this->data['subject']);
  938. }
  939. if (!empty($categories))
  940. {
  941. return array_unique($categories);
  942. }
  943. else
  944. {
  945. return false;
  946. }
  947. }
  948. function get_author($key)
  949. {
  950. $authors = $this->get_authors();
  951. if (!empty($authors[$key]))
  952. {
  953. return $authors[$key];
  954. }
  955. else
  956. {
  957. return false;
  958. }
  959. }
  960. function get_authors()
  961. {
  962. $authors = array();
  963. if (!empty($this->data['author']))
  964. {
  965. $authors = array_merge($authors, $this->data['author']);
  966. }
  967. if (!empty($this->data['creator']))
  968. {
  969. $authors = array_merge($authors, $this->data['creator']);
  970. }
  971. if (!empty($authors))
  972. {
  973. return array_unique($authors);
  974. }
  975. else
  976. {
  977. return false;
  978. }
  979. }
  980. function get_date($date_format = 'j F Y, g:i a')
  981. {
  982. if (!empty($this->data['pubdate']))
  983. {
  984. return date($date_format, $this->data['pubdate']);
  985. }
  986. else if (!empty($this->data['dc:date']))
  987. {
  988. return date($date_format, $this->data['dc:date']);
  989. }
  990. else if (!empty($this->data['issued']))
  991. {
  992. return date($date_format, $this->data['issued']);
  993. }
  994. else if (!empty($this->data['published']))
  995. {
  996. return date($date_format, $this->data['published']);
  997. }
  998. else if (!empty($this->data['modified']))
  999. {
  1000. return date($date_format, $this->data['modified']);
  1001. }
  1002. else if (!empty($this->data['updated']))
  1003. {
  1004. return date($date_format, $this->data['updated']);
  1005. }
  1006. else
  1007. {
  1008. return false;
  1009. }
  1010. }
  1011. function get_permalink()
  1012. {
  1013. $link = $this->get_link(0);
  1014. $enclosure = $this->get_enclosure(0);
  1015. if (!empty($link))
  1016. {
  1017. return $link;
  1018. }
  1019. else if (!empty($enclosure))
  1020. {
  1021. return $enclosure->get_link();
  1022. }
  1023. else
  1024. {
  1025. return false;
  1026. }
  1027. }
  1028. function get_link($key, $rel = 'alternate')
  1029. {
  1030. $links = $this->get_links($rel);
  1031. if (!empty($links[$key]))
  1032. {
  1033. return $links[$key];
  1034. }
  1035. else
  1036. {
  1037. return false;
  1038. }
  1039. }
  1040. function get_links($rel = 'alternate')
  1041. {
  1042. if (!empty($this->data['link'][$rel]))
  1043. {
  1044. return $this->data['link'][$rel];
  1045. }
  1046. else
  1047. {
  1048. return false;
  1049. }
  1050. }
  1051. function get_enclosure($key)
  1052. {
  1053. $enclosures = $this->get_enclosures();
  1054. if (!empty($enclosures[$key]))
  1055. {
  1056. return $enclosures[$key];
  1057. }
  1058. else
  1059. {
  1060. return false;
  1061. }
  1062. }
  1063. function get_enclosures()
  1064. {
  1065. $enclosures = array();
  1066. $links = $this->get_links('enclosure');
  1067. if (!empty($this->data['enclosures']))
  1068. {
  1069. $enclosures = array_merge($enclosures, $this->data['enclosures']);
  1070. }
  1071. if (!empty($links))
  1072. {
  1073. $enclosures = array_merge($enclosures, $links);
  1074. }
  1075. if (!empty($enclosures))
  1076. {
  1077. return array_unique($enclosures);
  1078. }
  1079. else
  1080. {
  1081. return false;
  1082. }
  1083. }
  1084. function add_to_blinklist()
  1085. {
  1086. if ($this->get_permalink())
  1087. {
  1088. $url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=' . rawurlencode($this->get_permalink());
  1089. if ($this->get_title())
  1090. {
  1091. $url .= '&amp;Title=' . rawurlencode($this->get_title());
  1092. }
  1093. return $url;
  1094. }
  1095. else
  1096. {
  1097. return false;
  1098. }
  1099. }
  1100. function add_to_blogmarks()
  1101. {
  1102. if ($this->get_permalink())
  1103. {
  1104. $url = 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=' . rawurlencode($this->get_permalink());
  1105. if ($this->get_title())
  1106. {
  1107. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1108. }
  1109. return $url;
  1110. }
  1111. else
  1112. {
  1113. return false;
  1114. }
  1115. }
  1116. function add_to_delicious()
  1117. {
  1118. if ($this->get_permalink())
  1119. {
  1120. $url = 'http://del.icio.us/post/?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1121. if ($this->get_title())
  1122. {
  1123. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1124. }
  1125. return $url;
  1126. }
  1127. else
  1128. {
  1129. return false;
  1130. }
  1131. }
  1132. function add_to_digg()
  1133. {
  1134. if ($this->get_permalink())
  1135. {
  1136. return 'http://digg.com/submit?phase=2&amp;URL=' . rawurlencode($this->get_permalink());
  1137. }
  1138. else
  1139. {
  1140. return false;
  1141. }
  1142. }
  1143. function add_to_furl()
  1144. {
  1145. if ($this->get_permalink())
  1146. {
  1147. $url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
  1148. if ($this->get_title())
  1149. {
  1150. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1151. }
  1152. return $url;
  1153. }
  1154. else
  1155. {
  1156. return false;
  1157. }
  1158. }
  1159. function add_to_magnolia()
  1160. {
  1161. if ($this->get_permalink())
  1162. {
  1163. $url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
  1164. if ($this->get_title())
  1165. {
  1166. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1167. }
  1168. return $url;
  1169. }
  1170. else
  1171. {
  1172. return false;
  1173. }
  1174. }
  1175. function add_to_myweb20()
  1176. {
  1177. if ($this->get_permalink())
  1178. {
  1179. $url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
  1180. if ($this->get_title())
  1181. {
  1182. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1183. }
  1184. return $url;
  1185. }
  1186. else
  1187. {
  1188. return false;
  1189. }
  1190. }
  1191. function add_to_newsvine()
  1192. {
  1193. if ($this->get_permalink())
  1194. {
  1195. $url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
  1196. if ($this->get_title())
  1197. {
  1198. $url .= '&amp;h=' . rawurlencode($this->get_title());
  1199. }
  1200. return $url;
  1201. }
  1202. else
  1203. {
  1204. return false;
  1205. }
  1206. }
  1207. function add_to_reddit()
  1208. {
  1209. if ($this->get_permalink())
  1210. {
  1211. $url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
  1212. if ($this->get_title())
  1213. {
  1214. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1215. }
  1216. return $url;
  1217. }
  1218. else
  1219. {
  1220. return false;
  1221. }
  1222. }
  1223. function add_to_segnalo()
  1224. {
  1225. if ($this->get_permalink())
  1226. {
  1227. $url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
  1228. if ($this->get_title())
  1229. {
  1230. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1231. }
  1232. return $url;
  1233. }
  1234. else
  1235. {
  1236. return false;
  1237. }
  1238. }
  1239. function add_to_simpy()
  1240. {
  1241. if ($this->get_permalink())
  1242. {
  1243. $url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
  1244. if ($this->get_title())
  1245. {
  1246. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1247. }
  1248. return $url;
  1249. }
  1250. else
  1251. {
  1252. return false;
  1253. }
  1254. }
  1255. function add_to_smarking()
  1256. {
  1257. if ($this->get_permalink())
  1258. {
  1259. return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
  1260. }
  1261. else
  1262. {
  1263. return false;
  1264. }
  1265. }
  1266. function add_to_spurl()
  1267. {
  1268. if ($this->get_permalink())
  1269. {
  1270. $url = 'http://www.spurl.net/spurl.php?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1271. if ($this->get_title())
  1272. {
  1273. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1274. }
  1275. return $url;
  1276. }
  1277. else
  1278. {
  1279. return false;
  1280. }
  1281. }
  1282. function add_to_wists()
  1283. {
  1284. if ($this->get_permalink())
  1285. {
  1286. $url = 'http://wists.com/r.php?c=&amp;r=' . rawurlencode($this->get_permalink());
  1287. if ($this->get_title())
  1288. {
  1289. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1290. }
  1291. return $url;
  1292. }
  1293. else
  1294. {
  1295. return false;
  1296. }
  1297. }
  1298. function search_technorati()
  1299. {
  1300. if ($this->get_permalink())
  1301. {
  1302. return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
  1303. }
  1304. else
  1305. {
  1306. return false;
  1307. }
  1308. }
  1309. }
  1310. class SimplePie_Author
  1311. {
  1312. var $name;
  1313. var $link;
  1314. var $email;
  1315. // Constructor, used to input the data
  1316. function SimplePie_Author($name, $link, $email) {
  1317. $this->name = $name;
  1318. $this->link = $link;
  1319. $this->email = $email;
  1320. }
  1321. function get_name() {
  1322. return (empty($this->name)) ? false : $this->name;
  1323. }
  1324. function get_link() {
  1325. return (empty($this->link)) ? false : $this->link;
  1326. }
  1327. function get_email() {
  1328. return (empty($this->email)) ? false : $this->email;
  1329. }
  1330. }
  1331. class SimplePie_Enclosure
  1332. {
  1333. var $link;
  1334. var $type;
  1335. var $length;
  1336. // Constructor, used to input the data
  1337. function SimplePie_Enclosure($link, $type, $length) {
  1338. $this->link = $link;
  1339. $this->type = $type;
  1340. $this->length = $length;
  1341. }
  1342. function get_link() {
  1343. return (empty($this->link)) ? false : $this->link;
  1344. }
  1345. function get_extension() {
  1346. if (!empty($this->link)) {
  1347. return pathinfo($this->link, PATHINFO_EXTENSION);
  1348. } else {
  1349. return false;
  1350. }
  1351. }
  1352. function get_type() {
  1353. return (empty($this->type)) ? false : $this->type;
  1354. }
  1355. function get_length() {
  1356. return (empty($this->length)) ? false : $this->length;
  1357. }
  1358. function get_size() {
  1359. return (empty($this->length)) ? false : round(($this->length/1048576), 2);
  1360. }
  1361. function embed($options) {
  1362. // Set up defaults
  1363. $audio='';
  1364. $video='';
  1365. $alt='';
  1366. $altclass='';
  1367. $loop='false';
  1368. $width='auto';
  1369. $height='auto';
  1370. $bgcolor='#ffffff';
  1371. $embed='';
  1372. // Process options and reassign values as necessary
  1373. $options = explode(',', $options);
  1374. foreach($options as $option) {
  1375. $opt = explode(':', trim($option));
  1376. if ($opt[0] == 'audio') $audio=$opt[1];
  1377. else if ($opt[0] == 'video') $video=$opt[1];
  1378. else if ($opt[0] == 'alt') $alt=$opt[1];
  1379. else if ($opt[0] == 'altclass') $altclass=$opt[1];
  1380. else if ($opt[0] == 'loop') $loop=$opt[1];
  1381. else if ($opt[0] == 'width') $width=$opt[1];
  1382. else if ($opt[0] == 'height') $height=$opt[1];
  1383. else if ($opt[0] == 'bgcolor') $bgcolor=$opt[1];
  1384. }
  1385. // Process values for 'auto'
  1386. if ($width == 'auto') {
  1387. if (stristr($this->type, 'audio/')) $width='100%';
  1388. else if (stristr($this->type, 'video/')) $width='320';
  1389. else $width='100%';
  1390. }
  1391. if ($height == 'auto') {
  1392. if (stristr($this->type, 'audio/')) $height=0;
  1393. else if (stristr($this->type, 'video/')) $height=240;
  1394. else $height=256;
  1395. }
  1396. // Set proper placeholder value
  1397. if (stristr($this->type, 'audio/')) $placeholder=$audio;
  1398. else if (stristr($this->type, 'video/')) $placeholder=$video;
  1399. // Make sure the JS library is included
  1400. // (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
  1401. $embed.='<script type="text/javascript" src="?js"></script>';
  1402. // Odeo Feed MP3's
  1403. if (substr(strtolower($this->link), 0, 15) == 'http://odeo.com') {
  1404. $embed.='<script type="text/javascript">embed_odeo("'.$this->link.'");</script>';
  1405. }
  1406. // QuickTime 7 file types. Need to test with QuickTime 6.
  1407. else if ($this->type == 'audio/3gpp' || $this->type == 'audio/3gpp2' || $this->type == 'audio/aac' || $this->type == 'audio/x-aac' || $this->type == 'audio/aiff' || $this->type == 'audio/x-aiff' || $this->type == 'audio/mid' || $this->type == 'audio/midi' || $this->type == 'audio/x-midi' || $this->type == 'audio/mpeg' || $this->type == 'audio/x-mpeg' || $this->type == 'audio/mp3' || $this->type == 'x-audio/mp3' || $this->type == 'audio/mp4' || $this->type == 'audio/m4a' || $this->type == 'audio/x-m4a' || $this->type == 'audio/wav' || $this->type == 'audio/x-wav' || $this->type == 'video/3gpp' || $this->type == 'video/3gpp2' || $this->type == 'video/m4v' || $this->type == 'video/x-m4v' || $this->type == 'video/mp4' || $this->type == 'video/mpeg' || $this->type == 'video/x-mpeg' || $this->type == 'video/quicktime' || $this->type == 'video/sd-video') {
  1408. $height+=16;
  1409. $embed.='<script type="text/javascript">embed_quicktime("'.$this->type.'", "'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$placeholder.'", "'.$loop.'");</script>';
  1410. }
  1411. // Flash
  1412. else if ($this->type == 'application/x-shockwave-flash' || $this->type == 'application/futuresplash') {
  1413. $embed.='<script type="text/javascript">embed_flash("'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$loop.'", "'.$this->type.'");</script>';
  1414. }
  1415. // Windows Media
  1416. else if ($this->type == 'application/asx' || $this->type == 'application/x-mplayer2' || $this->type == 'audio/x-ms-wma' || $this->type == 'audio/x-ms-wax' || $this->type == 'video/x-ms-asf-plugin' || $this->type == 'video/x-ms-asf' || $this->type == 'video/x-ms-wm' || $this->type == 'video/x-ms-wmv' || $this->type == 'video/x-ms-wvx') {
  1417. $height+=45;
  1418. $embed.='<script type="text/javascript">embed_wmedia("'.$width.'", "'.$height.'", "'.$this->link.'");</script>';
  1419. }
  1420. // Everything else
  1421. else $embed.='<a href="' . $this->link . '" class="' . $altclass . '">' . $alt . '</a>';
  1422. return $embed;
  1423. }
  1424. }
  1425. class SimplePie_File
  1426. {
  1427. var $url;
  1428. var $useragent;
  1429. var $success = true;
  1430. var $headers = array();
  1431. var $body;
  1432. var $fp;
  1433. var $redirects = 0;
  1434. function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null)
  1435. {
  1436. if (class_exists('idna_convert'))
  1437. {
  1438. $idn = new idna_convert;
  1439. $url = $idn->encode($url);
  1440. }
  1441. $this->url = $url;
  1442. $this->useragent = $useragent;
  1443. if (preg_match('/^http(s)?:\/\//i', $url))
  1444. {
  1445. if (empty($useragent))
  1446. {
  1447. $useragent = ini_get('user_agent');
  1448. $this->useragent = $useragent;
  1449. }
  1450. if (!is_array($headers))
  1451. {
  1452. $headers = array();
  1453. }
  1454. if (extension_loaded('curl'))
  1455. {
  1456. $headers2 = array();
  1457. foreach ($headers as $key => $value)
  1458. {
  1459. $headers2[] = "$key: $value";
  1460. }
  1461. $fp = curl_init();
  1462. curl_setopt($fp, CURLOPT_URL, $url);
  1463. curl_setopt($fp, CURLOPT_HEADER, 1);
  1464. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  1465. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  1466. curl_setopt($fp, CURLOPT_REFERER, $url);
  1467. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  1468. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  1469. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  1470. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  1471. $this->headers = trim(curl_exec($fp));
  1472. if (curl_errno($fp))
  1473. {
  1474. $this->success = false;
  1475. return false;
  1476. }
  1477. else
  1478. {
  1479. $info = curl_getinfo($fp);
  1480. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
  1481. $this->body = array_pop($this->headers);
  1482. $this->headers = array_pop($this->headers);
  1483. $this->headers = $this->parse_headers($this->headers);
  1484. }
  1485. }
  1486. else
  1487. {
  1488. $url_parts = parse_url($url);
  1489. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
  1490. {
  1491. $url_parts['host'] = "ssl://$url_parts[host]";
  1492. $url_parts['port'] = 443;
  1493. }
  1494. if (!isset($url_parts['port']))
  1495. {
  1496. $url_parts['port'] = 80;
  1497. }
  1498. $this->fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
  1499. if (!$this->fp)
  1500. {
  1501. $this->success = false;
  1502. return false;
  1503. }
  1504. else
  1505. {
  1506. stream_set_timeout($this->fp, $timeout);
  1507. $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
  1508. $out = "GET $get HTTP/1.0\r\n";
  1509. $out .= "Host: $url_parts[host]\r\n";
  1510. $out .= "User-Agent: $useragent\r\n";
  1511. if (!empty($url_parts['user']) && !empty($url_parts['pass']))
  1512. {
  1513. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  1514. }
  1515. foreach ($headers as $key => $value)
  1516. {
  1517. $out .= "$key: $value\r\n";
  1518. }
  1519. $out .= "Connection: Close\r\n\r\n";
  1520. fwrite($this->fp, $out);
  1521. $info = stream_get_meta_data($this->fp);
  1522. $data = '';
  1523. while (strpos($data, "\r\n\r\n") === false && $info['timed_out'] === false)
  1524. {
  1525. $data .= fgets($this->fp, 128);
  1526. $info = stream_get_meta_data($this->fp);
  1527. }
  1528. if ($info['timed_out'] === false)
  1529. {
  1530. $this->headers = $this->parse_headers($data);
  1531. if (($this->headers['status']['code'] == 301 || $this->headers['status']['code'] == 302 || $this->headers['status']['code'] == 303 || $this->headers['status']['code'] == 307) && !empty($this->headers['location']) && $this->redirects < $redirects)
  1532. {
  1533. $this->redirects++;
  1534. return $this->__construct($this->headers['location'], $timeout, $redirects, $headers, $useragent);
  1535. }
  1536. }
  1537. else
  1538. {
  1539. $this->close();
  1540. $this->success = false;
  1541. return false;
  1542. }
  1543. }
  1544. }
  1545. return $this->headers['status']['code'];
  1546. }
  1547. else
  1548. {
  1549. if ($this->fp = fopen($url, 'r'))
  1550. {
  1551. return true;
  1552. }
  1553. else
  1554. {
  1555. $this->success = false;
  1556. return false;
  1557. }
  1558. }
  1559. }
  1560. function headers()
  1561. {
  1562. return $this->headers;
  1563. }
  1564. function body()
  1565. {
  1566. if (is_null($this->body))
  1567. {
  1568. if ($this->fp)
  1569. {
  1570. $this->body = '';
  1571. while (!feof($this->fp))
  1572. {
  1573. $this->body .= fread($this->fp, 1024);
  1574. }
  1575. $this->body = trim($this->body);
  1576. $this->close();
  1577. }
  1578. else
  1579. {
  1580. return false;
  1581. }
  1582. }
  1583. return $this->body;
  1584. }
  1585. function close()
  1586. {
  1587. if (!is_null($this->fp))
  1588. {
  1589. if (fclose($this->fp))
  1590. {
  1591. $this->fp = null;
  1592. return true;
  1593. }
  1594. else
  1595. {
  1596. return false;
  1597. }
  1598. }
  1599. else
  1600. {
  1601. return false;
  1602. }
  1603. }
  1604. function parse_headers($headers)
  1605. {
  1606. $headers = explode("\r\n", trim($headers));
  1607. $status = array_shift($headers);
  1608. foreach ($headers as $header)
  1609. {
  1610. $data = explode(':', $header, 2);
  1611. $head[strtolower(trim($data[0]))] = trim($data[1]);
  1612. }
  1613. if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches))
  1614. {
  1615. if (isset($head['status']))
  1616. {
  1617. unset($head['status']);
  1618. }
  1619. $head['status']['code'] = $matches[1];
  1620. $head['status']['name'] = trim($matches[2]);
  1621. }
  1622. return $head;
  1623. }
  1624. }
  1625. class SimplePie_Cache
  1626. {
  1627. var $location;
  1628. var $filename;
  1629. var $extension;
  1630. var $name;
  1631. function SimplePie_Cache($location, $filename, $extension)
  1632. {
  1633. $this->location = $location;
  1634. $this->filename = rawurlencode($filename);
  1635. $this->extension = rawurlencode($extension);
  1636. $this->name = "$location/$this->filename.$this->extension";
  1637. }
  1638. function save($data)
  1639. {
  1640. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  1641. {
  1642. $fp = fopen($this->name, 'w');
  1643. if ($fp)
  1644. {
  1645. fwrite($fp, serialize($data));
  1646. fclose($fp);
  1647. return true;
  1648. }
  1649. }
  1650. return false;
  1651. }
  1652. function load()
  1653. {
  1654. if (file_exists($this->name) && is_readable($this->name))
  1655. {
  1656. return unserialize(file_get_contents($this->name));
  1657. }
  1658. return false;
  1659. }
  1660. function atime()
  1661. {
  1662. if (file_exists($this->name))
  1663. {
  1664. return fileatime($this->name);
  1665. }
  1666. return false;
  1667. }
  1668. function ctime()
  1669. {
  1670. if (file_exists($this->name))
  1671. {
  1672. return filectime($this->name);
  1673. }
  1674. return false;
  1675. }
  1676. function mtime()
  1677. {
  1678. if (file_exists($this->name))
  1679. {
  1680. return filemtime($this->name);
  1681. }
  1682. return false;
  1683. }
  1684. function touch()
  1685. {
  1686. if (file_exists($this->name))
  1687. {
  1688. return touch($this->name);
  1689. }
  1690. return false;
  1691. }
  1692. function unlink()
  1693. {
  1694. if (file_exists($this->name))
  1695. {
  1696. return unlink($this->name);
  1697. }
  1698. return false;
  1699. }
  1700. function clear($expire)
  1701. {
  1702. foreach (glob("$this->location/*.$this->extension") as $file)
  1703. {
  1704. if (time() - filemtime($file) > $expire)
  1705. {
  1706. unlink($file);
  1707. }
  1708. }
  1709. }
  1710. }
  1711. class SimplePie_Misc
  1712. {
  1713. function absolutize_url($href, $location)
  1714. {
  1715. $href_parts = @parse_url($href);
  1716. if (!empty($href_parts['scheme']))
  1717. {
  1718. return $href;
  1719. }
  1720. else
  1721. {
  1722. if (isset($location['host']))
  1723. {
  1724. $full_url = $location['scheme'] . '://' . $location['host'];
  1725. }
  1726. else
  1727. {
  1728. $full_url = '';
  1729. }
  1730. if (isset($location['port']))
  1731. {
  1732. $full_url .= ':' . $location['port'];
  1733. }
  1734. if (!empty($href_parts['path']))
  1735. {
  1736. if (substr($href_parts['path'], 0, 1) == '/')
  1737. {
  1738. $full_url .= $href_parts['path'];
  1739. }
  1740. else if (!empty($location['path']))
  1741. {
  1742. $full_url .= dirname($location['path'] . 'a') . '/' . $href_parts['path'];
  1743. }
  1744. else
  1745. {
  1746. $full_url .= $href_parts['path'];
  1747. }
  1748. }
  1749. else if (!empty($location['path']))
  1750. {
  1751. $full_url .= $location['path'];
  1752. }
  1753. else
  1754. {
  1755. $full_url .= '/';
  1756. }
  1757. if (!empty($href_parts['query']))
  1758. {
  1759. $full_url .= '?' . $href_parts['query'];
  1760. }
  1761. else if (!empty($location['query']))
  1762. {
  1763. $full_url .= '?' . $location['query'];
  1764. }
  1765. if (!empty($href_parts['fragment']))
  1766. {
  1767. $full_url .= '#' . $href_parts['fragment'];
  1768. }
  1769. else if (!empty($location['fragment']))
  1770. {
  1771. $full_url .= '#' . $location['fragment'];
  1772. }
  1773. return $full_url;
  1774. }
  1775. }
  1776. function get_element($realname, $string)
  1777. {
  1778. $return = array();
  1779. $name = preg_quote($realname, '/');
  1780. preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*(\/>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
  1781. for ($i = 0; $i < count($matches); $i++)
  1782. {
  1783. $return[$i]['tag'] = $realname;
  1784. $return[$i]['full'] = $matches[$i][0];
  1785. if (strlen($matches[$i][10]) == 2)
  1786. {
  1787. $return[$i]['self_closing'] = true;
  1788. }
  1789. else
  1790. {
  1791. $return[$i]['self_closing'] = false;
  1792. $return[$i]['content'] = $matches[$i][11];
  1793. }
  1794. $return[$i]['attribs'] = array();
  1795. if (!empty($matches[$i][2]))
  1796. {
  1797. preg_match_all('/\s((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', " $matches[$i][2] ", $attribs, PREG_SET_ORDER);
  1798. for ($j = 0; $j < count($attribs); $j++)
  1799. {
  1800. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
  1801. $first = substr($attribs[$j][2], 0, 1);
  1802. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
  1803. }
  1804. }
  1805. }
  1806. return $return;
  1807. }
  1808. function element_implode($element)
  1809. {
  1810. $full = "<$element[tag]";
  1811. foreach ($element['attribs'] as $key => $value)
  1812. {
  1813. $key = strtolower($key);
  1814. $full .= " $key=$value[split]$value[data]$value[split]";
  1815. }
  1816. if ($element['self_closing'])
  1817. {
  1818. $full .= ' />';
  1819. }
  1820. else
  1821. {
  1822. $full .= ">$element[content]</$element[tag]>";
  1823. }
  1824. return $full;
  1825. }
  1826. function error($message, $level, $file, $line)
  1827. {
  1828. switch ($level)
  1829. {
  1830. case E_USER_ERROR:
  1831. $note = 'PHP Error';
  1832. break;
  1833. case E_USER_WARNING:
  1834. $note = 'PHP Warning';
  1835. break;
  1836. case E_USER_NOTICE:
  1837. $note = 'PHP Notice';
  1838. break;
  1839. default:
  1840. $note = 'Unknown Error';
  1841. break;
  1842. }
  1843. error_log("$note: $message in $file on line $line", 0);
  1844. return $message;
  1845. }
  1846. function display_file($url, $timeout = 10, $useragent = null)
  1847. {
  1848. $file = new SimplePie_File($url, $timeout, 5, null, $useragent);
  1849. $headers = $file->headers();
  1850. if ($file->body() !== false)
  1851. {
  1852. header('Content-type: ' . $headers['content-type']);
  1853. echo $file->body();
  1854. exit;
  1855. }
  1856. }
  1857. /****************************************************
  1858. FIX PROTOCOL
  1859. Convert feed:// and no-protocol URL's to http://
  1860. Feed is allowed to have no protocol. Local files are toggled in init().
  1861. This is an internal function and is not intended to be used publically.
  1862. $http=1, http://www.domain.com/feed.xml (absolute)
  1863. $http=2, feed://www.domain.com/feed.xml (absolute)
  1864. $http=3, podcast://www.domain.com/feed.xml (absolute)
  1865. ****************************************************/
  1866. function fix_protocol($url, $http = 1)
  1867. {
  1868. $url = preg_replace('/^http:\/\/photocast.mac.com/i', 'http://web.mac.com', $url);
  1869. $url = preg_replace('/^(p(od)?cast|feed)[:]?[\/]*(http(s)?:\/\/)?/i', 'http://', $url);
  1870. //$url = preg_replace('/^(.*)(s)?:\/\//i', 'http\\2://', $url);
  1871. if ($http != 1 && strstr($url, 'http://'))
  1872. {
  1873. if ($http == 2)
  1874. {
  1875. $url = substr_replace($url, 'feed', 0, 4);
  1876. }
  1877. else if ($http == 3)
  1878. {
  1879. $url = substr_replace($url, 'podcast', 0, 4);
  1880. }
  1881. }
  1882. return $url;
  1883. }
  1884. function encoding($encoding)
  1885. {
  1886. $return['use_mbstring'] = false;
  1887. $return['use_iconv'] = false;
  1888. switch (strtolower($encoding))
  1889. {
  1890. // 7bit
  1891. case '7bit':
  1892. case '7-bit':
  1893. $return['encoding'] = '7bit';
  1894. $return['use_mbstring'] = true;
  1895. break;
  1896. // 8bit
  1897. case '8bit':
  1898. case '8-bit':
  1899. $return['encoding'] = '8bit';
  1900. $return['use_mbstring'] = true;
  1901. break;
  1902. // ARMSCII-8
  1903. case 'armscii-8':
  1904. case 'armscii':
  1905. $return['encoding'] = 'ARMSCII-8';
  1906. $return['use_iconv'] = true;
  1907. break;
  1908. // ASCII
  1909. case 'us-ascii':
  1910. case 'ascii':
  1911. $return['encoding'] = 'US-ASCII';
  1912. $return['use_iconv'] = true;
  1913. $return['use_mbstring'] = true;
  1914. break;
  1915. // BASE64
  1916. case 'base64':
  1917. case 'base-64':
  1918. $return['encoding'] = 'BASE64';
  1919. $return['use_mbstring'] = true;
  1920. break;
  1921. // Big5 - Traditional Chinese, mainly used in Taiwan
  1922. case 'big5':
  1923. case '950':
  1924. $return['encoding'] = 'BIG5';
  1925. $return['use_iconv'] = true;
  1926. $return['use_mbstring'] = true;
  1927. break;
  1928. // Big5 with Hong Kong extensions, Traditional Chinese
  1929. case 'big5-hkscs':
  1930. $return['encoding'] = 'BIG5-HKSCS';
  1931. $return['use_iconv'] = true;
  1932. $return['use_mbstring'] = true;
  1933. break;
  1934. // byte2be
  1935. case 'byte2be':
  1936. $return['encoding'] = 'byte2be';
  1937. $return['use_mbstring'] = true;
  1938. break;
  1939. // byte2le
  1940. case 'byte2le':
  1941. $return['encoding'] = 'byte2le';
  1942. $return['use_mbstring'] = true;
  1943. break;
  1944. // byte4be
  1945. case 'byte4be':
  1946. $return['encoding'] = 'byte4be';
  1947. $return['use_mbstring'] = true;
  1948. break;
  1949. // byte4le
  1950. case 'byte4le':
  1951. $return['encoding'] = 'byte4le';
  1952. $return['use_mbstring'] = true;
  1953. break;
  1954. // EUC-CN
  1955. case 'euc-cn':
  1956. case 'euccn':
  1957. $return['encoding'] = 'EUC-CN';
  1958. $return['use_iconv'] = true;
  1959. $return['use_mbstring'] = true;
  1960. break;
  1961. // EUC-JISX0213
  1962. case 'euc-jisx0213':
  1963. case 'eucjisx0213':
  1964. $return['encoding'] = 'EUC-JISX0213';
  1965. $return['use_iconv'] = true;
  1966. break;
  1967. // EUC-JP
  1968. case 'euc-jp':
  1969. case 'eucjp':
  1970. $return['encoding'] = 'EUC-JP';
  1971. $return['use_iconv'] = true;
  1972. $return['use_mbstring'] = true;
  1973. break;
  1974. // EUCJP-win
  1975. case 'euc-jp-win':
  1976. case 'eucjp-win':
  1977. case 'eucjpwin':
  1978. $return['encoding'] = 'EUCJP-win';
  1979. $return['use_iconv'] = true;
  1980. $return['use_mbstring'] = true;
  1981. break;
  1982. // EUC-KR
  1983. case 'euc-kr':
  1984. case 'euckr':
  1985. $return['encoding'] = 'EUC-KR';
  1986. $return['use_iconv'] = true;
  1987. $return['use_mbstring'] = true;
  1988. break;
  1989. // EUC-TW
  1990. case 'euc-tw':
  1991. case 'euctw':
  1992. $return['encoding'] = 'EUC-TW';
  1993. $return['use_iconv'] = true;
  1994. $return['use_mbstring'] = true;
  1995. break;
  1996. // GB18030 - Simplified Chinese, national standard character set
  1997. case 'gb18030-2000':
  1998. case 'gb18030':
  1999. $return['encoding'] = 'GB18030';
  2000. $return['use_iconv'] = true;
  2001. break;
  2002. // GB2312 - Simplified Chinese, national standard character set
  2003. case 'gb2312':
  2004. case '936':
  2005. $return['encoding'] = 'GB2312';
  2006. $return['use_mbstring'] = true;
  2007. break;
  2008. // GBK
  2009. case 'gbk':
  2010. $return['encoding'] = 'GBK';
  2011. $return['use_iconv'] = true;
  2012. break;
  2013. // Georgian-Academy
  2014. case 'georgian-academy':
  2015. $return['encoding'] = 'Georgian-Academy';
  2016. $return['use_iconv'] = true;
  2017. break;
  2018. // Georgian-PS
  2019. case 'georgian-ps':
  2020. $return['encoding'] = 'Georgian-PS';
  2021. $return['use_iconv'] = true;
  2022. break;
  2023. // HTML-ENTITIES
  2024. case 'html-entities':
  2025. case 'htmlentities':
  2026. $return['encoding'] = 'HTML-ENTITIES';
  2027. $return['use_mbstring'] = true;
  2028. break;
  2029. // HZ
  2030. case 'hz':
  2031. $return['encoding'] = 'HZ';
  2032. $return['use_iconv'] = true;
  2033. $return['use_mbstring'] = true;
  2034. break;
  2035. // ISO-2022-CN
  2036. case 'iso-2022-cn':
  2037. case 'iso2022-cn':
  2038. case 'iso2022cn':
  2039. $return['encoding'] = 'ISO-2022-CN';
  2040. $return['use_iconv'] = true;
  2041. break;
  2042. // ISO-2022-CN-EXT
  2043. case 'iso-2022-cn-ext':
  2044. case 'iso2022-cn-ext':
  2045. case 'iso2022cn-ext':
  2046. case 'iso2022cnext':
  2047. $return['encoding'] = 'ISO-2022-CN';
  2048. $return['use_iconv'] = true;
  2049. break;
  2050. // ISO-2022-JP
  2051. case 'iso-2022-jp':
  2052. case 'iso2022-jp':
  2053. case 'iso2022jp':
  2054. $return['encoding'] = 'ISO-2022-JP';
  2055. $return['use_iconv'] = true;
  2056. $return['use_mbstring'] = true;
  2057. break;
  2058. // ISO-2022-JP-1
  2059. case 'iso-2022-jp-1':
  2060. case 'iso2022-jp-1':
  2061. case 'iso2022jp-1':
  2062. case 'iso2022jp1':
  2063. $return['encoding'] = 'ISO-2022-JP-1';
  2064. $return['use_iconv'] = true;
  2065. break;
  2066. // ISO-2022-JP-2
  2067. case 'iso-2022-jp-2':
  2068. case 'iso2022-jp-2':
  2069. case 'iso2022jp-2':
  2070. case 'iso2022jp2':
  2071. $return['encoding'] = 'ISO-2022-JP-2';
  2072. $return['use_iconv'] = true;
  2073. break;
  2074. // ISO-2022-JP-3
  2075. case 'iso-2022-jp-3':
  2076. case 'iso2022-jp-3':
  2077. case 'iso2022jp-3':
  2078. case 'iso2022jp3':
  2079. $return['encoding'] = 'ISO-2022-JP-3';
  2080. $return['use_iconv'] = true;
  2081. break;
  2082. // ISO-2022-KR
  2083. case 'iso-2022-kr':
  2084. case 'iso2022-kr':
  2085. case 'iso2022kr':
  2086. $return['encoding'] = 'ISO-2022-KR';
  2087. $return['use_iconv'] = true;
  2088. $return['use_mbstring'] = true;
  2089. break;
  2090. // ISO-8859-1
  2091. case 'iso-8859-1':
  2092. case 'iso8859-1':
  2093. $return['encoding'] = 'ISO-8859-1';
  2094. $return['use_iconv'] = true;
  2095. $return['use_mbstring'] = true;
  2096. break;
  2097. // ISO-8859-2
  2098. case 'iso-8859-2':
  2099. case 'iso8859-2':
  2100. $return['encoding'] = 'ISO-8859-2';
  2101. $return['use_iconv'] = true;
  2102. $return['use_mbstring'] = true;
  2103. break;
  2104. // ISO-8859-3
  2105. case 'iso-8859-3':
  2106. case 'iso8859-3':
  2107. $return['encoding'] = 'ISO-8859-3';
  2108. $return['use_iconv'] = true;
  2109. $return['use_mbstring'] = true;
  2110. break;
  2111. // ISO-8859-4
  2112. case 'iso-8859-4':
  2113. case 'iso8859-4':
  2114. $return['encoding'] = 'ISO-8859-4';
  2115. $return['use_iconv'] = true;
  2116. $return['use_mbstring'] = true;
  2117. break;
  2118. // ISO-8859-5
  2119. case 'iso-8859-5':
  2120. case 'iso8859-5':
  2121. $return['encoding'] = 'ISO-8859-5';
  2122. $return['use_iconv'] = true;
  2123. $return['use_mbstring'] = true;
  2124. break;
  2125. // ISO-8859-6
  2126. case 'iso-8859-6':
  2127. case 'iso8859-6':
  2128. $return['encoding'] = 'ISO-8859-6';
  2129. $return['use_iconv'] = true;
  2130. $return['use_mbstring'] = true;
  2131. break;
  2132. // ISO-8859-7
  2133. case 'iso-8859-7':
  2134. case 'iso8859-7':
  2135. $return['encoding'] = 'ISO-8859-7';
  2136. $return['use_iconv'] = true;
  2137. $return['use_mbstring'] = true;
  2138. break;
  2139. // ISO-8859-8
  2140. case 'iso-8859-8':
  2141. case 'iso8859-8':
  2142. $return['encoding'] = 'ISO-8859-8';
  2143. $return['use_iconv'] = true;
  2144. $return['use_mbstring'] = true;
  2145. break;
  2146. // ISO-8859-9
  2147. case 'iso-8859-9':
  2148. case 'iso8859-9':
  2149. $return['encoding'] = 'ISO-8859-9';
  2150. $return['use_iconv'] = true;
  2151. $return['use_mbstring'] = true;
  2152. break;
  2153. // ISO-8859-10
  2154. case 'iso-8859-10':
  2155. case 'iso8859-10':
  2156. $return['encoding'] = 'ISO-8859-10';
  2157. $return['use_iconv'] = true;
  2158. $return['use_mbstring'] = true;
  2159. break;
  2160. // mbstring/iconv functions don't appear to support 11 & 12
  2161. // ISO-8859-13
  2162. case 'iso-8859-13':
  2163. case 'iso8859-13':
  2164. $return['encoding'] = 'ISO-8859-13';
  2165. $return['use_iconv'] = true;
  2166. $return['use_mbstring'] = true;
  2167. break;
  2168. // ISO-8859-14
  2169. case 'iso-8859-14':
  2170. case 'iso8859-14':
  2171. $return['encoding'] = 'ISO-8859-14';
  2172. $return['use_iconv'] = true;
  2173. $return['use_mbstring'] = true;
  2174. break;
  2175. // ISO-8859-15
  2176. case 'iso-8859-15':
  2177. case 'iso8859-15':
  2178. $return['encoding'] = 'ISO-8859-15';
  2179. $return['use_iconv'] = true;
  2180. $return['use_mbstring'] = true;
  2181. break;
  2182. // ISO-8859-16
  2183. case 'iso-8859-16':
  2184. case 'iso8859-16':
  2185. $return['encoding'] = 'ISO-8859-16';
  2186. $return['use_iconv'] = true;
  2187. break;
  2188. // JIS
  2189. case 'jis':
  2190. $return['encoding'] = 'JIS';
  2191. $return['use_mbstring'] = true;
  2192. break;
  2193. // JOHAB - Korean
  2194. case 'johab':
  2195. $return['encoding'] = 'JOHAB';
  2196. $return['use_iconv'] = true;
  2197. break;
  2198. // Russian
  2199. case 'koi8-r':
  2200. case 'koi8r':
  2201. $return['encoding'] = 'KOI8-R';
  2202. $return['use_iconv'] = true;
  2203. $return['use_mbstring'] = true;
  2204. break;
  2205. // Turkish
  2206. case 'koi8-t':
  2207. case 'koi8t':
  2208. $return['encoding'] = 'KOI8-T';
  2209. $return['use_iconv'] = true;
  2210. break;
  2211. // Ukrainian
  2212. case 'koi8-u':
  2213. case 'koi8u':
  2214. $return['encoding'] = 'KOI8-U';
  2215. $return['use_iconv'] = true;
  2216. break;
  2217. // Russian+Ukrainian
  2218. case 'koi8-ru':
  2219. case 'koi8ru':
  2220. $return['encoding'] = 'KOI8-RU';
  2221. $return['use_iconv'] = true;
  2222. break;
  2223. // Macintosh (Mac OS Classic)
  2224. case 'macintosh':
  2225. $return['encoding'] = 'Macintosh';
  2226. $return['use_iconv'] = true;
  2227. break;
  2228. // MacArabic (Mac OS Classic)
  2229. case 'macarabic':
  2230. $return['encoding'] = 'MacArabic';
  2231. $return['use_iconv'] = true;
  2232. break;
  2233. // MacCentralEurope (Mac OS Classic)
  2234. case 'maccentraleurope':
  2235. $return['encoding'] = 'MacCentralEurope';
  2236. $return['use_iconv'] = true;
  2237. break;
  2238. // MacCroatian (Mac OS Classic)
  2239. case 'maccroatian':
  2240. $return['encoding'] = 'MacCroatian';
  2241. $return['use_iconv'] = true;
  2242. break;
  2243. // MacCyrillic (Mac OS Classic)
  2244. case 'maccyrillic':
  2245. $return['encoding'] = 'MacCyrillic';
  2246. $return['use_iconv'] = true;
  2247. break;
  2248. // MacGreek (Mac OS Classic)
  2249. case 'macgreek':
  2250. $return['encoding'] = 'MacGreek';
  2251. $return['use_iconv'] = true;
  2252. break;
  2253. // MacHebrew (Mac OS Classic)
  2254. case 'machebrew':
  2255. $return['encoding'] = 'MacHebrew';
  2256. $return['use_iconv'] = true;
  2257. break;
  2258. // MacIceland (Mac OS Classic)
  2259. case 'maciceland':
  2260. $return['encoding'] = 'MacIceland';
  2261. $return['use_iconv'] = true;
  2262. break;
  2263. // MacRoman (Mac OS Classic)
  2264. case 'macroman':
  2265. $return['encoding'] = 'MacRoman';
  2266. $return['use_iconv'] = true;
  2267. break;
  2268. // MacRomania (Mac OS Classic)
  2269. case 'macromania':
  2270. $return['encoding'] = 'MacRomania';
  2271. $return['use_iconv'] = true;
  2272. break;
  2273. // MacThai (Mac OS Classic)
  2274. case 'macthai':
  2275. $return['encoding'] = 'MacThai';
  2276. $return['use_iconv'] = true;
  2277. break;
  2278. // MacTurkish (Mac OS Classic)
  2279. case 'macturkish':
  2280. $return['encoding'] = 'MacTurkish';
  2281. $return['use_iconv'] = true;
  2282. break;
  2283. // MacUkraine (Mac OS Classic)
  2284. case 'macukraine':
  2285. $return['encoding'] = 'MacUkraine';
  2286. $return['use_iconv'] = true;
  2287. break;
  2288. // MuleLao-1
  2289. case 'mulelao-1':
  2290. case 'mulelao1':
  2291. $return['encoding'] = 'MuleLao-1';
  2292. $return['use_iconv'] = true;
  2293. break;
  2294. // Shift_JIS
  2295. case 'shift_jis':
  2296. case 'sjis':
  2297. case '932':
  2298. $return['encoding'] = 'Shift_JIS';
  2299. $return['use_iconv'] = true;
  2300. $return['use_mbstring'] = true;
  2301. break;
  2302. // Shift_JISX0213
  2303. case 'shift-jisx0213':
  2304. case 'shiftjisx0213':
  2305. $return['encoding'] = 'Shift_JISX0213';
  2306. $return['use_iconv'] = true;
  2307. break;
  2308. // SJIS-win
  2309. case 'sjis-win':
  2310. case 'sjiswin':
  2311. case 'shift_jis-win':
  2312. $return['encoding'] = 'SJIS-win';
  2313. $return['use_iconv'] = true;
  2314. $return['use_mbstring'] = true;
  2315. break;
  2316. // TCVN - Vietnamese
  2317. case 'tcvn':
  2318. $return['encoding'] = 'TCVN';
  2319. $return['use_iconv'] = true;
  2320. break;
  2321. // TDS565 - Turkish
  2322. case 'tds565':
  2323. $return['encoding'] = 'TDS565';
  2324. $return['use_iconv'] = true;
  2325. break;
  2326. // TIS-620 Thai
  2327. case 'tis-620':
  2328. case 'tis620':
  2329. $return['encoding'] = 'TIS-620';
  2330. $return['use_iconv'] = true;
  2331. $return['use_mbstring'] = true;
  2332. break;
  2333. // UCS-2
  2334. case 'ucs-2':
  2335. case 'ucs2':
  2336. case 'utf-16':
  2337. case 'utf16':
  2338. $return['encoding'] = 'UCS-2';
  2339. $return['use_iconv'] = true;
  2340. $return['use_mbstring'] = true;
  2341. break;
  2342. // UCS-2BE
  2343. case 'ucs-2be':
  2344. case 'ucs2be':
  2345. case 'utf-16be':
  2346. case 'utf16be':
  2347. $return['encoding'] = 'UCS-2BE';
  2348. $return['use_iconv'] = true;
  2349. $return['use_mbstring'] = true;
  2350. break;
  2351. // UCS-2LE
  2352. case 'ucs-2le':
  2353. case 'ucs2le':
  2354. case 'utf-16le':
  2355. case 'utf16le':
  2356. $return['encoding'] = 'UCS-2LE';
  2357. $return['use_iconv'] = true;
  2358. $return['use_mbstring'] = true;
  2359. break;
  2360. // UCS-2-INTERNAL
  2361. case 'ucs-2-internal':
  2362. case 'ucs2internal':
  2363. $return['encoding'] = 'UCS-2-INTERNAL';
  2364. $return['use_iconv'] = true;
  2365. break;
  2366. // UCS-4
  2367. case 'ucs-4':
  2368. case 'ucs4':
  2369. case 'utf-32':
  2370. case 'utf32':
  2371. $return['encoding'] = 'UCS-4';
  2372. $return['use_iconv'] = true;
  2373. $return['use_mbstring'] = true;
  2374. break;
  2375. // UCS-4BE
  2376. case 'ucs-4be':
  2377. case 'ucs4be':
  2378. case 'utf-32be':
  2379. case 'utf32be':
  2380. $return['encoding'] = 'UCS-4BE';
  2381. $return['use_iconv'] = true;
  2382. $return['use_mbstring'] = true;
  2383. break;
  2384. // UCS-4LE
  2385. case 'ucs-4le':
  2386. case 'ucs4le':
  2387. case 'utf-32le':
  2388. case 'utf32le':
  2389. $return['encoding'] = 'UCS-4LE';
  2390. $return['use_iconv'] = true;
  2391. $return['use_mbstring'] = true;
  2392. break;
  2393. // UCS-4-INTERNAL
  2394. case 'ucs-4-internal':
  2395. case 'ucs4internal':
  2396. $return['encoding'] = 'UCS-4-INTERNAL';
  2397. $return['use_iconv'] = true;
  2398. break;
  2399. // UCS-16
  2400. case 'ucs-16':
  2401. case 'ucs16':
  2402. $return['encoding'] = 'UCS-16';
  2403. $return['use_iconv'] = true;
  2404. $return['use_mbstring'] = true;
  2405. break;
  2406. // UCS-16BE
  2407. case 'ucs-16be':
  2408. case 'ucs16be':
  2409. $return['encoding'] = 'UCS-16BE';
  2410. $return['use_iconv'] = true;
  2411. $return['use_mbstring'] = true;
  2412. break;
  2413. // UCS-16LE
  2414. case 'ucs-16le':
  2415. case 'ucs16le':
  2416. $return['encoding'] = 'UCS-16LE';
  2417. $return['use_iconv'] = true;
  2418. $return['use_mbstring'] = true;
  2419. break;
  2420. // UCS-32
  2421. case 'ucs-32':
  2422. case 'ucs32':
  2423. $return['encoding'] = 'UCS-32';
  2424. $return['use_iconv'] = true;
  2425. $return['use_mbstring'] = true;
  2426. break;
  2427. // UCS-32BE
  2428. case 'ucs-32be':
  2429. case 'ucs32be':
  2430. $return['encoding'] = 'UCS-32BE';
  2431. $return['use_iconv'] = true;
  2432. $return['use_mbstring'] = true;
  2433. break;
  2434. // UCS-32LE
  2435. case 'ucs-32le':
  2436. case 'ucs32le':
  2437. $return['encoding'] = 'UCS-32LE';
  2438. $return['use_iconv'] = true;
  2439. $return['use_mbstring'] = true;
  2440. break;
  2441. // UTF-7
  2442. case 'utf-7':
  2443. case 'utf7':
  2444. $return['encoding'] = 'UTF-7';
  2445. $return['use_iconv'] = true;
  2446. $return['use_mbstring'] = true;
  2447. break;
  2448. // UTF7-IMAP
  2449. case 'utf-7-imap':
  2450. case 'utf7-imap':
  2451. case 'utf7imap':
  2452. $return['encoding'] = 'UTF7-IMAP';
  2453. $return['use_mbstring'] = true;
  2454. break;
  2455. // VISCII - Vietnamese ASCII
  2456. case 'viscii':
  2457. $return['encoding'] = 'VISCII';
  2458. $return['use_iconv'] = true;
  2459. break;
  2460. // Windows-specific Central & Eastern Europe
  2461. case 'cp1250':
  2462. case 'windows-1250':
  2463. case 'win-1250':
  2464. case '1250':
  2465. $return['encoding'] = 'Windows-1250';
  2466. $return['use_iconv'] = true;
  2467. break;
  2468. // Windows-specific Cyrillic
  2469. case 'cp1251':
  2470. case 'windows-1251':
  2471. case 'win-1251':
  2472. case '1251':
  2473. $return['encoding'] = 'Windows-1251';
  2474. $return['use_iconv'] = true;
  2475. $return['use_mbstring'] = true;
  2476. break;
  2477. // Windows-specific Western Europe
  2478. case 'cp1252':
  2479. case 'windows-1252':
  2480. case '1252':
  2481. $return['encoding'] = 'Windows-1252';
  2482. $return['use_iconv'] = true;
  2483. $return['use_mbstring'] = true;
  2484. break;
  2485. // Windows-specific Greek
  2486. case 'cp1253':
  2487. case 'windows-1253':
  2488. case '1253':
  2489. $return['encoding'] = 'Windows-1253';
  2490. $return['use_iconv'] = true;
  2491. break;
  2492. // Windows-specific Turkish
  2493. case 'cp1254':
  2494. case 'windows-1254':
  2495. case '1254':
  2496. $return['encoding'] = 'Windows-1254';
  2497. $return['use_iconv'] = true;
  2498. break;
  2499. // Windows-specific Hebrew
  2500. case 'cp1255':
  2501. case 'windows-1255':
  2502. case '1255':
  2503. $return['encoding'] = 'Windows-1255';
  2504. $return['use_iconv'] = true;
  2505. break;
  2506. // Windows-specific Arabic
  2507. case 'cp1256':
  2508. case 'windows-1256':
  2509. case '1256':
  2510. $return['encoding'] = 'Windows-1256';
  2511. $return['use_iconv'] = true;
  2512. break;
  2513. // Windows-specific Baltic
  2514. case 'cp1257':
  2515. case 'windows-1257':
  2516. case '1257':
  2517. $return['encoding'] = 'Windows-1257';
  2518. $return['use_iconv'] = true;
  2519. break;
  2520. // Windows-specific Vietnamese
  2521. case 'cp1258':
  2522. case 'windows-1258':
  2523. case '1258':
  2524. $return['encoding'] = 'Windows-1258';
  2525. $return['use_iconv'] = true;
  2526. break;
  2527. // Default to UTF-8
  2528. default:
  2529. $return['encoding'] = 'UTF-8';
  2530. break;
  2531. }
  2532. // If mb_list_encodings() exists, use that to set use_mbstring
  2533. if (function_exists('mb_list_encodings'))
  2534. {
  2535. if (in_array($return['encoding'], mb_list_encodings()))
  2536. {
  2537. $return['use_mbstring'] = true;
  2538. }
  2539. else
  2540. {
  2541. $return['use_mbstring'] = false;
  2542. }
  2543. }
  2544. // Then, return it.
  2545. return $return;
  2546. }
  2547. }
  2548. class SimplePie_Locator
  2549. {
  2550. var $useragent;
  2551. var $parsed_url;
  2552. var $file;
  2553. var $local;
  2554. var $elsewhere;
  2555. function SimplePie_Locator(&$file)
  2556. {
  2557. if (!is_a($file, 'SimplePie_File'))
  2558. {
  2559. $this->file = new SimplePie_File($file);
  2560. }
  2561. else
  2562. {
  2563. $this->file =& $file;
  2564. }
  2565. }
  2566. function find()
  2567. {
  2568. if ($this->is_feed($this->file))
  2569. {
  2570. return $this->file->url;
  2571. }
  2572. $this->useragent = $this->file->useragent;
  2573. $this->parsed_url = parse_url($this->file->url);
  2574. if (!isset($this->parsed_url['path']))
  2575. {
  2576. $this->parsed_url['path'] = '/';
  2577. }
  2578. $autodiscovery = $this->autodiscovery($this->file);
  2579. if ($autodiscovery)
  2580. {
  2581. return $autodiscovery;
  2582. }
  2583. if ($this->get_links($this->file))
  2584. {
  2585. if (!empty($this->local))
  2586. {
  2587. $extension_local = $this->extension($this->local);
  2588. if ($extension_local)
  2589. {
  2590. return $extension_local;
  2591. }
  2592. $body_local = $this->body($this->local);
  2593. if ($body_local)
  2594. {
  2595. return $body_local;
  2596. }
  2597. }
  2598. if (!empty($this->elsewhere))
  2599. {
  2600. $extension_elsewhere = $this->extension($this->elsewhere);
  2601. if ($extension_elsewhere)
  2602. {
  2603. return $extension_elsewhere;
  2604. }
  2605. $body_elsewhere = $this->body($this->elsewhere);
  2606. if ($body_elsewhere)
  2607. {
  2608. return $body_elsewhere;
  2609. }
  2610. }
  2611. }
  2612. return false;
  2613. }
  2614. function is_feed(&$file)
  2615. {
  2616. if (!is_a($file, 'SimplePie_File'))
  2617. {
  2618. $file2 = new SimplePie_File($file, 1, 5, null, $this->useragent);
  2619. $file2->body();
  2620. $file2->close();
  2621. }
  2622. else
  2623. {
  2624. $file2 =& $file;
  2625. }
  2626. if (((stristr($file2->body(), '<rss') || preg_match('/<([a-z0-9]+\:)?RDF/mi', $file2->body())) && (preg_match('/<([a-z0-9]+\:)?channel/mi', $file2->body()) || preg_match('/<([a-z0-9]+\:)?item/mi', $file2->body()))) || (preg_match('/<([a-z0-9]+\:)?feed/mi', $file2->body()) && (preg_match('/<([a-z0-9]+\:)?author/mi', $file2->body()) || preg_match('/<([a-z0-9]+\:)?entry/mi', $file2->body()))))
  2627. {
  2628. return true;
  2629. }
  2630. return false;
  2631. }
  2632. function autodiscovery(&$file)
  2633. {
  2634. $links = SimplePie_Misc::get_element('link', $file->body());
  2635. $done = array();
  2636. foreach ($links as $link)
  2637. {
  2638. if (!empty($link['attribs']['TYPE']['data']) && !empty($link['attribs']['HREF']['data']))
  2639. {
  2640. $type = strtolower(trim($link['attribs']['TYPE']['data']));
  2641. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['HREF']['data']), $this->parsed_url);
  2642. if (!in_array($href, $done) && in_array($type, array('application/rss+xml', 'application/atom+xml', 'application/rdf+xml', 'application/xml+rss', 'application/xml+atom', 'application/xml+rdf', 'application/xml', 'application/x.atom+xml', 'text/xml')))
  2643. {
  2644. $feed = $this->is_feed($href);
  2645. if ($feed)
  2646. {
  2647. return $href;
  2648. }
  2649. }
  2650. $done[] = $href;
  2651. }
  2652. }
  2653. return false;
  2654. }
  2655. function get_links(&$file)
  2656. {
  2657. $links = SimplePie_Misc::get_element('a', $file->body());
  2658. foreach ($links as $link)
  2659. {
  2660. if (!empty($link['attribs']['HREF']['data']))
  2661. {
  2662. $href = trim($link['attribs']['HREF']['data']);
  2663. $parsed = @parse_url($href);
  2664. if (empty($parsed['scheme']) || $parsed['scheme'] != 'javascript')
  2665. {
  2666. if (empty($parsed['host']) || $parsed['host'] == $this->parsed_url['host'])
  2667. {
  2668. $this->local[] = SimplePie_Misc::absolutize_url($href, $this->parsed_url);
  2669. }
  2670. else
  2671. {
  2672. $this->elsewhere[] = SimplePie_Misc::absolutize_url($href, $this->parsed_url);
  2673. }
  2674. }
  2675. }
  2676. }
  2677. if (!empty($this->local))
  2678. {
  2679. $this->local = array_unique($this->local);
  2680. }
  2681. if (!empty($this->elsewhere))
  2682. {
  2683. $this->elsewhere = array_unique($this->elsewhere);
  2684. }
  2685. if (!empty($this->local) || !empty($this->elsewhere))
  2686. {
  2687. return true;
  2688. }
  2689. return false;
  2690. }
  2691. function extension(&$array)
  2692. {
  2693. foreach ($array as $key => $value)
  2694. {
  2695. $value = SimplePie_Misc::absolutize_url($value, $this->parsed_url);
  2696. if (in_array(strrchr($value, '.'), array('.rss', '.rdf', '.atom', '.xml')))
  2697. {
  2698. if ($this->is_feed($value))
  2699. {
  2700. return $value;
  2701. }
  2702. else
  2703. {
  2704. unset($array[$key]);
  2705. }
  2706. }
  2707. }
  2708. return false;
  2709. }
  2710. function body(&$array)
  2711. {
  2712. foreach ($array as $key => $value)
  2713. {
  2714. $value = SimplePie_Misc::absolutize_url($value, $this->parsed_url);
  2715. if (preg_match('/(rss|rdf|atom|xml)/i', $value))
  2716. {
  2717. if ($this->is_feed($value))
  2718. {
  2719. return $value;
  2720. }
  2721. else
  2722. {
  2723. unset($array[$key]);
  2724. }
  2725. }
  2726. }
  2727. return false;
  2728. }
  2729. }
  2730. class SimplePie_Parser
  2731. {
  2732. var $encoding;
  2733. var $data;
  2734. var $namespaces = array('xml' => 'HTTP://WWW.W3.ORG/XML/1998/NAMESPACE', 'atom' => 'ATOM', 'rss2' => 'RSS', 'rdf' => 'RDF', 'rss1' => 'RSS', 'dc' => 'DC', 'xhtml' => 'XHTML', 'content' => 'CONTENT');
  2735. var $xml;
  2736. var $error_code;
  2737. var $error_string;
  2738. var $current_line;
  2739. var $current_column;
  2740. var $current_byte;
  2741. var $tag_name;
  2742. var $inside_item;
  2743. var $item_number = 0;
  2744. var $inside_channel;
  2745. var $author_number= 0;
  2746. var $category_number = 0;
  2747. var $enclosure_number = 0;
  2748. var $link_number = 0;
  2749. var $item_link_number = 0;
  2750. var $inside_image;
  2751. var $attribs;
  2752. var $is_first;
  2753. var $inside_author;
  2754. function SimplePie_Parser($data, $encoding, $return_xml = false)
  2755. {
  2756. $this->encoding = $encoding;
  2757. // Strip BOM:
  2758. // UTF-32 Big Endian BOM
  2759. if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
  2760. {
  2761. $data = substr($data, 4);
  2762. }
  2763. // UTF-32 Little Endian BOM
  2764. else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
  2765. {
  2766. $data = substr($data, 4);
  2767. }
  2768. // UTF-16 Big Endian BOM
  2769. else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
  2770. {
  2771. $data = substr($data, 2);
  2772. }
  2773. // UTF-16 Little Endian BOM
  2774. else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
  2775. {
  2776. $data = substr($data, 2);
  2777. }
  2778. // UTF-8 BOM
  2779. else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
  2780. {
  2781. $data = substr($data, 3);
  2782. }
  2783. // Make sure the XML prolog is sane and has the correct encoding
  2784. if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog))
  2785. {
  2786. $data = substr_replace($data, '', 0, strlen($prolog[0]));
  2787. }
  2788. $data = "<?xml version='1.0' encoding='$encoding'?>\n" . $data;
  2789. // Add an internal attribute to CDATA sections
  2790. $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'))*)\s*(\/>|>\s*<\!\[CDATA\[(.*)<\/\\1>)/msiU', array(&$this, 'spencoded'), $data);
  2791. // Put some data into CDATA blocks
  2792. // If we're RSS
  2793. if ((stristr($data, '<rss') || preg_match('/<([a-z0-9]+\:)?RDF/mi', $data)) && (preg_match('/<([a-z0-9]+\:)?channel/mi', $data) || preg_match('/<([a-z0-9]+\:)?item/mi', $data)))
  2794. {
  2795. $sp_elements = array(
  2796. 'author',
  2797. 'description',
  2798. 'link',
  2799. 'title',
  2800. );
  2801. }
  2802. // Or if we're Atom
  2803. else
  2804. {
  2805. $sp_elements = array(
  2806. 'content',
  2807. 'copyright',
  2808. 'name',
  2809. 'subtitle',
  2810. 'summary',
  2811. 'tagline',
  2812. 'title',
  2813. );
  2814. }
  2815. foreach ($sp_elements as $full)
  2816. {
  2817. $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|>(.*)<\/$full>)/msiU", array(&$this, 'add_cdata'), $data);
  2818. }
  2819. foreach ($sp_elements as $full)
  2820. {
  2821. // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above)
  2822. $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|><!\[CDATA\[(.*)\]\]><\/$full>)/msiU", array(&$this, 'cdata_in_cdata'), $data);
  2823. }
  2824. // Return the XML, if so desired
  2825. if ($return_xml)
  2826. {
  2827. $this->data =& $data;
  2828. return;
  2829. }
  2830. // Create the parser
  2831. $this->xml = xml_parser_create_ns($encoding);
  2832. xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1);
  2833. xml_set_object($this->xml, $this);
  2834. xml_set_character_data_handler($this->xml, 'data_handler');
  2835. xml_set_element_handler($this->xml, 'start_handler', 'end_handler');
  2836. xml_set_start_namespace_decl_handler($this->xml, 'start_name_space');
  2837. xml_set_end_namespace_decl_handler($this->xml, 'end_name_space');
  2838. // Parse!
  2839. if (!xml_parse($this->xml, $data))
  2840. {
  2841. $this->data = null;
  2842. $this->error_code = xml_get_error_code($this->xml);
  2843. $this->error_string = xml_error_string($this->error_code);
  2844. }
  2845. $this->current_line = xml_get_current_line_number($this->xml);
  2846. $this->current_column = xml_get_current_column_number($this->xml);
  2847. $this->current_byte = xml_get_current_byte_index($this->xml);
  2848. xml_parser_free($this->xml);
  2849. return;
  2850. }
  2851. function add_cdata($match)
  2852. {
  2853. if (isset($match[10]))
  2854. {
  2855. $match[10] = preg_replace('/^\s*<\!\[CDATA\[/msiU', '', $match[10]);
  2856. $match[10] = preg_replace('/]]>\s*$/msiU', '', $match[10]);
  2857. return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
  2858. }
  2859. return $match[0];
  2860. }
  2861. function spencoded($match)
  2862. {
  2863. if (isset($match[10]))
  2864. {
  2865. return "<$match[1]$match[2] spencoded=\"false\"><![CDATA[$match[10]</$match[1]>";
  2866. }
  2867. return $match[0];
  2868. }
  2869. function cdata_in_cdata($match)
  2870. {
  2871. if (isset($match[10]))
  2872. {
  2873. $match[10] = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/msiU', array(&$this, 'real_cdata_in_cdata'), $match[10]);
  2874. return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
  2875. }
  2876. return $match[0];
  2877. }
  2878. function real_cdata_in_cdata($match)
  2879. {
  2880. return htmlentities($match[1], ENT_NOQUOTES, $this->encoding);
  2881. }
  2882. function do_add_content(&$array, $data)
  2883. {
  2884. if ($this->is_first)
  2885. {
  2886. $array['data'] = $data;
  2887. $array['attribs'] = $this->attribs;
  2888. }
  2889. else
  2890. {
  2891. $array['data'] .= $data;
  2892. }
  2893. }
  2894. function start_handler($parser, $name, $attribs)
  2895. {
  2896. $this->tag_name = $name;
  2897. $this->attribs = $attribs;
  2898. $this->is_first = true;
  2899. switch ($this->tag_name)
  2900. {
  2901. case 'ITEM':
  2902. case $this->namespaces['rss2'] . ':ITEM':
  2903. case $this->namespaces['rss1'] . ':ITEM':
  2904. case 'ENTRY':
  2905. case $this->namespaces['atom'] . ':ENTRY':
  2906. $this->inside_item = true;
  2907. $this->do_add_content($this->data['items'][$this->item_number], '');
  2908. break;
  2909. case 'CHANNEL':
  2910. case $this->namespaces['rss2'] . ':CHANNEL':
  2911. case $this->namespaces['rss1'] . ':CHANNEL':
  2912. $this->inside_channel = true;
  2913. break;
  2914. case 'RSS':
  2915. case $this->namespaces['rss2'] . ':RSS':
  2916. $this->data['feedinfo']['type'] = 'RSS';
  2917. $this->do_add_content($this->data['feeddata'], '');
  2918. if (!empty($attribs['VERSION']))
  2919. {
  2920. $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
  2921. }
  2922. break;
  2923. case $this->namespaces['rdf'] . ':RDF':
  2924. $this->data['feedinfo']['type'] = 'RSS';
  2925. $this->do_add_content($this->data['feeddata'], '');
  2926. $this->data['feedinfo']['version'] = 1;
  2927. break;
  2928. case 'FEED':
  2929. case $this->namespaces['atom'] . ':FEED':
  2930. $this->data['feedinfo']['type'] = 'Atom';
  2931. $this->do_add_content($this->data['feeddata'], '');
  2932. if (!empty($attribs['VERSION']))
  2933. {
  2934. $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
  2935. }
  2936. break;
  2937. case 'IMAGE':
  2938. case $this->namespaces['rss2'] . ':IMAGE':
  2939. case $this->namespaces['rss1'] . ':IMAGE':
  2940. if ($this->inside_channel)
  2941. {
  2942. $this->inside_image = true;
  2943. }
  2944. break;
  2945. }
  2946. if (!empty($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom' && ($this->tag_name == 'AUTHOR' || $this->tag_name == $this->namespaces['atom'] . ':AUTHOR'))
  2947. {
  2948. $this->inside_author = true;
  2949. }
  2950. $this->data_handler($this->xml, '');
  2951. }
  2952. function data_handler($parser, $data)
  2953. {
  2954. if ($this->inside_item)
  2955. {
  2956. switch ($this->tag_name)
  2957. {
  2958. case 'TITLE':
  2959. case $this->namespaces['rss1'] . ':TITLE':
  2960. case $this->namespaces['rss2'] . ':TITLE':
  2961. case $this->namespaces['atom'] . ':TITLE':
  2962. $this->do_add_content($this->data['items'][$this->item_number]['title'], $data);
  2963. break;
  2964. case $this->namespaces['dc'] . ':TITLE':
  2965. $this->do_add_content($this->data['items'][$this->item_number]['dc:title'], $data);
  2966. break;
  2967. case 'CONTENT':
  2968. case $this->namespaces['atom'] . ':CONTENT':
  2969. $this->do_add_content($this->data['items'][$this->item_number]['content'], $data);
  2970. break;
  2971. case $this->namespaces['content'] . ':ENCODED':
  2972. $this->do_add_content($this->data['items'][$this->item_number]['encoded'], $data);
  2973. break;
  2974. case 'SUMMARY':
  2975. case $this->namespaces['atom'] . ':SUMMARY':
  2976. $this->do_add_content($this->data['items'][$this->item_number]['summary'], $data);
  2977. break;
  2978. case 'LONGDESC':
  2979. $this->do_add_content($this->data['items'][$this->item_number]['longdesc'], $data);
  2980. break;
  2981. case 'DESCRIPTION':
  2982. case $this->namespaces['rss1'] . ':DESCRIPTION':
  2983. case $this->namespaces['rss2'] . ':DESCRIPTION':
  2984. $this->do_add_content($this->data['items'][$this->item_number]['description'], $data);
  2985. break;
  2986. case $this->namespaces['dc'] . ':DESCRIPTION':
  2987. $this->do_add_content($this->data['items'][$this->item_number]['dc:description'], $data);
  2988. break;
  2989. case 'LINK':
  2990. case $this->namespaces['rss1'] . ':LINK':
  2991. case $this->namespaces['rss2'] . ':LINK':
  2992. case $this->namespaces['atom'] . ':LINK':
  2993. $this->do_add_content($this->data['items'][$this->item_number]['link'][$this->item_link_number], $data);
  2994. break;
  2995. case 'ENCLOSURE':
  2996. case $this->namespaces['rss1'] . ':ENCLOSURE':
  2997. case $this->namespaces['rss2'] . ':ENCLOSURE':
  2998. case $this->namespaces['atom'] . ':ENCLOSURE':
  2999. $this->do_add_content($this->data['items'][$this->item_number]['enclosure'][$this->enclosure_number], $data);
  3000. break;
  3001. case 'GUID':
  3002. case $this->namespaces['rss1'] . ':GUID':
  3003. case $this->namespaces['rss2'] . ':GUID':
  3004. $this->do_add_content($this->data['items'][$this->item_number]['guid'], $data);
  3005. break;
  3006. case 'ID':
  3007. case $this->namespaces['atom'] . ':ID':
  3008. $this->do_add_content($this->data['items'][$this->item_number]['id'], $data);
  3009. break;
  3010. case 'PUBDATE':
  3011. case $this->namespaces['rss1'] . ':PUBDATE':
  3012. case $this->namespaces['rss2'] . ':PUBDATE':
  3013. $this->do_add_content($this->data['items'][$this->item_number]['pubdate'], $data);
  3014. break;
  3015. case $this->namespaces['dc'] . ':DATE':
  3016. $this->do_add_content($this->data['items'][$this->item_number]['dc:date'], $data);
  3017. break;
  3018. case 'ISSUED':
  3019. case $this->namespaces['atom'] . ':ISSUED':
  3020. $this->do_add_content($this->data['items'][$this->item_number]['issued'], $data);
  3021. break;
  3022. case 'PUBLISHED':
  3023. case $this->namespaces['atom'] . ':PUBLISHED':
  3024. $this->do_add_content($this->data['items'][$this->item_number]['published'], $data);
  3025. break;
  3026. case 'MODIFIED':
  3027. case $this->namespaces['atom'] . ':MODIFIED':
  3028. $this->do_add_content($this->data['items'][$this->item_number]['modified'], $data);
  3029. break;
  3030. case 'UPDATED':
  3031. case $this->namespaces['atom'] . ':UPDATED':
  3032. $this->do_add_content($this->data['items'][$this->item_number]['updated'], $data);
  3033. break;
  3034. case 'CATEGORY':
  3035. case $this->namespaces['rss1'] . ':CATEGORY':
  3036. case $this->namespaces['rss2'] . ':CATEGORY':
  3037. case $this->namespaces['atom'] . ':CATEGORY':
  3038. $this->do_add_content($this->data['items'][$this->item_number]['category'][$this->category_number], $data);
  3039. break;
  3040. case $this->namespaces['dc'] . ':SUBJECT':
  3041. $this->do_add_content($this->data['items'][$this->item_number]['subject'][$this->category_number], $data);
  3042. break;
  3043. case $this->namespaces['dc'] . ':CREATOR':
  3044. $this->do_add_content($this->data['items'][$this->item_number]['creator'][$this->author_number], $data);
  3045. break;
  3046. case 'AUTHOR':
  3047. case $this->namespaces['rss1'] . ':AUTHOR':
  3048. case $this->namespaces['rss2'] . ':AUTHOR':
  3049. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['rss'], $data);
  3050. break;
  3051. }
  3052. if ($this->inside_author)
  3053. {
  3054. switch ($this->tag_name)
  3055. {
  3056. case 'NAME':
  3057. case $this->namespaces['atom'] . ':NAME':
  3058. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['name'], $data);
  3059. break;
  3060. case 'URL':
  3061. case $this->namespaces['atom'] . ':URL':
  3062. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['url'], $data);
  3063. break;
  3064. case 'URI':
  3065. case $this->namespaces['atom'] . ':URI':
  3066. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['uri'], $data);
  3067. break;
  3068. case 'HOMEPAGE':
  3069. case $this->namespaces['atom'] . ':HOMEPAGE':
  3070. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['homepage'], $data);
  3071. break;
  3072. case 'EMAIL':
  3073. case $this->namespaces['atom'] . ':EMAIL':
  3074. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['email'], $data);
  3075. break;
  3076. }
  3077. }
  3078. }
  3079. else if (($this->inside_channel && !$this->inside_image) || (isset($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom'))
  3080. {
  3081. switch ($this->tag_name)
  3082. {
  3083. case 'TITLE':
  3084. case $this->namespaces['rss1'] . ':TITLE':
  3085. case $this->namespaces['rss2'] . ':TITLE':
  3086. case $this->namespaces['atom'] . ':TITLE':
  3087. $this->do_add_content($this->data['info']['title'], $data);
  3088. break;
  3089. case 'LINK':
  3090. case $this->namespaces['rss1'] . ':LINK':
  3091. case $this->namespaces['rss2'] . ':LINK':
  3092. case $this->namespaces['atom'] . ':LINK':
  3093. $this->do_add_content($this->data['info']['link'][$this->link_number], $data);
  3094. break;
  3095. case 'DESCRIPTION':
  3096. case $this->namespaces['rss1'] . ':DESCRIPTION':
  3097. case $this->namespaces['rss2'] . ':DESCRIPTION':
  3098. $this->do_add_content($this->data['info']['description'], $data);
  3099. break;
  3100. case $this->namespaces['dc'] . ':DESCRIPTION':
  3101. $this->do_add_content($this->data['info']['dc:description'], $data);
  3102. break;
  3103. case 'TAGLINE':
  3104. case $this->namespaces['atom'] . ':TAGLINE':
  3105. $this->do_add_content($this->data['info']['tagline'], $data);
  3106. break;
  3107. case 'SUBTITLE':
  3108. case $this->namespaces['atom'] . ':SUBTITLE':
  3109. $this->do_add_content($this->data['info']['subtitle'], $data);
  3110. break;
  3111. case 'COPYRIGHT':
  3112. case $this->namespaces['rss1'] . ':COPYRIGHT':
  3113. case $this->namespaces['rss2'] . ':COPYRIGHT':
  3114. case $this->namespaces['atom'] . ':COPYRIGHT':
  3115. $this->do_add_content($this->data['info']['copyright'], $data);
  3116. break;
  3117. case 'LANGUAGE':
  3118. case $this->namespaces['rss1'] . ':LANGUAGE':
  3119. case $this->namespaces['rss2'] . ':LANGUAGE':
  3120. $this->do_add_content($this->data['info']['language'], $data);
  3121. break;
  3122. case 'LOGO':
  3123. case $this->namespaces['atom'] . ':LOGO':
  3124. $this->do_add_content($this->data['info']['logo'], $data);
  3125. break;
  3126. }
  3127. }
  3128. else if ($this->inside_channel && $this->inside_image)
  3129. {
  3130. switch ($this->tag_name)
  3131. {
  3132. case 'TITLE':
  3133. case $this->namespaces['rss1'] . ':TITLE':
  3134. case $this->namespaces['rss2'] . ':TITLE':
  3135. $this->do_add_content($this->data['info']['image']['title'], $data);
  3136. break;
  3137. case 'URL':
  3138. case $this->namespaces['rss1'] . ':URL':
  3139. case $this->namespaces['rss2'] . ':URL':
  3140. $this->do_add_content($this->data['info']['image']['url'], $data);
  3141. break;
  3142. case 'LINK':
  3143. case $this->namespaces['rss1'] . ':LINK':
  3144. case $this->namespaces['rss2'] . ':LINK':
  3145. $this->do_add_content($this->data['info']['image']['link'], $data);
  3146. break;
  3147. case 'WIDTH':
  3148. case $this->namespaces['rss1'] . ':WIDTH':
  3149. case $this->namespaces['rss2'] . ':WIDTH':
  3150. $this->do_add_content($this->data['info']['image']['width'], $data);
  3151. break;
  3152. case 'HEIGHT':
  3153. case $this->namespaces['rss1'] . ':HEIGHT':
  3154. case $this->namespaces['rss2'] . ':HEIGHT':
  3155. $this->do_add_content($this->data['info']['image']['height'], $data);
  3156. break;
  3157. }
  3158. }
  3159. $this->is_first = false;
  3160. }
  3161. function end_handler($parser, $name)
  3162. {
  3163. $this->tag_name = '';
  3164. switch ($name)
  3165. {
  3166. case 'ITEM':
  3167. case $this->namespaces['rss1'] . ':ITEM':
  3168. case $this->namespaces['rss2'] . ':ITEM':
  3169. case 'ENTRY':
  3170. case $this->namespaces['atom'] . ':ENTRY':
  3171. $this->inside_item = false;
  3172. $this->item_number++;
  3173. $this->author_number = 0;
  3174. $this->category_number = 0;
  3175. $this->enclosure_number = 0;
  3176. $this->item_link_number = 0;
  3177. break;
  3178. case 'CHANNEL':
  3179. case $this->namespaces['rss1'] . ':CHANNEL':
  3180. case $this->namespaces['rss2'] . ':CHANNEL':
  3181. $this->inside_channel = false;
  3182. break;
  3183. case 'IMAGE':
  3184. case $this->namespaces['rss1'] . ':IMAGE':
  3185. case $this->namespaces['rss2'] . ':IMAGE':
  3186. $this->inside_image = false;
  3187. break;
  3188. case 'AUTHOR':
  3189. case $this->namespaces['rss1'] . ':AUTHOR':
  3190. case $this->namespaces['rss2'] . ':AUTHOR':
  3191. case $this->namespaces['atom'] . ':AUTHOR':
  3192. $this->author_number++;
  3193. $this->inside_author = false;
  3194. break;
  3195. case 'CATEGORY':
  3196. case $this->namespaces['rss1'] . ':CATEGORY':
  3197. case $this->namespaces['rss2'] . ':CATEGORY':
  3198. case $this->namespaces['atom'] . ':CATEGORY':
  3199. case $this->namespaces['dc'] . ':SUBJECT':
  3200. $this->category_number++;
  3201. break;
  3202. case 'ENCLOSURE':
  3203. case $this->namespaces['rss1'] . ':ENCLOSURE':
  3204. case $this->namespaces['rss2'] . ':ENCLOSURE':
  3205. $this->enclosure_number++;
  3206. break;
  3207. case 'LINK':
  3208. case $this->namespaces['rss1'] . ':LINK':
  3209. case $this->namespaces['rss2'] . ':LINK':
  3210. case $this->namespaces['atom'] . ':LINK':
  3211. if ($this->inside_item)
  3212. {
  3213. $this->item_link_number++;
  3214. }
  3215. else
  3216. {
  3217. $this->link_number++;
  3218. }
  3219. break;
  3220. }
  3221. }
  3222. function start_name_space($parser, $prefix, $uri = null)
  3223. {
  3224. $prefix = strtoupper($prefix);
  3225. $uri = strtoupper($uri);
  3226. if ($prefix == 'ATOM' || $uri == 'HTTP://WWW.W3.ORG/2005/ATOM' || $uri == 'HTTP://PURL.ORG/ATOM/NS#')
  3227. {
  3228. $this->namespaces['atom'] = $uri;
  3229. }
  3230. else if ($prefix == 'RSS2' || $uri == 'HTTP://BACKEND.USERLAND.COM/RSS2')
  3231. {
  3232. $this->namespaces['rss2'] = $uri;
  3233. }
  3234. else if ($prefix == 'RDF' || $uri == 'HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#')
  3235. {
  3236. $this->namespaces['rdf'] = $uri;
  3237. }
  3238. else if ($prefix == 'RSS' || $uri == 'HTTP://PURL.ORG/RSS/1.0/' || $uri == 'HTTP://MY.NETSCAPE.COM/RDF/SIMPLE/0.9/')
  3239. {
  3240. $this->namespaces['rss1'] = $uri;
  3241. }
  3242. else if ($prefix == 'DC' || $uri == 'HTTP://PURL.ORG/DC/ELEMENTS/1.1/')
  3243. {
  3244. $this->namespaces['dc'] = $uri;
  3245. }
  3246. else if ($prefix == 'XHTML' || $uri == 'HTTP://WWW.W3.ORG/1999/XHTML')
  3247. {
  3248. $this->namespaces['xhtml'] = $uri;
  3249. $this->xhtml_prefix = $prefix;
  3250. }
  3251. else if ($prefix == 'CONTENT' || $uri == 'HTTP://PURL.ORG/RSS/1.0/MODULES/CONTENT/')
  3252. {
  3253. $this->namespaces['content'] = $uri;
  3254. }
  3255. }
  3256. function end_name_space($parser, $prefix)
  3257. {
  3258. if ($key = array_search(strtoupper($prefix), $this->namespaces))
  3259. {
  3260. if ($key == 'atom')
  3261. {
  3262. $this->namespaces['atom'] = 'ATOM';
  3263. }
  3264. else if ($key == 'rss2')
  3265. {
  3266. $this->namespaces['rss2'] = 'RSS';
  3267. }
  3268. else if ($key == 'rdf')
  3269. {
  3270. $this->namespaces['rdf'] = 'RDF';
  3271. }
  3272. else if ($key == 'rss1')
  3273. {
  3274. $this->namespaces['rss1'] = 'RSS';
  3275. }
  3276. else if ($key == 'dc')
  3277. {
  3278. $this->namespaces['dc'] = 'DC';
  3279. }
  3280. else if ($key == 'xhtml')
  3281. {
  3282. $this->namespaces['xhtml'] = 'XHTML';
  3283. $this->xhtml_prefix = 'XHTML';
  3284. }
  3285. else if ($key == 'content')
  3286. {
  3287. $this->namespaces['content'] = 'CONTENT';
  3288. }
  3289. }
  3290. }
  3291. }
  3292. class SimplePie_Sanitize
  3293. {
  3294. // Private vars
  3295. var $feedinfo;
  3296. var $info;
  3297. var $items;
  3298. var $feed_xmlbase;
  3299. var $item_xmlbase;
  3300. var $attribs;
  3301. // Options
  3302. var $remove_div = true;
  3303. var $strip_ads = true;
  3304. var $replace_headers = false;
  3305. var $bypass_image_hotlink = 'i';
  3306. var $bypass_image_hotlink_page = false;
  3307. var $strip_htmltags = array('blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  3308. var $encode_instead_of_strip = false;
  3309. var $strip_attributes = array('class', 'id', 'style', 'onclick', 'onmouseover', 'onmouseout', 'onfocus', 'onblur');
  3310. function remove_div($enable = true)
  3311. {
  3312. $this->remove_div = (bool) $enable;
  3313. }
  3314. function strip_ads($enable = true)
  3315. {
  3316. $this->strip_ads = (bool) $enable;
  3317. }
  3318. function replace_headers($enable = false)
  3319. {
  3320. $this->enable_headers = (bool) $enable;
  3321. }
  3322. function bypass_image_hotlink($get = 'i')
  3323. {
  3324. if ($get)
  3325. {
  3326. $this->bypass_image_hotlink = (string) $get;
  3327. }
  3328. else
  3329. {
  3330. $this->bypass_image_hotlink = false;
  3331. }
  3332. }
  3333. function bypass_image_hotlink_page($page = false)
  3334. {
  3335. if ($page)
  3336. {
  3337. $this->bypass_image_hotlink_page = (string) $page;
  3338. }
  3339. else
  3340. {
  3341. $this->bypass_image_hotlink_page = false;
  3342. }
  3343. }
  3344. function strip_htmltags($tags = array('blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
  3345. {
  3346. if ($tags)
  3347. {
  3348. if (is_array($tags))
  3349. {
  3350. $this->strip_htmltags = $tags;
  3351. }
  3352. else
  3353. {
  3354. $this->strip_htmltags = explode(',', $tags);
  3355. }
  3356. }
  3357. else
  3358. {
  3359. $this->strip_htmltags = false;
  3360. }
  3361. }
  3362. function encode_instead_of_strip($enable = false)
  3363. {
  3364. $this->encode_instead_of_strip = (bool) $enable;
  3365. }
  3366. function strip_attributes($attribs = array('class', 'id', 'style', 'onclick', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
  3367. {
  3368. if ($attribs)
  3369. {
  3370. if (is_array($attribs))
  3371. {
  3372. $this->strip_attributes = $attribs;
  3373. }
  3374. else
  3375. {
  3376. $this->strip_attributes = explode(',', $attribs);
  3377. }
  3378. }
  3379. else
  3380. {
  3381. $this->strip_attributes = false;
  3382. }
  3383. }
  3384. function parse_data_array(&$data)
  3385. {
  3386. // Feed Info (Type and Version)
  3387. if (!empty($data['feedinfo']['type']))
  3388. {
  3389. $this->feedinfo = $data['feedinfo'];
  3390. }
  3391. // Feed level xml:base
  3392. if (!empty($data['feeddata']['attribs']['XML:BASE']))
  3393. {
  3394. $this->feed_xmlbase = parse_url($data['feeddata']['attribs']['XML:BASE']);
  3395. }
  3396. else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
  3397. {
  3398. $this->feed_xmlbase = parse_url($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']);
  3399. }
  3400. // Feed link(s)
  3401. if (!empty($data['info']['link']))
  3402. {
  3403. foreach ($data['info']['link'] as $link)
  3404. {
  3405. if (empty($link['attribs']['REL']))
  3406. {
  3407. $rel = 'alternate';
  3408. }
  3409. else
  3410. {
  3411. $rel = strtolower($link['attribs']['REL']);
  3412. }
  3413. if ($rel == 'enclosure')
  3414. {
  3415. $href = null;
  3416. $type = null;
  3417. $length = null;
  3418. if (!empty($link['data']))
  3419. {
  3420. $href = $this->sanitize($link['data'], $link['attribs'], true);
  3421. }
  3422. else if (!empty($link['attribs']['HREF']))
  3423. {
  3424. $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3425. }
  3426. if (!empty($link['attribs']['TYPE'])) {
  3427. $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
  3428. }
  3429. if (!empty($link['attribs']['LENGTH'])) {
  3430. $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
  3431. }
  3432. $this->info['link']['enclosure'][] = new SimplePie_Enclosure($href, $type, $length);
  3433. }
  3434. else
  3435. {
  3436. if (!empty($link['data']))
  3437. {
  3438. $this->info['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
  3439. }
  3440. else if (!empty($link['attribs']['HREF']))
  3441. {
  3442. $this->info['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3443. }
  3444. }
  3445. }
  3446. }
  3447. // Use the first alternate link if we don't have any feed xml:base
  3448. if (empty($this->feed_xmlbase) && !empty($this->info['link']['alternate'][0]))
  3449. {
  3450. $this->feed_xmlbase = parse_url($this->info['link']['alternate'][0]);
  3451. }
  3452. // Feed Title
  3453. if (!empty($data['info']['title']['data']))
  3454. {
  3455. $this->info['title'] = $this->sanitize($data['info']['title']['data'], $data['info']['title']['attribs']);
  3456. }
  3457. // Feed Descriptions
  3458. if (!empty($data['info']['description']['data']))
  3459. {
  3460. $this->info['description'] = $this->sanitize($data['info']['description']['data'], $data['info']['description']['attribs']);
  3461. }
  3462. if (!empty($data['info']['dc:description']['data']))
  3463. {
  3464. $this->info['dc:description'] = $this->sanitize($data['info']['dc:description']['data'], $data['info']['dc:description']['attribs']);
  3465. }
  3466. if (!empty($data['info']['tagline']['data']))
  3467. {
  3468. $this->info['tagline'] = $this->sanitize($data['info']['tagline']['data'], $data['info']['tagline']['attribs']);
  3469. }
  3470. if (!empty($data['info']['subtitle']['data']))
  3471. {
  3472. $this->info['subtitle'] = $this->sanitize($data['info']['subtitle']['data'], $data['info']['subtitle']['attribs']);
  3473. }
  3474. // Feed Language
  3475. if (!empty($data['info']['language']['data']))
  3476. {
  3477. $this->info['language'] = $this->sanitize($data['info']['language']['data'], $data['info']['language']['attribs']);
  3478. }
  3479. if (!empty($data['feeddata']['attribs']['XML:LANG']))
  3480. {
  3481. $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['XML:LANG'], null);
  3482. }
  3483. else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG']))
  3484. {
  3485. $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'], null);
  3486. }
  3487. // Feed Copyright
  3488. if (!empty($data['info']['copyright']['data']))
  3489. {
  3490. $this->info['copyright'] = $this->sanitize($data['info']['copyright']['data'], $data['info']['copyright']['attribs']);
  3491. }
  3492. // Feed Image
  3493. if (!empty($data['info']['image']['title']['data']))
  3494. {
  3495. $this->info['image']['title'] = $this->sanitize($data['info']['image']['title']['data'], $data['info']['image']['title']['attribs']);
  3496. }
  3497. if (!empty($data['info']['image']['url']['data']))
  3498. {
  3499. $this->info['image']['url'] = $this->sanitize($data['info']['image']['url']['data'], $data['info']['image']['url']['attribs'], true);
  3500. }
  3501. if (!empty($data['info']['logo']['data']))
  3502. {
  3503. $this->info['image']['logo'] = $this->sanitize($data['info']['logo']['data'], $data['info']['logo']['attribs'], true);
  3504. }
  3505. if (!empty($data['info']['image']['link']['data']))
  3506. {
  3507. $this->info['image']['link'] = $this->sanitize($data['info']['image']['link']['data'], $data['info']['image']['link']['attribs'], true);
  3508. }
  3509. if (!empty($data['info']['image']['width']['data']))
  3510. {
  3511. $this->info['image']['width'] = $this->sanitize($data['info']['image']['width']['data'], $data['info']['image']['width']['attribs']);
  3512. }
  3513. if (!empty($data['info']['image']['height']['data']))
  3514. {
  3515. $this->info['image']['height'] = $this->sanitize($data['info']['image']['height']['data'], $data['info']['image']['height']['attribs']);
  3516. }
  3517. // Items
  3518. if (!empty($data['items']))
  3519. {
  3520. foreach ($data['items'] as $key => $item)
  3521. {
  3522. $newitem = null;
  3523. // Item level xml:base
  3524. if (!empty($item['attribs']['XML:BASE']))
  3525. {
  3526. $this->item_xmlbase = parse_url(SimplePie_Misc::absolutize_url($item['attribs']['XML:BASE'], $this->feed_xmlbase));
  3527. }
  3528. else if (!empty($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
  3529. {
  3530. $this->item_xmlbase = parse_url(SimplePie_Misc::absolutize_url($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'], $this->feed_xmlbase));
  3531. }
  3532. else
  3533. {
  3534. $this->item_xmlbase = null;
  3535. }
  3536. // Title
  3537. if (!empty($item['title']['data'])) {
  3538. $newitem['title'] = $this->sanitize($item['title']['data'], $item['title']['attribs']);
  3539. }
  3540. if (!empty($item['dc:title']['data']))
  3541. {
  3542. $newitem['dc:title'] = $this->sanitize($item['dc:title']['data'], $item['dc:title']['attribs']);
  3543. }
  3544. // Description
  3545. if (!empty($item['content']['data']))
  3546. {
  3547. $newitem['content'] = $this->sanitize($item['content']['data'], $item['content']['attribs']);
  3548. }
  3549. if (!empty($item['encoded']['data']))
  3550. {
  3551. $newitem['encoded'] = $this->sanitize($item['encoded']['data'], $item['encoded']['attribs']);
  3552. }
  3553. if (!empty($item['summary']['data']))
  3554. {
  3555. $newitem['summary'] = $this->sanitize($item['summary']['data'], $item['summary']['attribs']);
  3556. }
  3557. if (!empty($item['description']['data']))
  3558. {
  3559. $newitem['description'] = $this->sanitize($item['description']['data'], $item['description']['attribs']);
  3560. }
  3561. if (!empty($item['dc:description']['data']))
  3562. {
  3563. $newitem['dc:description'] = $this->sanitize($item['dc:description']['data'], $item['dc:description']['attribs']);
  3564. }
  3565. if (!empty($item['longdesc']['data']))
  3566. {
  3567. $newitem['longdesc'] = $this->sanitize($item['longdesc']['data'], $item['longdesc']['attribs']);
  3568. }
  3569. // Link(s)
  3570. if (!empty($item['link']))
  3571. {
  3572. foreach ($item['link'] as $link)
  3573. {
  3574. if (empty($link['attribs']['REL']))
  3575. {
  3576. $rel = 'alternate';
  3577. }
  3578. else
  3579. {
  3580. $rel = strtolower($link['attribs']['REL']);
  3581. }
  3582. if ($rel == 'enclosure')
  3583. {
  3584. $href = null;
  3585. $type = null;
  3586. $length = null;
  3587. if (!empty($link['data']))
  3588. {
  3589. $href = $this->sanitize($link['data'], $link['attribs'], true);
  3590. }
  3591. else if (!empty($link['attribs']['HREF']))
  3592. {
  3593. $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3594. }
  3595. if (!empty($link['attribs']['TYPE'])) {
  3596. $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
  3597. }
  3598. if (!empty($link['attribs']['LENGTH'])) {
  3599. $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
  3600. }
  3601. if (!empty($href))
  3602. {
  3603. $newitem['link'][$rel][] = new SimplePie_Enclosure($href, $type, $length);
  3604. }
  3605. }
  3606. else
  3607. {
  3608. if (!empty($link['data']))
  3609. {
  3610. $newitem['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
  3611. }
  3612. else if (!empty($link['attribs']['HREF']))
  3613. {
  3614. $newitem['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3615. }
  3616. }
  3617. }
  3618. }
  3619. // Enclosure(s)
  3620. if (!empty($item['enclosure']))
  3621. {
  3622. foreach ($item['enclosure'] as $enclosure)
  3623. {
  3624. if (!empty($enclosure['attribs']['URL']))
  3625. {
  3626. $type = null;
  3627. $length = null;
  3628. $href = $this->sanitize($enclosure['attribs']['URL'], $enclosure['attribs'], true);
  3629. if (!empty($enclosure['attribs']['TYPE']))
  3630. {
  3631. $type = $this->sanitize($enclosure['attribs']['TYPE'], $enclosure['attribs']);
  3632. }
  3633. if (!empty($enclosure['attribs']['LENGTH']))
  3634. {
  3635. $length = $this->sanitize($enclosure['attribs']['LENGTH'], $enclosure['attribs']);
  3636. }
  3637. $newitem['enclosures'][] = new SimplePie_Enclosure($href, $type, $length);
  3638. }
  3639. }
  3640. }
  3641. // ID
  3642. if (!empty($item['guid']['data']))
  3643. {
  3644. if (!empty($item['guid']['attribs']['ISPERMALINK']) && strtolower($item['guid']['attribs']['ISPERMALINK']) == 'false')
  3645. {
  3646. $newitem['guid']['permalink'] = false;
  3647. }
  3648. else
  3649. {
  3650. $newitem['guid']['permalink'] = true;
  3651. }
  3652. $newitem['guid']['data'] = $this->sanitize($item['guid']['data'], $item['guid']['attribs']);
  3653. }
  3654. if (!empty($item['id']['data']))
  3655. {
  3656. $newitem['id'] = $this->sanitize($item['id']['data'], $item['id']['attribs']);
  3657. }
  3658. // Date
  3659. if (!empty($item['pubdate']['data']))
  3660. {
  3661. $newitem['pubdate'] = $this->parse_date($this->sanitize($item['pubdate']['data'], $item['pubdate']['attribs']));
  3662. }
  3663. if (!empty($item['dc:date']['data']))
  3664. {
  3665. $newitem['dc:date'] = $this->parse_date($this->sanitize($item['dc:date']['data'], $item['dc:date']['attribs']));
  3666. }
  3667. if (!empty($item['issued']['data']))
  3668. {
  3669. $newitem['issued'] = $this->parse_date($this->sanitize($item['issued']['data'], $item['issued']['attribs']));
  3670. }
  3671. if (!empty($item['published']['data']))
  3672. {
  3673. $newitem['published'] = $this->parse_date($this->sanitize($item['published']['data'], $item['published']['attribs']));
  3674. }
  3675. if (!empty($item['modified']['data']))
  3676. {
  3677. $newitem['modified'] = $this->parse_date($this->sanitize($item['modified']['data'], $item['modified']['attribs']));
  3678. }
  3679. if (!empty($item['updated']['data']))
  3680. {
  3681. $newitem['updated'] = $this->parse_date($this->sanitize($item['updated']['data'], $item['updated']['attribs']));
  3682. }
  3683. // Categories
  3684. if (!empty($item['category']))
  3685. {
  3686. foreach ($item['category'] as $category)
  3687. {
  3688. if (!empty($category['data']))
  3689. {
  3690. $newitem['category'][] = $this->sanitize($category['data'], $category['attribs']);
  3691. }
  3692. }
  3693. }
  3694. if (!empty($item['subject']))
  3695. {
  3696. foreach ($item['subject'] as $category)
  3697. {
  3698. if (!empty($category['data']))
  3699. {
  3700. $newitem['subject'][] = $this->sanitize($category['data'], $category['attribs']);
  3701. }
  3702. }
  3703. }
  3704. // Author
  3705. if (!empty($item['creator']))
  3706. {
  3707. foreach ($item['creator'] as $creator)
  3708. {
  3709. if (!empty($creator['data']))
  3710. {
  3711. $newitem['creator'][] = new SimplePie_Author($this->sanitize($creator['data'], $creator['attribs']), null, null);
  3712. }
  3713. }
  3714. }
  3715. if (!empty($item['author']))
  3716. {
  3717. foreach ($item['author'] as $author)
  3718. {
  3719. $name = null;
  3720. $link = null;
  3721. $email = null;
  3722. if (!empty($author['rss']))
  3723. {
  3724. $sane = $this->sanitize($author['rss']['data'], $author['rss']['attribs']);
  3725. if (preg_match('/(.*)@(.*) \((.*)\)/msiU', $sane, $matches)) {
  3726. $name = trim($matches[3]);
  3727. $email = trim("$matches[1]@$matches[2]");
  3728. } else {
  3729. $email = $sane;
  3730. }
  3731. }
  3732. else
  3733. {
  3734. if (!empty($author['name']))
  3735. {
  3736. $name = $this->sanitize($author['name']['data'], $author['name']['attribs']);
  3737. }
  3738. if (!empty($author['url']))
  3739. {
  3740. $link = $this->sanitize($author['url']['data'], $author['url']['attribs'], true);
  3741. }
  3742. else if (!empty($author['uri']))
  3743. {
  3744. $link = $this->sanitize($author['uri']['data'], $author['uri']['attribs'], true);
  3745. }
  3746. else if (!empty($author['homepage']))
  3747. {
  3748. $link = $this->sanitize($author['homepage']['data'], $author['homepage']['attribs'], true);
  3749. }
  3750. if (!empty($author['email'])) {
  3751. $email = $this->sanitize($author['email']['data'], $author['email']['attribs']);
  3752. }
  3753. }
  3754. $newitem['author'][] = new SimplePie_Author($name, $link, $email);
  3755. }
  3756. }
  3757. unset($data['items'][$key]);
  3758. $this->items[] = new SimplePie_Item($newitem);
  3759. }
  3760. }
  3761. }
  3762. function sanitize($data, $attribs, $is_url = false)
  3763. {
  3764. $this->attribs = $attribs;
  3765. if (isset($this->feedinfo['type']) && $this->feedinfo['type'] == 'Atom')
  3766. {
  3767. if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'base64') || (!empty($attribs['TYPE']) && $attribs['TYPE'] == 'application/octet-stream'))
  3768. {
  3769. $data = trim($data);
  3770. $data = base64_decode($data);
  3771. }
  3772. else if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'escaped' || !empty($attribs['TYPE']) && ($attribs['TYPE'] == 'html' || $attribs['TYPE'] == 'text/html')) && (empty($attribs['SPENCODED']) || $attribs['SPENCODED'] != 'false'))
  3773. {
  3774. $data = $this->entities_decode($data);
  3775. }
  3776. if (!empty($attribs['TYPE']) && ($attribs['TYPE'] == 'xhtml' || $attribs['TYPE'] == 'application/xhtml+xml'))
  3777. {
  3778. if ($this->remove_div)
  3779. {
  3780. $data = preg_replace('/<div( .*)?>/msiU', '', strrev(preg_replace('/>vid\/</i', '', strrev($data), 1)), 1);
  3781. }
  3782. else
  3783. {
  3784. $data = preg_replace('/<div( .*)?>/msiU', '<div>', $data, 1);
  3785. }
  3786. }
  3787. }
  3788. else
  3789. {
  3790. if (empty($attribs['SPENCODED']) || $attribs['SPENCODED'] != 'false')
  3791. {
  3792. $data = $this->entities_decode($data);
  3793. }
  3794. }
  3795. $data = trim($data);
  3796. $data = str_replace(' spencoded="false">', '>', $data);
  3797. // If Strip Ads is enabled, strip them.
  3798. if ($this->strip_ads)
  3799. {
  3800. $data = preg_replace('/<a (.*)href=(.*)click\.phdo\?s=(.*)<\/a>/msiU', '', $data); // Pheedo links (tested with Dooce.com)
  3801. $data = preg_replace('/<p(.*)>(.*)<a href="http:\/\/ad.doubleclick.net\/jump\/(.*)<\/p>/msiU', '', $data); // Doubleclick links (tested with InfoWorld.com)
  3802. $data = preg_replace('/<p><map (.*)name=(.*)google_ad_map(.*)<\/p>/msiU', '', $data); // Google AdSense for Feeds (tested with tuaw.com).
  3803. // Feedflare, from Feedburner
  3804. }
  3805. // Replace H1, H2, and H3 tags with the less important H4 tags.
  3806. // This is because on a site, the more important headers might make sense,
  3807. // but it most likely doesn't fit in the context of RSS-in-a-webpage.
  3808. if ($this->replace_headers)
  3809. {
  3810. $data = preg_replace('/<h[1-3]((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*>/msiU', '<h4\\1>', $data);
  3811. $data = preg_replace('/<\/h[1-3]>/i', '</h4>', $data);
  3812. }
  3813. if ($is_url)
  3814. {
  3815. $data = $this->replace_urls($data, true);
  3816. }
  3817. else
  3818. {
  3819. $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*(\/>|>(.*)<\/\S+>)/msiU', array(&$this, 'replace_urls'), $data);
  3820. }
  3821. // If Bypass Image Hotlink is enabled, rewrite all the image tags.
  3822. if ($this->bypass_image_hotlink)
  3823. {
  3824. $images = SimplePie_Misc::get_element('img', $data);
  3825. foreach ($images as $img)
  3826. {
  3827. if (!empty($img['attribs']['SRC']['data']))
  3828. {
  3829. $pre = '';
  3830. if ($this->bypass_image_hotlink_page)
  3831. {
  3832. $pre = $this->bypass_image_hotlink_page;
  3833. }
  3834. $pre .= "?$this->bypass_image_hotlink=";
  3835. $img['attribs']['SRC']['data'] = $pre . rawurlencode(strtr($img['attribs']['SRC']['data'], array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES))));
  3836. $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
  3837. }
  3838. }
  3839. }
  3840. // Strip out HTML tags and attributes that might cause various security problems.
  3841. // Based on recommendations by Mark Pilgrim at:
  3842. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  3843. if ($this->strip_htmltags)
  3844. {
  3845. foreach ($this->strip_htmltags as $tag)
  3846. {
  3847. $data = preg_replace_callback("/<($tag)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*(\/>|>(.*)<\/$tag>)/msiU", array(&$this, 'do_strip_htmltags'), $data);
  3848. }
  3849. }
  3850. if ($this->strip_attributes)
  3851. {
  3852. foreach ($this->strip_attributes as $attrib)
  3853. {
  3854. $data = preg_replace('/ '. trim($attrib) .'=("|&quot;)(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|&apos;|<|>|\+|{|})*("|&quot;)/i', '', $data);
  3855. $data = preg_replace('/ '. trim($attrib) .'=(\'|&apos;)(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|"|&quot;|<|>|\+|{|})*(\'|&apos;)/i', '', $data);
  3856. $data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i', '', $data);
  3857. }
  3858. }
  3859. return $data;
  3860. }
  3861. function do_strip_htmltags($match)
  3862. {
  3863. if ($this->encode_instead_of_strip)
  3864. {
  3865. if (isset($match[11]))
  3866. {
  3867. return "&lt;$match[1]$match[2]&gt;$match[11]&lt;/$match[1]&gt;";
  3868. }
  3869. else
  3870. {
  3871. return "&lt;$match[1]$match[2]/&gt;";
  3872. }
  3873. }
  3874. else
  3875. {
  3876. if (isset($match[11]))
  3877. {
  3878. return $match[11];
  3879. }
  3880. else
  3881. {
  3882. return '';
  3883. }
  3884. }
  3885. }
  3886. function replace_urls($data, $raw_url = false)
  3887. {
  3888. if (!empty($this->attribs['XML:BASE']))
  3889. {
  3890. $xmlbase = $attribs['XML:BASE'];
  3891. }
  3892. else if (!empty($this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
  3893. {
  3894. $xmlbase = $this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
  3895. }
  3896. if (!empty($xmlbase))
  3897. {
  3898. if (!empty($this->item_xmlbase))
  3899. {
  3900. $xmlbase = parse_url(SimplePie_Misc::absolutize_url($xmlbase, $this->item_xmlbase));
  3901. }
  3902. else
  3903. {
  3904. $xmlbase = parse_url(SimplePie_Misc::absolutize_url($xmlbase, $this->feed_xmlbase));
  3905. }
  3906. }
  3907. else if (!empty($this->item_xmlbase))
  3908. {
  3909. $xmlbase = $this->item_xmlbase;
  3910. }
  3911. else
  3912. {
  3913. $xmlbase = $this->feed_xmlbase;
  3914. }
  3915. if ($raw_url)
  3916. {
  3917. return SimplePie_Misc::absolutize_url($data, $xmlbase);
  3918. }
  3919. else
  3920. {
  3921. $attributes = array(
  3922. 'background',
  3923. 'href',
  3924. 'src',
  3925. 'longdesc',
  3926. 'usemap',
  3927. 'codebase',
  3928. 'data',
  3929. 'classid',
  3930. 'cite',
  3931. 'action',
  3932. 'profile',
  3933. 'for'
  3934. );
  3935. foreach ($attributes as $attribute)
  3936. {
  3937. if (preg_match("/$attribute='(.*)'/siU", $data[0], $attrib) || preg_match("/$attribute=\"(.*)\"/siU", $data[0], $attrib) || preg_match("/$attribute=(.*)[ |\/|>]/siU", $data[0], $attrib))
  3938. {
  3939. $new_tag = str_replace($attrib[1], SimplePie_Misc::absolutize_url($attrib[1], $xmlbase), $attrib[0]);
  3940. $data[0] = str_replace($attrib[0], $new_tag, $data[0]);
  3941. }
  3942. }
  3943. return $data[0];
  3944. }
  3945. }
  3946. function entities_decode($data) {
  3947. return preg_replace_callback('/&(#)?(x)?([0-9a-z]+);/mi', array(&$this, 'do_entites_decode'), $data);
  3948. }
  3949. function do_entites_decode($data)
  3950. {
  3951. $entity_html = utf8_encode(html_entity_decode($data[0], ENT_QUOTES));
  3952. if ($data[0] == $entity_html) {
  3953. return preg_replace_callback('/&#([0-9a-fx]+);/mi', array(&$this, 'replace_num_entity'), $data[0]);
  3954. } else {
  3955. return $entity_html;
  3956. }
  3957. }
  3958. /*
  3959. * Escape numeric entities
  3960. * From a PHP Manual note (on html_entity_decode())
  3961. * Copyright (c) 2005 by "php dot net at c dash ovidiu dot tk",
  3962. * "emilianomartinezluque at yahoo dot com" and "hurricane at cyberworldz dot org".
  3963. *
  3964. * This material may be distributed only subject to the terms and conditions set forth in
  3965. * the Open Publication License, v1.0 or later (the latest version is presently available at
  3966. * http://www.opencontent.org/openpub/).
  3967. */
  3968. function replace_num_entity($ord) {
  3969. $ord = $ord[1];
  3970. if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match))
  3971. $ord = hexdec($match[1]);
  3972. else
  3973. $ord = intval($ord);
  3974. $no_bytes = 0;
  3975. $byte = array();
  3976. if ($ord < 128)
  3977. return chr($ord);
  3978. if ($ord < 2048)
  3979. $no_bytes = 2;
  3980. else if ($ord < 65536)
  3981. $no_bytes = 3;
  3982. else if ($ord < 1114112)
  3983. $no_bytes = 4;
  3984. else return;
  3985. switch ($no_bytes) {
  3986. case 2:
  3987. $prefix = array(31, 192);
  3988. break;
  3989. case 3:
  3990. $prefix = array(15, 224);
  3991. break;
  3992. case 4:
  3993. $prefix = array(7, 240);
  3994. break;
  3995. }
  3996. for ($i=0; $i < $no_bytes; ++$i)
  3997. $byte[$no_bytes-$i-1] = (($ord & (63 * pow(2,6*$i))) / pow(2,6*$i)) & 63 | 128;
  3998. $byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
  3999. $ret = '';
  4000. for ($i=0; $i < $no_bytes; ++$i)
  4001. $ret .= chr($byte[$i]);
  4002. return $ret;
  4003. }
  4004. function parse_date($date)
  4005. {
  4006. if (preg_match('/([0-9]{2,4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(\.([0-9]{2}))?Z/i', $date, $matches))
  4007. {
  4008. if (isset($matches[8]) && $matches[8] >= 50)
  4009. {
  4010. $matches[6]++;
  4011. }
  4012. $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[6] -0000");
  4013. }
  4014. else if (preg_match('/([0-9]{2,4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2})(:([0-9]{2}))?(\.([0-9]{2}))?(\+|-)([0-9]{2}):([0-9]{2})/i', $date, $matches))
  4015. {
  4016. if (isset($matches[9]) && $matches[9] >= 50)
  4017. {
  4018. $matches[6]++;
  4019. }
  4020. if (empty($matches[7]))
  4021. {
  4022. $matches[7] = '00';
  4023. }
  4024. $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[7] $matches[10]$matches[11]$matches[12]");
  4025. }
  4026. else if (preg_match('/([0-9]{1,2})\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s*([0-9]{2}|[0-9]{4})\s*([0-9]{2}):([0-9]{2})(:([0-9]{2}))?\s*(UT|GMT|EST|EDT|CST|CDT|MST|MDT|PST|PDT|[a-z]|(\\+|-)[0-9]{4})/i', $date, $matches))
  4027. {
  4028. $three_month = array('Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
  4029. $military_timezone = array('A' => '-0100', 'B' => '-0200', 'C' => '-0300', 'D' => '-0400', 'E' => '-0500', 'F' => '-0600', 'G' => '-0700', 'H' => '-0800', 'I' => '-0900', 'K' => '-1000', 'L' => '-1100', 'M' => '-1200', 'N' => '+0100', 'O' => '+0200', 'P' => '+0300', 'Q' => '+0400', 'R' => '+0500', 'S' => '+0600', 'T' => '+0700', 'U' => '+0800', 'V' => '+0900', 'W' => '+1000', 'X' => '+1100', 'Y' => '+1200', 'Z' => '-0000');
  4030. $north_american_timezone = array('GMT' => '-0000', 'EST' => '-0500', 'EDT' => '-0400', 'CST' => '-0600', 'CDT' => '-0500', 'MST' => '-0700', 'MDT' => '-0600', 'PST' => '-0800', 'PDT' => '-0700');
  4031. $month = $three_month[$matches[2]];
  4032. if (strlen($matches[3]) == 2)
  4033. {
  4034. $year = ($matches[3] < 70) ? "20$matches[3]" : "19$matches[3]";
  4035. }
  4036. else
  4037. {
  4038. $year = $matches[3];
  4039. }
  4040. $second = (empty($matches[7])) ? '00' : $matches[7];
  4041. switch (strlen($matches[8]))
  4042. {
  4043. case 1:
  4044. $timezone = $military_timezone[strtoupper($matches[8])];
  4045. break;
  4046. case 2:
  4047. $timezone = '-0000';
  4048. break;
  4049. case 3:
  4050. $timezone = $north_american_timezone[strtoupper($matches[8])];
  4051. break;
  4052. default:
  4053. $timezone = $matches[8];
  4054. }
  4055. $date = strtotime("$year-$month-$matches[1] $matches[4]:$matches[5]:$second $timezone");
  4056. }
  4057. else
  4058. {
  4059. var_dump('else');
  4060. $tmp_date = $date; // fixed by komagata
  4061. $date = strtotime($date);
  4062. if ($date == -1) {
  4063. include_once 'Date.php';
  4064. $d =& new Date();
  4065. $d->setDate($tmp_date);
  4066. $date = $d->getDate(DATE_FORMAT_UNIXTIME);
  4067. }
  4068. }
  4069. return ($date > 0) ? $date : false;
  4070. }
  4071. }
  4072. ?>