Spam protection, AntiSpam, FireWall by CleanTalk - Version 5.83

Version Description

December 19 2017 = * Improving: Stability and compatibility. * Improving: Spam protection. * Fix: Comments logic filtration. * Fix: Admin bar counter. * Minor errors fixes.

Download this release

Release Info

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

Code changes from version 5.82.1 to 5.83

cleantalk.php CHANGED
@@ -3,15 +3,18 @@
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: http://cleantalk.org
5
  Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms. Formerly Anti-Spam by CleanTalk.
6
- Version: 5.82.1
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: http://cleantalk.org
9
  */
10
 
11
- $cleantalk_plugin_version='5.82.1';
12
- $ct_agent_version = 'wordpress-5821';
13
  $cleantalk_executed = false;
14
 
 
 
 
15
  define('CLEANTALK_REMOTE_CALL_SLEEP', 10); // Minimum time between remote call
16
 
17
  if(!defined('CLEANTALK_PLUGIN_DIR')){
@@ -23,6 +26,7 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
23
  require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
24
  require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
25
  require_once( CLEANTALK_PLUGIN_DIR . 'lib/CleantalkCron.php');
 
26
 
27
  $ct_options=ct_get_options();
28
  $ct_data=ct_get_data();
@@ -374,7 +378,6 @@ function apbct_activation() {
374
  CleantalkCron::addTask('sfw_update', 'ct_sfw_update', 86400, time()+43200);// SFW update
375
  CleantalkCron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time()+1800); // SFW send logs
376
  CleantalkCron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time()+3500); // Get data for dashboard widget
377
- // CleantalkCron::addTask('send_daily_request', 'ct_send_daily_request', 86400); // Daily sends request to servers
378
  CleantalkCron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time()+3500); // Send connection report to welcome@cleantalk.org
379
 
380
  // Additional options
@@ -513,8 +516,7 @@ function cleantalk_get_brief_data(){
513
  $ct_options = ct_get_options();
514
  $ct_data = ct_get_data();
515
 
516
- require_once('inc/cleantalk.class.php');
517
- $result = getAntispamReportBreif($ct_options['apikey']);
518
 
519
  $ct_data['brief_data'] = $result;
520
  update_option('cleantalk_data', $ct_data);
@@ -528,25 +530,6 @@ function ct_wp_logout(){
528
  setcookie('ct_trial_banner_closed', '', time()-3600);
529
  }
530
 
531
- function ct_send_daily_request(){
532
-
533
- $message = "Hello!\nThis is the test request to check connectivity to CleanTalk Anti-Spam servers.\nThank you!";
534
-
535
- $ct_base_call_result = ct_base_call(
536
- array(
537
- 'message' => $message,
538
- 'example' => '',
539
- 'sender_email' => 'test@cleantalk.org',
540
- 'sender_nickname' => 'CleanTalk',
541
- 'checkjs' => 1,
542
- 'post_info' => ''
543
- )
544
- );
545
-
546
- return true;
547
-
548
- }
549
-
550
  /*
551
  * Set Cookies test for cookie test
552
  * Sets cookies with pararms timestamp && landing_timestamp && pervious_referer
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: http://cleantalk.org
5
  Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms. Formerly Anti-Spam by CleanTalk.
6
+ Version: 5.83
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: http://cleantalk.org
9
  */
10
 
11
+ $cleantalk_plugin_version='5.83';
12
+ $ct_agent_version = 'wordpress-583';
13
  $cleantalk_executed = false;
14
 
15
+ define('APBCT_VERSION', '5.83');
16
+ define('APBCT_AGENT', 'wordpress-583');
17
+
18
  define('CLEANTALK_REMOTE_CALL_SLEEP', 10); // Minimum time between remote call
19
 
20
  if(!defined('CLEANTALK_PLUGIN_DIR')){
26
  require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
27
  require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
28
  require_once( CLEANTALK_PLUGIN_DIR . 'lib/CleantalkCron.php');
29
+ require_once( CLEANTALK_PLUGIN_DIR . 'lib/CleantalkHelper.php');
30
 
31
  $ct_options=ct_get_options();
32
  $ct_data=ct_get_data();
378
  CleantalkCron::addTask('sfw_update', 'ct_sfw_update', 86400, time()+43200);// SFW update
379
  CleantalkCron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time()+1800); // SFW send logs
380
  CleantalkCron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time()+3500); // Get data for dashboard widget
 
381
  CleantalkCron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time()+3500); // Send connection report to welcome@cleantalk.org
382
 
383
  // Additional options
516
  $ct_options = ct_get_options();
517
  $ct_data = ct_get_data();
518
 
519
+ $result = CleantalkHelper::getAntispamReportBreif($ct_options['apikey']);
 
520
 
521
  $ct_data['brief_data'] = $result;
522
  update_option('cleantalk_data', $ct_data);
530
  setcookie('ct_trial_banner_closed', '', time()-3600);
531
  }
532
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
533
  /*
534
  * Set Cookies test for cookie test
535
  * Sets cookies with pararms timestamp && landing_timestamp && pervious_referer
inc/cleantalk-admin.php CHANGED
@@ -32,8 +32,8 @@ function ct_dashboard_statistics_widget_output( $post, $callback_args ) {
32
  global $ct_data, $ct_options, $current_user;
33
 
34
  if(empty($ct_data['brief_data']) || !empty($_POST['ct_brief_refresh'])){
35
- require_once('cleantalk.class.php');
36
- $brief_data = getAntispamReportBreif($ct_options['apikey']);
37
 
38
  $ct_data['brief_data'] = $brief_data;
39
  update_option('cleantalk_data', $ct_data);
@@ -337,11 +337,8 @@ function ct_account_status_check(){
337
  : false);
338
 
339
  if($api_key){
340
-
341
- if(!function_exists('noticePaidTill'))
342
- require_once('cleantalk.class.php');
343
 
344
- $result = noticePaidTill($api_key);
345
 
346
  if ($result){
347
 
@@ -468,10 +465,9 @@ function apbct_admin_init(){
468
  $platform = 'wordpress';
469
  $timezone = $_POST['ct_admin_timezone'];
470
 
471
- if(!function_exists('getAutoKey'))
472
- require_once('cleantalk.class.php');
473
 
474
- $result = getAutoKey(ct_get_admin_email(), $website, $platform, $timezone);
475
 
476
  if ($result)
477
  {
@@ -1981,36 +1977,25 @@ function ct_update_option($option_name) {
1981
  $ct_data['sfw_log']= array();
1982
  }
1983
  }
1984
-
1985
- $key_valid = true;
1986
- $app_server_error = false;
1987
- $ct_data['testing_failed']=0;
1988
 
1989
- $request=Array();
1990
- $request['method_name'] = 'notice_validate_key';
1991
- $request['auth_key'] = $api_key;
1992
- $request['path_to_cms'] = preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1);
1993
- $url='https://api.cleantalk.org';
1994
- if(!function_exists('sendRawRequest'))
1995
- {
1996
- require_once('cleantalk.class.php');
1997
- }
1998
- $result=sendRawRequest($url, $request);
1999
-
2000
- if ($result)
2001
- {
2002
- $result = json_decode($result, true);
2003
- if (isset($result['valid']) && $result['valid'] == 0) {
2004
  $key_valid = false;
 
2005
  $ct_data['testing_failed']=1;
2006
  }
2007
- }
2008
- if (!$result || !isset($result['valid']))
2009
- {
2010
  $app_server_error = true;
2011
  $ct_data['testing_failed']=1;
2012
  }
2013
-
2014
  if ($key_valid) {
2015
  // Removes cookie for server errors
2016
  if ($app_server_error) {
32
  global $ct_data, $ct_options, $current_user;
33
 
34
  if(empty($ct_data['brief_data']) || !empty($_POST['ct_brief_refresh'])){
35
+
36
+ $brief_data = CleantalkHelper::getAntispamReportBreif($ct_options['apikey']);
37
 
38
  $ct_data['brief_data'] = $brief_data;
39
  update_option('cleantalk_data', $ct_data);
337
  : false);
338
 
339
  if($api_key){
 
 
 
340
 
341
+ $result = CleantalkHelper::noticePaidTill($api_key);
342
 
343
  if ($result){
344
 
465
  $platform = 'wordpress';
466
  $timezone = $_POST['ct_admin_timezone'];
467
 
468
+ require_once('cleantalk.class.php');
 
469
 
470
+ $result = CleantalkHelper::getAutoKey(ct_get_admin_email(), $website, $platform, $timezone);
471
 
472
  if ($result)
473
  {
1977
  $ct_data['sfw_log']= array();
1978
  }
1979
  }
 
 
 
 
1980
 
1981
+ $result = CleantalkHelper::noticeValidateKey($api_key, preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1));
1982
+
1983
+ if (empty($result['error'])){
1984
+ if($result['valid'] == 1){
1985
+ $key_valid = true;
1986
+ $app_server_error = false;
1987
+ $ct_data['testing_failed']=0;
1988
+ }else{
 
 
 
 
 
 
 
1989
  $key_valid = false;
1990
+ $app_server_error = false;
1991
  $ct_data['testing_failed']=1;
1992
  }
1993
+ }else{
1994
+ $key_valid = true;
 
1995
  $app_server_error = true;
1996
  $ct_data['testing_failed']=1;
1997
  }
1998
+
1999
  if ($key_valid) {
2000
  // Removes cookie for server errors
2001
  if ($app_server_error) {
inc/cleantalk-ajax.php CHANGED
@@ -138,104 +138,56 @@ $cleantalk_hooked_actions[]='smuzform_form_submit';
138
  /* hooks for reviewer plugin*/
139
  add_action( 'wp_ajax_nopriv_rwp_ajax_action_rating', 'ct_ajax_hook',1 );
140
  $cleantalk_hooked_actions[]='rwp-submit-wrap';
141
- function ct_validate_email_ajaxlogin($email=null, $is_ajax=true)
142
- {
143
  require_once(CLEANTALK_PLUGIN_DIR . 'cleantalk-public.php');
144
- global $ct_agent_version, $ct_checkjs_register_form, $bp, $ct_signup_done, $ct_negative_comment, $ct_options, $ct_data;
145
 
146
- $ct_options = ct_get_options();
147
- $ct_data = ct_get_data();
148
-
149
  $email = is_null( $email ) ? $email : $_POST['email'];
150
- $email=sanitize_email($email);
151
- $is_good=true;
152
- if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL )||email_exists( $email ) )
153
- {
154
- $is_good=false;
155
- }
156
-
157
- if(class_exists('AjaxLogin')&&isset($_POST['action'])&&$_POST['action']=='validate_email')
158
- {
159
 
160
- //$ct_options=ct_get_options();
161
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
162
- $submit_time = apbct_get_submit_time();
163
- $sender_info = get_sender_info();
164
- $sender_info['post_checkjs_passed']=$checkjs;
165
-
166
- if ($checkjs === null)
167
- {
168
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
169
  $sender_info['cookie_checkjs_passed'] = $checkjs;
170
  }
171
 
172
- $sender_info = json_encode($sender_info);
173
- if ($sender_info === false)
174
- {
175
- $sender_info= '';
176
- }
177
-
178
- require_once('cleantalk.class.php');
179
- $config = ct_get_server();
180
- $ct = new Cleantalk();
181
- $ct->work_url = $config['ct_work_url'];
182
- $ct->server_url = $ct_options['server'];
183
-
184
- $ct->server_ttl = $config['ct_server_ttl'];
185
- $ct->server_changed = $config['ct_server_changed'];
186
- $ct->ssl_on = $ct_options['ssl_on'];
187
 
188
- $ct_request = new CleantalkRequest();
189
- $ct_request->auth_key = $ct_options['apikey'];
190
- $ct_request->sender_email = $email;
191
- $ct_request->sender_ip = cleantalk_get_real_ip();
192
- $ct_request->sender_nickname = '';
193
- $ct_request->agent = $ct_agent_version;
194
- $ct_request->sender_info = $sender_info;
195
- $ct_request->js_on = $checkjs;
196
- $ct_request->submit_time = $submit_time;
197
 
198
- $ct_result = $ct->isAllowUser($ct_request);
199
- if ($ct_result->errno === 0 && empty($ct_result->errstr))
200
- $ct_data['connection_reports']['success']++;
201
- else
202
- {
203
- $ct_data['connection_reports']['negative']++;
204
- $ct_data['connection_reports']['negative_report'][] = array('date'=>date("Y-m-d H:i:s"),'page_url'=>$_SERVER['REQUEST_URI'],'lib_report'=>$ct_result->errstr);
205
- }
206
- update_option('cleantalk_data', $ct_data);
207
- if ($ct->server_change)
208
- {
209
- update_option(
210
- 'cleantalk_server', array(
211
- 'ct_work_url' => $ct->work_url,
212
- 'ct_server_ttl' => $ct->server_ttl,
213
- 'ct_server_changed' => time()
214
- )
215
- );
216
- }
217
- if ($ct_result->allow===0)
218
- {
219
  $is_good=false;
220
  }
221
  }
222
- if($is_good)
223
- {
224
  $ajaxresult=array(
225
  'description' => null,
226
  'cssClass' => 'noon',
227
  'code' => 'success'
228
  );
229
- }
230
- else
231
- {
232
  $ajaxresult=array(
233
  'description' => 'Invalid Email',
234
  'cssClass' => 'error-container',
235
  'code' => 'error'
236
  );
237
  }
238
- $ajaxresult=json_encode($ajaxresult);
 
239
  print $ajaxresult;
240
  wp_die();
241
  }
@@ -243,70 +195,31 @@ function ct_validate_email_ajaxlogin($email=null, $is_ajax=true)
243
  function ct_user_register_ajaxlogin($user_id)
