? mollom-client-api.pdf
? mollom.temp.inc
? mollom.token.inc
? molstats
? xmlrpc calls.txt
? translations/th.po
Index: mollom.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.module,v
retrieving revision 1.2.2.62
diff -u -p -r1.2.2.62 mollom.module
--- mollom.module	25 May 2009 12:57:54 -0000	1.2.2.62
+++ mollom.module	10 Jun 2009 01:39:57 -0000
@@ -274,8 +274,8 @@ function mollom_report_node_submit($form
 function mollom_mail_alter(&$message) {
   if (isset($GLOBALS['mollom_response']) && isset($GLOBALS['mollom_response']['session_id'])) {
     $report_link = t('Report as inappropriate: @link', array('@link' => url('mollom/contact/'. $GLOBALS['mollom_response']['session_id'], array('absolute' => TRUE))));
-    // The _mail_alter hook seems to accept both arrays as strings so we 
-    // need to handle both. TODO: it seems like something we want to clean 
+    // The _mail_alter hook seems to accept both arrays as strings so we
+    // need to handle both. TODO: it seems like something we want to clean
     // up upstream.
     if (is_array($message['body'])) {
       $message['body'][] = $report_link;
@@ -900,6 +900,9 @@ function mollom_theme() {
     'mollom' => array(
       'arguments' => array('element' => NULL),
     ),
+    'mollom_block_statistics' => array(
+      'arguments' => array('statistics' => NULL),
+    ),
   );
 }
 
@@ -1048,18 +1051,33 @@ function _mollom_insert_captcha(&$mollom
 
 /**
  * This function contacts Mollom to verify the configured key pair.
+ *
+ * @param $show_message
+ *   A boolean if TRUE will alert the user to the current Mollom key status
+ *   using drupal_set_message(). If FALSE, it will just return the status.
+ * @return
+ *   TRUE if the keys are valid and working, FALSE otherwise.
  */
-function _mollom_verify_key() {
+function _mollom_verify_key($show_message = TRUE) {
   $status = mollom('mollom.verifyKey');
 
   if ($status === NETWORK_ERROR) {
-    drupal_set_message(t('We tried to contact the Mollom servers but we encountered a network error. Please make sure that your web server can make outgoing HTTP requests.'), 'error');
+    if ($show_message) {
+      drupal_set_message(t('We tried to contact the Mollom servers but we encountered a network error. Please make sure that your web server can make outgoing HTTP requests.'), 'error');
+    }
+    return FALSE;
   }
   else if ($status === MOLLOM_ERROR) {
-    drupal_set_message(t('We contacted the Mollom servers to verify your keys: your keys do not exist or are no longer valid. Please visit the <em>Manage sites</em> page on the Mollom website again: <a href="@mollom-user">@mollom-user</a>.', array('@mollom-user' => 'http://mollom.com/user')), 'error');
+    if ($show_message) {
+      drupal_set_message(t('We contacted the Mollom servers to verify your keys: your keys do not exist or are no longer valid. Please visit the <em>Manage sites</em> page on the Mollom website again: <a href="@mollom-user">@mollom-user</a>.', array('@mollom-user' => 'http://mollom.com/user')), 'error');
+    }
+    return FALSE;
   }
   else {
-    drupal_set_message(t('We contacted the Mollom servers to verify your keys: the Mollom services are operating correctly. We are now blocking spam.'));
+    if ($show_message) {
+      drupal_set_message(t('We contacted the Mollom servers to verify your keys: the Mollom services are operating correctly. We are now blocking spam.'));
+    }
+    return TRUE;
   }
 }
 
@@ -1088,9 +1106,9 @@ function _mollom_retrieve_server_list() 
  * Call a remote procedure at the Mollom server.  This function
  * automatically adds the information required to authenticate against
  * Mollom.
- * 
+ *
  * TODO: currently this function's return value mixes actual values and
- * error values. We should rewrite the error handling so that calling 
+ * error values. We should rewrite the error handling so that calling
  * functions can properly handle error situations.
  */
 function mollom($method, $data = array()) {
@@ -1177,7 +1195,7 @@ function mollom($method, $data = array()
 
   // Report this error:
   watchdog('mollom', 'No Mollom servers could be reached or all servers returned an error -- the server list was emptied.', NULL, WATCHDOG_ERROR);
-  
+
   return NETWORK_ERROR;
 }
 
@@ -1235,3 +1253,93 @@ function _mollom_debug($message) {
   // print $message .'<br />';
   // error_log($message);
 }
+
+/**
+ * Implementation of hook_block().
+ */
+function mollom_block($op = 'list', $delta = 0, $edit = array()) {
+  if ($op == 'list') {
+    $blocks[0] = array(
+      'info' => t('Mollom statistics'),
+      'cache' => BLOCK_CACHE_GLOBAL,
+    );
+    return $blocks;
+  }
+  elseif ($op == 'view') {
+    $block = array(
+      'subject' => t('Mollom'),
+      'content' => theme('mollom_block_statistics', mollom_get_statistics()),
+    );
+    return $block;
+  }
+}
+
+/**
+ * Fetch the site's Mollom statistics.
+ *
+ * @param $refresh
+ *   A boolean if TRUE, will force the statistics to be re-fetched and stored
+ *   in the cache.
+ * @return
+ *   An array of statistics.
+ */
+function mollom_get_statistics($refresh = FALSE) {
+  $cache = cache_get('mollom_statistics');
+
+  // Do not re-fetch the data if it has been less than 5 minutes since the last
+  // fetch.
+  if ($cache && (!$refresh || time() - $cache->created < 300)) {
+    return $cache->data;
+  }
+  else {
+    if (_mollom_verify_key(FALSE)) {
+      $statistics = drupal_map_assoc(array(
+        'total_days',
+        'total_accepted',
+        'total_rejected',
+        'yesterday_accepted',
+        'yesterday_rejected',
+        'today_accepted',
+        'today_rejected',
+      ));
+
+      foreach ($statistics as $statistic) {
+        $result = mollom('mollom.getStatistics', array('type' => $statistic));
+        if ($result === NETWORK_ERROR || $result === MOLLOM_ERROR) {
+          $statistics = FALSE;
+          break;
+        }
+        else {
+          $statistics[$statistic] = $result;
+        }
+      }
+    }
+
+    cache_set('mollom_statistics', $statistics);
+    return $statistics;
+  }
+}
+
+/**
+ * Implementation of hook_cron().
+ */
+function mollom_cron() {
+  // Fetch fresh Mollom statistics and store in the cache.
+  mollom_get_statistics(TRUE);
+}
+
+/**
+ * Theme callback; statistics block.
+ */
+function theme_mollom_block_statistics($statistics) {
+  if ($statistics) {
+    $block = '<p>' . t('<a href="@link-mollom">Mollom</a> has blocked @today_rejected spam attempts today and @total_rejected spam attempts in the last @total_days.', array('@link-mollom' => url('http://mollom.com/', array('external' => TRUE)), '@today_rejected' => $statistics['today_rejected'], '@total_rejected' => $statistics['total_rejected'], '@total_days' => format_interval($statistics['total_days'] * 86400))) . '</p>';
+  }
+  else {
+    $block = '<p>' . t('Error contacting Mollom servers for statistics.') . '</p>';
+  }
+  $image = theme('image', drupal_get_path('module', 'mollom') . '/images/powered-by-mollom-1.gif', t('Powered by Mollom'), t('Powered by Mollom'));
+  $block .= '<p>' . l($image, 'http://mollom.com/', array('html' => TRUE, 'absolute' => TRUE, 'external' => TRUE)) . '</p>';
+  return $block;
+}
+
