- plugins can add now their page to the admin page

- new plugin (event_tracer) that demonstrate it and useful to see all calls 
to trigger_event

git-svn-id: http://piwigo.org/svn/trunk@1580 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2006-10-27 00:25:02 +00:00
parent 5cce84ff1c
commit 2b3bc579e4
10 changed files with 310 additions and 27 deletions

View file

@ -98,4 +98,19 @@ UPDATE '.CONFIG_TABLE.'
}
return false;
}
/*allows plugins to add their content to the administration page*/
function add_plugin_admin_menu($title, $func)
{
global $page;
$uid = md5( var_export($func, true) );
$page['plugin_admin_menu'][] =
array(
'title' => $title,
'function' => $func,
'uid' => $uid
);
}
?>

74
admin/plugin.php Normal file
View file

@ -0,0 +1,74 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
// +-----------------------------------------------------------------------+
// | 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. |
// +-----------------------------------------------------------------------+
if( !defined("PHPWG_ROOT_PATH") )
{
die ("Hacking attempt!");
}
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php');
check_status(ACCESS_ADMINISTRATOR);
$template->set_filenames(array('plugin' => 'admin/plugin.tpl'));
trigger_event('plugin_admin_menu');
if ( isset($page['plugin_admin_menu']) )
{
$template->assign_block_vars('plugin_menu.menu_item',
array(
'NAME' => l10n('Plugins'),
'URL' => PHPWG_ROOT_PATH.'admin.php?page=plugins'
)
);
$plug_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section=';
foreach ($page['plugin_admin_menu'] as $menu)
{
if (isset($_GET['section']) and $menu['uid']==$_GET['section'])
{
$found_menu=$menu;
}
$template->assign_block_vars('plugin_menu.menu_item',
array(
'NAME' => $menu['title'],
'URL' => $plug_base_url.$menu['uid']
)
);
}
}
if ( isset($found_menu) )
{
call_user_func(
$found_menu['function'],
PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section='.$found_menu['uid'] );
}
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin');
?>

View file

@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
@ -64,31 +64,61 @@ $plugins = get_plugins();
$template->set_filenames(array('plugins' => 'admin/plugins.tpl'));
if (count($plugins))
trigger_event('plugin_admin_menu');
$template->assign_block_vars('plugin_menu.menu_item',
array(
'NAME' => l10n('Plugins'),
'URL' => PHPWG_ROOT_PATH.'admin.php?page=plugins'
)
);
if ( isset($page['plugin_admin_menu']) )
{
$template->assign_block_vars( 'plugins', array() );
foreach( $plugins as $plugin_id => $plugin )
$plug_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugin&amp;section=';
foreach ($page['plugin_admin_menu'] as $menu)
{
$action_url = $my_base_url.'&amp;plugin='.$plugin_id;
if ( isset( $active_plugins[$plugin_id] ) )
{
$action_url .= '&amp;action=deactivate';
$action_name = l10n('Deactivate');
}
else
{
$action_url .= '&amp;action=activate';
$action_name = l10n('Activate');
}
$template->assign_block_vars( 'plugins.plugin',
$template->assign_block_vars('plugin_menu.menu_item',
array(
'NAME' => $plugin['name'],
'DESCRIPTION' => $plugin['description'],
'L_ACTION' => $action_name,
'U_ACTION' => $action_url,
)
);
'NAME' => $menu['title'],
'URL' => $plug_base_url.$menu['uid']
)
);
}
}
$num=0;
foreach( $plugins as $plugin_id => $plugin )
{
$action_url = $my_base_url.'&amp;plugin='.$plugin_id;
if ( isset( $active_plugins[$plugin_id] ) )
{
$action_url .= '&amp;action=deactivate';
$action_name = l10n('Deactivate');
}
else
{
$action_url .= '&amp;action=activate';
$action_name = l10n('Activate');
}
$display_name = $plugin['name'];
if ( !empty($plugin['uri']) )
{
$display_name='<a href="'.$plugin['uri'].'">'.$display_name.'</a>';
}
$template->assign_block_vars( 'plugins.plugin',
array(
'NAME' => $display_name,
'VERSION' => $plugin['version'],
'DESCRIPTION' => $plugin['description'],
'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1',
'L_ACTION' => $action_name,
'U_ACTION' => $action_url,
)
);
}
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugins');
?>

