WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

SimplePie::init() WP 1.0

Initialize the feed object

This is what makes everything happen. Period. This is where all of the configuration options get processed, feeds are fetched, cached, and parsed, and all of that other good stuff.

Это метод класса: SimplePie

Хуков нет.

Возвращает

true/false. True if successful, false otherwise

Использование

$SimplePie = new SimplePie();
$var = $SimplePie->init();

Код SimplePie::init: wp-includes/class-simplepie.php WP 5.2.2

<?php
public function init()
{
	// Check absolute bare minimum requirements.
	if (!extension_loaded('xml') || !extension_loaded('pcre'))
	{
		return false;
	}
	// Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.
	elseif (!extension_loaded('xmlreader'))
	{
		static $xml_is_sane = null;
		if ($xml_is_sane === null)
		{
			$parser_check = xml_parser_create();
			xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
			xml_parser_free($parser_check);
			$xml_is_sane = isset($values[0]['value']);
		}
		if (!$xml_is_sane)
		{
			return false;
		}
	}

	if (method_exists($this->sanitize, 'set_registry'))
	{
		$this->sanitize->set_registry($this->registry);
	}

	// Pass whatever was set with config options over to the sanitizer.
	// Pass the classes in for legacy support; new classes should use the registry instead
	$this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
	$this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);

	if (!empty($this->multifeed_url))
	{
		$i = 0;
		$success = 0;
		$this->multifeed_objects = array();
		$this->error = array();
		foreach ($this->multifeed_url as $url)
		{
			$this->multifeed_objects[$i] = clone $this;
			$this->multifeed_objects[$i]->set_feed_url($url);
			$single_success = $this->multifeed_objects[$i]->init();
			$success |= $single_success;
			if (!$single_success)
			{
				$this->error[$i] = $this->multifeed_objects[$i]->error();
			}
			$i++;
		}
		return (bool) $success;
	}
	elseif ($this->feed_url === null && $this->raw_data === null)
	{
		return false;
	}

	$this->error = null;
	$this->data = array();
	$this->multifeed_objects = array();
	$cache = false;

	if ($this->feed_url !== null)
	{
		$parsed_feed_url = $this->registry->call('Misc', 'parse_url', array($this->feed_url));

		// Decide whether to enable caching
		if ($this->cache && $parsed_feed_url['scheme'] !== '')
		{
			$cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
		}

		// Fetch the data via SimplePie_File into $this->raw_data
		if (($fetched = $this->fetch_data($cache)) === true)
		{
			return true;
		}
		elseif ($fetched === false) {
			return false;
		}

		list($headers, $sniffed) = $fetched;
	}

	// Set up array of possible encodings
	$encodings = array();

	// First check to see if input has been overridden.
	if ($this->input_encoding !== false)
	{
		$encodings[] = $this->input_encoding;
	}

	$application_types = array('application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity');
	$text_types = array('text/xml', 'text/xml-external-parsed-entity');

	// RFC 3023 (only applies to sniffed content)
	if (isset($sniffed))
	{
		if (in_array($sniffed, $application_types) || substr($sniffed, 0, 12) === 'application/' && substr($sniffed, -4) === '+xml')
		{
			if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
			{
				$encodings[] = strtoupper($charset[1]);
			}
			$encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
			$encodings[] = 'UTF-8';
		}
		elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml')
		{
			if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
			{
				$encodings[] = $charset[1];
			}
			$encodings[] = 'US-ASCII';
		}
		// Text MIME-type default
		elseif (substr($sniffed, 0, 5) === 'text/')
		{
			$encodings[] = 'US-ASCII';
		}
	}

	// Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1
	$encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', array($this->raw_data, &$this->registry)));
	$encodings[] = 'UTF-8';
	$encodings[] = 'ISO-8859-1';

	// There's no point in trying an encoding twice
	$encodings = array_unique($encodings);

	// Loop through each possible encoding, till we return something, or run out of possibilities
	foreach ($encodings as $encoding)
	{
		// Change the encoding to UTF-8 (as we always use UTF-8 internally)
		if ($utf8_data = $this->registry->call('Misc', 'change_encoding', array($this->raw_data, $encoding, 'UTF-8')))
		{
			// Create new parser
			$parser = $this->registry->create('Parser');

			// If it's parsed fine
			if ($parser->parse($utf8_data, 'UTF-8'))
			{
				$this->data = $parser->get_data();
				if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
				{
					$this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
					$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
					return false;
				}

				if (isset($headers))
				{
					$this->data['headers'] = $headers;
				}
				$this->data['build'] = SIMPLEPIE_BUILD;

				// Cache the file if caching is enabled
				if ($cache && !$cache->save($this))
				{
					trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
				}
				return true;
			}
		}
	}

	if (isset($parser))
	{
		// We have an error, just set SimplePie_Misc::error to it and quit
		$this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
	}
	else
	{
		$this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
	}

	$this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));

	return false;
}