? LICENSE.txt ? enhance_texts.diff ? nodeapi.diff ? settings.diff Index: taxonomy_hide.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_hide/taxonomy_hide.module,v retrieving revision 1.4 diff -u -2 -r1.4 taxonomy_hide.module --- taxonomy_hide.module 27 Dec 2006 12:15:23 -0000 1.4 +++ taxonomy_hide.module 27 Dec 2006 14:02:14 -0000 @@ -77,12 +77,17 @@ switch ($op) { case 'view': - $hidden = variable_get('taxonomy_hide_vocabularies', array ()); - if (count($hidden) == 0 && !variable_get('taxonomy_hide_group_by_vocabulary', 0)) { - return; + # Get all hidden vocabularies; keys of $hidden are the vocabulary ids. + $hidden = array_filter(variable_get('taxonomy_hide_vocabularies', array())); + if (count($hidden)) { + # Hide terms by removing them from the taxonomy field + foreach ($node->taxonomy as $key => $value) { + if (array_key_exists($value->vid, $hidden)) { + unset($node->taxonomy[$key]); + } + } } - foreach ($node->taxonomy as $key => $value) { - if ($hidden[$value->vid]) { - unset($node->taxonomy[$key]); - } + if (variable_get('taxonomy_hide_group_by_vocabulary', 0)) { + # Sort terms by sorting the taxonomy field + usort($node->taxonomy, "_taxonomy_hide_sort"); } break; @@ -91,4 +96,51 @@ } +# Comparison function for the usort of vocabulary terms. +function _taxonomy_hide_sort($a, $b) { + # Cache the extra vocabulary information (we need the vocabulary weight) + static $vocs = array(); + if (!array_key_exists($a->vid, $vocs)) { + $vocs[$a->vid] = taxonomy_get_vocabulary($a->vid); + } + if (!array_key_exists($b->vid, $vocs)) { + $vocs[$b->vid] = taxonomy_get_vocabulary($b->vid); + } + + # Compare first by vocabulary weight, next by vocabulary id, next by + # term weight, next by term name, and finally by term id. + # This is the same order as used by taxonomy_node_get_terms, except that + # we group by vocabulary too. + if ($vocs[$a->vid]->weight < $vocs[$b->vid]->weight) { + return -1; + } + elseif ($vocs[$a->vid]->weight > $vocs[$b->vid]->weight) { + return 1; + } + elseif ($a->vid < $b->vid) { + return -1; + } + elseif ($a->vid > $b->vid) { + return 1; + } + elseif ($a->weight < $b->weight) { + return -1; + } + elseif ($a->weight > $b->weight) { + return 1; + } + elseif (strcasecmp($a->name, $b->name)) { + return strcasecmp($a->name, $b->name); + } + elseif ($a->tid < $b->tid) { + return -1; + } + elseif ($a->tid > $b->tid) { + return 1; + } + else { + return 0; + } +} + # vim:ft=php sw=2