PHP Class SimplePie, simplepie

Version: "Lemon Meringue" Updated: 3 November 2006 Copyright: 2004-2006 Ryan Parman, Geoffrey Sneddon http://simplepie.org LICENSE: GNU Lesser General Public License 2.1 (LGPL) Please submit all bug reports and feature requests to the SimplePie forums. http://simplepie.org/support/
显示文件 Open project: simplepie/simplepie Class Usage Examples

Public Properties

Property Type Description
$add_attributes Stores the default attributes to add to different tags by add_attributes().
$all_discovered_feeds All the feeds found during the autodiscovery process
$autodiscovery Feed Autodiscovery Level
$autodiscovery_cache_duration Auto-discovery cache duration (in seconds)
$cache Enable/Disable Caching
$cache_duration Cache duration (in seconds)
$cache_location Cache location (relative to executing script)
$cache_name_function Function that creates the cache filename
$check_modified Stores if last-modified and/or etag headers were sent with the request when checking a feed.
$config_settings Stores the get_object_vars() array for use with multifeeds.
$curl_options Custom curl options
$data Raw data
$error Error string
$feed_url Feed URL
$file Instance of SimplePie_File to use as a feed
$force_cache_fallback Force SimplePie to fallback to expired cache, if enabled, when feed is unavailable.
$force_feed Force the given data/URL to be treated as a feed no matter what it appears like
$force_fsockopen Forces fsockopen() to be used for remote files instead of cURL, even if a new enough version is installed
$image_handler Web-accessible path to the handler_image.php file.
$input_encoding Force input encoding to be set to the follow value (false, or anything type-cast to false, disables this feature)
$item_limit Stores the number of items to return per-feed with multifeeds.
$max_checked_feeds Maximum number of feeds to check with autodiscovery
$multifeed_objects Stores SimplePie objects when multiple feeds initialized.
$multifeed_url Stores the URLs when multiple feeds are being initialized.
$order_by_date Reorder feed by date descending
$permanent_url Original feed URL, or new feed URL iff HTTP 301 Moved Permanently
$raw_data Raw feed data
$registry SimplePie_Registry Class registry object
$sanitize Instance of SimplePie_Sanitize (or other class)
$strip_attributes Stores the default attributes to be stripped by strip_attributes().
$strip_htmltags Stores the default tags to be stripped by strip_htmltags().
$timeout Timeout for fetching remote files
$useragent SimplePie Useragent

Public Methods

