diff options
author | Mario <mario@mariovavti.com> | 2023-01-27 07:28:21 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-01-27 07:28:21 +0000 |
commit | 9a16bf65bdd5858a2da8e850e9825b2a5498b044 (patch) | |
tree | 4208cf7ba1e176d79b82b00982a783988b5e45a7 /vendor/simplepie/simplepie/src/SimplePie.php | |
parent | c3d3dc9d92d14dbcfbaf39c4cc9ad4c120812a3d (diff) | |
download | volse-hubzilla-9a16bf65bdd5858a2da8e850e9825b2a5498b044.tar.gz volse-hubzilla-9a16bf65bdd5858a2da8e850e9825b2a5498b044.tar.bz2 volse-hubzilla-9a16bf65bdd5858a2da8e850e9825b2a5498b044.zip |
update simplepie
Diffstat (limited to 'vendor/simplepie/simplepie/src/SimplePie.php')
-rw-r--r-- | vendor/simplepie/simplepie/src/SimplePie.php | 637 |
1 files changed, 434 insertions, 203 deletions
diff --git a/vendor/simplepie/simplepie/src/SimplePie.php b/vendor/simplepie/simplepie/src/SimplePie.php index 22daa17aa..1dfa39fad 100644 --- a/vendor/simplepie/simplepie/src/SimplePie.php +++ b/vendor/simplepie/simplepie/src/SimplePie.php @@ -1,4 +1,6 @@ <?php + +declare(strict_types=1); /** * SimplePie * @@ -43,6 +45,16 @@ namespace SimplePie; +use InvalidArgumentException; +use Psr\SimpleCache\CacheInterface; +use SimplePie\Cache\Base; +use SimplePie\Cache\BaseDataCache; +use SimplePie\Cache\CallableNameFilter; +use SimplePie\Cache\DataCache; +use SimplePie\Cache\NameFilter; +use SimplePie\Cache\Psr16; +use SimplePie\Content\Type\Sniffer; + /** * SimplePie * @@ -54,350 +66,350 @@ class SimplePie /** * SimplePie Name */ - const NAME = 'SimplePie'; + public const NAME = 'SimplePie'; /** * SimplePie Version */ - const VERSION = '1.7.0'; + public const VERSION = '1.8.0'; /** * SimplePie Website URL */ - const URL = 'http://simplepie.org'; + public const URL = 'http://simplepie.org'; /** * SimplePie Linkback */ - const LINKBACK = '<a href="' . self::URL . '" title="' . self::NAME . ' ' . self::VERSION . '">' . self::NAME . '</a>'; + public const LINKBACK = '<a href="' . self::URL . '" title="' . self::NAME . ' ' . self::VERSION . '">' . self::NAME . '</a>'; /** * No Autodiscovery * @see SimplePie::set_autodiscovery_level() */ - const LOCATOR_NONE = 0; + public const LOCATOR_NONE = 0; /** * Feed Link Element Autodiscovery * @see SimplePie::set_autodiscovery_level() */ - const LOCATOR_AUTODISCOVERY = 1; + public const LOCATOR_AUTODISCOVERY = 1; /** * Local Feed Extension Autodiscovery * @see SimplePie::set_autodiscovery_level() */ - const LOCATOR_LOCAL_EXTENSION = 2; + public const LOCATOR_LOCAL_EXTENSION = 2; /** * Local Feed Body Autodiscovery * @see SimplePie::set_autodiscovery_level() */ - const LOCATOR_LOCAL_BODY = 4; + public const LOCATOR_LOCAL_BODY = 4; /** * Remote Feed Extension Autodiscovery * @see SimplePie::set_autodiscovery_level() */ - const LOCATOR_REMOTE_EXTENSION = 8; + public const LOCATOR_REMOTE_EXTENSION = 8; /** * Remote Feed Body Autodiscovery * @see SimplePie::set_autodiscovery_level() */ - const LOCATOR_REMOTE_BODY = 16; + public const LOCATOR_REMOTE_BODY = 16; /** * All Feed Autodiscovery * @see SimplePie::set_autodiscovery_level() */ - const LOCATOR_ALL = 31; + public const LOCATOR_ALL = 31; /** * No known feed type */ - const TYPE_NONE = 0; + public const TYPE_NONE = 0; /** * RSS 0.90 */ - const TYPE_RSS_090 = 1; + public const TYPE_RSS_090 = 1; /** * RSS 0.91 (Netscape) */ - const TYPE_RSS_091_NETSCAPE = 2; + public const TYPE_RSS_091_NETSCAPE = 2; /** * RSS 0.91 (Userland) */ - const TYPE_RSS_091_USERLAND = 4; + public const TYPE_RSS_091_USERLAND = 4; /** * RSS 0.91 (both Netscape and Userland) */ - const TYPE_RSS_091 = 6; + public const TYPE_RSS_091 = 6; /** * RSS 0.92 */ - const TYPE_RSS_092 = 8; + public const TYPE_RSS_092 = 8; /** * RSS 0.93 */ - const TYPE_RSS_093 = 16; + public const TYPE_RSS_093 = 16; /** * RSS 0.94 */ - const TYPE_RSS_094 = 32; + public const TYPE_RSS_094 = 32; /** * RSS 1.0 */ - const TYPE_RSS_10 = 64; + public const TYPE_RSS_10 = 64; /** * RSS 2.0 */ - const TYPE_RSS_20 = 128; + public const TYPE_RSS_20 = 128; /** * RDF-based RSS */ - const TYPE_RSS_RDF = 65; + public const TYPE_RSS_RDF = 65; /** * Non-RDF-based RSS (truly intended as syndication format) */ - const TYPE_RSS_SYNDICATION = 190; + public const TYPE_RSS_SYNDICATION = 190; /** * All RSS */ - const TYPE_RSS_ALL = 255; + public const TYPE_RSS_ALL = 255; /** * Atom 0.3 */ - const TYPE_ATOM_03 = 256; + public const TYPE_ATOM_03 = 256; /** * Atom 1.0 */ - const TYPE_ATOM_10 = 512; + public const TYPE_ATOM_10 = 512; /** * All Atom */ - const TYPE_ATOM_ALL = 768; + public const TYPE_ATOM_ALL = 768; /** * All feed types */ - const TYPE_ALL = 1023; + public const TYPE_ALL = 1023; /** * No construct */ - const CONSTRUCT_NONE = 0; + public const CONSTRUCT_NONE = 0; /** * Text construct */ - const CONSTRUCT_TEXT = 1; + public const CONSTRUCT_TEXT = 1; /** * HTML construct */ - const CONSTRUCT_HTML = 2; + public const CONSTRUCT_HTML = 2; /** * XHTML construct */ - const CONSTRUCT_XHTML = 4; + public const CONSTRUCT_XHTML = 4; /** * base64-encoded construct */ - const CONSTRUCT_BASE64 = 8; + public const CONSTRUCT_BASE64 = 8; /** * IRI construct */ - const CONSTRUCT_IRI = 16; + public const CONSTRUCT_IRI = 16; /** * A construct that might be HTML */ - const CONSTRUCT_MAYBE_HTML = 32; + public const CONSTRUCT_MAYBE_HTML = 32; /** * All constructs */ - const CONSTRUCT_ALL = 63; + public const CONSTRUCT_ALL = 63; /** * Don't change case */ - const SAME_CASE = 1; + public const SAME_CASE = 1; /** * Change to lowercase */ - const LOWERCASE = 2; + public const LOWERCASE = 2; /** * Change to uppercase */ - const UPPERCASE = 4; + public const UPPERCASE = 4; /** * PCRE for HTML attributes */ - const PCRE_HTML_ATTRIBUTE = '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*'; + public const PCRE_HTML_ATTRIBUTE = '((?:[\x09\x0A\x0B\x0C\x0D\x20]+[^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"(?:[^"]*)"|\'(?:[^\']*)\'|(?:[^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?)*)[\x09\x0A\x0B\x0C\x0D\x20]*'; /** * PCRE for XML attributes */ - const PCRE_XML_ATTRIBUTE = '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*'; + public const PCRE_XML_ATTRIBUTE = '((?:\s+(?:(?:[^\s:]+:)?[^\s:]+)\s*=\s*(?:"(?:[^"]*)"|\'(?:[^\']*)\'))*)\s*'; /** * XML Namespace */ - const NAMESPACE_XML = 'http://www.w3.org/XML/1998/namespace'; + public const NAMESPACE_XML = 'http://www.w3.org/XML/1998/namespace'; /** * Atom 1.0 Namespace */ - const NAMESPACE_ATOM_10 = 'http://www.w3.org/2005/Atom'; + public const NAMESPACE_ATOM_10 = 'http://www.w3.org/2005/Atom'; /** * Atom 0.3 Namespace */ - const NAMESPACE_ATOM_03 = 'http://purl.org/atom/ns#'; + public const NAMESPACE_ATOM_03 = 'http://purl.org/atom/ns#'; /** * RDF Namespace */ - const NAMESPACE_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; + public const NAMESPACE_RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; /** * RSS 0.90 Namespace */ - const NAMESPACE_RSS_090 = 'http://my.netscape.com/rdf/simple/0.9/'; + public const NAMESPACE_RSS_090 = 'http://my.netscape.com/rdf/simple/0.9/'; /** * RSS 1.0 Namespace */ - const NAMESPACE_RSS_10 = 'http://purl.org/rss/1.0/'; + public const NAMESPACE_RSS_10 = 'http://purl.org/rss/1.0/'; /** * RSS 1.0 Content Module Namespace */ - const NAMESPACE_RSS_10_MODULES_CONTENT = 'http://purl.org/rss/1.0/modules/content/'; + public const NAMESPACE_RSS_10_MODULES_CONTENT = 'http://purl.org/rss/1.0/modules/content/'; /** * RSS 2.0 Namespace * (Stupid, I know, but I'm certain it will confuse people less with support.) */ - const NAMESPACE_RSS_20 = ''; + public const NAMESPACE_RSS_20 = ''; /** * DC 1.0 Namespace */ - const NAMESPACE_DC_10 = 'http://purl.org/dc/elements/1.0/'; + public const NAMESPACE_DC_10 = 'http://purl.org/dc/elements/1.0/'; /** * DC 1.1 Namespace */ - const NAMESPACE_DC_11 = 'http://purl.org/dc/elements/1.1/'; + public const NAMESPACE_DC_11 = 'http://purl.org/dc/elements/1.1/'; /** * W3C Basic Geo (WGS84 lat/long) Vocabulary Namespace */ - const NAMESPACE_W3C_BASIC_GEO = 'http://www.w3.org/2003/01/geo/wgs84_pos#'; + public const NAMESPACE_W3C_BASIC_GEO = 'http://www.w3.org/2003/01/geo/wgs84_pos#'; /** * GeoRSS Namespace */ - const NAMESPACE_GEORSS = 'http://www.georss.org/georss'; + public const NAMESPACE_GEORSS = 'http://www.georss.org/georss'; /** * Media RSS Namespace */ - const NAMESPACE_MEDIARSS = 'http://search.yahoo.com/mrss/'; + public const NAMESPACE_MEDIARSS = 'http://search.yahoo.com/mrss/'; /** * Wrong Media RSS Namespace. Caused by a long-standing typo in the spec. */ - const NAMESPACE_MEDIARSS_WRONG = 'http://search.yahoo.com/mrss'; + public const NAMESPACE_MEDIARSS_WRONG = 'http://search.yahoo.com/mrss'; /** * Wrong Media RSS Namespace #2. New namespace introduced in Media RSS 1.5. */ - const NAMESPACE_MEDIARSS_WRONG2 = 'http://video.search.yahoo.com/mrss'; + public const NAMESPACE_MEDIARSS_WRONG2 = 'http://video.search.yahoo.com/mrss'; /** * Wrong Media RSS Namespace #3. A possible typo of the Media RSS 1.5 namespace. */ - const NAMESPACE_MEDIARSS_WRONG3 = 'http://video.search.yahoo.com/mrss/'; + public const NAMESPACE_MEDIARSS_WRONG3 = 'http://video.search.yahoo.com/mrss/'; /** * Wrong Media RSS Namespace #4. New spec location after the RSS Advisory Board takes it over, but not a valid namespace. */ - const NAMESPACE_MEDIARSS_WRONG4 = 'http://www.rssboard.org/media-rss'; + public const NAMESPACE_MEDIARSS_WRONG4 = 'http://www.rssboard.org/media-rss'; /** * Wrong Media RSS Namespace #5. A possible typo of the RSS Advisory Board URL. */ - const NAMESPACE_MEDIARSS_WRONG5 = 'http://www.rssboard.org/media-rss/'; + public const NAMESPACE_MEDIARSS_WRONG5 = 'http://www.rssboard.org/media-rss/'; /** * iTunes RSS Namespace */ - const NAMESPACE_ITUNES = 'http://www.itunes.com/dtds/podcast-1.0.dtd'; + public const NAMESPACE_ITUNES = 'http://www.itunes.com/dtds/podcast-1.0.dtd'; /** * XHTML Namespace */ - const NAMESPACE_XHTML = 'http://www.w3.org/1999/xhtml'; + public const NAMESPACE_XHTML = 'http://www.w3.org/1999/xhtml'; /** * IANA Link Relations Registry */ - const IANA_LINK_RELATIONS_REGISTRY = 'http://www.iana.org/assignments/relation/'; + public const IANA_LINK_RELATIONS_REGISTRY = 'http://www.iana.org/assignments/relation/'; /** * No file source */ - const FILE_SOURCE_NONE = 0; + public const FILE_SOURCE_NONE = 0; /** * Remote file source */ - const FILE_SOURCE_REMOTE = 1; + public const FILE_SOURCE_REMOTE = 1; /** * Local file source */ - const FILE_SOURCE_LOCAL = 2; + public const FILE_SOURCE_LOCAL = 2; /** * fsockopen() file source */ - const FILE_SOURCE_FSOCKOPEN = 4; + public const FILE_SOURCE_FSOCKOPEN = 4; /** * cURL file source */ - const FILE_SOURCE_CURL = 8; + public const FILE_SOURCE_CURL = 8; /** * file_get_contents() file source */ - const FILE_SOURCE_FILE_GET_CONTENTS = 16; + public const FILE_SOURCE_FILE_GET_CONTENTS = 16; /** * @var array Raw data @@ -495,7 +507,19 @@ class SimplePie * @see SimplePie::enable_cache() * @access private */ - public $cache = true; + private $enable_cache = true; + + /** + * @var DataCache|null + * @see SimplePie::set_cache() + */ + private $cache = null; + + /** + * @var NameFilter + * @see SimplePie::set_cache_namefilter() + */ + private $cache_namefilter; /** * @var bool Force SimplePie to fallback to expired cache, if enabled, @@ -666,20 +690,21 @@ class SimplePie */ public function __construct() { - if (version_compare(PHP_VERSION, '5.6', '<')) { - trigger_error('Please upgrade to PHP 5.6 or newer.'); + if (version_compare(PHP_VERSION, '7.2', '<')) { + trigger_error('Please upgrade to PHP 7.2 or newer.'); die(); } $this->set_useragent(); + $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) { - $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; - trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_duration() directly.', $level); + 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); $args = func_get_args(); switch (count($args)) { @@ -759,10 +784,10 @@ class SimplePie $this->multifeed_url = []; if (is_array($url)) { foreach ($url as $value) { - $this->multifeed_url[] = $this->registry->call('Misc', 'fix_protocol', [$value, 1]); + $this->multifeed_url[] = $this->registry->call(Misc::class, 'fix_protocol', [$value, 1]); } } else { - $this->feed_url = $this->registry->call('Misc', 'fix_protocol', [$url, 1]); + $this->feed_url = $this->registry->call(Misc::class, 'fix_protocol', [$url, 1]); $this->permanent_url = $this->feed_url; } } @@ -851,7 +876,19 @@ class SimplePie */ public function enable_cache($enable = true) { - $this->cache = (bool) $enable; + $this->enable_cache = (bool) $enable; + } + + /** + * Set a PSR-16 implementation as cache + * + * @param CacheInterface $psr16cache The PSR-16 cache implementation + * + * @return void + */ + public function set_cache(CacheInterface $cache) + { + $this->cache = new Psr16($cache); } /** @@ -861,12 +898,15 @@ class SimplePie * 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. - + * + * @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) { - $this->force_cache_fallback= (bool) $enable; + // @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; } /** @@ -894,15 +934,19 @@ class SimplePie /** * 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). */ @@ -926,7 +970,8 @@ class SimplePie ksort($options); $url .= '#' . urlencode(var_export($options, true)); } - return call_user_func($this->cache_name_function, $url); + + return $this->cache_namefilter->filter($url); } /** @@ -978,149 +1023,269 @@ class SimplePie * * Use this to override SimplePie's default classes * @see \SimplePie\Registry - * @return \SimplePie\Registry + * + * @return Registry */ public function &get_registry() { return $this->registry; } - /**#@+ - * Useful when you are overloading or extending SimplePie's default classes. + /** + * Set which class SimplePie uses for caching + * + * @deprecated since SimplePie 1.3, use {@see set_cache()} instead * - * @deprecated Use {@see get_registry()} instead - * @link http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.extends PHP5 extends documentation * @param string $class Name of custom class + * * @return boolean True on success, false otherwise */ - /** - * Set which class SimplePie uses for caching - */ - public function set_cache_class($class = 'SimplePie\Cache') + public function set_cache_class($class = Cache::class) { - return $this->registry->register('Cache', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_locator_class($class = 'SimplePie\Locator') + public function set_locator_class($class = Locator::class) { - return $this->registry->register('Locator', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_parser_class($class = 'SimplePie\Parser') + public function set_parser_class($class = Parser::class) { - return $this->registry->register('Parser', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_file_class($class = 'SimplePie\File') + public function set_file_class($class = File::class) { - return $this->registry->register('File', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_sanitize_class($class = 'SimplePie\Sanitize') + public function set_sanitize_class($class = Sanitize::class) { - return $this->registry->register('Sanitize', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_item_class($class = 'SimplePie\Item') + public function set_item_class($class = Item::class) { - return $this->registry->register('Item', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_author_class($class = 'SimplePie\Author') + public function set_author_class($class = Author::class) { - return $this->registry->register('Author', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_category_class($class = 'SimplePie\Category') + public function set_category_class($class = Category::class) { - return $this->registry->register('Category', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_enclosure_class($class = 'SimplePie\Enclosure') + public function set_enclosure_class($class = Enclosure::class) { - return $this->registry->register('Enclosure', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_caption_class($class = 'SimplePie\Caption') + public function set_caption_class($class = Caption::class) { - return $this->registry->register('Caption', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_copyright_class($class = 'SimplePie\Copyright') + public function set_copyright_class($class = Copyright::class) { - return $this->registry->register('Copyright', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_credit_class($class = 'SimplePie\Credit') + public function set_credit_class($class = Credit::class) { - return $this->registry->register('Credit', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_rating_class($class = 'SimplePie\Rating') + public function set_rating_class($class = Rating::class) { - return $this->registry->register('Rating', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_restriction_class($class = 'SimplePie\Restriction') + public function set_restriction_class($class = Restriction::class) { - return $this->registry->register('Restriction', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_content_type_sniffer_class($class = 'SimplePie\Content\Type\Sniffer') + public function set_content_type_sniffer_class($class = Sniffer::class) { - return $this->registry->register('Content_Type_Sniffer', $class, true); + // 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 string $class Name of custom class + * + * @return boolean True on success, false otherwise */ - public function set_source_class($class = 'SimplePie\Source') + public function set_source_class($class = Source::class) { - return $this->registry->register('Source', $class, true); + // 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 @@ -1137,14 +1302,32 @@ class SimplePie } /** + * Set a namefilter to modify the cache filename with + * + * @param NameFilter $filter + * + * @return void + */ + 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 mixed $function Callback function */ public function set_cache_name_function($function = 'md5') { + // trigger_error(sprintf('"%s()" is deprecated since SimplePie 1.8.0, please use "SimplePie\SimplePie::set_cache_namefilter()" instead.', __METHOD__), \E_USER_DEPRECATED); + if (is_callable($function)) { $this->cache_name_function = $function; + + $this->set_cache_namefilter(new CallableNameFilter($this->cache_name_function)); } } @@ -1352,8 +1535,8 @@ class SimplePie // The default sanitize class gets set in the constructor, check if it has // changed. - if ($this->registry->get_class('Sanitize') !== 'SimplePie\Sanitize') { - $this->sanitize = $this->registry->create('Sanitize'); + if ($this->registry->get_class(Sanitize::class) !== 'SimplePie\Sanitize') { + $this->sanitize = $this->registry->create(Sanitize::class); } if (method_exists($this->sanitize, 'set_registry')) { $this->sanitize->set_registry($this->registry); @@ -1361,8 +1544,14 @@ class SimplePie // Pass whatever was set with config options over to the sanitizer. // Pass the classes in for legacy support; new classes should use the registry instead - $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache')); - $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen, $this->curl_options); + $this->sanitize->pass_cache_data( + $this->enable_cache, + $this->cache_location, + $this->cache_namefilter, + $this->registry->get_class(Cache::class), + $this->cache + ); + $this->sanitize->pass_file_data($this->registry->get_class(File::class), $this->timeout, $this->useragent, $this->force_fsockopen, $this->curl_options); if (!empty($this->multifeed_url)) { $i = 0; @@ -1391,12 +1580,11 @@ class SimplePie $cache = false; if ($this->feed_url !== null) { - $parsed_feed_url = $this->registry->call('Misc', 'parse_url', [$this->feed_url]); + $parsed_feed_url = $this->registry->call(Misc::class, 'parse_url', [$this->feed_url]); // Decide whether to enable caching - if ($this->cache && $parsed_feed_url['scheme'] !== '') { - $filename = $this->get_cache_filename($this->feed_url); - $cache = $this->registry->call('Cache', 'get_handler', [$this->cache_location, $filename, 'spc']); + if ($this->enable_cache && $parsed_feed_url['scheme'] !== '') { + $cache = $this->get_cache($this->feed_url); } // Fetch the data via \SimplePie\File into $this->raw_data @@ -1406,13 +1594,13 @@ class SimplePie return false; } - list($headers, $sniffed) = $fetched; + [$headers, $sniffed] = $fetched; } // Empty response check if (empty($this->raw_data)) { $this->error = "A feed could not be found at `$this->feed_url`. Empty body."; - $this->registry->call('Misc', 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); + $this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); return false; } @@ -1433,7 +1621,7 @@ class SimplePie if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) { $encodings[] = strtoupper($charset[1]); } - $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', [$this->raw_data, &$this->registry])); + $encodings = array_merge($encodings, $this->registry->call(Misc::class, 'xml_encoding', [$this->raw_data, &$this->registry])); $encodings[] = 'UTF-8'; } elseif (in_array($sniffed, $text_types) || substr($sniffed, 0, 5) === 'text/' && substr($sniffed, -4) === '+xml') { if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset)) { @@ -1448,7 +1636,7 @@ class SimplePie } // Fallback to XML 1.0 Appendix F.1/UTF-8/ISO-8859-1 - $encodings = array_merge($encodings, $this->registry->call('Misc', 'xml_encoding', [$this->raw_data, &$this->registry])); + $encodings = array_merge($encodings, $this->registry->call(Misc::class, 'xml_encoding', [$this->raw_data, &$this->registry])); $encodings[] = 'UTF-8'; $encodings[] = 'ISO-8859-1'; @@ -1458,16 +1646,16 @@ class SimplePie // Loop through each possible encoding, till we return something, or run out of possibilities foreach ($encodings as $encoding) { // Change the encoding to UTF-8 (as we always use UTF-8 internally) - if ($utf8_data = $this->registry->call('Misc', 'change_encoding', [$this->raw_data, $encoding, 'UTF-8'])) { + if ($utf8_data = $this->registry->call(Misc::class, 'change_encoding', [$this->raw_data, $encoding, 'UTF-8'])) { // Create new parser - $parser = $this->registry->create('Parser'); + $parser = $this->registry->create(Parser::class); // If it's parsed fine if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url)) { $this->data = $parser->get_data(); if (!($this->get_type() & ~self::TYPE_NONE)) { $this->error = "A feed could not be found at `$this->feed_url`. This does not appear to be a valid RSS or Atom feed."; - $this->registry->call('Misc', 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); + $this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); return false; } @@ -1477,7 +1665,8 @@ class SimplePie $this->data['build'] = \SimplePie\Misc::get_build(); // Cache the file if caching is enabled - if ($cache && !$cache->save($this)) { + $this->data['cache_expiration_time'] = $this->cache_duration + time(); + if ($cache && ! $cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->cache_duration)) { trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); } return true; @@ -1508,7 +1697,7 @@ class SimplePie } } - $this->registry->call('Misc', 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); + $this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); return false; } @@ -1517,19 +1706,35 @@ class SimplePie * Fetch the data via \SimplePie\File * * If the data is already cached, attempt to fetch it from there instead - * @param \SimplePie\Cache\Base|false $cache Cache handler, or false to not load from the cache + * @param Base|DataCache|false $cache 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 */ protected function fetch_data(&$cache) { + if (is_object($cache) && $cache instanceof Base) { + // @trigger_error(sprintf('Providing $cache as "\SimplePie\Cache\Base" in %s() is deprecated since SimplePie 1.8.0, please provide "\SimplePie\Cache\DataCache" implementation instead.', __METHOD__), \E_USER_DEPRECATED); + $cache = new BaseDataCache($cache); + } + + if ($cache !== false && ! $cache instanceof DataCache) { + throw new InvalidArgumentException(sprintf( + '%s(): Argument #1 ($cache) must be of type %s|false', + __METHOD__, + DataCache::class + ), 1); + } + + $cacheKey = $this->get_cache_filename($this->feed_url); + // If it's enabled, use the cache if ($cache) { // Load the Cache - $this->data = $cache->load(); + $this->data = $cache->get_data($cacheKey, []); + if (!empty($this->data)) { // If the cache is for an outdated build of SimplePie if (!isset($this->data['build']) || $this->data['build'] !== \SimplePie\Misc::get_build()) { - $cache->unlink(); + $cache->delete_data($cacheKey); $this->data = []; } // If we've hit a collision just rerun it with caching disabled @@ -1539,20 +1744,21 @@ class SimplePie } // If we've got a non feed_url stored (if the page isn't actually a feed, or is a redirect) use that URL. elseif (isset($this->data['feed_url'])) { - // If the autodiscovery cache is still valid use it. - if ($cache->mtime() + $this->autodiscovery_cache_duration > time()) { - // Do not need to do feed autodiscovery yet. - if ($this->data['feed_url'] !== $this->data['url']) { - $this->set_feed_url($this->data['feed_url']); - return $this->init(); - } + // Do not need to do feed autodiscovery yet. + if ($this->data['feed_url'] !== $this->data['url']) { + $this->set_feed_url($this->data['feed_url']); + $this->data['url'] = $this->data['feed_url']; + + $cache->set_data($this->get_cache_filename($this->feed_url), $this->data, $this->autodiscovery_cache_duration); - $cache->unlink(); - $this->data = []; + return $this->init(); } + + $cache->delete_data($this->get_cache_filename($this->feed_url)); + $this->data = []; } // Check if the cache has been updated - elseif ($cache->mtime() + $this->cache_duration < time()) { + elseif (isset($this->data['cache_expiration_time']) && $this->data['cache_expiration_time'] > time()) { // Want to know if we tried to send last-modified and/or etag headers // when requesting this file. (Note that it's up to the file to // support this, but we don't always send the headers either.) @@ -1568,7 +1774,7 @@ class SimplePie $headers['if-none-match'] = $this->data['headers']['etag']; } - $file = $this->registry->create('File', [$this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]); + $file = $this->registry->create(File::class, [$this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]); $this->status_code = $file->status_code; if ($file->success) { @@ -1576,13 +1782,13 @@ class SimplePie // Set raw_data to false here too, to signify that the cache // is still valid. $this->raw_data = false; - $cache->touch(); + $cache->set_data($cacheKey, $this->data, $this->cache_duration); return true; } } else { $this->check_modified = false; if ($this->force_cache_fallback) { - $cache->touch(); + $cache->set_data($cacheKey, $this->data, $this->cache_duration); return true; } @@ -1596,12 +1802,12 @@ class SimplePie return true; } } - // If the cache is empty, delete it + // If the cache is empty else { - $cache->unlink(); $this->data = []; } } + // If we don't already have the file (it'll only exist if we've opened it to check if the cache has been modified), open it. if (!isset($file)) { if ($this->file instanceof \SimplePie\File && $this->file->url === $this->feed_url) { @@ -1610,7 +1816,7 @@ class SimplePie $headers = [ 'Accept' => 'application/atom+xml, application/rss+xml, application/rdf+xml;q=0.9, application/xml;q=0.8, text/xml;q=0.8, text/html;q=0.7, unknown/unknown;q=0.1, application/unknown;q=0.1, */*;q=0.1', ]; - $file = $this->registry->create('File', [$this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]); + $file = $this->registry->create(File::class, [$this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options]); } } $this->status_code = $file->status_code; @@ -1623,7 +1829,7 @@ class SimplePie if (!$this->force_feed) { // Check if the supplied URL is a feed, if it isn't, look for it. - $locate = $this->registry->create('Locator', [&$file, $this->timeout, $this->useragent, $this->max_checked_feeds, $this->force_fsockopen, $this->curl_options]); + $locate = $this->registry->create(Locator::class, [&$file, $this->timeout, $this->useragent, $this->max_checked_feeds, $this->force_fsockopen, $this->curl_options]); if (!$locate->is_feed($file)) { $copyStatusCode = $file->status_code; @@ -1665,7 +1871,7 @@ class SimplePie // been called that object is untouched unset($file); $this->error = "A feed could not be found at `$this->feed_url`; the status code is `$copyStatusCode` and content-type is `$copyContentType`"; - $this->registry->call('Misc', 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); + $this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, __FILE__, __LINE__]); return false; } } @@ -1674,15 +1880,21 @@ class SimplePie unset($file); // This is usually because DOMDocument doesn't exist $this->error = $e->getMessage(); - $this->registry->call('Misc', 'error', [$this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()]); + $this->registry->call(Misc::class, 'error', [$this->error, E_USER_NOTICE, $e->getFile(), $e->getLine()]); return false; } + if ($cache) { - $this->data = ['url' => $this->feed_url, 'feed_url' => $file->url, 'build' => \SimplePie\Misc::get_build()]; - if (!$cache->save($this)) { + $this->data = [ + 'url' => $this->feed_url, + 'feed_url' => $file->url, + 'build' => \SimplePie\Misc::get_build(), + 'cache_expiration_time' => $this->cache_duration + time(), + ]; + + if (!$cache->set_data($cacheKey, $this->data, $this->cache_duration)) { trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); } - $cache = $this->registry->call('Cache', 'get_handler', [$this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc']); } } $this->feed_url = $file->url; @@ -1692,7 +1904,7 @@ class SimplePie $this->raw_data = $file->body; $this->permanent_url = $file->permanent_url; $headers = $file->headers; - $sniffer = $this->registry->create('Content_Type_Sniffer', [&$file]); + $sniffer = $this->registry->create(Sniffer::class, [&$file]); $sniffed = $sniffer->get_type(); return [$headers, $sniffed]; @@ -2096,7 +2308,7 @@ class SimplePie } catch (\SimplePie\Exception $e) { if (!$this->enable_exceptions) { $this->error = $e->getMessage(); - $this->registry->call('Misc', 'error', [$this->error, E_USER_WARNING, $e->getFile(), $e->getLine()]); + $this->registry->call(Misc::class, 'error', [$this->error, E_USER_WARNING, $e->getFile(), $e->getLine()]); return ''; } @@ -2115,9 +2327,9 @@ class SimplePie public function get_title() { if ($return = $this->get_channel_tags(self::NAMESPACE_ATOM_10, 'title')) { - return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); + return $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_ATOM_03, 'title')) { - return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); + return $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_RSS_10, 'title')) { return $this->sanitize($return[0]['data'], self::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_RSS_090, 'title')) { @@ -2175,7 +2387,7 @@ class SimplePie if (isset($category['attribs']['']['label'])) { $label = $this->sanitize($category['attribs']['']['label'], self::CONSTRUCT_TEXT); } - $categories[] = $this->registry->create('Category', [$term, $scheme, $label]); + $categories[] = $this->registry->create(Category::class, [$term, $scheme, $label]); } foreach ((array) $this->get_channel_tags(self::NAMESPACE_RSS_20, 'category') as $category) { // This is really the label, but keep this as the term also for BC. @@ -2186,13 +2398,13 @@ class SimplePie } else { $scheme = null; } - $categories[] = $this->registry->create('Category', [$term, $scheme, null]); + $categories[] = $this->registry->create(Category::class, [$term, $scheme, null]); } foreach ((array) $this->get_channel_tags(self::NAMESPACE_DC_11, 'subject') as $category) { - $categories[] = $this->registry->create('Category', [$this->sanitize($category['data'], self::CONSTRUCT_TEXT), null, null]); + $categories[] = $this->registry->create(Category::class, [$this->sanitize($category['data'], self::CONSTRUCT_TEXT), null, null]); } foreach ((array) $this->get_channel_tags(self::NAMESPACE_DC_10, 'subject') as $category) { - $categories[] = $this->registry->create('Category', [$this->sanitize($category['data'], self::CONSTRUCT_TEXT), null, null]); + $categories[] = $this->registry->create(Category::class, [$this->sanitize($category['data'], self::CONSTRUCT_TEXT), null, null]); } if (!empty($categories)) { @@ -2244,7 +2456,7 @@ class SimplePie $email = $this->sanitize($author['child'][self::NAMESPACE_ATOM_10]['email'][0]['data'], self::CONSTRUCT_TEXT); } if ($name !== null || $email !== null || $uri !== null) { - $authors[] = $this->registry->create('Author', [$name, $uri, $email]); + $authors[] = $this->registry->create(Author::class, [$name, $uri, $email]); } } if ($author = $this->get_channel_tags(self::NAMESPACE_ATOM_03, 'author')) { @@ -2261,17 +2473,17 @@ class SimplePie $email = $this->sanitize($author[0]['child'][self::NAMESPACE_ATOM_03]['email'][0]['data'], self::CONSTRUCT_TEXT); } if ($name !== null || $email !== null || $url !== null) { - $authors[] = $this->registry->create('Author', [$name, $url, $email]); + $authors[] = $this->registry->create(Author::class, [$name, $url, $email]); } } foreach ((array) $this->get_channel_tags(self::NAMESPACE_DC_11, 'creator') as $author) { - $authors[] = $this->registry->create('Author', [$this->sanitize($author['data'], self::CONSTRUCT_TEXT), null, null]); + $authors[] = $this->registry->create(Author::class, [$this->sanitize($author['data'], self::CONSTRUCT_TEXT), null, null]); } foreach ((array) $this->get_channel_tags(self::NAMESPACE_DC_10, 'creator') as $author) { - $authors[] = $this->registry->create('Author', [$this->sanitize($author['data'], self::CONSTRUCT_TEXT), null, null]); + $authors[] = $this->registry->create(Author::class, [$this->sanitize($author['data'], self::CONSTRUCT_TEXT), null, null]); } foreach ((array) $this->get_channel_tags(self::NAMESPACE_ITUNES, 'author') as $author) { - $authors[] = $this->registry->create('Author', [$this->sanitize($author['data'], self::CONSTRUCT_TEXT), null, null]); + $authors[] = $this->registry->create(Author::class, [$this->sanitize($author['data'], self::CONSTRUCT_TEXT), null, null]); } if (!empty($authors)) { @@ -2323,7 +2535,7 @@ class SimplePie $email = $this->sanitize($contributor['child'][self::NAMESPACE_ATOM_10]['email'][0]['data'], self::CONSTRUCT_TEXT); } if ($name !== null || $email !== null || $uri !== null) { - $contributors[] = $this->registry->create('Author', [$name, $uri, $email]); + $contributors[] = $this->registry->create(Author::class, [$name, $uri, $email]); } } foreach ((array) $this->get_channel_tags(self::NAMESPACE_ATOM_03, 'contributor') as $contributor) { @@ -2340,7 +2552,7 @@ class SimplePie $email = $this->sanitize($contributor['child'][self::NAMESPACE_ATOM_03]['email'][0]['data'], self::CONSTRUCT_TEXT); } if ($name !== null || $email !== null || $url !== null) { - $contributors[] = $this->registry->create('Author', [$name, $url, $email]); + $contributors[] = $this->registry->create(Author::class, [$name, $url, $email]); } } @@ -2426,7 +2638,7 @@ class SimplePie $keys = array_keys($this->data['links']); foreach ($keys as $key) { - if ($this->registry->call('Misc', 'is_isegment_nz_nc', [$key])) { + if ($this->registry->call(Misc::class, 'is_isegment_nz_nc', [$key])) { if (isset($this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key])) { $this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key] = array_merge($this->data['links'][$key], $this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key]); $this->data['links'][$key] =& $this->data['links'][self::IANA_LINK_RELATIONS_REGISTRY . $key]; @@ -2476,9 +2688,9 @@ class SimplePie public function get_description() { if ($return = $this->get_channel_tags(self::NAMESPACE_ATOM_10, 'subtitle')) { - return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); + return $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_ATOM_03, 'tagline')) { - return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); + return $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_RSS_10, 'description')) { return $this->sanitize($return[0]['data'], self::CONSTRUCT_MAYBE_HTML, $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_RSS_090, 'description')) { @@ -2509,9 +2721,9 @@ class SimplePie public function get_copyright() { if ($return = $this->get_channel_tags(self::NAMESPACE_ATOM_10, 'rights')) { - return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); + return $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_10_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_ATOM_03, 'copyright')) { - return $this->sanitize($return[0]['data'], $this->registry->call('Misc', 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); + return $this->sanitize($return[0]['data'], $this->registry->call(Misc::class, 'atom_03_construct_type', [$return[0]['attribs']]), $this->get_base($return[0])); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_RSS_20, 'copyright')) { return $this->sanitize($return[0]['data'], self::CONSTRUCT_TEXT); } elseif ($return = $this->get_channel_tags(self::NAMESPACE_DC_11, 'rights')) { @@ -2686,17 +2898,17 @@ class SimplePie * * RSS 2.0 feeds are allowed to have a "feed logo" width. * - * Uses `<image><width>` or defaults to 88.0 if no width is specified and + * Uses `<image><width>` or defaults to 88 if no width is specified and * the feed is an RSS 2.0 feed. * - * @return int|float|null + * @return int|null */ public function get_image_width() { if ($return = $this->get_image_tags(self::NAMESPACE_RSS_20, 'width')) { - return round($return[0]['data']); + return intval($return[0]['data']); } elseif ($this->get_type() & self::TYPE_RSS_SYNDICATION && $this->get_image_tags(self::NAMESPACE_RSS_20, 'url')) { - return 88.0; + return 88; } return null; @@ -2707,17 +2919,17 @@ class SimplePie * * RSS 2.0 feeds are allowed to have a "feed logo" height. * - * Uses `<image><height>` or defaults to 31.0 if no height is specified and + * Uses `<image><height>` or defaults to 31 if no height is specified and * the feed is an RSS 2.0 feed. * - * @return int|float|null + * @return int|null */ public function get_image_height() { if ($return = $this->get_image_tags(self::NAMESPACE_RSS_20, 'height')) { - return round($return[0]['data']); + return intval($return[0]['data']); } elseif ($this->get_type() & self::TYPE_RSS_SYNDICATION && $this->get_image_tags(self::NAMESPACE_RSS_20, 'url')) { - return 31.0; + return 31; } return null; @@ -2792,31 +3004,31 @@ class SimplePie if ($items = $this->get_feed_tags(self::NAMESPACE_ATOM_10, 'entry')) { $keys = array_keys($items); foreach ($keys as $key) { - $this->data['items'][] = $this->registry->create('Item', [$this, $items[$key]]); + $this->data['items'][] = $this->registry->create(Item::class, [$this, $items[$key]]); } } if ($items = $this->get_feed_tags(self::NAMESPACE_ATOM_03, 'entry')) { $keys = array_keys($items); foreach ($keys as $key) { - $this->data['items'][] = $this->registry->create('Item', [$this, $items[$key]]); + $this->data['items'][] = $this->registry->create(Item::class, [$this, $items[$key]]); } } if ($items = $this->get_feed_tags(self::NAMESPACE_RSS_10, 'item')) { $keys = array_keys($items); foreach ($keys as $key) { - $this->data['items'][] = $this->registry->create('Item', [$this, $items[$key]]); + $this->data['items'][] = $this->registry->create(Item::class, [$this, $items[$key]]); } } if ($items = $this->get_feed_tags(self::NAMESPACE_RSS_090, 'item')) { $keys = array_keys($items); foreach ($keys as $key) { - $this->data['items'][] = $this->registry->create('Item', [$this, $items[$key]]); + $this->data['items'][] = $this->registry->create(Item::class, [$this, $items[$key]]); } } if ($items = $this->get_channel_tags(self::NAMESPACE_RSS_20, 'item')) { $keys = array_keys($items); foreach ($keys as $key) { - $this->data['items'][] = $this->registry->create('Item', [$this, $items[$key]]); + $this->data['items'][] = $this->registry->create(Item::class, [$this, $items[$key]]); } } } @@ -2849,8 +3061,7 @@ class SimplePie */ public function set_favicon_handler($page = false, $qs = 'i') { - $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; - trigger_error('Favicon handling has been removed, please use your own handling', $level); + trigger_error('Favicon handling has been removed, please use your own handling', \E_USER_DEPRECATED); return false; } @@ -2861,8 +3072,7 @@ class SimplePie */ public function get_favicon() { - $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; - trigger_error('Favicon handling has been removed, please use your own handling', $level); + trigger_error('Favicon handling has been removed, please use your own handling', \E_USER_DEPRECATED); if (($url = $this->get_link()) !== null) { return 'https://www.google.com/s2/favicons?domain=' . urlencode($url); @@ -2881,13 +3091,11 @@ class SimplePie public function __call($method, $args) { if (strpos($method, 'subscribe_') === 0) { - $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; - trigger_error('subscribe_*() has been deprecated, implement the callback yourself', $level); + trigger_error('subscribe_*() has been deprecated, implement the callback yourself', \E_USER_DEPRECATED); return ''; } if ($method === 'enable_xml_dump') { - $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING; - trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', $level); + trigger_error('enable_xml_dump() has been deprecated, use get_raw_data() instead', \E_USER_DEPRECATED); return false; } @@ -2992,6 +3200,29 @@ class SimplePie } } } + + /** + * Get a DataCache + * + * @param string $feed_url Only needed for BC, can be removed in SimplePie 2.0.0 + * + * @return DataCache + */ + private function get_cache($feed_url = '') + { + if ($this->cache === null) { + // @trigger_error(sprintf('Not providing as PSR-16 cache implementation is deprecated since SimplePie 1.8.0, please use "SimplePie\SimplePie::set_cache()".'), \E_USER_DEPRECATED); + $cache = $this->registry->call(Cache::class, 'get_handler', [ + $this->cache_location, + $this->get_cache_filename($feed_url), + Base::TYPE_FEED + ]); + + return new BaseDataCache($cache); + } + + return $this->cache; + } } class_alias('SimplePie\SimplePie', 'SimplePie'); |