⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplepie.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 5 页
字号:
							$this->data = array();						}						// If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL.						elseif (isset($this->data['feed_url']))						{							// If the autodiscovery cache is still valid use it.							if ($cache->mtime() + $this->autodiscovery_cache_duration > time())							{								// Do not need to do feed autodiscovery yet.								if ($this->data['feed_url'] == $this->data['url'])								{									$cache->unlink();									$this->data = array();								}								else								{									$this->set_feed_url($this->data['feed_url']);									return $this->init();								}							}						}						// Check if the cache has been updated						elseif ($cache->mtime() + $this->cache_duration < time())						{							// If we have last-modified and/or etag set							if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))							{								$headers = array();								if (isset($this->data['headers']['last-modified']))								{									$headers['if-modified-since'] = $this->data['headers']['last-modified'];								}								if (isset($this->data['headers']['etag']))								{									$headers['if-none-match'] = $this->data['headers']['etag'];								}								$file =& new $this->file_class($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen);								if ($file->success)								{									if ($file->status_code == 304)									{										$cache->touch();										return true;									}									else									{										$headers = $file->headers;									}								}								else								{									unset($file);								}							}						}						// If the cache is still valid, just return true						else						{							return true;						}					}					// If the cache is empty, delete it					else					{						$cache->unlink();						$this->data = array();					}				}				// If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it.				if (!isset($file))				{					if (SimplePie_Misc::is_a($this->file, 'SimplePie_File') && $this->file->url == $this->feed_url)					{						$file =& $this->file;					}					else					{						$file =& new $this->file_class($this->feed_url, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen);					}				}				// If the file connection has an error, set SimplePie::error to that and quit				if (!$file->success)				{					$this->error = $file->error;					if (!empty($this->data))					{						return true;					}					else					{						return false;					}				}				// Check if the supplied URL is a feed, if it isn't, look for it.				$locate =& new $this->locator_class($file, $this->timeout, $this->useragent, $this->file_class, $this->max_checked_feeds);				if (!$locate->is_feed($file))				{					// We need to unset this so that if SimplePie::set_file() has been called that object is untouched					unset($file);					if ($file = $locate->find($this->autodiscovery))					{						if ($cache)						{							if (!$cache->save(array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD)))							{								trigger_error("$cache->name is not writeable", E_USER_WARNING);							}							$cache =& new $this->cache_class($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');						}						$this->feed_url = $file->url;					}					else					{						$this->error = "A feed could not be found at $this->feed_url";						SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);						return false;					}				}				$locate = null;				$headers = $file->headers;				$data = trim($file->body);				unset($file);			}			else			{				$data = $this->raw_data;			}			// First check to see if input has been overridden.			if ($this->input_encoding !== false)			{				$encoding = $this->input_encoding;			}			// Second try HTTP headers			elseif (isset($headers['content-type']) && preg_match('/;[\x09\x20]*charset=([^;]*)/i', $headers['content-type'], $charset))			{				$encoding = $charset[1];			}			// Then prolog, if at the very start of the document			elseif (preg_match("/^<\?xml[\x20\x9\xD\xA]+version([\x20\x9\xD\xA]+)?=([\x20\x9\xD\xA]+)?(\"1.0\"|'1.0'|\"1.1\"|'1.1')[\x20\x9\xD\xA]+encoding([\x20\x9\xD\xA]+)?=([\x20\x9\xD\xA]+)?(\"[A-Za-z][A-Za-z0-9._\-]*\"|'[A-Za-z][A-Za-z0-9._\-]*')([\x20\x9\xD\xA]+standalone([\x20\x9\xD\xA]+)?=([\x20\x9\xD\xA]+)?(\"(yes|no)\"|'(yes|no)'))?([\x20\x9\xD\xA]+)?\?>/", $data, $prolog))			{				$encoding = substr($prolog[6], 1, -1);			}			// UTF-32 Big Endian BOM			elseif (strpos($data, "\x0\x0\xFE\xFF") === 0)			{				$encoding = 'UTF-32be';			}			// UTF-32 Little Endian BOM			elseif (strpos($data, "\xFF\xFE\x0\x0") === 0)			{				$encoding = 'UTF-32';			}			// UTF-16 Big Endian BOM			elseif (strpos($data, "\xFE\xFF") === 0)			{				$encoding = 'UTF-16be';			}			// UTF-16 Little Endian BOM			elseif (strpos($data, "\xFF\xFE") === 0)			{				$encoding = 'UTF-16le';			}			// UTF-8 BOM			elseif (strpos($data, "\xEF\xBB\xBF") === 0)			{				$encoding = 'UTF-8';			}			// Fallback to the default (US-ASCII for text/xml, ISO-8859-1 for text/* MIME types, UTF-8 otherwise)			elseif (isset($headers['content-type']) && strtolower(SimplePie_Misc::parse_mime($headers['content-type'])) == 'text/xml')			{				$encoding = 'US-ASCII';			}			elseif (isset($headers['content-type']) && SimplePie_Misc::stripos(SimplePie_Misc::parse_mime($headers['content-type']), 'text/') === 0)			{				$encoding = 'ISO-8859-1';			}			else			{				$encoding = 'UTF-8';			}			// Change the encoding to UTF-8 (as we always use UTF-8 internally)			if ($encoding != 'UTF-8')			{				$data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8');			}			// Strip illegal characters			//$data = SimplePie_Misc::utf8_bad_replace($data);			$parser =& new $this->parser_class();			$parser->pre_process($data, 'UTF-8');			// If we want the XML, just output that and quit			if ($this->xml_dump)			{				header('Content-type: text/xml; charset=UTF-8');				echo $data;				exit;			}			// If it's parsed fine			elseif ($parser->parse($data))			{				unset($data);				$this->data = $parser->get_data();				if (isset($this->data['child']))				{					if (isset($headers))					{						$this->data['headers'] = $headers;					}					$this->data['build'] = SIMPLEPIE_BUILD;					// Cache the file if caching is enabled					if ($cache && !$cache->save($this->data))					{						trigger_error("$cache->name is not writeable", E_USER_WARNING);					}					return true;				}				else				{					$this->error = "A feed could not be found at $this->feed_url";					SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);					return false;				}			}			// If we have an error, just set SimplePie::error to it and quit			else			{				$this->error = sprintf('XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());				SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);				return false;			}		}		elseif (!empty($this->multifeed_url))		{			$i = 0;			$success = 0;			$this->multifeed_objects = array();			foreach ($this->multifeed_url as $url)			{				if (SIMPLEPIE_PHP5)				{					// This keyword needs to defy coding standards for PHP4 compatibility					$this->multifeed_objects[$i] = clone($this);				}				else				{					$this->multifeed_objects[$i] = $this;				}				$this->multifeed_objects[$i]->set_feed_url($url);				$success |= $this->multifeed_objects[$i]->init();				$i++;			}			return (bool) $success;		}		else		{			return false;		}	}	/**	 * Return the error message for the occured error	 *	 * @access public	 * @return string Error message	 */	function error()	{		return $this->error;	}	function get_encoding()	{		return $this->sanitize->output_encoding;	}	function handle_content_type($mime = 'text/html')	{		if (!headers_sent())		{			$header = "Content-type: $mime;";			if ($this->get_encoding())			{				$header .= ' charset=' . $this->get_encoding();			}			else			{				$header .= ' charset=UTF-8';			}			header($header);		}	}	function get_type()	{		if (!isset($this->data['type']))		{			$this->data['type'] = SIMPLEPIE_TYPE_ALL;			if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed']))			{				$this->data['type'] &= SIMPLEPIE_TYPE_ATOM_10;			}			elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed']))			{				$this->data['type'] &= SIMPLEPIE_TYPE_ATOM_03;			}			elseif (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF']))			{				if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['channel'])				|| isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['image'])				|| isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['item'])				|| isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_10]['textinput']))				{					$this->data['type'] &= SIMPLEPIE_TYPE_RSS_10;				}				if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['channel'])				|| isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['image'])				|| isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['item'])				|| isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][SIMPLEPIE_NAMESPACE_RSS_090]['textinput']))				{					$this->data['type'] &= SIMPLEPIE_TYPE_RSS_090;				}			}			elseif (isset($this->data['child']['']['rss']))			{				$this->data['type'] &= SIMPLEPIE_TYPE_RSS_ALL;				if (isset($this->data['child']['']['rss'][0]['attribs']['']['version']))				{					switch (trim($this->data['child']['']['rss'][0]['attribs']['']['version']))					{						case '0.91':							$this->data['type'] &= SIMPLEPIE_TYPE_RSS_091;							if (isset($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data']))							{								switch (trim($this->data['child']['']['rss'][0]['child']['']['skiphours']['hour'][0]['data']))								{									case '0':										$this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_NETSCAPE;										break;									case '24':										$this->data['type'] &= SIMPLEPIE_TYPE_RSS_091_USERLAND;										break;								}							}							break;						case '0.92':							$this->data['type'] &= SIMPLEPIE_TYPE_RSS_092;							break;						case '0.93':							$this->data['type'] &= SIMPLEPIE_TYPE_RSS_093;							break;						case '0.94':							$this->data['type'] &= SIMPLEPIE_TYPE_RSS_094;							break;						case '2.0':							$this->data['type'] &= SIMPLEPIE_TYPE_RSS_20;							break;					}				}			}			else			{				$this->data['type'] = SIMPLEPIE_TYPE_NONE;			}		}		return $this->data['type'];	}	/**	 * Returns the URL for the favicon of the feed's website.	 *	 * @access public	 * @since 1.0	 */	function get_favicon()	{		if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'icon'))		{			return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));		}		elseif (($url = $this->get_link()) !== null && preg_match('/^http(s)?:\/\//i', $url))		{			$favicon = SimplePie_Misc::absolutize_url('/favicon.ico', $url);			if ($this->cache && $this->favicon_handler)			{				$cache =& new $this->cache_class($this->cache_location, call_user_func($this->cache_name_function, $favicon), 'spi');				if ($cache->load())				{					return $this->sanitize($this->favicon_handler . rawurlencode($favicon), SIMPLEPIE_CONSTRUCT_IRI);				}				else				{					$file =& new $this->file_class($favicon, $this->timeout / 10, 5, array('X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']), $this->useragent, $this->force_fsockopen);					if ($file->success && ($file->status_code == 200 || ($file->status_code > 206 && $file->status_code < 300)) && strlen($file->body) > 0)					{						if ($cache->save(array('headers' => $file->headers, 'body' => $file->body)))						{							return $this->sanitize($this->favicon_handler . rawurlencode($favicon), SIMPLEPIE_CONSTRUCT_IRI);						}						else						{							trigger_error("$cache->name is not writeable", E_USER_WARNING);							return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);						}					}				}			}			else			{				return $this->sanitize($favicon, SIMPLEPIE_CONSTRUCT_IRI);			}		}		return false;	}	/**	 * @todo If we have a perm redirect we should return the new URL	 * @todo When we make the above change, let's support <itunes:new-feed-url> as well	 * @todo Also, |atom:link|@rel=self	 */	function subscribe_url()	{		if ($this->feed_url !== null)		{			return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);		}		else		{			return null;		}	}	function subscribe_feed()	{		if ($this->feed_url !== null)		{			return $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);		}		else		{			return null;		}	}	function subscribe_outlook()	{		if ($this->feed_url !== null)		{			return 'outlook' . $this->sanitize(SimplePie_Misc::fix_protocol($this->feed_url, 2), SIMPLEPIE_CONSTRUCT_IRI);		}		else		{			return null;		}	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -