diff options
Diffstat (limited to '')
-rw-r--r-- | BSF/plugins/event_tracer/event_list.php | 90 | ||||
-rw-r--r-- | BSF/plugins/event_tracer/event_list.tpl | 17 | ||||
-rw-r--r-- | BSF/plugins/event_tracer/index.php | 30 | ||||
-rw-r--r-- | BSF/plugins/event_tracer/main.inc.php | 137 | ||||
-rw-r--r-- | BSF/plugins/event_tracer/maintain.inc.php | 9 | ||||
-rw-r--r-- | BSF/plugins/event_tracer/tracer_admin.php | 31 | ||||
-rw-r--r-- | BSF/plugins/event_tracer/tracer_admin.tpl | 29 |
7 files changed, 343 insertions, 0 deletions
diff --git a/BSF/plugins/event_tracer/event_list.php b/BSF/plugins/event_tracer/event_list.php new file mode 100644 index 000000000..ae617fe87 --- /dev/null +++ b/BSF/plugins/event_tracer/event_list.php @@ -0,0 +1,90 @@ +<?php +if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); + +function get_php_files($path, $to_ignore=array(), $recursive=true ) +{ + $files = array(); + if (is_dir($path)) + { + if ($contents = opendir($path)) + { + while (($node = readdir($contents)) !== false) + { + if ($node != '.' and $node != '..' and $node != '.svn' + and !in_array($node, $to_ignore) ) + { + if ( $recursive and is_dir($path.'/'.$node) ) + { + $files = array_merge($files, get_php_files($path.'/'.$node, $to_ignore)); + + } + if ( is_file($path.'/'.$node) ) + { + $files[] = $path.'/'.$node; + } + } + } + closedir($contents); + } + } + return $files; +} + +$files = array(); +$files = array_merge( $files, get_php_files('.', array(), false) ); +$files = array_merge( $files, get_php_files('./include') ); +$files = array_merge( $files, get_php_files('./admin') ); +$files = array_unique($files); + +$events = array(); +foreach ($files as $file) +{ + $code = file_get_contents($file); + $code = preg_replace( '#\?'.'>.*<\?php#m', '', $code); + $code = preg_replace( '#\/\*.*\*\/#m', '', $code); + $code = preg_replace( '#\/\/.*#', '', $code); + + $count = preg_match_all( + '#[^a-zA-Z_$-]trigger_(action|event)\s*\(\s*([^,)]+)#m', + $code, $matches + ); + + for ($i=0; $i<$count; $i++) + { + $type = $matches[1][$i]; + $name = preg_replace( '#^[\'"]?([^\'"]*)[\'"]?$#', '$1', $matches[2][$i]); + array_push($events, array($type,$name,$file) ); + } +} + +$sort= isset($_GET['sort']) ? $_GET['sort'] : 1; +usort( + $events, + create_function( '$a,$b', 'return $a['.$sort.']>$b['.$sort.'];' ) + ); + +global $template; + +$url = get_admin_plugin_menu_link(__FILE__); + +$template->assign( array( + 'NB_EVENTS' => count($events), + 'U_SORT0' => add_url_params($url, array('sort'=>0) ), + 'U_SORT1' => add_url_params($url, array('sort'=>1) ), + 'U_SORT2' => add_url_params($url, array('sort'=>2) ), + ) ); + +$template->assign('events', array()); +foreach ($events as $e) +{ + $template->append( 'events', array( + 'TYPE' => $e[0], + 'NAME' => $e[1], + 'FILE' => $e[2], + ) + ); +} + +$template->set_filenames( array('event_list' => dirname(__FILE__).'/event_list.tpl' ) ); +$template->assign_var_from_handle( 'ADMIN_CONTENT', 'event_list'); +?> diff --git a/BSF/plugins/event_tracer/event_list.tpl b/BSF/plugins/event_tracer/event_list.tpl new file mode 100644 index 000000000..accc27278 --- /dev/null +++ b/BSF/plugins/event_tracer/event_list.tpl @@ -0,0 +1,17 @@ +{* $Id$ *} +There are {$NB_EVENTS} calls to triger_event or triger_action. + +<table width="99%" class="table2"> +<tr class="throw"> + <th><a href="{$U_SORT0}">Type</a></th> + <th><a href="{$U_SORT1}">Name</a></th> + <th><a href="{$U_SORT2}">File</a></th> +</tr> +{foreach from=$events item=event} +<tr> + <td>{$event.TYPE}</td> + <td>{$event.NAME}</td> + <td>{$event.FILE}</td> +</tr> +{/foreach} +</table> diff --git a/BSF/plugins/event_tracer/index.php b/BSF/plugins/event_tracer/index.php new file mode 100644 index 000000000..c15b15795 --- /dev/null +++ b/BSF/plugins/event_tracer/index.php @@ -0,0 +1,30 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based picture gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008 Piwigo Team http://piwigo.org | +// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | +// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +// Recursive call +$url = '../'; +header( 'Request-URI: '.$url ); +header( 'Content-Location: '.$url ); +header( 'Location: '.$url ); +exit(); +?> diff --git a/BSF/plugins/event_tracer/main.inc.php b/BSF/plugins/event_tracer/main.inc.php new file mode 100644 index 000000000..dcf282146 --- /dev/null +++ b/BSF/plugins/event_tracer/main.inc.php @@ -0,0 +1,137 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based picture gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008 Piwigo Team http://piwigo.org | +// | Copyright(C) 2003-2008 Piwigo team http://phpwebgallery.net | +// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/* +Plugin Name: Event tracer +Version: 1.8.a +Description: For developers. Shows all calls to trigger_event. +Plugin URI: http://piwigo.org +Author: Piwigo team +Author URI: http://piwigo.org +*/ + +if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); + +class EventTracer +{ + var $me_working; + var $my_config; + + function EventTracer() + { + $this->me_working=0; + } + + function get_config_file_dir() + { + global $conf; + return $conf['local_data_dir'].'/plugins/'; + } + + function get_config_file_name() + { + return basename(dirname(__FILE__)).'.dat'; + } + + function load_config() + { + $x = @file_get_contents( $this->get_config_file_dir().$this->get_config_file_name() ); + if ($x!==false) + { + $c = unserialize($x); + // do some more tests here + $this->my_config = $c; + } + if ( !isset($this->my_config) + or empty($this->my_config['filters']) ) + { + $this->my_config['filters'] = array( '.*' ); + $this->my_config['show_args'] = false; + $this->save_config(); + } + } + + function save_config() + { + $dir = $this->get_config_file_dir(); + @mkdir($dir); + $file = fopen( $dir.$this->get_config_file_name(), 'w' ); + fwrite($file, serialize($this->my_config) ); + fclose( $file ); + } + + function on_pre_trigger_event($event_info) + { + $this->dump('pre_trigger_event', $event_info); + } + function on_post_trigger_event($event_info) + { + $this->dump('post_trigger_event', $event_info); + } + + function on_trigger_action($event_info) + { + $this->dump('trigger_action', $event_info); + } + + function dump($event, $event_info) + { + foreach( $this->my_config['filters'] as $filter) + { + if ( preg_match( '/'.$filter.'/', $event_info['event'] ) ) + { + if ($this->my_config['show_args']) + { + $s = '<pre>'; + $s .= htmlspecialchars( var_export( $event_info['data'], true ) ); + $s .= '</pre>'; + } + else + $s = ''; + pwg_debug($event.' "'.$event_info['event'].'" '.($s) ); + break; + } + } + } + + function plugin_admin_menu($menu) + { + array_push($menu, + array( + 'NAME' => 'Event Tracer', + 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/tracer_admin.php') + ) + ); + return $menu; + } +} + +$obj = new EventTracer(); +$obj->load_config(); + +add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') ); +add_event_handler('pre_trigger_event', array(&$obj, 'on_pre_trigger_event') ); +add_event_handler('post_trigger_event', array(&$obj, 'on_post_trigger_event') ); +add_event_handler('trigger_action', array(&$obj, 'on_trigger_action') ); +set_plugin_data($plugin['id'], $obj); +?> diff --git a/BSF/plugins/event_tracer/maintain.inc.php b/BSF/plugins/event_tracer/maintain.inc.php new file mode 100644 index 000000000..f7d0131c5 --- /dev/null +++ b/BSF/plugins/event_tracer/maintain.inc.php @@ -0,0 +1,9 @@ +<?php +if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); + +function plugin_uninstall($plugin_id) +{ + global $conf; + @unlink( $conf['local_data_dir'].'/plugins/'.$plugin_id.'.dat' ); +} +?> diff --git a/BSF/plugins/event_tracer/tracer_admin.php b/BSF/plugins/event_tracer/tracer_admin.php new file mode 100644 index 000000000..b17f2a301 --- /dev/null +++ b/BSF/plugins/event_tracer/tracer_admin.php @@ -0,0 +1,31 @@ +<?php +if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); + +$me = get_plugin_data($plugin_id); + +global $template; +$template->set_filenames( array('plugin_admin_content' => dirname(__FILE__).'/tracer_admin.tpl') ); + +if ( isset($_POST['eventTracer_filters']) ) +{ + $v = $_POST['eventTracer_filters']; + $v = str_replace( "\r\n", "\n", $v ); + $v = str_replace( "\n\n", "\n", $v ); + $v = stripslashes($v); + if (!empty($v)) + $me->my_config['filters'] = explode("\n", $v); + else + $me->my_config['filters'] = array(); + $me->my_config['show_args'] = isset($_POST['eventTracer_show_args']); + $me->save_config(); + global $page; + array_push($page['infos'], 'event tracer options saved'); +} +$template->assign('EVENT_TRACER_FILTERS', implode("\n", $me->my_config['filters'] ) ); +$template->assign('EVENT_TRACER_SHOW_ARGS', $me->my_config['show_args'] ? 'checked="checked"' : '' ); +$template->assign('U_LIST_EVENTS', get_admin_plugin_menu_link(dirname(__FILE__).'/event_list.php')); + +//$template->assign_var('EVENT_TRACER_F_ACTION', $my_url); + +$template->assign_var_from_handle( 'ADMIN_CONTENT', 'plugin_admin_content'); +?> diff --git a/BSF/plugins/event_tracer/tracer_admin.tpl b/BSF/plugins/event_tracer/tracer_admin.tpl new file mode 100644 index 000000000..17d7e2b01 --- /dev/null +++ b/BSF/plugins/event_tracer/tracer_admin.tpl @@ -0,0 +1,29 @@ +{* $Id$ *} +<div class="titrePage"> + <h2>Event Tracer</h2> +</div> + +<p> +The event tracer is a developer tool that logs in the footer of the window all calls to trigger_event method. +You can use this plugin to see what events is Piwigo calling. +<b>Note that $conf['show_queries'] must be true.</b> +</p> +<form method="post" action="" class="general"> +<fieldset> + <legend>Event Tracer</legend> + +<label>Show event argument + <input type="checkbox" name="eventTracer_show_args" {$EVENT_TRACER_SHOW_ARGS} /> +</label> +<br/> +<label>Fill below a list of regular expressions (one per line). +An event will be logged if its name matches at least one expression in the list. + <textarea name="eventTracer_filters" id="eventTracer_filters"rows="10" cols="80">{$EVENT_TRACER_FILTERS}</textarea> +</label> + +</fieldset> + +<p><input class="submit" type="submit" value="Submit" /></p> + +<p><a href="{$U_LIST_EVENTS}">Click here to see a complete list of actions and events trigered by this PWG version</a>.</p> +</form> |