- event tracer improvement: option to show all registered event handlers for every page ...

git-svn-id: http://piwigo.org/svn/branches/2.0@2771 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2008-10-18 00:50:19 +00:00
parent 79d51b19c1
commit 7a28366cba
3 changed files with 50 additions and 4 deletions

View file

@ -34,12 +34,11 @@ if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
class EventTracer
{
var $me_working;
var $my_config;
var $trigger_counts = array();
function EventTracer()
{
$this->me_working=0;
}
function get_config_file_dir()
@ -67,6 +66,7 @@ class EventTracer
{
$this->my_config['filters'] = array( '.*' );
$this->my_config['show_args'] = false;
$this->my_config['show_registered'] = true;
$this->save_config();
}
}
@ -82,6 +82,7 @@ class EventTracer
function on_pre_trigger_event($event_info)
{
@$this->trigger_counts[$event_info['event']]++;
$this->dump('pre_trigger_event', $event_info);
}
function on_post_trigger_event($event_info)
@ -91,9 +92,43 @@ class EventTracer
function on_trigger_action($event_info)
{
@$this->trigger_counts[$event_info['event']]++;
$this->dump('trigger_action', $event_info);
}
function on_page_tail()
{
if (1 || @$this->my_config['show_registered'])
{
global $debug, $pwg_event_handlers;
$out = '';
foreach ($pwg_event_handlers as $event => $prio_array)
{
$out .= $event.' '.intval(@$this->trigger_counts[$event])." calls\n";
foreach ($prio_array as $prio => $handlers)
{
foreach ($handlers as $handler)
{
$out .= "\t$prio ";
if ( is_array($handler['function']) )
{
if ( is_string($handler['function'][0]) )
$out .= $handler['function'][0].'::';
else
$out .= @get_class($handler['function'][0]).'->';
$out .= $handler['function'][1];
}
else
$out .= $handler['function'];
$out .= "\n";
}
}
$out .= "\n";
}
$debug .= '<pre>'.$out.'</pre>';
}
}
function dump($event, $event_info)
{
foreach( $this->my_config['filters'] as $filter)
@ -108,7 +143,7 @@ class EventTracer
}
else
$s = '';
pwg_debug($event.' "'.$event_info['event'].'" '.($s) );
pwg_debug($event.' "'.$event_info['event'].'" '.($this->trigger_counts[$event_info['event']]).' calls '.($s) );
break;
}
}
@ -132,6 +167,7 @@ $obj->load_config();
add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
add_event_handler('pre_trigger_event', array(&$obj, 'on_pre_trigger_event') );
add_event_handler('post_trigger_event', array(&$obj, 'on_post_trigger_event') );
add_event_handler('loc_begin_page_tail', array(&$obj, 'on_page_tail') );
add_event_handler('trigger_action', array(&$obj, 'on_trigger_action') );
set_plugin_data($plugin['id'], $obj);
?>

View file

@ -17,6 +17,7 @@ if ( isset($_POST['eventTracer_filters']) )
else
$me->my_config['filters'] = array();
$me->my_config['show_args'] = isset($_POST['eventTracer_show_args']);
$me->my_config['show_registered'] = isset($_POST['eventTracer_show_registered']);
$me->save_config();
global $page;
array_push($page['infos'], 'event tracer options saved');
@ -24,6 +25,7 @@ if ( isset($_POST['eventTracer_filters']) )
$template->assign('EVENT_TRACER_FILTERS', implode("\n", $me->my_config['filters'] ) );
$template->assign('EVENT_TRACER_SHOW_ARGS', $me->my_config['show_args'] ? 'checked="checked"' : '' );
$template->assign('U_LIST_EVENTS', get_admin_plugin_menu_link(dirname(__FILE__).'/event_list.php'));
$template->assign('EVENT_TRACER_SHOW_REGISTERED', $me->my_config['show_registered'] ? 'checked="checked"' : '' );
//$template->assign_var('EVENT_TRACER_F_ACTION', $my_url);

View file

@ -12,15 +12,23 @@ You can use this plugin to see what events is Piwigo calling.
<fieldset>
<legend>Event Tracer</legend>
<label>Show event argument
<label>Show event arguments
<input type="checkbox" name="eventTracer_show_args" {$EVENT_TRACER_SHOW_ARGS} />
</label>
<br/>
<label>Fill below a list of regular expressions (one per line).
An event will be logged if its name matches at least one expression in the list.
<textarea name="eventTracer_filters" id="eventTracer_filters"rows="10" cols="80">{$EVENT_TRACER_FILTERS}</textarea>
</label>
<br/>
<label>Show all registered handlers
<input type="checkbox" name="eventTracer_show_registered" {$EVENT_TRACER_SHOW_REGISTERED} />
</label>
</fieldset>
<p><input class="submit" type="submit" value="Submit" /></p>