SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: KahneFan on June 17, 2009, 10:34:11 PM

Title: SP 2.2.2 - Login / Register (smart) block?
Post by: KahneFan on June 17, 2009, 10:34:11 PM
Might it be possible to create a "smart" login / register block? I know most themes have the obligatory login area, but it might be nice if we could actually have a block which appears when user's are not logged in, which would give the "Please click here to register or login below". And, if a user is logged in, it would not appear. I know the user information block does this, but I don't usually use that at the top of my site, and a block of the login nature would be the very 1st block guests would see (on my site).
Title: Re: SP 2.2.2 - Login / Register (smart) block?
Post by: ???1031 on June 18, 2009, 11:46:06 AM
Might it be possible to create a "smart" login / register block? I know most themes have the obligatory login area, but it might be nice if we could actually have a block which appears when user's are not logged in, which would give the "Please click here to register or login below". And, if a user is logged in, it would not appear. I know the user information block does this, but I don't usually use that at the top of my site, and a block of the login nature would be the very 1st block guests would see (on my site).
If you add the user informations than this will be shown on the user info if he is not logged in.

Bye
DIN1031
Title: Re: SP 2.2.2 - Login / Register (smart) block?
Post by: KahneFan on June 18, 2009, 11:52:55 AM
...I know the user information block does this, but I don't usually use that at the top of my site, and a block of the login nature would be the very 1st block guests would see (on my site).

If you add the user informations than this will be shown on the user info if he is not logged in.

Bye
DIN1031
Title: Re: SP 2.2.2 - Login / Register (smart) block?
Post by: ???1031 on June 19, 2009, 04:10:31 AM
... you're right ... i did not read it...

Create a PHP block and insert this: (Select the code for your smf version).

SMF 1.1+
Code: [Select]
/*
Name: Simple Login Box
Author: DIN1031
Version: 1.0.0
Last updated: 19-06-09 10:27 CET

Requirements:
SMF Version: 1.1+
Simple Portal: 2.2+

Description:
Show a simple login and if the user is logged it show only an Hello.
You can setup permissions that only guests can see this block (Except admins, they can see it anyway)
*/

if (!function_exists('sp_simpleLogin'))
{
function sp_simpleLogin($parameters, $id, $return_parameters = false)
{
global $context, $txt, $scripturl, $memberContext, $modSettings, $user_info, $color_profile;

$block_parameters = array();

if ($return_parameters)
return $block_parameters;

echo '
<div class="sp_center sp_fullwidth">';

if ($context['user']['is_guest'])
{
echo '
<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '">
<table>
<tr>
<td class="sp_right"><label for="sp_user">', $txt[35], ':</label>&nbsp;</td>
<td><input type="text" id="sp_user" name="user" size="9" value="', !empty($user_info['username']) ? $user_info['username'] : '', '" /></td>
</tr><tr>
<td class="sp_right"><label for="sp_passwrd">', $txt[36], ':</label>&nbsp;</td>
<td><input type="password" name="passwrd" id="sp_passwrd" size="9" /></td>
</tr><tr>
<td>
<select name="cookielength">
<option value="60">', $txt['smf53'], '</option>
<option value="1440">', $txt['smf47'], '</option>
<option value="10080">', $txt['smf48'], '</option>
<option value="43200">', $txt['smf49'], '</option>
<option value="-1" selected="selected">', $txt['smf50'], '</option>
</select>
</td>
<td><input type="submit" value="', $txt[34], '" /></td>
</tr>
</table>
</form>', $txt['welcome_guest'];
}
else
{
loadMemberData($context['user']['id']);
loadMemberContext($context['user']['id']);

$member_info = $memberContext[$context['user']['id']];

if (empty($modSettings['MemberColorLinkInstalled']) && sp_loadColors($member_info['id']) !== false)
$member_info['colored_name'] = $color_profile[$member_info['id']]['colored_name'];

echo '
', $txt['hello_member'], ' <strong>', !empty($member_info['colored_name']) ? $member_info['colored_name'] : $member_info['name'], '</strong>
<br /><br />';
}

echo '
</div>';
}
}
sp_simpleLogin($parameters, $id);

SMF 2.0+
Code: [Select]
/*
Name: Simple Login Box
Author: DIN1031
Version: 1.0.0
Last updated: 19-06-09 10:27 CET

Requirements:
SMF Version: 2.0+
Simple Portal: 2.2+

Description:
Show a simple login and if the user is logged it show only an Hello.
You can setup permissions that only guests can see this block (Except admins, they can see it anyway)
*/

if (!function_exists('sp_simpleLogin'))
{
function sp_simpleLogin($parameters, $id, $return_parameters = false)
{
global $context, $txt, $scripturl, $memberContext, $modSettings, $user_info, $color_profile;

$block_parameters = array();

if ($return_parameters)
return $block_parameters;

echo '
<div class="sp_center sp_fullwidth">';

if ($context['user']['is_guest'])
{
echo '
<form action="', $scripturl, '?action=login2" method="post" accept-charset="', $context['character_set'], '">
<table>
<tr>
<td class="sp_right"><label for="sp_user">', $txt['username'], ':</label>&nbsp;</td>
<td><input type="text" id="sp_user" name="user" size="9" value="', !empty($user_info['username']) ? $user_info['username'] : '', '" /></td>
</tr><tr>
<td class="sp_right"><label for="sp_passwrd">', $txt['password'], ':</label>&nbsp;</td>
<td><input type="password" name="passwrd" id="sp_passwrd" size="9" /></td>
</tr><tr>
<td>
<select name="cookielength">
<option value="60">', $txt['one_hour'], '</option>
<option value="1440">', $txt['one_day'], '</option>
<option value="10080">', $txt['one_week'], '</option>
<option value="43200">', $txt['one_month'], '</option>
<option value="-1" selected="selected">', $txt['forever'], '</option>
</select>
</td>
<td><input type="submit" value="', $txt['login'], '" /></td>
</tr>
</table>
</form>', sprintf($txt['welcome_guest'], $txt['guest_title']);
}
else
{
loadMemberData($user_info['id']);
loadMemberContext($user_info['id']);

$member_info = $memberContext[$user_info['id']];

if (empty($modSettings['MemberColorLinkInstalled']) && sp_loadColors($member_info['id']) !== false)
$member_info['colored_name'] = $color_profile[$member_info['id']]['colored_name'];

$member_info['karma']['total'] = $member_info['karma']['good'] - $member_info['karma']['bad'];

echo '
', $txt['hello_member'], ' <strong>', !empty($member_info['colored_name']) ? $member_info['colored_name'] : $member_info['name'], '</strong>
<br /><br />';
}

echo '
</div>';
}
}
sp_simpleLogin($parameters, $id);

You can give a permission that only guests can see this block ;). (Except Admins, they can see it anyway),

Bye
DIN1031
Title: Re: SP 2.2.2 - Login / Register (smart) block?
Post by: KahneFan on June 19, 2009, 07:51:24 AM
Perfect, thanks! I tested it as a regular member and it goes away. As an admin, I'll just shrink it. Thanks.
SimplePortal 2.3.8 © 2008-2024, SimplePortal