You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.9 KiB

  1. <!--
  2. # Adapted from
  3. # PHP Calendar (version 2.3), written by Keith Devens
  4. # http://keithdevens.com/software/php_calendar
  5. # see example at http://keithdevens.com/weblog
  6. # License: http://keithdevens.com/software/license
  7. -->
  8. <?php
  9. $first_of_month = gmmktime(0,0,0,$month,1,$year);
  10. #remember that mktime will automatically correct if invalid dates are entered
  11. # for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
  12. # this provides a built in "rounding" feature to generate_calendar()
  13. $day_names = array(); #generate all the day names according to the current locale
  14. for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
  15. $day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
  16. list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
  17. $weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
  18. $title = htmlentities(ucfirst($month_name)).'&nbsp;'.$year; #note that some locales don't capitalize month and day names
  19. #Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
  20. @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
  21. if($p) $p = '<span class="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
  22. if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
  23. $calendar = '<table class="calendar">'."\n".
  24. '<caption class="calendar-month">'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";
  25. if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
  26. #if day_name_length is >3, the full name of the day will be printed
  27. foreach($day_names as $d)
  28. $calendar .= '<th abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
  29. $calendar .= "</tr>\n<tr>";
  30. }
  31. if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</td>'; #initial 'empty' days
  32. for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
  33. if($weekday == 7){
  34. $weekday = 0; #start a new week
  35. $calendar .= "</tr>\n<tr>";
  36. }
  37. if(isset($days[$day]) and is_array($days[$day])){
  38. @list($link, $classes, $content) = $days[$day];
  39. if(is_null($content)) $content = $day;
  40. $calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
  41. ($link ? '<a href="'.htmlspecialchars($link).'" data-date="'.sprintf('%4d-%02d-%02d',$year,$month,$day).'">'.$content.'</a>' : $content).'</td>';
  42. }
  43. else $calendar .= "<td>$day</td>";
  44. }
  45. if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days
  46. echo $calendar."</tr>\n</table>\n";