123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- require_once(INSTALLDIR.'/plugins/Recaptcha/recaptchalib.php');
- class RecaptchaPlugin extends Plugin
- {
- var $private_key;
- var $public_key;
- var $display_errors;
- var $failed;
- var $ssl;
- function onInitializePlugin()
- {
- if(!isset($this->private_key)) {
- common_log(LOG_ERR, 'Recaptcha: Must specify private_key in config.php');
- }
- if(!isset($this->public_key)) {
- common_log(LOG_ERR, 'Recaptcha: Must specify public_key in config.php');
- }
- }
- function onEndRegistrationFormData($action)
- {
- $action->elementStart('li');
-
- $action->raw('<label for="recaptcha">'._m('Captcha').'</label>');
-
-
-
- $action->element('div', array('id' => 'recaptcha'));
- $action->elementEnd('li');
- $action->recaptchaPluginNeedsOutput = true;
- return true;
- }
- function onEndShowScripts($action)
- {
- if (isset($action->recaptchaPluginNeedsOutput) && $action->recaptchaPluginNeedsOutput) {
-
- if (GNUsocial::isHTTPS()) {
- $url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
- } else {
- $url = "http://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
- }
- $action->script($url);
-
- $key = json_encode($this->public_key);
- $action->inlinescript("\$(function(){Recaptcha.create($key, 'recaptcha');});");
- }
- return true;
- }
- function onStartRegistrationTry($action)
- {
- $resp = recaptcha_check_answer ($this->private_key,
- $_SERVER["REMOTE_ADDR"],
- $action->trimmed('recaptcha_challenge_field'),
- $action->trimmed('recaptcha_response_field'));
- if (!$resp->is_valid) {
- if($this->display_errors) {
-
-
- $action->showForm(sprintf(_m('(reCAPTCHA error: %s)', $resp->error)));
- }
-
- $action->showForm(_m('Captcha does not match!'));
- return false;
- }
- }
- function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'Recaptcha',
- 'version' => GNUSOCIAL_VERSION,
- 'author' => 'Eric Helgeson',
- 'homepage' => 'http://status.net/wiki/Plugin:Recaptcha',
- 'rawdescription' =>
-
- _m('Uses <a href="http://recaptcha.org/">Recaptcha</a> service to add a '.
- 'captcha to the registration page.'));
- return true;
- }
- }
|