From: pdontthink Date: Tue, 12 Dec 2006 10:43:00 +0000 (+0000) Subject: Allow template sets to override plugin configuration. See config file in template... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=34904996deedab3892735357340ff202c0d30fa2;p=squirrelmail.git Allow template sets to override plugin configuration. See config file in template directories. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12008 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/template/Template.class.php b/class/template/Template.class.php index 1f4a6d7d..4853ea88 100644 --- a/class/template/Template.class.php +++ b/class/template/Template.class.php @@ -157,6 +157,7 @@ class Template function construct_template($template_set_id) { $template = new Template($template_set_id); + $template->override_plugins(); return $template->get_template_engine_subclass(); } @@ -306,6 +307,72 @@ class Template } + /** + * Allow template set to override plugin configuration by either + * adding or removing plugins. + * + */ + function override_plugins() { + + global $disable_plugins, $plugins, $squirrelmail_plugin_hooks; + if ($disable_plugins) return; + + $add_plugins = Template::get_template_config($this->template_set_id, + 'add_plugins', array()); + $remove_plugins = Template::get_template_config($this->template_set_id, + 'remove_plugins', array()); + +//FIXME (?) we assume $add_plugins and $remove_plugins are arrays -- we could +// error check here, or just assume that template authors or admins +// won't screw up their config files + + + // disable all plugins? (can still add some by using $add_plugins) + // + if (in_array('*', $remove_plugins)) { + $plugins = array(); + $squirrelmail_plugin_hooks = array(); + $remove_plugins = array(); + } + + + foreach ($add_plugins as $plugin_name) { + // add plugin to global plugin array + // + $plugins[] = $plugin_name; + + + // enable plugin -- emulate code from use_plugin() function + // in SquirrelMail core, but also need to call the + // "squirrelmail_plugin_init_" function, which + // in static configuration is not called (this inconsistency + // could be a source of anomalous-seeming bugs in poorly + // coded plugins) + // + if (file_exists(SM_PATH . "plugins/$plugin_name/setup.php")) { + include_once(SM_PATH . "plugins/$plugin_name/setup.php"); + + $function = "squirrelmail_plugin_init_$plugin_name"; + if (function_exists($function)) + $function(); + } + } + + foreach ($remove_plugins as $plugin_name) { + // remove plugin from both global plugin & plugin hook arrays + // + $plugin_key = array_search($plugin_name, $plugins); + if (!is_null($plugin_key) && $plugin_key !== FALSE) { + unset($plugins[$plugin_key]); + if (is_array($squirrelmail_plugin_hooks)) + foreach (array_keys($squirrelmail_plugin_hooks) as $hookName) { + unset($squirrelmail_plugin_hooks[$hookName][$plugin_name]); + } + } + } + + } + /** * Instantiate and return correct subclass for this template * set's templating engine. diff --git a/templates/default/config.php b/templates/default/config.php index 2384aa4f..e4e668f5 100644 --- a/templates/default/config.php +++ b/templates/default/config.php @@ -32,3 +32,14 @@ $template_engine = SQ_PHP_TEMPLATE; $parent_template_set = ''; +/** + * These settings allow this template set to change SquirrelMail's + * list of active plugins by adding or removing any of those listed + * herein. If the $remove_plugins list contains "*", then ALL plugins + * will be disabled, and only those in $add_plugins will be enabled. + * + */ +$add_plugins = array(); +$remove_plugins = array(); + + diff --git a/templates/default_advanced/config.php b/templates/default_advanced/config.php index e2108d7f..9e8a3db0 100644 --- a/templates/default_advanced/config.php +++ b/templates/default_advanced/config.php @@ -32,3 +32,14 @@ $template_engine = SQ_PHP_TEMPLATE; $parent_template_set = 'default'; +/** + * These settings allow this template set to change SquirrelMail's + * list of active plugins by adding or removing any of those listed + * herein. If the $remove_plugins list contains "*", then ALL plugins + * will be disabled, and only those in $add_plugins will be enabled. + * + */ +$add_plugins = array(); +$remove_plugins = array(); + +