Congratulating a user that is having a birthday

Started by Compuart, October 08, 2005, 07:55:25 AM

Previous topic - Next topic

Compuart

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>';



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

cotdagoo

I get Undefined index: time_offset errors trying to apply this in 1.1b3

Compuart

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']);

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

cotdagoo

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.

Compuart

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

DomP

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

Compuart

remove the
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

DomP

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 ?

Compuart

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();
Hendrik Jan Visser
Former Lead Developer & Co-founder www.simplemachines.org
Personal Signature:
Realitynet.nl -> ExpeditieRobinson.net / PekingExpress.org / WieIsDeMol.Com

DomP

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 ;)

Compuart

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

DomP

Kewl seems to be okay now :)

Thanx for the great mod :)

"goed weekend" ;)

Compuart

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

ViV

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???


Compuart

Quote from: ViV 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???
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

TechnoDragon

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!


Compuart

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

TechnoDragon

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!


Aitsukai

Any way to send them a PM when they log in for the first time on their birthday?

Advertisement: