summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/comment/helpers/comment.php6
-rw-r--r--modules/recaptcha/controllers/admin_recaptcha.php5
-rw-r--r--modules/recaptcha/helpers/recaptcha.php59
-rw-r--r--modules/recaptcha/views/admin_recaptcha.html.php1
4 files changed, 24 insertions, 47 deletions
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index ce9ddcbe..82b4f4b0 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -77,6 +77,9 @@ class comment_Core {
$group->input("url") ->label(t("Website (hidden)"))->id("gUrl");
$group->textarea("text")->label(t("Comment")) ->id("gText");
$group->hidden("item_id")->value($item->id);
+ if (module::is_installed("recaptcha")) {
+ $group->recaptcha("recaptcha")->label("")->id("gRecaptcha");
+ }
$group->submit("")->value(t("Add"));
$active = user::active();
@@ -100,6 +103,9 @@ class comment_Core {
$group->input("email") ->label(t("Email (hidden)")) ->id("gEmail");
$group->input("url") ->label(t("Website (hidden)"))->id("gUrl");
$group->textarea("text")->label(t("Comment")) ->id("gText");
+ if (module::is_installed("recaptcha")) {
+ $group->recaptcha("recaptcha")->label("")->id("gRecaptcha");
+ }
$group->submit("")->value(t("Edit"));
$group->text = $comment->text;
diff --git a/modules/recaptcha/controllers/admin_recaptcha.php b/modules/recaptcha/controllers/admin_recaptcha.php
index 10938187..23fd8ad3 100644
--- a/modules/recaptcha/controllers/admin_recaptcha.php
+++ b/modules/recaptcha/controllers/admin_recaptcha.php
@@ -26,7 +26,10 @@ class Admin_Recaptcha_Controller extends Admin_Controller {
$valid_key = $form->validate();
if ($valid_key) {
- $valid_key = recaptcha::is_recaptcha_valid($form,
+ $input = Input::instance();
+ $challenge = $input->post("recaptcha_challenge_field", "", true);
+ $response = $input->post("recaptcha_response_field", "", true);
+ $valid_key = recaptcha::is_recaptcha_valid($challenge, $response,
$form->configure_recaptcha->private_key->value);
if (empty($valid_key) && $form->captcha_error == "invalid-site-private-key") {
$form->configure_recaptcha->private_key->add_error("invalid", 1);
diff --git a/modules/recaptcha/helpers/recaptcha.php b/modules/recaptcha/helpers/recaptcha.php
index 1d40eb09..662b98d7 100644
--- a/modules/recaptcha/helpers/recaptcha.php
+++ b/modules/recaptcha/helpers/recaptcha.php
@@ -18,18 +18,6 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class recaptcha_Core {
- /**
- * The reCAPTCHA server URL"s
- */
- const API_SERVER = "http://api.recaptcha.net";
- const API_SECURE_SERVER = "https://api-secure.recaptcha.net";
- const VERIFY_SERVER = "api-verify.recaptcha.net";
-
- /**
- * RecaptchaOptions
- */
- private $options = array();
-
static function get_configure_form() {
$form = new Forge("admin/recaptcha", "", "post", array("id" => "gConfigureRecaptchaForm"));
$group = $form->group("configure_recaptcha")
@@ -49,8 +37,6 @@ class recaptcha_Core {
$group->submit("")->value(t("Save"));
$site_domain = urlencode(stripslashes($_SERVER["HTTP_HOST"]));
- $form->recaptcha_site = self::API_SERVER;
- $form->recaptcha_ssl_site = self::API_SECURE_SERVER;
$form->get_key_url = "http://recaptcha.net/api/getkey?domain=$site_domain&app=Gallery3";
return $form;
}
@@ -72,63 +58,46 @@ class recaptcha_Core {
* Gets the challenge HTML (javascript and non-javascript version).
* This is called from the browser, and the resulting reCAPTCHA HTML widget
* is embedded within the HTML form it was called from.
- * @param string $pubkey The public key to use in the challenge
* @param string $error The error given by reCAPTCHA (optional, default is null)
- * @param boolean $use_ssl Should the request be made over ssl? (optional, default is false)
- * @param string $lang Any supported language code
+ * @param string $pubkey The public key to use in the challenge (optional, default is null)
* @return string - The HTML to be embedded in the user"s form.
*/
- static function get_challenge_html($pubkey, $error = NULL, $use_ssl = false) {
- if (empty($pubkey)) {
- throw new Exception("@todo NEED KEY <a href=\"http://recaptcha.net/api/getkey\">" .
- "http://recaptcha.net/api/getkey</a>");
- }
-
- $lang = Kohana::config("locale.root_locale");
- $server = $use_ssl ? self::API_SECURE_SERVER : self::API_SERVER;
- $errorpart = "";
- if ($error) {
- $errorpart = "&amp;error=". $error;
- }
- return (count(self::$options) > 0 ? "<script type=\"text/javascript\">" .
- "var RecaptchaOptions = {lang:'$lang'};</script>" : "") .
- "<script type=\"text/javascript\" src=\"$server/challenge?k=" .
- "{$pubkey}$errorpart \"></script>";
+ static function get_challenge_html($id, $error=null, $public_key=null ) {
}
/**
* Form validation call back for captcha validation
* @param string $form
- * @return true if valid, false if not
+ * @return string error message or null
*/
- static function is_recaptcha_valid($form, $private_key=null) {
+ static function is_recaptcha_valid($challenge, $response, $private_key=null) {
+ if (!module::installed("recaptcha")) {
+ return null;
+ }
$input = Input::instance();
if (empty($private_key)) {
$private_key = module::get_var("recaptcha", "private_key");
}
- $remoteip = $_SERVER["REMOTE_ADDR"] ;
- $challenge = $input->post("recaptcha_challenge_field", "", true);
- $response = $input->post("recaptcha_response_field", "", true);
+ $remoteip = $input->server("REMOTE_ADDR");
//discard spam submissions
if (empty($challenge) || empty($response)) {
- $form->captcha_error = "incorrect-captcha-sol";
- return false;
+ return "incorrect-captcha-sol";
}
- $response = self::_http_post(self::VERIFY_SERVER, "/verify",
+ $response = self::_http_post("api-verify.recaptcha.net", "/verify",
array ("privatekey" => $private_key,
"remoteip" => $remoteip,
"challenge" => $challenge,
"response" => $response));
+ Kohana::log("debug", print_r($response, 1));
+ Kohana::log("debug", print_r(debug_backtrace(), 1));
$answers = explode ("\n", $response [1]);
if (trim ($answers [0]) == "true") {
- return true;
+ return null;
} else {
- $form->captcha_error = $answers[1];
- Kohana::log("debug", print_r($answers, 1));
- return false;
+ return $answers[1];
}
}
diff --git a/modules/recaptcha/views/admin_recaptcha.html.php b/modules/recaptcha/views/admin_recaptcha.html.php
index 64266d20..e4f00e00 100644
--- a/modules/recaptcha/views/admin_recaptcha.html.php
+++ b/modules/recaptcha/views/admin_recaptcha.html.php
@@ -1,7 +1,6 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<script type="text/javascript" src="http://api.recaptcha.net/js/recaptcha_ajax.js"></script>
<script>
-var site = (document.location.protocol == "http:") ? "<?= $form->recaptcha_site ?>" : "<?= $form->recaptcha_ssl_site ?>";
var RecaptchaOptions = {lang: 'en', theme: "white"};
$("#gConfigureRecaptchaForm").ready(function() {