Class SimplePie
SimplePie
Direct known subclasses
SimplePie_CoreCopyright: 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
License: BSD License
Author: Ryan Parman
Author: Geoffrey Sneddon
Author: Ryan McCue
Located at SimplePie.php
public
|
#
__construct( )
The SimplePie class contains feed level data and options 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
|
|||||||||||||||||||||
public
|
|||||||||||||||||||||
public
|
#
force_feed( boolean $enable = false )
Force the given data/URL to be treated as a feed This tells SimplePie to ignore the content-type provided by the server. Be careful when using this option, as it will also disable autodiscovery. Parameters
Since
1.1
|
||||||||||||||||||||
public
|
#
set_feed_url( string|array $url )
Set the URL of the feed you want to parse This allows you to enter the URL of the feed you want to parse, or the website you want to try to use auto-discovery on. This takes priority over any set raw data. You can set multiple feeds to mash together by passing an array instead of a string for the $url. Remember that with each additional feed comes additional processing and resources. Parameters
Since
1.0 Preview Release
See |
||||||||||||||||||||
public
boolean
|
#
set_file(
Set an instance of Parameters
Returnsboolean True on success, false on failure |
||||||||||||||||||||
public
|
#
set_raw_data( string $data )
Set the raw XML data to parse Allows you to use a string of RSS/Atom data instead of a remote feed. If you have a feed available as a string in PHP, you can tell SimplePie to parse that data string instead of a remote feed. Any set feed URL takes precedence. Parameters
Since
1.0 Beta 3
See |
||||||||||||||||||||
public
|
#
set_timeout( integer $timeout = 10 )
Set the the default timeout for fetching remote feeds This allows you to change the maximum time the feed's server to respond and send the feed back. Parameters
Since
1.0 Beta 3
|
||||||||||||||||||||
public
|
#
force_fsockopen( boolean $enable = false )
Force SimplePie to use fsockopen() instead of cURL Parameters
Since
1.0 Beta 3
|
||||||||||||||||||||
public
|
#
enable_cache( boolean $enable = true )
Enable/disable caching in SimplePie. This option allows you to disable caching all-together in SimplePie. However, disabling the cache can lead to longer load times. Parameters
Since
1.0 Preview Release
|
||||||||||||||||||||
public
|
#
set_cache_duration( integer $seconds = 3600 )
Set the length of time (in seconds) that the contents of a feed will be cached Parameters
|
||||||||||||||||||||
public
|
#
set_autodiscovery_cache_duration( integer $seconds = 604800 )
Set the length of time (in seconds) that the autodiscovered feed URL will be cached Parameters
|
||||||||||||||||||||
public
|
#
set_cache_location( string $location = './cache' )
Set the file system location where the cached files should be stored Parameters
|
||||||||||||||||||||
public
|
#
enable_order_by_date( boolean $enable = true )
Set whether feed items should be sorted into reverse chronological order Parameters
|
||||||||||||||||||||
public
|
#
set_input_encoding( string $encoding = false )
Set the character encoding used to parse the feed This overrides the encoding reported by the feed, however it will fall back to the normal encoding detection if the override fails Parameters
|
||||||||||||||||||||
public
|
#
set_autodiscovery_level( integer $level = SIMPLEPIE_LOCATOR_ALL )
Set how much feed autodiscovery to do Parameters
See
SIMPLEPIE_LOCATOR_NONE
SIMPLEPIE_LOCATOR_AUTODISCOVERY SIMPLEPIE_LOCATOR_LOCAL_EXTENSION SIMPLEPIE_LOCATOR_LOCAL_BODY SIMPLEPIE_LOCATOR_REMOTE_EXTENSION SIMPLEPIE_LOCATOR_REMOTE_BODY SIMPLEPIE_LOCATOR_ALL |
||||||||||||||||||||
public
|
#
get_registry( )
Get the class registry Use this to override SimplePie's default classes ReturnsSee |
||||||||||||||||||||
public
boolean
|
#
set_cache_class( string $class = 'SimplePie_Cache' )
Set which class SimplePie uses for caching Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_locator_class( string $class = 'SimplePie_Locator' )
Set which class SimplePie uses for auto-discovery Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_parser_class( string $class = 'SimplePie_Parser' )
Set which class SimplePie uses for XML parsing Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_file_class( string $class = 'SimplePie_File' )
Set which class SimplePie uses for remote file fetching Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_sanitize_class( string $class = 'SimplePie_Sanitize' )
Set which class SimplePie uses for data sanitization Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_item_class( string $class = 'SimplePie_Item' )
Set which class SimplePie uses for handling feed items Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_author_class( string $class = 'SimplePie_Author' )
Set which class SimplePie uses for handling author data Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_category_class( string $class = 'SimplePie_Category' )
Set which class SimplePie uses for handling category data Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_enclosure_class( string $class = 'SimplePie_Enclosure' )
Set which class SimplePie uses for feed enclosures Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_caption_class( string $class = 'SimplePie_Caption' )
Set which class SimplePie uses for Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_copyright_class( string $class = 'SimplePie_Copyright' )
Set which class SimplePie uses for Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_credit_class( string $class = 'SimplePie_Credit' )
Set which class SimplePie uses for Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_rating_class( string $class = 'SimplePie_Rating' )
Set which class SimplePie uses for Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_restriction_class( string $class = 'SimplePie_Restriction' )
Set which class SimplePie uses for Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_content_type_sniffer_class( string $class = 'SimplePie_Content_Type_Sniffer' )
Set which class SimplePie uses for content-type sniffing Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
boolean
|
#
set_source_class( string $class = 'SimplePie_Source' )
Set which class SimplePie uses item sources Deprecated
Use
SimplePie::get_registry() insteadParameters
Returnsboolean True on success, false otherwise Link |
||||||||||||||||||||
public
|
#
set_useragent( string $ua = SIMPLEPIE_USERAGENT )
Set the user agent string Parameters
|
||||||||||||||||||||
public
|
#
set_cache_name_function( mixed $function = 'md5' )
Set callback function to create cache filename with Parameters
|
||||||||||||||||||||
public
|
#
set_stupidly_fast( boolean $set = false )
Set options to make SP as fast as possible Forgoes a substantial amount of data sanitization in favor of speed. This turns SimplePie into a dumb parser of feeds. Parameters
|
||||||||||||||||||||
public
|
#
set_max_checked_feeds( integer $max = 10 )
Set maximum number of feeds to check with autodiscovery Parameters
|
||||||||||||||||||||
public
|
|||||||||||||||||||||
public
|
|||||||||||||||||||||
public
|
|||||||||||||||||||||
public
|
|||||||||||||||||||||
public
|
#
set_output_encoding( string $encoding = 'UTF-8' )
Set the output encoding Allows you to override SimplePie's output to match that of your webpage. This
is useful for times when your webpages are not being served as UTF-8. This
setting will be obeyed by It should be noted, however, that not all character encodings can support all characters. If your page is being served as ISO-8859-1 and you try to display a Japanese feed, you'll likely see garbled characters. Because of this, it is highly recommended to ensure that your webpages are served as UTF-8. The number of supported character encodings depends on whether your web host supports mbstring, iconv, or both. See http://simplepie.org/wiki/faq/Supported_Character_Encodings for more information. Parameters
|
||||||||||||||||||||
public
|
|||||||||||||||||||||
public
|
#
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 Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite,
Parameters
Since
1.0
|
||||||||||||||||||||
public
|
#
set_image_handler( str $page = false, str $qs = 'i' )
Set the handler to enable the display of cached images. Parameters
|
||||||||||||||||||||
public
|
#
set_item_limit( integer $limit = 0 )
Set the limit for items returned per-feed with multifeeds Parameters
|
||||||||||||||||||||
public
boolean
|
|||||||||||||||||||||
protected
array|true
|
#
fetch_data(
Fetch the data via SimplePie_File If the data is already cached, attempt to fetch it from there instead Parameters
Returnsarray|true Returns true if the data was loaded from the cache, or an array of HTTP headers and sniffed type |
||||||||||||||||||||
public
string|array
|
|||||||||||||||||||||
public
string|boolean
|
#
get_raw_data( )
Get the raw XML This is the same as the old Returnsstring|boolean Raw XML data, false if the cache is used |
||||||||||||||||||||
public
string
|
|||||||||||||||||||||
public
|
#
handle_content_type( string $mime = 'text/html' )
Send the content-type header with correct encoding This method ensures that the SimplePie-enabled page is being served with the
correct mime-type and character encoding HTTP headers (character encoding determined by
the This won't work properly if any content or whitespace has already been sent to the browser, because it relies on PHP's header() function, and these are the circumstances under which the function works. Because it's setting these settings for the entire page (as is the nature of HTTP headers), this should only be used once per page (again, at the top). Parameters
|
||||||||||||||||||||
public
integer
|
#
get_type( )
Get the type of the feed This returns a SIMPLEPIE_TYPE_* constant, which can be tested against using bitwise operators Returnsinteger SIMPLEPIE_TYPE_* constant Since
0.8 (usage changed to using constants in 1.0)
See
SIMPLEPIE_TYPE_NONE Unknown.
SIMPLEPIE_TYPE_RSS090 RSS 0.90. SIMPLEPIE_TYPE_RSS091_NETSCAPE RSS 0.91 (Netscape). SIMPLEPIE_TYPE_RSS091_USERLAND RSS 0.91 (Userland). SIMPLEPIE_TYPE_RSS091 RSS 0.91. SIMPLEPIE_TYPE_RSS092 RSS 0.92. SIMPLEPIE_TYPE_RSS093 RSS 0.93. SIMPLEPIE_TYPE_RSS094 RSS 0.94. SIMPLEPIE_TYPE_RSS10 RSS 1.0. SIMPLEPIE_TYPE_RSS20 RSS 2.0.x. SIMPLEPIE_TYPE_RSS_RDF RDF-based RSS. SIMPLEPIE_TYPE_RSS_SYNDICATION Non-RDF-based RSS (truly intended as syndication format). SIMPLEPIE_TYPE_RSS_ALL Any version of RSS. SIMPLEPIE_TYPE_ATOM03 Atom 0.3. SIMPLEPIE_TYPE_ATOM10 Atom 1.0. SIMPLEPIE_TYPE_ATOM_ALL Any version of Atom. SIMPLEPIE_TYPE_ALL Any known/supported feed type. |
||||||||||||||||||||
public
string|null
|
#
subscribe_url( )
Get the URL for the feed May or may not be different from the URL passed to Returnsstring|null Since
Preview Release (previously called
get_feed_url() since SimplePie
0.8.) |
||||||||||||||||||||
public
array
|
#
get_feed_tags( string $namespace, string $tag )
Get data for an feed-level element 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 For example: // This is probably a bad example because we already support // <media:content> 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; Parameters
Returnsarray Since
1.0
See |
||||||||||||||||||||
public
array
|
#
get_channel_tags( string $namespace, string $tag )
Get data for an channel-level element This method allows you to get access to ANY element/attribute in the channel/header section of the feed. See Parameters
Returnsarray Since
1.0
See |
||||||||||||||||||||
public
array
|
#
get_image_tags( string $namespace, string $tag )
Get data for an channel-level element This method allows you to get access to ANY element/attribute in the image/logo section of the feed. See Parameters
Returnsarray Since
1.0
See |
||||||||||||||||||||
public
string
|
|||||||||||||||||||||
public
string
|
|||||||||||||||||||||
public
string|null
|
|||||||||||||||||||||
public
|
#
get_category( integer $key = 0 )
Get a category for the feed Parameters
Returns
Since
Unknown
|
||||||||||||||||||||
public
array|null
|
#
get_categories( )
Get all categories for the feed Uses ReturnsSince
Unknown
|
||||||||||||||||||||
public
|
#
get_author( integer $key = 0 )
Get an author for the feed Parameters
Returns
Since
1.1
|
||||||||||||||||||||
public
array|null
|
#
get_authors( )
Get all authors for the feed Uses ReturnsSince
1.1
|
||||||||||||||||||||
public
|
#
get_contributor( integer $key = 0 )
Get a contributor for the feed Parameters
Returns
Since
1.1
|
||||||||||||||||||||
public
array|null
|
|||||||||||||||||||||
public
string|null
|
#
get_link( integer $key = 0, string $rel = 'alternate' )
Get a single link for the feed Parameters
Returnsstring|null Link URL Since
1.0 (previously called
get_feed_link since Preview Release,
get_feed_permalink() since 0.8) |
||||||||||||||||||||
public
string|null
|
#
get_permalink( )
Get the permalink for the item Returns the first link available with a relationship of "alternate".
Identical to Returnsstring|null Link URL Since
1.0 (previously called
get_feed_link since Preview Release,
get_feed_permalink() since 0.8)SeeInternal
Added for parity between the parent-level and the item/entry-level.
|
||||||||||||||||||||
public
array|null
|
|||||||||||||||||||||
public
|
|||||||||||||||||||||
public
string|null
|
#
get_description( )
Get the content for the item Uses Returnsstring|null Since
1.0 (previously called
get_feed_description() since 0.8) |
||||||||||||||||||||
public
string|null
|
#
get_copyright( )
Get the copyright info for the feed Uses Returnsstring|null Since
1.0 (previously called
get_feed_copyright() since 0.8) |
||||||||||||||||||||
public
string|null
|
#
get_language( )
Get the language for the feed Uses Returnsstring|null Since
1.0 (previously called
get_feed_language() since 0.8) |
||||||||||||||||||||
public
string|null
|
#
get_latitude( )
Get the latitude coordinates for the item Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications Uses Returnsstring|null Since
1.0
Link |
||||||||||||||||||||
public
string|null
|
#
get_longitude( )
Get the longitude coordinates for the feed Compatible with the W3C WGS84 Basic Geo and GeoRSS specifications Uses Returnsstring|null Since
1.0
Link |
||||||||||||||||||||
public
string|null
|
#
get_image_title( )
Get the feed logo's title RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" title. Uses Returnsstring|null |
||||||||||||||||||||
public
string|null
|
#
get_image_url( )
Get the feed logo's URL RSS 0.9.0, 2.0, Atom 1.0, and feeds with iTunes RSS tags are allowed to have a "feed logo" URL. This points directly to the image itself. Uses Returnsstring|null |
||||||||||||||||||||
public
string|null
|
#
get_image_link( )
Get the feed logo's link RSS 0.9.0, 1.0 and 2.0 feeds are allowed to have a "feed logo" link. This points to a human-readable page that the image should link to. Uses Returnsstring|null |
||||||||||||||||||||
public
integer|float|null
|
#
get_image_width( )
Get the feed logo's link RSS 2.0 feeds are allowed to have a "feed logo" width. Uses Returnsinteger|float|null |
||||||||||||||||||||
public
integer|float|null
|
#
get_image_height( )
Get the feed logo's height RSS 2.0 feeds are allowed to have a "feed logo" height. Uses Returnsinteger|float|null |
||||||||||||||||||||
public
integer
|
#
get_item_quantity( integer $max = 0 )
Get the number of items in the feed This is well-suited for for() loops with Parameters
Returnsinteger Number of items in the feed |
||||||||||||||||||||
public
|
#
get_item( integer $key = 0 )
Get a single item from the feed This is better suited for for() loops, whereas Parameters
Returns
Since
Beta 2
See |
||||||||||||||||||||
public
array|null
|
#
get_items( integer $start = 0, integer $end = 0 )
Get all items from the feed This is better suited for for() loops, whereas Parameters
ReturnsSince
Beta 2
See |
||||||||||||||||||||
public static
boolean
|
|||||||||||||||||||||
public static
array
|
#
merge_items( array $urls, integer $start = 0, integer $end = 0, integer $limit = 0 )
Merge items from several feeds into one If you're merging multiple feeds together, they need to all have dates for the items or else SimplePie will refuse to sort them. Parameters
Returnsarray Link |
public
array
|
$data | array() |
#
Raw data |
public
mixed
|
$error |
|
#
Error string |
public
object
|
$sanitize |
|
|
public
string
|
$useragent | SIMPLEPIE_USERAGENT |
|
public
string
|
$feed_url |
|
|
public
object
|
$file |
|
|
public
string
|
$raw_data |
|
|
public
integer
|
$timeout | 10 |
|
public
boolean
|
$force_fsockopen | false |
#
Forces fsockopen() to be used for remote files instead of cURL, even if a new enough version is installed See |
public
boolean
|
$force_feed | false |
#
Force the given data/URL to be treated as a feed no matter what it appears like See |
public
boolean
|
$cache | true |
|
public
integer
|
$cache_duration | 3600 |
|
public
integer
|
$autodiscovery_cache_duration | 604800 |
|
public
string
|
$cache_location | './cache' |
|
public
string
|
$cache_name_function | 'md5' |
|
public
boolean
|
$order_by_date | true |
|
public
mixed
|
$input_encoding | false |
#
Force input encoding to be set to the follow value (false, or anything type-cast to false, disables this feature) See |
public
integer
|
$autodiscovery | SIMPLEPIE_LOCATOR_ALL |
|
public
|
$registry |
|
#
Class registry object |
public
integer
|
$max_checked_feeds | 10 |
|
public
array
|
$all_discovered_feeds | array() |
|
public
string
|
$image_handler | '' |
|
public
array
|
$multifeed_url | array() |
|
public
array
|
$multifeed_objects | array() |
#
Stores SimplePie objects when multiple feeds initialized. |
public
array
|
$config_settings | null |
|
public
integer
|
$item_limit | 0 |
|
public
array
|
$strip_attributes | array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc') |
#
Stores the default attributes to be stripped by strip_attributes(). See |
public
array
|
$strip_htmltags | array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style') |