" . self::$_signupUrl . ""); } $this->_secret = $secret; } /** * Encodes the given data into a query string format. * * @param array $data array of string elements to be encoded. * * @return string - encoded request. */ private function _encodeQS($data) { $req = ''; foreach ($data as $key => $value) { $req .= $key . '=' . urlencode(stripslashes($value)) . '&'; } // Cut the last '&' return substr($req, 0, strlen($req) - 1); } /** * Submits an HTTP GET to a reCAPTCHA server. * * @param string $path URL path to recaptcha server. * @param array $data array of parameters to be sent. * * @return mixed JSON string or false on error */ private function _submitHTTPGet($path, $data) { $req = $this->_encodeQS($data); try { $http = JHttpFactory::getHttp(); $result = $http->get($path . '?' . $req)->body; } catch (RuntimeException $e) { return false; } return $result; } /** * Calls the reCAPTCHA siteverify API to verify whether the user passes * CAPTCHA test. * * @param string $remoteIp IP address of end user. * @param string $response response string from recaptcha verification. * * @return JReCaptchaResponse */ public function verifyResponse($remoteIp, $response) { // Discard empty solution submissions if ($response === null || $response === '') { $recaptchaResponse = new JReCaptchaResponse(); $recaptchaResponse->success = false; $recaptchaResponse->errorCodes = 'missing-input'; return $recaptchaResponse; } $getResponse = $this->_submitHttpGet( self::$_siteVerifyUrl, array( 'secret' => $this->_secret, 'remoteip' => $remoteIp, 'v' => self::$_version, 'response' => $response ) ); // Something is broken in submiting the http get request if ($getResponse === false) { $recaptchaResponse->success = false; } $answers = json_decode($getResponse, true); $recaptchaResponse = new JReCaptchaResponse(); if (trim($answers['success']) !== '') { $recaptchaResponse->success = true; } else { $recaptchaResponse->success = false; $recaptchaResponse->errorCodes = isset($answers['error-codes']) ? $answers['error-codes'] : ''; } return $recaptchaResponse; } }