104 lines
3.4 KiB
Plaintext
104 lines
3.4 KiB
Plaintext
<?php
|
|
|
|
class Calendar {
|
|
var $date;
|
|
|
|
function calendar($date = 0) {
|
|
// Prevent future dates
|
|
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
|
|
$this->date = (($date && $date <= $today) ? $date : $today);
|
|
}
|
|
|
|
function display() {
|
|
// Extract information from the given date:
|
|
$month = date("n", $this->date);
|
|
$year = date("Y", $this->date);
|
|
$day = date("d", $this->date);
|
|
|
|
// Extract today's date:
|
|
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
|
|
|
|
// Extract the timestamp of the last day of today's month:
|
|
$thislast = mktime(23, 59, 59, date("n", time()), date("t", time()), date("Y", time()));
|
|
|
|
// Extract first day of the month:
|
|
$first = date("w", mktime(0, 0, 0, $month, 1, $year));
|
|
|
|
// Extract last day of the month:
|
|
$last = date("t", mktime(0, 0, 0, $month, 1, $year));
|
|
|
|
// Calculate previous and next months dates and check for shorter months (28/30 days)
|
|
$prevmonth = mktime(23, 59, 59, $month - 1, 1, $year);
|
|
$prev = mktime(23, 59, 59, $month - 1, min(date("t", $prevmonth), $day), $year);
|
|
$nextmonth = mktime(23, 59, 59, $month + 1, 1, $year);
|
|
$next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year);
|
|
|
|
// Generate calendar header:
|
|
$output .= "\n<!-- calendar -->\n";
|
|
$output .= "<TABLE WIDTH=\"100%\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"1\">\n";
|
|
$output .= " <TR><TD ALIGN=\"center\" COLSPAN=\"7\"><SMALL><A HREF=\"index.php?date=$prev\"><</A> ". date("F Y", $this->date) ." " . ($next <= $thislast ? "<A HREF=\"index.php?date=$next\">></A>" : ">") . "</SMALL></TD></TR>\n";
|
|
|
|
// Generate the days of the week:
|
|
$output .= " <TR>";
|
|
$somesunday = mktime(0, 0, 0, 3, 20, 1994);
|
|
for ($i = 0; $i < 7; $i++) {
|
|
$output .= "<TD ALIGN=\"center\"><SMALL>" . substr(ucfirst(t(date("l", $somesunday + $i * 86400))), 0, 1) . "</SMALL></TD>";
|
|
}
|
|
$output .= "</TR>\n";
|
|
|
|
// Initialize temporary variables:
|
|
$nday = 1;
|
|
$sday = $first;
|
|
|
|
// Loop through all the days of the month:
|
|
while ($nday <= $last) {
|
|
// Set up blank days for first week of the month:
|
|
if ($first) {
|
|
$output .= " <TR><TD COLSPAN=\"$first\"> </TD>\n";
|
|
$first = 0;
|
|
}
|
|
|
|
// Start every week on a new line:
|
|
if ($sday == 0) $output .= " <TR>\n";
|
|
|
|
// Print one cell:
|
|
$date = mktime(23, 59, 59, $month, $nday, $year);
|
|
if ($date == $this->date) $output .= " <TD ALIGN=\"center\"><SMALL><B>$nday</B></SMALL></TD>\n";
|
|
else if ($date > $today) $output .= " <TD ALIGN=\"center\"><SMALL>$nday</SMALL></TD>\n";
|
|
else $output .= " <TD ALIGN=\"center\"><SMALL><A HREF=\"index.php?date=$date\" STYLE=\"text-decoration: none;\">$nday</A></SMALL></TD>\n";
|
|
|
|
// Start every week on a new line:
|
|
if ($sday == 6) $output .= " </TR>\n";
|
|
|
|
// Update temporary variables:
|
|
$sday++;
|
|
$sday = $sday % 7;
|
|
$nday++;
|
|
}
|
|
|
|
// Complete the calendar:
|
|
if ($sday) {
|
|
$end = 7 - $sday;
|
|
$output .= " <TD COLSPAN=\"$end\"> </TD>\n </TR>\n";
|
|
}
|
|
$output .= "</TABLE>\n\n";
|
|
|
|
// Return calendar:
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
function calendar_block() {
|
|
global $date;
|
|
|
|
$calendar = new Calendar($date);
|
|
|
|
$block[0]["subject"] = "Browse archives";
|
|
$block[0]["content"] = $calendar->display();
|
|
$block[0]["info"] = "Calendar to browse archives";
|
|
|
|
return $block;
|
|
}
|
|
|
|
?>
|