$this->autodiscovery_cache_duration = $seconds;
* Set the file system location where the cached files should be stored
* @deprecated since SimplePie 1.8.0, use SimplePie::set_cache() instead.
* @param string $location The file system location.
public function set_cache_location(string $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 = $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(string $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 !== 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(bool $enable = true)
$this->order_by_date = $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|false $encoding Character encoding
public function set_input_encoding($encoding = false)
$this->input_encoding = (string) $encoding;
$this->input_encoding = false;
* Set how much feed autodiscovery to do
* @see self::LOCATOR_NONE
* @see self::LOCATOR_AUTODISCOVERY
* @see self::LOCATOR_LOCAL_EXTENSION
* @see self::LOCATOR_LOCAL_BODY
* @see self::LOCATOR_REMOTE_EXTENSION
* @see self::LOCATOR_REMOTE_BODY
* @param self::LOCATOR_* $level Feed Autodiscovery Level (level can be a combination of the above constants, see bitwise OR operator)
public function set_autodiscovery_level(int $level = self::LOCATOR_ALL)
$this->autodiscovery = $level;
* Use this to override SimplePie's default classes
public function &get_registry()
* Set which class SimplePie uses for caching
* @deprecated since SimplePie 1.3, use {@see set_cache()} instead
* @param class-string<Cache> $class Name of custom class
* @return bool True on success, false otherwise
public function set_cache_class(string $class = Cache::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::set_cache()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Cache::class, $class, true);
* Set which class SimplePie uses for auto-discovery
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Locator> $class Name of custom class
* @return bool True on success, false otherwise
public function set_locator_class(string $class = Locator::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Locator::class, $class, true);
* Set which class SimplePie uses for XML parsing
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Parser> $class Name of custom class
* @return bool True on success, false otherwise
public function set_parser_class(string $class = Parser::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Parser::class, $class, true);
* Set which class SimplePie uses for remote file fetching
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<File> $class Name of custom class
* @return bool True on success, false otherwise
public function set_file_class(string $class = File::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(File::class, $class, true);
* Set which class SimplePie uses for data sanitization
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Sanitize> $class Name of custom class
* @return bool True on success, false otherwise
public function set_sanitize_class(string $class = Sanitize::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Sanitize::class, $class, true);
* Set which class SimplePie uses for handling feed items
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Item> $class Name of custom class
* @return bool True on success, false otherwise
public function set_item_class(string $class = Item::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Item::class, $class, true);
* Set which class SimplePie uses for handling author data
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Author> $class Name of custom class
* @return bool True on success, false otherwise
public function set_author_class(string $class = Author::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Author::class, $class, true);
* Set which class SimplePie uses for handling category data
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Category> $class Name of custom class
* @return bool True on success, false otherwise
public function set_category_class(string $class = Category::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Category::class, $class, true);
* Set which class SimplePie uses for feed enclosures
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Enclosure> $class Name of custom class
* @return bool True on success, false otherwise
public function set_enclosure_class(string $class = Enclosure::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Enclosure::class, $class, true);
* Set which class SimplePie uses for `<media:text>` captions
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Caption> $class Name of custom class
* @return bool True on success, false otherwise
public function set_caption_class(string $class = Caption::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Caption::class, $class, true);
* Set which class SimplePie uses for `<media:copyright>`
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Copyright> $class Name of custom class
* @return bool True on success, false otherwise
public function set_copyright_class(string $class = Copyright::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Copyright::class, $class, true);
* Set which class SimplePie uses for `<media:credit>`
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Credit> $class Name of custom class
* @return bool True on success, false otherwise
public function set_credit_class(string $class = Credit::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Credit::class, $class, true);
* Set which class SimplePie uses for `<media:rating>`
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Rating> $class Name of custom class
* @return bool True on success, false otherwise
public function set_rating_class(string $class = Rating::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Rating::class, $class, true);
* Set which class SimplePie uses for `<media:restriction>`
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Restriction> $class Name of custom class
* @return bool True on success, false otherwise
public function set_restriction_class(string $class = Restriction::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Restriction::class, $class, true);
* Set which class SimplePie uses for content-type sniffing
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Sniffer> $class Name of custom class
* @return bool True on success, false otherwise
public function set_content_type_sniffer_class(string $class = Sniffer::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Sniffer::class, $class, true);
* Set which class SimplePie uses item sources
* @deprecated since SimplePie 1.3, use {@see get_registry()} instead
* @param class-string<Source> $class Name of custom class
* @return bool True on success, false otherwise
public function set_source_class(string $class = Source::class)
trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.3, please use "SimplePie\SimplePie::get_registry()" instead.', __METHOD__), \E_USER_DEPRECATED);
return $this->registry->register(Source::class, $class, true);
* Set the user agent string
* @param string $ua New user agent string.
public function set_useragent(?string $ua = null)
if ($this->http_client_injected) {
throw new SimplePieException(sprintf(
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure user agent string in your HTTP client instead.',
$ua = Misc::get_default_useragent();
$this->useragent = (string) $ua;
// Reset a possible existing FileClient,
// so a new client with the changed value will be created
if (is_object($this->http_client) && $this->http_client instanceof FileClient) {
$this->http_client = null;
} elseif (is_object($this->http_client)) {
// Trigger notice if a PSR-18 client was set
'Using "%s()" has no effect, because you already provided a HTTP client with "%s::set_http_client()". Configure the useragent in your HTTP client instead.',
* Set a namefilter to modify the cache filename with
* @param NameFilter $filter
public function set_cache_namefilter(NameFilter $filter): void
$this->cache_namefilter = $filter;
* Set callback function to create cache filename with
* @deprecated since SimplePie 1.8.0, use {@see set_cache_namefilter()} instead
* @param (string&(callable(string): string))|null $function Callback function
public function set_cache_name_function(?string $function = null)
// trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.8.0, please use "SimplePie\SimplePie::set_cache_namefilter()" instead.', __METHOD__), \E_USER_DEPRECATED);
if ($function === null) {
$this->cache_name_function = $function;
$this->set_cache_namefilter(new CallableNameFilter($this->cache_name_function));
* 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.
* @param bool $set Whether to set them or not
public function set_stupidly_fast(bool $set = false)
$this->enable_order_by_date(false);
$this->remove_div(false);
$this->strip_comments(false);
$this->strip_htmltags([]);
$this->strip_attributes([]);
$this->add_attributes([]);
$this->set_image_handler(false);
$this->set_https_domains([]);
* Set maximum number of feeds to check with autodiscovery
* @param int $max Maximum number of feeds to check
public function set_max_checked_feeds(int $max = 10)
$this->max_checked_feeds = $max;
public function remove_div(bool $enable = true)
$this->sanitize->remove_div($enable);
* @param string[]|string|false $tags Set a list of tags to strip, or set empty string to use default tags, or false to strip nothing.
public function strip_htmltags($tags = '', ?bool $encode = null)
$tags = $this->strip_htmltags;
$this->sanitize->strip_htmltags($tags);
$this->sanitize->encode_instead_of_strip($encode);
public function encode_instead_of_strip(bool $enable = true)
$this->sanitize->encode_instead_of_strip($enable);
* @param string[]|string $attribs