]> git.joonet.de Git - adminer.git/commitdiff
New plugin: Configure menu table links
authorJakub Vrana <jakub@vrana.cz>
Sun, 6 Apr 2025 04:25:58 +0000 (06:25 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 6 Apr 2025 05:29:23 +0000 (07:29 +0200)
CHANGELOG.md
adminer/include/html.inc.php
plugins/menu-links.php [new file with mode: 0644]

index c6d9f16c4b15f73b37ba75514eb02951517cd783..bbd56273c6f9af31f08e9c0da1a7e7959949cd8f 100644 (file)
@@ -9,6 +9,7 @@
 - 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: Configure menu table links
 - New plugin: Set up driver, server and database in Adminer Editor
 
 ## Adminer 5.1.1 (released 2025-04-02)
index 543bcb4bd4a2ffcb7d0be740f5190c09cfc08de1..9193b5d5ba5c8e443256f2af49ede5c5111bf057 100644 (file)
@@ -100,10 +100,10 @@ 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 $separator = ""): string {
        $return = "";
        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>$separator";
        }
        return $return;
 }
diff --git a/plugins/menu-links.php b/plugins/menu-links.php
new file mode 100644 (file)
index 0000000..4ba89f0
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+
+/** Configure menu table links; combinable with AdminerConfig
+* @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 AdminerMenuLinks {
+       private $menu;
+
+       /** @param ''|'table'|'select'|'auto' $menu see config() for explanation */
+       function __construct($menu = '') {
+               $this->menu = Adminer\get_setting("menu", "adminer_config") ?: $menu;
+       }
+
+       function config() {
+               $options = array(
+                       'select' => Adminer\lang('Select'),
+                       'table' => Adminer\lang('Table'),
+                       '' => $this->lang('Both'),
+                       'auto' => $this->lang('Auto (Select on select page, Table otherwise)'),
+               );
+               return array($this->lang('Menu table links') => Adminer\html_radios('menu', $options, $this->menu, "<br>"));
+       }
+
+       function tablesPrint(array $tables) {
+               $menu = $this->menu;
+               $titles = array(
+                       'select' => Adminer\lang('Select data'),
+                       'table' => Adminer\lang('Show structure'),
+               );
+               // this is copied from Adminer::tablesPrint()
+               echo "<ul id='tables'>" . Adminer\script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
+               foreach ($tables as $table => $status) {
+                       $name = Adminer\adminer()->tableName($status);
+                       if ($name != "") {
+                               echo '<li>';
+                               if (!$menu) {
+                                       echo '<a href="' . Adminer\h(Adminer\ME) . 'select=' . urlencode($table) . '"'
+                                               . Adminer\bold($_GET["select"] == $table || $_GET["edit"] == $table, "select")
+                                               . " title='$titles[select]'>" . Adminer\lang('select') . "</a> "
+                                       ;
+                               }
+                               $actives = array($_GET["table"], $_GET["create"], $_GET["indexes"], $_GET["foreign"], $_GET["trigger"]);
+                               if ($menu) {
+                                       $actives[] = $_GET["select"];
+                               }
+                               $link =
+                                       ($menu == 'select' ? 'select' :
+                                       ($menu != 'auto' ? 'table' :
+                                       ($_GET["select"] ? 'select' : 'table')
+                               ));
+                               $class = ($link == "select" ? "select" : (Adminer\is_view($status) ? "view" : "structure"));
+                               echo (Adminer\support("table") || Adminer\support("indexes") || $menu
+                                       ? '<a href="' . Adminer\h(Adminer\ME) . "$link=" . urlencode($table) . '"'
+                                               . Adminer\bold(in_array($table, $actives), $class)
+                                               . " title='$titles[$link]'>$name</a>"
+                                       : "<span>$name</span>"
+                               );
+                               echo "\n";
+                       }
+               }
+               echo "</ul>\n";
+               return true;
+       }
+
+       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(
+                       'Menu table links' => 'Odkazy na tabulky v menu',
+                       'Both' => 'Oboje',
+                       'Auto (Select on select page, Table otherwise)' => 'Auto (Vypsat na vĂ˝pisech, jinak Tabulka)',
+               ),
+       );
+}