Spam protection, AntiSpam, FireWall by CleanTalk - Version 4.17

Version Description

2015-02-12 = * New base class. * Divided code to 3 separate files - common, public and admin.

Download this release

Release Info

Developer shagimuratov
Plugin Icon 128x128 Spam protection, AntiSpam, FireWall by CleanTalk
Version 4.17
Comparing to
See all releases

Code changes from version 4.16 to 4.17

Files changed (5) hide show
  1. cleantalk-common.php +278 -0
  2. cleantalk-public.php +1641 -0
  3. cleantalk.class.php +5 -3
  4. cleantalk.php +52 -1956
  5. readme.txt +10 -3
cleantalk-common.php ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $ct_agent_version = 'wordpress-417';
4
+ $ct_plugin_name = 'Anti-spam by CleanTalk';
5
+ $ct_checkjs_frm = 'ct_checkjs_frm';
6
+ $ct_checkjs_register_form = 'ct_checkjs_register_form';
7
+ $ct_session_request_id_label = 'request_id';
8
+ $ct_session_register_ok_label = 'register_ok';
9
+
10
+ $ct_checkjs_cf7 = 'ct_checkjs_cf7';
11
+ $ct_cf7_comment = '';
12
+
13
+ $ct_checkjs_jpcf = 'ct_checkjs_jpcf';
14
+ $ct_jpcf_patched = false;
15
+ $ct_jpcf_fields = array('name', 'email');
16
+
17
+ // Comment already proccessed
18
+ $ct_comment_done = false;
19
+
20
+ // Comment already proccessed
21
+ $ct_signup_done = false;
22
+
23
+ // Default value for JS test
24
+ $ct_checkjs_def = 0;
25
+
26
+ // COOKIE label to store request id for last approved
27
+ $ct_approved_request_id_label = 'ct_approved_request_id';
28
+
29
+ // Last request id approved for publication
30
+ $ct_approved_request_id = null;
31
+
32
+ // COOKIE label for trial notice flag
33
+ $ct_notice_trial_label = 'ct_notice_trial';
34
+
35
+ // Flag to show trial notice
36
+ $show_ct_notice_trial = false;
37
+
38
+ // COOKIE label for online notice flag
39
+ $ct_notice_online_label = 'ct_notice_online';
40
+
41
+ // Flag to show online notice - 'Y' or 'N'
42
+ $show_ct_notice_online = '';
43
+
44
+ // Timeout before new check for trial notice in hours
45
+ $trial_notice_check_timeout = 1;
46
+
47
+ // Timeout before new check account notice in hours
48
+ $account_notice_check_timeout = 24;
49
+
50
+ // Trial notice show time in minutes
51
+ $trial_notice_showtime = 10;
52
+
53
+ // COOKIE label for WP Landing Page proccessing result
54
+ $ct_wplp_result_label = 'ct_wplp_result';
55
+
56
+ // Flag indicates active JetPack comments
57
+ $ct_jp_comments = false;
58
+
59
+ // S2member PayPal post data label
60
+ $ct_post_data_label = 's2member_pro_paypal_registration';
61
+
62
+ // S2member Auth.Net post data label
63
+ $ct_post_data_authnet_label = 's2member_pro_authnet_registration';
64
+
65
+ // Form time load label
66
+ $ct_formtime_label = 'ct_formtime';
67
+
68
+ // Plugin's options
69
+ $ct_options = null;
70
+
71
+ // Account status check last time
72
+ $ct_account_status_check = 0;
73
+
74
+ // Post without page load
75
+ $ct_direct_post = 0;
76
+
77
+ // WP admin email notice interval in seconds
78
+ $ct_admin_notoice_period = 10800;
79
+
80
+ // Sevice negative comment to visitor.
81
+ // It uses for BuddyPress registrations to avoid double checks
82
+ $ct_negative_comment = null;
83
+
84
+ /**
85
+ * Public action 'plugins_loaded' - Loads locale, see http://codex.wordpress.org/Function_Reference/load_plugin_textdomain
86
+ */
87
+ function ct_plugin_loaded() {
88
+ load_plugin_textdomain('cleantalk', false, basename(dirname(__FILE__)) . '/i18n');
89
+ }
90
+
91
+ /**
92
+ * Session init
93
+ * @return null;
94
+ */
95
+ function ct_init_session() {
96
+ if(session_id() === '') {
97
+ @session_start();
98
+ }
99
+
100
+ return null;
101
+ }
102
+
103
+ /**
104
+ * Inner function - Current Cleantalk options
105
+ * @return mixed[] Array of options
106
+ */
107
+ function ct_get_options() {
108
+ $options = get_option('cleantalk_settings');
109
+ if (!is_array($options)){
110
+ $options = array();
111
+ }else{
112
+ if(array_key_exists('apikey', $options))
113
+ $options['apikey'] = trim($options['apikey']);
114
+ }
115
+ return array_merge(ct_def_options(), (array) $options);
116
+ }
117
+
118
+ /**
119
+ * Inner function - Default Cleantalk options
120
+ * @return mixed[] Array of default options
121
+ */
122
+ function ct_def_options() {
123
+ return array(
124
+ 'server' => 'http://moderate.cleantalk.org',
125
+ 'apikey' => __('enter key', 'cleantalk'),
126
+ 'autoPubRevelantMess' => '0',
127
+ 'registrations_test' => '1',
128
+ 'comments_test' => '1',
129
+ 'contact_forms_test' => '1',
130
+ 'general_contact_forms_test' => '1', // Antispam test for unsupported and untested contact forms
131
+ 'remove_old_spam' => '0',
132
+ 'spam_store_days' => '15', // Days before delete comments from folder Spam
133
+ 'ssl_on' => 0, // Secure connection to servers
134
+ 'next_account_status_check' => 0, // Time label when the plugin should check account status
135
+ 'user_token' => '', // User token
136
+ 'relevance_test' => 0, // Test comment for relevance
137
+ 'notice_api_errors' => 0, // Send API error notices to WP admin
138
+ 'js_keys' => array(), // Keys to do JavaScript antispam test
139
+ 'js_keys_store_days' => 1, // JavaScript keys store days
140
+ 'js_key_lifetime' => 3600, // JavaScript key life time in seconds
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Inner function - Stores ang returns cleantalk hash of current comment
146
+ * @param string New hash or NULL
147
+ * @return string New hash or current hash depending on parameter
148
+ */
149
+ function ct_hash($new_hash = '') {
150
+ /**
151
+ * Current hash
152
+ */
153
+ static $hash;
154
+
155
+ if (!empty($new_hash)) {
156
+ $hash = $new_hash;
157
+ }
158
+ return $hash;
159
+ }
160
+
161
+ /**
162
+ * Inner function - Write manual moderation results to PHP sessions
163
+ * @param string $hash Cleantalk comment hash
164
+ * @param string $message comment_content
165
+ * @param int $allow flag good comment (1) or bad (0)
166
+ * @return string comment_content w\o cleantalk resume
167
+ */
168
+ function ct_feedback($hash, $message = null, $allow) {
169
+ global $ct_options;
170
+
171
+ require_once('cleantalk.class.php');
172
+
173
+ $config = get_option('cleantalk_server');
174
+
175
+ $ct = new Cleantalk();
176
+ $ct->work_url = $config['ct_work_url'];
177
+ $ct->server_url = $ct_options['server'];
178
+ $ct->server_ttl = $config['ct_server_ttl'];
179
+ $ct->server_changed = $config['ct_server_changed'];
180
+
181
+ if (empty($hash)) {
182
+ $hash = $ct->getCleantalkCommentHash($message);
183
+ }
184
+
185
+ $resultMessage = null;
186
+ if ($message !== null) {
187
+ $resultMessage = $ct->delCleantalkComment($message);
188
+ }
189
+
190
+ $ct_feedback = $hash . ':' . $allow . ';';
191
+ if (empty($_SESSION['feedback_request'])) {
192
+ $_SESSION['feedback_request'] = $ct_feedback;
193
+ } else {
194
+ $_SESSION['feedback_request'] .= $ct_feedback;
195
+ }
196
+
197
+ return $resultMessage;
198
+ }
199
+
200
+ /**
201
+ * Inner function - Sends the results of moderation
202
+ * @param string $feedback_request
203
+ * @return bool
204
+ */
205
+ function ct_send_feedback($feedback_request = null) {
206
+ global $ct_options;
207
+
208
+ if (empty($feedback_request) && isset($_SESSION['feedback_request']) && preg_match("/^[a-z0-9\;\:]+$/", $_SESSION['feedback_request'])) {
209
+ $feedback_request = $_SESSION['feedback_request'];
210
+ unset($_SESSION['feedback_request']);
211
+ }
212
+
213
+ if ($feedback_request !== null) {
214
+ require_once('cleantalk.class.php');
215
+ $config = get_option('cleantalk_server');
216
+
217
+ $ct = new Cleantalk();
218
+ $ct->work_url = $config['ct_work_url'];
219
+ $ct->server_url = $ct_options['server'];
220
+ $ct->server_ttl = $config['ct_server_ttl'];
221
+ $ct->server_changed = $config['ct_server_changed'];
222
+
223
+ $ct_request = new CleantalkRequest();
224
+ $ct_request->auth_key = $ct_options['apikey'];
225
+ $ct_request->feedback = $feedback_request;
226
+
227
+ $ct->sendFeedback($ct_request);
228
+
229
+ if ($ct->server_change) {
230
+ update_option(
231
+ 'cleantalk_server', array(
232
+ 'ct_work_url' => $ct->work_url,
233
+ 'ct_server_ttl' => $ct->server_ttl,
234
+ 'ct_server_changed' => time()
235
+ )
236
+ );
237
+ }
238
+ return true;
239
+ }
240
+
241
+ return false;
242
+ }
243
+
244
+ /**
245
+ * On the scheduled action hook, run the function.
246
+ */
247
+ function ct_do_this_hourly() {
248
+ global $ct_options;
249
+ // do something every hour
250
+
251
+ if (!isset($ct_options))
252
+ $ct_options = ct_get_options();
253
+
254
+ delete_spam_comments();
255
+ ct_send_feedback();
256
+ }
257
+
258
+ /**
259
+ * Delete old spam comments
260
+ * @return null
261
+ */
262
+ function delete_spam_comments() {
263
+ global $pagenow, $ct_options;
264
+
265
+ if ($ct_options['remove_old_spam'] == 1) {
266
+ $last_comments = get_comments(array('status' => 'spam', 'number' => 1000, 'order' => 'ASC'));
267
+ foreach ($last_comments as $c) {
268
+ if (time() - strtotime($c->comment_date_gmt) > 86400 * $ct_options['spam_store_days']) {
269
+ // Force deletion old spam comments
270
+ wp_delete_comment($c->comment_ID, true);
271
+ }
272
+ }
273
+ }
274
+
275
+ return null;
276
+ }
277
+
278
+ ?>
cleantalk-public.php ADDED
@@ -0,0 +1,1641 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Init functions
5
+ * @return mixed[] Array of options
6
+ */
7
+ function ct_init() {
8
+ global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_direct_post, $ct_options;
9
+
10
+ $ct_options = ct_get_options();
11
+
12
+ ct_init_session();
13
+
14
+ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
15
+ if (!array_key_exists($ct_formtime_label, $_SESSION) && session_id() != '') {
16
+ $ct_direct_post = 1;
17
+ }
18
+ } else {
19
+ $_SESSION[$ct_formtime_label] = time();
20
+ }
21
+
22
+ // Fast Secure contact form
23
+ if(defined('FSCF_VERSION')){
24
+ add_filter('si_contact_display_after_fields', 'ct_si_contact_display_after_fields');
25
+ add_filter('si_contact_form_validate', 'ct_si_contact_form_validate');
26
+ }
27
+
28
+ // WooCoomerse signups
29
+ if(class_exists('WooCommerce')){
30
+ add_filter('woocommerce_register_post', 'ct_register_post', 1, 3);
31
+ }
32
+
33
+ // JetPack Contact form
34
+ $jetpack_active_modules = false;
35
+ if(defined('JETPACK__VERSION')){
36
+ add_filter('grunion_contact_form_field_html', 'ct_grunion_contact_form_field_html', 10, 2);
37
+ add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
38
+ $jetpack_active_modules = get_option('jetpack_active_modules');
39
+ if (
40
+ (class_exists( 'Jetpack', false) && $jetpack_active_modules && in_array('comments', $jetpack_active_modules))
41
+ ) {
42
+ $ct_jp_comments = true;
43
+ }
44
+ }
45
+
46
+ // Contact Form7
47
+ if(defined('WPCF7_VERSION')){
48
+ add_filter('wpcf7_form_elements', 'ct_wpcf7_form_elements');
49
+ if(WPCF7_VERSION >= '3.0.0'){
50
+ add_filter('wpcf7_spam', 'ct_wpcf7_spam');
51
+ }else{
52
+ add_filter('wpcf7_acceptance', 'ct_wpcf7_spam');
53
+ }
54
+ }
55
+
56
+ // Formidable
57
+ if(class_exists('FrmSettings')){
58
+ add_action('frm_validate_entry', 'ct_frm_validate_entry', 20, 2);
59
+ add_action('frm_entries_footer_scripts', 'ct_frm_entries_footer_scripts', 20, 2);
60
+ }
61
+
62
+ // BuddyPress
63
+ if(class_exists('BuddyPress')){
64
+ add_action('bp_before_registration_submit_buttons','ct_register_form');
65
+ add_filter('bp_signup_validate', 'ct_registration_errors');
66
+ }
67
+
68
+ // bbPress
69
+ if(class_exists('bbPress')){
70
+ add_filter('bbp_new_topic_pre_content', 'ct_bbp_new_pre_content', 1);
71
+ add_filter('bbp_new_reply_pre_content', 'ct_bbp_new_pre_content', 1);
72
+ add_action('bbp_theme_before_topic_form_content', 'ct_comment_form');
73
+ add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
74
+ }
75
+
76
+ add_action('comment_form', 'ct_comment_form');
77
+
78
+ //intercept WordPress Landing Pages POST
79
+ if (defined('LANDINGPAGES_CURRENT_VERSION') && !empty($_POST)){
80
+ if(array_key_exists('action', $_POST) && $_POST['action'] === 'inbound_store_lead'){ // AJAX action(s)
81
+ ct_check_wplp();
82
+ }else if(array_key_exists('inbound_submitted', $_POST) && $_POST['inbound_submitted'] == '1'){ // Final submit
83
+ ct_check_wplp();
84
+ }
85
+ }
86
+
87
+ // intercept S2member POST
88
+ if (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION') && (isset($_POST[$ct_post_data_label]['email']) || isset($_POST[$ct_post_data_authnet_label]['email']))){
89
+ ct_s2member_registration_test();
90
+ }
91
+
92
+ //
93
+ // New user approve hack
94
+ // https://wordpress.org/plugins/new-user-approve/
95
+ //
96
+ if (ct_plugin_active('new-user-approve/new-user-approve.php')) {
97
+ add_action('register_post', 'ct_register_post', 1, 3);
98
+ }
99
+
100
+ //
101
+ // Load JS code to website footer
102
+ //
103
+ if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
104
+ add_action('wp_footer', 'ct_footer_add_cookie', 1);
105
+ }
106
+ if (ct_is_user_enable()) {
107
+ ct_cookies_test();
108
+
109
+ if (isset($ct_options['general_contact_forms_test']) && $ct_options['general_contact_forms_test'] == 1) {
110
+ ct_contact_form_validate();
111
+ }
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Cookies test for sender
117
+ * @return null|0|1;
118
+ */
119
+ function ct_cookies_test ($test = false) {
120
+ $cookie_label = 'ct_cookies_test';
121
+ $secret_hash = ct_get_checkjs_value();
122
+
123
+ $result = null;
124
+ if (isset($_COOKIE[$cookie_label])) {
125
+ if ($_COOKIE[$cookie_label] == $secret_hash) {
126
+ $result = 1;
127
+ } else {
128
+ $result = 0;
129
+ }
130
+ } else {
131
+ @setcookie($cookie_label, $secret_hash, 0, '/');
132
+
133
+ if ($test) {
134
+ $result = 0;
135
+ }
136
+ }
137
+
138
+ return $result;
139
+ }
140
+
141
+ /**
142
+ * Inner function - Common part of request sending
143
+ * @param array Array of parameters:
144
+ * 'message' - string
145
+ * 'example' - string
146
+ * 'checkjs' - int
147
+ * 'sender_email' - string
148
+ * 'sender_nickname' - string
149
+ * 'sender_info' - array
150
+ * 'post_info' - string
151
+ * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
152
+ */
153
+ function ct_base_call($params = array()) {
154
+ global $wpdb, $ct_agent_version, $ct_formtime_label, $ct_options;
155
+
156
+ require_once('cleantalk.class.php');
157
+
158
+ $submit_time = submit_time_test();
159
+
160
+ $sender_info = get_sender_info();
161
+ if (array_key_exists('sender_info', $params)) {
162
+ $sender_info = array_merge($sender_info, (array) $params['sender_info']);
163
+ }
164
+ $sender_info = json_encode($sender_info);
165
+ if ($sender_info === false)
166
+ $sender_info = '';
167
+
168
+ $config = get_option('cleantalk_server');
169
+
170
+ $ct = new Cleantalk();
171
+ $ct->work_url = $config['ct_work_url'];
172
+ $ct->server_url = $ct_options['server'];
173
+ $ct->server_ttl = $config['ct_server_ttl'];
174
+ $ct->server_changed = $config['ct_server_changed'];
175
+ $ct->ssl_on = $ct_options['ssl_on'];
176
+
177
+ $ct_request = new CleantalkRequest();
178
+
179
+ $ct_request->auth_key = $ct_options['apikey'];
180
+ $ct_request->message = $params['message'];
181
+ $ct_request->example = $params['example'];
182
+ $ct_request->sender_email = $params['sender_email'];
183
+ $ct_request->sender_nickname = $params['sender_nickname'];
184
+ $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
185
+ $ct_request->agent = $ct_agent_version;
186
+ $ct_request->sender_info = $sender_info;
187
+ $ct_request->js_on = $params['checkjs'];
188
+ $ct_request->submit_time = $submit_time;
189
+ $ct_request->post_info = $params['post_info'];
190
+
191
+ $ct_result = $ct->isAllowMessage($ct_request);
192
+ if ($ct->server_change) {
193
+ update_option(
194
+ 'cleantalk_server', array(
195
+ 'ct_work_url' => $ct->work_url,
196
+ 'ct_server_ttl' => $ct->server_ttl,
197
+ 'ct_server_changed' => time()
198
+ )
199
+ );
200
+ }
201
+
202
+ // Restart submit form counter for failed requests
203
+ if ($ct_result->allow == 0) {
204
+ $_SESSION[$ct_formtime_label] = time();
205
+ }
206
+
207
+ return array('ct' => $ct, 'ct_result' => $ct_result);
208
+ }
209
+
210
+ /**
211
+ * Adds hidden filed to comment form
212
+ */
213
+ function ct_comment_form($post_id) {
214
+ global $ct_options;
215
+
216
+ if (ct_is_user_enable() === false) {
217
+ return false;
218
+ }
219
+
220
+ if ($ct_options['comments_test'] == 0) {
221
+ return false;
222
+ }
223
+
224
+ ct_add_hidden_fields(true, 'ct_checkjs', false, false);
225
+
226
+ return null;
227
+ }
228
+
229
+ /**
230
+ * Adds cookie script filed to footer
231
+ */
232
+ function ct_footer_add_cookie() {
233
+ if (ct_is_user_enable() === false) {
234
+ # return false;
235
+ }
236
+
237
+ ct_add_hidden_fields(true, 'ct_checkjs', false, true);
238
+
239
+ return null;
240
+ }
241
+
242
+ /**
243
+ * Adds hidden filed to define avaialbility of client's JavaScript
244
+ * @param bool $random_key switch on generation random key for every page load
245
+ */
246
+ function ct_add_hidden_fields($random_key = false, $field_name = 'ct_checkjs', $return_string = false, $cookie_check = false) {
247
+ global $ct_checkjs_def, $ct_plugin_name;
248
+
249
+ $ct_checkjs_key = ct_get_checkjs_value($random_key);
250
+ $field_id_hash = md5(rand(0, 1000));
251
+
252
+ if ($cookie_check) {
253
+ $html = '
254
+ <script type="text/javascript">
255
+ function ctSetCookie(c_name, value, def_value) {
256
+ document.cookie = c_name + "=" + escape(value.replace(/^def_value$/, value)) + "; path=/";
257
+ }
258
+ ctSetCookie("%s", "%s", "%s");
259
+ </script>
260
+ ';
261
+ $html = sprintf($html, $field_name, $ct_checkjs_key, $ct_checkjs_def);
262
+ } else {
263
+ $ct_input_challenge = sprintf("'%s'", $ct_checkjs_key);
264
+
265
+ $field_id = $field_name . '_' . $field_id_hash;
266
+ $html = '
267
+ <input type="hidden" id="%s" name="%s" value="%s" />
268
+ <script type="text/javascript">
269
+ setTimeout(function(){var ct_input_name = \'%s\';var ct_input_value = document.getElementById(ct_input_name).value;document.getElementById(ct_input_name).value = document.getElementById(ct_input_name).value.replace(ct_input_value, %s); }, 1000);
270
+ </script>
271
+ ';
272
+ $html = sprintf($html, $field_id, $field_name, $ct_checkjs_def, $field_id, $ct_input_challenge);
273
+ };
274
+
275
+ // Simplify JS code
276
+ // and fixing issue with wpautop()
277
+ $html = str_replace(array("\n","\r"),'', $html);
278
+
279
+ if ($return_string === true) {
280
+ return $html;
281
+ } else {
282
+ echo $html;
283
+ }
284
+ }
285
+
286
+ /**
287
+ * Is enable for user group
288
+ * @return boolean
289
+ */
290
+ function ct_is_user_enable() {
291
+ global $current_user;
292
+
293
+ if (!isset($current_user->roles)) {
294
+ return true;
295
+ }
296
+
297
+ $disable_roles = array('administrator', 'editor', 'author');
298
+ foreach ($current_user->roles as $k => $v) {
299
+ if (in_array($v, $disable_roles))
300
+ return false;
301
+ }
302
+
303
+ return true;
304
+ }
305
+
306
+ /**
307
+ * Public function - Insert JS code for spam tests
308
+ * return null;
309
+ */
310
+ function ct_frm_entries_footer_scripts($fields, $form) {
311
+ global $current_user, $ct_checkjs_frm, $ct_options;
312
+
313
+ if ($ct_options['contact_forms_test'] == 0) {
314
+ return false;
315
+ }
316
+
317
+ $ct_checkjs_key = ct_get_checkjs_value();
318
+ $ct_frm_name = 'form_' . $form->form_key;
319
+
320
+ ?>
321
+
322
+ var input = document.createElement("input");
323
+ input.setAttribute("type", "hidden");
324
+ input.setAttribute("name", "<?php echo $ct_checkjs_frm; ?>");
325
+ input.setAttribute("value", "<?php echo $ct_checkjs_key; ?>");
326
+ document.getElementById("<?php echo $ct_frm_name; ?>").appendChild(input);
327
+
328
+ <?php
329
+ }
330
+
331
+ /**
332
+ * Public function - Test Formidable data for spam activity
333
+ * return @array with errors if spam has found
334
+ */
335
+ function ct_frm_validate_entry ($errors, $values) {
336
+ global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_frm, $ct_options;
337
+
338
+ if ($ct_options['contact_forms_test'] == 0) {
339
+ return false;
340
+ }
341
+
342
+ $checkjs = js_test($ct_checkjs_frm, $_POST);
343
+
344
+ $post_info['comment_type'] = 'feedback';
345
+ $post_info = json_encode($post_info);
346
+ if ($post_info === false)
347
+ $post_info = '';
348
+
349
+ $sender_email = null;
350
+ $message = '';
351
+ foreach ($values['item_meta'] as $v) {
352
+ if (isset($v) && is_string($v) && preg_match("/^\S+@\S+\.\S+$/", $v)) {
353
+ $sender_email = $v;
354
+ continue;
355
+ }
356
+ $message .= ' ' . $v;
357
+ }
358
+
359
+ $ct_base_call_result = ct_base_call(array(
360
+ 'message' => $message,
361
+ 'example' => null,
362
+ 'sender_email' => $sender_email,
363
+ 'sender_nickname' => null,
364
+ 'post_info' => $post_info,
365
+ 'checkjs' => $checkjs
366
+ ));
367
+ $ct = $ct_base_call_result['ct'];
368
+ $ct_result = $ct_base_call_result['ct_result'];
369
+
370
+ if ($ct_result->spam == 1) {
371
+ $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
372
+ }
373
+
374
+ return $errors;
375
+ }
376
+
377
+ /**
378
+ * Public filter 'bbp_*' - Checks topics, replies by cleantalk
379
+ * @param mixed[] $comment Comment string
380
+ * @return mixed[] $comment Comment string
381
+ */
382
+ function ct_bbp_new_pre_content ($comment) {
383
+ global $ct_options;
384
+
385
+ if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || is_user_logged_in()) {
386
+ return $comment;
387
+ }
388
+
389
+ $checkjs = js_test('ct_checkjs', $_COOKIE, true);
390
+ if ($checkjs === null) {
391
+ $checkjs = js_test('ct_checkjs', $_POST, true);
392
+ }
393
+
394
+ $example = null;
395
+
396
+ $sender_info = array(
397
+ 'sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null
398
+ );
399
+
400
+ $post_info['comment_type'] = 'bbpress_comment';
401
+ $post_info['post_url'] = bbp_get_topic_permalink();
402
+
403
+ $post_info = json_encode($post_info);
404
+ if ($post_info === false) {
405
+ $post_info = '';
406
+ }
407
+
408
+ $ct_base_call_result = ct_base_call(array(
409
+ 'message' => $comment,
410
+ 'example' => $example,
411
+ 'sender_email' => isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null,
412
+ 'sender_nickname' => isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null,
413
+ 'post_info' => $post_info,
414
+ 'checkjs' => $checkjs,
415
+ 'sender_info' => $sender_info
416
+ ));
417
+ $ct = $ct_base_call_result['ct'];
418
+ $ct_result = $ct_base_call_result['ct_result'];
419
+
420
+ if ($ct_result->stop_queue == 1 || $ct_result->spam == 1 || ($ct_result->allow == 0 && $ct_result->stop_words !== null)) {
421
+ bbp_add_error('bbp_reply_content', $ct_result->comment);
422
+ }
423
+
424
+ return $comment;
425
+ }
426
+
427
+ /**
428
+ * Public filter 'preprocess_comment' - Checks comment by cleantalk server
429
+ * @param mixed[] $comment Comment data array
430
+ * @return mixed[] New data array of comment
431
+ */
432
+ function ct_preprocess_comment($comment) {
433
+ // this action is called just when WP process POST request (adds new comment)
434
+ // this action is called by wp-comments-post.php
435
+ // after processing WP makes redirect to post page with comment's form by GET request (see above)
436
+ global $wpdb, $current_user, $comment_post_id, $ct_agent_version, $ct_comment_done, $ct_approved_request_id_label, $ct_jp_comments, $ct_options;
437
+
438
+ if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || $ct_comment_done) {
439
+ return $comment;
440
+ }
441
+
442
+ $local_blacklists = wp_blacklist_check(
443
+ $comment['comment_author'],
444
+ $comment['comment_author_email'],
445
+ $comment['comment_author_url'],
446
+ $comment['comment_content'],
447
+ @$_SERVER['REMOTE_ADDR'],
448
+ @$_SERVER['HTTP_USER_AGENT']
449
+ );
450
+
451
+ // Go out if author in local blacklists
452
+ if ($local_blacklists === true) {
453
+ return $comment;
454
+ }
455
+
456
+ // Skip pingback anti-spam test
457
+ if ($comment['comment_type'] == 'pingback') {
458
+ return $comment;
459
+ }
460
+
461
+ $ct_comment_done = true;
462
+
463
+ $comment_post_id = $comment['comment_post_ID'];
464
+
465
+ $sender_info = array(
466
+ 'sender_url' => @$comment['comment_author_url']
467
+ );
468
+
469
+ //
470
+ // JetPack comments logic
471
+ //
472
+ if ($ct_jp_comments) {
473
+ $post_info['comment_type'] = 'jetpack_comment';
474
+ $checkjs = js_test('ct_checkjs', $_COOKIE, true);
475
+ } else {
476
+ $post_info['comment_type'] = $comment['comment_type'];
477
+ $checkjs = js_test('ct_checkjs', $_POST, true);
478
+ }
479
+
480
+ $post_info['post_url'] = ct_post_url(null, $comment_post_id);
481
+ $post_info = json_encode($post_info);
482
+ if ($post_info === false) {
483
+ $post_info = '';
484
+ }
485
+
486
+ $example = null;
487
+ if ($ct_options['relevance_test']) {
488
+ $post = get_post($comment_post_id);
489
+ if ($post !== null){
490
+ $example['title'] = $post->post_title;
491
+ $example['body'] = $post->post_content;
492
+ $example['comments'] = null;
493
+
494
+ $last_comments = get_comments(array('status' => 'approve', 'number' => 10, 'post_id' => $comment_post_id));
495
+ foreach ($last_comments as $post_comment){
496
+ $example['comments'] .= "\n\n" . $post_comment->comment_content;
497
+ }
498
+
499
+ $example = json_encode($example);
500
+ }
501
+
502
+ // Use plain string format if've failed with JSON
503
+ if ($example === false || $example === null){
504
+ $example = ($post->post_title !== null) ? $post->post_title : '';
505
+ $example .= ($post->post_content !== null) ? "\n\n" . $post->post_content : '';
506
+ }
507
+ }
508
+
509
+ $ct_base_call_result = ct_base_call(array(
510
+ 'message' => $comment['comment_content'],
511
+ 'example' => $example,
512
+ 'sender_email' => $comment['comment_author_email'],
513
+ 'sender_nickname' => $comment['comment_author'],
514
+ 'post_info' => $post_info,
515
+ 'checkjs' => $checkjs,
516
+ 'sender_info' => $sender_info
517
+ ));
518
+ $ct = $ct_base_call_result['ct'];
519
+ $ct_result = $ct_base_call_result['ct_result'];
520
+
521
+ if ($ct_result->stop_queue == 1) {
522
+ $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_result->comment;
523
+ $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
524
+ wp_die($err_text, 'Blacklisted', array('back_link' => true));
525
+
526
+ return $comment;
527
+ }
528
+
529
+ ct_hash($ct_result->id);
530
+ if ($ct_result->spam == 1) {
531
+ add_filter('pre_comment_approved', 'ct_set_comment_spam');
532
+
533
+ global $ct_comment;
534
+ $ct_comment = $ct_result->comment;
535
+ add_action('comment_post', 'ct_die', 12, 2);
536
+ add_action('comment_post', 'ct_set_meta', 10, 2);
537
+
538
+ return $comment;
539
+ }
540
+
541
+ if (isset($comment['comment_author_email'])) {
542
+ $approved_comments = get_comments(array('status' => 'approve', 'count' => true, 'author_email' => $comment['comment_author_email']));
543
+
544
+ // Change comment flow only for new authors
545
+ if ((int) $approved_comments == 0 || $ct_result->stop_words !== null) {
546
+
547
+ if ($ct_result->allow == 1 && get_option('comment_moderation') !== '1') {
548
+ add_filter('pre_comment_approved', 'ct_set_approved');
549
+ setcookie($ct_approved_request_id_label, $ct_result->id, 0, '/');
550
+ }
551
+ if ($ct_result->allow == 0) {
552
+ if (isset($ct_result->stop_words)) {
553
+ global $ct_stop_words;
554
+ $ct_stop_words = $ct_result->stop_words;
555
+ add_action('comment_post', 'ct_mark_red', 11, 2);
556
+ }
557
+
558
+ add_filter('pre_comment_approved', 'ct_set_not_approved');
559
+ }
560
+
561
+ add_action('comment_post', 'ct_set_meta', 10, 2);
562
+ }
563
+ }
564
+
565
+ return $comment;
566
+ }
567
+
568
+ /**
569
+ * Set die page with Cleantalk comment.
570
+ * @global type $ct_comment
571
+ $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_comment;
572
+ * @param type $comment_status
573
+ */
574
+ function ct_die($comment_id, $comment_status) {
575
+ global $ct_comment;
576
+ $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_comment;
577
+ $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
578
+ wp_die($err_text, 'Blacklisted', array('back_link' => true));
579
+ }
580
+
581
+ /**
582
+ * Set die page with Cleantalk comment from parameter.
583
+ * @param type $comment_body
584
+ */
585
+ function ct_die_extended($comment_body) {
586
+ $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $comment_body;
587
+ $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
588
+ wp_die($err_text, 'Blacklisted', array('back_link' => true));
589
+ }
590
+
591
+ /**
592
+ * Validates JavaScript anti-spam test
593
+ *
594
+ */
595
+ function js_test($field_name = 'ct_checkjs', $data = null, $random_key = false) {
596
+ global $ct_options;
597
+
598
+ $checkjs = null;
599
+ $js_post_value = null;
600
+
601
+ if (!$data)
602
+ return $checkjs;
603
+
604
+ if (isset($data[$field_name])) {
605
+ $js_post_value = $data[$field_name];
606
+
607
+ //
608
+ // Random key check
609
+ //
610
+ if ($random_key) {
611
+
612
+ $keys = $ct_options['js_keys'];
613
+ if (isset($keys[$js_post_value])) {
614
+ $checkjs = 1;
615
+ } else {
616
+ $checkjs = 0;
617
+ }
618
+ } else {
619
+ $ct_challenge = ct_get_checkjs_value();
620
+
621
+ if(preg_match("/$ct_challenge/", $js_post_value)) {
622
+ $checkjs = 1;
623
+ } else {
624
+ $checkjs = 0;
625
+ }
626
+ }
627
+
628
+
629
+ }
630
+
631
+ return $checkjs;
632
+ }
633
+
634
+ /**
635
+ * Validate form submit time
636
+ *
637
+ */
638
+ function submit_time_test() {
639
+ global $ct_formtime_label;
640
+
641
+ $submit_time = null;
642
+ if (isset($_SESSION[$ct_formtime_label])) {
643
+ $submit_time = time() - (int) $_SESSION[$ct_formtime_label];
644
+ }
645
+
646
+ return $submit_time;
647
+ }
648
+
649
+ /**
650
+ * Get post url
651
+ * @param int $comment_id
652
+ * @param int $comment_post_id
653
+ * @return string|bool
654
+ */
655
+ function ct_post_url($comment_id = null, $comment_post_id) {
656
+
657
+ if (empty($comment_post_id))
658
+ return null;
659
+
660
+ if ($comment_id === null) {
661
+ $last_comment = get_comments('number=1');
662
+ $comment_id = isset($last_comment[0]->comment_ID) ? (int) $last_comment[0]->comment_ID + 1 : 1;
663
+ }
664
+ $permalink = get_permalink($comment_post_id);
665
+
666
+ $post_url = null;
667
+ if ($permalink !== null)
668
+ $post_url = $permalink . '#comment-' . $comment_id;
669
+
670
+ return $post_url;
671
+ }
672
+
673
+ /**
674
+ * Public filter 'pre_comment_approved' - Mark comment unapproved always
675
+ * @return int Zero
676
+ */
677
+ function ct_set_not_approved() {
678
+ return 0;
679
+ }
680
+
681
+ /**
682
+ * @author Artem Leontiev
683
+ * Public filter 'pre_comment_approved' - Mark comment approved always
684
+ * @return int 1
685
+ */
686
+ function ct_set_approved() {
687
+ return 1;
688
+ }
689
+
690
+ /**
691
+ * Public filter 'pre_comment_approved' - Mark comment unapproved always
692
+ * @return int Zero
693
+ */
694
+ function ct_set_comment_spam() {
695
+ return 'spam';
696
+ }
697
+
698
+ /**
699
+ * Public action 'comment_post' - Store cleantalk hash in comment meta 'ct_hash'
700
+ * @param int $comment_id Comment ID
701
+ * @param mixed $comment_status Approval status ("spam", or 0/1), not used
702
+ */
703
+ function ct_set_meta($comment_id, $comment_status) {
704
+ global $comment_post_id;
705
+ $hash1 = ct_hash();
706
+ if (!empty($hash1)) {
707
+ update_comment_meta($comment_id, 'ct_hash', $hash1);
708
+ if (function_exists('base64_encode') && isset($comment_status) && $comment_status != 'spam') {
709
+ $post_url = ct_post_url($comment_id, $comment_post_id);
710
+ $post_url = base64_encode($post_url);
711
+ if ($post_url === false)
712
+ return false;
713
+ // 01 - URL to approved comment
714
+ $feedback_request = $hash1 . ':' . '01' . ':' . $post_url . ';';
715
+ ct_send_feedback($feedback_request);
716
+ }
717
+ }
718
+ return true;
719
+ }
720
+
721
+ /**
722
+ * Mark bad words
723
+ * @global string $ct_stop_words
724
+ * @param int $comment_id
725
+ * @param int $comment_status Not use
726
+ */
727
+ function ct_mark_red($comment_id, $comment_status) {
728
+ global $ct_stop_words;
729
+
730
+ $comment = get_comment($comment_id, 'ARRAY_A');
731
+ $message = $comment['comment_content'];
732
+ foreach (explode(':', $ct_stop_words) as $word) {
733
+ $message = preg_replace("/($word)/ui", '<font rel="cleantalk" color="#FF1000">' . "$1" . '</font>', $message);
734
+
735
+ }
736
+ $comment['comment_content'] = $message;
737
+ kses_remove_filters();
738
+ wp_update_comment($comment);
739
+ }
740
+
741
+ /**
742
+ * Unmark bad words
743
+ * @param string $message
744
+ * @return string Cleat comment
745
+ */
746
+ function ct_unmark_red($message) {
747
+ $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
748
+
749
+ return $message;
750
+ }
751
+
752
+ /**
753
+ * Tests plugin activation status
754
+ * @return bool
755
+ */
756
+ function ct_plugin_active($plugin_name){
757
+ foreach (get_option('active_plugins') as $k => $v) {
758
+ if ($plugin_name == $v)
759
+ return true;
760
+ }
761
+ return false;
762
+ }
763
+
764
+ /**
765
+ * Get ct_get_checkjs_value
766
+ * @return string
767
+ */
768
+ function ct_get_checkjs_value($random_key = false) {
769
+ global $ct_options;
770
+
771
+ if ($random_key) {
772
+ $keys = $ct_options['js_keys'];
773
+ $keys_checksum = md5(json_encode($keys));
774
+
775
+ $key = null;
776
+ $latest_key_time = 0;
777
+ foreach ($keys as $k => $t) {
778
+
779
+ // Removing key if it's to old
780
+ if (time() - $t > $ct_options['js_keys_store_days'] * 86400) {
781
+ unset($keys[$k]);
782
+ continue;
783
+ }
784
+
785
+ if ($t > $latest_key_time) {
786
+ $latest_key_time = $t;
787
+ $key = $k;
788
+ }
789
+ }
790
+
791
+ // Get new key if the latest key is too old
792
+ if (time() - $latest_key_time > $ct_options['js_key_lifetime']) {
793
+ $key = rand();
794
+ $keys[$key] = time();
795
+ }
796
+
797
+ if (md5(json_encode($keys)) != $keys_checksum) {
798
+ $ct_options['js_keys'] = $keys;
799
+ update_option('cleantalk_settings', $ct_options);
800
+ }
801
+ } else {
802
+ $key = md5($ct_options['apikey'] . '+' . get_option('admin_email'));
803
+ }
804
+
805
+ return $key;
806
+ }
807
+
808
+
809
+ /**
810
+ * Insert a hidden field to registration form
811
+ * @return null
812
+ */
813
+ function ct_register_form() {
814
+ global $ct_checkjs_register_form, $ct_options;
815
+
816
+ if ($ct_options['registrations_test'] == 0) {
817
+ return false;
818
+ }
819
+
820
+ ct_add_hidden_fields(true, $ct_checkjs_register_form, false);
821
+
822
+ return null;
823
+ }
824
+
825
+ /**
826
+ * Adds notification text to login form - to inform about approced registration
827
+ * @return null
828
+ */
829
+ function ct_login_message($message) {
830
+ global $errors, $ct_session_register_ok_label, $ct_options;
831
+
832
+ if ($ct_options['registrations_test'] != 0) {
833
+ if( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) {
834
+ if (isset($_SESSION[$ct_session_register_ok_label])) {
835
+ unset($_SESSION[$ct_session_register_ok_label]);
836
+ if(is_wp_error($errors))
837
+ $errors->add('ct_message','<br />' . sprintf(__('Registration is approved by %s.', 'cleantalk'), '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk</b>'), 'message');
838
+ }
839
+ }
840
+ }
841
+ return $message;
842
+ }
843
+
844
+ /**
845
+ * Test users registration for multisite enviroment
846
+ * @return array with errors
847
+ */
848
+ function ct_registration_errors_wpmu($errors) {
849
+ global $ct_signup_done;
850
+
851
+ //
852
+ // Multisite actions
853
+ //
854
+ $sanitized_user_login = null;
855
+ if (isset($errors['user_name'])) {
856
+ $sanitized_user_login = $errors['user_name'];
857
+ $wpmu = true;
858
+ }
859
+ $user_email = null;
860
+ if (isset($errors['user_email'])) {
861
+ $user_email = $errors['user_email'];
862
+ $wpmu = true;
863
+ }
864
+
865
+ if ($wpmu && isset($errors['errors']->errors) && count($errors['errors']->errors) > 0) {
866
+ return $errors;
867
+ }
868
+
869
+ $errors['errors'] = ct_registration_errors($errors['errors'], $sanitized_user_login, $user_email);
870
+
871
+ // Show CleanTalk errors in user_name field
872
+ if (isset($errors['errors']->errors['ct_error'])) {
873
+ $errors['errors']->errors['user_name'] = $errors['errors']->errors['ct_error'];
874
+ unset($errors['errors']->errors['ct_error']);
875
+ }
876
+
877
+ return $errors;
878
+ }
879
+
880
+ /**
881
+ * Shell for action register_post
882
+ * @return array with errors
883
+ */
884
+ function ct_register_post($sanitized_user_login = null, $user_email = null, $errors) {
885
+ return ct_registration_errors($errors, $sanitized_user_login, $user_email);
886
+ }
887
+
888
+ /**
889
+ * Test users registration
890
+ * @return array with errors
891
+ */
892
+ function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
893
+ global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options;
894
+
895
+ // Go out if a registrered user action
896
+ if (ct_is_user_enable() === false) {
897
+ return $errors;
898
+ }
899
+
900
+ if ($ct_options['registrations_test'] == 0) {
901
+ return $errors;
902
+ }
903
+
904
+ //
905
+ // The function already executed
906
+ // It happens when used ct_register_post();
907
+ //
908
+ if ($ct_signup_done && is_object($errors) && count($errors->errors) > 0) {
909
+ return $errors;
910
+ }
911
+
912
+ //
913
+ // BuddyPress actions
914
+ //
915
+ $buddypress = false;
916
+ if ($sanitized_user_login === null && isset($_POST['signup_username'])) {
917
+ $sanitized_user_login = $_POST['signup_username'];
918
+ $buddypress = true;
919
+ }
920
+ if ($user_email === null && isset($_POST['signup_email'])) {
921
+ $user_email = $_POST['signup_email'];
922
+ $buddypress = true;
923
+ }
924
+
925
+ //
926
+ // Break tests because we already have servers response
927
+ //
928
+ if ($buddypress && $ct_signup_done) {
929
+ if ($ct_negative_comment) {
930
+ $bp->signup->errors['signup_username'] = $ct_negative_comment;
931
+ }
932
+ return $errors;
933
+ }
934
+
935
+ $submit_time = submit_time_test();
936
+
937
+ $sender_info = get_sender_info();
938
+
939
+ $checkjs = js_test($ct_checkjs_register_form, $_POST, true);
940
+ $sender_info['post_checkjs_passed'] = $checkjs;
941
+
942
+ //
943
+ // This hack can be helpfull when plugin uses with untested themes&signups plugins.
944
+ //
945
+ if ($checkjs === null) {
946
+ $checkjs = js_test('ct_checkjs', $_COOKIE, true);
947
+ $sender_info['cookie_checkjs_passed'] = $checkjs;
948
+ }
949
+
950
+ $sender_info = json_encode($sender_info);
951
+ if ($sender_info === false) {
952
+ $sender_info= '';
953
+ }
954
+
955
+ require_once('cleantalk.class.php');
956
+ $config = get_option('cleantalk_server');
957
+ $ct = new Cleantalk();
958
+ $ct->work_url = $config['ct_work_url'];
959
+ $ct->server_url = $ct_options['server'];
960
+
961
+ $ct->server_ttl = $config['ct_server_ttl'];
962
+ $ct->server_changed = $config['ct_server_changed'];
963
+ $ct->ssl_on = $ct_options['ssl_on'];
964
+
965
+ $ct_request = new CleantalkRequest();
966
+ $ct_request->auth_key = $ct_options['apikey'];
967
+ $ct_request->sender_email = $user_email;
968
+ $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
969
+ $ct_request->sender_nickname = $sanitized_user_login;
970
+ $ct_request->agent = $ct_agent_version;
971
+ $ct_request->sender_info = $sender_info;
972
+ $ct_request->js_on = $checkjs;
973
+ $ct_request->submit_time = $submit_time;
974
+
975
+ $ct_result = $ct->isAllowUser($ct_request);
976
+ if ($ct->server_change) {
977
+ update_option(
978
+ 'cleantalk_server', array(
979
+ 'ct_work_url' => $ct->work_url,
980
+ 'ct_server_ttl' => $ct->server_ttl,
981
+ 'ct_server_changed' => time()
982
+ )
983
+ );
984
+ }
985
+
986
+ $ct_signup_done = true;
987
+
988
+ if ($ct_result->errno != 0 && $ct_options['notice_api_errors']) {
989
+ ct_send_error_notice($ct_result->comment);
990
+ return $errors;
991
+ }
992
+
993
+ if ($ct_result->inactive != 0) {
994
+ ct_send_error_notice($ct_result->comment);
995
+ return $errors;
996
+ }
997
+
998
+ if ($ct_result->allow == 0) {
999
+
1000
+ // Restart submit form counter for failed requests
1001
+ $_SESSION[$ct_formtime_label] = time();
1002
+
1003
+ if ($buddypress === true) {
1004
+ $bp->signup->errors['signup_username'] = $ct_result->comment;
1005
+ } else {
1006
+ $errors->add('ct_error', $ct_result->comment);
1007
+ $ct_negative_comment = $ct_result->comment;
1008
+ }
1009
+ } else {
1010
+ if ($ct_result->id !== null) {
1011
+ $_SESSION[$ct_session_request_id_label] = $ct_result->id;
1012
+ $_SESSION[$ct_session_register_ok_label] = $ct_result->id;
1013
+ }
1014
+ }
1015
+
1016
+ return $errors;
1017
+ }
1018
+
1019
+ /**
1020
+ * Set user meta
1021
+ * @return null
1022
+ */
1023
+ function ct_user_register($user_id) {
1024
+ global $ct_session_request_id_label;
1025
+
1026
+ if (isset($_SESSION[$ct_session_request_id_label])) {
1027
+ update_user_meta($user_id, 'ct_hash', $_SESSION[$ct_session_request_id_label]);
1028
+ unset($_SESSION[$ct_session_request_id_label]);
1029
+ }
1030
+ }
1031
+
1032
+
1033
+ /**
1034
+ * Test for JetPack contact form
1035
+ */
1036
+ function ct_grunion_contact_form_field_html($r, $field_label) {
1037
+ global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $ct_options;
1038
+
1039
+ if ($ct_options['contact_forms_test'] == 1 && $ct_jpcf_patched === false && preg_match("/[text|email]/i", $r)) {
1040
+
1041
+ // Looking for element name prefix
1042
+ $name_patched = false;
1043
+ foreach ($ct_jpcf_fields as $v) {
1044
+ if ($name_patched === false && preg_match("/(g\d-)$v/", $r, $matches)) {
1045
+ $ct_checkjs_jpcf = $matches[1] . $ct_checkjs_jpcf;
1046
+ $name_patched = true;
1047
+ }
1048
+ }
1049
+
1050
+ $r .= ct_add_hidden_fields(true, $ct_checkjs_jpcf, true);
1051
+ $ct_jpcf_patched = true;
1052
+ }
1053
+
1054
+ return $r;
1055
+ }
1056
+ /**
1057
+ * Test for JetPack contact form
1058
+ */
1059
+ function ct_contact_form_is_spam($form) {
1060
+ global $ct_checkjs_jpcf, $ct_options;
1061
+
1062
+ if ($ct_options['contact_forms_test'] == 0) {
1063
+ return null;
1064
+ }
1065
+
1066
+ $js_field_name = $ct_checkjs_jpcf;
1067
+ foreach ($_POST as $k => $v) {
1068
+ if (preg_match("/^.+$ct_checkjs_jpcf$/", $k))
1069
+ $js_field_name = $k;
1070
+ }
1071
+
1072
+ $checkjs = js_test($js_field_name, $_POST, true);
1073
+
1074
+ $sender_info = array(
1075
+ 'sender_url' => @$form['comment_author_url']
1076
+ );
1077
+
1078
+ $post_info['comment_type'] = 'feedback';
1079
+ $post_info = json_encode($post_info);
1080
+ if ($post_info === false)
1081
+ $post_info = '';
1082
+
1083
+ $sender_email = null;
1084
+ $sender_nickname = null;
1085
+ $message = '';
1086
+ if (isset($form['comment_author_email']))
1087
+ $sender_email = $form['comment_author_email'];
1088
+
1089
+ if (isset($form['comment_author']))
1090
+ $sender_nickname = $form['comment_author'];
1091
+
1092
+ if (isset($form['comment_content']))
1093
+ $message = $form['comment_content'];
1094
+
1095
+ $ct_base_call_result = ct_base_call(array(
1096
+ 'message' => $message,
1097
+ 'example' => null,
1098
+ 'sender_email' => $sender_email,
1099
+ 'sender_nickname' => $sender_nickname,
1100
+ 'post_info' => $post_info,
1101
+ 'sender_info' => $sender_info,
1102
+ 'checkjs' => $checkjs
1103
+ ));
1104
+ $ct = $ct_base_call_result['ct'];
1105
+ $ct_result = $ct_base_call_result['ct_result'];
1106
+
1107
+ if ($ct_result->spam == 1) {
1108
+ global $ct_comment;
1109
+ $ct_comment = $ct_result->comment;
1110
+ ct_die(null, null);
1111
+ exit;
1112
+ }
1113
+
1114
+ return (bool) $ct_result->spam;
1115
+ }
1116
+
1117
+
1118
+ /**
1119
+ * Inserts anti-spam hidden to CF7
1120
+ */
1121
+ function ct_wpcf7_form_elements($html) {
1122
+ global $wpdb, $current_user, $ct_checkjs_cf7, $ct_options;
1123
+
1124
+ if ($ct_options['contact_forms_test'] == 0) {
1125
+ return $html;
1126
+ }
1127
+
1128
+ $html .= ct_add_hidden_fields(true, $ct_checkjs_cf7, true);
1129
+
1130
+ return $html;
1131
+ }
1132
+
1133
+ /**
1134
+ * Test CF7 message for spam
1135
+ */
1136
+ function ct_wpcf7_spam($param) {
1137
+ global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_cf7, $ct_cf7_comment, $ct_options;
1138
+
1139
+ if (WPCF7_VERSION >= '3.0.0') {
1140
+ if($param === true)
1141
+ return $param;
1142
+ }else{
1143
+ if($param == false)
1144
+ return $param;
1145
+ }
1146
+
1147
+ if ($ct_options['contact_forms_test'] == 0) {
1148
+ return $param;
1149
+ }
1150
+
1151
+ $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1152
+ if($checkjs != 1){
1153
+ $checkjs = js_test($ct_checkjs_cf7, $_POST, true);
1154
+ }
1155
+
1156
+ $post_info['comment_type'] = 'feedback';
1157
+ $post_info = json_encode($post_info);
1158
+ if ($post_info === false)
1159
+ $post_info = '';
1160
+
1161
+ $sender_email = null;
1162
+ $sender_nickname = null;
1163
+ $message = '';
1164
+ $subject = '';
1165
+ foreach ($_POST as $k => $v) {
1166
+ if ($sender_email === null && preg_match("/^\S+@\S+\.\S+$/", $v)) {
1167
+ $sender_email = $v;
1168
+ }
1169
+ if ($message === '' && preg_match("/(\-message|\w*message\w*|contact|comment)$/", $k)) {
1170
+ $message = $v;
1171
+ }
1172
+ if ($sender_nickname === null && preg_match("/-name$/", $k)) {
1173
+ $sender_nickname = $v;
1174
+ }
1175
+ if ($subject === '' && ct_get_data_from_submit($k, 'subject')) {
1176
+ $subject = $v;
1177
+ }
1178
+
1179
+ }
1180
+
1181
+ if ($subject != '') {
1182
+ if ($message != '') {
1183
+ $message = "\n\n" . $message;
1184
+ }
1185
+ $message = sprintf("%s%s", $subject, $message);
1186
+ }
1187
+
1188
+ $ct_base_call_result = ct_base_call(array(
1189
+ 'message' => $message,
1190
+ 'example' => null,
1191
+ 'sender_email' => $sender_email,
1192
+ 'sender_nickname' => $sender_nickname,
1193
+ 'post_info' => $post_info,
1194
+ 'checkjs' => $checkjs
1195
+ ));
1196
+ $ct = $ct_base_call_result['ct'];
1197
+ $ct_result = $ct_base_call_result['ct_result'];
1198
+
1199
+ if ($ct_result->spam == 1) {
1200
+ if (WPCF7_VERSION >= '3.0.0') {
1201
+ $param = true;
1202
+ }else{
1203
+ $param = false;
1204
+ }
1205
+ $ct_cf7_comment = $ct_result->comment;
1206
+ add_filter('wpcf7_display_message', 'ct_wpcf7_display_message', 10, 2);
1207
+
1208
+ }
1209
+
1210
+ return $param;
1211
+ }
1212
+
1213
+ /**
1214
+ * Changes CF7 status message
1215
+ * @param string $hook URL of hooked page
1216
+ */
1217
+ function ct_wpcf7_display_message($message, $status = 'spam') {
1218
+ global $ct_cf7_comment;
1219
+
1220
+ if ($status == 'spam') {
1221
+ $message = $ct_cf7_comment;
1222
+ }
1223
+
1224
+ return $message;
1225
+ }
1226
+
1227
+ /**
1228
+ * Inserts anti-spam hidden to Fast Secure contact form
1229
+ */
1230
+ function ct_si_contact_display_after_fields($string = '', $style = '', $form_errors = array(), $form_id_num = 0) {
1231
+ $string .= ct_add_hidden_fields(true, 'ct_checkjs', true);
1232
+ return $string;
1233
+ }
1234
+
1235
+ /**
1236
+ * Test for Fast Secure contact form
1237
+ */
1238
+ function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
1239
+ global $ct_options;
1240
+
1241
+ if (!empty($form_errors))
1242
+ return $form_errors;
1243
+
1244
+ if ($ct_options['contact_forms_test'] == 0)
1245
+ return $form_errors;
1246
+
1247
+ $checkjs = js_test('ct_checkjs', $_POST, true);
1248
+
1249
+ $post_info['comment_type'] = 'feedback';
1250
+ $post_info = json_encode($post_info);
1251
+ if ($post_info === false)
1252
+ $post_info = '';
1253
+
1254
+ $sender_email = null;
1255
+ $sender_nickname = null;
1256
+ $subject = '';
1257
+ $message = '';
1258
+ if (isset($_POST['email']))
1259
+ $sender_email = $_POST['email'];
1260
+
1261
+ if (isset($_POST['full_name']))
1262
+ $sender_nickname = $_POST['full_name'];
1263
+
1264
+ if (isset($_POST['subject']))
1265
+ $subject = $_POST['subject'];
1266
+
1267
+ if (isset($_POST['message']))
1268
+ $message = $_POST['message'];
1269
+
1270
+ $ct_base_call_result = ct_base_call(array(
1271
+ 'message' => $subject . "\n\n" . $message,
1272
+ 'example' => null,
1273
+ 'sender_email' => $sender_email,
1274
+ 'sender_nickname' => $sender_nickname,
1275
+ 'post_info' => $post_info,
1276
+ 'sender_info' => $sender_info,
1277
+ 'checkjs' => $checkjs
1278
+ ));
1279
+ $ct = $ct_base_call_result['ct'];
1280
+ $ct_result = $ct_base_call_result['ct_result'];
1281
+
1282
+ if ($ct_result->spam == 1) {
1283
+ global $ct_comment;
1284
+ $ct_comment = $ct_result->comment;
1285
+ ct_die(null, null);
1286
+ exit;
1287
+ }
1288
+
1289
+ return $form_errors;
1290
+ }
1291
+
1292
+ /**
1293
+ * Notice for commentators which comment has automatically approved by plugin
1294
+ * @param string $hook URL of hooked page
1295
+ */
1296
+ function ct_comment_text($comment_text) {
1297
+ global $comment, $ct_approved_request_id_label;
1298
+
1299
+ if (isset($_COOKIE[$ct_approved_request_id_label]) && isset($comment->comment_ID)) {
1300
+ $ct_hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
1301
+
1302
+ if ($ct_hash !== '' && $_COOKIE[$ct_approved_request_id_label] == $ct_hash) {
1303
+ $comment_text .= '<br /><br /> <em class="comment-awaiting-moderation">' . __('Comment approved. Anti-spam by CleanTalk.', 'cleantalk') . '</em>';
1304
+ }
1305
+ }
1306
+
1307
+ return $comment_text;
1308
+ }
1309
+
1310
+
1311
+ /**
1312
+ * Checks WordPress Landing Pages raw $_POST values
1313
+ */
1314
+ function ct_check_wplp(){
1315
+ global $ct_wplp_result_label, $ct_options;
1316
+ if (!isset($_COOKIE[$ct_wplp_result_label])) {
1317
+ // First AJAX submit of WPLP form
1318
+ if ($ct_options['contact_forms_test'] == 0)
1319
+ return;
1320
+
1321
+ $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1322
+
1323
+ $post_info['comment_type'] = 'feedback';
1324
+ $post_info = json_encode($post_info);
1325
+ if ($post_info === false)
1326
+ $post_info = '';
1327
+
1328
+ $sender_email = '';
1329
+ foreach ($_POST as $v) {
1330
+ if (preg_match("/^\S+@\S+\.\S+$/", $v)) {
1331
+ $sender_email = $v;
1332
+ break;
1333
+ }
1334
+ }
1335
+
1336
+ $message = '';
1337
+ if(array_key_exists('form_input_values', $_POST)){
1338
+ $form_input_values = json_decode(stripslashes($_POST['form_input_values']), true);
1339
+ if (is_array($form_input_values) && array_key_exists('null', $form_input_values))
1340
+ $message = $form_input_values['null'];
1341
+ } else if (array_key_exists('null', $_POST)) {
1342
+ $message = $_POST['null'];
1343
+ }
1344
+
1345
+ $ct_base_call_result = ct_base_call(array(
1346
+ 'message' => $message,
1347
+ 'example' => null,
1348
+ 'sender_email' => $sender_email,
1349
+ 'sender_nickname' => null,
1350
+ 'post_info' => $post_info,
1351
+ 'checkjs' => $checkjs
1352
+ ));
1353
+ $ct = $ct_base_call_result['ct'];
1354
+ $ct_result = $ct_base_call_result['ct_result'];
1355
+
1356
+ if ($ct_result->spam == 1) {
1357
+ $cleantalk_comment = $ct_result->comment;
1358
+ } else {
1359
+ $cleantalk_comment = 'OK';
1360
+ }
1361
+
1362
+ setcookie($ct_wplp_result_label, $cleantalk_comment, strtotime("+5 seconds"), '/');
1363
+ } else {
1364
+ // Next POST/AJAX submit(s) of same WPLP form
1365
+ $cleantalk_comment = $_COOKIE[$ct_wplp_result_label];
1366
+ }
1367
+ if ($cleantalk_comment !== 'OK')
1368
+ ct_die_extended($cleantalk_comment);
1369
+ }
1370
+
1371
+ /**
1372
+ * Test S2member registration
1373
+ * @return array with errors
1374
+ */
1375
+ function ct_s2member_registration_test() {
1376
+ global $ct_agent_version, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_options;
1377
+
1378
+ if ($ct_options['registrations_test'] == 0) {
1379
+ return null;
1380
+ }
1381
+
1382
+ $submit_time = submit_time_test();
1383
+
1384
+ $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1385
+
1386
+ require_once('cleantalk.class.php');
1387
+
1388
+ $sender_info = get_sender_info();
1389
+ $sender_info = json_encode($sender_info);
1390
+ if ($sender_info === false) {
1391
+ $sender_info= '';
1392
+ }
1393
+
1394
+ $sender_email = null;
1395
+ if (isset($_POST[$ct_post_data_label]['email']))
1396
+ $sender_email = $_POST[$ct_post_data_label]['email'];
1397
+
1398
+ if (isset($_POST[$ct_post_data_authnet_label]['email']))
1399
+ $sender_email = $_POST[$ct_post_data_authnet_label]['email'];
1400
+
1401
+ $sender_nickname = null;
1402
+ if (isset($_POST[$ct_post_data_label]['username']))
1403
+ $sender_nickname = $_POST[$ct_post_data_label]['username'];
1404
+
1405
+ if (isset($_POST[$ct_post_data_authnet_label]['username']))
1406
+ $sender_nickname = $_POST[$ct_post_data_authnet_label]['username'];
1407
+
1408
+ $config = get_option('cleantalk_server');
1409
+
1410
+ $ct = new Cleantalk();
1411
+ $ct->work_url = $config['ct_work_url'];
1412
+ $ct->server_url = $ct_options['server'];
1413
+ $ct->server_ttl = $config['ct_server_ttl'];
1414
+ $ct->server_changed = $config['ct_server_changed'];
1415
+ $ct->ssl_on = $ct_options['ssl_on'];
1416
+
1417
+ $ct_request = new CleantalkRequest();
1418
+
1419
+ $ct_request->auth_key = $ct_options['apikey'];
1420
+ $ct_request->sender_email = $sender_email;
1421
+ $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
1422
+ $ct_request->sender_nickname = $sender_nickname;
1423
+ $ct_request->agent = $ct_agent_version;
1424
+ $ct_request->sender_info = $sender_info;
1425
+ $ct_request->js_on = $checkjs;
1426
+ $ct_request->submit_time = $submit_time;
1427
+
1428
+ $ct_result = $ct->isAllowUser($ct_request);
1429
+ if ($ct->server_change) {
1430
+ update_option(
1431
+ 'cleantalk_server', array(
1432
+ 'ct_work_url' => $ct->work_url,
1433
+ 'ct_server_ttl' => $ct->server_ttl,
1434
+ 'ct_server_changed' => time()
1435
+ )
1436
+ );
1437
+ }
1438
+
1439
+ if ($ct_result->errno != 0) {
1440
+ return false;
1441
+ }
1442
+
1443
+ // Restart submit form counter for failed requests
1444
+ if ($ct_result->allow == 0) {
1445
+ $_SESSION[$ct_formtime_label] = time();
1446
+ }
1447
+
1448
+ if ($ct_result->allow == 0) {
1449
+ ct_die_extended($ct_result->comment);
1450
+ }
1451
+
1452
+ return true;
1453
+ }
1454
+
1455
+ /**
1456
+ * General test for any contact form
1457
+ */
1458
+ function ct_contact_form_validate () {
1459
+ global $pagenow;
1460
+
1461
+ if ($_SERVER['REQUEST_METHOD'] != 'POST' ||
1462
+ (isset($_POST['log']) && isset($_POST['pwd']) && isset($pagenow) && $pagenow == 'wp-login.php') // WordPress log in form
1463
+ ) {
1464
+ return null;
1465
+ }
1466
+
1467
+ $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1468
+
1469
+ $post_info['comment_type'] = 'feedback_general_contact_form';
1470
+ $post_info = json_encode($post_info);
1471
+ if ($post_info === false) {
1472
+ $post_info = '';
1473
+ }
1474
+
1475
+ $sender_email = null;
1476
+ $sender_nickname = null;
1477
+ $subject = '';
1478
+ $message = '';
1479
+ $contact_form = true;
1480
+
1481
+ $skip_params = array(
1482
+ 'ipn_track_id', // PayPal IPN #
1483
+ 'txn_type', // PayPal transaction type
1484
+ );
1485
+ if (is_array($_POST)) {
1486
+ foreach ($_POST as $k => $v) {
1487
+ if (in_array($k, $skip_params) || preg_match("/^ct_checkjs/", $k)) {
1488
+ $contact_form = false;
1489
+ break;
1490
+ }
1491
+
1492
+ if ($sender_email === null && isset($v)) {
1493
+ if (is_string($v) && preg_match("/^\S+@\S+\.\S+$/", $v)) {
1494
+ $sender_email = $v;
1495
+ }
1496
+
1497
+ // Looing email address in arrays
1498
+ if (is_array($v)) {
1499
+ foreach ($v as $v2) {
1500
+ if ($sender_email) {
1501
+ continue;
1502
+ }
1503
+
1504
+ if (is_string($v2) && preg_match("/^\S+@\S+\.\S+$/", $v2)) {
1505
+ $sender_email = $v2;
1506
+ }
1507
+ }
1508
+ }
1509
+ }
1510
+ if ($sender_nickname === null && ct_get_data_from_submit($k, 'name')) {
1511
+ $sender_nickname = $v;
1512
+ }
1513
+ if ($message === '' && ct_get_data_from_submit($k, 'message')) {
1514
+ $message = $v;
1515
+ }
1516
+ if ($subject === '' && ct_get_data_from_submit($k, 'subject')) {
1517
+ $subject = $v;
1518
+ }
1519
+ }
1520
+ }
1521
+
1522
+ // Skip submission if no data found
1523
+ if (!$sender_email || !$contact_form) {
1524
+ return false;
1525
+ }
1526
+
1527
+ $ct_base_call_result = ct_base_call(array(
1528
+ 'message' => $subject . "\n\n" . $message,
1529
+ 'example' => null,
1530
+ 'sender_email' => $sender_email,
1531
+ 'sender_nickname' => $sender_nickname,
1532
+ 'post_info' => $post_info,
1533
+ 'sender_info' => $sender_info,
1534
+ 'checkjs' => $checkjs
1535
+ ));
1536
+
1537
+ $ct = $ct_base_call_result['ct'];
1538
+ $ct_result = $ct_base_call_result['ct_result'];
1539
+
1540
+ if ($ct_result->allow == 0) {
1541
+
1542
+ if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
1543
+ global $ct_comment;
1544
+ $ct_comment = $ct_result->comment;
1545
+ ct_die(null, null);
1546
+ } else {
1547
+ echo $ct_result->comment;
1548
+ }
1549
+ exit;
1550
+ }
1551
+
1552
+ return null;
1553
+ }
1554
+
1555
+
1556
+ /**
1557
+ * Inner function - Finds and returns pattern in string
1558
+ * @return null|bool
1559
+ */
1560
+ function ct_get_data_from_submit($value = null, $field_name = null) {
1561
+ if (!$value || !$field_name || !is_string($value)) {
1562
+ return false;
1563
+ }
1564
+ if (preg_match("/[a-z0-9_\-]*" . $field_name. "[a-z0-9_\-]*$/", $value)) {
1565
+ return true;
1566
+ }
1567
+ }
1568
+
1569
+
1570
+ /**
1571
+ * Inner function - Default data array for senders
1572
+ * @return array
1573
+ */
1574
+ function get_sender_info() {
1575
+ global $ct_direct_post, $ct_options;
1576
+
1577
+ $php_session = session_id() != '' ? 1 : 0;
1578
+
1579
+ // Raw data to validated JavaScript test in the cloud
1580
+ $checkjs_data_cookies = null;
1581
+ if (isset($_COOKIE['ct_checkjs'])) {
1582
+ $checkjs_data_cookies = $_COOKIE['ct_checkjs'];
1583
+ }
1584
+
1585
+ $checkjs_data_post = null;
1586
+ if (count($_POST) > 0) {
1587
+ foreach ($_POST as $k => $v) {
1588
+ if (preg_match("/^ct_check.+/", $k)) {
1589
+ $checkjs_data_post = $v;
1590
+ }
1591
+ }
1592
+ }
1593
+
1594
+ $options2server = array( // Options for sending to server for support information
1595
+ 'apikey' => $ct_options['apikey'],
1596
+ 'registrations_test' => $ct_options['registrations_test'],
1597
+ 'comments_test' => $ct_options['comments_test'],
1598
+ 'contact_forms_test' => $ct_options['contact_forms_test'],
1599
+ 'general_contact_forms_test' => $ct_options['general_contact_forms_test'],
1600
+ 'remove_old_spam' => $ct_options['remove_old_spam'],
1601
+ 'autoPubRevelantMess' => $ct_options['autoPubRevelantMess'],
1602
+ 'spam_store_days' => $ct_options['spam_store_days'],
1603
+ 'ssl_on' => $ct_options['ssl_on'],
1604
+ );
1605
+
1606
+ return $sender_info = array(
1607
+ 'page_url' => htmlspecialchars(@$_SERVER['SERVER_NAME'].@$_SERVER['REQUEST_URI']),
1608
+ 'cms_lang' => substr(get_locale(), 0, 2),
1609
+ 'REFFERRER' => htmlspecialchars(@$_SERVER['HTTP_REFERER']),
1610
+ 'USER_AGENT' => htmlspecialchars(@$_SERVER['HTTP_USER_AGENT']),
1611
+ 'php_session' => $php_session,
1612
+ 'cookies_enabled' => ct_cookies_test(true),
1613
+ 'direct_post' => $ct_direct_post,
1614
+ 'checkjs_data_post' => $checkjs_data_post,
1615
+ 'checkjs_data_cookies' => $checkjs_data_cookies,
1616
+ 'ct_options' => json_encode($options2server),
1617
+ );
1618
+ }
1619
+
1620
+ /**
1621
+ * Sends error notice to admin
1622
+ * @return null
1623
+ */
1624
+ function ct_send_error_notice ($comment = '') {
1625
+ global $ct_plugin_name, $ct_admin_notoice_period;
1626
+
1627
+ $timelabel_reg = intval( get_option('cleantalk_timelabel_reg') );
1628
+ if(time() - $ct_admin_notoice_period > $timelabel_reg){
1629
+ update_option('cleantalk_timelabel_reg', time());
1630
+
1631
+ $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1632
+ $message = __('Attention, please!', 'cleantalk') . "\r\n\r\n";
1633
+ $message .= sprintf(__('"%s" plugin error on your site %s:', 'cleantalk'), $ct_plugin_name, $blogname) . "\r\n\r\n";
1634
+ $message .= $comment . "\r\n\r\n";
1635
+ @wp_mail(get_option('admin_email'), sprintf(__('[%s] %s error!', 'cleantalk'), $ct_plugin_name, $blogname), $message);
1636
+ }
1637
+
1638
+ return null;
1639
+ }
1640
+
1641
+ ?>
cleantalk.class.php CHANGED
@@ -2,11 +2,11 @@
2
  /**
3
  * Cleantalk base class
4
  *
5
- * @version 1.34
6
  * @package Cleantalk
7
  * @subpackage Base
8
- * @author Сleantalk team (welcome@cleantalk.org)
9
- * @copyright (C) 2014 СleanTalk team (http://cleantalk.org)
10
  * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
11
  * @see https://github.com/CleanTalk/php-antispam
12
  *
@@ -590,6 +590,8 @@ class Cleantalk {
590
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
591
  // resolve 'Expect: 100-continue' issue
592
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
 
 
593
 
594
  // Disabling CA cert verivication
595
  // Disabling common name verification
2
  /**
3
  * Cleantalk base class
4
  *
5
+ * @version 1.35
6
  * @package Cleantalk
7
  * @subpackage Base
8
+ * @author Cleantalk team (welcome@cleantalk.org)
9
+ * @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
10
  * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
11
  * @see https://github.com/CleanTalk/php-antispam
12
  *
590
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
591
  // resolve 'Expect: 100-continue' issue
592
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
593
+ // see http://stackoverflow.com/a/23322368
594
+ curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
595
 
596
  // Disabling CA cert verivication
597
  // Disabling common name verification
cleantalk.php CHANGED
@@ -3,1991 +3,87 @@
3
  Plugin Name: Anti-spam by CleanTalk
4
  Plugin URI: http://cleantalk.org
5
  Description: Max power, all-in-one, captcha less, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
- Version: 4.16
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: http://cleantalk.org
9
  */
