diff --git a/admin/admin_user_search.php b/admin/admin_user_search.php index f0f5a956d..6bd5a9140 100644 --- a/admin/admin_user_search.php +++ b/admin/admin_user_search.php @@ -255,7 +255,7 @@ if (!isset($_REQUEST['dosearch'])) { $username = str_replace("\*", '%', trim(strip_tags(strtolower($username)))); - if (false !== strpos($username, '%')) { + if (str_contains($username, '%')) { $op = 'LIKE'; } else { $op = '='; @@ -276,7 +276,7 @@ if (!isset($_REQUEST['dosearch'])) { $email = str_replace("\*", '%', trim(strip_tags(strtolower($email)))); - if (false !== strpos($email, '%')) { + if (str_contains($email, '%')) { $op = 'LIKE'; } else { $op = '='; @@ -524,7 +524,7 @@ if (!isset($_REQUEST['dosearch'])) { break; case 'equals': // looking for a - - if (false !== strpos($postcount_value, '-')) { + if (str_contains($postcount_value, '-')) { $range = preg_split('/[-\s]+/', $postcount_value); $range_begin = (int)$range[0]; @@ -571,7 +571,7 @@ if (!isset($_REQUEST['dosearch'])) { $userfield_value = str_replace("\*", '%', trim(strip_tags(strtolower($userfield_value)))); - if (false !== strpos($userfield_value, '%')) { + if (str_contains($userfield_value, '%')) { $op = 'LIKE'; } else { $op = '='; diff --git a/bt/announce.php b/bt/announce.php index 79dec7adb..2a2a42fb0 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -27,7 +27,7 @@ if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) { } // Initial request verification -if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) { +if (str_contains($_SERVER['REQUEST_URI'], 'scrape')) { msg_die('Please disable SCRAPE!'); } diff --git a/dl.php b/dl.php index d74d3943d..d3f6f4a8a 100644 --- a/dl.php +++ b/dl.php @@ -38,7 +38,7 @@ function send_file_to_browser($attachment, $upload_dir) // Correct the mime type - we force application/octet-stream for all files, except images // Please do not change this, it is a security precaution - if (false === strpos($attachment['mimetype'], 'image')) { + if (!str_contains($attachment['mimetype'], 'image')) { $attachment['mimetype'] = 'application/octet-stream'; } diff --git a/library/ajax/manage_admin.php b/library/ajax/manage_admin.php index 869eebcd6..9a4019b51 100644 --- a/library/ajax/manage_admin.php +++ b/library/ajax/manage_admin.php @@ -41,7 +41,7 @@ switch ($mode) { $dir = $template->cachedir; $res = @opendir($dir); while (($file = readdir($res)) !== false) { - if (0 === strpos($file, $match)) { + if (str_starts_with($file, $match)) { @unlink($dir . $file); } } diff --git a/library/attach_mod/includes/functions_attach.php b/library/attach_mod/includes/functions_attach.php index 5c0b7f22c..46433e857 100644 --- a/library/attach_mod/includes/functions_attach.php +++ b/library/attach_mod/includes/functions_attach.php @@ -382,7 +382,7 @@ function attachment_sync_topic($topics) */ function get_extension($filename) { - if (false === strpos($filename, '.')) { + if (!str_contains($filename, '.')) { return ''; } $extension = strrchr(strtolower($filename), '.'); diff --git a/library/attach_mod/includes/functions_delete.php b/library/attach_mod/includes/functions_delete.php index b462226c6..adc1672f9 100644 --- a/library/attach_mod/includes/functions_delete.php +++ b/library/attach_mod/includes/functions_delete.php @@ -26,9 +26,9 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $post_id_array = []; if (!is_array($attach_id_array)) { - if (false !== strpos($attach_id_array, ', ')) { + if (str_contains($attach_id_array, ', ')) { $attach_id_array = explode(', ', $attach_id_array); - } elseif (false !== strpos($attach_id_array, ',')) { + } elseif (str_contains($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); } else { $attach_id = (int)$attach_id_array; @@ -67,9 +67,9 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, return; } - if (false !== strpos($post_id_array, ', ')) { + if (str_contains($post_id_array, ', ')) { $post_id_array = explode(', ', $post_id_array); - } elseif (false !== strpos($post_id_array, ',')) { + } elseif (str_contains($post_id_array, ',')) { $post_id_array = explode(',', $post_id_array); } else { $post_id = (int)$post_id_array; @@ -112,9 +112,9 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, } if (!is_array($attach_id_array)) { - if (false !== strpos($attach_id_array, ', ')) { + if (str_contains($attach_id_array, ', ')) { $attach_id_array = explode(', ', $attach_id_array); - } elseif (false !== strpos($attach_id_array, ',')) { + } elseif (str_contains($attach_id_array, ',')) { $attach_id_array = explode(',', $attach_id_array); } else { $attach_id = (int)$attach_id_array; diff --git a/library/defines.php b/library/defines.php index 4646deb2e..a54af9007 100644 --- a/library/defines.php +++ b/library/defines.php @@ -97,7 +97,7 @@ define('CRON_RUNNING', TRIGGERS_DIR . '/cron_running'); // Gzip define('GZIP_OUTPUT_ALLOWED', extension_loaded('zlib') && !ini_get('zlib.output_compression')); -define('UA_GZIP_SUPPORTED', isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false); +define('UA_GZIP_SUPPORTED', isset($_SERVER['HTTP_ACCEPT_ENCODING']) && str_contains($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')); // Torrents (reserved: -1) define('TOR_NOT_APPROVED', 0); // не проверено diff --git a/library/includes/functions.php b/library/includes/functions.php index 8dd9206d2..e1b39b9ff 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -553,7 +553,7 @@ function url_arg($url, $arg, $value, $amp = '&') $url = str_replace($cur, $new, $url); } // добавляем параметр elseif (null !== $value) { - $div = (strpos($url, '?') !== false) ? $amp : '?'; + $div = str_contains($url, '?') ? $amp : '?'; $url = $url . $div . $arg . '=' . urlencode($value); } return $url . $anchor; @@ -1469,7 +1469,7 @@ function redirect($url) trigger_error("Headers already sent in $filename($linenum)", E_USER_ERROR); } - if (false !== strpos(urldecode($url), "\n") || false !== strpos(urldecode($url), "\r") || false !== strpos(urldecode($url), ';url')) { + if (str_contains(urldecode($url), "\n") || str_contains(urldecode($url), "\r") || str_contains(urldecode($url), ';url')) { bb_die('Tried to redirect to potentially insecure url'); } diff --git a/login.php b/login.php index 5dc20198e..5cfd5627b 100644 --- a/login.php +++ b/login.php @@ -32,7 +32,7 @@ $login_errors = []; if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING'], $matches)) { $redirect_url = $matches[1]; - if (false === strpos($redirect_url, '?') && $first_amp = strpos($redirect_url, '&')) { + if (!str_contains($redirect_url, '?') && $first_amp = strpos($redirect_url, '&')) { $redirect_url[$first_amp] = '?'; } } elseif (!empty($_POST['redirect'])) { @@ -43,7 +43,7 @@ if (preg_match('/^redirect=([a-z0-9\.#\/\?&=\+\-_]+)/si', $_SERVER['QUERY_STRING $redirect_url = str_replace(['&admin=1', '?admin=1'], '', $redirect_url); -if (!$redirect_url || false !== strpos(urldecode($redirect_url), "\n") || false !== strpos(urldecode($redirect_url), "\r") || false !== strpos(urldecode($redirect_url), ';url')) { +if (!$redirect_url || str_contains(urldecode($redirect_url), "\n") || str_contains(urldecode($redirect_url), "\r") || str_contains(urldecode($redirect_url), ';url')) { $redirect_url = 'index.php'; } diff --git a/src/Helpers/IPHelper.php b/src/Helpers/IPHelper.php index 664e58d03..cfa1dfe81 100644 --- a/src/Helpers/IPHelper.php +++ b/src/Helpers/IPHelper.php @@ -29,7 +29,7 @@ class IPHelper extends Ip public static function anonymizeIP(string $ip): string { $wrappedIPv6 = false; - if ('[' === substr($ip, 0, 1) && ']' === substr($ip, -1, 1)) { + if (str_starts_with($ip, '[') && str_ends_with($ip, ']')) { $wrappedIPv6 = true; $ip = substr($ip, 1, -1); } diff --git a/src/Legacy/BBCode.php b/src/Legacy/BBCode.php index 3ffb4fcbc..7684e7b88 100644 --- a/src/Legacy/BBCode.php +++ b/src/Legacy/BBCode.php @@ -169,7 +169,7 @@ class BBCode private function parse($text): string { // Tag parse - if (strpos($text, '[') === false) { + if (!str_contains($text, '[')) { return $text; } diff --git a/src/Legacy/SqlDb.php b/src/Legacy/SqlDb.php index 345c23cea..f6a772759 100644 --- a/src/Legacy/SqlDb.php +++ b/src/Legacy/SqlDb.php @@ -968,7 +968,7 @@ class SqlDb $query = "SELECT * FROM $m[1] WHERE $m[2]"; } - if (0 === strpos($query, "SELECT")) { + if (str_starts_with($query, "SELECT")) { $html_table = false; if ($result = mysqli_query($this->link, "EXPLAIN $query")) { diff --git a/src/Legacy/Template.php b/src/Legacy/Template.php index ca028202e..b05826bb4 100644 --- a/src/Legacy/Template.php +++ b/src/Legacy/Template.php @@ -310,7 +310,7 @@ class Template */ public function assign_block_vars($blockname, $vararray) { - if (false !== strpos($blockname, '.')) { + if (str_contains($blockname, '.')) { // Nested block. $blocks = explode('.', $blockname); $blockcount = \count($blocks) - 1; @@ -994,7 +994,7 @@ class Template $this->vars['LANG'] ??= $bb_cfg['default_lang']; // adding current template $tpl = $this->root . '/'; - if (0 === strpos($tpl, './')) { + if (str_starts_with($tpl, './')) { $tpl = substr($tpl, 2, \strlen($tpl)); } $this->vars['TEMPLATE'] ??= $tpl;