]> git.joonet.de Git - adminer.git/commitdiff
Plugins: Handle autoloading errors
authorJakub Vrana <jakub@vrana.cz>
Thu, 20 Mar 2025 10:54:39 +0000 (11:54 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 20 Mar 2025 13:33:17 +0000 (14:33 +0100)
adminer/include/design.inc.php
adminer/include/plugins.inc.php
adminer/lang/cs.inc.php
adminer/lang/xx.inc.php

index b1c3133ed97597758b9783c01421ad92e018539c..d717769b7c37d0e7be03304d8acc51cf76efa8e9 100644 (file)
@@ -170,6 +170,7 @@ function get_nonce() {
 * @return null
 */
 function page_messages($error) {
+       global $adminer;
        $uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
        $messages = $_SESSION["messages"][$uri];
        if ($messages) {
@@ -179,6 +180,9 @@ function page_messages($error) {
        if ($error) {
                echo "<div class='error'>$error</div>\n";
        }
+       if ($adminer->error) { // separate <div>
+               echo "<div class='error'>$adminer->error</div>\n";
+       }
 }
 
 /** Print HTML footer
index dc9cfe2d29f1df8e80f22f86d649f4bed872088f..d1e9fcb5fd6a9bf3f2502299da4333d2c2bcdaf0 100644 (file)
@@ -3,6 +3,7 @@ namespace Adminer;
 
 class Plugins extends Adminer {
        public $plugins; ///< @var protected(set)
+       public $error = ''; ///< @var protected(set)
 
        /** Register plugins
        * @param array object instances or null to autoload plugins from adminer-plugins/
@@ -18,13 +19,23 @@ class Plugins extends Adminer {
                        }
                        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;
+                               if (is_array($include)) {
+                                       foreach ($include as $plugin) {
+                                               $plugins[get_class($plugin)] = $plugin;
+                                       }
+                               } else {
+                                       $this->error .= lang('<b>%s</b> must return an array.', "$basename.php") . "<br>";
                                }
                        }
                        foreach (get_declared_classes() as $class) {
                                if (!$plugins[$class] && preg_match('~^Adminer\w~i', $class)) {
-                                       $plugins[$class] = new $class; // if the constructor have some required parameters then PHP triggers an error here
+                                       $reflection = new \ReflectionClass($class);
+                                       $constructor = $reflection->getConstructor();
+                                       if ($constructor && $constructor->getNumberOfRequiredParameters()) {
+                                               $this->error .= lang('Configure <b>%s</b> in <b>%s</b>.', $class, "$basename.php") . "<br>";
+                                       } else {
+                                               $plugins[$class] = new $class;
+                                       }
                                }
                        }
                }
index 8a760ce368bd3ac5ea559cfd1383d72ff514e887..6ae4cc967b895aa14b9c496f05949f7eae8eb577 100644 (file)
@@ -11,9 +11,11 @@ $translations = array(
        'Login' => 'Přihlásit se',
        'Logout' => 'Odhlásit',
        'Logged as: %s' => 'Přihlášen jako: %s',
-       'Loaded plugins' => 'Nahrané pluginy',
        'Logout successful.' => 'Odhlášení proběhlo v pořádku.',
        'Thanks for using Adminer, consider <a href="https://www.adminer.org/en/donation/">donating</a>.' => 'Díky za použití Admineru, <a href="https://www.adminer.org/cs/donation/">přispějte</a> na vývoj.',
+       'Loaded plugins' => 'Nahrané pluginy',
+       '<b>%s</b> must return an array.' => '<b>%s</b> musí vracet pole.',
+       'Configure <b>%s</b> in <b>%s</b>.' => 'Nakonfigurujte <b>%s</b> v <b>%s</b>.',
        'Invalid credentials.' => 'Neplatné přihlašovací údaje.',
        'There is a space in the input password which might be the cause.' => 'Problém může být, že je v zadaném hesle mezera.',
        'Adminer does not support accessing a database without a password, <a href="https://www.adminer.org/en/password/"%s>more information</a>.' => 'Adminer nepodporuje přístup k databázi bez hesla, <a href="https://www.adminer.org/cs/password/"%s>více informací</a>.',
index d21ab09b4f1c0c6045c0444e6e27c736ea44f966..d0a4b5b563a4ee28f8af3a2fc4e9e1091546a6ea 100644 (file)
@@ -11,9 +11,11 @@ $translations = array(
        'Login' => 'Xx',
        'Logout' => 'Xx',
        'Logged as: %s' => 'Xx: %s',
-       'Loaded plugins' => 'Xx',
        'Logout successful.' => 'Xx.',
        'Thanks for using Adminer, consider <a href="https://www.adminer.org/en/donation/">donating</a>.' => 'Xx <a href="https://www.adminer.org/en/donation/">xx</a>.',
+       'Loaded plugins' => 'Xx',
+       '<b>%s</b> must return an array.' => '<b>%s</b> xx.',
+       'Configure <b>%s</b> in <b>%s</b>.' => 'Xx <b>%s</b> xx <b>%s</b>.',
        'Invalid credentials.' => 'Xx.',
        'There is a space in the input password which might be the cause.' => 'Xx.',
        'Adminer does not support accessing a database without a password, <a href="https://www.adminer.org/en/password/"%s>more information</a>.' => 'Xx, <a href="https://www.adminer.org/en/password/"%s>xx</a>.',