10
 
11
- define('CLEANTALK_PLUGIN_DIR', plugin_dir_path(__FILE__));
 
12
 
13
- $ct_agent_version = 'wordpress-416';
14
- $ct_plugin_name = 'Anti-spam by CleanTalk';
15
- $ct_checkjs_frm = 'ct_checkjs_frm';
16
- $ct_checkjs_register_form = 'ct_checkjs_register_form';
17
- $ct_session_request_id_label = 'request_id';
18
- $ct_session_register_ok_label = 'register_ok';
19
 
20
- $ct_checkjs_cf7 = 'ct_checkjs_cf7';
21
- $ct_cf7_comment = '';
 
 
22
 
23
- $ct_checkjs_jpcf = 'ct_checkjs_jpcf';
24
- $ct_jpcf_patched = false;
25
- $ct_jpcf_fields = array('name', 'email');
26
 
27
- // Comment already proccessed
28
- $ct_comment_done = false;
29
-
30
- // Comment already proccessed
31
- $ct_signup_done = false;
32
-
33
- // Default value for JS test
34
- $ct_checkjs_def = 0;
35
-
36
- // COOKIE label to store request id for last approved
37
- $ct_approved_request_id_label = 'ct_approved_request_id';
38
-
39
- // Last request id approved for publication
40
- $ct_approved_request_id = null;
41
-
42
- // COOKIE label for trial notice flag
43
- $ct_notice_trial_label = 'ct_notice_trial';
44
-
45
- // Flag to show trial notice
46
- $show_ct_notice_trial = false;
47
-
48
- // COOKIE label for online notice flag
49
- $ct_notice_online_label = 'ct_notice_online';
50
-
51
- // Flag to show online notice - 'Y' or 'N'
52
- $show_ct_notice_online = '';
53
-
54
- // Timeout before new check for trial notice in hours
55
- $trial_notice_check_timeout = 1;
56
-
57
- // Timeout before new check account notice in hours
58
- $account_notice_check_timeout = 24;
59
-
60
- // Trial notice show time in minutes
61
- $trial_notice_showtime = 10;
62
-
63
- // COOKIE label for WP Landing Page proccessing result
64
- $ct_wplp_result_label = 'ct_wplp_result';
65
-
66
- // Flag indicates active JetPack comments
67
- $ct_jp_comments = false;
68
-
69
- // S2member PayPal post data label
70
- $ct_post_data_label = 's2member_pro_paypal_registration';
71
-
72
- // S2member Auth.Net post data label
73
- $ct_post_data_authnet_label = 's2member_pro_authnet_registration';
74
-
75
- // Form time load label
76
- $ct_formtime_label = 'ct_formtime';
77
-
78
- // Plugin's options
79
- $ct_options = null;
80
-
81
- // Account status check last time
82
- $ct_account_status_check = 0;
83
-
84
- // Post without page load
85
- $ct_direct_post = 0;
86
-
87
- // WP admin email notice interval in seconds
88
- $ct_admin_notoice_period = 10800;
89
-
90
- // Sevice negative comment to visitor.
91
- // It uses for BuddyPress registrations to avoid double checks
92
- $ct_negative_comment = null;
93
-
94
- // Init action.
95
- add_action('init', 'ct_init', 1);
96
-
97
- // After plugin loaded - to load locale as described in manual
98
- add_action( 'plugins_loaded', 'ct_plugin_loaded' );
99
-
100
- // Comments
101
- add_filter('preprocess_comment', 'ct_preprocess_comment', 1, 1); // param - comment data array
102
- add_filter('comment_text', 'ct_comment_text' );
103
-
104
- // Registrations
105
- add_action('register_form','ct_register_form');
106
- add_filter('registration_errors', 'ct_registration_errors', 1, 3);
107
- add_action('user_register', 'ct_user_register');
108
-
109
- // Multisite registrations
110
- add_action('signup_extra_fields','ct_register_form');
111
- add_filter('wpmu_validate_user_signup', 'ct_registration_errors_wpmu', 10, 3);
112
-
113
- // Login form - for notifications only
114
- add_filter('login_message', 'ct_login_message');
115
-
116
- register_activation_hook( __FILE__, 'ct_activation' );
117
-
118
- /**
119
- * On activation, set a time, frequency and name of an action hook to be scheduled.
120
- */
121
- function ct_activation() {
122
- wp_schedule_event(time(), 'hourly', 'ct_hourly_event_hook' );
123
- }
124
-
125
- // Hourly run hook
126
- add_action('ct_hourly_event_hook', 'ct_do_this_hourly');
127
-
128
- /**
129
- * On the scheduled action hook, run the function.
130
- */
131
- function ct_do_this_hourly() {
132
- global $ct_options;
133
- // do something every hour
134
-
135
- if (!isset($ct_options))
136
- $ct_options = ct_get_options();
137
-
138
- delete_spam_comments();
139
- ct_send_feedback();
140
- }
141
-
142
- if (is_admin()) {
143
  require_once(CLEANTALK_PLUGIN_DIR . 'cleantalk-admin.php');
144
-
145
- if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
146
- add_action('admin_init', 'ct_admin_init', 1);
147
- add_action('admin_menu', 'ct_admin_add_page');
148
- add_action('admin_notices', 'admin_notice_message');
149
- }
150
-
151
- add_action('admin_enqueue_scripts', 'ct_enqueue_scripts');
152
- add_action('comment_unapproved_to_approvecomment', 'ct_comment_approved'); // param - comment object
153
- add_action('comment_unapproved_to_approved', 'ct_comment_approved'); // param - comment object
154
- add_action('comment_approved_to_unapproved', 'ct_comment_unapproved'); // param - comment object
155
- add_action('comment_unapproved_to_spam', 'ct_comment_spam'); // param - comment object
156
- add_action('comment_approved_to_spam', 'ct_comment_spam'); // param - comment object
157
- add_filter('get_comment_text', 'ct_get_comment_text'); // param - current comment text
158
- add_filter('unspam_comment', 'ct_unspam_comment');
159
- add_action('delete_user', 'ct_delete_user');
160
- add_filter('plugin_row_meta', 'ct_register_plugin_links', 10, 2);
161
- add_filter('plugin_action_links', 'ct_plugin_action_links', 10, 2);
162
- add_action('updated_option', 'ct_update_option'); // param - option name, i.e. 'cleantalk_settings'
163
- }
164
-
165
- /**
166
- * Init functions
167
- * @return mixed[] Array of options
168
- */
169
- function ct_init() {
170
- global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_direct_post, $ct_options;
171
 
172
- $ct_options = ct_get_options();
173
-
174
- ct_init_session();
175
-
176
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
177
- if (!array_key_exists($ct_formtime_label, $_SESSION) && session_id() != '') {
178
- $ct_direct_post = 1;
179
- }
180
- } else {
181
- $_SESSION[$ct_formtime_label] = time();
182
- }
183
-
184
- // Fast Secure contact form
185
- if(defined('FSCF_VERSION')){
186
- add_filter('si_contact_display_after_fields', 'ct_si_contact_display_after_fields');
187
- add_filter('si_contact_form_validate', 'ct_si_contact_form_validate');
188
- }
189
-
190
- // WooCoomerse signups
191
- if(class_exists('WooCommerce')){
192
- add_filter('woocommerce_register_post', 'ct_register_post', 1, 3);
193
- }
194
-
195
- // JetPack Contact form
196
- $jetpack_active_modules = false;
197
- if(defined('JETPACK__VERSION')){
198
- add_filter('grunion_contact_form_field_html', 'ct_grunion_contact_form_field_html', 10, 2);
199
- add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
200
- $jetpack_active_modules = get_option('jetpack_active_modules');
201
- if (
202
- (class_exists( 'Jetpack', false) && $jetpack_active_modules && in_array('comments', $jetpack_active_modules))
203
- ) {
204
- $ct_jp_comments = true;
205
- }
206
- }
207
-
208
- // Contact Form7
209
- if(defined('WPCF7_VERSION')){
210
- add_filter('wpcf7_form_elements', 'ct_wpcf7_form_elements');
211
- if(WPCF7_VERSION >= '3.0.0'){
212
- add_filter('wpcf7_spam', 'ct_wpcf7_spam');
213
- }else{
214
- add_filter('wpcf7_acceptance', 'ct_wpcf7_spam');
215
  }
216
- }
217
-
218
- // Formidable
219
- if(class_exists('FrmSettings')){
220
- add_action('frm_validate_entry', 'ct_frm_validate_entry', 20, 2);
221
- add_action('frm_entries_footer_scripts', 'ct_frm_entries_footer_scripts', 20, 2);
222
- }
223
-
224
- // BuddyPress
225
- if(class_exists('BuddyPress')){
226
- add_action('bp_before_registration_submit_buttons','ct_register_form');
227
- add_filter('bp_signup_validate', 'ct_registration_errors');
228
- }
229
-
230
- // bbPress
231
- if(class_exists('bbPress')){
232
- add_filter('bbp_new_topic_pre_content', 'ct_bbp_new_pre_content', 1);
233
- add_filter('bbp_new_reply_pre_content', 'ct_bbp_new_pre_content', 1);
234
- add_action('bbp_theme_before_topic_form_content', 'ct_comment_form');
235
- add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
236
- }
237
-
238
- add_action('comment_form', 'ct_comment_form');
239
-
240
- # if (
241
- # ($ct_jp_comments === true)
242
- # || (defined('LANDINGPAGES_CURRENT_VERSION'))
243
- # || (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION'))
244
- # || (defined('WOOCOMMERCE_VERSION'))
245
- # || (defined('WPCF7_VERSION'))
246
- # ) {
247
- # add_action('wp_footer', 'ct_footer_add_cookie', 1);
248
- # }
249
-
250
- //intercept WordPress Landing Pages POST
251
- if (defined('LANDINGPAGES_CURRENT_VERSION') && !empty($_POST)){
252
- if(array_key_exists('action', $_POST) && $_POST['action'] === 'inbound_store_lead'){ // AJAX action(s)
253
- ct_check_wplp();
254
- }else if(array_key_exists('inbound_submitted', $_POST) && $_POST['inbound_submitted'] == '1'){ // Final submit
255
- ct_check_wplp();
256
- }
257
- }
258
-
259
- // intercept S2member POST
260
- if (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION') && (isset($_POST[$ct_post_data_label]['email']) || isset($_POST[$ct_post_data_authnet_label]['email']))){
261
- ct_s2member_registration_test();
262
- }
263
-
264
- //
265
- // New user approve hack
266
- // https://wordpress.org/plugins/new-user-approve/
267
- //
268
- if (ct_plugin_active('new-user-approve/new-user-approve.php')) {
269
- add_action('register_post', 'ct_register_post', 1, 3);
270
- }
271
-
272
- //
273
- // Load JS code to website footer
274
- //
275
- if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
276
- add_action('wp_footer', 'ct_footer_add_cookie', 1);
277
- }
278
- if (ct_is_user_enable()) {
279
- ct_cookies_test();
280
 
281
- if (isset($ct_options['general_contact_forms_test']) && $ct_options['general_contact_forms_test'] == 1) {
282
- ct_contact_form_validate();
283
- }
284
- }
285
- }
286
-
287
- /**
288
- * Public action 'plugins_loaded' - Loads locale, see http://codex.wordpress.org/Function_Reference/load_plugin_textdomain
289
- */
290
- function ct_plugin_loaded() {
291
- load_plugin_textdomain('cleantalk', false, basename(dirname(__FILE__)) . '/i18n');
292
- }
293
-
294
- /**
295
- * Inner function - Current Cleantalk options
296
- * @return mixed[] Array of options
297
- */
298
- function ct_get_options() {
299
- $options = get_option('cleantalk_settings');
300
- if (!is_array($options)){
301
- $options = array();
302
  }else{
303
- if(array_key_exists('apikey', $options))
304
- $options['apikey'] = trim($options['apikey']);
305
- }
306
- return array_merge(ct_def_options(), (array) $options);
307
- }
308
-
309
- /**
310
- * Inner function - Default Cleantalk options
311
- * @return mixed[] Array of default options
312
- */
313
- function ct_def_options() {
314
- return array(
315
- 'server' => 'http://moderate.cleantalk.org',
316
- 'apikey' => __('enter key', 'cleantalk'),
317
- 'autoPubRevelantMess' => '0',
318
- 'registrations_test' => '1',
319
- 'comments_test' => '1',
320
- 'contact_forms_test' => '1',
321
- 'general_contact_forms_test' => '1', // Antispam test for unsupported and untested contact forms
322
- 'remove_old_spam' => '0',
323
- 'spam_store_days' => '15', // Days before delete comments from folder Spam
324
- 'ssl_on' => 0, // Secure connection to servers
325
- 'next_account_status_check' => 0, // Time label when the plugin should check account status
326
- 'user_token' => '', // User token
327
- 'relevance_test' => 0, // Test comment for relevance
328
- 'notice_api_errors' => 0, // Send API error notices to WP admin
329
- 'js_keys' => array(), // Keys to do JavaScript antispam test
330
- 'js_keys_store_days' => 1, // JavaScript keys store days
331
- 'js_key_lifetime' => 3600, // JavaScript key life time in seconds
332
- );
333
- }
334
-
335
- /**
336
- * Inner function - Stores ang returns cleantalk hash of current comment
337
- * @param string New hash or NULL
338
- * @return string New hash or current hash depending on parameter
339
- */
340
- function ct_hash($new_hash = '') {
341
- /**
342
- * Current hash
343
- */
344
- static $hash;
345
-
346
- if (!empty($new_hash)) {
347
- $hash = $new_hash;
348
- }
349
- return $hash;
350
- }
351
-
352
- /**
353
- * Inner function - Write manual moderation results to PHP sessions
354
- * @param string $hash Cleantalk comment hash
355
- * @param string $message comment_content
356
- * @param int $allow flag good comment (1) or bad (0)
357
- * @return string comment_content w\o cleantalk resume
358
- */
359
- function ct_feedback($hash, $message = null, $allow) {
360
- global $ct_options;
361
-
362
- require_once('cleantalk.class.php');
363
-
364
- $config = get_option('cleantalk_server');
365
-
366
- $ct = new Cleantalk();
367
- $ct->work_url = $config['ct_work_url'];
368
- $ct->server_url = $ct_options['server'];
369
- $ct->server_ttl = $config['ct_server_ttl'];
370
- $ct->server_changed = $config['ct_server_changed'];
371
-
372
- if (empty($hash)) {
373
- $hash = $ct->getCleantalkCommentHash($message);
374
- }
375
-
376
- $resultMessage = null;
377
- if ($message !== null) {
378
- $resultMessage = $ct->delCleantalkComment($message);
379
- }
380
-
381
- $ct_feedback = $hash . ':' . $allow . ';';
382
- if (empty($_SESSION['feedback_request'])) {
383
- $_SESSION['feedback_request'] = $ct_feedback;
384
- } else {
385
- $_SESSION['feedback_request'] .= $ct_feedback;
386
- }
387
-
388
- return $resultMessage;
389
- }
390
-
391
- /**
392
- * Inner function - Sends the results of moderation
393
- * @param string $feedback_request
394
- * @return bool
395
- */
396
- function ct_send_feedback($feedback_request = null) {
397
- global $ct_options;
398
-
399
- if (empty($feedback_request) && isset($_SESSION['feedback_request']) && preg_match("/^[a-z0-9\;\:]+$/", $_SESSION['feedback_request'])) {
400
- $feedback_request = $_SESSION['feedback_request'];
401
- unset($_SESSION['feedback_request']);
402
- }
403
-
404
- if ($feedback_request !== null) {
405
- require_once('cleantalk.class.php');
406
- $config = get_option('cleantalk_server');
407
-
408
- $ct = new Cleantalk();
409
- $ct->work_url = $config['ct_work_url'];
410
- $ct->server_url = $ct_options['server'];
411
- $ct->server_ttl = $config['ct_server_ttl'];
412
- $ct->server_changed = $config['ct_server_changed'];
413
-
414
- $ct_request = new CleantalkRequest();
415
- $ct_request->auth_key = $ct_options['apikey'];
416
- $ct_request->feedback = $feedback_request;
417
-
418
- $ct->sendFeedback($ct_request);
419
-
420
- if ($ct->server_change) {
421
- update_option(
422
- 'cleantalk_server', array(
423
- 'ct_work_url' => $ct->work_url,
424
- 'ct_server_ttl' => $ct->server_ttl,
425
- 'ct_server_changed' => time()
426
- )
427
- );
428
- }
429
- return true;
430
- }
431
-
432
- return false;
433
- }
434
-
435
- /**
436
- * Session init
437
- * @return null;
438
- */
439
- function ct_init_session() {
440
- if(session_id() === '') {
441
- @session_start();
442
- }
443
-
444
- return null;
445
- }
446
-
447
- /**
448
- * Cookies test for sender
449
- * @return null|0|1;
450
- */
451
- function ct_cookies_test ($test = false) {
452
- $cookie_label = 'ct_cookies_test';
453
- $secret_hash = ct_get_checkjs_value();
454
-
455
- $result = null;
456
- if (isset($_COOKIE[$cookie_label])) {
457
- if ($_COOKIE[$cookie_label] == $secret_hash) {
458
- $result = 1;
459
- } else {
460
- $result = 0;
461
- }
462
- } else {
463
- @setcookie($cookie_label, $secret_hash, 0, '/');
464
-
465
- if ($test) {
466
- $result = 0;
467
- }
468
- }
469
-
470
- return $result;
471
- }
472
-
473
- /**
474
- * Inner function - Common part of request sending
475
- * @param array Array of parameters:
476
- * 'message' - string
477
- * 'example' - string
478
- * 'checkjs' - int
479
- * 'sender_email' - string
480
- * 'sender_nickname' - string
481
- * 'sender_info' - array
482
- * 'post_info' - string
483
- * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
484
- */
485
- function ct_base_call($params = array()) {
486
- global $wpdb, $ct_agent_version, $ct_formtime_label, $ct_options;
487
-
488
- require_once('cleantalk.class.php');
489
-
490
- $submit_time = submit_time_test();
491
-
492
- $sender_info = get_sender_info();
493
- if (array_key_exists('sender_info', $params)) {
494
- $sender_info = array_merge($sender_info, (array) $params['sender_info']);
495
- }
496
- $sender_info = json_encode($sender_info);
497
- if ($sender_info === false)
498
- $sender_info = '';
499
-
500
- $config = get_option('cleantalk_server');
501
-
502
- $ct = new Cleantalk();
503
- $ct->work_url = $config['ct_work_url'];
504
- $ct->server_url = $ct_options['server'];
505
- $ct->server_ttl = $config['ct_server_ttl'];
506
- $ct->server_changed = $config['ct_server_changed'];
507
- $ct->ssl_on = $ct_options['ssl_on'];
508
-
509
- $ct_request = new CleantalkRequest();
510
-
511
- $ct_request->auth_key = $ct_options['apikey'];
512
- $ct_request->message = $params['message'];
513
- $ct_request->example = $params['example'];
514
- $ct_request->sender_email = $params['sender_email'];
515
- $ct_request->sender_nickname = $params['sender_nickname'];
516
- $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
517
- $ct_request->agent = $ct_agent_version;
518
- $ct_request->sender_info = $sender_info;
519
- $ct_request->js_on = $params['checkjs'];
520
- $ct_request->submit_time = $submit_time;
521
- $ct_request->post_info = $params['post_info'];
522
-
523
- $ct_result = $ct->isAllowMessage($ct_request);
524
- if ($ct->server_change) {
525
- update_option(
526
- 'cleantalk_server', array(
527
- 'ct_work_url' => $ct->work_url,
528
- 'ct_server_ttl' => $ct->server_ttl,
529
- 'ct_server_changed' => time()
530
- )
531
- );
532
- }
533
-
534
- // Restart submit form counter for failed requests
535
- if ($ct_result->allow == 0) {
536
- $_SESSION[$ct_formtime_label] = time();
537
- }
538
-
539
- return array('ct' => $ct, 'ct_result' => $ct_result);
540
- }
541
-
542
- /**
543
- * Adds hidden filed to comment form
544
- */
545
- function ct_comment_form($post_id) {
546
- global $ct_options;
547
-
548
- if (ct_is_user_enable() === false) {
549
- return false;
550
- }
551
-
552
- if ($ct_options['comments_test'] == 0) {
553
- return false;
554
- }
555
-
556
- ct_add_hidden_fields(true, 'ct_checkjs', false, false);
557
-
558
- return null;
559
- }
560
-
561
- /**
562
- * Adds cookie script filed to footer
563
- */
564
- function ct_footer_add_cookie() {
565
- if (ct_is_user_enable() === false) {
566
- # return false;
567
- }
568
-
569
- ct_add_hidden_fields(true, 'ct_checkjs', false, true);
570
-
571
- return null;
572
- }
573
-
574
- /**
575
- * Adds hidden filed to define avaialbility of client's JavaScript
576
- * @param bool $random_key switch on generation random key for every page load
577
- */
578
- function ct_add_hidden_fields($random_key = false, $field_name = 'ct_checkjs', $return_string = false, $cookie_check = false) {
579
- global $ct_checkjs_def, $ct_plugin_name;
580
-
581
- $ct_checkjs_key = ct_get_checkjs_value($random_key);
582
- $field_id_hash = md5(rand(0, 1000));
583
-
584
- if ($cookie_check) {
585
- $html = '
586
- <script type="text/javascript">
587
- function ctSetCookie(c_name, value, def_value) {
588
- document.cookie = c_name + "=" + escape(value.replace(/^def_value$/, value)) + "; path=/";
589
- }
590
- ctSetCookie("%s", "%s", "%s");
591
- </script>
592
- ';
593
- $html = sprintf($html, $field_name, $ct_checkjs_key, $ct_checkjs_def);
594
- } else {
595
- $ct_input_challenge = sprintf("'%s'", $ct_checkjs_key);
596
-
597
- $field_id = $field_name . '_' . $field_id_hash;
598
- $html = '
599
- <input type="hidden" id="%s" name="%s" value="%s" />
600
- <script type="text/javascript">
601
- setTimeout(function(){var ct_input_name = \'%s\';var ct_input_value = document.getElementById(ct_input_name).value;document.getElementById(ct_input_name).value = document.getElementById(ct_input_name).value.replace(ct_input_value, %s); }, 1000);
602
- </script>
603
- ';
604
- $html = sprintf($html, $field_id, $field_name, $ct_checkjs_def, $field_id, $ct_input_challenge);
605
- };
606
-
607
- // Simplify JS code
608
- // and fixing issue with wpautop()
609
- $html = str_replace(array("\n","\r"),'', $html);
610
-
611
- if ($return_string === true) {
612
- return $html;
613
- } else {
614
- echo $html;
615
- }
616
- }
617
-
618
- /**
619
- * Is enable for user group
620
- * @return boolean
621
- */
622
- function ct_is_user_enable() {
623
- global $current_user;
624
-
625
- if (!isset($current_user->roles)) {
626
- return true;
627
- }
628
-
629
- $disable_roles = array('administrator', 'editor', 'author');
630
- foreach ($current_user->roles as $k => $v) {
631
- if (in_array($v, $disable_roles))
632
- return false;
633
- }
634
-
635
- return true;
636
- }
637
-
638
- /**
639
- * Public function - Insert JS code for spam tests
640
- * return null;
641
- */
642
- function ct_frm_entries_footer_scripts($fields, $form) {
643
- global $current_user, $ct_checkjs_frm, $ct_options;
644
-
645
- if ($ct_options['contact_forms_test'] == 0) {
646
- return false;
647
- }
648
-
649
- $ct_checkjs_key = ct_get_checkjs_value();
650
- $ct_frm_name = 'form_' . $form->form_key;
651
-
652
- ?>
653
-
654
- var input = document.createElement("input");
655
- input.setAttribute("type", "hidden");
656
- input.setAttribute("name", "<?php echo $ct_checkjs_frm; ?>");
657
- input.setAttribute("value", "<?php echo $ct_checkjs_key; ?>");
658
- document.getElementById("<?php echo $ct_frm_name; ?>").appendChild(input);
659
-
660
- <?php
661
- }
662
-
663
- /**
664
- * Public function - Test Formidable data for spam activity
665
- * return @array with errors if spam has found
666
- */
667
- function ct_frm_validate_entry ($errors, $values) {
668
- global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_frm, $ct_options;
669
 
670
- if ($ct_options['contact_forms_test'] == 0) {
671
- return false;
672
- }
673
 
674
- $checkjs = js_test($ct_checkjs_frm, $_POST);
 
675
 
676
- $post_info['comment_type'] = 'feedback';
677
- $post_info = json_encode($post_info);
678
- if ($post_info === false)
679
- $post_info = '';
680
 
681
- $sender_email = null;
682
- $message = '';
683
- foreach ($values['item_meta'] as $v) {
684
- if (isset($v) && is_string($v) && preg_match("/^\S+@\S+\.\S+$/", $v)) {
685
- $sender_email = $v;
686
- continue;
687
- }
688
- $message .= ' ' . $v;
689
- }
690
 
691
- $ct_base_call_result = ct_base_call(array(
692
- 'message' => $message,
693
- 'example' => null,
694
- 'sender_email' => $sender_email,
695
- 'sender_nickname' => null,
696
- 'post_info' => $post_info,
697
- 'checkjs' => $checkjs
698
- ));
699
- $ct = $ct_base_call_result['ct'];
700
- $ct_result = $ct_base_call_result['ct_result'];
701
 
702
- if ($ct_result->spam == 1) {
703
- $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
704
  }
705
-
706
- return $errors;
707
  }
708
 
709
  /**
710
- * Public filter 'bbp_*' - Checks topics, replies by cleantalk
711
- * @param mixed[] $comment Comment string
712
- * @return mixed[] $comment Comment string
713
  */
714
- function ct_bbp_new_pre_content ($comment) {
715
- global $ct_options;
716
-
717
- if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || is_user_logged_in()) {
718
- return $comment;
719
- }
720
-
721
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
722
- if ($checkjs === null) {
723
- $checkjs = js_test('ct_checkjs', $_POST, true);
724
- }
725
-
726
- $example = null;
727
-
728
- $sender_info = array(
729
- 'sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null
730
- );
731
-
732
- $post_info['comment_type'] = 'bbpress_comment';
733
- $post_info['post_url'] = bbp_get_topic_permalink();
734
-
735
- $post_info = json_encode($post_info);
736
- if ($post_info === false) {
737
- $post_info = '';
738
- }
739
-
740
- $ct_base_call_result = ct_base_call(array(
741
- 'message' => $comment,
742
- 'example' => $example,
743
- 'sender_email' => isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null,
744
- 'sender_nickname' => isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null,
745
- 'post_info' => $post_info,
746
- 'checkjs' => $checkjs,
747
- 'sender_info' => $sender_info
748
- ));
749
- $ct = $ct_base_call_result['ct'];
750
- $ct_result = $ct_base_call_result['ct_result'];
751
-
752
- if ($ct_result->stop_queue == 1 || $ct_result->spam == 1 || ($ct_result->allow == 0 && $ct_result->stop_words !== null)) {
753
- bbp_add_error('bbp_reply_content', $ct_result->comment);
754
  }
755
-
756
- return $comment;
757
  }
758
-
759
  /**
760
- * Public filter 'preprocess_comment' - Checks comment by cleantalk server
761
- * @param mixed[] $comment Comment data array
762
- * @return mixed[] New data array of comment
763
  */
764
- function ct_preprocess_comment($comment) {
765
- // this action is called just when WP process POST request (adds new comment)
766
- // this action is called by wp-comments-post.php
767
- // after processing WP makes redirect to post page with comment's form by GET request (see above)
768
- global $wpdb, $current_user, $comment_post_id, $ct_agent_version, $ct_comment_done, $ct_approved_request_id_label, $ct_jp_comments, $ct_options;
769
-
770
- if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || $ct_comment_done) {
771
- return $comment;
772
- }
773
-
774
- $local_blacklists = wp_blacklist_check(
775
- $comment['comment_author'],
776
- $comment['comment_author_email'],
777
- $comment['comment_author_url'],
778
- $comment['comment_content'],
779
- @$_SERVER['REMOTE_ADDR'],
780
- @$_SERVER['HTTP_USER_AGENT']
781
- );
782
-
783
- // Go out if author in local blacklists
784
- if ($local_blacklists === true) {
785
- return $comment;
786
- }
787
-
788
- // Skip pingback anti-spam test
789
- if ($comment['comment_type'] == 'pingback') {
790
- return $comment;
791
- }
792
-
793
- $ct_comment_done = true;
794
-
795
- $comment_post_id = $comment['comment_post_ID'];
796
-
797
- $sender_info = array(
798
- 'sender_url' => @$comment['comment_author_url']
799
- );
800
-
801
- //
802
- // JetPack comments logic
803
- //
804
- if ($ct_jp_comments) {
805
- $post_info['comment_type'] = 'jetpack_comment';
806
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
807
- } else {
808
- $post_info['comment_type'] = $comment['comment_type'];
809
- $checkjs = js_test('ct_checkjs', $_POST, true);
810
- }
811
-
812
- $post_info['post_url'] = ct_post_url(null, $comment_post_id);
813
- $post_info = json_encode($post_info);
814
- if ($post_info === false) {
815
- $post_info = '';
816
- }
817
-
818
- $example = null;
819
- if ($ct_options['relevance_test']) {
820
- $post = get_post($comment_post_id);
821
- if ($post !== null){
822
- $example['title'] = $post->post_title;
823
- $example['body'] = $post->post_content;
824
- $example['comments'] = null;
825
-
826
- $last_comments = get_comments(array('status' => 'approve', 'number' => 10, 'post_id' => $comment_post_id));
827
- foreach ($last_comments as $post_comment){
828
- $example['comments'] .= "\n\n" . $post_comment->comment_content;
829
- }
830
-
831
- $example = json_encode($example);
832
- }
833
-
834
- // Use plain string format if've failed with JSON
835
- if ($example === false || $example === null){
836
- $example = ($post->post_title !== null) ? $post->post_title : '';
837
- $example .= ($post->post_content !== null) ? "\n\n" . $post->post_content : '';
838
- }
839
- }
840
-
841
- $ct_base_call_result = ct_base_call(array(
842
- 'message' => $comment['comment_content'],
843
- 'example' => $example,
844
- 'sender_email' => $comment['comment_author_email'],
845
- 'sender_nickname' => $comment['comment_author'],
846
- 'post_info' => $post_info,
847
- 'checkjs' => $checkjs,
848
- 'sender_info' => $sender_info
849
- ));
850
- $ct = $ct_base_call_result['ct'];
851
- $ct_result = $ct_base_call_result['ct_result'];
852
-
853
- if ($ct_result->stop_queue == 1) {
854
- $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_result->comment;
855
- $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
856
- wp_die($err_text, 'Blacklisted', array('back_link' => true));
857
-
858
- return $comment;
859
- }
860
-
861
- ct_hash($ct_result->id);
862
- if ($ct_result->spam == 1) {
863
- add_filter('pre_comment_approved', 'ct_set_comment_spam');
864
-
865
- global $ct_comment;
866
- $ct_comment = $ct_result->comment;
867
- add_action('comment_post', 'ct_die', 12, 2);
868
- add_action('comment_post', 'ct_set_meta', 10, 2);
869
-
870
- return $comment;
871
- }
872
-
873
- if (isset($comment['comment_author_email'])) {
874
- $approved_comments = get_comments(array('status' => 'approve', 'count' => true, 'author_email' => $comment['comment_author_email']));
875
-
876
- // Change comment flow only for new authors
877
- if ((int) $approved_comments == 0 || $ct_result->stop_words !== null) {
878
-
879
- if ($ct_result->allow == 1 && get_option('comment_moderation') !== '1') {
880
- add_filter('pre_comment_approved', 'ct_set_approved');
881
- setcookie($ct_approved_request_id_label, $ct_result->id, 0, '/');
882
- }
883
- if ($ct_result->allow == 0) {
884
- if (isset($ct_result->stop_words)) {
885
- global $ct_stop_words;
886
- $ct_stop_words = $ct_result->stop_words;
887
- add_action('comment_post', 'ct_mark_red', 11, 2);
888
- }
889
-
890
- add_filter('pre_comment_approved', 'ct_set_not_approved');
891
- }
892
-
893
- add_action('comment_post', 'ct_set_meta', 10, 2);
894
- }
895
  }
896
-
897
- return $comment;
898
- }
899
-
900
- /**
901
- * Set die page with Cleantalk comment.
902
- * @global type $ct_comment
903
- $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_comment;
904
- * @param type $comment_status
905
- */
906
- function ct_die($comment_id, $comment_status) {
907
- global $ct_comment;
908
- $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_comment;
909
- $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
910
- wp_die($err_text, 'Blacklisted', array('back_link' => true));
911
- }
912
-
913
- /**
914
- * Set die page with Cleantalk comment from parameter.
915
- * @param type $comment_body
916
- */
917
- function ct_die_extended($comment_body) {
918
- $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $comment_body;
919
- $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
920
- wp_die($err_text, 'Blacklisted', array('back_link' => true));
921
- }
922
-
923
- /**
924
- * Validates JavaScript anti-spam test
925
- *
926
- */
927
- function js_test($field_name = 'ct_checkjs', $data = null, $random_key = false) {
928
- global $ct_options;
929
-
930
- $checkjs = null;
931
- $js_post_value = null;
932
-
933
- if (!$data)
934
- return $checkjs;
935
-
936
- if (isset($data[$field_name])) {
937
- $js_post_value = $data[$field_name];
938
-
939
- //
940
- // Random key check
941
- //
942
- if ($random_key) {
943
-
944
- $keys = $ct_options['js_keys'];
945
- if (isset($keys[$js_post_value])) {
946
- $checkjs = 1;
947
- } else {
948
- $checkjs = 0;
949
- }
950
- } else {
951
- $ct_challenge = ct_get_checkjs_value();
952
-
953
- if(preg_match("/$ct_challenge/", $js_post_value)) {
954
- $checkjs = 1;
955
- } else {
956
- $checkjs = 0;
957
- }
958
- }
959
-
960
-
961
- }
962
-
963
- return $checkjs;
964
- }
965
-
966
- /**
967
- * Validate form submit time
968
- *
969
- */
970
- function submit_time_test() {
971
- global $ct_formtime_label;
972
-
973
- $submit_time = null;
974
- if (isset($_SESSION[$ct_formtime_label])) {
975
- $submit_time = time() - (int) $_SESSION[$ct_formtime_label];
976
- }
977
-
978
- return $submit_time;
979
- }
980
-
981
- /**
982
- * Get post url
983
- * @param int $comment_id
984
- * @param int $comment_post_id
985
- * @return string|bool
986
- */
987
- function ct_post_url($comment_id = null, $comment_post_id) {
988
-
989
- if (empty($comment_post_id))
990
- return null;
991
-
992
- if ($comment_id === null) {
993
- $last_comment = get_comments('number=1');
994
- $comment_id = isset($last_comment[0]->comment_ID) ? (int) $last_comment[0]->comment_ID + 1 : 1;
995
- }
996
- $permalink = get_permalink($comment_post_id);
997
-
998
- $post_url = null;
999
- if ($permalink !== null)
1000
- $post_url = $permalink . '#comment-' . $comment_id;
1001
-
1002
- return $post_url;
1003
- }
1004
-
1005
- /**
1006
- * Public filter 'pre_comment_approved' - Mark comment unapproved always
1007
- * @return int Zero
1008
- */
1009
- function ct_set_not_approved() {
1010
- return 0;
1011
- }
1012
-
1013
- /**
1014
- * @author Artem Leontiev
1015
- * Public filter 'pre_comment_approved' - Mark comment approved always
1016
- * @return int 1
1017
- */
1018
- function ct_set_approved() {
1019
- return 1;
1020
- }
1021
-
1022
- /**
1023
- * Public filter 'pre_comment_approved' - Mark comment unapproved always
1024
- * @return int Zero
1025
- */
1026
- function ct_set_comment_spam() {
1027
- return 'spam';
1028
- }
1029
-
1030
- /**
1031
- * Public action 'comment_post' - Store cleantalk hash in comment meta 'ct_hash'
1032
- * @param int $comment_id Comment ID
1033
- * @param mixed $comment_status Approval status ("spam", or 0/1), not used
1034
- */
1035
- function ct_set_meta($comment_id, $comment_status) {
1036
- global $comment_post_id;
1037
- $hash1 = ct_hash();
1038
- if (!empty($hash1)) {
1039
- update_comment_meta($comment_id, 'ct_hash', $hash1);
1040
- if (function_exists('base64_encode') && isset($comment_status) && $comment_status != 'spam') {
1041
- $post_url = ct_post_url($comment_id, $comment_post_id);
1042
- $post_url = base64_encode($post_url);
1043
- if ($post_url === false)
1044
- return false;
1045
- // 01 - URL to approved comment
1046
- $feedback_request = $hash1 . ':' . '01' . ':' . $post_url . ';';
1047
- ct_send_feedback($feedback_request);
1048
- }
1049
- }
1050
- return true;
1051
- }
1052
-
1053
- /**
1054
- * Mark bad words
1055
- * @global string $ct_stop_words
1056
- * @param int $comment_id
1057
- * @param int $comment_status Not use
1058
- */
1059
- function ct_mark_red($comment_id, $comment_status) {
1060
- global $ct_stop_words;
1061
-
1062
- $comment = get_comment($comment_id, 'ARRAY_A');
1063
- $message = $comment['comment_content'];
1064
- foreach (explode(':', $ct_stop_words) as $word) {
1065
- $message = preg_replace("/($word)/ui", '<font rel="cleantalk" color="#FF1000">' . "$1" . '</font>', $message);
1066
-
1067
- }
1068
- $comment['comment_content'] = $message;
1069
- kses_remove_filters();
1070
- wp_update_comment($comment);
1071
- }
1072
-
1073
- /**
1074
- * Unmark bad words
1075
- * @param string $message
1076
- * @return string Cleat comment
1077
- */
1078
- function ct_unmark_red($message) {
1079
- $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
1080
-
1081
- return $message;
1082
- }
1083
-
1084
- /**
1085
- * Tests plugin activation status
1086
- * @return bool
1087
- */
1088
- function ct_plugin_active($plugin_name){
1089
- foreach (get_option('active_plugins') as $k => $v) {
1090
- if ($plugin_name == $v)
1091
- return true;
1092
- }
1093
- return false;
1094
- }
1095
-
1096
- /**
1097
- * Get ct_get_checkjs_value
1098
- * @return string
1099
- */
1100
- function ct_get_checkjs_value($random_key = false) {
1101
- global $ct_options;
1102
-
1103
- if ($random_key) {
1104
- $keys = $ct_options['js_keys'];
1105
- $keys_checksum = md5(json_encode($keys));
1106
-
1107
- $key = null;
1108
- $latest_key_time = 0;
1109
- foreach ($keys as $k => $t) {
1110
-
1111
- // Removing key if it's to old
1112
- if (time() - $t > $ct_options['js_keys_store_days'] * 86400) {
1113
- unset($keys[$k]);
1114
- continue;
1115
- }
1116
-
1117
- if ($t > $latest_key_time) {
1118
- $latest_key_time = $t;
1119
- $key = $k;
1120
- }
1121
- }
1122
-
1123
- // Get new key if the latest key is too old
1124
- if (time() - $latest_key_time > $ct_options['js_key_lifetime']) {
1125
- $key = rand();
1126
- $keys[$key] = time();
1127
- }
1128
-
1129
- if (md5(json_encode($keys)) != $keys_checksum) {
1130
- $ct_options['js_keys'] = $keys;
1131
- update_option('cleantalk_settings', $ct_options);
1132
- }
1133
- } else {
1134
- $key = md5($ct_options['apikey'] . '+' . get_option('admin_email'));
1135
- }
1136
-
1137
- return $key;
1138
- }
1139
-
1140
-
1141
- /**
1142
- * Insert a hidden field to registration form
1143
- * @return null
1144
- */
1145
- function ct_register_form() {
1146
- global $ct_checkjs_register_form, $ct_options;
1147
-
1148
- if ($ct_options['registrations_test'] == 0) {
1149
- return false;
1150
- }
1151
-
1152
- ct_add_hidden_fields(true, $ct_checkjs_register_form, false);
1153
-
1154
- return null;
1155
- }
1156
-
1157
- /**
1158
- * Adds notification text to login form - to inform about approced registration
1159
- * @return null
1160
- */
1161
- function ct_login_message($message) {
1162
- global $errors, $ct_session_register_ok_label, $ct_options;
1163
-
1164
- if ($ct_options['registrations_test'] != 0) {
1165
- if( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) {
1166
- if (isset($_SESSION[$ct_session_register_ok_label])) {
1167
- unset($_SESSION[$ct_session_register_ok_label]);
1168
- if(is_wp_error($errors))
1169
- $errors->add('ct_message','<br />' . sprintf(__('Registration is approved by %s.', 'cleantalk'), '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk</b>'), 'message');
1170
- }
1171
- }
1172
- }
1173
- return $message;
1174
- }
1175
-
1176
- /**
1177
- * Test users registration for multisite enviroment
1178
- * @return array with errors
1179
- */
1180
- function ct_registration_errors_wpmu($errors) {
1181
- global $ct_signup_done;
1182
-
1183
- //
1184
- // Multisite actions
1185
- //
1186
- $sanitized_user_login = null;
1187
- if (isset($errors['user_name'])) {
1188
- $sanitized_user_login = $errors['user_name'];
1189
- $wpmu = true;
1190
- }
1191
- $user_email = null;
1192
- if (isset($errors['user_email'])) {
1193
- $user_email = $errors['user_email'];
1194
- $wpmu = true;
1195
- }
1196
-
1197
- if ($wpmu && isset($errors['errors']->errors) && count($errors['errors']->errors) > 0) {
1198
- return $errors;
1199
- }
1200
-
1201
- $errors['errors'] = ct_registration_errors($errors['errors'], $sanitized_user_login, $user_email);
1202
-
1203
- // Show CleanTalk errors in user_name field
1204
- if (isset($errors['errors']->errors['ct_error'])) {
1205
- $errors['errors']->errors['user_name'] = $errors['errors']->errors['ct_error'];
1206
- unset($errors['errors']->errors['ct_error']);
1207
- }
1208
-
1209
- return $errors;
1210
- }
1211
-
1212
- /**
1213
- * Shell for action register_post
1214
- * @return array with errors
1215
- */
1216
- function ct_register_post($sanitized_user_login = null, $user_email = null, $errors) {
1217
- return ct_registration_errors($errors, $sanitized_user_login, $user_email);
1218
- }
1219
-
1220
- /**
1221
- * Test users registration
1222
- * @return array with errors
1223
- */
1224
- function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
1225
- global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options;
1226
-
1227
- // Go out if a registrered user action
1228
- if (ct_is_user_enable() === false) {
1229
- return $errors;
1230
- }
1231
-
1232
- if ($ct_options['registrations_test'] == 0) {
1233
- return $errors;
1234
- }
1235
-
1236
- //
1237
- // The function already executed
1238
- // It happens when used ct_register_post();
1239
- //
1240
- if ($ct_signup_done && is_object($errors) && count($errors->errors) > 0) {
1241
- return $errors;
1242
- }
1243
-
1244
- //
1245
- // BuddyPress actions
1246
- //
1247
- $buddypress = false;
1248
- if ($sanitized_user_login === null && isset($_POST['signup_username'])) {
1249
- $sanitized_user_login = $_POST['signup_username'];
1250
- $buddypress = true;
1251
- }
1252
- if ($user_email === null && isset($_POST['signup_email'])) {
1253
- $user_email = $_POST['signup_email'];
1254
- $buddypress = true;
1255
- }
1256
-
1257
- //
1258
- // Break tests because we already have servers response
1259
- //
1260
- if ($buddypress && $ct_signup_done) {
1261
- if ($ct_negative_comment) {
1262
- $bp->signup->errors['signup_username'] = $ct_negative_comment;
1263
- }
1264
- return $errors;
1265
- }
1266
-
1267
- $submit_time = submit_time_test();
1268
-
1269
- $sender_info = get_sender_info();
1270
-
1271
- $checkjs = js_test($ct_checkjs_register_form, $_POST, true);
1272
- $sender_info['post_checkjs_passed'] = $checkjs;
1273
-
1274
- //
1275
- // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1276
- //
1277
- if ($checkjs === null) {
1278
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1279
- $sender_info['cookie_checkjs_passed'] = $checkjs;
1280
- }
1281
-
1282
- $sender_info = json_encode($sender_info);
1283
- if ($sender_info === false) {
1284
- $sender_info= '';
1285
- }
1286
-
1287
- require_once('cleantalk.class.php');
1288
- $config = get_option('cleantalk_server');
1289
- $ct = new Cleantalk();
1290
- $ct->work_url = $config['ct_work_url'];
1291
- $ct->server_url = $ct_options['server'];
1292
-
1293
- $ct->server_ttl = $config['ct_server_ttl'];
1294
- $ct->server_changed = $config['ct_server_changed'];
1295
- $ct->ssl_on = $ct_options['ssl_on'];
1296
-
1297
- $ct_request = new CleantalkRequest();
1298
- $ct_request->auth_key = $ct_options['apikey'];
1299
- $ct_request->sender_email = $user_email;
1300
- $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
1301
- $ct_request->sender_nickname = $sanitized_user_login;
1302
- $ct_request->agent = $ct_agent_version;
1303
- $ct_request->sender_info = $sender_info;
1304
- $ct_request->js_on = $checkjs;
1305
- $ct_request->submit_time = $submit_time;
1306
-
1307
- $ct_result = $ct->isAllowUser($ct_request);
1308
- if ($ct->server_change) {
1309
- update_option(
1310
- 'cleantalk_server', array(
1311
- 'ct_work_url' => $ct->work_url,
1312
- 'ct_server_ttl' => $ct->server_ttl,
1313
- 'ct_server_changed' => time()
1314
- )
1315
- );
1316
- }
1317
-
1318
- $ct_signup_done = true;
1319
-
1320
- if ($ct_result->errno != 0 && $ct_options['notice_api_errors']) {
1321
- ct_send_error_notice($ct_result->comment);
1322
- return $errors;
1323
- }
1324
-
1325
- if ($ct_result->inactive != 0) {
1326
- ct_send_error_notice($ct_result->comment);
1327
- return $errors;
1328
- }
1329
-
1330
- if ($ct_result->allow == 0) {
1331
-
1332
- // Restart submit form counter for failed requests
1333
- $_SESSION[$ct_formtime_label] = time();
1334
-
1335
- if ($buddypress === true) {
1336
- $bp->signup->errors['signup_username'] = $ct_result->comment;
1337
- } else {
1338
- $errors->add('ct_error', $ct_result->comment);
1339
- $ct_negative_comment = $ct_result->comment;
1340
- }
1341
- } else {
1342
- if ($ct_result->id !== null) {
1343
- $_SESSION[$ct_session_request_id_label] = $ct_result->id;
1344
- $_SESSION[$ct_session_register_ok_label] = $ct_result->id;
1345
- }
1346
- }
1347
-
1348
- return $errors;
1349
- }
1350
-
1351
- /**
1352
- * Set user meta
1353
- * @return null
1354
- */
1355
- function ct_user_register($user_id) {
1356
- global $ct_session_request_id_label;
1357
-
1358
- if (isset($_SESSION[$ct_session_request_id_label])) {
1359
- update_user_meta($user_id, 'ct_hash', $_SESSION[$ct_session_request_id_label]);
1360
- unset($_SESSION[$ct_session_request_id_label]);
1361
- }
1362
- }
1363
-
1364
-
1365
- /**
1366
- * Test for JetPack contact form
1367
- */
1368
- function ct_grunion_contact_form_field_html($r, $field_label) {
1369
- global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $ct_options;
1370
-
1371
- if ($ct_options['contact_forms_test'] == 1 && $ct_jpcf_patched === false && preg_match("/[text|email]/i", $r)) {
1372
-
1373
- // Looking for element name prefix
1374
- $name_patched = false;
1375
- foreach ($ct_jpcf_fields as $v) {
1376
- if ($name_patched === false && preg_match("/(g\d-)$v/", $r, $matches)) {
1377
- $ct_checkjs_jpcf = $matches[1] . $ct_checkjs_jpcf;
1378
- $name_patched = true;
1379
- }
1380
- }
1381
-
1382
- $r .= ct_add_hidden_fields(true, $ct_checkjs_jpcf, true);
1383
- $ct_jpcf_patched = true;
1384
- }
1385
-
1386
- return $r;
1387
- }
1388
- /**
1389
- * Test for JetPack contact form
1390
- */
1391
- function ct_contact_form_is_spam($form) {
1392
- global $ct_checkjs_jpcf, $ct_options;
1393
-
1394
- if ($ct_options['contact_forms_test'] == 0) {
1395
- return null;
1396
- }
1397
-
1398
- $js_field_name = $ct_checkjs_jpcf;
1399
- foreach ($_POST as $k => $v) {
1400
- if (preg_match("/^.+$ct_checkjs_jpcf$/", $k))
1401
- $js_field_name = $k;
1402
- }
1403
-
1404
- $checkjs = js_test($js_field_name, $_POST, true);
1405
-
1406
- $sender_info = array(
1407
- 'sender_url' => @$form['comment_author_url']
1408
- );
1409
-
1410
- $post_info['comment_type'] = 'feedback';
1411
- $post_info = json_encode($post_info);
1412
- if ($post_info === false)
1413
- $post_info = '';
1414
-
1415
- $sender_email = null;
1416
- $sender_nickname = null;
1417
- $message = '';
1418
- if (isset($form['comment_author_email']))
1419
- $sender_email = $form['comment_author_email'];
1420
-
1421
- if (isset($form['comment_author']))
1422
- $sender_nickname = $form['comment_author'];
1423
-
1424
- if (isset($form['comment_content']))
1425
- $message = $form['comment_content'];
1426
-
1427
- $ct_base_call_result = ct_base_call(array(
1428
- 'message' => $message,
1429
- 'example' => null,
1430
- 'sender_email' => $sender_email,
1431
- 'sender_nickname' => $sender_nickname,
1432
- 'post_info' => $post_info,
1433
- 'sender_info' => $sender_info,
1434
- 'checkjs' => $checkjs
1435
- ));
1436
- $ct = $ct_base_call_result['ct'];
1437
- $ct_result = $ct_base_call_result['ct_result'];
1438
-
1439
- if ($ct_result->spam == 1) {
1440
- global $ct_comment;
1441
- $ct_comment = $ct_result->comment;
1442
- ct_die(null, null);
1443
- exit;
1444
- }
1445
-
1446
- return (bool) $ct_result->spam;
1447
- }
1448
-
1449
-
1450
- /**
1451
- * Inserts anti-spam hidden to CF7
1452
- */
1453
- function ct_wpcf7_form_elements($html) {
1454
- global $wpdb, $current_user, $ct_checkjs_cf7, $ct_options;
1455
-
1456
- if ($ct_options['contact_forms_test'] == 0) {
1457
- return $html;
1458
- }
1459
-
1460
- $html .= ct_add_hidden_fields(true, $ct_checkjs_cf7, true);
1461
-
1462
- return $html;
1463
- }
1464
-
1465
- /**
1466
- * Test CF7 message for spam
1467
- */
1468
- function ct_wpcf7_spam($param) {
1469
- global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_cf7, $ct_cf7_comment, $ct_options;
1470
-
1471
- if (WPCF7_VERSION >= '3.0.0') {
1472
- if($param === true)
1473
- return $param;
1474
- }else{
1475
- if($param == false)
1476
- return $param;
1477
- }
1478
-
1479
- if ($ct_options['contact_forms_test'] == 0) {
1480
- return $param;
1481
- }
1482
-
1483
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1484
- if($checkjs != 1){
1485
- $checkjs = js_test($ct_checkjs_cf7, $_POST, true);
1486
- }
1487
-
1488
- $post_info['comment_type'] = 'feedback';
1489
- $post_info = json_encode($post_info);
1490
- if ($post_info === false)
1491
- $post_info = '';
1492
-
1493
- $sender_email = null;
1494
- $sender_nickname = null;
1495
- $message = '';
1496
- $subject = '';
1497
- foreach ($_POST as $k => $v) {
1498
- if ($sender_email === null && preg_match("/^\S+@\S+\.\S+$/", $v)) {
1499
- $sender_email = $v;
1500
- }
1501
- if ($message === '' && preg_match("/(\-message|\w*message\w*|contact|comment)$/", $k)) {
1502
- $message = $v;
1503
- }
1504
- if ($sender_nickname === null && preg_match("/-name$/", $k)) {
1505
- $sender_nickname = $v;
1506
- }
1507
- if ($subject === '' && ct_get_data_from_submit($k, 'subject')) {
1508
- $subject = $v;
1509
- }
1510
-
1511
- }
1512
-
1513
- if ($subject != '') {
1514
- if ($message != '') {
1515
- $message = "\n\n" . $message;
1516
- }
1517
- $message = sprintf("%s%s", $subject, $message);
1518
- }
1519
-
1520
- $ct_base_call_result = ct_base_call(array(
1521
- 'message' => $message,
1522
- 'example' => null,
1523
- 'sender_email' => $sender_email,
1524
- 'sender_nickname' => $sender_nickname,
1525
- 'post_info' => $post_info,
1526
- 'checkjs' => $checkjs
1527
- ));
1528
- $ct = $ct_base_call_result['ct'];
1529
- $ct_result = $ct_base_call_result['ct_result'];
1530
-
1531
- if ($ct_result->spam == 1) {
1532
- if (WPCF7_VERSION >= '3.0.0') {
1533
- $param = true;
1534
- }else{
1535
- $param = false;
1536
- }
1537
- $ct_cf7_comment = $ct_result->comment;
1538
- add_filter('wpcf7_display_message', 'ct_wpcf7_display_message', 10, 2);
1539
-
1540
- }
1541
-
1542
- return $param;
1543
- }
1544
-
1545
- /**
1546
- * Changes CF7 status message
1547
- * @param string $hook URL of hooked page
1548
- */
1549
- function ct_wpcf7_display_message($message, $status = 'spam') {
1550
- global $ct_cf7_comment;
1551
-
1552
- if ($status == 'spam') {
1553
- $message = $ct_cf7_comment;
1554
- }
1555
-
1556
- return $message;
1557
- }
1558
-
1559
- /**
1560
- * Inserts anti-spam hidden to Fast Secure contact form
1561
- */
1562
- function ct_si_contact_display_after_fields($string = '', $style = '', $form_errors = array(), $form_id_num = 0) {
1563
- $string .= ct_add_hidden_fields(true, 'ct_checkjs', true);
1564
- return $string;
1565
- }
1566
-
1567
- /**
1568
- * Test for Fast Secure contact form
1569
- */
1570
- function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
1571
- global $ct_options;
1572
-
1573
- if (!empty($form_errors))
1574
- return $form_errors;
1575
-
1576
- if ($ct_options['contact_forms_test'] == 0)
1577
- return $form_errors;
1578
-
1579
- $checkjs = js_test('ct_checkjs', $_POST, true);
1580
-
1581
- $post_info['comment_type'] = 'feedback';
1582
- $post_info = json_encode($post_info);
1583
- if ($post_info === false)
1584
- $post_info = '';
1585
-
1586
- $sender_email = null;
1587
- $sender_nickname = null;
1588
- $subject = '';
1589
- $message = '';
1590
- if (isset($_POST['email']))
1591
- $sender_email = $_POST['email'];
1592
-
1593
- if (isset($_POST['full_name']))
1594
- $sender_nickname = $_POST['full_name'];
1595
-
1596
- if (isset($_POST['subject']))
1597
- $subject = $_POST['subject'];
1598
-
1599
- if (isset($_POST['message']))
1600
- $message = $_POST['message'];
1601
-
1602
- $ct_base_call_result = ct_base_call(array(
1603
- 'message' => $subject . "\n\n" . $message,
1604
- 'example' => null,
1605
- 'sender_email' => $sender_email,
1606
- 'sender_nickname' => $sender_nickname,
1607
- 'post_info' => $post_info,
1608
- 'sender_info' => $sender_info,
1609
- 'checkjs' => $checkjs
1610
- ));
1611
- $ct = $ct_base_call_result['ct'];
1612
- $ct_result = $ct_base_call_result['ct_result'];
1613
-
1614
- if ($ct_result->spam == 1) {
1615
- global $ct_comment;
1616
- $ct_comment = $ct_result->comment;
1617
- ct_die(null, null);
1618
- exit;
1619
- }
1620
-
1621
- return $form_errors;
1622
- }
1623
-
1624
- /**
1625
- * Notice for commentators which comment has automatically approved by plugin
1626
- * @param string $hook URL of hooked page
1627
- */
1628
- function ct_comment_text($comment_text) {
1629
- global $comment, $ct_approved_request_id_label;
1630
-
1631
- if (isset($_COOKIE[$ct_approved_request_id_label]) && isset($comment->comment_ID)) {
1632
- $ct_hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
1633
-
1634
- if ($ct_hash !== '' && $_COOKIE[$ct_approved_request_id_label] == $ct_hash) {
1635
- $comment_text .= '<br /><br /> <em class="comment-awaiting-moderation">' . __('Comment approved. Anti-spam by CleanTalk.', 'cleantalk') . '</em>';
1636
- }
1637
- }
1638
-
1639
- return $comment_text;
1640
- }
1641
-
1642
-
1643
- /**
1644
- * Checks WordPress Landing Pages raw $_POST values
1645
- */
1646
- function ct_check_wplp(){
1647
- global $ct_wplp_result_label, $ct_options;
1648
- if (!isset($_COOKIE[$ct_wplp_result_label])) {
1649
- // First AJAX submit of WPLP form
1650
- if ($ct_options['contact_forms_test'] == 0)
1651
- return;
1652
-
1653
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1654
-
1655
- $post_info['comment_type'] = 'feedback';
1656
- $post_info = json_encode($post_info);
1657
- if ($post_info === false)
1658
- $post_info = '';
1659
-
1660
- $sender_email = '';
1661
- foreach ($_POST as $v) {
1662
- if (preg_match("/^\S+@\S+\.\S+$/", $v)) {
1663
- $sender_email = $v;
1664
- break;
1665
- }
1666
- }
1667
-
1668
- $message = '';
1669
- if(array_key_exists('form_input_values', $_POST)){
1670
- $form_input_values = json_decode(stripslashes($_POST['form_input_values']), true);
1671
- if (is_array($form_input_values) && array_key_exists('null', $form_input_values))
1672
- $message = $form_input_values['null'];
1673
- } else if (array_key_exists('null', $_POST)) {
1674
- $message = $_POST['null'];
1675
- }
1676
-
1677
- $ct_base_call_result = ct_base_call(array(
1678
- 'message' => $message,
1679
- 'example' => null,
1680
- 'sender_email' => $sender_email,
1681
- 'sender_nickname' => null,
1682
- 'post_info' => $post_info,
1683
- 'checkjs' => $checkjs
1684
- ));
1685
- $ct = $ct_base_call_result['ct'];
1686
- $ct_result = $ct_base_call_result['ct_result'];
1687
-
1688
- if ($ct_result->spam == 1) {
1689
- $cleantalk_comment = $ct_result->comment;
1690
- } else {
1691
- $cleantalk_comment = 'OK';
1692
- }
1693
-
1694
- setcookie($ct_wplp_result_label, $cleantalk_comment, strtotime("+5 seconds"), '/');
1695
- } else {
1696
- // Next POST/AJAX submit(s) of same WPLP form
1697
- $cleantalk_comment = $_COOKIE[$ct_wplp_result_label];
1698
- }
1699
- if ($cleantalk_comment !== 'OK')
1700
- ct_die_extended($cleantalk_comment);
1701
- }
1702
-
1703
- /**
1704
- * Test S2member registration
1705
- * @return array with errors
1706
- */
1707
- function ct_s2member_registration_test() {
1708
- global $ct_agent_version, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_options;
1709
-
1710
- if ($ct_options['registrations_test'] == 0) {
1711
- return null;
1712
- }
1713
-
1714
- $submit_time = submit_time_test();
1715
-
1716
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1717
-
1718
- require_once('cleantalk.class.php');
1719
-
1720
- $sender_info = get_sender_info();
1721
- $sender_info = json_encode($sender_info);
1722
- if ($sender_info === false) {
1723
- $sender_info= '';
1724
- }
1725
-
1726
- $sender_email = null;
1727
- if (isset($_POST[$ct_post_data_label]['email']))
1728
- $sender_email = $_POST[$ct_post_data_label]['email'];
1729
-
1730
- if (isset($_POST[$ct_post_data_authnet_label]['email']))
1731
- $sender_email = $_POST[$ct_post_data_authnet_label]['email'];
1732
-
1733
- $sender_nickname = null;
1734
- if (isset($_POST[$ct_post_data_label]['username']))
1735
- $sender_nickname = $_POST[$ct_post_data_label]['username'];
1736
-
1737
- if (isset($_POST[$ct_post_data_authnet_label]['username']))
1738
- $sender_nickname = $_POST[$ct_post_data_authnet_label]['username'];
1739
-
1740
- $config = get_option('cleantalk_server');
1741
-
1742
- $ct = new Cleantalk();
1743
- $ct->work_url = $config['ct_work_url'];
1744
- $ct->server_url = $ct_options['server'];
1745
- $ct->server_ttl = $config['ct_server_ttl'];
1746
- $ct->server_changed = $config['ct_server_changed'];
1747
- $ct->ssl_on = $ct_options['ssl_on'];
1748
-
1749
- $ct_request = new CleantalkRequest();
1750
-
1751
- $ct_request->auth_key = $ct_options['apikey'];
1752
- $ct_request->sender_email = $sender_email;
1753
- $ct_request->sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']);
1754
- $ct_request->sender_nickname = $sender_nickname;
1755
- $ct_request->agent = $ct_agent_version;
1756
- $ct_request->sender_info = $sender_info;
1757
- $ct_request->js_on = $checkjs;
1758
- $ct_request->submit_time = $submit_time;
1759
-
1760
- $ct_result = $ct->isAllowUser($ct_request);
1761
- if ($ct->server_change) {
1762
- update_option(
1763
- 'cleantalk_server', array(
1764
- 'ct_work_url' => $ct->work_url,
1765
- 'ct_server_ttl' => $ct->server_ttl,
1766
- 'ct_server_changed' => time()
1767
- )
1768
- );
1769
- }
1770
-
1771
- if ($ct_result->errno != 0) {
1772
- return false;
1773
- }
1774
-
1775
- // Restart submit form counter for failed requests
1776
- if ($ct_result->allow == 0) {
1777
- $_SESSION[$ct_formtime_label] = time();
1778
- }
1779
-
1780
- if ($ct_result->allow == 0) {
1781
- ct_die_extended($ct_result->comment);
1782
- }
1783
-
1784
- return true;
1785
- }
1786
-
1787
- /**
1788
- * General test for any contact form
1789
- */
1790
- function ct_contact_form_validate () {
1791
- global $pagenow;
1792
-
1793
- if ($_SERVER['REQUEST_METHOD'] != 'POST' ||
1794
- (isset($_POST['log']) && isset($_POST['pwd']) && isset($pagenow) && $pagenow == 'wp-login.php') // WordPress log in form
1795
- ) {
1796
- return null;
1797
- }
1798
-
1799
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1800
-
1801
- $post_info['comment_type'] = 'feedback_general_contact_form';
1802
- $post_info = json_encode($post_info);
1803
- if ($post_info === false) {
1804
- $post_info = '';
1805
- }
1806
-
1807
- $sender_email = null;
1808
- $sender_nickname = null;
1809
- $subject = '';
1810
- $message = '';
1811
- $contact_form = true;
1812
-
1813
- $skip_params = array(
1814
- 'ipn_track_id', // PayPal IPN #
1815
- 'txn_type', // PayPal transaction type
1816
- );
1817
- if (is_array($_POST)) {
1818
- foreach ($_POST as $k => $v) {
1819
- if (in_array($k, $skip_params) || preg_match("/^ct_checkjs/", $k)) {
1820
- $contact_form = false;
1821
- break;
1822
- }
1823
-
1824
- if ($sender_email === null && isset($v)) {
1825
- if (is_string($v) && preg_match("/^\S+@\S+\.\S+$/", $v)) {
1826
- $sender_email = $v;
1827
- }
1828
-
1829
- // Looing email address in arrays
1830
- if (is_array($v)) {
1831
- foreach ($v as $v2) {
1832
- if ($sender_email) {
1833
- continue;
1834
- }
1835
-
1836
- if (is_string($v2) && preg_match("/^\S+@\S+\.\S+$/", $v2)) {
1837
- $sender_email = $v2;
1838
- }
1839
- }
1840
- }
1841
- }
1842
- if ($sender_nickname === null && ct_get_data_from_submit($k, 'name')) {
1843
- $sender_nickname = $v;
1844
- }
1845
- if ($message === '' && ct_get_data_from_submit($k, 'message')) {
1846
- $message = $v;
1847
- }
1848
- if ($subject === '' && ct_get_data_from_submit($k, 'subject')) {
1849
- $subject = $v;
1850
- }
1851
- }
1852
- }
1853
-
1854
- // Skip submission if no data found
1855
- if (!$sender_email || !$contact_form) {
1856
- return false;
1857
- }
1858
-
1859
- $ct_base_call_result = ct_base_call(array(
1860
- 'message' => $subject . "\n\n" . $message,
1861
- 'example' => null,
1862
- 'sender_email' => $sender_email,
1863
- 'sender_nickname' => $sender_nickname,
1864
- 'post_info' => $post_info,
1865
- 'sender_info' => $sender_info,
1866
- 'checkjs' => $checkjs
1867
- ));
1868
-
1869
- $ct = $ct_base_call_result['ct'];
1870
- $ct_result = $ct_base_call_result['ct_result'];
1871
-
1872
- if ($ct_result->allow == 0) {
1873
-
1874
- if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
1875
- global $ct_comment;
1876
- $ct_comment = $ct_result->comment;
1877
- ct_die(null, null);
1878
- } else {
1879
- echo $ct_result->comment;
1880
- }
1881
- exit;
1882
- }
1883
-
1884
- return null;
1885
- }
1886
-
1887
-
1888
- /**
1889
- * Inner function - Finds and returns pattern in string
1890
- * @return null|bool
1891
- */
1892
- function ct_get_data_from_submit($value = null, $field_name = null) {
1893
- if (!$value || !$field_name || !is_string($value)) {
1894
- return false;
1895
- }
1896
- if (preg_match("/[a-z0-9_\-]*" . $field_name. "[a-z0-9_\-]*$/", $value)) {
1897
- return true;
1898
- }
1899
- }
1900
-
1901
-
1902
- /**
1903
- * Inner function - Default data array for senders
1904
- * @return array
1905
- */
1906
- function get_sender_info() {
1907
- global $ct_direct_post, $ct_options;
1908
-
1909
- $php_session = session_id() != '' ? 1 : 0;
1910
-
1911
- // Raw data to validated JavaScript test in the cloud
1912
- $checkjs_data_cookies = null;
1913
- if (isset($_COOKIE['ct_checkjs'])) {
1914
- $checkjs_data_cookies = $_COOKIE['ct_checkjs'];
1915
- }
1916
-
1917
- $checkjs_data_post = null;
1918
- if (count($_POST) > 0) {
1919
- foreach ($_POST as $k => $v) {
1920
- if (preg_match("/^ct_check.+/", $k)) {
1921
- $checkjs_data_post = $v;
1922
- }
1923
- }
1924
- }
1925
-
1926
- $options2server = array( // Options for sending to server for support information
1927
- 'apikey' => $ct_options['apikey'],
1928
- 'registrations_test' => $ct_options['registrations_test'],
1929
- 'comments_test' => $ct_options['comments_test'],
1930
- 'contact_forms_test' => $ct_options['contact_forms_test'],
1931
- 'general_contact_forms_test' => $ct_options['general_contact_forms_test'],
1932
- 'remove_old_spam' => $ct_options['remove_old_spam'],
1933
- 'autoPubRevelantMess' => $ct_options['autoPubRevelantMess'],
1934
- 'spam_store_days' => $ct_options['spam_store_days'],
1935
- 'ssl_on' => $ct_options['ssl_on'],
1936
- );
1937
-
1938
- return $sender_info = array(
1939
- 'page_url' => htmlspecialchars(@$_SERVER['SERVER_NAME'].@$_SERVER['REQUEST_URI']),
1940
- 'cms_lang' => substr(get_locale(), 0, 2),
1941
- 'REFFERRER' => htmlspecialchars(@$_SERVER['HTTP_REFERER']),
1942
- 'USER_AGENT' => htmlspecialchars(@$_SERVER['HTTP_USER_AGENT']),
1943
- 'php_session' => $php_session,
1944
- 'cookies_enabled' => ct_cookies_test(true),
1945
- 'direct_post' => $ct_direct_post,
1946
- 'checkjs_data_post' => $checkjs_data_post,
1947
- 'checkjs_data_cookies' => $checkjs_data_cookies,
1948
- 'ct_options' => json_encode($options2server),
1949
- );
1950
- }
1951
-
1952
- /**
1953
- * Delete old spam comments
1954
- * @return null
1955
- */
1956
- function delete_spam_comments() {
1957
- global $pagenow, $ct_options;
1958
-
1959
- if ($ct_options['remove_old_spam'] == 1) {
1960
- $last_comments = get_comments(array('status' => 'spam', 'number' => 1000, 'order' => 'ASC'));
1961
- foreach ($last_comments as $c) {
1962
- if (time() - strtotime($c->comment_date_gmt) > 86400 * $ct_options['spam_store_days']) {
1963
- // Force deletion old spam comments
1964
- wp_delete_comment($c->comment_ID, true);
1965
- }
1966
- }
1967
- }
1968
-
1969
- return null;
1970
- }
1971
-
1972
- /**
1973
- * Sends error notice to admin
1974
- * @return null
1975
- */
1976
- function ct_send_error_notice ($comment = '') {
1977
- global $ct_plugin_name, $ct_admin_notoice_period;
1978
-
1979
- $timelabel_reg = intval( get_option('cleantalk_timelabel_reg') );
1980
- if(time() - $ct_admin_notoice_period > $timelabel_reg){
1981
- update_option('cleantalk_timelabel_reg', time());
1982
-
1983
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1984
- $message = __('Attention, please!', 'cleantalk') . "\r\n\r\n";
1985
- $message .= sprintf(__('"%s" plugin error on your site %s:', 'cleantalk'), $ct_plugin_name, $blogname) . "\r\n\r\n";
1986
- $message .= $comment . "\r\n\r\n";
1987
- @wp_mail(get_option('admin_email'), sprintf(__('[%s] %s error!', 'cleantalk'), $ct_plugin_name, $blogname), $message);
1988
- }
1989
-
1990
- return null;
1991
  }