244
  {
245
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
246
- global $ct_agent_version, $ct_checkjs_register_form, $bp, $ct_signup_done, $ct_negative_comment, $ct_options, $ct_data;
247
 
248
- $ct_options = ct_get_options();
249
- $ct_data = ct_get_data();
250
-
251
  if(class_exists('AjaxLogin')&&isset($_POST['action'])&&$_POST['action']=='register_submit')
252
  {
253
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
254
- $submit_time = apbct_get_submit_time();
255
- $sender_info = get_sender_info();
256
- $sender_info['post_checkjs_passed']=$checkjs;
257
 
258
- if ($checkjs === null)
259
- {
 
260
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
261
  $sender_info['cookie_checkjs_passed'] = $checkjs;
262
  }
263
 
264
- $sender_info = json_encode($sender_info);
265
- if ($sender_info === false)
266
- {
267
- $sender_info= '';
268
- }
269
-
270
- require_once('cleantalk.class.php');
271
- $config = ct_get_server();
272
- $ct = new Cleantalk();
273
- $ct->work_url = $config['ct_work_url'];
274
- $ct->server_url = $ct_options['server'];
275
-
276
- $ct->server_ttl = $config['ct_server_ttl'];
277
- $ct->server_changed = $config['ct_server_changed'];
278
- $ct->ssl_on = $ct_options['ssl_on'];
279
 
280
- $ct_request = new CleantalkRequest();
281
- $ct_request->auth_key = $ct_options['apikey'];
282
- $ct_request->sender_email = sanitize_email($_POST['email']);
283
- $ct_request->sender_ip = cleantalk_get_real_ip();
284
- $ct_request->sender_nickname = sanitize_email($_POST['login']); ;
285
- $ct_request->agent = $ct_agent_version;
286
- $ct_request->sender_info = $sender_info;
287
- $ct_request->js_on = $checkjs;
288
- $ct_request->submit_time = $submit_time;
289
 
290
- $ct_result = $ct->isAllowUser($ct_request);
291
- if ($ct_result->errno === 0 && empty($ct_result->errstr))
292
- $ct_data['connection_reports']['success']++;
293
- else
294
- {
295
- $ct_data['connection_reports']['negative']++;
296
- $ct_data['connection_reports']['negative_report'][] = array('date'=>date("Y-m-d H:i:s"),'page_url'=>$_SERVER['REQUEST_URI'],'lib_report'=>$ct_result->errstr);
297
- }
298
- update_option('cleantalk_data', $ct_data);
299
- if ($ct->server_change)
300
- {
301
- update_option(
302
- 'cleantalk_server', array(
303
- 'ct_work_url' => $ct->work_url,
304
- 'ct_server_ttl' => $ct->server_ttl,
305
- 'ct_server_changed' => time()
306
- )
307
- );
308
- }
309
- if ($ct_result->allow===0)
310
  {
311
  wp_delete_user($user_id);
312
  }
@@ -414,56 +327,35 @@ function ct_ajax_hook($message_obj = false, $additional = false)
414
  $ct_post_temp['name'] = $_POST['user_name'];
415
  $ct_post_temp['email'] = $_POST['user_email'];
416
  $ct_post_temp['comment'] = $_POST['comment'];
417
- }
418
- if(isset($ct_post_temp))
419
- $ct_temp_msg_data = ct_get_fields_any($ct_post_temp);
420
- else
421
- $ct_temp_msg_data = ct_get_fields_any($_POST);
422
 
423
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
424
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
425
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
426
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
427
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
428
-
429
- if ($subject != '') {
430
- $message = array_merge(array('subject' => $subject), $message);
431
  }
432
-
433
- $message = json_encode($message);
434
-
435
- if($sender_email!=null)
436
- {
437
- $submit_time = apbct_get_submit_time();
438
- $sender_info = get_sender_info();
439
- $sender_info['post_checkjs_passed']=$checkjs;
440
-
441
- $sender_info = json_encode($sender_info);
442
- if ($sender_info === false)
443
- {
444
- $sender_info= '';
445
- }
446
-
447
- $post_info['comment_type'] = 'feedback_ajax';
448
- $post_info = json_encode($post_info);
449
- if ($post_info === false)
450
- $post_info = '';
451
-
452
-
453
- $ct_base_call_result = ct_base_call(
454
  array(
455
- 'message' => $message,
456
- 'example' => null,
457
- 'sender_email' => $sender_email,
458
  'sender_nickname' => $sender_nickname,
459
- 'sender_info' => $sender_info,
460
- 'post_info'=> $post_info,
461
- 'checkjs' => $checkjs
462
  )
463
  );
464
-
465
- $ct = $ct_base_call_result['ct'];
466
- $ct_result = $ct_base_call_result['ct_result'];
467
  if ($ct_result->allow == 0)
468
  {
469
  if(isset($_POST['action']) && $_POST['action']=='wpuf_submit_register'){
138
  /* hooks for reviewer plugin*/
139
  add_action( 'wp_ajax_nopriv_rwp_ajax_action_rating', 'ct_ajax_hook',1 );
140
  $cleantalk_hooked_actions[]='rwp-submit-wrap';
141
+ function ct_validate_email_ajaxlogin($email=null, $is_ajax=true){
142
+
143
  require_once(CLEANTALK_PLUGIN_DIR . 'cleantalk-public.php');
 
144
 
 
 
 
145
  $email = is_null( $email ) ? $email : $_POST['email'];
146
+ $email = sanitize_email($email);
147
+ $is_good = !filter_var($email, FILTER_VALIDATE_EMAIL) || email_exists($email) ? false : true;
148
+
149
+ if(class_exists('AjaxLogin')&&isset($_POST['action'])&&$_POST['action']=='validate_email'){
 
 
 
 
 
150
 
151
+ $checkjs = js_test('ct_checkjs', $_POST, true);
152
+ $sender_info['post_checkjs_passed'] = $checkjs;
153
+ if ($checkjs === null){
 
 
 
 
 
154
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
155
  $sender_info['cookie_checkjs_passed'] = $checkjs;
156
  }
157
 
158
+ //Making a call
159
+ $base_call_result = apbct_base_call(
160
+ array(
161
+ 'sender_email' => $email,
162
+ 'sender_nickname' => '',
163
+ 'sender_info' => $sender_info,
164
+ 'checkjs' => $checkjs,
165
+ ),
166
+ true
167
+ );
 
 
 
 
 
168
 
169
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
 
 
 
170
 
171
+ if ($ct_result->allow===0){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  $is_good=false;
173
  }
174
  }
175
+
176
+ if($is_good){
177
  $ajaxresult=array(
178
  'description' => null,
179
  'cssClass' => 'noon',
180
  'code' => 'success'
181
  );
182
+ }else{
 
 
183
  $ajaxresult=array(
184
  'description' => 'Invalid Email',
185
  'cssClass' => 'error-container',
186
  'code' => 'error'
187
  );
188
  }
189
+
190
+ $ajaxresult = json_encode($ajaxresult);
191
  print $ajaxresult;
192
  wp_die();
193
  }
195
  function ct_user_register_ajaxlogin($user_id)
196
  {
197
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
 
198
 
 
 
 
199
  if(class_exists('AjaxLogin')&&isset($_POST['action'])&&$_POST['action']=='register_submit')
200
  {
 
 
 
 
201
 
202
+ $checkjs = js_test('ct_checkjs', $_POST, true);
203
+ $sender_info['post_checkjs_passed'] = $checkjs;
204
+ if ($checkjs === null){
205
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
206
  $sender_info['cookie_checkjs_passed'] = $checkjs;
207
  }
208
 
209
+ //Making a call
210
+ $base_call_result = apbct_base_call(
211
+ array(
212
+ 'sender_email' => sanitize_email($_POST['email']),
213
+ 'sender_nickname' => sanitize_email($_POST['login']),
214
+ 'sender_info' => $sender_info,
215
+ 'checkjs' => $checkjs,
216
+ ),
217
+ true
218
+ );
 
 
 
 
 
219
 
220
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
 
 
 
221
 
222
+ if ($ct_result->allow === 0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  {
224
  wp_delete_user($user_id);
225
  }
327
  $ct_post_temp['name'] = $_POST['user_name'];
328
  $ct_post_temp['email'] = $_POST['user_email'];
329
  $ct_post_temp['comment'] = $_POST['comment'];
330
+ }
331
+
332
+ $ct_temp_msg_data = isset($ct_post_temp)
333
+ ? ct_get_fields_any($ct_post_temp)
334
+ : ct_get_fields_any($_POST);
335
 
336
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
337
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
338
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
339
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
340
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
341
+ if($subject != '') {
342
+ $message['subject'] = $subject;
 
343
  }
344
+
345
+ if($sender_email != null)
346
+ {
347
+ $base_call_result = apbct_base_call(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
348
  array(
349
+ 'message' => $message,
350
+ 'sender_email' => $sender_email,
 
351
  'sender_nickname' => $sender_nickname,
352
+ 'sender_info' => array('post_checkjs_passed' => $checkjs),
353
+ 'post_info' => array('comment_type' => 'feedback_ajax'),
354
+ 'checkjs' => $checkjs,
355
  )
356
  );
357
+ $ct_result = $base_call_result['ct_result'];
358
+
 
359
  if ($ct_result->allow == 0)
360
  {
361
  if(isset($_POST['action']) && $_POST['action']=='wpuf_submit_register'){
inc/cleantalk-comments.php CHANGED
@@ -267,31 +267,48 @@ function ct_ajax_check_comments(){
267
  }
268
 
269
  // Gettings comments 100 unchecked comments
270
- $params = array(
271
- 'meta_query' => array(
272
- 'relation' => 'AND',
273
- array(
274
- 'key' => 'ct_checked',
275
- 'compare' => 'NOT EXISTS'
276
- ),
277
- array(
278
- 'key' => 'ct_bad',
279
- 'compare' => 'NOT EXISTS'
280
  )
281
- ),
282
- 'orderby' => 'comment_date_gmt',
283
- 'order' => 'ASC',
284
- 'number' => 100
285
- );
286
- if(isset($from_date, $till_date)){
287
- $params['date_query'] = array(
288
- 'column' => 'comment_date_gmt',
289
- 'after' => $from_date,
290
- 'before' => $till_date,
291
- 'inclusive' => true,
292
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  }
294
- $c = get_comments( $params );
295
 
296
  $check_result = array(
297
  'end' => 0,
@@ -440,12 +457,31 @@ function ct_ajax_info_comments($direct_call = false){
440
 
441
  $result = array();
442
  foreach($metas as $meta){
443
- $params = array('fields' => 'ids', 'count' => true);
444
- if(!empty($meta))
445
- $params['meta_key'] = $meta;
446
- if(isset($from_date, $till_date))
447
- $params['date_query'] = array('column' => 'comment_date_gmt', 'after' => $from_date, 'before' => $till_date, 'inclusive' => true);
448
- $result[] = get_comments( $params );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  }
450
 
451
  $cnt = $result[0]; // Total comments
267
  }
268
 
269
  // Gettings comments 100 unchecked comments
270
+ if(isset($_COOKIE['ct_comments_safe_check'])){
271
+ $c = $wpdb->get_results("
272
+ SELECT comment_ID, comment_date_gmt, comment_author_IP, comment_author_email
273
+ FROM wp_comments as comm
274
+ WHERE
275
+ (comm.comment_approved = '1' OR comm.comment_approved = '0')
276
+ AND NOT EXISTS(
277
+ SELECT comment_id meta_key
278
+ FROM wp_commentmeta as meta
279
+ WHERE comm.comment_ID = meta.comment_id AND (meta_key = 'ct_checked' OR meta_key = 'ct_bad')
280
  )
281
+ ORDER BY comment_date_gmt
282
+ LIMIT 100",
283
+ ARRAY_A
 
 
 
 
 
 
 
 
284
  );
285
+ }else{
286
+ $params = array(
287
+ 'meta_query' => array(
288
+ 'relation' => 'AND',
289
+ array(
290
+ 'key' => 'ct_checked',
291
+ 'compare' => 'NOT EXISTS'
292
+ ),
293
+ array(
294
+ 'key' => 'ct_bad',
295
+ 'compare' => 'NOT EXISTS'
296
+ )
297
+ ),
298
+ 'orderby' => 'comment_date_gmt',
299
+ 'order' => 'ASC',
300
+ 'number' => 100
301
+ );
302
+ if(isset($from_date, $till_date)){
303
+ $params['date_query'] = array(
304
+ 'column' => 'comment_date_gmt',
305
+ 'after' => $from_date,
306
+ 'before' => $till_date,
307
+ 'inclusive' => true,
308
+ );
309
+ }
310
+ $c = get_comments( $params );
311
  }
 
312
 
313
  $check_result = array(
314
  'end' => 0,
457
 
458
  $result = array();
459
  foreach($metas as $meta){
460
+ if(isset($_COOKIE['ct_comments_safe_check'])){
461
+ $res = $wpdb->get_results("
462
+ SELECT COUNT(DISTINCT comment_ID) AS cnt
463
+ FROM `wp_comments` AS comm
464
+ WHERE comm.comment_approved IN ('1','0')".
465
+ (!empty($meta)
466
+ ? " AND EXISTS (SELECT comment_id, meta_key
467
+ FROM wp_commentmeta meta
468
+ WHERE comm.comment_ID = meta.comment_id AND meta_key = '$meta')"
469
+ : '').
470
+ (isset($from_date, $till_date)
471
+ ? " AND comment_date_gmt BETWEEN
472
+ STR_TO_DATE('$from_date', '%Y-%m-%d %H:%i:%s') AND
473
+ STR_TO_DATE('$till_date', '%Y-%m-%d %H:%i:%s')"
474
+ : ''),
475
+ ARRAY_A);
476
+ $result[] = $res[0]['cnt'];
477
+ }else{
478
+ $params = array('fields' => 'ids', 'count' => true);
479
+ if(!empty($meta))
480
+ $params['meta_key'] = $meta;
481
+ if(isset($from_date, $till_date))
482
+ $params['date_query'] = array('column' => 'comment_date_gmt', 'after' => $from_date, 'before' => $till_date, 'inclusive' => true);
483
+ $result[] = get_comments( $params );
484
+ }
485
  }
486
 
487
  $cnt = $result[0]; // Total comments
inc/cleantalk-common.php CHANGED
@@ -113,35 +113,40 @@ function apbct_plugin_loaded() {
113
  * 'post_info' - string
114
  * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
115
  */
116
- function apbct_check(){
117
 
118
- global $ct_agent_version, $ct_options, $ct_data;
119
 
120
  $ct_options = ct_get_options();
121
  $ct_data = ct_get_data();
122
 
123
- $sender_info = get_sender_info($cookie_submit_time, $field_count);
124
- if (isset($params['sender_info']))
125
- $sender_info = array_merge($sender_info, (array) $params['sender_info']);
126
 
127
  $config = ct_get_server();
128
 
129
  require_once('cleantalk.class.php');
130
 
131
  $ct_request = new CleantalkRequest();
132
-
 
 
 
 
 
 
133
  $ct_request->auth_key = $ct_options['apikey'];
134
- $ct_request->message = $params['message'];
135
- $ct_request->example = $params['example'];
136
- $ct_request->sender_email = $params['sender_email'];
137
- $ct_request->sender_nickname = $params['sender_nickname'];
138
- $ct_request->sender_ip = cleantalk_get_real_ip();
139
- $ct_request->agent = $ct_agent_version;
 
140
  $ct_request->sender_info = json_encode($sender_info);
141
- $ct_request->js_on = $params['checkjs'];
142
  $ct_request->submit_time = apbct_get_submit_time();
143
- $ct_request->post_info = $params['post_info'];
144
-
145
  $ct = new Cleantalk();
146
 
147
  $ct->ssl_on = $ct_options['ssl_on'];
@@ -150,60 +155,13 @@ function apbct_check(){
150
  $ct->work_url = $config['ct_work_url'];
151
  $ct->server_changed = $config['ct_server_changed'];
152
 
153
- $ct_result = @$ct->isAllowMessage($ct_request);
154
-
155
- }
156
-
157
- /**
158
- * Inner function - Common part of request sending
159
- * @param array Array of parameters:
160
- * 'message' - string
161
- * 'example' - string
162
- * 'checkjs' - int
163
- * 'sender_email' - string
164
- * 'sender_nickname' - string
165
- * 'sender_info' - array
166
- * 'post_info' - string
167
- * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
168
- */
169
- function ct_base_call($params = array(), $cookie_submit_time = false, $field_count = false) {
170
- global $ct_agent_version, $ct_options, $ct_data;
171
-
172
- $ct_options = ct_get_options();
173
- $ct_data = ct_get_data();
174
-
175
- require_once('cleantalk.class.php');
176
-
177
- $sender_info = get_sender_info($cookie_submit_time, $field_count);
178
- if (isset($params['sender_info']))
179
- $sender_info = array_merge($sender_info, (array) $params['sender_info']);
180
-
181
- $config = ct_get_server();
182
-
183
- $ct = new Cleantalk();
184
-
185
- $ct->ssl_on = $ct_options['ssl_on'];
186
- $ct->server_url = $ct_options['server'];
187
- $ct->server_ttl = $config['ct_server_ttl'];
188
- $ct->work_url = $config['ct_work_url'];
189
- $ct->server_changed = $config['ct_server_changed'];
190
-
191
- $ct_request = new CleantalkRequest();
192
-
193
- $ct_request->auth_key = $ct_options['apikey'];
194
- $ct_request->message = $params['message'];
195
- $ct_request->example = $params['example'];
196
- $ct_request->sender_email = $params['sender_email'];
197
- $ct_request->sender_nickname = $params['sender_nickname'];
198
- $ct_request->sender_ip = cleantalk_get_real_ip();
199
- $ct_request->agent = $ct_agent_version;
200
- $ct_request->sender_info = json_encode($sender_info);
201
- $ct_request->js_on = $params['checkjs'];
202
- $ct_request->submit_time = apbct_get_submit_time();
203
- $ct_request->post_info = $params['post_info'];
204
 
205
- $ct_result = @$ct->isAllowMessage($ct_request);
206
- if ($ct_result->errno === 0 && empty($ct_result->errstr))
207
  $ct_data['connection_reports']['success']++;
208
  else
209
  {
@@ -214,35 +172,35 @@ function ct_base_call($params = array(), $cookie_submit_time = false, $field_cou
214
  update_option(
215
  'cleantalk_server',
216
  array(
217
- 'ct_work_url' => $ct->work_url,
218
- 'ct_server_ttl' => $ct->server_ttl,
219
  'ct_server_changed' => time(),
220
  )
221
  );
222
  }
223
 
224
- $ct_result = ct_change_plugin_resonse($ct_result, $params['checkjs']);
225
-
226
- // Restart submit form counter for failed requests
227
- if ($ct_result->allow == 0) {
228
  apbct_cookie(); // Setting page timer and cookies
229
  ct_add_event('no');
230
- }
231
- else
232
- {
233
  ct_add_event('yes');
234
  }
 
235
  return array('ct' => $ct, 'ct_result' => $ct_result);
 
236
  }
237
 
238
  /**
239
  * Inner function - Default data array for senders
240
  * @return array
241
  */
242
- function get_sender_info($cookie_submit_time = false, $field_count = false) {
243
 
244
  // Validate cookie from the backend
245
- $ct = apbct_cookies_test();
246
 
247
  if (count($_POST) > 0) {
248
  foreach ($_POST as $k => $v) {
@@ -251,40 +209,42 @@ function get_sender_info($cookie_submit_time = false, $field_count = false) {
251
  }
252
  }
253
  }
254
-
255
- $sender_info = array(
256
- 'REFFERRER' => htmlspecialchars(@$_SERVER['HTTP_REFERER']),
257
- 'USER_AGENT' => htmlspecialchars(@$_SERVER['HTTP_USER_AGENT']),
258
- 'page_url' => htmlspecialchars(@$_SERVER['SERVER_NAME'].@$_SERVER['REQUEST_URI']),
 
 
 
 
 
 
 
 
259
  'cms_lang' => substr(get_locale(), 0, 2),
260
  'ct_options' => json_encode(ct_get_options()),
261
  'fields_number' => sizeof($_POST),
262
- 'direct_post' => $ct === null && $_SERVER['REQUEST_METHOD'] == 'POST'? 1 : 0,
263
- 'cookies_enabled' => $cookie_submit_time ? $ct : ct_cookies_test(true),
264
- 'checkjs_data_post' => !empty($checkjs_data_post) ? $checkjs_data_post : null,
265
- 'checkjs_data_cookies' => !empty($_COOKIE['ct_checkjs']) ? $_COOKIE['ct_checkjs'] : null, // Raw data to validated JavaScript test in the cloud
266
- 'REFFERRER_PREVIOUS' => !empty($_COOKIE['apbct_prev_referer']) && $ct ? $_COOKIE['apbct_prev_referer'] : null,
267
- 'site_landing_ts' => !empty($_COOKIE['apbct_site_landing_ts']) && $ct ? $_COOKIE['apbct_site_landing_ts'] : null,
268
- 'js_info' => !empty($_COOKIE['ct_user_info']) ? json_decode(stripslashes($_COOKIE['ct_user_info'])) : '',
269
- 'mouse_cursor_positions' => !empty($_COOKIE['ct_pointer_data']) ? json_decode($_COOKIE['ct_pointer_data']) : 0,
270
- 'js_timezone' => !empty($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : 0,
271
- 'key_press_timestamp' => !empty($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : 0,
272
- 'page_set_timestamp' => !empty($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : 0,
273
- 'page_hits' => !empty($_COOKIE['apbct_page_hits']) ? $_COOKIE['apbct_page_hits'] : 0,
 
 
 
 
 
 
 
274
  );
275
-
276
- if($field_count){
277
- $visible_inputs_count = !empty($_COOKIE['apbct_visible_fields_count'])
278
- ? $_COOKIE['apbct_visible_fields_count']
279
- : null;
280
- $apbct_visible_fields = !empty($_COOKIE['apbct_visible_fields'])
281
- ? json_decode(stripslashes($_COOKIE['apbct_visible_fields']), true)
282
- : null;
283
- $sender_info['form_visible_inputs'] = $visible_inputs_count;
284
- $sender_info['apbct_visible_fields'] = $apbct_visible_fields;
285
- }
286
-
287
- return $sender_info;
288
  }
289
 
290
  /**
@@ -668,12 +628,14 @@ function ct_delete_spam_comments() {
668
  * @return array
669
  */
670
  function ct_get_fields_any($arr, $message=array(), $email = null, $nickname = array('nick' => '', 'first' => '', 'last' => ''), $subject = null, $contact = true, $prev_name = ''){
 
671
  $skip_params = array( //Skip request if fields exists
672
  'ipn_track_id', // PayPal IPN #
673
  'txn_type', // PayPal transaction type
674
  'payment_status', // PayPal payment status
675
- 'ccbill_ipn', //CCBill IPN
676
- 'ct_checkjs' //skip ct_checkjs field
 
677
  );
678
  $obfuscate_params = array( //Fields to replace with ****
679
  'password',
@@ -746,7 +708,7 @@ function ct_get_fields_any($arr, $message=array(), $email = null, $nickname = ar
746
 
747
  if(!is_array($value) && !is_object($value) && @get_class($value)!='WP_User'){
748
 
749
- if (in_array($key, $skip_params, true) && $key!=0 && $key!='' || preg_match("/^ct_checkjs/", $key))
750
  $contact = false;
751
 
752
  if($value === '')
@@ -802,7 +764,7 @@ function ct_get_fields_any($arr, $message=array(), $email = null, $nickname = ar
802
  $message[$prev_name.$key] = $value;
803
  }
804
 
805
- }else if(!is_object($value)&&@get_class($value)!='WP_User'){
806
 
807
  $prev_name_original = $prev_name;
808
  $prev_name = ($prev_name === '' ? $key.'_' : $prev_name.$key.'_');
@@ -971,7 +933,6 @@ function ct_filter_array(&$array)
971
  }else{
972
  $array[$key] = ct_filter_array($value);
973
  }
974
-
975
  }
976
 
977
  return $array;
113
  * 'post_info' - string
114
  * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
115
  */
116
+ function apbct_base_call($params = array(), $reg_flag = false){
117
 
118
+ global $ct_options, $ct_data;
119
 
120
  $ct_options = ct_get_options();
121
  $ct_data = ct_get_data();
122
 
123
+ $sender_info = !empty($params['sender_info'])
124
+ ? array_merge(apbct_get_sender_info(), (array) $params['sender_info'])
125
+ : apbct_get_sender_info();
126
 
127
  $config = ct_get_server();
128
 
129
  require_once('cleantalk.class.php');
130
 
131
  $ct_request = new CleantalkRequest();
132
+
133
+ // IPs
134
+ $ct_request->sender_ip = isset($params['sender_ip']) ? $params['sender_ip'] : CleantalkHelper::get_ip_real();
135
+ $ct_request->x_forwarded_for = CleantalkHelper::get_ip_x_forwarded_for();
136
+ $ct_request->x_real_ip = CleantalkHelper::get_ip_x_real_ip();
137
+
138
+ // Misc
139
  $ct_request->auth_key = $ct_options['apikey'];
140
+ $ct_request->message = !empty($params['message']) ? ct_filter_array($params['message']) : null;
141
+ $ct_request->example = !empty($params['example']) ? $params['example'] : null;
142
+ $ct_request->sender_email = !empty($params['sender_email']) ? $params['sender_email'] : null;
143
+ $ct_request->sender_nickname = !empty($params['sender_nickname']) ? $params['sender_nickname'] : null;
144
+ $ct_request->post_info = isset($params['post_info']) ? json_encode($params['post_info']) : null;
145
+ $ct_request->js_on = isset($params['checkjs']) ? $params['checkjs'] : js_test('ct_checkjs', $_COOKIE, true);
146
+ $ct_request->agent = APBCT_AGENT;
147
  $ct_request->sender_info = json_encode($sender_info);
 
148
  $ct_request->submit_time = apbct_get_submit_time();
149
+
 
150
  $ct = new Cleantalk();
151
 
152
  $ct->ssl_on = $ct_options['ssl_on'];
155
  $ct->work_url = $config['ct_work_url'];
156
  $ct->server_changed = $config['ct_server_changed'];
157
 
158
+ if($reg_flag){
159
+ $ct_result = @$ct->isAllowUser($ct_request);
160
+ }else{
161
+ $ct_result = @$ct->isAllowMessage($ct_request);
162
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
+ if ($ct_result->errno === 0 && empty($ct_result->errstr))
 
165
  $ct_data['connection_reports']['success']++;
166
  else
167
  {
172
  update_option(
173
  'cleantalk_server',
174
  array(
175
+ 'ct_work_url' => $ct->work_url,
176
+ 'ct_server_ttl' => $ct->server_ttl,
177
  'ct_server_changed' => time(),
178
  )
179
  );
180
  }
181
 
182
+ $ct_result = ct_change_plugin_resonse($ct_result, $ct_request->js_on);
183
+
184
+ // Restart submit form counter for failed requests
185
+ if ($ct_result->allow == 0){
186
  apbct_cookie(); // Setting page timer and cookies
187
  ct_add_event('no');
188
+ }else{
 
 
189
  ct_add_event('yes');
190
  }
191
+
192
  return array('ct' => $ct, 'ct_result' => $ct_result);
193
+
194
  }
195
 
196
  /**
197
  * Inner function - Default data array for senders
198
  * @return array
199
  */
200
+ function apbct_get_sender_info() {
201
 
202
  // Validate cookie from the backend
203
+ $cookie_is_ok = apbct_cookies_test();
204
 
205
  if (count($_POST) > 0) {
206
  foreach ($_POST as $k => $v) {
209
  }
210
  }
211
  }
212
+
213
+ // AMP check
214
+ $amp_detected = isset($_SERVER['HTTP_REFERER'])
215
+ ? strpos($_SERVER['HTTP_REFERER'], '/amp/') !== false || strpos($_SERVER['HTTP_REFERER'], '?amp=1') !== false || strpos($_SERVER['HTTP_REFERER'], '&amp=1') !== false
216
+ ? 1
217
+ : 0
218
+ : null;
219
+
220
+ return array(
221
+ 'remote_addr' => CleantalkHelper::get_ip_remote_addr(),
222
+ 'REFFERRER' => isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : null,
223
+ 'USER_AGENT' => isset($_SERVER['HTTP_USER_AGENT']) ? htmlspecialchars($_SERVER['HTTP_USER_AGENT']) : null,
224
+ 'page_url' => isset($_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI']) ? htmlspecialchars($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']) : null,
225
  'cms_lang' => substr(get_locale(), 0, 2),
226
  'ct_options' => json_encode(ct_get_options()),
227
  'fields_number' => sizeof($_POST),
228
+ 'direct_post' => $cookie_is_ok === null && $_SERVER['REQUEST_METHOD'] == 'POST' ? 1 : 0,
229
+ // Raw data to validated JavaScript test in the cloud
230
+ 'checkjs_data_cookies' => !empty($_COOKIE['ct_checkjs']) ? $_COOKIE['ct_checkjs'] : null,
231
+ 'checkjs_data_post' => !empty($checkjs_data_post) ? $checkjs_data_post : null,
232
+ // PHP cookies
233
+ 'cookies_enabled' => $cookie_is_ok,
234
+ 'REFFERRER_PREVIOUS' => !empty($_COOKIE['apbct_prev_referer']) && $cookie_is_ok ? $_COOKIE['apbct_prev_referer'] : null,
235
+ 'site_landing_ts' => !empty($_COOKIE['apbct_site_landing_ts']) && $cookie_is_ok ? $_COOKIE['apbct_site_landing_ts'] : null,
236
+ 'page_hits' => !empty($_COOKIE['apbct_page_hits']) ? $_COOKIE['apbct_page_hits'] : null,
237
+ // JS cookies
238
+ 'js_info' => !empty($_COOKIE['ct_user_info']) ? json_decode(stripslashes($_COOKIE['ct_user_info'])) : null,
239
+ 'mouse_cursor_positions' => !empty($_COOKIE['ct_pointer_data']) ? json_decode(stripslashes($_COOKIE['ct_pointer_data']), true) : null,
240
+ 'js_timezone' => !empty($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : null,
241
+ 'key_press_timestamp' => !empty($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : null,
242
+ 'page_set_timestamp' => !empty($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : null,
243
+ 'form_visible_inputs' => !empty($_COOKIE['apbct_visible_fields_count']) ? $_COOKIE['apbct_visible_fields_count'] : null,
244
+ 'apbct_visible_fields' => !empty($_COOKIE['apbct_visible_fields']) ? json_decode(stripslashes($_COOKIE['apbct_visible_fields']), true) : null,
245
+ // Debug stuff
246
+ 'amp_detected' => $amp_detected,
247
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  }
249
 
250
  /**
628
  * @return array
629
  */
630
  function ct_get_fields_any($arr, $message=array(), $email = null, $nickname = array('nick' => '', 'first' => '', 'last' => ''), $subject = null, $contact = true, $prev_name = ''){
631
+
632
  $skip_params = array( //Skip request if fields exists
633
  'ipn_track_id', // PayPal IPN #
634
  'txn_type', // PayPal transaction type
635
  'payment_status', // PayPal payment status
636
+ 'ccbill_ipn', // CCBill IPN
637
+ 'ct_checkjs', // skip ct_checkjs field
638
+ 'api_mode', // DigiStore-API
639
  );
640
  $obfuscate_params = array( //Fields to replace with ****
641
  'password',
708
 
709
  if(!is_array($value) && !is_object($value) && @get_class($value)!='WP_User'){
710
 
711
+ if (in_array($key, $skip_params, true) && $key != 0 && $key != '' || preg_match("/^ct_checkjs/", $key))
712
  $contact = false;
713
 
714
  if($value === '')
764
  $message[$prev_name.$key] = $value;
765
  }
766
 
767
+ }elseif(!is_object($value) && @get_class($value) != 'WP_User'){
768
 
769
  $prev_name_original = $prev_name;
770
  $prev_name = ($prev_name === '' ? $key.'_' : $prev_name.$key.'_');
933
  }else{
934
  $array[$key] = ct_filter_array($value);
935
  }
 
936
  }
937
 
938
  return $array;
inc/cleantalk-public.php CHANGED
@@ -308,48 +308,37 @@ function ct_validate_ccf_submission($value, $field_id, $required){
308
 
309
  unset($ct_global_temporary_data);
310
 
311
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
312
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
313
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
314
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
315
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
316
 
317
  if ($subject != '')
318
- $message = array_merge(array('subject' => $subject), $message);
319
- $message = json_encode($message);
320
 
321
- $post_info['comment_type'] = 'feedback_custom_contact_forms';
322
- $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
323
- $post_info = json_encode($post_info);
324
- if ($post_info === false)
325
- $post_info = '';
326
 
327
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
328
- if ($checkjs === null)
329
- $checkjs = js_test('ct_checkjs', $_POST, true);
330
 
331
- $sender_info = array(
332
- 'sender_url' => null
333
- );
334
-
335
  //Making a call
336
- $ct_base_call_result = ct_base_call(array(
337
- 'message' => $subject." ".$message,
338
- 'example' => null,
339
- 'sender_email' => $sender_email,
340
- 'sender_nickname' => $sender_nickname,
341
- 'post_info' => $post_info,
342
- 'checkjs' => $checkjs,
343
- 'sender_info' => $sender_info
344
- ));
345
-
346
- $ct = $ct_base_call_result['ct'];
347
- $ct_result = $ct_base_call_result['ct_result'];
348
 
349
- if ($ct_result->allow == 0)
350
- return $ct_result->comment;
351
- else
352
- return true;
353
  }
354
 
355
  function ct_woocommerce_wishlist_check($args){
@@ -378,31 +367,24 @@ function ct_woocommerce_wishlist_check($args){
378
 
379
  $post_info['comment_type'] = 'feedback';
380
  $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
381
- $post_info = json_encode($post_info);
382
- if ($post_info === false)
383
- $post_info = '';
384
-
385
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
386
- if ($checkjs === null)
387
- $checkjs = js_test('ct_checkjs', $_POST, true);
388
-
389
- $sender_info = array(
390
- 'sender_url' => null
391
- );
392
 
 
 
 
 
393
  //Making a call
394
- $ct_base_call_result = ct_base_call(array(
395
- 'message' => $subject." ".$message,
396
- 'example' => null,
397
- 'sender_email' => $email,
398
- 'sender_nickname' => $nickname,
399
- 'post_info' => $post_info,
400
- 'checkjs' => $checkjs,
401
- 'sender_info' => $sender_info
402
- ));
403
-
404
- $ct = $ct_base_call_result['ct'];
405
- $ct_result = $ct_base_call_result['ct_result'];
406
 
407
  if ($ct_result->allow == 0)
408
  wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
@@ -469,32 +451,24 @@ function ct_bp_private_msg_check( $bp_message_obj){
469
 
470
  $post_info['comment_type'] = 'buddypress_comment';
471
  $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
472
- $post_info = json_encode($post_info);
473
- if ($post_info === false)
474
- $post_info = '';
475
-
476
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
477
- if ($checkjs === null)
478
- $checkjs = js_test('ct_checkjs', $_POST, true);
479
 
480
- $sender_info = array(
481
- 'sender_url' => null
482
- );
483
 
484
  //Making a call
485
 
486
- $ct_base_call_result = ct_base_call(array(
487
- 'message' => $subject." ".$message,
488
- 'example' => null,
489
- 'sender_email' => $email,
490
- 'sender_nickname' => $nickname,
491
- 'post_info' => $post_info,
492
- 'checkjs' => $checkjs,
493
- 'sender_info' => $sender_info
494
- ));
495
-
496
- $ct = $ct_base_call_result['ct'];
497
- $ct_result = $ct_base_call_result['ct_result'];
498
 
499
  if ($ct_result->allow == 0)
500
  wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
@@ -512,50 +486,35 @@ function ct_pirate_forms_check(){
512
  //Check for enabled option
513
  if($ct_options['contact_forms_test'] == 0)
514
  return;
515
-
516
- $ct_temp_msg_data = ct_get_fields_any($_POST);
517
 
518
  //Getting request params
519
-
520
  $ct_temp_msg_data = ct_get_fields_any($_POST);
521
 
522
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
523
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
524
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
525
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
526
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
527
 
528
  if($subject != '')
529
  $message = array_merge(array('subject' => $subject), $message);
530
 
531
- $message = json_encode($message);
532
-
533
  $post_info['comment_type'] = 'feedback_pirate_contact_form';
534
  $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
535
- $post_info = json_encode($post_info);
536
- if ($post_info === false)
537
- $post_info = '';
538
-
539
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
540
-
541
- $sender_info = array(
542
- 'sender_url' => null
543
- );
544
 
545
  //Making a call
 
 
 
 
 
 
 
 
 
 
546
 
547
- $ct_base_call_result = ct_base_call(array(
548
- 'message' => $message,
549
- 'example' => null,
550
- 'sender_email' => $sender_email,
551
- 'sender_nickname' => $sender_nickname,
552
- 'post_info' => $post_info,
553
- 'checkjs' => $checkjs,
554
- 'sender_info' => $sender_info
555
- ));
556
-
557
- $ct = $ct_base_call_result['ct'];
558
- $ct_result = $ct_base_call_result['ct_result'];
559
 
560
  if ($ct_result->allow == 0)
561
  wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
@@ -719,37 +678,29 @@ function ct_frm_validate_entry ($errors, $values) {
719
  if ($ct_options['protect_logged_in'] != 1 && is_user_logged_in()) {
720
  return $errors;
721
  }
722
-
723
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
724
- if($checkjs != 1){
725
- $checkjs = js_test($ct_checkjs_frm, $_POST, true);
726
- }
727
-
728
- $post_info['comment_type'] = 'feedback';
729
- $post_info = json_encode($post_info);
730
- if ($post_info === false)
731
- $post_info = '';
732
-
733
  $ct_temp_msg_data = ct_get_fields_any($values['item_meta']);
734
 
735
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
736
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
737
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
738
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
739
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
740
-
741
- $message = json_encode($message);
742
-
743
- $ct_base_call_result = ct_base_call(array(
744
- 'message' => $message,
745
- 'example' => null,
746
- 'sender_email' => $sender_email,
747
- 'sender_nickname' => $sender_nickname,
748
- 'post_info' => $post_info,
749
- 'checkjs' => $checkjs
750
- ));
751
- $ct = $ct_base_call_result['ct'];
752
- $ct_result = $ct_base_call_result['ct_result'];
 
 
753
 
754
  if ($ct_result->allow == 0) {
755
  $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
@@ -790,42 +741,30 @@ function ct_bbp_new_pre_content ($comment) {
790
  if ($ct_options['protect_logged_in'] != 1 && is_user_logged_in() ||
791
  in_array("administrator", $current_user->roles))
792
  return $comment;
793
-
794
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
795
- if ($checkjs === null) {
796
- $checkjs = js_test('ct_checkjs', $_POST, true);
797
- }
798
-
799
- $example = null;
800
 
801
- $sender_info = array(
802
- 'sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null
803
- );
804
-
805
  $post_info['comment_type'] = 'bbpress_comment';
806
  $post_info['post_url'] = bbp_get_topic_permalink();
807
-
808
- $post_info = json_encode($post_info);
809
- if ($post_info === false) {
810
- $post_info = '';
811
- }
812
 
813
  if(isset($ct_bbp_topic))
814
  $message = $ct_bbp_topic." ".$comment;
815
  else
816
  $message = $comment;
817
 
818
- $ct_base_call_result = ct_base_call(array(
819
- 'message' => $comment,
820
- 'example' => $example,
821
- 'sender_email' => isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null,
822
- 'sender_nickname' => isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null,
823
- 'post_info' => $post_info,
824
- 'checkjs' => $checkjs,
825
- 'sender_info' => $sender_info
826
- ));
827
- $ct = $ct_base_call_result['ct'];
828
- $ct_result = $ct_base_call_result['ct_result'];
829
 
830
  if ($ct_result->allow == 0) {
831
  bbp_add_error('bbp_reply_content', $ct_result->comment);
@@ -852,31 +791,31 @@ function ct_preprocess_comment($comment) {
852
  if (in_array("administrator", $current_user->roles))
853
  return $comment;
854
 
855
- if(defined('CLEANTALK_CHECK_COMMENTS_NUMBER'))
856
- $comments_check_number = CLEANTALK_CHECK_COMMENTS_NUMBER;
857
- else
858
- $comments_check_number = 3;
859
-
860
- $is_max_comments = false;
861
- if(isset($ct_options['check_comments_number']))
862
- $value = @intval($ct_options['check_comments_number']);
863
- else
864
- $value=1;
865
 
866
  if($value == 1){
867
- $args=Array('author_email' => $comment['comment_author_email'],
868
- 'status' => 'approve',
869
- 'count' => false,
870
- 'number' => $comments_check_number
871
- );
872
- $cnt = sizeof(get_comments( $args ));
873
-
874
- if($cnt >= $comments_check_number)
875
- $is_max_comments = true;
876
-
877
- }
878
-
879
- if (($comment['comment_type']!='trackback') && (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || $ct_comment_done || (isset($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'],'page=wysija_campaigns&action=editTemplate')!==false) || $is_max_comments || strpos($_SERVER['REQUEST_URI'],'/wp-admin/')!==false)) {
 
 
 
 
 
 
 
 
880
  return $comment;
881
  }
882
 
@@ -902,36 +841,18 @@ function ct_preprocess_comment($comment) {
902
  $ct_comment_done = true;
903
 
904
  $comment_post_id = $comment['comment_post_ID'];
905
-
906
- $sender_info = array(
907
- 'sender_url' => @$comment['comment_author_url']
908
- );
909
-
910
- //
911
  // JetPack comments logic
912
- //
913
- $checkjs = 0;
914
- if ($ct_jp_comments) {
915
- $post_info['comment_type'] = 'jetpack_comment';
916
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
917
- } else {
918
- $post_info['comment_type'] = $comment['comment_type'];
919
- $checkjs = js_test('ct_checkjs', $_POST, true);
920
- }
921
- if($checkjs==0)
922
- {
923
- $checkjs = js_test('ct_checkjs', $_POST, true);
924
- }
925
- if($checkjs==0)
926
- {
927
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
928
- }
929
 
930
- $post_info['post_url'] = ct_post_url(null, $comment_post_id);
931
- $post_info = json_encode($post_info);
932
- if ($post_info === false) {
933
- $post_info = '';
934
- }
935
 
936
  $example = null;
937
  if ($ct_options['relevance_test']) {
@@ -956,17 +877,18 @@ function ct_preprocess_comment($comment) {
956
  }
957
  }
958
 
959
- $ct_base_call_result = ct_base_call(array(
960
- 'message' => $comment['comment_content'],
961
- 'example' => $example,
962
- 'sender_email' => $comment['comment_author_email'],
963
- 'sender_nickname' => $comment['comment_author'],
964
- 'post_info' => $post_info,
965
- 'checkjs' => $checkjs,
966
- 'sender_info' => $sender_info
967
- ));
968
- $ct = $ct_base_call_result['ct'];
969
- $ct_result = $ct_base_call_result['ct_result'];
 
970
 
971
  ct_hash($ct_result->id);
972
 
@@ -1319,22 +1241,18 @@ function ct_register_post($sanitized_user_login = null, $user_email = null, $err
1319
  */
1320
 
1321
  function ct_test_message($nickname, $email, $ip, $text){
1322
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1323
-
1324
- $post_info['comment_type'] = 'feedback_plugin_check';
1325
- $post_info = json_encode($post_info);
1326
-
1327
- $ct_base_call_result = ct_base_call(array(
1328
- 'message' => $text,
1329
- 'example' => null,
1330
- 'sender_email' => $email,
1331
- 'sender_nickname' => $nickname,
1332
- 'post_info' => $post_info,
1333
- 'sender_info' => get_sender_info(),
1334
- 'checkjs' => $checkjs
1335
- ));
1336
 
1337
- $ct_result = $ct_base_call_result['ct_result'];
1338
 
1339
  $result=Array(
1340
  'allow' => $ct_result->allow,
@@ -1348,66 +1266,31 @@ function ct_test_message($nickname, $email, $ip, $text){
1348
  * @return array with checking result;
1349
  */
1350
  function ct_test_registration($nickname, $email, $ip){
1351
- global $ct_checkjs_register_form, $ct_agent_version, $ct_options, $ct_data;
1352
 
1353
  $ct_options = ct_get_options();
1354
- $ct_data = ct_get_data();
1355
-
1356
- $submit_time = apbct_get_submit_time();
1357
 
1358
- $sender_info = get_sender_info(true);
1359
-
1360
- $checkjs=0;
1361
-
1362
  $checkjs = js_test($ct_checkjs_register_form, $_POST, true);
1363
  $sender_info['post_checkjs_passed'] = $checkjs;
1364
-
1365
- //
1366
- // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1367
- //
1368
- if ($checkjs == 0) {
1369
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1370
  $sender_info['cookie_checkjs_passed'] = $checkjs;
1371
  }
1372
-
1373
- $sender_info = json_encode($sender_info);
1374
- if ($sender_info === false) {
1375
- $sender_info= '';
1376
- }
1377
-
1378
- require_once('cleantalk.class.php');
1379
- $config = ct_get_server();
1380
- $ct = new Cleantalk();
1381
- $ct->work_url = $config['ct_work_url'];
1382
- $ct->server_url = $ct_options['server'];
1383
-
1384
- $ct->server_ttl = $config['ct_server_ttl'];
1385
- $ct->server_changed = $config['ct_server_changed'];
1386
- $ct->ssl_on = $ct_options['ssl_on'];
1387
-
1388
- $ct_request = new CleantalkRequest();
1389
- $ct_request->auth_key = $ct_options['apikey'];
1390
- $ct_request->sender_email = $email;
1391
- $ct_request->sender_ip = $ip;
1392
- $ct_request->sender_nickname = $nickname;
1393
- $ct_request->agent = $ct_agent_version;
1394
- $ct_request->sender_info = $sender_info;
1395
- $ct_request->js_on = $checkjs;
1396
- $ct_request->submit_time = $submit_time;
1397
-
1398
- $ct_result = $ct->isAllowUser($ct_request);
1399
- if ($ct_result->errno === 0 && empty($ct_result->errstr))
1400
- $ct_data['connection_reports']['success']++;
1401
- else
1402
- {
1403
- $ct_data['connection_reports']['negative']++;
1404
- $ct_data['connection_reports']['negative_report'][] = array('date'=>date("Y-m-d H:i:s"),'page_url'=>$_SERVER['REQUEST_URI'],'lib_report'=>$ct_result->errstr);
1405
- }
1406
- update_option('cleantalk_data', $ct_data);
1407
- $ct_result = ct_change_plugin_resonse($ct_result, $checkjs);
1408
-
1409
- ct_add_event($ct_result->allow);
1410
-
1411
  $result=Array(
1412
  'allow' => $ct_result->allow,
1413
  'comment' => $ct_result->comment,
@@ -1472,81 +1355,25 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
1472
  }
1473
  return $errors;
1474
  }
1475
-
1476
- $submit_time = apbct_get_submit_time();
1477
-
1478
- $sender_info = get_sender_info(true);
1479
-
1480
- $checkjs=0;
1481
-
1482
  $checkjs = js_test($ct_checkjs_register_form, $_POST, true);
1483
  $sender_info['post_checkjs_passed'] = $checkjs;
1484
- //
1485
  // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1486
- //
1487
  if ($checkjs == 0) {
1488
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1489
  $sender_info['cookie_checkjs_passed'] = $checkjs;
1490
  }
1491
-
1492
- // Pointer data
1493
- $pointer_data = isset($_COOKIE['ct_pointer_data']) ? json_decode($_COOKIE['ct_pointer_data']) : 0;
1494
-
1495
- // Timezone from JS
1496
- $js_timezone = isset($_COOKIE['ct_timezone']) ? $_COOKIE['ct_timezone'] : 0;
1497
-
1498
- //First key down timestamp
1499
- $first_key_press_timestamp = isset($_COOKIE['ct_fkp_timestamp']) ? $_COOKIE['ct_fkp_timestamp'] : 0;
1500
- $page_set_timestamp = (isset($_COOKIE['ct_ps_timestamp']) ? $_COOKIE['ct_ps_timestamp'] : 0);
1501
-
1502
- $sender_info['mouse_cursor_positions'] = $pointer_data;
1503
- $sender_info['js_timezone'] = $js_timezone;
1504
- $sender_info['key_press_timestamp'] = $first_key_press_timestamp;
1505
- $sender_info['page_set_timestamp'] = $page_set_timestamp;
1506
-
1507
- $sender_info = json_encode($sender_info);
1508
- if ($sender_info === false) {
1509
- $sender_info= '';
1510
- }
1511
-
1512
- require_once('cleantalk.class.php');
1513
- $config = ct_get_server();
1514
- $ct = new Cleantalk();
1515
- $ct->work_url = $config['ct_work_url'];
1516
- $ct->server_url = $ct_options['server'];
1517
-
1518
- $ct->server_ttl = $config['ct_server_ttl'];
1519
- $ct->server_changed = $config['ct_server_changed'];
1520
- $ct->ssl_on = $ct_options['ssl_on'];
1521
 
1522
- $ct_request = new CleantalkRequest();
1523
- $ct_request->auth_key = $ct_options['apikey'];
1524
- $ct_request->sender_email = $user_email;
1525
- $ct_request->sender_ip = cleantalk_get_real_ip();
1526
- $ct_request->sender_nickname = $sanitized_user_login;
1527
- $ct_request->agent = $ct_agent_version;
1528
- $ct_request->sender_info = $sender_info;
1529
- $ct_request->js_on = $checkjs;
1530
- $ct_request->submit_time = $submit_time;
1531
-
1532
- $ct_result = $ct->isAllowUser($ct_request);
1533
- if ($ct_result->errno === 0 && empty($ct_result->errstr))
1534
- $ct_data['connection_reports']['success']++;
1535
- else
1536
- {
1537
- $ct_data['connection_reports']['negative']++;
1538
- $ct_data['connection_reports']['negative_report'][] = array('date'=>date("Y-m-d H:i:s"),'page_url'=>$_SERVER['REQUEST_URI'],'lib_report'=>$ct_result->errstr);
1539
- }
1540
- update_option('cleantalk_data', $ct_data);
1541
- if ($ct->server_change) {
1542
- update_option(
1543
- 'cleantalk_server', array(
1544
- 'ct_work_url' => $ct->work_url,
1545
- 'ct_server_ttl' => $ct->server_ttl,
1546
- 'ct_server_changed' => time()
1547
- )
1548
- );
1549
- }
1550
 
1551
  $ct_signup_done = true;
1552
 
@@ -1558,9 +1385,7 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
1558
  }
1559
 
1560
  if ($ct_result->allow == 0) {
1561
-
1562
- apbct_cookie(); // Setting page timer and cookies
1563
-
1564
  if ($buddypress === true) {
1565
  $bp->signup->errors['signup_username'] = $ct_result->comment;
1566
  }elseif(!empty($facebook)){
@@ -1581,9 +1406,7 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
1581
  setcookie($apbct_cookie_request_id_label, $ct_result->id, time()+10, '/');
1582
  }
1583
  }
1584
-
1585
- ct_add_event($ct_result->allow);
1586
-
1587
  return $errors;
1588
  }
1589
 
@@ -1672,17 +1495,6 @@ function ct_contact_form_is_spam($form) {
1672
  $js_field_name = $k;
1673
  }
1674
 
1675
- $checkjs = js_test($js_field_name, $_POST, true);
1676
-
1677
- $sender_info = array(
1678
- 'sender_url' => @$form['comment_author_url']
1679
- );
1680
-
1681
- $post_info['comment_type'] = 'feedback';
1682
- $post_info = json_encode($post_info);
1683
- if ($post_info === false)
1684
- $post_info = '';
1685
-
1686
  $sender_email = null;
1687
  $sender_nickname = null;
1688
  $message = '';
@@ -1695,17 +1507,17 @@ function ct_contact_form_is_spam($form) {
1695
  if (isset($form['comment_content']))
1696
  $message = $form['comment_content'];
1697
 
1698
- $ct_base_call_result = ct_base_call(array(
1699
- 'message' => $message,
1700
- 'example' => null,
1701
- 'sender_email' => $sender_email,
1702
- 'sender_nickname' => $sender_nickname,
1703
- 'post_info' => $post_info,
1704
- 'sender_info' => $sender_info,
1705
- 'checkjs' => $checkjs
1706
- ));
1707
- $ct = $ct_base_call_result['ct'];
1708
- $ct_result = $ct_base_call_result['ct_result'];
1709
 
1710
  if ($ct_result->allow == 0) {
1711
  global $ct_comment;
@@ -1733,17 +1545,6 @@ function ct_contact_form_is_spam_jetpack($is_spam,$form) {
1733
  $js_field_name = $k;
1734
  }
1735
 
1736
- $checkjs = js_test($js_field_name, $_POST, true);
1737
-
1738
- $sender_info = array(
1739
- 'sender_url' => @$form['comment_author_url']
1740
- );
1741
-
1742
- $post_info['comment_type'] = 'feedback';
1743
- $post_info = json_encode($post_info);
1744
- if ($post_info === false)
1745
- $post_info = '';
1746
-
1747
  $sender_email = null;
1748
  $sender_nickname = null;
1749
  $message = '';
@@ -1756,17 +1557,16 @@ function ct_contact_form_is_spam_jetpack($is_spam,$form) {
1756
  if (isset($form['comment_content']))
1757
  $message = $form['comment_content'];
1758
 
1759
- $ct_base_call_result = ct_base_call(array(
1760
- 'message' => $message,
1761
- 'example' => null,
1762
- 'sender_email' => $sender_email,
1763
- 'sender_nickname' => $sender_nickname,
1764
- 'post_info' => $post_info,
1765
- 'sender_info' => $sender_info,
1766
- 'checkjs' => $checkjs
1767
- ));
1768
- $ct = $ct_base_call_result['ct'];
1769
- $ct_result = $ct_base_call_result['ct_result'];
1770
 
1771
  if ($ct_result->allow == 0) {
1772
  global $ct_comment;
@@ -1824,59 +1624,42 @@ function ct_wpcf7_spam($param) {
1824
  return $param;
1825
  }
1826
 
1827
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1828
- if($checkjs != 1){
1829
- $checkjs = js_test($ct_checkjs_cf7, $_POST, true);
1830
- }
1831
-
1832
- $post_info['comment_type'] = 'feedback';
1833
- $post_info = json_encode($post_info);
1834
- if ($post_info === false)
1835
- $post_info = '';
1836
-
1837
  $sender_email = null;
1838
  $sender_nickname = null;
1839
- $message = '';
1840
  $subject = '';
1841
- foreach ($_POST as $k => $v) {
1842
- if(is_array($v))
1843
- {
1844
  continue;
1845
  }
1846
- if ($sender_email === null && preg_match("/^\S+@\S+\.\S+$/", $v)) {
1847
  $sender_email = $v;
1848
- }
1849
- else if ($sender_nickname === null && preg_match("/-name$/", $k)) {
1850
  $sender_nickname = $v;
1851
- }
1852
- else if ($subject === '' && ct_get_data_from_submit($k, 'subject')) {
1853
  $subject = $v;
 
 
1854
  }
1855
- else if (preg_match("/(\-message|\w*message\w*|contact|comment|contact\-)$/", $k))
1856
- {
1857
- $message.= $v."\n";
1858
- }
1859
-
1860
  }
1861
-
1862
- if ($subject != '') {
1863
- if ($message != '') {
1864
- $message = "\n\n" . $message;
1865
- }
1866
- $message = sprintf("%s%s", $subject, $message);
1867
- }
1868
-
1869
- $ct_base_call_result = ct_base_call(array(
1870
- 'submit_time' => apbct_get_submit_time(),
1871
- 'message' => $message,
1872
- 'example' => null,
1873
- 'sender_email' => $sender_email,
1874
- 'sender_nickname' => $sender_nickname,
1875
- 'post_info' => $post_info,
1876
- 'checkjs' => $checkjs
1877
- ), true, true);
1878
- $ct = $ct_base_call_result['ct'];
1879
- $ct_result = $ct_base_call_result['ct_result'];
1880
 
1881
  if ($ct_result->allow == 0) {
1882
 
@@ -1924,53 +1707,40 @@ function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
1924
  $ct_data = ct_get_data();
1925
 
1926
  if (!empty($form_errors))
1927
- return $form_errors;
1928
 
1929
  if ($ct_options['contact_forms_test'] == 0)
1930
- return $form_errors;
1931
 
1932
  // Skip processing because data already processed.
1933
  if ($cleantalk_executed) {
1934
  return $form_errors;
1935
  }
1936
-
1937
-
1938
- $sender_info='';
1939
-
1940
- $checkjs = js_test('ct_checkjs', $_POST, true);
1941
-
1942
- $post_info['comment_type'] = 'feedback';
1943
- $post_info = json_encode($post_info);
1944
- if ($post_info === false)
1945
- $post_info = '';
1946
-
1947
  //getting info from custom fields
1948
  $ct_temp_msg_data = ct_get_fields_any($_POST);
1949
 
1950
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
1951
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
1952
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
1953
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
1954
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1955
 
1956
- //setting fields if they with defaults names
1957
- if ($subject != '') {
1958
- $message = array_merge(array('subject' => $subject), $message);
1959
- }
1960
- $message = json_encode($message);
1961
-
1962
-
1963
- $ct_base_call_result = ct_base_call(array(
1964
- 'message' => $message,
1965
- 'example' => null,
1966
- 'sender_email' => $sender_email,
1967
- 'sender_nickname' => $sender_nickname,
1968
- 'post_info' => $post_info,
1969
- 'sender_info' => $sender_info,
1970
- 'checkjs' => $checkjs
1971
- ));
1972
- $ct = $ct_base_call_result['ct'];
1973
- $ct_result = $ct_base_call_result['ct_result'];
1974
 
1975
  $cleantalk_executed = true;
1976
 
@@ -2007,17 +1777,17 @@ function ct_comment_text($comment_text) {
2007
  * Checks WordPress Landing Pages raw $_POST values
2008
  */
2009
  function ct_check_wplp(){
 
2010
  global $ct_wplp_result_label, $ct_options, $ct_data;
2011
 
2012
  $ct_options = ct_get_options();
2013
  $ct_data = ct_get_data();
 
2014
  if (!isset($_COOKIE[$ct_wplp_result_label])) {
2015
  // First AJAX submit of WPLP form
2016
  if ($ct_options['contact_forms_test'] == 0)
2017
  return;
2018
-
2019
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
2020
-
2021
  $post_info['comment_type'] = 'feedback';
2022
  $post_info = json_encode($post_info);
2023
  if ($post_info === false)
@@ -2040,16 +1810,15 @@ function ct_check_wplp(){
2040
  $message = $_POST['null'];
2041
  }
2042
 
2043
- $ct_base_call_result = ct_base_call(array(
2044
- 'message' => $message,
2045
- 'example' => null,
2046
  'sender_email' => $sender_email,
2047
- 'sender_nickname' => null,
2048
- 'post_info' => $post_info,
2049
- 'checkjs' => $checkjs
2050
- ));
2051
- $ct = $ct_base_call_result['ct'];
2052
- $ct_result = $ct_base_call_result['ct_result'];
2053
 
2054
  if ($ct_result->allow == 0) {
2055
  $cleantalk_comment = $ct_result->comment;
@@ -2111,18 +1880,6 @@ function ct_gforms_spam_test ($is_spam, $form, $entry) {
2111
  if ($cleantalk_executed)
2112
  return $is_spam;
2113
 
2114
- $sender_info='';
2115
-
2116
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
2117
- if (!$checkjs) {
2118
- $checkjs = js_test('ct_checkjs', $_POST, true);
2119
- }
2120
-
2121
- $post_info['comment_type'] = 'feedback_gravity';
2122
- $post_info = json_encode($post_info);
2123
- if ($post_info === false)
2124
- $post_info = '';
2125
-
2126
  $ct_temp = array();
2127
  foreach($entry as $key => $value){
2128
  if(is_numeric($key))
@@ -2131,27 +1888,29 @@ function ct_gforms_spam_test ($is_spam, $form, $entry) {
2131
 
2132
  $ct_temp_msg_data = ct_get_fields_any($ct_temp);
2133
 
2134
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2135
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
2136
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2137
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
2138
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2139
-
2140
- if ($subject != '') {
2141
- $message = array_merge(array('subject' => $subject), $message);
2142
- }
2143
- $message = json_encode($message);
2144
-
2145
- $ct_base_call_result = ct_base_call(array(
2146
- 'message' => $message,
2147
- 'example' => null,
2148
- 'sender_email' => $sender_email,
2149
- 'sender_nickname' => $sender_nickname,
2150
- 'post_info' => $post_info,
2151
- 'sender_info' => $sender_info,
2152
- 'checkjs' => $checkjs
2153
- ));
2154
- $ct_result = $ct_base_call_result['ct_result'];
 
 
2155
 
2156
  if ($ct_result->allow == 0) {
2157
  $is_spam = true;
@@ -2166,90 +1925,38 @@ function ct_gforms_spam_test ($is_spam, $form, $entry) {
2166
  * @return array with errors
2167
  */
2168
  function ct_s2member_registration_test() {
2169
- global $ct_agent_version, $ct_post_data_label, $ct_post_data_authnet_label, $ct_options, $ct_data;
2170
 
2171
  $ct_options = ct_get_options();
2172
- $ct_data = ct_get_data();
2173
 
2174
  if ($ct_options['registrations_test'] == 0) {
2175
  return null;
2176
  }
2177
-
2178
- $submit_time = apbct_get_submit_time();
2179
-
2180
- $sender_info = get_sender_info(true);
2181
-
2182
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
2183
-
2184
- require_once('cleantalk.class.php');
2185
-
2186
- $sender_info = json_encode($sender_info);
2187
- if ($sender_info === false) {
2188
- $sender_info= '';
2189
- }
2190
-
2191
  $sender_email = null;
2192
  if (isset($_POST[$ct_post_data_label]['email']))
2193
  $sender_email = $_POST[$ct_post_data_label]['email'];
2194
-
2195
  if (isset($_POST[$ct_post_data_authnet_label]['email']))
2196
  $sender_email = $_POST[$ct_post_data_authnet_label]['email'];
2197
 
2198
  $sender_nickname = null;
2199
  if (isset($_POST[$ct_post_data_label]['username']))
2200
  $sender_nickname = $_POST[$ct_post_data_label]['username'];
2201
-
2202
  if (isset($_POST[$ct_post_data_authnet_label]['username']))
2203
  $sender_nickname = $_POST[$ct_post_data_authnet_label]['username'];
2204
 
2205
- $config = ct_get_server();
2206
-
2207
- $ct = new Cleantalk();
2208
- $ct->work_url = $config['ct_work_url'];
2209
- $ct->server_url = $ct_options['server'];
2210
- $ct->server_ttl = $config['ct_server_ttl'];
2211
- $ct->server_changed = $config['ct_server_changed'];
2212
- $ct->ssl_on = $ct_options['ssl_on'];
2213
-
2214
- $ct_request = new CleantalkRequest();
2215
-
2216
- $ct_request->auth_key = $ct_options['apikey'];
2217
- $ct_request->sender_email = $sender_email;
2218
- $ct_request->sender_ip = cleantalk_get_real_ip();
2219
- $ct_request->sender_nickname = $sender_nickname;
2220
- $ct_request->agent = $ct_agent_version;
2221
- $ct_request->sender_info = $sender_info;
2222
- $ct_request->js_on = $checkjs;
2223
- $ct_request->submit_time = $submit_time;
2224
-
2225
- $ct_result = $ct->isAllowUser($ct_request);
2226
- if ($ct_result->errno === 0 && empty($ct_result->errstr))
2227
- $ct_data['connection_reports']['success']++;
2228
- else
2229
- {
2230
- $ct_data['connection_reports']['negative']++;
2231
- $ct_data['connection_reports']['negative_report'][] = array('date'=>date("Y-m-d H:i:s"),'page_url'=>$_SERVER['REQUEST_URI'],'lib_report'=>$ct_result->errstr);
2232
- }
2233
- update_option('cleantalk_data', $ct_data);
2234
- if ($ct->server_change) {
2235
- update_option(
2236
- 'cleantalk_server', array(
2237
- 'ct_work_url' => $ct->work_url,
2238
- 'ct_server_ttl' => $ct->server_ttl,
2239
- 'ct_server_changed' => time()
2240
- )
2241
- );
2242
- }
2243
-
2244
- $ct_result = ct_change_plugin_resonse($ct_result, $checkjs);
2245
-
2246
- ct_add_event($ct_result->allow);
2247
-
2248
- // Restart submit form counter for failed requests
2249
- if ($ct_result->allow == 0) {
2250
- apbct_cookie(); // Setting page timer and cookies
2251
- }
2252
-
2253
  if ($ct_result->allow == 0) {
2254
  ct_die_extended($ct_result->comment);
2255
  }
@@ -2311,11 +2018,7 @@ function ct_contact_form_validate() {
2311
  // Do not execute anti-spam test for logged in users.
2312
  if (isset($_COOKIE[LOGGED_IN_COOKIE]) && $ct_options['protect_logged_in'] != 1)
2313
  return null;
2314
-
2315
- $_POST=ct_filter_array($_POST);
2316
-
2317
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
2318
-
2319
  $post_info['comment_type'] = 'feedback_general_contact_form';
2320
 
2321
  // Skip the test if it's WooCommerce and the checkout test unset
@@ -2329,11 +2032,6 @@ function ct_contact_form_validate() {
2329
  }
2330
  }
2331
 
2332
- $post_info = json_encode($post_info);
2333
- if ($post_info === false) {
2334
- $post_info = '';
2335
- }
2336
-
2337
  $ct_temp_msg_data = ct_get_fields_any($_POST);
2338
 
2339
  $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
@@ -2341,42 +2039,35 @@ function ct_contact_form_validate() {
2341
  $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2342
  $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
2343
  $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2344
-
2345
  if ($subject != '') {
2346
  $message = array_merge(array('subject' => $subject), $message);
2347
  }
2348
- $message = json_encode($message);
2349
 
2350
  // Skip submission if no data found
2351
- if ($sender_email===''|| !$contact_form) {
2352
  return false;
2353
  }
2354
  $cleantalk_executed=true;
2355
 
2356
- if(isset($_POST['TellAFriend_Link']))
2357
- {
2358
- $tmp=$_POST['TellAFriend_Link'];
2359
  unset($_POST['TellAFriend_Link']);
2360
  }
2361
 
2362
- $ct_base_call_result = ct_base_call(array(
2363
- 'submit_time' => apbct_get_submit_time(),
2364
- 'message' => $message,
2365
- 'example' => null,
2366
- 'sender_email' => $sender_email,
2367
- 'sender_nickname' => $sender_nickname,
2368
- 'post_info' => $post_info,
2369
- 'sender_info' => get_sender_info(),
2370
- 'checkjs' => $checkjs
2371
- ), true, true);
2372
 
2373
- if(isset($_POST['TellAFriend_Link']))
2374
- {
2375
  $_POST['TellAFriend_Link']=$tmp;
2376
  }
2377
-
2378
- $ct = $ct_base_call_result['ct'];
2379
- $ct_result = $ct_base_call_result['ct_result'];
2380
  if ($ct_result->allow == 0) {
2381
 
2382
  // Recognize contact form an set it's name to $contact_form to use later
@@ -2511,53 +2202,34 @@ function ct_contact_form_validate_postdata() {
2511
  ) {
2512
  return null;
2513
  }
2514
-
2515
- $_POST=ct_filter_array($_POST);
2516
-
2517
- $checkjs = js_test('ct_checkjs', $_COOKIE, true);
2518
-
2519
- $post_info['comment_type'] = 'feedback_general_postdata';
2520
- $post_info = json_encode($post_info);
2521
- if ($post_info === false) {
2522
- $post_info = '';
2523
- }
2524
-
2525
  $message = ct_get_fields_any_postdata($_POST);
2526
 
2527
- $message = json_encode($message);
 
 
2528
 
2529
- if(strlen(trim($message))<10)
2530
- {
2531
- return null;
2532
- }
2533
  $skip_params = array(
2534
- 'ipn_track_id', // PayPal IPN #
2535
- 'txn_type', // PayPal transaction type
2536
  'payment_status', // PayPal payment status
2537
  );
2538
-
2539
- foreach($skip_params as $key=>$value)
2540
- {
2541
  if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST))
2542
- {
2543
  return null;
2544
- }
2545
  }
2546
 
2547
- $ct_base_call_result = ct_base_call(array(
2548
- 'message' => $message,
2549
- 'example' => null,
2550
- 'sender_email' => '',
2551
- 'sender_nickname' => '',
2552
- 'post_info' => $post_info,
2553
- 'sender_info' => get_sender_info(),
2554
- 'checkjs' => $checkjs
2555
- ));
2556
 
2557
  $cleantalk_executed=true;
2558
 
2559
- $ct = $ct_base_call_result['ct'];
2560
- $ct_result = $ct_base_call_result['ct_result'];
2561
 
2562
  if ($ct_result->allow == 0) {
2563
 
308
 
309
  unset($ct_global_temporary_data);
310
 
311
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
312
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
313
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
314
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
315
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
316
 
317
  if ($subject != '')
318
+ $message['subject'] = $subject;
 
319
 
320
+ $post_info['comment_type'] = 'feedback_custom_contact_forms';
321
+ $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
 
 
 
322
 
323
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
324
+ ? js_test('ct_checkjs', $_COOKIE, true)
325
+ : js_test('ct_checkjs', $_POST, true);
326
 
 
 
 
 
327
  //Making a call
328
+ $base_call_result = apbct_base_call(
329
+ array(
330
+ 'message' => $subject." ".$message,
331
+ 'sender_email' => $sender_email,
332
+ 'sender_nickname' => $sender_nickname,
333
+ 'post_info' => $post_info,
334
+ 'checkjs' => $checkjs,
335
+ 'sender_info' => array('sender_url' => null),
336
+ )
337
+ );
338
+
339
+ $ct_result = $base_call_result['ct_result'];
340
 
341
+ return $ct_result->allow == 0 ? $ct_result->comment : true;;
 
 
 
342
  }
343
 
344
  function ct_woocommerce_wishlist_check($args){
367
 
368
  $post_info['comment_type'] = 'feedback';
369
  $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
 
 
 
 
 
 
 
 
 
 
 
370
 
371
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
372
+ ? js_test('ct_checkjs', $_COOKIE, true)
373
+ : js_test('ct_checkjs', $_POST, true);
374
+
375
  //Making a call
376
+ $base_call_result = apbct_base_call(
377
+ array(
378
+ 'message' => $subject." ".$message,
379
+ 'sender_email' => $email,
380
+ 'sender_nickname' => $nickname,
381
+ 'post_info' => $post_info,
382
+ 'checkjs' => $checkjs,
383
+ 'sender_info' => array('sender_url' => null),
384
+ )
385
+ );
386
+
387
+ $ct_result = $base_call_result['ct_result'];
388
 
389
  if ($ct_result->allow == 0)
390
  wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
451
 
452
  $post_info['comment_type'] = 'buddypress_comment';
453
  $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
 
 
 
 
 
 
 
454
 
455
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
456
+ ? js_test('ct_checkjs', $_COOKIE, true)
457
+ : js_test('ct_checkjs', $_POST, true);
458
 
459
  //Making a call
460
 
461
+ $base_call_result = apbct_base_call(
462
+ array(
463
+ 'message' => $subject." ".$message,
464
+ 'sender_email' => $email,
465
+ 'sender_nickname' => $nickname,
466
+ 'post_info' => $post_info,
467
+ 'checkjs' => $checkjs,
468
+ 'sender_info' => array('sender_url' => null),
469
+ )
470
+ );
471
+ $ct_result = $base_call_result['ct_result'];
 
472
 
473
  if ($ct_result->allow == 0)
474
  wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
486
  //Check for enabled option
487
  if($ct_options['contact_forms_test'] == 0)
488
  return;
 
 
489
 
490
  //Getting request params
 
491
  $ct_temp_msg_data = ct_get_fields_any($_POST);
492
 
493
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
494
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
495
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
496
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
497
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
498
 
499
  if($subject != '')
500
  $message = array_merge(array('subject' => $subject), $message);
501
 
 
 
502
  $post_info['comment_type'] = 'feedback_pirate_contact_form';
503
  $post_info['post_url'] = $_SERVER['HTTP_REFERER'];
 
 
 
 
 
 
 
 
 
504
 
505
  //Making a call
506
+ $base_call_result = apbct_base_call(
507
+ array(
508
+ 'message' => $message,
509
+ 'sender_email' => $sender_email,
510
+ 'sender_nickname' => $sender_nickname,
511
+ 'post_info' => $post_info,
512
+ 'checkjs' => js_test('ct_checkjs', $_COOKIE, true),
513
+ 'sender_info' => array('sender_url' => null),
514
+ )
515
+ );
516
 
517
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
 
 
 
 
 
 
518
 
519
  if ($ct_result->allow == 0)
520
  wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
678
  if ($ct_options['protect_logged_in'] != 1 && is_user_logged_in()) {
679
  return $errors;
680
  }
681
+
 
 
 
 
 
 
 
 
 
 
682
  $ct_temp_msg_data = ct_get_fields_any($values['item_meta']);
683
 
684
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
685
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
686
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
687
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
688
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
689
+
690
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
691
+ ? js_test('ct_checkjs', $_COOKIE, true)
692
+ : js_test('ct_checkjs', $_POST, true);
693
+
694
+ $base_call_result = apbct_base_call(
695
+ array(
696
+ 'message' => $message,
697
+ 'sender_email' => $sender_email,
698
+ 'sender_nickname' => $sender_nickname,
699
+ 'post_info' => array('comment_type' => 'feedback'),
700
+ 'checkjs' => $checkjs
701
+ )
702
+ );
703
+ $ct_result = $base_call_result['ct_result'];
704
 
705
  if ($ct_result->allow == 0) {
706
  $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
741
  if ($ct_options['protect_logged_in'] != 1 && is_user_logged_in() ||
742
  in_array("administrator", $current_user->roles))
743
  return $comment;
 
 
 
 
 
 
 
744
 
745
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
746
+ ? js_test('ct_checkjs', $_COOKIE, true)
747
+ : js_test('ct_checkjs', $_POST, true);
748
+
749
  $post_info['comment_type'] = 'bbpress_comment';
750
  $post_info['post_url'] = bbp_get_topic_permalink();
 
 
 
 
 
751
 
752
  if(isset($ct_bbp_topic))
753
  $message = $ct_bbp_topic." ".$comment;
754
  else
755
  $message = $comment;
756
 
757
+ $base_call_result = apbct_base_call(
758
+ array(
759
+ 'message' => $comment,
760
+ 'sender_email' => isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null,
761
+ 'sender_nickname' => isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null,
762
+ 'post_info' => $post_info,
763
+ 'checkjs' => $checkjs,
764
+ 'sender_info' => array('sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null),
765
+ )
766
+ );
767
+ $ct_result = $base_call_result['ct_result'];
768
 
769
  if ($ct_result->allow == 0) {
770
  bbp_add_error('bbp_reply_content', $ct_result->comment);
791
  if (in_array("administrator", $current_user->roles))
792
  return $comment;
793
 
794
+ $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3;
795
+ $value = isset($ct_options['check_comments_number']) ? intval($ct_options['check_comments_number']) : 1;
 
 
 
 
 
 
 
 
796
 
797
  if($value == 1){
798
+ $args = array(
799
+ 'author_email' => $comment['comment_author_email'],
800
+ 'status' => 'approve',
801
+ 'count' => false,
802
+ 'number' => $comments_check_number,
803
+ );
804
+ $cnt = count(get_comments($args));
805
+ $is_max_comments = $cnt >= $comments_check_number ? true : false;
806
+ }
807
+
808
+ if (
809
+ ($comment['comment_type']!='trackback') &&
810
+ (
811
+ ct_is_user_enable() === false ||
812
+ $ct_options['comments_test'] == 0 ||
813
+ $ct_comment_done ||
814
+ (isset($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'],'page=wysija_campaigns&action=editTemplate')!==false) ||
815
+ (isset($is_max_comments) && $is_max_comments) ||
816
+ strpos($_SERVER['REQUEST_URI'],'/wp-admin/')!==false)
817
+ )
818
+ {
819
  return $comment;
820
  }
821
 
841
  $ct_comment_done = true;
842
 
843
  $comment_post_id = $comment['comment_post_ID'];
844
+
 
 
 
 
 
845
  // JetPack comments logic
846
+ $post_info['comment_type'] = $ct_jp_comments ? 'jetpack_comment' : $comment['comment_type'];
847
+ $post_info['post_url'] = ct_post_url(null, $comment_post_id);
848
+
849
+ // Comment type
850
+ $post_info['comment_type'] = empty($post_info['comment_type']) ? 'general_comment' : $post_info['comment_type'];
851
+
852
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
853
+ ? js_test('ct_checkjs', $_COOKIE, true)
854
+ : js_test('ct_checkjs', $_POST, true);
 
 
 
 
 
 
 
 
855
 
 
 
 
 
 
856
 
857
  $example = null;
858
  if ($ct_options['relevance_test']) {
877
  }
878
  }
879
 
880
+ $base_call_result = apbct_base_call(
881
+ array(
882
+ 'message' => $comment['comment_content'],
883
+ 'example' => $example,
884
+ 'sender_email' => $comment['comment_author_email'],
885
+ 'sender_nickname' => $comment['comment_author'],
886
+ 'post_info' => $post_info,
887
+ 'checkjs' => $checkjs,
888
+ 'sender_info' => array('sender_url' => @$comment['comment_author_url']),
889
+ )
890
+ );
891
+ $ct_result = $base_call_result['ct_result'];
892
 
893
  ct_hash($ct_result->id);
894
 
1241
  */
1242
 
1243
  function ct_test_message($nickname, $email, $ip, $text){
1244
+
1245
+ $base_call_result = apbct_base_call(
1246
+ array(
1247
+ 'message' => $text,
1248
+ 'sender_email' => $email,
1249
+ 'sender_nickname' => $nickname,
1250
+ 'post_info' => array('comment_type' => 'feedback_plugin_check'),
1251
+ 'checkjs' => js_test('ct_checkjs', $_COOKIE, true),
1252
+ )
1253
+ );
 
 
 
 
1254
 
1255
+ $ct_result = $base_call_result['ct_result'];
1256
 
1257
  $result=Array(
1258
  'allow' => $ct_result->allow,
1266
  * @return array with checking result;
1267
  */
1268
  function ct_test_registration($nickname, $email, $ip){
1269
+ global $ct_checkjs_register_form, $ct_options;
1270
 
1271
  $ct_options = ct_get_options();
 
 
 
1272
 
 
 
 
 
1273
  $checkjs = js_test($ct_checkjs_register_form, $_POST, true);
1274
  $sender_info['post_checkjs_passed'] = $checkjs;
1275
+ // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1276
+ if (!$checkjs) {
 
 
 
1277
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1278
  $sender_info['cookie_checkjs_passed'] = $checkjs;
1279
  }
1280
+
1281
+ //Making a call
1282
+ $base_call_result = apbct_base_call(
1283
+ array(
1284
+ 'sender_ip' => $ip,
1285
+ 'sender_email' => $email,
1286
+ 'sender_nickname' => $nickname,
1287
+ 'sender_info' => $sender_info,
1288
+ 'checkjs' => $checkjs,
1289
+ ),
1290
+ true
1291
+ );
1292
+ $ct_result = $base_call_result['ct_result'];
1293
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1294
  $result=Array(
1295
  'allow' => $ct_result->allow,
1296
  'comment' => $ct_result->comment,
1355
  }
1356
  return $errors;
1357
  }
1358
+
 
 
 
 
 
 
1359
  $checkjs = js_test($ct_checkjs_register_form, $_POST, true);
1360
  $sender_info['post_checkjs_passed'] = $checkjs;
 
1361
  // This hack can be helpfull when plugin uses with untested themes&signups plugins.
 
1362
  if ($checkjs == 0) {
1363
  $checkjs = js_test('ct_checkjs', $_COOKIE, true);
1364
  $sender_info['cookie_checkjs_passed'] = $checkjs;
1365
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1366
 
1367
+ $base_call_result = apbct_base_call(
1368
+ array(
1369
+ 'sender_email' => $user_email,
1370
+ 'sender_nickname' => $sanitized_user_login,
1371
+ 'sender_info' => $sender_info,
1372
+ 'checkjs' => $checkjs,
1373
+ ),
1374
+ true
1375
+ );
1376
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1377
 
1378
  $ct_signup_done = true;
1379
 
1385
  }
1386
 
1387
  if ($ct_result->allow == 0) {
1388
+
 
 
1389
  if ($buddypress === true) {
1390
  $bp->signup->errors['signup_username'] = $ct_result->comment;
1391
  }elseif(!empty($facebook)){
1406
  setcookie($apbct_cookie_request_id_label, $ct_result->id, time()+10, '/');
1407
  }
1408
  }
1409
+
 
 
1410
  return $errors;
1411
  }
1412
 
1495
  $js_field_name = $k;
1496
  }
1497
 
 
 
 
 
 
 
 
 
 
 
 
1498
  $sender_email = null;
1499
  $sender_nickname = null;
1500
  $message = '';
1507
  if (isset($form['comment_content']))
1508
  $message = $form['comment_content'];
1509
 
1510
+ $base_call_result = apbct_base_call(
1511
+ array(
1512
+ 'message' => $message,
1513
+ 'sender_email' => $sender_email,
1514
+ 'sender_nickname' => $sender_nickname,
1515
+ 'post_info' => array('comment_type' => 'feedback'),
1516
+ 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1517
+ 'checkjs' => js_test($js_field_name, $_POST, true),
1518
+ )
1519
+ );
1520
+ $ct_result = $base_call_result['ct_result'];
1521
 
1522
  if ($ct_result->allow == 0) {
1523
  global $ct_comment;
1545
  $js_field_name = $k;
1546
  }
1547
 
 
 
 
 
 
 
 
 
 
 
 
1548
  $sender_email = null;
1549
  $sender_nickname = null;
1550
  $message = '';
1557
  if (isset($form['comment_content']))
1558
  $message = $form['comment_content'];
1559
 
1560
+ $base_call_result = apbct_base_call(
1561
+ array(
1562
+ 'message' => $message,
1563
+ 'sender_email' => $sender_email,
1564
+ 'sender_nickname' => $sender_nickname,
1565
+ 'post_info' => array('comment_type' => 'feedback'),
1566
+ 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1567
+ )
1568
+ );
1569
+ $ct_result = $base_call_result['ct_result'];
 
1570
 
1571
  if ($ct_result->allow == 0) {
1572
  global $ct_comment;
1624
  return $param;
1625
  }
1626
 
1627
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
1628
+ ? js_test('ct_checkjs', $_COOKIE, true)
1629
+ : js_test($ct_checkjs_cf7, $_POST, true);
1630
+
 
 
 
 
 
 
1631
  $sender_email = null;
1632
  $sender_nickname = null;
1633
+ $message = array();
1634
  $subject = '';
1635
+ foreach ($_POST as $k => $v){
1636
+ if(is_array($v)){
 
1637
  continue;
1638
  }
1639
+ if ($sender_email === null && preg_match("/^\S+@\S+\.\S+$/", $v)){
1640
  $sender_email = $v;
1641
+ }else if ($sender_nickname === null && preg_match("/-name$/", $k)){
 
1642
  $sender_nickname = $v;
1643
+ }else if ($subject === '' && ct_get_data_from_submit($k, 'subject')){
 
1644
  $subject = $v;
1645
+ }else if (preg_match("/(\-message|\w*message\w*|contact|comment|contact\-)$/", $k)){
1646
+ $message[$k]= $v;
1647
  }
 
 
 
 
 
1648
  }
1649
+ if($subject != ''){
1650
+ $message['subject'] = $subject;
1651
+ }
1652
+
1653
+ $base_call_result = apbct_base_call(
1654
+ array(
1655
+ 'message' => $message,
1656
+ 'sender_email' => $sender_email,
1657
+ 'sender_nickname' => $sender_nickname,
1658
+ 'post_info' => array('comment_type' => 'feedback'),
1659
+ 'checkjs' => $checkjs,
1660
+ )
1661
+ );
1662
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
1663
 
1664
  if ($ct_result->allow == 0) {
1665
 
1707
  $ct_data = ct_get_data();
1708
 
1709
  if (!empty($form_errors))
1710
+ return $form_errors;
1711
 
1712
  if ($ct_options['contact_forms_test'] == 0)
1713
+ return $form_errors;
1714
 
1715
  // Skip processing because data already processed.
1716
  if ($cleantalk_executed) {
1717
  return $form_errors;
1718
  }
1719
+
 
 
 
 
 
 
 
 
 
 
1720
  //getting info from custom fields
1721
  $ct_temp_msg_data = ct_get_fields_any($_POST);
1722
 
1723
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
1724
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
1725
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
1726
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
1727
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
1728
+ if($subject != '') {
1729
+ $message['subject'] = $subject;
1730
+ }
1731
+
1732
+ $base_call_result = apbct_base_call(
1733
+ array(
1734
+ 'message' => $message,
1735
+ 'sender_email' => $sender_email,
1736
+ 'sender_nickname' => $sender_nickname,
1737
+ 'post_info' => array('comment_type' => 'feedback'),
1738
+ 'sender_info' => $sender_info,
1739
+ 'checkjs' => js_test('ct_checkjs', $_POST, true),
1740
+ )
1741
+ );
1742
 
1743
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1744
 
1745
  $cleantalk_executed = true;
1746
 
1777
  * Checks WordPress Landing Pages raw $_POST values
1778
  */
1779
  function ct_check_wplp(){
1780
+
1781
  global $ct_wplp_result_label, $ct_options, $ct_data;
1782
 
1783
  $ct_options = ct_get_options();
1784
  $ct_data = ct_get_data();
1785
+
1786
  if (!isset($_COOKIE[$ct_wplp_result_label])) {
1787
  // First AJAX submit of WPLP form
1788
  if ($ct_options['contact_forms_test'] == 0)
1789
  return;
1790
+
 
 
1791
  $post_info['comment_type'] = 'feedback';
1792
  $post_info = json_encode($post_info);
1793
  if ($post_info === false)
1810
  $message = $_POST['null'];
1811
  }
1812
 
1813
+ $base_call_result = apbct_base_call(
1814
+ array(
1815
+ 'message' => $message,
1816
  'sender_email' => $sender_email,
1817
+ 'post_info' => array('comment_type' => 'feedback'),
1818
+ )
1819
+ );
1820
+
1821
+ $ct_result = $base_call_result['ct_result'];
 
1822
 
1823
  if ($ct_result->allow == 0) {
1824
  $cleantalk_comment = $ct_result->comment;
1880
  if ($cleantalk_executed)
1881
  return $is_spam;
1882
 
 
 
 
 
 
 
 
 
 
 
 
 
1883
  $ct_temp = array();
1884
  foreach($entry as $key => $value){
1885
  if(is_numeric($key))
1888
 
1889
  $ct_temp_msg_data = ct_get_fields_any($ct_temp);
1890
 
1891
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
1892
  $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
1893
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
1894
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
1895
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
1896
+ if($subject != '') {
1897
+ $message['subject'] = $subject;
1898
+ }
1899
+
1900
+ $checkjs = !js_test('ct_checkjs', $_COOKIE, true)
1901
+ ? js_test('ct_checkjs', $_COOKIE, true)
1902
+ : js_test('ct_checkjs', $_POST, true);
1903
+
1904
+ $base_call_result = apbct_base_call(
1905
+ array(
1906
+ 'message' => $message,
1907
+ 'sender_email' => $sender_email,
1908
+ 'sender_nickname' => $sender_nickname,
1909
+ 'post_info' => array('comment_type' => 'feedback_gravity'),
1910
+ 'checkjs' => $checkjs,
1911
+ )
1912
+ );
1913
+ $ct_result = $base_call_result['ct_result'];
1914
 
1915
  if ($ct_result->allow == 0) {
1916
  $is_spam = true;
1925
  * @return array with errors
1926
  */
1927
  function ct_s2member_registration_test() {
1928
+ global $ct_post_data_label, $ct_post_data_authnet_label, $ct_options;
1929
 
1930
  $ct_options = ct_get_options();
 
1931
 
1932
  if ($ct_options['registrations_test'] == 0) {
1933
  return null;
1934
  }
1935
+
 
 
 
 
 
 
 
 
 
 
 
 
 
1936
  $sender_email = null;
1937
  if (isset($_POST[$ct_post_data_label]['email']))
1938
  $sender_email = $_POST[$ct_post_data_label]['email'];
 
1939
  if (isset($_POST[$ct_post_data_authnet_label]['email']))
1940
  $sender_email = $_POST[$ct_post_data_authnet_label]['email'];
1941
 
1942
  $sender_nickname = null;
1943
  if (isset($_POST[$ct_post_data_label]['username']))
1944
  $sender_nickname = $_POST[$ct_post_data_label]['username'];
 
1945
  if (isset($_POST[$ct_post_data_authnet_label]['username']))
1946
  $sender_nickname = $_POST[$ct_post_data_authnet_label]['username'];
1947
 
1948
+ //Making a call
1949
+ $base_call_result = apbct_base_call(
1950
+ array(
1951
+ 'sender_email' => sanitize_email($_POST['email']),
1952
+ 'sender_nickname' => sanitize_email($_POST['login']),
1953
+ 'sender_info' => $sender_info,
1954
+ 'checkjs' => $checkjs,
1955
+ ),
1956
+ true
1957
+ );
1958
+ $ct_result = $base_call_result['ct_result'];
1959
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1960
  if ($ct_result->allow == 0) {
1961
  ct_die_extended($ct_result->comment);
1962
  }
2018
  // Do not execute anti-spam test for logged in users.
2019
  if (isset($_COOKIE[LOGGED_IN_COOKIE]) && $ct_options['protect_logged_in'] != 1)
2020
  return null;
2021
+
 
 
 
 
2022
  $post_info['comment_type'] = 'feedback_general_contact_form';
2023
 
2024
  // Skip the test if it's WooCommerce and the checkout test unset
2032
  }
2033
  }
2034
 
 
 
 
 
 
2035
  $ct_temp_msg_data = ct_get_fields_any($_POST);
2036
 
2037
  $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2039
  $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2040
  $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
2041
  $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
 
2042
  if ($subject != '') {
2043
  $message = array_merge(array('subject' => $subject), $message);
2044
  }
 
2045
 
2046
  // Skip submission if no data found
2047
+ if ($sender_email === ''|| !$contact_form) {
2048
  return false;
2049
  }
2050
  $cleantalk_executed=true;
2051
 
2052
+ if(isset($_POST['TellAFriend_Link'])){
2053
+ $tmp = $_POST['TellAFriend_Link'];
 
2054
  unset($_POST['TellAFriend_Link']);
2055
  }
2056
 
2057
+ $base_call_result = apbct_base_call(
2058
+ array(
2059
+ 'message' => $message,
2060
+ 'sender_email' => $sender_email,
2061
+ 'sender_nickname' => $sender_nickname,
2062
+ 'post_info' => $post_info,
2063
+ )
2064
+ );
 
 
2065
 
2066
+ if(isset($_POST['TellAFriend_Link'])){
 
2067
  $_POST['TellAFriend_Link']=$tmp;
2068
  }
2069
+
2070
+ $ct_result = $base_call_result['ct_result'];
 
2071
  if ($ct_result->allow == 0) {
2072
 
2073
  // Recognize contact form an set it's name to $contact_form to use later
2202
  ) {
2203
  return null;
2204
  }
2205
+
 
 
 
 
 
 
 
 
 
 
2206
  $message = ct_get_fields_any_postdata($_POST);
2207
 
2208
+ // ???
2209
+ if(strlen(json_encode($message))<10)
2210
+ return null;
2211
 
2212
+ // Skip if request contains params
 
 
 
2213
  $skip_params = array(
2214
+ 'ipn_track_id', // PayPal IPN #
2215
+ 'txn_type', // PayPal transaction type
2216
  'payment_status', // PayPal payment status
2217
  );
2218
+ foreach($skip_params as $key=>$value){
 
 
2219
  if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST))
 
2220
  return null;
 
2221
  }
2222
 
2223
+ $base_call_result = apbct_base_call(
2224
+ array(
2225
+ 'message' => $message,
2226
+ 'post_info' => array('comment_type' => 'feedback_general_postdata'),
2227
+ )
2228
+ );
 
 
 
2229
 
2230
  $cleantalk_executed=true;
2231
 
2232
+ $ct_result = $base_call_result['ct_result'];
 
2233
 
2234
  if ($ct_result->allow == 0) {
2235
 
inc/cleantalk.class.php CHANGED
@@ -429,7 +429,7 @@ class Cleantalk {
429
  *
430
  */
431
  public $min_server_timeout = 50;
432
-
433
  /**
434
  * Function checks whether it is possible to publish the message
435
  * @param CleantalkRequest $request
@@ -470,39 +470,24 @@ class Cleantalk {
470
  * @return type
471
  */
472
  private function filterRequest(CleantalkRequest $request) {
 
473
  // general and optional
474
  foreach ($request as $param => $value) {
475
- if (in_array($param, array('message', 'example', 'agent',
476
- 'sender_info', 'sender_nickname', 'post_info', 'phone')) && !empty($value)) {
477
- if (!is_string($value) && !is_integer($value)) {
478
- $request->$param = NULL;
479
- }
480
- }
481
-
482
- if (in_array($param, array('js_on')) && !empty($value)) {
483
- if (!is_integer($value)) {
484
- $request->$param = NULL;
485
- }
486
- }
487
-
488
- if ($param == 'sender_ip' && !empty($value)) {
489
- if (!is_string($value)) {
490
- $request->$param = NULL;
491
- }
492
- }
493
-
494
- if ($param == 'sender_email' && !empty($value)) {
495
- if (!is_string($value)) {
496
- $request->$param = NULL;
497
- }
498
- }
499
-
500
- if ($param == 'submit_time' && !empty($value)) {
501
- if (!is_int($value)) {
502
- $request->$param = NULL;
503
- }
504
- }
505
  }
 
506
  return $request;
507
  }
508
 
@@ -538,21 +523,22 @@ class Cleantalk {
538
  * @return \xmlrpcmsg
539
  */
540
  private function createMsg($method, CleantalkRequest $request) {
 
541
  switch ($method) {
542
  case 'check_message':
543
  // Convert strings to UTF8
544
- $request->message = $this->stringToUTF8($request->message, $this->data_codepage);
545
- $request->example = $this->stringToUTF8($request->example, $this->data_codepage);
546
- $request->sender_email = $this->stringToUTF8($request->sender_email, $this->data_codepage);
547
  $request->sender_nickname = $this->stringToUTF8($request->sender_nickname, $this->data_codepage);
548
 
549
- $request->message = $this->compressData($request->message);
550
- $request->example = $this->compressData($request->example);
551
  break;
552
 
553
  case 'check_newuser':
554
  // Convert strings to UTF8
555
- $request->sender_email = $this->stringToUTF8($request->sender_email, $this->data_codepage);
556
  $request->sender_nickname = $this->stringToUTF8($request->sender_nickname, $this->data_codepage);
557
  break;
558
 
@@ -562,17 +548,18 @@ class Cleantalk {
562
  }
563
  break;
564
  }
565
-
566
  $request->method_name = $method;
567
 
568
- //
569
  // Removing non UTF8 characters from request, because non UTF8 or malformed characters break json_encode().
570
- //
571
  foreach ($request as $param => $value) {
572
- if (!preg_match('//u', $value))
573
- $request->{$param} = 'Nulled. Not UTF8 encoded or malformed.';
 
 
574
  }
575
 
 
576
  return $request;
577
  }
578
 
@@ -581,10 +568,12 @@ class Cleantalk {
581
  * @param $msg
582
  * @return boolean|\CleantalkResponse
583
  */
584
- private function sendRequest($data = null, $url, $server_timeout = 3) {
 
585
  // Convert to array
586
  $data = (array)json_decode(json_encode($data), true);
587
 
 
588
  $original_url = $url;
589
  $original_data = $data;
590
 
@@ -605,7 +594,7 @@ class Cleantalk {
605
  }
606
 
607
  // Switching to secure connection
608
- if ($this->ssl_on && !preg_match("/^https:/", $url)) {
609
  $url = preg_replace("/^(http)/i", "$1s", $url);
610
  }
611
 
@@ -707,6 +696,7 @@ class Cleantalk {
707
  $result = false;
708
 
709
  if($msg->method_name != 'send_feedback'){
 
710
  $ct_tmp = apache_request_headers();
711
 
712
  if(isset($ct_tmp['Cookie']))
@@ -715,31 +705,33 @@ class Cleantalk {
715
  $cookie_name = 'cookie';
716
  else
717
  $cookie_name = 'COOKIE';
718
-
719
  $ct_tmp[$cookie_name] = preg_replace(array(
720
- '/\s?ct_checkjs=[a-z0-9]*[;|$]/',
721
- '/\s?ct_timezone=.{0,1}\d{1,2}[;|$]/',
722
- '/\s?ct_pointer_data=.*5D[;|$]/',
723
- '/\s?apbct_timestamp=\d*[;|$]/',
724
- '/\s?apbct_site_landing_ts=\d*[;|$]/',
725
- '/\s?apbct_cookies_test=%7B.*%7D[;|$]/',
726
- '/\s?apbct_prev_referer=http.*?[;|$]/',
 
 
 
 
 
 
 
727
  ), '', $ct_tmp[$cookie_name]);
728
- $msg->all_headers=json_encode($ct_tmp);
729
  }
730
-
731
- $si=(array)json_decode($msg->sender_info,true);
732
-
733
- $si['remote_addr'] = $_SERVER['REMOTE_ADDR'];
734
- $msg->x_forwarded_for = @$_SERVER['X_FORWARDED_FOR'];
735
- $msg->x_real_ip = @$_SERVER['X_REAL_IP'];
736
-
737
- $msg->sender_info=json_encode($si);
738
  if (((isset($this->work_url) && $this->work_url !== '') && ($this->server_changed + $this->server_ttl > time()))
739
  || $this->stay_on_server == true) {
740
 
741
  $url = (!empty($this->work_url)) ? $this->work_url : $this->server_url;
742
-
743
  $result = $this->sendRequest($msg, $url, $this->server_timeout);
744
  }
745
 
@@ -917,14 +909,6 @@ class Cleantalk {
917
 
918
  return $message;
919
  }
920
-
921
- /**
922
- * From http://php.net/manual/en/function.ip2long.php#82397
923
- */
924
- public function net_match($CIDR,$IP) {
925
- list ($net, $mask) = explode ('/', $CIDR);
926
- return ( ip2long ($IP) & ~((1 << (32 - $mask)) - 1) ) == ip2long ($net);
927
- }
928
 
929
  /**
930
  * Function to check response time
@@ -953,24 +937,72 @@ class Cleantalk {
953
  return $status;
954
  }
955
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
956
  /**
957
  * Function convert string to UTF8 and removes non UTF8 characters
958
  * param string
959
  * param string
960
  * @return string
961
  */
962
- function stringToUTF8($str, $data_codepage = null){
963
- if (!preg_match('//u', $str) && function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding'))
964
- {
965
 
966
  if ($data_codepage !== null)
967
  return mb_convert_encoding($str, 'UTF-8', $data_codepage);
968
-
969
  $encoding = mb_detect_encoding($str);
 
970
  if ($encoding)
971
  return mb_convert_encoding($str, 'UTF-8', $encoding);
972
  }
973
-
974
  return $str;
975
  }
976
 
@@ -980,133 +1012,13 @@ class Cleantalk {
980
  * param string
981
  * @return string
982
  */
983
- function stringFromUTF8($str, $data_codepage = null){
 
984
  if (preg_match('//u', $str) && function_exists('mb_convert_encoding') && $data_codepage !== null)
985
- {
986
- return mb_convert_encoding($str, $data_codepage, 'UTF-8');
987
- }
988
-
989
  return $str;
990
  }
991
-
992
- /**
993
- * Function gets information about spam active networks
994
- *
995
- * @param string api_key
996
- * @return JSON/array
997
- */
998
- public function get_2s_blacklists_db ($api_key) {
999
- $request=array();
1000
- $request['method_name'] = '2s_blacklists_db';
1001
- $request['auth_key'] = $api_key;
1002
- $url='https://api.cleantalk.org';
1003
- $result=sendRawRequest($url,$request);
1004
- return $result;
1005
- }
1006
- }
1007
-
1008
- /**
1009
- * Function gets access key automatically
1010
- *
1011
- * @param string website admin email
1012
- * @param string website host
1013
- * @param string website platform
1014
- * @return type
1015
- */
1016
-
1017
- if(!function_exists('getAutoKey'))
1018
- {
1019
- function getAutoKey($email, $host, $platform, $timezone = null)
1020
- {
1021
- $request=array();
1022
- $request['method_name'] = 'get_api_key';
1023
- $request['email'] = $email;
1024
- $request['website'] = $host;
1025
- $request['platform'] = $platform;
1026
- $request['timezone'] = $timezone;
1027
- $request['product_name'] = 'antispam';
1028
- $url='https://api.cleantalk.org';
1029
- $result=sendRawRequest($url,$request);
1030
- return $result;
1031
- }
1032
- }
1033
-
1034
- /**
1035
- * Function gets information about renew notice
1036
- *
1037
- * @param string api_key
1038
- * @return type
1039
- */
1040
-
1041
- function noticePaidTill($api_key)
1042
- {
1043
- $request=array();
1044
- $request['method_name'] = 'notice_paid_till';
1045
- $request['auth_key'] = $api_key;
1046
- $url='https://api.cleantalk.org';
1047
- $result=sendRawRequest($url,$request);
1048
- return $result;
1049
  }
1050
-
1051
- /**
1052
- * Function gets spam report
1053
- *
1054
- * @param string website host
1055
- * @param integer report days
1056
- * @return type
1057
- */
1058
-
1059
- if(!function_exists('getAntispamReport'))
1060
- {
1061
- function getAntispamReport($host, $period = 1)
1062
- {
1063
- $url='https://api.cleantalk.org';
1064
- $request=Array(
1065
- 'method_name' => 'get_antispam_report',
1066
- 'hostname' => $host,
1067
- 'period' => $period
1068
- );
1069
- $result=sendRawRequest($url,$request);
1070
- return $result;
1071
- }
1072
- }
1073
-
1074
- /**
1075
- * Function gets spam statistics
1076
- *
1077
- * @param string website host
1078
- * @param integer report days
1079
- * @return type
1080
- */
1081
-
1082
- if(!function_exists('getAntispamReportBreif'))
1083
- {
1084
- function getAntispamReportBreif($key='')
1085
- {
1086
-
1087
- $url="https://api.cleantalk.org?auth_key=$key";
1088
- $request=Array(
1089
- 'method_name' => 'get_antispam_report_breif'
1090
- );
1091
- $result = sendRawRequest($url,$request);
1092
-
1093
- if($result === false)
1094
- return "Network error. Please, check <a target='_blank' href='https://cleantalk.org/help/faq-setup#hosting'>this article</a>.";
1095
-
1096
- $result = !empty($result) ? json_decode($result, true) : false;
1097
-
1098
- if(!empty($result['error_message']))
1099
- return $result['error_message'];
1100
- else{
1101
- $tmp = array();
1102
- for($i=0; $i<7; $i++)
1103
- $tmp[date("Y-m-d", time()-86400*7+86400*$i)] = 0;
1104
- $result['data']['spam_stat'] = array_merge($tmp, $result['data']['spam_stat']);
1105
- return $result['data'];
1106
- }
1107
- }
1108
- }
1109
-
1110
  /**
1111
  * Function sends raw request to API server
1112
  *
@@ -1192,37 +1104,6 @@ if(!function_exists('apache_request_headers')){
1192
  }
1193
  }
1194
 
1195
- function cleantalk_get_real_ip(){
1196
-
1197
- // Getting headers
1198
- $headers = function_exists('apache_request_headers') ? apache_request_headers() : $_SERVER;
1199
-
1200
- // Getting IP for validating
1201
- if (array_key_exists( 'X-Forwarded-For', $headers )){
1202
- $ip = explode(",", trim($headers['X-Forwarded-For']));
1203
- $ip = trim($ip[0]);
1204
- }elseif(array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers)){
1205
- $ip = explode(",", trim($headers['HTTP_X_FORWARDED_FOR']));
1206
- $ip = trim($ip[0]);
1207
- }else{
1208
- $ip = $_SERVER['REMOTE_ADDR'];
1209
- }
1210
-
1211
- // Validating IP
1212
- // IPv4
1213
- if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){
1214
- $the_ip = $ip;
1215
- // IPv6
1216
- }elseif(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)){
1217
- $the_ip = $ip;
1218
- // Unknown
1219
- }else{
1220
- $the_ip = null;
1221
- }
1222
-
1223
- return $the_ip;
1224
- }
1225
-
1226
  function cleantalk_is_JSON($string)
1227
  {
1228
  return ((is_string($string) && (is_object(json_decode($string)) || is_array(json_decode($string))))) ? true : false;
429
  *
430
  */
431
  public $min_server_timeout = 50;
432
+
433
  /**
434
  * Function checks whether it is possible to publish the message
435
  * @param CleantalkRequest $request
470
  * @return type
471
  */
472
  private function filterRequest(CleantalkRequest $request) {
473
+
474
  // general and optional
475
  foreach ($request as $param => $value) {
476
+
477
+ if($param == 'js_on') { if(!is_int($value)) { $request->$param = null; }}
478
+ if($param == 'submit_time') { if(!is_int($value)) { $request->$param = null; }}
479
+ if($param == 'message') { if(!is_string($value)) { $request->$param = null; }} // Should be array, but servers understand only JSON
480
+ if($param == 'example') { if(!is_string($value)) { $request->$param = null; }} // Should be array, but servers understand only JSON
481
+ if($param == 'sender_info') { if(!is_string($value)) { $request->$param = null; }} // Should be array, but servers understand only JSON
482
+ if($param == 'post_info') { if(!is_string($value)) { $request->$param = null; }} // Should be array, but servers understand only JSON
483
+ if($param == 'agent') { if(!is_string($value)) { $request->$param = null; }}
484
+ if($param == 'sender_nickname') { if(!is_string($value)) { $request->$param = null; }}
485
+ if($param == 'phone') { if(!is_string($value)) { $request->$param = null; }}
486
+ if($param == 'sender_email') { if(!is_string($value)) { $request->$param = null; }}
487
+ if($param == 'sender_ip') { if(!is_string($value)) { $request->$param = null; }}
488
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  }
490
+
491
  return $request;
492
  }
493
 
523
  * @return \xmlrpcmsg
524
  */
525
  private function createMsg($method, CleantalkRequest $request) {
526
+
527
  switch ($method) {
528
  case 'check_message':
529
  // Convert strings to UTF8
530
+ $request->message = $this->arrayToUTF8( $request->message, $this->data_codepage);
531
+ $request->example = $this->arrayToUTF8( $request->example, $this->data_codepage);
532
+ $request->sender_email = $this->stringToUTF8($request->sender_email, $this->data_codepage);
533
  $request->sender_nickname = $this->stringToUTF8($request->sender_nickname, $this->data_codepage);
534
 
535
+ // $request->message = $this->compressData($request->message);
536
+ // $request->example = $this->compressData($request->example);
537
  break;
538
 
539
  case 'check_newuser':
540
  // Convert strings to UTF8
541
+ $request->sender_email = $this->stringToUTF8($request->sender_email, $this->data_codepage);
542
  $request->sender_nickname = $this->stringToUTF8($request->sender_nickname, $this->data_codepage);
543
  break;
544
 
548
  }
549
  break;
550
  }
551
+
552
  $request->method_name = $method;
553
 
 
554
  // Removing non UTF8 characters from request, because non UTF8 or malformed characters break json_encode().
 
555
  foreach ($request as $param => $value) {
556
+ if(is_array($request->$param))
557
+ $request->$param = $this->removeNonUTF8FromArray($value);
558
+ if(is_string($request->$param) || is_int($request->$param))
559
+ $request->$param = $this->removeNonUTF8FromString($value);
560
  }
561
 
562
+
563
  return $request;
564
  }
565
 
568
  * @param $msg
569
  * @return boolean|\CleantalkResponse
570
  */
571
+ private function sendRequest($data = null, $url, $server_timeout = 3)
572
+ {
573
  // Convert to array
574
  $data = (array)json_decode(json_encode($data), true);
575
 
576
+
577
  $original_url = $url;
578
  $original_data = $data;
579
 
594
  }
595
 
596
  // Switching to secure connection
597
+ if ($this->ssl_on && !preg_match("/^https:/", $url)){
598
  $url = preg_replace("/^(http)/i", "$1s", $url);
599
  }
600
 
696
  $result = false;
697
 
698
  if($msg->method_name != 'send_feedback'){
699
+
700
  $ct_tmp = apache_request_headers();
701
 
702
  if(isset($ct_tmp['Cookie']))
705
  $cookie_name = 'cookie';
706
  else
707
  $cookie_name = 'COOKIE';
708
+
709
  $ct_tmp[$cookie_name] = preg_replace(array(
710
+ '/\s?ct_checkjs=[a-z0-9]*[^;]*;?/',
711
+ '/\s?ct_timezone=.{0,1}\d{1,2}[^;]*;?/',
712
+ '/\s?ct_pointer_data=.*5D[^;]*;?/',
713
+ '/\s?apbct_timestamp=\d*[^;]*;?/',
714
+ '/\s?apbct_site_landing_ts=\d*[^;]*;?/',
715
+ '/\s?apbct_cookies_test=%7B.*%7D[^;]*;?/',
716
+ '/\s?apbct_prev_referer=http.*?[^;]*;?/',
717
+ '/\s?ct_cookies_test=.*?[^;]*;?/',
718
+ '/\s?ct_ps_timestamp=.*?[^;]*;?/',
719
+ '/\s?ct_fkp_timestamp=\d*?[^;]*;?/',
720
+ '/\s?ct_sfw_pass_key=\d*?[^;]*;?/',
721
+ '/\s?apbct_page_hits=\d*?[^;]*;?/',
722
+ '/\s?apbct_visible_fields_count=\d*?[^;]*;?/',
723
+ '/\s?apbct_visible_fields=%7B.*%7D[^;]*;?/',
724
  ), '', $ct_tmp[$cookie_name]);
725
+ $msg->all_headers = $ct_tmp;
726
  }
727
+
728
+ $msg->all_headers = json_encode($msg->all_headers);
729
+
 
 
 
 
 
730
  if (((isset($this->work_url) && $this->work_url !== '') && ($this->server_changed + $this->server_ttl > time()))
731
  || $this->stay_on_server == true) {
732
 
733
  $url = (!empty($this->work_url)) ? $this->work_url : $this->server_url;
734
+
735
  $result = $this->sendRequest($msg, $url, $this->server_timeout);
736
  }
737
 
909
 
910
  return $message;
911
  }
 
 
 
 
 
 
 
 
912
 
913
  /**
914
  * Function to check response time
937
  return $status;
938
  }
939
 
940
+
941
+ /**
942
+ * Function removing non UTF8 characters from array||string
943
+ * param mixed(array||string)
944
+ * return mixed(array||string)
945
+ */
946
+ function removeNonUTF8FromArray($data)
947
+ {
948
+ foreach($data as $key => $val){
949
+ if(is_array($val)){
950
+ $data[$key] = $this->removeNonUTF8FromArray($val);
951
+ }else{
952
+ $data[$key] = $this->removeNonUTF8FromString($val);
953
+ }
954
+ }
955
+ return $data;
956
+ }
957
+
958
+ /**
959
+ * Function removing non UTF8 characters from array||string
960
+ * param mixed(array||string)
961
+ * return mixed(array||string)
962
+ */
963
+ function removeNonUTF8FromString($data)
964
+ {
965
+ if(!preg_match('//u', $data))
966
+ $data = 'Nulled. Not UTF8 encoded or malformed.';
967
+ return $data;
968
+ }
969
+
970
+ /**
971
+ * Function convert array to UTF8 and removes non UTF8 characters
972
+ * param array
973
+ * param string
974
+ * @return array
975
+ */
976
+ function arrayToUTF8($array, $data_codepage = null)
977
+ {
978
+ foreach($array as $key => $val){
979
+
980
+ if(is_array($val))
981
+ $array[$key] = $this->arrayToUTF8($val, $data_codepage);
982
+ else
983
+ $array[$key] = $this->stringToUTF8($val, $data_codepage);
984
+ }
985
+ return $array;
986
+ }
987
+
988
  /**
989
  * Function convert string to UTF8 and removes non UTF8 characters
990
  * param string
991
  * param string
992
  * @return string
993
  */
994
+ function stringToUTF8($str, $data_codepage = null)
995
+ {
996
+ if (!preg_match('//u', $str) && function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')){
997
 
998
  if ($data_codepage !== null)
999
  return mb_convert_encoding($str, 'UTF-8', $data_codepage);
1000
+
1001
  $encoding = mb_detect_encoding($str);
1002
+
1003
  if ($encoding)
1004
  return mb_convert_encoding($str, 'UTF-8', $encoding);
1005
  }
 
1006
  return $str;
1007
  }
1008
 
1012
  * param string
1013
  * @return string
1014
  */
1015
+ function stringFromUTF8($str, $data_codepage = null)
1016
+ {
1017
  if (preg_match('//u', $str) && function_exists('mb_convert_encoding') && $data_codepage !== null)
1018
+ return mb_convert_encoding($str, $data_codepage, 'UTF-8');
 
 
 
1019
  return $str;
1020
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1021
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022
  /**
1023
  * Function sends raw request to API server
1024
  *
1104
  }
1105
  }
1106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1107
  function cleantalk_is_JSON($string)
1108
  {
1109
  return ((is_string($string) && (is_object(json_decode($string)) || is_array(json_decode($string))))) ? true : false;
js/apbct-public.js CHANGED
@@ -81,6 +81,7 @@ apbct_attach_event_handler(window, "keydown", ctFunctionFirstKey);
81
 
82
  // Ready function
83
  function apbct_ready(){
 
84
  ctSetCookieSec("apbct_visible_fields_count", 0);
85
  for(var i=0; i < document.forms.length; i++){
86
  var form = document.forms[i];
81
 
82
  // Ready function
83
  function apbct_ready(){
84
+ ctSetCookieSec("apbct_visible_fields", 0);
85
  ctSetCookieSec("apbct_visible_fields_count", 0);
86
  for(var i=0; i < document.forms.length; i++){
87
  var form = document.forms[i];
js/cleantalk-comments-checkspam.js CHANGED
@@ -143,6 +143,12 @@ function ct_send_comments(){
143
  status_string += ctCommentsCheck.ct_status_string_warning;
144
  jQuery('#ct_checking_status').html(status_string);
145
  jQuery('#ct_error_message').hide();
 
 
 
 
 
 
146
  ct_send_comments();
147
  }
148
  }
143
  status_string += ctCommentsCheck.ct_status_string_warning;
144
  jQuery('#ct_checking_status').html(status_string);
145
  jQuery('#ct_error_message').hide();
146
+ // If DB woks not properly
147
+ if(+ct_comments_total < ct_comments_checked + ct_comments_bad){
148
+ document.cookie = 'ct_comments_start_check=1; path=/';
149
+ document.cookie = 'ct_comments_safe_check=1; path=/';
150
+ location.href = 'edit-comments.php?page=ct_check_spam';
151
+ }
152
  ct_send_comments();
153
  }
154
  }
lib/CleantalkHelper.php ADDED
@@ -0,0 +1,507 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class CleantalkHelper
4
+ {
5
+ const URL = 'https://api.cleantalk.org';
6
+
7
+ private $cdn_pool = array(
8
+ 'cloud_flare' => array(
9
+ '103.21.244.0/22',
10
+ '103.22.200.0/22',
11
+ '103.31.4.0/22',
12
+ '104.16.0.0/12',
13
+ '108.162.192.0/18',
14
+ '131.0.72.0/22',
15
+ '141.101.64.0/18',
16
+ '162.158.0.0/15',
17
+ '172.64.0.0/13',
18
+ '173.245.48.0/20',
19
+ '188.114.96.0/20',
20
+ '190.93.240.0/20',
21
+ '197.234.240.0/22',
22
+ '198.41.128.0/17',
23
+ ),
24
+ );
25
+
26
+ /*
27
+ * Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)
28
+ * reutrns array('remote_addr' => 'val', ['x_forwarded_for' => 'val', ['x_real_ip' => 'val', ['cloud_flare' => 'val']]])
29
+ */
30
+ static public function get_ips()
31
+ {
32
+ $ips = array(
33
+ 'remote_addr' => '',
34
+ 'x_forwarded_for' => '',
35
+ 'x_real_ip' => '',
36
+ 'cloud_flare' => '',
37
+ );
38
+ $headers = self::get_request_headers();
39
+
40
+ // Getting IP
41
+
42
+ // REMOTE_ADDR
43
+ $ips['remote_addr'] = $_SERVER['REMOTE_ADDR'];
44
+
45
+ // X-Forwarded-For
46
+ if( isset($headers['X-Forwarded-For']) ){
47
+ $tmp = explode(",", trim($headers['X-Forwarded-For']));
48
+ $ips['x_forwarded_for']= trim($tmp[0]);
49
+ }
50
+
51
+ // X-Real-Ip
52
+ if(isset($headers['X-Real-Ip'])){
53
+ $tmp = explode(",", trim($headers['X-Real-Ip']));
54
+ $ips['x_real_ip']= trim($tmp[0]);
55
+ }
56
+
57
+ // Cloud Flare
58
+ if(isset($headers['Cf_Connecting_Ip'])){
59
+ foreach(self::cdn_cf['cloud_flare'] as $cidr){
60
+ if($this->ip_mask_match($ips['remote_addr'], $cidr)){
61
+ $ips['cloud_flare'] = $headers['Cf_Connecting_Ip'];
62
+ break;
63
+ }
64
+ }
65
+ }
66
+
67
+ // Validating IPs
68
+ foreach($ips as $key => $ip){
69
+ $ips[$key] = self::ip_validate($ip)
70
+ ? $ip
71
+ : null;
72
+ }
73
+ return $ips;
74
+ }
75
+
76
+ /*
77
+ * Getting IP from REMOTE_ADDR or Cf_Connecting_Ip if set
78
+ * reutrns (string)
79
+ */
80
+ static public function get_ip_real()
81
+ {
82
+ $headers = self::get_request_headers();
83
+
84
+ // REMOTE_ADDR
85
+ $ip = $_SERVER['REMOTE_ADDR'];
86
+
87
+ // Cloud Flare
88
+ if(isset($headers['Cf_Connecting_Ip'])){
89
+ foreach(self::cdn_cf['cloud_flare'] as $cidr){
90
+ if($this->ip_mask_match($ips['remote_addr'], $cidr)){
91
+ $ip = $headers['Cf_Connecting_Ip'];
92
+ break;
93
+ }
94
+ }
95
+ }
96
+
97
+ return self::ip_validate($ip) ? $ip : false;
98
+ }
99
+
100
+ // Return validated REMOTE_ADDR
101
+ static public function get_ip_remote_addr()
102
+ {
103
+ if(isset($_SERVER['REMOTE_ADDR'])){
104
+ $ip = $_SERVER['REMOTE_ADDR'];
105
+ }
106
+ return isset($ip) && self::ip_validate($ip) ? $ip : null;
107
+ }
108
+
109
+ // Return validated X-Forwarded-For
110
+ static public function get_ip_x_forwarded_for()
111
+ {
112
+ $headers = self::get_request_headers();
113
+ if(isset($headers['X-Forwarded-For'])){
114
+ $tmp = explode(',', trim($headers['X-Forwarded-For']));
115
+ $ip = trim($tmp[0]);
116
+ }
117
+ return isset($ip) && self::ip_validate($ip) ? $ip : null;
118
+ }
119
+
120
+ // Return validated X-Real-Ip
121
+ static public function get_ip_x_real_ip()
122
+ {
123
+ $headers = self::get_request_headers();
124
+ if(isset($headers['X-Real-Ip'])){
125
+ $tmp = explode(',', trim($headers['X-Real-Ip']));
126
+ $ip = trim($tmp[0]);
127
+ }
128
+ return isset($ip) && self::ip_validate($ip) ? $ip : null;
129
+ }
130
+
131
+ // Return validated Cloud Flare
132
+ static public function get_ip_cloud_flare()
133
+ {
134
+ $headers = self::get_request_headers();
135
+ if(isset($headers['Cf_Connecting_Ip'])){
136
+ foreach(self::cdn_cf['cloud_flare'] as $cidr){
137
+ if($this->ip_mask_match($_SERVER['remote_addr'], $cidr)){
138
+ $ip = $headers['Cf_Connecting_Ip'];
139
+ break;
140
+ }
141
+ }
142
+ }
143
+ return isset($ip) && self::ip_validate($ip) ? $ip : null;
144
+ }
145
+
146
+ static public function ip_mask_match($ip, $cidr){
147
+ $exploded = explode ('/', $cidr);
148
+ $net = $exploded[0];
149
+ $mask = 4294967295 << (32 - $exploded[1]);
150
+ return (ip2long($ip) & $mask) == (ip2long($net) & $mask);
151
+ }
152
+
153
+ /*
154
+ * Validating IPv4, IPv6
155
+ * param (string) $ip
156
+ * returns (string) 'v4' || (string) 'v6' || (bool) false
157
+ */
158
+ static public function ip_validate($ip)
159
+ {
160
+ // IPv4
161
+ if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4))
162
+ return 'v4';
163
+ // IPv6
164
+ if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
165
+ return 'v6';
166
+ // Unknown
167
+ return false;
168
+ }
169
+
170
+ /*
171
+ * If Apache web server is missing then making
172
+ * Patch for apache_request_headers()
173
+ */
174
+ static public function get_request_headers()
175
+ {
176
+ $headers = array();
177
+ foreach($_SERVER as $key => $val){
178
+ if(preg_match('/\AHTTP_/', $key)){
179
+ $server_key = preg_replace('/\AHTTP_/', '', $key);
180
+ $key_parts = explode('_', $server_key);
181
+ if(count($key_parts) > 0 and strlen($server_key) > 2){
182
+ foreach($key_parts as $part_index => $part){
183
+ $key_parts[$part_index] = mb_strtolower($part);
184
+ $key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
185
+ }
186
+ $server_key = implode('-', $key_parts);
187
+ }
188
+ $headers[$server_key] = $val;
189
+ }
190
+ }
191
+ return $headers;
192
+ }
193
+
194
+
195
+ /**
196
+ * Function gets information about spam active networks
197
+ *
198
+ * @param string api_key
199
+ * @return JSON/array
200
+ */
201
+ static public function get_2s_blacklists_db($api_key, $do_check = true)
202
+ {
203
+ $request = array(
204
+ 'agent' => APBCT_AGENT,
205
+ 'method_name' => '2s_blacklists_db',
206
+ 'auth_key' => $api_key,
207
+ );
208
+
209
+ $result = self::sendRawRequest(self::URL, $request);
210
+ // $result = $do_check ? self::checkRequestResult($result, '2s_blacklists_db') : $result;
211
+
212
+ return $result;
213
+ }
214
+
215
+ /**
216
+ * Function gets access key automatically
217
+ *
218
+ * @param string website admin email
219
+ * @param string website host
220
+ * @param string website platform
221
+ * @return type
222
+ */
223
+ static public function getAutoKey($email, $host, $platform, $timezone = null, $do_check = true)
224
+ {
225
+ $request = array(
226
+ 'method_name' => 'get_api_key',
227
+ 'agent' => APBCT_AGENT,
228
+ 'email' => $email,
229
+ 'website' => $host,
230
+ 'platform' => $platform,
231
+ 'timezone' => $timezone,
232
+ 'product_name' => 'antispam',
233
+ );
234
+
235
+ $result = self::sendRawRequest(self::URL, $request);
236
+ // $result = $do_check ? self::checkRequestResult($result, 'get_api_key') : $result;
237
+
238
+ return $result;
239
+ }
240
+
241
+ /**
242
+ * Function gets information about renew notice
243
+ *
244
+ * @param string api_key
245
+ * @return type
246
+ */
247
+ static public function noticeValidateKey($api_key, $path_to_cms, $do_check = true)
248
+ {
249
+ $request = array(
250
+ 'agent' => APBCT_AGENT,
251
+ 'method_name' => 'notice_validate_key',
252
+ 'auth_key' => $api_key,
253
+ 'path_to_cms' => $path_to_cms
254
+ );
255
+
256
+ $result = self::sendRawRequest(self::URL, $request);
257
+ $result = $do_check ? self::checkRequestResult($result, 'notice_validate_key') : $result;
258
+
259
+ return $result;
260
+ }
261
+
262
+ /**
263
+ * Function gets information about renew notice
264
+ *
265
+ * @param string api_key
266
+ * @return type
267
+ */
268
+ static public function noticePaidTill($api_key, $do_check = true)
269
+ {
270
+ $request = array(
271
+ 'agent' => APBCT_AGENT,
272
+ 'method_name' => 'notice_paid_till',
273
+ 'auth_key' => $api_key
274
+ );
275
+
276
+ $result = self::sendRawRequest(self::URL, $request);
277
+ // $result = $do_check ? self::checkRequestResult($result, 'notice_paid_till') : $result;
278
+
279
+ return $result;
280
+ }
281
+
282
+ /**
283
+ * Function gets spam report
284
+ *
285
+ * @param string website host
286
+ * @param integer report days
287
+ * @return type
288
+ */
289
+ static public function getAntispamReport($host, $period = 1)
290
+ {
291
+ $request=Array(
292
+ 'agent' => APBCT_AGENT,
293
+ 'method_name' => 'get_antispam_report',
294
+ 'hostname' => $host,
295
+ 'period' => $period
296
+ );
297
+
298
+ $result = self::sendRawRequest(self::URL, $request);
299
+ // $result = $do_check ? self::checkRequestResult($result, 'get_antispam_report') : $result;
300
+
301
+ return $result;
302
+ }
303
+
304
+ /**
305
+ * Function gets spam statistics
306
+ *
307
+ * @param string website host
308
+ * @param integer report days
309
+ * @return type
310
+ */
311
+ static public function getAntispamReportBreif($key='')
312
+ {
313
+
314
+ $url="https://api.cleantalk.org?auth_key=$key";
315
+ $request=Array(
316
+ 'method_name' => 'get_antispam_report_breif'
317
+ );
318
+ $result = self::sendRawRequest($url,$request);
319
+
320
+ if($result === false)
321
+ return "Network error. Please, check <a target='_blank' href='https://cleantalk.org/help/faq-setup#hosting'>this article</a>.";
322
+
323
+ $result = !empty($result) ? json_decode($result, true) : false;
324
+
325
+ if(!empty($result['error_message']))
326
+ return $result['error_message'];
327
+ else{
328
+ $tmp = array();
329
+ for($i=0; $i<7; $i++)
330
+ $tmp[date("Y-m-d", time()-86400*7+86400*$i)] = 0;
331
+ $result['data']['spam_stat'] = array_merge($tmp, $result['data']['spam_stat']);
332
+ return $result['data'];
333
+ }
334
+ }
335
+
336
+ static public function sendRawRequest($url,$data,$isJSON=false,$timeout=3)
337
+ {
338
+
339
+ $result = null;
340
+ if(!$isJSON){
341
+ $data = http_build_query($data);
342
+ $data = str_replace("&amp;", "&", $data);
343
+ }else{
344
+ $data = json_encode($data);
345
+ }
346
+
347
+ $curl_exec = false;
348
+
349
+ if (function_exists('curl_init') && function_exists('json_decode')){
350
+
351
+ $ch = curl_init();
352
+ curl_setopt($ch, CURLOPT_URL, $url);
353
+ curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
354
+ curl_setopt($ch, CURLOPT_POST, true);
355
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
356
+
357
+ // receive server response ...
358
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
359
+ // resolve 'Expect: 100-continue' issue
360
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
361
+
362
+ $result = curl_exec($ch);
363
+
364
+ if($result !== false)
365
+ $curl_exec = true;
366
+
367
+ curl_close($ch);
368
+ }
369
+ if(!$curl_exec){
370
+
371
+ $opts = array(
372
+ 'http'=>array(
373
+ 'method' => "POST",
374
+ 'timeout' => $timeout,
375
+ 'content' => $data,
376
+ )
377
+ );
378
+ $context = stream_context_create($opts);
379
+ $result = @file_get_contents($url, 0, $context);
380
+ }
381
+
382
+ return $result;
383
+ }
384
+
385
+ /**
386
+ * Function checks server response
387
+ *
388
+ * @param string result
389
+ * @param string request_method
390
+ * @return mixed (array || array('error' => true))
391
+ */
392
+ static public function checkRequestResult($result, $method_name = null)
393
+ {
394
+ // Errors handling
395
+
396
+ // Bad connection
397
+ if(empty($result)){
398
+ return array(
399
+ 'error' => true,
400
+ 'error_string' => 'CONNECTION_ERROR'
401
+ );
402
+ }
403
+
404
+ // JSON decode errors
405
+ $result = json_decode($result, true);
406
+ if(empty($result)){
407
+ return array(
408
+ 'error' => true,
409
+ 'error_string' => 'JSON_DECODE_ERROR'
410
+ );
411
+ }
412
+
413
+ // Server errors
414
+ if($result && (isset($result['error_no']) || isset($result['error_message']))){
415
+ return array(
416
+ 'error' => true,
417
+ 'error_string' => "SERVER_ERROR NO: {$result['error_no']} MSG: {$result['error_message']}",
418
+ 'error_no' => $result['error_no'],
419
+ 'error_message' => $result['error_message']
420
+ );
421
+ }
422
+
423
+ // Pathces for different methods
424
+
425
+ // mehod_name = notice_validate_key
426
+ if($method_name == 'notice_validate_key' && isset($result['valid'])){
427
+ return $result;
428
+ }
429
+
430
+ // Other methods
431
+ if(isset($result['data']) && is_array($result['data'])){
432
+ return $result['data'];
433
+ }
434
+ }
435
+
436
+ /**
437
+ * Prepares an adds an error to the plugin's data
438
+ *
439
+ * @param string type
440
+ * @param mixed array || string
441
+ * @returns null
442
+ */
443
+ static public function addError($type, $error, $set_time = true)
444
+ {
445
+ global $apbct;
446
+
447
+ $error_string = is_array($error)
448
+ ? $error['error_string']
449
+ : $error;
450
+
451
+ // Exceptions
452
+ if( ($type == 'send_logs' && $error_string == 'NO_LOGS_TO_SEND') ||
453
+ ($type == 'send_firewall_logs' && $error_string == 'NO_LOGS_TO_SEND')
454
+ )
455
+ return;
456
+
457
+ if($set_time == true)
458
+ $apbct->data['errors'][$type]['error_time'] = current_time('timestamp');
459
+ $apbct->data['errors'][$type]['error_string'] = $error_string;
460
+ $apbct->save('data');
461
+ }
462
+
463
+ /**
464
+ * Deletes an error from the plugin's data
465
+ *
466
+ * @param mixed (array of strings || string 'elem1 elem2...' || string 'elem') type
467
+ * @param delay saving
468
+ * @returns null
469
+ */
470
+ static public function deleteError($type, $save_flag = false)
471
+ {
472
+ global $apbct;
473
+
474
+ $before = empty($apbct->data['errors']) ? 0 : count($apbct->data['errors']);
475
+
476
+ if(is_string($type))
477
+ $type = explode(' ', $type);
478
+
479
+ foreach($type as $val){
480
+ if(isset($apbct->data['errors'][$val])){
481
+ unset($apbct->data['errors'][$val]);
482
+ }
483
+ }
484
+
485
+ $after = empty($apbct->data['errors']) ? 0 : count($apbct->data['errors']);
486
+ // Save if flag is set and there are changes
487
+ if($save_flag && $before != $after)
488
+ $apbct->save('data');
489
+ }
490
+
491
+ /**
492
+ * Deletes all errors from the plugin's data
493
+ *
494
+ * @param delay saving
495
+ * @returns null
496
+ */
497
+ static public function deleteAllErrors($save_flag = false)
498
+ {
499
+ global $apbct;
500
+
501
+ if(isset($apbct->data['errors']))
502
+ unset($apbct->data['errors']);
503
+
504
+ if($save_flag)
505
+ $apbct->save('data');
506
+ }
507
+ }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: znaeff, shagimuratov, sartemd174
3
  Tags: spam, antispam, protection, comments, firewall
4
  Requires at least: 3.0
5
  Tested up to: 4.9.1
6
- Stable tag: 5.82.1
7
  License: GPLv2
8
 
9
  Spam protection, antispam, all-in-one, premium plugin. No spam comments & users, no spam contact form & WooCommerce spam. Forget spam.
@@ -504,6 +504,13 @@ We develop plugin to do it as optimized as possible, CleanTalk doesn't downgrade
504
  1. The plugin deletes/removes the existing spam comments and users accounts.
505
 
506
  == Changelog ==
 
 
 
 
 
 
 
507
  = 5.82.1 December 7 2017 =
508
  * Fixed minor error with attaching JS and CSS files.
509
 
@@ -1471,6 +1478,13 @@ We develop plugin to do it as optimized as possible, CleanTalk doesn't downgrade
1471
  * First version
1472
 
1473
  == Upgrade Notice ==
 
 
 
 
 
 
 
1474
  = 5.82.1 December 7 2017 =
1475
  * Fixed minor error with attaching JS and CSS files.
1476
 
3
  Tags: spam, antispam, protection, comments, firewall
4
  Requires at least: 3.0
5
  Tested up to: 4.9.1
6
+ Stable tag: 5.83
7
  License: GPLv2
8
 
9
  Spam protection, antispam, all-in-one, premium plugin. No spam comments & users, no spam contact form & WooCommerce spam. Forget spam.
504
  1. The plugin deletes/removes the existing spam comments and users accounts.
505
 
506
  == Changelog ==
507
+ = 5.83 December 19 2017 =
508
+ * Improving: Stability and compatibility.
509
+ * Improving: Spam protection.
510
+ * Fix: Comments logic filtration.
511
+ * Fix: Admin bar counter.
512
+ * Minor errors fixes.
513
+
514
  = 5.82.1 December 7 2017 =
515
  * Fixed minor error with attaching JS and CSS files.
516
 
1478
  * First version
1479
 
1480
  == Upgrade Notice ==
1481
+ = 5.83 December 19 2017 =
1482
+ * Improving: Stability and compatibility.
1483
+ * Improving: Spam protection.
1484
+ * Fix: Comments logic filtration.
1485
+ * Fix: Admin bar counter.
1486
+ * Minor errors fixes.
1487
+
1488
  = 5.82.1 December 7 2017 =
1489
  * Fixed minor error with attaching JS and CSS files.
1490