Index: location.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_import/supported/Attic/location.inc,v
retrieving revision 1.4.4.2
diff -u -r1.4.4.2 location.inc
--- location.inc	17 Mar 2008 13:02:50 -0000	1.4.4.2
+++ location.inc	19 Aug 2008 04:25:11 -0000
@@ -10,9 +10,22 @@
   }
 
   $fields = array();
-  foreach ((array)location_field_names() as $field => $fieldname) {
-    if (variable_get('location_'. $field .'_'. $type, $field == 'country' ? 1 : 0)) {
-      $fields['node_import_location_'. $field] = t('Location: @fieldname', array('@fieldname' => $fieldname));
+  if (function_exists('location_newapi')) {
+    // Location 3.x.
+    $settings = _node_import_location_newapi_get_settings($type);
+    $names = location_field_names();
+    foreach ($settings as $field => $enabled) {
+      if ($enabled) {
+        $fields['node_import_location_'. $field] = t('Location: @fieldname', array('@fieldname' => $names[$field]));
+      }
+    }
+  }
+  else {
+    // Location 2.x and under.
+    foreach ((array)location_field_names() as $field => $fieldname) {
+      if (variable_get('location_'. $field .'_'. $type, $field == 'country' ? 1 : 0)) {
+        $fields['node_import_location_'. $field] = t('Location: @fieldname', array('@fieldname' => $fieldname));
+      }
     }
   }
   if (user_access('submit latitude/longitude')) {
@@ -33,6 +46,14 @@
   $errors = array();
   $location = array();
 
+  if (function_exists('location_newapi')) {
+    // Location 3.x.
+    $dummy = '';
+    // Load in default values.
+    $location = location_invoke_locationapi($dummy, 'default values');
+  }
+
+
   $location_fields = array_keys((array)location_field_names());
   $location_fields[] = 'latitude';
   $location_fields[] = 'longitude';
@@ -68,8 +89,19 @@
   }
 
   // Validate required fields (see location_nodeapi('validate')).
+  if (function_exists('location_newapi')) {
+    // Location 3.x.
+    $settings = _node_import_location_newapi_get_settings($node->type);
+  }
   foreach ((array)location_field_names() as $field => $fieldname) {
-    $workflow = variable_get('location_'. $field .'_'. $node->type, $field == 'country' ? 1 : 0);
+    if (function_exists('location_newapi')) {
+      // Location 3.x.
+      $workflow = $settings[$field];
+    }
+    else {
+      // Location 2.x and under.
+      $workflow = variable_get('location_'. $field .'_'. $node->type, $field == 'country' ? 1 : 0);
+    }
     switch ($workflow) {
       case 0: // not collected
         unset($location[$field]);
@@ -164,8 +196,15 @@
 function _node_import_location_get_province_code($province, $country) {
   static $codes = array();
   if (!isset($codes[$country])) {
-    $form = _location_province_select_options('', FALSE, $country);
-    $codes[$country] = (array)$form['#options'];
+    if (function_exists('location_newapi')) {
+      // Location 3.x.
+      $codes[$country] = location_get_provinces($country);
+    }
+    else {
+      // Location 2.x and under.
+      $form = _location_province_select_options('', FALSE, $country);
+      $codes[$country] = (array)$form['#options'];
+    }
   }
 
   $province = strtolower($province);
@@ -177,3 +216,16 @@
 
   return '';
 }
+
+/**
+ * Get the field settings for Location 3.x installs.
+ */
+function _node_import_location_newapi_get_settings($type) {
+  $dummy = '';
+  $defaults = location_invoke_locationapi($dummy, 'default values');
+  $settings = array_merge(
+    location_invoke_locationapi($dummy, 'default values'),
+    variable_get('location_fields_'. $type, array())
+  );
+  return $settings;
+}

