: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$this->data['type'] = SIMPLEPIE_TYPE_NONE;
return $this->data['type'];
* Get the URL for the feed
* When the 'permanent' mode is enabled, returns the original feed URL,
* except in the case of an `HTTP 301 Moved Permanently` status response,
* in which case the location of the first redirection is returned.
* When the 'permanent' mode is disabled (default),
* may or may not be different from the URL passed to {@see set_feed_url()},
* depending on whether auto-discovery was used, and whether there were
* any redirects along the way.
* @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
* @todo Support <itunes:new-feed-url>
* @todo Also, |atom:link|@rel=self
* @param bool $permanent Permanent mode to return only the original URL or the first redirection
* iff it is a 301 redirection
public function subscribe_url($permanent = false)
if ($this->permanent_url !== null)
// sanitize encodes ampersands which are required when used in a url.
return str_replace('&', '&',
$this->sanitize($this->permanent_url,
SIMPLEPIE_CONSTRUCT_IRI));
if ($this->feed_url !== null)
return str_replace('&', '&',
$this->sanitize($this->feed_url,
SIMPLEPIE_CONSTRUCT_IRI));
* 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 `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 is probably a bad example because we already support
* // <media:content> natively, but it shows you how to parse through
* $group = $item->get_item_tags(SIMPLEPIE_NAMESPACE_MEDIARSS, 'group');
* $content = $group[0]['child'][SIMPLEPIE_NAMESPACE_MEDIARSS]['content'];
* $file = $content[0]['attribs']['']['url'];
* @see http://simplepie.org/wiki/faq/supported_xml_namespaces
* @param string $namespace The URL of the XML namespace of the elements you're trying to access
* @param string $tag Tag name
public function get_feed_tags($namespace, $tag)
$type = $this->get_type();
if ($type & SIMPLEPIE_TYPE_ATOM_10)
if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag]))
return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['feed'][0]['child'][$namespace][$tag];
if ($type & SIMPLEPIE_TYPE_ATOM_03)
if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag]))
return $this->data['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['feed'][0]['child'][$namespace][$tag];
if ($type & SIMPLEPIE_TYPE_RSS_RDF)
if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag]))
return $this->data['child'][SIMPLEPIE_NAMESPACE_RDF]['RDF'][0]['child'][$namespace][$tag];
if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
if (isset($this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$tag]))
return $this->data['child'][SIMPLEPIE_NAMESPACE_RSS_20]['rss'][0]['child'][$namespace][$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 {@see SimplePie::get_feed_tags()} for a description of the return value
* @see http://simplepie.org/wiki/faq/supported_xml_namespaces
* @param string $namespace The URL of the XML namespace of the elements you're trying to access
* @param string $tag Tag name
public function get_channel_tags($namespace, $tag)
$type = $this->get_type();
if ($type & SIMPLEPIE_TYPE_ATOM_ALL)
if ($return = $this->get_feed_tags($namespace, $tag))
if ($type & SIMPLEPIE_TYPE_RSS_10)
if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'channel'))
if (isset($channel[0]['child'][$namespace][$tag]))
return $channel[0]['child'][$namespace][$tag];
if ($type & SIMPLEPIE_TYPE_RSS_090)
if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'channel'))
if (isset($channel[0]['child'][$namespace][$tag]))
return $channel[0]['child'][$namespace][$tag];
if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
if ($channel = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'channel'))
if (isset($channel[0]['child'][$namespace][$tag]))
return $channel[0]['child'][$namespace][$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 {@see SimplePie::get_feed_tags()} for a description of the return value
* @see http://simplepie.org/wiki/faq/supported_xml_namespaces
* @param string $namespace The URL of the XML namespace of the elements you're trying to access
* @param string $tag Tag name
public function get_image_tags($namespace, $tag)
$type = $this->get_type();
if ($type & SIMPLEPIE_TYPE_RSS_10)
if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'image'))
if (isset($image[0]['child'][$namespace][$tag]))
return $image[0]['child'][$namespace][$tag];
if ($type & SIMPLEPIE_TYPE_RSS_090)
if ($image = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'image'))
if (isset($image[0]['child'][$namespace][$tag]))
return $image[0]['child'][$namespace][$tag];
if ($type & SIMPLEPIE_TYPE_RSS_SYNDICATION)
if ($image = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'image'))
if (isset($image[0]['child'][$namespace][$tag]))
return $image[0]['child'][$namespace][$tag];
* Get the base URL value from the feed
* Uses `<xml:base>` if available, otherwise uses the first link in the
* feed, or failing that, the URL of the feed itself.
public function get_base($element = array())
if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base']))
return $element['xml_base'];
elseif ($this->get_link() !== null)
return $this->get_link();
return $this->subscribe_url();
* @see SimplePie_Sanitize::sanitize()
* @param string $data Data to sanitize
* @param int $type One of the SIMPLEPIE_CONSTRUCT_* constants
* @param string $base Base URL to resolve URLs against
* @return string Sanitized data
public function sanitize($data, $type, $base = '')
return $this->sanitize->sanitize($data, $type, $base);
catch (SimplePie_Exception $e)
if (!$this->enable_exceptions)
$this->error = $e->getMessage();
$this->registry->call('Misc', 'error', array($this->error, E_USER_WARNING, $e->getFile(), $e->getLine()));
* Get the title of the feed
* Uses `<atom:title>`, `<title>` or `<dc:title>`
* @since 1.0 (previously called `get_feed_title` since 0.8)
public function get_title()
if ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'title'))
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'title'))
return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', array($return[0]['attribs'])), $this->get_base($return[0]));
elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'title'))
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'title'))
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'title'))
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_MAYBE_HTML, $this->get_base($return[0]));
elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'title'))
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
elseif ($return = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'title'))
return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
* Get a category for the feed
* @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
* @return SimplePie_Category|null
public function get_category($key = 0)
$categories = $this->get_categories();
if (isset($categories[$key]))
return $categories[$key];
* Get all categories for the feed
* Uses `<atom:category>`, `<category>` or `<dc:subject>`
* @return array|null List of {@see SimplePie_Category} objects
public function get_categories()
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'category') as $category)
if (isset($category['attribs']['']['term']))
$term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT);
if (isset($category['attribs']['']['scheme']))
$scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT);
if (isset($category['attribs']['']['label']))
$label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT);
$categories[] = $this->registry->create('Category', array($term, $scheme, $label));
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'category') as $category)
// This is really the label, but keep this as the term also for BC.
// Label will also work on retrieving because that falls back to term.
$term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT);
if (isset($category['attribs']['']['domain']))
$scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT);
$categories[] = $this->registry->create('Category', array($term, $scheme, null));
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'subject') as $category)
$categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'subject') as $category)
$categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
return array_unique($categories);
* Get an author for the feed
* @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
* @return SimplePie_Author|null
public function get_author($key = 0)
$authors = $this->get_authors();
if (isset($authors[$key]))
* Get all authors for the feed
* Uses `<atom:author>`, `<author>`, `<dc:creator>` or `<itunes:author>`
* @return array|null List of {@see SimplePie_Author} objects
public function get_authors()
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author') as $author)
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data']))
$name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data']))
$uri = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]));
if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data']))
$email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
if ($name !== null || $email !== null || $uri !== null)
$authors[] = $this->registry->create('Author', array($name, $uri, $email));
if ($author = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'author'))
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data']))
$name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data']))
$url = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]));
if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data']))
$email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
if ($name !== null || $email !== null || $url !== null)
$authors[] = $this->registry->create('Author', array($name, $url, $email));
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author)
$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author)
$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
foreach ((array) $this->get_channel_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author)
$authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null));
return array_unique($authors);
* Get a contributor for the feed
* @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1