1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
<?php
/**
* plugin.php
*
* This file provides the framework for a plugin architecture.
*
* Documentation on how to write plugins might show up some time.
*
* @copyright 1999-2012 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: plugin.php 14248 2012-01-02 00:18:17Z pdontthink $
* @package squirrelmail
*/
/** Everything needs global.. */
require_once(SM_PATH . 'functions/global.php');
global $squirrelmail_plugin_hooks;
$squirrelmail_plugin_hooks = array();
/**
* This function adds a plugin.
* @param string $name Internal plugin name (ie. delete_move_next)
* @return void
*/
function use_plugin ($name) {
if (file_exists(SM_PATH . "plugins/$name/setup.php")) {
include_once(SM_PATH . "plugins/$name/setup.php");
$function = "squirrelmail_plugin_init_$name";
if (function_exists($function)) {
$function();
}
}
}
/**
* This function executes a hook.
* @param string $name Name of hook to fire
* @return mixed $data
*/
function do_hook ($name) {
global $squirrelmail_plugin_hooks;
$data = func_get_args();
$ret = '';
if (isset($squirrelmail_plugin_hooks[$name])
&& is_array($squirrelmail_plugin_hooks[$name])) {
foreach ($squirrelmail_plugin_hooks[$name] as $function) {
/* Add something to set correct gettext domain for plugin. */
if (function_exists($function)) {
$function($data);
}
}
}
/* Variable-length argument lists have a slight problem when */
/* passing values by reference. Pity. This is a workaround. */
return $data;
}
/**
* This function executes a hook and allows for parameters to be passed.
*
* @param string name the name of the hook
* @param mixed param the parameters to pass to the hook function
* @return mixed the return value of the hook function
*/
function do_hook_function($name,$parm=NULL) {
global $squirrelmail_plugin_hooks;
$ret = '';
if (isset($squirrelmail_plugin_hooks[$name])
&& is_array($squirrelmail_plugin_hooks[$name])) {
foreach ($squirrelmail_plugin_hooks[$name] as $function) {
/* Add something to set correct gettext domain for plugin. */
if (function_exists($function)) {
$ret = $function($parm);
}
}
}
/* Variable-length argument lists have a slight problem when */
/* passing values by reference. Pity. This is a workaround. */
return $ret;
}
/**
* This function executes a hook, concatenating the results of each
* plugin that has the hook defined.
*
* @param string name the name of the hook
* @param mixed parm optional hook function parameters
* @return string a concatenation of the results of each plugin function
*/
function concat_hook_function($name,$parm=NULL) {
global $squirrelmail_plugin_hooks;
$ret = '';
if (isset($squirrelmail_plugin_hooks[$name])
&& is_array($squirrelmail_plugin_hooks[$name])) {
foreach ($squirrelmail_plugin_hooks[$name] as $function) {
/* Concatenate results from hook. */
if (function_exists($function)) {
$ret .= $function($parm);
}
}
}
/* Variable-length argument lists have a slight problem when */
/* passing values by reference. Pity. This is a workaround. */
return $ret;
}
/**
* This function is used for hooks which are to return true or
* false. If $priority is > 0, any one or more trues will override
* any falses. If $priority < 0, then one or more falses will
* override any trues.
* Priority 0 means majority rules. Ties will be broken with $tie
*
* @param string name the hook name
* @param mixed parm the parameters for the hook function
* @param int priority
* @param bool tie
* @return bool the result of the function
*/
function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
global $squirrelmail_plugin_hooks;
$yea = 0;
$nay = 0;
$ret = $tie;
if (isset($squirrelmail_plugin_hooks[$name]) &&
is_array($squirrelmail_plugin_hooks[$name])) {
/* Loop over the plugins that registered the hook */
foreach ($squirrelmail_plugin_hooks[$name] as $function) {
if (function_exists($function)) {
$ret = $function($parm);
if ($ret) {
$yea++;
} else {
$nay++;
}
}
}
/* Examine the aftermath and assign the return value appropriately */
if (($priority > 0) && ($yea)) {
$ret = true;
} elseif (($priority < 0) && ($nay)) {
$ret = false;
} elseif ($yea > $nay) {
$ret = true;
} elseif ($nay > $yea) {
$ret = false;
} else {
// There's a tie, no action needed.
}
return $ret;
}
// If the code gets here, there was a problem - no hooks, etc.
return NULL;
}
/**
* This function checks whether the user's USER_AGENT is known to
* be broken. If so, returns true and the plugin is invisible to the
* offending browser.
* *** THIS IS A TEST FOR JAVASCRIPT SUPPORT ***
* FIXME: This function needs to have its name changed!
*
* @return bool whether this browser properly supports JavaScript
*/
function soupNazi(){
$soup_menu = array('Mozilla/3','Mozilla/2','Mozilla/1', 'Opera 4',
'Opera/4', 'OmniWeb', 'Lynx');
sqgetGlobalVar('HTTP_USER_AGENT', $user_agent, SQ_SERVER);
foreach($soup_menu as $browser) {
if(stristr($user_agent, $browser)) {
return 1;
}
}
return 0;
}
/*************************************/
/*** MAIN PLUGIN LOADING CODE HERE ***/
/*************************************/
/* On startup, register all plugins configured for use.
$plugins needs to be globalized because this file is
sometimes included inside function (non-global) scope,
such as for logout_error. */
global $plugins;
if (isset($plugins) && is_array($plugins)) {
// turn on output buffering in order to prevent output of new lines
ob_start();
foreach ($plugins as $name) {
use_plugin($name);
}
$output = trim(ob_get_contents());
ob_end_clean();
// if plugins output more than newlines and spacing, stop script execution.
if (!empty($output)) {
die($output);
}
}
|