View file

@ -42,6 +42,7 @@ $lang['%d waiting pictures rejected'] = '%d waiting pictures rejected';
$lang['%d waiting pictures validated'] = '%d waiting pictures validated';
$lang['A new version of PhpWebGallery is available.'] = 'A new version of PhpWebGallery is available.';
$lang['Actions'] = 'Actions';
$lang['Activate'] = 'Activate';
$lang['Add a tag'] = 'Add a tag';
$lang['Add a user'] = 'Add a user';
$lang['Add group'] = 'Add group';
@ -65,6 +66,7 @@ $lang['Controversy'] = 'Controversy';
$lang['Creation date'] = 'Creation date';
$lang['Current name'] = 'Current name';
$lang['Database'] = 'Database';
$lang['Deactivate'] = 'Deactivate';
$lang['Delete Representant'] = 'Delete Representant';
$lang['Delete selected tags'] = 'Delete selected tags';
$lang['Delete selected users'] = 'Delete selected users';
@ -137,6 +139,7 @@ $lang['Permission granted'] = 'Permission granted';
$lang['PhpWebGallery Administration'] = 'PhpWebGallery Administration';
$lang['PhpWebGallery version'] = 'PhpWebGallery version';
$lang['Picture informations updated'] = 'Picture informations updated';
$lang['Plugins'] = 'Plugins';
$lang['Position'] = 'Position';
$lang['Preferences'] = 'Preferences';
$lang['Properties'] = 'Properties';
@ -175,6 +178,7 @@ $lang['Users'] = 'Users';
$lang['Validate All'] = 'Validate All';
$lang['Validate'] = 'Validate';
$lang['Validation'] = 'Validation';
$lang['Version'] = 'Version';
$lang['Virtual categories movement'] = 'Virtual categories movement';
$lang['Virtual categories to move'] = 'Virtual categories to move';
$lang['Virtual category name'] = 'Virtual category name';

View file

@ -42,6 +42,7 @@ $lang['%d waiting pictures rejected'] = '%d images en attente rejet
$lang['%d waiting pictures validated'] = '%d images en attente validées';
$lang['A new version of PhpWebGallery is available.'] = 'Une nouvelle version de PhpWebGallery est disponible.';
$lang['Actions'] = 'Actions';
$lang['Activate'] = 'Activer';
$lang['Add a tag'] = 'Ajouter un tag';
$lang['Add a user'] = 'Ajouter un utilisateur';
$lang['Add group'] = 'Ajouter un groupe';
@ -65,6 +66,7 @@ $lang['Controversy'] = 'Controverse';
$lang['Creation date'] = 'Date de création';
$lang['Current name'] = 'Nom courant';
$lang['Database'] = 'Base de données';
$lang['Deactivate'] = 'Désactiver';
$lang['Delete Representant'] = 'Supprimer le représentant';
$lang['Delete selected tags'] = 'Supprimer les tags sélectionnés';
$lang['Delete selected users'] = 'Supprimer les utilisateurs sélectionnés';
@ -137,6 +139,7 @@ $lang['Permission granted'] = 'Acc
$lang['PhpWebGallery Administration'] = 'Administration de PhpWebGallery';
$lang['PhpWebGallery version'] = 'Version de PhpWebGallery';
$lang['Picture informations updated'] = 'Informations de l\'image mises à jour';
$lang['Plugins'] = 'Plugins';
$lang['Position'] = 'Position';
$lang['Preferences'] = 'Préférences';
$lang['Properties'] = 'Propriétés';
@ -175,6 +178,7 @@ $lang['Users'] = 'Utilisateurs';
$lang['Validate All'] = 'Tout valider';
$lang['Validate'] = 'Valider';
$lang['Validation'] = 'Validation';
$lang['Version'] = 'Version';
$lang['Virtual categories movement'] = 'Déplacement de catégories virtuelles';
$lang['Virtual categories to move'] = 'Catégories virtuelles à déplacer';
$lang['Virtual category name'] = 'Nom de la catégorie virtuelle';

View file

