1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Event tracer |
---|
4 | Version: 1.0 |
---|
5 | Description: For developers. Shows all calls to trigger_event. |
---|
6 | Plugin URI: http://www.phpwebgallery.net |
---|
7 | */ |
---|
8 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
9 | |
---|
10 | class EventTracer |
---|
11 | { |
---|
12 | var $me_working; |
---|
13 | var $my_config; |
---|
14 | |
---|
15 | function EventTracer() |
---|
16 | { |
---|
17 | $this->me_working=0; |
---|
18 | } |
---|
19 | |
---|
20 | function load_config() |
---|
21 | { |
---|
22 | $x = @file_get_contents( dirname(__FILE__).'/data.dat' ); |
---|
23 | if ($x!==false) |
---|
24 | { |
---|
25 | $c = unserialize($x); |
---|
26 | // do some more tests here |
---|
27 | $this->my_config = $c; |
---|
28 | } |
---|
29 | if ( !isset($this->my_config) |
---|
30 | or empty($this->my_config['filters']) ) |
---|
31 | { |
---|
32 | $this->my_config['filters'] = array( '.*' ); |
---|
33 | $this->my_config['show_args'] = false; |
---|
34 | $this->save_config(); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | function save_config() |
---|
39 | { |
---|
40 | $file = fopen( dirname(__FILE__).'/data.dat', 'w' ); |
---|
41 | fwrite($file, serialize($this->my_config) ); |
---|
42 | fclose( $file ); |
---|
43 | } |
---|
44 | |
---|
45 | function on_pre_trigger_event($event_info) |
---|
46 | { |
---|
47 | $this->dump('pre_trigger_event', $event_info); |
---|
48 | } |
---|
49 | function on_post_trigger_event($event_info) |
---|
50 | { |
---|
51 | $this->dump('post_trigger_event', $event_info); |
---|
52 | } |
---|
53 | |
---|
54 | function on_trigger_action($event_info) |
---|
55 | { |
---|
56 | $this->dump('trigger_action', $event_info); |
---|
57 | } |
---|
58 | |
---|
59 | function dump($event, $event_info) |
---|
60 | { |
---|
61 | foreach( $this->my_config['filters'] as $filter) |
---|
62 | { |
---|
63 | if ( preg_match( '/'.$filter.'/', $event_info['event'] ) ) |
---|
64 | { |
---|
65 | if ($this->my_config['show_args']) |
---|
66 | { |
---|
67 | $s = '<pre>'; |
---|
68 | $s .= htmlspecialchars( var_export( $event_info['data'], true ) ); |
---|
69 | $s .= '</pre>'; |
---|
70 | } |
---|
71 | else |
---|
72 | $s = ''; |
---|
73 | pwg_debug($event.' "'.$event_info['event'].'" '.($s) ); |
---|
74 | break; |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | function plugin_admin_menu() |
---|
80 | { |
---|
81 | add_plugin_admin_menu( "Event Tracer", array(&$this, 'do_admin') ); |
---|
82 | } |
---|
83 | |
---|
84 | function do_admin($my_url) |
---|
85 | { |
---|
86 | include( dirname(__FILE__).'/tracer_admin.php' ); |
---|
87 | } |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | $eventTracer = new EventTracer(); |
---|
92 | $eventTracer->load_config(); |
---|
93 | |
---|
94 | add_event_handler('plugin_admin_menu', array(&$eventTracer, 'plugin_admin_menu') ); |
---|
95 | add_event_handler('pre_trigger_event', array(&$eventTracer, 'on_pre_trigger_event') ); |
---|
96 | add_event_handler('post_trigger_event', array(&$eventTracer, 'on_post_trigger_event') ); |
---|
97 | add_event_handler('trigger_action', array(&$eventTracer, 'on_trigger_action') ); |
---|
98 | ?> |
---|