Changeset 60771 for trunk/src/wp-includes/SimplePie/src/Misc.php
- Timestamp:
- 09/16/2025 10:45:37 PM (2 months ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/SimplePie/src/Misc.php (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/src/Misc.php
r59141 r60771 1 1 <?php 2 2 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 6 declare(strict_types=1); 44 7 45 8 namespace SimplePie; … … 49 12 /** 50 13 * Miscellaneous utilities 51 *52 * @package SimplePie53 14 */ 54 15 class Misc 55 16 { 17 /** @var int|null */ 56 18 private static $SIMPLEPIE_BUILD = null; 57 19 58 public static function time_hms($seconds) 20 /** 21 * @return string 22 */ 23 public static function time_hms(int $seconds) 59 24 { 60 25 $time = ''; … … 81 46 } 82 47 83 public static function absolutize_url($relative, $base) 48 /** 49 * @return string|false 50 */ 51 public static function absolutize_url(string $relative, string $base) 84 52 { 85 53 $iri = \SimplePie\IRI::absolutize(new \SimplePie\IRI($base), $relative); … … 88 56 } 89 57 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; 90 66 } 91 67 … … 96 72 * @param string $realname Element name (including namespace prefix if applicable) 97 73 * @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) 101 77 { 102 78 // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED); … … 117 93 $return[$i]['attribs'] = []; 118 94 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($attrib s[$j]) === 2) {121 $attrib s[$j][2] = $attribs[$j][1];95 foreach ($attribs as $attrib) { 96 if (count($attrib) === 2) { 97 $attrib[2] = $attrib[1]; 122 98 } 123 $return[$i]['attribs'][strtolower($attrib s[$j][1])]['data'] = Misc::entities_decode(end($attribs[$j]));99 $return[$i]['attribs'][strtolower($attrib[1])]['data'] = Misc::entities_decode(end($attrib)); 124 100 } 125 101 } … … 129 105 } 130 106 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']}"; 134 117 foreach ($element['attribs'] as $key => $value) { 135 118 $key = strtolower($key); … … 139 122 $full .= ' />'; 140 123 } else { 141 $full .= "> $element[content]</$element[tag]>";124 $full .= ">{$element['content']}</{$element['tag']}>"; 142 125 } 143 126 return $full; 144 127 } 145 128 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) 147 137 { 148 138 if ((error_reporting() & $level) > 0) { … … 180 170 } 181 171 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) 183 176 { 184 177 $url = Misc::normalize_url($url); … … 205 198 /** 206 199 * @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) 209 205 { 210 206 foreach ($array2 as $key => $value) { … … 219 215 } 220 216 221 public static function parse_url($url) 217 /** 218 * @return array<string, string> 219 */ 220 public static function parse_url(string $url) 222 221 { 223 222 $iri = new \SimplePie\IRI($url); … … 231 230 } 232 231 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 = '') 234 236 { 235 237 $iri = new \SimplePie\IRI(''); … … 242 244 } 243 245 244 public static function normalize_url($url) 246 /** 247 * @return string 248 */ 249 public static function normalize_url(string $url) 245 250 { 246 251 $iri = new \SimplePie\IRI($url); … … 248 253 } 249 254 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) 251 261 { 252 262 $integer = hexdec($match[1]); 253 263 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); 255 266 } 256 267 … … 265 276 * @return string UTF-8 encoded string 266 277 */ 267 public static function windows_1252_to_utf8( $string)278 public static function windows_1252_to_utf8(string $string) 268 279 { 269 280 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"]; … … 278 289 * @param string $input Encoding of $data 279 290 * @param string $output Encoding you want 280 * @return string| booleanFalse if we can't convert it281 */ 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) 283 294 { 284 295 $input = Misc::encoding($input); … … 287 298 // We fail to fail on non US-ASCII bytes 288 299 if ($input === 'US-ASCII') { 289 static $non_ascii_octe cts = '';290 if (!$non_ascii_octe cts) {300 static $non_ascii_octets = ''; 301 if (!$non_ascii_octets) { 291 302 for ($i = 0x80; $i <= 0xFF; $i++) { 292 $non_ascii_octe cts .= chr($i);303 $non_ascii_octets .= chr($i); 293 304 } 294 305 } 295 $data = substr($data, 0, strcspn($data, $non_ascii_octe cts));306 $data = substr($data, 0, strcspn($data, $non_ascii_octets)); 296 307 } 297 308 … … 317 328 } 318 329 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) 320 334 { 321 335 if ($input === 'windows-949') { … … 349 363 } 350 364 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) 352 369 { 353 370 return @iconv($input, $output, $data); … … 355 372 356 373 /** 357 * @param string $data358 * @param string $input359 * @param string $output360 374 * @return string|false 361 375 */ 362 protected static function change_encoding_uconverter( $data, $input,$output)376 protected static function change_encoding_uconverter(string $data, string $input, string $output) 363 377 { 364 378 return @\UConverter::transcode($data, $output, $input); … … 376 390 * @return string Standardised name 377 391 */ 378 public static function encoding( $charset)392 public static function encoding(string $charset) 379 393 { 380 394 // 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))) { 382 397 case 'adobestandardencoding': 383 398 case 'csadobestandardencoding': … … 1688 1703 } 1689 1704 1705 /** 1706 * @return string 1707 */ 1690 1708 public static function get_curl_version() 1691 1709 { 1692 1710 if (is_array($curl = curl_version())) { 1693 1711 $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));1698 1712 } else { 1699 $curl = 0;1713 $curl = '0'; 1700 1714 } 1701 1715 return $curl; … … 1705 1719 * Strip HTML comments 1706 1720 * 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. 1707 1722 * @param string $data Data to strip comments from 1708 1723 * @return string Comment stripped string 1709 1724 */ 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 1712 1729 $output = ''; 1713 1730 while (($start = strpos($data, '<!--')) !== false) { … … 1722 1739 } 1723 1740 1724 public static function parse_date($dt) 1741 /** 1742 * @return int|false 1743 */ 1744 public static function parse_date(string $dt) 1725 1745 { 1726 1746 $parser = \SimplePie\Parse\Date::get(); … … 1735 1755 * @return string Output data 1736 1756 */ 1737 public static function entities_decode( $data)1757 public static function entities_decode(string $data) 1738 1758 { 1739 1759 // trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED); … … 1746 1766 * Remove RFC822 comments 1747 1767 * 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 1749 1770 * @return string Comment stripped string 1750 1771 */ 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 1754 1776 $position = 0; 1755 1777 $length = strlen($string); … … 1792 1814 } 1793 1815 1794 public static function parse_mime($mime) 1816 /** 1817 * @return string 1818 */ 1819 public static function parse_mime(string $mime) 1795 1820 { 1796 1821 if (($pos = strpos($mime, ';')) === false) { … … 1801 1826 } 1802 1827 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) 1804 1833 { 1805 1834 if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode'])) === 'base64') { … … 1830 1859 } 1831 1860 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) 1833 1866 { 1834 1867 if (isset($attribs['']['type'])) { … … 1850 1883 } 1851 1884 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) 1853 1890 { 1854 1891 if (isset($attribs['']['type'])) { … … 1874 1911 } 1875 1912 1876 public static function is_isegment_nz_nc($string) 1913 /** 1914 * @return bool 1915 */ 1916 public static function is_isegment_nz_nc(string $string) 1877 1917 { 1878 1918 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); 1879 1919 } 1880 1920 1881 public static function space_separated_tokens($string) 1921 /** 1922 * @return string[] 1923 */ 1924 public static function space_separated_tokens(string $string) 1882 1925 { 1883 1926 $space_characters = "\x20\x09\x0A\x0B\x0C\x0D"; … … 1902 1945 * @static 1903 1946 * @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 { 1909 1951 if ($codepoint < 0) { 1910 1952 return false; … … 1929 1971 * array of values that have used the same name 1930 1972 * 1973 * @deprecated since SimplePie 1.9.0. If you need it, consider copying the function to your codebase. 1931 1974 * @static 1932 1975 * @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 1937 1982 $return = []; 1938 1983 $str = explode('&', $str); … … 1956 2001 * @param string $data XML data 1957 2002 * @param \SimplePie\Registry $registry Class registry 1958 * @return array Possible encodings1959 */ 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) 1961 2006 { 1962 2007 // UTF-32 Big Endian BOM … … 2037 2082 } 2038 2083 2084 /** 2085 * @return void 2086 */ 2039 2087 public static function output_javascript() 2040 2088 { … … 2046 2094 header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days 2047 2095 2048 $body = <<< END2096 $body = <<<JS 2049 2097 function embed_quicktime(type, bgcolor, width, height, link, placeholder, loop) { 2050 2098 if (placeholder != '') { … … 2067 2115 document.writeln('<embed type="application/x-mplayer2" src="'+link+'" autosize="1" width="'+width+'" height="'+height+'" showcontrols="1" showstatusbar="0" showdisplay="0" autostart="0"></embed>'); 2068 2116 } 2069 END;2117 JS; 2070 2118 echo $body; 2071 2119 } … … 2076 2124 * Uses the git index if it exists, otherwise uses the modification time 2077 2125 * of the newest file. 2126 * 2127 * @return int 2078 2128 */ 2079 2129 public static function get_build() 2080 2130 { 2081 if (s tatic::$SIMPLEPIE_BUILD !== null) {2082 return s tatic::$SIMPLEPIE_BUILD;2131 if (self::$SIMPLEPIE_BUILD !== null) { 2132 return self::$SIMPLEPIE_BUILD; 2083 2133 } 2084 2134 2085 2135 $root = dirname(__FILE__, 2); 2086 2136 if (file_exists($root . '/.git/index')) { 2087 s tatic::$SIMPLEPIE_BUILD =filemtime($root . '/.git/index');2088 2089 return s tatic::$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')) { 2091 2141 $time = 0; 2092 foreach (glob($root . '/ SimplePie/*.php')as $file) {2142 foreach (glob($root . '/src/*.php') ?: [] as $file) { 2093 2143 if (($mtime = filemtime($file)) > $time) { 2094 2144 $time = $mtime; 2095 2145 } 2096 2146 } 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; 2109 2156 } 2110 2157 … … 2121 2168 /** 2122 2169 * Format debugging information 2123 */ 2124 public static function debug(&$sp) 2170 * 2171 * @return string 2172 */ 2173 public static function debug(SimplePie &$sp) 2125 2174 { 2126 2175 $info = 'SimplePie ' . \SimplePie\SimplePie::VERSION . ' Build ' . static::get_build() . "\n"; 2127 2176 $info .= 'PHP ' . PHP_VERSION . "\n"; 2128 2177 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"; 2130 2180 } else { 2131 2181 $info .= "No error found.\n"; … … 2141 2191 break; 2142 2192 case 'curl': 2143 $version = curl_version();2193 $version = (array) curl_version(); 2144 2194 $info .= ' Version ' . $version['version'] . "\n"; 2145 break;2146 case 'mbstring':2147 $info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";2148 2195 break; 2149 2196 case 'iconv': … … 2161 2208 } 2162 2209 2163 public static function silence_errors($num, $str) 2210 /** 2211 * @return bool 2212 */ 2213 public static function silence_errors(int $num, string $str) 2164 2214 { 2165 2215 // No-op 2216 return true; 2166 2217 } 2167 2218 … … 2171 2222 * @return string the same URL without HTTP credentials. 2172 2223 */ 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); 2176 2230 } 2177 2231 }
Note: See TracChangeset
for help on using the changeset viewer.