From 87f149ce1d47eba6b0ea99db72dadbbd187b9e98 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sat, 29 Mar 2025 18:08:55 +0100 Subject: [PATCH] Move HTML function, fix types --- adminer/include/functions.inc.php | 22 +++++----------------- adminer/include/html.inc.php | 10 ++++++++++ adminer/include/plugins.inc.php | 2 +- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 005f3dce..c8fbf48d 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -11,17 +11,15 @@ function connection(): Db { } /** Get Adminer object -* @return Adminer +* @return Adminer|Plugins */ function adminer() { global $adminer; return $adminer; } -/** Get Driver object -* @return Driver -*/ -function driver() { +/** Get Driver object */ +function driver(): Driver { global $driver; return $driver; } @@ -70,7 +68,7 @@ function number_type(): string { } /** Disable magic_quotes_gpc -* @param list $process e.g. (&$_GET, &$_POST, &$_COOKIE) +* @param list $process e.g. [&$_GET, &$_POST, &$_COOKIE] * @param bool $filter whether to leave values as is * @return void modified in place */ @@ -172,7 +170,7 @@ function get_val(string $query, int $field = 0, ?Db $conn = null) { } /** Get list of values from database -* @param mixed $column +* @param array-key $column * @return list */ function get_vals(string $query, $column = 0): array { @@ -566,16 +564,6 @@ function is_utf8(?string $val): bool { return (preg_match('~~u', $val) && !preg_match('~[\0-\x8\xB\xC\xE-\x1F]~', $val)); } -/** Shorten UTF-8 string -* @return string escaped string with appended ... -*/ -function shorten_utf8(string $string, int $length = 80, string $suffix = ""): string { - if (!preg_match("(^(" . repeat_pattern("[\t\r\n -\x{10FFFF}]", $length) . ")($)?)u", $string, $match)) { // ~s causes trash in $match[2] under some PHP versions, (.|\n) is slow - preg_match("(^(" . repeat_pattern("[\t\r\n -~]", $length) . ")($)?)", $string, $match); - } - return h($match[1]) . $suffix . (isset($match[2]) ? "" : ""); -} - /** Format decimal number * @param float|numeric-string $val */ diff --git a/adminer/include/html.inc.php b/adminer/include/html.inc.php index ad9260c9..2f804d52 100644 --- a/adminer/include/html.inc.php +++ b/adminer/include/html.inc.php @@ -467,6 +467,16 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er echo "\n"; } +/** Shorten UTF-8 string +* @return string escaped string with appended ... +*/ +function shorten_utf8(string $string, int $length = 80, string $suffix = ""): string { + if (!preg_match("(^(" . repeat_pattern("[\t\r\n -\x{10FFFF}]", $length) . ")($)?)u", $string, $match)) { // ~s causes trash in $match[2] under some PHP versions, (.|\n) is slow + preg_match("(^(" . repeat_pattern("[\t\r\n -~]", $length) . ")($)?)", $string, $match); + } + return h($match[1]) . $suffix . (isset($match[2]) ? "" : ""); +} + /** Get button with icon */ function icon(string $icon, string $name, string $html, string $title): string { return ""; diff --git a/adminer/include/plugins.inc.php b/adminer/include/plugins.inc.php index 723537db..6c22dbdb 100644 --- a/adminer/include/plugins.inc.php +++ b/adminer/include/plugins.inc.php @@ -64,7 +64,7 @@ class Plugins { * @param mixed[] $params * @return mixed */ - function __call($name, array $params) { + function __call(string $name, array $params) { $args = array(); foreach ($params as $key => $val) { // some plugins accept params by reference - we don't need to propage it outside, just to the other plugins