From 12182ddcfeced9934f45f20a3859049066ce0726 Mon Sep 17 00:00:00 2001 From: rvelices Date: Thu, 26 Oct 2006 03:35:20 +0000 Subject: plugins: first prototype version git-svn-id: http://piwigo.org/svn/trunk@1578 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions_plugins.inc.php | 155 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 include/functions_plugins.inc.php (limited to 'include/functions_plugins.inc.php') diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php new file mode 100644 index 000000000..23b6df5cd --- /dev/null +++ b/include/functions_plugins.inc.php @@ -0,0 +1,155 @@ +$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'); +} +?> \ No newline at end of file -- cgit v1.2.3