First bunch of fixes for PHP8.3

This commit is contained in:
adminerevo 2023-11-17 06:24:10 +01:00
parent 4d81695272
commit 6283155f69
7 changed files with 32 additions and 23 deletions

View file

@ -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]))";
}

View file

@ -289,11 +289,11 @@ class Adminer {
* @return string
*/
function selectVal($val, $link, $field, $original) {
$return = ($val === null ? "<i>NULL</i>" : (preg_match("~char|binary|boolean~", $field["type"]) && !preg_match("~var~", $field["type"]) ? "<code>$val</code>" : $val));
if (preg_match('~blob|bytea|raw|file~', $field["type"]) && !is_utf8($val)) {
$return = ($val === null ? "<i>NULL</i>" : (preg_match("~char|binary|boolean~", $field["type"] ?? null) && !preg_match("~var~", $field["type"] ?? null) ? "<code>$val</code>" : $val));
if (preg_match('~blob|bytea|raw|file~', $field["type"] ?? null) && !is_utf8($val)) {
$return = "<i>" . lang('%d byte(s)', strlen($original)) . "</i>";
}
if (preg_match('~json~', $field["type"])) {
if (preg_match('~json~', $field["type"] ?? null)) {
$return = "<code class='jush-js'>$return</code>";
}
return ($link ? "<a href='" . h($link) . "'" . (is_url($link) ? target_blank() : "") . ">$return</a>" : $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 "<div>" . ($functions || $grouping ? "<select name='columns[$i][fun]'>"
. optionlist(array(-1 => "") + array_filter(array(lang('Functions') => $functions, lang('Aggregation') => $grouping)), $val["fun"]) . "</select>"
. optionlist(array(-1 => "") + array_filter(array(lang('Functions') => $functions, lang('Aggregation') => $grouping)), $val["fun"] ?? null) . "</select>"
. 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) . "</div>\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) {

View file

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

View file

@ -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 "<div class='message'>" . implode("</div>\n<div class='message'>", $messages) . "</div>" . script("messagesPrint();");
unset($_SESSION["messages"][$uri]);
}

View file

@ -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 == "");
?>
<tr<?php echo ($display ? "" : " style='display: none;'"); ?>>
<?php echo ($type == "PROCEDURE" ? "<td>" . html_select("fields[$i][inout]", explode("|", $inout), $field["inout"]) : ""); ?>

View file

@ -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 "<tr><th>" . $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)) {

View file

@ -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 "<th id='th[" . h(bracket_escape($key)) . "]'>" . script("mixin(qsl('th'), {onmouseover: partial(columnMouse), onmouseout: partial(columnMouse, ' hidden')});", "");
echo '<a href="' . h($href . ($order[0] == $column || $order[0] == $key || (!$order && $is_group && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*)
echo apply_sql_function($val["fun"], $name) . "</a>"; //! columns looking like functions
echo apply_sql_function($val["fun"] ?? null, $name) . "</a>"; //! columns looking like functions
echo "<span class='column hidden'>";
echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
if (!$val["fun"]) {
if (isset($val["fun"]) === false) {
echo '<a href="#fieldset-search" title="' . lang('Search') . '" class="text jsonly"> =</a>';
echo script("qsl('a').onclick = partial(selectSearch, '" . js_escape($key) . "');");
}
echo "</span>";
}
$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 "<td id='$id'";
if (($_GET["modify"] && $editable) || $value !== null) {
$h_value = h($value !== null ? $value : $row[$key]);