-
Notifications
You must be signed in to change notification settings - Fork 5
/
cleantalk.php
2979 lines (2541 loc) · 99.7 KB
/
cleantalk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: Anti-Spam by CleanTalk
Plugin URI: https://cleantalk.org
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.
Version: 6.47
Author: СleanTalk - Anti-Spam Protection <[email protected]>
Author URI: https://cleantalk.org
Text Domain: cleantalk-spam-protect
Domain Path: /i18n
*/
use Cleantalk\ApbctWP\Activator;
use Cleantalk\ApbctWP\AdminNotices;
use Cleantalk\ApbctWP\Antispam\EmailEncoder;
use Cleantalk\ApbctWP\API;
use Cleantalk\ApbctWP\CleantalkRealPerson;
use Cleantalk\ApbctWP\CleantalkUpgrader;
use Cleantalk\ApbctWP\CleantalkUpgraderSkin;
use Cleantalk\ApbctWP\CleantalkUpgraderSkinDeprecated;
use Cleantalk\ApbctWP\Cron;
use Cleantalk\ApbctWP\DB;
use Cleantalk\ApbctWP\Deactivator;
use Cleantalk\ApbctWP\Firewall\AntiCrawler;
use Cleantalk\ApbctWP\Firewall\AntiFlood;
use Cleantalk\ApbctWP\Firewall\SFW;
use Cleantalk\ApbctWP\Firewall\SFWUpdateHelper;
use Cleantalk\ApbctWP\FormDecorator\FormDecorator;
use Cleantalk\ApbctWP\Helper;
use Cleantalk\ApbctWP\RemoteCalls;
use Cleantalk\ApbctWP\RequestParameters\RequestParameters;
use Cleantalk\ApbctWP\RestController;
use Cleantalk\ApbctWP\Sanitize;
use Cleantalk\ApbctWP\State;
use Cleantalk\ApbctWP\Transaction;
use Cleantalk\ApbctWP\UpdatePlugin\DbTablesCreator;
use Cleantalk\ApbctWP\Variables\Cookie;
use Cleantalk\ApbctWP\Variables\Get;
use Cleantalk\ApbctWP\Variables\Post;
use Cleantalk\ApbctWP\Variables\Request;
use Cleantalk\ApbctWP\Variables\Server;
use Cleantalk\Common\DNS;
use Cleantalk\Common\Firewall;
use Cleantalk\Common\Schema;
use Cleantalk\Common\TT;
global $apbct, $wpdb, $pagenow;
$cleantalk_executed = false;
/**
* Define common const.
*/
$plugin_info = get_file_data(__FILE__, array('Version' => 'Version', 'Name' => 'Plugin Name',));
define('APBCT_NAME', isset($plugin_info['Name']) ? $plugin_info['Name'] : 'Anti-Spam by CleanTalk');
define('APBCT_VERSION', isset($plugin_info['Version']) ? $plugin_info['Version'] : '1.0.0');
define('APBCT_URL_PATH', plugins_url('', __FILE__)); //HTTP path. Plugin root folder without '/'.
define('APBCT_CSS_ASSETS_PATH', plugins_url('css', __FILE__)); //CSS assets path. Plugin root folder without '/'.
define('APBCT_JS_ASSETS_PATH', plugins_url('js', __FILE__)); //JS assets path. Plugin root folder without '/'.
define('APBCT_IMG_ASSETS_PATH', plugins_url('inc/images', __FILE__)); //IMAGES assets path. Plugin root folder without '/'.
define('APBCT_DIR_PATH', dirname(__FILE__) . '/'); //System path. Plugin root folder with '/'.
define('APBCT_PLUGIN_BASE_NAME', plugin_basename(__FILE__)); //Plugin base name.
define(
'APBCT_CASERT_PATH',
file_exists(ABSPATH . WPINC . '/certificates/ca-bundle.crt') ? ABSPATH . WPINC . '/certificates/ca-bundle.crt' : ''
); // SSL Serttificate path
/**
* Define options names const.
*/
define('APBCT_DATA', 'cleantalk_data'); // Option name with different plugin data.
define('APBCT_SETTINGS', 'cleantalk_settings'); // Option name with plugin settings.
define('APBCT_NETWORK_SETTINGS', 'cleantalk_network_settings'); // Option name with plugin network settings.
define('APBCT_JS_ERRORS', 'cleantalk_js_errors'); // Option name with js errors. Empty by default.
/**
* Define service const.
*/
define('APBCT_REMOTE_CALL_SLEEP', 5); // Minimum time between remote call
define('APBCT_WPMS', (is_multisite() ? true : false)); // WordPress Multisite - if WMPS is enabled
define('APBCT_LANG_REL_PATH', 'cleantalk-spam-protect/i18n');
if ( ! defined('CLEANTALK_PLUGIN_DIR') ) {
define('CLEANTALK_PLUGIN_DIR', dirname(__FILE__) . '/');
}
/**
* Require PHP patch.
*/
require_once(CLEANTALK_PLUGIN_DIR . 'lib/cleantalk-php-patch.php'); // Pathces fpr different functions which not exists
/**
* Require the Autoloader
*/
require_once(CLEANTALK_PLUGIN_DIR . 'lib/autoloader.php');
if (!defined('APBCT_IS_LOCALHOST')) {
define('APBCT_IS_LOCALHOST', in_array(Server::getDomain(), array('lc', 'loc', 'lh', 'test')));
}
/**
* Define API params const.
*/
$plugin_version__agent = APBCT_VERSION;
// Converts version to xxx.xxx.xx-dev to xxx.xxx.2xx and xxx.xxx.xx-fix to xxx.xxx.1xx
if ( preg_match('@^(\d+)\.(\d+)\.(\d{1,2})-(dev|fix)$@', $plugin_version__agent, $m) ) {
$major_version = TT::getArrayValueAsString($m, 1);
$minor_version = TT::getArrayValueAsString($m, 2);
$branch_sub = TT::getArrayValueAsString($m, 4) === 'dev' ? '2' : '1';
$padded = str_pad(
TT::getArrayValueAsString($m, 3),
2,
'0',
STR_PAD_LEFT
);
$plugin_version__agent = $major_version . '.' . $minor_version . '.' . $branch_sub . $padded;
}
define('APBCT_AGENT', 'wordpress-' . $plugin_version__agent); // Prepared agent
const APBCT_MODERATE_URL = 'https://moderate.cleantalk.org'; // Api URL
/**
* Require base classes.
*/
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-pluggable.php'); // Pluggable functions
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-wpcli.php');
/**
* Global state handle.
*/
// Global ArrayObject with settings and other global variables
$apbct = new State('cleantalk', array('settings', 'data', 'errors', 'remote_calls', 'stats', 'fw_stats'));
// Init plugin basename.
$apbct->base_name = 'cleantalk-spam-protect/cleantalk.php';
// Identify plugin execution
$apbct->plugin_request_id = md5(microtime());
// Init logos.
$apbct->logo = plugin_dir_url(__FILE__) . 'inc/images/logo.png';
$apbct->logo__small = plugin_dir_url(__FILE__) . 'inc/images/logo_small.png';
$apbct->logo__small__colored = plugin_dir_url(__FILE__) . 'inc/images/logo_color.png';
// Init Account status
$apbct->white_label = $apbct->network_settings['multisite__white_label'];
$apbct->allow_custom_key = $apbct->network_settings['multisite__work_mode'] != 2;
$apbct->plugin_name = $apbct->network_settings['multisite__white_label__plugin_name'] ? $apbct->network_settings['multisite__white_label__plugin_name'] : APBCT_NAME;
$apbct->api_key = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->settings['apikey'] : $apbct->network_settings['apikey'];
$apbct->key_is_ok = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['key_is_ok'] : $apbct->network_data['key_is_ok'];
$apbct->moderate = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['moderate'] : $apbct->network_data['moderate'];
// Init counter
$apbct->data['user_counter']['since'] = isset($apbct->data['user_counter']['since'])
? $apbct->data['user_counter']['since']
: date('d M');
// Init SFW update data
$apbct->firewall_updating = (bool)$apbct->fw_stats['firewall_updating_id'];
$apbct->data['sfw_load_type'] = (!APBCT_WPMS || is_main_site() || $apbct->network_settings['multisite__work_mode'] === 2) ? 'all' : 'personal';
$apbct->saveData();
// Init settings link
$apbct->settings_link = is_network_admin() ? 'settings.php?page=cleantalk' : 'options-general.php?page=cleantalk';
// Connection reports
$apbct->setConnectionReports();
// SFW update sentinel
$apbct->setSFWUpdateSentinel();
// Disabling comments
if ( $apbct->settings['comments__disable_comments__all'] || $apbct->settings['comments__disable_comments__posts'] || $apbct->settings['comments__disable_comments__pages'] || $apbct->settings['comments__disable_comments__media'] ) {
\Cleantalk\Antispam\DisableComments::getInstance();
}
// Email encoder
if (
$apbct->key_is_ok &&
( ! is_admin() || apbct_is_ajax() ) &&
current_action() !== 'wp_ajax_delete-plugin'
) {
$skip_email_encode = false;
if (!empty($_POST)) {
foreach ( $_POST as $param => $_value ) {
if ( strpos((string)$param, 'et_pb_contactform_submit') === 0 ) {
$skip_email_encode = true;
break;
}
}
}
if (!$skip_email_encode && !apbct_is_amp_request()) {
EmailEncoder::getInstance();
// Email Encoder ajax handlers
EmailEncoder::getInstance()->registerAjaxRoute();
}
}
if ( $apbct->settings['comments__the_real_person'] ) {
new CleantalkRealPerson();
}
if ( $apbct->settings['comments__form_decoration'] && $apbct->settings['comments__form_decoration_selector']) {
$decorator = new FormDecorator();
$decorator->setDecorationSet($apbct->settings['comments__form_decoration_selector']);
}
add_action('rest_api_init', 'apbct_register_my_rest_routes');
function apbct_register_my_rest_routes()
{
$controller = new RestController();
$controller->register_routes();
}
// Alt cookies via WP ajax handler
add_action('wp_ajax_nopriv_apbct_alt_session__save__AJAX', 'apbct_alt_session__save__WP_AJAX');
add_action('wp_ajax_apbct_alt_session__save__AJAX', 'apbct_alt_session__save__WP_AJAX');
function apbct_alt_session__save__WP_AJAX()
{
Cleantalk\ApbctWP\Variables\AltSessions::setFromRemote();
}
// Get JS via WP ajax handler
add_action('wp_ajax_nopriv_apbct_js_keys__get', 'apbct_js_keys__get__ajax');
add_action('wp_ajax_apbct_js_keys__get', 'apbct_js_keys__get__ajax');
// Get Pixel URL via WP ajax handler
add_action('wp_ajax_nopriv_apbct_get_pixel_url', 'apbct_get_pixel_url__ajax');
add_action('wp_ajax_apbct_get_pixel_url', 'apbct_get_pixel_url__ajax');
// Checking email before POST
add_action('wp_ajax_nopriv_apbct_email_check_before_post', 'apbct_email_check_before_post');
// Checking email exist POST
add_action('wp_ajax_nopriv_apbct_email_check_exist_post', 'apbct_email_check_exist_post');
// Force ajax set important parameters (apbct_timestamp etc)
add_action('wp_ajax_nopriv_apbct_set_important_parameters', 'apbct_cookie');
add_action('wp_ajax_apbct_set_important_parameters', 'apbct_cookie');
// Database prefix
global $wpdb, $wp_version;
$apbct->db_prefix = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $wpdb->prefix : $wpdb->base_prefix;
$apbct->db_prefix = ! $apbct->white_label && defined('CLEANTALK_ACCESS_KEY') ? $wpdb->base_prefix : $wpdb->prefix;
/** @todo HARDCODE FIX */
if ( $apbct->plugin_version === '1.0.0' ) {
$apbct->plugin_version = '5.100';
}
/**
* Do update actions if version is changed
* ! we can`t place this function to the hook "upgrader_process_complete" !
*/
apbct_update_actions();
add_action('init', function () {
global $apbct;
// Self cron
$ct_cron = new Cron();
$tasks_to_run = $ct_cron->checkTasks(); // Check for current tasks. Drop tasks inner counters.
if (
$tasks_to_run && // There are tasks to run
! RemoteCalls::check() && // Do not do CRON in remote call action
(
! defined('DOING_CRON') ||
(defined('DOING_CRON') && DOING_CRON !== true)
)
) {
$cron_res = $ct_cron->runTasks($tasks_to_run);
if ( is_array($cron_res) ) {
foreach ( $cron_res as $_task => $res ) {
if ( $res === true ) {
$apbct->errorDelete('cron', true);
} else {
$apbct->errorAdd('cron', $res);
}
}
}
}
// Remote calls
if ( RemoteCalls::check() ) {
try {
/**
* Needs to include apbct_settings__validate() for run_service_template_get remote call.
* TODO:Probably we should refactor apbct_settings__validate() to a class feature to use it within autoloader
*/
if ( Get::get('spbc_remote_call_action') === 'run_service_template_get' ) {
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-settings.php');
}
RemoteCalls::perform();
} catch ( Exception $e ) {
die(json_encode(array('ERROR' => $e->getMessage())));
}
}
});
//Delete cookie for admin trial notice
add_action('wp_logout', 'apbct__hook__wp_logout__delete_trial_notice_cookie');
// Set cookie only for public pages and for non-AJAX requests
if ( ! is_admin() && ! apbct_is_ajax() && ! defined('DOING_CRON')
&& ! apbct__is_rest_api_request()
&& empty(Post::get('ct_checkjs_register_form')) // Buddy press registration fix
&& empty(Get::get('ct_checkjs_search_default')) // Search form fix
&& empty(Post::get('action')) //bbPress
&& ! \Cleantalk\Variables\Server::inUri('/favicon.ico') // /favicon request rewritten cookies fix
) {
if ( $apbct->data['cookies_type'] !== 'alternative' ) {
if ( !$apbct->settings['forms__search_test'] && !Get::get('s') ) { //skip cookie set for search form redirect page
add_action('template_redirect', 'apbct_cookie', 2);
}
add_action('template_redirect', 'apbct_store__urls', 2);
}
if (
empty($_POST) &&
( (isset($_GET['q']) && $_GET['q'] !== '') || empty($_GET) ) &&
$apbct->data['key_is_ok']
) {
apbct_cookie();
apbct_store__urls();
}
}
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate-skip-functions.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
// Early checks
if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'wpmlsubscribe') {
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
ct_ajax_hook();
}
// Iphorm
if (
Post::get('iphorm_ajax') !== '' &&
Post::get('iphorm_id') !== '' &&
Post::get('iphorm_uid') !== ''
) {
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
ct_ajax_hook();
}
// Facebook
if ( $apbct->settings['forms__general_contact_forms_test'] == 1
&& ( Post::get('action') === 'fb_intialize')
&& ! empty(Post::get('FB_userdata'))
) {
if ( apbct_is_user_enable() ) {
ct_registration_errors(null);
}
}
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-integrations-by-hook.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-integrations-by-class.php');
// WP Delicious integration
add_filter('delicious_recipes_process_registration_errors', 'apbct_wp_delicious', 10, 4);
$js_errors_arr = apbct_check_post_for_no_cookie_data();
if ($js_errors_arr && isset($js_errors_arr['data'])) {
apbct_write_js_errors($js_errors_arr['data']);
}
/**
* @param string $data
* @psalm-suppress UnusedVariable
*/
function apbct_write_js_errors($data)
{
if (!is_string($data) || empty($data)) {
return false;
}
$tmp = substr($data, strlen('_ct_no_cookie_data_'));
$errors = json_decode(base64_decode($tmp), true);
if (!isset($errors['ct_js_errors'])) {
return false;
}
$errors = $errors['ct_js_errors'];
$exist_errors = get_option(APBCT_JS_ERRORS);
if (!$exist_errors) {
return update_option(APBCT_JS_ERRORS, $errors);
}
$errors_collection_msgs = [];
foreach ($exist_errors as $err_index => $err_value) {
array_push($errors_collection_msgs, $err_value['err']['msg']);
}
foreach ($errors as $err_index => $err_value) {
if (!in_array($err_value['err']['msg'], $errors_collection_msgs)) {
array_push($exist_errors, $err_value);
}
}
return update_option(APBCT_JS_ERRORS, $exist_errors);
}
// LearnPress
if (
apbct_is_plugin_active('learnpress/learnpress.php') &&
apbct_is_in_uri('lp-ajax=checkout') &&
sizeof($_POST) > 0
) {
apbct_form__learnpress__testSpam();
}
// OptimizePress
if (
apbct_is_plugin_active('op-dashboard/op-dashboard.php') &&
apbct_is_in_uri('/optin/submit') &&
sizeof($_POST) > 0
) {
apbct_form__optimizepress__testSpam();
}
// Mailoptin. Pass without action because url for ajax request is domain.com/any-page/?mailoptin-ajax=subscribe_to_email_list
if (
apbct_is_plugin_active('mailoptin/mailoptin.php') &&
sizeof($_POST) > 0 &&
Get::get('mailoptin-ajax') === 'subscribe_to_email_list'
) {
apbct_form__mo_subscribe_to_email_list__testSpam();
}
// Metform
if (
apbct_is_plugin_active('metform/metform.php') &&
apbct_is_in_uri('/wp-json/metform/') &&
sizeof($_POST) > 0
) {
apbct_form__metform_subscribe__testSpam();
}
// Memberpress integration
if (
!empty($_POST) &&
apbct_is_plugin_active('memberpress/memberpress.php') &&
Post::hasString('mepr_process_signup_form', '1') &&
(int)$apbct->settings['forms__registrations_test'] === 1
) {
apbct_memberpress_signup_request_test();
}
// Ninja Forms. Making GET action to POST action
if (
apbct_is_in_uri('admin-ajax.php') &&
sizeof($_POST) > 0 &&
Get::get('action') === 'ninja_forms_ajax_submit'
) {
$_POST['action'] = 'ninja_forms_ajax_submit';
}
// GiveWP without ajax
if (
!empty($_POST) &&
(int)$apbct->settings['forms__contact_forms_test'] === 1 &&
apbct_is_plugin_active('give/give.php') &&
!empty($_POST['give-form-hash']) &&
!empty($_POST['give-form-id'])
) {
apbct_givewp_donate_request_test();
}
// JetformBuilder
if (
!empty($_POST) &&
apbct_is_plugin_active('jetformbuilder/jet-form-builder.php') &&
Get::get('jet_form_builder_submit') === 'submit'
) {
apbct_jetformbuilder_request_test();
}
// DHVC Form
if (
!empty($_POST) &&
apbct_is_plugin_active('dhvc-form/dhvc-form.php') &&
Post::get('dhvc_form') && Post::get('_dhvc_form_nonce')
) {
apbct_dhvcform_request_test();
}
// SeedConfirmPro
if (!empty($_POST) &&
apbct_is_plugin_active('seed-confirm-pro/seed-confirm-pro.php') &&
Post::get('seed_confirm_nonce')
) {
apbct_seedConfirmPro_request_test();
}
add_action('wp_ajax_nopriv_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
add_action('wp_ajax_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
add_action('wp_ajax_nopriv_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
add_action('wp_ajax_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
add_action('ninja_forms_process', 'apbct_form__ninjaForms__testSpam', 1); // Depricated ?
add_action('ninja_forms_display_after_form', 'apbct_form__ninjaForms__addField', 1000, 10);
// SeedProd Coming Soon Page Pro integration
add_action('wp_ajax_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
add_action('wp_ajax_nopriv_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
add_action('wp_ajax_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
add_action('wp_ajax_nopriv_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
// The 7 theme contact form integration
add_action('wp_ajax_nopriv_dt_send_mail', 'apbct_form__the7_contact_form', 1);
add_action('wp_ajax_dt_send_mail', 'apbct_form__the7_contact_form', 1);
// Custom register form (ticket_id=13668)
add_action('website_neotrends_signup_fields_check', function ($username, $fields) {
$ip = Helper::ipGet('real', false);
$ct_result = ct_test_registration($username, $fields['email'], $ip);
if ( TT::getArrayValueAsInt($ct_result, 'allow') === 0 ) {
ct_die_extended(TT::getArrayValueAsString($ct_result, 'comment'));
}
}, 1, 2);
add_action('elementor/frontend/the_content', 'apbct_form__elementor_pro__addField', 10, 2);
// INEVIO theme integration
add_action('wp_ajax_contact_form_handler', 'apbct_form__inevio__testSpam', 1);
add_action('wp_ajax_nopriv_contact_form_handler', 'apbct_form__inevio__testSpam', 1);
// Enfold Theme contact form
add_filter('avf_form_send', 'apbct_form__enfold_contact_form__test_spam', 4, 10);
// Profile Builder integration
add_filter('wppb_output_field_errors_filter', 'apbct_form_profile_builder__check_register', 1, 3);
// Advanced Classifieds & Directory Pro
add_filter('acadp_is_spam', 'apbct_advanced_classifieds_directory_pro__check_register', 1, 2);
// WP Foro register system integration
add_filter('wpforo_create_profile', 'wpforo_create_profile__check_register', 1, 1);
// HappyForms integration
add_filter('happyforms_validate_submission', 'apbct_form_happyforms_test_spam', 1, 3);
add_filter('happyforms_use_hash_protection', '__return_false');
// WPForms
// Adding fields
add_action('wpforms_frontend_output', 'apbct_form__WPForms__addField', 1000, 5);
// Gathering data to validate
add_filter('wpforms_process_before_filter', 'apbct_from__WPForms__gatherData', 100, 2);
// Do spam check
add_filter('wpforms_process_initial_errors', 'apbct_form__WPForms__showResponse', 100, 2);
// Formidable
add_filter('frm_entries_before_create', 'apbct_form__formidable__testSpam', 999999, 2);
add_action('frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2);
add_action('mec_booking_end_form_step_2', function () {
echo "<script>
if (typeof ctPublic.force_alt_cookies == 'undefined' || (ctPublic.force_alt_cookies !== 'undefined' && !ctPublic.force_alt_cookies)) {
ctNoCookieAttachHiddenFieldsToForms();
}
</script>";
});
// Public actions
if ( ! is_admin() && ! apbct_is_ajax() && ! apbct_is_customize_preview() ) {
// Default search
add_filter('get_search_query', 'apbct_forms__search__testSpam');
add_action('wp_head', 'apbct_search_add_noindex', 1);
if (apbct_is_plugin_active('fluentformpro/fluentformpro.php') && apbct_is_in_uri('ff_landing=')) {
add_action('wp_head', function () {
echo '<script data-pagespeed-no-defer="" src="'
. APBCT_URL_PATH
. '/js/apbct-public-bundle.min.js'
. '?ver=' . APBCT_VERSION . '" id="ct_public_functions-js"></script>';
echo '<script src="https://moderate.cleantalk.org/ct-bot-detector-wrapper.js?ver='
. APBCT_VERSION . '" id="ct_bot_detector-js"></script>';
}, 100);
}
// SpamFireWall check
if ( $apbct->plugin_version == APBCT_VERSION && // Do not call with first start
$apbct->settings['sfw__enabled'] == 1 &&
$apbct->stats['sfw']['last_update_time'] &&
apbct_is_get() &&
! apbct_wp_doing_cron() &&
! Server::inUri('/favicon.ico') &&
! apbct_is_cli()
) {
wp_suspend_cache_addition(true);
apbct_sfw__check();
wp_suspend_cache_addition(false);
}
}
// Activation/deactivation functions must be in main plugin file.
// http://codex.wordpress.org/Function_Reference/register_activation_hook
register_activation_hook(__FILE__, 'apbct_activation');
function apbct_activation($network_wide)
{
Activator::activation($network_wide);
}
register_deactivation_hook(__FILE__, 'apbct_deactivation');
function apbct_deactivation($network_wide)
{
Deactivator::deactivation($network_wide);
}
register_uninstall_hook(__FILE__, 'apbct_uninstall');
function apbct_uninstall($network_wide)
{
global $apbct;
$apbct->settings['misc__complete_deactivation'] = 1;
$apbct->saveSettings();
Deactivator::deactivation($network_wide);
}
// Hook for newly added blog
if ( version_compare($wp_version, '5.1') >= 0 ) {
add_action('wp_initialize_site', 'apbct_activation__new_blog', 10, 2);
add_action('wp_uninitialize_site', 'apbct_wpms__delete_blog', 10, 1);
} else {
add_action('wpmu_new_blog', 'apbct_activation__new_blog__deprecated', 10, 6);
add_action('delete_blog', 'apbct_wpms__delete_blog__deprecated', 10, 2);
}
function apbct_activation__new_blog__deprecated($blog_id, $_user_id, $_domain, $_path, $_site_id, $_meta)
{
Activator::activation(false, $blog_id);
}
function apbct_activation__new_blog(WP_Site $new_site, $_args)
{
Activator::activation(false, $new_site->blog_id);
}
function apbct_wpms__delete_blog__deprecated($blog_id, $_drop)
{
apbct_sfw__delete_tables($blog_id);
}
function apbct_wpms__delete_blog(WP_Site $old_site)
{
apbct_sfw__delete_tables($old_site->blog_id);
}
// Async loading for JavaScript
add_filter('script_loader_tag', 'apbct_add_async_attribute', 10, 3);
// Redirect admin to plugin settings.
if ( ! defined('WP_ALLOW_MULTISITE') || (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == false) ) {
add_action('admin_init', 'apbct_plugin_redirect');
}
// After plugin loaded - to load locale as described in manual
add_action('plugins_loaded', 'apbct_plugin_loaded');
if ( ! empty($apbct->settings['data__use_ajax']) &&
! apbct_is_in_uri('.xml') &&
! apbct_is_in_uri('.xsl') ) {
add_action('wp_ajax_nopriv_ct_get_cookie', 'ct_get_cookie', 1);
add_action('wp_ajax_ct_get_cookie', 'ct_get_cookie', 1);
}
// Admin panel actions
if ( is_admin() || is_network_admin() ) {
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-find-spam.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-admin.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-settings.php');
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-wc-spam-orders.php');
add_action('admin_init', 'apbct_admin__init', 1);
// Show notices
add_action('admin_init', array(AdminNotices::class, 'showAdminNotices'));
if ( ! (defined('DOING_AJAX') && DOING_AJAX) ) {
add_action('admin_enqueue_scripts', 'apbct_admin__enqueue_scripts');
add_action('admin_menu', 'apbct_settings_add_page');
add_action('network_admin_menu', 'apbct_settings_add_page');
//Show widget only if enables and not IP license
if ( $apbct->settings['wp__dashboard_widget__show'] && ! $apbct->moderate_ip ) {
add_action('wp_dashboard_setup', 'ct_dashboard_statistics_widget');
}
}
if ( apbct_is_ajax() || Post::get('cma-action') !== '' ) {
$_cleantalk_hooked_actions = array();
$_cleantalk_ajax_actions_to_check = array();
global $apbct_active_integrations;
if (isset($apbct_active_integrations) && is_array($apbct_active_integrations)) {
$integrated_hooks = array_column($apbct_active_integrations, 'hook');
foreach ( $integrated_hooks as $hook ) {
if ( is_array($hook) ) {
foreach ( $hook as $_item ) {
$_cleantalk_hooked_actions[] = $_item;
}
} else {
$_cleantalk_hooked_actions[] = $hook;
}
}
}
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
// Feedback for comments
if ( Post::get('action') === 'ct_feedback_comment' ) {
add_action('wp_ajax_nopriv_ct_feedback_comment', 'apbct_comment__send_feedback', 1);
add_action('wp_ajax_ct_feedback_comment', 'apbct_comment__send_feedback', 1);
}
if ( Post::get('action') === 'ct_feedback_user' ) {
add_action('wp_ajax_nopriv_ct_feedback_user', 'apbct_user__send_feedback', 1);
add_action('wp_ajax_ct_feedback_user', 'apbct_user__send_feedback', 1);
}
// Check AJAX requests
// if User is not logged in
// if Unknown action or Known action with mandatory check
if (
( ! apbct_is_user_logged_in() || $apbct->settings['data__protect_logged_in'] == 1) &&
Post::get('action') !== '' &&
(
! in_array(Post::get('action'), $_cleantalk_hooked_actions) ||
in_array(Post::get('action'), $_cleantalk_ajax_actions_to_check)
)
) {
add_action('plugins_loaded', 'ct_ajax_hook');
}
//QAEngine Theme answers
if ( intval($apbct->settings['forms__general_contact_forms_test']) ) {
add_filter('et_pre_insert_question', 'ct_ajax_hook', 1, 1);
} // Questions
add_filter('et_pre_insert_answer', 'ct_ajax_hook', 1, 1); // Answers
// Some of plugins to register a users use AJAX context.
add_filter('registration_errors', 'ct_registration_errors', 1, 3);
add_filter('registration_errors', 'ct_check_registration_errors', 999999, 3);
add_action('user_register', 'apbct_user_register');
}
//Bitrix24 contact form
if ( $apbct->settings['forms__general_contact_forms_test'] == 1 &&
! empty(Post::get('your-phone')) &&
! empty(Post::get('your-email')) &&
! empty(Post::get('your-message'))
) {
ct_contact_form_validate();
}
// Sends feedback to the cloud about comments
// add_action('wp_set_comment_status', 'ct_comment_send_feedback', 10, 2);
// Sends feedback to the cloud about deleted users
if ( $pagenow === 'users.php' ) {
add_action('delete_user', 'apbct_user__delete__hook', 10, 2);
}
if ( $pagenow === 'plugins.php' || apbct_is_in_uri('plugins.php') ) {
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'apbct_admin__plugin_action_links', 10, 2);
add_filter(
'network_admin_plugin_action_links_' . plugin_basename(__FILE__),
'apbct_admin__plugin_action_links',
10,
2
);
add_filter('all_plugins', 'apbct_admin__change_plugin_description');
add_filter('plugin_row_meta', 'apbct_admin__register_plugin_links', 10, 3);
}
// Public pages actions
} else {
add_action('wp_enqueue_scripts', 'ct_enqueue_scripts_public');
add_action('wp_enqueue_scripts', 'ct_enqueue_styles_public');
add_action('login_enqueue_scripts', 'ct_enqueue_styles_public');
// Init action.
add_action('plugins_loaded', 'apbct_init', 1);
// Comments
add_filter('comment_text', 'ct_comment_text');
// Registrations
if ( ! Post::get('wp-submit') ) {
add_action('login_form_register', 'apbct_cookie');
add_action('login_form_register', 'apbct_store__urls');
}
add_action('login_enqueue_scripts', 'apbct_login__scripts');
add_action('register_form', 'ct_register_form');
add_filter('registration_errors', 'ct_registration_errors', 1, 3);
add_filter('registration_errors', 'ct_check_registration_errors', 999999, 3);
add_action('user_register', 'apbct_user_register');
// WordPress Multisite registrations
add_action('signup_extra_fields', 'ct_register_form');
add_filter('wpmu_validate_user_signup', 'ct_registration_errors_wpmu', 10, 3);
// Login form - for notifications only
add_filter('login_message', 'ct_login_message');
// Comments output hook
add_filter('wp_list_comments_args', 'ct_wp_list_comments_args');
// Ait-Themes fix
if ( Get::get('ait-action') === 'register' ) {
$tmp = Post::get('redirect_to');
unset($_POST['redirect_to']);
ct_contact_form_validate();
$_POST['redirect_to'] = $tmp;
}
}
/**
* Function for SpamFireWall check
*/
function apbct_sfw__check()
{
global $apbct, $spbc, $cleantalk_url_exclusions;
// Turn off the SpamFireWall if current url in the exceptions list and WordPress core pages
if ( ! empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions) ) {
$core_page_to_skip_check = array('/feed');
foreach ( array_merge($cleantalk_url_exclusions, $core_page_to_skip_check) as $v ) {
if ( apbct_is_in_uri($v) ) {
return;
}
}
}
// Skip the check
if ( ! empty(Get::get('access')) ) {
$spbc_settings = get_option('spbc_settings');
$spbc_key = ! empty($spbc_settings['spbc_key']) ? $spbc_settings['spbc_key'] : false;
if ( Get::get('access') === $apbct->api_key || ($spbc_key !== false && Get::get('access') === $spbc_key) ) {
Cookie::set(
'spbc_firewall_pass_key',
md5(Server::get('REMOTE_ADDR') . $spbc_key),
time() + 1200,
'/',
''
);
Cookie::set(
'ct_sfw_pass_key',
md5(Server::get('REMOTE_ADDR') . $apbct->api_key),
time() + 1200,
'/',
''
);
return;
}
unset($spbc_settings, $spbc_key);
}
// Turn off the SpamFireWall if Remote Call is in progress
if ( $apbct->rc_running || ( ! empty($spbc) && $spbc->rc_running) ) {
return;
}
// update mode - skip checking
if ( isset($apbct->fw_stats['update_mode']) && $apbct->fw_stats['update_mode'] === 1 ) {
return;
}
// Checking if database was outdated
$is_sfw_outdated = $apbct->stats['sfw']['last_update_time'] + $apbct->stats['sfw']['update_period'] * 3 < time();
$apbct->errorToggle(
$is_sfw_outdated,
'sfw_outdated',
esc_html__(
'SpamFireWall database is outdated. Please, try to synchronize with the cloud.',
'cleantalk-spam-protect'
)
);
if ( $is_sfw_outdated ) {
return;
}
$firewall = new Firewall(
DB::getInstance()
);
$sfw_tables_names = SFW::getSFWTablesNames();
if (!$sfw_tables_names) {
$apbct->errorAdd(
'sfw',
esc_html__(
'Can not get SFW table names from main blog options',
'cleantalk-spam-protect'
)
);
return;
}
$firewall->loadFwModule(
new SFW(
APBCT_TBL_FIREWALL_LOG,
$sfw_tables_names['sfw_personal_table_name'],
array(
'sfw_counter' => $apbct->settings['admin_bar__sfw_counter'],
'api_key' => $apbct->api_key,
'apbct' => $apbct,
'cookie_domain' => parse_url(get_option('home'), PHP_URL_HOST),
'data__cookies_type' => $apbct->data['cookies_type'],
'sfw_common_table_name' => $sfw_tables_names['sfw_common_table_name'],
)
)
);
if ( $apbct->settings['sfw__anti_crawler'] && $apbct->stats['sfw']['entries'] > 50 ) {
$firewall->loadFwModule(
new \Cleantalk\ApbctWP\Firewall\AntiCrawler(
APBCT_TBL_FIREWALL_LOG,
APBCT_TBL_AC_LOG,
array(
'api_key' => $apbct->api_key,
'apbct' => $apbct,
)
)
);
}
if ( $apbct->settings['sfw__anti_flood'] && is_null(apbct_wp_get_current_user()) ) {
$firewall->loadFwModule(
new AntiFlood(
APBCT_TBL_FIREWALL_LOG,
APBCT_TBL_AC_LOG,
array(
'api_key' => $apbct->api_key,
'view_limit' => $apbct->settings['sfw__anti_flood__view_limit'],
'apbct' => $apbct,
)
)
);
}
$firewall->run();
}
/**
* Redirects admin to plugin settings after activation.
* @psalm-suppress UnusedVariable
*/
function apbct_plugin_redirect()
{
global $apbct;
wp_suspend_cache_addition(true);
if (
get_option('ct_plugin_do_activation_redirect', false) &&
delete_option('ct_plugin_do_activation_redirect') &&
! Get::get('activate-multi')
) {
ct_account_status_check(null, false);
apbct_sfw_update__init(3); // Updating SFW
wp_redirect($apbct->settings_link);
}
wp_suspend_cache_addition(false);
}
/**
* @param $event_type
*
* @psalm-suppress UnusedVariable
*/
function ct_add_event($event_type)
{
global $apbct, $cleantalk_executed;
//
// To migrate on the new version of ct_add_event().
//
switch ( $event_type ) {
case '0':
$event_type = 'no';
break;
case '1':
$event_type = 'yes';
break;
}
$current_hour = (int)date('G');
// Updating current hour
if ( $current_hour != $apbct->data['current_hour'] ) {
$apbct->data['current_hour'] = $current_hour;
$apbct->data['array_accepted'][$current_hour] = 0;
$apbct->data['array_blocked'][$current_hour] = 0;
}
//Add 1 to counters
if ( $event_type === 'yes' ) {
$apbct->data['array_accepted'][$current_hour]++;
$apbct->data['admin_bar__all_time_counter']['accepted']++;
$apbct->data['user_counter']['accepted']++;
}
if ( $event_type === 'no' ) {