Newer
Older
* @version 1.0
* @copyright 2011
* @Author : Enmask.com
*/
class EnmaskCaptcha {
private $protocol;
private $server;
private $port;
public function EnmaskCaptcha() {
$this->protocol = "http://";
$this->server = "enmask.com";
$this->port = "";
}
public function getHtml($name) {
global $language;
$lang_code = $language->language;
if ($lang_code != '') {
$js_append = 'data-enmask-langcode="' . $lang_code . '"';
}
else {
$js_append = '';
}
$url = $this->protocol . $this->server . $this->port . "/Scripts/Enmask.Captcha.js";
return '<script type="text/javascript" ' . $js_append . ' src="' . $url . '" data-enmask="true" data-enmask-name="' . $name . '"></script>';
}
/*
* Validating by posting data in enmask server using drupal_http_request.
*/
public function validate($captchaResponse, $captchaChallenge) {
$url = $this->protocol . $this->server . $this->port . "/CaptchaFont/ValidateCaptcha";
$headers = array('Content-Type' => 'application/x-www-form-urlencoded');
$data = array(
'response' => $captchaResponse,
'challenge' => $captchaChallenge);
$buffer = drupal_http_request($url, array('headers' => array('Content-Type' => 'application/x-www-form-urlencoded'), 'method' => 'POST', 'data' => http_build_query($data, '', '&')));
$result = json_decode($buffer->data);
// Return message will be from the enmask server.
return array($result->isValid, t('Captcha you entered was not valid.'));