+ // FIXME: note that it is possible for $default to
+ // point to an invalid (nonexistent) template set
+ // and that error will not be caught here
+ //
+ return $default;
+
+ }
+
+ /**
+ * Allow template set to override plugin configuration by either
+ * adding or removing plugins.
+ *
+ * NOTE: due to when this code executes, plugins activated here
+ * do not have access to the config_override and loading_prefs
+ * hooks; instead, such plugins can use the
+ * "template_plugins_override_after" hook defined below.
+ *
+ */
+ function override_plugins() {
+
+ global $disable_plugins, $plugins, $squirrelmail_plugin_hooks, $null;
+ 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_<plugin_name>" 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]);
+ }
+ }
+ }
+
+ do_hook('template_plugins_override_after', $null);