Version Description
- New: Multiple Math Captcha on one page support
- New: Chinese translation, thanks to xiaoyaole
- Fix: COntact Form 7 errors and general CF7 support
- Tweak: crypt_key generation changed to AUTH_KEY usage
Download this release
Release Info
Developer | dfactory |
Plugin | Math Captcha |
Version | 1.0.9 |
Comparing to | |
See all releases |
Code changes from version 1.0.8 to 1.0.9
- includes/math-captcha-cf7.php +17 -21
- languages/math-captcha-zh_CN.mo +0 -0
- languages/math-captcha-zh_CN.po +347 -0
- readme.txt +11 -3
- wp-math-captcha.php +222 -162
includes/math-captcha-cf7.php
CHANGED
@@ -13,25 +13,21 @@ function wpcf7_add_shortcode_mathcaptcha()
|
|
13 |
|
14 |
function wpcf7_mathcaptcha_shortcode_handler($tag)
|
15 |
{
|
16 |
-
|
17 |
global $mc_class;
|
18 |
|
19 |
-
if
|
20 |
{
|
21 |
-
|
22 |
$tag = new WPCF7_Shortcode($tag);
|
23 |
-
|
24 |
if(empty($tag->name))
|
25 |
return '';
|
26 |
-
|
27 |
$validation_error = wpcf7_get_validation_error($tag->name);
|
28 |
$class = wpcf7_form_controls_class($tag->type);
|
29 |
-
|
30 |
if($validation_error)
|
31 |
-
{
|
32 |
$class .= ' wpcf7-not-valid';
|
33 |
-
|
34 |
-
|
35 |
$atts = array();
|
36 |
$atts['size'] = 2;
|
37 |
$atts['maxlength'] = 2;
|
@@ -43,16 +39,14 @@ function wpcf7_mathcaptcha_shortcode_handler($tag)
|
|
43 |
$atts['name'] = $tag->name;
|
44 |
$atts['value'] = '';
|
45 |
$atts = wpcf7_format_atts($atts);
|
46 |
-
|
47 |
$mc_form = $mc_class->generate_captcha_phrase('cf7');
|
48 |
$mc_form[$mc_form['input']] = '<input %2$s />';
|
49 |
-
|
50 |
-
$math_captcha_title = apply_filters('math_captcha_title', $mc_class->
|
51 |
-
|
52 |
-
return sprintf(((empty($math_captcha_title)) ? '' :
|
53 |
-
|
54 |
}
|
55 |
-
|
56 |
}
|
57 |
|
58 |
|
@@ -70,9 +64,11 @@ function wpcf7_mathcaptcha_validation_filter($result, $tag)
|
|
70 |
{
|
71 |
if($_POST[$name] !== '')
|
72 |
{
|
73 |
-
|
|
|
|
|
74 |
{
|
75 |
-
if(strcmp(get_transient('cf7_'.$
|
76 |
{
|
77 |
$result['valid'] = FALSE;
|
78 |
$result['reason'][$name] = wpcf7_get_message('wrong_mathcaptcha');
|
@@ -107,15 +103,15 @@ function wpcf7_mathcaptcha_messages($messages)
|
|
107 |
array(
|
108 |
'wrong_mathcaptcha' => array(
|
109 |
'description' => __('Invalid captcha value.', 'math-captcha'),
|
110 |
-
'default' => $mc_class->
|
111 |
),
|
112 |
'fill_mathcaptcha' => array(
|
113 |
'description' => __('Please enter captcha value.', 'math-captcha'),
|
114 |
-
'default' => $mc_class->
|
115 |
),
|
116 |
'time_mathcaptcha' => array(
|
117 |
'description' => __('Captcha time expired.', 'math-captcha'),
|
118 |
-
'default' => $mc_class->
|
119 |
)
|
120 |
)
|
121 |
);
|
13 |
|
14 |
function wpcf7_mathcaptcha_shortcode_handler($tag)
|
15 |
{
|
|
|
16 |
global $mc_class;
|
17 |
|
18 |
+
if(!is_user_logged_in() || (is_user_logged_in() && $mc_class->get_options('hide_for_logged_users') === FALSE))
|
19 |
{
|
|
|
20 |
$tag = new WPCF7_Shortcode($tag);
|
21 |
+
|
22 |
if(empty($tag->name))
|
23 |
return '';
|
24 |
+
|
25 |
$validation_error = wpcf7_get_validation_error($tag->name);
|
26 |
$class = wpcf7_form_controls_class($tag->type);
|
27 |
+
|
28 |
if($validation_error)
|
|
|
29 |
$class .= ' wpcf7-not-valid';
|
30 |
+
|
|
|
31 |
$atts = array();
|
32 |
$atts['size'] = 2;
|
33 |
$atts['maxlength'] = 2;
|
39 |
$atts['name'] = $tag->name;
|
40 |
$atts['value'] = '';
|
41 |
$atts = wpcf7_format_atts($atts);
|
42 |
+
|
43 |
$mc_form = $mc_class->generate_captcha_phrase('cf7');
|
44 |
$mc_form[$mc_form['input']] = '<input %2$s />';
|
45 |
+
|
46 |
+
$math_captcha_title = apply_filters('math_captcha_title', $mc_class->get_options('title'));
|
47 |
+
|
48 |
+
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="'.($mc_class->get_session_number() - 1).'" name="'.$tag->name.'-sn" />', $tag->name, $atts, $validation_error);
|
|
|
49 |
}
|
|
|
50 |
}
|
51 |
|
52 |
|
64 |
{
|
65 |
if($_POST[$name] !== '')
|
66 |
{
|
67 |
+
$session_id = (isset($_POST[$name.'-sn']) && $_POST[$name.'-sn'] !== '' ? $mc_class->get_session_id($_POST[$name.'-sn']) : '');
|
68 |
+
|
69 |
+
if($session_id !== '' && get_transient('cf7_'.$session_id) !== FALSE)
|
70 |
{
|
71 |
+
if(strcmp(get_transient('cf7_'.$session_id), sha1(AUTH_KEY.$_POST[$name].$session_id, FALSE)) !== 0)
|
72 |
{
|
73 |
$result['valid'] = FALSE;
|
74 |
$result['reason'][$name] = wpcf7_get_message('wrong_mathcaptcha');
|
103 |
array(
|
104 |
'wrong_mathcaptcha' => array(
|
105 |
'description' => __('Invalid captcha value.', 'math-captcha'),
|
106 |
+
'default' => $mc_class->get_error_messages('wrong')
|
107 |
),
|
108 |
'fill_mathcaptcha' => array(
|
109 |
'description' => __('Please enter captcha value.', 'math-captcha'),
|
110 |
+
'default' => $mc_class->get_error_messages('fill')
|
111 |
),
|
112 |
'time_mathcaptcha' => array(
|
113 |
'description' => __('Captcha time expired.', 'math-captcha'),
|
114 |
+
'default' => $mc_class->get_error_messages('time')
|
115 |
)
|
116 |
)
|
117 |
);
|
languages/math-captcha-zh_CN.mo
ADDED
Binary file
|
languages/math-captcha-zh_CN.po
ADDED
@@ -0,0 +1,347 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-10-08 15:43+0800\n"
|
6 |
+
"Last-Translator: Stephan Hilchenbach <info@elcats.de>\n"
|
7 |
+
"Language-Team: 逍遥乐汉化 <luoxiao123@outlook.com>\n"
|
8 |
+
"Language: zh-CN\n"
|
9 |
+
"MIME-Version: 1.0\n"
|
10 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
+
"Content-Transfer-Encoding: 8bit\n"
|
12 |
+
"X-Generator: Poedit 1.5.7\n"
|
13 |
+
"X-Poedit-KeywordsList: gettext;gettext_noop;__;_e\n"
|
14 |
+
"X-Poedit-Basepath: .\n"
|
15 |
+
"X-Poedit-SourceCharset: UTF-8\n"
|
16 |
+
"X-Poedit-SearchPath-0: ..\n"
|
17 |
+
|
18 |
+
#: ../wp-math-captcha.php:496
|
19 |
+
msgid "one"
|
20 |
+
msgstr "一"
|
21 |
+
|
22 |
+
#: ../wp-math-captcha.php:497
|
23 |
+
msgid "two"
|
24 |
+
msgstr "二"
|
25 |
+
|
26 |
+
#: ../wp-math-captcha.php:498
|
27 |
+
msgid "three"
|
28 |
+
msgstr "三"
|
29 |
+
|
30 |
+
#: ../wp-math-captcha.php:499
|
31 |
+
msgid "four"
|
32 |
+
msgstr "四"
|
33 |
+
|
34 |
+
#: ../wp-math-captcha.php:500
|
35 |
+
msgid "five"
|
36 |
+
msgstr "五"
|
37 |
+
|
38 |
+
#: ../wp-math-captcha.php:501
|
39 |
+
msgid "six"
|
40 |
+
msgstr "六"
|
41 |
+
|
42 |
+
#: ../wp-math-captcha.php:502
|
43 |
+
msgid "seven"
|
44 |
+
msgstr "七"
|
45 |
+
|
46 |
+
#: ../wp-math-captcha.php:503
|
47 |
+
msgid "eight"
|
48 |
+
msgstr "八"
|
49 |
+
|
50 |
+
#: ../wp-math-captcha.php:504
|
51 |
+
msgid "nine"
|
52 |
+
msgstr "九"
|
53 |
+
|
54 |
+
#: ../wp-math-captcha.php:505
|
55 |
+
msgid "ten"
|
56 |
+
msgstr "十"
|
57 |
+
|
58 |
+
#: ../wp-math-captcha.php:506
|
59 |
+
msgid "eleven"
|
60 |
+
msgstr "十一"
|
61 |
+
|
62 |
+
#: ../wp-math-captcha.php:507
|
63 |
+
msgid "twelve"
|
64 |
+
msgstr "十二"
|
65 |
+
|
66 |
+
#: ../wp-math-captcha.php:508
|
67 |
+
msgid "thirteen"
|
68 |
+
msgstr "十三"
|
69 |
+
|
70 |
+
#: ../wp-math-captcha.php:509
|
71 |
+
msgid "fourteen"
|
72 |
+
msgstr "十四"
|
73 |
+
|
74 |
+
#: ../wp-math-captcha.php:510
|
75 |
+
msgid "fifteen"
|
76 |
+
msgstr "十五"
|
77 |
+
|
78 |
+
#: ../wp-math-captcha.php:511
|
79 |
+
msgid "sixteen"
|
80 |
+
msgstr "十六"
|
81 |
+
|
82 |
+
#: ../wp-math-captcha.php:512
|
83 |
+
msgid "seventeen"
|
84 |
+
msgstr "十七"
|
85 |
+
|
86 |
+
#: ../wp-math-captcha.php:513
|
87 |
+
msgid "eighteen"
|
88 |
+
msgstr "十八"
|
89 |
+
|
90 |
+
#: ../wp-math-captcha.php:514
|
91 |
+
msgid "nineteen"
|
92 |
+
msgstr "十九"
|
93 |
+
|
94 |
+
#: ../wp-math-captcha.php:515
|
95 |
+
msgid "twenty"
|
96 |
+
msgstr "二十"
|
97 |
+
|
98 |
+
#: ../wp-math-captcha.php:516
|
99 |
+
msgid "thirty"
|
100 |
+
msgstr "三十"
|
101 |
+
|
102 |
+
#: ../wp-math-captcha.php:517
|
103 |
+
msgid "forty"
|
104 |
+
msgstr "四十"
|
105 |
+
|
106 |
+
#: ../wp-math-captcha.php:518
|
107 |
+
msgid "fifty"
|
108 |
+
msgstr "五十"
|
109 |
+
|
110 |
+
#: ../wp-math-captcha.php:519
|
111 |
+
msgid "sixty"
|
112 |
+
msgstr "六十"
|
113 |
+
|
114 |
+
#: ../wp-math-captcha.php:520
|
115 |
+
msgid "seventy"
|
116 |
+
msgstr "七十"
|
117 |
+
|
118 |
+
#: ../wp-math-captcha.php:521
|
119 |
+
msgid "eighty"
|
120 |
+
msgstr "八十"
|
121 |
+
|
122 |
+
#: ../wp-math-captcha.php:522
|
123 |
+
msgid "ninety"
|
124 |
+
msgstr "九十"
|
125 |
+
|
126 |
+
#: ../wp-math-captcha.php:812 ../wp-math-captcha.php:813
|
127 |
+
#: ../wp-math-captcha.php:814
|
128 |
+
msgid "ERROR"
|
129 |
+
msgstr "错误"
|
130 |
+
|
131 |
+
#: ../wp-math-captcha.php:812 ../includes/math-captcha-cf7.php:113
|
132 |
+
msgid "Please enter captcha value."
|
133 |
+
msgstr "oh my gad! 兄弟你忘记填写验证码了!"
|
134 |
+
|
135 |
+
#: ../wp-math-captcha.php:813 ../includes/math-captcha-cf7.php:109
|
136 |
+
msgid "Invalid captcha value."
|
137 |
+
msgstr "您输入的验证码不正确,请重新输入"
|
138 |
+
|
139 |
+
#: ../wp-math-captcha.php:814 ../includes/math-captcha-cf7.php:117
|
140 |
+
msgid "Captcha time expired."
|
141 |
+
msgstr "验证码过期时间。"
|
142 |
+
|
143 |
+
#: ../wp-math-captcha.php:818
|
144 |
+
msgid "login form"
|
145 |
+
msgstr "登录表单"
|
146 |
+
|
147 |
+
#: ../wp-math-captcha.php:819
|
148 |
+
msgid "registration form"
|
149 |
+
msgstr "注册表单"
|
150 |
+
|
151 |
+
#: ../wp-math-captcha.php:820
|
152 |
+
msgid "reset password form"
|
153 |
+
msgstr "重置密码表单"
|
154 |
+
|
155 |
+
#: ../wp-math-captcha.php:821
|
156 |
+
msgid "comment form"
|
157 |
+
msgstr "评论表单"
|
158 |
+
|
159 |
+
#: ../wp-math-captcha.php:822
|
160 |
+
msgid "bbpress"
|
161 |
+
msgstr "bbpress"
|
162 |
+
|
163 |
+
#: ../wp-math-captcha.php:823
|
164 |
+
msgid "contact form 7"
|
165 |
+
msgstr "contact form 7"
|
166 |
+
|
167 |
+
#: ../wp-math-captcha.php:827
|
168 |
+
msgid "yes"
|
169 |
+
msgstr "是"
|
170 |
+
|
171 |
+
#: ../wp-math-captcha.php:828
|
172 |
+
msgid "no"
|
173 |
+
msgstr "否"
|
174 |
+
|
175 |
+
#: ../wp-math-captcha.php:832
|
176 |
+
msgid "addition (+)"
|
177 |
+
msgstr "加法 (+)"
|
178 |
+
|
179 |
+
#: ../wp-math-captcha.php:833
|
180 |
+
msgid "subtraction (-)"
|
181 |
+
msgstr "减法 (-)"
|
182 |
+
|
183 |
+
#: ../wp-math-captcha.php:834
|
184 |
+
msgid "multiplication (×)"
|
185 |
+
msgstr "乘法 (×)"
|
186 |
+
|
187 |
+
#: ../wp-math-captcha.php:835
|
188 |
+
msgid "division (÷)"
|
189 |
+
msgstr "除法 (÷)"
|
190 |
+
|
191 |
+
#: ../wp-math-captcha.php:839
|
192 |
+
msgid "numbers"
|
193 |
+
msgstr "阿拉伯数字"
|
194 |
+
|
195 |
+
#: ../wp-math-captcha.php:840
|
196 |
+
msgid "words"
|
197 |
+
msgstr "中文大写数字"
|
198 |
+
|
199 |
+
#: ../wp-math-captcha.php:852
|
200 |
+
msgid "Math Captcha settings"
|
201 |
+
msgstr "Math Captcha设置"
|
202 |
+
|
203 |
+
#: ../wp-math-captcha.php:853
|
204 |
+
msgid "Enable Math Captcha for"
|
205 |
+
msgstr "启用 Math Captcha 到"
|
206 |
+
|
207 |
+
#: ../wp-math-captcha.php:854
|
208 |
+
msgid "Hide for logged in users"
|
209 |
+
msgstr "登录用户不显示验证码"
|
210 |
+
|
211 |
+
#: ../wp-math-captcha.php:855
|
212 |
+
msgid "Mathematical operations"
|
213 |
+
msgstr "数学运算"
|
214 |
+
|
215 |
+
#: ../wp-math-captcha.php:856
|
216 |
+
msgid "Display captcha as"
|
217 |
+
msgstr "显示验证码"
|
218 |
+
|
219 |
+
#: ../wp-math-captcha.php:857
|
220 |
+
msgid "Captcha field title"
|
221 |
+
msgstr "验证码字段标题"
|
222 |
+
|
223 |
+
#: ../wp-math-captcha.php:858
|
224 |
+
msgid "Captcha time"
|
225 |
+
msgstr "验证码时间"
|
226 |
+
|
227 |
+
#: ../wp-math-captcha.php:859
|
228 |
+
msgid "Deactivation"
|
229 |
+
msgstr "停用"
|
230 |
+
|
231 |
+
#: ../wp-math-captcha.php:879
|
232 |
+
msgid "Select were would you like to use Math Captcha."
|
233 |
+
msgstr "选择你想使用的数学验证码。"
|
234 |
+
|
235 |
+
#: ../wp-math-captcha.php:900
|
236 |
+
msgid "Would you like to hide captcha for logged in users?"
|
237 |
+
msgstr "你想让登录用户隐藏验证码?"
|
238 |
+
|
239 |
+
#: ../wp-math-captcha.php:913
|
240 |
+
msgid ""
|
241 |
+
"Select what kind of mathematical operations will be used to generate captcha."
|
242 |
+
msgstr "选择什么样的数学运算,将被用来生成验证码。"
|
243 |
+
|
244 |
+
#: ../wp-math-captcha.php:926
|
245 |
+
msgid "Enter the time (in seconds) a user has to enter captcha value."
|
246 |
+
msgstr "输入的时间(以秒为单位),用户必须输入验证码值。"
|
247 |
+
|
248 |
+
#: ../wp-math-captcha.php:947
|
249 |
+
msgid "Delete settings on plugin deactivation"
|
250 |
+
msgstr "停用插件时删除设置"
|
251 |
+
|
252 |
+
#: ../wp-math-captcha.php:968
|
253 |
+
msgid "Select which mathematical operations to use in your captcha."
|
254 |
+
msgstr "选择算术运算的类型被用来生成的验证码。"
|
255 |
+
|
256 |
+
#: ../wp-math-captcha.php:989
|
257 |
+
msgid "Select how you'd like to display you captcha."
|
258 |
+
msgstr "选择你想怎么显示的验证码。"
|
259 |
+
|
260 |
+
#: ../wp-math-captcha.php:1030
|
261 |
+
msgid ""
|
262 |
+
"You need to check at least one mathematical operation. Defaults settings of "
|
263 |
+
"this option restored."
|
264 |
+
msgstr "您必须选择至少一个算术运算。对于此选项,恢复默认值。"
|
265 |
+
|
266 |
+
#: ../wp-math-captcha.php:1046
|
267 |
+
msgid ""
|
268 |
+
"You need to check at least one group. Defaults settings of this option "
|
269 |
+
"restored."
|
270 |
+
msgstr "你必须选择至少一组。对于此选项,恢复默认值。"
|
271 |
+
|
272 |
+
#: ../wp-math-captcha.php:1080 ../wp-math-captcha.php:1081
|
273 |
+
#: ../wp-math-captcha.php:1096 ../wp-math-captcha.php:1109
|
274 |
+
#: ../includes/math-captcha-cf7.php:148
|
275 |
+
msgid "Math Captcha"
|
276 |
+
msgstr "Math Captcha"
|
277 |
+
|
278 |
+
#: ../wp-math-captcha.php:1111
|
279 |
+
msgid "Need support?"
|
280 |
+
msgstr "需要支持吗?"
|
281 |
+
|
282 |
+
#: ../wp-math-captcha.php:1112
|
283 |
+
msgid ""
|
284 |
+
"If you are having problems with this plugin, please talk about them in the"
|
285 |
+
msgstr ""
|
286 |
+
"本插件由逍遥乐进行汉化,如果您在使用本插件时遇到什么汉化问题,请联系<a href="
|
287 |
+
"\"http://www.luoxiao123.cn\">逍遥乐</a>,一切汉化相关稳定都可以到<a href="
|
288 |
+
"\"http://www.luoxiao123.cn\">逍遥乐IT博客www.luoxiao123.cn</a>咨询逍遥乐!插"
|
289 |
+
"件具体问题请到原作者支持论坛:"
|
290 |
+
|
291 |
+
#: ../wp-math-captcha.php:1112
|
292 |
+
msgid "Support forum"
|
293 |
+
msgstr "支持论坛"
|
294 |
+
|
295 |
+
#: ../wp-math-captcha.php:1114
|
296 |
+
msgid "Do you like this plugin?"
|
297 |
+
msgstr "你喜欢这个插件?"
|
298 |
+
|
299 |
+
#: ../wp-math-captcha.php:1115
|
300 |
+
msgid "Rate it 5"
|
301 |
+
msgstr "评分5"
|
302 |
+
|
303 |
+
#: ../wp-math-captcha.php:1115
|
304 |
+
msgid "on WordPress.org"
|
305 |
+
msgstr "在 WordPress.org"
|
306 |
+
|
307 |
+
#: ../wp-math-captcha.php:1116
|
308 |
+
msgid "Blog about it & link to the"
|
309 |
+
msgstr "关于博客&链接到"
|
310 |
+
|
311 |
+
#: ../wp-math-captcha.php:1116
|
312 |
+
msgid "plugin page"
|
313 |
+
msgstr "插件页面"
|
314 |
+
|
315 |
+
#: ../wp-math-captcha.php:1117
|
316 |
+
msgid "Check out our other"
|
317 |
+
msgstr ""
|
318 |
+
"请到<a href=\"http://www.luoxiao123.cn\">逍遥乐IT博客www.luoxiao123.cn</a>查"
|
319 |
+
"看更多汉化作品!原作者更多作品请到:"
|
320 |
+
|
321 |
+
#: ../wp-math-captcha.php:1117
|
322 |
+
msgid "WordPress plugins"
|
323 |
+
msgstr "WordPress 插件"
|
324 |
+
|
325 |
+
#: ../wp-math-captcha.php:1170
|
326 |
+
msgid "Support"
|
327 |
+
msgstr "支持"
|
328 |
+
|
329 |
+
#: ../wp-math-captcha.php:1192
|
330 |
+
msgid "Settings"
|
331 |
+
msgstr "设置"
|
332 |
+
|
333 |
+
#: ../includes/math-captcha-cf7.php:160
|
334 |
+
msgid "Name"
|
335 |
+
msgstr "名称"
|
336 |
+
|
337 |
+
#: ../includes/math-captcha-cf7.php:166
|
338 |
+
msgid "Input field settings"
|
339 |
+
msgstr "输入字段设置"
|
340 |
+
|
341 |
+
#: ../includes/math-captcha-cf7.php:169 ../includes/math-captcha-cf7.php:173
|
342 |
+
msgid "optional"
|
343 |
+
msgstr "可选"
|
344 |
+
|
345 |
+
#: ../includes/math-captcha-cf7.php:179
|
346 |
+
msgid "Copy this code and paste it into the form left."
|
347 |
+
msgstr "将此代码复制并粘贴到左侧。"
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.dfactory.eu/
|
|
4 |
Tags: antispam, capcha, captcha, captha, catcha, comment, comments, spam, security, login, lost password, math captcha, registration, cf7, contact, contact forms, form, contact form 7, bbpress
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.6.1
|
7 |
-
Stable tag: 1.0.
|
8 |
License: MIT License
|
9 |
License URI: http://opensource.org/licenses/MIT
|
10 |
|
@@ -22,12 +22,14 @@ For more information, check out the [plugin page](http://www.dfactory.eu/plugins
|
|
22 |
* Hiding captcha for logged in users
|
23 |
* Select which mathematical operation to use
|
24 |
* Displaying captcha as numbers and/or words
|
|
|
25 |
* Option to set captcha field title
|
26 |
* Option to set captcha input time
|
27 |
* .pot file for translations included
|
28 |
|
29 |
= Translations: =
|
30 |
|
|
|
31 |
* Dutch - by [Monique](http://www.datisslimbedacht.nl)
|
32 |
* French - by sil3r
|
33 |
* German - by Stephan Hilchenbach
|
@@ -54,6 +56,12 @@ No questions yet.
|
|
54 |
|
55 |
== Changelog ==
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
= 1.0.8 =
|
58 |
* Fix: Strict Standards warnings on some server setups.
|
59 |
|
@@ -88,5 +96,5 @@ No questions yet.
|
|
88 |
|
89 |
== Upgrade Notice ==
|
90 |
|
91 |
-
= 1.0.
|
92 |
-
|
4 |
Tags: antispam, capcha, captcha, captha, catcha, comment, comments, spam, security, login, lost password, math captcha, registration, cf7, contact, contact forms, form, contact form 7, bbpress
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 3.6.1
|
7 |
+
Stable tag: 1.0.9
|
8 |
License: MIT License
|
9 |
License URI: http://opensource.org/licenses/MIT
|
10 |
|
22 |
* Hiding captcha for logged in users
|
23 |
* Select which mathematical operation to use
|
24 |
* Displaying captcha as numbers and/or words
|
25 |
+
* Multiple captcha on one page support
|
26 |
* Option to set captcha field title
|
27 |
* Option to set captcha input time
|
28 |
* .pot file for translations included
|
29 |
|
30 |
= Translations: =
|
31 |
|
32 |
+
* Chinese - by xiaoyaole
|
33 |
* Dutch - by [Monique](http://www.datisslimbedacht.nl)
|
34 |
* French - by sil3r
|
35 |
* German - by Stephan Hilchenbach
|
56 |
|
57 |
== Changelog ==
|
58 |
|
59 |
+
= 1.0.9 =
|
60 |
+
* New: Multiple Math Captcha on one page support
|
61 |
+
* New: Chinese translation, thanks to xiaoyaole
|
62 |
+
* Fix: COntact Form 7 errors and general CF7 support
|
63 |
+
* Tweak: crypt_key generation changed to AUTH_KEY usage
|
64 |
+
|
65 |
= 1.0.8 =
|
66 |
* Fix: Strict Standards warnings on some server setups.
|
67 |
|
96 |
|
97 |
== Upgrade Notice ==
|
98 |
|
99 |
+
= 1.0.9 =
|
100 |
+
Chinese translation, fixed errors for CF7 and multiple Math Cpatchas on one page support
|
wp-math-captcha.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/*
|
3 |
Plugin Name: Math Captcha
|
4 |
Description: Math Captcha is a <strong>100% effective CAPTCHA for WordPress</strong> that integrates into login, registration, comments, Contact Form 7 and bbPress.
|
5 |
-
Version: 1.0.
|
6 |
Author: dFactory
|
7 |
Author URI: http://www.dfactory.eu/
|
8 |
Plugin URI: http://www.dfactory.eu/plugins/math-captcha/
|
@@ -19,33 +19,41 @@ The above copyright notice and this permission notice shall be included in all c
|
|
19 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20 |
*/
|
21 |
|
|
|
|
|
|
|
22 |
|
23 |
class Math_Captcha
|
24 |
{
|
25 |
private $defaults = array(
|
26 |
-
'
|
27 |
-
'
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
'
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
),
|
42 |
-
'
|
43 |
-
'numbers' => TRUE,
|
44 |
-
'words' => FALSE
|
45 |
-
),
|
46 |
-
'time' => 300,
|
47 |
-
'deactivation_delete' => FALSE
|
48 |
);
|
|
|
|
|
49 |
private $options = array();
|
50 |
private $choices = array();
|
51 |
private $enable_for = array();
|
@@ -53,9 +61,6 @@ class Math_Captcha
|
|
53 |
private $groups = array();
|
54 |
private $error_messages = array();
|
55 |
private $errors;
|
56 |
-
private $session_id = '';
|
57 |
-
private $crypt_key = 'u.%ds)4;?D<gM#%fd!W2]9';
|
58 |
-
private $err_msg = array();
|
59 |
|
60 |
|
61 |
public function __construct()
|
@@ -63,7 +68,19 @@ class Math_Captcha
|
|
63 |
register_activation_hook(__FILE__, array(&$this, 'activation'));
|
64 |
register_deactivation_hook(__FILE__, array(&$this, 'deactivation'));
|
65 |
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
//actions
|
69 |
add_action('plugins_loaded', array(&$this, 'init_mc_session'), 1);
|
@@ -81,6 +98,65 @@ class Math_Captcha
|
|
81 |
}
|
82 |
|
83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
/**
|
85 |
* Loads required filters
|
86 |
*/
|
@@ -89,13 +165,13 @@ class Math_Captcha
|
|
89 |
global $pagenow;
|
90 |
|
91 |
//comments
|
92 |
-
if($this->options['enable_for']['comment_form'] === TRUE)
|
93 |
{
|
94 |
if(!is_user_logged_in())
|
95 |
add_action('comment_form_after_fields', array(&$this, 'add_captcha_form'));
|
96 |
else
|
97 |
{
|
98 |
-
if($this->options['hide_for_logged_users'] === FALSE)
|
99 |
{
|
100 |
add_action('comment_form_logged_in_after', array(&$this, 'add_captcha_form'));
|
101 |
}
|
@@ -109,7 +185,7 @@ class Math_Captcha
|
|
109 |
{
|
110 |
$action = (isset($_GET['action']) && $_GET['action'] !== '' ? $_GET['action'] : NULL);
|
111 |
|
112 |
-
if($this->options['enable_for']['registration_form'] === TRUE && (!is_user_logged_in() || (is_user_logged_in() && $this->options['hide_for_logged_users'] === FALSE)) && $action === 'register')
|
113 |
{
|
114 |
add_action('register_form', array(&$this, 'add_captcha_form'));
|
115 |
add_action('register_post', array(&$this, 'add_user_with_captcha'), 10, 3);
|
@@ -117,13 +193,13 @@ class Math_Captcha
|
|
117 |
add_filter('wpmu_validate_user_signup', array(&$this, 'validate_user_with_captcha'));
|
118 |
}
|
119 |
|
120 |
-
if($this->options['enable_for']['reset_password_form'] === TRUE && (!is_user_logged_in() || (is_user_logged_in() && $this->options['hide_for_logged_users'] === FALSE)) && $action === 'lostpassword')
|
121 |
{
|
122 |
add_action('lostpassword_form', array(&$this, 'add_captcha_form'));
|
123 |
add_action('lostpassword_post', array(&$this, 'check_lost_password_with_captcha'));
|
124 |
}
|
125 |
|
126 |
-
if($this->options['enable_for']['login_form'] === TRUE && (!is_user_logged_in() || (is_user_logged_in() && $this->options['hide_for_logged_users'] === FALSE)) && $action === NULL)
|
127 |
{
|
128 |
add_action('login_form', array(&$this, 'add_captcha_form'));
|
129 |
add_filter('login_redirect', array(&$this, 'redirect_login_with_captcha'), 10, 3);
|
@@ -131,11 +207,11 @@ class Math_Captcha
|
|
131 |
}
|
132 |
|
133 |
//bbPress
|
134 |
-
if($this->options['enable_for']['bbpress'] === TRUE)
|
135 |
{
|
136 |
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
137 |
|
138 |
-
if(is_plugin_active('bbpress/bbpress.php') && (!is_user_logged_in() || (is_user_logged_in() && $this->options['hide_for_logged_users'] === FALSE)))
|
139 |
{
|
140 |
add_action('bbp_theme_after_reply_form_content', array(&$this, 'add_bbp_captcha_form'));
|
141 |
add_action('bbp_theme_after_topic_form_content', array(&$this, 'add_bbp_captcha_form'));
|
@@ -145,7 +221,7 @@ class Math_Captcha
|
|
145 |
}
|
146 |
|
147 |
//Contact Form 7
|
148 |
-
if($this->options['enable_for']['contact_form_7'] === TRUE)
|
149 |
{
|
150 |
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
151 |
|
@@ -160,26 +236,6 @@ class Math_Captcha
|
|
160 |
}
|
161 |
|
162 |
|
163 |
-
/**
|
164 |
-
* Gets attribute from options
|
165 |
-
*/
|
166 |
-
public function get_attribute($attr)
|
167 |
-
{
|
168 |
-
switch($attr)
|
169 |
-
{
|
170 |
-
case 'session_id':
|
171 |
-
case 'crypt_key':
|
172 |
-
return $this->{$attr};
|
173 |
-
|
174 |
-
case 'title':
|
175 |
-
return $this->options['title'];
|
176 |
-
|
177 |
-
default:
|
178 |
-
return '';
|
179 |
-
}
|
180 |
-
}
|
181 |
-
|
182 |
-
|
183 |
/**
|
184 |
* Validates lost password form
|
185 |
*/
|
@@ -192,16 +248,16 @@ class Math_Captcha
|
|
192 |
//checks captcha
|
193 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
194 |
{
|
195 |
-
if($this->
|
196 |
{
|
197 |
-
if(strcmp(get_transient('mc_'.$this->
|
198 |
-
$this->errors->add('math-captcha-error', $this->
|
199 |
}
|
200 |
else
|
201 |
-
$this->errors->add('math-captcha-error', $this->
|
202 |
}
|
203 |
else
|
204 |
-
$this->errors->add('math-captcha-error', $this->
|
205 |
|
206 |
//checks user_login (from wp-login.php)
|
207 |
if(empty($_POST['user_login']))
|
@@ -256,21 +312,43 @@ class Math_Captcha
|
|
256 |
{
|
257 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
258 |
{
|
259 |
-
if($this->
|
260 |
{
|
261 |
-
if(strcmp(get_transient('mc_'.$this->
|
262 |
-
$errors->add('math-captcha-error', $this->
|
263 |
}
|
264 |
else
|
265 |
-
$errors->add('math-captcha-error', $this->
|
266 |
}
|
267 |
else
|
268 |
-
$errors->add('math-captcha-error', $this->
|
269 |
|
270 |
return $errors;
|
271 |
}
|
272 |
|
273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
/**
|
275 |
* Posts login form
|
276 |
*/
|
@@ -281,30 +359,30 @@ class Math_Captcha
|
|
281 |
|
282 |
if(isset($_GET['captcha']) && in_array($_GET['captcha'], array('fill', 'wrong', 'time'), TRUE))
|
283 |
{
|
284 |
-
$errors->add('math-captcha-error', $this->
|
285 |
}
|
286 |
|
287 |
if(!empty($_POST))
|
288 |
{
|
289 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
290 |
{
|
291 |
-
if($this->
|
292 |
{
|
293 |
-
if(strcmp(get_transient('mc_'.$this->
|
294 |
{
|
295 |
-
$error = (!is_wp_error($errors) ? TRUE : $errors->add('math-captcha-error', $this->
|
296 |
$act = 'wrong';
|
297 |
}
|
298 |
}
|
299 |
else
|
300 |
{
|
301 |
-
$error = (!is_wp_error($errors) ? TRUE : $errors->add('math-captcha-error', $this->
|
302 |
$act = 'time';
|
303 |
}
|
304 |
}
|
305 |
else
|
306 |
{
|
307 |
-
$error = (!is_wp_error($errors) ? TRUE : $errors->add('math-captcha-error', $this->
|
308 |
$act = 'fill';
|
309 |
}
|
310 |
}
|
@@ -330,28 +408,6 @@ class Math_Captcha
|
|
330 |
}
|
331 |
|
332 |
|
333 |
-
/**
|
334 |
-
* Validates register form
|
335 |
-
*/
|
336 |
-
public function validate_user_with_captcha($result)
|
337 |
-
{
|
338 |
-
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
339 |
-
{
|
340 |
-
if($this->session_id !== '' && get_transient('mc_'.$this->session_id) !== FALSE)
|
341 |
-
{
|
342 |
-
if(strcmp(get_transient('mc_'.$this->session_id), sha1($this->crypt_key.$_POST['mc-value'].$this->session_id, FALSE)) !== 0)
|
343 |
-
$results['errors']->add('math-captcha-error', $this->err_msg['wrong']);
|
344 |
-
}
|
345 |
-
else
|
346 |
-
$results['errors']->add('math-captcha-error', $this->err_msg['time']);
|
347 |
-
}
|
348 |
-
else
|
349 |
-
$results['errors']->add('math-captcha-error', $this->err_msg['fill']);
|
350 |
-
|
351 |
-
return $results;
|
352 |
-
}
|
353 |
-
|
354 |
-
|
355 |
/**
|
356 |
* Adds captcha to comment form
|
357 |
*/
|
@@ -361,18 +417,18 @@ class Math_Captcha
|
|
361 |
{
|
362 |
if($_POST['mc-value'] !== '')
|
363 |
{
|
364 |
-
if($this->
|
365 |
{
|
366 |
-
if(strcmp(get_transient('mc_'.$this->
|
367 |
return $comment;
|
368 |
else
|
369 |
-
wp_die($this->
|
370 |
}
|
371 |
else
|
372 |
-
wp_die($this->
|
373 |
}
|
374 |
else
|
375 |
-
wp_die($this->
|
376 |
}
|
377 |
else
|
378 |
return $comment;
|
@@ -384,12 +440,34 @@ class Math_Captcha
|
|
384 |
*/
|
385 |
public function init_mc_session()
|
386 |
{
|
387 |
-
if(isset($_COOKIE['
|
388 |
-
$this->
|
389 |
else
|
390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
|
392 |
-
setcookie('
|
|
|
|
|
|
|
|
|
|
|
393 |
}
|
394 |
|
395 |
|
@@ -401,7 +479,7 @@ class Math_Captcha
|
|
401 |
if(is_admin())
|
402 |
return;
|
403 |
|
404 |
-
$captcha_title = apply_filters('math_captcha_title', $this->options['title']);
|
405 |
|
406 |
echo '
|
407 |
<p class="math-captcha-form">';
|
@@ -424,7 +502,7 @@ class Math_Captcha
|
|
424 |
if(is_admin())
|
425 |
return;
|
426 |
|
427 |
-
$captcha_title = apply_filters('math_captcha_title', $this->options['title']);
|
428 |
|
429 |
echo '
|
430 |
<p class="math-captcha-form">';
|
@@ -446,16 +524,16 @@ class Math_Captcha
|
|
446 |
{
|
447 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
448 |
{
|
449 |
-
if($this->
|
450 |
{
|
451 |
-
if(strcmp(get_transient('bbp_'.$this->
|
452 |
-
bbp_add_error('math-captcha-wrong', $this->
|
453 |
}
|
454 |
else
|
455 |
-
bbp_add_error('math-captcha-wrong', $this->
|
456 |
}
|
457 |
else
|
458 |
-
bbp_add_error('math-captcha-wrong', $this->
|
459 |
}
|
460 |
|
461 |
|
@@ -568,17 +646,17 @@ class Math_Captcha
|
|
568 |
);
|
569 |
|
570 |
$operations = $groups = array();
|
571 |
-
$input = '<input type="text" size="2" length="2" id="mc-input" name="mc-value" value="" aria-required="true"
|
572 |
|
573 |
//available operations
|
574 |
-
foreach($this->options['mathematical_operations'] as $operation => $enable)
|
575 |
{
|
576 |
if($enable === TRUE)
|
577 |
$operations[] = $operation;
|
578 |
}
|
579 |
|
580 |
//available groups
|
581 |
-
foreach($this->options['groups'] as $group => $enable)
|
582 |
{
|
583 |
if($enable === TRUE)
|
584 |
$groups[] = $group;
|
@@ -594,6 +672,7 @@ class Math_Captcha
|
|
594 |
//place where to put empty input
|
595 |
$rnd_input = mt_rand(0, 2);
|
596 |
|
|
|
597 |
switch($rnd_op)
|
598 |
{
|
599 |
case 'addition':
|
@@ -749,6 +828,7 @@ class Math_Captcha
|
|
749 |
$return = $this->encode_operation($number[0]).' '.$number[3].' '.$this->encode_operation($number[1]).' = '.$input;
|
750 |
|
751 |
$transient_name = ($form === 'bbpress' ? 'bbp' : 'mc');
|
|
|
752 |
}
|
753 |
elseif($form === 'cf7')
|
754 |
{
|
@@ -774,39 +854,21 @@ class Math_Captcha
|
|
774 |
}
|
775 |
|
776 |
$transient_name = 'cf7';
|
|
|
777 |
}
|
778 |
|
779 |
-
set_transient($transient_name.'_'.$
|
780 |
|
781 |
return $return;
|
782 |
}
|
783 |
|
784 |
|
785 |
-
/**
|
786 |
-
* Activation
|
787 |
-
*/
|
788 |
-
public function activation()
|
789 |
-
{
|
790 |
-
add_option('mc_options', $this->defaults, '', 'no');
|
791 |
-
}
|
792 |
-
|
793 |
-
|
794 |
-
/**
|
795 |
-
* Deactivation
|
796 |
-
*/
|
797 |
-
public function deactivation()
|
798 |
-
{
|
799 |
-
if($this->options['deactivation_delete'] === TRUE)
|
800 |
-
delete_option('mc_options');
|
801 |
-
}
|
802 |
-
|
803 |
-
|
804 |
/**
|
805 |
* Load defaults
|
806 |
*/
|
807 |
public function load_defaults()
|
808 |
{
|
809 |
-
$this->
|
810 |
'fill' => '<strong>'. __('ERROR', 'math-captcha').'</strong>: '.__('Please enter captcha value.', 'math-captcha'),
|
811 |
'wrong' => '<strong>'. __('ERROR', 'math-captcha').'</strong>: '.__('Invalid captcha value.', 'math-captcha'),
|
812 |
'time' => '<strong>'. __('ERROR', 'math-captcha').'</strong>: '.__('Captcha time expired.', 'math-captcha')
|
@@ -846,15 +908,15 @@ class Math_Captcha
|
|
846 |
public function register_settings()
|
847 |
{
|
848 |
//inline edit
|
849 |
-
register_setting('
|
850 |
-
add_settings_section('math_captcha_settings', __('Math Captcha settings', 'math-captcha'), '', '
|
851 |
-
add_settings_field('mc_enable_for', __('Enable Math Captcha for', 'math-captcha'), array(&$this, 'mc_enable_captcha_for'), '
|
852 |
-
add_settings_field('mc_hide_for_logged_users', __('Hide for logged in users', 'math-captcha'), array(&$this, 'mc_hide_for_logged_users'), '
|
853 |
-
add_settings_field('mc_mathematical_operations', __('Mathematical operations', 'math-captcha'), array(&$this, 'mc_mathematical_operations'), '
|
854 |
-
add_settings_field('mc_groups', __('Display captcha as', 'math-captcha'), array(&$this, 'mc_groups'), '
|
855 |
-
add_settings_field('mc_title', __('Captcha field title', 'math-captcha'), array(&$this, 'mc_title'), '
|
856 |
-
add_settings_field('mc_time', __('Captcha time', 'math-captcha'), array(&$this, 'mc_time'), '
|
857 |
-
add_settings_field('mc_deactivation_delete', __('Deactivation', 'math-captcha'), array(&$this, 'mc_deactivation_delete'), '
|
858 |
}
|
859 |
|
860 |
|
@@ -869,7 +931,7 @@ class Math_Captcha
|
|
869 |
foreach($this->enable_for as $val => $trans)
|
870 |
{
|
871 |
echo '
|
872 |
-
<input id="mc-enable-for-'.$val.'" type="checkbox" name="
|
873 |
<label for="mc-enable-for-'.$val.'">'.$trans.'</label>';
|
874 |
}
|
875 |
|
@@ -890,7 +952,7 @@ class Math_Captcha
|
|
890 |
foreach($this->choices as $val => $trans)
|
891 |
{
|
892 |
echo '
|
893 |
-
<input id="mc-hide-for-logged-'.$val.'" type="radio" name="
|
894 |
<label for="mc-hide-for-logged-'.$val.'">'.$trans.'</label>';
|
895 |
}
|
896 |
|
@@ -907,7 +969,7 @@ class Math_Captcha
|
|
907 |
{
|
908 |
echo '
|
909 |
<div>
|
910 |
-
<input type="text" name="
|
911 |
<p class="description">'.__('How to entitle field with captcha?', 'math-captcha').'</p>
|
912 |
</div>';
|
913 |
}
|
@@ -920,7 +982,7 @@ class Math_Captcha
|
|
920 |
{
|
921 |
echo '
|
922 |
<div>
|
923 |
-
<input type="text" name="
|
924 |
<p class="description">'.__('Enter the time (in seconds) a user has to enter captcha value.', 'math-captcha').'</p>
|
925 |
</div>';
|
926 |
}
|
@@ -937,7 +999,7 @@ class Math_Captcha
|
|
937 |
foreach($this->choices as $val => $trans)
|
938 |
{
|
939 |
echo '
|
940 |
-
<input id="mc-deactivation-delete-'.$val.'" type="radio" name="
|
941 |
<label for="mc-deactivation-delete-'.$val.'">'.$trans.'</label>';
|
942 |
}
|
943 |
|
@@ -958,7 +1020,7 @@ class Math_Captcha
|
|
958 |
foreach($this->mathematical_operations as $val => $trans)
|
959 |
{
|
960 |
echo '
|
961 |
-
<input id="mc-mathematical-operations-'.$val.'" type="checkbox" name="
|
962 |
<label for="mc-mathematical-operations-'.$val.'">'.$trans.'</label>';
|
963 |
}
|
964 |
|
@@ -979,7 +1041,7 @@ class Math_Captcha
|
|
979 |
foreach($this->groups as $val => $trans)
|
980 |
{
|
981 |
echo '
|
982 |
-
<input id="mc-groups-'.$val.'" type="checkbox" name="
|
983 |
<label for="mc-groups-'.$val.'">'.$trans.'</label>';
|
984 |
}
|
985 |
|
@@ -994,7 +1056,7 @@ class Math_Captcha
|
|
994 |
*/
|
995 |
public function validate_configuration($input)
|
996 |
{
|
997 |
-
if(isset($_POST['
|
998 |
{
|
999 |
$enable_for = array();
|
1000 |
$mathematical_operations = array();
|
@@ -1002,7 +1064,7 @@ class Math_Captcha
|
|
1002 |
|
1003 |
if(empty($input['enable_for']))
|
1004 |
{
|
1005 |
-
foreach($this->defaults['enable_for'] as $enable => $bool)
|
1006 |
{
|
1007 |
$input['enable_for'][$enable] = FALSE;
|
1008 |
}
|
@@ -1017,17 +1079,17 @@ class Math_Captcha
|
|
1017 |
$input['enable_for'] = $enable_for;
|
1018 |
}
|
1019 |
|
1020 |
-
if(!is_plugin_active('contact-form-7/wp-contact-form-7.php') && $this->options['enable_for']['contact_form_7'] === TRUE)
|
1021 |
$input['enable_for']['contact_form_7'] = TRUE;
|
1022 |
|
1023 |
-
if(!is_plugin_active('bbpress/bbpress.php') && $this->options['enable_for']['bbpress'] === TRUE)
|
1024 |
$input['enable_for']['bbpress'] = TRUE;
|
1025 |
|
1026 |
if(empty($input['mathematical_operations']))
|
1027 |
{
|
1028 |
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');
|
1029 |
|
1030 |
-
$input['mathematical_operations'] = $this->defaults['mathematical_operations'];
|
1031 |
}
|
1032 |
else
|
1033 |
{
|
@@ -1043,7 +1105,7 @@ class Math_Captcha
|
|
1043 |
{
|
1044 |
add_settings_error('empty-groups', 'settings_updated', __('You need to check at least one group. Defaults settings of this option restored.', 'math-captcha'), 'error');
|
1045 |
|
1046 |
-
$input['groups'] = $this->defaults['groups'];
|
1047 |
}
|
1048 |
else
|
1049 |
{
|
@@ -1055,14 +1117,14 @@ class Math_Captcha
|
|
1055 |
$input['groups'] = $groups;
|
1056 |
}
|
1057 |
|
1058 |
-
$input['hide_for_logged_users'] = (isset($input['hide_for_logged_users']) && in_array($input['hide_for_logged_users'], array_keys($this->choices)) ? ($input['hide_for_logged_users'] === 'yes' ? TRUE : FALSE) : $this->defaults['hide_for_logged_users']);
|
1059 |
|
1060 |
-
$input['deactivation_delete'] = (isset($input['deactivation_delete']) && in_array($input['deactivation_delete'], array_keys($this->choices)) ? ($input['deactivation_delete'] === 'yes' ? TRUE : FALSE) : $this->options['deactivation_delete']);
|
1061 |
|
1062 |
$input['title'] = trim(sanitize_text_field($input['title']));
|
1063 |
|
1064 |
$time = (int)$input['time'];
|
1065 |
-
$input['time'] = ($time < 0 ? $this->defaults['time'] : $time);
|
1066 |
}
|
1067 |
|
1068 |
return $input;
|
@@ -1096,9 +1158,9 @@ class Math_Captcha
|
|
1096 |
<form action="options.php" method="post">';
|
1097 |
|
1098 |
wp_nonce_field('update-options');
|
1099 |
-
settings_fields('
|
1100 |
-
do_settings_sections('
|
1101 |
-
submit_button('', 'primary', '
|
1102 |
|
1103 |
echo '
|
1104 |
</form>
|
@@ -1194,6 +1256,4 @@ class Math_Captcha
|
|
1194 |
return $links;
|
1195 |
}
|
1196 |
}
|
1197 |
-
|
1198 |
-
$math_captcha = new Math_Captcha();
|
1199 |
?>
|
2 |
/*
|
3 |
Plugin Name: Math Captcha
|
4 |
Description: Math Captcha is a <strong>100% effective CAPTCHA for WordPress</strong> that integrates into login, registration, comments, Contact Form 7 and bbPress.
|
5 |
+
Version: 1.0.9
|
6 |
Author: dFactory
|
7 |
Author URI: http://www.dfactory.eu/
|
8 |
Plugin URI: http://www.dfactory.eu/plugins/math-captcha/
|
19 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20 |
*/
|
21 |
|
22 |
+
if(!defined('ABSPATH')) exit; //exit if accessed directly
|
23 |
+
|
24 |
+
new Math_Captcha();
|
25 |
|
26 |
class Math_Captcha
|
27 |
{
|
28 |
private $defaults = array(
|
29 |
+
'general' => array(
|
30 |
+
'enable_for' => array(
|
31 |
+
'login_form' => FALSE,
|
32 |
+
'registration_form' => TRUE,
|
33 |
+
'reset_password_form' => TRUE,
|
34 |
+
'comment_form' => TRUE,
|
35 |
+
'bbpress' => FALSE,
|
36 |
+
'contact_form_7' => FALSE
|
37 |
+
),
|
38 |
+
'hide_for_logged_users' => TRUE,
|
39 |
+
'title' => 'Math Captcha',
|
40 |
+
'mathematical_operations' => array(
|
41 |
+
'addition' => TRUE,
|
42 |
+
'subtraction' => TRUE,
|
43 |
+
'multiplication' => FALSE,
|
44 |
+
'division' => FALSE
|
45 |
+
),
|
46 |
+
'groups' => array(
|
47 |
+
'numbers' => TRUE,
|
48 |
+
'words' => FALSE
|
49 |
+
),
|
50 |
+
'time' => 300,
|
51 |
+
'deactivation_delete' => FALSE
|
52 |
),
|
53 |
+
'version' => '1.0.9'
|
|
|
|
|
|
|
|
|
|
|
54 |
);
|
55 |
+
private $session_ids = array();
|
56 |
+
private $session_number = 0;
|
57 |
private $options = array();
|
58 |
private $choices = array();
|
59 |
private $enable_for = array();
|
61 |
private $groups = array();
|
62 |
private $error_messages = array();
|
63 |
private $errors;
|
|
|
|
|
|
|
64 |
|
65 |
|
66 |
public function __construct()
|
68 |
register_activation_hook(__FILE__, array(&$this, 'activation'));
|
69 |
register_deactivation_hook(__FILE__, array(&$this, 'deactivation'));
|
70 |
|
71 |
+
//changes from older versions
|
72 |
+
$db_version = get_option('math_captcha_version');
|
73 |
+
|
74 |
+
if(version_compare(($db_version === FALSE ? '1.0.0' : $db_version), '1.0.9', '<'))
|
75 |
+
{
|
76 |
+
if(($array = get_option('mc_options')) !== FALSE)
|
77 |
+
{
|
78 |
+
update_option('math_captcha_options', $array);
|
79 |
+
delete_option('mc_options');
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
$this->options['general'] = array_merge($this->defaults['general'], (($array = get_option('math_captcha_options')) === FALSE ? array() : $array));
|
84 |
|
85 |
//actions
|
86 |
add_action('plugins_loaded', array(&$this, 'init_mc_session'), 1);
|
98 |
}
|
99 |
|
100 |
|
101 |
+
/**
|
102 |
+
* Activation
|
103 |
+
*/
|
104 |
+
public function activation()
|
105 |
+
{
|
106 |
+
add_option('math_captcha_options', $this->defaults['general'], '', 'no');
|
107 |
+
update_option('math_captcha_version', $this->defaults['version'], '', 'no');
|
108 |
+
}
|
109 |
+
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Deactivation
|
113 |
+
*/
|
114 |
+
public function deactivation()
|
115 |
+
{
|
116 |
+
if($this->options['general']['deactivation_delete'] === TRUE)
|
117 |
+
{
|
118 |
+
delete_option('math_captcha_options');
|
119 |
+
delete_option('math_captcha_version');
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Gets error messages
|
126 |
+
*/
|
127 |
+
public function get_error_messages($error)
|
128 |
+
{
|
129 |
+
return $this->error_messages[$error];
|
130 |
+
}
|
131 |
+
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Gets options
|
135 |
+
*/
|
136 |
+
public function get_options($option)
|
137 |
+
{
|
138 |
+
return $this->options['general'][$option];
|
139 |
+
}
|
140 |
+
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Gets session's ID
|
144 |
+
*/
|
145 |
+
public function get_session_id($number = 0)
|
146 |
+
{
|
147 |
+
return $this->session_ids['multi'][$number];
|
148 |
+
}
|
149 |
+
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Gets session's number for Contact Form 7 multi instances
|
153 |
+
*/
|
154 |
+
public function get_session_number()
|
155 |
+
{
|
156 |
+
return $this->session_number;
|
157 |
+
}
|
158 |
+
|
159 |
+
|
160 |
/**
|
161 |
* Loads required filters
|
162 |
*/
|
165 |
global $pagenow;
|
166 |
|
167 |
//comments
|
168 |
+
if($this->options['general']['enable_for']['comment_form'] === TRUE)
|
169 |
{
|
170 |
if(!is_user_logged_in())
|
171 |
add_action('comment_form_after_fields', array(&$this, 'add_captcha_form'));
|
172 |
else
|
173 |
{
|
174 |
+
if($this->options['general']['hide_for_logged_users'] === FALSE)
|
175 |
{
|
176 |
add_action('comment_form_logged_in_after', array(&$this, 'add_captcha_form'));
|
177 |
}
|
185 |
{
|
186 |
$action = (isset($_GET['action']) && $_GET['action'] !== '' ? $_GET['action'] : NULL);
|
187 |
|
188 |
+
if($this->options['general']['enable_for']['registration_form'] === TRUE && (!is_user_logged_in() || (is_user_logged_in() && $this->options['general']['hide_for_logged_users'] === FALSE)) && $action === 'register')
|
189 |
{
|
190 |
add_action('register_form', array(&$this, 'add_captcha_form'));
|
191 |
add_action('register_post', array(&$this, 'add_user_with_captcha'), 10, 3);
|
193 |
add_filter('wpmu_validate_user_signup', array(&$this, 'validate_user_with_captcha'));
|
194 |
}
|
195 |
|
196 |
+
if($this->options['general']['enable_for']['reset_password_form'] === TRUE && (!is_user_logged_in() || (is_user_logged_in() && $this->options['general']['hide_for_logged_users'] === FALSE)) && $action === 'lostpassword')
|
197 |
{
|
198 |
add_action('lostpassword_form', array(&$this, 'add_captcha_form'));
|
199 |
add_action('lostpassword_post', array(&$this, 'check_lost_password_with_captcha'));
|
200 |
}
|
201 |
|
202 |
+
if($this->options['general']['enable_for']['login_form'] === TRUE && (!is_user_logged_in() || (is_user_logged_in() && $this->options['general']['hide_for_logged_users'] === FALSE)) && $action === NULL)
|
203 |
{
|
204 |
add_action('login_form', array(&$this, 'add_captcha_form'));
|
205 |
add_filter('login_redirect', array(&$this, 'redirect_login_with_captcha'), 10, 3);
|
207 |
}
|
208 |
|
209 |
//bbPress
|
210 |
+
if($this->options['general']['enable_for']['bbpress'] === TRUE)
|
211 |
{
|
212 |
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
213 |
|
214 |
+
if(is_plugin_active('bbpress/bbpress.php') && (!is_user_logged_in() || (is_user_logged_in() && $this->options['general']['hide_for_logged_users'] === FALSE)))
|
215 |
{
|
216 |
add_action('bbp_theme_after_reply_form_content', array(&$this, 'add_bbp_captcha_form'));
|
217 |
add_action('bbp_theme_after_topic_form_content', array(&$this, 'add_bbp_captcha_form'));
|
221 |
}
|
222 |
|
223 |
//Contact Form 7
|
224 |
+
if($this->options['general']['enable_for']['contact_form_7'] === TRUE)
|
225 |
{
|
226 |
include_once(ABSPATH.'wp-admin/includes/plugin.php');
|
227 |
|
236 |
}
|
237 |
|
238 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
239 |
/**
|
240 |
* Validates lost password form
|
241 |
*/
|
248 |
//checks captcha
|
249 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
250 |
{
|
251 |
+
if($this->session_ids['default'] !== '' && get_transient('mc_'.$this->session_ids['default']) !== FALSE)
|
252 |
{
|
253 |
+
if(strcmp(get_transient('mc_'.$this->session_ids['default']), sha1(AUTH_KEY.$_POST['mc-value'].$this->session_ids['default'], FALSE)) !== 0)
|
254 |
+
$this->errors->add('math-captcha-error', $this->error_messages['wrong']);
|
255 |
}
|
256 |
else
|
257 |
+
$this->errors->add('math-captcha-error', $this->error_messages['time']);
|
258 |
}
|
259 |
else
|
260 |
+
$this->errors->add('math-captcha-error', $this->error_messages['fill']);
|
261 |
|
262 |
//checks user_login (from wp-login.php)
|
263 |
if(empty($_POST['user_login']))
|
312 |
{
|
313 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
314 |
{
|
315 |
+
if($this->session_ids['default'] !== '' && get_transient('mc_'.$this->session_ids['default']) !== FALSE)
|
316 |
{
|
317 |
+
if(strcmp(get_transient('mc_'.$this->session_ids['default']), sha1(AUTH_KEY.$_POST['mc-value'].$this->session_ids['default'], FALSE)) !== 0)
|
318 |
+
$errors->add('math-captcha-error', $this->error_messages['wrong']);
|
319 |
}
|
320 |
else
|
321 |
+
$errors->add('math-captcha-error', $this->error_messages['time']);
|
322 |
}
|
323 |
else
|
324 |
+
$errors->add('math-captcha-error', $this->error_messages['fill']);
|
325 |
|
326 |
return $errors;
|
327 |
}
|
328 |
|
329 |
|
330 |
+
/**
|
331 |
+
* Validates register form
|
332 |
+
*/
|
333 |
+
public function validate_user_with_captcha($result)
|
334 |
+
{
|
335 |
+
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
336 |
+
{
|
337 |
+
if($this->session_ids['default'] !== '' && get_transient('mc_'.$this->session_ids['default']) !== FALSE)
|
338 |
+
{
|
339 |
+
if(strcmp(get_transient('mc_'.$this->session_ids['default']), sha1(AUTH_KEY.$_POST['mc-value'].$this->session_ids['default'], FALSE)) !== 0)
|
340 |
+
$results['errors']->add('math-captcha-error', $this->error_messages['wrong']);
|
341 |
+
}
|
342 |
+
else
|
343 |
+
$results['errors']->add('math-captcha-error', $this->error_messages['time']);
|
344 |
+
}
|
345 |
+
else
|
346 |
+
$results['errors']->add('math-captcha-error', $this->error_messages['fill']);
|
347 |
+
|
348 |
+
return $results;
|
349 |
+
}
|
350 |
+
|
351 |
+
|
352 |
/**
|
353 |
* Posts login form
|
354 |
*/
|
359 |
|
360 |
if(isset($_GET['captcha']) && in_array($_GET['captcha'], array('fill', 'wrong', 'time'), TRUE))
|
361 |
{
|
362 |
+
$errors->add('math-captcha-error', $this->error_messages[$_GET['captcha']]);
|
363 |
}
|
364 |
|
365 |
if(!empty($_POST))
|
366 |
{
|
367 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
368 |
{
|
369 |
+
if($this->session_ids['default'] !== '' && get_transient('mc_'.$this->session_ids['default']) !== FALSE)
|
370 |
{
|
371 |
+
if(strcmp(get_transient('mc_'.$this->session_ids['default']), sha1(AUTH_KEY.$_POST['mc-value'].$this->session_ids['default'], FALSE)) !== 0)
|
372 |
{
|
373 |
+
$error = (!is_wp_error($errors) ? TRUE : $errors->add('math-captcha-error', $this->error_messages['wrong']));
|
374 |
$act = 'wrong';
|
375 |
}
|
376 |
}
|
377 |
else
|
378 |
{
|
379 |
+
$error = (!is_wp_error($errors) ? TRUE : $errors->add('math-captcha-error', $this->error_messages['time']));
|
380 |
$act = 'time';
|
381 |
}
|
382 |
}
|
383 |
else
|
384 |
{
|
385 |
+
$error = (!is_wp_error($errors) ? TRUE : $errors->add('math-captcha-error', $this->error_messages['fill']));
|
386 |
$act = 'fill';
|
387 |
}
|
388 |
}
|
408 |
}
|
409 |
|
410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
411 |
/**
|
412 |
* Adds captcha to comment form
|
413 |
*/
|
417 |
{
|
418 |
if($_POST['mc-value'] !== '')
|
419 |
{
|
420 |
+
if($this->session_ids['default'] !== '' && get_transient('mc_'.$this->session_ids['default']) !== FALSE)
|
421 |
{
|
422 |
+
if(strcmp(get_transient('mc_'.$this->session_ids['default']), sha1(AUTH_KEY.$_POST['mc-value'].$this->session_ids['default'], FALSE)) === 0)
|
423 |
return $comment;
|
424 |
else
|
425 |
+
wp_die($this->error_messages['wrong']);
|
426 |
}
|
427 |
else
|
428 |
+
wp_die($this->error_messages['time']);
|
429 |
}
|
430 |
else
|
431 |
+
wp_die($this->error_messages['fill']);
|
432 |
}
|
433 |
else
|
434 |
return $comment;
|
440 |
*/
|
441 |
public function init_mc_session()
|
442 |
{
|
443 |
+
if(isset($_COOKIE['mc_session_ids']))
|
444 |
+
$this->session_ids = $_COOKIE['mc_session_ids'];
|
445 |
else
|
446 |
+
{
|
447 |
+
foreach(array('default', 'multi') as $place)
|
448 |
+
{
|
449 |
+
switch($place)
|
450 |
+
{
|
451 |
+
case 'multi':
|
452 |
+
for($i = 0; $i < 5; $i++)
|
453 |
+
{
|
454 |
+
$this->session_ids[$place][$i] = sha1(wp_generate_password(64, FALSE, FALSE));
|
455 |
+
}
|
456 |
+
break;
|
457 |
+
|
458 |
+
case 'default':
|
459 |
+
$this->session_ids[$place] = sha1(wp_generate_password(64, FALSE, FALSE));
|
460 |
+
break;
|
461 |
+
}
|
462 |
+
}
|
463 |
+
}
|
464 |
|
465 |
+
setcookie('mc_session_ids[default]', $this->session_ids['default'], current_time('timestamp', TRUE) + apply_filters('math_captcha_time', $this->options['general']['time']), COOKIEPATH, COOKIE_DOMAIN);
|
466 |
+
|
467 |
+
for($i = 0; $i < 5; $i++)
|
468 |
+
{
|
469 |
+
setcookie('mc_session_ids[multi]['.$i.']', $this->session_ids['multi'][$i], current_time('timestamp', TRUE) + apply_filters('math_captcha_time', $this->options['general']['time']), COOKIEPATH, COOKIE_DOMAIN);
|
470 |
+
}
|
471 |
}
|
472 |
|
473 |
|
479 |
if(is_admin())
|
480 |
return;
|
481 |
|
482 |
+
$captcha_title = apply_filters('math_captcha_title', $this->options['general']['title']);
|
483 |
|
484 |
echo '
|
485 |
<p class="math-captcha-form">';
|
502 |
if(is_admin())
|
503 |
return;
|
504 |
|
505 |
+
$captcha_title = apply_filters('math_captcha_title', $this->options['general']['title']);
|
506 |
|
507 |
echo '
|
508 |
<p class="math-captcha-form">';
|
524 |
{
|
525 |
if(isset($_POST['mc-value']) && $_POST['mc-value'] !== '')
|
526 |
{
|
527 |
+
if($this->session_ids['default'] !== '' && get_transient('bbp_'.$this->session_ids['default']) !== FALSE)
|
528 |
{
|
529 |
+
if(strcmp(get_transient('bbp_'.$this->session_ids['default']), sha1(AUTH_KEY.$_POST['mc-value'].$this->session_ids['default'], FALSE)) !== 0)
|
530 |
+
bbp_add_error('math-captcha-wrong', $this->error_messages['wrong']);
|
531 |
}
|
532 |
else
|
533 |
+
bbp_add_error('math-captcha-wrong', $this->error_messages['time']);
|
534 |
}
|
535 |
else
|
536 |
+
bbp_add_error('math-captcha-wrong', $this->error_messages['fill']);
|
537 |
}
|
538 |
|
539 |
|
646 |
);
|
647 |
|
648 |
$operations = $groups = array();
|
649 |
+
$input = '<input type="text" size="2" length="2" id="mc-input" name="mc-value" value="" aria-required="true" />';
|
650 |
|
651 |
//available operations
|
652 |
+
foreach($this->options['general']['mathematical_operations'] as $operation => $enable)
|
653 |
{
|
654 |
if($enable === TRUE)
|
655 |
$operations[] = $operation;
|
656 |
}
|
657 |
|
658 |
//available groups
|
659 |
+
foreach($this->options['general']['groups'] as $group => $enable)
|
660 |
{
|
661 |
if($enable === TRUE)
|
662 |
$groups[] = $group;
|
672 |
//place where to put empty input
|
673 |
$rnd_input = mt_rand(0, 2);
|
674 |
|
675 |
+
//which random operation
|
676 |
switch($rnd_op)
|
677 |
{
|
678 |
case 'addition':
|
828 |
$return = $this->encode_operation($number[0]).' '.$number[3].' '.$this->encode_operation($number[1]).' = '.$input;
|
829 |
|
830 |
$transient_name = ($form === 'bbpress' ? 'bbp' : 'mc');
|
831 |
+
$session_id = $this->session_ids['default'];
|
832 |
}
|
833 |
elseif($form === 'cf7')
|
834 |
{
|
854 |
}
|
855 |
|
856 |
$transient_name = 'cf7';
|
857 |
+
$session_id = $this->session_ids['multi'][$this->session_number++];
|
858 |
}
|
859 |
|
860 |
+
set_transient($transient_name.'_'.$session_id, sha1(AUTH_KEY.$number[$rnd_input].$session_id, FALSE), apply_filters('math_captcha_time', $this->options['general']['time']));
|
861 |
|
862 |
return $return;
|
863 |
}
|
864 |
|
865 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
866 |
/**
|
867 |
* Load defaults
|
868 |
*/
|
869 |
public function load_defaults()
|
870 |
{
|
871 |
+
$this->error_messages = array(
|
872 |
'fill' => '<strong>'. __('ERROR', 'math-captcha').'</strong>: '.__('Please enter captcha value.', 'math-captcha'),
|
873 |
'wrong' => '<strong>'. __('ERROR', 'math-captcha').'</strong>: '.__('Invalid captcha value.', 'math-captcha'),
|
874 |
'time' => '<strong>'. __('ERROR', 'math-captcha').'</strong>: '.__('Captcha time expired.', 'math-captcha')
|
908 |
public function register_settings()
|
909 |
{
|
910 |
//inline edit
|
911 |
+
register_setting('math_captcha_options', 'math_captcha_options', array(&$this, 'validate_configuration'));
|
912 |
+
add_settings_section('math_captcha_settings', __('Math Captcha settings', 'math-captcha'), '', 'math_captcha_options');
|
913 |
+
add_settings_field('mc_enable_for', __('Enable Math Captcha for', 'math-captcha'), array(&$this, 'mc_enable_captcha_for'), 'math_captcha_options', 'math_captcha_settings');
|
914 |
+
add_settings_field('mc_hide_for_logged_users', __('Hide for logged in users', 'math-captcha'), array(&$this, 'mc_hide_for_logged_users'), 'math_captcha_options', 'math_captcha_settings');
|
915 |
+
add_settings_field('mc_mathematical_operations', __('Mathematical operations', 'math-captcha'), array(&$this, 'mc_mathematical_operations'), 'math_captcha_options', 'math_captcha_settings');
|
916 |
+
add_settings_field('mc_groups', __('Display captcha as', 'math-captcha'), array(&$this, 'mc_groups'), 'math_captcha_options', 'math_captcha_settings');
|
917 |
+
add_settings_field('mc_title', __('Captcha field title', 'math-captcha'), array(&$this, 'mc_title'), 'math_captcha_options', 'math_captcha_settings');
|
918 |
+
add_settings_field('mc_time', __('Captcha time', 'math-captcha'), array(&$this, 'mc_time'), 'math_captcha_options', 'math_captcha_settings');
|
919 |
+
add_settings_field('mc_deactivation_delete', __('Deactivation', 'math-captcha'), array(&$this, 'mc_deactivation_delete'), 'math_captcha_options', 'math_captcha_settings');
|
920 |
}
|
921 |
|
922 |
|
931 |
foreach($this->enable_for as $val => $trans)
|
932 |
{
|
933 |
echo '
|
934 |
+
<input id="mc-enable-for-'.$val.'" type="checkbox" name="math_captcha_options[enable_for][]" value="'.$val.'" '.checked(TRUE, $this->options['general']['enable_for'][$val], FALSE).' '.disabled((($val === 'contact_form_7' && !is_plugin_active('contact-form-7/wp-contact-form-7.php')) || ($val === 'bbpress' && !is_plugin_active('bbpress/bbpress.php'))), TRUE, FALSE).' />
|
935 |
<label for="mc-enable-for-'.$val.'">'.$trans.'</label>';
|
936 |
}
|
937 |
|
952 |
foreach($this->choices as $val => $trans)
|
953 |
{
|
954 |
echo '
|
955 |
+
<input id="mc-hide-for-logged-'.$val.'" type="radio" name="math_captcha_options[hide_for_logged_users]" value="'.$val.'" '.checked(($val === 'yes' ? TRUE : FALSE), $this->options['general']['hide_for_logged_users'], FALSE).' />
|
956 |
<label for="mc-hide-for-logged-'.$val.'">'.$trans.'</label>';
|
957 |
}
|
958 |
|
969 |
{
|
970 |
echo '
|
971 |
<div>
|
972 |
+
<input type="text" name="math_captcha_options[title]" value="'.$this->options['general']['title'].'" />
|
973 |
<p class="description">'.__('How to entitle field with captcha?', 'math-captcha').'</p>
|
974 |
</div>';
|
975 |
}
|
982 |
{
|
983 |
echo '
|
984 |
<div>
|
985 |
+
<input type="text" name="math_captcha_options[time]" value="'.$this->options['general']['time'].'" />
|
986 |
<p class="description">'.__('Enter the time (in seconds) a user has to enter captcha value.', 'math-captcha').'</p>
|
987 |
</div>';
|
988 |
}
|
999 |
foreach($this->choices as $val => $trans)
|
1000 |
{
|
1001 |
echo '
|
1002 |
+
<input id="mc-deactivation-delete-'.$val.'" type="radio" name="math_captcha_options[deactivation_delete]" value="'.$val.'" '.checked(($val === 'yes' ? TRUE : FALSE), $this->options['general']['deactivation_delete'], FALSE).' />
|
1003 |
<label for="mc-deactivation-delete-'.$val.'">'.$trans.'</label>';
|
1004 |
}
|
1005 |
|
1020 |
foreach($this->mathematical_operations as $val => $trans)
|
1021 |
{
|
1022 |
echo '
|
1023 |
+
<input id="mc-mathematical-operations-'.$val.'" type="checkbox" name="math_captcha_options[mathematical_operations][]" value="'.$val.'" '.checked(TRUE, $this->options['general']['mathematical_operations'][$val], FALSE).' />
|
1024 |
<label for="mc-mathematical-operations-'.$val.'">'.$trans.'</label>';
|
1025 |
}
|
1026 |
|
1041 |
foreach($this->groups as $val => $trans)
|
1042 |
{
|
1043 |
echo '
|
1044 |
+
<input id="mc-groups-'.$val.'" type="checkbox" name="math_captcha_options[groups][]" value="'.$val.'" '.checked(TRUE, $this->options['general']['groups'][$val], FALSE).' />
|
1045 |
<label for="mc-groups-'.$val.'">'.$trans.'</label>';
|
1046 |
}
|
1047 |
|
1056 |
*/
|
1057 |
public function validate_configuration($input)
|
1058 |
{
|
1059 |
+
if(isset($_POST['save_math_captcha_options']))
|
1060 |
{
|
1061 |
$enable_for = array();
|
1062 |
$mathematical_operations = array();
|
1064 |
|
1065 |
if(empty($input['enable_for']))
|
1066 |
{
|
1067 |
+
foreach($this->defaults['general']['enable_for'] as $enable => $bool)
|
1068 |
{
|
1069 |
$input['enable_for'][$enable] = FALSE;
|
1070 |
}
|
1079 |
$input['enable_for'] = $enable_for;
|
1080 |
}
|
1081 |
|
1082 |
+
if(!is_plugin_active('contact-form-7/wp-contact-form-7.php') && $this->options['general']['enable_for']['contact_form_7'] === TRUE)
|
1083 |
$input['enable_for']['contact_form_7'] = TRUE;
|
1084 |
|
1085 |
+
if(!is_plugin_active('bbpress/bbpress.php') && $this->options['general']['enable_for']['bbpress'] === TRUE)
|
1086 |
$input['enable_for']['bbpress'] = TRUE;
|
1087 |
|
1088 |
if(empty($input['mathematical_operations']))
|
1089 |
{
|
1090 |
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');
|
1091 |
|
1092 |
+
$input['mathematical_operations'] = $this->defaults['general']['mathematical_operations'];
|
1093 |
}
|
1094 |
else
|
1095 |
{
|
1105 |
{
|
1106 |
add_settings_error('empty-groups', 'settings_updated', __('You need to check at least one group. Defaults settings of this option restored.', 'math-captcha'), 'error');
|
1107 |
|
1108 |
+
$input['groups'] = $this->defaults['general']['groups'];
|
1109 |
}
|
1110 |
else
|
1111 |
{
|
1117 |
$input['groups'] = $groups;
|
1118 |
}
|
1119 |
|
1120 |
+
$input['hide_for_logged_users'] = (isset($input['hide_for_logged_users']) && in_array($input['hide_for_logged_users'], array_keys($this->choices)) ? ($input['hide_for_logged_users'] === 'yes' ? TRUE : FALSE) : $this->defaults['general']['hide_for_logged_users']);
|
1121 |
|
1122 |
+
$input['deactivation_delete'] = (isset($input['deactivation_delete']) && in_array($input['deactivation_delete'], array_keys($this->choices)) ? ($input['deactivation_delete'] === 'yes' ? TRUE : FALSE) : $this->options['general']['deactivation_delete']);
|
1123 |
|
1124 |
$input['title'] = trim(sanitize_text_field($input['title']));
|
1125 |
|
1126 |
$time = (int)$input['time'];
|
1127 |
+
$input['time'] = ($time < 0 ? $this->defaults['general']['time'] : $time);
|
1128 |
}
|
1129 |
|
1130 |
return $input;
|
1158 |
<form action="options.php" method="post">';
|
1159 |
|
1160 |
wp_nonce_field('update-options');
|
1161 |
+
settings_fields('math_captcha_options');
|
1162 |
+
do_settings_sections('math_captcha_options');
|
1163 |
+
submit_button('', 'primary', 'save_math_captcha_options', TRUE);
|
1164 |
|
1165 |
echo '
|
1166 |
</form>
|
1256 |
return $links;
|
1257 |
}
|
1258 |
}
|
|
|
|
|
1259 |
?>
|