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 class recaptcha extends Plugin
44 function __construct($public_key, $private_key, $display_errors=false)
46 parent::__construct();
47 require_once(INSTALLDIR.'/plugins/recaptcha/recaptchalib.php');
48 $this->public_key = $public_key;
49 $this->private_key = $private_key;
50 $this->display_errors = $display_errors;
54 if(common_config('site', 'ssl') === 'sometimes' || common_config('site', 'ssl') === 'always') {
60 function onStartShowHTML($action)
62 //XXX: Horrible hack to make Safari, FF2, and Chrome work with
63 //reChapcha. reChapcha beaks xhtml strict
64 header('Content-Type: text/html');
66 $action->extraHeaders();
68 $action->startXML('html');
70 $action->raw('<style type="text/css">#recaptcha_area{float:left;}</style>');
74 function onEndRegistrationFormData($action)
76 $action->elementStart('li');
77 $action->raw('<label for="recaptcha_area">Captcha</label>');
78 if($this->checkssl() === true){
79 $action->raw(recaptcha_get_html($this->public_key), null, true);
81 $action->raw(recaptcha_get_html($this->public_key));
83 $action->elementEnd('li');
87 function onStartRegistrationTry($action)
89 $resp = recaptcha_check_answer ($this->private_key,
90 $_SERVER["REMOTE_ADDR"],
91 $action->trimmed('recaptcha_challenge_field'),
92 $action->trimmed('recaptcha_response_field'));
96 if($this->display_errors)
98 $action->showForm ("(reCAPTCHA said: " . $resp->error . ")");
100 $action->showForm("Captcha does not match!");