diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2010-01-29 11:39:22 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2010-01-29 11:39:22 -0800 |
commit | e4d9ea3394ee2db82d9dee6c6ed78543fd0f78fb (patch) | |
tree | 85759cfef46cc1df79a1ddf3225dce8809b9121a | |
parent | 1bc0d05760df7bff5cee0a330b5b7181b3c49835 (diff) | |
parent | 660130cf1ab9fd6cb051712b57966b191064a6a6 (diff) |
Merge branch 'master' of git@github.com:gallery/gallery3
Conflicts:
modules/gallery/views/in_place_edit.html.php
-rw-r--r-- | modules/akismet/controllers/admin_akismet.php | 11 | ||||
-rw-r--r-- | modules/akismet/helpers/akismet.php | 17 | ||||
-rw-r--r-- | modules/digibug/views/digibug_form.html.php | 2 | ||||
-rw-r--r-- | modules/gallery/libraries/InPlaceEdit.php | 1 | ||||
-rw-r--r-- | modules/gallery/views/in_place_edit.html.php | 8 | ||||
-rw-r--r-- | modules/recaptcha/controllers/admin_recaptcha.php | 2 | ||||
-rw-r--r-- | modules/recaptcha/helpers/recaptcha.php | 40 |
7 files changed, 41 insertions, 40 deletions
diff --git a/modules/akismet/controllers/admin_akismet.php b/modules/akismet/controllers/admin_akismet.php index ca3a1473..4847db53 100644 --- a/modules/akismet/controllers/admin_akismet.php +++ b/modules/akismet/controllers/admin_akismet.php @@ -25,17 +25,8 @@ class Admin_Akismet_Controller extends Admin_Controller { // @todo move the "post" handler part of this code into a separate function access::verify_csrf(); - $valid = $form->validate(); - - if ($valid) { + if ($form->validate()) { $new_key = $form->configure_akismet->api_key->value; - if ($new_key && !akismet::validate_key($new_key)) { - $form->configure_akismet->api_key->add_error("invalid", 1); - $valid = false; - } - } - - if ($valid) { $old_key = module::get_var("akismet", "api_key"); if ($old_key && !$new_key) { message::success(t("Your Akismet key has been cleared.")); diff --git a/modules/akismet/helpers/akismet.php b/modules/akismet/helpers/akismet.php index 46a305b2..b4405de5 100644 --- a/modules/akismet/helpers/akismet.php +++ b/modules/akismet/helpers/akismet.php @@ -23,8 +23,9 @@ class akismet_Core { static function get_configure_form() { $form = new Forge("admin/akismet", "", "post", array("id" => "g-configure-akismet-form")); $group = $form->group("configure_akismet")->label(t("Configure Akismet")); - $group->input("api_key")->label(t("API Key"))->value(module::get_var("akismet", "api_key")); - $group->api_key->error_messages("invalid", t("The API key you provided is invalid.")); + $group->input("api_key")->label(t("API Key"))->value(module::get_var("akismet", "api_key")) + ->callback("akismet::validate_key") + ->error_messages("invalid", t("The API key you provided is invalid.")); $group->submit("")->value(t("Save")); return $form; } @@ -82,10 +83,14 @@ class akismet_Core { * @param string $api_key the API key * @return boolean */ - static function validate_key($api_key) { - $request = self::_build_verify_request($api_key); - $response = self::_http_post($request, "rest.akismet.com"); - return "valid" == $response->body[0]; + static function validate_key($api_key_input) { + if ($api_key_input->value) { + $request = self::_build_verify_request($api_key_input->value); + $response = self::_http_post($request, "rest.akismet.com"); + if ("valid" != $response->body[0]) { + $api_key_input->add_error("invalid", 1); + } + } } diff --git a/modules/digibug/views/digibug_form.html.php b/modules/digibug/views/digibug_form.html.php index c6994cbe..f7b34e16 100644 --- a/modules/digibug/views/digibug_form.html.php +++ b/modules/digibug/views/digibug_form.html.php @@ -3,7 +3,7 @@ <body> <?= form::open("http://www.digibug.com/dapi/order.php") ?> <?= form::hidden($order_parms) ?> - <?= form::close() ?> + </form> <script type="text/javascript"> document.forms[0].submit(); </script> diff --git a/modules/gallery/libraries/InPlaceEdit.php b/modules/gallery/libraries/InPlaceEdit.php index 67ab3805..04a2e9a5 100644 --- a/modules/gallery/libraries/InPlaceEdit.php +++ b/modules/gallery/libraries/InPlaceEdit.php @@ -70,7 +70,6 @@ class InPlaceEdit_Core { public function render() { $v = new View("in_place_edit.html"); - $v->hidden = array("csrf" => access::csrf_token()); $v->action = url::site($this->action); $v->form = $this->form; $v->errors = $this->errors; diff --git a/modules/gallery/views/in_place_edit.html.php b/modules/gallery/views/in_place_edit.html.php index ad9ea845..05a16ad4 100644 --- a/modules/gallery/views/in_place_edit.html.php +++ b/modules/gallery/views/in_place_edit.html.php @@ -1,5 +1,5 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<?= form::open($action, array("method" => "post", "id" => "g-in-place-edit-form", "class" => "g-short-form"), $hidden) ?> +<?= form::open($action, array("method" => "post", "id" => "g-in-place-edit-form", "class" => "g-short-form")) ?> <?= access::csrf_form_field() ?> <ul> <li<? if (!empty($errors["input"])): ?> class="g-error"<? endif ?>> @@ -10,8 +10,6 @@ </li> <li><a href="#" class="g-cancel"><?= t("Cancel") ?></a></li> </ul> -</form/> -<? if (!empty($errors["input"])): ?> -<div id="g-in-place-edit-message" class="g-error"><?= $errors["input"] ?></div> -<? endif ?> +</form> + diff --git a/modules/recaptcha/controllers/admin_recaptcha.php b/modules/recaptcha/controllers/admin_recaptcha.php index 6874fce9..0ddb98c1 100644 --- a/modules/recaptcha/controllers/admin_recaptcha.php +++ b/modules/recaptcha/controllers/admin_recaptcha.php @@ -42,7 +42,7 @@ class Admin_Recaptcha_Controller extends Admin_Controller { } else { module::set_var("recaptcha", "public_key", ""); module::set_var("recaptcha", "private_key", ""); - message::success(t("reCAPTCHA disabled!")); + message::success(t("No keys provided. reCAPTCHA is disabled!")); log::success("recaptcha", t("reCAPTCHA public and private keys cleared")); url::redirect("admin/recaptcha"); } diff --git a/modules/recaptcha/helpers/recaptcha.php b/modules/recaptcha/helpers/recaptcha.php index 789bae85..5df22cbc 100644 --- a/modules/recaptcha/helpers/recaptcha.php +++ b/modules/recaptcha/helpers/recaptcha.php @@ -24,12 +24,16 @@ class recaptcha_Core { ->label(t("Configure reCAPTCHA")); $group->input("public_key") ->label(t("Public Key")) - ->value(module::get_var("recaptcha", "public_key")); - $group->public_key->error_messages("invalid", t("The public key you provided is invalid.")); + ->value(module::get_var("recaptcha", "public_key")) + ->rules("required") + ->error_messages("required", t("You must enter a public key")) + ->error_messages("invalid", t("This public key is invalid")); $group->input("private_key") ->label(t("Private Key")) - ->value(module::get_var("recaptcha", "private_key")); - $group->private_key->error_messages("invalid", t("The private key you provided is invalid.")); + ->value(module::get_var("recaptcha", "private_key")) + ->callback("recaptcha::verify_key") + ->error_messages("required", t("You must enter a private key")) + ->error_messages("invalid", t("This private key is invalid")); $group->submit("")->value(t("Save")); $site_domain = urlencode(stripslashes($_SERVER["HTTP_HOST"])); @@ -55,19 +59,23 @@ class recaptcha_Core { * @param string $private_key * @return boolean */ - static function verify_key($private_key) { + static function verify_key($private_key_input) { + if (!$private_key_input->value) { + $private_key_input->add_error("required", 1); + return; + } + $remote_ip = Input::instance()->server("REMOTE_ADDR"); $response = self::_http_post("api-verify.recaptcha.net", "/verify", - array("privatekey" => $private_key, + array("privatekey" => $private_key_input->value, "remoteip" => $remote_ip, "challenge" => "right", "response" => "wrong")); - $answers = explode("\n", $response[1]); - if (trim($answers[0]) == "true") { - return null; - } else { - return $answers[1]; + if ($response[1] == "false\ninvalid-site-private-key") { + // This is the only thing I can figure out how to verify. + // See http://recaptcha.net/apidocs/captcha for possible return values + $private_key_input->add_error("invalid", 1); } } @@ -80,16 +88,16 @@ class recaptcha_Core { $input = Input::instance(); $remote_ip = $input->server("REMOTE_ADDR"); - //discard spam submissions + // 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, - "remoteip" => $remote_ip, - "challenge" => $challenge, - "response" => $response)); + array("privatekey" => $private_key, + "remoteip" => $remote_ip, + "challenge" => $challenge, + "response" => $response)); $answers = explode ("\n", $response [1]); if (trim ($answers [0]) == "true") { |