TinyPortal

Development => Support => Topic started by: ApplianceJunk on January 01, 2008, 03:59:37 PM

Title: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 01, 2008, 03:59:37 PM
I think it would be useful to have a profile and logout link included in the userbox.
How do I go about adding these links?

Thank you,
AJ

Edited to add:

1. If you have a URL, please post it.

http://www.ApplianceJunk.com (http://www.appliancejunk.com)

2. If you are getting an error message, copy it and paste it into your post. You can delete any privacy info, like usernames, etc., but try to keep as much of the error message intact as possible.

We are not getting any error messages at this time.


3. Let us know what version(s) you are using.
       
SMF 1.1.4/TinyPortal v0.9.8


4. Do you have any mods installed? If yes, tell us.

We have these mods installed.

1. SMF 1.1.2 Update Package 1.1.2
2. SMF 1.0.11 / 1.1.3 Update 1.1 
3. Ad Managment 2.3
4. Streaming 3 4.2.2b
5. nwsw.nwswAdminAttachAnything 1.1 RC3
6. SMF Sitemap 1.2.1
7. Users Online Today Mod 1.4.0
8. SMF Arcade 2.0.11
9. URL Popup 1.0
10. SMF Trader System 1.1 
11. SMF Classifieds Recent Classifieds Board Index 1.0 
12. TinyPortal 0.983 
13. SMF Gallery Pro 1.3beta3 
14. SMF Gallery Pro Upgrade 1.3
15. SMF 1.0.12 / 1.1.4 / 2.0 b1.1 Update 1.0 
16. Internal Links Use Same Window 1.1 
17. SMF Classifieds 1.1
18. Social Bookmarks 1.1
19. SSI Topic and Replies 0.1 
20. SMFBlog 0.1 Beta 
21. Treasury 2.04
22. Topic description 1.1
Title: Re: userbox: how do I add profile and logout links?
Post by: G6Cad on January 01, 2008, 04:25:56 PM
Can you please read our posting guide we have for this site and apply the proper changes to your post ?
Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 01, 2008, 04:56:59 PM
Quote from: G6 on January 01, 2008, 04:25:56 PM
Can you please read our posting guide we have for this site and apply the proper changes to your post ?

Yes I can, sorry about that.

I should have known better the first time.

Thank you,
AJ
Title: Re: userbox: how do I add profile and logout links?
Post by: IchBin on January 01, 2008, 05:16:58 PM
In the TPortal.template.php file you'll fine the function userbox() section in there. You can add a logout and profile button there. Take a look, and if you need help post back and I'll look at the file when I'm able to for you.
Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 01, 2008, 06:44:41 PM
In the attachment is the file.

I looked through it, but I am lost at this point.

I would like to put the links in this order.

PM:
Profile
Show unread
Show replies
Show own posts
Logout

It would be great if you could take a look at it when you get some time.

thanks,
Title: Re: userbox: how do I add profile and logout links?
Post by: IchBin on January 01, 2008, 10:25:13 PM
I'm sorry, I should have said TPortalBlocks.template.php file. :)
Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 01, 2008, 10:34:36 PM
No problem,

My TPortalBlocks.template.php is now attached.

I have been trying to make a logout link on the side and am not finding it so easy.

It would really be great if you could code it for me.


Title: Re: userbox: how do I add profile and logout links?
Post by: IchBin on January 01, 2008, 11:10:56 PM
Lets do this together so that you can learn some stuff. :) Here's the code for the userbox. Lets disect it a bit, and see if you can figure out how to add the links. I'll put comments about the code so you can see what its doing. :)
function TPortal_userbox()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;
// The following bullet variables are created so we don't have to type out the image code where we want
// these images to be put in the rest of the code below.
$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;" />';
// start the box here :)
echo'
<div class="smalltext">';
// if the user's avatar is not empty AND TP's userbox avatar is set, echo the avatar image.
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>';
// the following lines display the unread/unread replies, and show own posts links.
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 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'];
}
}
// 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 '</div>';
}


Now to put a profile and logout link how can we do that? If you don't know what the link code would look like where can you look? Two places, you can get the link simply by copying the link from your browser window. (which you'll need to change a couple of things, but it will give you a start), OR you can look in another template file that already has the links for you. :) Let me know if you can't figure it out.
Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 01, 2008, 11:25:36 PM
QuoteLets do this together so that you can learn some stuff.

Sounds good to me. :)


QuoteOR you can look in another template file that already has the links for you.


Now why did I not think of that before? lol..


Just to see if I am on the right track first. This is what I found in the index.template.php file.

I am thinking it's what I need to use for the logout link, correct?


// Otherwise, they might want to [logout]...
if ($context['user']['is_logged'])
echo'
<td align="center" class="menubg' , $current_action == 'logout' ? '2' : '' , '">
<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>
</td>';
Title: Re: userbox: how do I add profile and logout links?
Post by: IchBin on January 02, 2008, 12:45:00 AM
That is exactly right on the code. Just remember you don't need the table code. All you need is the link code. :) Everything starting with the <a href to the ending < /a > tag.
Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 02, 2008, 12:50:20 AM
While I can not seem to get the Logout link to work right so I moved onto the profile one.

