7b086a80 |
1 | <?php |
2 | |
2ba13803 |
3 | /** |
4 | ** plugin.php |
2d367c68 |
5 | ** |
2ba13803 |
6 | ** Copyright (c) 1999-2001 The Squirrelmail Development Team |
7 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
2d367c68 |
8 | ** |
2ba13803 |
9 | ** This file provides the framework for a plugin architecture. |
2d367c68 |
10 | ** |
2ba13803 |
11 | ** Documentation on how to write plugins might show up some time. |
2d367c68 |
12 | ** |
2ba13803 |
13 | ** $Id$ |
2d367c68 |
14 | **/ |
15 | |
16 | global $squirrelmail_plugin_hooks; |
17 | |
18 | $squirrelmail_plugin_hooks = array(); |
19 | |
20 | // This function adds a plugin |
21 | function use_plugin ($name) { |
22 | |
23 | if (file_exists('../plugins/'.$name.'/setup.php')) { |
24 | include_once('../plugins/'.$name.'/setup.php'); |
25 | $function = 'squirrelmail_plugin_init_'.$name; |
dd389be5 |
26 | if (function_exists($function)) { |
2d367c68 |
27 | $function(); |
28 | } |
29 | } |
30 | |
31 | } |
32 | |
33 | // This function executes a hook |
34 | function do_hook ($name) { |
35 | global $squirrelmail_plugin_hooks; |
36 | $Data = func_get_args(); |
37 | if (isset($squirrelmail_plugin_hooks[$name]) && |
38 | is_array($squirrelmail_plugin_hooks[$name])) { |
39 | foreach ($squirrelmail_plugin_hooks[$name] as $function) { |
40 | // Add something to set correct gettext domain for plugin |
41 | if (function_exists($function)) { |
42 | $function($Data); |
43 | } |
dd389be5 |
44 | } |
2d367c68 |
45 | } |
46 | |
47 | // Variable-length argument lists have a slight problem when |
48 | // passing values by reference. Pity. This is a workaround. |
49 | return $Data; |
50 | } |
7b086a80 |
51 | |
2d367c68 |
52 | /* -------------------- MAIN --------------------- */ |
7b086a80 |
53 | |
2d367c68 |
54 | // On startup, register all plugins configured for use |
55 | if (isset($plugins) && is_array($plugins)) { |
56 | foreach ($plugins as $name) { |
57 | use_plugin($name); |
58 | } |
59 | } |
076c01d7 |
60 | |
0fc2aca0 |
61 | ?> |