Index: trunk/include/functions_plugins.inc.php
===================================================================
--- trunk/include/functions_plugins.inc.php	(revision 27221)
+++ trunk/include/functions_plugins.inc.php	(revision 27238)
@@ -173,15 +173,17 @@
  * @param Callable $func the callback function
  * @param int $priority greater priority will be executed at last
+ * @param string $include_path file to include before executing the callback
+ * @return bool false is handler already exists
  */
 function add_event_handler($event, $func,
-    $priority=EVENT_HANDLER_PRIORITY_NEUTRAL, $accepted_args=1)
+    $priority=EVENT_HANDLER_PRIORITY_NEUTRAL, $include_path=null)
 {
   global $pwg_event_handlers;
 
-  if ( isset($pwg_event_handlers[$event][$priority]) )
-  {
-    foreach($pwg_event_handlers[$event][$priority] as $handler)
-    {
-      if ( $handler['function'] == $func )
+  if (isset($pwg_event_handlers[$event][$priority]))
+  {
+    foreach ($pwg_event_handlers[$event][$priority] as $handler)
+    {
+      if ($handler['function'] == $func)
       {
         return false;
@@ -190,9 +192,10 @@
   }
 
-  $pwg_event_handlers[$event][$priority][] =
-    array(
-      'function'=>$func,
-      'accepted_args'=>$accepted_args);
-  ksort( $pwg_event_handlers[$event] );
+  $pwg_event_handlers[$event][$priority][] = array(
+    'function' => $func,
+    'include_path' => is_string($include_path) ? $include_path : null,
+    );
+
+  ksort($pwg_event_handlers[$event]);
   return true;
 }
@@ -211,5 +214,5 @@
   global $pwg_event_handlers;
 
-  if (!isset( $pwg_event_handlers[$event][$priority] ) )
+  if (!isset($pwg_event_handlers[$event][$priority]))
   {
     return false;
@@ -223,10 +226,10 @@
         array_values($pwg_event_handlers[$event][$priority]);
 
-      if ( empty($pwg_event_handlers[$event][$priority]) )
-      {
-        unset( $pwg_event_handlers[$event][$priority] );
-        if (empty( $pwg_event_handlers[$event] ) )
+      if (empty($pwg_event_handlers[$event][$priority]))
+      {
+        unset($pwg_event_handlers[$event][$priority]);
+        if (empty($pwg_event_handlers[$event]))
         {
-          unset( $pwg_event_handlers[$event] );
+          unset($pwg_event_handlers[$event]);
         }
       }
@@ -265,11 +268,12 @@
   global $pwg_event_handlers;
 
-  if ( isset($pwg_event_handlers['trigger']) )
-  {// just for debugging
+  if (isset($pwg_event_handlers['trigger']))
+  {// debugging
     trigger_action('trigger',
-        array('type'=>'event', 'event'=>$event, 'data'=>$data) );
-  }
-
-  if ( !isset($pwg_event_handlers[$event]) )
+      array('type'=>'event', 'event'=>$event, 'data'=>$data)
+      );
+  }
+
+  if (!isset($pwg_event_handlers[$event]))
   {
     return $data;
@@ -279,14 +283,24 @@
   foreach ($pwg_event_handlers[$event] as $priority => $handlers)
   {
-    foreach($handlers as $handler)
-    {
-      $function_name = $handler['function'];
-      $accepted_args = $handler['accepted_args'];
+    foreach ($handlers as $handler)
+    {
       $args[1] = $data;
-      $data = call_user_func_array($function_name, array_slice($args,1,$accepted_args) );
-    }
-  }
-  trigger_action('trigger',
-       array('type'=>'post_event', 'event'=>$event, 'data'=>$data) );
+
+      if (!empty($handler['include_path']))
+      {
+        include_once($handler['include_path']);
+      }
+
+      $data = call_user_func_array($handler['function'], array_slice($args, 1));
+    }
+  }
+
+  if (isset($pwg_event_handlers['trigger']))
+  {// debugging
+    trigger_action('trigger',
+      array('type'=>'post_event', 'event'=>$event, 'data'=>$data)
+      );
+  }
+
   return $data;
 }
@@ -315,11 +329,13 @@
 {
   global $pwg_event_handlers;
-  if ( isset($pwg_event_handlers['trigger']) and $event!='trigger' )
-  {// special case for debugging - avoid recursive calls
+
+  if (isset($pwg_event_handlers['trigger']) and $event!='trigger')
+  {// debugging - avoid recursive calls
     trigger_action('trigger',
-        array('type'=>'action', 'event'=>$event, 'data'=>null) );
-  }
-
-  if ( !isset($pwg_event_handlers[$event]) )
+      array('type'=>'action', 'event'=>$event, 'data'=>null)
+      );
+  }
+
+  if (!isset($pwg_event_handlers[$event]))
   {
     return;
@@ -329,10 +345,12 @@
   foreach ($pwg_event_handlers[$event] as $priority => $handlers)
   {
-    foreach($handlers as $handler)
-    {
-      $function_name = $handler['function'];
-      $accepted_args = $handler['accepted_args'];
-
-      call_user_func_array($function_name, array_slice($args,1,$accepted_args) );
+    foreach ($handlers as $handler)
+    {
+      if (!empty($handler['include_path']))
+      {
+        include_once($handler['include_path']);
+      }
+
+      call_user_func_array($handler['function'], array_slice($args,1));
     }
   }
