Version Description
- Fix: Contact form 7 compatibility fix
- Tweak: Removed local translation files in favor of WP repository translations.
Download this release
Release Info
Developer | dfactory |
Plugin | Math Captcha |
Version | 1.2.7 |
Comparing to | |
See all releases |
Code changes from version 1.2.6 to 1.2.7
- css/admin.css +19 -19
- css/frontend.css +16 -16
- includes/class-cookie-session.php +70 -66
- includes/class-core.php +678 -632
- includes/class-settings.php +315 -342
- includes/class-update.php +36 -38
- includes/integrations/contact-form-7.php +178 -178
- index.php +1 -1
- js/admin-settings.js +11 -7
- languages/math-captcha-de_DE.mo +0 -0
- languages/math-captcha-de_DE.po +0 -349
- languages/math-captcha-fa_IR.mo +0 -0
- languages/math-captcha-fa_IR.po +0 -344
- languages/math-captcha-fr_FR.mo +0 -0
- languages/math-captcha-fr_FR.po +0 -427
- languages/math-captcha-it_IT.mo +0 -0
- languages/math-captcha-it_IT.po +0 -343
- languages/math-captcha-ja.mo +0 -0
- languages/math-captcha-ja.po +0 -263
- languages/math-captcha-nl_NL.mo +0 -0
- languages/math-captcha-nl_NL.po +0 -427
- languages/math-captcha-pl_PL.mo +0 -0
- languages/math-captcha-pl_PL.po +666 -715
- languages/math-captcha-ro_RO.mo +0 -0
- languages/math-captcha-ro_RO.po +0 -415
- languages/math-captcha-ru_RU.mo +0 -0
- languages/math-captcha-ru_RU.po +0 -356
- languages/math-captcha-sk_SK.mo +0 -0
- languages/math-captcha-sk_SK.po +0 -371
- languages/math-captcha-zh_CN.mo +0 -0
- languages/math-captcha-zh_CN.po +0 -347
- languages/wp-math-captcha-he_IL.mo +0 -0
- languages/wp-math-captcha-he_IL.po +0 -605
- readme.txt +8 -19
- wp-math-captcha.php +229 -217
css/admin.css
CHANGED
@@ -1,20 +1,20 @@
|
|
1 |
-
/* Math Captcha settings */
|
2 |
-
.df-credits { float: right; width: 280px; background: #fff; margin: 20px -300px 20px 20px; position: relative; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05); }
|
3 |
-
.df-credits .inner { padding-left: 10px; padding-right: 10px; }
|
4 |
-
.df-credits h3 { font-size: 14px; line-height: 1.4; margin: 0; padding: 8px 12px; border-bottom: 1px solid #eee; }
|
5 |
-
.df-credits .df-link { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif; font-style:italic; padding-bottom: 10px; margin: 0; }
|
6 |
-
.df-credits .df-link a { vertical-align: middle; padding: 5px 0 0 4px; }
|
7 |
-
.math-captcha-settings .df-credits form { min-width: 260px; margin-bottom: 1em; }
|
8 |
-
.math-captcha-settings .df-credits form input { margin: 0; padding: 0; }
|
9 |
-
.math-captcha-settings { margin-right: 300px; }
|
10 |
-
.math-captcha-settings hr, .df-credits hr { border: solid #eee; border-width: 1px 0 0; clear: both; height: 0; }
|
11 |
-
.math-captcha-settings form { float: left; min-width: 463px; width: auto; }
|
12 |
-
.math-captcha-settings fieldset span.description { margin-bottom: 8px; margin-top: 4px; display: block; }
|
13 |
-
.math-captcha-settings .ui-button { margin-bottom: 5px; }
|
14 |
-
.math-captcha-settings .description { font-size: 13px; margin-bottom: 8px; }
|
15 |
-
|
16 |
-
/* All Mobile Sizes (devices and browser) */
|
17 |
-
@media only screen and (max-width: 959px) {
|
18 |
-
.df-credits { width: 100%; float: none; margin: 20px 0; }
|
19 |
-
.math-captcha-settings { margin-right: 0; }
|
20 |
}
|
1 |
+
/* Math Captcha settings */
|
2 |
+
.df-credits { float: right; width: 280px; background: #fff; margin: 20px -300px 20px 20px; position: relative; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05); }
|
3 |
+
.df-credits .inner { padding-left: 10px; padding-right: 10px; }
|
4 |
+
.df-credits h3 { font-size: 14px; line-height: 1.4; margin: 0; padding: 8px 12px; border-bottom: 1px solid #eee; }
|
5 |
+
.df-credits .df-link { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif; font-style:italic; padding-bottom: 10px; margin: 0; }
|
6 |
+
.df-credits .df-link a { vertical-align: middle; padding: 5px 0 0 4px; }
|
7 |
+
.math-captcha-settings .df-credits form { min-width: 260px; margin-bottom: 1em; }
|
8 |
+
.math-captcha-settings .df-credits form input { margin: 0; padding: 0; }
|
9 |
+
.math-captcha-settings { margin-right: 300px; }
|
10 |
+
.math-captcha-settings hr, .df-credits hr { border: solid #eee; border-width: 1px 0 0; clear: both; height: 0; }
|
11 |
+
.math-captcha-settings form { float: left; min-width: 463px; width: auto; }
|
12 |
+
.math-captcha-settings fieldset span.description { margin-bottom: 8px; margin-top: 4px; display: block; }
|
13 |
+
.math-captcha-settings .ui-button { margin-bottom: 5px; }
|
14 |
+
.math-captcha-settings .description { font-size: 13px; margin-bottom: 8px; }
|
15 |
+
|
16 |
+
/* All Mobile Sizes (devices and browser) */
|
17 |
+
@media only screen and (max-width: 959px) {
|
18 |
+
.df-credits { width: 100%; float: none; margin: 20px 0; }
|
19 |
+
.math-captcha-settings { margin-right: 0; }
|
20 |
}
|
css/frontend.css
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
-
.math-captcha-form {
|
2 |
-
display:block;
|
3 |
-
float:none;
|
4 |
-
clear:both;
|
5 |
-
}
|
6 |
-
|
7 |
-
.login form .math-captcha-form span {
|
8 |
-
display: inline-block;
|
9 |
-
margin-bottom: 16px;
|
10 |
-
}
|
11 |
-
input[type="text"].mc-input {
|
12 |
-
display: inline-block;
|
13 |
-
width: 60px!important;
|
14 |
-
vertical-align: middle;
|
15 |
-
margin-bottom: 0;
|
16 |
-
}
|
1 |
+
.math-captcha-form {
|
2 |
+
display:block;
|
3 |
+
float:none;
|
4 |
+
clear:both;
|
5 |
+
}
|
6 |
+
|
7 |
+
.login form .math-captcha-form span {
|
8 |
+
display: inline-block;
|
9 |
+
margin-bottom: 16px;
|
10 |
+
}
|
11 |
+
input[type="text"].mc-input {
|
12 |
+
display: inline-block;
|
13 |
+
width: 60px!important;
|
14 |
+
vertical-align: middle;
|
15 |
+
margin-bottom: 0;
|
16 |
+
}
|
includes/class-cookie-session.php
CHANGED
@@ -1,67 +1,71 @@
|
|
1 |
-
<?php
|
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 |
}
|
1 |
+
<?php
|
2 |
+
// exit if accessed directly
|
3 |
+
if ( ! defined( 'ABSPATH' ) )
|
4 |
+
exit;
|
5 |
+
|
6 |
+
new Math_Captcha_Cookie_Session();
|
7 |
+
|
8 |
+
class Math_Captcha_Cookie_Session {
|
9 |
+
|
10 |
+
public $session_ids;
|
11 |
+
|
12 |
+
public function __construct() {
|
13 |
+
// set instance
|
14 |
+
Math_Captcha()->cookie_session = $this;
|
15 |
+
|
16 |
+
// actions
|
17 |
+
add_action( 'plugins_loaded', array( &$this, 'init_session' ), 1 );
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Initialize cookie-session.
|
22 |
+
*/
|
23 |
+
public function init_session() {
|
24 |
+
if ( is_admin() )
|
25 |
+
return;
|
26 |
+
|
27 |
+
if ( isset( $_COOKIE['mc_session_ids'] ) )
|
28 |
+
$this->session_ids = $_COOKIE['mc_session_ids'];
|
29 |
+
else {
|
30 |
+
foreach ( array( 'default', 'multi' ) as $place ) {
|
31 |
+
switch ( $place ) {
|
32 |
+
case 'multi':
|
33 |
+
for ( $i = 0; $i < 5; $i ++ ) {
|
34 |
+
$this->session_ids[$place][$i] = sha1( $this->generate_password() );
|
35 |
+
}
|
36 |
+
break;
|
37 |
+
|
38 |
+
case 'default':
|
39 |
+
$this->session_ids[$place] = sha1( $this->generate_password() );
|
40 |
+
break;
|
41 |
+
}
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
if ( ! isset( $_COOKIE['mc_session_ids'] ) ) {
|
46 |
+
setcookie( 'mc_session_ids[default]', $this->session_ids['default'], current_time( 'timestamp', true ) + apply_filters( 'math_captcha_time', Math_Captcha()->options['general']['time'] ), COOKIEPATH, COOKIE_DOMAIN, (isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ? true : false ), true );
|
47 |
+
|
48 |
+
for ( $i = 0; $i < 5; $i ++ ) {
|
49 |
+
setcookie( 'mc_session_ids[multi][' . $i . ']', $this->session_ids['multi'][$i], current_time( 'timestamp', true ) + apply_filters( 'math_captcha_time', Math_Captcha()->options['general']['time'] ), COOKIEPATH, COOKIE_DOMAIN );
|
50 |
+
}
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Generate password helper, without wp_rand() call
|
56 |
+
*
|
57 |
+
* @param int $length
|
58 |
+
* @return string
|
59 |
+
*/
|
60 |
+
private function generate_password( $length = 64 ) {
|
61 |
+
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
62 |
+
$password = '';
|
63 |
+
|
64 |
+
for ( $i = 0; $i < $length; $i ++ ) {
|
65 |
+
$password .= substr( $chars, mt_rand( 0, strlen( $chars ) - 1 ), 1 );
|
66 |
+
}
|
67 |
+
|
68 |
+
return $password;
|
69 |
+
}
|
70 |
+
|
71 |
}
|
includes/class-core.php
CHANGED
@@ -1,633 +1,679 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
public $
|
11 |
-
public $
|
12 |
-
public $
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
add_action( '
|
24 |
-
add_action( '
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
add_filter( '
|
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 |
-
add_action( '
|
69 |
-
add_action( '
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
add_action( '
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
add_filter( '
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
add_action( '
|
90 |
-
add_action( '
|
91 |
-
add_action( '
|
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 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
'
|
420 |
-
|
421 |
-
'
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
$
|
502 |
-
|
503 |
-
$number[
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
$number[
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
$
|
545 |
-
|
546 |
-
$number[
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
$number[
|
552 |
-
|
553 |
-
$number[
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
$
|
568 |
-
|
569 |
-
|
570 |
-
$
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
$
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
}
|
1 |
+
<?php
|
2 |
+
// exit if accessed directly
|
3 |
+
if ( ! defined( 'ABSPATH' ) )
|
4 |
+
exit;
|
5 |
+
|
6 |
+
new Math_Captcha_Core();
|
7 |
+
|
8 |
+
class Math_Captcha_Core {
|
9 |
+
|
10 |
+
public $session_number = 0;
|
11 |
+
public $login_failed = false;
|
12 |
+
public $error_messages;
|
13 |
+
public $errors;
|
14 |
+
|
15 |
+
/**
|
16 |
+
*
|
17 |
+
*/
|
18 |
+
public function __construct() {
|
19 |
+
// set instance
|
20 |
+
Math_Captcha()->core = $this;
|
21 |
+
|
22 |
+
// actions
|
23 |
+
add_action( 'init', array( &$this, 'load_actions_filters' ), 1 );
|
24 |
+
add_action( 'plugins_loaded', array( &$this, 'load_defaults' ) );
|
25 |
+
add_action( 'admin_init', array( &$this, 'flush_rewrites' ) );
|
26 |
+
|
27 |
+
// filters
|
28 |
+
add_filter( 'shake_error_codes', array( &$this, 'add_shake_error_codes' ), 1 );
|
29 |
+
add_filter( 'mod_rewrite_rules', array( &$this, 'block_direct_comments' ) );
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Load defaults.
|
34 |
+
*/
|
35 |
+
public function load_defaults() {
|
36 |
+
$this->error_messages = array(
|
37 |
+
'fill' => '<strong>' . __( 'ERROR', 'math-captcha' ) . '</strong>: ' . __( 'Please enter captcha value.', 'math-captcha' ),
|
38 |
+
'wrong' => '<strong>' . __( 'ERROR', 'math-captcha' ) . '</strong>: ' . __( 'Invalid captcha value.', 'math-captcha' ),
|
39 |
+
'time' => '<strong>' . __( 'ERROR', 'math-captcha' ) . '</strong>: ' . __( 'Captcha time expired.', 'math-captcha' )
|
40 |
+
);
|
41 |
+
}
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Load required filters.
|
45 |
+
*/
|
46 |
+
public function load_actions_filters() {
|
47 |
+
// Contact Form 7
|
48 |
+
if ( Math_Captcha()->options['general']['enable_for']['contact_form_7'] && class_exists( 'WPCF7_ContactForm' ) )
|
49 |
+
include_once(MATH_CAPTCHA_PATH . 'includes/integrations/contact-form-7.php');
|
50 |
+
|
51 |
+
if ( is_admin() )
|
52 |
+
return;
|
53 |
+
|
54 |
+
$action = (isset( $_GET['action'] ) && $_GET['action'] !== '' ? $_GET['action'] : null);
|
55 |
+
|
56 |
+
// comments
|
57 |
+
if ( Math_Captcha()->options['general']['enable_for']['comment_form'] ) {
|
58 |
+
if ( ! is_user_logged_in() )
|
59 |
+
add_action( 'comment_form_after_fields', array( &$this, 'add_captcha_form' ) );
|
60 |
+
elseif ( ! Math_Captcha()->options['general']['hide_for_logged_users'] )
|
61 |
+
add_action( 'comment_form_logged_in_after', array( &$this, 'add_captcha_form' ) );
|
62 |
+
|
63 |
+
add_filter( 'preprocess_comment', array( &$this, 'add_comment_with_captcha' ) );
|
64 |
+
}
|
65 |
+
|
66 |
+
// registration
|
67 |
+
if ( Math_Captcha()->options['general']['enable_for']['registration_form'] && ( ! is_user_logged_in() || (is_user_logged_in() && ! Math_Captcha()->options['general']['hide_for_logged_users'])) && $action === 'register' ) {
|
68 |
+
add_action( 'register_form', array( &$this, 'add_captcha_form' ) );
|
69 |
+
add_action( 'register_post', array( &$this, 'add_user_with_captcha' ), 10, 3 );
|
70 |
+
add_action( 'signup_extra_fields', array( &$this, 'add_captcha_form' ) );
|
71 |
+
add_filter( 'wpmu_validate_user_signup', array( &$this, 'validate_user_with_captcha' ) );
|
72 |
+
}
|
73 |
+
|
74 |
+
// lost password
|
75 |
+
if ( Math_Captcha()->options['general']['enable_for']['reset_password_form'] && ( ! is_user_logged_in() || (is_user_logged_in() && ! Math_Captcha()->options['general']['hide_for_logged_users'])) && $action === 'lostpassword' ) {
|
76 |
+
add_action( 'lostpassword_form', array( &$this, 'add_captcha_form' ) );
|
77 |
+
add_action( 'lostpassword_post', array( &$this, 'check_lost_password_with_captcha' ) );
|
78 |
+
}
|
79 |
+
|
80 |
+
// login
|
81 |
+
if ( Math_Captcha()->options['general']['enable_for']['login_form'] && ( ! is_user_logged_in() || (is_user_logged_in() && ! Math_Captcha()->options['general']['hide_for_logged_users'])) && $action === null ) {
|
82 |
+
add_action( 'login_form', array( &$this, 'add_captcha_form' ) );
|
83 |
+
add_filter( 'login_redirect', array( &$this, 'redirect_login_with_captcha' ), 10, 3 );
|
84 |
+
add_filter( 'authenticate', array( &$this, 'authenticate_user' ), 1000, 3 );
|
85 |
+
}
|
86 |
+
|
87 |
+
// bbPress
|
88 |
+
if ( Math_Captcha()->options['general']['enable_for']['bbpress'] && class_exists( 'bbPress' ) && ( ! is_user_logged_in() || (is_user_logged_in() && ! Math_Captcha()->options['general']['hide_for_logged_users'])) ) {
|
89 |
+
add_action( 'bbp_theme_after_reply_form_content', array( &$this, 'add_bbp_captcha_form' ) );
|
90 |
+
add_action( 'bbp_theme_after_topic_form_content', array( &$this, 'add_bbp_captcha_form' ) );
|
91 |
+
add_action( 'bbp_new_reply_pre_extras', array( &$this, 'check_bbpress_captcha' ) );
|
92 |
+
add_action( 'bbp_new_topic_pre_extras', array( &$this, 'check_bbpress_captcha' ) );
|
93 |
+
}
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Add lost password errors.
|
98 |
+
*
|
99 |
+
* @param array $errors
|
100 |
+
* @return array
|
101 |
+
*/
|
102 |
+
public function add_lostpassword_captcha_message( $errors ) {
|
103 |
+
return $errors . $this->errors->errors['math-captcha-error'][0];
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Add lost password errors (special way)
|
108 |
+
*
|
109 |
+
* @return array
|
110 |
+
*/
|
111 |
+
public function add_lostpassword_wp_message() {
|
112 |
+
return $this->errors;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Validate lost password form.
|
117 |
+
*/
|
118 |
+
public function check_lost_password_with_captcha() {
|
119 |
+
$this->errors = new WP_Error();
|
120 |
+
$user_error = false;
|
121 |
+
$user_data = null;
|
122 |
+
|
123 |
+
// checks captcha
|
124 |
+
if ( isset( $_POST['mc-value'] ) && $_POST['mc-value'] !== '' ) {
|
125 |
+
if ( Math_Captcha()->cookie_session->session_ids['default'] !== '' && get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ) !== false ) {
|
126 |
+
if ( strcmp( get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ), sha1( AUTH_KEY . $_POST['mc-value'] . Math_Captcha()->cookie_session->session_ids['default'], false ) ) !== 0 )
|
127 |
+
$this->errors->add( 'math-captcha-error', $this->error_messages['wrong'] );
|
128 |
+
} else
|
129 |
+
$this->errors->add( 'math-captcha-error', $this->error_messages['time'] );
|
130 |
+
} else
|
131 |
+
$this->errors->add( 'math-captcha-error', $this->error_messages['fill'] );
|
132 |
+
|
133 |
+
// checks user_login (from wp-login.php)
|
134 |
+
if ( empty( $_POST['user_login'] ) )
|
135 |
+
$user_error = true;
|
136 |
+
elseif ( strpos( $_POST['user_login'], '@' ) ) {
|
137 |
+
$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
|
138 |
+
|
139 |
+
if ( empty( $user_data ) )
|
140 |
+
$user_error = true;
|
141 |
+
} else
|
142 |
+
$user_data = get_user_by( 'login', trim( $_POST['user_login'] ) );
|
143 |
+
|
144 |
+
if ( ! $user_data )
|
145 |
+
$user_error = true;
|
146 |
+
|
147 |
+
// something went wrong?
|
148 |
+
if ( ! empty( $this->errors->errors ) ) {
|
149 |
+
// nasty hack (captcha is invalid but user_login is fine)
|
150 |
+
if ( $user_error === false )
|
151 |
+
add_filter( 'allow_password_reset', array( &$this, 'add_lostpassword_wp_message' ) );
|
152 |
+
else
|
153 |
+
add_filter( 'login_errors', array( &$this, 'add_lostpassword_captcha_message' ) );
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Validate registration form.
|
159 |
+
*
|
160 |
+
* @param string $login
|
161 |
+
* @param string $email
|
162 |
+
* @param array $errors
|
163 |
+
* @return array
|
164 |
+
*/
|
165 |
+
public function add_user_with_captcha( $login, $email, $errors ) {
|
166 |
+
if ( isset( $_POST['mc-value'] ) && $_POST['mc-value'] !== '' ) {
|
167 |
+
if ( Math_Captcha()->cookie_session->session_ids['default'] !== '' && get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ) !== false ) {
|
168 |
+
if ( strcmp( get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ), sha1( AUTH_KEY . $_POST['mc-value'] . Math_Captcha()->cookie_session->session_ids['default'], false ) ) !== 0 )
|
169 |
+
$errors->add( 'math-captcha-error', $this->error_messages['wrong'] );
|
170 |
+
} else
|
171 |
+
$errors->add( 'math-captcha-error', $this->error_messages['time'] );
|
172 |
+
} else
|
173 |
+
$errors->add( 'math-captcha-error', $this->error_messages['fill'] );
|
174 |
+
|
175 |
+
return $errors;
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Validate registration form.
|
180 |
+
*
|
181 |
+
* @param array $result
|
182 |
+
* @return array
|
183 |
+
*/
|
184 |
+
public function validate_user_with_captcha( $result ) {
|
185 |
+
if ( isset( $_POST['mc-value'] ) && $_POST['mc-value'] !== '' ) {
|
186 |
+
if ( Math_Captcha()->cookie_session->session_ids['default'] !== '' && get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ) !== false ) {
|
187 |
+
if ( strcmp( get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ), sha1( AUTH_KEY . $_POST['mc-value'] . Math_Captcha()->cookie_session->session_ids['default'], false ) ) !== 0 )
|
188 |
+
$result['errors']->add( 'math-captcha-error', $this->error_messages['wrong'] );
|
189 |
+
} else
|
190 |
+
$result['errors']->add( 'math-captcha-error', $this->error_messages['time'] );
|
191 |
+
} else
|
192 |
+
$result['errors']->add( 'math-captcha-error', $this->error_messages['fill'] );
|
193 |
+
|
194 |
+
return $result;
|
195 |
+
}
|
196 |
+
|
197 |
+
/**
|
198 |
+
* Posts login form
|
199 |
+
*
|
200 |
+
* @param string $redirect
|
201 |
+
* @param bool $bool
|
202 |
+
* @param array $errors
|
203 |
+
* @return array
|
204 |
+
*/
|
205 |
+
public function redirect_login_with_captcha( $redirect, $bool, $errors ) {
|
206 |
+
if ( $this->login_failed === false && ! empty( $_POST ) ) {
|
207 |
+
$error = '';
|
208 |
+
|
209 |
+
if ( isset( $_POST['mc-value'] ) && $_POST['mc-value'] !== '' ) {
|
210 |
+
if ( Math_Captcha()->cookie_session->session_ids['default'] !== '' && get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ) !== false ) {
|
211 |
+
if ( strcmp( get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ), sha1( AUTH_KEY . $_POST['mc-value'] . Math_Captcha()->cookie_session->session_ids['default'], false ) ) !== 0 )
|
212 |
+
$error = 'wrong';
|
213 |
+
} else
|
214 |
+
$error = 'time';
|
215 |
+
} else
|
216 |
+
$error = 'fill';
|
217 |
+
|
218 |
+
if ( is_wp_error( $errors ) && ! empty( $error ) )
|
219 |
+
$errors->add( 'math-captcha-error', $this->error_messages[$error] );
|
220 |
+
}
|
221 |
+
|
222 |
+
return $redirect;
|
223 |
+
}
|
224 |
+
|
225 |
+
/**
|
226 |
+
* Authenticate user.
|
227 |
+
*
|
228 |
+
* @param WP_Error $user
|
229 |
+
* @param string $username
|
230 |
+
* @param string $password
|
231 |
+
* @return \WP_Error
|
232 |
+
*/
|
233 |
+
public function authenticate_user( $user, $username, $password ) {
|
234 |
+
// user gave us valid login and password
|
235 |
+
if ( ! is_wp_error( $user ) ) {
|
236 |
+
if ( ! empty( $_POST ) ) {
|
237 |
+
if ( isset( $_POST['mc-value'] ) && $_POST['mc-value'] !== '' ) {
|
238 |
+
if ( Math_Captcha()->cookie_session->session_ids['default'] !== '' && get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ) !== false ) {
|
239 |
+
if ( strcmp( get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ), sha1( AUTH_KEY . $_POST['mc-value'] . Math_Captcha()->cookie_session->session_ids['default'], false ) ) !== 0 )
|
240 |
+
$error = 'wrong';
|
241 |
+
} else
|
242 |
+
$error = 'time';
|
243 |
+
} else
|
244 |
+
$error = 'fill';
|
245 |
+
}
|
246 |
+
|
247 |
+
if ( ! empty( $error ) ) {
|
248 |
+
// destroy cookie
|
249 |
+
wp_clear_auth_cookie();
|
250 |
+
|
251 |
+
$user = new WP_Error();
|
252 |
+
$user->add( 'math-captcha-error', $this->error_messages[$error] );
|
253 |
+
|
254 |
+
// inform redirect function that we failed to login
|
255 |
+
$this->login_failed = true;
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
return $user;
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Add shake.
|
264 |
+
*
|
265 |
+
* @param array $codes
|
266 |
+
* @return array
|
267 |
+
*/
|
268 |
+
public function add_shake_error_codes( $codes ) {
|
269 |
+
$codes[] = 'math-captcha-error';
|
270 |
+
|
271 |
+
return $codes;
|
272 |
+
}
|
273 |
+
|
274 |
+
/**
|
275 |
+
* Add captcha to comment form.
|
276 |
+
*
|
277 |
+
* @param array $comment
|
278 |
+
* @return array
|
279 |
+
*/
|
280 |
+
public function add_comment_with_captcha( $comment ) {
|
281 |
+
if ( isset( $_POST['mc-value'] ) && ( ! is_admin() || DOING_AJAX) && ($comment['comment_type'] === '' || $comment['comment_type'] === 'comment') ) {
|
282 |
+
if ( $_POST['mc-value'] !== '' ) {
|
283 |
+
if ( Math_Captcha()->cookie_session->session_ids['default'] !== '' && get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ) !== false ) {
|
284 |
+
if ( strcmp( get_transient( 'mc_' . Math_Captcha()->cookie_session->session_ids['default'] ), sha1( AUTH_KEY . $_POST['mc-value'] . Math_Captcha()->cookie_session->session_ids['default'], false ) ) === 0 )
|
285 |
+
return $comment;
|
286 |
+
else
|
287 |
+
wp_die( $this->error_messages['wrong'] );
|
288 |
+
} else
|
289 |
+
wp_die( $this->error_messages['time'] );
|
290 |
+
} else
|
291 |
+
wp_die( $this->error_messages['fill'] );
|
292 |
+
} else
|
293 |
+
return $comment;
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* Display and generate captcha.
|
298 |
+
*
|
299 |
+
* @return mixed
|
300 |
+
*/
|
301 |
+
public function add_captcha_form() {
|
302 |
+
if ( is_admin() )
|
303 |
+
return;
|
304 |
+
|
305 |
+
$captcha_title = apply_filters( 'math_captcha_title', Math_Captcha()->options['general']['title'] );
|
306 |
+
|
307 |
+
echo '
|
308 |
+
<p class="math-captcha-form">';
|
309 |
+
|
310 |
+
if ( ! empty( $captcha_title ) )
|
311 |
+
echo '
|
312 |
+
<label>' . $captcha_title . '<br/></label>';
|
313 |
+
|
314 |
+
echo '
|
315 |
+
<span>' . $this->generate_captcha_phrase( 'default' ) . '</span>
|
316 |
+
</p>';
|
317 |
+
}
|
318 |
+
|
319 |
+
/**
|
320 |
+
* Display and generate captcha for bbPress forms.
|
321 |
+
*
|
322 |
+
* @return mixed
|
323 |
+
*/
|
324 |
+
public function add_bbp_captcha_form() {
|
325 |
+
if ( is_admin() )
|
326 |
+
return;
|
327 |
+
|
328 |
+
$captcha_title = apply_filters( 'math_captcha_title', Math_Captcha()->options['general']['title'] );
|
329 |
+
|
330 |
+
echo '
|
331 |
+
<p class="math-captcha-form">';
|
332 |
+
|
333 |
+
if ( ! empty( $captcha_title ) )
|
334 |
+
echo '
|
335 |
+
<label>' . $captcha_title . '<br/></label>';
|
336 |
+
|
337 |
+
echo '
|
338 |
+
<span>' . $this->generate_captcha_phrase( 'bbpress' ) . '</span>
|
339 |
+
</p>';
|
340 |
+
}
|
341 |
+
|
342 |
+
/**
|
343 |
+
* Validate bbpress topics and replies.
|
344 |
+
*/
|
345 |
+
public function check_bbpress_captcha() {
|
346 |
+
if ( isset( $_POST['mc-value'] ) && $_POST['mc-value'] !== '' ) {
|
347 |
+
if ( Math_Captcha()->cookie_session->session_ids['default'] !== '' && get_transient( 'bbp_' . Math_Captcha()->cookie_session->session_ids['default'] ) !== false ) {
|
348 |
+
if ( strcmp( get_transient( 'bbp_' . Math_Captcha()->cookie_session->session_ids['default'] ), sha1( AUTH_KEY . $_POST['mc-value'] . Math_Captcha()->cookie_session->session_ids['default'], false ) ) !== 0 )
|
349 |
+
bbp_add_error( 'math-captcha-wrong', $this->error_messages['wrong'] );
|
350 |
+
} else
|
351 |
+
bbp_add_error( 'math-captcha-wrong', $this->error_messages['time'] );
|
352 |
+
} else
|
353 |
+
bbp_add_error( 'math-captcha-wrong', $this->error_messages['fill'] );
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Encode chars.
|
358 |
+
*
|
359 |
+
* @param string $string
|
360 |
+
* @return string
|
361 |
+
*/
|
362 |
+
private function encode_operation( $string ) {
|
363 |
+
$chars = str_split( $string );
|
364 |
+
$seed = mt_rand( 0, (int) abs( crc32( $string ) / strlen( $string ) ) );
|
365 |
+
|
366 |
+
foreach ( $chars as $key => $char ) {
|
367 |
+
$ord = ord( $char );
|
368 |
+
|
369 |
+
// ignore non-ascii chars
|
370 |
+
if ( $ord < 128 ) {
|
371 |
+
// pseudo "random function"
|
372 |
+
$r = ($seed * (1 + $key)) % 100;
|
373 |
+
|
374 |
+
if ( $r > 60 && $char !== '@' ) {
|
375 |
+
|
376 |
+
} // plain character (not encoded), if not @-sign
|
377 |
+
elseif ( $r < 45 )
|
378 |
+
$chars[$key] = '&#x' . dechex( $ord ) . ';'; // hexadecimal
|
379 |
+
else
|
380 |
+
$chars[$key] = '&#' . $ord . ';'; // decimal (ascii)
|
381 |
+
}
|
382 |
+
}
|
383 |
+
|
384 |
+
return implode( '', $chars );
|
385 |
+
}
|
386 |
+
|
387 |
+
/**
|
388 |
+
* Convert numbers to words.
|
389 |
+
*
|
390 |
+
* @param int $number
|
391 |
+
* @return string
|
392 |
+
*/
|
393 |
+
private function numberToWords( $number ) {
|
394 |
+
$words = array(
|
395 |
+
1 => __( 'one', 'math-captcha' ),
|
396 |
+
2 => __( 'two', 'math-captcha' ),
|
397 |
+
3 => __( 'three', 'math-captcha' ),
|
398 |
+
4 => __( 'four', 'math-captcha' ),
|
399 |
+
5 => __( 'five', 'math-captcha' ),
|
400 |
+
6 => __( 'six', 'math-captcha' ),
|
401 |
+
7 => __( 'seven', 'math-captcha' ),
|
402 |
+
8 => __( 'eight', 'math-captcha' ),
|
403 |
+
9 => __( 'nine', 'math-captcha' ),
|
404 |
+
10 => __( 'ten', 'math-captcha' ),
|
405 |
+
11 => __( 'eleven', 'math-captcha' ),
|
406 |
+
12 => __( 'twelve', 'math-captcha' ),
|
407 |
+
13 => __( 'thirteen', 'math-captcha' ),
|
408 |
+
14 => __( 'fourteen', 'math-captcha' ),
|
409 |
+
15 => __( 'fifteen', 'math-captcha' ),
|
410 |
+
16 => __( 'sixteen', 'math-captcha' ),
|
411 |
+
17 => __( 'seventeen', 'math-captcha' ),
|
412 |
+
18 => __( 'eighteen', 'math-captcha' ),
|
413 |
+
19 => __( 'nineteen', 'math-captcha' ),
|
414 |
+
20 => __( 'twenty', 'math-captcha' ),
|
415 |
+
30 => __( 'thirty', 'math-captcha' ),
|
416 |
+
40 => __( 'forty', 'math-captcha' ),
|
417 |
+
50 => __( 'fifty', 'math-captcha' ),
|
418 |
+
60 => __( 'sixty', 'math-captcha' ),
|
419 |
+
70 => __( 'seventy', 'math-captcha' ),
|
420 |
+
80 => __( 'eighty', 'math-captcha' ),
|
421 |
+
90 => __( 'ninety', 'math-captcha' )
|
422 |
+
);
|
423 |
+
|
424 |
+
if ( isset( $words[$number] ) )
|
425 |
+
return $words[$number];
|
426 |
+
else {
|
427 |
+
$reverse = false;
|
428 |
+
|
429 |
+
switch ( get_bloginfo( 'language' ) ) {
|
430 |
+
case 'de-DE':
|
431 |
+
$spacer = 'und';
|
432 |
+
$reverse = true;
|
433 |
+
break;
|
434 |
+
|
435 |
+
case 'nl-NL':
|
436 |
+
$spacer = 'en';
|
437 |
+
$reverse = true;
|
438 |
+
break;
|
439 |
+
|
440 |
+
case 'ru-RU':
|
441 |
+
case 'pl-PL':
|
442 |
+
case 'en-EN':
|
443 |
+
default:
|
444 |
+
$spacer = ' ';
|
445 |
+
}
|
446 |
+
|
447 |
+
$first = (int) (substr( $number, 0, 1 ) * 10);
|
448 |
+
$second = (int) substr( $number, -1 );
|
449 |
+
|
450 |
+
return ($reverse === false ? $words[$first] . $spacer . $words[$second] : $words[$second] . $spacer . $words[$first]);
|
451 |
+
}
|
452 |
+
}
|
453 |
+
|
454 |
+
/**
|
455 |
+
* Generate captcha phrase.
|
456 |
+
*
|
457 |
+
* @param string $form
|
458 |
+
* @return array
|
459 |
+
*/
|
460 |
+
public function generate_captcha_phrase( $form = '' ) {
|
461 |
+
$ops = array(
|
462 |
+
'addition' => '+',
|
463 |
+
'subtraction' => '−',
|
464 |
+
'multiplication' => '×',
|
465 |
+
'division' => '÷',
|
466 |
+
);
|
467 |
+
|
468 |
+
$operations = $groups = array();
|
469 |
+
$input = '<input type="text" size="2" length="2" id="mc-input" class="mc-input" name="mc-value" value="" aria-required="true"/>';
|
470 |
+
|
471 |
+
// available operations
|
472 |
+
foreach ( Math_Captcha()->options['general']['mathematical_operations'] as $operation => $enable ) {
|
473 |
+
if ( $enable === true )
|
474 |
+
$operations[] = $operation;
|
475 |
+
}
|
476 |
+
|
477 |
+
// available groups
|
478 |
+
foreach ( Math_Captcha()->options['general']['groups'] as $group => $enable ) {
|
479 |
+
if ( $enable === true )
|
480 |
+
$groups[] = $group;
|
481 |
+
}
|
482 |
+
|
483 |
+
// number of groups
|
484 |
+
$ao = count( $groups );
|
485 |
+
|
486 |
+
// operation
|
487 |
+
$rnd_op = $operations[mt_rand( 0, count( $operations ) - 1 )];
|
488 |
+
$number[3] = $ops[$rnd_op];
|
489 |
+
|
490 |
+
// place where to put empty input
|
491 |
+
$rnd_input = mt_rand( 0, 2 );
|
492 |
+
|
493 |
+
// which random operation
|
494 |
+
switch ( $rnd_op ) {
|
495 |
+
case 'addition':
|
496 |
+
if ( $rnd_input === 0 ) {
|
497 |
+
$number[0] = mt_rand( 1, 10 );
|
498 |
+
$number[1] = mt_rand( 1, 89 );
|
499 |
+
} elseif ( $rnd_input === 1 ) {
|
500 |
+
$number[0] = mt_rand( 1, 89 );
|
501 |
+
$number[1] = mt_rand( 1, 10 );
|
502 |
+
} elseif ( $rnd_input === 2 ) {
|
503 |
+
$number[0] = mt_rand( 1, 9 );
|
504 |
+
$number[1] = mt_rand( 1, 10 - $number[0] );
|
505 |
+
}
|
506 |
+
|
507 |
+
$number[2] = $number[0] + $number[1];
|
508 |
+
break;
|
509 |
+
|
510 |
+
case 'subtraction':
|
511 |
+
if ( $rnd_input === 0 ) {
|
512 |
+
$number[0] = mt_rand( 2, 10 );
|
513 |
+
$number[1] = mt_rand( 1, $number[0] - 1 );
|
514 |
+
} elseif ( $rnd_input === 1 ) {
|
515 |
+
$number[0] = mt_rand( 11, 99 );
|
516 |
+
$number[1] = mt_rand( 1, 10 );
|
517 |
+
} elseif ( $rnd_input === 2 ) {
|
518 |
+
$number[0] = mt_rand( 11, 99 );
|
519 |
+
$number[1] = mt_rand( $number[0] - 10, $number[0] - 1 );
|
520 |
+
}
|
521 |
+
|
522 |
+
$number[2] = $number[0] - $number[1];
|
523 |
+
break;
|
524 |
+
|
525 |
+
case 'multiplication':
|
526 |
+
if ( $rnd_input === 0 ) {
|
527 |
+
$number[0] = mt_rand( 1, 10 );
|
528 |
+
$number[1] = mt_rand( 1, 9 );
|
529 |
+
} elseif ( $rnd_input === 1 ) {
|
530 |
+
$number[0] = mt_rand( 1, 9 );
|
531 |
+
$number[1] = mt_rand( 1, 10 );
|
532 |
+
} elseif ( $rnd_input === 2 ) {
|
533 |
+
$number[0] = mt_rand( 1, 10 );
|
534 |
+
$number[1] = ($number[0] > 5 ? 1 : ($number[0] === 4 && $number[0] === 5 ? mt_rand( 1, 2 ) : ($number[0] === 3 ? mt_rand( 1, 3 ) : ($number[0] === 2 ? mt_rand( 1, 5 ) : mt_rand( 1, 10 )))));
|
535 |
+
}
|
536 |
+
|
537 |
+
$number[2] = $number[0] * $number[1];
|
538 |
+
break;
|
539 |
+
|
540 |
+
case 'division':
|
541 |
+
$divide = array( 1 => 99, 2 => 49, 3 => 33, 4 => 24, 5 => 19, 6 => 16, 7 => 14, 8 => 12, 9 => 11, 10 => 9 );
|
542 |
+
|
543 |
+
if ( $rnd_input === 0 ) {
|
544 |
+
$divide = array( 2 => array( 1, 2 ), 3 => array( 1, 3 ), 4 => array( 1, 2, 4 ), 5 => array( 1, 5 ), 6 => array( 1, 2, 3, 6 ), 7 => array( 1, 7 ), 8 => array( 1, 2, 4, 8 ), 9 => array( 1, 3, 9 ), 10 => array( 1, 2, 5, 10 ) );
|
545 |
+
$number[0] = mt_rand( 2, 10 );
|
546 |
+
$number[1] = $divide[$number[0]][mt_rand( 0, count( $divide[$number[0]] ) - 1 )];
|
547 |
+
} elseif ( $rnd_input === 1 ) {
|
548 |
+
$number[1] = mt_rand( 1, 10 );
|
549 |
+
$number[0] = $number[1] * mt_rand( 1, $divide[$number[1]] );
|
550 |
+
} elseif ( $rnd_input === 2 ) {
|
551 |
+
$number[2] = mt_rand( 1, 10 );
|
552 |
+
$number[0] = $number[2] * mt_rand( 1, $divide[$number[2]] );
|
553 |
+
$number[1] = (int) ($number[0] / $number[2]);
|
554 |
+
}
|
555 |
+
|
556 |
+
if ( ! isset( $number[2] ) )
|
557 |
+
$number[2] = (int) ($number[0] / $number[1]);
|
558 |
+
|
559 |
+
break;
|
560 |
+
}
|
561 |
+
|
562 |
+
// words
|
563 |
+
if ( $ao === 1 && $groups[0] === 'words' ) {
|
564 |
+
if ( $rnd_input === 0 ) {
|
565 |
+
$number[1] = $this->numberToWords( $number[1] );
|
566 |
+
$number[2] = $this->numberToWords( $number[2] );
|
567 |
+
} elseif ( $rnd_input === 1 ) {
|
568 |
+
$number[0] = $this->numberToWords( $number[0] );
|
569 |
+
$number[2] = $this->numberToWords( $number[2] );
|
570 |
+
} elseif ( $rnd_input === 2 ) {
|
571 |
+
$number[0] = $this->numberToWords( $number[0] );
|
572 |
+
$number[1] = $this->numberToWords( $number[1] );
|
573 |
+
}
|
574 |
+
}
|
575 |
+
// numbers and words
|
576 |
+
elseif ( $ao === 2 ) {
|
577 |
+
if ( $rnd_input === 0 ) {
|
578 |
+
if ( mt_rand( 1, 2 ) === 2 ) {
|
579 |
+
$number[1] = $this->numberToWords( $number[1] );
|
580 |
+
$number[2] = $this->numberToWords( $number[2] );
|
581 |
+
} else
|
582 |
+
$number[$tmp = mt_rand( 1, 2 )] = $this->numberToWords( $number[$tmp] );
|
583 |
+
}
|
584 |
+
elseif ( $rnd_input === 1 ) {
|
585 |
+
if ( mt_rand( 1, 2 ) === 2 ) {
|
586 |
+
$number[0] = $this->numberToWords( $number[0] );
|
587 |
+
$number[2] = $this->numberToWords( $number[2] );
|
588 |
+
} else
|
589 |
+
$number[$tmp = array_rand( array( 0 => 0, 2 => 2 ), 1 )] = $this->numberToWords( $number[$tmp] );
|
590 |
+
}
|
591 |
+
elseif ( $rnd_input === 2 ) {
|
592 |
+
if ( mt_rand( 1, 2 ) === 2 ) {
|
593 |
+
$number[0] = $this->numberToWords( $number[0] );
|
594 |
+
$number[1] = $this->numberToWords( $number[1] );
|
595 |
+
} else
|
596 |
+
$number[$tmp = mt_rand( 0, 1 )] = $this->numberToWords( $number[$tmp] );
|
597 |
+
}
|
598 |
+
}
|
599 |
+
|
600 |
+
if ( in_array( $form, array( 'default', 'bbpress' ), true ) ) {
|
601 |
+
// position of empty input
|
602 |
+
if ( $rnd_input === 0 )
|
603 |
+
$return = $input . ' ' . $number[3] . ' ' . $this->encode_operation( $number[1] ) . ' = ' . $this->encode_operation( $number[2] );
|
604 |
+
elseif ( $rnd_input === 1 )
|
605 |
+
$return = $this->encode_operation( $number[0] ) . ' ' . $number[3] . ' ' . $input . ' = ' . $this->encode_operation( $number[2] );
|
606 |
+
elseif ( $rnd_input === 2 )
|
607 |
+
$return = $this->encode_operation( $number[0] ) . ' ' . $number[3] . ' ' . $this->encode_operation( $number[1] ) . ' = ' . $input;
|
608 |
+
|
609 |
+
$transient_name = ($form === 'bbpress' ? 'bbp' : 'mc');
|
610 |
+
$session_id = Math_Captcha()->cookie_session->session_ids['default'];
|
611 |
+
}
|
612 |
+
elseif ( $form === 'cf7' ) {
|
613 |
+
$return = array();
|
614 |
+
|
615 |
+
if ( $rnd_input === 0 ) {
|
616 |
+
$return['input'] = 1;
|
617 |
+
$return[2] = ' ' . $number[3] . ' ' . $this->encode_operation( $number[1] ) . ' = ';
|
618 |
+
$return[3] = $this->encode_operation( $number[2] );
|
619 |
+
} elseif ( $rnd_input === 1 ) {
|
620 |
+
$return[1] = $this->encode_operation( $number[0] ) . ' ' . $number[3] . ' ';
|
621 |
+
$return['input'] = 2;
|
622 |
+
$return[3] = ' = ' . $this->encode_operation( $number[2] );
|
623 |
+
} elseif ( $rnd_input === 2 ) {
|
624 |
+
$return[1] = $this->encode_operation( $number[0] ) . ' ' . $number[3] . ' ';
|
625 |
+
$return[2] = $this->encode_operation( $number[1] ) . ' = ';
|
626 |
+
$return['input'] = 3;
|
627 |
+
}
|
628 |
+
|
629 |
+
$transient_name = 'cf7';
|
630 |
+
$session_id = Math_Captcha()->cookie_session->session_ids['multi'][$this->session_number ++];
|
631 |
+
}
|
632 |
+
|
633 |
+
set_transient( $transient_name . '_' . $session_id, sha1( AUTH_KEY . $number[$rnd_input] . $session_id, false ), apply_filters( 'math_captcha_time', Math_Captcha()->options['general']['time'] ) );
|
634 |
+
|
635 |
+
return $return;
|
636 |
+
}
|
637 |
+
|
638 |
+
/**
|
639 |
+
* FLush rewrite rules.
|
640 |
+
*/
|
641 |
+
public function flush_rewrites() {
|
642 |
+
if ( Math_Captcha()->options['general']['flush_rules'] ) {
|
643 |
+
global $wp_rewrite;
|
644 |
+
|
645 |
+
$wp_rewrite->flush_rules();
|
646 |
+
|
647 |
+
Math_Captcha()->options['general']['flush_rules'] = false;
|
648 |
+
update_option( 'math_captcha_options', Math_Captcha()->options['general'] );
|
649 |
+
}
|
650 |
+
}
|
651 |
+
|
652 |
+
/**
|
653 |
+
* Block direct comments.
|
654 |
+
*
|
655 |
+
* @param string $rules
|
656 |
+
* @return string
|
657 |
+
*/
|
658 |
+
public function block_direct_comments( $rules ) {
|
659 |
+
if ( Math_Captcha()->options['general']['block_direct_comments'] ) {
|
660 |
+
$new_rules = <<<EOT
|
661 |
+
\n# BEGIN Math Captcha
|
662 |
+
<IfModule mod_rewrite.c>
|
663 |
+
RewriteEngine On
|
664 |
+
RewriteCond %{REQUEST_METHOD} POST
|
665 |
+
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
|
666 |
+
RewriteCond %{HTTP_REFERER} !.*{$_SERVER['HTTP_HOST']}.* [OR]
|
667 |
+
RewriteCond %{HTTP_USER_AGENT} ^$
|
668 |
+
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
|
669 |
+
</IfModule>
|
670 |
+
# END Math Captcha\n\n
|
671 |
+
EOT;
|
672 |
+
|
673 |
+
return $new_rules . $rules;
|
674 |
+
}
|
675 |
+
|
676 |
+
return $rules;
|
677 |
+
}
|
678 |
+
|
679 |
}
|
includes/class-settings.php
CHANGED
@@ -1,343 +1,316 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
public $
|
11 |
-
public $
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
add_action( '
|
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 |
-
public function options_page() {
|
65 |
-
echo '
|
66 |
-
<div class="wrap">
|
67 |
-
<h2>' . __( 'Math Captcha', 'math-captcha' ) . '</h2>
|
68 |
-
<div class="math-captcha-settings">
|
69 |
-
<div class="df-credits">
|
70 |
-
<h3 class="hndle">' . __( 'Math Captcha', 'math-captcha' ) . ' ' . Math_Captcha()->defaults['version'] . '</h3>
|
71 |
-
<div class="inside">
|
72 |
-
<h4 class="inner">' . __( 'Need support?', 'math-captcha' ) . '</h4>
|
73 |
-
<p class="inner">' . __( 'If you are having problems with this plugin, please talk about them in the', 'math-captcha' ) . ' <a href="http://www.dfactory.eu/support/?utm_source=math-captcha-settings&utm_medium=link&utm_campaign=support" target="_blank" title="' . __( 'Support forum', 'math-captcha' ) . '">' . __( 'Support forum', 'math-captcha' ) . '</a></p>
|
74 |
-
<hr/>
|
75 |
-
<h4 class="inner">' . __( 'Do you like this plugin?', 'math-captcha' ) . '</h4>
|
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 |
-
add_settings_field( '
|
121 |
-
add_settings_field( '
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
echo '
|
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 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
// hide for logged in users
|
317 |
-
$input['hide_for_logged_users'] = isset( $input['hide_for_logged_users'] );
|
318 |
-
|
319 |
-
// block direct comments access
|
320 |
-
$input['block_direct_comments'] = isset( $input['block_direct_comments'] );
|
321 |
-
|
322 |
-
// deactivation delete
|
323 |
-
$input['deactivation_delete'] = isset( $input['deactivation_delete'] );
|
324 |
-
|
325 |
-
// captcha title
|
326 |
-
$input['title'] = trim( $input['title'] );
|
327 |
-
|
328 |
-
// captcha time
|
329 |
-
$time = (int) $input['time'];
|
330 |
-
$input['time'] = ($time < 0 ? Math_Captcha()->defaults['general']['time'] : $time);
|
331 |
-
|
332 |
-
// flush rules
|
333 |
-
$input['flush_rules'] = true;
|
334 |
-
} elseif ( isset( $_POST['reset_mc_general'] ) ) {
|
335 |
-
$input = Math_Captcha()->defaults['general'];
|
336 |
-
|
337 |
-
add_settings_error( 'settings', 'settings_reset', __( 'Settings restored to defaults.', 'math-captcha' ), 'updated' );
|
338 |
-
}
|
339 |
-
|
340 |
-
return $input;
|
341 |
-
}
|
342 |
-
|
343 |
}
|
1 |
+
<?php
|
2 |
+
// exit if accessed directly
|
3 |
+
if ( ! defined( 'ABSPATH' ) )
|
4 |
+
exit;
|
5 |
+
|
6 |
+
new Math_Captcha_Settings();
|
7 |
+
|
8 |
+
class Math_Captcha_Settings {
|
9 |
+
|
10 |
+
public $mathematical_operations;
|
11 |
+
public $groups;
|
12 |
+
public $forms;
|
13 |
+
|
14 |
+
public function __construct() {
|
15 |
+
// actions
|
16 |
+
add_action( 'init', array( &$this, 'load_defaults' ) );
|
17 |
+
add_action( 'admin_init', array( &$this, 'register_settings' ) );
|
18 |
+
add_action( 'admin_menu', array( &$this, 'admin_menu_options' ) );
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Load defaults.
|
23 |
+
*/
|
24 |
+
public function load_defaults() {
|
25 |
+
if ( ! is_admin() )
|
26 |
+
return;
|
27 |
+
|
28 |
+
$this->forms = array(
|
29 |
+
'login_form' => __( 'login form', 'math-captcha' ),
|
30 |
+
'registration_form' => __( 'registration form', 'math-captcha' ),
|
31 |
+
'reset_password_form' => __( 'reset password form', 'math-captcha' ),
|
32 |
+
'comment_form' => __( 'comment form', 'math-captcha' ),
|
33 |
+
'bbpress' => __( 'bbpress', 'math-captcha' ),
|
34 |
+
'contact_form_7' => __( 'contact form 7', 'math-captcha' )
|
35 |
+
);
|
36 |
+
|
37 |
+
$this->mathematical_operations = array(
|
38 |
+
'addition' => __( 'addition (+)', 'math-captcha' ),
|
39 |
+
'subtraction' => __( 'subtraction (-)', 'math-captcha' ),
|
40 |
+
'multiplication' => __( 'multiplication (×)', 'math-captcha' ),
|
41 |
+
'division' => __( 'division (÷)', 'math-captcha' )
|
42 |
+
);
|
43 |
+
|
44 |
+
$this->groups = array(
|
45 |
+
'numbers' => __( 'numbers', 'math-captcha' ),
|
46 |
+
'words' => __( 'words', 'math-captcha' )
|
47 |
+
);
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Add options menu.
|
52 |
+
*/
|
53 |
+
public function admin_menu_options() {
|
54 |
+
add_options_page(
|
55 |
+
__( 'Math Captcha', 'math-captcha' ), __( 'Math Captcha', 'math-captcha' ), 'manage_options', 'math-captcha', array( &$this, 'options_page' )
|
56 |
+
);
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Render options page.
|
61 |
+
*
|
62 |
+
* @return mixed
|
63 |
+
*/
|
64 |
+
public function options_page() {
|
65 |
+
echo '
|
66 |
+
<div class="wrap">
|
67 |
+
<h2>' . __( 'Math Captcha', 'math-captcha' ) . '</h2>
|
68 |
+
<div class="math-captcha-settings">
|
69 |
+
<div class="df-credits">
|
70 |
+
<h3 class="hndle">' . __( 'Math Captcha', 'math-captcha' ) . ' ' . Math_Captcha()->defaults['version'] . '</h3>
|
71 |
+
<div class="inside">
|
72 |
+
<h4 class="inner">' . __( 'Need support?', 'math-captcha' ) . '</h4>
|
73 |
+
<p class="inner">' . __( 'If you are having problems with this plugin, please talk about them in the', 'math-captcha' ) . ' <a href="http://www.dfactory.eu/support/?utm_source=math-captcha-settings&utm_medium=link&utm_campaign=support" target="_blank" title="' . __( 'Support forum', 'math-captcha' ) . '">' . __( 'Support forum', 'math-captcha' ) . '</a></p>
|
74 |
+
<hr/>
|
75 |
+
<h4 class="inner">' . __( 'Do you like this plugin?', 'math-captcha' ) . '</h4>
|
76 |
+
<p class="inner"><a href="http://wordpress.org/support/view/plugin-reviews/wp-math-captcha" target="_blank" title="' . __( 'Rate it 5', 'math-captcha' ) . '">' . __( 'Rate it 5', 'math-captcha' ) . '</a> ' . __( 'on WordPress.org', 'math-captcha' ) . '<br/>' .
|
77 |
+
__( 'Blog about it & link to the', 'math-captcha' ) . ' <a href="http://www.dfactory.eu/plugins/math-captcha/?utm_source=math-captcha-settings&utm_medium=link&utm_campaign=blog-about" target="_blank" title="' . __( 'plugin page', 'math-captcha' ) . '">' . __( 'plugin page', 'math-captcha' ) . '</a><br/>' .
|
78 |
+
__( 'Check out our other', 'math-captcha' ) . ' <a href="http://www.dfactory.eu/plugins/?utm_source=math-captcha-settings&utm_medium=link&utm_campaign=other-plugins" target="_blank" title="' . __( 'WordPress plugins', 'math-captcha' ) . '">' . __( 'WordPress plugins', 'math-captcha' ) . '</a>
|
79 |
+
</p>
|
80 |
+
<hr/>
|
81 |
+
<p class="df-link inner">Created by <a href="http://www.dfactory.eu/?utm_source=math-captcha-settings&utm_medium=link&utm_campaign=created-by" target="_blank" title="dFactory - Quality plugins for WordPress"><img src="' . MATH_CAPTCHA_URL . '/images/logo-dfactory.png" title="dFactory - Quality plugins for WordPress" alt="dFactory - Quality plugins for WordPress"/></a></p>
|
82 |
+
</div>
|
83 |
+
</div>
|
84 |
+
<form action="options.php" method="post">';
|
85 |
+
|
86 |
+
wp_nonce_field( 'update-options' );
|
87 |
+
settings_fields( 'math_captcha_options' );
|
88 |
+
do_settings_sections( 'math_captcha_options' );
|
89 |
+
|
90 |
+
echo '
|
91 |
+
<p class="submit">';
|
92 |
+
|
93 |
+
submit_button( '', 'primary', 'save_mc_general', false );
|
94 |
+
|
95 |
+
echo ' ';
|
96 |
+
|
97 |
+
submit_button( __( 'Reset to defaults', 'math-captcha' ), 'secondary reset_mc_settings', 'reset_mc_general', false );
|
98 |
+
|
99 |
+
echo '
|
100 |
+
</p>
|
101 |
+
</form>
|
102 |
+
</div>
|
103 |
+
<div class="clear"></div>
|
104 |
+
</div>';
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Register settings.
|
109 |
+
*/
|
110 |
+
public function register_settings() {
|
111 |
+
// general settings
|
112 |
+
register_setting( 'math_captcha_options', 'math_captcha_options', array( &$this, 'validate_settings' ) );
|
113 |
+
add_settings_section( 'math_captcha_settings', __( 'Math Captcha settings', 'math-captcha' ), '', 'math_captcha_options' );
|
114 |
+
add_settings_field( 'mc_general_enable_captcha_for', __( 'Enable Math Captcha for', 'math-captcha' ), array( &$this, 'mc_general_enable_captcha_for' ), 'math_captcha_options', 'math_captcha_settings' );
|
115 |
+
add_settings_field( 'mc_general_hide_for_logged_users', __( 'Hide for logged in users', 'math-captcha' ), array( &$this, 'mc_general_hide_for_logged_users' ), 'math_captcha_options', 'math_captcha_settings' );
|
116 |
+
add_settings_field( 'mc_general_mathematical_operations', __( 'Mathematical operations', 'math-captcha' ), array( &$this, 'mc_general_mathematical_operations' ), 'math_captcha_options', 'math_captcha_settings' );
|
117 |
+
add_settings_field( 'mc_general_groups', __( 'Display captcha as', 'math-captcha' ), array( &$this, 'mc_general_groups' ), 'math_captcha_options', 'math_captcha_settings' );
|
118 |
+
add_settings_field( 'mc_general_title', __( 'Captcha field title', 'math-captcha' ), array( &$this, 'mc_general_title' ), 'math_captcha_options', 'math_captcha_settings' );
|
119 |
+
add_settings_field( 'mc_general_time', __( 'Captcha time', 'math-captcha' ), array( &$this, 'mc_general_time' ), 'math_captcha_options', 'math_captcha_settings' );
|
120 |
+
add_settings_field( 'mc_general_block_direct_comments', __( 'Block Direct Comments', 'math-captcha' ), array( &$this, 'mc_general_block_direct_comments' ), 'math_captcha_options', 'math_captcha_settings' );
|
121 |
+
add_settings_field( 'mc_general_deactivation_delete', __( 'Deactivation', 'math-captcha' ), array( &$this, 'mc_general_deactivation_delete' ), 'math_captcha_options', 'math_captcha_settings' );
|
122 |
+
}
|
123 |
+
|
124 |
+
public function mc_general_enable_captcha_for() {
|
125 |
+
echo '
|
126 |
+
<div id="mc_general_enable_captcha_for">
|
127 |
+
<fieldset>';
|
128 |
+
|
129 |
+
foreach ( $this->forms as $val => $trans ) {
|
130 |
+
echo '
|
131 |
+
<input id="mc-general-enable-captcha-for-' . $val . '" type="checkbox" name="math_captcha_options[enable_for][]" value="' . $val . '" ' . checked( true, Math_Captcha()->options['general']['enable_for'][$val], false ) . ' ' . disabled( (($val === 'contact_form_7' && ! class_exists( 'WPCF7_ContactForm' )) || ($val === 'bbpress' && ! class_exists( 'bbPress' )) ), true, false ) . '/><label for="mc-general-enable-captcha-for-' . $val . '">' . esc_html( $trans ) . '</label>';
|
132 |
+
}
|
133 |
+
|
134 |
+
echo '
|
135 |
+
<br/>
|
136 |
+
<span class="description">' . __( 'Select where you\'d like to use Math Captcha.', 'math-captcha' ) . '</span>
|
137 |
+
</fieldset>
|
138 |
+
</div>';
|
139 |
+
}
|
140 |
+
|
141 |
+
public function mc_general_hide_for_logged_users() {
|
142 |
+
echo '
|
143 |
+
<div id="mc_general_hide_for_logged_users">
|
144 |
+
<fieldset>
|
145 |
+
<input id="mc-general-hide-for-logged" type="checkbox" name="math_captcha_options[hide_for_logged_users]" ' . checked( true, Math_Captcha()->options['general']['hide_for_logged_users'], false ) . '/><label for="mc-general-hide-for-logged">' . __( 'Enable to hide captcha for logged in users.', 'math-captcha' ) . '</label>
|
146 |
+
<br/>
|
147 |
+
<span class="description">' . __( 'Would you like to hide captcha for logged in users?', 'math-captcha' ) . '</span>
|
148 |
+
</fieldset>
|
149 |
+
</div>';
|
150 |
+
}
|
151 |
+
|
152 |
+
public function mc_general_mathematical_operations() {
|
153 |
+
echo '
|
154 |
+
<div id="mc_general_mathematical_operations">
|
155 |
+
<fieldset>';
|
156 |
+
|
157 |
+
foreach ( $this->mathematical_operations as $val => $trans ) {
|
158 |
+
echo '
|
159 |
+
<input id="mc-general-mathematical-operations-' . $val . '" type="checkbox" name="math_captcha_options[mathematical_operations][]" value="' . $val . '" ' . checked( true, Math_Captcha()->options['general']['mathematical_operations'][$val], false ) . '/><label for="mc-general-mathematical-operations-' . $val . '">' . esc_html( $trans ) . '</label>';
|
160 |
+
}
|
161 |
+
|
162 |
+
echo '
|
163 |
+
<br/>
|
164 |
+
<span class="description">' . __( 'Select which mathematical operations to use in your captcha.', 'math-captcha' ) . '</span>
|
165 |
+
</fieldset>
|
166 |
+
</div>';
|
167 |
+
}
|
168 |
+
|
169 |
+
public function mc_general_groups() {
|
170 |
+
echo '
|
171 |
+
<div id="mc_general_groups">
|
172 |
+
<fieldset>';
|
173 |
+
|
174 |
+
foreach ( $this->groups as $val => $trans ) {
|
175 |
+
echo '
|
176 |
+
<input id="mc-general-groups-' . $val . '" type="checkbox" name="math_captcha_options[groups][]" value="' . $val . '" ' . checked( true, Math_Captcha()->options['general']['groups'][$val], false ) . '/><label for="mc-general-groups-' . $val . '">' . esc_html( $trans ) . '</label>';
|
177 |
+
}
|
178 |
+
|
179 |
+
echo '
|
180 |
+
<br/>
|
181 |
+
<span class="description">' . __( 'Select how you\'d like to display you captcha.', 'math-captcha' ) . '</span>
|
182 |
+
</fieldset>
|
183 |
+
</div>';
|
184 |
+
}
|
185 |
+
|
186 |
+
public function mc_general_title() {
|
187 |
+
echo '
|
188 |
+
<div id="mc_general_title">
|
189 |
+
<fieldset>
|
190 |
+
<input type="text" name="math_captcha_options[title]" value="' . Math_Captcha()->options['general']['title'] . '"/>
|
191 |
+
<br/>
|
192 |
+
<span class="description">' . __( 'How to entitle field with captcha?', 'math-captcha' ) . '</span>
|
193 |
+
</fieldset>
|
194 |
+
</div>';
|
195 |
+
}
|
196 |
+
|
197 |
+
public function mc_general_time() {
|
198 |
+
echo '
|
199 |
+
<div id="mc_general_time">
|
200 |
+
<fieldset>
|
201 |
+
<input type="text" name="math_captcha_options[time]" value="' . Math_Captcha()->options['general']['time'] . '"/>
|
202 |
+
<br/>
|
203 |
+
<span class="description">' . __( 'Enter the time (in seconds) a user has to enter captcha value.', 'math-captcha' ) . '</span>
|
204 |
+
</fieldset>
|
205 |
+
</div>';
|
206 |
+
}
|
207 |
+
|
208 |
+
public function mc_general_block_direct_comments() {
|
209 |
+
echo '
|
210 |
+
<div id="mc_general_block_direct_comments">
|
211 |
+
<fieldset>
|
212 |
+
<input id="mc-general-block-direct-comments" type="checkbox" name="math_captcha_options[block_direct_comments]" ' . checked( true, Math_Captcha()->options['general']['block_direct_comments'], false ) . '/><label for="mc-general-block-direct-comments">' . __( 'Block direct access to wp-comments-post.php.', 'math-captcha' ) . '</label>
|
213 |
+
<br/>
|
214 |
+
<span class="description">' . __( 'Enable this to prevent spambots from posting to Wordpress via a URL.', 'math-captcha' ) . '</span>
|
215 |
+
</fieldset>
|
216 |
+
</div>';
|
217 |
+
}
|
218 |
+
|
219 |
+
public function mc_general_deactivation_delete() {
|
220 |
+
echo '
|
221 |
+
<div id="mc_general_deactivation_delete">
|
222 |
+
<fieldset>
|
223 |
+
<input id="mc-general-deactivation-delete" type="checkbox" name="math_captcha_options[deactivation_delete]" ' . checked( true, Math_Captcha()->options['general']['deactivation_delete'], false ) . '/><label for="mc-general-deactivation-delete">' . __( 'Delete settings on plugin deactivation.', 'math-captcha' ) . '</label>
|
224 |
+
<br/>
|
225 |
+
<span class="description">' . __( 'Delete settings on plugin deactivation', 'math-captcha' ) . '</span>
|
226 |
+
</fieldset>
|
227 |
+
</div>';
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Validate settings.
|
232 |
+
*
|
233 |
+
* @param array $input
|
234 |
+
* @return array
|
235 |
+
*/
|
236 |
+
public function validate_settings( $input ) {
|
237 |
+
if ( isset( $_POST['save_mc_general'] ) ) {
|
238 |
+
// enable captcha forms
|
239 |
+
$enable_for = array();
|
240 |
+
|
241 |
+
if ( empty( $input['enable_for'] ) ) {
|
242 |
+
foreach ( Math_Captcha()->defaults['general']['enable_for'] as $enable => $bool ) {
|
243 |
+
$input['enable_for'][$enable] = false;
|
244 |
+
}
|
245 |
+
} else {
|
246 |
+
foreach ( $this->forms as $enable => $trans ) {
|
247 |
+
$enable_for[$enable] = (in_array( $enable, $input['enable_for'] ) ? true : false);
|
248 |
+
}
|
249 |
+
|
250 |
+
$input['enable_for'] = $enable_for;
|
251 |
+
}
|
252 |
+
|
253 |
+
if ( ! class_exists( 'WPCF7_ContactForm' ) && Math_Captcha()->options['general']['enable_for']['contact_form_7'] )
|
254 |
+
$input['enable_for']['contact_form_7'] = true;
|
255 |
+
|
256 |
+
if ( ! class_exists( 'bbPress' ) && Math_Captcha()->options['general']['enable_for']['bbpress'] )
|
257 |
+
$input['enable_for']['bbpress'] = true;
|
258 |
+
|
259 |
+
// enable mathematical operations
|
260 |
+
$mathematical_operations = array();
|
261 |
+
|
262 |
+
if ( empty( $input['mathematical_operations'] ) ) {
|
263 |
+
add_settings_error( 'empty-operations', 'settings_updated', __( 'You need to check at least one mathematical operation. Defaults settings of this option restored.', 'math-captcha' ), 'error' );
|
264 |
+
|
265 |
+
$input['mathematical_operations'] = Math_Captcha()->defaults['general']['mathematical_operations'];
|
266 |
+
} else {
|
267 |
+
foreach ( $this->mathematical_operations as $operation => $trans ) {
|
268 |
+
$mathematical_operations[$operation] = (in_array( $operation, $input['mathematical_operations'] ) ? true : false);
|
269 |
+
}
|
270 |
+
|
271 |
+
$input['mathematical_operations'] = $mathematical_operations;
|
272 |
+
}
|
273 |
+
|
274 |
+
// enable groups
|
275 |
+
$groups = array();
|
276 |
+
|
277 |
+
if ( empty( $input['groups'] ) ) {
|
278 |
+
add_settings_error( 'empty-groups', 'settings_updated', __( 'You need to check at least one group. Defaults settings of this option restored.', 'math-captcha' ), 'error' );
|
279 |
+
|
280 |
+
$input['groups'] = Math_Captcha()->defaults['general']['groups'];
|
281 |
+
} else {
|
282 |
+
foreach ( $this->groups as $group => $trans ) {
|
283 |
+
$groups[$group] = (in_array( $group, $input['groups'] ) ? true : false);
|
284 |
+
}
|
285 |
+
|
286 |
+
$input['groups'] = $groups;
|
287 |
+
}
|
288 |
+
|
289 |
+
// hide for logged in users
|
290 |
+
$input['hide_for_logged_users'] = isset( $input['hide_for_logged_users'] );
|
291 |
+
|
292 |
+
// block direct comments access
|
293 |
+
$input['block_direct_comments'] = isset( $input['block_direct_comments'] );
|
294 |
+
|
295 |
+
// deactivation delete
|
296 |
+
$input['deactivation_delete'] = isset( $input['deactivation_delete'] );
|
297 |
+
|
298 |
+
// captcha title
|
299 |
+
$input['title'] = trim( $input['title'] );
|
300 |
+
|
301 |
+
// captcha time
|
302 |
+
$time = (int) $input['time'];
|
303 |
+
$input['time'] = ($time < 0 ? Math_Captcha()->defaults['general']['time'] : $time);
|
304 |
+
|
305 |
+
// flush rules
|
306 |
+
$input['flush_rules'] = true;
|
307 |
+
} elseif ( isset( $_POST['reset_mc_general'] ) ) {
|
308 |
+
$input = Math_Captcha()->defaults['general'];
|
309 |
+
|
310 |
+
add_settings_error( 'settings', 'settings_reset', __( 'Settings restored to defaults.', 'math-captcha' ), 'updated' );
|
311 |
+
}
|
312 |
+
|
313 |
+
return $input;
|
314 |
+
}
|
315 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
}
|
includes/class-update.php
CHANGED
@@ -1,39 +1,37 @@
|
|
1 |
-
<?php
|
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 |
}
|
1 |
+
<?php
|
2 |
+
// exit if accessed directly
|
3 |
+
if ( ! defined( 'ABSPATH' ) )
|
4 |
+
exit;
|
5 |
+
|
6 |
+
new Math_Captcha_Update();
|
7 |
+
|
8 |
+
class Math_Captcha_Update {
|
9 |
+
|
10 |
+
public function __construct() {
|
11 |
+
// actions
|
12 |
+
add_action( 'init', array( &$this, 'check_update' ) );
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Check update.
|
17 |
+
*/
|
18 |
+
public function check_update() {
|
19 |
+
if ( ! is_admin() || ! current_user_can( 'manage_options' ) )
|
20 |
+
return;
|
21 |
+
|
22 |
+
// gets current database version
|
23 |
+
$current_db_version = get_option( 'math_captcha_version', '1.0.0' );
|
24 |
+
|
25 |
+
// new version?
|
26 |
+
if ( version_compare( $current_db_version, Math_Captcha()->defaults['version'], '<' ) ) {
|
27 |
+
if ( version_compare( $current_db_version, '1.0.9', '<' ) ) {
|
28 |
+
update_option( 'math_captcha_options', Math_Captcha()->options['general'] );
|
29 |
+
delete_option( 'mc_options' );
|
30 |
+
}
|
31 |
+
|
32 |
+
// updates plugin version
|
33 |
+
update_option( 'math_captcha_version', Math_Captcha()->defaults['version'] );
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
|
|
|
|
37 |
}
|
includes/integrations/contact-form-7.php
CHANGED
@@ -1,179 +1,179 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* A module for [mathcaptcha]
|
4 |
-
*/
|
5 |
-
|
6 |
-
// shortcode handler
|
7 |
-
add_action( 'init', 'wpcf7_add_shortcode_mathcaptcha', 5 );
|
8 |
-
|
9 |
-
function wpcf7_add_shortcode_mathcaptcha() {
|
10 |
-
|
11 |
-
}
|
12 |
-
|
13 |
-
function wpcf7_mathcaptcha_shortcode_handler( $tag ) {
|
14 |
-
if ( ! is_user_logged_in() || (is_user_logged_in() && ! Math_Captcha()->options['general']['hide_for_logged_users']) ) {
|
15 |
-
$tag = new
|
16 |
-
|
17 |
-
if ( empty( $tag->name ) )
|
18 |
-
return '';
|
19 |
-
|
20 |
-
$validation_error = wpcf7_get_validation_error( $tag->name );
|
21 |
-
$class = wpcf7_form_controls_class( $tag->type );
|
22 |
-
|
23 |
-
if ( $validation_error )
|
24 |
-
$class .= ' wpcf7-not-valid';
|
25 |
-
|
26 |
-
$atts = array();
|
27 |
-
$atts['size'] = 2;
|
28 |
-
$atts['maxlength'] = 2;
|
29 |
-
$atts['class'] = $tag->get_class_option( $class );
|
30 |
-
$atts['id'] = $tag->get_option( 'id', 'id', true );
|
31 |
-
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
|
32 |
-
$atts['aria-required'] = 'true';
|
33 |
-
$atts['type'] = 'text';
|
34 |
-
$atts['name'] = $tag->name;
|
35 |
-
$atts['value'] = '';
|
36 |
-
$atts = wpcf7_format_atts( $atts );
|
37 |
-
|
38 |
-
$mc_form = Math_Captcha()->core->generate_captcha_phrase( 'cf7' );
|
39 |
-
$mc_form[$mc_form['input']] = '<input %2$s />';
|
40 |
-
|
41 |
-
$math_captcha_title = apply_filters( 'math_captcha_title', Math_Captcha()->options['general']['title'] );
|
42 |
-
|
43 |
-
return sprintf( ((empty( $math_captcha_title )) ? '' : $math_captcha_title) . '<span class="wpcf7-form-control-wrap %1$s">' . $mc_form[1] . $mc_form[2] . $mc_form[3] . '%3$s</span><input type="hidden" value="' . (Math_Captcha()->core->session_number - 1) . '" name="' . $tag->name . '-sn" />', $tag->name, $atts, $validation_error );
|
44 |
-
}
|
45 |
-
}
|
46 |
-
|
47 |
-
// validation
|
48 |
-
add_filter( 'wpcf7_validate_mathcaptcha', 'wpcf7_mathcaptcha_validation_filter', 10, 2 );
|
49 |
-
|
50 |
-
function wpcf7_mathcaptcha_validation_filter( $result, $tag ) {
|
51 |
-
$tag = new
|
52 |
-
$name = $tag->name;
|
53 |
-
|
54 |
-
if ( ! is_admin() && isset( $_POST[$name] ) ) {
|
55 |
-
$cf7_version = get_option( 'wpcf7', '1.0.0' );
|
56 |
-
|
57 |
-
if ( is_array( $cf7_version ) && isset( $cf7_version['version'] ) )
|
58 |
-
$cf7_version = $cf7_version['version'];
|
59 |
-
|
60 |
-
if ( $_POST[$name] !== '' ) {
|
61 |
-
$session_id = (isset( $_POST[$name . '-sn'] ) && $_POST[$name . '-sn'] !== '' ? Math_Captcha()->cookie_session->session_ids['multi'][$_POST[$name . '-sn']] : '');
|
62 |
-
|
63 |
-
if ( $session_id !== '' && get_transient( 'cf7_' . $session_id ) !== false ) {
|
64 |
-
if ( strcmp( get_transient( 'cf7_' . $session_id ), sha1( AUTH_KEY . $_POST[$name] . $session_id, false ) ) !== 0 ) {
|
65 |
-
if ( version_compare( $cf7_version, '4.1.0', '>=' ) )
|
66 |
-
$result->invalidate( $tag, wpcf7_get_message( 'wrong_mathcaptcha' ) );
|
67 |
-
else {
|
68 |
-
$result['valid'] = false;
|
69 |
-
$result['reason'][$name] = wpcf7_get_message( 'wrong_mathcaptcha' );
|
70 |
-
}
|
71 |
-
}
|
72 |
-
} else {
|
73 |
-
if ( version_compare( $cf7_version, '4.1.0', '>=' ) )
|
74 |
-
$result->invalidate( $tag, wpcf7_get_message( 'time_mathcaptcha' ) );
|
75 |
-
else {
|
76 |
-
$result['valid'] = false;
|
77 |
-
$result['reason'][$name] = wpcf7_get_message( 'time_mathcaptcha' );
|
78 |
-
}
|
79 |
-
}
|
80 |
-
} else {
|
81 |
-
if ( version_compare( $cf7_version, '4.1.0', '>=' ) )
|
82 |
-
$result->invalidate( $tag, wpcf7_get_message( 'fill_mathcaptcha' ) );
|
83 |
-
else {
|
84 |
-
$result['valid'] = false;
|
85 |
-
$result['reason'][$name] = wpcf7_get_message( 'fill_mathcaptcha' );
|
86 |
-
}
|
87 |
-
}
|
88 |
-
}
|
89 |
-
|
90 |
-
return $result;
|
91 |
-
}
|
92 |
-
|
93 |
-
// messages
|
94 |
-
add_filter( 'wpcf7_messages', 'wpcf7_mathcaptcha_messages' );
|
95 |
-
|
96 |
-
function wpcf7_mathcaptcha_messages( $messages ) {
|
97 |
-
return array_merge(
|
98 |
-
$messages, array(
|
99 |
-
'wrong_mathcaptcha' => array(
|
100 |
-
'description' => __( 'Invalid captcha value.', 'math-captcha' ),
|
101 |
-
'default' => Math_Captcha()->core->error_messages['wrong']
|
102 |
-
),
|
103 |
-
'fill_mathcaptcha' => array(
|
104 |
-
'description' => __( 'Please enter captcha value.', 'math-captcha' ),
|
105 |
-
'default' => Math_Captcha()->core->error_messages['fill']
|
106 |
-
),
|
107 |
-
'time_mathcaptcha' => array(
|
108 |
-
'description' => __( 'Captcha time expired.', 'math-captcha' ),
|
109 |
-
'default' => Math_Captcha()->core->error_messages['time']
|
110 |
-
)
|
111 |
-
)
|
112 |
-
);
|
113 |
-
}
|
114 |
-
|
115 |
-
// warning message
|
116 |
-
add_action( 'wpcf7_admin_notices', 'wpcf7_mathcaptcha_display_warning_message' );
|
117 |
-
|
118 |
-
function wpcf7_mathcaptcha_display_warning_message() {
|
119 |
-
if ( empty( $_GET['post'] ) || ! ($contact_form = wpcf7_contact_form( $_GET['post'] )) )
|
120 |
-
return;
|
121 |
-
|
122 |
-
$has_tags = (bool) $contact_form->form_scan_shortcode( array( 'type' => array( 'mathcaptcha' ) ) );
|
123 |
-
|
124 |
-
if ( ! $has_tags )
|
125 |
-
return;
|
126 |
-
}
|
127 |
-
|
128 |
-
// tag generator
|
129 |
-
add_action( 'admin_init', 'wpcf7_add_tag_generator_mathcaptcha', 45 );
|
130 |
-
|
131 |
-
function wpcf7_add_tag_generator_mathcaptcha() {
|
132 |
-
if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
|
133 |
-
return;
|
134 |
-
|
135 |
-
wpcf7_add_tag_generator( 'mathcaptcha', __( 'Math Captcha', 'math-captcha' ), 'wpcf7-mathcaptcha', 'wpcf7_tg_pane_mathcaptcha' );
|
136 |
-
}
|
137 |
-
|
138 |
-
function wpcf7_tg_pane_mathcaptcha( $contact_form ) {
|
139 |
-
echo '
|
140 |
-
<div class="control-box">
|
141 |
-
<fieldset>
|
142 |
-
<table class="form-table">
|
143 |
-
<tbody>
|
144 |
-
<tr>
|
145 |
-
<th scope="row">
|
146 |
-
<label for="tag-generator-panel-mathcaptcha-name">' . esc_html__( 'Name', 'contact-form-7' ) . '</label>
|
147 |
-
</th>
|
148 |
-
<td>
|
149 |
-
<input type="text" name="name" class="tg-name oneline" id="tag-generator-panel-mathcaptcha-name" />
|
150 |
-
</td>
|
151 |
-
</tr>
|
152 |
-
<tr>
|
153 |
-
<th scope="row">
|
154 |
-
<label for="tag-generator-panel-mathcaptcha-id">' . esc_html__( 'Id attribute', 'contact-form-7' ) . '</label>
|
155 |
-
</th>
|
156 |
-
<td>
|
157 |
-
<input type="text" name="id" class="idvalue oneline option" id="tag-generator-panel-mathcaptcha-id" />
|
158 |
-
</td>
|
159 |
-
</tr>
|
160 |
-
<tr>
|
161 |
-
<th scope="row">
|
162 |
-
<label for="tag-generator-panel-mathcaptcha-class">' . esc_html__( 'Class attribute', 'contact-form-7' ) . '</label>
|
163 |
-
</th>
|
164 |
-
<td>
|
165 |
-
<input type="text" name="class" class="classvalue oneline option" id="tag-generator-panel-mathcaptcha-class" />
|
166 |
-
</td>
|
167 |
-
</tr>
|
168 |
-
</tbody>
|
169 |
-
</table>
|
170 |
-
</fieldset>
|
171 |
-
</div>
|
172 |
-
<div class="insert-box">
|
173 |
-
<input type="text" name="mathcaptcha" class="tag code" readonly="readonly" onfocus="this.select();">
|
174 |
-
<div class="submitbox">
|
175 |
-
<input type="button" class="button button-primary insert-tag" value="' . esc_attr__( 'Insert Tag', 'contact-form-7' ) . '">
|
176 |
-
</div>
|
177 |
-
<br class="clear">
|
178 |
-
</div>';
|
179 |
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* A module for [mathcaptcha]
|
4 |
+
*/
|
5 |
+
|
6 |
+
// shortcode handler
|
7 |
+
add_action( 'init', 'wpcf7_add_shortcode_mathcaptcha', 5 );
|
8 |
+
|
9 |
+
function wpcf7_add_shortcode_mathcaptcha() {
|
10 |
+
wpcf7_add_form_tag( 'mathcaptcha', 'wpcf7_mathcaptcha_shortcode_handler', true );
|
11 |
+
}
|
12 |
+
|
13 |
+
function wpcf7_mathcaptcha_shortcode_handler( $tag ) {
|
14 |
+
if ( ! is_user_logged_in() || (is_user_logged_in() && ! Math_Captcha()->options['general']['hide_for_logged_users']) ) {
|
15 |
+
$tag = new WPCF7_FormTag( $tag );
|
16 |
+
|
17 |
+
if ( empty( $tag->name ) )
|
18 |
+
return '';
|
19 |
+
|
20 |
+
$validation_error = wpcf7_get_validation_error( $tag->name );
|
21 |
+
$class = wpcf7_form_controls_class( $tag->type );
|
22 |
+
|
23 |
+
if ( $validation_error )
|
24 |
+
$class .= ' wpcf7-not-valid';
|
25 |
+
|
26 |
+
$atts = array();
|
27 |
+
$atts['size'] = 2;
|
28 |
+
$atts['maxlength'] = 2;
|
29 |
+
$atts['class'] = $tag->get_class_option( $class );
|
30 |
+
$atts['id'] = $tag->get_option( 'id', 'id', true );
|
31 |
+
$atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );
|
32 |
+
$atts['aria-required'] = 'true';
|
33 |
+
$atts['type'] = 'text';
|
34 |
+
$atts['name'] = $tag->name;
|
35 |
+
$atts['value'] = '';
|
36 |
+
$atts = wpcf7_format_atts( $atts );
|
37 |
+
|
38 |
+
$mc_form = Math_Captcha()->core->generate_captcha_phrase( 'cf7' );
|
39 |
+
$mc_form[$mc_form['input']] = '<input %2$s />';
|
40 |
+
|
41 |
+
$math_captcha_title = apply_filters( 'math_captcha_title', Math_Captcha()->options['general']['title'] );
|
42 |
+
|
43 |
+
return sprintf( ((empty( $math_captcha_title )) ? '' : $math_captcha_title) . '<span class="wpcf7-form-control-wrap %1$s">' . $mc_form[1] . $mc_form[2] . $mc_form[3] . '%3$s</span><input type="hidden" value="' . (Math_Captcha()->core->session_number - 1) . '" name="' . $tag->name . '-sn" />', $tag->name, $atts, $validation_error );
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
// validation
|
48 |
+
add_filter( 'wpcf7_validate_mathcaptcha', 'wpcf7_mathcaptcha_validation_filter', 10, 2 );
|
49 |
+
|
50 |
+
function wpcf7_mathcaptcha_validation_filter( $result, $tag ) {
|
51 |
+
$tag = new WPCF7_FormTag( $tag );
|
52 |
+
$name = $tag->name;
|
53 |
+
|
54 |
+
if ( ! is_admin() && isset( $_POST[$name] ) ) {
|
55 |
+
$cf7_version = get_option( 'wpcf7', '1.0.0' );
|
56 |
+
|
57 |
+
if ( is_array( $cf7_version ) && isset( $cf7_version['version'] ) )
|
58 |
+
$cf7_version = $cf7_version['version'];
|
59 |
+
|
60 |
+
if ( $_POST[$name] !== '' ) {
|
61 |
+
$session_id = (isset( $_POST[$name . '-sn'] ) && $_POST[$name . '-sn'] !== '' ? Math_Captcha()->cookie_session->session_ids['multi'][$_POST[$name . '-sn']] : '');
|
62 |
+
|
63 |
+
if ( $session_id !== '' && get_transient( 'cf7_' . $session_id ) !== false ) {
|
64 |
+
if ( strcmp( get_transient( 'cf7_' . $session_id ), sha1( AUTH_KEY . $_POST[$name] . $session_id, false ) ) !== 0 ) {
|
65 |
+
if ( version_compare( $cf7_version, '4.1.0', '>=' ) )
|
66 |
+
$result->invalidate( $tag, wpcf7_get_message( 'wrong_mathcaptcha' ) );
|
67 |
+
else {
|
68 |
+
$result['valid'] = false;
|
69 |
+
$result['reason'][$name] = wpcf7_get_message( 'wrong_mathcaptcha' );
|
70 |
+
}
|
71 |
+
}
|
72 |
+
} else {
|
73 |
+
if ( version_compare( $cf7_version, '4.1.0', '>=' ) )
|
74 |
+
$result->invalidate( $tag, wpcf7_get_message( 'time_mathcaptcha' ) );
|
75 |
+
else {
|
76 |
+
$result['valid'] = false;
|
77 |
+
$result['reason'][$name] = wpcf7_get_message( 'time_mathcaptcha' );
|
78 |
+
}
|
79 |
+
}
|
80 |
+
} else {
|
81 |
+
if ( version_compare( $cf7_version, '4.1.0', '>=' ) )
|
82 |
+
$result->invalidate( $tag, wpcf7_get_message( 'fill_mathcaptcha' ) );
|
83 |
+
else {
|
84 |
+
$result['valid'] = false;
|
85 |
+
$result['reason'][$name] = wpcf7_get_message( 'fill_mathcaptcha' );
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
|
90 |
+
return $result;
|
91 |
+
}
|
92 |
+
|
93 |
+
// messages
|
94 |
+
add_filter( 'wpcf7_messages', 'wpcf7_mathcaptcha_messages' );
|
95 |
+
|
96 |
+
function wpcf7_mathcaptcha_messages( $messages ) {
|
97 |
+
return array_merge(
|
98 |
+
$messages, array(
|
99 |
+
'wrong_mathcaptcha' => array(
|
100 |
+
'description' => __( 'Invalid captcha value.', 'math-captcha' ),
|
101 |
+
'default' => Math_Captcha()->core->error_messages['wrong']
|
102 |
+
),
|
103 |
+
'fill_mathcaptcha' => array(
|
104 |
+
'description' => __( 'Please enter captcha value.', 'math-captcha' ),
|
105 |
+
'default' => Math_Captcha()->core->error_messages['fill']
|
106 |
+
),
|
107 |
+
'time_mathcaptcha' => array(
|
108 |
+
'description' => __( 'Captcha time expired.', 'math-captcha' ),
|
109 |
+
'default' => Math_Captcha()->core->error_messages['time']
|
110 |
+
)
|
111 |
+
)
|
112 |
+
);
|
113 |
+
}
|
114 |
+
|
115 |
+
// warning message
|
116 |
+
add_action( 'wpcf7_admin_notices', 'wpcf7_mathcaptcha_display_warning_message' );
|
117 |
+
|
118 |
+
function wpcf7_mathcaptcha_display_warning_message() {
|
119 |
+
if ( empty( $_GET['post'] ) || ! ($contact_form = wpcf7_contact_form( $_GET['post'] )) )
|
120 |
+
return;
|
121 |
+
|
122 |
+
$has_tags = (bool) $contact_form->form_scan_shortcode( array( 'type' => array( 'mathcaptcha' ) ) );
|
123 |
+
|
124 |
+
if ( ! $has_tags )
|
125 |
+
return;
|
126 |
+
}
|
127 |
+
|
128 |
+
// tag generator
|
129 |
+
add_action( 'admin_init', 'wpcf7_add_tag_generator_mathcaptcha', 45 );
|
130 |
+
|
131 |
+
function wpcf7_add_tag_generator_mathcaptcha() {
|
132 |
+
if ( ! function_exists( 'wpcf7_add_tag_generator' ) )
|
133 |
+
return;
|
134 |
+
|
135 |
+
wpcf7_add_tag_generator( 'mathcaptcha', __( 'Math Captcha', 'math-captcha' ), 'wpcf7-mathcaptcha', 'wpcf7_tg_pane_mathcaptcha' );
|
136 |
+
}
|
137 |
+
|
138 |
+
function wpcf7_tg_pane_mathcaptcha( $contact_form ) {
|
139 |
+
echo '
|
140 |
+
<div class="control-box">
|
141 |
+
<fieldset>
|
142 |
+
<table class="form-table">
|
143 |
+
<tbody>
|
144 |
+
<tr>
|
145 |
+
<th scope="row">
|
146 |
+
<label for="tag-generator-panel-mathcaptcha-name">' . esc_html__( 'Name', 'contact-form-7' ) . '</label>
|
147 |
+
</th>
|
148 |
+
<td>
|
149 |
+
<input type="text" name="name" class="tg-name oneline" id="tag-generator-panel-mathcaptcha-name" />
|
150 |
+
</td>
|
151 |
+
</tr>
|
152 |
+
<tr>
|
153 |
+
<th scope="row">
|
154 |
+
<label for="tag-generator-panel-mathcaptcha-id">' . esc_html__( 'Id attribute', 'contact-form-7' ) . '</label>
|
155 |
+
</th>
|
156 |
+
<td>
|
157 |
+
<input type="text" name="id" class="idvalue oneline option" id="tag-generator-panel-mathcaptcha-id" />
|
158 |
+
</td>
|
159 |
+
</tr>
|
160 |
+
<tr>
|
161 |
+
<th scope="row">
|
162 |
+
<label for="tag-generator-panel-mathcaptcha-class">' . esc_html__( 'Class attribute', 'contact-form-7' ) . '</label>
|
163 |
+
</th>
|
164 |
+
<td>
|
165 |
+
<input type="text" name="class" class="classvalue oneline option" id="tag-generator-panel-mathcaptcha-class" />
|
166 |
+
</td>
|
167 |
+
</tr>
|
168 |
+
</tbody>
|
169 |
+
</table>
|
170 |
+
</fieldset>
|
171 |
+
</div>
|
172 |
+
<div class="insert-box">
|
173 |
+
<input type="text" name="mathcaptcha" class="tag code" readonly="readonly" onfocus="this.select();">
|
174 |
+
<div class="submitbox">
|
175 |
+
<input type="button" class="button button-primary insert-tag" value="' . esc_attr__( 'Insert Tag', 'contact-form-7' ) . '">
|
176 |
+
</div>
|
177 |
+
<br class="clear">
|
178 |
+
</div>';
|
179 |
}
|
index.php
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
<?php
|
2 |
// Silence is golden.
|
1 |
+
<?php
|
2 |
// Silence is golden.
|
js/admin-settings.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
});
|
|
|
|
|
|
|
|
1 |
+
( function ( $ ) {
|
2 |
+
|
3 |
+
$( document ).ready( function () {
|
4 |
+
// reset options to defaults if needed
|
5 |
+
$( document ).on( 'click', '.reset_mc_settings', function () {
|
6 |
+
return confirm( mcArgsSettings.resetToDefaults );
|
7 |
+
} );
|
8 |
+
|
9 |
+
} );
|
10 |
+
|
11 |
+
} )( jQuery );
|
languages/math-captcha-de_DE.mo
DELETED
Binary file
|
languages/math-captcha-de_DE.po
DELETED
@@ -1,349 +0,0 @@
|
|
1 |
-
msgid ""
|
2 |
-
msgstr ""
|
3 |
-
"Project-Id-Version: Math Captcha\n"
|
4 |
-
"POT-Creation-Date: 2013-08-08 08:01+0100\n"
|
5 |
-
"PO-Revision-Date: 2013-08-08 08:01+0100\n"
|
6 |
-
"Last-Translator: Stephan Hilchenbach <info@elcats.de>\n"
|
7 |
-
"Language-Team: \n"
|
8 |
-
"Language: de-DE\n"
|
9 |
-
"MIME-Version: 1.0\n"
|
10 |
-
"Content-Type: text/plain; charset=U |