1992
 
1993
  ?>
3
  Plugin Name: Anti-spam by CleanTalk
4
  Plugin URI: http://cleantalk.org
5
  Description: Max power, all-in-one, captcha less, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
+ Version: 4.17
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: http://cleantalk.org
9
  */
10
 
11
+ if(!defined('CLEANTALK_PLUGIN_DIR')){
12
+ define('CLEANTALK_PLUGIN_DIR', plugin_dir_path(__FILE__));
13
 
14
+ require_once(CLEANTALK_PLUGIN_DIR . 'cleantalk-common.php');
 
 
 
 
 
15
 
16
+ // Activation/deactivation functions must be in main plugin file.
17
+ // http://codex.wordpress.org/Function_Reference/register_activation_hook
18
+ register_activation_hook( __FILE__, 'ct_activation' );
19
+ register_deactivation_hook( __FILE__, 'ct_deactivation' );
20
 
21
+ // After plugin loaded - to load locale as described in manual
22
+ add_action( 'plugins_loaded', 'ct_plugin_loaded' );
 
23
 
24
+ if (is_admin()) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  require_once(CLEANTALK_PLUGIN_DIR . 'cleantalk-admin.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
28
+ add_action('admin_init', 'ct_admin_init', 1);
29
+ add_action('admin_menu', 'ct_admin_add_page');
30
+ add_action('admin_notices', 'admin_notice_message');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ add_action('admin_enqueue_scripts', 'ct_enqueue_scripts');
34
+ add_action('comment_unapproved_to_approvecomment', 'ct_comment_approved'); // param - comment object
35
+ add_action('comment_unapproved_to_approved', 'ct_comment_approved'); // param - comment object
36
+ add_action('comment_approved_to_unapproved', 'ct_comment_unapproved'); // param - comment object
37
+ add_action('comment_unapproved_to_spam', 'ct_comment_spam'); // param - comment object
38
+ add_action('comment_approved_to_spam', 'ct_comment_spam'); // param - comment object
39
+ add_filter('get_comment_text', 'ct_get_comment_text'); // param - current comment text
40
+ add_filter('unspam_comment', 'ct_unspam_comment');
41
+ add_action('delete_user', 'ct_delete_user');
42
+ add_filter('plugin_row_meta', 'ct_register_plugin_links', 10, 2);
43
+ add_filter('plugin_action_links', 'ct_plugin_action_links', 10, 2);
44
+ add_action('updated_option', 'ct_update_option'); // param - option name, i.e. 'cleantalk_settings'
 
 
 
 
 
 
 
 
 
45
  }else{
46
+ require_once(CLEANTALK_PLUGIN_DIR . 'cleantalk-public.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ // Init action.
49
+ add_action('init', 'ct_init', 1);
 
50
 
51
+ // Hourly run hook
52
+ add_action('ct_hourly_event_hook', 'ct_do_this_hourly');
53
 
54
+ // Comments
55
+ add_filter('preprocess_comment', 'ct_preprocess_comment', 1, 1); // param - comment data array
56
+ add_filter('comment_text', 'ct_comment_text' );
 
57
 
58
+ // Registrations
59
+ add_action('register_form','ct_register_form');
60
+ add_filter('registration_errors', 'ct_registration_errors', 1, 3);
61
+ add_action('user_register', 'ct_user_register');
 
 
 
 
 
62
 
63
+ // Multisite registrations
64
+ add_action('signup_extra_fields','ct_register_form');
65
+ add_filter('wpmu_validate_user_signup', 'ct_registration_errors_wpmu', 10, 3);
 
 
 
 
 
 
 
66
 
67
+ // Login form - for notifications only
68
+ add_filter('login_message', 'ct_login_message');
69
  }
 
 
70
  }
71
 
72
  /**
73
+ * On activation, set a time, frequency and name of an action hook to be scheduled.
 
 
74
  */
75
+ if (!function_exists ( 'ct_activation')) {
76
+ function ct_activation() {
77
+ wp_schedule_event(time(), 'hourly', 'ct_hourly_event_hook' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
 
 
79
  }
 
80
  /**
81
+ * On deactivation, clear schedule.
 
 
82
  */
83
+ if (!function_exists ( 'ct_deactivation')) {
84
+ function ct_deactivation() {
85
+ wp_clear_scheduled_hook( 'ct_hourly_event_hook' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  }
88
 
89
  ?>
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Anti-spam by CleanTalk (no CAPTCHA) ===
2
  Contributors: znaeff, shagimuratov
3
- Tags: Akismet, anti spam, antispam, bbpress spam, buddypress spam, capcha, captcha antispam, cf7 spam, comments spam, contact form spam, fast secure contact form spam, form, Formidable spam, jetpack spam, landing pages, math, registration spam, s2member, signup spam, spam, spammers, spammy, WooCommerce spam, wordpress spam, booking spam, order spam, subscriptions spam, comments, gravity spam, gravity forms spam
4
  Requires at least: 3.0
5
  Tested up to: 4.1
6
- Stable tag: 4.16
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -171,6 +171,10 @@ WordPress 3.0 at least. PHP 4, 5 with CURL or file_get_contents() function and e
171
  1. Setup Android/iOS app to have push notices when new legitiamte comments/registrations or contactcs appears on the website.
172
 
173
  == Changelog ==
 
 
 
 
174
  = 4.16 2015-02-05 =
175
  * New base class.
176
  * Fixed JetPack filters logics.
@@ -493,7 +497,10 @@ WordPress 3.0 at least. PHP 4, 5 with CURL or file_get_contents() function and e
493
  * First version
494
 
495
  == Upgrade Notice ==
496
- = 4.16 2015-06-05 =
 
 
 
497
  New base class, fixed JetPack filters logics, optimized Formidable, bbPress, BuddyPress filters.
498
 
499
  = 4.15 2015-01-29 =
1
  === Anti-spam by CleanTalk (no CAPTCHA) ===
2
  Contributors: znaeff, shagimuratov
3
+ Tags: akismet, anti spam, antispam, bbpress spam, buddypress spam, captcha antispam, cf7 spam, comments spam, contact form spam, fast secure contact form spam, form, Formidable spam, jetpack spam, landing pages, math, registration spam, s2member spam, signup spam, spam, spammers, spammy, WooCommerce spam, wordpress spam, booking spam, order spam, subscriptions spam, comments, gravity spam, gravity forms spam
4
  Requires at least: 3.0
5
  Tested up to: 4.1
6
+ Stable tag: 4.17
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
171
  1. Setup Android/iOS app to have push notices when new legitiamte comments/registrations or contactcs appears on the website.
172
 
173
  == Changelog ==
174
+ = 4.17 2015-02-12 =
175
+ * New base class.
176
+ * Divided code to 3 separate files - common, public and admin.
177
+
178
  = 4.16 2015-02-05 =
179
  * New base class.
180
  * Fixed JetPack filters logics.
497
  * First version
498
 
499
  == Upgrade Notice ==
500
+ = 4.17 2015-02-12 =
501
+ New base class, divided code to 3 separate files - common, public and admin.
502
+
503
+ = 4.16 2015-02-05 =
504
  New base class, fixed JetPack filters logics, optimized Formidable, bbPress, BuddyPress filters.
505
 
506
  = 4.15 2015-01-29 =