--- taxonomy_search.ori	Sun May 11 11:16:36 2008
+++ taxonomy_search.module	Mon Apr 20 00:13:36 2009
@@ -3,12 +3,22 @@
 
 
 /**
+ * Implementation of hook_perm().
+ */
+function taxonomy_search_perm() {
+  return array('access taxonomy search');
+}
+
+
+/**
  * Implementation of hook_form_alter().
  */
 function taxonomy_search_form_alter($form_id, &$form) {
   switch ($form_id) {
     case 'search_form':
-      taxonomy_search_search_form_alter($form);
+      if (user_access('access taxonomy search')) {
+        taxonomy_search_search_form_alter($form);
+      }
       break;
   }
 }
@@ -131,57 +141,59 @@ function taxonomy_search_update_shutdown
  * Implementation of hook_search().
  */
 function taxonomy_search_search($op = 'search', $keys = null) {
-  switch ($op) {
-    case 'name':
-      return t('Taxonomy');
-    
-    case 'reset':
-      variable_del('taxonomy_search_cron_last_id');
-      variable_del('taxonomy_search_cron_last_change');
-      return;
+  if (user_access('access taxonomy search')) {
+    switch ($op) {
+      case 'name':
+        return t('Taxonomy');
       
-    case 'search':
-      // Build any conditionals
-      list($join1, $where1) = _db_rewrite_sql('', 'td', 'tid');
-      $conditions1 = 1;
-      $arguments1 = array();
-      $category = search_query_extract($keys, 'vocabulary');
-      if ($category || !empty($where1)) {
-        $categories = array();
-        foreach (explode(',', $category) as $c) {
-          $categories[] = "td.vid = %d";
-          $arguments1[] = $c;
+      case 'reset':
+        variable_del('taxonomy_search_cron_last_id');
+        variable_del('taxonomy_search_cron_last_change');
+        return;
+        
+      case 'search':
+        // Build any conditionals
+        list($join1, $where1) = _db_rewrite_sql('', 'td', 'tid');
+        $conditions1 = 1;
+        $arguments1 = array();
+        $category = search_query_extract($keys, 'vocabulary');
+        if ($category || !empty($where1)) {
+          $categories = array();
+          foreach (explode(',', $category) as $c) {
+            $categories[] = "td.vid = %d";
+            $arguments1[] = $c;
+          }
+          $conditions1 .= ' AND ('. implode(' OR ', $categories) .')';
+          $join1 .= 'INNER JOIN {term_data} td ON td.tid = i.sid';
+          $keys = search_query_insert($keys, 'vocabulary');
         }
-        $conditions1 .= ' AND ('. implode(' OR ', $categories) .')';
-        $join1 .= 'INNER JOIN {term_data} td ON td.tid = i.sid';
-        $keys = search_query_insert($keys, 'vocabulary');
-      }
-      
-      $conditions1 = empty($where1) ? $conditions1 : $conditions1 .' AND '. $where1;
-      
-      $hits = do_search($keys, 'taxonomy', $join1, $conditions1, $arguments1);
-      $results = array();
-      
-      if (count($hits)) {
-        foreach ($hits as $item) {
-          $term = taxonomy_get_term($item->sid);
-          $term->keys = $keys;
-          $results[] = $term;
+        
+        $conditions1 = empty($where1) ? $conditions1 : $conditions1 .' AND '. $where1;
+        
+        $hits = do_search($keys, 'taxonomy', $join1, $conditions1, $arguments1);
+        $results = array();
+        
+        if (count($hits)) {
+          foreach ($hits as $item) {
+            $term = taxonomy_get_term($item->sid);
+            $term->keys = $keys;
+            $results[] = $term;
+          }
         }
-      }
+        
+        return $results;
       
-      return $results;
-    
-    case 'status':
-      $last_changed = variable_get('taxonomy_search_cron_last_change', 0);
-      $last_tid = variable_get('taxonomy_search_cron_last_id', 0);
-      $total = db_result(db_query('SELECT COUNT(*) FROM {term_data}'));
-      $sql = "SELECT COUNT(*) 
-              FROM {taxonomy_search}
-              WHERE (GREATEST(created, changed) = %d AND tid > %d)
-              OR (created > %d OR changed > %d)";
-      $remaining = db_result(db_query($sql, $last_changed, $last_tid, $last_changed, $last_changed));
-      return array('remaining' => $remaining, 'total' => $total);
+      case 'status':
+        $last_changed = variable_get('taxonomy_search_cron_last_change', 0);
+        $last_tid = variable_get('taxonomy_search_cron_last_id', 0);
+        $total = db_result(db_query('SELECT COUNT(*) FROM {term_data}'));
+        $sql = "SELECT COUNT(*) 
+                FROM {taxonomy_search}
+                WHERE (GREATEST(created, changed) = %d AND tid > %d)
+                OR (created > %d OR changed > %d)";
+        $remaining = db_result(db_query($sql, $last_changed, $last_tid, $last_changed, $last_changed));
+        return array('remaining' => $remaining, 'total' => $total);
+    }
   }
 }
 
