Index: taxonomy_hide.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/taxonomy_hide/taxonomy_hide.module,v
retrieving revision 1.6
diff -u -p -r1.6 taxonomy_hide.module
--- taxonomy_hide.module	27 Dec 2006 14:10:01 -0000	1.6
+++ taxonomy_hide.module	4 May 2007 11:44:29 -0000
@@ -1,94 +1,104 @@
 <?php
 
-/* $Id: taxonomy_hide.module,v 1.6 2006/12/27 14:10:01 frodo Exp $ */
+/* $Id$ */
+
+
+function taxonomy_hide_menu($may_cache) {
+  $items = array();
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/build/taxonomy_hide',
+      'title' => t('Taxonomy hide'),
+      'description' => t('Hide and group vocabulary terms in node views.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => 'taxonomy_hide_admin_settings',
+      'access' => user_access('administer site configuration'), // or 'administer taxonomy'
+    );
+  }
+  
+  return $items;
+}
+
 
 function taxonomy_hide_help($section) {
   $output = '';
   switch ($section) {
-    case 'admin/modules#description':
-      $output = t('Hides and groups vocabulary terms in node views.');
+    case 'admin/build/taxonomy_hide':
+      $output = t('The taxonomy_hide module allows you to hide and group vocabulary terms in node views.');
       break;
+    
     case 'admin/help#taxonomy_hide':
-      $output = t('<p>The taxonomy_hide module allows you to hide and group vocabulary terms in node views.<p>'.
-                  '<p>When you view a node, you usually see all vocabulary terms it is associated with. Sometimes, you might want to hide terms of a specific vocabulary. This module allows you to specify the vocabularies whose terms are never displayed in node views.</p>'.
-		  '<p>The list of vocabulary terms is usually sorted first by vocabulary weight, and next alphabetically. So terms of different vocabularies with the same weight are mixed. This module allows you to group terms by vocabulary in node views, which means that all terms of one vocabulary are always next to each other.</p>'.
-		  '<p>You can</p>'.
-		  '<ul><li>Specify vocabularies whose terms will be hidden at %admin</li><li>Enable grouping of vocabulary terms at %admin</li></ul>',
-		  array('%admin' => l('administer >> settings >> taxonomy_hide', 'admin/settings/taxonomy_hide')));
+      $output = t(
+        '<p>The taxonomy_hide module allows you to hide and group vocabulary terms in node views.</p>'.
+        '<p>When you view a node, you usually see all vocabulary terms it is associated with. Sometimes, you might want to hide terms of a specific vocabulary. This module allows you to specify the vocabularies whose terms are never displayed in node views.</p>'.
+        '<p>The list of vocabulary terms is usually sorted first by vocabulary weight, and next alphabetically. So terms of different vocabularies with the same weight are mixed. This module allows you to group terms by vocabulary in node views, which means that all terms of one vocabulary are always next to each other.</p>'.
+        '<p>You can</p>'.
+        '<ul><li>Specify vocabularies whose terms will be hidden at !admin</li><li>Enable grouping of vocabulary terms at !admin</li></ul>',
+        array('!admin' => l('administer >> settings >> taxonomy_hide', 'admin/settings/taxonomy_hide'))
+      );
       break;
   }
-
+  
   return $output;
 }
 
-function taxonomy_hide_settings() {
+function taxonomy_hide_admin_settings() {
+  $form = array();
   $form['taxonomy_hide'] = array(
     '#type' => 'fieldset',
     '#title' => t('Vocabulary settings'),
   );
-  if (!module_exist('taxonomy')) {
-    $form['taxonomy_hide'][] = array(
-      '#type' => 'markup',
-      '#value' => l(t('Taxonomy module not enabled'), 'admin/modules')
-    );
-  }
-  else {
-    $form['taxonomy_hide_group_by_vocabulary'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Group by vocabulary'),
-      '#return_value' => 1,
-      '#default_value' => variable_get('taxonomy_hide_group_by_vocabulary', 0),
-      '#description' => t('Check this box to group terms by vocabulary in node views.'),
-      '#weight' => -1,
-    );
+  $form['taxonomy_hide_group_by_vocabulary'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Group by vocabulary'),
+    '#return_value' => 1,
+    '#default_value' => variable_get('taxonomy_hide_group_by_vocabulary', 0),
+    '#description' => t('Check this box to group terms by vocabulary in node views.'),
+    '#weight' => -1,
+  );
 
-    # Note that the settings will be saved as an array whose keys are
-    # the vocabulary ids ($vid) and whose values are 0 (disabled) or 
-    # $vid (enabled).
-    # The default_value should be an array whose values are the enabled
-    # vocabulary ids.
-    # The options should be an array whose keys are the vocabulary ids,
-    # and whose values are the names of the vocabularies.
-    $select = array();
-    $vocabularies = taxonomy_get_vocabularies();
-    foreach ($vocabularies as $vocabulary) {
-      $select[$vocabulary->vid] = $vocabulary->name;
-    }
-    $form['taxonomy_hide']['taxonomy_hide_vocabularies'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Hide vocabularies'),
-      '#default_value' => array_keys(array_filter(variable_get('taxonomy_hide_vocabularies', array()))),
-      '#options' => $select,
-      '#description' => t('Select the vocabularies whose terms should disappear from node views'),
-      '#extra' => '',
-      '#multiple' => true,
-    );
-  }
-  
-  return $form;
+  # Note that the settings will be saved as an array whose keys are
+  # the vocabulary ids ($vid) and whose values are 0 (disabled) or 
+  # $vid (enabled).
+  # The default_value should be an array whose values are the enabled
+  # vocabulary ids.
+  # The options should be an array whose keys are the vocabulary ids,
+  # and whose values are the names of the vocabularies.
+  $select = array();
+  $vocabularies = taxonomy_get_vocabularies();
+  foreach ($vocabularies as $vocabulary) {
+    $select[$vocabulary->vid] = $vocabulary->name;
+  }
+  $form['taxonomy_hide']['taxonomy_hide_vocabularies'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Hide vocabularies'),
+    '#default_value' => array_keys(array_filter(variable_get('taxonomy_hide_vocabularies', array()))),
+    '#options' => $select,
+    '#description' => t('Select the vocabularies whose terms should disappear from node views'),
+    '#extra' => '',
+    '#multiple' => true,
+  );
+
+  return system_settings_form($form);
 }
 
 
 function taxonomy_hide_nodeapi(&$node, $op, $arg = 0, $arg2 = 0) {
-  if (!module_exist('taxonomy')) {
-    return;
-  }
-  
   switch ($op) { 
     case 'view':
       # 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]);
-	  }
-	}
+      if (count($hidden) && !empty($node->taxonomy)) {
+        # 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]);
+          }
+        }
       }
       if (variable_get('taxonomy_hide_group_by_vocabulary', 0)) {
-	# Sort terms by sorting the taxonomy field
-	usort($node->taxonomy, "_taxonomy_hide_sort");
+        # Sort terms by sorting the taxonomy field
+        usort($node->taxonomy, "_taxonomy_hide_sort");
       }
       break;
   }
@@ -141,7 +151,3 @@ function _taxonomy_hide_sort($a, $b) {
     return 0;
   }
 }
-
-# vim:ft=php sw=2
-
-?>
