From 2b3bc579e4dcd4bf64c712eeca86f05e2d70fbf0 Mon Sep 17 00:00:00 2001 From: rvelices Date: Fri, 27 Oct 2006 00:25:02 +0000 Subject: - 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 --- admin/include/functions_plugins.inc.php | 15 ++++++ admin/plugin.php | 74 ++++++++++++++++++++++++++ admin/plugins.php | 74 ++++++++++++++++++-------- language/en_UK.iso-8859-1/admin.lang.php | 4 ++ language/fr_FR.iso-8859-1/admin.lang.php | 4 ++ plugins/event_tracer/index.php | 90 ++++++++++++++++++++++++++++++++ plugins/event_tracer/tracer_admin.php | 23 ++++++++ plugins/event_tracer/tracer_admin.tpl | 22 ++++++++ template/yoga/admin/plugin.tpl | 12 +++++ template/yoga/admin/plugins.tpl | 19 +++++-- 10 files changed, 310 insertions(+), 27 deletions(-) create mode 100644 admin/plugin.php create mode 100644 plugins/event_tracer/index.php create mode 100644 plugins/event_tracer/tracer_admin.php create mode 100644 plugins/event_tracer/tracer_admin.tpl create mode 100644 template/yoga/admin/plugin.tpl 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 @@ +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=''.$display_name.''; + } + $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 $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'; 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 @@ +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 @@ +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 @@ +

+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. +Note that $conf['show_queries'] must be true. +

+
+
+ Event Tracer + + +
+ + +
+ +

+
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 @@ +
+

+ + + {plugin_menu.menu_item.NAME} + + +

+
+ + +{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 @@
-

{lang:Plugins}

+

+ + + {plugin_menu.menu_item.NAME} + + +

+ - - +
+ + - + - + + -- cgit v1.2.3
{lang:Name}{lang:Version} {lang:Description}{lang:Action}{lang:Actions}
{plugins.plugin.NAME}{plugins.plugin.VERSION} {plugins.plugin.DESCRIPTION} {plugins.plugin.L_ACTION}