diff options
Diffstat (limited to 'modules/akismet')
| -rw-r--r-- | modules/akismet/controllers/admin_akismet.php | 11 | ||||
| -rw-r--r-- | modules/akismet/helpers/akismet.php | 17 | 
2 files changed, 12 insertions, 16 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); +      } +    }    } | 
