6 * Copyright (c) 1999-2003 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. */
63 /* This function executes a hook. */
64 function do_hook_function($name,$parm=NULL) {
65 global $squirrelmail_plugin_hooks;
68 if (isset($squirrelmail_plugin_hooks[$name])
69 && is_array($squirrelmail_plugin_hooks[$name])) {
70 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
71 /* Add something to set correct gettext domain for plugin. */
72 if (function_exists($function)) {
73 $ret = $function($parm);
78 /* Variable-length argument lists have a slight problem when */
79 /* passing values by reference. Pity. This is a workaround. */
83 /* This function executes a hook. */
84 function concat_hook_function($name,$parm=NULL) {
85 global $squirrelmail_plugin_hooks;
88 if (isset($squirrelmail_plugin_hooks[$name])
89 && is_array($squirrelmail_plugin_hooks[$name])) {
90 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
91 /* Concatenate results from hook. */
92 if (function_exists($function)) {
93 $ret .= $function($parm);
98 /* Variable-length argument lists have a slight problem when */
99 /* passing values by reference. Pity. This is a workaround. */
104 * This function is used for hooks which are to return true or
105 * false. If $priority is > 0, any one or more trues will override
106 * any falses. If $priority < 0, then one or more falses will
107 * override any trues.
108 * Priority 0 means majority rules. Ties will be broken with $tie */
109 function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
110 global $squirrelmail_plugin_hooks;
115 if (isset($squirrelmail_plugin_hooks[$name]) &&
116 is_array($squirrelmail_plugin_hooks[$name])) {
118 /* Loop over the plugins that registered the hook */
119 foreach ($squirrelmail_plugin_hooks[$name] as $function) {
120 if (function_exists($function)) {
121 $ret = $function($parm);
130 /* Examine the aftermath and assign the return value appropriately */
131 if (($priority > 0) && ($yea)) {
133 } elseif (($priority < 0) && ($nay)) {
135 } elseif ($yea > $nay) {
137 } elseif ($nay > $yea) {
140 // There's a tie, no action needed.
144 // If the code gets here, there was a problem - no hooks, etc.
149 * This function checks whether the user's USER_AGENT is known to
150 * be broken. If so, returns true and the plugin is invisible to the
155 $soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
156 'Opera/4', 'OmniWeb', 'Lynx');
157 sqgetGlobalVar('HTTP_USER_AGENT', $user_agent, SQ_SERVER
);
158 foreach($soup_menu as $browser) {
159 if(stristr($user_agent, $browser)) {
165 /*************************************/
166 /*** MAIN PLUGIN LOADING CODE HERE ***/
167 /*************************************/
169 /* On startup, register all plugins configured for use. */
170 if (isset($plugins) && is_array($plugins)) {
171 foreach ($plugins as $name) {