From 47c9307c62b1ea444c9798f0002c56fd0da87a59 Mon Sep 17 00:00:00 2001 From: Brandon Holtsclaw Date: Thu, 8 Dec 2011 00:50:46 -0600 Subject: [PATCH] updating captcha module support, addresses http://drupal.org/node/562318 --- ajax.js | 4 + plugins/captcha/ajax_captcha.module | 83 ++++++++++---------- plugins/captcha/patches/captcha.module.patch | 34 ++++---- 3 files changed, 64 insertions(+), 57 deletions(-) diff --git a/ajax.js b/ajax.js index 5662ef7..1d9f51a 100755 --- a/ajax.js +++ b/ajax.js @@ -212,6 +212,10 @@ Drupal.Ajax.updater = function(updaters) { else if(updaters[i].type === 'remove') { elm.remove(); } + // HIDE + else if(updaters[i].type === 'hide') { + elm.hide(); + } } return true; }; diff --git a/plugins/captcha/ajax_captcha.module b/plugins/captcha/ajax_captcha.module index 7f25c21..bbd4f48 100755 --- a/plugins/captcha/ajax_captcha.module +++ b/plugins/captcha/ajax_captcha.module @@ -46,60 +46,59 @@ function ajax_captcha_ajax_validate_pass(&$form, &$form_state, &$data, &$pass) { * @param $data Assoc * @return Bool */ + function ajax_captcha_process(&$form, &$form_state, &$data) { - //$data['debug'] = 'A'; + //print_r($data); if (array_key_exists('captcha_token', $form_state['values']) && array_key_exists('captcha_type', $form_state['values']) && array_key_exists('captcha_query', $form_state['values'])) { //$data['debug'] .= 'B'; - // COnditional show - if (_captcha_persistence_skip($form['form_id']['#value'])) { + // Conditional show + if (_captcha_required_for_user($form_state['values']['captcha_sid'], $form_id) == NULL) { $data['updaters'][] = array( - 'type' => 'remove', + 'type' => 'hide', 'selector' => 'fieldset.captcha', 'value' => NULL ); //$data['debug'] .= 'C'; } - // ALways Show - else { - //$data['debug'] .= 'D'; - // MATH - if ($form_state['values']['captcha_type'] === 'math') { - $selector = - "#edit-captcha-response-wrapper .field-prefix"; - $type = 'html_in'; - //$data['debug'] .= 'E'; - } - elseif ($form_state['values']['captcha_type'] === 'text') { - $selector = - "#edit-captcha-response-wrapper label[for='edit-captcha-response']"; - $type = 'html_in'; - //$data['debug'] .= 'F'; - } - elseif ($form_state['values']['captcha_type'] === 'image') { - $selector = - ".captcha img"; - $type = 'html_out'; - //$data['debug'] .= 'G'; - } - $data['updaters'][] = array( - 'type' => 'field', - 'selector' => '#edit-captcha-token', - 'value' => $form_state['values']['captcha_token'] - ); - $data['updaters'][] = array( - 'type' => $type, - 'selector' => $selector, - 'value' => $form_state['values']['captcha_query'] - ); - $data['updaters'][] = array( - 'type' => 'field', - 'selector' => '#edit-captcha-response', - 'value' => '' - ); - captcha_pre_render($form); + //$data['debug'] .= 'D'; + // MATH + if ($form_state['values']['captcha_type'] === 'math') { + $selector = + "#edit-captcha-response-wrapper .field-prefix"; + $type = 'html_in'; + //$data['debug'] .= 'E'; + } + elseif ($form_state['values']['captcha_type'] === 'text') { + $selector = + "#edit-captcha-response-wrapper label[for='edit-captcha-response']"; + $type = 'html_in'; + //$data['debug'] .= 'F'; + } + elseif ($form_state['values']['captcha_type'] === 'image') { + $selector = + ".captcha img"; + $type = 'html_out'; + //$data['debug'] .= 'G'; } + $data['updaters'][] = array( + 'type' => 'field', + 'selector' => '#edit-captcha-token', + 'value' => $form_state['values']['captcha_token'] + ); + $data['updaters'][] = array( + 'type' => $type, + 'selector' => $selector, + 'value' => $form_state['values']['captcha_query'] + ); + $data['updaters'][] = array( + 'type' => 'field', + 'selector' => '#edit-captcha-response', + 'value' => '' + ); + theme_captcha($form); } + return TRUE; } diff --git a/plugins/captcha/patches/captcha.module.patch b/plugins/captcha/patches/captcha.module.patch index 61956cc..623cfca 100755 --- a/plugins/captcha/patches/captcha.module.patch +++ b/plugins/captcha/patches/captcha.module.patch @@ -1,22 +1,23 @@ ---- captcha.module.orig 2008-11-14 02:28:11.000000000 -0800 -+++ captcha.module 2008-11-14 03:02:59.000000000 -0800 -@@ -240,7 +240,14 @@ function captcha_form_alter(&$form, $for - '#type' => 'value', - '#value' => $captcha['solution'], - ); -- -+ $form['captcha']['captcha_query'] = array( +diff --git a/captcha.module b/captcha.module +index 19744a1..0ff5179 100644 +--- a/captcha.module ++++ b/captcha.module +@@ -365,6 +365,14 @@ function captcha_form_alter(&$form, $form_state, $form_id) { + '#type' => 'captcha', + '#captcha_type' => $captcha_point->module .'/'. $captcha_point->captcha_type, + ); ++ $captcha_element['captcha_query'] = array( + '#type' => 'value', + '#value' => $captcha['query'] + ); -+ $form['captcha']['captcha_type'] = array( ++ $captcha_element['captcha_type'] = array( + '#type' => 'value', + '#value' => $captcha['type'] + ); - // 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 -@@ -446,12 +453,15 @@ function captcha_captcha($op, $captcha_t + // Add a CAPTCHA description if required. + if (variable_get('captcha_add_captcha_description', TRUE)) { + $captcha_element['#description'] = _captcha_get_description(); +@@ -705,7 +713,10 @@ function captcha_captcha($op, $captcha_type = '') { $answer = mt_rand(1, 20); $x = mt_rand(1, $answer); $y = $answer - $x; @@ -24,9 +25,12 @@ $result['solution'] = "$answer"; + $result['query'] = $query; + $result['type'] = 'math'; - $result['form']['captcha_response'] = array( + // Build challenge widget. + // Note that we also use t() for the math challenge itself. This makes + // it possible to 'rephrase' the challenge a bit through localization +@@ -714,7 +725,7 @@ function captcha_captcha($op, $captcha_type = '') { '#type' => 'textfield', - '#title' => t('Math Question'), + '#title' => t('Math question'), '#description' => t('Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.'), - '#field_prefix' => t('@x + @y = ', array('@x' => $x, '@y' => $y)), + '#field_prefix' => $query,