TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,970
  • Latest: bynw
Stats
  • Total Posts: 196,062
  • Total Topics: 21,338
  • Online today: 171
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 170
  • Total: 170

modified userbox

Started by hsdk, November 26, 2006, 07:49:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

hsdk

Hi, I have modified the userbox in TPortalBlocks.template.php a little bit, and i would like to share it with the rest of you.
This is kind of newbie stuff, so be nice to me :)

I have added in the bullet list of the userbox:


  • Logout
  • Submit Article
  • Upload File
  • Link
  • Admin

To use it, just replace the TPortal_userbox() function in TPortalBlocks.template.php. Or just add the function itself to a phpbox. You can edit the link and the link titile in the code. The submit article, upload file and admin lines will only show for thoose allowed to view them.


//modifies userbox, with logout button, submit links and a extra link
function TPortal_userbox()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;

$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet2 = '<img src="'.$settings['images_url'].'/TPdivider2.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet3 = '<img src="'.$settings['images_url'].'/TPdivider3.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet4 = '<img src="'.$settings['images_url'].'/tpgoto.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet5 = '<img src="'.$settings['images_url'].'/tpmodule2.gif" alt="" border="0" style="margin:0 2px 0 0;" />';

echo'
<table width="99%" cellpadding="0" cellspacing="5" border="0">
<tr>
<td width="100%" valign="top" class="smalltext" style="font-family: verdana, arial, sans-serif;">';

if (!empty($context['user']['avatar']) && isset($context['TPortal']['userbox']['avatar']))
echo $context['user']['avatar']['image'] . '<br />';

// If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged']){
echo '<span class="normaltext">', $txt['hello_member'], ' <b>', $context['user']['name'], '</b></span>';

// Only tell them about their messages if they can read their messages!
if ($context['allow_pm']){
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=pm">' .$txt['tp-pm'].' ', $context['user']['messages'], '</a>';
if($context['user']['unread_messages']>0)
echo '<br />'.$bullet.'<a style="font-weight: bold; " href="', $scripturl, '?action=pm">' .$txt['tp-pm2'].' ',$context['user']

['unread_messages'] , '</a>';
}
// Are there any members waiting for approval?
if (!empty($context['unapproved_members']))
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=viewmembers;sa=browse;type=approve">'.$txt['tp_unapproved_members'].'<b> '. $context

['unapproved_members']  . '</b></a>';

if(isset($context['TPortal']['userbox']['unread'])){
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=unread">' .$txt['tp-unread'].'</a>
<br />'.$bullet.'<a href="', $scripturl, '?action=unreadreplies">'.$txt['tp-replies'].'</a>
<br />'.$bullet.'<a href="', $scripturl, '?action=profile;u='.$context['user']['id'].';sa=showPosts">'.$txt['tp-showownposts'].'</a>';
}

// Is the forum in maintenance mode?
if ($context['in_maintenance'] && $context['user']['is_admin'])
echo '<br /><b>' .$bullet.$txt['tp_maintenace']. '</b>';

//Show the logout button in your userbox
if($context['user']['is_logged'])
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'],'">'.$txt[108].' </a><br />';

// If user is allowed to submit articles, show the link here
              if($context['TPortal']['can_submit_article']==1 && !allowedTo('tp_articles'))
                       echo $bullet.'<a href="', $scripturl, '?action=tpmod;sa=submitarticle">' . $txt['tp-submitarticle']. '</a><br />';

// same for upload, show if allowed
              if(allowedTo('tp_dlupload') || allowedTo('tp_dlmanager'))
                       echo $bullet.'<a href="', $scripturl, '?action=tpmod;dl=upload">' . $txt['permissionname_tp_dlupload']. '</a><br />';
