View source
<?php
define('TEXT_CAPTCHA_GENERATE_NONSENSE_WORDS', 0);
define('TEXT_CAPTCHA_USER_DEFINED_WORDS', 1);
define('TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM', 20);
function text_captcha_help($path, $arg) {
switch ($path) {
case 'admin/user/captcha/text_captcha':
return '<p>' . t('In this challenge the visitor is asked for the n<sup>th</sup> word of a given phrase.') . '</p>';
}
}
function text_captcha_menu() {
$items['admin/user/captcha/text_captcha'] = array(
'title' => 'Text CAPTCHA',
'file' => 'text_captcha.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'text_captcha_settings_form',
),
'access arguments' => array(
'administer CAPTCHA settings',
),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function text_captcha_captcha($op, $captcha_type = '') {
switch ($op) {
case 'list':
return array(
'Text',
);
case 'generate':
require_once drupal_get_path('module', 'text_captcha') . '/text_captcha.user.inc';
if ($captcha_type == 'Text') {
$words = _text_captcha_generate_words((int) variable_get('text_captcha_word_quantity', 5));
$key = array_rand($words, 1);
$answer = $words[$key];
$result = array();
$result['solution'] = $answer;
$result['form']['captcha_response'] = array(
'#type' => 'textfield',
'#title' => t('What is the @nth word in the phrase "@words"?', array(
'@nth' => _text_captcha_ordinal($key + 1),
'@words' => implode(' ', $words),
)),
'#weight' => 0,
'#size' => 15,
'#required' => TRUE,
);
return $result;
}
}
}