phase 1 of interface improvements -- alternating row colors (needs some work)
[squirrelmail.git] / functions / plugin.php
CommitLineData
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;
8bcb6326 20 $plugin_general_debug = false;
51a79892 21
22 $squirrelmail_plugin_hooks = array();
7b086a80 23
24 // This function adds a plugin
25 function use_plugin ($name) {
8bcb6326 26 global $plugin_general_debug;
27
6b638171 28 if (file_exists('../plugins/'.$name.'/setup.php')) {
8bcb6326 29 if ($plugin_general_debug)
30 echo "plugin: -- Loading $name/setup.php<br>\n";
6b638171 31 include ('../plugins/'.$name.'/setup.php');
32 $function = 'squirrelmail_plugin_init_'.$name;
dd389be5 33 if (function_exists($function))
8bcb6326 34 {
35 if ($plugin_general_debug)
36 echo "plugin: ---- Executing $function to init plugin<br>\n";
f191a7da 37 $function($plugin_general_debug);
8bcb6326 38 }
39 elseif ($plugin_general_debug)
40 echo "plugin: -- Init function $function doesn't exist.<br>\n";
6b638171 41 }
8bcb6326 42 elseif ($plugin_general_debug)
43 echo "plugin: Couldn't find $name/setup.php<br>\n";
7b086a80 44 }
45
46 // This function executes a hook
47 function do_hook ($name) {
48 global $squirrelmail_plugin_hooks;
dd389be5 49 $Data = func_get_args();
245a6892 50 if (isset($squirrelmail_plugin_hooks[$name]) &&
51 is_array($squirrelmail_plugin_hooks[$name])) {
dd389be5 52 foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
7b086a80 53 // Add something to set correct gettext domain for plugin
dd389be5 54 if (function_exists($function)) {
0e0d9c2f 55 $function($Data);
dd389be5 56 }
7b086a80 57 }
58 }
dd389be5 59
60 // Variable-length argument lists have a slight problem when
61 // passing values by reference. Pity. This is a workaround.
62 return $Data;
63 }
7b086a80 64
65 // On startup, register all plugins configured for use
245a6892 66 if (isset($plugins) && is_array($plugins))
dd389be5 67 foreach ($plugins as $id => $name)
8bcb6326 68 {
69 if ($plugin_general_debug)
70 echo "plugin: Attempting load of plugin $name<br>\n";
c27d5a49 71 use_plugin($name);
8bcb6326 72 }
7b086a80 73
076c01d7 74 if ($plugin_general_debug)
75 {
076c01d7 76 echo "plugin: Hook list<br>\n";
77 foreach ($squirrelmail_plugin_hooks as $Hook => $Plugins)
78 {
79 foreach ($Plugins as $Name => $Func)
80 {
81 echo "[$Hook][$Name] = $Func<br>\n";
82 }
83 }
84 }
85
7b086a80 86?>