PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/simplepie/simplepie_060803.inc

https://github.com/komagata/plnet
PHP | 4471 lines | 3802 code | 307 blank | 362 comment | 619 complexity | 6ebb26fb8e7581b0d788a2c60cf3e934 MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /****************************************************
  3. SIMPLEPIE
  4. A PHP-Based RSS and Atom Feed Framework
  5. Takes the hard work out of managing a complete RSS/Atom solution.
  6. Version: "Lemon Meringue"
  7. Updated: 3 August 2006
  8. Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon
  9. http://simplepie.org
  10. *****************************************************
  11. LICENSE:
  12. GNU Lesser General Public License 2.1 (LGPL)
  13. http://creativecommons.org/licenses/LGPL/2.1/
  14. *****************************************************
  15. Please submit all bug reports and feature requests to the SimplePie forums.
  16. http://simplepie.org/support/
  17. ****************************************************/
  18. class SimplePie
  19. {
  20. // SimplePie Info
  21. var $name = 'SimplePie';
  22. var $version = 'Lemon Meringue';
  23. var $build = '20060803';
  24. var $url = 'http://simplepie.org/';
  25. var $useragent;
  26. var $linkback;
  27. // Other objects, instances created here so we can set options on them
  28. var $sanitize;
  29. // Options
  30. var $rss_url;
  31. var $xml_dump = false;
  32. var $enable_cache = true;
  33. var $max_minutes = 60;
  34. var $cache_location = './cache';
  35. var $order_by_date = true;
  36. // Misc. variables
  37. var $data;
  38. var $error;
  39. function SimplePie($feed_url = null, $cache_location = null, $cache_max_minutes = null)
  40. {
  41. $this->useragent = $this->name . '/' . $this->version . ' (Feed Parser; ' . $this->url . '; Allow like Gecko) Build/' . $this->build;
  42. $this->linkback = '<a href="' . $this->url . '" title="' . $this->name . ' ' . $this->version . '">' . $this->name . '</a>';
  43. // Other objects, instances created here so we can set options on them
  44. $this->sanitize = new SimplePie_Sanitize;
  45. // Parse the feed, if we get the data sent directly here
  46. if (!is_null($feed_url)) {
  47. $this->feed_url($feed_url);
  48. }
  49. if (!is_null($cache_location)) {
  50. $this->cache_location($cache_location);
  51. }
  52. if (!is_null($cache_max_minutes)) {
  53. $this->cache_max_minutes($cache_max_minutes);
  54. }
  55. // If we've passed an xmldump variable in the URL, snap into XMLdump mode
  56. if (isset($_GET['xmldump'])) {
  57. $this->enable_xmldump(true);
  58. }
  59. if (!is_null($feed_url)) {
  60. return $this->init();
  61. }
  62. }
  63. function feed_url($url)
  64. {
  65. $this->rss_url = SimplePie_Misc::fix_protocol($url, 1);
  66. }
  67. function enable_xmldump($enable = false)
  68. {
  69. $this->xml_dump = (bool) $enable;
  70. }
  71. function enable_caching($enable = true)
  72. {
  73. $this->enable_cache = (bool) $enable;
  74. }
  75. function cache_max_minutes($minutes = 60)
  76. {
  77. $this->max_minutes = (float) $minutes;
  78. }
  79. function cache_location($location = './cache')
  80. {
  81. $this->cache_location = (string) $location;
  82. }
  83. function order_by_date($enable = true)
  84. {
  85. $this->order_by_date = (bool) $enable;
  86. }
  87. function bypass_image_hotlink($get = 'i')
  88. {
  89. $this->sanitize->bypass_image_hotlink($get);
  90. }
  91. function bypass_image_hotlink_page($page = false)
  92. {
  93. $this->sanitize->bypass_image_hotlink_page($page);
  94. }
  95. function replace_headers($enable = false)
  96. {
  97. $this->sanitize->replace_headers($enable);
  98. }
  99. function remove_div($enable = true)
  100. {
  101. $this->sanitize->remove_div($enable);
  102. }
  103. function strip_ads($enable = true)
  104. {
  105. $this->sanitize->strip_ads($enable);
  106. }
  107. function strip_htmltags($tags = array('blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'), $encode = null)
  108. {
  109. $this->sanitize->strip_htmltags($tags);
  110. if (!is_null($encode))
  111. {
  112. $this->sanitize->encode_instead_of_strip($tags);
  113. }
  114. }
  115. function encode_instead_of_strip($enable = true)
  116. {
  117. $this->sanitize->encode_instead_of_strip($enable);
  118. }
  119. function strip_attributes($attribs = array('class', 'id', 'style', 'onclick', 'onmouseover', 'onmouseout', 'onfocus', 'onblur'))
  120. {
  121. $this->sanitize->strip_attributes($attribs);
  122. }
  123. function init()
  124. {
  125. if ($this->sanitize->bypass_image_hotlink && !empty($_GET[$this->sanitize->bypass_image_hotlink]))
  126. {
  127. if (get_magic_quotes_gpc())
  128. {
  129. $_GET[$this->sanitize->bypass_image_hotlink] = stripslashes($_GET[$this->sanitize->bypass_image_hotlink]);
  130. }
  131. SimplePie_Misc::display_file($_GET[$this->sanitize->bypass_image_hotlink], 10, $this->useragent);
  132. }
  133. if (isset($_GET['js']))
  134. {
  135. $embed = <<<EOT
  136. function embed_odeo(link) {document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="440" height="80" align="middle"><param name="movie" value="http://odeo.com/flash/audio_player_fullsize.swf" /><param name="allowScriptAccess" value="any" /><param name="quality" value="high"><param name="wmode" value="transparent"><param name="flashvars" value="valid_sample_rate=true&external_url='+link+'" /><embed src="http://odeo.com/flash/audio_player_fullsize.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" width="440" height="80" wmode="transparent" allowScriptAccess="any" flashvars="valid_sample_rate=true&external_url='+link+'"></embed></object>');}
  137. function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {document.writeln('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" style="cursor:hand; cursor:pointer;" type="'+type+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'"><param name="href" value="'+link+'" /><param name="src" value="'+placeholder+'" /><param name="autoplay" value="false" /><param name="target" value="myself" /><param name="controller" value="false" /><param name="loop" value="'+loop+'" /><param name="scale" value="aspect" /><param name="bgcolor" value="'+bgcolor+'"><embed type="'+type+'" style="cursor:hand; cursor:pointer;" href="'+link+'" src="'+placeholder+'" width="'+width+'" height="'+height+'" autoplay="false" target="myself" controller="false" loop="'+loop+'" scale="aspect" bgcolor="'+bgcolor+'" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>');}
  138. function embed_flash(bgcolor, width, height, link, loop, type) {document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" bgcolor="'+bgcolor+'" width="'+width+'" height="'+height+'"><param name="movie" value="'+link+'"><param name="quality" value="high"><param name="loop" value="'+loop+'"><param name="bgcolor" value="'+bgcolor+'"><embed src="'+link+'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="'+type+'" quality="high" width="'+width+'" height="'+height+'" bgcolor="'+bgcolor+'" loop="'+loop+'"></embed></object>');}
  139. function embed_wmedia(width, height, link) {document.writeln('<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" type="application/x-oleobject" width="'+width+'" height="'+height+'" standby="Loading Windows Media Player..."><param name="FileName" value="'+link+'"><param name="autosize" value="true"><param name="ShowControls" value="true"><param name="ShowStatusBar" value="false"><param name="ShowDisplay" value="false"><param name="autostart" value="false"><embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed></object>');}
  140. EOT;
  141. ob_start('ob_gzhandler');
  142. header('Content-type: text/javascript; charset: UTF-8');
  143. header('Cache-Control: must-revalidate');
  144. header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
  145. echo $embed;
  146. exit;
  147. }
  148. if (!empty($this->rss_url))
  149. {
  150. $this->data = array();
  151. if ($this->enable_cache && preg_match('/^http(s)?:\/\//i', $this->rss_url))
  152. {
  153. $cache = new SimplePie_Cache($this->cache_location, sha1($this->rss_url), 'spc');
  154. }
  155. else
  156. {
  157. $cache = false;
  158. }
  159. if ($cache && !$this->xml_dump)
  160. {
  161. $this->data = $cache->load();
  162. if (!empty($this->data))
  163. {
  164. if (!empty($this->data['feed_url']))
  165. {
  166. $this->rss_url = $this->data['feed_url'];
  167. return $this->init();
  168. }
  169. else if ($cache->mtime() + $this->max_minutes * 60 < time())
  170. {
  171. if (!empty($this->data['last-modified']) || !empty($this->data['etag']))
  172. {
  173. $headers = array();
  174. if (!empty($this->data['last-modified']))
  175. {
  176. $headers['if-modified-since'] = $this->data['last-modified'];
  177. }
  178. if (!empty($this->data['etag']))
  179. {
  180. $headers['if-none-match'] = $this->data['etag'];
  181. }
  182. $file = new SimplePie_File($this->rss_url, 1, 5, $headers, $this->useragent);
  183. if ($file->success)
  184. {
  185. $headers = $file->headers();
  186. if ($headers['status']['code'] == 304)
  187. {
  188. $cache->touch();
  189. return true;
  190. }
  191. }
  192. unset($file);
  193. }
  194. else
  195. {
  196. $cache->unlink();
  197. }
  198. }
  199. else
  200. {
  201. return true;
  202. }
  203. }
  204. else
  205. {
  206. $cache->unlink();
  207. }
  208. }
  209. $this->data = array();
  210. if (!isset($file))
  211. {
  212. $file = new SimplePie_File($this->rss_url, 10, 5, null, $this->useragent);
  213. }
  214. if (!$file->success)
  215. {
  216. return false;
  217. }
  218. if (!SimplePie_Locator::is_feed($file))
  219. {
  220. $locate = new SimplePie_Locator($file);
  221. $feed = $locate->find();
  222. if ($feed)
  223. {
  224. if ($cache && !$cache->save(array('feed_url' => $feed)))
  225. {
  226. $this->error = "$cache->name is not writeable";
  227. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  228. }
  229. $this->rss_url = $feed;
  230. return $this->init();
  231. }
  232. else
  233. {
  234. $this->error = "A feed could not be found at $this->rss_url";
  235. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  236. return false;
  237. }
  238. }
  239. $headers = $file->headers();
  240. $data = trim($file->body());
  241. $file->close();
  242. unset($file);
  243. // First try HTTP headers
  244. if (!empty($headers['content-type']) && preg_match('/charset=(.*)/i', $headers['content-type'], $charset))
  245. {
  246. $encoding = SimplePie_Misc::encoding($charset[1]);
  247. }
  248. // Then prolog, if at the very start of the document
  249. else if (preg_match('/^<\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\s*=\s*["|\'](.*)["|\']/Ui', $prolog[1], $encoding))
  250. {
  251. $encoding = SimplePie_Misc::encoding($encoding[1]);
  252. }
  253. // UTF-32 Big Endian BOM
  254. else if (strpos($data, sprintf('%c%c%c%c', 0x00, 0x00, 0xFE, 0xFF)) === 0)
  255. {
  256. $encoding = SimplePie_Misc::encoding('UTF-32be');
  257. }
  258. // UTF-32 Little Endian BOM
  259. else if (strpos($data, sprintf('%c%c%c%c', 0xFF, 0xFE, 0x00, 0x00)) === 0)
  260. {
  261. $encoding = SimplePie_Misc::encoding('UTF-32');
  262. }
  263. // UTF-16 Big Endian BOM
  264. else if (strpos($data, sprintf('%c%c', 0xFE, 0xFF)) === 0)
  265. {
  266. $encoding = SimplePie_Misc::encoding('UTF-16be');
  267. }
  268. // UTF-16 Little Endian BOM
  269. else if (strpos($data, sprintf('%c%c', 0xFF, 0xFE)) === 0)
  270. {
  271. $encoding = SimplePie_Misc::encoding('UTF-16le');
  272. }
  273. // UTF-8 BOM
  274. else if (strpos($data, sprintf('%c%c%c', 0xEF, 0xBB, 0xBF)) === 0)
  275. {
  276. $encoding = SimplePie_Misc::encoding('UTF-8');
  277. }
  278. // Fallback to the default
  279. else
  280. {
  281. $encoding = SimplePie_Misc::encoding(null);
  282. }
  283. if (function_exists('iconv') && $encoding['use_iconv'] && iconv($encoding['encoding'], 'UTF-8//TRANSLIT', $data))
  284. {
  285. $data = iconv($encoding['encoding'], 'UTF-8//TRANSLIT', $data);
  286. $encoding['encoding'] = 'UTF-8';
  287. }
  288. else if (function_exists('iconv') && $encoding['use_iconv'] && iconv($encoding['encoding'], 'UTF-8', $data))
  289. {
  290. $data = iconv($encoding['encoding'], 'UTF-8', $data);
  291. $encoding['encoding'] = 'UTF-8';
  292. }
  293. else if (function_exists('mb_convert_encoding') && $encoding['use_mbstring'])
  294. {
  295. $data = mb_convert_encoding($data, 'UTF-8', $encoding['encoding']);
  296. $encoding['encoding'] = 'UTF-8';
  297. }
  298. else if ($encoding['encoding'] == 'ISO-8859-1')
  299. {
  300. $data = utf8_encode($data);
  301. $encoding['encoding'] = 'UTF-8';
  302. }
  303. else
  304. {
  305. $encoding['encoding'] = 'UTF-8';
  306. }
  307. $data = new SimplePie_Parser($data, 'UTF-8', $this->xml_dump);
  308. if ($this->xml_dump)
  309. {
  310. header('Content-type: text/xml; charset=UTF-8');
  311. echo $data->data;
  312. exit;
  313. }
  314. else if (!$data->error_code)
  315. {
  316. $this->sanitize->parse_data_array($data->data);
  317. unset($data);
  318. $this->data['feedinfo'] = $this->sanitize->feedinfo;
  319. $this->data['info'] = $this->sanitize->info;
  320. $this->data['items'] = $this->sanitize->items;
  321. unset($this->sanitize);
  322. $this->data['feedinfo']['encoding'] = 'UTF-8';
  323. if (!empty($headers['last-modified']))
  324. {
  325. $this->data['last-modified'] = $headers['last-modified'];
  326. }
  327. if (!empty($headers['etag']))
  328. {
  329. $this->data['etag'] = $headers['etag'];
  330. }
  331. if ($this->order_by_date && !empty($this->data['items']))
  332. {
  333. $do_sort = true;
  334. foreach ($this->data['items'] as $item)
  335. {
  336. if (!isset($item->date))
  337. {
  338. $do_sort = false;
  339. break;
  340. }
  341. }
  342. if ($do_sort)
  343. {
  344. usort($this->data['items'], create_function('$a,$b', 'if ($a->date == $b->date) return 0; return ($a->date < $b->date) ? 1 : -1;'));
  345. }
  346. }
  347. if ($cache && !$cache->save($this->data))
  348. {
  349. $this->error = "$cache->name is not writeable";
  350. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  351. }
  352. return true;
  353. }
  354. else
  355. {
  356. $this->error = "XML error: $data->error_string at line $data->current_line, column $data->current_column";
  357. SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
  358. return false;
  359. }
  360. }
  361. }
  362. function get_encoding()
  363. {
  364. if (!empty($this->data['feedinfo']['encoding']))
  365. {
  366. return $this->data['feedinfo']['encoding'];
  367. }
  368. else
  369. {
  370. return false;
  371. }
  372. }
  373. function handle_content_type($mime='text/html')
  374. {
  375. if (!headers_sent())
  376. {
  377. $header = "Content-type: $mime;";
  378. if ($this->get_encoding())
  379. {
  380. $header .= ' charset=' . $this->get_encoding();
  381. }
  382. else
  383. {
  384. $header .= ' charset=UTF-8';
  385. }
  386. header($header);
  387. }
  388. }
  389. function get_type()
  390. {
  391. if (!empty($this->data['feedinfo']['type']))
  392. {
  393. return $this->data['feedinfo']['type'];
  394. }
  395. else
  396. {
  397. return false;
  398. }
  399. }
  400. function get_version()
  401. {
  402. if (!empty($this->data['feedinfo']['version']))
  403. {
  404. return $this->data['feedinfo']['version'];
  405. }
  406. else
  407. {
  408. return false;
  409. }
  410. }
  411. function subscribe_url()
  412. {
  413. if (!empty($this->rss_url))
  414. {
  415. return $this->rss_url;
  416. }
  417. else
  418. {
  419. return false;
  420. }
  421. }
  422. function subscribe_feed()
  423. {
  424. if (!empty($this->rss_url))
  425. {
  426. return SimplePie_Misc::fix_protocol($this->rss_url, 2);
  427. }
  428. else
  429. {
  430. return false;
  431. }
  432. }
  433. function subscribe_outlook()
  434. {
  435. if (!empty($this->rss_url))
  436. {
  437. return 'outlook' . SimplePie_Misc::fix_protocol($this->rss_url, 2);
  438. }
  439. else
  440. {
  441. return false;
  442. }
  443. }
  444. function subscribe_podcast()
  445. {
  446. if (!empty($this->rss_url))
  447. {
  448. return SimplePie_Misc::fix_protocol($this->rss_url, 3);
  449. }
  450. else
  451. {
  452. return false;
  453. }
  454. }
  455. function subscribe_aol()
  456. {
  457. if ($this->subscribe_url())
  458. {
  459. return 'http://feeds.my.aol.com/add.jsp?url=' . rawurlencode($this->subscribe_url());
  460. }
  461. else
  462. {
  463. return false;
  464. }
  465. }
  466. function subscribe_bloglines()
  467. {
  468. if ($this->subscribe_url())
  469. {
  470. return 'http://www.bloglines.com/sub/' . rawurlencode($this->subscribe_url());
  471. }
  472. else
  473. {
  474. return false;
  475. }
  476. }
  477. function subscribe_eskobo()
  478. {
  479. if ($this->subscribe_url())
  480. {
  481. return 'http://www.eskobo.com/?AddToMyPage=' . rawurlencode($this->subscribe_url());
  482. }
  483. else
  484. {
  485. return false;
  486. }
  487. }
  488. function subscribe_feedfeeds()
  489. {
  490. if ($this->subscribe_url())
  491. {
  492. return 'http://www.feedfeeds.com/add?feed=' . rawurlencode($this->subscribe_url());
  493. }
  494. else
  495. {
  496. return false;
  497. }
  498. }
  499. function subscribe_feedlounge()
  500. {
  501. if ($this->subscribe_url())
  502. {
  503. return 'http://my.feedlounge.com/external/subscribe?url=' . rawurlencode($this->subscribe_url());
  504. }
  505. else
  506. {
  507. return false;
  508. }
  509. }
  510. function subscribe_feedster()
  511. {
  512. if ($this->subscribe_url())
  513. {
  514. return 'http://www.feedster.com/myfeedster.php?action=addrss&amp;confirm=no&amp;rssurl=' . rawurlencode($this->subscribe_url());
  515. }
  516. else
  517. {
  518. return false;
  519. }
  520. }
  521. function subscribe_google()
  522. {
  523. if ($this->subscribe_url())
  524. {
  525. return 'http://fusion.google.com/add?feedurl=' . rawurlencode($this->subscribe_url());
  526. }
  527. else
  528. {
  529. return false;
  530. }
  531. }
  532. function subscribe_gritwire()
  533. {
  534. if ($this->subscribe_url())
  535. {
  536. return 'http://my.gritwire.com/feeds/addExternalFeed.aspx?FeedUrl=' . rawurlencode($this->subscribe_url());
  537. }
  538. else
  539. {
  540. return false;
  541. }
  542. }
  543. function subscribe_msn()
  544. {
  545. if ($this->subscribe_url())
  546. {
  547. $url = 'http://my.msn.com/addtomymsn.armx?id=rss&amp;ut=' . rawurlencode($this->subscribe_url());
  548. if ($this->get_feed_link())
  549. {
  550. $url .= '&amp;ru=' . rawurlencode($this->get_feed_link());
  551. }
  552. return $url;
  553. }
  554. else
  555. {
  556. return false;
  557. }
  558. }
  559. function subscribe_netvibes()
  560. {
  561. if ($this->subscribe_url())
  562. {
  563. return 'http://www.netvibes.com/subscribe.php?url=' . rawurlencode($this->subscribe_url());
  564. }
  565. else
  566. {
  567. return false;
  568. }
  569. }
  570. function subscribe_newsburst()
  571. {
  572. if ($this->subscribe_url())
  573. {
  574. return 'http://www.newsburst.com/Source/?add=' . rawurlencode($this->subscribe_url());
  575. }
  576. else
  577. {
  578. return false;
  579. }
  580. }
  581. function subscribe_newsgator()
  582. {
  583. if ($this->subscribe_url())
  584. {
  585. return 'http://www.newsgator.com/ngs/subscriber/subext.aspx?url=' . rawurlencode($this->subscribe_url());
  586. }
  587. else
  588. {
  589. return false;
  590. }
  591. }
  592. function subscribe_odeo()
  593. {
  594. if ($this->subscribe_url())
  595. {
  596. return 'http://www.odeo.com/listen/subscribe?feed=' . rawurlencode($this->subscribe_url());
  597. }
  598. else
  599. {
  600. return false;
  601. }
  602. }
  603. function subscribe_pluck()
  604. {
  605. if ($this->subscribe_url())
  606. {
  607. return 'http://client.pluck.com/pluckit/prompt.aspx?GCID=C12286x053&amp;a=' . rawurlencode($this->subscribe_url());
  608. }
  609. else
  610. {
  611. return false;
  612. }
  613. }
  614. function subscribe_podnova()
  615. {
  616. if ($this->subscribe_url())
  617. {
  618. return 'http://www.podnova.com/index_your_podcasts.srf?action=add&amp;url=' . rawurlencode($this->subscribe_url());
  619. }
  620. else
  621. {
  622. return false;
  623. }
  624. }
  625. function subscribe_rojo()
  626. {
  627. if ($this->subscribe_url())
  628. {
  629. return 'http://www.rojo.com/add-subscription?resource=' . rawurlencode($this->subscribe_url());
  630. }
  631. else
  632. {
  633. return false;
  634. }
  635. }
  636. function subscribe_yahoo()
  637. {
  638. if ($this->subscribe_url())
  639. {
  640. return 'http://add.my.yahoo.com/rss?url=' . rawurlencode($this->subscribe_url());
  641. }
  642. else
  643. {
  644. return false;
  645. }
  646. }
  647. function get_feed_title()
  648. {
  649. if (!empty($this->data['info']['title']))
  650. {
  651. return $this->data['info']['title'];
  652. }
  653. else
  654. {
  655. return false;
  656. }
  657. }
  658. function get_feed_link()
  659. {
  660. if (!empty($this->data['info']['link']['alternate'][0]))
  661. {
  662. return $this->data['info']['link']['alternate'][0];
  663. }
  664. else
  665. {
  666. return false;
  667. }
  668. }
  669. function get_feed_links()
  670. {
  671. if (!empty($this->data['info']['link']))
  672. {
  673. return $this->data['info']['link'];
  674. }
  675. else
  676. {
  677. return false;
  678. }
  679. }
  680. function get_feed_description()
  681. {
  682. if (!empty($this->data['info']['description']))
  683. {
  684. return $this->data['info']['description'];
  685. }
  686. else if (!empty($this->data['info']['dc:description']))
  687. {
  688. return $this->data['info']['dc:description'];
  689. }
  690. else if (!empty($this->data['info']['tagline']))
  691. {
  692. return $this->data['info']['tagline'];
  693. }
  694. else if (!empty($this->data['info']['subtitle']))
  695. {
  696. return $this->data['info']['subtitle'];
  697. }
  698. else
  699. {
  700. return false;
  701. }
  702. }
  703. function get_feed_copyright()
  704. {
  705. if (!empty($this->data['info']['copyright']))
  706. {
  707. return $this->data['info']['copyright'];
  708. }
  709. else
  710. {
  711. return false;
  712. }
  713. }
  714. function get_feed_language()
  715. {
  716. if (!empty($this->data['info']['language']))
  717. {
  718. return $this->data['info']['language'];
  719. }
  720. else if (!empty($this->data['info']['xml:lang']))
  721. {
  722. return $this->data['info']['xml:lang'];
  723. }
  724. else
  725. {
  726. return false;
  727. }
  728. }
  729. function get_image_exist()
  730. {
  731. if (!empty($this->data['info']['image']['url']) || !empty($this->data['info']['image']['logo']))
  732. {
  733. return true;
  734. }
  735. else
  736. {
  737. return false;
  738. }
  739. }
  740. function get_image_title()
  741. {
  742. if (!empty($this->data['info']['image']['title']))
  743. {
  744. return $this->data['info']['image']['title'];
  745. }
  746. else
  747. {
  748. return false;
  749. }
  750. }
  751. function get_image_url()
  752. {
  753. if (!empty($this->data['info']['image']['url']))
  754. {
  755. return $this->data['info']['image']['url'];
  756. }
  757. else if (!empty($this->data['info']['image']['logo']))
  758. {
  759. return $this->data['info']['image']['logo'];
  760. }
  761. else
  762. {
  763. return false;
  764. }
  765. }
  766. function get_image_link()
  767. {
  768. if (!empty($this->data['info']['image']['link']))
  769. {
  770. return $this->data['info']['image']['link'];
  771. }
  772. else
  773. {
  774. return false;
  775. }
  776. }
  777. function get_image_width()
  778. {
  779. if (!empty($this->data['info']['image']['width']))
  780. {
  781. return $this->data['info']['image']['width'];
  782. }
  783. else
  784. {
  785. return false;
  786. }
  787. }
  788. function get_image_height()
  789. {
  790. if (!empty($this->data['info']['image']['height']))
  791. {
  792. return $this->data['info']['image']['height'];
  793. }
  794. else
  795. {
  796. return false;
  797. }
  798. }
  799. function get_item_quantity($max = 0)
  800. {
  801. if (!empty($this->data['items']))
  802. {
  803. $qty = sizeof($this->data['items']);
  804. }
  805. else
  806. {
  807. $qty = 0;
  808. }
  809. if ($max == 0)
  810. {
  811. return $qty;
  812. }
  813. else
  814. {
  815. return ($qty > $max) ? $max : $qty;
  816. }
  817. }
  818. function get_item($key)
  819. {
  820. if (!empty($this->data['items'][$key]))
  821. {
  822. return $this->data['items'][$key];
  823. }
  824. else
  825. {
  826. return false;
  827. }
  828. }
  829. function get_items($start = 0, $end = 0)
  830. {
  831. if ($end == 0)
  832. {
  833. return array_slice($this->data['items'], $start);
  834. }
  835. else
  836. {
  837. return array_slice($this->data['items'], $start, $end);
  838. }
  839. }
  840. }
  841. class SimplePie_Item
  842. {
  843. var $data;
  844. function SimplePie_Item($data)
  845. {
  846. $this->data =& $data;
  847. }
  848. function get_id()
  849. {
  850. if (!empty($this->data['guid']['data']))
  851. {
  852. return $this->data['guid']['data'];
  853. }
  854. else if (!empty($this->data['id']))
  855. {
  856. return $this->data['id'];
  857. }
  858. else
  859. {
  860. return false;
  861. }
  862. }
  863. function get_title()
  864. {
  865. if (!empty($this->data['title']))
  866. {
  867. return $this->data['title'];
  868. }
  869. else if (!empty($this->data['dc:title']))
  870. {
  871. return $this->data['dc:title'];
  872. }
  873. else
  874. {
  875. return false;
  876. }
  877. }
  878. function get_description()
  879. {
  880. if (!empty($this->data['content']))
  881. {
  882. return $this->data['content'];
  883. }
  884. else if (!empty($this->data['encoded']))
  885. {
  886. return $this->data['encoded'];
  887. }
  888. else if (!empty($this->data['summary']))
  889. {
  890. return $this->data['summary'];
  891. }
  892. else if (!empty($this->data['description']))
  893. {
  894. return $this->data['description'];
  895. }
  896. else if (!empty($this->data['dc:description']))
  897. {
  898. return $this->data['dc:description'];
  899. }
  900. else if (!empty($this->data['longdesc']))
  901. {
  902. return $this->data['longdesc'];
  903. }
  904. else
  905. {
  906. return false;
  907. }
  908. }
  909. function get_category($key = null)
  910. {
  911. if (is_null($key))
  912. {
  913. return $this->get_categories();
  914. }
  915. else
  916. {
  917. $categories = $this->get_categories();
  918. if (!empty($categories[$key]))
  919. {
  920. return $categories[$key];
  921. }
  922. else
  923. {
  924. return false;
  925. }
  926. }
  927. }
  928. function get_categories()
  929. {
  930. $categories = array();
  931. if (!empty($this->data['category']))
  932. {
  933. $categories = array_merge($categories, $this->data['category']);
  934. }
  935. if (!empty($this->data['subject']))
  936. {
  937. $categories = array_merge($categories, $this->data['subject']);
  938. }
  939. if (!empty($categories))
  940. {
  941. return array_unique($categories);
  942. }
  943. else
  944. {
  945. return false;
  946. }
  947. }
  948. function get_author($key)
  949. {
  950. $authors = $this->get_authors();
  951. if (!empty($authors[$key]))
  952. {
  953. return $authors[$key];
  954. }
  955. else
  956. {
  957. return false;
  958. }
  959. }
  960. function get_authors()
  961. {
  962. $authors = array();
  963. if (!empty($this->data['author']))
  964. {
  965. $authors = array_merge($authors, $this->data['author']);
  966. }
  967. if (!empty($this->data['creator']))
  968. {
  969. $authors = array_merge($authors, $this->data['creator']);
  970. }
  971. if (!empty($authors))
  972. {
  973. return array_unique($authors);
  974. }
  975. else
  976. {
  977. return false;
  978. }
  979. }
  980. function get_date($date_format = 'j F Y, g:i a')
  981. {
  982. if (!empty($this->data['pubdate']))
  983. {
  984. return date($date_format, $this->data['pubdate']);
  985. }
  986. else if (!empty($this->data['dc:date']))
  987. {
  988. return date($date_format, $this->data['dc:date']);
  989. }
  990. else if (!empty($this->data['issued']))
  991. {
  992. return date($date_format, $this->data['issued']);
  993. }
  994. else if (!empty($this->data['published']))
  995. {
  996. return date($date_format, $this->data['published']);
  997. }
  998. else if (!empty($this->data['modified']))
  999. {
  1000. return date($date_format, $this->data['modified']);
  1001. }
  1002. else if (!empty($this->data['updated']))
  1003. {
  1004. return date($date_format, $this->data['updated']);
  1005. }
  1006. else
  1007. {
  1008. return false;
  1009. }
  1010. }
  1011. function get_permalink()
  1012. {
  1013. $link = $this->get_link(0);
  1014. $enclosure = $this->get_enclosure(0);
  1015. if (!empty($link))
  1016. {
  1017. return $link;
  1018. }
  1019. else if (!empty($enclosure))
  1020. {
  1021. return $enclosure->get_link();
  1022. }
  1023. else
  1024. {
  1025. return false;
  1026. }
  1027. }
  1028. function get_link($key, $rel = 'alternate')
  1029. {
  1030. $links = $this->get_links($rel);
  1031. if (!empty($links[$key]))
  1032. {
  1033. return $links[$key];
  1034. }
  1035. else
  1036. {
  1037. return false;
  1038. }
  1039. }
  1040. function get_links($rel = 'alternate')
  1041. {
  1042. if (!empty($this->data['link'][$rel]))
  1043. {
  1044. return $this->data['link'][$rel];
  1045. }
  1046. else
  1047. {
  1048. return false;
  1049. }
  1050. }
  1051. function get_enclosure($key)
  1052. {
  1053. $enclosures = $this->get_enclosures();
  1054. if (!empty($enclosures[$key]))
  1055. {
  1056. return $enclosures[$key];
  1057. }
  1058. else
  1059. {
  1060. return false;
  1061. }
  1062. }
  1063. function get_enclosures()
  1064. {
  1065. $enclosures = array();
  1066. $links = $this->get_links('enclosure');
  1067. if (!empty($this->data['enclosures']))
  1068. {
  1069. $enclosures = array_merge($enclosures, $this->data['enclosures']);
  1070. }
  1071. if (!empty($links))
  1072. {
  1073. $enclosures = array_merge($enclosures, $links);
  1074. }
  1075. if (!empty($enclosures))
  1076. {
  1077. return array_unique($enclosures);
  1078. }
  1079. else
  1080. {
  1081. return false;
  1082. }
  1083. }
  1084. function add_to_blinklist()
  1085. {
  1086. if ($this->get_permalink())
  1087. {
  1088. $url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=' . rawurlencode($this->get_permalink());
  1089. if ($this->get_title())
  1090. {
  1091. $url .= '&amp;Title=' . rawurlencode($this->get_title());
  1092. }
  1093. return $url;
  1094. }
  1095. else
  1096. {
  1097. return false;
  1098. }
  1099. }
  1100. function add_to_blogmarks()
  1101. {
  1102. if ($this->get_permalink())
  1103. {
  1104. $url = 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=' . rawurlencode($this->get_permalink());
  1105. if ($this->get_title())
  1106. {
  1107. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1108. }
  1109. return $url;
  1110. }
  1111. else
  1112. {
  1113. return false;
  1114. }
  1115. }
  1116. function add_to_delicious()
  1117. {
  1118. if ($this->get_permalink())
  1119. {
  1120. $url = 'http://del.icio.us/post/?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1121. if ($this->get_title())
  1122. {
  1123. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1124. }
  1125. return $url;
  1126. }
  1127. else
  1128. {
  1129. return false;
  1130. }
  1131. }
  1132. function add_to_digg()
  1133. {
  1134. if ($this->get_permalink())
  1135. {
  1136. return 'http://digg.com/submit?phase=2&amp;URL=' . rawurlencode($this->get_permalink());
  1137. }
  1138. else
  1139. {
  1140. return false;
  1141. }
  1142. }
  1143. function add_to_furl()
  1144. {
  1145. if ($this->get_permalink())
  1146. {
  1147. $url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
  1148. if ($this->get_title())
  1149. {
  1150. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1151. }
  1152. return $url;
  1153. }
  1154. else
  1155. {
  1156. return false;
  1157. }
  1158. }
  1159. function add_to_magnolia()
  1160. {
  1161. if ($this->get_permalink())
  1162. {
  1163. $url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
  1164. if ($this->get_title())
  1165. {
  1166. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1167. }
  1168. return $url;
  1169. }
  1170. else
  1171. {
  1172. return false;
  1173. }
  1174. }
  1175. function add_to_myweb20()
  1176. {
  1177. if ($this->get_permalink())
  1178. {
  1179. $url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
  1180. if ($this->get_title())
  1181. {
  1182. $url .= '&amp;t=' . rawurlencode($this->get_title());
  1183. }
  1184. return $url;
  1185. }
  1186. else
  1187. {
  1188. return false;
  1189. }
  1190. }
  1191. function add_to_newsvine()
  1192. {
  1193. if ($this->get_permalink())
  1194. {
  1195. $url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
  1196. if ($this->get_title())
  1197. {
  1198. $url .= '&amp;h=' . rawurlencode($this->get_title());
  1199. }
  1200. return $url;
  1201. }
  1202. else
  1203. {
  1204. return false;
  1205. }
  1206. }
  1207. function add_to_reddit()
  1208. {
  1209. if ($this->get_permalink())
  1210. {
  1211. $url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
  1212. if ($this->get_title())
  1213. {
  1214. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1215. }
  1216. return $url;
  1217. }
  1218. else
  1219. {
  1220. return false;
  1221. }
  1222. }
  1223. function add_to_segnalo()
  1224. {
  1225. if ($this->get_permalink())
  1226. {
  1227. $url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
  1228. if ($this->get_title())
  1229. {
  1230. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1231. }
  1232. return $url;
  1233. }
  1234. else
  1235. {
  1236. return false;
  1237. }
  1238. }
  1239. function add_to_simpy()
  1240. {
  1241. if ($this->get_permalink())
  1242. {
  1243. $url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
  1244. if ($this->get_title())
  1245. {
  1246. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1247. }
  1248. return $url;
  1249. }
  1250. else
  1251. {
  1252. return false;
  1253. }
  1254. }
  1255. function add_to_smarking()
  1256. {
  1257. if ($this->get_permalink())
  1258. {
  1259. return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
  1260. }
  1261. else
  1262. {
  1263. return false;
  1264. }
  1265. }
  1266. function add_to_spurl()
  1267. {
  1268. if ($this->get_permalink())
  1269. {
  1270. $url = 'http://www.spurl.net/spurl.php?v=3&amp;url=' . rawurlencode($this->get_permalink());
  1271. if ($this->get_title())
  1272. {
  1273. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1274. }
  1275. return $url;
  1276. }
  1277. else
  1278. {
  1279. return false;
  1280. }
  1281. }
  1282. function add_to_wists()
  1283. {
  1284. if ($this->get_permalink())
  1285. {
  1286. $url = 'http://wists.com/r.php?c=&amp;r=' . rawurlencode($this->get_permalink());
  1287. if ($this->get_title())
  1288. {
  1289. $url .= '&amp;title=' . rawurlencode($this->get_title());
  1290. }
  1291. return $url;
  1292. }
  1293. else
  1294. {
  1295. return false;
  1296. }
  1297. }
  1298. function search_technorati()
  1299. {
  1300. if ($this->get_permalink())
  1301. {
  1302. return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
  1303. }
  1304. else
  1305. {
  1306. return false;
  1307. }
  1308. }
  1309. }
  1310. class SimplePie_Author
  1311. {
  1312. var $name;
  1313. var $link;
  1314. var $email;
  1315. // Constructor, used to input the data
  1316. function SimplePie_Author($name, $link, $email) {
  1317. $this->name = $name;
  1318. $this->link = $link;
  1319. $this->email = $email;
  1320. }
  1321. function get_name() {
  1322. return (empty($this->name)) ? false : $this->name;
  1323. }
  1324. function get_link() {
  1325. return (empty($this->link)) ? false : $this->link;
  1326. }
  1327. function get_email() {
  1328. return (empty($this->email)) ? false : $this->email;
  1329. }
  1330. }
  1331. class SimplePie_Enclosure
  1332. {
  1333. var $link;
  1334. var $type;
  1335. var $length;
  1336. // Constructor, used to input the data
  1337. function SimplePie_Enclosure($link, $type, $length) {
  1338. $this->link = $link;
  1339. $this->type = $type;
  1340. $this->length = $length;
  1341. }
  1342. function get_link() {
  1343. return (empty($this->link)) ? false : $this->link;
  1344. }
  1345. function get_extension() {
  1346. if (!empty($this->link)) {
  1347. return pathinfo($this->link, PATHINFO_EXTENSION);
  1348. } else {
  1349. return false;
  1350. }
  1351. }
  1352. function get_type() {
  1353. return (empty($this->type)) ? false : $this->type;
  1354. }
  1355. function get_length() {
  1356. return (empty($this->length)) ? false : $this->length;
  1357. }
  1358. function get_size() {
  1359. return (empty($this->length)) ? false : round(($this->length/1048576), 2);
  1360. }
  1361. function embed($options) {
  1362. // Set up defaults
  1363. $audio='';
  1364. $video='';
  1365. $alt='';
  1366. $altclass='';
  1367. $loop='false';
  1368. $width='auto';
  1369. $height='auto';
  1370. $bgcolor='#ffffff';
  1371. $embed='';
  1372. // Process options and reassign values as necessary
  1373. $options = explode(',', $options);
  1374. foreach($options as $option) {
  1375. $opt = explode(':', trim($option));
  1376. if ($opt[0] == 'audio') $audio=$opt[1];
  1377. else if ($opt[0] == 'video') $video=$opt[1];
  1378. else if ($opt[0] == 'alt') $alt=$opt[1];
  1379. else if ($opt[0] == 'altclass') $altclass=$opt[1];
  1380. else if ($opt[0] == 'loop') $loop=$opt[1];
  1381. else if ($opt[0] == 'width') $width=$opt[1];
  1382. else if ($opt[0] == 'height') $height=$opt[1];
  1383. else if ($opt[0] == 'bgcolor') $bgcolor=$opt[1];
  1384. }
  1385. // Process values for 'auto'
  1386. if ($width == 'auto') {
  1387. if (stristr($this->type, 'audio/')) $width='100%';
  1388. else if (stristr($this->type, 'video/')) $width='320';
  1389. else $width='100%';
  1390. }
  1391. if ($height == 'auto') {
  1392. if (stristr($this->type, 'audio/')) $height=0;
  1393. else if (stristr($this->type, 'video/')) $height=240;
  1394. else $height=256;
  1395. }
  1396. // Set proper placeholder value
  1397. if (stristr($this->type, 'audio/')) $placeholder=$audio;
  1398. else if (stristr($this->type, 'video/')) $placeholder=$video;
  1399. // Make sure the JS library is included
  1400. // (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
  1401. $embed.='<script type="text/javascript" src="?js"></script>';
  1402. // Odeo Feed MP3's
  1403. if (substr(strtolower($this->link), 0, 15) == 'http://odeo.com') {
  1404. $embed.='<script type="text/javascript">embed_odeo("'.$this->link.'");</script>';
  1405. }
  1406. // QuickTime 7 file types. Need to test with QuickTime 6.
  1407. else if ($this->type == 'audio/3gpp' || $this->type == 'audio/3gpp2' || $this->type == 'audio/aac' || $this->type == 'audio/x-aac' || $this->type == 'audio/aiff' || $this->type == 'audio/x-aiff' || $this->type == 'audio/mid' || $this->type == 'audio/midi' || $this->type == 'audio/x-midi' || $this->type == 'audio/mpeg' || $this->type == 'audio/x-mpeg' || $this->type == 'audio/mp3' || $this->type == 'x-audio/mp3' || $this->type == 'audio/mp4' || $this->type == 'audio/m4a' || $this->type == 'audio/x-m4a' || $this->type == 'audio/wav' || $this->type == 'audio/x-wav' || $this->type == 'video/3gpp' || $this->type == 'video/3gpp2' || $this->type == 'video/m4v' || $this->type == 'video/x-m4v' || $this->type == 'video/mp4' || $this->type == 'video/mpeg' || $this->type == 'video/x-mpeg' || $this->type == 'video/quicktime' || $this->type == 'video/sd-video') {
  1408. $height+=16;
  1409. $embed.='<script type="text/javascript">embed_quicktime("'.$this->type.'", "'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$placeholder.'", "'.$loop.'");</script>';
  1410. }
  1411. // Flash
  1412. else if ($this->type == 'application/x-shockwave-flash' || $this->type == 'application/futuresplash') {
  1413. $embed.='<script type="text/javascript">embed_flash("'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$loop.'", "'.$this->type.'");</script>';
  1414. }
  1415. // Windows Media
  1416. else if ($this->type == 'application/asx' || $this->type == 'application/x-mplayer2' || $this->type == 'audio/x-ms-wma' || $this->type == 'audio/x-ms-wax' || $this->type == 'video/x-ms-asf-plugin' || $this->type == 'video/x-ms-asf' || $this->type == 'video/x-ms-wm' || $this->type == 'video/x-ms-wmv' || $this->type == 'video/x-ms-wvx') {
  1417. $height+=45;
  1418. $embed.='<script type="text/javascript">embed_wmedia("'.$width.'", "'.$height.'", "'.$this->link.'");</script>';
  1419. }
  1420. // Everything else
  1421. else $embed.='<a href="' . $this->link . '" class="' . $altclass . '">' . $alt . '</a>';
  1422. return $embed;
  1423. }
  1424. }
  1425. class SimplePie_File
  1426. {
  1427. var $url;
  1428. var $useragent;
  1429. var $success = true;
  1430. var $headers = array();
  1431. var $body;
  1432. var $fp;
  1433. var $redirects = 0;
  1434. function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null)
  1435. {
  1436. if (class_exists('idna_convert'))
  1437. {
  1438. $idn = new idna_convert;
  1439. $url = $idn->encode($url);
  1440. }
  1441. $this->url = $url;
  1442. $this->useragent = $useragent;
  1443. if (preg_match('/^http(s)?:\/\//i', $url))
  1444. {
  1445. if (empty($useragent))
  1446. {
  1447. $useragent = ini_get('user_agent');
  1448. $this->useragent = $useragent;
  1449. }
  1450. if (!is_array($headers))
  1451. {
  1452. $headers = array();
  1453. }
  1454. if (extension_loaded('curl'))
  1455. {
  1456. $headers2 = array();
  1457. foreach ($headers as $key => $value)
  1458. {
  1459. $headers2[] = "$key: $value";
  1460. }
  1461. $fp = curl_init();
  1462. curl_setopt($fp, CURLOPT_URL, $url);
  1463. curl_setopt($fp, CURLOPT_HEADER, 1);
  1464. curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
  1465. curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
  1466. curl_setopt($fp, CURLOPT_REFERER, $url);
  1467. curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
  1468. curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
  1469. curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
  1470. curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
  1471. $this->headers = trim(curl_exec($fp));
  1472. if (curl_errno($fp))
  1473. {
  1474. $this->success = false;
  1475. return false;
  1476. }
  1477. else
  1478. {
  1479. $info = curl_getinfo($fp);
  1480. $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
  1481. $this->body = array_pop($this->headers);
  1482. $this->headers = array_pop($this->headers);
  1483. $this->headers = $this->parse_headers($this->headers);
  1484. }
  1485. }
  1486. else
  1487. {
  1488. $url_parts = parse_url($url);
  1489. if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
  1490. {
  1491. $url_parts['host'] = "ssl://$url_parts[host]";
  1492. $url_parts['port'] = 443;
  1493. }
  1494. if (!isset($url_parts['port']))
  1495. {
  1496. $url_parts['port'] = 80;
  1497. }
  1498. $this->fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
  1499. if (!$this->fp)
  1500. {
  1501. $this->success = false;
  1502. return false;
  1503. }
  1504. else
  1505. {
  1506. stream_set_timeout($this->fp, $timeout);
  1507. $get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
  1508. $out = "GET $get HTTP/1.0\r\n";
  1509. $out .= "Host: $url_parts[host]\r\n";
  1510. $out .= "User-Agent: $useragent\r\n";
  1511. if (!empty($url_parts['user']) && !empty($url_parts['pass']))
  1512. {
  1513. $out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
  1514. }
  1515. foreach ($headers as $key => $value)
  1516. {
  1517. $out .= "$key: $value\r\n";
  1518. }
  1519. $out .= "Connection: Close\r\n\r\n";
  1520. fwrite($this->fp, $out);
  1521. $info = stream_get_meta_data($this->fp);
  1522. $data = '';
  1523. while (strpos($data, "\r\n\r\n") === false && $info['timed_out'] === false)
  1524. {
  1525. $data .= fgets($this->fp, 128);
  1526. $info = stream_get_meta_data($this->fp);
  1527. }
  1528. if ($info['timed_out'] === false)
  1529. {
  1530. $this->headers = $this->parse_headers($data);
  1531. if (($this->headers['status']['code'] == 301 || $this->headers['status']['code'] == 302 || $this->headers['status']['code'] == 303 || $this->headers['status']['code'] == 307) && !empty($this->headers['location']) && $this->redirects < $redirects)
  1532. {
  1533. $this->redirects++;
  1534. return $this->__construct($this->headers['location'], $timeout, $redirects, $headers, $useragent);
  1535. }
  1536. }
  1537. else
  1538. {
  1539. $this->close();
  1540. $this->success = false;
  1541. return false;
  1542. }
  1543. }
  1544. }
  1545. return $this->headers['status']['code'];
  1546. }
  1547. else
  1548. {
  1549. if ($this->fp = fopen($url, 'r'))
  1550. {
  1551. return true;
  1552. }
  1553. else
  1554. {
  1555. $this->success = false;
  1556. return false;
  1557. }
  1558. }
  1559. }
  1560. function headers()
  1561. {
  1562. return $this->headers;
  1563. }
  1564. function body()
  1565. {
  1566. if (is_null($this->body))
  1567. {
  1568. if ($this->fp)
  1569. {
  1570. $this->body = '';
  1571. while (!feof($this->fp))
  1572. {
  1573. $this->body .= fread($this->fp, 1024);
  1574. }
  1575. $this->body = trim($this->body);
  1576. $this->close();
  1577. }
  1578. else
  1579. {
  1580. return false;
  1581. }
  1582. }
  1583. return $this->body;
  1584. }
  1585. function close()
  1586. {
  1587. if (!is_null($this->fp))
  1588. {
  1589. if (fclose($this->fp))
  1590. {
  1591. $this->fp = null;
  1592. return true;
  1593. }
  1594. else
  1595. {
  1596. return false;
  1597. }
  1598. }
  1599. else
  1600. {
  1601. return false;
  1602. }
  1603. }
  1604. function parse_headers($headers)
  1605. {
  1606. $headers = explode("\r\n", trim($headers));
  1607. $status = array_shift($headers);
  1608. foreach ($headers as $header)
  1609. {
  1610. $data = explode(':', $header, 2);
  1611. $head[strtolower(trim($data[0]))] = trim($data[1]);
  1612. }
  1613. if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches))
  1614. {
  1615. if (isset($head['status']))
  1616. {
  1617. unset($head['status']);
  1618. }
  1619. $head['status']['code'] = $matches[1];
  1620. $head['status']['name'] = trim($matches[2]);
  1621. }
  1622. return $head;
  1623. }
  1624. }
  1625. class SimplePie_Cache
  1626. {
  1627. var $location;
  1628. var $filename;
  1629. var $extension;
  1630. var $name;
  1631. function SimplePie_Cache($location, $filename, $extension)
  1632. {
  1633. $this->location = $location;
  1634. $this->filename = rawurlencode($filename);
  1635. $this->extension = rawurlencode($extension);
  1636. $this->name = "$location/$this->filename.$this->extension";
  1637. }
  1638. function save($data)
  1639. {
  1640. if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
  1641. {
  1642. $fp = fopen($this->name, 'w');
  1643. if ($fp)
  1644. {
  1645. fwrite($fp, serialize($data));
  1646. fclose($fp);
  1647. return true;
  1648. }
  1649. }
  1650. return false;
  1651. }
  1652. function load()
  1653. {
  1654. if (file_exists($this->name) && is_readable($this->name))
  1655. {
  1656. return unserialize(file_get_contents($this->name));
  1657. }
  1658. return false;
  1659. }
  1660. function atime()
  1661. {
  1662. if (file_exists($this->name))
  1663. {
  1664. return fileatime($this->name);
  1665. }
  1666. return false;
  1667. }
  1668. function ctime()
  1669. {
  1670. if (file_exists($this->name))
  1671. {
  1672. return filectime($this->name);
  1673. }
  1674. return false;
  1675. }
  1676. function mtime()
  1677. {
  1678. if (file_exists($this->name))
  1679. {
  1680. return filemtime($this->name);
  1681. }
  1682. return false;
  1683. }
  1684. function touch()
  1685. {
  1686. if (file_exists($this->name))
  1687. {
  1688. return touch($this->name);
  1689. }
  1690. return false;
  1691. }
  1692. function unlink()
  1693. {
  1694. if (file_exists($this->name))
  1695. {
  1696. return unlink($this->name);
  1697. }
  1698. return false;
  1699. }
  1700. function clear($expire)
  1701. {
  1702. foreach (glob("$this->location/*.$this->extension") as $file)
  1703. {
  1704. if (time() - filemtime($file) > $expire)
  1705. {
  1706. unlink($file);
  1707. }
  1708. }
  1709. }
  1710. }
  1711. class SimplePie_Misc
  1712. {
  1713. function absolutize_url($href, $location)
  1714. {
  1715. $href_parts = @parse_url($href);
  1716. if (!empty($href_parts['scheme']))
  1717. {
  1718. return $href;
  1719. }
  1720. else
  1721. {
  1722. if (isset($location['host']))
  1723. {
  1724. $full_url = $location['scheme'] . '://' . $location['host'];
  1725. }
  1726. else
  1727. {
  1728. $full_url = '';
  1729. }
  1730. if (isset($location['port']))
  1731. {
  1732. $full_url .= ':' . $location['port'];
  1733. }
  1734. if (!empty($href_parts['path']))
  1735. {
  1736. if (substr($href_parts['path'], 0, 1) == '/')
  1737. {
  1738. $full_url .= $href_parts['path'];
  1739. }
  1740. else if (!empty($location['path']))
  1741. {
  1742. $full_url .= dirname($location['path'] . 'a') . '/' . $href_parts['path'];
  1743. }
  1744. else
  1745. {
  1746. $full_url .= $href_parts['path'];
  1747. }
  1748. }
  1749. else if (!empty($location['path']))
  1750. {
  1751. $full_url .= $location['path'];
  1752. }
  1753. else
  1754. {
  1755. $full_url .= '/';
  1756. }
  1757. if (!empty($href_parts['query']))
  1758. {
  1759. $full_url .= '?' . $href_parts['query'];
  1760. }
  1761. else if (!empty($location['query']))
  1762. {
  1763. $full_url .= '?' . $location['query'];
  1764. }
  1765. if (!empty($href_parts['fragment']))
  1766. {
  1767. $full_url .= '#' . $href_parts['fragment'];
  1768. }
  1769. else if (!empty($location['fragment']))
  1770. {
  1771. $full_url .= '#' . $location['fragment'];
  1772. }
  1773. return $full_url;
  1774. }
  1775. }
  1776. function get_element($realname, $string)
  1777. {
  1778. $return = array();
  1779. $name = preg_quote($realname, '/');
  1780. preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*(\/>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
  1781. for ($i = 0; $i < count($matches); $i++)
  1782. {
  1783. $return[$i]['tag'] = $realname;
  1784. $return[$i]['full'] = $matches[$i][0];
  1785. if (strlen($matches[$i][10]) == 2)
  1786. {
  1787. $return[$i]['self_closing'] = true;
  1788. }
  1789. else
  1790. {
  1791. $return[$i]['self_closing'] = false;
  1792. $return[$i]['content'] = $matches[$i][11];
  1793. }
  1794. $return[$i]['attribs'] = array();
  1795. if (!empty($matches[$i][2]))
  1796. {
  1797. preg_match_all('/\s((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', " $matches[$i][2] ", $attribs, PREG_SET_ORDER);
  1798. for ($j = 0; $j < count($attribs); $j++)
  1799. {
  1800. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
  1801. $first = substr($attribs[$j][2], 0, 1);
  1802. $return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
  1803. }
  1804. }
  1805. }
  1806. return $return;
  1807. }
  1808. function element_implode($element)
  1809. {
  1810. $full = "<$element[tag]";
  1811. foreach ($element['attribs'] as $key => $value)
  1812. {
  1813. $key = strtolower($key);
  1814. $full .= " $key=$value[split]$value[data]$value[split]";
  1815. }
  1816. if ($element['self_closing'])
  1817. {
  1818. $full .= ' />';
  1819. }
  1820. else
  1821. {
  1822. $full .= ">$element[content]</$element[tag]>";
  1823. }
  1824. return $full;
  1825. }
  1826. function error($message, $level, $file, $line)
  1827. {
  1828. switch ($level)
  1829. {
  1830. case E_USER_ERROR:
  1831. $note = 'PHP Error';
  1832. break;
  1833. case E_USER_WARNING:
  1834. $note = 'PHP Warning';
  1835. break;
  1836. case E_USER_NOTICE:
  1837. $note = 'PHP Notice';
  1838. break;
  1839. default:
  1840. $note = 'Unknown Error';
  1841. break;
  1842. }
  1843. error_log("$note: $message in $file on line $line", 0);
  1844. return $message;
  1845. }
  1846. function display_file($url, $timeout = 10, $useragent = null)
  1847. {
  1848. $file = new SimplePie_File($url, $timeout, 5, null, $useragent);
  1849. $headers = $file->headers();
  1850. if ($file->body() !== false)
  1851. {
  1852. header('Content-type: ' . $headers['content-type']);
  1853. echo $file->body();
  1854. exit;
  1855. }
  1856. }
  1857. /****************************************************
  1858. FIX PROTOCOL
  1859. Convert feed:// and no-protocol URL's to http://
  1860. Feed is allowed to have no protocol. Local files are toggled in init().
  1861. This is an internal function and is not intended to be used publically.
  1862. $http=1, http://www.domain.com/feed.xml (absolute)
  1863. $http=2, feed://www.domain.com/feed.xml (absolute)
  1864. $http=3, podcast://www.domain.com/feed.xml (absolute)
  1865. ****************************************************/
  1866. function fix_protocol($url, $http = 1)
  1867. {
  1868. $url = preg_replace('/^http:\/\/photocast.mac.com/i', 'http://web.mac.com', $url);
  1869. $url = preg_replace('/^(p(od)?cast|feed)[:]?[\/]*(http(s)?:\/\/)?/i', 'http://', $url);
  1870. //$url = preg_replace('/^(.*)(s)?:\/\//i', 'http\\2://', $url);
  1871. if ($http != 1 && strstr($url, 'http://'))
  1872. {
  1873. if ($http == 2)
  1874. {
  1875. $url = substr_replace($url, 'feed', 0, 4);
  1876. }
  1877. else if ($http == 3)
  1878. {
  1879. $url = substr_replace($url, 'podcast', 0, 4);
  1880. }
  1881. }
  1882. return $url;
  1883. }
  1884. function encoding($encoding)
  1885. {
  1886. $return['use_mbstring'] = false;
  1887. $return['use_iconv'] = false;
  1888. switch (strtolower($encoding))
  1889. {
  1890. // 7bit
  1891. case '7bit':
  1892. case '7-bit':
  1893. $return['encoding'] = '7bit';
  1894. $return['use_mbstring'] = true;
  1895. break;
  1896. // 8bit
  1897. case '8bit':
  1898. case '8-bit':
  1899. $return['encoding'] = '8bit';
  1900. $return['use_mbstring'] = true;
  1901. break;
  1902. // ARMSCII-8
  1903. case 'armscii-8':
  1904. case 'armscii':
  1905. $return['encoding'] = 'ARMSCII-8';
  1906. $return['use_iconv'] = true;
  1907. break;
  1908. // ASCII
  1909. case 'us-ascii':
  1910. case 'ascii':
  1911. $return['encoding'] = 'US-ASCII';
  1912. $return['use_iconv'] = true;
  1913. $return['use_mbstring'] = true;
  1914. break;
  1915. // BASE64
  1916. case 'base64':
  1917. case 'base-64':
  1918. $return['encoding'] = 'BASE64';
  1919. $return['use_mbstring'] = true;
  1920. break;
  1921. // Big5 - Traditional Chinese, mainly used in Taiwan
  1922. case 'big5':
  1923. case '950':
  1924. $return['encoding'] = 'BIG5';
  1925. $return['use_iconv'] = true;
  1926. $return['use_mbstring'] = true;
  1927. break;
  1928. // Big5 with Hong Kong extensions, Traditional Chinese
  1929. case 'big5-hkscs':
  1930. $return['encoding'] = 'BIG5-HKSCS';
  1931. $return['use_iconv'] = true;
  1932. $return['use_mbstring'] = true;
  1933. break;
  1934. // byte2be
  1935. case 'byte2be':
  1936. $return['encoding'] = 'byte2be';
  1937. $return['use_mbstring'] = true;
  1938. break;
  1939. // byte2le
  1940. case 'byte2le':
  1941. $return['encoding'] = 'byte2le';
  1942. $return['use_mbstring'] = true;
  1943. break;
  1944. // byte4be
  1945. case 'byte4be':
  1946. $return['encoding'] = 'byte4be';
  1947. $return['use_mbstring'] = true;
  1948. break;
  1949. // byte4le
  1950. case 'byte4le':
  1951. $return['encoding'] = 'byte4le';
  1952. $return['use_mbstring'] = true;
  1953. break;
  1954. // EUC-CN
  1955. case 'euc-cn':
  1956. case 'euccn':
  1957. $return['encoding'] = 'EUC-CN';
  1958. $return['use_iconv'] = true;
  1959. $return['use_mbstring'] = true;
  1960. break;
  1961. // EUC-JISX0213
  1962. case 'euc-jisx0213':
  1963. case 'eucjisx0213':
  1964. $return['encoding'] = 'EUC-JISX0213';
  1965. $return['use_iconv'] = true;
  1966. break;
  1967. // EUC-JP
  1968. case 'euc-jp':
  1969. case 'eucjp':
  1970. $return['encoding'] = 'EUC-JP';
  1971. $return['use_iconv'] = true;
  1972. $return['use_mbstring'] = true;
  1973. break;
  1974. // EUCJP-win
  1975. case 'euc-jp-win':
  1976. case 'eucjp-win':
  1977. case 'eucjpwin':
  1978. $return['encoding'] = 'EUCJP-win';
  1979. $return['use_iconv'] = true;
  1980. $return['use_mbstring'] = true;
  1981. break;
  1982. // EUC-KR
  1983. case 'euc-kr':
  1984. case 'euckr':
  1985. $return['encoding'] = 'EUC-KR';
  1986. $return['use_iconv'] = true;
  1987. $return['use_mbstring'] = true;
  1988. break;
  1989. // EUC-TW
  1990. case 'euc-tw':
  1991. case 'euctw':
  1992. $return['encoding'] = 'EUC-TW';
  1993. $return['use_iconv'] = true;
  1994. $return['use_mbstring'] = true;
  1995. break;
  1996. // GB18030 - Simplified Chinese, national standard character set
  1997. case 'gb18030-2000':
  1998. case 'gb18030':
  1999. $return['encoding'] = 'GB18030';
  2000. $return['use_iconv'] = true;
  2001. break;
  2002. // GB2312 - Simplified Chinese, national standard character set
  2003. case 'gb2312':
  2004. case '936':
  2005. $return['encoding'] = 'GB2312';
  2006. $return['use_mbstring'] = true;
  2007. break;
  2008. // GBK
  2009. case 'gbk':
  2010. $return['encoding'] = 'GBK';
  2011. $return['use_iconv'] = true;
  2012. break;
  2013. // Georgian-Academy
  2014. case 'georgian-academy':
  2015. $return['encoding'] = 'Georgian-Academy';
  2016. $return['use_iconv'] = true;
  2017. break;
  2018. // Georgian-PS
  2019. case 'georgian-ps':
  2020. $return['encoding'] = 'Georgia…

Large files files are truncated, but you can click here to view the full file