Révision 99781f3b
Ajouté par Assos Assos il y a plus de 7 ans
drupal7/sites/all/modules/hidden_captcha/hidden_captcha.module | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
/** |
4 |
* Implementation of hook_help(). |
|
4 |
* @file |
|
5 |
* All code for the Foo Bar module, except installation-related code. |
|
6 |
*/ |
|
7 |
|
|
8 |
/** |
|
9 |
* Implements hook_help(). |
|
5 | 10 |
*/ |
6 | 11 |
function hidden_captcha_help($path, $arg) { |
7 | 12 |
switch ($path) { |
8 | 13 |
case 'admin/config/people/captcha/hidden_captcha': |
9 |
return '<p>'. t('This CAPTCHA presents a text field that we expect no one to fill. The text field can be given any name and will be hidden from view using CSS.') .'</p>';
|
|
14 |
return '<p>' . t('This CAPTCHA presents a text field that we expect no one to fill. The text field can be given any name and will be hidden from view using CSS.') . '</p>';
|
|
10 | 15 |
} |
11 | 16 |
} |
12 | 17 |
|
13 | 18 |
/** |
14 |
* Implementation of hook_menu().
|
|
19 |
* Implements hook_menu().
|
|
15 | 20 |
*/ |
16 | 21 |
function hidden_captcha_menu() { |
17 | 22 |
$items = array(); |
... | ... | |
35 | 40 |
'#type' => 'textfield', |
36 | 41 |
'#title' => t('Hidden text field label'), |
37 | 42 |
'#description' => t( |
38 |
"This is the hidden captcha form field's label, describing the expected input.<br />". |
|
39 |
"<strong>It is highly recommended to change it!</strong><br />". |
|
40 |
"The label should be as \"machine-readable\" as possible, encouraging spambots to fill in the field. An example might be a simple math challenge.<br />". |
|
43 |
"This is the hidden captcha form field's label, describing the expected input.<br />" .
|
|
44 |
"<strong>It is highly recommended to change it!</strong><br />" .
|
|
45 |
"The label should be as \"machine-readable\" as possible, encouraging spambots to fill in the field. An example might be a simple math challenge.<br />" .
|
|
41 | 46 |
"The label will only be visible to people who do not have CSS enabled and to robots." |
42 | 47 |
), |
43 | 48 |
'#default_value' => variable_get('hidden_captcha_label', 'Website URL'), |
... | ... | |
46 | 51 |
} |
47 | 52 |
|
48 | 53 |
/** |
49 |
* Implementation of hook_captcha().
|
|
54 |
* Implements hook_captcha().
|
|
50 | 55 |
*/ |
51 | 56 |
function hidden_captcha_captcha($op, $captcha_type = '') { |
52 | 57 |
switch ($op) { |
... | ... | |
58 | 63 |
$captcha['form']['captcha_response'] = array( |
59 | 64 |
'#type' => 'textfield', |
60 | 65 |
'#title' => variable_get('hidden_captcha_label', 'Website URL'), |
61 |
'#required' => FALSE |
|
66 |
'#required' => FALSE, |
|
67 |
'#attributes' => array('tabindex' => '-1'), |
|
62 | 68 |
); |
63 | 69 |
return $captcha; |
64 | 70 |
} |
... | ... | |
67 | 73 |
} |
68 | 74 |
|
69 | 75 |
/** |
70 |
* Implementation of hook_theme().
|
|
76 |
* Implements hook_theme().
|
|
71 | 77 |
*/ |
72 | 78 |
function hidden_captcha_theme() { |
73 | 79 |
return array( |
... | ... | |
79 | 85 |
} |
80 | 86 |
|
81 | 87 |
/** |
82 |
* Implementation of theme_hook().
|
|
88 |
* Implements theme_hook().
|
|
83 | 89 |
*/ |
84 | 90 |
function theme_hidden_captcha_captcha($element) { |
85 | 91 |
$captcha = theme_captcha($element); |
... | ... | |
89 | 95 |
$class = ""; |
90 | 96 |
for ($i = 0; $i < 64; ++$i) $class .= substr($chars, rand(0, strlen($chars)-1), 1); |
91 | 97 |
//hide the random class via css |
92 |
drupal_add_css(".$class{width:0;height:0;overflow:hidden;}","inline"); // TODO: move the random class to an external file |
|
98 |
drupal_add_css(".$class{width:0;height:0;overflow:hidden;}", "inline"); // TODO: move the random class to an external file
|
|
93 | 99 |
//html for the captcha |
94 | 100 |
$captcha = "<div class=\"$class\">" . $captcha . "</div>"; |
95 | 101 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules