summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2011-09-22 20:36:17 -0700
committerLuke Shumaker <lukeshu@sbcglobal.net>2011-09-22 20:36:17 -0700
commitd9043d59d9109a0fb8350b9829806b7cab910425 (patch)
tree699ccc284e3e9a6105987fa3b31f332c2329e6e2 /src/plugins
parent98f65a9b001382720d16b34c18256c20410a627c (diff)
parentdb3cb85d0992dd49ca2fdf33ea35c0cad60e312f (diff)
Merge branch 'master' of https://git.gitorious.org/messagemanager/messagemanager
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/ReCaptcha.class.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/plugins/ReCaptcha.class.php b/src/plugins/ReCaptcha.class.php
index c25147f..165493b 100644
--- a/src/plugins/ReCaptcha.class.php
+++ b/src/plugins/ReCaptcha.class.php
@@ -1,4 +1,6 @@
<?php
+// We only include the recaptchalib.php file when we use it because we don't
+// want it polluting the global namespace thing.
class ReCaptcha extends Plugin {
protected $config = array('public_key'=>'',
@@ -11,4 +13,35 @@ class ReCaptcha extends Plugin {
'private_key'=>'text');
}
public function init() {}
+
+ private $resp = null;
+ private function getResp() {
+ if ($this->resp===null) {
+ require_once('recaptchalib.php');
+ @$response = $_POST['recaptcha_response_field'];
+ @$challenge = $_POST['recaptcha_challenge_field'];
+ $this->resp = recaptcha_check_answer($this->config['private_key'],
+ $_SERVER['REMOTE_ADDR'],
+ $challenge,
+ $response);
+ }
+ return $this->resp;
+ }
+
+ private function getError() {
+ if ($_POST["recaptcha_response_field"] && !$this->antispam_verify()) {
+ return $this->getResp()->error;
+ } else {
+ return false;
+ }
+ }
+
+ public function antispam_verify() {
+ return $this->getResp()->is_valid;
+ }
+
+ public function antispam_html() {
+ require_once('recaptchalib.php');
+ return recaptcha_get_html($this->config['public_key'], $this->getError());
+ }
}