1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class SimpleCaptchaPlugin extends Plugin
- {
- const PLUGIN_VERSION = '2.0.0';
- public function initialize()
- {
-
- $client_ip = common_client_ip();
- $this->client_ip = $client_ip[0] ?: $client_ip[1];
- }
- public function onEndRegistrationFormData(Action $action)
- {
- $action->elementStart('li');
-
- $action->input('simplecaptcha', _m('Captcha'), null,
-
- sprintf(_m('Copy this to the textbox: "%s"'), $this->getCaptchaText()),
-
- null, true, ['placeholder'=>_m('Prove that you are sentient.')]);
- $action->elementEnd('li');
- return true;
- }
- protected function getCaptchaText()
- {
- return common_config('site', 'name');
- }
- public function onStartRegistrationTry(Action $action)
- {
- if ($action->arg('simplecaptcha') !== $this->getCaptchaText()) {
- common_log(LOG_INFO, 'Stopped non-sentient registration of nickname '._ve($action->trimmed('nickname')).' from IP: '._ve($this->client_ip));
- throw new ClientException(_m('Captcha does not match!'));
- }
- return true;
- }
- public function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'Simple Captcha',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Mikael Nordfeldth',
- 'homepage' => 'https://gnu.io/social',
- 'rawdescription' =>
-
- _m('A simple captcha to get rid of spambots.'));
- return true;
- }
- }
|