Projet

Général

Profil

Paste
Télécharger (22,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / captcha / captcha.admin.inc @ ac1bc5de

1
<?php
2

    
3
/**
4
 * @file
5
 * Functionality and helper functions for CAPTCHA administration.
6
 */
7

    
8
/**
9
 * Return an array with the available CAPTCHA types, for use as options array for a select form elements.
10
 *
11
 * @param bool $add_special_options
12
 *   if true: also add a 'none' and 'default' option
13
 *
14
 * @return array
15
 *   Mapping "$module/$type" to
16
 *   "$type (from module $module)" with $module the module name implementing the CAPTCHA
17
 *   and $type the name of the CAPTCHA type.
18
 */
19
function _captcha_available_challenge_types($add_special_options = TRUE) {
20
  $captcha_types = array();
21
  if ($add_special_options) {
22
    $captcha_types['none'] = t('- No challenge -');
23
    $captcha_types['default'] = t('Default challenge type');
24
  }
25
  // We do our own version of Drupal's module_invoke_all() here because
26
  // we want to build an array with custom keys and values.
27
  foreach (module_implements('captcha') as $module) {
28
    $result = call_user_func_array($module . '_captcha', array('list'));
29
    if (is_array($result)) {
30
      foreach ($result as $type) {
31
        $captcha_types["$module/$type"] = t('@type (from module @module)', array('@type' => $type, '@module' => $module));
32
      }
33
    }
34
  }
35
  return $captcha_types;
36
}
37

    
38
/**
39
 * Form builder function for the general CAPTCHA configuration.
40
 */
41
function captcha_admin_settings() {
42
  module_load_include('inc', 'captcha');
43

    
44
  // Use javascript for some added usability on admin form.
45
  drupal_add_js(drupal_get_path('module', 'captcha') . '/captcha.js');
46

    
47
  // Configuration of which forms to protect, with what challenge.
48
  $form['captcha_form_protection'] = array(
49
    '#type' => 'fieldset',
50
    '#title' => t('Form protection'),
51
    '#description' => t("Select the challenge type you want for each of the listed forms (identified by their so called <em>form_id</em>'s). You can easily add arbitrary forms with the textfield at the bottom of the table or with the help of the option <em>Add CAPTCHA administration links to forms</em> below."),
52
  );
53
  $form['captcha_form_protection']['captcha_default_challenge'] = array(
54
    '#type' => 'select',
55
    '#title' => t('Default challenge type'),
56
    '#description' => t('Select the default challenge type for CAPTCHAs. This can be overriden for each form if desired.'),
57
    '#options' => _captcha_available_challenge_types(FALSE),
58
    '#default_value' => variable_get('captcha_default_challenge', 'captcha/Math'),
59
  );
60
  // List known form_ids.
61
  $form['captcha_form_protection']['captcha_form_id_overview'] = array(
62
    '#theme' => 'captcha_admin_settings_captcha_points',
63
    '#tree' => TRUE,
64
  );
65
  $form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'] = array();
66
  $captcha_type_options = _captcha_available_challenge_types();
67
  $result = db_select('captcha_points', 'cp')->fields('cp')->orderBy('form_id')->execute();
68
  foreach ($result as $captcha_point) {
69
    $form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id] = array();
70
    $form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id]['form_id'] = array(
71
      '#markup' => $captcha_point->form_id,
72
    );
73
    // Select widget for CAPTCHA type.
74
    if (isset($captcha_point->module) && $captcha_point->module) {
75
      $captcha_type = $captcha_point->module . '/' . $captcha_point->captcha_type;
76
    }
77
    elseif (isset($captcha_point->captcha_type) && ($captcha_point->captcha_type == 'default')) {
78
      $captcha_type = 'default';
79
    }
80
    else {
81
      $captcha_type = 'none';
82
    }
83
    $form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id]['captcha_type'] = array(
84
      '#type' => 'select',
85
      '#default_value' => $captcha_type,
86
      '#options' => $captcha_type_options,
87
    );
88
    // Additional operations.
89
    $form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id]['operations'] = array(
90
      '#markup' => implode(", ", array(
91
        l(t('delete'), "admin/config/people/captcha/captcha/captcha_point/{$captcha_point->form_id}/delete"),
92
      )),
93
    );
