Suppose you want to make changes to your templates, if it's someones birthday, for instance by greeting him/her with a special message. Here's how to do it.
Step 1. Calculate whether it's a birthday and store it in $user_info.
$user_info['groups'] = array_unique($user_info['groups']);
if (isset($user_settings['birthdate']))
{
$cur_date = getdate(forum_time());
$user_info['today_is_birthday'] = $cur_date['mon'] == substr($user_settings['birthdate'], 5, 2) && $cur_date['mday'] == substr($user_settings['birthdate'], 8);
}
Step 2. Pass the value to the template $context variable.
'email' => &$user_info['email']
'email' => &$user_info['email'],
'today_is_birthday' => &$user_info['today_is_birthday'],
Step 3. Use the $context value to tweak the template
for instance:
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';
if ($context['user']['today_is_birthday'])
echo '
CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';
I get Undefined index: time_offset errors trying to apply this in 1.1b3
Odd. Can you confirm that the additional code in step 1 is put after this block of code?
// Set up the $user_info array.
$user_info += array(
'username' => $username,
'name' => isset($user_settings['realName']) ? $user_settings['realName'] : '',
'email' => isset($user_settings['emailAddress']) ? $user_settings['emailAddress'] : '',
'passwd' => isset($user_settings['passwd']) ? $user_settings['passwd'] : '',
(...)
'permissions' => array()
);
$user_info['groups'] = array_unique($user_info['groups']);
Hmm.. looks like vWarnMod has re-arranged that piece of code in Load.php - and it's now appearing above like this:
// we do this here, so we don't have to do it for warnings seperately ;)
$user_info['groups'] = array_unique($user_info['groups']);
// only warning-groups in this one :D
$user_info['warnings'] = array_intersect($user_info['groups'], array_keys($warningGroups));
}
// If the user is a guest, initialize all the critial user settings.
else
{
// This is what a guest's variables should be.
$username = '';
$user_info = array('groups' => array(-1), 'warnings' => array());
$user_settings = array();
if (isset($_COOKIE[$cookiename]))
$_COOKIE[$cookiename] = '';
}
// Set up the $user_info array.
It can be put it the very end of the loadUserSettings() function, doesn't really matter. As long as $user_info['time_offset'] has been set.
I like this mod :)
I think my install was okay too.......
I changed birthday but get an template error now, this only affects me. Other users don't have the problem So I think it only happens during that day for everyone who has a birthday.
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in .../Themes/default/index.template.php on line 234
225: if (!empty($context['user']['avatar']))
226: echo '<td valign="middle">', $context['user']['avatar']['image'], '</td>';
227:
228: echo '<td valign="top" class="smalltext" style="width: 100%; font-family: verdana, arial, sans-serif;">';
229:
230: // If the user is logged in, display stuff like their name, new messages, etc.
231: if ($context['user']['is_logged'])
232: {
233: echo '
234: if ($context['user']['today_is_birthday'])
235: echo '
236: CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
237: else
238: echo '
It's also causing an template error at the bridged Coppermine Gallery
Hope this helps
remove the
echo '
from line 233, should do the trick.
I fixed that, only problem is still with the gallery ...
Fatal error: Call to undefined function forum_time() in /home/online16/public_html/gallery/bridge/smf.inc.php(127) : eval()'d code on line 158
158: // get first 50 chars
159: $HTTP_USER_AGENT = substr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 0, 50);
160: $REMOTE_ADDR = substr($HTTP_SERVER_VARS['REMOTE_ADDR'], 0, 50);
Any idea ?
Make sure that before the bridge calls the loadUserSettings() function it first includes the Subs.php file.
So replace (at some point in the bridge):
loadUserSettings();
by:
require_once($sourcedir . '/Subs.php');
loadUserSettings();
Did that... now it gives me:
Fatal error: Cannot redeclare db_query() (previously declared in /home/online16/public_html/gallery/include/functions.inc.php:71) in /home/online16/public_html/forum/Sources/Subs.php on line 322
Subs.php
317: // Debugging.
318: if (isset($GLOBALS['db_show_debug']) && $GLOBALS['db_show_debug'] === true)
319: $db_cache[$db_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st));
320:
321: return $ret;
322: }
I'm lost ;)
maybe instead of
require_once($sourcedir . '/Subs.php');
define the missing function:
function forum_time($use_user_offset = true, $timestamp = null)
{
global $user_info, $modSettings;
if ($timestamp === null)
$timestamp = time();
elseif ($timestamp == 0)
return 0;
return $timestamp + ($modSettings['time_offset'] + ($use_user_offset ? $user_info['time_offset'] : 0)) * 3600;
}
hope this works.
Kewl seems to be okay now :)
Thanx for the great mod :)
"goed weekend" ;)
dank je :)
Similarly, Is there a way in which a small cake can appear next to a person's name, in his posts and in user's online list, when it's his/her birthday???
???
Zitat von: ViV in Oktober 20, 2005, 05:26:44 VORMITTAG
Similarly, Is there a way in which a small cake can appear next to a person's name, in his posts and in user's online list, when it's his/her birthday???
This modification only works for the person who's birthday it is. The option to change a name in online lists and posts would need to compare the birthday of every member shown to the current date. For that you could adjust the loadUser function which loads the user data for most screens. But that's beyond the scope of this modification.
Okay...i read this post and there were several code snippets all over...could someone possibly post the final tested working code in one message?
and which version of SMF is it for?
The first message still contains the right code. It'll work for both 1.1 RC1 (default theme) and 1.1 RC2 (babylon theme).
ok...i entered the code exactly as you have listed and it still does not show up in the status box...it just still says "hey, username"
Am i missing something?
EDIT: Never mind...figured it out!
Any way to send them a PM when they log in for the first time on their birthday?
is this can be a module?
so that we can change the message easily etc... ?
Step 3. Use the $context value to tweak the template
for instance:
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';
if ($context['user']['today_is_birthday'])
echo '
CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';
im not sure how to do this in 1.1 rc2
Will this work in 1.07 please.
Thankyou
Hopefully someone can show the codes we need to make this work in 1.1RC2 or better, make a mod from this one.
are you have 1.1 RC2 codes?
Help me !!!
Here is the code snippet...it also includes the good morning, afternoon, evening code as well.
if ($context['user']['is_logged'])
{
if ($context['user']['today_is_birthday'])
echo '<span class="normaltext">
<SCRIPT LANGUAGE="JavaScript">
<!--Begin
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);
// End -->
</script>
<br>Happy Birthday! <br> <b>', $context['user']['name'], '</b>, <br>have a piece of cake!<br><img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '<span class="normaltext">
<SCRIPT LANGUAGE="JavaScript">
<!--Begin
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);
// End -->
</script> <br> <b>', $context['user']['name'], '</b></span>';
it should replace what is below this:
// If the user is logged in, display stuff like their name, new messages, etc.
Sorry cannot remember what the original code was...but should go in the index template...i know that line exists in tinyportal...i'll look around and see if i can find where the original unedited code is...
What does this do?
It changes the standard "Hey [username]" to either Good morning, good afternoon, good evening, [username] as well as when it is the members birthday it changes the greeting on that day only to Happy Birthday [username], have a piece of cake, with an image of a piece of cake.
Does this code change the welcome greeting to a happy birthday greeting once the member is logged in or does it send a PM or email when it's a person's birthday? I want to have a code that sends an email or PM when it's a member's birthday.
You might be able (or someone sles) to accomplish that, but as it is written it only changes the greeting
Thanks, this is a realy great Idea.
Implemented it in rc2 with a little tweaking.
Workes perfect
StarBuG
Does this work with RC3?
Zitat von: LocoTurk in September 16, 2006, 10:18:46 VORMITTAG
Does this work with RC3?
Almost, the one change for RC3 with use of the new default theme (Core) or themes styled after it, is for the file Themes/default/index.template.php you have to look for:
if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';and change it to:
if ($context['user']['today_is_birthday'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;">CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" /></span>
</td>';
else if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';The changes for Load.php are the same.
Isn't there any modification that makes us able to send an automatic email to the user when it's his birthday?
Zitat von: akabugeyes in September 22, 2006, 07:28:54 NACHMITTAGS
Zitat von: LocoTurk in September 16, 2006, 10:18:46 VORMITTAG
Does this work with RC3?
Almost, the one change for RC3 with use of the new default theme (Core) or themes styled after it, is for the file Themes/default/index.template.php you have to look for:
if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';
and change it to:
if ($context['user']['today_is_birthday'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;">CONGRATULATIONS <b>', $context['user']['name'], '</b>, have a <img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" /></span>
</td>';
else if($context['user']['is_logged'])
echo '
<td class="titlebg2" height="32">
<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
</td>';
The changes for Load.php are the same.
not working on index of site the hello thing also got removed and nothing no cake image or somthing
I would like to display a slice of cake below users avatars on the Display.template.php page.
so, I tried this...
echo '
', $context['member']['age'] . ($context['member']['today_is_birthday'] ? ' <img src="' . $settings['images_url'] . '/bdaycake.gif" width="40" alt="" />' : ''), '';
It didn't work. Can someone please help me get this snippet working?
Thanks in advance.
@digit,
you have two single qoutation mark on your echo.
- g
Zitat von: LocoTurk in September 23, 2006, 11:46:10 NACHMITTAGS
Isn't there any modification that makes us able to send an automatic email to the user when it's his birthday?
Something like this would be nice.
Does it not do that already? My site had sent me an e-mail on my birthday.
What I do is just do a NEWS item... make it bold and a large font.....it looks good....no code needed!
Zitat von: Loverboy in September 23, 2006, 11:46:10 NACHMITTAGS
Isn't there any modification that makes us able to send an automatic email to the user when it's his birthday?
I would like to see this too... my mods are overworked!
IS there any version of this for dummies like me?
hey, do you still need help with this?
I would like a way to automatically PM members with Random Birthday greetings from predesigned Templates. :-)
hi Aileen, this is possible, however his feature is one of the features that have been announced when smf2 is released as stable... if you can wait that long... if you cant wait ill try and work the coding for you :)
I see, thanks Runic Warrior :) BTW when will it be released?
uh no idea to be honest :S
Doe's this mod works with SMF 1.1.4 and Dilber MC theme??
if ($context['user']['is_logged'])
{
if ($context['user']['today_is_birthday'])
echo '<span class="normaltext">
<SCRIPT LANGUAGE="JavaScript">
<!--Begin
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);
// End -->
</script>
<br>Happy Birthday! <br> <b>', $context['user']['name'], '</b>, <br>have a piece of cake!<br><img src="', $settings['images_url'], '/bdaycake.gif" width="40" alt="" />';
else
echo '<span class="normaltext">
<SCRIPT LANGUAGE="JavaScript">
<!--Begin
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);
// End -->
</script> <br> <b>', $context['user']['name'], '</b></span>';
It should do. Make sure the first bit of code goes into load.php, as described in the first post. You'll then need to make sure the code for index.template.php goes in the index.template.php of the diblermc theme instead of the default theme.
love this feature.
Nice. :)
sorry but i´m searching for a mod like this soon
i know there is a mod "welcome topic" (http://custom.simplemachines.org/mods/index.php?mod=789) and i hope someone can help me
i´m not a specialist in coding but i think if a coder could change the request to the database
like ->birthday_field instead of ->new_registration that would be perfekt
is there an way to do it ?
I like this detailed information brout forth in these forums. I cant wait to share some of my knowledge and coding experience.
@Jessikard
You may want to try posting in this board to see if someone can help you find a solution :)
SMF Coding Discussion (http://www.simplemachines.org/community/index.php?board=60.0)
works fine on 1.1.8, thx