diff options
author | Dries Buytaert <dries@buytaert.net> | 2003-06-05 21:34:56 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2003-06-05 21:34:56 +0000 |
commit | 56e3e7d4a9b60f2cc11626c277f4c33249846a5c (patch) | |
tree | c8899c463575ca8739ad1e0d4533ff7954aa8051 | |
parent | 522ed4d64ce7b271cd6cbb6da259361eadda3c40 (diff) | |
download | brdo-56e3e7d4a9b60f2cc11626c277f4c33249846a5c.tar.gz brdo-56e3e7d4a9b60f2cc11626c277f4c33249846a5c.tar.bz2 |
- 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'.
-rw-r--r-- | modules/archive.module | 39 | ||||
-rw-r--r-- | modules/archive/archive.module | 39 |
2 files changed, 66 insertions, 12 deletions
diff --git a/modules/archive.module b/modules/archive.module index 51ca1db35..a39cc9f9c 100644 --- a/modules/archive.module +++ b/modules/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<!-- calendar -->\n"; $output .= "<div class=\"calendar\">"; @@ -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 .= " <td class=\"day-selected\">$nday</td>\n"; + $output .= " <td class=\"day-selected\">$daytext</td>\n"; } else if ($date == $start_of_today) { - $output .= " <td class=\"day-today\">". l($nday, "archive/$year/$month/$nday") ."</td>\n"; + $output .= " <td class=\"day-today\">$daytext</td>\n"; } else if ($date > $end_of_today) { - $output .= " <td class=\"day-future\">$nday</td>\n"; + $output .= " <td class=\"day-future\">$daytext</td>\n"; } else { - $output .= " <td class=\"day-link\">". l($nday, "archive/$year/$month/$nday") ."</td>\n"; + $output .= " <td class=\"day-link\">$daytext</td>\n"; } // Start every week on a new line: @@ -113,6 +138,8 @@ function archive_calendar($original = 0) { $output .= "</table></div>\n\n"; + cache_set("archive:calendar:$first", $output, time() + variable_get("cache_clear", 120)); + return $output; } 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<!-- calendar -->\n"; $output .= "<div class=\"calendar\">"; @@ -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 .= " <td class=\"day-selected\">$nday</td>\n"; + $output .= " <td class=\"day-selected\">$daytext</td>\n"; } else if ($date == $start_of_today) { - $output .= " <td class=\"day-today\">". l($nday, "archive/$year/$month/$nday") ."</td>\n"; + $output .= " <td class=\"day-today\">$daytext</td>\n"; } else if ($date > $end_of_today) { - $output .= " <td class=\"day-future\">$nday</td>\n"; + $output .= " <td class=\"day-future\">$daytext</td>\n"; } else { - $output .= " <td class=\"day-link\">". l($nday, "archive/$year/$month/$nday") ."</td>\n"; + $output .= " <td class=\"day-link\">$daytext</td>\n"; } // Start every week on a new line: @@ -113,6 +138,8 @@ function archive_calendar($original = 0) { $output .= "</table></div>\n\n"; + cache_set("archive:calendar:$first", $output, time() + variable_get("cache_clear", 120)); + return $output; } |