Skip to content

Commit

Permalink
MDL-75467 libraries: upgrade to version 1.6.0 of SimplePie.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Sep 27, 2022
1 parent 8f492a8 commit ea0e463
Show file tree
Hide file tree
Showing 37 changed files with 364 additions and 41 deletions.
5 changes: 3 additions & 2 deletions lib/simplepie/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------
Expand Down
2 changes: 2 additions & 0 deletions lib/simplepie/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
*/
class SimplePie_Autoloader
{
protected $path;

/**
* Constructor
*/
Expand Down
115 changes: 103 additions & 12 deletions lib/simplepie/library/SimplePie.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,7 +50,7 @@
/**
* SimplePie Version
*/
define('SIMPLEPIE_VERSION', '1.5.6');
define('SIMPLEPIE_VERSION', '1.6.0');

/**
* SimplePie Build
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -908,6 +922,39 @@ public function set_cache_location($location = './cache')
$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
*
Expand Down Expand Up @@ -1146,6 +1193,7 @@ public function set_stupidly_fast($set = false)
$this->strip_attributes(false);
$this->add_attributes(false);
$this->set_image_handler(false);
$this->set_https_domains(array());
}
}

Expand Down Expand Up @@ -1182,6 +1230,15 @@ public function encode_instead_of_strip($enable = true)
$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 === '')
Expand Down Expand Up @@ -1248,6 +1305,19 @@ public function set_url_replacements($element_attribute = null)
$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.
*
Expand Down Expand Up @@ -1373,8 +1443,8 @@ public function init()
// 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
Expand Down Expand Up @@ -1514,7 +1584,7 @@ public function init()
* 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)
Expand Down Expand Up @@ -1577,6 +1647,7 @@ protected function fetch_data(&$cache)
}

$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)
{
Expand Down Expand Up @@ -1631,6 +1702,8 @@ protected function fetch_data(&$cache)
$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)))
{
Expand Down Expand Up @@ -1728,7 +1801,7 @@ protected function fetch_data(&$cache)
}

/**
* 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
*/
Expand All @@ -1737,6 +1810,16 @@ public function error()
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
*
Expand Down Expand Up @@ -2132,7 +2215,7 @@ public function get_image_tags($namespace, $tag)
*/
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'];
}
Expand Down Expand Up @@ -2580,13 +2663,19 @@ public function get_links($rel = 'alternate')
}
}

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];
}
Expand Down Expand Up @@ -3243,3 +3332,5 @@ private function store_links(&$file, $hub, $self) {
}
}
}

class_alias('SimplePie', 'SimplePie\SimplePie', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ public function get_email()
return null;
}
}

class_alias('SimplePie_Author', 'SimplePie\Author', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ public static function parse_URL($url)
return $params;
}
}

class_alias('SimplePie_Cache', 'SimplePie\Cache', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Cache/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ public function touch();
*/
public function unlink();
}

class_alias('SimplePie_Cache_Base', 'SimplePie\Cache\Base', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Cache/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ protected static function prepare_simplepie_object_for_cache($data)
return array(serialize($data->data), $items_by_id);
}
}

class_alias('SimplePie_Cache_DB', 'SimplePie\Cache\DB', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Cache/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@ public function unlink()
return false;
}
}

class_alias('SimplePie_Cache_File', 'SimplePie\Cache\File', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Cache/Memcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,5 @@ public function unlink()
return $this->cache->delete($this->name, 0);
}
}

class_alias('SimplePie_Cache_Memcache', 'SimplePie\Cache\Memcache', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Cache/Memcached.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ private function setData($data) {
return false;
}
}

class_alias('SimplePie_Cache_Memcached', 'SimplePie\Cache\Memcached', false);
4 changes: 3 additions & 1 deletion lib/simplepie/library/SimplePie/Cache/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function save($data)
$query->bindValue(':data', serialize($data));
$query->bindValue(':time', time());
$query->bindValue(':feed', $this->id);
if ($this->execute())
if ($query->execute())
{
return true;
}
Expand Down Expand Up @@ -438,3 +438,5 @@ public function unlink()
return $query->execute() && $query2->execute();
}
}

class_alias('SimplePie_Cache_MySQL', 'SimplePie\Cache\MySQL', false);
4 changes: 3 additions & 1 deletion lib/simplepie/library/SimplePie/Cache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function touch() {
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;
}
Expand All @@ -170,3 +170,5 @@ public function unlink() {
}

}

class_alias('SimplePie_Cache_Redis', 'SimplePie\Cache\Redis', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Caption.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,5 @@ public function get_type()
return null;
}
}

class_alias('SimplePie_Caption', 'SimplePie\Caption', false);
3 changes: 2 additions & 1 deletion lib/simplepie/library/SimplePie/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SimplePie_Category

/**
* Category type
*
*
* category for <category>
* subject for <dc:subject>
*
Expand Down Expand Up @@ -161,3 +161,4 @@ public function get_type()
}
}

class_alias('SimplePie_Category', 'SimplePie\Category', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Content/Type/Sniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,5 @@ public function feed_or_html()
return 'text/html';
}
}

class_alias('SimplePie_Content_Type_Sniffer', 'SimplePie\Content\Type\Sniffer', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Copyright.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ public function get_attribution()
return null;
}
}

class_alias('SimplePie_Copyright', 'SimplePie\Copyright', false);
2 changes: 2 additions & 0 deletions lib/simplepie/library/SimplePie/Credit.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ public function get_name()
return null;
}
}

class_alias('SimplePie_Credit', 'SimplePie\Credit', false);
9 changes: 8 additions & 1 deletion lib/simplepie/library/SimplePie/Enclosure.php
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,12 @@ public function get_real_type($find_handler = false)
// 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':
Expand Down Expand Up @@ -1302,3 +1307,5 @@ public function get_real_type($find_handler = false)
return $type;
}
}

class_alias('SimplePie_Enclosure', 'SimplePie\Enclosure', false);
4 changes: 3 additions & 1 deletion lib/simplepie/library/SimplePie/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@
*/
class SimplePie_Exception extends Exception
{
}
}

class_alias('SimplePie_Exception', 'SimplePie\Exception', false);
Loading

0 comments on commit ea0e463

Please sign in to comment.