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