aboutsummaryrefslogtreecommitdiffstats
path: root/BSF/plugins/admin_multi_view
diff options
context:
space:
mode:
authorvdigital <vdigital@piwigo.org>2008-05-23 21:05:41 +0000
committervdigital <vdigital@piwigo.org>2008-05-23 21:05:41 +0000
commit77fd1f51a3c5f5a52f72ef8a299fe368228e2285 (patch)
treea67ede42904657ccf3349ecdaef1cec8b8e36ff8 /BSF/plugins/admin_multi_view
parent553727dffacc48e8337c1d141f2a25af359e74b1 (diff)
git-svn-id: http://piwigo.org/svn/trunk@2357 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'BSF/plugins/admin_multi_view')
-rw-r--r--BSF/plugins/admin_multi_view/controller.php221
-rw-r--r--BSF/plugins/admin_multi_view/index.php30
-rw-r--r--BSF/plugins/admin_multi_view/is_admin.inc.php47
-rw-r--r--BSF/plugins/admin_multi_view/main.inc.php42
4 files changed, 340 insertions, 0 deletions
diff --git a/BSF/plugins/admin_multi_view/controller.php b/BSF/plugins/admin_multi_view/controller.php
new file mode 100644
index 000000000..861df63a7
--- /dev/null
+++ b/BSF/plugins/admin_multi_view/controller.php
@@ -0,0 +1,221 @@
+<?php
+define('MULTIVIEW_CONTROLLER', 1);
+define('PHPWG_ROOT_PATH','../../');
+include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
+
+if (!is_admin() or !function_exists('multiview_user_init') )
+{
+ pwg_unset_session_var( 'multiview_as' );
+ pwg_unset_session_var( 'multiview_theme' );
+ pwg_unset_session_var( 'multiview_lang' );
+ pwg_unset_session_var( 'multiview_show_queries' );
+ pwg_unset_session_var( 'multiview_debug_l10n' );
+ pwg_unset_session_var( 'multiview_debug_template' );
+?>
+
+<script type="text/javascript">
+ window.close();
+</script>
+<?php
+ exit();
+}
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+"http://www.w3.org/TR/html4/strict.dtd">
+<?php
+
+$refresh_main = false;
+
+if ( isset($_GET['view_as']) )
+{
+ if ( is_adviser() and $user['id']!=$_GET['view_as'] and $conf['guest_id']!=$_GET['view_as'])
+ die('security error');
+ pwg_set_session_var( 'multiview_as', (int)$_GET['view_as'] );
+ // user change resets theme/lang
+ pwg_unset_session_var( 'multiview_theme' );
+ pwg_unset_session_var( 'multiview_lang' );
+ $refresh_main = true;
+}
+if (pwg_get_session_var( 'multiview_as', $user['id']) != $user['id'] )
+ $view_as_user = build_user( pwg_get_session_var( 'multiview_as',0), false);
+else
+ $view_as_user = $user;
+
+if ( isset($_GET['theme']) )
+{
+ pwg_set_session_var( 'multiview_theme', $_GET['theme'] );
+ $refresh_main = true;
+}
+
+if ( isset($_GET['lang']) )
+{
+ pwg_set_session_var( 'multiview_lang', $_GET['lang'] );
+ $refresh_main = true;
+}
+
+if ( isset($_GET['show_queries']) )
+{
+ if ( $_GET['show_queries']> 0 )
+ pwg_set_session_var( 'multiview_show_queries', 1 );
+ else
+ pwg_unset_session_var( 'multiview_show_queries' );
+ $refresh_main = true;
+}
+
+if ( isset($_GET['debug_l10n']) )
+{
+ if ( $_GET['debug_l10n']>0 )
+ pwg_set_session_var( 'multiview_debug_l10n', 1 );
+ else
+ pwg_unset_session_var( 'multiview_debug_l10n' );
+ $refresh_main = true;
+}
+
+
+if ( isset($_GET['debug_template']) )
+{
+ if ( $_GET['debug_template']>0 )
+ pwg_set_session_var( 'multiview_debug_template', 1 );
+ else
+ pwg_unset_session_var( 'multiview_debug_template' );
+ $refresh_main = true;
+}
+
+$my_url = get_root_url().'plugins/'.basename(dirname(__FILE__)).'/'.basename(__FILE__);
+
+// +-----------------------------------------------------------------------+
+// | users |
+$query = '
+SELECT '.$conf['user_fields']['id'].' AS id,'.$conf['user_fields']['username'].' AS username
+FROM '.USERS_TABLE;
+if (is_adviser())
+{
+ $query .='
+ WHERE '.$conf['user_fields']['id']. ' IN ('.$user['id'].','.$conf['guest_id'].')
+';
+}
+$query .='
+ ORDER BY CONVERT('.$conf['user_fields']['username'].',CHAR)
+;';
+$user_map = simple_hash_from_query($query, 'id', 'username');
+
+$users_html = '<select onchange="document.location = this.options[this.selectedIndex].value;">';
+foreach( $user_map as $id=>$username)
+{
+ $selected = ($id==$view_as_user['id']) ? 'selected="selected"' : '';
+ $users_html .=
+ '<option value="'
+ .$my_url.'?view_as='.$id
+ .'" '.$selected.'>'
+ .$username
+ .'</option>';
+}
+$users_html.= '</select>';
+
+
+// +-----------------------------------------------------------------------+
+// | templates |
+$my_template = '';
+$themes_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
+foreach (get_pwg_themes() as $pwg_template)
+{
+ $selected = $pwg_template == pwg_get_session_var( 'multiview_theme', $view_as_user['template'].'/'.$view_as_user['theme'] ) ? 'selected="selected"' : '';
+ $my_template = $selected == '' ? $my_template : $view_as_user['template'].'/theme/'.$view_as_user['theme'];
+ $themes_html .=
+ '<option value="'
+ .$my_url.'?theme='.$pwg_template
+ .'" '.$selected.'>'
+ .$pwg_template
+ .'</option>';
+}
+$themes_html .= '</select>';
+
+// +-----------------------------------------------------------------------+
+// | language |
+$lang_html='<select onchange="document.location = this.options[this.selectedIndex].value;">';
+foreach (get_languages() as $language_code => $language_name)
+{
+ $selected = $language_code == pwg_get_session_var( 'multiview_lang', $view_as_user['language'] ) ? 'selected="selected"' : '';
+ $lang_html .=
+ '<option value="'
+ .$my_url.'?lang='.$language_code
+ .'" '.$selected.'>'
+ .$language_name
+ .'</option>';
+}
+$lang_html .= '</select>';
+
+// +-----------------------------------------------------------------------+
+// | show queries |
+$show_queries_html='';
+if (!$conf['show_queries'])
+{
+ if ( !pwg_get_session_var( 'multiview_show_queries', 0 ) )
+ $show_queries_html.='<a href="'.$my_url.'?show_queries=1">Show SQL queries</a>';
+ else
+ $show_queries_html.='<a href="'.$my_url.'?show_queries=0">Hide SQL queries</a>';
+}
+
+// +-----------------------------------------------------------------------+
+// | debug language |
+$debug_l10n_html='';
+if (!$conf['debug_l10n'])
+{
+ if ( !pwg_get_session_var( 'multiview_debug_l10n', 0 ) )
+ $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=1">Debug language</a>';
+ else
+ $debug_l10n_html.='<a href="'.$my_url.'?debug_l10n=0">Revert debug language</a>';
+}
+
+// +-----------------------------------------------------------------------+
+// | debug template |
+$debug_template_html='';
+if (!$conf['debug_template'])
+{
+ if ( !pwg_get_session_var( 'multiview_debug_template', 0 ) )
+ $debug_template_html.='<a href="'.$my_url.'?debug_template=1">Debug template</a>';
+ else
+ $debug_template_html.='<a href="'.$my_url.'?debug_template=0">Revert debug template</a>';
+}
+
+?>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo get_pwg_charset() ?>">
+<title>Controller</title>
+<?php
+// Controller will be displayed with the **real admin template** (without Any if it has been removed)
+if ( $my_template !== '') {
+ $my_template = get_root_url().'template/'.$my_template.'/theme.css';
+ echo '<link rel="stylesheet" type="text/css" href="' . $my_template .'">';
+}
+?>
+
+</head>
+<body>
+<div>
+<script type="text/javascript">
+if (window.opener==null) {
+ window.close();
+ document.write("<"+"h2>How did you get here ???<"+"/h2>");
+}
+</script>
+
+<table>
+<tr><td>User</td><td><?php echo $users_html; ?></td></tr>
+
+<tr><td>Theme</td><td><?php echo $themes_html; ?></td></tr>
+
+<tr><td>Lang</td><td><?php echo $lang_html; ?></td></tr>
+</table>
+<?php echo implode( "<br/>\n", array($show_queries_html, $debug_l10n_html, $debug_template_html) ); ?>
+
+<script type="text/javascript">
+<?php
+ if ($refresh_main) echo '
+window.opener.location = window.opener.location;';
+?>
+</script>
+</div>
+</body>
+</html>
diff --git a/BSF/plugins/admin_multi_view/index.php b/BSF/plugins/admin_multi_view/index.php
new file mode 100644
index 000000000..c15b15795
--- /dev/null
+++ b/BSF/plugins/admin_multi_view/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/admin_multi_view/is_admin.inc.php b/BSF/plugins/admin_multi_view/is_admin.inc.php
new file mode 100644
index 000000000..7ae1f90dc
--- /dev/null
+++ b/BSF/plugins/admin_multi_view/is_admin.inc.php
@@ -0,0 +1,47 @@
+<?php
+if (! defined('MULTIVIEW_CONTROLLER') )
+{
+ global $user;
+ $view_as = pwg_get_session_var( 'multiview_as', 0 );
+ if ($view_as)
+ {
+ $user = build_user( $view_as, true);
+ }
+ $theme = pwg_get_session_var( 'multiview_theme', '' );
+ if ( !empty($theme) )
+ {
+ list($user['template'], $user['theme']) = explode('/', $theme);
+ unset( $user['admin_template'], $user['admin_theme']);
+ }
+ $lang = pwg_get_session_var( 'multiview_lang', '' );
+ if ( !empty($lang) )
+ {
+ $user['language'] = $lang;
+ }
+ global $conf;
+ if (pwg_get_session_var( 'multiview_show_queries', 0 ))
+ $conf['show_queries'] = true;
+ if (pwg_get_session_var( 'multiview_debug_l10n', 0 ))
+ $conf['debug_l10n'] = true;
+ if (pwg_get_session_var( 'multiview_debug_template', 0 ))
+ $conf['debug_template'] = true;
+}
+
+add_event_handler('loc_end_page_header', 'multiview_loc_end_page_header');
+
+function multiview_loc_end_page_header()
+{
+ global $template;
+ $my_root_url = get_root_url().'plugins/'. basename(dirname(__FILE__)).'/';
+ $js =
+'<script type="text/javascript">
+var theController = window.open("", "mview_controller", "alwaysRaised=yes,dependent=yes,toolbar=no,height=200,width=220,menubar=no,resizable=yes,scrollbars=yes,status=no");
+if ( theController.location.toString()=="about:blank" || !theController.location.toString().match(/^(https?.*\/)controller\.php(\?.+)?$/))
+{
+ theController.location = "'.$my_root_url.'controller.php";
+}
+</script>';
+
+ $template->append( 'head_elements', $js );
+}
+?>
diff --git a/BSF/plugins/admin_multi_view/main.inc.php b/BSF/plugins/admin_multi_view/main.inc.php
new file mode 100644
index 000000000..d29486fd0
--- /dev/null
+++ b/BSF/plugins/admin_multi_view/main.inc.php
@@ -0,0 +1,42 @@
+<?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: Multi view
+Version: 1.8
+Description: Allows administrators to view gallery as guests and/or change the language and/or theme on the fly. Practical to debug changes ...
+Plugin URI: http://piwigo.org
+Author: Piwigo team
+Author URI: http://piwigo.org
+*/
+
+add_event_handler('user_init', 'multiview_user_init' );
+
+function multiview_user_init()
+{
+ if (!is_admin())
+ return;
+ include_once( dirname(__FILE__).'/is_admin.inc.php' );
+}
+
+?>