Index: taxonomy_block.module
===================================================================
--- taxonomy_block.module	(revisione 77)
+++ taxonomy_block.module	(revisione 82)
@@ -69,43 +69,37 @@
     switch($delta) {
       case 0:
         $block['subject'] = t('Taxonomy Block');    
-        
-        $output  = '';
-        
-		
-		  //Check database
+        //Check database
 
-      if ($num_term == 0) {
-        $sql = " SELECT td.tid, td.name, th.parent  from {term_data} td "
-            ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
-            ." WHERE vid='%d' AND th.parent=0 ORDER BY %s %s";    
-      } else {
-        $sql = " SELECT td.tid, td.name, th.parent  from {term_data} td "
-            ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
-            ." WHERE vid='%d' AND th.parent=0 ORDER BY %s %s LIMIT %d";  
-      }
+       if ($num_term == 0) {
+         $sql = " SELECT td.tid, td.name, th.parent  from {term_data} td "
+               ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
+               ." WHERE vid='%d' AND th.parent=0 ORDER BY %s %s";
+       } else {
+         $sql = " SELECT td.tid, td.name, th.parent  from {term_data} td "
+               ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
+               ." WHERE vid='%d' AND th.parent=0 ORDER BY %s %s LIMIT %d";
+       }
       
-      $term_parents = db_query($sql, $vid, $order_by, $order_type, $num_term );
+       $term_parents = db_query($sql, $vid, $order_by, $order_type, $num_term );
 
-      $output .= '<ul class="menu">';
-      while ($term_parent = db_fetch_object($term_parents)) {
+       while ($term_parent = db_fetch_object($term_parents)) {
         $tid_parent = $term_parent->tid;
         $name_parent= $term_parent->name;
       
-        $output .= '<li>';
         $term_parent = taxonomy_get_term($tid_parent);
-        
+
+	$link_text = "";
         if (module_exists("i18n")) {
-          $output .= l(tt("taxonomy:term:$tid_parent:name", $name_parent), taxonomy_term_path($term_parent));
+	  $link_text = tt("taxonomy:term:$tid_parent:name", $name_parent);
         } else {
-          //$output .= l(t($name_parent), "taxonomy/term/$tid_parent");  
-          $output .= l(t($name_parent), taxonomy_term_path($term_parent));  
+	  $link_text = t($name_parent);
         }
         if ($node_count) {
-          $total_parent = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $tid_parent));
-          $output .= " ($total_parent)"; 
+	  $total_parent = db_result(db_query("select count(distinct(n.tnid)) from {term_node} tn inner join {node} n on tn.nid = n.nid where tid=%d and n.status=1", $tid_parent));
+	  $link_text .= " ($total_parent)";
         }
-        $output .= "</li>";
+	$links[$tid_parent]['data'] = l($link_text, taxonomy_term_path($term_parent));
         
         $sql_count_childs = " SELECT count(td.tid) from {term_data} td "
                            ." INNER JOIN {term_hierarchy} th ON th.tid=td.tid "
@@ -124,41 +118,36 @@
           }                  
           
           $term_childs = db_query($sql_term_childs, $vid, $tid_parent, $order_by, $order_type, $num_term );
-          $output .= '<ul>';
+
           while ($term_child = db_fetch_object($term_childs)) {
             $tid_child = $term_child->tid;
             $name_child = $term_child->name;
-            
-            $output .= '<li>';
+                        
             $term_child = taxonomy_get_term($tid_child);
-
+            $link_text_child = "";
             if (module_exists("i18n")) {
-              $output .= l(tt("taxonomy:term:$tid_child:name", $name_child), taxonomy_term_path($term_child));
+	      $link_text_child = tt("taxonomy:term:$tid_child:name", $name_child);
             } else {
-              $output .= l(t($name_child), taxonomy_term_path($term_child));  
+	      $link_text_child = t($name_child);
             }
             if ($node_count) {
-              $total_child = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $tid_child));
-              $output .= " ($total_child)"; 
+//              $total_child = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $tid_child));
+	      $total_child = db_result(db_query("select count(distinct(n.tnid)) from {term_node} tn inner join {node} n on tn.nid = n.nid where tid=%d and n.status=1", $tid_child));
+              $link_text_child .= " ($total_child)";
             }
-            $output .= "</li>"; 
+            // $output .= "</li>";
+	    $links[$tid_parent]['children'][] = l($link_text_child, taxonomy_term_path($term_child));
           }
-          $output .= "</ul>";
+          // $output .= "</ul>";
         }
-      }
-    
-      $output .= "</ul>";
-      
-      //if(count($items)) {
-      //  return theme('item_list',$items);
-      //}
-            
-      $block['content'] = $output;
-        
-      break;  
-    }
-    
-	  return $block;	
+       }
+       if(count($links)) {
+         $block['content'] = theme('item_list',$links, null, 'ul', array('class' => 'menu'));
+       }
+       break;
+     }
+
+    return $block;
   }
     
 }