Method Description
__call ( string $method, array $args ) : mixed Magic method handler
__construct ( ) The SimplePie class contains feed level data and options
__destruct ( ) Remove items that link back to this before destroying this object
__toString ( ) Used for converting object to a string
add_attributes ( $attribs = '' )
enable_cache ( boolean $enable = true ) Enable/disable caching in SimplePie.
enable_exceptions ( boolean $enable = true ) Enable throwing exceptions
enable_order_by_date ( boolean $enable = true ) Set whether feed items should be sorted into reverse chronological order
encode_instead_of_strip ( $enable = true )
error ( ) : string | array Get the error message for the occured error
force_cache_fallback ( boolean $enable = false ) SimplePie to continue to fall back to expired cache, if enabled, when feed is unavailable.
force_feed ( boolean $enable = false ) Force the given data/URL to be treated as a feed
force_fsockopen ( boolean $enable = false ) Force SimplePie to use fsockopen() instead of cURL
get_all_discovered_feeds ( )
get_author ( integer $key ) : SimplePie_Author | null Get an author for the feed
get_authors ( ) : array | null Get all authors for the feed
get_base ( array $element = [] ) : string Get the base URL value from the feed
get_categories ( ) : array | null Get all categories for the feed
get_category ( integer $key ) : SimplePie_Category | null Get a category for the feed
get_channel_tags ( string $namespace, string $tag ) : array Get data for an channel-level element
get_contributor ( integer $key ) : SimplePie_Author | null Get a contributor for the feed
get_contributors ( ) : array | null Get all contributors for the feed
get_copyright ( ) : string | null Get the copyright info for the feed
get_description ( ) : string | null Get the content for the item
get_encoding ( ) : string Get the character encoding used for output
get_favicon ( ) Get the favicon for the current feed
get_feed_tags ( string $namespace, string $tag ) : array Get data for an feed-level element
get_image_height ( ) : integer | float | null Get the feed logo's height
get_image_link ( ) : string | null Get the feed logo's link
get_image_tags ( string $namespace, string $tag ) : array Get data for an channel-level element
get_image_title ( ) : string | null Get the feed logo's title
get_image_url ( ) : string | null Get the feed logo's URL
get_image_width ( ) : integer | float | null Get the feed logo's link
get_item ( integer $key ) : SimplePie_Item | null Get a single item from the feed
get_item_quantity ( integer $max ) : integer Get the number of items in the feed
get_items ( integer $start, integer $end ) : SimplePie_Item[] | null Get all items from the feed
get_language ( ) : string | null Get the language for the feed
get_latitude ( ) : string | null Get the latitude coordinates for the item
get_link ( integer $key, string $rel = 'alternate' ) : string | null Get a single link for the feed
get_links ( string $rel = 'alternate' ) : array | null Get all links for the feed
get_longitude ( ) : string | null Get the longitude coordinates for the feed
get_permalink ( ) : string | null Get the permalink for the item
get_raw_data ( ) : string | boolean Get the raw XML
get_registry ( ) : SimplePie_Registry Get the class registry
get_title ( ) : string | null Get the title of the feed
get_type ( ) : integer Get the type of the feed
handle_content_type ( string $mime = 'text/html' ) Send the content-type header with correct encoding
init ( ) : boolean Initialize the feed object
merge_items ( array $urls, integer $start, integer $end, integer $limit ) : array Merge items from several feeds into one
remove_div ( $enable = true )
sanitize ( string $data, integer $type, string $base = '' ) : string Sanitize feed data
set_author_class ( $class = 'SimplePie_Author' ) Set which class SimplePie uses for handling author data
set_autodiscovery_cache_duration ( integer $seconds = 604800 ) Set the length of time (in seconds) that the autodiscovered feed URL will be cached
set_autodiscovery_level ( integer $level = SIMPLEPIE_LOCATOR_ALL ) Set how much feed autodiscovery to do
set_cache_class ( $class = 'SimplePie_Cache' ) Set which class SimplePie uses for caching
set_cache_duration ( integer $seconds = 3600 ) Set the length of time (in seconds) that the contents of a feed will be cached
set_cache_location ( string $location = './cache' ) Set the file system location where the cached files should be stored
set_cache_name_function ( mixed $function = 'md5' ) Set callback function to create cache filename with
set_caption_class ( $class = 'SimplePie_Caption' ) Set which class SimplePie uses for captions
set_category_class ( $class = 'SimplePie_Category' ) Set which class SimplePie uses for handling category data
set_content_type_sniffer_class ( $class = 'SimplePie_Content_Type_Sniffer' ) Set which class SimplePie uses for content-type sniffing
set_copyright_class ( $class = 'SimplePie_Copyright' ) Set which class SimplePie uses for
set_credit_class ( $class = 'SimplePie_Credit' ) Set which class SimplePie uses for
set_curl_options ( array $curl_options = [] ) Set custom curl options
set_enclosure_class ( $class = 'SimplePie_Enclosure' ) Set which class SimplePie uses for feed enclosures
set_favicon_handler ( $page = false, $qs = 'i' ) Set the favicon handler
set_feed_url ( string | array $url ) Set the URL of the feed you want to parse
set_file ( &$file ) : boolean Set an instance of {@see SimplePie_File} to use as a feed
set_file_class ( $class = 'SimplePie_File' ) Set which class SimplePie uses for remote file fetching
set_image_handler ( str $page = false, str $qs = 'i' ) Set the handler to enable the display of cached images.
set_input_encoding ( string $encoding = false ) Set the character encoding used to parse the feed
set_item_class ( $class = 'SimplePie_Item' ) Set which class SimplePie uses for handling feed items
set_item_limit ( integer $limit ) Set the limit for items returned per-feed with multifeeds
set_locator_class ( $class = 'SimplePie_Locator' ) Set which class SimplePie uses for auto-discovery
set_max_checked_feeds ( integer $max = 10 ) Set maximum number of feeds to check with autodiscovery
set_output_encoding ( string $encoding = 'UTF-8' ) Set the output encoding
set_parser_class ( $class = 'SimplePie_Parser' ) Set which class SimplePie uses for XML parsing
set_rating_class ( $class = 'SimplePie_Rating' ) Set which class SimplePie uses for
set_raw_data ( string $data ) Set the raw XML data to parse
set_restriction_class ( $class = 'SimplePie_Restriction' ) Set which class SimplePie uses for
set_sanitize_class ( $class = 'SimplePie_Sanitize' ) Set which class SimplePie uses for data sanitization
set_source_class ( $class = 'SimplePie_Source' ) Set which class SimplePie uses item sources
set_stupidly_fast ( boolean $set = false ) Set options to make SP as fast as possible
set_timeout ( integer $timeout = 10 ) Set the the default timeout for fetching remote feeds
set_url_replacements ( array | null $element_attribute = null ) Set element/attribute key/value pairs of HTML attributes containing URLs that need to be resolved relative to the feed
set_useragent ( string $ua = SIMPLEPIE_USERAGENT ) Set the user agent string
sort_items ( SimplePie $a, SimplePie $b ) : boolean Sorting callback for items
strip_attributes ( $attribs = '' )
strip_comments ( $strip = false )
strip_htmltags ( $tags = '', $encode = null )
subscribe_url ( boolean $permanent = false ) : string | null Get the URL for the feed

