6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file provides the framework for a plugin architecture.
11 * Documentation on how to write plugins might show up some time.
14 * @package squirrelmail
17 /** Everything needs global.. */
18 require_once(SM_PATH
. 'functions/global.php');
19 require_once(SM_PATH
. 'functions/prefs.php');
21 global $squirrelmail_plugin_hooks;
22 $squirrelmail_plugin_hooks = array();
25 * This function adds a plugin.
26 * @param string $name Internal plugin name (ie. delete_move_next)
29 function use_plugin ($name) {
30 if (file_exists(SM_PATH
. "plugins/$name/setup.php")) {
31 include_once(SM_PATH
. "plugins/$name/setup.php");
32 $function = "squirrelmail_plugin_init_$name";
33 if (function_exists($function)) {
40 * This function executes a hook.
41 * @param string $name Name of hook to fire
44 function do_hook ($name) {
45 global $squirrelmail_plugin_hooks;
46 $data = func_get_args();
49 if (isset($squirrelmail_plugin_hooks[$name])
50 && is_array($squirrelmail_plugin_hooks[$name])) {
51 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
52 /* Add something to set correct gettext domain for plugin. */
53 if (function_exists($function)) {
59 /* Variable-length argument lists have a slight problem when */
60 /* passing values by reference. Pity. This is a workaround. */
65 * This function executes a hook and allows for parameters to be passed.
67 * @param string name the name of the hook
68 * @param mixed param the parameters to pass to the hook function
69 * @return mixed the return value of the hook function
71 function do_hook_function($name,$parm=NULL) {
72 global $squirrelmail_plugin_hooks;
75 if (isset($squirrelmail_plugin_hooks[$name])
76 && is_array($squirrelmail_plugin_hooks[$name])) {
77 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
78 /* Add something to set correct gettext domain for plugin. */
79 if (function_exists($function)) {
80 $ret = $function($parm);
85 /* Variable-length argument lists have a slight problem when */
86 /* passing values by reference. Pity. This is a workaround. */
91 * This function executes a hook, concatenating the results of each
92 * plugin that has the hook defined.
94 * @param string name the name of the hook
95 * @param mixed parm optional hook function parameters
96 * @return string a concatenation of the results of each plugin function
98 function concat_hook_function($name,$parm=NULL) {
99 global $squirrelmail_plugin_hooks;
102 if (isset($squirrelmail_plugin_hooks[$name])
103 && is_array($squirrelmail_plugin_hooks[$name])) {
104 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
105 /* Concatenate results from hook. */
106 if (function_exists($function)) {
107 $ret .= $function($parm);
112 /* Variable-length argument lists have a slight problem when */
113 /* passing values by reference. Pity. This is a workaround. */
118 * This function is used for hooks which are to return true or
119 * false. If $priority is > 0, any one or more trues will override
120 * any falses. If $priority < 0, then one or more falses will
121 * override any trues.
122 * Priority 0 means majority rules. Ties will be broken with $tie
124 * @param string name the hook name
125 * @param mixed parm the parameters for the hook function
126 * @param int priority
128 * @return bool the result of the function
130 function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
131 global $squirrelmail_plugin_hooks;
136 if (isset($squirrelmail_plugin_hooks[$name]) &&
137 is_array($squirrelmail_plugin_hooks[$name])) {
139 /* Loop over the plugins that registered the hook */
140 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
141 if (function_exists($function)) {
142 $ret = $function($parm);
151 /* Examine the aftermath and assign the return value appropriately */
152 if (($priority > 0) && ($yea)) {
154 } elseif (($priority < 0) && ($nay)) {
156 } elseif ($yea > $nay) {
158 } elseif ($nay > $yea) {
161 // There's a tie, no action needed.
165 // If the code gets here, there was a problem - no hooks, etc.
170 * This function checks whether the user's USER_AGENT is known to
171 * be broken. If so, returns true and the plugin is invisible to the
173 * *** THIS IS A TEST FOR JAVASCRIPT SUPPORT ***
174 * This function needs to have its name changed!
176 * @return bool whether this browser properly supports JavaScript
179 return !checkForJavascript();
181 /*************************************/
182 /*** MAIN PLUGIN LOADING CODE HERE ***/
183 /*************************************/
185 /* On startup, register all plugins configured for use. */
186 if (isset($plugins) && is_array($plugins)) {
187 foreach ($plugins as $name) {