7b086a80 |
1 | <?php |
2 | |
2d367c68 |
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 | global $squirrelmail_plugin_hooks; |
19 | |
20 | $squirrelmail_plugin_hooks = array(); |
21 | |
22 | // This function adds a plugin |
23 | function use_plugin ($name) { |
24 | |
25 | if (file_exists('../plugins/'.$name.'/setup.php')) { |
26 | include_once('../plugins/'.$name.'/setup.php'); |
27 | $function = 'squirrelmail_plugin_init_'.$name; |
dd389be5 |
28 | if (function_exists($function)) { |
2d367c68 |
29 | $function(); |
30 | } |
31 | } |
32 | |
33 | } |
34 | |
35 | // This function executes a hook |
36 | function do_hook ($name) { |
37 | global $squirrelmail_plugin_hooks; |
38 | $Data = func_get_args(); |
39 | if (isset($squirrelmail_plugin_hooks[$name]) && |
40 | is_array($squirrelmail_plugin_hooks[$name])) { |
41 | foreach ($squirrelmail_plugin_hooks[$name] as $function) { |
42 | // Add something to set correct gettext domain for plugin |
43 | if (function_exists($function)) { |
44 | $function($Data); |
45 | } |
dd389be5 |
46 | } |
2d367c68 |
47 | } |
48 | |
49 | // Variable-length argument lists have a slight problem when |
50 | // passing values by reference. Pity. This is a workaround. |
51 | return $Data; |
52 | } |
7b086a80 |
53 | |
2d367c68 |
54 | /* -------------------- MAIN --------------------- */ |
7b086a80 |
55 | |
2d367c68 |
56 | // On startup, register all plugins configured for use |
57 | if (isset($plugins) && is_array($plugins)) { |
58 | foreach ($plugins as $name) { |
59 | use_plugin($name); |
60 | } |
61 | } |
076c01d7 |
62 | |
0fc2aca0 |
63 | ?> |