1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-08 15:47:00 +02:00

New plugin: Configure options by end-users and store them to a cookie

This commit is contained in:
Jakub Vrana
2025-04-06 06:24:55 +02:00
parent 48f82b3454
commit cca943015f
6 changed files with 81 additions and 2 deletions

View File

@@ -8,6 +8,7 @@
- CSS: Add logo
- Editor: Move mass sending e-mails to a plugin
- 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
## Adminer 5.1.1 (released 2025-04-02)

View File

@@ -300,6 +300,13 @@ class Adminer {
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
* @param Field[] $fields
* @param TableStatus $tableStatus

View File

@@ -100,7 +100,7 @@ function html_select(string $name, array $options, ?string $value = "", string $
/** Generate HTML radio list
* @param string[] $options
*/
function html_radios(string $name, array $options, string $value = ""): string {
function html_radios(string $name, array $options, ?string $value = ""): string {
$return = "";
foreach ($options as $key => $val) {
$return .= "<label><input type='radio' name='" . h($name) . "' value='" . h($key) . "'" . ($key == $value ? " checked" : "") . ">" . h($val) . "</label>";

View File

@@ -2,7 +2,7 @@
namespace Adminer;
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;
/** @visibility protected(set) */ public string $error = ''; // HTML

View File

@@ -231,6 +231,10 @@ ORDER BY ORDINAL_POSITION", null, "") as $row
return $val;
}
function config() {
return array();
}
function selectColumnsPrint($select, $columns) {
// can allow grouping functions by indexes
}

67
plugins/config.php Normal file
View 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.',
),
);
}