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');
20 global $squirrelmail_plugin_hooks;
21 $squirrelmail_plugin_hooks = array();
24 * This function adds a plugin.
25 * @param string $name Internal plugin name (ie. delete_move_next)
28 function use_plugin ($name) {
29 if (file_exists(SM_PATH
. "plugins/$name/setup.php")) {
30 include_once(SM_PATH
. "plugins/$name/setup.php");
31 $function = "squirrelmail_plugin_init_$name";
32 if (function_exists($function)) {
39 * This function executes a hook.
40 * @param string $name Name of hook to fire
43 function do_hook ($name) {
44 global $squirrelmail_plugin_hooks;
45 $data = func_get_args();
48 if (isset($squirrelmail_plugin_hooks[$name])
49 && is_array($squirrelmail_plugin_hooks[$name])) {
50 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
51 /* Add something to set correct gettext domain for plugin. */
52 if (function_exists($function)) {
58 /* Variable-length argument lists have a slight problem when */
59 /* passing values by reference. Pity. This is a workaround. */
64 * This function executes a hook and allows for parameters to be passed.
66 * @param string name the name of the hook
67 * @param mixed param the parameters to pass to the hook function
68 * @return mixed the return value of the hook function
70 function do_hook_function($name,$parm=NULL) {
71 global $squirrelmail_plugin_hooks;
74 if (isset($squirrelmail_plugin_hooks[$name])
75 && is_array($squirrelmail_plugin_hooks[$name])) {
76 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
77 /* Add something to set correct gettext domain for plugin. */
78 if (function_exists($function)) {
79 $ret = $function($parm);
84 /* Variable-length argument lists have a slight problem when */
85 /* passing values by reference. Pity. This is a workaround. */
90 * This function executes a hook, concatenating the results of each
91 * plugin that has the hook defined.
93 * @param string name the name of the hook
94 * @param mixed parm optional hook function parameters
95 * @return string a concatenation of the results of each plugin function
97 function concat_hook_function($name,$parm=NULL) {
98 global $squirrelmail_plugin_hooks;
101 if (isset($squirrelmail_plugin_hooks[$name])
102 && is_array($squirrelmail_plugin_hooks[$name])) {
103 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
104 /* Concatenate results from hook. */
105 if (function_exists($function)) {
106 $ret .= $function($parm);
111 /* Variable-length argument lists have a slight problem when */
112 /* passing values by reference. Pity. This is a workaround. */
117 * This function is used for hooks which are to return true or
118 * false. If $priority is > 0, any one or more trues will override
119 * any falses. If $priority < 0, then one or more falses will
120 * override any trues.
121 * Priority 0 means majority rules. Ties will be broken with $tie
123 * @param string name the hook name
124 * @param mixed parm the parameters for the hook function
125 * @param int priority
127 * @return bool the result of the function
129 function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
130 global $squirrelmail_plugin_hooks;
135 if (isset($squirrelmail_plugin_hooks[$name]) &&
136 is_array($squirrelmail_plugin_hooks[$name])) {
138 /* Loop over the plugins that registered the hook */
139 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
140 if (function_exists($function)) {
141 $ret = $function($parm);
150 /* Examine the aftermath and assign the return value appropriately */
151 if (($priority > 0) && ($yea)) {
153 } elseif (($priority < 0) && ($nay)) {
155 } elseif ($yea > $nay) {
157 } elseif ($nay > $yea) {
160 // There's a tie, no action needed.
164 // If the code gets here, there was a problem - no hooks, etc.
169 * This function checks whether the user's USER_AGENT is known to
170 * be broken. If so, returns true and the plugin is invisible to the
172 * This function needs to have its name changed!
174 * @return bool whether this browser properly supports JavaScript
178 $soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
179 'Opera/4', 'OmniWeb', 'Lynx');
180 sqgetGlobalVar('HTTP_USER_AGENT', $user_agent, SQ_SERVER
);
181 foreach($soup_menu as $browser) {
182 if(stristr($user_agent, $browser)) {
188 /*************************************/
189 /*** MAIN PLUGIN LOADING CODE HERE ***/
190 /*************************************/
192 /* On startup, register all plugins configured for use. */
193 if (isset($plugins) && is_array($plugins)) {
194 foreach ($plugins as $name) {