]> git.joonet.de Git - adminer.git/commitdiff
Plugins: Move operators to a method
authorJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 13:22:42 +0000 (14:22 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 13:30:00 +0000 (14:30 +0100)
adminer/include/adminer.inc.php
adminer/include/auth.inc.php
adminer/include/plugins.inc.php
editor/include/adminer.inc.php
plugins/drivers/mongo.php

index 8f9a207cc00a9e79a21139c21039ce5a7844dff2..483ff56a1c314d1bdd79df0d38455dc6a4a80f1b 100644 (file)
@@ -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<string> */ 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<string> operators
+       */
+       function operators(): array {
+               global $driver;
+               return $driver->operators;
+       }
+
        /** Get list of schemas
        * @return list<string>
        */
@@ -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 "<div>" . 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 "<input type='search' name='where[$i][val]' value='" . h($val["val"]) . "'>";
                                echo script("mixin(qsl('input'), {oninput: function () { $change_next }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", "");
                                echo "</div>\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"])) {
index 903248fcb01daf1c4684844d61945de0862b40e5..baa36588fdbf0fe4c1c7df1eb4d26db2db5c4f66 100644 (file)
@@ -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]));
                }
index 3454a1e0b6bd7c9d7a225b335d441cbdeba9df95..723537dbc03fca4b360d6c42b7957b0fe592db7e 100644 (file)
@@ -6,7 +6,6 @@ class Plugins {
 
        /** @var list<object> @visibility protected(set) */ public array $plugins;
        /** @visibility protected(set) */ public string $error = ''; // HTML
-       /** @var ?list<string> */ public ?array $operators; //! delete
        /** @var list<object>[] */ private array $hooks = array();
 
        /** Register plugins
index f34d3b26132633784b852114ceb52a5e6e60ad6a..c23c0428ecf950da2a39e85141a4c2cadcc808b1 100644 (file)
@@ -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 '<fieldset id="fieldset-search"><legend>' . lang('Search') . "</legend><div>\n";
                $keys = array();
@@ -269,14 +273,14 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
                foreach ($where as $val) {
                        if (($val["col"] == "" || $columns[$val["col"]]) && "$val[col]$val[val]" != "") {
                                echo "<div><select name='where[$i][col]'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, $val["col"], true) . "</select>";
-                               echo html_select("where[$i][op]", array(-1 => "") + $this->operators, $val["op"]);
+                               echo html_select("where[$i][op]", array(-1 => "") + $adminer->operators(), $val["op"]);
                                echo "<input type='search' name='where[$i][val]' value='" . h($val["val"]) . "'>" . script("mixin(qsl('input'), {onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", "") . "</div>\n";
                                $i++;
                        }
                }
                echo "<div><select name='where[$i][col]'><option value=''>(" . lang('anywhere') . ")" . optionlist($columns, null, true) . "</select>";
                echo script("qsl('select').onchange = selectAddRow;", "");
-               echo html_select("where[$i][op]", array(-1 => "") + $this->operators);
+               echo html_select("where[$i][op]", array(-1 => "") + $adminer->operators());
                echo "<input type='search' name='where[$i][val]'></div>";
                echo script("mixin(qsl('input'), {onchange: function () { this.parentNode.firstChild.onchange(); }, onsearch: selectSearchSearch});");
                echo "</div></fieldset>\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) . ")"
                                                        )));
index 0ee052fe1cf2ff46cd9e532c0740a66db484c001..f9fca199307500abb49f8b317452e91a84e9edbf 100644 (file)
@@ -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)) {