Spam protection, AntiSpam, FireWall by CleanTalk - Version 5.30

Version Description

2015-11-05 = * Improved anti-spam checking * Optimized performance * Fixed blocking email preview in MailPoet * Interface fixes * WPMU interface fixes

Download this release

Release Info

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

Code changes from version 5.29 to 5.30

cleantalk.php CHANGED
@@ -3,11 +3,11 @@
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: http://cleantalk.org
5
  Description: Max power, all-in-one, captcha less, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
- Version: 5.29
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: http://cleantalk.org
9
  */
10
- $cleantalk_plugin_version='5.29';
11
  $cleantalk_executed=false;
12
 
13
  if(defined('CLEANTALK_AJAX_USE_BUFFER'))
@@ -29,7 +29,7 @@ else
29
  }
30
  if(!defined('CLEANTALK_PLUGIN_DIR')){
31
  define('CLEANTALK_PLUGIN_DIR', plugin_dir_path(__FILE__));
32
- global $ct_options, $ct_data;
33
 
34
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
35
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
@@ -47,6 +47,7 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
47
 
48
  if($value==1 && !is_admin() && stripos($_SERVER['REQUEST_URI'],'/wp-admin/')===false) //&& (!isset($_POST) || isset($_POST) && sizeof($_POST)==0)
49
  {
 
50
  $is_sfw_check=true;
51
  if(isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key']==md5(cleantalk_get_ip().$ct_options['apikey']))
52
  {
@@ -66,6 +67,23 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
66
  $sfw->sfw_die();
67
  }
68
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
 
71
  if(isset($ct_options['check_external']))
@@ -133,12 +151,16 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
133
  }
134
 
135
 
136
- if (is_admin())
137
  {
138
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-admin.php');
139
  if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
140
  add_action('admin_init', 'ct_admin_init', 1);
141
  add_action('admin_menu', 'ct_admin_add_page');
 
 
 
 
142
  add_action('admin_notices', 'cleantalk_admin_notice_message');
143
  }
144
  if (defined( 'DOING_AJAX' ) && DOING_AJAX||isset($_POST['cma-action']))
@@ -148,6 +170,8 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
148
  }
149
 
150
  add_action('admin_enqueue_scripts', 'ct_enqueue_scripts');
 
 
151
  add_action('comment_unapproved_to_approvecomment', 'ct_comment_approved'); // param - comment object
152
  add_action('comment_unapproved_to_approved', 'ct_comment_approved'); // param - comment object
153
  add_action('comment_approved_to_unapproved', 'ct_comment_unapproved'); // param - comment object
@@ -155,9 +179,16 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
155
  add_action('comment_approved_to_spam', 'ct_comment_spam'); // param - comment object
156
  //add_filter('get_comment_text', 'ct_get_comment_text'); // param - current comment text
157
  add_filter('unspam_comment', 'ct_unspam_comment');
 
 
 
158
  add_action('delete_user', 'ct_delete_user');
 
 
 
159
  add_filter('plugin_row_meta', 'ct_register_plugin_links', 10, 2);
160
  add_filter('plugin_action_links', 'ct_plugin_action_links', 10, 2);
 
161
  add_action('updated_option', 'ct_update_option'); // param - option name, i.e. 'cleantalk_settings'
162
  }else{
163
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
@@ -193,7 +224,7 @@ if(!defined('CLEANTALK_PLUGIN_DIR')){
193
  if (!function_exists ( 'ct_activation')) {
194
  function ct_activation() {
195
  wp_schedule_event(time(), 'hourly', 'ct_hourly_event_hook' );
196
- wp_schedule_event(time(), 'hourly', 'ct_send_sfw_log' );
197
  wp_schedule_event(time(), 'daily', 'cleantalk_update_sfw' );
198
 
199
  cleantalk_update_sfw();
@@ -206,7 +237,7 @@ if (!function_exists ( 'ct_activation')) {
206
  if (!function_exists ( 'ct_deactivation')) {
207
  function ct_deactivation() {
208
  wp_clear_scheduled_hook( 'ct_hourly_event_hook' );
209
- wp_clear_scheduled_hook( 'ct_send_sfw_log' );
210
  wp_clear_scheduled_hook( 'cleantalk_update_sfw' );
211
  }
212
  }
@@ -337,7 +368,7 @@ INDEX ( `network` , `mask` )
337
  {
338
  require_once('inc/cleantalk.class.php');
339
  }
340
- global $ct_options, $ct_data, $wpdb;
341
  if(isset($ct_options['spam_firewall']))
342
  {
343
  $value = @intval($ct_options['spam_firewall']);
@@ -359,9 +390,9 @@ INDEX ( `network` , `mask` )
359
  {
360
  $result=$result['data'];
361
  $query="INSERT INTO `".$wpdb->base_prefix."cleantalk_sfw` VALUES ";
362
- if(sizeof($result)>200)
363
  {
364
- $wpdb->query("TRUNCATE TABLE `".$wpdb->base_prefix."cleantalk_sfw`;");
365
  for($i=0;$i<sizeof($result);$i++)
366
  {
367
  if($i==sizeof($result)-1)
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: http://cleantalk.org
5
  Description: Max power, all-in-one, captcha less, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
+ Version: 5.30
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: http://cleantalk.org
9
  */
10
+ $cleantalk_plugin_version='5.30';
11
  $cleantalk_executed=false;
12
 
13
  if(defined('CLEANTALK_AJAX_USE_BUFFER'))
29
  }
30
  if(!defined('CLEANTALK_PLUGIN_DIR')){
31
  define('CLEANTALK_PLUGIN_DIR', plugin_dir_path(__FILE__));
32
+ global $ct_options, $ct_data, $pagenow;
33
 
34
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
35
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
47
 
48
  if($value==1 && !is_admin() && stripos($_SERVER['REQUEST_URI'],'/wp-admin/')===false) //&& (!isset($_POST) || isset($_POST) && sizeof($_POST)==0)
49
  {
50
+
51
  $is_sfw_check=true;
52
  if(isset($_COOKIE['ct_sfw_pass_key']) && $_COOKIE['ct_sfw_pass_key']==md5(cleantalk_get_ip().$ct_options['apikey']))
53
  {
67
  $sfw->sfw_die();
68
  }
69
  }
70
+
71
+ //cron start
72
+ if(isset($ct_data['last_sfw_send']))
73
+ {
74
+ $last_sfw_send=$ct_data['last_sfw_send'];
75
+ }
76
+ else
77
+ {
78
+ $last_sfw_send=0;
79
+ }
80
+ if(time()-$last_sfw_send>3600)
81
+ {
82
+ ct_send_sfw_log();
83
+ $ct_data['last_sfw_send']=time();
84
+ update_option('cleantalk_data', $ct_data);
85
+ }
86
+ //cron end
87
  }
88
 
89
  if(isset($ct_options['check_external']))
151
  }
152
 
153
 
154
+ if (is_admin()||is_network_admin())
155
  {
156
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-admin.php');
157
  if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
158
  add_action('admin_init', 'ct_admin_init', 1);
159
  add_action('admin_menu', 'ct_admin_add_page');
160
+ if(is_network_admin())
161
+ {
162
+ add_action('network_admin_menu', 'ct_admin_add_page');
163
+ }
164
  add_action('admin_notices', 'cleantalk_admin_notice_message');
165
  }
166
  if (defined( 'DOING_AJAX' ) && DOING_AJAX||isset($_POST['cma-action']))
170
  }
171
 
172
  add_action('admin_enqueue_scripts', 'ct_enqueue_scripts');
173
+ if($pagenow=='edit-comments.php')
174
+ {
175
  add_action('comment_unapproved_to_approvecomment', 'ct_comment_approved'); // param - comment object
176
  add_action('comment_unapproved_to_approved', 'ct_comment_approved'); // param - comment object
177
  add_action('comment_approved_to_unapproved', 'ct_comment_unapproved'); // param - comment object
179
  add_action('comment_approved_to_spam', 'ct_comment_spam'); // param - comment object
180
  //add_filter('get_comment_text', 'ct_get_comment_text'); // param - current comment text
181
  add_filter('unspam_comment', 'ct_unspam_comment');
182
+ }
183
+ if($pagenow=='users.php')
184
+ {
185
  add_action('delete_user', 'ct_delete_user');
186
+ }
187
+ if($pagenow=='plugins.php' || @strpos($_SERVER['REQUEST_URI'],'plugins.php')!==false)
188
+ {
189
  add_filter('plugin_row_meta', 'ct_register_plugin_links', 10, 2);
190
  add_filter('plugin_action_links', 'ct_plugin_action_links', 10, 2);
191
+ }
192
  add_action('updated_option', 'ct_update_option'); // param - option name, i.e. 'cleantalk_settings'
193
  }else{
194
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
224
  if (!function_exists ( 'ct_activation')) {
225
  function ct_activation() {
226
  wp_schedule_event(time(), 'hourly', 'ct_hourly_event_hook' );
227
+ //wp_schedule_event(time(), 'hourly', 'ct_send_sfw_log' );
228
  wp_schedule_event(time(), 'daily', 'cleantalk_update_sfw' );
229
 
230
  cleantalk_update_sfw();
237
  if (!function_exists ( 'ct_deactivation')) {
238
  function ct_deactivation() {
239
  wp_clear_scheduled_hook( 'ct_hourly_event_hook' );
240
+ @wp_clear_scheduled_hook( 'ct_send_sfw_log' );
241
  wp_clear_scheduled_hook( 'cleantalk_update_sfw' );
242
  }
243
  }
368
  {
369
  require_once('inc/cleantalk.class.php');
370
  }
371
+ global $ct_options, $ct_data;
372
  if(isset($ct_options['spam_firewall']))
373
  {
374
  $value = @intval($ct_options['spam_firewall']);
390
  {
391
  $result=$result['data'];
392
  $query="INSERT INTO `".$wpdb->base_prefix."cleantalk_sfw` VALUES ";
393
+ if(sizeof($result)>10)
394
  {
395
+ //$wpdb->query("TRUNCATE TABLE `".$wpdb->base_prefix."cleantalk_sfw`;");
396
  for($i=0;$i<sizeof($result);$i++)
397
  {
398
  if($i==sizeof($result)-1)
inc/cleantalk-admin.js CHANGED
@@ -25,7 +25,10 @@ jQuery(document).ready(function(){
25
  banner_html="<div id='ct_stats_banner'>"+cleantalk_blocked_message;
26
  banner_html+=cleantalk_statistics_link+'</div>';
27
  jQuery('.form-table').first().before(banner_html);
28
- jQuery('.form-table').first().before("<br /><a href='#' style='font-size:10pt;' id='cleantalk_access_key_link'>Show the access key</a>");
 
 
 
29
  }
30
 
31
  jQuery('#cleantalk_access_key_link').click(function(){
@@ -39,10 +42,6 @@ jQuery(document).ready(function(){
39
  }
40
  });
41
 
42
- /*jQuery('#cleantalk_registrations_test1').parent().parent().hide();
43
- jQuery('#cleantalk_comments_test1').parent().parent().hide();
44
- jQuery('#cleantalk_contact_forms_test1').parent().parent().hide();*/
45
-
46
  ct_adv_settings=jQuery('#cleantalk_registrations_test1').parent().parent().parent().parent();
47
  ct_adv_settings.hide();
48
  ct_adv_settings_title=ct_adv_settings.prev();
25
  banner_html="<div id='ct_stats_banner'>"+cleantalk_blocked_message;
26
  banner_html+=cleantalk_statistics_link+'</div>';
27
  jQuery('.form-table').first().before(banner_html);
28
+ if(!cleantalk_wpmu)
29
+ {
30
+ jQuery('.form-table').first().before("<br /><a href='#' style='font-size:10pt;' id='cleantalk_access_key_link'>Show the access key</a>");
31
+ }
32
  }
33
 
34
  jQuery('#cleantalk_access_key_link').click(function(){
42
  }
43
  });
44
 
 
 
 
 
45
  ct_adv_settings=jQuery('#cleantalk_registrations_test1').parent().parent().parent().parent();
46
  ct_adv_settings.hide();
47
  ct_adv_settings_title=ct_adv_settings.prev();
inc/cleantalk-admin.php CHANGED
@@ -22,9 +22,9 @@ function cleantalk_custom_glance_items( )
22
  $blocked = number_format($blocked, 0, ',', ' ');
23
  print "<div style='height:24px;width:100%;display:table-cell; vertical-align:middle;'><img src='" . plugin_dir_url(__FILE__) . "images/logo_color.png' style='margin-right:1em;vertical-align:middle;'/><span><a href='options-general.php?page=cleantalk'>CleanTalk</a> ";
24
  printf(
25
- /* translators: %s: Number of spam messages */
26
- __( 'has blocked %s spam', 'cleantalk' ),
27
- $blocked
28
  );
29
  print "</span></div>";
30
  }
@@ -82,227 +82,262 @@ add_action( 'wp_ajax_ajax_get_timezone', 'ct_ajax_get_timezone' );
82
  * @param string $hook URL of hooked page
83
  */
84
  function ct_enqueue_scripts($hook) {
85
- if ($hook == 'edit-comments.php')
86
- wp_enqueue_script('ct_reload_script', plugins_url('/cleantalk-rel.js', __FILE__));
87
  }
88
 
89
  /**
90
  * Admin action 'admin_menu' - Add the admin options page
91
  */
92
  function ct_admin_add_page() {
93
- add_options_page(__('CleanTalk settings', 'cleantalk'), 'CleanTalk', 'manage_options', 'cleantalk', 'ct_settings_page');
 
 
 
 
 
 
 
94
  }
95
 
96
  /**
97
  * Admin action 'admin_init' - Add the admin settings and such
98
  */
99
- function ct_admin_init() {
100
- global $ct_server_timeout, $show_ct_notice_autokey, $ct_notice_autokey_label, $ct_notice_autokey_value, $show_ct_notice_renew, $ct_notice_renew_label, $show_ct_notice_trial, $ct_notice_trial_label, $show_ct_notice_online, $ct_notice_online_label, $renew_notice_showtime, $trial_notice_showtime, $ct_plugin_name, $ct_options, $ct_data, $trial_notice_check_timeout, $account_notice_check_timeout, $ct_user_token_label, $cleantalk_plugin_version, $notice_check_timeout;
101
-
102
- $ct_options = ct_get_options();
103
- $ct_data = ct_get_data();
104
-
105
- $current_version=@trim($ct_data['current_version']);
106
- if($current_version!=$cleantalk_plugin_version)
107
- {
108
- $ct_data['current_version']=$cleantalk_plugin_version;
109
- update_option('cleantalk_data', $ct_data);
110
- $ct_base_call_result = ct_base_call(array(
111
- 'message' => 'CleanTalk setup test',
112
- 'example' => null,
113
- 'sender_email' => 'good@cleantalk.org',
114
- 'sender_nickname' => 'CleanTalk',
115
- 'post_info' => '',
116
- 'checkjs' => 1
117
- ));
118
- }
119
- if(isset($_POST['option_page'])&&$_POST['option_page']=='cleantalk_settings')
120
- {
121
- $ct_base_call_result = ct_base_call(array(
122
- 'message' => 'CleanTalk setup test',
123
- 'example' => null,
124
- 'sender_email' => 'good@cleantalk.org',
125
- 'sender_nickname' => 'CleanTalk',
126
- 'post_info' => '',
127
- 'checkjs' => 1
128
- ));
129
- }
130
-
131
- if(@isset($_POST['cleantalk_settings']['spam_firewall']) && $_POST['cleantalk_settings']['spam_firewall']==1 || isset($ct_options['spam_firewall']) && intval($ct_options['spam_firewall'])==1)
132
- {
133
- cleantalk_update_sfw();
134
- }
135
-
136
- $show_ct_notice_trial = false;
137
- if (isset($_COOKIE[$ct_notice_trial_label])) {
138
- if ($_COOKIE[$ct_notice_trial_label] == 1) {
139
- $show_ct_notice_trial = true;
140
- }
141
- }
142
- $show_ct_notice_renew = false;
143
- if (isset($_COOKIE[$ct_notice_renew_label])) {
144
- if ($_COOKIE[$ct_notice_renew_label] == 1) {
145
- $show_ct_notice_renew = true;
146
- }
147
- }
148
- $show_ct_notice_autokey = false;
149
- if (isset($_COOKIE[$ct_notice_autokey_label]) && !empty($_COOKIE[$ct_notice_autokey_label])) {
150
- if (!empty($_COOKIE[$ct_notice_autokey_label])) {
151
- $show_ct_notice_autokey = true;
152
- $ct_notice_autokey_value = base64_decode($_COOKIE[$ct_notice_autokey_label]);
153
- setcookie($ct_notice_autokey_label, '', 1, '/');
154
- }
155
- }
156
-
157
- if (isset($_POST['get_apikey_auto'])){
158
- $email = get_option('admin_email');
159
- $website = parse_url(get_option('siteurl'),PHP_URL_HOST);
160
- $platform = 'wordpress';
161
-
162
- if(!function_exists('getAutoKey'))
163
- {
164
- require_once('cleantalk.class.php');
165
- }
166
-
167
- $result = getAutoKey($email, $website, $platform);
168
-
169
- if ($result)
170
- {
171
- $ct_data['next_account_status_check']=0;
172
- update_option('cleantalk_data', $ct_data);
173
- $result = json_decode($result, true);
174
- if (isset($result['data']) && is_array($result['data']))
175
- {
176
- $result = $result['data'];
177
- }
178
- if(isset($result['user_token']))
179
- {
180
- $ct_data['user_token'] = $result['user_token'];
181
- update_option('cleantalk_data', $ct_data);
182
- }
183
- if (isset($result['auth_key']) && !empty($result['auth_key']))
184
- {
185
- $_POST['cleantalk_settings']['apikey'] = $result['auth_key'];
186
- $ct_options['apikey']=$result['auth_key'];
187
- update_option('cleantalk_settings', $ct_options);
188
- /*$ct_base_call_result = ct_base_call(array(
189
- 'message' => 'CleanTalk setup test',
190
- 'example' => null,
191
- 'sender_email' => 'good@cleantalk.org',
192
- 'sender_nickname' => 'CleanTalk',
193
- 'post_info' => '',
194
- 'checkjs' => 1
195
- )); */
196
- } else {
197
- setcookie($ct_notice_autokey_label, (string) base64_encode($result['error_message']), 0, '/');
198
  }
199
- } else {
200
- setcookie($ct_notice_autokey_label, (string) base64_encode(sprintf(__('Unable to connect to %s.', 'cleantalk'), 'api.cleantalk.org')), 0, '/');
201
- }
202
- }
203
-
204
- if (time() > $ct_data['next_account_status_check']||
205
- isset($_POST['option_page'])&&$_POST['option_page']=='cleantalk_settings'&&$ct_options['apikey']!=$_POST['cleantalk_settings']['apikey']) {
206
- $result = false;
207
- if (function_exists('curl_init') && function_exists('json_decode') && ct_valid_key($ct_options['apikey'])) {
208
- if(!function_exists('noticePaidTill'))
209
- {
210
- require_once('cleantalk.class.php');
211
- }
212
- if(@isset($_POST['cleantalk_settings']['apikey']))
213
- {
214
- $result=noticePaidTill($_POST['cleantalk_settings']['apikey']);
215
- }
216
- else
217
- {
218
- $result=noticePaidTill($ct_options['apikey']);
219
- }
220
-
221
- if ($result) {
222
- $result = json_decode($result, true);
223
- if (isset($result['data']) && is_array($result['data'])) {
224
- $result = $result['data'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  }
226
  if(isset($result['spam_count']))
227
  {
228
  $ct_data['admin_blocked']=$result['spam_count'];
229
  }
230
 
231
- if (isset($result['show_notice'])) {
232
- if ($result['show_notice'] == 1 && isset($result['trial']) && $result['trial'] == 1) {
233
- $notice_check_timeout = $trial_notice_check_timeout;
234
- $show_ct_notice_trial = true;
235
- }
236
- if ($result['show_notice'] == 1 && isset($result['renew']) && $result['renew'] == 1) {
237
- $notice_check_timeout = $account_notice_check_timeout;
238
- $show_ct_notice_renew = true;
239
- }
240
-
241
- if ($result['show_notice'] == 0) {
242
- $notice_check_timeout = $account_notice_check_timeout;
243
- }
244
- }
245
-
246
- if (isset($result['user_token'])) {
247
- $ct_data['user_token'] = $result['user_token'];
248
- }
249
- }
250
-
251
- // Save next status request time
252
- $ct_data['next_account_status_check'] = strtotime("+$notice_check_timeout hours", time());
253
- update_option('cleantalk_data', $ct_data);
254
- }
255
-
256
- if ($result) {
257
- if($show_ct_notice_trial == true){
258
- setcookie($ct_notice_trial_label, (string) $show_ct_notice_trial, strtotime("+$trial_notice_showtime minutes"), '/');
259
- }
260
- if($show_ct_notice_renew == true){
261
- setcookie($ct_notice_renew_label, (string) $show_ct_notice_renew, strtotime("+$renew_notice_showtime minutes"), '/');
262
- }
263
- }
264
- }
265
-
266
- $show_ct_notice_online = '';
267
- if (isset($_COOKIE[$ct_notice_online_label])) {
268
- if ($_COOKIE[$ct_notice_online_label] === 'BAD_KEY') {
269
- $show_ct_notice_online = 'N';
270
- } else if (time() - $_COOKIE[$ct_notice_online_label] <= 5) {
271
- $show_ct_notice_online = 'Y';
272
- }
273
- }
274
-
275
- //ct_init_session();
276
-
277
- if(stripos($_SERVER['REQUEST_URI'],'options.php')!==false || stripos($_SERVER['REQUEST_URI'],'options-general.php')!==false)
278
- {
279
-
280
- if(isset($ct_data['testing_failed'])&&$ct_data['testing_failed']==1)
281
- {
282
- $buttons_html='
 
 
 
 
 
 
 
 
 
 
 
 
283
  <style type="text/css">
284
  #ct_button_check_comments, #ct_button_check_users {background: #999999;}
285
-
286
- ';
287
- }
288
- else
289
- {
290
- $buttons_html='
291
  <style type="text/css">
292
  #ct_button_check_comments, #ct_button_check_users {background: #69dd69;}
293
-
294
- ';
295
- }
296
-
297
- $buttons_html.='
298
  #ct_button_check_comments, #ct_button_check_users {padding: 10px; color: #fff; border:0 none;
299
- cursor:pointer;
300
- -webkit-border-radius: 5px;
301
- border-radius: 5px;
302
- font-size: 12pt;
303
- text-decoration:none;
304
- margin-bottom:5px;
305
- display:inline-block;
306
  }
307
 
308
  #ct_stats_banner
@@ -310,10 +345,10 @@ function ct_admin_init() {
310
  padding: 0px;
311
  color: #000;
312
  /*border:2px solid #e5e5e5;*/
313
- font-size: 10pt;
314
- text-decoration:none;
315
- margin-bottom:5px;
316
- display:inline-block;
317
  }
318
  </style>';
319
  if(isset($ct_data['testing_failed'])&&$ct_data['testing_failed']==1)
@@ -326,32 +361,35 @@ function ct_admin_init() {
326
  /*$buttons_html.='<a href="edit-comments.php?page=ct_check_spam&do_check=1" style="font-size:10pt;font-weight:400;">'.__('Check comments', 'cleantalk').'</a><br />
327
  <a href="users.php?page=ct_check_users&do_check=1" style="font-size:10pt;font-weight:400;">'.__('Check users', 'cleantalk').'</a><div class="clear"></div>';*/
328
  }
329
-
330
- register_setting('cleantalk_settings', 'cleantalk_settings', 'ct_settings_validate');
331
- add_settings_section('cleantalk_settings_main', __($ct_plugin_name, 'cleantalk'), 'ct_section_settings_main', 'cleantalk');
332
- add_settings_section('cleantalk_settings_state', "<hr>".__('Protection is active', 'cleantalk'), 'ct_section_settings_state', 'cleantalk');
333
- //add_settings_section('cleantalk_settings_autodel', "<hr>", 'ct_section_settings_autodel', 'cleantalk');
334
- add_settings_section('cleantalk_settings_banner', "<hr></h3>", '', 'cleantalk');
335
- add_settings_section('cleantalk_settings_anti_spam', "<a href='#' style='text-decoration:underline;font-size:10pt;font-weight:400;'>".__('Advanced settings', 'cleantalk')."</a>", 'ct_section_settings_anti_spam', 'cleantalk');
336
-
337
- //if((is_network_admin() || (!defined('WP_ALLOW_MULTISITE')||defined('WP_ALLOW_MULTISITE')&&WP_ALLOW_MULTISITE==false) && is_admin()))
338
- //{
339
- add_settings_field('cleantalk_apikey', __('Access key', 'cleantalk'), 'ct_input_apikey', 'cleantalk', 'cleantalk_settings_main');
340
- //}
341
- add_settings_field('cleantalk_remove_old_spam', __('Automatically delete spam comments', 'cleantalk'), 'ct_input_remove_old_spam', 'cleantalk', 'cleantalk_settings_anti_spam');
342
-
343
- add_settings_field('cleantalk_registrations_test', __('Registration forms', 'cleantalk'), 'ct_input_registrations_test', 'cleantalk', 'cleantalk_settings_anti_spam');
344
- add_settings_field('cleantalk_comments_test', __('Comments form', 'cleantalk'), 'ct_input_comments_test', 'cleantalk', 'cleantalk_settings_anti_spam');
345
- add_settings_field('cleantalk_contact_forms_test', __('Contact forms', 'cleantalk'), 'ct_input_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
346
- add_settings_field('cleantalk_general_contact_forms_test', __('Custom contact forms', 'cleantalk'), 'ct_input_general_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
347
- add_settings_field('cleantalk_general_postdata_test', __('Check all post data', 'cleantalk'), 'ct_input_general_postdata_test', 'cleantalk', 'cleantalk_settings_anti_spam');
348
- add_settings_field('cleantalk_show_adminbar', __('Show statistics in admin bar', 'cleantalk'), 'ct_input_show_adminbar', 'cleantalk', 'cleantalk_settings_anti_spam');
349
- add_settings_field('cleantalk_use_ajax', __('Use AJAX for JavaScript check', 'cleantalk'), 'ct_input_use_ajax', 'cleantalk', 'cleantalk_settings_anti_spam');
350
- add_settings_field('cleantalk_check_external', __('Protect external forms', 'cleantalk'), 'ct_input_check_external', 'cleantalk', 'cleantalk_settings_anti_spam');
351
- add_settings_field('cleantalk_check_comments_number', __("Don't check comments", 'cleantalk'), 'ct_input_check_comments_number', 'cleantalk', 'cleantalk_settings_anti_spam');
352
- //add_settings_field('cleantalk_check_messages_number', __("Don't check messages", 'cleantalk'), 'ct_input_check_messages_number', 'cleantalk', 'cleantalk_settings_anti_spam');
353
- add_settings_field('cleantalk_show_link', __('', 'cleantalk'), 'ct_input_show_link', 'cleantalk', 'cleantalk_settings_banner');
354
- add_settings_field('cleantalk_spam_firewall', __('', 'cleantalk'), 'ct_input_spam_firewall', 'cleantalk', 'cleantalk_settings_anti_spam');
 
 
 
355
  }
356
  }
357
 
@@ -359,46 +397,46 @@ function ct_admin_init() {
359
  * Admin callback function - Displays description of 'main' plugin parameters section
360
  */
361
  function ct_section_settings_main() {
362
- return true;
363
  }
364
 
365
  /**
366
  * Admin callback function - Displays description of 'anti-spam' plugin parameters section
367
  */
368
  function ct_section_settings_anti_spam() {
369
- return true;
370
  }
371
 
372
  add_action( 'admin_bar_menu', 'ct_add_admin_menu', 999 );
373
 
374
  function ct_add_admin_menu( $wp_admin_bar ) {
375
  // add a parent item
376
- global $ct_options, $ct_data;
377
-
378
- $ct_options = ct_get_options();
379
- $ct_data = ct_get_data();
380
-
381
- if(isset($ct_options['show_adminbar']))
382
- {
383
- $value = @intval($ct_options['show_adminbar']);
384
- }
385
- else
386
- {
387
- $value=1;
388
- }
389
-
390
  if ( current_user_can('activate_plugins')&&$value==1 )
391
  {
392
  //$ct_data=ct_get_data();
393
  $args = array(
394
- 'id' => 'ct_parent_node',
395
  'title' => '<img src="' . plugin_dir_url(__FILE__) . 'images/logo_small1.png" alt="" height="" style="margin-top:9px;" /><a href="#" class="ab-item alignright" title="allowed / blocked" alt="allowed / blocked"><span class="ab-label" id="ct_stats"><span>0</span> / <span>0</span></span></a>'
396
  );
397
  $wp_admin_bar->add_node( $args );
398
 
399
  // add a child item to our parent item
400
  $args = array(
401
- 'id' => 'ct_dashboard_link',
402
  'title' => '<a href="https://cleantalk.org/my/?user_token='.@$ct_data['user_token'].'&utm_source=wp-backend&utm_medium=admin-bar" target="_blank">CleanTalk '.__('dashboard', 'cleantalk').'</a>',
403
  'parent' => 'ct_parent_node'
404
  );
@@ -406,7 +444,7 @@ function ct_add_admin_menu( $wp_admin_bar ) {
406
 
407
  // add another child item to our parent item (not to our first group)
408
  $args = array(
409
- 'id' => 'ct_settings_link',
410
  'title' => '<a href="options-general.php?page=cleantalk">'.__('Settings', 'cleantalk').'</a>',
411
  'parent' => 'ct_parent_node'
412
  );
@@ -421,7 +459,7 @@ function ct_section_settings_state() {
421
  global $ct_options, $ct_data;
422
 
423
  $ct_options = ct_get_options();
424
- $ct_data = ct_get_data();
425
 
426
  $img="yes.png";
427
  $img_no="no.png";
@@ -484,25 +522,25 @@ function ct_section_settings_state() {
484
  //print "Testing is failed, check settings. Tech support <a target=_blank href='mailto:support@cleantalk.org'>support@cleantalk.org</a>";
485
  print __("Testing is failed, check settings. Tech support <a target=_blank href='mailto:support@cleantalk.org'>support@cleantalk.org</a>", 'cleantalk');
486
  }
487
- return true;
488
  }
489
 
490
  /**
491
  * Admin callback function - Displays description of 'autodel' plugin parameters section
492
  */
493
  function ct_section_settings_autodel() {
494
- return true;
495
  }
496
 
497
  /**
498
  * Admin callback function - Displays inputs of 'apikey' plugin parameter
499
  */
500
  function ct_input_apikey() {
501
- global $ct_options, $ct_data, $ct_notice_online_label;
502
- $ct_options=ct_get_options();
503
- $ct_data=ct_get_data();
504
-
505
- if(!isset($ct_data['admin_blocked']))
506
  {
507
  $blocked=0;
508
  }
@@ -514,106 +552,115 @@ function ct_input_apikey() {
514
  if($blocked>0)
515
  {
516
  $blocked = number_format($blocked, 0, ',', ' ');
517
-
518
- echo "<script>var cleantalk_blocked_message=\"<div style='height:24px;width:100%;display:table-cell; vertical-align:middle;'><span>CleanTalk ";
519
- printf(
520
- /* translators: %s: Number of spam messages */
521
- __( 'has blocked <b>%s</b> spam.', 'cleantalk' ),
522
- $blocked
523
  );
524
- print "</span></div><br />\";\n";
525
- }
526
- else
527
- {
528
- echo "<script>var cleantalk_blocked_message=\"\";\n";
529
- }
530
- echo "var cleantalk_statistics_link=\"<a target='__blank' href='https://cleantalk.org/my?user_token=".@$ct_data['user_token']."'>".__('Click here to get anti-spam statistics', 'cleantalk')."</a>\";
531
- </script>";
532
-
533
- echo "<script src='".plugins_url( 'cleantalk-admin.js', __FILE__ )."'></script>\n";
534
-
535
- $value = $ct_options['apikey'];
536
- $def_value = '';
537
- echo "<input id='cleantalk_apikey' name='cleantalk_settings[apikey]' size='20' type='text' value='$value' style=\"font-size: 14pt;\"/>";
538
- if (ct_valid_key($value) === false) {
539
- echo "<script>var cleantalk_good_key=false;</script>";
540
- echo "<br /><br /><a target='__blank' class='cleantalk_manual_link' style='text-decoration:none;' href='https://cleantalk.org/register?platform=wordpress&email=".urlencode(get_option('admin_email'))."&website=".urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))."'>".__('Get the Access key', 'cleantalk')."</a>";
541
- if (function_exists('curl_init') && function_exists('json_decode')) {
542
- //echo '<br /><br /><input name="get_apikey_auto" type="submit" value="' . __('Get access key automatically', 'cleantalk') . '" />';
543
- //admin_addDescriptionsFields(sprintf(__('Admin e-mail (%s) will be used for registration', 'cleantalk'), get_option('admin_email')));
544
- //admin_addDescriptionsFields(sprintf('<a target="__blank" style="color:#BBB;" href="https://cleantalk.org/publicoffer">%s</a>', __('License agreement', 'cleantalk')));
545
- }
546
- } else {
547
- echo "<script>var cleantalk_good_key=true;</script>";
548
- if (isset($_COOKIE[$ct_notice_online_label]) && $_COOKIE[$ct_notice_online_label] > 0) {
549
- //echo '&nbsp;&nbsp;<span style="text-decoration: underline;">The key accepted!</span>&nbsp;';
550
- }
551
- //echo "<br /><br /><a target='__blank' href='https://cleantalk.org/my?user_token=".@$ct_data['user_token']."'>".__('Click here to get anti-spam statistics', 'cleantalk')."</a>";
552
- }
 
 
 
 
 
 
 
 
 
553
  }
554
 
555
  /**
556
  * Admin callback function - Displays inputs of 'comments_test' plugin parameter
557
  */
558
  function ct_input_comments_test() {
559
- global $ct_options, $ct_data;
560
-
561
- $ct_options = ct_get_options();
562
- $ct_data = ct_get_data();
563
-
564
- $value = $ct_options['comments_test'];
565
- echo "<input type='radio' id='cleantalk_comments_test1' name='cleantalk_settings[comments_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_comments_test1'> " . __('Yes') . "</label>";
566
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
567
- echo "<input type='radio' id='cleantalk_comments_test0' name='cleantalk_settings[comments_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_comments_test0'> " . __('No') . "</label>";
568
- admin_addDescriptionsFields(__('WordPress, JetPack, WooCommerce', 'cleantalk'));
569
  }
570
 
571
  /**
572
  * Admin callback function - Displays inputs of 'comments_test' plugin parameter
573
  */
574
  function ct_input_registrations_test() {
575
- global $ct_options, $ct_data;
576
-
577
- $ct_options = ct_get_options();
578
- $ct_data = ct_get_data();
579
-
580
- $value = $ct_options['registrations_test'];
581
- echo "<input type='radio' id='cleantalk_registrations_test1' name='cleantalk_settings[registrations_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_registrations_test1'> " . __('Yes') . "</label>";
582
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
583
- echo "<input type='radio' id='cleantalk_registrations_test0' name='cleantalk_settings[registrations_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_registrations_test0'> " . __('No') . "</label>";
584
- admin_addDescriptionsFields(__('WordPress, BuddyPress, bbPress, S2Member, WooCommerce', 'cleantalk'));
585
  }
586
 
587
  /**
588
  * Admin callback function - Displays inputs of 'contact_forms_test' plugin parameter
589
  */
590
  function ct_input_contact_forms_test() {
591
- global $ct_options, $ct_data;
592
-
593
- $ct_options = ct_get_options();
594
- $ct_data = ct_get_data();
595
-
596
- $value = $ct_options['contact_forms_test'];
597
- echo "<input type='radio' id='cleantalk_contact_forms_test1' name='cleantalk_settings[contact_forms_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_contact_forms_test1'> " . __('Yes') . "</label>";
598
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
599
- echo "<input type='radio' id='cleantalk_contact_forms_test0' name='cleantalk_settings[contact_forms_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_contact_forms_test0'> " . __('No') . "</label>";
600
- admin_addDescriptionsFields(__('Contact Form 7, Formiadble forms, JetPack, Fast Secure Contact Form, WordPress Landing Pages', 'cleantalk'));
601
  }
602
 
603
  /**
604
  * Admin callback function - Displays inputs of 'general_contact_forms_test' plugin parameter
605
  */
606
  function ct_input_general_contact_forms_test() {
607
- global $ct_options, $ct_data;
608
-
609
- $ct_options = ct_get_options();
610
- $ct_data = ct_get_data();
611
-
612
- $value = $ct_options['general_contact_forms_test'];
613
- echo "<input type='radio' id='cleantalk_general_contact_forms_test1' name='cleantalk_settings[general_contact_forms_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_general_contact_forms_test1'> " . __('Yes') . "</label>";
614
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
615
- echo "<input type='radio' id='cleantalk_general_contact_forms_test0' name='cleantalk_settings[general_contact_forms_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_general_contact_forms_test0'> " . __('No') . "</label>";
616
- admin_addDescriptionsFields(__('Anti spam test for any WordPress or themes contacts forms', 'cleantalk'));
617
  }
618
 
619
  /**
@@ -623,16 +670,16 @@ function ct_input_general_contact_forms_test() {
623
  * @return null
624
  */
625
  function ct_input_remove_old_spam() {
626
- global $ct_options, $ct_data;
627
-
628
- $ct_options = ct_get_options();
629
- $ct_data = ct_get_data();
630
-
631
- $value = $ct_options['remove_old_spam'];
632
- echo "<input type='radio' id='cleantalk_remove_old_spam1' name='cleantalk_settings[remove_old_spam]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_remove_old_spam1'> " . __('Yes') . "</label>";
633
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
634
- echo "<input type='radio' id='cleantalk_remove_old_spam0' name='cleantalk_settings[remove_old_spam]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_remove_old_spam0'> " . __('No') . "</label>";
635
- admin_addDescriptionsFields(sprintf(__('Delete spam comments older than %d days.', 'cleantalk'), $ct_options['spam_store_days']));
636
  }
637
 
638
  /**
@@ -641,23 +688,23 @@ function ct_input_remove_old_spam() {
641
  * @return null
642
  */
643
  function ct_input_show_adminbar() {
644
- global $ct_options, $ct_data;
645
-
646
- $ct_options = ct_get_options();
647
- $ct_data = ct_get_data();
648
-
649
- if(isset($ct_options['show_adminbar']))
650
- {
651
- $value = @intval($ct_options['show_adminbar']);
652
- }
653
- else
654
- {
655
- $value=1;
656
- }
657
- echo "<input type='radio' id='cleantalk_show_adminbar1' name='cleantalk_settings[show_adminbar]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_show_adminbar1'> " . __('Yes') . "</label>";
658
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
659
- echo "<input type='radio' id='cleantalk_show_adminbar0' name='cleantalk_settings[show_adminbar]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_show_adminbar0'> " . __('No') . "</label>";
660
- admin_addDescriptionsFields(sprintf(__('Show/hide CleanTalk icon in top level menu in WordPress backend.', 'cleantalk'), $ct_options['show_adminbar']));
661
  }
662
 
663
  /**
@@ -666,180 +713,180 @@ function ct_input_show_adminbar() {
666
  * @return null
667
  */
668
  function ct_input_general_postdata_test() {
669
- global $ct_options, $ct_data;
670
-
671
- $ct_options = ct_get_options();
672
- $ct_data = ct_get_data();
673
-
674
- if(isset($ct_options['general_postdata_test']))
675
- {
676
- $value = @intval($ct_options['general_postdata_test']);
677
- }
678
- else
679
- {
680
- $value=0;
681
- }
682
- echo "<input type='radio' id='cleantalk_general_postdata_test1' name='cleantalk_settings[general_postdata_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_general_postdata_test1'> " . __('Yes') . "</label>";
683
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
684
- echo "<input type='radio' id='cleantalk_general_postdata_test0' name='cleantalk_settings[general_postdata_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_general_postdata_test0'> " . __('No') . "</label>";
685
- @admin_addDescriptionsFields(sprintf(__('Check all POST submissions from website visitors. Enable this option if you have spam misses on website or you don`t have records about missed spam in <a href="https://cleantalk.org/my/?user_token='.@$ct_data['user_token'].'&utm_source=wp-backend&utm_medium=admin-bar" target="_blank">CleanTalk dashboard</a>.', 'cleantalk'), $ct_options['general_postdata_test']));
686
  }
687
 
688
  function ct_input_use_ajax() {
689
- global $ct_options, $ct_data;
690
-
691
- $ct_options = ct_get_options();
692
- $ct_data = ct_get_data();
693
-
694
- if(isset($ct_options['use_ajax']))
695
- {
696
- $value = @intval($ct_options['use_ajax']);
697
- }
698
- else
699
- {
700
- $value=1;
701
- }
702
- echo "<input type='radio' id='cleantalk_use_ajax1' name='cleantalk_settings[use_ajax]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_use_ajax1'> " . __('Yes') . "</label>";
703
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
704
- echo "<input type='radio' id='cleantalk_use_ajax0' name='cleantalk_settings[use_ajax]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_use_ajax0'> " . __('No') . "</label>";
705
- @admin_addDescriptionsFields(sprintf(__('', 'cleantalk'), $ct_options['use_ajax']));
706
  }
707
 
708
  function ct_input_check_comments_number() {
709
- global $ct_options, $ct_data;
710
-
711
- $ct_options = ct_get_options();
712
- $ct_data = ct_get_data();
713
-
714
- if(isset($ct_options['check_comments_number']))
715
- {
716
- $value = @intval($ct_options['check_comments_number']);
717
- }
718
- else
719
- {
720
- $value=1;
721
- }
722
-
723
- if(defined('CLEANTALK_CHECK_COMMENTS_NUMBER'))
724
- {
725
- $comments_check_number = CLEANTALK_CHECK_COMMENTS_NUMBER;
726
- }
727
- else
728
- {
729
- $comments_check_number = 3;
730
- }
731
-
732
- echo "<input type='radio' id='cleantalk_check_comments_number1' name='cleantalk_settings[check_comments_number]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_check_comments_number1'> " . __('Yes') . "</label>";
733
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
734
- echo "<input type='radio' id='cleantalk_check_comments_number0' name='cleantalk_settings[check_comments_number]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_check_comments_number0'> " . __('No') . "</label>";
735
- @admin_addDescriptionsFields(sprintf(__("Dont't check comments for users with above $comments_check_number comments", 'cleantalk'), $ct_options['check_comments_number']));
736
  }
737
 
738
  function ct_input_check_messages_number() {
739
- global $ct_options, $ct_data;
740
-
741
- $ct_options = ct_get_options();
742
- $ct_data = ct_get_data();
743
-
744
- if(isset($ct_options['check_messages_number']))
745
- {
746
- $value = @intval($ct_options['check_messages_number']);
747
- }
748
- else
749
- {
750
- $value=0;
751
- }
752
-
753
- if(defined('CLEANTALK_CHECK_MESSAGES_NUMBER'))
754
- {
755
- $messages_check_number = CLEANTALK_CHECK_MESSAGES_NUMBER;
756
- }
757
- else
758
- {
759
- $messages_check_number = 3;
760
- }
761
-
762
- echo "<input type='radio' id='cleantalk_check_messages_number1' name='cleantalk_settings[check_messages_number]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_check_messages_number1'> " . __('Yes') . "</label>";
763
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
764
- echo "<input type='radio' id='cleantalk_check_messages_number0' name='cleantalk_settings[check_messages_number]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_check_messages_number0'> " . __('No') . "</label>";
765
- @admin_addDescriptionsFields(sprintf(__("Dont't check messages for users with above $messages_check_number messages", 'cleantalk'), $ct_options['check_messages_number']));
766
  }
767
 
768
  function ct_input_check_external() {
769
- global $ct_options, $ct_data;
770
-
771
- $ct_options = ct_get_options();
772
- $ct_data = ct_get_data();
773
-
774
- if(isset($ct_options['check_external']))
775
- {
776
- $value = @intval($ct_options['check_external']);
777
- }
778
- else
779
- {
780
- $value=0;
781
- }
782
- echo "<input type='radio' id='cleantalk_check_external1' name='cleantalk_settings[check_external]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_check_external1'> " . __('Yes') . "</label>";
783
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
784
- echo "<input type='radio' id='cleantalk_check_external0' name='cleantalk_settings[check_external]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_check_external0'> " . __('No') . "</label>";
785
- @admin_addDescriptionsFields(sprintf(__('', 'cleantalk'), $ct_options['check_external']));
786
  }
787
 
788
  function ct_input_show_link() {
789
- global $ct_options, $ct_data;
790
-
791
- $ct_options = ct_get_options();
792
- $ct_data = ct_get_data();
793
-
794
- if(isset($ct_options['show_link']))
795
- {
796
- $value = @intval($ct_options['show_link']);
797
- }
798
- else
799
- {
800
- $value=0;
801
- }
802
-
803
  /* echo "<input type='radio' id='cleantalk_show_link1' name='cleantalk_settings[show_link]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_show_link1'> " . __('Yes') . "</label>";
804
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
805
- echo "<input type='radio' id='cleantalk_show_link0' name='cleantalk_settings[show_link]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_show_link0'> " . __('No') . "</label>";*/
806
-
807
- echo "<div id='cleantalk_anchor' style='display:none'></div><input type=hidden name='cleantalk_settings[show_link]' value='0' />";
808
- echo "<input type='checkbox' id='cleantalk_show_link1' name='cleantalk_settings[show_link]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_show_link1'> " . __('Tell others about CleanTalk') . "</label>";
809
- @admin_addDescriptionsFields(sprintf(__("Checking this box places a small link under the comment form that lets others know what anti-spam tool protects your site.", 'cleantalk'), $ct_options['show_link']));
810
- echo "<script>
811
- jQuery(document).ready(function(){
812
- jQuery('#cleantalk_anchor').parent().parent().children().first().hide();
813
- jQuery('#cleantalk_anchor').parent().css('padding-left','0px');
814
- });
815
- </script>";
816
  }
817
 
818
  function ct_input_spam_firewall() {
819
- global $ct_options, $ct_data;
820
-
821
- $ct_options = ct_get_options();
822
- $ct_data = ct_get_data();
823
-
824
- if(isset($ct_options['spam_firewall']))
825
- {
826
- $value = @intval($ct_options['spam_firewall']);
827
- }
828
- else
829
- {
830
- $value=0;
831
- }
832
-
833
- echo "<div id='cleantalk_anchor1' style='display:none'></div><input type=hidden name='cleantalk_settings[spam_firewall]' value='0' />";
834
- echo "<input type='checkbox' id='cleantalk_spam_firewall1' name='cleantalk_settings[spam_firewall]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_spam_firewall1'> " . __('SpamFireWall') . "</label>";
835
- @admin_addDescriptionsFields(sprintf(__("EXPEREMENTAL! Use on your own risk.<br />This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.", 'cleantalk'), $ct_options['spam_firewall']));
836
- echo "<script>
837
- jQuery(document).ready(function(){
838
- jQuery('#cleantalk_anchor1').parent().parent().children().first().hide();
839
- jQuery('#cleantalk_anchor1').parent().css('padding-left','0px');
840
- jQuery('#cleantalk_anchor1').parent().attr('colspan', '2');
841
- });
842
- </script>";
843
  }
844
 
845
 
@@ -847,7 +894,7 @@ function ct_input_spam_firewall() {
847
  * Admin callback function - Plugin parameters validator
848
  */
849
  function ct_settings_validate($input) {
850
- return $input;
851
  }
852
 
853
 
@@ -855,41 +902,90 @@ function ct_settings_validate($input) {
855
  * Admin callback function - Displays plugin options page
856
  */
857
  function ct_settings_page() {
858
- ?>
859
  <style type="text/css">
860
- input[type=submit], .cleantalk_manual_link {padding: 10px; background: #3399FF; color: #fff; border:0 none;
861
- cursor:pointer;
862
- -webkit-border-radius: 5px;
863
- border-radius: 5px;
864
- font-size: 12pt;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
865
  }
866
  .cleantalk_manual_link:hover
867
  {
868
  color:white;
869
  }
 
870
  </style>
871
 
872
- <div>
873
- <form action="options.php" method="post">
874
- <?php settings_fields('cleantalk_settings'); ?>
875
- <?php do_settings_sections('cleantalk'); ?>
876
- <br>
877
- <input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
878
- </form>
879
- </div>
880
- <?php
881
-
882
- if (ct_valid_key() === false)
883
- return null;
884
- ?>
885
- <br />
886
- <br />
887
- <br />
888
- <div>
889
- <?php echo __('Plugin Homepage at', 'cleantalk'); ?> <a href="http://cleantalk.org" target="_blank">cleantalk.org</a>.<br />
890
- <?php echo __('Tech support CleanTalk:', 'cleantalk'); ?> <a href="https://cleantalk.org/forum/viewforum.php?f=25" target="_blank"><?php echo __('CleanTalk tech forum', 'cleantalk'); ?></a>.<br /><?php echo __('Use s@cleantalk.org to test plugin in any WordPress form.', 'cleantalk'); ?><br />
891
- </div>
892
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
893
  }
894
 
895
  /**
@@ -897,85 +993,85 @@ input[type=submit], .cleantalk_manual_link {padding: 10px; background: #3399FF;
897
  * @return bool
898
  */
899
  function cleantalk_admin_notice_message(){
900
- global $show_ct_notice_trial, $show_ct_notice_renew, $show_ct_notice_online, $show_ct_notice_autokey, $ct_notice_autokey_value, $ct_plugin_name, $ct_options, $ct_data;
901
-
902
- $ct_options = ct_get_options();
903
- $ct_data = ct_get_data();
904
-
905
- $user_token = '';
906
- if (isset($ct_data['user_token']) && $ct_data['user_token'] != '') {
907
- $user_token = '&user_token=' . $ct_data['user_token'];
908
- }
909
-
910
- $show_notice = true;
911
-
912
- if(current_user_can('activate_plugins'))
913
- {
914
- $value = 1;
915
- }
916
- else
917
- {
918
- $value = 0;
919
- }
920
-
921
- if ($show_notice && $show_ct_notice_autokey && $value==1) {
922
- echo '<div class="error"><h3>' . sprintf(__("Unable to get Access key automatically: %s", 'cleantalk'), $ct_notice_autokey_value);
923
- echo " <a target='__blank' style='margin-left: 10px' href='https://cleantalk.org/register?platform=wordpress&email=".urlencode(get_option('admin_email'))."&website=".urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))."'>".__('Get the Access key', 'cleantalk').'</a></h3></div>';
924
- }
925
-
926
- if ($show_notice && ct_valid_key($ct_options['apikey']) === false && $value==1) {
927
- echo '<div class="error"><h3>' . sprintf(__("Please enter Access Key in %s settings to enable anti spam protection!", 'cleantalk'), "<a href=\"options-general.php?page=cleantalk\">CleanTalk plugin</a>") . '</h3></div>';
928
- $show_notice = false;
929
- }
930
-
931
- if ($show_notice && $show_ct_notice_trial && $value==1) {
932
- echo '<div class="error"><h3>' . sprintf(__("%s trial period ends, please upgrade to %s!", 'cleantalk'), "<a href=\"options-general.php?page=cleantalk\">$ct_plugin_name</a>", "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20trial$user_token\" target=\"_blank\"><b>premium version</b></a>") . '</h3></div>';
933
- $show_notice = false;
934
- }
935
-
936
- if(isset($ct_data['next_notice_show']))
937
- {
938
- $next_notice_show=$ct_data['next_notice_show'];
939
- }
940
- else
941
- {
942
- $next_notice_show=0;
943
- }
944
-
945
- $link=@$_SERVER["QUERY_STRING"];
946
- if($link!='')
947
- {
948
- $link="?".$link."&close_notice=1";
949
- }
950
- else
951
- {
952
- $link="?close_notice=1";
953
- }
954
-
955
- if ($show_notice && $show_ct_notice_renew && $value==1 && time()>$next_notice_show) {
956
  $button_html = "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20renew$user_token\" target=\"_blank\">" . '<input type="button" class="button button-primary" value="' . __('RENEW ANTI-SPAM', 'cleantalk') . '" />' . "</a>";
957
- echo '<div class="updated"><a href="'.$link.'" style="text-decoration:none;float:right;font-size:16px;margin-top:5px;"><b>X</b></a><h3>' . sprintf(__("Please renew your anti-spam license for %s.", 'cleantalk'), "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20renew$user_token\" target=\"_blank\"><b>" . __('next year', 'cleantalk') ."</b></a>") . '<br /><br />' . $button_html . '</h3></div>';
958
- $show_notice = false;
959
- }
960
-
961
- if ($show_notice && $show_ct_notice_online != '' && $value==1) {
962
- if($show_ct_notice_online === 'Y'){
963
- echo '<div class="updated"><h3><b>';
964
- //echo __("Don’t forget to disable CAPTCHA if you have it!", 'cleantalk');
965
- echo __("Settings updated!", 'cleantalk');
966
- echo '</b></h3></div>';
967
- }
968
-
969
- if($show_ct_notice_online === 'N' && $value==1){
970
- echo '<div class="error"><h3><b>';
971
- echo __("Wrong <a href=\"options-general.php?page=cleantalk\"><b style=\"color: #49C73B;\">Clean</b><b style=\"color: #349ebf;\">Talk</b> access key</a>! Please check it or ask <a target=\"_blank\" href=\"https://cleantalk.org/forum/\">support</a>.", 'cleantalk');
972
- echo '</b></h3></div>';
973
- }
974
- }
975
-
976
- //ct_send_feedback(); -- removed to ct_do_this_hourly()
977
-
978
- return true;
979
  }
980
 
981
  /**
@@ -984,23 +1080,23 @@ function cleantalk_admin_notice_message(){
984
  * Add descriptions for field
985
  */
986
  function admin_addDescriptionsFields($descr = '') {
987
- echo "<div style='font-size: 10pt; color: #666 !important'>$descr</div>";
988
  }
989
 
990
  /**
991
  * Test API key
992
  */
993
  function ct_valid_key($apikey = null) {
994
- global $ct_options, $ct_data;
995
-
996
- $ct_options = ct_get_options();
997
- $ct_data = ct_get_data();
998
-
999
- if ($apikey === null) {
1000
- $apikey = $ct_options['apikey'];
1001
- }
1002
-
1003
- return ($apikey === 'enter key' || $apikey === '') ? false : true;
1004
  }
1005
 
1006
  /**
@@ -1009,15 +1105,15 @@ function ct_valid_key($apikey = null) {
1009
  * @return boolean TRUE
1010
  */
1011
  function ct_comment_approved($comment_object) {
1012
- $comment = get_comment($comment_object->comment_ID, 'ARRAY_A');
1013
- $hash = get_comment_meta($comment_object->comment_ID, 'ct_hash', true);
1014
 
1015
- $comment['comment_content'] = ct_unmark_red($comment['comment_content']);
1016
- $comment['comment_content'] = ct_feedback($hash, $comment['comment_content'], 1);
1017
- $comment['comment_approved'] = 1;
1018
- wp_update_comment($comment);
1019
 
1020
- return true;
1021
  }
1022
 
1023
  /**
@@ -1026,13 +1122,13 @@ function ct_comment_approved($comment_object) {
1026
  * @return boolean TRUE
1027
  */
1028
  function ct_comment_unapproved($comment_object) {
1029
- $comment = get_comment($comment_object->comment_ID, 'ARRAY_A');
1030
- $hash = get_comment_meta($comment_object->comment_ID, 'ct_hash', true);
1031
- ct_feedback($hash, $comment['comment_content'], 0);
1032
- $comment['comment_approved'] = 0;
1033
- wp_update_comment($comment);
1034
 
1035
- return true;
1036
  }
1037
 
1038
  /**
@@ -1041,13 +1137,13 @@ function ct_comment_unapproved($comment_object) {
1041
  * @return boolean TRUE
1042
  */
1043
  function ct_comment_spam($comment_object) {
1044
- $comment = get_comment($comment_object->comment_ID, 'ARRAY_A');
1045
- $hash = get_comment_meta($comment_object->comment_ID, 'ct_hash', true);
1046
- ct_feedback($hash, $comment['comment_content'], 0);
1047
- $comment['comment_approved'] = 'spam';
1048
- wp_update_comment($comment);
1049
 
1050
- return true;
1051
  }
1052
 
1053
 
@@ -1056,13 +1152,13 @@ function ct_comment_spam($comment_object) {
1056
  * @param type $comment_id
1057
  */
1058
  function ct_unspam_comment($comment_id) {
1059
- update_comment_meta($comment_id, '_wp_trash_meta_status', 1);
1060
- $comment = get_comment($comment_id, 'ARRAY_A');
1061
- $hash = get_comment_meta($comment_id, 'ct_hash', true);
1062
- $comment['comment_content'] = ct_unmark_red($comment['comment_content']);
1063
- $comment['comment_content'] = ct_feedback($hash, $comment['comment_content'], 1);
1064
 
1065
- wp_update_comment($comment);
1066
  }
1067
 
1068
  /**
@@ -1071,15 +1167,15 @@ function ct_unspam_comment($comment_id) {
1071
  * @return string New comment text
1072
  */
1073
  function ct_get_comment_text($current_text) {
1074
- global $comment;
1075
- $new_text = $current_text;
1076
- if (isset($comment) && is_object($comment)) {
1077
- $hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
1078
- if (!empty($hash)) {
1079
- $new_text .= '<hr>Cleantalk ID = ' . $hash;
1080
- }
1081
- }
1082
- return $new_text;
1083
  }
1084
 
1085
  /**
@@ -1087,10 +1183,10 @@ function ct_get_comment_text($current_text) {
1087
  * @return null
1088
  */
1089
  function ct_delete_user($user_id) {
1090
- $hash = get_user_meta($user_id, 'ct_hash', true);
1091
- if ($hash !== '') {
1092
- ct_feedback($hash, null, 0);
1093
- }
1094
  }
1095
 
1096
  /**
@@ -1098,16 +1194,23 @@ function ct_delete_user($user_id) {
1098
  * @return array
1099
  */
1100
  if (!function_exists ( 'ct_register_plugin_links')) {
1101
- function ct_register_plugin_links($links, $file) {
1102
- global $ct_plugin_basename;
1103
-
1104
- if ($file == $ct_plugin_basename) {
1105
- $links[] = '<a href="options-general.php?page=cleantalk">' . __( 'Settings' ) . '</a>';
1106
- $links[] = '<a href="http://wordpress.org/plugins/cleantalk-spam-protect/faq/" target="_blank">' . __( 'FAQ','cleantalk' ) . '</a>';
1107
- $links[] = '<a href="http://cleantalk.org/forum" target="_blank">' . __( 'Support','cleantalk' ) . '</a>';
1108
- }
1109
- return $links;
1110
- }
 
 
 
 
 
 
 
1111
  }
1112
 
1113
  /**
@@ -1115,15 +1218,22 @@ if (!function_exists ( 'ct_register_plugin_links')) {
1115
  * @return array
1116
  */
1117
  if (!function_exists ( 'ct_plugin_action_links')) {
1118
- function ct_plugin_action_links($links, $file) {
1119
- global $ct_plugin_basename;
1120
-
1121
- if ($file == $ct_plugin_basename) {
1122
- $settings_link = '<a href="options-general.php?page=cleantalk">' . __( 'Settings' ) . '</a>';
1123
- array_unshift( $links, $settings_link ); // before other links
1124
- }
1125
- return $links;
1126
- }
 
 
 
 
 
 
 
1127
  }
1128
 
1129
  /**
@@ -1131,86 +1241,86 @@ if (!function_exists ( 'ct_plugin_action_links')) {
1131
  * @return array
1132
  */
1133
  function ct_update_option($option_name) {
1134
- global $show_ct_notice_online, $ct_notice_online_label, $ct_notice_trial_label, $trial_notice_showtime, $ct_options, $ct_data, $ct_server_timeout;
1135
-
1136
- $ct_options = ct_get_options(true);
1137
- $ct_data = ct_get_data(true);
1138
-
1139
- if($option_name !== 'cleantalk_settings') {
1140
- return;
1141
- }
1142
-
1143
- $api_key = $ct_options['apikey'];
1144
- if (isset($_POST['cleantalk_settings']['apikey'])) {
1145
- $api_key = trim($_POST['cleantalk_settings']['apikey']);
1146
- $ct_options['apikey'] = $api_key;
1147
- }
1148
-
1149
- if(@isset($_POST['cleantalk_settings']['spam_firewall']) && $_POST['cleantalk_settings']['spam_firewall']==1 || isset($ct_options['spam_firewall']) && intval($ct_options['spam_firewall'])==1)
1150
- {
1151
- cleantalk_update_sfw();
1152
- }
1153
-
1154
- if (!ct_valid_key($api_key)) {
1155
- return;
1156
- }
1157
-
1158
- /*$ct_base_call_result = ct_base_call(array(
1159
- 'message' => 'CleanTalk setup test',
1160
- 'example' => null,
1161
- 'sender_email' => 'good@cleantalk.org',
1162
- 'sender_nickname' => 'CleanTalk',
1163
- 'post_info' => '',
1164
- 'checkjs' => 1
1165
- ));*/
1166
-
1167
- $key_valid = true;
1168
- $app_server_error = false;
1169
- $ct_data['testing_failed']=0;
1170
-
1171
-
1172
- if(!function_exists('sendRawRequest'))
1173
- {
1174
- require_once('cleantalk.class.php');
1175
- }
1176
-
1177
- $request=Array();
1178
  $request['method_name'] = 'notice_validate_key';
1179
  $request['auth_key'] = $api_key;
1180
  $url='https://api.cleantalk.org';
1181
  if(!function_exists('sendRawRequest'))
1182
- {
1183
- require_once('cleantalk.class.php');
1184
- }
1185
- $result=sendRawRequest($url, $request);
1186
- if ($result)
1187
- {
1188
- $result = json_decode($result, true);
1189
- if (isset($result['valid']) && $result['valid'] == 0) {
1190
- $key_valid = false;
1191
- $ct_data['testing_failed']=1;
1192
- }
1193
- }
1194
- if (!$result || !isset($result['valid']))
1195
- {
1196
- $app_server_error = true;
1197
- $ct_data['testing_failed']=1;
1198
- }
1199
-
1200
- update_option('cleantalk_data', $ct_data);
1201
-
1202
- if ($key_valid) {
1203
- // Removes cookie for server errors
1204
- if ($app_server_error) {
1205
- setcookie($ct_notice_online_label, '', 1, '/'); // time 1 is exactly in past even clients time() is wrong
1206
- unset($_COOKIE[$ct_notice_online_label]);
1207
- } else {
1208
- setcookie($ct_notice_online_label, (string) time(), strtotime("+14 days"), '/');
1209
- }
1210
- setcookie($ct_notice_trial_label, '0', strtotime("+$trial_notice_showtime minutes"), '/');
1211
- } else {
1212
- setcookie($ct_notice_online_label, 'BAD_KEY', 0, '/');
1213
- }
1214
  }
1215
 
1216
  /**
@@ -1219,9 +1329,9 @@ function ct_update_option($option_name) {
1219
  * @return string Cleat comment
1220
  */
1221
  function ct_unmark_red($message) {
1222
- $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
1223
 
1224
- return $message;
1225
  }
1226
 
1227
  ?>
22
  $blocked = number_format($blocked, 0, ',', ' ');
23
  print "<div style='height:24px;width:100%;display:table-cell; vertical-align:middle;'><img src='" . plugin_dir_url(__FILE__) . "images/logo_color.png' style='margin-right:1em;vertical-align:middle;'/><span><a href='options-general.php?page=cleantalk'>CleanTalk</a> ";
24
  printf(
25
+ /* translators: %s: Number of spam messages */
26
+ __( 'has blocked %s spam', 'cleantalk' ),
27
+ $blocked
28
  );
29
  print "</span></div>";
30
  }
82
  * @param string $hook URL of hooked page
83
  */
84
  function ct_enqueue_scripts($hook) {
85
+ if ($hook == 'edit-comments.php')
86
+ wp_enqueue_script('ct_reload_script', plugins_url('/cleantalk-rel.js', __FILE__));
87
  }
88
 
89
  /**
90
  * Admin action 'admin_menu' - Add the admin options page
91
  */
92
  function ct_admin_add_page() {
93
+ if(is_network_admin())
94
+ {
95
+ add_submenu_page("settings.php", __('CleanTalk settings', 'cleantalk'), 'CleanTalk', 'manage_options', 'cleantalk', 'ct_settings_page');
96
+ }
97
+ else
98
+ {
99
+ add_options_page(__('CleanTalk settings', 'cleantalk'), 'CleanTalk', 'manage_options', 'cleantalk', 'ct_settings_page');
100
+ }
101
  }
102
 
103
  /**
104
  * Admin action 'admin_init' - Add the admin settings and such
105
  */
106
+ function ct_admin_init()
107
+ {
108
+ global $ct_server_timeout, $show_ct_notice_autokey, $ct_notice_autokey_label, $ct_notice_autokey_value, $show_ct_notice_renew, $ct_notice_renew_label, $show_ct_notice_trial, $ct_notice_trial_label, $show_ct_notice_online, $ct_notice_online_label, $renew_notice_showtime, $trial_notice_showtime, $ct_plugin_name, $ct_options, $ct_data, $trial_notice_check_timeout, $account_notice_check_timeout, $ct_user_token_label, $cleantalk_plugin_version, $notice_check_timeout;
109
+
110
+ $ct_options = ct_get_options();
111
+ $ct_data = ct_get_data();
112
+
113
+ $current_version=@trim($ct_data['current_version']);
114
+ if($current_version!=$cleantalk_plugin_version)
115
+ {
116
+ $ct_data['current_version']=$cleantalk_plugin_version;
117
+ update_option('cleantalk_data', $ct_data);
118
+ $ct_base_call_result = ct_base_call(array(
119
+ 'message' => 'This message is a test to check the connection to the CleanTalk servers. ',
120
+ 'example' => null,
121
+ 'sender_email' => 'good@cleantalk.org',
122
+ 'sender_nickname' => 'CleanTalk',
123
+ 'post_info' => '',
124
+ 'checkjs' => 1
125
+ ));
126
+ }
127
+ if(isset($_POST['option_page'])&&$_POST['option_page']=='cleantalk_settings')
128
+ {
129
+ $ct_base_call_result = ct_base_call(array(
130
+ 'message' => 'This message is a test to check the connection to the CleanTalk servers. ',
131
+ 'example' => null,
132
+ 'sender_email' => 'good@cleantalk.org',
133
+ 'sender_nickname' => 'CleanTalk',
134
+ 'post_info' => '',
135
+ 'checkjs' => 1
136
+ ));
137
+ }
138
+
139
+ if(@isset($_POST['cleantalk_settings']['spam_firewall']) && $_POST['cleantalk_settings']['spam_firewall']==1 || isset($ct_options['spam_firewall']) && intval($ct_options['spam_firewall'])==1)
140
+ {
141
+ cleantalk_update_sfw();
142
+ }
143
+
144
+ $show_ct_notice_trial = false;
145
+ if (isset($_COOKIE[$ct_notice_trial_label]))
146
+ {
147
+ if ($_COOKIE[$ct_notice_trial_label] == 1)
148
+ {
149
+ $show_ct_notice_trial = true;
150
+ }
151
+ }
152
+ $show_ct_notice_renew = false;
153
+ if (isset($_COOKIE[$ct_notice_renew_label]))
154
+ {
155
+ if ($_COOKIE[$ct_notice_renew_label] == 1)
156
+ {
157
+ $show_ct_notice_renew = true;
158
+ }
159
+ }
160
+ $show_ct_notice_autokey = false;
161
+ if (isset($_COOKIE[$ct_notice_autokey_label]) && !empty($_COOKIE[$ct_notice_autokey_label]))
162
+ {
163
+ if (!empty($_COOKIE[$ct_notice_autokey_label]))
164
+ {
165
+ $show_ct_notice_autokey = true;
166
+ $ct_notice_autokey_value = base64_decode($_COOKIE[$ct_notice_autokey_label]);
167
+ setcookie($ct_notice_autokey_label, '', 1, '/');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
+ }
170
+
171
+ if (isset($_POST['get_apikey_auto']))
172
+ {
173
+ $email = get_option('admin_email');
174
+ $website = parse_url(get_option('siteurl'),PHP_URL_HOST);
175
+ $platform = 'wordpress';
176
+
177
+ if(!function_exists('getAutoKey'))
178
+ {
179
+ require_once('cleantalk.class.php');
180
+ }
181
+
182
+ $result = getAutoKey($email, $website, $platform);
183
+
184
+ if ($result)
185
+ {
186
+ $ct_data['next_account_status_check']=0;
187
+ update_option('cleantalk_data', $ct_data);
188
+ $result = json_decode($result, true);
189
+ if (isset($result['data']) && is_array($result['data']))
190
+ {
191
+ $result = $result['data'];
192
+ }
193
+ if(isset($result['user_token']))
194
+ {
195
+ $ct_data['user_token'] = $result['user_token'];
196
+ update_option('cleantalk_data', $ct_data);
197
+ }
198
+ if (isset($result['auth_key']) && !empty($result['auth_key']))
199
+ {
200
+ $_POST['cleantalk_settings']['apikey'] = $result['auth_key'];
201
+ $ct_options['apikey']=$result['auth_key'];
202
+ update_option('cleantalk_settings', $ct_options);
203
+ /*$ct_base_call_result = ct_base_call(array(
204
+ 'message' => 'CleanTalk setup test',
205
+ 'example' => null,
206
+ 'sender_email' => 'good@cleantalk.org',
207
+ 'sender_nickname' => 'CleanTalk',
208
+ 'post_info' => '',
209
+ 'checkjs' => 1
210
+ )); */
211
+ }
212
+ else
213
+ {
214
+ setcookie($ct_notice_autokey_label, (string) base64_encode($result['error_message']), 0, '/');
215
+ }
216
+ }
217
+ else
218
+ {
219
+ setcookie($ct_notice_autokey_label, (string) base64_encode(sprintf(__('Unable to connect to %s.', 'cleantalk'), 'api.cleantalk.org')), 0, '/');
220
+ }
221
+ }
222
+
223
+ if (time() > $ct_data['next_account_status_check']||
224
+ isset($_POST['option_page'])&&$_POST['option_page']=='cleantalk_settings'&&$ct_options['apikey']!=$_POST['cleantalk_settings']['apikey'])
225
+ {
226
+ $result = false;
227
+ if (function_exists('curl_init') && function_exists('json_decode') && ct_valid_key($ct_options['apikey']))
228
+ {
229
+ if(!function_exists('noticePaidTill'))
230
+ {
231
+ require_once('cleantalk.class.php');
232
+ }
233
+ if(@isset($_POST['cleantalk_settings']['apikey']))
234
+ {
235
+ $result=noticePaidTill($_POST['cleantalk_settings']['apikey']);
236
+ }
237
+ else
238
+ {
239
+ $result=noticePaidTill($ct_options['apikey']);
240
+ }
241
+
242
+ if ($result)
243
+ {
244
+ $result = json_decode($result, true);
245
+ if (isset($result['data']) && is_array($result['data']))
246
+ {
247
+ $result = $result['data'];
248
  }
249
  if(isset($result['spam_count']))
250
  {
251
  $ct_data['admin_blocked']=$result['spam_count'];
252
  }
253
 
254
+ if (isset($result['show_notice']))
255
+ {
256
+ if ($result['show_notice'] == 1 && isset($result['trial']) && $result['trial'] == 1)
257
+ {
258
+ $notice_check_timeout = $trial_notice_check_timeout;
259
+ $show_ct_notice_trial = true;
260
+ }
261
+ if ($result['show_notice'] == 1 && isset($result['renew']) && $result['renew'] == 1)
262
+ {
263
+ $notice_check_timeout = $account_notice_check_timeout;
264
+ $show_ct_notice_renew = true;
265
+ }
266
+
267
+ if ($result['show_notice'] == 0)
268
+ {
269
+ $notice_check_timeout = $account_notice_check_timeout;
270
+ }
271
+ }
272
+
273
+ if (isset($result['user_token']))
274
+ {
275
+ $ct_data['user_token'] = $result['user_token'];
276
+ }
277
+ }
278
+
279
+ // Save next status request time
280
+ $ct_data['next_account_status_check'] = strtotime("+$notice_check_timeout hours", time());
281
+ update_option('cleantalk_data', $ct_data);
282
+ }
283
+
284
+ if ($result)
285
+ {
286
+ if($show_ct_notice_trial == true)
287
+ {
288
+ setcookie($ct_notice_trial_label, (string) $show_ct_notice_trial, strtotime("+$trial_notice_showtime minutes"), '/');
289
+ }
290
+ if($show_ct_notice_renew == true)
291
+ {
292
+ setcookie($ct_notice_renew_label, (string) $show_ct_notice_renew, strtotime("+$renew_notice_showtime minutes"), '/');
293
+ }
294
+ }
295
+ }
296
+
297
+ $show_ct_notice_online = '';
298
+ if (isset($_COOKIE[$ct_notice_online_label]))
299
+ {
300
+ if ($_COOKIE[$ct_notice_online_label] === 'BAD_KEY')
301
+ {
302
+ $show_ct_notice_online = 'N';
303
+ }
304
+ else if (time() - $_COOKIE[$ct_notice_online_label] <= 5)
305
+ {
306
+ $show_ct_notice_online = 'Y';
307
+ }
308
+ }
309
+
310
+ //ct_init_session();
311
+
312
+ if(stripos($_SERVER['REQUEST_URI'],'options.php')!==false || stripos($_SERVER['REQUEST_URI'],'options-general.php')!==false || stripos($_SERVER['REQUEST_URI'],'network/settings.php')!==false)
313
+ {
314
+
315
+ if(isset($ct_data['testing_failed'])&&$ct_data['testing_failed']==1)
316
+ {
317
+ $buttons_html='
318
  <style type="text/css">
319
  #ct_button_check_comments, #ct_button_check_users {background: #999999;}
320
+
321
+ ';
322
+ }
323
+ else
324
+ {
325
+ $buttons_html='
326
  <style type="text/css">
327
  #ct_button_check_comments, #ct_button_check_users {background: #69dd69;}
328
+
329
+ ';
330
+ }
331
+
332
+ $buttons_html.='
333
  #ct_button_check_comments, #ct_button_check_users {padding: 10px; color: #fff; border:0 none;
334
+ cursor:pointer;
335
+ -webkit-border-radius: 5px;
336
+ border-radius: 5px;
337
+ font-size: 12pt;
338
+ text-decoration:none;
339
+ margin-bottom:5px;
340
+ display:inline-block;
341
  }
342
 
343
  #ct_stats_banner
345
  padding: 0px;
346
  color: #000;
347
  /*border:2px solid #e5e5e5;*/
348
+ font-size: 10pt;
349
+ text-decoration:none;
350
+ margin-bottom:5px;
351
+ display:inline-block;
352
  }
353
  </style>';
354
  if(isset($ct_data['testing_failed'])&&$ct_data['testing_failed']==1)
361
  /*$buttons_html.='<a href="edit-comments.php?page=ct_check_spam&do_check=1" style="font-size:10pt;font-weight:400;">'.__('Check comments', 'cleantalk').'</a><br />
362
  <a href="users.php?page=ct_check_users&do_check=1" style="font-size:10pt;font-weight:400;">'.__('Check users', 'cleantalk').'</a><div class="clear"></div>';*/
363
  }
364
+ register_setting('cleantalk_settings', 'cleantalk_settings', 'ct_settings_validate');
365
+ add_settings_section('cleantalk_settings_main', __($ct_plugin_name, 'cleantalk'), 'ct_section_settings_main', 'cleantalk');
366
+ add_settings_section('cleantalk_settings_state', "<hr>".__('Protection is active', 'cleantalk'), 'ct_section_settings_state', 'cleantalk');
367
+ //add_settings_section('cleantalk_settings_autodel', "<hr>", 'ct_section_settings_autodel', 'cleantalk');
368
+ add_settings_section('cleantalk_settings_banner', "<hr></h3>", '', 'cleantalk');
369
+ add_settings_section('cleantalk_settings_anti_spam', "<a href='#' style='text-decoration:underline;font-size:10pt;font-weight:400;'>".__('Advanced settings', 'cleantalk')."</a>", 'ct_section_settings_anti_spam', 'cleantalk');
370
+
371
+ if(!defined('CLEANTALK_ACCESS_KEY'))
372
+ {
373
+ add_settings_field('cleantalk_apikey', __('Access key', 'cleantalk'), 'ct_input_apikey', 'cleantalk', 'cleantalk_settings_main');
374
+ }
375
+ else
376
+ {
377
+ add_settings_field('cleantalk_apikey', '', 'ct_input_apikey', 'cleantalk', 'cleantalk_settings_main');
378
+ }
379
+ add_settings_field('cleantalk_remove_old_spam', __('Automatically delete spam comments', 'cleantalk'), 'ct_input_remove_old_spam', 'cleantalk', 'cleantalk_settings_anti_spam');
380
+
381
+ add_settings_field('cleantalk_registrations_test', __('Registration forms', 'cleantalk'), 'ct_input_registrations_test', 'cleantalk', 'cleantalk_settings_anti_spam');
382
+ add_settings_field('cleantalk_comments_test', __('Comments form', 'cleantalk'), 'ct_input_comments_test', 'cleantalk', 'cleantalk_settings_anti_spam');
383
+ add_settings_field('cleantalk_contact_forms_test', __('Contact forms', 'cleantalk'), 'ct_input_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
384
+ add_settings_field('cleantalk_general_contact_forms_test', __('Custom contact forms', 'cleantalk'), 'ct_input_general_contact_forms_test', 'cleantalk', 'cleantalk_settings_anti_spam');
385
+ add_settings_field('cleantalk_general_postdata_test', __('Check all post data', 'cleantalk'), 'ct_input_general_postdata_test', 'cleantalk', 'cleantalk_settings_anti_spam');
386
+ add_settings_field('cleantalk_show_adminbar', __('Show statistics in admin bar', 'cleantalk'), 'ct_input_show_adminbar', 'cleantalk', 'cleantalk_settings_anti_spam');
387
+ add_settings_field('cleantalk_use_ajax', __('Use AJAX for JavaScript check', 'cleantalk'), 'ct_input_use_ajax', 'cleantalk', 'cleantalk_settings_anti_spam');
388
+ add_settings_field('cleantalk_check_external', __('Protect external forms', 'cleantalk'), 'ct_input_check_external', 'cleantalk', 'cleantalk_settings_anti_spam');
389
+ add_settings_field('cleantalk_check_comments_number', __("Don't check comments", 'cleantalk'), 'ct_input_check_comments_number', 'cleantalk', 'cleantalk_settings_anti_spam');
390
+ //add_settings_field('cleantalk_check_messages_number', __("Don't check messages", 'cleantalk'), 'ct_input_check_messages_number', 'cleantalk', 'cleantalk_settings_anti_spam');
391
+ add_settings_field('cleantalk_show_link', __('', 'cleantalk'), 'ct_input_show_link', 'cleantalk', 'cleantalk_settings_banner');
392
+ add_settings_field('cleantalk_spam_firewall', __('', 'cleantalk'), 'ct_input_spam_firewall', 'cleantalk', 'cleantalk_settings_anti_spam');
393
  }
394
  }
395
 
397
  * Admin callback function - Displays description of 'main' plugin parameters section
398
  */
399
  function ct_section_settings_main() {
400
+ return true;
401
  }
402
 
403
  /**
404
  * Admin callback function - Displays description of 'anti-spam' plugin parameters section
405
  */
406
  function ct_section_settings_anti_spam() {
407
+ return true;
408
  }
409
 
410
  add_action( 'admin_bar_menu', 'ct_add_admin_menu', 999 );
411
 
412
  function ct_add_admin_menu( $wp_admin_bar ) {
413
  // add a parent item
414
+ global $ct_options, $ct_data;
415
+
416
+ $ct_options = ct_get_options();
417
+ $ct_data = ct_get_data();
418
+
419
+ if(isset($ct_options['show_adminbar']))
420
+ {
421
+ $value = @intval($ct_options['show_adminbar']);
422
+ }
423
+ else
424
+ {
425
+ $value=1;
426
+ }
427
+
428
  if ( current_user_can('activate_plugins')&&$value==1 )
429
  {
430
  //$ct_data=ct_get_data();
431
  $args = array(
432
+ 'id' => 'ct_parent_node',
433
  'title' => '<img src="' . plugin_dir_url(__FILE__) . 'images/logo_small1.png" alt="" height="" style="margin-top:9px;" /><a href="#" class="ab-item alignright" title="allowed / blocked" alt="allowed / blocked"><span class="ab-label" id="ct_stats"><span>0</span> / <span>0</span></span></a>'
434
  );
435
  $wp_admin_bar->add_node( $args );
436
 
437
  // add a child item to our parent item
438
  $args = array(
439
+ 'id' => 'ct_dashboard_link',
440
  'title' => '<a href="https://cleantalk.org/my/?user_token='.@$ct_data['user_token'].'&utm_source=wp-backend&utm_medium=admin-bar" target="_blank">CleanTalk '.__('dashboard', 'cleantalk').'</a>',
441
  'parent' => 'ct_parent_node'
442
  );
444
 
445
  // add another child item to our parent item (not to our first group)
446
  $args = array(
447
+ 'id' => 'ct_settings_link',
448
  'title' => '<a href="options-general.php?page=cleantalk">'.__('Settings', 'cleantalk').'</a>',
449
  'parent' => 'ct_parent_node'
450
  );
459
  global $ct_options, $ct_data;
460
 
461
  $ct_options = ct_get_options();
462
+ $ct_data = ct_get_data();
463
 
464
  $img="yes.png";
465
  $img_no="no.png";
522
  //print "Testing is failed, check settings. Tech support <a target=_blank href='mailto:support@cleantalk.org'>support@cleantalk.org</a>";
523
  print __("Testing is failed, check settings. Tech support <a target=_blank href='mailto:support@cleantalk.org'>support@cleantalk.org</a>", 'cleantalk');
524
  }
525
+ return true;
526
  }
527
 
528
  /**
529
  * Admin callback function - Displays description of 'autodel' plugin parameters section
530
  */
531
  function ct_section_settings_autodel() {
532
+ return true;
533
  }
534
 
535
  /**
536
  * Admin callback function - Displays inputs of 'apikey' plugin parameter
537
  */
538
  function ct_input_apikey() {
539
+ global $ct_options, $ct_data, $ct_notice_online_label;
540
+ $ct_options=ct_get_options();
541
+ $ct_data=ct_get_data();
542
+
543
+ if(!isset($ct_data['admin_blocked']))
544
  {
545
  $blocked=0;
546
  }
552
  if($blocked>0)
553
  {
554
  $blocked = number_format($blocked, 0, ',', ' ');
555
+
556
+ echo "<script>var cleantalk_blocked_message=\"<div style='height:24px;width:100%;display:table-cell; vertical-align:middle;'><span>CleanTalk ";
557
+ printf(
558
+ /* translators: %s: Number of spam messages */
559
+ __( 'has blocked <b>%s</b> spam.', 'cleantalk' ),
560
+ $blocked
561
  );
562
+ print "</span></div><br />\";\n";
563
+ }
564
+ else
565
+ {
566
+ echo "<script>var cleantalk_blocked_message=\"\";\n";
567
+ }
568
+ echo "var cleantalk_statistics_link=\"<a class='cleantalk_manual_link' target='__blank' href='https://cleantalk.org/my?user_token=".@$ct_data['user_token']."'>".__('Click here to get anti-spam statistics', 'cleantalk')."</a>\";
569
+ </script>";
570
+
571
+ $value = $ct_options['apikey'];
572
+ $def_value = '';
573
+ $is_wpmu=false;
574
+ if(!defined('CLEANTALK_ACCESS_KEY'))
575
+ {
576
+ echo "<input id='cleantalk_apikey' name='cleantalk_settings[apikey]' size='20' type='text' value='$value' style=\"font-size: 14pt;\"/>";
577
+ echo "<script>var cleantalk_wpmu=false;</script>";
578
+ }
579
+ else
580
+ {
581
+ echo "<script>var cleantalk_wpmu=true;</script>";
582
+ $is_wpmu=true;
583
+ }
584
+ echo "<script src='".plugins_url( 'cleantalk-admin.js', __FILE__ )."'></script>\n";
585
+ if (ct_valid_key($value) === false && !$is_wpmu) {
586
+ echo "<script>var cleantalk_good_key=false;</script>";
587
+ echo "<br /><br /><a target='__blank' class='cleantalk_manual_link' style='text-decoration:none;' href='https://cleantalk.org/register?platform=wordpress&email=".urlencode(get_option('admin_email'))."&website=".urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))."'>".__('Get the Access key', 'cleantalk')."</a>";
588
+ if (function_exists('curl_init') && function_exists('json_decode')) {
589
+ //echo '<br /><br /><input name="get_apikey_auto" type="submit" value="' . __('Get access key automatically', 'cleantalk') . '" />';
590
+ //admin_addDescriptionsFields(sprintf(__('Admin e-mail (%s) will be used for registration', 'cleantalk'), get_option('admin_email')));
591
+ //admin_addDescriptionsFields(sprintf('<a target="__blank" style="color:#BBB;" href="https://cleantalk.org/publicoffer">%s</a>', __('License agreement', 'cleantalk')));
592
+ }
593
+ } else {
594
+ echo "<script>var cleantalk_good_key=true;</script>";
595
+ if (isset($_COOKIE[$ct_notice_online_label]) && $_COOKIE[$ct_notice_online_label] > 0) {
596
+ //echo '&nbsp;&nbsp;<span style="text-decoration: underline;">The key accepted!</span>&nbsp;';
597
+ }
598
+ //echo "<br /><br /><a class='cleantalk_manual_link' target='__blank' href='https://cleantalk.org/my?user_token=".@$ct_data['user_token']."'>".__('Click here to get anti-spam statistics', 'cleantalk')."</a>";
599
+ }
600
  }
601
 
602
  /**
603
  * Admin callback function - Displays inputs of 'comments_test' plugin parameter
604
  */
605
  function ct_input_comments_test() {
606
+ global $ct_options, $ct_data;
607
+
608
+ $ct_options = ct_get_options();
609
+ $ct_data = ct_get_data();
610
+
611
+ $value = $ct_options['comments_test'];
612
+ echo "<input type='radio' id='cleantalk_comments_test1' name='cleantalk_settings[comments_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_comments_test1'> " . __('Yes') . "</label>";
613
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
614
+ echo "<input type='radio' id='cleantalk_comments_test0' name='cleantalk_settings[comments_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_comments_test0'> " . __('No') . "</label>";
615
+ admin_addDescriptionsFields(__('WordPress, JetPack, WooCommerce', 'cleantalk'));
616
  }
617
 
618
  /**
619
  * Admin callback function - Displays inputs of 'comments_test' plugin parameter
620
  */
621
  function ct_input_registrations_test() {
622
+ global $ct_options, $ct_data;
623
+
624
+ $ct_options = ct_get_options();
625
+ $ct_data = ct_get_data();
626
+
627
+ $value = $ct_options['registrations_test'];
628
+ echo "<input type='radio' id='cleantalk_registrations_test1' name='cleantalk_settings[registrations_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_registrations_test1'> " . __('Yes') . "</label>";
629
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
630
+ echo "<input type='radio' id='cleantalk_registrations_test0' name='cleantalk_settings[registrations_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_registrations_test0'> " . __('No') . "</label>";
631
+ admin_addDescriptionsFields(__('WordPress, BuddyPress, bbPress, S2Member, WooCommerce', 'cleantalk'));
632
  }
633
 
634
  /**
635
  * Admin callback function - Displays inputs of 'contact_forms_test' plugin parameter
636
  */
637
  function ct_input_contact_forms_test() {
638
+ global $ct_options, $ct_data;
639
+
640
+ $ct_options = ct_get_options();
641
+ $ct_data = ct_get_data();
642
+
643
+ $value = $ct_options['contact_forms_test'];
644
+ echo "<input type='radio' id='cleantalk_contact_forms_test1' name='cleantalk_settings[contact_forms_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_contact_forms_test1'> " . __('Yes') . "</label>";
645
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
646
+ echo "<input type='radio' id='cleantalk_contact_forms_test0' name='cleantalk_settings[contact_forms_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_contact_forms_test0'> " . __('No') . "</label>";
647
+ admin_addDescriptionsFields(__('Contact Form 7, Formiadble forms, JetPack, Fast Secure Contact Form, WordPress Landing Pages', 'cleantalk'));
648
  }
649
 
650
  /**
651
  * Admin callback function - Displays inputs of 'general_contact_forms_test' plugin parameter
652
  */
653
  function ct_input_general_contact_forms_test() {
654
+ global $ct_options, $ct_data;
655
+
656
+ $ct_options = ct_get_options();
657
+ $ct_data = ct_get_data();
658
+
659
+ $value = $ct_options['general_contact_forms_test'];
660
+ echo "<input type='radio' id='cleantalk_general_contact_forms_test1' name='cleantalk_settings[general_contact_forms_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_general_contact_forms_test1'> " . __('Yes') . "</label>";
661
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
662
+ echo "<input type='radio' id='cleantalk_general_contact_forms_test0' name='cleantalk_settings[general_contact_forms_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_general_contact_forms_test0'> " . __('No') . "</label>";
663
+ admin_addDescriptionsFields(__('Anti spam test for any WordPress or themes contacts forms', 'cleantalk'));
664
  }
665
 
666
  /**
670
  * @return null
671
  */
672
  function ct_input_remove_old_spam() {
673
+ global $ct_options, $ct_data;
674
+
675
+ $ct_options = ct_get_options();
676
+ $ct_data = ct_get_data();
677
+
678
+ $value = $ct_options['remove_old_spam'];
679
+ echo "<input type='radio' id='cleantalk_remove_old_spam1' name='cleantalk_settings[remove_old_spam]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_remove_old_spam1'> " . __('Yes') . "</label>";
680
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
681
+ echo "<input type='radio' id='cleantalk_remove_old_spam0' name='cleantalk_settings[remove_old_spam]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_remove_old_spam0'> " . __('No') . "</label>";
682
+ admin_addDescriptionsFields(sprintf(__('Delete spam comments older than %d days.', 'cleantalk'), $ct_options['spam_store_days']));
683
  }
684
 
685
  /**
688
  * @return null
689
  */
690
  function ct_input_show_adminbar() {
691
+ global $ct_options, $ct_data;
692
+
693
+ $ct_options = ct_get_options();
694
+ $ct_data = ct_get_data();
695
+
696
+ if(isset($ct_options['show_adminbar']))
697
+ {
698
+ $value = @intval($ct_options['show_adminbar']);
699
+ }
700
+ else
701
+ {
702
+ $value=1;
703
+ }
704
+ echo "<input type='radio' id='cleantalk_show_adminbar1' name='cleantalk_settings[show_adminbar]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_show_adminbar1'> " . __('Yes') . "</label>";
705
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
706
+ echo "<input type='radio' id='cleantalk_show_adminbar0' name='cleantalk_settings[show_adminbar]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_show_adminbar0'> " . __('No') . "</label>";
707
+ admin_addDescriptionsFields(sprintf(__('Show/hide CleanTalk icon in top level menu in WordPress backend.', 'cleantalk'), $ct_options['show_adminbar']));
708
  }
709
 
710
  /**
713
  * @return null
714
  */
715
  function ct_input_general_postdata_test() {
716
+ global $ct_options, $ct_data;
717
+
718
+ $ct_options = ct_get_options();
719
+ $ct_data = ct_get_data();
720
+
721
+ if(isset($ct_options['general_postdata_test']))
722
+ {
723
+ $value = @intval($ct_options['general_postdata_test']);
724
+ }
725
+ else
726
+ {
727
+ $value=0;
728
+ }
729
+ echo "<input type='radio' id='cleantalk_general_postdata_test1' name='cleantalk_settings[general_postdata_test]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_general_postdata_test1'> " . __('Yes') . "</label>";
730
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
731
+ echo "<input type='radio' id='cleantalk_general_postdata_test0' name='cleantalk_settings[general_postdata_test]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_general_postdata_test0'> " . __('No') . "</label>";
732
+ @admin_addDescriptionsFields(sprintf(__('Check all POST submissions from website visitors. Enable this option if you have spam misses on website or you don`t have records about missed spam in <a href="https://cleantalk.org/my/?user_token='.@$ct_data['user_token'].'&utm_source=wp-backend&utm_medium=admin-bar" target="_blank">CleanTalk dashboard</a>.<br />СAUTION! Option can catch POST requests in WordPress backend', 'cleantalk'), $ct_options['general_postdata_test']));
733
  }
734
 
735
  function ct_input_use_ajax() {
736
+ global $ct_options, $ct_data;
737
+
738
+ $ct_options = ct_get_options();
739
+ $ct_data = ct_get_data();
740
+
741
+ if(isset($ct_options['use_ajax']))
742
+ {
743
+ $value = @intval($ct_options['use_ajax']);
744
+ }
745
+ else
746
+ {
747
+ $value=1;
748
+ }
749
+ echo "<input type='radio' id='cleantalk_use_ajax1' name='cleantalk_settings[use_ajax]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_use_ajax1'> " . __('Yes') . "</label>";
750
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
751
+ echo "<input type='radio' id='cleantalk_use_ajax0' name='cleantalk_settings[use_ajax]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_use_ajax0'> " . __('No') . "</label>";
752
+ @admin_addDescriptionsFields(sprintf(__('', 'cleantalk'), $ct_options['use_ajax']));
753
  }
754
 
755
  function ct_input_check_comments_number() {
756
+ global $ct_options, $ct_data;
757
+
758
+ $ct_options = ct_get_options();
759
+ $ct_data = ct_get_data();
760
+
761
+ if(isset($ct_options['check_comments_number']))
762
+ {
763
+ $value = @intval($ct_options['check_comments_number']);
764
+ }
765
+ else
766
+ {
767
+ $value=1;
768
+ }
769
+
770
+ if(defined('CLEANTALK_CHECK_COMMENTS_NUMBER'))
771
+ {
772
+ $comments_check_number = CLEANTALK_CHECK_COMMENTS_NUMBER;
773
+ }
774
+ else
775
+ {
776
+ $comments_check_number = 3;
777
+ }
778
+
779
+ echo "<input type='radio' id='cleantalk_check_comments_number1' name='cleantalk_settings[check_comments_number]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_check_comments_number1'> " . __('Yes') . "</label>";
780
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
781
+ echo "<input type='radio' id='cleantalk_check_comments_number0' name='cleantalk_settings[check_comments_number]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_check_comments_number0'> " . __('No') . "</label>";
782
+ @admin_addDescriptionsFields(sprintf(__("Dont't check comments for users with above $comments_check_number comments", 'cleantalk'), $ct_options['check_comments_number']));
783
  }
784
 
785
  function ct_input_check_messages_number() {
786
+ global $ct_options, $ct_data;
787
+
788
+ $ct_options = ct_get_options();
789
+ $ct_data = ct_get_data();
790
+
791
+ if(isset($ct_options['check_messages_number']))
792
+ {
793
+ $value = @intval($ct_options['check_messages_number']);
794
+ }
795
+ else
796
+ {
797
+ $value=0;
798
+ }
799
+
800
+ if(defined('CLEANTALK_CHECK_MESSAGES_NUMBER'))
801
+ {
802
+ $messages_check_number = CLEANTALK_CHECK_MESSAGES_NUMBER;
803
+ }
804
+ else
805
+ {
806
+ $messages_check_number = 3;
807
+ }
808
+
809
+ echo "<input type='radio' id='cleantalk_check_messages_number1' name='cleantalk_settings[check_messages_number]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_check_messages_number1'> " . __('Yes') . "</label>";
810
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
811
+ echo "<input type='radio' id='cleantalk_check_messages_number0' name='cleantalk_settings[check_messages_number]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_check_messages_number0'> " . __('No') . "</label>";
812
+ @admin_addDescriptionsFields(sprintf(__("Dont't check messages for users with above $messages_check_number messages", 'cleantalk'), $ct_options['check_messages_number']));
813
  }
814
 
815
  function ct_input_check_external() {
816
+ global $ct_options, $ct_data;
817
+
818
+ $ct_options = ct_get_options();
819
+ $ct_data = ct_get_data();
820
+
821
+ if(isset($ct_options['check_external']))
822
+ {
823
+ $value = @intval($ct_options['check_external']);
824
+ }
825
+ else
826
+ {
827
+ $value=0;
828
+ }
829
+ echo "<input type='radio' id='cleantalk_check_external1' name='cleantalk_settings[check_external]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_check_external1'> " . __('Yes') . "</label>";
830
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
831
+ echo "<input type='radio' id='cleantalk_check_external0' name='cleantalk_settings[check_external]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_check_external0'> " . __('No') . "</label>";
832
+ @admin_addDescriptionsFields(sprintf(__('', 'cleantalk'), $ct_options['check_external']));
833
  }
834
 
835
  function ct_input_show_link() {
836
+ global $ct_options, $ct_data;
837
+
838
+ $ct_options = ct_get_options();
839
+ $ct_data = ct_get_data();
840
+
841
+ if(isset($ct_options['show_link']))
842
+ {
843
+ $value = @intval($ct_options['show_link']);
844
+ }
845
+ else
846
+ {
847
+ $value=0;
848
+ }
849
+
850
  /* echo "<input type='radio' id='cleantalk_show_link1' name='cleantalk_settings[show_link]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_show_link1'> " . __('Yes') . "</label>";
851
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
852
+ echo "<input type='radio' id='cleantalk_show_link0' name='cleantalk_settings[show_link]' value='0' " . ($value == '0' ? 'checked' : '') . " /><label for='cleantalk_show_link0'> " . __('No') . "</label>";*/
853
+
854
+ echo "<div id='cleantalk_anchor' style='display:none'></div><input type=hidden name='cleantalk_settings[show_link]' value='0' />";
855
+ echo "<input type='checkbox' id='cleantalk_show_link1' name='cleantalk_settings[show_link]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_show_link1'> " . __('Tell others about CleanTalk') . "</label>";
856
+ @admin_addDescriptionsFields(sprintf(__("Checking this box places a small link under the comment form that lets others know what anti-spam tool protects your site.", 'cleantalk'), $ct_options['show_link']));
857
+ echo "<script>
858
+ jQuery(document).ready(function(){
859
+ jQuery('#cleantalk_anchor').parent().parent().children().first().hide();
860
+ jQuery('#cleantalk_anchor').parent().css('padding-left','0px');
861
+ });
862
+ </script>";
863
  }
864
 
865
  function ct_input_spam_firewall() {
866
+ global $ct_options, $ct_data;
867
+
868
+ $ct_options = ct_get_options();
869
+ $ct_data = ct_get_data();
870
+
871
+ if(isset($ct_options['spam_firewall']))
872
+ {
873
+ $value = @intval($ct_options['spam_firewall']);
874
+ }
875
+ else
876
+ {
877
+ $value=0;
878
+ }
879
+
880
+ echo "<div id='cleantalk_anchor1' style='display:none'></div><input type=hidden name='cleantalk_settings[spam_firewall]' value='0' />";
881
+ echo "<input type='checkbox' id='cleantalk_spam_firewall1' name='cleantalk_settings[spam_firewall]' value='1' " . ($value == '1' ? 'checked' : '') . " /><label for='cleantalk_spam_firewall1'> " . __('SpamFireWall') . "</label>";
882
+ @admin_addDescriptionsFields(sprintf(__("EXPEREMENTAL! Use on your own risk.<br />This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.", 'cleantalk'), $ct_options['spam_firewall']));
883
+ echo "<script>
884
+ jQuery(document).ready(function(){
885
+ jQuery('#cleantalk_anchor1').parent().parent().children().first().hide();
886
+ jQuery('#cleantalk_anchor1').parent().css('padding-left','0px');
887
+ jQuery('#cleantalk_anchor1').parent().attr('colspan', '2');
888
+ });
889
+ </script>";
890
  }
891
 
892
 
894
  * Admin callback function - Plugin parameters validator
895
  */
896
  function ct_settings_validate($input) {
897
+ return $input;
898
  }
899
 
900
 
902
  * Admin callback function - Displays plugin options page
903
  */
904
  function ct_settings_page() {
905
+ ?>
906
  <style type="text/css">
907
+ .cleantalk_manual_link {padding: 10px; background: #3399FF; color: #fff; border:0 none;
908
+ cursor:pointer;
909
+ -webkit-border-radius: 5px;
910
+ border-radius: 5px;
911
+ font-size: 12pt;
912
+ }
913
+ .cleantalk_manual_link
914
+ {
915
+ background: #2ea2cc;
916
+ border-color: #0074a2;
917
+ -webkit-box-shadow: inset 0 1px 0 rgba(120,200,230,.5),0 1px 0 rgba(0,0,0,.15);
918
+ box-shadow: inset 0 1px 0 rgba(120,200,230,.5),0 1px 0 rgba(0,0,0,.15);
919
+ color: #fff;
920
+ text-decoration: none;
921
+ display: inline-block;
922
+ text-decoration: none;
923
+ font-size: 13px;
924
+ line-height: 26px;
925
+ height: 28px;
926
+ margin: 0;
927
+ padding: 0 10px 1px;
928
+ cursor: pointer;
929
+ border-width: 1px;
930
+ border-style: solid;
931
+ -webkit-appearance: none;
932
+ -webkit-border-radius: 3px;
933
+ border-radius: 3px;
934
+ white-space: nowrap;
935
+ -webkit-box-sizing: border-box;
936
+ -moz-box-sizing: border-box;
937
+ box-sizing: border-box;
938
  }
939
  .cleantalk_manual_link:hover
940
  {
941
  color:white;
942
  }
943
+
944
  </style>
945
 
946
+ <div>
947
+ <?php
948
+ if(is_network_admin())
949
+ {
950
+ print '<form method="post">';
951
+ if(defined('CLEANTALK_ACCESS_KEY'))
952
+ {
953
+ print "<br />Your CleanTalk access key is: <b>".CLEANTALK_ACCESS_KEY."</b><br />
954
+ You can change it in your wp-config.php file.<br />";
955
+ }
956
+ else
957
+ {
958
+ print "<br />To set up global CleanTalk access key for all websites, define constant in your wp-config.php file before defining database constants:<br />
959
+ <pre>define('CLEANTALK_ACCESS_KEY', 'place your key here');</pre>";
960
+ }
961
+ }
962
+ else
963
+ {
964
+ ?>
965
+ <form action="options.php" method="post">
966
+ <?php settings_fields('cleantalk_settings'); ?>
967
+ <?php do_settings_sections('cleantalk'); ?>
968
+ <br>
969
+ <input name="Submit" type="submit" class='cleantalk_manual_link' value="<?php esc_attr_e('Save Changes'); ?>" />
970
+ <?php
971
+ }
972
+ ?>
973
+
974
+ </form>
975
+ </div>
976
+ <?php
977
+
978
+ if (ct_valid_key() === false)
979
+ return null;
980
+ ?>
981
+ <br />
982
+ <br />
983
+ <br />
984
+ <div>
985
+ <?php echo __('Plugin Homepage at', 'cleantalk'); ?> <a href="http://cleantalk.org" target="_blank">cleantalk.org</a>.<br />
986
+ <?php echo __('Tech support CleanTalk:', 'cleantalk'); ?> <a href="https://cleantalk.org/forum/viewforum.php?f=25" target="_blank"><?php echo __('CleanTalk tech forum', 'cleantalk'); ?></a>.<br /><?php echo __('Use s@cleantalk.org to test plugin in any WordPress form.', 'cleantalk'); ?><br />
987
+ </div>
988
+ <?php
989
  }
990
 
991
  /**
993
  * @return bool
994
  */
995
  function cleantalk_admin_notice_message(){
996
+ global $show_ct_notice_trial, $show_ct_notice_renew, $show_ct_notice_online, $show_ct_notice_autokey, $ct_notice_autokey_value, $ct_plugin_name, $ct_options, $ct_data;
997
+
998
+ $ct_options = ct_get_options();
999
+ $ct_data = ct_get_data();
1000
+
1001
+ $user_token = '';
1002
+ if (isset($ct_data['user_token']) && $ct_data['user_token'] != '') {
1003
+ $user_token = '&user_token=' . $ct_data['user_token'];
1004
+ }
1005
+
1006
+ $show_notice = true;
1007
+
1008
+ if(current_user_can('activate_plugins'))
1009
+ {
1010
+ $value = 1;
1011
+ }
1012
+ else
1013
+ {
1014
+ $value = 0;
1015
+ }
1016
+
1017
+ if ($show_notice && $show_ct_notice_autokey && $value==1 && (is_network_admin() || (!defined('WP_ALLOW_MULTISITE')||defined('WP_ALLOW_MULTISITE')&&WP_ALLOW_MULTISITE==false) && is_admin())) {
1018
+ echo '<div class="error"><h3>' . sprintf(__("Unable to get Access key automatically: %s", 'cleantalk'), $ct_notice_autokey_value);
1019
+ echo " <a target='__blank' style='margin-left: 10px' href='https://cleantalk.org/register?platform=wordpress&email=".urlencode(get_option('admin_email'))."&website=".urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))."'>".__('Get the Access key', 'cleantalk').'</a></h3></div>';
1020
+ }
1021
+
1022
+ if ($show_notice && ct_valid_key($ct_options['apikey']) === false && $value==1 && (is_network_admin() || (!defined('WP_ALLOW_MULTISITE')||defined('WP_ALLOW_MULTISITE')&&WP_ALLOW_MULTISITE==false) && is_admin())) {
1023
+ echo '<div class="error"><h3>' . sprintf(__("Please enter Access Key in %s settings to enable anti spam protection!", 'cleantalk'), "<a href=\"options-general.php?page=cleantalk\">CleanTalk plugin</a>") . '</h3></div>';
1024
+ $show_notice = false;
1025
+ }
1026
+
1027
+ if ($show_notice && $show_ct_notice_trial && $value==1 && (is_network_admin() || (!defined('WP_ALLOW_MULTISITE')||defined('WP_ALLOW_MULTISITE')&&WP_ALLOW_MULTISITE==false) && is_admin())) {
1028
+ echo '<div class="error"><h3>' . sprintf(__("%s trial period ends, please upgrade to %s!", 'cleantalk'), "<a href=\"options-general.php?page=cleantalk\">$ct_plugin_name</a>", "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20trial$user_token\" target=\"_blank\"><b>premium version</b></a>") . '</h3></div>';
1029
+ $show_notice = false;
1030
+ }
1031
+
1032
+ if(isset($ct_data['next_notice_show']))
1033
+ {
1034
+ $next_notice_show=$ct_data['next_notice_show'];
1035
+ }
1036
+ else
1037
+ {
1038
+ $next_notice_show=0;
1039
+ }
1040
+
1041
+ $link=@$_SERVER["QUERY_STRING"];
1042
+ if($link!='')
1043
+ {
1044
+ $link="?".$link."&close_notice=1";
1045
+ }
1046
+ else
1047
+ {
1048
+ $link="?close_notice=1";
1049
+ }
1050
+
1051
+ if ($show_notice && $show_ct_notice_renew && $value==1 && time()>$next_notice_show && (is_network_admin() || (!defined('WP_ALLOW_MULTISITE')||defined('WP_ALLOW_MULTISITE')&&WP_ALLOW_MULTISITE==false) && is_admin())) {
1052
  $button_html = "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20renew$user_token\" target=\"_blank\">" . '<input type="button" class="button button-primary" value="' . __('RENEW ANTI-SPAM', 'cleantalk') . '" />' . "</a>";
1053
+ echo '<div class="updated"><a href="'.$link.'" style="text-decoration:none;float:right;font-size:16px;margin-top:5px;"><b>X</b></a><h3>' . sprintf(__("Please renew your anti-spam license for %s.", 'cleantalk'), "<a href=\"http://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20renew$user_token\" target=\"_blank\"><b>" . __('next year', 'cleantalk') ."</b></a>") . '<br /><br />' . $button_html . '</h3></div>';
1054
+ $show_notice = false;
1055
+ }
1056
+
1057
+ if ($show_notice && $show_ct_notice_online != '' && $value==1 && (is_network_admin() || (!defined('WP_ALLOW_MULTISITE')||defined('WP_ALLOW_MULTISITE')&&WP_ALLOW_MULTISITE==false) && is_admin())) {
1058
+ if($show_ct_notice_online === 'Y'){
1059
+ echo '<div class="updated"><h3><b>';
1060
+ //echo __("Don’t forget to disable CAPTCHA if you have it!", 'cleantalk');
1061
+ echo __("Settings updated!", 'cleantalk');
1062
+ echo '</b></h3></div>';
1063
+ }
1064
+
1065
+ if($show_ct_notice_online === 'N' && $value==1 && (is_network_admin() || (!defined('WP_ALLOW_MULTISITE')||defined('WP_ALLOW_MULTISITE')&&WP_ALLOW_MULTISITE==false) && is_admin())){
1066
+ echo '<div class="error"><h3><b>';
1067
+ echo __("Wrong <a href=\"options-general.php?page=cleantalk\"><b style=\"color: #49C73B;\">Clean</b><b style=\"color: #349ebf;\">Talk</b> access key</a>! Please check it or ask <a target=\"_blank\" href=\"https://cleantalk.org/forum/\">support</a>.", 'cleantalk');
1068
+ echo '</b></h3></div>';
1069
+ }
1070
+ }
1071
+
1072
+ //ct_send_feedback(); -- removed to ct_do_this_hourly()
1073
+
1074
+ return true;
1075
  }
1076
 
1077
  /**
1080
  * Add descriptions for field
1081
  */
1082
  function admin_addDescriptionsFields($descr = '') {
1083
+ echo "<div style='font-size: 10pt; color: #666 !important'>$descr</div>";
1084
  }
1085
 
1086
  /**
1087
  * Test API key
1088
  */
1089
  function ct_valid_key($apikey = null) {
1090
+ global $ct_options, $ct_data;
1091
+
1092
+ $ct_options = ct_get_options();
1093
+ $ct_data = ct_get_data();
1094
+
1095
+ if ($apikey === null) {
1096
+ $apikey = $ct_options['apikey'];
1097
+ }
1098
+
1099
+ return ($apikey === 'enter key' || $apikey === '') ? false : true;
1100
  }
1101
 
1102
  /**
1105
  * @return boolean TRUE
1106
  */
1107
  function ct_comment_approved($comment_object) {
1108
+ $comment = get_comment($comment_object->comment_ID, 'ARRAY_A');
1109
+ $hash = get_comment_meta($comment_object->comment_ID, 'ct_hash', true);
1110
 
1111
+ $comment['comment_content'] = ct_unmark_red($comment['comment_content']);
1112
+ $comment['comment_content'] = ct_feedback($hash, $comment['comment_content'], 1);
1113
+ $comment['comment_approved'] = 1;
1114
+ wp_update_comment($comment);
1115
 
1116
+ return true;
1117
  }
1118
 
1119
  /**
1122
  * @return boolean TRUE
1123
  */
1124
  function ct_comment_unapproved($comment_object) {
1125
+ $comment = get_comment($comment_object->comment_ID, 'ARRAY_A');
1126
+ $hash = get_comment_meta($comment_object->comment_ID, 'ct_hash', true);
1127
+ ct_feedback($hash, $comment['comment_content'], 0);
1128
+ $comment['comment_approved'] = 0;
1129
+ wp_update_comment($comment);
1130
 
1131
+ return true;
1132
  }
1133
 
1134
  /**
1137
  * @return boolean TRUE
1138
  */
1139
  function ct_comment_spam($comment_object) {
1140
+ $comment = get_comment($comment_object->comment_ID, 'ARRAY_A');
1141
+ $hash = get_comment_meta($comment_object->comment_ID, 'ct_hash', true);
1142
+ ct_feedback($hash, $comment['comment_content'], 0);
1143
+ $comment['comment_approved'] = 'spam';
1144
+ wp_update_comment($comment);
1145
 
1146
+ return true;
1147
  }
1148
 
1149
 
1152
  * @param type $comment_id
1153
  */
1154
  function ct_unspam_comment($comment_id) {
1155
+ update_comment_meta($comment_id, '_wp_trash_meta_status', 1);
1156
+ $comment = get_comment($comment_id, 'ARRAY_A');
1157
+ $hash = get_comment_meta($comment_id, 'ct_hash', true);
1158
+ $comment['comment_content'] = ct_unmark_red($comment['comment_content']);
1159
+ $comment['comment_content'] = ct_feedback($hash, $comment['comment_content'], 1);
1160
 
1161
+ wp_update_comment($comment);
1162
  }
1163
 
1164
  /**
1167
  * @return string New comment text
1168
  */
1169
  function ct_get_comment_text($current_text) {
1170
+ global $comment;
1171
+ $new_text = $current_text;
1172
+ if (isset($comment) && is_object($comment)) {
1173
+ $hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
1174
+ if (!empty($hash)) {
1175
+ $new_text .= '<hr>Cleantalk ID = ' . $hash;
1176
+ }
1177
+ }
1178
+ return $new_text;
1179
  }
1180
 
1181
  /**
1183
  * @return null
1184
  */
1185
  function ct_delete_user($user_id) {
1186
+ $hash = get_user_meta($user_id, 'ct_hash', true);
1187
+ if ($hash !== '') {
1188
+ ct_feedback($hash, null, 0);
1189
+ }
1190
  }
1191
 
1192
  /**
1194
  * @return array
1195
  */
1196
  if (!function_exists ( 'ct_register_plugin_links')) {
1197
+ function ct_register_plugin_links($links, $file) {
1198
+ global $ct_plugin_basename;
1199
+ if ($file == $ct_plugin_basename ) {
1200
+ if(!is_network_admin())
1201
+ {
1202
+ $links[] = '<a href="options-general.php?page=cleantalk">' . __( 'Settings' ) . '</a>';
1203
+ }
1204
+ else
1205
+ {
1206
+ $links[] = '<a href="settings.php?page=cleantalk">' . __( 'Settings' ) . '</a>';
1207
+ }
1208
+
1209
+ $links[] = '<a href="http://wordpress.org/plugins/cleantalk-spam-protect/faq/" target="_blank">' . __( 'FAQ','cleantalk' ) . '</a>';
1210
+ $links[] = '<a href="http://cleantalk.org/forum" target="_blank">' . __( 'Support','cleantalk' ) . '</a>';
1211
+ }
1212
+ return $links;
1213
+ }
1214
  }
1215
 
1216
  /**
1218
  * @return array
1219
  */
1220
  if (!function_exists ( 'ct_plugin_action_links')) {
1221
+ function ct_plugin_action_links($links, $file) {
1222
+ global $ct_plugin_basename;
1223
+
1224
+ if ($file == $ct_plugin_basename) {
1225
+ if(!is_network_admin())
1226
+ {
1227
+ $settings_link = '<a href="options-general.php?page=cleantalk">' . __( 'Settings' ) . '</a>';
1228
+ }
1229
+ else
1230
+ {
1231
+ $settings_link = '<a href="settings.php?page=cleantalk">' . __( 'Settings' ) . '</a>';
1232
+ }
1233
+ array_unshift( $links, $settings_link ); // before other links
1234
+ }
1235
+ return $links;
1236
+ }
1237
  }
1238
 
1239
  /**
1241
  * @return array
1242
  */
1243
  function ct_update_option($option_name) {
1244
+ global $show_ct_notice_online, $ct_notice_online_label, $ct_notice_trial_label, $trial_notice_showtime, $ct_options, $ct_data, $ct_server_timeout;
1245
+
1246
+ $ct_options = ct_get_options(true);
1247
+ $ct_data = ct_get_data(true);
1248
+
1249
+ if($option_name !== 'cleantalk_settings') {
1250
+ return;
1251
+ }
1252
+
1253
+ $api_key = $ct_options['apikey'];
1254
+ if (isset($_POST['cleantalk_settings']['apikey'])) {
1255
+ $api_key = trim($_POST['cleantalk_settings']['apikey']);
1256
+ $ct_options['apikey'] = $api_key;
1257
+ }
1258
+
1259
+ if(@isset($_POST['cleantalk_settings']['spam_firewall']) && $_POST['cleantalk_settings']['spam_firewall']==1 || isset($ct_options['spam_firewall']) && intval($ct_options['spam_firewall'])==1)
1260
+ {
1261
+ cleantalk_update_sfw();
1262
+ }
1263
+
1264
+ if (!ct_valid_key($api_key)) {
1265
+ return;
1266
+ }
1267
+
1268
+ /*$ct_base_call_result = ct_base_call(array(
1269
+ 'message' => 'CleanTalk setup test',
1270
+ 'example' => null,
1271
+ 'sender_email' => 'good@cleantalk.org',
1272
+ 'sender_nickname' => 'CleanTalk',
1273
+ 'post_info' => '',
1274
+ 'checkjs' => 1
1275
+ ));*/
1276
+
1277
+ $key_valid = true;
1278
+ $app_server_error = false;
1279
+ $ct_data['testing_failed']=0;
1280
+
1281
+
1282
+ if(!function_exists('sendRawRequest'))
1283
+ {
1284
+ require_once('cleantalk.class.php');
1285
+ }
1286
+
1287
+ $request=Array();
1288
  $request['method_name'] = 'notice_validate_key';
1289
  $request['auth_key'] = $api_key;
1290
  $url='https://api.cleantalk.org';
1291
  if(!function_exists('sendRawRequest'))
1292
+ {
1293
+ require_once('cleantalk.class.php');
1294
+ }
1295
+ $result=sendRawRequest($url, $request);
1296
+ if ($result)
1297
+ {
1298
+ $result = json_decode($result, true);
1299
+ if (isset($result['valid']) && $result['valid'] == 0) {
1300
+ $key_valid = false;
1301
+ $ct_data['testing_failed']=1;
1302
+ }
1303
+ }
1304
+ if (!$result || !isset($result['valid']))
1305
+ {
1306
+ $app_server_error = true;
1307
+ $ct_data['testing_failed']=1;
1308
+ }
1309
+
1310
+ update_option('cleantalk_data', $ct_data);
1311
+
1312
+ if ($key_valid) {
1313
+ // Removes cookie for server errors
1314
+ if ($app_server_error) {
1315
+ setcookie($ct_notice_online_label, '', 1, '/'); // time 1 is exactly in past even clients time() is wrong
1316
+ unset($_COOKIE[$ct_notice_online_label]);
1317
+ } else {
1318
+ setcookie($ct_notice_online_label, (string) time(), strtotime("+14 days"), '/');
1319
+ }
1320
+ setcookie($ct_notice_trial_label, '0', strtotime("+$trial_notice_showtime minutes"), '/');
1321
+ } else {
1322
+ setcookie($ct_notice_online_label, 'BAD_KEY', 0, '/');
1323
+ }
1324
  }
1325
 
1326
  /**
1329
  * @return string Cleat comment
1330
  */
1331
  function ct_unmark_red($message) {
1332
+ $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
1333
 
1334
+ return $message;
1335
  }
1336
 
1337
  ?>
inc/cleantalk-ajax.php CHANGED
@@ -370,7 +370,7 @@ function ct_ajax_hook()
370
  print json_encode($result);
371
  die();
372
  }
373
- else if($_POST['action']=='wysija_ajax')
374
  {
375
  $result=Array('result'=>false,'msgs'=>Array('updated'=>Array($ct_result->comment)));
376
  //@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
370
  print json_encode($result);
371
  die();
372
  }
373
+ else if($_POST['action']=='wysija_ajax'&&$_POST['task']!='send_preview')
374
  {
375
  $result=Array('result'=>false,'msgs'=>Array('updated'=>Array($ct_result->comment)));
376
  //@header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
inc/cleantalk-common.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- $ct_agent_version = 'wordpress-529';
4
  $ct_plugin_name = 'Anti-spam by CleanTalk';
5
  $ct_checkjs_frm = 'ct_checkjs_frm';
6
  $ct_checkjs_register_form = 'ct_checkjs_register_form';
@@ -379,6 +379,10 @@ function ct_get_options($force=false) {
379
  global $ct_options;
380
  if(!$force && isset($ct_options) && isset($ct_options['apikey']) && strlen($ct_options['apikey'])>3)
381
  {
 
 
 
 
382
  return $ct_options;
383
  }
384
  else
@@ -390,6 +394,10 @@ function ct_get_options($force=false) {
390
  if(array_key_exists('apikey', $options))
391
  $options['apikey'] = trim($options['apikey']);
392
  }
 
 
 
 
393
  return array_merge(ct_def_options(), (array) $options);
394
  }
395
  }
@@ -445,7 +453,7 @@ function ct_def_data() {
445
  'next_account_status_check' => 0, // Time label when the plugin should check account status
446
  'user_token' => '', // User token
447
  'js_keys' => array(), // Keys to do JavaScript antispam test
448
- 'js_keys_store_days' => 8, // JavaScript keys store days - 8 days now
449
  'js_key_lifetime' => 86400, // JavaScript key life time in seconds - 1 day now
450
  );
451
  }
@@ -626,7 +634,7 @@ function ct_get_fields_any(&$email,&$message,&$nickname,&$subject, &$contact,$ar
626
  {
627
  if(!is_array($value)&&!is_object($value)&&@get_class($value)!='WP_User')
628
  {
629
- if (in_array($key, $skip_params) || preg_match("/^ct_checkjs/", $key)) {
630
  $contact = false;
631
  }
632
  if ($email === '' && @preg_match("/^\S+@\S+\.\S+$/", $value))
1
  <?php
2
 
3
+ $ct_agent_version = 'wordpress-530';
4
  $ct_plugin_name = 'Anti-spam by CleanTalk';
5
  $ct_checkjs_frm = 'ct_checkjs_frm';
6
  $ct_checkjs_register_form = 'ct_checkjs_register_form';
379
  global $ct_options;
380
  if(!$force && isset($ct_options) && isset($ct_options['apikey']) && strlen($ct_options['apikey'])>3)
381
  {
382
+ if(defined('CLEANTALK_ACCESS_KEY'))
383
+ {
384
+ $options['apikey']=CLEANTALK_ACCESS_KEY;
385
+ }
386
  return $ct_options;
387
  }
388
  else
394
  if(array_key_exists('apikey', $options))
395
  $options['apikey'] = trim($options['apikey']);
396
  }
397
+ if(defined('CLEANTALK_ACCESS_KEY'))
398
+ {
399
+ $options['apikey']=CLEANTALK_ACCESS_KEY;
400
+ }
401
  return array_merge(ct_def_options(), (array) $options);
402
  }
403
  }
453
  'next_account_status_check' => 0, // Time label when the plugin should check account status
454
  'user_token' => '', // User token
455
  'js_keys' => array(), // Keys to do JavaScript antispam test
456
+ 'js_keys_store_days' => 14, // JavaScript keys store days - 8 days now
457
  'js_key_lifetime' => 86400, // JavaScript key life time in seconds - 1 day now
458
  );
459
  }
634
  {
635
  if(!is_array($value)&&!is_object($value)&&@get_class($value)!='WP_User')
636
  {
637
+ if (in_array($key, $skip_params) && $key!=0 && $key!='' || preg_match("/^ct_checkjs/", $key)) {
638
  $contact = false;
639
  }
640
  if ($email === '' && @preg_match("/^\S+@\S+\.\S+$/", $value))
inc/cleantalk-public.php CHANGED
@@ -79,26 +79,26 @@ function ct_init() {
79
 
80
  // JetPack Contact form
81
  $jetpack_active_modules = false;
82
- if(defined('JETPACK__VERSION')){
83
- add_filter('grunion_contact_form_field_html', 'ct_grunion_contact_form_field_html', 10, 2);
84
- if(JETPACK__VERSION=='3.4-beta')
85
- {
86
- add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
87
- }
88
- else if(JETPACK__VERSION=='3.4-beta2'||JETPACK__VERSION>='3.4')
89
- {
90
- add_filter('jetpack_contact_form_is_spam', 'ct_contact_form_is_spam_jetpack',1,2);
91
- }
92
- else
93
- {
94
- add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
95
- }
 
96
  $jetpack_active_modules = get_option('jetpack_active_modules');
97
- if (
98
- (class_exists( 'Jetpack', false) && $jetpack_active_modules && in_array('comments', $jetpack_active_modules))
99
- ) {
100
- $ct_jp_comments = true;
101
- }
102
  }
103
 
104
  // Contact Form7
79
 
80
  // JetPack Contact form
81
  $jetpack_active_modules = false;
82
+ if(defined('JETPACK__VERSION') && isset($_POST['comment_post_ID']))
83
+ {
84
+ add_filter('grunion_contact_form_field_html', 'ct_grunion_contact_form_field_html', 10, 2);
85
+ if(JETPACK__VERSION=='3.4-beta')
86
+ {
87
+ add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
88
+ }
89
+ else if(JETPACK__VERSION=='3.4-beta2'||JETPACK__VERSION>='3.4')
90
+ {
91
+ add_filter('jetpack_contact_form_is_spam', 'ct_contact_form_is_spam_jetpack',1,2);
92
+ }
93
+ else
94
+ {
95
+ add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
96
+ }
97
  $jetpack_active_modules = get_option('jetpack_active_modules');
98
+ if ((class_exists( 'Jetpack', false) && $jetpack_active_modules && in_array('comments', $jetpack_active_modules)))
99
+ {
100
+ $ct_jp_comments = true;
101
+ }
 
102
  }
103
 
104
  // Contact Form7
inc/cleantalk-sfw.class.php CHANGED
@@ -59,28 +59,20 @@ class CleanTalkSFW
59
  }
60
  else
61
  {
62
- $sfw_log[$this->ip_str] = Array('all' => 1, 'block' => 0);
63
  }
64
 
65
  if(sizeof($r)>0)
66
  {
67
- $sfw_log[$this->ip_str]['block']++;
68
  $this->result=true;
69
  }
70
  else
71
  {
 
72
  @setcookie ('ct_sfw_pass_key', md5($this->ip_str.$ct_options['apikey']), 0, "/");
73
  }
74
  $ct_data['sfw_log'] = $sfw_log;
75
  update_option('cleantalk_data', $ct_data);
76
- if($this->result)
77
- {
78
- @header("CtSFWCheck: block");
79
- }
80
- else
81
- {
82
- @header("CtSFWCheck: allow");
83
- }
84
  }
85
 
86
  public function sfw_die()
@@ -115,13 +107,17 @@ class CleanTalkSFW
115
  $data=Array();
116
  foreach($sfw_log as $key=>$value)
117
  {
118
- $data[]=Array($key, $value['all'], $value['block']);
119
  }
120
  $qdata = array (
121
  'data' => json_encode($data),
122
  'rows' => count($data),
123
  'timestamp' => time()
124
  );
 
 
 
 
125
 
126
  $result = sendRawRequest('https://api.cleantalk.org/?method_name=sfw_logs&auth_key='.$ct_options['apikey'],$qdata);
127
  $result = json_decode($result);
59
  }
60
  else
61
  {
62
+ $sfw_log[$this->ip_str] = Array('datetime'=>time(), 'all' => 1, 'allow' => 0);
63
  }
64
 
65
  if(sizeof($r)>0)
66
  {
 
67
  $this->result=true;
68
  }
69
  else
70
  {
71
+ $sfw_log[$this->ip_str]['allow']++;
72
  @setcookie ('ct_sfw_pass_key', md5($this->ip_str.$ct_options['apikey']), 0, "/");
73
  }
74
  $ct_data['sfw_log'] = $sfw_log;
75
  update_option('cleantalk_data', $ct_data);
 
 
 
 
 
 
 
 
76
  }
77
 
78
  public function sfw_die()
107
  $data=Array();
108
  foreach($sfw_log as $key=>$value)
109
  {
110
+ $data[]=Array($key, $value['all'], $value['allow'], $value['datetime']);
111
  }
112
  $qdata = array (
113
  'data' => json_encode($data),
114
  'rows' => count($data),
115
  'timestamp' => time()
116
  );
117
+ if(!function_exists('sendRawRequest'))
118
+ {
119
+ require_once('cleantalk.class.php');
120
+ }
121
 
122
  $result = sendRawRequest('https://api.cleantalk.org/?method_name=sfw_logs&auth_key='.$ct_options['apikey'],$qdata);
123
  $result = json_decode($result);
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: znaeff, shagimuratov, vlad-cleantalk
3
  Tags: anti-spam, antispam, bbpress, buddypress, captcha, capcha, captha, catcha, cf7 spam, comments, contact form spam, signup, spam, spammers, spammy, woocommerce, wordpress spam, booking, order, subscription, gravity spam, jetpack, bots, contact form 7, contact form, registrations, ninja, Fast Secure Contact, Gravity forms, formidable, mailchimp, s2member, protection, protect, email, akismet, plugin, contact, recaptcha, google captcha, math, security, login, blacklist, cache, prevent, wordpress, User Frontend, bulk delete, bulk remove, cloudflare, widget, review, auth forms, firewall, ddos, cleantalk, mailpoet
4
  Requires at least: 3.0
5
  Tested up to: 4.3
6
- Stable tag: 5.29
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -138,6 +138,13 @@ Audience engagement plugin <a href="http://wordpress.org/plugins/feedweb/">Feedw
138
 
139
  Done!
140
 
 
 
 
 
 
 
 
141
  = Manage and control spam protection =
142
  Go to <a href="https://cleantalk.org/my" target="_blank">Dashboard</a> at the cleantalk.org or use <a href="https://play.google.com/store/apps/details?id=org.cleantalk.app">Android</a>, <a href="https://itunes.apple.com/us/app/cleantalk/id825479913?mt=8">iPhone</a> anti-spam app to manage and control spam protection.
143
 
@@ -264,6 +271,23 @@ Use special IP 10.10.10.10 in URL to test Spam FireWall. For example,
264
 
265
  https://cleantalk.org/blog/?sfw_test_ip=10.10.10.10
266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  == Other notes ==
268
 
269
  = Troubleshooting Guide =
@@ -347,9 +371,16 @@ WordPress 3.0 at least. PHP 5 with CURL or file_get_contents() function and enab
347
  1. Anti-spam stopped spam bot at the CAPTCHA less registration form. The plugin provide explanation to visitor and websites about eache rejected comment/registration or contact message.
348
  1. Use anti-spam analytics tool for each website in service Dashboard to have information about spam/legitimate statistics.
349
  1. Use anti-spam log to control anti-spam plugin.
350
- 1. Setup Android/iOS app to have push notices when new legitiamte comments/registrations or contactcs appears on the website.
351
 
352
  == Changelog ==
 
 
 
 
 
 
 
353
  = 5.29 2015-10-27 =
354
  * Optimized performance
355
  * Fixed bugs in custom contact forms spam checking
@@ -836,6 +867,13 @@ WordPress 3.0 at least. PHP 5 with CURL or file_get_contents() function and enab
836
  * First version
837
 
838
  == Upgrade Notice ==
 
 
 
 
 
 
 
839
  = 5.29 2015-10-27 =
840
  * Optimized performance
841
  * Fixed bugs in custom contact forms spam checking
3
  Tags: anti-spam, antispam, bbpress, buddypress, captcha, capcha, captha, catcha, cf7 spam, comments, contact form spam, signup, spam, spammers, spammy, woocommerce, wordpress spam, booking, order, subscription, gravity spam, jetpack, bots, contact form 7, contact form, registrations, ninja, Fast Secure Contact, Gravity forms, formidable, mailchimp, s2member, protection, protect, email, akismet, plugin, contact, recaptcha, google captcha, math, security, login, blacklist, cache, prevent, wordpress, User Frontend, bulk delete, bulk remove, cloudflare, widget, review, auth forms, firewall, ddos, cleantalk, mailpoet
4
  Requires at least: 3.0
5
  Tested up to: 4.3
6
+ Stable tag: 5.30
7
  License: GPLv2
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
138
 
139
  Done!
140
 
141
+ = How can setup plugin in WPMU version? =
142
+ In WordPress multisite version you can switch the plugin to use Global Access key. In this way the plugin doesn't show any options to enter Access key in plugin settings and doesn't show Trial banner in WordPress backend. To setup global CleanTalk access key for all websites in WPMU, define constant in your wp-config.php file before defining database constants:
143
+
144
+ define('CLEANTALK_ACCESS_KEY', 'place your key here');
145
+
146
+ Now, all subsites will have this access key.
147
+
148
  = Manage and control spam protection =
149
  Go to <a href="https://cleantalk.org/my" target="_blank">Dashboard</a> at the cleantalk.org or use <a href="https://play.google.com/store/apps/details?id=org.cleantalk.app">Android</a>, <a href="https://itunes.apple.com/us/app/cleantalk/id825479913?mt=8">iPhone</a> anti-spam app to manage and control spam protection.
150
 
271
 
272
  https://cleantalk.org/blog/?sfw_test_ip=10.10.10.10
273
 
274
+ = How can I enter access key in WPMU version? =
275
+ To set up global CleanTalk access key for all websites in WPMU, define constant in your wp-config.php file before defining database constants:
276
+
277
+ define('CLEANTALK_ACCESS_KEY', 'place your key here');
278
+
279
+ Now, all subsites will have this access key.
280
+
281
+ = Why CleanTalk is faster and more reliable than stand-alone solutions? =
282
+ All anti-spam checks are held in the cloud and aren't loading the web server. The cloud solutions have a huge advantage since the parameters are compared with information from more 100,000 websites.
283
+
284
+ = I see in logs a lot of blocked messages with reason "Forbidden. Please enable JavaScript. Spam sender name." =
285
+ A lot of spam bots can't perform JavaScript code, so it is one of the important checks and most of the spam bots will be blocked with reason "Forbidden. Please enable JavaScript. Spam sender name." All browsers can perform JS code, so real visitors won't be blocked.
286
+
287
+ If you think that message was blocked wrong, let us know about it.
288
+
289
+ If you or someone from your visitors have error "Forbidden. Enable JavaScript." please check JavaScript support in your browser and do JavaScript test at this page <a href="https://cleantalk.org/checkout-javascript-support">Check out JavaScript support</a>.
290
+
291
  == Other notes ==
292
 
293
  = Troubleshooting Guide =
371
  1. Anti-spam stopped spam bot at the CAPTCHA less registration form. The plugin provide explanation to visitor and websites about eache rejected comment/registration or contact message.
372
  1. Use anti-spam analytics tool for each website in service Dashboard to have information about spam/legitimate statistics.
373
  1. Use anti-spam log to control anti-spam plugin.
374
+ 1. CleanTalk works faster than most of the other anti-spam plugins.
375
 
376
  == Changelog ==
377
+ = 5.30 2015-11-05 =
378
+ * Improved anti-spam checking
379
+ * Optimized performance
380
+ * Fixed blocking email preview in MailPoet
381
+ * Interface fixes
382
+ * WPMU interface fixes
383
+
384
  = 5.29 2015-10-27 =
385
  * Optimized performance
386
  * Fixed bugs in custom contact forms spam checking
867
  * First version
868
 
869
  == Upgrade Notice ==
870
+ = 5.30 2015-11-05 =
871
+ * Improved anti-spam checking
872
+ * Optimized performance
873
+ * Fixed blocking email preview in MailPoet
874
+ * Interface fixes
875
+ * WPMU interface fixes
876
+
877
  = 5.29 2015-10-27 =
878
  * Optimized performance
879
  * Fixed bugs in custom contact forms spam checking
screenshot-5.png CHANGED
Binary file