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

Plugins: Handle autoloading errors

This commit is contained in:
Jakub Vrana
2025-03-20 11:54:39 +01:00
parent cd686c7a1e
commit bcd5164e2f
4 changed files with 24 additions and 5 deletions

View File

@@ -170,6 +170,7 @@ function get_nonce() {
* @return null * @return null
*/ */
function page_messages($error) { function page_messages($error) {
global $adminer;
$uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]); $uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
$messages = $_SESSION["messages"][$uri]; $messages = $_SESSION["messages"][$uri];
if ($messages) { if ($messages) {
@@ -179,6 +180,9 @@ function page_messages($error) {
if ($error) { if ($error) {
echo "<div class='error'>$error</div>\n"; echo "<div class='error'>$error</div>\n";
} }
if ($adminer->error) { // separate <div>
echo "<div class='error'>$adminer->error</div>\n";
}
} }
/** Print HTML footer /** Print HTML footer

View File

@@ -3,6 +3,7 @@ namespace Adminer;
class Plugins extends Adminer { class Plugins extends Adminer {
public $plugins; ///< @var protected(set) public $plugins; ///< @var protected(set)
public $error = ''; ///< @var protected(set)
/** Register plugins /** Register plugins
* @param array object instances or null to autoload plugins from adminer-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")) { if (file_exists("$basename.php")) {
$include = include_once "./$basename.php"; // example: return array(new AdminerLoginOtp($secret)) $include = include_once "./$basename.php"; // example: return array(new AdminerLoginOtp($secret))
foreach ($include as $plugin) { if (is_array($include)) {
$plugins[get_class($plugin)] = $plugin; 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) { foreach (get_declared_classes() as $class) {
if (!$plugins[$class] && preg_match('~^Adminer\w~i', $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;
}
} }
} }
} }

View File

@@ -11,9 +11,11 @@ $translations = array(
'Login' => 'Přihlásit se', 'Login' => 'Přihlásit se',
'Logout' => 'Odhlásit', 'Logout' => 'Odhlásit',
'Logged as: %s' => 'Přihlášen jako: %s', 'Logged as: %s' => 'Přihlášen jako: %s',
'Loaded plugins' => 'Nahrané pluginy',
'Logout successful.' => 'Odhlášení proběhlo v pořádku.', '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.', '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.', '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.', '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>.', '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>.',

View File

@@ -11,9 +11,11 @@ $translations = array(
'Login' => 'Xx', 'Login' => 'Xx',
'Logout' => 'Xx', 'Logout' => 'Xx',
'Logged as: %s' => 'Xx: %s', 'Logged as: %s' => 'Xx: %s',
'Loaded plugins' => 'Xx',
'Logout successful.' => '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>.', '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.', 'Invalid credentials.' => 'Xx.',
'There is a space in the input password which might be the cause.' => '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>.', '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>.',