SimplePortal

Customization => Custom Coding => Topic started by: edi67 on October 11, 2008, 03:01:45 PM

Title: Calendar Block
Post by: edi67 on October 11, 2008, 03:01:45 PM
These are 2 type of calendar for our Simpleportal ;) need only to create one NEW PHP BLOCK and insert code in php block it's all

Regards to oringal author:
http://keithdevens.com/software/php_calendar

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

This same version but with events and months clickable for smf calendar
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";
Title: Re: Calendar Block
Post by: cme1st2302 on October 21, 2008, 09:10:24 AM
Thanks works great!!

Chris
Title: Re: Calendar Block
Post by: Flip on October 23, 2008, 11:16:23 AM
will either of the codes above show the holidays on the calendar in the block?
And take it from the defined settings - example, show upcoming holidays x number of days before they arrive?
If not, any clue how to do that?
What I want to do, if it's possible, is to have one block that has the calendar in the top part of it and the upcoming events, birthdays and holidays in the bottom part of it. This way, for the visually impaired, the screen readers can read it a lot easier.

Thanks in advance,
Flip
Title: Re: Calendar Block
Post by: Costa on October 23, 2008, 11:24:21 AM
It works fine to me here

Thank you!
Title: Re: Calendar Block
Post by: Burke Knight on October 26, 2008, 11:01:08 AM
How do you change it so it shows Sunday at first of the week?
All members have that set in profiles, but the block still shows it at end of week.
Title: Re: Calendar Block
Post by: cme1st2302 on October 26, 2008, 05:58:27 PM
find this code
Code: [Select]
$first_day = 0;
and change the 0 to 1
Title: Re: Calendar Block
Post by: AlenNS on October 26, 2008, 08:44:08 PM
Is it possible to translate months and days?
Title: Re: Calendar Block
Post by: Burke Knight on October 26, 2008, 09:29:24 PM
find this code
Code: [Select]
$first_day = 0;
and change the 0 to 1

Actually, it was at 1, and I had to change it to 0.
But thank you, you at least showed me the way. :)
Title: Re: Calendar Block
Post by: AlenNS on October 27, 2008, 11:42:25 PM
Is it possible to translate months and days?
Bump.
Title: Re: Calendar Block
Post by: ???1031 on October 28, 2008, 01:40:24 AM
Bump.
Which one do you use? :)
Title: Re: Calendar Block
Post by: AlenNS on October 28, 2008, 10:59:11 AM
Serbianl-utf8

Serbian has latin and cyrilic.
I'm using latin. :)
Title: Re: Calendar Block
Post by: Aw06 on October 28, 2008, 11:53:06 AM
I entered the second code posted, but in my block its not displaying events, ... so im not seeing halloween/etc ??

Running SP 2.0.4 .. SMF 1.1.6
Title: Re: Calendar Block
Post by: cme1st2302 on October 28, 2008, 12:17:22 PM
As far as I know, the events part of the second code lets you click on a date to post an event.  It does not show events.

Chris
Title: Re: Calendar Block
Post by: Aw06 on October 28, 2008, 12:25:23 PM
Check here http://www.burkeknight.com/ and http://yarriesafety.mine.nu/

They both displaying events .. unless they using a diff or edited code ...

can those website owners give some imput please  8)
Title: Re: Calendar Block
Post by: cme1st2302 on October 28, 2008, 12:38:20 PM
Yes please!!!  That is what I want as well!!
Title: Re: Calendar Block
Post by: Manu on October 28, 2008, 02:43:11 PM
Here you can find the codes for the calendar you can see at the sites there:
http://simpleportal.net/index.php?topic=89.0
Title: Re: Calendar Block
Post by: Mithotyn on October 29, 2008, 06:06:30 PM
Thank you  :applause:
Title: Re: Calendar Block
Post by: GreenStork on November 08, 2008, 09:06:31 AM
Thank you very much!  ;D
Title: Re: Calendar Block
Post by: jb3398 on December 31, 2008, 10:05:39 PM
Second PHP Block worked like a charm! Just what I was looking for.
SimplePortal 2.3.8 © 2008-2024, SimplePortal