mirror of
https://github.com/vrana/adminer.git
synced 2025-08-10 00:28:34 +02:00
New plugin: Configure options by end-users and store them to a cookie
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
- CSS: Add logo
|
- CSS: Add logo
|
||||||
- Editor: Move mass sending e-mails to a plugin
|
- Editor: Move mass sending e-mails to a plugin
|
||||||
- Plugins: Allow formatting translations using Adminer\lang_format()
|
- Plugins: Allow formatting translations using Adminer\lang_format()
|
||||||
|
- New plugin: Configure options by end-users and store them to a cookie
|
||||||
- New plugin: Set up driver, server and database in Adminer Editor
|
- New plugin: Set up driver, server and database in Adminer Editor
|
||||||
|
|
||||||
## Adminer 5.1.1 (released 2025-04-02)
|
## Adminer 5.1.1 (released 2025-04-02)
|
||||||
|
@@ -300,6 +300,13 @@ class Adminer {
|
|||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get configuration options for AdminerConfig
|
||||||
|
* @return string[] key is config description, value is HTML
|
||||||
|
*/
|
||||||
|
function config(): array {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
/** Print table structure in tabular format
|
/** Print table structure in tabular format
|
||||||
* @param Field[] $fields
|
* @param Field[] $fields
|
||||||
* @param TableStatus $tableStatus
|
* @param TableStatus $tableStatus
|
||||||
|
@@ -100,7 +100,7 @@ function html_select(string $name, array $options, ?string $value = "", string $
|
|||||||
/** Generate HTML radio list
|
/** Generate HTML radio list
|
||||||
* @param string[] $options
|
* @param string[] $options
|
||||||
*/
|
*/
|
||||||
function html_radios(string $name, array $options, string $value = ""): string {
|
function html_radios(string $name, array $options, ?string $value = ""): string {
|
||||||
$return = "";
|
$return = "";
|
||||||
foreach ($options as $key => $val) {
|
foreach ($options as $key => $val) {
|
||||||
$return .= "<label><input type='radio' name='" . h($name) . "' value='" . h($key) . "'" . ($key == $value ? " checked" : "") . ">" . h($val) . "</label>";
|
$return .= "<label><input type='radio' name='" . h($name) . "' value='" . h($key) . "'" . ($key == $value ? " checked" : "") . ">" . h($val) . "</label>";
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
class Plugins {
|
class Plugins {
|
||||||
/** @var true[] */ private static array $append = array('dumpFormat' => true, 'dumpOutput' => true, 'editRowPrint' => true, 'editFunctions' => true); // these hooks expect the value to be appended to the result
|
/** @var true[] */ private static array $append = array('dumpFormat' => true, 'dumpOutput' => true, 'editRowPrint' => true, 'editFunctions' => true, 'config' => true); // these hooks expect the value to be appended to the result
|
||||||
|
|
||||||
/** @var list<object> @visibility protected(set) */ public array $plugins;
|
/** @var list<object> @visibility protected(set) */ public array $plugins;
|
||||||
/** @visibility protected(set) */ public string $error = ''; // HTML
|
/** @visibility protected(set) */ public string $error = ''; // HTML
|
||||||
|
@@ -231,6 +231,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
|
|||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function config() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
function selectColumnsPrint($select, $columns) {
|
function selectColumnsPrint($select, $columns) {
|
||||||
// can allow grouping functions by indexes
|
// can allow grouping functions by indexes
|
||||||
}
|
}
|
||||||
|
67
plugins/config.php
Normal file
67
plugins/config.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/** Configure options by end-users and store them to a cookie
|
||||||
|
* @link https://www.adminer.org/plugins/#use
|
||||||
|
* @author Jakub Vrana, https://www.vrana.cz/
|
||||||
|
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||||
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||||
|
*/
|
||||||
|
class AdminerConfig {
|
||||||
|
|
||||||
|
function headers() {
|
||||||
|
static $called; // this function is called from page_header() and it also calls page_header()
|
||||||
|
if (isset($_GET["config"]) && !$called && Adminer\connection()) {
|
||||||
|
$called = true;
|
||||||
|
if ($_POST) { //! check $error
|
||||||
|
unset($_POST["token"]);
|
||||||
|
Adminer\save_settings($_POST, "adminer_config");
|
||||||
|
Adminer\redirect($_SERVER["REQUEST_URI"], $this->lang('Configuration saved.'));
|
||||||
|
}
|
||||||
|
Adminer\page_header($this->lang('Configuration'));
|
||||||
|
$config = Adminer\adminer()->config();
|
||||||
|
if (!$config) {
|
||||||
|
echo "<p>" . $this->lang('Only some plugins support configuration, e.g. %s.', '<a href="https://github.com/vrana/adminer/blob/master/plugins/menu-links.php"' . Adminer\target_blank() . '>menu-links</a>') . "\n";
|
||||||
|
} else {
|
||||||
|
echo "<form action='' method='post'>\n";
|
||||||
|
echo "<table>\n";
|
||||||
|
foreach ($config as $title => $html) {
|
||||||
|
echo "<tr><th>$title<td>$html\n";
|
||||||
|
}
|
||||||
|
echo "</table>\n";
|
||||||
|
echo "<p><input type='submit' value='" . Adminer\lang('Save') . "'>\n";
|
||||||
|
echo Adminer\input_token();
|
||||||
|
echo "</form>\n";
|
||||||
|
}
|
||||||
|
Adminer\page_footer('db');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function navigation() {
|
||||||
|
if (Adminer\connection()) {
|
||||||
|
$link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', Adminer\ME), 0, -1);
|
||||||
|
?>
|
||||||
|
<style>
|
||||||
|
#configlink { position: absolute; top: -2.6em; left: 17.8em; }
|
||||||
|
#configlink a { font-size: 150%; }
|
||||||
|
@media all and (max-width: 800px) {
|
||||||
|
#configlink { top: 5em; left: auto; right: 20px; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<?php
|
||||||
|
echo "<div id='configlink'><a href='" . Adminer\h($link) . "&config=' title='" . $this->lang('Configuration') . "'>⚙</a></div>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function lang($idf, $number = null) {
|
||||||
|
return Adminer\lang_format(Adminer\idx(self::$translations[Adminer\LANG], $idf) ?: $idf, $number);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static $translations = array(
|
||||||
|
'cs' => array(
|
||||||
|
'Configuration' => 'Konfigurace',
|
||||||
|
'Configuration saved.' => 'Konfigurace uložena.',
|
||||||
|
'Only some plugins support configuration, e.g. %s.' => 'Konfiguraci podporují jen některé pluginy, např. %s.',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user