PageRenderTime 792ms CodeModel.GetById 163ms app.highlight 513ms RepoModel.GetById 89ms app.codeStats 2ms

/lib/simplepie/simplepie_060803.inc

https://github.com/komagata/plnet
PHP | 4471 lines | 3802 code | 307 blank | 362 comment | 619 complexity | 6ebb26fb8e7581b0d788a2c60cf3e934 MD5 | raw file

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: 3 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 = '20060803';
  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', 'id', 'style', 'onclick', '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)
 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 = null)
 995	{
 996		if (is_null($key))
 997		{
 998			return $this->get_categories();
 999		}
1000		else
1001		{
1002			$categories = $this->get_categories();
1003			if (!empty($categories[$key]))
1004			{
1005				return $categories[$key];
1006			}
1007			else
1008			{
1009				return false;
1010			}
1011		}
1012	}
1013	
1014	function get_categories()
1015	{
1016		$categories = array();
1017		if (!empty($this->data['category']))
1018		{
1019			$categories = array_merge($categories, $this->data['category']);
1020		}
1021		if (!empty($this->data['subject']))
1022		{
1023			$categories = array_merge($categories, $this->data['subject']);
1024		}
1025		if (!empty($categories))
1026		{
1027			return array_unique($categories);
1028		}
1029		else
1030		{
1031			return false;
1032		}
1033	}
1034	
1035	function get_author($key)
1036	{
1037		$authors = $this->get_authors();
1038		if (!empty($authors[$key]))
1039		{
1040			return $authors[$key];
1041		}
1042		else
1043		{
1044			return false;
1045		}
1046	}
1047	
1048	function get_authors()
1049	{
1050		$authors = array();
1051		if (!empty($this->data['author']))
1052		{
1053			$authors = array_merge($authors, $this->data['author']);
1054		}
1055		if (!empty($this->data['creator']))
1056		{
1057			$authors = array_merge($authors, $this->data['creator']);
1058		}
1059		if (!empty($authors))
1060		{
1061			return array_unique($authors);
1062		}
1063		else
1064		{
1065			return false;
1066		}
1067	}
1068	
1069	function get_date($date_format = 'j F Y, g:i a')
1070	{
1071		if (!empty($this->data['pubdate']))
1072		{
1073			return date($date_format, $this->data['pubdate']);
1074		}
1075		else if (!empty($this->data['dc:date']))
1076		{
1077			return date($date_format, $this->data['dc:date']);
1078		}
1079		else if (!empty($this->data['issued']))
1080		{
1081			return date($date_format, $this->data['issued']);
1082		}
1083		else if (!empty($this->data['published']))
1084		{
1085			return date($date_format, $this->data['published']);
1086		}
1087		else if (!empty($this->data['modified']))
1088		{
1089			return date($date_format, $this->data['modified']);
1090		}
1091		else if (!empty($this->data['updated']))
1092		{
1093			return date($date_format, $this->data['updated']);
1094		}
1095		else
1096		{
1097			return false;
1098		}
1099	}
1100	
1101	function get_permalink()
1102	{
1103		$link = $this->get_link(0);
1104		$enclosure = $this->get_enclosure(0);
1105		if (!empty($link))
1106		{
1107			return $link;
1108		}
1109		else if (!empty($enclosure))
1110		{
1111			return $enclosure->get_link();
1112		}
1113		else
1114		{
1115			return false;
1116		}
1117	}
1118	
1119	function get_link($key, $rel = 'alternate')
1120	{
1121		$links = $this->get_links($rel);
1122		if (!empty($links[$key]))
1123		{
1124			return $links[$key];
1125		}
1126		else
1127		{
1128			return false;
1129		}
1130	}
1131	
1132	function get_links($rel = 'alternate')
1133	{
1134		if (!empty($this->data['link'][$rel]))
1135		{
1136			return $this->data['link'][$rel];
1137		}
1138		else
1139		{
1140			return false;
1141		}
1142	}
1143	
1144	function get_enclosure($key)
1145	{
1146		$enclosures = $this->get_enclosures();
1147		if (!empty($enclosures[$key]))
1148		{
1149			return $enclosures[$key];
1150		}
1151		else
1152		{
1153			return false;
1154		}
1155	}
1156	
1157	function get_enclosures()
1158	{
1159		$enclosures = array();
1160		$links = $this->get_links('enclosure');
1161		if (!empty($this->data['enclosures']))
1162		{
1163			$enclosures = array_merge($enclosures, $this->data['enclosures']);
1164		}
1165		if (!empty($links))
1166		{
1167			$enclosures = array_merge($enclosures, $links);
1168		}
1169		if (!empty($enclosures))
1170		{
1171			return array_unique($enclosures);
1172		}
1173		else
1174		{
1175			return false;
1176		}
1177	}
1178	
1179	function add_to_blinklist()
1180	{
1181		if ($this->get_permalink())
1182		{
1183			$url = 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Description=&amp;Url=' . rawurlencode($this->get_permalink());
1184			if ($this->get_title())
1185			{
1186				$url .= '&amp;Title=' . rawurlencode($this->get_title());
1187			}
1188			return $url;
1189		}
1190		else
1191		{
1192			return false;
1193		}
1194	}
1195	
1196	function add_to_blogmarks()
1197	{
1198		if ($this->get_permalink())
1199		{
1200			$url = 'http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url=' . rawurlencode($this->get_permalink());
1201			if ($this->get_title())
1202			{
1203				$url .= '&amp;title=' . rawurlencode($this->get_title());
1204			}
1205			return $url;
1206		}
1207		else
1208		{
1209			return false;
1210		}
1211	}
1212	
1213	function add_to_delicious()
1214	{
1215		if ($this->get_permalink())
1216		{
1217			$url = 'http://del.icio.us/post/?v=3&amp;url=' . rawurlencode($this->get_permalink());
1218			if ($this->get_title())
1219			{
1220				$url .= '&amp;title=' . rawurlencode($this->get_title());
1221			}
1222			return $url;
1223		}
1224		else
1225		{
1226			return false;
1227		}
1228	}
1229	
1230	function add_to_digg()
1231	{
1232		if ($this->get_permalink())
1233		{
1234			return 'http://digg.com/submit?phase=2&amp;URL=' . rawurlencode($this->get_permalink());
1235		}
1236		else
1237		{
1238			return false;
1239		}
1240	}
1241	
1242	function add_to_furl()
1243	{
1244		if ($this->get_permalink())
1245		{
1246			$url = 'http://www.furl.net/storeIt.jsp?u=' . rawurlencode($this->get_permalink());
1247			if ($this->get_title())
1248			{
1249				$url .= '&amp;t=' . rawurlencode($this->get_title());
1250			}
1251			return $url;
1252		}
1253		else
1254		{
1255			return false;
1256		}
1257	}
1258	
1259	function add_to_magnolia()
1260	{
1261		if ($this->get_permalink())
1262		{
1263			$url = 'http://ma.gnolia.com/bookmarklet/add?url=' . rawurlencode($this->get_permalink());
1264			if ($this->get_title())
1265			{
1266				$url .= '&amp;title=' . rawurlencode($this->get_title());
1267			}
1268			return $url;
1269		}
1270		else
1271		{
1272			return false;
1273		}
1274	}
1275	
1276	function add_to_myweb20()
1277	{
1278		if ($this->get_permalink())
1279		{
1280			$url = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=' . rawurlencode($this->get_permalink());
1281			if ($this->get_title())
1282			{
1283				$url .= '&amp;t=' . rawurlencode($this->get_title());
1284			}
1285			return $url;
1286		}
1287		else
1288		{
1289			return false;
1290		}
1291	}
1292	
1293	function add_to_newsvine()
1294	{
1295		if ($this->get_permalink())
1296		{
1297			$url = 'http://www.newsvine.com/_wine/save?u=' . rawurlencode($this->get_permalink());
1298			if ($this->get_title())
1299			{
1300				$url .= '&amp;h=' . rawurlencode($this->get_title());
1301			}
1302			return $url;
1303		}
1304		else
1305		{
1306			return false;
1307		}
1308	}
1309	
1310	function add_to_reddit()
1311	{
1312		if ($this->get_permalink())
1313		{
1314			$url = 'http://reddit.com/submit?url=' . rawurlencode($this->get_permalink());
1315			if ($this->get_title())
1316			{
1317				$url .= '&amp;title=' . rawurlencode($this->get_title());
1318			}
1319			return $url;
1320		}
1321		else
1322		{
1323			return false;
1324		}
1325	}
1326	
1327	function add_to_segnalo()
1328	{
1329		if ($this->get_permalink())
1330		{
1331			$url = 'http://segnalo.com/post.html.php?url=' . rawurlencode($this->get_permalink());
1332			if ($this->get_title())
1333			{
1334				$url .= '&amp;title=' . rawurlencode($this->get_title());
1335			}
1336			return $url;
1337		}
1338		else
1339		{
1340			return false;
1341		}
1342	}
1343	
1344	function add_to_simpy()
1345	{
1346		if ($this->get_permalink())
1347		{
1348			$url = 'http://www.simpy.com/simpy/LinkAdd.do?href=' . rawurlencode($this->get_permalink());
1349			if ($this->get_title())
1350			{
1351				$url .= '&amp;title=' . rawurlencode($this->get_title());
1352			}
1353			return $url;
1354		}
1355		else
1356		{
1357			return false;
1358		}
1359	}
1360	
1361	function add_to_smarking()
1362	{
1363		if ($this->get_permalink())
1364		{
1365			return 'http://smarking.com/editbookmark/?url=' . rawurlencode($this->get_permalink());
1366		}
1367		else
1368		{
1369			return false;
1370		}
1371	}
1372	
1373	function add_to_spurl()
1374	{
1375		if ($this->get_permalink())
1376		{
1377			$url = 'http://www.spurl.net/spurl.php?v=3&amp;url=' . rawurlencode($this->get_permalink());
1378			if ($this->get_title())
1379			{
1380				$url .= '&amp;title=' . rawurlencode($this->get_title());
1381			}
1382			return $url;
1383		}
1384		else
1385		{
1386			return false;
1387		}
1388	}
1389	
1390	function add_to_wists()
1391	{
1392		if ($this->get_permalink())
1393		{
1394			$url = 'http://wists.com/r.php?c=&amp;r=' . rawurlencode($this->get_permalink());
1395			if ($this->get_title())
1396			{
1397				$url .= '&amp;title=' . rawurlencode($this->get_title());
1398			}
1399			return $url;
1400		}
1401		else
1402		{
1403			return false;
1404		}
1405	}
1406	
1407	function search_technorati()
1408	{
1409		if ($this->get_permalink())
1410		{
1411			return 'http://www.technorati.com/search/' . rawurlencode($this->get_permalink());
1412		}
1413		else
1414		{
1415			return false;
1416		}
1417	}
1418}
1419
1420class SimplePie_Author
1421{
1422	var $name;
1423	var $link;
1424	var $email;
1425	
1426	// Constructor, used to input the data
1427	function SimplePie_Author($name, $link, $email) {
1428		$this->name = $name;
1429		$this->link = $link;
1430		$this->email = $email;
1431	}
1432	
1433	function get_name() {
1434		return (empty($this->name)) ? false : $this->name;
1435	}
1436	
1437	function get_link() {
1438		return (empty($this->link)) ? false : $this->link;
1439	}
1440	
1441	function get_email() {
1442		return (empty($this->email)) ? false : $this->email;
1443	}
1444}
1445
1446class SimplePie_Enclosure
1447{
1448	var $link;
1449	var $type;
1450	var $length;
1451
1452	// Constructor, used to input the data
1453	function SimplePie_Enclosure($link, $type, $length) {
1454		$this->link = $link;
1455		$this->type = $type;
1456		$this->length = $length;
1457	}
1458
1459	function get_link() {
1460		return (empty($this->link)) ? false : $this->link;
1461	}
1462
1463	function get_extension() {
1464		if (!empty($this->link)) {
1465			return pathinfo($this->link, PATHINFO_EXTENSION);
1466		} else {
1467			return false;
1468		}
1469	}
1470
1471	function get_type() {
1472		return (empty($this->type)) ? false : $this->type;
1473	}
1474
1475	function get_length() {
1476		return (empty($this->length)) ? false : $this->length;
1477	}
1478
1479	function get_size() {
1480		return (empty($this->length)) ? false : round(($this->length/1048576), 2);
1481	}
1482
1483	function embed($options) {
1484
1485		// Set up defaults
1486		$audio='';
1487		$video='';
1488		$alt='';
1489		$altclass='';
1490		$loop='false';
1491		$width='auto';
1492		$height='auto';
1493		$bgcolor='#ffffff';
1494		$embed='';
1495
1496		// Process options and reassign values as necessary
1497		$options = explode(',', $options);
1498		foreach($options as $option) {
1499			$opt = explode(':', trim($option));
1500			if ($opt[0] == 'audio') $audio=$opt[1];
1501			else if ($opt[0] == 'video') $video=$opt[1];
1502			else if ($opt[0] == 'alt') $alt=$opt[1];
1503			else if ($opt[0] == 'altclass') $altclass=$opt[1];
1504			else if ($opt[0] == 'loop') $loop=$opt[1];
1505			else if ($opt[0] == 'width') $width=$opt[1];
1506			else if ($opt[0] == 'height') $height=$opt[1];
1507			else if ($opt[0] == 'bgcolor') $bgcolor=$opt[1];
1508		}
1509
1510		// Process values for 'auto'
1511		if ($width == 'auto') {
1512			if (stristr($this->type, 'audio/')) $width='100%';
1513			else if (stristr($this->type, 'video/')) $width='320';
1514			else $width='100%';
1515		}
1516		if ($height == 'auto') {
1517			if (stristr($this->type, 'audio/')) $height=0;
1518			else if (stristr($this->type, 'video/')) $height=240;
1519			else $height=256;
1520		}
1521
1522		// Set proper placeholder value
1523		if (stristr($this->type, 'audio/')) $placeholder=$audio;
1524		else if (stristr($this->type, 'video/')) $placeholder=$video;
1525
1526		// Make sure the JS library is included
1527		// (I know it'll be included multiple times, but I can't think of a better way to do this automatically)
1528		$embed.='<script type="text/javascript" src="?js"></script>';
1529
1530		// Odeo Feed MP3's
1531		if (substr(strtolower($this->link), 0, 15) == 'http://odeo.com') {
1532			$embed.='<script type="text/javascript">embed_odeo("'.$this->link.'");</script>';
1533		}
1534
1535		// QuickTime 7 file types.  Need to test with QuickTime 6.
1536		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') {
1537			$height+=16;
1538			$embed.='<script type="text/javascript">embed_quicktime("'.$this->type.'", "'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$placeholder.'", "'.$loop.'");</script>';
1539		}
1540
1541		// Flash
1542		else if ($this->type == 'application/x-shockwave-flash' || $this->type == 'application/futuresplash') {
1543			$embed.='<script type="text/javascript">embed_flash("'.$bgcolor.'", "'.$width.'", "'.$height.'", "'.$this->link.'", "'.$loop.'", "'.$this->type.'");</script>';
1544		}
1545
1546		// Windows Media
1547		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') {
1548			$height+=45;
1549			$embed.='<script type="text/javascript">embed_wmedia("'.$width.'", "'.$height.'", "'.$this->link.'");</script>';
1550		}
1551
1552		// Everything else
1553		else $embed.='<a href="' . $this->link . '" class="' . $altclass . '">' . $alt . '</a>';
1554
1555		return $embed;
1556	}
1557}
1558
1559class SimplePie_File
1560{
1561	var $url;
1562	var $useragent;
1563	var $success = true;
1564	var $headers = array();
1565	var $body;
1566	var $fp;
1567	var $redirects = 0;
1568	
1569	function SimplePie_File($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null)
1570	{
1571		if (class_exists('idna_convert'))
1572		{
1573			$idn = new idna_convert;
1574			$url = $idn->encode($url);
1575		}
1576		$this->url = $url;
1577		$this->useragent = $useragent;
1578		if (preg_match('/^http(s)?:\/\//i', $url))
1579		{
1580			if (empty($useragent))
1581			{
1582				$useragent = ini_get('user_agent');
1583				$this->useragent = $useragent;
1584			}
1585			if (!is_array($headers))
1586			{
1587				$headers = array();
1588			}
1589			if (extension_loaded('curl'))
1590			{
1591				$headers2 = array();
1592				foreach ($headers as $key => $value)
1593				{
1594					$headers2[] = "$key: $value";
1595				}
1596				$fp = curl_init();
1597				curl_setopt($fp, CURLOPT_URL, $url);
1598				curl_setopt($fp, CURLOPT_HEADER, 1);
1599				curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
1600				curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
1601				curl_setopt($fp, CURLOPT_REFERER, $url);
1602				curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
1603				curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1);
1604				curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects);
1605				curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
1606				$this->headers = trim(curl_exec($fp));
1607				if (curl_errno($fp))
1608				{
1609					$this->success = false;
1610					return false;
1611				}
1612				else
1613				{
1614					$info = curl_getinfo($fp);
1615					$this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 2);
1616					$this->body = array_pop($this->headers);
1617					$this->headers = array_pop($this->headers);
1618					$this->headers = $this->parse_headers($this->headers);
1619				}
1620			}
1621			else
1622			{
1623				$url_parts = parse_url($url);
1624				if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) == 'https')
1625				{
1626					$url_parts['host'] = "ssl://$url_parts[host]";
1627					$url_parts['port'] = 443;
1628				}
1629				if (!isset($url_parts['port']))
1630				{
1631					$url_parts['port'] = 80;
1632				}
1633				$this->fp = fsockopen($url_parts['host'], $url_parts['port'], $errno, $errstr, $timeout);
1634				if (!$this->fp)
1635				{
1636					$this->success = false;
1637					return false;
1638				}
1639				else
1640				{
1641					stream_set_timeout($this->fp, $timeout);
1642					$get = (isset($url_parts['query'])) ? "$url_parts[path]?$url_parts[query]" : $url_parts['path'];
1643					$out = "GET $get HTTP/1.0\r\n";
1644					$out .= "Host: $url_parts[host]\r\n";
1645					$out .= "User-Agent: $useragent\r\n";
1646					if (!empty($url_parts['user']) && !empty($url_parts['pass']))
1647					{
1648						$out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
1649					}
1650					foreach ($headers as $key => $value)
1651					{
1652						$out .= "$key: $value\r\n";
1653					}
1654					$out .= "Connection: Close\r\n\r\n";
1655					fwrite($this->fp, $out);
1656					
1657					$info = stream_get_meta_data($this->fp);
1658					$data = '';
1659					while (strpos($data, "\r\n\r\n") === false && $info['timed_out'] === false)
1660					{
1661						$data .= fgets($this->fp, 128);
1662						$info = stream_get_meta_data($this->fp);
1663					}
1664					if ($info['timed_out'] === false)
1665					{
1666						$this->headers = $this->parse_headers($data);
1667						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)
1668						{
1669							$this->redirects++;
1670							return $this->__construct($this->headers['location'], $timeout, $redirects, $headers, $useragent);
1671						}
1672					}
1673					else
1674					{
1675						$this->close();
1676						$this->success = false;
1677						return false;
1678					}
1679				}
1680			}
1681			return $this->headers['status']['code'];
1682		}
1683		else
1684		{
1685			if ($this->fp = fopen($url, 'r'))
1686			{
1687				return true;
1688			}
1689			else
1690			{
1691				$this->success = false;
1692				return false;
1693			}
1694		}
1695	}
1696	
1697	function headers()
1698	{
1699		return $this->headers;
1700	}
1701	
1702	function body()
1703	{
1704		if (is_null($this->body))
1705		{
1706			if ($this->fp)
1707			{
1708				$this->body = '';
1709				while (!feof($this->fp))
1710				{
1711					$this->body .= fread($this->fp, 1024);
1712				}
1713				$this->body = trim($this->body);
1714				$this->close();
1715			}
1716			else
1717			{
1718				return false;
1719			}
1720		}
1721		return $this->body;
1722	}
1723	
1724	function close()
1725	{
1726		if (!is_null($this->fp))
1727		{
1728			if (fclose($this->fp))
1729			{
1730				$this->fp = null;
1731				return true;
1732			}
1733			else
1734			{
1735				return false;
1736			}
1737		}
1738		else
1739		{
1740			return false;
1741		}
1742	}
1743	
1744	function parse_headers($headers)
1745	{
1746		$headers = explode("\r\n", trim($headers));
1747		$status = array_shift($headers);
1748		foreach ($headers as $header)
1749		{
1750			$data = explode(':', $header, 2);
1751			$head[strtolower(trim($data[0]))] = trim($data[1]);
1752		}
1753		if (preg_match('/HTTP\/[0-9\.]+ ([0-9]+)(.*)$/i', $status, $matches))
1754		{
1755			if (isset($head['status']))
1756			{
1757				unset($head['status']);
1758			}
1759			$head['status']['code'] = $matches[1];
1760			$head['status']['name'] = trim($matches[2]);
1761		}
1762		return $head;
1763	}
1764}
1765
1766class SimplePie_Cache
1767{
1768	var $location;
1769	var $filename;
1770	var $extension;
1771	var $name;
1772	
1773	function SimplePie_Cache($location, $filename, $extension)
1774	{
1775		$this->location = $location;
1776		$this->filename = rawurlencode($filename);
1777		$this->extension = rawurlencode($extension);
1778		$this->name = "$location/$this->filename.$this->extension";
1779	}
1780	
1781	function save($data)
1782	{
1783		if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location))
1784		{
1785			$fp = fopen($this->name, 'w');
1786			if ($fp)
1787			{
1788				fwrite($fp, serialize($data));
1789				fclose($fp);
1790				return true;
1791			}
1792		}
1793		return false;
1794	}
1795	
1796	function load()
1797	{
1798		if (file_exists($this->name) && is_readable($this->name))
1799		{
1800			return unserialize(file_get_contents($this->name));
1801		}
1802		return false;
1803	}
1804	
1805	function atime()
1806	{
1807		if (file_exists($this->name))
1808		{
1809			return fileatime($this->name);
1810		}
1811		return false;
1812	}
1813	
1814	function ctime()
1815	{
1816		if (file_exists($this->name))
1817		{
1818			return filectime($this->name);
1819		}
1820		return false;
1821	}
1822	
1823	function mtime()
1824	{
1825		if (file_exists($this->name))
1826		{
1827			return filemtime($this->name);
1828		}
1829		return false;
1830	}
1831	
1832	function touch()
1833	{
1834		if (file_exists($this->name))
1835		{
1836			return touch($this->name);
1837		}
1838		return false;
1839	}
1840	
1841	function unlink()
1842	{
1843		if (file_exists($this->name))
1844		{
1845			return unlink($this->name);
1846		}
1847		return false;
1848	}
1849	
1850	function clear($expire)
1851	{
1852		foreach (glob("$this->location/*.$this->extension") as $file)
1853		{
1854			if (time() - filemtime($file) > $expire)
1855			{
1856				unlink($file);
1857			}
1858		}
1859	}
1860}
1861
1862class SimplePie_Misc
1863{
1864	function absolutize_url($href, $location)
1865	{
1866		$href_parts = @parse_url($href);
1867		if (!empty($href_parts['scheme']))
1868		{
1869			return $href;
1870		}
1871		else
1872		{
1873			if (isset($location['host']))
1874			{
1875				$full_url = $location['scheme'] . '://' . $location['host'];
1876			}
1877			else
1878			{
1879				$full_url = '';
1880			}
1881			if (isset($location['port']))
1882			{
1883				$full_url .= ':' . $location['port'];
1884			}
1885			if (!empty($href_parts['path']))
1886			{
1887				if (substr($href_parts['path'], 0, 1) == '/')
1888				{
1889					$full_url .= $href_parts['path'];
1890				}
1891				else if (!empty($location['path']))
1892				{
1893					$full_url .= dirname($location['path'] . 'a') . '/' . $href_parts['path'];
1894				}
1895				else
1896				{
1897					$full_url .= $href_parts['path'];
1898				}
1899			}
1900			else if (!empty($location['path']))
1901			{
1902				$full_url .= $location['path'];
1903			}
1904			else
1905			{
1906				$full_url .= '/';
1907			}
1908			if (!empty($href_parts['query']))
1909			{
1910				$full_url .= '?' . $href_parts['query'];
1911			}
1912			else if (!empty($location['query']))
1913			{
1914				$full_url .= '?' . $location['query'];
1915			}
1916			if (!empty($href_parts['fragment']))
1917			{
1918				$full_url .= '#' . $href_parts['fragment'];
1919			}
1920			else if (!empty($location['fragment']))
1921			{
1922				$full_url .= '#' . $location['fragment'];
1923			}
1924			return $full_url;
1925		}
1926	}
1927	
1928	function get_element($realname, $string)
1929	{
1930		$return = array();
1931		$name = preg_quote($realname, '/');
1932		preg_match_all("/<($name)((\s*((\w+:)?\w+)\s*=\s*(\"([^\"]*)\"|'([^']*)'|(.*)))*)\s*(\/>|>(.*)<\/$name>)/msiU", $string, $matches, PREG_SET_ORDER);
1933		for ($i = 0; $i < count($matches); $i++)
1934		{
1935			$return[$i]['tag'] = $realname;
1936			$return[$i]['full'] = $matches[$i][0];
1937			if (strlen($matches[$i][10]) == 2)
1938			{
1939				$return[$i]['self_closing'] = true;
1940			}
1941			else
1942			{
1943				$return[$i]['self_closing'] = false;
1944				$return[$i]['content'] = $matches[$i][11];
1945			}
1946			$return[$i]['attribs'] = array();
1947			if (!empty($matches[$i][2]))
1948			{
1949				preg_match_all('/\s((\w+:)?\w+)\s*=\s*("([^"]*)"|\'([^\']*)\'|(\S+))\s/msiU', " $matches[$i][2] ", $attribs, PREG_SET_ORDER);
1950				for ($j = 0; $j < count($attribs);  $j++)
1951				{
1952					$return[$i]['attribs'][strtoupper($attribs[$j][1])]['data'] = $attribs[$j][count($attribs[$j])-1];
1953					$first = substr($attribs[$j][2], 0, 1);
1954					$return[$i]['attribs'][strtoupper($attribs[$j][1])]['split'] = ($first == '"' || $first == "'") ? $first : '"';
1955				}
1956			}
1957		}
1958		return $return;
1959	}
1960	
1961	function element_implode($element)
1962	{
1963		$full = "<$element[tag]";
1964		foreach ($element['attribs'] as $key => $value)
1965		{
1966			$key = strtolower($key);
1967			$full .= " $key=$value[split]$value[data]$value[split]";
1968		}
1969		if ($element['self_closing'])
1970		{
1971			$full .= ' />';
1972		}
1973		else
1974		{
1975			$full .= ">$element[content]</$element[tag]>";
1976		}
1977		return $full;
1978	}
1979	
1980	function error($message, $level, $file, $line)
1981	{
1982		switch ($level)
1983		{
1984			case E_USER_ERROR:
1985				$note = 'PHP Error';
1986				break;
1987			case E_USER_WARNING:
1988				$note = 'PHP Warning';
1989				break;
1990			case E_USER_NOTICE:
1991				$note = 'PHP Notice';
1992				break;
1993			default:
1994				$note = 'Unknown Error';
1995				break;
1996		}
1997		error_log("$note: $message in $file on line $line", 0);
1998		return $message;
1999	}
2000	
2001	function display_file($url, $timeout = 10, $useragent = null)
2002	{
2003		$file = new SimplePie_File($url, $timeout, 5, null, $useragent);
2004		$headers = $file->headers();
2005		if ($file->body() !== false)
2006		{
2007			header('Content-type: ' . $headers['content-type']);
2008			echo $file->body();
2009			exit;
2010		}
2011	}
2012	
2013	/****************************************************
2014	FIX PROTOCOL
2015	Convert feed:// and no-protocol URL's to http://
2016	Feed is allowed to have no protocol.  Local files are toggled in init().
2017	This is an internal function and is not intended to be used publically.
2018
2019	$http=1, http://www.domain.com/feed.xml (absolute)
2020	$http=2, feed://www.domain.com/feed.xml (absolute)
2021	$http=3, podcast://www.domain.com/feed.xml (absolute)
2022	****************************************************/
2023	function fix_protocol($url, $http = 1)
2024	{
2025		$url = preg_replace('/^http:\/\/photocast.mac.com/i', 'http://web.mac.com', $url);
2026		$url = preg_replace('/^(p(od)?cast|feed)[:]?[\/]*(http(s)?:\/\/)?/i', 'http://', $url);
2027		//$url = preg_replace('/^(.*)(s)?:\/\//i', 'http\\2://', $url);
2028
2029		if ($http != 1 && strstr($url, 'http://'))
2030		{
2031			if ($http == 2)
2032			{
2033				$url = substr_replace($url, 'feed', 0, 4);
2034			}
2035			else if ($http == 3)
2036			{
2037				$url = substr_replace($url, 'podcast', 0, 4);
2038			}
2039		}
2040		return $url;
2041	}
2042	
2043	function encoding($encoding)
2044	{
2045		$return['use_mbstring'] = false;
2046		$return['use_iconv'] = false;
2047		switch (strtolower($encoding))
2048		{
2049
2050			// 7bit
2051			case '7bit':
2052			case '7-bit':
2053				$return['encoding'] = '7bit';
2054				$return['use_mbstring'] = true;
2055				break;
2056
2057			// 8bit
2058			case '8bit':
2059			case '8-bit':
2060				$return['encoding'] = '8bit';
2061				$return['use_mbstring'] = true;
2062				break;
2063
2064			// ARMSCII-8
2065			case 'armscii-8':
2066			case 'armscii':
2067				$return['encoding'] = 'ARMSCII-8';
2068				$return['use_iconv'] = true;
2069				break;
2070
2071			// ASCII
2072			case 'us-ascii':
2073			case 'ascii':
2074				$return['encoding'] = 'US-ASCII';
2075				$return['use_iconv'] = true;
2076				$return['use_mbstring'] = true;
2077				break;
2078
2079			// BASE64
2080			case 'base64':
2081			case 'base-64':
2082				$return['encoding'] = 'BASE64';
2083				$return['use_mbstring'] = true;
2084				break;
2085
2086			// Big5 - Traditional Chinese, mainly used in Taiwan
2087			case 'big5':
2088			case '950':
2089				$return['encoding'] = 'BIG5';
2090				$return['use_iconv'] = true;
2091				$return['use_mbstring'] = true;
2092				break;
2093
2094			// Big5 with Hong Kong extensions, Traditional Chinese
2095			case 'big5-hkscs':
2096				$return['encoding'] = 'BIG5-HKSCS';
2097				$return['use_iconv'] = true;
2098				$return['use_mbstring'] = true;
2099				break;
2100
2101			// byte2be
2102			case 'byte2be':
2103				$return['encoding'] = 'byte2be';
2104				$return['use_mbstring'] = true;
2105				break;
2106
2107			// byte2le
2108			case 'byte2le':
2109				$return['encoding'] = 'byte2le';
2110				$return['use_mbstring'] = true;
2111				break;
2112
2113			// byte4be
2114			case 'byte4be':
2115				$return['encoding'] = 'byte4be';
2116				$return['use_mbstring'] = true;
2117				break;
2118
2119			// byte4le
2120			case 'byte4le':
2121				$return['encoding'] = 'byte4le';
2122				$return['use_mbstring'] = true;
2123				break;
2124
2125			// EUC-CN
2126			case 'euc-cn':
2127			case 'euccn':
2128				$return['encoding'] = 'EUC-CN';
2129				$return['use_iconv'] = true;
2130				$return['use_mbstring'] = true;
2131				break;
2132
2133			// EUC-JISX0213
2134			case 'euc-jisx0213':
2135			case 'eucjisx0213':
2136				$return['encoding'] = 'EUC-JISX0213';
2137				$return['use_iconv'] = true;
2138				break;
2139
2140			// EUC-JP
2141			case 'euc-jp':
2142			case 'eucjp':
2143				$return['encoding'] = 'EUC-JP';
2144				$return['use_iconv'] = true;
2145				$return['use_mbstring'] = true;
2146				break;
2147
2148			// EUCJP-win
2149			case 'euc-jp-win':
2150			case 'eucjp-win':
2151			case 'eucjpwin':
2152				$return['encoding'] = 'EUCJP-win';
2153				$return['use_iconv'] = true;
2154				$return['use_mbstring'] = true;
2155				break;
2156
2157			// EUC-KR
2158			case 'euc-kr':
2159			case 'euckr':
2160				$return['encoding'] = 'EUC-KR';
2161				$return['use_iconv'] = true;
2162				$return['use_mbstring'] = true;
2163				break;
2164
2165			// EUC-TW
2166			case 'euc-tw':
2167			case 'euctw':
2168				$return['encoding'] = 'EUC-TW';
2169				$return['use_iconv'] = true;
2170				$return['use_mbstring'] = true;
2171				break;
2172
2173			// GB18030 - Simplified Chinese, national standard character set
2174			case 'gb18030-2000':
2175			case 'gb18030':
2176				$return['encoding'] = 'GB18030';
2177				$return['use_iconv'] = true;
2178				break;
2179
2180			// GB2312 - Simplified Chinese, national standard character set
2181			case 'gb2312':
2182			case '936':
2183				$return['encoding'] = 'GB2312';
2184				$return['use_mbstring'] = true;
2185				break;
2186
2187			// GBK
2188			case 'gbk':
2189				$return['encoding'] = 'GBK';
2190				$return['use_iconv'] = true;
2191				break;
2192
2193			// Georgian-Academy
2194			case 'georgian-academy':
2195				$return['encoding'] = 'Georgian-Academy';
2196				$return['use_iconv'] = true;
2197				break;
2198
2199			// Georgian-PS
2200			case 'georgian-ps':
2201				$return['encoding'] = 'Georgia

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