public $force_feed = false;
* @var bool Enable/Disable Caching
* @see SimplePie::enable_cache()
private $enable_cache = true;
* @see SimplePie::set_cache()
* @see SimplePie::set_cache_namefilter()
private $cache_namefilter;
* @var bool Force SimplePie to fallback to expired cache, if enabled,
* when feed is unavailable.
* @see SimplePie::force_cache_fallback()
public $force_cache_fallback = false;
* @var int Cache duration (in seconds)
* @see SimplePie::set_cache_duration()
public $cache_duration = 3600;
* @var int Auto-discovery cache duration (in seconds)
* @see SimplePie::set_autodiscovery_cache_duration()
public $autodiscovery_cache_duration = 604800; // 7 Days.
* @var string Cache location (relative to executing script)
* @see SimplePie::set_cache_location()
public $cache_location = './cache';
* @var string Function that creates the cache filename
* @see SimplePie::set_cache_name_function()
public $cache_name_function = 'md5';
* @var bool Reorder feed by date descending
* @see SimplePie::enable_order_by_date()
public $order_by_date = true;
* @var mixed Force input encoding to be set to the follow value
* (false, or anything type-cast to false, disables this feature)
* @see SimplePie::set_input_encoding()
public $input_encoding = false;
* @var int Feed Autodiscovery Level
* @see SimplePie::set_autodiscovery_level()
public $autodiscovery = self::LOCATOR_ALL;
* @var \SimplePie\Registry
* @var int Maximum number of feeds to check with autodiscovery
* @see SimplePie::set_max_checked_feeds()
public $max_checked_feeds = 10;
* @var array All the feeds found during the autodiscovery process
* @see SimplePie::get_all_discovered_feeds()
public $all_discovered_feeds = [];
* @var string Web-accessible path to the handler_image.php file.
* @see SimplePie::set_image_handler()
public $image_handler = '';
* @var array Stores the URLs when multiple feeds are being initialized.
* @see SimplePie::set_feed_url()
public $multifeed_url = [];
* @var array Stores SimplePie objects when multiple feeds initialized.
public $multifeed_objects = [];
* @var array Stores the get_object_vars() array for use with multifeeds.
* @see SimplePie::set_feed_url()
public $config_settings = null;
* @var integer Stores the number of items to return per-feed with multifeeds.
* @see SimplePie::set_item_limit()
* @var bool Stores if last-modified and/or etag headers were sent with the
* request when checking a feed.
public $check_modified = false;
* @var array Stores the default attributes to be stripped by strip_attributes().
* @see SimplePie::strip_attributes()
public $strip_attributes = ['bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'];
* @var array Stores the default attributes to add to different tags by add_attributes().
* @see SimplePie::add_attributes()
public $add_attributes = ['audio' => ['preload' => 'none'], 'iframe' => ['sandbox' => 'allow-scripts allow-same-origin'], 'video' => ['preload' => 'none']];
* @var array Stores the default tags to be stripped by strip_htmltags().
* @see SimplePie::strip_htmltags()
public $strip_htmltags = ['base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'];
* @var array Stores the default attributes to be renamed by rename_attributes().
* @see SimplePie::rename_attributes()
public $rename_attributes = [];
* @var bool Should we throw exceptions, or use the old-style error property?
public $enable_exceptions = false;
* 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 function __construct()
if (version_compare(PHP_VERSION, '7.2', '<')) {
exit('Please upgrade to PHP 7.2 or newer.');
$this->set_cache_namefilter(new CallableNameFilter($this->cache_name_function));
// Other objects, instances created here so we can set options on them
$this->sanitize = new \SimplePie\Sanitize();
$this->registry = new \SimplePie\Registry();
if (func_num_args() > 0) {
trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_duration() directly.', \E_USER_DEPRECATED);
$this->set_cache_duration($args[2]);
$this->set_cache_location($args[1]);
$this->set_feed_url($args[0]);
* Used for converting object to a string
public function __toString()
return md5(serialize($this->data));
* Remove items that link back to this before destroying this object
public function __destruct()
if (!empty($this->data['items'])) {
foreach ($this->data['items'] as $item) {
unset($item, $this->data['items']);
if (!empty($this->data['ordered_items'])) {
foreach ($this->data['ordered_items'] as $item) {
unset($item, $this->data['ordered_items']);
* 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.
* @param bool $enable Force the given data/URL to be treated as a feed
public function force_feed($enable = false)
$this->force_feed = (bool) $enable;
* 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
* 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.
* @since 1.0 Preview Release
* @param string|array $url This is the URL (or array of URLs) that you want to parse.
public function set_feed_url($url)
$this->multifeed_url = [];
foreach ($url as $value) {
$this->multifeed_url[] = $this->registry->call(Misc::class, 'fix_protocol', [$value, 1]);
$this->feed_url = $this->registry->call(Misc::class, 'fix_protocol', [$url, 1]);
$this->permanent_url = $this->feed_url;
* Set an instance of {@see \SimplePie\File} to use as a feed
* @param \SimplePie\File &$file
* @return bool True on success, false on failure
public function set_file(&$file)
if ($file instanceof \SimplePie\File) {
$this->feed_url = $file->url;
$this->permanent_url = $this->feed_url;
* 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
* @param string $data RSS or Atom data as a string.
public function set_raw_data($data)
* Set 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.
* @param int $timeout The maximum number of seconds to spend waiting to retrieve a feed.
public function set_timeout($timeout = 10)
$this->timeout = (int) $timeout;
* Set custom curl options
* This allows you to change default curl options
* @param array $curl_options Curl options to add to default settings
public function set_curl_options(array $curl_options = [])
$this->curl_options = $curl_options;
* Force SimplePie to use fsockopen() instead of cURL
* @param bool $enable Force fsockopen() to be used
public function force_fsockopen($enable = false)
$this->force_fsockopen = (bool) $enable;
* 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.
* @since 1.0 Preview Release
* @param bool $enable Enable caching
public function enable_cache($enable = true)
$this->enable_cache = (bool) $enable;
* Set a PSR-16 implementation as cache
* @param CacheInterface $psr16cache The PSR-16 cache implementation
public function set_cache(CacheInterface $cache)
$this->cache = new Psr16($cache);
* SimplePie to continue to fall back to expired cache, if enabled, when
* This tells SimplePie to ignore any file errors and fall back to cache
* instead. This only works if caching is enabled and cached content
* @deprecated since SimplePie 1.8.0, expired cache will not be used anymore.
* @param bool $enable Force use of cache on fail.
public function force_cache_fallback($enable = false)
// @trigger_error(sprintf('SimplePie\SimplePie::force_cache_fallback() is deprecated since SimplePie 1.8.0, expired cache will not be used anymore.'), \E_USER_DEPRECATED);
$this->force_cache_fallback = (bool) $enable;
* Set the length of time (in seconds) that the contents of a feed will be
* @param int $seconds The feed content cache duration
public function set_cache_duration($seconds = 3600)
$this->cache_duration = (int) $seconds;
* Set the length of time (in seconds) that the autodiscovered feed URL will
* @param int $seconds The autodiscovered feed URL cache duration.
public function set_autodiscovery_cache_duration($seconds = 604800)
$this->autodiscovery_cache_duration = (int) $seconds;
* Set the file system location where the cached files should be stored
* @deprecated since SimplePie 1.8.0, use \SimplePie\SimplePie::set_cache() instead.
* @param string $location The file system location.
public function set_cache_location($location = './cache')
// @trigger_error(sprintf('SimplePie\SimplePie::set_cache_location() is deprecated since SimplePie 1.8.0, please use "SimplePie\SimplePie::set_cache()" instead.'), \E_USER_DEPRECATED);
$this->cache_location = (string) $location;
* Return the filename (i.e. hash, without path and without extension) of the file to cache a given URL.
* @param string $url The URL of the feed to be cached.
* @return string A filename (i.e. hash, without path and without extension).
public function get_cache_filename($url)
// Append custom parameters to the URL to avoid cache pollution in case of multiple calls with different parameters.
$url .= $this->force_feed ? '#force_feed' : '';
if ($this->timeout != 10) {
$options[CURLOPT_TIMEOUT] = $this->timeout;
if ($this->useragent !== \SimplePie\Misc::get_default_useragent()) {
$options[CURLOPT_USERAGENT] = $this->useragent;
if (!empty($this->curl_options)) {
foreach ($this->curl_options as $k => $v) {
$url .= '#' . urlencode(var_export($options, true));
return $this->cache_namefilter->filter($url);
* Set whether feed items should be sorted into reverse chronological order
* @param bool $enable Sort as reverse chronological order.
public function enable_order_by_date($enable = true)
$this->order_by_date = (bool) $enable;
* 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
* @param string $encoding Character encoding
public function set_input_encoding($encoding = false)
$this->input_encoding = (string) $encoding;
$this->input_encoding = false;