diff --git a/modules/recaptcha/controllers/admin_recaptcha.php b/modules/recaptcha/controllers/admin_recaptcha.php
index 0f05a82b..5fad6155 100644
--- a/modules/recaptcha/controllers/admin_recaptcha.php
+++ b/modules/recaptcha/controllers/admin_recaptcha.php
@@ -37,11 +37,17 @@ class Admin_Recaptcha_Controller extends Admin_Controller {
$new_public_key = $form->configure_recaptcha->public_key->value;
$new_private_key = $form->configure_recaptcha->private_key->value;
- $updated = false;
- if ($this->_update_key("public_key", $old_public_key, $new_public_key) ||
- $this->_update_key("private_key", $old_private_key, $new_private_key)) {
- message::success(t("Recaptcha Configured"));
+ $this->_update_key("public_key", $old_public_key, $new_public_key);
+ $this->_update_key("private_key", $old_private_key, $new_private_key);
+
+ $add_recaptcha_to = array();
+ foreach ($form->configure_recaptcha->activated_forms->value as $name) {
+ $add_recaptcha_to[$name] = 1;
}
+ module::set_var("recaptcha", "form_list", serialize($add_recaptcha_to));
+ log::success(t("Recaptcha active forms have changed."));
+
+ message::success(t("Recaptcha Configured"));
recaptcha::check_config();
}
} else {
@@ -68,9 +74,8 @@ class Admin_Recaptcha_Controller extends Admin_Controller {
$changed = false;
}
if ($changed) {
- module::set_var("recaptcha", $key, $new_key);
+ module::set_var("recaptcha", $type, $new_key);
}
-
}
public function gethtml($public_key, $error=null) {
diff --git a/modules/recaptcha/helpers/recaptcha.php b/modules/recaptcha/helpers/recaptcha.php
index eea000b1..371b4746 100644
--- a/modules/recaptcha/helpers/recaptcha.php
+++ b/modules/recaptcha/helpers/recaptcha.php
@@ -31,7 +31,7 @@ class recaptcha_Core {
private $options = array();
static function get_configure_form() {
- $form = new Forge("admin/recaptcha", "", "post", array("id" => "gConfigure_Recaptcha_Form"));
+ $form = new Forge("admin/recaptcha", "", "post", array("id" => "gConfigureRecaptchaForm"));
$group = $form->group("configure_recaptcha")
->label(t("Configure Recaptcha"));
$group->hidden("orig_public_key")
@@ -46,6 +46,11 @@ class recaptcha_Core {
->value(module::get_var("recaptcha", "private_key"))
->rules("required|length[40]");
$group->private_key->error_messages("invalid", t("The private key you provided is invalid."));
+
+ $forms_list = self::_get_form_list();
+ $group->checklist("activated_forms")
+ ->label(t("Recaptcha Activated on:"))
+ ->options($forms_list);
$group->submit("")->value(t("Save"));
$site_domain = urlencode(stripslashes($_SERVER["HTTP_HOST"]));
$form->recaptcha_site = self::API_SERVER;
@@ -106,7 +111,6 @@ class recaptcha_Core {
if (empty($private_key)) {
$private_key = module::get_var("recaptcha", "private_key");
}
- Kohana::log("debug", $private_key);
$remoteip = $_SERVER["REMOTE_ADDR"] ;
$challenge = $input->post("recaptcha_challenge_field", "", true);
$response = $input->post("recaptcha_response_field", "", true);
@@ -174,4 +178,32 @@ class recaptcha_Core {
$response = explode("\r\n\r\n", $response, 2);
return $response;
}
+
+ function _get_form_list() {
+ $forms = unserialize(module::get_var("recaptcha", "form_list", "a:0:{}"));
+ Kohana::log("debug", print_r($forms, 1));
+ $form_list = array();
+
+ // @todo Ignore administrative forms
+ foreach (array_merge(glob(APPPATH . "helpers/*"), glob(MODPATH . "*/helpers/*")) as $path) {
+ if (preg_match("#.*/(.*)/helpers/(.*).*\.php$#", $path, $matches)) {
+ Kohana::log("debug", "$path => $matches[1]");
+ if ("recaptcha" == $matches[1]) {
+ continue;
+ }
+ $content = file_get_contents($path);
+
+ $preg_match_all = preg_match_all("#.*\"(g([A-Za-z]*)Form)\"#m",
+ $content, $matches, PREG_SET_ORDER);
+ if ($preg_match_all !== false) {
+ foreach ($matches as $match) {
+ $label = trim(preg_replace("/([A-Z])/", " $1", $match[2]));
+ $form_id = $match[1];
+ $form_list[$form_id] = array($label, !empty($forms[$form_id]));
+ }
+ }
+ }
+ }
+ return $form_list;
+ }
}
diff --git a/modules/recaptcha/views/admin_recaptcha.html.php b/modules/recaptcha/views/admin_recaptcha.html.php
index ebba31d5..64266d20 100644
--- a/modules/recaptcha/views/admin_recaptcha.html.php
+++ b/modules/recaptcha/views/admin_recaptcha.html.php
@@ -2,10 +2,10 @@
");
}
});