News:

Wondering if this will always be free?  See why free is better.

Main Menu

Help modifying output of ssi_welcome();

Started by sbarnes, June 02, 2006, 05:32:17 AM

Previous topic - Next topic

sbarnes

Hi there,
I am now using the ssi_welcome(); to show logged in members their message status.

You may or may not know that this outputs something like this:
Hey, Username, you have 3 messages, 0 are new.

I would like to modify this output slightly so it says something like:

You have 3 messages, 0 are new.

(simply remove the 'hey username')

Also possibly saying just 'You have no messages' when there are none at all.

Is there a way of doing this without editing the ssi.php itself?

I have read the basic and advanced ssi faq's but still cant work it out.

kegobeer

No, that function is an echo function only.  If you look at the function, all it does is spit out $txt, $scripturl, and $context variables, which you can use without calling the function.  Just copy


global $txt, $context, $scripturl;
if ($context['user']['is_guest']) {
echo $txt['welcome_guest'];
} else {
echo $txt['hello_member'], ' <b>', $context['user']['name'], '</b>', allowedTo('pm_read') ? ', ' . $txt[152] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] == '1' ? $txt[471] : $txt[153]) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == '1' ? $txt['newmessages0'] : $txt['newmessages1']) : '', '.';
        }


to your custom file, and edit the echo statement to output whatever you want.

If you want a unique message if there are no messages, add another if/else block to the code using $context['user']['messages'] == '0' to check for no messages.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

sbarnes

Thats great, thank you very much.
I will play around with that to suit my needs.

All the best

sbarnes

#3
I've just really confused myself now.

I couldnt work out how to make the script read like 'if the user is logged in and they have no messages echo a different message.

I thought  if ($context['user']['is_logged']['messages'] == '0')might have worked but it didnt.

I have been playing around with it but cannot get it to work for logged in members and not show for guests.

My setup is slightly different and was trying to adapt it rather than re-write it.

I think to get what I wanted I need:
allowedTo('pm_read') ? ', ' . $txt[152] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] == '1' ? $txt[471] : $txt[153]) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == '1' ? $txt['newmessages0'] : $txt['newmessages1']) : '', '.';
        }

But couldnt work out all the all the 's etc. and wether or not I needed the allowedTo('pm_read')

can you or somone please help me.

I want to show:
You have 3 messages, 0 are new.
when there are messages.

and show

You have no messages
when there are no messages.

(I would be able to add the the english file)

For guests obviously show nothing (the welcome_guest is shown further my script at the moment).

Here is that section of my index.template that I am currently using:
// If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged'])
{
ssi_welcome();
echo ' <br />
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unread;all;start=0">' .$txt['tp-allunread'].'</a> <br />
<a href="', $scripturl, '?action=recent">', $txt['tp-recent'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';
echo $GLOBALS['user_settings']['pmAutoRespondAwayMsgActivate'] ? $txt['pmAutoRespondAwayWarning'].'<br/>':'';


}
// Otherwise they're a guest - send them a lovely greating...
else
echo $txt['welcome_guest'];

// Now, onto our second set of info, are they logged in again?


Should I re-write the whole section to something like this?

global $txt, $context, $scripturl;
if ($context['user']['is_guest']) {
echo $txt['welcome_guest'];
} else {
echo allowedTo('pm_read') ? ', ' . $txt[152] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] == '1' ? $txt[471] : $txt[153]) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == '1' ? $txt['newmessages0'] : $txt['newmessages1']) : , '
        <br />
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unread;all;start=0">' .$txt['tp-allunread'].'</a> <br />
<a href="', $scripturl, '?action=recent">', $txt['tp-recent'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';
echo $GLOBALS['user_settings']['pmAutoRespondAwayMsgActivate'] ? $txt['pmAutoRespondAwayWarning'].'<br/>':'';


}

I realise that probably needs altering and cleaning up and would need help with that please.


kegobeer

You didn't mention changing a template file.  If you use SSI, then normally you aren't trying to make changes to any theme files, you are writing a custom php file (like a welcome to the website page).  Are you trying to customize your theme's index.template.php file?
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

sbarnes

Although I am now learning how the ssi instructions work I may be using these features to produce a front page in the future.

Yes, I started this thread with the intention of customizing my index.template.php file.

I started using the ssi_welcome as I thought it was the only way to produce the output about the messages, that was until you told me otherwise and that I could just use the variables that it uses direct.

Therefore I would like to adapt my index.template to include these variables to produce the right output.

I need the help in coding and adapting what I already have as I am not fluant in php coding at all.

Any help greatly appreciated.

kegobeer

You don't use SSI in any template file.  There's no reason to do so.  What version of SMF are you trying to customize?
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

sbarnes

#7
Thank you, I have worked that out now, I guess you use it for adding info from smf to other pages outside of the smf folder. e.g you can include recent posts, people logged in etc on a home where your forum is actually inside a folder.
Or I guess you could also use them in pages you create and add to your website which are not part of smf

The ssi functions use variables etc that smf uses directly in the forum.

This is now no longer really a call for help regarding ssi functions, now I'm asking for general coding help with variables I beleive.

I want to replace the ssi_welcome(); function I have added to my template with the variables it uses instead but without the 'hey username' at the beginning and at the same time not conflict with the other items I have there and work in the correct situation e.g only for logged in members etc.

I want to make these changes to my index.template using the variables, e.g
($context['user']['unread_messages'] == '1' ? $txt['newmessages0'] : $txt['newmessages1']) etc.

I am running smf 1.1 RC2

Am I right in thinking that my last idea is on the right tracks? I know the code needs looking at and altered:
global $txt, $context, $scripturl;
if ($context['user']['is_guest']) {
echo $txt['welcome_guest'];
} else {
echo allowedTo('pm_read') ? ', ' . $txt[152] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] == '1' ? $txt[471] : $txt[153]) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == '1' ? $txt['newmessages0'] : $txt['newmessages1']) : , '
        <br />
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unread;all;start=0">' .$txt['tp-allunread'].'</a> <br />
<a href="', $scripturl, '?action=recent">', $txt['tp-recent'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';
echo $GLOBALS['user_settings']['pmAutoRespondAwayMsgActivate'] ? $txt['pmAutoRespondAwayWarning'].'<br/>':'';


}


The site is http://www.pick-your-brains.co.uk its the header section I am referring to if you want to see what I mean.

Advertisement: