]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SimpleCaptcha/SimpleCaptchaPlugin.php
SimpleCaptcha plugin to stop basic bots
[quix0rs-gnu-social.git] / plugins / SimpleCaptcha / SimpleCaptchaPlugin.php
1 <?php
2 /*
3  * GNU Social - a federating social network
4  * Copyright (C) 2014, Free Software Foundation, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('GNUSOCIAL')) { exit(1); }
21
22 /**
23  * @package     Plugin
24  * @maintainer  Mikael Nordfeldth <mmn@hethane.se>
25  */
26 class SimpleCaptchaPlugin extends Plugin
27 {
28     public function onEndRegistrationFormData(Action $action)
29     {
30         $action->elementStart('li');
31         // TRANS: Field label.
32         $action->input('simplecaptcha', _m('Captcha'), null,
33                         // TRANS: The instruction box for our simple captcha plugin
34                         sprintf(_m('Copy this to the textbox: "%s"'), $this->getCaptchaText()),
35                         // TRANS: Placeholder in the text box
36                         /* name=id */ null, /* required */ true, ['placeholder'=>_m('Prove that you are sentient.')]);
37         $action->elementEnd('li');
38         return true;
39     }
40
41     protected function getCaptchaText()
42     {
43         return common_config('site', 'name');
44     }
45
46     public function onStartRegistrationTry(Action $action)
47     {
48         if ($action->arg('simplecaptcha') !== $this->getCaptchaText()) {
49             throw new ClientException(_m('Captcha does not match!'));
50         }
51         return true;
52     }
53
54     public function onPluginVersion(array &$versions)
55     {
56         $versions[] = array('name' => 'Simple Captcha',
57                             'version' => GNUSOCIAL_VERSION,
58                             'author' => 'Mikael Nordfeldth',
59                             'homepage' => 'https://gnu.io/social',
60                             'rawdescription' =>
61                             // TRANS: Plugin description.
62                             _m('A simple captcha to get rid of spambots.'));
63
64         return true;
65     }
66 }