Protected Methods

Method Description
fetch_data ( SimplePie_Cache | false &$cache ) : array | true Fetch the data via SimplePie_File

Private Methods

Method Description
store_links ( SimplePie_File &$file, string $hub, string $self ) Store PubSubHubbub links as headers

Method Details

__call() public method

Magic method handler
public __call ( string $method, array $args ) : mixed
$method string Method name
$args array Arguments to the method
return mixed

__construct() public method

To use SimplePie, create the SimplePie object with no parameters. You can then set configuration options using the provided methods. After setting them, you must initialise the feed using $feed->init(). At that point the object's methods and properties will be available to you. Previously, it was possible to pass in the feed URL along with cache options directly into the constructor. This has been removed as of 1.3 as it caused a lot of confusion.
Since: 1.0 Preview Release
public __construct ( )

__destruct() public method

Remove items that link back to this before destroying this object
public __destruct ( )

__toString() public method

Used for converting object to a string
public __toString ( )

add_attributes() public method

public add_attributes ( $attribs = '' )

enable_cache() public method

This option allows you to disable caching all-together in SimplePie. However, disabling the cache can lead to longer load times.
Since: 1.0 Preview Release
public enable_cache ( boolean $enable = true )
$enable boolean Enable caching

enable_exceptions() public method

Enable throwing exceptions
public enable_exceptions ( boolean $enable = true )
$enable boolean Should we throw exceptions, or use the old-style error property?

enable_order_by_date() public method

Set whether feed items should be sorted into reverse chronological order
public enable_order_by_date ( boolean $enable = true )
$enable boolean Sort as reverse chronological order.

encode_instead_of_strip() public method

public encode_instead_of_strip ( $enable = true )

error() public method

Get the error message for the occured error
public error ( ) : string | array
return string | array Error message, or array of messages for multifeeds

fetch_data() protected method

If the data is already cached, attempt to fetch it from there instead
protected fetch_data ( SimplePie_Cache | false &$cache ) : array | true
$cache SimplePie_Cache | false Cache handler, or false to not load from the cache
return array | true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type

