function _phrase_captcha_word_question_alphabetical_misplaced in CAPTCHA Pack 8
Same name and namespace in other branches
- 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()
- 7 text_captcha/phrase_captcha/phrase_captcha.module \_phrase_captcha_word_question_alphabetical_misplaced()
Return details of 'alphabetical misplaced' challenge.
1 string reference to '_phrase_captcha_word_question_alphabetical_misplaced'
- phrase_captcha.settings.yml in text_captcha/
modules/ phrase_captcha/ config/ install/ phrase_captcha.settings.yml - text_captcha/modules/phrase_captcha/config/install/phrase_captcha.settings.yml
File
- text_captcha/
modules/ phrase_captcha/ phrase_captcha.module, line 212 - Implementation of a phrase based CAPTCHA, for use with the CAPTCHA module.
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 [
$words,
$description,
$answer,
];
}