Index: captcha.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/captcha/captcha.module,v retrieving revision 1.42.2.32 diff -u -u -p -r1.42.2.32 captcha.module --- captcha.module 19 Sep 2007 15:31:27 -0000 1.42.2.32 +++ captcha.module 19 Sep 2007 17:12:08 -0000 @@ -3,9 +3,11 @@ /** * @file - * This module enables basic captcha functionality: - * adminstrators can add a captcha to desired forms that users without - * the 'skip captcha' permission (typically anonymous visitors) have to solve. + * This module enables basic CAPTCHA functionality: + * adminstrators can add a CAPTCHA to desired forms that users without + * the 'skip CAPTCHA' permission (typically anonymous visitors) have + * to solve. + * */ define('CAPTCHA_UNSOLVED_CHALLENGES_MAX', 20); @@ -20,7 +22,7 @@ define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SU function captcha_help($section = 'admin/help#captcha') { switch ($section) { case 'admin/help#captcha': - $output = '

'. t('A CAPTCHA is a tool to fight automated spam submission of forms (e.g. user registration forms, comment forms, guestbook forms, etc.) by malicious users. A CAPTCHA is an extra field (or several fields) on a form presented to the user. It represents a challenge, which should be easy for a normal human to solve (e.g. a simple math problem), but hard enough to keep automated scripts and spam bots out.') .'

'; + $output .= '

'. t('"CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart". It is typically a challenge-response test to determine whether the user is human. The CAPTCHA module is a tool to fight automated submission by malicious users (spamming) of for example comments forms, user registration forms, guestbook forms, etc. You can extend the desired forms with an additional question or challenge, which should be easy for a human to solve correctly, but hard enough to keep automated scripts and spam bots out.') .'

'; $output .= '

'. t('Note that CAPTCHA interacts with page caching (see performance settings). Because a CAPTCHA should be a unique challenge for each generated form, the caching of the page it appears on is prevented. Make sure that the CAPTCHA enabled forms do not appear on too many pages or you will lose much caching efficiency. For example, if you put a CAPTCHA on the user login block, which typically appears on each page for anonymous visitors, caching will practically be disabled. Another example are the comment submission forms. If untrusted users can post comments (with CAPTCHA protection), you should set the "%commentlocation" to "%separatepage" in the comment settings. for better caching efficiency.' , array( '!performancesettings' => url('admin/settings/performance'), @@ -29,18 +31,18 @@ function captcha_help($section = 'admin/ '!commentsettings' => url('admin/content/comment/settings'), ) ) .'

'; + $output .= '

'. t('CAPTCHA is a trademark of Carnegie Mellon University.') .'

'; return $output; case 'admin/user/captcha': case 'admin/user/captcha/captcha': case 'admin/user/captcha/captcha/settings': - return t('

A captcha can be added to virtually each drupal form (which is identified by a form_id). The captcha module comes with some default forms to add a captcha to, but arbitrary forms can be easily added and managed when the option "%adminlinks" is enabled.

Users with the "%skipcaptcha" permission won\'t be offered a captcha. Be sure to grant this permission to the trusted users (e.g. site administrators). If you want to test the captcha challenges, be sure to do it as a user without the "%skipcaptcha" permission (e.g. as unauthenticated user).

', + return t('

A CAPTCHA can be added to virtually each Drupal form (which is identified by a form_id). The CAPTCHA module comes with some default forms to add a CAPTCHA to, but arbitrary forms can be easily added and managed when the option "%adminlinks" is enabled.

Users with the "%skipcaptcha" permission won\'t be offered a CAPTCHA. Be sure to grant this permission to the trusted users (e.g. site administrators). If you want to test a CAPTCHA, be sure to do it as a user without the "%skipcaptcha" permission (e.g. as anonymous user).

