$event, 'function'=>$func) ); $pwg_event_handlers[$event]["$priority"][] = array( 'function'=>$func, 'accepted_args'=>$accepted_args); return true; } /* Triggers an event and calls all registered event handlers * @param string $event name of the event * @param mixed $data data to pass to handlers */ 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; } /* Returns an array of plugins defined in the database * @param string $state optional filter on this state * @param string $id optional returns only data about given plugin */ function get_db_plugins($state='', $id='') { $query = ' SELECT * FROM '.PLUGINS_TABLE; if (!empty($state) or !empty($id) ) { $query .= ' WHERE 1=1'; if (!empty($state)) { $query .= ' AND state="'.$state.'"'; } if (!empty($id)) { $query .= ' AND id="'.$id.'"'; } } $result = pwg_query($query); $plugins = array(); while ($row = mysql_fetch_array($result)) { array_push($plugins, $row); } return $plugins; } /*loads all the plugins on startup*/ function load_plugins() { global $conf; if ($conf['disable_plugins']) { return; } $plugins = get_db_plugins('active'); foreach( $plugins as $plugin) { @include_once( PHPWG_PLUGINS_PATH.$plugin['id'].'/index.php' ); } trigger_event('plugins_loaded'); } ?>