Index: mollom.module =================================================================== RCS file: /cvs/drupal/contributions/modules/mollom/mollom.module,v retrieving revision 1.2.2.137 diff -u -r1.2.2.137 mollom.module --- mollom.module 24 Mar 2010 16:27:51 -0000 1.2.2.137 +++ mollom.module 20 May 2010 00:37:15 -0000 @@ -203,6 +203,8 @@ ); $items['admin/settings/mollom/manage/%mollom_form'] = array( 'title' => 'Configure', + 'title callback' => 'mollom_admin_configure_form_title', + 'title arguments' => array(4), 'page callback' => 'drupal_get_form', 'page arguments' => array('mollom_admin_configure_form', 4), 'access arguments' => array('administer mollom'), @@ -265,6 +267,13 @@ } /** + * Title callback for mollom form configration forms. + */ +function mollom_admin_configure_form_title($mollom_form) { + return t('Configure Mollom') . ': ' . $mollom_form['title']; +} + +/** * Access callback; check if the module is configured. * * This function does not actually check whether Mollom keys are valid for the @@ -725,6 +734,7 @@ 'bypass access' => array(), 'elements' => array(), 'mapping' => array(), + 'fallbacks' => array(), ); // Allow modules to alter the default form information. @@ -1273,12 +1283,25 @@ $data += array('session_id' => $form_state['mollom']['session_id']); } $result = mollom('mollom.checkContent', $data); - - // Trigger global fallback behavior if there is no result. + // Trigger fallback behavior if there is no result. + $mollom_form = $form['mollom']['#mollom_form']; if (!isset($result['session_id']) || !isset($result['spam'])) { + // Check for custom fallback configuration. + if (!empty($mollom_form['fallback'])) { + if (isset($mollom_form['fallbacks'][$mollom_form['fallback']])) { + if (isset($mollom_form['fallbacks'][$mollom_form['fallback']]['validate callback'])) { + $function = $mollom_form['fallbacks'][$mollom_form['fallback']]['validate callback']; + if (function_exists($function)) { + return $function($form, $form_state); + } + } + // No validate callback for this fallback. + return; + } + } + // Trigger global fallback behavior if custom behavior was not run. return _mollom_fallback(); } - // Assign the session ID returned by Mollom. $form_state['mollom']['session_id'] = $result['session_id']; // Store the response for #submit handlers. @@ -1438,15 +1461,31 @@ } /** - * Form submit handler to flush Mollom session and form information from cache. + * Form submit handler to run fallback logic and flush Mollom session and form + * information from cache. */ -function mollom_form_submit($form_id, &$form_state) { +function mollom_form_submit($form, &$form_state) { // Some modules are implementing multi-step forms without separate form // submit handlers. In case we reach here and the form will be rebuilt, we // need to defer our submit handling until final submission. if (!empty($form_state['rebuild'])) { return; } + // If no Mollom session_id was generated, then check if fallback logic needs + // to be run. + if (!isset($form_state['mollom']['session_id']) || empty($form_state['mollom']['session_id'])) { + $mollom_form = $form['mollom']['#mollom_form']; + if (!empty($mollom_form['fallback'])) { + if (isset($mollom_form['fallbacks'][$mollom_form['fallback']])) { + if (isset($mollom_form['fallbacks'][$mollom_form['fallback']]['submit callback'])) { + $function = $mollom_form['fallbacks'][$mollom_form['fallback']]['submit callback']; + if (function_exists($function)) { + $function($form, $form_state); + } + } + } + } + } // If an 'entity' and a 'post_id' mapping was provided via // hook_mollom_form_info(), try to automatically store Mollom session data. if (!empty($form_state['mollom']['entity']) && isset($form_state['mollom']['mapping']['post_id'])) { @@ -1879,6 +1918,12 @@ 'author_mail' => 'mail', 'author_url' => 'homepage', ), + 'fallbacks' => array( + 'moderation' => array( + 'title' => t('Post comments to the moderation queue.'), + 'validate callback' => 'comment_mollom_fallback_moderation_validate', + ), + ), ); return $form_info; @@ -1933,7 +1978,7 @@ /** * Implements hook_comment(). */ -function mollom_comment($comment, $op) { +function mollom_comment(&$comment, $op) { if ($op == 'insert') { mollom_data_save('comment', $comment['cid']); } @@ -1975,6 +2020,13 @@ } /** + * Validate callback for moderation fallback. + */ +function comment_mollom_fallback_moderation_validate($form, &$form_state) { + $form_state['values']['status'] = COMMENT_NOT_PUBLISHED; +} + +/** * @} End of "name mollom_comment". */ Index: mollom.install =================================================================== RCS file: /cvs/drupal/contributions/modules/mollom/mollom.install,v retrieving revision 1.2.2.28 diff -u -r1.2.2.28 mollom.install --- mollom.install 30 Mar 2010 14:53:03 -0000 1.2.2.28 +++ mollom.install 20 May 2010 00:37:15 -0000 @@ -123,6 +123,13 @@ 'type' => 'text', 'serialize' => TRUE, ), + 'fallback' => array( + 'description' => 'The configured fallback strategy for the form.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), 'module' => array( 'description' => 'The module name the $form_id belongs to.', 'type' => 'varchar', @@ -382,3 +389,19 @@ } return $ret; } + +/** + * Add the {mollom_form}.fallback column. + */ +function mollom_update_6113() { + $ret = array(); + // Add the 'entity' column. + db_add_field($ret, 'mollom_form', 'fallback', array( + 'description' => 'The configured fallback strategy for the form.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + )); + return $ret; +} Index: mollom.api.php =================================================================== RCS file: /cvs/drupal/contributions/modules/mollom/mollom.api.php,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 mollom.api.php --- mollom.api.php 6 Mar 2010 21:37:59 -0000 1.1.2.2 +++ mollom.api.php 20 May 2010 00:37:14 -0000 @@ -109,6 +109,15 @@ * 'author_id', if no explicit form element value mapping was specified. * - author_ip: Mollom automatically assigns the user's IP address if no * explicit form element value mapping was specified. + * - fallbacks: (optional) An associative array of custom fallbacks. + * Fallbacks allow a form to offer special handling when the Mollom + * servers are unreachable, or otherwise cannot respond. + * Each fallback should contain the following information: + * - title: The title of the fallback option. + * - validate callback: (optional) A function that will be called during + * the form validation. + * - submit callback: (optional) A function that will be called during the + * form's submit process. */ function hook_mollom_form_info($form_id) { switch ($form_id) { @@ -130,6 +139,13 @@ 'author_mail' => 'mail', 'author_url' => 'homepage', ), + 'fallbacks' => array( + 'moderate' => array( + 'title' => t('Post comments to the moderation queue.'), + 'validate callback' => 'mymodule_comment_fallback_validate', + 'submit callback' => 'mymodule_comment_fallback_submit', + ), + ), ); return $form_info; Index: mollom.admin.inc =================================================================== RCS file: /cvs/drupal/contributions/modules/mollom/mollom.admin.inc,v retrieving revision 1.1.2.26 diff -u -r1.1.2.26 mollom.admin.inc --- mollom.admin.inc 12 Mar 2010 03:07:44 -0000 1.1.2.26 +++ mollom.admin.inc 20 May 2010 00:37:14 -0000 @@ -126,8 +126,7 @@ '#value' => $mollom_form['form_id'], ); $form['mollom']['form_title'] = array( - '#type' => 'item', - '#title' => t('Form'), + '#type' => 'value', '#value' => $mollom_form['title'], ); // Form elements defined by hook_mollom_form_info() use the @@ -151,15 +150,48 @@ $enabled_fields[] = rawurlencode($value); } $form['mollom']['enabled_fields'] = array( - '#type' => 'checkboxes', + '#type' => 'fieldset', '#title' => t('Fields to analyze'), + '#description' => t('If no fields are selected, the form will be protected by a CAPTCHA.'), + ); + $form['mollom']['enabled_fields']['enabled_fields'] = array( + '#type' => 'checkboxes', '#options' => $elements, '#default_value' => $enabled_fields, - '#description' => t('If no fields are selected, the form will be protected by a CAPTCHA.'), + '#parents' => array('mollom', 'enabled_fields'), ); - if (empty($form['mollom']['enabled_fields']['#options'])) { + if (empty($form['mollom']['enabled_fields']['enabled_fields']['#options'])) { $form['mollom']['enabled_fields']['#description'] = t('No fields are available.'); } + + // Display fallback options. + $default_fallback = variable_get('mollom_fallback', MOLLOM_FALLBACK_BLOCK); + $block_suffix = ($default_fallback == MOLLOM_FALLBACK_BLOCK) ? ' ' . t('(Site Default)') . '' : ''; + $accept_suffix = ($default_fallback == MOLLOM_FALLBACK_ACCEPT) ? ' ' . t('(Site Default)') . '' : ''; + $fallback_options = array( + '' => t('Site default'), + MOLLOM_FALLBACK_BLOCK => t('Block all submissions of protected forms until the server problems are resolved') . $block_suffix, + MOLLOM_FALLBACK_ACCEPT => t('Leave all forms unprotected and accept all submissions') . $accept_suffix, + ); + foreach ($mollom_form['fallbacks'] as $key => $fallback) { + $fallback_options[$key] = $fallback['title']; + } + $form['mollom']['fallback'] = array( + '#type' => 'fieldset', + '#title' => t('Fallback strategy'), + '#description' => t('When the Mollom servers are down or otherwise unreachable, no text analysis is performed and no CAPTCHAs are generated. If this occurs, your site will use the configured fallback strategy. Subscribers to Mollom Plus receive access to Mollom\'s high-availability backend infrastructure, not available to free users, reducing potential downtime.', array( + '@pricing-url' => 'http://mollom.com/pricing', + '@sla-url' => 'http://mollom.com/standard-service-level-agreement', + )), + ); + $form['mollom']['fallback']['fallback'] = array( + '#type' => 'radios', + '#options' => $fallback_options, + '#default_value' => $mollom_form['fallback'] ? $mollom_form['fallback'] : '', + '#parents' => array('mollom', 'fallback'), + ); + + $form['actions']['submit'] = array( '#type' => 'submit', '#value' => t('Save'), @@ -215,7 +247,6 @@ // Determine form protection to use; use CAPTCHA-only protection if no fields // were selected, otherwise text analysis. $mollom_form['mode'] = (!empty($mollom_form['enabled_fields']) ? MOLLOM_MODE_ANALYSIS : MOLLOM_MODE_CAPTCHA); - $status = mollom_form_save($mollom_form); if ($status === SAVED_NEW) { drupal_set_message('The form protection has been added.'); @@ -437,7 +468,7 @@ $form['server'] = array( '#type' => 'fieldset', - '#title' => t('Fallback strategy'), + '#title' => t('Default fallback strategy'), '#description' => t('When the Mollom servers are down or otherwise unreachable, no text analysis is performed and no CAPTCHAs are generated. If this occurs, your site will use the configured fallback strategy. Subscribers to Mollom Plus receive access to Mollom\'s high-availability backend infrastructure, not available to free users, reducing potential downtime.', array( '@pricing-url' => 'http://mollom.com/pricing', '@sla-url' => 'http://mollom.com/standard-service-level-agreement',