{image}
{instructions_visual}{instructions_audio} {input}
{refresh_btn} {visual_challenge}{audio_challenge} {help_btn}
'; var $validation_error_message = 'It was not entered the correct text.'; var $key = ''; var $private_key = ''; var $valid = 0; var $widget = ''; var $challenge = ''; var $response = ''; var $text = array( 'instructions_visual'=>'Enter the words above', 'instructions_audio'=>'Enter the numbers you hear', 'visual_challenge'=>'Enter text in an image instead', 'audio_challenge'=>'Enter numbers you hear instead', 'refresh_btn'=>'Try another', 'help_btn'=>'Help', 'play_again'=>'Play the sound again', 'cant_hear_this'=>'Download the sound as a MP3 file', 'image_alt_text'=>'Image with text to enter' ); var $tab_index = ''; Function CheckRequirements() { if(!class_exists('http_class')) return('the HTTP class to access the Recaptcha server is not available'); return(''); } Function AddInput(&$form, $arguments) { if(strlen($error = $this->CheckRequirements())) return($error); if(!IsSet($arguments['Key']) || strlen($arguments['Key']) != 40) return('it was not specified a valid Recaptcha public key'); $this->key = $arguments['Key']; if(!IsSet($arguments['PrivateKey']) || strlen($arguments['PrivateKey']) != 40) return('it was not specified a valid Recaptcha private key'); $this->private_key = $arguments['PrivateKey']; if(IsSet($arguments['ValidationErrorMessage'])) { if(strlen($arguments['ValidationErrorMessage'])) $this->validation_error_message = $arguments['ValidationErrorMessage']; else return('it was not specified a valid validation error message'); } if(IsSet($arguments['Text'])) { if(GetType($text = $arguments['Text']) != 'array') return('it was not specified a valid array with Recaptcha text definitions'); Reset($text); $tt = count($text); for($t = 0; $t < $tt; ++$t) { $k = Key($text); if(!IsSet($this->text[$k])) return($k.' is not a supported reCAPTCHA text definition'); $this->text[$k] = $text[$k]; Next($text); } } Reset($this->text); $this->widget = $this->GenerateInputID($form, $this->input, 'widget'); $this->challenge = 'recaptcha_challenge_field'; $this->focus_input = $this->response = 'recaptcha_response_field'; $input_arguments = array( 'NAME'=>$this->challenge, 'TYPE'=>'textarea', 'COLS'=>40, 'ROWS'=>3 ); if(strlen($error = $form->AddInput($input_arguments))) return($error); $input_arguments = array( 'NAME'=>$this->response, 'ID'=>$this->response, 'TYPE'=>'text', 'ValidateAsNotEmpty'=>1, 'ValidationErrorMessage'=>$this->validation_error_message, 'ONKEYPRESS'=>'return(event.keyCode!=13)' ); if(IsSet($arguments['DependentValidation'])) $input_arguments['DependentValidation'] = $arguments['DependentValidation']; if(IsSet($arguments['InputClass'])) $input_arguments['CLASS'] = $arguments['InputClass']; if(IsSet($arguments['InputStyle'])) $input_arguments['STYLE'] = $arguments['InputStyle']; if(IsSet($arguments['InputTabIndex'])) $this->tab_index = $input_arguments['TABINDEX'] = $arguments['InputTabIndex']; if(IsSet($arguments['InputExtraAttributes'])) $input_arguments['ExtraAttributes'] = $arguments['InputExtraAttributes']; if(strlen($error = $form->AddInput($input_arguments))) return($error); if(IsSet($arguments['Format'])) $this->format = $arguments['Format']; $this->valid_marks = array( 'input'=>array( 'input'=>$this->response, ), 'data'=>array( 'image'=>'
', 'instructions_visual'=>''.HtmlSpecialChars($this->text['instructions_visual']).'', 'instructions_audio'=>''.HtmlSpecialChars($this->text['instructions_audio']).'', 'refresh_btn'=>''.HtmlSpecialChars($this->text['refresh_btn']).'', 'audio_challenge'=>''.HtmlSpecialChars($this->text['audio_challenge']).'', 'visual_challenge'=>''.HtmlSpecialChars($this->text['visual_challenge']).'', 'help_btn'=>''.HtmlSpecialChars($this->text['help_btn']).'' ) ); return ''; } Function LoadInputValues(&$form, $submitted) { if(!$submitted) return(''); $http = new http_class; $http->timeout = 60; $http->data_timeout = 60; $http->debug = 0; $http->log_debug = 1; $http->html_debug = 0; $error = $http->GetRequestArguments('http://www.google.com/recaptcha/api/verify', $arguments); $arguments['RequestMethod'] = 'POST'; $arguments['PostValues'] = array( 'privatekey'=>$this->private_key, 'remoteip'=>GetEnv('REMOTE_ADDR'), 'challenge'=>$form->GetInputValue($this->challenge), 'response'=>$form->GetInputValue($this->response), ); if(strlen($error = $http->Open($arguments))) return('recaptcha-not-reachable: '.$error); if(strlen($error = $http->SendRequest($arguments)) == 0) $error = $http->ReadWholeReplyBody($response); $http->Close(); if(strlen($error)) return('recaptcha-not-reachable: '.$error); $this->valid = !strcmp(strtok($response,"\n"), 'true'); if(!$this->valid) { switch($error = strtok("\n")) { case 'incorrect-captcha-sol': break; case 'invalid-site-private-key': return($error.': the specified reCAPTCHA private key is incorrect'); case 'invalid-request-cookie': return($error.': the reCAPTCHA challenge parameter is corrupted'); case 'recaptcha-not-reachable': return($error.': it was not possible to access the reCAPTCHA server'); default: return($error.': not yet supported reCAPTCHA error'); } } return(''); } Function ValidateInput(&$form) { return($this->valid ? '' : $this->validation_error_message); } Function AddInputPart(&$form) { if(strlen($error = $form->AddDataPart(''))) return($error); return(''); } }; ?>