浏览代码

Allow template sets to override plugin configuration. See config file in template directories.

pdontthink 18 年之前
父节点
当前提交
c047501dc9
共有 3 个文件被更改,包括 89 次插入0 次删除
  1. 67 0
      class/template/Template.class.php
  2. 11 0
      templates/default/config.php
  3. 11 0
      templates/default_advanced/config.php

+ 67 - 0
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_<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]);
+                    }
+            }
+        }
+
+    }
+
     /**
       * Instantiate and return correct subclass for this template
       * set's templating engine.

+ 11 - 0
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();
+
+

+ 11 - 0
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();
+
+