You are here

function _antispam_settings_form in AntiSpam 6

Build the antispam settings form.

1 call to _antispam_settings_form()
antispam_settings in ./antispam.admin.inc
Implementation of hook_settings().

File

./antispam.admin.inc, line 18

Code

function _antispam_settings_form() {
  $form = array();
  $enable_options = array(
    '1' => t('Enabled'),
    '0' => t('Disabled'),
  );
  $antispam_wpapikey = variable_get('antispam_wpapikey', '');
  $antispam_tpapikey = variable_get('antispam_tpapikey', '');
  $antispam_deapikey = variable_get('antispam_deapikey', '');
  $service_provider = antispam_get_service_provider();

  // Validate the current API key.
  $apikey = antispam_get_api_key($service_provider);
  if (empty($apikey)) {
    $is_valid = TRUE;
  }
  else {
    $is_valid = antispam_api_cmd_verify_key($apikey) == ANTISPAM_API_RESULT_SUCCESS ? TRUE : FALSE;
  }

  // Provide the AntiSpam administration JavaScript.
  drupal_add_js(drupal_get_path('module', 'antispam') . '/antispam.js');
  $service_fieldset_collapsed = FALSE;

  // always show
  $form['service'] = array(
    '#type' => 'fieldset',
    '#title' => t('AntiSpam Service Options'),
    '#collapsible' => TRUE,
    '#collapsed' => $service_fieldset_collapsed,
  );
  $form['service']['antispam_service_provider'] = array(
    '#type' => 'radios',
    '#title' => t('Service Provider'),
    '#options' => array(
      t('Akismet'),
      t('TypePad AntiSpam'),
      t('Defensio'),
    ),
    '#default_value' => $service_provider,
    '#description' => t('Please select the anti spam service provider. Although they provide the similar services, TypePad AntiSpam service is free even for commercial sites while Akismet and Defensio have some limitations on the commercial usage.'),
  );
  $form['service']['antispam_wpapikey'] = array(
    '#type' => 'textfield',
    '#title' => t('WordPress.com API key'),
    '#size' => 30,
    '#maxlength' => 60,
    '#default_value' => $antispam_wpapikey,
    '#description' => t('Please, enter here your <a href="!wpapikey">WordPress.com API key</a>. If you don\'t have one already, you can get it by simply signing up for a free account at <a href="!wordpress-com">WordPress.com</a>. Note that this information is required in order to use the <a href="!akismet">Akismet Service</a>. Please, consult the <a href="!akismet-faq">Akismet FAQ</a> for further information.', array(
      '!wpapikey' => url('http://wordpress.com/api-keys/'),
      '!wordpress-com' => url('http://wordpress.com'),
      '!akismet' => url('http://akismet.com'),
      '!akismet-faq' => url('http://akismet.com/faq/'),
    )),
    '#prefix' => '<div id="antispam-wrapper-0" class="antispam-wrapper">',
    '#suffix' => '</div>',
  );
  $form['service']['antispam_tpapikey'] = array(
    '#type' => 'textfield',
    '#title' => t('TypePad AntiSpam API key'),
    '#size' => 50,
    '#maxlength' => 90,
    '#default_value' => $antispam_tpapikey,
    '#description' => t('Please, enter here your <a href="!tpapikey">TypePad.com AntiSpam API key</a>. If you don\'t have one already, you can get it by simply signing up for a free account at <a href="!typepad-com">Typepad.com</a>. Once you get a free acount, visit the <a href="!tpapikey">TypePad AntiSpam Service</a> and get your free TypePad AntiSpam API Key there. Please, consult the <a href="!antispam-faq">TypePad AntiSpam FAQ</a> for further information.', array(
      '!tpapikey' => url('http://antispam.typepad.com/info/get-api-key.html'),
      '!typepad-com' => url('http://typepad.com/connect/register'),
      '!antispam-faq' => url('http://antispam.typepad.com/info/faq.html'),
    )),
    '#prefix' => '<div id="antispam-wrapper-1" class="antispam-wrapper">',
    '#suffix' => '</div>',
  );
  $form['service']['antispam_deapikey'] = array(
    '#type' => 'textfield',
    '#title' => t('Defensio API key'),
    '#size' => 50,
    '#maxlength' => 90,
    '#default_value' => $antispam_deapikey,
    '#description' => t('Please, enter here your <a href="!defensio-com">Defensio API key</a>. If you don\'t have one already, you can get it by simply signing up for a free account at <a href="!defensio-key">Defensio.com</a>. Then you will get your API key to use <a href="!defensio-com">Defensio</a> antispam service. Please, consult the <a href="!antispam-faq">Defensio FAQ</a> for further information.', array(
      '!defensio-com' => url('http://defensio.com/'),
      '!defensio-key' => url('http://defensio.com/signup/'),
      '!antispam-faq' => url('http://defensio.com/faq'),
    )),
    '#prefix' => '<div id="antispam-wrapper-2" class="antispam-wrapper">',
    '#suffix' => '</div>',
  );

  // Give a warning if the active key is not valid.
  if (!empty($apikey) && !$is_valid) {
    switch ($service_provider) {
      case 0:
        $apikeyname = 'antispam_wpapikey';
        break;
      case 1:
        $apikeyname = 'antispam_tpapikey';
        break;
      case 2:
        $apikeyname = 'antispam_deapikey';
        break;
    }
    $form['service'][$apikeyname]['#description'] .= '<div class="marker">' . t('<strong>WARNING: Your API Key doesn\'t seem to be valid!</strong>') . '</div>';
  }
  $form['service']['antispam_connection_enabled'] = array(
    '#type' => 'radios',
    '#title' => t('Service provider connections'),
    '#options' => $enable_options,
    '#default_value' => variable_get('antispam_connection_enabled', 1),
    '#description' => t('<strong>This option must be enabled in order to perform real requests to the specified antispam service provider.</strong> You may want to disable this option for testing purposes, however. In this case, the <em>antispam module</em> will operate as normal, except sending real requests to the service provider. ie. no automatic spam detection will be performed and no remote requests will be made when content is manually <em>marked</em>/<em>unmarked</em> as spam.<br />Note: regardless of this option, the <em>antispam module</em> will still connect, from this panel, to validate your API key, if specified.'),
  );
  $timeout_options = array();
  for ($n = 1; $n <= 30; $n++) {
    $timeout_options[$n] = $n;
  }
  $form['service']['antispam_connection_timeout'] = array(
    '#type' => 'select',
    '#title' => t('Connection timeout'),
    '#default_value' => variable_get('antispam_connection_timeout', 10),
    '#options' => $timeout_options,
    '#description' => t('This option allows you to specify the connection timeout in seconds that is used for real time antispam service connections.'),
  );
  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General Options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $age_options = drupal_map_assoc(array(
    0,
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
    172800,
    259200,
    604800,
    1209600,
    1814400,
  ), 'format_interval');
  $age_options[0] = t('never');
  $age_options[2592000] = t('1 month');
  $age_options[5184000] = t('2 months');
  $age_options[7776000] = t('3 months');
  $age_options[10368000] = t('4 months');
  $age_options[15768000] = t('6 months');
  $age_options[31536000] = t('1 year');
  $form['general']['antispam_remove_spam_age'] = array(
    '#type' => 'select',
    '#title' => t('Remove spam older than'),
    '#default_value' => variable_get('antispam_remove_spam_age', 259200),
    '#options' => $age_options,
    '#description' => t('Content marked as <em>spam</em> is still saved into database so it can be reviewed by content administrators. This option allows you to specify how long this information will be kept in the database. <em>Spam</em> older than the age specified here will be automatically removed. Requires crontab.'),
  );
  $form['general']['antispam_records_per_page'] = array(
    '#type' => 'select',
    '#title' => t('Records per page'),
    '#default_value' => variable_get('antispam_records_per_page', 50),
    '#options' => drupal_map_assoc(array(
      10,
      20,
      30,
      40,
      50,
      60,
      70,
      80,
      90,
      100,
      200,
    )),
    '#description' => t('The maximum number of records per page on moderation queue.'),
  );
  $form['general']['antispam_blocks_counter'] = array(
    '#type' => 'select',
    '#title' => t('Number of blocks'),
    '#default_value' => variable_get('antispam_blocks_counter', 1),
    '#options' => array(
      0 => t('none'),
      1 => 1,
      2 => 2,
      3 => 3,
      4 => 4,
      5 => 5,
    ),
    '#description' => t('The antispam module may generate a number of blocks for you to display the current spam counter anywhere on your site. The number of blocks is variable to help you keep your <a href="!admin-block">blocks administration panel</a> as clean as possible. This option allows you to specify how many blocks you wish to use. If you do not plan to show the spam counter to your visitors, set this option to <em>none</em>.', array(
      '!admin-block' => url('admin/block'),
    )),
  );
  $form['general']['antispam_email_enabled'] = array(
    '#type' => 'radios',
    '#title' => t('E-mail notifications'),
    '#options' => $enable_options,
    '#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.'),
  );
  $form['node_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Node Options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['node_options']['antispam_check_nodetypes'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Check for spam in these node types'),
    '#options' => node_get_types('names'),
    '#default_value' => variable_get('antispam_check_nodetypes', array()),
    '#description' => t('Use this option to <em>enable</em> or <em>disable</em> spam check for nodes of types specified here. When this option is enabled, a request will be sent to the selected antispam service, in real time. If the service was down, nodes would simply be queued for manual moderation. Users with <a href="!admin-access">@admin-nodes</a> permission and <a href="!admin-access">spam moderators</a> are exempt from this check.', array(
      '@admin-nodes' => t('administer nodes'),
      '!admin-access' => url('admin/access'),
    )),
  );
  $form['node_options']['antispam_node_publish_links'] = array(
    '#type' => 'radios',
    '#title' => t('Show publish/unpublish links'),
    '#options' => $enable_options,
    '#default_value' => variable_get('antispam_node_publish_links', 0),
    '#description' => t('Use this option to <em>enable</em> or <em>disable</em> links for <em>publish</em>/<em>unpublish</em> operations in nodes. If enabled, these links will only be displayed to <a href="!admin-access">spam moderators</a> and users with <a href="!admin-access">@admin-nodes</a> permission.', array(
      '@admin-nodes' => t('administer nodes'),
      '!admin-access' => url('admin/access'),
    )),
  );
  $form['node_options']['antispam_node_spam_links'] = array(
    '#type' => 'radios',
    '#title' => t('Show submit spam/ham links'),
    '#options' => $enable_options,
    '#default_value' => variable_get('antispam_node_spam_links', 0),
    '#description' => t('Use this option to <em>enable</em> or <em>disable</em> links for <em>submit spam</em>/<em>ham</em> operations in nodes. If enabled, these links will only be displayed to <a href="!admin-access">spam moderators</a> and users with <a href="!admin-access">@admin-nodes</a> permission.', array(
      '@admin-nodes' => t('administer nodes'),
      '!admin-access' => url('admin/access'),
    )) . '<br />' . t('<strong>Note:</strong> To interact fully with the antispam service, you really should try putting data back into the system as well as just taking it out. If it is at all possible, please use these links to submit missed spam and false positives (ham), otherwise antispam service will never learn from its mistakes. Thank you.'),
  );
  if (module_exists('comment')) {
    $form['comment_options'] = array(
      '#type' => 'fieldset',
      '#title' => t('Comment Options'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['comment_options']['antispam_check_comments'] = array(
      '#type' => 'radios',
      '#title' => t('Check for spam in comments'),
      '#options' => $enable_options,
      '#default_value' => variable_get('antispam_check_comments', 1),
      '#description' => t('Use this option to <em>enable</em> or <em>disable</em> spam check for comments. When this option is enabled, a request will be sent to the selected antispam service, in real time. If the antispam service was down, comments would simply be queued for manual moderation. Users with <a href="!admin-access">@admin-comments</a> permission and <a href="!admin-access">spam moderators</a> are exempt from this check.', array(
        '@admin-comments' => t('administer comments'),
        '!admin-access' => url('admin/access'),
      )),
    );
    $form['comment_options']['antispam_comment_publish_links'] = array(
      '#type' => 'radios',
      '#title' => t('Show publish/unpublish links'),
      '#options' => $enable_options,
      '#default_value' => variable_get('antispam_comment_publish_links', 1),
      '#description' => t('Use this option to <em>enable</em> or <em>disable</em> links for <em>publish</em>/<em>unpublish</em> operations in comments. If enabled, these links will only be displayed to <a href="!admin-access">spam moderators</a> and users with <a href="!admin-access">@admin-comments</a> permission.', array(
        '@admin-comments' => t('administer comments'),
        '!admin-access' => url('admin/access'),
      )),
    );
    $form['comment_options']['antispam_comment_spam_links'] = array(
      '#type' => 'radios',
      '#title' => t('Show submit spam/ham links'),
      '#options' => $enable_options,
      '#default_value' => variable_get('antispam_comment_spam_links', 1),
      '#description' => t('Use this option to <em>enable</em> or <em>disable</em> links for <em>submit spam</em>/<em>ham</em> operations in comments. If enabled, these links will only be displayed to <a href="!admin-access">spam moderators</a> and users with <a href="!admin-access">@admin-comments</a> permission.', array(
        '@admin-comments' => t('administer comments'),
        '!admin-access' => url('admin/access'),
      )) . '<br />' . t('<strong>Note:</strong> To interact fully with the selected antispam service, you really should try putting data back into the system as well as just taking it out. If it is at all possible, please use these links to submit missed spam and false positives (ham), otherwise the antispam service will never learn from its mistakes. Thank you.'),
    );
  }
  $date_formats = array(
    'F j, Y',
    'j F, Y',
    'Y, F j',
    'M j, Y',
    'j M, Y',
    'Y, M j',
    'Y/m/d',
    'm/d/Y',
    'd/m/Y',
    'Y-m-d',
    'm-d-Y',
    'd-m-Y',
  );
  $date_options = array();
  $now = time();
  foreach ($date_formats as $format) {
    $date_options[$format] = format_date($now, 'custom', $format);
  }
  $form['counter_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Spam Counter Options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['counter_options']['antispam_counter_since'] = array(
    '#type' => 'date',
    '#title' => t('Counting since'),
    '#default_value' => variable_get('antispam_counter_since', array(
      'day' => date('j'),
      'month' => date('n'),
      'year' => date('Y'),
    )),
    '#description' => t('This is the date that will tell your visitors when your spam counter started to increment.'),
  );
  $form['counter_options']['antispam_counter_date_format'] = array(
    '#type' => 'select',
    '#title' => t('Date format'),
    '#default_value' => variable_get('antispam_counter_date_format', $date_formats[0]),
    '#options' => $date_options,
    '#description' => t('Date format used to render the <em>Counting since</em> date.'),
  );
  $form['statistics_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Statistics Chart Options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['statistics_options']['antispam_chart_width'] = array(
    '#type' => 'select',
    '#title' => t('Chart width'),
    '#default_value' => variable_get('antispam_chart_width', 480),
    '#options' => drupal_map_assoc(array(
      320,
      400,
      480,
      540,
      600,
    )),
    '#description' => t('This is the width of charts in the statictics page. Use the width that matches to the width of the admin page of your site. The height of charts are automatically determined based on the width.'),
  );
  $form['anti_spambot'] = array(
    '#type' => 'fieldset',
    '#title' => t('Anti-Spambot Options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('The goal of this section is not to replace anything that the antispam service itself can do a lot better than us, but to provide a set of simple rules aimed to prevent Denial of Service (DoS) situations that could be caused by certain spambots.'),
  );
  $delay_options = drupal_map_assoc(array(
    0,
    30,
    60,
    90,
    120,
    150,
    180,
  ), 'format_interval');
  $delay_options[0] = t('none');
  $form['anti_spambot']['antispam_antispambot_delay'] = array(
    '#type' => 'select',
    '#title' => t('Delay when spam is detected'),
    '#default_value' => variable_get('antispam_antispambot_delay', 60),
    '#options' => $delay_options,
    '#description' => t('Use this option to delay the response when content has been identified as spam or to requests that match the rules defined below.'),
  );
  $anti_spambot_rules = array(
    'ip' => t('IP addresses used by known spammers.'),
    'mail' => t('E-mail addresses used by known spammers.'),
    'body' => t('Content that has already been identified as spam.'),
  );
  $form['anti_spambot']['antispam_antispambot_rules'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Identify spambots by'),
    '#options' => $anti_spambot_rules,
    '#default_value' => variable_get('antispam_antispambot_rules', array()),
    '#description' => t('These rules will be applied before sending any request to the antispam service. If a request to send content matches any of these rules, the actions defined below will be triggered. Requests to send content are checked against spam that is stored locally (visible from the <a href="!moderation-queue">moderation queue</a>).', array(
      '!moderation-queue' => url('admin/content/antispam'),
    )),
  );
  $anti_spambot_actions = array(
    'none' => t('None (only the delay specified above, if any).'),
    '503' => t('HTTP error 503 (Service Unavailable), showing a simple blank page.'),
    '403' => t('HTTP error 403 (Forbidden), showing a simple blank page.'),
    '403d' => t('HTTP error 403 (Forbidden), showing a Drupal generated page.'),
  );
  $form['anti_spambot']['antispam_antispambot_action'] = array(
    '#type' => 'radios',
    '#title' => t('Actions against spambots'),
    '#options' => $anti_spambot_actions,
    '#default_value' => variable_get('antispam_antispambot_action', '503'),
    '#description' => t('Use this option to specify what to do against spambots identified by any of the above rules. When a <em>HTTP error</em> is generated (403 or 503), no request to the antispam service will be made, the request to post content will not be stored into database and no further moderator notifications will be sent. In any case, when a rule matches, a record of the event will be <a href="!admin-reports">logged</a> for further analysis.', array(
      '!admin-reports' => url('admin/reports'),
    )),
  );
  return system_settings_form($form);
}