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,973
  • Latest: NonStop
Stats
  • Total Posts: 196,231
  • Total Topics: 21,353
  • Online today: 651
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 137
  • Total: 137

userbox: how do I add profile and logout links?

Started by ApplianceJunk, January 01, 2008, 03:59:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ApplianceJunk

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.


ApplianceJunk

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.

IchBin

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


ApplianceJunk

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.




IchBin

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. :)

ApplianceJunk

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!

IchBin

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

This website is proudly hosted on Crocweb Cloud Website Hosting.