Index: ip_anon.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ip_anon/Attic/ip_anon.info,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 ip_anon.info
--- ip_anon.info	31 Mar 2008 03:43:55 -0000	1.1.2.1
+++ ip_anon.info	29 Jul 2008 17:48:15 -0000
@@ -1,5 +1,3 @@
 ; $Id: ip_anon.info,v 1.1.2.1 2008/03/31 03:43:55 mfb Exp $
 name = IP anonymizer
 description = Establishes an IP address retention policy.
-package = Indymedia
-core = 6.x
Index: ip_anon.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ip_anon/Attic/ip_anon.module,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 ip_anon.module
--- ip_anon.module	31 Mar 2008 03:43:55 -0000	1.1.2.1
+++ ip_anon.module	29 Jul 2008 17:48:15 -0000
@@ -9,23 +9,75 @@
 /**
  * Implementation of hook_menu().
  */
-function ip_anon_menu() {
+function ip_anon_menu($may_cache) {
   $items = array();
-  $items['admin/settings/ip_anon'] = array(
-    'title' => 'IP anonymizer',
-    'description' => 'Configure the IP address retention policy.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('ip_anon_settings'),
-    'access arguments' => array('administer site configuration'),
-    'file' => 'ip_anon.pages.inc',
-  );
+  if ($may_cache) {
+    $items[] = array(
+      'path' => 'admin/settings/ip_anon',
+      'title' => t('IP anonymizer'),
+      'description' => t('Configure the IP address retention policy.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('ip_anon_settings'),
+      'access' => user_access('administer site configuration')
+    );
+  }
   return $items;
 }
 
 /**
  * Implementation of hook_cron().
+ *
+ * Anonymize IP addresses which have exceeded the retention period.
  */
 function ip_anon_cron() {
-  module_load_include('pages.inc', 'ip_anon');
-  ip_anon_cron_run();
+  if (variable_get('ip_anon_policy', 0)) {
+    foreach (ip_anon_tables() as $table => $columns) {
+      db_query("UPDATE {{$table}} SET {$columns['hostname']} = '%s' WHERE {$columns['timestamp']} < %d", 0, time() - variable_get('ip_anon_period_'. $table, 10800));
+    }
+  }
+}
+
+/**
+ * Configuration options for IP anonymizer.
+ */
+function ip_anon_settings() {
+  $form = array();
+  $form['ip_anon_policy'] = array(
+    '#type' => 'radios',
+    '#title' => t('Retention policy'),
+    '#options' => array(0 => t('Preserve IP addresses'), 1 => t('Anonymize IP addresses')),
+    '#description' => t('This setting may be used to temporarily disable IP anonymization.'),
+    '#default_value' => variable_get('ip_anon_policy', 0),
+  );
+  $form['ip_anon_period'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Retention period',
+    '#description' => t('IP addresses older than the retention period will be anonymized. The flood table expects a retention period of at least @one_hour.', array('@one_hour' => format_interval(3600))),
+  );
+  $options = drupal_map_assoc(array(0, 30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), 'format_interval');
+  foreach (ip_anon_tables() as $table => $columns) {
+    $form['ip_anon_period']['ip_anon_period_'. $table] = array(
+      '#type' => 'select',
+      '#title' => t('@table table', array('@table' => $table)),
+      '#options' => $options,
+      '#default_value' => variable_get('ip_anon_period_'. $table, 10800),
+    );
+  }
+  return system_settings_form($form);
+}
+
+/**
+ * Array of tables and columns which store hostnames and timestamps.
+ * Other modules may use hook_ip_anon_alter() to add tables:
+ * function my_module_ip_anon_alter(&$tables) {
+ *   $tables['my_table_name'] = array(
+ *     'hostname' => 'my_hostname_column',
+ *     'timestamp' => 'my_timestamp_column',
+ *   );
+ * }
+ */
+function ip_anon_tables() {
+  $columns = drupal_map_assoc(array('hostname', 'timestamp'));
+  $tables = array('accesslog' => $columns, 'comments' => $columns, 'flood' => $columns, 'sessions' => $columns, 'watchdog' => $columns);
+  return $tables;
 }
