* We now escape properly in strings
[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;
7b086a80 21
22 // This function adds a plugin
23 function use_plugin ($name) {
8bcb6326 24 global $plugin_general_debug;
25
6b638171 26 if (file_exists('../plugins/'.$name.'/setup.php')) {
8bcb6326 27 if ($plugin_general_debug)
28 echo "plugin: -- Loading $name/setup.php<br>\n";
6b638171 29 include ('../plugins/'.$name.'/setup.php');
30 $function = 'squirrelmail_plugin_init_'.$name;
dd389be5 31 if (function_exists($function))
8bcb6326 32 {
33 if ($plugin_general_debug)
34 echo "plugin: ---- Executing $function to init plugin<br>\n";
dd389be5 35 $function();
8bcb6326 36 }
37 elseif ($plugin_general_debug)
38 echo "plugin: -- Init function $function doesn't exist.<br>\n";
6b638171 39 }
8bcb6326 40 elseif ($plugin_general_debug)
41 echo "plugin: Couldn't find $name/setup.php<br>\n";
7b086a80 42 }
43
44 // This function executes a hook
45 function do_hook ($name) {
46 global $squirrelmail_plugin_hooks;
dd389be5 47 $Data = func_get_args();
245a6892 48 if (isset($squirrelmail_plugin_hooks[$name]) &&
49 is_array($squirrelmail_plugin_hooks[$name])) {
dd389be5 50 foreach ($squirrelmail_plugin_hooks[$name] as $id => $function) {
7b086a80 51 // Add something to set correct gettext domain for plugin
dd389be5 52 if (function_exists($function)) {
0e0d9c2f 53 $function($Data);
dd389be5 54 }
7b086a80 55 }
56 }
dd389be5 57
58 // Variable-length argument lists have a slight problem when
59 // passing values by reference. Pity. This is a workaround.
60 return $Data;
61 }
7b086a80 62
63 // On startup, register all plugins configured for use
245a6892 64 if (isset($plugins) && is_array($plugins))
dd389be5 65 foreach ($plugins as $id => $name)
8bcb6326 66 {
67 if ($plugin_general_debug)
68 echo "plugin: Attempting load of plugin $name<br>\n";
c27d5a49 69 use_plugin($name);
8bcb6326 70 }
7b086a80 71
72?>