Index: gallery_menu.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/gallery/gallery_menu/Attic/gallery_menu.module,v
retrieving revision 1.1.2.13
diff -u -r1.1.2.13 gallery_menu.module
--- gallery_menu.module	30 Sep 2007 15:32:53 -0000	1.1.2.13
+++ gallery_menu.module	5 Oct 2007 22:57:05 -0000
@@ -48,6 +48,7 @@
  */
 function gallery_menu_enable() {
   variable_set('gallery_page_callback', 'gallery_menu_page');
+  cache_clear_all('gallery_menu:', 'cache', TRUE);
 }
 
 /**
@@ -61,21 +62,35 @@
  * Function gallery_menu_page().
  */
 function gallery_menu_page() {
+  if (!empty($_GET['g2_path'])) {
+    $_GET['g2_path'] = rtrim($_GET['g2_path'], '/');
+  }
   $result = gallery_page(TRUE);
-  if (isset($result['themeData']['pageUrl']['itemId'])) {
-    $id = $result['themeData']['pageUrl']['itemId'];
-    $item = gallery_item_details($id);
-    if ($item['g2type'] != 'GalleryAlbumItem') {
-      $id = $item['g2parent'];
+  if (isset($result['themeData']['item'])) {
+    $id = $result['themeData']['item']['id'];
+    if ($result['themeData']['item']['entityType'] != 'GalleryAlbumItem') {
+      $id = $result['themeData']['item']['parentId'];
+    }
+    $url_generator =& $GLOBALS['gallery']->getUrlGenerator();
+    if (isset($url_generator->_shortUrls)) {
+      $path = _gallery_menu_album_path($id);
     }
-    list($ret, $parents) = GalleryCoreApi::fetchParentSequence($id);
+    else {
+      list($ret, $parents) = GalleryCoreApi::fetchParentSequence($id);
+      if ($ret) {
+        gallery_error(t('Error fetching item parents'), $ret);
+      }
+      else {
+        array_shift($parents);
+        $path = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
+      }
+    }
+    list($ret, $root) = GalleryCoreApi::getDefaultAlbumId();
     if ($ret) {
-      gallery_error(t('Error fetching item parents'), $ret);
+      gallery_error(t('Error calling getDefaultAlbumId()'), $ret);
     }
     else {
-      array_shift($parents);
-      $path = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
-      menu_set_active_item($path);
+      menu_set_active_item(($id == $root) ? 'gallery' : $path);
     }
   }
   
@@ -122,15 +137,21 @@
   foreach (array_keys($tree) as $id) {
     $album = gallery_item_details($id);
     if (variable_get('gallery_menu_show_'. $id, 1)) {
-      $path = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
-      $items[] = array(
-        'path' => $path,
-        'title' => $album['title'],
-        'callback' => 'gallery_menu_album',
-        'callback arguments' => array($id),
-        'access' => user_access('access gallery'),
-        'type' => MENU_DYNAMIC_ITEM
-      );
+      $item = array();
+      // Check for URL Rewrite being available
+      $url_generator =& $GLOBALS['gallery']->getUrlGenerator();
+      if (isset($url_generator->_shortUrls)) {
+        $item['path'] = _gallery_menu_album_path($id);
+      }
+      else {
+        $item['path'] = 'gallery/'. (count($parents) ? implode('/', $parents) .'/' : '') . $id;
+        $item['callback'] = 'gallery_menu_album';
+        $item['callback arguments'] = array($id);
+      }
+      $item['title'] = $album['title'];
+      $item['access'] = user_access('access gallery');
+      $item['type'] = MENU_DYNAMIC_ITEM;
+      $items[] = $item;
       if (count($tree[$id])) {
         array_push($parents, $id);
         _gallery_menu_traverse($tree[$id], $items);
@@ -142,6 +163,16 @@
 }
 
 /**
+ * Function _gallery_menu_album_path().
+ */
+function _gallery_menu_album_path($id) {
+  $path = urldecode(gallery_generate_url(array('itemId' => $id), FALSE, FALSE));
+  $path = rtrim(substr($path, strlen(base_path())), '/');
+  
+  return $path;
+}
+
+/**
  * Function _gallery_menu_settings().
  */
 function _gallery_menu_settings() {
