Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: luuuciano on January 07, 2011, 12:08:42 PM

Title: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: luuuciano on January 07, 2011, 12:08:42 PM
Hi!

I do not want to use the full set of calendar features (events, post -> events vinculation, etc)... I just need a list of upcoming birthday at the main board section...

I have tried adding a few comments to the BoardIndex.template.php file, to force it to show...
But it looks like $context['calendar_birthdays'] is allways empty when Calendar if OFF?

Any idea about how to achieve this?
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: hadesflames on January 07, 2011, 09:59:18 PM
No, this would require a mod to make it work without the calendar being on. I suggest you ask for one in the mod request board, or see if one already exists that does this.
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: luuuciano on January 07, 2011, 10:53:40 PM
Yep... well, before posting this I have searched for "birthday" in the mod directory, without luck...

Will do the mod request, as soon as I can :)
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: hadesflames on January 08, 2011, 12:20:23 AM
Meanwhile, I'll mark this topic as solved ;)
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: feline on January 08, 2011, 12:48:55 PM
Here a small code part to show birthdays for the current month even if the calendar off ..


global $smcFunc, $scripturl, $sourcedir, $txt;

include_once($sourcedir .'/Subs-Calendar.php');
$month = (int) strftime('%m', forum_time());
$year = (int) strftime('%Y', forum_time());

$start_data = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
if($month == 12)
{
   $month = 1;
   $year++;
}
else
   $month++;
$end_data = date('Y-m-d', mktime(0, 0, 0, $month, 0, $year));

$calbirthdays = getBirthdayRange($start_data, $end_data);
ksort($calbirthdays);

foreach($calbirthdays as $cdate => $data)
{
   list($cdt['year'], $cdt['month'], $cdt['day']) = explode('-', $cdate);
   foreach($data as $vals)
      echo $smcFunc['substr']($txt['months'][intval($cdt['month'])], 0, 3) .' '. $cdt['day'] .': <a href="'. $scripturl .'?action=profile;u='. $vals['id'] .'">'. $vals['name'] .(!empty($vals['age']) ? '('. $vals['age'] .')' : '') .'</a><br />';
}


Fel
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: luuuciano on January 09, 2011, 10:36:47 PM
I have tried and it works great! I will need to reformat the output of course...

Thanks a lot feline!

btw. this should be added to the tips section/list, or something, at least...
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: luuuciano on January 16, 2011, 03:46:00 PM
feline, after a couple of days I saw this errors in the logs:

2: Invalid argument supplied for foreach()
File: /home/username/public_html/foros/Themes/default/BoardIndex.template.php
Línea: 394

Any idea? what to do?
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: feline on January 16, 2011, 08:27:17 PM
please post the code for exact this line .. the I can check that.

Fel
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: luuuciano on January 16, 2011, 10:50:59 PM
Oops, sorry, here it is:


if (!$context['user']['is_guest'])
{
echo '
<span class="birthday">Cumpleaños de este mes:</span>
<p class="smalltext">';

global $smcFunc, $scripturl, $sourcedir, $txt;

include_once($sourcedir .'/Subs-Calendar.php');
$month = (int) strftime('%m', forum_time());
$year = (int) strftime('%Y', forum_time());

$start_data = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
if($month == 12)
{
   $month = 1;
   $year++;
}
else
   $month++;
$end_data = date('Y-m-d', mktime(0, 0, 0, $month, 0, $year));

$calbirthdays = getBirthdayRange($start_data, $end_data);
ksort($calbirthdays);

foreach($calbirthdays as $cdate => $data)
{
   list($cdt['year'], $cdt['month'], $cdt['day']) = explode('-', $cdate);
   foreach($data as $vals)
//      echo $smcFunc['substr']($txt['months'][intval($cdt['month'])], 0, 3) .' '. $cdt['day'] .': <a href="'. $scripturl .'?action=profile;u='. $vals['id'] .'">'. $vals['name'] .(!empty($vals['age']) ? '('. $vals['age'] .')' : '') .'</a><br />';
      echo $smcFunc['substr']($txt['months'][intval($cdt['month'])], 0, 3) .' '. $cdt['day'] .', <a href="'. $scripturl .'?action=profile;u='. $vals['id'] .'">'. $vals['name'] .(!empty($vals['age']) ? ' ('. $vals['age'] .')' : '') .'</a>. ';
}


line 394 is "foreach($calbirthdays as $cdate => $data)"
the commented echo is your original example
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: feline on January 17, 2011, 05:25:13 PM
Pleae check follow:

if(is_array($calbirthdays))
{
foreach($calbirthdays as $cdate => $data)
{
list($cdt['year'], $cdt['month'], $cdt['day']) = explode('-', $cdate);
foreach($data as $vals)
echo $smcFunc['substr']($txt['months'][intval($cdt['month'])], 0, 3) .' '. $cdt['day'] .', <a href="'. $scripturl .'?action=profile;u='. $vals['id'] .'">'. $vals['name'] .(!empty($vals['age']) ? ' ('. $vals['age'] .')' : '') .'</a>. ';
}
}


Fel
Title: Re: How to show the upcoming birthdays, at home, with the calendar OFF?
Post by: luuuciano on January 18, 2011, 12:09:08 PM
oops!
Its not doing those errors again (without change anything...)
maybe it was an old code or something... will check in a few days!

thanks a lot!