summaryrefslogtreecommitdiff
path: root/modules/recaptcha/helpers
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-01-25 16:35:25 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-01-25 16:35:25 +0000
commit4bb2c53c8ff99a879aaffb90338a92d56cf65e28 (patch)
treee2dac1bee54b8ede2a8696503fd1114fe30e5b35 /modules/recaptcha/helpers
parent1633001d7fddbb5fd5baa0a774041e001d8e7723 (diff)
Added the ability to identify and present the defined forms to the
adminstrator. The forms are presented as a checklist, I would have preferred a selection list, but Forge doesn't have one. The generated html to contain the recaptcha challenge is defined as <ul> as that was the only way to force itto line up.
Diffstat (limited to 'modules/recaptcha/helpers')
-rw-r--r--modules/recaptcha/helpers/recaptcha.php36
1 files changed, 34 insertions, 2 deletions
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;
+ }
}