- // This function executes a hook
- function do_hook ($name) {
- global $squirrelmail_plugin_hooks;
- $Data = func_get_args();
- 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);
+ $currentHookName = '';
+
+ /* 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, $currentHookName;
+ $ret = '';
+ $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. */
+ if (function_exists($function)) {
+ $ret .= $function($parm);
+ }
+ }
+ }
+
+ $currentHookName = '';
+
+ /* 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, $currentHookName;
+ $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 */
+ $currentHookName = $name;
+ foreach ($squirrelmail_plugin_hooks[$name] as $function) {
+ if (function_exists($function)) {
+ $ret = $function($parm);
+ if ($ret) {
+ $yea++;
+ } else {
+ $nay++;