]> git.joonet.de Git - adminer.git/commitdiff
Plugins: Load config from adminer-plugins.php
authorJakub Vrana <jakub@vrana.cz>
Wed, 19 Mar 2025 04:05:42 +0000 (05:05 +0100)
committerJakub Vrana <jakub@vrana.cz>
Wed, 19 Mar 2025 04:05:42 +0000 (05:05 +0100)
.gitignore
CHANGELOG.md
README.md
adminer/include/bootstrap.inc.php
adminer/include/plugins.inc.php

index 946395f2b30632e7c46d3f167bee252f9a972ac2..131e7cf17ce2a001873dc3f81e2a050d6c9f0611 100644 (file)
@@ -6,3 +6,4 @@
 /editor*.php
 /vendor/
 adminer-plugins/
+adminer-plugins.php
index 56a77204ddda66d3b923536153b2b4f4d3c3ee48..b386eca3f96136176c54b2eea0835e4a2bd5c7dd 100644 (file)
@@ -6,7 +6,8 @@
 - CSS: Allow more custom styles with dark mode (bug #925)
 - IMAP: New plugin driver created for fun
 - Plugins: autoload plugins from adminer-plugins/
-- Plugins: configure plugins with adminer-plugins/config.php
+- Plugins: configure plugins with adminer-plugins.php
+- Plugins: Display loaded plugins in server overview
 
 ## Adminer 5.0.6 (released 2025-03-17)
 - Align numbers right (bug #912)
index b70f40d097c365754cce1652c04b9c5637f59ebb..b8086d42a20f38415b276c1e3990a130d7ffb23e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -32,19 +32,19 @@ To use a plugin, simply upload it to `adminer-plugins/` next to `adminer.php`.
 
 ```
 - adminer.php
-- adminer-plugins
-    - config.php
+- adminer-plugins/
     - dump-xml.php
     - login-password-less.php
+    - ...
+- adminer-plugins.php
 ```
 
-Some plugins require configuration. To use them, you need to create another file in `adminer-plugins/`:
+Some plugins require configuration. To use them, create file `adminer-plugins.php`. You can also specify loading order here.
 
 ```php
-<?php // config.php
-require_once __DIR__ . "/login-password-less.php";
-
+<?php // adminer-plugins.php
 return array(
     new AdminerLoginPasswordLess('$2y$07$Czp9G/aLi3AnaUqpvkF05OHO1LMizrAgMLvnaOdvQovHaRv28XDhG'),
+    // You can specify all plugins here or just the ones needing configuration.
 );
 ```
index bc19b7ec0bcc8973765a2b76e24104b245839f2f..0cc14345f4ad7f5799392200ce4671966e04d67e 100644 (file)
@@ -80,7 +80,7 @@ include "./include/adminer.inc.php";
 
 if (function_exists('adminer_object')) {
        $adminer = adminer_object();
-} elseif (file_exists("adminer-plugins/")) {
+} elseif (is_dir("adminer-plugins") || file_exists("adminer-plugins.php")) {
        include "./include/plugins.inc.php";
        $adminer = new Plugins(null);
 } else {
index d7d36f5e4e8a289ac7e47e578a4ff7352158aa0d..d5bf15b18bf6d6d967eea24df9d66c4c8d94b58a 100644 (file)
@@ -10,12 +10,16 @@ class Plugins extends Adminer {
        function __construct($plugins) {
                if ($plugins === null) {
                        $plugins = array();
-                       foreach (glob("adminer-plugins/*.php") as $filename) {
-                               $include = include_once "./$filename";
-                               if (is_array($include)) { // example: return array(new AdminerLoginOtp($secret))
-                                       foreach ($include as $plugin) {
-                                               $plugins[get_class($plugin)] = $plugin;
-                                       }
+                       $basename = "adminer-plugins";
+                       if (is_dir($basename)) {
+                               foreach (glob("$basename/*.php") as $filename) {
+                                       $include = include_once "./$filename";
+                               }
+                       }
+                       if (file_exists("$basename.php")) {
+                               $include = include_once "./$basename.php"; // example: return array(new AdminerLoginOtp($secret))
+                               foreach ($include as $plugin) {
+                                       $plugins[get_class($plugin)] = $plugin;
                                }
                        }
                        foreach (get_declared_classes() as $class) {