Commit cddb1162 authored by Damien McKenna's avatar Damien McKenna
Browse files

Issue #1787068 by DamienMcKenna, Chris Maissan: Webform integration.

parent f91d19c6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ By DamienMcKenna: Added a CHANGELOG.txt file.
#2194633 by Growiel, DamienMcKenna: Update node revision when node updated.
#2108131 by Nitebreed, DamienMcKenna: antispam_prepare_comment_data requires an
  object, so antispam_api_cmd_spam_check must pass it an object.
#1787068 by DamienMcKenna, Chris Maissan: Webform integration.


AntiSpam 7.x-1.5, 2012-07-09
+9 −0
Original line number Diff line number Diff line
@@ -178,6 +178,15 @@ function antispam_settings_form() {
    '#default_value' => variable_get('antispam_email_enabled', 1),
    '#description' => t('Use this option to <em>enable</em> or <em>disable</em> e-mail notifications to content moderators. If enabled, users with proper permissions are allowed to set, from their user profiles, whether they wish to receive e-mail notications for all new (or updated) posts, just for content needing approval or no notifications at all. Users are notified about content types they are allowed to moderate only.')
  );
  // Optional integration with Webform.
  if (module_enabled('webform')) {
    $form['general']['antispam_webform_enabled'] = array(
      '#type' => 'checkbox',
      '#title' => 'Webform integration',
      '#default_value' => variable_get('antispam_webform_enabled', FALSE),
      '#description' => t('Optionally check all text values submitted as Webform fields.'),
    );
  }

  $form['node_options'] = array(
    '#type' => 'fieldset', '#title' => t('Node Options'),
+21 −0
Original line number Diff line number Diff line
@@ -730,6 +730,22 @@ function antispam_callback_set_spam_status($content_type, $object, $op) {
  }
}

/**
 * Webform: Check submitted values for spam.
 */
function antispam_webform_check($form, &$form_state) {
  if (variable_get('antispam_webform_enabled', FALSE)) {
    foreach ($form_state['values']['submitted'] as $value) {
      if (is_string($value) && !is_numeric($value) && strlen($value) > 5 && antispam_api_cmd_spam_check($value) === ANTISPAM_API_RESULT_IS_SPAM) {
        watchdog('spam detected', "Spam detected in webform value '%value'", array('%value' => $value), WATCHDOG_NOTICE);
        form_error($form_state['clicked_button'], t('Invalid input'));
        return;
      }
    }
  }
}


/*******************************************************************************
 * Node operations
 ******************************************************************************/
@@ -1518,6 +1534,11 @@ function _antispam_get_email_for_options() {
 * Implements hook_form_alter().
 */
function antispam_form_alter(&$form, &$form_state, $form_id) {
  // Add anti-spam integration to webforms.
  if (strpos($form_id, 'webform_client_form_') !== FALSE) {
    $form['#validate'][] = 'antispam_webform_check';
  }

  if (!($form_id == 'user_register_form' || $form_id == 'user_profile_form')) {
    return;
  }