Index: whois.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/whois/whois.module,v
retrieving revision 1.3
diff -u -r1.3 whois.module
--- whois.module	12 Aug 2008 11:15:57 -0000	1.3
+++ whois.module	21 Mar 2009 18:48:01 -0000
@@ -11,7 +11,7 @@
     case 'install' :
     case 'runtime' :
       $path = drupal_get_path('module', 'whois') . '/phpwhois/whois.main.php';
-	  if (!file_exists($path)) {
+      if (!file_exists($path)) {
         $requirements['whois'] = array(
           'title' => $t('Whois lookup'),
           'description' => $t("Whois module requires !phpwhois to do whois queries. !download and put it's contents in <em>modules/whois</em> directory (so that it looks something like this: <em>modules/whois/phpwhois/example.php</em>).", array('!phpwhois' => l('phpWhois library', 'http://phpwhois.sf.net/'), '!download' => l('Download phpWhois', 'http://sourceforge.net/project/showfiles.php?group_id=31207&package_id=23260'))),
@@ -102,7 +102,7 @@
     // Check for hourly threshold.
     if (flood_is_allowed('whois', variable_get('whois_hourly_threshold', 13))) {
       $output .= '<h3>' . t('Whois lookup for %address:', array('%address' => $address)) . '</h3>';
-      $output .= whois_get_whois($address);
+      $output .= whois_display_whois($address);
     }
     else {
       $output .= t("You cannot do more than %number whois lookups per hour. Please try again later.", array('%number' => variable_get('whois_hourly_threshold', 13)));
@@ -111,13 +111,6 @@
       // Avoid debug information(devel.module) from being added to the preview.
       $GLOBALS['devel_shutdown'] = FALSE;
 
-      if (variable_get('whois_log_watchdog', 1)) {
-        // Watchdog entry for lookup request.
-        watchdog('whois',
-          t('Whois lookup for: %address', array('%address' => $address)),
-          array($address), WATCHDOG_NOTICE, l('View', "whois/$address") . ' · ' . l('Address', "http://$address/"));
-      }
-
       // Stop further processing and return requested data.
       exit(drupal_json(array('html' => $output)));
     }
@@ -163,31 +156,14 @@
   global $user;
   $address = whois_parse_url($form_state['values']['whois_address']);
 
-  if (variable_get('whois_log_watchdog', 1)) {
-    // Watchdog entry for lookup request.
-    watchdog('whois',
-      t('Whois lookup for: %address', array('%address' => $address)),
-      array($address), WATCHDOG_NOTICE, l('View', "whois/$address") . ' · ' . l('Address', "http://$address/"));
-  }
-
   $form_state['redirect'] = 'whois/' . $address;
   return;
 }
 
-function whois_get_whois($address) {
+function whois_display_whois($address) {
   $data = '';
-  $path = drupal_get_path('module', 'whois') . '/phpwhois/whois.main.php';
-
-  if (!file_exists($path)) {
-    drupal_set_message(t('There are problems with <em>Whois lookup</em> setup. Report to the website administrators promptly!', array('@status' => url('admin/logs/status'))), 'error');
-  }
-  elseif ($address != '') {
-    include_once('phpwhois/whois.main.php');
-    include_once('phpwhois/whois.utils.php');
-    $option = variable_get('whois_output_method', 'html');
-    $whois = new Whois();
-    $result = $whois->Lookup($address);
-
+  $result = whois_get_whois($address);
+  if ($result) {
     switch($option) {
       case 'html':
         if (!empty($result['rawdata'])) {
@@ -223,6 +199,37 @@
   return $data;
 }
 
+/**
+ * Return the whois information for a given host.
+ *
+ * @param $address
+ *   The address of the host to look up.
+ *
+ * @return
+ *   An object describing the Whois result.
+ */
+function whois_get_whois($address) {
+  $data = '';
+  $path = drupal_get_path('module', 'whois') . '/phpwhois/whois.main.php';
+
+  if (!file_exists($path)) {
+    drupal_set_message(t('There are problems with <em>Whois lookup</em> setup. Report to the website administrators promptly!', array('@status' => url('admin/logs/status'))), 'error');
+  }
+  elseif ($address != '') {
+    include_once('phpwhois/whois.main.php');
+    include_once('phpwhois/whois.utils.php');
+    $whois = new Whois();
+    if (variable_get('whois_log_watchdog', 1)) {
+      // Watchdog entry for lookup request.
+      watchdog('whois',
+        t('Whois lookup for: %address', array('%address' => $address)),
+        array($address), WATCHDOG_NOTICE, l('View', "whois/$address") . ' · ' . l('Address', "http://$address/"));
+    }
+    return $whois->Lookup($address);
+  }
+  return FALSE;
+}
+
 function whois_parse_url($url) {
   $r  = "^(?:(?P<scheme>\w+)://)?";
   $r .= "(?:(?P<login>\w+):(?P<pass>\w+)@)?";
