Wednesday 29 June 2005 9:10:14 am
It may not take as much time as you think - here is a solution that has the added benefit of being easily extendible to pass/manage other dynamic content/values: Add the following to the bottom of your pagelayout.tpl
<iframe style="visibility:hidden;" src="/utils.php"></iframe>
Implement utils.php as follows:
<?php
//
// Created on: <28-June-2005>
//
// Copyright (C) Geraint Edwards. All rights reserved.
//
// This file may be distributed and/or modified under the terms of the
// "GNU General Public License" version 2 as published by the Free
// Software Foundation and appearing in the file LICENSE.GPL included in
// the packaging of this file.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
// THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// send header information
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Pragma: no-cache' );
header( 'Content-Type: text/html;' );
//header( 'Content-Type: application/x-javascript;' );
include_once( "lib/ezutils/classes/ezini.php" );
include_once( "lib/ezutils/classes/ezdebug.php" );
include_once( "lib/ezutils/classes/ezdebugsetting.php" );
$debugINI =& eZINI::instance( 'debug.ini' );
eZDebugSetting::setDebugINI( $debugINI );
$ini =& eZINI::instance();
print "<html><head></head>";
if( include_once( "kernel/classes/datatypes/ezuser/ezuser.php" ) )
{
$currentUser =& eZUser::currentUser();
$user =& eZUser::currentUser();
$userID = $user->attribute( 'contentobject_id' );
$userObject = $user->attribute( 'contentobject' );
$userName = $userObject->name();
print "<script language='JavaScript' type='text/javascript'>";
if ($currentUser->ContentObjectID== $ini->variable('UserSettings', 'AnonymousUserID' ) )
{
print "var loggedIn=false;";
print "var userName='';";
}
else {
print "var loggedIn=true;";
print "var userName='".$currentUser->Login."';";
}
print "if (window.parent && window.parent.setupUserLoggedIn!=null) window.parent.setupUserLoggedIn(loggedIn, userName);";
}
print "</script></body></html>";
Then use a login.tpl along the following lines:
{section show=$first}
<ul>
{/section}
<script>
{literal}
function setupUserLoggedIn(loggedIn, UserName)
{
if (loggedIn) {
document.getElementById("userNotLoggedIn").style.display="none";
document.getElementById("loginusername").innerHTML=UserName;
document.getElementById("userLoggedIn").style.display="inline";
}
else {
document.getElementById("userLoggedIn").style.display="none";
document.getElementById("loginusername").innerHTML="";
document.getElementById("userNotLoggedIn").style.display="inline";
}
}
{/literal}
</script>
<li class="toolbar-item {$placement}">
<span id="userNotLoggedIn" style="display:none"><a href={"/user/login"|ezurl}>{"Login"|i18n("design/standard/toolbar")}</a> </span>
<span id="userLoggedIn" style="display:inline"><a
href={"/user/logout"|ezurl}>{"Logout"|i18n("design/standard/toolbar")}(<span id="loginusername"></span>)</a> </span>
</li>
{section show=$last}
</ul>
{/section}
This solution can be improved to force a fresh request to utils.php by adding a random query string to the src for the IFrame, otherwise there is a risk that a badly configured proxy or web browser cache could result in the wrong user data being obtained. The only risk is that someone else's username would be revealed - they can't do too much with a username alone!
|