// If user is logged in, display a link to a page you choose.
if ($context['user']['is_logged'])
echo $bullet. '<a href="choose a page">link title</a>';
//if user has admin right, display a link to the admin section
if ($context['user']['is_admin'])
echo $bullet. ''<a href="', $scripturl, '?action=admin">'Admin</a>';
echo '</div>';
}
// Otherwise they're a guest - so politely ask them to register or login.
else{
echo '
', $txt['welcome_guest'], '<br />
', $context['current_time'], '<br />
<form action="', $scripturl, '?action=login2" method="post" >
<input type="text" name="user" size="10" /> <input type="password" name="passwrd" size="10" />
        <select name="cookielength">
<option value="60">', $txt['smf53'], '</option>
<option value="1440">', $txt['smf47'], '</option>
<option value="10080">', $txt['smf48'], '</option>
<option value="302400">', $txt['smf49'], '</option>
<option value="-1" selected="selected">', $txt['smf50'], '</option>
</select>
        <input type="submit" value="', $txt[34], '" /><br />
        ', $txt['smf52'], '
</form>';
}
echo ' <br />
</td>
</tr>
</table>';
}

IchBin

A picture or a demo would be fantastic so everyone could see exactly what it looks like. :)

hsdk

Quote from: IchBinâââ,¬Å¾Ã,¢ on November 27, 2006, 12:01:11 AM
A picture or a demo would be fantastic so everyone could see exactly what it looks like. :)

Added a picture to the first post :)

akulion


RoarinRow


SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

pvcblue

picture looks nice - but when used it doesn't work, template parse error something wrong with this line - //if user has admin right, display a link to the admin section
            if ($context['user']['is_admin'])
            echo $bullet. ''<a href="', $scripturl, '?action=admin">'Admin</a>';

hsdk

#6
author=pvcblue link=topic=10861.msg89582#msg89582 date=1164603776]
picture looks nice - but when used it doesn't work, template parse error something wrong with this line - //if user has admin right, display a link to the admin section
if ($context['user']['is_admin'])
echo $bullet. ''<a href="', $scripturl, '?action=admin">'Admin</a>';


Hmm, just replace the href with the actual link to wour admin page.

Techdomain

#7
The code was slightly wrong -

find:

// If user is logged in, display a link to a page you choose.
if ($context['user']['is_logged'])
echo $bullet. '<a href="choose a page">link title</a>';
//if user has admin right, display a link to the admin section
if ($context['user']['is_admin'])
echo $bullet. ''<a href="', $scripturl, '?action=admin">'Admin</a>';



Replace with:

// If user is logged in, display a link to a page you choose.
if ($context['user']['is_logged'])
echo $bullet. '<a href="Put your link in here">Your Link Name</a><br />';
                        //if user has admin right, display a link to the admin section
if ($context['user']['is_admin'])
echo $bullet. '<a href="', $scripturl, '?action=admin">Admin</a>';


The admin bit had a couple of ' in the wrong place (at start and before Admin), and the link above it needed a break <br />

Like the code though, and am now using it :)

Techdomain

I added in the time (the code for the total time logged is still there also, but commented out)


// Tportal userbox
//modifies userbox, with logout button, submit links and a extra link
function TPortal_userbox()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;

$bullet = '<img src="'.$settings['images_url'].'/TPdivider.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet2 = '<img src="'.$settings['images_url'].'/TPdivider2.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet3 = '<img src="'.$settings['images_url'].'/TPdivider3.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet4 = '<img src="'.$settings['images_url'].'/tpgoto.gif" alt="" border="0" style="margin:0 2px 0 0;" />';
$bullet5 = '<img src="'.$settings['images_url'].'/tpmodule2.gif" alt="" border="0" style="margin:0 2px 0 0;" />';

echo'
<table width="99%" cellpadding="0" cellspacing="5" border="0">
<tr>
<td width="100%" valign="top" class="smalltext" style="font-family: verdana, arial, sans-serif;">';

if (!empty($context['user']['avatar']) && isset($context['TPortal']['userbox']['avatar']))
echo $context['user']['avatar']['image'] . '<br />';

// If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged']){
echo '<span class="normaltext">', $txt['hello_member'], ' <b>', $context['user']['name'], '</b></span>';