94
  }
95

    
96
  // Form items for new form_id.
97
  $form['captcha_form_protection']['captcha_form_id_overview']['captcha_new_captcha_point'] = array();
98
  // Textfield for form_id.
99
  $form['captcha_form_protection']['captcha_form_id_overview']['captcha_new_captcha_point']['form_id'] = array(
100
    '#type' => 'textfield',
101
    '#size' => 16,
102
  );
103
  // Select widget for CAPTCHA type.
104
  $form['captcha_form_protection']['captcha_form_id_overview']['captcha_new_captcha_point']['captcha_type'] = array(
105
    '#type' => 'select',
106
    '#default_value' => 'none',
107
    '#options' => $captcha_type_options,
108
  );
109

    
110
  // Checkbox to add default CAPTCHA to all non listed forms as well.
111
  $form['captcha_form_protection']['captcha_default_challenge_on_nonlisted_forms'] = array(
112
    '#type' => 'checkbox',
113
    '#title' => t('Default challenge on non-listed forms.'),
114
    '#default_value' => variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE),
115
    '#description' => t('Normally, no challenge is added to forms that are not listed above. Enabling this option will add the default challenge instead.'),
116
  );
117

    
118
  // Field for the CAPTCHA administration mode.
119
  $form['captcha_form_protection']['captcha_administration_mode'] = array(
120
    '#type' => 'checkbox',
121
    '#title' => t('Add CAPTCHA administration links to forms'),
122
    '#default_value' => variable_get('captcha_administration_mode', FALSE),
123
    '#description' => t('This option makes it easy to manage CAPTCHA settings on forms. When enabled, users with the <em>administer CAPTCHA settings</em> permission will see a fieldset with CAPTCHA administration links on all forms, except on administrative pages.'),
124
  );
125
  // Field for the CAPTCHAs on admin pages.
126
  $form['captcha_form_protection']['captcha_allow_on_admin_pages'] = array(
127
    '#type' => 'checkbox',
128
    '#title' => t('Allow CAPTCHAs and CAPTCHA administration links on administrative pages'),
129
    '#default_value' => variable_get('captcha_allow_on_admin_pages', FALSE),
130
    '#description' => t("This option makes it possible to add CAPTCHAs to forms on administrative pages. CAPTCHAs are disabled by default on administrative pages (which shouldn't be accessible to untrusted users normally) to avoid the related overhead. In some situations, e.g. in the case of demo sites, it can be usefull to allow CAPTCHAs on administrative pages."),
131
  );
132

    
133
  // Button for clearing the CAPTCHA placement cache.
134
  // Based on Drupal core's "Clear all caches" (performance settings page).
135
  $form['captcha_form_protection']['captcha_placement_caching'] = array(
136
    '#type' => 'item',
137
    '#title' => t('CAPTCHA placement caching'),
138
    '#description' => t('For efficiency, the positions of the CAPTCHA elements in each of the configured forms are cached. Most of the time, the structure of a form does not change and it would be a waste to recalculate the positions every time. Occasionally however, the form structure can change (e.g. during site building) and clearing the CAPTCHA placement cache can be required to fix the CAPTCHA placement.'),
139
  );
140
  $form['captcha_form_protection']['captcha_placement_caching']['captcha_placement_cache_clear'] = array(
141
    '#type' => 'submit',
142
    '#value' => t('Clear the CAPTCHA placement cache'),
143
    '#submit' => array('captcha_clear_captcha_placement_cache_submit'),
144
  );
145

    
146
  // Configuration option for adding a CAPTCHA description.
147
  $form['captcha_add_captcha_description'] = array(
148
    '#type' => 'checkbox',
149
    '#title' => t('Add a description to the CAPTCHA'),
150
    '#description' => t('Add a configurable description to explain the purpose of the CAPTCHA to the visitor.'),
151
    '#default_value' => variable_get('captcha_add_captcha_description', TRUE),
152
  );
153
  // Textfield(s) for the CAPTCHA description.
