-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathq2apro-stopspam-captcha.php
309 lines (271 loc) · 10.4 KB
/
q2apro-stopspam-captcha.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/*
Plugin Name: Stop Spam
Plugin URI: http://www.q2apro.com/plugins/stop-spam
Plugin Description: An easy to use customizable captcha with a honeypot that keeps 99 % of the spam away
Plugin Version: 1.0
Plugin Date: 2014-02-20
Plugin Author: q2apro.com
Plugin Author URI: http://www.q2apro.com
Plugin Minimum Question2Answer Version: 1.5
Plugin Update Check URI: http://www.q2apro.com/pluginupdate?id=7
Licence: Copyright © q2apro.com - All rights reserved
*/
if (!defined('QA_VERSION'))
{ // don't allow this page to be requested directly from browser
header('Location: ../');
exit;
}
class q2apro_stopspam_captcha
{
// set captcha module to Stop Spam Captcha on first plugin run
function init_queries($tableslc)
{
if(qa_opt('q2apro_stopspam_captcha_init')!='1')
{
qa_opt('captcha_module', 'Stop Spam Captcha');
qa_opt('q2apro_stopspam_captcha_init', '1');
}
}
var $directory;
function load_module($directory, $urltoroot)
{
$this->directory=$directory;
}
// option's value is requested but the option has not yet been set
function option_default($option)
{
switch($option)
{
case 'q2apro_stopspam_captcha_question':
return qa_lang('q2apro_stopspam_lang/captcha_question');
case 'q2apro_stopspam_captcha_answer':
return qa_lang('q2apro_stopspam_lang/captcha_answer');
case 'q2apro_stopspam_captcha_answer2':
return qa_lang('q2apro_stopspam_lang/captcha_answer2');
case 'q2apro_stopspam_captcha_errormsg':
return qa_lang('q2apro_stopspam_lang/captcha_errormsg');
case 'q2apro_stopspam_filter_emails':
return 'trbvn.com, trashmail, 10minutemail.com';
case 'q2apro_stopspam_filter_words':
return '';
case 'q2apro_stopspam_filter_languages':
return '';
case 'q2apro_stopspam_notify_mentioning':
return '@admin';
case 'q2apro_stopspam_allow_links_count':
return '3';
case 'q2apro_stopspam_moderate_post_with_links':
return '';
case 'q2apro_stopspam_remove_linebreaks':
return '1'; // true
case 'q2apro_stopspam_mask_emails':
return '1'; // true
case 'q2apro_prevent_spamvotes':
return '1'; // true
case 'q2apro_block_guestswithoutip':
return '1'; // true
default:
return null;
}
}
function admin_form(&$qa_content)
{
// process the admin form if admin hit Save-Changes-button
$ok = null;
if (qa_clicked('q2apro_stopspam_save'))
{
qa_opt('q2apro_stopspam_captcha_question', (string)qa_post_text('q2apro_stopspam_captcha_question'));
qa_opt('q2apro_stopspam_captcha_answer', (string)qa_post_text('q2apro_stopspam_captcha_answer'));
qa_opt('q2apro_stopspam_captcha_answer2', (string)qa_post_text('q2apro_stopspam_captcha_answer2'));
qa_opt('q2apro_stopspam_captcha_errormsg', (string)qa_post_text('q2apro_stopspam_captcha_errormsg'));
// filter words
qa_opt('q2apro_stopspam_filter_emails', (string)qa_post_text('q2apro_stopspam_filter_emails'));
qa_opt('q2apro_stopspam_filter_words', (string)qa_post_text('q2apro_stopspam_filter_words'));
qa_opt('q2apro_stopspam_filter_languages', (string)qa_post_text('q2apro_stopspam_filter_languages'));
qa_opt('q2apro_stopspam_notify_mentioning', (string)qa_post_text('q2apro_stopspam_notify_mentioning'));
qa_opt('q2apro_stopspam_allow_links_count', (int)qa_post_text('q2apro_stopspam_allow_links_count'));
qa_opt('q2apro_stopspam_moderate_post_with_links', (int)qa_post_text('q2apro_stopspam_moderate_post_with_links'));
qa_opt('q2apro_stopspam_remove_linebreaks', (int)qa_post_text('q2apro_stopspam_remove_linebreaks'));
qa_opt('q2apro_stopspam_mask_emails', (int)qa_post_text('q2apro_stopspam_mask_emails'));
qa_opt('q2apro_prevent_spamvotes', (int)qa_post_text('q2apro_prevent_spamvotes'));
qa_opt('q2apro_block_guestswithoutip', (int)qa_post_text('q2apro_block_guestswithoutip'));
$ok = qa_lang('admin/options_saved');
}
// form fields to display frontend for admin
$fields = array();
$fields[] = array(
'type' => 'static',
'note' => qa_lang('q2apro_stopspam_lang/open_page').' <a style="color:#00F;" href="'.qa_path('listlinks').'">List Links in all Posts</a>',
);
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_stopspam_lang/label_q'),
'tags' => 'name="q2apro_stopspam_captcha_question"',
'value' => qa_opt('q2apro_stopspam_captcha_question'),
);
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_stopspam_lang/label_a'),
'tags' => 'name="q2apro_stopspam_captcha_answer"',
'value' => qa_opt('q2apro_stopspam_captcha_answer'),
);
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_stopspam_lang/label_a2'),
'tags' => 'name="q2apro_stopspam_captcha_answer2"',
'value' => qa_opt('q2apro_stopspam_captcha_answer2'),
);
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_stopspam_lang/label_error'),
'tags' => 'name="q2apro_stopspam_captcha_errormsg"',
'value' => qa_opt('q2apro_stopspam_captcha_errormsg'),
);
// 'options/captcha_module'
$fields[] = array(
'type' => 'static',
'note' => '<span><b>'.qa_lang('q2apro_stopspam_lang/note').'</b> '.strtr( qa_lang('q2apro_stopspam_lang/disable_captcha'), array(
'^1' => '<a target="_blank" href="./spam">',
'^2' => '</a>'
)).'</span>',
);
// anti spam emails
$fields[] = array(
'type' => 'textarea',
'rows' => 10,
'label' => 'List domains (or part of their names) that prevent user registration:',
'tags' => 'name="q2apro_stopspam_filter_emails"',
'value' => qa_opt('q2apro_stopspam_filter_emails'),
);
// anti spam words
$fields[] = array(
'type' => 'textarea',
'rows' => 10,
'label' => 'Spam words that prevent the posting to be submitted (separate with comma):',
'tags' => 'name="q2apro_stopspam_filter_words"',
'value' => qa_opt('q2apro_stopspam_filter_words'),
);
// spam languages
$fields[] = array(
'type' => 'input',
'label' => 'Disallow certain languages here, separate them by comma. Available are: Han,Hangul,Hebrew,Arabic,Cyrillic,Greek,Khmer. Note: "Han" stands for Chinese.',
'tags' => 'name="q2apro_stopspam_filter_languages"',
'value' => qa_opt('q2apro_stopspam_filter_languages'),
);
// notify on mentioning
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_stopspam_lang/notify_mentioning'),
'tags' => 'name="q2apro_stopspam_notify_mentioning"',
'value' => qa_opt('q2apro_stopspam_notify_mentioning'),
);
// number of allowed links in post
$fields[] = array(
'type' => 'number',
'label' => qa_lang('q2apro_stopspam_lang/allow_links_count'),
'tags' => 'name="q2apro_stopspam_allow_links_count"',
'value' => qa_opt('q2apro_stopspam_allow_links_count'),
);
// moderate answer-comment posts with links
$fields[] = array(
'type' => 'checkbox',
'label' => strtr( qa_lang('q2apro_stopspam_lang/moderate_post_with_links'), array(
'^1' => '<a href="'.qa_path('admin/moderate').'">',
'^2' => '</a>'
)),
'tags' => 'name="q2apro_stopspam_moderate_post_with_links"',
'value' => qa_opt('q2apro_stopspam_moderate_post_with_links'),
);
// mask email addresses
$fields[] = array(
'type' => 'checkbox',
'label' => qa_lang('q2apro_stopspam_lang/mask_emails'),
'tags' => 'name="q2apro_stopspam_mask_emails"',
'value' => qa_opt('q2apro_stopspam_mask_emails'),
);
// remove too many line breaks and merge them into one
$fields[] = array(
'type' => 'checkbox',
'label' => qa_lang('q2apro_stopspam_lang/remove_linebreaks'),
'tags' => 'name="q2apro_stopspam_remove_linebreaks"',
'value' => qa_opt('q2apro_stopspam_remove_linebreaks'),
);
// prevent spam votes
$fields[] = array(
'type' => 'checkbox',
'label' => qa_lang('q2apro_stopspam_lang/prevent_spamvotes'),
'tags' => 'name="q2apro_prevent_spamvotes"',
'value' => qa_opt('q2apro_prevent_spamvotes'),
);
// prevent spam votes
$fields[] = array(
'type' => 'checkbox',
'label' => qa_lang('q2apro_stopspam_lang/block_guestswithoutip'),
'tags' => 'name="q2apro_block_guestswithoutip"',
'value' => qa_opt('q2apro_block_guestswithoutip'),
);
// q2apro link
$fields[] = array(
'type' => 'static',
'note' => '<span style="font-size:75%;color:#789;">'.strtr( qa_lang('q2apro_stopspam_lang/contact'), array(
'^1' => '<a target="_blank" href="http://www.q2apro.com/plugins/stop-spam">',
'^2' => '</a>'
)).'</span>',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang('main/save_button'),
'tags' => 'name="q2apro_stopspam_save"',
),
),
);
}
// indicates whether the module is ready to be used
function allow_captcha()
{
return true;
}
// returns the HTML form to be displayed for the captcha challenge
function form_html(&$qa_content, $error)
{
$html = '<div class="q2apro_captcha">';
$html .= '<span class="captcha_q">'.qa_opt('q2apro_stopspam_captcha_question').'</span>';
$html .= '<input type="text" name="captcha_challenge_field" />';
$html .= '<input type="checkbox" name="response_field" id="response_field" />';
$html .= '</div>';
// insert css to hide the honeypot
$html .= '<style type="text/css"> .captcha_q{margin-right:10px;color:#00C;} #response_field{display:none;} .q2apro_captcha { margin-bottom:20px; }</style>';
return $html;
}
// check if user has given the correct answer
function validate_post(&$error)
{
// honeypot: bot filled input field (which is hidden by CSS)
if(!empty($_POST['response_field']))
{
$error = 's-p-a-m-b-o-t';
}
else if(!empty($_POST['captcha_challenge_field']))
{
// correct answer given
if( $_POST['captcha_challenge_field']==qa_opt('q2apro_stopspam_captcha_answer')
|| $_POST['captcha_challenge_field']==qa_opt('q2apro_stopspam_captcha_answer2') )
{
return true;
}
else
{
// wrong answer
$error = qa_opt('q2apro_stopspam_captcha_errormsg');
}
}
return false;
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/