math_captcha.module in CAPTCHA Pack 8
Same filename and directory in other branches
Contains general functionality of the module.
File
math_captcha/math_captcha.moduleView source
<?php
/**
* @file
* Contains general functionality of the module.
*/
/**
* Implements hook_help().
*/
function math_captcha_help($path, $arg) {
switch ($path) {
case 'admin/config/people/captcha/math_captcha':
return '<p>' . t("Provide math CAPTCHAs like 'two + three = ?' and '2 times ? = 6'.") . '</p>';
}
}
/**
* Implements hook_captcha().
*/
function math_captcha_captcha($op, $captcha_type = '') {
switch ($op) {
case 'list':
return [
'Math CAPTCHA',
];
case 'generate':
if ($captcha_type == 'Math CAPTCHA') {
module_load_include('inc', 'math_captcha', 'math_captcha.challenge');
// Get the available challenges.
$enabled_challenges = _math_captcha_enabled_challenges();
$challenges = array_filter($enabled_challenges);
$challenge = $challenges[array_rand($challenges)];
$form_item = call_user_func("_math_captcha_{$challenge}_challenge");
\Drupal::service('page_cache_kill_switch')
->trigger();
return $form_item;
}
break;
}
}
/**
* Get enabled math captcha challenges.
*/
function _math_captcha_enabled_challenges() {
return Drupal::config('math_captcha.settings')
->get('math_captcha_enabled_challenges');
}
Functions
Name | Description |
---|---|
math_captcha_captcha | Implements hook_captcha(). |
math_captcha_help | Implements hook_help(). |
_math_captcha_enabled_challenges | Get enabled math captcha challenges. |