? GeoIP.dat
? lib/geoip.inc
Index: geoip.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/geoip/geoip.module,v
retrieving revision 1.2.2.1
diff -u -p -r1.2.2.1 geoip.module
--- geoip.module	20 Feb 2009 22:04:54 -0000	1.2.2.1
+++ geoip.module	23 Feb 2009 19:40:45 -0000
@@ -103,7 +103,7 @@ function geoip_data_file_validate($form_
  * Fetch the geoip info for a given ip address
  */
 function _geoip_info($ip) {
-  include_once(drupal_get_path('module', 'geoip') .'/lib/geoip.inc');
+  _geoip_load_lib();
 
   $gi = geoip_instance();
 
@@ -157,13 +157,41 @@ function geoip_country_code($ip = NULL) 
  * Singleton wrapper around geoip_open().
  */
 function geoip_instance() {
-  $data_file = variable_get('geoip_data_file', drupal_get_path('module', 'geoip') .'/GeoIP.dat');
+  $data_file = variable_get('geoip_data_file', '');
+  if (!$data_file) {
+    $data_file = drupal_get_path('module', 'geoip') . '/GeoIP.dat';
+  }
   if (!$data_file || !file_exists($data_file)) {
     drupal_set_message(t('Please <a href="!url">configure</a> the GeoIP data file location.', array('!url' => url('admin/settings/geoip'))));
     return FALSE;
   }
-  include_once(drupal_get_path('module', 'geoip') .'/lib/geoip.inc');
+  _geoip_load_lib();
   $instance = geoip_open($data_file, GEOIP_STANDARD);
 
   return $instance;
 }
+
+/**
+ * Include the external geoip libraries.
+ *
+ * @return
+ *   None
+ */
+function _geoip_load_lib() {
+  static $loaded;
+  // If we've haven't tried to include geoip.inc do so. Otherwise, just fall
+  // through.
+  if (!isset($loaded)) {
+    $loaded = TRUE;
+    if (function_exists('drupal_get_path')) {
+      // Let drupal set the path for the library.
+      $path = drupal_get_path('module', 'geoip');
+    }
+    else {
+      // Fallback to trying to find this file based on PHP's knowledge of our
+      // current path.
+      $path = dirname(__FILE__);
+    }
+    include_once($path . '/lib/geoip.inc');
+  }
+}
