Spam protection, AntiSpam, FireWall by CleanTalk - Version 5.159.8

Version Description

Jul 07 2021 = * Fix: Fixed the connection error Ajax.php when the site files are in a subfolder. * Fix. SFW. Anticrawler redirect detection fixed. * Fix. Checking sql before the tables creating. * Fix. Updater fixed. * Fix: Set alt cookies if sg optimizer is enabled. * Fix: Exclusion for GiveWP plugin in apbct-public.js. #2

Download this release

Release Info

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

Code changes from version 5.159.7 to 5.159.8

cleantalk.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://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.
6
- Version: 5.159.7
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk-spam-protect
@@ -176,7 +176,9 @@ if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
176
 
177
  // Iphorm
178
  if( isset( $_POST['iphorm_ajax'], $_POST['iphorm_id'], $_POST['iphorm_uid'] ) ){
 
179
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
 
180
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
181
  ct_ajax_hook();
182
  }
@@ -186,7 +188,9 @@ if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
186
  && (!empty($_POST['action']) && $_POST['action'] == 'fb_intialize')
187
  && !empty($_POST['FB_userdata'])
188
  ){
 
189
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
 
190
  if (apbct_is_user_enable()){
191
  $ct_check_post_result=false;
192
  ct_registration_errors(null);
@@ -273,7 +277,8 @@ if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
273
  $apbct->settings['sfw__enabled'] == 1 &&
274
  apbct_is_get() &&
275
  ! apbct_wp_doing_cron() &&
276
- ! \Cleantalk\Variables\Server::in_uri( '/favicon.ico' )
 
277
  ){
278
  wp_suspend_cache_addition( true );
279
  apbct_sfw__check();
@@ -341,8 +346,10 @@ if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
341
 
342
  $cleantalk_hooked_actions = array();
343
  $cleantalk_ajax_actions_to_check = array();
344
-
 
345
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
 
346
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
347
 
348
  // Feedback for comments
@@ -372,8 +379,8 @@ if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
372
  add_filter('et_pre_insert_answer', 'ct_ajax_hook', 1, 1); // Answers
373
 
374
  // Formidable
375
- add_filter( 'frm_entries_before_create', 'apbct_rorm__formidable__testSpam', 10, 2 );
376
- add_action( 'frm_entries_footer_scripts', 'apbct_rorm__formidable__footerScripts', 20, 2 );
377
 
378
  // Some of plugins to register a users use AJAX context.
379
  add_filter('registration_errors', 'ct_registration_errors', 1, 3);
@@ -381,14 +388,18 @@ if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
381
  add_action('user_register', 'apbct_user_register');
382
 
383
  if(class_exists('BuddyPress')){
 
384
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
 
385
  add_filter('bp_activity_is_spam_before_save', 'apbct_integration__buddyPres__activityWall', 999 ,2); /* ActivityWall */
386
  add_action('bp_locate_template', 'apbct_integration__buddyPres__getTemplateName', 10, 6);
387
  }
388
 
389
  }
390
-
391
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
 
 
392
  //Bitrix24 contact form
393
  if ($apbct->settings['forms__general_contact_forms_test'] == 1 &&
394
  !empty($_POST['your-phone']) &&
@@ -417,10 +428,10 @@ if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
417
 
418
  // Public pages actions
419
  }else{
420
-
421
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
422
-
423
 
 
 
 
424
 
425
  add_action('wp_enqueue_scripts', 'ct_enqueue_scripts_public');
426
 
@@ -602,7 +613,11 @@ function apbct_activation( $network = false ) {
602
  }
603
 
604
  function apbct_activation__create_tables( $sqls, $db_prefix = '' ) {
605
-
 
 
 
 
606
  global $wpdb;
607
 
608
  $db_prefix = $db_prefix ? $db_prefix : $wpdb->prefix;
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://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.
6
+ Version: 5.159.8
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk-spam-protect
176
 
177
  // Iphorm
178
  if( isset( $_POST['iphorm_ajax'], $_POST['iphorm_id'], $_POST['iphorm_uid'] ) ){
179
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
180
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
181
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
182
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
183
  ct_ajax_hook();
184
  }
188
  && (!empty($_POST['action']) && $_POST['action'] == 'fb_intialize')
189
  && !empty($_POST['FB_userdata'])
190
  ){
191
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
192
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
193
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
194
  if (apbct_is_user_enable()){
195
  $ct_check_post_result=false;
196
  ct_registration_errors(null);
277
  $apbct->settings['sfw__enabled'] == 1 &&
278
  apbct_is_get() &&
279
  ! apbct_wp_doing_cron() &&
280
+ ! \Cleantalk\Variables\Server::in_uri( '/favicon.ico' ) &&
281
+ ! apbct_is_cli()
282
  ){
283
  wp_suspend_cache_addition( true );
284
  apbct_sfw__check();
346
 
347
  $cleantalk_hooked_actions = array();
348
  $cleantalk_ajax_actions_to_check = array();
349
+
350
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
351
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
352
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
353
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
354
 
355
  // Feedback for comments
379
  add_filter('et_pre_insert_answer', 'ct_ajax_hook', 1, 1); // Answers
380
 
381
  // Formidable
382
+ add_filter( 'frm_entries_before_create', 'apbct_form__formidable__testSpam', 10, 2 );
383
+ add_action( 'frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2 );
384
 
385
  // Some of plugins to register a users use AJAX context.
386
  add_filter('registration_errors', 'ct_registration_errors', 1, 3);
388
  add_action('user_register', 'apbct_user_register');
389
 
390
  if(class_exists('BuddyPress')){
391
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
392
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
393
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
394
  add_filter('bp_activity_is_spam_before_save', 'apbct_integration__buddyPres__activityWall', 999 ,2); /* ActivityWall */
395
  add_action('bp_locate_template', 'apbct_integration__buddyPres__getTemplateName', 10, 6);
396
  }
397
 
398
  }
399
+
400
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
401
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
402
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
403
  //Bitrix24 contact form
404
  if ($apbct->settings['forms__general_contact_forms_test'] == 1 &&
405
  !empty($_POST['your-phone']) &&
428
 
429
  // Public pages actions
430
  }else{
 
 
 
431
 
432
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
433
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
434
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
435
 
436
  add_action('wp_enqueue_scripts', 'ct_enqueue_scripts_public');
437
 
613
  }
614
 
615
  function apbct_activation__create_tables( $sqls, $db_prefix = '' ) {
616
+
617
+ if( ! is_array( $sqls ) && empty( $sqls ) ) {
618
+ return;
619
+ }
620
+
621
  global $wpdb;
622
 
623
  $db_prefix = $db_prefix ? $db_prefix : $wpdb->prefix;
inc/cleantalk-pluggable.php CHANGED
@@ -244,6 +244,15 @@ function apbct_is_rest() {
244
  return defined( 'REST_REQUEST' ) && REST_REQUEST;
245
  }
246
 
 
 
 
 
 
 
 
 
 
247
  /**
248
  * Checks if the user is logged in
249
  *
@@ -406,6 +415,13 @@ function apbct_is_skip_request( $ajax = false ) {
406
  {
407
  return 'youzier_login_form';
408
  }
 
 
 
 
 
 
 
409
  // InJob theme lost password skip
410
  if( apbct_is_plugin_active( 'iwjob/iwjob.php' ) &&
411
  isset( $_POST['action'] ) &&
244
  return defined( 'REST_REQUEST' ) && REST_REQUEST;
245
  }
246
 
247
+ /**
248
+ * Checks if the request is the command line access
249
+ *
250
+ * @return boolean
251
+ */
252
+ function apbct_is_cli() {
253
+ return PHP_SAPI === "cli";
254
+ }
255
+
256
  /**
257
  * Checks if the user is logged in
258
  *
415
  {
416
  return 'youzier_login_form';
417
  }
418
+ // Youzify login form skip
419
+ if( apbct_is_plugin_active( 'youzify/youzify.php' ) &&
420
+ isset( $_POST['action'] ) &&
421
+ $_POST['action'] === 'youzify_ajax_login' )
422
+ {
423
+ return 'youzify_login_form';
424
+ }
425
  // InJob theme lost password skip
426
  if( apbct_is_plugin_active( 'iwjob/iwjob.php' ) &&
427
  isset( $_POST['action'] ) &&
inc/cleantalk-public-integrations.php ADDED
@@ -0,0 +1,2692 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Cleantalk\ApbctWP\Helper;
4
+ use Cleantalk\Variables\Server;
5
+
6
+ // MailChimp Premium for Wordpress
7
+ function ct_add_mc4wp_error_message($messages){
8
+
9
+ $messages['ct_mc4wp_response'] = array(
10
+ 'type' => 'error',
11
+ 'text' => 'Your message looks like spam.'
12
+ );
13
+ return $messages;
14
+ }
15
+ add_filter( 'mc4wp_form_messages', 'ct_add_mc4wp_error_message' );
16
+
17
+ /*
18
+ * Function to set validate fucntion for CCF form
19
+ * Input - Сonsistently each form field
20
+ * Returns - String. Validate function
21
+ */
22
+ function ct_ccf($callback, $value, $field_id, $type){
23
+ return 'ct_validate_ccf_submission';
24
+ }
25
+
26
+ /*
27
+ * Validate function for CCF form. Gatheering data. Multiple calls.
28
+ * Input - void. Global $ct_global_temporary_data
29
+ * Returns - String. CleanTalk comment.
30
+ */
31
+ $ct_global_temporary_data = array();
32
+ function ct_validate_ccf_submission($value, $field_id, $required){
33
+ global $ct_global_temporary_data, $apbct;
34
+
35
+ //If the check for contact forms enabled
36
+ if(!$apbct->settings['forms__contact_forms_test']) {
37
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
38
+ return true;
39
+ }
40
+
41
+ //If the check for logged in users enabled
42
+ if($apbct->settings['data__protect_logged_in'] == 1 && is_user_logged_in()) {
43
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
44
+ return true;
45
+ }
46
+
47
+ //Accumulate data
48
+ $ct_global_temporary_data[] = $value;
49
+
50
+ //If it's the last field of the form
51
+ (!isset($ct_global_temporary_data['count']) ? $ct_global_temporary_data['count'] = 1 : $ct_global_temporary_data['count']++);
52
+ $form_id = $_POST['form_id'];
53
+ if($ct_global_temporary_data['count'] != count(get_post_meta( $form_id, 'ccf_attached_fields', true ))) {
54
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
55
+ return true;
56
+ }
57
+
58
+ unset($ct_global_temporary_data['count']);
59
+
60
+ //Getting request params
61
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
62
+
63
+ unset($ct_global_temporary_data);
64
+
65
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
66
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
67
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
68
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
69
+
70
+ if ($subject != '')
71
+ $message['subject'] = $subject;
72
+
73
+ $post_info['comment_type'] = 'feedback_custom_contact_forms';
74
+ $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
75
+
76
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
77
+ ? apbct_js_test('ct_checkjs', $_COOKIE, true)
78
+ : apbct_js_test('ct_checkjs', $_POST);
79
+
80
+ //Making a call
81
+ $base_call_result = apbct_base_call(
82
+ array(
83
+ 'message' => $message,
84
+ 'sender_email' => $sender_email,
85
+ 'sender_nickname' => $sender_nickname,
86
+ 'post_info' => $post_info,
87
+ 'js_on' => $checkjs,
88
+ 'sender_info' => array('sender_url' => null),
89
+ )
90
+ );
91
+
92
+ $ct_result = $base_call_result['ct_result'];
93
+
94
+ return $ct_result->allow == 0 ? $ct_result->comment : true;;
95
+ }
96
+
97
+ function ct_woocommerce_wishlist_check($args){
98
+ global $apbct;
99
+
100
+ //Protect logged in users
101
+ if($args['wishlist_status']) {
102
+ if ( $apbct->settings['data__protect_logged_in'] == 0 ) {
103
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
104
+
105
+ return $args;
106
+ }
107
+ }
108
+
109
+ //If the IP is a Google bot
110
+ $hostname = gethostbyaddr( apbct_get_server_variable( 'REMOTE_ADDR' ) );
111
+ if(!strpos($hostname, 'googlebot.com')) {
112
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
113
+ return $args;
114
+ }
115
+
116
+ //Getting request params
117
+ $message = '';
118
+ $subject = '';
119
+ $email = $args['wishlist_owner_email'];
120
+ if($args['wishlist_first_name']!='' || $args['wishlist_last_name']!='')
121
+ $nickname = trim($args['wishlist_first_name']." ".$args['wishlist_last_name']);
122
+ else
123
+ $nickname = '';
124
+
125
+ $post_info['comment_type'] = 'feedback';
126
+ $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
127
+
128
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
129
+ ? apbct_js_test('ct_checkjs', $_COOKIE, true)
130
+ : apbct_js_test('ct_checkjs', $_POST);
131
+
132
+ //Making a call
133
+ $base_call_result = apbct_base_call(
134
+ array(
135
+ 'message' => $subject." ".$message,
136
+ 'sender_email' => $email,
137
+ 'sender_nickname' => $nickname,
138
+ 'post_info' => $post_info,
139
+ 'js_on' => $checkjs,
140
+ 'sender_info' => array('sender_url' => null),
141
+ )
142
+ );
143
+
144
+ $ct_result = $base_call_result['ct_result'];
145
+
146
+ if ($ct_result->allow == 0)
147
+ wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
148
+ else
149
+ return $args;
150
+ }
151
+
152
+ function apbct_integration__buddyPres__getTemplateName( $located, $template_name, $template_names, $template_locations, $load, $require_once ) {
153
+ global $apbct;
154
+ preg_match("/\/([a-z-_]+)\/buddypress-functions\.php$/", $located, $matches);
155
+ $apbct->buddy_press_tmpl = isset($matches[1]) ? $matches[1] : 'unknown';
156
+ }
157
+
158
+ /**
159
+ * Test BuddyPress activity for spam (post update only)
160
+ *
161
+ * @global SpbcState $apbct
162
+ * @param bool $is_spam
163
+ * @param BP_Activity_Activity $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
164
+ * @return boolean Spam flag
165
+ */
166
+ function apbct_integration__buddyPres__activityWall( $is_spam, $activity_obj = null ){
167
+
168
+ global $apbct;
169
+
170
+ $allowed_post_actions = array('post_update', 'new_activity_comment');
171
+
172
+ if( ! in_array(\Cleantalk\Variables\Post::get('action'), $allowed_post_actions) ||
173
+ $activity_obj === null ||
174
+ ! \Cleantalk\Variables\Post::get('action') ||
175
+ $activity_obj->privacy == 'media' ||
176
+ apbct_exclusions_check()
177
+ ) {
178
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
179
+ return false;
180
+ }
181
+
182
+ $curr_user = get_user_by('id', $activity_obj->user_id);
183
+
184
+ //Making a call
185
+ $base_call_result = apbct_base_call(
186
+ array(
187
+ 'message' => is_string($activity_obj->content) ? $activity_obj->content : '',
188
+ 'sender_email' => $curr_user->data->user_email,
189
+ 'sender_nickname' => $curr_user->data->user_login,
190
+ 'post_info' => array(
191
+ 'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ),
192
+ 'comment_type' => 'buddypress_activitywall',
193
+ ),
194
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
195
+ 'sender_info' => array('sender_url' => null),
196
+ )
197
+ );
198
+
199
+ $ct_result = $base_call_result['ct_result'];
200
+
201
+ if ($ct_result->allow == 0){
202
+ add_action('bp_activity_after_save', 'apbct_integration__buddyPres__activityWall_showResponse', 1, 1);
203
+ $apbct->spam_notification = $ct_result->comment;
204
+ return true;
205
+ }else
206
+ return $is_spam;
207
+ }
208
+
209
+ /**
210
+ * Outputs message to AJAX frontend handler
211
+ *
212
+ * @global SpbcState $apbct
213
+ * @param BP_Activity_Activity $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
214
+ */
215
+ function apbct_integration__buddyPres__activityWall_showResponse( $activity_obj ){
216
+
217
+ global $apbct;
218
+
219
+ // Legacy template
220
+ if($apbct->buddy_press_tmpl === 'bp-legacy'){
221
+ die('<div id="message" class="error bp-ajax-message"><p>'. $apbct->spam_notification .'</p></div>');
222
+ // Nouveau tamplate and others
223
+ }else{
224
+ @header( 'Content-Type: application/json; charset=' . get_option('blog_charset'));
225
+ die(json_encode(array(
226
+ 'success' => false,
227
+ 'data' => array('message' => $apbct->spam_notification),
228
+ )));
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Public function - Tests new private messages (dialogs)
234
+ *
235
+ * @global SpbcState $apbct
236
+ * @param type $bp_message_obj
237
+ * @return void|array with errors if spam has found
238
+ */
239
+ function apbct_integration__buddyPres__private_msg_check( $bp_message_obj){
240
+
241
+ global $apbct;
242
+
243
+ //Check for enabled option
244
+ if(
245
+ $apbct->settings['comments__bp_private_messages'] == 0 ||
246
+ apbct_exclusions_check()
247
+ ) {
248
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
249
+ return;
250
+ }
251
+
252
+ //Check for quantity of comments
253
+ $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER')
254
+ ? CLEANTALK_CHECK_COMMENTS_NUMBER
255
+ : 3;
256
+
257
+ if($apbct->settings['comments__check_comments_number']){
258
+ $args = array(
259
+ 'user_id' => $bp_message_obj->sender_id,
260
+ 'box' => 'sentbox',
261
+ 'type' => 'all',
262
+ 'limit' => $comments_check_number,
263
+ 'page' => null,
264
+ 'search_terms' => '',
265
+ 'meta_query' => array()
266
+ );
267
+ $sentbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
268
+ $cnt_sentbox_msgs = $sentbox_msgs['total'];
269
+ $args['box'] = 'inbox';
270
+ $inbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
271
+ $cnt_inbox_msgs = $inbox_msgs['total'];
272
+
273
+ if(($cnt_inbox_msgs + $cnt_sentbox_msgs) >= $comments_check_number)
274
+ $is_max_comments = true;
275
+ }
276
+
277
+ if(!empty($is_max_comments)) {
278
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
279
+ return;
280
+ }
281
+
282
+ $sender_user_obj = get_user_by('id', $bp_message_obj->sender_id);
283
+
284
+ //Making a call
285
+ $base_call_result = apbct_base_call(
286
+ array(
287
+ 'message' => $bp_message_obj->subject." ".$bp_message_obj->message,
288
+ 'sender_email' => $sender_user_obj->data->user_email,
289
+ 'sender_nickname' => $sender_user_obj->data->user_login,
290
+ 'post_info' => array(
291
+ 'comment_type' => 'buddypress_comment',
292
+ 'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ),
293
+ ),
294
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true)
295
+ ? apbct_js_test('ct_checkjs', $_COOKIE, true)
296
+ : apbct_js_test('ct_checkjs', $_POST),
297
+ 'sender_info' => array('sender_url' => null),
298
+ )
299
+ );
300
+
301
+ $ct_result = $base_call_result['ct_result'];
302
+
303
+ if ($ct_result->allow == 0)
304
+ wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
305
+ }
306
+
307
+ /**
308
+ * Adds hiden filed to deafualt serach form
309
+ *
310
+ * @param $form string
311
+ * @return string
312
+ */
313
+ function apbct_forms__search__addField( $form ){
314
+ global $apbct;
315
+ if($apbct->settings['forms__search_test'] == 1){
316
+ $js_filed = ct_add_hidden_fields('ct_checkjs_search_default', true, false, false, false);
317
+ $form = str_replace('</form>', $js_filed, $form);
318
+ }
319
+ return $form;
320
+ }
321
+
322
+ /**
323
+ * Test default search string for spam
324
+ *
325
+ * @param $search string
326
+ * @return string
327
+ */
328
+ function apbct_forms__search__testSpam( $search ){
329
+
330
+ global $apbct, $cleantalk_executed;
331
+
332
+ if(
333
+ empty($search) ||
334
+ $cleantalk_executed ||
335
+ $apbct->settings['forms__search_test'] == 0 ||
336
+ ( $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() ) // Skip processing for logged in users.
337
+ ){
338
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
339
+ return $search;
340
+ }
341
+
342
+ if(apbct_is_user_logged_in())
343
+ $user = wp_get_current_user();
344
+
345
+ $base_call_result = apbct_base_call(
346
+ array(
347
+ 'message' => $search,
348
+ 'sender_email' => !empty($user) ? $user->user_email : null,
349
+ 'sender_nickname' => !empty($user) ? $user->user_login : null,
350
+ 'post_info' => array('comment_type' => 'site_search_wordpress'),
351
+ //'js_on' => apbct_js_test('ct_checkjs_search_default', $_GET, true),
352
+ )
353
+ );
354
+ $ct_result = $base_call_result['ct_result'];
355
+
356
+ $cleantalk_executed = true;
357
+
358
+ if ($ct_result->allow == 0){
359
+ die($ct_result->comment);
360
+ }
361
+
362
+ return $search;
363
+ }
364
+
365
+ function apbct_search_add_noindex() {
366
+
367
+ global $apbct;
368
+
369
+ if(
370
+ ! is_search() || // If it is search results
371
+ $apbct->settings['forms__search_test'] == 0 ||
372
+ ( $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() ) // Skip processing for logged in users.
373
+ ){
374
+ return ;
375
+ }
376
+
377
+ echo '<!-- meta by Cleantalk AntiSpam Protection plugin -->' . "\n";
378
+ echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
379
+
380
+ }
381
+
382
+ /**
383
+ * Test woocommerce checkout form for spam
384
+ *
385
+ */
386
+ function ct_woocommerce_checkout_check() {
387
+
388
+ global $apbct, $cleantalk_executed;
389
+
390
+ //Getting request params
391
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
392
+
393
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
394
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
395
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
396
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
397
+
398
+ if($subject != '')
399
+ $message = array_merge(array('subject' => $subject), $message);
400
+
401
+ $post_info['comment_type'] = 'order';
402
+ $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
403
+
404
+ //Making a call
405
+ $base_call_result = apbct_base_call(
406
+ array(
407
+ 'message' => $message,
408
+ 'sender_email' => $sender_email,
409
+ 'sender_nickname' => $sender_nickname,
410
+ 'post_info' => $post_info,
411
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
412
+ 'sender_info' => array('sender_url' => null),
413
+ )
414
+ );
415
+
416
+ if( $apbct->settings['forms__wc_register_from_order'] ) {
417
+ $cleantalk_executed = false;
418
+ }
419
+
420
+ $ct_result = $base_call_result['ct_result'];
421
+
422
+ if ($ct_result->allow == 0) {
423
+ wp_send_json(array(
424
+ 'result' => 'failure',
425
+ 'messages' => "<ul class=\"woocommerce-error\"><li>".$ct_result->comment."</li></ul>",
426
+ 'refresh' => 'false',
427
+ 'reload' => 'false'
428
+ ));
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Triggered when adding an item to the shopping cart
434
+ * for un-logged users
435
+ *
436
+ * @param $cart_item_key
437
+ * @param $product_id
438
+ * @param $quantity
439
+ * @param $variation_id
440
+ * @param $variation
441
+ * @param $cart_item_data
442
+ * @return void
443
+ */
444
+
445
+ function apbct_wc__add_to_cart_unlogged_user($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
446
+ global $apbct;
447
+
448
+ if(! apbct_is_user_logged_in() && $apbct->settings['forms__wc_add_to_cart']) {
449
+ /**
450
+ * Getting request params
451
+ * POST contains an array of product information
452
+ * Example: Array
453
+ *(
454
+ * [product_sku] => woo-beanie
455
+ * [product_id] => 15
456
+ * [quantity] => 1
457
+ *)
458
+ */
459
+ $message = $_POST ?: array();
460
+
461
+ $post_info['comment_type'] = 'order__add_to_cart';
462
+ $post_info['post_url'] = Server::get('HTTP_REFERER');
463
+
464
+ //Making a call
465
+ $base_call_result = apbct_base_call(
466
+ array(
467
+ 'message' => $message,
468
+ 'post_info' => $post_info,
469
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
470
+ 'sender_info' => array('sender_url' => null),
471
+ )
472
+ );
473
+
474
+ $ct_result = $base_call_result['ct_result'];
475
+
476
+ if ($ct_result->allow == 0) {
477
+ wp_send_json(array(
478
+ 'result' => 'failure',
479
+ 'messages' => "<ul class=\"woocommerce-error\"><li>" . $ct_result->comment . "</li></ul>",
480
+ 'refresh' => 'false',
481
+ 'reload' => 'false',
482
+ 'response_type' => 'wc_add_to_cart_block'
483
+ ));
484
+ }
485
+ }
486
+ }
487
+
488
+ /**
489
+ * Public function - Tests for Pirate contact froms
490
+ * return NULL
491
+ */
492
+ function apbct_form__piratesForm__testSpam(){
493
+
494
+ global $apbct;
495
+
496
+ //Check for enabled option
497
+ if( !$apbct->settings['forms__contact_forms_test']) {
498
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
499
+ return;
500
+ }
501
+
502
+ //Getting request params
503
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
504
+
505
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
506
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
507
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
508
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
509
+
510
+ if($subject != '')
511
+ $message = array_merge(array('subject' => $subject), $message);
512
+
513
+ $post_info['comment_type'] = 'contact_form_wordpress_feedback_pirate';
514
+ $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
515
+
516
+ //Making a call
517
+ $base_call_result = apbct_base_call(
518
+ array(
519
+ 'message' => $message,
520
+ 'sender_email' => $sender_email,
521
+ 'sender_nickname' => $sender_nickname,
522
+ 'post_info' => $post_info,
523
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
524
+ 'sender_info' => array('sender_url' => null),
525
+ )
526
+ );
527
+
528
+ $ct_result = $base_call_result['ct_result'];
529
+
530
+ if ($ct_result->allow == 0)
531
+ wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
532
+ }
533
+
534
+ /**
535
+ * Adds hidden filed to comment form
536
+ */
537
+ function ct_comment_form($post_id){
538
+
539
+ global $apbct;
540
+
541
+ if (apbct_is_user_enable() === false) {
542
+ return false;
543
+ }
544
+
545
+ if ( !$apbct->settings['forms__comments_test']) {
546
+ return false;
547
+ }
548
+
549
+ ct_add_hidden_fields('ct_checkjs', false, false);
550
+
551
+ return null;
552
+ }
553
+
554
+
555
+ /**
556
+ * Public function - Insert JS code for spam tests
557
+ * return null;
558
+ */
559
+ function apbct_form__formidable__footerScripts($fields, $form) {
560
+
561
+ global $apbct, $ct_checkjs_frm;
562
+
563
+ if ( !$apbct->settings['forms__contact_forms_test'])
564
+ return false;
565
+
566
+ $ct_checkjs_key = ct_get_checkjs_value();
567
+ $ct_frm_base_name = 'form_';
568
+ $ct_frm_name = $ct_frm_base_name . $form->form_key;
569
+
570
+ echo "var input = document.createElement('input');
571
+ input.setAttribute('type', 'hidden');
572
+ input.setAttribute('name', '$ct_checkjs_frm');
573
+ input.setAttribute('value', '$ct_checkjs_key');
574
+ for (i = 0; i < document.forms.length; i++) {
575
+ if (typeof document.forms[i].id == 'string'){
576
+ if(document.forms[i].id.search('$ct_frm_name') != -1) {
577
+ document.forms[i].appendChild(input);
578
+ }
579
+ }
580
+ }";
581
+ }
582
+
583
+ /**
584
+ * Public function - Test Formidable data for spam activity
585
+ * @param $errors
586
+ * @param $form
587
+ *
588
+ * @return array with errors if spam has found
589
+ */
590
+ function apbct_form__formidable__testSpam ( $errors, $form ) {
591
+
592
+ global $apbct;
593
+
594
+ if ( !$apbct->settings['forms__contact_forms_test']) {
595
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
596
+ return $errors;
597
+ }
598
+
599
+ // Skip processing for logged in users.
600
+ if ( !$apbct->settings['data__protect_logged_in'] && is_user_logged_in()) {
601
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
602
+ return $errors;
603
+ }
604
+
605
+ $form_data = array();
606
+ foreach( $_POST['item_meta'] as $key => $value ) {
607
+ $form_data['item_meta[' . $key . ']'] = $value;
608
+ }
609
+
610
+ $ct_temp_msg_data = ct_get_fields_any( $form_data );
611
+
612
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
613
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
614
+ $message = $ct_temp_msg_data['message'] ?: array();
615
+
616
+ // @todo convert key 'NUM' to 'input_meta[NUM]'
617
+ // Adding 'input_meta[]' to every field /Formidable fix/
618
+ // because filed names is 'input_meta[NUM]'
619
+ // Get all scalar values
620
+ $tmp_message = array();
621
+ $tmp_message2 = array();
622
+ foreach( $message as $key => $value ){
623
+ if( is_scalar( $value ) ){
624
+ $tmp_message[ $key ] = $value;
625
+ }else{
626
+ $tmp_message2[ $key ] = $value;
627
+ }
628
+ }
629
+ // Replacing key to input_meta[NUM] for scalar values
630
+ $tmp_message = array_flip($tmp_message);
631
+ foreach($tmp_message as &$value){
632
+ $value = 'item_meta['.$value.']';
633
+ } unset($value);
634
+ $tmp_message = array_flip($tmp_message);
635
+ // Combine it with non-scalar values
636
+ $message = array_merge( $tmp_message, $tmp_message2 );
637
+
638
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
639
+ ? apbct_js_test('ct_checkjs', $_COOKIE, true)
640
+ : apbct_js_test('ct_checkjs', $_POST);
641
+
642
+ $base_call_result = apbct_base_call(
643
+ array(
644
+ 'message' => $message,
645
+ 'sender_email' => $sender_email,
646
+ 'sender_nickname' => $sender_nickname,
647
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_formidable'),
648
+ 'js_on' => $checkjs
649
+ )
650
+ );
651
+ $ct_result = $base_call_result['ct_result'];
652
+
653
+ if ($ct_result->allow == 0) {
654
+ $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
655
+ }
656
+
657
+ return $errors;
658
+ }
659
+
660
+ /**
661
+ * Public filter 'bbp_*' - Get new topic name to global $ct_bbp_topic
662
+ * @param mixed[] $comment Comment string
663
+ * @return mixed[] $comment Comment string
664
+ */
665
+ function ct_bbp_get_topic($topic){
666
+ global $ct_bbp_topic;
667
+
668
+ $ct_bbp_topic=$topic;
669
+
670
+ return $topic;
671
+ }
672
+
673
+ /**
674
+ * Public filter 'bbp_*' - Checks topics, replies by cleantalk
675
+ * @param mixed[] $comment Comment string
676
+ * @return mixed[] $comment Comment string
677
+ */
678
+ function ct_bbp_new_pre_content ($comment) {
679
+
680
+ global $apbct, $current_user;
681
+
682
+ if ( !$apbct->settings['forms__comments_test']) {
683
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
684
+ return $comment;
685
+ }
686
+
687
+ // Skip processing for logged in users and admin.
688
+ if ( !$apbct->settings['data__protect_logged_in'] && is_user_logged_in() ||
689
+ apbct_exclusions_check()
690
+ ) {
691
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
692
+ return $comment;
693
+ }
694
+
695
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
696
+ ? apbct_js_test('ct_checkjs', $_COOKIE, true)
697
+ : apbct_js_test('ct_checkjs', $_POST);
698
+
699
+ $post_info['comment_type'] = 'bbpress_comment';
700
+ $post_info['post_url'] = bbp_get_topic_permalink();
701
+
702
+ if( is_user_logged_in() ) {
703
+ $sender_email = $current_user->user_email;
704
+ $sender_nickname = $current_user->display_name;
705
+ } else {
706
+ $sender_email = isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null;
707
+ $sender_nickname = isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null;
708
+ }
709
+
710
+ $base_call_result = apbct_base_call(
711
+ array(
712
+ 'message' => $comment,
713
+ 'sender_email' => $sender_email,
714
+ 'sender_nickname' => $sender_nickname,
715
+ 'post_info' => $post_info,
716
+ 'js_on' => $checkjs,
717
+ 'sender_info' => array('sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null),
718
+ )
719
+ );
720
+ $ct_result = $base_call_result['ct_result'];
721
+
722
+ if ($ct_result->allow == 0) {
723
+ bbp_add_error('bbp_reply_content', $ct_result->comment);
724
+ }
725
+
726
+ return $comment;
727
+ }
728
+
729
+ function apbct_comment__sanitize_data__before_wp_die($function){
730
+
731
+ global $apbct;
732
+
733
+ $comment_data = wp_unslash($_POST);
734
+
735
+ $user_ID = 0;
736
+
737
+ $comment_type = '';
738
+
739
+ $comment_content = isset($comment_data['comment']) ? (string) $comment_data['comment'] : null;
740
+ $comment_parent = isset($comment_data['comment_parent']) ? (int) absint($comment_data['comment_parent']) : null;
741
+
742
+ $comment_author = isset($comment_data['author']) ? (string) trim(strip_tags($comment_data['author'])) : null;
743
+ $comment_author_email = isset($comment_data['email']) ? (string) trim($comment_data['email']) : null;
744
+ $comment_author_url = isset($comment_data['url']) ? (string) trim($comment_data['url']) : null;
745
+ $comment_post_ID = isset($comment_data['comment_post_ID']) ? (int) $comment_data['comment_post_ID'] : null;
746
+
747
+ if(isset($comment_content, $comment_parent)){
748
+
749
+ $user = function_exists('apbct_wp_get_current_user') ? apbct_wp_get_current_user() : null;
750
+
751
+ if($user && $user->exists()){
752
+ $comment_author = empty($user->display_name) ? $user->user_login : $user->display_name;
753
+ $comment_author_email = $user->user_email;
754
+ $comment_author_url = $user->user_url;
755
+ $user_ID = $user->ID;
756
+ }
757
+
758
+ $apbct->comment_data = compact(
759
+ 'comment_post_ID',
760
+ 'comment_author',
761
+ 'comment_author_email',
762
+ 'comment_author_url',
763
+ 'comment_content',
764
+ 'comment_type',
765
+ 'comment_parent',
766
+ 'user_ID'
767
+ );
768
+
769
+ $function = 'apbct_comment__check_via_wp_die';
770
+
771
+ }
772
+
773
+ return $function;
774
+ }
775
+
776
+ function apbct_comment__check_via_wp_die($message, $title, $args){
777
+ if($title == __('Comment Submission Failure')){
778
+ global $apbct;
779
+ $apbct->validation_error = $message;
780
+ ct_preprocess_comment($apbct->comment_data);
781
+ }
782
+ _default_wp_die_handler($message, $title, $args);
783
+ }
784
+
785
+ /**
786
+ * Public filter 'preprocess_comment' - Checks comment by cleantalk server
787
+ * @param mixed[] $comment Comment data array
788
+ * @return mixed[] New data array of comment
789
+ */
790
+ function ct_preprocess_comment($comment) {
791
+ // this action is called just when WP process POST request (adds new comment)
792
+ // this action is called by wp-comments-post.php
793
+ // after processing WP makes redirect to post page with comment's form by GET request (see above)
794
+ global $current_user, $comment_post_id, $ct_comment_done, $ct_jp_comments, $apbct;
795
+
796
+ // Send email notification for chosen groups of users
797
+ if($apbct->settings['wp__comment_notify'] && !empty($apbct->settings['wp__comment_notify__roles']) && $apbct->data['moderate']){
798
+
799
+ add_filter('notify_post_author', 'apbct_comment__Wordpress__doNotify', 100, 2);
800
+
801
+ $users = get_users(array(
802
+ 'role__in' => $apbct->settings['wp__comment_notify__roles'],
803
+ 'fileds' => array('user_email')
804
+ ));
805
+
806
+ if($users){
807
+ add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotificationGroups', 100, 2);
808
+ add_filter('comment_notification_recipients', 'apbct_comment__Wordpress__changeMailNotificationRecipients', 100, 2);
809
+ foreach($users as $user){
810
+ $emails[] = $user->user_email;
811
+ }
812
+ $apbct->comment_notification_recipients = json_encode($emails);
813
+ }
814
+ }
815
+
816
+ // Skip processing admin.
817
+ if (in_array("administrator", $current_user->roles)){
818
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
819
+ return $comment;
820
+ }
821
+
822
+ $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3;
823
+
824
+ if($apbct->settings['comments__check_comments_number'] && $comment['comment_author_email']){
825
+ $args = array(
826
+ 'author_email' => $comment['comment_author_email'],
827
+ 'status' => 'approve',
828
+ 'count' => false,
829
+ 'number' => $comments_check_number,
830
+ );
831
+ $cnt = count(get_comments($args));
832
+ $is_max_comments = $cnt >= $comments_check_number ? true : false;
833
+ }
834
+
835
+ if (
836
+ ($comment['comment_type']!='trackback') &&
837
+ (
838
+ apbct_is_user_enable() === false ||
839
+ $apbct->settings['forms__comments_test'] == 0 ||
840
+ $ct_comment_done ||
841
+ (isset($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'],'page=wysija_campaigns&action=editTemplate')!==false) ||
842
+ (isset($is_max_comments) && $is_max_comments) ||
843
+ (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['REQUEST_URI'],'/wp-admin/')!==false)
844
+ )
845
+ )
846
+ {
847
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
848
+ return $comment;
849
+ }
850
+
851
+ $local_blacklists = apbct_wp_blacklist_check(
852
+ $comment['comment_author'],
853
+ $comment['comment_author_email'],
854
+ $comment['comment_author_url'],
855
+ $comment['comment_content'],
856
+ apbct_get_server_variable( 'REMOTE_ADDR' ),
857
+ apbct_get_server_variable( 'HTTP_USER_AGENT' )
858
+ );
859
+
860
+ // Go out if author in local blacklists
861
+ if ($comment['comment_type']!='trackback' && $local_blacklists === true) {
862
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
863
+ return $comment;
864
+ }
865
+
866
+ $ct_comment_done = true;
867
+
868
+ $comment_post_id = $comment['comment_post_ID'];
869
+
870
+ // JetPack comments logic
871
+ $post_info['comment_type'] = $ct_jp_comments ? 'jetpack_comment' : $comment['comment_type'];
872
+ $post_info['post_url'] = ct_post_url(null, $comment_post_id);
873
+
874
+ // Comment type
875
+ $post_info['comment_type'] = empty($post_info['comment_type']) ? 'general_comment' : $post_info['comment_type'];
876
+
877
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
878
+ ? apbct_js_test('ct_checkjs', $_COOKIE, true)
879
+ : apbct_js_test('ct_checkjs', $_POST);
880
+
881
+ $example = null;
882
+ if ($apbct->data['relevance_test']) {
883
+ $post = get_post($comment_post_id);
884
+ if ($post !== null){
885
+ $example['title'] = $post->post_title;
886
+ $example['body'] = $post->post_content;
887
+ $example['comments'] = null;
888
+
889
+ $last_comments = get_comments(array('status' => 'approve', 'number' => 10, 'post_id' => $comment_post_id));
890
+ foreach ($last_comments as $post_comment){
891
+ $example['comments'] .= "\n\n" . $post_comment->comment_content;
892
+ }
893
+
894
+ $example = json_encode($example);
895
+ }
896
+
897
+ // Use plain string format if've failed with JSON
898
+ if ($example === false || $example === null){
899
+ $example = ($post->post_title !== null) ? $post->post_title : '';
900
+ $example .= ($post->post_content !== null) ? "\n\n" . $post->post_content : '';
901
+ }
902
+ }
903
+
904
+ // Add honeypot_field field
905
+ $honeypot_field = 1;
906
+
907
+ if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
908
+ if(isset($_POST['url']) && !empty($_POST['url']) && $post_info['comment_type'] === 'comment' && isset($_POST['comment_post_ID'])) {
909
+ $honeypot_field = 0;
910
+ }
911
+ }
912
+
913
+ $base_call_result = apbct_base_call(
914
+ array(
915
+ 'message' => $comment['comment_content'],
916
+ 'example' => $example,
917
+ 'sender_email' => $comment['comment_author_email'],
918
+ 'sender_nickname' => $comment['comment_author'],
919
+ 'post_info' => $post_info,
920
+ 'js_on' => $checkjs,
921
+ 'sender_info' => array(
922
+ 'sender_url' => @$comment['comment_author_url'],
923
+ 'form_validation' => !isset($apbct->validation_error)
924
+ ? null
925
+ : json_encode(array(
926
+ 'validation_notice' => $apbct->validation_error,
927
+ 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
928
+ ))
929
+ ),
930
+ 'honeypot_field' => $honeypot_field
931
+ )
932
+ );
933
+ $ct_result = $base_call_result['ct_result'];
934
+
935
+ ct_hash($ct_result->id);
936
+
937
+ //Don't check trusted users
938
+ if (isset($comment['comment_author_email'])){
939
+ $approved_comments = get_comments(array('status' => 'approve', 'count' => true, 'author_email' => $comment['comment_author_email']));
940
+ $new_user = $approved_comments == 0 ? true : false;
941
+ }
942
+
943
+ // Change comment flow only for new authors
944
+ if (!empty($new_user) || $ct_result->stop_words !== null || $ct_result->spam == 1)
945
+ add_action('comment_post', 'ct_set_meta', 10, 2);
946
+
947
+ if($ct_result->allow){ // Pass if allowed
948
+ if(get_option('comment_moderation') === '1') // Wordpress moderation flag
949
+ add_filter('pre_comment_approved', 'ct_set_not_approved', 999, 2);
950
+ else
951
+ add_filter('pre_comment_approved', 'ct_set_approved', 999, 2);
952
+ // Modify the email notification
953
+ add_filter('comment_notification_text', 'apbct_comment__wordpress__show_blacklists', 100, 2); // Add two blacklist links: by email and IP
954
+ }else{
955
+
956
+ global $ct_comment, $ct_stop_words;
957
+
958
+ $ct_comment = $ct_result->comment;
959
+ $ct_stop_words = $ct_result->stop_words;
960
+
961
+ $err_text = '<center>' . ((defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE == true) ? '' : '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ') . __('Spam protection', 'cleantalk-spam-protect') . "</center><br><br>\n" . $ct_result->comment;
962
+ if( ! $ct_jp_comments ) {
963
+ $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
964
+ }
965
+
966
+ // Terminate. Definitely spam.
967
+ if($ct_result->stop_queue == 1)
968
+ wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments ));
969
+
970
+ // Terminate by user's setting.
971
+ if($ct_result->spam == 3)
972
+ wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments));
973
+
974
+ // Trash comment.
975
+ if($ct_result->spam == 2){
976
+ add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
977
+ add_action('comment_post', 'ct_wp_trash_comment', 997, 2);
978
+ }
979
+
980
+ // Spam comment
981
+ if($ct_result->spam == 1)
982
+ add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
983
+
984
+ // Move to pending folder. Contains stop_words.
985
+ if($ct_result->stop_words){
986
+ add_filter('pre_comment_approved', 'ct_set_not_approved', 998, 2);
987
+ add_action('comment_post', 'ct_mark_red', 998, 2);
988
+ }
989
+
990
+ add_action('comment_post', 'ct_die', 999, 2);
991
+ }
992
+
993
+ if($apbct->settings['comments__remove_comments_links'] == 1){
994
+ $comment['comment_content'] = preg_replace("~(http|https|ftp|ftps)://(.*?)(\s|\n|[,.?!](\s|\n)|$)~", '[Link deleted]', $comment['comment_content']);
995
+ }
996
+
997
+ // Change mail notification if license is out of date
998
+ if($apbct->data['moderate'] == 0){
999
+ $apbct->sender_email = $comment['comment_author_email'];
1000
+ $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
1001
+ add_filter('comment_moderation_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment sent to moderation
1002
+ add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment approved
1003
+ }
1004
+
1005
+ return $comment;
1006
+ }
1007
+
1008
+ /**
1009
+ * Insert a hidden field to registration form
1010
+ * @return null
1011
+ */
1012
+ function ct_register_form() {
1013
+
1014
+ global $ct_checkjs_register_form, $apbct;
1015
+
1016
+ if ($apbct->settings['forms__registrations_test'] == 0) {
1017
+ return false;
1018
+ }
1019
+
1020
+ ct_add_hidden_fields($ct_checkjs_register_form, false, false, false, false);
1021
+
1022
+ return null;
1023
+ }
1024
+
1025
+ /**
1026
+ * Adds notification text to login form - to inform about approved registration
1027
+ * @return null
1028
+ */
1029
+ function ct_login_message($message) {
1030
+
1031
+ global $errors, $apbct, $apbct_cookie_register_ok_label;
1032
+
1033
+ if ($apbct->settings['forms__registrations_test'] != 0){
1034
+ if( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ){
1035
+ if (isset($_COOKIE[$apbct_cookie_register_ok_label])){
1036
+ if(is_wp_error($errors)){
1037
+ $errors->add('ct_message',sprintf(__('Registration approved by %s.', 'cleantalk-spam-protect'), '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk</b>'), 'message');
1038
+ }
1039
+ }
1040
+ }
1041
+ }
1042
+ return $message;
1043
+ }
1044
+
1045
+
1046
+ /**
1047
+ * Test users registration for pPress
1048
+ * @return array with errors
1049
+ */
1050
+ function ct_registration_errors_ppress($reg_errors, $form_id) {
1051
+
1052
+ $email = $_POST['reg_email'];
1053
+ $login = $_POST['reg_username'];
1054
+
1055
+ $reg_errors = ct_registration_errors($reg_errors, $login, $email);
1056
+
1057
+ return $reg_errors;
1058
+ }
1059
+
1060
+ /**
1061
+ * Test users registration for multisite enviroment
1062
+ * @return array with errors
1063
+ */
1064
+ function ct_registration_errors_wpmu($errors) {
1065
+
1066
+ //
1067
+ // Multisite actions
1068
+ //
1069
+ $sanitized_user_login = null;
1070
+ if (isset($errors['user_name'])) {
1071
+ $sanitized_user_login = $errors['user_name'];
1072
+ $wpmu = true;
1073
+ }
1074
+ $user_email = null;
1075
+ if (isset($errors['user_email'])) {
1076
+ $user_email = $errors['user_email'];
1077
+ $wpmu = true;
1078
+ }
1079
+
1080
+ if ($wpmu && isset($errors['errors']->errors) && count($errors['errors']->errors) > 0) {
1081
+ return $errors;
1082
+ }
1083
+
1084
+ $errors['errors'] = ct_registration_errors($errors['errors'], $sanitized_user_login, $user_email);
1085
+
1086
+ // Show CleanTalk errors in user_name field
1087
+ if (isset($errors['errors']->errors['ct_error'])) {
1088
+ $errors['errors']->errors['user_name'] = $errors['errors']->errors['ct_error'];
1089
+ unset($errors['errors']->errors['ct_error']);
1090
+ }
1091
+
1092
+ return $errors;
1093
+ }
1094
+
1095
+ /**
1096
+ * Shell for action register_post
1097
+ *
1098
+ * @param $sanitized_user_login
1099
+ * @param $user_email
1100
+ * @param $errors
1101
+ *
1102
+ * @return void|WP_Error
1103
+ */
1104
+ function ct_register_post($sanitized_user_login, $user_email, $errors) {
1105
+ return ct_registration_errors($errors, $sanitized_user_login, $user_email);
1106
+ }
1107
+
1108
+
1109
+ /**
1110
+ * Check messages for external plugins
1111
+ * @return array with checking result;
1112
+ */
1113
+
1114
+ function ct_test_message($nickname, $email, $ip, $text){
1115
+
1116
+ $base_call_result = apbct_base_call(
1117
+ array(
1118
+ 'message' => $text,
1119
+ 'sender_email' => $email,
1120
+ 'sender_nickname' => $nickname,
1121
+ 'post_info' => array('comment_type' => 'feedback_plugin_check'),
1122
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
1123
+ )
1124
+ );
1125
+
1126
+ $ct_result = $base_call_result['ct_result'];
1127
+
1128
+ $result=Array(
1129
+ 'allow' => $ct_result->allow,
1130
+ 'comment' => $ct_result->comment,
1131
+ );
1132
+ return $result;
1133
+ }
1134
+
1135
+ /**
1136
+ * Check registrations for external plugins
1137
+ * @return array with checking result;
1138
+ */
1139
+ function ct_test_registration($nickname, $email, $ip = null){
1140
+
1141
+ global $ct_checkjs_register_form;
1142
+
1143
+ if(apbct_js_test($ct_checkjs_register_form, $_POST)){
1144
+ $checkjs = apbct_js_test($ct_checkjs_register_form, $_POST);
1145
+ $sender_info['post_checkjs_passed'] = $checkjs;
1146
+ }else{
1147
+ $checkjs = $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1148
+ $sender_info['cookie_checkjs_passed'] = $checkjs;
1149
+ }
1150
+
1151
+ //Making a call
1152
+ $base_call_result = apbct_base_call(
1153
+ array(
1154
+ 'sender_ip' => $ip,
1155
+ 'sender_email' => $email,
1156
+ 'sender_nickname' => $nickname,
1157
+ 'sender_info' => $sender_info,
1158
+ 'js_on' => $checkjs,
1159
+ ),
1160
+ true
1161
+ );
1162
+ $ct_result = $base_call_result['ct_result'];
1163
+
1164
+ $result = array(
1165
+ 'allow' => $ct_result->allow,
1166
+ 'comment' => $ct_result->comment,
1167
+ );
1168
+ return $result;
1169
+ }
1170
+
1171
+ /**
1172
+ * Test users registration
1173
+ *
1174
+ * @param $errors
1175
+ * @param null $sanitized_user_login
1176
+ * @param null $user_email
1177
+ *
1178
+ * @return void|WP_Error
1179
+ */
1180
+ function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
1181
+
1182
+ global $ct_checkjs_register_form, $apbct_cookie_request_id_label, $apbct_cookie_register_ok_label, $apbct_cookie_request_id, $bp, $ct_signup_done, $ct_negative_comment, $apbct, $ct_registration_error_comment, $cleantalk_executed;
1183
+
1184
+ // Go out if a registrered user action
1185
+ if (apbct_is_user_enable() === false) {
1186
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1187
+ return $errors;
1188
+ }
1189
+
1190
+ if ($apbct->settings['forms__registrations_test'] == 0) {
1191
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1192
+ return $errors;
1193
+ }
1194
+
1195
+ // The function already executed
1196
+ // It happens when used ct_register_post();
1197
+ if ($ct_signup_done && is_object($errors) && count($errors->errors) > 0) {
1198
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1199
+ return $errors;
1200
+ }
1201
+
1202
+ // Facebook registration
1203
+ if ($sanitized_user_login === null && isset($_POST['FB_userdata'])){
1204
+ $sanitized_user_login = $_POST['FB_userdata']['name'];
1205
+ $facebook = true;
1206
+ }
1207
+ if ($user_email === null && isset($_POST['FB_userdata'])){
1208
+ $user_email = $_POST['FB_userdata']['email'];
1209
+ $facebook = true;
1210
+ }
1211
+
1212
+ // BuddyPress actions
1213
+ $buddypress = false;
1214
+ if ($sanitized_user_login === null && isset($_POST['signup_username'])) {
1215
+ $sanitized_user_login = $_POST['signup_username'];
1216
+ $buddypress = true;
1217
+ }
1218
+ if ($user_email === null && isset($_POST['signup_email'])) {
1219
+ $user_email = $_POST['signup_email'];
1220
+ $buddypress = true;
1221
+ }
1222
+
1223
+ //
1224
+ // Break tests because we already have servers response
1225
+ //
1226
+ if ($buddypress && $ct_signup_done) {
1227
+ if ($ct_negative_comment) {
1228
+ $bp->signup->errors['signup_username'] = $ct_negative_comment;
1229
+ }
1230
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1231
+ return $errors;
1232
+ }
1233
+
1234
+
1235
+ if(current_filter() == 'woocommerce_registration_errors'){
1236
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1237
+ $checkjs_post = null;
1238
+ $checkjs_cookie = $checkjs;
1239
+ }else{
1240
+ // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1241
+ $checkjs_post = apbct_js_test($ct_checkjs_register_form, $_POST);
1242
+ $checkjs_cookie = apbct_js_test('ct_checkjs', $_COOKIE, true);
1243
+ $checkjs = $checkjs_cookie ? $checkjs_cookie : $checkjs_post;
1244
+ }
1245
+
1246
+ $sender_info = array(
1247
+ 'post_checkjs_passed' => $checkjs_post,
1248
+ 'cookie_checkjs_passed' => $checkjs_cookie,
1249
+ 'form_validation' => ! empty( $errors )
1250
+ ? json_encode( array(
1251
+ 'validation_notice' => $errors->get_error_message(),
1252
+ 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
1253
+ ) )
1254
+ : null,
1255
+ );
1256
+
1257
+ $base_call_result = apbct_base_call(
1258
+ array(
1259
+ 'sender_email' => $user_email,
1260
+ 'sender_nickname' => $sanitized_user_login,
1261
+ 'sender_info' => $sender_info,
1262
+ 'js_on' => $checkjs,
1263
+ ),
1264
+ true
1265
+ );
1266
+ $ct_result = $base_call_result['ct_result'];
1267
+
1268
+ // Change mail notification if license is out of date
1269
+ if($apbct->data['moderate'] == 0 &&
1270
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1271
+ ){
1272
+ $apbct->sender_email = $user_email;
1273
+ $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
1274
+ add_filter('wp_new_user_notification_email_admin', 'apbct_registration__Wordpress__changeMailNotification', 100, 3);
1275
+ }
1276
+
1277
+ $ct_signup_done = true;
1278
+
1279
+ $ct_result = ct_change_plugin_resonse($ct_result, $checkjs);
1280
+
1281
+ $cleantalk_executed = true;
1282
+
1283
+ if ($ct_result->inactive != 0) {
1284
+ ct_send_error_notice($ct_result->comment);
1285
+ return $errors;
1286
+ }
1287
+
1288
+ if ($ct_result->allow == 0) {
1289
+
1290
+ if ($buddypress === true) {
1291
+ $bp->signup->errors['signup_username'] = $ct_result->comment;
1292
+ }elseif(!empty($facebook)){
1293
+ $_POST['FB_userdata']['email'] = '';
1294
+ $_POST['FB_userdata']['name'] = '';
1295
+ return;
1296
+ }elseif(defined('MGM_PLUGIN_NAME')) {
1297
+ ct_die_extended($ct_result->comment);
1298
+ }else{
1299
+ if(is_wp_error($errors))
1300
+ $errors->add('ct_error', $ct_result->comment);
1301
+ $ct_negative_comment = $ct_result->comment;
1302
+ }
1303
+
1304
+ $ct_registration_error_comment = $ct_result->comment;
1305
+
1306
+ } else {
1307
+ if ($ct_result->id !== null) {
1308
+ $apbct_cookie_request_id = $ct_result->id;
1309
+ \Cleantalk\ApbctWP\Variables\Cookie::set($apbct_cookie_register_ok_label, $ct_result->id, time()+10, '/');
1310
+ \Cleantalk\ApbctWP\Variables\Cookie::set($apbct_cookie_request_id_label, $ct_result->id, time()+10, '/');
1311
+ }
1312
+ }
1313
+
1314
+ return $errors;
1315
+ }
1316
+
1317
+ /**
1318
+ * Changes email notification for newly registred user
1319
+ *
1320
+ * @param string $wp_new_user_notification_email_admin Body of email notification
1321
+ * @param array $user User inof
1322
+ * @param string $blogname Blog name
1323
+ * @return string Body for email notification
1324
+ */
1325
+ function apbct_registration__Wordpress__changeMailNotification($wp_new_user_notification_email_admin, $user, $blogname){
1326
+
1327
+ global $apbct;
1328
+
1329
+ $wp_new_user_notification_email_admin['message'] = PHP_EOL
1330
+ .__('CleanTalk AntiSpam: This registration is spam.', 'cleantalk-spam-protect')
1331
+ ."\n" . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
1332
+ ."\n" . 'IP: ' . $apbct->sender_ip
1333
+ ."\n" . 'Email: ' . $apbct->sender_email
1334
+ .PHP_EOL . PHP_EOL .
1335
+ __('Activate protection in your Anti-Spam Dashboard: ', 'clentalk')
1336
+ .'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wp_spam_registration_passed'
1337
+ .($apbct->data['user_token']
1338
+ ? '&iser_token='.$apbct->data['user_token']
1339
+ : ''
1340
+ )
1341
+ .PHP_EOL . '---'
1342
+ .PHP_EOL
1343
+ .$wp_new_user_notification_email_admin['message'];
1344
+
1345
+ return $wp_new_user_notification_email_admin;
1346
+
1347
+
1348
+ }
1349
+
1350
+ /**
1351
+ * Checks Ultimate Members registration for spam
1352
+ *
1353
+ * @param $args forms arguments with names and values
1354
+ *
1355
+ * @return mixed
1356
+ *
1357
+ */
1358
+ function apbct_registration__UltimateMembers__check( $args ){
1359
+
1360
+ if ( isset( UM()->form()->errors ) ) {
1361
+ $sender_info['previous_form_validation'] = true;
1362
+ $sender_info['validation_notice'] = json_encode( UM()->form()->errors );
1363
+ }
1364
+
1365
+ global $apbct, $cleantalk_executed;
1366
+
1367
+ if ($apbct->settings['forms__registrations_test'] == 0) {
1368
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1369
+ return $args;
1370
+ }
1371
+
1372
+
1373
+ $checkjs = apbct_js_test('ct_checkjs_register_form', $args);
1374
+ $sender_info['post_checkjs_passed'] = $checkjs;
1375
+
1376
+ // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1377
+ if ($checkjs == 0) {
1378
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1379
+ $sender_info['cookie_checkjs_passed'] = $checkjs;
1380
+ }
1381
+
1382
+ $base_call_result = apbct_base_call(
1383
+ array(
1384
+ 'sender_email' => $args['user_email'],
1385
+ 'sender_nickname' => $args['user_login'],
1386
+ 'sender_info' => $sender_info,
1387
+ 'js_on' => $checkjs,
1388
+ ),
1389
+ true
1390
+ );
1391
+ $ct_result = $base_call_result['ct_result'];
1392
+
1393
+ $cleantalk_executed = true;
1394
+
1395
+ if ($ct_result->inactive != 0) {
1396
+ ct_send_error_notice($ct_result->comment);
1397
+ return $args;
1398
+ }
1399
+
1400
+ if ($ct_result->allow == 0)
1401
+ UM()->form()->add_error('user_password', $ct_result->comment );
1402
+
1403
+ return $args;
1404
+ }
1405
+
1406
+ /**
1407
+ * Checks registration error and set it if it was dropped
1408
+ * @return errors
1409
+ */
1410
+ function ct_check_registration_erros($errors, $sanitized_user_login = null, $user_email = null) {
1411
+ global $bp, $ct_registration_error_comment;
1412
+
1413
+ if($ct_registration_error_comment){
1414
+
1415
+ if(isset($bp))
1416
+ if(method_exists($bp, 'signup'))
1417
+ if(method_exists($bp->signup, 'errors'))
1418
+ if(isset($bp->signup->errors['signup_username']))
1419
+ if($bp->signup->errors['signup_username'] != $ct_registration_error_comment)
1420
+ $bp->signup->errors['signup_username'] = $ct_registration_error_comment;
1421
+
1422
+ if(isset($errors))
1423
+ if(method_exists($errors, 'errors'))
1424
+ if(isset($errors->errors['ct_error']))
1425
+ if($errors->errors['ct_error'][0] != $ct_registration_error_comment)
1426
+ $errors->add('ct_error', $ct_registration_error_comment);
1427
+
1428
+ }
1429
+ return $errors;
1430
+ }
1431
+
1432
+
1433
+ /**
1434
+ * Set user meta (ct_hash) for successed registration
1435
+ * @return null
1436
+ */
1437
+ function apbct_user_register($user_id) {
1438
+
1439
+ global $apbct_cookie_request_id_label, $apbct_cookie_request_id;
1440
+
1441
+ if ( ! empty( $apbct_cookie_request_id ) ) {
1442
+ update_user_meta($user_id, 'ct_hash', $apbct_cookie_request_id);
1443
+ return;
1444
+ }
1445
+
1446
+ if ( isset($_COOKIE[$apbct_cookie_request_id_label]) ) {
1447
+ if(update_user_meta($user_id, 'ct_hash', $_COOKIE[$apbct_cookie_request_id_label])){
1448
+ \Cleantalk\ApbctWP\Variables\Cookie::set($apbct_cookie_request_id_label, '0', 1, '/');
1449
+ }
1450
+ return;
1451
+ }
1452
+
1453
+ }
1454
+
1455
+
1456
+ /**
1457
+ * Test for JetPack contact form
1458
+ */
1459
+ function ct_grunion_contact_form_field_html($r, $field_label) {
1460
+
1461
+ global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $apbct;
1462
+
1463
+ if ($apbct->settings['forms__contact_forms_test'] == 1 && $ct_jpcf_patched === false && preg_match( "/(text|email)/i", $r)) {
1464
+
1465
+ // Looking for element name prefix
1466
+ $name_patched = false;
1467
+ foreach ($ct_jpcf_fields as $v) {
1468
+ if ($name_patched === false && preg_match("/(g\d-)$v/", $r, $matches)) {
1469
+ $ct_checkjs_jpcf = $matches[1] . $ct_checkjs_jpcf;
1470
+ $name_patched = true;
1471
+ }
1472
+ }
1473
+
1474
+ $r .= ct_add_hidden_fields($ct_checkjs_jpcf, true);
1475
+ $ct_jpcf_patched = true;
1476
+ }
1477
+
1478
+ return $r;
1479
+ }
1480
+ /**
1481
+ * Test for JetPack contact form
1482
+ */
1483
+ function ct_contact_form_is_spam($form) {
1484
+
1485
+ global $ct_checkjs_jpcf, $apbct;
1486
+
1487
+ if ($apbct->settings['forms__contact_forms_test'] == 0) {
1488
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1489
+ return null;
1490
+ }
1491
+
1492
+ $js_field_name = $ct_checkjs_jpcf;
1493
+ foreach ($_POST as $k => $v) {
1494
+ if (preg_match("/^.+$ct_checkjs_jpcf$/", $k))
1495
+ $js_field_name = $k;
1496
+ }
1497
+
1498
+ $sender_email = null;
1499
+ $sender_nickname = null;
1500
+ $message = '';
1501
+ if (isset($form['comment_author_email']))
1502
+ $sender_email = $form['comment_author_email'];
1503
+
1504
+ if (isset($form['comment_author']))
1505
+ $sender_nickname = $form['comment_author'];
1506
+
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' => 'contact_form_wordpress_grunion'),
1516
+ 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1517
+ 'js_on' => apbct_js_test($js_field_name, $_POST),
1518
+ )
1519
+ );
1520
+ $ct_result = $base_call_result['ct_result'];
1521
+
1522
+ if ($ct_result->allow == 0) {
1523
+ global $ct_comment;
1524
+ $ct_comment = $ct_result->comment;
1525
+ ct_die(null, null);
1526
+ exit;
1527
+ }
1528
+
1529
+ return ! $ct_result->allow;
1530
+ }
1531
+
1532
+ function ct_contact_form_is_spam_jetpack($is_spam,$form) {
1533
+ global $ct_checkjs_jpcf, $apbct;
1534
+
1535
+ if ($apbct->settings['forms__contact_forms_test'] == 0) {
1536
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1537
+ return null;
1538
+ }
1539
+
1540
+ $base_call_result = apbct_base_call(
1541
+ array(
1542
+ 'message' => isset($form['comment_content']) ? $form['comment_content'] : '',
1543
+ 'sender_email' => isset($form['comment_author_email']) ? $form['comment_author_email'] : null,
1544
+ 'sender_nickname' => isset($form['comment_author']) ? $form['comment_author'] : null,
1545
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_grunion'),
1546
+ 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1547
+ )
1548
+ );
1549
+ $ct_result = $base_call_result['ct_result'];
1550
+
1551
+ if ($ct_result->allow == 0) {
1552
+ global $ct_comment;
1553
+ $ct_comment = $ct_result->comment;
1554
+ ct_die(null, null);
1555
+ exit;
1556
+ }
1557
+
1558
+ return (bool) !$ct_result->allow;
1559
+ }
1560
+
1561
+ /**
1562
+ * Inserts anti-spam hidden to WP Maintenance Mode (wpmm)
1563
+ */
1564
+ function apbct_form__wpmm__addField(){
1565
+ ct_add_hidden_fields('ct_checkjs', false, true, true);
1566
+ }
1567
+
1568
+ /**
1569
+ * Inserts anti-spam hidden to CF7
1570
+ */
1571
+ function apbct_form__contactForm7__addField($html) {
1572
+ global $ct_checkjs_cf7, $apbct;
1573
+
1574
+
1575
+
1576
+ if ($apbct->settings['forms__contact_forms_test'] == 0) {
1577
+ return $html;
1578
+ }
1579
+
1580
+ $html .= ct_add_hidden_fields($ct_checkjs_cf7, true);
1581
+
1582
+ return $html;
1583
+ }
1584
+
1585
+ /**
1586
+ * Test spam for Contact Fomr 7 (CF7) right before validation
1587
+ *
1588
+ * @global SpbcState $apbct
1589
+ * @param type $result
1590
+ * @param type $tags
1591
+ * @return type
1592
+ */
1593
+ function apbct_form__contactForm7__tesSpam__before_validate($result = null, $tags = null) {
1594
+ global $apbct;
1595
+
1596
+ if ($result && method_exists($result, 'get_invalid_fields')){
1597
+ $invalid_fields = $result->get_invalid_fields();
1598
+ if(!empty($invalid_fields) && is_array($invalid_fields)){
1599
+ $apbct->validation_error = $invalid_fields[key($invalid_fields)]['reason'];
1600
+ apbct_form__contactForm7__testSpam( false );
1601
+ }
1602
+ }
1603
+
1604
+ return $result;
1605
+ }
1606
+
1607
+ /**
1608
+ * Test CF7 message for spam
1609
+ */
1610
+ function apbct_form__contactForm7__testSpam( $spam, $submission = null ) {
1611
+
1612
+ global $ct_checkjs_cf7, $apbct;
1613
+
1614
+ if(
1615
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
1616
+ $spam == false && WPCF7_VERSION < '3.0.0' ||
1617
+ $spam === true && WPCF7_VERSION >= '3.0.0' ||
1618
+ $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() || // Skip processing for logged in users.
1619
+ apbct_exclusions_check__url() ||
1620
+ apbct_exclusions_check__ip() ||
1621
+ isset($apbct->cf7_checked)
1622
+ ){
1623
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1624
+ return $spam;
1625
+ }
1626
+
1627
+ $checkjs = apbct_js_test($ct_checkjs_cf7, $_POST)
1628
+ ? apbct_js_test($ct_checkjs_cf7, $_POST)
1629
+ : apbct_js_test('ct_checkjs', $_COOKIE, true);
1630
+
1631
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
1632
+
1633
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
1634
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
1635
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
1636
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
1637
+ if ($subject != '') {
1638
+ $message = array_merge(array('subject' => $subject), $message);
1639
+ }
1640
+
1641
+ $base_call_result = apbct_base_call(
1642
+ array(
1643
+ 'message' => $message,
1644
+ 'sender_email' => $sender_email,
1645
+ 'sender_nickname' => $sender_nickname,
1646
+ 'js_on' => $checkjs,
1647
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_cf7'),
1648
+ 'sender_info' => array(
1649
+ 'form_validation' => !isset($apbct->validation_error)
1650
+ ? null
1651
+ : json_encode(array(
1652
+ 'validation_notice' => $apbct->validation_error,
1653
+ 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
1654
+ ))
1655
+ ),
1656
+ )
1657
+ );
1658
+
1659
+ $ct_result = $base_call_result['ct_result'];
1660
+
1661
+ // Change mail notification if license is out of date
1662
+ if($apbct->data['moderate'] == 0 &&
1663
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1664
+ ){
1665
+ $apbct->sender_email = $sender_email;
1666
+ $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
1667
+ add_filter('wpcf7_mail_components', 'apbct_form__contactForm7__changeMailNotification');
1668
+ }
1669
+
1670
+ if ($ct_result->allow == 0) {
1671
+
1672
+ global $ct_cf7_comment;
1673
+ $ct_cf7_comment = $ct_result->comment;
1674
+
1675
+ add_filter('wpcf7_display_message', 'apbct_form__contactForm7__showResponse', 10, 2);
1676
+
1677
+ $spam = WPCF7_VERSION >= '3.0.0' ? true : false;
1678
+
1679
+ }
1680
+
1681
+ $apbct->cf7_checked = true;
1682
+
1683
+ return $spam;
1684
+ }
1685
+
1686
+ /**
1687
+ * Changes CF7 status message
1688
+ * @param string $hook URL of hooked page
1689
+ */
1690
+ function apbct_form__contactForm7__showResponse($message, $status = 'spam') {
1691
+ global $ct_cf7_comment;
1692
+
1693
+ if ($status == 'spam') {
1694
+ $message = $ct_cf7_comment;
1695
+ }
1696
+
1697
+ return $message;
1698
+ }
1699
+
1700
+ /**
1701
+ * Changes email notification for succes subscription for Contact Form 7
1702
+ *
1703
+ * @param array $component Arguments for email notification
1704
+ * @return array Arguments for email notification
1705
+ */
1706
+ function apbct_form__contactForm7__changeMailNotification($component){
1707
+
1708
+ global $apbct;
1709
+
1710
+ $component['body'] =
1711
+ __('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
1712
+ .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
1713
+ .PHP_EOL . 'IP: ' . $apbct->sender_ip
1714
+ .PHP_EOL . 'Email: ' . $apbct->sender_email
1715
+ .PHP_EOL . sprintf(
1716
+ __('Activate protection in your Anti-Spam Dashboard: %s.', 'clentalk'),
1717
+ 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=cf7_activate_antispam&user_token='.$apbct->user_token
1718
+ )
1719
+ .PHP_EOL . '---' . PHP_EOL . PHP_EOL
1720
+ .$component['body'];
1721
+
1722
+ return (array) $component;
1723
+ }
1724
+
1725
+ /**
1726
+ * Test Ninja Forms message for spam
1727
+ *
1728
+ * @global SpbcState $apbct
1729
+ * @return void
1730
+ */
1731
+ function apbct_form__ninjaForms__testSpam() {
1732
+
1733
+ global $apbct, $cleantalk_executed;
1734
+
1735
+ if( $cleantalk_executed ){
1736
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1737
+ return;
1738
+ }
1739
+
1740
+ if(
1741
+ $apbct->settings['forms__contact_forms_test'] == 0
1742
+ || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
1743
+ || apbct_exclusions_check__url()
1744
+ ){
1745
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1746
+ return;
1747
+ }
1748
+
1749
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1750
+
1751
+ // Choosing between POST and GET
1752
+ $params = ct_get_fields_any(isset($_GET['ninja_forms_ajax_submit']) || isset($_GET['nf_ajax_submit']) ? $_GET : $_POST);
1753
+
1754
+ $sender_email = ($params['email'] ? $params['email'] : '');
1755
+ $sender_nickname = ($params['nickname'] ? $params['nickname'] : '');
1756
+ $subject = ($params['subject'] ? $params['subject'] : '');
1757
+ $message = ($params['message'] ? $params['message'] : array());
1758
+ if ($subject != '') {
1759
+ $message = array_merge(array('subject' => $subject), $message);
1760
+ }
1761
+
1762
+ //Ninja Forms xml fix
1763
+ foreach ($message as $key => $value){
1764
+ if (strpos($value, '<xml>') !== false)
1765
+ unset($message[$key]);
1766
+ }
1767
+
1768
+ $base_call_result = apbct_base_call(
1769
+ array(
1770
+ 'message' => $message,
1771
+ 'sender_email' => $sender_email,
1772
+ 'sender_nickname' => $sender_nickname,
1773
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_ninja_froms'),
1774
+ 'js_on' => $checkjs,
1775
+ )
1776
+ );
1777
+ $ct_result = $base_call_result['ct_result'];
1778
+
1779
+ // Change mail notification if license is out of date
1780
+ if($apbct->data['moderate'] == 0 &&
1781
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1782
+ ){
1783
+ $apbct->sender_email = $sender_email;
1784
+ $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
1785
+ add_filter('ninja_forms_action_email_message', 'apbct_form__ninjaForms__changeMailNotification', 1, 3);
1786
+ }
1787
+
1788
+ if ($ct_result->allow == 0) {
1789
+
1790
+ // We have to use GLOBAL variable to transfer the comment to apbct_form__ninjaForms__changeResponse() function :(
1791
+ $apbct->response = $ct_result->comment;
1792
+ add_action( 'ninja_forms_before_response', 'apbct_form__ninjaForms__changeResponse', 10, 1 );
1793
+ add_action( 'ninja_forms_action_email_send', 'apbct_form__ninjaForms__stopEmail', 1, 5 ); // Prevent mail notification
1794
+ add_action( 'ninja_forms_save_submission', 'apbct_form__ninjaForms__preventSubmission', 1, 2 ); // Prevent mail notification
1795
+ }
1796
+ }
1797
+
1798
+ function apbct_form__ninjaForms__preventSubmission($some, $form_id){
1799
+ return false;
1800
+ }
1801
+
1802
+ function apbct_form__ninjaForms__stopEmail($some, $action_settings, $message, $headers, $attachments){
1803
+ global $apbct;
1804
+ throw new Exception($apbct->response);
1805
+ }
1806
+
1807
+ function apbct_form__ninjaForms__changeResponse( $data ) {
1808
+
1809
+ global $apbct;
1810
+
1811
+ // Show error message below field found by ID
1812
+ if(array_key_exists('email', $data['fields_by_key'])){
1813
+ // Find ID of EMAIL field
1814
+ $nf_field_id = $data['fields_by_key']['email']['id'];
1815
+ }else{
1816
+ // Find ID of last field (usually SUBMIT)
1817
+ $fields_keys = array_keys($data['fields']);
1818
+ $nf_field_id = array_pop($fields_keys);
1819
+ }
1820
+
1821
+ // Below is modified NJ logic
1822
+ $error = array(
1823
+ 'fields' => array(
1824
+ $nf_field_id => $apbct->response,
1825
+ ),
1826
+ );
1827
+
1828
+ $response = array( 'data' => $data, 'errors' => $error, 'debug' => '' );
1829
+
1830
+ die(wp_json_encode( $response, JSON_FORCE_OBJECT ));
1831
+
1832
+ }
1833
+
1834
+ function apbct_form__seedprod_coming_soon__testSpam() {
1835
+
1836
+ global $apbct;
1837
+
1838
+ if(
1839
+ $apbct->settings['forms__contact_forms_test'] == 0
1840
+ || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
1841
+ || apbct_exclusions_check__url()
1842
+ ){
1843
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1844
+ return;
1845
+ }
1846
+
1847
+ $ct_temp_msg_data = ct_get_fields_any($_REQUEST);
1848
+
1849
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
1850
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
1851
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
1852
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
1853
+ if ($subject != '') {
1854
+ $message = array_merge(array('subject' => $subject), $message);
1855
+ }
1856
+
1857
+ $post_info['comment_type'] = 'contact_form_wordpress_seedprod_coming_soon';
1858
+
1859
+ $base_call_result = apbct_base_call(
1860
+ array(
1861
+ 'message' => $message,
1862
+ 'sender_email' => $sender_email,
1863
+ 'sender_nickname' => $sender_nickname,
1864
+ 'post_info' => $post_info,
1865
+ )
1866
+ );
1867
+
1868
+ $ct_result = $base_call_result['ct_result'];
1869
+ if ($ct_result->allow == 0) {
1870
+ global $ct_comment;
1871
+ $ct_comment = $ct_result->comment;
1872
+
1873
+ $response = array(
1874
+ 'status' => 200,
1875
+ 'html' => "<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>"
1876
+ );
1877
+
1878
+ echo sanitize_text_field($_GET['callback']) . '(' . json_encode($response) . ')';
1879
+ exit();
1880
+ }
1881
+
1882
+ }
1883
+
1884
+ /**
1885
+ * Changes email notification for succes subscription for Ninja Forms
1886
+ *
1887
+ * @param string $message Body of email notification
1888
+ * @return string Body for email notification
1889
+ */
1890
+ function apbct_form__ninjaForms__changeMailNotification($message, $data, $action_settings){
1891
+
1892
+ global $apbct;
1893
+
1894
+ if($action_settings['to'] !== $apbct->sender_email){
1895
+
1896
+ $message .= wpautop(PHP_EOL . '---'
1897
+ .PHP_EOL
1898
+ .__('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
1899
+ .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
1900
+ .PHP_EOL . 'IP: ' . $apbct->sender_ip
1901
+ .PHP_EOL . 'Email: ' . $apbct->sender_email
1902
+ .PHP_EOL .
1903
+ __('Activate protection in your Anti-Spam Dashboard: ', 'clentalk').
1904
+ 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=ninjaform_activate_antispam'.$apbct->user_token
1905
+ );
1906
+ }
1907
+
1908
+ return $message;
1909
+ }
1910
+
1911
+ /**
1912
+ * Inserts anti-spam hidden to WPForms
1913
+ *
1914
+ * @global SpbcState $apbct
1915
+ * @return void
1916
+ */
1917
+ function apbct_form__WPForms__addField($form_data, $some, $title, $description, $errors) {
1918
+
1919
+ global $apbct;
1920
+
1921
+ if($apbct->settings['forms__contact_forms_test'] == 1)
1922
+ ct_add_hidden_fields('ct_checkjs_wpforms', false);
1923
+
1924
+ }
1925
+
1926
+ /**
1927
+ * Gather fields data from submission and store it
1928
+ *
1929
+ * @param array $entry
1930
+ * @param $form
1931
+ *
1932
+ * @return array
1933
+ * @global SpbcState $apbct
1934
+ */
1935
+ function apbct_from__WPForms__gatherData($entry, $form){
1936
+
1937
+ global $apbct;
1938
+ $handled_result = array();
1939
+
1940
+ $entry_fields_data = $entry['fields'] ?: array();
1941
+ $form_fields_info = $form['fields'] ?: array();
1942
+
1943
+ foreach ($form_fields_info as $form_field) {
1944
+ $field_id = $form_field['id'];
1945
+ $field_type = $form_field['type'];
1946
+ $field_label = $form_field['label'] ?: '';
1947
+ if( ! isset( $entry_fields_data[$field_id] ) ){
1948
+ continue;
1949
+ }
1950
+ $entry_field_value = $entry_fields_data[$field_id];
1951
+
1952
+ # search email field
1953
+ if($field_type === 'email') {
1954
+ if( ! isset($handled_result['email']) || empty($handled_result['email'])) {
1955
+ $handled_result['email'] = $entry_field_value;
1956
+ continue;
1957
+ }
1958
+ }
1959
+
1960
+ # search name
1961
+ if($field_type === 'name') {
1962
+ if( ! isset($handled_result['name']) || empty($handled_result['name'])) {
1963
+ if(is_array($entry_field_value)) {
1964
+ $handled_result['name'] = implode(' ', $entry_field_value);
1965
+ } else {
1966
+ $handled_result['name'] = array('nick' => $entry_field_value, 'first' => '', 'last' => '');
1967
+ }
1968
+ continue;
1969
+ }
1970
+ }
1971
+
1972
+ # Add field label as key for result array
1973
+ # add unique key if key exist
1974
+ if($field_label) {
1975
+ $field_label = trim(mb_strtolower($field_label));
1976
+ $field_label = str_replace(' ', '_', $field_label);
1977
+ $field_label = preg_replace('/\W/u', '', $field_label);
1978
+
1979
+ if( ! isset($handled_result[$field_label]) || empty($handled_result[$field_label])) {
1980
+ $handled_result[$field_label] = $entry_field_value;
1981
+ } else {
1982
+ $handled_result[$field_label . rand(0, 100)] = $entry_field_value;
1983
+ }
1984
+ }
1985
+ }
1986
+
1987
+ $apbct->form_data = $handled_result;
1988
+
1989
+ return $entry;
1990
+ }
1991
+
1992
+ /**
1993
+ * Adding error to form entry if message is spam
1994
+ * Call spam test from here
1995
+ *
1996
+ * @param array $errors
1997
+ * @param array $form_data
1998
+ * @return array
1999
+ */
2000
+ function apbct_form__WPForms__showResponse($errors, $form_data) {
2001
+
2002
+ if(empty($errors) || ( isset($form_data['id'], $errors[$form_data['id']]) && !count($errors[$form_data['id']]) ) ){
2003
+
2004
+ $spam_comment = apbct_form__WPForms__testSpam();
2005
+
2006
+ $filed_id = $form_data && !empty($form_data['fields']) && is_array($form_data['fields'])
2007
+ ? key($form_data['fields'])
2008
+ : 0;
2009
+
2010
+ if($spam_comment)
2011
+ $errors[ $form_data['id'] ][ $filed_id ] = $spam_comment;
2012
+
2013
+ }
2014
+
2015
+ return $errors;
2016
+ }
2017
+
2018
+ /**
2019
+ * Test WPForms message for spam
2020
+ * Doesn't hooked anywhere.
2021
+ * Called directly from apbct_form__WPForms__showResponse()
2022
+ *
2023
+ * @global SpbcState $apbct
2024
+ * @global array $apbct->form_data Contains form data
2025
+ * @param array $errors Array of errors to write false result in
2026
+ * @return void|array|null
2027
+ */
2028
+ function apbct_form__WPForms__testSpam() {
2029
+
2030
+ global $apbct;
2031
+
2032
+ if(
2033
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2034
+ $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() // Skip processing for logged in users.
2035
+ ){
2036
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2037
+ return;
2038
+ }
2039
+
2040
+ $checkjs = apbct_js_test('ct_checkjs_wpforms', $_POST);
2041
+
2042
+ $email = $apbct->form_data['email'] ?: null;
2043
+ $nickname = $apbct->form_data['name'] ?: null;
2044
+ $form_data = $apbct->form_data;
2045
+
2046
+ if($email) {
2047
+ unset($form_data['email']);
2048
+ }
2049
+ if($nickname) {
2050
+ unset($form_data['name']);
2051
+ }
2052
+
2053
+ $params = ct_get_fields_any($apbct->form_data, array(), $email);
2054
+
2055
+ if(is_array($params['nickname'])) {
2056
+ $params['nickname'] = implode(' ', $params['nickname']);
2057
+ }
2058
+
2059
+ $sender_email = ($params['email'] ? $params['email'] : '');
2060
+ $sender_nickname = ($params['nickname'] ? $params['nickname'] : '');
2061
+ $subject = ($params['subject'] ? $params['subject'] : '');
2062
+ $message = ($params['message'] ? $params['message'] : array());
2063
+ if ($subject != '') {
2064
+ $message = array_merge(array('subject' => $subject), $message);
2065
+ }
2066
+
2067
+ $base_call_result = apbct_base_call(
2068
+ array(
2069
+ 'message' => $message,
2070
+ 'sender_email' => $sender_email,
2071
+ 'sender_nickname' => $sender_nickname,
2072
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_wp_forms'),
2073
+ 'js_on' => $checkjs,
2074
+ )
2075
+ );
2076
+ $ct_result = $base_call_result['ct_result'];
2077
+
2078
+ // Change mail notification if license is out of date
2079
+ if($apbct->data['moderate'] == 0 &&
2080
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
2081
+ ){
2082
+ $apbct->sender_email = $sender_email;
2083
+ $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
2084
+ add_filter('wpforms_email_message', 'apbct_form__WPForms__changeMailNotification', 100, 2);
2085
+ }
2086
+
2087
+ if ($ct_result->allow == 0){
2088
+ return $ct_result->comment;
2089
+ }
2090
+
2091
+ return null;
2092
+
2093
+ }
2094
+
2095
+ /**
2096
+ * Changes email notification for succes subscription for Ninja Forms
2097
+ *
2098
+ * @param string $message Body of email notification
2099
+ * @param WPForms_WP_Emails $wpforms_email WPForms email class object
2100
+ * @return string Body for email notification
2101
+ */
2102
+ function apbct_form__WPForms__changeMailNotification($message, $wpforms_email){
2103
+
2104
+ global $apbct;
2105
+
2106
+ $message = str_replace('</html>', '', $message);
2107
+ $message = str_replace('</body>', '', $message);
2108
+ $message .= wpautop(PHP_EOL . '---'
2109
+ .PHP_EOL
2110
+ .__('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
2111
+ .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
2112
+ .PHP_EOL . 'IP: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_ip . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_ip . '</a>'
2113
+ .PHP_EOL . 'Email: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_email . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_email . '</a>'
2114
+ .PHP_EOL . sprintf(
2115
+ __('Activate protection in your %sAnti-Spam Dashboard%s.', 'clentalk'),
2116
+ '<a href="https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_activate_antispam" target="_blank">',
2117
+ '</a>'
2118
+ ))
2119
+ .'</body></html>';
2120
+
2121
+ return $message;
2122
+
2123
+ }
2124
+
2125
+ /*
2126
+ * QuForms check spam
2127
+ * works with singl-paged forms
2128
+ * and with multi-paged forms - check only last step of the forms
2129
+ */
2130
+ function ct_quform_post_validate($result, $form) {
2131
+
2132
+ if ( $form->hasPages() ) {
2133
+ $comment_type = 'contact_form_wordpress_quforms_multipage';
2134
+ } else {
2135
+ $comment_type = 'contact_form_wordpress_quforms_singlepage';
2136
+ }
2137
+
2138
+ $ct_temp_msg_data = ct_get_fields_any( $form->getValues() );
2139
+ // @ToDo If we have several emails at the form - will be used only the first detected!
2140
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2141
+
2142
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
2143
+ $base_call_result = apbct_base_call(
2144
+ array(
2145
+ 'message' => $form->getValues(),
2146
+ 'sender_email' => $sender_email,
2147
+ 'post_info' => array('comment_type' => $comment_type),
2148
+ 'js_on' => $checkjs,
2149
+ )
2150
+ );
2151
+
2152
+ $ct_result = $base_call_result['ct_result'];
2153
+ if ($ct_result->allow == 0) {
2154
+ die(json_encode(array('type' => 'error', 'apbct' => array('blocked' => true, 'comment' => $ct_result->comment)), JSON_HEX_QUOT | JSON_HEX_TAG));
2155
+ } else {
2156
+ return $result;
2157
+ }
2158
+
2159
+ return $result;
2160
+
2161
+ }
2162
+
2163
+ /**
2164
+ * Inserts anti-spam hidden to Fast Secure contact form
2165
+ */
2166
+ function ct_si_contact_display_after_fields($string = '', $style = '', $form_errors = array(), $form_id_num = 0) {
2167
+ $string .= ct_add_hidden_fields('ct_checkjs', true);
2168
+ return $string;
2169
+ }
2170
+
2171
+ /**
2172
+ * Test for Fast Secure contact form
2173
+ */
2174
+ function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
2175
+ global $apbct, $cleantalk_executed;
2176
+
2177
+ if (!empty($form_errors)) {
2178
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2179
+ return $form_errors;
2180
+ }
2181
+
2182
+
2183
+ if ($apbct->settings['forms__contact_forms_test'] == 0) {
2184
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2185
+ return $form_errors;
2186
+ }
2187
+
2188
+ // Skip processing because data already processed.
2189
+ if ($cleantalk_executed) {
2190
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2191
+ return $form_errors;
2192
+ }
2193
+
2194
+ //getting info from custom fields
2195
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
2196
+
2197
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2198
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
2199
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2200
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2201
+ if($subject != '') {
2202
+ $message['subject'] = $subject;
2203
+ }
2204
+
2205
+ $base_call_result = apbct_base_call(
2206
+ array(
2207
+ 'message' => $message,
2208
+ 'sender_email' => $sender_email,
2209
+ 'sender_nickname' => $sender_nickname,
2210
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_fscf'),
2211
+ 'js_on' => apbct_js_test('ct_checkjs', $_POST),
2212
+ )
2213
+ );
2214
+
2215
+ $ct_result = $base_call_result['ct_result'];
2216
+
2217
+ $cleantalk_executed = true;
2218
+
2219
+ if ($ct_result->allow == 0) {
2220
+ global $ct_comment;
2221
+ $ct_comment = $ct_result->comment;
2222
+ ct_die(null, null);
2223
+ exit;
2224
+ }
2225
+
2226
+ return $form_errors;
2227
+ }
2228
+
2229
+ /**
2230
+ * Notice for commentators which comment has automatically approved by plugin
2231
+ * @param string $hook URL of hooked page
2232
+ */
2233
+ function ct_comment_text($comment_text) {
2234
+ global $comment, $ct_approved_request_id_label;
2235
+
2236
+ if (isset($_COOKIE[$ct_approved_request_id_label]) && isset($comment->comment_ID)) {
2237
+ $ct_hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
2238
+
2239
+ if ($ct_hash !== '' && $_COOKIE[$ct_approved_request_id_label] == $ct_hash) {
2240
+ $comment_text .= '<br /><br /> <em class="comment-awaiting-moderation">' . __('Comment approved. Anti-spam by CleanTalk.', 'cleantalk-spam-protect') . '</em>';
2241
+ }
2242
+ }
2243
+
2244
+ return $comment_text;
2245
+ }
2246
+
2247
+
2248
+ /**
2249
+ * Checks WordPress Landing Pages raw $_POST values
2250
+ */
2251
+ function ct_check_wplp(){
2252
+
2253
+ global $ct_wplp_result_label, $apbct;
2254
+
2255
+ if (!isset($_COOKIE[$ct_wplp_result_label])) {
2256
+ // First AJAX submit of WPLP form
2257
+ if ($apbct->settings['forms__contact_forms_test'] == 0) {
2258
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2259
+ return;
2260
+ }
2261
+
2262
+ $post_info['comment_type'] = 'feedback';
2263
+ $post_info = json_encode($post_info);
2264
+ if ($post_info === false)
2265
+ $post_info = '';
2266
+
2267
+ $sender_email = '';
2268
+ foreach ($_POST as $v) {
2269
+ if (preg_match("/^\S+@\S+\.\S+$/", $v)) {
2270
+ $sender_email = $v;
2271
+ break;
2272
+ }
2273
+ }
2274
+
2275
+ $message = '';
2276
+ if(array_key_exists('form_input_values', $_POST)){
2277
+ $form_input_values = json_decode(stripslashes($_POST['form_input_values']), true);
2278
+ if (is_array($form_input_values) && array_key_exists('null', $form_input_values))
2279
+ $message = $form_input_values['null'];
2280
+ } else if (array_key_exists('null', $_POST)) {
2281
+ $message = $_POST['null'];
2282
+ }
2283
+
2284
+ $base_call_result = apbct_base_call(
2285
+ array(
2286
+ 'message' => $message,
2287
+ 'sender_email' => $sender_email,
2288
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_wplp'),
2289
+ )
2290
+ );
2291
+
2292
+ $ct_result = $base_call_result['ct_result'];
2293
+
2294
+ if ($ct_result->allow == 0) {
2295
+ $cleantalk_comment = $ct_result->comment;
2296
+ } else {
2297
+ $cleantalk_comment = 'OK';
2298
+ }
2299
+
2300
+ \Cleantalk\ApbctWP\Variables\Cookie::set($ct_wplp_result_label, $cleantalk_comment, strtotime("+5 seconds"), '/');
2301
+ } else {
2302
+ // Next POST/AJAX submit(s) of same WPLP form
2303
+ $cleantalk_comment = $_COOKIE[$ct_wplp_result_label];
2304
+ }
2305
+ if ($cleantalk_comment !== 'OK')
2306
+ ct_die_extended($cleantalk_comment);
2307
+ }
2308
+
2309
+ /**
2310
+ * Places a hidding field to Gravity forms.
2311
+ * @return string
2312
+ */
2313
+ function apbct_form__gravityForms__addField($form_string, $form){
2314
+ $ct_hidden_field = 'ct_checkjs';
2315
+
2316
+ // Do not add a hidden field twice.
2317
+ if (preg_match("/$ct_hidden_field/", $form_string)) {
2318
+ return $form_string;
2319
+ }
2320
+
2321
+ $search = "</form>";
2322
+
2323
+ // Adding JS code
2324
+ $js_code = ct_add_hidden_fields($ct_hidden_field, true, false);
2325
+ $form_string = str_replace($search, $js_code . $search, $form_string);
2326
+
2327
+ // Adding field for multipage form. Look for cleantalk.php -> apbct_cookie();
2328
+ $append_string = isset($form['lastPageButton']) ? "<input type='hidden' name='ct_multipage_form' value='yes'>" : '';
2329
+ $form_string = str_replace($search, $append_string.$search, $form_string);
2330
+
2331
+ return $form_string;
2332
+ }
2333
+
2334
+ /**
2335
+ * Gravity forms anti-spam test.
2336
+ * @return boolean
2337
+ */
2338
+ function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
2339
+
2340
+ global $apbct, $cleantalk_executed, $ct_gform_is_spam, $ct_gform_response;
2341
+
2342
+ if (
2343
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2344
+ $cleantalk_executed // Return unchanged result if the submission was already tested.
2345
+ ) {
2346
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2347
+ return $is_spam;
2348
+ }
2349
+
2350
+ $form_fields_for_ct = array();
2351
+ foreach($entry as $key => $value){
2352
+ if(is_numeric($key))
2353
+ $form_fields_for_ct['input_' . $key]=$value;
2354
+ } unset($key, $value);
2355
+
2356
+ $ct_temp_msg_data = ct_get_fields_any( $form_fields_for_ct );
2357
+
2358
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2359
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
2360
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2361
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2362
+
2363
+ if($subject != '')
2364
+ $message['subject'] = $subject;
2365
+
2366
+ $checkjs = apbct_js_test('ct_checkjs', $_POST)
2367
+ ? apbct_js_test('ct_checkjs', $_POST)
2368
+ : apbct_js_test('ct_checkjs', $_COOKIE, true);
2369
+
2370
+ $base_call_result = apbct_base_call(
2371
+ array(
2372
+ 'message' => $message,
2373
+ 'sender_email' => $sender_email,
2374
+ 'sender_nickname' => $sender_nickname,
2375
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_gravity_forms'),
2376
+ 'js_on' => $checkjs,
2377
+ )
2378
+ );
2379
+
2380
+ $ct_result = $base_call_result['ct_result'];
2381
+ if ($ct_result->allow == 0) {
2382
+ $is_spam = true;
2383
+ $ct_gform_is_spam = true;
2384
+ $ct_gform_response = $ct_result->comment;
2385
+ }
2386
+
2387
+ return $is_spam;
2388
+ }
2389
+
2390
+ function apbct_form__gravityForms__showResponse( $confirmation, $form, $entry, $ajax ){
2391
+
2392
+ global $ct_gform_is_spam, $ct_gform_response;
2393
+
2394
+ if(!empty($ct_gform_is_spam)){
2395
+ $confirmation = '<a id="gf_'.$form['id'].'" class="gform_anchor" ></a><div id="gform_confirmation_wrapper_'.$form['id'].'" class="gform_confirmation_wrapper "><div id="gform_confirmation_message_'.$form['id'].'" class="gform_confirmation_message_'.$form['id'].' gform_confirmation_message"><font style="color: red">'.$ct_gform_response.'</font></div></div>';
2396
+ }
2397
+
2398
+ return $confirmation;
2399
+ }
2400
+
2401
+ /**
2402
+ * Test S2member registration
2403
+ * @return array with errors
2404
+ */
2405
+ function ct_s2member_registration_test($post_key) {
2406
+
2407
+ global $apbct;
2408
+
2409
+ if ($apbct->settings['forms__registrations_test'] == 0) {
2410
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2411
+ return null;
2412
+ }
2413
+
2414
+ $sender_email = isset($_POST[$post_key]['email']) ? sanitize_email($_POST[$post_key]['email']) : null;
2415
+ $sender_nickname = isset($_POST[$post_key]['username']) ? sanitize_email($_POST[$post_key]['username']) : null;
2416
+
2417
+ //Making a call
2418
+ $base_call_result = apbct_base_call(
2419
+ array(
2420
+ 'sender_email' => $sender_email,
2421
+ 'sender_nickname' => $sender_nickname,
2422
+ ),
2423
+ true
2424
+ );
2425
+ $ct_result = $base_call_result['ct_result'];
2426
+
2427
+ if ($ct_result->allow == 0) {
2428
+ ct_die_extended($ct_result->comment);
2429
+ }
2430
+
2431
+ return true;
2432
+ }
2433
+
2434
+ function apbct_form__the7_contact_form() {
2435
+
2436
+ global $cleantalk_executed;
2437
+
2438
+ if ( check_ajax_referer( 'dt_contact_form', 'nonce', false ) && isset($_POST) ) {
2439
+
2440
+ $post_info['comment_type'] = 'contact_the7_theme_contact_form';
2441
+
2442
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
2443
+
2444
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2445
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
2446
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2447
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
2448
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2449
+ if ($subject != '') {
2450
+ $message = array_merge(array('subject' => $subject), $message);
2451
+ }
2452
+
2453
+ // Skip submission if no data found
2454
+ if ($sender_email === ''|| !$contact_form) {
2455
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2456
+ return false;
2457
+ }
2458
+ $cleantalk_executed = true;
2459
+
2460
+ $base_call_result = apbct_base_call(
2461
+ array(
2462
+ 'message' => $message,
2463
+ 'sender_email' => $sender_email,
2464
+ 'sender_nickname' => $sender_nickname,
2465
+ 'post_info' => $post_info,
2466
+ )
2467
+ );
2468
+
2469
+ $ct_result = $base_call_result['ct_result'];
2470
+ if ($ct_result->allow == 0) {
2471
+
2472
+ $response = json_encode(
2473
+ array(
2474
+ 'success' => false ,
2475
+ 'errors' => $ct_result->comment,
2476
+ 'nonce' => wp_create_nonce( 'dt_contact_form' )
2477
+ )
2478
+ );
2479
+
2480
+ // response output
2481
+ header( "Content-Type: application/json" );
2482
+ echo $response;
2483
+
2484
+ // IMPORTANT: don't forget to "exit"
2485
+ exit;
2486
+
2487
+ }
2488
+
2489
+ }
2490
+
2491
+ }
2492
+
2493
+ function apbct_form__elementor_pro__testSpam() {
2494
+
2495
+ global $apbct;
2496
+
2497
+ if(
2498
+ $apbct->settings['forms__contact_forms_test'] == 0
2499
+ || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
2500
+ || apbct_exclusions_check__url()
2501
+ ){
2502
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2503
+ return;
2504
+ }
2505
+
2506
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
2507
+
2508
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2509
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
2510
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2511
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2512
+ if ($subject != '') {
2513
+ $message = array_merge(array('subject' => $subject), $message);
2514
+ }
2515
+
2516
+ $post_info['comment_type'] = 'contact_form_wordpress_elementor_pro';
2517
+
2518
+ $base_call_result = apbct_base_call(
2519
+ array(
2520
+ 'message' => $message,
2521
+ 'sender_email' => $sender_email,
2522
+ 'sender_nickname' => $sender_nickname,
2523
+ 'post_info' => $post_info,
2524
+ )
2525
+ );
2526
+
2527
+ $ct_result = $base_call_result['ct_result'];
2528
+
2529
+ if ($ct_result->allow == 0) {
2530
+
2531
+ wp_send_json_error( array(
2532
+ 'message' => $ct_result->comment,
2533
+ 'data' => array()
2534
+ ) );
2535
+
2536
+ }
2537
+
2538
+ }
2539
+
2540
+ // INEVIO theme integration
2541
+ function apbct_form__inevio__testSpam() {
2542
+
2543
+ global $apbct;
2544
+
2545
+ $theme = wp_get_theme();
2546
+ if(
2547
+ stripos( $theme->get( 'Name' ), 'INEVIO' ) === false ||
2548
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2549
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
2550
+ apbct_exclusions_check__url()
2551
+ ) {
2552
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2553
+ return false;
2554
+ }
2555
+ $form_data = array();
2556
+ parse_str($_POST['data'], $form_data);
2557
+
2558
+ $name = isset($form_data['name']) ? $form_data['name'] : '';
2559
+ $email = isset($form_data['email']) ? $form_data['email'] : '';
2560
+ $message = isset($form_data['message']) ? $form_data['message'] : '';
2561
+
2562
+ $post_info['comment_type'] = 'contact_form_wordpress_inevio_theme';
2563
+
2564
+ $base_call_result = apbct_base_call(
2565
+ array(
2566
+ 'message' => $message,
2567
+ 'sender_email' => $email,
2568
+ 'sender_nickname' => $name,
2569
+ 'post_info' => $post_info,
2570
+ )
2571
+ );
2572
+
2573
+ $ct_result = $base_call_result['ct_result'];
2574
+
2575
+ if ( $ct_result->allow == 0 ) {
2576
+ die(json_encode(array('apbct' => array('blocked' => true, 'comment' => $ct_result->comment,)), JSON_HEX_QUOT | JSON_HEX_TAG));
2577
+ }
2578
+
2579
+ return true;
2580
+
2581
+ }
2582
+
2583
+
2584
+ /**
2585
+ * Filters the 'status' array before register the user
2586
+ * using only by WICITY theme
2587
+ *
2588
+ * @param $success array array( 'status' => 'success' )
2589
+ * @param $data array ['username'] ['password'] ['email']
2590
+ * @return array array( 'status' => 'error' ) or array( 'status' => 'success' ) by default
2591
+ */
2592
+ function apbct_wilcity_reg_validation( $success, $data ) {
2593
+ $check = ct_test_registration( $data['username'], $data['email'], '' );
2594
+ if( $check['allow'] == 0 ) {
2595
+ return array( 'status' => 'error' );
2596
+ }
2597
+ return $success;
2598
+ }
2599
+
2600
+ // Enfold Theme contact form
2601
+ function apbct_form__enfold_contact_form__test_spam( $send, $new_post, $form_params, $obj ){
2602
+
2603
+ global $cleantalk_executed;
2604
+
2605
+ $url_decoded_data = array();
2606
+ foreach( $new_post as $key => $value ) {
2607
+ $url_decoded_data[$key] = urldecode($value);
2608
+ }
2609
+
2610
+ $data = ct_get_fields_any( $url_decoded_data );
2611
+
2612
+ $base_call_result = apbct_base_call(
2613
+ array(
2614
+ 'message' => !empty( $data['message'] ) ? json_encode( $data['message'] ) : '',
2615
+ 'sender_email' => !empty( $data['email'] ) ? $data['email'] : '',
2616
+ 'sender_nickname' => !empty( $data['nickname'] ) ? $data['nickname'] : '',
2617
+ 'post_info' => array(
2618
+ 'comment_type' => 'contact_form_wordpress_enfold'
2619
+ ),
2620
+ )
2621
+ );
2622
+
2623
+ $ct_result = $base_call_result['ct_result'];
2624
+
2625
+ $cleantalk_executed = true;
2626
+
2627
+ if( $ct_result->allow == 0 ) {
2628
+ $obj->submit_error = $ct_result->comment;
2629
+ return null;
2630
+ }
2631
+
2632
+ return $send;
2633
+
2634
+ }
2635
+
2636
+ // Profile Builder integration
2637
+ function apbct_form_profile_builder__check_register ( $errors, $fields, $global_request ){
2638
+
2639
+ if( isset( $global_request['action'] ) && $global_request['action'] == 'register' ) {
2640
+
2641
+ global $cleantalk_executed;
2642
+
2643
+ $data = ct_get_fields_any( $global_request );
2644
+
2645
+ $base_call_result = apbct_base_call(
2646
+ array(
2647
+ 'message' => !empty( $data['message'] ) ? json_encode( $data['message'] ) : '',
2648
+ 'sender_email' => !empty( $data['email'] ) ? $data['email'] : '',
2649
+ 'sender_nickname' => !empty( $data['nickname'] ) ? $data['nickname'] : '',
2650
+ 'post_info' => array(
2651
+ 'comment_type' => 'register_profile_builder'
2652
+ ),
2653
+ ), true
2654
+ );
2655
+
2656
+ $ct_result = $base_call_result['ct_result'];
2657
+
2658
+ $cleantalk_executed = true;
2659
+
2660
+ if( $ct_result->allow == 0 ) {
2661
+ $errors['error'] = $ct_result->comment;
2662
+ $GLOBALS['global_profile_builder_error'] = $ct_result->comment;
2663
+
2664
+ add_filter( 'wppb_general_top_error_message', 'apbct_form_profile_builder__error_message', 1 );
2665
+ }
2666
+
2667
+ }
2668
+ return $errors;
2669
+
2670
+ }
2671
+
2672
+ /**
2673
+ * Profile Builder Integration - add error message in response
2674
+ */
2675
+ function apbct_form_profile_builder__error_message() {
2676
+ return '<p id="wppb_form_general_message" class="wppb-error">'. $GLOBALS['global_profile_builder_error'] .'</p>';
2677
+ }
2678
+
2679
+ // WP Foro register system integration
2680
+ function wpforo_create_profile__check_register( $user_fields ) {
2681
+
2682
+ global $ct_signup_done;
2683
+
2684
+ $ip = Helper::ip__get( 'real', false );
2685
+ $check = ct_test_registration( $user_fields['user_login'], $user_fields['user_email'], $ip );
2686
+ if( $check['allow'] == 0 ) {
2687
+ return array( 'error' => $check['comment'] );
2688
+ }
2689
+
2690
+ $ct_signup_done = true;
2691
+ return $user_fields;
2692
+ }
inc/cleantalk-public-validate.php ADDED
@@ -0,0 +1,407 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use Cleantalk\Variables\Server;
4
+
5
+ /**
6
+ * General test for any contact form
7
+ */
8
+ function ct_contact_form_validate() {
9
+
10
+ global $pagenow ,$apbct, $ct_checkjs_frm;
11
+
12
+ // Exclusios common function
13
+ if ( apbct_exclusions_check(__FUNCTION__) ) {
14
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
15
+ return null;
16
+ }
17
+
18
+ if (@sizeof($_POST)==0 ||
19
+ (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
20
+ (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
21
+ (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action']=='lostpassword') ||
22
+ apbct_is_in_referer( 'lostpassword' ) ||
23
+ apbct_is_in_referer( 'lost-password' ) || //Skip lost-password form check
24
+ (apbct_is_in_uri('/wp-admin/') && (empty($_POST['your-phone']) && empty($_POST['your-email']) && empty($_POST['your-message']))) || //Bitrix24 Contact
25
+ apbct_is_in_uri('wp-login.php') ||
26
+ apbct_is_in_uri('wp-comments-post.php') ||
27
+ apbct_is_in_uri('?provider=facebook&') ||
28
+ apbct_is_in_uri('reset-password/') || // Ticket #13668. Password reset.
29
+ apbct_is_in_referer( '/wp-admin/') ||
30
+ apbct_is_in_uri('/login/') ||
31
+ apbct_is_in_uri( '/my-account/edit-account/') || // WooCommerce edit account page
32
+ apbct_is_in_uri( '/my-account/edit-address/') || // WooCommerce edit account page
33
+ (isset($_POST['action']) && $_POST['action'] == 'save_account_details') || // WooCommerce edit account action
34
+ apbct_is_in_uri( '/peepsoajax/profilefieldsajax.validate_register') ||
35
+ isset($_GET['ptype']) && $_GET['ptype']=='login' ||
36
+ isset($_POST['ct_checkjs_register_form']) ||
37
+ (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit']) ) ||
38
+ $apbct->settings['forms__general_contact_forms_test'] == 0 ||
39
+ isset($_POST['bbp_topic_content']) ||
40
+ isset($_POST['bbp_reply_content']) ||
41
+ isset($_POST['fscf_submitted']) ||
42
+ apbct_is_in_uri('/wc-api') ||
43
+ isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit']) ||
44
+ isset($_POST[$ct_checkjs_frm]) && $apbct->settings['forms__contact_forms_test'] == 1 ||// Formidable forms
45
+ ( isset($_POST['comment_post_ID']) && ! isset($_POST['comment-submit'] ) ) || // The comment form && ! DW Question & Answer
46
+ isset($_GET['for']) ||
47
+ (isset($_POST['log'], $_POST['pwd'])) || //WooCommerce Sensei login form fix
48
+ (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || // WooCommerce recovery password form
49
+ ((isset($_POST['woocommerce-login-nonce']) || isset($_POST['_wpnonce'])) && isset($_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || // WooCommerce login form
50
+ (isset($_POST['wc-api']) && strtolower($_POST['wc-api']) == 'wc_gateway_systempay') || // Woo Systempay payment plugin
51
+ apbct_is_in_uri( 'wc-api=WC_Gateway_Realex_Redirect') || // Woo Realex payment Gateway plugin
52
+ apbct_is_in_uri( 'wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
53
+ (isset($_POST['_wpcf7'], $_POST['_wpcf7_version'], $_POST['_wpcf7_locale'])) || //CF7 fix)
54
+ (isset($_POST['hash'], $_POST['device_unique_id'], $_POST['device_name'])) ||//Mobile Assistant Connector fix
55
+ isset($_POST['gform_submit']) || //Gravity form
56
+ apbct_is_in_uri( 'wc-ajax=get_refreshed_fragments') ||
57
+ (isset($_POST['ccf_form']) && intval($_POST['ccf_form']) == 1) ||
58
+ (isset($_POST['contact_tags']) && strpos($_POST['contact_tags'], 'MBR:') !== false) ||
59
+ (apbct_is_in_uri( 'bizuno.php') && !empty($_POST['bizPass'])) ||
60
+ apbct_is_in_referer( 'my-dashboard/' ) || // ticket_id=7885
61
+ isset($_POST['slm_action'], $_POST['license_key'], $_POST['secret_key'], $_POST['registered_domain']) || // ticket_id=9122
62
+ (isset($_POST['wpforms']['submit']) && $_POST['wpforms']['submit'] == 'wpforms-submit') || // WPForms
63
+ (isset($_POST['action']) && $_POST['action'] == 'grunion-contact-form') || // JetPack
64
+ (isset($_POST['action']) && $_POST['action'] == 'bbp-update-user') || //BBP update user info page
65
+ apbct_is_in_referer( '?wc-api=WC_Gateway_Transferuj' ) || //WC Gateway
66
+ (isset($_GET['mbr'], $_GET['amp;appname'], $_GET['amp;master'])) || // ticket_id=10773
67
+ (isset($_POST['call_function']) && $_POST['call_function'] == 'push_notification_settings') || // Skip mobile requests (push settings)
68
+ apbct_is_in_uri('membership-login') || // Skip login form
69
+ (isset($_GET['cookie-state-change'])) || //skip GDPR plugin
70
+ ( apbct_get_server_variable( 'HTTP_USER_AGENT' ) == 'MailChimp' && apbct_is_in_uri( 'mc4wp-sync-api/webhook-listener') ) || // Mailchimp webhook skip
71
+ apbct_is_in_uri('researcher-log-in') || // Skip login form
72
+ apbct_is_in_uri('admin_aspcms/_system/AspCms_SiteSetting.asp?action=saves') || // Skip admin save callback
73
+ apbct_is_in_uri('?profile_tab=postjobs') || // Skip post vacancies
74
+ (isset($_POST['btn_insert_post_type_hotel']) && $_POST['btn_insert_post_type_hotel'] == 'SUBMIT HOTEL') || // Skip adding hotel
75
+ (isset($_POST['action']) && $_POST['action'] == 'updraft_savesettings') || // Updraft save settings
76
+ isset($_POST['quform_submit']) || //QForms multi-paged form skip
77
+ (isset($_POST['wpum_form']) && $_POST['wpum_form'] == 'login') || //WPUM login skip
78
+ isset($_POST['password']) || // Exception for login form. From Analysis uid=406596
79
+ (isset($_POST['action']) && $_POST['action'] == 'wilcity_reset_password') || // Exception for reset password form. From Analysis uid=430898
80
+ (isset($_POST['action']) && $_POST['action'] == 'wilcity_login') || // Exception for login form. From Analysis uid=430898
81
+ (isset($_POST['qcfsubmit'])) || //Exception for submit quick forms - duplicates with qcfvalidate
82
+ apbct_is_in_uri('tin-canny-learndash-reporting/src/h5p-xapi/process-xapi-statement.php?v=asd') || //Skip Tin Canny plugin
83
+ ( isset( $_POST['na'], $_POST['ts'], $_POST['nhr'] ) && !apbct_is_in_uri( '?na=s' ) ) || // The Newsletter Plugin double requests fix. Ticket #14772
84
+ (isset($_POST['spl_action']) && $_POST['spl_action'] == 'register') || //Skip interal action with empty params
85
+ (isset($_POST['action']) && $_POST['action'] == 'bwfan_insert_abandoned_cart' && apbct_is_in_uri( 'my-account/edit-address' )) || //Skip edit account
86
+ apbct_is_in_uri('login-1') || //Skip login form
87
+ apbct_is_in_uri('recuperacao-de-senha-2') || //Skip form reset password
88
+ apbct_is_in_uri('membermouse/api/request.php') && isset($_POST['membership_level_id'],$_POST['apikey'],$_POST['apisecret']) || // Membermouse API
89
+ ( isset( $_POST['AppKey'] ) && ( isset( $_POST['cbAP'] ) && $_POST['cbAP'] == 'Caspio' ) ) || // Caspio exclusion (ticket #16444)
90
+ isset($_POST['wpforms_id'], $_POST['wpforms_author']) || //Skip wpforms
91
+ ( isset( $_POST['somfrp_action'], $_POST['submitted'] ) && $_POST['somfrp_action'] == 'somfrp_lost_pass' ) || // Frontend Reset Password exclusion
92
+ ( isset( $_POST['action'] ) && $_POST['action'] == 'dokan_save_account_details' ) ||
93
+ \Cleantalk\Variables\Post::get('action') === 'frm_get_lookup_text_value' || // Exception for Formidable multilevel form
94
+ ( isset( $_POST['ihcaction'] ) && $_POST['ihcaction'] == 'reset_pass') || //Reset pass exclusion
95
+ ( isset( $_POST['action'], $_POST['register_unspecified_nonce_field'] ) && $_POST['action'] == 'register' ) || // Profile Builder have a direct integration
96
+ ( isset( $_POST['_wpmem_register_nonce'] ) && wp_verify_nonce( $_POST['_wpmem_register_nonce'], 'wpmem_longform_nonce' ) ) || // WP Members have a direct integration
97
+ apbct_is_in_uri('/settings/') && isset($_POST['submit']) || // Buddypress integration
98
+ apbct_is_in_uri('/settings/notifications/') && isset($_POST['submit']) || // Buddypress integration
99
+ apbct_is_in_uri('/settings/profile/') && isset($_POST['submit']) || // Buddypress integration
100
+ apbct_is_in_uri('/settings/data/') && isset($_POST['submit']) || // Buddypress integration
101
+ apbct_is_in_uri('/settings/delete-account/') && isset($_POST['submit']) || // Buddypress integration
102
+ apbct_is_in_uri('/profile/') && isset($_POST['submit']) || // Buddypress integration
103
+ ( isset( $_POST['action'] ) && $_POST['action'] == 'bwfan_insert_abandoned_cart' ) || // Autonami Marketing Automations - WC Plugin - integration
104
+ ( isset( $_POST['action'] ) && $_POST['action'] == 'check_email_exists' ) // Handling an unknown action check_email_exists
105
+ /* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
106
+ ) {
107
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
108
+ return null;
109
+ }
110
+
111
+ // Skip REST API requests
112
+ if ( Server::isPost() && Server::in_uri( 'rest_route') )
113
+ {
114
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
115
+ return null;
116
+ }
117
+
118
+ //Skip woocommerce checkout
119
+ if (apbct_is_in_uri('wc-ajax=update_order_review') ||
120
+ apbct_is_in_uri('wc-ajax=checkout') ||
121
+ !empty($_POST['woocommerce_checkout_place_order']) ||
122
+ apbct_is_in_uri('wc-ajax=wc_ppec_start_checkout') ||
123
+ apbct_is_in_referer('wc-ajax=update_order_review')
124
+ )
125
+ {
126
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
127
+ return null;
128
+ }
129
+
130
+ //Skip woocommerce add_to_cart
131
+ if( ! empty( $_POST['add-to-cart'] ) )
132
+ {
133
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
134
+ return null;
135
+ }
136
+
137
+ // Do not execute anti-spam test for logged in users.
138
+ if (isset($_COOKIE[LOGGED_IN_COOKIE]) && $apbct->settings['data__protect_logged_in'] != 1) {
139
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
140
+ return null;
141
+ }
142
+ //Skip WP Fusion web hooks
143
+ if ( apbct_is_in_uri('wpf_action') && apbct_is_in_uri('access_key') && isset( $_GET['access_key'] ) ) {
144
+ if( function_exists( 'wp_fusion' ) ) {
145
+ $key = wp_fusion()->settings->get('access_key');
146
+ if ( $key == $_GET['access_key'] ) {
147
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
148
+ return null;
149
+ }
150
+ }
151
+ }
152
+ //Skip system fields for divi
153
+ if (strpos( \Cleantalk\Variables\Post::get('action'), 'et_pb_contactform_submit') === 0) {
154
+ foreach ($_POST as $key => $value) {
155
+ if (strpos($key, 'et_pb_contact_email_fields') === 0) {
156
+ unset($_POST[$key]);
157
+ }
158
+ }
159
+ }
160
+
161
+ if( apbct_is_skip_request( false ) ) {
162
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . '(' . apbct_is_skip_request() . ')', $_POST );
163
+ return false;
164
+ }
165
+
166
+ $post_info['comment_type'] = 'feedback_general_contact_form';
167
+
168
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
169
+
170
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
171
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
172
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
173
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
174
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
175
+ if ($subject != '') {
176
+ $message = array_merge(array('subject' => $subject), $message);
177
+ }
178
+
179
+ // Skip submission if no data found
180
+ if ($sender_email === ''|| !$contact_form) {
181
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
182
+ return false;
183
+ }
184
+
185
+ if(isset($_POST['TellAFriend_Link'])){
186
+ $tmp = $_POST['TellAFriend_Link'];
187
+ unset($_POST['TellAFriend_Link']);
188
+ }
189
+
190
+ $base_call_result = apbct_base_call(
191
+ array(
192
+ 'message' => $message,
193
+ 'sender_email' => $sender_email,
194
+ 'sender_nickname' => $sender_nickname,
195
+ 'post_info' => $post_info,
196
+ 'sender_info' => array( 'sender_email' => urlencode( $sender_email ) ),
197
+ )
198
+ );
199
+
200
+ if(isset($_POST['TellAFriend_Link'])){
201
+ $_POST['TellAFriend_Link']=$tmp;
202
+ }
203
+
204
+ $ct_result = $base_call_result['ct_result'];
205
+ if ($ct_result->allow == 0) {
206
+
207
+ // Recognize contact form an set it's name to $contact_form to use later
208
+ $contact_form = null;
209
+ foreach($_POST as $param => $value){
210
+ if(strpos($param, 'et_pb_contactform_submit') === 0){
211
+ $contact_form = 'contact_form_divi_theme';
212
+ $contact_form_additional = str_replace('et_pb_contactform_submit', '', $param);
213
+ }
214
+ if(strpos($param, 'avia_generated_form') === 0){
215
+ $contact_form = 'contact_form_enfold_theme';
216
+ $contact_form_additional = str_replace('avia_generated_form', '', $param);
217
+ }
218
+ if(!empty($contact_form))
219
+ break;
220
+ }
221
+
222
+ $ajax_call = false;
223
+ if ((defined( 'DOING_AJAX' ) && DOING_AJAX)
224
+ ) {
225
+ $ajax_call = true;
226
+ }
227
+ if ($ajax_call) {
228
+ echo $ct_result->comment;
229
+ } else {
230
+
231
+ global $ct_comment;
232
+ $ct_comment = $ct_result->comment;
233
+ if(isset($_POST['cma-action'])&&$_POST['cma-action']=='add'){
234
+ $result=Array('success'=>0, 'thread_id'=>null,'messages'=>Array($ct_result->comment));
235
+ header("Content-Type: application/json");
236
+ print json_encode($result);
237
+ die();
238
+
239
+ }else if(isset($_POST['TellAFriend_email'])){
240
+ echo $ct_result->comment;
241
+ die();
242
+
243
+ }else if(isset($_POST['gform_submit'])){ // Gravity forms submission
244
+ $response = sprintf("<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'><div id='gform_confirmation_wrapper_1' class='gform_confirmation_wrapper '><div id='gform_confirmation_message_1' class='gform_confirmation_message_1
245
+ gform_confirmation_message'>%s</div></div></body></html>",
246
+ $ct_result->comment
247
+ );
248
+ echo $response;
249
+ die();
250
+
251
+ }elseif(isset($_POST['action']) && $_POST['action'] == 'ct_check_internal'){
252
+ return $ct_result->comment;
253
+
254
+ }elseif(isset($_POST['vfb-submit']) && defined('VFB_VERSION')){
255
+ wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
256
+ // Caldera Contact Forms
257
+ }elseif(isset($_POST['action']) && $_POST['action'] == 'cf_process_ajax_submit'){
258
+ print "<h3 style='color: red;'><red>".$ct_result->comment."</red></h3>";
259
+ die();
260
+ // Mailster
261
+ }elseif(isset($_POST['_referer'], $_POST['formid'], $_POST['email'])){
262
+ $return = array(
263
+ 'success' => false,
264
+ 'html' => '<p>' . $ct_result->comment . '</p>',
265
+ );
266
+ print json_encode($return);
267
+ die();
268
+ // Divi Theme Contact Form. Using $contact_form
269
+ }elseif(!empty($contact_form) && $contact_form == 'contact_form_divi_theme'){
270
+ echo "<div id='et_pb_contact_form{$contact_form_additional}'><h1>Your request looks like spam.</h1><div><p>{$ct_result->comment}</p></div></div>";
271
+ die();
272
+ // Enfold Theme Contact Form. Using $contact_form
273
+ }elseif(!empty($contact_form) && $contact_form == 'contact_form_enfold_theme'){
274
+ echo "<div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1' style='display: block;'><div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1'><h3 class='avia-form-success'>Antispam by CleanTalk: ".$ct_result->comment."</h3><a href='.'><-Back</a></div></div>";
275
+ die();
276
+ }else{
277
+ ct_die(null, null);
278
+ }
279
+ }
280
+ exit;
281
+ }
282
+
283
+ return null;
284
+ }
285
+
286
+ /**
287
+ * General test for any post data
288
+ */
289
+ function ct_contact_form_validate_postdata() {
290
+
291
+ global $apbct, $pagenow,$cleantalk_executed;
292
+
293
+ // Exclusios common function
294
+ if ( apbct_exclusions_check(__FUNCTION__) ) {
295
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
296
+ return null;
297
+ }
298
+
299
+ if (@sizeof($_POST)==0 ||
300
+ (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
301
+ (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
302
+ (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action']=='lostpassword') ||
303
+ apbct_is_in_uri('/checkout/') ||
304
+ /* WooCommerce Service Requests - skip them */
305
+ isset($_GET['wc-ajax']) && (
306
+ $_GET['wc-ajax']=='checkout' ||
307
+ $_GET['wc-ajax']=='get_refreshed_fragments' ||
308
+ $_GET['wc-ajax']=='apply_coupon' ||
309
+ $_GET['wc-ajax']=='remove_coupon' ||
310
+ $_GET['wc-ajax']=='update_shipping_method' ||
311
+ $_GET['wc-ajax']=='get_cart_totals' ||
312
+ $_GET['wc-ajax']=='update_order_review' ||
313
+ $_GET['wc-ajax']=='add_to_cart' ||
314
+ $_GET['wc-ajax']=='remove_from_cart' ||
315
+ $_GET['wc-ajax']=='get_variation' ||
316
+ $_GET['wc-ajax']=='get_customer_location'
317
+ ) ||
318
+ /* END: WooCommerce Service Requests */
319
+ apbct_is_in_uri('/wp-admin/') ||
320
+ apbct_is_in_uri('wp-login.php') ||
321
+ apbct_is_in_uri('wp-comments-post.php') ||
322
+ apbct_is_in_referer('/wp-admin/') ||
323
+ apbct_is_in_uri('/login/') ||
324
+ apbct_is_in_uri('?provider=facebook&') ||
325
+ isset($_GET['ptype']) && $_GET['ptype']=='login' ||
326
+ isset($_POST['ct_checkjs_register_form']) ||
327
+ (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit']) ) ||
328
+ $apbct->settings['forms__general_contact_forms_test']==0 ||
329
+ isset($_POST['bbp_topic_content']) ||
330
+ isset($_POST['bbp_reply_content']) ||
331
+ isset($_POST['fscf_submitted']) ||
332
+ isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit'])||
333
+ apbct_is_in_uri('/wc-api') ||
334
+ apbct_is_in_uri( 'wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
335
+ (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || //WooCommerce recovery password form
336
+ (isset($_POST['woocommerce-login-nonce'], $_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || //WooCommerce login form
337
+ (isset($_POST['provider'], $_POST['authcode']) && $_POST['provider'] == 'Two_Factor_Totp') || //TwoFactor authorization
338
+ (isset($_GET['wc-ajax']) && $_GET['wc-ajax'] == 'sa_wc_buy_now_get_ajax_buy_now_button') || //BuyNow add to cart
339
+ apbct_is_in_uri('/wp-json/wpstatistics/v1/hit') || //WPStatistics
340
+ (isset($_POST['ihcaction']) && $_POST['ihcaction'] == 'login') || //Skip login form
341
+ (isset($_POST['action']) && $_POST['action'] == 'infinite_scroll') || //Scroll
342
+ isset($_POST['gform_submit']) || //Skip gravity checking because of direct integration
343
+ (isset($_POST['lrm_action']) && $_POST['lrm_action'] == 'login') || //Skip login form
344
+ apbct_is_in_uri( 'xmlrpc.php?for=jetpack' ) ||
345
+ apbct_is_in_uri( 'connector=bridge&task=put_sql' )
346
+ ) {
347
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
348
+ return null;
349
+ }
350
+
351
+ $message = ct_get_fields_any_postdata($_POST);
352
+
353
+ // ???
354
+ if(strlen(json_encode($message))<10) {
355
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
356
+ return null;
357
+ }
358
+
359
+
360
+ // Skip if request contains params
361
+ $skip_params = array(
362
+ 'ipn_track_id', // PayPal IPN #
363
+ 'txn_type', // PayPal transaction type
364
+ 'payment_status', // PayPal payment status
365
+ );
366
+ foreach($skip_params as $key=>$value){
367
+ if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST)) {
368
+ do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
369
+ return null;
370
+ }
371
+ }
372
+
373
+ $base_call_result = apbct_base_call(
374
+ array(
375
+ 'message' => $message,
376
+ 'post_info' => array('comment_type' => 'feedback_general_postdata'),
377
+ )
378
+ );
379
+
380
+ $cleantalk_executed=true;
381
+
382
+ $ct_result = $base_call_result['ct_result'];
383
+
384
+ if ($ct_result->allow == 0) {
385
+
386
+ if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
387
+ global $ct_comment;
388
+ $ct_comment = $ct_result->comment;
389
+ if(isset($_POST['cma-action'])&&$_POST['cma-action']=='add')
390
+ {
391
+ $result=Array('success'=>0, 'thread_id'=>null,'messages'=>Array($ct_result->comment));
392
+ header("Content-Type: application/json");
393
+ print json_encode($result);
394
+ die();
395
+ }
396
+ else
397
+ {
398
+ ct_die(null, null);
399
+ }
400
+ } else {
401
+ echo $ct_result->comment;
402
+ }
403
+ exit;
404
+ }
405
+
406
+ return null;
407
+ }
inc/cleantalk-public.php CHANGED
@@ -1,6 +1,5 @@
1
  <?php
2
 
3
- use Cleantalk\ApbctWP\Helper;
4
  use Cleantalk\Variables\Server;
5
 
6
  /**
@@ -9,26 +8,26 @@ use Cleantalk\Variables\Server;
9
  */
10
  function apbct_init() {
11
 
12
- global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $apbct, $test_external_forms, $cleantalk_executed, $wpdb;
13
-
14
  // Pixel
15
  if( $apbct->settings['data__pixel'] ){
16
-
17
  $pixel_hash = md5(
18
  \Cleantalk\Common\Helper::ip__get()
19
  . $apbct->api_key
20
  . \Cleantalk\Common\Helper::time__get_interval_start( 3600 * 3 ) // Unique for every 3 hours
21
  );
22
-
23
  // Change server each 3 hours depending on current time interval
24
  $servers = array_keys( \Cleantalk\Common\Helper::$cleantalks_moderate_servers );
25
  $server_num = \Cleantalk\Common\Helper::time__get_interval_start( 3600 * 3 ) % count($servers);
26
  $pixel_server = $servers[ $server_num ];
27
-
28
  $apbct->pixel_url = 'https://' . $pixel_server . '/pixel/' . $pixel_hash . '.gif';
29
-
30
  }
31
-
32
  //Check internal forms with such "action" http://wordpress.loc/contact-us/some_script.php
33
  if((isset($_POST['action']) && $_POST['action'] == 'ct_check_internal') &&
34
  $apbct->settings['forms__check_internal']
@@ -58,7 +57,7 @@ function apbct_init() {
58
 
59
  // Fixing form and directs it this site
60
  if($apbct->settings['forms__check_external__capture_buffer'] && !is_admin() && !apbct_is_ajax() && !apbct_is_post() && apbct_is_user_enable() && !(defined('DOING_CRON') && DOING_CRON) && !(defined('XMLRPC_REQUEST') && XMLRPC_REQUEST)){
61
-
62
  if (defined('CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL') && is_string(CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL)) {
63
  $catch_buffer = false;
64
  $urls = explode(',', CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL);
@@ -69,7 +68,7 @@ function apbct_init() {
69
  }else{
70
  $catch_buffer = true;
71
  }
72
-
73
  if( $catch_buffer ){
74
  add_action('wp', 'apbct_buffer__start');
75
  add_action('shutdown', 'apbct_buffer__end', 0);
@@ -127,13 +126,6 @@ function apbct_init() {
127
  unset($_POST['ct_checkjs_register_form']);
128
  ct_contact_form_validate();
129
  }
130
- /*if(isset($_GET['ait-action'])&&$_GET['ait-action']=='register')
131
- {
132
- $tmp=$_POST['redirect_to'];
133
- unset($_POST['redirect_to']);
134
- ct_contact_form_validate();
135
- $_POST['redirect_to']=$tmp;
136
- }*/
137
  }
138
 
139
  if($apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7']))
@@ -142,10 +134,10 @@ function apbct_init() {
142
  //add_action('wp_footer','ct_ajaxurl');
143
 
144
  // Fast Secure contact form
145
- if(defined('FSCF_VERSION')){
146
- add_filter('si_contact_display_after_fields', 'ct_si_contact_display_after_fields');
147
- add_filter('si_contact_form_validate', 'ct_si_contact_form_validate');
148
- }
149
 
150
  // WooCommerce registration
151
  if(class_exists('WooCommerce')){
@@ -167,7 +159,6 @@ function apbct_init() {
167
 
168
 
169
  // JetPack Contact form
170
- $jetpack_active_modules = false;
171
  if(defined('JETPACK__VERSION'))
172
  {
173
  // Checking Jetpack contact form
@@ -199,28 +190,28 @@ function apbct_init() {
199
  }
200
 
201
  // WP Maintenance Mode (wpmm)
202
- add_action('wpmm_head', 'apbct_form__wpmm__addField', 1);
203
 
204
  // Contact Form7
205
- if(defined('WPCF7_VERSION')){
206
- add_filter('wpcf7_form_elements', 'apbct_form__contactForm7__addField');
207
- add_filter('wpcf7_validate', 'apbct_form__contactForm7__tesSpam__before_validate', 999, 2);
208
- $hook = WPCF7_VERSION >= '3.0.0' ? 'wpcf7_spam' : 'wpcf7_acceptance';
209
- $num_arg = WPCF7_VERSION >= '5.3.0' ? 2 : 1;
210
- add_filter( $hook, 'apbct_form__contactForm7__testSpam', 9999, $num_arg );
211
- }
212
 
213
  // Formidable
214
- add_filter( 'frm_entries_before_create', 'apbct_rorm__formidable__testSpam', 10, 2 );
215
- add_action( 'frm_entries_footer_scripts', 'apbct_rorm__formidable__footerScripts', 20, 2 );
216
 
217
  // BuddyPress
218
- if(class_exists('BuddyPress')){
219
- add_action('bp_before_registration_submit_buttons','ct_register_form',1);
220
- add_action('messages_message_before_save', 'apbct_integration__buddyPres__private_msg_check', 1);
221
- add_filter('bp_signup_validate', 'ct_registration_errors',1);
222
- add_filter('bp_signup_validate', 'ct_check_registration_erros', 999999);
223
- }
224
 
225
  if(defined('PROFILEPRESS_SYSTEM_FILE_PATH')){
226
  add_filter('pp_registration_validation', 'ct_registration_errors_ppress', 11, 2);
@@ -228,17 +219,17 @@ function apbct_init() {
228
 
229
 
230
  // bbPress
231
- if(class_exists('bbPress')){
232
- add_filter('bbp_new_topic_pre_title', 'ct_bbp_get_topic', 1);
233
- add_filter('bbp_new_topic_pre_content', 'ct_bbp_new_pre_content', 1);
234
- add_filter('bbp_new_reply_pre_content', 'ct_bbp_new_pre_content', 1);
235
- add_action('bbp_theme_before_topic_form_content', 'ct_comment_form');
236
- add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
237
- }
238
 
239
  //Custom Contact Forms
240
- if(defined('CCF_VERSION'))
241
- add_filter('ccf_field_validator', 'ct_ccf', 1, 4);
242
 
243
  add_action('comment_form', 'ct_comment_form');
244
 
@@ -252,17 +243,17 @@ function apbct_init() {
252
  }
253
 
254
  // S2member. intercept POST
255
- if (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION')){
256
- $post_keys = array_keys($_POST);
257
- foreach($post_keys as $post_key){
258
-
259
- // Detect POST keys like /s2member_pro.*registration/
260
- if(strpos($post_key, 's2member') !== false && strpos($post_key, 'registration') !== false){
261
- ct_s2member_registration_test($post_key);
262
- break;
263
- }
264
  }
265
  }
 
266
 
267
  // New user approve hack
268
  // https://wordpress.org/plugins/new-user-approve/
@@ -273,27 +264,26 @@ function apbct_init() {
273
  // Wilcity theme registration validation fix
274
  add_filter( 'wilcity/filter/wiloke-listing-tools/validate-before-insert-account', 'apbct_wilcity_reg_validation', 10, 2 );
275
 
276
-
277
  // Gravity forms
278
- if (defined('GF_MIN_WP_VERSION')) {
279
- add_filter('gform_get_form_filter', 'apbct_form__gravityForms__addField', 10, 2);
280
- add_filter('gform_entry_is_spam', 'apbct_form__gravityForms__testSpam', 999, 3);
281
- add_filter('gform_confirmation', 'apbct_form__gravityForms__showResponse', 999, 4 );
282
- }
283
 
284
  //Pirate forms
285
- if(defined('PIRATE_FORMS_VERSION')){
286
- if(isset($_POST['pirate-forms-contact-name']) && $_POST['pirate-forms-contact-name'] && isset($_POST['pirate-forms-contact-email']) && $_POST['pirate-forms-contact-email'])
287
- apbct_form__piratesForm__testSpam();
288
- }
289
 
290
  // WPForms
291
- // Adding fields
292
- add_action('wpforms_frontend_output', 'apbct_form__WPForms__addField', 1000, 5);
293
- // Gathering data to validate
294
- add_filter('wpforms_process_before_filter', 'apbct_from__WPForms__gatherData', 100, 2);
295
- // Do spam check
296
- add_filter('wpforms_process_initial_errors', 'apbct_form__WPForms__showResponse', 100, 2);
297
 
298
  // QForms integration
299
  add_filter( 'quform_post_validate', 'ct_quform_post_validate', 10, 2 );
@@ -335,7 +325,7 @@ function apbct_init() {
335
  ct_contact_form_validate();
336
  }
337
 
338
- if (apbct_is_user_enable()) {
339
 
340
  if ($apbct->settings['forms__general_contact_forms_test'] == 1 && !isset($_POST['comment_post_ID']) && !isset($_GET['for'])){
341
  add_action( 'init', 'ct_contact_form_validate', 999 );
@@ -467,7 +457,7 @@ function apbct_buffer_modify_by_dom() {
467
  }
468
 
469
  } unset($form);
470
-
471
  $html = $dom->getElementsByTagName('html');
472
 
473
  return is_object( $html ) && isset( $html[0], $html[0]->childNodes, $html[0]->childNodes[0] ) && $dom->getElementsByTagName( 'rss' )->length == 0
@@ -476,572 +466,6 @@ function apbct_buffer_modify_by_dom() {
476
 
477
  }
478
 
479
- // MailChimp Premium for Wordpress
480
- function ct_add_mc4wp_error_message($messages){
481
-
482
- $messages['ct_mc4wp_response'] = array(
483
- 'type' => 'error',
484
- 'text' => 'Your message looks like spam.'
485
- );
486
- return $messages;
487
- }
488
- add_filter( 'mc4wp_form_messages', 'ct_add_mc4wp_error_message' );
489
-
490
- /*
491
- * Function to set validate fucntion for CCF form
492
- * Input - Сonsistently each form field
493
- * Returns - String. Validate function
494
- */
495
- function ct_ccf($callback, $value, $field_id, $type){
496
- /*
497
- if($type == 'name')
498
- $ct_global_temporary_data['name'] = $value;
499
- elseif($type == 'email')
500
- $ct_global_temporary_data['email'] = $value;
501
- else
502
- $ct_global_temporary_data[] = $value;
503
- //*/
504
- return 'ct_validate_ccf_submission';
505
- }
506
- /*
507
- * Validate function for CCF form. Gatheering data. Multiple calls.
508
- * Input - void. Global $ct_global_temporary_data
509
- * Returns - String. CleanTalk comment.
510
- */
511
- $ct_global_temporary_data = array();
512
- function ct_validate_ccf_submission($value, $field_id, $required){
513
- global $ct_global_temporary_data, $apbct;
514
-
515
-
516
-
517
- //If the check for contact forms enabled
518
- if(!$apbct->settings['forms__contact_forms_test']) {
519
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
520
- return true;
521
- }
522
-
523
- //If the check for logged in users enabled
524
- if($apbct->settings['data__protect_logged_in'] == 1 && is_user_logged_in()) {
525
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
526
- return true;
527
- }
528
-
529
-
530
- //Accumulate data
531
- $ct_global_temporary_data[] = $value;
532
-
533
- //If it's the last field of the form
534
- (!isset($ct_global_temporary_data['count']) ? $ct_global_temporary_data['count'] = 1 : $ct_global_temporary_data['count']++);
535
- $form_id = $_POST['form_id'];
536
- if($ct_global_temporary_data['count'] != count(get_post_meta( $form_id, 'ccf_attached_fields', true ))) {
537
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
538
- return true;
539
- }
540
-
541
- unset($ct_global_temporary_data['count']);
542
-
543
- //Getting request params
544
- $ct_temp_msg_data = ct_get_fields_any($_POST);
545
-
546
- unset($ct_global_temporary_data);
547
-
548
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
549
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
550
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
551
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
552
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
553
-
554
- if ($subject != '')
555
- $message['subject'] = $subject;
556
-
557
- $post_info['comment_type'] = 'feedback_custom_contact_forms';
558
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
559
-
560
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
561
- ? apbct_js_test('ct_checkjs', $_COOKIE, true)
562
- : apbct_js_test('ct_checkjs', $_POST);
563
-
564
- //Making a call
565
- $base_call_result = apbct_base_call(
566
- array(
567
- 'message' => $message,
568
- 'sender_email' => $sender_email,
569
- 'sender_nickname' => $sender_nickname,
570
- 'post_info' => $post_info,
571
- 'js_on' => $checkjs,
572
- 'sender_info' => array('sender_url' => null),
573
- )
574
- );
575
-
576
- $ct_result = $base_call_result['ct_result'];
577
-
578
- return $ct_result->allow == 0 ? $ct_result->comment : true;;
579
- }
580
-
581
- function ct_woocommerce_wishlist_check($args){
582
- global $apbct;
583
-
584
-
585
-
586
- //Protect logged in users
587
- if($args['wishlist_status'])
588
- if($apbct->settings['data__protect_logged_in'] == 0) {
589
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
590
- return $args;
591
- }
592
-
593
-
594
- //If the IP is a Google bot
595
- $hostname = gethostbyaddr( apbct_get_server_variable( 'REMOTE_ADDR' ) );
596
- if(!strpos($hostname, 'googlebot.com')) {
597
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
598
- return $args;
599
- }
600
-
601
-
602
- //Getting request params
603
- $message = '';
604
- $subject = '';
605
- $email = $args['wishlist_owner_email'];
606
- if($args['wishlist_first_name']!='' || $args['wishlist_last_name']!='')
607
- $nickname = trim($args['wishlist_first_name']." ".$args['wishlist_last_name']);
608
- else
609
- $nickname = '';
610
-
611
- $post_info['comment_type'] = 'feedback';
612
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
613
-
614
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
615
- ? apbct_js_test('ct_checkjs', $_COOKIE, true)
616
- : apbct_js_test('ct_checkjs', $_POST);
617
-
618
- //Making a call
619
- $base_call_result = apbct_base_call(
620
- array(
621
- 'message' => $subject." ".$message,
622
- 'sender_email' => $email,
623
- 'sender_nickname' => $nickname,
624
- 'post_info' => $post_info,
625
- 'js_on' => $checkjs,
626
- 'sender_info' => array('sender_url' => null),
627
- )
628
- );
629
-
630
- $ct_result = $base_call_result['ct_result'];
631
-
632
- if ($ct_result->allow == 0)
633
- wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
634
- else
635
- return $args;
636
- }
637
-
638
- function apbct_integration__buddyPres__getTemplateName( $located, $template_name, $template_names, $template_locations, $load, $require_once ) {
639
- global $apbct;
640
- preg_match("/\/([a-z-_]+)\/buddypress-functions\.php$/", $located, $matches);
641
- $apbct->buddy_press_tmpl = isset($matches[1]) ? $matches[1] : 'unknown';
642
- }
643
-
644
- /**
645
- * Test BuddyPress activity for spam (post update only)
646
- *
647
- * @global SpbcState $apbct
648
- * @param bool $is_spam
649
- * @param BP_Activity_Activity $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
650
- * @return boolean Spam flag
651
- */
652
- function apbct_integration__buddyPres__activityWall( $is_spam, $activity_obj = null ){
653
-
654
- global $apbct;
655
-
656
- $allowed_post_actions = array('post_update', 'new_activity_comment');
657
-
658
- if( ! in_array(\Cleantalk\Variables\Post::get('action'), $allowed_post_actions) ||
659
- $activity_obj === null ||
660
- ! \Cleantalk\Variables\Post::get('action') ||
661
- $activity_obj->privacy == 'media' ||
662
- apbct_exclusions_check()
663
- ) {
664
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
665
- return false;
666
- }
667
-
668
- $curr_user = get_user_by('id', $activity_obj->user_id);
669
-
670
- //Making a call
671
- $base_call_result = apbct_base_call(
672
- array(
673
- 'message' => is_string($activity_obj->content) ? $activity_obj->content : '',
674
- 'sender_email' => $curr_user->data->user_email,
675
- 'sender_nickname' => $curr_user->data->user_login,
676
- 'post_info' => array(
677
- 'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ),
678
- 'comment_type' => 'buddypress_activitywall',
679
- ),
680
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
681
- 'sender_info' => array('sender_url' => null),
682
- )
683
- );
684
-
685
- $ct_result = $base_call_result['ct_result'];
686
-
687
- if ($ct_result->allow == 0){
688
- add_action('bp_activity_after_save', 'apbct_integration__buddyPres__activityWall_showResponse', 1, 1);
689
- $apbct->spam_notification = $ct_result->comment;
690
- return true;
691
- }else
692
- return $is_spam;
693
- }
694
-
695
- /**
696
- * Outputs message to AJAX frontend handler
697
- *
698
- * @global SpbcState $apbct
699
- * @param BP_Activity_Activity $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
700
- */
701
- function apbct_integration__buddyPres__activityWall_showResponse( $activity_obj ){
702
-
703
- global $apbct;
704
-
705
- // Legacy template
706
- if($apbct->buddy_press_tmpl === 'bp-legacy'){
707
- die('<div id="message" class="error bp-ajax-message"><p>'. $apbct->spam_notification .'</p></div>');
708
- // Nouveau tamplate and others
709
- }else{
710
- @header( 'Content-Type: application/json; charset=' . get_option('blog_charset'));
711
- die(json_encode(array(
712
- 'success' => false,
713
- 'data' => array('message' => $apbct->spam_notification),
714
- )));
715
- }
716
- }
717
-
718
- /**
719
- * Public function - Tests new private messages (dialogs)
720
- *
721
- * @global SpbcState $apbct
722
- * @param type $bp_message_obj
723
- * @return void|array with errors if spam has found
724
- */
725
- function apbct_integration__buddyPres__private_msg_check( $bp_message_obj){
726
-
727
- global $apbct;
728
-
729
- //Check for enabled option
730
- if(
731
- $apbct->settings['comments__bp_private_messages'] == 0 ||
732
- apbct_exclusions_check()
733
- ) {
734
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
735
- return;
736
- }
737
-
738
-
739
- //Check for quantity of comments
740
- $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER')
741
- ? CLEANTALK_CHECK_COMMENTS_NUMBER
742
- : 3;
743
-
744
- if($apbct->settings['comments__check_comments_number']){
745
- $args = array(
746
- 'user_id' => $bp_message_obj->sender_id,
747
- 'box' => 'sentbox',
748
- 'type' => 'all',
749
- 'limit' => $comments_check_number,
750
- 'page' => null,
751
- 'search_terms' => '',
752
- 'meta_query' => array()
753
- );
754
- $sentbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
755
- $cnt_sentbox_msgs = $sentbox_msgs['total'];
756
- $args['box'] = 'inbox';
757
- $inbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
758
- $cnt_inbox_msgs = $inbox_msgs['total'];
759
-
760
- if(($cnt_inbox_msgs + $cnt_sentbox_msgs) >= $comments_check_number)
761
- $is_max_comments = true;
762
- }
763
-
764
- if(!empty($is_max_comments)) {
765
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
766
- return;
767
- }
768
-
769
-
770
- $sender_user_obj = get_user_by('id', $bp_message_obj->sender_id);
771
-
772
- //Making a call
773
- $base_call_result = apbct_base_call(
774
- array(
775
- 'message' => $bp_message_obj->subject." ".$bp_message_obj->message,
776
- 'sender_email' => $sender_user_obj->data->user_email,
777
- 'sender_nickname' => $sender_user_obj->data->user_login,
778
- 'post_info' => array(
779
- 'comment_type' => 'buddypress_comment',
780
- 'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ),
781
- ),
782
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true)
783
- ? apbct_js_test('ct_checkjs', $_COOKIE, true)
784
- : apbct_js_test('ct_checkjs', $_POST),
785
- 'sender_info' => array('sender_url' => null),
786
- )
787
- );
788
-
789
- $ct_result = $base_call_result['ct_result'];
790
-
791
- if ($ct_result->allow == 0)
792
- wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
793
- }
794
-
795
- /**
796
- * Adds hiden filed to deafualt serach form
797
- *
798
- * @param $form string
799
- * @return string
800
- */
801
- function apbct_forms__search__addField( $form ){
802
- global $apbct;
803
- if($apbct->settings['forms__search_test'] == 1){
804
- $js_filed = ct_add_hidden_fields('ct_checkjs_search_default', true, false, false, false);
805
- $form = str_replace('</form>', $js_filed, $form);
806
- }
807
- return $form;
808
- }
809
-
810
- /**
811
- * Test default search string for spam
812
- *
813
- * @param $search string
814
- * @return string
815
- */
816
- function apbct_forms__search__testSpam( $search ){
817
-
818
- global $apbct, $cleantalk_executed;
819
-
820
- if(
821
- empty($search) ||
822
- $cleantalk_executed ||
823
- $apbct->settings['forms__search_test'] == 0 ||
824
- $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() // Skip processing for logged in users.
825
- ){
826
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
827
- return $search;
828
- }
829
-
830
- if(apbct_is_user_logged_in())
831
- $user = wp_get_current_user();
832
-
833
- $base_call_result = apbct_base_call(
834
- array(
835
- 'message' => $search,
836
- 'sender_email' => !empty($user) ? $user->user_email : null,
837
- 'sender_nickname' => !empty($user) ? $user->user_login : null,
838
- 'post_info' => array('comment_type' => 'site_search_wordpress'),
839
- //'js_on' => apbct_js_test('ct_checkjs_search_default', $_GET, true),
840
- )
841
- );
842
- $ct_result = $base_call_result['ct_result'];
843
-
844
- $cleantalk_executed = true;
845
-
846
- if ($ct_result->allow == 0){
847
- die($ct_result->comment);
848
- }
849
-
850
- return $search;
851
- }
852
-
853
- function apbct_search_add_noindex() {
854
-
855
- global $apbct;
856
-
857
- if(
858
- ! is_search() || // If it is search results
859
- $apbct->settings['forms__search_test'] == 0 ||
860
- $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() // Skip processing for logged in users.
861
- ){
862
- return ;
863
- }
864
-
865
- echo '<!-- meta by Cleantalk AntiSpam Protection plugin -->' . "\n";
866
- echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
867
-
868
- }
869
-
870
- /**
871
- * Test woocommerce checkout form for spam
872
- *
873
- */
874
- function ct_woocommerce_checkout_check() {
875
-
876
- global $apbct, $cleantalk_executed;
877
-
878
- //Getting request params
879
- $ct_temp_msg_data = ct_get_fields_any($_POST);
880
-
881
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
882
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
883
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
884
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
885
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
886
-
887
- if($subject != '')
888
- $message = array_merge(array('subject' => $subject), $message);
889
-
890
- $post_info['comment_type'] = 'order';
891
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
892
-
893
- //Making a call
894
- $base_call_result = apbct_base_call(
895
- array(
896
- 'message' => $message,
897
- 'sender_email' => $sender_email,
898
- 'sender_nickname' => $sender_nickname,
899
- 'post_info' => $post_info,
900
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
901
- 'sender_info' => array('sender_url' => null),
902
- )
903
- );
904
-
905
- if( $apbct->settings['forms__wc_register_from_order'] ) {
906
- $cleantalk_executed = false;
907
- }
908
-
909
- $ct_result = $base_call_result['ct_result'];
910
-
911
- if ($ct_result->allow == 0) {
912
- wp_send_json(array(
913
- 'result' => 'failure',
914
- 'messages' => "<ul class=\"woocommerce-error\"><li>".$ct_result->comment."</li></ul>",
915
- 'refresh' => 'false',
916
- 'reload' => 'false'
917
- ));
918
- }
919
- }
920
-
921
- /**
922
- * Triggered when adding an item to the shopping cart
923
- * for un-logged users
924
- *
925
- * @param $cart_item_key
926
- * @param $product_id
927
- * @param $quantity
928
- * @param $variation_id
929
- * @param $variation
930
- * @param $cart_item_data
931
- * @return void
932
- */
933
-
934
- function apbct_wc__add_to_cart_unlogged_user($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
935
- global $apbct;
936
-
937
- if(! apbct_is_user_logged_in() && $apbct->settings['forms__wc_add_to_cart']) {
938
- /**
939
- * Getting request params
940
- * POST contains an array of product information
941
- * Example: Array
942
- *(
943
- * [product_sku] => woo-beanie
944
- * [product_id] => 15
945
- * [quantity] => 1
946
- *)
947
- */
948
- $message = $_POST ?: array();
949
-
950
- $post_info['comment_type'] = 'order__add_to_cart';
951
- $post_info['post_url'] = Server::get('HTTP_REFERER');
952
-
953
- //Making a call
954
- $base_call_result = apbct_base_call(
955
- array(
956
- 'message' => $message,
957
- 'post_info' => $post_info,
958
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
959
- 'sender_info' => array('sender_url' => null),
960
- )
961
- );
962
-
963
- $ct_result = $base_call_result['ct_result'];
964
-
965
- if ($ct_result->allow == 0) {
966
- wp_send_json(array(
967
- 'result' => 'failure',
968
- 'messages' => "<ul class=\"woocommerce-error\"><li>" . $ct_result->comment . "</li></ul>",
969
- 'refresh' => 'false',
970
- 'reload' => 'false',
971
- 'response_type' => 'wc_add_to_cart_block'
972
- ));
973
- }
974
- }
975
- }
976
-
977
- /**
978
- * Public function - Tests for Pirate contact froms
979
- * return NULL
980
- */
981
- function apbct_form__piratesForm__testSpam(){
982
-
983
- global $apbct;
984
-
985
- //Check for enabled option
986
- if( !$apbct->settings['forms__contact_forms_test']) {
987
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
988
- return;
989
- }
990
-
991
-
992
- //Getting request params
993
- $ct_temp_msg_data = ct_get_fields_any($_POST);
994
-
995
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
996
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
997
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
998
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
999
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
1000
-
1001
- if($subject != '')
1002
- $message = array_merge(array('subject' => $subject), $message);
1003
-
1004
- $post_info['comment_type'] = 'contact_form_wordpress_feedback_pirate';
1005
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
1006
-
1007
- //Making a call
1008
- $base_call_result = apbct_base_call(
1009
- array(
1010
- 'message' => $message,
1011
- 'sender_email' => $sender_email,
1012
- 'sender_nickname' => $sender_nickname,
1013
- 'post_info' => $post_info,
1014
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
1015
- 'sender_info' => array('sender_url' => null),
1016
- )
1017
- );
1018
-
1019
- $ct_result = $base_call_result['ct_result'];
1020
-
1021
- if ($ct_result->allow == 0)
1022
- wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
1023
- }
1024
-
1025
- /**
1026
- * Adds hidden filed to comment form
1027
- */
1028
- function ct_comment_form($post_id){
1029
-
1030
- global $apbct;
1031
-
1032
- if (apbct_is_user_enable() === false) {
1033
- return false;
1034
- }
1035
-
1036
- if ( !$apbct->settings['forms__comments_test']) {
1037
- return false;
1038
- }
1039
-
1040
- ct_add_hidden_fields('ct_checkjs', false, false);
1041
-
1042
- return null;
1043
- }
1044
-
1045
  /**
1046
  * Adds cookie script filed to head
1047
  */
@@ -1066,7 +490,7 @@ function apbct_hook__wp_footer() {
1066
  ){
1067
  echo '<img style="display: none; left: 99999px;" src="' . $apbct->pixel_url . '">';
1068
  }
1069
-
1070
  if( $apbct->settings['data__use_ajax'] ){
1071
 
1072
  $timeout = $apbct->settings['misc__async_js'] ? 1000 : 0;
@@ -1134,7 +558,6 @@ function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false
1134
  if($no_print)
1135
  return;
1136
 
1137
- $ct_input_challenge = sprintf("'%s'", $ct_checkjs_key);
1138
  $field_id = $field_name . '_' . $field_id_hash;
1139
  $html = "<input type=\"hidden\" id=\"{$field_id}\" name=\"{$field_name}\" value=\"{$ct_checkjs_def}\" />";
1140
 
@@ -1169,499 +592,30 @@ function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false
1169
  }
1170
 
1171
  /**
1172
- * Public function - Insert JS code for spam tests
1173
- * return null;
1174
- */
1175
- function apbct_rorm__formidable__footerScripts($fields, $form) {
1176
-
1177
- global $apbct, $ct_checkjs_frm;
1178
-
1179
- if ( !$apbct->settings['forms__contact_forms_test'])
1180
- return false;
1181
-
1182
- $ct_checkjs_key = ct_get_checkjs_value();
1183
- $ct_frm_base_name = 'form_';
1184
- $ct_frm_name = $ct_frm_base_name . $form->form_key;
1185
-
1186
- echo "var input = document.createElement('input');
1187
- input.setAttribute('type', 'hidden');
1188
- input.setAttribute('name', '$ct_checkjs_frm');
1189
- input.setAttribute('value', '$ct_checkjs_key');
1190
- for (i = 0; i < document.forms.length; i++) {
1191
- if (typeof document.forms[i].id == 'string'){
1192
- if(document.forms[i].id.search('$ct_frm_name') != -1) {
1193
- document.forms[i].appendChild(input);
1194
- }
1195
- }
1196
- }";
1197
-
1198
- /* Excessive cookie set
1199
- $js_code = ct_add_hidden_fields(true, 'ct_checkjs', true, true);
1200
- $js_code = strip_tags($js_code); // Removing <script> tag
1201
- echo $js_code;
1202
- //*/
1203
  }
1204
 
1205
  /**
1206
- * Public function - Test Formidable data for spam activity
1207
- * @param $errors
1208
- * @param $form
 
1209
  *
1210
- * @return array with errors if spam has found
1211
  */
1212
- function apbct_rorm__formidable__testSpam ( $errors, $form ) {
1213
-
1214
- global $apbct;
1215
-
1216
- if ( !$apbct->settings['forms__contact_forms_test']) {
1217
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1218
- return $errors;
1219
- }
1220
-
1221
- // Skip processing for logged in users.
1222
- if ( !$apbct->settings['data__protect_logged_in'] && is_user_logged_in()) {
1223
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1224
- return $errors;
1225
- }
1226
-
1227
- $form_data = array();
1228
- foreach( $_POST['item_meta'] as $key => $value ) {
1229
- $form_data['item_meta[' . $key . ']'] = $value;
1230
- }
1231
-
1232
- $ct_temp_msg_data = ct_get_fields_any( $form_data );
1233
-
1234
- $sender_email = $ct_temp_msg_data['email'] ?: '';
1235
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
1236
- $subject = $ct_temp_msg_data['subject'] ?: '';
1237
- $contact_form = $ct_temp_msg_data['contact'] ?: true;
1238
- $message = $ct_temp_msg_data['message'] ?: array();
1239
-
1240
- // @todo convert key 'NUM' to 'input_meta[NUM]'
1241
- // Adding 'input_meta[]' to every field /Formidable fix/
1242
- // because filed names is 'input_meta[NUM]'
1243
- // Get all scalar values
1244
- $tmp_message = array();
1245
- $tmp_message2 = array();
1246
- foreach( $message as $key => $value ){
1247
- if( is_scalar( $value ) ){
1248
- $tmp_message[ $key ] = $value;
1249
- }else{
1250
- $tmp_message2[ $key ] = $value;
1251
- }
1252
- }
1253
- // Replacing key to input_meta[NUM] for scalar values
1254
- $tmp_message = array_flip($tmp_message);
1255
- foreach($tmp_message as &$value){
1256
- $value = 'item_meta['.$value.']';
1257
- } unset($value);
1258
- $tmp_message = array_flip($tmp_message);
1259
- // Combine it with non-scalar values
1260
- $message = array_merge( $tmp_message, $tmp_message2 );
1261
-
1262
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
1263
- ? apbct_js_test('ct_checkjs', $_COOKIE, true)
1264
- : apbct_js_test('ct_checkjs', $_POST);
1265
-
1266
- $base_call_result = apbct_base_call(
1267
- array(
1268
- 'message' => $message,
1269
- 'sender_email' => $sender_email,
1270
- 'sender_nickname' => $sender_nickname,
1271
- 'post_info' => array('comment_type' => 'contact_form_wordpress_formidable'),
1272
- 'js_on' => $checkjs
1273
- )
1274
- );
1275
- $ct_result = $base_call_result['ct_result'];
1276
-
1277
- if ($ct_result->allow == 0) {
1278
- $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
1279
- }
1280
-
1281
- return $errors;
1282
- }
1283
-
1284
- /**
1285
- * Public filter 'bbp_*' - Get new topic name to global $ct_bbp_topic
1286
- * @param mixed[] $comment Comment string
1287
- * @return mixed[] $comment Comment string
1288
- */
1289
- function ct_bbp_get_topic($topic){
1290
- global $ct_bbp_topic;
1291
-
1292
- $ct_bbp_topic=$topic;
1293
-
1294
- return $topic;
1295
- }
1296
-
1297
- /**
1298
- * Public filter 'bbp_*' - Checks topics, replies by cleantalk
1299
- * @param mixed[] $comment Comment string
1300
- * @return mixed[] $comment Comment string
1301
- */
1302
- function ct_bbp_new_pre_content ($comment) {
1303
-
1304
- global $apbct, $current_user;
1305
-
1306
- if ( !$apbct->settings['forms__comments_test']) {
1307
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1308
- return $comment;
1309
- }
1310
-
1311
- // Skip processing for logged in users and admin.
1312
- if ( !$apbct->settings['data__protect_logged_in'] && is_user_logged_in() ||
1313
- apbct_exclusions_check()
1314
- ) {
1315
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1316
- return $comment;
1317
- }
1318
-
1319
-
1320
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
1321
- ? apbct_js_test('ct_checkjs', $_COOKIE, true)
1322
- : apbct_js_test('ct_checkjs', $_POST);
1323
-
1324
- $post_info['comment_type'] = 'bbpress_comment';
1325
- $post_info['post_url'] = bbp_get_topic_permalink();
1326
-
1327
- if( is_user_logged_in() ) {
1328
- $sender_email = $current_user->user_email;
1329
- $sender_nickname = $current_user->display_name;
1330
- } else {
1331
- $sender_email = isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null;
1332
- $sender_nickname = isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null;
1333
- }
1334
-
1335
- $base_call_result = apbct_base_call(
1336
- array(
1337
- 'message' => $comment,
1338
- 'sender_email' => $sender_email,
1339
- 'sender_nickname' => $sender_nickname,
1340
- 'post_info' => $post_info,
1341
- 'js_on' => $checkjs,
1342
- 'sender_info' => array('sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null),
1343
- )
1344
- );
1345
- $ct_result = $base_call_result['ct_result'];
1346
-
1347
- if ($ct_result->allow == 0) {
1348
- bbp_add_error('bbp_reply_content', $ct_result->comment);
1349
- }
1350
-
1351
- return $comment;
1352
- }
1353
-
1354
- function apbct_comment__sanitize_data__before_wp_die($function){
1355
-
1356
- global $apbct;
1357
-
1358
- $comment_data = wp_unslash($_POST);
1359
-
1360
- $user_ID = 0;
1361
-
1362
- $comment_type = '';
1363
-
1364
- $comment_content = isset($comment_data['comment']) ? (string) $comment_data['comment'] : null;
1365
- $comment_parent = isset($comment_data['comment_parent']) ? (int) absint($comment_data['comment_parent']) : null;
1366
-
1367
- $comment_author = isset($comment_data['author']) ? (string) trim(strip_tags($comment_data['author'])) : null;
1368
- $comment_author_email = isset($comment_data['email']) ? (string) trim($comment_data['email']) : null;
1369
- $comment_author_url = isset($comment_data['url']) ? (string) trim($comment_data['url']) : null;
1370
- $comment_post_ID = isset($comment_data['comment_post_ID']) ? (int) $comment_data['comment_post_ID'] : null;
1371
-
1372
- if(isset($comment_content, $comment_parent)){
1373
-
1374
- $user = function_exists('apbct_wp_get_current_user') ? apbct_wp_get_current_user() : null;
1375
-
1376
- if($user && $user->exists()){
1377
- $comment_author = empty($user->display_name) ? $user->user_login : $user->display_name;
1378
- $comment_author_email = $user->user_email;
1379
- $comment_author_url = $user->user_url;
1380
- $user_ID = $user->ID;
1381
- }
1382
-
1383
- $apbct->comment_data = compact(
1384
- 'comment_post_ID',
1385
- 'comment_author',
1386
- 'comment_author_email',
1387
- 'comment_author_url',
1388
- 'comment_content',
1389
- 'comment_type',
1390
- 'comment_parent',
1391
- 'user_ID'
1392
- );
1393
-
1394
- $function = 'apbct_comment__check_via_wp_die';
1395
-
1396
- }
1397
-
1398
- return $function;
1399
- }
1400
-
1401
- function apbct_comment__check_via_wp_die($message, $title, $args){
1402
- if($title == __('Comment Submission Failure')){
1403
- global $apbct;
1404
- $apbct->validation_error = $message;
1405
- ct_preprocess_comment($apbct->comment_data);
1406
- }
1407
- _default_wp_die_handler($message, $title, $args);
1408
- }
1409
-
1410
- /**
1411
- * Public filter 'preprocess_comment' - Checks comment by cleantalk server
1412
- * @param mixed[] $comment Comment data array
1413
- * @return mixed[] New data array of comment
1414
- */
1415
- function ct_preprocess_comment($comment) {
1416
- // this action is called just when WP process POST request (adds new comment)
1417
- // this action is called by wp-comments-post.php
1418
- // after processing WP makes redirect to post page with comment's form by GET request (see above)
1419
- global $current_user, $comment_post_id, $ct_comment_done, $ct_jp_comments, $apbct;
1420
-
1421
- // Send email notification for chosen groups of users
1422
- if($apbct->settings['wp__comment_notify'] && !empty($apbct->settings['wp__comment_notify__roles']) && $apbct->data['moderate']){
1423
-
1424
- add_filter('notify_post_author', 'apbct_comment__Wordpress__doNotify', 100, 2);
1425
-
1426
- $users = get_users(array(
1427
- 'role__in' => $apbct->settings['wp__comment_notify__roles'],
1428
- 'fileds' => array('user_email')
1429
- ));
1430
-
1431
- if($users){
1432
- add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotificationGroups', 100, 2);
1433
- add_filter('comment_notification_recipients', 'apbct_comment__Wordpress__changeMailNotificationRecipients', 100, 2);
1434
- foreach($users as $user){
1435
- $emails[] = $user->user_email;
1436
- }
1437
- $apbct->comment_notification_recipients = json_encode($emails);
1438
- }
1439
- }
1440
-
1441
- // Skip processing admin.
1442
- if (in_array("administrator", $current_user->roles)){
1443
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1444
- return $comment;
1445
- }
1446
-
1447
-
1448
- $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3;
1449
-
1450
- if($apbct->settings['comments__check_comments_number'] && $comment['comment_author_email']){
1451
- $args = array(
1452
- 'author_email' => $comment['comment_author_email'],
1453
- 'status' => 'approve',
1454
- 'count' => false,
1455
- 'number' => $comments_check_number,
1456
- );
1457
- $cnt = count(get_comments($args));
1458
- $is_max_comments = $cnt >= $comments_check_number ? true : false;
1459
- }
1460
-
1461
- if (
1462
- ($comment['comment_type']!='trackback') &&
1463
- (
1464
- apbct_is_user_enable() === false ||
1465
- $apbct->settings['forms__comments_test'] == 0 ||
1466
- $ct_comment_done ||
1467
- (isset($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'],'page=wysija_campaigns&action=editTemplate')!==false) ||
1468
- (isset($is_max_comments) && $is_max_comments) ||
1469
- (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['REQUEST_URI'],'/wp-admin/')!==false)
1470
- )
1471
- )
1472
- {
1473
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1474
- return $comment;
1475
- }
1476
-
1477
- $local_blacklists = apbct_wp_blacklist_check(
1478
- $comment['comment_author'],
1479
- $comment['comment_author_email'],
1480
- $comment['comment_author_url'],
1481
- $comment['comment_content'],
1482
- apbct_get_server_variable( 'REMOTE_ADDR' ),
1483
- apbct_get_server_variable( 'HTTP_USER_AGENT' )
1484
- );
1485
-
1486
- // Go out if author in local blacklists
1487
- if ($comment['comment_type']!='trackback' && $local_blacklists === true) {
1488
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1489
- return $comment;
1490
- }
1491
-
1492
- // Skip pingback anti-spam test
1493
- /*if ($comment['comment_type'] == 'pingback') {
1494
- return $comment;
1495
- }*/
1496
-
1497
- $ct_comment_done = true;
1498
-
1499
- $comment_post_id = $comment['comment_post_ID'];
1500
-
1501
- // JetPack comments logic
1502
- $post_info['comment_type'] = $ct_jp_comments ? 'jetpack_comment' : $comment['comment_type'];
1503
- $post_info['post_url'] = ct_post_url(null, $comment_post_id);
1504
-
1505
- // Comment type
1506
- $post_info['comment_type'] = empty($post_info['comment_type']) ? 'general_comment' : $post_info['comment_type'];
1507
-
1508
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
1509
- ? apbct_js_test('ct_checkjs', $_COOKIE, true)
1510
- : apbct_js_test('ct_checkjs', $_POST);
1511
-
1512
-
1513
- $example = null;
1514
- if ($apbct->data['relevance_test']) {
1515
- $post = get_post($comment_post_id);
1516
- if ($post !== null){
1517
- $example['title'] = $post->post_title;
1518
- $example['body'] = $post->post_content;
1519
- $example['comments'] = null;
1520
-
1521
- $last_comments = get_comments(array('status' => 'approve', 'number' => 10, 'post_id' => $comment_post_id));
1522
- foreach ($last_comments as $post_comment){
1523
- $example['comments'] .= "\n\n" . $post_comment->comment_content;
1524
- }
1525
-
1526
- $example = json_encode($example);
1527
- }
1528
-
1529
- // Use plain string format if've failed with JSON
1530
- if ($example === false || $example === null){
1531
- $example = ($post->post_title !== null) ? $post->post_title : '';
1532
- $example .= ($post->post_content !== null) ? "\n\n" . $post->post_content : '';
1533
- }
1534
- }
1535
-
1536
- // Add honeypot_field field
1537
- $honeypot_field = 1;
1538
-
1539
- if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
1540
- if(isset($_POST['url']) && !empty($_POST['url']) && $post_info['comment_type'] === 'comment' && isset($_POST['comment_post_ID'])) {
1541
- $honeypot_field = 0;
1542
- }
1543
- }
1544
-
1545
- $base_call_result = apbct_base_call(
1546
- array(
1547
- 'message' => $comment['comment_content'],
1548
- 'example' => $example,
1549
- 'sender_email' => $comment['comment_author_email'],
1550
- 'sender_nickname' => $comment['comment_author'],
1551
- 'post_info' => $post_info,
1552
- 'js_on' => $checkjs,
1553
- 'sender_info' => array(
1554
- 'sender_url' => @$comment['comment_author_url'],
1555
- 'form_validation' => !isset($apbct->validation_error)
1556
- ? null
1557
- : json_encode(array(
1558
- 'validation_notice' => $apbct->validation_error,
1559
- 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
1560
- ))
1561
- ),
1562
- 'honeypot_field' => $honeypot_field
1563
- )
1564
- );
1565
- $ct_result = $base_call_result['ct_result'];
1566
-
1567
- ct_hash($ct_result->id);
1568
-
1569
- //Don't check trusted users
1570
- if (isset($comment['comment_author_email'])){
1571
- $approved_comments = get_comments(array('status' => 'approve', 'count' => true, 'author_email' => $comment['comment_author_email']));
1572
- $new_user = $approved_comments == 0 ? true : false;
1573
- }
1574
-
1575
- // Change comment flow only for new authors
1576
- if (!empty($new_user) || $ct_result->stop_words !== null || $ct_result->spam == 1)
1577
- add_action('comment_post', 'ct_set_meta', 10, 2);
1578
-
1579
- if($ct_result->allow){ // Pass if allowed
1580
- if(get_option('comment_moderation') === '1') // Wordpress moderation flag
1581
- add_filter('pre_comment_approved', 'ct_set_not_approved', 999, 2);
1582
- else
1583
- add_filter('pre_comment_approved', 'ct_set_approved', 999, 2);
1584
- // Modify the email notification
1585
- add_filter('comment_notification_text', 'apbct_comment__wordpress__show_blacklists', 100, 2); // Add two blacklist links: by email and IP
1586
- }else{
1587
-
1588
- global $ct_comment, $ct_stop_words;
1589
-
1590
- $ct_comment = $ct_result->comment;
1591
- $ct_stop_words = $ct_result->stop_words;
1592
-
1593
- $err_text = '<center>' . ((defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE == true) ? '' : '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ') . __('Spam protection', 'cleantalk-spam-protect') . "</center><br><br>\n" . $ct_result->comment;
1594
- if( ! $ct_jp_comments ) {
1595
- $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
1596
- }
1597
-
1598
- // Terminate. Definitely spam.
1599
- if($ct_result->stop_queue == 1)
1600
- wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments ));
1601
-
1602
- // Terminate by user's setting.
1603
- if($ct_result->spam == 3)
1604
- wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments));
1605
-
1606
- // Trash comment.
1607
- if($ct_result->spam == 2){
1608
- add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
1609
- add_action('comment_post', 'ct_wp_trash_comment', 997, 2);
1610
- }
1611
-
1612
- // Spam comment
1613
- if($ct_result->spam == 1)
1614
- add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
1615
-
1616
- // Move to pending folder. Contains stop_words.
1617
- if($ct_result->stop_words){
1618
- add_filter('pre_comment_approved', 'ct_set_not_approved', 998, 2);
1619
- add_action('comment_post', 'ct_mark_red', 998, 2);
1620
- }
1621
-
1622
- add_action('comment_post', 'ct_die', 999, 2);
1623
- }
1624
-
1625
- if($apbct->settings['comments__remove_comments_links'] == 1){
1626
- $comment['comment_content'] = preg_replace("~(http|https|ftp|ftps)://(.*?)(\s|\n|[,.?!](\s|\n)|$)~", '[Link deleted]', $comment['comment_content']);
1627
- }
1628
-
1629
- // Change mail notification if license is out of date
1630
- if($apbct->data['moderate'] == 0){
1631
- $apbct->sender_email = $comment['comment_author_email'];
1632
- $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
1633
- add_filter('comment_moderation_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment sent to moderation
1634
- add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment approved
1635
- }
1636
-
1637
- return $comment;
1638
- }
1639
-
1640
- /**
1641
- * Changes whether notify admin/athor or not.
1642
- *
1643
- * @param bool $maybe_notify notify flag
1644
- * @param int $comment_ID Comment id
1645
- * @return bool flag
1646
- */
1647
- function apbct_comment__Wordpress__doNotify($maybe_notify, $comment_ID){
1648
- return true;
1649
- }
1650
-
1651
- /**
1652
- * Add notification setting link
1653
- *
1654
- * @param string $notify_message
1655
- * @param integer $comment_id
1656
- *
1657
- * @return string
1658
- */
1659
- function apbct_comment__Wordpress__changeMailNotificationGroups($notify_message, $comment_id){
1660
- return $notify_message
1661
- .PHP_EOL
1662
- .'---'.PHP_EOL
1663
- .'Manage notifications settings: '.get_site_url().'/wp-admin/options-general.php?page=cleantalk';
1664
- }
1665
 
1666
  /**
1667
  * Change email notification recipients
@@ -1811,7 +765,6 @@ function ct_die_extended($comment_body) {
1811
  $back_link = '<a href="' . $_SERVER['HTTP_REFERER'] . '">' . __('Back') . '</a>';
1812
  }
1813
 
1814
-
1815
  if(file_exists(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html")){
1816
 
1817
  $ct_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html");
@@ -1848,14 +801,14 @@ function ct_die_extended($comment_body) {
1848
  function apbct_js_test($field_name = 'ct_checkjs', $data = null, $is_cookie = false ) {
1849
 
1850
  global $apbct;
1851
-
1852
  $out = null;
1853
 
1854
  if(
1855
  ($data && isset($data[$field_name])) ||
1856
  ($is_cookie && $apbct->settings['data__set_cookies'] == 2 && \Cleantalk\ApbctWP\Variables\Cookie::get( $field_name ))
1857
  ){
1858
-
1859
  $js_key = $is_cookie && $apbct->settings['data__set_cookies'] == 2
1860
  ? \Cleantalk\ApbctWP\Variables\Cookie::get( $field_name )
1861
  : trim($data[$field_name]);
@@ -1995,22 +948,7 @@ function ct_plugin_active($plugin_name){
1995
  return false;
1996
  }
1997
 
1998
- /**
1999
- * Insert a hidden field to registration form
2000
- * @return null
2001
- */
2002
- function ct_register_form() {
2003
-
2004
- global $ct_checkjs_register_form, $apbct;
2005
-
2006
- if ($apbct->settings['forms__registrations_test'] == 0) {
2007
- return false;
2008
- }
2009
-
2010
- ct_add_hidden_fields($ct_checkjs_register_form, false, false, false, false);
2011
 
2012
- return null;
2013
- }
2014
 
2015
  function apbct_login__scripts(){
2016
  global $apbct;
@@ -2038,2071 +976,101 @@ function apbct_login__scripts(){
2038
  }
2039
 
2040
  /**
2041
- * Adds notification text to login form - to inform about approved registration
2042
- * @return null
2043
  */
2044
- function ct_login_message($message) {
2045
-
2046
- global $errors, $apbct, $apbct_cookie_register_ok_label;
2047
-
2048
- if ($apbct->settings['forms__registrations_test'] != 0){
2049
- if( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ){
2050
- if (isset($_COOKIE[$apbct_cookie_register_ok_label])){
2051
- if(is_wp_error($errors)){
2052
- $errors->add('ct_message',sprintf(__('Registration approved by %s.', 'cleantalk-spam-protect'), '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk</b>'), 'message');
2053
- }
2054
- }
2055
- }
2056
  }
2057
- return $message;
2058
- }
2059
-
2060
- /**
2061
- * Test users registration for pPress
2062
- * @return array with errors
2063
- */
2064
- function ct_registration_errors_ppress($reg_errors, $form_id) {
2065
-
2066
- $email = $_POST['reg_email'];
2067
- $login = $_POST['reg_username'];
2068
-
2069
- $reg_errors = ct_registration_errors($reg_errors, $login, $email);
2070
-
2071
- return $reg_errors;
2072
  }
2073
 
2074
  /**
2075
- * Test users registration for multisite enviroment
2076
- * @return array with errors
2077
  */
2078
- function ct_registration_errors_wpmu($errors) {
2079
- global $ct_signup_done;
2080
 
2081
- //
2082
- // Multisite actions
2083
- //
2084
- $sanitized_user_login = null;
2085
- if (isset($errors['user_name'])) {
2086
- $sanitized_user_login = $errors['user_name'];
2087
- $wpmu = true;
2088
- }
2089
- $user_email = null;
2090
- if (isset($errors['user_email'])) {
2091
- $user_email = $errors['user_email'];
2092
- $wpmu = true;
2093
- }
2094
 
2095
- if ($wpmu && isset($errors['errors']->errors) && count($errors['errors']->errors) > 0) {
2096
- return $errors;
 
 
 
2097
  }
2098
 
2099
- $errors['errors'] = ct_registration_errors($errors['errors'], $sanitized_user_login, $user_email);
2100
-
2101
- // Show CleanTalk errors in user_name field
2102
- if (isset($errors['errors']->errors['ct_error'])) {
2103
- $errors['errors']->errors['user_name'] = $errors['errors']->errors['ct_error'];
2104
- unset($errors['errors']->errors['ct_error']);
2105
- }
2106
-
2107
- return $errors;
2108
  }
2109
 
2110
  /**
2111
- * Shell for action register_post
2112
- *
2113
- * @param $sanitized_user_login
2114
- * @param $user_email
2115
- * @param $errors
2116
  *
2117
- * @return void|WP_Error
 
2118
  */
2119
- function ct_register_post($sanitized_user_login, $user_email, $errors) {
2120
- return ct_registration_errors($errors, $sanitized_user_login, $user_email);
2121
- }
2122
 
2123
- /**
2124
- * Check messages for external plugins
2125
- * @return array with checking result;
2126
- */
 
 
 
 
 
 
2127
 
2128
- function ct_test_message($nickname, $email, $ip, $text){
2129
 
2130
- $base_call_result = apbct_base_call(
2131
- array(
2132
- 'message' => $text,
2133
- 'sender_email' => $email,
2134
- 'sender_nickname' => $nickname,
2135
- 'post_info' => array('comment_type' => 'feedback_plugin_check'),
2136
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
2137
- )
2138
- );
2139
 
2140
- $ct_result = $base_call_result['ct_result'];
2141
 
2142
- $result=Array(
2143
- 'allow' => $ct_result->allow,
2144
- 'comment' => $ct_result->comment,
2145
- );
2146
- return $result;
2147
  }
2148
 
2149
  /**
2150
- * Check registrations for external plugins
2151
- * @return array with checking result;
2152
  */
2153
- function ct_test_registration($nickname, $email, $ip = null){
2154
 
2155
- global $ct_checkjs_register_form, $apbct;
2156
 
2157
- if(apbct_js_test($ct_checkjs_register_form, $_POST)){
2158
- $checkjs = apbct_js_test($ct_checkjs_register_form, $_POST);
2159
- $sender_info['post_checkjs_passed'] = $checkjs;
2160
- }else{
2161
- $checkjs = $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
2162
- $sender_info['cookie_checkjs_passed'] = $checkjs;
2163
  }
2164
 
2165
- //Making a call
2166
- $base_call_result = apbct_base_call(
2167
- array(
2168
- 'sender_ip' => $ip,
2169
- 'sender_email' => $email,
2170
- 'sender_nickname' => $nickname,
2171
- 'sender_info' => $sender_info,
2172
- 'js_on' => $checkjs,
2173
- ),
2174
- true
2175
- );
2176
- $ct_result = $base_call_result['ct_result'];
2177
-
2178
- $result = array(
2179
- 'allow' => $ct_result->allow,
2180
- 'comment' => $ct_result->comment,
2181
- );
2182
- return $result;
2183
- }
2184
 
2185
- /**
2186
- * Test users registration
2187
- *
2188
- * @param $errors
2189
- * @param null $sanitized_user_login
2190
- * @param null $user_email
2191
- *
2192
- * @return void|WP_Error
2193
- */
2194
- function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
2195
 
2196
- global $ct_checkjs_register_form, $apbct_cookie_request_id_label, $apbct_cookie_register_ok_label, $apbct_cookie_request_id, $bp, $ct_signup_done, $ct_negative_comment, $apbct, $ct_registration_error_comment, $cleantalk_executed;
2197
-
2198
- // Go out if a registrered user action
2199
- if (apbct_is_user_enable() === false) {
2200
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2201
- return $errors;
2202
- }
2203
-
2204
- if ($apbct->settings['forms__registrations_test'] == 0) {
2205
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2206
- return $errors;
2207
- }
2208
-
2209
- // The function already executed
2210
- // It happens when used ct_register_post();
2211
- if ($ct_signup_done && is_object($errors) && count($errors->errors) > 0) {
2212
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2213
- return $errors;
2214
- }
2215
-
2216
- // Facebook registration
2217
- if ($sanitized_user_login === null && isset($_POST['FB_userdata'])){
2218
- $sanitized_user_login = $_POST['FB_userdata']['name'];
2219
- $facebook = true;
2220
- }
2221
- if ($user_email === null && isset($_POST['FB_userdata'])){
2222
- $user_email = $_POST['FB_userdata']['email'];
2223
- $facebook = true;
2224
- }
2225
-
2226
- // BuddyPress actions
2227
- $buddypress = false;
2228
- if ($sanitized_user_login === null && isset($_POST['signup_username'])) {
2229
- $sanitized_user_login = $_POST['signup_username'];
2230
- $buddypress = true;
2231
- }
2232
- if ($user_email === null && isset($_POST['signup_email'])) {
2233
- $user_email = $_POST['signup_email'];
2234
- $buddypress = true;
2235
- }
2236
-
2237
- //
2238
- // Break tests because we already have servers response
2239
- //
2240
- if ($buddypress && $ct_signup_done) {
2241
- if ($ct_negative_comment) {
2242
- $bp->signup->errors['signup_username'] = $ct_negative_comment;
2243
- }
2244
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2245
- return $errors;
2246
- }
2247
-
2248
-
2249
- if(current_filter() == 'woocommerce_registration_errors'){
2250
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
2251
- $checkjs_post = null;
2252
- $checkjs_cookie = $checkjs;
2253
- }else{
2254
- // This hack can be helpfull when plugin uses with untested themes&signups plugins.
2255
- $checkjs_post = apbct_js_test($ct_checkjs_register_form, $_POST);
2256
- $checkjs_cookie = apbct_js_test('ct_checkjs', $_COOKIE, true);
2257
- $checkjs = $checkjs_cookie ? $checkjs_cookie : $checkjs_post;
2258
- }
2259
-
2260
- $sender_info = array(
2261
- 'post_checkjs_passed' => $checkjs_post,
2262
- 'cookie_checkjs_passed' => $checkjs_cookie,
2263
- 'form_validation' => ! empty( $errors )
2264
- ? json_encode( array(
2265
- 'validation_notice' => $errors->get_error_message(),
2266
- 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
2267
- ) )
2268
- : null,
2269
- );
2270
-
2271
- $base_call_result = apbct_base_call(
2272
- array(
2273
- 'sender_email' => $user_email,
2274
- 'sender_nickname' => $sanitized_user_login,
2275
- 'sender_info' => $sender_info,
2276
- 'js_on' => $checkjs,
2277
- ),
2278
- true
2279
- );
2280
- $ct_result = $base_call_result['ct_result'];
2281
-
2282
- // Change mail notification if license is out of date
2283
- if($apbct->data['moderate'] == 0 &&
2284
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
2285
- ){
2286
- $apbct->sender_email = $user_email;
2287
- $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
2288
- add_filter('wp_new_user_notification_email_admin', 'apbct_registration__Wordpress__changeMailNotification', 100, 3);
2289
- }
2290
-
2291
- $ct_signup_done = true;
2292
-
2293
- $ct_result = ct_change_plugin_resonse($ct_result, $checkjs);
2294
-
2295
- $cleantalk_executed = true;
2296
-
2297
- if ($ct_result->inactive != 0) {
2298
- ct_send_error_notice($ct_result->comment);
2299
- return $errors;
2300
- }
2301
-
2302
- if ($ct_result->allow == 0) {
2303
-
2304
- if ($buddypress === true) {
2305
- $bp->signup->errors['signup_username'] = $ct_result->comment;
2306
- }elseif(!empty($facebook)){
2307
- $_POST['FB_userdata']['email'] = '';
2308
- $_POST['FB_userdata']['name'] = '';
2309
- return;
2310
- }elseif(defined('MGM_PLUGIN_NAME')) {
2311
- ct_die_extended($ct_result->comment);
2312
- }else{
2313
- if(is_wp_error($errors))
2314
- $errors->add('ct_error', $ct_result->comment);
2315
- $ct_negative_comment = $ct_result->comment;
2316
- }
2317
-
2318
- $ct_registration_error_comment = $ct_result->comment;
2319
-
2320
- } else {
2321
- if ($ct_result->id !== null) {
2322
- $apbct_cookie_request_id = $ct_result->id;
2323
- \Cleantalk\ApbctWP\Variables\Cookie::set($apbct_cookie_register_ok_label, $ct_result->id, time()+10, '/');
2324
- \Cleantalk\ApbctWP\Variables\Cookie::set($apbct_cookie_request_id_label, $ct_result->id, time()+10, '/');
2325
- }
2326
- }
2327
-
2328
- return $errors;
2329
- }
2330
-
2331
- /**
2332
- * Changes email notification for newly registred user
2333
- *
2334
- * @param string $wp_new_user_notification_email_admin Body of email notification
2335
- * @param array $user User inof
2336
- * @param string $blogname Blog name
2337
- * @return string Body for email notification
2338
- */
2339
- function apbct_registration__Wordpress__changeMailNotification($wp_new_user_notification_email_admin, $user, $blogname){
2340
-
2341
- global $apbct;
2342
-
2343
- $wp_new_user_notification_email_admin['message'] = PHP_EOL
2344
- .__('CleanTalk AntiSpam: This registration is spam.', 'cleantalk-spam-protect')
2345
- ."\n" . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
2346
- ."\n" . 'IP: ' . $apbct->sender_ip
2347
- ."\n" . 'Email: ' . $apbct->sender_email
2348
- .PHP_EOL . PHP_EOL .
2349
- __('Activate protection in your Anti-Spam Dashboard: ', 'clentalk')
2350
- .'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wp_spam_registration_passed'
2351
- .($apbct->data['user_token']
2352
- ? '&iser_token='.$apbct->data['user_token']
2353
- : ''
2354
- )
2355
- .PHP_EOL . '---'
2356
- .PHP_EOL
2357
- .$wp_new_user_notification_email_admin['message'];
2358
-
2359
- return $wp_new_user_notification_email_admin;
2360
-
2361
-
2362
- }
2363
-
2364
- /**
2365
- * Checks Ultimate Members registration for spam
2366
- *
2367
- * @param $args forms arguments with names and values
2368
- *
2369
- * @return mixed
2370
- *
2371
- */
2372
- function apbct_registration__UltimateMembers__check( $args ){
2373
-
2374
- if ( isset( UM()->form()->errors ) ) {
2375
- $sender_info['previous_form_validation'] = true;
2376
- $sender_info['validation_notice'] = json_encode( UM()->form()->errors );
2377
- }
2378
-
2379
- global $apbct, $cleantalk_executed;
2380
-
2381
- if ($apbct->settings['forms__registrations_test'] == 0) {
2382
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2383
- return $args;
2384
- }
2385
-
2386
-
2387
- $checkjs = apbct_js_test('ct_checkjs_register_form', $args);
2388
- $sender_info['post_checkjs_passed'] = $checkjs;
2389
-
2390
- // This hack can be helpfull when plugin uses with untested themes&signups plugins.
2391
- if ($checkjs == 0) {
2392
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
2393
- $sender_info['cookie_checkjs_passed'] = $checkjs;
2394
- }
2395
-
2396
- $base_call_result = apbct_base_call(
2397
- array(
2398
- 'sender_email' => $args['user_email'],
2399
- 'sender_nickname' => $args['user_login'],
2400
- 'sender_info' => $sender_info,
2401
- 'js_on' => $checkjs,
2402
- ),
2403
- true
2404
- );
2405
- $ct_result = $base_call_result['ct_result'];
2406
-
2407
- $cleantalk_executed = true;
2408
-
2409
- if ($ct_result->inactive != 0) {
2410
- ct_send_error_notice($ct_result->comment);
2411
- return $args;
2412
- }
2413
-
2414
- if ($ct_result->allow == 0)
2415
- UM()->form()->add_error('user_password', $ct_result->comment );
2416
-
2417
- return $args;
2418
- }
2419
-
2420
- /**
2421
- * Checks registration error and set it if it was dropped
2422
- * @return errors
2423
- */
2424
- function ct_check_registration_erros($errors, $sanitized_user_login = null, $user_email = null) {
2425
- global $bp, $ct_registration_error_comment;
2426
-
2427
- if($ct_registration_error_comment){
2428
-
2429
- if(isset($bp))
2430
- if(method_exists($bp, 'signup'))
2431
- if(method_exists($bp->signup, 'errors'))
2432
- if(isset($bp->signup->errors['signup_username']))
2433
- if($bp->signup->errors['signup_username'] != $ct_registration_error_comment)
2434
- $bp->signup->errors['signup_username'] = $ct_registration_error_comment;
2435
-
2436
- if(isset($errors))
2437
- if(method_exists($errors, 'errors'))
2438
- if(isset($errors->errors['ct_error']))
2439
- if($errors->errors['ct_error'][0] != $ct_registration_error_comment)
2440
- $errors->add('ct_error', $ct_registration_error_comment);
2441
-
2442
- }
2443
- return $errors;
2444
- }
2445
-
2446
- /**
2447
- * Set user meta (ct_hash) for successed registration
2448
- * @return null
2449
- */
2450
- function apbct_user_register($user_id) {
2451
-
2452
- global $apbct_cookie_request_id_label, $apbct_cookie_request_id;
2453
-
2454
- if ( ! empty( $apbct_cookie_request_id ) ) {
2455
- update_user_meta($user_id, 'ct_hash', $apbct_cookie_request_id);
2456
- return;
2457
- }
2458
-
2459
- if ( isset($_COOKIE[$apbct_cookie_request_id_label]) ) {
2460
- if(update_user_meta($user_id, 'ct_hash', $_COOKIE[$apbct_cookie_request_id_label])){
2461
- \Cleantalk\ApbctWP\Variables\Cookie::set($apbct_cookie_request_id_label, '0', 1, '/');
2462
- }
2463
- return;
2464
- }
2465
-
2466
- }
2467
-
2468
-
2469
- /**
2470
- * Test for JetPack contact form
2471
- */
2472
- function ct_grunion_contact_form_field_html($r, $field_label) {
2473
-
2474
- global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $apbct;
2475
-
2476
- if ($apbct->settings['forms__contact_forms_test'] == 1 && $ct_jpcf_patched === false && preg_match( "/(text|email)/i", $r)) {
2477
-
2478
- // Looking for element name prefix
2479
- $name_patched = false;
2480
- foreach ($ct_jpcf_fields as $v) {
2481
- if ($name_patched === false && preg_match("/(g\d-)$v/", $r, $matches)) {
2482
- $ct_checkjs_jpcf = $matches[1] . $ct_checkjs_jpcf;
2483
- $name_patched = true;
2484
- }
2485
- }
2486
-
2487
- $r .= ct_add_hidden_fields($ct_checkjs_jpcf, true);
2488
- $ct_jpcf_patched = true;
2489
- }
2490
-
2491
- return $r;
2492
- }
2493
- /**
2494
- * Test for JetPack contact form
2495
- */
2496
- function ct_contact_form_is_spam($form) {
2497
-
2498
- global $ct_checkjs_jpcf, $apbct;
2499
-
2500
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
2501
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2502
- return null;
2503
- }
2504
-
2505
- $js_field_name = $ct_checkjs_jpcf;
2506
- foreach ($_POST as $k => $v) {
2507
- if (preg_match("/^.+$ct_checkjs_jpcf$/", $k))
2508
- $js_field_name = $k;
2509
- }
2510
-
2511
- $sender_email = null;
2512
- $sender_nickname = null;
2513
- $message = '';
2514
- if (isset($form['comment_author_email']))
2515
- $sender_email = $form['comment_author_email'];
2516
-
2517
- if (isset($form['comment_author']))
2518
- $sender_nickname = $form['comment_author'];
2519
-
2520
- if (isset($form['comment_content']))
2521
- $message = $form['comment_content'];
2522
-
2523
- $base_call_result = apbct_base_call(
2524
- array(
2525
- 'message' => $message,
2526
- 'sender_email' => $sender_email,
2527
- 'sender_nickname' => $sender_nickname,
2528
- 'post_info' => array('comment_type' => 'contact_form_wordpress_grunion'),
2529
- 'sender_info' => array('sender_url' => @$form['comment_author_url']),
2530
- 'js_on' => apbct_js_test($js_field_name, $_POST),
2531
- )
2532
- );
2533
- $ct_result = $base_call_result['ct_result'];
2534
-
2535
- if ($ct_result->allow == 0) {
2536
- global $ct_comment;
2537
- $ct_comment = $ct_result->comment;
2538
- ct_die(null, null);
2539
- exit;
2540
- }
2541
-
2542
- return (bool) !$ct_result->allow;
2543
- }
2544
-
2545
- function ct_contact_form_is_spam_jetpack($is_spam,$form) {
2546
- global $ct_checkjs_jpcf, $apbct;
2547
-
2548
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
2549
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2550
- return null;
2551
- }
2552
-
2553
- $js_field_name = $ct_checkjs_jpcf;
2554
- foreach ($_POST as $k => $v) {
2555
- if (preg_match("/^.+$ct_checkjs_jpcf$/", $k))
2556
- $js_field_name = $k;
2557
- }
2558
-
2559
- $base_call_result = apbct_base_call(
2560
- array(
2561
- 'message' => isset($form['comment_content']) ? $form['comment_content'] : '',
2562
- 'sender_email' => isset($form['comment_author_email']) ? $form['comment_author_email'] : null,
2563
- 'sender_nickname' => isset($form['comment_author']) ? $form['comment_author'] : null,
2564
- 'post_info' => array('comment_type' => 'contact_form_wordpress_grunion'),
2565
- 'sender_info' => array('sender_url' => @$form['comment_author_url']),
2566
- )
2567
- );
2568
- $ct_result = $base_call_result['ct_result'];
2569
-
2570
- if ($ct_result->allow == 0) {
2571
- global $ct_comment;
2572
- $ct_comment = $ct_result->comment;
2573
- ct_die(null, null);
2574
- exit;
2575
- }
2576
-
2577
- return (bool) !$ct_result->allow;
2578
- }
2579
-
2580
- /**
2581
- * Inserts anti-spam hidden to WP Maintenance Mode (wpmm)
2582
- */
2583
- function apbct_form__wpmm__addField(){
2584
- ct_add_hidden_fields('ct_checkjs', false, true, true);
2585
- }
2586
-
2587
- /**
2588
- * Inserts anti-spam hidden to CF7
2589
- */
2590
- function apbct_form__contactForm7__addField($html) {
2591
- global $ct_checkjs_cf7, $apbct;
2592
-
2593
-
2594
-
2595
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
2596
- return $html;
2597
- }
2598
-
2599
- $html .= ct_add_hidden_fields($ct_checkjs_cf7, true);
2600
-
2601
- return $html;
2602
- }
2603
-
2604
- /**
2605
- * Test spam for Contact Fomr 7 (CF7) right before validation
2606
- *
2607
- * @global SpbcState $apbct
2608
- * @param type $result
2609
- * @param type $tags
2610
- * @return type
2611
- */
2612
- function apbct_form__contactForm7__tesSpam__before_validate($result = null, $tags = null) {
2613
- global $apbct;
2614
-
2615
- if ($result && method_exists($result, 'get_invalid_fields')){
2616
- $invalid_fields = $result->get_invalid_fields();
2617
- if(!empty($invalid_fields) && is_array($invalid_fields)){
2618
- $apbct->validation_error = $invalid_fields[key($invalid_fields)]['reason'];
2619
- apbct_form__contactForm7__testSpam( false );
2620
- }
2621
- }
2622
-
2623
- return $result;
2624
- }
2625
-
2626
- /**
2627
- * Test CF7 message for spam
2628
- */
2629
- function apbct_form__contactForm7__testSpam( $spam, $submission = null ) {
2630
-
2631
- global $ct_checkjs_cf7, $apbct;
2632
-
2633
- if(
2634
- $apbct->settings['forms__contact_forms_test'] == 0 ||
2635
- $spam == false && WPCF7_VERSION < '3.0.0' ||
2636
- $spam === true && WPCF7_VERSION >= '3.0.0' ||
2637
- $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() || // Skip processing for logged in users.
2638
- apbct_exclusions_check__url() ||
2639
- apbct_exclusions_check__ip() ||
2640
- isset($apbct->cf7_checked)
2641
- ){
2642
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2643
- return $spam;
2644
- }
2645
-
2646
- $checkjs = apbct_js_test($ct_checkjs_cf7, $_POST)
2647
- ? apbct_js_test($ct_checkjs_cf7, $_POST)
2648
- : apbct_js_test('ct_checkjs', $_COOKIE, true);
2649
-
2650
- $ct_temp_msg_data = ct_get_fields_any($_POST);
2651
-
2652
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2653
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
2654
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2655
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
2656
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2657
- if ($subject != '') {
2658
- $message = array_merge(array('subject' => $subject), $message);
2659
- }
2660
-
2661
- $base_call_result = apbct_base_call(
2662
- array(
2663
- 'message' => $message,
2664
- 'sender_email' => $sender_email,
2665
- 'sender_nickname' => $sender_nickname,
2666
- 'js_on' => $checkjs,
2667
- 'post_info' => array('comment_type' => 'contact_form_wordpress_cf7'),
2668
- 'sender_info' => array(
2669
- 'form_validation' => !isset($apbct->validation_error)
2670
- ? null
2671
- : json_encode(array(
2672
- 'validation_notice' => $apbct->validation_error,
2673
- 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
2674
- ))
2675
- ),
2676
- )
2677
- );
2678
-
2679
- $ct_result = $base_call_result['ct_result'];
2680
-
2681
- // Change mail notification if license is out of date
2682
- if($apbct->data['moderate'] == 0 &&
2683
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
2684
- ){
2685
- $apbct->sender_email = $sender_email;
2686
- $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
2687
- add_filter('wpcf7_mail_components', 'apbct_form__contactForm7__changeMailNotification');
2688
- }
2689
-
2690
- if ($ct_result->allow == 0) {
2691
-
2692
- global $ct_cf7_comment;
2693
- $ct_cf7_comment = $ct_result->comment;
2694
-
2695
- add_filter('wpcf7_display_message', 'apbct_form__contactForm7__showResponse', 10, 2);
2696
-
2697
- $spam = WPCF7_VERSION >= '3.0.0' ? true : false;
2698
-
2699
- }
2700
-
2701
- $apbct->cf7_checked = true;
2702
-
2703
- return $spam;
2704
- }
2705
-
2706
- /**
2707
- * Changes CF7 status message
2708
- * @param string $hook URL of hooked page
2709
- */
2710
- function apbct_form__contactForm7__showResponse($message, $status = 'spam') {
2711
- global $ct_cf7_comment;
2712
-
2713
- if ($status == 'spam') {
2714
- $message = $ct_cf7_comment;
2715
- }
2716
-
2717
- return $message;
2718
- }
2719
-
2720
- /**
2721
- * Changes email notification for succes subscription for Contact Form 7
2722
- *
2723
- * @param array $component Arguments for email notification
2724
- * @return array Arguments for email notification
2725
- */
2726
- function apbct_form__contactForm7__changeMailNotification($component){
2727
-
2728
- global $apbct;
2729
-
2730
- $component['body'] =
2731
- __('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
2732
- .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
2733
- .PHP_EOL . 'IP: ' . $apbct->sender_ip
2734
- .PHP_EOL . 'Email: ' . $apbct->sender_email
2735
- .PHP_EOL . sprintf(
2736
- __('Activate protection in your Anti-Spam Dashboard: %s.', 'clentalk'),
2737
- 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=cf7_activate_antispam&user_token='.$apbct->user_token
2738
- )
2739
- .PHP_EOL . '---' . PHP_EOL . PHP_EOL
2740
- .$component['body'];
2741
-
2742
- return (array) $component;
2743
- }
2744
-
2745
- /**
2746
- * Test Ninja Forms message for spam
2747
- *
2748
- * @global SpbcState $apbct
2749
- * @return void
2750
- */
2751
- function apbct_form__ninjaForms__testSpam() {
2752
-
2753
- global $apbct, $cleantalk_executed;
2754
-
2755
- if( $cleantalk_executed ){
2756
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2757
- return;
2758
- }
2759
-
2760
- if(
2761
- $apbct->settings['forms__contact_forms_test'] == 0
2762
- || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
2763
- || apbct_exclusions_check__url()
2764
- ){
2765
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2766
- return;
2767
- }
2768
-
2769
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
2770
-
2771
- // Choosing between POST and GET
2772
- $params = ct_get_fields_any(isset($_GET['ninja_forms_ajax_submit']) || isset($_GET['nf_ajax_submit']) ? $_GET : $_POST);
2773
-
2774
- $sender_email = ($params['email'] ? $params['email'] : '');
2775
- $sender_nickname = ($params['nickname'] ? $params['nickname'] : '');
2776
- $subject = ($params['subject'] ? $params['subject'] : '');
2777
- $message = ($params['message'] ? $params['message'] : array());
2778
- if ($subject != '') {
2779
- $message = array_merge(array('subject' => $subject), $message);
2780
- }
2781
-
2782
- //Ninja Forms xml fix
2783
- foreach ($message as $key => $value){
2784
- if (strpos($value, '<xml>') !== false)
2785
- unset($message[$key]);
2786
- }
2787
-
2788
- $base_call_result = apbct_base_call(
2789
- array(
2790
- 'message' => $message,
2791
- 'sender_email' => $sender_email,
2792
- 'sender_nickname' => $sender_nickname,
2793
- 'post_info' => array('comment_type' => 'contact_form_wordpress_ninja_froms'),
2794
- 'js_on' => $checkjs,
2795
- )
2796
- );
2797
- $ct_result = $base_call_result['ct_result'];
2798
-
2799
- // Change mail notification if license is out of date
2800
- if($apbct->data['moderate'] == 0 &&
2801
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
2802
- ){
2803
- $apbct->sender_email = $sender_email;
2804
- $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
2805
- add_filter('ninja_forms_action_email_message', 'apbct_form__ninjaForms__changeMailNotification', 1, 3);
2806
- }
2807
-
2808
- if ($ct_result->allow == 0) {
2809
-
2810
- // We have to use GLOBAL variable to transfer the comment to apbct_form__ninjaForms__changeResponse() function :(
2811
- $apbct->response = $ct_result->comment;
2812
- add_action( 'ninja_forms_before_response', 'apbct_form__ninjaForms__changeResponse', 10, 1 );
2813
- add_action( 'ninja_forms_action_email_send', 'apbct_form__ninjaForms__stopEmail', 1, 5 ); // Prevent mail notification
2814
- add_action( 'ninja_forms_save_submission', 'apbct_form__ninjaForms__preventSubmission', 1, 2 ); // Prevent mail notification
2815
- }
2816
- }
2817
-
2818
- function apbct_form__ninjaForms__preventSubmission($some, $form_id){
2819
- return false;
2820
- }
2821
-
2822
- function apbct_form__ninjaForms__stopEmail($some, $action_settings, $message, $headers, $attachments){
2823
- global $apbct;
2824
- throw new Exception($apbct->response);
2825
- }
2826
-
2827
- function apbct_form__ninjaForms__changeResponse( $data ) {
2828
-
2829
- global $apbct;
2830
-
2831
- // Show error message below field found by ID
2832
- if(array_key_exists('email', $data['fields_by_key'])){
2833
- // Find ID of EMAIL field
2834
- $nf_field_id = $data['fields_by_key']['email']['id'];
2835
- }else{
2836
- // Find ID of last field (usually SUBMIT)
2837
- $fields_keys = array_keys($data['fields']);
2838
- $nf_field_id = array_pop($fields_keys);
2839
- }
2840
-
2841
- // Below is modified NJ logic
2842
- $error = array(
2843
- 'fields' => array(
2844
- $nf_field_id => $apbct->response,
2845
- ),
2846
- );
2847
-
2848
- $response = array( 'data' => $data, 'errors' => $error, 'debug' => '' );
2849
-
2850
- die(wp_json_encode( $response, JSON_FORCE_OBJECT ));
2851
-
2852
- }
2853
-
2854
- function apbct_form__seedprod_coming_soon__testSpam() {
2855
-
2856
- global $apbct;
2857
-
2858
- if(
2859
- $apbct->settings['forms__contact_forms_test'] == 0
2860
- || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
2861
- || apbct_exclusions_check__url()
2862
- ){
2863
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2864
- return;
2865
- }
2866
-
2867
- $ct_temp_msg_data = ct_get_fields_any($_REQUEST);
2868
-
2869
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
2870
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
2871
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
2872
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
2873
- if ($subject != '') {
2874
- $message = array_merge(array('subject' => $subject), $message);
2875
- }
2876
-
2877
- $post_info['comment_type'] = 'contact_form_wordpress_seedprod_coming_soon';
2878
-
2879
- $base_call_result = apbct_base_call(
2880
- array(
2881
- 'message' => $message,
2882
- 'sender_email' => $sender_email,
2883
- 'sender_nickname' => $sender_nickname,
2884
- 'post_info' => $post_info,
2885
- )
2886
- );
2887
-
2888
- $ct_result = $base_call_result['ct_result'];
2889
- if ($ct_result->allow == 0) {
2890
- global $ct_comment;
2891
- $ct_comment = $ct_result->comment;
2892
-
2893
- $response = array(
2894
- 'status' => 200,
2895
- 'html' => "<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>"
2896
- );
2897
-
2898
- echo sanitize_text_field($_GET['callback']) . '(' . json_encode($response) . ')';
2899
- exit();
2900
- }
2901
-
2902
- }
2903
-
2904
- /**
2905
- * Changes email notification for succes subscription for Ninja Forms
2906
- *
2907
- * @param string $message Body of email notification
2908
- * @return string Body for email notification
2909
- */
2910
- function apbct_form__ninjaForms__changeMailNotification($message, $data, $action_settings){
2911
-
2912
- global $apbct;
2913
-
2914
- if($action_settings['to'] !== $apbct->sender_email){
2915
-
2916
- $message .= wpautop(PHP_EOL . '---'
2917
- .PHP_EOL
2918
- .__('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
2919
- .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
2920
- .PHP_EOL . 'IP: ' . $apbct->sender_ip
2921
- .PHP_EOL . 'Email: ' . $apbct->sender_email
2922
- .PHP_EOL .
2923
- __('Activate protection in your Anti-Spam Dashboard: ', 'clentalk').
2924
- 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=ninjaform_activate_antispam'.$apbct->user_token
2925
- );
2926
- }
2927
-
2928
- return $message;
2929
- }
2930
-
2931
- /**
2932
- * Inserts anti-spam hidden to WPForms
2933
- *
2934
- * @global SpbcState $apbct
2935
- * @return void
2936
- */
2937
- function apbct_form__WPForms__addField($form_data, $some, $title, $description, $errors) {
2938
-
2939
- global $apbct;
2940
-
2941
- if($apbct->settings['forms__contact_forms_test'] == 1)
2942
- ct_add_hidden_fields('ct_checkjs_wpforms', false);
2943
-
2944
- }
2945
-
2946
- /**
2947
- * Gather fields data from submission and store it
2948
- *
2949
- * @param array $entry
2950
- * @param $form
2951
- *
2952
- * @return array
2953
- * @global SpbcState $apbct
2954
- */
2955
- function apbct_from__WPForms__gatherData($entry, $form){
2956
-
2957
- global $apbct;
2958
- $handled_result = array();
2959
-
2960
- $entry_fields_data = $entry['fields'] ?: array();
2961
- $form_fields_info = $form['fields'] ?: array();
2962
-
2963
- foreach ($form_fields_info as $form_field) {
2964
- $field_id = $form_field['id'];
2965
- $field_type = $form_field['type'];
2966
- $field_label = $form_field['label'] ?: '';
2967
- if( ! isset( $entry_fields_data[$field_id] ) ){
2968
- continue;
2969
- }
2970
- $entry_field_value = $entry_fields_data[$field_id];
2971
-
2972
- # search email field
2973
- if($field_type === 'email') {
2974
- if( ! isset($handled_result['email']) || empty($handled_result['email'])) {
2975
- $handled_result['email'] = $entry_field_value;
2976
- continue;
2977
- }
2978
- }
2979
-
2980
- # search name
2981
- if($field_type === 'name') {
2982
- if( ! isset($handled_result['name']) || empty($handled_result['name'])) {
2983
- if(is_array($entry_field_value)) {
2984
- $handled_result['name'] = implode(' ', $entry_field_value);
2985
- } else {
2986
- $handled_result['name'] = array('nick' => $entry_field_value, 'first' => '', 'last' => '');
2987
- }
2988
- continue;
2989
- }
2990
- }
2991
-
2992
- # Add field label as key for result array
2993
- # add unique key if key exist
2994
- if($field_label) {
2995
- $field_label = trim(mb_strtolower($field_label));
2996
- $field_label = str_replace(' ', '_', $field_label);
2997
- $field_label = preg_replace('/\W/u', '', $field_label);
2998
-
2999
- if( ! isset($handled_result[$field_label]) || empty($handled_result[$field_label])) {
3000
- $handled_result[$field_label] = $entry_field_value;
3001
- } else {
3002
- $handled_result[$field_label . rand(0, 100)] = $entry_field_value;
3003
- }
3004
- }
3005
- }
3006
-
3007
- $apbct->form_data = $handled_result;
3008
-
3009
- return $entry;
3010
- }
3011
-
3012
- /**
3013
- * Adding error to form entry if message is spam
3014
- * Call spam test from here
3015
- *
3016
- * @param array $errors
3017
- * @param array $form_data
3018
- * @return array
3019
- */
3020
- function apbct_form__WPForms__showResponse($errors, $form_data) {
3021
-
3022
- if(empty($errors) || ( isset($form_data['id'], $errors[$form_data['id']]) && !count($errors[$form_data['id']]) ) ){
3023
-
3024
- $spam_comment = apbct_form__WPForms__testSpam();
3025
-
3026
- $filed_id = $form_data && !empty($form_data['fields']) && is_array($form_data['fields'])
3027
- ? key($form_data['fields'])
3028
- : 0;
3029
-
3030
- if($spam_comment)
3031
- $errors[ $form_data['id'] ][ $filed_id ] = $spam_comment;
3032
-
3033
- }
3034
-
3035
- return $errors;
3036
- }
3037
-
3038
- /**
3039
- * Test WPForms message for spam
3040
- * Doesn't hooked anywhere.
3041
- * Called directly from apbct_form__WPForms__showResponse()
3042
- *
3043
- * @global SpbcState $apbct
3044
- * @global array $apbct->form_data Contains form data
3045
- * @param array $errors Array of errors to write false result in
3046
- * @return void|array|null
3047
- */
3048
- function apbct_form__WPForms__testSpam() {
3049
-
3050
- global $apbct;
3051
-
3052
- if(
3053
- $apbct->settings['forms__contact_forms_test'] == 0 ||
3054
- $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() // Skip processing for logged in users.
3055
- ){
3056
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3057
- return;
3058
- }
3059
-
3060
- $checkjs = apbct_js_test('ct_checkjs_wpforms', $_POST);
3061
-
3062
- $email = $apbct->form_data['email'] ?: null;
3063
- $nickname = $apbct->form_data['name'] ?: null;
3064
- $form_data = $apbct->form_data;
3065
-
3066
- if($email) {
3067
- unset($form_data['email']);
3068
- }
3069
- if($nickname) {
3070
- unset($form_data['name']);
3071
- }
3072
-
3073
- $params = ct_get_fields_any($apbct->form_data, array(), $email);
3074
-
3075
- if(is_array($params['nickname'])) {
3076
- $params['nickname'] = implode(' ', $params['nickname']);
3077
- }
3078
-
3079
- $sender_email = ($params['email'] ? $params['email'] : '');
3080
- $sender_nickname = ($params['nickname'] ? $params['nickname'] : '');
3081
- $subject = ($params['subject'] ? $params['subject'] : '');
3082
- $message = ($params['message'] ? $params['message'] : array());
3083
- if ($subject != '') {
3084
- $message = array_merge(array('subject' => $subject), $message);
3085
- }
3086
-
3087
- $base_call_result = apbct_base_call(
3088
- array(
3089
- 'message' => $message,
3090
- 'sender_email' => $sender_email,
3091
- 'sender_nickname' => $sender_nickname,
3092
- 'post_info' => array('comment_type' => 'contact_form_wordpress_wp_forms'),
3093
- 'js_on' => $checkjs,
3094
- )
3095
- );
3096
- $ct_result = $base_call_result['ct_result'];
3097
-
3098
- // Change mail notification if license is out of date
3099
- if($apbct->data['moderate'] == 0 &&
3100
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
3101
- ){
3102
- $apbct->sender_email = $sender_email;
3103
- $apbct->sender_ip = \Cleantalk\ApbctWP\Helper::ip__get('real');
3104
- add_filter('wpforms_email_message', 'apbct_form__WPForms__changeMailNotification', 100, 2);
3105
- }
3106
-
3107
- if ($ct_result->allow == 0){
3108
- return $ct_result->comment;
3109
- }
3110
-
3111
- return null;
3112
-
3113
- }
3114
-
3115
- /**
3116
- * Changes email notification for succes subscription for Ninja Forms
3117
- *
3118
- * @param string $message Body of email notification
3119
- * @param WPForms_WP_Emails $wpforms_email WPForms email class object
3120
- * @return string Body for email notification
3121
- */
3122
- function apbct_form__WPForms__changeMailNotification($message, $wpforms_email){
3123
-
3124
- global $apbct;
3125
-
3126
- $message = str_replace('</html>', '', $message);
3127
- $message = str_replace('</body>', '', $message);
3128
- $message .= wpautop(PHP_EOL . '---'
3129
- .PHP_EOL
3130
- .__('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
3131
- .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
3132
- .PHP_EOL . 'IP: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_ip . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_ip . '</a>'
3133
- .PHP_EOL . 'Email: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_email . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_email . '</a>'
3134
- .PHP_EOL . sprintf(
3135
- __('Activate protection in your %sAnti-Spam Dashboard%s.', 'clentalk'),
3136
- '<a href="https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_activate_antispam" target="_blank">',
3137
- '</a>'
3138
- ))
3139
- .'</body></html>';
3140
-
3141
- return $message;
3142
-
3143
- }
3144
-
3145
- /*
3146
- * QuForms check spam
3147
- * works with singl-paged forms
3148
- * and with multi-paged forms - check only last step of the forms
3149
- */
3150
- function ct_quform_post_validate($result, $form) {
3151
-
3152
- if ( $form->hasPages() ) {
3153
- $comment_type = 'contact_form_wordpress_quforms_multipage';
3154
- } else {
3155
- $comment_type = 'contact_form_wordpress_quforms_singlepage';
3156
- }
3157
-
3158
- $ct_temp_msg_data = ct_get_fields_any( $form->getValues() );
3159
- // @ToDo If we have several emails at the form - will be used only the first detected!
3160
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
3161
-
3162
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
3163
- $base_call_result = apbct_base_call(
3164
- array(
3165
- 'message' => $form->getValues(),
3166
- 'sender_email' => $sender_email,
3167
- 'post_info' => array('comment_type' => $comment_type),
3168
- 'js_on' => $checkjs,
3169
- )
3170
- );
3171
-
3172
- $ct_result = $base_call_result['ct_result'];
3173
- if ($ct_result->allow == 0) {
3174
- die(json_encode(array('type' => 'error', 'apbct' => array('blocked' => true, 'comment' => $ct_result->comment)), JSON_HEX_QUOT | JSON_HEX_TAG));
3175
- } else {
3176
- return $result;
3177
- }
3178
-
3179
- return $result;
3180
-
3181
- }
3182
-
3183
- /**
3184
- * Inserts anti-spam hidden to Fast Secure contact form
3185
- */
3186
- function ct_si_contact_display_after_fields($string = '', $style = '', $form_errors = array(), $form_id_num = 0) {
3187
- $string .= ct_add_hidden_fields('ct_checkjs', true);
3188
- return $string;
3189
- }
3190
-
3191
- /**
3192
- * Test for Fast Secure contact form
3193
- */
3194
- function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
3195
- global $apbct, $cleantalk_executed;
3196
-
3197
- if (!empty($form_errors)) {
3198
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3199
- return $form_errors;
3200
- }
3201
-
3202
-
3203
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
3204
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3205
- return $form_errors;
3206
- }
3207
-
3208
- // Skip processing because data already processed.
3209
- if ($cleantalk_executed) {
3210
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3211
- return $form_errors;
3212
- }
3213
-
3214
- //getting info from custom fields
3215
- $ct_temp_msg_data = ct_get_fields_any($_POST);
3216
-
3217
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
3218
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
3219
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
3220
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
3221
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
3222
- if($subject != '') {
3223
- $message['subject'] = $subject;
3224
- }
3225
-
3226
- $base_call_result = apbct_base_call(
3227
- array(
3228
- 'message' => $message,
3229
- 'sender_email' => $sender_email,
3230
- 'sender_nickname' => $sender_nickname,
3231
- 'post_info' => array('comment_type' => 'contact_form_wordpress_fscf'),
3232
- 'js_on' => apbct_js_test('ct_checkjs', $_POST),
3233
- )
3234
- );
3235
-
3236
- $ct_result = $base_call_result['ct_result'];
3237
-
3238
- $cleantalk_executed = true;
3239
-
3240
- if ($ct_result->allow == 0) {
3241
- global $ct_comment;
3242
- $ct_comment = $ct_result->comment;
3243
- ct_die(null, null);
3244
- exit;
3245
- }
3246
-
3247
- return $form_errors;
3248
- }
3249
-
3250
- /**
3251
- * Notice for commentators which comment has automatically approved by plugin
3252
- * @param string $hook URL of hooked page
3253
- */
3254
- function ct_comment_text($comment_text) {
3255
- global $comment, $ct_approved_request_id_label;
3256
-
3257
- if (isset($_COOKIE[$ct_approved_request_id_label]) && isset($comment->comment_ID)) {
3258
- $ct_hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
3259
-
3260
- if ($ct_hash !== '' && $_COOKIE[$ct_approved_request_id_label] == $ct_hash) {
3261
- $comment_text .= '<br /><br /> <em class="comment-awaiting-moderation">' . __('Comment approved. Anti-spam by CleanTalk.', 'cleantalk-spam-protect') . '</em>';
3262
- }
3263
- }
3264
-
3265
- return $comment_text;
3266
- }
3267
-
3268
-
3269
- /**
3270
- * Checks WordPress Landing Pages raw $_POST values
3271
- */
3272
- function ct_check_wplp(){
3273
-
3274
- global $ct_wplp_result_label, $apbct;
3275
-
3276
- if (!isset($_COOKIE[$ct_wplp_result_label])) {
3277
- // First AJAX submit of WPLP form
3278
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
3279
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3280
- return;
3281
- }
3282
-
3283
- $post_info['comment_type'] = 'feedback';
3284
- $post_info = json_encode($post_info);
3285
- if ($post_info === false)
3286
- $post_info = '';
3287
-
3288
- $sender_email = '';
3289
- foreach ($_POST as $v) {
3290
- if (preg_match("/^\S+@\S+\.\S+$/", $v)) {
3291
- $sender_email = $v;
3292
- break;
3293
- }
3294
- }
3295
-
3296
- $message = '';
3297
- if(array_key_exists('form_input_values', $_POST)){
3298
- $form_input_values = json_decode(stripslashes($_POST['form_input_values']), true);
3299
- if (is_array($form_input_values) && array_key_exists('null', $form_input_values))
3300
- $message = $form_input_values['null'];
3301
- } else if (array_key_exists('null', $_POST)) {
3302
- $message = $_POST['null'];
3303
- }
3304
-
3305
- $base_call_result = apbct_base_call(
3306
- array(
3307
- 'message' => $message,
3308
- 'sender_email' => $sender_email,
3309
- 'post_info' => array('comment_type' => 'contact_form_wordpress_wplp'),
3310
- )
3311
- );
3312
-
3313
- $ct_result = $base_call_result['ct_result'];
3314
-
3315
- if ($ct_result->allow == 0) {
3316
- $cleantalk_comment = $ct_result->comment;
3317
- } else {
3318
- $cleantalk_comment = 'OK';
3319
- }
3320
-
3321
- \Cleantalk\ApbctWP\Variables\Cookie::set($ct_wplp_result_label, $cleantalk_comment, strtotime("+5 seconds"), '/');
3322
- } else {
3323
- // Next POST/AJAX submit(s) of same WPLP form
3324
- $cleantalk_comment = $_COOKIE[$ct_wplp_result_label];
3325
- }
3326
- if ($cleantalk_comment !== 'OK')
3327
- ct_die_extended($cleantalk_comment);
3328
- }
3329
-
3330
- /**
3331
- * Places a hidding field to Gravity forms.
3332
- * @return string
3333
- */
3334
- function apbct_form__gravityForms__addField($form_string, $form){
3335
- $ct_hidden_field = 'ct_checkjs';
3336
-
3337
- // Do not add a hidden field twice.
3338
- if (preg_match("/$ct_hidden_field/", $form_string)) {
3339
- return $form_string;
3340
- }
3341
-
3342
- $search = "</form>";
3343
-
3344
- // Adding JS code
3345
- $js_code = ct_add_hidden_fields($ct_hidden_field, true, false);
3346
- $form_string = str_replace($search, $js_code . $search, $form_string);
3347
-
3348
- // Adding field for multipage form. Look for cleantalk.php -> apbct_cookie();
3349
- $append_string = isset($form['lastPageButton']) ? "<input type='hidden' name='ct_multipage_form' value='yes'>" : '';
3350
- $form_string = str_replace($search, $append_string.$search, $form_string);
3351
-
3352
- return $form_string;
3353
- }
3354
-
3355
- /**
3356
- * Gravity forms anti-spam test.
3357
- * @return boolean
3358
- */
3359
- function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
3360
-
3361
- global $apbct, $cleantalk_executed, $ct_gform_is_spam, $ct_gform_response;
3362
-
3363
- if (
3364
- $apbct->settings['forms__contact_forms_test'] == 0 ||
3365
- $cleantalk_executed // Return unchanged result if the submission was already tested.
3366
- ) {
3367
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3368
- return $is_spam;
3369
- }
3370
-
3371
- $form_fields_for_ct = array();
3372
- foreach($entry as $key => $value){
3373
- if(is_numeric($key))
3374
- $form_fields_for_ct['input_' . $key]=$value;
3375
- } unset($key, $value);
3376
-
3377
- $ct_temp_msg_data = ct_get_fields_any( $form_fields_for_ct );
3378
-
3379
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
3380
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
3381
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
3382
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
3383
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
3384
-
3385
- if($subject != '')
3386
- $message['subject'] = $subject;
3387
-
3388
- $checkjs = apbct_js_test('ct_checkjs', $_POST)
3389
- ? apbct_js_test('ct_checkjs', $_POST)
3390
- : apbct_js_test('ct_checkjs', $_COOKIE, true);
3391
-
3392
- $base_call_result = apbct_base_call(
3393
- array(
3394
- 'message' => $message,
3395
- 'sender_email' => $sender_email,
3396
- 'sender_nickname' => $sender_nickname,
3397
- 'post_info' => array('comment_type' => 'contact_form_wordpress_gravity_forms'),
3398
- 'js_on' => $checkjs,
3399
- )
3400
- );
3401
-
3402
- $ct_result = $base_call_result['ct_result'];
3403
- if ($ct_result->allow == 0) {
3404
- $is_spam = true;
3405
- $ct_gform_is_spam = true;
3406
- $ct_gform_response = $ct_result->comment;
3407
- }
3408
-
3409
- return $is_spam;
3410
- }
3411
-
3412
- function apbct_form__gravityForms__showResponse( $confirmation, $form, $entry, $ajax ){
3413
-
3414
- global $ct_gform_is_spam, $ct_gform_response;
3415
-
3416
- if(!empty($ct_gform_is_spam)){
3417
- $confirmation = '<a id="gf_'.$form['id'].'" class="gform_anchor" ></a><div id="gform_confirmation_wrapper_'.$form['id'].'" class="gform_confirmation_wrapper "><div id="gform_confirmation_message_'.$form['id'].'" class="gform_confirmation_message_'.$form['id'].' gform_confirmation_message"><font style="color: red">'.$ct_gform_response.'</font></div></div>';
3418
- }
3419
-
3420
- return $confirmation;
3421
- }
3422
-
3423
- /**
3424
- * Test S2member registration
3425
- * @return array with errors
3426
- */
3427
- function ct_s2member_registration_test($post_key) {
3428
-
3429
- global $apbct;
3430
-
3431
- if ($apbct->settings['forms__registrations_test'] == 0) {
3432
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3433
- return null;
3434
- }
3435
-
3436
- $sender_email = isset($_POST[$post_key]['email']) ? sanitize_email($_POST[$post_key]['email']) : null;
3437
- $sender_nickname = isset($_POST[$post_key]['username']) ? sanitize_email($_POST[$post_key]['username']) : null;
3438
-
3439
- //Making a call
3440
- $base_call_result = apbct_base_call(
3441
- array(
3442
- 'sender_email' => $sender_email,
3443
- 'sender_nickname' => $sender_nickname,
3444
- ),
3445
- true
3446
- );
3447
- $ct_result = $base_call_result['ct_result'];
3448
-
3449
- if ($ct_result->allow == 0) {
3450
- ct_die_extended($ct_result->comment);
3451
- }
3452
-
3453
- return true;
3454
- }
3455
-
3456
- function apbct_form__the7_contact_form() {
3457
-
3458
- global $cleantalk_executed;
3459
-
3460
- if ( check_ajax_referer( 'dt_contact_form', 'nonce', false ) && isset($_POST) ) {
3461
-
3462
- $post_info['comment_type'] = 'contact_the7_theme_contact_form';
3463
-
3464
- $ct_temp_msg_data = ct_get_fields_any($_POST);
3465
-
3466
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
3467
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
3468
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
3469
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
3470
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
3471
- if ($subject != '') {
3472
- $message = array_merge(array('subject' => $subject), $message);
3473
- }
3474
-
3475
- // Skip submission if no data found
3476
- if ($sender_email === ''|| !$contact_form) {
3477
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3478
- return false;
3479
- }
3480
- $cleantalk_executed = true;
3481
-
3482
- $base_call_result = apbct_base_call(
3483
- array(
3484
- 'message' => $message,
3485
- 'sender_email' => $sender_email,
3486
- 'sender_nickname' => $sender_nickname,
3487
- 'post_info' => $post_info,
3488
- )
3489
- );
3490
-
3491
- $ct_result = $base_call_result['ct_result'];
3492
- if ($ct_result->allow == 0) {
3493
-
3494
- $response = json_encode(
3495
- array(
3496
- 'success' => false ,
3497
- 'errors' => $ct_result->comment,
3498
- 'nonce' => wp_create_nonce( 'dt_contact_form' )
3499
- )
3500
- );
3501
-
3502
- // response output
3503
- header( "Content-Type: application/json" );
3504
- echo $response;
3505
-
3506
- // IMPORTANT: don't forget to "exit"
3507
- exit;
3508
-
3509
- }
3510
-
3511
- }
3512
-
3513
- }
3514
-
3515
- function apbct_form__elementor_pro__testSpam() {
3516
-
3517
- global $apbct, $cleantalk_executed;
3518
-
3519
- if(
3520
- $apbct->settings['forms__contact_forms_test'] == 0
3521
- || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
3522
- || apbct_exclusions_check__url()
3523
- ){
3524
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3525
- return;
3526
- }
3527
-
3528
- $ct_temp_msg_data = ct_get_fields_any($_POST);
3529
-
3530
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
3531
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
3532
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
3533
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
3534
- if ($subject != '') {
3535
- $message = array_merge(array('subject' => $subject), $message);
3536
- }
3537
-
3538
- $post_info['comment_type'] = 'contact_form_wordpress_elementor_pro';
3539
-
3540
- $base_call_result = apbct_base_call(
3541
- array(
3542
- 'message' => $message,
3543
- 'sender_email' => $sender_email,
3544
- 'sender_nickname' => $sender_nickname,
3545
- 'post_info' => $post_info,
3546
- )
3547
- );
3548
-
3549
- $ct_result = $base_call_result['ct_result'];
3550
-
3551
- if ($ct_result->allow == 0) {
3552
-
3553
- wp_send_json_error( array(
3554
- 'message' => $ct_result->comment,
3555
- 'data' => array()
3556
- ) );
3557
-
3558
- }
3559
-
3560
- }
3561
-
3562
- // INEVIO theme integration
3563
- function apbct_form__inevio__testSpam() {
3564
-
3565
- global $apbct, $cleantalk_executed;
3566
-
3567
- $theme = wp_get_theme();
3568
- if(
3569
- stripos( $theme->get( 'Name' ), 'INEVIO' ) === false ||
3570
- $apbct->settings['forms__contact_forms_test'] == 0 ||
3571
- ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
3572
- apbct_exclusions_check__url()
3573
- ) {
3574
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3575
- return false;
3576
- }
3577
- $form_data = array();
3578
- parse_str($_POST['data'], $form_data);
3579
-
3580
- $name = isset($form_data['name']) ? $form_data['name'] : '';
3581
- $email = isset($form_data['email']) ? $form_data['email'] : '';
3582
- $message = isset($form_data['message']) ? $form_data['message'] : '';
3583
-
3584
- $post_info['comment_type'] = 'contact_form_wordpress_inevio_theme';
3585
-
3586
- $base_call_result = apbct_base_call(
3587
- array(
3588
- 'message' => $message,
3589
- 'sender_email' => $email,
3590
- 'sender_nickname' => $name,
3591
- 'post_info' => $post_info,
3592
- )
3593
- );
3594
-
3595
- $ct_result = $base_call_result['ct_result'];
3596
-
3597
- if ( $ct_result->allow == 0 ) {
3598
- die(json_encode(array('apbct' => array('blocked' => true, 'comment' => $ct_result->comment,)), JSON_HEX_QUOT | JSON_HEX_TAG));
3599
- }
3600
-
3601
- return true;
3602
-
3603
- }
3604
-
3605
- /**
3606
- * General test for any contact form
3607
- */
3608
- function ct_contact_form_validate() {
3609
-
3610
- global $pagenow,$cleantalk_executed ,$apbct, $ct_checkjs_frm;
3611
-
3612
- // Exclusios common function
3613
- if ( apbct_exclusions_check(__FUNCTION__) ) {
3614
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3615
- return null;
3616
- }
3617
-
3618
- if (@sizeof($_POST)==0 ||
3619
- (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
3620
- (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
3621
- (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action']=='lostpassword') ||
3622
- apbct_is_in_referer( 'lostpassword' ) ||
3623
- apbct_is_in_referer( 'lost-password' ) || //Skip lost-password form check
3624
- (apbct_is_in_uri('/wp-admin/') && (empty($_POST['your-phone']) && empty($_POST['your-email']) && empty($_POST['your-message']))) || //Bitrix24 Contact
3625
- apbct_is_in_uri('wp-login.php') ||
3626
- apbct_is_in_uri('wp-comments-post.php') ||
3627
- apbct_is_in_uri('?provider=facebook&') ||
3628
- apbct_is_in_uri('reset-password/') || // Ticket #13668. Password reset.
3629
- apbct_is_in_referer( '/wp-admin/') ||
3630
- apbct_is_in_uri('/login/') ||
3631
- apbct_is_in_uri( '/my-account/edit-account/') || // WooCommerce edit account page
3632
- apbct_is_in_uri( '/my-account/edit-address/') || // WooCommerce edit account page
3633
- (isset($_POST['action']) && $_POST['action'] == 'save_account_details') || // WooCommerce edit account action
3634
- apbct_is_in_uri( '/peepsoajax/profilefieldsajax.validate_register') ||
3635
- isset($_GET['ptype']) && $_GET['ptype']=='login' ||
3636
- isset($_POST['ct_checkjs_register_form']) ||
3637
- (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit']) ) ||
3638
- $apbct->settings['forms__general_contact_forms_test'] == 0 ||
3639
- isset($_POST['bbp_topic_content']) ||
3640
- isset($_POST['bbp_reply_content']) ||
3641
- isset($_POST['fscf_submitted']) ||
3642
- apbct_is_in_uri('/wc-api') ||
3643
- isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit']) ||
3644
- isset($_POST[$ct_checkjs_frm]) && $apbct->settings['forms__contact_forms_test'] == 1 ||// Formidable forms
3645
- ( isset($_POST['comment_post_ID']) && ! isset($_POST['comment-submit'] ) ) || // The comment form && ! DW Question & Answer
3646
- isset($_GET['for']) ||
3647
- (isset($_POST['log'], $_POST['pwd'])) || //WooCommerce Sensei login form fix
3648
- (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || // WooCommerce recovery password form
3649
- ((isset($_POST['woocommerce-login-nonce']) || isset($_POST['_wpnonce'])) && isset($_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || // WooCommerce login form
3650
- (isset($_POST['wc-api']) && strtolower($_POST['wc-api']) == 'wc_gateway_systempay') || // Woo Systempay payment plugin
3651
- apbct_is_in_uri( 'wc-api=WC_Gateway_Realex_Redirect') || // Woo Realex payment Gateway plugin
3652
- apbct_is_in_uri( 'wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
3653
- (isset($_POST['_wpcf7'], $_POST['_wpcf7_version'], $_POST['_wpcf7_locale'])) || //CF7 fix)
3654
- (isset($_POST['hash'], $_POST['device_unique_id'], $_POST['device_name'])) ||//Mobile Assistant Connector fix
3655
- isset($_POST['gform_submit']) || //Gravity form
3656
- apbct_is_in_uri( 'wc-ajax=get_refreshed_fragments') ||
3657
- (isset($_POST['ccf_form']) && intval($_POST['ccf_form']) == 1) ||
3658
- (isset($_POST['contact_tags']) && strpos($_POST['contact_tags'], 'MBR:') !== false) ||
3659
- (apbct_is_in_uri( 'bizuno.php') && !empty($_POST['bizPass'])) ||
3660
- apbct_is_in_referer( 'my-dashboard/' ) || // ticket_id=7885
3661
- isset($_POST['slm_action'], $_POST['license_key'], $_POST['secret_key'], $_POST['registered_domain']) || // ticket_id=9122
3662
- (isset($_POST['wpforms']['submit']) && $_POST['wpforms']['submit'] == 'wpforms-submit') || // WPForms
3663
- (isset($_POST['action']) && $_POST['action'] == 'grunion-contact-form') || // JetPack
3664
- (isset($_POST['action']) && $_POST['action'] == 'bbp-update-user') || //BBP update user info page
3665
- apbct_is_in_referer( '?wc-api=WC_Gateway_Transferuj' ) || //WC Gateway
3666
- (isset($_GET['mbr'], $_GET['amp;appname'], $_GET['amp;master'])) || // ticket_id=10773
3667
- (isset($_POST['call_function']) && $_POST['call_function'] == 'push_notification_settings') || // Skip mobile requests (push settings)
3668
- apbct_is_in_uri('membership-login') || // Skip login form
3669
- (isset($_GET['cookie-state-change'])) || //skip GDPR plugin
3670
- ( apbct_get_server_variable( 'HTTP_USER_AGENT' ) == 'MailChimp' && apbct_is_in_uri( 'mc4wp-sync-api/webhook-listener') ) || // Mailchimp webhook skip
3671
- apbct_is_in_uri('researcher-log-in') || // Skip login form
3672
- apbct_is_in_uri('admin_aspcms/_system/AspCms_SiteSetting.asp?action=saves') || // Skip admin save callback
3673
- apbct_is_in_uri('?profile_tab=postjobs') || // Skip post vacancies
3674
- (isset($_POST['btn_insert_post_type_hotel']) && $_POST['btn_insert_post_type_hotel'] == 'SUBMIT HOTEL') || // Skip adding hotel
3675
- (isset($_POST['action']) && $_POST['action'] == 'updraft_savesettings') || // Updraft save settings
3676
- isset($_POST['quform_submit']) || //QForms multi-paged form skip
3677
- (isset($_POST['wpum_form']) && $_POST['wpum_form'] == 'login') || //WPUM login skip
3678
- isset($_POST['password']) || // Exception for login form. From Analysis uid=406596
3679
- (isset($_POST['action']) && $_POST['action'] == 'wilcity_reset_password') || // Exception for reset password form. From Analysis uid=430898
3680
- (isset($_POST['action']) && $_POST['action'] == 'wilcity_login') || // Exception for login form. From Analysis uid=430898
3681
- (isset($_POST['qcfsubmit'])) || //Exception for submit quick forms - duplicates with qcfvalidate
3682
- apbct_is_in_uri('tin-canny-learndash-reporting/src/h5p-xapi/process-xapi-statement.php?v=asd') || //Skip Tin Canny plugin
3683
- ( isset( $_POST['na'], $_POST['ts'], $_POST['nhr'] ) && !apbct_is_in_uri( '?na=s' ) ) || // The Newsletter Plugin double requests fix. Ticket #14772
3684
- (isset($_POST['spl_action']) && $_POST['spl_action'] == 'register') || //Skip interal action with empty params
3685
- (isset($_POST['action']) && $_POST['action'] == 'bwfan_insert_abandoned_cart' && apbct_is_in_uri( 'my-account/edit-address' )) || //Skip edit account
3686
- apbct_is_in_uri('login-1') || //Skip login form
3687
- apbct_is_in_uri('recuperacao-de-senha-2') || //Skip form reset password
3688
- apbct_is_in_uri('membermouse/api/request.php') && isset($_POST['membership_level_id'],$_POST['apikey'],$_POST['apisecret']) || // Membermouse API
3689
- ( isset( $_POST['AppKey'] ) && ( isset( $_POST['cbAP'] ) && $_POST['cbAP'] == 'Caspio' ) ) || // Caspio exclusion (ticket #16444)
3690
- isset($_POST['wpforms_id'], $_POST['wpforms_author']) || //Skip wpforms
3691
- ( isset( $_POST['somfrp_action'], $_POST['submitted'] ) && $_POST['somfrp_action'] == 'somfrp_lost_pass' ) || // Frontend Reset Password exclusion
3692
- ( isset( $_POST['action'] ) && $_POST['action'] == 'dokan_save_account_details' ) ||
3693
- \Cleantalk\Variables\Post::get('action') === 'frm_get_lookup_text_value' || // Exception for Formidable multilevel form
3694
- ( isset( $_POST['ihcaction'] ) && $_POST['ihcaction'] == 'reset_pass') || //Reset pass exclusion
3695
- ( isset( $_POST['action'], $_POST['register_unspecified_nonce_field'] ) && $_POST['action'] == 'register' ) || // Profile Builder have a direct integration
3696
- ( isset( $_POST['_wpmem_register_nonce'] ) && wp_verify_nonce( $_POST['_wpmem_register_nonce'], 'wpmem_longform_nonce' ) ) || // WP Members have a direct integration
3697
- apbct_is_in_uri('/settings/') && isset($_POST['submit']) || // Buddypress integration
3698
- apbct_is_in_uri('/settings/notifications/') && isset($_POST['submit']) || // Buddypress integration
3699
- apbct_is_in_uri('/settings/profile/') && isset($_POST['submit']) || // Buddypress integration
3700
- apbct_is_in_uri('/settings/data/') && isset($_POST['submit']) || // Buddypress integration
3701
- apbct_is_in_uri('/settings/delete-account/') && isset($_POST['submit']) || // Buddypress integration
3702
- apbct_is_in_uri('/profile/') && isset($_POST['submit']) || // Buddypress integration
3703
- ( isset( $_POST['action'] ) && $_POST['action'] == 'bwfan_insert_abandoned_cart' ) || // Autonami Marketing Automations - WC Plugin - integration
3704
- ( isset( $_POST['action'] ) && $_POST['action'] == 'check_email_exists' ) // Handling an unknown action check_email_exists
3705
- /* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
3706
- ) {
3707
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3708
- return null;
3709
- }
3710
-
3711
- // Skip REST API requests
3712
- if ( Server::isPost() && Server::in_uri( 'rest_route') )
3713
- {
3714
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3715
- return null;
3716
- }
3717
-
3718
- //Skip woocommerce checkout
3719
- if (apbct_is_in_uri('wc-ajax=update_order_review') ||
3720
- apbct_is_in_uri('wc-ajax=checkout') ||
3721
- !empty($_POST['woocommerce_checkout_place_order']) ||
3722
- apbct_is_in_uri('wc-ajax=wc_ppec_start_checkout') ||
3723
- apbct_is_in_referer('wc-ajax=update_order_review')
3724
- )
3725
- {
3726
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3727
- return null;
3728
- }
3729
-
3730
- //Skip woocommerce add_to_cart
3731
- if( ! empty( $_POST['add-to-cart'] ) )
3732
- {
3733
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3734
- return null;
3735
- }
3736
-
3737
- // Do not execute anti-spam test for logged in users.
3738
- if (isset($_COOKIE[LOGGED_IN_COOKIE]) && $apbct->settings['data__protect_logged_in'] != 1) {
3739
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3740
- return null;
3741
- }
3742
- //Skip WP Fusion web hooks
3743
- if ( apbct_is_in_uri('wpf_action') && apbct_is_in_uri('access_key') && isset( $_GET['access_key'] ) ) {
3744
- if( function_exists( 'wp_fusion' ) ) {
3745
- $key = wp_fusion()->settings->get('access_key');
3746
- if ( $key == $_GET['access_key'] ) {
3747
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3748
- return null;
3749
- }
3750
- }
3751
- }
3752
- //Skip system fields for divi
3753
- if (strpos( \Cleantalk\Variables\Post::get('action'), 'et_pb_contactform_submit') === 0) {
3754
- foreach ($_POST as $key => $value) {
3755
- if (strpos($key, 'et_pb_contact_email_fields') === 0) {
3756
- unset($_POST[$key]);
3757
- }
3758
- }
3759
- }
3760
-
3761
- if( apbct_is_skip_request( false ) ) {
3762
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . '(' . apbct_is_skip_request() . ')', $_POST );
3763
- return false;
3764
- }
3765
-
3766
- $post_info['comment_type'] = 'feedback_general_contact_form';
3767
-
3768
- $ct_temp_msg_data = ct_get_fields_any($_POST);
3769
-
3770
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
3771
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
3772
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
3773
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
3774
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
3775
- if ($subject != '') {
3776
- $message = array_merge(array('subject' => $subject), $message);
3777
- }
3778
-
3779
- // Skip submission if no data found
3780
- if ($sender_email === ''|| !$contact_form) {
3781
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3782
- return false;
3783
- }
3784
-
3785
- if(isset($_POST['TellAFriend_Link'])){
3786
- $tmp = $_POST['TellAFriend_Link'];
3787
- unset($_POST['TellAFriend_Link']);
3788
- }
3789
-
3790
- $base_call_result = apbct_base_call(
3791
- array(
3792
- 'message' => $message,
3793
- 'sender_email' => $sender_email,
3794
- 'sender_nickname' => $sender_nickname,
3795
- 'post_info' => $post_info,
3796
- 'sender_info' => array( 'sender_email' => urlencode( $sender_email ) ),
3797
- )
3798
- );
3799
-
3800
- if(isset($_POST['TellAFriend_Link'])){
3801
- $_POST['TellAFriend_Link']=$tmp;
3802
- }
3803
-
3804
- $ct_result = $base_call_result['ct_result'];
3805
- if ($ct_result->allow == 0) {
3806
-
3807
- // Recognize contact form an set it's name to $contact_form to use later
3808
- $contact_form = null;
3809
- foreach($_POST as $param => $value){
3810
- if(strpos($param, 'et_pb_contactform_submit') === 0){
3811
- $contact_form = 'contact_form_divi_theme';
3812
- $contact_form_additional = str_replace('et_pb_contactform_submit', '', $param);
3813
- }
3814
- if(strpos($param, 'avia_generated_form') === 0){
3815
- $contact_form = 'contact_form_enfold_theme';
3816
- $contact_form_additional = str_replace('avia_generated_form', '', $param);
3817
- }
3818
- if(!empty($contact_form))
3819
- break;
3820
- }
3821
-
3822
- $ajax_call = false;
3823
- if ((defined( 'DOING_AJAX' ) && DOING_AJAX)
3824
- ) {
3825
- $ajax_call = true;
3826
- }
3827
- if ($ajax_call) {
3828
- echo $ct_result->comment;
3829
- } else {
3830
-
3831
- global $ct_comment;
3832
- $ct_comment = $ct_result->comment;
3833
- if(isset($_POST['cma-action'])&&$_POST['cma-action']=='add'){
3834
- $result=Array('success'=>0, 'thread_id'=>null,'messages'=>Array($ct_result->comment));
3835
- header("Content-Type: application/json");
3836
- print json_encode($result);
3837
- die();
3838
-
3839
- }else if(isset($_POST['TellAFriend_email'])){
3840
- echo $ct_result->comment;
3841
- die();
3842
-
3843
- }else if(isset($_POST['gform_submit'])){ // Gravity forms submission
3844
- $response = sprintf("<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'><div id='gform_confirmation_wrapper_1' class='gform_confirmation_wrapper '><div id='gform_confirmation_message_1' class='gform_confirmation_message_1
3845
- gform_confirmation_message'>%s</div></div></body></html>",
3846
- $ct_result->comment
3847
- );
3848
- echo $response;
3849
- die();
3850
-
3851
- }elseif(isset($_POST['action']) && $_POST['action'] == 'ct_check_internal'){
3852
- return $ct_result->comment;
3853
-
3854
- }elseif(isset($_POST['vfb-submit']) && defined('VFB_VERSION')){
3855
- wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
3856
- // Caldera Contact Forms
3857
- }elseif(isset($_POST['action']) && $_POST['action'] == 'cf_process_ajax_submit'){
3858
- print "<h3 style='color: red;'><red>".$ct_result->comment."</red></h3>";
3859
- die();
3860
- // Mailster
3861
- }elseif(isset($_POST['_referer'], $_POST['formid'], $_POST['email'])){
3862
- $return = array(
3863
- 'success' => false,
3864
- 'html' => '<p>' . $ct_result->comment . '</p>',
3865
- );
3866
- print json_encode($return);
3867
- die();
3868
- // Divi Theme Contact Form. Using $contact_form
3869
- }elseif(!empty($contact_form) && $contact_form == 'contact_form_divi_theme'){
3870
- echo "<div id='et_pb_contact_form{$contact_form_additional}'><h1>Your request looks like spam.</h1><div><p>{$ct_result->comment}</p></div></div>";
3871
- die();
3872
- // Enfold Theme Contact Form. Using $contact_form
3873
- }elseif(!empty($contact_form) && $contact_form == 'contact_form_enfold_theme'){
3874
- echo "<div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1' style='display: block;'><div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1'><h3 class='avia-form-success'>Antispam by CleanTalk: ".$ct_result->comment."</h3><a href='.'><-Back</a></div></div>";
3875
- die();
3876
- }else{
3877
- ct_die(null, null);
3878
- }
3879
- }
3880
- exit;
3881
- }
3882
-
3883
- return null;
3884
- }
3885
-
3886
- /**
3887
- * General test for any post data
3888
- */
3889
- function ct_contact_form_validate_postdata() {
3890
-
3891
- global $apbct, $pagenow,$cleantalk_executed;
3892
-
3893
- // Exclusios common function
3894
- if ( apbct_exclusions_check(__FUNCTION__) ) {
3895
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3896
- return null;
3897
- }
3898
-
3899
- if (@sizeof($_POST)==0 ||
3900
- (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
3901
- (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
3902
- (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action']=='lostpassword') ||
3903
- apbct_is_in_uri('/checkout/') ||
3904
- /* WooCommerce Service Requests - skip them */
3905
- isset($_GET['wc-ajax']) && (
3906
- $_GET['wc-ajax']=='checkout' ||
3907
- $_GET['wc-ajax']=='get_refreshed_fragments' ||
3908
- $_GET['wc-ajax']=='apply_coupon' ||
3909
- $_GET['wc-ajax']=='remove_coupon' ||
3910
- $_GET['wc-ajax']=='update_shipping_method' ||
3911
- $_GET['wc-ajax']=='get_cart_totals' ||
3912
- $_GET['wc-ajax']=='update_order_review' ||
3913
- $_GET['wc-ajax']=='add_to_cart' ||
3914
- $_GET['wc-ajax']=='remove_from_cart' ||
3915
- $_GET['wc-ajax']=='get_variation' ||
3916
- $_GET['wc-ajax']=='get_customer_location'
3917
- ) ||
3918
- /* END: WooCommerce Service Requests */
3919
- apbct_is_in_uri('/wp-admin/') ||
3920
- apbct_is_in_uri('wp-login.php') ||
3921
- apbct_is_in_uri('wp-comments-post.php') ||
3922
- apbct_is_in_referer('/wp-admin/') ||
3923
- apbct_is_in_uri('/login/') ||
3924
- apbct_is_in_uri('?provider=facebook&') ||
3925
- isset($_GET['ptype']) && $_GET['ptype']=='login' ||
3926
- isset($_POST['ct_checkjs_register_form']) ||
3927
- (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit']) ) ||
3928
- $apbct->settings['forms__general_contact_forms_test']==0 ||
3929
- isset($_POST['bbp_topic_content']) ||
3930
- isset($_POST['bbp_reply_content']) ||
3931
- isset($_POST['fscf_submitted']) ||
3932
- isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit'])||
3933
- apbct_is_in_uri('/wc-api') ||
3934
- apbct_is_in_uri( 'wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
3935
- (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || //WooCommerce recovery password form
3936
- (isset($_POST['woocommerce-login-nonce'], $_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || //WooCommerce login form
3937
- (isset($_POST['provider'], $_POST['authcode']) && $_POST['provider'] == 'Two_Factor_Totp') || //TwoFactor authorization
3938
- (isset($_GET['wc-ajax']) && $_GET['wc-ajax'] == 'sa_wc_buy_now_get_ajax_buy_now_button') || //BuyNow add to cart
3939
- apbct_is_in_uri('/wp-json/wpstatistics/v1/hit') || //WPStatistics
3940
- (isset($_POST['ihcaction']) && $_POST['ihcaction'] == 'login') || //Skip login form
3941
- (isset($_POST['action']) && $_POST['action'] == 'infinite_scroll') || //Scroll
3942
- isset($_POST['gform_submit']) || //Skip gravity checking because of direct integration
3943
- (isset($_POST['lrm_action']) && $_POST['lrm_action'] == 'login') || //Skip login form
3944
- apbct_is_in_uri( 'xmlrpc.php?for=jetpack' ) ||
3945
- apbct_is_in_uri( 'connector=bridge&task=put_sql' )
3946
- ) {
3947
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3948
- return null;
3949
- }
3950
-
3951
- $message = ct_get_fields_any_postdata($_POST);
3952
-
3953
- // ???
3954
- if(strlen(json_encode($message))<10) {
3955
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3956
- return null;
3957
- }
3958
-
3959
-
3960
- // Skip if request contains params
3961
- $skip_params = array(
3962
- 'ipn_track_id', // PayPal IPN #
3963
- 'txn_type', // PayPal transaction type
3964
- 'payment_status', // PayPal payment status
3965
- );
3966
- foreach($skip_params as $key=>$value){
3967
- if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST)) {
3968
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
3969
- return null;
3970
- }
3971
- }
3972
-
3973
- $base_call_result = apbct_base_call(
3974
- array(
3975
- 'message' => $message,
3976
- 'post_info' => array('comment_type' => 'feedback_general_postdata'),
3977
- )
3978
- );
3979
-
3980
- $cleantalk_executed=true;
3981
-
3982
- $ct_result = $base_call_result['ct_result'];
3983
-
3984
- if ($ct_result->allow == 0) {
3985
-
3986
- if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
3987
- global $ct_comment;
3988
- $ct_comment = $ct_result->comment;
3989
- if(isset($_POST['cma-action'])&&$_POST['cma-action']=='add')
3990
- {
3991
- $result=Array('success'=>0, 'thread_id'=>null,'messages'=>Array($ct_result->comment));
3992
- header("Content-Type: application/json");
3993
- print json_encode($result);
3994
- die();
3995
- }
3996
- else
3997
- {
3998
- ct_die(null, null);
3999
- }
4000
- } else {
4001
- echo $ct_result->comment;
4002
- }
4003
- exit;
4004
- }
4005
-
4006
- return null;
4007
- }
4008
-
4009
-
4010
- /**
4011
- * Inner function - Finds and returns pattern in string
4012
- * @return null|bool
4013
- */
4014
- function ct_get_data_from_submit($value = null, $field_name = null) {
4015
- if (!$value || !$field_name || !is_string($value)) {
4016
- return false;
4017
- }
4018
- if (preg_match("/[a-z0-9_\-]*" . $field_name. "[a-z0-9_\-]*$/", $value)) {
4019
- return true;
4020
- }
4021
- }
4022
-
4023
- /**
4024
- * Sends error notice to admin
4025
- * @return null
4026
- */
4027
- function ct_send_error_notice ($comment = '') {
4028
- global $ct_admin_notoice_period, $apbct;
4029
-
4030
- $timelabel_reg = intval( get_option('cleantalk_timelabel_reg') );
4031
- if(time() - $ct_admin_notoice_period > $timelabel_reg){
4032
- update_option('cleantalk_timelabel_reg', time());
4033
-
4034
- $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
4035
- $message = __('Attention, please!', 'cleantalk-spam-protect') . "\r\n\r\n";
4036
- $message .= sprintf(__('"%s" plugin error on your site "%s":', 'cleantalk-spam-protect'), $apbct->plugin_name, $blogname) . "\r\n\r\n";
4037
- $message .= preg_replace('/^(.*?)<a.*?"(.*?)".*?>(.*?)<.a>(.*)$/', '$1. $3: $2?user_token='. $apbct->user_token .' $4', $comment) . "\r\n\r\n";
4038
- @wp_mail(ct_get_admin_email(), sprintf(__('[%s] "%s" error!', 'cleantalk-spam-protect'), $apbct->plugin_name, $blogname), $message);
4039
- }
4040
-
4041
- return null;
4042
- }
4043
-
4044
- /**
4045
- * Prints form for "protect externals
4046
- *
4047
- * @param $arr
4048
- * @param $k
4049
- */
4050
- function ct_print_form( $arr, $k ){
4051
-
4052
- // Fix for pages04.net forms
4053
- if( isset( $arr['formSourceName'] ) ){
4054
- $tmp = array();
4055
- foreach( $arr as $key => $val ){
4056
- $tmp_key = str_replace( '_', '+', $key );
4057
- $tmp[$tmp_key] = $val;
4058
- }
4059
- $arr = $tmp;
4060
- unset( $tmp, $key, $tmp_key, $val );
4061
- }
4062
-
4063
- foreach( $arr as $key => $value ){
4064
-
4065
- if( ! is_array( $value ) ){
4066
- print '<textarea
4067
- name="' . ( $k == '' ? $key : $k . '[' . $key . ']' ) . '"
4068
- style="display:none;">' . htmlspecialchars( $value )
4069
- . '</textarea>';
4070
- }else{
4071
- ct_print_form( $value, $k == '' ? $key : $k . '[' . $key . ']' );
4072
- }
4073
-
4074
- }
4075
-
4076
- }
4077
-
4078
- /**
4079
- * Attaches public scripts and styles.
4080
- */
4081
- function ct_enqueue_scripts_public($hook){
4082
-
4083
- global $current_user, $apbct;
4084
-
4085
- if (apbct_exclusions_check__url()) {
4086
- return;
4087
- }
4088
-
4089
- if(
4090
- $apbct->settings['forms__registrations_test'] ||
4091
- $apbct->settings['forms__comments_test'] ||
4092
- $apbct->settings['forms__contact_forms_test'] ||
4093
- $apbct->settings['forms__general_contact_forms_test'] ||
4094
- $apbct->settings['forms__wc_checkout_test'] ||
4095
- $apbct->settings['forms__check_external'] ||
4096
- $apbct->settings['forms__check_internal'] ||
4097
- $apbct->settings['comments__bp_private_messages'] ||
4098
- $apbct->settings['data__general_postdata_test']
4099
- ){
4100
-
4101
- if( ! $apbct->public_script_loaded ) {
4102
-
4103
- // Differnt JS params
4104
- wp_enqueue_script( 'ct_public', APBCT_URL_PATH . '/js/apbct-public.min.js?apbct_ver=' . APBCT_VERSION, array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
4105
- wp_enqueue_script('cleantalk-modal', plugins_url( '/cleantalk-spam-protect/js/cleantalk-modal.min.js' ), array(), APBCT_VERSION, false );
4106
 
4107
  wp_localize_script('ct_public', 'ctPublic', array(
4108
  '_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
@@ -4119,7 +1087,7 @@ function ct_enqueue_scripts_public($hook){
4119
  'data__email_check_before_post' =>$apbct->settings['data__email_check_before_post'],
4120
  ));
4121
  }
4122
-
4123
  // ct_nocache
4124
  // @todo needs to be refactored
4125
  if(
@@ -4129,7 +1097,7 @@ function ct_enqueue_scripts_public($hook){
4129
  ! apbct_is_in_uri( '.xsl' ) &&
4130
  ! apbct_is_in_uri( 'jm-ajax' )
4131
  ){
4132
-
4133
  // Collect details about browsers
4134
  if($apbct->settings['misc__collect_details']){
4135
  wp_enqueue_script('ct_collect_details', plugins_url('/cleantalk-spam-protect/js/cleantalk_collect_details.min.js'), array(), APBCT_VERSION, false /*in header*/);
@@ -4137,7 +1105,7 @@ function ct_enqueue_scripts_public($hook){
4137
  'set_cookies_flag' => $apbct->settings['data__set_cookies'] ? false : true,
4138
  ));
4139
  }
4140
-
4141
  wp_enqueue_script('ct_nocache', plugins_url('/cleantalk-spam-protect/js/cleantalk_nocache.min.js'), array(), APBCT_VERSION, false /*in header*/);
4142
  wp_localize_script('ct_nocache', 'ctNocache', array(
4143
  'ajaxurl' => admin_url('admin-ajax.php', 'relative'),
@@ -4146,7 +1114,7 @@ function ct_enqueue_scripts_public($hook){
4146
  'blog_home' => get_home_url().'/',
4147
  ));
4148
  }
4149
-
4150
  // GDPR script
4151
  if($apbct->settings['gdpr__enabled']){
4152
 
@@ -4159,12 +1127,12 @@ function ct_enqueue_scripts_public($hook){
4159
  }
4160
 
4161
  }
4162
-
4163
  // External forms check
4164
  if($apbct->settings['forms__check_external']){
4165
  wp_enqueue_script( 'ct_external', plugins_url( '/cleantalk-spam-protect/js/cleantalk_external.min.js' ), array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
4166
  }
4167
-
4168
  // Internal forms check
4169
  if($apbct->settings['forms__check_internal']){
4170
  wp_enqueue_script( 'ct_internal', plugins_url( '/cleantalk-spam-protect/js/cleantalk_internal.min.js' ), array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
@@ -4208,7 +1176,7 @@ function ct_enqueue_scripts_public($hook){
4208
  function ct_wp_list_comments_args($options){
4209
 
4210
  global $current_user, $apbct;
4211
-
4212
  if(in_array("administrator", $current_user->roles)){
4213
  if($apbct->settings['comments__manage_comments_on_public_page']) {
4214
  $theme = wp_get_theme();
@@ -4216,7 +1184,7 @@ function ct_wp_list_comments_args($options){
4216
  $options['end-callback'] = 'ct_comments_output';
4217
  }
4218
  }
4219
-
4220
  return $options;
4221
  }
4222
 
@@ -4224,9 +1192,9 @@ function ct_wp_list_comments_args($options){
4224
  * Callback function for the bootom comment output.
4225
  */
4226
  function ct_comments_output($curr_comment, $param2, $wp_list_comments_args){
4227
-
4228
  global $apbct;
4229
-
4230
  $email = $curr_comment->comment_author_email;
4231
  $ip = $curr_comment->comment_author_IP;
4232
  $id = $curr_comment->comment_ID;
@@ -4270,13 +1238,13 @@ function ct_comments_output($curr_comment, $param2, $wp_list_comments_args){
4270
  echo "</p>";
4271
 
4272
  echo "</div>";
4273
-
4274
  // @todo research what such themes and make exception for them
4275
  $ending_tag = isset( $wp_list_comments_args['style'] ) ? $wp_list_comments_args['style'] : null ;
4276
  if( in_array( $apbct->active_theme, array( 'Paperio', 'Twenty Twenty' ) ) ){
4277
  $ending_tag = is_null($wp_list_comments_args['style']) ? 'div' : $wp_list_comments_args['style'];
4278
  };
4279
-
4280
  // Ending comment output
4281
  echo "</{$ending_tag}>";
4282
  }
@@ -4299,113 +1267,3 @@ function apbct_shrotcode_handler__GDPR_public_notice__form( $attrs ){
4299
  $out = '<script ' . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . '>'.$out.'</script>';
4300
  return $out;
4301
  }
4302
-
4303
- /**
4304
- * Filters the 'status' array before register the user
4305
- * using only by WICITY theme
4306
- *
4307
- * @param $success array array( 'status' => 'success' )
4308
- * @param $data array ['username'] ['password'] ['email']
4309
- * @return array array( 'status' => 'error' ) or array( 'status' => 'success' ) by default
4310
- */
4311
- function apbct_wilcity_reg_validation( $success, $data ) {
4312
- $check = ct_test_registration( $data['username'], $data['email'], '' );
4313
- if( $check['allow'] == 0 ) {
4314
- return array( 'status' => 'error' );
4315
- }
4316
- return $success;
4317
- }
4318
-
4319
- // Enfold Theme contact form
4320
- function apbct_form__enfold_contact_form__test_spam( $send, $new_post, $form_params, $obj ){
4321
-
4322
- global $cleantalk_executed;
4323
-
4324
- $url_decoded_data = array();
4325
- foreach( $new_post as $key => $value ) {
4326
- $url_decoded_data[$key] = urldecode($value);
4327
- }
4328
-
4329
- $data = ct_get_fields_any( $url_decoded_data );
4330
-
4331
- $base_call_result = apbct_base_call(
4332
- array(
4333
- 'message' => !empty( $data['message'] ) ? json_encode( $data['message'] ) : '',
4334
- 'sender_email' => !empty( $data['email'] ) ? $data['email'] : '',
4335
- 'sender_nickname' => !empty( $data['nickname'] ) ? $data['nickname'] : '',
4336
- 'post_info' => array(
4337
- 'comment_type' => 'contact_form_wordpress_enfold'
4338
- ),
4339
- )
4340
- );
4341
-
4342
- $ct_result = $base_call_result['ct_result'];
4343
-
4344
- $cleantalk_executed = true;
4345
-
4346
- if( $ct_result->allow == 0 ) {
4347
- $obj->submit_error = $ct_result->comment;
4348
- return null;
4349
- }
4350
-
4351
- return $send;
4352
-
4353
- }
4354
-
4355
- // Profile Builder integration
4356
- function apbct_form_profile_builder__check_register ( $errors, $fields, $global_request ){
4357
-
4358
- if( isset( $global_request['action'] ) && $global_request['action'] == 'register' ) {
4359
-
4360
- global $cleantalk_executed;
4361
-
4362
- $data = ct_get_fields_any( $global_request );
4363
-
4364
- $base_call_result = apbct_base_call(
4365
- array(
4366
- 'message' => !empty( $data['message'] ) ? json_encode( $data['message'] ) : '',
4367
- 'sender_email' => !empty( $data['email'] ) ? $data['email'] : '',
4368
- 'sender_nickname' => !empty( $data['nickname'] ) ? $data['nickname'] : '',
4369
- 'post_info' => array(
4370
- 'comment_type' => 'register_profile_builder'
4371
- ),
4372
- ), true
4373
- );
4374
-
4375
- $ct_result = $base_call_result['ct_result'];
4376
-
4377
- $cleantalk_executed = true;
4378
-
4379
- if( $ct_result->allow == 0 ) {
4380
- $errors['error'] = $ct_result->comment;
4381
- $GLOBALS['global_profile_builder_error'] = $ct_result->comment;
4382
-
4383
- add_filter( 'wppb_general_top_error_message', 'apbct_form_profile_builder__error_message', 1 );
4384
- }
4385
-
4386
- }
4387
- return $errors;
4388
-
4389
- }
4390
-
4391
- /**
4392
- * Profile Builder Integration - add error message in response
4393
- */
4394
- function apbct_form_profile_builder__error_message() {
4395
- return '<p id="wppb_form_general_message" class="wppb-error">'. $GLOBALS['global_profile_builder_error'] .'</p>';
4396
- }
4397
-
4398
- // WP Foro register system integration
4399
- function wpforo_create_profile__check_register( $user_fields ) {
4400
-
4401
- global $ct_signup_done;
4402
-
4403
- $ip = Helper::ip__get( 'real', false );
4404
- $check = ct_test_registration( $user_fields['user_login'], $user_fields['user_email'], $ip );
4405
- if( $check['allow'] == 0 ) {
4406
- return array( 'error' => $check['comment'] );
4407
- }
4408
-
4409
- $ct_signup_done = true;
4410
- return $user_fields;
4411
- }
1
  <?php
2
 
 
3
  use Cleantalk\Variables\Server;
4
 
5
  /**
8
  */
9
  function apbct_init() {
10
 
11
+ global $ct_jp_comments, $apbct;
12
+
13
  // Pixel
14
  if( $apbct->settings['data__pixel'] ){
15
+
16
  $pixel_hash = md5(
17
  \Cleantalk\Common\Helper::ip__get()
18
  . $apbct->api_key
19
  . \Cleantalk\Common\Helper::time__get_interval_start( 3600 * 3 ) // Unique for every 3 hours
20
  );
21
+
22
  // Change server each 3 hours depending on current time interval
23
  $servers = array_keys( \Cleantalk\Common\Helper::$cleantalks_moderate_servers );
24
  $server_num = \Cleantalk\Common\Helper::time__get_interval_start( 3600 * 3 ) % count($servers);
25
  $pixel_server = $servers[ $server_num ];
26
+
27
  $apbct->pixel_url = 'https://' . $pixel_server . '/pixel/' . $pixel_hash . '.gif';
28
+
29
  }
30
+
31
  //Check internal forms with such "action" http://wordpress.loc/contact-us/some_script.php
32
  if((isset($_POST['action']) && $_POST['action'] == 'ct_check_internal') &&
33
  $apbct->settings['forms__check_internal']
57
 
58
  // Fixing form and directs it this site
59
  if($apbct->settings['forms__check_external__capture_buffer'] && !is_admin() && !apbct_is_ajax() && !apbct_is_post() && apbct_is_user_enable() && !(defined('DOING_CRON') && DOING_CRON) && !(defined('XMLRPC_REQUEST') && XMLRPC_REQUEST)){
60
+
61
  if (defined('CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL') && is_string(CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL)) {
62
  $catch_buffer = false;
63
  $urls = explode(',', CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL);
68
  }else{
69
  $catch_buffer = true;
70
  }
71
+
72
  if( $catch_buffer ){
73
  add_action('wp', 'apbct_buffer__start');
74
  add_action('shutdown', 'apbct_buffer__end', 0);
126
  unset($_POST['ct_checkjs_register_form']);
127
  ct_contact_form_validate();
128
  }
 
 
 
 
 
 
 
129
  }
130
 
131
  if($apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7']))
134
  //add_action('wp_footer','ct_ajaxurl');
135
 
136
  // Fast Secure contact form
137
+ if(defined('FSCF_VERSION')){
138
+ add_filter('si_contact_display_after_fields', 'ct_si_contact_display_after_fields');
139
+ add_filter('si_contact_form_validate', 'ct_si_contact_form_validate');
140
+ }
141
 
142
  // WooCommerce registration
143
  if(class_exists('WooCommerce')){
159
 
160
 
161
  // JetPack Contact form
 
162
  if(defined('JETPACK__VERSION'))
163
  {
164
  // Checking Jetpack contact form
190
  }
191
 
192
  // WP Maintenance Mode (wpmm)
193
+ add_action('wpmm_head', 'apbct_form__wpmm__addField', 1);
194
 
195
  // Contact Form7
196
+ if(defined('WPCF7_VERSION')){
197
+ add_filter('wpcf7_form_elements', 'apbct_form__contactForm7__addField');
198
+ add_filter('wpcf7_validate', 'apbct_form__contactForm7__tesSpam__before_validate', 999, 2);
199
+ $hook = WPCF7_VERSION >= '3.0.0' ? 'wpcf7_spam' : 'wpcf7_acceptance';
200
+ $num_arg = WPCF7_VERSION >= '5.3.0' ? 2 : 1;
201
+ add_filter( $hook, 'apbct_form__contactForm7__testSpam', 9999, $num_arg );
202
+ }
203
 
204
  // Formidable
205
+ add_filter( 'frm_entries_before_create', 'apbct_form__formidable__testSpam', 10, 2 );
206
+ add_action( 'frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2 );
207
 
208
  // BuddyPress
209
+ if(class_exists('BuddyPress')){
210
+ add_action('bp_before_registration_submit_buttons','ct_register_form',1);
211
+ add_action('messages_message_before_save', 'apbct_integration__buddyPres__private_msg_check', 1);
212
+ add_filter('bp_signup_validate', 'ct_registration_errors',1);
213
+ add_filter('bp_signup_validate', 'ct_check_registration_erros', 999999);
214
+ }
215
 
216
  if(defined('PROFILEPRESS_SYSTEM_FILE_PATH')){
217
  add_filter('pp_registration_validation', 'ct_registration_errors_ppress', 11, 2);
219
 
220
 
221
  // bbPress
222
+ if(class_exists('bbPress')){
223
+ add_filter('bbp_new_topic_pre_title', 'ct_bbp_get_topic', 1);
224
+ add_filter('bbp_new_topic_pre_content', 'ct_bbp_new_pre_content', 1);
225
+ add_filter('bbp_new_reply_pre_content', 'ct_bbp_new_pre_content', 1);
226
+ add_action('bbp_theme_before_topic_form_content', 'ct_comment_form');
227
+ add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
228
+ }
229
 
230
  //Custom Contact Forms
231
+ if(defined('CCF_VERSION'))
232
+ add_filter('ccf_field_validator', 'ct_ccf', 1, 4);
233
 
234
  add_action('comment_form', 'ct_comment_form');
235
 
243
  }
244
 
245
  // S2member. intercept POST
246
+ if (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION')){
247
+ $post_keys = array_keys($_POST);
248
+ foreach($post_keys as $post_key){
249
+
250
+ // Detect POST keys like /s2member_pro.*registration/
251
+ if(strpos($post_key, 's2member') !== false && strpos($post_key, 'registration') !== false){
252
+ ct_s2member_registration_test($post_key);
253
+ break;
 
254
  }
255
  }
256
+ }
257
 
258
  // New user approve hack
259
  // https://wordpress.org/plugins/new-user-approve/
264
  // Wilcity theme registration validation fix
265
  add_filter( 'wilcity/filter/wiloke-listing-tools/validate-before-insert-account', 'apbct_wilcity_reg_validation', 10, 2 );
266
 
 
267
  // Gravity forms
268
+ if (defined('GF_MIN_WP_VERSION')) {
269
+ add_filter('gform_get_form_filter', 'apbct_form__gravityForms__addField', 10, 2);
270
+ add_filter('gform_entry_is_spam', 'apbct_form__gravityForms__testSpam', 999, 3);
271
+ add_filter('gform_confirmation', 'apbct_form__gravityForms__showResponse', 999, 4 );
272
+ }
273
 
274
  //Pirate forms
275
+ if(defined('PIRATE_FORMS_VERSION')){
276
+ if(isset($_POST['pirate-forms-contact-name']) && $_POST['pirate-forms-contact-name'] && isset($_POST['pirate-forms-contact-email']) && $_POST['pirate-forms-contact-email'])
277
+ apbct_form__piratesForm__testSpam();
278
+ }
279
 
280
  // WPForms
281
+ // Adding fields
282
+ add_action('wpforms_frontend_output', 'apbct_form__WPForms__addField', 1000, 5);
283
+ // Gathering data to validate
284
+ add_filter('wpforms_process_before_filter', 'apbct_from__WPForms__gatherData', 100, 2);
285
+ // Do spam check
286
+ add_filter('wpforms_process_initial_errors', 'apbct_form__WPForms__showResponse', 100, 2);
287
 
288
  // QForms integration
289
  add_filter( 'quform_post_validate', 'ct_quform_post_validate', 10, 2 );
325
  ct_contact_form_validate();
326
  }
327
 
328
+ if ( apbct_is_user_enable() ) {
329
 
330
  if ($apbct->settings['forms__general_contact_forms_test'] == 1 && !isset($_POST['comment_post_ID']) && !isset($_GET['for'])){
331
  add_action( 'init', 'ct_contact_form_validate', 999 );
457
  }
458
 
459
  } unset($form);
460
+
461
  $html = $dom->getElementsByTagName('html');
462
 
463
  return is_object( $html ) && isset( $html[0], $html[0]->childNodes, $html[0]->childNodes[0] ) && $dom->getElementsByTagName( 'rss' )->length == 0
466
 
467
  }
468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
469
  /**
470
  * Adds cookie script filed to head
471
  */
490
  ){
491
  echo '<img style="display: none; left: 99999px;" src="' . $apbct->pixel_url . '">';
492
  }
493
+
494
  if( $apbct->settings['data__use_ajax'] ){
495
 
496
  $timeout = $apbct->settings['misc__async_js'] ? 1000 : 0;
558
  if($no_print)
559
  return;
560
 
 
561
  $field_id = $field_name . '_' . $field_id_hash;
562
  $html = "<input type=\"hidden\" id=\"{$field_id}\" name=\"{$field_name}\" value=\"{$ct_checkjs_def}\" />";
563
 
592
  }
593
 
594
  /**
595
+ * Changes whether notify admin/athor or not.
596
+ *
597
+ * @param bool $maybe_notify notify flag
598
+ * @param int $comment_ID Comment id
599
+ * @return bool flag
600
+ */
601
+ function apbct_comment__Wordpress__doNotify($maybe_notify, $comment_ID){
602
+ return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
  }
604
 
605
  /**
606
+ * Add notification setting link
607
+ *
608
+ * @param string $notify_message
609
+ * @param integer $comment_id
610
  *
611
+ * @return string
612
  */
613
+ function apbct_comment__Wordpress__changeMailNotificationGroups($notify_message, $comment_id){
614
+ return $notify_message
615
+ .PHP_EOL
616
+ .'---'.PHP_EOL
617
+ .'Manage notifications settings: '.get_site_url().'/wp-admin/options-general.php?page=cleantalk';
618
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
619
 
620
  /**
621
  * Change email notification recipients
765
  $back_link = '<a href="' . $_SERVER['HTTP_REFERER'] . '">' . __('Back') . '</a>';
766
  }
767
 
 
768
  if(file_exists(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html")){
769
 
770
  $ct_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html");
801
  function apbct_js_test($field_name = 'ct_checkjs', $data = null, $is_cookie = false ) {
802
 
803
  global $apbct;
804
+
805
  $out = null;
806
 
807
  if(
808
  ($data && isset($data[$field_name])) ||
809
  ($is_cookie && $apbct->settings['data__set_cookies'] == 2 && \Cleantalk\ApbctWP\Variables\Cookie::get( $field_name ))
810
  ){
811
+
812
  $js_key = $is_cookie && $apbct->settings['data__set_cookies'] == 2
813
  ? \Cleantalk\ApbctWP\Variables\Cookie::get( $field_name )
814
  : trim($data[$field_name]);
948
  return false;
949
  }
950
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
 
 
 
952
 
953
  function apbct_login__scripts(){
954
  global $apbct;
976
  }
977
 
978
  /**
979
+ * Inner function - Finds and returns pattern in string
980
+ * @return null|bool
981
  */
982
+ function ct_get_data_from_submit($value = null, $field_name = null) {
983
+ if (!$value || !$field_name || !is_string($value)) {
984
+ return false;
985
+ }
986
+ if (preg_match("/[a-z0-9_\-]*" . $field_name. "[a-z0-9_\-]*$/", $value)) {
987
+ return true;
 
 
 
 
 
 
988
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
989
  }
990
 
991
  /**
992
+ * Sends error notice to admin
993
+ * @return null
994
  */
995
+ function ct_send_error_notice ($comment = '') {
996
+ global $ct_admin_notoice_period, $apbct;
997
 
998
+ $timelabel_reg = intval( get_option('cleantalk_timelabel_reg') );
999
+ if(time() - $ct_admin_notoice_period > $timelabel_reg){
1000
+ update_option('cleantalk_timelabel_reg', time());
 
 
 
 
 
 
 
 
 
 
1001
 
1002
+ $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1003
+ $message = __('Attention, please!', 'cleantalk-spam-protect') . "\r\n\r\n";
1004
+ $message .= sprintf(__('"%s" plugin error on your site "%s":', 'cleantalk-spam-protect'), $apbct->plugin_name, $blogname) . "\r\n\r\n";
1005
+ $message .= preg_replace('/^(.*?)<a.*?"(.*?)".*?>(.*?)<.a>(.*)$/', '$1. $3: $2?user_token='. $apbct->user_token .' $4', $comment) . "\r\n\r\n";
1006
+ @wp_mail(ct_get_admin_email(), sprintf(__('[%s] "%s" error!', 'cleantalk-spam-protect'), $apbct->plugin_name, $blogname), $message);
1007
  }
1008
 
1009
+ return null;
 
 
 
 
 
 
 
 
1010
  }
1011
 
1012
  /**
1013
+ * Prints form for "protect externals
 
 
 
 
1014
  *
1015
+ * @param $arr
1016
+ * @param $k
1017
  */
1018
+ function ct_print_form( $arr, $k ){
 
 
1019
 
1020
+ // Fix for pages04.net forms
1021
+ if( isset( $arr['formSourceName'] ) ){
1022
+ $tmp = array();
1023
+ foreach( $arr as $key => $val ){
1024
+ $tmp_key = str_replace( '_', '+', $key );
1025
+ $tmp[$tmp_key] = $val;
1026
+ }
1027
+ $arr = $tmp;
1028
+ unset( $tmp, $key, $tmp_key, $val );
1029
+ }
1030
 
1031
+ foreach( $arr as $key => $value ){
1032
 
1033
+ if( ! is_array( $value ) ){
1034
+ print '<textarea
1035
+ name="' . ( $k == '' ? $key : $k . '[' . $key . ']' ) . '"
1036
+ style="display:none;">' . htmlspecialchars( $value )
1037
+ . '</textarea>';
1038
+ }else{
1039
+ ct_print_form( $value, $k == '' ? $key : $k . '[' . $key . ']' );
1040
+ }
 
1041
 
1042
+ }
1043
 
 
 
 
 
 
1044
  }
1045
 
1046
  /**
1047
+ * Attaches public scripts and styles.
 
1048
  */
1049
+ function ct_enqueue_scripts_public($hook){
1050
 
1051
+ global $current_user, $apbct;
1052
 
1053
+ if (apbct_exclusions_check__url()) {
1054
+ return;
 
 
 
 
1055
  }
1056
 
1057
+ if(
1058
+ $apbct->settings['forms__registrations_test'] ||
1059
+ $apbct->settings['forms__comments_test'] ||
1060
+ $apbct->settings['forms__contact_forms_test'] ||
1061
+ $apbct->settings['forms__general_contact_forms_test'] ||
1062
+ $apbct->settings['forms__wc_checkout_test'] ||
1063
+ $apbct->settings['forms__check_external'] ||
1064
+ $apbct->settings['forms__check_internal'] ||
1065
+ $apbct->settings['comments__bp_private_messages'] ||
1066
+ $apbct->settings['data__general_postdata_test']
1067
+ ){
 
 
 
 
 
 
 
 
1068
 
1069
+ if( ! $apbct->public_script_loaded ) {
 
 
 
 
 
 
 
 
 
1070
 
1071
+ // Differnt JS params
1072
+ wp_enqueue_script( 'ct_public', APBCT_URL_PATH . '/js/apbct-public.min.js?apbct_ver=' . APBCT_VERSION, array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
1073
+ wp_enqueue_script('cleantalk-modal', plugins_url( '/cleantalk-spam-protect/js/cleantalk-modal.min.js' ), array(), APBCT_VERSION, false );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1074
 
1075
  wp_localize_script('ct_public', 'ctPublic', array(
1076
  '_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
1087
  'data__email_check_before_post' =>$apbct->settings['data__email_check_before_post'],
1088
  ));
1089
  }
1090
+
1091
  // ct_nocache
1092
  // @todo needs to be refactored
1093
  if(
1097
  ! apbct_is_in_uri( '.xsl' ) &&
1098
  ! apbct_is_in_uri( 'jm-ajax' )
1099
  ){
1100
+
1101
  // Collect details about browsers
1102
  if($apbct->settings['misc__collect_details']){
1103
  wp_enqueue_script('ct_collect_details', plugins_url('/cleantalk-spam-protect/js/cleantalk_collect_details.min.js'), array(), APBCT_VERSION, false /*in header*/);
1105
  'set_cookies_flag' => $apbct->settings['data__set_cookies'] ? false : true,
1106
  ));
1107
  }
1108
+
1109
  wp_enqueue_script('ct_nocache', plugins_url('/cleantalk-spam-protect/js/cleantalk_nocache.min.js'), array(), APBCT_VERSION, false /*in header*/);
1110
  wp_localize_script('ct_nocache', 'ctNocache', array(
1111
  'ajaxurl' => admin_url('admin-ajax.php', 'relative'),
1114
  'blog_home' => get_home_url().'/',
1115
  ));
1116
  }
1117
+
1118
  // GDPR script
1119
  if($apbct->settings['gdpr__enabled']){
1120
 
1127
  }
1128
 
1129
  }
1130
+
1131
  // External forms check
1132
  if($apbct->settings['forms__check_external']){
1133
  wp_enqueue_script( 'ct_external', plugins_url( '/cleantalk-spam-protect/js/cleantalk_external.min.js' ), array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
1134
  }
1135
+
1136
  // Internal forms check
1137
  if($apbct->settings['forms__check_internal']){
1138
  wp_enqueue_script( 'ct_internal', plugins_url( '/cleantalk-spam-protect/js/cleantalk_internal.min.js' ), array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
1176
  function ct_wp_list_comments_args($options){
1177
 
1178
  global $current_user, $apbct;
1179
+
1180
  if(in_array("administrator", $current_user->roles)){
1181
  if($apbct->settings['comments__manage_comments_on_public_page']) {
1182
  $theme = wp_get_theme();
1184
  $options['end-callback'] = 'ct_comments_output';
1185
  }
1186
  }
1187
+
1188
  return $options;
1189
  }
1190
 
1192
  * Callback function for the bootom comment output.
1193
  */
1194
  function ct_comments_output($curr_comment, $param2, $wp_list_comments_args){
1195
+
1196
  global $apbct;
1197
+
1198
  $email = $curr_comment->comment_author_email;
1199
  $ip = $curr_comment->comment_author_IP;
1200
  $id = $curr_comment->comment_ID;
1238
  echo "</p>";
1239
 
1240
  echo "</div>";
1241
+
1242
  // @todo research what such themes and make exception for them
1243
  $ending_tag = isset( $wp_list_comments_args['style'] ) ? $wp_list_comments_args['style'] : null ;
1244
  if( in_array( $apbct->active_theme, array( 'Paperio', 'Twenty Twenty' ) ) ){
1245
  $ending_tag = is_null($wp_list_comments_args['style']) ? 'div' : $wp_list_comments_args['style'];
1246
  };
1247
+
1248
  // Ending comment output
1249
  echo "</{$ending_tag}>";
1250
  }
1267
  $out = '<script ' . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . '>'.$out.'</script>';
1268
  return $out;
1269
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/cleantalk-updater.php CHANGED
@@ -3,35 +3,49 @@
3
  use Cleantalk\ApbctWP\Cron;
4
  use Cleantalk\Common\Schema;
5
 
6
- function apbct_run_update_actions($current_version, $new_version){
 
 
 
 
 
 
 
 
 
 
7
 
8
- $current_version = apbct_version_standartization($current_version);
9
- $new_version = apbct_version_standartization($new_version);
10
 
11
- $current_version_str = implode('.', $current_version);
12
- $new_version_str = implode('.', $new_version);
13
-
14
- for($ver_major = $current_version[0]; $ver_major <= $new_version[0]; $ver_major++){
15
  for($ver_minor = 0; $ver_minor <= 300; $ver_minor++){
16
  for($ver_fix = 0; $ver_fix <= 10; $ver_fix++){
17
 
18
- if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $current_version_str, '<='))
19
  continue;
 
20
 
21
  if(function_exists("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}")){
22
  $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}");
23
- if(!empty($result['error']))
24
  break;
 
25
  }
26
 
27
  if( $ver_fix == 0 && function_exists("apbct_update_to_{$ver_major}_{$ver_minor}") ){
28
  $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}");
29
- if(!empty($result['error']))
30
  break;
 
31
  }
32
 
33
- if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $new_version_str, '>='))
34
- break(2);
 
35
 
36
  }
37
  }
@@ -41,18 +55,31 @@ function apbct_run_update_actions($current_version, $new_version){
41
 
42
  }
43
 
44
- function apbct_version_standartization($version){
45
-
46
- $version = explode('.', $version);
47
- $version = !empty($version) ? $version : array();
 
 
 
 
48
 
49
- $version[0] = !empty($version[0]) ? (int)$version[0] : 0;
50
- $version[1] = !empty($version[1]) ? (int)$version[1] : 0;
51
- $version[2] = !empty($version[2]) ? (int)$version[2] : 0;
52
-
53
- return $version;
 
 
54
  }
55
 
 
 
 
 
 
 
 
56
  function apbct_get_table_columns( $table_name ) {
57
  global $wpdb;
58
  $query = 'SHOW COLUMNS FROM ' . $table_name;
@@ -64,6 +91,9 @@ function apbct_get_table_columns( $table_name ) {
64
  return $columns_names;
65
  }
66
 
 
 
 
67
  function apbct_update_to_5_50_0(){
68
  global $wpdb;
69
  $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_DATA .'` (
@@ -80,10 +110,17 @@ function apbct_update_to_5_50_0(){
80
  PRIMARY KEY (`ip`));');
81
  }
82
 
 
 
 
83
  function apbct_update_to_5_56_0(){
84
  if (!wp_next_scheduled('cleantalk_update_sfw_hook'))
85
  wp_schedule_event(time()+1800, 'daily', 'cleantalk_update_sfw_hook' );
86
  }
 
 
 
 
87
  function apbct_update_to_5_70_0(){
88
 
89
  global $wpdb;
@@ -116,11 +153,18 @@ function apbct_update_to_5_70_0(){
116
  $cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // New
117
  $cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500);
118
  }
 
 
 
 
119
  function apbct_update_to_5_74_0(){
120
  $cron = new Cron();
121
  $cron->removeTask('send_daily_request');
122
  }
123
 
 
 
 
124
  function apbct_update_to_5_97_0(){
125
 
126
  global $apbct;
@@ -131,6 +175,9 @@ function apbct_update_to_5_97_0(){
131
  $apbct->saveData();
132
  }
133
 
 
 
 
134
  function apbct_update_to_5_109_0(){
135
 
136
  global $apbct, $wpdb;
@@ -170,6 +217,9 @@ function apbct_update_to_5_109_0(){
170
  }
171
  }
172
 
 
 
 
173
  function apbct_update_to_5_110_0(){
174
  global $apbct;
175
  unset($apbct->data['last_remote_call']);
@@ -177,10 +227,16 @@ function apbct_update_to_5_110_0(){
177
  $apbct->save('remote_calls');
178
  }
179
 
 
 
 
180
  function apbct_update_to_5_115_1(){
181
  apbct_sfw_update__init();
182
  }
183
 
 
 
 
184
  function apbct_update_to_5_116_0(){
185
 
186
  global $apbct, $wpdb;
@@ -198,6 +254,9 @@ function apbct_update_to_5_116_0(){
198
  );
199
  }
200
 
 
 
 
201
  function apbct_update_to_5_116_1(){
202
 
203
  global $wpdb;
@@ -211,6 +270,9 @@ function apbct_update_to_5_116_1(){
211
  );
212
  }
213
 
 
 
 
214
  function apbct_update_to_5_116_2(){
215
 
216
  global $wpdb;
@@ -224,6 +286,9 @@ function apbct_update_to_5_116_2(){
224
  );
225
  }
226
 
 
 
 
227
  function apbct_update_to_5_118_0(){
228
  global $wpdb;
229
  $wpdb->query(
@@ -234,6 +299,9 @@ function apbct_update_to_5_118_0(){
234
  delete_option('cleantalk_server');
235
  }
236
 
 
 
 
237
  function apbct_update_to_5_118_2(){
238
  global $apbct;
239
  $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
@@ -241,12 +309,17 @@ function apbct_update_to_5_118_2(){
241
  $apbct->saveData();
242
  }
243
 
 
 
 
244
  function apbct_update_to_5_119_0(){
245
 
246
  global $wpdb;
247
 
248
  $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
249
-
 
 
250
  // SFW data
251
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
252
  `network` int(11) unsigned NOT NULL,
@@ -273,8 +346,8 @@ function apbct_update_to_5_119_0(){
273
  apbct_activation__create_tables($sqls);
274
 
275
  // WPMS
276
- if(is_multisite()){
277
- global $wpdb;
278
  $initial_blog = get_current_blog_id();
279
  $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
280
  foreach ($blogs as $blog) {
@@ -296,6 +369,9 @@ function apbct_update_to_5_119_0(){
296
  );
297
  }
298
 
 
 
 
299
  function apbct_update_to_5_124_0(){
300
  global $apbct;
301
  // Deleting error in database because format were changed
@@ -303,6 +379,9 @@ function apbct_update_to_5_124_0(){
303
  $apbct->saveErrors();
304
  }
305
 
 
 
 
306
  function apbct_update_to_5_126_0(){
307
  global $apbct;
308
  // Enable storing URLs
@@ -311,34 +390,37 @@ function apbct_update_to_5_126_0(){
311
  $apbct->saveSettings();
312
  }
313
 
 
 
 
314
  function apbct_update_to_5_127_0(){
315
 
316
- global $apbct;
317
 
318
  // Move exclusions from variable to settins
319
  global $cleantalk_url_exclusions, $cleantalk_key_exclusions;
320
  // URLs
321
  if(!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)){
322
  $apbct->settings['exclusions__urls'] = implode(',', $cleantalk_url_exclusions);
323
- if(APBCT_WPMS){
324
  $initial_blog = get_current_blog_id();
325
  switch_to_blog( 1 );
326
- }
327
- $apbct->saveSettings();
328
- if(APBCT_WPMS){
329
  switch_to_blog($initial_blog);
 
 
330
  }
331
  }
332
  // Fields
333
  if(!empty($cleantalk_key_exclusions) && is_array($cleantalk_key_exclusions)){
334
  $apbct->settings['exclusions__fields'] = implode(',', $cleantalk_key_exclusions);
335
- if(APBCT_WPMS){
336
  $initial_blog = get_current_blog_id();
337
  switch_to_blog( 1 );
338
- }
339
- $apbct->saveSettings();
340
- if(APBCT_WPMS){
341
  switch_to_blog($initial_blog);
 
 
342
  }
343
  }
344
 
@@ -351,8 +433,7 @@ function apbct_update_to_5_127_0(){
351
  if(APBCT_WPMS){
352
 
353
  // Whitelabel
354
- // Reset "api_key_is_recieved" flag
355
- global $wpdb;
356
  $initial_blog = get_current_blog_id();
357
  $blogs = array_keys( $wpdb->get_results( 'SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K ) );
358
  foreach ( $blogs as $blog ){
@@ -395,9 +476,12 @@ function apbct_update_to_5_127_0(){
395
  }
396
  }
397
 
 
 
 
398
  function apbct_update_to_5_127_1(){
 
399
  if(APBCT_WPMS && is_main_site()){
400
- global $apbct;
401
  $network_settings = get_site_option( 'cleantalk_network_settings' );
402
  if( $network_settings !== false && empty( $network_settings['allow_custom_key'] ) && empty( $network_settings['white_label'] ) ){
403
  $network_settings['allow_custom_key'] = 1;
@@ -409,15 +493,21 @@ function apbct_update_to_5_127_1(){
409
  }
410
  }
411
 
 
 
 
412
  function apbct_update_to_5_128_0(){
413
  global $apbct;
414
  $apbct->remote_calls = array();
415
  $apbct->save('remote_calls');
416
  }
417
 
 
 
 
418
  function apbct_update_to_5_133_0() {
419
 
420
- global $wpdb;
421
 
422
  // Scan comment/user log
423
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
@@ -434,10 +524,19 @@ function apbct_update_to_5_133_0() {
434
 
435
  }
436
 
 
 
 
 
 
437
  function apbct_update_to_5_138_0() {
438
-
439
  global $wpdb;
440
-
 
 
 
 
441
  // SQL queries for each blog
442
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
443
  `id` int(11) NOT NULL AUTO_INCREMENT,
@@ -464,8 +563,9 @@ function apbct_update_to_5_138_0() {
464
 
465
  // Getting all blog ids
466
  $initial_blog = get_current_blog_id();
467
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
468
-
 
469
  // Getting main blog setting
470
  switch_to_blog( 1 );
471
  $main_blog_settings = get_option( 'cleantalk_settings' );
@@ -474,7 +574,7 @@ function apbct_update_to_5_138_0() {
474
  // Getting network settings
475
  $net_settings = get_site_option('cleantalk_network_settings');
476
 
477
- foreach ($blogs as $blog) {
478
 
479
  // Update time limit to prevent exec time error
480
  set_time_limit(20);
@@ -543,8 +643,13 @@ function apbct_update_to_5_138_0() {
543
 
544
  }
545
 
 
 
 
546
  function apbct_update_to_5_142_0() {
547
-
 
 
548
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
549
  `id` VARCHAR(40) NOT NULL,
550
  `ip` VARCHAR(40) NOT NULL,
@@ -568,8 +673,12 @@ function apbct_update_to_5_142_0() {
568
 
569
  }
570
 
 
 
 
571
  function apbct_update_to_5_142_1() {
572
-
 
573
  $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
574
 
575
  $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
@@ -579,8 +688,12 @@ function apbct_update_to_5_142_1() {
579
 
580
  }
581
 
 
 
 
582
  function apbct_update_to_5_142_2() {
583
-
 
584
  $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
585
 
586
  $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
@@ -590,10 +703,14 @@ function apbct_update_to_5_142_2() {
590
 
591
  }
592
 
 
 
 
593
  function apbct_update_to_5_142_3() {
594
 
595
  global $apbct;
596
-
 
597
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
598
  `id` VARCHAR(40) NOT NULL,
599
  `ip` VARCHAR(15) NOT NULL,
@@ -607,10 +724,14 @@ function apbct_update_to_5_142_3() {
607
 
608
  }
609
 
 
 
 
610
  function apbct_update_to_5_143_2() {
611
 
612
  global $apbct;
613
-
 
614
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
615
 
616
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
@@ -626,10 +747,14 @@ function apbct_update_to_5_143_2() {
626
 
627
  }
628
 
 
 
 
629
  function apbct_update_to_5_146_1() {
630
 
631
  global $apbct;
632
 
 
633
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ac_log`;';
634
 
635
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
@@ -644,19 +769,29 @@ function apbct_update_to_5_146_1() {
644
 
645
  }
646
 
 
 
 
647
  function apbct_update_to_5_146_3() {
648
  update_option( 'cleantalk_plugin_request_ids', array() );
649
  }
650
 
 
 
 
651
  function apbct_update_to_5_148_0() {
652
  $cron = new Cron();
653
  $cron->updateTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400);
654
  }
655
 
 
 
 
656
  function apbct_update_to_5_149_2() {
657
 
658
  global $apbct;
659
 
 
660
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
661
  `id` INT(11) NOT NULL,
662
  `ua_template` VARCHAR(255) NULL DEFAULT NULL,
@@ -682,6 +817,9 @@ function apbct_update_to_5_149_2() {
682
 
683
  }
684
 
 
 
 
685
  function apbct_update_to_5_150_0() {
686
 
687
  global $wpdb;
@@ -706,10 +844,13 @@ function apbct_update_to_5_150_0() {
706
 
707
  }
708
 
 
 
 
709
  function apbct_update_to_5_150_1() {
710
 
711
  global $apbct;
712
-
713
  // UA BL with default charset
714
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ua_bl`;';
715
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
@@ -723,6 +864,9 @@ function apbct_update_to_5_150_1() {
723
  apbct_activation__create_tables( $sqls, $apbct->db_prefix );
724
  }
725
 
 
 
 
726
  function apbct_update_to_5_151_1 () {
727
  global $apbct;
728
  $apbct->fw_stats['firewall_updating_id'] = isset( $apbct->data['firewall_updating_id'] )
@@ -737,6 +881,10 @@ function apbct_update_to_5_151_1 () {
737
  $apbct->save('fw_stats');
738
  }
739
 
 
 
 
 
740
  function apbct_update_to_5_151_3 ()
741
  {
742
  global $wpdb, $apbct;
@@ -753,12 +901,18 @@ function apbct_update_to_5_151_3 ()
753
  apbct_sfw_update__init();
754
  }
755
 
 
 
 
756
  function apbct_update_to_5_151_6 ()
757
  {
758
  global $apbct;
759
  $apbct->error_delete( 'sfw_update', true );
760
  }
761
 
 
 
 
762
  function apbct_update_to_5_153_4(){
763
 
764
  // Adding cooldown to sending SFW logs
@@ -768,6 +922,9 @@ function apbct_update_to_5_153_4(){
768
 
769
  }
770
 
 
 
 
771
  function apbct_update_to_5_154_0(){
772
 
773
  global $apbct, $wpdb;
@@ -834,6 +991,7 @@ function apbct_update_to_5_154_0(){
834
  $network_settings = get_site_option( 'cleantalk_network_settings' );
835
 
836
  if( $network_settings ) {
 
837
  // replacing old key to new keys
838
  foreach( $network_settings as $key => $value ){
839
  if( array_key_exists( $key, $keys_map ) ) {
@@ -842,7 +1000,9 @@ function apbct_update_to_5_154_0(){
842
  $_network_settings[$key] = $value;
843
  }
844
  }
845
- update_site_option( 'cleantalk_network_settings', $_network_settings );
 
 
846
  }
847
 
848
  $initial_blog = get_current_blog_id();
@@ -854,6 +1014,7 @@ function apbct_update_to_5_154_0(){
854
 
855
  if( $settings ) {
856
  // replacing old key to new keys
 
857
  foreach( $settings as $key => $value ){
858
  if( array_key_exists( $key, $keys_map ) ) {
859
  $_settings[$keys_map[$key]] = $value;
@@ -861,7 +1022,9 @@ function apbct_update_to_5_154_0(){
861
  $_settings[$key] = $value;
862
  }
863
  }
864
- update_option( 'cleantalk_settings', $_settings );
 
 
865
  }
866
 
867
  }
@@ -876,6 +1039,7 @@ function apbct_update_to_5_154_0(){
876
  $settings = (array) $apbct->settings;
877
 
878
  if( $settings ) {
 
879
  // replacing old key to new keys
880
  foreach( $settings as $key => $value ){
881
  if( array_key_exists( $key, $keys_map ) ) {
@@ -891,6 +1055,8 @@ function apbct_update_to_5_154_0(){
891
 
892
  }
893
 
 
 
894
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
895
 
896
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
@@ -908,6 +1074,9 @@ function apbct_update_to_5_154_0(){
908
 
909
  }
910
 
 
 
 
911
  function apbct_update_to_5_156_0(){
912
 
913
  global $apbct;
@@ -921,6 +1090,9 @@ function apbct_update_to_5_156_0(){
921
 
922
  }
923
 
 
 
 
924
  function apbct_update_to_5_157_0(){
925
 
926
  global $apbct;
@@ -939,9 +1111,16 @@ function apbct_update_to_5_157_0(){
939
 
940
  }
941
 
 
 
 
942
  function apbct_update_to_5_158_0(){
943
 
944
  global $apbct, $wpdb;
 
 
 
 
945
 
946
  $table_sfw_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_DATA );
947
  $table_sfw_logs_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_LOG );
@@ -965,7 +1144,7 @@ function apbct_update_to_5_158_0(){
965
  if( APBCT_WPMS ){
966
  // Getting all blog ids
967
  $initial_blog = get_current_blog_id();
968
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
969
 
970
  foreach ($blogs as $blog) {
971
 
@@ -983,16 +1162,19 @@ function apbct_update_to_5_158_0(){
983
  // Update from fix branch
984
  if(APBCT_WPMS && is_main_site()){
985
 
986
- $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM '. $wpdb->blogs, OBJECT_K);
987
  $current_sites_list = $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'];
988
 
989
  if( is_array( $wp_blogs ) && is_array( $current_sites_list ) ) {
990
  foreach ($wp_blogs as $blog) {
991
  $blog_details = get_blog_details( array( 'blog_id' => $blog->blog_id ) );
992
- $site_list_index = array_search( $blog_details->blogname, $current_sites_list, true );
993
- if( $site_list_index !== false ) {
994
- $current_sites_list[$site_list_index] = $blog_details->id;
 
 
995
  }
 
996
  }
997
  $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'] = $current_sites_list;
998
  $apbct->settings['comments__hide_website_field'] = '0';
@@ -1007,12 +1189,18 @@ function apbct_update_to_5_158_0(){
1007
  }
1008
  }
1009
 
 
 
 
1010
  function apbct_update_to_5_158_2() {
1011
  global $apbct;
1012
  $apbct->stats['cron']['last_start'] = 0;
1013
  $apbct->save('stats');
1014
  }
1015
 
 
 
 
1016
  function apbct_update_to_5_159_6() {
1017
 
1018
  global $wpdb;
@@ -1048,8 +1236,15 @@ function apbct_update_to_5_159_6() {
1048
  }
1049
  }
1050
 
 
 
 
1051
  function apbct_update_to_5_159_7() {
1052
  global $wpdb;
 
 
 
 
1053
 
1054
  $table_sfw_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_DATA );
1055
  $table_sfw_logs_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_LOG );
@@ -1070,21 +1265,24 @@ function apbct_update_to_5_159_7() {
1070
  . ';';
1071
  }
1072
 
1073
- if( APBCT_WPMS ){
1074
- // Getting all blog ids
1075
- $initial_blog = get_current_blog_id();
1076
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
 
1077
 
1078
- foreach ($blogs as $blog) {
1079
 
1080
- switch_to_blog($blog);
1081
- apbct_activation__create_tables($sqls);
1082
- }
1083
 
1084
- // Restoring initial blog
1085
- switch_to_blog($initial_blog);
1086
 
1087
- }else{
1088
- apbct_activation__create_tables($sqls);
 
1089
  }
 
1090
  }
3
  use Cleantalk\ApbctWP\Cron;
4
  use Cleantalk\Common\Schema;
5
 
6
+ /**
7
+ * Main function to compare versions and run necessary update functions.
8
+ *
9
+ * @param string $current_version
10
+ * @param string $new_version
11
+ *
12
+ * @return bool
13
+ *
14
+ * @psalm-suppress PossiblyUndefinedIntArrayOffset
15
+ */
16
+ function apbct_run_update_actions( $current_version, $new_version ){
17
 
18
+ $current_version_arr = apbct_version_standardization( $current_version );
19
+ $new_version_arr = apbct_version_standardization( $new_version );
20
 
21
+ $current_version_str = implode( '.', $current_version_arr );
22
+ $new_version_str = implode( '.', $new_version_arr );
23
+
24
+ for( $ver_major = $current_version_arr[0]; $ver_major <= $current_version_arr[0]; $ver_major++ ){
25
  for($ver_minor = 0; $ver_minor <= 300; $ver_minor++){
26
  for($ver_fix = 0; $ver_fix <= 10; $ver_fix++){
27
 
28
+ if( version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $current_version_str, '<=') ) {
29
  continue;
30
+ }
31
 
32
  if(function_exists("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}")){
33
  $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}");
34
+ if(!empty($result['error'])) {
35
  break;
36
+ }
37
  }
38
 
39
  if( $ver_fix == 0 && function_exists("apbct_update_to_{$ver_major}_{$ver_minor}") ){
40
  $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}");
41
+ if(!empty($result['error'])) {
42
  break;
43
+ }
44
  }
45
 
46
+ if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $new_version_str, '>=')) {
47
+ break( 2 );
48
+ }
49
 
50
  }
51
  }
55
 
56
  }
57
 
58
+ /**
59
+ * Convert string version to an array
60
+ *
61
+ * @param string $version
62
+ *
63
+ * @return array
64
+ */
65
+ function apbct_version_standardization( $version ){
66
 
67
+ $parsed_version = explode( '.', $version );
68
+
69
+ $parsed_version[0] = !empty($parsed_version[0]) ? (int)$parsed_version[0] : 0;
70
+ $parsed_version[1] = !empty($parsed_version[1]) ? (int)$parsed_version[1] : 0;
71
+ $parsed_version[2] = !empty($parsed_version[2]) ? (int)$parsed_version[2] : 0;
72
+
73
+ return $parsed_version;
74
  }
75
 
76
+ /**
77
+ * Get columns from a selected DB table
78
+ *
79
+ * @param string $table_name
80
+ *
81
+ * @return array
82
+ */
83
  function apbct_get_table_columns( $table_name ) {
84
  global $wpdb;
85
  $query = 'SHOW COLUMNS FROM ' . $table_name;
91
  return $columns_names;
92
  }
93
 
94
+ /**
95
+ * @return void
96
+ */
97
  function apbct_update_to_5_50_0(){
98
  global $wpdb;
99
  $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_DATA .'` (
110
  PRIMARY KEY (`ip`));');
111
  }
112
 
113
+ /**
114
+ * @return void
115
+ */
116
  function apbct_update_to_5_56_0(){
117
  if (!wp_next_scheduled('cleantalk_update_sfw_hook'))
118
  wp_schedule_event(time()+1800, 'daily', 'cleantalk_update_sfw_hook' );
119
  }
120
+
121
+ /**
122
+ * @return void
123
+ */
124
  function apbct_update_to_5_70_0(){
125
 
126
  global $wpdb;
153
  $cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // New
154
  $cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500);
155
  }
156
+
157
+ /**
158
+ * @return void
159
+ */
160
  function apbct_update_to_5_74_0(){
161
  $cron = new Cron();
162
  $cron->removeTask('send_daily_request');
163
  }
164
 
165
+ /**
166
+ * @return void
167
+ */
168
  function apbct_update_to_5_97_0(){
169
 
170
  global $apbct;
175
  $apbct->saveData();
176
  }
177
 
178
+ /**
179
+ * @return void
180
+ */
181
  function apbct_update_to_5_109_0(){
182
 
183
  global $apbct, $wpdb;
217
  }
218
  }
219
 
220
+ /**
221
+ * @return void
222
+ */
223
  function apbct_update_to_5_110_0(){
224
  global $apbct;
225
  unset($apbct->data['last_remote_call']);
227
  $apbct->save('remote_calls');
228
  }
229
 
230
+ /**
231
+ * @return void
232
+ */
233
  function apbct_update_to_5_115_1(){
234
  apbct_sfw_update__init();
235
  }
236
 
237
+ /**
238
+ * @return void
239
+ */
240
  function apbct_update_to_5_116_0(){
241
 
242
  global $apbct, $wpdb;
254
  );
255
  }
256
 
257
+ /**
258
+ * @return void
259
+ */
260
  function apbct_update_to_5_116_1(){
261
 
262
  global $wpdb;
270
  );
271
  }
272
 
273
+ /**
274
+ * @return void
275
+ */
276
  function apbct_update_to_5_116_2(){
277
 
278
  global $wpdb;
286
  );
287
  }
288
 
289
+ /**
290
+ * @return void
291
+ */
292
  function apbct_update_to_5_118_0(){
293
  global $wpdb;
294
  $wpdb->query(
299
  delete_option('cleantalk_server');
300
  }
301
 
302
+ /**
303
+ * @return void
304
+ */
305
  function apbct_update_to_5_118_2(){
306
  global $apbct;
307
  $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
309
  $apbct->saveData();
310
  }
311
 
312
+ /**
313
+ * @return void
314
+ */
315
  function apbct_update_to_5_119_0(){
316
 
317
  global $wpdb;
318
 
319
  $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
320
+
321
+ $sqls = array();
322
+
323
  // SFW data
324
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
325
  `network` int(11) unsigned NOT NULL,
346
  apbct_activation__create_tables($sqls);
347
 
348
  // WPMS
349
+ if( is_multisite() ){
350
+
351
  $initial_blog = get_current_blog_id();
352
  $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
353
  foreach ($blogs as $blog) {
369
  );
370
  }
371
 
372
+ /**
373
+ * @return void
374
+ */
375
  function apbct_update_to_5_124_0(){
376
  global $apbct;
377
  // Deleting error in database because format were changed
379
  $apbct->saveErrors();
380
  }
381
 
382
+ /**
383
+ * @return void
384
+ */
385
  function apbct_update_to_5_126_0(){
386
  global $apbct;
387
  // Enable storing URLs
390
  $apbct->saveSettings();
391
  }
392
 
393
+ /**
394
+ * @return void
395
+ */
396
  function apbct_update_to_5_127_0(){
397
 
398
+ global $apbct, $wpdb;
399
 
400
  // Move exclusions from variable to settins
401
  global $cleantalk_url_exclusions, $cleantalk_key_exclusions;
402
  // URLs
403
  if(!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)){
404
  $apbct->settings['exclusions__urls'] = implode(',', $cleantalk_url_exclusions);
405
+ if( APBCT_WPMS ){
406
  $initial_blog = get_current_blog_id();
407
  switch_to_blog( 1 );
408
+ $apbct->saveSettings();
 
 
409
  switch_to_blog($initial_blog);
410
+ } else {
411
+ $apbct->saveSettings();
412
  }
413
  }
414
  // Fields
415
  if(!empty($cleantalk_key_exclusions) && is_array($cleantalk_key_exclusions)){
416
  $apbct->settings['exclusions__fields'] = implode(',', $cleantalk_key_exclusions);
417
+ if( APBCT_WPMS ){
418
  $initial_blog = get_current_blog_id();
419
  switch_to_blog( 1 );
420
+ $apbct->saveSettings();
 
 
421
  switch_to_blog($initial_blog);
422
+ } else {
423
+ $apbct->saveSettings();
424
  }
425
  }
426
 
433
  if(APBCT_WPMS){
434
 
435
  // Whitelabel
436
+ // Reset "api_key_is_received" flag
 
437
  $initial_blog = get_current_blog_id();
438
  $blogs = array_keys( $wpdb->get_results( 'SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K ) );
439
  foreach ( $blogs as $blog ){
476
  }
477
  }
478
 
479
+ /**
480
+ * @return void
481
+ */
482
  function apbct_update_to_5_127_1(){
483
+ global $apbct;
484
  if(APBCT_WPMS && is_main_site()){
 
485
  $network_settings = get_site_option( 'cleantalk_network_settings' );
486
  if( $network_settings !== false && empty( $network_settings['allow_custom_key'] ) && empty( $network_settings['white_label'] ) ){
487
  $network_settings['allow_custom_key'] = 1;
493
  }
494
  }
495
 
496
+ /**
497
+ * @return void
498
+ */
499
  function apbct_update_to_5_128_0(){
500
  global $apbct;
501
  $apbct->remote_calls = array();
502
  $apbct->save('remote_calls');
503
  }
504
 
505
+ /**
506
+ * @return void
507
+ */
508
  function apbct_update_to_5_133_0() {
509
 
510
+ $sqls = array();
511
 
512
  // Scan comment/user log
513
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
524
 
525
  }
526
 
527
+ /**
528
+ * @return void
529
+ *
530
+ * @psalm-suppress PossiblyUndefinedStringArrayOffset
531
+ */
532
  function apbct_update_to_5_138_0() {
533
+
534
  global $wpdb;
535
+ // change name for prevent psalm false positive
536
+ $_wpdb = $wpdb;
537
+
538
+ $sqls = array();
539
+
540
  // SQL queries for each blog
541
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
542
  `id` int(11) NOT NULL AUTO_INCREMENT,
563
 
564
  // Getting all blog ids
565
  $initial_blog = get_current_blog_id();
566
+ $blogs = $_wpdb->get_results('SELECT blog_id FROM '. $_wpdb->blogs, OBJECT_K);
567
+ $blogs_ids = array_keys( $blogs );
568
+
569
  // Getting main blog setting
570
  switch_to_blog( 1 );
571
  $main_blog_settings = get_option( 'cleantalk_settings' );
574
  // Getting network settings
575
  $net_settings = get_site_option('cleantalk_network_settings');
576
 
577
+ foreach ($blogs_ids as $blog) {
578
 
579
  // Update time limit to prevent exec time error
580
  set_time_limit(20);
643
 
644
  }
645
 
646
+ /**
647
+ * @return void
648
+ */
649
  function apbct_update_to_5_142_0() {
650
+
651
+ $sqls = array();
652
+
653
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
654
  `id` VARCHAR(40) NOT NULL,
655
  `ip` VARCHAR(40) NOT NULL,
673
 
674
  }
675
 
676
+ /**
677
+ * @return void
678
+ */
679
  function apbct_update_to_5_142_1() {
680
+
681
+ $sqls = array();
682
  $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
683
 
684
  $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
688
 
689
  }
690
 
691
+ /**
692
+ * @return void
693
+ */
694
  function apbct_update_to_5_142_2() {
695
+
696
+ $sqls = array();
697
  $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
698
 
699
  $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
703
 
704
  }
705
 
706
+ /**
707
+ * @return void
708
+ */
709
  function apbct_update_to_5_142_3() {
710
 
711
  global $apbct;
712
+
713
+ $sqls = array();
714
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
715
  `id` VARCHAR(40) NOT NULL,
716
  `ip` VARCHAR(15) NOT NULL,
724
 
725
  }
726
 
727
+ /**
728
+ * @return void
729
+ */
730
  function apbct_update_to_5_143_2() {
731
 
732
  global $apbct;
733
+
734
+ $sqls = array();
735
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
736
 
737
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
747
 
748
  }
749
 
750
+ /**
751
+ * @return void
752
+ */
753
  function apbct_update_to_5_146_1() {
754
 
755
  global $apbct;
756
 
757
+ $sqls = array();
758
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ac_log`;';
759
 
760
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
769
 
770
  }
771
 
772
+ /**
773
+ * @return void
774
+ */
775
  function apbct_update_to_5_146_3() {
776
  update_option( 'cleantalk_plugin_request_ids', array() );
777
  }
778
 
779
+ /**
780
+ * @return void
781
+ */
782
  function apbct_update_to_5_148_0() {
783
  $cron = new Cron();
784
  $cron->updateTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400);
785
  }
786
 
787
+ /**
788
+ * @return void
789
+ */
790
  function apbct_update_to_5_149_2() {
791
 
792
  global $apbct;
793
 
794
+ $sqls = array();
795
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
796
  `id` INT(11) NOT NULL,
797
  `ua_template` VARCHAR(255) NULL DEFAULT NULL,
817
 
818
  }
819
 
820
+ /**
821
+ * @return void
822
+ */
823
  function apbct_update_to_5_150_0() {
824
 
825
  global $wpdb;
844
 
845
  }
846
 
847
+ /**
848
+ * @return void
849
+ */
850
  function apbct_update_to_5_150_1() {
851
 
852
  global $apbct;
853
+ $sqls = array();
854
  // UA BL with default charset
855
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ua_bl`;';
856
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
864
  apbct_activation__create_tables( $sqls, $apbct->db_prefix );
865
  }
866
 
867
+ /**
868
+ * @return void
869
+ */
870
  function apbct_update_to_5_151_1 () {
871
  global $apbct;
872
  $apbct->fw_stats['firewall_updating_id'] = isset( $apbct->data['firewall_updating_id'] )
881
  $apbct->save('fw_stats');
882
  }
883
 
884
+ /**
885
+ * @return void
886
+ * @throws Exception
887
+ */
888
  function apbct_update_to_5_151_3 ()
889
  {
890
  global $wpdb, $apbct;
901
  apbct_sfw_update__init();
902
  }
903
 
904
+ /**
905
+ * @return void
906
+ */
907
  function apbct_update_to_5_151_6 ()
908
  {
909
  global $apbct;
910
  $apbct->error_delete( 'sfw_update', true );
911
  }
912
 
913
+ /**
914
+ * @return void
915
+ */
916
  function apbct_update_to_5_153_4(){
917
 
918
  // Adding cooldown to sending SFW logs
922
 
923
  }
924
 
925
+ /**
926
+ * @return void
927
+ */
928
  function apbct_update_to_5_154_0(){
929
 
930
  global $apbct, $wpdb;
991
  $network_settings = get_site_option( 'cleantalk_network_settings' );
992
 
993
  if( $network_settings ) {
994
+ $_network_settings = array();
995
  // replacing old key to new keys
996
  foreach( $network_settings as $key => $value ){
997
  if( array_key_exists( $key, $keys_map ) ) {
1000
  $_network_settings[$key] = $value;
1001
  }
1002
  }
1003
+ if( ! empty( $_network_settings ) ) {
1004
+ update_site_option( 'cleantalk_network_settings', $_network_settings );
1005
+ }
1006
  }
1007
 
1008
  $initial_blog = get_current_blog_id();
1014
 
1015
  if( $settings ) {
1016
  // replacing old key to new keys
1017
+ $_settings = array();
1018
  foreach( $settings as $key => $value ){
1019
  if( array_key_exists( $key, $keys_map ) ) {
1020
  $_settings[$keys_map[$key]] = $value;
1022
  $_settings[$key] = $value;
1023
  }
1024
  }
1025
+ if( ! empty( $_settings ) ){
1026
+ update_option( 'cleantalk_settings', $_settings );
1027
+ }
1028
  }
1029
 
1030
  }
1039
  $settings = (array) $apbct->settings;
1040
 
1041
  if( $settings ) {
1042
+ $_settings = array();
1043
  // replacing old key to new keys
1044
  foreach( $settings as $key => $value ){
1045
  if( array_key_exists( $key, $keys_map ) ) {
1055
 
1056
  }
1057
 
1058
+ $sqls = array();
1059
+
1060
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
1061
 
1062
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
1074
 
1075
  }
1076
 
1077
+ /**
1078
+ * @return void
1079
+ */
1080
  function apbct_update_to_5_156_0(){
1081
 
1082
  global $apbct;
1090
 
1091
  }
1092
 
1093
+ /**
1094
+ * @return void
1095
+ */
1096
  function apbct_update_to_5_157_0(){
1097
 
1098
  global $apbct;
1111
 
1112
  }
1113
 
1114
+ /**
1115
+ * @return void
1116
+ */
1117
  function apbct_update_to_5_158_0(){
1118
 
1119
  global $apbct, $wpdb;
1120
+ // change name for prevent psalm false positive
1121
+ $_wpdb = $wpdb;
1122
+
1123
+ $sqls = array();
1124
 
1125
  $table_sfw_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_DATA );
1126
  $table_sfw_logs_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_LOG );
1144
  if( APBCT_WPMS ){
1145
  // Getting all blog ids
1146
  $initial_blog = get_current_blog_id();
1147
+ $blogs = array_keys($_wpdb->get_results('SELECT blog_id FROM '. $_wpdb->blogs, OBJECT_K));
1148
 
1149
  foreach ($blogs as $blog) {
1150
 
1162
  // Update from fix branch
1163
  if(APBCT_WPMS && is_main_site()){
1164
 
1165
+ $wp_blogs = $_wpdb->get_results('SELECT blog_id, site_id FROM '. $_wpdb->blogs, OBJECT_K);
1166
  $current_sites_list = $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'];
1167
 
1168
  if( is_array( $wp_blogs ) && is_array( $current_sites_list ) ) {
1169
  foreach ($wp_blogs as $blog) {
1170
  $blog_details = get_blog_details( array( 'blog_id' => $blog->blog_id ) );
1171
+ if( $blog_details ) {
1172
+ $site_list_index = array_search( $blog_details->blogname, $current_sites_list, true );
1173
+ if( $site_list_index !== false ) {
1174
+ $current_sites_list[$site_list_index] = $blog_details->id;
1175
+ }
1176
  }
1177
+
1178
  }
1179
  $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'] = $current_sites_list;
1180
  $apbct->settings['comments__hide_website_field'] = '0';
1189
  }
1190
  }
1191
 
1192
+ /**
1193
+ * @return void
1194
+ */
1195
  function apbct_update_to_5_158_2() {
1196
  global $apbct;
1197
  $apbct->stats['cron']['last_start'] = 0;
1198
  $apbct->save('stats');
1199
  }
1200
 
1201
+ /**
1202
+ * @return void
1203
+ */
1204
  function apbct_update_to_5_159_6() {
1205
 
1206
  global $wpdb;
1236
  }
1237
  }
1238
 
1239
+ /**
1240
+ * @return void
1241
+ */
1242
  function apbct_update_to_5_159_7() {
1243
  global $wpdb;
1244
+ // change name for prevent psalm false positive
1245
+ $_wpdb = $wpdb;
1246
+
1247
+ $sqls = array();
1248
 
1249
  $table_sfw_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_DATA );
1250
  $table_sfw_logs_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_LOG );
1265
  . ';';
1266
  }
1267
 
1268
+ if( ! empty( $sqls ) ) {
1269
+ if( APBCT_WPMS ){
1270
+ // Getting all blog ids
1271
+ $initial_blog = get_current_blog_id();
1272
+ $blogs = array_keys($_wpdb->get_results('SELECT blog_id FROM '. $_wpdb->blogs, OBJECT_K));
1273
 
1274
+ foreach ($blogs as $blog) {
1275
 
1276
+ switch_to_blog($blog);
1277
+ apbct_activation__create_tables($sqls);
1278
+ }
1279
 
1280
+ // Restoring initial blog
1281
+ switch_to_blog($initial_blog);
1282
 
1283
+ }else{
1284
+ apbct_activation__create_tables($sqls);
1285
+ }
1286
  }
1287
+
1288
  }
js/apbct-public.min.js CHANGED
@@ -1,2 +1,2 @@
1
- function ctSetCookie(e,t,n){var o;("string"==typeof e&&"string"==typeof t||"number"==typeof t)&&(o="ct_pointer_data"===e||"ct_user_info"===e,e=[[e,t,n]]),0!=+ctPublic.data__set_cookies&&(1==+ctPublic.data__set_cookies?e.forEach(function(e,t,n){var o=void 0!==e[2]?"expires="+o+"; ":"",i="https:"===location.protocol?"; secure":"";document.cookie=e[0]+"="+encodeURIComponent(e[1])+"; "+o+"path=/; samesite=lax"+i}):2!=+ctPublic.data__set_cookies||o||(1==+ctPublic.data__set_cookies__alt_sessions_type?apbct_public_sendREST("alt_sessions",{method:"POST",data:{cookies:e}}):2==+ctPublic.data__set_cookies__alt_sessions_type&&apbct_public_sendAJAX({action:"apbct_alt_session__save__AJAX",cookies:e},{apbct_ajax:1,notJson:1})))}function apbct_collect_visible_fields(e){var t=[],o="",i=0,c="",a=0,n=[];for(var l in e.elements)isNaN(+l)||(t[l]=e.elements[l]);return(t=t.filter(function(e){return-1===n.indexOf(e.getAttribute("name"))&&(-1===["radio","checkbox"].indexOf(e.getAttribute("type"))||(n.push(e.getAttribute("name")),!1))})).forEach(function(e,t,n){"submit"!==e.getAttribute("type")&&null!==e.getAttribute("name")&&"ct_checkjs"!==e.getAttribute("name")&&("none"!==getComputedStyle(e).display&&"hidden"!==getComputedStyle(e).visibility&&"0"!==getComputedStyle(e).opacity&&"hidden"!==e.getAttribute("type")||e.classList.contains("wp-editor-area")?(o+=" "+e.getAttribute("name"),i++):(c+=" "+e.getAttribute("name"),a++))}),c=c.trim(),{visible_fields:o=o.trim(),visible_fields_count:i,invisible_fields:c,invisible_fields_count:a}}function apbct_visible_fields_set_cookie(e){var t="object"==typeof e&&null!==e?e:{};ctSetCookie("apbct_visible_fields",JSON.stringify(t))}function apbct_js_keys__set_input_value(e,t,n,o){if(0<document.querySelectorAll("[name^=ct_checkjs]").length)for(var i=document.querySelectorAll("[name^=ct_checkjs]"),c=0;c<i.length;c++)i[c].value=e.js_key}function apbct_public_sendAJAX(t,n,o){var i=n.callback||null,c=n.callback_context||null,a=n.callback_params||null,e=n.async||!0,l=n.notJson||null,s=n.timeout||15e3,o=o||null,r=n.button||null,u=n.spinner||null,_=n.progressbar||null,d=n.silent||null,p=n.no_nonce||null,m=n.apbct_ajax||null;"string"==typeof t?(p||(t=t+"&_ajax_nonce="+ctPublic._ajax_nonce),t=t+"&no_cache="+Math.random()):(p||(t._ajax_nonce=ctPublic._ajax_nonce),t.no_cache=Math.random()),r&&(r.setAttribute("disabled","disabled"),r.style.cursor="not-allowed"),u&&jQuery(u).css("display","inline"),jQuery.ajax({type:"POST",url:m?ctPublic._apbct_ajax_url:ctPublic._ajax_url,data:t,async:e,success:function(e){r&&(r.removeAttribute("disabled"),r.style.cursor="pointer"),u&&jQuery(u).css("display","none"),l||(e=JSON.parse(e)),e.error?(setTimeout(function(){_&&_.fadeOut("slow")},1e3),console.log("Error happens: "+(e.error||"Unkown"))):i&&(a?i.apply(c,a.concat(e,t,n,o)):i(e,t,n,o))},error:function(e,t,n){r&&(r.removeAttribute("disabled"),r.style.cursor="pointer"),u&&jQuery(u).css("display","none"),n&&!d&&(console.log("APBCT_AJAX_ERROR"),console.log(e),console.log(t),console.log("Anti-spam by Cleantalk plugin error: "+n+"Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/"))},timeout:s})}function apbct_public_sendREST(t,n){var o=n.callback||null,e=n.data||[],i=n.method||"POST";jQuery.ajax({type:i,url:ctPublic._rest_url+"cleantalk-antispam/v1/"+t,data:e,beforeSend:function(e){e.setRequestHeader("X-WP-Nonce",ctPublic._rest_nonce)},success:function(e){e.error?console.log("Error happens: "+(e.error||"Unknown")):o&&o(e,t,n,null)},error:function(e,t,n){n&&(console.log("APBCT_REST_ERROR"),console.log(e),console.log(t),console.log("Anti-spam by Cleantalk plugin REST API error: "+n+" Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/"))}})}function apbctGetScreenInfo(){return JSON.stringify({fullWidth:document.documentElement.scrollWidth,fullHeight:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight),visibleWidth:document.documentElement.clientWidth,visibleHeight:document.documentElement.clientHeight})}!function(){var e=new Date,t=(new Date).getTime(),n=!0,o=[],i=0,c={},a=!1;function l(e,t,n){"function"==typeof window.addEventListener?e.addEventListener(t,n):e.attachEvent(t,n)}function s(e,t,n){"function"==typeof window.removeEventListener?e.removeEventListener(t,n):e.detachEvent(t,n)}ctSetCookie([["ct_ps_timestamp",Math.floor((new Date).getTime()/1e3)],["ct_fkp_timestamp","0"],["ct_pointer_data","0"],["ct_timezone",e.getTimezoneOffset()/60*-1],["apbct_visible_fields","0"]]);var r=function(){ctSetCookie("ct_fkp_timestamp",Math.floor((new Date).getTime()/1e3)),s(window,"mousedown",r),s(window,"keydown",r)},u=setInterval(function(){n=!0},150),_=setInterval(function(){ctSetCookie("ct_pointer_data",JSON.stringify(o))},1200),d=function(e){!0===n&&(o.push([Math.round(e.clientY),Math.round(e.clientX),Math.round((new Date).getTime()-t)]),n=!1,50<=++i&&(s(window,"mousemove",d),clearInterval(u),clearInterval(_)))};function p(e){var t=e.target.value;!t||t in c||apbct_public_sendAJAX({action:"apbct_email_check_before_post",data:{email:t}},{apbct_ajax:1,callback:function(e){e.result&&(c[t]={result:e.result,timestamp:Date.now()/1e3|0},ctSetCookie("ct_checked_emails",JSON.stringify(c)))}})}l(window,"mousemove",d),l(window,"mousedown",r),l(window,"keydown",r),l(window,"scroll",function(){a||(ctSetCookie("ct_has_scrolled",JSON.stringify(!0)),a=!0)}),l(window,"DOMContentLoaded",function(){+ctPublic.pixel__setting&&(ctSetCookie("apbct_pixel_url",ctPublic.pixel__url),+ctPublic.pixel__enabled&&jQuery("body").append('<img style="display: none; left: 99999px;" src="'+ctPublic.pixel__url+'">')),+ctPublic.data__email_check_before_post&&(ctSetCookie("ct_checked_emails","0"),jQuery("input[type = 'email'], #email").blur(p)),ctSetCookie("ct_screen_info",apbctGetScreenInfo()),ctSetCookie("ct_has_scrolled",JSON.stringify(!1)),setTimeout(function(){for(var e={},t=0;t<document.forms.length;t++){var n=document.forms[t];n.classList.contains("slp_search_form")||n.parentElement.classList.contains("mec-booking")||-1!==n.action.toString().indexOf("activehosted.com")||n.id&&"caspioform"==n.id||n.name.classList&&n.name.classList.contains("tinkoffPayRow")||n.name.classList&&n.name.classList.contains("give-form ")||(e[t]=apbct_collect_visible_fields(n),n.onsubmit_prev=n.onsubmit,n.onsubmit=function(e){var t={};t[0]=apbct_collect_visible_fields(this),apbct_visible_fields_set_cookie(t),e.target.onsubmit_prev instanceof Function&&setTimeout(function(){e.target.onsubmit_prev.call(e.target,e)},500)})}apbct_visible_fields_set_cookie(e)},1e3)})}(),"undefined"!=typeof jQuery&&jQuery(document).ajaxComplete(function(e,t,n){var o;!t.responseText||-1===t.responseText.indexOf('"apbct')||void 0!==(o=JSON.parse(t.responseText)).apbct&&(o=o.apbct).blocked&&(document.dispatchEvent(new CustomEvent("apbctAjaxBockAlert",{bubbles:!0,detail:{message:o.comment}})),cleantalkModal.loaded=o.comment,cleantalkModal.open(),1==+o.stop_script&&window.stop())});
2
  //# sourceMappingURL=apbct-public.min.js.map
1
+ function ctSetCookie(e,t,n){var o;("string"==typeof e&&"string"==typeof t||"number"==typeof t)&&(o="ct_pointer_data"===e||"ct_user_info"===e,e=[[e,t,n]]),0==+ctPublic.data__set_cookies||(1==+ctPublic.data__set_cookies?e.forEach(function(e,t,n){var o=void 0!==e[2]?"expires="+o+"; ":"",i="https:"===location.protocol?"; secure":"";document.cookie=e[0]+"="+encodeURIComponent(e[1])+"; "+o+"path=/; samesite=lax"+i}):2!=+ctPublic.data__set_cookies||o||(1==+ctPublic.data__set_cookies__alt_sessions_type?apbct_public_sendREST("alt_sessions",{method:"POST",data:{cookies:e}}):2==+ctPublic.data__set_cookies__alt_sessions_type&&apbct_public_sendAJAX({action:"apbct_alt_session__save__AJAX",cookies:e},{apbct_ajax:1,notJson:1})))}function apbct_collect_visible_fields(e){var t,n=[],o="",i=0,c="",l=0,a=[];for(t in e.elements)isNaN(+t)||(n[t]=e.elements[t]);return(n=n.filter(function(e){return-1===a.indexOf(e.getAttribute("name"))&&(-1===["radio","checkbox"].indexOf(e.getAttribute("type"))||(a.push(e.getAttribute("name")),!1))})).forEach(function(e,t,n){"submit"!==e.getAttribute("type")&&null!==e.getAttribute("name")&&"ct_checkjs"!==e.getAttribute("name")&&("none"!==getComputedStyle(e).display&&"hidden"!==getComputedStyle(e).visibility&&"0"!==getComputedStyle(e).opacity&&"hidden"!==e.getAttribute("type")||e.classList.contains("wp-editor-area")?(o+=" "+e.getAttribute("name"),i++):(c+=" "+e.getAttribute("name"),l++))}),c=c.trim(),{visible_fields:o=o.trim(),visible_fields_count:i,invisible_fields:c,invisible_fields_count:l}}function apbct_visible_fields_set_cookie(e){e="object"==typeof e&&null!==e?e:{};ctSetCookie("apbct_visible_fields",JSON.stringify(e))}function apbct_js_keys__set_input_value(e,t,n,o){if(0<document.querySelectorAll("[name^=ct_checkjs]").length)for(var i=document.querySelectorAll("[name^=ct_checkjs]"),c=0;c<i.length;c++)i[c].value=e.js_key}function apbct_public_sendAJAX(t,n,o){var i=n.callback||null,c=n.callback_context||null,l=n.callback_params||null,e=n.async||!0,a=n.notJson||null,s=n.timeout||15e3,o=o||null,r=n.button||null,u=n.spinner||null,_=n.progressbar||null,d=n.silent||null,p=n.no_nonce||null,m=n.apbct_ajax||null;"string"==typeof t?t=(t=!p?t+"&_ajax_nonce="+ctPublic._ajax_nonce:t)+"&no_cache="+Math.random():(p||(t._ajax_nonce=ctPublic._ajax_nonce),t.no_cache=Math.random()),r&&(r.setAttribute("disabled","disabled"),r.style.cursor="not-allowed"),u&&jQuery(u).css("display","inline"),jQuery.ajax({type:"POST",url:m?ctPublic._apbct_ajax_url:ctPublic._ajax_url,data:t,async:e,success:function(e){r&&(r.removeAttribute("disabled"),r.style.cursor="pointer"),u&&jQuery(u).css("display","none"),(e=!a?JSON.parse(e):e).error?(setTimeout(function(){_&&_.fadeOut("slow")},1e3),console.log("Error happens: "+(e.error||"Unkown"))):i&&(l?i.apply(c,l.concat(e,t,n,o)):i(e,t,n,o))},error:function(e,t,n){r&&(r.removeAttribute("disabled"),r.style.cursor="pointer"),u&&jQuery(u).css("display","none"),n&&!d&&(console.log("APBCT_AJAX_ERROR"),console.log(e),console.log(t),console.log("Anti-spam by Cleantalk plugin error: "+n+"Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/"))},timeout:s})}function apbct_public_sendREST(t,n){var o=n.callback||null,e=n.data||[],i=n.method||"POST";jQuery.ajax({type:i,url:ctPublic._rest_url+"cleantalk-antispam/v1/"+t,data:e,beforeSend:function(e){e.setRequestHeader("X-WP-Nonce",ctPublic._rest_nonce)},success:function(e){e.error?console.log("Error happens: "+(e.error||"Unknown")):o&&o(e,t,n,null)},error:function(e,t,n){n&&(console.log("APBCT_REST_ERROR"),console.log(e),console.log(t),console.log("Anti-spam by Cleantalk plugin REST API error: "+n+" Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/"))}})}function apbctGetScreenInfo(){return JSON.stringify({fullWidth:document.documentElement.scrollWidth,fullHeight:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight),visibleWidth:document.documentElement.clientWidth,visibleHeight:document.documentElement.clientHeight})}!function(){var e=new Date,t=(new Date).getTime(),n=!0,o=[],i=0,c={},l=!1;function a(e,t,n){"function"==typeof window.addEventListener?e.addEventListener(t,n):e.attachEvent(t,n)}function s(e,t,n){"function"==typeof window.removeEventListener?e.removeEventListener(t,n):e.detachEvent(t,n)}ctSetCookie([["ct_ps_timestamp",Math.floor((new Date).getTime()/1e3)],["ct_fkp_timestamp","0"],["ct_pointer_data","0"],["ct_timezone",e.getTimezoneOffset()/60*-1],["apbct_visible_fields","0"]]);var r=function(e){ctSetCookie("ct_fkp_timestamp",Math.floor((new Date).getTime()/1e3)),s(window,"mousedown",r),s(window,"keydown",r)},u=setInterval(function(){n=!0},150),_=setInterval(function(){ctSetCookie("ct_pointer_data",JSON.stringify(o))},1200),d=function(e){!0===n&&(o.push([Math.round(e.clientY),Math.round(e.clientX),Math.round((new Date).getTime()-t)]),n=!1,50<=++i&&(s(window,"mousemove",d),clearInterval(u),clearInterval(_)))};function p(e){var t=e.target.value;!t||t in c||apbct_public_sendAJAX({action:"apbct_email_check_before_post",data:{email:t}},{apbct_ajax:1,callback:function(e){e.result&&(c[t]={result:e.result,timestamp:Date.now()/1e3|0},ctSetCookie("ct_checked_emails",JSON.stringify(c)))}})}a(window,"mousemove",d),a(window,"mousedown",r),a(window,"keydown",r),a(window,"scroll",function(){l||(ctSetCookie("ct_has_scrolled",JSON.stringify(!0)),l=!0)}),a(window,"DOMContentLoaded",function(){+ctPublic.pixel__setting&&(ctSetCookie("apbct_pixel_url",ctPublic.pixel__url),+ctPublic.pixel__enabled&&jQuery("body").append('<img style="display: none; left: 99999px;" src="'+ctPublic.pixel__url+'">')),+ctPublic.data__email_check_before_post&&(ctSetCookie("ct_checked_emails","0"),jQuery("input[type = 'email'], #email").blur(p)),ctSetCookie("ct_screen_info",apbctGetScreenInfo()),ctSetCookie("ct_has_scrolled",JSON.stringify(!1)),setTimeout(function(){for(var e={},t=0;t<document.forms.length;t++){var n=document.forms[t];n.classList.contains("slp_search_form")||n.parentElement.classList.contains("mec-booking")||-1!==n.action.toString().indexOf("activehosted.com")||n.id&&"caspioform"==n.id||n.name.classList&&n.name.classList.contains("tinkoffPayRow")||n.name.classList&&n.name.classList.contains("give-form")||(e[t]=apbct_collect_visible_fields(n),n.onsubmit_prev=n.onsubmit,n.onsubmit=function(e){var t={};t[0]=apbct_collect_visible_fields(this),apbct_visible_fields_set_cookie(t),e.target.onsubmit_prev instanceof Function&&setTimeout(function(){e.target.onsubmit_prev.call(e.target,e)},500)})}apbct_visible_fields_set_cookie(e)},1e3)})}(),"undefined"!=typeof jQuery&&jQuery(document).ajaxComplete(function(e,t,n){!t.responseText||-1===t.responseText.indexOf('"apbct')||void 0!==(t=JSON.parse(t.responseText)).apbct&&(t=t.apbct).blocked&&(document.dispatchEvent(new CustomEvent("apbctAjaxBockAlert",{bubbles:!0,detail:{message:t.comment}})),cleantalkModal.loaded=t.comment,cleantalkModal.open(),1==+t.stop_script&&window.stop())});
2
  //# sourceMappingURL=apbct-public.min.js.map
js/apbct-public.min.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"apbct-public.min.js","sources":["apbct-public.js"],"sourcesContent":["(function() {\n\n\tvar ct_date = new Date(),\n\t\tctTimeMs = new Date().getTime(),\n\t\tctMouseEventTimerFlag = true, //Reading interval flag\n\t\tctMouseData = [],\n\t\tctMouseDataCounter = 0,\n\t\tctCheckedEmails = {},\n\t\tctScrollCollected = false;\n\n\tfunction apbct_attach_event_handler(elem, event, callback){\n\t\tif(typeof window.addEventListener === \"function\") elem.addEventListener(event, callback);\n\t\telse elem.attachEvent(event, callback);\n\t}\n\n\tfunction apbct_remove_event_handler(elem, event, callback){\n\t\tif(typeof window.removeEventListener === \"function\") elem.removeEventListener(event, callback);\n\t\telse elem.detachEvent(event, callback);\n\t}\n\n\tctSetCookie(\n\t\t[\n\t\t\t[ \"ct_ps_timestamp\", Math.floor(new Date().getTime() / 1000) ],\n\t\t\t[ \"ct_fkp_timestamp\", \"0\" ],\n\t\t\t[ \"ct_pointer_data\", \"0\" ],\n\t\t\t[ \"ct_timezone\", ct_date.getTimezoneOffset()/60*(-1) ],\n\t\t\t[ \"apbct_visible_fields\", \"0\" ],\n\t\t]\n\t);\n\n\t//Writing first key press timestamp\n\tvar ctFunctionFirstKey = function output(event){\n\t\tvar KeyTimestamp = Math.floor(new Date().getTime()/1000);\n\t\tctSetCookie(\"ct_fkp_timestamp\", KeyTimestamp);\n\t\tctKeyStopStopListening();\n\t};\n\n\t//Reading interval\n\tvar ctMouseReadInterval = setInterval(function(){\n\t\tctMouseEventTimerFlag = true;\n\t}, 150);\n\n\t//Writting interval\n\tvar ctMouseWriteDataInterval = setInterval(function(){\n\t\tctSetCookie(\"ct_pointer_data\", JSON.stringify(ctMouseData));\n\t}, 1200);\n\n\t//Logging mouse position each 150 ms\n\tvar ctFunctionMouseMove = function output(event){\n\t\tif(ctMouseEventTimerFlag === true){\n\n\t\t\tctMouseData.push([\n\t\t\t\tMath.round(event.clientY),\n\t\t\t\tMath.round(event.clientX),\n\t\t\t\tMath.round(new Date().getTime() - ctTimeMs)\n\t\t\t]);\n\n\t\t\tctMouseDataCounter++;\n\t\t\tctMouseEventTimerFlag = false;\n\t\t\tif(ctMouseDataCounter >= 50){\n\t\t\t\tctMouseStopData();\n\t\t\t}\n\t\t}\n\t};\n\n\t//Stop mouse observing function\n\tfunction ctMouseStopData(){\n\t\tapbct_remove_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\t\tclearInterval(ctMouseReadInterval);\n\t\tclearInterval(ctMouseWriteDataInterval);\n\t}\n\n\t//Stop key listening function\n\tfunction ctKeyStopStopListening(){\n\t\tapbct_remove_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\t\tapbct_remove_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\t}\n\n\tfunction checkEmail(e) {\n\t\tvar current_email = e.target.value;\n\t\tif (current_email && !(current_email in ctCheckedEmails)) {\n\t\t\tapbct_public_sendAJAX(\n\t\t\t\t{action: 'apbct_email_check_before_post', data : {'email' : current_email}},\n\t\t\t\t{\n\t\t\t\t\tapbct_ajax: 1,\n\t\t\t\t\tcallback: function (result) {\n\t\t\t\t\t\tif (result.result) {\n\t\t\t\t\t\t\tctCheckedEmails[current_email] = {'result' : result.result, 'timestamp': Date.now() / 1000 |0};\n\t\t\t\t\t\t\tctSetCookie('ct_checked_emails', JSON.stringify(ctCheckedEmails));\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\t\t\n\t\t}\n\t}\n\n\tfunction ctSetHasScrolled() {\n\t\tif( ! ctScrollCollected ) {\n\t\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( true ) );\n\t\t\tctScrollCollected = true;\n\t\t}\n\t}\n\n\tapbct_attach_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\tapbct_attach_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"scroll\", ctSetHasScrolled);\n\n\t// Ready function\n\tfunction apbct_ready(){\n\n\t\tif( +ctPublic.pixel__setting ){\n\t\t\tctSetCookie( 'apbct_pixel_url', ctPublic.pixel__url );\n\t\t\tif( +ctPublic.pixel__enabled ){\n\t\t\t\tjQuery('body').append( '<img style=\"display: none; left: 99999px;\" src=\"' + ctPublic.pixel__url + '\">' );\n\t\t\t}\n\t\t}\n\n\t\tif ( +ctPublic.data__email_check_before_post) {\n\t\t\tctSetCookie( 'ct_checked_emails', '0');\n\t\t\tjQuery(\"input[type = 'email'], #email\").blur(checkEmail);\n\t\t}\n\n\t\t// Collect scrolling info\n\t\tctSetCookie( 'ct_screen_info', apbctGetScreenInfo() );\n\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( false ) );\n\n\t\tsetTimeout(function(){\n\n\t\t\tvar visible_fields_collection = {};\n\n\t\t\tfor(var i = 0; i < document.forms.length; i++){\n\t\t\t\tvar form = document.forms[i];\n\n\t\t\t\t//Exclusion for forms\n\t\t\t\tif (\n\t\t\t\t\tform.classList.contains('slp_search_form') || //StoreLocatorPlus form\n\t\t\t\t\tform.parentElement.classList.contains('mec-booking') ||\n\t\t\t\t\tform.action.toString().indexOf('activehosted.com') !== -1 || // Active Campaign\n\t\t\t\t\t(form.id && form.id == 'caspioform') || //Caspio Form\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('tinkoffPayRow')) || // TinkoffPayForm\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('give-form ')) // GiveWP\n\t\t\t\t)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tvisible_fields_collection[i] = apbct_collect_visible_fields( form );\n\n\t\t\t\tform.onsubmit_prev = form.onsubmit;\n\t\t\t\tform.onsubmit = function (event) {\n\n\t\t\t\t\tvar visible_fields = {};\n\t\t\t\t\tvisible_fields[0] = apbct_collect_visible_fields(this);\n\t\t\t\t\tapbct_visible_fields_set_cookie( visible_fields );\n\n\t\t\t\t\t// Call previous submit action\n\t\t\t\t\tif (event.target.onsubmit_prev instanceof Function) {\n\t\t\t\t\t\tsetTimeout(function () {\n\t\t\t\t\t\t\tevent.target.onsubmit_prev.call(event.target, event);\n\t\t\t\t\t\t}, 500);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tapbct_visible_fields_set_cookie( visible_fields_collection );\n\n\t\t}, 1000);\n\t}\n\tapbct_attach_event_handler(window, \"DOMContentLoaded\", apbct_ready);\n\n}());\n\nfunction ctSetCookie( cookies, value, expires ){\n\n\tif( typeof cookies === 'string' && typeof value === 'string' || typeof value === 'number'){\n\t\tvar skip_alt = cookies === 'ct_pointer_data' || cookies === 'ct_user_info';\n\t\tcookies = [ [ cookies, value, expires ] ];\n\t}\n\n\t// Cookies disabled\n\tif( +ctPublic.data__set_cookies === 0 ){\n\t\treturn;\n\n\t// Using traditional cookies\n\t}else if( +ctPublic.data__set_cookies === 1 ){\n\t\tcookies.forEach( function (item, i, arr\t) {\n\t\t\tvar expires = typeof item[2] !== 'undefined' ? \"expires=\" + expires + '; ' : '';\n\t\t\tvar ctSecure = location.protocol === 'https:' ? '; secure' : '';\n\t\t\tdocument.cookie = item[0] + \"=\" + encodeURIComponent(item[1]) + \"; \" + expires + \"path=/; samesite=lax\" + ctSecure;\n\t\t});\n\n\t// Using alternative cookies\n\t}else if( +ctPublic.data__set_cookies === 2 && ! skip_alt ){\n\n\t\t// Using REST API handler\n\t\tif( +ctPublic.data__set_cookies__alt_sessions_type === 1 ){\n\t\t\tapbct_public_sendREST(\n\t\t\t\t'alt_sessions',\n\t\t\t\t{\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: { cookies: cookies }\n\t\t\t\t}\n\t\t\t);\n\n\t\t// Using AJAX request and handler\n\t\t}else if( +ctPublic.data__set_cookies__alt_sessions_type === 2 ) {\n\t\t\tapbct_public_sendAJAX(\n\t\t\t\t{\n\t\t\t\t\taction: 'apbct_alt_session__save__AJAX',\n\t\t\t\t\tcookies: cookies,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tapbct_ajax: 1,\n\t\t\t\t\tnotJson: 1,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction apbct_collect_visible_fields( form ) {\n\n\t// Get only fields\n\tvar inputs = [],\n\t\tinputs_visible = '',\n\t\tinputs_visible_count = 0,\n\t\tinputs_invisible = '',\n\t\tinputs_invisible_count = 0,\n\t\tinputs_with_duplicate_names = [];\n\n\tfor(var key in form.elements){\n\t\tif(!isNaN(+key))\n\t\t\tinputs[key] = form.elements[key];\n\t}\n\n\t// Filter fields\n\tinputs = inputs.filter(function(elem){\n\n\t\t// Filter already added fields\n\t\tif( inputs_with_duplicate_names.indexOf( elem.getAttribute('name') ) !== -1 ){\n\t\t\treturn false;\n\t\t}\n\t\t// Filter inputs with same names for type == radio\n\t\tif( -1 !== ['radio', 'checkbox'].indexOf( elem.getAttribute(\"type\") )){\n\t\t\tinputs_with_duplicate_names.push( elem.getAttribute('name') );\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Visible fields\n\tinputs.forEach(function(elem, i, elements){\n\t\t// Unnecessary fields\n\t\tif(\n\t\t\telem.getAttribute(\"type\") === \"submit\" || // type == submit\n\t\t\telem.getAttribute('name') === null ||\n\t\t\telem.getAttribute('name') === 'ct_checkjs'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\t// Invisible fields\n\t\tif(\n\t\t\tgetComputedStyle(elem).display === \"none\" || // hidden\n\t\t\tgetComputedStyle(elem).visibility === \"hidden\" || // hidden\n\t\t\tgetComputedStyle(elem).opacity === \"0\" || // hidden\n\t\t\telem.getAttribute(\"type\") === \"hidden\" // type == hidden\n\t\t) {\n\t\t\tif( elem.classList.contains(\"wp-editor-area\") ) {\n\t\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_visible_count++;\n\t\t\t} else {\n\t\t\t\tinputs_invisible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_invisible_count++;\n\t\t\t}\n\t\t}\n\t\t// Visible fields\n\t\telse {\n\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\tinputs_visible_count++;\n\t\t}\n\n\t});\n\n\tinputs_invisible = inputs_invisible.trim();\n\tinputs_visible = inputs_visible.trim();\n\n\treturn {\n\t\tvisible_fields : inputs_visible,\n\t\tvisible_fields_count : inputs_visible_count,\n\t\tinvisible_fields : inputs_invisible,\n\t\tinvisible_fields_count : inputs_invisible_count,\n\t}\n\n}\n\nfunction apbct_visible_fields_set_cookie( visible_fields_collection ) {\n\n\tvar collection = typeof visible_fields_collection === 'object' && visible_fields_collection !== null ? visible_fields_collection : {};\n\n\tctSetCookie(\"apbct_visible_fields\", JSON.stringify( collection ) );\n\n}\n\nfunction apbct_js_keys__set_input_value(result, data, params, obj){\n\tif( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {\n\t\tvar elements = document.querySelectorAll('[name^=ct_checkjs]');\n\t\tfor ( var i = 0; i < elements.length; i++ ) {\n\t\t\telements[i].value = result.js_key;\n\t\t}\n\t}\n}\n\nfunction apbct_public_sendAJAX(data, params, obj){\n\n\t// Default params\n\tvar callback = params.callback || null;\n\tvar callback_context = params.callback_context || null;\n\tvar callback_params = params.callback_params || null;\n\tvar async = params.async || true;\n\tvar notJson = params.notJson || null;\n\tvar timeout = params.timeout || 15000;\n\tvar obj = obj || null;\n\tvar button = params.button || null;\n\tvar spinner = params.spinner || null;\n\tvar progressbar = params.progressbar || null;\n\tvar silent = params.silent || null;\n\tvar no_nonce = params.no_nonce || null;\n\tvar apbct_ajax = params.apbct_ajax || null;\n\n\tif(typeof (data) === 'string') {\n\t\tif( ! no_nonce )\n\t\t\tdata = data + '&_ajax_nonce=' + ctPublic._ajax_nonce;\n\t\tdata = data + '&no_cache=' + Math.random()\n\t} else {\n\t\tif( ! no_nonce )\n\t\t\tdata._ajax_nonce = ctPublic._ajax_nonce;\n\t\tdata.no_cache = Math.random();\n\t}\n\t// Button and spinner\n\tif(button) {button.setAttribute('disabled', 'disabled'); button.style.cursor = 'not-allowed'; }\n\tif(spinner) jQuery(spinner).css('display', 'inline');\n\n\tjQuery.ajax({\n\t\ttype: \"POST\",\n\t\turl: apbct_ajax ? ctPublic._apbct_ajax_url : ctPublic._ajax_url,\n\t\tdata: data,\n\t\tasync: async,\n\t\tsuccess: function(result){\n\t\t\tif(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n\t\t\tif(spinner) jQuery(spinner).css('display', 'none');\n\t\t\tif(!notJson) result = JSON.parse(result);\n\t\t\tif(result.error){\n\t\t\t\tsetTimeout(function(){ if(progressbar) progressbar.fadeOut('slow'); }, 1000);\n\t\t\t\tconsole.log('Error happens: ' + (result.error || 'Unkown'));\n\t\t\t}else{\n\t\t\t\tif(callback) {\n\t\t\t\t\tif (callback_params)\n\t\t\t\t\t\tcallback.apply( callback_context, callback_params.concat( result, data, params, obj ) );\n\t\t\t\t\telse\n\t\t\t\t\t\tcallback(result, data, params, obj);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\terror: function(jqXHR, textStatus, errorThrown){\n\t\t\tif(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n\t\t\tif(spinner) jQuery(spinner).css('display', 'none');\n\t\t\tif( errorThrown && ! silent ) {\n\t\t\t\tconsole.log('APBCT_AJAX_ERROR');\n\t\t\t\tconsole.log(jqXHR);\n\t\t\t\tconsole.log(textStatus);\n\t\t\t\tconsole.log('Anti-spam by Cleantalk plugin error: ' + errorThrown + 'Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n\t\t\t}\n\t\t},\n\t\ttimeout: timeout,\n\t});\n}\n\nfunction apbct_public_sendREST( route, params ) {\n\n\tvar callback = params.callback || null;\n\tvar data = params.data || [];\n\tvar method = params.method || 'POST';\n\n\tjQuery.ajax({\n\t\ttype: method,\n\t\turl: ctPublic._rest_url + 'cleantalk-antispam/v1/' + route,\n\t\tdata: data,\n\t\tbeforeSend : function ( xhr ) {\n\t\t\txhr.setRequestHeader( 'X-WP-Nonce', ctPublic._rest_nonce );\n\t\t},\n\t\tsuccess: function(result){\n\t\t\tif(result.error){\n\t\t\t\tconsole.log('Error happens: ' + (result.error || 'Unknown'));\n\t\t\t}else{\n\t\t\t\tif(callback) {\n\t\t\t\t\tvar obj = null;\n\t\t\t\t\tcallback(result, route, params, obj);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\terror: function(jqXHR, textStatus, errorThrown){\n\t\t\tif( errorThrown ) {\n\t\t\t\tconsole.log('APBCT_REST_ERROR');\n\t\t\t\tconsole.log(jqXHR);\n\t\t\t\tconsole.log(textStatus);\n\t\t\t\tconsole.log('Anti-spam by Cleantalk plugin REST API error: ' + errorThrown + ' Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n\t\t\t}\n\t\t},\n\t});\n\n}\n\nfunction apbctGetScreenInfo() {\n\treturn JSON.stringify({\n\t\tfullWidth : document.documentElement.scrollWidth,\n\t\tfullHeight : Math.max(\n\t\t\tdocument.body.scrollHeight, document.documentElement.scrollHeight,\n\t\t\tdocument.body.offsetHeight, document.documentElement.offsetHeight,\n\t\t\tdocument.body.clientHeight, document.documentElement.clientHeight\n\t\t),\n\t\tvisibleWidth : document.documentElement.clientWidth,\n\t\tvisibleHeight : document.documentElement.clientHeight,\n\t});\n}\n\nif(typeof jQuery !== 'undefined') {\n\n\t// Capturing responses and output block message for unknown AJAX forms\n\tjQuery(document).ajaxComplete(function (event, xhr, settings) {\n\t\tif (xhr.responseText && xhr.responseText.indexOf('\"apbct') !== -1) {\n\t\t\tvar response = JSON.parse(xhr.responseText);\n\t\t\tif (typeof response.apbct !== 'undefined') {\n\t\t\t\tresponse = response.apbct;\n\t\t\t\tif (response.blocked) {\n\t\t\t\t\tdocument.dispatchEvent(\n\t\t\t\t\t\tnew CustomEvent( \"apbctAjaxBockAlert\", {\n\t\t\t\t\t\t\tbubbles: true,\n\t\t\t\t\t\t\tdetail: { message: response.comment }\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\n\t\t\t\t\t// Show the result by modal\n\t\t\t\t\tcleantalkModal.loaded = response.comment;\n\t\t\t\t\tcleantalkModal.open();\n\n\t\t\t\t\tif(+response.stop_script == 1)\n\t\t\t\t\t\twindow.stop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n}"],"names":["ctSetCookie","cookies","value","expires","skip_alt","ctPublic","data__set_cookies","forEach","item","i","arr","ctSecure","location","protocol","document","cookie","encodeURIComponent","data__set_cookies__alt_sessions_type","apbct_public_sendREST","method","data","apbct_public_sendAJAX","action","apbct_ajax","notJson","apbct_collect_visible_fields","form","inputs","inputs_visible","inputs_visible_count","inputs_invisible","inputs_invisible_count","inputs_with_duplicate_names","key","elements","isNaN","filter","elem","indexOf","getAttribute","push","getComputedStyle","display","visibility","opacity","classList","contains","trim","visible_fields","visible_fields_count","invisible_fields","invisible_fields_count","apbct_visible_fields_set_cookie","visible_fields_collection","collection","JSON","stringify","apbct_js_keys__set_input_value","result","params","obj","querySelectorAll","length","js_key","callback","callback_context","callback_params","async","timeout","button","spinner","progressbar","silent","no_nonce","_ajax_nonce","Math","random","no_cache","setAttribute","style","cursor","jQuery","css","ajax","type","url","_apbct_ajax_url","_ajax_url","success","removeAttribute","parse","error","setTimeout","fadeOut","console","log","apply","concat","jqXHR","textStatus","errorThrown","route","_rest_url","beforeSend","xhr","setRequestHeader","_rest_nonce","apbctGetScreenInfo","fullWidth","documentElement","scrollWidth","fullHeight","max","body","scrollHeight","offsetHeight","clientHeight","visibleWidth","clientWidth","visibleHeight","ct_date","Date","ctTimeMs","getTime","ctMouseEventTimerFlag","ctMouseData","ctMouseDataCounter","ctCheckedEmails","ctScrollCollected","apbct_attach_event_handler","event","window","addEventListener","attachEvent","apbct_remove_event_handler","removeEventListener","detachEvent","floor","getTimezoneOffset","ctFunctionFirstKey","ctMouseReadInterval","setInterval","ctMouseWriteDataInterval","ctFunctionMouseMove","round","clientY","clientX","clearInterval","checkEmail","e","current_email","target","email","timestamp","now","pixel__setting","pixel__url","pixel__enabled","append","data__email_check_before_post","blur","forms","parentElement","toString","id","name","onsubmit_prev","onsubmit","this","Function","call","ajaxComplete","settings","response","responseText","apbct","blocked","dispatchEvent","CustomEvent","bubbles","detail","message","comment","cleantalkModal","loaded","open","stop_script","stop"],"mappings":"AA2KA,SAASA,YAAaC,EAASC,EAAOC,GAErC,IACKC,GADkB,iBAAZH,GAAyC,iBAAVC,GAAuC,iBAAVA,KAClEE,EAAuB,oBAAZH,GAA6C,iBAAZA,EAChDA,EAAU,CAAE,CAAEA,EAASC,EAAOC,KAIK,IAA/BE,SAASC,oBAI4B,IAA/BD,SAASC,kBACnBL,EAAQM,QAAS,SAAUC,EAAMC,EAAGC,GACnC,IAAIP,OAA6B,IAAZK,EAAK,GAAqB,WAAaL,EAAU,KAAO,GACzEQ,EAAiC,WAAtBC,SAASC,SAAwB,WAAa,GAC7DC,SAASC,OAASP,EAAK,GAAK,IAAMQ,mBAAmBR,EAAK,IAAM,KAAOL,EAAU,uBAAyBQ,IAIlE,IAA/BN,SAASC,mBAA6BF,IAGO,IAAlDC,SAASY,qCACbC,sBACC,eACA,CACCC,OAAQ,OACRC,KAAM,CAAEnB,QAASA,KAKyC,IAAlDI,SAASY,sCACnBI,sBACC,CACCC,OAAQ,gCACRrB,QAASA,GAEV,CACCsB,WAAY,EACZC,QAAS,MAOd,SAASC,6BAA8BC,GAGtC,IAAIC,EAAS,GACZC,EAAiB,GACjBC,EAAuB,EACvBC,EAAmB,GACnBC,EAAyB,EACzBC,EAA8B,GAE/B,IAAI,IAAIC,KAAOP,EAAKQ,SACfC,OAAOF,KACVN,EAAOM,GAAOP,EAAKQ,SAASD,IAsD9B,OAlDAN,EAASA,EAAOS,OAAO,SAASC,GAG/B,OAA0E,IAAtEL,EAA4BM,QAASD,EAAKE,aAAa,YAItD,IAAM,CAAC,QAAS,YAAYD,QAASD,EAAKE,aAAa,WAC3DP,EAA4BQ,KAAMH,EAAKE,aAAa,UAC7C,OAMFhC,QAAQ,SAAS8B,EAAM5B,EAAGyB,GAGO,WAAtCG,EAAKE,aAAa,SACoB,OAAtCF,EAAKE,aAAa,SACoB,eAAtCF,EAAKE,aAAa,UAMoB,SAAtCE,iBAAiBJ,GAAMK,SACe,WAAtCD,iBAAiBJ,GAAMM,YACe,MAAtCF,iBAAiBJ,GAAMO,SACe,WAAtCP,EAAKE,aAAa,SAEdF,EAAKQ,UAAUC,SAAS,mBAU5BlB,GAAkB,IAAMS,EAAKE,aAAa,QAC1CV,MAPCC,GAAoB,IAAMO,EAAKE,aAAa,QAC5CR,QAWHD,EAAmBA,EAAiBiB,OAG7B,CACNC,eAHDpB,EAAiBA,EAAemB,OAI/BE,qBAAuBpB,EACvBqB,iBAAmBpB,EACnBqB,uBAAyBpB,GAK3B,SAASqB,gCAAiCC,GAEzC,IAAIC,EAAkD,iBAA9BD,GAAwE,OAA9BA,EAAsCA,EAA4B,GAEpIrD,YAAY,uBAAwBuD,KAAKC,UAAWF,IAIrD,SAASG,+BAA+BC,EAAQtC,EAAMuC,EAAQC,GAC7D,GAA6D,EAAzD9C,SAAS+C,iBAAiB,sBAAsBC,OAEnD,IADA,IAAI5B,EAAWpB,SAAS+C,iBAAiB,sBAC/BpD,EAAI,EAAGA,EAAIyB,EAAS4B,OAAQrD,IACrCyB,EAASzB,GAAGP,MAAQwD,EAAOK,OAK9B,SAAS1C,sBAAsBD,EAAMuC,EAAQC,GAG5C,IAAII,EAAcL,EAAOK,UAAe,KACpCC,EAAmBN,EAAOM,kBAAoB,KAC9CC,EAAkBP,EAAOO,iBAAmB,KAC5CC,EAAQR,EAAOQ,QAAS,EACxB3C,EAAcmC,EAAOnC,SAAe,KACpC4C,EAAcT,EAAOS,SAAe,KACpCR,EAAcA,GAAsB,KACpCS,EAAcV,EAAOU,QAAe,KACpCC,EAAcX,EAAOW,SAAe,KACpCC,EAAcZ,EAAOY,aAAe,KACpCC,EAAcb,EAAOa,QAAe,KACpCC,EAAcd,EAAOc,UAAe,KACpClD,EAAcoC,EAAOpC,YAAe,KAEnB,iBAAX,GACHkD,IACLrD,EAAOA,EAAO,gBAAkBf,SAASqE,aAC1CtD,EAAOA,EAAO,aAAeuD,KAAKC,WAE5BH,IACLrD,EAAKsD,YAAcrE,SAASqE,aAC7BtD,EAAKyD,SAAWF,KAAKC,UAGnBP,IAAUA,EAAOS,aAAa,WAAY,YAAaT,EAAOU,MAAMC,OAAS,eAC7EV,GAASW,OAAOX,GAASY,IAAI,UAAW,UAE3CD,OAAOE,KAAK,CACXC,KAAM,OACNC,IAAK9D,EAAalB,SAASiF,gBAAkBjF,SAASkF,UACtDnE,KAAMA,EACN+C,MAAOA,EACPqB,QAAS,SAAS9B,GACdW,IAAUA,EAAOoB,gBAAgB,YAAapB,EAAOU,MAAMC,OAAS,WACpEV,GAAUW,OAAOX,GAASY,IAAI,UAAW,QACxC1D,IAASkC,EAASH,KAAKmC,MAAMhC,IAC9BA,EAAOiC,OACTC,WAAW,WAAerB,GAAaA,EAAYsB,QAAQ,SAAY,KACvEC,QAAQC,IAAI,mBAAqBrC,EAAOiC,OAAS,YAE9C3B,IACEE,EACHF,EAASgC,MAAO/B,EAAkBC,EAAgB+B,OAAQvC,EAAQtC,EAAMuC,EAAQC,IAEhFI,EAASN,EAAQtC,EAAMuC,EAAQC,KAInC+B,MAAO,SAASO,EAAOC,EAAYC,GAC/B/B,IAAUA,EAAOoB,gBAAgB,YAAapB,EAAOU,MAAMC,OAAS,WACpEV,GAASW,OAAOX,GAASY,IAAI,UAAW,QACvCkB,IAAiB5B,IACpBsB,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,wCAA0CK,EAAc,yGAGtEhC,QAASA,IAIX,SAASlD,sBAAuBmF,EAAO1C,GAEtC,IAAIK,EAAWL,EAAOK,UAAY,KAC9B5C,EAAWuC,EAAOvC,MAAQ,GAC1BD,EAAWwC,EAAOxC,QAAU,OAEhC8D,OAAOE,KAAK,CACXC,KAAMjE,EACNkE,IAAKhF,SAASiG,UAAY,yBAA2BD,EACrDjF,KAAMA,EACNmF,WAAa,SAAWC,GACvBA,EAAIC,iBAAkB,aAAcpG,SAASqG,cAE9ClB,QAAS,SAAS9B,GACdA,EAAOiC,MACTG,QAAQC,IAAI,mBAAqBrC,EAAOiC,OAAS,YAE9C3B,GAEFA,EAASN,EAAQ2C,EAAO1C,EADd,OAKbgC,MAAO,SAASO,EAAOC,EAAYC,GAC9BA,IACHN,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,iDAAmDK,EAAc,4GAOjF,SAASO,qBACR,OAAOpD,KAAKC,UAAU,CACrBoD,UAAY9F,SAAS+F,gBAAgBC,YACrCC,WAAapC,KAAKqC,IACjBlG,SAASmG,KAAKC,aAAcpG,SAAS+F,gBAAgBK,aACrDpG,SAASmG,KAAKE,aAAcrG,SAAS+F,gBAAgBM,aACrDrG,SAASmG,KAAKG,aAActG,SAAS+F,gBAAgBO,cAEtDC,aAAevG,SAAS+F,gBAAgBS,YACxCC,cAAgBzG,SAAS+F,gBAAgBO,gBApa1C,WAEA,IAAII,EAAU,IAAIC,KACjBC,GAAW,IAAID,MAAOE,UACtBC,GAAwB,EACxBC,EAAc,GACdC,EAAqB,EACrBC,EAAkB,GAClBC,GAAoB,EAErB,SAASC,EAA2B5F,EAAM6F,EAAOlE,GACV,mBAA5BmE,OAAOC,iBAAiC/F,EAAK+F,iBAAiBF,EAAOlE,GAC7B3B,EAAKgG,YAAYH,EAAOlE,GAG3E,SAASsE,EAA2BjG,EAAM6F,EAAOlE,GACP,mBAA/BmE,OAAOI,oBAAoClG,EAAKkG,oBAAoBL,EAAOlE,GAChC3B,EAAKmG,YAAYN,EAAOlE,GAG9EhE,YACC,CACC,CAAE,kBAAmB2E,KAAK8D,OAAM,IAAIhB,MAAOE,UAAY,MACvD,CAAE,mBAAoB,KACtB,CAAE,kBAAmB,KACrB,CAAE,cAAeH,EAAQkB,oBAAoB,IAAK,GAClD,CAAE,uBAAwB,OAK5B,IAAIC,EAAqB,WAExB3I,YAAY,mBADO2E,KAAK8D,OAAM,IAAIhB,MAAOE,UAAU,MA0CnDW,EAA2BH,OAAQ,YAAaQ,GAChDL,EAA2BH,OAAQ,UAAWQ,IArC3CC,EAAsBC,YAAY,WACrCjB,GAAwB,GACtB,KAGCkB,EAA2BD,YAAY,WAC1C7I,YAAY,kBAAmBuD,KAAKC,UAAUqE,KAC5C,MAGCkB,EAAsB,SAAgBb,IACZ,IAA1BN,IAEFC,EAAYrF,KAAK,CAChBmC,KAAKqE,MAAMd,EAAMe,SACjBtE,KAAKqE,MAAMd,EAAMgB,SACjBvE,KAAKqE,OAAM,IAAIvB,MAAOE,UAAYD,KAInCE,GAAwB,EACC,MAFzBE,IAUDQ,EAA2BH,OAAQ,YAAaY,GAChDI,cAAcP,GACdO,cAAcL,MASf,SAASM,EAAWC,GACnB,IAAIC,EAAgBD,EAAEE,OAAOrJ,OACzBoJ,GAAmBA,KAAiBvB,GACvC1G,sBACC,CAACC,OAAQ,gCAAiCF,KAAO,CAACoI,MAAUF,IAC5D,CACC/H,WAAY,EACZyC,SAAU,SAAUN,GACfA,EAAOA,SACVqE,EAAgBuB,GAAiB,CAAC5F,OAAWA,EAAOA,OAAQ+F,UAAahC,KAAKiC,MAAQ,IAAM,GAC5F1J,YAAY,oBAAqBuD,KAAKC,UAAUuE,QAetDE,EAA2BE,OAAQ,YAAaY,GAChDd,EAA2BE,OAAQ,YAAaQ,GAChDV,EAA2BE,OAAQ,UAAWQ,GAC9CV,EAA2BE,OAAQ,SAVnC,WACOH,IACLhI,YAAY,kBAAmBuD,KAAKC,WAAW,IAC/CwE,GAAoB,KAoEtBC,EAA2BE,OAAQ,mBA1DnC,YAEM9H,SAASsJ,iBACb3J,YAAa,kBAAmBK,SAASuJ,aACpCvJ,SAASwJ,gBACb5E,OAAO,QAAQ6E,OAAQ,mDAAqDzJ,SAASuJ,WAAa,QAI9FvJ,SAAS0J,gCACd/J,YAAa,oBAAqB,KAClCiF,OAAO,iCAAiC+E,KAAKZ,IAI9CpJ,YAAa,iBAAkB2G,sBAC/B3G,YAAY,kBAAmBuD,KAAKC,WAAW,IAE/CoC,WAAW,WAIV,IAFA,IAAIvC,EAA4B,GAExB5C,EAAI,EAAGA,EAAIK,SAASmJ,MAAMnG,OAAQrD,IAAI,CAC7C,IAAIiB,EAAOZ,SAASmJ,MAAMxJ,GAIzBiB,EAAKmB,UAAUC,SAAS,oBACxBpB,EAAKwI,cAAcrH,UAAUC,SAAS,iBACkB,IAAxDpB,EAAKJ,OAAO6I,WAAW7H,QAAQ,qBAC9BZ,EAAK0I,IAAiB,cAAX1I,EAAK0I,IAChB1I,EAAK2I,KAAKxH,WAAanB,EAAK2I,KAAKxH,UAAUC,SAAS,kBACpDpB,EAAK2I,KAAKxH,WAAanB,EAAK2I,KAAKxH,UAAUC,SAAS,gBAItDO,EAA0B5C,GAAKgB,6BAA8BC,GAE7DA,EAAK4I,cAAgB5I,EAAK6I,SAC1B7I,EAAK6I,SAAW,SAAUrC,GAEzB,IAAIlF,EAAiB,GACrBA,EAAe,GAAKvB,6BAA6B+I,MACjDpH,gCAAiCJ,GAG7BkF,EAAMqB,OAAOe,yBAAyBG,UACzC7E,WAAW,WACVsC,EAAMqB,OAAOe,cAAcI,KAAKxC,EAAMqB,OAAQrB,IAC5C,OAKN9E,gCAAiCC,IAE/B,OArKL,GAwaqB,oBAAX4B,QAGTA,OAAOnE,UAAU6J,aAAa,SAAUzC,EAAO1B,EAAKoE,GACnD,IACKC,GADDrE,EAAIsE,eAAwD,IAAxCtE,EAAIsE,aAAaxI,QAAQ,gBAElB,KAD1BuI,EAAWtH,KAAKmC,MAAMc,EAAIsE,eACVC,QACnBF,EAAWA,EAASE,OACPC,UACZlK,SAASmK,cACR,IAAIC,YAAa,qBAAsB,CACtCC,SAAS,EACTC,OAAQ,CAAEC,QAASR,EAASS,YAK9BC,eAAeC,OAASX,EAASS,QACjCC,eAAeE,OAEa,IAAxBZ,EAASa,aACZvD,OAAOwD"}
1
+ {"version":3,"file":"apbct-public.min.js","sources":["apbct-public.js"],"sourcesContent":["(function() {\n\n\tvar ct_date = new Date(),\n\t\tctTimeMs = new Date().getTime(),\n\t\tctMouseEventTimerFlag = true, //Reading interval flag\n\t\tctMouseData = [],\n\t\tctMouseDataCounter = 0,\n\t\tctCheckedEmails = {},\n\t\tctScrollCollected = false;\n\n\tfunction apbct_attach_event_handler(elem, event, callback){\n\t\tif(typeof window.addEventListener === \"function\") elem.addEventListener(event, callback);\n\t\telse elem.attachEvent(event, callback);\n\t}\n\n\tfunction apbct_remove_event_handler(elem, event, callback){\n\t\tif(typeof window.removeEventListener === \"function\") elem.removeEventListener(event, callback);\n\t\telse elem.detachEvent(event, callback);\n\t}\n\n\tctSetCookie(\n\t\t[\n\t\t\t[ \"ct_ps_timestamp\", Math.floor(new Date().getTime() / 1000) ],\n\t\t\t[ \"ct_fkp_timestamp\", \"0\" ],\n\t\t\t[ \"ct_pointer_data\", \"0\" ],\n\t\t\t[ \"ct_timezone\", ct_date.getTimezoneOffset()/60*(-1) ],\n\t\t\t[ \"apbct_visible_fields\", \"0\" ],\n\t\t]\n\t);\n\n\t//Writing first key press timestamp\n\tvar ctFunctionFirstKey = function output(event){\n\t\tvar KeyTimestamp = Math.floor(new Date().getTime()/1000);\n\t\tctSetCookie(\"ct_fkp_timestamp\", KeyTimestamp);\n\t\tctKeyStopStopListening();\n\t};\n\n\t//Reading interval\n\tvar ctMouseReadInterval = setInterval(function(){\n\t\tctMouseEventTimerFlag = true;\n\t}, 150);\n\n\t//Writting interval\n\tvar ctMouseWriteDataInterval = setInterval(function(){\n\t\tctSetCookie(\"ct_pointer_data\", JSON.stringify(ctMouseData));\n\t}, 1200);\n\n\t//Logging mouse position each 150 ms\n\tvar ctFunctionMouseMove = function output(event){\n\t\tif(ctMouseEventTimerFlag === true){\n\n\t\t\tctMouseData.push([\n\t\t\t\tMath.round(event.clientY),\n\t\t\t\tMath.round(event.clientX),\n\t\t\t\tMath.round(new Date().getTime() - ctTimeMs)\n\t\t\t]);\n\n\t\t\tctMouseDataCounter++;\n\t\t\tctMouseEventTimerFlag = false;\n\t\t\tif(ctMouseDataCounter >= 50){\n\t\t\t\tctMouseStopData();\n\t\t\t}\n\t\t}\n\t};\n\n\t//Stop mouse observing function\n\tfunction ctMouseStopData(){\n\t\tapbct_remove_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\t\tclearInterval(ctMouseReadInterval);\n\t\tclearInterval(ctMouseWriteDataInterval);\n\t}\n\n\t//Stop key listening function\n\tfunction ctKeyStopStopListening(){\n\t\tapbct_remove_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\t\tapbct_remove_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\t}\n\n\tfunction checkEmail(e) {\n\t\tvar current_email = e.target.value;\n\t\tif (current_email && !(current_email in ctCheckedEmails)) {\n\t\t\tapbct_public_sendAJAX(\n\t\t\t\t{action: 'apbct_email_check_before_post', data : {'email' : current_email}},\n\t\t\t\t{\n\t\t\t\t\tapbct_ajax: 1,\n\t\t\t\t\tcallback: function (result) {\n\t\t\t\t\t\tif (result.result) {\n\t\t\t\t\t\t\tctCheckedEmails[current_email] = {'result' : result.result, 'timestamp': Date.now() / 1000 |0};\n\t\t\t\t\t\t\tctSetCookie('ct_checked_emails', JSON.stringify(ctCheckedEmails));\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\t\t\n\t\t}\n\t}\n\n\tfunction ctSetHasScrolled() {\n\t\tif( ! ctScrollCollected ) {\n\t\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( true ) );\n\t\t\tctScrollCollected = true;\n\t\t}\n\t}\n\n\tapbct_attach_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\tapbct_attach_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"scroll\", ctSetHasScrolled);\n\n\t// Ready function\n\tfunction apbct_ready(){\n\n\t\tif( +ctPublic.pixel__setting ){\n\t\t\tctSetCookie( 'apbct_pixel_url', ctPublic.pixel__url );\n\t\t\tif( +ctPublic.pixel__enabled ){\n\t\t\t\tjQuery('body').append( '<img style=\"display: none; left: 99999px;\" src=\"' + ctPublic.pixel__url + '\">' );\n\t\t\t}\n\t\t}\n\n\t\tif ( +ctPublic.data__email_check_before_post) {\n\t\t\tctSetCookie( 'ct_checked_emails', '0');\n\t\t\tjQuery(\"input[type = 'email'], #email\").blur(checkEmail);\n\t\t}\n\n\t\t// Collect scrolling info\n\t\tctSetCookie( 'ct_screen_info', apbctGetScreenInfo() );\n\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( false ) );\n\n\t\tsetTimeout(function(){\n\n\t\t\tvar visible_fields_collection = {};\n\n\t\t\tfor(var i = 0; i < document.forms.length; i++){\n\t\t\t\tvar form = document.forms[i];\n\n\t\t\t\t//Exclusion for forms\n\t\t\t\tif (\n\t\t\t\t\tform.classList.contains('slp_search_form') || //StoreLocatorPlus form\n\t\t\t\t\tform.parentElement.classList.contains('mec-booking') ||\n\t\t\t\t\tform.action.toString().indexOf('activehosted.com') !== -1 || // Active Campaign\n\t\t\t\t\t(form.id && form.id == 'caspioform') || //Caspio Form\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('tinkoffPayRow')) || // TinkoffPayForm\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('give-form')) // GiveWP\n\t\t\t\t)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tvisible_fields_collection[i] = apbct_collect_visible_fields( form );\n\n\t\t\t\tform.onsubmit_prev = form.onsubmit;\n\t\t\t\tform.onsubmit = function (event) {\n\n\t\t\t\t\tvar visible_fields = {};\n\t\t\t\t\tvisible_fields[0] = apbct_collect_visible_fields(this);\n\t\t\t\t\tapbct_visible_fields_set_cookie( visible_fields );\n\n\t\t\t\t\t// Call previous submit action\n\t\t\t\t\tif (event.target.onsubmit_prev instanceof Function) {\n\t\t\t\t\t\tsetTimeout(function () {\n\t\t\t\t\t\t\tevent.target.onsubmit_prev.call(event.target, event);\n\t\t\t\t\t\t}, 500);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tapbct_visible_fields_set_cookie( visible_fields_collection );\n\n\t\t}, 1000);\n\t}\n\tapbct_attach_event_handler(window, \"DOMContentLoaded\", apbct_ready);\n\n}());\n\nfunction ctSetCookie( cookies, value, expires ){\n\n\tif( typeof cookies === 'string' && typeof value === 'string' || typeof value === 'number'){\n\t\tvar skip_alt = cookies === 'ct_pointer_data' || cookies === 'ct_user_info';\n\t\tcookies = [ [ cookies, value, expires ] ];\n\t}\n\n\t// Cookies disabled\n\tif( +ctPublic.data__set_cookies === 0 ){\n\t\treturn;\n\n\t// Using traditional cookies\n\t}else if( +ctPublic.data__set_cookies === 1 ){\n\t\tcookies.forEach( function (item, i, arr\t) {\n\t\t\tvar expires = typeof item[2] !== 'undefined' ? \"expires=\" + expires + '; ' : '';\n\t\t\tvar ctSecure = location.protocol === 'https:' ? '; secure' : '';\n\t\t\tdocument.cookie = item[0] + \"=\" + encodeURIComponent(item[1]) + \"; \" + expires + \"path=/; samesite=lax\" + ctSecure;\n\t\t});\n\n\t// Using alternative cookies\n\t}else if( +ctPublic.data__set_cookies === 2 && ! skip_alt ){\n\n\t\t// Using REST API handler\n\t\tif( +ctPublic.data__set_cookies__alt_sessions_type === 1 ){\n\t\t\tapbct_public_sendREST(\n\t\t\t\t'alt_sessions',\n\t\t\t\t{\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: { cookies: cookies }\n\t\t\t\t}\n\t\t\t);\n\n\t\t// Using AJAX request and handler\n\t\t}else if( +ctPublic.data__set_cookies__alt_sessions_type === 2 ) {\n\t\t\tapbct_public_sendAJAX(\n\t\t\t\t{\n\t\t\t\t\taction: 'apbct_alt_session__save__AJAX',\n\t\t\t\t\tcookies: cookies,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tapbct_ajax: 1,\n\t\t\t\t\tnotJson: 1,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction apbct_collect_visible_fields( form ) {\n\n\t// Get only fields\n\tvar inputs = [],\n\t\tinputs_visible = '',\n\t\tinputs_visible_count = 0,\n\t\tinputs_invisible = '',\n\t\tinputs_invisible_count = 0,\n\t\tinputs_with_duplicate_names = [];\n\n\tfor(var key in form.elements){\n\t\tif(!isNaN(+key))\n\t\t\tinputs[key] = form.elements[key];\n\t}\n\n\t// Filter fields\n\tinputs = inputs.filter(function(elem){\n\n\t\t// Filter already added fields\n\t\tif( inputs_with_duplicate_names.indexOf( elem.getAttribute('name') ) !== -1 ){\n\t\t\treturn false;\n\t\t}\n\t\t// Filter inputs with same names for type == radio\n\t\tif( -1 !== ['radio', 'checkbox'].indexOf( elem.getAttribute(\"type\") )){\n\t\t\tinputs_with_duplicate_names.push( elem.getAttribute('name') );\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Visible fields\n\tinputs.forEach(function(elem, i, elements){\n\t\t// Unnecessary fields\n\t\tif(\n\t\t\telem.getAttribute(\"type\") === \"submit\" || // type == submit\n\t\t\telem.getAttribute('name') === null ||\n\t\t\telem.getAttribute('name') === 'ct_checkjs'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\t// Invisible fields\n\t\tif(\n\t\t\tgetComputedStyle(elem).display === \"none\" || // hidden\n\t\t\tgetComputedStyle(elem).visibility === \"hidden\" || // hidden\n\t\t\tgetComputedStyle(elem).opacity === \"0\" || // hidden\n\t\t\telem.getAttribute(\"type\") === \"hidden\" // type == hidden\n\t\t) {\n\t\t\tif( elem.classList.contains(\"wp-editor-area\") ) {\n\t\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_visible_count++;\n\t\t\t} else {\n\t\t\t\tinputs_invisible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_invisible_count++;\n\t\t\t}\n\t\t}\n\t\t// Visible fields\n\t\telse {\n\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\tinputs_visible_count++;\n\t\t}\n\n\t});\n\n\tinputs_invisible = inputs_invisible.trim();\n\tinputs_visible = inputs_visible.trim();\n\n\treturn {\n\t\tvisible_fields : inputs_visible,\n\t\tvisible_fields_count : inputs_visible_count,\n\t\tinvisible_fields : inputs_invisible,\n\t\tinvisible_fields_count : inputs_invisible_count,\n\t}\n\n}\n\nfunction apbct_visible_fields_set_cookie( visible_fields_collection ) {\n\n\tvar collection = typeof visible_fields_collection === 'object' && visible_fields_collection !== null ? visible_fields_collection : {};\n\n\tctSetCookie(\"apbct_visible_fields\", JSON.stringify( collection ) );\n\n}\n\nfunction apbct_js_keys__set_input_value(result, data, params, obj){\n\tif( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {\n\t\tvar elements = document.querySelectorAll('[name^=ct_checkjs]');\n\t\tfor ( var i = 0; i < elements.length; i++ ) {\n\t\t\telements[i].value = result.js_key;\n\t\t}\n\t}\n}\n\nfunction apbct_public_sendAJAX(data, params, obj){\n\n\t// Default params\n\tvar callback = params.callback || null;\n\tvar callback_context = params.callback_context || null;\n\tvar callback_params = params.callback_params || null;\n\tvar async = params.async || true;\n\tvar notJson = params.notJson || null;\n\tvar timeout = params.timeout || 15000;\n\tvar obj = obj || null;\n\tvar button = params.button || null;\n\tvar spinner = params.spinner || null;\n\tvar progressbar = params.progressbar || null;\n\tvar silent = params.silent || null;\n\tvar no_nonce = params.no_nonce || null;\n\tvar apbct_ajax = params.apbct_ajax || null;\n\n\tif(typeof (data) === 'string') {\n\t\tif( ! no_nonce )\n\t\t\tdata = data + '&_ajax_nonce=' + ctPublic._ajax_nonce;\n\t\tdata = data + '&no_cache=' + Math.random()\n\t} else {\n\t\tif( ! no_nonce )\n\t\t\tdata._ajax_nonce = ctPublic._ajax_nonce;\n\t\tdata.no_cache = Math.random();\n\t}\n\t// Button and spinner\n\tif(button) {button.setAttribute('disabled', 'disabled'); button.style.cursor = 'not-allowed'; }\n\tif(spinner) jQuery(spinner).css('display', 'inline');\n\n\tjQuery.ajax({\n\t\ttype: \"POST\",\n\t\turl: apbct_ajax ? ctPublic._apbct_ajax_url : ctPublic._ajax_url,\n\t\tdata: data,\n\t\tasync: async,\n\t\tsuccess: function(result){\n\t\t\tif(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n\t\t\tif(spinner) jQuery(spinner).css('display', 'none');\n\t\t\tif(!notJson) result = JSON.parse(result);\n\t\t\tif(result.error){\n\t\t\t\tsetTimeout(function(){ if(progressbar) progressbar.fadeOut('slow'); }, 1000);\n\t\t\t\tconsole.log('Error happens: ' + (result.error || 'Unkown'));\n\t\t\t}else{\n\t\t\t\tif(callback) {\n\t\t\t\t\tif (callback_params)\n\t\t\t\t\t\tcallback.apply( callback_context, callback_params.concat( result, data, params, obj ) );\n\t\t\t\t\telse\n\t\t\t\t\t\tcallback(result, data, params, obj);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\terror: function(jqXHR, textStatus, errorThrown){\n\t\t\tif(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n\t\t\tif(spinner) jQuery(spinner).css('display', 'none');\n\t\t\tif( errorThrown && ! silent ) {\n\t\t\t\tconsole.log('APBCT_AJAX_ERROR');\n\t\t\t\tconsole.log(jqXHR);\n\t\t\t\tconsole.log(textStatus);\n\t\t\t\tconsole.log('Anti-spam by Cleantalk plugin error: ' + errorThrown + 'Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n\t\t\t}\n\t\t},\n\t\ttimeout: timeout,\n\t});\n}\n\nfunction apbct_public_sendREST( route, params ) {\n\n\tvar callback = params.callback || null;\n\tvar data = params.data || [];\n\tvar method = params.method || 'POST';\n\n\tjQuery.ajax({\n\t\ttype: method,\n\t\turl: ctPublic._rest_url + 'cleantalk-antispam/v1/' + route,\n\t\tdata: data,\n\t\tbeforeSend : function ( xhr ) {\n\t\t\txhr.setRequestHeader( 'X-WP-Nonce', ctPublic._rest_nonce );\n\t\t},\n\t\tsuccess: function(result){\n\t\t\tif(result.error){\n\t\t\t\tconsole.log('Error happens: ' + (result.error || 'Unknown'));\n\t\t\t}else{\n\t\t\t\tif(callback) {\n\t\t\t\t\tvar obj = null;\n\t\t\t\t\tcallback(result, route, params, obj);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\terror: function(jqXHR, textStatus, errorThrown){\n\t\t\tif( errorThrown ) {\n\t\t\t\tconsole.log('APBCT_REST_ERROR');\n\t\t\t\tconsole.log(jqXHR);\n\t\t\t\tconsole.log(textStatus);\n\t\t\t\tconsole.log('Anti-spam by Cleantalk plugin REST API error: ' + errorThrown + ' Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n\t\t\t}\n\t\t},\n\t});\n\n}\n\nfunction apbctGetScreenInfo() {\n\treturn JSON.stringify({\n\t\tfullWidth : document.documentElement.scrollWidth,\n\t\tfullHeight : Math.max(\n\t\t\tdocument.body.scrollHeight, document.documentElement.scrollHeight,\n\t\t\tdocument.body.offsetHeight, document.documentElement.offsetHeight,\n\t\t\tdocument.body.clientHeight, document.documentElement.clientHeight\n\t\t),\n\t\tvisibleWidth : document.documentElement.clientWidth,\n\t\tvisibleHeight : document.documentElement.clientHeight,\n\t});\n}\n\nif(typeof jQuery !== 'undefined') {\n\n\t// Capturing responses and output block message for unknown AJAX forms\n\tjQuery(document).ajaxComplete(function (event, xhr, settings) {\n\t\tif (xhr.responseText && xhr.responseText.indexOf('\"apbct') !== -1) {\n\t\t\tvar response = JSON.parse(xhr.responseText);\n\t\t\tif (typeof response.apbct !== 'undefined') {\n\t\t\t\tresponse = response.apbct;\n\t\t\t\tif (response.blocked) {\n\t\t\t\t\tdocument.dispatchEvent(\n\t\t\t\t\t\tnew CustomEvent( \"apbctAjaxBockAlert\", {\n\t\t\t\t\t\t\tbubbles: true,\n\t\t\t\t\t\t\tdetail: { message: response.comment }\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\n\t\t\t\t\t// Show the result by modal\n\t\t\t\t\tcleantalkModal.loaded = response.comment;\n\t\t\t\t\tcleantalkModal.open();\n\n\t\t\t\t\tif(+response.stop_script == 1)\n\t\t\t\t\t\twindow.stop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n}"],"names":["ctSetCookie","cookies","value","expires","skip_alt","ctPublic","data__set_cookies","forEach","item","i","arr","ctSecure","location","protocol","document","cookie","encodeURIComponent","data__set_cookies__alt_sessions_type","apbct_public_sendREST","method","data","apbct_public_sendAJAX","action","apbct_ajax","notJson","apbct_collect_visible_fields","form","key","inputs","inputs_visible","inputs_visible_count","inputs_invisible","inputs_invisible_count","inputs_with_duplicate_names","elements","isNaN","filter","elem","indexOf","getAttribute","push","getComputedStyle","display","visibility","opacity","classList","contains","trim","visible_fields","visible_fields_count","invisible_fields","invisible_fields_count","apbct_visible_fields_set_cookie","visible_fields_collection","collection","JSON","stringify","apbct_js_keys__set_input_value","result","params","obj","querySelectorAll","length","js_key","callback","callback_context","callback_params","async","timeout","button","spinner","progressbar","silent","no_nonce","_ajax_nonce","Math","random","no_cache","setAttribute","style","cursor","jQuery","css","ajax","type","url","_apbct_ajax_url","_ajax_url","success","removeAttribute","parse","error","setTimeout","fadeOut","console","log","apply","concat","jqXHR","textStatus","errorThrown","route","_rest_url","beforeSend","xhr","setRequestHeader","_rest_nonce","apbctGetScreenInfo","fullWidth","documentElement","scrollWidth","fullHeight","max","body","scrollHeight","offsetHeight","clientHeight","visibleWidth","clientWidth","visibleHeight","ct_date","Date","ctTimeMs","getTime","ctMouseEventTimerFlag","ctMouseData","ctMouseDataCounter","ctCheckedEmails","ctScrollCollected","apbct_attach_event_handler","event","window","addEventListener","attachEvent","apbct_remove_event_handler","removeEventListener","detachEvent","floor","getTimezoneOffset","ctFunctionFirstKey","ctMouseReadInterval","setInterval","ctMouseWriteDataInterval","ctFunctionMouseMove","round","clientY","clientX","clearInterval","checkEmail","e","current_email","target","email","timestamp","now","pixel__setting","pixel__url","pixel__enabled","append","data__email_check_before_post","blur","forms","parentElement","toString","id","name","onsubmit_prev","onsubmit","this","Function","call","ajaxComplete","settings","responseText","response","apbct","blocked","dispatchEvent","CustomEvent","bubbles","detail","message","comment","cleantalkModal","loaded","open","stop_script","stop"],"mappings":"AA2KA,SAASA,YAAaC,EAASC,EAAOC,GAErC,IACKC,GADkB,iBAAZH,GAAyC,iBAAVC,GAAuC,iBAAVA,KAClEE,EAAuB,oBAAZH,GAA6C,iBAAZA,EAChDA,EAAU,CAAE,CAAEA,EAASC,EAAOC,KAIK,IAA/BE,SAASC,oBAI4B,IAA/BD,SAASC,kBACnBL,EAAQM,QAAS,SAAUC,EAAMC,EAAGC,GACnC,IAAIP,OAA6B,IAAZK,EAAK,GAAqB,WAAaL,EAAU,KAAO,GACzEQ,EAAiC,WAAtBC,SAASC,SAAwB,WAAa,GAC7DC,SAASC,OAASP,EAAK,GAAK,IAAMQ,mBAAmBR,EAAK,IAAM,KAAOL,EAAU,uBAAyBQ,IAIlE,IAA/BN,SAASC,mBAA6BF,IAGO,IAAlDC,SAASY,qCACbC,sBACC,eACA,CACCC,OAAQ,OACRC,KAAM,CAAEnB,QAASA,KAKyC,IAAlDI,SAASY,sCACnBI,sBACC,CACCC,OAAQ,gCACRrB,QAASA,GAEV,CACCsB,WAAY,EACZC,QAAS,MAOd,SAASC,6BAA8BC,GAGtC,IAOQC,EAPJC,EAAS,GACZC,EAAiB,GACjBC,EAAuB,EACvBC,EAAmB,GACnBC,EAAyB,EACzBC,EAA8B,GAE/B,IAAQN,KAAOD,EAAKQ,SACfC,OAAOR,KACVC,EAAOD,GAAOD,EAAKQ,SAASP,IAsD9B,OAlDAC,EAASA,EAAOQ,OAAO,SAASC,GAG/B,OAA0E,IAAtEJ,EAA4BK,QAASD,EAAKE,aAAa,YAItD,IAAM,CAAC,QAAS,YAAYD,QAASD,EAAKE,aAAa,WAC3DN,EAA4BO,KAAMH,EAAKE,aAAa,UAC7C,OAMFhC,QAAQ,SAAS8B,EAAM5B,EAAGyB,GAGO,WAAtCG,EAAKE,aAAa,SACoB,OAAtCF,EAAKE,aAAa,SACoB,eAAtCF,EAAKE,aAAa,UAMoB,SAAtCE,iBAAiBJ,GAAMK,SACe,WAAtCD,iBAAiBJ,GAAMM,YACe,MAAtCF,iBAAiBJ,GAAMO,SACe,WAAtCP,EAAKE,aAAa,SAEdF,EAAKQ,UAAUC,SAAS,mBAU5BjB,GAAkB,IAAMQ,EAAKE,aAAa,QAC1CT,MAPCC,GAAoB,IAAMM,EAAKE,aAAa,QAC5CP,QAWHD,EAAmBA,EAAiBgB,OAG7B,CACNC,eAHDnB,EAAiBA,EAAekB,OAI/BE,qBAAuBnB,EACvBoB,iBAAmBnB,EACnBoB,uBAAyBnB,GAK3B,SAASoB,gCAAiCC,GAErCC,EAAkD,iBAA9BD,GAAwE,OAA9BA,EAAsCA,EAA4B,GAEpIrD,YAAY,uBAAwBuD,KAAKC,UAAWF,IAIrD,SAASG,+BAA+BC,EAAQtC,EAAMuC,EAAQC,GAC7D,GAA6D,EAAzD9C,SAAS+C,iBAAiB,sBAAsBC,OAEnD,IADA,IAAI5B,EAAWpB,SAAS+C,iBAAiB,sBAC/BpD,EAAI,EAAGA,EAAIyB,EAAS4B,OAAQrD,IACrCyB,EAASzB,GAAGP,MAAQwD,EAAOK,OAK9B,SAAS1C,sBAAsBD,EAAMuC,EAAQC,GAG5C,IAAII,EAAcL,EAAOK,UAAe,KACpCC,EAAmBN,EAAOM,kBAAoB,KAC9CC,EAAkBP,EAAOO,iBAAmB,KAC5CC,EAAQR,EAAOQ,QAAS,EACxB3C,EAAcmC,EAAOnC,SAAe,KACpC4C,EAAcT,EAAOS,SAAe,KACpCR,EAAcA,GAAsB,KACpCS,EAAcV,EAAOU,QAAe,KACpCC,EAAcX,EAAOW,SAAe,KACpCC,EAAcZ,EAAOY,aAAe,KACpCC,EAAcb,EAAOa,QAAe,KACpCC,EAAcd,EAAOc,UAAe,KACpClD,EAAcoC,EAAOpC,YAAe,KAEnB,iBAAX,EAGTH,GADCA,GADKqD,EACErD,EAAO,gBAAkBf,SAASqE,YACnCtD,GAAO,aAAeuD,KAAKC,UAE5BH,IACLrD,EAAKsD,YAAcrE,SAASqE,aAC7BtD,EAAKyD,SAAWF,KAAKC,UAGnBP,IAAUA,EAAOS,aAAa,WAAY,YAAaT,EAAOU,MAAMC,OAAS,eAC7EV,GAASW,OAAOX,GAASY,IAAI,UAAW,UAE3CD,OAAOE,KAAK,CACXC,KAAM,OACNC,IAAK9D,EAAalB,SAASiF,gBAAkBjF,SAASkF,UACtDnE,KAAMA,EACN+C,MAAOA,EACPqB,QAAS,SAAS9B,GACdW,IAAUA,EAAOoB,gBAAgB,YAAapB,EAAOU,MAAMC,OAAS,WACpEV,GAAUW,OAAOX,GAASY,IAAI,UAAW,SAC/BxB,GAATlC,EAAkB+B,KAAKmC,MAAMhC,GAC9BA,GAAOiC,OACTC,WAAW,WAAerB,GAAaA,EAAYsB,QAAQ,SAAY,KACvEC,QAAQC,IAAI,mBAAqBrC,EAAOiC,OAAS,YAE9C3B,IACEE,EACHF,EAASgC,MAAO/B,EAAkBC,EAAgB+B,OAAQvC,EAAQtC,EAAMuC,EAAQC,IAEhFI,EAASN,EAAQtC,EAAMuC,EAAQC,KAInC+B,MAAO,SAASO,EAAOC,EAAYC,GAC/B/B,IAAUA,EAAOoB,gBAAgB,YAAapB,EAAOU,MAAMC,OAAS,WACpEV,GAASW,OAAOX,GAASY,IAAI,UAAW,QACvCkB,IAAiB5B,IACpBsB,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,wCAA0CK,EAAc,yGAGtEhC,QAASA,IAIX,SAASlD,sBAAuBmF,EAAO1C,GAEtC,IAAIK,EAAWL,EAAOK,UAAY,KAC9B5C,EAAWuC,EAAOvC,MAAQ,GAC1BD,EAAWwC,EAAOxC,QAAU,OAEhC8D,OAAOE,KAAK,CACXC,KAAMjE,EACNkE,IAAKhF,SAASiG,UAAY,yBAA2BD,EACrDjF,KAAMA,EACNmF,WAAa,SAAWC,GACvBA,EAAIC,iBAAkB,aAAcpG,SAASqG,cAE9ClB,QAAS,SAAS9B,GACdA,EAAOiC,MACTG,QAAQC,IAAI,mBAAqBrC,EAAOiC,OAAS,YAE9C3B,GAEFA,EAASN,EAAQ2C,EAAO1C,EADd,OAKbgC,MAAO,SAASO,EAAOC,EAAYC,GAC9BA,IACHN,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,iDAAmDK,EAAc,4GAOjF,SAASO,qBACR,OAAOpD,KAAKC,UAAU,CACrBoD,UAAY9F,SAAS+F,gBAAgBC,YACrCC,WAAapC,KAAKqC,IACjBlG,SAASmG,KAAKC,aAAcpG,SAAS+F,gBAAgBK,aACrDpG,SAASmG,KAAKE,aAAcrG,SAAS+F,gBAAgBM,aACrDrG,SAASmG,KAAKG,aAActG,SAAS+F,gBAAgBO,cAEtDC,aAAevG,SAAS+F,gBAAgBS,YACxCC,cAAgBzG,SAAS+F,gBAAgBO,gBApa1C,WAEA,IAAII,EAAU,IAAIC,KACjBC,GAAW,IAAID,MAAOE,UACtBC,GAAwB,EACxBC,EAAc,GACdC,EAAqB,EACrBC,EAAkB,GAClBC,GAAoB,EAErB,SAASC,EAA2B5F,EAAM6F,EAAOlE,GACV,mBAA5BmE,OAAOC,iBAAiC/F,EAAK+F,iBAAiBF,EAAOlE,GAC7B3B,EAAKgG,YAAYH,EAAOlE,GAG3E,SAASsE,EAA2BjG,EAAM6F,EAAOlE,GACP,mBAA/BmE,OAAOI,oBAAoClG,EAAKkG,oBAAoBL,EAAOlE,GAChC3B,EAAKmG,YAAYN,EAAOlE,GAG9EhE,YACC,CACC,CAAE,kBAAmB2E,KAAK8D,OAAM,IAAIhB,MAAOE,UAAY,MACvD,CAAE,mBAAoB,KACtB,CAAE,kBAAmB,KACrB,CAAE,cAAeH,EAAQkB,oBAAoB,IAAK,GAClD,CAAE,uBAAwB,OAK5B,IAAIC,EAAqB,SAAgBT,GAExClI,YAAY,mBADO2E,KAAK8D,OAAM,IAAIhB,MAAOE,UAAU,MA0CnDW,EAA2BH,OAAQ,YAAaQ,GAChDL,EAA2BH,OAAQ,UAAWQ,IArC3CC,EAAsBC,YAAY,WACrCjB,GAAwB,GACtB,KAGCkB,EAA2BD,YAAY,WAC1C7I,YAAY,kBAAmBuD,KAAKC,UAAUqE,KAC5C,MAGCkB,EAAsB,SAAgBb,IACZ,IAA1BN,IAEFC,EAAYrF,KAAK,CAChBmC,KAAKqE,MAAMd,EAAMe,SACjBtE,KAAKqE,MAAMd,EAAMgB,SACjBvE,KAAKqE,OAAM,IAAIvB,MAAOE,UAAYD,KAInCE,GAAwB,EACC,MAFzBE,IAUDQ,EAA2BH,OAAQ,YAAaY,GAChDI,cAAcP,GACdO,cAAcL,MASf,SAASM,EAAWC,GACnB,IAAIC,EAAgBD,EAAEE,OAAOrJ,OACzBoJ,GAAmBA,KAAiBvB,GACvC1G,sBACC,CAACC,OAAQ,gCAAiCF,KAAO,CAACoI,MAAUF,IAC5D,CACC/H,WAAY,EACZyC,SAAU,SAAUN,GACfA,EAAOA,SACVqE,EAAgBuB,GAAiB,CAAC5F,OAAWA,EAAOA,OAAQ+F,UAAahC,KAAKiC,MAAQ,IAAM,GAC5F1J,YAAY,oBAAqBuD,KAAKC,UAAUuE,QAetDE,EAA2BE,OAAQ,YAAaY,GAChDd,EAA2BE,OAAQ,YAAaQ,GAChDV,EAA2BE,OAAQ,UAAWQ,GAC9CV,EAA2BE,OAAQ,SAVnC,WACOH,IACLhI,YAAY,kBAAmBuD,KAAKC,WAAW,IAC/CwE,GAAoB,KAoEtBC,EAA2BE,OAAQ,mBA1DnC,YAEM9H,SAASsJ,iBACb3J,YAAa,kBAAmBK,SAASuJ,aACpCvJ,SAASwJ,gBACb5E,OAAO,QAAQ6E,OAAQ,mDAAqDzJ,SAASuJ,WAAa,QAI9FvJ,SAAS0J,gCACd/J,YAAa,oBAAqB,KAClCiF,OAAO,iCAAiC+E,KAAKZ,IAI9CpJ,YAAa,iBAAkB2G,sBAC/B3G,YAAY,kBAAmBuD,KAAKC,WAAW,IAE/CoC,WAAW,WAIV,IAFA,IAAIvC,EAA4B,GAExB5C,EAAI,EAAGA,EAAIK,SAASmJ,MAAMnG,OAAQrD,IAAI,CAC7C,IAAIiB,EAAOZ,SAASmJ,MAAMxJ,GAIzBiB,EAAKmB,UAAUC,SAAS,oBACxBpB,EAAKwI,cAAcrH,UAAUC,SAAS,iBACkB,IAAxDpB,EAAKJ,OAAO6I,WAAW7H,QAAQ,qBAC9BZ,EAAK0I,IAAiB,cAAX1I,EAAK0I,IAChB1I,EAAK2I,KAAKxH,WAAanB,EAAK2I,KAAKxH,UAAUC,SAAS,kBACpDpB,EAAK2I,KAAKxH,WAAanB,EAAK2I,KAAKxH,UAAUC,SAAS,eAItDO,EAA0B5C,GAAKgB,6BAA8BC,GAE7DA,EAAK4I,cAAgB5I,EAAK6I,SAC1B7I,EAAK6I,SAAW,SAAUrC,GAEzB,IAAIlF,EAAiB,GACrBA,EAAe,GAAKvB,6BAA6B+I,MACjDpH,gCAAiCJ,GAG7BkF,EAAMqB,OAAOe,yBAAyBG,UACzC7E,WAAW,WACVsC,EAAMqB,OAAOe,cAAcI,KAAKxC,EAAMqB,OAAQrB,IAC5C,OAKN9E,gCAAiCC,IAE/B,OArKL,GAwaqB,oBAAX4B,QAGTA,OAAOnE,UAAU6J,aAAa,SAAUzC,EAAO1B,EAAKoE,IAC/CpE,EAAIqE,eAAwD,IAAxCrE,EAAIqE,aAAavI,QAAQ,gBAElB,KAD1BwI,EAAWvH,KAAKmC,MAAMc,EAAIqE,eACVE,QACnBD,EAAWA,EAASC,OACPC,UACZlK,SAASmK,cACR,IAAIC,YAAa,qBAAsB,CACtCC,SAAS,EACTC,OAAQ,CAAEC,QAASP,EAASQ,YAK9BC,eAAeC,OAASV,EAASQ,QACjCC,eAAeE,OAEa,IAAxBX,EAASY,aACZvD,OAAOwD"}
lib/Cleantalk/Antispam/Cleantalk.php CHANGED
@@ -194,7 +194,7 @@ class Cleantalk {
194
  else
195
  $cookie_name = 'COOKIE';
196
 
197
- if( $ct_tmp ) {
198
  $ct_tmp[$cookie_name] = preg_replace(array(
199
  '/\s?ct_checkjs=[a-z0-9]*[^;]*;?/',
200
  '/\s?ct_timezone=.{0,1}\d{1,2}[^;]*;?/',
194
  else
195
  $cookie_name = 'COOKIE';
196
 
197
+ if( $ct_tmp && isset( $ct_tmp[$cookie_name] ) ) {
198
  $ct_tmp[$cookie_name] = preg_replace(array(
199
  '/\s?ct_checkjs=[a-z0-9]*[^;]*;?/',
200
  '/\s?ct_timezone=.{0,1}\d{1,2}[^;]*;?/',
lib/Cleantalk/ApbctWP/Ajax.php CHANGED
@@ -16,8 +16,8 @@ class Ajax {
16
  define( 'DOING_AJAX', true );
17
  define( 'SHORTINIT', true );
18
 
19
- require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );
20
- require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/pluggable.php' );
21
 
22
  $this->checkRequest();
23
 
16
  define( 'DOING_AJAX', true );
17
  define( 'SHORTINIT', true );
18
 
19
+ require_once( '../../../../../../wp-load.php' );
20
+ require_once( '../../../../../../wp-includes/pluggable.php' );
21
 
22
  $this->checkRequest();
23
 
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php CHANGED
@@ -434,7 +434,9 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
434
  $is_redirect = false;
435
  if( Server::get( 'HTTP_REFERER' ) !== '' && Server::get( 'HTTP_HOST' ) !== '' && $this->is_cloudflare() ) {
436
  $parse_referer = parse_url( Server::get( 'HTTP_REFERER' ) );
437
- $is_redirect = Server::get( 'HTTP_HOST' ) !== $parse_referer['host'];
 
 
438
  }
439
  return http_response_code() === 301 || http_response_code() === 302 || $is_redirect;
440
  }
434
  $is_redirect = false;
435
  if( Server::get( 'HTTP_REFERER' ) !== '' && Server::get( 'HTTP_HOST' ) !== '' && $this->is_cloudflare() ) {
436
  $parse_referer = parse_url( Server::get( 'HTTP_REFERER' ) );
437
+ if( $parse_referer && isset( $parse_referer['host'] ) ) {
438
+ $is_redirect = Server::get( 'HTTP_HOST' ) !== $parse_referer['host'];
439
+ }
440
  }
441
  return http_response_code() === 301 || http_response_code() === 302 || $is_redirect;
442
  }
lib/Cleantalk/ApbctWP/State.php CHANGED
@@ -332,6 +332,10 @@ class State
332
 
333
  // Setting default options
334
  if($this->option_prefix.'_'.$option_name === 'cleantalk_settings'){
 
 
 
 
335
  $option = is_array($option) ? array_merge($this->def_settings, $option) : $this->def_settings;
336
  }
337
 
332
 
333
  // Setting default options
334
  if($this->option_prefix.'_'.$option_name === 'cleantalk_settings'){
335
+ if ( !$option ) {
336
+ //Set alt cookies if sg optimizer is installed
337
+ $this->def_settings['data__set_cookies'] = defined('SiteGround_Optimizer\VERSION') ? 2 : 1;
338
+ }
339
  $option = is_array($option) ? array_merge($this->def_settings, $option) : $this->def_settings;
340
  }
341
 
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: safronik
3
  Tags: spam, antispam, anti-spam, comments, firewall
4
  Requires at least: 3.0
5
- Tested up to: 5.7
6
  Requires PHP: 5.6
7
- Stable tag: 5.159.7
8
  License: GPLv2
9
 
10
  Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
@@ -573,6 +573,14 @@ If your website has forms that send data to external sources, you can enable opt
573
 
574
  == Changelog ==
575
 
 
 
 
 
 
 
 
 
576
  = 5.159.7 Jul 01 2021 =
577
  * Fix. Updater fixed.
578
 
2
  Contributors: safronik
3
  Tags: spam, antispam, anti-spam, comments, firewall
4
  Requires at least: 3.0
5
+ Tested up to: 5.8
6
  Requires PHP: 5.6
7
+ Stable tag: 5.159.8
8
  License: GPLv2
9
 
10
  Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
573
 
574
  == Changelog ==
575
 
576
+ = 5.159.8 Jul 07 2021 =
577
+ * Fix: Fixed the connection error Ajax.php when the site files are in a subfolder.
578
+ * Fix. SFW. Anticrawler redirect detection fixed.
579
+ * Fix. Checking sql before the tables creating.
580
+ * Fix. Updater fixed.
581
+ * Fix: Set alt cookies if sg optimizer is enabled.
582
+ * Fix: Exclusion for GiveWP plugin in apbct-public.js. #2
583
+
584
  = 5.159.7 Jul 01 2021 =
585
  * Fix. Updater fixed.
586