[2302] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5196] | 5 | // | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | |
---|
[2342] | 6 | // | Copyright(C) 2003-2008 Piwigo team http://phpwebgallery.net | |
---|
[2302] | 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 | /* |
---|
[1580] | 25 | Plugin Name: Event tracer |
---|
[7629] | 26 | Version: 2.1.0 |
---|
[1580] | 27 | Description: For developers. Shows all calls to trigger_event. |
---|
[3275] | 28 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=288 |
---|
[2342] | 29 | Author: Piwigo team |
---|
| 30 | Author URI: http://piwigo.org |
---|
[1580] | 31 | */ |
---|
[2302] | 32 | |
---|
[1580] | 33 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 34 | |
---|
| 35 | class EventTracer |
---|
| 36 | { |
---|
| 37 | var $my_config; |
---|
[2773] | 38 | var $trigger_counts = array(); |
---|
[2497] | 39 | |
---|
[1731] | 40 | function EventTracer() |
---|
[1580] | 41 | { |
---|
| 42 | } |
---|
| 43 | |
---|
[2254] | 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 | |
---|
[1580] | 55 | function load_config() |
---|
| 56 | { |
---|
[2254] | 57 | $x = @file_get_contents( $this->get_config_file_dir().$this->get_config_file_name() ); |
---|
[1580] | 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( '.*' ); |
---|
[2773] | 68 | $this->my_config['show_registered'] = true; |
---|
[1580] | 69 | $this->save_config(); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | function save_config() |
---|
| 74 | { |
---|
[2254] | 75 | $dir = $this->get_config_file_dir(); |
---|
[2497] | 76 | @mkgetdir($dir); |
---|
[2254] | 77 | $file = fopen( $dir.$this->get_config_file_name(), 'w' ); |
---|
[1580] | 78 | fwrite($file, serialize($this->my_config) ); |
---|
| 79 | fclose( $file ); |
---|
| 80 | } |
---|
| 81 | |
---|
[2773] | 82 | function on_page_tail() |
---|
| 83 | { |
---|
[3611] | 84 | global $debug; |
---|
| 85 | if (@$this->my_config['show_registered']) |
---|
[2773] | 86 | { |
---|
[3611] | 87 | global $pwg_event_handlers; |
---|
[2773] | 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 | } |
---|
[3611] | 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 | } |
---|
[2773] | 118 | } |
---|
| 119 | |
---|
[3136] | 120 | function on_trigger($event_info) |
---|
[1590] | 121 | { |
---|
[3136] | 122 | if ($event_info['type']!='post_event') |
---|
| 123 | @$this->trigger_counts[$event_info['event']]++; |
---|
| 124 | |
---|
[1590] | 125 | foreach( $this->my_config['filters'] as $filter) |
---|
[1580] | 126 | { |
---|
[1590] | 127 | if ( preg_match( '/'.$filter.'/', $event_info['event'] ) ) |
---|
[1580] | 128 | { |
---|
[3611] | 129 | if (@$this->my_config['show_args']) |
---|
[1580] | 130 | { |
---|
[1590] | 131 | $s = '<pre>'; |
---|
| 132 | $s .= htmlspecialchars( var_export( $event_info['data'], true ) ); |
---|
| 133 | $s .= '</pre>'; |
---|
[1580] | 134 | } |
---|
[1590] | 135 | else |
---|
| 136 | $s = ''; |
---|
[3136] | 137 | pwg_debug($event_info['type'].' "'.$event_info['event'].'" '.($this->trigger_counts[$event_info['event']]).' calls '.($s) ); |
---|
[1590] | 138 | break; |
---|
[1580] | 139 | } |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
[1705] | 143 | function plugin_admin_menu($menu) |
---|
[1580] | 144 | { |
---|
[1705] | 145 | array_push($menu, |
---|
| 146 | array( |
---|
| 147 | 'NAME' => 'Event Tracer', |
---|
[1731] | 148 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/tracer_admin.php') |
---|
[1705] | 149 | ) |
---|
| 150 | ); |
---|
| 151 | return $menu; |
---|
[1580] | 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
[1731] | 155 | $obj = new EventTracer(); |
---|
[1705] | 156 | $obj->load_config(); |
---|
[1580] | 157 | |
---|
[1705] | 158 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
[2773] | 159 | add_event_handler('loc_begin_page_tail', array(&$obj, 'on_page_tail') ); |
---|
[3136] | 160 | add_event_handler('trigger', array(&$obj, 'on_trigger') ); |
---|
[1705] | 161 | set_plugin_data($plugin['id'], $obj); |
---|
[2254] | 162 | ?> |
---|