summaryrefslogtreecommitdiff
path: root/modules/recaptcha/controllers/admin_recaptcha.php
blob: ca3e77ad7054cb707acd5d2284cfa8f0bf978f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php defined("SYSPATH") or die("No direct script access.");
/**
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2008 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */
class Admin_Recaptcha_Controller extends Admin_Controller {
  public function index() {
    $form = recaptcha::get_configure_form();
    if (request::method() == "post") {
      $old_public_key = module::get_var("recaptcha", "public_key");
      $old_private_key = module::get_var("recaptcha", "private_key");
      if ($form->validate()) {
        $public_key = $form->configure_recaptcha->public_key->value;
        $private_key = $form->configure_recaptcha->private_key->value;

        if ($public_key && $private_key) {
          module::set_var("recaptcha", "public_key", $public_key);
          module::set_var("recaptcha", "private_key", $private_key);
          message::success(t("Recaptcha configured!"));
          log::success("recaptcha", t("Recaptcha public and private keys set"));
          url::redirect("admin/recaptcha");
        } else if ($public_key && !$private_key) {
          $form->configure_recaptcha->private_key->add_error("invalid");
        } else if ($private_key && !$public_key) {
          $form->configure_recaptcha->public_key->add_error("invalid");
        } else {
          module::set_var("recaptcha", "public_key", "");
          module::set_var("recaptcha", "private_key", "");
          message::success(t("Recaptcha disabled!"));
          log::success("recaptcha", t("Recaptcha public and private keys cleared"));
          url::redirect("admin/recaptcha");
        }
      }
    }

    recaptcha::check_config();
    $view = new Admin_View("admin.html");
    $view->content = new View("admin_recaptcha.html");
    $view->content->public_key = module::get_var("recaptcha", "public_key");
    $view->content->private_key = module::get_var("recaptcha", "private_key");
    $view->content->form = $form;
    print $view;
  }

  public function test() {
    $view = new View("admin_recaptcha_test.html");
    $view->public_key = module::get_var("recaptcha", "public_key");
    print $view;
  }
}