|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
You may not change or alter any portion of this comment or credits |
|
4
|
|
|
of supporting developers from this source code or any supporting source code |
|
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
6
|
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
|
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* CAPTCHA for Recaptcha mode |
|
14
|
|
|
* |
|
15
|
|
|
* PHP 5.3 |
|
16
|
|
|
* |
|
17
|
|
|
* @category Xoops\Class\Captcha\CaptchaRecaptcha |
|
18
|
|
|
* @package CaptchaRecaptcha |
|
19
|
|
|
* @author trabis <[email protected]> |
|
20
|
|
|
* @copyright 2013 XOOPS Project (http://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
22
|
|
|
* @version $Id$ |
|
23
|
|
|
* @link http://xoops.org |
|
24
|
|
|
* @since 2.6.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
class XoopsCaptchaRecaptcha extends XoopsCaptchaMethod |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* XoopsCaptchaRecaptcha::isActive() |
|
30
|
|
|
* |
|
31
|
|
|
* @return bool |
|
32
|
|
|
*/ |
|
33
|
1 |
|
public function isActive() |
|
34
|
|
|
{ |
|
35
|
1 |
|
return true; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* XoopsCaptchaRecaptcha::render() |
|
40
|
|
|
* |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function render() |
|
44
|
|
|
{ |
|
45
|
1 |
|
include_once __DIR__ . '/recaptcha/recaptchalib.php'; |
|
46
|
|
|
$form = "<script type=\"text/javascript\"> |
|
47
|
|
|
var RecaptchaOptions = { |
|
48
|
1 |
|
theme : '" . (empty($this->config['theme']) ? '' : $this->config['theme']) . "', |
|
49
|
1 |
|
lang : '" . (empty($this->config['lang']) ? '' : $this->config['lang']) . "' |
|
50
|
|
|
}; |
|
51
|
|
|
</script>"; |
|
52
|
1 |
|
$public_key = empty($this->config['public_key']) ? '' : $this->config['public_key']; |
|
53
|
1 |
|
$form .= recaptcha_get_html($public_key); |
|
54
|
1 |
|
return $form; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* XoopsCaptchaRecaptcha::verify() |
|
59
|
|
|
* |
|
60
|
|
|
* @param $sessionName name of session |
|
61
|
|
|
* @return bool |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function verify($sessionName = null) |
|
64
|
|
|
{ |
|
65
|
2 |
|
$is_valid = false; |
|
66
|
2 |
|
include_once __DIR__ . '/recaptcha/recaptchalib.php'; |
|
67
|
2 |
|
if (!empty($_POST['recaptcha_response_field'])) { |
|
68
|
1 |
|
$resp = recaptcha_check_answer($this->config['private_key'], $_SERVER['REMOTE_ADDR'], |
|
69
|
1 |
|
$_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); |
|
70
|
1 |
|
if (!$resp->is_valid) { |
|
71
|
1 |
|
$this->handler->message[] = $resp->error; |
|
72
|
|
|
} else { |
|
73
|
|
|
$is_valid = true; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
2 |
|
return $is_valid; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|