foo_captcha.module in CAPTCHA Pack 5
File
foo_captcha/foo_captcha.module
View source
<?php
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>';
}
}
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 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);
}
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;
}
}