Make WordPress Core


Ignore:
Timestamp:
05/01/2020 02:24:42 PM (5 years ago)
Author:
desrosj
Message:

External Libraries: Update the SimplePie library to the latest version (1.5.5).

This brings SimplePie in sync with the most up to date version, 1.5.5.

This update brings many bug fixes, small enhancements, and PHP compatibility fixes for newer versions of PHP.

For a full list of changes, see https://github.com/simplepie/simplepie/blob/master/CHANGELOG.md#155-may-1-2020.

Props dshanske, slushman, etruel, wpshades, dmenard, desrosj, hareesh-pillai, stevenkword, jrf, Ipstenu, johnbillion.
Fixes #36669.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-simplepie.php

    r47198 r47733  
    4141 * Takes the hard work out of managing a complete RSS/Atom solution.
    4242 *
    43  * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
     43 * Copyright (c) 2004-2017, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
    4444 * All rights reserved.
    4545 *
     
    6969 *
    7070 * @package SimplePie
    71  * @version 1.3.1
    72  * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
     71 * @version 1.5.5
     72 * @copyright 2004-2017 Ryan Parman, Sam Sneddon, Ryan McCue
    7373 * @author Ryan Parman
    74  * @author Geoffrey Sneddon
     74 * @author Sam Sneddon
    7575 * @author Ryan McCue
    7676 * @link http://simplepie.org/ SimplePie
     
    8686 * SimplePie Version
    8787 */
    88 define('SIMPLEPIE_VERSION', '1.3.1');
     88define('SIMPLEPIE_VERSION', '1.5.5');
    8989
    9090/**
     
    482482
    483483    /**
     484     * @var string Original feed URL, or new feed URL iff HTTP 301 Moved Permanently
     485     * @see SimplePie::subscribe_url()
     486     * @access private
     487     */
     488    public $permanent_url = null;
     489
     490    /**
    484491     * @var object Instance of SimplePie_File to use as a feed
    485492     * @see SimplePie::set_file()
     
    501508     */
    502509    public $timeout = 10;
     510
     511    /**
     512     * @var array Custom curl options
     513     * @see SimplePie::set_curl_options()
     514     * @access private
     515     */
     516    public $curl_options = array();
    503517
    504518    /**
     
    526540
    527541    /**
     542     * @var bool Force SimplePie to fallback to expired cache, if enabled,
     543     * when feed is unavailable.
     544     * @see SimplePie::force_cache_fallback()
     545     * @access private
     546     */
     547    public $force_cache_fallback = false;
     548
     549    /**
    528550     * @var int Cache duration (in seconds)
    529551     * @see SimplePie::set_cache_duration()
     
    631653
    632654    /**
     655     * @var bool Stores if last-modified and/or etag headers were sent with the
     656     * request when checking a feed.
     657     */
     658    public $check_modified = false;
     659
     660    /**
    633661     * @var array Stores the default attributes to be stripped by strip_attributes().
    634662     * @see SimplePie::strip_attributes()
     
    638666
    639667    /**
     668     * @var array Stores the default attributes to add to different tags by add_attributes().
     669     * @see SimplePie::add_attributes()
     670     * @access private
     671     */
     672    public $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none'));
     673
     674    /**
    640675     * @var array Stores the default tags to be stripped by strip_htmltags().
    641676     * @see SimplePie::strip_htmltags()
     
    643678     */
    644679    public $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
     680
     681    /**
     682     * @var bool Should we throw exceptions, or use the old-style error property?
     683     * @access private
     684     */
     685    public $enable_exceptions = false;
    645686
    646687    /**
     
    660701    public function __construct()
    661702    {
    662         if (version_compare(PHP_VERSION, '5.2', '<'))
    663         {
    664             trigger_error('PHP 4.x, 5.0 and 5.1 are no longer supported. Please upgrade to PHP 5.2 or newer.');
     703        if (version_compare(PHP_VERSION, '5.6', '<'))
     704        {
     705            trigger_error('Please upgrade to PHP 5.6 or newer.');
    665706            die();
    666707        }
     
    673714        {
    674715            $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_WARNING;
    675             trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_location() directly.', $level);
     716            trigger_error('Passing parameters to the constructor is no longer supported. Please use set_feed_url(), set_cache_location(), and set_cache_duration() directly.', $level);
    676717
    677718            $args = func_get_args();
     
    701742    public function __destruct()
    702743    {
    703         if ((version_compare(PHP_VERSION, '5.3', '<') || !gc_enabled()) && !ini_get('zend.ze1_compatibility_mode'))
     744        if (!gc_enabled())
    704745        {
    705746            if (!empty($this->data['items']))
     
    764805        {
    765806            $this->feed_url = $this->registry->call('Misc', 'fix_protocol', array($url, 1));
     807            $this->permanent_url = $this->feed_url;
    766808        }
    767809    }
     
    778820        {
    779821            $this->feed_url = $file->url;
     822            $this->permanent_url = $this->feed_url;
    780823            $this->file =& $file;
    781824            return true;
     
    803846
    804847    /**
    805      * Set the the default timeout for fetching remote feeds
     848     * Set the default timeout for fetching remote feeds
    806849     *
    807850     * This allows you to change the maximum time the feed's server to respond
     
    817860
    818861    /**
     862     * Set custom curl options
     863     *
     864     * This allows you to change default curl options
     865     *
     866     * @since 1.0 Beta 3
     867     * @param array $curl_options Curl options to add to default settings
     868     */
     869    public function set_curl_options(array $curl_options = array())
     870    {
     871        $this->curl_options = $curl_options;
     872    }
     873
     874    /**
    819875     * Force SimplePie to use fsockopen() instead of cURL
    820876     *
     
    839895    {
    840896        $this->cache = (bool) $enable;
     897    }
     898
     899    /**
     900     * SimplePie to continue to fall back to expired cache, if enabled, when
     901     * feed is unavailable.
     902     *
     903     * This tells SimplePie to ignore any file errors and fall back to cache
     904     * instead. This only works if caching is enabled and cached content
     905     * still exists.
     906
     907     * @param bool $enable Force use of cache on fail.
     908     */
     909    public function force_cache_fallback($enable = false)
     910    {
     911        $this->force_cache_fallback= (bool) $enable;
    841912    }
    842913
     
    11091180            $this->strip_htmltags(false);
    11101181            $this->strip_attributes(false);
     1182            $this->add_attributes(false);
    11111183            $this->set_image_handler(false);
    11121184        }
     
    11551227    }
    11561228
     1229    public function add_attributes($attribs = '')
     1230    {
     1231        if ($attribs === '')
     1232        {
     1233            $attribs = $this->add_attributes;
     1234        }
     1235        $this->sanitize->add_attributes($attribs);
     1236    }
     1237
    11571238    /**
    11581239     * Set the output encoding
     
    11601241     * Allows you to override SimplePie's output to match that of your webpage.
    11611242     * This is useful for times when your webpages are not being served as
    1162      * UTF-8.  This setting will be obeyed by {@see handle_content_type()}, and
     1243     * UTF-8. This setting will be obeyed by {@see handle_content_type()}, and
    11631244     * is similar to {@see set_input_encoding()}.
    11641245     *
    11651246     * It should be noted, however, that not all character encodings can support
    1166      * all characters.  If your page is being served as ISO-8859-1 and you try
     1247     * all characters. If your page is being served as ISO-8859-1 and you try
    11671248     * to display a Japanese feed, you'll likely see garbled characters.
    11681249     * Because of this, it is highly recommended to ensure that your webpages
     
    12061287     * Set the handler to enable the display of cached images.
    12071288     *
    1208      * @param str $page Web-accessible path to the handler_image.php file.
    1209      * @param str $qs The query string that the value should be passed to.
     1289     * @param string $page Web-accessible path to the handler_image.php file.
     1290     * @param string $qs The query string that the value should be passed to.
    12101291     */
    12111292    public function set_image_handler($page = false, $qs = 'i')
     
    12321313
    12331314    /**
     1315     * Enable throwing exceptions
     1316     *
     1317     * @param boolean $enable Should we throw exceptions, or use the old-style error property?
     1318     */
     1319    public function enable_exceptions($enable = true)
     1320    {
     1321        $this->enable_exceptions = $enable;
     1322    }
     1323
     1324    /**
    12341325     * Initialize the feed object
    12351326     *
    1236      * This is what makes everything happen.  Period. This is where all of the
     1327     * This is what makes everything happen. Period. This is where all of the
    12371328     * configuration options get processed, feeds are fetched, cached, and
    12381329     * parsed, and all of that other good stuff.
     
    12451336        if (!extension_loaded('xml') || !extension_loaded('pcre'))
    12461337        {
     1338            $this->error = 'XML or PCRE extensions not loaded!';
    12471339            return false;
    12481340        }
     
    12641356        }
    12651357
     1358        // The default sanitize class gets set in the constructor, check if it has
     1359        // changed.
     1360        if ($this->registry->get_class('Sanitize') !== 'SimplePie_Sanitize') {
     1361            $this->sanitize = $this->registry->create('Sanitize');
     1362        }
    12661363        if (method_exists($this->sanitize, 'set_registry'))
    12671364        {
     
    12721369        // Pass the classes in for legacy support; new classes should use the registry instead
    12731370        $this->sanitize->pass_cache_data($this->cache, $this->cache_location, $this->cache_name_function, $this->registry->get_class('Cache'));
    1274         $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen);
     1371        $this->sanitize->pass_file_data($this->registry->get_class('File'), $this->timeout, $this->useragent, $this->force_fsockopen, $this->curl_options);
    12751372
    12761373        if (!empty($this->multifeed_url))
     
    13011398        $this->error = null;
    13021399        $this->data = array();
     1400        $this->check_modified = false;
    13031401        $this->multifeed_objects = array();
    13041402        $cache = false;
     
    13111409            if ($this->cache && $parsed_feed_url['scheme'] !== '')
    13121410            {
    1313                 $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $this->feed_url), 'spc'));
     1411                $url = $this->feed_url . ($this->force_feed ? '#force_feed' : '');
     1412                $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $url), 'spc'));
    13141413            }
    13151414
     
    13261425        }
    13271426
     1427        // Empty response check
     1428        if(empty($this->raw_data)){
     1429            $this->error = "A feed could not be found at `$this->feed_url`. Empty body.";
     1430            $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
     1431            return false;
     1432        }
     1433
    13281434        // Set up array of possible encodings
    13291435        $encodings = array();
     
    13321438        if ($this->input_encoding !== false)
    13331439        {
    1334             $encodings[] = $this->input_encoding;
     1440            $encodings[] = strtoupper($this->input_encoding);
    13351441        }
    13361442
     
    13541460                if (isset($headers['content-type']) && preg_match('/;\x20?charset=([^;]*)/i', $headers['content-type'], $charset))
    13551461                {
    1356                     $encodings[] = $charset[1];
     1462                    $encodings[] = strtoupper($charset[1]);
    13571463                }
    13581464                $encodings[] = 'US-ASCII';
     
    13611467            elseif (substr($sniffed, 0, 5) === 'text/')
    13621468            {
    1363                 $encodings[] = 'US-ASCII';
     1469                $encodings[] = 'UTF-8';
    13641470            }
    13651471        }
     
    13831489
    13841490                // If it's parsed fine
    1385                 if ($parser->parse($utf8_data, 'UTF-8'))
     1491                if ($parser->parse($utf8_data, 'UTF-8', $this->permanent_url))
    13861492                {
    13871493                    $this->data = $parser->get_data();
    13881494                    if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))
    13891495                    {
    1390                         $this->error = "A feed could not be found at $this->feed_url. This does not appear to be a valid RSS or Atom feed.";
     1496                        $this->error = "A feed could not be found at `$this->feed_url`. This does not appear to be a valid RSS or Atom feed.";
    13911497                        $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
    13921498                        return false;
     
    14021508                    if ($cache && !$cache->save($this))
    14031509                    {
    1404                         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);
     1510                        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);
    14051511                    }
    14061512                    return true;
     
    14121518        {
    14131519            // We have an error, just set SimplePie_Misc::error to it and quit
    1414             $this->error = sprintf('This XML document is invalid, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
     1520            $this->error = $this->feed_url;
     1521            $this->error .= sprintf(' is invalid XML, likely due to invalid characters. XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
    14151522        }
    14161523        else
    14171524        {
    1418             $this->error = 'The data could not be converted to UTF-8. You MUST have either the iconv or mbstring extension installed. Upgrading to PHP 5.x (which includes iconv) is highly recommended.';
     1525            $this->error = 'The data could not be converted to UTF-8.';
     1526            if (!extension_loaded('mbstring') && !extension_loaded('iconv') && !class_exists('\UConverter')) {
     1527                $this->error .= ' You MUST have either the iconv, mbstring or intl (PHP 5.5+) extension installed and enabled.';
     1528            } else {
     1529                $missingExtensions = array();
     1530                if (!extension_loaded('iconv')) {
     1531                    $missingExtensions[] = 'iconv';
     1532                }
     1533                if (!extension_loaded('mbstring')) {
     1534                    $missingExtensions[] = 'mbstring';
     1535                }
     1536                if (!class_exists('\UConverter')) {
     1537                    $missingExtensions[] = 'intl (PHP 5.5+)';
     1538                }
     1539                $this->error .= ' Try installing/enabling the ' . implode(' or ', $missingExtensions) . ' extension.';
     1540            }
    14191541        }
    14201542
     
    14721594                elseif ($cache->mtime() + $this->cache_duration < time())
    14731595                {
    1474                     // If we have last-modified and/or etag set
     1596                    // Want to know if we tried to send last-modified and/or etag headers
     1597                    // when requesting this file. (Note that it's up to the file to
     1598                    // support this, but we don't always send the headers either.)
     1599                    $this->check_modified = true;
    14751600                    if (isset($this->data['headers']['last-modified']) || isset($this->data['headers']['etag']))
    14761601                    {
     
    14871612                        }
    14881613
    1489                         $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen));
     1614                        $file = $this->registry->create('File', array($this->feed_url, $this->timeout/10, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
    14901615
    14911616                        if ($file->success)
     
    14931618                            if ($file->status_code === 304)
    14941619                            {
     1620                                // Set raw_data to false here too, to signify that the cache
     1621                                // is still valid.
     1622                                $this->raw_data = false;
    14951623                                $cache->touch();
    14961624                                return true;
     
    14991627                        else
    15001628                        {
     1629                            $this->check_modified = false;
     1630                            if($this->force_cache_fallback)
     1631                            {
     1632                                $cache->touch();
     1633                                return true;
     1634                            }
     1635
    15011636                            unset($file);
    15021637                        }
     
    15291664                    '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',
    15301665                );
    1531                 $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen));
     1666                $file = $this->registry->create('File', array($this->feed_url, $this->timeout, 5, $headers, $this->useragent, $this->force_fsockopen, $this->curl_options));
    15321667            }
    15331668        }
     
    15421677        {
    15431678            // Check if the supplied URL is a feed, if it isn't, look for it.
    1544             $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds));
     1679            $locate = $this->registry->create('Locator', array(&$file, $this->timeout, $this->useragent, $this->max_checked_feeds, $this->force_fsockopen, $this->curl_options));
    15451680
    15461681            if (!$locate->is_feed($file))
    15471682            {
    1548                 // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
    1549                 unset($file);
     1683                $copyStatusCode = $file->status_code;
     1684                $copyContentType = $file->headers['content-type'];
    15501685                try
    15511686                {
    1552                     if (!($file = $locate->find($this->autodiscovery, $this->all_discovered_feeds)))
     1687                    $microformats = false;
     1688                    if (class_exists('DOMXpath') && function_exists('Mf2\parse')) {
     1689                        $doc = new DOMDocument();
     1690                        @$doc->loadHTML($file->body);
     1691                        $xpath = new DOMXpath($doc);
     1692                        // Check for both h-feed and h-entry, as both a feed with no entries
     1693                        // and a list of entries without an h-feed wrapper are both valid.
     1694                        $query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '.
     1695                            'contains(concat(" ", @class, " "), " h-entry ")]';
     1696                        $result = $xpath->query($query);
     1697                        $microformats = $result->length !== 0;
     1698                    }
     1699                    // Now also do feed discovery, but if microformats were found don't
     1700                    // overwrite the current value of file.
     1701                    $discovered = $locate->find($this->autodiscovery,
     1702                                                $this->all_discovered_feeds);
     1703                    if ($microformats)
    15531704                    {
    1554                         $this->error = "A feed could not be found at $this->feed_url. A feed with an invalid mime type may fall victim to this error, or " . SIMPLEPIE_NAME . " was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.";
    1555                         $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
    1556                         return false;
     1705                        if ($hub = $locate->get_rel_link('hub'))
     1706                        {
     1707                            $self = $locate->get_rel_link('self');
     1708                            $this->store_links($file, $hub, $self);
     1709                        }
     1710                        // Push the current file onto all_discovered feeds so the user can
     1711                        // be shown this as one of the options.
     1712                        if (isset($this->all_discovered_feeds)) {
     1713                            $this->all_discovered_feeds[] = $file;
     1714                        }
    15571715                    }
     1716                    else
     1717                    {
     1718                        if ($discovered)
     1719                        {
     1720                            $file = $discovered;
     1721                        }
     1722                        else
     1723                        {
     1724                            // We need to unset this so that if SimplePie::set_file() has
     1725                            // been called that object is untouched
     1726                            unset($file);
     1727                            $this->error = "A feed could not be found at `$this->feed_url`; the status code is `$copyStatusCode` and content-type is `$copyContentType`";
     1728                            $this->registry->call('Misc', 'error', array($this->error, E_USER_NOTICE, __FILE__, __LINE__));
     1729                            return false;
     1730                        }
     1731                    }
    15581732                }
    15591733                catch (SimplePie_Exception $e)
    15601734                {
     1735                    // We need to unset this so that if SimplePie::set_file() has been called that object is untouched
     1736                    unset($file);
    15611737                    // This is usually because DOMDocument doesn't exist
    15621738                    $this->error = $e->getMessage();
     
    15691745                    if (!$cache->save($this))
    15701746                    {
    1571                         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);
     1747                        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);
    15721748                    }
    15731749                    $cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc'));
    15741750                }
    1575                 $this->feed_url = $file->url;
    1576             }
     1751            }
     1752            $this->feed_url = $file->url;
    15771753            $locate = null;
    15781754        }
    15791755
    15801756        $this->raw_data = $file->body;
    1581 
     1757        $this->permanent_url = $file->permanent_url;
    15821758        $headers = $file->headers;
    15831759        $sniffer = $this->registry->create('Content_Type_Sniffer', array(&$file));
     
    15881764
    15891765    /**
    1590      * Get the error message for the occurred error.
     1766     * Get the error message for the occured error
    15911767     *
    15921768     * @return string|array Error message, or array of messages for multifeeds
     
    17661942     * Get the URL for the feed
    17671943     *
    1768      * May or may not be different from the URL passed to {@see set_feed_url()},
    1769      * depending on whether auto-discovery was used.
     1944     * When the 'permanent' mode is enabled, returns the original feed URL,
     1945     * except in the case of an `HTTP 301 Moved Permanently` status response,
     1946     * in which case the location of the first redirection is returned.
     1947     *
     1948     * When the 'permanent' mode is disabled (default),
     1949     * may or may not be different from the URL passed to {@see set_feed_url()},
     1950     * depending on whether auto-discovery was used, and whether there were
     1951     * any redirects along the way.
    17701952     *
    17711953     * @since Preview Release (previously called `get_feed_url()` since SimplePie 0.8.)
    1772      * @todo If we have a perm redirect we should return the new URL
    1773      * @todo When we make the above change, let's support <itunes:new-feed-url> as well
     1954     * @todo Support <itunes:new-feed-url>
    17741955     * @todo Also, |atom:link|@rel=self
     1956     * @param bool $permanent Permanent mode to return only the original URL or the first redirection
     1957     * iff it is a 301 redirection
    17751958     * @return string|null
    17761959     */
    1777     public function subscribe_url()
    1778     {
    1779         if ($this->feed_url !== null)
    1780         {
    1781             return $this->sanitize($this->feed_url, SIMPLEPIE_CONSTRUCT_IRI);
     1960    public function subscribe_url($permanent = false)
     1961    {
     1962        if ($permanent)
     1963        {
     1964            if ($this->permanent_url !== null)
     1965            {
     1966                // sanitize encodes ampersands which are required when used in a url.
     1967                return str_replace('&amp;', '&',
     1968                                   $this->sanitize($this->permanent_url,
     1969                                                   SIMPLEPIE_CONSTRUCT_IRI));
     1970            }
    17821971        }
    17831972        else
    17841973        {
    1785             return null;
    1786         }
     1974            if ($this->feed_url !== null)
     1975            {
     1976                return str_replace('&amp;', '&',
     1977                                   $this->sanitize($this->feed_url,
     1978                                                   SIMPLEPIE_CONSTRUCT_IRI));
     1979            }
     1980        }
     1981        return null;
    17871982    }
    17881983
     
    19812176            return $this->get_link();
    19822177        }
    1983         else
    1984         {
    1985             return $this->subscribe_url();
    1986         }
     2178
     2179        return $this->subscribe_url();
    19872180    }
    19882181
     
    19992192    public function sanitize($data, $type, $base = '')
    20002193    {
    2001         return $this->sanitize->sanitize($data, $type, $base);
     2194        try
     2195        {
     2196            return $this->sanitize->sanitize($data, $type, $base);
     2197        }
     2198        catch (SimplePie_Exception $e)
     2199        {
     2200            if (!$this->enable_exceptions)
     2201            {
     2202                $this->error = $e->getMessage();
     2203                $this->registry->call('Misc', 'error', array($this->error, E_USER_WARNING, $e->getFile(), $e->getLine()));
     2204                return '';
     2205            }
     2206
     2207            throw $e;
     2208        }
    20022209    }
    20032210
     
    20402247            return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    20412248        }
    2042         else
    2043         {
    2044             return null;
    2045         }
     2249
     2250        return null;
    20462251    }
    20472252
     
    20502255     *
    20512256     * @since Unknown
    2052      * @param int $key The category that you want to return.  Remember that arrays begin with 0, not 1
     2257     * @param int $key The category that you want to return. Remember that arrays begin with 0, not 1
    20532258     * @return SimplePie_Category|null
    20542259     */
     
    20602265            return $categories[$key];
    20612266        }
    2062         else
    2063         {
    2064             return null;
    2065         }
     2267
     2268        return null;
    20662269    }
    20672270
     
    21252328            return array_unique($categories);
    21262329        }
    2127         else
    2128         {
    2129             return null;
    2130         }
     2330
     2331        return null;
    21312332    }
    21322333
     
    21352336     *
    21362337     * @since 1.1
    2137      * @param int $key The author that you want to return.  Remember that arrays begin with 0, not 1
     2338     * @param int $key The author that you want to return. Remember that arrays begin with 0, not 1
    21382339     * @return SimplePie_Author|null
    21392340     */
     
    21452346            return $authors[$key];
    21462347        }
    2147         else
    2148         {
    2149             return null;
    2150         }
     2348
     2349        return null;
    21512350    }
    21522351
     
    22232422            return array_unique($authors);
    22242423        }
    2225         else
    2226         {
    2227             return null;
    2228         }
     2424
     2425        return null;
    22292426    }
    22302427
     
    22332430     *
    22342431     * @since 1.1
    2235      * @param int $key The contrbutor that you want to return.  Remember that arrays begin with 0, not 1
     2432     * @param int $key The contrbutor that you want to return. Remember that arrays begin with 0, not 1
    22362433     * @return SimplePie_Author|null
    22372434     */
     
    22432440            return $contributors[$key];
    22442441        }
    2245         else
    2246         {
    2247             return null;
    2248         }
     2442
     2443        return null;
    22492444    }
    22502445
     
    23092504            return array_unique($contributors);
    23102505        }
    2311         else
    2312         {
    2313             return null;
    2314         }
     2506
     2507        return null;
    23152508    }
    23162509
     
    23192512     *
    23202513     * @since 1.0 (previously called `get_feed_link` since Preview Release, `get_feed_permalink()` since 0.8)
    2321      * @param int $key The link that you want to return.  Remember that arrays begin with 0, not 1
     2514     * @param int $key The link that you want to return. Remember that arrays begin with 0, not 1
    23222515     * @param string $rel The relationship of the link to return
    23232516     * @return string|null Link URL
     
    23302523            return $links[$key];
    23312524        }
    2332         else
    2333         {
    2334             return null;
    2335         }
     2525
     2526        return null;
    23362527    }
    23372528
     
    24252616        }
    24262617
    2427         if (isset($this->data['links'][$rel]))
     2618        if (isset($this->data['headers']['link']) &&
     2619            preg_match('/<([^>]+)>; rel='.preg_quote($rel).'/',
     2620                       $this->data['headers']['link'], $match))
     2621        {
     2622            return array($match[1]);
     2623        }
     2624        else if (isset($this->data['links'][$rel]))
    24282625        {
    24292626            return $this->data['links'][$rel];
    24302627        }
    2431         else
    2432         {
    2433             return null;
    2434         }
     2628
     2629        return null;
    24352630    }
    24362631
     
    24872682            return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_HTML, $this->get_base($return[0]));
    24882683        }
    2489         else
    2490         {
    2491             return null;
    2492         }
     2684
     2685        return null;
    24932686    }
    24942687
     
    25232716            return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    25242717        }
    2525         else
    2526         {
    2527             return null;
    2528         }
     2718
     2719        return null;
    25292720    }
    25302721
     
    25672758            return $this->sanitize($this->data['headers']['content-language'], SIMPLEPIE_CONSTRUCT_TEXT);
    25682759        }
    2569         else
    2570         {
    2571             return null;
    2572         }
     2760
     2761        return null;
    25732762    }
    25742763
     
    25962785            return (float) $match[1];
    25972786        }
    2598         else
    2599         {
    2600             return null;
    2601         }
     2787
     2788        return null;
    26022789    }
    26032790
     
    26282815            return (float) $match[2];
    26292816        }
    2630         else
    2631         {
    2632             return null;
    2633         }
     2817
     2818        return null;
    26342819    }
    26352820
     
    26652850            return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_TEXT);
    26662851        }
    2667         else
    2668         {
    2669             return null;
    2670         }
     2852
     2853        return null;
    26712854    }
    26722855
     
    27082891            return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
    27092892        }
    2710         else
    2711         {
    2712             return null;
    2713         }
     2893
     2894        return null;
    27142895    }
    27152896
     
    27402921            return $this->sanitize($return[0]['data'], SIMPLEPIE_CONSTRUCT_IRI, $this->get_base($return[0]));
    27412922        }
    2742         else
    2743         {
    2744             return null;
    2745         }
     2923
     2924        return null;
    27462925    }
    27472926
     
    27662945            return 88.0;
    27672946        }
    2768         else
    2769         {
    2770             return null;
    2771         }
     2947
     2948        return null;
    27722949    }
    27732950
     
    27922969            return 31.0;
    27932970        }
    2794         else
    2795         {
    2796             return null;
    2797         }
     2971
     2972        return null;
    27982973    }
    27992974
     
    28152990            return $qty;
    28162991        }
    2817         else
    2818         {
    2819             return ($qty > $max) ? $max : $qty;
    2820         }
     2992
     2993        return ($qty > $max) ? $max : $qty;
    28212994    }
    28222995
     
    28303003     * @see get_item_quantity()
    28313004     * @since Beta 2
    2832      * @param int $key The item that you want to return.  Remember that arrays begin with 0, not 1
     3005     * @param int $key The item that you want to return. Remember that arrays begin with 0, not 1
    28333006     * @return SimplePie_Item|null
    28343007     */
     
    28403013            return $items[$key];
    28413014        }
    2842         else
    2843         {
    2844             return null;
    2845         }
     3015
     3016        return null;
    28463017    }
    28473018
     
    28573028     * @param int $start Index to start at
    28583029     * @param int $end Number of items to return. 0 for all items after `$start`
    2859      * @return array|null List of {@see SimplePie_Item} objects
     3030     * @return SimplePie_Item[]|null List of {@see SimplePie_Item} objects
    28603031     */
    28613032    public function get_items($start = 0, $end = 0)
     
    28663037            {
    28673038                $this->data['items'] = SimplePie::merge_items($this->multifeed_objects, $start, $end, $this->item_limit);
    2868             }
    2869             else
    2870             {
    2871                 $this->data['items'] = array();
    2872                 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
    2873                 {
    2874                     $keys = array_keys($items);
    2875                     foreach ($keys as $key)
    2876                     {
    2877                         $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
    2878                     }
    2879                 }
    2880                 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
    2881                 {
    2882                     $keys = array_keys($items);
    2883                     foreach ($keys as $key)
    2884                     {
    2885                         $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
    2886                     }
    2887                 }
    2888                 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
    2889                 {
    2890                     $keys = array_keys($items);
    2891                     foreach ($keys as $key)
    2892                     {
    2893                         $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
    2894                     }
    2895                 }
    2896                 if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
    2897                 {
    2898                     $keys = array_keys($items);
    2899                     foreach ($keys as $key)
    2900                     {
    2901                         $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
    2902                     }
    2903                 }
    2904                 if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
    2905                 {
    2906                     $keys = array_keys($items);
    2907                     foreach ($keys as $key)
    2908                     {
    2909                         $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
    2910                     }
    2911                 }
    2912             }
    2913         }
    2914 
    2915         if (!empty($this->data['items']))
    2916         {
    2917             // If we want to order it by date, check if all items have a date, and then sort it
    2918             if ($this->order_by_date && empty($this->multifeed_objects))
    2919             {
    2920                 if (!isset($this->data['ordered_items']))
    2921                 {
    2922                     $do_sort = true;
    2923                     foreach ($this->data['items'] as $item)
    2924                     {
    2925                         if (!$item->get_date('U'))
    2926                         {
    2927                             $do_sort = false;
    2928                             break;
    2929                         }
    2930                     }
    2931                     $item = null;
    2932                     $this->data['ordered_items'] = $this->data['items'];
    2933                     if ($do_sort)
    2934                     {
    2935                         usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
    2936                     }
    2937                 }
    2938                 $items = $this->data['ordered_items'];
    2939             }
    2940             else
    2941             {
    2942                 $items = $this->data['items'];
    2943             }
    2944 
    2945             // Slice the data as desired
    2946             if ($end === 0)
    2947             {
    2948                 return array_slice($items, $start);
    2949             }
    2950             else
    2951             {
    2952                 return array_slice($items, $start, $end);
    2953             }
     3039                if (empty($this->data['items']))
     3040                {
     3041                    return array();
     3042                }
     3043                return $this->data['items'];
     3044            }
     3045            $this->data['items'] = array();
     3046            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'entry'))
     3047            {
     3048                $keys = array_keys($items);
     3049                foreach ($keys as $key)
     3050                {
     3051                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
     3052                }
     3053            }
     3054            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_03, 'entry'))
     3055            {
     3056                $keys = array_keys($items);
     3057                foreach ($keys as $key)
     3058                {
     3059                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
     3060                }
     3061            }
     3062            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_10, 'item'))
     3063            {
     3064                $keys = array_keys($items);
     3065                foreach ($keys as $key)
     3066                {
     3067                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
     3068                }
     3069            }
     3070            if ($items = $this->get_feed_tags(SIMPLEPIE_NAMESPACE_RSS_090, 'item'))
     3071            {
     3072                $keys = array_keys($items);
     3073                foreach ($keys as $key)
     3074                {
     3075                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
     3076                }
     3077            }
     3078            if ($items = $this->get_channel_tags(SIMPLEPIE_NAMESPACE_RSS_20, 'item'))
     3079            {
     3080                $keys = array_keys($items);
     3081                foreach ($keys as $key)
     3082                {
     3083                    $this->data['items'][] = $this->registry->create('Item', array($this, $items[$key]));
     3084                }
     3085            }
     3086        }
     3087
     3088        if (empty($this->data['items']))
     3089        {
     3090            return array();
     3091        }
     3092
     3093        if ($this->order_by_date)
     3094        {
     3095            if (!isset($this->data['ordered_items']))
     3096            {
     3097                $this->data['ordered_items'] = $this->data['items'];
     3098                usort($this->data['ordered_items'], array(get_class($this), 'sort_items'));
     3099            }
     3100            $items = $this->data['ordered_items'];
    29543101        }
    29553102        else
    29563103        {
    2957             return array();
    2958         }
     3104            $items = $this->data['items'];
     3105        }
     3106        // Slice the data as desired
     3107        if ($end === 0)
     3108        {
     3109            return array_slice($items, $start);
     3110        }
     3111
     3112        return array_slice($items, $start, $end);
    29593113    }
    29603114
     
    29833137        if (($url = $this->get_link()) !== null)
    29843138        {
    2985             return 'http://g.etfv.co/' . urlencode($url);
     3139            return 'https://www.google.com/s2/favicons?domain=' . urlencode($url);
    29863140        }
    29873141
     
    30283182    public static function sort_items($a, $b)
    30293183    {
    3030         return $a->get_date('U') <= $b->get_date('U');
     3184        $a_date = $a->get_date('U');
     3185        $b_date = $b->get_date('U');
     3186        if ($a_date && $b_date) {
     3187            return $a_date > $b_date ? -1 : 1;
     3188        }
     3189        // Sort items without dates to the top.
     3190        if ($a_date) {
     3191            return 1;
     3192        }
     3193        if ($b_date) {
     3194            return -1;
     3195        }
     3196        return 0;
    30313197    }
    30323198
     
    30613227            }
    30623228
    3063             $do_sort = true;
    3064             foreach ($items as $item)
    3065             {
    3066                 if (!$item->get_date('U'))
    3067                 {
    3068                     $do_sort = false;
    3069                     break;
    3070                 }
    3071             }
    3072             $item = null;
    3073             if ($do_sort)
    3074             {
    3075                 usort($items, array(get_class($urls[0]), 'sort_items'));
    3076             }
     3229            usort($items, array(get_class($urls[0]), 'sort_items'));
    30773230
    30783231            if ($end === 0)
     
    30803233                return array_slice($items, $start);
    30813234            }
     3235
     3236            return array_slice($items, $start, $end);
     3237        }
     3238
     3239        trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
     3240        return array();
     3241    }
     3242
     3243    /**
     3244     * Store PubSubHubbub links as headers
     3245     *
     3246     * There is no way to find PuSH links in the body of a microformats feed,
     3247     * so they are added to the headers when found, to be used later by get_links.
     3248     * @param SimplePie_File $file
     3249     * @param string $hub
     3250     * @param string $self
     3251     */
     3252    private function store_links(&$file, $hub, $self) {
     3253        if (isset($file->headers['link']['hub']) ||
     3254              (isset($file->headers['link']) &&
     3255               preg_match('/rel=hub/', $file->headers['link'])))
     3256        {
     3257            return;
     3258        }
     3259
     3260        if ($hub)
     3261        {
     3262            if (isset($file->headers['link']))
     3263            {
     3264                if ($file->headers['link'] !== '')
     3265                {
     3266                    $file->headers['link'] = ', ';
     3267                }
     3268            }
    30823269            else
    30833270            {
    3084                 return array_slice($items, $start, $end);
    3085             }
    3086         }
    3087         else
    3088         {
    3089             trigger_error('Cannot merge zero SimplePie objects', E_USER_WARNING);
    3090             return array();
     3271                $file->headers['link'] = '';
     3272            }
     3273            $file->headers['link'] .= '<'.$hub.'>; rel=hub';
     3274            if ($self)
     3275            {
     3276                $file->headers['link'] .= ', <'.$self.'>; rel=self';
     3277            }
    30913278        }
    30923279    }
Note: See TracChangeset for help on using the changeset viewer.