From 0db60ced010cea3a14b2b3fc225692e5f2d6a272 Mon Sep 17 00:00:00 2001 From: pdontthink Date: Wed, 3 Jan 2007 20:33:11 +0000 Subject: [PATCH] Fix for unknown index notices caused in templates when looking for plugin output in what was an empty string instead of an empty array git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12057 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- class/template/Template.class.php | 11 +++-------- functions/plugin.php | 31 ++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/class/template/Template.class.php b/class/template/Template.class.php index 08c0cc61..c43e04ae 100644 --- a/class/template/Template.class.php +++ b/class/template/Template.class.php @@ -1410,14 +1410,9 @@ FIXME: We could make the incoming array more complex so it can } else { $aPluginOutput = array(); - // At this moment concat_hook_function can return string and arrays. - // In php 4.3.x a notice will be raised when a string is passed as $aPluginOutput - // TODO, only return an arrays by concat_hook_function. - $mixedOutput = concat_hook_function('template_construct_' . $file, - $temp=array(&$aPluginOutput, &$this)); - if (is_array($mixedOutput)) { - $aPluginOutput = $mixedOutput; - } + $aPluginOutput = concat_hook_function('template_construct_' . $file, + $temp=array(&$aPluginOutput, &$this), + TRUE); $this->assign('plugin_output', $aPluginOutput); //$output = $this->apply_template($template); diff --git a/functions/plugin.php b/functions/plugin.php index 9e155e6e..74ddbea1 100644 --- a/functions/plugin.php +++ b/functions/plugin.php @@ -104,7 +104,8 @@ function do_hook($name, &$args) { * 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. + * with all returned strings concatenated together is returned + * (unless $force_array is TRUE). * * If any plugin on this hook wants to modify the $args * plugin parameter, it simply has to use call-by-reference @@ -112,19 +113,27 @@ function do_hook($name, &$args) { * current hook. Note that this is in addition to (entirely * independent of) the return value for this hook. * - * @param string $name Name of hook being executed - * @param mixed $args A single value or an array of arguments - * that are to be passed to all plugins - * operating off the hook being called. - * Note that this argument is passed by - * reference thus it is liable to be - * changed after the hook completes. + * @param string $name Name of hook being executed + * @param mixed $args A single value or an array of arguments + * that are to be passed to all plugins + * operating off the hook being called. + * Note that this argument is passed by + * reference thus it is liable to be + * changed after the hook completes. + * @param boolean $force_array When TRUE, guarantees the return + * value will ALWAYS be an array, + * (simple strings will be forced + * into a one-element array). + * When FALSE, behavior is as + * described above (OPTIONAL; + * default behavior is to return + * mixed - array or string). * * @return mixed the merged return arrays or strings of each * plugin on this hook. * */ -function concat_hook_function($name, &$args) { +function concat_hook_function($name, &$args, $force_array=FALSE) { global $squirrelmail_plugin_hooks, $currentHookName; $currentHookName = $name; @@ -143,6 +152,10 @@ function concat_hook_function($name, &$args) { } } + if ($force_array && is_string($ret)) { + $ret = array($ret); + } + $currentHookName = ''; return $ret; -- 2.25.1