force_cache_fallback() public method

This tells SimplePie to ignore any file errors and fall back to cache instead. This only works if caching is enabled and cached content still exists.
public force_cache_fallback ( boolean $enable = false )
$enable boolean Force use of cache on fail.

force_feed() public method

This tells SimplePie to ignore the content-type provided by the server. Be careful when using this option, as it will also disable autodiscovery.
Since: 1.1
public force_feed ( boolean $enable = false )
$enable boolean Force the given data/URL to be treated as a feed

force_fsockopen() public method

Force SimplePie to use fsockopen() instead of cURL
Since: 1.0 Beta 3
public force_fsockopen ( boolean $enable = false )
$enable boolean Force fsockopen() to be used

get_all_discovered_feeds() public method

get_author() public method

Get an author for the feed
Since: 1.1
public get_author ( integer $key ) : SimplePie_Author | null
$key integer The author that you want to return. Remember that arrays begin with 0, not 1
return SimplePie_Author | null

get_authors() public method

Uses , , or
Since: 1.1
public get_authors ( ) : array | null
return array | null List of {@see \SimplePie_Author} objects

get_base() public method

Uses if available, otherwise uses the first link in the feed, or failing that, the URL of the feed itself.
See also: get_link
See also: subscribe_url
public get_base ( array $element = [] ) : string
$element array
return string

get_categories() public method

Uses , or
public get_categories ( ) : array | null
return array | null List of {@see \SimplePie_Category} objects

get_category() public method

Get a category for the feed
public get_category ( integer $key ) : SimplePie_Category | null
$key integer The category that you want to return. Remember that arrays begin with 0, not 1
return SimplePie_Category | null

get_channel_tags() public method

This method allows you to get access to ANY element/attribute in the channel/header section of the feed. See {@see \SimplePie::get_feed_tags()} for a description of the return value
See also: http://simplepie.org/wiki/faq/supported_xml_namespaces
Since: 1.0
public get_channel_tags ( string $namespace, string $tag ) : array
$namespace string The URL of the XML namespace of the elements you're trying to access
$tag string Tag name
return array

get_contributor() public method

Get a contributor for the feed
Since: 1.1
public get_contributor ( integer $key ) : SimplePie_Author | null
$key integer The contrbutor that you want to return. Remember that arrays begin with 0, not 1
return SimplePie_Author | null

get_contributors() public method

Uses
Since: 1.1
public get_contributors ( ) : array | null
return array | null List of {@see \SimplePie_Author} objects

get_description() public method

Uses , , , , or
Since: 1.0 (previously called `get_feed_description()` since 0.8)
public get_description ( ) : string | null
return string | null

get_encoding() public method

Get the character encoding used for output
public get_encoding ( ) : string
return string

get_favicon() public method

Get the favicon for the current feed
Deprecation: Use your own favicon handling instead
public get_favicon ( )

get_feed_tags() public method

This method allows you to get access to ANY element/attribute that is a sub-element of the opening feed tag. The return value is an indexed array of elements matching the given namespace and tag name. Each element has attribs, data and child subkeys. For attribs and child, these contain namespace subkeys. attribs then has one level of associative name => value data (where value is a string) after the namespace. child has tag-indexed keys after the namespace, each member of which is an indexed array matching this same format. For example:
This is probably a bad example because we already support
 natively, but it shows you how to parse through
the nodes.
$group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group');
$content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'];
$file = $content[0]['attribs']['']['url'];
echo $file;
See also: http://simplepie.org/wiki/faq/supported_xml_namespaces
Since: 1.0
public get_feed_tags ( string $namespace, string $tag ) : array
$namespace string The URL of the XML namespace of the elements you're trying to access
$tag string Tag name
return array

get_image_height() public method

RSS 2.0 feeds are allowed to have a "feed logo" height. Uses or defaults to 31.0 if no height is specified and the feed is an RSS 2.0 feed.
public get_image_height ( ) : integer | float | null
return integer | float | null