--- blockregion.module	2008-11-23 16:40:45.000000000 +0100
+++ blockregion.new.module	2008-12-12 13:02:55.000000000 +0100
@@ -28,7 +28,7 @@
       array( 
 				'all_themes' => array(
 				  '#type' => 'fieldset',
-				  '#title' => 'Theme sharing options',
+				  '#title' => t('Theme sharing options'),
 				  'basic' => array(
 				    '#type' => 'checkbox',
 				    '#title' => t('Apply all settings except "Region" to all themes\' blocks'),
@@ -56,7 +56,7 @@
  * @return
  *   An array of system name of the regions in the form $region['name'] = 'description'.
  */
-function  blockregion_region_list($theme_key) {
+function blockregion_region_list($theme_key) {
   static $list = array();
 
   if (!array_key_exists($theme_key, $list)) {
@@ -68,7 +68,7 @@
 }
 
 /**
- * Perform best match between an string and a collection of strings.
+ * (Private) Perform best match between an string and a collection of strings.
  * 
  * @param $haystack
  *   Collection of strings where to search.
@@ -77,7 +77,7 @@
  * @return
  *   Index of the best matching element of the $haystack.
  */
-function blockregion_levenshtein_match($haystack, $needle) {
+function _blockregion_levenshtein_match($haystack, $needle) {
 	$shortest = 255;
 	$needle = strtolower(str_replace(" ", "", $needle));
 	for ($i = 0; $i < count($haystack); $i++) {
@@ -110,11 +110,12 @@
 	  $block['region'] = $block['status'] ? $block['region'] : '';
 	  $block['throttle'] = isset($block['throttle']) ? $block['throttle'] : 0;
     foreach ($themes as $theme) {
-    	$exists = db_fetch_array(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['module'], $block['delta'], $theme));
-    	if (is_array($exists))
+    	$exists = db_result(db_query("SELECT count(*) FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['module'], $block['delta'], $theme));
+    	if ($exists) {
 	 	 		db_query("UPDATE {blocks} SET status = %d, weight = %d, throttle = %d WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['throttle'], $block['module'], $block['delta'], $theme);
-    	else
+    	} else {
     		db_query("INSERT INTO {blocks} (status, weight, throttle, module, delta, theme) VALUES (%d, %d, %d, '%s', '%s', '%s')", $block['status'], $block['weight'], isset($block['throttle']) ? $block['throttle'] : 0, $block['module'], $block['delta'], $theme);
+			}
 	  }
 	}
 }
@@ -138,19 +139,19 @@
 			} else {
 				// Match this theme region name with other theme region names
 				$other_regions = blockregion_region_list($theme);
-				$match_index = blockregion_levenshtein_match($other_regions, $block['region']);
+				$match_index = _blockregion_levenshtein_match($other_regions, $block['region']);
 				$match_region = $other_regions[$match_index];
 	    }
-			$exists = db_fetch_array(db_query("SELECT bid FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['module'], $block['delta'], $theme));
-			if (is_array($exists))
+			$exists = db_result(db_query("SELECT count(*) FROM {blocks} WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['module'], $block['delta'], $theme));
+			if ($exists) {
 				db_query("UPDATE {blocks} SET region = '%s' WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $match_region, $block['module'], $block['delta'], $theme);
-			else
+			} else {
 				db_query("INSERT INTO {blocks} (region) VALUES('%s') WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $match_region, $block['module'], $block['delta'], $theme);
+			}
 		}
 	}
 }
 
-
 /**
  * Custom submit handler.
  */
@@ -168,26 +169,29 @@
 
 	$themes = array();
 	// Select enabled themes only
-	foreach (list_themes() as $theme => $themeObj) {
-		if ($themeObj->status) {
+	foreach (list_themes() as $theme => $theme_object) {
+		if ($theme_object->status) {
 			$themes[] = $theme;
 		}
 	}
 
 	// Perform basic settings sharing
-  if($do_basic)
+  if($do_basic) {
  		blockregion_basic_sharing($blocks, $themes);
+	}
 	// Perform region settings sharing
-  if($do_regions)
+  if($do_regions) {
  		blockregion_region_sharing($blocks, $themes);
-
+	}
 
   if ($do_basic || $do_regions) {
   	$themes_string = implode(', ', $themes);		
-		if($do_basic)
-			drupal_set_message(t('Block settings have been shared with the following themes: %themes_string.', array("%themes_string" =>$themes_string)));
-	  if($do_regions)
-	  	drupal_set_message(t('Regions settings have been shared with the following themes: %themes_string.', array("%themes_string" =>$themes_string)));
+		if($do_basic) {
+			drupal_set_message(t('Block settings have been shared with the following themes: %themes_string.', array("%themes_string" => $themes_string)));
+		}
+	  if($do_regions) {
+	  	drupal_set_message(t('Regions settings have been shared with the following themes: %themes_string.', array("%themes_string" => $themes_string)));
+		}
   }
   cache_clear_all();
-}
\ No newline at end of file
+}
