You are here

function _phrase_captcha_word_question_word_index in CAPTCHA Pack 8

Same name and namespace in other branches
  1. 5 text_captcha/phrase_captcha/phrase_captcha.module \_phrase_captcha_word_question_word_index()
  2. 6 text_captcha/phrase_captcha/phrase_captcha.inc \_phrase_captcha_word_question_word_index()
  3. 7 text_captcha/phrase_captcha/phrase_captcha.module \_phrase_captcha_word_question_word_index()

Return details of 'word index' challenge.

1 string reference to '_phrase_captcha_word_question_word_index'
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 189
Implementation of a phrase based CAPTCHA, for use with the CAPTCHA module.

Code

function _phrase_captcha_word_question_word_index($words) {
  $key = array_rand($words, 1);
  $answer = $words[$key];
  if (mt_rand(0, 1)) {
    $description = t('What is the @nth word in the CAPTCHA phrase above?', [
      '@nth' => _phrase_captcha_ordinal($key + 1),
    ]);
  }
  else {
    $n = count($words) - $key;
    if ($n == 1) {
      $description = t('What is the last word in the CAPTCHA phrase above?');
    }
    else {
      $description = t('What is the @nth last word in the CAPTCHA phrase above?', [
        '@nth' => _phrase_captcha_ordinal($n),
      ]);
    }
  }
  return [
    $words,
    $description,
    $answer,
  ];
}