function captcha_examples in CAPTCHA 5.3
Same name and namespace in other branches
- 6.2 captcha.admin.inc \captcha_examples()
- 6 captcha.admin.inc \captcha_examples()
- 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.module, line 747 - This module enables basic CAPTCHA functionality: administrators can add a CAPTCHA to desired forms that users without the 'skip CAPTCHA' permission (typically anonymous visitors) have to solve.
Code
function captcha_examples($module = NULL, $challenge = NULL) {
if ($module && $challenge) {
// generate 10 examples
$output = '';
for ($i = 0; $i < 10; $i++) {
// generate CAPTCHA
$captcha = call_user_func_array($module . '_captcha', array(
'generate',
$challenge,
));
$form = $captcha['form'];
$id = "captcha_examples_{$module_}{$challenge_}{$i}";
drupal_process_form($id, $form);
$output .= drupal_render_form($id, $form);
}
}
else {
// generate a list with examples of the available CAPTCHA types
$output = t('This page gives an overview of all available challenge types, generated with their current settings.');
foreach (module_implements('captcha') as $module) {
$challenges = call_user_func_array($module . '_captcha', array(
'list',
));
if ($challenges) {
foreach ($challenges as $challenge) {
// generate CAPTCHA
$captcha = call_user_func_array($module . '_captcha', array(
'generate',
$challenge,
));
// build form
$form = array();
$form['captcha'] = array(
'#type' => 'fieldset',
'#title' => t('Challenge "%challenge" by module "%module"', array(
'%challenge' => $challenge,
'%module' => $module,
)),
);
$form['captcha'] = array_merge($form['captcha'], $captcha['form']);
$form['captcha']['more_examples'] = array(
'#type' => 'markup',
'#value' => l(t('10 more examples of this challenge.'), "admin/user/captcha/captcha/examples/{$module}/{$challenge}"),
);
// return rendered form
$id = "captcha_examples_{$module_}{$challenge}";
drupal_process_form($id, $form);
$output .= drupal_render_form($id, $form);
}
}
}
}
return $output;
}