diff options
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/Article.php | 2 | ||||
| -rw-r--r-- | classes/Config.php | 2 | ||||
| -rw-r--r-- | classes/Db_Migrations.php | 2 | ||||
| -rw-r--r-- | classes/Feeds.php | 10 | ||||
| -rw-r--r-- | classes/OPML.php | 2 | ||||
| -rw-r--r-- | classes/Pref_Feeds.php | 4 | ||||
| -rw-r--r-- | classes/Pref_Filters.php | 6 | ||||
| -rw-r--r-- | classes/RPC.php | 4 | ||||
| -rw-r--r-- | classes/RSSUtils.php | 4 | ||||
| -rw-r--r-- | classes/Sanitizer.php | 4 | ||||
| -rw-r--r-- | classes/Templator.php | 2 | ||||
| -rw-r--r-- | classes/TimeHelper.php | 2 | ||||
| -rw-r--r-- | classes/UrlHelper.php | 17 |
13 files changed, 31 insertions, 30 deletions
diff --git a/classes/Article.php b/classes/Article.php index c668bfa74..efb5e4e89 100644 --- a/classes/Article.php +++ b/classes/Article.php @@ -623,7 +623,7 @@ class Article extends Handler_Protected { if (!$article_image) foreach ($enclosures as $enc) { - if (strpos($enc["content_type"], "image/") !== false) { + if (str_contains($enc["content_type"], "image/")) { $article_image = $enc["content_url"]; break; } diff --git a/classes/Config.php b/classes/Config.php index 4775faf71..e22808faa 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -510,7 +510,7 @@ class Config { $errors = []; - if (strpos(self::get(Config::PLUGINS), "auth_") === false) { + if (!str_contains(self::get(Config::PLUGINS), "auth_")) { array_push($errors, "Please enable at least one authentication module via PLUGINS"); } diff --git a/classes/Db_Migrations.php b/classes/Db_Migrations.php index c2a8c326d..7dcfc24b1 100644 --- a/classes/Db_Migrations.php +++ b/classes/Db_Migrations.php @@ -190,7 +190,7 @@ class Db_Migrations { if (file_exists($filename)) { $lines = array_filter(preg_split("/[\r\n]/", file_get_contents($filename)), - fn($line) => strlen(trim($line)) > 0 && strpos($line, "--") !== 0); + fn($line) => strlen(trim($line)) > 0 && !str_starts_with($line, "--")); return array_filter(explode(";", implode("", $lines)), fn($line) => strlen(trim($line)) > 0 && !in_array(strtolower($line), ["begin", "commit"])); diff --git a/classes/Feeds.php b/classes/Feeds.php index d3a28fe8d..39380cc01 100644 --- a/classes/Feeds.php +++ b/classes/Feeds.php @@ -152,8 +152,8 @@ class Feeds extends Handler_Protected { $feed_title = $qfh_ret[1]; $feed_site_url = $qfh_ret[2]; $last_error = $qfh_ret[3]; - $last_updated = strpos($qfh_ret[4] ?? "", '1970-') === false ? - TimeHelper::make_local_datetime($qfh_ret[4], false) : __("Never"); + $last_updated = str_contains($qfh_ret[4] ?? "", '1970-') ? + __("Never") : TimeHelper::make_local_datetime($qfh_ret[4], false); $highlight_words = $qfh_ret[5]; $reply['first_id'] = $qfh_ret[6]; $reply['is_vfeed'] = $qfh_ret[7]; @@ -1073,7 +1073,7 @@ class Feeds extends Handler_Protected { return array("code" => 5, "message" => UrlHelper::$fetch_last_error); } - if (mb_strpos(UrlHelper::$fetch_last_content_type, "html") !== false && self::_is_html($contents)) { + if (str_contains(UrlHelper::$fetch_last_content_type, "html") && self::_is_html($contents)) { $feedUrls = self::_get_feeds_from_html($url, $contents); if (count($feedUrls) == 0) { @@ -2205,7 +2205,7 @@ class Feeds extends Handler_Protected { /** @var string $k a keyword pair (not yet split) or standalone value */ foreach ($keywords as $k) { - if (strpos($k, "-") === 0) { + if (str_starts_with($k, "-")) { $k = substr($k, 1); $not = "NOT"; } else { @@ -2311,7 +2311,7 @@ class Feeds extends Handler_Protected { break; default: // @{date} handling - if (strpos($k, "@") === 0) { + if (str_starts_with($k, "@")) { $user_tz_string = Prefs::get(Prefs::USER_TIMEZONE, $_SESSION['uid']); $orig_ts = strtotime(substr($k, 1)); $k = date("Y-m-d", TimeHelper::convert_timestamp($orig_ts, $user_tz_string, 'UTC')); diff --git a/classes/OPML.php b/classes/OPML.php index e2ec6a7ff..1debc8623 100644 --- a/classes/OPML.php +++ b/classes/OPML.php @@ -217,7 +217,7 @@ class OPML extends Handler_Protected { $match = []; foreach (json_decode($tmp_line["match_on"], true) as $feed_id) { - if (strpos($feed_id, "CAT:") === 0) { + if (str_starts_with($feed_id, "CAT:")) { $feed_id = (int)substr($feed_id, 4); if ($feed_id) { array_push($match, [Feeds::_get_cat_title($feed_id), true, false]); diff --git a/classes/Pref_Feeds.php b/classes/Pref_Feeds.php index 7256a5dce..0dc79bceb 100644 --- a/classes/Pref_Feeds.php +++ b/classes/Pref_Feeds.php @@ -385,7 +385,7 @@ class Pref_Feeds extends Handler_Protected { if ($item['_reference']) { - if (strpos($id, "FEED") === 0) { + if (str_starts_with($id, "FEED")) { $feed = ORM::for_table('ttrss_feeds') ->where('owner_uid', $_SESSION['uid']) @@ -396,7 +396,7 @@ class Pref_Feeds extends Handler_Protected { $feed->cat_id = ($item_id != "root" && $bare_item_id) ? $bare_item_id : null; $feed->save(); } - } else if (strpos($id, "CAT:") === 0) { + } else if (str_starts_with($id, "CAT:")) { $this->process_category_order($data_map, $item['_reference'], $item_id, $nest_level+1); diff --git a/classes/Pref_Filters.php b/classes/Pref_Filters.php index 45b11d345..46180e0cb 100644 --- a/classes/Pref_Filters.php +++ b/classes/Pref_Filters.php @@ -106,7 +106,7 @@ class Pref_Filters extends Handler_Protected { /** @var int|string $feed_id may be a category string (e.g. 'CAT:7') or feed ID int */ foreach ($rule["feed_id"] as $feed_id) { - if (strpos("$feed_id", "CAT:") === 0) { + if (str_starts_with("$feed_id", "CAT:")) { $cat_id = (int) substr("$feed_id", 4); array_push($scope_inner_qparts, "cat_id = " . $cat_id); } else if (is_numeric($feed_id) && $feed_id > 0) { @@ -206,7 +206,7 @@ class Pref_Filters extends Handler_Protected { foreach ($feeds as $feed_id) { - if (strpos($feed_id, "CAT:") === 0) { + if (str_starts_with($feed_id, "CAT:")) { $feed_id = (int)substr($feed_id, 4); array_push($feeds_fmt, Feeds::_get_cat_title($feed_id)); } else { @@ -404,7 +404,7 @@ class Pref_Filters extends Handler_Protected { foreach ($feeds as $feed_id) { - if (strpos($feed_id, "CAT:") === 0) { + if (str_starts_with($feed_id, "CAT:")) { $feed_id = (int)substr($feed_id, 4); array_push($feeds_fmt, Feeds::_get_cat_title($feed_id)); } else { diff --git a/classes/RPC.php b/classes/RPC.php index 6edc88480..03786beaa 100644 --- a/classes/RPC.php +++ b/classes/RPC.php @@ -23,7 +23,7 @@ class RPC extends Handler_Protected { for ($i = 0; $i < $l10n->total; $i++) { if (isset($l10n->table_originals[$i * 2 + 2]) && $orig = $l10n->get_original_string($i)) { - if(strpos($orig, "\000") !== false) { // Plural forms + if(str_contains($orig, "\000")) { // Plural forms $key = explode(chr(0), $orig); $rv[$key[0]] = _ngettext($key[0], $key[1], 1); // Singular @@ -774,7 +774,7 @@ class RPC extends Handler_Protected { if (!empty($omap[$action])) { foreach ($omap[$action] as $sequence) { - if (strpos($sequence, "|") !== false) { + if (str_contains($sequence, "|")) { $sequence = substr($sequence, strpos($sequence, "|")+1, strlen($sequence)); diff --git a/classes/RSSUtils.php b/classes/RSSUtils.php index 97b52c9aa..1c931e7e7 100644 --- a/classes/RSSUtils.php +++ b/classes/RSSUtils.php @@ -1432,7 +1432,7 @@ class RSSUtils { /** @var DOMElement $entry */ foreach ($entries as $entry) { foreach (array('src', 'poster') as $attr) { - if ($entry->hasAttribute($attr) && strpos($entry->getAttribute($attr), "data:") !== 0) { + if ($entry->hasAttribute($attr) && !str_starts_with($entry->getAttribute($attr), "data:")) { self::cache_media_url($cache, $entry->getAttribute($attr), $site_url); } } @@ -1753,7 +1753,7 @@ class RSSUtils { if ($dh) { while (($old_filename = readdir($dh)) !== false) { - if (strpos($old_filename, ".ico") !== false) { + if (str_ends_with($old_filename, ".ico")) { $new_filename = str_replace(".ico", "", $old_filename); $old_full_path = "$old_dir/$old_filename"; diff --git a/classes/Sanitizer.php b/classes/Sanitizer.php index 20ca72dc8..94d6fe621 100644 --- a/classes/Sanitizer.php +++ b/classes/Sanitizer.php @@ -20,11 +20,11 @@ class Sanitizer { foreach ($entry->attributes as $attr) { - if (strpos($attr->nodeName, 'on') === 0) { + if (str_starts_with($attr->nodeName, 'on')) { array_push($attrs_to_remove, $attr); } - if (strpos($attr->nodeName, "data-") === 0) { + if (str_starts_with($attr->nodeName, 'data-')) { array_push($attrs_to_remove, $attr); } diff --git a/classes/Templator.php b/classes/Templator.php index b682f8b82..e083bd425 100644 --- a/classes/Templator.php +++ b/classes/Templator.php @@ -5,7 +5,7 @@ class Templator extends MiniTemplator { /* this reads tt-rss template from templates.local/ or templates/ if only base filename is given */ function readTemplateFromFile ($fileName) { - if (strpos($fileName, "/") === false) { + if (!str_contains($fileName, "/")) { $fileName = basename($fileName); diff --git a/classes/TimeHelper.php b/classes/TimeHelper.php index a516f83a6..07df3b87c 100644 --- a/classes/TimeHelper.php +++ b/classes/TimeHelper.php @@ -9,7 +9,7 @@ class TimeHelper { return T_sprintf("%d min", date("i", time() + $tz_offset - $timestamp)); } else if (date("Y.m.d", $timestamp) == date("Y.m.d", time() + $tz_offset)) { $format = Prefs::get(Prefs::SHORT_DATE_FORMAT, $owner_uid, $profile); - if (strpos((strtolower($format)), "a") === false) + if (!str_contains((strtolower($format)), "a")) return date("G:i", $timestamp); else return date("g:i a", $timestamp); diff --git a/classes/UrlHelper.php b/classes/UrlHelper.php index add3d7d6b..ad01266ee 100644 --- a/classes/UrlHelper.php +++ b/classes/UrlHelper.php @@ -86,7 +86,7 @@ class UrlHelper { return self::validate($rel_url); // protocol-relative URL (rare but they exist) - } else if (strpos($rel_url, "//") === 0) { + } else if (str_starts_with($rel_url, "//")) { return self::validate("https:" . $rel_url); // allow some extra schemes for A href } else if (in_array($rel_parts["scheme"] ?? "", self::EXTRA_HREF_SCHEMES, true) && @@ -118,10 +118,10 @@ class UrlHelper { // 1. absolute relative path (/test.html) = no-op, proceed as is // 2. dotslash relative URI (./test.html) - strip "./", append base path - if (strpos($rel_parts['path'], './') === 0) { + if (str_starts_with($rel_parts['path'], './')) { $rel_parts['path'] = $base_path . substr($rel_parts['path'], 2); // 3. anything else relative (test.html) - append dirname() of base path - } else if (strpos($rel_parts['path'], '/') !== 0) { + } else if (!str_starts_with($rel_parts['path'], '/')) { $rel_parts['path'] = $base_path . $rel_parts['path']; } @@ -141,7 +141,7 @@ class UrlHelper { $url = clean($url); # fix protocol-relative URLs - if (strpos($url, "//") === 0) + if (str_starts_with($url, "//")) $url = "https:" . $url; $tokens = parse_url($url); @@ -191,7 +191,8 @@ class UrlHelper { if (!in_array($tokens['port'] ?? '', [80, 443, ''])) return false; - if (strtolower($tokens['host']) == 'localhost' || $tokens['host'] == '::1' || strpos($tokens['host'], '127.') === 0) + if (strtolower($tokens['host']) == 'localhost' || $tokens['host'] == '::1' + || str_starts_with($tokens['host'], '127.')) return false; } @@ -295,7 +296,7 @@ class UrlHelper { $url_host = parse_url($url, PHP_URL_HOST); $ip_addr = gethostbyname($url_host); - if (!$ip_addr || strpos($ip_addr, '127.') === 0) { + if (!$ip_addr || str_starts_with($ip_addr, '127.')) { self::$fetch_last_error = "URL hostname failed to resolve or resolved to a loopback address ($ip_addr)"; return false; } @@ -396,7 +397,7 @@ class UrlHelper { self::$fetch_last_content_type = $ex->getResponse()->getHeaderLine('content-type'); - if ($type && strpos(self::$fetch_last_content_type, "$type") === false) + if ($type && !str_contains(self::$fetch_last_content_type, "$type")) self::$fetch_last_error_content = (string) $ex->getResponse()->getBody(); } elseif (array_key_exists('errno', $ex->getHandlerContext())) { $errno = (int) $ex->getHandlerContext()['errno']; @@ -433,7 +434,7 @@ class UrlHelper { self::$fetch_effective_ip_addr = gethostbyname(parse_url(self::$fetch_effective_url, PHP_URL_HOST)); - if (!self::$fetch_effective_ip_addr || strpos(self::$fetch_effective_ip_addr, '127.') === 0) { + if (!self::$fetch_effective_ip_addr || str_starts_with(self::$fetch_effective_ip_addr, '127.')) { self::$fetch_last_error = 'URL hostname received after redirection failed to resolve or resolved to a loopback address (' . self::$fetch_effective_ip_addr . ')'; return false; |