Make WordPress Core


Ignore:
Timestamp:
09/16/2025 10:45:37 PM (2 months ago)
Author:
SergeyBiryukov
Message:

External Libraries: Update the SimplePie library to version 1.9.0.

References:

Follow-up to [59141], [60490].

Props swissspidy, TobiasBg, SergeyBiryukov.
Fixes #63961.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/SimplePie/src/Misc.php

    r59141 r60771  
    11<?php
    22
    3 /**
    4  * SimplePie
    5  *
    6  * A PHP-Based RSS and Atom Feed Framework.
    7  * Takes the hard work out of managing a complete RSS/Atom solution.
    8  *
    9  * Copyright (c) 2004-2022, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
    10  * All rights reserved.
    11  *
    12  * Redistribution and use in source and binary forms, with or without modification, are
    13  * permitted provided that the following conditions are met:
    14  *
    15  *  * Redistributions of source code must retain the above copyright notice, this list of
    16  *    conditions and the following disclaimer.
    17  *
    18  *  * Redistributions in binary form must reproduce the above copyright notice, this list
    19  *    of conditions and the following disclaimer in the documentation and/or other materials
    20  *    provided with the distribution.
    21  *
    22  *  * Neither the name of the SimplePie Team nor the names of its contributors may be used
    23  *    to endorse or promote products derived from this software without specific prior
    24  *    written permission.
    25  *
    26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
    27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
    28  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
    29  * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    33  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    34  * POSSIBILITY OF SUCH DAMAGE.
    35  *
    36  * @package SimplePie
    37  * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
    38  * @author Ryan Parman
    39  * @author Sam Sneddon
    40  * @author Ryan McCue
    41  * @link http://simplepie.org/ SimplePie
    42  * @license http://www.opensource.org/licenses/bsd-license.php BSD License
    43  */
     3// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
     4// SPDX-License-Identifier: BSD-3-Clause
     5
     6declare(strict_types=1);
    447
    458namespace SimplePie;
     
    4912/**
    5013 * Miscellaneous utilities
    51  *
    52  * @package SimplePie
    5314 */
    5415class Misc
    5516{
     17    /** @var int|null */
    5618    private static $SIMPLEPIE_BUILD = null;
    5719
    58     public static function time_hms($seconds)
     20    /**
     21     * @return string
     22     */
     23    public static function time_hms(int $seconds)
    5924    {
    6025        $time = '';
     
    8146    }
    8247
    83     public static function absolutize_url($relative, $base)
     48    /**
     49     * @return string|false
     50     */
     51    public static function absolutize_url(string $relative, string $base)
    8452    {
    8553        $iri = \SimplePie\IRI::absolutize(new \SimplePie\IRI($base), $relative);
     
    8856        }
    8957        return $iri->get_uri();
     58    }
     59
     60    /**
     61     * @internal
     62     */
     63    public static function is_remote_uri(string $uri): bool
     64    {
     65        return preg_match('/^https?:\/\//i', $uri) === 1;
    9066    }
    9167
     
    9672     * @param string $realname Element name (including namespace prefix if applicable)
    9773     * @param string $string HTML document
    98      * @return array
    99      */
    100     public static function get_element($realname, $string)
     74     * @return array<array{tag: string, self_closing: bool, attribs: array<string, array{data: string}>, content?: string}>
     75     */
     76    public static function get_element(string $realname, string $string)
    10177    {
    10278        // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED);
     
    11793                $return[$i]['attribs'] = [];
    11894                if (isset($matches[$i][2][0]) && preg_match_all('/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER)) {
    119                     for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++) {
    120                         if (count($attribs[$j]) === 2) {
    121                             $attribs[$j][2] = $attribs[$j][1];
     95                    foreach ($attribs as $attrib) {
     96                        if (count($attrib) === 2) {
     97                            $attrib[2] = $attrib[1];
    12298                        }
    123                         $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = Misc::entities_decode(end($attribs[$j]));
     99                        $return[$i]['attribs'][strtolower($attrib[1])]['data'] = Misc::entities_decode(end($attrib));
    124100                    }
    125101                }
     
    129105    }
    130106
    131     public static function element_implode($element)
    132     {
    133         $full = "<$element[tag]";
     107    /**
     108     * @deprecated since SimplePie 1.9.0. If you need it, you can copy the function to your codebase. But you should consider using `DOMDocument` for any DOM wrangling.
     109     * @param array{tag: string, self_closing: bool, attribs: array<string, array{data: string}>, content: string} $element
     110     * @return string
     111     */
     112    public static function element_implode(array $element)
     113    {
     114        // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
     115
     116        $full = "<{$element['tag']}";
    134117        foreach ($element['attribs'] as $key => $value) {
    135118            $key = strtolower($key);
     
    139122            $full .= ' />';
    140123        } else {
    141             $full .= ">$element[content]</$element[tag]>";
     124            $full .= ">{$element['content']}</{$element['tag']}>";
    142125        }
    143126        return $full;
    144127    }
    145128
    146     public static function error($message, $level, $file, $line)
     129    /**
     130     * @param string $message
     131     * @param int $level
     132     * @param string $file
     133     * @param int $line
     134     * @return string
     135     */
     136    public static function error(string $message, int $level, string $file, int $line)
    147137    {
    148138        if ((error_reporting() & $level) > 0) {
     
    180170    }
    181171
    182     public static function fix_protocol($url, $http = 1)
     172    /**
     173     * @return string
     174     */
     175    public static function fix_protocol(string $url, int $http = 1)
    183176    {
    184177        $url = Misc::normalize_url($url);
     
    205198    /**
    206199     * @deprecated since SimplePie 1.8.0, use PHP native array_replace_recursive() instead.
    207      */
    208     public static function array_merge_recursive($array1, $array2)
     200     * @param array<mixed> $array1
     201     * @param array<mixed> $array2
     202     * @return array<mixed>
     203     */
     204    public static function array_merge_recursive(array $array1, array $array2)
    209205    {
    210206        foreach ($array2 as $key => $value) {
     
    219215    }
    220216
    221     public static function parse_url($url)
     217    /**
     218     * @return array<string, string>
     219     */
     220    public static function parse_url(string $url)
    222221    {
    223222        $iri = new \SimplePie\IRI($url);
     
    231230    }
    232231
    233     public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
     232    /**
     233     * @return string
     234     */
     235    public static function compress_parse_url(string $scheme = '', string $authority = '', string $path = '', string $query = '', ?string $fragment = '')
    234236    {
    235237        $iri = new \SimplePie\IRI('');
     
    242244    }
    243245
    244     public static function normalize_url($url)
     246    /**
     247     * @return string
     248     */
     249    public static function normalize_url(string $url)
    245250    {
    246251        $iri = new \SimplePie\IRI($url);
     
    248253    }
    249254
    250     public static function percent_encoding_normalization($match)
     255    /**
     256     * @deprecated since SimplePie 1.9.0. This functionality is part of `IRI` – if you need it standalone, consider copying the function to your codebase.
     257     * @param array<int, string> $match
     258     * @return string
     259     */
     260    public static function percent_encoding_normalization(array $match)
    251261    {
    252262        $integer = hexdec($match[1]);
    253263        if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E) {
    254             return chr($integer);
     264            // Cast for PHPStan, the value would only be float when above PHP_INT_MAX, which would not go in this branch.
     265            return chr((int) $integer);
    255266        }
    256267
     
    265276     * @return string UTF-8 encoded string
    266277     */
    267     public static function windows_1252_to_utf8($string)
     278    public static function windows_1252_to_utf8(string $string)
    268279    {
    269280        static $convert_table = ["\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF"];
     
    278289     * @param string $input Encoding of $data
    279290     * @param string $output Encoding you want
    280      * @return string|boolean False if we can't convert it
    281      */
    282     public static function change_encoding($data, $input, $output)
     291     * @return string|false False if we can't convert it
     292     */
     293    public static function change_encoding(string $data, string $input, string $output)
    283294    {
    284295        $input = Misc::encoding($input);
     
    287298        // We fail to fail on non US-ASCII bytes
    288299        if ($input === 'US-ASCII') {
    289             static $non_ascii_octects = '';
    290             if (!$non_ascii_octects) {
     300            static $non_ascii_octets = '';
     301            if (!$non_ascii_octets) {
    291302                for ($i = 0x80; $i <= 0xFF; $i++) {
    292                     $non_ascii_octects .= chr($i);
     303                    $non_ascii_octets .= chr($i);
    293304                }
    294305            }
    295             $data = substr($data, 0, strcspn($data, $non_ascii_octects));
     306            $data = substr($data, 0, strcspn($data, $non_ascii_octets));
    296307        }
    297308
     
    317328    }
    318329
    319     protected static function change_encoding_mbstring($data, $input, $output)
     330    /**
     331     * @return string|false
     332     */
     333    protected static function change_encoding_mbstring(string $data, string $input, string $output)
    320334    {
    321335        if ($input === 'windows-949') {
     
    349363    }
    350364
    351     protected static function change_encoding_iconv($data, $input, $output)
     365    /**
     366     * @return string|false
     367     */
     368    protected static function change_encoding_iconv(string $data, string $input, string $output)
    352369    {
    353370        return @iconv($input, $output, $data);
     
    355372
    356373    /**
    357      * @param string $data
    358      * @param string $input
    359      * @param string $output
    360374     * @return string|false
    361375     */
    362     protected static function change_encoding_uconverter($data, $input, $output)
     376    protected static function change_encoding_uconverter(string $data, string $input, string $output)
    363377    {
    364378        return @\UConverter::transcode($data, $output, $input);
     
    376390     * @return string Standardised name
    377391     */
    378     public static function encoding($charset)
     392    public static function encoding(string $charset)
    379393    {
    380394        // Normalization from UTS #22
    381         switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset))) {
     395        // Cast for PHPStan, the regex should not fail.
     396        switch (strtolower((string) preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset))) {
    382397            case 'adobestandardencoding':
    383398            case 'csadobestandardencoding':
     
    16881703    }
    16891704
     1705    /**
     1706     * @return string
     1707     */
    16901708    public static function get_curl_version()
    16911709    {
    16921710        if (is_array($curl = curl_version())) {
    16931711            $curl = $curl['version'];
    1694         } elseif (substr($curl, 0, 5) === 'curl/') {
    1695             $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
    1696         } elseif (substr($curl, 0, 8) === 'libcurl/') {
    1697             $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
    16981712        } else {
    1699             $curl = 0;
     1713            $curl = '0';
    17001714        }
    17011715        return $curl;
     
    17051719     * Strip HTML comments
    17061720     *
     1721     * @deprecated since SimplePie 1.9.0. If you need it, you can copy the function to your codebase. But you should consider using `DOMDocument` for any DOM wrangling.
    17071722     * @param string $data Data to strip comments from
    17081723     * @return string Comment stripped string
    17091724     */
    1710     public static function strip_comments($data)
    1711     {
     1725    public static function strip_comments(string $data)
     1726    {
     1727        // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
     1728
    17121729        $output = '';
    17131730        while (($start = strpos($data, '<!--')) !== false) {
     
    17221739    }
    17231740
    1724     public static function parse_date($dt)
     1741    /**
     1742     * @return int|false
     1743     */
     1744    public static function parse_date(string $dt)
    17251745    {
    17261746        $parser = \SimplePie\Parse\Date::get();
     
    17351755     * @return string Output data
    17361756     */
    1737     public static function entities_decode($data)
     1757    public static function entities_decode(string $data)
    17381758    {
    17391759        // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED);
     
    17461766     * Remove RFC822 comments
    17471767     *
    1748      * @param string $data Data to strip comments from
     1768     * @deprecated since SimplePie 1.9.0. If you need it, consider copying the function to your codebase.
     1769     * @param string $string Data to strip comments from
    17491770     * @return string Comment stripped string
    17501771     */
    1751     public static function uncomment_rfc822($string)
    1752     {
    1753         $string = (string) $string;
     1772    public static function uncomment_rfc822(string $string)
     1773    {
     1774        // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
     1775
    17541776        $position = 0;
    17551777        $length = strlen($string);
     
    17921814    }
    17931815
    1794     public static function parse_mime($mime)
     1816    /**
     1817     * @return string
     1818     */
     1819    public static function parse_mime(string $mime)
    17951820    {
    17961821        if (($pos = strpos($mime, ';')) === false) {
     
    18011826    }
    18021827
    1803     public static function atom_03_construct_type($attribs)
     1828    /**
     1829     * @param array<string, array<string, string>> $attribs
     1830     * @return int-mask-of<SimplePie::CONSTRUCT_*>
     1831     */
     1832    public static function atom_03_construct_type(array $attribs)
    18041833    {
    18051834        if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode'])) === 'base64') {
     
    18301859    }
    18311860
    1832     public static function atom_10_construct_type($attribs)
     1861    /**
     1862     * @param array<string, array<string, string>> $attribs
     1863     * @return int-mask-of<SimplePie::CONSTRUCT_*>
     1864     */
     1865    public static function atom_10_construct_type(array $attribs)
    18331866    {
    18341867        if (isset($attribs['']['type'])) {
     
    18501883    }
    18511884
    1852     public static function atom_10_content_construct_type($attribs)
     1885    /**
     1886     * @param array<string, array<string, string>> $attribs
     1887     * @return int-mask-of<SimplePie::CONSTRUCT_*>
     1888     */
     1889    public static function atom_10_content_construct_type(array $attribs)
    18531890    {
    18541891        if (isset($attribs['']['type'])) {
     
    18741911    }
    18751912
    1876     public static function is_isegment_nz_nc($string)
     1913    /**
     1914     * @return bool
     1915     */
     1916    public static function is_isegment_nz_nc(string $string)
    18771917    {
    18781918        return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string);
    18791919    }
    18801920
    1881     public static function space_separated_tokens($string)
     1921    /**
     1922     * @return string[]
     1923     */
     1924    public static function space_separated_tokens(string $string)
    18821925    {
    18831926        $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
     
    19021945     * @static
    19031946     * @param int $codepoint Unicode codepoint
    1904      * @return string UTF-8 character
    1905      */
    1906     public static function codepoint_to_utf8($codepoint)
    1907     {
    1908         $codepoint = (int) $codepoint;
     1947     * @return string|false UTF-8 character
     1948     */
     1949    public static function codepoint_to_utf8(int $codepoint)
     1950    {
    19091951        if ($codepoint < 0) {
    19101952            return false;
     
    19291971     * array of values that have used the same name
    19301972     *
     1973     * @deprecated since SimplePie 1.9.0. If you need it, consider copying the function to your codebase.
    19311974     * @static
    19321975     * @param string $str The input string.
    1933      * @return array
    1934      */
    1935     public static function parse_str($str)
    1936     {
     1976     * @return array<string, array<string|null>>
     1977     */
     1978    public static function parse_str(string $str)
     1979    {
     1980        // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
     1981
    19371982        $return = [];
    19381983        $str = explode('&', $str);
     
    19562001     * @param string $data XML data
    19572002     * @param \SimplePie\Registry $registry Class registry
    1958      * @return array Possible encodings
    1959      */
    1960     public static function xml_encoding($data, $registry)
     2003     * @return array<string> Possible encodings
     2004     */
     2005    public static function xml_encoding(string $data, \SimplePie\Registry $registry)
    19612006    {
    19622007        // UTF-32 Big Endian BOM
     
    20372082    }
    20382083
     2084    /**
     2085     * @return void
     2086     */
    20392087    public static function output_javascript()
    20402088    {
     
    20462094        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
    20472095
    2048         $body = <<<END
     2096        $body = <<<JS
    20492097function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) {
    20502098    if (placeholder != '') {
     
    20672115    document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>');
    20682116}
    2069 END;
     2117JS;
    20702118        echo $body;
    20712119    }
     
    20762124     * Uses the git index if it exists, otherwise uses the modification time
    20772125     * of the newest file.
     2126     *
     2127     * @return int
    20782128     */
    20792129    public static function get_build()
    20802130    {
    2081         if (static::$SIMPLEPIE_BUILD !== null) {
    2082             return static::$SIMPLEPIE_BUILD;
     2131        if (self::$SIMPLEPIE_BUILD !== null) {
     2132            return self::$SIMPLEPIE_BUILD;
    20832133        }
    20842134
    20852135        $root = dirname(__FILE__, 2);
    20862136        if (file_exists($root . '/.git/index')) {
    2087             static::$SIMPLEPIE_BUILD = filemtime($root . '/.git/index');
    2088 
    2089             return static::$SIMPLEPIE_BUILD;
    2090         } elseif (file_exists($root . '/SimplePie')) {
     2137            self::$SIMPLEPIE_BUILD = (int) filemtime($root . '/.git/index');
     2138
     2139            return self::$SIMPLEPIE_BUILD;
     2140        } elseif (file_exists($root . '/src')) {
    20912141            $time = 0;
    2092             foreach (glob($root . '/SimplePie/*.php') as $file) {
     2142            foreach (glob($root . '/src/*.php') ?: [] as $file) {
    20932143                if (($mtime = filemtime($file)) > $time) {
    20942144                    $time = $mtime;
    20952145                }
    20962146            }
    2097             static::$SIMPLEPIE_BUILD = $time;
    2098 
    2099             return static::$SIMPLEPIE_BUILD;
    2100         } elseif (file_exists(dirname(__FILE__) . '/Core.php')) {
    2101             static::$SIMPLEPIE_BUILD = filemtime(dirname(__FILE__) . '/Core.php');
    2102 
    2103             return static::$SIMPLEPIE_BUILD;
    2104         }
    2105 
    2106         static::$SIMPLEPIE_BUILD = filemtime(__FILE__);
    2107 
    2108         return static::$SIMPLEPIE_BUILD;
     2147
     2148            self::$SIMPLEPIE_BUILD = $time;
     2149
     2150            return self::$SIMPLEPIE_BUILD;
     2151        }
     2152
     2153        self::$SIMPLEPIE_BUILD = (int) filemtime(__FILE__);
     2154
     2155        return self::$SIMPLEPIE_BUILD;
    21092156    }
    21102157
     
    21212168    /**
    21222169     * Format debugging information
    2123      */
    2124     public static function debug(&$sp)
     2170     *
     2171     * @return string
     2172     */
     2173    public static function debug(SimplePie &$sp)
    21252174    {
    21262175        $info = 'SimplePie ' . \SimplePie\SimplePie::VERSION . ' Build ' . static::get_build() . "\n";
    21272176        $info .= 'PHP ' . PHP_VERSION . "\n";
    21282177        if ($sp->error() !== null) {
    2129             $info .= 'Error occurred: ' . $sp->error() . "\n";
     2178            // TODO: Remove cast with multifeeds.
     2179            $info .= 'Error occurred: ' . implode(', ', (array) $sp->error()) . "\n";
    21302180        } else {
    21312181            $info .= "No error found.\n";
     
    21412191                        break;
    21422192                    case 'curl':
    2143                         $version = curl_version();
     2193                        $version = (array) curl_version();
    21442194                        $info .= '      Version ' . $version['version'] . "\n";
    2145                         break;
    2146                     case 'mbstring':
    2147                         $info .= '      Overloading: ' . mb_get_info('func_overload') . "\n";
    21482195                        break;
    21492196                    case 'iconv':
     
    21612208    }
    21622209
    2163     public static function silence_errors($num, $str)
     2210    /**
     2211     * @return bool
     2212     */
     2213    public static function silence_errors(int $num, string $str)
    21642214    {
    21652215        // No-op
     2216        return true;
    21662217    }
    21672218
     
    21712222     * @return string the same URL without HTTP credentials.
    21722223     */
    2173     public static function url_remove_credentials($url)
    2174     {
    2175         return preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url);
     2224    public static function url_remove_credentials(string $url)
     2225    {
     2226        // Cast for PHPStan: I do not think this can fail.
     2227        // The regex is valid and there should be no backtracking.
     2228        // https://github.com/phpstan/phpstan/issues/11547
     2229        return (string) preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url);
    21762230    }
    21772231}
Note: See TracChangeset for help on using the changeset viewer.