PageRenderTime 204ms CodeModel.GetById 19ms app.highlight 167ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/simplepie/simplepie.test.inc

https://github.com/komagata/plnet
PHP | 4487 lines | 3815 code | 310 blank | 362 comment | 626 complexity | 553f2dddde77ba9f8e0633fb8cc1f096 MD5 | raw file

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

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

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