Skip to content
foo_captcha.module 1.52 KiB
Newer Older
soxofaan's avatar
soxofaan committed
<?php

/**
 * Implements hook_help().
soxofaan's avatar
soxofaan committed
 */
soxofaan's avatar
soxofaan committed
function foo_captcha_help($path, $arg) {
  switch ($path) {
    case 'admin/config/people/captcha/foo_captcha':
      return '<p>' . t('This is a very simple CAPTCHA, which requires users to enter "foo" in a textfield.') . '</p>';
 * Implements hook_menu().
soxofaan's avatar
soxofaan committed
 */
soxofaan's avatar
soxofaan committed
function foo_captcha_menu() {
soxofaan's avatar
soxofaan committed
  $items = array();
  $items['admin/config/people/captcha/foo_captcha'] = array(
soxofaan's avatar
soxofaan committed
    'title' => 'Foo CAPTCHA',
soxofaan's avatar
soxofaan committed
    'page callback' => 'drupal_get_form',
    'page arguments' => array('foo_captcha_settings_form'),
    'access arguments' => array('administer CAPTCHA settings'),
    'file' => 'foo_captcha.admin.inc',
soxofaan's avatar
soxofaan committed
    'type' => MENU_LOCAL_TASK,
  );
soxofaan's avatar
soxofaan committed
  return $items;
}

/**
 * Implements hook_captcha().
soxofaan's avatar
soxofaan committed
 */
function foo_captcha_captcha($op, $captcha_type = '') {
soxofaan's avatar
soxofaan committed
    case 'list':
soxofaan's avatar
soxofaan committed
    case 'generate':
      if ($captcha_type == 'Foo CAPTCHA') {
soxofaan's avatar
soxofaan committed
        $captcha = array();
        $captcha['solution'] = 'foo';
        $captcha['form']['captcha_response'] = array(
soxofaan's avatar
soxofaan committed
          '#type' => 'textfield',
          '#title' => t('Enter "foo"'),
          '#required' => TRUE,
          '#process' => array('foo_captcha_process'),
soxofaan's avatar
soxofaan committed
        );
        return $captcha;
      }
      break;
  }
}

/**
 * Process the response to the foo CAPTCHA before validation.
 */
function foo_captcha_process($element, $edit) {
  if (variable_get('foo_captcha_ignore_spaces', FALSE)) {
    $element['#value'] = preg_replace('/\s*/', '', $element['#value']);
  }
  return $element;
}