TinyPortal

Development => Block Codes => Topic started by: hsdk on November 26, 2006, 07:49:15 PM

Title: modified userbox
Post by: hsdk on November 26, 2006, 07:49:15 PM
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:


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>';
}
Title: Re: modified userbox
Post by: 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. :)
Title: Re: modified userbox
Post by: hsdk on November 27, 2006, 12:12:39 AM
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 :)
Title: Re: modified userbox
Post by: akulion on November 27, 2006, 12:42:49 AM
nice job - thanks :up:
Title: Re: modified userbox
Post by: RoarinRow on November 27, 2006, 03:58:52 AM
yup, very cool   :up:
Title: Re: modified userbox
Post by: pvcblue on November 27, 2006, 05:02:56 AM
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>';
Title: Re: modified userbox
Post by: hsdk on November 27, 2006, 09:54:09 AM
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.
Title: Re: modified userbox
Post by: Techdomain on November 27, 2006, 10:06:24 PM
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 :)
Title: Re: modified userbox
Post by: Techdomain on November 27, 2006, 10:23:14 PM
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>';
}
Title: Re: modified userbox
Post by: hsdk on November 27, 2006, 10:30:00 PM
nice! :)
Title: Re: modified userbox
Post by: Shadow on April 18, 2007, 02:33:29 AM
I pot this at RebelRose forum. 

Quote from: Ã,©RebelRose on April 18, 2007, 01:41:43 AM
:-??  well lets post about it on TP because that is where it came from.

I try this code out. And I use a php box and I get a error.

Fatal error: Cannot redeclare tportal_userbox() (previously declared in /home/wishyou/public_html/skhilled/smf3/Sources/Load.php(1733) : eval()'d code:388) in /home/wishyou/public_html/skhilled/smf3/Sources/Load.php(1733) : eval()'d code(35) : eval()'d code on line 3
Title: Re: modified userbox
Post by: G6Cad on April 18, 2007, 09:42:09 AM
You have to give us more info then that Shadow Queen.
What code did you use to get that error ?

Where did you put it ?
A link to your site to please
Title: Re: modified userbox
Post by: Shadow on April 18, 2007, 10:14:22 AM
Two member's post this code off of this topic I think..Here the code is below here.  RebelRose just say put the code in a phpbox and dont work and I get that error. I just did what the post told me to do and I did...

Here is my test site I am testing thing's out.  I won't test thing's on my live site all that.  Because I put tons of hard work on the site.

Here is my test site link http://www.skhilled.com/smf3/index.php

G6 You can can me Shadow just letting you know  ;)

Quote from: Ã,©RebelRose on April 18, 2007, 12:53:52 AM
You can just create a new user block and turn the other off, just put that code in a php block.


// 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>';
}


Title: Re: modified userbox
Post by: G6Cad on April 18, 2007, 11:14:16 AM
dont know if it will help, but try and change the

function TPortal_userbox()

to

function tportal_userbox()
Title: Re: modified userbox
Post by: Shadow on April 18, 2007, 01:10:48 PM
No, Its didn't help at all G6