2
// $Id: random_captcha_type.module,v 1.11 2008/04/07 22:55:02 soxofaan Exp $
5
* Implementation of a "meta CAPTCHA" which randomly picks a CAPTCHA type
9
* Implementation of hook_help().
11
function random_captcha_type_help($path, $arg) {
13
case 'admin/user/captcha/random_captcha_type':
14
return '<p>'. t('This CAPTCHA type is a "meta" CAPTCHA type, which randomly picks one of the selected CAPTCHA types.') .'</p>';
19
* Implementation of hook_menu().
21
function random_captcha_type_menu() {
23
// add an administration tab for random_captcha_type
24
$items['admin/user/captcha/random_captcha_type'] = array(
25
'title' => 'Random CAPTCHA type',
26
'file' => 'random_captcha_type.admin.inc',
27
'page callback' => 'drupal_get_form',
28
'page arguments' => array('random_captcha_type_settings_form'),
29
'access arguments' => array('administer CAPTCHA settings'),
30
'type' => MENU_LOCAL_TASK,
36
* Implementation of hook_captcha
38
function random_captcha_type_captcha($op, $captcha_type='') {
41
require_once('random_captcha_type.inc');
42
$enabled_types = _random_captcha_type_get_enabled_types();
43
if (count($enabled_types) < 2) {
46
return array('Random CAPTCHA type');
48
if ($captcha_type == 'Random CAPTCHA type') {
49
require_once('random_captcha_type.inc');
50
if (isset($_POST['random_captcha_type'])) {
51
// If this is a POST request, we're possibly in a validation phase
52
// so the CAPTCHA type should be the same as in the originating form
53
$module_and_type = $_POST['random_captcha_type'];
56
// If not, just pick a random one
57
$types = _random_captcha_type_get_enabled_types();
58
$module_and_type = $types[array_rand($types)];
60
list($module, $type) = explode('/', $module_and_type);
61
// Call the generate CAPTCHA hook
62
$captcha = module_invoke($module, 'captcha', 'generate', $type);
63
// Store the current CAPTCHA type so it can be recovered for
64
// regenerating the form in the validation phase
65
$captcha['form']['random_captcha_type'] = array(
67
'#value' => $module_and_type,