Révision ac1bc5de
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/captcha/captcha.admin.inc | ||
---|---|---|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Return an array with the available CAPTCHA types, for use as options array |
|
10 |
* for a select form elements. |
|
9 |
* Return an array with the available CAPTCHA types, for use as options array for a select form elements. |
|
11 | 10 |
* |
12 |
* @param $add_special_options if true: also add a 'none' and 'default' option |
|
11 |
* @param bool $add_special_options |
|
12 |
* if true: also add a 'none' and 'default' option |
|
13 | 13 |
* |
14 |
* @return an associative array mapping "$module/$type" to |
|
14 |
* @return array |
|
15 |
* Mapping "$module/$type" to |
|
15 | 16 |
* "$type (from module $module)" with $module the module name implementing the CAPTCHA |
16 | 17 |
* and $type the name of the CAPTCHA type. |
17 | 18 |
*/ |
18 |
function _captcha_available_challenge_types($add_special_options=TRUE) {
|
|
19 |
function _captcha_available_challenge_types($add_special_options = TRUE) {
|
|
19 | 20 |
$captcha_types = array(); |
20 | 21 |
if ($add_special_options) { |
21 | 22 |
$captcha_types['none'] = t('- No challenge -'); |
... | ... | |
35 | 36 |
} |
36 | 37 |
|
37 | 38 |
/** |
38 |
* Form builder function for the general CAPTCHA configuration |
|
39 |
* Form builder function for the general CAPTCHA configuration.
|
|
39 | 40 |
*/ |
40 | 41 |
function captcha_admin_settings() { |
41 | 42 |
module_load_include('inc', 'captcha'); |
... | ... | |
88 | 89 |
$form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id]['operations'] = array( |
89 | 90 |
'#markup' => implode(", ", array( |
90 | 91 |
l(t('delete'), "admin/config/people/captcha/captcha/captcha_point/{$captcha_point->form_id}/delete"), |
91 |
)) |
|
92 |
)),
|
|
92 | 93 |
); |
93 | 94 |
} |
94 | 95 |
|
... | ... | |
197 | 198 |
'#title' => t('Persistence'), |
198 | 199 |
'#default_value' => variable_get('captcha_persistence', CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_INSTANCE), |
199 | 200 |
'#options' => array( |
200 |
CAPTCHA_PERSISTENCE_SHOW_ALWAYS => |
|
201 |
t('Always add a challenge.'), |
|
202 |
CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_INSTANCE => |
|
203 |
t('Omit challenges in a multi-step/preview workflow once the user successfully responds to a challenge.'), |
|
204 |
CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_TYPE => |
|
205 |
t('Omit challenges on a form type once the user successfully responds to a challenge on a form of that type.'), |
|
206 |
CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL => |
|
207 |
t('Omit challenges on all forms once the user successfully responds to any challenge on the site.'), |
|
201 |
CAPTCHA_PERSISTENCE_SHOW_ALWAYS => t('Always add a challenge.'), |
|
202 |
CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_INSTANCE => t('Omit challenges in a multi-step/preview workflow once the user successfully responds to a challenge.'), |
|
203 |
CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_TYPE => t('Omit challenges on a form type once the user successfully responds to a challenge on a form of that type.'), |
|
204 |
CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL => t('Omit challenges on all forms once the user successfully responds to any challenge on the site.'), |
|
208 | 205 |
), |
209 | 206 |
'#description' => t('Define if challenges should be omitted during the rest of a session once the user successfully responds to a challenge.'), |
210 | 207 |
); |
... | ... | |
236 | 233 |
} |
237 | 234 |
|
238 | 235 |
/** |
239 |
* Custom theme function for a table of (form_id -> CAPTCHA type) settings |
|
236 |
* Custom theme function for a table of (form_id -> CAPTCHA type) settings.
|
|
240 | 237 |
*/ |
241 | 238 |
function theme_captcha_admin_settings_captcha_points($variables) { |
242 | 239 |
$form = $variables['form']; |
... | ... | |
282 | 279 |
variable_set('captcha_default_challenge', $form_state['values']['captcha_default_challenge']); |
283 | 280 |
variable_set('captcha_default_challenge_on_nonlisted_forms', $form_state['values']['captcha_default_challenge_on_nonlisted_forms']); |
284 | 281 |
|
285 |
// Process CAPTCHA points |
|
282 |
// Process CAPTCHA points.
|
|
286 | 283 |
if (isset($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'])) { |
287 | 284 |
foreach ($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'] as $captcha_point_form_id => $data) { |
288 | 285 |
captcha_set_form_id_setting($captcha_point_form_id, $data['captcha_type']); |
... | ... | |
332 | 329 |
drupal_set_message(t('The CAPTCHA settings have been saved.'), 'status'); |
333 | 330 |
} |
334 | 331 |
|
335 |
|
|
336 |
|
|
337 |
|
|
338 | 332 |
/** |
339 | 333 |
* Submit callback; clear CAPTCHA placement cache. |
340 | 334 |
*/ |
... | ... | |
343 | 337 |
drupal_set_message(t('Cleared the CAPTCHA placement cache.')); |
344 | 338 |
} |
345 | 339 |
|
346 |
|
|
347 | 340 |
/** |
348 |
* Central handler for CAPTCHA point administration (adding, disabling, deleting) |
|
341 |
* Central handler for CAPTCHA point administration (adding, disabling, deleting).
|
|
349 | 342 |
*/ |
350 |
function captcha_point_admin($captcha_point_form_id=NULL, $op=NULL) {
|
|
343 |
function captcha_point_admin($captcha_point_form_id = NULL, $op = NULL) {
|
|
351 | 344 |
module_load_include('inc', 'captcha'); |
352 | 345 |
|
353 |
// if $captcha_point_form_id and action $op given: do the action
|
|
346 |
// If $captcha_point_form_id and action $op given: do the action.
|
|
354 | 347 |
if ($captcha_point_form_id) { |
355 | 348 |
switch ($op) { |
356 | 349 |
case 'disable': |
357 | 350 |
return drupal_get_form('captcha_point_disable_confirm', $captcha_point_form_id, FALSE); |
351 |
|
|
358 | 352 |
case 'delete': |
359 | 353 |
return drupal_get_form('captcha_point_disable_confirm', $captcha_point_form_id, TRUE); |
360 | 354 |
} |
361 |
// return edit form for CAPTCHA point
|
|
355 |
// Return edit form for CAPTCHA point.
|
|
362 | 356 |
return drupal_get_form('captcha_point_admin_form', $captcha_point_form_id); |
363 | 357 |
} |
364 |
// return add form for CAPTCHA point
|
|
358 |
// Return add form for CAPTCHA point.
|
|
365 | 359 |
return drupal_get_form('captcha_point_admin_form'); |
366 | 360 |
} |
367 | 361 |
|
368 |
function captcha_point_admin_form($form, $form_state, $captcha_point_form_id=NULL) { |
|
362 |
/** |
|
363 |
* Admin form. |
|
364 |
*/ |
|
365 |
function captcha_point_admin_form($form, $form_state, $captcha_point_form_id = NULL) { |
|
369 | 366 |
$form = array(); |
370 | 367 |
$default_captcha_type = 'none'; |
371 | 368 |
if (isset($captcha_point_form_id)) { |
372 |
// use given CAPTCHA point form_id
|
|
369 |
// Use given CAPTCHA point form_id.
|
|
373 | 370 |
$form['captcha_point_form_id'] = array( |
374 | 371 |
'#type' => 'textfield', |
375 | 372 |
'#title' => t('Form ID'), |
... | ... | |
383 | 380 |
} |
384 | 381 |
} |
385 | 382 |
else { |
386 |
// textfield for CAPTCHA point form_id
|
|
383 |
// Textfield for CAPTCHA point form_id.
|
|
387 | 384 |
$form['captcha_point_form_id'] = array( |
388 | 385 |
'#type' => 'textfield', |
389 | 386 |
'#title' => t('Form ID'), |
390 | 387 |
'#description' => t('The Drupal form_id of the form to add the CAPTCHA to.'), |
391 | 388 |
); |
392 | 389 |
} |
393 |
// select widget for CAPTCHA type
|
|
390 |
// Select widget for CAPTCHA type.
|
|
394 | 391 |
$form['captcha_type'] = array( |
395 | 392 |
'#type' => 'select', |
396 | 393 |
'#title' => t('Challenge type'), |
... | ... | |
398 | 395 |
'#default_value' => $default_captcha_type, |
399 | 396 |
'#options' => _captcha_available_challenge_types(), |
400 | 397 |
); |
401 |
// redirect to general CAPTCHA settings page after submission
|
|
398 |
// Redirect to general CAPTCHA settings page after submission.
|
|
402 | 399 |
$form['#redirect'] = 'admin/config/people/captcha'; |
403 |
// submit button
|
|
400 |
// Submit button.
|
|
404 | 401 |
$form['actions'] = array('#type' => 'actions'); |
405 | 402 |
$form['actions']['submit'] = array( |
406 | 403 |
'#type' => 'submit', |
... | ... | |
409 | 406 |
return $form; |
410 | 407 |
} |
411 | 408 |
|
412 |
|
|
413 | 409 |
/** |
414 |
* validation function for captcha_point_admin_form
|
|
410 |
* Validation function for captcha_point_admin_form.
|
|
415 | 411 |
*/ |
416 | 412 |
function captcha_point_admin_form_validate($form, $form_state) { |
417 | 413 |
if (!preg_match('/^[a-z0-9_]+$/', $form_state['values']['captcha_point_form_id'])) { |
... | ... | |
419 | 415 |
} |
420 | 416 |
} |
421 | 417 |
|
422 |
|
|
423 | 418 |
/** |
424 | 419 |
* Submit function for captcha_point_admin_form. |
425 | 420 |
*/ |
... | ... | |
431 | 426 |
} |
432 | 427 |
|
433 | 428 |
/** |
434 |
* Confirm dialog for disabling/deleting a CAPTCHA point |
|
429 |
* Confirm dialog for disabling/deleting a CAPTCHA point.
|
|
435 | 430 |
*/ |
436 | 431 |
function captcha_point_disable_confirm($form, &$form_state, $captcha_point_form_id, $delete) { |
437 | 432 |
$form = array(); |
... | ... | |
496 | 491 |
$form = array(); |
497 | 492 |
if ($module && $challenge) { |
498 | 493 |
// Generate 10 example challenges. |
499 |
for ($i=0; $i<10; $i++) {
|
|
494 |
for ($i = 0; $i < 10; $i++) {
|
|
500 | 495 |
$form["challenge_{$i}"] = _captcha_generate_example_challenge($module, $challenge); |
501 | 496 |
} |
502 | 497 |
} |
503 | 498 |
else { |
504 |
// generate a list with examples of the available CAPTCHA types
|
|
499 |
// Generate a list with examples of the available CAPTCHA types.
|
|
505 | 500 |
$form['info'] = array( |
506 | 501 |
'#markup' => t('This page gives an overview of all available challenge types, generated with their current settings.'), |
507 | 502 |
); |
Formats disponibles : Unified diff
Weekly update of contrib modules