block uw mailbox abuse in imap select command instead of applying same
[squirrelmail.git] / functions / plugin.php
index 062021c9cced356c53a89f6c77bd7f33917f68bb..342d2ac428c156d442b2f61f9f6273cc0ee9f605 100644 (file)
@@ -55,6 +55,39 @@ function do_hook ($name) {
     return $data;
 }
 
+/**
+ * This function executes a hook and allows for parameters to be 
+ * passed, wherein each plugin can modify the parameters before 
+ * they are passed to the next funciton. Whether or not the 
+ * parameters are modified, plugins on this hook should always
+ * return the given parameters.
+ *
+ * @param string name the name of the hook
+ * @param mixed param the parameters to pass to the hook function
+ * @return mixed the possibly modified hook parameters
+ */
+function filter_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) {
+            /* Add something to set correct gettext domain for plugin. */
+            if (function_exists($function)) {
+                $parm = $function($parm);
+            }
+        }
+    }
+
+    $currentHookName = '';
+
+    /* Variable-length argument lists have a slight problem when */
+    /* passing values by reference. Pity. This is a workaround.  */
+    return $parm;
+}
+
 /**
  * This function executes a hook and allows for parameters to be passed.
  *
@@ -108,8 +141,7 @@ function do_hook_function($name,$parm=NULL) {
  */
 function concat_hook_function($name,$parm=NULL) {
     global $squirrelmail_plugin_hooks, $currentHookName;
-//    $ret = '';
-    $ret = array();
+    $ret = '';
     $currentHookName = $name;
 
     if (isset($squirrelmail_plugin_hooks[$name])
@@ -117,8 +149,10 @@ function concat_hook_function($name,$parm=NULL) {
         foreach ($squirrelmail_plugin_hooks[$name] as $function) {
             /* Add something to set correct gettext domain for plugin. */
             if (function_exists($function)) {
-//                $ret .= $function($parm);
-                $ret = sqm_array_merge($ret, $function($parm));
+                $plugin_ret = $function($parm);
+                if (!empty($plugin_ret)) {
+                    $ret = sqm_array_merge($ret, $plugin_ret);
+                }
             }
         }
     }