PageRenderTime 71ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/simplepie/simplepie.inc

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

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