@ -0,0 +1,90 @@
<?php
/*
Plugin Name: Event tracer
Version: 1.0
Description: For developers. Shows all calls to trigger_event.
Plugin URI: http://www.phpwebgallery.net
*/
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
class EventTracer
{
var $me_working;
var $my_config;
function EventTracer()
{
$this->me_working=0;
}
function load_config()
{
$x = @file_get_contents( dirname(__FILE__).'/tracer.dat' );
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()
{
$file = fopen( dirname(__FILE__).'/tracer.dat', 'w' );
fwrite($file, serialize($this->my_config) );
fclose( $file );
}
function pre_trigger_event($event_info)
{
if (!$this->me_working)
{
foreach( $this->my_config['filters'] as $filter)
{
if ( preg_match( '/'.$filter.'/', $event_info['event'] ) )
{
if ($this->my_config['show_args'])
$s = var_export( $event_info['data'], true );
else
$s = '';
pwg_debug('begin trigger_event "'.$event_info['event'].'" '.htmlspecialchars($s) );
break;
}
}
}
}
/*function post_trigger_event($filter_info)
{
if (!$this->me_working)
{
$s = var_export( $filter_info['data'], true );
pwg_debug('end trigger_event '.$filter_info['event'].' '.$s );
}
}*/
function plugin_admin_menu()
{
add_plugin_admin_menu( "Event Tracer", array(&$this, 'do_admin') );
}
function do_admin($my_url)
{
include( dirname(__FILE__).'/tracer_admin.php' );
}
}
$eventTracer = new EventTracer();
$eventTracer->load_config();
add_event_handler('plugin_admin_menu', array(&$eventTracer, 'plugin_admin_menu') );
add_event_handler('pre_trigger_event', array(&$eventTracer, 'pre_trigger_event') );
?>

View file

@ -0,0 +1,23 @@
<?php
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
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 );
$this->my_config['filters'] = explode("\n", $v);
$this->my_config['show_args'] = isset($_POST['eventTracer_show_args']);
$this->save_config();
global $page;
array_push($page['infos'], 'event tracer options saved');
}
$template->assign_var('EVENT_TRACER_FILTERS', implode("\n", $this->my_config['filters'] ) );
$template->assign_var('EVENT_TRACER_SHOW_ARGS', $this->my_config['show_args'] ? 'checked="checked"' : '' );
$template->assign_var('EVENT_TRACER_F_ACTION', $my_url);
$template->assign_var_from_handle( 'PLUGIN_ADMIN_CONTENT', 'plugin_admin_content');
?>

View file

@ -0,0 +1,22 @@
<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 PhpWebGallery calling.
<b>Note that $conf['show_queries'] must be true.</b>
</p>
<form method="post" action="{EVENT_TRACER_F_ACTION}" class="general">
<fieldset>
<legend>Event Tracer</legend>
<label>Show event argument
<input type="checkbox" name="eventTracer_show_args" value="{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 type="submit" value="Submit" /></p>
</form>

View file

@ -0,0 +1,12 @@
<div class="titrePage">
<h2>
<!-- BEGIN plugin_menu -->
<!-- BEGIN menu_item -->
<span style="margin-left:2px;"><a href="{plugin_menu.menu_item.URL}">{plugin_menu.menu_item.NAME}</a></span>
<!-- END menu_item -->
<!-- END plugin_menu -->
</h2>
</div>
{PLUGIN_ADMIN_CONTENT}

View file

@ -1,17 +1,26 @@
<div class="titrePage">
<h2>{lang:Plugins}</h2>
<h2>
<!-- BEGIN plugin_menu -->
<!-- BEGIN menu_item -->
<span style="margin-left:2px;"><a href="{plugin_menu.menu_item.URL}">{plugin_menu.menu_item.NAME}</a></span>
<!-- END menu_item -->
<!-- END plugin_menu -->
</h2>
</div>
<!-- BEGIN plugins -->
<table>
<thead><tr>
<table class="table2">
<thead><tr class="throw">
<td>{lang:Name}</td>
<td>{lang:Version}</td>
<td>{lang:Description}</td>
<td>{lang:Action}</td>
<td>{lang:Actions}</td>
</tr></thead>
<!-- BEGIN plugin -->
<tr>
<tr class="{plugins.plugin.CLASS}">
<td>{plugins.plugin.NAME}</td>
<td>{plugins.plugin.VERSION}</td>
<td>{plugins.plugin.DESCRIPTION}</td>
<td><a href="{plugins.plugin.U_ACTION}">{plugins.plugin.L_ACTION}</a></td>
</tr>