'. t('The archive page allows content to be viewed by date. It also provides a monthly calendar view that users can use to navigate through content.') .'
'; $output .= ''. t('To view the archive by date, select the date in the calendar. Administrators can enable the browse archives block in block administration to allow users to browse by calendar. Clicking on a date in the monthly calendar view shows the content for that date. Users can navigate to different months using arrows beside the month\'s name in the calendar display. The current date will be highlighted in the calendar.') .'
'; $output .= t('You can
'. t('For more information please read the configuration and customization handbook Archive page.', array('%archive' => 'http://drupal.org/handbook/modules/archive/')) .'
'; return $output; case 'admin/modules#description': return t('Displays a calendar for navigating older content.'); } } /** * Implementation of hook_menu(). */ function archive_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array('path' => 'archive', 'title' => t('archives'), 'access' => user_access('access content'), 'callback' => 'archive_page', 'type' => MENU_SUGGESTED_ITEM); } return $items; } /** * Implementation of hook_block(). * * Generates a calendar for the current month, with links to the archives * for each day. */ function archive_block($op = 'list', $delta = 0) { if ($op == 'list') { $blocks[0]['info'] = t('Calendar to browse archives'); return $blocks; } else if ($op == 'view' && user_access('access content')) { $block['subject'] = t('Browse archives'); $block['content'] = archive_calendar(); return $block; } } /** * Generates a monthly calendar, for display in the archive block. */ function archive_calendar() { global $user; // Extract today's date: $start_of_today = mktime(0, 0, 0, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone; $end_of_today = mktime(23, 59, 59, date('n', time()), date('d', time()), date('Y', time())) + $user->timezone; // Extract the requested date: if (arg(0) == 'archive' && arg(3)) { $year = arg(1); $month = arg(2); $day = arg(3); $requested = mktime(0, 0, 0, $month, $day, $year) + $user->timezone; } else { $year = date('Y', time()); $month = date('n', time()); $day = date('d', time()); $requested = $end_of_today + $user->timezone; } $start_of_month = mktime(0, 0, 0, $month, 1, $year); // Extract first day of the month: $first = date('w', $start_of_month); // Extract last day of the month: $last = date('t', $start_of_month); $end_of_month = mktime(23, 59, 59, $month, $last, $year); $cache = cache_get("archive:calendar:$day-$month-$year"); 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); $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); $sql = 'SELECT n.nid, n.created FROM {node} n WHERE n.status = 1 AND n.created > %d AND n.created < %d ORDER BY n.created'; $sql = db_rewrite_sql($sql); $result = db_query($sql, $start_of_month, $end_of_month); $days_with_posts = array(); while ($day_with_post = db_fetch_object($result)) { $daynum = date('j', $day_with_post->created + $user->timezone); if (isset($days_with_posts[$daynum])) { $days_with_posts[$daynum]++; } else { $days_with_posts[$daynum] = 1; } } // Generate calendar header: $output .= "\n\n"; $output .= ''. $name . " | \n"; } $output .= "|||
---|---|---|---|
\n", $blankdays); $first = $weekstart; } // Start every week on a new line: if ($sday == $weekstart) { $output .= " | |||
$daytext | \n"; } else if ($date == $start_of_today) { $output .= "$daytext | \n"; } else if ($date > $end_of_today) { $output .= "$daytext | \n"; } else { $output .= "$daytext | \n"; } // Start every week on a new line: if ($sday == $lastday) { $output .= "\n", $end) . "\n"; } $output .= " |