6 * This file provides the framework for a plugin architecture.
8 * Documentation on how to write plugins might show up some time.
10 * @copyright © 1999-2006 The SquirrelMail Project Team
11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * @package squirrelmail
17 * This function adds a plugin.
18 * @param string $name Internal plugin name (ie. delete_move_next)
21 function use_plugin ($name) {
22 if (file_exists(SM_PATH
. "plugins/$name/setup.php")) {
23 include_once(SM_PATH
. "plugins/$name/setup.php");
24 $function = "squirrelmail_plugin_init_$name";
25 if (function_exists($function)) {
32 * This function executes a hook.
33 * @param string $name Name of hook to fire
36 function do_hook ($name) {
37 global $squirrelmail_plugin_hooks, $currentHookName;
38 $data = func_get_args();
39 $currentHookName = $name;
41 if (isset($squirrelmail_plugin_hooks[$name])
42 && is_array($squirrelmail_plugin_hooks[$name])) {
43 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
44 /* Add something to set correct gettext domain for plugin. */
45 if (function_exists($function)) {
51 $currentHookName = '';
53 /* Variable-length argument lists have a slight problem when */
54 /* passing values by reference. Pity. This is a workaround. */
59 * This function executes a hook and allows for parameters to be passed.
61 * @param string name the name of the hook
62 * @param mixed param the parameters to pass to the hook function
63 * @return mixed the return value of the hook function
65 function do_hook_function($name,$parm=NULL) {
66 global $squirrelmail_plugin_hooks, $currentHookName;
68 $currentHookName = $name;
70 if (isset($squirrelmail_plugin_hooks[$name])
71 && is_array($squirrelmail_plugin_hooks[$name])) {
72 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
73 /* Add something to set correct gettext domain for plugin. */
74 if (function_exists($function)) {
75 $ret = $function($parm);
80 $currentHookName = '';
82 /* Variable-length argument lists have a slight problem when */
83 /* passing values by reference. Pity. This is a workaround. */
88 * This function executes a hook, concatenating the results of each
89 * plugin that has the hook defined.
91 * @param string name the name of the hook
92 * @param mixed parm optional hook function parameters
93 * @return string a concatenation of the results of each plugin function
95 function concat_hook_function($name,$parm=NULL) {
96 global $squirrelmail_plugin_hooks, $currentHookName;
98 $currentHookName = $name;
100 if (isset($squirrelmail_plugin_hooks[$name])
101 && is_array($squirrelmail_plugin_hooks[$name])) {
102 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
103 /* Concatenate results from hook. */
104 if (function_exists($function)) {
105 $ret .= $function($parm);
110 $currentHookName = '';
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, $currentHookName;
136 if (isset($squirrelmail_plugin_hooks[$name]) &&
137 is_array($squirrelmail_plugin_hooks[$name])) {
139 /* Loop over the plugins that registered the hook */
140 $currentHookName = $name;
141 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
142 if (function_exists($function)) {
143 $ret = $function($parm);
151 $currentHookName = '';
153 /* Examine the aftermath and assign the return value appropriately */
154 if (($priority > 0) && ($yea)) {
156 } elseif (($priority < 0) && ($nay)) {
158 } elseif ($yea > $nay) {
160 } elseif ($nay > $yea) {
163 // There's a tie, no action needed.
167 // If the code gets here, there was a problem - no hooks, etc.
172 * This function checks whether the user's USER_AGENT is known to
173 * be broken. If so, returns true and the plugin is invisible to the
175 * *** THIS IS A TEST FOR JAVASCRIPT SUPPORT ***
176 * FIXME: This function needs to have its name changed!
178 * @return bool whether this browser properly supports JavaScript
179 * @deprecated use checkForJavascript() since 1.5.1
182 return !checkForJavascript();
186 * Check if plugin is enabled
187 * @param string $plugin_name plugin name
191 function is_plugin_enabled($plugin_name) {
195 * check if variable is empty. if var is not set, php empty
196 * returns true without error notice.
198 * then check if it is an array
200 if (empty($plugins) ||
! is_array($plugins))
203 if ( in_array($plugin_name,$plugins) ) {