Exemplo n.º 1
0
 public function index()
 {
     $form = akismet::get_configure_form();
     if (request::method() == "post") {
         // @todo move the "post" handler part of this code into a separate function
         access::verify_csrf();
         $valid = $form->validate();
         if ($valid) {
             $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."));
             } else {
                 if ($old_key && $new_key && $old_key != $new_key) {
                     message::success(t("Your Akismet key has been changed."));
                 } else {
                     if (!$old_key && $new_key) {
                         message::success(t("Your Akismet key has been saved."));
                     }
                 }
             }
             log::success("akismet", t("Akismet key changed to {$new_key}"));
             module::set_var("akismet", "api_key", $new_key);
             akismet::check_config();
             url::redirect("admin/akismet");
         } else {
             $valid_key = false;
         }
     } else {
         $valid_key = module::get_var("akismet", "api_key") ? 1 : 0;
     }
     akismet::check_config();
     $view = new Admin_View("admin.html");
     $view->content = new View("admin_akismet.html");
     $view->content->valid_key = $valid_key;
     $view->content->form = $form;
     print $view;
 }