4b86b769824c00d8d8f76abce5745e87025edab4
[squirrelmail.git] / functions / plugin.php
1 <?php
2
3 /**
4 ** plugin.php
5 **
6 ** This file provides the framework for a plugin architecture.
7 **
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
11 ** future.
12 **
13 ** Documentation on how to write plugins might show up some time.
14 **
15 ** $Id$
16 **/
17
18
19 $plugin_php = true;
20 $plugin_general_debug = false;
21
22 // This function adds a plugin
23 function use_plugin ($name) {
24 global $plugin_general_debug;
25
26 if (file_exists('../plugins/'.$name.'/setup.php')) {
27 if ($plugin_general_debug)
28 echo "plugin: -- Loading $name/setup.php<br>\n";
29 include ('../plugins/'.$name.'/setup.php');
30 $function = 'squirrelmail_plugin_init_'.$name;
31 if (function_exists($function))
32 {
33 if ($plugin_general_debug)
34 echo "plugin: ---- Executing $function to init plugin<br>\n";
35 $function();
36 }
37 elseif ($plugin_general_debug)
38 echo "plugin: -- Init function $function doesn't exist.<br>\n";
39 }
40 elseif ($plugin_general_debug)
41 echo "plugin: Couldn't find $name/setup.php<br>\n";
42 }
43
44 // This function executes a hook
45 function do_hook ($name) {
46 global $squirrelmail_plugin_hooks;
47 $Data = func_get_args();
48 if (isset($squirrelmail_plugin_hooks[$name]) &&
49 is_array($squirrelmail_plugin_hooks[$name])) {
50 foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
51 // Add something to set correct gettext domain for plugin
52 if (function_exists($function)) {
53 $function($Data);
54 }
55 }
56 }
57
58 // Variable-length argument lists have a slight problem when
59 // passing values by reference. Pity. This is a workaround.
60 return $Data;
61 }
62
63 // On startup, register all plugins configured for use
64 if (isset($plugins) && is_array($plugins))
65 foreach ($plugins as $id => $name)
66 {
67 if ($plugin_general_debug)
68 echo "plugin: Attempting load of plugin $name<br>\n";
69 use_plugin($name);
70 }
71
72 ?>