Advertisement:

Author Topic: Congratulating a user that is having a birthday  (Read 68141 times)

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Congratulating a user that is having a birthday
« on: October 08, 2005, 07:55:25 AM »
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) [Select]
$user_info['groups'] = array_unique($user_info['groups']);

Code: (add after) [Select]
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) [Select]
'email' => &$user_info['email']

Code: (replace) [Select]
'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) [Select]
echo '
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>';

Code: (replace) [Select]
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>';


« Last Edit: October 08, 2005, 08:03:45 AM by Compuart »
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline cotdagoo

  • Semi-Newbie
  • *
  • Posts: 36
Re: Congratulating a user that is having a birthday
« Reply #1 on: October 09, 2005, 03:23:25 AM »
I get Undefined index: time_offset errors trying to apply this in 1.1b3

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #2 on: October 09, 2005, 07:52:36 AM »
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(
	
	
&
#39;username&#39; => $username,
	
	
&
#39;name&#39; => isset($user_settings[&#39;realName&#39;]) ? $user_settings[&#39;realName&#39;] : &#39;&#39;,
	
	
&
#39;email&#39; => isset($user_settings[&#39;emailAddress&#39;]) ? $user_settings[&#39;emailAddress&#39;] : &#39;&#39;,
	
	
&
#39;passwd&#39; => isset($user_settings[&#39;passwd&#39;]) ? $user_settings[&#39;passwd&#39;] : &#39;&#39;,
(...)
	
	
&
#39;permissions&#39; => array()
	
);
	
$user_info[&#39;groups&#39;] = array_unique($user_info[&#39;groups&#39;]);

Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline cotdagoo

  • Semi-Newbie
  • *
  • Posts: 36
Re: Congratulating a user that is having a birthday
« Reply #3 on: October 09, 2005, 09:00:13 AM »
Hmm.. looks like vWarnMod has re-arranged that piece of code in Load.php - and it's now appearing above like this:

Code: [Select]
// 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.

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #4 on: October 09, 2005, 09:19:28 AM »
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.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline DomP

  • Semi-Newbie
  • *
  • Posts: 21
Re: Congratulating a user that is having a birthday
« Reply #5 on: October 12, 2005, 07:21:13 PM »
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.

Code: [Select]
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

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #6 on: October 12, 2005, 08:08:40 PM »
remove the
Code: [Select]
echo 'from line 233, should do the trick.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline DomP

  • Semi-Newbie
  • *
  • Posts: 21
Re: Congratulating a user that is having a birthday
« Reply #7 on: October 13, 2005, 02:47:22 PM »
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

Code: [Select]

 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 ?

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #8 on: October 13, 2005, 03:33:13 PM »
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):
Code: [Select]
loadUserSettings();
by:
Code: [Select]
require_once($sourcedir . '/Subs.php');
loadUserSettings();
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline DomP

  • Semi-Newbie
  • *
  • Posts: 21
Re: Congratulating a user that is having a birthday
« Reply #9 on: October 13, 2005, 04:46:18 PM »
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
Code: [Select]
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 ;)

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #10 on: October 14, 2005, 07:04:15 AM »
maybe instead of
Code: [Select]
require_once($sourcedir . '/Subs.php');
define the missing function:
Code: [Select]
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.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline DomP

  • Semi-Newbie
  • *
  • Posts: 21
Re: Congratulating a user that is having a birthday
« Reply #11 on: October 14, 2005, 09:04:56 AM »
Kewl seems to be okay now :)

Thanx for the great mod :)

"goed weekend" ;)

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #12 on: October 14, 2005, 02:03:58 PM »
dank je :)
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline ViV

  • Semi-Newbie
  • *
  • Posts: 81
    • Value Add Consultancy
Re: Congratulating a user that is having a birthday
« Reply #13 on: October 20, 2005, 05:26:44 AM »
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???

Offline ViV

  • Semi-Newbie
  • *
  • Posts: 81
    • Value Add Consultancy
Re: Congratulating a user that is having a birthday
« Reply #14 on: November 04, 2005, 09:23:37 AM »
???

Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #15 on: November 04, 2005, 01:44:52 PM »
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.
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: Congratulating a user that is having a birthday
« Reply #16 on: January 20, 2006, 12:16:09 AM »
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?
Don't tell me to get into shape...I have a shape...It is round!


Offline Compuart

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,774
  • Gender: Male
  • Zéeeeal
    • RealityNet
Re: Congratulating a user that is having a birthday
« Reply #17 on: January 20, 2006, 11:24:21 AM »
The first message still contains the right code. It'll work for both 1.1 RC1 (default theme) and 1.1 RC2 (babylon theme).
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: Congratulating a user that is having a birthday
« Reply #18 on: February 26, 2006, 12:37:49 AM »
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!
Don't tell me to get into shape...I have a shape...It is round!


Offline Aitsukai

  • Jr. Member
  • **
  • Posts: 114
Re: Congratulating a user that is having a birthday
« Reply #19 on: March 10, 2006, 07:15:56 PM »
Any way to send them a PM when they log in for the first time on their birthday?