PageRenderTime 71ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/simplepie/simplepie_060828.inc

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