From 6283155f69b4a2fff775294b303cfd9180f05ed5 Mon Sep 17 00:00:00 2001 From: adminerevo Date: Fri, 17 Nov 2023 06:24:10 +0100 Subject: [PATCH] First bunch of fixes for PHP8.3 --- adminer/drivers/mysql.inc.php | 6 +++--- adminer/include/adminer.inc.php | 14 +++++++------- adminer/include/auth.inc.php | 3 +++ adminer/include/design.inc.php | 7 +++++-- adminer/include/editing.inc.php | 2 +- adminer/include/functions.inc.php | 6 +++--- adminer/select.inc.php | 17 ++++++++++------- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 1df1ad3d..50da1292 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -1092,13 +1092,13 @@ if (!defined("DRIVER")) { * @return string */ function unconvert_field($field, $return) { - if (preg_match("~binary~", $field["type"])) { + if (preg_match("~binary~", $field["type"] ?? null)) { $return = "UNHEX($return)"; } - if ($field["type"] == "bit") { + if (isset($field["type"]) && $field["type"] == "bit") { $return = "CONV($return, 2, 10) + 0"; } - if (preg_match("~geometry|point|linestring|polygon~", $field["type"])) { + if (preg_match("~geometry|point|linestring|polygon~", $field["type"] ?? null)) { $prefix = (min_version(8) ? "ST_" : ""); $return = $prefix . "GeomFromText($return, $prefix" . "SRID($field[field]))"; } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 34bc5d67..8777d1e2 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -289,11 +289,11 @@ class Adminer { * @return string */ function selectVal($val, $link, $field, $original) { - $return = ($val === null ? "NULL" : (preg_match("~char|binary|boolean~", $field["type"]) && !preg_match("~var~", $field["type"]) ? "$val" : $val)); - if (preg_match('~blob|bytea|raw|file~', $field["type"]) && !is_utf8($val)) { + $return = ($val === null ? "NULL" : (preg_match("~char|binary|boolean~", $field["type"] ?? null) && !preg_match("~var~", $field["type"] ?? null) ? "$val" : $val)); + if (preg_match('~blob|bytea|raw|file~', $field["type"] ?? null) && !is_utf8($val)) { $return = "" . lang('%d byte(s)', strlen($original)) . ""; } - if (preg_match('~json~', $field["type"])) { + if (preg_match('~json~', $field["type"] ?? null)) { $return = "$return"; } return ($link ? "$return" : $return); @@ -360,15 +360,15 @@ class Adminer { $i = 0; $select[""] = array(); foreach ($select as $key => $val) { - $val = $_GET["columns"][$key]; + $val = $_GET["columns"][$key] ?? null; $column = select_input( " name='columns[$i][col]'", $columns, - $val["col"], + $val["col"] ?? null, ($key !== "" ? "selectFieldChange" : "selectAddRow") ); echo "
" . ($functions || $grouping ? "" + . optionlist(array(-1 => "") + array_filter(array(lang('Functions') => $functions, lang('Aggregation') => $grouping)), $val["fun"] ?? null) . "" . on_help("getTarget(event).value && getTarget(event).value.replace(/ |\$/, '(') + ')'", 1) . script("qsl('select').onchange = function () { helpClose();" . ($key !== "" ? "" : " qsl('select, input', this.parentNode).onchange();") . " };", "") . "($column)" : $column) . "
\n"; @@ -641,7 +641,7 @@ class Adminer { global $jush, $driver; restart_session(); $history = &get_session("queries"); - if (!$history[$_GET["db"]]) { + if (isset($history[$_GET["db"]]) === false) { $history[$_GET["db"]] = array(); } if (strlen($query) > 1e6) { diff --git a/adminer/include/auth.inc.php b/adminer/include/auth.inc.php index a1690deb..8669351f 100644 --- a/adminer/include/auth.inc.php +++ b/adminer/include/auth.inc.php @@ -42,6 +42,9 @@ function check_invalid_login() { global $adminer; $invalids = unserialize(@file_get_contents(get_temp_dir() . "/adminer.invalid")); // @ - may not exist $invalid = ($invalids ? $invalids[$adminer->bruteForceKey()] : array()); + if ($invalid === null) { + return; + } $next_attempt = ($invalid[1] > 29 ? $invalid[0] - time() : 0); // allow 30 invalid attempts if ($next_attempt > 0) { //! do the same with permanent login auth_error(lang('Too many unsuccessful logins, try again in %d minute(s).', ceil($next_attempt / 60))); diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index 60d3b5e8..88a295d5 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -159,8 +159,11 @@ function get_nonce() { */ function page_messages($error) { $uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]); - $messages = $_SESSION["messages"][$uri]; - if ($messages) { + $messages = []; + if (isset($_SESSION["messages"][$uri])) { + $messages = $_SESSION["messages"][$uri]; + } + if (count($messages) > 0) { echo "
" . implode("
\n
", $messages) . "
" . script("messagesPrint();"); unset($_SESSION["messages"][$uri]); } diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 87b109c3..f94a18f8 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -300,7 +300,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra foreach ($fields as $i => $field) { $i++; $orig = $field[($_POST ? "orig" : "field")]; - $display = (isset($_POST["add"][$i-1]) || (isset($field["field"]) && !$_POST["drop_col"][$i])) && (support("drop_col") || $orig == ""); + $display = (isset($_POST["add"][$i-1]) || (isset($field["field"]) && isset($_POST["drop_col"][$i]) === false)) && (support("drop_col") || $orig == ""); ?> > " . html_select("fields[$i][inout]", explode("|", $inout), $field["inout"]) : ""); ?> diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 73d1169b..537c2768 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -499,7 +499,7 @@ function where($where, $fields = array()) { : " = " . unconvert_field($fields[$key], q($val)) )) ; //! enum and set - if ($jush == "sql" && preg_match('~char|text~', $fields[$key]["type"]) && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters + if ($jush == "sql" && preg_match('~char|text~', $fields[$key]["type"] ?? null) && preg_match("~[^ -@]~", $val)) { // not just [a-z] to catch non-ASCII characters $return[] = "$column = " . q($val) . " COLLATE " . charset($connection) . "_bin"; } } @@ -1343,7 +1343,7 @@ function is_url($string) { * @return bool */ function is_shortable($field) { - return preg_match('~char|text|json|lob|geometry|point|linestring|polygon|string|bytea~', $field["type"]); + return preg_match('~char|text|json|lob|geometry|point|linestring|polygon|string|bytea~', $field["type"] ?? null); } /** Get query to compute number of found rows @@ -1488,7 +1488,7 @@ function edit_form($table, $fields, $row, $update) { foreach ($fields as $name => $field) { echo "" . $adminer->fieldName($field); - $default = $_GET["set"][bracket_escape($name)]; + $default = $_GET["set"][bracket_escape($name)] ?? null; if ($default === null) { $default = $field["default"]; if ($field["type"] == "bit" && preg_match("~^b'([01]*)'\$~", $default, $regs)) { diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 99cabb45..9c6e9426 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -322,7 +322,7 @@ if (!$columns && support("table")) { $rank = 1; foreach ($rows[0] as $key => $val) { if (!isset($unselected[$key])) { - $val = $_GET["columns"][key($select)]; + $val = $_GET["columns"][key($select)] ?? null; $field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key]; $name = ($field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : $key)); if ($name != "") { @@ -333,16 +333,16 @@ if (!$columns && support("table")) { $desc = "&desc%5B0%5D=1"; echo "" . script("mixin(qsl('th'), {onmouseover: partial(columnMouse), onmouseout: partial(columnMouse, ' hidden')});", ""); echo ''; // $order[0] == $key - COUNT(*) - echo apply_sql_function($val["fun"], $name) . ""; //! columns looking like functions + echo apply_sql_function($val["fun"] ?? null, $name) . ""; //! columns looking like functions echo ""; } - $functions[$key] = $val["fun"]; + $functions[$key] = $val["fun"] ?? null; next($select); } } @@ -398,7 +398,7 @@ if (!$columns && support("table")) { } $link = ""; - if (preg_match('~blob|bytea|raw|file~', $field["type"]) && $val != "") { + if (preg_match('~blob|bytea|raw|file~', $field["type"] ?? null) && $val != "") { $link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf; } if (!$link && $val !== null) { // link related items @@ -433,9 +433,12 @@ if (!$columns && support("table")) { $val = select_value($val, $link, $field, $text_length); $id = h("val[$unique_idf][" . bracket_escape($key) . "]"); - $value = $_POST["val"][$unique_idf][bracket_escape($key)]; + $value = null; + if (isset($_POST["val"][$unique_idf][bracket_escape($key)])) { + $_POST["val"][$unique_idf][bracket_escape($key)]; + } $editable = !is_array($row[$key]) && is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key]; - $text = preg_match('~text|lob~', $field["type"]); + $text = preg_match('~text|lob~', $field["type"] ?? null); echo "