You are here

function captcha_examples in CAPTCHA 7

Same name and namespace in other branches
  1. 5.3 captcha.module \captcha_examples()
  2. 6.2 captcha.admin.inc \captcha_examples()
  3. 6 captcha.admin.inc \captcha_examples()

Funtion for generating a page with CAPTCHA examples.

If the arguments $module and $challenge are not set, generate a list with examples of the available CAPTCHA types. If $module and $challenge are set, generate 10 examples of the concerning CAPTCHA.

1 string reference to 'captcha_examples'
captcha_menu in ./captcha.module
Implements of hook_menu().

File

./captcha.admin.inc, line 572
Functionality and helper functions for CAPTCHA administration.

Code

function captcha_examples($form, $form_state, $module, $challenge) {
  module_load_include('inc', 'captcha');
  $form = array();
  if ($module && $challenge) {

    // Generate 10 example challenges.
    for ($i = 0; $i < 10; $i++) {
      $form["challenge_{$i}"] = _captcha_generate_example_challenge($module, $challenge);
    }
  }
  else {

    // Generate a list with examples of the available CAPTCHA types.
    $form['info'] = array(
      '#markup' => t('This page gives an overview of all available challenge types, generated with their current settings.'),
    );
    foreach (module_implements('captcha') as $mkey => $module) {
      $challenges = call_user_func_array($module . '_captcha', array(
        'list',
      ));
      if ($challenges) {
        foreach ($challenges as $ckey => $challenge) {
          $form["captcha_{$mkey}_{$ckey}"] = array(
            '#type' => 'fieldset',
            '#title' => t('Challenge %challenge by module %module', array(
              '%challenge' => $challenge,
              '%module' => $module,
            )),
            'challenge' => _captcha_generate_example_challenge($module, $challenge),
            'more_examples' => array(
              '#markup' => l(t('10 more examples of this challenge.'), "admin/config/people/captcha/captcha/examples/{$module}/{$challenge}"),
            ),
          );
        }
      }
    }
  }
  return $form;
}