aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/functions_plugins.inc.php123
-rw-r--r--include/page_header.php9
-rw-r--r--include/picture_metadata.inc.php4
3 files changed, 106 insertions, 30 deletions
diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php
index f381b0a89..e83f76df7 100644
--- a/include/functions_plugins.inc.php
+++ b/include/functions_plugins.inc.php
@@ -35,17 +35,22 @@ string.
define('PHPWG_PLUGINS_PATH',PHPWG_ROOT_PATH.'plugins/');
+define('EVENT_HANDLER_PRIORITY_NEUTRAL', 50);
+
/* Register a event handler.
* @param string $event the name of the event to listen to
* @param mixed $func the function that will handle the event
+ * @param int $priority optional priority (greater priority will
+ * be executed at last)
*/
-function add_event_handler($event, $func, $priority=50, $accepted_args=1)
+function add_event_handler($event, $func,
+ $priority=EVENT_HANDLER_PRIORITY_NEUTRAL, $accepted_args=1)
{
global $pwg_event_handlers;
- if ( isset($pwg_event_handlers[$event]["$priority"]) )
+ if ( isset($pwg_event_handlers[$event][$priority]) )
{
- foreach($pwg_event_handlers[$event]["$priority"] as $handler)
+ foreach($pwg_event_handlers[$event][$priority] as $handler)
{
if ( $handler['function'] == $func )
{
@@ -54,18 +59,50 @@ function add_event_handler($event, $func, $priority=50, $accepted_args=1)
}
}
- trigger_event('add_event_handler',
- array('event'=>$event, 'function'=>$func)
- );
-
- $pwg_event_handlers[$event]["$priority"][] =
+ $pwg_event_handlers[$event][$priority][] =
array(
'function'=>$func,
'accepted_args'=>$accepted_args);
-
+ ksort( $pwg_event_handlers[$event] );
return true;
}
+/* Register a event handler.
+ * @param string $event the name of the event to listen to
+ * @param mixed $func the function that needs removal
+ * @param int $priority optional priority (greater priority will
+ * be executed at last)
+*/
+function remove_event_handler($event, $func,
+ $priority=EVENT_HANDLER_PRIORITY_NEUTRAL)
+{
+ global $pwg_event_handlers;
+
+ if (!isset( $pwg_event_handlers[$event][$priority] ) )
+ {
+ return false;
+ }
+ for ($i=0; $i<count($pwg_event_handlers[$event][$priority]); $i++)
+ {
+ if ($pwg_event_handlers[$event][$priority][$i]['function']==$func)
+ {
+ unset($pwg_event_handlers[$event][$priority][$i]);
+ $pwg_event_handlers[$event][$priority] =
+ 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] ) )
+ {
+ unset( $pwg_event_handlers[$event] );
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+}
/* Triggers an event and calls all registered event handlers
* @param string $event name of the event
@@ -74,19 +111,15 @@ function add_event_handler($event, $func, $priority=50, $accepted_args=1)
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',
+
+ // just for debugging
+ trigger_action('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]) )
{
+ trigger_action('post_trigger_event',
+ array('event'=>$event, 'data'=>$data) );
return $data;
}
$args = array_slice(func_get_args(), 2);
@@ -114,17 +147,53 @@ function trigger_event($event, $data=null)
}
}
}
+ trigger_action('post_trigger_event',
+ array('event'=>$event, 'data'=>$data) );
+ return $data;
+}
- if ($event!='pre_trigger_event' and $event!='post_trigger_event')
- {
- trigger_event('post_trigger_event',
+
+function trigger_action($event, $data=null)
+{
+ global $pwg_event_handlers;
+ if ($event!='pre_trigger_event'
+ and $event!='post_trigger_event'
+ and $event!='trigger_action')
+ {// special case for debugging - avoid recursive calls
+ trigger_action('trigger_action',
array('event'=>$event, 'data'=>$data) );
}
- return $data;
-}
+ if ( !isset($pwg_event_handlers[$event]) )
+ {
+ return;
+ }
+ $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;
+
+ call_user_func_array($function_name, $the_args);
+ }
+ }
+ }
+}
/* Returns an array of plugins defined in the database
@@ -173,8 +242,12 @@ function load_plugins()
$plugins = get_db_plugins('active');
foreach( $plugins as $plugin)
{
- @include_once( PHPWG_PLUGINS_PATH.$plugin['id'].'/index.php' );
+ $file_name = PHPWG_PLUGINS_PATH.$plugin['id'].'/main.inc.php';
+ if ( file_exists($file_name) )
+ {
+ include_once( $file_name );
+ }
}
- trigger_event('plugins_loaded');
+ trigger_action('plugins_loaded');
}
?> \ No newline at end of file
diff --git a/include/page_header.php b/include/page_header.php
index af571ab19..1535eb896 100644
--- a/include/page_header.php
+++ b/include/page_header.php
@@ -30,6 +30,8 @@
//
$template->set_filenames(array('header'=>'header.tpl'));
+trigger_action('loc_begin_page_header');
+
$template->assign_vars(
array(
'GALLERY_TITLE' =>
@@ -37,9 +39,8 @@ $template->assign_vars(
$page['gallery_title'] : $conf['gallery_title'],
'PAGE_BANNER' =>
- trigger_event('page_banner',
- isset($page['page_banner']) ?
- $page['page_banner'] : $conf['page_banner'] ),
+ isset($page['page_banner']) ?
+ $page['page_banner'] : $conf['page_banner'],
'BODY_ID' =>
isset($page['body_id']) ?
@@ -67,6 +68,8 @@ if ( isset( $refresh ) and intval($refresh) >= 0
$template->assign_block_vars('refresh', array());
}
+trigger_action('loc_end_page_header');
+
header('Content-Type: text/html; charset='.$lang_info['charset']);
$template->parse('header');
?>
diff --git a/include/picture_metadata.inc.php b/include/picture_metadata.inc.php
index 777cbd822..038737eb7 100644
--- a/include/picture_metadata.inc.php
+++ b/include/picture_metadata.inc.php
@@ -39,7 +39,7 @@ if ($conf['show_exif'])
die('Exif extension not available, admin should disable exif display');
}
- if ($exif = @read_exif_data($picture['current']['src_file_system']))
+ if ($exif = @read_exif_data($picture['current']['image_path']))
{
$template->assign_block_vars(
'metadata.headline',
@@ -92,7 +92,7 @@ if ($conf['show_exif'])
}
if ($conf['show_iptc'])
{
- $iptc = get_iptc_data($picture['current']['src_file_system'],
+ $iptc = get_iptc_data($picture['current']['image_path'],
$conf['show_iptc_mapping']);
if (count($iptc) > 0)