PageRenderTime 70ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/simplepie/simplepie.test.inc

https://github.com/komagata/plnet
PHP | 4487 lines | 3815 code | 310 blank | 362 comment | 626 complexity | 553f2dddde77ba9f8e0633fb8cc1f096 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: 6 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 = '20060806';
  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', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', '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 = 0)
  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 = 0)
  910. {
  911. $categories = $this->get_categories();
  912. if (!empty($categories[$key]))
  913. {
  914. return $categories[$key];
  915. }
  916. else
  917. {
  918. return false;
  919. }
  920. }
  921. function get_categories()
  922. {
  923. $categories = array();
  924. if (!empty($this->data['category']))
  925. {
  926. $categories = array_merge($categories, $this->data['category']);
  927. }
  928. if (!empty($this->data['subject']))
  929. {
  930. $categories = array_merge($categories, $this->data['subject']);
  931. }
  932. if (!empty($categories))
  933. {
  934. return array_unique($categories);
  935. }
  936. else
  937. {
  938. return false;
  939. }
  940. }
  941. function get_author($key = 0)
  942. {
  943. $authors = $this->get_authors();
  944. if (!empty($authors[$key]))
  945. {
  946. return $authors[$key];
  947. }
  948. else
  949. {
  950. return false;
  951. }
  952. }
  953. function get_authors()
  954. {
  955. $authors = array();
  956. if (!empty($this->data['author']))
  957. {
  958. $authors = array_merge($authors, $this->data['author']);
  959. }
  960. if (!empty($this->data['creator']))
  961. {
  962. $authors = array_merge($authors, $this->data['creator']);
  963. }
  964. if (!empty($authors))
  965. {
  966. return array_unique($authors);
  967. }
  968. else
  969. {
  970. return false;
  971. }
  972. }
  973. function get_date($date_format = 'j F Y, g:i a')
  974. {
  975. if (!empty($this->data['pubdate']))
  976. {
  977. return date($date_format, $this->data['pubdate']);
  978. }
  979. else if (!empty($this->data['dc:date']))
  980. {
  981. return date($date_format, $this->data['dc:date']);
  982. }
  983. else if (!empty($this->data['issued']))
  984. {
  985. return date($date_format, $this->data['issued']);
  986. }
  987. else if (!empty($this->data['published']))
  988. {
  989. return date($date_format, $this->data['published']);
  990. }
  991. else if (!empty($this->data['modified']))
  992. {
  993. return date($date_format, $this->data['modified']);
  994. }
  995. else if (!empty($this->data['updated']))
  996. {
  997. return date($date_format, $this->data['updated']);
  998. }
  999. else
  1000. {
  1001. return false;
  1002. }
  1003. }
  1004. function get_permalink()
  1005. {
  1006. $link = $this->get_link(0);
  1007. $enclosure = $this->get_enclosure(0);
  1008. if (!empty($link))
  1009. {
  1010. return $link;
  1011. }
  1012. else if (!empty($enclosure))
  1013. {
  1014. return $enclosure->get_link();
  1015. }
  1016. else
  1017. {
  1018. return false;
  1019. }
  1020. }
  1021. function get_link($key = 0, $rel = 'alternate')
  1022. {
  1023. $links = $this->get_links($rel);
  1024. if (!empty($links[$key]))
  1025. {
  1026. return $links[$key];
  1027. }
  1028. else
  1029. {
  1030. return false;
  1031. }
  1032. }
  1033. function get_links($rel = 'alternate')
  1034. {
  1035. if (!empty($this->data['link'][$rel]))
  1036. {
  1037. return $this->data['link'][$rel];
  1038. }
  1039. else
  1040. {
  1041. return false;
  1042. }
  1043. }
  1044. function get_enclosure($key = 0)
  1045. {
  1046. $enclosures = $this->get_enclosures();
  1047. if (!empty($enclosures[$key]))
  1048. {
  1049. return $enclosures[$key];
  1050. }
  1051. else
  1052. {
  1053. return false;
  1054. }
  1055. }
  1056. function get_enclosures()
  1057. {
  1058. $enclosures = array();
  1059. $links = $this->get_links('enclosure');
  1060. if (!empty($this->data['enclosures']))
  1061. {
  1062. $enclosures = array_merge($enclosures, $this->data['enclosures']);
  1063. }
  1064. if (!empty($links))
  1065. {
  1066. $enclosures = array_merge($enclosures, $links);
  1067. }
  1068. if (!empty($enclosures))
  1069. {
  1070. return array_unique($enclosures);
  1071. }
  1072. else
  1073. {
  1074. return false;
  1075. }
  1076. }
  1077. function add_to_blinklist()
  1078. {
  1079. if ($this->get_permalink())
  1080. {
  1081. $url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=' . rawurlencode($this->get_permalink());
  1082. if ($this->get_title())
  1083. {
  1084. $url .= '&amp;Title=' . rawurlencode($this->get_title());
  1085. }
  1086. return $url;
  1087. }
  1088. else
  1089. {
  1090. return false;
  1091. }
  1092. }
  1093. function add_to_blogmarks()
  1094. {
  1095. if ($this->get_permalink())
  1096. {
  1097. $url = 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=' . rawurlencode($this->get_permalink());
  1098. if ($this->get_title())
  1099. {
  1100. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1101. }
  1102. return $url;
  1103. }
  1104. else
  1105. {
  1106. return false;
  1107. }
  1108. }
  1109. function add_to_delicious()
  1110. {
  1111. if ($this->get_permalink())
  1112. {
  1113. $url = 'http://del.icio.us/post/?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1114. if ($this->get_title())
  1115. {
  1116. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1117. }
  1118. return $url;
  1119. }
  1120. else
  1121. {
  1122. return false;
  1123. }
  1124. }
  1125. function add_to_digg()
  1126. {
  1127. if ($this->get_permalink())
  1128. {
  1129. return 'http://digg.com/submit?phase=2&amp;URL=' . rawurlencode($this->get_permalink());
  1130. }
  1131. else
  1132. {
  1133. return false;
  1134. }
  1135. }
  1136. function add_to_furl()
  1137. {
  1138. if ($this->get_permalink())
  1139. {
  1140. $url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
  1141. if ($this->get_title())
  1142. {
  1143. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1144. }
  1145. return $url;
  1146. }
  1147. else
  1148. {
  1149. return false;
  1150. }
  1151. }
  1152. function add_to_magnolia()
  1153. {
  1154. if ($this->get_permalink())
  1155. {
  1156. $url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
  1157. if ($this->get_title())
  1158. {
  1159. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1160. }
  1161. return $url;
  1162. }
  1163. else
  1164. {
  1165. return false;
  1166. }
  1167. }
  1168. function add_to_myweb20()
  1169. {
  1170. if ($this->get_permalink())
  1171. {
  1172. $url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
  1173. if ($this->get_title())
  1174. {
  1175. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1176. }
  1177. return $url;
  1178. }
  1179. else
  1180. {
  1181. return false;
  1182. }
  1183. }
  1184. function add_to_newsvine()
  1185. {
  1186. if ($this->get_permalink())
  1187. {
  1188. $url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
  1189. if ($this->get_title())
  1190. {
  1191. $url .= '&amp;h=' . rawurlencode($this->get_title());
  1192. }
  1193. return $url;
  1194. }
  1195. else
  1196. {
  1197. return false;
  1198. }
  1199. }
  1200. function add_to_reddit()
  1201. {
  1202. if ($this->get_permalink())
  1203. {
  1204. $url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
  1205. if ($this->get_title())
  1206. {
  1207. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1208. }
  1209. return $url;
  1210. }
  1211. else
  1212. {
  1213. return false;
  1214. }
  1215. }
  1216. function add_to_segnalo()
  1217. {
  1218. if ($this->get_permalink())
  1219. {
  1220. $url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
  1221. if ($this->get_title())
  1222. {
  1223. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1224. }
  1225. return $url;
  1226. }
  1227. else
  1228. {
  1229. return false;
  1230. }
  1231. }
  1232. function add_to_simpy()
  1233. {
  1234. if ($this->get_permalink())
  1235. {
  1236. $url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
  1237. if ($this->get_title())
  1238. {
  1239. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1240. }
  1241. return $url;
  1242. }
  1243. else
  1244. {
  1245. return false;
  1246. }
  1247. }
  1248. function add_to_smarking()
  1249. {
  1250. if ($this->get_permalink())
  1251. {
  1252. return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
  1253. }
  1254. else
  1255. {
  1256. return false;
  1257. }
  1258. }
  1259. function add_to_spurl()
  1260. {
  1261. if ($this->get_permalink())
  1262. {
  1263. $url = 'http://www.spurl.net/spurl.php?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1264. if ($this->get_title())
  1265. {
  1266. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1267. }
  1268. return $url;
  1269. }
  1270. else
  1271. {
  1272. return false;
  1273. }
  1274. }
  1275. function add_to_wists()
  1276. {
  1277. if ($this->get_permalink())
  1278. {
  1279. $url = 'http://wists.com/r.php?c=&amp;r=' . rawurlencode($this->get_permalink());
  1280. if ($this->get_title())
  1281. {
  1282. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1283. }
  1284. return $url;
  1285. }
  1286. else
  1287. {
  1288. return false;
  1289. }
  1290. }
  1291. function search_technorati()
  1292. {
  1293. if ($this->get_permalink())
  1294. {
  1295. return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
  1296. }
  1297. else
  1298. {
  1299. return false;
  1300. }
  1301. }
  1302. }
  1303. class SimplePie_Author
  1304. {
  1305. var $name;
  1306. var $link;
  1307. var $email;
  1308. // Constructor, used to input the data
  1309. function SimplePie_Author($name, $link, $email) {
  1310. $this->name = $name;
  1311. $this->link = $link;
  1312. $this->email = $email;
  1313. }
  1314. function get_name() {
  1315. return (empty($this->name)) ? false : $this->name;
  1316. }
  1317. function get_link() {
  1318. return (empty($this->link)) ? false : $this->link;
  1319. }
  1320. function get_email() {
  1321. return (empty($this->email)) ? false : $this->email;
  1322. }
  1323. }
  1324. class SimplePie_Enclosure
  1325. {
  1326. var $link;
  1327. var $type;
  1328. var $length;
  1329. // Constructor, used to input the data
  1330. function SimplePie_Enclosure($link, $type, $length) {
  1331. $this->link = $link;
  1332. $this->type = $type;
  1333. $this->length = $length;
  1334. }
  1335. function get_link() {
  1336. return (empty($this->link)) ? false : $this->link;
  1337. }
  1338. function get_extension() {
  1339. if (!empty($this->link)) {
  1340. return pathinfo($this->link, PATHINFO_EXTENSION);
  1341. } else {
  1342. return false;
  1343. }
  1344. }
  1345. function get_type() {
  1346. return (empty($this->type)) ? false : $this->type;
  1347. }
  1348. function get_length() {
  1349. return (empty($this->length)) ? false : $this->length;
  1350. }
  1351. function get_size() {
  1352. return (empty($this->length)) ? false : round(($this->length/1048576), 2);
  1353. }
  1354. function embed($options) {
  1355. // Set up defaults
  1356. $audio='';
  1357. $video='';
  1358. $alt='';
  1359. $altclass='';
  1360. $loop='false';
  1361. $width='auto';
  1362. $height='auto';
  1363. $bgcolor='#ffffff';
  1364. $embed='';
  1365. // Process options and reassign values as necessary
  1366. $options = explode(',', $options);
  1367. foreach($options as $option) {
  1368. $opt = explode(':', trim($option));
  1369. if ($opt[0] == 'audio') $audio=$opt[1];
  1370. else if ($opt[0] == 'video') $video=$opt[1];
  1371. else if ($opt[0] == 'alt') $alt=$opt[1];
  1372. else if ($opt[0] == 'altclass') $altclass=$opt[1];
  1373. else if ($opt[0] == 'loop') $loop=$opt[1];
  1374. else if ($opt[0] == 'width') $width=$opt[1];
  1375. else if ($opt[0] == 'height') $height=$opt[1];
  1376. else if ($opt[0] == 'bgcolor') $bgcolor=$opt[1];
  1377. }
  1378. // Process values for 'auto'
  1379. if ($width == 'auto') {
  1380. if (stristr($this->type, 'audio/')) $width='100%';
  1381. else if (stristr($this->type, 'video/')) $width='320';
  1382. else $width='100%';
  1383. }
  1384. if ($height == 'auto') {
  1385. if (stristr($this->type, 'audio/')) $height=0;
  1386. else if (stristr($this->type, 'video/')) $height=240;
  1387. else $height=256;
  1388. }
  1389. // Set proper placeholder value
  1390. if (stristr($this->type, 'audio/')) $placeholder=$audio;
  1391. else if (stristr($this->type, 'video/')) $placeholder=$video;
  1392. // Make sure the JS library is included
  1393. // (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
  1394. $embed.='<script type="text/javascript" src="?js"></script>';
  1395. // Odeo Feed MP3's
  1396. if (substr(strtolower($this->link), 0, 15) == 'http://odeo.com') {
  1397. $embed.='<script type="text/javascript">embed_odeo("'.$this->link.'");</script>';
  1398. }
  1399. // QuickTime 7 file types. Need to test with QuickTime 6.
  1400. 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') {
  1401. $height+=16;
  1402. $embed.='<script type="text/javascript">embed_quicktime("'.$this->type.'", "'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$placeholder.'", "'.$loop.'");</script>';
  1403. }
  1404. // Flash
  1405. else if ($this->type == 'application/x-shockwave-flash' || $this->type == 'application/futuresplash') {
  1406. $embed.='<script type="text/javascript">embed_flash("'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$loop.'", "'.$this->type.'");</script>';
  1407. }
  1408. // Windows Media
  1409. 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') {
  1410. $height+=45;
  1411. $embed.='<script type="text/javascript">embed_wmedia("'.$width.'", "'.$height.'", "'.$this->link.'");</script>';
  1412. }
  1413. // Everything else
  1414. else $embed.='<a href="' . $this->link . '" class="' . $altclass . '">' . $alt . '</a>';
  1415. return $embed;
  1416. }
  1417. }
  1418. class SimplePie_File
  1419. {
  1420. var $url;
  1421. var $useragent;
  1422. var $success = true;
  1423. var $headers = array();
  1424. var $body;
  1425. var $fp;
  1426. var $redirects = 0;
  1427. function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null)
  1428. {
  1429. if (class_exists('idna_convert'))
  1430. {
  1431. $idn = new idna_convert;
  1432. $url = $idn->encode($url);
  1433. }
  1434. $this->url = $url;
  1435. $this->useragent = $useragent;
  1436. if (preg_match('/^http(s)?:\/\//i', $url))
  1437. {
  1438. if (empty($useragent))
  1439. {
  1440. $useragent = ini_get('user_agent');
  1441. $this->useragent = $useragent;
  1442. }
  1443. if (!is_array($headers))
  1444. {
  1445. $headers = array();
  1446. }
  1447. if (extension_loaded('curl'))
  1448. {
  1449. $fp = curl_init();
  1450. $headers2 = array();
  1451. foreach ($headers as $key => $value)
  1452. {
  1453. $headers2[] = "$key: $value";
  1454. }
  1455. if (version_compare(SimplePie_Misc::get_curl_version(), '7.10', '>='))
  1456. {
  1457. curl_setopt($fp, CURLOPT_ENCODING, '');
  1458. }
  1459. else if (extension_loaded('zlib') && function_exists('gzinflate'))
  1460. {
  1461. $headers2[] = 'Accept-Encoding: gzip,deflate';
  1462. }
  1463. curl_setopt($fp, CURLOPT_URL, $url);
  1464. curl_setopt($fp, CURLOPT_HEADER, 1);
  1465. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  1466. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  1467. curl_setopt($fp, CURLOPT_REFERER, $url);
  1468. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  1469. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  1470. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  1471. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  1472. $this->headers = trim(curl_exec($fp));
  1473. if (curl_errno($fp))
  1474. {
  1475. $this->success = false;
  1476. return false;
  1477. }
  1478. else
  1479. {
  1480. $info = curl_getinfo($fp);
  1481. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
  1482. $this->body = array_pop($this->headers);
  1483. $this->headers = array_pop($this->headers);
  1484. $this->headers = $this->parse_headers($this->headers);
  1485. }
  1486. }
  1487. else
  1488. {
  1489. $url_parts = parse_url($url);
  1490. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
  1491. {
  1492. $url_parts['host'] = "ssl://$url_parts[host]";
  1493. $url_parts['port'] = 443;
  1494. }
  1495. if (!isset($url_parts['port']))
  1496. {
  1497. $url_parts['port'] = 80;
  1498. }
  1499. $this->fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
  1500. if (!$this->fp)
  1501. {
  1502. $this->success = false;
  1503. return false;
  1504. }
  1505. else
  1506. {
  1507. stream_set_timeout($this->fp, $timeout);
  1508. $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
  1509. $out = "GET $get HTTP/1.0\r\n";
  1510. $out .= "Host: $url_parts[host]\r\n";
  1511. $out .= "User-Agent: $useragent\r\n";
  1512. if (extension_loaded('zlib') && function_exists('gzinflate'))
  1513. {
  1514. $out .= "Accept-Encoding: gzip,deflate\r\n";
  1515. }
  1516. if (!empty($url_parts['user']) && !empty($url_parts['pass']))
  1517. {
  1518. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  1519. }
  1520. foreach ($headers as $key => $value)
  1521. {
  1522. $out .= "$key: $value\r\n";
  1523. }
  1524. $out .= "Connection: Close\r\n\r\n";
  1525. fwrite($this->fp, $out);
  1526. $info = stream_get_meta_data($this->fp);
  1527. $data = '';
  1528. while (strpos($data, "\r\n\r\n") === false && $info['timed_out'] === false)
  1529. {
  1530. $data .= fgets($this->fp, 128);
  1531. $info = stream_get_meta_data($this->fp);
  1532. }
  1533. if ($info['timed_out'] === false)
  1534. {
  1535. $this->headers = $this->parse_headers($data);
  1536. 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)
  1537. {
  1538. $this->redirects++;
  1539. return $this->__construct($this->headers['location'], $timeout, $redirects, $headers, $useragent);
  1540. }
  1541. }
  1542. else
  1543. {
  1544. $this->close();
  1545. $this->success = false;
  1546. return false;
  1547. }
  1548. }
  1549. }
  1550. return $this->headers['status']['code'];
  1551. }
  1552. else
  1553. {
  1554. if ($this->fp = fopen($url, 'r'))
  1555. {
  1556. return true;
  1557. }
  1558. else
  1559. {
  1560. $this->success = false;
  1561. return false;
  1562. }
  1563. }
  1564. }
  1565. function headers()
  1566. {
  1567. return $this->headers;
  1568. }
  1569. function body()
  1570. {
  1571. if (is_null($this->body))
  1572. {
  1573. if ($this->fp)
  1574. {
  1575. $this->body = '';
  1576. while (!feof($this->fp))
  1577. {
  1578. $this->body .= fread($this->fp, 1024);
  1579. }
  1580. $this->body = trim($this->body);
  1581. $this->close();
  1582. }
  1583. else
  1584. {
  1585. return false;
  1586. }
  1587. }
  1588. return $this->body;
  1589. }
  1590. function close()
  1591. {
  1592. if (!is_null($this->fp))
  1593. {
  1594. if (fclose($this->fp))
  1595. {
  1596. $this->fp = null;
  1597. return true;
  1598. }
  1599. else
  1600. {
  1601. return false;
  1602. }
  1603. }
  1604. else
  1605. {
  1606. return false;
  1607. }
  1608. }
  1609. function parse_headers($headers)
  1610. {
  1611. $headers = explode("\r\n", trim($headers));
  1612. $status = array_shift($headers);
  1613. foreach ($headers as $header)
  1614. {
  1615. $data = explode(':', $header, 2);
  1616. $head[strtolower(trim($data[0]))] = trim($data[1]);
  1617. }
  1618. if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches))
  1619. {
  1620. if (isset($head['status']))
  1621. {
  1622. unset($head['status']);
  1623. }
  1624. $head['status']['code'] = $matches[1];
  1625. $head['status']['name'] = trim($matches[2]);
  1626. }
  1627. return $head;
  1628. }
  1629. }
  1630. class SimplePie_Cache
  1631. {
  1632. var $location;
  1633. var $filename;
  1634. var $extension;
  1635. var $name;
  1636. function SimplePie_Cache($location, $filename, $extension)
  1637. {
  1638. $this->location = $location;
  1639. $this->filename = rawurlencode($filename);
  1640. $this->extension = rawurlencode($extension);
  1641. $this->name = "$location/$this->filename.$this->extension";
  1642. }
  1643. function save($data)
  1644. {
  1645. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  1646. {
  1647. $fp = fopen($this->name, 'w');
  1648. if ($fp)
  1649. {
  1650. fwrite($fp, serialize($data));
  1651. fclose($fp);
  1652. return true;
  1653. }
  1654. }
  1655. return false;
  1656. }
  1657. function load()
  1658. {
  1659. if (file_exists($this->name) && is_readable($this->name))
  1660. {
  1661. return unserialize(file_get_contents($this->name));
  1662. }
  1663. return false;
  1664. }
  1665. function atime()
  1666. {
  1667. if (file_exists($this->name))
  1668. {
  1669. return fileatime($this->name);
  1670. }
  1671. return false;
  1672. }
  1673. function ctime()
  1674. {
  1675. if (file_exists($this->name))
  1676. {
  1677. return filectime($this->name);
  1678. }
  1679. return false;
  1680. }
  1681. function mtime()
  1682. {
  1683. if (file_exists($this->name))
  1684. {
  1685. return filemtime($this->name);
  1686. }
  1687. return false;
  1688. }
  1689. function touch()
  1690. {
  1691. if (file_exists($this->name))
  1692. {
  1693. return touch($this->name);
  1694. }
  1695. return false;
  1696. }
  1697. function unlink()
  1698. {
  1699. if (file_exists($this->name))
  1700. {
  1701. return unlink($this->name);
  1702. }
  1703. return false;
  1704. }
  1705. function clear($expire)
  1706. {
  1707. foreach (glob("$this->location/*.$this->extension") as $file)
  1708. {
  1709. if (time() - filemtime($file) > $expire)
  1710. {
  1711. unlink($file);
  1712. }
  1713. }
  1714. }
  1715. }
  1716. class SimplePie_Misc
  1717. {
  1718. function absolutize_url($href, $location)
  1719. {
  1720. $href_parts = @parse_url($href);
  1721. if (!empty($href_parts['scheme']))
  1722. {
  1723. return $href;
  1724. }
  1725. else
  1726. {
  1727. if (isset($location['host']))
  1728. {
  1729. $full_url = $location['scheme'] . '://' . $location['host'];
  1730. }
  1731. else
  1732. {
  1733. $full_url = '';
  1734. }
  1735. if (isset($location['port']))
  1736. {
  1737. $full_url .= ':' . $location['port'];
  1738. }
  1739. if (!empty($href_parts['path']))
  1740. {
  1741. if (substr($href_parts['path'], 0, 1) == '/')
  1742. {
  1743. $full_url .= $href_parts['path'];
  1744. }
  1745. else if (!empty($location['path']))
  1746. {
  1747. $full_url .= dirname($location['path'] . 'a') . '/' . $href_parts['path'];
  1748. }
  1749. else
  1750. {
  1751. $full_url .= $href_parts['path'];
  1752. }
  1753. }
  1754. else if (!empty($location['path']))
  1755. {
  1756. $full_url .= $location['path'];
  1757. }
  1758. else
  1759. {
  1760. $full_url .= '/';
  1761. }
  1762. if (!empty($href_parts['query']))
  1763. {
  1764. $full_url .= '?' . $href_parts['query'];
  1765. }
  1766. else if (!empty($location['query']))
  1767. {
  1768. $full_url .= '?' . $location['query'];
  1769. }
  1770. if (!empty($href_parts['fragment']))
  1771. {
  1772. $full_url .= '#' . $href_parts['fragment'];
  1773. }
  1774. else if (!empty($location['fragment']))
  1775. {
  1776. $full_url .= '#' . $location['fragment'];
  1777. }
  1778. return $full_url;
  1779. }
  1780. }
  1781. function get_element($realname, $string)
  1782. {
  1783. $return = array();
  1784. $name = preg_quote($realname, '/');
  1785. preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*(\/>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
  1786. for ($i = 0; $i < count($matches); $i++)
  1787. {
  1788. $return[$i]['tag'] = $realname;
  1789. $return[$i]['full'] = $matches[$i][0];
  1790. if (strlen($matches[$i][10]) == 2)
  1791. {
  1792. $return[$i]['self_closing'] = true;
  1793. }
  1794. else
  1795. {
  1796. $return[$i]['self_closing'] = false;
  1797. $return[$i]['content'] = $matches[$i][11];
  1798. }
  1799. $return[$i]['attribs'] = array();
  1800. if (!empty($matches[$i][2]))
  1801. {
  1802. preg_match_all('/\s((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', " $matches[$i][2] ", $attribs, PREG_SET_ORDER);
  1803. for ($j = 0; $j < count($attribs); $j++)
  1804. {
  1805. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
  1806. $first = substr($attribs[$j][2], 0, 1);
  1807. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
  1808. }
  1809. }
  1810. }
  1811. return $return;
  1812. }
  1813. function element_implode($element)
  1814. {
  1815. $full = "<$element[tag]";
  1816. foreach ($element['attribs'] as $key => $value)
  1817. {
  1818. $key = strtolower($key);
  1819. $full .= " $key=$value[split]$value[data]$value[split]";
  1820. }
  1821. if ($element['self_closing'])
  1822. {
  1823. $full .= ' />';
  1824. }
  1825. else
  1826. {
  1827. $full .= ">$element[content]</$element[tag]>";
  1828. }
  1829. return $full;
  1830. }
  1831. function error($message, $level, $file, $line)
  1832. {
  1833. switch ($level)
  1834. {
  1835. case E_USER_ERROR:
  1836. $note = 'PHP Error';
  1837. break;
  1838. case E_USER_WARNING:
  1839. $note = 'PHP Warning';
  1840. break;
  1841. case E_USER_NOTICE:
  1842. $note = 'PHP Notice';
  1843. break;
  1844. default:
  1845. $note = 'Unknown Error';
  1846. break;
  1847. }
  1848. error_log("$note: $message in $file on line $line", 0);
  1849. return $message;
  1850. }
  1851. function display_file($url, $timeout = 10, $useragent = null)
  1852. {
  1853. $file = new SimplePie_File($url, $timeout, 5, null, $useragent);
  1854. $headers = $file->headers();
  1855. if ($file->body() !== false)
  1856. {
  1857. header('Content-type: ' . $headers['content-type']);
  1858. echo $file->body();
  1859. exit;
  1860. }
  1861. }
  1862. /****************************************************
  1863. FIX PROTOCOL
  1864. Convert feed:// and no-protocol URL's to http://
  1865. Feed is allowed to have no protocol. Local files are toggled in init().
  1866. This is an internal function and is not intended to be used publically.
  1867. $http=1, http://www.domain.com/feed.xml (absolute)
  1868. $http=2, feed://www.domain.com/feed.xml (absolute)
  1869. $http=3, podcast://www.domain.com/feed.xml (absolute)
  1870. ****************************************************/
  1871. function fix_protocol($url, $http = 1)
  1872. {
  1873. $url = preg_replace('/^http:\/\/photocast.mac.com/i', 'http://web.mac.com', $url);
  1874. $url = preg_replace('/^(p(od)?cast|feed)[:]?[\/]*(http(s)?:\/\/)?/i', 'http://', $url);
  1875. //$url = preg_replace('/^(.*)(s)?:\/\//i', 'http\\2://', $url);
  1876. if ($http != 1 && strstr($url, 'http://'))
  1877. {
  1878. if ($http == 2)
  1879. {
  1880. $url = substr_replace($url, 'feed', 0, 4);
  1881. }
  1882. else if ($http == 3)
  1883. {
  1884. $url = substr_replace($url, 'podcast', 0, 4);
  1885. }
  1886. }
  1887. return $url;
  1888. }
  1889. function encoding($encoding)
  1890. {
  1891. $return['use_mbstring'] = false;
  1892. $return['use_iconv'] = false;
  1893. switch (strtolower($encoding))
  1894. {
  1895. // 7bit
  1896. case '7bit':
  1897. case '7-bit':
  1898. $return['encoding'] = '7bit';
  1899. $return['use_mbstring'] = true;
  1900. break;
  1901. // 8bit
  1902. case '8bit':
  1903. case '8-bit':
  1904. $return['encoding'] = '8bit';
  1905. $return['use_mbstring'] = true;
  1906. break;
  1907. // ARMSCII-8
  1908. case 'armscii-8':
  1909. case 'armscii':
  1910. $return['encoding'] = 'ARMSCII-8';
  1911. $return['use_iconv'] = true;
  1912. break;
  1913. // ASCII
  1914. case 'us-ascii':
  1915. case 'ascii':
  1916. $return['encoding'] = 'US-ASCII';
  1917. $return['use_iconv'] = true;
  1918. $return['use_mbstring'] = true;
  1919. break;
  1920. // BASE64
  1921. case 'base64':
  1922. case 'base-64':
  1923. $return['encoding'] = 'BASE64';
  1924. $return['use_mbstring'] = true;
  1925. break;
  1926. // Big5 - Traditional Chinese, mainly used in Taiwan
  1927. case 'big5':
  1928. case '950':
  1929. $return['encoding'] = 'BIG5';
  1930. $return['use_iconv'] = true;
  1931. $return['use_mbstring'] = true;
  1932. break;
  1933. // Big5 with Hong Kong extensions, Traditional Chinese
  1934. case 'big5-hkscs':
  1935. $return['encoding'] = 'BIG5-HKSCS';
  1936. $return['use_iconv'] = true;
  1937. $return['use_mbstring'] = true;
  1938. break;
  1939. // byte2be
  1940. case 'byte2be':
  1941. $return['encoding'] = 'byte2be';
  1942. $return['use_mbstring'] = true;
  1943. break;
  1944. // byte2le
  1945. case 'byte2le':
  1946. $return['encoding'] = 'byte2le';
  1947. $return['use_mbstring'] = true;
  1948. break;
  1949. // byte4be
  1950. case 'byte4be':
  1951. $return['encoding'] = 'byte4be';
  1952. $return['use_mbstring'] = true;
  1953. break;
  1954. // byte4le
  1955. case 'byte4le':
  1956. $return['encoding'] = 'byte4le';
  1957. $return['use_mbstring'] = true;
  1958. break;
  1959. // EUC-CN
  1960. case 'euc-cn':
  1961. case 'euccn':
  1962. $return['encoding'] = 'EUC-CN';
  1963. $return['use_iconv'] = true;
  1964. $return['use_mbstring'] = true;
  1965. break;
  1966. // EUC-JISX0213
  1967. case 'euc-jisx0213':
  1968. case 'eucjisx0213':
  1969. $return['encoding'] = 'EUC-JISX0213';
  1970. $return['use_iconv'] = true;
  1971. break;
  1972. // EUC-JP
  1973. case 'euc-jp':
  1974. case 'eucjp':
  1975. $return['encoding'] = 'EUC-JP';
  1976. $return['use_iconv'] = true;
  1977. $return['use_mbstring'] = true;
  1978. break;
  1979. // EUCJP-win
  1980. case 'euc-jp-win':
  1981. case 'eucjp-win':
  1982. case 'eucjpwin':
  1983. $return['encoding'] = 'EUCJP-win';
  1984. $return['use_iconv'] = true;
  1985. $return['use_mbstring'] = true;
  1986. break;
  1987. // EUC-KR
  1988. case 'euc-kr':
  1989. case 'euckr':
  1990. $return['encoding'] = 'EUC-KR';
  1991. $return['use_iconv'] = true;
  1992. $return['use_mbstring'] = true;
  1993. break;
  1994. // EUC-TW
  1995. case 'euc-tw':
  1996. case 'euctw':
  1997. $return['encoding'] = 'EUC-TW';
  1998. $return['use_iconv'] = true;
  1999. $return['use_mbstring'] = true;
  2000. break;
  2001. // GB18030 - Simplified Chinese, national standard character set
  2002. case 'gb18030-2000':
  2003. case 'gb18030':
  2004. $return['encoding'] = 'GB18030';
  2005. $return['use_iconv'] = true;
  2006. break;
  2007. // GB2312 - Simplified Chinese, national standard character set
  2008. case 'gb2312':
  2009. case '936':
  2010. $return['encoding'] = 'GB2312';
  2011. $return['use_mbstring'] = true;
  2012. break;
  2013. // GBK
  2014. case 'gbk':
  2015. $return['encoding'] = 'GBK';
  2016. $return['use_iconv'] = true;
  2017. break;
  2018. // Georgian-Academy
  2019. case 'georgian-academy':
  2020. $return['encoding'] = 'Georgian-Academy';
  2021. $return['use_iconv'] = true;
  2022. break;
  2023. // Georgian-PS
  2024. case 'georgian-ps':
  2025. $return['encoding'] = 'Georgian-PS';
  2026. $return['use_iconv'] = true;
  2027. break;
  2028. // HTML-ENTITIES
  2029. case 'html-entities':
  2030. case 'htmlentities':
  2031. $return['encoding'] = 'HTML-ENTITIES';
  2032. $return['use_mbstring'] = true;
  2033. break;
  2034. // HZ
  2035. case 'hz':
  2036. $return['encoding'] = 'HZ';
  2037. $return['use_iconv'] = true;
  2038. $return['use_mbstring'] = true;
  2039. break;
  2040. // ISO-2022-CN
  2041. case 'iso-2022-cn':
  2042. case 'iso2022-cn':
  2043. case 'iso2022cn':
  2044. $return['encoding'] = 'ISO-2022-CN';
  2045. $return['use_iconv'] = true;
  2046. break;
  2047. // ISO-2022-CN-EXT
  2048. case 'iso-2022-cn-ext':
  2049. case 'iso2022-cn-ext':
  2050. case 'iso2022cn-ext':
  2051. case 'iso2022cnext':
  2052. $return['encoding'] = 'ISO-2022-CN';
  2053. $return['use_iconv'] = true;
  2054. break;
  2055. // ISO-2022-JP
  2056. case 'iso-2022-jp':
  2057. case 'iso2022-jp':
  2058. case 'iso2022jp':
  2059. $return['encoding'] = 'ISO-2022-JP';
  2060. $return['use_iconv'] = true;
  2061. $return['use_mbstring'] = true;
  2062. break;
  2063. // ISO-2022-JP-1
  2064. case 'iso-2022-jp-1':
  2065. case 'iso2022-jp-1':
  2066. case 'iso2022jp-1':
  2067. case 'iso2022jp1':
  2068. $return['encoding'] = 'ISO-2022-JP-1';
  2069. $return['use_iconv'] = true;
  2070. break;
  2071. // ISO-2022-JP-2
  2072. case 'iso-2022-jp-2':
  2073. case 'iso2022-jp-2':
  2074. case 'iso2022jp-2':
  2075. case 'iso2022jp2':
  2076. $return['encoding'] = 'ISO-2022-JP-2';
  2077. $return['use_iconv'] = true;
  2078. break;
  2079. // ISO-2022-JP-3
  2080. case 'iso-2022-jp-3':
  2081. case 'iso2022-jp-3':
  2082. case 'iso2022jp-3':
  2083. case 'iso2022jp3':
  2084. $return['encoding'] = 'ISO-2022-JP-3';
  2085. $return['use_iconv'] = true;
  2086. break;
  2087. // ISO-2022-KR
  2088. case 'iso-2022-kr':
  2089. case 'iso2022-kr':
  2090. case 'iso2022kr':
  2091. $return['encoding'] = 'ISO-2022-KR';
  2092. $return['use_iconv'] = true;
  2093. $return['use_mbstring'] = true;
  2094. break;
  2095. // ISO-8859-1
  2096. case 'iso-8859-1':
  2097. case 'iso8859-1':
  2098. $return['encoding'] = 'ISO-8859-1';
  2099. $return['use_iconv'] = true;
  2100. $return['use_mbstring'] = true;
  2101. break;
  2102. // ISO-8859-2
  2103. case 'iso-8859-2':
  2104. case 'iso8859-2':
  2105. $return['encoding'] = 'ISO-8859-2';
  2106. $return['use_iconv'] = true;
  2107. $return['use_mbstring'] = true;
  2108. break;
  2109. // ISO-8859-3
  2110. case 'iso-8859-3':
  2111. case 'iso8859-3':
  2112. $return['encoding'] = 'ISO-8859-3';
  2113. $return['use_iconv'] = true;
  2114. $return['use_mbstring'] = true;
  2115. break;
  2116. // ISO-8859-4
  2117. case 'iso-8859-4':
  2118. case 'iso8859-4':
  2119. $return['encoding'] = 'ISO-8859-4';
  2120. $return['use_iconv'] = true;
  2121. $return['use_mbstring'] = true;
  2122. break;
  2123. // ISO-8859-5
  2124. case 'iso-8859-5':
  2125. case 'iso8859-5':
  2126. $return['encoding'] = 'ISO-8859-5';
  2127. $return['use_iconv'] = true;
  2128. $return['use_mbstring'] = true;
  2129. break;
  2130. // ISO-8859-6
  2131. case 'iso-8859-6':
  2132. case 'iso8859-6':
  2133. $return['encoding'] = 'ISO-8859-6';
  2134. $return['use_iconv'] = true;
  2135. $return['use_mbstring'] = true;
  2136. break;
  2137. // ISO-8859-7
  2138. case 'iso-8859-7':
  2139. case 'iso8859-7':
  2140. $return['encoding'] = 'ISO-8859-7';
  2141. $return['use_iconv'] = true;
  2142. $return['use_mbstring'] = true;
  2143. break;
  2144. // ISO-8859-8
  2145. case 'iso-8859-8':
  2146. case 'iso8859-8':
  2147. $return['encoding'] = 'ISO-8859-8';
  2148. $return['use_iconv'] = true;
  2149. $return['use_mbstring'] = true;
  2150. break;
  2151. // ISO-8859-9
  2152. case 'iso-8859-9':
  2153. case 'iso8859-9':
  2154. $return['encoding'] = 'ISO-8859-9';
  2155. $return['use_iconv'] = true;
  2156. $return['use_mbstring'] = true;
  2157. break;
  2158. // ISO-8859-10
  2159. case 'iso-8859-10':
  2160. case 'iso8859-10':
  2161. $return['encoding'] = 'ISO-8859-10';
  2162. $return['use_iconv'] = true;
  2163. $return['use_mbstring'] = true;
  2164. break;
  2165. // mbstring/iconv functions don't appear to support 11 & 12
  2166. // ISO-8859-13
  2167. case 'iso-8859-13':
  2168. case 'iso8859-13':
  2169. $return['encoding'] = 'ISO-8859-13';
  2170. $return['use_iconv'] = true;
  2171. $return['use_mbstring'] = true;
  2172. break;
  2173. // ISO-8859-14
  2174. case 'iso-8859-14':
  2175. case 'iso8859-14':
  2176. $return['encoding'] = 'ISO-8859-14';
  2177. $return['use_iconv'] = true;
  2178. $return['use_mbstring'] = true;
  2179. break;
  2180. // ISO-8859-15
  2181. case 'iso-8859-15':
  2182. case 'iso8859-15':
  2183. $return['encoding'] = 'ISO-8859-15';
  2184. $return['use_iconv'] = true;
  2185. $return['use_mbstring'] = true;
  2186. break;
  2187. // ISO-8859-16
  2188. case 'iso-8859-16':
  2189. case 'iso8859-16':
  2190. $return['encoding'] = 'ISO-8859-16';
  2191. $return['use_iconv'] = true;
  2192. break;
  2193. // JIS
  2194. case 'jis':
  2195. $return['encoding'] = 'JIS';
  2196. $return['use_mbstring'] = true;
  2197. break;
  2198. // JOHAB - Korean
  2199. case 'johab':
  2200. $return['encoding'] = 'JOHAB';
  2201. $return['use_iconv'] = true;
  2202. break;
  2203. // Russian
  2204. case 'koi8-r':
  2205. case 'koi8r':
  2206. $return['encoding'] = 'KOI8-R';
  2207. $return['use_iconv'] = true;
  2208. $return['use_mbstring'] = true;
  2209. break;
  2210. // Turkish
  2211. case 'koi8-t':
  2212. case 'koi8t':
  2213. $return['encoding'] = 'KOI8-T';
  2214. $return['use_iconv'] = true;
  2215. break;
  2216. // Ukrainian
  2217. case 'koi8-u':
  2218. case 'koi8u':
  2219. $return['encoding'] = 'KOI8-U';
  2220. $return['use_iconv'] = true;
  2221. break;
  2222. // Russian+Ukrainian
  2223. case 'koi8-ru':
  2224. case 'koi8ru':
  2225. $return['encoding'] = 'KOI8-RU';
  2226. $return['use_iconv'] = true;
  2227. break;
  2228. // Macintosh (Mac OS Classic)
  2229. case 'macintosh':
  2230. $return['encoding'] = 'Macintosh';
  2231. $return['use_iconv'] = true;
  2232. break;
  2233. // MacArabic (Mac OS Classic)
  2234. case 'macarabic':
  2235. $return['encoding'] = 'MacArabic';
  2236. $return['use_iconv'] = true;
  2237. break;
  2238. // MacCentralEurope (Mac OS Classic)
  2239. case 'maccentraleurope':
  2240. $return['encoding'] = 'MacCentralEurope';
  2241. $return['use_iconv'] = true;
  2242. break;
  2243. // MacCroatian (Mac OS Classic)
  2244. case 'maccroatian':
  2245. $return['encoding'] = 'MacCroatian';
  2246. $return['use_iconv'] = true;
  2247. break;
  2248. // MacCyrillic (Mac OS Classic)
  2249. case 'maccyrillic':
  2250. $return['encoding'] = 'MacCyrillic';
  2251. $return['use_iconv'] = true;
  2252. break;
  2253. // MacGreek (Mac OS Classic)
  2254. case 'macgreek':
  2255. $return['encoding'] = 'MacGreek';
  2256. $return['use_iconv'] = true;
  2257. break;
  2258. // MacHebrew (Mac OS Classic)
  2259. case 'machebrew':
  2260. $return['encoding'] = 'MacHebrew';
  2261. $return['use_iconv'] = true;
  2262. break;
  2263. // MacIceland (Mac OS Classic)
  2264. case 'maciceland':
  2265. $return['encoding'] = 'MacIceland';
  2266. $return['use_iconv'] = true;
  2267. break;
  2268. // MacRoman (Mac OS Classic)
  2269. case 'macroman':
  2270. $return['encoding'] = 'MacRoman';
  2271. $return['use_iconv'] = true;
  2272. break;
  2273. // MacRomania (Mac OS Classic)
  2274. case 'macromania':
  2275. $return['encoding'] = 'MacRomania';
  2276. $return['use_iconv'] = true;
  2277. break;
  2278. // MacThai (Mac OS Classic)
  2279. case 'macthai':
  2280. $return['encoding'] = 'MacThai';
  2281. $return['use_iconv'] = true;
  2282. break;
  2283. // MacTurkish (Mac OS Classic)
  2284. case 'macturkish':
  2285. $return['encoding'] = 'MacTurkish';
  2286. $return['use_iconv'] = true;
  2287. break;
  2288. // MacUkraine (Mac OS Classic)
  2289. case 'macukraine':
  2290. $return['encoding'] = 'MacUkraine';
  2291. $return['use_iconv'] = true;
  2292. break;
  2293. // MuleLao-1
  2294. case 'mulelao-1':
  2295. case 'mulelao1':
  2296. $return['encoding'] = 'MuleLao-1';
  2297. $return['use_iconv'] = true;
  2298. break;
  2299. // Shift_JIS
  2300. case 'shift_jis':
  2301. case 'sjis':
  2302. case '932':
  2303. $return['encoding'] = 'Shift_JIS';
  2304. $return['use_iconv'] = true;
  2305. $return['use_mbstring'] = true;
  2306. break;
  2307. // Shift_JISX0213
  2308. case 'shift-jisx0213':
  2309. case 'shiftjisx0213':
  2310. $return['encoding'] = 'Shift_JISX0213';
  2311. $return['use_iconv'] = true;
  2312. break;
  2313. // SJIS-win
  2314. case 'sjis-win':
  2315. case 'sjiswin':
  2316. case 'shift_jis-win':
  2317. $return['encoding'] = 'SJIS-win';
  2318. $return['use_iconv'] = true;
  2319. $return['use_mbstring'] = true;
  2320. break;
  2321. // TCVN - Vietnamese
  2322. case 'tcvn':
  2323. $return['encoding'] = 'TCVN';
  2324. $return['use_iconv'] = true;
  2325. break;
  2326. // TDS565 - Turkish
  2327. case 'tds565':
  2328. $return['encoding'] = 'TDS565';
  2329. $return['use_iconv'] = true;
  2330. break;
  2331. // TIS-620 Thai
  2332. case 'tis-620':
  2333. case 'tis620':
  2334. $return['encoding'] = 'TIS-620';
  2335. $return['use_iconv'] = true;
  2336. $return['use_mbstring'] = true;
  2337. break;
  2338. // UCS-2
  2339. case 'ucs-2':
  2340. case 'ucs2':
  2341. case 'utf-16':
  2342. case 'utf16':
  2343. $return['encoding'] = 'UCS-2';
  2344. $return['use_iconv'] = true;
  2345. $return['use_mbstring'] = true;
  2346. break;
  2347. // UCS-2BE
  2348. case 'ucs-2be':
  2349. case 'ucs2be':
  2350. case 'utf-16be':
  2351. case 'utf16be':
  2352. $return['encoding'] = 'UCS-2BE';
  2353. $return['use_iconv'] = true;
  2354. $return['use_mbstring'] = true;
  2355. break;
  2356. // UCS-2LE
  2357. case 'ucs-2le':
  2358. case 'ucs2le':
  2359. case 'utf-16le':
  2360. case 'utf16le':
  2361. $return['encoding'] = 'UCS-2LE';
  2362. $return['use_iconv'] = true;
  2363. $return['use_mbstring'] = true;
  2364. break;
  2365. // UCS-2-INTERNAL
  2366. case 'ucs-2-internal':
  2367. case 'ucs2internal':
  2368. $return['encoding'] = 'UCS-2-INTERNAL';
  2369. $return['use_iconv'] = true;
  2370. break;
  2371. // UCS-4
  2372. case 'ucs-4':
  2373. case 'ucs4':
  2374. case 'utf-32':
  2375. case 'utf32':
  2376. $return['encoding'] = 'UCS-4';
  2377. $return['use_iconv'] = true;
  2378. $return['use_mbstring'] = true;
  2379. break;
  2380. // UCS-4BE
  2381. case 'ucs-4be':
  2382. case 'ucs4be':
  2383. case 'utf-32be':
  2384. case 'utf32be':
  2385. $return['encoding'] = 'UCS-4BE';
  2386. $return['use_iconv'] = true;
  2387. $return['use_mbstring'] = true;
  2388. break;
  2389. // UCS-4LE
  2390. case 'ucs-4le':
  2391. case 'ucs4le':
  2392. case 'utf-32le':
  2393. case 'utf32le':
  2394. $return['encoding'] = 'UCS-4LE';
  2395. $return['use_iconv'] = true;
  2396. $return['use_mbstring'] = true;
  2397. break;
  2398. // UCS-4-INTERNAL
  2399. case 'ucs-4-internal':
  2400. case 'ucs4internal':
  2401. $return['encoding'] = 'UCS-4-INTERNAL';
  2402. $return['use_iconv'] = true;
  2403. break;
  2404. // UCS-16
  2405. case 'ucs-16':
  2406. case 'ucs16':
  2407. $return['encoding'] = 'UCS-16';
  2408. $return['use_iconv'] = true;
  2409. $return['use_mbstring'] = true;
  2410. break;
  2411. // UCS-16BE
  2412. case 'ucs-16be':
  2413. case 'ucs16be':
  2414. $return['encoding'] = 'UCS-16BE';
  2415. $return['use_iconv'] = true;
  2416. $return['use_mbstring'] = true;
  2417. break;
  2418. // UCS-16LE
  2419. case 'ucs-16le':
  2420. case 'ucs16le':
  2421. $return['encoding'] = 'UCS-16LE';
  2422. $return['use_iconv'] = true;
  2423. $return['use_mbstring'] = true;
  2424. break;
  2425. // UCS-32
  2426. case 'ucs-32':
  2427. case 'ucs32':
  2428. $return['encoding'] = 'UCS-32';
  2429. $return['use_iconv'] = true;
  2430. $return['use_mbstring'] = true;
  2431. break;
  2432. // UCS-32BE
  2433. case 'ucs-32be':
  2434. case 'ucs32be':
  2435. $return['encoding'] = 'UCS-32BE';
  2436. $return['use_iconv'] = true;
  2437. $return['use_mbstring'] = true;
  2438. break;
  2439. // UCS-32LE
  2440. case 'ucs-32le':
  2441. case 'ucs32le':
  2442. $return['encoding'] = 'UCS-32LE';
  2443. $return['use_iconv'] = true;
  2444. $return['use_mbstring'] = true;
  2445. break;
  2446. // UTF-7
  2447. case 'utf-7':
  2448. case 'utf7':
  2449. $return['encoding'] = 'UTF-7';
  2450. $return['use_iconv'] = true;
  2451. $return['use_mbstring'] = true;
  2452. break;
  2453. // UTF7-IMAP
  2454. case 'utf-7-imap':
  2455. case 'utf7-imap':
  2456. case 'utf7imap':
  2457. $return['encoding'] = 'UTF7-IMAP';
  2458. $return['use_mbstring'] = true;
  2459. break;
  2460. // VISCII - Vietnamese ASCII
  2461. case 'viscii':
  2462. $return['encoding'] = 'VISCII';
  2463. $return['use_iconv'] = true;
  2464. break;
  2465. // Windows-specific Central & Eastern Europe
  2466. case 'cp1250':
  2467. case 'windows-1250':
  2468. case 'win-1250':
  2469. case '1250':
  2470. $return['encoding'] = 'Windows-1250';
  2471. $return['use_iconv'] = true;
  2472. break;
  2473. // Windows-specific Cyrillic
  2474. case 'cp1251':
  2475. case 'windows-1251':
  2476. case 'win-1251':
  2477. case '1251':
  2478. $return['encoding'] = 'Windows-1251';
  2479. $return['use_iconv'] = true;
  2480. $return['use_mbstring'] = true;
  2481. break;
  2482. // Windows-specific Western Europe
  2483. case 'cp1252':
  2484. case 'windows-1252':
  2485. case '1252':
  2486. $return['encoding'] = 'Windows-1252';
  2487. $return['use_iconv'] = true;
  2488. $return['use_mbstring'] = true;
  2489. break;
  2490. // Windows-specific Greek
  2491. case 'cp1253':
  2492. case 'windows-1253':
  2493. case '1253':
  2494. $return['encoding'] = 'Windows-1253';
  2495. $return['use_iconv'] = true;
  2496. break;
  2497. // Windows-specific Turkish
  2498. case 'cp1254':
  2499. case 'windows-1254':
  2500. case '1254':
  2501. $return['encoding'] = 'Windows-1254';
  2502. $return['use_iconv'] = true;
  2503. break;
  2504. // Windows-specific Hebrew
  2505. case 'cp1255':
  2506. case 'windows-1255':
  2507. case '1255':
  2508. $return['encoding'] = 'Windows-1255';
  2509. $return['use_iconv'] = true;
  2510. break;
  2511. // Windows-specific Arabic
  2512. case 'cp1256':
  2513. case 'windows-1256':
  2514. case '1256':
  2515. $return['encoding'] = 'Windows-1256';
  2516. $return['use_iconv'] = true;
  2517. break;
  2518. // Windows-specific Baltic
  2519. case 'cp1257':
  2520. case 'windows-1257':
  2521. case '1257':
  2522. $return['encoding'] = 'Windows-1257';
  2523. $return['use_iconv'] = true;
  2524. break;
  2525. // Windows-specific Vietnamese
  2526. case 'cp1258':
  2527. case 'windows-1258':
  2528. case '1258':
  2529. $return['encoding'] = 'Windows-1258';
  2530. $return['use_iconv'] = true;
  2531. break;
  2532. // Default to UTF-8
  2533. default:
  2534. $return['encoding'] = 'UTF-8';
  2535. break;
  2536. }
  2537. // If mb_list_encodings() exists, use that to set use_mbstring
  2538. if (function_exists('mb_list_encodings'))
  2539. {
  2540. if (in_array($return['encoding'], mb_list_encodings()))
  2541. {
  2542. $return['use_mbstring'] = true;
  2543. }
  2544. else
  2545. {
  2546. $return['use_mbstring'] = false;
  2547. }
  2548. }
  2549. // Then, return it.
  2550. return $return;
  2551. }
  2552. function get_curl_version() {
  2553. $curl = 0;
  2554. if (is_array(curl_version()))
  2555. {
  2556. $curl = curl_version();
  2557. $curl = $curl['version'];
  2558. }
  2559. else {
  2560. $curl = curl_version();
  2561. $curl = explode(' ', $curl);
  2562. $curl = explode('/', $curl[0]);
  2563. $curl = $curl[1];
  2564. }
  2565. return $curl;
  2566. }
  2567. }
  2568. class SimplePie_Locator
  2569. {
  2570. var $useragent;
  2571. var $parsed_url;
  2572. var $file;
  2573. var $local;
  2574. var $elsewhere;
  2575. function SimplePie_Locator(&$file)
  2576. {
  2577. if (!is_a($file, 'SimplePie_File'))
  2578. {
  2579. $this->file = new SimplePie_File($file);
  2580. }
  2581. else
  2582. {
  2583. $this->file =& $file;
  2584. }
  2585. }
  2586. function find()
  2587. {
  2588. if ($this->is_feed($this->file))
  2589. {
  2590. return $this->file->url;
  2591. }
  2592. $this->useragent = $this->file->useragent;
  2593. $this->parsed_url = parse_url($this->file->url);
  2594. if (!isset($this->parsed_url['path']))
  2595. {
  2596. $this->parsed_url['path'] = '/';
  2597. }
  2598. $autodiscovery = $this->autodiscovery($this->file);
  2599. if ($autodiscovery)
  2600. {
  2601. return $autodiscovery;
  2602. }
  2603. if ($this->get_links($this->file))
  2604. {
  2605. if (!empty($this->local))
  2606. {
  2607. $extension_local = $this->extension($this->local);
  2608. if ($extension_local)
  2609. {
  2610. return $extension_local;
  2611. }
  2612. $body_local = $this->body($this->local);
  2613. if ($body_local)
  2614. {
  2615. return $body_local;
  2616. }
  2617. }
  2618. if (!empty($this->elsewhere))
  2619. {
  2620. $extension_elsewhere = $this->extension($this->elsewhere);
  2621. if ($extension_elsewhere)
  2622. {
  2623. return $extension_elsewhere;
  2624. }
  2625. $body_elsewhere = $this->body($this->elsewhere);
  2626. if ($body_elsewhere)
  2627. {
  2628. return $body_elsewhere;
  2629. }
  2630. }
  2631. }
  2632. return false;
  2633. }
  2634. function is_feed(&$file)
  2635. {
  2636. if (!is_a($file, 'SimplePie_File'))
  2637. {
  2638. $file2 = new SimplePie_File($file, 1, 5, null, $this->useragent);
  2639. $file2->body();
  2640. $file2->close();
  2641. }
  2642. else
  2643. {
  2644. $file2 =& $file;
  2645. }
  2646. 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()))))
  2647. {
  2648. return true;
  2649. }
  2650. return false;
  2651. }
  2652. function autodiscovery(&$file)
  2653. {
  2654. $links = SimplePie_Misc::get_element('link', $file->body());
  2655. $done = array();
  2656. foreach ($links as $link)
  2657. {
  2658. if (!empty($link['attribs']['TYPE']['data']) && !empty($link['attribs']['HREF']['data']))
  2659. {
  2660. $type = strtolower(trim($link['attribs']['TYPE']['data']));
  2661. $href = SimplePie_Misc::absolutize_url(trim($link['attribs']['HREF']['data']), $this->parsed_url);
  2662. 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')))
  2663. {
  2664. $feed = $this->is_feed($href);
  2665. if ($feed)
  2666. {
  2667. return $href;
  2668. }
  2669. }
  2670. $done[] = $href;
  2671. }
  2672. }
  2673. return false;
  2674. }
  2675. function get_links(&$file)
  2676. {
  2677. $links = SimplePie_Misc::get_element('a', $file->body());
  2678. foreach ($links as $link)
  2679. {
  2680. if (!empty($link['attribs']['HREF']['data']))
  2681. {
  2682. $href = trim($link['attribs']['HREF']['data']);
  2683. $parsed = @parse_url($href);
  2684. if (empty($parsed['scheme']) || $parsed['scheme'] != 'javascript')
  2685. {
  2686. if (empty($parsed['host']) || $parsed['host'] == $this->parsed_url['host'])
  2687. {
  2688. $this->local[] = SimplePie_Misc::absolutize_url($href, $this->parsed_url);
  2689. }
  2690. else
  2691. {
  2692. $this->elsewhere[] = SimplePie_Misc::absolutize_url($href, $this->parsed_url);
  2693. }
  2694. }
  2695. }
  2696. }
  2697. if (!empty($this->local))
  2698. {
  2699. $this->local = array_unique($this->local);
  2700. }
  2701. if (!empty($this->elsewhere))
  2702. {
  2703. $this->elsewhere = array_unique($this->elsewhere);
  2704. }
  2705. if (!empty($this->local) || !empty($this->elsewhere))
  2706. {
  2707. return true;
  2708. }
  2709. return false;
  2710. }
  2711. function extension(&$array)
  2712. {
  2713. foreach ($array as $key => $value)
  2714. {
  2715. $value = SimplePie_Misc::absolutize_url($value, $this->parsed_url);
  2716. if (in_array(strrchr($value, '.'), array('.rss', '.rdf', '.atom', '.xml')))
  2717. {
  2718. if ($this->is_feed($value))
  2719. {
  2720. return $value;
  2721. }
  2722. else
  2723. {
  2724. unset($array[$key]);
  2725. }
  2726. }
  2727. }
  2728. return false;
  2729. }
  2730. function body(&$array)
  2731. {
  2732. foreach ($array as $key => $value)
  2733. {
  2734. $value = SimplePie_Misc::absolutize_url($value, $this->parsed_url);
  2735. if (preg_match('/(rss|rdf|atom|xml)/i', $value))
  2736. {
  2737. if ($this->is_feed($value))
  2738. {
  2739. return $value;
  2740. }
  2741. else
  2742. {
  2743. unset($array[$key]);
  2744. }
  2745. }
  2746. }
  2747. return false;
  2748. }
  2749. }
  2750. class SimplePie_Parser
  2751. {
  2752. var $encoding;
  2753. var $data;
  2754. 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');
  2755. var $xml;
  2756. var $error_code;
  2757. var $error_string;
  2758. var $current_line;
  2759. var $current_column;
  2760. var $current_byte;
  2761. var $tag_name;
  2762. var $inside_item;
  2763. var $item_number = 0;
  2764. var $inside_channel;
  2765. var $author_number= 0;
  2766. var $category_number = 0;
  2767. var $enclosure_number = 0;
  2768. var $link_number = 0;
  2769. var $item_link_number = 0;
  2770. var $inside_image;
  2771. var $attribs;
  2772. var $is_first;
  2773. var $inside_author;
  2774. function SimplePie_Parser($data, $encoding, $return_xml = false)
  2775. {
  2776. $this->encoding = $encoding;
  2777. // Strip BOM:
  2778. // UTF-32 Big Endian BOM
  2779. if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
  2780. {
  2781. $data = substr($data, 4);
  2782. }
  2783. // UTF-32 Little Endian BOM
  2784. else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
  2785. {
  2786. $data = substr($data, 4);
  2787. }
  2788. // UTF-16 Big Endian BOM
  2789. else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
  2790. {
  2791. $data = substr($data, 2);
  2792. }
  2793. // UTF-16 Little Endian BOM
  2794. else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
  2795. {
  2796. $data = substr($data, 2);
  2797. }
  2798. // UTF-8 BOM
  2799. else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
  2800. {
  2801. $data = substr($data, 3);
  2802. }
  2803. // Make sure the XML prolog is sane and has the correct encoding
  2804. if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog))
  2805. {
  2806. $data = substr_replace($data, '', 0, strlen($prolog[0]));
  2807. }
  2808. $data = "<?xml version='1.0' encoding='$encoding'?>\n" . $data;
  2809. // Add an internal attribute to CDATA sections
  2810. $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'))*)\s*(\/>|>\s*<\!\[CDATA\[(.*)<\/\\1>)/msiU', array(&$this, 'spencoded'), $data);
  2811. // Put some data into CDATA blocks
  2812. // If we're RSS
  2813. 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)))
  2814. {
  2815. $sp_elements = array(
  2816. 'author',
  2817. 'description',
  2818. 'link',
  2819. 'title',
  2820. );
  2821. }
  2822. // Or if we're Atom
  2823. else
  2824. {
  2825. $sp_elements = array(
  2826. 'content',
  2827. 'copyright',
  2828. 'name',
  2829. 'subtitle',
  2830. 'summary',
  2831. 'tagline',
  2832. 'title',
  2833. );
  2834. }
  2835. foreach ($sp_elements as $full)
  2836. {
  2837. $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|>(.*)<\/$full>)/msiU", array(&$this, 'add_cdata'), $data);
  2838. }
  2839. foreach ($sp_elements as $full)
  2840. {
  2841. // Deal with CDATA within CDATA (this can be caused by us inserting CDATA above)
  2842. $data = preg_replace_callback("/<($full)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'))*)\s*(\/>|><!\[CDATA\[(.*)\]\]><\/$full>)/msiU", array(&$this, 'cdata_in_cdata'), $data);
  2843. }
  2844. // Return the XML, if so desired
  2845. if ($return_xml)
  2846. {
  2847. $this->data =& $data;
  2848. return;
  2849. }
  2850. // Create the parser
  2851. $this->xml = xml_parser_create_ns($encoding);
  2852. xml_parser_set_option($this->xml, XML_OPTION_SKIP_WHITE, 1);
  2853. xml_set_object($this->xml, $this);
  2854. xml_set_character_data_handler($this->xml, 'data_handler');
  2855. xml_set_element_handler($this->xml, 'start_handler', 'end_handler');
  2856. xml_set_start_namespace_decl_handler($this->xml, 'start_name_space');
  2857. xml_set_end_namespace_decl_handler($this->xml, 'end_name_space');
  2858. // Parse!
  2859. if (!xml_parse($this->xml, $data))
  2860. {
  2861. $this->data = null;
  2862. $this->error_code = xml_get_error_code($this->xml);
  2863. $this->error_string = xml_error_string($this->error_code);
  2864. }
  2865. $this->current_line = xml_get_current_line_number($this->xml);
  2866. $this->current_column = xml_get_current_column_number($this->xml);
  2867. $this->current_byte = xml_get_current_byte_index($this->xml);
  2868. xml_parser_free($this->xml);
  2869. return;
  2870. }
  2871. function add_cdata($match)
  2872. {
  2873. if (isset($match[10]))
  2874. {
  2875. $match[10] = preg_replace('/^\s*<\!\[CDATA\[/msiU', '', $match[10]);
  2876. $match[10] = preg_replace('/]]>\s*$/msiU', '', $match[10]);
  2877. return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
  2878. }
  2879. return $match[0];
  2880. }
  2881. function spencoded($match)
  2882. {
  2883. if (isset($match[10]))
  2884. {
  2885. return "<$match[1]$match[2] spencoded=\"false\"><![CDATA[$match[10]</$match[1]>";
  2886. }
  2887. return $match[0];
  2888. }
  2889. function cdata_in_cdata($match)
  2890. {
  2891. if (isset($match[10]))
  2892. {
  2893. $match[10] = preg_replace_callback('/<!\[CDATA\[(.*)\]\]>/msiU', array(&$this, 'real_cdata_in_cdata'), $match[10]);
  2894. return "<$match[1]$match[2]><![CDATA[$match[10]]]></$match[1]>";
  2895. }
  2896. return $match[0];
  2897. }
  2898. function real_cdata_in_cdata($match)
  2899. {
  2900. return htmlentities($match[1], ENT_NOQUOTES, $this->encoding);
  2901. }
  2902. function do_add_content(&$array, $data)
  2903. {
  2904. if ($this->is_first)
  2905. {
  2906. $array['data'] = $data;
  2907. $array['attribs'] = $this->attribs;
  2908. }
  2909. else
  2910. {
  2911. $array['data'] .= $data;
  2912. }
  2913. }
  2914. function start_handler($parser, $name, $attribs)
  2915. {
  2916. $this->tag_name = $name;
  2917. $this->attribs = $attribs;
  2918. $this->is_first = true;
  2919. switch ($this->tag_name)
  2920. {
  2921. case 'ITEM':
  2922. case $this->namespaces['rss2'] . ':ITEM':
  2923. case $this->namespaces['rss1'] . ':ITEM':
  2924. case 'ENTRY':
  2925. case $this->namespaces['atom'] . ':ENTRY':
  2926. $this->inside_item = true;
  2927. $this->do_add_content($this->data['items'][$this->item_number], '');
  2928. break;
  2929. case 'CHANNEL':
  2930. case $this->namespaces['rss2'] . ':CHANNEL':
  2931. case $this->namespaces['rss1'] . ':CHANNEL':
  2932. $this->inside_channel = true;
  2933. break;
  2934. case 'RSS':
  2935. case $this->namespaces['rss2'] . ':RSS':
  2936. $this->data['feedinfo']['type'] = 'RSS';
  2937. $this->do_add_content($this->data['feeddata'], '');
  2938. if (!empty($attribs['VERSION']))
  2939. {
  2940. $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
  2941. }
  2942. break;
  2943. case $this->namespaces['rdf'] . ':RDF':
  2944. $this->data['feedinfo']['type'] = 'RSS';
  2945. $this->do_add_content($this->data['feeddata'], '');
  2946. $this->data['feedinfo']['version'] = 1;
  2947. break;
  2948. case 'FEED':
  2949. case $this->namespaces['atom'] . ':FEED':
  2950. $this->data['feedinfo']['type'] = 'Atom';
  2951. $this->do_add_content($this->data['feeddata'], '');
  2952. if (!empty($attribs['VERSION']))
  2953. {
  2954. $this->data['feedinfo']['version'] = trim($attribs['VERSION']);
  2955. }
  2956. break;
  2957. case 'IMAGE':
  2958. case $this->namespaces['rss2'] . ':IMAGE':
  2959. case $this->namespaces['rss1'] . ':IMAGE':
  2960. if ($this->inside_channel)
  2961. {
  2962. $this->inside_image = true;
  2963. }
  2964. break;
  2965. }
  2966. if (!empty($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom' && ($this->tag_name == 'AUTHOR' || $this->tag_name == $this->namespaces['atom'] . ':AUTHOR'))
  2967. {
  2968. $this->inside_author = true;
  2969. }
  2970. $this->data_handler($this->xml, '');
  2971. }
  2972. function data_handler($parser, $data)
  2973. {
  2974. if ($this->inside_item)
  2975. {
  2976. switch ($this->tag_name)
  2977. {
  2978. case 'TITLE':
  2979. case $this->namespaces['rss1'] . ':TITLE':
  2980. case $this->namespaces['rss2'] . ':TITLE':
  2981. case $this->namespaces['atom'] . ':TITLE':
  2982. $this->do_add_content($this->data['items'][$this->item_number]['title'], $data);
  2983. break;
  2984. case $this->namespaces['dc'] . ':TITLE':
  2985. $this->do_add_content($this->data['items'][$this->item_number]['dc:title'], $data);
  2986. break;
  2987. case 'CONTENT':
  2988. case $this->namespaces['atom'] . ':CONTENT':
  2989. $this->do_add_content($this->data['items'][$this->item_number]['content'], $data);
  2990. break;
  2991. case $this->namespaces['content'] . ':ENCODED':
  2992. $this->do_add_content($this->data['items'][$this->item_number]['encoded'], $data);
  2993. break;
  2994. case 'SUMMARY':
  2995. case $this->namespaces['atom'] . ':SUMMARY':
  2996. $this->do_add_content($this->data['items'][$this->item_number]['summary'], $data);
  2997. break;
  2998. case 'LONGDESC':
  2999. $this->do_add_content($this->data['items'][$this->item_number]['longdesc'], $data);
  3000. break;
  3001. case 'DESCRIPTION':
  3002. case $this->namespaces['rss1'] . ':DESCRIPTION':
  3003. case $this->namespaces['rss2'] . ':DESCRIPTION':
  3004. $this->do_add_content($this->data['items'][$this->item_number]['description'], $data);
  3005. break;
  3006. case $this->namespaces['dc'] . ':DESCRIPTION':
  3007. $this->do_add_content($this->data['items'][$this->item_number]['dc:description'], $data);
  3008. break;
  3009. case 'LINK':
  3010. case $this->namespaces['rss1'] . ':LINK':
  3011. case $this->namespaces['rss2'] . ':LINK':
  3012. case $this->namespaces['atom'] . ':LINK':
  3013. $this->do_add_content($this->data['items'][$this->item_number]['link'][$this->item_link_number], $data);
  3014. break;
  3015. case 'ENCLOSURE':
  3016. case $this->namespaces['rss1'] . ':ENCLOSURE':
  3017. case $this->namespaces['rss2'] . ':ENCLOSURE':
  3018. case $this->namespaces['atom'] . ':ENCLOSURE':
  3019. $this->do_add_content($this->data['items'][$this->item_number]['enclosure'][$this->enclosure_number], $data);
  3020. break;
  3021. case 'GUID':
  3022. case $this->namespaces['rss1'] . ':GUID':
  3023. case $this->namespaces['rss2'] . ':GUID':
  3024. $this->do_add_content($this->data['items'][$this->item_number]['guid'], $data);
  3025. break;
  3026. case 'ID':
  3027. case $this->namespaces['atom'] . ':ID':
  3028. $this->do_add_content($this->data['items'][$this->item_number]['id'], $data);
  3029. break;
  3030. case 'PUBDATE':
  3031. case $this->namespaces['rss1'] . ':PUBDATE':
  3032. case $this->namespaces['rss2'] . ':PUBDATE':
  3033. $this->do_add_content($this->data['items'][$this->item_number]['pubdate'], $data);
  3034. break;
  3035. case $this->namespaces['dc'] . ':DATE':
  3036. $this->do_add_content($this->data['items'][$this->item_number]['dc:date'], $data);
  3037. break;
  3038. case 'ISSUED':
  3039. case $this->namespaces['atom'] . ':ISSUED':
  3040. $this->do_add_content($this->data['items'][$this->item_number]['issued'], $data);
  3041. break;
  3042. case 'PUBLISHED':
  3043. case $this->namespaces['atom'] . ':PUBLISHED':
  3044. $this->do_add_content($this->data['items'][$this->item_number]['published'], $data);
  3045. break;
  3046. case 'MODIFIED':
  3047. case $this->namespaces['atom'] . ':MODIFIED':
  3048. $this->do_add_content($this->data['items'][$this->item_number]['modified'], $data);
  3049. break;
  3050. case 'UPDATED':
  3051. case $this->namespaces['atom'] . ':UPDATED':
  3052. $this->do_add_content($this->data['items'][$this->item_number]['updated'], $data);
  3053. break;
  3054. case 'CATEGORY':
  3055. case $this->namespaces['rss1'] . ':CATEGORY':
  3056. case $this->namespaces['rss2'] . ':CATEGORY':
  3057. case $this->namespaces['atom'] . ':CATEGORY':
  3058. $this->do_add_content($this->data['items'][$this->item_number]['category'][$this->category_number], $data);
  3059. break;
  3060. case $this->namespaces['dc'] . ':SUBJECT':
  3061. $this->do_add_content($this->data['items'][$this->item_number]['subject'][$this->category_number], $data);
  3062. break;
  3063. case $this->namespaces['dc'] . ':CREATOR':
  3064. $this->do_add_content($this->data['items'][$this->item_number]['creator'][$this->author_number], $data);
  3065. break;
  3066. case 'AUTHOR':
  3067. case $this->namespaces['rss1'] . ':AUTHOR':
  3068. case $this->namespaces['rss2'] . ':AUTHOR':
  3069. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['rss'], $data);
  3070. break;
  3071. }
  3072. if ($this->inside_author)
  3073. {
  3074. switch ($this->tag_name)
  3075. {
  3076. case 'NAME':
  3077. case $this->namespaces['atom'] . ':NAME':
  3078. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['name'], $data);
  3079. break;
  3080. case 'URL':
  3081. case $this->namespaces['atom'] . ':URL':
  3082. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['url'], $data);
  3083. break;
  3084. case 'URI':
  3085. case $this->namespaces['atom'] . ':URI':
  3086. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['uri'], $data);
  3087. break;
  3088. case 'HOMEPAGE':
  3089. case $this->namespaces['atom'] . ':HOMEPAGE':
  3090. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['homepage'], $data);
  3091. break;
  3092. case 'EMAIL':
  3093. case $this->namespaces['atom'] . ':EMAIL':
  3094. $this->do_add_content($this->data['items'][$this->item_number]['author'][$this->author_number]['email'], $data);
  3095. break;
  3096. }
  3097. }
  3098. }
  3099. else if (($this->inside_channel && !$this->inside_image) || (isset($this->data['feedinfo']['type']) && $this->data['feedinfo']['type'] == 'Atom'))
  3100. {
  3101. switch ($this->tag_name)
  3102. {
  3103. case 'TITLE':
  3104. case $this->namespaces['rss1'] . ':TITLE':
  3105. case $this->namespaces['rss2'] . ':TITLE':
  3106. case $this->namespaces['atom'] . ':TITLE':
  3107. $this->do_add_content($this->data['info']['title'], $data);
  3108. break;
  3109. case 'LINK':
  3110. case $this->namespaces['rss1'] . ':LINK':
  3111. case $this->namespaces['rss2'] . ':LINK':
  3112. case $this->namespaces['atom'] . ':LINK':
  3113. $this->do_add_content($this->data['info']['link'][$this->link_number], $data);
  3114. break;
  3115. case 'DESCRIPTION':
  3116. case $this->namespaces['rss1'] . ':DESCRIPTION':
  3117. case $this->namespaces['rss2'] . ':DESCRIPTION':
  3118. $this->do_add_content($this->data['info']['description'], $data);
  3119. break;
  3120. case $this->namespaces['dc'] . ':DESCRIPTION':
  3121. $this->do_add_content($this->data['info']['dc:description'], $data);
  3122. break;
  3123. case 'TAGLINE':
  3124. case $this->namespaces['atom'] . ':TAGLINE':
  3125. $this->do_add_content($this->data['info']['tagline'], $data);
  3126. break;
  3127. case 'SUBTITLE':
  3128. case $this->namespaces['atom'] . ':SUBTITLE':
  3129. $this->do_add_content($this->data['info']['subtitle'], $data);
  3130. break;
  3131. case 'COPYRIGHT':
  3132. case $this->namespaces['rss1'] . ':COPYRIGHT':
  3133. case $this->namespaces['rss2'] . ':COPYRIGHT':
  3134. case $this->namespaces['atom'] . ':COPYRIGHT':
  3135. $this->do_add_content($this->data['info']['copyright'], $data);
  3136. break;
  3137. case 'LANGUAGE':
  3138. case $this->namespaces['rss1'] . ':LANGUAGE':
  3139. case $this->namespaces['rss2'] . ':LANGUAGE':
  3140. $this->do_add_content($this->data['info']['language'], $data);
  3141. break;
  3142. case 'LOGO':
  3143. case $this->namespaces['atom'] . ':LOGO':
  3144. $this->do_add_content($this->data['info']['logo'], $data);
  3145. break;
  3146. }
  3147. }
  3148. else if ($this->inside_channel && $this->inside_image)
  3149. {
  3150. switch ($this->tag_name)
  3151. {
  3152. case 'TITLE':
  3153. case $this->namespaces['rss1'] . ':TITLE':
  3154. case $this->namespaces['rss2'] . ':TITLE':
  3155. $this->do_add_content($this->data['info']['image']['title'], $data);
  3156. break;
  3157. case 'URL':
  3158. case $this->namespaces['rss1'] . ':URL':
  3159. case $this->namespaces['rss2'] . ':URL':
  3160. $this->do_add_content($this->data['info']['image']['url'], $data);
  3161. break;
  3162. case 'LINK':
  3163. case $this->namespaces['rss1'] . ':LINK':
  3164. case $this->namespaces['rss2'] . ':LINK':
  3165. $this->do_add_content($this->data['info']['image']['link'], $data);
  3166. break;
  3167. case 'WIDTH':
  3168. case $this->namespaces['rss1'] . ':WIDTH':
  3169. case $this->namespaces['rss2'] . ':WIDTH':
  3170. $this->do_add_content($this->data['info']['image']['width'], $data);
  3171. break;
  3172. case 'HEIGHT':
  3173. case $this->namespaces['rss1'] . ':HEIGHT':
  3174. case $this->namespaces['rss2'] . ':HEIGHT':
  3175. $this->do_add_content($this->data['info']['image']['height'], $data);
  3176. break;
  3177. }
  3178. }
  3179. $this->is_first = false;
  3180. }
  3181. function end_handler($parser, $name)
  3182. {
  3183. $this->tag_name = '';
  3184. switch ($name)
  3185. {
  3186. case 'ITEM':
  3187. case $this->namespaces['rss1'] . ':ITEM':
  3188. case $this->namespaces['rss2'] . ':ITEM':
  3189. case 'ENTRY':
  3190. case $this->namespaces['atom'] . ':ENTRY':
  3191. $this->inside_item = false;
  3192. $this->item_number++;
  3193. $this->author_number = 0;
  3194. $this->category_number = 0;
  3195. $this->enclosure_number = 0;
  3196. $this->item_link_number = 0;
  3197. break;
  3198. case 'CHANNEL':
  3199. case $this->namespaces['rss1'] . ':CHANNEL':
  3200. case $this->namespaces['rss2'] . ':CHANNEL':
  3201. $this->inside_channel = false;
  3202. break;
  3203. case 'IMAGE':
  3204. case $this->namespaces['rss1'] . ':IMAGE':
  3205. case $this->namespaces['rss2'] . ':IMAGE':
  3206. $this->inside_image = false;
  3207. break;
  3208. case 'AUTHOR':
  3209. case $this->namespaces['rss1'] . ':AUTHOR':
  3210. case $this->namespaces['rss2'] . ':AUTHOR':
  3211. case $this->namespaces['atom'] . ':AUTHOR':
  3212. $this->author_number++;
  3213. $this->inside_author = false;
  3214. break;
  3215. case 'CATEGORY':
  3216. case $this->namespaces['rss1'] . ':CATEGORY':
  3217. case $this->namespaces['rss2'] . ':CATEGORY':
  3218. case $this->namespaces['atom'] . ':CATEGORY':
  3219. case $this->namespaces['dc'] . ':SUBJECT':
  3220. $this->category_number++;
  3221. break;
  3222. case 'ENCLOSURE':
  3223. case $this->namespaces['rss1'] . ':ENCLOSURE':
  3224. case $this->namespaces['rss2'] . ':ENCLOSURE':
  3225. $this->enclosure_number++;
  3226. break;
  3227. case 'LINK':
  3228. case $this->namespaces['rss1'] . ':LINK':
  3229. case $this->namespaces['rss2'] . ':LINK':
  3230. case $this->namespaces['atom'] . ':LINK':
  3231. if ($this->inside_item)
  3232. {
  3233. $this->item_link_number++;
  3234. }
  3235. else
  3236. {
  3237. $this->link_number++;
  3238. }
  3239. break;
  3240. }
  3241. }
  3242. function start_name_space($parser, $prefix, $uri = null)
  3243. {
  3244. $prefix = strtoupper($prefix);
  3245. $uri = strtoupper($uri);
  3246. if ($prefix == 'ATOM' || $uri == 'HTTP://WWW.W3.ORG/2005/ATOM' || $uri == 'HTTP://PURL.ORG/ATOM/NS#')
  3247. {
  3248. $this->namespaces['atom'] = $uri;
  3249. }
  3250. else if ($prefix == 'RSS2' || $uri == 'HTTP://BACKEND.USERLAND.COM/RSS2')
  3251. {
  3252. $this->namespaces['rss2'] = $uri;
  3253. }
  3254. else if ($prefix == 'RDF' || $uri == 'HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#')
  3255. {
  3256. $this->namespaces['rdf'] = $uri;
  3257. }
  3258. else if ($prefix == 'RSS' || $uri == 'HTTP://PURL.ORG/RSS/1.0/' || $uri == 'HTTP://MY.NETSCAPE.COM/RDF/SIMPLE/0.9/')
  3259. {
  3260. $this->namespaces['rss1'] = $uri;
  3261. }
  3262. else if ($prefix == 'DC' || $uri == 'HTTP://PURL.ORG/DC/ELEMENTS/1.1/')
  3263. {
  3264. $this->namespaces['dc'] = $uri;
  3265. }
  3266. else if ($prefix == 'XHTML' || $uri == 'HTTP://WWW.W3.ORG/1999/XHTML')
  3267. {
  3268. $this->namespaces['xhtml'] = $uri;
  3269. $this->xhtml_prefix = $prefix;
  3270. }
  3271. else if ($prefix == 'CONTENT' || $uri == 'HTTP://PURL.ORG/RSS/1.0/MODULES/CONTENT/')
  3272. {
  3273. $this->namespaces['content'] = $uri;
  3274. }
  3275. }
  3276. function end_name_space($parser, $prefix)
  3277. {
  3278. if ($key = array_search(strtoupper($prefix), $this->namespaces))
  3279. {
  3280. if ($key == 'atom')
  3281. {
  3282. $this->namespaces['atom'] = 'ATOM';
  3283. }
  3284. else if ($key == 'rss2')
  3285. {
  3286. $this->namespaces['rss2'] = 'RSS';
  3287. }
  3288. else if ($key == 'rdf')
  3289. {
  3290. $this->namespaces['rdf'] = 'RDF';
  3291. }
  3292. else if ($key == 'rss1')
  3293. {
  3294. $this->namespaces['rss1'] = 'RSS';
  3295. }
  3296. else if ($key == 'dc')
  3297. {
  3298. $this->namespaces['dc'] = 'DC';
  3299. }
  3300. else if ($key == 'xhtml')
  3301. {
  3302. $this->namespaces['xhtml'] = 'XHTML';
  3303. $this->xhtml_prefix = 'XHTML';
  3304. }
  3305. else if ($key == 'content')
  3306. {
  3307. $this->namespaces['content'] = 'CONTENT';
  3308. }
  3309. }
  3310. }
  3311. }
  3312. class SimplePie_Sanitize
  3313. {
  3314. // Private vars
  3315. var $feedinfo;
  3316. var $info;
  3317. var $items;
  3318. var $feed_xmlbase;
  3319. var $item_xmlbase;
  3320. var $attribs;
  3321. // Options
  3322. var $remove_div = true;
  3323. var $strip_ads = true;
  3324. var $replace_headers = false;
  3325. var $bypass_image_hotlink = 'i';
  3326. var $bypass_image_hotlink_page = false;
  3327. var $strip_htmltags = array('blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
  3328. var $encode_instead_of_strip = false;
  3329. var $strip_attributes = array('class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur');
  3330. function remove_div($enable = true)
  3331. {
  3332. $this->remove_div = (bool) $enable;
  3333. }
  3334. function strip_ads($enable = true)
  3335. {
  3336. $this->strip_ads = (bool) $enable;
  3337. }
  3338. function replace_headers($enable = false)
  3339. {
  3340. $this->enable_headers = (bool) $enable;
  3341. }
  3342. function bypass_image_hotlink($get = 'i')
  3343. {
  3344. if ($get)
  3345. {
  3346. $this->bypass_image_hotlink = (string) $get;
  3347. }
  3348. else
  3349. {
  3350. $this->bypass_image_hotlink = false;
  3351. }
  3352. }
  3353. function bypass_image_hotlink_page($page = false)
  3354. {
  3355. if ($page)
  3356. {
  3357. $this->bypass_image_hotlink_page = (string) $page;
  3358. }
  3359. else
  3360. {
  3361. $this->bypass_image_hotlink_page = false;
  3362. }
  3363. }
  3364. function strip_htmltags($tags = array('blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'))
  3365. {
  3366. if ($tags)
  3367. {
  3368. if (is_array($tags))
  3369. {
  3370. $this->strip_htmltags = $tags;
  3371. }
  3372. else
  3373. {
  3374. $this->strip_htmltags = explode(',', $tags);
  3375. }
  3376. }
  3377. else
  3378. {
  3379. $this->strip_htmltags = false;
  3380. }
  3381. }
  3382. function encode_instead_of_strip($enable = false)
  3383. {
  3384. $this->encode_instead_of_strip = (bool) $enable;
  3385. }
  3386. function strip_attributes($attribs = array('class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
  3387. {
  3388. if ($attribs)
  3389. {
  3390. if (is_array($attribs))
  3391. {
  3392. $this->strip_attributes = $attribs;
  3393. }
  3394. else
  3395. {
  3396. $this->strip_attributes = explode(',', $attribs);
  3397. }
  3398. }
  3399. else
  3400. {
  3401. $this->strip_attributes = false;
  3402. }
  3403. }
  3404. function parse_data_array(&$data)
  3405. {
  3406. // Feed Info (Type and Version)
  3407. if (!empty($data['feedinfo']['type']))
  3408. {
  3409. $this->feedinfo = $data['feedinfo'];
  3410. }
  3411. // Feed level xml:base
  3412. if (!empty($data['feeddata']['attribs']['XML:BASE']))
  3413. {
  3414. $this->feed_xmlbase = parse_url($data['feeddata']['attribs']['XML:BASE']);
  3415. }
  3416. else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
  3417. {
  3418. $this->feed_xmlbase = parse_url($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']);
  3419. }
  3420. // Feed link(s)
  3421. if (!empty($data['info']['link']))
  3422. {
  3423. foreach ($data['info']['link'] as $link)
  3424. {
  3425. if (empty($link['attribs']['REL']))
  3426. {
  3427. $rel = 'alternate';
  3428. }
  3429. else
  3430. {
  3431. $rel = strtolower($link['attribs']['REL']);
  3432. }
  3433. if ($rel == 'enclosure')
  3434. {
  3435. $href = null;
  3436. $type = null;
  3437. $length = null;
  3438. if (!empty($link['data']))
  3439. {
  3440. $href = $this->sanitize($link['data'], $link['attribs'], true);
  3441. }
  3442. else if (!empty($link['attribs']['HREF']))
  3443. {
  3444. $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3445. }
  3446. if (!empty($link['attribs']['TYPE'])) {
  3447. $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
  3448. }
  3449. if (!empty($link['attribs']['LENGTH'])) {
  3450. $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
  3451. }
  3452. $this->info['link']['enclosure'][] = new SimplePie_Enclosure($href, $type, $length);
  3453. }
  3454. else
  3455. {
  3456. if (!empty($link['data']))
  3457. {
  3458. $this->info['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
  3459. }
  3460. else if (!empty($link['attribs']['HREF']))
  3461. {
  3462. $this->info['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3463. }
  3464. }
  3465. }
  3466. }
  3467. // Use the first alternate link if we don't have any feed xml:base
  3468. if (empty($this->feed_xmlbase) && !empty($this->info['link']['alternate'][0]))
  3469. {
  3470. $this->feed_xmlbase = parse_url($this->info['link']['alternate'][0]);
  3471. }
  3472. // Feed Title
  3473. if (!empty($data['info']['title']['data']))
  3474. {
  3475. $this->info['title'] = $this->sanitize($data['info']['title']['data'], $data['info']['title']['attribs']);
  3476. }
  3477. // Feed Descriptions
  3478. if (!empty($data['info']['description']['data']))
  3479. {
  3480. $this->info['description'] = $this->sanitize($data['info']['description']['data'], $data['info']['description']['attribs']);
  3481. }
  3482. if (!empty($data['info']['dc:description']['data']))
  3483. {
  3484. $this->info['dc:description'] = $this->sanitize($data['info']['dc:description']['data'], $data['info']['dc:description']['attribs']);
  3485. }
  3486. if (!empty($data['info']['tagline']['data']))
  3487. {
  3488. $this->info['tagline'] = $this->sanitize($data['info']['tagline']['data'], $data['info']['tagline']['attribs']);
  3489. }
  3490. if (!empty($data['info']['subtitle']['data']))
  3491. {
  3492. $this->info['subtitle'] = $this->sanitize($data['info']['subtitle']['data'], $data['info']['subtitle']['attribs']);
  3493. }
  3494. // Feed Language
  3495. if (!empty($data['info']['language']['data']))
  3496. {
  3497. $this->info['language'] = $this->sanitize($data['info']['language']['data'], $data['info']['language']['attribs']);
  3498. }
  3499. if (!empty($data['feeddata']['attribs']['XML:LANG']))
  3500. {
  3501. $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['XML:LANG'], null);
  3502. }
  3503. else if (!empty($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG']))
  3504. {
  3505. $this->info['xml:lang'] = $this->sanitize($data['feeddata']['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:LANG'], null);
  3506. }
  3507. // Feed Copyright
  3508. if (!empty($data['info']['copyright']['data']))
  3509. {
  3510. $this->info['copyright'] = $this->sanitize($data['info']['copyright']['data'], $data['info']['copyright']['attribs']);
  3511. }
  3512. // Feed Image
  3513. if (!empty($data['info']['image']['title']['data']))
  3514. {
  3515. $this->info['image']['title'] = $this->sanitize($data['info']['image']['title']['data'], $data['info']['image']['title']['attribs']);
  3516. }
  3517. if (!empty($data['info']['image']['url']['data']))
  3518. {
  3519. $this->info['image']['url'] = $this->sanitize($data['info']['image']['url']['data'], $data['info']['image']['url']['attribs'], true);
  3520. }
  3521. if (!empty($data['info']['logo']['data']))
  3522. {
  3523. $this->info['image']['logo'] = $this->sanitize($data['info']['logo']['data'], $data['info']['logo']['attribs'], true);
  3524. }
  3525. if (!empty($data['info']['image']['link']['data']))
  3526. {
  3527. $this->info['image']['link'] = $this->sanitize($data['info']['image']['link']['data'], $data['info']['image']['link']['attribs'], true);
  3528. }
  3529. if (!empty($data['info']['image']['width']['data']))
  3530. {
  3531. $this->info['image']['width'] = $this->sanitize($data['info']['image']['width']['data'], $data['info']['image']['width']['attribs']);
  3532. }
  3533. if (!empty($data['info']['image']['height']['data']))
  3534. {
  3535. $this->info['image']['height'] = $this->sanitize($data['info']['image']['height']['data'], $data['info']['image']['height']['attribs']);
  3536. }
  3537. // Items
  3538. if (!empty($data['items']))
  3539. {
  3540. foreach ($data['items'] as $key => $item)
  3541. {
  3542. $newitem = null;
  3543. // Item level xml:base
  3544. if (!empty($item['attribs']['XML:BASE']))
  3545. {
  3546. $this->item_xmlbase = parse_url(SimplePie_Misc::absolutize_url($item['attribs']['XML:BASE'], $this->feed_xmlbase));
  3547. }
  3548. else if (!empty($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
  3549. {
  3550. $this->item_xmlbase = parse_url(SimplePie_Misc::absolutize_url($item['attribs']['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'], $this->feed_xmlbase));
  3551. }
  3552. else
  3553. {
  3554. $this->item_xmlbase = null;
  3555. }
  3556. // Title
  3557. if (!empty($item['title']['data'])) {
  3558. $newitem['title'] = $this->sanitize($item['title']['data'], $item['title']['attribs']);
  3559. }
  3560. if (!empty($item['dc:title']['data']))
  3561. {
  3562. $newitem['dc:title'] = $this->sanitize($item['dc:title']['data'], $item['dc:title']['attribs']);
  3563. }
  3564. // Description
  3565. if (!empty($item['content']['data']))
  3566. {
  3567. $newitem['content'] = $this->sanitize($item['content']['data'], $item['content']['attribs']);
  3568. }
  3569. if (!empty($item['encoded']['data']))
  3570. {
  3571. $newitem['encoded'] = $this->sanitize($item['encoded']['data'], $item['encoded']['attribs']);
  3572. }
  3573. if (!empty($item['summary']['data']))
  3574. {
  3575. $newitem['summary'] = $this->sanitize($item['summary']['data'], $item['summary']['attribs']);
  3576. }
  3577. if (!empty($item['description']['data']))
  3578. {
  3579. $newitem['description'] = $this->sanitize($item['description']['data'], $item['description']['attribs']);
  3580. }
  3581. if (!empty($item['dc:description']['data']))
  3582. {
  3583. $newitem['dc:description'] = $this->sanitize($item['dc:description']['data'], $item['dc:description']['attribs']);
  3584. }
  3585. if (!empty($item['longdesc']['data']))
  3586. {
  3587. $newitem['longdesc'] = $this->sanitize($item['longdesc']['data'], $item['longdesc']['attribs']);
  3588. }
  3589. // Link(s)
  3590. if (!empty($item['link']))
  3591. {
  3592. foreach ($item['link'] as $link)
  3593. {
  3594. if (empty($link['attribs']['REL']))
  3595. {
  3596. $rel = 'alternate';
  3597. }
  3598. else
  3599. {
  3600. $rel = strtolower($link['attribs']['REL']);
  3601. }
  3602. if ($rel == 'enclosure')
  3603. {
  3604. $href = null;
  3605. $type = null;
  3606. $length = null;
  3607. if (!empty($link['data']))
  3608. {
  3609. $href = $this->sanitize($link['data'], $link['attribs'], true);
  3610. }
  3611. else if (!empty($link['attribs']['HREF']))
  3612. {
  3613. $href = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3614. }
  3615. if (!empty($link['attribs']['TYPE'])) {
  3616. $type = $this->sanitize($link['attribs']['TYPE'], $link['attribs']);
  3617. }
  3618. if (!empty($link['attribs']['LENGTH'])) {
  3619. $length = $this->sanitize($link['attribs']['LENGTH'], $link['attribs']);
  3620. }
  3621. if (!empty($href))
  3622. {
  3623. $newitem['link'][$rel][] = new SimplePie_Enclosure($href, $type, $length);
  3624. }
  3625. }
  3626. else
  3627. {
  3628. if (!empty($link['data']))
  3629. {
  3630. $newitem['link'][$rel][] = $this->sanitize($link['data'], $link['attribs'], true);
  3631. }
  3632. else if (!empty($link['attribs']['HREF']))
  3633. {
  3634. $newitem['link'][$rel][] = $this->sanitize($link['attribs']['HREF'], $link['attribs'], true);
  3635. }
  3636. }
  3637. }
  3638. }
  3639. // Enclosure(s)
  3640. if (!empty($item['enclosure']))
  3641. {
  3642. foreach ($item['enclosure'] as $enclosure)
  3643. {
  3644. if (!empty($enclosure['attribs']['URL']))
  3645. {
  3646. $type = null;
  3647. $length = null;
  3648. $href = $this->sanitize($enclosure['attribs']['URL'], $enclosure['attribs'], true);
  3649. if (!empty($enclosure['attribs']['TYPE']))
  3650. {
  3651. $type = $this->sanitize($enclosure['attribs']['TYPE'], $enclosure['attribs']);
  3652. }
  3653. if (!empty($enclosure['attribs']['LENGTH']))
  3654. {
  3655. $length = $this->sanitize($enclosure['attribs']['LENGTH'], $enclosure['attribs']);
  3656. }
  3657. $newitem['enclosures'][] = new SimplePie_Enclosure($href, $type, $length);
  3658. }
  3659. }
  3660. }
  3661. // ID
  3662. if (!empty($item['guid']['data']))
  3663. {
  3664. if (!empty($item['guid']['attribs']['ISPERMALINK']) && strtolower($item['guid']['attribs']['ISPERMALINK']) == 'false')
  3665. {
  3666. $newitem['guid']['permalink'] = false;
  3667. }
  3668. else
  3669. {
  3670. $newitem['guid']['permalink'] = true;
  3671. }
  3672. $newitem['guid']['data'] = $this->sanitize($item['guid']['data'], $item['guid']['attribs']);
  3673. }
  3674. if (!empty($item['id']['data']))
  3675. {
  3676. $newitem['id'] = $this->sanitize($item['id']['data'], $item['id']['attribs']);
  3677. }
  3678. // Date
  3679. if (!empty($item['pubdate']['data']))
  3680. {
  3681. $newitem['pubdate'] = $this->parse_date($this->sanitize($item['pubdate']['data'], $item['pubdate']['attribs']));
  3682. }
  3683. if (!empty($item['dc:date']['data']))
  3684. {
  3685. $newitem['dc:date'] = $this->parse_date($this->sanitize($item['dc:date']['data'], $item['dc:date']['attribs']));
  3686. }
  3687. if (!empty($item['issued']['data']))
  3688. {
  3689. $newitem['issued'] = $this->parse_date($this->sanitize($item['issued']['data'], $item['issued']['attribs']));
  3690. }
  3691. if (!empty($item['published']['data']))
  3692. {
  3693. $newitem['published'] = $this->parse_date($this->sanitize($item['published']['data'], $item['published']['attribs']));
  3694. }
  3695. if (!empty($item['modified']['data']))
  3696. {
  3697. $newitem['modified'] = $this->parse_date($this->sanitize($item['modified']['data'], $item['modified']['attribs']));
  3698. }
  3699. if (!empty($item['updated']['data']))
  3700. {
  3701. $newitem['updated'] = $this->parse_date($this->sanitize($item['updated']['data'], $item['updated']['attribs']));
  3702. }
  3703. // Categories
  3704. if (!empty($item['category']))
  3705. {
  3706. foreach ($item['category'] as $category)
  3707. {
  3708. if (!empty($category['data']))
  3709. {
  3710. $newitem['category'][] = $this->sanitize($category['data'], $category['attribs']);
  3711. }
  3712. }
  3713. }
  3714. if (!empty($item['subject']))
  3715. {
  3716. foreach ($item['subject'] as $category)
  3717. {
  3718. if (!empty($category['data']))
  3719. {
  3720. $newitem['subject'][] = $this->sanitize($category['data'], $category['attribs']);
  3721. }
  3722. }
  3723. }
  3724. // Author
  3725. if (!empty($item['creator']))
  3726. {
  3727. foreach ($item['creator'] as $creator)
  3728. {
  3729. if (!empty($creator['data']))
  3730. {
  3731. $newitem['creator'][] = new SimplePie_Author($this->sanitize($creator['data'], $creator['attribs']), null, null);
  3732. }
  3733. }
  3734. }
  3735. if (!empty($item['author']))
  3736. {
  3737. foreach ($item['author'] as $author)
  3738. {
  3739. $name = null;
  3740. $link = null;
  3741. $email = null;
  3742. if (!empty($author['rss']))
  3743. {
  3744. $sane = $this->sanitize($author['rss']['data'], $author['rss']['attribs']);
  3745. if (preg_match('/(.*)@(.*) \((.*)\)/msiU', $sane, $matches)) {
  3746. $name = trim($matches[3]);
  3747. $email = trim("$matches[1]@$matches[2]");
  3748. } else {
  3749. $email = $sane;
  3750. }
  3751. }
  3752. else
  3753. {
  3754. if (!empty($author['name']))
  3755. {
  3756. $name = $this->sanitize($author['name']['data'], $author['name']['attribs']);
  3757. }
  3758. if (!empty($author['url']))
  3759. {
  3760. $link = $this->sanitize($author['url']['data'], $author['url']['attribs'], true);
  3761. }
  3762. else if (!empty($author['uri']))
  3763. {
  3764. $link = $this->sanitize($author['uri']['data'], $author['uri']['attribs'], true);
  3765. }
  3766. else if (!empty($author['homepage']))
  3767. {
  3768. $link = $this->sanitize($author['homepage']['data'], $author['homepage']['attribs'], true);
  3769. }
  3770. if (!empty($author['email'])) {
  3771. $email = $this->sanitize($author['email']['data'], $author['email']['attribs']);
  3772. }
  3773. }
  3774. $newitem['author'][] = new SimplePie_Author($name, $link, $email);
  3775. }
  3776. }
  3777. unset($data['items'][$key]);
  3778. $this->items[] = new SimplePie_Item($newitem);
  3779. }
  3780. }
  3781. }
  3782. function sanitize($data, $attribs, $is_url = false)
  3783. {
  3784. $this->attribs = $attribs;
  3785. if (isset($this->feedinfo['type']) && $this->feedinfo['type'] == 'Atom')
  3786. {
  3787. if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'base64') || (!empty($attribs['TYPE']) && $attribs['TYPE'] == 'application/octet-stream'))
  3788. {
  3789. $data = trim($data);
  3790. $data = base64_decode($data);
  3791. }
  3792. else if ((!empty($attribs['MODE']) && $attribs['MODE'] == 'escaped' || !empty($attribs['TYPE']) && ($attribs['TYPE'] == 'html' || $attribs['TYPE'] == 'text/html')) && (empty($attribs['SPENCODED']) || $attribs['SPENCODED'] != 'false'))
  3793. {
  3794. $data = $this->entities_decode($data);
  3795. }
  3796. if (!empty($attribs['TYPE']) && ($attribs['TYPE'] == 'xhtml' || $attribs['TYPE'] == 'application/xhtml+xml'))
  3797. {
  3798. if ($this->remove_div)
  3799. {
  3800. $data = preg_replace('/<div( .*)?>/msiU', '', strrev(preg_replace('/>vid\/</i', '', strrev($data), 1)), 1);
  3801. }
  3802. else
  3803. {
  3804. $data = preg_replace('/<div( .*)?>/msiU', '<div>', $data, 1);
  3805. }
  3806. }
  3807. }
  3808. else
  3809. {
  3810. if (empty($attribs['SPENCODED']) || $attribs['SPENCODED'] != 'false')
  3811. {
  3812. $data = $this->entities_decode($data);
  3813. }
  3814. }
  3815. $data = trim($data);
  3816. $data = str_replace(' spencoded="false">', '>', $data);
  3817. // If Strip Ads is enabled, strip them.
  3818. if ($this->strip_ads)
  3819. {
  3820. $data = preg_replace('/<a (.*)href=(.*)click\.phdo\?s=(.*)<\/a>/msiU', '', $data); // Pheedo links (tested with Dooce.com)
  3821. $data = preg_replace('/<p(.*)>(.*)<a href="http:\/\/ad.doubleclick.net\/jump\/(.*)<\/p>/msiU', '', $data); // Doubleclick links (tested with InfoWorld.com)
  3822. $data = preg_replace('/<p><map (.*)name=(.*)google_ad_map(.*)<\/p>/msiU', '', $data); // Google AdSense for Feeds (tested with tuaw.com).
  3823. // Feedflare, from Feedburner
  3824. }
  3825. // Replace H1, H2, and H3 tags with the less important H4 tags.
  3826. // This is because on a site, the more important headers might make sense,
  3827. // but it most likely doesn't fit in the context of RSS-in-a-webpage.
  3828. if ($this->replace_headers)
  3829. {
  3830. $data = preg_replace('/<h[1-3]((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*>/msiU', '<h4\\1>', $data);
  3831. $data = preg_replace('/<\/h[1-3]>/i', '</h4>', $data);
  3832. }
  3833. if ($is_url)
  3834. {
  3835. $data = $this->replace_urls($data, true);
  3836. }
  3837. else
  3838. {
  3839. $data = preg_replace_callback('/<(\S+)((\s*((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(.*)))*)\s*(\/>|>(.*)<\/\S+>)/msiU', array(&$this, 'replace_urls'), $data);
  3840. }
  3841. // If Bypass Image Hotlink is enabled, rewrite all the image tags.
  3842. if ($this->bypass_image_hotlink)
  3843. {
  3844. $images = SimplePie_Misc::get_element('img', $data);
  3845. foreach ($images as $img)
  3846. {
  3847. if (!empty($img['attribs']['SRC']['data']))
  3848. {
  3849. $pre = '';
  3850. if ($this->bypass_image_hotlink_page)
  3851. {
  3852. $pre = $this->bypass_image_hotlink_page;
  3853. }
  3854. $pre .= "?$this->bypass_image_hotlink=";
  3855. $img['attribs']['SRC']['data'] = $pre . rawurlencode(strtr($img['attribs']['SRC']['data'], array_flip(get_html_translation_table(HTML_SPECIALCHARS, ENT_QUOTES))));
  3856. $data = str_replace($img['full'], SimplePie_Misc::element_implode($img), $data);
  3857. }
  3858. }
  3859. }
  3860. // Strip out HTML tags and attributes that might cause various security problems.
  3861. // Based on recommendations by Mark Pilgrim at:
  3862. // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely
  3863. if ($this->strip_htmltags)
  3864. {
  3865. foreach ($this->strip_htmltags as $tag)
  3866. {
  3867. $data = preg_replace_callback("/<($tag)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*(\/>|>(.*)<\/$tag>)/msiU", array(&$this, 'do_strip_htmltags'), $data);
  3868. }
  3869. }
  3870. if ($this->strip_attributes)
  3871. {
  3872. foreach ($this->strip_attributes as $attrib)
  3873. {
  3874. $data = preg_replace('/ '. trim($attrib) .'=("|&quot;)(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\'|&apos;|<|>|\+|{|})*("|&quot;)/i', '', $data);
  3875. $data = preg_replace('/ '. trim($attrib) .'=(\'|&apos;)(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|"|&quot;|<|>|\+|{|})*(\'|&apos;)/i', '', $data);
  3876. $data = preg_replace('/ '. trim($attrib) .'=(\w|\s|=|-|:|;|\/|\.|\?|&|,|#|!|\(|\)|\+|{|})*/i', '', $data);
  3877. }
  3878. }
  3879. return $data;
  3880. }
  3881. function do_strip_htmltags($match)
  3882. {
  3883. if ($this->encode_instead_of_strip)
  3884. {
  3885. if (isset($match[11]))
  3886. {
  3887. return "&lt;$match[1]$match[2]&gt;$match[11]&lt;/$match[1]&gt;";
  3888. }
  3889. else
  3890. {
  3891. return "&lt;$match[1]$match[2]/&gt;";
  3892. }
  3893. }
  3894. else
  3895. {
  3896. if (isset($match[11]))
  3897. {
  3898. return $match[11];
  3899. }
  3900. else
  3901. {
  3902. return '';
  3903. }
  3904. }
  3905. }
  3906. function replace_urls($data, $raw_url = false)
  3907. {
  3908. if (!empty($this->attribs['XML:BASE']))
  3909. {
  3910. $xmlbase = $attribs['XML:BASE'];
  3911. }
  3912. else if (!empty($this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE']))
  3913. {
  3914. $xmlbase = $this->attribs['HTTP://WWW.W3.ORG/XML/1998/NAMESPACE:BASE'];
  3915. }
  3916. if (!empty($xmlbase))
  3917. {
  3918. if (!empty($this->item_xmlbase))
  3919. {
  3920. $xmlbase = parse_url(SimplePie_Misc::absolutize_url($xmlbase, $this->item_xmlbase));
  3921. }
  3922. else
  3923. {
  3924. $xmlbase = parse_url(SimplePie_Misc::absolutize_url($xmlbase, $this->feed_xmlbase));
  3925. }
  3926. }
  3927. else if (!empty($this->item_xmlbase))
  3928. {
  3929. $xmlbase = $this->item_xmlbase;
  3930. }
  3931. else
  3932. {
  3933. $xmlbase = $this->feed_xmlbase;
  3934. }
  3935. if ($raw_url)
  3936. {
  3937. return SimplePie_Misc::absolutize_url($data, $xmlbase);
  3938. }
  3939. else
  3940. {
  3941. $attributes = array(
  3942. 'background',
  3943. 'href',
  3944. 'src',
  3945. 'longdesc',
  3946. 'usemap',
  3947. 'codebase',
  3948. 'data',
  3949. 'classid',
  3950. 'cite',
  3951. 'action',
  3952. 'profile',
  3953. 'for'
  3954. );
  3955. foreach ($attributes as $attribute)
  3956. {
  3957. if (preg_match("/$attribute='(.*)'/siU", $data[0], $attrib) || preg_match("/$attribute=\"(.*)\"/siU", $data[0], $attrib) || preg_match("/$attribute=(.*)[ |\/|>]/siU", $data[0], $attrib))
  3958. {
  3959. $new_tag = str_replace($attrib[1], SimplePie_Misc::absolutize_url($attrib[1], $xmlbase), $attrib[0]);
  3960. $data[0] = str_replace($attrib[0], $new_tag, $data[0]);
  3961. }
  3962. }
  3963. return $data[0];
  3964. }
  3965. }
  3966. function entities_decode($data) {
  3967. return preg_replace_callback('/&(#)?(x)?([0-9a-z]+);/mi', array(&$this, 'do_entites_decode'), $data);
  3968. }
  3969. function do_entites_decode($data)
  3970. {
  3971. $entity_html = utf8_encode(html_entity_decode($data[0], ENT_QUOTES));
  3972. if ($data[0] == $entity_html) {
  3973. return preg_replace_callback('/&#([0-9a-fx]+);/mi', array(&$this, 'replace_num_entity'), $data[0]);
  3974. } else {
  3975. return $entity_html;
  3976. }
  3977. }
  3978. /*
  3979. * Escape numeric entities
  3980. * From a PHP Manual note (on html_entity_decode())
  3981. * Copyright (c) 2005 by "php dot net at c dash ovidiu dot tk",
  3982. * "emilianomartinezluque at yahoo dot com" and "hurricane at cyberworldz dot org".
  3983. *
  3984. * This material may be distributed only subject to the terms and conditions set forth in
  3985. * the Open Publication License, v1.0 or later (the latest version is presently available at
  3986. * http://www.opencontent.org/openpub/).
  3987. */
  3988. function replace_num_entity($ord) {
  3989. $ord = $ord[1];
  3990. if (preg_match('/^x([0-9a-f]+)$/i', $ord, $match))
  3991. $ord = hexdec($match[1]);
  3992. else
  3993. $ord = intval($ord);
  3994. $no_bytes = 0;
  3995. $byte = array();
  3996. if ($ord < 128)
  3997. return chr($ord);
  3998. if ($ord < 2048)
  3999. $no_bytes = 2;
  4000. else if ($ord < 65536)
  4001. $no_bytes = 3;
  4002. else if ($ord < 1114112)
  4003. $no_bytes = 4;
  4004. else return;
  4005. switch ($no_bytes) {
  4006. case 2:
  4007. $prefix = array(31, 192);
  4008. break;
  4009. case 3:
  4010. $prefix = array(15, 224);
  4011. break;
  4012. case 4:
  4013. $prefix = array(7, 240);
  4014. break;
  4015. }
  4016. for ($i=0; $i < $no_bytes; ++$i)
  4017. $byte[$no_bytes-$i-1] = (($ord & (63 * pow(2,6*$i))) / pow(2,6*$i)) & 63 | 128;
  4018. $byte[0] = ($byte[0] & $prefix[0]) | $prefix[1];
  4019. $ret = '';
  4020. for ($i=0; $i < $no_bytes; ++$i)
  4021. $ret .= chr($byte[$i]);
  4022. return $ret;
  4023. }
  4024. function parse_date($date)
  4025. {
  4026. 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))
  4027. {
  4028. if (isset($matches[8]) && $matches[8] >= 50)
  4029. {
  4030. $matches[6]++;
  4031. }
  4032. $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[6] -0000");
  4033. }
  4034. 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))
  4035. {
  4036. var_dump($date);
  4037. if (isset($matches[9]) && $matches[9] >= 50)
  4038. {
  4039. $matches[6]++;
  4040. }
  4041. if (empty($matches[7]))
  4042. {
  4043. $matches[7] = '00';
  4044. }
  4045. $date = strtotime("$matches[1]-$matches[2]-$matches[3] $matches[4]:$matches[5]:$matches[7] $matches[10]$matches[11]$matches[12]");
  4046. }
  4047. 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))
  4048. {
  4049. $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);
  4050. $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', 'J' => '+0900');
  4051. $north_american_timezone = array('GMT' => '-0000', 'EST' => '-0500', 'EDT' => '-0400', 'CST' => '-0600', 'CDT' => '-0500', 'MST' => '-0700', 'MDT' => '-0600', 'PST' => '-0800', 'PDT' => '-0700');
  4052. $month = $three_month[$matches[2]];
  4053. if (strlen($matches[3]) == 2)
  4054. {
  4055. $year = ($matches[3] < 70) ? "20$matches[3]" : "19$matches[3]";
  4056. }
  4057. else
  4058. {
  4059. $year = $matches[3];
  4060. }
  4061. $second = (empty($matches[7])) ? '00' : $matches[7];
  4062. switch (strlen($matches[8]))
  4063. {
  4064. case 1:
  4065. $timezone = $military_timezone[strtoupper($matches[8])];
  4066. break;
  4067. case 2:
  4068. $timezone = '-0000';
  4069. break;
  4070. case 3:
  4071. $timezone = $north_american_timezone[strtoupper($matches[8])];
  4072. break;
  4073. default:
  4074. $timezone = $matches[8];
  4075. }
  4076. $date = strtotime("$year-$month-$matches[1] $matches[4]:$matches[5]:$second $timezone");
  4077. }
  4078. else
  4079. {
  4080. $date = strtotime($date);
  4081. }
  4082. return ($date > 0) ? $date : false;
  4083. }
  4084. }
  4085. ?>