aboutsummaryrefslogtreecommitdiffstats
path: root/lib/simplepie/library/SimplePie.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/simplepie/library/SimplePie.php')
-rwxr-xr-xlib/simplepie/library/SimplePie.php97
1 files changed, 83 insertions, 14 deletions
diff --git a/lib/simplepie/library/SimplePie.php b/lib/simplepie/library/SimplePie.php
index 78e724525..d4c2f0f1d 100755
--- a/lib/simplepie/library/SimplePie.php
+++ b/lib/simplepie/library/SimplePie.php
@@ -5,7 +5,7 @@
* A PHP-Based RSS and Atom Feed Framework.
* Takes the hard work out of managing a complete RSS/Atom solution.
*
- * Copyright (c) 2004-2017, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
+ * Copyright (c) 2004-2017, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
@@ -33,10 +33,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @package SimplePie
- * @version 1.5.2
- * @copyright 2004-2017 Ryan Parman, Geoffrey Sneddon, Ryan McCue
+ * @version 1.5.6
+ * @copyright 2004-2017 Ryan Parman, Sam Sneddon, Ryan McCue
* @author Ryan Parman
- * @author Geoffrey Sneddon
+ * @author Sam Sneddon
* @author Ryan McCue
* @link http://simplepie.org/ SimplePie
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
@@ -50,7 +50,7 @@ define('SIMPLEPIE_NAME', 'SimplePie');
/**
* SimplePie Version
*/
-define('SIMPLEPIE_VERSION', '1.5.2');
+define('SIMPLEPIE_VERSION', '1.5.6');
/**
* SimplePie Build
@@ -425,6 +425,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()
* @access private
@@ -665,9 +672,9 @@ class SimplePie
*/
public function __construct()
{
- if (version_compare(PHP_VERSION, '5.3', '<'))
+ if (version_compare(PHP_VERSION, '5.6', '<'))
{
- trigger_error('Please upgrade to PHP 5.3 or newer.');
+ trigger_error('Please upgrade to PHP 5.6 or newer.');
die();
}
@@ -706,7 +713,7 @@ class SimplePie
*/
public function __destruct()
{
- if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
+ if (!gc_enabled())
{
if (!empty($this->data['items']))
{
@@ -909,6 +916,39 @@ class SimplePie
}
/**
+ * 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
*
* @param bool $enable Sort as reverse chronological order.
@@ -1146,6 +1186,7 @@ class SimplePie
$this->strip_attributes(false);
$this->add_attributes(false);
$this->set_image_handler(false);
+ $this->set_https_domains(array());
}
}
@@ -1249,10 +1290,23 @@ class SimplePie
}
/**
+ * 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.
*
- * @param str $page Web-accessible path to the handler_image.php file.
- * @param str $qs The query string that the value should be passed to.
+ * @param string $page Web-accessible path to the handler_image.php file.
+ * @param string $qs The query string that the value should be passed to.
*/
public function set_image_handler($page = false, $qs = 'i')
{
@@ -1373,7 +1427,8 @@ class SimplePie
// Decide whether to enable caching
if ($this->cache && $parsed_feed_url['scheme'] !== '')
{
- $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_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
@@ -1513,7 +1568,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)
@@ -1576,6 +1631,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)
{
@@ -1630,6 +1686,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)))
{
@@ -1712,8 +1770,8 @@ class SimplePie
}
$cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
}
- $this->feed_url = $file->url;
}
+ $this->feed_url = $file->url;
$locate = null;
}
@@ -1737,6 +1795,16 @@ class SimplePie
}
/**
+ * Get the last HTTP status code
+ *
+ * @return int Status code
+ */
+ public function status_code()
+ {
+ return $this->status_code;
+ }
+
+ /**
* Get the raw XML
*
* This is the same as the old `$feed->enable_xml_dump(true)`, but returns
@@ -1911,7 +1979,8 @@ class SimplePie
*
* When the 'permanent' mode is disabled (default),
* may or may not be different from the URL passed to {@see set_feed_url()},
- * depending on whether auto-discovery was used.
+ * depending on whether auto-discovery was used, and whether there were
+ * any redirects along the way.
*
* @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
* @todo Support <itunes:new-feed-url>