function _phrase_captcha_word_question_alphabetical_misplaced in CAPTCHA Pack 7
Same name and namespace in other branches
- 8 text_captcha/modules/phrase_captcha/phrase_captcha.module \_phrase_captcha_word_question_alphabetical_misplaced()
- 5 text_captcha/phrase_captcha/phrase_captcha.module \_phrase_captcha_word_question_alphabetical_misplaced()
- 6 text_captcha/phrase_captcha/phrase_captcha.inc \_phrase_captcha_word_question_alphabetical_misplaced()
File
- text_captcha/
phrase_captcha/ phrase_captcha.module, line 212
Code
function _phrase_captcha_word_question_alphabetical_misplaced($words) {
// Sort the words
mt_rand(0, 1) ? sort($words) : rsort($words);
// Pick a word and its new destination
// New destination has to be at least 2 places from the original place,
// otherwise it could lead to something like swapping two neighbours,
// in which case there is no unique answer.
$from = 0;
$to = 0;
while (abs($from - $to) < 2) {
$from = array_rand($words, 1);
$to = array_rand($words, 1);
}
// Get the word
$answer = $words[$from];
// Move the word from $from to $to
unset($words[$from]);
array_splice($words, $to, 0, $answer);
// bBuild the description
$description = t('Which word does not follow the alphabetical order in the CAPTCHA phrase above?');
return array(
$words,
$description,
$answer,
);
}