From dc38a7ded38dadb386cc68eb16b2ecba86b10362 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 28 Mar 2025 14:22:42 +0100 Subject: [PATCH] Plugins: Move operators to a method --- adminer/include/adminer.inc.php | 16 ++++++++++++---- adminer/include/auth.inc.php | 3 --- adminer/include/plugins.inc.php | 1 - editor/include/adminer.inc.php | 12 ++++++++---- plugins/drivers/mongo.php | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 8f9a207c..483ff56a 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -4,7 +4,6 @@ namespace Adminer; // any method change in this file should be transferred to editor/include/adminer.inc.php and plugins.inc.php class Adminer { - /** @var ?list */ public ?array $operators = null; // operators used in select, null for all operators /** @visibility protected(set) */ public string $error = ''; // HTML /** Name in title and navigation @@ -59,6 +58,14 @@ class Adminer { return get_databases($flush); } + /** Operators used in select + * @return list operators + */ + function operators(): array { + global $driver; + return $driver->operators; + } + /** Get list of schemas * @return list */ @@ -376,6 +383,7 @@ class Adminer { * @param Index[] $indexes */ function selectSearchPrint(array $where, array $columns, array $indexes): void { + global $adminer; print_fieldset("search", lang('Search'), $where); foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT") { @@ -388,7 +396,7 @@ class Adminer { } $change_next = "this.parentNode.firstChild.onchange();"; foreach (array_merge((array) $_GET["where"], array(array())) as $i => $val) { - if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) { + if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $adminer->operators()))) { echo "
" . select_input( " name='where[$i][col]'", $columns, @@ -396,7 +404,7 @@ class Adminer { ($val ? "selectFieldChange" : "selectAddRow"), "(" . lang('anywhere') . ")" ); - echo html_select("where[$i][op]", $this->operators, $val["op"], $change_next); + echo html_select("where[$i][op]", $adminer->operators(), $val["op"], $change_next); echo ""; echo script("mixin(qsl('input'), {oninput: function () { $change_next }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", ""); echo "
\n"; @@ -527,7 +535,7 @@ class Adminer { } } foreach ((array) $_GET["where"] as $key => $val) { - if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) { + if ("$val[col]$val[val]" != "" && in_array($val["op"], $adminer->operators())) { $prefix = ""; $cond = " $val[op]"; if (preg_match('~IN$~', $val["op"])) { diff --git a/adminer/include/auth.inc.php b/adminer/include/auth.inc.php index 903248fc..baa36588 100644 --- a/adminer/include/auth.inc.php +++ b/adminer/include/auth.inc.php @@ -185,9 +185,6 @@ if (isset($_GET["username"]) && is_string(get_password())) { $connection = connect($adminer->credentials()); if (is_object($connection)) { $driver = new Driver($connection); - if ($adminer->operators === null) { - $adminer->operators = $driver->operators; - } if ($connection->flavor) { save_settings(array("vendor-" . DRIVER . "-" . SERVER => $drivers[DRIVER])); } diff --git a/adminer/include/plugins.inc.php b/adminer/include/plugins.inc.php index 3454a1e0..723537db 100644 --- a/adminer/include/plugins.inc.php +++ b/adminer/include/plugins.inc.php @@ -6,7 +6,6 @@ class Plugins { /** @var list @visibility protected(set) */ public array $plugins; /** @visibility protected(set) */ public string $error = ''; // HTML - /** @var ?list */ public ?array $operators; //! delete /** @var list[] */ private array $hooks = array(); /** Register plugins diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index f34d3b26..c23c0428 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -2,7 +2,6 @@ namespace Adminer; class Adminer { - public $operators = array("<=", ">="); public $error = ''; private $values = array(); @@ -41,6 +40,10 @@ class Adminer { } } + function operators() { + return array("<=", ">="); + } + function schemas() { return schemas(); } @@ -235,6 +238,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row } function selectSearchPrint($where, $columns, $indexes) { + global $adminer; $where = (array) $_GET["where"]; echo '\n"; @@ -369,7 +373,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row $text_type = preg_match('~char|text|enum|set~', $field["type"]); $value = $adminer->processInput($field, (!$op && $text_type && preg_match('~^[^%]+$~', $val) ? "%$val%" : $val)); $conds[] = $driver->convertSearch($name, $where, $field) . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value" - : (in_array($op, $this->operators) || $op == "=" ? " $op $value" + : (in_array($op, $adminer->operators()) || $op == "=" ? " $op $value" : ($text_type ? " LIKE $value" : " IN (" . str_replace(",", "', '", $value) . ")" ))); diff --git a/plugins/drivers/mongo.php b/plugins/drivers/mongo.php index 0ee052fe..f9fca199 100644 --- a/plugins/drivers/mongo.php +++ b/plugins/drivers/mongo.php @@ -242,7 +242,7 @@ if (isset($_GET["mongo"])) { list(, $class, $val) = $match; $val = new $class($val); } - if (!in_array($op, adminer()->operators)) { + if (!in_array($op, adminer()->operators())) { continue; } if (preg_match('~^\(f\)(.+)~', $op, $match)) {