154
  if (module_exists('locale')) {
155
    $langs = locale_language_list();
156
    $form['captcha_descriptions'] = array(
157
      '#type' => 'fieldset',
158
      '#title' => t('CAPTCHA description'),
159
      '#description' => t('Configurable description of the CAPTCHA. An empty entry will reset the description to default.'),
160
      '#attributes' => array('id' => 'edit-captcha-description-wrapper'),
161
    );
162
    foreach ($langs as $lang_code => $lang_name) {
163
      $form['captcha_descriptions']["captcha_description_$lang_code"] = array(
164
        '#type' => 'textfield',
165
        '#title' => t('For language %lang_name (code %lang_code)', array('%lang_name' => $lang_name, '%lang_code' => $lang_code)),
166
        '#default_value' => _captcha_get_description($lang_code),
167
        '#maxlength' => 256,
168
      );
169
    }
170
  }
171
  else {
172
    $form['captcha_description'] = array(
173
      '#type' => 'textfield',
174
      '#title' => t('Challenge description'),
175
      '#description' => t('Configurable description of the CAPTCHA. An empty entry will reset the description to default.'),
176
      '#default_value' => _captcha_get_description(),
177
      '#maxlength' => 256,
178
      '#attributes' => array('id' => 'edit-captcha-description-wrapper'),
179
    );
180
  }
181

    
182
  // Option for case sensitive/insensitive validation of the responses.
183
  $form['captcha_default_validation'] = array(
184
    '#type' => 'radios',
185
    '#title' => t('Default CAPTCHA validation'),
186
    '#description' => t('Define how the response should be processed by default. Note that the modules that provide the actual challenges can override or ignore this.'),
187
    '#options' => array(
188
      CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE => t('Case sensitive validation: the response has to exactly match the solution.'),
189
      CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE => t('Case insensitive validation: lowercase/uppercase errors are ignored.'),
190
    ),
191
    '#default_value' => variable_get('captcha_default_validation', CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE),
192
  );
193

    
194
  // Field for CAPTCHA persistence.
195
  // TODO for D7: Rethink/simplify the explanation and UI strings.
196
  $form['captcha_persistence'] = array(
197
    '#type' => 'radios',
198
    '#title' => t('Persistence'),
199
    '#default_value' => variable_get('captcha_persistence', CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_INSTANCE),
200
    '#options' => array(
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.'),
205
    ),
206
    '#description' => t('Define if challenges should be omitted during the rest of a session once the user successfully responds to a challenge.'),
207
  );
208

    
209
  // Enable wrong response counter.
210
  $form['captcha_enable_stats'] = array(
211
    '#type' => 'checkbox',
212
    '#title' => t('Enable statistics'),
213
    '#description' => t('Keep CAPTCHA related counters in the <a href="!statusreport">status report</a>. Note that this comes with a performance penalty as updating the counters results in clearing the variable cache.', array('!statusreport' => url('admin/reports/status'))),
214
    '#default_value' => variable_get('captcha_enable_stats', FALSE),
215
  );
216

    
217
  // Option for logging wrong responses.
218
  $form['captcha_log_wrong_responses'] = array(
219
    '#type' => 'checkbox',
220
    '#title' => t('Log wrong responses'),
221
    '#description' => t('Report information about wrong responses to the <a href="!dblog">log</a>.', array('!dblog' => url('admin/reports/dblog'))),
222
    '#default_value' => variable_get('captcha_log_wrong_responses', FALSE),
223
  );
224

    
225
  // Submit button.
226
  $form['actions'] = array('#type' => 'actions');
227
  $form['actions']['submit'] = array(
228
    '#type' => 'submit',
229
    '#value' => t('Save configuration'),
230
  );
231

    
232
  return $form;
233
}
234

    
235
/**
236
 * Custom theme function for a table of (form_id -> CAPTCHA type) settings.
237
 */
