Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

December 01, 2022, 12:20:03 AM

Login with username, password and session length
Members
  • Total Members: 3853
  • Latest: tty456
Stats
  • Total Posts: 193625
  • Total Topics: 21107
  • Online today: 26
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 1
Guests: 25
Total: 26

Author Topic: SMF Calendar Block  (Read 287894 times)

0 Members and 2 Guests are viewing this topic.

Offline bloc

  • Founder
  • *
  • Posts: 5229
    • Bloc
SMF Calendar Block
« on: September 03, 2005, 04:30:42 AM »
Here is simple calendar to be used in a php-block, the code is from http://keithdevens.com/software/php_calendar , slightly modified. It simply displays the date and the days in current month/year. Current day is highlighted. Probably better to turn off "title/frame" in the block as well. :)

Code: [Select]
global $scripturl;

         $now = mktime();
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: red; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = NULL;
         $first_day = 0;
         $pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);
#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()

$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr>";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr>";
}
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content))  $content  = $day;
$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
}
else $calendar .= "<td class=\"smalltext\">$day</td>";
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar."</tr>\n</table>\n";


See screenshot for how it looks.

[attachment deleted by admin]
« Last Edit: June 16, 2008, 10:47:34 AM by Xarcell »

Racenut

  • Guest
Re: Calendar in a php-block
« Reply #1 on: September 03, 2005, 05:37:50 AM »
Worked like a charm  :) I do agree Bloc that it would be cool to have the mini calendar call info from the forum calendar. To me, it looks better using the frame.

In my opinion, this is the stuff that is going to make TP shine. To me, versitility in a portal is the most important thing. You code guru's keep coming up with more neat stuff  :laugh:
« Last Edit: September 03, 2005, 05:42:47 AM by Racenut »

Miraenda

  • Guest
Re: Calendar in a php-block
« Reply #2 on: September 03, 2005, 08:32:49 AM »
Great feature to include, and I think linking it to the forum's calendar would be fantastic, too.  Is this a possibility to have in a future TP version this calendar available and linking to the forum's calendar then? :)

ontap

  • Guest
Re: Calendar in a php-block
« Reply #3 on: September 03, 2005, 09:09:34 AM »

thanks for looking into this bloc, is there anyway of highlighten events or birthdays on the calendar block?

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Calendar in a php-block
« Reply #4 on: September 03, 2005, 09:29:10 AM »
Currently this Calendar isn't integrated with the SMF one. So having events or birthdays etc. isn't possible.  I imagine that will be another little project that he'll be adding to his list.

Offline bloc

  • Founder
  • *
  • Posts: 5229
    • Bloc
Re: Calendar in a php-block
« Reply #5 on: September 04, 2005, 01:45:01 AM »
Its not difficult to link events, birthdays etc. to it..but I will need to add fetching of the info to the code.

I was thinking perhaps adding some form of "snippet downloading" in tpadmin section at one point..but I archived that one for the time being. A live news part telling what snippets is availabe is more realistic perhaps. Adding of course latest version of TP available too.

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: Calendar in a php-block
« Reply #6 on: September 04, 2005, 01:13:55 PM »
That is an awesome idea Bloc. That would make it so easy for everyone to customize their TP's.

Offline bloc

  • Founder
  • *
  • Posts: 5229
    • Bloc
Re: Calendar in a php-block
« Reply #7 on: September 05, 2005, 04:04:48 AM »
Yes, I am going for this, especially when its so many versions out.

borgBOB

  • Guest
Re: Calendar in a php-block
« Reply #8 on: September 07, 2005, 12:44:56 AM »
Does this calendar adjust to the user selected / or board default theme?

pcw

  • Guest
Re: Calendar in a php-block
« Reply #9 on: September 07, 2005, 04:16:01 AM »
I've done a little change in this block.
It doesn't shows info from the smf calendar but now it links month and days to it

Code: [Select]
$now = mktime();
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 1;
         $pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);
#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()

$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content))  $content  = $day;
$calendar .= '<td "'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
}
else
{
$calendar .= "<td class=\"smalltext\" style=\"padding-right:4px;\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar."</tr>\n</table>\n";
« Last Edit: September 07, 2005, 04:53:08 AM by pcw »