From 56e3e7d4a9b60f2cc11626c277f4c33249846a5c Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 5 Jun 2003 21:34:56 +0000 Subject: - Usability improvements: in the calendar, only add a link for days on which new nodes have been posted. Patch by Al. Al: I modified the query slightly - it will check whether 'status = 1'. --- modules/archive/archive.module | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'modules/archive') diff --git a/modules/archive/archive.module b/modules/archive/archive.module index 51ca1db35..a39cc9f9c 100644 --- a/modules/archive/archive.module +++ b/modules/archive/archive.module @@ -29,11 +29,21 @@ function archive_calendar($original = 0) { $requested = $end_of_today; } + $start_of_month = mktime(0, 0, 0, $month, 1, $year); + // Extract first day of the month: - $first = date("w", mktime(0, 0, 0, $month, 1, $year)); + $first = date("w", $start_of_month); // Extract last day of the month: - $last = date("t", mktime(0, 0, 0, $month, 1, $year)); + $last = date("t", $start_of_month); + + $end_of_month = mktime(23,59,59, $month, $last, $year); + + $cache = cache_get("archive:calendar:$start_of_month"); + + if (!empty($cache)) { + return $cache->data; + } // Calculate previous and next months dates and check for shorter months (28/30 days) $prevmonth = mktime(23, 59, 59, $month - 1, 1, $year); @@ -41,6 +51,15 @@ function archive_calendar($original = 0) { $nextmonth = mktime(23, 59, 59, $month + 1, 1, $year); $next = mktime(23, 59, 59, $month + 1, min(date("t", $nextmonth), $day), $year); + + $result = db_query("SELECT created FROM node WHERE status = 1 AND created > $start_of_month AND created < $end_of_month"); + + $days_with_posts = array(); + while ($day_with_post = db_fetch_object($result)) { + $days_with_posts[] = date("j", $day_with_post->created); + } + $days_with_posts = array_unique($days_with_posts); + // Generate calendar header: $output .= "\n\n"; $output .= "
"; @@ -81,17 +100,23 @@ function archive_calendar($original = 0) { // Print one cell: $date = mktime(0, 0, 0, $month, $nday, $year); + if (in_array($nday, $days_with_posts)) { + $daytext = l($nday, "archive/$year/$month/$nday"); + } + else { + $daytext = $nday; + } if ($date == $requested) { - $output .= " $nday\n"; + $output .= " $daytext\n"; } else if ($date == $start_of_today) { - $output .= " ". l($nday, "archive/$year/$month/$nday") ."\n"; + $output .= " $daytext\n"; } else if ($date > $end_of_today) { - $output .= " $nday\n"; + $output .= " $daytext\n"; } else { - $output .= " ". l($nday, "archive/$year/$month/$nday") ."\n"; + $output .= " $daytext\n"; } // Start every week on a new line: @@ -113,6 +138,8 @@ function archive_calendar($original = 0) { $output .= "
\n\n"; + cache_set("archive:calendar:$first", $output, time() + variable_get("cache_clear", 120)); + return $output; } -- cgit v1.2.3