// Only tell them about their messages if they can read their messages!
if ($context['allow_pm']){
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=pm">' .$txt['tp-pm'].' ', $context['user']['messages'], '</a>';
if($context['user']['unread_messages']>0)
echo '<br />'.$bullet.'<a style="font-weight: bold; " href="', $scripturl, '?action=pm">' .$txt['tp-pm2'].' ',$context['user']

['unread_messages'] , '</a>';
}
// Are there any members waiting for approval?
if (!empty($context['unapproved_members']))
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=viewmembers;sa=browse;type=approve">'.$txt['tp_unapproved_members'].'<b> '. $context

['unapproved_members']  . '</b></a>';

if(isset($context['TPortal']['userbox']['unread'])){
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=unread">' .$txt['tp-unread'].'</a>
<br />'.$bullet.'<a href="', $scripturl, '?action=unreadreplies">'.$txt['tp-replies'].'</a>
<br />'.$bullet.'<a href="', $scripturl, '?action=profile;u='.$context['user']['id'].';sa=showPosts">'.$txt['tp-showownposts'].'</a>';
}

// Is the forum in maintenance mode?
if ($context['in_maintenance'] && $context['user']['is_admin'])
echo '<br /><b>' .$bullet.$txt['tp_maintenace']. '</b>';

//Show the logout button in your userbox
if($context['user']['is_logged'])
echo '<br />'.$bullet.'<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'],'">'.$txt[108].' </a><br />';

// If user is allowed to submit articles, show the link here
              if($context['TPortal']['can_submit_article']==1 && !allowedTo('tp_articles'))
                       echo $bullet.'<a href="', $scripturl, '?action=tpmod;sa=submitarticle">' . $txt['tp-submitarticle']. '</a><br />';

// same for upload, show if allowed
              if(allowedTo('tp_dlupload') || allowedTo('tp_dlmanager'))
                       echo $bullet.'<a href="', $scripturl, '?action=tpmod;dl=upload">' . $txt['permissionname_tp_dlupload']. '</a><br />';
// If user is logged in, display a link to a page you choose.
if ($context['user']['is_logged'])
echo $bullet. '<a href="your url goes here">Your url link</a><br />';
                        //if user has admin right, display a link to the admin section
if ($context['user']['is_admin'])
echo $bullet. '<a href="', $scripturl, '?action=admin">Admin</a>';

// Show the total time logged in?
/*
if (!empty($context['user']['total_time_logged_in']) && isset($context['TPortal']['userbox']['logged'])){

echo '<br />'.$bullet.$txt['tp-loggedintime'] . ' ';

echo '<br />'.$context['user']['total_time_logged_in']['days'] . $txt['tp-acronymdays'];

echo $context['user']['total_time_logged_in']['hours'] . $txt['tp-acronymhours'];

echo $context['user']['total_time_logged_in']['minutes'] .$txt['tp-acronymminutes'];

}
*/
if(isset($context['TPortal']['userbox']['time'])){

echo '<br />'.$bullet. $context['current_time'];

}

echo '</div>';
}
// Otherwise they're a guest - so politely ask them to register or login.
else{
echo '
', $txt['welcome_guest'], '<br />
', $context['current_time'], '<br />
<form action="', $scripturl, '?action=login2" method="post" >
<input type="text" name="user" size="10" /> <input type="password" name="passwrd" size="10" />
        <select name="cookielength">
<option value="60">', $txt['smf53'], '</option>
<option value="1440">', $txt['smf47'], '</option>
<option value="10080">', $txt['smf48'], '</option>
<option value="302400">', $txt['smf49'], '</option>
<option value="-1" selected="selected">', $txt['smf50'], '</option>
</select>
        <input type="submit" value="', $txt[34], '" /><br />
        ', $txt['smf52'], '
</form>';
}
echo ' <br />
</td>
</tr>
</table>';
}


This website is proudly hosted on Crocweb Cloud Website Hosting.