$event, 'function'=>$func) ); $pwg_event_handlers[$event]["$priority"][] = array( 'function'=>$func, 'accepted_args'=>$accepted_args); return true; } function trigger_event($event, $data=null) { global $pwg_event_handlers; if ($event!='pre_trigger_event' and $event!='post_trigger_event') {// special case trigger_event('pre_trigger_event', array('event'=>$event, 'data'=>$data) ); if ( !isset($pwg_event_handlers[$event]) ) { trigger_event('post_trigger_event', array('event'=>$event, 'data'=>$data) ); } } if ( !isset($pwg_event_handlers[$event]) ) { return $data; } $args = array_slice(func_get_args(), 2); foreach ($pwg_event_handlers[$event] as $priority => $handlers) { if ( !is_null($handlers) ) { foreach($handlers as $handler) { $all_args = array_merge( array($data), $args); $function_name = $handler['function']; $accepted_args = $handler['accepted_args']; if ( $accepted_args == 1 ) $the_args = array($data); elseif ( $accepted_args > 1 ) $the_args = array_slice($all_args, 0, $accepted_args); elseif ( $accepted_args == 0 ) $the_args = NULL; else $the_args = $all_args; $data = call_user_func_array($function_name, $the_args); } } } if ($event!='pre_trigger_event' and $event!='post_trigger_event') { trigger_event('post_trigger_event', array('event'=>$event, 'data'=>$data) ); } return $data; } function get_active_plugins($runtime = true) { global $conf; if ($conf['disable_plugins'] and $runtime) { return array(); } if (empty($conf['active_plugins'])) { return array(); } return explode(',', $conf['active_plugins']); } function load_plugins() { $plugins = get_active_plugins(); foreach( $plugins as $plugin) { if (!empty($plugin)) { include_once( PHPWG_PLUGINS_PATH.$plugin.'/index.php' ); } } trigger_event('plugins_loaded'); } ?>