1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 22:56:46 +02:00

Move HTML function, fix types

This commit is contained in:
Jakub Vrana
2025-03-29 18:08:55 +01:00
parent 79f5280f3d
commit 87f149ce1d
3 changed files with 16 additions and 18 deletions

View File

@@ -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<array> $process e.g. (&$_GET, &$_POST, &$_COOKIE)
* @param list<array> $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<string>
*/
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]) ? "" : "<i>…</i>");
}
/** Format decimal number
* @param float|numeric-string $val
*/

View File

@@ -467,6 +467,16 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er
echo "</form>\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]) ? "" : "<i>…</i>");
}
/** Get button with icon */
function icon(string $icon, string $name, string $html, string $title): string {
return "<button type='submit' name='$name' title='" . h($title) . "' class='icon icon-$icon'><span>$html</span></button>";

View File

@@ -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