Przeglądaj źródła

Make current hook name globally available when running a hook

pdontthink 21 lat temu
rodzic
commit
adb48be6a4
2 zmienionych plików z 17 dodań i 5 usunięć
  1. 1 0
      ChangeLog
  2. 16 5
      functions/plugin.php

+ 1 - 0
ChangeLog

@@ -75,6 +75,7 @@ Version 1.5.1 -- CVS
   - Custom option page values now repopulate correctly
   - Custom option page values now repopulate correctly
   - Added "no focus" option for compose page in display preferences (setting
   - Added "no focus" option for compose page in display preferences (setting
     reply focus to "No focus" also affects composing new messages)
     reply focus to "No focus" also affects composing new messages)
+  - Current hook name is now globally available when running a hook ($currentHookName)
 
 
 Version 1.5.0
 Version 1.5.0
 --------------------
 --------------------

+ 16 - 5
functions/plugin.php

@@ -42,9 +42,10 @@ function use_plugin ($name) {
  * @return mixed $data
  * @return mixed $data
  */
  */
 function do_hook ($name) {
 function do_hook ($name) {
-    global $squirrelmail_plugin_hooks;
+    global $squirrelmail_plugin_hooks, $currentHookName;
     $data = func_get_args();
     $data = func_get_args();
     $ret = '';
     $ret = '';
+    $currentHookName = $name;
 
 
     if (isset($squirrelmail_plugin_hooks[$name])
     if (isset($squirrelmail_plugin_hooks[$name])
           && is_array($squirrelmail_plugin_hooks[$name])) {
           && is_array($squirrelmail_plugin_hooks[$name])) {
@@ -56,6 +57,8 @@ function do_hook ($name) {
         }
         }
     }
     }
 
 
+    $currentHookName = '';
+
     /* Variable-length argument lists have a slight problem when */
     /* Variable-length argument lists have a slight problem when */
     /* passing values by reference. Pity. This is a workaround.  */
     /* passing values by reference. Pity. This is a workaround.  */
     return $data;
     return $data;
@@ -69,8 +72,9 @@ function do_hook ($name) {
  * @return mixed the return value of the hook function
  * @return mixed the return value of the hook function
  */
  */
 function do_hook_function($name,$parm=NULL) {
 function do_hook_function($name,$parm=NULL) {
-    global $squirrelmail_plugin_hooks;
+    global $squirrelmail_plugin_hooks, $currentHookName;
     $ret = '';
     $ret = '';
+    $currentHookName = $name;
 
 
     if (isset($squirrelmail_plugin_hooks[$name])
     if (isset($squirrelmail_plugin_hooks[$name])
           && is_array($squirrelmail_plugin_hooks[$name])) {
           && is_array($squirrelmail_plugin_hooks[$name])) {
@@ -82,6 +86,8 @@ function do_hook_function($name,$parm=NULL) {
         }
         }
     }
     }
 
 
+    $currentHookName = '';
+
     /* Variable-length argument lists have a slight problem when */
     /* Variable-length argument lists have a slight problem when */
     /* passing values by reference. Pity. This is a workaround.  */
     /* passing values by reference. Pity. This is a workaround.  */
     return $ret;
     return $ret;
@@ -96,8 +102,9 @@ function do_hook_function($name,$parm=NULL) {
  * @return string a concatenation of the results of each plugin function
  * @return string a concatenation of the results of each plugin function
  */
  */
 function concat_hook_function($name,$parm=NULL) {
 function concat_hook_function($name,$parm=NULL) {
-    global $squirrelmail_plugin_hooks;
+    global $squirrelmail_plugin_hooks, $currentHookName;
     $ret = '';
     $ret = '';
+    $currentHookName = $name;
 
 
     if (isset($squirrelmail_plugin_hooks[$name])
     if (isset($squirrelmail_plugin_hooks[$name])
           && is_array($squirrelmail_plugin_hooks[$name])) {
           && is_array($squirrelmail_plugin_hooks[$name])) {
@@ -109,6 +116,8 @@ function concat_hook_function($name,$parm=NULL) {
         }
         }
     }
     }
 
 
+    $currentHookName = '';
+
     /* Variable-length argument lists have a slight problem when */
     /* Variable-length argument lists have a slight problem when */
     /* passing values by reference. Pity. This is a workaround.  */
     /* passing values by reference. Pity. This is a workaround.  */
     return $ret;
     return $ret;
@@ -128,7 +137,7 @@ function concat_hook_function($name,$parm=NULL) {
  * @return bool the result of the function
  * @return bool the result of the function
  */
  */
 function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
 function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
-    global $squirrelmail_plugin_hooks;
+    global $squirrelmail_plugin_hooks, $currentHookName;
     $yea = 0;
     $yea = 0;
     $nay = 0;
     $nay = 0;
     $ret = $tie;
     $ret = $tie;
@@ -137,6 +146,7 @@ function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
         is_array($squirrelmail_plugin_hooks[$name])) {
         is_array($squirrelmail_plugin_hooks[$name])) {
 
 
         /* Loop over the plugins that registered the hook */
         /* Loop over the plugins that registered the hook */
+        $currentHookName = $name;
         foreach ($squirrelmail_plugin_hooks[$name] as $function) {
         foreach ($squirrelmail_plugin_hooks[$name] as $function) {
             if (function_exists($function)) {
             if (function_exists($function)) {
                 $ret = $function($parm);
                 $ret = $function($parm);
@@ -147,6 +157,7 @@ function boolean_hook_function($name,$parm=NULL,$priority=0,$tie=false) {
                 }
                 }
             }
             }
         }
         }
+        $currentHookName = '';
 
 
         /* Examine the aftermath and assign the return value appropriately */
         /* Examine the aftermath and assign the return value appropriately */
         if (($priority > 0) && ($yea)) {
         if (($priority > 0) && ($yea)) {
@@ -189,4 +200,4 @@ if (isset($plugins) && is_array($plugins)) {
     }
     }
 }
 }
 
 
-?>
+?>