### Eclipse Workspace Patch 1.0
#P Archive
Index: archive.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/archive/archive.module,v
retrieving revision 1.30
diff -u -r1.30 archive.module
--- archive.module	29 Dec 2007 17:25:30 -0000	1.30
+++ archive.module	3 Jan 2008 18:45:49 -0000
@@ -77,40 +77,29 @@
 
 /**
  * Returns a single month as a calendar grid.
- * 
- * @todo
- *   Take the archive logic out to allow better theme-overloading
- *   of this function.
  */
-function theme_archive_block_calendar($timestamp) {
+function theme_archive_block_calendar($day_posts, $month_post_count, $timestamp) {
   $the_date = explode(' ', format_date($timestamp, 'custom', 'F Y n t'));
-  $title = $the_date[0] .' '. $the_date[1];
   $year = $the_date[1];
   $month = $the_date[2];
   $num_days = (int)$the_date[3];
   
   $date = _archive_date('all', $year, $month);
   
-  $month_title = '';
-  if (in_array($month, $date->months)) {
-    $month_title = l($title, _archive_url('all', $date, $year, $month), array('title' => format_plural($date->months[format_date($timestamp, 'custom', 'n')], '1 post', '@count posts')));
-  }
-  else {
-    $month_title = $title;
+  // Fashion us up a nice title. Link to archive page
+  // for current month if posts exist.
+  $title = $the_date[0] .' '. $the_date[1];
+  if ($month_post_count) {
+    $title = l($title, _archive_url('all', $date, $year, $month), array('title' => format_plural($month_post_count, '1 post', '@count posts')));
   }
   
-  $rows[] = array(
-    array('data' => $month_title, 'colspan' => 7, 'style' => 'text-align:center'),
-  );
-  
-  // Build the week starting with 
+  // Build the week starting with the first day
   $first_day_of_week = variable_get('date_first_day', 0);
   $week = array(t('Sun'), t('Mon'), t('Tue'), t('Wed'), t('Thu'), t('Fri'), t('Sat'));
   $day_titles = array();
   for ($i = $first_day_of_week; $i < $first_day_of_week + 7; $i++) {
     $day_titles[] = $week[$i%7];
   }
-  $rows[] = $day_titles;
   
   // Grab the first day of the month using the user's timezone
   list($start_year, $start_month) = explode(' ', format_date($timestamp, 'custom', 'Y m'));
@@ -121,8 +110,8 @@
   // From http://www.theadminzone.com/forums/showthread.php?t=17490
   for ($i = 1-$weekday;$i <= ceil(($weekday+$num_days)/7)*7;$i++) {
     if ($i > 0) {
-      if (array_key_exists($i, $date->days)) {
-        $days_row[] = l($i, _archive_url('all', $year, $month, $i), array('title' => format_plural($date->days[$i], '1 post', '@count posts')));
+      if (array_key_exists($i, $day_posts)) {
+        $days_row[] = l($i, _archive_url('all', $year, $month, $i), array('title' => format_plural($day_posts[$i], '1 post', '@count posts')));
       }
       else if ($i <= $num_days) {
         $days_row[] = $i;
@@ -141,7 +130,8 @@
       $days_row[] = '';
     }
   }
-  return theme('table', array(), $rows);
+  
+  return theme('table', $day_titles, $rows, array(), $title);
 }
 
 
@@ -154,9 +144,14 @@
     return $blocks;
   }
   else if ($op == 'view') {
+    list($year, $month) = explode(' ', format_date(time(), 'custom', 'Y n'));
+    $date = _archive_date('all', $year, $month);
+
+    $month_post_count = is_null($date->months[$month])?0:$date->months[$month];
+
     $block = array(
       'subject' => t('Archives'),
-      'content' => theme('archive_block_calendar', time()),
+      'content' => theme('archive_block_calendar', $date->days, $month_post_count, time())
     );
     return $block;
   }
