You are here

foo_captcha.module in CAPTCHA Pack 5

File

foo_captcha/foo_captcha.module
View source
<?php

/**
 * Implementation of hook_help().
 */
function foo_captcha_help($section) {
  switch ($section) {
    case 'admin/user/captcha/foo_captcha':
      return '<p>' . t('This is a very simple CAPTCHA, which requires users to enter "foo" in a textfield.') . '</p>';
  }
}

/**
 * Implementation of hook_menu().
 */
function foo_captcha_menu($may_cache) {
  $items = array();
  if ($may_cache) {
    $items[] = array(
      'path' => 'admin/user/captcha/foo_captcha',
      'title' => t('Foo CAPTCHA'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array(
        'foo_captcha_settings_form',
      ),
      'type' => MENU_LOCAL_TASK,
    );
  }
  return $items;
}

/**
 * Function for the settings form
 */
function foo_captcha_settings_form() {
  $form = array();
  $form['foo_captcha_case_insensitive'] = array(
    '#type' => 'checkbox',
    '#title' => t('Case insensitive validation'),
    '#default_value' => variable_get('foo_captcha_case_insensitive', TRUE),
  );
  return system_settings_form($form);
}

/**
 * Implementation of hook_captcha().
 */
function foo_captcha_captcha($op, $captcha_type = '', $response = '') {
  switch ($op) {
    case 'list':
      return array(
        'Foo CAPTCHA',
      );
      break;
    case 'generate':
      if ($captcha_type == 'Foo CAPTCHA') {
        $captcha = array();
        $captcha['solution'] = 'foo';
        $captcha['form']['captcha_response'] = array(
          '#type' => 'textfield',
          '#title' => t('Enter "foo"'),
          '#required' => TRUE,
        );
        $captcha['preprocess'] = TRUE;
        return $captcha;
      }
      break;
    case 'preprocess':
      if ($captcha_type == 'Foo CAPTCHA') {
        if (variable_get('foo_captcha_case_insensitive', TRUE)) {
          $response = strtolower($response);
        }
        return $response;
      }
      break;
  }
}

Functions

Namesort descending Description
foo_captcha_captcha Implementation of hook_captcha().
foo_captcha_help Implementation of hook_help().
foo_captcha_menu Implementation of hook_menu().
foo_captcha_settings_form Function for the settings form