? profile_taxonomy-929008.patch
Index: profile_taxonomy.api.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/profile_taxonomy/profile_taxonomy.api.inc,v
retrieving revision 1.3
diff -u -p -r1.3 profile_taxonomy.api.inc
--- profile_taxonomy.api.inc	16 Jun 2010 08:52:27 -0000	1.3
+++ profile_taxonomy.api.inc	1 Oct 2010 22:03:18 -0000
@@ -36,7 +36,7 @@ function profile_taxonomy_get_profile_fi
   $result = db_query($sql, $vid);
   $fields = array();
   while (($row = db_fetch_object($result)) != NULL) {
-  	$fields[] = db_fetch_object(db_query("SELECT * FROM {profile_fields} WHERE fid = %d", $row->fid));
+    $fields[] = db_fetch_object(db_query("SELECT * FROM {profile_fields} WHERE fid = %d", $row->fid));
   }
   return $fields;
 }
@@ -82,10 +82,12 @@ function profile_taxonomy_add($fid, $vid
  *   profile taxonomy assignements
  */
 function profile_taxonomy_get_assignments() {
-  $result = db_query('SELECT * FROM {profile_taxonomy}');
-  $assignments = array();
-  while (($row = db_fetch_object($result)) != NULL) {
-    $assignments[] = $row;
+  static $assignments = array();
+  if (empty($assignments)) {
+    $result = db_query('SELECT * FROM {profile_taxonomy}');
+    while (($row = db_fetch_object($result)) != NULL) {
+      $assignments[] = $row;
+    }
   }
   return $assignments;
-}
\ No newline at end of file
+}
Index: profile_taxonomy.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/profile_taxonomy/profile_taxonomy.module,v
retrieving revision 1.7
diff -u -p -r1.7 profile_taxonomy.module
--- profile_taxonomy.module	23 Aug 2010 19:16:41 -0000	1.7
+++ profile_taxonomy.module	1 Oct 2010 22:03:18 -0000
@@ -22,7 +22,7 @@ function profile_taxonomy_menu() {
   $items['profile_taxonomy'] = array(
     'access arguments' => FALSE,
   );
-  
+
   $items['profile_taxonomy/list_vocabulary_terms'] = array(
     'page callback' => 'profile_taxonomy_list_vocabulary_terms',
     'access arguments' => array('access content'),
@@ -52,7 +52,7 @@ function profile_taxonomy_init() {
 }
 
 /**
- * Implementation of hook_form_alter() adapting user related forms. 
+ * Implementation of hook_form_alter() adapting user related forms.
  * @param $form
  *   array of form content
  * @param $form_state
@@ -64,9 +64,9 @@ function profile_taxonomy_form_alter(&$f
   //Alter the profile field's administration form. Vocabularies are referenced here
   //that supply the term names as options.
   switch ($form_id) {
-  	case 'profile_field_form':
+    case 'profile_field_form':
       $type = _profile_taxonomy_get_field_type($form); //determine field type
-      switch ($type) { 
+      switch ($type) {
         case 'selection':
           profile_taxonomy_field_type_selection($form);
           //load terms dynamically when user selects a certain vocabulary
@@ -103,7 +103,7 @@ function profile_taxonomy_field_type_sel
     }
   }
   $form['fields']['vocabulary'] = $taxonomy; //add vocabularies selection to form
-  array_unshift($form['#submit'], 'profile_taxonomy_field_type_selection_submit'); //additional submit handler 
+  array_unshift($form['#submit'], 'profile_taxonomy_field_type_selection_submit'); //additional submit handler
 }
 
 /**
@@ -115,14 +115,14 @@ function profile_taxonomy_field_type_sel
   //get submit parameter
   $fid = $form_state['values']['fid']; //profile field
   $vocabulary = $form_state['values']['vocabulary']; //assigned vocabulary
-    
+
   if (!$form_state['values']['options']) {
     $tree = taxonomy_get_tree($vocabulary); //get taxonomy terms
     if ($tree) { //build tree, i. e. term list
-      foreach ($tree as $term) 
+      foreach ($tree as $term)
         $form_state['values']['options'] .= $term->name . "\r\n";
     }
-  }  
+  }
 
   //remove field assignment
   profile_taxonomy_delete_by_fid($fid);
@@ -148,11 +148,11 @@ function profile_taxonomy_field_type_sel
 function profile_taxonomy_taxonomy($op, $type, $array = NULL) {
   switch ($type) {
     case 'vocabulary':
-	  profile_taxonomy_taxonomy_vocabulary($op, $array);	
-	  break;	
-	case 'term':
-	  profile_taxonomy_taxonomy_term($op, $array);
-	  break; 
+    profile_taxonomy_taxonomy_vocabulary($op, $array);
+    break;
+  case 'term':
+    profile_taxonomy_taxonomy_term($op, $array);
+    break;
   }
 }
 
@@ -169,10 +169,10 @@ function profile_taxonomy_taxonomy_vocab
       //get all profile fields which have assignments to this vocabulary
       $fields = profile_taxonomy_get_profile_fields($voc['vid']);
       foreach ($fields as $field) {
-      	//delete profile field options
-        db_query("UPDATE profile_fields SET options = '' WHERE fid = %d", $field->fid); 
-		profile_taxonomy_delete_by_vid($voc['vid']); //remove assignment
-      }	    
+        //delete profile field options
+        db_query("UPDATE profile_fields SET options = '' WHERE fid = %d", $field->fid);
+    profile_taxonomy_delete_by_vid($voc['vid']); //remove assignment
+      }
   }
 }
 
@@ -184,57 +184,57 @@ function profile_taxonomy_taxonomy_vocab
  *   array of term data
  */
 function profile_taxonomy_taxonomy_term($op, $term) {
-			
+
   $fields = profile_taxonomy_get_profile_fields($term['vid']);
   $options = _profile_taxonomy_list_vocabulary_terms($term['vid']);
-  
+
   if (!$options[$term['tid']]) //new term, add to options
-    $options[$term['tid']] = $term['name'];  
-		  
+    $options[$term['tid']] = $term['name'];
+
   foreach ($fields as $field) {
     if ($options[$term['tid']]) {//existing term
-	  $option =& $options[$term['tid']];
-	  
-	  //match against single and multiple, values, e. g. "term" or "termA", "termB"
-	  $result = db_query(
-	  			"SELECT value FROM {profile_values} 
-	  			WHERE fid = %d AND (value = '%s' OR value LIKE '%s' OR value LIKE '%s' OR value LIKE '%s')", 
-	  			$field->fid, 
-	  			$option, "$option,%", "%, $option,%", "%, $option");
-	  $value = db_fetch_object($result)->value;
-	  $bits = explode(',', $value);
-	  if (!empty($bits)) {
-	    foreach ($bits as $id => &$bit) {
-	      $bit = trim($bit);
-  		  if ($option == $bit) {
-  		  	if ($op == 'update' || $op == 'instert')
-  		  	  $bit = $term['name'];
-  		  	elseif ($op == 'delete')
-  		  	  unset($bits[$id]);
-  		  }
-	    }
-	    $new_value = implode(', ', $bits);
-	  }
-	  else {
-	    $new_value = $term['name'];
-	  }
-	 
-	  switch ($op) {
-	    case 'insert':
-	    case 'update':
-	   	  db_query("UPDATE profile_values SET value = '%s' WHERE fid = %d AND (value = '%s' OR value LIKE '%s' OR value LIKE '%s' OR value LIKE '%s')", $new_value, $field->fid, $option, "$option,%", "%, $option,%", "%, $option");
-		  $option = $term['name'];
-		  break;
-	    case 'delete':
-	      db_query("UPDATE profile_values SET value = '%s' WHERE fid = %d AND (value = '%s' OR value LIKE '%s' OR value LIKE '%s' OR value LIKE '%s')", $new_value, $field->fid, $option, "$option,%", "%, $option,%", "%, $option");
-		  unset($options[$term['tid']]);
-		  break;
-	  }
-	  
-	  //update profile field options
-	  sort($options);
-	  $field->options = implode("\r\n", $options);
-	  db_query("UPDATE profile_fields SET options = '%s' WHERE fid = %d", $field->options, $field->fid); 
+    $option =& $options[$term['tid']];
+
+    //match against single and multiple, values, e. g. "term" or "termA", "termB"
+    $result = db_query(
+          "SELECT value FROM {profile_values}
+          WHERE fid = %d AND (value = '%s' OR value LIKE '%s' OR value LIKE '%s' OR value LIKE '%s')",
+          $field->fid,
+          $option, "$option,%", "%, $option,%", "%, $option");
+    $value = db_fetch_object($result)->value;
+    $bits = explode(',', $value);
+    if (!empty($bits)) {
+      foreach ($bits as $id => &$bit) {
+        $bit = trim($bit);
+        if ($option == $bit) {
+          if ($op == 'update' || $op == 'instert')
+            $bit = $term['name'];
+          elseif ($op == 'delete')
+            unset($bits[$id]);
+        }
+      }
+      $new_value = implode(', ', $bits);
+    }
+    else {
+      $new_value = $term['name'];
+    }
+
+    switch ($op) {
+      case 'insert':
+      case 'update':
+         db_query("UPDATE profile_values SET value = '%s' WHERE fid = %d AND (value = '%s' OR value LIKE '%s' OR value LIKE '%s' OR value LIKE '%s')", $new_value, $field->fid, $option, "$option,%", "%, $option,%", "%, $option");
+      $option = $term['name'];
+      break;
+      case 'delete':
+        db_query("UPDATE profile_values SET value = '%s' WHERE fid = %d AND (value = '%s' OR value LIKE '%s' OR value LIKE '%s' OR value LIKE '%s')", $new_value, $field->fid, $option, "$option,%", "%, $option,%", "%, $option");
+      unset($options[$term['tid']]);
+      break;
+    }
+
+    //update profile field options
+    sort($options);
+    $field->options = implode("\r\n", $options);
+    db_query("UPDATE profile_fields SET options = '%s' WHERE fid = %d", $field->options, $field->fid);
     }
   }
 }
@@ -295,12 +295,12 @@ function profile_taxonomy_user_load(&$ac
  *   associative array of vocabulary terms
  */
 function _profile_taxonomy_list_vocabulary_terms($vid) {
-	$options = array();
-	$tree = taxonomy_get_tree($vid); //get taxonomy terms
+  $options = array();
+  $tree = taxonomy_get_tree($vid); //get taxonomy terms
   if ($tree) { //build tree, i. e. term list
-    foreach ($tree as $term) 
+    foreach ($tree as $term)
        $options[$term->tid] = $term->name;
-  }  
+  }
   return $options;
 }
 
@@ -328,7 +328,11 @@ function _profile_taxonomy_get_field_typ
  *   profile field object
  */
 function _profile_taxonomy_get_profile_field_by_id($fid) {
-  return db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
+  static $profiles = array();
+  if (empty($profiles[$fid])) {
+    $profiles[$fid] = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
+  }
+  return $profiles[$fid];
 }
 
 /**
@@ -346,4 +350,4 @@ function _profile_taxonomy_vocabularies_
     $options[$vid] = $voc->name;
 
   return $options;
-}
\ No newline at end of file
+}
