From 667528d5b927f0f284a067b0e24c9ca7f26c28a4 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sat, 23 Nov 2024 18:23:49 +0000 Subject: Use PHP 8 'str_' functions. A few more characters in some places, but helps with readability. --- include/colors.php | 2 +- include/controls.php | 6 +++--- include/functions.php | 6 +----- include/login_form.php | 2 +- 4 files changed, 6 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/colors.php b/include/colors.php index 35b84b9de..2dfa10dce 100644 --- a/include/colors.php +++ b/include/colors.php @@ -221,7 +221,7 @@ function _color_hue2rgb(float $m1, float $m2, float $h): int { * @return array{0: int, 1: int, 2: int} */ function _color_unpack(string $hex, bool $normalize = false): array { - $hex = strpos($hex, '#') !== 0 ? _resolve_htmlcolor($hex) : substr($hex, 1); + $hex = str_starts_with($hex, '#') ? substr($hex, 1) : _resolve_htmlcolor($hex); if (strlen($hex) == 4) { $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3]; diff --git a/include/controls.php b/include/controls.php index 4443bbc55..5c6174e3d 100755 --- a/include/controls.php +++ b/include/controls.php @@ -46,7 +46,7 @@ */ function input_tag(string $name, string $value, string $type = "text", array $attributes = [], string $id = ""): string { $attributes_str = attributes_to_string($attributes); - $dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='dijit.form.TextBox'" : ""; + $dojo_type = str_contains($attributes_str, "dojoType") ? "" : "dojoType='dijit.form.TextBox'"; return ""; @@ -86,7 +86,7 @@ */ function select_tag(string $name, mixed $value, array $values, array $attributes = [], string $id = ""): string { $attributes_str = attributes_to_string($attributes); - $dojo_type = strpos($attributes_str, "dojoType") === false ? "dojoType='fox.form.Select'" : ""; + $dojo_type = str_contains($attributes_str, "dojoType") ? "" : "dojoType='fox.form.Select'"; $rv = ""; diff --git a/include/functions.php b/include/functions.php index 95d31b248..5e906a977 100644 --- a/include/functions.php +++ b/include/functions.php @@ -279,11 +279,7 @@ } function with_trailing_slash(string $str) : string { - if (substr($str, -1) === "/") { - return $str; - } else { - return "$str/"; - } + return str_ends_with($str, '/') ? $str : "$str/"; } function make_password(int $length = 12): string { diff --git a/include/login_form.php b/include/login_form.php index 5ff2b378e..c0f1a93af 100755 --- a/include/login_form.php +++ b/include/login_form.php @@ -138,7 +138,7 @@ onblur="UtilityApp.fetchProfiles()" value=""/> - +
-- cgit v1.2.3-54-g00ecf