You are here

function captcha_examples in CAPTCHA 6

Same name and namespace in other branches
  1. 5.3 captcha.module \captcha_examples()
  2. 6.2 captcha.admin.inc \captcha_examples()
  3. 7 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
Implementation of hook_menu().

File

./captcha.admin.inc, line 305

Code

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

    // generate 10 examples
    for ($i = 0; $i < 10; $i++) {

      // generate CAPTCHA
      $captcha = call_user_func_array($module . '_captcha', array(
        'generate',
        $challenge,
      ));

      // add form elements
      $form["challenge_{$i}"] = $captcha['form'];
    }
  }
  else {

    // generate a list with examples of the available CAPTCHA types
    $form['info'] = array(
      '#value' => 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', 'list');
      if ($challenges) {
        foreach ($challenges as $ckey => $challenge) {

          // generate CAPTCHA
          $captcha = call_user_func_array($module . '_captcha', array(
            'generate',
            $challenge,
          ));

          // build form
          $form["captcha_{$mkey}_{$ckey}"] = array(
            '#type' => 'fieldset',
            '#title' => t('Challenge "%challenge" by module "%module"', array(
              '%challenge' => $challenge,
              '%module' => $module,
            )),
            'challenge' => $captcha['form'],
            'more_examples' => array(
              '#value' => l(t('10 more examples of this challenge.'), "admin/user/captcha/captcha/examples/{$module}/{$challenge}"),
            ),
          );
        }
      }
    }
  }
  return $form;
}