]> git.joonet.de Git - adminer.git/commitdiff
New plugin: Configure options by end-users and store them to a cookie
authorJakub Vrana <jakub@vrana.cz>
Sun, 6 Apr 2025 04:24:55 +0000 (06:24 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 6 Apr 2025 05:29:16 +0000 (07:29 +0200)
CHANGELOG.md
adminer/include/adminer.inc.php
adminer/include/html.inc.php
adminer/include/plugins.inc.php
editor/include/adminer.inc.php
plugins/config.php [new file with mode: 0644]

index d495d0f27a7c5693d69641ad95aeb8557811c44a..c6d9f16c4b15f73b37ba75514eb02951517cd783 100644 (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)
index 0b62ec42487c8fff80f985b6c3993f8b9fe72062..3fa74ca313e55f0dcecb175c4e296a0d95342c0d 100644 (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
index 20b86e8697f738369242cda1b2df202d20f66d29..543bcb4bd4a2ffcb7d0be740f5190c09cfc08de1 100644 (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>";
index 6c22dbdbfdf2549baa751e06462fdfb20268c15e..5523d939bd8492663d67e39e193d56c4975ee4b2 100644 (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
index 943e5b68d67aaa83544ecb681fb8d4671c61e425..545baa2dbaaad3b03f958119fe303daabeaebf44 100644 (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
        }
diff --git a/plugins/config.php b/plugins/config.php
new file mode 100644 (file)
index 0000000..a0c060f
--- /dev/null
@@ -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.',
+               ),
+       );
+}