'. t('The challenge in this CAPTCHA is to determine the lost character(s) of a given word.') .'

'; } } /** * Implementation of hook_menu(). */ function lost_character_captcha_menu() { $items = array(); $items['admin/user/captcha/lost_character_captcha'] = array( 'title' => 'Lost characters', 'file' => 'lost_character_captcha.admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('lost_character_captcha_settings_form'), 'access arguments' => array('administer CAPTCHA settings'), 'type' => MENU_LOCAL_TASK, ); return $items; } /** * Implementation of hook_captcha(). */ function lost_character_captcha_captcha($op, $captcha_type='') { switch ($op) { case 'list': return array("Lost characters"); case 'generate': if ($captcha_type == "Lost characters") { // get the word pool $words = _text_captcha_word_pool_get_content('lost_character_captcha_word_pool', NULL, LOST_CHARACTER_CAPTCHA_DEFAULT_WORD_POOL, TRUE); // pick a random word $word = $words[array_rand($words)]; // split in characters $characters = _text_captcha_utf8_split($word); // lose characters $lost = array(); $lose_quantity = variable_get('lost_character_captcha_quantity', 1); for ($i=0; $i<$lose_quantity; $i++) { // pick a random character $n = array_rand($characters); while ($characters[$n] == LOST_CHARACTER_CAPTCHA_HINTER) { $n = array_rand($characters); } // save it for building the solution $lost[] = $characters[$n]; // and lose it in the given word if (variable_get('lost_character_captcha_enable_hint', TRUE)) { $characters[$n] = LOST_CHARACTER_CAPTCHA_HINTER; } else { unset($characters[$n]); } } // build the CAPTCHA sort($lost); $given_word = implode('', $characters); $solution = implode('', $lost); if ($lose_quantity == 1) { $title = t('Enter the missing character from the following word'); } else { $title = t('Enter the @num missing characters from the following word', array('@num' => $lose_quantity)); } // $captcha = array(); $captcha['solution'] = $solution; $captcha['form']['captcha_response'] = array( '#type' => 'textfield', '#title' => $title, '#field_prefix' => "$given_word: ", '#size' => 3, '#maxlength' => 3, '#required' => TRUE, '#process' => array('lost_character_process'), ); return $captcha; } break; } } /** * Process the response before validation. */ function lost_character_process($element, $edit, &$form_state, $complete_form) { $response = $element['#value']; // remove white spaces $parts = _text_captcha_whitespace_explode($response); $response = implode('', $parts); // split in utf8 characters, sort and rejoin $characters = _text_captcha_utf8_split($response); sort($characters); $response = implode('', $characters); // Put back in element and return. $element['#value'] = $response; return $element; }