diff -N -r -u captcha_pack.orig/question_captcha/question_captcha.admin.inc captcha_pack/question_captcha/question_captcha.admin.inc --- captcha_pack.orig/question_captcha/question_captcha.admin.inc 1969-12-31 18:00:00 -0600 +++ captcha_pack/question_captcha/question_captcha.admin.inc 2009-05-14 10:21:55 -0500 @@ -0,0 +1,40 @@ + 'textfield', + '#title' => t('Question to ask the user.'), + '#default_value' => variable_get('question_captcha_question', 'Replace this with a question specific to your expected users.'), + ); + $form['question_captcha_answer'] = array( + '#type' => 'textfield', + '#title' => t('Answer to the asked question.'), + '#default_value' => variable_get('question_captcha_answer', NULL), + ); + $form['question_captcha_case_insensitive'] = array( + '#type' => 'checkbox', + '#title' => t('Case insensitive validation'), + '#default_value' => variable_get('question_captcha_case_insensitive', TRUE), + ); + $form['question_captcha_regex'] = array( + '#type' => 'checkbox', + '#title' => t('Regular Expression validation'), + '#default_value' => variable_get('question_captcha_regex', FALSE), + ); + + $form['#validate'] = array('question_captcha_settings_form_validate'); + return system_settings_form($form); +} + +/** + * Validation function + */ +function question_captcha_settings_form_validate($form, &$form_state) { + if (empty($form_state['values']['question_captcha_answer'])) { + form_set_error('question_captcha_answer', t('You must enter in an answer.')); + } +} diff -N -r -u captcha_pack.orig/question_captcha/question_captcha.info captcha_pack/question_captcha/question_captcha.info --- captcha_pack.orig/question_captcha/question_captcha.info 1969-12-31 18:00:00 -0600 +++ captcha_pack/question_captcha/question_captcha.info 2009-05-14 10:21:55 -0500 @@ -0,0 +1,5 @@ +name = "QUESTION CAPTCHA" +description = "Provides a CAPTCHA type that asks questions for the user to answer." +package = "Spam control" +dependencies[] = captcha +core = 6.x diff -N -r -u captcha_pack.orig/question_captcha/question_captcha.install captcha_pack/question_captcha/question_captcha.install --- captcha_pack.orig/question_captcha/question_captcha.install 1969-12-31 18:00:00 -0600 +++ captcha_pack/question_captcha/question_captcha.install 2009-05-14 10:21:55 -0500 @@ -0,0 +1,9 @@ +'. t('The QUESTION CAPTCHA asks a single question to the user, expecting a specific answer.') .'

' ; + } +} + +/** + * Implementation of hook_menu(). + */ +function question_captcha_menu() { + $items = array(); + $items['admin/user/captcha/question_captcha'] = array( + 'title' => 'QUESTION CAPTCHA', + 'file' => 'question_captcha.admin.inc', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('question_captcha_settings_form'), + 'access arguments' => array('administer CAPTCHA settings'), + 'type' => MENU_LOCAL_TASK, + ); + return $items; +} + +/** + * Implementation of hook_captcha() + */ +function question_captcha_captcha($op, $captcha_type='', $response='') { + switch ($op) { + case 'list': + return array("QUESTION CAPTCHA"); + case 'generate': + if ($captcha_type == "QUESTION CAPTCHA") { + // get settings + $question_to_ask = variable_get('question_captcha_question', NULL); + + if (variable_get('question_captcha_case_insensitive', TRUE)) { + $answer_to_question = strtolower(variable_get('question_captcha_answer', NULL)); + } else { + $answer_to_question = variable_get('question_captcha_answer', NULL); + } + + // build form + $captcha = array(); + + // If using a regex, then the solution will be either TRUE or FALSE depending on what ereg() returns + if (variable_get('question_captcha_regex', FALSE)) { + $captcha['solution'] = "TRUE"; + } else { + $captcha['solution'] = $answer_to_question; + } + + $captcha['form']['captcha_response'] = array( + '#type' => 'textfield', + '#title' => t($question_to_ask), + '#required' => TRUE, + ); + + $captcha['preprocess'] = TRUE; + return $captcha; + + } + case 'preprocess': + if ($captcha_type == 'QUESTION CAPTCHA') { + if (variable_get('question_captcha_case_insensitive', TRUE)) { + $response = strtolower($response); + } + + // If the regex passes return either TRUE or FALSE, otherwise return the actual response + if (variable_get('question_captcha_regex', FALSE)) { + if (variable_get('question_captcha_case_insensitive', TRUE)) { + $regular_expression = strtolower(variable_get('question_captcha_answer', NULL)); + } else { + $regular_expression = variable_get('question_captcha_answer', NULL); + } + + if (!empty($regular_expression) && ereg($regular_expression, $response)){ + return "TRUE"; + } else { + return "FALSE"; + } + } else { + return $response; + } + } + break; + + break; + } +}