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