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 require_once(INSTALLDIR.'/plugins/Recaptcha/recaptchalib.php');
36 class RecaptchaPlugin extends Plugin
44 function onInitializePlugin(){
45 if(!isset($this->private_key)) {
46 common_log(LOG_ERR, 'Recaptcha: Must specify private_key in config.php');
48 if(!isset($this->public_key)) {
49 common_log(LOG_ERR, 'Recaptcha: Must specify public_key in config.php');
54 if(common_config('site', 'ssl') === 'sometimes' || common_config('site', 'ssl') === 'always') {
61 function onEndRegistrationFormData($action)
63 $action->elementStart('li');
64 $action->raw('<label for="recaptcha">Captcha</label>');
65 if($this->checkssl() === true) {
66 $action->raw(recaptcha_get_html($this->public_key), null, true);
68 $action->raw(recaptcha_get_html($this->public_key));
70 $action->elementEnd('li');
74 function onStartRegistrationTry($action)
76 $resp = recaptcha_check_answer ($this->private_key,
77 $_SERVER["REMOTE_ADDR"],
78 $action->trimmed('recaptcha_challenge_field'),
79 $action->trimmed('recaptcha_response_field'));
81 if (!$resp->is_valid) {
82 if($this->display_errors) {
83 $action->showForm ("(reCAPTCHA error: " . $resp->error . ")");
85 $action->showForm("Captcha does not match!");
90 function onPluginVersion(&$versions)
92 $versions[] = array('name' => 'Recaptcha',
93 'version' => STATUSNET_VERSION,
94 'author' => 'Eric Helgeson',
95 'homepage' => 'http://status.net/wiki/Plugin:Recaptcha',
97 _m('Uses <a href="http://recaptcha.org/">Recaptcha</a> service to add a '.
98 'captcha to the registration page.'));