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.

51 lines
2.9 KiB

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