From d747d6324d1ffdf835fd11071f6b97d2972f2ba9 Mon Sep 17 00:00:00 2001 From: "Jehan-Guillaume (ioguix) de Rorthais" Date: Fri, 5 Apr 2013 12:54:37 +0200 Subject: [PATCH] Add try/catch blocks around plugin instanciation so they can throw an exception if needed. This is usefull if a plugin don't want to start for some reasons. Throwing an exception from the plugin constructors allows to remove this plugin entirely during the script execution. --- classes/PluginManager.php | 9 +++++++-- libraries/lib.inc.php | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/classes/PluginManager.php b/classes/PluginManager.php index 794f8c7b..33603c75 100644 --- a/classes/PluginManager.php +++ b/classes/PluginManager.php @@ -39,8 +39,13 @@ class PluginManager { // Verify is the activated plugin exists if (file_exists($plugin_file)) { include_once($plugin_file); - $plugin = new $activated_plugin($language); - $this->add_plugin($plugin); + try { + $plugin = new $activated_plugin($language); + $this->add_plugin($plugin); + } + catch (Exception $e) { + continue; + } } else { printf($lang['strpluginnotfound']."\t\n", $activated_plugin); exit; diff --git a/libraries/lib.inc.php b/libraries/lib.inc.php index 99a44f64..0a05f101 100644 --- a/libraries/lib.inc.php +++ b/libraries/lib.inc.php @@ -185,6 +185,9 @@ exit; } + // Manage the plugins + require_once('./classes/PluginManager.php'); + // Create data accessor object, if necessary if (!isset($_no_db_connection)) { if (!isset($_REQUEST['server'])) { @@ -199,6 +202,7 @@ // Redirect to the login form if not logged in if (!isset($_server_info['username'])) { + $plugin_manager = new PluginManager($_language); include('./login.php'); exit; } @@ -232,7 +236,5 @@ } } - // Manage the plugins - require_once('./classes/PluginManager.php'); $plugin_manager = new PluginManager($_language); ?> -- 2.39.5