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.
20 $plugin_general_debug = false;
22 $squirrelmail_plugin_hooks = array();
24 // This function adds a plugin
25 function use_plugin ($name) {
26 global $plugin_general_debug;
28 if (file_exists('../plugins/'.$name.'/setup.php')) {
29 if ($plugin_general_debug)
30 echo "plugin: -- Loading $name/setup.php<br>\n";
31 include ('../plugins/'.$name.'/setup.php');
32 $function = 'squirrelmail_plugin_init_'.$name;
33 if (function_exists($function))
35 if ($plugin_general_debug)
36 echo "plugin: ---- Executing $function to init plugin<br>\n";
37 $function($plugin_general_debug);
39 elseif ($plugin_general_debug)
40 echo "plugin: -- Init function $function doesn't exist.<br>\n";
42 elseif ($plugin_general_debug)
43 echo "plugin: Couldn't find $name/setup.php<br>\n";
46 // This function executes a hook
47 function do_hook ($name) {
48 global $squirrelmail_plugin_hooks;
49 $Data = func_get_args();
50 if (isset($squirrelmail_plugin_hooks[$name]) &&
51 is_array($squirrelmail_plugin_hooks[$name])) {
52 foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
53 // Add something to set correct gettext domain for plugin
54 if (function_exists($function)) {
60 // Variable-length argument lists have a slight problem when
61 // passing values by reference. Pity. This is a workaround.
65 // On startup, register all plugins configured for use
66 if (isset($plugins) && is_array($plugins))
67 foreach ($plugins as $id => $name)
69 if ($plugin_general_debug)
70 echo "plugin: Attempting load of plugin $name<br>\n";
74 if ($plugin_general_debug)
76 echo "plugin: Hook list<br>\n";
77 foreach ($squirrelmail_plugin_hooks as $Hook => $Plugins)
79 foreach ($Plugins as $Name => $Func)
81 echo "[$Hook][$Name] = $Func<br>\n";