3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to show reCaptcha when a user registers
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Eric Helgeson <erichelgeson@gmail.com>
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 define('RECAPTCHA', '0.2');
36 require_once(INSTALLDIR.'/plugins/Recaptcha/recaptchalib.php');
38 class RecaptchaPlugin extends Plugin
46 function onInitializePlugin(){
47 if(!isset($this->private_key)) {
48 common_log(LOG_ERR, 'Recaptcha: Must specify private_key in config.php');
50 if(!isset($this->public_key)) {
51 common_log(LOG_ERR, 'Recaptcha: Must specify public_key in config.php');
56 if(common_config('site', 'ssl') === 'sometimes' || common_config('site', 'ssl') === 'always') {
63 function onEndRegistrationFormData($action)
65 $action->style('#recaptcha_area{float:left;}');
66 $action->elementStart('li');
67 $action->raw('<label for="recaptcha_area">Captcha</label>');
68 if($this->checkssl() === true) {
69 $action->raw(recaptcha_get_html($this->public_key), null, true);
71 $action->raw(recaptcha_get_html($this->public_key));
73 $action->elementEnd('li');
77 function onStartRegistrationTry($action)
79 $resp = recaptcha_check_answer ($this->private_key,
80 $_SERVER["REMOTE_ADDR"],
81 $action->trimmed('recaptcha_challenge_field'),
82 $action->trimmed('recaptcha_response_field'));
84 if (!$resp->is_valid) {
85 if($this->display_errors) {
86 $action->showForm ("(reCAPTCHA error: " . $resp->error . ")");
88 $action->showForm("Captcha does not match!");