6 ** This file provides the framework for a plugin architecture.
8 ** Plugins will eventually be a way to provide added functionality
9 ** without having to patch the SquirrelMail source code. Have some
10 ** patience, though, as the these funtions might change in the near
13 ** Documentation on how to write plugins might show up some time.
19 if (defined('plugin_php'))
21 define('plugin_php', true);
23 global $plugin_general_debug, $squirrelmail_plugin_hooks;
24 $plugin_general_debug = false;
26 $squirrelmail_plugin_hooks = array();
28 // This function adds a plugin
29 function use_plugin ($name) {
30 global $plugin_general_debug;
32 if (file_exists('../plugins/'.$name.'/setup.php')) {
33 if ($plugin_general_debug)
34 echo "plugin: -- Loading $name/setup.php<br>\n";
35 include ('../plugins/'.$name.'/setup.php');
36 $function = 'squirrelmail_plugin_init_'.$name;
37 if (function_exists($function))
39 if ($plugin_general_debug)
40 echo "plugin: ---- Executing $function to init plugin<br>\n";
41 $function($plugin_general_debug);
43 elseif ($plugin_general_debug)
44 echo "plugin: -- Init function $function doesn't exist.<br>\n";
46 elseif ($plugin_general_debug)
47 echo "plugin: Couldn't find $name/setup.php<br>\n";
50 // This function executes a hook
51 function do_hook ($name) {
52 global $squirrelmail_plugin_hooks;
53 $Data = func_get_args();
54 if (isset($squirrelmail_plugin_hooks[$name]) &&
55 is_array($squirrelmail_plugin_hooks[$name])) {
56 foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
57 // Add something to set correct gettext domain for plugin
58 if (function_exists($function)) {
64 // Variable-length argument lists have a slight problem when
65 // passing values by reference. Pity. This is a workaround.
69 // On startup, register all plugins configured for use
70 if (isset($plugins) && is_array($plugins))
71 foreach ($plugins as $id => $name)
73 if ($plugin_general_debug)
74 echo "plugin: Attempting load of plugin $name<br>\n";
78 if ($plugin_general_debug)
80 echo "plugin: Hook list<br>\n";
81 foreach ($squirrelmail_plugin_hooks as $Hook => $Plugins)
83 foreach ($Plugins as $Name => $Func)
85 echo "[$Hook][$Name] = $Func<br>\n";