From ea0e463cc71eb1e8145a1f5aa6733e93af01c528 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 27 Sep 2022 12:41:39 +0100 Subject: [PATCH] MDL-75467 libraries: upgrade to version 1.6.0 of SimplePie. --- lib/simplepie/README.markdown | 5 +- lib/simplepie/autoloader.php | 2 + lib/simplepie/library/SimplePie.php | 115 ++++++++++++++-- lib/simplepie/library/SimplePie/Author.php | 2 + lib/simplepie/library/SimplePie/Cache.php | 2 + .../library/SimplePie/Cache/Base.php | 2 + lib/simplepie/library/SimplePie/Cache/DB.php | 2 + .../library/SimplePie/Cache/File.php | 2 + .../library/SimplePie/Cache/Memcache.php | 2 + .../library/SimplePie/Cache/Memcached.php | 2 + .../library/SimplePie/Cache/MySQL.php | 4 +- .../library/SimplePie/Cache/Redis.php | 4 +- lib/simplepie/library/SimplePie/Caption.php | 2 + lib/simplepie/library/SimplePie/Category.php | 3 +- .../SimplePie/Content/Type/Sniffer.php | 2 + lib/simplepie/library/SimplePie/Copyright.php | 2 + lib/simplepie/library/SimplePie/Credit.php | 2 + lib/simplepie/library/SimplePie/Enclosure.php | 9 +- lib/simplepie/library/SimplePie/Exception.php | 4 +- lib/simplepie/library/SimplePie/File.php | 5 +- .../library/SimplePie/HTTP/Parser.php | 12 +- lib/simplepie/library/SimplePie/IRI.php | 2 + lib/simplepie/library/SimplePie/Item.php | 13 +- lib/simplepie/library/SimplePie/Locator.php | 14 +- lib/simplepie/library/SimplePie/Misc.php | 12 ++ lib/simplepie/library/SimplePie/Net/IPv6.php | 2 + .../library/SimplePie/Parse/Date.php | 2 + lib/simplepie/library/SimplePie/Parser.php | 26 +++- lib/simplepie/library/SimplePie/Rating.php | 2 + lib/simplepie/library/SimplePie/Registry.php | 5 +- .../library/SimplePie/Restriction.php | 2 + lib/simplepie/library/SimplePie/Sanitize.php | 129 +++++++++++++++++- lib/simplepie/library/SimplePie/Source.php | 2 + .../SimplePie/XML/Declaration/Parser.php | 2 + lib/simplepie/library/SimplePie/gzdecode.php | 2 + lib/simplepie/readme_moodle.txt | 3 +- lib/thirdpartylibs.xml | 2 +- 37 files changed, 364 insertions(+), 41 deletions(-) mode change 100644 => 100755 lib/simplepie/library/SimplePie.php mode change 100644 => 100755 lib/simplepie/library/SimplePie/Cache/Memcached.php mode change 100644 => 100755 lib/simplepie/library/SimplePie/Registry.php diff --git a/lib/simplepie/README.markdown b/lib/simplepie/README.markdown index 5522b7b7222..f54b077361d 100644 --- a/lib/simplepie/README.markdown +++ b/lib/simplepie/README.markdown @@ -38,8 +38,9 @@ What comes in the package? Since SimplePie 1.3, we've split the classes into separate files to make it easier to maintain and use. -If you'd like a single monolithic file, you can run `php build/compile.php` to -generate `SimplePie.compiled.php`. +If you'd like a single monolithic file, see the assets in the +[releases](https://github.com/simplepie/simplepie/releases), or you can +run `php build/compile.php` to generate `SimplePie.compiled.php` yourself. To start the demo ----------------- diff --git a/lib/simplepie/autoloader.php b/lib/simplepie/autoloader.php index e42f07b3aa0..bf34a700348 100644 --- a/lib/simplepie/autoloader.php +++ b/lib/simplepie/autoloader.php @@ -58,6 +58,8 @@ if (!class_exists('SimplePie')) */ class SimplePie_Autoloader { + protected $path; + /** * Constructor */ diff --git a/lib/simplepie/library/SimplePie.php b/lib/simplepie/library/SimplePie.php old mode 100644 new mode 100755 index a6a5a9e137c..2ae78c3593a --- a/lib/simplepie/library/SimplePie.php +++ b/lib/simplepie/library/SimplePie.php @@ -33,7 +33,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * @package SimplePie - * @version 1.5.6 + * @version 1.6.0 * @copyright 2004-2017 Ryan Parman, Sam Sneddon, Ryan McCue * @author Ryan Parman * @author Sam Sneddon @@ -50,7 +50,7 @@ define('SIMPLEPIE_NAME', 'SimplePie'); /** * SimplePie Version */ -define('SIMPLEPIE_VERSION', '1.5.6'); +define('SIMPLEPIE_VERSION', '1.6.0'); /** * SimplePie Build @@ -424,6 +424,13 @@ class SimplePie */ public $error; + /** + * @var int HTTP status code + * @see SimplePie::status_code() + * @access private + */ + public $status_code; + /** * @var object Instance of SimplePie_Sanitize (or other class) * @see SimplePie::set_sanitize_class() @@ -643,6 +650,13 @@ class SimplePie */ public $strip_htmltags = array('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() + * @access private + */ + public $rename_attributes = array(); + /** * @var bool Should we throw exceptions, or use the old-style error property? * @access private @@ -908,6 +922,39 @@ class SimplePie $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' : ''; + $options = array(); + if ($this->timeout != 10) + { + $options[CURLOPT_TIMEOUT] = $this->timeout; + } + if ($this->useragent !== SIMPLEPIE_USERAGENT) + { + $options[CURLOPT_USERAGENT] = $this->useragent; + } + if (!empty($this->curl_options)) + { + foreach ($this->curl_options as $k => $v) + { + $options[$k] = $v; + } + } + if (!empty($options)) + { + ksort($options); + $url .= '#' . urlencode(var_export($options, true)); + } + return call_user_func($this->cache_name_function, $url); + } + /** * Set whether feed items should be sorted into reverse chronological order * @@ -1146,6 +1193,7 @@ class SimplePie $this->strip_attributes(false); $this->add_attributes(false); $this->set_image_handler(false); + $this->set_https_domains(array()); } } @@ -1182,6 +1230,15 @@ class SimplePie $this->sanitize->encode_instead_of_strip($enable); } + public function rename_attributes($attribs = '') + { + if ($attribs === '') + { + $attribs = $this->rename_attributes; + } + $this->sanitize->rename_attributes($attribs); + } + public function strip_attributes($attribs = '') { if ($attribs === '') @@ -1248,6 +1305,19 @@ class SimplePie $this->sanitize->set_url_replacements($element_attribute); } + /** + * Set the list of domains for which to force HTTPS. + * @see SimplePie_Sanitize::set_https_domains() + * @param array List of HTTPS domains. Example array('biz', 'example.com', 'example.org', 'www.example.net'). + */ + public function set_https_domains($domains = array()) + { + if (is_array($domains)) + { + $this->sanitize->set_https_domains($domains); + } + } + /** * Set the handler to enable the display of cached images. * @@ -1373,8 +1443,8 @@ class SimplePie // Decide whether to enable caching if ($this->cache && $parsed_feed_url['scheme'] !== '') { - $url = $this->feed_url . ($this->force_feed ? '#force_feed' : ''); - $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $url), 'spc')); + $filename = $this->get_cache_filename($this->feed_url); + $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, $filename, 'spc')); } // Fetch the data via SimplePie_File into $this->raw_data @@ -1514,7 +1584,7 @@ class SimplePie * Fetch the data via SimplePie_File * * If the data is already cached, attempt to fetch it from there instead - * @param SimplePie_Cache|false $cache Cache handler, or false to not load from the cache + * @param SimplePie_Cache_Base|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) @@ -1577,6 +1647,7 @@ class SimplePie } $file = $this->registry->create('File', array($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) { @@ -1631,6 +1702,8 @@ class SimplePie $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); } } + $this->status_code = $file->status_code; + // If the file connection has an error, set SimplePie::error to that and quit if (!$file->success && !($file->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($file->status_code === 200 || $file->status_code > 206 && $file->status_code < 300))) { @@ -1728,7 +1801,7 @@ class SimplePie } /** - * Get the error message for the occured error + * Get the error message for the occurred error * * @return string|array Error message, or array of messages for multifeeds */ @@ -1737,6 +1810,16 @@ class SimplePie return $this->error; } + /** + * Get the last HTTP status code + * + * @return int Status code + */ + public function status_code() + { + return $this->status_code; + } + /** * Get the raw XML * @@ -2132,7 +2215,7 @@ class SimplePie */ public function get_base($element = array()) { - if (!($this->get_type() & SIMPLEPIE_TYPE_RSS_SYNDICATION) && !empty($element['xml_base_explicit']) && isset($element['xml_base'])) + if (!empty($element['xml_base_explicit']) && isset($element['xml_base'])) { return $element['xml_base']; } @@ -2580,13 +2663,19 @@ class SimplePie } } - if (isset($this->data['headers']['link']) && - preg_match('/<([^>]+)>; rel='.preg_quote($rel).'/', - $this->data['headers']['link'], $match)) + if (isset($this->data['headers']['link'])) { - return array($match[1]); + $link_headers = $this->data['headers']['link']; + if (is_string($link_headers)) { + $link_headers = array($link_headers); + } + $matches = preg_filter('/<([^>]+)>; rel='.preg_quote($rel).'/', '$1', $link_headers); + if (!empty($matches)) { + return $matches; + } } - else if (isset($this->data['links'][$rel])) + + if (isset($this->data['links'][$rel])) { return $this->data['links'][$rel]; } @@ -3243,3 +3332,5 @@ class SimplePie } } } + +class_alias('SimplePie', 'SimplePie\SimplePie', false); diff --git a/lib/simplepie/library/SimplePie/Author.php b/lib/simplepie/library/SimplePie/Author.php index 563932f4c62..3baadee6293 100644 --- a/lib/simplepie/library/SimplePie/Author.php +++ b/lib/simplepie/library/SimplePie/Author.php @@ -147,3 +147,5 @@ class SimplePie_Author return null; } } + +class_alias('SimplePie_Author', 'SimplePie\Author', false); diff --git a/lib/simplepie/library/SimplePie/Cache.php b/lib/simplepie/library/SimplePie/Cache.php index 9c5577d9566..88d811660a9 100644 --- a/lib/simplepie/library/SimplePie/Cache.php +++ b/lib/simplepie/library/SimplePie/Cache.php @@ -132,3 +132,5 @@ class SimplePie_Cache return $params; } } + +class_alias('SimplePie_Cache', 'SimplePie\Cache', false); diff --git a/lib/simplepie/library/SimplePie/Cache/Base.php b/lib/simplepie/library/SimplePie/Cache/Base.php index 522ff7e10e8..29eb0594bb7 100644 --- a/lib/simplepie/library/SimplePie/Cache/Base.php +++ b/lib/simplepie/library/SimplePie/Cache/Base.php @@ -111,3 +111,5 @@ interface SimplePie_Cache_Base */ public function unlink(); } + +class_alias('SimplePie_Cache_Base', 'SimplePie\Cache\Base', false); diff --git a/lib/simplepie/library/SimplePie/Cache/DB.php b/lib/simplepie/library/SimplePie/Cache/DB.php index 74d57b8da7d..3dca8e5db63 100644 --- a/lib/simplepie/library/SimplePie/Cache/DB.php +++ b/lib/simplepie/library/SimplePie/Cache/DB.php @@ -134,3 +134,5 @@ abstract class SimplePie_Cache_DB implements SimplePie_Cache_Base return array(serialize($data->data), $items_by_id); } } + +class_alias('SimplePie_Cache_DB', 'SimplePie\Cache\DB', false); diff --git a/lib/simplepie/library/SimplePie/Cache/File.php b/lib/simplepie/library/SimplePie/Cache/File.php index 03758e923bd..db30e7a0fe1 100644 --- a/lib/simplepie/library/SimplePie/Cache/File.php +++ b/lib/simplepie/library/SimplePie/Cache/File.php @@ -162,3 +162,5 @@ class SimplePie_Cache_File implements SimplePie_Cache_Base return false; } } + +class_alias('SimplePie_Cache_File', 'SimplePie\Cache\File', false); diff --git a/lib/simplepie/library/SimplePie/Cache/Memcache.php b/lib/simplepie/library/SimplePie/Cache/Memcache.php index caf785275a9..2cc37f90776 100644 --- a/lib/simplepie/library/SimplePie/Cache/Memcache.php +++ b/lib/simplepie/library/SimplePie/Cache/Memcache.php @@ -178,3 +178,5 @@ class SimplePie_Cache_Memcache implements SimplePie_Cache_Base return $this->cache->delete($this->name, 0); } } + +class_alias('SimplePie_Cache_Memcache', 'SimplePie\Cache\Memcache', false); diff --git a/lib/simplepie/library/SimplePie/Cache/Memcached.php b/lib/simplepie/library/SimplePie/Cache/Memcached.php old mode 100644 new mode 100755 index 0b40d87c80a..32a53eb7b63 --- a/lib/simplepie/library/SimplePie/Cache/Memcached.php +++ b/lib/simplepie/library/SimplePie/Cache/Memcached.php @@ -164,3 +164,5 @@ class SimplePie_Cache_Memcached implements SimplePie_Cache_Base return false; } } + +class_alias('SimplePie_Cache_Memcached', 'SimplePie\Cache\Memcached', false); diff --git a/lib/simplepie/library/SimplePie/Cache/MySQL.php b/lib/simplepie/library/SimplePie/Cache/MySQL.php index a684eb83344..d21e2b6e4cc 100644 --- a/lib/simplepie/library/SimplePie/Cache/MySQL.php +++ b/lib/simplepie/library/SimplePie/Cache/MySQL.php @@ -278,7 +278,7 @@ class SimplePie_Cache_MySQL extends SimplePie_Cache_DB $query->bindValue(':data', serialize($data)); $query->bindValue(':time', time()); $query->bindValue(':feed', $this->id); - if ($this->execute()) + if ($query->execute()) { return true; } @@ -438,3 +438,5 @@ class SimplePie_Cache_MySQL extends SimplePie_Cache_DB return $query->execute() && $query2->execute(); } } + +class_alias('SimplePie_Cache_MySQL', 'SimplePie\Cache\MySQL', false); diff --git a/lib/simplepie/library/SimplePie/Cache/Redis.php b/lib/simplepie/library/SimplePie/Cache/Redis.php index dbc88e829a7..82d759b0147 100644 --- a/lib/simplepie/library/SimplePie/Cache/Redis.php +++ b/lib/simplepie/library/SimplePie/Cache/Redis.php @@ -152,7 +152,7 @@ class SimplePie_Cache_Redis implements SimplePie_Cache_Base { if ($data !== false) { $return = $this->cache->set($this->name, $data); if ($this->options['expire']) { - return $this->cache->expire($this->name, $this->ttl); + return $this->cache->expire($this->name, $this->options['expire']); } return $return; } @@ -170,3 +170,5 @@ class SimplePie_Cache_Redis implements SimplePie_Cache_Base { } } + +class_alias('SimplePie_Cache_Redis', 'SimplePie\Cache\Redis', false); diff --git a/lib/simplepie/library/SimplePie/Caption.php b/lib/simplepie/library/SimplePie/Caption.php index 3d7bfdd7164..355ab52f39c 100644 --- a/lib/simplepie/library/SimplePie/Caption.php +++ b/lib/simplepie/library/SimplePie/Caption.php @@ -196,3 +196,5 @@ class SimplePie_Caption return null; } } + +class_alias('SimplePie_Caption', 'SimplePie\Caption', false); diff --git a/lib/simplepie/library/SimplePie/Category.php b/lib/simplepie/library/SimplePie/Category.php index e4dabed8b13..02cb764824f 100644 --- a/lib/simplepie/library/SimplePie/Category.php +++ b/lib/simplepie/library/SimplePie/Category.php @@ -79,7 +79,7 @@ class SimplePie_Category /** * Category type - * + * * category for * subject for * @@ -161,3 +161,4 @@ class SimplePie_Category } } +class_alias('SimplePie_Category', 'SimplePie\Category', false); diff --git a/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php b/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php index 027e131ef9c..b3a8cf37899 100644 --- a/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php +++ b/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php @@ -316,3 +316,5 @@ class SimplePie_Content_Type_Sniffer return 'text/html'; } } + +class_alias('SimplePie_Content_Type_Sniffer', 'SimplePie\Content\Type\Sniffer', false); diff --git a/lib/simplepie/library/SimplePie/Copyright.php b/lib/simplepie/library/SimplePie/Copyright.php index 92f9b09471d..e043ced8b3b 100644 --- a/lib/simplepie/library/SimplePie/Copyright.php +++ b/lib/simplepie/library/SimplePie/Copyright.php @@ -122,3 +122,5 @@ class SimplePie_Copyright return null; } } + +class_alias('SimplePie_Copyright', 'SimplePie\Copyright', false); diff --git a/lib/simplepie/library/SimplePie/Credit.php b/lib/simplepie/library/SimplePie/Credit.php index d6ff07eba65..347902e027a 100644 --- a/lib/simplepie/library/SimplePie/Credit.php +++ b/lib/simplepie/library/SimplePie/Credit.php @@ -146,3 +146,5 @@ class SimplePie_Credit return null; } } + +class_alias('SimplePie_Credit', 'SimplePie\Credit', false); diff --git a/lib/simplepie/library/SimplePie/Enclosure.php b/lib/simplepie/library/SimplePie/Enclosure.php index 32216d848cb..71cdd7d455e 100644 --- a/lib/simplepie/library/SimplePie/Enclosure.php +++ b/lib/simplepie/library/SimplePie/Enclosure.php @@ -1152,7 +1152,12 @@ class SimplePie_Enclosure // If we encounter an unsupported mime-type, check the file extension and guess intelligently. if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3))) { - switch (strtolower($this->get_extension())) + $extension = $this->get_extension(); + if ($extension === null) { + return null; + } + + switch (strtolower($extension)) { // Audio mime-types case 'aac': @@ -1302,3 +1307,5 @@ class SimplePie_Enclosure return $type; } } + +class_alias('SimplePie_Enclosure', 'SimplePie\Enclosure', false); diff --git a/lib/simplepie/library/SimplePie/Exception.php b/lib/simplepie/library/SimplePie/Exception.php index 7a04c560cc7..715cefc72bc 100644 --- a/lib/simplepie/library/SimplePie/Exception.php +++ b/lib/simplepie/library/SimplePie/Exception.php @@ -48,4 +48,6 @@ */ class SimplePie_Exception extends Exception { -} \ No newline at end of file +} + +class_alias('SimplePie_Exception', 'SimplePie\Exception', false); diff --git a/lib/simplepie/library/SimplePie/File.php b/lib/simplepie/library/SimplePie/File.php index 90ad8196a67..7f894fb5937 100644 --- a/lib/simplepie/library/SimplePie/File.php +++ b/lib/simplepie/library/SimplePie/File.php @@ -106,7 +106,7 @@ class SimplePie_File curl_setopt($fp, CURLOPT_FAILONERROR, 1); curl_setopt($fp, CURLOPT_TIMEOUT, $timeout); curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout); - curl_setopt($fp, CURLOPT_REFERER, $url); + curl_setopt($fp, CURLOPT_REFERER, SimplePie_Misc::url_remove_credentials($url)); curl_setopt($fp, CURLOPT_USERAGENT, $useragent); curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2); foreach ($curl_options as $curl_param => $curl_value) { @@ -119,6 +119,7 @@ class SimplePie_File curl_setopt($fp, CURLOPT_ENCODING, 'none'); $this->headers = curl_exec($fp); } + $this->status_code = curl_getinfo($fp, CURLINFO_HTTP_CODE); if (curl_errno($fp)) { $this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp); @@ -298,3 +299,5 @@ class SimplePie_File } } } + +class_alias('SimplePie_File', 'SimplePie\File', false); diff --git a/lib/simplepie/library/SimplePie/HTTP/Parser.php b/lib/simplepie/library/SimplePie/HTTP/Parser.php index 1dbe06c3e32..b0f0f4a8be0 100644 --- a/lib/simplepie/library/SimplePie/HTTP/Parser.php +++ b/lib/simplepie/library/SimplePie/HTTP/Parser.php @@ -507,12 +507,16 @@ class SimplePie_HTTP_Parser { $data = explode("\r\n\r\n", $headers, $count); $data = array_pop($data); - if (false !== stripos($data, "HTTP/1.0 200 Connection established\r\n\r\n")) { - $data = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $data); + if (false !== stripos($data, "HTTP/1.0 200 Connection established\r\n")) { + $exploded = explode("\r\n\r\n", $data, 2); + $data = end($exploded); } - if (false !== stripos($data, "HTTP/1.1 200 Connection established\r\n\r\n")) { - $data = str_ireplace("HTTP/1.1 200 Connection established\r\n\r\n", '', $data); + if (false !== stripos($data, "HTTP/1.1 200 Connection established\r\n")) { + $exploded = explode("\r\n\r\n", $data, 2); + $data = end($exploded); } return $data; } } + +class_alias('SimplePie_HTTP_Parser', 'SimplePie\HTTP\Parser', false); diff --git a/lib/simplepie/library/SimplePie/IRI.php b/lib/simplepie/library/SimplePie/IRI.php index a02de682c5b..6cd27ddba56 100644 --- a/lib/simplepie/library/SimplePie/IRI.php +++ b/lib/simplepie/library/SimplePie/IRI.php @@ -1234,3 +1234,5 @@ class SimplePie_IRI return $iauthority; } } + +class_alias('SimplePie_IRI', 'SimplePie\IRI', false); diff --git a/lib/simplepie/library/SimplePie/Item.php b/lib/simplepie/library/SimplePie/Item.php index 5be6b199409..02f158bfc60 100644 --- a/lib/simplepie/library/SimplePie/Item.php +++ b/lib/simplepie/library/SimplePie/Item.php @@ -1803,7 +1803,7 @@ class SimplePie_Item } if (isset($content['attribs']['']['fileSize'])) { - $length = ceil($content['attribs']['']['fileSize']); + $length = intval($content['attribs']['']['fileSize']); } if (isset($content['attribs']['']['medium'])) { @@ -2425,7 +2425,7 @@ class SimplePie_Item } if (isset($content['attribs']['']['fileSize'])) { - $length = ceil($content['attribs']['']['fileSize']); + $length = intval($content['attribs']['']['fileSize']); } if (isset($content['attribs']['']['medium'])) { @@ -2790,7 +2790,7 @@ class SimplePie_Item } if (isset($link['attribs']['']['length'])) { - $length = ceil($link['attribs']['']['length']); + $length = intval($link['attribs']['']['length']); } if (isset($link['attribs']['']['title'])) { @@ -2833,7 +2833,7 @@ class SimplePie_Item } if (isset($link['attribs']['']['length'])) { - $length = ceil($link['attribs']['']['length']); + $length = intval($link['attribs']['']['length']); } // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor @@ -2862,13 +2862,14 @@ class SimplePie_Item $width = null; $url = $this->sanitize($enclosure[0]['attribs']['']['url'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($enclosure[0])); + $url = $this->feed->sanitize->https_url($url); if (isset($enclosure[0]['attribs']['']['type'])) { $type = $this->sanitize($enclosure[0]['attribs']['']['type'], SIMPLEPIE_CONSTRUCT_TEXT); } if (isset($enclosure[0]['attribs']['']['length'])) { - $length = ceil($enclosure[0]['attribs']['']['length']); + $length = intval($enclosure[0]['attribs']['']['length']); } // Since we don't have group or content for these, we'll just pass the '*_parent' variables directly to the constructor @@ -2964,3 +2965,5 @@ class SimplePie_Item return null; } } + +class_alias('SimplePie_Item', 'SimplePie\Item', false); diff --git a/lib/simplepie/library/SimplePie/Locator.php b/lib/simplepie/library/SimplePie/Locator.php index a207df6feeb..12961dd3dc7 100644 --- a/lib/simplepie/library/SimplePie/Locator.php +++ b/lib/simplepie/library/SimplePie/Locator.php @@ -64,6 +64,7 @@ class SimplePie_Locator var $max_checked_feeds = 10; var $force_fsockopen = false; var $curl_options = array(); + var $dom; protected $registry; public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10, $force_fsockopen = false, $curl_options = array()) @@ -75,12 +76,19 @@ class SimplePie_Locator $this->force_fsockopen = $force_fsockopen; $this->curl_options = $curl_options; - if (class_exists('DOMDocument')) + if (class_exists('DOMDocument') && $this->file->body != '') { $this->dom = new DOMDocument(); set_error_handler(array('SimplePie_Misc', 'silence_errors')); - $this->dom->loadHTML($this->file->body); + try + { + $this->dom->loadHTML($this->file->body); + } + catch (Throwable $ex) + { + $this->dom = null; + } restore_error_handler(); } else @@ -422,3 +430,5 @@ class SimplePie_Locator return null; } } + +class_alias('SimplePie_Locator', 'SimplePie\Locator', false); diff --git a/lib/simplepie/library/SimplePie/Misc.php b/lib/simplepie/library/SimplePie/Misc.php index a52498ac763..4318573bae6 100644 --- a/lib/simplepie/library/SimplePie/Misc.php +++ b/lib/simplepie/library/SimplePie/Misc.php @@ -2260,4 +2260,16 @@ function embed_wmedia(width, height, link) { { // No-op } + + /** + * Sanitize a URL by removing HTTP credentials. + * @param string $url the URL to sanitize. + * @return string the same URL without HTTP credentials. + */ + public static function url_remove_credentials($url) + { + return preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url); + } } + +class_alias('SimplePie_Misc', 'SimplePie\Misc', false); diff --git a/lib/simplepie/library/SimplePie/Net/IPv6.php b/lib/simplepie/library/SimplePie/Net/IPv6.php index 25c992bd147..c7e466a54af 100644 --- a/lib/simplepie/library/SimplePie/Net/IPv6.php +++ b/lib/simplepie/library/SimplePie/Net/IPv6.php @@ -267,3 +267,5 @@ class SimplePie_Net_IPv6 return self::check_ipv6($ip); } } + +class_alias('SimplePie_Net_IPv6', 'SimplePie\Net\IPv6', false); diff --git a/lib/simplepie/library/SimplePie/Parse/Date.php b/lib/simplepie/library/SimplePie/Parse/Date.php index cf57437d2e4..fe7e3ea4961 100644 --- a/lib/simplepie/library/SimplePie/Parse/Date.php +++ b/lib/simplepie/library/SimplePie/Parse/Date.php @@ -1023,3 +1023,5 @@ class SimplePie_Parse_Date return $strtotime; } } + +class_alias('SimplePie_Parse_Date', 'SimplePie\Parse\Date', false); diff --git a/lib/simplepie/library/SimplePie/Parser.php b/lib/simplepie/library/SimplePie/Parser.php index 4efdf41a710..65f32d72a3c 100644 --- a/lib/simplepie/library/SimplePie/Parser.php +++ b/lib/simplepie/library/SimplePie/Parser.php @@ -164,12 +164,30 @@ class SimplePie_Parser xml_set_element_handler($xml, 'tag_open', 'tag_close'); // Parse! - if (!xml_parse($xml, $data, true)) + $wrapper = @is_writable(sys_get_temp_dir()) ? 'php://temp' : 'php://memory'; + if (($stream = fopen($wrapper, 'r+')) && + fwrite($stream, $data) && + rewind($stream)) + { + //Parse by chunks not to use too much memory + do + { + $stream_data = fread($stream, 1048576); + if (!xml_parse($xml, $stream_data === false ? '' : $stream_data, feof($stream))) + { + $this->error_code = xml_get_error_code($xml); + $this->error_string = xml_error_string($this->error_code); + $return = false; + break; + } + } while (!feof($stream)); + fclose($stream); + } + else { - $this->error_code = xml_get_error_code($xml); - $this->error_string = xml_error_string($this->error_code); $return = false; } + $this->current_line = xml_get_current_line_number($xml); $this->current_column = xml_get_current_column_number($xml); $this->current_byte = xml_get_current_byte_index($xml); @@ -659,3 +677,5 @@ class SimplePie_Parser return ' ]>'; } } + +class_alias('SimplePie_Parser', 'SimplePie\Parser', false); diff --git a/lib/simplepie/library/SimplePie/Rating.php b/lib/simplepie/library/SimplePie/Rating.php index 599f75acbbe..eae6718a753 100644 --- a/lib/simplepie/library/SimplePie/Rating.php +++ b/lib/simplepie/library/SimplePie/Rating.php @@ -122,3 +122,5 @@ class SimplePie_Rating return null; } } + +class_alias('SimplePie_Rating', 'SimplePie\Rating', false); diff --git a/lib/simplepie/library/SimplePie/Registry.php b/lib/simplepie/library/SimplePie/Registry.php old mode 100644 new mode 100755 index bf3baf17939..2486f3c69d9 --- a/lib/simplepie/library/SimplePie/Registry.php +++ b/lib/simplepie/library/SimplePie/Registry.php @@ -208,7 +208,8 @@ class SimplePie_Registry { case 'Cache': // For backwards compatibility with old non-static - // Cache::create() methods + // Cache::create() methods in PHP < 8.0. + // No longer supported as of PHP 8.0. if ($method === 'get_handler') { $result = @call_user_func_array(array($class, 'create'), $parameters); @@ -222,3 +223,5 @@ class SimplePie_Registry return $result; } } + +class_alias('SimplePie_Registry', 'SimplePie\Registry', false); diff --git a/lib/simplepie/library/SimplePie/Restriction.php b/lib/simplepie/library/SimplePie/Restriction.php index 950017fae98..0a168bbbe73 100644 --- a/lib/simplepie/library/SimplePie/Restriction.php +++ b/lib/simplepie/library/SimplePie/Restriction.php @@ -146,3 +146,5 @@ class SimplePie_Restriction return null; } } + +class_alias('SimplePie_Restriction', 'SimplePie\Restriction', false); diff --git a/lib/simplepie/library/SimplePie/Sanitize.php b/lib/simplepie/library/SimplePie/Sanitize.php index 35838032fcb..1f202ecc090 100644 --- a/lib/simplepie/library/SimplePie/Sanitize.php +++ b/lib/simplepie/library/SimplePie/Sanitize.php @@ -61,6 +61,7 @@ class SimplePie_Sanitize var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'); var $encode_instead_of_strip = false; var $strip_attributes = array('bgsound', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'); + var $rename_attributes = array(); var $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none')); var $strip_comments = false; var $output_encoding = 'UTF-8'; @@ -71,6 +72,15 @@ class SimplePie_Sanitize var $useragent = ''; var $force_fsockopen = false; var $replace_url_attributes = null; + var $registry; + + /** + * List of domains for which to force HTTPS. + * @see SimplePie_Sanitize::set_https_domains() + * Array is a tree split at DNS levels. Example: + * array('biz' => true, 'com' => array('example' => true), 'net' => array('example' => array('www' => true))) + */ + var $https_domains = array(); public function __construct() { @@ -160,6 +170,25 @@ class SimplePie_Sanitize $this->encode_instead_of_strip = (bool) $encode; } + public function rename_attributes($attribs = array()) + { + if ($attribs) + { + if (is_array($attribs)) + { + $this->rename_attributes = $attribs; + } + else + { + $this->rename_attributes = explode(',', $attribs); + } + } + else + { + $this->rename_attributes = false; + } + } + public function strip_attributes($attribs = array('bgsound', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc')) { if ($attribs) @@ -212,9 +241,9 @@ class SimplePie_Sanitize * Set element/attribute key/value pairs of HTML attributes * containing URLs that need to be resolved relative to the feed * - * Defaults to |a|@href, |area|@href, |blockquote|@cite, |del|@cite, - * |form|@action, |img|@longdesc, |img|@src, |input|@src, |ins|@cite, - * |q|@cite + * Defaults to |a|@href, |area|@href, |audio|@src, |blockquote|@cite, + * |del|@cite, |form|@action, |img|@longdesc, |img|@src, |input|@src, + * |ins|@cite, |q|@cite, |source|@src, |video|@src * * @since 1.0 * @param array|null $element_attribute Element/attribute key/value pairs, null for default @@ -226,6 +255,7 @@ class SimplePie_Sanitize $element_attribute = array( 'a' => 'href', 'area' => 'href', + 'audio' => 'src', 'blockquote' => 'cite', 'del' => 'cite', 'form' => 'action', @@ -235,12 +265,79 @@ class SimplePie_Sanitize ), 'input' => 'src', 'ins' => 'cite', - 'q' => 'cite' + 'q' => 'cite', + 'source' => 'src', + 'video' => array( + 'poster', + 'src' + ) ); } $this->replace_url_attributes = (array) $element_attribute; } + /** + * Set the list of domains for which to force HTTPS. + * @see SimplePie_Misc::https_url() + * Example array('biz', 'example.com', 'example.org', 'www.example.net'); + */ + public function set_https_domains($domains) + { + $this->https_domains = array(); + foreach ($domains as $domain) + { + $domain = trim($domain, ". \t\n\r\0\x0B"); + $segments = array_reverse(explode('.', $domain)); + $node =& $this->https_domains; + foreach ($segments as $segment) + {//Build a tree + if ($node === true) + { + break; + } + if (!isset($node[$segment])) + { + $node[$segment] = array(); + } + $node =& $node[$segment]; + } + $node = true; + } + } + + /** + * Check if the domain is in the list of forced HTTPS. + */ + protected function is_https_domain($domain) + { + $domain = trim($domain, '. '); + $segments = array_reverse(explode('.', $domain)); + $node =& $this->https_domains; + foreach ($segments as $segment) + {//Explore the tree + if (isset($node[$segment])) + { + $node =& $node[$segment]; + } + else + { + break; + } + } + return $node === true; + } + + /** + * Force HTTPS for selected Web sites. + */ + public function https_url($url) + { + return (strtolower(substr($url, 0, 7)) === 'http://') && + $this->is_https_domain(parse_url($url, PHP_URL_HOST)) ? + substr_replace($url, 's', 4, 0) : //Add the 's' to HTTPS + $url; + } + public function sanitize($data, $type, $base = '') { $data = trim($data); @@ -303,6 +400,14 @@ class SimplePie_Sanitize } } + if ($this->rename_attributes) + { + foreach ($this->rename_attributes as $attrib) + { + $this->rename_attr($attrib, $xpath); + } + } + if ($this->strip_attributes) { foreach ($this->strip_attributes as $attrib) @@ -376,6 +481,8 @@ class SimplePie_Sanitize { $data = preg_replace('/^/', '
', $data); } + + $data = str_replace('', '', $data); } if ($type & SIMPLEPIE_CONSTRUCT_IRI) @@ -443,6 +550,7 @@ class SimplePie_Sanitize $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base)); if ($value !== false) { + $value = $this->https_url($value); $element->setAttribute($attribute, $value); } } @@ -570,6 +678,17 @@ class SimplePie_Sanitize } } + protected function rename_attr($attrib, $xpath) + { + $elements = $xpath->query('//*[@' . $attrib . ']'); + + foreach ($elements as $element) + { + $element->setAttribute('data-sanitized-' . $attrib, $element->getAttribute($attrib)); + $element->removeAttribute($attrib); + } + } + protected function add_attr($tag, $valuePairs, $document) { $elements = $document->getElementsByTagName($tag); @@ -582,3 +701,5 @@ class SimplePie_Sanitize } } } + +class_alias('SimplePie_Sanitize', 'SimplePie\Sanitize', false); diff --git a/lib/simplepie/library/SimplePie/Source.php b/lib/simplepie/library/SimplePie/Source.php index f14e5b220e3..9e7ddf04de2 100644 --- a/lib/simplepie/library/SimplePie/Source.php +++ b/lib/simplepie/library/SimplePie/Source.php @@ -575,3 +575,5 @@ class SimplePie_Source return null; } } + +class_alias('SimplePie_Source', 'SimplePie\Source', false); diff --git a/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php b/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php index 0c857a58689..9ac0887046b 100644 --- a/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php +++ b/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php @@ -357,3 +357,5 @@ class SimplePie_XML_Declaration_Parser } } } + +class_alias('SimplePie_XML_Declaration_Parser', 'SimplePie\XML\Declaration\Parser', false); diff --git a/lib/simplepie/library/SimplePie/gzdecode.php b/lib/simplepie/library/SimplePie/gzdecode.php index 9c54f88330b..030a230d0e0 100644 --- a/lib/simplepie/library/SimplePie/gzdecode.php +++ b/lib/simplepie/library/SimplePie/gzdecode.php @@ -364,3 +364,5 @@ class SimplePie_gzdecode return false; } } + +class_alias('SimplePie_gzdecode', 'SimplePie\Gzdecode', false); diff --git a/lib/simplepie/readme_moodle.txt b/lib/simplepie/readme_moodle.txt index 4df2261a895..59f82e2d70a 100644 --- a/lib/simplepie/readme_moodle.txt +++ b/lib/simplepie/readme_moodle.txt @@ -1,4 +1,4 @@ -Description of SimplePie v1.5.6 library import into Moodle +Description of SimplePie library import into Moodle Obtained from https://github.com/simplepie/simplepie/releases/ @@ -13,6 +13,7 @@ To upgrade this library: - README.markdown 5. That should leave you with just the following. Do not move them. If there is any difference, check if they also need to be moved and update this doc: - idn (This is a third-party library that SimplePie can optionally use. We don't use this in Moodle) + - src - CHANGELOG.md - composer.json - db.sql diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml index 47118aed1ce..0503fa10036 100644 --- a/lib/thirdpartylibs.xml +++ b/lib/thirdpartylibs.xml @@ -167,7 +167,7 @@ simplepie SimplePie Simple Pie helps with blogs. - 1.5.6 + 1.6.0 BSD https://github.com/simplepie/simplepie