--- nofollowlist.module.old	2007-07-05 10:07:01.000000000 -0400
+++ nofollowlist.module	2007-07-05 10:21:21.000000000 -0400
@@ -1,4 +1,53 @@
 <?php
+// $Id$
+
+/**
+ * Implementation of hook_menu()
+ */
+function nofollowlist_menu($may_cache) {
+  $items[] = array(
+    'path' => 'admin/settings/nofollowlist',
+    'title' => t('Nofollowlist'),
+    'description' => t('Add sites to the nofollowlist and determine whether links to those sites are followable or not.'),
+    'callback' => 'drupal_get_form',
+    'callback arguments' => array('nofollowlist_settings_form'),
+    'access' => user_access('administer nofollowlist'),
+  );
+
+  return $items;
+}
+
+/**
+ * Implementation of hook_perm().
+ */
+function nofollowlist_perm() {
+  return array('administer nofollowlist');
+}
+
+/**
+ * Builds the form for administrators to add sites to the black/white lists.
+ */
+function nofollowlist_settings_form() {
+  $form['nofollowlist_option'] = array(
+    '#type' => 'radios',
+    '#title' => t('Hosts list option'),
+    '#description' => t('If you choose the whitelist option, be sure to add your own site to the list!'),
+    '#options' => array(
+      'black' => t('Blacklist: Add rel="nofollow" to links leading to the listed hosts.'),
+      'white' => t('Whitelist: Add rel="nofollow" to all links <b>except</b> the listed hosts.'),
+    ),
+    '#default_value' => variable_get('nofollowlist_option', 'black'),
+  );
+
+  $form['nofollowlist_hosts'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Nofollowlist hosts'),
+    '#description' => t('Add one host per line. Ex: en.wikipedia.org'),
+    '#default_value' => variable_get('nofollowlist_hosts', 'en.wikipedia.org'),
+  );
+
+  return system_settings_form($form);
+}
 
 /**
  * Enter description here...
@@ -11,7 +60,7 @@
 function nofollowlist_help($section) {
   switch ($section) {
     case 'admin/help#nofollowlist':
-      $output = '<p>'. t('This module implements a simple filter to add the nofollow tag to sites that are on your blacklist.') .'</p>';
+      $output = '<p>'. t('This module implements a simple filter to add the nofollow tag to sites that are on your blacklist or to all sites except those on your whitelist.') .'</p>';
       return $output;
   }
 }
@@ -28,12 +77,12 @@ function nofollowlist_help($section) {
  *   The tip to be displayed
  */
 function nofollowlist_filter_tips($delta, $format, $long = false) {
-  $output .= '<p>'. t('Links to certain hosts will have a rel="nofollow" added to them.'). "</p>\n";
+  $output .= '<p>'. t('Links to specified hosts will have a rel="nofollow" added to them.'). "</p>\n";
   return $output;
 }
 
 /**
- * Implentation of hook_filter. Defines a filter, "nofollow list filter",
+ * Implementation of hook_filter. Defines a filter, "Nofollow list filter",
  * that can be used in conjunction with the built in HTML filter to 
  * automatically add the rel="nofollow" to links to certain sites 
  *
@@ -47,13 +96,13 @@ function nofollowlist_filter_tips($delta
 function nofollowlist_filter($op, $delta = 0, $format = -1, $text = '') {
   switch ($op) {
     case 'list':
-      return array(0 => t('nofollow list filter'));
+      return array(0 => t('Nofollow list filter'));
 
     case 'description':
-      return t('Links to certain hosts will have a rel="nofollow" added to them.');
+      return t('Links to specified hosts will have a rel="nofollow" added to them.');
 
     case "process":
-     $text = preg_replace_callback('!<a.*?href="([^"]+)".*?>!', nofollowlist_replace, $text);
+     $text = preg_replace_callback('!<a.*?href="([^"]+)".*?>!', 'nofollowlist_replace', $text);
      return $text;
 
     default:
@@ -70,12 +119,17 @@ function nofollowlist_filter($op, $delta
  */
 function nofollowlist_replace($match) {
   $url = parse_url($match[1]);
-  $blacklist = array("en.wikipedia.org");
+  $list = preg_split('/\s+/', variable_get('nofollowlist_hosts', 'en.wikipedia.org'));
 
   // Default in case it doesn't get changed.
   $link = $match[0];
 
-  if (in_array($url['host'],$blacklist)) {
+  // Matches if the list is set as a blacklist and the host is in the list or if
+  // the list is set as a whitelist and the host is not found in the list.
+  if ((variable_get('nofollowlist_option', 'black') == 'black' &&
+       in_array($url['host'], $list)) ||
+      (variable_get('nofollowlist_option', 'black') == 'white' &&
+       !in_array($url['host'], $list))) {
     if (strpos($match[0], 'nofollow') === FALSE) {
 
       // Only add the nofollow if it doesn't already exist.
@@ -91,6 +145,6 @@ function nofollowlist_replace($match) {
       }
     }
   }
-  
+
   return $link;
 }
\ No newline at end of file
