fix bug #481886 with anonymous hint from sourceforge trackers :-)
[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 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;
28 if (function_exists($function)) {
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 }
46 }
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 }
53
54 /* -------------------- MAIN --------------------- */
55
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 }
62
63 ?>