summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/recaptcha/helpers/recaptcha.php106
1 files changed, 52 insertions, 54 deletions
diff --git a/modules/recaptcha/helpers/recaptcha.php b/modules/recaptcha/helpers/recaptcha.php
index 74601250..b2d223df 100644
--- a/modules/recaptcha/helpers/recaptcha.php
+++ b/modules/recaptcha/helpers/recaptcha.php
@@ -22,8 +22,6 @@ class recaptcha_Core {
$form = new Forge("admin/recaptcha", "", "post", array("id" => "gConfigureRecaptchaForm"));
$group = $form->group("configure_recaptcha")
->label(t("Configure Recaptcha"));
- $group->hidden("orig_public_key")
- ->value(module::get_var());
$group->input("public_key")
->label(t("Public Key"))
->value(module::get_var("recaptcha", "public_key"));
@@ -52,11 +50,11 @@ class recaptcha_Core {
}
}
- /**
+ /**
* Verify that the recaptcha key is valid.
* @param string $private_key
* @return boolean
- */
+ */
static function verify_key($private_key) {
$remote_ip = Input::instance()->server("REMOTE_ADDR");
$response = self::_http_post("api-verify.recaptcha.net", "/verify",
@@ -72,75 +70,75 @@ class recaptcha_Core {
return $answers[1];
}
}
-
- /**
+
+ /**
* Form validation call back for captcha validation
* @param string $form
* @return string error message or null
- */
+ */
static function is_recaptcha_valid($challenge, $response, $private_key) {
$input = Input::instance();
$remote_ip = $input->server("REMOTE_ADDR");
- //discard spam submissions
- if (empty($challenge) || empty($response)) {
+ //discard spam submissions
+ if (empty($challenge) || empty($response)) {
return "incorrect-captcha-sol";
- }
+ }
- $response = self::_http_post("api-verify.recaptcha.net", "/verify",
- array ("privatekey" => $private_key,
+ $response = self::_http_post("api-verify.recaptcha.net", "/verify",
+ array ("privatekey" => $private_key,
"remoteip" => $remote_ip,
- "challenge" => $challenge,
- "response" => $response));
+ "challenge" => $challenge,
+ "response" => $response));
- $answers = explode ("\n", $response [1]);
- if (trim ($answers [0]) == "true") {
- return null;
+ $answers = explode ("\n", $response [1]);
+ if (trim ($answers [0]) == "true") {
+ return null;
} else {
return $answers[1];
- }
+ }
}
- /**
- * Encodes the given data into a query string format
- * @param $data - array of string elements to be encoded
- * @return string - encoded request
- */
- private static function _encode(array $data){
+ /**
+ * Encodes the given data into a query string format
+ * @param $data - array of string elements to be encoded
+ * @return string - encoded request
+ */
+ private static function _encode(array $data){
$req = array();
- foreach ($data as $key => $value){
- $req[] = "$key=" . urlencode(stripslashes($value));
- }
- return implode("&", $req);
+ foreach ($data as $key => $value){
+ $req[] = "$key=" . urlencode(stripslashes($value));
+ }
+ return implode("&", $req);
}
- /**
- * Submits an HTTP POST to a reCAPTCHA server
- * @param string $host
- * @param string $path
- * @param array $data
- * @param int port
- * @return array response
- */
- private static function _http_post($host, $path, $data, $port = 80) {
- $req = self::_encode($data);
- $http_request = "POST $path HTTP/1.0\r\n";
- $http_request .= "Host: $host\r\n";
- $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
- $http_request .= "Content-Length: " . strlen($req) . "\r\n";
- $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
- $http_request .= "\r\n";
- $http_request .= $req;
- $response = "";
- if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
- throw new Exception("@todo COULD NOT OPEN SOCKET");
- }
- fwrite($fs, $http_request);
- while (!feof($fs)) {
+ /**
+ * Submits an HTTP POST to a reCAPTCHA server
+ * @param string $host
+ * @param string $path
+ * @param array $data
+ * @param int port
+ * @return array response
+ */
+ private static function _http_post($host, $path, $data, $port = 80) {
+ $req = self::_encode($data);
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
+ $http_request .= "Content-Length: " . strlen($req) . "\r\n";
+ $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $req;
+ $response = "";
+ if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
+ throw new Exception("@todo COULD NOT OPEN SOCKET");
+ }
+ fwrite($fs, $http_request);
+ while (!feof($fs)) {
$response .= fgets($fs, 1160); // One TCP-IP packet
}
- fclose($fs);
- $response = explode("\r\n\r\n", $response, 2);
- return $response;
+ fclose($fs);
+ $response = explode("\r\n\r\n", $response, 2);
+ return $response;
}
}