From 4155b7a40baf85113c18cc9240351b218bd2966c Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Tue, 18 Jun 2019 10:51:36 +0800 Subject: [PATCH] MDL-65750 lib: update simplepie to 1.5.2 --- lib/simplepie/library/SimplePie.php | 220 +++++++---------- lib/simplepie/library/SimplePie/Author.php | 19 +- .../library/SimplePie/Cache/File.php | 2 +- .../library/SimplePie/Cache/Memcached.php | 0 .../library/SimplePie/Cache/MySQL.php | 28 +-- .../library/SimplePie/Cache/Redis.php | 6 + lib/simplepie/library/SimplePie/Caption.php | 31 +-- .../SimplePie/Content/Type/Sniffer.php | 37 +-- lib/simplepie/library/SimplePie/Copyright.php | 13 +- lib/simplepie/library/SimplePie/Credit.php | 19 +- .../SimplePie/Decode/HTML/Entities.php | 13 +- lib/simplepie/library/SimplePie/Enclosure.php | 223 ++++++------------ lib/simplepie/library/SimplePie/File.php | 5 +- .../library/SimplePie/HTTP/Parser.php | 37 ++- lib/simplepie/library/SimplePie/IRI.php | 151 +++++------- lib/simplepie/library/SimplePie/Item.php | 167 +++++-------- lib/simplepie/library/SimplePie/Locator.php | 29 +-- lib/simplepie/library/SimplePie/Misc.php | 55 ++--- lib/simplepie/library/SimplePie/Net/IPv6.php | 18 +- .../library/SimplePie/Parse/Date.php | 67 ++++-- lib/simplepie/library/SimplePie/Parser.php | 175 +++++++------- lib/simplepie/library/SimplePie/Rating.php | 12 +- lib/simplepie/library/SimplePie/Registry.php | 0 .../library/SimplePie/Restriction.php | 18 +- lib/simplepie/library/SimplePie/Sanitize.php | 2 +- lib/simplepie/library/SimplePie/Source.php | 97 +++----- .../SimplePie/XML/Declaration/Parser.php | 12 +- lib/simplepie/library/SimplePie/gzdecode.php | 12 +- 28 files changed, 591 insertions(+), 877 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/library/SimplePie.php b/lib/simplepie/library/SimplePie.php old mode 100644 new mode 100755 index 428bfc06886..78e724525b1 --- 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 + * @version 1.5.2 * @copyright 2004-2017 Ryan Parman, Geoffrey Sneddon, Ryan McCue * @author Ryan Parman * @author Geoffrey Sneddon @@ -50,7 +50,7 @@ /** * SimplePie Version */ -define('SIMPLEPIE_VERSION', '1.5'); +define('SIMPLEPIE_VERSION', '1.5.2'); /** * SimplePie Build @@ -648,7 +648,7 @@ class SimplePie * @access private */ public $enable_exceptions = false; - + /** * The SimplePie class contains feed level data and options * @@ -810,7 +810,7 @@ public function set_raw_data($data) } /** - * Set the the default timeout for fetching remote feeds + * Set the default timeout for fetching remote feeds * * This allows you to change the maximum time the feed's server to respond * and send the feed back. @@ -1320,6 +1320,11 @@ public function init() } } + // 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 (method_exists($this->sanitize, 'set_registry')) { $this->sanitize->set_registry($this->registry); @@ -1382,7 +1387,7 @@ public function init() list($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."; @@ -1466,7 +1471,7 @@ public function init() // Cache the file if caching is enabled if ($cache && !$cache->save($this)) { - trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); + 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; } @@ -1635,7 +1640,7 @@ protected function fetch_data(&$cache) if (!$this->force_feed) { // Check if the supplied URL is a feed, if it isn't, look for it. - $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds)); + $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds, $this->force_fsockopen, $this->curl_options)); if (!$locate->is_feed($file)) { @@ -1644,33 +1649,18 @@ protected function fetch_data(&$cache) try { $microformats = false; - if (function_exists('Mf2\parse')) { + if (class_exists('DOMXpath') && function_exists('Mf2\parse')) { + $doc = new DOMDocument(); + @$doc->loadHTML($file->body); + $xpath = new DOMXpath($doc); // Check for both h-feed and h-entry, as both a feed with no entries // and a list of entries without an h-feed wrapper are both valid. - $position = 0; - while ($position = strpos($file->body, 'h-feed', $position)) - { - $start = $position < 200 ? 0 : $position - 200; - $check = substr($file->body, $start, 400); - if ($microformats = preg_match('/class="[^"]*h-feed/', $check)) - { - break; - } - $position += 7; - } - $position = 0; - while ($position = strpos($file->body, 'h-entry', $position)) - { - $start = $position < 200 ? 0 : $position - 200; - $check = substr($file->body, $start, 400); - if ($microformats = preg_match('/class="[^"]*h-entry/', $check)) - { - break; - } - $position += 7; - } + $query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '. + 'contains(concat(" ", @class, " "), " h-entry ")]'; + $result = $xpath->query($query); + $microformats = $result->length !== 0; } - // Now also do feed discovery, but if an h-entry was found don't + // Now also do feed discovery, but if microformats were found don't // overwrite the current value of file. $discovered = $locate->find($this->autodiscovery, $this->all_discovered_feeds); @@ -1718,7 +1708,7 @@ protected function fetch_data(&$cache) $this->data = array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD); if (!$cache->save($this)) { - trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); + 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', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc')); } @@ -1914,7 +1904,7 @@ public function get_type() /** * Get the URL for the feed - * + * * When the 'permanent' mode is enabled, returns the original feed URL, * except in the case of an `HTTP 301 Moved Permanently` status response, * in which case the location of the first redirection is returned. @@ -2148,10 +2138,8 @@ public function get_base($element = array()) { return $this->get_link(); } - else - { - return $this->subscribe_url(); - } + + return $this->subscribe_url(); } /** @@ -2221,10 +2209,8 @@ public function get_title() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } /** @@ -2241,10 +2227,8 @@ public function get_category($key = 0) { return $categories[$key]; } - else - { - return null; - } + + return null; } /** @@ -2306,10 +2290,8 @@ public function get_categories() { return array_unique($categories); } - else - { - return null; - } + + return null; } /** @@ -2326,10 +2308,8 @@ public function get_author($key = 0) { return $authors[$key]; } - else - { - return null; - } + + return null; } /** @@ -2404,10 +2384,8 @@ public function get_authors() { return array_unique($authors); } - else - { - return null; - } + + return null; } /** @@ -2424,10 +2402,8 @@ public function get_contributor($key = 0) { return $contributors[$key]; } - else - { - return null; - } + + return null; } /** @@ -2490,10 +2466,8 @@ public function get_contributors() { return array_unique($contributors); } - else - { - return null; - } + + return null; } /** @@ -2511,10 +2485,8 @@ public function get_link($key = 0, $rel = 'alternate') { return $links[$key]; } - else - { - return null; - } + + return null; } /** @@ -2606,20 +2578,18 @@ public function get_links($rel = 'alternate') } } - if (isset($this->data['links'][$rel])) - { - return $this->data['links'][$rel]; - } - else if (isset($this->data['headers']['link']) && - preg_match('/<([^>]+)>; rel='.preg_quote($rel).'/', - $this->data['headers']['link'], $match)) + if (isset($this->data['headers']['link']) && + preg_match('/<([^>]+)>; rel='.preg_quote($rel).'/', + $this->data['headers']['link'], $match)) { return array($match[1]); } - else + else if (isset($this->data['links'][$rel])) { - return null; + return $this->data['links'][$rel]; } + + return null; } public function get_all_discovered_feeds() @@ -2674,10 +2644,8 @@ public function get_description() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); } - else - { - return null; - } + + return null; } /** @@ -2710,10 +2678,8 @@ public function get_copyright() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } /** @@ -2754,10 +2720,8 @@ public function get_language() { return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } /** @@ -2783,10 +2747,8 @@ public function get_latitude() { return (float) $match[1]; } - else - { - return null; - } + + return null; } /** @@ -2815,10 +2777,8 @@ public function get_longitude() { return (float) $match[2]; } - else - { - return null; - } + + return null; } /** @@ -2852,10 +2812,8 @@ public function get_image_title() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } /** @@ -2895,10 +2853,8 @@ public function get_image_url() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); } - else - { - return null; - } + + return null; } @@ -2927,10 +2883,8 @@ public function get_image_link() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); } - else - { - return null; - } + + return null; } /** @@ -2953,10 +2907,8 @@ public function get_image_width() { return 88.0; } - else - { - return null; - } + + return null; } /** @@ -2979,10 +2931,8 @@ public function get_image_height() { return 31.0; } - else - { - return null; - } + + return null; } /** @@ -3002,10 +2952,8 @@ public function get_item_quantity($max = 0) { return $qty; } - else - { - return ($qty > $max) ? $max : $qty; - } + + return ($qty > $max) ? $max : $qty; } /** @@ -3027,10 +2975,8 @@ public function get_item($key = 0) { return $items[$key]; } - else - { - return null; - } + + return null; } /** @@ -3125,10 +3071,8 @@ public function get_items($start = 0, $end = 0) { return array_slice($items, $start); } - else - { - return array_slice($items, $start, $end); - } + + return array_slice($items, $start, $end); } /** @@ -3155,7 +3099,7 @@ public function get_favicon() if (($url = $this->get_link()) !== null) { - return 'http://g.etfv.co/' . urlencode($url); + return 'https://www.google.com/s2/favicons?domain=' . urlencode($url); } return false; @@ -3251,16 +3195,12 @@ public static function merge_items($urls, $start = 0, $end = 0, $limit = 0) { return array_slice($items, $start); } - else - { - return array_slice($items, $start, $end); - } - } - else - { - trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); - return array(); + + return array_slice($items, $start, $end); } + + trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING); + return array(); } /** diff --git a/lib/simplepie/library/SimplePie/Author.php b/lib/simplepie/library/SimplePie/Author.php index e6768ff2910..14794cf2706 100644 --- a/lib/simplepie/library/SimplePie/Author.php +++ b/lib/simplepie/library/SimplePie/Author.php @@ -113,10 +113,8 @@ public function get_name() { return $this->name; } - else - { - return null; - } + + return null; } /** @@ -130,10 +128,8 @@ public function get_link() { return $this->link; } - else - { - return null; - } + + return null; } /** @@ -147,10 +143,7 @@ public function get_email() { return $this->email; } - else - { - return null; - } + + return null; } } - diff --git a/lib/simplepie/library/SimplePie/Cache/File.php b/lib/simplepie/library/SimplePie/Cache/File.php index 6ba6c5f6e74..a09dea637f6 100644 --- a/lib/simplepie/library/SimplePie/Cache/File.php +++ b/lib/simplepie/library/SimplePie/Cache/File.php @@ -101,7 +101,7 @@ public function __construct($location, $name, $type) */ public function save($data) { - if (file_exists($this->name) && is_writeable($this->name) || file_exists($this->location) && is_writeable($this->location)) + if (file_exists($this->name) && is_writable($this->name) || file_exists($this->location) && is_writable($this->location)) { if ($data instanceof SimplePie) { diff --git a/lib/simplepie/library/SimplePie/Cache/Memcached.php b/lib/simplepie/library/SimplePie/Cache/Memcached.php old mode 100644 new mode 100755 diff --git a/lib/simplepie/library/SimplePie/Cache/MySQL.php b/lib/simplepie/library/SimplePie/Cache/MySQL.php index 8686b6c6747..061ed043a8c 100644 --- a/lib/simplepie/library/SimplePie/Cache/MySQL.php +++ b/lib/simplepie/library/SimplePie/Cache/MySQL.php @@ -96,7 +96,7 @@ public function __construct($location, $name, $type) 'cache_purge_time' => 2592000 ), ); - + $this->options = SimplePie_Misc::array_merge_recursive($this->options, SimplePie_Cache::parse_URL($location)); // Path is prefixed with a "/" @@ -395,10 +395,8 @@ public function mtime() { return $time; } - else - { - return false; - } + + return false; } /** @@ -416,14 +414,8 @@ public function touch() $query = $this->mysql->prepare('UPDATE `' . $this->options['extras']['prefix'] . 'cache_data` SET `mtime` = :time WHERE `id` = :id'); $query->bindValue(':time', time()); $query->bindValue(':id', $this->id); - if ($query->execute() && $query->rowCount() > 0) - { - return true; - } - else - { - return false; - } + + return $query->execute() && $query->rowCount() > 0; } /** @@ -442,13 +434,7 @@ public function unlink() $query->bindValue(':id', $this->id); $query2 = $this->mysql->prepare('DELETE FROM `' . $this->options['extras']['prefix'] . 'items` WHERE `feed_id` = :id'); $query2->bindValue(':id', $this->id); - if ($query->execute() && $query2->execute()) - { - return true; - } - else - { - return false; - } + + return $query->execute() && $query2->execute(); } } diff --git a/lib/simplepie/library/SimplePie/Cache/Redis.php b/lib/simplepie/library/SimplePie/Cache/Redis.php index 04d72c79a8e..dbc88e829a7 100644 --- a/lib/simplepie/library/SimplePie/Cache/Redis.php +++ b/lib/simplepie/library/SimplePie/Cache/Redis.php @@ -65,6 +65,12 @@ public function __construct($location, $name, $options = null) { $parsed = SimplePie_Cache::parse_URL($location); $redis = new Redis(); $redis->connect($parsed['host'], $parsed['port']); + if (isset($parsed['pass'])) { + $redis->auth($parsed['pass']); + } + if (isset($parsed['path'])) { + $redis->select((int)substr($parsed['path'], 1)); + } $this->cache = $redis; if (!is_null($options) && is_array($options)) { diff --git a/lib/simplepie/library/SimplePie/Caption.php b/lib/simplepie/library/SimplePie/Caption.php index abf07de1bc9..85485760312 100644 --- a/lib/simplepie/library/SimplePie/Caption.php +++ b/lib/simplepie/library/SimplePie/Caption.php @@ -131,10 +131,8 @@ public function get_endtime() { return $this->endTime; } - else - { - return null; - } + + return null; } /** @@ -149,10 +147,8 @@ public function get_language() { return $this->lang; } - else - { - return null; - } + + return null; } /** @@ -166,10 +162,8 @@ public function get_starttime() { return $this->startTime; } - else - { - return null; - } + + return null; } /** @@ -183,10 +177,8 @@ public function get_text() { return $this->text; } - else - { - return null; - } + + return null; } /** @@ -200,10 +192,7 @@ public function get_type() { return $this->type; } - else - { - return null; - } + + return null; } } - diff --git a/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php b/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php index ff35de61497..b86dfa33ce9 100644 --- a/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php +++ b/lib/simplepie/library/SimplePie/Content/Type/Sniffer.php @@ -120,24 +120,18 @@ public function get_type() { return $return; } - else - { - return $official; - } + + return $official; } elseif ($official === 'text/html') { return $this->feed_or_html(); } - else - { - return $official; - } - } - else - { - return $this->unknown(); + + return $official; } + + return $this->unknown(); } /** @@ -158,10 +152,8 @@ public function text_or_binary() { return 'application/octect-stream'; } - else - { - return 'text/plain'; - } + + return 'text/plain'; } /** @@ -207,10 +199,8 @@ public function unknown() { return 'image/vnd.microsoft.icon'; } - else - { - return $this->text_or_binary(); - } + + return $this->text_or_binary(); } /** @@ -241,10 +231,8 @@ public function image() { return 'image/vnd.microsoft.icon'; } - else - { - return false; - } + + return false; } /** @@ -328,4 +316,3 @@ public function feed_or_html() return 'text/html'; } } - diff --git a/lib/simplepie/library/SimplePie/Copyright.php b/lib/simplepie/library/SimplePie/Copyright.php index 3f3d07d3b18..a57f323e686 100644 --- a/lib/simplepie/library/SimplePie/Copyright.php +++ b/lib/simplepie/library/SimplePie/Copyright.php @@ -103,10 +103,8 @@ public function get_url() { return $this->url; } - else - { - return null; - } + + return null; } /** @@ -120,10 +118,7 @@ public function get_attribution() { return $this->label; } - else - { - return null; - } + + return null; } } - diff --git a/lib/simplepie/library/SimplePie/Credit.php b/lib/simplepie/library/SimplePie/Credit.php index 9bad9ef34e9..064a1b8646b 100644 --- a/lib/simplepie/library/SimplePie/Credit.php +++ b/lib/simplepie/library/SimplePie/Credit.php @@ -112,10 +112,8 @@ public function get_role() { return $this->role; } - else - { - return null; - } + + return null; } /** @@ -129,10 +127,8 @@ public function get_scheme() { return $this->scheme; } - else - { - return null; - } + + return null; } /** @@ -146,10 +142,7 @@ public function get_name() { return $this->name; } - else - { - return null; - } + + return null; } } - diff --git a/lib/simplepie/library/SimplePie/Decode/HTML/Entities.php b/lib/simplepie/library/SimplePie/Decode/HTML/Entities.php index de3f2cb53e9..773481a8c84 100644 --- a/lib/simplepie/library/SimplePie/Decode/HTML/Entities.php +++ b/lib/simplepie/library/SimplePie/Decode/HTML/Entities.php @@ -117,10 +117,8 @@ public function consume() $this->consumed .= $this->data[$this->position]; return $this->data[$this->position++]; } - else - { - return false; - } + + return false; } /** @@ -139,10 +137,8 @@ public function consume_range($chars) $this->position += $len; return $data; } - else - { - return false; - } + + return false; } /** @@ -612,4 +608,3 @@ public function entity() } } } - diff --git a/lib/simplepie/library/SimplePie/Enclosure.php b/lib/simplepie/library/SimplePie/Enclosure.php index 15060e19334..ddbbc3c929c 100644 --- a/lib/simplepie/library/SimplePie/Enclosure.php +++ b/lib/simplepie/library/SimplePie/Enclosure.php @@ -282,10 +282,8 @@ public function get_bitrate() { return $this->bitrate; } - else - { - return null; - } + + return null; } /** @@ -301,10 +299,8 @@ public function get_caption($key = 0) { return $captions[$key]; } - else - { - return null; - } + + return null; } /** @@ -318,10 +314,8 @@ public function get_captions() { return $this->captions; } - else - { - return null; - } + + return null; } /** @@ -337,10 +331,8 @@ public function get_category($key = 0) { return $categories[$key]; } - else - { - return null; - } + + return null; } /** @@ -354,10 +346,8 @@ public function get_categories() { return $this->categories; } - else - { - return null; - } + + return null; } /** @@ -371,10 +361,8 @@ public function get_channels() { return $this->channels; } - else - { - return null; - } + + return null; } /** @@ -388,10 +376,8 @@ public function get_copyright() { return $this->copyright; } - else - { - return null; - } + + return null; } /** @@ -407,10 +393,8 @@ public function get_credit($key = 0) { return $credits[$key]; } - else - { - return null; - } + + return null; } /** @@ -424,10 +408,8 @@ public function get_credits() { return $this->credits; } - else - { - return null; - } + + return null; } /** @@ -441,10 +423,8 @@ public function get_description() { return $this->description; } - else - { - return null; - } + + return null; } /** @@ -462,15 +442,11 @@ public function get_duration($convert = false) $time = SimplePie_Misc::time_hms($this->duration); return $time; } - else - { - return $this->duration; - } - } - else - { - return null; + + return $this->duration; } + + return null; } /** @@ -484,10 +460,8 @@ public function get_expression() { return $this->expression; } - else - { - return 'full'; - } + + return 'full'; } /** @@ -519,10 +493,8 @@ public function get_framerate() { return $this->framerate; } - else - { - return null; - } + + return null; } /** @@ -549,10 +521,8 @@ public function get_hash($key = 0) { return $hashes[$key]; } - else - { - return null; - } + + return null; } /** @@ -566,10 +536,8 @@ public function get_hashes() { return $this->hashes; } - else - { - return null; - } + + return null; } /** @@ -583,10 +551,8 @@ public function get_height() { return $this->height; } - else - { - return null; - } + + return null; } /** @@ -601,10 +567,8 @@ public function get_language() { return $this->lang; } - else - { - return null; - } + + return null; } /** @@ -620,10 +584,8 @@ public function get_keyword($key = 0) { return $keywords[$key]; } - else - { - return null; - } + + return null; } /** @@ -637,10 +599,8 @@ public function get_keywords() { return $this->keywords; } - else - { - return null; - } + + return null; } /** @@ -654,10 +614,8 @@ public function get_length() { return $this->length; } - else - { - return null; - } + + return null; } /** @@ -671,10 +629,8 @@ public function get_link() { return urldecode($this->link); } - else - { - return null; - } + + return null; } /** @@ -689,10 +645,8 @@ public function get_medium() { return $this->medium; } - else - { - return null; - } + + return null; } /** @@ -707,10 +661,8 @@ public function get_player() { return $this->player; } - else - { - return null; - } + + return null; } /** @@ -726,10 +678,8 @@ public function get_rating($key = 0) { return $ratings[$key]; } - else - { - return null; - } + + return null; } /** @@ -743,10 +693,8 @@ public function get_ratings() { return $this->ratings; } - else - { - return null; - } + + return null; } /** @@ -762,10 +710,8 @@ public function get_restriction($key = 0) { return $restrictions[$key]; } - else - { - return null; - } + + return null; } /** @@ -779,10 +725,8 @@ public function get_restrictions() { return $this->restrictions; } - else - { - return null; - } + + return null; } /** @@ -796,10 +740,8 @@ public function get_sampling_rate() { return $this->samplingrate; } - else - { - return null; - } + + return null; } /** @@ -814,10 +756,8 @@ public function get_size() { return round($length/1048576, 2); } - else - { - return null; - } + + return null; } /** @@ -833,10 +773,8 @@ public function get_thumbnail($key = 0) { return $thumbnails[$key]; } - else - { - return null; - } + + return null; } /** @@ -850,10 +788,8 @@ public function get_thumbnails() { return $this->thumbnails; } - else - { - return null; - } + + return null; } /** @@ -867,10 +803,8 @@ public function get_title() { return $this->title; } - else - { - return null; - } + + return null; } /** @@ -885,10 +819,8 @@ public function get_type() { return $this->type; } - else - { - return null; - } + + return null; } /** @@ -902,10 +834,8 @@ public function get_width() { return $this->width; } - else - { - return null; - } + + return null; } /** @@ -1365,15 +1295,10 @@ public function get_real_type($find_handler = false) { return 'mp3'; } - else - { - return null; - } - } - else - { - return $type; + + return null; } + + return $type; } } - diff --git a/lib/simplepie/library/SimplePie/File.php b/lib/simplepie/library/SimplePie/File.php index e670e05a011..c73e0fbc9ce 100644 --- a/lib/simplepie/library/SimplePie/File.php +++ b/lib/simplepie/library/SimplePie/File.php @@ -71,7 +71,7 @@ public function __construct($url, $timeout = 10, $redirects = 5, $headers = null { $idn = new idna_convert(); $parsed = SimplePie_Misc::parse_url($url); - $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], $parsed['fragment']); + $url = SimplePie_Misc::compress_parse_url($parsed['scheme'], $idn->encode($parsed['authority']), $parsed['path'], $parsed['query'], NULL); } $this->url = $url; $this->permanent_url = $url; @@ -136,8 +136,7 @@ public function __construct($url, $timeout = 10, $redirects = 5, $headers = null $this->url = $info['url']; } curl_close($fp); - $this->headers = explode("\r\n\r\n", $this->headers, $info['redirect_count'] + 1); - $this->headers = array_pop($this->headers); + $this->headers = SimplePie_HTTP_Parser::prepareHeaders($this->headers, $info['redirect_count'] + 1); $parser = new SimplePie_HTTP_Parser($this->headers); if ($parser->parse()) { diff --git a/lib/simplepie/library/SimplePie/HTTP/Parser.php b/lib/simplepie/library/SimplePie/HTTP/Parser.php index 63ae1e03d21..7d6188dd1b5 100644 --- a/lib/simplepie/library/SimplePie/HTTP/Parser.php +++ b/lib/simplepie/library/SimplePie/HTTP/Parser.php @@ -155,15 +155,13 @@ public function parse() { return true; } - else - { - $this->http_version = ''; - $this->status_code = ''; - $this->reason = ''; - $this->headers = array(); - $this->body = ''; - return false; - } + + $this->http_version = ''; + $this->status_code = ''; + $this->reason = ''; + $this->headers = array(); + $this->body = ''; + return false; } /** @@ -496,4 +494,25 @@ protected function chunked() } } } + + /** + * Prepare headers (take care of proxies headers) + * + * @param string $headers Raw headers + * @param integer $count Redirection count. Default to 1. + * + * @return string + */ + static public function prepareHeaders($headers, $count = 1) + { + $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.1 200 Connection established\r\n\r\n")) { + $data = str_ireplace("HTTP/1.1 200 Connection established\r\n\r\n", '', $data); + } + return $data; + } } diff --git a/lib/simplepie/library/SimplePie/IRI.php b/lib/simplepie/library/SimplePie/IRI.php index 2b3fbaf07e2..ffba232b1e3 100644 --- a/lib/simplepie/library/SimplePie/IRI.php +++ b/lib/simplepie/library/SimplePie/IRI.php @@ -211,10 +211,8 @@ public function __get($name) { return $this->normalization[$this->scheme][$name]; } - else - { - return $return; - } + + return $return; } /** @@ -225,14 +223,7 @@ public function __get($name) */ public function __isset($name) { - if (method_exists($this, 'get_' . $name) || isset($this->$name)) - { - return true; - } - else - { - return false; - } + return method_exists($this, 'get_' . $name) || isset($this->$name); } /** @@ -356,10 +347,8 @@ public static function absolutize($base, $relative) $target->scheme_normalization(); return $target; } - else - { - return false; - } + + return false; } } @@ -396,11 +385,9 @@ protected function parse_iri($iri) } return $match; } - else - { - // This can occur when a paragraph is accidentally parsed as a URI - return false; - } + + // This can occur when a paragraph is accidentally parsed as a URI + return false; } /** @@ -804,7 +791,7 @@ public function is_valid() public function set_iri($iri, $clear_cache = false) { static $cache; - if ($clear_cache) + if ($clear_cache) { $cache = null; return; @@ -830,30 +817,28 @@ public function set_iri($iri, $clear_cache = false) $return) = $cache[$iri]; return $return; } - else - { - $parsed = $this->parse_iri((string) $iri); - if (!$parsed) - { - return false; - } - $return = $this->set_scheme($parsed['scheme']) - && $this->set_authority($parsed['authority']) - && $this->set_path($parsed['path']) - && $this->set_query($parsed['query']) - && $this->set_fragment($parsed['fragment']); - - $cache[$iri] = array($this->scheme, - $this->iuserinfo, - $this->ihost, - $this->port, - $this->ipath, - $this->iquery, - $this->ifragment, - $return); - return $return; + $parsed = $this->parse_iri((string) $iri); + if (!$parsed) + { + return false; } + + $return = $this->set_scheme($parsed['scheme']) + && $this->set_authority($parsed['authority']) + && $this->set_path($parsed['path']) + && $this->set_query($parsed['query']) + && $this->set_fragment($parsed['fragment']); + + $cache[$iri] = array($this->scheme, + $this->iuserinfo, + $this->ihost, + $this->port, + $this->ipath, + $this->iquery, + $this->ifragment, + $return); + return $return; } /** @@ -915,42 +900,40 @@ public function set_authority($authority, $clear_cache = false) return $return; } + + $remaining = $authority; + if (($iuserinfo_end = strrpos($remaining, '@')) !== false) + { + $iuserinfo = substr($remaining, 0, $iuserinfo_end); + $remaining = substr($remaining, $iuserinfo_end + 1); + } else { - $remaining = $authority; - if (($iuserinfo_end = strrpos($remaining, '@')) !== false) - { - $iuserinfo = substr($remaining, 0, $iuserinfo_end); - $remaining = substr($remaining, $iuserinfo_end + 1); - } - else - { - $iuserinfo = null; - } - if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) - { - if (($port = substr($remaining, $port_start + 1)) === false) - { - $port = null; - } - $remaining = substr($remaining, 0, $port_start); - } - else + $iuserinfo = null; + } + if (($port_start = strpos($remaining, ':', strpos($remaining, ']'))) !== false) + { + if (($port = substr($remaining, $port_start + 1)) === false) { $port = null; } + $remaining = substr($remaining, 0, $port_start); + } + else + { + $port = null; + } - $return = $this->set_userinfo($iuserinfo) && - $this->set_host($remaining) && - $this->set_port($port); + $return = $this->set_userinfo($iuserinfo) && + $this->set_host($remaining) && + $this->set_port($port); - $cache[$authority] = array($this->iuserinfo, - $this->ihost, - $this->port, - $return); + $cache[$authority] = array($this->iuserinfo, + $this->ihost, + $this->port, + $return); - return $return; - } + return $return; } /** @@ -1050,11 +1033,9 @@ public function set_port($port) $this->scheme_normalization(); return true; } - else - { - $this->port = null; - return false; - } + + $this->port = null; + return false; } /** @@ -1066,7 +1047,7 @@ public function set_port($port) public function set_path($ipath, $clear_cache = false) { static $cache; - if ($clear_cache) + if ($clear_cache) { $cache = null; return; @@ -1185,7 +1166,7 @@ public function get_iri() { $iri .= $this->ipath; } - elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '') + elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '') { $iri .= $this->normalization[$this->scheme]['ipath']; } @@ -1229,16 +1210,14 @@ protected function get_iauthority() { $iauthority .= $this->ihost; } - if ($this->port !== null) + if ($this->port !== null && $this->port !== 0) { $iauthority .= ':' . $this->port; } return $iauthority; } - else - { - return null; - } + + return null; } /** @@ -1251,7 +1230,7 @@ protected function get_authority() $iauthority = $this->get_iauthority(); if (is_string($iauthority)) return $this->to_uri($iauthority); - else - return $iauthority; + + return $iauthority; } } diff --git a/lib/simplepie/library/SimplePie/Item.php b/lib/simplepie/library/SimplePie/Item.php index 00f4179bffd..9b9c1f5db8d 100644 --- a/lib/simplepie/library/SimplePie/Item.php +++ b/lib/simplepie/library/SimplePie/Item.php @@ -147,10 +147,8 @@ public function get_item_tags($namespace, $tag) { return $this->data['child'][$namespace][$tag]; } - else - { - return null; - } + + return null; } /** @@ -366,10 +364,8 @@ public function get_description($description_only = false) { return $this->get_content(true); } - else - { - return null; - } + + return null; } /** @@ -407,18 +403,16 @@ public function get_content($content_only = false) { return $this->get_description(true); } - else - { - return null; - } + + return null; } - + /** * Get the media:thumbnail of the item * * Uses `` * - * + * * @return array|null */ public function get_thumbnail() @@ -435,7 +429,7 @@ public function get_thumbnail() } } return $this->data['thumbnail']; - } + } /** * Get a category for the item @@ -451,10 +445,8 @@ public function get_category($key = 0) { return $categories[$key]; } - else - { - return null; - } + + return null; } /** @@ -477,15 +469,15 @@ public function get_categories() $label = null; if (isset($category['attribs']['']['term'])) { - $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_HTML); + $term = $this->sanitize($category['attribs']['']['term'], SIMPLEPIE_CONSTRUCT_TEXT); } if (isset($category['attribs']['']['scheme'])) { - $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_HTML); + $scheme = $this->sanitize($category['attribs']['']['scheme'], SIMPLEPIE_CONSTRUCT_TEXT); } if (isset($category['attribs']['']['label'])) { - $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_HTML); + $label = $this->sanitize($category['attribs']['']['label'], SIMPLEPIE_CONSTRUCT_TEXT); } $categories[] = $this->registry->create('Category', array($term, $scheme, $label, $type)); } @@ -493,10 +485,10 @@ public function get_categories() { // This is really the label, but keep this as the term also for BC. // Label will also work on retrieving because that falls back to term. - $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML); + $term = $this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT); if (isset($category['attribs']['']['domain'])) { - $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_HTML); + $scheme = $this->sanitize($category['attribs']['']['domain'], SIMPLEPIE_CONSTRUCT_TEXT); } else { @@ -508,21 +500,19 @@ public function get_categories() $type = 'subject'; foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, $type) as $category) { - $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type)); + $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type)); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, $type) as $category) { - $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null, $type)); + $categories[] = $this->registry->create('Category', array($this->sanitize($category['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null, $type)); } if (!empty($categories)) { return array_unique($categories); } - else - { - return null; - } + + return null; } /** @@ -539,10 +529,8 @@ public function get_author($key = 0) { return $authors[$key]; } - else - { - return null; - } + + return null; } /** @@ -559,10 +547,8 @@ public function get_contributor($key = 0) { return $contributors[$key]; } - else - { - return null; - } + + return null; } /** @@ -571,7 +557,7 @@ public function get_contributor($key = 0) * Uses `` * * @since 1.1 - * @return array|null List of {@see SimplePie_Author} objects + * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects */ public function get_contributors() { @@ -625,10 +611,8 @@ public function get_contributors() { return array_unique($contributors); } - else - { - return null; - } + + return null; } /** @@ -637,7 +621,7 @@ public function get_contributors() * Uses ``, ``, `` or `` * * @since Beta 2 - * @return array|null List of {@see SimplePie_Author} objects + * @return SimplePie_Author[]|null List of {@see SimplePie_Author} objects */ public function get_authors() { @@ -649,7 +633,7 @@ public function get_authors() $email = null; if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])) { - $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML); + $name = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['uri'][0]['data'])) { @@ -657,7 +641,7 @@ public function get_authors() } if (isset($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'])) { - $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML); + $email = $this->sanitize($author['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } if ($name !== null || $email !== null || $uri !== null) { @@ -671,7 +655,7 @@ public function get_authors() $email = null; if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'])) { - $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML); + $name = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['name'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['url'][0]['data'])) { @@ -679,7 +663,7 @@ public function get_authors() } if (isset($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'])) { - $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_HTML); + $email = $this->sanitize($author[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_03]['email'][0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } if ($name !== null || $email !== null || $url !== null) { @@ -688,19 +672,19 @@ public function get_authors() } if ($author = $this->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'author')) { - $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_HTML))); + $authors[] = $this->registry->create('Author', array(null, null, $this->sanitize($author[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT))); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_11, 'creator') as $author) { - $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null)); + $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_DC_10, 'creator') as $author) { - $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null)); + $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); } foreach ((array) $this->get_item_tags(SIMPLEPIE_NAMESPACE_ITUNES, 'author') as $author) { - $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_HTML), null, null)); + $authors[] = $this->registry->create('Author', array($this->sanitize($author['data'], SIMPLEPIE_CONSTRUCT_TEXT), null, null)); } if (!empty($authors)) @@ -715,10 +699,8 @@ public function get_authors() { return $authors; } - else - { - return null; - } + + return null; } /** @@ -743,10 +725,8 @@ public function get_copyright() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } /** @@ -825,10 +805,8 @@ public function get_date($date_format = 'j F Y, g:i a') return date($date_format, $this->data['date']['parsed']); } } - else - { - return null; - } + + return null; } /** @@ -876,10 +854,8 @@ public function get_updated_date($date_format = 'j F Y, g:i a') return date($date_format, $this->data['updated']['parsed']); } } - else - { - return null; - } + + return null; } /** @@ -905,10 +881,8 @@ public function get_local_date($date_format = '%c') { return strftime($date_format, $date); } - else - { - return null; - } + + return null; } /** @@ -969,10 +943,8 @@ public function get_permalink() { return $enclosure->get_link(); } - else - { - return null; - } + + return null; } /** @@ -990,10 +962,8 @@ public function get_link($key = 0, $rel = 'alternate') { return $links[$key]; } - else - { - return null; - } + + return null; } /** @@ -1073,10 +1043,8 @@ public function get_links($rel = 'alternate') { return $this->data['links'][$rel]; } - else - { - return null; - } + + return null; } /** @@ -1096,10 +1064,8 @@ public function get_enclosure($key = 0, $prefer = null) { return $enclosures[$key]; } - else - { - return null; - } + + return null; } /** @@ -2922,10 +2888,8 @@ public function get_enclosures() { return $this->data['enclosures']; } - else - { - return null; - } + + return null; } /** @@ -2950,10 +2914,8 @@ public function get_latitude() { return (float) $match[1]; } - else - { - return null; - } + + return null; } /** @@ -2982,10 +2944,8 @@ public function get_longitude() { return (float) $match[2]; } - else - { - return null; - } + + return null; } /** @@ -3000,10 +2960,7 @@ public function get_source() { return $this->registry->create('Source', array($this, $return[0])); } - else - { - return null; - } + + return null; } } - diff --git a/lib/simplepie/library/SimplePie/Locator.php b/lib/simplepie/library/SimplePie/Locator.php index bc314c2cdcd..3876a2da6bb 100644 --- a/lib/simplepie/library/SimplePie/Locator.php +++ b/lib/simplepie/library/SimplePie/Locator.php @@ -62,14 +62,18 @@ class SimplePie_Locator var $base_location = 0; var $checked_feeds = 0; var $max_checked_feeds = 10; + var $force_fsockopen = false; + var $curl_options = array(); protected $registry; - public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10) + public function __construct(SimplePie_File $file, $timeout = 10, $useragent = null, $max_checked_feeds = 10, $force_fsockopen = false, $curl_options = array()) { $this->file = $file; $this->useragent = $useragent; $this->timeout = $timeout; $this->max_checked_feeds = $max_checked_feeds; + $this->force_fsockopen = $force_fsockopen; + $this->curl_options = $curl_options; if (class_exists('DOMDocument')) { @@ -154,14 +158,8 @@ public function is_feed($file, $check_html = false) { $mime_types[] = 'text/html'; } - if (in_array($sniffed, $mime_types)) - { - return true; - } - else - { - return false; - } + + return in_array($sniffed, $mime_types); } elseif ($file->method & SIMPLEPIE_FILE_SOURCE_LOCAL) { @@ -210,10 +208,8 @@ public function autodiscovery() { return array_values($feeds); } - else - { - return null; - } + + return null; } protected function search_elements_by_tag($name, &$done, $feeds) @@ -254,7 +250,7 @@ protected function search_elements_by_tag($name, &$done, $feeds) $headers = array( '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', ); - $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent)); + $feed = $this->registry->create('File', array($href, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed, true)) { $feeds[$href] = $feed; @@ -384,7 +380,7 @@ public function extension(&$array) $headers = array( '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', ); - $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent)); + $feed = $this->registry->create('File', array($value, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options)); if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) { return array($feed); @@ -412,7 +408,7 @@ public function body(&$array) $headers = array( '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', ); - $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent)); + $feed = $this->registry->create('File', array($value, $this->timeout, 5, null, $this->useragent, $this->force_fsockopen, $this->curl_options)); if ($feed->success && ($feed->method & SIMPLEPIE_FILE_SOURCE_REMOTE === 0 || ($feed->status_code === 200 || $feed->status_code > 206 && $feed->status_code < 300)) && $this->is_feed($feed)) { return array($feed); @@ -426,4 +422,3 @@ public function body(&$array) return null; } } - diff --git a/lib/simplepie/library/SimplePie/Misc.php b/lib/simplepie/library/SimplePie/Misc.php index 2e3107eb404..2a2ecc575bc 100644 --- a/lib/simplepie/library/SimplePie/Misc.php +++ b/lib/simplepie/library/SimplePie/Misc.php @@ -217,10 +217,8 @@ public static function fix_protocol($url, $http = 1) { return substr_replace($url, 'itpc', 0, 4); } - else - { - return $url; - } + + return $url; } public static function array_merge_recursive($array1, $array2) @@ -234,9 +232,9 @@ public static function array_merge_recursive($array1, $array2) else { $array1[$key] = $value; - } + } } - + return $array1; } @@ -276,10 +274,8 @@ public static function percent_encoding_normalization($match) { return chr($integer); } - else - { - return strtoupper($match[0]); - } + + return strtoupper($match[0]); } /** @@ -343,11 +339,9 @@ public static function change_encoding($data, $input, $output) { return $return; } + // If we can't do anything, just fail - else - { - return false; - } + return false; } protected static function change_encoding_mbstring($data, $input, $output) @@ -1858,10 +1852,8 @@ public static function parse_mime($mime) { return trim($mime); } - else - { - return trim(substr($mime, 0, $pos)); - } + + return trim(substr($mime, 0, $pos)); } public static function atom_03_construct_type($attribs) @@ -1894,10 +1886,8 @@ public static function atom_03_construct_type($attribs) return SIMPLEPIE_CONSTRUCT_NONE | $mode; } } - else - { - return SIMPLEPIE_CONSTRUCT_TEXT | $mode; - } + + return SIMPLEPIE_CONSTRUCT_TEXT | $mode; } public static function atom_10_construct_type($attribs) @@ -1947,10 +1937,8 @@ public static function atom_10_content_construct_type($attribs) return SIMPLEPIE_CONSTRUCT_BASE64; } } - else - { - return SIMPLEPIE_CONSTRUCT_TEXT; - } + + return SIMPLEPIE_CONSTRUCT_TEXT; } public static function is_isegment_nz_nc($string) @@ -2007,11 +1995,9 @@ public static function codepoint_to_utf8($codepoint) { return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f)); } - else - { - // U+FFFD REPLACEMENT CHARACTER - return "\xEF\xBF\xBD"; - } + + // U+FFFD REPLACEMENT CHARACTER + return "\xEF\xBF\xBD"; } /** @@ -2215,10 +2201,8 @@ public static function get_build() { return filemtime(dirname(__FILE__) . '/Core.php'); } - else - { - return filemtime(__FILE__); - } + + return filemtime(__FILE__); } /** @@ -2276,4 +2260,3 @@ public static function silence_errors($num, $str) // No-op } } - diff --git a/lib/simplepie/library/SimplePie/Net/IPv6.php b/lib/simplepie/library/SimplePie/Net/IPv6.php index 47658aff2af..a054e8be579 100644 --- a/lib/simplepie/library/SimplePie/Net/IPv6.php +++ b/lib/simplepie/library/SimplePie/Net/IPv6.php @@ -173,10 +173,8 @@ public static function compress($ip) { return implode(':', $ip_parts); } - else - { - return $ip_parts[0]; - } + + return $ip_parts[0]; } /** @@ -200,10 +198,8 @@ private static function split_v6_v4($ip) $ipv4_part = substr($ip, $pos + 1); return array($ipv6_part, $ipv4_part); } - else - { - return array($ip, ''); - } + + return array($ip, ''); } /** @@ -253,10 +249,8 @@ public static function check_ipv6($ip) } return true; } - else - { - return false; - } + + return false; } /** diff --git a/lib/simplepie/library/SimplePie/Parse/Date.php b/lib/simplepie/library/SimplePie/Parse/Date.php index 1f21566556e..85c4776bdf9 100644 --- a/lib/simplepie/library/SimplePie/Parse/Date.php +++ b/lib/simplepie/library/SimplePie/Parse/Date.php @@ -145,6 +145,14 @@ class SimplePie_Parse_Date 'Παρ' => 5, 'Σαβ' => 6, 'Κυρ' => 7, + // Russian + 'Пн.' => 1, + 'Вт.' => 2, + 'Ср.' => 3, + 'Чт.' => 4, + 'Пт.' => 5, + 'Сб.' => 6, + 'Вс.' => 7, ); /** @@ -289,7 +297,33 @@ class SimplePie_Parse_Date 'Σεπ' => 9, 'Οκτ' => 10, 'Νοέ' => 11, - 'Δεκ' => 12, + 'Δεκ' => 12, + // Russian + 'Янв' => 1, + 'января' => 1, + 'Фев' => 2, + 'февраля' => 2, + 'Мар' => 3, + 'марта' => 3, + 'Апр' => 4, + 'апреля' => 4, + 'Май' => 5, + 'мая' => 5, + 'Июн' => 6, + 'июня' => 6, + 'Июл' => 7, + 'июля' => 7, + 'Авг' => 8, + 'августа' => 8, + 'Сен' => 9, + 'сентября' => 9, + 'Окт' => 10, + 'октября' => 10, + 'Ноя' => 11, + 'ноября' => 11, + 'Дек' => 12, + 'декабря' => 12, + ); /** @@ -694,10 +728,8 @@ public function date_w3cdtf($date) return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone; } - else - { - return false; - } + + return false; } /** @@ -848,10 +880,8 @@ public function date_rfc2822($date) return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone; } - else - { - return false; - } + + return false; } /** @@ -913,10 +943,8 @@ public function date_rfc850($date) return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone; } - else - { - return false; - } + + return false; } /** @@ -955,10 +983,8 @@ public function date_asctime($date) $month = $this->month[strtolower($match[2])]; return gmmktime($match[4], $match[5], $match[6], $month, $match[3], $match[7]); } - else - { - return false; - } + + return false; } /** @@ -974,10 +1000,7 @@ public function date_strtotime($date) { return false; } - else - { - return $strtotime; - } + + return $strtotime; } } - diff --git a/lib/simplepie/library/SimplePie/Parser.php b/lib/simplepie/library/SimplePie/Parser.php index 17139abe95a..3cef2287dba 100644 --- a/lib/simplepie/library/SimplePie/Parser.php +++ b/lib/simplepie/library/SimplePie/Parser.php @@ -76,26 +76,17 @@ public function set_registry(SimplePie_Registry $registry) public function parse(&$data, $encoding, $url = '') { - if (function_exists('Mf2\parse')) { + if (class_exists('DOMXpath') && function_exists('Mf2\parse')) { + $doc = new DOMDocument(); + @$doc->loadHTML($data); + $xpath = new DOMXpath($doc); // Check for both h-feed and h-entry, as both a feed with no entries // and a list of entries without an h-feed wrapper are both valid. - $position = 0; - while ($position = strpos($data, 'h-feed', $position)) { - $start = $position < 200 ? 0 : $position - 200; - $check = substr($data, $start, 400); - if (preg_match('/class="[^"]*h-feed/', $check)) { - return $this->parse_microformats($data, $url); - } - $position += 7; - } - $position = 0; - while ($position = strpos($data, 'h-entry', $position)) { - $start = $position < 200 ? 0 : $position - 200; - $check = substr($data, $start, 400); - if (preg_match('/class="[^"]*h-entry/', $check)) { - return $this->parse_microformats($data, $url); - } - $position += 7; + $query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '. + 'contains(concat(" ", @class, " "), " h-entry ")]'; + $result = $xpath->query($query); + if ($result->length !== 0) { + return $this->parse_microformats($data, $url); } } @@ -185,76 +176,72 @@ public function parse(&$data, $encoding, $url = '') xml_parser_free($xml); return $return; } - else + + libxml_clear_errors(); + $xml = new XMLReader(); + $xml->xml($data); + while (@$xml->read()) { - libxml_clear_errors(); - $xml = new XMLReader(); - $xml->xml($data); - while (@$xml->read()) + switch ($xml->nodeType) { - switch ($xml->nodeType) - { - case constant('XMLReader::END_ELEMENT'): + case constant('XMLReader::END_ELEMENT'): + if ($xml->namespaceURI !== '') + { + $tagName = $xml->namespaceURI . $this->separator . $xml->localName; + } + else + { + $tagName = $xml->localName; + } + $this->tag_close(null, $tagName); + break; + case constant('XMLReader::ELEMENT'): + $empty = $xml->isEmptyElement; + if ($xml->namespaceURI !== '') + { + $tagName = $xml->namespaceURI . $this->separator . $xml->localName; + } + else + { + $tagName = $xml->localName; + } + $attributes = array(); + while ($xml->moveToNextAttribute()) + { if ($xml->namespaceURI !== '') { - $tagName = $xml->namespaceURI . $this->separator . $xml->localName; + $attrName = $xml->namespaceURI . $this->separator . $xml->localName; } else { - $tagName = $xml->localName; + $attrName = $xml->localName; } + $attributes[$attrName] = $xml->value; + } + $this->tag_open(null, $tagName, $attributes); + if ($empty) + { $this->tag_close(null, $tagName); - break; - case constant('XMLReader::ELEMENT'): - $empty = $xml->isEmptyElement; - if ($xml->namespaceURI !== '') - { - $tagName = $xml->namespaceURI . $this->separator . $xml->localName; - } - else - { - $tagName = $xml->localName; - } - $attributes = array(); - while ($xml->moveToNextAttribute()) - { - if ($xml->namespaceURI !== '') - { - $attrName = $xml->namespaceURI . $this->separator . $xml->localName; - } - else - { - $attrName = $xml->localName; - } - $attributes[$attrName] = $xml->value; - } - $this->tag_open(null, $tagName, $attributes); - if ($empty) - { - $this->tag_close(null, $tagName); - } - break; - case constant('XMLReader::TEXT'): + } + break; + case constant('XMLReader::TEXT'): - case constant('XMLReader::CDATA'): - $this->cdata(null, $xml->value); - break; - } - } - if ($error = libxml_get_last_error()) - { - $this->error_code = $error->code; - $this->error_string = $error->message; - $this->current_line = $error->line; - $this->current_column = $error->column; - return false; - } - else - { - return true; + case constant('XMLReader::CDATA'): + $this->cdata(null, $xml->value); + break; } } + if ($error = libxml_get_last_error()) + { + $this->error_code = $error->code; + $this->error_string = $error->message; + $this->current_line = $error->line; + $this->current_column = $error->column; + return false; + } + + return true; } public function get_error_code() @@ -465,7 +452,7 @@ private function parse_microformats(&$data, $url) { $h_feed = $mf_item; break; } - // Also look for an h-feed in the children of each top level item. + // Also look for h-feed or h-entry in the children of each top level item. if (!isset($mf_item['children'][0]['type'])) continue; if (in_array('h-feed', $mf_item['children'][0]['type'])) { $h_feed = $mf_item['children'][0]; @@ -474,6 +461,13 @@ private function parse_microformats(&$data, $url) { if (in_array('h-card', $mf_item['type'])) $feed_author = $mf_item; break; } + else if (in_array('h-entry', $mf_item['children'][0]['type'])) { + $entries = $mf_item['children']; + // In this case the parent of the h-entry list may be an h-card, so use + // it as the feed_author. + if (in_array('h-card', $mf_item['type'])) $feed_author = $mf_item; + break; + } } if (isset($h_feed['children'])) { $entries = $h_feed['children']; @@ -485,7 +479,7 @@ private function parse_microformats(&$data, $url) { $feed_author = $mf['items'][0]['properties']['author'][0]; } } - else { + else if (count($entries) === 0) { $entries = $mf['items']; } for ($i = 0; $i < count($entries); $i++) { @@ -554,18 +548,21 @@ private function parse_microformats(&$data, $url) { $photo_list = array(); for ($j = 0; $j < count($entry['properties']['photo']); $j++) { $photo = $entry['properties']['photo'][$j]; - if (strpos($content, $photo) === false) { + if (!empty($photo) && strpos($content, $photo) === false) { $photo_list[] = $photo; } } // When there's more than one photo show the first and use a lightbox. + // Need a permanent, unique name for the image set, but don't have + // anything unique except for the content itself, so use that. $count = count($photo_list); if ($count > 1) { + $image_set_id = preg_replace('/[[:^alnum:]]/', '', $photo_list[0]); $description = '

'; for ($j = 0; $j < $count; $j++) { $hidden = $j === 0 ? '' : 'class="hidden" '; $description .= ''. + 'data-lightbox="image-set-'.$image_set_id.'">'. ''; } $description .= '
'.$count.' photos

'; @@ -583,10 +580,18 @@ private function parse_microformats(&$data, $url) { $item['title'] = array(array('data' => $title)); } $description .= $entry['properties']['content'][0]['html']; - if (isset($entry['properties']['in-reply-to'][0]['value'])) { - $in_reply_to = $entry['properties']['in-reply-to'][0]['value']; - $description .= '

'. - ''.$in_reply_to.'

'; + if (isset($entry['properties']['in-reply-to'][0])) { + $in_reply_to = ''; + if (is_string($entry['properties']['in-reply-to'][0])) { + $in_reply_to = $entry['properties']['in-reply-to'][0]; + } + else if (isset($entry['properties']['in-reply-to'][0]['value'])) { + $in_reply_to = $entry['properties']['in-reply-to'][0]['value']; + } + if ($in_reply_to !== '') { + $description .= '

'. + ''.$in_reply_to.'

'; + } } $item['description'] = array(array('data' => $description)); } @@ -627,7 +632,7 @@ private function parse_microformats(&$data, $url) { $image = array(array('child' => array('' => array('url' => array(array('data' => $feed_author['properties']['photo'][0])))))); } - // Use the a name given for the h-feed, or get the title from the html. + // Use the name given for the h-feed, or get the title from the html. if ($feed_title !== '') { $feed_title = array(array('data' => htmlspecialchars($feed_title))); } @@ -653,4 +658,4 @@ private function declare_html_entities() { // html is allowed, but the xml specification says they must be declared. return ' ]>'; } -} \ No newline at end of file +} diff --git a/lib/simplepie/library/SimplePie/Rating.php b/lib/simplepie/library/SimplePie/Rating.php index eaf57080c0d..108dd22bfa6 100644 --- a/lib/simplepie/library/SimplePie/Rating.php +++ b/lib/simplepie/library/SimplePie/Rating.php @@ -103,10 +103,8 @@ public function get_scheme() { return $this->scheme; } - else - { - return null; - } + + return null; } /** @@ -120,9 +118,7 @@ public function get_value() { return $this->value; } - else - { - return null; - } + + return null; } } diff --git a/lib/simplepie/library/SimplePie/Registry.php b/lib/simplepie/library/SimplePie/Registry.php old mode 100644 new mode 100755 diff --git a/lib/simplepie/library/SimplePie/Restriction.php b/lib/simplepie/library/SimplePie/Restriction.php index 001a5cd2821..803d84fde92 100644 --- a/lib/simplepie/library/SimplePie/Restriction.php +++ b/lib/simplepie/library/SimplePie/Restriction.php @@ -112,10 +112,8 @@ public function get_relationship() { return $this->relationship; } - else - { - return null; - } + + return null; } /** @@ -129,10 +127,8 @@ public function get_type() { return $this->type; } - else - { - return null; - } + + return null; } /** @@ -146,9 +142,7 @@ public function get_value() { return $this->value; } - else - { - return null; - } + + return null; } } diff --git a/lib/simplepie/library/SimplePie/Sanitize.php b/lib/simplepie/library/SimplePie/Sanitize.php index 5a11721df12..40b06626639 100644 --- a/lib/simplepie/library/SimplePie/Sanitize.php +++ b/lib/simplepie/library/SimplePie/Sanitize.php @@ -354,7 +354,7 @@ public function sanitize($data, $type, $base = '') } else { - trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING); + 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); } } } diff --git a/lib/simplepie/library/SimplePie/Source.php b/lib/simplepie/library/SimplePie/Source.php index 1a66a392db5..8fac13ef7eb 100644 --- a/lib/simplepie/library/SimplePie/Source.php +++ b/lib/simplepie/library/SimplePie/Source.php @@ -79,10 +79,8 @@ public function get_source_tags($namespace, $tag) { return $this->data['child'][$namespace][$tag]; } - else - { - return null; - } + + return null; } public function get_base($element = array()) @@ -130,10 +128,8 @@ public function get_title() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } public function get_category($key = 0) @@ -143,10 +139,8 @@ public function get_category($key = 0) { return $categories[$key]; } - else - { - return null; - } + + return null; } public function get_categories() @@ -200,10 +194,8 @@ public function get_categories() { return array_unique($categories); } - else - { - return null; - } + + return null; } public function get_author($key = 0) @@ -213,10 +205,8 @@ public function get_author($key = 0) { return $authors[$key]; } - else - { - return null; - } + + return null; } public function get_authors() @@ -283,10 +273,8 @@ public function get_authors() { return array_unique($authors); } - else - { - return null; - } + + return null; } public function get_contributor($key = 0) @@ -296,10 +284,8 @@ public function get_contributor($key = 0) { return $contributors[$key]; } - else - { - return null; - } + + return null; } public function get_contributors() @@ -354,10 +340,8 @@ public function get_contributors() { return array_unique($contributors); } - else - { - return null; - } + + return null; } public function get_link($key = 0, $rel = 'alternate') @@ -367,10 +351,8 @@ public function get_link($key = 0, $rel = 'alternate') { return $links[$key]; } - else - { - return null; - } + + return null; } /** @@ -449,10 +431,8 @@ public function get_links($rel = 'alternate') { return $this->data['links'][$rel]; } - else - { - return null; - } + + return null; } public function get_description() @@ -493,10 +473,8 @@ public function get_description() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0])); } - else - { - return null; - } + + return null; } public function get_copyright() @@ -521,10 +499,8 @@ public function get_copyright() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } public function get_language() @@ -545,10 +521,8 @@ public function get_language() { return $this->sanitize($this->data['xml_lang'], SIMPLEPIE_CONSTRUCT_TEXT); } - else - { - return null; - } + + return null; } public function get_latitude() @@ -561,10 +535,8 @@ public function get_latitude() { return (float) $match[1]; } - else - { - return null; - } + + return null; } public function get_longitude() @@ -581,10 +553,8 @@ public function get_longitude() { return (float) $match[2]; } - else - { - return null; - } + + return null; } public function get_image_url() @@ -601,10 +571,7 @@ public function get_image_url() { return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0])); } - else - { - return null; - } + + return null; } } - diff --git a/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php b/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php index 99e751672a5..18ca1b79b5e 100644 --- a/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php +++ b/lib/simplepie/library/SimplePie/XML/Declaration/Parser.php @@ -136,13 +136,11 @@ public function parse() { return true; } - else - { - $this->version = ''; - $this->encoding = ''; - $this->standalone = ''; - return false; - } + + $this->version = ''; + $this->encoding = ''; + $this->standalone = ''; + return false; } /** diff --git a/lib/simplepie/library/SimplePie/gzdecode.php b/lib/simplepie/library/SimplePie/gzdecode.php index 0e8bc8fc695..f4aeafa2885 100644 --- a/lib/simplepie/library/SimplePie/gzdecode.php +++ b/lib/simplepie/library/SimplePie/gzdecode.php @@ -338,10 +338,8 @@ public function parse() { return false; } - else - { - $this->position = $this->compressed_size - 8; - } + + $this->position = $this->compressed_size - 8; // Check CRC of data $crc = current(unpack('V', substr($this->compressed_data, $this->position, 4))); @@ -362,9 +360,7 @@ public function parse() // Wow, against all odds, we've actually got a valid gzip string return true; } - else - { - return false; - } + + return false; } }