diff options
author | 2021-10-30 01:06:04 +0500 | |
---|---|---|
committer | 2021-10-30 01:06:04 +0500 | |
commit | b86ed70376fd53e52cfc63496bbd872424415976 (patch) | |
tree | 47e550aed28fed13dcab7fe988653154de204103 | |
parent | 9254d14f50685322192ae0ef7e8174848e6b73b2 (diff) | |
download | rss-bridge-b86ed70376fd53e52cfc63496bbd872424415976.tar.gz rss-bridge-b86ed70376fd53e52cfc63496bbd872424415976.tar.zst rss-bridge-b86ed70376fd53e52cfc63496bbd872424415976.zip |
[core] Backported str_starts_with, str_ends_with and str_contains from php 8 (#2318)
-rw-r--r-- | bridges/NordbayernBridge.php | 11 | ||||
-rw-r--r-- | lib/php8backports.php | 32 | ||||
-rw-r--r-- | lib/rssbridge.php | 1 |
3 files changed, 34 insertions, 10 deletions
diff --git a/bridges/NordbayernBridge.php b/bridges/NordbayernBridge.php index 6aa2d5a9..52b1f3ec 100644 --- a/bridges/NordbayernBridge.php +++ b/bridges/NordbayernBridge.php @@ -47,15 +47,6 @@ class NordbayernBridge extends BridgeAbstract { ) )); - private function startsWith($string, $startString) { - $len = strlen($startString); - return (substr($string, 0, $len) === $startString); - } - - private function contains($haystack, $needle) { - return (strpos($haystack, $needle) !== false); - } - private function getUseFullContent($rawContent) { $content = ''; foreach($rawContent->children as $element) { @@ -109,7 +100,7 @@ class NordbayernBridge extends BridgeAbstract { // exclude police reports if descired if($this->getInput('policeReports') || - !self::contains($item['content'], 'Hier geht es zu allen aktuellen Polizeimeldungen.')) { + !str_contains($item['content'], 'Hier geht es zu allen aktuellen Polizeimeldungen.')) { $this->items[] = $item; } diff --git a/lib/php8backports.php b/lib/php8backports.php new file mode 100644 index 00000000..aa68b77a --- /dev/null +++ b/lib/php8backports.php @@ -0,0 +1,32 @@ +<?php +/** + * This file is part of RSS-Bridge, a PHP project capable of generating RSS and + * Atom feeds for websites that don't have one. + * + * For the full license information, please view the UNLICENSE file distributed + * with this source code. + * + * @package Core + * @license http://unlicense.org/ UNLICENSE + * @link https://github.com/rss-bridge/rss-bridge + */ + +// based on https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Str.php + +if (!function_exists('str_starts_with')) { + function str_starts_with($haystack, $needle) { + return (string)$needle !== '' && strncmp($haystack, $needle, strlen($needle)) === 0; + } +} + +if (!function_exists('str_ends_with')) { + function str_ends_with($haystack, $needle) { + return $needle !== '' && substr($haystack, -strlen($needle)) === (string)$needle; + } +} + +if (!function_exists('str_contains')) { + function str_contains($haystack, $needle) { + return $needle !== '' && mb_strpos($haystack, $needle) !== false; + } +} diff --git a/lib/rssbridge.php b/lib/rssbridge.php index 2e7fbf2a..47a92e73 100644 --- a/lib/rssbridge.php +++ b/lib/rssbridge.php @@ -80,6 +80,7 @@ require_once PATH_LIB . 'XPathAbstract.php'; require_once PATH_LIB . 'html.php'; require_once PATH_LIB . 'error.php'; require_once PATH_LIB . 'contents.php'; +require_once PATH_LIB . 'php8backports.php'; // Vendor define('MAX_FILE_SIZE', 10000000); /* Allow larger files for simple_html_dom */ |