238
function theme_captcha_admin_settings_captcha_points($variables) {
239
  $form = $variables['form'];
240
  $header = array('form_id', t('Challenge type'), t('Operations'));
241
  $rows = array();
242
  // Existing CAPTCHA points.
243
  foreach (element_children($form['captcha_captcha_points']) as $key) {
244
    $row = array();
245
    $row[] = drupal_render($form['captcha_captcha_points'][$key]['form_id']);
246
    $row[] = drupal_render($form['captcha_captcha_points'][$key]['captcha_type']);
247
    $row[] = drupal_render($form['captcha_captcha_points'][$key]['operations']);
248
    $rows[] = $row;
249
  }
250
  // For new CAPTCHA point.
251
  $row = array();
252
  $row[] = drupal_render($form['captcha_new_captcha_point']['form_id']);
253
  $row[] = drupal_render($form['captcha_new_captcha_point']['captcha_type']);
254
  $row[] = '';
255
  $rows[] = $row;
256

    
257
  $output = theme('table', array('header' => $header, 'rows' => $rows));
258
  return $output;
259
}
260

    
261
/**
262
 * Validation handler for captcha_admin_settings form.
263
 */
264
function captcha_admin_settings_validate($form, $form_state) {
265
  $form_id = $form_state['values']['captcha_form_id_overview']['captcha_new_captcha_point']['form_id'];
266
  if (!preg_match('/^[a-z0-9_]*$/', $form_id)) {
267
    form_set_error('captcha_form_id_overview][captcha_new_captcha_point][form_id', t('Illegal form_id'));
268
  }
269
}
270

    
271
/**
272
 * Submission function for captcha_admin_settings form.
273
 */
