--- X:/Homepages/drupal/module/_D6/_D60809/_issues/taxonomy_menu_issue122648/curdev/taxonomy_menu.inc	Thu Sep 11 16:28:36 2008
+++ X:/Homepages/drupal/module/_D6/_D60809/_issues/taxonomy_menu_issue122648/taxonomy_menu.inc	Thu Sep 11 16:13:18 2008
@@ -1,7 +1,6 @@
 <?php
-// $Id: taxonomy_menu.inc,v 1.3 2008/09/08 19:21:56 afief Exp $
-
 /**
+ * $Id: taxonomy_menu.inc,v 1.2 2008/01/31 16:51:55 brmassa Exp $
  * @author Jonathan Chaffer   <jchaffer@structureinteractive.com>
  * @author Bruno Massa        <http://drupal.org/user/67164>
  * @file taxonomy_menu.inc
@@ -24,24 +23,20 @@
 
   // If the Views module is enabled, add some special
   // new features
-//   if (module_exists('views')) {
-//     // Add the Views file with more functions
-//     require_once(drupal_get_path('module', 'views') .'/views_cache.inc');
-//
-//     // Add a new options on Categories
-//     $options[TAXONOMY_MENU_VIEW] = t('Views');
-//
-//     // Get the list of User generated views
-//     $views = db_query("SELECT * FROM {view_view}");
-//     while ($view = db_fetch_array($views)) {
-//       $views_list[$view['name']] = $view['page_title'];
-//     }
-//
-//     // Now get a list of default Views
-//     foreach (_views_get_default_views() as $view => $viewdata) {
-//       $views_list[$view] = $viewdata->name;
-//     }
-//   }
+   if (module_exists('views')) {
+     // Add the Views file with more functions
+     require_once(drupal_get_path('module', 'views') .'/includes/cache.inc');
+
+     // Add a new options on Categories
+     $options[TAXONOMY_MENU_VIEW] = t('Views');
+
+     // Get the list of User generated views
+     $views = db_query("SELECT * FROM {views_view} a LEFT JOIN {views_display} b ON a.vid=b.vid");
+     while ($view = db_fetch_array($views)) {
+        $views_list[$view['name'].':'.$view['id']] = $view['name'].' : '.$view['id'];
+     }
+     
+   }
 
   // If the Taxonomy Default module is enabled, add some special
   // new features
@@ -64,14 +59,14 @@
     );
 
     // In case of View options selected, select Views
-//     if (module_exists('views')) {
-//       $form[$vocab->vid]['taxonomy_menu_show_view_'. $vocab->vid] = array(
-//         '#default_value'  => variable_get('taxonomy_menu_show_view_'. $vocab->vid, ''),
-//         '#options'        => $views_list,
-//         '#title'          => t('Views available'),
-//         '#type'           => 'select'
-//       );
-//     }
+     if (module_exists('views')) {
+       $form[$vocab->vid]['taxonomy_menu_show_view_'. $vocab->vid] = array(
+         '#default_value'  => variable_get('taxonomy_menu_show_view_'. $vocab->vid, ''),
+         '#options'        => $views_list,
+         '#title'          => t('Views available'),
+         '#type'           => 'select'
+       );
+     }
   }
 
   // General options
@@ -125,7 +120,7 @@
   foreach (taxonomy_get_vocabularies() as $vocab) {
     variable_set('taxonomy_menu_show_'. $vocab->vid,
       $form_state['values']['taxonomy_menu_show_'. $vocab->vid]);
-    variable_set('taxonomy_menu_show_views_'. $vocab->vid,
+    variable_set('taxonomy_menu_show_view_'. $vocab->vid,
       $form_state['values']['taxonomy_menu_show_view_'. $vocab->vid]);
   }
 
@@ -188,12 +183,10 @@
             $name .= ' ('. $num .')';
           }
           $items[$path] = array(
-            'access arguments' => array('access content'),
-            'file'            => 'taxonomy_menu.inc',
-            'page callback'   => '_taxonomy_menu_page',
+        	'access arguments'    => array('access content'),          
             'description'     => t($term->description),
             'title'           => $name,
-            'weight'          => $term->weight,
+            'weight'          => $term->weight
           );
         }
       }
@@ -235,24 +228,24 @@
       $old_path   = $path;
 
        if ($term->tid == $vocab[0]) { //create all the breadcrumb items
-         $breadcrumb=array();
-         $tmpterm=$term;
-         $patharray=explode('/', $path);
-
-         while($tmpterm) { //create items for all the ancestors
-           $breadcrumb[] = l($tmpterm->name, implode('/', $patharray));
-           array_pop($patharray);
-           if(isset($tmpterm->parents[0])) $tmpterm = taxonomy_get_term($tmpterm->parents[0]); 
-           else unset($tmpterm); //we're done with ancestors
-         }
- 
-        $vocabulary = taxonomy_vocabulary_load($term->vid);
-        $breadcrumb[] = l($vocabulary->name, implode('/', $patharray)); //add the vocabulary item
-        $breadcrumb[] = l(t('Home'), '<front>');
- 
-        drupal_set_breadcrumb(array_reverse($breadcrumb));
 
-        // Quit after the first match.
+		$breadcrumb=array();
+		$tmpterm=$term;
+		$patharray=explode('/', $path);
+
+		while($tmpterm) { //create items for all the ancestors
+		  $breadcrumb[] = l($tmpterm->name, implode('/', $patharray));
+		  array_pop($patharray);
+		  if(isset($tmpterm->parents[0])) $tmpterm = taxonomy_get_term($tmpterm->parents[0]); 
+		  else unset($tmpterm); //we're done with ancestors
+		}
+
+		$vocabulary = taxonomy_vocabulary_load($term->vid);
+		$breadcrumb[] = l($vocabulary->name, implode('/', $patharray)); //add the vocabulary item
+		$breadcrumb[] = l(t('Home'), '<front>');
+
+		drupal_set_breadcrumb(array_reverse($breadcrumb));
+		// Quit after the first match.
         return;
       }
     }
@@ -306,19 +299,20 @@
     elseif (variable_get('taxonomy_menu_show_'. $vid, TAXONOMY_MENU_NONE) == TAXONOMY_MENU_VIEW) {
       // Get the last page argument
       $tid = explode('/', $_GET['q']);
-      $tid = db_escape_string(array_pop($tid));
-
-      $arguments[] = $vid;
-
-      // Only add the Term ID if its not the Vocabulary ID
-      if ($vid != $tid) {
-        $arguments[] = $tid;
+	  while ($vid2 = array_shift($tid)){
+		if ($vid2 == $vid) {break;}
+	  }
+	  $tid = (empty($tid))?FALSE:db_escape_string(array_pop($tid));
+
+      list($wview, $wpage) = explode(':', variable_get('taxonomy_menu_show_view_'. $vid, ''));
+      
+      // Only add the Term ID if it is present
+      if (!$tid) {
+		$output = views_page($wview,$wpage,$vid);
       }
-
-      // Embed the views output into the page
-      $output = views_build_view('embed',
-        views_get_view(variable_get('taxonomy_menu_show_views_'. $vid, '')),
-        $arguments, FALSE, NULL);
+      else {
+		$output = views_page($wview,$wpage,$vid,$tid);
+  	  }  
     }
     elseif (variable_get('taxonomy_menu_show_'. $vid, TAXONOMY_MENU_NONE) == TAXONOMY_MENU_DEFAULT_TAX) {
 
