? diff
? guidelines.position.patch
? remove.useless.code.patch
? sorting.directory.patch
Index: directory.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/directory/directory.module,v
retrieving revision 1.11.2.12
diff -u -p -r1.11.2.12 directory.module
--- directory.module	18 May 2007 10:24:45 -0000	1.11.2.12
+++ directory.module	18 May 2007 15:03:30 -0000
@@ -441,18 +441,19 @@ function theme_directory_home_section($v
   foreach ($tree as $term) {
     $nodecount = 0;
     if ($showcounts || $hideempty) {
-      $nodecount = taxonomy_term_count_nodes($term->tid);
+      $nodecount = directory_taxonomy_term_count_nodes($term->tid);
     }
     $nodecount_span = '';
     if ($showcounts) {
       $item_span='<span class="directory-category-nochildren">';
-      if ($nodecount) {
+      if ($nodecount['count_own'] || $nodecount['count_children']) {
         $item_span='<span class="directory-category-haschildren">';
-        $nodecount_span = "<span class='directory-nodecount'> ($nodecount)</span>";
+        $nodecount_span = "<span class='directory-nodecount'> [". $nodecount['count_own'];
+        $nodecount_span .= $nodecount['count_children'] ? ' + '. $nodecount['count_children'] .']</span>' : ']</span>';
       }
     }
     // if desired, exclude items 
-    if ((!$hideempty) || $nodecount>0) {
+    if ((!$hideempty) || ($nodecount['count_own'] || $nodecount['count_children'])) {
       $items[] = $item_span . l(str_repeat('-', $term->depth) .' '. $term->name, "directory/$term->tid", (($term->description) ? array('title' => $term->description) : array())) 
          . $nodecount_span . '</span>';
     }
@@ -613,7 +614,7 @@ function theme_directory_resource($tid, 
     if ($num_nodes < $threshold && $taxonomy = taxonomy_get_children($tid)) {
 	    $subcat_count = variable_get('directory_subcat_res_count', 5);
       foreach ($taxonomy as $term) {
-        $count = taxonomy_term_count_nodes($term->tid);
+        $count = directory_taxonomy_term_count_nodes($term->tid);
         if ($count > 0) {
           $nodes = directory_get_nodes_by_term($term->tid, $subcat_count);
           $output .= "<div class=\"directory-sub-category\">". theme('directory_resource_section', $nodes, $term, false, $subcat_count) . "</div>\n";
@@ -657,8 +658,8 @@ function theme_directory_resource_sectio
   }
 
   if ($limit) {
-    $num_nodes = taxonomy_term_count_nodes($term->tid);
-    if ($num_nodes > $limit) {
+    $num_nodes = directory_taxonomy_term_count_nodes($term->tid);
+    if ($num_nodes['count_own'] > $limit) {
       $more = '<div class="directory-all-resources"><span class="directory-limit">'. t('%limit of %num_nodes showing in <span class="directory-term-name">"%term"</span>.', array('%limit' => $limit, '%num_nodes' => $num_nodes, '%term' => $term->name)). '  '. l(t('View all items.'), "directory/$term->tid"). "</span></div>\n";
     }
   }
@@ -800,3 +801,80 @@ function &_last(&$array) {
   return $array[key($array)];
 }
 
+/**
+ * This is a replacement function for taxonomy_term_count_nodes.
+ * See: http://drupal.org/node/144969 (drupal issue)
+ * and: http://drupal.org/node/145023 (directory issue).
+ * 
+ * Count the number of published nodes classified by a term.
+ *
+ * @param $tid
+ *   The term's ID
+ *
+ * @param $type
+ *   The $node->type. If given, taxonomy_term_count_nodes only counts
+ *   nodes of $type that are classified with the term $tid.
+ *
+ * @return $array
+ *   where: 
+ *     $array['count_own'] being the number of nodes within the term proper.
+ *     $array['count_children'] being the number of nodes in children terms, not counting those which are already counted in the parent term.
+ *     $array['own_nodes'] array of nid's within this $tid.
+ *     $array['children_nodes'] array of all the descendent nid's from children terms, not including those already set as one's own.
+ *
+ *   Results are statically cached.
+ */
+function directory_taxonomy_term_count_nodes($tid, $type = 0) {
+  static $count = array();
+
+  if (!isset($count[$type])) {
+    $count[$type] = array();
+    // In the queries below, we cannot use 'SELECT t.tid, COUNT(n.nid) AS c FROM ...'
+    // because a node may be assigned more than one term and be counted more than once. 
+    // We therefore take note of the nid's and count the number of items in the $count array, 
+    // making sure there is no duplicate.
+
+    // $type == 0 always evaluates TRUE if $type is a string
+    if (is_numeric($type)) {
+      $result = db_query(db_rewrite_sql('SELECT t.tid, n.nid FROM {term_node} t JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 '));
+    }
+    else {
+      $result = db_query(db_rewrite_sql("SELECT t.tid, n.nid FROM {term_node} t JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 AND n.type = '%s'"), $type);
+    }
+    while ($item = db_fetch_object($result)) {
+      if (!isset($count[$type][$item->tid])) {
+        $count[$type][$item->tid] = array('own_nodes' => array());
+      }
+      $count[$type][$item->tid]['own_nodes'][$item->nid] = 1;  
+    }
+  }
+
+  if (!isset($count[$type][$tid]['count_own'])) {
+    $count[$type][$tid]['count_own'] = count($count[$type][$tid]['own_nodes']);
+  }
+  
+  if (!isset($count[$type][$tid]['count_children'])) {
+    $count[$type][$tid]['count_children'] = 0;
+    $count[$type][$tid]['children_nodes'] = array();
+    foreach (_taxonomy_term_children($tid) as $c) {
+      $children = directory_taxonomy_term_count_nodes($c, $type);
+      // Add the children's own nodes:
+      foreach ($children['own_nodes'] AS $child_nid => $n) {
+        if (!isset($count[$type][$tid]['own_nodes'][$child_nid])) { // make sure the nid is not already counted for the parent.
+          $count[$type][$tid]['children_nodes'][$child_nid] = 1;
+        }
+      }
+      // Add the nodes of the children's children.
+      foreach ($children['children_nodes'] AS $child_nid => $n) {
+        if (!isset($count[$type][$tid]['own_nodes'][$child_nid])) { // make sure the nid is not already counted for the parent.
+          $count[$type][$tid]['children_nodes'][$child_nid] = 1;
+        }
+      }
+    }
+    $count[$type][$tid]['count_children'] = count($count[$type][$tid]['children_nodes']);
+  }
+
+  return $count[$type][$tid];
+}
+
+ 
