From: pdontthink Date: Fri, 22 Sep 2006 03:31:50 +0000 (+0000) Subject: Extensive rework of concat hook function to support merged array return values X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7edd8ad6bee6e1d756ec633ffe502c6a7f64b93b;p=squirrelmail.git Extensive rework of concat hook function to support merged array return values git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11734 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/functions/plugin.php b/functions/plugin.php index 4401a06f..c5b206fe 100644 --- a/functions/plugin.php +++ b/functions/plugin.php @@ -85,24 +85,40 @@ function do_hook_function($name,$parm=NULL) { } /** - * This function executes a hook, concatenating the results of each - * plugin that has the hook defined. + * This function executes a hook, allows for parameters to be passed, + * and looks for an array returned from each plugin: each array is + * then merged into one and returned to the core hook location. + * + * Note that unlike PHP's array_merge function, matching array keys + * will not overwrite each other, instead, values under such keys + * will be concatenated if they are both strings, or merged if they + * are arrays (in the same (non-overwrite) manner recursively). + * + * Plugins returning non-arrays (strings, objects, etc) will have + * their output added to the end of the ultimate return array, + * unless ALL values returned are strings, in which case one string + * with all returned strings concatenated together is returned. * * @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 + * @param mixed param the parameters to pass to the hook function + * + * @return mixed the merged return arrays or strings of each + * plugin on this hook + * */ function concat_hook_function($name,$parm=NULL) { global $squirrelmail_plugin_hooks, $currentHookName; - $ret = ''; +// $ret = ''; + $ret = array(); $currentHookName = $name; if (isset($squirrelmail_plugin_hooks[$name]) && is_array($squirrelmail_plugin_hooks[$name])) { foreach ($squirrelmail_plugin_hooks[$name] as $function) { - /* Concatenate results from hook. */ + /* Add something to set correct gettext domain for plugin. */ if (function_exists($function)) { - $ret .= $function($parm); +// $ret .= $function($parm); + $ret = sq_array_merge($ret, $function($parm)); } } }