274
function captcha_admin_settings_submit($form, &$form_state) {
275

    
276
  variable_set('captcha_administration_mode', $form_state['values']['captcha_administration_mode']);
277
  variable_set('captcha_allow_on_admin_pages', $form_state['values']['captcha_allow_on_admin_pages']);
278

    
279
  variable_set('captcha_default_challenge', $form_state['values']['captcha_default_challenge']);
280
  variable_set('captcha_default_challenge_on_nonlisted_forms', $form_state['values']['captcha_default_challenge_on_nonlisted_forms']);
281

    
282
  // Process CAPTCHA points.
283
  if (isset($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'])) {
284
    foreach ($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'] as $captcha_point_form_id => $data) {
285
      captcha_set_form_id_setting($captcha_point_form_id, $data['captcha_type']);
286
    }
287
  }
288

    
289
  // Add new CAPTCHA point?
290
  $captcha_point_form_id = $form_state['values']['captcha_form_id_overview']['captcha_new_captcha_point']['form_id'];
291
  if (!empty($captcha_point_form_id)) {
292
    $captcha_type = $form_state['values']['captcha_form_id_overview']['captcha_new_captcha_point']['captcha_type'];
293
    captcha_set_form_id_setting($captcha_point_form_id, $captcha_type);
294
    drupal_set_message(t('Added CAPTCHA point.'), 'status');
295
  }
296

    
297
  // CAPTCHA description stuff.
298
  variable_set('captcha_add_captcha_description', $form_state['values']['captcha_add_captcha_description']);
299
  // Save (or reset) the CAPTCHA descriptions.
300
  if (module_exists('locale')) {
301
    $langs = locale_language_list();
302
    foreach ($langs as $lang_code => $lang_name) {
303
      $description = $form_state['values']["captcha_description_$lang_code"];
304
      if ($description) {
305
        variable_set("captcha_description_$lang_code", $description);
306
      }
307
      else {
308
        variable_del("captcha_description_$lang_code");
309
        drupal_set_message(t('Reset of CAPTCHA description for language %language.', array('%language' => $lang_name)), 'status');
310
      }
311
    }
312
  }
313
  else {
314
    $description = $form_state['values']['captcha_description'];
315
    if ($description) {
316
      variable_set('captcha_description', $description);
317
    }
318
    else {
319
      variable_del('captcha_description');
320
      drupal_set_message(t('Reset of CAPTCHA description.'), 'status');
321
    }
322
  }
323

    
324
  variable_set('captcha_default_validation', $form_state['values']['captcha_default_validation']);
325
  variable_set('captcha_persistence', $form_state['values']['captcha_persistence']);
326
  variable_set('captcha_enable_stats', $form_state['values']['captcha_enable_stats']);
327
  variable_set('captcha_log_wrong_responses', $form_state['values']['captcha_log_wrong_responses']);
328

    
329
  drupal_set_message(t('The CAPTCHA settings have been saved.'), 'status');
330
}
331

    
332
/**
333
 * Submit callback; clear CAPTCHA placement cache.
334
 */
335
function captcha_clear_captcha_placement_cache_submit($form, &$form_state) {
336
  variable_del('captcha_placement_map_cache');
337
  drupal_set_message(t('Cleared the CAPTCHA placement cache.'));
338
}
339

    
340
/**
341
 * Central handler for CAPTCHA point administration (adding, disabling, deleting).
342
 */
343
function captcha_point_admin($captcha_point_form_id = NULL, $op = NULL) {
344
  module_load_include('inc', 'captcha');
345

    
346
  // If $captcha_point_form_id and action $op given: do the action.
347
  if ($captcha_point_form_id) {
348
    switch ($op) {
349
      case 'disable':
350
        return drupal_get_form('captcha_point_disable_confirm', $captcha_point_form_id, FALSE);
351

    
352
      case 'delete':
353
        return drupal_get_form('captcha_point_disable_confirm', $captcha_point_form_id, TRUE);
354
    }
355
    // Return edit form for CAPTCHA point.
356
    return drupal_get_form('captcha_point_admin_form', $captcha_point_form_id);
357
  }
358
  // Return add form for CAPTCHA point.
359
  return drupal_get_form('captcha_point_admin_form');
360
}
361

    
362
/**
363
 * Admin form.
364
 */
365
function captcha_point_admin_form($form, $form_state, $captcha_point_form_id = NULL) {
366
  $form = array();
367
  $default_captcha_type = 'none';
368
  if (isset($captcha_point_form_id)) {
369
    // Use given CAPTCHA point form_id.
370
    $form['captcha_point_form_id'] = array(
371
      '#type' => 'textfield',
372
      '#title' => t('Form ID'),
373
      '#description' => t('The Drupal form_id of the form to add the CAPTCHA to.'),
374
      '#value' => check_plain($captcha_point_form_id),
375
      '#disabled' => TRUE,
376
    );
377
    $captcha_point = captcha_get_form_id_setting($captcha_point_form_id);
378
    if ($captcha_point) {
379
      $default_captcha_type = "{$captcha_point->module}/{$captcha_point->captcha_type}";
380
    }
381
  }
382
  else {
383
    // Textfield for CAPTCHA point form_id.
384
    $form['captcha_point_form_id'] = array(
385
      '#type' => 'textfield',
386
      '#title' => t('Form ID'),
387
      '#description' => t('The Drupal form_id of the form to add the CAPTCHA to.'),
388
    );
389
  }
390
  // Select widget for CAPTCHA type.
391
  $form['captcha_type'] = array(
392
    '#type' => 'select',
393
    '#title' => t('Challenge type'),
394
    '#description' => t('The CAPTCHA type to use for this form.'),
395
    '#default_value' => $default_captcha_type,
396
    '#options' => _captcha_available_challenge_types(),
397
  );
398
  // Redirect to general CAPTCHA settings page after submission.
399
  $form['#redirect'] = 'admin/config/people/captcha';
400
  // Submit button.
401
  $form['actions'] = array('#type' => 'actions');
402
  $form['actions']['submit'] = array(
403
    '#type' => 'submit',
404
    '#value' => t('Save'),
405
  );
406
  return $form;
407
}
408

    
409
/**
410
 * Validation function for captcha_point_admin_form.
411
 */
412
function captcha_point_admin_form_validate($form, $form_state) {
413
  if (!preg_match('/^[a-z0-9_]+$/', $form_state['values']['captcha_point_form_id'])) {
414
    form_set_error('captcha_point_form_id', t('Illegal form_id'));
415
  }
416
}
417

    
418
/**
419
 * Submit function for captcha_point_admin_form.
420
 */
421
function captcha_point_admin_form_submit($form, $form_state) {
422
  $captcha_point_form_id = $form_state['values']['captcha_point_form_id'];
423
  $captcha_type = $form_state['values']['captcha_type'];
424
  captcha_set_form_id_setting($captcha_point_form_id, $captcha_type);
425
  drupal_set_message(t('Saved CAPTCHA point settings.'), 'status');
426
}
427

    
428
/**
429
 * Confirm dialog for disabling/deleting a CAPTCHA point.
430
 */
431
function captcha_point_disable_confirm($form, &$form_state, $captcha_point_form_id, $delete) {
432
  $form = array();
433
  $form['captcha_point_form_id'] = array(
434
    '#type' => 'value',
435
    '#value' => $captcha_point_form_id,
436
  );
437
  $form['captcha_point_delete'] = array(
438
    '#type' => 'value',
439
    '#value' => $delete,
440
  );
441
  if ($delete) {
442
    $message = t('Are you sure you want to delete the CAPTCHA for form_id %form_id?', array('%form_id' => $captcha_point_form_id));
443
    $yes = t('Delete');
444
  }
445
  else {
446
    $message = t('Are you sure you want to disable the CAPTCHA for form_id %form_id?', array('%form_id' => $captcha_point_form_id));
447
    $yes = t('Disable');
448
  }
449
  return confirm_form($form, $message, 'admin/config/people/captcha/captcha', '', $yes);
450
}
451

    
452
/**
453
 * Submission handler of CAPTCHA point disabling/deleting confirm_form.
454
 */
455
function captcha_point_disable_confirm_submit($form, &$form_state) {
456
  $captcha_point_form_id = $form_state['values']['captcha_point_form_id'];
457
  $delete = $form_state['values']['captcha_point_delete'];
458
  if ($delete) {
459
    captcha_set_form_id_setting($captcha_point_form_id, NULL);
460
    drupal_set_message(t('Deleted CAPTCHA for form %form_id.', array('%form_id' => $captcha_point_form_id)));
461
  }
462
  else {
463
    captcha_set_form_id_setting($captcha_point_form_id, 'none');
464
    drupal_set_message(t('Disabled CAPTCHA for form %form_id.', array('%form_id' => $captcha_point_form_id)));
465
  }
466
  $form_state['redirect'] = 'admin/config/people/captcha/captcha';
467
}
468

    
469
/**
470
 * Helper function for generating an example challenge.
471
 */
472
function _captcha_generate_example_challenge($module, $type) {
473
  return array(
474
    '#type' => 'captcha',
475
    '#captcha_type' => $module . '/' . $type,
476
    '#captcha_admin_mode' => TRUE,
477
  );
478
}
479

    
480
/**
481
 * Funtion for generating a page with CAPTCHA examples.
482
 *
483
 * If the arguments $module and $challenge are not set, generate a list with
484
 * examples of the available CAPTCHA types.
485
 * If $module and $challenge are set, generate 10 examples of the concerning
486
 * CAPTCHA.
487
 */
488
function captcha_examples($form, $form_state, $module, $challenge) {
489
  module_load_include('inc', 'captcha');
490

    
491
  $form = array();
492
  if ($module && $challenge) {
493
    // Generate 10 example challenges.
494
    for ($i = 0; $i < 10; $i++) {
495
      $form["challenge_{$i}"] = _captcha_generate_example_challenge($module, $challenge);
496
    }
497
  }
498
  else {
499
    // Generate a list with examples of the available CAPTCHA types.
500
    $form['info'] = array(
501
      '#markup' => t('This page gives an overview of all available challenge types, generated with their current settings.'),
502
    );
503
    foreach (module_implements('captcha') as $mkey => $module) {
504
      $challenges = call_user_func_array($module . '_captcha', array('list'));
505
      if ($challenges) {
506
        foreach ($challenges as $ckey => $challenge) {
507
          $form["captcha_{$mkey}_{$ckey}"] = array(
508
            '#type' => 'fieldset',
509
            '#title' => t('Challenge %challenge by module %module', array('%challenge' => $challenge, '%module' => $module)),
510
            'challenge' => _captcha_generate_example_challenge($module, $challenge),
511
            'more_examples' => array(
512
              '#markup' => l(t('10 more examples of this challenge.'), "admin/config/people/captcha/captcha/examples/$module/$challenge"),
513
            ),
514
          );
515
        }
516
      }
517
    }
518
  }
519
  return $form;
520
}