View source
<?php
require_once drupal_get_path('module', 'phrase_captcha') . '/../text_captcha.inc';
define('PHRASE_CAPTCHA_GENERATE_NONSENSE_WORDS', 0);
define('PHRASE_CAPTCHA_USER_DEFINED_WORDS', 1);
function phrase_captcha_help($path, $arg) {
switch ($path) {
case 'admin/user/captcha/phrase_captcha':
return '<p>' . t('This phrase based CAPTCHA presents a CAPTCHA phrase of a given number of words and asks to pick the right word (based on counting, alphabetical order, etc).') . '</p>';
}
}
function phrase_captcha_menu() {
$items = array();
$items['admin/user/captcha/phrase_captcha'] = array(
'title' => 'Phrase CAPTCHA',
'file' => 'phrase_captcha.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'phrase_captcha_settings_form',
),
'access arguments' => array(
'administer CAPTCHA settings',
),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function phrase_captcha_captcha($op, $captcha_type = '') {
switch ($op) {
case 'list':
return array(
'Phrase CAPTCHA',
);
case 'generate':
if ($captcha_type == 'Phrase CAPTCHA') {
require_once 'phrase_captcha.inc';
$words = _phrase_captcha_generate_words((int) variable_get('phrase_captcha_word_quantity', 5));
$word_challenges = _phrase_captcha_enabled_word_challenges();
$key = array_rand($word_challenges);
$function = $word_challenges[$key];
list($phrase_words, $question, $solution) = call_user_func($function, $words);
$all_words = array_merge($words, _phrase_captcha_generate_words((int) variable_get('phrase_captcha_additional_word_quantity', 1)));
shuffle($all_words);
$options = array();
foreach ($all_words as $word) {
$options[$word] = $word;
}
$captcha = array();
$captcha['solution'] = $solution;
$captcha['form']['captcha_phrase'] = array(
'#type' => 'markup',
'#value' => '"' . implode(' ', $phrase_words) . '"',
'#weight' => -2,
);
$captcha['form']['captcha_response'] = array(
'#type' => 'radios',
'#title' => $question,
'#options' => $options,
'#attributes' => array(
'class' => 'text-captcha-word-list-radios',
),
'#DANGEROUS_SKIP_CHECK' => TRUE,
'#required' => TRUE,
);
drupal_add_css(drupal_get_path('module', 'phrase_captcha') . '/../text_captcha.css');
return $captcha;
}
}
}