7b086a80 |
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 |
c27d5a49 |
10 | ** patience, though, as the these funtions might change in the near |
7b086a80 |
11 | ** future. |
12 | ** |
13 | ** Documentation on how to write plugins might show up some time. |
14 | ** |
245a6892 |
15 | ** $Id$ |
7b086a80 |
16 | **/ |
17 | |
18 | |
19 | $plugin_php = true; |
20 | |
21 | // This function adds a plugin |
22 | function use_plugin ($name) { |
6b638171 |
23 | if (file_exists('../plugins/'.$name.'/setup.php')) { |
24 | include ('../plugins/'.$name.'/setup.php'); |
25 | $function = 'squirrelmail_plugin_init_'.$name; |
dd389be5 |
26 | if (function_exists($function)) |
27 | $function(); |
6b638171 |
28 | } |
7b086a80 |
29 | } |
30 | |
31 | // This function executes a hook |
32 | function do_hook ($name) { |
33 | global $squirrelmail_plugin_hooks; |
dd389be5 |
34 | $Data = func_get_args(); |
245a6892 |
35 | if (isset($squirrelmail_plugin_hooks[$name]) && |
36 | is_array($squirrelmail_plugin_hooks[$name])) { |
dd389be5 |
37 | foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) { |
7b086a80 |
38 | // Add something to set correct gettext domain for plugin |
dd389be5 |
39 | if (function_exists($function)) { |
40 | $function(&$Data); |
41 | } |
7b086a80 |
42 | } |
43 | } |
dd389be5 |
44 | |
45 | // Variable-length argument lists have a slight problem when |
46 | // passing values by reference. Pity. This is a workaround. |
47 | return $Data; |
48 | } |
7b086a80 |
49 | |
50 | // On startup, register all plugins configured for use |
245a6892 |
51 | if (isset($plugins) && is_array($plugins)) |
dd389be5 |
52 | foreach ($plugins as $id => $name) |
c27d5a49 |
53 | use_plugin($name); |
7b086a80 |
54 | |
55 | ?> |