forked from joseconti/WangGuard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwangguard-admin.php
2437 lines (2415 loc) · 109 KB
/
wangguard-admin.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: WangGuard
Plugin URI: http://www.wangguard.com
Description: <strong>Stop Sploggers</strong>. It is very important to use <a href="http://www.wangguard.com" target="_new">WangGuard</a> at least for a week, reporting your site's unwanted users as sploggers from the Users panel. WangGuard will learn at that time to protect your site from sploggers in a much more effective way. WangGuard protects each web site in a personalized way using information provided by Administrators who report sploggers world-wide, that's why it's very important that you report your sploggers to WangGuard. The longer you use WangGuard, the more effective it will become.
Version: 1.7-RC1
Author: WangGuard
Author URI: http://www.wangguard.com
License: GPL2
*/
/* Copyright 2010 WangGuard (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define('WANGGUARD_VERSION', '1.7-RC1');
define('WANGGUARD_PLUGIN_FILE', 'wangguard/wangguard-admin.php');
define('WANGGUARD_README_URL', 'http://plugins.trac.wordpress.org/browser/wangguard/trunk/readme.txt?format=txt');
define('WANGGUARD_API_HOST', 'rest.wangguard.com');
define('WANGGUARD_REST_PATH', '/');
if ( ( get_site_option("wangguard-no-use-ssl") == '1' ) ) {
define('WANGGUARD_API_PORT', '80');
} else {
define('WANGGUARD_API_PORT', '443');
}
/**
* Include some helpers
*/
include_once( 'inc/helpers/helpers.php' );
register_activation_hook(__FILE__,'wangguard_install');
// Debug WangGuard
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
//Which file are we are getting called from?
$wuangguard_parent = basename($_SERVER['SCRIPT_NAME']);
if( defined('WANGUARD_VERSION' ) ) { $wangguard_version = WANGGUARD_VERSION; }
$wangguard_is_network_admin = function_exists("is_multisite") && function_exists( 'is_network_admin' );
if ($wangguard_is_network_admin)$wangguard_is_network_admin = is_multisite();
include_once 'wangguard-xml.php';
include_once 'wangguard-core.php';
$wangguard_api_key = get_site_option('wangguard_api_key');
$wangguard_cronjob_run_options = array("daily"=> __('Once a day', 'wangguard'),"wangguard_3days"=> __('Every 3 days', 'wangguard'),"wangguard_5days"=> __('Every 5 days', 'wangguard'),"wangguard_weekly"=> __('Weekly', 'wangguard'),"wangguard_2weeks"=> __('Two Weeks', 'wangguard'));
$wangguard_cronjob_actions_options = array("f"=>__('Flag detected Sploggers as Sploggers and Spam users', 'wangguard') ,"d"=>__('Delete detected Sploggers', 'wangguard'));
$wangguard_cronjob_lookup_options = array("7"=>__('Week', 'wangguard') ,"5"=>__('5 days', 'wangguard'),"3"=>__('3 days', 'wangguard'),"1"=>__('1 day', 'wangguard'));
/********************************************************************/
/*** CONFIG BEGINS ***/
/********************************************************************/
include_once 'wangguard-conf.php';
include_once 'wangguard-queue.php';
include_once 'wangguard-wizard.php';
include_once 'wangguard-cronjobs.php';
include_once 'wangguard-stats.php';
include_once 'wangguard-users.php';
include_once 'wangguard-user-info.php';
include_once 'wangguard-help.php';
include_once 'wangguard-about.php';
include_once 'wangguard-compatible-plugins.php';
include_once 'wangguard-addons.php';
include_once 'wangguard-allow-signup-splogger-detected.php';
$wggmoderationisactive = get_site_option('wangguard-moderation-is-active');
if( empty( $wggmoderationisactive ) ) $wggmoderationisactive = '0';
if( $wggmoderationisactive == '1' ) include_once 'wangguard-block-login-moderation.php';
/********************************************************************/
/*** CONFIG ENDS ***/
/********************************************************************/
/********************************************************************/
/*** ADD & VALIDATE SECURITY QUESTIONS ON REGISTER BEGINS ***/
/********************************************************************/
// for wp regular
if ( get_site_option("wangguard-add-honeypot")== '1' ) {
add_action('register_form','wangguard_add_hfield_1' , rand(1,10));
add_action('register_form','wangguard_add_hfield_2' , rand(1,10));
add_action('register_form','wangguard_add_hfield_3' , rand(1,10));
add_action('register_form','wangguard_add_hfield_4' , rand(1,10));
}
add_action('register_form','wangguard_register_add_question');
add_action('register_post','wangguard_signup_validate',10,3);
// for WooCommerce
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action('woocommerce_after_checkout_validation','wangguard_plugin_woocommerce_checkout_signup');
}
$wangguard_add_mu_filter_actions = true;
//Calling to functions for BuddyPress
function wangguard_buddypress_init() {
require( dirname( __FILE__ ) . '/wangguard-buddypress.php' );
}
add_action( 'bp_include', 'wangguard_buddypress_init' );
// if (has_action( 'bp_include', 'wangguard_buddypress_init' ) ) $wangguard_add_mu_filter_actions = false;
// for wpmu and (buddypress versions before 1.1)
if ( defined( 'BP_VERSION' ) ) $wangguard_add_mu_filter_actions = false;
if($wangguard_add_mu_filter_actions){
if ( get_site_option("wangguard-add-honeypot")=='1') {
add_action('signup_extra_fields','wangguard_add_hfield_1' , rand(1,10));
add_action('signup_extra_fields','wangguard_add_hfield_2' , rand(1,10));
add_action('signup_extra_fields','wangguard_add_hfield_3' , rand(1,10));
add_action('signup_extra_fields','wangguard_add_hfield_4' , rand(1,10));
}
add_action('signup_extra_fields', 'wangguard_register_add_question_mu' );
add_filter('wpmu_validate_user_signup', 'wangguard_wpmu_signup_validate_mu', 90);
}
/**
* Checks MX record for an email domain's
*
* @param type $email
* @return boolean
*/
function wangguard_mx_record_is_ok($email) {
//checks if an associated MX record is found on the server's DNS for the email domain
//option is activated and getmxrr() function exists?
$wangguard_mx_ok = function_exists('getmxrr');
if ( !$wangguard_mx_ok || get_site_option("wangguard-verify-dns-mx")!='1')return true;
$email = explode("@" , $email);
if( count($email) != 2 )return true;
$mxr = array();
$ret = getmxrr($email[1] , $mxr);
return $ret && count($mxr);
}
/**
* Cleans username from an email address
*/
function wangguard_get_clean_gmail_username($email) {
//Cleans dots and + from gmail.com and googlemail.com addresses, lowercases the username and returns it. Returns false otherwise.
$email = explode("@" , $email);
if( count($email) != 2 )return false;
$email[1] = strtolower($email[1]);
if ( ($email[1] == "gmail.com") || ($email[1] == "googlemail.com") ) {
$email[0] = str_replace(".", "" , $email[0]);
//if the gmail address has a plus sign, remove from it to the end as gmail ignores that
if ( strpos( $email[0] , "+") !== false) {
$email[0] = substr($email[0] , 0 , strpos( $email[0] , "+"));
}
return strtolower($email[0]);
} else return false;
}
/**
* Checks wheter an alias of an email already exists
*
* @global type $wpdb
* @param type $email
* @return boolean
*/
function wangguard_email_aliases_exists($email) {
global $wpdb;
//option is activated?
if ( get_site_option("wangguard-verify-gmail")!='1') return false;
//cleans the email
$guser = wangguard_get_clean_gmail_username($email);
if ($guser !== false) {
//if the email already exists, WP catches it, there's no need for WangGuard to check for aliases
if (email_exists($email))return false;
//get gmail.com and googlemail.com registered users
$gmailaddresses = $wpdb->get_results("select user_email from {$wpdb->users}
where LOWER(user_email) LIKE '%@gmail.com' OR LOWER(user_email) LIKE '%@googlemail.com'");
if (!empty ($gmailaddresses)) {
foreach ($gmailaddresses as $r) {
$existing = wangguard_get_clean_gmail_username($r->user_email);
if ($existing == $guser)return true;
}
}
}
return false;
}
$wangguard_NonceHName = 'wangguard-hidden-field-check';
$wangguard_NonceFName = 'wangguard-hidden-display-check';
$wangguard_NoncePName = 'wangguard-hidden-position-check';
$wangguard_NonceCName = 'wangguard-hidden-check-check';
$wangguard_HPrefix = 'signup_';
$wangguard_FPrefix = 'newsignup_';
//$prefix = $wpdb->prefix;
/**
* Get a random string
*/
function wangguard_randomstring($rndLen) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$str = '';
$strlen = strlen($chars);
for ($i=0; $i < $rndLen; $i++){
$str .= substr($chars, mt_rand(0, $strlen - 1), 1);
}
return $str;
}
function wangguard_add_hfield_1() {
global $wangguard_NonceHName , $wangguard_HPrefix;
$nonceAct = $wangguard_NonceHName;
$nonceValue = wp_create_nonce( $nonceAct );
$fieldID = wangguard_randomstring(mt_rand(6,10));
$nonce_field = '<![if !IE]><input autocomplete="off" type="hidden" id="' . $fieldID . '" name="' . $wangguard_HPrefix . $nonceValue . '" value="" /><![endif]>';
echo $nonce_field;
}
function wangguard_add_hfield_2() {
global $wangguard_NonceFName , $wangguard_FPrefix;
$style = wangguard_randomstring(mt_rand(6,10));
$fieldID = wangguard_randomstring(mt_rand(6,10));
echo '<![if !IE]><style type="text/css">.'.$style.' {visibility:hidden!important; display:none!important;}</style>';
$nonceAct = $wangguard_NonceFName;
$nonceValue = wp_create_nonce( $nonceAct );
$nonce_field = '<div class="'.$style.'"><input autocomplete="off" type="text" id="' . $fieldID . '" name="' . $wangguard_FPrefix . $nonceValue . '" value="" /></div><![endif]>';
echo $nonce_field;
}
function wangguard_add_hfield_3() {
global $wangguard_NoncePName;
$style = wangguard_randomstring(mt_rand(6,10));
$fieldID = wangguard_randomstring(mt_rand(6,10));
$cssStyle = 'visibility:hidden!important; display:none!important; position:absolute; top:-'.mt_rand(10000 , 20000).'px;';
$question = wangguard_randomstring(mt_rand(6,10));
$nonceAct = $wangguard_NoncePName;
$nonceValue = wp_create_nonce( $nonceAct );
$nonce_field = '<![if !IE]><div style="' .$cssStyle.'"><label for="'.$nonceValue.'">'.$question.'</label><br/><input autocomplete="off" tabindex="'.mt_rand(9999,99999).'" type="text" id="' . $fieldID . '" name="' . $nonceValue . '" value="" /></div><![endif]>';
echo $nonce_field;
}
function wangguard_add_hfield_4() {
global $wangguard_NonceCName;
$style = wangguard_randomstring(mt_rand(6,10));
$fieldID = wangguard_randomstring(mt_rand(6,10));
echo '<![if !IE]><style type="text/css">.'.$style.' {visibility:hidden!important; display:none!important;}</style>';
$nonceAct = $wangguard_NonceCName;
$nonceValue = wp_create_nonce( $nonceAct );
$nonce_field = '<div class="'.$style.'"><input autocomplete="off" type="text" value="" id="' . $fieldID . '" name="' . $nonceValue . '" /></div><![endif]>';
echo $nonce_field;
}
/**
* WangGuard nonce
*/
function wangguard_get_nonce_value($action) {
$user = wp_get_current_user();
$uid = (int) $user->ID;
$i = wp_nonce_tick();
return substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10);
}
/**
* Validates if there is suspicius activity on signup
*
* @global string $wangguard_NonceHName
* @global string $wangguard_HPrefix
* @global string $wangguard_NonceFName
* @global string $wangguard_FPrefix
* @global string $wangguard_NoncePName
* @global string $wangguard_NonceCName
* @param type $userEmail
* @return boolean
*/
function wangguard_validate_hfields($userEmail) {
global $wangguard_NonceHName , $wangguard_HPrefix;
global $wangguard_NonceFName , $wangguard_FPrefix;
global $wangguard_NoncePName;
global $wangguard_NonceCName;
$hNonce = wangguard_get_nonce_value($wangguard_NonceHName);
$fNonce = wangguard_get_nonce_value($wangguard_NonceFName);
$pNonce = wangguard_get_nonce_value($wangguard_NoncePName);
$cNonce = wangguard_get_nonce_value($wangguard_NonceCName);
$validated = empty ($_POST[$wangguard_HPrefix.$hNonce]) &&empty ($_POST[$wangguard_FPrefix.$fNonce]) &&empty ($_POST[$pNonce]) &&empty ($_POST[$cNonce]);
if (!$validated) {
wangguard_report_email($userEmail , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() , true);
}
return $validated;
}
//*********** WPMU ***********
/**
* Adds a security question if any exists
*
* @global type $wpdb
* @param type $errors
*/
function wangguard_register_add_question_mu($errors) {
global $wpdb;
$table_name = $wpdb->base_prefix . "wangguardquestions";
//Get one random question from the question table
$qrs = $wpdb->get_row("select * from $table_name order by RAND() LIMIT 1");
if (!is_null($qrs)) {
$question = $qrs->Question;
$questionID = $qrs->id;
$html = '
<label for="wangguardquestansw">' . $question . '</label>';
echo $html;
if ( $errmsg = $errors->get_error_message('wangguardquestansw') ) {
echo '<p class="error">'.$errmsg.'</p>';
}
$html = '
<input type="text" name="wangguardquestansw" id="wangguardquestansw" class="wangguard-mu-register-field" value="" maxlength="50" />
<input type="hidden" name="wangguardquest" value="'.$questionID.'" />';
echo $html;
}
}
/**
* Validates security question
*
* @global type $wangguard_bp_validated
* @param type $param
* @return array
*/
function wangguard_wpmu_signup_validate_mu($result) {
global $wangguard_bp_validated;
if ( strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false ) {
return $result;
}
$wggmoderationisactive = get_site_option('wangguard-moderation-is-active');
if( empty( $wggmoderationisactive ) ) $wggmoderationisactive = '0';
if( isset( $_POST['signup_email'] ) ) return;
if( isset( $_POST['user_email'] ) && !empty( $_POST['user_email'] ) ){$user_email = sanitize_email($_POST['user_email']);}else{$user_email=$user_email;}
//$user_email = $_POST['user_email'];
//BP1.1+ calls the new BP filter first (wangguard_signup_validate_bp11) and then the legacy MU filters (this one), if the BP new 1.1+ filter has been already called, silently return
if ( wangguard_look_for_allowed_email($user_email) ) return $result;
if ($wangguard_bp_validated)return $result;
if (!wangguard_validate_hfields($user_email)) {
$result['errors']->add('user_name', __('<strong>ERROR</strong>: Banned by WangGuard <a href="http://www.wangguard.com/faq" target="_new">Is it an error?</a> Perhaps you tried to register many times.', 'wangguard'));
return $result;
}
$answerOK = wangguard_question_repliedOK();
//If at least a question exists on the questions table, then check the provided answer
if (!$answerOK) { $result['errors']->add('wangguardquestansw', __('<strong>ERROR</strong>: The answer to the security question is invalid.', 'wangguard')); } else {
//check domain against the list of selected blocked domains
$blocked = wangguard_is_domain_blocked($user_email);
if ($blocked) {
$result['errors']->add('user_email', __('<strong>ERROR</strong>: Domain not allowed.', 'wangguard'));
} else {
if( $wggmoderationisactive == '0' ){
$reported = wangguard_is_email_reported_as_sp($user_email , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP());
if ($reported) $result['errors']->add('user_email', __('<strong>ERROR</strong>: Banned by WangGuard <a href="http://www.wangguard.com/faq" target="_new">Is it an error?</a> Perhaps you tried to register many times.', 'wangguard')); else
if (wangguard_email_aliases_exists($user_email))$result['errors']->add('user_email', __('<strong>ERROR</strong>: Duplicate alias email found by WangGuard.', 'wangguard')); else
if (!wangguard_mx_record_is_ok($user_email))$result['errors']->add('user_email', __("<strong>ERROR</strong>: WangGuard couldn't find an MX record associated with your email domain.", 'wangguard'));
}
}
}
return $result;
}
//*********** WPMU ***********
//*********** BP1.1+ ***********
/**
* Adds a security question if any exists
*
* @global type $wpdb
* @return array
*/
function wangguard_register_add_question_bp11(){
global $wpdb;
if ( strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false ) {
return $param;
}
$table_name = $wpdb->base_prefix . "wangguardquestions";
//Get one random question from the question table
$qrs = $wpdb->get_row("select * from $table_name order by RAND() LIMIT 1");
if (!is_null($qrs)) {
$question = $qrs->Question;
$questionID = $qrs->id;
$html = '
<div class="register-section wangguard">
<label for="wangguardquestansw">' . $question . '</label>';
echo $html;
do_action( 'bp_wangguardquestansw_errors' );
$html = '
<input type="text" name="wangguardquestansw" id="wangguardquestansw" value="" maxlength="50" />
<input type="hidden" name="wangguardquest" value="'.$questionID.'" />
</div>';
echo $html;
}
}
function wangguard_fix_bp_slashes_maybe($str) {
if (defined('BP_VERSION')) {
if ( version_compare(BP_VERSION, '1.5.5') < 0 )$str = addslashes($str);
return $str;
} else return $str;
}
//*********** BP1.1+ ***********
//*********** WP REGULAR ***********
/**
* Adds a security question if any exists
*
* @global type $wpdb
*/
function wangguard_register_add_question(){
global $wpdb;
$table_name = $wpdb->base_prefix . "wangguardquestions";
//Get one random question from the question table
$qrs = $wpdb->get_row("select * from $table_name order by RAND() LIMIT 1");
if (!is_null($qrs)) {
$question = $qrs->Question;
$questionID = $qrs->id;
if ( ! defined( 'APP_FRAMEWORK_DIR' ) ){
$html = '
<p>
<label>' . $question . '<br />
<input type="text" name="wangguardquestansw" id="wangguardquestansw" class="input wpreg-wangguardquestansw" value="" tabindex="26" />
<input type="hidden" name="wangguardquest" value="'.$questionID.'" />
</p>';
echo $html;
} else {
$AppthemeName = get_theme_data( get_template_directory() . '/style.css' );
if ('JobRoller' == $AppthemeName['Title']) {
$html = '
<p>
<label>' . $question . '</label><br />
<input type="text" name="wangguardquestansw" id="wangguardquestansw" class="input wpreg-wangguardquestansw text" value="" tabindex="26" />
<input type="hidden" name="wangguardquest" value="'.$questionID.'" />
</p>';
}
elseif (('ClassiPress' == $AppthemeName['Title']) || ('Clipper' == $AppthemeName['Title'])) {
$html = '
<p>
<label>' . $question . ': </label>
<input type="text" name="wangguardquestansw" id="wangguardquestansw" class="input wpreg-wangguardquestansw text" value="" tabindex="26" />
<input type="hidden" name="wangguardquest" value="'.$questionID.'" />
</p>';
}
elseif (('Vantage' == $AppthemeName['Title']) || ('Quality Control' == $AppthemeName['Title'])) {
$html = '
<div class="form-field">
<label>
' . $question . ' <input tabindex="1" type="text" class="text required wpreg-wangguardquestansw" name="wangguardquestansw" id="wangguardquestansw" value="">
<input type="hidden" name="wangguardquest" value="'.$questionID.'" />
</label>
</div>';
}
elseif ('Ideas' == $AppthemeName['Title']) {
$html = '
<p>
<label>' . $question . '</label>
<input tabindex="3" type="text" name="wangguardquestansw" id="wangguardquestansw" value="" class="required">
<input type="hidden" name="wangguardquest" value="'.$questionID.'" />
</p>';
}
echo $html;
}
}
}
/**
* Validates security question
*
* @param type $user_name
* @param type $user_email
* @param type $errors
*/
function wangguard_signup_validate($user_name, $user_email, $errors){
//if ($_POST['user_email']){ $user_email = $_POST['user_email']; }else{ $user_email = $user_email; }
$wggstopcheck = false;
do_action('pre_wangguard_validate_signup_form_wordpress_no_multisite', $user_email);
$wggstopcheck = apply_filters('pre_wangguard_validate_signup_form_wordpress_no_multisite', $wggstopcheck );
$wggmoderationisactive = get_site_option('wangguard-moderation-is-active');
if( empty( $wggmoderationisactive ) ) $wggmoderationisactive = '0';
if ( !$wggstopcheck ){
if (!wangguard_validate_hfields($user_email)) {
$errors->add('user_login',__('<strong>ERROR</strong>: Banned by WangGuard <a href="http://www.wangguard.com/faq" target="_new">Is it an error?</a> Perhaps you tried to register many times.', 'wangguard'));
return;
}
$answerOK = wangguard_question_repliedOK();
//If at least a question exists on the questions table, then check the provided answer
if (!$answerOK)$errors->add('wangguard_error',__('<strong>ERROR</strong>: The answer to the security question is invalid.', 'wangguard')); else {
//check domain against the list of selected blocked domains
$blocked = wangguard_is_domain_blocked($user_email);
if ($blocked) {
$errors->add('wangguard_error',__('<strong>ERROR</strong>: Domain not allowed.', 'wangguard'));
} else {
if( $wggmoderationisactive == '0' ){
$reported = wangguard_is_email_reported_as_sp($user_email, wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() , true);
if ($reported)$errors->add('wangguard_error',__('<strong>ERROR</strong>: Banned by WangGuard <a href="http://www.wangguard.com/faq" target="_new">Is it an error?</a> Perhaps you tried to register many times.', 'wangguard')); else
if (wangguard_email_aliases_exists($user_email))$errors->add('wangguard_error', __('<strong>ERROR</strong>: Duplicate alias email found by WangGuard.', 'wangguard')); else
if (!wangguard_mx_record_is_ok($user_email))$errors->add('wangguard_error', __("<strong>ERROR</strong>: WangGuard couldn't find an MX record associated with your email domain.", 'wangguard'));
}
}
}
}
}
//*********** WP REGULAR ***********
/**
* Checks if a domain for an email address is selected to be blocked on the "Blocked domains" configuration screen
*
* @param type $email
*/
function wangguard_is_domain_blocked($email) {
$parts = explode("@", $email);
//if email is not well formed, return TRUE, this should never happens as WP already checks for a valid email format
if (count($parts) != 2)return true;
$domain = strtolower($parts[1]);
$selectedDomains = maybe_unserialize( get_site_option('blocked-list-domains') );
if (!is_array($selectedDomains)) $selectedDomains = array();
//matches exact domain?
if (isset($selectedDomains[$domain]))return true;
$domainParts = explode(".", $domain);
if (count($domainParts) > 1) {
$subdomcheck = $domainParts[count($domainParts)-1];
//check for the top level domain
if (isset($selectedDomains["*." . $subdomcheck]))return true;
//n-level domains
$from = count($domainParts)-2;
for ($i = $from ; $i>=0 ; $i-- ) {
$subdomcheck = $domainParts[$i] . "." . $subdomcheck;
if (isset($selectedDomains["*." . $subdomcheck]))return true;
}
} else //malformed domain
return true;
return false;
}
/**
* Verifies the email against WangGuard service
*
* @global type $wpdb
* @global type $wangguard_api_key
* @global type $wangguard_user_check_status
* @param type $email
* @param type $clientIP
* @param type $callingFromRegularWPHook regular WP hook sends true on this param
* @return boolean
*/
function wangguard_is_email_reported_as_sp($email , $clientIP , $ProxyIP , $callingFromRegularWPHook = false) {
global $wpdb;
global $wangguard_api_key;
global $wangguard_user_check_status;
if (empty ($wangguard_api_key))return false;
$wangguard_user_check_status = "not-checked";
if ( get_site_option("wangguard-do-not-check-client-ip")=='1') {
$clientIP = '';
$ProxyIP = '';
}
$response = wangguard_http_post("wg=<in><apikey>$wangguard_api_key</apikey><email>".$email."</email><ip>".$clientIP."</ip><proxyip>".$ProxyIP."</proxyip></in>", 'query-email.php');
$responseArr = WGG_XML_unserialize($response);
wangguard_stats_update("check");
if ( is_array($responseArr)) {
if (($responseArr['out']['cod'] == '10') || ($responseArr['out']['cod'] == '11')) {
wangguard_stats_update("detected");
return true;
} else {
if ($responseArr['out']['cod'] == '20') {
$wangguard_user_check_status = 'checked';
}
elseif ($responseArr['out']['cod'] == '100')$wangguard_user_check_status = 'error:' . __('Your WangGuard API KEY is invalid.', 'wangguard'); else $wangguard_user_check_status = 'error:'.$responseArr['out']['cod'];
}
}
return false;
}
/**
* Verifies the security question, used from the WP, WPMU and BP validation functions
* @global type $wpdb
* @return boolean
*/
function wangguard_question_repliedOK() {
//WP 3.2.1 multisite introduces a new two step registration, on step 2 we don't have to check the security question as it was checked in the step 1
if (@$_POST['stage'] == 'validate-blog-signup') {
if (!wp_verify_nonce($_POST['_signup_form'] , 'signup_form_' . $_POST['signup_form_id']))return false; else return true;
}
global $wpdb;
$table_name = $wpdb->base_prefix . "wangguardquestions";
//How many questions are created?
$questionCount = $wpdb->get_col("select count(*) as q from $table_name");
$answerOK = true;
//If at least a question exists on the questions table, then check the provided answer
if ($questionCount[0]) {
$questionID = intval($_REQUEST['wangguardquest']);
$answer = $_REQUEST['wangguardquestansw'];
$qrs = $wpdb->get_row( $wpdb->prepare("select * from $table_name where id = %d" , $questionID));
if (!is_null($qrs)) {
if (mb_strtolower( $_REQUEST['wangguardquestansw'] ) == mb_strtolower( $qrs->Answer ) ) {
$wpdb->query( $wpdb->prepare("update $table_name set RepliedOK = RepliedOK + 1 where id = %d" , $questionID ) );
} else {
$answerOK = false;
$wpdb->query( $wpdb->prepare("update $table_name set RepliedWRONG = RepliedWRONG + 1 where id = %d" , $questionID ) );
}
} else {
$answerOK = false;
$wpdb->query( $wpdb->prepare("update $table_name set RepliedWRONG = RepliedWRONG + 1 where id = %d" , $questionID ) );
}
}
return $answerOK;
}
/********************************************************************/
/*** ADD & VALIDATE SECURITY QUESTIONS ON REGISTER ENDS ***/
/********************************************************************/
/********************************************************************/
/*** USER REGISTATION & DELETE FILTERS BEGINS ***/
/********************************************************************/
// user register and delete actions
add_action('user_register','wangguard_plugin_user_register');
add_action('bp_complete_signup','wangguard_plugin_bp_complete_signup');
add_action('bp_core_activated_user','wangguard_bp_core_activated_user' , 10 , 3);
add_action('wpmu_activate_user','wangguard_wpmu_activate_user' , 10 , 3);
add_action('delete_user','wangguard_plugin_user_delete');
add_action('wpmu_delete_user','wangguard_plugin_user_delete');
add_action('make_spam_user','wangguard_make_spam_user');
add_action('make_ham_user','wangguard_make_ham_user');
add_action('bp_core_action_set_spammer_status','wangguard_bp_core_action_set_spammer_status' , 10 , 2);
/**
* Save the status of the verification upon BP signups
*
* @global type $wpdb
* @global type $wangguard_user_check_status
*/
function wangguard_plugin_bp_complete_signup() {
global $wpdb;
global $wangguard_user_check_status;
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
//delete just in case a previous record from a user which didn't activate the account is there
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $_POST['signup_username']));
//Insert the new signup record
$wpdb->query( $wpdb->prepare("insert into $table_name(signup_username , user_status , user_ip , user_proxy_ip) values ('%s' , '%s' , '%s' , '%s')" , $_POST['signup_username'] , $wangguard_user_check_status , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() ) );
}
/**
WooCommerce
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function wangguard_plugin_woocommerce_checkout_signup() {
global $wpdb, $current_user;
global $wangguard_user_check_status;
global $woocommerce;
if ((isset( $_POST['createaccount'] ) && ($_POST['createaccount'] == 1)) && (isset( $_POST['payment_method'] ) )){
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
//delete just in case a previous record from a user which didn't activate the account is there
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $_POST['account_username']));
//Insert the new signup record
$wangguard_user_check_status = 'buyer';
$wpdb->query( $wpdb->prepare("insert into $table_name(signup_username , user_status , user_ip , user_proxy_ip) values ('%s' , '%s' , '%s' , '%s')" , $_POST['account_username'] , $wangguard_user_check_status , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() ) );
}
elseif (isset( $_POST['payment_method'] ) ) {
get_currentuserinfo();
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
$WangUser_login = $current_user->user_login;
$WangUser_ID = $current_user->ID;
$wangguard_user_check_status = 'buyer';
//delete just in case a previous record from a user which didn't activate the account is there
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $WangUser_login));
$wpdb->query( $wpdb->prepare("insert into $table_name(signup_username , user_status , user_ip , user_proxy_ip) values ('%s' , '%s' , '%s' , '%s')" , $WangUser_login , $wangguard_user_check_status , wangguard_getRemoteIP() ,wangguard_getRemoteProxyIP() ) );
wangguard_plugin_user_register($WangUser_ID);
}
}
}
/**
* Account activated on BP hook
*
* @global type $wpdb
* @global type $wangguard_api_key
* @global type $wangguard_user_check_status
* @param type $userid
* @param type $key
* @param type $user
*/
function wangguard_bp_core_activated_user($userid, $key, $user) {
global $wpdb;
global $wangguard_api_key;
global $wangguard_user_check_status;
wangguard_plugin_user_register($userid);
}
/**
* Account activated on WPMU hook
*
* @global type $wpdb
* @global type $wangguard_api_key
* @global type $wangguard_user_check_status
* @param type $userid
* @param type $password
* @param type $meta
*/
function wangguard_wpmu_activate_user($userid, $password, $meta) {
global $wpdb;
global $wangguard_api_key;
global $wangguard_user_check_status;
wangguard_plugin_user_register($userid);
}
/**
* Check if moderation is active and which one is active
*/
function wangguard_check_moderation_active(){
$wggmoderationisactive = get_site_option('wangguard-moderation-is-active');
if( empty( $wggmoderationisactive ) ) $wggmoderationisactive = '0';
$wggmoderationtype = get_site_option('wangguard-moderation-type');
if( $wggmoderationisactive == 1 && $wggmoderationtype == 'splog' ){
$wggmoderationactivetype = 'splog';
}
elseif( $wggmoderationisactive == 1 && $wggmoderationtype == 'all' ){
$wggmoderationactivetype = 'all';
}
else{
$wggmoderationactivetype = false;
}
return $wggmoderationactivetype;
}
/**
* Saves the status of the verification against WangGuard service upon user registration
*
* @global type $wpdb
* @global type $wangguard_user_check_status
* @param type $userid
*/
function wangguard_plugin_user_register($userid) {
global $wpdb;
global $wangguard_user_check_status;
$user = new WP_User($userid);
$user_email = $user->user_email;
$wggmoderationisactive = wangguard_check_moderation_active();
$wangguarstatus = wangguard_look_for_allowed_email($user_email);
if ( !$wangguarstatus && !$wggmoderationisactive ) {
if (empty ($wangguard_user_check_status)) {
$user = new WP_User($userid);
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
//if there a status on the signups table?
$user_status = $wpdb->get_var( $wpdb->prepare("select user_status from $table_name where signup_username = '%s'" , $user->user_login));
//delete the signup status
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $user->user_login));
//If not empty, overrides the status with the signup status
if (!empty ($user_status))$wangguard_user_check_status = $user_status;
}
$table_name = $wpdb->base_prefix . "wangguarduserstatus";
$user_status = $wpdb->get_var( $wpdb->prepare("select ID from $table_name where ID = %d" , $userid));
if (is_null($user_status))//insert the new status
$wpdb->query( $wpdb->prepare("insert into $table_name(ID , user_status , user_ip , user_proxy_ip) values (%d , '%s' , '%s' , '%s')" , $userid , $wangguard_user_check_status , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() ) ); else //update the new status
$wpdb->query( $wpdb->prepare("update $table_name set user_status = '%s' where ID = %d" , $wangguard_user_check_status , $userid ) );
} elseif ( $wggmoderationisactive == 'all' || $wggmoderationisactive == 'splog' ) {
$reported = wangguard_is_email_reported_as_sp($user_email, wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() , true);
if ( $reported ){
$wangguard_user_check_status = 'moderation-splogger';
if (empty ($wangguard_user_check_status)) {
$user2 = new WP_User($userid);
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
//if there a status on the signups table?
$user_status = $wpdb->get_var( $wpdb->prepare("select user_status from $table_name where signup_username = '%s'" , $user2->user_login));
//delete the signup status
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $user2->user_login));
//If not empty, overrides the status with the signup status
if (!empty ($user_status))$wangguard_user_check_status = 'moderation-splogger';
}
$table_name = $wpdb->base_prefix . "wangguarduserstatus";
$user_status = $wpdb->get_var( $wpdb->prepare("select ID from $table_name where ID = %d" , $userid));
if (is_null($user_status))//insert the new status
$wpdb->query( $wpdb->prepare("insert into $table_name(ID , user_status , user_ip , user_proxy_ip) values (%d , '%s' , '%s' , '%s')" , $userid , $wangguard_user_check_status , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() ) ); else //update the new status
$wpdb->query( $wpdb->prepare("update $table_name set user_status = '%s' where ID = %d" , $wangguard_user_check_status , $userid ) );
}
elseif ( $wggmoderationisactive == 'all' && !$reported ){
$wangguard_user_check_status = 'moderation-allowed';
if (empty ($wangguard_user_check_status)) {
$user2 = new WP_User($userid);
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
//if there a status on the signups table?
$user_status = $wpdb->get_var( $wpdb->prepare("select user_status from $table_name where signup_username = '%s'" , $user2->user_login));
//delete the signup status
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $user2->user_login));
//If not empty, overrides the status with the signup status
if (!empty ($user_status))$wangguard_user_check_status = 'moderation-allowed';
}
$table_name = $wpdb->base_prefix . "wangguarduserstatus";
$user_status = $wpdb->get_var( $wpdb->prepare("select ID from $table_name where ID = %d" , $userid));
if (is_null($user_status))//insert the new status
$wpdb->query( $wpdb->prepare("insert into $table_name(ID , user_status , user_ip , user_proxy_ip) values (%d , '%s' , '%s' , '%s')" , $userid , $wangguard_user_check_status , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() ) ); else //update the new status
$wpdb->query( $wpdb->prepare("update $table_name set user_status = '%s' where ID = %d" , $wangguard_user_check_status , $userid ) );
}
else {
$wangguard_user_check_status = 'checked';
if (empty ($wangguard_user_check_status)) {
$user2 = new WP_User($userid);
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
//if there a status on the signups table?
$user_status = $wpdb->get_var( $wpdb->prepare("select user_status from $table_name where signup_username = '%s'" , $user2->user_login));
//delete the signup status
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $user2->user_login));
//If not empty, overrides the status with the signup status
if (!empty ($user_status))$wangguard_user_check_status = 'moderation-allowed';
}
$table_name = $wpdb->base_prefix . "wangguarduserstatus";
$user_status = $wpdb->get_var( $wpdb->prepare("select ID from $table_name where ID = %d" , $userid));
if (is_null($user_status))//insert the new status
$wpdb->query( $wpdb->prepare("insert into $table_name(ID , user_status , user_ip , user_proxy_ip) values (%d , '%s' , '%s' , '%s')" , $userid , $wangguard_user_check_status , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() ) ); else //update the new status
$wpdb->query( $wpdb->prepare("update $table_name set user_status = '%s' where ID = %d" , $wangguard_user_check_status , $userid ) );
}
} else {
$wangguard_user_check_status = 'whitelisted';
if (empty ($wangguard_user_check_status)) {
$user2 = new WP_User($userid);
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
//if there a status on the signups table?
$user_status = $wpdb->get_var( $wpdb->prepare("select user_status from $table_name where signup_username = '%s'" , $user2->user_login));
//delete the signup status
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $user2->user_login));
//If not empty, overrides the status with the signup status
if (!empty ($user_status))$wangguard_user_check_status = 'whitelisted';
}
$table_name = $wpdb->base_prefix . "wangguarduserstatus";
$user_status = $wpdb->get_var( $wpdb->prepare("select ID from $table_name where ID = %d" , $userid));
if (is_null($user_status))//insert the new status
$wpdb->query( $wpdb->prepare("insert into $table_name(ID , user_status , user_ip , user_proxy_ip) values (%d , '%s' , '%s' , '%s')" , $userid , $wangguard_user_check_status , wangguard_getRemoteIP() , wangguard_getRemoteProxyIP() ) ); else //update the new status
$wpdb->query( $wpdb->prepare("update $table_name set user_status = '%s' where ID = %d" , $wangguard_user_check_status , $userid ) );
}
}
/**
* Deletes the status of a user from the WangGuard status tracking table
*
* @global type $wpdb
* @param type $userid
*/
function wangguard_plugin_user_delete($userid) {
global $wpdb;
$user = new WP_User($userid);
//delete the signup status
$table_name = $wpdb->base_prefix . "wangguardsignupsstatus";
$wpdb->query( $wpdb->prepare("delete from $table_name where signup_username = '%s'" , $user->user_login));
//delete the user status
$table_name = $wpdb->base_prefix . "wangguarduserstatus";
$wpdb->query( $wpdb->prepare("delete from $table_name where ID = %d" , $userid ) );
//delete the user from the moderation queue
$table_name = $wpdb->base_prefix . "wangguardreportqueue";
$wpdb->query( $wpdb->prepare("delete from $table_name where ID = %d" , $userid ) );
//delete the user reports from the moderation queue
$table_name = $wpdb->base_prefix . "wangguardreportqueue";
$wpdb->query( $wpdb->prepare("delete from $table_name where reported_by_ID = %d" , $userid ) );
}
/**
* User has been reported as spam, send to WangGuard
* @global type $wpdb
* @param type $userid
*/
function wangguard_make_spam_user($userid) {
global $wpdb;
do_action('wangguard_pre_make_spam_user');
//flag a user
//get the recordset of the user to flag
$wpusersRs = $wpdb->get_col( $wpdb->prepare("select ID from $wpdb->users where ID = %d" , $userid ) );
wangguard_report_users($wpusersRs , "email" , false);
do_action('wangguard_make_spam_user');
}
/**
* User has been reported as safe, rollback on WangGuard
* @global type $wpdb
* @param type $userid
*/
function wangguard_make_ham_user($userid) {
global $wpdb;
//flag a user
//get the recordset of the user to make as safe
$wpusersRs = $wpdb->get_col( $wpdb->prepare("select ID from $wpdb->users where ID = %d" , $userid ) );
wangguard_rollback_report($wpusersRs);
}
/**
* Updates WangGuard user staus when a user is flagged as spam or ham
* @param type $userid
* @param type $is_spam
*/
function wangguard_bp_core_action_set_spammer_status($userid , $is_spam) {
if ($is_spam)wangguard_make_spam_user ($userid); else wangguard_make_ham_user ($userid);
}
/********************************************************************/
/*** USER REGISTATION & DELETE FILTERS ENDS ***/
/********************************************************************/
/********************************************************************/
/*** AJAX FRONT HANDLERS BEGINS ***/
/********************************************************************/
if ( ( (get_site_option ("wangguard-enable-bp-report-btn")==1) && ( defined('BP_VERSION') ) ) || ( get_site_option ("wangguard-enable-bp-report-blog")==1) ) {
add_action('wp_head', 'wangguard_ajax_front_setup');
add_action('wp_ajax_wangguard_ajax_front_handler', 'wangguard_ajax_front_callback');
}
/**
* Front end ajax functions
*
* @global type $wuangguard_parent
*/
function wangguard_ajax_front_setup() {
global $wuangguard_parent;
if ( !is_user_logged_in() )return;
?>
<script type="text/javascript" >
function wangguard_isjQuery17() {
var jQueryVersion = jQuery.fn.jquery.split('.');
var ret = ( (parseInt(jQueryVersion[0])==1) && (parseInt(jQueryVersion[1])>=7) ) || ( parseInt(jQueryVersion[0])>1 );
return ret;
}
if (typeof ajaxurl == 'undefined')
ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
else if (ajaxurl == undefined)
ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
jQuery(document).ready(function() {
if (wangguard_isjQuery17() == true) {
jQuery(document).on("click", ".wangguard-user-report", function(){
wangguardUserReport_handler(this);
});
}
else {
jQuery('.wangguard-user-report').live('click' , function () {
wangguardUserReport_handler(this);
});
}
function wangguardUserReport_handler(sender) {
if (!confirm('<?php echo addslashes(__("Do you confirm to report the user?" , "wangguard")) ?>'))
return;
var userID = jQuery(sender).attr("rel");
if ((userID == undefined) || (userID == '')) {
userID = 0;
//BP profile button doesn't allow to add a rel attr to the button so we store it in tne class field
var tmpClass = jQuery(sender).attr("class");
var matches = tmpClass.match(/wangguard-user-report-id-(\d+)/);
if (matches != null)
userID = matches[1];
}
data = {
action : 'wangguard_ajax_front_handler',
object : 'user',
wpnonce : '<?php echo wp_create_nonce("wangguardreport") ?>',
userid : userID
};
jQuery.post(ajaxurl, data, function(response) {
if (response=='0') {
alert('<?php echo addslashes(__('The user was reported.', 'wangguard')) ?>');
jQuery(".wangguard-user-report[rel='"+userID+"']").fadeOut();
jQuery(".wangguard-user-report-id-"+userID).fadeOut();
}
});
};
if (wangguard_isjQuery17() == true) {
jQuery(document).on("click", ".wangguard-blog-report", function(){
wangguardBlogReport_handler(this);
});
}
else {
jQuery('.wangguard-blog-report').live('click' , function () {
wangguardBlogReport_handler(this);
});
}
function wangguardBlogReport_handler(sender) {
if (!confirm('<?php echo addslashes(__("Do you confirm to report the blog and authors?" , "wangguard")) ?>'))
return;
var blogID = jQuery(sender).attr("rel");
if ((blogID == undefined) || (blogID == '')) {
blogID = 0;
//BP profile button doesn't allow to add a rel attr to the button so we store it in tne class field
var tmpClass = jQuery(sender).attr("class");
var matches = tmpClass.match(/wangguard-blog-report-id-(\d+)/);
if (matches != null)
blogID = matches[1];
}
data = {
action : 'wangguard_ajax_front_handler',
object : 'blog',
wpnonce : '<?php echo wp_create_nonce("wangguardreport") ?>',
blogid : blogID
};
jQuery.post(ajaxurl, data, function(response) {
if (response=='0') {
alert('<?php echo addslashes(__('The blog was reported.', 'wangguard')) ?>');
jQuery(".wangguard-blog-report").fadeOut();
}
});
};
});</script>
<?php
}
/**
* Checks whether a user is reported on queue
*
* @global type $wpdb
* @param type $userid
* @return boolean
*/
function wangguard_is_user_reported($userid) {
global $wpdb;
$table_name = $wpdb->base_prefix . "wangguardreportqueue";
$Count = $wpdb->get_col( $wpdb->prepare("select count(*) as q from $table_name where ID = %d" , $userid) );
return $Count[0] > 0;
}
/**
* Checks whether a blog is reported on queue
*
* @global type $wpdb
* @param type $blogid
* @return boolean
*/
function wangguard_is_blog_reported($blogid) {
global $wpdb;
$table_name = $wpdb->base_prefix . "wangguardreportqueue";
$Count = $wpdb->get_col( $wpdb->prepare("select count(*) as q from $table_name where blog_id = %d" , $blogid) );
return $Count[0] > 0;
}
/**
* Front end AJAX handler
*
* @global type $wpdb
*/
function wangguard_ajax_front_callback() {
global $wpdb;
if (!is_user_logged_in()) return;
//add user ID or blog ID to the
$object = $_REQUEST['object'];
$nonce = $_REQUEST['wpnonce'];
if ( !wp_verify_nonce( $nonce, 'wangguardreport' ) )die();
$thisUserID = get_current_user_id();
if ($object == "user") {
$userid = (int)$_REQUEST['userid'];
if (empty ($userid)) die();