diff options
-rw-r--r-- | admin/include/functions_plugins.inc.php | 15 | ||||
-rw-r--r-- | admin/plugin.php | 74 | ||||
-rw-r--r-- | admin/plugins.php | 74 | ||||
-rw-r--r-- | language/en_UK.iso-8859-1/admin.lang.php | 4 | ||||
-rw-r--r-- | language/fr_FR.iso-8859-1/admin.lang.php | 4 | ||||
-rw-r--r-- | plugins/event_tracer/index.php | 90 | ||||
-rw-r--r-- | plugins/event_tracer/tracer_admin.php | 23 | ||||
-rw-r--r-- | plugins/event_tracer/tracer_admin.tpl | 22 | ||||
-rw-r--r-- | template/yoga/admin/plugin.tpl | 12 | ||||
-rw-r--r-- | template/yoga/admin/plugins.tpl | 19 |
10 files changed, 310 insertions, 27 deletions
diff --git a/admin/include/functions_plugins.inc.php b/admin/include/functions_plugins.inc.php index bb85e15f6..91266841b 100644 --- a/admin/include/functions_plugins.inc.php +++ b/admin/include/functions_plugins.inc.php @@ -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 + ); +} + ?>
\ No newline at end of file diff --git a/admin/plugin.php b/admin/plugin.php new file mode 100644 index 000000000..08afccc61 --- /dev/null +++ b/admin/plugin.php @@ -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&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&section='.$found_menu['uid'] ); +} + +$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin'); +?> diff --git a/admin/plugins.php b/admin/plugins.php index 04c79aeca..e187cac21 100644 --- a/admin/plugins.php +++ b/admin/plugins.php @@ -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&section='; + foreach ($page['plugin_admin_menu'] as $menu) { - $action_url = $my_base_url.'&plugin='.$plugin_id; - if ( isset( $active_plugins[$plugin_id] ) ) - { - $action_url .= '&action=deactivate'; - $action_name = l10n('Deactivate'); - } - else - { - $action_url .= '&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.'&plugin='.$plugin_id; + if ( isset( $active_plugins[$plugin_id] ) ) + { + $action_url .= '&action=deactivate'; + $action_name = l10n('Deactivate'); + } + else + { + $action_url .= '&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'); ?> diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php index 32857e949..adf98646d 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -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'; diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php index 2c80ed08a..0dfb32044 100644 --- a/language/fr_FR.iso-8859-1/admin.lang.php +++ b/language/fr_FR.iso-8859-1/admin.lang.php @@ -42,6 +42,7 @@ $lang['%d waiting pictures rejected'] = '%d images en attente rejetées'; $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ès autorisé'; $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'; diff --git a/plugins/event_tracer/index.php b/plugins/event_tracer/index.php new file mode 100644 index 000000000..cc9130b67 --- /dev/null +++ b/plugins/event_tracer/index.php @@ -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') ); +?>
\ No newline at end of file diff --git a/plugins/event_tracer/tracer_admin.php b/plugins/event_tracer/tracer_admin.php new file mode 100644 index 000000000..9231638b1 --- /dev/null +++ b/plugins/event_tracer/tracer_admin.php @@ -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'); +?>
\ No newline at end of file diff --git a/plugins/event_tracer/tracer_admin.tpl b/plugins/event_tracer/tracer_admin.tpl new file mode 100644 index 000000000..38fbd2796 --- /dev/null +++ b/plugins/event_tracer/tracer_admin.tpl @@ -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> diff --git a/template/yoga/admin/plugin.tpl b/template/yoga/admin/plugin.tpl new file mode 100644 index 000000000..96b0c3ae8 --- /dev/null +++ b/template/yoga/admin/plugin.tpl @@ -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} diff --git a/template/yoga/admin/plugins.tpl b/template/yoga/admin/plugins.tpl index 81bade54d..ef45360f1 100644 --- a/template/yoga/admin/plugins.tpl +++ b/template/yoga/admin/plugins.tpl @@ -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> |