diff options
Diffstat (limited to 'lib/simplepie/library/SimplePie.php')
-rwxr-xr-x | lib/simplepie/library/SimplePie.php | 135 |
1 files changed, 114 insertions, 21 deletions
diff --git a/lib/simplepie/library/SimplePie.php b/lib/simplepie/library/SimplePie.php index 78e724525..2ae78c359 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.6.0 + * @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.6.0'); /** * 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 @@ -644,6 +651,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 */ @@ -665,9 +679,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 +720,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 +923,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 +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 === '') @@ -1249,10 +1306,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 +1443,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 +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) @@ -1576,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) { @@ -1630,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))) { @@ -1712,8 +1786,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; } @@ -1727,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 +1811,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 +1995,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> @@ -2130,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']; } @@ -2578,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]; } @@ -3241,3 +3332,5 @@ class SimplePie } } } + +class_alias('SimplePie', 'SimplePie\SimplePie', false); |