1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 Piwigo team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | /* |
---|
25 | Plugin Name: Event tracer |
---|
26 | Version: 2.0.3 |
---|
27 | Description: For developers. Shows all calls to trigger_event. |
---|
28 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=288 |
---|
29 | Author: Piwigo team |
---|
30 | Author URI: http://piwigo.org |
---|
31 | */ |
---|
32 | |
---|
33 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
34 | |
---|
35 | class EventTracer |
---|
36 | { |
---|
37 | var $my_config; |
---|
38 | var $trigger_counts = array(); |
---|
39 | |
---|
40 | function EventTracer() |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | function get_config_file_dir() |
---|
45 | { |
---|
46 | global $conf; |
---|
47 | return $conf['local_data_dir'].'/plugins/'; |
---|
48 | } |
---|
49 | |
---|
50 | function get_config_file_name() |
---|
51 | { |
---|
52 | return basename(dirname(__FILE__)).'.dat'; |
---|
53 | } |
---|
54 | |
---|
55 | function load_config() |
---|
56 | { |
---|
57 | $x = @file_get_contents( $this->get_config_file_dir().$this->get_config_file_name() ); |
---|
58 | if ($x!==false) |
---|
59 | { |
---|
60 | $c = unserialize($x); |
---|
61 | // do some more tests here |
---|
62 | $this->my_config = $c; |
---|
63 | } |
---|
64 | if ( !isset($this->my_config) |
---|
65 | or empty($this->my_config['filters']) ) |
---|
66 | { |
---|
67 | $this->my_config['filters'] = array( '.*' ); |
---|
68 | $this->my_config['show_registered'] = true; |
---|
69 | $this->save_config(); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | function save_config() |
---|
74 | { |
---|
75 | $dir = $this->get_config_file_dir(); |
---|
76 | @mkgetdir($dir); |
---|
77 | $file = fopen( $dir.$this->get_config_file_name(), 'w' ); |
---|
78 | fwrite($file, serialize($this->my_config) ); |
---|
79 | fclose( $file ); |
---|
80 | } |
---|
81 | |
---|
82 | function on_page_tail() |
---|
83 | { |
---|
84 | global $debug; |
---|
85 | if (@$this->my_config['show_registered']) |
---|
86 | { |
---|
87 | global $pwg_event_handlers; |
---|
88 | $out = ''; |
---|
89 | foreach ($pwg_event_handlers as $event => $prio_array) |
---|
90 | { |
---|
91 | $out .= $event.' '.intval(@$this->trigger_counts[$event])." calls\n"; |
---|
92 | foreach ($prio_array as $prio => $handlers) |
---|
93 | { |
---|
94 | foreach ($handlers as $handler) |
---|
95 | { |
---|
96 | $out .= "\t$prio "; |
---|
97 | if ( is_array($handler['function']) ) |
---|
98 | { |
---|
99 | if ( is_string($handler['function'][0]) ) |
---|
100 | $out .= $handler['function'][0].'::'; |
---|
101 | else |
---|
102 | $out .= @get_class($handler['function'][0]).'->'; |
---|
103 | $out .= $handler['function'][1]; |
---|
104 | } |
---|
105 | else |
---|
106 | $out .= $handler['function']; |
---|
107 | $out .= "\n"; |
---|
108 | } |
---|
109 | } |
---|
110 | $out .= "\n"; |
---|
111 | } |
---|
112 | $debug .= '<pre>'.$out.'</pre>'; |
---|
113 | } |
---|
114 | if (@$this->my_config['show_included_files']) |
---|
115 | { |
---|
116 | $debug .= "<pre><em>Included files</em>\n".var_export( get_included_files(), true ).'</pre>'; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | function on_trigger($event_info) |
---|
121 | { |
---|
122 | if ($event_info['type']!='post_event') |
---|
123 | @$this->trigger_counts[$event_info['event']]++; |
---|
124 | |
---|
125 | foreach( $this->my_config['filters'] as $filter) |
---|
126 | { |
---|
127 | if ( preg_match( '/'.$filter.'/', $event_info['event'] ) ) |
---|
128 | { |
---|
129 | if (@$this->my_config['show_args']) |
---|
130 | { |
---|
131 | $s = '<pre>'; |
---|
132 | $s .= htmlspecialchars( var_export( $event_info['data'], true ) ); |
---|
133 | $s .= '</pre>'; |
---|
134 | } |
---|
135 | else |
---|
136 | $s = ''; |
---|
137 | pwg_debug($event_info['type'].' "'.$event_info['event'].'" '.($this->trigger_counts[$event_info['event']]).' calls '.($s) ); |
---|
138 | break; |
---|
139 | } |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | function plugin_admin_menu($menu) |
---|
144 | { |
---|
145 | array_push($menu, |
---|
146 | array( |
---|
147 | 'NAME' => 'Event Tracer', |
---|
148 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/tracer_admin.php') |
---|
149 | ) |
---|
150 | ); |
---|
151 | return $menu; |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | $obj = new EventTracer(); |
---|
156 | $obj->load_config(); |
---|
157 | |
---|
158 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
159 | add_event_handler('loc_begin_page_tail', array(&$obj, 'on_page_tail') ); |
---|
160 | add_event_handler('trigger', array(&$obj, 'on_trigger') ); |
---|
161 | set_plugin_data($plugin['id'], $obj); |
---|
162 | ?> |
---|