Is this what I need for the profile link?

if ($context['allow_edit_profile'])
echo'
<td align="center" class="menubg' , $current_action == 'profile' ? '2' : '' , '">
<a href="', $scripturl, '?action=profile">' , $txt[79] , '</a>
</td>';



QuoteJust remember you don't need the table code. All you need is the link code.

That is maybe why I am having trouble getting the logout link to work.
I will go back and try again.

Thank for taking the time to help me learn.

Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 02, 2008, 12:55:22 AM
I am so excited right now.
I got a working profile link in the userbox.  :laugh:

QuoteJust remember you don't need the table code. All you need is the link code.

I removed the table codes and it worked!

I just need to get it in the right place now, but it sure is nice to see it show up on the page.
Title: Re: userbox: how do I add profile and logout links?
Post by: IchBin on January 02, 2008, 12:58:54 AM
Yes, that is the code for the profile. If you get stuck, post your code so I can show you the correction you need  to make. FYI, this code:
if ($context['allow_edit_profile'])

That code is telling you, "if the user is allowed to edit a their profile", then echo the link. Otherwise, if they are not allowed to edit their profile (such as a guest is not), then do not show the link. :)

So you can still use the if statement, but you need to make sure you don't break any other echo statements. You can learn a little more about the echo statement at my site in a little tutorial I posted.
http://www.ichbin.us/index.php?topic=19

Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 02, 2008, 01:15:04 AM
Think I got it.

This is what I ended up with.
Does it look ok?

// Tportal userbox
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'
<div class="smalltext">';

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

// Edit Profile... [profile]
if ($context['allow_edit_profile'])
echo'<br />'.$bullet.'<a href="', $scripturl, '?action=profile">' , $txt[79] , '</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>';
}

// Otherwise, they might want to [logout]...
if ($context['user']['is_logged'])
echo'<br />'.$bullet.'<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>';



I must say there is much I don't understand about it, but I seem to learn enough tonight that I could copy and past the right stuff.

This is so very interesting. :)

I was not sure about putting these little things in there.

}

At first I put them at the end of the code I added for the profile and logout as it looked like the other links had them, but things did not work.

Once I removed them from the code I added things seem to work ok.



Title: Re: userbox: how do I add profile and logout links?
Post by: IchBin on January 02, 2008, 01:33:20 AM
Your code looks good, is it working? The brackets are to tell the "if" statement how much code to include. They are not necessary if you only have one echo statement. For instance:

// Otherwise, they might want to [logout]...
if ($context['user']['is_logged'])
    echo'<br />'.$bullet.'<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>';


The code above does not require it, but if you wanted to add some more to it you would need to use the brackets. Well, to be more specific, PHP will stop at the first ending echo statements semi-colon. Unless you use the brackets like this:
// Otherwise, they might want to [logout]...
if ($context['user']['is_logged']){
    echo'<br />'.$bullet.'<a href="', $scripturl, '?action=logout;sesc=', $context['session_id'], '">' , $txt[108] , '</a>';
    echo 'another link here';
}


All the code in between your brackets will only display if your if statement is true. You are catching the basics of it very well. Keep it up! If you don't understand something, then just ask and I'll try to explain. :)
Title: Re: userbox: how do I add profile and logout links?
Post by: ApplianceJunk on January 02, 2008, 02:24:38 AM
QuoteYour code looks good, is it working?

It's working great, thank you.

I was wonder if there is a easier way to play around with the code.
This is how I am doing it now.

I have one folder called SMF and a second folder called SMF fixed.

I ftp the file I want to edit to the SMF folder.
I open that file with evrsoft first page 2006 to view the code and edit it.

I then save the changed file to the SMF fixed folder and then ftp it back to my site to view the changes.

If something is not right I have to try again or go back to the SMF folder and ftp the untouch file back to the site.

In evrsoft first page I can change html files and then view how it looks right away in evrsoft first page. But with these .php files I can not see if my changes work until I ftp the edited file back to my site and check it.

Is there some other editing program I can use to make changes to .php file and view the changes right away without having to ftp the edit file back to my site?

Thanks a million for all the help. I have ton of reading and playing around to do now. :)

Happy New Year!
Title: Re: userbox: how do I add profile and logout links?
Post by: IchBin on January 02, 2008, 04:48:12 AM
Unfortunately, there's no easy way to do it like HTML. Because HTML is not a true programming language like PHP, HTML only requires a browser to parse the HTML code. Where as, PHP actually has to be compiled at run time and has to be parsed on the server side, unlike HTML being on the client side. The easiest way I do it is to download a program called wamp. It installs PHP, MySQL, and Apache on your machine. You can then install stuff to the www folder of that program. Once you start the program up you have a web server running on your computer. Just install SMF like you would on your hosted account, only your address is http://localhost
You make changes to the file, and just reload your browser viewing the changes locally on your computer. Its quite nice if you really get serious about coding in PHP. Theres a lot more details to it than what I described, so if you are serious you should read up on it some more before just assuming about everything i said. lol