Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Thema gestartet von: Compuart in Oktober 08, 2005, 07:55:25 VORMITTAG

Titel: Congratulating a user that is having a birthday
Beitrag von: Compuart in Oktober 08, 2005, 07:55:25 VORMITTAG
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.

Code (search: Load.php) Auswählen
$user_info['groups'] = array_unique($user_info['groups']);


Code (add after) Auswählen
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.

Code (search: Load.php) Auswählen
'email' => &$user_info['email']


Code (replace) Auswählen
'email' => &$user_info['email'],
'today_is_birthday' => &$user_info['today_is_birthday'],




Step 3. Use the $context value to tweak the template

for instance:
Code (search: index.template.php) Auswählen
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';


Code (replace) Auswählen
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>';



Titel: Re: Congratulating a user that is having a birthday
Beitrag von: cotdagoo in Oktober 09, 2005, 03:23:25 VORMITTAG
I get Undefined index: time_offset errors trying to apply this in 1.1b3
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in Oktober 09, 2005, 07:52:36 VORMITTAG
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']);
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: cotdagoo in Oktober 09, 2005, 09:00:13 VORMITTAG
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in Oktober 09, 2005, 09:19:28 VORMITTAG
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: DomP in Oktober 12, 2005, 07:21:13 NACHMITTAGS
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
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in Oktober 12, 2005, 08:08:40 NACHMITTAGS
remove the
echo '
from line 233, should do the trick.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: DomP in Oktober 13, 2005, 02:47:22 NACHMITTAGS
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 ?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in Oktober 13, 2005, 03:33:13 NACHMITTAGS
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();
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: DomP in Oktober 13, 2005, 04:46:18 NACHMITTAGS
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 ;)
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in Oktober 14, 2005, 07:04:15 VORMITTAG
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: DomP in Oktober 14, 2005, 09:04:56 VORMITTAG
Kewl seems to be okay now :)

Thanx for the great mod :)

"goed weekend" ;)
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in Oktober 14, 2005, 02:03:58 NACHMITTAGS
dank je :)
Titel: Re: Congratulating a user that is having a birthday
Beitrag 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???
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: ViV in November 04, 2005, 09:23:37 VORMITTAG
???
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in November 04, 2005, 01:44:52 NACHMITTAGS
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: TechnoDragon in Januar 20, 2006, 12:16:09 VORMITTAG
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?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Compuart in Januar 20, 2006, 11:24:21 VORMITTAG
The first message still contains the right code. It'll work for both 1.1 RC1 (default theme) and 1.1 RC2 (babylon theme).
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: TechnoDragon in Februar 26, 2006, 12:37:49 VORMITTAG
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!
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Aitsukai in März 10, 2006, 07:15:56 NACHMITTAGS
Any way to send them a PM when they log in for the first time on their birthday?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: SekondeR in April 10, 2006, 02:58:19 NACHMITTAGS
is this can be a module?
so that we can change the message easily  etc... ?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: ArkServer in April 11, 2006, 11:57:30 VORMITTAG
Step 3. Use the $context value to tweak the template

for instance:
Code (search: index.template.php) Auswählen
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';


Code (replace) Auswählen
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
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: sonic in April 24, 2006, 07:14:57 VORMITTAG
Will this work in 1.07 please.

Thankyou
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: geezmo in Juni 21, 2006, 11:57:39 VORMITTAG
Hopefully someone can show the codes we need to make this work in 1.1RC2 or better, make a mod from this one.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: husmen73 (Gulhin) in Juni 27, 2006, 09:32:18 VORMITTAG
are you have 1.1 RC2 codes?

Help me !!!
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: TechnoDragon in Juni 27, 2006, 10:52:32 NACHMITTAGS
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...
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: PrizeLive.com in Juli 09, 2006, 07:08:27 NACHMITTAGS
What does this do?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: TechnoDragon in Juli 10, 2006, 12:44:26 VORMITTAG
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: geezmo in Juli 31, 2006, 03:17:33 VORMITTAG
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: TechnoDragon in Juli 31, 2006, 10:16:47 VORMITTAG
You might be able (or someone sles) to accomplish that, but as it is written it only changes the greeting
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: StarBuG in August 07, 2006, 10:54:07 VORMITTAG
Thanks, this is a realy great Idea.

Implemented it in rc2 with a little tweaking.

Workes perfect

StarBuG
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Loverboy in September 16, 2006, 10:18:46 VORMITTAG
Does this work with RC3?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: codenaught 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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag 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?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: xcrazyxfrogx in Oktober 08, 2006, 03:05:47 VORMITTAG
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
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: digit in Oktober 28, 2006, 08:02:08 VORMITTAG
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'] ? ' &nbsp; <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.

Titel: Re: Congratulating a user that is having a birthday
Beitrag von: guilliam in November 11, 2006, 02:19:35 VORMITTAG
@digit,

you have two single qoutation mark on your echo.

- g
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: rzx in November 11, 2006, 12:38:50 NACHMITTAGS
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: GC in Dezember 17, 2006, 04:43:14 NACHMITTAGS
Does it not do that already? My site had sent me an e-mail on my birthday.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: cmcmom in August 23, 2007, 10:48:00 NACHMITTAGS
What I do is just do a NEWS item... make it bold and a large font.....it looks good....no code needed!
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: digit in August 24, 2007, 04:15:48 VORMITTAG
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!
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Aileen in November 18, 2007, 12:15:05 NACHMITTAGS
IS there any version of this for dummies like me?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Deaks in Dezember 09, 2007, 08:15:52 NACHMITTAGS
hey, do you still need help with this?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: digit in Dezember 10, 2007, 02:36:16 VORMITTAG
I would like a way to automatically PM members with Random Birthday greetings from predesigned Templates. :-)

Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Aileen in Dezember 10, 2007, 10:34:15 VORMITTAG
Zitat von: RunicWarrior in Dezember 09, 2007, 08:15:52 NACHMITTAGS
hey, do you still need help with this?

Hope you could help me
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Deaks in Dezember 10, 2007, 11:49:24 VORMITTAG
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 :)
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Aileen in Dezember 10, 2007, 01:43:16 NACHMITTAGS
I see, thanks Runic Warrior :) BTW when will it be released?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Deaks in Dezember 10, 2007, 05:07:03 NACHMITTAGS
uh no idea to be honest :S
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Fallen Angel in Dezember 11, 2007, 01:38:04 NACHMITTAGS
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>';
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: H in Dezember 15, 2007, 05:55:03 NACHMITTAGS
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.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: TheWrath! in Januar 21, 2008, 12:49:20 NACHMITTAGS
love this feature.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Sarge in Februar 01, 2008, 02:20:40 VORMITTAG
Nice. :)
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Jessikard in März 12, 2009, 05:55:14 NACHMITTAGS
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 ?
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: agbattery in März 23, 2009, 03:58:31 NACHMITTAGS
I like this detailed information brout forth in these forums.  I cant wait to share some of my knowledge and coding experience.
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: Tyrsson in April 25, 2009, 04:12:46 VORMITTAG
@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)
Titel: Re: Congratulating a user that is having a birthday
Beitrag von: blanix in Mai 06, 2009, 06:52:04 VORMITTAG
works fine on 1.1.8, thx