Changeset 1686938
- Timestamp:
- 06/28/2017 01:07:30 PM (9 years ago)
- Location:
- cleantalk-spam-protect/trunk
- Files:
-
- 3 edited
-
assets/js/cleantalk-users-checkspam.js (modified) (14 diffs)
-
inc/cleantalk-admin.php (modified) (1 diff)
-
inc/cleantalk-users.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cleantalk-spam-protect/trunk/assets/js/cleantalk-users-checkspam.js
r1667018 r1686938 1 var working = false; 2 var ajax_nonce = ctUsersCheck.ct_ajax_nonce; 1 // Printf for JS 2 String.prototype.printf = function(){ 3 var formatted = this; 4 for( var arg in arguments ) { 5 var before_formatted = formatted.substring(0, formatted.indexOf("%s", 0)); 6 var after_formatted = formatted.substring(formatted.indexOf("%s", 0)+2, formatted.length); 7 formatted = before_formatted + arguments[arg] + after_formatted; 8 } 9 return formatted; 10 }; 11 12 // Flags 13 var ct_working = false, 14 ct_new_check = true, 15 ct_cooling_down_flag = false; 16 // Settings 3 17 var ct_cool_down_time = 65000, 4 18 ct_requests_counter = 0, 5 ct_max_requests = 95, 6 ct_cooling_down_flag = false; 7 var ct_new_check = true; 8 9 String.prototype.format = String.prototype.f = function (){ 10 var args = arguments; 11 return this.replace(/\{\{|\}\}|\{(\d+)\}/g, function (m, n){ 12 if (m == "{{") { return "{"; } 13 if (m == "}}") { return "}"; } 14 return args[n]; 15 }); 16 }; 19 ct_max_requests = 95; 20 // Variables 21 var ct_ajax_nonce = ctUsersCheck.ct_ajax_nonce, 22 ct_users_total = 0, 23 ct_users_checked = 0, 24 ct_users_spam = 0, 25 ct_users_bad = 0, 26 ct_unchecked = 'unset'; 17 27 18 28 var close_animate=true; … … 36 46 var data = { 37 47 'action': 'ajax_clear_users', 38 'security': ajax_nonce48 'security': ct_ajax_nonce 39 49 }; 40 50 … … 73 83 var data = { 74 84 'action': 'ajax_check_users', 75 'security': ajax_nonce, 76 'new_check': ct_new_check 85 'security': ct_ajax_nonce, 86 'new_check': ct_new_check, 87 'unchecked': ct_unchecked 77 88 }; 78 89 … … 82 93 data: data, 83 94 success: function(msg){ 84 ct_new_check = false; 85 if(parseInt(msg)==1){ 86 ct_send_users(); 87 }else if(parseInt(msg)==0){ 88 working=false; 89 jQuery('#ct_working_message').hide(); 95 var msg_obj = JSON.parse(msg); 96 97 if(parseInt(msg_obj.error)){ 98 ct_working=false; 99 alert(msg.error_message); 90 100 location.href='users.php?page=ct_check_users&ct_worked=1'; 91 101 }else{ 92 working=false; 93 alert(msg); 94 location.href='users.php?page=ct_check_users&ct_worked=1'; 102 ct_new_check = false; 103 if(parseInt(msg_obj.end) == 0){ 104 ct_users_checked += msg_obj.checked; 105 ct_users_spam += msg_obj.spam; 106 ct_users_bad += msg_obj.bad; 107 ct_unchecked = ct_users_total - ct_users_checked - ct_users_bad; 108 var status_string = String(ctUsersCheck.ct_status_string); 109 var status_string = status_string.printf(ct_users_total, ct_users_checked, ct_users_spam, ct_users_bad); 110 if(parseInt(ct_users_spam) > 0) 111 status_string += ctUsersCheck.ct_status_string_warning; 112 jQuery('#ct_checking_users_status').html(status_string); 113 ct_send_users(); 114 }else if(parseInt(msg_obj.end) == 1){ 115 ct_working=false; 116 jQuery('#ct_working_message').hide(); 117 location.href='users.php?page=ct_check_users&ct_worked=1'; 118 } 95 119 } 96 120 }, … … 106 130 function ct_show_users_info(){ 107 131 108 if( working){132 if(ct_working){ 109 133 110 134 if(ct_cooling_down_flag == true){ … … 116 140 } 117 141 118 var data = { 119 'action': 'ajax_info_users', 120 'security': ajax_nonce 121 }; 122 jQuery.ajax({ 123 type: "POST", 124 url: ajaxurl, 125 data: data, 126 success: function(msg){ 127 jQuery('#ct_checking_users_status').html(msg); 128 setTimeout(ct_show_users_info, 3000); 129 }, 130 error: function (jqXHR, textStatus, errorThrown){ 131 jQuery('#ct_error_message').show(); 132 jQuery('#cleantalk_ajax_error').html(textStatus); 133 jQuery('#cleantalk_js_func').html('Show users'); 134 setTimeout(ct_show_users_info(), 3000); 135 }, 136 timeout: 5000 137 }); 142 setTimeout(ct_show_users_info, 3000); 143 144 if(!ct_users_total){ 145 var data = { 146 'action': 'ajax_info_users', 147 'security': ct_ajax_nonce 148 }; 149 jQuery.ajax({ 150 type: "POST", 151 url: ajaxurl, 152 data: data, 153 success: function(msg){ 154 var msg = jQuery.parseJSON(msg); 155 jQuery('#ct_checking_users_status').html(msg.message); 156 ct_users_total = msg.total; 157 }, 158 error: function (jqXHR, textStatus, errorThrown){ 159 jQuery('#ct_error_message').show(); 160 jQuery('#cleantalk_ajax_error').html(textStatus); 161 jQuery('#cleantalk_js_func').html('Show users'); 162 setTimeout(ct_show_users_info(), 3000); 163 }, 164 timeout: 15000 165 }); 166 } 138 167 } 139 168 } … … 142 171 var data = { 143 172 'action': 'ajax_insert_users', 144 'security': ajax_nonce173 'security': ct_ajax_nonce 145 174 }; 146 175 … … 158 187 var data = { 159 188 'action': 'ajax_delete_all_users', 160 'security': ajax_nonce189 'security': ct_ajax_nonce 161 190 }; 162 191 … … 194 223 var data = { 195 224 'action': 'ajax_delete_checked_users', 196 'security': ajax_nonce,225 'security': ct_ajax_nonce, 197 226 'ids':ids 198 227 }; … … 225 254 var data = { 226 255 'action': 'ajax_delete_checked_users', 227 'security': ajax_nonce,256 'security': ct_ajax_nonce, 228 257 'ids':ids 229 258 }; … … 259 288 jQuery('#ct_working_message').show(); 260 289 jQuery('#ct_preloader').show(); 261 working=true;290 ct_working=true; 262 291 ct_clear_users(); 263 292 ct_show_users_info(); … … 321 350 var data = { 322 351 'action': 'ajax_ct_approve_user', 323 'security': ajax_nonce,352 'security': ct_ajax_nonce, 324 353 'id': ct_id 325 354 }; … … 338 367 var data = { 339 368 'action': 'ct_feedback_user', 340 'security': ajax_nonce,369 'security': ct_ajax_nonce, 341 370 'user_id': ct_id, 342 371 'status': 'approve' … … 369 398 var data = { 370 399 'action': 'ajax_ct_get_csv_file', 371 'security': ajax_nonce,400 'security': ct_ajax_nonce, 372 401 'filename': ctUsersCheck.ct_csv_filename 373 402 }; -
cleantalk-spam-protect/trunk/inc/cleantalk-admin.php
r1685423 r1686938 275 275 'ct_confirm_deletion_checked' => __('Delete checked users?', 'cleantalk'), 276 276 'ct_csv_filename' => "user_check_by_".$current_user->user_login, 277 'ct_bad_csv' => __("File doesn't exist. File will be generated while checking. Please, press \"Check for spam\".") 277 'ct_bad_csv' => __("File doesn't exist. File will be generated while checking. Please, press \"Check for spam\"."), 278 'ct_status_string' => __("Total users %s, checked %s, found %s spam users and %s bad users (without IP or email)", 'cleantalk'), 279 'ct_status_string_warning' => "<p>".__("Please do backup of WordPress database before delete any accounts!", 'cleantalk')."</p>" 278 280 )); 279 281 wp_localize_script( 'jquery', 'ctUsersScreen', array( -
cleantalk-spam-protect/trunk/inc/cleantalk-users.php
r1681278 r1686938 28 28 , ARRAY_A); 29 29 $cnt_spam1=$r[0]['cnt']; 30 31 // Parsing status message 32 $status = ct_ajax_info_users(true); 33 $status = json_decode($status, true); 34 $status_message = $status['message']; 30 35 ?> 31 36 <div class="wrap"> … … 48 53 49 54 <!-- Main info --> 50 <h3 id="ct_checking_users_status" style="text-align:center;width:90%;"><?php ct_ajax_info_users(true);?></h3>55 <h3 id="ct_checking_users_status" style="text-align:center;width:90%;"><?php echo $status_message; ?></h3> 51 56 52 57 <!-- Cooling notice --> … … 273 278 $u = get_users($args_unchecked); 274 279 280 $check_result = array( 281 'end' => 0, 282 'checked' => 0, 283 'spam' => 0, 284 'bad' => 0, 285 'error' => 0 286 ); 287 275 288 if(count($u) > 0){ 276 289 … … 301 314 302 315 if(empty($curr_ip) && empty($curr_email)){ 316 $check_result['bad']++; 303 317 update_user_meta($u[$i]->ID,'ct_bad','1',true); 304 318 unset($u[$i]); … … 314 328 } 315 329 316 // Drop if data empty 317 if(count($data) == 0) 318 die('1'); 330 // Drop if data empty and there's no users to check 331 if(count($data) == 0){ 332 333 if($_POST['unchecked'] === 0) 334 $check_result['end'] = 1; 335 336 print json_encode($check_result); 337 die(); 338 } 319 339 320 340 $data=implode(',',$data); … … 332 352 333 353 if(empty($result)){ 334 echo "Connection error"; 354 $check_result['error'] = 1; 355 $check_result['error_message'] = __('Connection error', 'cleantalk'); 356 print json_encode($check_result); 335 357 }else{ 336 358 337 359 $result = json_decode($result); 338 360 339 if(isset($result->error_message)) 361 if(isset($result->error_message)){ 362 $check_result['error'] = 1; 363 $check_result['error_message'] = __('Server response: ', 'cleantalk').$result->error_message;; 340 364 print "Server response: ".$result->error_message; 341 else{365 }else{ 342 366 343 367 // Opening CSV file … … 355 379 for($i=0;$i<sizeof($u);$i++){ 356 380 381 $check_result['checked']++; 357 382 update_user_meta($u[$i]->ID,'ct_checked',date("Y-m-d H:m:s"),true); 358 383 … … 378 403 379 404 if ($mark_spam_ip || $mark_spam_email){ 405 $check_result['spam']++; 380 406 update_user_meta($u[$i]->ID,'ct_marked_as_spam','1',true); 381 407 $text .= $u[$i]->user_login.','; … … 386 412 } 387 413 fwrite($file_desc, $text); 388 fclose($file_desc); 389 print 1;414 fclose($file_desc); 415 print json_encode($check_result); 390 416 } 391 417 } 392 }else 393 print 0; 394 418 }else{ 419 $check_result['end'] = 1; 420 print json_encode($check_result); 421 } 395 422 die; 396 423 } … … 398 425 function ct_ajax_info_users($direct_call = false) 399 426 { 400 if (!$direct_call) {427 if (!$direct_call) 401 428 check_ajax_referer( 'ct_secret_nonce', 'security' ); 402 } 403 404 global $wpdb; 405 406 // All users407 // $r=$wpdb->get_results("408 // SELECT409 // COUNT(ID) AS cnt410 // FROM $wpdb->users411 // ");412 // $cnt = $r[0]->cnt;413 $args = array(414 'total_users' => true415 );416 $user_query = new WP_User_Query($args);417 $cnt = $user_query->get_total();418 419 // Checked420 $r=$wpdb->get_results("select distinct count($wpdb->users.ID) as cnt from $wpdb->users inner join $wpdb->usermeta on $wpdb->users.ID=$wpdb->usermeta.user_id where $wpdb->usermeta.meta_key='ct_checked' or $wpdb->usermeta.meta_key='ct_hash';");421 $cnt_checked = $r[0]->cnt;422 423 //Spam424 $r=$wpdb->get_results("select distinct count($wpdb->users.ID) as cnt from $wpdb->users inner join $wpdb->usermeta on $wpdb->users.ID=$wpdb->usermeta.user_id where $wpdb->usermeta.meta_key='ct_marked_as_spam';", ARRAY_A);425 $cnt_spam = $r[0]['cnt'];426 427 //Bad428 $r=$wpdb->get_results("select distinct count($wpdb->users.ID) as cnt from $wpdb->users inner join $wpdb->usermeta on $wpdb->users.ID=$wpdb->usermeta.user_id where $wpdb->usermeta.meta_key='ct_bad';", ARRAY_A);429 $cnt_bad = $r[0]['cnt'];430 431 printf (__("Total users %s, checked %s, found %s spam users and %s bad users (without IP or email)", 'cleantalk'), $cnt, $cnt_checked, $cnt_spam, $cnt_bad);429 430 global $wpdb; 431 432 // All users 433 $r=$wpdb->get_results(" 434 SELECT 435 COUNT(ID) AS cnt 436 FROM $wpdb->users 437 "); 438 $cnt = $r[0]->cnt; 439 440 // Checked 441 $r=$wpdb->get_results("select distinct count($wpdb->users.ID) as cnt from $wpdb->users inner join $wpdb->usermeta on $wpdb->users.ID=$wpdb->usermeta.user_id where $wpdb->usermeta.meta_key='ct_checked' or $wpdb->usermeta.meta_key='ct_hash';"); 442 $cnt_checked = $r[0]->cnt; 443 444 //Spam 445 $r=$wpdb->get_results("select distinct count($wpdb->users.ID) as cnt from $wpdb->users inner join $wpdb->usermeta on $wpdb->users.ID=$wpdb->usermeta.user_id where $wpdb->usermeta.meta_key='ct_marked_as_spam';", ARRAY_A); 446 $cnt_spam = $r[0]['cnt']; 447 448 //Bad 449 $r=$wpdb->get_results("select distinct count($wpdb->users.ID) as cnt from $wpdb->users inner join $wpdb->usermeta on $wpdb->users.ID=$wpdb->usermeta.user_id where $wpdb->usermeta.meta_key='ct_bad';", ARRAY_A); 450 $cnt_bad = $r[0]['cnt']; 451 452 $return = array( 453 'message' => '', 454 'total' => $cnt 455 ); 456 457 $return['message'] .= sprintf (__("Total users %s, checked %s, found %s spam users and %s bad users (without IP or email)", 'cleantalk'), $cnt, $cnt_checked, $cnt_spam, $cnt_bad); 458 432 459 $backup_notice = ' '; 433 460 if ($cnt_spam > 0) { 434 461 $backup_notice = __("Please do backup of WordPress database before delete any accounts!", 'cleantalk'); 435 462 } 436 print "<p>$backup_notice</p>"; 437 438 if (!$direct_call) 439 die(); 440 463 $return['message'] .= "<p>$backup_notice</p>"; 464 465 if($direct_call){ 466 return json_encode($return); 467 }else{ 468 echo json_encode($return); 469 die(); 470 } 471 441 472 return null; 442 473 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)