PageRenderTime 81ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/simplepie/simplepie.test.inc

https://github.com/komagata/plnet
PHP | 4487 lines | 3815 code | 310 blank | 362 comment | 626 complexity | 553f2dddde77ba9f8e0633fb8cc1f096 MD5 | raw file
Possible License(s): LGPL-2.1

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

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