mirror of
https://github.com/vrana/adminer.git
synced 2025-08-06 06:37:33 +02:00
Plugins: Move operators to a method
This commit is contained in:
@@ -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"])) {
|
||||
|
@@ -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]));
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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) . ")"
|
||||
)));
|
||||
|
@@ -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)) {
|
||||
|
Reference in New Issue
Block a user