-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleantalk-public.php
1927 lines (1596 loc) · 55.2 KB
/
cleantalk-public.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
/**
* Init functions
* @return mixed[] Array of options
*/
function ct_init() {
global $ct_wplp_result_label, $ct_jp_comments, $ct_post_data_label, $ct_post_data_authnet_label, $ct_formtime_label, $ct_direct_post, $ct_options, $ct_data, $ct_check_post_result, $test_external_forms;
$ct_options=ct_get_options();
$ct_data=ct_get_data();
//fix for EPM registration form
if(isset($_POST) && isset($_POST['reg_email']) && shortcode_exists( 'epm_registration_form' ))
{
unset($_POST['ct_checkjs_register_form']);
}
ct_init_session();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (is_array($_SESSION) && !array_key_exists($ct_formtime_label, $_SESSION) && session_id() != '') {
$ct_direct_post = 1;
}
} else {
/*if(isset($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'],'preview')!==false)
{
//do nothing
}
else
{*/
$_SESSION[$ct_formtime_label] = time();
//}
}
if($test_external_forms && $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['cleantalk_hidden_method']) && isset($_POST['cleantalk_hidden_action']))
{
$action=htmlspecialchars($_POST['cleantalk_hidden_action']);
$method=htmlspecialchars($_POST['cleantalk_hidden_method']);
unset($_POST['cleantalk_hidden_action']);
unset($_POST['cleantalk_hidden_method']);
ct_contact_form_validate();
print "<html><body><form method='$method' action='$action'>";
ct_print_form($_POST,'');
print "</form><center>Redirecting to ".$action."... Anti-spam by CleanTalk.</center></body></html>";
print "<script>document.forms[0].submit();</script>";
die();
}
if(isset($ct_options['general_postdata_test']))
{
$ct_general_postdata_test = @intval($ct_options['general_postdata_test']);
//hook for Anonymous Post
add_action('template_redirect','ct_contact_form_validate_postdata',1);
}
else
{
$ct_general_postdata_test=0;
}
if (isset($ct_options['general_contact_forms_test']) && $ct_options['general_contact_forms_test'] == 1)
{
add_action('CMA_custom_post_type_nav','ct_contact_form_validate_postdata',1);
add_action('template_redirect','ct_contact_form_validate',1);
/*if(isset($_GET['ait-action'])&&$_GET['ait-action']=='register')
{
$tmp=$_POST['redirect_to'];
unset($_POST['redirect_to']);
ct_contact_form_validate();
$_POST['redirect_to']=$tmp;
}*/
}
if($ct_general_postdata_test==1)
{
add_action('CMA_custom_post_type_nav','ct_contact_form_validate_postdata',1);
}
//add_action('wp_footer','ct_ajaxurl');
// Fast Secure contact form
if(defined('FSCF_VERSION')){
add_filter('si_contact_display_after_fields', 'ct_si_contact_display_after_fields');
add_filter('si_contact_form_validate', 'ct_si_contact_form_validate');
}
// WooCoomerse signups
if(class_exists('WooCommerce')){
add_filter('woocommerce_register_post', 'ct_register_post', 1, 3);
}
// JetPack Contact form
$jetpack_active_modules = false;
if(defined('JETPACK__VERSION')){
add_filter('grunion_contact_form_field_html', 'ct_grunion_contact_form_field_html', 10, 2);
if(JETPACK__VERSION=='3.4-beta')
{
add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
}
else if(JETPACK__VERSION=='3.4-beta2'||JETPACK__VERSION>='3.4')
{
add_filter('jetpack_contact_form_is_spam', 'ct_contact_form_is_spam_jetpack',1,2);
}
else
{
add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
}
$jetpack_active_modules = get_option('jetpack_active_modules');
if (
(class_exists( 'Jetpack', false) && $jetpack_active_modules && in_array('comments', $jetpack_active_modules))
) {
$ct_jp_comments = true;
}
}
// Contact Form7
if(defined('WPCF7_VERSION')){
add_filter('wpcf7_form_elements', 'ct_wpcf7_form_elements');
if(WPCF7_VERSION >= '3.0.0')
{
add_filter('wpcf7_spam', 'ct_wpcf7_spam');
}
else
{
add_filter('wpcf7_acceptance', 'ct_wpcf7_spam');
}
}
// Formidable
if(class_exists('FrmSettings')){
add_action('frm_validate_entry', 'ct_frm_validate_entry', 20, 2);
add_action('frm_entries_footer_scripts', 'ct_frm_entries_footer_scripts', 20, 2);
}
// BuddyPress
if(class_exists('BuddyPress')){
add_action('bp_before_registration_submit_buttons','ct_register_form',1);
add_filter('bp_signup_validate', 'ct_registration_errors',1);
}
// bbPress
if(class_exists('bbPress')){
add_filter('bbp_new_topic_pre_content', 'ct_bbp_new_pre_content', 1);
add_filter('bbp_new_reply_pre_content', 'ct_bbp_new_pre_content', 1);
add_action('bbp_theme_before_topic_form_content', 'ct_comment_form');
add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
}
add_action('comment_form', 'ct_comment_form');
//intercept WordPress Landing Pages POST
if (defined('LANDINGPAGES_CURRENT_VERSION') && !empty($_POST)){
if(array_key_exists('action', $_POST) && $_POST['action'] === 'inbound_store_lead'){ // AJAX action(s)
ct_check_wplp();
}else if(array_key_exists('inbound_submitted', $_POST) && $_POST['inbound_submitted'] == '1'){ // Final submit
ct_check_wplp();
}
}
// intercept S2member POST
if (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION') && (isset($_POST[$ct_post_data_label]['email']) || isset($_POST[$ct_post_data_authnet_label]['email']))){
ct_s2member_registration_test();
}
//
// New user approve hack
// https://wordpress.org/plugins/new-user-approve/
//
if (ct_plugin_active('new-user-approve/new-user-approve.php')) {
add_action('register_post', 'ct_register_post', 1, 3);
}
//
// Load JS code to website footer
//
if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
add_action('wp_footer', 'ct_footer_add_cookie', 1);
}
if (ct_is_user_enable()) {
ct_cookies_test();
if (isset($ct_options['general_contact_forms_test']) && $ct_options['general_contact_forms_test'] == 1 && !isset($_POST['comment_post_ID']) && !isset($_GET['for'])) {
$ct_check_post_result=false;
ct_contact_form_validate();
}
if($_SERVER['REQUEST_METHOD'] == 'POST' && $ct_general_postdata_test==1 && !is_admin())
{
$ct_check_post_result=false;
ct_contact_form_validate_postdata();
}
}
}
function ct_ajaxurl() {
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
</script>
<?php
wp_enqueue_script('ct_nocache_js',plugins_url( '/cleantalk_nocache.js' , __FILE__ ));
}
/**
* Adds hidden filed to comment form
*/
function ct_comment_form($post_id) {
global $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
if (ct_is_user_enable() === false) {
return false;
}
if ($ct_options['comments_test'] == 0) {
return false;
}
ct_add_hidden_fields(true, 'ct_checkjs', false, false);
return null;
}
/**
* Adds cookie script filed to footer
*/
function ct_footer_add_cookie() {
if (ct_is_user_enable() === false) {
# return false;
}
ct_add_hidden_fields(true, 'ct_checkjs', false, true);
return null;
}
/**
* Adds hidden filed to define avaialbility of client's JavaScript
* @param bool $random_key switch on generation random key for every page load
*/
function ct_add_hidden_fields($random_key = false, $field_name = 'ct_checkjs', $return_string = false, $cookie_check = false) {
global $ct_checkjs_def, $ct_plugin_name, $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
if(isset($ct_options['use_ajax']))
{
$use_ajax = @intval($ct_options['use_ajax']);
}
else
{
$use_ajax=1;
}
$ct_checkjs_key = ct_get_checkjs_value($random_key);
$field_id_hash = md5(rand(0, 1000));
if ($cookie_check) {
$html = '
<script type="text/javascript">
function ctSetCookie(c_name, value, def_value) {
document.cookie = c_name + "=" + escape(value.replace(/^def_value$/, value)) + "; path=/";
}
ctSetCookie("%s", "%s", "%s");
</script>
';
$html = sprintf($html, $field_name, $ct_checkjs_key, $ct_checkjs_def);
/*!!! IT'S A TEMPORARILY CODE FOR DEBUGGING CF7 !!!*/
if($use_ajax==1)
{
$html='';
}
/*!!! IT'S A TEMPORARILY CODE FOR DEBUGGING CF7 !!!*/
} else {
$ct_input_challenge = sprintf("'%s'", $ct_checkjs_key);
$field_id = $field_name . '_' . $field_id_hash;
$html = '
<input type="hidden" id="%s" name="%s" value="%s" />
<script type="text/javascript">
setTimeout(function(){var ct_input_name = \'%s\';var ct_input_value = document.getElementById(ct_input_name).value;document.getElementById(ct_input_name).value = document.getElementById(ct_input_name).value.replace(ct_input_value, %s); }, 1000);
</script>
';
$html = sprintf($html, $field_id, $field_name, $ct_checkjs_def, $field_id, $ct_input_challenge);
/*!!! IT'S A TEMPORARILY CODE FOR DEBUGGING CF7 !!!*/
if($use_ajax==1)
{
$html='<input type="hidden" id="%s" name="%s" value="%s" />';
$html = sprintf($html, $field_id, $field_name, $ct_checkjs_def);
}
/*!!! IT'S A TEMPORARILY CODE FOR DEBUGGING CF7 !!!*/
};
// Simplify JS code
// and fixing issue with wpautop()
$html = str_replace(array("\n","\r"),'', $html);
if ($return_string === true) {
return $html;
} else {
echo $html;
}
}
/**
* Is enable for user group
* @return boolean
*/
function ct_is_user_enable() {
global $current_user;
if (!isset($current_user->roles)) {
return true;
}
$disable_roles = array('administrator', 'editor', 'author');
foreach ($current_user->roles as $k => $v) {
if (in_array($v, $disable_roles))
return false;
}
return true;
}
/**
* Public function - Insert JS code for spam tests
* return null;
*/
function ct_frm_entries_footer_scripts($fields, $form) {
global $current_user, $ct_checkjs_frm, $ct_options, $ct_data;
if ($ct_options['contact_forms_test'] == 0) {
return false;
}
$ct_checkjs_key = ct_get_checkjs_value();
$ct_frm_name = 'form_' . $form->form_key;
?>
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", "<?php echo $ct_checkjs_frm; ?>");
input.setAttribute("value", "<?php echo $ct_checkjs_key; ?>");
document.getElementById("<?php echo $ct_frm_name; ?>").appendChild(input);
<?php
}
/**
* Public function - Test Formidable data for spam activity
* return @array with errors if spam has found
*/
function ct_frm_validate_entry ($errors, $values) {
global $wpdb, $current_user, $ct_agent_version, $ct_checkjs_frm, $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
if ($ct_options['contact_forms_test'] == 0) {
return false;
}
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
if($checkjs != 1){
$checkjs = js_test($ct_checkjs_frm, $_POST, true);
}
$post_info['comment_type'] = 'feedback';
$post_info = json_encode($post_info);
if ($post_info === false)
$post_info = '';
$sender_email = null;
$message = '';
foreach ($values['item_meta'] as $v) {
if (isset($v) && is_string($v) && preg_match("/^\S+@\S+\.\S+$/", $v)) {
$sender_email = $v;
continue;
}
$message .= ' ' . $v;
}
$ct_base_call_result = ct_base_call(array(
'message' => $message,
'example' => null,
'sender_email' => $sender_email,
'sender_nickname' => null,
'post_info' => $post_info,
'checkjs' => $checkjs
));
$ct = $ct_base_call_result['ct'];
$ct_result = $ct_base_call_result['ct_result'];
if ($ct_result->spam == 1) {
$errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
}
return $errors;
}
/**
* Public filter 'bbp_*' - Checks topics, replies by cleantalk
* @param mixed[] $comment Comment string
* @return mixed[] $comment Comment string
*/
function ct_bbp_new_pre_content ($comment) {
global $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || is_user_logged_in()) {
return $comment;
}
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
if ($checkjs === null) {
$checkjs = js_test('ct_checkjs', $_POST, true);
}
$example = null;
$sender_info = array(
'sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null
);
$post_info['comment_type'] = 'bbpress_comment';
$post_info['post_url'] = bbp_get_topic_permalink();
$post_info = json_encode($post_info);
if ($post_info === false) {
$post_info = '';
}
$ct_base_call_result = ct_base_call(array(
'message' => $comment,
'example' => $example,
'sender_email' => isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null,
'sender_nickname' => isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null,
'post_info' => $post_info,
'checkjs' => $checkjs,
'sender_info' => $sender_info
));
$ct = $ct_base_call_result['ct'];
$ct_result = $ct_base_call_result['ct_result'];
if ($ct_result->stop_queue == 1 || $ct_result->spam == 1 || ($ct_result->allow == 0 && $ct_result->stop_words !== null)) {
bbp_add_error('bbp_reply_content', $ct_result->comment);
}
return $comment;
}
/**
* Public filter 'preprocess_comment' - Checks comment by cleantalk server
* @param mixed[] $comment Comment data array
* @return mixed[] New data array of comment
*/
function ct_preprocess_comment($comment) {
// this action is called just when WP process POST request (adds new comment)
// this action is called by wp-comments-post.php
// after processing WP makes redirect to post page with comment's form by GET request (see above)
global $wpdb, $current_user, $comment_post_id, $ct_agent_version, $ct_comment_done, $ct_approved_request_id_label, $ct_jp_comments, $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
if (ct_is_user_enable() === false || $ct_options['comments_test'] == 0 || $ct_comment_done) {
return $comment;
}
$local_blacklists = wp_blacklist_check(
$comment['comment_author'],
$comment['comment_author_email'],
$comment['comment_author_url'],
$comment['comment_content'],
@$_SERVER['REMOTE_ADDR'],
@$_SERVER['HTTP_USER_AGENT']
);
// Go out if author in local blacklists
if ($local_blacklists === true) {
return $comment;
}
// Skip pingback anti-spam test
if ($comment['comment_type'] == 'pingback') {
return $comment;
}
$ct_comment_done = true;
$comment_post_id = $comment['comment_post_ID'];
$sender_info = array(
'sender_url' => @$comment['comment_author_url']
);
//
// JetPack comments logic
//
$checkjs = 0;
if ($ct_jp_comments) {
$post_info['comment_type'] = 'jetpack_comment';
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
} else {
$post_info['comment_type'] = $comment['comment_type'];
$checkjs = js_test('ct_checkjs', $_POST, true);
}
if($checkjs==0)
{
$checkjs = js_test('ct_checkjs', $_POST, true);
}
if($checkjs==0)
{
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
}
$post_info['post_url'] = ct_post_url(null, $comment_post_id);
$post_info = json_encode($post_info);
if ($post_info === false) {
$post_info = '';
}
$example = null;
if ($ct_options['relevance_test']) {
$post = get_post($comment_post_id);
if ($post !== null){
$example['title'] = $post->post_title;
$example['body'] = $post->post_content;
$example['comments'] = null;
$last_comments = get_comments(array('status' => 'approve', 'number' => 10, 'post_id' => $comment_post_id));
foreach ($last_comments as $post_comment){
$example['comments'] .= "\n\n" . $post_comment->comment_content;
}
$example = json_encode($example);
}
// Use plain string format if've failed with JSON
if ($example === false || $example === null){
$example = ($post->post_title !== null) ? $post->post_title : '';
$example .= ($post->post_content !== null) ? "\n\n" . $post->post_content : '';
}
}
$ct_base_call_result = ct_base_call(array(
'message' => $comment['comment_content'],
'example' => $example,
'sender_email' => $comment['comment_author_email'],
'sender_nickname' => $comment['comment_author'],
'post_info' => $post_info,
'checkjs' => $checkjs,
'sender_info' => $sender_info
));
$ct = $ct_base_call_result['ct'];
$ct_result = $ct_base_call_result['ct_result'];
if ($ct_result->stop_queue == 1) {
$err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_result->comment;
$err_text .= '<script>setTimeout("history.back()", 5000);</script>';
wp_die($err_text, 'Blacklisted', array('back_link' => true));
return $comment;
}
ct_hash($ct_result->id);
if ($ct_result->spam == 1) {
add_filter('pre_comment_approved', 'ct_set_comment_spam');
global $ct_comment;
$ct_comment = $ct_result->comment;
add_action('comment_post', 'ct_die', 12, 2);
add_action('comment_post', 'ct_set_meta', 10, 2);
return $comment;
}
if (isset($comment['comment_author_email'])) {
$approved_comments = get_comments(array('status' => 'approve', 'count' => true, 'author_email' => $comment['comment_author_email']));
// Change comment flow only for new authors
if ((int) $approved_comments == 0 || $ct_result->stop_words !== null) {
if ($ct_result->allow == 1 && get_option('comment_moderation') !== '1') {
add_filter('pre_comment_approved', 'ct_set_approved', 99, 2);
}
if ($ct_result->allow == 0) {
if (isset($ct_result->stop_words)) {
global $ct_stop_words;
$ct_stop_words = $ct_result->stop_words;
add_action('comment_post', 'ct_mark_red', 11, 2);
}
add_filter('pre_comment_approved', 'ct_set_not_approved');
}
add_action('comment_post', 'ct_set_meta', 10, 2);
}
}
return $comment;
}
/**
* Set die page with Cleantalk comment.
* @global type $ct_comment
$err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_comment;
* @param type $comment_status
*/
function ct_die($comment_id, $comment_status) {
global $ct_comment;
$err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $ct_comment;
$err_text .= '<script>setTimeout("history.back()", 5000);</script>';
if(isset($_POST['et_pb_contact_email']))
{
$mes='<div id="et_pb_contact_form_1" class="et_pb_contact_form_container clearfix"><h1 class="et_pb_contact_main_title">Blacklisted</h1><div class="et-pb-contact-message"><p>'.$ct_comment.'</p></div></div>';
wp_die($mes, 'Blacklisted', array('back_link' => true,'response'=>200));
}
else
{
wp_die($err_text, 'Blacklisted', array('back_link' => true));
}
}
/**
* Set die page with Cleantalk comment from parameter.
* @param type $comment_body
*/
function ct_die_extended($comment_body) {
$err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk') . "</center><br><br>\n" . $comment_body;
$err_text .= '<script>setTimeout("history.back()", 5000);</script>';
wp_die($err_text, 'Blacklisted', array('back_link' => true));
}
/**
* Validates JavaScript anti-spam test
*
*/
function js_test($field_name = 'ct_checkjs', $data = null, $random_key = false) {
global $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
$checkjs = null;
$js_post_value = null;
if (!$data)
return $checkjs;
if (isset($data[$field_name])) {
$js_post_value = $data[$field_name];
//
// Random key check
//
if ($random_key) {
$keys = $ct_data['js_keys'];
if (isset($keys[$js_post_value])) {
$checkjs = 1;
} else {
$checkjs = 0;
}
} else {
$ct_challenge = ct_get_checkjs_value();
if(preg_match("/$ct_challenge/", $js_post_value)) {
$checkjs = 1;
} else {
$checkjs = 0;
}
}
}
return $checkjs;
}
/**
* Get post url
* @param int $comment_id
* @param int $comment_post_id
* @return string|bool
*/
function ct_post_url($comment_id = null, $comment_post_id) {
if (empty($comment_post_id))
return null;
if ($comment_id === null) {
$last_comment = get_comments('number=1');
$comment_id = isset($last_comment[0]->comment_ID) ? (int) $last_comment[0]->comment_ID + 1 : 1;
}
$permalink = get_permalink($comment_post_id);
$post_url = null;
if ($permalink !== null)
$post_url = $permalink . '#comment-' . $comment_id;
return $post_url;
}
/**
* Public filter 'pre_comment_approved' - Mark comment unapproved always
* @return int Zero
*/
function ct_set_not_approved() {
return 0;
}
/**
* @author Artem Leontiev
* Public filter 'pre_comment_approved' - Mark comment approved if it's not 'spam' only
* @return int 1
*/
function ct_set_approved($approved, $comment) {
if ($approved == 'spam'){
return $approved;
}else {
return 1;
}
}
/**
* Public filter 'pre_comment_approved' - Mark comment unapproved always
* @return int Zero
*/
function ct_set_comment_spam() {
return 'spam';
}
/**
* Public action 'comment_post' - Store cleantalk hash in comment meta 'ct_hash'
* @param int $comment_id Comment ID
* @param mixed $comment_status Approval status ("spam", or 0/1), not used
*/
function ct_set_meta($comment_id, $comment_status) {
global $comment_post_id;
$hash1 = ct_hash();
if (!empty($hash1)) {
update_comment_meta($comment_id, 'ct_hash', $hash1);
if (function_exists('base64_encode') && isset($comment_status) && $comment_status != 'spam') {
$post_url = ct_post_url($comment_id, $comment_post_id);
$post_url = base64_encode($post_url);
if ($post_url === false)
return false;
// 01 - URL to approved comment
$feedback_request = $hash1 . ':' . '01' . ':' . $post_url . ';';
ct_send_feedback($feedback_request);
}
}
return true;
}
/**
* Mark bad words
* @global string $ct_stop_words
* @param int $comment_id
* @param int $comment_status Not use
*/
function ct_mark_red($comment_id, $comment_status) {
global $ct_stop_words;
$comment = get_comment($comment_id, 'ARRAY_A');
$message = $comment['comment_content'];
foreach (explode(':', $ct_stop_words) as $word) {
$message = preg_replace("/($word)/ui", '<font rel="cleantalk" color="#FF1000">' . "$1" . '</font>', $message);
}
$comment['comment_content'] = $message;
kses_remove_filters();
wp_update_comment($comment);
}
/**
* Tests plugin activation status
* @return bool
*/
function ct_plugin_active($plugin_name){
foreach (get_option('active_plugins') as $k => $v) {
if ($plugin_name == $v)
return true;
}
return false;
}
/**
* Insert a hidden field to registration form
* @return null
*/
function ct_register_form() {
global $ct_checkjs_register_form, $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
if ($ct_options['registrations_test'] == 0) {
return false;
}
ct_add_hidden_fields(true, $ct_checkjs_register_form, false);
return null;
}
/**
* Adds notification text to login form - to inform about approced registration
* @return null
*/
function ct_login_message($message) {
global $errors, $ct_session_register_ok_label, $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
if ($ct_options['registrations_test'] != 0) {
if( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) {
if (isset($_SESSION[$ct_session_register_ok_label])) {
unset($_SESSION[$ct_session_register_ok_label]);
if(is_wp_error($errors))
$errors->add('ct_message','<br />' . sprintf(__('Registration is approved by %s.', 'cleantalk'), '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk</b>'), 'message');
}
}
}
return $message;
}
/**
* Test users registration for multisite enviroment
* @return array with errors
*/
function ct_registration_errors_wpmu($errors) {
global $ct_signup_done;
//
// Multisite actions
//
$sanitized_user_login = null;
if (isset($errors['user_name'])) {
$sanitized_user_login = $errors['user_name'];
$wpmu = true;
}
$user_email = null;
if (isset($errors['user_email'])) {
$user_email = $errors['user_email'];
$wpmu = true;
}
if ($wpmu && isset($errors['errors']->errors) && count($errors['errors']->errors) > 0) {
return $errors;
}
$errors['errors'] = ct_registration_errors($errors['errors'], $sanitized_user_login, $user_email);
// Show CleanTalk errors in user_name field
if (isset($errors['errors']->errors['ct_error'])) {
$errors['errors']->errors['user_name'] = $errors['errors']->errors['ct_error'];
unset($errors['errors']->errors['ct_error']);
}
return $errors;
}
/**
* Shell for action register_post
* @return array with errors
*/
function ct_register_post($sanitized_user_login = null, $user_email = null, $errors) {
return ct_registration_errors($errors, $sanitized_user_login, $user_email);
}
/**
* Check messages for external plugins
* @return array with checking result;
*/
function ct_test_message($nickname, $email, $ip, $text){
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
$post_info['comment_type'] = 'feedback_plugin_check';
$post_info = json_encode($post_info);
$ct_base_call_result = ct_base_call(array(
'message' => $text,
'example' => null,
'sender_email' => $email,
'sender_nickname' => $nickname,
'post_info' => $post_info,
'sender_info' => get_sender_info(),
'checkjs' => $checkjs
));
$ct_result = $ct_base_call_result['ct_result'];
$result=Array(
'allow' => $ct_result->allow,
'comment' => $ct_result->comment,
);
return $result;
}
/**
* Check registrations for external plugins
* @return array with checking result;
*/
function ct_test_registration($nickname, $email, $ip){
global $ct_checkjs_register_form, $ct_agent_version, $ct_options, $ct_data;
$ct_options = ct_get_options();
$ct_data = ct_get_data();
$submit_time = submit_time_test();
$sender_info = get_sender_info();
$checkjs=0;
$checkjs = js_test($ct_checkjs_register_form, $_POST, true);
$sender_info['post_checkjs_passed'] = $checkjs;
//
// This hack can be helpfull when plugin uses with untested themes&signups plugins.
//
if ($checkjs == 0) {
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
$sender_info['cookie_checkjs_passed'] = $checkjs;
}
$sender_info = json_encode($sender_info);
if ($sender_info === false) {
$sender_info= '';
}
require_once('cleantalk.class.php');
$config = get_option('cleantalk_server');
$ct = new Cleantalk();
$ct->work_url = $config['ct_work_url'];
$ct->server_url = $ct_options['server'];
$ct->server_ttl = $config['ct_server_ttl'];
$ct->server_changed = $config['ct_server_changed'];
$ct->ssl_on = $ct_options['ssl_on'];
$ct_request = new CleantalkRequest();
$ct_request->auth_key = $ct_options['apikey'];
$ct_request->sender_email = $email;
$ct_request->sender_ip = $ip;
$ct_request->sender_nickname = $nickname;
$ct_request->agent = $ct_agent_version;
$ct_request->sender_info = $sender_info;
$ct_request->js_on = $checkjs;
$ct_request->submit_time = $submit_time;
$ct_result = $ct->isAllowUser($ct_request);
if ($ct_result->errno != 0 && $checkjs==0)
{
$ct_result->allow=0;
}
$result=Array(
'allow' => $ct_result->allow,
'comment' => $ct_result->comment,
);
return $result;
}
/**
* Test users registration
* @return array with errors
*/
function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
global $ct_agent_version, $ct_checkjs_register_form, $ct_session_request_id_label, $ct_session_register_ok_label, $bp, $ct_signup_done, $ct_formtime_label, $ct_negative_comment, $ct_options, $ct_data;
$ct_options=ct_get_options();
$ct_data=ct_get_data();
// Go out if a registrered user action
if (ct_is_user_enable() === false) {
return $errors;
}
if ($ct_options['registrations_test'] == 0) {
return $errors;
}
//
// The function already executed
// It happens when used ct_register_post();
//
if ($ct_signup_done && is_object($errors) && count($errors->errors) > 0) {