[2302] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008 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 |
---|
[2254] | 26 | Version: 1.8.a |
---|
[1580] | 27 | Description: For developers. Shows all calls to trigger_event. |
---|
[2342] | 28 | Plugin URI: http://piwigo.org |
---|
| 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 $me_working; |
---|
| 38 | var $my_config; |
---|
[2497] | 39 | |
---|
[1731] | 40 | function EventTracer() |
---|
[1580] | 41 | { |
---|
| 42 | $this->me_working=0; |
---|
| 43 | } |
---|
| 44 | |
---|
[2254] | 45 | function get_config_file_dir() |
---|
| 46 | { |
---|
| 47 | global $conf; |
---|
| 48 | return $conf['local_data_dir'].'/plugins/'; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | function get_config_file_name() |
---|
| 52 | { |
---|
| 53 | return basename(dirname(__FILE__)).'.dat'; |
---|
| 54 | } |
---|
| 55 | |
---|
[1580] | 56 | function load_config() |
---|
| 57 | { |
---|
[2254] | 58 | $x = @file_get_contents( $this->get_config_file_dir().$this->get_config_file_name() ); |
---|
[1580] | 59 | if ($x!==false) |
---|
| 60 | { |
---|
| 61 | $c = unserialize($x); |
---|
| 62 | // do some more tests here |
---|
| 63 | $this->my_config = $c; |
---|
| 64 | } |
---|
| 65 | if ( !isset($this->my_config) |
---|
| 66 | or empty($this->my_config['filters']) ) |
---|
| 67 | { |
---|
| 68 | $this->my_config['filters'] = array( '.*' ); |
---|
| 69 | $this->my_config['show_args'] = false; |
---|
| 70 | $this->save_config(); |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | function save_config() |
---|
| 75 | { |
---|
[2254] | 76 | $dir = $this->get_config_file_dir(); |
---|
[2497] | 77 | @mkgetdir($dir); |
---|
[2254] | 78 | $file = fopen( $dir.$this->get_config_file_name(), 'w' ); |
---|
[1580] | 79 | fwrite($file, serialize($this->my_config) ); |
---|
| 80 | fclose( $file ); |
---|
| 81 | } |
---|
| 82 | |
---|
[1590] | 83 | function on_pre_trigger_event($event_info) |
---|
[1580] | 84 | { |
---|
[1590] | 85 | $this->dump('pre_trigger_event', $event_info); |
---|
| 86 | } |
---|
| 87 | function on_post_trigger_event($event_info) |
---|
| 88 | { |
---|
| 89 | $this->dump('post_trigger_event', $event_info); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | function on_trigger_action($event_info) |
---|
| 93 | { |
---|
| 94 | $this->dump('trigger_action', $event_info); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | function dump($event, $event_info) |
---|
| 98 | { |
---|
| 99 | foreach( $this->my_config['filters'] as $filter) |
---|
[1580] | 100 | { |
---|
[1590] | 101 | if ( preg_match( '/'.$filter.'/', $event_info['event'] ) ) |
---|
[1580] | 102 | { |
---|
[1590] | 103 | if ($this->my_config['show_args']) |
---|
[1580] | 104 | { |
---|
[1590] | 105 | $s = '<pre>'; |
---|
| 106 | $s .= htmlspecialchars( var_export( $event_info['data'], true ) ); |
---|
| 107 | $s .= '</pre>'; |
---|
[1580] | 108 | } |
---|
[1590] | 109 | else |
---|
| 110 | $s = ''; |
---|
| 111 | pwg_debug($event.' "'.$event_info['event'].'" '.($s) ); |
---|
| 112 | break; |
---|
[1580] | 113 | } |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
[1705] | 117 | function plugin_admin_menu($menu) |
---|
[1580] | 118 | { |
---|
[1705] | 119 | array_push($menu, |
---|
| 120 | array( |
---|
| 121 | 'NAME' => 'Event Tracer', |
---|
[1731] | 122 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/tracer_admin.php') |
---|
[1705] | 123 | ) |
---|
| 124 | ); |
---|
| 125 | return $menu; |
---|
[1580] | 126 | } |
---|
| 127 | } |
---|
| 128 | |
---|
[1731] | 129 | $obj = new EventTracer(); |
---|
[1705] | 130 | $obj->load_config(); |
---|
[1580] | 131 | |
---|
[1705] | 132 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); |
---|
| 133 | add_event_handler('pre_trigger_event', array(&$obj, 'on_pre_trigger_event') ); |
---|
| 134 | add_event_handler('post_trigger_event', array(&$obj, 'on_post_trigger_event') ); |
---|
| 135 | add_event_handler('trigger_action', array(&$obj, 'on_trigger_action') ); |
---|
| 136 | set_plugin_data($plugin['id'], $obj); |
---|
[2254] | 137 | ?> |
---|