mirror of
https://github.com/vrana/adminer.git
synced 2025-08-07 15:16:44 +02:00
Use adminer() instead of $adminer
This commit is contained in:
@@ -36,12 +36,12 @@ if (!$error && $_POST) {
|
||||
$start = microtime(true);
|
||||
$result = $connection->multi_query($query);
|
||||
$affected = $connection->affected_rows; // getting warnings overwrites this
|
||||
echo $adminer->selectQuery($query, $start, !$result);
|
||||
echo adminer()->selectQuery($query, $start, !$result);
|
||||
|
||||
if (!$result) {
|
||||
echo "<p class='error'>" . error() . "\n";
|
||||
} else {
|
||||
$connection2 = connect($adminer->credentials());
|
||||
$connection2 = connect(adminer()->credentials());
|
||||
if (is_object($connection2)) {
|
||||
$connection2->select_db(DB);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ if ($in) {
|
||||
foreach ($in as $key) {
|
||||
$field = $routine["fields"][$key];
|
||||
$name = $field["field"];
|
||||
echo "<tr><th>" . $adminer->fieldName($field);
|
||||
echo "<tr><th>" . adminer()->fieldName($field);
|
||||
$value = idx($_POST["fields"], $name);
|
||||
if ($value != "") {
|
||||
if ($field["type"] == "set") {
|
||||
|
@@ -54,7 +54,7 @@ if ($tables_views && !$error && !$_POST["search"]) {
|
||||
|
||||
page_header(($_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema') . ": " . h($_GET["ns"])), $error, true);
|
||||
|
||||
if ($adminer->homepage()) {
|
||||
if (adminer()->homepage()) {
|
||||
if ($_GET["ns"] !== "") {
|
||||
echo "<h3 id='tables-views'>" . lang('Tables and views') . "</h3>\n";
|
||||
$tables_list = tables_list();
|
||||
@@ -146,7 +146,7 @@ if ($adminer->homepage()) {
|
||||
: "")))
|
||||
. "<input type='submit' name='truncate' value='" . lang('Truncate') . "'> " . on_help(JUSH == "sqlite" ? "'DELETE'" : "'TRUNCATE" . (JUSH == "pgsql" ? "'" : " TABLE'")) . confirm()
|
||||
. "<input type='submit' name='drop' value='" . lang('Drop') . "'>" . on_help("'DROP TABLE'") . confirm() . "\n";
|
||||
$databases = (support("scheme") ? $adminer->schemas() : $adminer->databases());
|
||||
$databases = (support("scheme") ? adminer()->schemas() : adminer()->databases());
|
||||
if (count($databases) != 1 && JUSH != "sqlite") {
|
||||
$db = (isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB));
|
||||
echo "<p>" . lang('Move to other database') . ": ";
|
||||
|
@@ -26,16 +26,15 @@ if (isset($_GET["mssql"])) {
|
||||
}
|
||||
|
||||
function attach(?string $server, string $username, string $password): string {
|
||||
global $adminer;
|
||||
$connection_info = array("UID" => $username, "PWD" => $password, "CharacterSet" => "UTF-8");
|
||||
$ssl = $adminer->connectSsl();
|
||||
$ssl = adminer()->connectSsl();
|
||||
if (isset($ssl["Encrypt"])) {
|
||||
$connection_info["Encrypt"] = $ssl["Encrypt"];
|
||||
}
|
||||
if (isset($ssl["TrustServerCertificate"])) {
|
||||
$connection_info["TrustServerCertificate"] = $ssl["TrustServerCertificate"];
|
||||
}
|
||||
$db = $adminer->database();
|
||||
$db = adminer()->database();
|
||||
if ($db != "") {
|
||||
$connection_info["Database"] = $db;
|
||||
}
|
||||
|
@@ -15,10 +15,9 @@ if (!defined('Adminer\DRIVER')) {
|
||||
}
|
||||
|
||||
function attach(?string $server, string $username, string $password): string {
|
||||
global $adminer;
|
||||
mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4
|
||||
list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket
|
||||
$ssl = $adminer->connectSsl();
|
||||
$ssl = adminer()->connectSsl();
|
||||
if ($ssl) {
|
||||
$this->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], '', '');
|
||||
}
|
||||
@@ -158,9 +157,8 @@ if (!defined('Adminer\DRIVER')) {
|
||||
public string $extension = "PDO_MySQL";
|
||||
|
||||
function attach(?string $server, string $username, string $password): string {
|
||||
global $adminer;
|
||||
$options = array(\PDO::MYSQL_ATTR_LOCAL_INFILE => false);
|
||||
$ssl = $adminer->connectSsl();
|
||||
$ssl = adminer()->connectSsl();
|
||||
if ($ssl) {
|
||||
if ($ssl['key']) {
|
||||
$options[\PDO::MYSQL_ATTR_SSL_KEY] = $ssl['key'];
|
||||
|
@@ -20,11 +20,10 @@ if (isset($_GET["pgsql"])) {
|
||||
}
|
||||
|
||||
function attach(?string $server, string $username, string $password): string {
|
||||
global $adminer;
|
||||
$db = $adminer->database();
|
||||
$db = adminer()->database();
|
||||
set_error_handler(array($this, '_error'));
|
||||
$this->string = "host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' user='" . addcslashes($username, "'\\") . "' password='" . addcslashes($password, "'\\") . "'";
|
||||
$ssl = $adminer->connectSsl();
|
||||
$ssl = adminer()->connectSsl();
|
||||
if (isset($ssl["mode"])) {
|
||||
$this->string .= " sslmode='" . $ssl["mode"] . "'";
|
||||
}
|
||||
@@ -53,8 +52,7 @@ if (isset($_GET["pgsql"])) {
|
||||
}
|
||||
|
||||
function select_db(string $database): bool {
|
||||
global $adminer;
|
||||
if ($database == $adminer->database()) {
|
||||
if ($database == adminer()->database()) {
|
||||
return $this->database;
|
||||
}
|
||||
$return = @pg_connect("$this->string dbname='" . addcslashes($database, "'\\") . "'", PGSQL_CONNECT_FORCE_NEW);
|
||||
@@ -130,11 +128,10 @@ if (isset($_GET["pgsql"])) {
|
||||
public int $timeout;
|
||||
|
||||
function attach(?string $server, string $username, string $password): string {
|
||||
global $adminer;
|
||||
$db = $adminer->database();
|
||||
$db = adminer()->database();
|
||||
//! client_encoding is supported since 9.1, but we can't yet use min_version here
|
||||
$dsn = "pgsql:host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' client_encoding=utf8 dbname='" . ($db != "" ? addcslashes($db, "'\\") : "postgres") . "'";
|
||||
$ssl = $adminer->connectSsl();
|
||||
$ssl = adminer()->connectSsl();
|
||||
if (isset($ssl["mode"])) {
|
||||
$dsn .= " sslmode='" . $ssl["mode"] . "'";
|
||||
}
|
||||
@@ -142,8 +139,7 @@ if (isset($_GET["pgsql"])) {
|
||||
}
|
||||
|
||||
function select_db(string $database): bool {
|
||||
global $adminer;
|
||||
return ($adminer->database() == $database);
|
||||
return (adminer()->database() == $database);
|
||||
}
|
||||
|
||||
function query(string $query, bool $unbuffered = false) {
|
||||
|
@@ -39,7 +39,7 @@ SET foreign_key_checks = 0;
|
||||
}
|
||||
|
||||
foreach ((array) $databases as $db) {
|
||||
$adminer->dumpDatabase($db);
|
||||
adminer()->dumpDatabase($db);
|
||||
if ($connection->select_db($db)) {
|
||||
if ($is_sql && preg_match('~CREATE~', $style) && ($create = get_val("SHOW CREATE DATABASE " . idf_escape($db), 1))) {
|
||||
set_utf8mb4($create);
|
||||
@@ -99,12 +99,12 @@ SET foreign_key_checks = 0;
|
||||
ob_start(array($tmp_file, 'write'), 1e5);
|
||||
}
|
||||
|
||||
$adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0));
|
||||
adminer()->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0));
|
||||
if (is_view($table_status)) {
|
||||
$views[] = $name;
|
||||
} elseif ($data) {
|
||||
$fields = fields($name);
|
||||
$adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name));
|
||||
adminer()->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name));
|
||||
}
|
||||
if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name))) {
|
||||
echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n";
|
||||
@@ -130,7 +130,7 @@ SET foreign_key_checks = 0;
|
||||
}
|
||||
|
||||
foreach ($views as $view) {
|
||||
$adminer->dumpTable($view, $_POST["table_style"], 1);
|
||||
adminer()->dumpTable($view, $_POST["table_style"], 1);
|
||||
}
|
||||
|
||||
if ($ext == "tar") {
|
||||
@@ -140,7 +140,7 @@ SET foreign_key_checks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$adminer->dumpFooter();
|
||||
adminer()->dumpFooter();
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -165,9 +165,9 @@ if (!isset($row["events"])) { // backwards compatibility
|
||||
$row["triggers"] = $row["table_style"];
|
||||
}
|
||||
|
||||
echo "<tr><th>" . lang('Output') . "<td>" . html_radios("output", $adminer->dumpOutput(), $row["output"]) . "\n";
|
||||
echo "<tr><th>" . lang('Output') . "<td>" . html_radios("output", adminer()->dumpOutput(), $row["output"]) . "\n";
|
||||
|
||||
echo "<tr><th>" . lang('Format') . "<td>" . html_radios("format", $adminer->dumpFormat(), $row["format"]) . "\n";
|
||||
echo "<tr><th>" . lang('Format') . "<td>" . html_radios("format", adminer()->dumpFormat(), $row["format"]) . "\n";
|
||||
|
||||
echo (JUSH == "sqlite" ? "" : "<tr><th>" . lang('Database') . "<td>" . html_select('db_style', $db_style, $row["db_style"])
|
||||
. (support("type") ? checkbox("types", 1, $row["types"], lang('User types')) : "")
|
||||
@@ -221,7 +221,7 @@ if (DB != "") {
|
||||
echo "<label class='block'><input type='checkbox' id='check-databases'" . ($TABLE == "" ? " checked" : "") . ">" . lang('Database') . "</label>";
|
||||
echo script("qs('#check-databases').onclick = partial(formCheck, /^databases\\[/);", "");
|
||||
echo "</thead>\n";
|
||||
$databases = $adminer->databases();
|
||||
$databases = adminer()->databases();
|
||||
if ($databases) {
|
||||
foreach ($databases as $db) {
|
||||
if (!information_schema($db)) {
|
||||
|
@@ -6,7 +6,7 @@ $fields = fields($TABLE);
|
||||
$where = (isset($_GET["select"]) ? ($_POST["check"] && count($_POST["check"]) == 1 ? where_check($_POST["check"][0], $fields) : "") : where($_GET, $fields));
|
||||
$update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
|
||||
foreach ($fields as $name => $field) {
|
||||
if (!isset($field["privileges"][$update ? "update" : "insert"]) || $adminer->fieldName($field) == "" || $field["generated"]) {
|
||||
if (!isset($field["privileges"][$update ? "update" : "insert"]) || adminer()->fieldName($field) == "" || $field["generated"]) {
|
||||
unset($fields[$name]);
|
||||
}
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ $target = array_keys(fields(in_array($row["table"], $referencable) ? $row["table
|
||||
$onchange = "this.form['change-js'].value = '1'; this.form.submit();";
|
||||
echo "<p>" . lang('Target table') . ": " . html_select("table", $referencable, $row["table"], $onchange) . "\n";
|
||||
if (support("scheme")) {
|
||||
$schemas = array_filter($adminer->schemas(), function ($schema) {
|
||||
$schemas = array_filter(adminer()->schemas(), function ($schema) {
|
||||
return !preg_match('~^information_schema$~i', $schema);
|
||||
});
|
||||
echo lang('Schema') . ": " . html_select("ns", $schemas, $row["ns"] != "" ? $row["ns"] : $_GET["ns"], $onchange);
|
||||
@@ -78,7 +78,7 @@ if (support("scheme")) {
|
||||
}
|
||||
} elseif (JUSH != "sqlite") {
|
||||
$dbs = array();
|
||||
foreach ($adminer->databases() as $db) {
|
||||
foreach (adminer()->databases() as $db) {
|
||||
if (!information_schema($db)) {
|
||||
$dbs[] = $db;
|
||||
}
|
||||
|
@@ -3,8 +3,9 @@ namespace Adminer;
|
||||
|
||||
// any method change in this file should be transferred to editor/include/adminer.inc.php
|
||||
|
||||
/** Default Adminer plugin; it should call methods via $adminer->f() instead of $this->f() to give chance to other plugins */
|
||||
/** Default Adminer plugin; it should call methods via adminer()->f() instead of $this->f() to give chance to other plugins */
|
||||
class Adminer {
|
||||
/** @var Adminer|Plugins */ static $instance;
|
||||
/** @visibility protected(set) */ public string $error = ''; // HTML
|
||||
|
||||
/** Name in title and navigation
|
||||
@@ -119,15 +120,14 @@ class Adminer {
|
||||
|
||||
/** Print login form */
|
||||
function loginForm(): void {
|
||||
global $adminer;
|
||||
echo "<table class='layout'>\n";
|
||||
// this is matched by compile.php
|
||||
echo $adminer->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);"));
|
||||
echo $adminer->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">');
|
||||
echo adminer()->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);"));
|
||||
echo adminer()->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">');
|
||||
// this is matched by compile.php
|
||||
echo $adminer->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">' . script("qs('#username').form['auth[driver]'].onchange();"));
|
||||
echo $adminer->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
|
||||
echo $adminer->loginFormField('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">');
|
||||
echo adminer()->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">' . script("qs('#username').form['auth[driver]'].onchange();"));
|
||||
echo adminer()->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
|
||||
echo adminer()->loginFormField('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">');
|
||||
echo "</table>\n";
|
||||
echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
|
||||
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
|
||||
@@ -384,7 +384,6 @@ 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") {
|
||||
@@ -397,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"], $adminer->operators()))) {
|
||||
if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], adminer()->operators()))) {
|
||||
echo "<div>" . select_input(
|
||||
" name='where[$i][col]'",
|
||||
$columns,
|
||||
@@ -405,7 +404,7 @@ class Adminer {
|
||||
($val ? "selectFieldChange" : "selectAddRow"),
|
||||
"(" . lang('anywhere') . ")"
|
||||
);
|
||||
echo html_select("where[$i][op]", $adminer->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";
|
||||
@@ -528,7 +527,7 @@ class Adminer {
|
||||
* @return list<string> expressions to join by AND
|
||||
*/
|
||||
function selectSearchProcess(array $fields, array $indexes): array {
|
||||
global $connection, $driver, $adminer;
|
||||
global $connection, $driver;
|
||||
$return = array();
|
||||
foreach ($indexes as $i => $index) {
|
||||
if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
|
||||
@@ -536,7 +535,7 @@ class Adminer {
|
||||
}
|
||||
}
|
||||
foreach ((array) $_GET["where"] as $key => $val) {
|
||||
if ("$val[col]$val[val]" != "" && in_array($val["op"], $adminer->operators())) {
|
||||
if ("$val[col]$val[val]" != "" && in_array($val["op"], adminer()->operators())) {
|
||||
$prefix = "";
|
||||
$cond = " $val[op]";
|
||||
if (preg_match('~IN$~', $val["op"])) {
|
||||
@@ -545,14 +544,14 @@ class Adminer {
|
||||
} elseif ($val["op"] == "SQL") {
|
||||
$cond = " $val[val]"; // SQL injection
|
||||
} elseif ($val["op"] == "LIKE %%") {
|
||||
$cond = " LIKE " . $adminer->processInput($fields[$val["col"]], "%$val[val]%");
|
||||
$cond = " LIKE " . adminer()->processInput($fields[$val["col"]], "%$val[val]%");
|
||||
} elseif ($val["op"] == "ILIKE %%") {
|
||||
$cond = " ILIKE " . $adminer->processInput($fields[$val["col"]], "%$val[val]%");
|
||||
$cond = " ILIKE " . adminer()->processInput($fields[$val["col"]], "%$val[val]%");
|
||||
} elseif ($val["op"] == "FIND_IN_SET") {
|
||||
$prefix = "$val[op](" . q($val["val"]) . ", ";
|
||||
$cond = ")";
|
||||
} elseif (!preg_match('~NULL$~', $val["op"])) {
|
||||
$cond .= " " . $adminer->processInput($fields[$val["col"]], $val["val"]);
|
||||
$cond .= " " . adminer()->processInput($fields[$val["col"]], $val["val"]);
|
||||
}
|
||||
if ($val["col"] != "") {
|
||||
$return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $val, $fields[$val["col"]]) . $cond;
|
||||
@@ -947,8 +946,8 @@ class Adminer {
|
||||
* @param string $missing can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
|
||||
*/
|
||||
function navigation(string $missing): void {
|
||||
global $connection, $adminer;
|
||||
echo "<h1>" . $adminer->name() . " <span class='version'>" . VERSION;
|
||||
global $connection;
|
||||
echo "<h1>" . adminer()->name() . " <span class='version'>" . VERSION;
|
||||
$new_version = $_COOKIE["adminer_version"];
|
||||
echo " <a href='https://www.adminer.org/#download'" . target_blank() . " id='version'>" . (version_compare(VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>";
|
||||
echo "</span></h1>\n";
|
||||
@@ -963,7 +962,7 @@ class Adminer {
|
||||
if ($password !== null) {
|
||||
$dbs = $_SESSION["db"][$vendor][$server][$username];
|
||||
foreach (($dbs ? array_keys($dbs) : array("")) as $db) {
|
||||
$output .= "<li><a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>($name) " . h($username . ($server != "" ? "@" . $adminer->serverName($server) : "") . ($db != "" ? " - $db" : "")) . "</a>\n";
|
||||
$output .= "<li><a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>($name) " . h($username . ($server != "" ? "@" . adminer()->serverName($server) : "") . ($db != "" ? " - $db" : "")) . "</a>\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -978,8 +977,8 @@ class Adminer {
|
||||
$connection->select_db(DB);
|
||||
$tables = table_status('', true);
|
||||
}
|
||||
$adminer->syntaxHighlighting($tables);
|
||||
$adminer->databasesPrint($missing);
|
||||
adminer()->syntaxHighlighting($tables);
|
||||
adminer()->databasesPrint($missing);
|
||||
$actions = array();
|
||||
if (DB == "" || !$missing) {
|
||||
if (support("sql")) {
|
||||
@@ -995,7 +994,7 @@ class Adminer {
|
||||
echo ($actions ? "<p class='links'>\n" . implode("\n", $actions) . "\n" : "");
|
||||
if ($in_db) {
|
||||
if ($tables) {
|
||||
$adminer->tablesPrint($tables);
|
||||
adminer()->tablesPrint($tables);
|
||||
} else {
|
||||
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
|
||||
}
|
||||
@@ -1035,8 +1034,8 @@ class Adminer {
|
||||
|
||||
/** Print databases list in menu */
|
||||
function databasesPrint(string $missing): void {
|
||||
global $adminer, $connection;
|
||||
$databases = $adminer->databases();
|
||||
global $connection;
|
||||
$databases = adminer()->databases();
|
||||
if (DB && $databases && !in_array(DB, $databases)) {
|
||||
array_unshift($databases, DB);
|
||||
}
|
||||
@@ -1050,7 +1049,7 @@ class Adminer {
|
||||
echo "<input type='submit' value='" . lang('Use') . "'" . ($databases ? " class='hidden'" : "") . ">\n";
|
||||
if (support("scheme")) {
|
||||
if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
|
||||
echo "<br><span>" . lang('Schema') . ":</span> " . html_select("ns", array("" => "") + $adminer->schemas(), $_GET["ns"]) . $db_events;
|
||||
echo "<br><span>" . lang('Schema') . ":</span> " . html_select("ns", array("" => "") + adminer()->schemas(), $_GET["ns"]) . $db_events;
|
||||
if ($_GET["ns"] != "") {
|
||||
set_schema($_GET["ns"]);
|
||||
}
|
||||
@@ -1069,10 +1068,9 @@ class Adminer {
|
||||
* @param TableStatus[] $tables
|
||||
*/
|
||||
function tablesPrint(array $tables): void {
|
||||
global $adminer;
|
||||
echo "<ul id='tables'>" . script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
|
||||
foreach ($tables as $table => $status) {
|
||||
$name = $adminer->tableName($status);
|
||||
$name = adminer()->tableName($status);
|
||||
if ($name != "") {
|
||||
echo '<li><a href="' . h(ME) . 'select=' . urlencode($table) . '"'
|
||||
. bold($_GET["select"] == $table || $_GET["edit"] == $table, "select")
|
||||
|
@@ -12,7 +12,6 @@ if ($_COOKIE["adminer_permanent"]) {
|
||||
}
|
||||
|
||||
function add_invalid_login(): void {
|
||||
global $adminer;
|
||||
$base = get_temp_dir() . "/adminer.invalid";
|
||||
// adminer.invalid may not be writable by us, try the files with random suffixes
|
||||
foreach (glob("$base*") ?: array($base) as $filename) {
|
||||
@@ -36,7 +35,7 @@ function add_invalid_login(): void {
|
||||
}
|
||||
}
|
||||
}
|
||||
$invalid = &$invalids[$adminer->bruteForceKey()];
|
||||
$invalid = &$invalids[adminer()->bruteForceKey()];
|
||||
if (!$invalid) {
|
||||
$invalid = array($time + 30*60, 0); // active for 30 minutes
|
||||
}
|
||||
@@ -46,7 +45,6 @@ function add_invalid_login(): void {
|
||||
|
||||
/** @param string[] $permanent */
|
||||
function check_invalid_login(array &$permanent): void {
|
||||
global $adminer;
|
||||
$invalids = array();
|
||||
foreach (glob(get_temp_dir() . "/adminer.invalid*") as $filename) {
|
||||
$fp = file_open_lock($filename);
|
||||
@@ -57,7 +55,7 @@ function check_invalid_login(array &$permanent): void {
|
||||
}
|
||||
}
|
||||
/** @var array{int, int} */
|
||||
$invalid = idx($invalids, $adminer->bruteForceKey(), array());
|
||||
$invalid = idx($invalids, adminer()->bruteForceKey(), array());
|
||||
$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)), $permanent);
|
||||
@@ -76,7 +74,7 @@ if ($auth) {
|
||||
$_SESSION["db"][$vendor][$server][$username][$db] = true;
|
||||
if ($auth["permanent"]) {
|
||||
$key = implode("-", array_map('base64_encode', array($vendor, $server, $username, $db)));
|
||||
$private = $adminer->permanentLogin(true);
|
||||
$private = adminer()->permanentLogin(true);
|
||||
$permanent[$key] = "$key:" . base64_encode($private ? encrypt_string($password, $private) : "");
|
||||
cookie("adminer_permanent", implode(" ", $permanent));
|
||||
}
|
||||
@@ -99,7 +97,7 @@ if ($auth) {
|
||||
|
||||
} elseif ($permanent && !$_SESSION["pwds"]) {
|
||||
session_regenerate_id();
|
||||
$private = $adminer->permanentLogin();
|
||||
$private = adminer()->permanentLogin();
|
||||
foreach ($permanent as $key => $val) {
|
||||
list(, $cipher) = explode(":", $val);
|
||||
list($vendor, $server, $username, $db) = array_map('base64_decode', explode("-", $key));
|
||||
@@ -127,7 +125,6 @@ function unset_permanent(array &$permanent): void {
|
||||
* @return never
|
||||
*/
|
||||
function auth_error(string $error, array &$permanent) {
|
||||
global $adminer;
|
||||
$session_name = session_name();
|
||||
if (isset($_GET["username"])) {
|
||||
header("HTTP/1.1 403 Forbidden"); // 401 requires sending WWW-Authenticate header
|
||||
@@ -158,7 +155,7 @@ function auth_error(string $error, array &$permanent) {
|
||||
echo "<p class='message'>" . lang('The action will be performed after successful login with the same credentials.') . "\n";
|
||||
}
|
||||
echo "</div>\n";
|
||||
$adminer->loginForm();
|
||||
adminer()->loginForm();
|
||||
echo "</form>\n";
|
||||
page_footer("auth");
|
||||
exit;
|
||||
@@ -178,7 +175,7 @@ if (isset($_GET["username"]) && is_string(get_password())) {
|
||||
auth_error(lang('Connecting to privileged ports is not allowed.'), $permanent);
|
||||
}
|
||||
check_invalid_login($permanent);
|
||||
$connection = connect($adminer->credentials());
|
||||
$connection = connect(adminer()->credentials());
|
||||
if (is_object($connection)) {
|
||||
$driver = new Driver($connection);
|
||||
if ($connection->flavor) {
|
||||
@@ -188,7 +185,7 @@ if (isset($_GET["username"]) && is_string(get_password())) {
|
||||
}
|
||||
|
||||
$login = null;
|
||||
if (!is_object($connection) || ($login = $adminer->login($_GET["username"], get_password())) !== true) {
|
||||
if (!is_object($connection) || ($login = adminer()->login($_GET["username"], get_password())) !== true) {
|
||||
$error = (is_string($connection) ? nl_br(h($connection)) : (is_string($login) ? $login : lang('Invalid credentials.')));
|
||||
auth_error(
|
||||
$error . (preg_match('~^ | $~', get_password()) ? '<br>' . lang('There is a space in the input password which might be the cause.') : ''),
|
||||
|
@@ -39,7 +39,7 @@ if ($_GET["script"] == "version") {
|
||||
exit;
|
||||
}
|
||||
|
||||
global $adminer, $connection, $driver, $translations; // allows including Adminer inside a function
|
||||
global $connection, $driver, $translations; // allows including Adminer inside a function
|
||||
|
||||
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
|
||||
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
|
||||
@@ -81,11 +81,11 @@ include "./include/adminer.inc.php";
|
||||
include "../adminer/include/plugins.inc.php";
|
||||
|
||||
if (function_exists('adminer_object')) {
|
||||
$adminer = adminer_object();
|
||||
Adminer::$instance = adminer_object();
|
||||
} elseif (is_dir("adminer-plugins") || file_exists("adminer-plugins.php")) {
|
||||
$adminer = new Plugins(null);
|
||||
Adminer::$instance = new Plugins(null);
|
||||
} else {
|
||||
$adminer = new Adminer;
|
||||
Adminer::$instance = new Adminer;
|
||||
}
|
||||
|
||||
// this is matched by compile.php
|
||||
|
@@ -44,15 +44,15 @@ if (
|
||||
}
|
||||
echo "<p>" . lang('%s version: %s through PHP extension %s', get_driver(DRIVER), "<b>" . h($connection->server_info) . "</b>", "<b>$connection->extension</b>") . "\n";
|
||||
echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
|
||||
if (isset($adminer->plugins) && is_array($adminer->plugins)) {
|
||||
if (isset(adminer()->plugins) && is_array(adminer()->plugins)) {
|
||||
echo "<p>" . lang('Loaded plugins') . ":\n<ul>\n";
|
||||
foreach ($adminer->plugins as $plugin) {
|
||||
foreach (adminer()->plugins as $plugin) {
|
||||
$reflection = new \ReflectionObject($plugin);
|
||||
echo "<li><b>" . get_class($plugin) . "</b>" . h(preg_match('~^/[\s*]+(.+)~', $reflection->getDocComment(), $match) ? ": $match[1]" : "") . "\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
}
|
||||
$databases = $adminer->databases();
|
||||
$databases = adminer()->databases();
|
||||
if ($databases) {
|
||||
$scheme = support("scheme");
|
||||
$collations = collations();
|
||||
|
@@ -7,7 +7,6 @@ namespace Adminer;
|
||||
* @param string $title2 used after colon in title and heading, should be HTML escaped
|
||||
*/
|
||||
function page_header(string $title, string $error = "", $breadcrumb = array(), string $title2 = ""): void {
|
||||
global $adminer;
|
||||
page_headers();
|
||||
if (is_ajax() && $error) {
|
||||
page_messages($error);
|
||||
@@ -17,7 +16,7 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s
|
||||
ob_start(null, 4096);
|
||||
}
|
||||
$title_all = $title . ($title2 != "" ? ": $title2" : "");
|
||||
$title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name());
|
||||
$title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . adminer()->name());
|
||||
// initial-scale=1 is the default but Chrome 134 on iOS is not able to zoom out without it
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
@@ -28,7 +27,7 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s
|
||||
<title><?php echo $title_page; ?></title>
|
||||
<link rel="stylesheet" href="../adminer/static/default.css">
|
||||
<?php
|
||||
$css = $adminer->css();
|
||||
$css = adminer()->css();
|
||||
$has_light = false;
|
||||
$has_dark = false;
|
||||
foreach ($css as $filename) {
|
||||
@@ -51,7 +50,7 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s
|
||||
// this is matched by compile.php
|
||||
echo script_src("../adminer/static/functions.js");
|
||||
echo script_src("static/editing.js");
|
||||
if ($adminer->head($dark)) {
|
||||
if (adminer()->head($dark)) {
|
||||
echo "<link rel='shortcut icon' type='image/x-icon' href='../adminer/static/favicon.ico'>\n";
|
||||
echo "<link rel='apple-touch-icon' href='../adminer/static/favicon.ico'>\n";
|
||||
}
|
||||
@@ -91,7 +90,7 @@ const thousandsSeparator = '" . js_escape(lang(',')) . "';")
|
||||
$link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1);
|
||||
echo '<p id="breadcrumb"><a href="' . h($link ?: ".") . '">' . get_driver(DRIVER) . '</a> » ';
|
||||
$link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', ME), 0, -1);
|
||||
$server = $adminer->serverName(SERVER);
|
||||
$server = adminer()->serverName(SERVER);
|
||||
$server = ($server != "" ? $server : lang('Server'));
|
||||
if ($breadcrumb === false) {
|
||||
echo "$server\n";
|
||||
@@ -128,21 +127,20 @@ const thousandsSeparator = '" . js_escape(lang(',')) . "';")
|
||||
|
||||
/** Send HTTP headers */
|
||||
function page_headers(): void {
|
||||
global $adminer;
|
||||
header("Content-Type: text/html; charset=utf-8");
|
||||
header("Cache-Control: no-cache");
|
||||
header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox 3.6.9
|
||||
header("X-XSS-Protection: 0"); // prevents introducing XSS in IE8 by removing safe parts of the page
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("Referrer-Policy: origin-when-cross-origin");
|
||||
foreach ($adminer->csp() as $csp) {
|
||||
foreach (adminer()->csp() as $csp) {
|
||||
$header = array();
|
||||
foreach ($csp as $key => $val) {
|
||||
$header[] = "$key $val";
|
||||
}
|
||||
header("Content-Security-Policy: " . implode("; ", $header));
|
||||
}
|
||||
$adminer->headers();
|
||||
adminer()->headers();
|
||||
}
|
||||
|
||||
/** Get Content Security Policy headers
|
||||
@@ -174,7 +172,6 @@ function get_nonce(): string {
|
||||
|
||||
/** Print flash and error messages */
|
||||
function page_messages(string $error): void {
|
||||
global $adminer;
|
||||
$uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
|
||||
$messages = idx($_SESSION["messages"], $uri);
|
||||
if ($messages) {
|
||||
@@ -184,8 +181,8 @@ function page_messages(string $error): void {
|
||||
if ($error) {
|
||||
echo "<div class='error'>$error</div>\n";
|
||||
}
|
||||
if ($adminer->error) { // separate <div>
|
||||
echo "<div class='error'>$adminer->error</div>\n";
|
||||
if (adminer()->error) { // separate <div>
|
||||
echo "<div class='error'>" . adminer()->error . "</div>\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,9 +190,8 @@ function page_messages(string $error): void {
|
||||
* @param ''|'auth'|'db'|'ns' $missing
|
||||
*/
|
||||
function page_footer(string $missing = ""): void {
|
||||
global $adminer;
|
||||
echo "</div>\n\n<div id='foot' class='foot'>\n<div id='menu'>\n";
|
||||
$adminer->navigation($missing);
|
||||
adminer()->navigation($missing);
|
||||
echo "</div>\n";
|
||||
if ($missing != "auth") {
|
||||
?>
|
||||
|
@@ -63,19 +63,18 @@ abstract class SqlDriver {
|
||||
}
|
||||
|
||||
/** Select data from table
|
||||
* @param list<string> $select result of $adminer->selectColumnsProcess()[0]
|
||||
* @param list<string> $where result of $adminer->selectSearchProcess()
|
||||
* @param list<string> $group result of $adminer->selectColumnsProcess()[1]
|
||||
* @param list<string> $order result of $adminer->selectOrderProcess()
|
||||
* @param int|numeric-string $limit result of $adminer->selectLimitProcess()
|
||||
* @param list<string> $select result of adminer()->selectColumnsProcess()[0]
|
||||
* @param list<string> $where result of adminer()->selectSearchProcess()
|
||||
* @param list<string> $group result of adminer()->selectColumnsProcess()[1]
|
||||
* @param list<string> $order result of adminer()->selectOrderProcess()
|
||||
* @param int|numeric-string $limit result of adminer()->selectLimitProcess()
|
||||
* @param int $page index of page starting at zero
|
||||
* @param bool $print whether to print the query
|
||||
* @return Result|false
|
||||
*/
|
||||
function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) {
|
||||
global $adminer;
|
||||
$is_group = (count($group) < count($select));
|
||||
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
|
||||
$query = adminer()->selectQueryBuild($select, $where, $group, $order, $limit, $page);
|
||||
if (!$query) {
|
||||
$query = "SELECT" . limit(
|
||||
($_GET["page"] != "last" && $limit != "" && $group && $is_group && JUSH == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
|
||||
@@ -88,7 +87,7 @@ abstract class SqlDriver {
|
||||
$start = microtime(true);
|
||||
$return = $this->conn->query($query);
|
||||
if ($print) {
|
||||
echo $adminer->selectQuery($query, $start, !$return);
|
||||
echo adminer()->selectQuery($query, $start, !$return);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
@@ -14,8 +14,7 @@ function connection(): Db {
|
||||
* @return Adminer|Plugins
|
||||
*/
|
||||
function adminer() {
|
||||
global $adminer;
|
||||
return $adminer;
|
||||
return Adminer::$instance;
|
||||
}
|
||||
|
||||
/** Get Driver object */
|
||||
@@ -432,15 +431,15 @@ function redirect(?string $location, string $message = null): void {
|
||||
* @param bool $redirect
|
||||
*/
|
||||
function query_redirect(string $query, ?string $location, string $message, $redirect = true, bool $execute = true, bool $failed = false, string $time = ""): bool {
|
||||
global $connection, $adminer;
|
||||
global $connection;
|
||||
if ($execute) {
|
||||
$start = microtime(true);
|
||||
$failed = !$connection->query($query);
|
||||
$time = format_time($start);
|
||||
}
|
||||
$sql = ($query ? $adminer->messageQuery($query, $time, $failed) : "");
|
||||
$sql = ($query ? adminer()->messageQuery($query, $time, $failed) : "");
|
||||
if ($failed) {
|
||||
$adminer->error .= error() . $sql . script("messagesPrint();") . "<br>";
|
||||
adminer()->error .= error() . $sql . script("messagesPrint();") . "<br>";
|
||||
return false;
|
||||
}
|
||||
if ($redirect) {
|
||||
@@ -589,9 +588,8 @@ function table_status1(string $table, bool $fast = false): array {
|
||||
* @return list<ForeignKey>[] [$col => []]
|
||||
*/
|
||||
function column_foreign_keys(string $table): array {
|
||||
global $adminer;
|
||||
$return = array();
|
||||
foreach ($adminer->foreignKeys($table) as $foreign_key) {
|
||||
foreach (adminer()->foreignKeys($table) as $foreign_key) {
|
||||
foreach ($foreign_key["source"] as $val) {
|
||||
$return[$val][] = $foreign_key;
|
||||
}
|
||||
@@ -628,11 +626,10 @@ function fields_from_edit(): array { // used by Mongo and SimpleDB
|
||||
* @return string extension
|
||||
*/
|
||||
function dump_headers(string $identifier, bool $multi_table = false): string {
|
||||
global $adminer;
|
||||
$return = $adminer->dumpHeaders($identifier, $multi_table);
|
||||
$return = adminer()->dumpHeaders($identifier, $multi_table);
|
||||
$output = $_POST["output"];
|
||||
if ($output != "text") {
|
||||
header("Content-Disposition: attachment; filename=" . $adminer->dumpFilename($identifier) . ".$return" . ($output != "file" && preg_match('~^[0-9a-z]+$~', $output) ? ".$output" : ""));
|
||||
header("Content-Disposition: attachment; filename=" . adminer()->dumpFilename($identifier) . ".$return" . ($output != "file" && preg_match('~^[0-9a-z]+$~', $output) ? ".$output" : ""));
|
||||
}
|
||||
session_write_close();
|
||||
if (!ob_get_level()) {
|
||||
@@ -762,7 +759,6 @@ function rand_string(): string {
|
||||
* @return string HTML
|
||||
*/
|
||||
function select_value($val, string $link, array $field, ?string $text_length): string {
|
||||
global $adminer;
|
||||
if (is_array($val)) {
|
||||
$return = "";
|
||||
foreach ($val as $k => $v) {
|
||||
@@ -774,7 +770,7 @@ function select_value($val, string $link, array $field, ?string $text_length): s
|
||||
return "<table>$return</table>";
|
||||
}
|
||||
if (!$link) {
|
||||
$link = $adminer->selectLink($val, $field);
|
||||
$link = adminer()->selectLink($val, $field);
|
||||
}
|
||||
if ($link === null) {
|
||||
if (is_mail($val)) {
|
||||
@@ -784,7 +780,7 @@ function select_value($val, string $link, array $field, ?string $text_length): s
|
||||
$link = $val; // IE 11 and all modern browsers hide referrer
|
||||
}
|
||||
}
|
||||
$return = $adminer->editVal($val, $field);
|
||||
$return = adminer()->editVal($val, $field);
|
||||
if ($return !== null) {
|
||||
if (!is_utf8($return)) {
|
||||
$return = "\0"; // htmlspecialchars of binary data returns an empty string
|
||||
@@ -794,7 +790,7 @@ function select_value($val, string $link, array $field, ?string $text_length): s
|
||||
$return = h($return);
|
||||
}
|
||||
}
|
||||
return $adminer->selectVal($return, $link, $field, $val);
|
||||
return adminer()->selectVal($return, $link, $field, $val);
|
||||
}
|
||||
|
||||
/** Check whether the string is e-mail address */
|
||||
@@ -834,13 +830,13 @@ function count_rows(string $table, array $where, bool $is_group, array $group):
|
||||
* @return string[]
|
||||
*/
|
||||
function slow_query(string $query): array {
|
||||
global $adminer, $driver;
|
||||
$db = $adminer->database();
|
||||
$timeout = $adminer->queryTimeout();
|
||||
global $driver;
|
||||
$db = adminer()->database();
|
||||
$timeout = adminer()->queryTimeout();
|
||||
$slow_query = $driver->slowQuery($query, $timeout);
|
||||
$connection2 = null;
|
||||
if (!$slow_query && support("kill")) {
|
||||
$connection2 = connect($adminer->credentials());
|
||||
$connection2 = connect(adminer()->credentials());
|
||||
if (is_object($connection2) && ($db == "" || $connection2->select_db($db))) {
|
||||
$kill = get_val(connection_id(), 0, $connection2); // MySQL and MySQLi can use thread_id but it's not in PDO_MySQL
|
||||
echo script("const timeout = setTimeout(() => { ajax('" . js_escape(ME) . "script=kill', function () {}, 'kill=$kill&token=" . get_token() . "'); }, 1000 * $timeout);");
|
||||
|
@@ -174,13 +174,12 @@ function hidden_fields_get(): void {
|
||||
* @param mixed $value string|array
|
||||
*/
|
||||
function enum_input(string $type, string $attrs, array $field, $value, string $empty = null): string {
|
||||
global $adminer;
|
||||
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
||||
$return = ($empty !== null ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === $empty) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
|
||||
foreach ($matches[1] as $i => $val) {
|
||||
$val = stripcslashes(str_replace("''", "'", $val));
|
||||
$checked = (is_array($value) ? in_array($val, $value) : $value === $val);
|
||||
$return .= " <label><input type='$type'$attrs value='" . h($val) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
|
||||
$return .= " <label><input type='$type'$attrs value='" . h($val) . "'" . ($checked ? ' checked' : '') . '>' . h(adminer()->editVal($val, $field)) . '</label>';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
@@ -190,7 +189,7 @@ function enum_input(string $type, string $attrs, array $field, $value, string $e
|
||||
* @param mixed $value
|
||||
*/
|
||||
function input(array $field, $value, ?string $function, ?bool $autofocus = false): void {
|
||||
global $driver, $adminer;
|
||||
global $driver;
|
||||
$name = h(bracket_escape($field["field"]));
|
||||
echo "<td class='function'>";
|
||||
if (is_array($value) && !$function) {
|
||||
@@ -201,7 +200,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false
|
||||
if ($reset && !$_POST["save"]) {
|
||||
$function = null;
|
||||
}
|
||||
$functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
|
||||
$functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + adminer()->editFunctions($field);
|
||||
$disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled=''" : "";
|
||||
$attrs = " name='fields[$name]'$disabled" . ($autofocus ? " autofocus" : "");
|
||||
$enums = $driver->enumLength($field);
|
||||
@@ -212,7 +211,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false
|
||||
echo $driver->unconvertFunction($field) . " ";
|
||||
$table = $_GET["edit"] ?: $_GET["select"];
|
||||
if ($field["type"] == "enum") {
|
||||
echo h($functions[""]) . "<td>" . $adminer->editInput($table, $field, $attrs, $value);
|
||||
echo h($functions[""]) . "<td>" . adminer()->editInput($table, $field, $attrs, $value);
|
||||
} else {
|
||||
$has_function = (in_array($function, $functions) || isset($functions[$function]));
|
||||
echo (count($functions) > 1
|
||||
@@ -221,7 +220,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false
|
||||
. script("qsl('select').onchange = functionChange;", "")
|
||||
: h(reset($functions))
|
||||
) . '<td>';
|
||||
$input = $adminer->editInput($table, $field, $attrs, $value); // usage in call is without a table
|
||||
$input = adminer()->editInput($table, $field, $attrs, $value); // usage in call is without a table
|
||||
if ($input != "") {
|
||||
echo $input;
|
||||
} elseif (preg_match('~bool~', $field["type"])) {
|
||||
@@ -232,7 +231,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false
|
||||
foreach ($matches[1] as $i => $val) {
|
||||
$val = stripcslashes(str_replace("''", "'", $val));
|
||||
$checked = in_array($val, explode(",", $value), true);
|
||||
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . h($val) . "'" . ($checked ? ' checked' : '') . ">" . h($adminer->editVal($val, $field)) . '</label>';
|
||||
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . h($val) . "'" . ($checked ? ' checked' : '') . ">" . h(adminer()->editVal($val, $field)) . '</label>';
|
||||
}
|
||||
} elseif (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
|
||||
echo "<input type='file' name='fields-$name'>";
|
||||
@@ -264,7 +263,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false
|
||||
. "$attrs>"
|
||||
;
|
||||
}
|
||||
echo $adminer->editHint($table, $field, $value);
|
||||
echo adminer()->editHint($table, $field, $value);
|
||||
// skip 'original'
|
||||
$first = 0;
|
||||
foreach ($functions as $key => $val) {
|
||||
@@ -284,7 +283,7 @@ function input(array $field, $value, ?string $function, ?bool $autofocus = false
|
||||
* @return mixed false to leave the original value
|
||||
*/
|
||||
function process_input(array $field) {
|
||||
global $adminer, $driver;
|
||||
global $driver;
|
||||
if (stripos($field["default"], "GENERATED ALWAYS AS ") === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -326,7 +325,7 @@ function process_input(array $field) {
|
||||
}
|
||||
return $driver->quoteBinary($file);
|
||||
}
|
||||
return $adminer->processInput($field, $value, $function);
|
||||
return adminer()->processInput($field, $value, $function);
|
||||
}
|
||||
|
||||
/** Print results of search in all tables
|
||||
@@ -334,13 +333,13 @@ function process_input(array $field) {
|
||||
* @uses $_POST["tables"]
|
||||
*/
|
||||
function search_tables(): void {
|
||||
global $adminer, $connection;
|
||||
global $connection;
|
||||
$_GET["where"][0]["val"] = $_POST["query"];
|
||||
$sep = "<ul>\n";
|
||||
foreach (table_status('', true) as $table => $table_status) {
|
||||
$name = $adminer->tableName($table_status);
|
||||
$name = adminer()->tableName($table_status);
|
||||
if (isset($table_status["Engine"]) && $name != "" && (!$_POST["tables"] || in_array($table, $_POST["tables"]))) {
|
||||
$result = $connection->query("SELECT" . limit("1 FROM " . table($table), " WHERE " . implode(" AND ", $adminer->selectSearchProcess(fields($table), array())), 1));
|
||||
$result = $connection->query("SELECT" . limit("1 FROM " . table($table), " WHERE " . implode(" AND ", adminer()->selectSearchProcess(fields($table), array())), 1));
|
||||
if (!$result || $result->fetch_row()) {
|
||||
$print = "<a href='" . h(ME . "select=" . urlencode($table) . "&where[0][op]=" . urlencode($_GET["where"][0]["op"]) . "&where[0][val]=" . urlencode($_GET["where"][0]["val"])) . "'>$name</a>";
|
||||
echo "$sep<li>" . ($result ? $print : "<p class='error'>$print: " . error()) . "\n";
|
||||
@@ -364,15 +363,14 @@ function on_help(string $command, int $side = 0): string {
|
||||
* @param mixed $row
|
||||
*/
|
||||
function edit_form(string $table, array $fields, $row, ?bool $update, string $error = ''): void {
|
||||
global $adminer;
|
||||
$table_name = $adminer->tableName(table_status1($table, true));
|
||||
$table_name = adminer()->tableName(table_status1($table, true));
|
||||
page_header(
|
||||
($update ? lang('Edit') : lang('Insert')),
|
||||
$error,
|
||||
array("select" => array($table, $table_name)),
|
||||
$table_name
|
||||
);
|
||||
$adminer->editRowPrint($table, $fields, $row, $update);
|
||||
adminer()->editRowPrint($table, $fields, $row, $update);
|
||||
if ($row === false) {
|
||||
echo "<p class='error'>" . lang('No rows.') . "\n";
|
||||
return;
|
||||
@@ -384,7 +382,7 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er
|
||||
echo "<table class='layout'>" . script("qsl('table').onkeydown = editingKeydown;");
|
||||
$autofocus = !$_POST;
|
||||
foreach ($fields as $name => $field) {
|
||||
echo "<tr><th>" . $adminer->fieldName($field);
|
||||
echo "<tr><th>" . adminer()->fieldName($field);
|
||||
$default = idx($_GET["set"], bracket_escape($name));
|
||||
if ($default === null) {
|
||||
$default = $field["default"];
|
||||
@@ -406,7 +404,7 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er
|
||||
)
|
||||
);
|
||||
if (!$_POST["save"] && is_string($value)) {
|
||||
$value = $adminer->editVal($value, $field);
|
||||
$value = adminer()->editVal($value, $field);
|
||||
}
|
||||
$function = ($_POST["save"]
|
||||
? idx($_POST["function"], $name, "")
|
||||
@@ -439,7 +437,7 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er
|
||||
echo "<tr>"
|
||||
. "<th><input name='field_keys[]'>"
|
||||
. script("qsl('input').oninput = fieldChange;")
|
||||
. "<td class='function'>" . html_select("field_funs[]", $adminer->editFunctions(array("null" => isset($_GET["select"]))))
|
||||
. "<td class='function'>" . html_select("field_funs[]", adminer()->editFunctions(array("null" => isset($_GET["select"]))))
|
||||
. "<td><input name='field_vals[]'>"
|
||||
. "\n"
|
||||
;
|
||||
|
@@ -31,7 +31,7 @@ foreach (table_status('', true) as $table => $table_status) {
|
||||
$schema[$table]["fields"][$name] = $field;
|
||||
}
|
||||
$schema[$table]["pos"] = ($table_pos[$table] ?: array($top, 0));
|
||||
foreach ($adminer->foreignKeys($table) as $val) {
|
||||
foreach (adminer()->foreignKeys($table) as $val) {
|
||||
if (!$val["db"]) {
|
||||
$left = $base_left;
|
||||
if (idx($table_pos[$table], 1) || idx($table_pos[$val["table"]], 1)) {
|
||||
|
@@ -39,7 +39,7 @@ if ($_GET["script"] == "db") {
|
||||
$connection->query("KILL " . number($_POST["kill"]));
|
||||
|
||||
} else { // connect
|
||||
foreach (count_tables($adminer->databases()) as $db => $val) {
|
||||
foreach (count_tables(adminer()->databases()) as $db => $val) {
|
||||
json_row("tables-$db", $val);
|
||||
json_row("size-$db", db_size($db));
|
||||
}
|
||||
|
@@ -15,12 +15,12 @@ $search_columns = array(); // searchable columns
|
||||
$order_columns = array(); // searchable columns
|
||||
$text_length = "";
|
||||
foreach ($fields as $key => $field) {
|
||||
$name = $adminer->fieldName($field);
|
||||
$name = adminer()->fieldName($field);
|
||||
$name_plain = html_entity_decode(strip_tags($name), ENT_QUOTES);
|
||||
if (isset($field["privileges"]["select"]) && $name != "") {
|
||||
$columns[$key] = $name_plain;
|
||||
if (is_shortable($field)) {
|
||||
$text_length = $adminer->selectLengthProcess();
|
||||
$text_length = adminer()->selectLengthProcess();
|
||||
}
|
||||
}
|
||||
if (isset($field["privileges"]["where"]) && $name != "") {
|
||||
@@ -32,13 +32,13 @@ foreach ($fields as $key => $field) {
|
||||
$rights += $field["privileges"];
|
||||
}
|
||||
|
||||
list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
|
||||
list($select, $group) = adminer()->selectColumnsProcess($columns, $indexes);
|
||||
$select = array_unique($select);
|
||||
$group = array_unique($group);
|
||||
$is_group = count($group) < count($select);
|
||||
$where = $adminer->selectSearchProcess($fields, $indexes);
|
||||
$order = $adminer->selectOrderProcess($fields, $indexes);
|
||||
$limit = $adminer->selectLimitProcess();
|
||||
$where = adminer()->selectSearchProcess($fields, $indexes);
|
||||
$order = adminer()->selectOrderProcess($fields, $indexes);
|
||||
$limit = adminer()->selectLimitProcess();
|
||||
|
||||
if ($_GET["val"] && is_ajax()) {
|
||||
header("Content-Type: text/plain; charset=utf-8");
|
||||
@@ -85,7 +85,7 @@ if ($_POST && !$error) {
|
||||
if ($_POST["export"]) {
|
||||
save_settings(array("output" => $_POST["output"], "format" => $_POST["format"]), "adminer_import");
|
||||
dump_headers($TABLE);
|
||||
$adminer->dumpTable($TABLE, "");
|
||||
adminer()->dumpTable($TABLE, "");
|
||||
$from = ($select ? implode(", ", $select) : "*")
|
||||
. convert_fields($columns, $fields, $select)
|
||||
. "\nFROM " . table($TABLE);
|
||||
@@ -99,12 +99,12 @@ if ($_POST && !$error) {
|
||||
}
|
||||
$query = implode(" UNION ALL ", $union);
|
||||
}
|
||||
$adminer->dumpData($TABLE, "table", $query);
|
||||
$adminer->dumpFooter();
|
||||
adminer()->dumpData($TABLE, "table", $query);
|
||||
adminer()->dumpFooter();
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
|
||||
if (!adminer()->selectEmailProcess($where, $foreign_keys)) {
|
||||
if ($_POST["save"] || $_POST["delete"]) { // edit
|
||||
$result = true;
|
||||
$affected = 0;
|
||||
@@ -174,7 +174,7 @@ if ($_POST && !$error) {
|
||||
$set = array();
|
||||
foreach ($row as $key => $val) {
|
||||
$key = bracket_escape($key, true); // true - back
|
||||
$set[idf_escape($key)] = (preg_match('~char|text~', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
|
||||
$set[idf_escape($key)] = (preg_match('~char|text~', $fields[$key]["type"]) || $val != "" ? adminer()->processInput($fields[$key], $val) : "NULL");
|
||||
}
|
||||
$result = $driver->update(
|
||||
$TABLE,
|
||||
@@ -229,7 +229,7 @@ if ($_POST && !$error) {
|
||||
}
|
||||
}
|
||||
|
||||
$table_name = $adminer->tableName($table_status);
|
||||
$table_name = adminer()->tableName($table_status);
|
||||
if (is_ajax()) {
|
||||
page_headers();
|
||||
ob_start();
|
||||
@@ -251,7 +251,7 @@ if (isset($rights["insert"]) || !support("table")) {
|
||||
|
||||
$set = $params ? "&" . http_build_query($params) : "";
|
||||
}
|
||||
$adminer->selectLinks($table_status, $set);
|
||||
adminer()->selectLinks($table_status, $set);
|
||||
|
||||
if (!$columns && support("table")) {
|
||||
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
|
||||
@@ -262,12 +262,12 @@ if (!$columns && support("table")) {
|
||||
echo (DB != "" ? input_hidden("db", DB) . (isset($_GET["ns"]) ? input_hidden("ns", $_GET["ns"]) : "") : ""); // not used in Editor
|
||||
echo input_hidden("select", $TABLE);
|
||||
echo "</div>\n";
|
||||
$adminer->selectColumnsPrint($select, $columns);
|
||||
$adminer->selectSearchPrint($where, $search_columns, $indexes);
|
||||
$adminer->selectOrderPrint($order, $order_columns, $indexes);
|
||||
$adminer->selectLimitPrint($limit);
|
||||
$adminer->selectLengthPrint($text_length);
|
||||
$adminer->selectActionPrint($indexes);
|
||||
adminer()->selectColumnsPrint($select, $columns);
|
||||
adminer()->selectSearchPrint($where, $search_columns, $indexes);
|
||||
adminer()->selectOrderPrint($order, $order_columns, $indexes);
|
||||
adminer()->selectLimitPrint($limit);
|
||||
adminer()->selectLengthPrint($text_length);
|
||||
adminer()->selectActionPrint($indexes);
|
||||
echo "</form>\n";
|
||||
|
||||
$page = $_GET["page"];
|
||||
@@ -325,7 +325,7 @@ if (!$columns && support("table")) {
|
||||
if (!$rows) {
|
||||
echo "<p class='message'>" . lang('No rows.') . "\n";
|
||||
} else {
|
||||
$backward_keys = $adminer->backwardKeys($TABLE, $table_name);
|
||||
$backward_keys = adminer()->backwardKeys($TABLE, $table_name);
|
||||
|
||||
echo "<div class='scrollable'>";
|
||||
echo "<table id='table' class='nowrap checkable odds'>";
|
||||
@@ -343,7 +343,7 @@ if (!$columns && support("table")) {
|
||||
/** @var array{fun?:string, col?:string} */
|
||||
$val = idx($_GET["columns"], key($select)) ?: array();
|
||||
$field = $fields[$select ? ($val ? $val["col"] : current($select)) : $key];
|
||||
$name = ($field ? $adminer->fieldName($field, $rank) : ($val["fun"] ? "*" : h($key)));
|
||||
$name = ($field ? adminer()->fieldName($field, $rank) : ($val["fun"] ? "*" : h($key)));
|
||||
if ($name != "") {
|
||||
$rank++;
|
||||
$names[$key] = $name;
|
||||
@@ -384,7 +384,7 @@ if (!$columns && support("table")) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
|
||||
foreach (adminer()->rowDescriptions($rows, $foreign_keys) as $n => $row) {
|
||||
$unique_array = unique_array($rows[$n], $indexes);
|
||||
if (!$unique_array) {
|
||||
$unique_array = array();
|
||||
@@ -472,7 +472,7 @@ if (!$columns && support("table")) {
|
||||
if ($backward_keys) {
|
||||
echo "<td>";
|
||||
}
|
||||
$adminer->backwardKeysPrint($backward_keys, $rows[$n]);
|
||||
adminer()->backwardKeysPrint($backward_keys, $rows[$n]);
|
||||
echo "</tr>\n"; // close to allow white-space: pre
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ if (!$columns && support("table")) {
|
||||
echo checkbox("all", 1, 0, ($found_rows !== false ? ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) : ""), $onclick) . "\n";
|
||||
echo "</fieldset>\n";
|
||||
|
||||
if ($adminer->selectCommandPrint()) {
|
||||
if (adminer()->selectCommandPrint()) {
|
||||
?>
|
||||
<fieldset<?php echo ($_GET["modify"] ? '' : ' class="jsonly"'); ?>><legend><?php echo lang('Modify'); ?></legend><div>
|
||||
<input type="submit" value="<?php echo lang('Save'); ?>"<?php echo ($_GET["modify"] ? '' : ' title="' . lang('Ctrl+click on a value to modify it.') . '"'); ?>>
|
||||
@@ -562,7 +562,7 @@ if (!$columns && support("table")) {
|
||||
<?php
|
||||
}
|
||||
|
||||
$format = $adminer->dumpFormat();
|
||||
$format = adminer()->dumpFormat();
|
||||
foreach ((array) $_GET["columns"] as $column) {
|
||||
if ($column["fun"]) {
|
||||
unset($format['sql']);
|
||||
@@ -571,18 +571,18 @@ if (!$columns && support("table")) {
|
||||
}
|
||||
if ($format) {
|
||||
print_fieldset("export", lang('Export') . " <span id='selected2'></span>");
|
||||
$output = $adminer->dumpOutput();
|
||||
$output = adminer()->dumpOutput();
|
||||
echo ($output ? html_select("output", $output, $adminer_import["output"]) . " " : "");
|
||||
echo html_select("format", $format, $adminer_import["format"]);
|
||||
echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
|
||||
echo "</div></fieldset>\n";
|
||||
}
|
||||
|
||||
$adminer->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
|
||||
adminer()->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
|
||||
echo "</div></div>\n";
|
||||
}
|
||||
|
||||
if ($adminer->selectImportPrint()) {
|
||||
if (adminer()->selectImportPrint()) {
|
||||
echo "<div>";
|
||||
echo "<a href='#import'>" . lang('Import') . "</a>";
|
||||
echo script("qsl('a').onclick = partial(toggle, 'import');", "");
|
||||
|
@@ -4,9 +4,9 @@ namespace Adminer;
|
||||
if (!$error && $_POST["export"]) {
|
||||
save_settings(array("output" => $_POST["output"], "format" => $_POST["format"]), "adminer_import");
|
||||
dump_headers("sql");
|
||||
$adminer->dumpTable("", "");
|
||||
$adminer->dumpData("", "table", $_POST["query"]);
|
||||
$adminer->dumpFooter();
|
||||
adminer()->dumpTable("", "");
|
||||
adminer()->dumpData("", "table", $_POST["query"]);
|
||||
adminer()->dumpFooter();
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ if (!$error && $_POST) {
|
||||
if (!isset($_GET["import"])) {
|
||||
$query = $_POST["query"];
|
||||
} elseif ($_POST["webfile"]) {
|
||||
$sql_file_path = $adminer->importServerPath();
|
||||
$sql_file_path = adminer()->importServerPath();
|
||||
$fp = @fopen((file_exists($sql_file_path)
|
||||
? $sql_file_path
|
||||
: "compress.zlib://$sql_file_path.gz"
|
||||
@@ -54,7 +54,7 @@ if (!$error && $_POST) {
|
||||
$delimiter = ";";
|
||||
$offset = 0;
|
||||
$empty = true;
|
||||
$connection2 = connect($adminer->credentials()); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error
|
||||
$connection2 = connect(adminer()->credentials()); // connection for exploring indexes and EXPLAIN (to not replace FOUND_ROWS()) //! PDO - silent error
|
||||
if (is_object($connection2) && DB != "") {
|
||||
$connection2->select_db(DB);
|
||||
if ($_GET["ns"] != "") {
|
||||
@@ -66,7 +66,7 @@ if (!$error && $_POST) {
|
||||
$parse = '[\'"' . (JUSH == "sql" ? '`#' : (JUSH == "sqlite" ? '`[' : (JUSH == "mssql" ? '[' : ''))) . ']|/\*|-- |$' . (JUSH == "pgsql" ? '|\$[^$]*\$' : '');
|
||||
$total_start = microtime(true);
|
||||
$adminer_export = get_settings("adminer_import"); // this doesn't offer SQL export so we match the import/export style at select
|
||||
$dump_format = $adminer->dumpFormat();
|
||||
$dump_format = adminer()->dumpFormat();
|
||||
unset($dump_format["sql"]);
|
||||
|
||||
while ($query != "") {
|
||||
@@ -109,7 +109,7 @@ if (!$error && $_POST) {
|
||||
$empty = false;
|
||||
$q = substr($query, 0, $pos);
|
||||
$commands++;
|
||||
$print = "<pre id='sql-$commands'><code class='jush-" . JUSH . "'>" . $adminer->sqlCommandQuery($q) . "</code></pre>\n";
|
||||
$print = "<pre id='sql-$commands'><code class='jush-" . JUSH . "'>" . adminer()->sqlCommandQuery($q) . "</code></pre>\n";
|
||||
if (JUSH == "sqlite" && preg_match("~^$space*+ATTACH\\b~i", $q, $match)) {
|
||||
// PHP doesn't support setting SQLITE_LIMIT_ATTACHED
|
||||
echo $print;
|
||||
@@ -167,7 +167,7 @@ if (!$error && $_POST) {
|
||||
}
|
||||
$id = "export-$commands";
|
||||
echo ", <a href='#$id'>" . lang('Export') . "</a>" . script("qsl('a').onclick = partial(toggle, '$id');", "") . "<span id='$id' class='hidden'>: "
|
||||
. html_select("output", $adminer->dumpOutput(), $adminer_export["output"]) . " "
|
||||
. html_select("output", adminer()->dumpOutput(), $adminer_export["output"]) . " "
|
||||
. html_select("format", $dump_format, $adminer_export["format"])
|
||||
. input_hidden("query", $q)
|
||||
. "<input type='submit' name='export' value='" . lang('Export') . "'>" . input_token() . "</span>\n"
|
||||
@@ -237,7 +237,7 @@ if (!isset($_GET["import"])) {
|
||||
textarea("query", $q, 20);
|
||||
echo script(($_POST ? "" : "qs('textarea').focus();\n") . "qs('#form').onsubmit = partial(sqlSubmit, qs('#form'), '" . js_escape(remove_from_uri("sql|limit|error_stops|only_errors|history")) . "');");
|
||||
echo "<p>";
|
||||
$adminer->sqlPrintAfter();
|
||||
adminer()->sqlPrintAfter();
|
||||
echo "$execute\n";
|
||||
echo lang('Limit rows') . ": <input type='number' name='limit' class='size' value='" . h($_POST ? $_POST["limit"] : $_GET["limit"]) . "'>\n";
|
||||
|
||||
@@ -249,7 +249,7 @@ if (!isset($_GET["import"])) {
|
||||
: lang('File uploads are disabled.')
|
||||
);
|
||||
echo "</div></fieldset>\n";
|
||||
$importServerPath = $adminer->importServerPath();
|
||||
$importServerPath = adminer()->importServerPath();
|
||||
if ($importServerPath) {
|
||||
echo "<fieldset><legend>" . lang('From server') . "</legend><div>";
|
||||
echo lang('Webserver file %s', "<code>" . h($importServerPath) . "$gz</code>");
|
||||
|
@@ -7,7 +7,7 @@ if (!$fields) {
|
||||
$error = error() ?: lang('No tables.');
|
||||
}
|
||||
$table_status = table_status1($TABLE);
|
||||
$name = $adminer->tableName($table_status);
|
||||
$name = adminer()->tableName($table_status);
|
||||
|
||||
page_header(($fields && is_view($table_status) ? $table_status['Engine'] == 'materialized view' ? lang('Materialized view') : lang('View') : lang('Table')) . ": " . ($name != "" ? $name : h($TABLE)), $error);
|
||||
|
||||
@@ -15,7 +15,7 @@ $rights = array();
|
||||
foreach ($fields as $key => $field) {
|
||||
$rights += $field["privileges"];
|
||||
}
|
||||
$adminer->selectLinks($table_status, (isset($rights["insert"]) || !support("table") ? "" : null));
|
||||
adminer()->selectLinks($table_status, (isset($rights["insert"]) || !support("table") ? "" : null));
|
||||
|
||||
$comment = $table_status["Comment"];
|
||||
if ($comment != "") {
|
||||
@@ -23,14 +23,14 @@ if ($comment != "") {
|
||||
}
|
||||
|
||||
if ($fields) {
|
||||
$adminer->tableStructurePrint($fields, $table_status);
|
||||
adminer()->tableStructurePrint($fields, $table_status);
|
||||
}
|
||||
|
||||
if (support("indexes") && $driver->supportsIndex($table_status)) {
|
||||
echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
|
||||
$indexes = indexes($TABLE);
|
||||
if ($indexes) {
|
||||
$adminer->tableIndexesPrint($indexes);
|
||||
adminer()->tableIndexesPrint($indexes);
|
||||
}
|
||||
echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ namespace Adminer;
|
||||
|
||||
page_header(lang('Server'), "", false);
|
||||
|
||||
if ($adminer->homepage()) {
|
||||
if (adminer()->homepage()) {
|
||||
echo "<form action='' method='post'>\n";
|
||||
echo "<p>" . lang('Search data in tables') . ": <input type='search' name='query' value='" . h($_POST["query"]) . "'> <input type='submit' value='" . lang('Search') . "'>\n";
|
||||
if ($_POST["query"] != "") {
|
||||
@@ -19,7 +19,7 @@ if ($adminer->homepage()) {
|
||||
echo "</thead>\n";
|
||||
|
||||
foreach (table_status() as $table => $row) {
|
||||
$name = $adminer->tableName($row);
|
||||
$name = adminer()->tableName($row);
|
||||
if ($name != "") {
|
||||
echo '<tr><td>' . checkbox("tables[]", $table, in_array($table, (array) $_POST["tables"], true));
|
||||
echo "<th><a href='" . h(ME) . 'select=' . urlencode($table) . "'>$name</a>";
|
||||
|
@@ -2,6 +2,7 @@
|
||||
namespace Adminer;
|
||||
|
||||
class Adminer {
|
||||
static $instance;
|
||||
public $error = '';
|
||||
private $values = array();
|
||||
|
||||
@@ -30,9 +31,9 @@ class Adminer {
|
||||
}
|
||||
|
||||
function database() {
|
||||
global $connection, $adminer;
|
||||
global $connection;
|
||||
if ($connection) {
|
||||
$databases = $adminer->databases(false);
|
||||
$databases = adminer()->databases(false);
|
||||
return (!$databases
|
||||
? get_val("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1)") // username without the database list
|
||||
: $databases[(information_schema($databases[0]) ? 1 : 0)] // first available database
|
||||
@@ -79,10 +80,9 @@ class Adminer {
|
||||
}
|
||||
|
||||
function loginForm() {
|
||||
global $adminer;
|
||||
echo "<table class='layout'>\n";
|
||||
echo $adminer->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', input_hidden("auth[driver]", "server") . '<input name="auth[username]" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">');
|
||||
echo $adminer->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
|
||||
echo adminer()->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', input_hidden("auth[driver]", "server") . '<input name="auth[username]" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">');
|
||||
echo adminer()->loginFormField('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
|
||||
echo "</table>\n";
|
||||
echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
|
||||
echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
|
||||
@@ -119,20 +119,19 @@ class Adminer {
|
||||
}
|
||||
|
||||
function backwardKeys($table, $tableName) {
|
||||
global $adminer;
|
||||
$return = array();
|
||||
foreach (
|
||||
get_rows("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
|
||||
FROM information_schema.KEY_COLUMN_USAGE
|
||||
WHERE TABLE_SCHEMA = " . q($adminer->database()) . "
|
||||
AND REFERENCED_TABLE_SCHEMA = " . q($adminer->database()) . "
|
||||
WHERE TABLE_SCHEMA = " . q(adminer()->database()) . "
|
||||
AND REFERENCED_TABLE_SCHEMA = " . q(adminer()->database()) . "
|
||||
AND REFERENCED_TABLE_NAME = " . q($table) . "
|
||||
ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
) {
|
||||
$return[$row["TABLE_NAME"]]["keys"][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];
|
||||
}
|
||||
foreach ($return as $key => $val) {
|
||||
$name = $adminer->tableName(table_status1($key, true));
|
||||
$name = adminer()->tableName(table_status1($key, true));
|
||||
if ($name != "") {
|
||||
$search = preg_quote($tableName);
|
||||
$separator = "(:|\\s*-)?\\s+";
|
||||
@@ -238,7 +237,6 @@ 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();
|
||||
@@ -273,14 +271,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 => "") + $adminer->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 => "") + $adminer->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";
|
||||
@@ -356,7 +354,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
}
|
||||
|
||||
function selectSearchProcess($fields, $indexes) {
|
||||
global $driver, $adminer;
|
||||
global $driver;
|
||||
$return = array();
|
||||
foreach ((array) $_GET["where"] as $key => $where) {
|
||||
$col = $where["col"];
|
||||
@@ -371,9 +369,9 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
$conds[] = (in_array(0, $val) ? "$name IS NULL OR " : "") . "$name IN (" . implode(", ", array_map('intval', $val)) . ")";
|
||||
} else {
|
||||
$text_type = preg_match('~char|text|enum|set~', $field["type"]);
|
||||
$value = $adminer->processInput($field, (!$op && $text_type && preg_match('~^[^%]+$~', $val) ? "%$val%" : $val));
|
||||
$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, $adminer->operators()) || $op == "=" ? " $op $value"
|
||||
: (in_array($op, adminer()->operators()) || $op == "=" ? " $op $value"
|
||||
: ($text_type ? " LIKE $value"
|
||||
: " IN (" . str_replace(",", "', '", $value) . ")"
|
||||
)));
|
||||
@@ -426,7 +424,6 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
}
|
||||
|
||||
function selectEmailProcess($where, $foreignKeys) {
|
||||
global $adminer;
|
||||
if ($_POST["email_append"]) {
|
||||
return true;
|
||||
}
|
||||
@@ -444,10 +441,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
. ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('Adminer\where_check', (array) $_POST["check"])) . "))")
|
||||
);
|
||||
$fields = fields($_GET["select"]);
|
||||
foreach ($adminer->rowDescriptions($rows, $foreignKeys) as $row) {
|
||||
foreach (adminer()->rowDescriptions($rows, $foreignKeys) as $row) {
|
||||
$replace = array('{\\' => '{'); // allow literal {$name}
|
||||
foreach ($matches[1] as $val) {
|
||||
$replace['{$' . "$val}"] = $adminer->editVal($row[$val], $fields[$val]);
|
||||
$replace['{$' . "$val}"] = adminer()->editVal($row[$val], $fields[$val]);
|
||||
}
|
||||
$email = $row[$_POST["email_field"]];
|
||||
if (is_mail($email) && send_mail($email, strtr($subject, $replace), strtr($message, $replace), $_POST["email_from"], $_FILES["email_files"])) {
|
||||
@@ -596,8 +593,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
}
|
||||
|
||||
function navigation($missing) {
|
||||
global $adminer;
|
||||
echo "<h1>" . $adminer->name() . " <span class='version'>" . VERSION;
|
||||
echo "<h1>" . adminer()->name() . " <span class='version'>" . VERSION;
|
||||
$new_version = $_COOKIE["adminer_version"];
|
||||
echo " <a href='https://www.adminer.org/editor/#download'" . target_blank() . " id='version'>" . (version_compare(VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>";
|
||||
echo "</span></h1>\n";
|
||||
@@ -617,13 +613,13 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$adminer->databasesPrint($missing);
|
||||
adminer()->databasesPrint($missing);
|
||||
if ($missing != "db" && $missing != "ns") {
|
||||
$table_status = table_status('', true);
|
||||
if (!$table_status) {
|
||||
echo "<p class='message'>" . lang('No tables.') . "\n";
|
||||
} else {
|
||||
$adminer->tablesPrint($table_status);
|
||||
adminer()->tablesPrint($table_status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -636,12 +632,11 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
}
|
||||
|
||||
function tablesPrint($tables) {
|
||||
global $adminer;
|
||||
echo "<ul id='tables'>";
|
||||
echo script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
|
||||
foreach ($tables as $row) {
|
||||
echo '<li>';
|
||||
$name = $adminer->tableName($row);
|
||||
$name = adminer()->tableName($row);
|
||||
if ($name != "") { // ignore tables without name
|
||||
echo "<a href='" . h(ME) . 'select=' . urlencode($row["Name"]) . "'"
|
||||
. bold($_GET["select"] == $row["Name"] || $_GET["edit"] == $row["Name"], "select")
|
||||
@@ -653,10 +648,9 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
||||
}
|
||||
|
||||
function _foreignColumn($foreignKeys, $column) {
|
||||
global $adminer;
|
||||
foreach ((array) $foreignKeys[$column] as $foreignKey) {
|
||||
if (count($foreignKey["source"]) == 1) {
|
||||
$name = $adminer->rowDescription($foreignKey["table"]);
|
||||
$name = adminer()->rowDescription($foreignKey["table"]);
|
||||
if ($name != "") {
|
||||
$id = idf_escape($foreignKey["target"][0]);
|
||||
return array($foreignKey["table"], $id, $name);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
namespace Adminer;
|
||||
|
||||
$connection->select_db($adminer->database());
|
||||
$connection->select_db(adminer()->database());
|
||||
|
@@ -4,7 +4,7 @@ namespace Adminer;
|
||||
if ($_GET["script"] == "kill") {
|
||||
$connection->query("KILL " . number($_POST["kill"]));
|
||||
|
||||
} elseif (list($table, $id, $name) = $adminer->_foreignColumn(column_foreign_keys($_GET["source"]), $_GET["field"])) { // complete
|
||||
} elseif (list($table, $id, $name) = adminer()->_foreignColumn(column_foreign_keys($_GET["source"]), $_GET["field"])) { // complete
|
||||
$limit = 11;
|
||||
$result = $connection->query("SELECT $id, $name FROM " . table($table) . " WHERE " . (preg_match('~^[0-9]+$~', $_GET["value"]) ? "$id = $_GET[value] OR " : "") . "$name LIKE " . q("$_GET[value]%") . " ORDER BY 2 LIMIT $limit");
|
||||
for ($i=1; ($row = $result->fetch_row()) && $i < $limit; $i++) {
|
||||
|
@@ -257,8 +257,7 @@ if (isset($_GET["clickhouse"])) {
|
||||
}
|
||||
|
||||
function logged_user() {
|
||||
$adminer = adminer();
|
||||
$credentials = $adminer->credentials();
|
||||
$credentials = adminer()->credentials();
|
||||
return $credentials[1];
|
||||
}
|
||||
|
||||
|
@@ -125,8 +125,7 @@ if (isset($_GET["firebird"])) {
|
||||
}
|
||||
|
||||
function logged_user() {
|
||||
$adminer = adminer();
|
||||
$credentials = $adminer->credentials();
|
||||
$credentials = adminer()->credentials();
|
||||
return $credentials[1];
|
||||
}
|
||||
|
||||
|
@@ -260,8 +260,7 @@ if (isset($_GET["simpledb"])) {
|
||||
}
|
||||
|
||||
function logged_user() {
|
||||
$adminer = adminer();
|
||||
$credentials = $adminer->credentials();
|
||||
$credentials = adminer()->credentials();
|
||||
return $credentials[1];
|
||||
}
|
||||
|
||||
@@ -383,9 +382,8 @@ if (isset($_GET["simpledb"])) {
|
||||
}
|
||||
|
||||
function sdb_request($action, $params = array()) {
|
||||
$adminer = adminer();
|
||||
$connection = connection();
|
||||
list($host, $params['AWSAccessKeyId'], $secret) = $adminer->credentials();
|
||||
list($host, $params['AWSAccessKeyId'], $secret) = adminer()->credentials();
|
||||
$params['Action'] = $action;
|
||||
$params['Timestamp'] = gmdate('Y-m-d\TH:i:s+00:00');
|
||||
$params['Version'] = '2009-04-15';
|
||||
|
@@ -26,8 +26,7 @@ class AdminerSqlLog {
|
||||
|
||||
private function log($query) {
|
||||
if ($this->filename == "") {
|
||||
$adminer = Adminer\adminer();
|
||||
$this->filename = $adminer->database() . ".sql"; // no database goes to ".sql" to avoid collisions
|
||||
$this->filename = Adminer\adminer()->database() . ".sql"; // no database goes to ".sql" to avoid collisions
|
||||
}
|
||||
$fp = fopen($this->filename, "a");
|
||||
flock($fp, LOCK_EX);
|
||||
|
Reference in New Issue
Block a user