Index: site_map.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/site_map/site_map.module,v
retrieving revision 1.39.2.17
diff -u -r1.39.2.17 site_map.module
--- site_map.module	21 Aug 2009 06:58:49 -0000	1.39.2.17
+++ site_map.module	16 Sep 2009 21:23:00 -0000
@@ -39,6 +39,12 @@
     'site_map_feed_icon' => array(
       'arguments' => array('url' => NULL, 'type' => 'node'),
     ),
+    'site_map_menu_item' => array(
+      'arguments' => array(),
+    ),
+    'site_map_menu_tree' => array(
+      'arguments' => array(),
+    ),
   );
 }
 
@@ -332,7 +338,7 @@
       $tree = menu_tree_all_data($node->book['menu_name'], $node->book);
       $data = array_shift($tree);
       $output .= theme('book_title_link', $data['link']);
-      $output .= ($data['below']) ? menu_tree_output($data['below']) : '';
+      $output .= ($data['below']) ? _site_map_menu_tree_output($data['below']) : '';
     }
 
     if ($output) {
@@ -365,7 +371,7 @@
       if (module_exists('i18nmenu')) {
         i18nmenu_localize_tree($tree);
       }
-      $menu_display = menu_tree_output($tree);
+      $menu_display = _site_map_menu_tree_output($tree);
       if (!empty($menu_display)) {
         $title = $menu['title'];
         $output .= theme('site_map_box', $title, $menu_display, 'sitemap-menu');
@@ -534,3 +540,63 @@
 
   return $message;
 }
+
+/**
+ * This is a clone of the core menu_tree_output() function with the exception
+ * of theme('site_map_menu_tree') for theming override reasons.
+ */
+function _site_map_menu_tree_output($tree) {
+  $output = '';
+  $items = array();
+
+  // Pull out just the menu items we are going to render so that we
+  // get an accurate count for the first/last classes.
+  foreach ($tree as $data) {
+    if (!$data['link']['hidden']) {
+      $items[] = $data;
+    }
+  }
+
+  $num_items = count($items);
+  foreach ($items as $i => $data) {
+    $extra_class = NULL;
+    if ($i == 0) {
+      $extra_class = 'first';
+    }
+    if ($i == $num_items - 1) {
+      $extra_class = 'last';
+    }
+    $link = theme('menu_item_link', $data['link']);
+    if ($data['below']) {
+      $output .= theme('site_map_menu_item', $link, $data['link']['has_children'], _site_map_menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
+    }
+    else {
+      $output .= theme('site_map_menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
+    }
+  }
+  return $output ? theme('site_map_menu_tree', $output) : '';
+}
+
+/**
+ * This is a clone of the core theme_menu_tree() function with the exception of
+ * the site_map specific class name used in the UL that also allow themers to
+ * override the function only for the sitemap page.
+ */
+function theme_site_map_menu_tree($tree) {
+  return '<ul class="site-map-menu">'. $tree .'</ul>';
+}
+
+/**
+ * This is a one by one clone of the core theme_menu_item() function that allows
+ * custom theming of the sitemap page items.
+ */
+function theme_site_map_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
+  $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
+  if (!empty($extra_class)) {
+    $class .= ' '. $extra_class;
+  }
+  if ($in_active_trail) {
+    $class .= ' active-trail';
+  }
+  return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
+}