', array( '@perm' => url('admin/user/access'), - '%adminlinks' => t('Add captcha adminstration links to forms'), - '%skipcaptcha' => 'skip captcha challenges', + '%adminlinks' => t('Add CAPTCHA adminstration links to forms'), + '%skipcaptcha' => 'skip CAPTCHA', )); } - return $output; } /** @@ -49,20 +51,20 @@ function captcha_help($section = 'admin/ function captcha_menu($may_cache) { $items = array(); if ($may_cache) { - // main configuration page of the basic captcha module + // main configuration page of the basic CAPTCHA module $items[] = array( 'path' => 'admin/user/captcha', - 'title' => t('Captcha'), - 'description' => t('Administer how and where Captchas are used.'), + 'title' => t('CAPTCHA'), + 'description' => t('Administer how and where CAPTCHAs are used.'), 'callback' => 'captcha_admin', - 'access' => user_access('administer captcha'), + 'access' => user_access('administer CAPTCHA settings'), 'type' => MENU_NORMAL_ITEM, ); - // the default local task (needed when other modules want to offer alternative - // captcha challenges and their own configuration page as local task) + // the default local task (needed when other modules want to offer + // alternative CAPTCHA types and their own configuration page as local task) $items[] = array( 'path' => 'admin/user/captcha/captcha', - 'title' => t('Captcha'), + 'title' => t('CAPTCHA'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -20, ); @@ -75,7 +77,7 @@ function captcha_menu($may_cache) { $items[] = array( 'path' => 'admin/user/captcha/captcha/examples', 'title' => t('Examples'), - 'description' => t('An overview of the available captcha types with examples.'), + 'description' => t('An overview of the available CAPTCHA types with examples.'), 'callback' => 'captcha_examples', 'type' => MENU_LOCAL_TASK, 'weight' => 5, @@ -88,32 +90,32 @@ function captcha_menu($may_cache) { * Implementation of hook_perm(). */ function captcha_perm() { - return array('administer captcha', 'skip captcha challenges'); + return array('administer CAPTCHA settings', 'skip CAPTCHA'); } /** - * Return an array with the available captcha types, for use as options array + * Return an array with the available CAPTCHA types, for use as options array * for a select form elements. - * The array is an associative array mapping "$module/$challenge" to - * "$module/$challenge" with $module the module name implementing the captcha - * challenge and $challenge the name of the challenge type. + * The array is an associative array mapping "$module/$type" to + * "$module/$type" with $module the module name implementing the CAPTCHA + * and $type the name of the CAPTCHA type. * (It also includes a 'none' => 'none' option) */ function _captcha_available_challenge_types(){ - $captcha_challenges['none'] = 'none'; + $captcha_types['none'] = 'none'; foreach(module_implements('captcha') as $module) { $result = call_user_func_array($module .'_captcha', 'list'); if (is_array($result)) { - foreach($result as $challenge) { - $captcha_challenges["$module/$challenge"] = "$challenge ($module)"; + foreach($result as $type) { + $captcha_types["$module/$type"] = "$type ($module)"; } } } - return $captcha_challenges; + return $captcha_types; } /** - * Get the description which appears above the captcha in forms. + * Get the description which appears above the CAPTCHA in forms. * If the locale module is enabled, an optional language code can be given */ function _captcha_get_description($lang_code=NULL) { @@ -131,80 +133,80 @@ function _captcha_get_description($lang_ } /** - * General Captcha settings handler. Main entry point for captcha management + * General CAPTCHA settings handler. Main entry point for CAPTCHA management. * * If arguments are given: first argument is used as form_id, the second one * is interpreted as action (such as disable, delete and enable) to execute on * the form_id. - * Otherwise: returns the general captcha configuration form. + * Otherwise: returns the general CAPTCHA configuration form. */ function captcha_admin($form_id='', $op='') { // if $form_id and action $op given: do the action if ($form_id) { switch ($op) { case 'disable': - // disable the captcha for the form: set the module and type to NULL + // disable the CAPTCHA for the form: set the module and type to NULL db_query("UPDATE {captcha_points} SET module = NULL, type = NULL WHERE form_id = '%s'", $form_id); - drupal_set_message(t('Disabled captcha for form %form_id.', array('%form_id'=>$form_id))); - // goto the captcha adminstration or alternative destination if present in URI + drupal_set_message(t('Disabled CAPTCHA for form %form_id.', array('%form_id'=>$form_id))); + // goto the CAPTCHA adminstration or alternative destination if present in URI drupal_goto('admin/user/captcha'); break; case 'delete': db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id); - drupal_set_message(t('Deleted captcha for form %form_id.', array('%form_id'=>$form_id))); - // goto the captcha adminstration or alternative destination if present in URI + drupal_set_message(t('Deleted CAPTCHA for form %form_id.', array('%form_id'=>$form_id))); + // goto the CAPTCHA adminstration or alternative destination if present in URI drupal_goto('admin/user/captcha'); break; case 'enable': db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id); db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id); - // No drupal_goto() call because we have to go to the captcha adminstration + // No drupal_goto() call because we have to go to the CAPTCHA adminstration // form and not a different destination if that would be present in the // URI. So we call this form explicitly. The destination will be preserved // so after completing the form, the user will still be redirected. return drupal_get_form('captcha_captcha_point_settings_form', $form_id); break; } - // return edit form for individual form (aka captcha point) + // return edit form for individual form (aka CAPTCHA point) return drupal_get_form('captcha_captcha_point_settings_form', $form_id); } - // no $form_id or legal action given: generate general captcha settings form + // no $form_id or legal action given: generate general CAPTCHA settings form return drupal_get_form('captcha_admin_settings'); } /** - * Form builder function for the general captcha configuration + * Form builder function for the general CAPTCHA configuration */ function captcha_admin_settings() { - // field for the captcha adminstration mode + // field for the CAPTCHA adminstration mode $form['captcha_administration_mode'] = array( '#type' => 'checkbox', - '#title' => t('Add captcha adminstration links to forms'), + '#title' => t('Add CAPTCHA adminstration links to forms'), '#default_value' => variable_get('captcha_administration_mode', FALSE), - '#description' => t('This option is very helpful to enable/disable captchas on forms. When enabled, users with the "%admincaptcha" permission will see captcha administration links on all forms (except on administrative pages, which shouldn\'t be accessible to untrusted users in the first place).', array('%admincaptcha' => 'administer captcha')), + '#description' => t('This option is very helpful to enable/disable CAPTCHAs on forms. When enabled, users with the "%admincaptcha" permission will see CAPTCHA administration links on all forms (except on administrative pages, which shouldn\'t be accessible to untrusted users in the first place). These links make it possible to enable/disable a CAPTCHA and configure the CAPTCHA type.', array('%admincaptcha' => 'administer CAPTCHA settings')), ); - // field set with form_id -> captcha type configuration + // field set with form_id -> CAPTCHA type configuration $form['captcha_types'] = array( '#type' => 'fieldset', - '#title' => t('Select captcha types'), - '#description' => t('Select what kind of captcha challenge you want for each form.'), + '#title' => t('CAPTCHA configuration per form'), + '#description' => t('Select what kind of CAPTCHA you want for each available form. You can easily add arbitrary forms with the help of the \'%CAPTCHA_admin_links\' option.', array('%CAPTCHA_admin_links'=>t('Add CAPTCHA adminstration links to forms.'))), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => FALSE, '#theme' => 'captcha_admin_settings_captcha_points', ); // list all possible form_id's - $captcha_challenges = _captcha_available_challenge_types(); + $captcha_types = _captcha_available_challenge_types(); $result = db_query("SELECT * FROM {captcha_points} ORDER BY form_id"); while ($captcha_point = db_fetch_object($result)) { $form['captcha_types'][$captcha_point->form_id]['form_id'] = array( '#value' => $captcha_point->form_id, ); - // select widget for captcha type + // select widget for CAPTCHA type $form['captcha_types'][$captcha_point->form_id]['captcha_type'] = array( '#type' => 'select', '#default_value' => "{$captcha_point->module}/{$captcha_point->type}", - '#options' => $captcha_challenges, + '#options' => $captcha_types, ); // additional operations $form['captcha_types'][$captcha_point->form_id]['operations'] = array( @@ -213,19 +215,19 @@ function captcha_admin_settings() { )) ); } - // field(s) for setting the additional captcha description + // field(s) for setting the additional CAPTCHA description if (module_exists('locale')) { global $locale; $langs = locale_supported_languages(); $form['captcha_descriptions'] = array( '#type' => 'fieldset', - '#title' => t('Captcha description'), - '#description' => t('With this description you can explain the purpose of the captcha challenge to the user.'), + '#title' => t('CAPTCHA description'), + '#description' => t('With this description you can explain the purpose of the CAPTCHA to the user.'), ); foreach ($langs['name'] as $lang_code => $lang_name) { $form['captcha_descriptions']["captcha_description_$lang_code"] = array( '#type' => 'textfield', - '#title' => t('Captcha description for %lang_name (locale %lang_code)', array('%lang_name'=>$lang_name, '%lang_code'=>$lang_code)), + '#title' => t('For language %lang_name (code %lang_code)', array('%lang_name'=>$lang_name, '%lang_code'=>$lang_code)), '#default_value' => _captcha_get_description($lang_code), '#maxlength' => 256, ); @@ -233,14 +235,14 @@ function captcha_admin_settings() { } else { $form['captcha_description'] = array( - '#type' => 'textfield', - '#title' => t('Captcha description'), - '#description' => t('With this description you can explain the purpose of the captcha challenge to the user.'), - '#default_value' => _captcha_get_description(), - '#maxlength' => 256, - ); + '#type' => 'textfield', + '#title' => t('CAPTCHA description'), + '#description' => t('With this description you can explain the purpose of the CAPTCHA to the user.'), + '#default_value' => _captcha_get_description(), + '#maxlength' => 256, + ); } - // field for captcha persistence + // field for CAPTCHA persistence $form['captcha_persistence'] = array( '#type' => 'radios', '#title' => t('CAPTCHA persistence'), @@ -261,7 +263,7 @@ function captcha_admin_settings() { } /** - * Custom theme function for a table of (form_id -> captcha type) settings + * Custom theme function for a table of (form_id -> CAPTCHA type) settings */ function theme_captcha_admin_settings_captcha_points($form) { foreach (element_children($form) as $key) { @@ -271,7 +273,7 @@ function theme_captcha_admin_settings_ca $row[] = drupal_render($form[$key]['operations']); $rows[] = $row; } - $header = array('form_id', t('Captcha type (module)'), t('Operations')); + $header = array('form_id', t('CAPTCHA type (module)'), t('Operations')); $output = theme('table', $header, $rows); return $output; } @@ -302,12 +304,12 @@ function captcha_admin_settings_submit($ variable_set('captcha_description', $form_values['captcha_description']); } variable_set('captcha_persistence', $form_values['captcha_persistence']); - drupal_set_message(t('Your captcha settings were saved.'), 'status'); + drupal_set_message(t('The CAPTCHA settings were saved.'), 'status'); } } /** - * form generating function for captcha point settings + * form generating function for CAPTCHA point settings */ function captcha_captcha_point_settings_form($form_id) { $result = db_query("SELECT * FROM {captcha_points} WHERE form_id = '%s'", $form_id); @@ -318,7 +320,7 @@ function captcha_captcha_point_settings_ '#type' => 'hidden', '#value' => $captcha_point->form_id, ); - // select widget for captcha type + // select widget for CAPTCHA type $form['captcha_type'] = array( '#type' => 'select', '#title' => t('Select the CAPTCHA for @form_id', array('@form_id'=>$form_id)), @@ -340,7 +342,7 @@ function captcha_captcha_point_settings_ else { // illegal form_id drupal_set_message(t('Unavailable form_id %form_id ', array('%form_id'=>$form_id)), 'error'); - // goto the captcha adminstration or alternative destination if present in URI + // goto the CAPTCHA adminstration or alternative destination if present in URI drupal_goto('admin/user/captcha'); } } @@ -377,14 +379,15 @@ function _captcha_persistence_skip($form /** * Implementation of hook_form_alter(). * - * This function adds a captcha to forms for untrusted users if needed and adds - * captcha adminstration links for site adminstrators if this option is enabled. + * This function adds a CAPTCHA to forms for untrusted users if needed and adds + * CAPTCHA adminstration links for site adminstrators if this option is enabled. */ function captcha_form_alter($form_id, &$form) { - if (!user_access('skip captcha challenges')) { - // Visitor does not have permission to skip the captcha challenge - // Get captcha type and module for this form. Return if no captcha was set. + if (!user_access('skip CAPTCHA')) { + // Visitor does not have permission to skip the CAPTCHA + + // Get CAPTCHA type and module for this form. Return if no CAPTCHA was set. $result = db_query("SELECT module, type FROM {captcha_points} WHERE form_id = '%s'", $form_id); if (!$result) { return; @@ -401,45 +404,45 @@ function captcha_form_alter($form_id, &$ global $conf; $conf['cache'] = FALSE; - // Do not present captcha if not captcha-persistent and user has already solved a captcha for this form + // Do not present CAPTCHA if not CAPTCHA-persistent and user has already solved a CAPTCHA for this form if (_captcha_persistence_skip($form_id)) { return; } - // Generate a captcha challenge and its solution + // Generate a CAPTCHA and its solution $captcha = module_invoke($captcha_point->module, 'captcha', 'generate', $captcha_point->type); if (!$captcha) { //The selected module returned nothing, maybe it is disabled or it's wrong, we should watchdog that and then quit. - watchdog('captcha', - t('Captcha problem: hook_captcha() of module %module returned nothing when trying to retrieve captcha type %type for form %form_id.', + watchdog('CAPTCHA', + t('CAPTCHA problem: hook_captcha() of module %module returned nothing when trying to retrieve CAPTCHA type %type for form %form_id.', array('%type' => $captcha_point->type, '%module' => $captcha_point->module, '%form_id'=> $form_id)), WATCHDOG_ERROR); return; } - // Add a captcha part to the form (depends on value of captcha_description) + // Add a CAPTCHA part to the form (depends on value of captcha_description) $captcha_description = _captcha_get_description(); if ($captcha_description) { - // $captcha_description is not empty: captcha part is a fieldset with description + // $captcha_description is not empty: CAPTCHA part is a fieldset with description $form['captcha'] = array( '#type' => 'fieldset', - '#title' => t('Captcha'), + '#title' => t('CAPTCHA'), '#description' => $captcha_description, ); } else { - // $captcha_description is empty: captcha part is an empty markup form element + // $captcha_description is empty: CAPTCHA part is an empty markup form element $form['captcha'] = array(); } - // Add the form elements of the generated captcha challenge to the form + // Add the form elements of the generated CAPTCHA to the form $form['captcha'] = array_merge($form['captcha'], $captcha['form']); - // Store the solution of the generated captcha challenge as an internal form value. + // Store the solution of the generated CAPTCHA as an internal form value. // This will be stored later in $_SESSION during the pre_render phase. // It can't be saved at this point because hook_form_alter is not only run // before form rendering, but also before form validation (which happens - // in a new (POST) request. Consequently the right captcha solution would be + // in a new (POST) request. Consequently the right CAPTCHA solution would be // overwritten just before validation. The pre_render functions are not run // before validation and are the right place to store the solution in $_SESSION. $form['captcha']['captcha_solution'] = array ( @@ -447,9 +450,9 @@ function captcha_form_alter($form_id, &$ '#value' => $captcha['solution'], ); - // The captcha token is used to differentiate between different instances + // The CAPTCHA token is used to differentiate between different instances // of the same form. This makes it possible to request the same form a - // couple of times before submitting them. The solution of the captcha of + // couple of times before submitting them. The solution of the CAPTCHA of // each of these form instances will be stored at the pre_render phase in // $_SESSION['captcha'][$form_id][$captcha_token] $form['captcha']['captcha_token'] = array ( @@ -471,12 +474,12 @@ function captcha_form_alter($form_id, &$ // handle the pre_render functions $form['#pre_render'] = ((array) $form['#pre_render']) + array('captcha_pre_render', 'captcha_pre_render_place_captcha'); - // Add a validation function for the captcha part of the form + // Add a validation function for the CAPTCHA part of the form $form['captcha']['#validate'] = ((array) $form['captcha']['#validate']) + array('captcha_validate' => array()); } - elseif (user_access('administer captcha') && variable_get('captcha_administration_mode', FALSE) && arg(0) != 'admin') { - // For administrators: show captcha info and offer link to configure it + elseif (user_access('administer CAPTCHA settings') && variable_get('captcha_administration_mode', FALSE) && arg(0) != 'admin') { + // For administrators: show CAPTCHA info and offer link to configure it $result = db_query("SELECT module, type FROM {captcha_points} WHERE form_id = '%s'", $form_id); if (!$result) { return; @@ -485,24 +488,26 @@ function captcha_form_alter($form_id, &$ if ($captcha_point->type) { $form['captcha'] = array( '#type' => 'item', - '#title' => t('Captcha administration'), - '#description' => t('The captcha "@type" (by module "@module") is enabled here for untrusted users: !edit, !disable or !general.', array( + '#title' => t('CAPTCHA administration'), + '#description' => t('The CAPTCHA "@type" (by module "@module") is enabled here for untrusted users: !edit, !disable or !general.', array( '@type' => $captcha_point->type, '@module' => $captcha_point->module, - '!edit' => l(t('edit captcha type'), "admin/user/captcha/$form_id", array(), drupal_get_destination()), - '!disable' => l(t('disable captcha'), "admin/user/captcha/$form_id/disable", array(), drupal_get_destination()), - '!general' => l(t('general captcha settings'), "admin/user/captcha"), + '!edit' => l(t('edit CAPTCHA type'), "admin/user/captcha/$form_id", array(), drupal_get_destination()), + '!disable' => l(t('disable CAPTCHA'), "admin/user/captcha/$form_id/disable", array(), drupal_get_destination()), + '!edit' => l(t('edit CAPTCHA type'), "admin/user/captcha/$form_id", array(), drupal_get_destination()), + '!disable' => l(t('disable CAPTCHA'), "admin/user/captcha/$form_id/disable", array(), drupal_get_destination()), + '!general' => l(t('edit general CAPTCHA settings'), "admin/user/captcha"), )) ); } else { $form['captcha'] = array( '#type' => 'item', - '#title' => t('Captcha administration'), - '#description' => l(t('Place a captcha challenge here for untrusted users.'), "admin/user/captcha/$form_id/enable", array(), drupal_get_destination()), + '#title' => t('CAPTCHA administration'), + '#description' => l(t('Place a CAPTCHA here for untrusted users.'), "admin/user/captcha/$form_id/enable", array(), drupal_get_destination()), ); } - // Add pre_render function for placing the captcha just above the submit button + // Add pre_render function for placing the CAPTCHA just above the submit button $form['#pre_render'] = ((array) $form['#pre_render']) + array('captcha_pre_render_place_captcha'); } } @@ -521,7 +526,7 @@ function captcha_validate($form_values) $captcha_token = $form_values['#post']['captcha_token']; // Check if captcha_token exists if (!isset($_SESSION['captcha'][$form_id][$captcha_token])) { - form_set_error('captcha_token', t('Invalid captcha token.')); + form_set_error('captcha_token', t('Invalid CAPTCHA token.')); } // Check answer if ($captcha_response === $_SESSION['captcha'][$form_id][$captcha_token]) { @@ -529,7 +534,7 @@ function captcha_validate($form_values) $_SESSION['captcha']['success'] = TRUE; } else { - form_set_error('captcha_response', t('The answer you entered for the captcha challenge was not correct.')); + form_set_error('captcha_response', t('The answer you entered for the CAPTCHA was not correct.')); // If CAPTCHA was on a login form: stop validating, quit the current request // and forward to the current page (like a reload) to prevent loging in. // We do that because the log in procedure, which happens after @@ -540,9 +545,9 @@ function captcha_validate($form_values) } } - // Unset the solution to prevent reuse of the same captcha solution + // Unset the solution to prevent reuse of the same CAPTCHA solution // by a spammer that repeats posting a form without requesting - // (and thus rendering) a new form. Note that a new captcha solution is only + // (and thus rendering) a new form. Note that a new CAPTCHA solution is only // set at the pre_render phase. unset($_SESSION['captcha'][$form_id][$captcha_token]); } @@ -550,35 +555,35 @@ function captcha_validate($form_values) /** * Implementation of form #pre_render. * - * The main purpose of this function is to store the solution of the captcha - * challenge in the $_SESSION variable. + * The main purpose of this function is to store the solution of the CAPTCHA + * in the $_SESSION variable. */ function captcha_pre_render($form_id, &$form) { - // Unset the captcha challenge if non-captcha persistent and the captcha has + // Unset the CAPTCHA if non-CAPTCHA persistent and the CAPTCHA has // already been successfully solved for this form. // This needs to be done in this pre_render phase when previewing for example // nodes and comments before submission. // On submission of such a forms for preview, captcha_form_alter() is called - // *before* the captcha validation function (which sets + // *before* the CAPTCHA validation function (which sets // $_SESSION['captcha'][$form_id]['success'] to TRUE on a correctly answered - // captcha). After this the form_values are entered in the generated form + // CAPTCHA). After this the form_values are entered in the generated form // and this form is presented with the preview. - // This means that captcha_form_alter() can't know if the captcha was - // correctly answered and consequently adds a captcha challenge to the form. + // This means that captcha_form_alter() can't know if the CAPTCHA was + // correctly answered and consequently adds a CAPTCHA to the form. // The pre_render phase happens after the validation phase and makes it - // possible to remove the captcha from the form after all. + // possible to remove the CAPTCHA from the form after all. if (_captcha_persistence_skip($form_id)) { unset($form['captcha']); return; } - // count the number of unsolved captcha challenges and flush those if too many + // count the number of unsolved CAPTCHAs and flush those if too many // minus 1 is needed because 'success' is also an item of $_SESSION['captcha'][$form_id] if (count($_SESSION['captcha'][$form_id]) - 1 > CAPTCHA_UNSOLVED_CHALLENGES_MAX) { unset($_SESSION['captcha'][$form_id]); - drupal_set_message(t('You can\'t request more than @num captcha challenges without solving them. Your previous captcha challenges were flushed.', array('@num' => CAPTCHA_UNSOLVED_CHALLENGES_MAX))); + drupal_set_message(t('You can\'t request more than @num CAPTCHAs without solving them. Your previous CAPTCHA were flushed.', array('@num' => CAPTCHA_UNSOLVED_CHALLENGES_MAX))); } - // store the current captcha solution in $_SESSION + // store the current CAPTCHA solution in $_SESSION $captcha_token = $form['captcha']['captcha_token']['#value']; $_SESSION['captcha'][$form_id][$captcha_token] = $form['captcha']['captcha_solution']['#value']; $_SESSION['captcha'][$form_id]['success'] = FALSE; @@ -587,7 +592,7 @@ function captcha_pre_render($form_id, &$ } /** - * Pre_render function to place the captcha form element just above the last submit button + * Pre_render function to place the CAPTCHA form element just above the last submit button */ function captcha_pre_render_place_captcha($form_id, &$form) { // search the weights of the buttons in the form @@ -598,7 +603,7 @@ function captcha_pre_render_place_captch } } if ($button_weights) { - // set the weight of the captcha element a tiny bit smaller than the lightest button weight + // set the weight of the CAPTCHA element a tiny bit smaller than the lightest button weight // (note that the default resolution of #weight values is 1/1000 (see drupal/includes/form.inc)) $first_button_weight = min($button_weights); $form['captcha']['#weight'] = $first_button_weight - 0.5/1000.0; @@ -608,18 +613,18 @@ function captcha_pre_render_place_captch } /** - * Funtion for generating a page with captcha challenge 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 challenge types. + * examples of the available CAPTCHA types. * If $module and $challenge are set, generate 10 examples of the concerning - * challenge. + * CAPTCHA. */ function captcha_examples($module=NULL, $challenge=NULL) { if ($module && $challenge) { // generate 10 examples $output = ''; for ($i=0; $i<10; $i++) { - // generate captcha challenge + // generate CAPTCHA $captcha = call_user_func_array($module .'_captcha', array('generate', $challenge)); $form = $captcha['form']; $id = "captcha_examples_$module_$challenge_$i"; @@ -628,24 +633,24 @@ function captcha_examples($module=NULL, } } else { - // generate a list with examples of the available challenges - $output = t('This page gives an overview of all available captcha types, generated with their current settings.'); + // generate a list with examples of the available CAPTCHA types + $output = t('This page gives an overview of all available CAPTCHA types, generated with their current settings.'); foreach(module_implements('captcha') as $module) { $challenges = call_user_func_array($module .'_captcha', 'list'); if ($challenges) { - foreach($challenges as $challenge) { - // generate captcha challenge + 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)), + '#title' => t('CAPTCHA "%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 captcha type.'), "admin/user/captcha/captcha/examples/$module/$challenge"), + '#value' => l(t('10 more examples of this CAPTCHA type.'), "admin/user/captcha/captcha/examples/$module/$challenge"), ); // return rendered form $id = "captcha_examples_$module_$challenge";