Spam protection, AntiSpam, FireWall by CleanTalk - Version 5.144

Version Description

Aug 13 2020 = * Fix: WPMS setting updating fixed. * Fix: Text domain added for some options name. * Fix: AntiCrowler die page fixed. * Fix: Pause button for comments check fixed. * Fix: Delete Anti-Flood table when subsite is deleted. * New: Clear Anti-Flood table each 10 minutes. * Fix: FW checking for whitelisted skipped. * Fix: WP 5.5 JS errors fixed. * New: Debug message for auto updating error. * Fix: Array declaration fixed. * Fix: Skip anti-flood checking for authorized users. * Fix: Is whitelisted checking fixed.

Download this release

Release Info

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

Code changes from version 5.143.1 to 5.144

cleantalk.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://cleantalk.org
5
  Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
- Version: 5.143.1
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk-spam-protect
@@ -583,7 +583,7 @@ function apbct_remote_call__perform()
583
  function apbct_sfw__check()
584
  {
585
  global $apbct, $spbc, $cleantalk_url_exclusions;
586
-
587
  // Turn off the SpamFireWall if current url in the exceptions list and WordPress core pages
588
  if (!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)) {
589
  $core_page_to_skip_check = array('/feed');
@@ -641,7 +641,7 @@ function apbct_sfw__check()
641
  ) );
642
  }
643
 
644
- if( $apbct->settings['sfw__anti_flood'] ){
645
  $firewall->load_fw_module( new \Cleantalk\ApbctWP\Firewall\AntiFlood(
646
  APBCT_TBL_FIREWALL_LOG,
647
  APBCT_TBL_AC_LOG,
@@ -721,6 +721,7 @@ function apbct_activation( $network = false ) {
721
  Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
722
  Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
723
  Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
 
724
  }
725
  switch_to_blog($initial_blog);
726
  }else{
@@ -733,6 +734,7 @@ function apbct_activation( $network = false ) {
733
  Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
734
  Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
735
  Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
 
736
 
737
  apbct_activation__create_tables($sqls);
738
  ct_account_status_check(null, false);
@@ -822,6 +824,7 @@ function apbct_activation__new_blog($blog_id, $user_id, $domain, $path, $site_id
822
  Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
823
  Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
824
  Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
 
825
  apbct_activation__create_tables($sqls);
826
  ct_sfw_update(); // Updating SFW
827
  ct_account_status_check(null, false);
@@ -1104,6 +1107,25 @@ function ct_sfw_send_logs($api_key = '')
1104
  return array('error' => 'SFW_DISABLED');
1105
  }
1106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1107
  /**
1108
  * Wrapper for Cleantalk's remote calls
1109
  *
@@ -1360,7 +1382,11 @@ function apbct_rc__update(){
1360
  $upgrader = new CleantalkUpgrader( new CleantalkUpgraderSkin_Deprecated( compact('title', 'nonce', 'url', 'plugin') ) );
1361
  }
1362
 
1363
- $upgrader->upgrade($plugin);
 
 
 
 
1364
 
1365
  apbct_maintance_mode__disable();
1366
 
@@ -1411,7 +1437,7 @@ function apbct_rc__update(){
1411
 
1412
  }else{
1413
  die('FAIL '. json_encode(array('error' => $upgrader->apbct_result)));
1414
- }
1415
  }
1416
 
1417
  function apbct_rc__update_settings($source) {
@@ -1971,6 +1997,7 @@ function apbct_sfw__delete_tables( $blog_id, $drop ) {
1971
  switch_to_blog($blog_id);
1972
  $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw`;'); // Deleting SFW data
1973
  $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw_logs`;'); // Deleting SFW logs
 
1974
 
1975
  switch_to_blog($initial_blog);
1976
  }
3
  Plugin Name: Anti-Spam by CleanTalk
4
  Plugin URI: https://cleantalk.org
5
  Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms.
6
+ Version: 5.144
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk-spam-protect
583
  function apbct_sfw__check()
584
  {
585
  global $apbct, $spbc, $cleantalk_url_exclusions;
586
+
587
  // Turn off the SpamFireWall if current url in the exceptions list and WordPress core pages
588
  if (!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)) {
589
  $core_page_to_skip_check = array('/feed');
641
  ) );
642
  }
643
 
644
+ if( $apbct->settings['sfw__anti_flood'] && is_null( apbct_wp_get_current_user() ) ){
645
  $firewall->load_fw_module( new \Cleantalk\ApbctWP\Firewall\AntiFlood(
646
  APBCT_TBL_FIREWALL_LOG,
647
  APBCT_TBL_AC_LOG,
721
  Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
722
  Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
723
  Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
724
+ Cron::addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 600, time() + 300); // Clear Anti-Flood table
725
  }
726
  switch_to_blog($initial_blog);
727
  }else{
734
  Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
735
  Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
736
  Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
737
+ Cron::addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 600, time() + 300); // Clear Anti-Flood table
738
 
739
  apbct_activation__create_tables($sqls);
740
  ct_account_status_check(null, false);
824
  Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
825
  Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
826
  Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
827
+ Cron::addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 600, time() + 300); // Clear Anti-Flood table
828
  apbct_activation__create_tables($sqls);
829
  ct_sfw_update(); // Updating SFW
830
  ct_account_status_check(null, false);
1107
  return array('error' => 'SFW_DISABLED');
1108
  }
1109
 
1110
+ function apbct_antiflood__clear_table(){
1111
+
1112
+ global $apbct;
1113
+
1114
+ if( $apbct->settings['sfw__anti_flood'] ){
1115
+
1116
+ $anti_flood = new \Cleantalk\ApbctWP\Firewall\AntiFlood(
1117
+ APBCT_TBL_FIREWALL_LOG,
1118
+ APBCT_TBL_AC_LOG,
1119
+ array(
1120
+ 'chance_to_clean' => 100,
1121
+ )
1122
+ );
1123
+ $anti_flood->setDb( \Cleantalk\ApbctWP\DB::getInstance() );
1124
+ $anti_flood->clear_table();
1125
+ unset( $anti_flood );
1126
+ }
1127
+ }
1128
+
1129
  /**
1130
  * Wrapper for Cleantalk's remote calls
1131
  *
1382
  $upgrader = new CleantalkUpgrader( new CleantalkUpgraderSkin_Deprecated( compact('title', 'nonce', 'url', 'plugin') ) );
1383
  }
1384
 
1385
+ $upgrader_result = $upgrader->upgrade( $plugin );
1386
+ if( is_wp_error( $upgrader_result ) ){
1387
+ error_log('CleanTalk debug message:');
1388
+ error_log( var_export( $upgrader_result->get_error_message(), 1) );
1389
+ }
1390
 
1391
  apbct_maintance_mode__disable();
1392
 
1437
 
1438
  }else{
1439
  die('FAIL '. json_encode(array('error' => $upgrader->apbct_result)));
1440
+ }
1441
  }
1442
 
1443
  function apbct_rc__update_settings($source) {
1997
  switch_to_blog($blog_id);
1998
  $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw`;'); // Deleting SFW data
1999
  $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw_logs`;'); // Deleting SFW logs
2000
+ $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_ac_log`;'); // Deleting SFW logs
2001
 
2002
  switch_to_blog($initial_blog);
2003
  }
inc/cleantalk-admin.php CHANGED
@@ -1,713 +1,713 @@
1
- <?php
2
-
3
- require_once('cleantalk-settings.php');
4
-
5
- // Add buttons to comments list table
6
- add_action( 'manage_comments_nav', 'apbct_add_buttons_to_comments_and_users', 10, 1 );
7
- add_action( 'manage_users_extra_tablenav', 'apbct_add_buttons_to_comments_and_users', 10, 1 );
8
-
9
- // Check renew banner
10
- add_action( 'wp_ajax_apbct_settings__check_renew_banner', 'apbct_settings__check_renew_banner');
11
-
12
- // Crunch for Anti-Bot
13
- add_action( 'admin_head','apbct_admin_set_cookie_for_anti_bot' );
14
-
15
- function apbct_admin_set_cookie_for_anti_bot(){
16
- global $apbct;
17
- echo '<script>document.cookie = "apbct_antibot=' . md5( $apbct->api_key . \Cleantalk\ApbctWP\Helper::ip__get(array('real'), true ) ) . '; path=/; expires=0; samesite=lax";</script>';
18
- }
19
-
20
- function apbct_add_buttons_to_comments_and_users( $unused_argument ) {
21
-
22
- global $apbct;
23
- $current_screen = get_current_screen();
24
-
25
- if( 'users' == $current_screen->base ) {
26
- $button_url__check = $current_screen->base . '.php?page=ct_check_users';
27
- $button_url__results = $current_screen->base . '.php?page=ct_check_users_total';
28
- $button_description = 'users';
29
- } elseif ( 'edit-comments' == $current_screen->base ) {
30
- $button_url__check = $current_screen->base . '.php?page=ct_check_spam';
31
- $button_url__results = $current_screen->base . '.php?page=ct_check_spam_total';
32
- $button_description = 'comments';
33
- } else {
34
- return;
35
- }
36
-
37
- echo '
38
- <a href="' . $button_url__check . '" class="button" style="margin:1px 0 0 0; display: inline-block;">
39
- <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
40
- ' . sprintf(__( 'Find spam %s', 'cleantalk-spam-protect'), $button_description ) . '
41
- </a>
42
- <a href="' . $button_url__results . '" class="button" style="margin:1px 0 0 0; display: inline-block;">
43
- <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
44
- ' . sprintf(__( 'View spam %s', 'cleantalk-spam-protect'), $button_description ) . '
45
- </a>
46
- <a href="https://cleantalk.org/my/show_requests?service_id=' . $apbct->data['service_id'] . '&int=week" target="_blank" class="button" style="margin:1px 0 0 0; display: inline-block;">
47
- <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
48
- ' . __( 'CleanTalk Anti-Spam Log', 'cleantalk-spam-protect') . '
49
- </a>
50
- ';
51
-
52
- }
53
-
54
- add_action( 'admin_bar_menu', 'apbct_admin__admin_bar__add', 999 );
55
-
56
- //Adding widjet
57
- function ct_dashboard_statistics_widget() {
58
-
59
- global $apbct;
60
-
61
- if(apbct_is_user_role_in(array('administrator'))){
62
- wp_add_dashboard_widget(
63
- 'ct_dashboard_statistics_widget',
64
- $apbct->plugin_name
65
- ."<div class='ct_widget_top_links'>"
66
- ."<img src='".plugins_url('/cleantalk-spam-protect/inc/images/preloader.gif')."' class='ct_preloader'>"
67
- .sprintf(__("%sRefresh%s", 'cleantalk-spam-protect'), "<a href='#ct_widget' class='ct_widget_refresh_link'>", "</a>")
68
- .sprintf(__("%sConfigure%s", 'cleantalk-spam-protect'), "<a href='{$apbct->settings_link}' class='ct_widget_settings_link'>", "</a>")
69
- ."</div>",
70
- 'ct_dashboard_statistics_widget_output'
71
- );
72
- }
73
- }
74
-
75
- // Outputs statistics widget content
76
- function ct_dashboard_statistics_widget_output( $post, $callback_args ) {
77
-
78
- global $apbct, $current_user;
79
-
80
- echo "<div id='ct_widget_wrapper'>";
81
- ?>
82
- <form id='ct_refresh_form' method='POST' action='#ct_widget'>
83
- <input type='hidden' name='ct_brief_refresh' value='1'>
84
- </form>
85
- <h4 class='ct_widget_block_header' style='margin-left: 12px;'><?php _e('7 days anti-spam stats', 'cleantalk-spam-protect'); ?></h4>
86
- <div class='ct_widget_block ct_widget_chart_wrapper'>
87
- <div id='ct_widget_chart'></div>
88
- </div>
89
- <h4 class='ct_widget_block_header'><?php _e('Top 5 spam IPs blocked', 'cleantalk-spam-protect'); ?></h4>
90
- <hr class='ct_widget_hr'>
91
- <?php
92
- if(!apbct_api_key__is_correct() || (isset($apbct->data['brief_data']['error_no']) && $apbct->data['brief_data']['error_no'] == 6)){
93
- ?> <div class='ct_widget_block'>
94
- <form action='<? echo $apbct->settings_link; ?>' method='POST'>
95
- <h2 class='ct_widget_activate_header'><?php _e('Get Access key to activate Anti-Spam protection!', 'cleantalk-spam-protect'); ?></h2>
96
- <input class='ct_widget_button ct_widget_activate_button' type='submit' name='get_apikey_auto' value='ACTIVATE' />
97
- </form>
98
- </div>
99
- <?php
100
- }elseif(!empty($apbct->data['brief_data']['error'])){
101
- echo '<div class="ct_widget_block">'
102
- .'<h2 class="ct_widget_activate_header">'
103
- .sprintf(__('Something went wrong! Error: "%s".', 'cleantalk-spam-protect'), "<u>{$apbct->brief_data['error']}</u>")
104
- .'</h2>';
105
- if($apbct->user_token && !$apbct->white_label){
106
- echo '<h2 class="ct_widget_activate_header">'
107
- .__('Please, visit your dashboard.', 'cleantalk-spam-protect')
108
- .'</h2>'
109
- .'<a target="_blank" href="https://cleantalk.org/my?user_token='.$apbct->user_token.'&cp_mode=antispam">'
110
- .'<input class="ct_widget_button ct_widget_activate_button ct_widget_resolve_button" type="button" value="VISIT CONTROL PANEL">'
111
- .'</a>';
112
- }
113
- echo '</div>';
114
- }
115
-
116
- if(apbct_api_key__is_correct() && empty($apbct->data['brief_data']['error'])){
117
- ?>
118
- <div class='ct_widget_block'>
119
- <table cellspacing="0">
120
- <tr>
121
- <th><?php _e('IP', 'cleantalk-spam-protect'); ?></th>
122
- <th><?php _e('Country', 'cleantalk-spam-protect'); ?></th>
123
- <th><?php _e('Block Count', 'cleantalk-spam-protect'); ?></th>
124
- </tr>
125
- <?php foreach($apbct->brief_data['top5_spam_ip'] as $val){ ?>
126
- <tr>
127
- <td><?php echo $val[0]; ?></td>
128
- <td><?php echo $val[1] ? "<img src='https://cleantalk.org/images/flags/".strtolower($val[1]).".png'>" : ''; ?>&nbsp;<?php
129
- echo $val[1]
130
- ? locale_get_display_region('sl-Latn-'.$val[1].'-nedis', substr(get_locale(), 0, 2))
131
- : 'Unknown'; ?></td>
132
- <td style='text-align: center;'><?php echo $val[2]; ?></td>
133
- </tr>
134
- <?php } ?>
135
- </table>
136
- <?php if($apbct->user_token){ ?>
137
- <a target='_blank' href='https://cleantalk.org/my?user_token=<?php echo $apbct->user_token; ?>&cp_mode=antispam'>
138
- <input class='ct_widget_button' id='ct_widget_button_view_all' type='button' value='View all'>
139
- </a>
140
- <?php } ?>
141
- </div>
142
-
143
- <?php
144
- }
145
- // Notice at the bottom
146
- if(isset($current_user) && in_array('administrator', $current_user->roles)){
147
-
148
- if($apbct->spam_count && $apbct->spam_count > 0){
149
- echo '<div class="ct_widget_wprapper_total_blocked">'
150
- .'<img src="'.$apbct->logo__small__colored.'" class="ct_widget_small_logo"/>'
151
- .'<span title="'.sprintf(__('This is the count from the %s\'s cloud and could be different to admin bar counters', 'cleantalk-spam-protect').'">', $apbct->plugin_name)
152
- .sprintf(
153
- /* translators: %s: Number of spam messages */
154
- __( '%s%s%s has blocked %s spam for all time. The statistics are automatically updated every 24 hours.', 'cleantalk-spam-protect'),
155
- !$apbct->white_label ? '<a href="https://cleantalk.org/my/?user_token='.$apbct->user_token.'&utm_source=wp-backend&utm_medium=dashboard_widget&cp_mode=antispam" target="_blank">' : '',
156
- $apbct->plugin_name,
157
- !$apbct->white_label ? '</a>' : '',
158
- number_format($apbct->data['spam_count'], 0, ',', ' ')
159
- )
160
- .'</span>'
161
- .(!$apbct->white_label
162
- ? '<br><br>'
163
- .'<b style="font-size: 16px;">'
164
- .sprintf(
165
- __('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'),
166
- '<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">',
167
- '</a></u>'
168
- )
169
- .'</b>'
170
- : ''
171
- )
172
- .'</div>';
173
- }
174
- }
175
- echo '</div>';
176
- }
177
-
178
- /**
179
- * Admin action 'admin_init' - Add the admin settings and such
180
- */
181
- function apbct_admin__init(){
182
-
183
- global $apbct;
184
-
185
- // Getting dashboard widget statistics
186
- if(!empty($_POST['ct_brief_refresh'])){
187
- $apbct->data['brief_data'] = \Cleantalk\ApbctWP\API::method__get_antispam_report_breif($apbct->api_key);
188
- $apbct->saveData();
189
- }
190
-
191
- // Getting key like hoster. Only once!
192
- if(!is_main_site() && $apbct->white_label && ( empty($apbct->api_key) || $apbct->settings['apikey'] == $apbct->network_settings['apikey'] ) ){
193
-
194
- $_POST['submit'] = 'get_key_auto';
195
- $apbct->save('settings');
196
- $settings = get_option('cleantalk_settings');
197
- $apbct->api_key = $settings['apikey'];
198
- unset($_POST['submit']);
199
-
200
- }
201
- }
202
-
203
- function apbct_admin__init___ajax_actions(){
204
-
205
- // Settings
206
- add_action('wp_ajax_apbct_settings__get__long_description', 'apbct_settings__get__long_description'); // Long description
207
-
208
- add_action( 'wp_ajax_apbct_sync', 'apbct_settings__sync' );
209
- }
210
-
211
- /**
212
- * Manage links in plugins list
213
- * @return array
214
- */
215
- function apbct_admin__plugin_action_links($links, $file) {
216
-
217
- global $apbct;
218
-
219
- $settings_link = '<a href="' . $apbct->settings_link . '">' . __( 'Settings' ) . '</a>';
220
-
221
- array_unshift( $links, $settings_link ); // before other links
222
- return $links;
223
- }
224
-
225
- /**
226
- * Manage links and plugins page
227
- * @return array
228
- */
229
- function apbct_admin__register_plugin_links($links, $file){
230
-
231
- global $apbct;
232
-
233
- //Return if it's not our plugin
234
- if ($file != $apbct->base_name)
235
- return $links;
236
-
237
- if($apbct->white_label){
238
- $links = array_slice($links, 0, 1);
239
- $links[] = "<script>jQuery('.plugin-title strong').each(function(i, item){
240
- if(jQuery(item).html() == 'Anti-Spam by CleanTalk')
241
- jQuery(item).html('{$apbct->plugin_name}');
242
- });</script>";
243
- return $links;
244
- }
245
-
246
- if(substr(get_locale(), 0, 2) != 'en')
247
- $links[] = '<a class="ct_meta_links ct_translate_links" href="'
248
- .sprintf('https://translate.wordpress.org/locale/%s/default/wp-plugins/cleantalk-spam-protect', substr(get_locale(), 0, 2))
249
- .'" target="_blank">'
250
- .__('Translate', 'cleantalk-spam-protect')
251
- .'</a>';
252
-
253
- $links[] = '<a class="ct_meta_links" href="'.$apbct->settings_link.'" target="_blank">' . __( 'Start here','cleantalk-spam-protect') . '</a>';
254
- $links[] = '<a class="ct_meta_links ct_faq_links" href="https://wordpress.org/plugins/cleantalk-spam-protect/faq/" target="_blank">' . __( 'FAQ','cleantalk-spam-protect') . '</a>';
255
- $links[] = '<a class="ct_meta_links ct_support_links"href="https://wordpress.org/support/plugin/cleantalk-spam-protect" target="_blank">' . __( 'Support','cleantalk-spam-protect') . '</a>';
256
- $trial = apbct_admin__badge__get_premium(false);
257
- if(!empty($trial))
258
- $links[] = apbct_admin__badge__get_premium(false);
259
-
260
- return $links;
261
- }
262
-
263
- /**
264
- * Admin action 'admin_enqueue_scripts' - Enqueue admin script of reloading admin page after needed AJAX events
265
- * @param string $hook URL of hooked page
266
- */
267
- function apbct_admin__enqueue_scripts($hook){
268
-
269
- global $apbct;
270
-
271
- // Scripts to all admin pages
272
- wp_enqueue_script('ct_admin_js_notices', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin.min.js'), array(), APBCT_VERSION);
273
- wp_enqueue_style ('ct_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin.min.css'), array(), APBCT_VERSION, 'all');
274
-
275
- wp_localize_script( 'jquery', 'ctAdminCommon', array(
276
- '_ajax_nonce' => wp_create_nonce( 'ct_secret_nonce' ),
277
- '_ajax_url' => admin_url( 'admin-ajax.php' ),
278
- 'plugin_name' => $apbct->plugin_name,
279
- 'logo' => '<img src="' . $apbct->logo . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
280
- 'logo_small' => '<img src="' . $apbct->logo__small . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
281
- 'logo_small_colored' => '<img src="' . $apbct->logo__small__colored . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
282
- ) );
283
-
284
- // DASHBOARD page JavaScript and CSS
285
- if($hook == 'index.php' && apbct_is_user_role_in(array('administrator'))){
286
-
287
- wp_enqueue_style('ct_admin_css_widget_dashboard', plugins_url('/cleantalk-spam-protect/css/cleantalk-dashboard-widget.min.css'), array(), APBCT_VERSION, 'all');
288
- wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
289
-
290
- wp_enqueue_script('ct_gstatic_charts_loader', plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget--google-charts.min.js'), array(), APBCT_VERSION);
291
- wp_enqueue_script('ct_admin_js_widget_dashboard', plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget.min.js'), array('ct_gstatic_charts_loader'), APBCT_VERSION);
292
-
293
- // Preparing widget data
294
- // Parsing brief data 'spam_stat' {"yyyy-mm-dd": spam_count, "yyyy-mm-dd": spam_count} to [["yyyy-mm-dd", "spam_count"], ["yyyy-mm-dd", "spam_count"]]
295
- $to_chart = array();
296
-
297
- // Crunch. Response contains error.
298
- if(!empty($apbct->data['brief_data']['error']))
299
- $apbct->data['brief_data'] = array_merge($apbct->data['brief_data'], $apbct->def_data['brief_data']);
300
-
301
- foreach( $apbct->data['brief_data']['spam_stat'] as $key => $value ){
302
- $to_chart[] = array( $key, $value );
303
- } unset( $key, $value );
304
-
305
- wp_localize_script( 'jquery', 'apbctDashboardWidget', array(
306
- 'data' => $to_chart,
307
- ));
308
- }
309
-
310
- // SETTINGS's page JavaScript and CSS
311
- if( $hook == 'settings_page_cleantalk' ){
312
-
313
- // jQueryUI
314
- wp_enqueue_script('jqueryui', plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'), array('jquery'), '1.12.1' );
315
- wp_enqueue_style('jqueryui_css', plugins_url('/cleantalk-spam-protect/css/jquery-ui.min.css'),array(), '1.21.1', 'all');
316
-
317
- wp_enqueue_script('cleantalk_admin_js_settings_page', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin-settings-page.min.js'), array(), APBCT_VERSION);
318
- wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin-settings-page.min.css'), array(), APBCT_VERSION, 'all');
319
- wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
320
-
321
- wp_localize_script( 'jquery', 'ctSettingsPage', array(
322
- 'ct_subtitle' => $apbct->ip_license ? __('Hosting AntiSpam', 'cleantalk-spam-protect') : '',
323
- 'ip_license' => $apbct->ip_license ? true : false,
324
- 'key_changed' => ! empty( $apbct->data['key_changed'] ) ? true : false,
325
- ));
326
- }
327
-
328
- // COMMENTS page JavaScript
329
- if($hook == 'edit-comments.php'){
330
- wp_enqueue_script('ct_comments_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-editscreen.min.js'), array(), APBCT_VERSION);
331
- wp_localize_script( 'jquery', 'ctCommentsScreen', array(
332
- 'ct_ajax_nonce' => wp_create_nonce('ct_secret_nonce'),
333
- 'spambutton_text' => __("Find spam comments", 'cleantalk-spam-protect'),
334
- 'ct_feedback_msg_whitelisted' => __("The sender has been whitelisted.", 'cleantalk-spam-protect'),
335
- 'ct_feedback_msg_blacklisted' => __("The sender has been blacklisted.", 'cleantalk-spam-protect'),
336
- 'ct_feedback_msg' => sprintf(__("Feedback has been sent to %sCleanTalk Dashboard%s.", 'cleantalk-spam-protect'), $apbct->user_token ? "<a target='_blank' href=https://cleantalk.org/my?user_token={$apbct->user_token}&cp_mode=antispam>" : '', $apbct->user_token ? "</a>" : ''),
337
- 'ct_show_check_links' => (bool)$apbct->settings['show_check_links'],
338
- 'ct_img_src_new_tab' => plugin_dir_url(__FILE__)."images/new_window.gif",
339
- ));
340
- }
341
-
342
- // USERS page JavaScript
343
- if($hook == 'users.php'){
344
- wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
345
- wp_enqueue_script('ct_users_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-users-editscreen.min.js'), array(), APBCT_VERSION);
346
- wp_localize_script( 'jquery', 'ctUsersScreen', array(
347
- 'spambutton_text' => __("Find spam-users", 'cleantalk-spam-protect'),
348
- 'ct_show_check_links' => (bool)$apbct->settings['show_check_links'],
349
- 'ct_img_src_new_tab' => plugin_dir_url(__FILE__)."images/new_window.gif"
350
- ));
351
- }
352
-
353
- }
354
-
355
- /**
356
- * Notice blog owner if plugin is used without Access key
357
- * @return bool
358
- */
359
- function apbct_admin__notice_message(){
360
-
361
- global $apbct;
362
-
363
- $page = get_current_screen();
364
-
365
- //General notice control flags
366
- $self_owned_key = ($apbct->moderate_ip == 0 && !defined('CLEANTALK_ACCESS_KEY') ? true : false);
367
- $is_dashboard = (is_network_admin() || is_admin() ? true : false);
368
- $is_admin = (current_user_can('activate_plugins') ? true : false);
369
-
370
- $page_is_ct_settings = (in_array($page->id, array('settings_page_cleantalk', 'settings_page_cleantalk-network', 'comments_page_ct_check_spam', 'users_page_ct_check_users')) ? true : false);
371
-
372
- //Misc
373
- $user_token = ($apbct->user_token ? '&user_token='.$apbct->user_token : '');
374
-
375
- if( is_network_admin() ) {
376
- $site_url = get_site_option('siteurl');
377
- $site_url = preg_match( '/\/$/', $site_url ) ? $site_url : $site_url . '/';
378
- $settings_link = $site_url . 'wp-admin/options-general.php?page=cleantalk';
379
- } else {
380
- $settings_link = 'options-general.php?page=cleantalk';
381
- }
382
-
383
- if($self_owned_key && $is_dashboard && $is_admin){
384
- // Auto update notice
385
- /* Disabled at 09.09.2018
386
- if($apbct->notice_auto_update == 1 && $apbct->auto_update != -1 && empty($_COOKIE['apbct_update_banner_closed'])){
387
- $link = '<a href="https://cleantalk.org/help/cleantalk-auto-update" target="_blank">%s</a>';
388
- $button = sprintf($link, '<input type="button" class="button button-primary" value="'.__('Learn more', 'cleantalk-spam-protect').'" />');
389
- echo '<div class="error notice is-dismissible apbct_update_notice">'
390
- .'<h3>'
391
- .__('Do you know that Anti-Spam by CleanTalk has auto update option?', 'cleantalk-spam-protect')
392
- .'</br></br>'
393
- .$button
394
- .'</h3>'
395
- .'</div>';
396
- }
397
- */
398
- //Unable to get key automatically (if apbct_admin__init().getAutoKey() returns error)
399
- if ($apbct->notice_show && !empty($apbct->errors['get_key']) && !$apbct->white_label){
400
- echo '<div class="error">
401
- <h3>' . sprintf(__("Unable to get Access key automatically: %s", 'cleantalk-spam-protect'), $apbct->api_key).
402
- "<a target='__blank' style='margin-left: 10px' href='https://cleantalk.org/register?platform=wordpress&email=" . urlencode(ct_get_admin_email())."&website=" . urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))."'>".__('Get the Access key', 'cleantalk-spam-protect').'</a>
403
- </h3>
404
- </div>';
405
- }
406
-
407
- //key == "" || "enter key"
408
- if (!apbct_api_key__is_correct() && $apbct->moderate_ip == 0){
409
- echo "<div class='error'>"
410
- ."<h3>"
411
- .sprintf(__("Please enter Access Key in %s settings to enable anti spam protection!", 'cleantalk-spam-protect'), "<a href='{$settings_link}'>$apbct->plugin_name</a>")
412
- ."</h3>"
413
- ."</div>";
414
- $apbct->notice_show = false;
415
- }
416
-
417
- //"Trial period ends" notice from apbct_admin__init().api_method__notice_paid_till()
418
- if ($apbct->notice_show && $apbct->notice_trial == 1 && $apbct->moderate_ip == 0 && !$apbct->white_label) {
419
- if(isset($_GET['page']) && in_array($_GET['page'], array('cleantalk', 'ct_check_spam', 'ct_check_users'))){
420
- echo '<div class="error" id="apbct_trial_notice">
421
- <h3>' . sprintf(__("%s trial period ends, please upgrade to %s!", 'cleantalk-spam-protect'),
422
- "<a href='{$settings_link}'>".$apbct->plugin_name."</a>",
423
- "<a href=\"https://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20trial$user_token&cp_mode=antispam\" target=\"_blank\"><b>premium version</b></a>") .
424
- '</h3>
425
- <h4 style = "color: gray">Account status updates every 15 minutes.</h4>
426
- </div>';
427
- $apbct->notice_show = false;
428
- }
429
- }
430
-
431
- //Renew notice from apbct_admin_init().api_method__notice_paid_till()
432
- if ($apbct->notice_show && $apbct->notice_renew == 1 && $apbct->moderate_ip == 0 && !$apbct->white_label) {
433
- $renew_link = "<a href=\"https://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%%20backend%%20renew$user_token&cp_mode=antispam\" target=\"_blank\">%s</a>";
434
- $button_html = sprintf($renew_link, '<input type="button" class="button button-primary" value="'.__('RENEW ANTI-SPAM', 'cleantalk-spam-protect').'" />');
435
- $link_html = sprintf($renew_link, "<b>".__('next year', 'cleantalk-spam-protect')."</b>");
436
-
437
- echo '<div class="updated" id="apbct_renew_notice">
438
- <h3>'.
439
- sprintf(__("Please renew your anti-spam license for %s.", 'cleantalk-spam-protect'), $link_html).
440
- '</h3>
441
- <h4 style = "color: gray">Account status updates every 15 minutes.</h4>
442
- '.$button_html.'
443
- <br/><br/>
444
- </div>';
445
- $apbct->notice_show = false;
446
- }
447
-
448
- //"Wrong access key" notice (if ct_update_option().METHOD_notice_validate_key returns a error)
449
- if ($apbct->notice_show && $page_is_ct_settings && !$apbct->data['key_is_ok'] && $apbct->moderate_ip == 0 && !$apbct->white_label){
450
- echo '<div class="error">
451
- <h3><b>'.
452
- __("Wrong <a href='{$settings_link}'><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://wordpress.org/support/plugin/cleantalk-spam-protect/\">support</a>.", 'cleantalk-spam-protect').
453
- '</b></h3>
454
- </div>';
455
- }
456
- }
457
-
458
- return true;
459
- }
460
-
461
- function apbct_admin__badge__get_premium($print = true, $out = ''){
462
-
463
- global $apbct;
464
-
465
- if($apbct->license_trial == 1 && $apbct->user_token){
466
- $out .= '<b style="display: inline-block; margin-top: 10px;">'
467
- .($print ? __('Make it right!', 'cleantalk-spam-protect').' ' : '')
468
- .sprintf(
469
- __('%sGet premium%s', 'cleantalk-spam-protect'),
470
- '<a href="https://cleantalk.org/my/bill/recharge?user_token='.$apbct->user_token.'" target="_blank">',
471
- '</a>'
472
- )
473
- .'</b>';
474
- }
475
-
476
- if($print)
477
- echo $out;
478
- else
479
- return $out;
480
- }
481
-
482
- function apbct_admin__admin_bar__add( $wp_admin_bar ) {
483
-
484
- global $apbct;
485
-
486
- if (current_user_can('activate_plugins') && $apbct->settings['show_adminbar'] == 1 && (apbct_api_key__is_correct($apbct->api_key) !== false || (defined('CLEANTALK_SHOW_ADMIN_BAR_FORCE') && CLEANTALK_SHOW_ADMIN_BAR_FORCE))) {
487
-
488
- //Reset or create user counter
489
- if(!empty($_GET['ct_reset_user_counter'])){
490
- $apbct->data['user_counter']['accepted'] = 0;
491
- $apbct->data['user_counter']['blocked'] = 0;
492
- $apbct->data['user_counter']['since'] = date('d M');
493
- $apbct->saveData();
494
- }
495
- //Reset or create all counters
496
- if(!empty($_GET['ct_reset_all_counters'])){
497
- $apbct->data['sfw_counter'] = array('all' => 0, 'blocked' => 0);
498
- $apbct->data['all_time_counter'] = array('accepted' => 0, 'blocked' => 0);
499
- $apbct->data['user_counter'] = array('all' => 0, 'accepted' => 0, 'blocked' => 0, 'since' => date('d M'));
500
- $apbct->data['array_accepted'] = array();
501
- $apbct->data['array_blocked'] = array();
502
- $apbct->data['current_hour'] = '';
503
- $apbct->saveData();
504
- }
505
- //Compile user's counter string
506
- $user_counter=Array('accepted'=>$apbct->data['user_counter']['accepted'], 'blocked'=>$apbct->data['user_counter']['blocked'], 'all'=>$apbct->data['user_counter']['accepted'] + $apbct->data['user_counter']['blocked'], 'since'=>$apbct->data['user_counter']['since']);
507
- //Previous version $user_counter_str='<span style="color: white;">Since '.$user_counter['since'].': ' .$user_counter['all']*/. '</span> / <span style="color: green;">' .$user_counter['accepted']. '</span> / <span style="color: red;">' .$user_counter['blocked']. '</span>';
508
- $user_counter_str='<span style="color: white;">' . __('Since', 'cleantalk-spam-protect') . '&nbsp;' . $user_counter['since'].': </span><span style="color: green;">' .$user_counter['accepted']. '</span> / <span style="color: red;">' .$user_counter['blocked']. '</span>';
509
-
510
- $all_time_counter_str='';
511
- //Don't compile if all time counter disabled
512
- if($apbct->settings['all_time_counter'] == 1){
513
- $all_time_counter=Array('accepted'=>$apbct->data['all_time_counter']['accepted'], 'blocked'=>$apbct->data['all_time_counter']['blocked'], 'all'=>$apbct->data['all_time_counter']['accepted'] + $apbct->data['all_time_counter']['blocked']);
514
- $all_time_counter_str='<span style="color: white;" title="'.__('All / Allowed / Blocked submissions. The number of submissions is being counted since CleanTalk plugin installation.', 'cleantalk-spam-protect').'"><span style="color: white;"> | ' . __('All', 'cleantalk-spam-protect') . ': ' .$all_time_counter['all']. '</span> / <span style="color: green;">' .$all_time_counter['accepted']. '</span> / <span style="color: red;">' .$all_time_counter['blocked']. '</span></span>';
515
- }
516
-
517
- $daily_counter_str='';
518
- //Don't compile if daily counter disabled
519
- if( $apbct->settings['daily_counter'] == 1){
520
- $daily_counter=Array('accepted'=>array_sum($apbct->data['array_accepted']), 'blocked'=>array_sum($apbct->data['array_blocked']), 'all'=>array_sum($apbct->data['array_accepted']) + array_sum($apbct->data['array_blocked']));
521
- //Previous version $daily_counter_str='<span style="color: white;" title="'.__('All / Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk-spam-protect').'"><span style="color: white;"> | Day: ' .$daily_counter['all']. '</span> / <span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
522
- $daily_counter_str='<span style="color: white;" title="'.__('Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk-spam-protect').'"><span style="color: white;"> | ' . __('Day', 'cleantalk-spam-protect') . ': </span><span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
523
- }
524
- $sfw_counter_str='';
525
- //Don't compile if SFW counter disabled
526
- if( $apbct->settings['sfw_counter'] == 1 && $apbct->settings['spam_firewall'] == 1){
527
- $sfw_counter=Array('all'=>$apbct->data['sfw_counter']['all'], 'blocked'=>$apbct->data['sfw_counter']['blocked']);
528
- $sfw_counter_str='<span style="color: white;" title="'.__('All / Blocked events. Access attempts regitred by SpamFireWall counted since the last plugin activation.', 'cleantalk-spam-protect').'"><span style="color: white;"> | SpamFireWall: ' .$sfw_counter['all']. '</span> / <span style="color: red;">' .$sfw_counter['blocked']. '</span></span>';
529
- }
530
-
531
- $args = array(
532
- 'id' => 'ct_parent_node',
533
- 'title' => '<img src="' . plugin_dir_url(__FILE__) . 'images/logo_small1.png" alt="" height="" style="margin-top:9px; float: left;" />'
534
- .'<div style="margin: auto 7px;" class="ab-item alignright">'
535
- .'<div class="ab-label" id="ct_stats">'
536
- .($apbct->notice_trial == 1
537
- ? "<span><a style='color: red;' href=\"https://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20trial&user_token={$apbct->user_token}&cp_mode=antispam\" target=\"_blank\">Renew Anti-Spam</a></span>"
538
- : '<span style="color: white;" title="'.__('Allowed / Blocked submissions. The number of submissions is being counted since ', 'cleantalk-spam-protect').' '.$user_counter['since'].'">'.$user_counter_str.'</span> '.$daily_counter_str.$all_time_counter_str.$sfw_counter_str
539
- )
540
- .'</div>'
541
- .'</div>' //You could change widget string here by simply deleting variables
542
- );
543
- $wp_admin_bar->add_node( $args );
544
-
545
- // DASHBOARD LINK
546
- if(!$apbct->white_label){
547
- $wp_admin_bar->add_node( array(
548
- 'id' => 'ct_dashboard_link',
549
- 'title' => '<a href="https://cleantalk.org/my/?user_token='.$apbct->user_token.'&utm_source=wp-backend&utm_medium=admin-bar&cp_mode=antispam " target="_blank">CleanTalk '.__('dashboard', 'cleantalk-spam-protect').'</a>',
550
- 'parent' => 'ct_parent_node'
551
- ));
552
- }
553
-
554
- $wp_admin_bar->add_node( array(
555
- 'id' => 'ct_settings_link',
556
- 'title' => '<a href="'.$apbct->settings_link.'">'.__('Settings', 'cleantalk-spam-protect').'</a>',
557
- 'parent' => 'ct_parent_node'
558
- ));
559
-
560
- // add a child item to our parent item. Bulk checks.
561
- if(!is_network_admin()){
562
- $args = array(
563
- 'id' => 'ct_settings_bulk_comments',
564
- 'title' => '<hr style="margin-top: 7px;" /><a href="edit-comments.php?page=ct_check_spam" title="'.__('Bulk spam comments removal tool.', 'cleantalk-spam-protect').'">'.__('Check comments for spam', 'cleantalk-spam-protect').'</a>',
565
- 'parent' => 'ct_parent_node'
566
- );
567
- }
568
- $wp_admin_bar->add_node( $args );
569
-
570
- // add a child item to our parent item. Bulk checks.
571
- if(!is_network_admin()){
572
- $args = array(
573
- 'id' => 'ct_settings_bulk_users',
574
- 'title' => '<a href="users.php?page=ct_check_users" title="Bulk spam users removal tool.">'.__('Check users for spam', 'cleantalk-spam-protect').'</a>',
575
- 'parent' => 'ct_parent_node'
576
- );
577
- }
578
- $wp_admin_bar->add_node( $args );
579
-
580
- // User counter reset.
581
- $args = array(
582
- 'id' => 'ct_reset_counter',
583
- 'title' => '<hr style="margin-top: 7px;"><a href="?ct_reset_user_counter=1" title="Reset your personal counter of submissions.">'.__('Reset first counter', 'cleantalk-spam-protect').'</a>',
584
- 'parent' => 'ct_parent_node'
585
- );
586
- $wp_admin_bar->add_node( $args );// add a child item to our parent item. Counter reset.
587
-
588
- // Reset ALL counter
589
- $args = array(
590
- 'id' => 'ct_reset_counters_all',
591
- 'title' => '<a href="?ct_reset_all_counters=1" title="Reset all counters.">'.__('Reset all counters', 'cleantalk-spam-protect').'</a>',
592
- 'parent' => 'ct_parent_node'
593
- );
594
- $wp_admin_bar->add_node( $args );
595
-
596
- // Support link
597
- if(!$apbct->white_label){
598
- $wp_admin_bar->add_node( array(
599
- 'id' => 'ct_admin_bar_support_link',
600
- 'title' => '<hr style="margin-top: 7px;" /><a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">'.__('Support', 'cleantalk-spam-protect').'</a>',
601
- 'parent' => 'ct_parent_node'
602
- ));
603
- }
604
- }
605
- }
606
-
607
- /**
608
- * Unmark bad words
609
- * @param string $message
610
- * @return string Cleat comment
611
- */
612
- function apbct_comment__unmark_red($message) {
613
- $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
614
-
615
- return $message;
616
- }
617
-
618
- // Ajax action feedback form comments page.
619
- function apbct_comment__send_feedback($comment_id = null, $comment_status = null, $change_status = false, $direct_call = null){
620
-
621
- // For AJAX call
622
- if( ! $direct_call ){
623
- check_ajax_referer('ct_secret_nonce', 'security');
624
- }
625
-
626
- $comment_id = ! $comment_id && isset( $_POST['comment_id'] ) ? $_POST['comment_id'] : false;
627
- $comment_status = ! $comment_status && isset( $_POST['comment_status'] ) ? $_POST['comment_status'] : false;
628
- $change_status = ! $change_status && isset( $_POST['change_status'] ) ? $_POST['change_status'] : false;
629
-
630
- // If enter params is empty exit
631
- if( ! $comment_id || ! $comment_status )
632
- die();
633
-
634
- // $comment = get_comment($comment_id, 'ARRAY_A');
635
- $hash = get_comment_meta($comment_id, 'ct_hash', true);
636
-
637
- // If we can send the feedback
638
- if($hash){
639
-
640
- // Approving
641
- if($comment_status == '1' || $comment_status == 'approve'){
642
- $result = ct_send_feedback($hash.":1");
643
- // $comment['comment_content'] = apbct_comment__unmark_red($comment['comment_content']);
644
- // wp_update_comment($comment);
645
- $result === true ? 1 : 0;
646
- }
647
-
648
- // Disapproving
649
- if($comment_status == 'spam'){
650
- $result = ct_send_feedback($hash.":0");
651
- $result === true ? 1 : 0;
652
- }
653
- }else{
654
- $result = 'no_hash';
655
- }
656
-
657
- // Changing comment status(folder) if flag is set. spam || approve
658
- if($change_status !== false)
659
- wp_set_comment_status($comment_id, $comment_status);
660
-
661
- if(!$direct_call){
662
- echo !empty($result) ? $result : 0;
663
- die();
664
- }else{
665
-
666
- }
667
- }
668
-
669
- // Ajax action feedback form user page.
670
- function apbct_user__send_feedback($user_id = null, $status = null, $direct_call = null){
671
-
672
- check_ajax_referer('ct_secret_nonce', 'security');
673
-
674
- if(!$direct_call){
675
- $user_id = $_POST['user_id'];
676
- $status = $_POST['status'];
677
- }
678
-
679
- $hash = get_user_meta($user_id, 'ct_hash', true);
680
-
681
- if($hash){
682
- if($status == 'approve' || $status == 1){
683
- $result = ct_send_feedback($hash.":1");
684
- $result === true ? 1 : 0;
685
- }
686
- if($status == 'spam' || $status == 'disapprove' || $status == 0){
687
- $result = ct_send_feedback($hash.":0");
688
- $result === true ? 1 : 0;
689
- }
690
- }else{
691
- $result = 'no_hash';
692
- }
693
-
694
- if(!$direct_call){
695
- echo !empty($result) ? $result : 0;
696
- die();
697
- }else{
698
-
699
- }
700
-
701
- }
702
-
703
- /**
704
- * Send feedback when user deleted
705
- * @return null
706
- */
707
- function apbct_user__delete__hook($user_id, $reassign = null){
708
-
709
- $hash = get_user_meta($user_id, 'ct_hash', true);
710
- if ($hash !== '') {
711
- ct_feedback($hash, 0);
712
- }
713
  }
1
+ <?php
2
+
3
+ require_once('cleantalk-settings.php');
4
+
5
+ // Add buttons to comments list table
6
+ add_action( 'manage_comments_nav', 'apbct_add_buttons_to_comments_and_users', 10, 1 );
7
+ add_action( 'manage_users_extra_tablenav', 'apbct_add_buttons_to_comments_and_users', 10, 1 );
8
+
9
+ // Check renew banner
10
+ add_action( 'wp_ajax_apbct_settings__check_renew_banner', 'apbct_settings__check_renew_banner');
11
+
12
+ // Crunch for Anti-Bot
13
+ add_action( 'admin_head','apbct_admin_set_cookie_for_anti_bot' );
14
+
15
+ function apbct_admin_set_cookie_for_anti_bot(){
16
+ global $apbct;
17
+ echo '<script>document.cookie = "apbct_antibot=' . md5( $apbct->api_key . \Cleantalk\ApbctWP\Helper::ip__get(array('real'), true ) ) . '; path=/; expires=0; samesite=lax";</script>';
18
+ }
19
+
20
+ function apbct_add_buttons_to_comments_and_users( $unused_argument ) {
21
+
22
+ global $apbct;
23
+ $current_screen = get_current_screen();
24
+
25
+ if( 'users' == $current_screen->base ) {
26
+ $button_url__check = $current_screen->base . '.php?page=ct_check_users';
27
+ $button_url__results = $current_screen->base . '.php?page=ct_check_users_total';
28
+ $button_description = 'users';
29
+ } elseif ( 'edit-comments' == $current_screen->base ) {
30
+ $button_url__check = $current_screen->base . '.php?page=ct_check_spam';
31
+ $button_url__results = $current_screen->base . '.php?page=ct_check_spam_total';
32
+ $button_description = 'comments';
33
+ } else {
34
+ return;
35
+ }
36
+
37
+ echo '
38
+ <a href="' . $button_url__check . '" class="button" style="margin:1px 0 0 0; display: inline-block;">
39
+ <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
40
+ ' . sprintf(__( 'Find spam %s', 'cleantalk-spam-protect'), $button_description ) . '
41
+ </a>
42
+ <a href="' . $button_url__results . '" class="button" style="margin:1px 0 0 0; display: inline-block;">
43
+ <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
44
+ ' . sprintf(__( 'View spam %s', 'cleantalk-spam-protect'), $button_description ) . '
45
+ </a>
46
+ <a href="https://cleantalk.org/my/show_requests?service_id=' . $apbct->data['service_id'] . '&int=week" target="_blank" class="button" style="margin:1px 0 0 0; display: inline-block;">
47
+ <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
48
+ ' . __( 'CleanTalk Anti-Spam Log', 'cleantalk-spam-protect') . '
49
+ </a>
50
+ ';
51
+
52
+ }
53
+
54
+ add_action( 'admin_bar_menu', 'apbct_admin__admin_bar__add', 999 );
55
+
56
+ //Adding widjet
57
+ function ct_dashboard_statistics_widget() {
58
+
59
+ global $apbct;
60
+
61
+ if(apbct_is_user_role_in(array('administrator'))){
62
+ wp_add_dashboard_widget(
63
+ 'ct_dashboard_statistics_widget',
64
+ $apbct->plugin_name
65
+ ."<div class='ct_widget_top_links'>"
66
+ ."<img src='".plugins_url('/cleantalk-spam-protect/inc/images/preloader.gif')."' class='ct_preloader'>"
67
+ .sprintf(__("%sRefresh%s", 'cleantalk-spam-protect'), "<a href='#ct_widget' class='ct_widget_refresh_link'>", "</a>")
68
+ .sprintf(__("%sConfigure%s", 'cleantalk-spam-protect'), "<a href='{$apbct->settings_link}' class='ct_widget_settings_link'>", "</a>")
69
+ ."</div>",
70
+ 'ct_dashboard_statistics_widget_output'
71
+ );
72
+ }
73
+ }
74
+
75
+ // Outputs statistics widget content
76
+ function ct_dashboard_statistics_widget_output( $post, $callback_args ) {
77
+
78
+ global $apbct, $current_user;
79
+
80
+ echo "<div id='ct_widget_wrapper'>";
81
+ ?>
82
+ <form id='ct_refresh_form' method='POST' action='#ct_widget'>
83
+ <input type='hidden' name='ct_brief_refresh' value='1'>
84
+ </form>
85
+ <h4 class='ct_widget_block_header' style='margin-left: 12px;'><?php _e('7 days anti-spam stats', 'cleantalk-spam-protect'); ?></h4>
86
+ <div class='ct_widget_block ct_widget_chart_wrapper'>
87
+ <div id='ct_widget_chart'></div>
88
+ </div>
89
+ <h4 class='ct_widget_block_header'><?php _e('Top 5 spam IPs blocked', 'cleantalk-spam-protect'); ?></h4>
90
+ <hr class='ct_widget_hr'>
91
+ <?php
92
+ if(!apbct_api_key__is_correct() || (isset($apbct->data['brief_data']['error_no']) && $apbct->data['brief_data']['error_no'] == 6)){
93
+ ?> <div class='ct_widget_block'>
94
+ <form action='<? echo $apbct->settings_link; ?>' method='POST'>
95
+ <h2 class='ct_widget_activate_header'><?php _e('Get Access key to activate Anti-Spam protection!', 'cleantalk-spam-protect'); ?></h2>
96
+ <input class='ct_widget_button ct_widget_activate_button' type='submit' name='get_apikey_auto' value='ACTIVATE' />
97
+ </form>
98
+ </div>
99
+ <?php
100
+ }elseif(!empty($apbct->data['brief_data']['error'])){
101
+ echo '<div class="ct_widget_block">'
102
+ .'<h2 class="ct_widget_activate_header">'
103
+ .sprintf(__('Something went wrong! Error: "%s".', 'cleantalk-spam-protect'), "<u>{$apbct->brief_data['error']}</u>")
104
+ .'</h2>';
105
+ if($apbct->user_token && !$apbct->white_label){
106
+ echo '<h2 class="ct_widget_activate_header">'
107
+ .__('Please, visit your dashboard.', 'cleantalk-spam-protect')
108
+ .'</h2>'
109
+ .'<a target="_blank" href="https://cleantalk.org/my?user_token='.$apbct->user_token.'&cp_mode=antispam">'
110
+ .'<input class="ct_widget_button ct_widget_activate_button ct_widget_resolve_button" type="button" value="VISIT CONTROL PANEL">'
111
+ .'</a>';
112
+ }
113
+ echo '</div>';
114
+ }
115
+
116
+ if(apbct_api_key__is_correct() && empty($apbct->data['brief_data']['error'])){
117
+ ?>
118
+ <div class='ct_widget_block'>
119
+ <table cellspacing="0">
120
+ <tr>
121
+ <th><?php _e('IP', 'cleantalk-spam-protect'); ?></th>
122
+ <th><?php _e('Country', 'cleantalk-spam-protect'); ?></th>
123
+ <th><?php _e('Block Count', 'cleantalk-spam-protect'); ?></th>
124
+ </tr>
125
+ <?php foreach($apbct->brief_data['top5_spam_ip'] as $val){ ?>
126
+ <tr>
127
+ <td><?php echo $val[0]; ?></td>
128
+ <td><?php echo $val[1] ? "<img src='https://cleantalk.org/images/flags/".strtolower($val[1]).".png'>" : ''; ?>&nbsp;<?php
129
+ echo $val[1]
130
+ ? locale_get_display_region('sl-Latn-'.$val[1].'-nedis', substr(get_locale(), 0, 2))
131
+ : 'Unknown'; ?></td>
132
+ <td style='text-align: center;'><?php echo $val[2]; ?></td>
133
+ </tr>
134
+ <?php } ?>
135
+ </table>
136
+ <?php if($apbct->user_token){ ?>
137
+ <a target='_blank' href='https://cleantalk.org/my?user_token=<?php echo $apbct->user_token; ?>&cp_mode=antispam'>
138
+ <input class='ct_widget_button' id='ct_widget_button_view_all' type='button' value='View all'>
139
+ </a>
140
+ <?php } ?>
141
+ </div>
142
+
143
+ <?php
144
+ }
145
+ // Notice at the bottom
146
+ if(isset($current_user) && in_array('administrator', $current_user->roles)){
147
+
148
+ if($apbct->spam_count && $apbct->spam_count > 0){
149
+ echo '<div class="ct_widget_wprapper_total_blocked">'
150
+ .'<img src="'.$apbct->logo__small__colored.'" class="ct_widget_small_logo"/>'
151
+ .'<span title="'.sprintf(__('This is the count from the %s\'s cloud and could be different to admin bar counters', 'cleantalk-spam-protect').'">', $apbct->plugin_name)
152
+ .sprintf(
153
+ /* translators: %s: Number of spam messages */
154
+ __( '%s%s%s has blocked %s spam for all time. The statistics are automatically updated every 24 hours.', 'cleantalk-spam-protect'),
155
+ !$apbct->white_label ? '<a href="https://cleantalk.org/my/?user_token='.$apbct->user_token.'&utm_source=wp-backend&utm_medium=dashboard_widget&cp_mode=antispam" target="_blank">' : '',
156
+ $apbct->plugin_name,
157
+ !$apbct->white_label ? '</a>' : '',
158
+ number_format($apbct->data['spam_count'], 0, ',', ' ')
159
+ )
160
+ .'</span>'
161
+ .(!$apbct->white_label
162
+ ? '<br><br>'
163
+ .'<b style="font-size: 16px;">'
164
+ .sprintf(
165
+ __('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'),
166
+ '<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">',
167
+ '</a></u>'
168
+ )
169
+ .'</b>'
170
+ : ''
171
+ )
172
+ .'</div>';
173
+ }
174
+ }
175
+ echo '</div>';
176
+ }
177
+
178
+ /**
179
+ * Admin action 'admin_init' - Add the admin settings and such
180
+ */
181
+ function apbct_admin__init(){
182
+
183
+ global $apbct;
184
+
185
+ // Getting dashboard widget statistics
186
+ if(!empty($_POST['ct_brief_refresh'])){
187
+ $apbct->data['brief_data'] = \Cleantalk\ApbctWP\API::method__get_antispam_report_breif($apbct->api_key);
188
+ $apbct->saveData();
189
+ }
190
+
191
+ // Getting key like hoster. Only once!
192
+ if(!is_main_site() && $apbct->white_label && ( empty($apbct->api_key) || $apbct->settings['apikey'] == $apbct->network_settings['apikey'] ) ){
193
+
194
+ $_POST['submit'] = 'get_key_auto';
195
+ $apbct->save('settings');
196
+ $settings = get_option('cleantalk_settings');
197
+ $apbct->api_key = $settings['apikey'];
198
+ unset($_POST['submit']);
199
+
200
+ }
201
+ }
202
+
203
+ function apbct_admin__init___ajax_actions(){
204
+
205
+ // Settings
206
+ add_action('wp_ajax_apbct_settings__get__long_description', 'apbct_settings__get__long_description'); // Long description
207
+
208
+ add_action( 'wp_ajax_apbct_sync', 'apbct_settings__sync' );
209
+ }
210
+
211
+ /**
212
+ * Manage links in plugins list
213
+ * @return array
214
+ */
215
+ function apbct_admin__plugin_action_links($links, $file) {
216
+
217
+ global $apbct;
218
+
219
+ $settings_link = '<a href="' . $apbct->settings_link . '">' . __( 'Settings' ) . '</a>';
220
+
221
+ array_unshift( $links, $settings_link ); // before other links
222
+ return $links;
223
+ }
224
+
225
+ /**
226
+ * Manage links and plugins page
227
+ * @return array
228
+ */
229
+ function apbct_admin__register_plugin_links($links, $file){
230
+
231
+ global $apbct;
232
+
233
+ //Return if it's not our plugin
234
+ if ($file != $apbct->base_name)
235
+ return $links;
236
+
237
+ if($apbct->white_label){
238
+ $links = array_slice($links, 0, 1);
239
+ $links[] = "<script>jQuery('.plugin-title strong').each(function(i, item){
240
+ if(jQuery(item).html() == 'Anti-Spam by CleanTalk')
241
+ jQuery(item).html('{$apbct->plugin_name}');
242
+ });</script>";
243
+ return $links;
244
+ }
245
+
246
+ if(substr(get_locale(), 0, 2) != 'en')
247
+ $links[] = '<a class="ct_meta_links ct_translate_links" href="'
248
+ .sprintf('https://translate.wordpress.org/locale/%s/default/wp-plugins/cleantalk-spam-protect', substr(get_locale(), 0, 2))
249
+ .'" target="_blank">'
250
+ .__('Translate', 'cleantalk-spam-protect')
251
+ .'</a>';
252
+
253
+ $links[] = '<a class="ct_meta_links" href="'.$apbct->settings_link.'" target="_blank">' . __( 'Start here','cleantalk-spam-protect') . '</a>';
254
+ $links[] = '<a class="ct_meta_links ct_faq_links" href="https://wordpress.org/plugins/cleantalk-spam-protect/faq/" target="_blank">' . __( 'FAQ','cleantalk-spam-protect') . '</a>';
255
+ $links[] = '<a class="ct_meta_links ct_support_links"href="https://wordpress.org/support/plugin/cleantalk-spam-protect" target="_blank">' . __( 'Support','cleantalk-spam-protect') . '</a>';
256
+ $trial = apbct_admin__badge__get_premium(false);
257
+ if(!empty($trial))
258
+ $links[] = apbct_admin__badge__get_premium(false);
259
+
260
+ return $links;
261
+ }
262
+
263
+ /**
264
+ * Admin action 'admin_enqueue_scripts' - Enqueue admin script of reloading admin page after needed AJAX events
265
+ * @param string $hook URL of hooked page
266
+ */
267
+ function apbct_admin__enqueue_scripts($hook){
268
+
269
+ global $apbct;
270
+
271
+ // Scripts to all admin pages
272
+ wp_enqueue_script('ct_admin_js_notices', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin.min.js'), array(), APBCT_VERSION);
273
+ wp_enqueue_style ('ct_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin.min.css'), array(), APBCT_VERSION, 'all');
274
+
275
+ wp_localize_script( 'ct_admin_js_notices', 'ctAdminCommon', array(
276
+ '_ajax_nonce' => wp_create_nonce( 'ct_secret_nonce' ),
277
+ '_ajax_url' => admin_url( 'admin-ajax.php' ),
278
+ 'plugin_name' => $apbct->plugin_name,
279
+ 'logo' => '<img src="' . $apbct->logo . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
280
+ 'logo_small' => '<img src="' . $apbct->logo__small . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
281
+ 'logo_small_colored' => '<img src="' . $apbct->logo__small__colored . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
282
+ ) );
283
+
284
+ // DASHBOARD page JavaScript and CSS
285
+ if($hook == 'index.php' && apbct_is_user_role_in(array('administrator'))){
286
+
287
+ wp_enqueue_style('ct_admin_css_widget_dashboard', plugins_url('/cleantalk-spam-protect/css/cleantalk-dashboard-widget.min.css'), array(), APBCT_VERSION, 'all');
288
+ wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
289
+
290
+ wp_enqueue_script('ct_gstatic_charts_loader', plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget--google-charts.min.js'), array(), APBCT_VERSION);
291
+ wp_enqueue_script('ct_admin_js_widget_dashboard', plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget.min.js'), array('ct_gstatic_charts_loader'), APBCT_VERSION);
292
+
293
+ // Preparing widget data
294
+ // Parsing brief data 'spam_stat' {"yyyy-mm-dd": spam_count, "yyyy-mm-dd": spam_count} to [["yyyy-mm-dd", "spam_count"], ["yyyy-mm-dd", "spam_count"]]
295
+ $to_chart = array();
296
+
297
+ // Crunch. Response contains error.
298
+ if(!empty($apbct->data['brief_data']['error']))
299
+ $apbct->data['brief_data'] = array_merge($apbct->data['brief_data'], $apbct->def_data['brief_data']);
300
+
301
+ foreach( $apbct->data['brief_data']['spam_stat'] as $key => $value ){
302
+ $to_chart[] = array( $key, $value );
303
+ } unset( $key, $value );
304
+
305
+ wp_localize_script( 'ct_admin_js_widget_dashboard', 'apbctDashboardWidget', array(
306
+ 'data' => $to_chart,
307
+ ));
308
+ }
309
+
310
+ // SETTINGS's page JavaScript and CSS
311
+ if( $hook == 'settings_page_cleantalk' ){
312
+
313
+ // jQueryUI
314
+ wp_enqueue_script('jqueryui', plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'), array('jquery'), '1.12.1' );
315
+ wp_enqueue_style('jqueryui_css', plugins_url('/cleantalk-spam-protect/css/jquery-ui.min.css'),array(), '1.21.1', 'all');
316
+
317
+ wp_enqueue_script('cleantalk_admin_js_settings_page', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin-settings-page.min.js'), array(), APBCT_VERSION);
318
+ wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin-settings-page.min.css'), array(), APBCT_VERSION, 'all');
319
+ wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
320
+
321
+ wp_localize_script( 'cleantalk_admin_js_settings_page', 'ctSettingsPage', array(
322
+ 'ct_subtitle' => $apbct->ip_license ? __('Hosting AntiSpam', 'cleantalk-spam-protect') : '',
323
+ 'ip_license' => $apbct->ip_license ? true : false,
324
+ 'key_changed' => ! empty( $apbct->data['key_changed'] ) ? true : false,
325
+ ));
326
+ }
327
+
328
+ // COMMENTS page JavaScript
329
+ if($hook == 'edit-comments.php'){
330
+ wp_enqueue_script('ct_comments_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-editscreen.min.js'), array(), APBCT_VERSION);
331
+ wp_localize_script( 'ct_comments_editscreen', 'ctCommentsScreen', array(
332
+ 'ct_ajax_nonce' => wp_create_nonce('ct_secret_nonce'),
333
+ 'spambutton_text' => __("Find spam comments", 'cleantalk-spam-protect'),
334
+ 'ct_feedback_msg_whitelisted' => __("The sender has been whitelisted.", 'cleantalk-spam-protect'),
335
+ 'ct_feedback_msg_blacklisted' => __("The sender has been blacklisted.", 'cleantalk-spam-protect'),
336
+ 'ct_feedback_msg' => sprintf(__("Feedback has been sent to %sCleanTalk Dashboard%s.", 'cleantalk-spam-protect'), $apbct->user_token ? "<a target='_blank' href=https://cleantalk.org/my?user_token={$apbct->user_token}&cp_mode=antispam>" : '', $apbct->user_token ? "</a>" : ''),
337
+ 'ct_show_check_links' => (bool)$apbct->settings['show_check_links'],
338
+ 'ct_img_src_new_tab' => plugin_dir_url(__FILE__)."images/new_window.gif",
339
+ ));
340
+ }
341
+
342
+ // USERS page JavaScript
343
+ if($hook == 'users.php'){
344
+ wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
345
+ wp_enqueue_script('ct_users_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-users-editscreen.min.js'), array(), APBCT_VERSION);
346
+ wp_localize_script( 'ct_users_editscreen', 'ctUsersScreen', array(
347
+ 'spambutton_text' => __("Find spam-users", 'cleantalk-spam-protect'),
348
+ 'ct_show_check_links' => (bool)$apbct->settings['show_check_links'],
349
+ 'ct_img_src_new_tab' => plugin_dir_url(__FILE__)."images/new_window.gif"
350
+ ));
351
+ }
352
+
353
+ }
354
+
355
+ /**
356
+ * Notice blog owner if plugin is used without Access key
357
+ * @return bool
358
+ */
359
+ function apbct_admin__notice_message(){
360
+
361
+ global $apbct;
362
+
363
+ $page = get_current_screen();
364
+
365
+ //General notice control flags
366
+ $self_owned_key = ($apbct->moderate_ip == 0 && !defined('CLEANTALK_ACCESS_KEY') ? true : false);
367
+ $is_dashboard = (is_network_admin() || is_admin() ? true : false);
368
+ $is_admin = (current_user_can('activate_plugins') ? true : false);
369
+
370
+ $page_is_ct_settings = (in_array($page->id, array('settings_page_cleantalk', 'settings_page_cleantalk-network', 'comments_page_ct_check_spam', 'users_page_ct_check_users')) ? true : false);
371
+
372
+ //Misc
373
+ $user_token = ($apbct->user_token ? '&user_token='.$apbct->user_token : '');
374
+
375
+ if( is_network_admin() ) {
376
+ $site_url = get_site_option('siteurl');
377
+ $site_url = preg_match( '/\/$/', $site_url ) ? $site_url : $site_url . '/';
378
+ $settings_link = $site_url . 'wp-admin/options-general.php?page=cleantalk';
379
+ } else {
380
+ $settings_link = 'options-general.php?page=cleantalk';
381
+ }
382
+
383
+ if($self_owned_key && $is_dashboard && $is_admin){
384
+ // Auto update notice
385
+ /* Disabled at 09.09.2018
386
+ if($apbct->notice_auto_update == 1 && $apbct->auto_update != -1 && empty($_COOKIE['apbct_update_banner_closed'])){
387
+ $link = '<a href="https://cleantalk.org/help/cleantalk-auto-update" target="_blank">%s</a>';
388
+ $button = sprintf($link, '<input type="button" class="button button-primary" value="'.__('Learn more', 'cleantalk-spam-protect').'" />');
389
+ echo '<div class="error notice is-dismissible apbct_update_notice">'
390
+ .'<h3>'
391
+ .__('Do you know that Anti-Spam by CleanTalk has auto update option?', 'cleantalk-spam-protect')
392
+ .'</br></br>'
393
+ .$button
394
+ .'</h3>'
395
+ .'</div>';
396
+ }
397
+ */
398
+ //Unable to get key automatically (if apbct_admin__init().getAutoKey() returns error)
399
+ if ($apbct->notice_show && !empty($apbct->errors['get_key']) && !$apbct->white_label){
400
+ echo '<div class="error">
401
+ <h3>' . sprintf(__("Unable to get Access key automatically: %s", 'cleantalk-spam-protect'), $apbct->api_key).
402
+ "<a target='__blank' style='margin-left: 10px' href='https://cleantalk.org/register?platform=wordpress&email=" . urlencode(ct_get_admin_email())."&website=" . urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))."'>".__('Get the Access key', 'cleantalk-spam-protect').'</a>
403
+ </h3>
404
+ </div>';
405
+ }
406
+
407
+ //key == "" || "enter key"
408
+ if (!apbct_api_key__is_correct() && $apbct->moderate_ip == 0){
409
+ echo "<div class='error'>"
410
+ ."<h3>"
411
+ .sprintf(__("Please enter Access Key in %s settings to enable anti spam protection!", 'cleantalk-spam-protect'), "<a href='{$settings_link}'>$apbct->plugin_name</a>")
412
+ ."</h3>"
413
+ ."</div>";
414
+ $apbct->notice_show = false;
415
+ }
416
+
417
+ //"Trial period ends" notice from apbct_admin__init().api_method__notice_paid_till()
418
+ if ($apbct->notice_show && $apbct->notice_trial == 1 && $apbct->moderate_ip == 0 && !$apbct->white_label) {
419
+ if(isset($_GET['page']) && in_array($_GET['page'], array('cleantalk', 'ct_check_spam', 'ct_check_users'))){
420
+ echo '<div class="error" id="apbct_trial_notice">
421
+ <h3>' . sprintf(__("%s trial period ends, please upgrade to %s!", 'cleantalk-spam-protect'),
422
+ "<a href='{$settings_link}'>".$apbct->plugin_name."</a>",
423
+ "<a href=\"https://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20trial$user_token&cp_mode=antispam\" target=\"_blank\"><b>premium version</b></a>") .
424
+ '</h3>
425
+ <h4 style = "color: gray">Account status updates every 15 minutes.</h4>
426
+ </div>';
427
+ $apbct->notice_show = false;
428
+ }
429
+ }
430
+
431
+ //Renew notice from apbct_admin_init().api_method__notice_paid_till()
432
+ if ($apbct->notice_show && $apbct->notice_renew == 1 && $apbct->moderate_ip == 0 && !$apbct->white_label) {
433
+ $renew_link = "<a href=\"https://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%%20backend%%20renew$user_token&cp_mode=antispam\" target=\"_blank\">%s</a>";
434
+ $button_html = sprintf($renew_link, '<input type="button" class="button button-primary" value="'.__('RENEW ANTI-SPAM', 'cleantalk-spam-protect').'" />');
435
+ $link_html = sprintf($renew_link, "<b>".__('next year', 'cleantalk-spam-protect')."</b>");
436
+
437
+ echo '<div class="updated" id="apbct_renew_notice">
438
+ <h3>'.
439
+ sprintf(__("Please renew your anti-spam license for %s.", 'cleantalk-spam-protect'), $link_html).
440
+ '</h3>
441
+ <h4 style = "color: gray">Account status updates every 15 minutes.</h4>
442
+ '.$button_html.'
443
+ <br/><br/>
444
+ </div>';
445
+ $apbct->notice_show = false;
446
+ }
447
+
448
+ //"Wrong access key" notice (if ct_update_option().METHOD_notice_validate_key returns a error)
449
+ if ($apbct->notice_show && $page_is_ct_settings && !$apbct->data['key_is_ok'] && $apbct->moderate_ip == 0 && !$apbct->white_label){
450
+ echo '<div class="error">
451
+ <h3><b>'.
452
+ __("Wrong <a href='{$settings_link}'><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://wordpress.org/support/plugin/cleantalk-spam-protect/\">support</a>.", 'cleantalk-spam-protect').
453
+ '</b></h3>
454
+ </div>';
455
+ }
456
+ }
457
+
458
+ return true;
459
+ }
460
+
461
+ function apbct_admin__badge__get_premium($print = true, $out = ''){
462
+
463
+ global $apbct;
464
+
465
+ if($apbct->license_trial == 1 && $apbct->user_token){
466
+ $out .= '<b style="display: inline-block; margin-top: 10px;">'
467
+ .($print ? __('Make it right!', 'cleantalk-spam-protect').' ' : '')
468
+ .sprintf(
469
+ __('%sGet premium%s', 'cleantalk-spam-protect'),
470
+ '<a href="https://cleantalk.org/my/bill/recharge?user_token='.$apbct->user_token.'" target="_blank">',
471
+ '</a>'
472
+ )
473
+ .'</b>';
474
+ }
475
+
476
+ if($print)
477
+ echo $out;
478
+ else
479
+ return $out;
480
+ }
481
+
482
+ function apbct_admin__admin_bar__add( $wp_admin_bar ) {
483
+
484
+ global $apbct;
485
+
486
+ if (current_user_can('activate_plugins') && $apbct->settings['show_adminbar'] == 1 && (apbct_api_key__is_correct($apbct->api_key) !== false || (defined('CLEANTALK_SHOW_ADMIN_BAR_FORCE') && CLEANTALK_SHOW_ADMIN_BAR_FORCE))) {
487
+
488
+ //Reset or create user counter
489
+ if(!empty($_GET['ct_reset_user_counter'])){
490
+ $apbct->data['user_counter']['accepted'] = 0;
491
+ $apbct->data['user_counter']['blocked'] = 0;
492
+ $apbct->data['user_counter']['since'] = date('d M');
493
+ $apbct->saveData();
494
+ }
495
+ //Reset or create all counters
496
+ if(!empty($_GET['ct_reset_all_counters'])){
497
+ $apbct->data['sfw_counter'] = array('all' => 0, 'blocked' => 0);
498
+ $apbct->data['all_time_counter'] = array('accepted' => 0, 'blocked' => 0);
499
+ $apbct->data['user_counter'] = array('all' => 0, 'accepted' => 0, 'blocked' => 0, 'since' => date('d M'));
500
+ $apbct->data['array_accepted'] = array();
501
+ $apbct->data['array_blocked'] = array();
502
+ $apbct->data['current_hour'] = '';
503
+ $apbct->saveData();
504
+ }
505
+ //Compile user's counter string
506
+ $user_counter=Array('accepted'=>$apbct->data['user_counter']['accepted'], 'blocked'=>$apbct->data['user_counter']['blocked'], 'all'=>$apbct->data['user_counter']['accepted'] + $apbct->data['user_counter']['blocked'], 'since'=>$apbct->data['user_counter']['since']);
507
+ //Previous version $user_counter_str='<span style="color: white;">Since '.$user_counter['since'].': ' .$user_counter['all']*/. '</span> / <span style="color: green;">' .$user_counter['accepted']. '</span> / <span style="color: red;">' .$user_counter['blocked']. '</span>';
508
+ $user_counter_str='<span style="color: white;">' . __('Since', 'cleantalk-spam-protect') . '&nbsp;' . $user_counter['since'].': </span><span style="color: green;">' .$user_counter['accepted']. '</span> / <span style="color: red;">' .$user_counter['blocked']. '</span>';
509
+
510
+ $all_time_counter_str='';
511
+ //Don't compile if all time counter disabled
512
+ if($apbct->settings['all_time_counter'] == 1){
513
+ $all_time_counter=Array('accepted'=>$apbct->data['all_time_counter']['accepted'], 'blocked'=>$apbct->data['all_time_counter']['blocked'], 'all'=>$apbct->data['all_time_counter']['accepted'] + $apbct->data['all_time_counter']['blocked']);
514
+ $all_time_counter_str='<span style="color: white;" title="'.__('All / Allowed / Blocked submissions. The number of submissions is being counted since CleanTalk plugin installation.', 'cleantalk-spam-protect').'"><span style="color: white;"> | ' . __('All', 'cleantalk-spam-protect') . ': ' .$all_time_counter['all']. '</span> / <span style="color: green;">' .$all_time_counter['accepted']. '</span> / <span style="color: red;">' .$all_time_counter['blocked']. '</span></span>';
515
+ }
516
+
517
+ $daily_counter_str='';
518
+ //Don't compile if daily counter disabled
519
+ if( $apbct->settings['daily_counter'] == 1){
520
+ $daily_counter=Array('accepted'=>array_sum($apbct->data['array_accepted']), 'blocked'=>array_sum($apbct->data['array_blocked']), 'all'=>array_sum($apbct->data['array_accepted']) + array_sum($apbct->data['array_blocked']));
521
+ //Previous version $daily_counter_str='<span style="color: white;" title="'.__('All / Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk-spam-protect').'"><span style="color: white;"> | Day: ' .$daily_counter['all']. '</span> / <span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
522
+ $daily_counter_str='<span style="color: white;" title="'.__('Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk-spam-protect').'"><span style="color: white;"> | ' . __('Day', 'cleantalk-spam-protect') . ': </span><span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
523
+ }
524
+ $sfw_counter_str='';
525
+ //Don't compile if SFW counter disabled
526
+ if( $apbct->settings['sfw_counter'] == 1 && $apbct->settings['spam_firewall'] == 1){
527
+ $sfw_counter=Array('all'=>$apbct->data['sfw_counter']['all'], 'blocked'=>$apbct->data['sfw_counter']['blocked']);
528
+ $sfw_counter_str='<span style="color: white;" title="'.__('All / Blocked events. Access attempts regitred by SpamFireWall counted since the last plugin activation.', 'cleantalk-spam-protect').'"><span style="color: white;"> | SpamFireWall: ' .$sfw_counter['all']. '</span> / <span style="color: red;">' .$sfw_counter['blocked']. '</span></span>';
529
+ }
530
+
531
+ $args = array(
532
+ 'id' => 'ct_parent_node',
533
+ 'title' => '<img src="' . plugin_dir_url(__FILE__) . 'images/logo_small1.png" alt="" height="" style="margin-top:9px; float: left;" />'
534
+ .'<div style="margin: auto 7px;" class="ab-item alignright">'
535
+ .'<div class="ab-label" id="ct_stats">'
536
+ .($apbct->notice_trial == 1
537
+ ? "<span><a style='color: red;' href=\"https://cleantalk.org/my/bill/recharge?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20trial&user_token={$apbct->user_token}&cp_mode=antispam\" target=\"_blank\">Renew Anti-Spam</a></span>"
538
+ : '<span style="color: white;" title="'.__('Allowed / Blocked submissions. The number of submissions is being counted since ', 'cleantalk-spam-protect').' '.$user_counter['since'].'">'.$user_counter_str.'</span> '.$daily_counter_str.$all_time_counter_str.$sfw_counter_str
539
+ )
540
+ .'</div>'
541
+ .'</div>' //You could change widget string here by simply deleting variables
542
+ );
543
+ $wp_admin_bar->add_node( $args );
544
+
545
+ // DASHBOARD LINK
546
+ if(!$apbct->white_label){
547
+ $wp_admin_bar->add_node( array(
548
+ 'id' => 'ct_dashboard_link',
549
+ 'title' => '<a href="https://cleantalk.org/my/?user_token='.$apbct->user_token.'&utm_source=wp-backend&utm_medium=admin-bar&cp_mode=antispam " target="_blank">CleanTalk '.__('dashboard', 'cleantalk-spam-protect').'</a>',
550
+ 'parent' => 'ct_parent_node'
551
+ ));
552
+ }
553
+
554
+ $wp_admin_bar->add_node( array(
555
+ 'id' => 'ct_settings_link',
556
+ 'title' => '<a href="'.$apbct->settings_link.'">'.__('Settings', 'cleantalk-spam-protect').'</a>',
557
+ 'parent' => 'ct_parent_node'
558
+ ));
559
+
560
+ // add a child item to our parent item. Bulk checks.
561
+ if(!is_network_admin()){
562
+ $args = array(
563
+ 'id' => 'ct_settings_bulk_comments',
564
+ 'title' => '<hr style="margin-top: 7px;" /><a href="edit-comments.php?page=ct_check_spam" title="'.__('Bulk spam comments removal tool.', 'cleantalk-spam-protect').'">'.__('Check comments for spam', 'cleantalk-spam-protect').'</a>',
565
+ 'parent' => 'ct_parent_node'
566
+ );
567
+ }
568
+ $wp_admin_bar->add_node( $args );
569
+
570
+ // add a child item to our parent item. Bulk checks.
571
+ if(!is_network_admin()){
572
+ $args = array(
573
+ 'id' => 'ct_settings_bulk_users',
574
+ 'title' => '<a href="users.php?page=ct_check_users" title="Bulk spam users removal tool.">'.__('Check users for spam', 'cleantalk-spam-protect').'</a>',
575
+ 'parent' => 'ct_parent_node'
576
+ );
577
+ }
578
+ $wp_admin_bar->add_node( $args );
579
+
580
+ // User counter reset.
581
+ $args = array(
582
+ 'id' => 'ct_reset_counter',
583
+ 'title' => '<hr style="margin-top: 7px;"><a href="?ct_reset_user_counter=1" title="Reset your personal counter of submissions.">'.__('Reset first counter', 'cleantalk-spam-protect').'</a>',
584
+ 'parent' => 'ct_parent_node'
585
+ );
586
+ $wp_admin_bar->add_node( $args );// add a child item to our parent item. Counter reset.
587
+
588
+ // Reset ALL counter
589
+ $args = array(
590
+ 'id' => 'ct_reset_counters_all',
591
+ 'title' => '<a href="?ct_reset_all_counters=1" title="Reset all counters.">'.__('Reset all counters', 'cleantalk-spam-protect').'</a>',
592
+ 'parent' => 'ct_parent_node'
593
+ );
594
+ $wp_admin_bar->add_node( $args );
595
+
596
+ // Support link
597
+ if(!$apbct->white_label){
598
+ $wp_admin_bar->add_node( array(
599
+ 'id' => 'ct_admin_bar_support_link',
600
+ 'title' => '<hr style="margin-top: 7px;" /><a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">'.__('Support', 'cleantalk-spam-protect').'</a>',
601
+ 'parent' => 'ct_parent_node'
602
+ ));
603
+ }
604
+ }
605
+ }
606
+
607
+ /**
608
+ * Unmark bad words
609
+ * @param string $message
610
+ * @return string Cleat comment
611
+ */
612
+ function apbct_comment__unmark_red($message) {
613
+ $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
614
+
615
+ return $message;
616
+ }
617
+
618
+ // Ajax action feedback form comments page.
619
+ function apbct_comment__send_feedback($comment_id = null, $comment_status = null, $change_status = false, $direct_call = null){
620
+
621
+ // For AJAX call
622
+ if( ! $direct_call ){
623
+ check_ajax_referer('ct_secret_nonce', 'security');
624
+ }
625
+
626
+ $comment_id = ! $comment_id && isset( $_POST['comment_id'] ) ? $_POST['comment_id'] : false;
627
+ $comment_status = ! $comment_status && isset( $_POST['comment_status'] ) ? $_POST['comment_status'] : false;
628
+ $change_status = ! $change_status && isset( $_POST['change_status'] ) ? $_POST['change_status'] : false;
629
+
630
+ // If enter params is empty exit
631
+ if( ! $comment_id || ! $comment_status )
632
+ die();
633
+
634
+ // $comment = get_comment($comment_id, 'ARRAY_A');
635
+ $hash = get_comment_meta($comment_id, 'ct_hash', true);
636
+
637
+ // If we can send the feedback
638
+ if($hash){
639
+
640
+ // Approving
641
+ if($comment_status == '1' || $comment_status == 'approve'){
642
+ $result = ct_send_feedback($hash.":1");
643
+ // $comment['comment_content'] = apbct_comment__unmark_red($comment['comment_content']);
644
+ // wp_update_comment($comment);
645
+ $result === true ? 1 : 0;
646
+ }
647
+
648
+ // Disapproving
649
+ if($comment_status == 'spam'){
650
+ $result = ct_send_feedback($hash.":0");
651
+ $result === true ? 1 : 0;
652
+ }
653
+ }else{
654
+ $result = 'no_hash';
655
+ }
656
+
657
+ // Changing comment status(folder) if flag is set. spam || approve
658
+ if($change_status !== false)
659
+ wp_set_comment_status($comment_id, $comment_status);
660
+
661
+ if(!$direct_call){
662
+ echo !empty($result) ? $result : 0;
663
+ die();
664
+ }else{
665
+
666
+ }
667
+ }
668
+
669
+ // Ajax action feedback form user page.
670
+ function apbct_user__send_feedback($user_id = null, $status = null, $direct_call = null){
671
+
672
+ check_ajax_referer('ct_secret_nonce', 'security');
673
+
674
+ if(!$direct_call){
675
+ $user_id = $_POST['user_id'];
676
+ $status = $_POST['status'];
677
+ }
678
+
679
+ $hash = get_user_meta($user_id, 'ct_hash', true);
680
+
681
+ if($hash){
682
+ if($status == 'approve' || $status == 1){
683
+ $result = ct_send_feedback($hash.":1");
684
+ $result === true ? 1 : 0;
685
+ }
686
+ if($status == 'spam' || $status == 'disapprove' || $status == 0){
687
+ $result = ct_send_feedback($hash.":0");
688
+ $result === true ? 1 : 0;
689
+ }
690
+ }else{
691
+ $result = 'no_hash';
692
+ }
693
+
694
+ if(!$direct_call){
695
+ echo !empty($result) ? $result : 0;
696
+ die();
697
+ }else{
698
+
699
+ }
700
+
701
+ }
702
+
703
+ /**
704
+ * Send feedback when user deleted
705
+ * @return null
706
+ */
707
+ function apbct_user__delete__hook($user_id, $reassign = null){
708
+
709
+ $hash = get_user_meta($user_id, 'ct_hash', true);
710
+ if ($hash !== '') {
711
+ ct_feedback($hash, 0);
712
+ }
713
  }
inc/cleantalk-settings.php CHANGED
@@ -1,1684 +1,1712 @@
1
- <?php
2
-
3
- /**
4
- * Admin action 'admin_menu' - Add the admin options page
5
- */
6
- function apbct_settings_add_page() {
7
-
8
- global $apbct, $pagenow;
9
-
10
- $parent_slug = is_network_admin() ? 'settings.php' : 'options-general.php';
11
- $callback = is_network_admin() ? 'apbct_settings__display__network' : 'apbct_settings__display';
12
-
13
- // Adding settings page
14
- add_submenu_page(
15
- $parent_slug,
16
- $apbct->plugin_name.' '.__('settings'),
17
- $apbct->plugin_name,
18
- 'manage_options',
19
- 'cleantalk',
20
- $callback
21
- );
22
-
23
- if(!in_array($pagenow, array('options.php', 'options-general.php', 'settings.php', 'admin.php')))
24
- return;
25
-
26
- register_setting('cleantalk_settings', 'cleantalk_settings', 'apbct_settings__validate');
27
-
28
- $fields = array();
29
- $fields = apbct_settings__set_fileds($fields);
30
- $fields = APBCT_WPMS && is_main_site() ? apbct_settings__set_fileds__network($fields) : $fields;
31
- apbct_settings__add_groups_and_fields($fields);
32
-
33
- }
34
-
35
- function apbct_settings__set_fileds( $fields ){
36
- global $apbct;
37
-
38
- $fields = array(
39
-
40
- 'main' => array(
41
- 'title' => '',
42
- 'default_params' => array(),
43
- 'description' => '',
44
- 'html_before' => '',
45
- 'html_after' => '',
46
- 'fields' => array(
47
- 'action_buttons' => array(
48
- 'callback' => 'apbct_settings__field__action_buttons',
49
- ),
50
- 'connection_reports' => array(
51
- 'callback' => 'apbct_settings__field__statistics',
52
- ),
53
- 'api_key' => array(
54
- 'display' => !$apbct->white_label || is_main_site(),
55
- 'callback' => 'apbct_settings__field__apikey',
56
- ),
57
- ),
58
- ),
59
-
60
- 'state' => array(
61
- 'title' => '',
62
- 'default_params' => array(),
63
- 'description' => '',
64
- 'html_before' => '<hr style="width: 100%;">',
65
- 'html_after' => '',
66
- 'fields' => array(
67
- 'state' => array(
68
- 'callback' => 'apbct_settings__field__state',
69
- ),
70
- ),
71
- ),
72
-
73
- 'debug' => array(
74
- 'title' => '',
75
- 'default_params' => array(),
76
- 'description' => '',
77
- 'html_before' => '',
78
- 'html_after' => '',
79
- 'fields' => array(
80
- 'state' => array(
81
- 'callback' => 'apbct_settings__field__debug',
82
- ),
83
- ),
84
- ),
85
-
86
- // Different
87
- 'different' => array(
88
- 'title' => '',
89
- 'default_params' => array(),
90
- 'description' => '',
91
- 'html_before' => '<hr>',
92
- 'html_after' => '',
93
- 'fields' => array(
94
- 'spam_firewall' => array(
95
- 'type' => 'checkbox',
96
- 'title' => __('SpamFireWall', 'cleantalk-spam-protect'),
97
- 'description' => __("This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.", 'cleantalk-spam-protect'),
98
- 'childrens' => array('sfw__anti_flood', 'sfw__anti_crawler'),
99
- ),
100
- 'sfw__anti_flood' => array(
101
- 'type' => 'checkbox',
102
- 'title' => __('Anti-Flood', 'cleantalk-spam-protect'),
103
- 'class' => 'apbct_settings-field_wrapper--sub',
104
- 'parent' => 'spam_firewall',
105
- 'childrens' => array('sfw__anti_flood__view_limit',),
106
- 'description' => __('Shows SpamFireWall page for bot which are trying to scan your website. Look for the page limit setting below.', 'cleantalk-spam-protect'),
107
- ),
108
- 'sfw__anti_crawler' => array(
109
- 'type' => 'checkbox',
110
- 'title' => __('Anti-Crawler', 'cleantalk-spam-protect'),
111
- 'class' => 'apbct_settings-field_wrapper--sub',
112
- 'parent' => 'spam_firewall',
113
- 'description' => __('Plugin shows SpamFireWall stop page for any bot, except allowed bots (Google, Yahoo and etc).', 'cleantalk-spam-protect'),
114
- ),
115
- ),
116
- ),
117
-
118
- // Forms protection
119
- 'forms_protection' => array(
120
- 'title' => __('Forms to protect', 'cleantalk-spam-protect'),
121
- 'default_params' => array(),
122
- 'description' => '',
123
- 'html_before' => '<hr><br>'
124
- .'<span id="ct_adv_showhide">'
125
- .'<a href="#" class="apbct_color--gray" onclick="event.preventDefault(); apbct_show_hide_elem(\'apbct_settings__davanced_settings\');">'
126
- .__('Advanced settings', 'cleantalk-spam-protect')
127
- .'</a>'
128
- .'</span>'
129
- .'<div id="apbct_settings__davanced_settings" style="display: none;">',
130
- 'html_after' => '',
131
- 'fields' => array(
132
- 'registrations_test' => array(
133
- 'title' => __('Registration Forms', 'cleantalk-spam-protect'),
134
- 'description' => __('WordPress, BuddyPress, bbPress, S2Member, WooCommerce.', 'cleantalk-spam-protect'),
135
- ),
136
- 'comments_test' => array(
137
- 'title' => __('Comments form', 'cleantalk-spam-protect'),
138
- 'description' => __('WordPress, JetPack, WooCommerce.', 'cleantalk-spam-protect'),
139
- ),
140
- 'contact_forms_test' => array(
141
- 'title' => __('Contact forms', 'cleantalk-spam-protect'),
142
- 'description' => __('Contact Form 7, Formidable forms, JetPack, Fast Secure Contact Form, WordPress Landing Pages, Gravity Forms.', 'cleantalk-spam-protect'),
143
- ),
144
- 'general_contact_forms_test' => array(
145
- 'title' => __('Custom contact forms', 'cleantalk-spam-protect'),
146
- 'description' => __('Anti spam test for any WordPress themes or contacts forms.', 'cleantalk-spam-protect'),
147
- ),
148
- 'search_test' => array(
149
- 'title' => __('Test default Wordpress search form for spam', 'cleantalk-spam-protect'),
150
- 'description' => __('Spam protection for Search form.', 'cleantalk-spam-protect')
151
- . (!$apbct->white_label || is_main_site()
152
- ? sprintf(__('Read more about %sspam protection for Search form%s on our blog. “noindex” tag will be placed in meta derictive on search page.', 'cleantalk-spam-protect'),
153
- '<a href="https://blog.cleantalk.org/how-to-protect-website-search-from-spambots/" target="_blank">',
154
- '</a>'
155
- )
156
- : ''
157
- )
158
- ),
159
- 'check_external' => array(
160
- 'title' => __('Protect external forms', 'cleantalk-spam-protect'),
161
- 'description' => __('Turn this option on to protect forms on your WordPress that send data to third-part servers (like MailChimp).', 'cleantalk-spam-protect'),
162
- 'childrens' => array('check_external__capture_buffer'),
163
- ),
164
- 'check_external__capture_buffer' => array(
165
- 'title' => __('Capture buffer', 'cleantalk-spam-protect'),
166
- 'description' => __('This setting gives you more sophisticated and strengthened protection for external forms. But it could break plugins which use a buffer like Ninja Forms.', 'cleantalk-spam-protect'),
167
- 'class' => 'apbct_settings-field_wrapper--sub',
168
- 'parent' => 'check_external',
169
- ),
170
- 'check_internal' => array(
171
- 'title' => __('Protect internal forms', 'cleantalk-spam-protect'),
172
- 'description' => __('This option will enable protection for custom (hand-made) AJAX forms with PHP scripts handlers on your WordPress.', 'cleantalk-spam-protect'),
173
- ),
174
- ),
175
- ),
176
-
177
- // Comments and Messages
178
- 'wc' => array(
179
- 'title' => __('WooCommerce', 'cleantalk-spam-protect'),
180
- 'fields' => array(
181
- 'wc_checkout_test' => array(
182
- 'title' => __('WooCommerce checkout form', 'cleantalk-spam-protect'),
183
- 'description' => __('Anti spam test for WooCommerce checkout form.', 'cleantalk-spam-protect'),
184
- 'childrens' => array('wc_register_from_order')
185
- ),
186
- 'wc_register_from_order' => array(
187
- 'title' => __('Spam test for registration during checkout', 'cleantalk-spam-protect'),
188
- 'description' => __('Enable anti spam test for registration process which during woocommerce\'s checkout.', 'cleantalk-spam-protect'),
189
- 'parent' => 'wc_checkout_test',
190
- 'class' => 'apbct_settings-field_wrapper--sub',
191
- 'reverse_trigger' => true
192
- ),
193
- ),
194
- ),
195
-
196
- // Comments and Messages
197
- 'comments_and_messages' => array(
198
- 'title' => __('Comments and Messages', 'cleantalk-spam-protect'),
199
- 'fields' => array(
200
- 'disable_comments__all' => array(
201
- 'title' => __( 'Disable all comments', 'cleantalk-spam-protect'),
202
- 'description' => __( 'Disabling comments for all types of content.', 'cleantalk-spam-protect'),
203
- 'childrens' => array(
204
- 'disable_comments__posts',
205
- 'disable_comments__pages',
206
- 'disable_comments__media',
207
- ),
208
- 'options' => array(
209
- array( 'val' => 1, 'label' => __( 'On' ), 'childrens_enable' => 0, ),
210
- array( 'val' => 0, 'label' => __( 'Off' ), 'childrens_enable' => 1, ),
211
- ),
212
- ),
213
- 'disable_comments__posts' => array(
214
- 'title' => __( 'Disable comments for all posts', 'cleantalk-spam-protect'),
215
- 'class' => 'apbct_settings-field_wrapper--sub',
216
- 'parent' => 'disable_comments__all',
217
- 'reverse_trigger' => true,
218
- ),
219
- 'disable_comments__pages' => array(
220
- 'title' => __( 'Disable comments for all pages', 'cleantalk-spam-protect'),
221
- 'class' => 'apbct_settings-field_wrapper--sub',
222
- 'parent' => 'disable_comments__all',
223
- 'reverse_trigger' => true,
224
- ),
225
- 'disable_comments__media' => array(
226
- 'title' => __( 'Disable comments for all media', 'cleantalk-spam-protect'),
227
- 'class' => 'apbct_settings-field_wrapper--sub',
228
- 'parent' => 'disable_comments__all',
229
- 'reverse_trigger' => true,
230
- ),
231
- 'bp_private_messages' => array(
232
- 'title' => __('BuddyPress Private Messages', 'cleantalk-spam-protect'),
233
- 'description' => __('Check buddyPress private messages.', 'cleantalk-spam-protect'),
234
- ),
235
- 'remove_old_spam' => array(
236
- 'title' => __('Automatically delete spam comments', 'cleantalk-spam-protect'),
237
- 'description' => sprintf(__('Delete spam comments older than %d days.', 'cleantalk-spam-protect'), $apbct->data['spam_store_days']),
238
- ),
239
- 'remove_comments_links' => array(
240
- 'title' => __('Remove links from approved comments', 'cleantalk-spam-protect'),
241
- 'description' => __('Remove links from approved comments. Replace it with "[Link deleted]"', 'cleantalk-spam-protect'),
242
- ),
243
- 'show_check_links' => array(
244
- 'title' => __('Show links to check Emails, IPs for spam', 'cleantalk-spam-protect'),
245
- 'description' => __('Shows little icon near IP addresses and Emails allowing you to check it via CleanTalk\'s database.', 'cleantalk-spam-protect'),
246
- 'display' => !$apbct->white_label,
247
- ),
248
- 'manage_comments_on_public_page' => array(
249
- 'title' => __('Manage comments on public pages', 'cleantalk-spam-protect'),
250
- 'description' => __('Allows administrators to manage comments on public post\'s pages with small interactive menu.', 'cleantalk-spam-protect'),
251
- 'display' => !$apbct->white_label,
252
- ),
253
- ),
254
- ),
255
-
256
- // Data Processing
257
- 'data_processing' => array(
258
- 'title' => __('Data Processing', 'cleantalk-spam-protect'),
259
- 'fields' => array(
260
- 'protect_logged_in' => array(
261
- 'title' => __("Protect logged in Users", 'cleantalk-spam-protect'),
262
- 'description' => __('Turn this option on to check for spam any submissions (comments, contact forms and etc.) from registered Users.', 'cleantalk-spam-protect'),
263
- ),
264
- 'check_comments_number' => array(
265
- 'title' => __("Don't check trusted user's comments", 'cleantalk-spam-protect'),
266
- 'description' => sprintf(__("Don't check comments for users with above %d comments.", 'cleantalk-spam-protect'), defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3),
267
- ),
268
- 'use_ajax' => array(
269
- 'title' => __('Use AJAX for JavaScript check', 'cleantalk-spam-protect'),
270
- 'description' => __('Options helps protect WordPress against spam with any caching plugins. Turn this option on to avoid issues with caching plugins.', 'cleantalk-spam-protect'),
271
- ),
272
- 'use_static_js_key' => array(
273
- 'title' => __('Use static keys for JS check.', 'cleantalk-spam-protect'),
274
- 'description' => __('Could help if you have cache for AJAX requests and you are dealing with false positives. Slightly decreases protection quality. Auto - Static key will be used if caching plugin is spotted.', 'cleantalk-spam-protect'),
275
- 'options' => array(
276
- array('val' => 1, 'label' => __('On'), ),
277
- array('val' => 0, 'label' => __('Off'), ),
278
- array('val' => -1, 'label' => __('Auto'),),
279
- ),
280
- ),
281
- 'general_postdata_test' => array(
282
- 'title' => __('Check all post data', 'cleantalk-spam-protect'),
283
- 'description' => __('Check all POST submissions from website visitors. Enable this option if you have spam misses on website.', 'cleantalk-spam-protect')
284
- .(!$apbct->white_label
285
- ? __(' Or you don`t have records about missed spam here:', 'cleantalk-spam-protect') . '&nbsp;' . '<a href="https://cleantalk.org/my/?user_token='.$apbct->user_token.'&utm_source=wp-backend&utm_medium=admin-bar&cp_mode=antispam" target="_blank">' . __('CleanTalk dashboard', 'cleantalk-spam-protect') . '</a>.'
286
- : ''
287
- )
288
- .'<br />' . __('СAUTION! Option can catch POST requests in WordPress backend', 'cleantalk-spam-protect'),
289
- ),
290
- 'set_cookies' => array(
291
- 'title' => __("Set cookies", 'cleantalk-spam-protect'),
292
- 'description' => __('Turn this option off to deny plugin generates any cookies on website front-end. This option is helpful if you use Varnish. But most of contact forms will not be protected if the option is turned off! <b>Warning: We strongly recommend you to enable this otherwise it could cause false positives spam detection.</b>', 'cleantalk-spam-protect'),
293
- 'childrens' => array('set_cookies__sessions'),
294
- ),
295
- 'set_cookies__sessions' => array(
296
- 'title' => __('Use alternative mechanism for cookies', 'cleantalk-spam-protect'),
297
- 'description' => __('Doesn\'t use cookie or PHP sessions. Collect data for all types of bots.', 'cleantalk-spam-protect'),
298
- 'parent' => 'set_cookies',
299
- 'class' => 'apbct_settings-field_wrapper--sub',
300
- ),
301
- 'ssl_on' => array(
302
- 'title' => __("Use SSL", 'cleantalk-spam-protect'),
303
- 'description' => __('Turn this option on to use encrypted (SSL) connection with servers.', 'cleantalk-spam-protect'),
304
- ),
305
- 'use_buitin_http_api' => array(
306
- 'title' => __("Use Wordpress HTTP API", 'cleantalk-spam-protect'),
307
- 'description' => __('Alternative way to connect the Cloud. Use this if you have connection problems.', 'cleantalk-spam-protect'),
308
- ),
309
- ),
310
- ),
311
-
312
- // Exclusions
313
- 'exclusions' => array(
314
- 'title' => __('Exclusions', 'cleantalk-spam-protect'),
315
- 'fields' => array(
316
- 'exclusions__urls' => array(
317
- 'type' => 'text',
318
- 'title' => __('URL exclusions', 'cleantalk-spam-protect'),
319
- 'description' => __('You could type here URL you want to exclude. Use comma as separator.', 'cleantalk-spam-protect'),
320
- ),
321
- 'exclusions__urls__use_regexp' => array(
322
- 'type' => 'checkbox',
323
- 'title' => __('Use Regular Expression in URL Exclusions', 'cleantalk-spam-protect'),
324
- ),
325
- 'exclusions__fields' => array(
326
- 'type' => 'text',
327
- 'title' => __('Field name exclusions', 'cleantalk-spam-protect'),
328
- 'description' => __('You could type here fields names you want to exclude. Use comma as separator.', 'cleantalk-spam-protect'),
329
- ),
330
- 'exclusions__fields__use_regexp' => array(
331
- 'type' => 'checkbox',
332
- 'title' => __('Use Regular Expression in Field Exclusions', 'cleantalk-spam-protect'),
333
- ),
334
- 'exclusions__roles' => array(
335
- 'type' => 'select',
336
- 'multiple' => true,
337
- 'options_callback' => 'apbct_get_all_roles',
338
- 'options_callback_params' => array(true),
339
- 'description' => __('Roles which bypass spam test. Hold CTRL to select multiple roles.', 'cleantalk-spam-protect'),
340
- ),
341
- ),
342
- ),
343
-
344
- // Admin bar
345
- 'admin_bar' => array(
346
- 'title' => __('Admin bar', 'cleantalk-spam-protect'),
347
- 'default_params' => array(),
348
- 'description' => '',
349
- 'html_before' => '',
350
- 'html_after' => '',
351
- 'fields' => array(
352
- 'show_adminbar' => array(
353
- 'title' => __('Show statistics in admin bar', 'cleantalk-spam-protect'),
354
- 'description' => __('Show/hide icon in top level menu in WordPress backend. The number of submissions is being counted for past 24 hours.', 'cleantalk-spam-protect'),
355
- 'childrens' => array('all_time_counter','daily_counter','sfw_counter'),
356
- ),
357
- 'all_time_counter' => array(
358
- 'title' => __('Show All-time counter', 'cleantalk-spam-protect'),
359
- 'description' => __('Display all-time requests counter in the admin bar. Counter displays number of requests since plugin installation.', 'cleantalk-spam-protect'),
360
- 'parent' => 'show_adminbar',
361
- 'class' => 'apbct_settings-field_wrapper--sub',
362
- ),
363
- 'daily_counter' => array(
364
- 'title' => __('Show 24 hours counter', 'cleantalk-spam-protect'),
365
- 'description' => __('Display daily requests counter in the admin bar. Counter displays number of requests of the past 24 hours.', 'cleantalk-spam-protect'),
366
- 'parent' => 'show_adminbar',
367
- 'class' => 'apbct_settings-field_wrapper--sub',
368
- ),
369
- 'sfw_counter' => array(
370
- 'title' => __('SpamFireWall counter', 'cleantalk-spam-protect'),
371
- 'description' => __('Display SpamFireWall requests in the admin bar. Counter displays number of requests since plugin installation.', 'cleantalk-spam-protect'),
372
- 'parent' => 'show_adminbar',
373
- 'class' => 'apbct_settings-field_wrapper--sub',
374
- ),
375
- ),
376
- ),
377
-
378
- // Misc
379
- 'misc' => array(
380
- 'html_after' => '</div><br>',
381
- 'fields' => array(
382
- 'collect_details' => array(
383
- 'type' => 'checkbox',
384
- 'title' => __('Collect details about browsers', 'cleantalk-spam-protect'),
385
- 'description' => __("Checking this box you allow plugin store information about screen size and browser plugins of website visitors. The option in a beta state.", 'cleantalk-spam-protect'),
386
- ),
387
- 'send_connection_reports' => array(
388
- 'type' => 'checkbox',
389
- 'title' => __('Send connection reports', 'cleantalk-spam-protect'),
390
- 'description' => __("Checking this box you allow plugin to send the information about your connection. The option in a beta state.", 'cleantalk-spam-protect'),
391
- ),
392
- 'async_js' => array(
393
- 'type' => 'checkbox',
394
- 'title' => __('Async JavaScript loading', 'cleantalk-spam-protect'),
395
- 'description' => __('Use async loading for scripts. Warning: This could reduce filtration quality.', 'cleantalk-spam-protect'),
396
- ),
397
- 'gdpr_enabled' => array(
398
- 'type' => 'checkbox',
399
- 'title' => __('Allow to add GDPR notice via shortcode', 'cleantalk-spam-protect'),
400
- 'description' => __(' Adds small checkbox under your website form. To add it you should use the shortcode on the form\'s page: [cleantalk_gdpr_form id="FORM_ID"]', 'cleantalk-spam-protect'),
401
- 'childrens' => array('gdpr_text'),
402
- ),
403
- 'gdpr_text' => array(
404
- 'type' => 'text',
405
- 'title' => __('GDPR text notice', 'cleantalk-spam-protect'),
406
- 'description' => __('This text will be added as a description to the GDPR checkbox.', 'cleantalk-spam-protect'),
407
- 'parent' => 'gdpr_enabled',
408
- 'class' => 'apbct_settings-field_wrapper--sub',
409
- ),
410
- 'store_urls' => array(
411
- 'type' => 'checkbox',
412
- 'title' => __('Store visited URLs', 'cleantalk-spam-protect'),
413
- 'description' => __("Plugin stores last 10 visited URLs (HTTP REFFERERS) before visitor submits form on the site. You can see stored visited URLS for each visitor in your Dashboard. Turn the option on to improve Anti-Spam protection.", 'cleantalk-spam-protect'),
414
- 'childrens' => array('store_urls__sessions'),
415
- ),
416
- 'store_urls__sessions' => array(
417
- 'type' => 'checkbox',
418
- 'title' => __('Use cookies less sessions', 'cleantalk-spam-protect'),
419
- 'description' => __('Doesn\'t use cookie or PHP sessions. Collect data for all types of bots.', 'cleantalk-spam-protect'),
420
- 'parent' => 'store_urls',
421
- 'class' => 'apbct_settings-field_wrapper--sub',
422
- ),
423
- 'comment_notify' => array(
424
- 'type' => 'checkbox',
425
- 'title' => __('Notify users with selected roles about new approved comments. Hold CTRL to select multiple roles.', 'cleantalk-spam-protect'),
426
- 'description' => sprintf(__("If enabled, overrides similar Wordpress %sdiscussion settings%s.", 'cleantalk-spam-protect'), '<a href="options-discussion.php">','</a>'),
427
- 'childrens' => array('comment_notify__roles'),
428
- ),
429
- 'comment_notify__roles' => array(
430
- 'type' => 'select',
431
- 'multiple' => true,
432
- 'parent' => 'comment_notify',
433
- 'options_callback' => 'apbct_get_all_roles',
434
- 'options_callback_params' => array(true),
435
- 'class' => 'apbct_settings-field_wrapper--sub',
436
- ),
437
- 'sfw__anti_flood__view_limit' => array(
438
- 'type' => 'text',
439
- 'title' => __('Anti-Flood Page Views Limit', 'cleantalk-spam-protect'),
440
- 'class' => 'apbct_settings-field_wrapper',
441
- 'parent' => 'sfw__anti_flood',
442
- 'description' => __('Count of page view per 1 minute before plugin shows SpamFireWall page. SpamFireWall page active for 30 second after that valid visitor (with JavaScript) passes the page to the demanded page of the site.', 'cleantalk-spam-protect'),
443
- ),
444
- 'dashboard_widget__show' => array(
445
- 'type' => 'checkbox',
446
- 'title' => __('Show Dashboard Widget', 'cleantalk-spam-protect'),
447
- ),
448
- 'complete_deactivation' => array(
449
- 'type' => 'checkbox',
450
- 'title' => __('Complete deactivation', 'cleantalk-spam-protect'),
451
- 'description' => __('Leave no trace in the system after deactivation.', 'cleantalk-spam-protect'),
452
- ),
453
-
454
- ),
455
- ),
456
- );
457
-
458
- return $fields;
459
- }
460
-
461
- function apbct_settings__set_fileds__network( $fields ){
462
- global $apbct;
463
- $additional_fields = array(
464
- 'main' => array(
465
- 'fields' => array(
466
- 'white_label' => array(
467
- 'type' => 'checkbox',
468
- 'title' => __('Enable White Label Mode', 'cleantalk-spam-protect'),
469
- 'description' => sprintf(__("Learn more information %shere%s.", 'cleantalk-spam-protect'), '<a target="_blank" href="https://cleantalk.org/ru/help/hosting-white-label">', '</a>'),
470
- 'childrens' => array( 'white_label__hoster_key', 'white_label__plugin_name', 'allow_custom_key', ),
471
- 'disabled' => defined('CLEANTALK_ACCESS_KEY'),
472
- 'network' => true,
473
- ),
474
- 'white_label__hoster_key' => array(
475
- 'title' => __('Hoster API Key', 'cleantalk-spam-protect'),
476
- 'description' => sprintf(__("You can get it in %sCleantalk's Control Panel%s", 'cleantalk-spam-protect'), '<a target="_blank" href="https://cleantalk.org/my/profile">', '</a>'),
477
- 'type' => 'text',
478
- 'parent' => 'white_label',
479
- 'class' => 'apbct_settings-field_wrapper--sub',
480
- 'network' => true,
481
- 'required' => true,
482
- ),
483
- 'white_label__plugin_name' => array(
484
- 'title' => __('Plugin name', 'cleantalk-spam-protect'),
485
- 'description' => sprintf(__("Specify plugin name. Leave empty for deafult %sAntispam by Cleantalk%s", 'cleantalk-spam-protect'), '<b>', '</b>'),
486
- 'type' => 'text',
487
- 'parent' => 'white_label',
488
- 'class' => 'apbct_settings-field_wrapper--sub',
489
- 'network' => true,
490
- 'required' => true,
491
- ),
492
- 'allow_custom_key' => array(
493
- 'type' => 'checkbox',
494
- 'title' => __('Allow users to use other key', 'cleantalk-spam-protect'),
495
- 'description' => __('Allow users to use different Access key in their plugin settings on child blogs. They could use different CleanTalk account.', 'cleantalk-spam-protect')
496
- . (defined('CLEANTALK_ACCESS_KEY')
497
- ? ' <span style="color: red">'
498
- . __('Constant <b>CLEANTALK_ACCESS_KEY</b> is set. All websites will use API key from this constant. Look into wp-config.php', 'cleantalk-spam-protect')
499
- . '<br>'
500
- . __('You are not able to use white label mode while <b>CLEANTALK_ACCESS_KEY</b> is defined.', 'cleantalk-spam-protect')
501
- . '</span>'
502
- : ''
503
- ),
504
- 'display' => APBCT_WPMS && is_main_site(),
505
- 'disabled' => $apbct->network_settings['white_label'],
506
- 'network' => true,
507
- ),
508
- 'allow_custom_settings' => array(
509
- 'type' => 'checkbox',
510
- 'title' => __('Allow users to manage plugin settings', 'cleantalk-spam-protect'),
511
- 'description' => __('Allow to change settings on child sites.', 'cleantalk-spam-protect'),
512
- 'display' => APBCT_WPMS && is_main_site(),
513
- 'network' => true,
514
- ),
515
- 'use_settings_template' => array(
516
- 'type' => 'checkbox',
517
- 'title' => __('Use settings template', 'cleantalk-spam-protect'),
518
- 'description' => __("Use the current settings template for child sites.", 'cleantalk-spam-protect'),
519
- 'childrens' => array( 'use_settings_template_apply_for_new', 'use_settings_template_apply_for_current'),
520
- 'network' => true,
521
- ),
522
- 'use_settings_template_apply_for_new' => array(
523
- 'type' => 'checkbox',
524
- 'title' => __('Apply for newly added sites.', 'cleantalk-spam-protect'),
525
- 'description' => __("The newly added site will have the same preset settings template.", 'cleantalk-spam-protect'),
526
- 'parent' => 'use_settings_template',
527
- 'class' => 'apbct_settings-field_wrapper--sub',
528
- 'network' => true,
529
- ),
530
- 'use_settings_template_apply_for_current' => array(
531
- 'type' => 'checkbox',
532
- 'title' => __('Apply for current sites.', 'cleantalk-spam-protect'),
533
- 'description' => __("Apply current settings template for selected sites.", 'cleantalk-spam-protect'),
534
- 'parent' => 'use_settings_template',
535
- 'childrens' => array( 'use_settings_template_apply_for_current_list_sites'),
536
- 'class' => 'apbct_settings-field_wrapper--sub',
537
- 'network' => true,
538
- ),
539
- 'use_settings_template_apply_for_current_list_sites' => array(
540
- 'type' => 'select',
541
- 'multiple' => true,
542
- 'options_callback' => 'apbct_get_all_child_domains',
543
- 'options_callback_params' => array(true),
544
- 'class' => 'apbct_settings-field_wrapper--sub',
545
- 'parent' => 'use_settings_template_apply_for_current',
546
- 'description' => __('Sites to apply settings. Hold CTRL to select multiple sites.', 'cleantalk-spam-protect'),
547
- 'network' => true,
548
- ),
549
- )
550
- )
551
- );
552
-
553
- $fields = array_merge_recursive($fields, $additional_fields);
554
-
555
- return $fields;
556
-
557
- }
558
-
559
- function apbct_settings__add_groups_and_fields( $fields ){
560
-
561
- global $apbct;
562
-
563
- $apbct->settings_fields_in_groups = $fields;
564
-
565
- $field_default_params = array(
566
- 'callback' => 'apbct_settings__field__draw',
567
- 'type' => 'radio',
568
- 'options' => array(
569
- array('val' => 1, 'label' => __('On'), 'childrens_enable' => 1, ),
570
- array('val' => 0, 'label' => __('Off'), 'childrens_enable' => 0, ),
571
- ),
572
- 'def_class' => 'apbct_settings-field_wrapper',
573
- 'class' => '',
574
- 'parent' => '',
575
- 'childrens' => array(),
576
- 'hide' => array(),
577
- // 'title' => 'Default title',
578
- // 'description' => 'Default description',
579
- 'display' => true, // Draw settings or not
580
- 'reverse_trigger' => false, // How to allow child settings. Childrens are opened when the parent triggered "ON". This is overrides by this option
581
- 'multiple' => false,
582
- 'description' => '',
583
- 'network' => false,
584
- 'disabled' => false,
585
- 'required' => false,
586
- );
587
-
588
- foreach($apbct->settings_fields_in_groups as $group_name => $group){
589
-
590
- add_settings_section('apbct_section__'.$group_name, '', 'apbct_section__'.$group_name, 'cleantalk-spam-protect');
591
-
592
- foreach($group['fields'] as $field_name => $field){
593
-
594
- // Normalize $field['options'] from callback function to this type array( array( 'val' => 1, 'label' => __('On'), ), )
595
- if(!empty($field['options_callback'])){
596
- $options = call_user_func_array($field['options_callback'], !empty($field['options_callback_params']) ? $field['options_callback_params'] : array());
597
- foreach ($options as &$option){
598
- $option = array('val' => $option, 'label' => $option);
599
- } unset($option);
600
- $field['options'] = $options;
601
- }
602
-
603
- $params = !empty($group['default_params'])
604
- ? array_merge($group['default_params'], $field)
605
- : array_merge($field_default_params, $field);
606
-
607
- $params['name'] = $field_name;
608
-
609
- if(!$params['display'])
610
- continue;
611
-
612
- add_settings_field(
613
- 'apbct_field__'.$field_name,
614
- '',
615
- $params['callback'],
616
- 'cleantalk',
617
- 'apbct_section__'.$group_name,
618
- $params
619
- );
620
-
621
- }
622
- }
623
- }
624
-
625
- /**
626
- * Admin callback function - Displays plugin options page
627
- */
628
- function apbct_settings__display() {
629
-
630
- global $apbct;
631
-
632
- // Title
633
- echo '<h2 class="apbct_settings-title">'.__($apbct->plugin_name, 'cleantalk-spam-protect').'</h2>';
634
-
635
- // Subtitle for IP license
636
- if($apbct->moderate_ip)
637
- echo '<h4 class="apbct_settings-subtitle apbct_color--gray">'. __('Hosting AntiSpam', 'cleantalk-spam-protect').'</h4>';
638
-
639
- echo '<form action="options.php" method="post">';
640
-
641
- apbct_settings__error__output();
642
-
643
- // Top info
644
- if(!$apbct->white_label){
645
- echo '<div style="float: right; padding: 15px 15px 5px 15px; font-size: 13px; position: relative; background: #f1f1f1;">';
646
-
647
- echo __('CleanTalk\'s tech support:', 'cleantalk-spam-protect')
648
- .'&nbsp;'
649
- .'<a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">Wordpress.org</a>.'
650
- // .' <a href="https://community.cleantalk.org/viewforum.php?f=25" target="_blank">'.__("Tech forum", 'cleantalk-spam-protect').'</a>'
651
- // .($user_token ? ", <a href='https://cleantalk.org/my/support?user_token=$user_token&cp_mode=antispam' target='_blank'>".__("Service support ", 'cleantalk-spam-protect').'</a>' : '').
652
- .'<br>';
653
- echo __('Plugin Homepage at', 'cleantalk-spam-protect').' <a href="https://cleantalk.org" target="_blank">cleantalk.org</a>.<br/>';
654
- echo '<span id="apbct_gdpr_open_modal" style="text-decoration: underline;">'.__('GDPR compliance', 'cleantalk-spam-protect').'</span><br/>';
655
- echo __('Use s@cleantalk.org to test plugin in any WordPress form.', 'cleantalk-spam-protect').'<br>';
656
- echo __('CleanTalk is registered Trademark. All rights reserved.', 'cleantalk-spam-protect').'<br/>';
657
- if($apbct->key_is_ok)
658
- echo '<b style="display: inline-block; margin-top: 10px;">'.sprintf(__('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'), '<a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">', '</a>').'</b><br />';
659
- apbct_admin__badge__get_premium();
660
- echo '<div id="gdpr_dialog" style="display: none; padding: 7px;">';
661
- apbct_settings_show_gdpr_text('print');
662
- echo '</div>';
663
- echo '</div>';
664
- }
665
-
666
- // Output spam count
667
- if($apbct->key_is_ok && apbct_api_key__is_correct()){
668
- if( $apbct->spam_count > 0 ){
669
- echo '<div class="apbct_settings-subtitle" style="top: 0; margin-bottom: 10px; width: 200px;">'
670
- . '<br>'
671
- . '<span>'
672
- . sprintf(
673
- __( '%s has blocked <b>%s</b> spam.', 'cleantalk-spam-protect' ),
674
- $apbct->plugin_name,
675
- number_format( $apbct->spam_count, 0, ',', ' ' )
676
- )
677
- . '</span>'
678
- . '<br>'
679
- . '<br>'
680
- . '</div>';
681
- }
682
- }
683
-
684
-
685
- // Output spam count
686
- if($apbct->key_is_ok && apbct_api_key__is_correct()){
687
- if(!$apbct->white_label){
688
-
689
- // CP button
690
- echo '<a class="cleantalk_link cleantalk_link-manual" target="__blank" href="https://cleantalk.org/my?user_token='.$apbct->user_token.'&cp_mode=antispam">'
691
- .__('Click here to get anti-spam statistics', 'cleantalk-spam-protect')
692
- .'</a>';
693
- echo '&nbsp;&nbsp;';
694
-
695
- }
696
- }
697
-
698
- if( apbct_api_key__is_correct() && ! $apbct->white_label ){
699
- // Sync button
700
- echo '<button type="button" class="cleantalk_link cleantalk_link-auto" id="apbct_button__sync" title="Synchronizing account status, SpamFireWall database, all kind of journals.">'
701
- . '<i class="icon-upload-cloud"></i>&nbsp;&nbsp;'
702
- . __( 'Synchronize with Cloud', 'security-malware-firewall' )
703
- . '<img style="margin-left: 10px;" class="apbct_preloader_button" src="' . APBCT_URL_PATH . '/inc/images/preloader2.gif" />'
704
- . '<img style="margin-left: 10px;" class="apbct_success --hide" src="' . APBCT_URL_PATH . '/inc/images/yes.png" />'
705
- . '</button>';
706
- echo '&nbsp;&nbsp;';
707
- }
708
-
709
- // Output spam count
710
- if($apbct->key_is_ok && apbct_api_key__is_correct()){
711
- if(!$apbct->white_label){
712
-
713
- // Support button
714
- echo '<a class="cleantalk_link cleantalk_link-auto" target="__blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">'.__('Support', 'cleantalk-spam-protect').'</a>';
715
- echo '&nbsp;&nbsp;';
716
- echo '<br>'
717
- . '<br>';
718
- }
719
- }
720
-
721
- settings_fields('cleantalk_settings');
722
- do_settings_fields('cleantalk', 'cleantalk_section_settings_main');
723
-
724
- foreach($apbct->settings_fields_in_groups as $group_name => $group){
725
-
726
- echo !empty($group['html_before']) ? $group['html_before'] : '';
727
- echo !empty($group['title']) ? '<h3 style="margin-left: 220px;">'.$group['title'].'</h3>' : '';
728
-
729
- do_settings_fields('cleantalk', 'apbct_section__'.$group_name);
730
-
731
- echo !empty($group['html_after']) ? $group['html_after'] : '';
732
-
733
- }
734
-
735
- echo '<br>';
736
- echo '<button name="submit" class="cleantalk_link cleantalk_link-manual" value="save_changes">'.__('Save Changes').'</button>';
737
-
738
- echo "</form>";
739
-
740
- if(!$apbct->white_label){
741
- // Translate banner for non EN locale
742
- if(substr(get_locale(), 0, 2) != 'en'){
743
- global $ct_translate_banner_template;
744
- require_once(CLEANTALK_PLUGIN_DIR.'templates/translate_banner.php');
745
- printf($ct_translate_banner_template, substr(get_locale(), 0, 2));
746
- }
747
- }
748
- }
749
-
750
- function apbct_settings__display__network(){
751
- // If it's network admin dashboard
752
- if(is_network_admin()){
753
- $site_url = get_site_option('siteurl');
754
- $site_url = preg_match( '/\/$/', $site_url ) ? $site_url : $site_url . '/';
755
- $link = $site_url . 'wp-admin/options-general.php?page=cleantalk';
756
- printf("<h2>" . __("Please, enter the %splugin settings%s in main site dashboard.", 'cleantalk-spam-protect') . "</h2>", "<a href='$link'>", "</a>");
757
- return;
758
- }
759
- }
760
-
761
- function apbct_settings__error__output($return = false){
762
-
763
- global $apbct;
764
-
765
- // If have error message output error block.
766
-
767
- $out = '';
768
-
769
- if(!empty($apbct->errors) && !defined('CLEANTALK_ACCESS_KEY')){
770
-
771
- $errors = $apbct->errors;
772
-
773
- $error_texts = array(
774
- // Misc
775
- 'key_invalid' => __('Error occurred while API key validating. Error: ', 'cleantalk-spam-protect'),
776
- 'key_get' => __('Error occurred while automatically gettings access key. Error: ', 'cleantalk-spam-protect'),
777
- 'sfw_send_logs' => __('Error occurred while sending SpamFireWall logs. Error: ', 'cleantalk-spam-protect'),
778
- 'sfw_update' => __('Error occurred while updating SpamFireWall local base. Error: ' , 'cleantalk-spam-protect'),
779
- 'account_check' => __('Error occurred while checking account status. Error: ', 'cleantalk-spam-protect'),
780
- 'api' => __('Error occurred while excuting API call. Error: ', 'cleantalk-spam-protect'),
781
-
782
- // Validating settings
783
- 'settings_validate' => 'Validate Settings',
784
- 'exclusions_urls' => 'URL Exclusions',
785
- 'exclusions_fields' => 'Field Exclusions',
786
-
787
- // Unknown
788
- 'unknown' => __('Unknown error. Error: ', 'cleantalk-spam-protect'),
789
- );
790
-
791
- $errors_out = array();
792
-
793
- foreach($errors as $type => $error){
794
-
795
- if(!empty($error)){
796
-
797
- if(is_array(current($error))){
798
-
799
- foreach($error as $sub_type => $sub_error){
800
- $errors_out[$sub_type] = '';
801
- if(isset($sub_error['error_time']))
802
- $errors_out[$sub_type] .= date('Y-m-d H:i:s', $sub_error['error_time']) . ': ';
803
- $errors_out[$sub_type] .= (isset($error_texts[$type]) ? $error_texts[$type] : ucfirst($type)) . ': ';
804
- $errors_out[$sub_type] .= (isset($error_texts[$sub_type]) ? $error_texts[$sub_type] : $error_texts['unknown']) . ' ' . $sub_error['error'];
805
- }
806
- continue;
807
- }
808
-
809
- $errors_out[$type] = '';
810
- if(isset($error['error_time']))
811
- $errors_out[$type] .= date('Y-m-d H:i:s', $error['error_time']) . ': ';
812
- $errors_out[$type] .= (isset($error_texts[$type]) ? $error_texts[$type] : $error_texts['unknown']) . ' ' . (isset($error['error']) ? $error['error'] : '');
813
-
814
- }
815
- }
816
-
817
- if(!empty($errors_out)){
818
- $out .= '<div id="apbctTopWarning" class="error" style="position: relative;">'
819
- .'<h3 style="display: inline-block;">'.__('Errors:', 'cleantalk-spam-protect').'</h3>';
820
- foreach($errors_out as $value){
821
- $out .= '<h4>'.$value.'</h4>';
822
- }
823
- $out .= !$apbct->white_label
824
- ? '<h4 style="text-align: unset;">'.sprintf(__('You can get support any time here: %s.', 'cleantalk-spam-protect'), '<a target="blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">https://wordpress.org/support/plugin/cleantalk-spam-protect</a>').'</h4>'
825
- : '';
826
- $out .= '</div>';
827
- }
828
- }
829
-
830
- if($return) return $out; else echo $out;
831
- }
832
-
833
- function apbct_settings__field__debug(){
834
-
835
- global $apbct;
836
-
837
- if($apbct->debug){
838
-
839
- echo '<hr /><h2>Debug:</h2>';
840
- echo '<h4>Constants:</h4>';
841
- echo 'CLEANTALK_AJAX_USE_BUFFER '. (defined('CLEANTALK_AJAX_USE_BUFFER') ? (CLEANTALK_AJAX_USE_BUFFER ? 'true' : 'flase') : 'NOT_DEFINED')."<br>";
842
- echo 'CLEANTALK_AJAX_USE_FOOTER_HEADER '. (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') ? (CLEANTALK_AJAX_USE_FOOTER_HEADER ? 'true' : 'flase') : 'NOT_DEFINED')."<br>";
843
- echo 'CLEANTALK_ACCESS_KEY '. (defined('CLEANTALK_ACCESS_KEY') ? (CLEANTALK_ACCESS_KEY ? CLEANTALK_ACCESS_KEY : 'flase') : 'NOT_DEFINED')."<br>";
844
- echo 'CLEANTALK_CHECK_COMMENTS_NUMBER '. (defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? (CLEANTALK_CHECK_COMMENTS_NUMBER ? CLEANTALK_CHECK_COMMENTS_NUMBER : 0) : 'NOT_DEFINED')."<br>";
845
- echo 'CLEANTALK_CHECK_MESSAGES_NUMBER '. (defined('CLEANTALK_CHECK_MESSAGES_NUMBER') ? (CLEANTALK_CHECK_MESSAGES_NUMBER ? CLEANTALK_CHECK_MESSAGES_NUMBER : 0) : 'NOT_DEFINED')."<br>";
846
- echo 'CLEANTALK_PLUGIN_DIR '. (defined('CLEANTALK_PLUGIN_DIR') ? (CLEANTALK_PLUGIN_DIR ? CLEANTALK_PLUGIN_DIR : 'flase') : 'NOT_DEFINED')."<br>";
847
- echo 'WP_ALLOW_MULTISITE '. (defined('WP_ALLOW_MULTISITE') ? (WP_ALLOW_MULTISITE ? 'true' : 'flase') : 'NOT_DEFINED');
848
-
849
- echo "<h4>Debug log: <button type='submit' value='debug_drop' name='submit' style='font-size: 11px; padding: 1px;'>Drop debug data</button></h4>";
850
- echo "<div style='height: 500px; width: 80%; overflow: auto;'>";
851
-
852
- $output = print_r($apbct->debug, true);
853
- $output = str_replace("\n", "<br>", $output);
854
- $output = preg_replace("/[^\S]{4}/", "&nbsp;&nbsp;&nbsp;&nbsp;", $output);
855
- echo "$output";
856
-
857
- echo "</div>";
858
-
859
- }
860
- }
861
-
862
- function apbct_settings__field__state(){
863
-
864
- global $apbct;
865
-
866
- $path_to_img = plugin_dir_url(__FILE__) . "images/";
867
-
868
- $img = $path_to_img."yes.png";
869
- $img_no = $path_to_img."no.png";
870
- $img_no_gray = $path_to_img."no_gray.png";
871
- $preloader = $path_to_img."preloader.gif";
872
- $color="black";
873
-
874
- if( ! $apbct->key_is_ok ){
875
- $img=$path_to_img."no.png";
876
- $img_no=$path_to_img."no.png";
877
- $color="black";
878
- }
879
-
880
- if(!apbct_api_key__is_correct($apbct->api_key)){
881
- $img = $path_to_img."yes_gray.png";
882
- $img_no = $path_to_img."no_gray.png";
883
- $color="gray";
884
- }
885
-
886
- if($apbct->moderate_ip){
887
- $img = $path_to_img."yes.png";
888
- $img_no = $path_to_img."no.png";
889
- $color="black";
890
- }
891
-
892
- if( $apbct->moderate == 0 ){
893
- $img = $path_to_img."no.png";
894
- $img_no = $path_to_img."no.png";
895
- $color="black";
896
- }
897
-
898
- print '<div class="apbct_settings-field_wrapper" style="color:'.$color.'">';
899
-
900
- print '<h2>'.__('Protection is active', 'cleantalk-spam-protect').'</h2>';
901
-
902
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['registrations_test'] == 1 ? $img : $img_no).'"/>'.__('Registration forms', 'cleantalk-spam-protect');
903
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['comments_test'] == 1 ? $img : $img_no).'"/>'.__('Comments forms', 'cleantalk-spam-protect');
904
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['contact_forms_test'] == 1 ? $img : $img_no).'"/>'.__('Contact forms', 'cleantalk-spam-protect');
905
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['general_contact_forms_test'] == 1 ? $img : $img_no).'"/>'.__('Custom contact forms', 'cleantalk-spam-protect');
906
- if(!$apbct->white_label || is_main_site())
907
- echo '<img class="apbct_status_icon" src="'.($apbct->data['moderate'] == 1 ? $img : $img_no).'"/>'
908
- .'<a style="color: black" href="https://blog.cleantalk.org/real-time-email-address-existence-validation/">'.__('Validate email for existence', 'cleantalk-spam-protect').'</a>';
909
- // Autoupdate status
910
- if($apbct->notice_auto_update && (!$apbct->white_label || is_main_site())){
911
- echo '<img class="apbct_status_icon" src="'.($apbct->auto_update == 1 ? $img : ($apbct->auto_update == -1 ? $img_no : $img_no_gray)).'"/>'.__('Auto update', 'cleantalk-spam-protect')
912
- .' <sup><a href="https://cleantalk.org/help/cleantalk-auto-update" target="_blank">?</a></sup>';
913
- }
914
-
915
- // WooCommerce
916
- if(class_exists('WooCommerce'))
917
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['wc_checkout_test'] == 1 ? $img : $img_no).'"/>'.__('WooCommerce checkout form', 'cleantalk-spam-protect');
918
- if($apbct->moderate_ip)
919
- print "<br /><br />The anti-spam service is paid by your hosting provider. License #".$apbct->data['ip_license'].".<br />";
920
-
921
- print "</div>";
922
- }
923
-
924
- /**
925
- * Admin callback function - Displays inputs of 'apikey' plugin parameter
926
- */
927
- function apbct_settings__field__apikey(){
928
-
929
- global $apbct;
930
-
931
- echo '<div id="cleantalk_apikey_wrapper" class="apbct_settings-field_wrapper">';
932
-
933
- // Using key from Main site, or from CLEANTALK_ACCESS_KEY constant
934
- if(APBCT_WPMS && !is_main_site() && (!$apbct->allow_custom_key || defined('CLEANTALK_ACCESS_KEY'))){
935
- _e('<h3>Key is provided by Super Admin.</h3>', 'cleantalk-spam-protect');
936
- return;
937
- }
938
-
939
- echo '<label class="apbct_settings__label" for="cleantalk_apkey">' . __('Access key', 'cleantalk-spam-protect') . '</label>';
940
-
941
- echo '<input
942
- id="apbct_setting_apikey"
943
- class="apbct_setting_text apbct_setting---apikey"
944
- type="text"
945
- name="cleantalk_settings[apikey]"
946
- value="'
947
- . ($apbct->key_is_ok
948
- ? str_repeat('*', strlen($apbct->api_key))
949
- : $apbct->api_key
950
- )
951
- . '"
952
- key="' . $apbct->api_key . '"
953
- size="20"
954
- placeholder="' . __('Enter the key', 'cleantalk-spam-protect') . '"'
955
- . ' />';
956
-
957
- // Show account name associated with key
958
- if(!empty($apbct->data['account_name_ob'])){
959
- echo '<div class="apbct_display--none">'
960
- . sprintf( __('Account at cleantalk.org is %s.', 'cleantalk-spam-protect'),
961
- '<b>'.$apbct->data['account_name_ob'].'</b>'
962
- )
963
- . '</div>';
964
- };
965
-
966
- // Show key button
967
- if((apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok)){
968
- echo '<a id="apbct_showApiKey" class="ct_support_link" style="display: block" href="#">'
969
- . __('Show the access key', 'cleantalk-spam-protect')
970
- . '</a>';
971
-
972
- // "Auto Get Key" buttons. License agreement
973
- }else{
974
-
975
- echo '<br /><br />';
976
-
977
- // Auto get key
978
- if(!$apbct->ip_license){
979
- echo '<button class="cleantalk_link cleantalk_link-manual apbct_setting---get_key_auto" name="submit" type="submit" value="get_key_auto">'
980
- .__('Get Access Key Automatically', 'cleantalk-spam-protect')
981
- .'</button>';
982
- echo '<input type="hidden" id="ct_admin_timezone" name="ct_admin_timezone" value="null" />';
983
- echo '<br />';
984
- echo '<br />';
985
- }
986
-
987
- // Warnings and GDPR
988
- printf( __('Admin e-mail (%s) will be used for registration, if you want to use other email please %sGet Access Key Manually%s.', 'cleantalk-spam-protect'),
989
- ct_get_admin_email(),
990
- '<a class="apbct_color--gray" target="__blank" href="'
991
- . sprintf( 'https://cleantalk.org/register?platform=wordpress&email=%s&website=%s',
992
- urlencode(ct_get_admin_email()),
993
- urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))
994
- )
995
- . '">',
996
- '</a>'
997
- );
998
-
999
- // License agreement
1000
- if(!$apbct->ip_license){
1001
- echo '<div>';
1002
- echo '<input checked type="checkbox" id="license_agreed" onclick="apbctSettingsDependencies(\'apbct_setting---get_key_auto\');"/>';
1003
- echo '<label for="spbc_license_agreed">';
1004
- printf( __('I accept %sLicense Agreement%s.', 'cleantalk-spam-protect'),
1005
- '<a class = "apbct_color--gray" href="https://cleantalk.org/publicoffer" target="_blank">',
1006
- '</a>'
1007
- );
1008
- echo "</label>";
1009
- echo '</div>';
1010
- }
1011
- }
1012
-
1013
- echo '</div>';
1014
- }
1015
-
1016
- function apbct_settings__field__action_buttons(){
1017
-
1018
- global $apbct;
1019
-
1020
- $links = apply_filters(
1021
- 'apbct_settings_action_buttons',
1022
- array(
1023
- '<a href="edit-comments.php?page=ct_check_spam" class="ct_support_link">' . __('Check comments for spam', 'cleantalk-spam-protect') . '</a>',
1024
- '<a href="users.php?page=ct_check_users" class="ct_support_link">' . __('Check users for spam', 'cleantalk-spam-protect') . '</a>',
1025
- '<a href="#" class="ct_support_link" onclick="apbct_show_hide_elem(\'apbct_statistics\')">' . __('Statistics & Reports', 'cleantalk-spam-protect') . '</a>',
1026
- )
1027
- );
1028
-
1029
- echo '<div class="apbct_settings-field_wrapper">';
1030
-
1031
- if( apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok ){
1032
- echo '<div>';
1033
- foreach( $links as $link ) {
1034
- echo $link . '&nbsp;&nbsp;&nbsp;&nbsp;';
1035
- }
1036
- echo '</div>';
1037
- }
1038
-
1039
- echo '</div>';
1040
- }
1041
-
1042
- function apbct_settings__field__statistics() {
1043
-
1044
- global $apbct, $wpdb;
1045
-
1046
- echo '<div id="apbct_statistics" class="apbct_settings-field_wrapper" style="display: none;">';
1047
-
1048
- // Last request
1049
- printf(
1050
- __('Last spam check request to %s server was at %s.', 'cleantalk-spam-protect'),
1051
- $apbct->stats['last_request']['server'] ? $apbct->stats['last_request']['server'] : __('unknown', 'cleantalk-spam-protect'),
1052
- $apbct->stats['last_request']['time'] ? date('M d Y H:i:s', $apbct->stats['last_request']['time']) : __('unknown', 'cleantalk-spam-protect')
1053
- );
1054
- echo '<br>';
1055
-
1056
- // Avarage time request
1057
- printf(
1058
- __('Average request time for past 7 days: %s seconds.', 'cleantalk-spam-protect'),
1059
- $apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time']
1060
- ? round($apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time'], 3)
1061
- : __('unknown', 'cleantalk-spam-protect')
1062
- );
1063
- echo '<br>';
1064
-
1065
- // SFW last die
1066
- printf(
1067
- __('Last time SpamFireWall was triggered for %s IP at %s', 'cleantalk-spam-protect'),
1068
- $apbct->stats['last_sfw_block']['ip'] ? $apbct->stats['last_sfw_block']['ip'] : __('unknown', 'cleantalk-spam-protect'),
1069
- $apbct->stats['last_sfw_block']['time'] ? date('M d Y H:i:s', $apbct->stats['last_sfw_block']['time']) : __('unknown', 'cleantalk-spam-protect')
1070
- );
1071
- echo '<br>';
1072
-
1073
- // SFW last update
1074
- $sfw_netwoks_amount = $wpdb->get_results("SELECT count(*) AS cnt FROM `".$wpdb->prefix."cleantalk_sfw`", ARRAY_A);
1075
- printf(
1076
- __('SpamFireWall was updated %s. Now contains %s entries.', 'cleantalk-spam-protect'),
1077
- $apbct->stats['sfw']['last_update_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_update_time']) : __('unknown', 'cleantalk-spam-protect'),
1078
- isset($sfw_netwoks_amount[0]['cnt']) ? $sfw_netwoks_amount[0]['cnt'] : __('unknown', 'cleantalk-spam-protect')
1079
- );
1080
- echo '<br>';
1081
-
1082
- // SFW last sent logs
1083
- printf(
1084
- __('SpamFireWall sent %s events at %s.', 'cleantalk-spam-protect'),
1085
- $apbct->stats['sfw']['last_send_amount'] ? $apbct->stats['sfw']['last_send_amount'] : __('unknown', 'cleantalk-spam-protect'),
1086
- $apbct->stats['sfw']['last_send_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_send_time']) : __('unknown', 'cleantalk-spam-protect')
1087
- );
1088
- echo '<br>';
1089
-
1090
- // Connection reports
1091
- if ($apbct->connection_reports){
1092
-
1093
- if ($apbct->connection_reports['negative'] == 0){
1094
- _e('There are no failed connections to server.', 'cleantalk-spam-protect');
1095
- }else{
1096
- echo "<table id='negative_reports_table''>
1097
- <tr>
1098
- <td>#</td>
1099
- <td><b>Date</b></td>
1100
- <td><b>Page URL</b></td>
1101
- <td><b>Report</b></td>
1102
- <td><b>Server IP</b></td>
1103
- </tr>";
1104
- foreach($apbct->connection_reports['negative_report'] as $key => $report){
1105
- echo '<tr>'
1106
- . '<td>'.($key+1).'.</td>'
1107
- . '<td>'.$report['date'].'</td>'
1108
- . '<td>'.$report['page_url'].'</td>'
1109
- . '<td>'.$report['lib_report'].'</td>'
1110
- . '<td>'.$report['work_url'].'</td>'
1111
- . '</tr>';
1112
- }
1113
- echo "</table>";
1114
- echo '<br/>';
1115
- echo '<button'
1116
- . ' name="submit"'
1117
- . ' class="cleantalk_link cleantalk_link-manual"'
1118
- . ' value="ct_send_connection_report"'
1119
- . (!$apbct->settings['send_connection_reports'] ? ' disabled="disabled"' : '')
1120
- . '>'
1121
- .__('Send report', 'cleantalk-spam-protect')
1122
- .'</button>';
1123
- if (!$apbct->settings['send_connection_reports']){
1124
- echo '<br><br>';
1125
- _e('Please, enable "Send connection reports" setting to be able to send reports', 'cleantalk-spam-protect');
1126
- }
1127
- }
1128
-
1129
- }
1130
-
1131
- echo '<br/>';
1132
- echo 'Plugin version: ' . APBCT_VERSION;
1133
-
1134
- echo '</div>';
1135
- }
1136
- function apbct_get_all_child_domains($except_main_site = false) {
1137
- global $wpdb;
1138
- $blogs = array();
1139
- $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM '. $wpdb->blogs, OBJECT_K);
1140
-
1141
- if ($except_main_site) {
1142
- foreach ($wp_blogs as $blog) {
1143
- if ($blog->blog_id != $blog->site_id)
1144
- $blogs[] = get_blog_details( array( 'blog_id' => $blog->blog_id ) )->blogname;
1145
- }
1146
- }
1147
- return $blogs;
1148
- }
1149
- /**
1150
- * Get all current Wordpress roles, could except 'subscriber' role
1151
- *
1152
- * @param bool $except_subscriber
1153
- *
1154
- * @return array
1155
- */
1156
- function apbct_get_all_roles($except_subscriber = false) {
1157
-
1158
- global $wp_roles;
1159
-
1160
- $wp_roles = new WP_Roles();
1161
- $roles = $wp_roles->get_names();
1162
-
1163
- if($except_subscriber) {
1164
- $key = array_search( 'Subscriber', $roles );
1165
- if ( $key !== false ) {
1166
- unset( $roles[ $key ] );
1167
- }
1168
- }
1169
-
1170
- return $roles;
1171
- }
1172
-
1173
- function apbct_settings__field__draw($params = array()){
1174
-
1175
- global $apbct;
1176
-
1177
- $value = $params['network'] ? $apbct->network_settings[$params['name']] : $apbct->settings[$params['name']];
1178
- $value_parent = $params['parent']
1179
- ? ($params['network'] ? $apbct->network_settings[$params['parent']] : $apbct->settings[$params['parent']])
1180
- : false;
1181
-
1182
- // Is element is disabled
1183
- $disabled = $params['parent'] && !$value_parent ? ' disabled="disabled"' : ''; // Strait
1184
- $disabled = $params['parent'] && $params['reverse_trigger'] && !$value_parent ? ' disabled="disabled"' : $disabled; // Reverse logic
1185
- $disabled = $params['disabled'] ? ' disabled="disabled"' : $disabled; // Direct disable from params
1186
- $disabled = ! is_main_site() && $apbct->network_settings && ! $apbct->network_settings['allow_custom_settings'] ? ' disabled="disabled"' : $disabled; // Disabled by super admin on sub-sites
1187
-
1188
- $childrens = $params['childrens'] ? 'apbct_setting---' . implode(",apbct_setting---",$params['childrens']) : '';
1189
- $hide = $params['hide'] ? implode(",",$params['hide']) : '';
1190
-
1191
- echo '<div class="'.$params['def_class'].(isset($params['class']) ? ' '.$params['class'] : '').'">';
1192
-
1193
- switch($params['type']){
1194
-
1195
- // Checkbox type
1196
- case 'checkbox':
1197
- echo '<input
1198
- type="checkbox"
1199
- name="cleantalk_settings['.$params['name'].']"
1200
- id="apbct_setting_'.$params['name'].'"
1201
- value="1" '
1202
- ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1203
- .($value == '1' ? ' checked' : '')
1204
- .$disabled
1205
- .($params['required'] ? ' required="required"' : '')
1206
- .($params['childrens'] ? ' apbct_children="'. $childrens .'"' : '')
1207
- .' onchange="'
1208
- . ($params['childrens'] ? ' apbctSettingsDependencies(\''. $childrens .'\');' : '')
1209
- . ($params['hide'] ? ' apbct_show_hide_elem(\''. $hide . '\');' : '')
1210
- . '"'
1211
- .' />'
1212
- .'<label for="apbct_setting_'.$params['name'].'" class="apbct_setting-field_title--'.$params['type'].'">'
1213
- .$params['title']
1214
- .'</label>';
1215
- echo isset($params['long_description'])
1216
- ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1217
- : '';
1218
- echo '<div class="apbct_settings-field_description">'
1219
- .$params['description']
1220
- .'</div>';
1221
- break;
1222
-
1223
- // Radio type
1224
- case 'radio':
1225
-
1226
- // Title
1227
- echo isset($params['title'])
1228
- ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
1229
- : '';
1230
-
1231
- // Popup description
1232
- echo isset($params['long_description'])
1233
- ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1234
- : '';
1235
-
1236
- echo '<div class="apbct_settings-field_content apbct_settings-field_content--'.$params['type'].'">';
1237
-
1238
- echo '<div class="apbct_switchers" style="direction: ltr">';
1239
- foreach($params['options'] as $option){
1240
- echo '<input'
1241
- .' type="radio"'
1242
- ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1243
- ." id='apbct_setting_{$params['name']}__{$option['label']}'"
1244
- .' name="cleantalk_settings['.$params['name'].']"'
1245
- .' value="'.$option['val'].'"'
1246
- . $disabled
1247
- .($params['childrens']
1248
- ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\', ' . $option['childrens_enable'] . ')"'
1249
- : ''
1250
- )
1251
- .($value == $option['val'] ? ' checked' : '')
1252
- .($params['required'] ? ' required="required"' : '')
1253
- .' />';
1254
- echo '<label for="apbct_setting_'.$params['name'].'__'.$option['label'].'"> ' . $option['label'] . '</label>';
1255
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1256
- }
1257
- echo '</div>';
1258
-
1259
- echo isset($params['description'])
1260
- ? '<div class="apbct_settings-field_description">'.$params['description'].'</div>'
1261
- : '';
1262
-
1263
- echo '</div>';
1264
- break;
1265
-
1266
- // Dropdown list type
1267
- case 'select':
1268
- echo isset($params['title'])
1269
- ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
1270
- : '';
1271
- echo isset($params['long_description'])
1272
- ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1273
- : '';
1274
- echo '<select'
1275
- . ' id="apbct_setting_'.$params['name'].'"'
1276
- . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1277
- . ' name="cleantalk_settings['.$params['name'].']'.($params['multiple'] ? '[]"' : '"')
1278
- . ($params['multiple'] ? ' size="'. count($params['options']). '""' : '')
1279
- . ($params['multiple'] ? ' multiple="multiple"' : '')
1280
- . $disabled
1281
- . ($params['required'] ? ' required="required"' : '')
1282
- . ' >';
1283
-
1284
- foreach($params['options'] as $option){
1285
- echo '<option'
1286
- . ' value="' . $option['val'] . '"'
1287
- . ($params['multiple']
1288
- ? (!empty($value) && in_array($option['val'], $value) ? ' selected="selected"' : '')
1289
- : ($value == $option['val'] ? 'selected="selected"' : '')
1290
- )
1291
- .'>'
1292
- . $option['label']
1293
- . '</option>';
1294
- }
1295
-
1296
- echo '</select>';
1297
- echo isset($params['long_description'])
1298
- ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1299
- : '';
1300
- echo isset($params['description'])
1301
- ? '<div class="apbct_settings-field_description">'.$params['description'].'</div>'
1302
- : '';
1303
-
1304
- break;
1305
-
1306
- // Text type
1307
- case 'text':
1308
-
1309
- echo '<input
1310
- type="text"
1311
- id="apbct_setting_'.$params['name'].'"
1312
- name="cleantalk_settings['.$params['name'].']"'
1313
- ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1314
- .' value="'. $value .'" '
1315
- .$disabled
1316
- .($params['required'] ? ' required="required"' : '')
1317
- .($params['childrens'] ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\')"' : '')
1318
- .' />'
1319
- . '&nbsp;'
1320
- .'<label for="apbct_setting_'.$params['name'].'" class="apbct_setting-field_title--'.$params['type'].'">'
1321
- .$params['title']
1322
- .'</label>';
1323
- echo '<div class="apbct_settings-field_description">'
1324
- .$params['description']
1325
- .'</div>';
1326
- break;
1327
- }
1328
-
1329
- echo '</div>';
1330
- }
1331
-
1332
- /**
1333
- * Admin callback function - Plugin parameters validator
1334
- *
1335
- * @global \Cleantalk\ApbctWP\State $apbct
1336
- * @param array $settings Array with passed settings
1337
- * @return array Array with processed settings
1338
- */
1339
- function apbct_settings__validate($settings) {
1340
-
1341
- global $apbct;
1342
-
1343
- // If user is not allowed to manage settings. Get settings from the storage
1344
- if( ! is_main_site() && ( ! $apbct->network_settings['allow_custom_settings'] ) ){
1345
- foreach ($apbct->settings as $key => $setting){
1346
- $settings[ $key ] = $setting;
1347
- }
1348
- }
1349
-
1350
- // Set missing settings.
1351
- foreach($apbct->def_settings as $setting => $value){
1352
- if(!isset($settings[$setting])){
1353
- $settings[$setting] = null;
1354
- settype($settings[$setting], gettype($value));
1355
- }
1356
- } unset($setting, $value);
1357
-
1358
- // Set missing settings.
1359
- foreach($apbct->def_network_settings as $setting => $value){
1360
- if(!isset($settings[$setting])){
1361
- $settings[$setting] = null;
1362
- settype($settings[$setting], gettype($value));
1363
- }
1364
- } unset($setting, $value);
1365
-
1366
- //Sanitizing sfw__anti_flood__view_limit setting
1367
- $settings['sfw__anti_flood__view_limit'] = floor( intval( $settings['sfw__anti_flood__view_limit'] ) );
1368
- $settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] == 0 ? 10 : $settings['sfw__anti_flood__view_limit'] ); // Default if 0 passed
1369
- $settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] < 5 ? 5 : $settings['sfw__anti_flood__view_limit'] ); //
1370
-
1371
- // Auto getting key
1372
- if (isset($_POST['submit']) && $_POST['submit'] == 'get_key_auto'){
1373
-
1374
- $website = parse_url(get_option('siteurl'), PHP_URL_HOST).parse_url(get_option('siteurl'), PHP_URL_PATH);
1375
- $platform = 'wordpress';
1376
- $user_ip = \Cleantalk\ApbctWP\Helper::ip__get(array('real'), false);
1377
- $timezone = filter_input(INPUT_POST, 'ct_admin_timezone');
1378
- $language = apbct_get_server_variable( 'HTTP_ACCEPT_LANGUAGE' );
1379
- $wpms = APBCT_WPMS && defined('SUBDOMAIN_INSTALL') && !SUBDOMAIN_INSTALL ? true : false;
1380
- $white_label = $apbct->network_settings['white_label'] ? 1 : 0;
1381
- $hoster_api_key = $apbct->network_settings['white_label__hoster_key'] ? $apbct->network_settings['white_label__hoster_key'] : '';
1382
-
1383
- $result = \Cleantalk\ApbctWP\API::method__get_api_key(
1384
- ! is_main_site() && $apbct->white_label ? 'anti-spam-hosting' : 'antispam',
1385
- ct_get_admin_email(),
1386
- $website,
1387
- $platform,
1388
- $timezone,
1389
- $language,
1390
- $user_ip,
1391
- $wpms,
1392
- $white_label,
1393
- $hoster_api_key
1394
- );
1395
-
1396
- if(empty($result['error'])){
1397
-
1398
- if(isset($result['user_token'])){
1399
- $apbct->data['user_token'] = $result['user_token'];
1400
- }
1401
-
1402
- if(!empty($result['auth_key'])){
1403
- $settings['apikey'] = $result['auth_key'];
1404
- }
1405
-
1406
- }else{
1407
- $apbct->error_add(
1408
- 'key_get',
1409
- $result['error']
1410
- . ($apbct->white_label
1411
- ? ' <button name="submit" type="submit" class="cleantalk_link cleantalk_link-manual" value="get_key_auto">'
1412
- : ''
1413
- )
1414
- );
1415
- }
1416
- }
1417
-
1418
- // Validating API key
1419
- $settings['apikey'] = strpos($settings['apikey'], '*') === false ? $settings['apikey'] : $apbct->settings['apikey'];
1420
-
1421
- $apbct->data['key_changed'] = $settings['apikey'] !== $apbct->settings['apikey'];
1422
-
1423
- $settings['apikey'] = !empty($settings['apikey']) ? trim($settings['apikey']) : '';
1424
- $settings['apikey'] = defined( 'CLEANTALK_ACCESS_KEY') ? CLEANTALK_ACCESS_KEY : $settings['apikey'];
1425
- $settings['apikey'] = ! is_main_site() && $apbct->white_label ? $apbct->settings['apikey'] : $settings['apikey'];
1426
- $settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $settings['apikey'] : $apbct->network_settings['apikey'];
1427
- $settings['apikey'] = is_main_site() || !$settings['white_label'] ? $settings['apikey'] : $apbct->settings['apikey'];
1428
-
1429
- // Sanitize setting values
1430
- foreach ($settings as &$setting ){
1431
- if( is_scalar( $setting ) )
1432
- $setting = preg_replace( '/[<"\'>]/', '', trim( $setting ) ); // Make HTML code inactive
1433
- }
1434
-
1435
- // Validate Exclusions
1436
- // URLs
1437
- $result = apbct_settings__sanitize__exclusions($settings['exclusions__urls'], $settings['exclusions__urls__use_regexp']);
1438
- $result === false
1439
- ? $apbct->error_add( 'exclusions_urls', 'is not valid: "' . $settings['exclusions__urls'] . '"', 'settings_validate' )
1440
- : $apbct->error_delete( 'exclusions_urls', true, 'settings_validate' );
1441
- $settings['exclusions__urls'] = $result ? $result: '';
1442
-
1443
- // Fields
1444
- $result = apbct_settings__sanitize__exclusions($settings['exclusions__fields'], $settings['exclusions__fields__use_regexp']);
1445
- $result === false
1446
- ? $apbct->error_add( 'exclusions_fields', 'is not valid: "' . $settings['exclusions__fields'] . '"', 'settings_validate' )
1447
- : $apbct->error_delete( 'exclusions_fields', true, 'settings_validate' );
1448
- $settings['exclusions__fields'] = $result ? $result: '';
1449
-
1450
- // WPMS Logic.
1451
- if(APBCT_WPMS && is_main_site()){
1452
- $network_settings = array(
1453
- 'allow_custom_key' => $settings['allow_custom_key'],
1454
- 'allow_custom_settings' => $settings['allow_custom_settings'],
1455
- 'white_label' => $settings['white_label'],
1456
- 'white_label__hoster_key' => $settings['white_label__hoster_key'],
1457
- 'white_label__plugin_name' => $settings['white_label__plugin_name'],
1458
- 'use_settings_template' => $settings['use_settings_template'],
1459
- 'use_settings_template_apply_for_new' => $settings['use_settings_template_apply_for_new'],
1460
- 'use_settings_template_apply_for_current' => $settings['use_settings_template_apply_for_current'],
1461
- 'use_settings_template_apply_for_current_list_sites' => $settings['use_settings_template_apply_for_current_list_sites'],
1462
- );
1463
- unset( $settings['allow_custom_key'], $settings['white_label'], $settings['white_label__hoster_key'], $settings['white_label__plugin_name'] );
1464
- }
1465
-
1466
- // Drop debug data
1467
- if (isset($_POST['submit']) && $_POST['submit'] == 'debug_drop'){
1468
- $apbct->debug = false;
1469
- delete_option('cleantalk_debug');
1470
- return $settings;
1471
- }
1472
-
1473
- // Send connection reports
1474
- if (isset($_POST['submit']) && $_POST['submit'] == 'ct_send_connection_report'){
1475
- ct_mail_send_connection_report();
1476
- return $settings;
1477
- }
1478
-
1479
- $apbct->saveData();
1480
-
1481
- return $settings;
1482
- }
1483
-
1484
- function apbct_settings__sync( $direct_call = false ){
1485
-
1486
- if( ! $direct_call )
1487
- check_ajax_referer('ct_secret_nonce' );
1488
-
1489
- global $apbct;
1490
-
1491
- // Feedback with app_agent
1492
- ct_send_feedback('0:' . APBCT_AGENT); // 0 - request_id, agent version.
1493
-
1494
- // Key is good by default
1495
- $apbct->data['key_is_ok'] = true;
1496
-
1497
- // Checking account status
1498
- $result = ct_account_status_check( $apbct->settings['apikey'] );
1499
-
1500
- // Is key valid?
1501
- if( $result ){
1502
-
1503
- // Deleting errors about invalid key
1504
- $apbct->error_delete( 'key_invalid key_get', 'save' );
1505
-
1506
- // SFW actions
1507
- if( $apbct->settings['spam_firewall'] == 1 ){
1508
-
1509
- $result = ct_sfw_update( $apbct->settings['apikey'] );
1510
- if( ! empty( $result['error'] ) )
1511
- $apbct->error_add( 'sfw_update', $result['error'] );
1512
-
1513
- $result = ct_sfw_send_logs( $apbct->settings['apikey'] );
1514
- if( ! empty( $result['error'] ) )
1515
- $apbct->error_add( 'sfw_send_logs', $result['error'] );
1516
-
1517
- }
1518
-
1519
- // Updating brief data for dashboard widget
1520
- $apbct->data['brief_data'] = \Cleantalk\ApbctWP\API::method__get_antispam_report_breif( $apbct->settings['apikey'] );
1521
-
1522
- // Key is not valid
1523
- }else{
1524
- $apbct->data['key_is_ok'] = false;
1525
- $apbct->error_add( 'key_invalid', __( 'Testing is failed. Please check the Access key.', 'cleantalk-spam-protect' ) );
1526
- }
1527
-
1528
- // WPMS Logic.
1529
- if(APBCT_WPMS){
1530
- if(is_main_site()){
1531
-
1532
- // Network settings
1533
- $network_settings['apikey'] = $apbct->settings['apikey'];
1534
- $apbct->network_settings = $network_settings;
1535
- $apbct->saveNetworkSettings();
1536
-
1537
- // Network data
1538
- $apbct->network_data = array(
1539
- 'key_is_ok' => $apbct->data['key_is_ok'],
1540
- 'moderate' => $apbct->data['moderate'],
1541
- 'valid' => $apbct->data['valid'],
1542
- 'auto_update' => $apbct->data['auto_update'],
1543
- 'user_token' => $apbct->data['user_token'],
1544
- 'service_id' => $apbct->data['service_id'],
1545
- );
1546
- $apbct->saveNetworkData();
1547
- if (isset($settings['use_settings_template_apply_for_current_list_sites']) && !empty($settings['use_settings_template_apply_for_current_list_sites'])) {
1548
- apbct_update_blogs_options($settings['use_settings_template_apply_for_current_list_sites'], $settings);
1549
- }
1550
- }
1551
- if(!$apbct->white_label && !is_main_site() && !$apbct->allow_custom_key){
1552
- $settings['apikey'] = '';
1553
- }
1554
- }
1555
-
1556
- if($apbct->data['key_is_ok'] == false && $apbct->data['moderate_ip'] == 0){
1557
-
1558
- // Notices
1559
- $apbct->data['notice_show'] = 1;
1560
- $apbct->data['notice_renew'] = 0;
1561
- $apbct->data['notice_trial'] = 0;
1562
- $apbct->data['notice_review'] = 0;
1563
- $apbct->data['notice_auto_update'] = 0;
1564
-
1565
- // Other
1566
- $apbct->data['service_id'] = 0;
1567
- $apbct->data['valid'] = 0;
1568
- $apbct->data['moderate'] = 0;
1569
- $apbct->data['ip_license'] = 0;
1570
- $apbct->data['moderate_ip'] = 0;
1571
- $apbct->data['spam_count'] = 0;
1572
- $apbct->data['auto_update'] = 0;
1573
- $apbct->data['user_token'] = '';
1574
- $apbct->data['license_trial'] = 0;
1575
- $apbct->data['account_name_ob'] = '';
1576
- }
1577
-
1578
- $out = array(
1579
- 'success' => true,
1580
- 'reload' => $apbct->data['key_changed'],
1581
- );
1582
-
1583
- $apbct->data['key_changed'] = false;
1584
-
1585
- $apbct->saveData();
1586
-
1587
- die( json_encode( $out ) );
1588
- }
1589
-
1590
- function apbct_update_blogs_options ($blog_names = array(), $settings) {
1591
- global $wpdb;
1592
-
1593
- $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM '. $wpdb->blogs, OBJECT_K);
1594
-
1595
- foreach ($wp_blogs as $blog) {
1596
- $blog_name = get_blog_details( array( 'blog_id' => $blog->blog_id ) )->blogname;
1597
- if (in_array($blog_name, $blog_names)) {
1598
- update_blog_option ($blog->blog_id, 'cleantalk_settings', $settings);
1599
- }
1600
- }
1601
- }
1602
- /**
1603
- * Sanitize and validate exclusions.
1604
- * Explode given string by commas and trim each string.
1605
- * Skip element if it's empty.
1606
- *
1607
- * Return false if exclusion is bad
1608
- * Return sanitized string if all is ok
1609
- *
1610
- * @param string $exclusions
1611
- * @param bool $regexp
1612
- *
1613
- * @return bool|string
1614
- */
1615
- function apbct_settings__sanitize__exclusions($exclusions, $regexp = false){
1616
- $result = array();
1617
- if( ! empty( $exclusions ) ){
1618
- $exclusions = explode( ',', $exclusions );
1619
- foreach ( $exclusions as $exclusion ){
1620
- $sanitized_exclusion = trim( $exclusion );
1621
- if ( ! empty( $sanitized_exclusion ) ) {
1622
- if( $regexp && ! apbct_is_regexp( $exclusion ) )
1623
- return false;
1624
- $result[] = $sanitized_exclusion;
1625
- }
1626
- }
1627
- }
1628
- return implode( ',', $result );
1629
- }
1630
-
1631
- function apbct_settings_show_gdpr_text($print = false){
1632
-
1633
- $out = wpautop('The notice requirements remain and are expanded. They must include the retention time for personal data, and contact information for data controller and data protection officer has to be provided.
1634
- Automated individual decision-making, including profiling (Article 22) is contestable, similarly to the Data Protection Directive (Article 15). Citizens have rights to question and fight significant decisions that affect them that have been made on a solely-algorithmic basis. Many media outlets have commented on the introduction of a "right to explanation" of algorithmic decisions, but legal scholars have since argued that the existence of such a right is highly unclear without judicial tests and is limited at best.
1635
- To be able to demonstrate compliance with the GDPR, the data controller should implement measures, which meet the principles of data protection by design and data protection by default. Privacy by design and by default (Article 25) require data protection measures to be designed into the development of business processes for products and services. Such measures include pseudonymising personal data, by the controller, as soon as possible (Recital 78).
1636
- It is the responsibility and the liability of the data controller to implement effective measures and be able to demonstrate the compliance of processing activities even if the processing is carried out by a data processor on behalf of the controller (Recital 74).
1637
- Data Protection Impact Assessments (Article 35) have to be conducted when specific risks occur to the rights and freedoms of data subjects. Risk assessment and mitigation is required and prior approval of the national data protection authorities (DPAs) is required for high risks. Data protection officers (Articles 37–39) are required to ensure compliance within organisations.
1638
- They have to be appointed:')
1639
- .'<ul style="padding: 0px 25px; list-style: disc;">'
1640
- .'<li>for all public authorities, except for courts acting in their judicial capacity</li>'
1641
- .'<li>if the core activities of the controller or the processor are:</li>'
1642
- .'<ul style="padding: 0px 25px; list-style: disc;">'
1643
- .'<li>processing operations, which, by virtue of their nature, their scope and/or their purposes, require regular and systematic monitoring of data subjects on a large scale</li>'
1644
- .'<li>processing on a large scale of special categories of data pursuant to Article 9 and personal data relating to criminal convictions and offences referred to in Article 10;</li>'
1645
- .'</ul>'
1646
- .'</li>'
1647
- .'</ul>';
1648
-
1649
- if($print) echo $out; else return $out;
1650
- }
1651
-
1652
- function apbct_settings__get__long_description(){
1653
-
1654
- global $apbct;
1655
-
1656
- check_ajax_referer('ct_secret_nonce' );
1657
-
1658
- $setting_id = $_POST['setting_id'] ? $_POST['setting_id'] : '';
1659
-
1660
- $descriptions = array(
1661
- 'white_label' => array(
1662
- 'title' => __( 'XSS check', 'cleantalk-spam-protect'),
1663
- 'desc' => __( 'Cross-Site Scripting (XSS) prevents malicious code to be executed/sent to any user. As a result malicious scripts can not get access to the cookie files, session tokens and any other confidential information browsers use and store. Such scripts can even overwrite content of HTML pages. CleanTalk WAF monitors for patterns of these parameters and block them.', 'cleantalk-spam-protect'),
1664
- ),
1665
- 'white_label__hoster_key' => array(
1666
- 'title' => __( 'SQL-injection check', 'cleantalk-spam-protect'),
1667
- 'desc' => __( 'SQL Injection one of the most popular ways to hack websites and programs that work with databases. It is based on injection of a custom SQL code into database queries. It could transmit data through GET, POST requests or cookie files in an SQL code. If a website is vulnerable and execute such injections then it would allow attackers to apply changes to the website\'s MySQL database.', 'cleantalk-spam-protect'),
1668
- ),
1669
- 'white_label__plugin_name' => array(
1670
- 'title' => __( 'Check uploaded files', 'cleantalk-spam-protect'),
1671
- 'desc' => __( 'The option checks each uploaded file to a website for malicious code. If it\'s possible for visitors to upload files to a website, for instance a work resume, then attackers could abuse it and upload an infected file to execute it later and get access to your website.', 'cleantalk-spam-protect'),
1672
- ),
1673
- );
1674
-
1675
- die(json_encode($descriptions[$setting_id]));
1676
- }
1677
-
1678
- function apbct_settings__check_renew_banner() {
1679
- global $apbct;
1680
-
1681
- check_ajax_referer('ct_secret_nonce' );
1682
-
1683
- die(json_encode(array('close_renew_banner' => ($apbct->data['notice_trial'] == 0 && $apbct->data['notice_renew'] == 0) ? true : false)));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1684
  }
1
+ <?php
2
+
3
+ /**
4
+ * Admin action 'admin_menu' - Add the admin options page
5
+ */
6
+ function apbct_settings_add_page() {
7
+
8
+ global $apbct, $pagenow;
9
+
10
+ $parent_slug = is_network_admin() ? 'settings.php' : 'options-general.php';
11
+ $callback = is_network_admin() ? 'apbct_settings__display__network' : 'apbct_settings__display';
12
+
13
+ // Adding settings page
14
+ add_submenu_page(
15
+ $parent_slug,
16
+ $apbct->plugin_name.' '.__('settings'),
17
+ $apbct->plugin_name,
18
+ 'manage_options',
19
+ 'cleantalk',
20
+ $callback
21
+ );
22
+
23
+ if(!in_array($pagenow, array('options.php', 'options-general.php', 'settings.php', 'admin.php')))
24
+ return;
25
+
26
+ register_setting('cleantalk_settings', 'cleantalk_settings', 'apbct_settings__validate');
27
+
28
+ $fields = array();
29
+ $fields = apbct_settings__set_fileds($fields);
30
+ $fields = APBCT_WPMS && is_main_site() ? apbct_settings__set_fileds__network($fields) : $fields;
31
+ apbct_settings__add_groups_and_fields($fields);
32
+
33
+ }
34
+
35
+ function apbct_settings__set_fileds( $fields ){
36
+ global $apbct;
37
+
38
+ $fields = array(
39
+
40
+ 'main' => array(
41
+ 'title' => '',
42
+ 'default_params' => array(),
43
+ 'description' => '',
44
+ 'html_before' => '',
45
+ 'html_after' => '',
46
+ 'fields' => array(
47
+ 'action_buttons' => array(
48
+ 'callback' => 'apbct_settings__field__action_buttons',
49
+ ),
50
+ 'connection_reports' => array(
51
+ 'callback' => 'apbct_settings__field__statistics',
52
+ ),
53
+ 'api_key' => array(
54
+ 'display' => !$apbct->white_label || is_main_site(),
55
+ 'callback' => 'apbct_settings__field__apikey',
56
+ ),
57
+ ),
58
+ ),
59
+
60
+ 'state' => array(
61
+ 'title' => '',
62
+ 'default_params' => array(),
63
+ 'description' => '',
64
+ 'html_before' => '<hr style="width: 100%;">',
65
+ 'html_after' => '',
66
+ 'fields' => array(
67
+ 'state' => array(
68
+ 'callback' => 'apbct_settings__field__state',
69
+ ),
70
+ ),
71
+ ),
72
+
73
+ 'debug' => array(
74
+ 'title' => '',
75
+ 'default_params' => array(),
76
+ 'description' => '',
77
+ 'html_before' => '',
78
+ 'html_after' => '',
79
+ 'fields' => array(
80
+ 'state' => array(
81
+ 'callback' => 'apbct_settings__field__debug',
82
+ ),
83
+ ),
84
+ ),
85
+
86
+ // Different
87
+ 'different' => array(
88
+ 'title' => '',
89
+ 'default_params' => array(),
90
+ 'description' => '',
91
+ 'html_before' => '<hr>',
92
+ 'html_after' => '',
93
+ 'fields' => array(
94
+ 'spam_firewall' => array(
95
+ 'type' => 'checkbox',
96
+ 'title' => __('SpamFireWall', 'cleantalk-spam-protect'),
97
+ 'description' => __("This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.", 'cleantalk-spam-protect'),
98
+ 'childrens' => array('sfw__anti_flood', 'sfw__anti_crawler'),
99
+ ),
100
+ 'sfw__anti_flood' => array(
101
+ 'type' => 'checkbox',
102
+ 'title' => __('Anti-Flood', 'cleantalk-spam-protect'),
103
+ 'class' => 'apbct_settings-field_wrapper--sub',
104
+ 'parent' => 'spam_firewall',
105
+ 'childrens' => array('sfw__anti_flood__view_limit',),
106
+ 'description' => __('Shows SpamFireWall page for bot which are trying to scan your website. Look for the page limit setting below.', 'cleantalk-spam-protect'),
107
+ ),
108
+ 'sfw__anti_crawler' => array(
109
+ 'type' => 'checkbox',
110
+ 'title' => __('Anti-Crawler', 'cleantalk-spam-protect'),
111
+ 'class' => 'apbct_settings-field_wrapper--sub',
112
+ 'parent' => 'spam_firewall',
113
+ 'description' => __('Plugin shows SpamFireWall stop page for any bot, except allowed bots (Google, Yahoo and etc).', 'cleantalk-spam-protect'),
114
+ ),
115
+ ),
116
+ ),
117
+
118
+ // Forms protection
119
+ 'forms_protection' => array(
120
+ 'title' => __('Forms to protect', 'cleantalk-spam-protect'),
121
+ 'default_params' => array(),
122
+ 'description' => '',
123
+ 'html_before' => '<hr><br>'
124
+ .'<span id="ct_adv_showhide">'
125
+ .'<a href="#" class="apbct_color--gray" onclick="event.preventDefault(); apbct_show_hide_elem(\'apbct_settings__davanced_settings\');">'
126
+ .__('Advanced settings', 'cleantalk-spam-protect')
127
+ .'</a>'
128
+ .'</span>'
129
+ .'<div id="apbct_settings__davanced_settings" style="display: none;">',
130
+ 'html_after' => '',
131
+ 'fields' => array(
132
+ 'registrations_test' => array(
133
+ 'title' => __('Registration Forms', 'cleantalk-spam-protect'),
134
+ 'description' => __('WordPress, BuddyPress, bbPress, S2Member, WooCommerce.', 'cleantalk-spam-protect'),
135
+ ),
136
+ 'comments_test' => array(
137
+ 'title' => __('Comments form', 'cleantalk-spam-protect'),
138
+ 'description' => __('WordPress, JetPack, WooCommerce.', 'cleantalk-spam-protect'),
139
+ ),
140
+ 'contact_forms_test' => array(
141
+ 'title' => __('Contact forms', 'cleantalk-spam-protect'),
142
+ 'description' => __('Contact Form 7, Formidable forms, JetPack, Fast Secure Contact Form, WordPress Landing Pages, Gravity Forms.', 'cleantalk-spam-protect'),
143
+ ),
144
+ 'general_contact_forms_test' => array(
145
+ 'title' => __('Custom contact forms', 'cleantalk-spam-protect'),
146
+ 'description' => __('Anti spam test for any WordPress themes or contacts forms.', 'cleantalk-spam-protect'),
147
+ ),
148
+ 'search_test' => array(
149
+ 'title' => __('Test default Wordpress search form for spam', 'cleantalk-spam-protect'),
150
+ 'description' => __('Spam protection for Search form.', 'cleantalk-spam-protect')
151
+ . (!$apbct->white_label || is_main_site()
152
+ ? sprintf(__('Read more about %sspam protection for Search form%s on our blog. “noindex” tag will be placed in meta derictive on search page.', 'cleantalk-spam-protect'),
153
+ '<a href="https://blog.cleantalk.org/how-to-protect-website-search-from-spambots/" target="_blank">',
154
+ '</a>'
155
+ )
156
+ : ''
157
+ )
158
+ ),
159
+ 'check_external' => array(
160
+ 'title' => __('Protect external forms', 'cleantalk-spam-protect'),
161
+ 'description' => __('Turn this option on to protect forms on your WordPress that send data to third-part servers (like MailChimp).', 'cleantalk-spam-protect'),
162
+ 'childrens' => array('check_external__capture_buffer'),
163
+ ),
164
+ 'check_external__capture_buffer' => array(
165
+ 'title' => __('Capture buffer', 'cleantalk-spam-protect'),
166
+ 'description' => __('This setting gives you more sophisticated and strengthened protection for external forms. But it could break plugins which use a buffer like Ninja Forms.', 'cleantalk-spam-protect'),
167
+ 'class' => 'apbct_settings-field_wrapper--sub',
168
+ 'parent' => 'check_external',
169
+ ),
170
+ 'check_internal' => array(
171
+ 'title' => __('Protect internal forms', 'cleantalk-spam-protect'),
172
+ 'description' => __('This option will enable protection for custom (hand-made) AJAX forms with PHP scripts handlers on your WordPress.', 'cleantalk-spam-protect'),
173
+ ),
174
+ ),
175
+ ),
176
+
177
+ // Comments and Messages
178
+ 'wc' => array(
179
+ 'title' => __('WooCommerce', 'cleantalk-spam-protect'),
180
+ 'fields' => array(
181
+ 'wc_checkout_test' => array(
182
+ 'title' => __('WooCommerce checkout form', 'cleantalk-spam-protect'),
183
+ 'description' => __('Anti spam test for WooCommerce checkout form.', 'cleantalk-spam-protect'),
184
+ 'childrens' => array('wc_register_from_order')
185
+ ),
186
+ 'wc_register_from_order' => array(
187
+ 'title' => __('Spam test for registration during checkout', 'cleantalk-spam-protect'),
188
+ 'description' => __('Enable anti spam test for registration process which during woocommerce\'s checkout.', 'cleantalk-spam-protect'),
189
+ 'parent' => 'wc_checkout_test',
190
+ 'class' => 'apbct_settings-field_wrapper--sub',
191
+ 'reverse_trigger' => true
192
+ ),
193
+ ),
194
+ ),
195
+
196
+ // Comments and Messages
197
+ 'comments_and_messages' => array(
198
+ 'title' => __('Comments and Messages', 'cleantalk-spam-protect'),
199
+ 'fields' => array(
200
+ 'disable_comments__all' => array(
201
+ 'title' => __( 'Disable all comments', 'cleantalk-spam-protect'),
202
+ 'description' => __( 'Disabling comments for all types of content.', 'cleantalk-spam-protect'),
203
+ 'childrens' => array(
204
+ 'disable_comments__posts',
205
+ 'disable_comments__pages',
206
+ 'disable_comments__media',
207
+ ),
208
+ 'options' => array(
209
+ array( 'val' => 1, 'label' => __( 'On' ), 'childrens_enable' => 0, ),
210
+ array( 'val' => 0, 'label' => __( 'Off' ), 'childrens_enable' => 1, ),
211
+ ),
212
+ ),
213
+ 'disable_comments__posts' => array(
214
+ 'title' => __( 'Disable comments for all posts', 'cleantalk-spam-protect'),
215
+ 'class' => 'apbct_settings-field_wrapper--sub',
216
+ 'parent' => 'disable_comments__all',
217
+ 'reverse_trigger' => true,
218
+ ),
219
+ 'disable_comments__pages' => array(
220
+ 'title' => __( 'Disable comments for all pages', 'cleantalk-spam-protect'),
221
+ 'class' => 'apbct_settings-field_wrapper--sub',
222
+ 'parent' => 'disable_comments__all',
223
+ 'reverse_trigger' => true,
224
+ ),
225
+ 'disable_comments__media' => array(
226
+ 'title' => __( 'Disable comments for all media', 'cleantalk-spam-protect'),
227
+ 'class' => 'apbct_settings-field_wrapper--sub',
228
+ 'parent' => 'disable_comments__all',
229
+ 'reverse_trigger' => true,
230
+ ),
231
+ 'bp_private_messages' => array(
232
+ 'title' => __('BuddyPress Private Messages', 'cleantalk-spam-protect'),
233
+ 'description' => __('Check buddyPress private messages.', 'cleantalk-spam-protect'),
234
+ ),
235
+ 'remove_old_spam' => array(
236
+ 'title' => __('Automatically delete spam comments', 'cleantalk-spam-protect'),
237
+ 'description' => sprintf(__('Delete spam comments older than %d days.', 'cleantalk-spam-protect'), $apbct->data['spam_store_days']),
238
+ ),
239
+ 'remove_comments_links' => array(
240
+ 'title' => __('Remove links from approved comments', 'cleantalk-spam-protect'),
241
+ 'description' => __('Remove links from approved comments. Replace it with "[Link deleted]"', 'cleantalk-spam-protect'),
242
+ ),
243
+ 'show_check_links' => array(
244
+ 'title' => __('Show links to check Emails, IPs for spam', 'cleantalk-spam-protect'),
245
+ 'description' => __('Shows little icon near IP addresses and Emails allowing you to check it via CleanTalk\'s database.', 'cleantalk-spam-protect'),
246
+ 'display' => !$apbct->white_label,
247
+ ),
248
+ 'manage_comments_on_public_page' => array(
249
+ 'title' => __('Manage comments on public pages', 'cleantalk-spam-protect'),
250
+ 'description' => __('Allows administrators to manage comments on public post\'s pages with small interactive menu.', 'cleantalk-spam-protect'),
251
+ 'display' => !$apbct->white_label,
252
+ ),
253
+ ),
254
+ ),
255
+
256
+ // Data Processing
257
+ 'data_processing' => array(
258
+ 'title' => __('Data Processing', 'cleantalk-spam-protect'),
259
+ 'fields' => array(
260
+ 'protect_logged_in' => array(
261
+ 'title' => __("Protect logged in Users", 'cleantalk-spam-protect'),
262
+ 'description' => __('Turn this option on to check for spam any submissions (comments, contact forms and etc.) from registered Users.', 'cleantalk-spam-protect'),
263
+ ),
264
+ 'check_comments_number' => array(
265
+ 'title' => __("Don't check trusted user's comments", 'cleantalk-spam-protect'),
266
+ 'description' => sprintf(__("Don't check comments for users with above %d comments.", 'cleantalk-spam-protect'), defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3),
267
+ ),
268
+ 'use_ajax' => array(
269
+ 'title' => __('Use AJAX for JavaScript check', 'cleantalk-spam-protect'),
270
+ 'description' => __('Options helps protect WordPress against spam with any caching plugins. Turn this option on to avoid issues with caching plugins.', 'cleantalk-spam-protect'),
271
+ ),
272
+ 'use_static_js_key' => array(
273
+ 'title' => __('Use static keys for JS check.', 'cleantalk-spam-protect'),
274
+ 'description' => __('Could help if you have cache for AJAX requests and you are dealing with false positives. Slightly decreases protection quality. Auto - Static key will be used if caching plugin is spotted.', 'cleantalk-spam-protect'),
275
+ 'options' => array(
276
+ array('val' => 1, 'label' => __('On'), ),
277
+ array('val' => 0, 'label' => __('Off'), ),
278
+ array('val' => -1, 'label' => __('Auto'),),
279
+ ),
280
+ ),
281
+ 'general_postdata_test' => array(
282
+ 'title' => __('Check all post data', 'cleantalk-spam-protect'),
283
+ 'description' => __('Check all POST submissions from website visitors. Enable this option if you have spam misses on website.', 'cleantalk-spam-protect')
284
+ .(!$apbct->white_label
285
+ ? __(' Or you don`t have records about missed spam here:', 'cleantalk-spam-protect') . '&nbsp;' . '<a href="https://cleantalk.org/my/?user_token='.$apbct->user_token.'&utm_source=wp-backend&utm_medium=admin-bar&cp_mode=antispam" target="_blank">' . __('CleanTalk dashboard', 'cleantalk-spam-protect') . '</a>.'
286
+ : ''
287
+ )
288
+ .'<br />' . __('СAUTION! Option can catch POST requests in WordPress backend', 'cleantalk-spam-protect'),
289
+ ),
290
+ 'set_cookies' => array(
291
+ 'title' => __("Set cookies", 'cleantalk-spam-protect'),
292
+ 'description' => __('Turn this option off to deny plugin generates any cookies on website front-end. This option is helpful if you use Varnish. But most of contact forms will not be protected if the option is turned off! <b>Warning: We strongly recommend you to enable this otherwise it could cause false positives spam detection.</b>', 'cleantalk-spam-protect'),
293
+ 'childrens' => array('set_cookies__sessions'),
294
+ ),
295
+ 'set_cookies__sessions' => array(
296
+ 'title' => __('Use alternative mechanism for cookies', 'cleantalk-spam-protect'),
297
+ 'description' => __('Doesn\'t use cookie or PHP sessions. Collect data for all types of bots.', 'cleantalk-spam-protect'),
298
+ 'parent' => 'set_cookies',
299
+ 'class' => 'apbct_settings-field_wrapper--sub',
300
+ ),
301
+ 'ssl_on' => array(
302
+ 'title' => __("Use SSL", 'cleantalk-spam-protect'),
303
+ 'description' => __('Turn this option on to use encrypted (SSL) connection with servers.', 'cleantalk-spam-protect'),
304
+ ),
305
+ 'use_buitin_http_api' => array(
306
+ 'title' => __("Use Wordpress HTTP API", 'cleantalk-spam-protect'),
307
+ 'description' => __('Alternative way to connect the Cloud. Use this if you have connection problems.', 'cleantalk-spam-protect'),
308
+ ),
309
+ ),
310
+ ),
311
+
312
+ // Exclusions
313
+ 'exclusions' => array(
314
+ 'title' => __('Exclusions', 'cleantalk-spam-protect'),
315
+ 'fields' => array(
316
+ 'exclusions__urls' => array(
317
+ 'type' => 'text',
318
+ 'title' => __('URL exclusions', 'cleantalk-spam-protect'),
319
+ 'description' => __('You could type here URL you want to exclude. Use comma as separator.', 'cleantalk-spam-protect'),
320
+ ),
321
+ 'exclusions__urls__use_regexp' => array(
322
+ 'type' => 'checkbox',
323
+ 'title' => __('Use Regular Expression in URL Exclusions', 'cleantalk-spam-protect'),
324
+ ),
325
+ 'exclusions__fields' => array(
326
+ 'type' => 'text',
327
+ 'title' => __('Field name exclusions', 'cleantalk-spam-protect'),
328
+ 'description' => __('You could type here fields names you want to exclude. Use comma as separator.', 'cleantalk-spam-protect'),
329
+ ),
330
+ 'exclusions__fields__use_regexp' => array(
331
+ 'type' => 'checkbox',
332
+ 'title' => __('Use Regular Expression in Field Exclusions', 'cleantalk-spam-protect'),
333
+ ),
334
+ 'exclusions__roles' => array(
335
+ 'type' => 'select',
336
+ 'multiple' => true,
337
+ 'options_callback' => 'apbct_get_all_roles',
338
+ 'options_callback_params' => array(true),
339
+ 'description' => __('Roles which bypass spam test. Hold CTRL to select multiple roles.', 'cleantalk-spam-protect'),
340
+ ),
341
+ ),
342
+ ),
343
+
344
+ // Admin bar
345
+ 'admin_bar' => array(
346
+ 'title' => __('Admin bar', 'cleantalk-spam-protect'),
347
+ 'default_params' => array(),
348
+ 'description' => '',
349
+ 'html_before' => '',
350
+ 'html_after' => '',
351
+ 'fields' => array(
352
+ 'show_adminbar' => array(
353
+ 'title' => __('Show statistics in admin bar', 'cleantalk-spam-protect'),
354
+ 'description' => __('Show/hide icon in top level menu in WordPress backend. The number of submissions is being counted for past 24 hours.', 'cleantalk-spam-protect'),
355
+ 'childrens' => array('all_time_counter','daily_counter','sfw_counter'),
356
+ ),
357
+ 'all_time_counter' => array(
358
+ 'title' => __('Show All-time counter', 'cleantalk-spam-protect'),
359
+ 'description' => __('Display all-time requests counter in the admin bar. Counter displays number of requests since plugin installation.', 'cleantalk-spam-protect'),
360
+ 'parent' => 'show_adminbar',
361
+ 'class' => 'apbct_settings-field_wrapper--sub',
362
+ ),
363
+ 'daily_counter' => array(
364
+ 'title' => __('Show 24 hours counter', 'cleantalk-spam-protect'),
365
+ 'description' => __('Display daily requests counter in the admin bar. Counter displays number of requests of the past 24 hours.', 'cleantalk-spam-protect'),
366
+ 'parent' => 'show_adminbar',
367
+ 'class' => 'apbct_settings-field_wrapper--sub',
368
+ ),
369
+ 'sfw_counter' => array(
370
+ 'title' => __('SpamFireWall counter', 'cleantalk-spam-protect'),
371
+ 'description' => __('Display SpamFireWall requests in the admin bar. Counter displays number of requests since plugin installation.', 'cleantalk-spam-protect'),
372
+ 'parent' => 'show_adminbar',
373
+ 'class' => 'apbct_settings-field_wrapper--sub',
374
+ ),
375
+ ),
376
+ ),
377
+
378
+ // Misc
379
+ 'misc' => array(
380
+ 'html_after' => '</div><br>',
381
+ 'fields' => array(
382
+ 'collect_details' => array(
383
+ 'type' => 'checkbox',
384
+ 'title' => __('Collect details about browsers', 'cleantalk-spam-protect'),
385
+ 'description' => __("Checking this box you allow plugin store information about screen size and browser plugins of website visitors. The option in a beta state.", 'cleantalk-spam-protect'),
386
+ ),
387
+ 'send_connection_reports' => array(
388
+ 'type' => 'checkbox',
389
+ 'title' => __('Send connection reports', 'cleantalk-spam-protect'),
390
+ 'description' => __("Checking this box you allow plugin to send the information about your connection. The option in a beta state.", 'cleantalk-spam-protect'),
391
+ ),
392
+ 'async_js' => array(
393
+ 'type' => 'checkbox',
394
+ 'title' => __('Async JavaScript loading', 'cleantalk-spam-protect'),
395
+ 'description' => __('Use async loading for scripts. Warning: This could reduce filtration quality.', 'cleantalk-spam-protect'),
396
+ ),
397
+ 'gdpr_enabled' => array(
398
+ 'type' => 'checkbox',
399
+ 'title' => __('Allow to add GDPR notice via shortcode', 'cleantalk-spam-protect'),
400
+ 'description' => __(' Adds small checkbox under your website form. To add it you should use the shortcode on the form\'s page: [cleantalk_gdpr_form id="FORM_ID"]', 'cleantalk-spam-protect'),
401
+ 'childrens' => array('gdpr_text'),
402
+ ),
403
+ 'gdpr_text' => array(
404
+ 'type' => 'text',
405
+ 'title' => __('GDPR text notice', 'cleantalk-spam-protect'),
406
+ 'description' => __('This text will be added as a description to the GDPR checkbox.', 'cleantalk-spam-protect'),
407
+ 'parent' => 'gdpr_enabled',
408
+ 'class' => 'apbct_settings-field_wrapper--sub',
409
+ ),
410
+ 'store_urls' => array(
411
+ 'type' => 'checkbox',
412
+ 'title' => __('Store visited URLs', 'cleantalk-spam-protect'),
413
+ 'description' => __("Plugin stores last 10 visited URLs (HTTP REFFERERS) before visitor submits form on the site. You can see stored visited URLS for each visitor in your Dashboard. Turn the option on to improve Anti-Spam protection.", 'cleantalk-spam-protect'),
414
+ 'childrens' => array('store_urls__sessions'),
415
+ ),
416
+ 'store_urls__sessions' => array(
417
+ 'type' => 'checkbox',
418
+ 'title' => __('Use cookies less sessions', 'cleantalk-spam-protect'),
419
+ 'description' => __('Doesn\'t use cookie or PHP sessions. Collect data for all types of bots.', 'cleantalk-spam-protect'),
420
+ 'parent' => 'store_urls',
421
+ 'class' => 'apbct_settings-field_wrapper--sub',
422
+ ),
423
+ 'comment_notify' => array(
424
+ 'type' => 'checkbox',
425
+ 'title' => __('Notify users with selected roles about new approved comments. Hold CTRL to select multiple roles.', 'cleantalk-spam-protect'),
426
+ 'description' => sprintf(__("If enabled, overrides similar Wordpress %sdiscussion settings%s.", 'cleantalk-spam-protect'), '<a href="options-discussion.php">','</a>'),
427
+ 'childrens' => array('comment_notify__roles'),
428
+ ),
429
+ 'comment_notify__roles' => array(
430
+ 'type' => 'select',
431
+ 'multiple' => true,
432
+ 'parent' => 'comment_notify',
433
+ 'options_callback' => 'apbct_get_all_roles',
434
+ 'options_callback_params' => array(true),
435
+ 'class' => 'apbct_settings-field_wrapper--sub',
436
+ ),
437
+ 'sfw__anti_flood__view_limit' => array(
438
+ 'type' => 'text',
439
+ 'title' => __('Anti-Flood Page Views Limit', 'cleantalk-spam-protect'),
440
+ 'class' => 'apbct_settings-field_wrapper',
441
+ 'parent' => 'sfw__anti_flood',
442
+ 'description' => __('Count of page view per 1 minute before plugin shows SpamFireWall page. SpamFireWall page active for 30 second after that valid visitor (with JavaScript) passes the page to the demanded page of the site.', 'cleantalk-spam-protect'),
443
+ ),
444
+ 'dashboard_widget__show' => array(
445
+ 'type' => 'checkbox',
446
+ 'title' => __('Show Dashboard Widget', 'cleantalk-spam-protect'),
447
+ ),
448
+ 'complete_deactivation' => array(
449
+ 'type' => 'checkbox',
450
+ 'title' => __('Complete deactivation', 'cleantalk-spam-protect'),
451
+ 'description' => __('Leave no trace in the system after deactivation.', 'cleantalk-spam-protect'),
452
+ ),
453
+
454
+ ),
455
+ ),
456
+ );
457
+
458
+ return $fields;
459
+ }
460
+
461
+ function apbct_settings__set_fileds__network( $fields ){
462
+ global $apbct;
463
+ $additional_fields = array(
464
+ 'main' => array(
465
+ 'fields' => array(
466
+ 'white_label' => array(
467
+ 'type' => 'checkbox',
468
+ 'title' => __('Enable White Label Mode', 'cleantalk-spam-protect'),
469
+ 'description' => sprintf(__("Learn more information %shere%s.", 'cleantalk-spam-protect'), '<a target="_blank" href="https://cleantalk.org/ru/help/hosting-white-label">', '</a>'),
470
+ 'childrens' => array( 'white_label__hoster_key', 'white_label__plugin_name', 'allow_custom_key', ),
471
+ 'disabled' => defined('CLEANTALK_ACCESS_KEY'),
472
+ 'network' => true,
473
+ ),
474
+ 'white_label__hoster_key' => array(
475
+ 'title' => __('Hoster API Key', 'cleantalk-spam-protect'),
476
+ 'description' => sprintf(__("You can get it in %sCleantalk's Control Panel%s", 'cleantalk-spam-protect'), '<a target="_blank" href="https://cleantalk.org/my/profile">', '</a>'),
477
+ 'type' => 'text',
478
+ 'parent' => 'white_label',
479
+ 'class' => 'apbct_settings-field_wrapper--sub',
480
+ 'network' => true,
481
+ 'required' => true,
482
+ ),
483
+ 'white_label__plugin_name' => array(
484
+ 'title' => __('Plugin name', 'cleantalk-spam-protect'),
485
+ 'description' => sprintf(__("Specify plugin name. Leave empty for deafult %sAntispam by Cleantalk%s", 'cleantalk-spam-protect'), '<b>', '</b>'),
486
+ 'type' => 'text',
487
+ 'parent' => 'white_label',
488
+ 'class' => 'apbct_settings-field_wrapper--sub',
489
+ 'network' => true,
490
+ 'required' => true,
491
+ ),
492
+ 'allow_custom_key' => array(
493
+ 'type' => 'checkbox',
494
+ 'title' => __('Allow users to use other key', 'cleantalk-spam-protect'),
495
+ 'description' => __('Allow users to use different Access key in their plugin settings on child blogs. They could use different CleanTalk account.', 'cleantalk-spam-protect')
496
+ . (defined('CLEANTALK_ACCESS_KEY')
497
+ ? ' <span style="color: red">'
498
+ . __('Constant <b>CLEANTALK_ACCESS_KEY</b> is set. All websites will use API key from this constant. Look into wp-config.php', 'cleantalk-spam-protect')
499
+ . '<br>'
500
+ . __('You are not able to use white label mode while <b>CLEANTALK_ACCESS_KEY</b> is defined.', 'cleantalk-spam-protect')
501
+ . '</span>'
502
+ : ''
503
+ ),
504
+ 'display' => APBCT_WPMS && is_main_site(),
505
+ 'disabled' => $apbct->network_settings['white_label'],
506
+ 'network' => true,
507
+ ),
508
+ 'allow_custom_settings' => array(
509
+ 'type' => 'checkbox',
510
+ 'title' => __('Allow users to manage plugin settings', 'cleantalk-spam-protect'),
511
+ 'description' => __('Allow to change settings on child sites.', 'cleantalk-spam-protect'),
512
+ 'display' => APBCT_WPMS && is_main_site(),
513
+ 'network' => true,
514
+ ),
515
+ 'use_settings_template' => array(
516
+ 'type' => 'checkbox',
517
+ 'title' => __('Use settings template', 'cleantalk-spam-protect'),
518
+ 'description' => __("Use the current settings template for child sites.", 'cleantalk-spam-protect'),
519
+ 'childrens' => array( 'use_settings_template_apply_for_new', 'use_settings_template_apply_for_current'),
520
+ 'network' => true,
521
+ ),
522
+ 'use_settings_template_apply_for_new' => array(
523
+ 'type' => 'checkbox',
524
+ 'title' => __('Apply for newly added sites.', 'cleantalk-spam-protect'),
525
+ 'description' => __("The newly added site will have the same preset settings template.", 'cleantalk-spam-protect'),
526
+ 'parent' => 'use_settings_template',
527
+ 'class' => 'apbct_settings-field_wrapper--sub',
528
+ 'network' => true,
529
+ ),
530
+ 'use_settings_template_apply_for_current' => array(
531
+ 'type' => 'checkbox',
532
+ 'title' => __('Apply for current sites.', 'cleantalk-spam-protect'),
533
+ 'description' => __("Apply current settings template for selected sites.", 'cleantalk-spam-protect'),
534
+ 'parent' => 'use_settings_template',
535
+ 'childrens' => array( 'use_settings_template_apply_for_current_list_sites'),
536
+ 'class' => 'apbct_settings-field_wrapper--sub',
537
+ 'network' => true,
538
+ ),
539
+ 'use_settings_template_apply_for_current_list_sites' => array(
540
+ 'type' => 'select',
541
+ 'multiple' => true,
542
+ 'options_callback' => 'apbct_get_all_child_domains',
543
+ 'options_callback_params' => array(true),
544
+ 'class' => 'apbct_settings-field_wrapper--sub',
545
+ 'parent' => 'use_settings_template_apply_for_current',
546
+ 'description' => __('Sites to apply settings. Hold CTRL to select multiple sites.', 'cleantalk-spam-protect'),
547
+ 'network' => true,
548
+ ),
549
+ )
550
+ )
551
+ );
552
+
553
+ $fields = array_merge_recursive($fields, $additional_fields);
554
+
555
+ return $fields;
556
+
557
+ }
558
+
559
+ function apbct_settings__add_groups_and_fields( $fields ){
560
+
561
+ global $apbct;
562
+
563
+ $apbct->settings_fields_in_groups = $fields;
564
+
565
+ $field_default_params = array(
566
+ 'callback' => 'apbct_settings__field__draw',
567
+ 'type' => 'radio',
568
+ 'options' => array(
569
+ array('val' => 1, 'label' => __('On', 'cleantalk-spam-protect'), 'childrens_enable' => 1, ),
570
+ array('val' => 0, 'label' => __('Off', 'cleantalk-spam-protect'), 'childrens_enable' => 0, ),
571
+ ),
572
+ 'def_class' => 'apbct_settings-field_wrapper',
573
+ 'class' => '',
574
+ 'parent' => '',
575
+ 'childrens' => array(),
576
+ 'hide' => array(),
577
+ // 'title' => 'Default title',
578
+ // 'description' => 'Default description',
579
+ 'display' => true, // Draw settings or not
580
+ 'reverse_trigger' => false, // How to allow child settings. Childrens are opened when the parent triggered "ON". This is overrides by this option
581
+ 'multiple' => false,
582
+ 'description' => '',
583
+ 'network' => false,
584
+ 'disabled' => false,
585
+ 'required' => false,
586
+ );
587
+
588
+ foreach($apbct->settings_fields_in_groups as $group_name => $group){
589
+
590
+ add_settings_section('apbct_section__'.$group_name, '', 'apbct_section__'.$group_name, 'cleantalk-spam-protect');
591
+
592
+ foreach($group['fields'] as $field_name => $field){
593
+
594
+ // Normalize $field['options'] from callback function to this type array( array( 'val' => 1, 'label' => __('On'), ), )
595
+ if(!empty($field['options_callback'])){
596
+ $options = call_user_func_array($field['options_callback'], !empty($field['options_callback_params']) ? $field['options_callback_params'] : array());
597
+ foreach ($options as &$option){
598
+ $option = array('val' => $option, 'label' => $option);
599
+ } unset($option);
600
+ $field['options'] = $options;
601
+ }
602
+
603
+ $params = !empty($group['default_params'])
604
+ ? array_merge($group['default_params'], $field)
605
+ : array_merge($field_default_params, $field);
606
+
607
+ $params['name'] = $field_name;
608
+
609
+ if(!$params['display'])
610
+ continue;
611
+
612
+ add_settings_field(
613
+ 'apbct_field__'.$field_name,
614
+ '',
615
+ $params['callback'],
616
+ 'cleantalk',
617
+ 'apbct_section__'.$group_name,
618
+ $params
619
+ );
620
+
621
+ }
622
+ }
623
+ }
624
+
625
+ /**
626
+ * Admin callback function - Displays plugin options page
627
+ */
628
+ function apbct_settings__display() {
629
+
630
+ global $apbct;
631
+
632
+ // Title
633
+ echo '<h2 class="apbct_settings-title">'.__($apbct->plugin_name, 'cleantalk-spam-protect').'</h2>';
634
+
635
+ // Subtitle for IP license
636
+ if($apbct->moderate_ip)
637
+ echo '<h4 class="apbct_settings-subtitle apbct_color--gray">'. __('Hosting AntiSpam', 'cleantalk-spam-protect').'</h4>';
638
+
639
+ echo '<form action="options.php" method="post">';
640
+
641
+ apbct_settings__error__output();
642
+
643
+ // Top info
644
+ if(!$apbct->white_label){
645
+ echo '<div style="float: right; padding: 15px 15px 5px 15px; font-size: 13px; position: relative; background: #f1f1f1;">';
646
+
647
+ echo __('CleanTalk\'s tech support:', 'cleantalk-spam-protect')
648
+ .'&nbsp;'
649
+ .'<a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">Wordpress.org</a>.'
650
+ // .' <a href="https://community.cleantalk.org/viewforum.php?f=25" target="_blank">'.__("Tech forum", 'cleantalk-spam-protect').'</a>'
651
+ // .($user_token ? ", <a href='https://cleantalk.org/my/support?user_token=$user_token&cp_mode=antispam' target='_blank'>".__("Service support ", 'cleantalk-spam-protect').'</a>' : '').
652
+ .'<br>';
653
+ echo __('Plugin Homepage at', 'cleantalk-spam-protect').' <a href="https://cleantalk.org" target="_blank">cleantalk.org</a>.<br/>';
654
+ echo '<span id="apbct_gdpr_open_modal" style="text-decoration: underline;">'.__('GDPR compliance', 'cleantalk-spam-protect').'</span><br/>';
655
+ echo __('Use s@cleantalk.org to test plugin in any WordPress form.', 'cleantalk-spam-protect').'<br>';
656
+ echo __('CleanTalk is registered Trademark. All rights reserved.', 'cleantalk-spam-protect').'<br/>';
657
+ if($apbct->key_is_ok)
658
+ echo '<b style="display: inline-block; margin-top: 10px;">'.sprintf(__('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'), '<a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">', '</a>').'</b><br />';
659
+ apbct_admin__badge__get_premium();
660
+ echo '<div id="gdpr_dialog" style="display: none; padding: 7px;">';
661
+ apbct_settings_show_gdpr_text('print');
662
+ echo '</div>';
663
+ echo '</div>';
664
+ }
665
+
666
+ // Output spam count
667
+ if($apbct->key_is_ok && apbct_api_key__is_correct()){
668
+ if( $apbct->spam_count > 0 ){
669
+ echo '<div class="apbct_settings-subtitle" style="top: 0; margin-bottom: 10px; width: 200px;">'
670
+ . '<br>'
671
+ . '<span>'
672
+ . sprintf(
673
+ __( '%s has blocked <b>%s</b> spam.', 'cleantalk-spam-protect' ),
674
+ $apbct->plugin_name,
675
+ number_format( $apbct->spam_count, 0, ',', ' ' )
676
+ )
677
+ . '</span>'
678
+ . '<br>'
679
+ . '<br>'
680
+ . '</div>';
681
+ }
682
+ }
683
+
684
+
685
+ // Output spam count
686
+ if($apbct->key_is_ok && apbct_api_key__is_correct()){
687
+ if(!$apbct->white_label){
688
+
689
+ // CP button
690
+ echo '<a class="cleantalk_link cleantalk_link-manual" target="__blank" href="https://cleantalk.org/my?user_token='.$apbct->user_token.'&cp_mode=antispam">'
691
+ .__('Click here to get anti-spam statistics', 'cleantalk-spam-protect')
692
+ .'</a>';
693
+ echo '&nbsp;&nbsp;';
694
+
695
+ }
696
+ }
697
+
698
+ if( apbct_api_key__is_correct() && ! $apbct->white_label ){
699
+ // Sync button
700
+ echo '<button type="button" class="cleantalk_link cleantalk_link-auto" id="apbct_button__sync" title="Synchronizing account status, SpamFireWall database, all kind of journals.">'
701
+ . '<i class="icon-upload-cloud"></i>&nbsp;&nbsp;'
702
+ . __( 'Synchronize with Cloud', 'security-malware-firewall' )
703
+ . '<img style="margin-left: 10px;" class="apbct_preloader_button" src="' . APBCT_URL_PATH . '/inc/images/preloader2.gif" />'
704
+ . '<img style="margin-left: 10px;" class="apbct_success --hide" src="' . APBCT_URL_PATH . '/inc/images/yes.png" />'
705
+ . '</button>';
706
+ echo '&nbsp;&nbsp;';
707
+ }
708
+
709
+ // Output spam count
710
+ if($apbct->key_is_ok && apbct_api_key__is_correct()){
711
+ if(!$apbct->white_label){
712
+
713
+ // Support button
714
+ echo '<a class="cleantalk_link cleantalk_link-auto" target="__blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">'.__('Support', 'cleantalk-spam-protect').'</a>';
715
+ echo '&nbsp;&nbsp;';
716
+ echo '<br>'
717
+ . '<br>';
718
+ }
719
+ }
720
+
721
+ settings_fields('cleantalk_settings');
722
+ do_settings_fields('cleantalk', 'cleantalk_section_settings_main');
723
+
724
+ foreach($apbct->settings_fields_in_groups as $group_name => $group){
725
+
726
+ echo !empty($group['html_before']) ? $group['html_before'] : '';
727
+ echo !empty($group['title']) ? '<h3 style="margin-left: 220px;">'.$group['title'].'</h3>' : '';
728
+
729
+ do_settings_fields('cleantalk', 'apbct_section__'.$group_name);
730
+
731
+ echo !empty($group['html_after']) ? $group['html_after'] : '';
732
+
733
+ }
734
+
735
+ echo '<br>';
736
+ echo '<button name="submit" class="cleantalk_link cleantalk_link-manual" value="save_changes">'.__('Save Changes').'</button>';
737
+
738
+ echo "</form>";
739
+
740
+ if(!$apbct->white_label){
741
+ // Translate banner for non EN locale
742
+ if(substr(get_locale(), 0, 2) != 'en'){
743
+ global $ct_translate_banner_template;
744
+ require_once(CLEANTALK_PLUGIN_DIR.'templates/translate_banner.php');
745
+ printf($ct_translate_banner_template, substr(get_locale(), 0, 2));
746
+ }
747
+ }
748
+ }
749
+
750
+ function apbct_settings__display__network(){
751
+ // If it's network admin dashboard
752
+ if(is_network_admin()){
753
+ $site_url = get_site_option('siteurl');
754
+ $site_url = preg_match( '/\/$/', $site_url ) ? $site_url : $site_url . '/';
755
+ $link = $site_url . 'wp-admin/options-general.php?page=cleantalk';
756
+ printf("<h2>" . __("Please, enter the %splugin settings%s in main site dashboard.", 'cleantalk-spam-protect') . "</h2>", "<a href='$link'>", "</a>");
757
+ return;
758
+ }
759
+ }
760
+
761
+ function apbct_settings__error__output($return = false){
762
+
763
+ global $apbct;
764
+
765
+ // If have error message output error block.
766
+
767
+ $out = '';
768
+
769
+ if(!empty($apbct->errors) && !defined('CLEANTALK_ACCESS_KEY')){
770
+
771
+ $errors = $apbct->errors;
772
+
773
+ $error_texts = array(
774
+ // Misc
775
+ 'key_invalid' => __('Error occurred while API key validating. Error: ', 'cleantalk-spam-protect'),
776
+ 'key_get' => __('Error occurred while automatically gettings access key. Error: ', 'cleantalk-spam-protect'),
777
+ 'sfw_send_logs' => __('Error occurred while sending SpamFireWall logs. Error: ', 'cleantalk-spam-protect'),
778
+ 'sfw_update' => __('Error occurred while updating SpamFireWall local base. Error: ' , 'cleantalk-spam-protect'),
779
+ 'account_check' => __('Error occurred while checking account status. Error: ', 'cleantalk-spam-protect'),
780
+ 'api' => __('Error occurred while excuting API call. Error: ', 'cleantalk-spam-protect'),
781
+
782
+ // Validating settings
783
+ 'settings_validate' => 'Validate Settings',
784
+ 'exclusions_urls' => 'URL Exclusions',
785
+ 'exclusions_fields' => 'Field Exclusions',
786
+
787
+ // Unknown
788
+ 'unknown' => __('Unknown error. Error: ', 'cleantalk-spam-protect'),
789
+ );
790
+
791
+ $errors_out = array();
792
+
793
+ foreach($errors as $type => $error){
794
+
795
+ if(!empty($error)){
796
+
797
+ if(is_array(current($error))){
798
+
799
+ foreach($error as $sub_type => $sub_error){
800
+ $errors_out[$sub_type] = '';
801
+ if(isset($sub_error['error_time']))
802
+ $errors_out[$sub_type] .= date('Y-m-d H:i:s', $sub_error['error_time']) . ': ';
803
+ $errors_out[$sub_type] .= (isset($error_texts[$type]) ? $error_texts[$type] : ucfirst($type)) . ': ';
804
+ $errors_out[$sub_type] .= (isset($error_texts[$sub_type]) ? $error_texts[$sub_type] : $error_texts['unknown']) . ' ' . $sub_error['error'];
805
+ }
806
+ continue;
807
+ }
808
+
809
+ $errors_out[$type] = '';
810
+ if(isset($error['error_time']))
811
+ $errors_out[$type] .= date('Y-m-d H:i:s', $error['error_time']) . ': ';
812
+ $errors_out[$type] .= (isset($error_texts[$type]) ? $error_texts[$type] : $error_texts['unknown']) . ' ' . (isset($error['error']) ? $error['error'] : '');
813
+
814
+ }
815
+ }
816
+
817
+ if(!empty($errors_out)){
818
+ $out .= '<div id="apbctTopWarning" class="error" style="position: relative;">'
819
+ .'<h3 style="display: inline-block;">'.__('Errors:', 'cleantalk-spam-protect').'</h3>';
820
+ foreach($errors_out as $value){
821
+ $out .= '<h4>'.$value.'</h4>';
822
+ }
823
+ $out .= !$apbct->white_label
824
+ ? '<h4 style="text-align: unset;">'.sprintf(__('You can get support any time here: %s.', 'cleantalk-spam-protect'), '<a target="blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">https://wordpress.org/support/plugin/cleantalk-spam-protect</a>').'</h4>'
825
+ : '';
826
+ $out .= '</div>';
827
+ }
828
+ }
829
+
830
+ if($return) return $out; else echo $out;
831
+ }
832
+
833
+ function apbct_settings__field__debug(){
834
+
835
+ global $apbct;
836
+
837
+ if($apbct->debug){
838
+
839
+ echo '<hr /><h2>Debug:</h2>';
840
+ echo '<h4>Constants:</h4>';
841
+ echo 'CLEANTALK_AJAX_USE_BUFFER '. (defined('CLEANTALK_AJAX_USE_BUFFER') ? (CLEANTALK_AJAX_USE_BUFFER ? 'true' : 'flase') : 'NOT_DEFINED')."<br>";
842
+ echo 'CLEANTALK_AJAX_USE_FOOTER_HEADER '. (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') ? (CLEANTALK_AJAX_USE_FOOTER_HEADER ? 'true' : 'flase') : 'NOT_DEFINED')."<br>";
843
+ echo 'CLEANTALK_ACCESS_KEY '. (defined('CLEANTALK_ACCESS_KEY') ? (CLEANTALK_ACCESS_KEY ? CLEANTALK_ACCESS_KEY : 'flase') : 'NOT_DEFINED')."<br>";
844
+ echo 'CLEANTALK_CHECK_COMMENTS_NUMBER '. (defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? (CLEANTALK_CHECK_COMMENTS_NUMBER ? CLEANTALK_CHECK_COMMENTS_NUMBER : 0) : 'NOT_DEFINED')."<br>";
845
+ echo 'CLEANTALK_CHECK_MESSAGES_NUMBER '. (defined('CLEANTALK_CHECK_MESSAGES_NUMBER') ? (CLEANTALK_CHECK_MESSAGES_NUMBER ? CLEANTALK_CHECK_MESSAGES_NUMBER : 0) : 'NOT_DEFINED')."<br>";
846
+ echo 'CLEANTALK_PLUGIN_DIR '. (defined('CLEANTALK_PLUGIN_DIR') ? (CLEANTALK_PLUGIN_DIR ? CLEANTALK_PLUGIN_DIR : 'flase') : 'NOT_DEFINED')."<br>";
847
+ echo 'WP_ALLOW_MULTISITE '. (defined('WP_ALLOW_MULTISITE') ? (WP_ALLOW_MULTISITE ? 'true' : 'flase') : 'NOT_DEFINED');
848
+
849
+ echo "<h4>Debug log: <button type='submit' value='debug_drop' name='submit' style='font-size: 11px; padding: 1px;'>Drop debug data</button></h4>";
850
+ echo "<div style='height: 500px; width: 80%; overflow: auto;'>";
851
+
852
+ $output = print_r($apbct->debug, true);
853
+ $output = str_replace("\n", "<br>", $output);
854
+ $output = preg_replace("/[^\S]{4}/", "&nbsp;&nbsp;&nbsp;&nbsp;", $output);
855
+ echo "$output";
856
+
857
+ echo "</div>";
858
+
859
+ }
860
+ }
861
+
862
+ function apbct_settings__field__state(){
863
+
864
+ global $apbct;
865
+
866
+ $path_to_img = plugin_dir_url(__FILE__) . "images/";
867
+
868
+ $img = $path_to_img."yes.png";
869
+ $img_no = $path_to_img."no.png";
870
+ $img_no_gray = $path_to_img."no_gray.png";
871
+ $preloader = $path_to_img."preloader.gif";
872
+ $color="black";
873
+
874
+ if( ! $apbct->key_is_ok ){
875
+ $img=$path_to_img."no.png";
876
+ $img_no=$path_to_img."no.png";
877
+ $color="black";
878
+ }
879
+
880
+ if(!apbct_api_key__is_correct($apbct->api_key)){
881
+ $img = $path_to_img."yes_gray.png";
882
+ $img_no = $path_to_img."no_gray.png";
883
+ $color="gray";
884
+ }
885
+
886
+ if($apbct->moderate_ip){
887
+ $img = $path_to_img."yes.png";
888
+ $img_no = $path_to_img."no.png";
889
+ $color="black";
890
+ }
891
+
892
+ if( $apbct->moderate == 0 ){
893
+ $img = $path_to_img."no.png";
894
+ $img_no = $path_to_img."no.png";
895
+ $color="black";
896
+ }
897
+
898
+ print '<div class="apbct_settings-field_wrapper" style="color:'.$color.'">';
899
+
900
+ print '<h2>'.__('Protection is active', 'cleantalk-spam-protect').'</h2>';
901
+
902
+ echo '<img class="apbct_status_icon" src="'.($apbct->settings['registrations_test'] == 1 ? $img : $img_no).'"/>'.__('Registration forms', 'cleantalk-spam-protect');
903
+ echo '<img class="apbct_status_icon" src="'.($apbct->settings['comments_test'] == 1 ? $img : $img_no).'"/>'.__('Comments forms', 'cleantalk-spam-protect');
904
+ echo '<img class="apbct_status_icon" src="'.($apbct->settings['contact_forms_test'] == 1 ? $img : $img_no).'"/>'.__('Contact forms', 'cleantalk-spam-protect');
905
+ echo '<img class="apbct_status_icon" src="'.($apbct->settings['general_contact_forms_test'] == 1 ? $img : $img_no).'"/>'.__('Custom contact forms', 'cleantalk-spam-protect');
906
+ if(!$apbct->white_label || is_main_site())
907
+ echo '<img class="apbct_status_icon" src="'.($apbct->data['moderate'] == 1 ? $img : $img_no).'"/>'
908
+ .'<a style="color: black" href="https://blog.cleantalk.org/real-time-email-address-existence-validation/">'.__('Validate email for existence', 'cleantalk-spam-protect').'</a>';
909
+ // Autoupdate status
910
+ if($apbct->notice_auto_update && (!$apbct->white_label || is_main_site())){
911
+ echo '<img class="apbct_status_icon" src="'.($apbct->auto_update == 1 ? $img : ($apbct->auto_update == -1 ? $img_no : $img_no_gray)).'"/>'.__('Auto update', 'cleantalk-spam-protect')
912
+ .' <sup><a href="https://cleantalk.org/help/cleantalk-auto-update" target="_blank">?</a></sup>';
913
+ }
914
+
915
+ // WooCommerce
916
+ if(class_exists('WooCommerce'))
917
+ echo '<img class="apbct_status_icon" src="'.($apbct->settings['wc_checkout_test'] == 1 ? $img : $img_no).'"/>'.__('WooCommerce checkout form', 'cleantalk-spam-protect');
918
+ if($apbct->moderate_ip)
919
+ print "<br /><br />The anti-spam service is paid by your hosting provider. License #".$apbct->data['ip_license'].".<br />";
920
+
921
+ print "</div>";
922
+ }
923
+
924
+ /**
925
+ * Admin callback function - Displays inputs of 'apikey' plugin parameter
926
+ */
927
+ function apbct_settings__field__apikey(){
928
+
929
+ global $apbct;
930
+
931
+ echo '<div id="cleantalk_apikey_wrapper" class="apbct_settings-field_wrapper">';
932
+
933
+ // Using key from Main site, or from CLEANTALK_ACCESS_KEY constant
934
+ if(APBCT_WPMS && !is_main_site() && (!$apbct->allow_custom_key || defined('CLEANTALK_ACCESS_KEY'))){
935
+ _e('<h3>Key is provided by Super Admin.</h3>', 'cleantalk-spam-protect');
936
+ return;
937
+ }
938
+
939
+ echo '<label class="apbct_settings__label" for="cleantalk_apkey">' . __('Access key', 'cleantalk-spam-protect') . '</label>';
940
+
941
+ echo '<input
942
+ id="apbct_setting_apikey"
943
+ class="apbct_setting_text apbct_setting---apikey"
944
+ type="text"
945
+ name="cleantalk_settings[apikey]"
946
+ value="'
947
+ . ($apbct->key_is_ok
948
+ ? str_repeat('*', strlen($apbct->api_key))
949
+ : $apbct->api_key
950
+ )
951
+ . '"
952
+ key="' . $apbct->api_key . '"
953
+ size="20"
954
+ placeholder="' . __('Enter the key', 'cleantalk-spam-protect') . '"'
955
+ . ' />';
956
+
957
+ // Show account name associated with key
958
+ if(!empty($apbct->data['account_name_ob'])){
959
+ echo '<div class="apbct_display--none">'
960
+ . sprintf( __('Account at cleantalk.org is %s.', 'cleantalk-spam-protect'),
961
+ '<b>'.$apbct->data['account_name_ob'].'</b>'
962
+ )
963
+ . '</div>';
964
+ };
965
+
966
+ // Show key button
967
+ if((apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok)){
968
+ echo '<a id="apbct_showApiKey" class="ct_support_link" style="display: block" href="#">'
969
+ . __('Show the access key', 'cleantalk-spam-protect')
970
+ . '</a>';
971
+
972
+ // "Auto Get Key" buttons. License agreement
973
+ }else{
974
+
975
+ echo '<br /><br />';
976
+
977
+ // Auto get key
978
+ if(!$apbct->ip_license){
979
+ echo '<button class="cleantalk_link cleantalk_link-manual apbct_setting---get_key_auto" name="submit" type="submit" value="get_key_auto">'
980
+ .__('Get Access Key Automatically', 'cleantalk-spam-protect')
981
+ .'</button>';
982
+ echo '<input type="hidden" id="ct_admin_timezone" name="ct_admin_timezone" value="null" />';
983
+ echo '<br />';
984
+ echo '<br />';
985
+ }
986
+
987
+ // Warnings and GDPR
988
+ printf( __('Admin e-mail (%s) will be used for registration, if you want to use other email please %sGet Access Key Manually%s.', 'cleantalk-spam-protect'),
989
+ ct_get_admin_email(),
990
+ '<a class="apbct_color--gray" target="__blank" href="'
991
+ . sprintf( 'https://cleantalk.org/register?platform=wordpress&email=%s&website=%s',
992
+ urlencode(ct_get_admin_email()),
993
+ urlencode(parse_url(get_option('siteurl'),PHP_URL_HOST))
994
+ )
995
+ . '">',
996
+ '</a>'
997
+ );
998
+
999
+ // License agreement
1000
+ if(!$apbct->ip_license){
1001
+ echo '<div>';
1002
+ echo '<input checked type="checkbox" id="license_agreed" onclick="apbctSettingsDependencies(\'apbct_setting---get_key_auto\');"/>';
1003
+ echo '<label for="spbc_license_agreed">';
1004
+ printf( __('I accept %sLicense Agreement%s.', 'cleantalk-spam-protect'),
1005
+ '<a class = "apbct_color--gray" href="https://cleantalk.org/publicoffer" target="_blank">',
1006
+ '</a>'
1007
+ );
1008
+ echo "</label>";
1009
+ echo '</div>';
1010
+ }
1011
+ }
1012
+
1013
+ echo '</div>';
1014
+ }
1015
+
1016
+ function apbct_settings__field__action_buttons(){
1017
+
1018
+ global $apbct;
1019
+
1020
+ $links = apply_filters(
1021
+ 'apbct_settings_action_buttons',
1022
+ array(
1023
+ '<a href="edit-comments.php?page=ct_check_spam" class="ct_support_link">' . __('Check comments for spam', 'cleantalk-spam-protect') . '</a>',
1024
+ '<a href="users.php?page=ct_check_users" class="ct_support_link">' . __('Check users for spam', 'cleantalk-spam-protect') . '</a>',
1025
+ '<a href="#" class="ct_support_link" onclick="apbct_show_hide_elem(\'apbct_statistics\')">' . __('Statistics & Reports', 'cleantalk-spam-protect') . '</a>',
1026
+ )
1027
+ );
1028
+
1029
+ echo '<div class="apbct_settings-field_wrapper">';
1030
+
1031
+ if( apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok ){
1032
+ echo '<div>';
1033
+ foreach( $links as $link ) {
1034
+ echo $link . '&nbsp;&nbsp;&nbsp;&nbsp;';
1035
+ }
1036
+ echo '</div>';
1037
+ }
1038
+
1039
+ echo '</div>';
1040
+ }
1041
+
1042
+ function apbct_settings__field__statistics() {
1043
+
1044
+ global $apbct, $wpdb;
1045
+
1046
+ echo '<div id="apbct_statistics" class="apbct_settings-field_wrapper" style="display: none;">';
1047
+
1048
+ // Last request
1049
+ printf(
1050
+ __('Last spam check request to %s server was at %s.', 'cleantalk-spam-protect'),
1051
+ $apbct->stats['last_request']['server'] ? $apbct->stats['last_request']['server'] : __('unknown', 'cleantalk-spam-protect'),
1052
+ $apbct->stats['last_request']['time'] ? date('M d Y H:i:s', $apbct->stats['last_request']['time']) : __('unknown', 'cleantalk-spam-protect')
1053
+ );
1054
+ echo '<br>';
1055
+
1056
+ // Avarage time request
1057
+ printf(
1058
+ __('Average request time for past 7 days: %s seconds.', 'cleantalk-spam-protect'),
1059
+ $apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time']
1060
+ ? round($apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time'], 3)
1061
+ : __('unknown', 'cleantalk-spam-protect')
1062
+ );
1063
+ echo '<br>';
1064
+
1065
+ // SFW last die
1066
+ printf(
1067
+ __('Last time SpamFireWall was triggered for %s IP at %s', 'cleantalk-spam-protect'),
1068
+ $apbct->stats['last_sfw_block']['ip'] ? $apbct->stats['last_sfw_block']['ip'] : __('unknown', 'cleantalk-spam-protect'),
1069
+ $apbct->stats['last_sfw_block']['time'] ? date('M d Y H:i:s', $apbct->stats['last_sfw_block']['time']) : __('unknown', 'cleantalk-spam-protect')
1070
+ );
1071
+ echo '<br>';
1072
+
1073
+ // SFW last update
1074
+ $sfw_netwoks_amount = $wpdb->get_results("SELECT count(*) AS cnt FROM `".$wpdb->prefix."cleantalk_sfw`", ARRAY_A);
1075
+ printf(
1076
+ __('SpamFireWall was updated %s. Now contains %s entries.', 'cleantalk-spam-protect'),
1077
+ $apbct->stats['sfw']['last_update_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_update_time']) : __('unknown', 'cleantalk-spam-protect'),
1078
+ isset($sfw_netwoks_amount[0]['cnt']) ? $sfw_netwoks_amount[0]['cnt'] : __('unknown', 'cleantalk-spam-protect')
1079
+ );
1080
+ echo '<br>';
1081
+
1082
+ // SFW last sent logs
1083
+ printf(
1084
+ __('SpamFireWall sent %s events at %s.', 'cleantalk-spam-protect'),
1085
+ $apbct->stats['sfw']['last_send_amount'] ? $apbct->stats['sfw']['last_send_amount'] : __('unknown', 'cleantalk-spam-protect'),
1086
+ $apbct->stats['sfw']['last_send_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_send_time']) : __('unknown', 'cleantalk-spam-protect')
1087
+ );
1088
+ echo '<br>';
1089
+
1090
+ // Connection reports
1091
+ if ($apbct->connection_reports){
1092
+
1093
+ if ($apbct->connection_reports['negative'] == 0){
1094
+ _e('There are no failed connections to server.', 'cleantalk-spam-protect');
1095
+ }else{
1096
+ echo "<table id='negative_reports_table''>
1097
+ <tr>
1098
+ <td>#</td>
1099
+ <td><b>Date</b></td>
1100
+ <td><b>Page URL</b></td>
1101
+ <td><b>Report</b></td>
1102
+ <td><b>Server IP</b></td>
1103
+ </tr>";
1104
+ foreach($apbct->connection_reports['negative_report'] as $key => $report){
1105
+ echo '<tr>'
1106
+ . '<td>'.($key+1).'.</td>'
1107
+ . '<td>'.$report['date'].'</td>'
1108
+ . '<td>'.$report['page_url'].'</td>'
1109
+ . '<td>'.$report['lib_report'].'</td>'
1110
+ . '<td>'.$report['work_url'].'</td>'
1111
+ . '</tr>';
1112
+ }
1113
+ echo "</table>";
1114
+ echo '<br/>';
1115
+ echo '<button'
1116
+ . ' name="submit"'
1117
+ . ' class="cleantalk_link cleantalk_link-manual"'
1118
+ . ' value="ct_send_connection_report"'
1119
+ . (!$apbct->settings['send_connection_reports'] ? ' disabled="disabled"' : '')
1120
+ . '>'
1121
+ .__('Send report', 'cleantalk-spam-protect')
1122
+ .'</button>';
1123
+ if (!$apbct->settings['send_connection_reports']){
1124
+ echo '<br><br>';
1125
+ _e('Please, enable "Send connection reports" setting to be able to send reports', 'cleantalk-spam-protect');
1126
+ }
1127
+ }
1128
+
1129
+ }
1130
+
1131
+ echo '<br/>';
1132
+ echo 'Plugin version: ' . APBCT_VERSION;
1133
+
1134
+ echo '</div>';
1135
+ }
1136
+ function apbct_get_all_child_domains($except_main_site = false) {
1137
+ global $wpdb;
1138
+ $blogs = array();
1139
+ $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM '. $wpdb->blogs, OBJECT_K);
1140
+
1141
+ if ($except_main_site) {
1142
+ foreach ($wp_blogs as $blog) {
1143
+ if ($blog->blog_id != $blog->site_id)
1144
+ $blogs[] = get_blog_details( array( 'blog_id' => $blog->blog_id ) )->blogname;
1145
+ }
1146
+ }
1147
+ return $blogs;
1148
+ }
1149
+ /**
1150
+ * Get all current Wordpress roles, could except 'subscriber' role
1151
+ *
1152
+ * @param bool $except_subscriber
1153
+ *
1154
+ * @return array
1155
+ */
1156
+ function apbct_get_all_roles($except_subscriber = false) {
1157
+
1158
+ global $wp_roles;
1159
+
1160
+ $wp_roles = new WP_Roles();
1161
+ $roles = $wp_roles->get_names();
1162
+
1163
+ if($except_subscriber) {
1164
+ $key = array_search( 'Subscriber', $roles );
1165
+ if ( $key !== false ) {
1166
+ unset( $roles[ $key ] );
1167
+ }
1168
+ }
1169
+
1170
+ return $roles;
1171
+ }
1172
+
1173
+ function apbct_settings__field__draw($params = array()){
1174
+
1175
+ global $apbct;
1176
+
1177
+ $value = $params['network'] ? $apbct->network_settings[$params['name']] : $apbct->settings[$params['name']];
1178
+ $value_parent = $params['parent']
1179
+ ? ($params['network'] ? $apbct->network_settings[$params['parent']] : $apbct->settings[$params['parent']])
1180
+ : false;
1181
+
1182
+ // Is element is disabled
1183
+ $disabled = $params['parent'] && !$value_parent ? ' disabled="disabled"' : ''; // Strait
1184
+ $disabled = $params['parent'] && $params['reverse_trigger'] && !$value_parent ? ' disabled="disabled"' : $disabled; // Reverse logic
1185
+ $disabled = $params['disabled'] ? ' disabled="disabled"' : $disabled; // Direct disable from params
1186
+ $disabled = ! is_main_site() && $apbct->network_settings && ! $apbct->network_settings['allow_custom_settings'] ? ' disabled="disabled"' : $disabled; // Disabled by super admin on sub-sites
1187
+
1188
+ $childrens = $params['childrens'] ? 'apbct_setting---' . implode(",apbct_setting---",$params['childrens']) : '';
1189
+ $hide = $params['hide'] ? implode(",",$params['hide']) : '';
1190
+
1191
+ echo '<div class="'.$params['def_class'].(isset($params['class']) ? ' '.$params['class'] : '').'">';
1192
+
1193
+ switch($params['type']){
1194
+
1195
+ // Checkbox type
1196
+ case 'checkbox':
1197
+ echo '<input
1198
+ type="checkbox"
1199
+ name="cleantalk_settings['.$params['name'].']"
1200
+ id="apbct_setting_'.$params['name'].'"
1201
+ value="1" '
1202
+ ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1203
+ .($value == '1' ? ' checked' : '')
1204
+ .$disabled
1205
+ .($params['required'] ? ' required="required"' : '')
1206
+ .($params['childrens'] ? ' apbct_children="'. $childrens .'"' : '')
1207
+ .' onchange="'
1208
+ . ($params['childrens'] ? ' apbctSettingsDependencies(\''. $childrens .'\');' : '')
1209
+ . ($params['hide'] ? ' apbct_show_hide_elem(\''. $hide . '\');' : '')
1210
+ . '"'
1211
+ .' />'
1212
+ .'<label for="apbct_setting_'.$params['name'].'" class="apbct_setting-field_title--'.$params['type'].'">'
1213
+ .$params['title']
1214
+ .'</label>';
1215
+ echo isset($params['long_description'])
1216
+ ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1217
+ : '';
1218
+ echo '<div class="apbct_settings-field_description">'
1219
+ .$params['description']
1220
+ .'</div>';
1221
+ break;
1222
+
1223
+ // Radio type
1224
+ case 'radio':
1225
+
1226
+ // Title
1227
+ echo isset($params['title'])
1228
+ ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
1229
+ : '';
1230
+
1231
+ // Popup description
1232
+ echo isset($params['long_description'])
1233
+ ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1234
+ : '';
1235
+
1236
+ echo '<div class="apbct_settings-field_content apbct_settings-field_content--'.$params['type'].'">';
1237
+
1238
+ echo '<div class="apbct_switchers" style="direction: ltr">';
1239
+ foreach($params['options'] as $option){
1240
+ echo '<input'
1241
+ .' type="radio"'
1242
+ ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1243
+ ." id='apbct_setting_{$params['name']}__{$option['label']}'"
1244
+ .' name="cleantalk_settings['.$params['name'].']"'
1245
+ .' value="'.$option['val'].'"'
1246
+ . $disabled
1247
+ .($params['childrens']
1248
+ ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\', ' . $option['childrens_enable'] . ')"'
1249
+ : ''
1250
+ )
1251
+ .($value == $option['val'] ? ' checked' : '')
1252
+ .($params['required'] ? ' required="required"' : '')
1253
+ .' />';
1254
+ echo '<label for="apbct_setting_'.$params['name'].'__'.$option['label'].'"> ' . $option['label'] . '</label>';
1255
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1256
+ }
1257
+ echo '</div>';
1258
+
1259
+ echo isset($params['description'])
1260
+ ? '<div class="apbct_settings-field_description">'.$params['description'].'</div>'
1261
+ : '';
1262
+
1263
+ echo '</div>';
1264
+ break;
1265
+
1266
+ // Dropdown list type
1267
+ case 'select':
1268
+ echo isset($params['title'])
1269
+ ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
1270
+ : '';
1271
+ echo isset($params['long_description'])
1272
+ ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1273
+ : '';
1274
+ echo '<select'
1275
+ . ' id="apbct_setting_'.$params['name'].'"'
1276
+ . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1277
+ . ' name="cleantalk_settings['.$params['name'].']'.($params['multiple'] ? '[]"' : '"')
1278
+ . ($params['multiple'] ? ' size="'. count($params['options']). '""' : '')
1279
+ . ($params['multiple'] ? ' multiple="multiple"' : '')
1280
+ . $disabled
1281
+ . ($params['required'] ? ' required="required"' : '')
1282
+ . ' >';
1283
+
1284
+ foreach($params['options'] as $option){
1285
+ echo '<option'
1286
+ . ' value="' . $option['val'] . '"'
1287
+ . ($params['multiple']
1288
+ ? (!empty($value) && in_array($option['val'], $value) ? ' selected="selected"' : '')
1289
+ : ($value == $option['val'] ? 'selected="selected"' : '')
1290
+ )
1291
+ .'>'
1292
+ . $option['label']
1293
+ . '</option>';
1294
+ }
1295
+
1296
+ echo '</select>';
1297
+ echo isset($params['long_description'])
1298
+ ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1299
+ : '';
1300
+ echo isset($params['description'])
1301
+ ? '<div class="apbct_settings-field_description">'.$params['description'].'</div>'
1302
+ : '';
1303
+
1304
+ break;
1305
+
1306
+ // Text type
1307
+ case 'text':
1308
+
1309
+ echo '<input
1310
+ type="text"
1311
+ id="apbct_setting_'.$params['name'].'"
1312
+ name="cleantalk_settings['.$params['name'].']"'
1313
+ ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1314
+ .' value="'. $value .'" '
1315
+ .$disabled
1316
+ .($params['required'] ? ' required="required"' : '')
1317
+ .($params['childrens'] ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\')"' : '')
1318
+ .' />'
1319
+ . '&nbsp;'
1320
+ .'<label for="apbct_setting_'.$params['name'].'" class="apbct_setting-field_title--'.$params['type'].'">'
1321
+ .$params['title']
1322
+ .'</label>';
1323
+ echo '<div class="apbct_settings-field_description">'
1324
+ .$params['description']
1325
+ .'</div>';
1326
+ break;
1327
+ }
1328
+
1329
+ echo '</div>';
1330
+ }
1331
+
1332
+ /**
1333
+ * Admin callback function - Plugin parameters validator
1334
+ *
1335
+ * @global \Cleantalk\ApbctWP\State $apbct
1336
+ * @param array $settings Array with passed settings
1337
+ * @return array Array with processed settings
1338
+ */
1339
+ function apbct_settings__validate($settings) {
1340
+
1341
+ global $apbct;
1342
+
1343
+ // If user is not allowed to manage settings. Get settings from the storage
1344
+ if( ! is_main_site() && ( ! $apbct->network_settings['allow_custom_settings'] ) ){
1345
+ foreach ($apbct->settings as $key => $setting){
1346
+ $settings[ $key ] = $setting;
1347
+ }
1348
+ }
1349
+
1350
+ // Set missing settings.
1351
+ foreach($apbct->def_settings as $setting => $value){
1352
+ if(!isset($settings[$setting])){
1353
+ $settings[$setting] = null;
1354
+ settype($settings[$setting], gettype($value));
1355
+ }
1356
+ } unset($setting, $value);
1357
+
1358
+ // Set missing settings.
1359
+ foreach($apbct->def_network_settings as $setting => $value){
1360
+ if(!isset($settings[$setting])){
1361
+ $settings[$setting] = null;
1362
+ settype($settings[$setting], gettype($value));
1363
+ }
1364
+ } unset($setting, $value);
1365
+
1366
+ //Sanitizing sfw__anti_flood__view_limit setting
1367
+ $settings['sfw__anti_flood__view_limit'] = floor( intval( $settings['sfw__anti_flood__view_limit'] ) );
1368
+ $settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] == 0 ? 10 : $settings['sfw__anti_flood__view_limit'] ); // Default if 0 passed
1369
+ $settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] < 5 ? 5 : $settings['sfw__anti_flood__view_limit'] ); //
1370
+
1371
+ // Auto getting key
1372
+ if (isset($_POST['submit']) && $_POST['submit'] == 'get_key_auto'){
1373
+
1374
+ $website = parse_url(get_option('siteurl'), PHP_URL_HOST).parse_url(get_option('siteurl'), PHP_URL_PATH);
1375
+ $platform = 'wordpress';
1376
+ $user_ip = \Cleantalk\ApbctWP\Helper::ip__get(array('real'), false);
1377
+ $timezone = filter_input(INPUT_POST, 'ct_admin_timezone');
1378
+ $language = apbct_get_server_variable( 'HTTP_ACCEPT_LANGUAGE' );
1379
+ $wpms = APBCT_WPMS && defined('SUBDOMAIN_INSTALL') && !SUBDOMAIN_INSTALL ? true : false;
1380
+ $white_label = $apbct->network_settings['white_label'] ? 1 : 0;
1381
+ $hoster_api_key = $apbct->network_settings['white_label__hoster_key'] ? $apbct->network_settings['white_label__hoster_key'] : '';
1382
+
1383
+ $result = \Cleantalk\ApbctWP\API::method__get_api_key(
1384
+ ! is_main_site() && $apbct->white_label ? 'anti-spam-hosting' : 'antispam',
1385
+ ct_get_admin_email(),
1386
+ $website,
1387
+ $platform,
1388
+ $timezone,
1389
+ $language,
1390
+ $user_ip,
1391
+ $wpms,
1392
+ $white_label,
1393
+ $hoster_api_key
1394
+ );
1395
+
1396
+ if(empty($result['error'])){
1397
+
1398
+ if(isset($result['user_token'])){
1399
+ $apbct->data['user_token'] = $result['user_token'];
1400
+ }
1401
+
1402
+ if(!empty($result['auth_key'])){
1403
+ $settings['apikey'] = $result['auth_key'];
1404
+ }
1405
+
1406
+ }else{
1407
+ $apbct->error_add(
1408
+ 'key_get',
1409
+ $result['error']
1410
+ . ($apbct->white_label
1411
+ ? ' <button name="submit" type="submit" class="cleantalk_link cleantalk_link-manual" value="get_key_auto">'
1412
+ : ''
1413
+ )
1414
+ );
1415
+ }
1416
+ }
1417
+
1418
+ // Validating API key
1419
+ $settings['apikey'] = strpos($settings['apikey'], '*') === false ? $settings['apikey'] : $apbct->settings['apikey'];
1420
+
1421
+ $apbct->data['key_changed'] = $settings['apikey'] !== $apbct->settings['apikey'];
1422
+
1423
+ $settings['apikey'] = !empty($settings['apikey']) ? trim($settings['apikey']) : '';
1424
+ $settings['apikey'] = defined( 'CLEANTALK_ACCESS_KEY') ? CLEANTALK_ACCESS_KEY : $settings['apikey'];
1425
+ $settings['apikey'] = ! is_main_site() && $apbct->white_label ? $apbct->settings['apikey'] : $settings['apikey'];
1426
+ $settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $settings['apikey'] : $apbct->network_settings['apikey'];
1427
+ $settings['apikey'] = is_main_site() || !$settings['white_label'] ? $settings['apikey'] : $apbct->settings['apikey'];
1428
+
1429
+ // Sanitize setting values
1430
+ foreach ($settings as &$setting ){
1431
+ if( is_scalar( $setting ) )
1432
+ $setting = preg_replace( '/[<"\'>]/', '', trim( $setting ) ); // Make HTML code inactive
1433
+ }
1434
+
1435
+ // Validate Exclusions
1436
+ // URLs
1437
+ $result = apbct_settings__sanitize__exclusions($settings['exclusions__urls'], $settings['exclusions__urls__use_regexp']);
1438
+ $result === false
1439
+ ? $apbct->error_add( 'exclusions_urls', 'is not valid: "' . $settings['exclusions__urls'] . '"', 'settings_validate' )
1440
+ : $apbct->error_delete( 'exclusions_urls', true, 'settings_validate' );
1441
+ $settings['exclusions__urls'] = $result ? $result: '';
1442
+
1443
+ // Fields
1444
+ $result = apbct_settings__sanitize__exclusions($settings['exclusions__fields'], $settings['exclusions__fields__use_regexp']);
1445
+ $result === false
1446
+ ? $apbct->error_add( 'exclusions_fields', 'is not valid: "' . $settings['exclusions__fields'] . '"', 'settings_validate' )
1447
+ : $apbct->error_delete( 'exclusions_fields', true, 'settings_validate' );
1448
+ $settings['exclusions__fields'] = $result ? $result: '';
1449
+
1450
+ // WPMS Logic.
1451
+ if(APBCT_WPMS && is_main_site()){
1452
+ $network_settings = array(
1453
+ 'allow_custom_key' => $settings['allow_custom_key'],
1454
+ 'allow_custom_settings' => $settings['allow_custom_settings'],
1455
+ 'white_label' => $settings['white_label'],
1456
+ 'white_label__hoster_key' => $settings['white_label__hoster_key'],
1457
+ 'white_label__plugin_name' => $settings['white_label__plugin_name'],
1458
+ 'use_settings_template' => $settings['use_settings_template'],
1459
+ 'use_settings_template_apply_for_new' => $settings['use_settings_template_apply_for_new'],
1460
+ 'use_settings_template_apply_for_current' => $settings['use_settings_template_apply_for_current'],
1461
+ 'use_settings_template_apply_for_current_list_sites' => $settings['use_settings_template_apply_for_current_list_sites'],
1462
+ );
1463
+ unset( $settings['allow_custom_key'], $settings['white_label'], $settings['white_label__hoster_key'], $settings['white_label__plugin_name'] );
1464
+ }
1465
+
1466
+ // Drop debug data
1467
+ if (isset($_POST['submit']) && $_POST['submit'] == 'debug_drop'){
1468
+ $apbct->debug = false;
1469
+ delete_option('cleantalk_debug');
1470
+ return $settings;
1471
+ }
1472
+
1473
+ // Send connection reports
1474
+ if (isset($_POST['submit']) && $_POST['submit'] == 'ct_send_connection_report'){
1475
+ ct_mail_send_connection_report();
1476
+ return $settings;
1477
+ }
1478
+
1479
+ $apbct->saveData();
1480
+
1481
+ // WPMS Logic.
1482
+ if(APBCT_WPMS){
1483
+ if(is_main_site()){
1484
+
1485
+ // Network settings
1486
+ $network_settings['apikey'] = $settings['apikey'];
1487
+ $apbct->network_settings = $network_settings;
1488
+ $apbct->saveNetworkSettings();
1489
+
1490
+ // Network data
1491
+ $apbct->network_data = array(
1492
+ 'key_is_ok' => $apbct->data['key_is_ok'],
1493
+ 'moderate' => $apbct->data['moderate'],
1494
+ 'valid' => $apbct->data['valid'],
1495
+ 'auto_update' => $apbct->data['auto_update'],
1496
+ 'user_token' => $apbct->data['user_token'],
1497
+ 'service_id' => $apbct->data['service_id'],
1498
+ );
1499
+ $apbct->saveNetworkData();
1500
+ if (isset($settings['use_settings_template_apply_for_current_list_sites']) && !empty($settings['use_settings_template_apply_for_current_list_sites'])) {
1501
+ apbct_update_blogs_options($settings['use_settings_template_apply_for_current_list_sites'], $settings);
1502
+ }
1503
+ }
1504
+ if(!$apbct->white_label && !is_main_site() && !$apbct->allow_custom_key){
1505
+ $settings['apikey'] = '';
1506
+ }
1507
+ }
1508
+
1509
+ return $settings;
1510
+ }
1511
+
1512
+ function apbct_settings__sync( $direct_call = false ){
1513
+
1514
+ if( ! $direct_call )
1515
+ check_ajax_referer('ct_secret_nonce' );
1516
+
1517
+ global $apbct;
1518
+
1519
+ // Feedback with app_agent
1520
+ ct_send_feedback('0:' . APBCT_AGENT); // 0 - request_id, agent version.
1521
+
1522
+ // Key is good by default
1523
+ $apbct->data['key_is_ok'] = true;
1524
+
1525
+ // Checking account status
1526
+ $result = ct_account_status_check( $apbct->settings['apikey'] );
1527
+
1528
+ // Is key valid?
1529
+ if( $result ){
1530
+
1531
+ // Deleting errors about invalid key
1532
+ $apbct->error_delete( 'key_invalid key_get', 'save' );
1533
+
1534
+ // SFW actions
1535
+ if( $apbct->settings['spam_firewall'] == 1 ){
1536
+
1537
+ $result = ct_sfw_update( $apbct->settings['apikey'] );
1538
+ if( ! empty( $result['error'] ) )
1539
+ $apbct->error_add( 'sfw_update', $result['error'] );
1540
+
1541
+ $result = ct_sfw_send_logs( $apbct->settings['apikey'] );
1542
+ if( ! empty( $result['error'] ) )
1543
+ $apbct->error_add( 'sfw_send_logs', $result['error'] );
1544
+
1545
+ }
1546
+
1547
+ // Updating brief data for dashboard widget
1548
+ $apbct->data['brief_data'] = \Cleantalk\ApbctWP\API::method__get_antispam_report_breif( $apbct->settings['apikey'] );
1549
+
1550
+ // Key is not valid
1551
+ }else{
1552
+ $apbct->data['key_is_ok'] = false;
1553
+ $apbct->error_add( 'key_invalid', __( 'Testing is failed. Please check the Access key.', 'cleantalk-spam-protect' ) );
1554
+ }
1555
+
1556
+ // WPMS Logic.
1557
+ if(APBCT_WPMS){
1558
+ if(is_main_site()){
1559
+
1560
+ // Network settings
1561
+ $network_settings['apikey'] = $apbct->settings['apikey'];
1562
+ $apbct->network_settings = $network_settings;
1563
+ $apbct->saveNetworkSettings();
1564
+
1565
+ // Network data
1566
+ $apbct->network_data = array(
1567
+ 'key_is_ok' => $apbct->data['key_is_ok'],
1568
+ 'moderate' => $apbct->data['moderate'],
1569
+ 'valid' => $apbct->data['valid'],
1570
+ 'auto_update' => $apbct->data['auto_update'],
1571
+ 'user_token' => $apbct->data['user_token'],
1572
+ 'service_id' => $apbct->data['service_id'],
1573
+ );
1574
+ $apbct->saveNetworkData();
1575
+ if (isset($settings['use_settings_template_apply_for_current_list_sites']) && !empty($settings['use_settings_template_apply_for_current_list_sites'])) {
1576
+ apbct_update_blogs_options($settings['use_settings_template_apply_for_current_list_sites'], $settings);
1577
+ }
1578
+ }
1579
+ if(!$apbct->white_label && !is_main_site() && !$apbct->allow_custom_key){
1580
+ $settings['apikey'] = '';
1581
+ }
1582
+ }
1583
+
1584
+ if($apbct->data['key_is_ok'] == false && $apbct->data['moderate_ip'] == 0){
1585
+
1586
+ // Notices
1587
+ $apbct->data['notice_show'] = 1;
1588
+ $apbct->data['notice_renew'] = 0;
1589
+ $apbct->data['notice_trial'] = 0;
1590
+ $apbct->data['notice_review'] = 0;
1591
+ $apbct->data['notice_auto_update'] = 0;
1592
+
1593
+ // Other
1594
+ $apbct->data['service_id'] = 0;
1595
+ $apbct->data['valid'] = 0;
1596
+ $apbct->data['moderate'] = 0;
1597
+ $apbct->data['ip_license'] = 0;
1598
+ $apbct->data['moderate_ip'] = 0;
1599
+ $apbct->data['spam_count'] = 0;
1600
+ $apbct->data['auto_update'] = 0;
1601
+ $apbct->data['user_token'] = '';
1602
+ $apbct->data['license_trial'] = 0;
1603
+ $apbct->data['account_name_ob'] = '';
1604
+ }
1605
+
1606
+ $out = array(
1607
+ 'success' => true,
1608
+ 'reload' => $apbct->data['key_changed'],
1609
+ );
1610
+
1611
+ $apbct->data['key_changed'] = false;
1612
+
1613
+ $apbct->saveData();
1614
+
1615
+ die( json_encode( $out ) );
1616
+ }
1617
+
1618
+ function apbct_update_blogs_options ($blog_names = array(), $settings) {
1619
+ global $wpdb;
1620
+
1621
+ $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM '. $wpdb->blogs, OBJECT_K);
1622
+
1623
+ foreach ($wp_blogs as $blog) {
1624
+ $blog_name = get_blog_details( array( 'blog_id' => $blog->blog_id ) )->blogname;
1625
+ if (in_array($blog_name, $blog_names)) {
1626
+ update_blog_option ($blog->blog_id, 'cleantalk_settings', $settings);
1627
+ }
1628
+ }
1629
+ }
1630
+ /**
1631
+ * Sanitize and validate exclusions.
1632
+ * Explode given string by commas and trim each string.
1633
+ * Skip element if it's empty.
1634
+ *
1635
+ * Return false if exclusion is bad
1636
+ * Return sanitized string if all is ok
1637
+ *
1638
+ * @param string $exclusions
1639
+ * @param bool $regexp
1640
+ *
1641
+ * @return bool|string
1642
+ */
1643
+ function apbct_settings__sanitize__exclusions($exclusions, $regexp = false){
1644
+ $result = array();
1645
+ if( ! empty( $exclusions ) ){
1646
+ $exclusions = explode( ',', $exclusions );
1647
+ foreach ( $exclusions as $exclusion ){
1648
+ $sanitized_exclusion = trim( $exclusion );
1649
+ if ( ! empty( $sanitized_exclusion ) ) {
1650
+ if( $regexp && ! apbct_is_regexp( $exclusion ) )
1651
+ return false;
1652
+ $result[] = $sanitized_exclusion;
1653
+ }
1654
+ }
1655
+ }
1656
+ return implode( ',', $result );
1657
+ }
1658
+
1659
+ function apbct_settings_show_gdpr_text($print = false){
1660
+
1661
+ $out = wpautop('The notice requirements remain and are expanded. They must include the retention time for personal data, and contact information for data controller and data protection officer has to be provided.
1662
+ Automated individual decision-making, including profiling (Article 22) is contestable, similarly to the Data Protection Directive (Article 15). Citizens have rights to question and fight significant decisions that affect them that have been made on a solely-algorithmic basis. Many media outlets have commented on the introduction of a "right to explanation" of algorithmic decisions, but legal scholars have since argued that the existence of such a right is highly unclear without judicial tests and is limited at best.
1663
+ To be able to demonstrate compliance with the GDPR, the data controller should implement measures, which meet the principles of data protection by design and data protection by default. Privacy by design and by default (Article 25) require data protection measures to be designed into the development of business processes for products and services. Such measures include pseudonymising personal data, by the controller, as soon as possible (Recital 78).
1664
+ It is the responsibility and the liability of the data controller to implement effective measures and be able to demonstrate the compliance of processing activities even if the processing is carried out by a data processor on behalf of the controller (Recital 74).
1665
+ Data Protection Impact Assessments (Article 35) have to be conducted when specific risks occur to the rights and freedoms of data subjects. Risk assessment and mitigation is required and prior approval of the national data protection authorities (DPAs) is required for high risks. Data protection officers (Articles 37–39) are required to ensure compliance within organisations.
1666
+ They have to be appointed:')
1667
+ .'<ul style="padding: 0px 25px; list-style: disc;">'
1668
+ .'<li>for all public authorities, except for courts acting in their judicial capacity</li>'
1669
+ .'<li>if the core activities of the controller or the processor are:</li>'
1670
+ .'<ul style="padding: 0px 25px; list-style: disc;">'
1671
+ .'<li>processing operations, which, by virtue of their nature, their scope and/or their purposes, require regular and systematic monitoring of data subjects on a large scale</li>'
1672
+ .'<li>processing on a large scale of special categories of data pursuant to Article 9 and personal data relating to criminal convictions and offences referred to in Article 10;</li>'
1673
+ .'</ul>'
1674
+ .'</li>'
1675
+ .'</ul>';
1676
+
1677
+ if($print) echo $out; else return $out;
1678
+ }
1679
+
1680
+ function apbct_settings__get__long_description(){
1681
+
1682
+ global $apbct;
1683
+
1684
+ check_ajax_referer('ct_secret_nonce' );
1685
+
1686
+ $setting_id = $_POST['setting_id'] ? $_POST['setting_id'] : '';
1687
+
1688
+ $descriptions = array(
1689
+ 'white_label' => array(
1690
+ 'title' => __( 'XSS check', 'cleantalk-spam-protect'),
1691
+ 'desc' => __( 'Cross-Site Scripting (XSS) — prevents malicious code to be executed/sent to any user. As a result malicious scripts can not get access to the cookie files, session tokens and any other confidential information browsers use and store. Such scripts can even overwrite content of HTML pages. CleanTalk WAF monitors for patterns of these parameters and block them.', 'cleantalk-spam-protect'),
1692
+ ),
1693
+ 'white_label__hoster_key' => array(
1694
+ 'title' => __( 'SQL-injection check', 'cleantalk-spam-protect'),
1695
+ 'desc' => __( 'SQL Injection — one of the most popular ways to hack websites and programs that work with databases. It is based on injection of a custom SQL code into database queries. It could transmit data through GET, POST requests or cookie files in an SQL code. If a website is vulnerable and execute such injections then it would allow attackers to apply changes to the website\'s MySQL database.', 'cleantalk-spam-protect'),
1696
+ ),
1697
+ 'white_label__plugin_name' => array(
1698
+ 'title' => __( 'Check uploaded files', 'cleantalk-spam-protect'),
1699
+ 'desc' => __( 'The option checks each uploaded file to a website for malicious code. If it\'s possible for visitors to upload files to a website, for instance a work resume, then attackers could abuse it and upload an infected file to execute it later and get access to your website.', 'cleantalk-spam-protect'),
1700
+ ),
1701
+ );
1702
+
1703
+ die(json_encode($descriptions[$setting_id]));
1704
+ }
1705
+
1706
+ function apbct_settings__check_renew_banner() {
1707
+ global $apbct;
1708
+
1709
+ check_ajax_referer('ct_secret_nonce' );
1710
+
1711
+ die(json_encode(array('close_renew_banner' => ($apbct->data['notice_trial'] == 0 && $apbct->data['notice_renew'] == 0) ? true : false)));
1712
  }
inc/cleantalk-updater.php CHANGED
@@ -1,578 +1,597 @@
1
- <?php
2
-
3
- use Cleantalk\ApbctWP\Cron;
4
-
5
- function apbct_run_update_actions($current_version, $new_version){
6
-
7
- $current_version = apbct_version_standartization($current_version);
8
- $new_version = apbct_version_standartization($new_version);
9
-
10
- $current_version_str = implode('.', $current_version);
11
- $new_version_str = implode('.', $new_version);
12
-
13
- for($ver_major = $current_version[0]; $ver_major <= $new_version[0]; $ver_major++){
14
- for($ver_minor = 0; $ver_minor <= 200; $ver_minor++){
15
- for($ver_fix = 0; $ver_fix <= 10; $ver_fix++){
16
-
17
- if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $current_version_str, '<='))
18
- continue;
19
-
20
- if(function_exists("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}")){
21
- $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}");
22
- if(!empty($result['error']))
23
- break;
24
- }
25
-
26
- if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $new_version_str, '>='))
27
- break(2);
28
-
29
- }
30
- }
31
- }
32
-
33
- return true;
34
-
35
- }
36
-
37
- function apbct_version_standartization($version){
38
-
39
- $version = explode('.', $version);
40
- $version = !empty($version) ? $version : array();
41
-
42
- $version[0] = !empty($version[0]) ? (int)$version[0] : 0;
43
- $version[1] = !empty($version[1]) ? (int)$version[1] : 0;
44
- $version[2] = !empty($version[2]) ? (int)$version[2] : 0;
45
-
46
- return $version;
47
- }
48
-
49
- function apbct_update_to_5_50_0(){
50
- global $wpdb;
51
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_DATA .'` (
52
- `network` int(11) unsigned NOT NULL,
53
- `mask` int(11) unsigned NOT NULL,
54
- INDEX ( `network` , `mask` )
55
- );');
56
-
57
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_LOG .'` (
58
- `ip` VARCHAR(15) NOT NULL ,
59
- `all` INT NOT NULL ,
60
- `blocked` INT NOT NULL ,
61
- `timestamp` INT NOT NULL ,
62
- PRIMARY KEY (`ip`));');
63
- }
64
-
65
- function apbct_update_to_5_56_0(){
66
- if (!wp_next_scheduled('cleantalk_update_sfw_hook'))
67
- wp_schedule_event(time()+1800, 'daily', 'cleantalk_update_sfw_hook' );
68
- }
69
- function apbct_update_to_5_70_0(){
70
-
71
- global $wpdb;
72
-
73
- if(!in_array('all_entries', $wpdb->get_col('DESC '. APBCT_TBL_FIREWALL_LOG, 0))){
74
- $wpdb->query('ALTER TABLE `'. APBCT_TBL_FIREWALL_LOG .'`
75
- CHANGE `all` `all_entries` INT(11) NOT NULL,
76
- CHANGE `blocked` `blocked_entries` INT(11) NOT NULL,
77
- CHANGE `timestamp` `entries_timestamp` INT(11) NOT NULL;'
78
- );
79
- }
80
-
81
- // Deleting usless data
82
- delete_option('cleantalk_sends_reports_till');
83
- delete_option('cleantalk_activation_timestamp');
84
-
85
- // Disabling WP_Cron tasks
86
- wp_clear_scheduled_hook('cleantalk_send_daily_report_hook');
87
- wp_clear_scheduled_hook('ct_hourly_event_hook');
88
- wp_clear_scheduled_hook('ct_send_sfw_log');
89
- wp_clear_scheduled_hook('cleantalk_update_sfw_hook');
90
- wp_clear_scheduled_hook('cleantalk_get_brief_data_hook');
91
-
92
- // Adding Self cron system tasks
93
- Cron::addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // New
94
- Cron::addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500);
95
- Cron::addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500);
96
- Cron::addTask('sfw_update', 'ct_sfw_update', 86400, time() + 43200);
97
- Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // New
98
- Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500);
99
- }
100
- function apbct_update_to_5_74_0(){
101
- Cron::removeTask('send_daily_request');
102
- }
103
-
104
- function apbct_update_to_5_97_0(){
105
-
106
- global $apbct;
107
-
108
- if(count($apbct->data['connection_reports']['negative_report']) >= 20)
109
- $apbct->data['connection_reports']['negative_report'] = array_slice($apbct->data['connection_reports']['negative_report'], -20, 20);
110
-
111
- $apbct->saveData();
112
- }
113
-
114
- function apbct_update_to_5_109_0(){
115
-
116
- global $apbct, $wpdb;
117
-
118
- if(apbct_is_plugin_active_for_network($apbct->base_name) && !defined('CLEANTALK_ACCESS_KEY')){
119
-
120
- $sfw_data_query = 'CREATE TABLE IF NOT EXISTS `%s` (
121
- `network` int(11) unsigned NOT NULL,
122
- `mask` int(11) unsigned NOT NULL,
123
- INDEX ( `network` , `mask` )
124
- );';
125
-
126
- $sfw_log_query = 'CREATE TABLE IF NOT EXISTS `%s` (
127
- `ip` VARCHAR(15) NOT NULL,
128
- `all_entries` INT NOT NULL,
129
- `blocked_entries` INT NOT NULL,
130
- `entries_timestamp` INT NOT NULL,
131
- PRIMARY KEY (`ip`));';
132
-
133
- $initial_blog = get_current_blog_id();
134
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
135
- foreach ($blogs as $blog) {
136
- switch_to_blog($blog);
137
- $wpdb->query(sprintf($sfw_data_query, $wpdb->prefix . 'cleantalk_sfw')); // Table for SpamFireWall data
138
- $wpdb->query(sprintf($sfw_log_query, $wpdb->prefix . 'cleantalk_sfw_logs')); // Table for SpamFireWall logs
139
- // Cron tasks
140
- Cron::addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
141
- Cron::addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
142
- Cron::addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
143
- Cron::addTask('sfw_update', 'ct_sfw_update', 86400, time() + 300); // SFW update
144
- Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
145
- Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
146
- Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
147
- }
148
- switch_to_blog($initial_blog);
149
- }
150
- }
151
-
152
- function apbct_update_to_5_110_0(){
153
- global $apbct;
154
- unset($apbct->data['last_remote_call']);
155
- $apbct->saveData;
156
- $apbct->save('remote_calls');
157
- }
158
-
159
- function apbct_update_to_5_115_1(){
160
- ct_sfw_update();
161
- }
162
-
163
- function apbct_update_to_5_116_0(){
164
-
165
- global $apbct, $wpdb;
166
-
167
- $apbct->settings['store_urls'] = 0;
168
- $apbct->settings['store_urls__sessions'] = 0;
169
- $apbct->saveSettings();
170
-
171
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
172
- `id` VARCHAR(64) NOT NULL,
173
- `name` TEXT NOT NULL,
174
- `value` TEXT NULL,
175
- `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
176
- PRIMARY KEY (`id`, `name`(10)));'
177
- );
178
- }
179
-
180
- function apbct_update_to_5_116_1(){
181
-
182
- global $wpdb;
183
-
184
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
185
- `id` VARCHAR(64) NOT NULL,
186
- `name` TEXT NOT NULL,
187
- `value` TEXT NULL,
188
- `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
189
- PRIMARY KEY (`id`, `name`(10)));'
190
- );
191
- }
192
-
193
- function apbct_update_to_5_116_2(){
194
-
195
- global $wpdb;
196
-
197
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
198
- `id` VARCHAR(64) NOT NULL,
199
- `name` TEXT NOT NULL,
200
- `value` TEXT NULL DEFAULT NULL,
201
- `last_update` DATETIME NULL DEFAULT NULL,
202
- PRIMARY KEY (`id`, `name`(10)));'
203
- );
204
- }
205
-
206
- function apbct_update_to_5_118_0(){
207
- global $wpdb;
208
- $wpdb->query(
209
- 'DELETE
210
- FROM `'. APBCT_TBL_SESSIONS .'`
211
- WHERE last_update < NOW() - INTERVAL '. APBCT_SEESION__LIVE_TIME .' SECOND;'
212
- );
213
- delete_option('cleantalk_server');
214
- }
215
-
216
- function apbct_update_to_5_118_2(){
217
- global $apbct;
218
- $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
219
- $apbct->data['connection_reports']['since'] = date('d M');
220
- $apbct->saveData();
221
- }
222
-
223
- function apbct_update_to_5_119_0(){
224
-
225
- global $wpdb;
226
-
227
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
228
-
229
- // SFW data
230
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
231
- `network` int(11) unsigned NOT NULL,
232
- `mask` int(11) unsigned NOT NULL,
233
- INDEX ( `network` , `mask` )
234
- );';
235
-
236
- // SFW log
237
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
238
- `ip` VARCHAR(15) NOT NULL,
239
- `all_entries` INT NOT NULL,
240
- `blocked_entries` INT NOT NULL,
241
- `entries_timestamp` INT NOT NULL,
242
- PRIMARY KEY (`ip`));';
243
-
244
- // Sessions
245
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sessions` (
246
- `id` VARCHAR(64) NOT NULL,
247
- `name` VARCHAR(64) NOT NULL,
248
- `value` TEXT NULL DEFAULT NULL,
249
- `last_update` DATETIME NULL DEFAULT NULL,
250
- PRIMARY KEY (`id`(64), `name`(64)));';
251
-
252
- apbct_activation__create_tables($sqls);
253
-
254
- // WPMS
255
- if(is_multisite()){
256
- global $wpdb;
257
- $initial_blog = get_current_blog_id();
258
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
259
- foreach ($blogs as $blog) {
260
- switch_to_blog($blog);
261
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
262
- apbct_activation__create_tables($sqls);
263
- }
264
- switch_to_blog($initial_blog);
265
- }
266
-
267
- // Drop work url
268
- update_option(
269
- 'cleantalk_server',
270
- array(
271
- 'ct_work_url' => null,
272
- 'ct_server_ttl' => 0,
273
- 'ct_server_changed' => 0,
274
- )
275
- );
276
- }
277
-
278
- function apbct_update_to_5_124_0(){
279
- global $apbct;
280
- // Deleting error in database because format were changed
281
- $apbct->errors = array();
282
- $apbct->saveErrors();
283
- }
284
-
285
- function apbct_update_to_5_126_0(){
286
- global $apbct;
287
- // Enable storing URLs
288
- $apbct->settings['store_urls'] = 1;
289
- $apbct->settings['store_urls__sessions'] = 1;
290
- $apbct->saveSettings();
291
- }
292
-
293
- function apbct_update_to_5_127_0(){
294
-
295
- global $apbct;
296
-
297
- // Move exclusions from variable to settins
298
- global $cleantalk_url_exclusions, $cleantalk_key_exclusions;
299
- // URLs
300
- if(!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)){
301
- $apbct->settings['exclusions__urls'] = implode(',', $cleantalk_url_exclusions);
302
- if(APBCT_WPMS){
303
- $initial_blog = get_current_blog_id();
304
- switch_to_blog( 1 );
305
- }
306
- $apbct->saveSettings();
307
- if(APBCT_WPMS){
308
- switch_to_blog($initial_blog);
309
- }
310
- }
311
- // Fields
312
- if(!empty($cleantalk_key_exclusions) && is_array($cleantalk_key_exclusions)){
313
- $apbct->settings['exclusions__fields'] = implode(',', $cleantalk_key_exclusions);
314
- if(APBCT_WPMS){
315
- $initial_blog = get_current_blog_id();
316
- switch_to_blog( 1 );
317
- }
318
- $apbct->saveSettings();
319
- if(APBCT_WPMS){
320
- switch_to_blog($initial_blog);
321
- }
322
- }
323
-
324
- // Deleting legacy
325
- if(isset($apbct->data['testing_failed'])){
326
- unset($apbct->data['testing_failed']);
327
- $apbct->saveData();
328
- }
329
-
330
- if(APBCT_WPMS){
331
-
332
- // Whitelabel
333
- // Reset "api_key_is_recieved" flag
334
- global $wpdb;
335
- $initial_blog = get_current_blog_id();
336
- $blogs = array_keys( $wpdb->get_results( 'SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K ) );
337
- foreach ( $blogs as $blog ){
338
- switch_to_blog( $blog );
339
-
340
- $settings = get_option( 'cleantalk_settings' );
341
- if( isset( $settings['use_static_js_key'] ) ){
342
- $settings['use_static_js_key'] = $settings['use_static_js_key'] === 0
343
- ? - 1
344
- : $settings['use_static_js_key'];
345
- update_option( 'cleantalk_settings', $settings );
346
-
347
- $data = get_option( 'cleantalk_data' );
348
- if( isset( $data['white_label_data']['is_key_recieved'] ) ){
349
- unset( $data['white_label_data']['is_key_recieved'] );
350
- update_option( 'cleantalk_data', $data );
351
- }
352
- }
353
- switch_to_blog( $initial_blog );
354
-
355
- if( defined( 'APBCT_WHITELABEL' ) ){
356
- $apbct->network_settings = array(
357
- 'white_label' => defined( 'APBCT_WHITELABEL' ) && APBCT_WHITELABEL == true ? 1 : 0,
358
- 'white_label__hoster_key' => defined( 'APBCT_HOSTER_API_KEY' ) ? APBCT_HOSTER_API_KEY : '',
359
- 'white_label__plugin_name' => defined( 'APBCT_WHITELABEL_NAME' ) ? APBCT_WHITELABEL_NAME : APBCT_NAME,
360
- );
361
- }elseif( defined( 'CLEANTALK_ACCESS_KEY' ) ){
362
- $apbct->network_settings = array(
363
- 'allow_custom_key' => 0,
364
- 'apikey' => CLEANTALK_ACCESS_KEY,
365
- );
366
- }
367
- $apbct->saveNetworkSettings();
368
- }
369
- }else{
370
- // Switch use_static_js_key to Auto if it was disabled
371
- $apbct->settings['use_static_js_key'] = $apbct->settings['use_static_js_key'] === 0
372
- ? -1
373
- : $apbct->settings['use_static_js_key'];
374
- $apbct->saveSettings();
375
- }
376
- }
377
-
378
- function apbct_update_to_5_127_1(){
379
- if(APBCT_WPMS && is_main_site()){
380
- global $apbct;
381
- $network_settings = get_site_option( 'cleantalk_network_settings' );
382
- if( $network_settings !== false && empty( $network_settings['allow_custom_key'] ) && empty( $network_settings['white_label'] ) ){
383
- $network_settings['allow_custom_key'] = 1;
384
- update_site_option( 'cleantalk_network_settings', $network_settings );
385
- }
386
- if( $network_settings !== false && $network_settings['white_label'] == 1 && $apbct->data['moderate'] == 0 ){
387
- ct_account_status_check( $network_settings['apikey'] ? $network_settings['apikey'] : $apbct->settings['apikey'], false);
388
- }
389
- }
390
- }
391
-
392
- function apbct_update_to_5_128_0(){
393
- global $apbct;
394
- $apbct->remote_calls = array();
395
- $apbct->save('remote_calls');
396
- }
397
-
398
- function apbct_update_to_5_133_0() {
399
-
400
- global $wpdb;
401
-
402
- // Scan comment/user log
403
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
404
- `id` int(11) NOT NULL AUTO_INCREMENT,
405
- `scan_type` varchar(11) NOT NULL,
406
- `start_time` datetime NOT NULL,
407
- `finish_time` datetime NOT NULL,
408
- `count_to_scan` int(11) DEFAULT NULL,
409
- `found_spam` int(11) DEFAULT NULL,
410
- `found_bad` int(11) DEFAULT NULL,
411
- PRIMARY KEY (`id`));';
412
-
413
- apbct_activation__create_tables($sqls);
414
-
415
- }
416
-
417
- function apbct_update_to_5_138_0() {
418
-
419
- global $wpdb;
420
-
421
- // SQL queries for each blog
422
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
423
- `id` int(11) NOT NULL AUTO_INCREMENT,
424
- `scan_type` varchar(11) NOT NULL,
425
- `start_time` datetime NOT NULL,
426
- `finish_time` datetime NOT NULL,
427
- `count_to_scan` int(11) DEFAULT NULL,
428
- `found_spam` int(11) DEFAULT NULL,
429
- `found_bad` int(11) DEFAULT NULL,
430
- PRIMARY KEY (`id`));';
431
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
432
- `network` int(11) unsigned NOT NULL,
433
- `mask` int(11) unsigned NOT NULL,
434
- INDEX ( `network` , `mask` )
435
- );';
436
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN status TINYINT(1) NOT NULL DEFAULT 0 AFTER mask;';
437
-
438
- // Actions for WPMS
439
- if( APBCT_WPMS ){
440
-
441
- // Getting all blog ids
442
- $initial_blog = get_current_blog_id();
443
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
444
-
445
- // Getting main blog setting
446
- switch_to_blog( 1 );
447
- $main_blog_settings = get_option( 'cleantalk_settings' );
448
- switch_to_blog( $initial_blog );
449
-
450
- // Getting network settings
451
- $net_settings = get_site_option('cleantalk_network_settings');
452
-
453
- foreach ($blogs as $blog) {
454
-
455
- // Update time limit to prevent exec time error
456
- set_time_limit(20);
457
-
458
- switch_to_blog($blog);
459
-
460
- // Update SQL structure
461
- apbct_activation__create_tables($sqls);
462
-
463
- // Getting key
464
- $settings = $net_settings['allow_custom_key']
465
- ? get_option('cleantalk_settings')
466
- : $main_blog_settings;
467
-
468
- // Update plugin status
469
- if( ! empty( $settings['apikey'] ) ){
470
-
471
- $data = get_option( 'cleantalk_data', array() );
472
-
473
- $result = \Cleantalk\ApbctWP\API::method__notice_paid_till(
474
- $settings['api_key'],
475
- preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
476
- ! is_main_site() && $net_settings['white_label'] ? 'anti-spam-hosting' : 'antispam'
477
- );
478
-
479
- if( empty( $result['error'] ) || ! empty( $result['valid'] ) ){
480
-
481
- // Notices
482
- $data['notice_show'] = isset($result['show_notice']) ? (int)$result['show_notice'] : 0;
483
- $data['notice_renew'] = isset($result['renew']) ? (int)$result['renew'] : 0;
484
- $data['notice_trial'] = isset($result['trial']) ? (int)$result['trial'] : 0;
485
- $data['notice_review'] = isset($result['show_review']) ? (int)$result['show_review'] : 0;
486
- $data['notice_auto_update'] = isset($result['show_auto_update_notice']) ? (int)$result['show_auto_update_notice'] : 0;
487
-
488
- // Other
489
- $data['service_id'] = isset($result['service_id']) ? (int)$result['service_id'] : 0;
490
- $data['valid'] = isset($result['valid']) ? (int)$result['valid'] : 0;
491
- $data['moderate'] = isset($result['moderate']) ? (int)$result['moderate'] : 0;
492
- $data['ip_license'] = isset($result['ip_license']) ? (int)$result['ip_license'] : 0;
493
- $data['moderate_ip'] = isset($result['moderate_ip'], $result['ip_license']) ? (int)$result['moderate_ip'] : 0;
494
- $data['spam_count'] = isset($result['spam_count']) ? (int)$result['spam_count'] : 0;
495
- $data['auto_update'] = isset($result['auto_update_app']) ? (int)$result['auto_update_app'] : 0;
496
- $data['user_token'] = isset($result['user_token']) ? (string)$result['user_token'] : '';
497
- $data['license_trial'] = isset($result['license_trial']) ? (int)$result['license_trial'] : 0;
498
- $data['account_name_ob'] = isset($result['account_name_ob']) ? (string)$result['account_name_ob'] : '';
499
-
500
- }
501
-
502
- $data['key_is_ok'] = ! empty( $result['valid'] )
503
- ? true
504
- : false;
505
-
506
- update_option( 'cleantalk_data', $data );
507
-
508
- }
509
-
510
- }
511
-
512
- // Restoring initial blog
513
- switch_to_blog($initial_blog);
514
-
515
- // Actions for stand alone blog
516
- }else{
517
- apbct_activation__create_tables($sqls);
518
- }
519
-
520
- }
521
-
522
- function apbct_update_to_5_142_0() {
523
-
524
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
525
- `id` VARCHAR(40) NOT NULL,
526
- `ip` VARCHAR(40) NOT NULL,
527
- `entries` INT DEFAULT 0,
528
- `interval_start` INT NOT NULL,
529
- PRIMARY KEY (`id`));';
530
-
531
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
532
- ADD COLUMN `id` VARCHAR(40) NOT NULL FIRST,
533
- ADD COLUMN `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTIBOT\',\'DENY_ANTICRAWLER\') NOT NULL AFTER `ip`,
534
- DROP PRIMARY KEY,
535
- ADD PRIMARY KEY (`id`);';
536
-
537
- apbct_activation__create_tables( $sqls );
538
-
539
- }
540
-
541
- function apbct_update_to_5_142_1() {
542
-
543
- $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
544
-
545
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
546
- CHANGE `status` `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTICRAWLER\',\'DENY_ANTIFLOOD\') NOT NULL AFTER `ip`;';
547
-
548
- apbct_activation__create_tables( $sqls );
549
-
550
- }
551
-
552
- function apbct_update_to_5_142_2() {
553
-
554
- $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
555
-
556
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
557
- CHANGE `status` `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW__BY_WHITELIST\',\'PASS_SFW__BY_COOKIE\',\'DENY_ANTICRAWLER\',\'PASS_ANTICRAWLER\',\'DENY_ANTIFLOOD\',\'PASS_ANTIFLOOD\') NOT NULL AFTER `ip`;';
558
-
559
- apbct_activation__create_tables( $sqls );
560
-
561
- }
562
-
563
- function apbct_update_to_5_142_3() {
564
-
565
- global $apbct;
566
-
567
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
568
- `id` VARCHAR(40) NOT NULL,
569
- `ip` VARCHAR(15) NOT NULL,
570
- `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW__BY_WHITELIST\',\'PASS_SFW__BY_COOKIE\',\'DENY_ANTICRAWLER\',\'PASS_ANTICRAWLER\',\'DENY_ANTIFLOOD\',\'PASS_ANTIFLOOD\') NULL DEFAULT NULL,
571
- `all_entries` INT NOT NULL,
572
- `blocked_entries` INT NOT NULL,
573
- `entries_timestamp` INT NOT NULL,
574
- PRIMARY KEY (`id`));';
575
-
576
- apbct_activation__create_tables( $sqls, $apbct->db_prefix );
577
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
  }
1
+ <?php
2
+
3
+ use Cleantalk\ApbctWP\Cron;
4
+
5
+ function apbct_run_update_actions($current_version, $new_version){
6
+
7
+ $current_version = apbct_version_standartization($current_version);
8
+ $new_version = apbct_version_standartization($new_version);
9
+
10
+ $current_version_str = implode('.', $current_version);
11
+ $new_version_str = implode('.', $new_version);
12
+
13
+ for($ver_major = $current_version[0]; $ver_major <= $new_version[0]; $ver_major++){
14
+ for($ver_minor = 0; $ver_minor <= 200; $ver_minor++){
15
+ for($ver_fix = 0; $ver_fix <= 10; $ver_fix++){
16
+
17
+ if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $current_version_str, '<='))
18
+ continue;
19
+
20
+ if(function_exists("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}")){
21
+ $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}");
22
+ if(!empty($result['error']))
23
+ break;
24
+ }
25
+
26
+ if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $new_version_str, '>='))
27
+ break(2);
28
+
29
+ }
30
+ }
31
+ }
32
+
33
+ return true;
34
+
35
+ }
36
+
37
+ function apbct_version_standartization($version){
38
+
39
+ $version = explode('.', $version);
40
+ $version = !empty($version) ? $version : array();
41
+
42
+ $version[0] = !empty($version[0]) ? (int)$version[0] : 0;
43
+ $version[1] = !empty($version[1]) ? (int)$version[1] : 0;
44
+ $version[2] = !empty($version[2]) ? (int)$version[2] : 0;
45
+
46
+ return $version;
47
+ }
48
+
49
+ function apbct_update_to_5_50_0(){
50
+ global $wpdb;
51
+ $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_DATA .'` (
52
+ `network` int(11) unsigned NOT NULL,
53
+ `mask` int(11) unsigned NOT NULL,
54
+ INDEX ( `network` , `mask` )
55
+ );');
56
+
57
+ $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_LOG .'` (
58
+ `ip` VARCHAR(15) NOT NULL ,
59
+ `all` INT NOT NULL ,
60
+ `blocked` INT NOT NULL ,
61
+ `timestamp` INT NOT NULL ,
62
+ PRIMARY KEY (`ip`));');
63
+ }
64
+
65
+ function apbct_update_to_5_56_0(){
66
+ if (!wp_next_scheduled('cleantalk_update_sfw_hook'))
67
+ wp_schedule_event(time()+1800, 'daily', 'cleantalk_update_sfw_hook' );
68
+ }
69
+ function apbct_update_to_5_70_0(){
70
+
71
+ global $wpdb;
72
+
73
+ if(!in_array('all_entries', $wpdb->get_col('DESC '. APBCT_TBL_FIREWALL_LOG, 0))){
74
+ $wpdb->query('ALTER TABLE `'. APBCT_TBL_FIREWALL_LOG .'`
75
+ CHANGE `all` `all_entries` INT(11) NOT NULL,
76
+ CHANGE `blocked` `blocked_entries` INT(11) NOT NULL,
77
+ CHANGE `timestamp` `entries_timestamp` INT(11) NOT NULL;'
78
+ );
79
+ }
80
+
81
+ // Deleting usless data
82
+ delete_option('cleantalk_sends_reports_till');
83
+ delete_option('cleantalk_activation_timestamp');
84
+
85
+ // Disabling WP_Cron tasks
86
+ wp_clear_scheduled_hook('cleantalk_send_daily_report_hook');
87
+ wp_clear_scheduled_hook('ct_hourly_event_hook');
88
+ wp_clear_scheduled_hook('ct_send_sfw_log');
89
+ wp_clear_scheduled_hook('cleantalk_update_sfw_hook');
90
+ wp_clear_scheduled_hook('cleantalk_get_brief_data_hook');
91
+
92
+ // Adding Self cron system tasks
93
+ Cron::addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // New
94
+ Cron::addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500);
95
+ Cron::addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500);
96
+ Cron::addTask('sfw_update', 'ct_sfw_update', 86400, time() + 43200);
97
+ Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // New
98
+ Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500);
99
+ }
100
+ function apbct_update_to_5_74_0(){
101
+ Cron::removeTask('send_daily_request');
102
+ }
103
+
104
+ function apbct_update_to_5_97_0(){
105
+
106
+ global $apbct;
107
+
108
+ if(count($apbct->data['connection_reports']['negative_report']) >= 20)
109
+ $apbct->data['connection_reports']['negative_report'] = array_slice($apbct->data['connection_reports']['negative_report'], -20, 20);
110
+
111
+ $apbct->saveData();
112
+ }
113
+
114
+ function apbct_update_to_5_109_0(){
115
+
116
+ global $apbct, $wpdb;
117
+
118
+ if(apbct_is_plugin_active_for_network($apbct->base_name) && !defined('CLEANTALK_ACCESS_KEY')){
119
+
120
+ $sfw_data_query = 'CREATE TABLE IF NOT EXISTS `%s` (
121
+ `network` int(11) unsigned NOT NULL,
122
+ `mask` int(11) unsigned NOT NULL,
123
+ INDEX ( `network` , `mask` )
124
+ );';
125
+
126
+ $sfw_log_query = 'CREATE TABLE IF NOT EXISTS `%s` (
127
+ `ip` VARCHAR(15) NOT NULL,
128
+ `all_entries` INT NOT NULL,
129
+ `blocked_entries` INT NOT NULL,
130
+ `entries_timestamp` INT NOT NULL,
131
+ PRIMARY KEY (`ip`));';
132
+
133
+ $initial_blog = get_current_blog_id();
134
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
135
+ foreach ($blogs as $blog) {
136
+ switch_to_blog($blog);
137
+ $wpdb->query(sprintf($sfw_data_query, $wpdb->prefix . 'cleantalk_sfw')); // Table for SpamFireWall data
138
+ $wpdb->query(sprintf($sfw_log_query, $wpdb->prefix . 'cleantalk_sfw_logs')); // Table for SpamFireWall logs
139
+ // Cron tasks
140
+ Cron::addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
141
+ Cron::addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
142
+ Cron::addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
143
+ Cron::addTask('sfw_update', 'ct_sfw_update', 86400, time() + 300); // SFW update
144
+ Cron::addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
145
+ Cron::addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
146
+ Cron::addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
147
+ }
148
+ switch_to_blog($initial_blog);
149
+ }
150
+ }
151
+
152
+ function apbct_update_to_5_110_0(){
153
+ global $apbct;
154
+ unset($apbct->data['last_remote_call']);
155
+ $apbct->saveData;
156
+ $apbct->save('remote_calls');
157
+ }
158
+
159
+ function apbct_update_to_5_115_1(){
160
+ ct_sfw_update();
161
+ }
162
+
163
+ function apbct_update_to_5_116_0(){
164
+
165
+ global $apbct, $wpdb;
166
+
167
+ $apbct->settings['store_urls'] = 0;
168
+ $apbct->settings['store_urls__sessions'] = 0;
169
+ $apbct->saveSettings();
170
+
171
+ $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
172
+ `id` VARCHAR(64) NOT NULL,
173
+ `name` TEXT NOT NULL,
174
+ `value` TEXT NULL,
175
+ `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
176
+ PRIMARY KEY (`id`, `name`(10)));'
177
+ );
178
+ }
179
+
180
+ function apbct_update_to_5_116_1(){
181
+
182
+ global $wpdb;
183
+
184
+ $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
185
+ `id` VARCHAR(64) NOT NULL,
186
+ `name` TEXT NOT NULL,
187
+ `value` TEXT NULL,
188
+ `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
189
+ PRIMARY KEY (`id`, `name`(10)));'
190
+ );
191
+ }
192
+
193
+ function apbct_update_to_5_116_2(){
194
+
195
+ global $wpdb;
196
+
197
+ $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
198
+ `id` VARCHAR(64) NOT NULL,
199
+ `name` TEXT NOT NULL,
200
+ `value` TEXT NULL DEFAULT NULL,
201
+ `last_update` DATETIME NULL DEFAULT NULL,
202
+ PRIMARY KEY (`id`, `name`(10)));'
203
+ );
204
+ }
205
+
206
+ function apbct_update_to_5_118_0(){
207
+ global $wpdb;
208
+ $wpdb->query(
209
+ 'DELETE
210
+ FROM `'. APBCT_TBL_SESSIONS .'`
211
+ WHERE last_update < NOW() - INTERVAL '. APBCT_SEESION__LIVE_TIME .' SECOND;'
212
+ );
213
+ delete_option('cleantalk_server');
214
+ }
215
+
216
+ function apbct_update_to_5_118_2(){
217
+ global $apbct;
218
+ $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
219
+ $apbct->data['connection_reports']['since'] = date('d M');
220
+ $apbct->saveData();
221
+ }
222
+
223
+ function apbct_update_to_5_119_0(){
224
+
225
+ global $wpdb;
226
+
227
+ $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
228
+
229
+ // SFW data
230
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
231
+ `network` int(11) unsigned NOT NULL,
232
+ `mask` int(11) unsigned NOT NULL,
233
+ INDEX ( `network` , `mask` )
234
+ );';
235
+
236
+ // SFW log
237
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
238
+ `ip` VARCHAR(15) NOT NULL,
239
+ `all_entries` INT NOT NULL,
240
+ `blocked_entries` INT NOT NULL,
241
+ `entries_timestamp` INT NOT NULL,
242
+ PRIMARY KEY (`ip`));';
243
+
244
+ // Sessions
245
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sessions` (
246
+ `id` VARCHAR(64) NOT NULL,
247
+ `name` VARCHAR(64) NOT NULL,
248
+ `value` TEXT NULL DEFAULT NULL,
249
+ `last_update` DATETIME NULL DEFAULT NULL,
250
+ PRIMARY KEY (`id`(64), `name`(64)));';
251
+
252
+ apbct_activation__create_tables($sqls);
253
+
254
+ // WPMS
255
+ if(is_multisite()){
256
+ global $wpdb;
257
+ $initial_blog = get_current_blog_id();
258
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
259
+ foreach ($blogs as $blog) {
260
+ switch_to_blog($blog);
261
+ $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
262
+ apbct_activation__create_tables($sqls);
263
+ }
264
+ switch_to_blog($initial_blog);
265
+ }
266
+
267
+ // Drop work url
268
+ update_option(
269
+ 'cleantalk_server',
270
+ array(
271
+ 'ct_work_url' => null,
272
+ 'ct_server_ttl' => 0,
273
+ 'ct_server_changed' => 0,
274
+ )
275
+ );
276
+ }
277
+
278
+ function apbct_update_to_5_124_0(){
279
+ global $apbct;
280
+ // Deleting error in database because format were changed
281
+ $apbct->errors = array();
282
+ $apbct->saveErrors();
283
+ }
284
+
285
+ function apbct_update_to_5_126_0(){
286
+ global $apbct;
287
+ // Enable storing URLs
288
+ $apbct->settings['store_urls'] = 1;
289
+ $apbct->settings['store_urls__sessions'] = 1;
290
+ $apbct->saveSettings();
291
+ }
292
+
293
+ function apbct_update_to_5_127_0(){
294
+
295
+ global $apbct;
296
+
297
+ // Move exclusions from variable to settins
298
+ global $cleantalk_url_exclusions, $cleantalk_key_exclusions;
299
+ // URLs
300
+ if(!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)){
301
+ $apbct->settings['exclusions__urls'] = implode(',', $cleantalk_url_exclusions);
302
+ if(APBCT_WPMS){
303
+ $initial_blog = get_current_blog_id();
304
+ switch_to_blog( 1 );
305
+ }
306
+ $apbct->saveSettings();
307
+ if(APBCT_WPMS){
308
+ switch_to_blog($initial_blog);
309
+ }
310
+ }
311
+ // Fields
312
+ if(!empty($cleantalk_key_exclusions) && is_array($cleantalk_key_exclusions)){
313
+ $apbct->settings['exclusions__fields'] = implode(',', $cleantalk_key_exclusions);
314
+ if(APBCT_WPMS){
315
+ $initial_blog = get_current_blog_id();
316
+ switch_to_blog( 1 );
317
+ }
318
+ $apbct->saveSettings();
319
+ if(APBCT_WPMS){
320
+ switch_to_blog($initial_blog);
321
+ }
322
+ }
323
+
324
+ // Deleting legacy
325
+ if(isset($apbct->data['testing_failed'])){
326
+ unset($apbct->data['testing_failed']);
327
+ $apbct->saveData();
328
+ }
329
+
330
+ if(APBCT_WPMS){
331
+
332
+ // Whitelabel
333
+ // Reset "api_key_is_recieved" flag
334
+ global $wpdb;
335
+ $initial_blog = get_current_blog_id();
336
+ $blogs = array_keys( $wpdb->get_results( 'SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K ) );
337
+ foreach ( $blogs as $blog ){
338
+ switch_to_blog( $blog );
339
+
340
+ $settings = get_option( 'cleantalk_settings' );
341
+ if( isset( $settings['use_static_js_key'] ) ){
342
+ $settings['use_static_js_key'] = $settings['use_static_js_key'] === 0
343
+ ? - 1
344
+ : $settings['use_static_js_key'];
345
+ update_option( 'cleantalk_settings', $settings );
346
+
347
+ $data = get_option( 'cleantalk_data' );
348
+ if( isset( $data['white_label_data']['is_key_recieved'] ) ){
349
+ unset( $data['white_label_data']['is_key_recieved'] );
350
+ update_option( 'cleantalk_data', $data );
351
+ }
352
+ }
353
+ switch_to_blog( $initial_blog );
354
+
355
+ if( defined( 'APBCT_WHITELABEL' ) ){
356
+ $apbct->network_settings = array(
357
+ 'white_label' => defined( 'APBCT_WHITELABEL' ) && APBCT_WHITELABEL == true ? 1 : 0,
358
+ 'white_label__hoster_key' => defined( 'APBCT_HOSTER_API_KEY' ) ? APBCT_HOSTER_API_KEY : '',
359
+ 'white_label__plugin_name' => defined( 'APBCT_WHITELABEL_NAME' ) ? APBCT_WHITELABEL_NAME : APBCT_NAME,
360
+ );
361
+ }elseif( defined( 'CLEANTALK_ACCESS_KEY' ) ){
362
+ $apbct->network_settings = array(
363
+ 'allow_custom_key' => 0,
364
+ 'apikey' => CLEANTALK_ACCESS_KEY,
365
+ );
366
+ }
367
+ $apbct->saveNetworkSettings();
368
+ }
369
+ }else{
370
+ // Switch use_static_js_key to Auto if it was disabled
371
+ $apbct->settings['use_static_js_key'] = $apbct->settings['use_static_js_key'] === 0
372
+ ? -1
373
+ : $apbct->settings['use_static_js_key'];
374
+ $apbct->saveSettings();
375
+ }
376
+ }
377
+
378
+ function apbct_update_to_5_127_1(){
379
+ if(APBCT_WPMS && is_main_site()){
380
+ global $apbct;
381
+ $network_settings = get_site_option( 'cleantalk_network_settings' );
382
+ if( $network_settings !== false && empty( $network_settings['allow_custom_key'] ) && empty( $network_settings['white_label'] ) ){
383
+ $network_settings['allow_custom_key'] = 1;
384
+ update_site_option( 'cleantalk_network_settings', $network_settings );
385
+ }
386
+ if( $network_settings !== false && $network_settings['white_label'] == 1 && $apbct->data['moderate'] == 0 ){
387
+ ct_account_status_check( $network_settings['apikey'] ? $network_settings['apikey'] : $apbct->settings['apikey'], false);
388
+ }
389
+ }
390
+ }
391
+
392
+ function apbct_update_to_5_128_0(){
393
+ global $apbct;
394
+ $apbct->remote_calls = array();
395
+ $apbct->save('remote_calls');
396
+ }
397
+
398
+ function apbct_update_to_5_133_0() {
399
+
400
+ global $wpdb;
401
+
402
+ // Scan comment/user log
403
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
404
+ `id` int(11) NOT NULL AUTO_INCREMENT,
405
+ `scan_type` varchar(11) NOT NULL,
406
+ `start_time` datetime NOT NULL,
407
+ `finish_time` datetime NOT NULL,
408
+ `count_to_scan` int(11) DEFAULT NULL,
409
+ `found_spam` int(11) DEFAULT NULL,
410
+ `found_bad` int(11) DEFAULT NULL,
411
+ PRIMARY KEY (`id`));';
412
+
413
+ apbct_activation__create_tables($sqls);
414
+
415
+ }
416
+
417
+ function apbct_update_to_5_138_0() {
418
+
419
+ global $wpdb;
420
+
421
+ // SQL queries for each blog
422
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
423
+ `id` int(11) NOT NULL AUTO_INCREMENT,
424
+ `scan_type` varchar(11) NOT NULL,
425
+ `start_time` datetime NOT NULL,
426
+ `finish_time` datetime NOT NULL,
427
+ `count_to_scan` int(11) DEFAULT NULL,
428
+ `found_spam` int(11) DEFAULT NULL,
429
+ `found_bad` int(11) DEFAULT NULL,
430
+ PRIMARY KEY (`id`));';
431
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
432
+ `network` int(11) unsigned NOT NULL,
433
+ `mask` int(11) unsigned NOT NULL,
434
+ INDEX ( `network` , `mask` )
435
+ );';
436
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN status TINYINT(1) NOT NULL DEFAULT 0 AFTER mask;';
437
+
438
+ // Actions for WPMS
439
+ if( APBCT_WPMS ){
440
+
441
+ // Getting all blog ids
442
+ $initial_blog = get_current_blog_id();
443
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
444
+
445
+ // Getting main blog setting
446
+ switch_to_blog( 1 );
447
+ $main_blog_settings = get_option( 'cleantalk_settings' );
448
+ switch_to_blog( $initial_blog );
449
+
450
+ // Getting network settings
451
+ $net_settings = get_site_option('cleantalk_network_settings');
452
+
453
+ foreach ($blogs as $blog) {
454
+
455
+ // Update time limit to prevent exec time error
456
+ set_time_limit(20);
457
+
458
+ switch_to_blog($blog);
459
+
460
+ // Update SQL structure
461
+ apbct_activation__create_tables($sqls);
462
+
463
+ // Getting key
464
+ $settings = $net_settings['allow_custom_key']
465
+ ? get_option('cleantalk_settings')
466
+ : $main_blog_settings;
467
+
468
+ // Update plugin status
469
+ if( ! empty( $settings['apikey'] ) ){
470
+
471
+ $data = get_option( 'cleantalk_data', array() );
472
+
473
+ $result = \Cleantalk\ApbctWP\API::method__notice_paid_till(
474
+ $settings['api_key'],
475
+ preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
476
+ ! is_main_site() && $net_settings['white_label'] ? 'anti-spam-hosting' : 'antispam'
477
+ );
478
+
479
+ if( empty( $result['error'] ) || ! empty( $result['valid'] ) ){
480
+
481
+ // Notices
482
+ $data['notice_show'] = isset($result['show_notice']) ? (int)$result['show_notice'] : 0;
483
+ $data['notice_renew'] = isset($result['renew']) ? (int)$result['renew'] : 0;
484
+ $data['notice_trial'] = isset($result['trial']) ? (int)$result['trial'] : 0;
485
+ $data['notice_review'] = isset($result['show_review']) ? (int)$result['show_review'] : 0;
486
+ $data['notice_auto_update'] = isset($result['show_auto_update_notice']) ? (int)$result['show_auto_update_notice'] : 0;
487
+
488
+ // Other
489
+ $data['service_id'] = isset($result['service_id']) ? (int)$result['service_id'] : 0;
490
+ $data['valid'] = isset($result['valid']) ? (int)$result['valid'] : 0;
491
+ $data['moderate'] = isset($result['moderate']) ? (int)$result['moderate'] : 0;
492
+ $data['ip_license'] = isset($result['ip_license']) ? (int)$result['ip_license'] : 0;
493
+ $data['moderate_ip'] = isset($result['moderate_ip'], $result['ip_license']) ? (int)$result['moderate_ip'] : 0;
494
+ $data['spam_count'] = isset($result['spam_count']) ? (int)$result['spam_count'] : 0;
495
+ $data['auto_update'] = isset($result['auto_update_app']) ? (int)$result['auto_update_app'] : 0;
496
+ $data['user_token'] = isset($result['user_token']) ? (string)$result['user_token'] : '';
497
+ $data['license_trial'] = isset($result['license_trial']) ? (int)$result['license_trial'] : 0;
498
+ $data['account_name_ob'] = isset($result['account_name_ob']) ? (string)$result['account_name_ob'] : '';
499
+
500
+ }
501
+
502
+ $data['key_is_ok'] = ! empty( $result['valid'] )
503
+ ? true
504
+ : false;
505
+
506
+ update_option( 'cleantalk_data', $data );
507
+
508
+ }
509
+
510
+ }
511
+
512
+ // Restoring initial blog
513
+ switch_to_blog($initial_blog);
514
+
515
+ // Actions for stand alone blog
516
+ }else{
517
+ apbct_activation__create_tables($sqls);
518
+ }
519
+
520
+ }
521
+
522
+ function apbct_update_to_5_142_0() {
523
+
524
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
525
+ `id` VARCHAR(40) NOT NULL,
526
+ `ip` VARCHAR(40) NOT NULL,
527
+ `entries` INT DEFAULT 0,
528
+ `interval_start` INT NOT NULL,
529
+ PRIMARY KEY (`id`));';
530
+
531
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
532
+ ADD COLUMN `id` VARCHAR(40) NOT NULL FIRST,
533
+ ADD COLUMN `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTIBOT\',\'DENY_ANTICRAWLER\') NOT NULL AFTER `ip`,
534
+ DROP PRIMARY KEY,
535
+ ADD PRIMARY KEY (`id`);';
536
+
537
+ apbct_activation__create_tables( $sqls );
538
+
539
+ }
540
+
541
+ function apbct_update_to_5_142_1() {
542
+
543
+ $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
544
+
545
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
546
+ CHANGE `status` `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTICRAWLER\',\'DENY_ANTIFLOOD\') NOT NULL AFTER `ip`;';
547
+
548
+ apbct_activation__create_tables( $sqls );
549
+
550
+ }
551
+
552
+ function apbct_update_to_5_142_2() {
553
+
554
+ $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
555
+
556
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
557
+ CHANGE `status` `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW__BY_WHITELIST\',\'PASS_SFW__BY_COOKIE\',\'DENY_ANTICRAWLER\',\'PASS_ANTICRAWLER\',\'DENY_ANTIFLOOD\',\'PASS_ANTIFLOOD\') NOT NULL AFTER `ip`;';
558
+
559
+ apbct_activation__create_tables( $sqls );
560
+
561
+ }
562
+
563
+ function apbct_update_to_5_142_3() {
564
+
565
+ global $apbct;
566
+
567
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
568
+ `id` VARCHAR(40) NOT NULL,
569
+ `ip` VARCHAR(15) NOT NULL,
570
+ `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW__BY_WHITELIST\',\'PASS_SFW__BY_COOKIE\',\'DENY_ANTICRAWLER\',\'PASS_ANTICRAWLER\',\'DENY_ANTIFLOOD\',\'PASS_ANTIFLOOD\') NULL DEFAULT NULL,
571
+ `all_entries` INT NOT NULL,
572
+ `blocked_entries` INT NOT NULL,
573
+ `entries_timestamp` INT NOT NULL,
574
+ PRIMARY KEY (`id`));';
575
+
576
+ apbct_activation__create_tables( $sqls, $apbct->db_prefix );
577
+
578
+ }
579
+
580
+ function apbct_update_to_5_143_2() {
581
+
582
+ global $apbct;
583
+
584
+ $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
585
+
586
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
587
+ `id` VARCHAR(40) NOT NULL,
588
+ `ip` VARCHAR(15) NOT NULL,
589
+ `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW__BY_WHITELIST\',\'PASS_SFW__BY_COOKIE\',\'DENY_ANTICRAWLER\',\'PASS_ANTICRAWLER\',\'DENY_ANTIFLOOD\',\'PASS_ANTIFLOOD\') NULL DEFAULT NULL,
590
+ `all_entries` INT NOT NULL,
591
+ `blocked_entries` INT NOT NULL,
592
+ `entries_timestamp` INT NOT NULL,
593
+ PRIMARY KEY (`id`));';
594
+
595
+ apbct_activation__create_tables( $sqls, $apbct->db_prefix );
596
+
597
  }
js/cleantalk-comments-checkspam.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var ct_working=!(String.prototype.printf=function(){var e=this;for(var t in arguments)var c=e.substring(0,e.indexOf("%s",0)),_=e.substring(e.indexOf("%s",0)+2,e.length),e=c+arguments[t]+_;return e}),ct_new_check=!0,ct_cooling_down_flag=!1,ct_close_animate=!0,ct_accurate_check=!1,ct_pause=!1,ct_prev_accurate=ctCommentsCheck.ct_prev_accurate,ct_prev_from=ctCommentsCheck.ct_prev_from,ct_prev_till=ctCommentsCheck.ct_prev_till,ct_cool_down_time=9e4,ct_requests_counter=0,ct_max_requests=60,ct_ajax_nonce=ctCommentsCheck.ct_ajax_nonce,ct_comments_total=0,ct_comments_checked=0,ct_comments_spam=0,ct_comments_bad=0,ct_unchecked="unset",ct_date_from=0,ct_date_till=0;function animate_comment(e,t){ct_close_animate?.3==e?jQuery("#comment-"+t).fadeTo(200,e,function(){animate_comment(1,t)}):jQuery("#comment-"+t).fadeTo(200,e,function(){animate_comment(.3,t)}):ct_close_animate=!0}function ct_clear_comments(){var e=0,t=0;jQuery("#ct_allow_date_range").is(":checked")&&(e=jQuery("#ct_date_range_from").val(),t=jQuery("#ct_date_range_till").val());var c={action:"ajax_clear_comments",security:ct_ajax_nonce,from:e,till:t};jQuery.ajax({type:"POST",url:ajaxurl,data:c,success:function(e){ct_show_info(),ct_send_comments()}})}function ct_cooling_down_toggle(){ct_cooling_down_flag=!1,ct_send_comments(),ct_show_info()}function ct_send_comments(){if(!0!==ct_cooling_down_flag){if(ct_max_requests<=ct_requests_counter)return setTimeout(ct_cooling_down_toggle,ct_cool_down_time),void(ct_cooling_down_flag=!(ct_requests_counter=0));ct_requests_counter++;var e={action:"ajax_check_comments",security:ct_ajax_nonce,new_check:ct_new_check,unchecked:ct_unchecked};ct_accurate_check&&(e.accurate_check=!0),ct_date_from&&ct_date_till&&(e.from=ct_date_from,e.till=ct_date_till),jQuery.ajax({type:"POST",url:ajaxurl,data:e,success:function(e){var t,c;e=jQuery.parseJSON(e),parseInt(e.error)?(ct_working=!1,confirm(e.error_message+". Do you want to proceed?")?ct_send_comments():(t="edit-comments.php?page=ct_check_spam",0!=ct_date_from&&0!=ct_date_till&&(t+="&from="+ct_date_from+"&till="+ct_date_till),location.href=t)):(ct_new_check=!1,1==parseInt(e.end)||!0===ct_pause?(1==parseInt(e.end)&&(document.cookie="ct_paused_comments_check=0; path=/; samesite=lax"),ct_working=!1,jQuery("#ct_working_message").hide(),t="edit-comments.php?page=ct_check_spam",0!=ct_date_from&&0!=ct_date_till&&(t+="&from="+ct_date_from+"&till="+ct_date_till),location.href=t):0==parseInt(e.end)&&(ct_comments_checked+=e.checked,ct_comments_spam+=e.spam,ct_comments_bad+=e.bad,ct_unchecked=ct_comments_total-ct_comments_checked-ct_comments_bad,c=(c=String(ctCommentsCheck.ct_status_string)).printf(ct_comments_checked,ct_comments_spam,ct_comments_bad),0<parseInt(ct_comments_spam)&&(c+=ctCommentsCheck.ct_status_string_warning),jQuery("#ct_checking_status").html(c),jQuery("#ct_error_message").hide(),+ct_comments_total<ct_comments_checked+ct_comments_bad&&(document.cookie="ct_comments_start_check=1; path=/; samesite=lax",document.cookie="ct_comments_safe_check=1; path=/; samesite=lax",location.href="edit-comments.php?page=ct_check_spam"),ct_send_comments()))},error:function(e,t,c){jQuery("#ct_error_message").show(),jQuery("#cleantalk_ajax_error").html(t),jQuery("#cleantalk_js_func").html("Check comments"),setTimeout(ct_send_comments(),3e3)},timeout:25e3})}}function ct_show_info(){if(ct_working){if(1==ct_cooling_down_flag)return jQuery("#ct_cooling_notice").html("Waiting for API to cool down. (About a minute)"),void jQuery("#ct_cooling_notice").show();var e;jQuery("#ct_cooling_notice").hide(),ct_comments_total||(e={action:"ajax_info_comments",security:ct_ajax_nonce},ct_date_from&&ct_date_till&&(e.from=ct_date_from,e.till=ct_date_till),jQuery.ajax({type:"POST",url:ajaxurl,data:e,success:function(e){e=jQuery.parseJSON(e),jQuery("#ct_checking_status").html(e.message),ct_comments_total=e.total,ct_comments_spam=e.spam,ct_comments_checked=e.checked,ct_comments_bad=e.bad},error:function(e,t,c){jQuery("#ct_error_message").show(),jQuery("#cleantalk_ajax_error").html(t),jQuery("#cleantalk_js_func").html("Check comments"),setTimeout(ct_show_info(),3e3)},timeout:15e3}))}}function ct_toggle_depended(e,t){t=t||null;var c=jQuery(e.data("depended"));e.data("state")||t?(e.data("state",!1),c.prop("disabled",!0),c.removeProp("checked"),c.data("depended")&&ct_toggle_depended(c,!0)):(e.data("state",!0),c.removeProp("disabled"))}function ct_delete_all(_){var e={action:"ajax_delete_all",security:ct_ajax_nonce};jQuery("."+_.target.id).addClass("disabled"),jQuery(".spinner").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:e,success:function(e){0<e?(jQuery("#cleantalk_comments_left").html(e),ct_delete_all(_)):(jQuery("."+_.target.id).removeClass("disabled"),jQuery(".spinner").css("visibility","hidden"),location.href="edit-comments.php?page=ct_check_spam_total")},error:function(e,t,c){jQuery("#ct_error_message").show(),jQuery("#cleantalk_ajax_error").html(t),jQuery("#cleantalk_js_func").html("Check comments"),setTimeout(ct_delete_all(_),3e3)},timeout:25e3})}jQuery(document).ready(function(){jQuery("#ct_allow_date_range").data({depended:".ct_date",state:!1}),ct_prev_accurate&&jQuery("#ct_accurate_check").prop("checked",!0),ct_prev_from&&(jQuery("#ct_allow_date_range").prop("checked",!0).data("state",!0),jQuery("#ct_date_range_from").removeProp("disabled").val(ct_prev_from),jQuery("#ct_date_range_till").removeProp("disabled").val(ct_prev_till)),jQuery("#ct_allow_date_range, #ct_accurate_check").on("change",function(){ct_toggle_depended(jQuery(this))}),jQuery.datepicker.setDefaults(jQuery.datepicker.regional.en);var a=jQuery("#ct_date_range_from, #ct_date_range_till").datepicker({dateFormat:"M d yy",maxDate:"+0D",changeMonth:!0,changeYear:!0,showAnim:"slideDown",onSelect:function(e){var t="ct_date_range_from"==this.id?"minDate":"maxDate",c=jQuery(this).data("datepicker"),_=jQuery.datepicker.parseDate(c.settings.dateFormat||jQuery.datepicker._defaults.dateFormat,e,c.settings);a.not(this).datepicker("option",t,_)}});function e(e){e=e||null,jQuery("#ct_allow_date_range").is(":checked")&&(ct_date_from=jQuery("#ct_date_range_from").val(),ct_date_till=jQuery("#ct_date_range_till").val(),""==ct_date_from||""==ct_date_till)?alert("Please, specify a date range."):(jQuery("#ct_accurate_check").is(":checked")&&(ct_accurate_check=!0),jQuery(".ct_to_hide").hide(),jQuery("#ct_working_message").show(),jQuery("#ct_preloader").show(),jQuery("#ct_pause").show(),ct_working=!0,e?(ct_show_info(),ct_send_comments()):ct_clear_comments())}jQuery("#ct_check_spam_button").click(function(){e(!(document.cookie="ct_paused_comments_check=0; path=/; samesite=lax"))}),jQuery("#ct_proceed_check_button").click(function(){e(!0)}),jQuery("#ct_pause").on("click",function(){ct_pause=!0;var e={accurate:ct_accurate_check,from:ct_date_from,till:ct_date_till};document.cookie="ct_paused_comments_check="+JSON.stringify(e)+"; path=/; samesite=lax"}),"1"===ctCommentsCheck.start&&(document.cookie="ct_comments_start_check=0; expires="+new Date(0).toUTCString()+"; path=/; samesite=lax",jQuery("#ct_check_spam_button").click()),jQuery(".ct_delete_all").click(function(e){return!!confirm(ctCommentsCheck.ct_confirm_deletion_all)&&void ct_delete_all(e)})});
2
  //# sourceMappingURL=cleantalk-comments-checkspam.min.js.map
1
+ var ct_working=!(String.prototype.printf=function(){var e=this;for(var t in arguments)var c=e.substring(0,e.indexOf("%s",0)),_=e.substring(e.indexOf("%s",0)+2,e.length),e=c+arguments[t]+_;return e}),ct_new_check=!0,ct_cooling_down_flag=!1,ct_close_animate=!0,ct_accurate_check=!1,ct_pause=!1,ct_prev_accurate=ctCommentsCheck.ct_prev_accurate,ct_prev_from=ctCommentsCheck.ct_prev_from,ct_prev_till=ctCommentsCheck.ct_prev_till,ct_cool_down_time=9e4,ct_requests_counter=0,ct_max_requests=60,ct_ajax_nonce=ctCommentsCheck.ct_ajax_nonce,ct_comments_total=0,ct_comments_checked=0,ct_comments_spam=0,ct_comments_bad=0,ct_unchecked="unset",ct_date_from=0,ct_date_till=0;function animate_comment(e,t){ct_close_animate?.3==e?jQuery("#comment-"+t).fadeTo(200,e,function(){animate_comment(1,t)}):jQuery("#comment-"+t).fadeTo(200,e,function(){animate_comment(.3,t)}):ct_close_animate=!0}function ct_clear_comments(){var e=0,t=0;jQuery("#ct_allow_date_range").is(":checked")&&(e=jQuery("#ct_date_range_from").val(),t=jQuery("#ct_date_range_till").val());var c={action:"ajax_clear_comments",security:ct_ajax_nonce,from:e,till:t};jQuery.ajax({type:"POST",url:ajaxurl,data:c,success:function(e){ct_show_info(),ct_send_comments()}})}function ct_cooling_down_toggle(){ct_cooling_down_flag=!1,ct_send_comments(),ct_show_info()}function ct_send_comments(){if(!0!==ct_cooling_down_flag){if(ct_max_requests<=ct_requests_counter)return setTimeout(ct_cooling_down_toggle,ct_cool_down_time),void(ct_cooling_down_flag=!(ct_requests_counter=0));ct_requests_counter++;var e={action:"ajax_check_comments",security:ct_ajax_nonce,new_check:ct_new_check,unchecked:ct_unchecked};ct_accurate_check&&(e.accurate_check=!0),ct_date_from&&ct_date_till&&(e.from=ct_date_from,e.till=ct_date_till),jQuery.ajax({type:"POST",url:ajaxurl,data:e,success:function(e){var t,c;e=jQuery.parseJSON(e),parseInt(e.error)?(ct_working=!1,confirm(e.error_message+". Do you want to proceed?")?ct_send_comments():(t="edit-comments.php?page=ct_check_spam",0!=ct_date_from&&0!=ct_date_till&&(t+="&from="+ct_date_from+"&till="+ct_date_till),location.href=t)):(ct_new_check=!1,1==parseInt(e.end)||!0===ct_pause?(1==parseInt(e.end)&&(document.cookie="ct_paused_spam_check=0; path=/; samesite=lax"),ct_working=!1,jQuery("#ct_working_message").hide(),t="edit-comments.php?page=ct_check_spam",0!=ct_date_from&&0!=ct_date_till&&(t+="&from="+ct_date_from+"&till="+ct_date_till),location.href=t):0==parseInt(e.end)&&(ct_comments_checked+=e.checked,ct_comments_spam+=e.spam,ct_comments_bad+=e.bad,ct_unchecked=ct_comments_total-ct_comments_checked-ct_comments_bad,c=(c=String(ctCommentsCheck.ct_status_string)).printf(ct_comments_checked,ct_comments_spam,ct_comments_bad),0<parseInt(ct_comments_spam)&&(c+=ctCommentsCheck.ct_status_string_warning),jQuery("#ct_checking_status").html(c),jQuery("#ct_error_message").hide(),+ct_comments_total<ct_comments_checked+ct_comments_bad&&(document.cookie="ct_comments_start_check=1; path=/; samesite=lax",document.cookie="ct_comments_safe_check=1; path=/; samesite=lax",location.href="edit-comments.php?page=ct_check_spam"),ct_send_comments()))},error:function(e,t,c){jQuery("#ct_error_message").show(),jQuery("#cleantalk_ajax_error").html(t),jQuery("#cleantalk_js_func").html("Check comments"),setTimeout(ct_send_comments(),3e3)},timeout:25e3})}}function ct_show_info(){if(ct_working){if(1==ct_cooling_down_flag)return jQuery("#ct_cooling_notice").html("Waiting for API to cool down. (About a minute)"),void jQuery("#ct_cooling_notice").show();var e;jQuery("#ct_cooling_notice").hide(),ct_comments_total||(e={action:"ajax_info_comments",security:ct_ajax_nonce},ct_date_from&&ct_date_till&&(e.from=ct_date_from,e.till=ct_date_till),jQuery.ajax({type:"POST",url:ajaxurl,data:e,success:function(e){e=jQuery.parseJSON(e),jQuery("#ct_checking_status").html(e.message),ct_comments_total=e.total,ct_comments_spam=e.spam,ct_comments_checked=e.checked,ct_comments_bad=e.bad},error:function(e,t,c){jQuery("#ct_error_message").show(),jQuery("#cleantalk_ajax_error").html(t),jQuery("#cleantalk_js_func").html("Check comments"),setTimeout(ct_show_info(),3e3)},timeout:15e3}))}}function ct_toggle_depended(e,t){t=t||null;var c=jQuery(e.data("depended"));e.data("state")||t?(e.data("state",!1),c.prop("disabled",!0),c.removeProp("checked"),c.data("depended")&&ct_toggle_depended(c,!0)):(e.data("state",!0),c.removeProp("disabled"))}function ct_delete_all(_){var e={action:"ajax_delete_all",security:ct_ajax_nonce};jQuery("."+_.target.id).addClass("disabled"),jQuery(".spinner").css("visibility","visible"),jQuery.ajax({type:"POST",url:ajaxurl,data:e,success:function(e){0<e?(jQuery("#cleantalk_comments_left").html(e),ct_delete_all(_)):(jQuery("."+_.target.id).removeClass("disabled"),jQuery(".spinner").css("visibility","hidden"),location.href="edit-comments.php?page=ct_check_spam_total")},error:function(e,t,c){jQuery("#ct_error_message").show(),jQuery("#cleantalk_ajax_error").html(t),jQuery("#cleantalk_js_func").html("Check comments"),setTimeout(ct_delete_all(_),3e3)},timeout:25e3})}jQuery(document).ready(function(){jQuery("#ct_allow_date_range").data({depended:".ct_date",state:!1}),ct_prev_accurate&&jQuery("#ct_accurate_check").prop("checked",!0),ct_prev_from&&(jQuery("#ct_allow_date_range").prop("checked",!0).data("state",!0),jQuery("#ct_date_range_from").removeProp("disabled").val(ct_prev_from),jQuery("#ct_date_range_till").removeProp("disabled").val(ct_prev_till)),jQuery("#ct_allow_date_range, #ct_accurate_check").on("change",function(){ct_toggle_depended(jQuery(this))}),jQuery.datepicker.setDefaults(jQuery.datepicker.regional.en);var a=jQuery("#ct_date_range_from, #ct_date_range_till").datepicker({dateFormat:"M d yy",maxDate:"+0D",changeMonth:!0,changeYear:!0,showAnim:"slideDown",onSelect:function(e){var t="ct_date_range_from"==this.id?"minDate":"maxDate",c=jQuery(this).data("datepicker"),_=jQuery.datepicker.parseDate(c.settings.dateFormat||jQuery.datepicker._defaults.dateFormat,e,c.settings);a.not(this).datepicker("option",t,_)}});function e(e){e=e||null,jQuery("#ct_allow_date_range").is(":checked")&&(ct_date_from=jQuery("#ct_date_range_from").val(),ct_date_till=jQuery("#ct_date_range_till").val(),""==ct_date_from||""==ct_date_till)?alert("Please, specify a date range."):(jQuery("#ct_accurate_check").is(":checked")&&(ct_accurate_check=!0),jQuery(".ct_to_hide").hide(),jQuery("#ct_working_message").show(),jQuery("#ct_preloader").show(),jQuery("#ct_pause").show(),ct_working=!0,e?(ct_show_info(),ct_send_comments()):ct_clear_comments())}jQuery("#ct_check_spam_button").click(function(){e(!(document.cookie="ct_paused_spam_check=0; path=/; samesite=lax"))}),jQuery("#ct_proceed_check_button").click(function(){e(!0)}),jQuery("#ct_pause").on("click",function(){ct_pause=!0;var e={accurate:ct_accurate_check,from:ct_date_from,till:ct_date_till};document.cookie="ct_paused_spam_check="+JSON.stringify(e)+"; path=/; samesite=lax"}),"1"===ctCommentsCheck.start&&(document.cookie="ct_comments_start_check=0; expires="+new Date(0).toUTCString()+"; path=/; samesite=lax",jQuery("#ct_check_spam_button").click()),jQuery(".ct_delete_all").click(function(e){return!!confirm(ctCommentsCheck.ct_confirm_deletion_all)&&void ct_delete_all(e)})});
2
  //# sourceMappingURL=cleantalk-comments-checkspam.min.js.map
js/cleantalk-comments-checkspam.min.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cleantalk-comments-checkspam.min.js","sources":["cleantalk-comments-checkspam.js"],"sourcesContent":["// Printf for JS\r\nString.prototype.printf = function(){\r\n var formatted = this;\r\n for( var arg in arguments ) {\r\n\t\tvar before_formatted = formatted.substring(0, formatted.indexOf(\"%s\", 0));\r\n\t\tvar after_formatted = formatted.substring(formatted.indexOf(\"%s\", 0)+2, formatted.length);\r\n\t\tformatted = before_formatted + arguments[arg] + after_formatted;\r\n }\r\n return formatted;\r\n};\r\n\r\n// Flags\r\nvar ct_working = false,\r\n\tct_new_check = true,\r\n\tct_cooling_down_flag = false,\r\n\tct_close_animate = true,\r\n\tct_accurate_check = false,\r\n\tct_pause = false,\r\n\tct_prev_accurate = ctCommentsCheck.ct_prev_accurate,\r\n\tct_prev_from = ctCommentsCheck.ct_prev_from,\t\r\n\tct_prev_till = ctCommentsCheck.ct_prev_till;\r\n// Settings\r\nvar ct_cool_down_time = 90000,\r\n\tct_requests_counter = 0,\r\n\tct_max_requests = 60;\r\n// Variables\r\nvar ct_ajax_nonce = ctCommentsCheck.ct_ajax_nonce,\r\n\tct_comments_total = 0,\r\n\tct_comments_checked = 0,\r\n\tct_comments_spam = 0,\r\n\tct_comments_bad = 0,\r\n\tct_unchecked = 'unset',\r\n\tct_date_from = 0,\r\n\tct_date_till = 0;\r\n\r\nfunction animate_comment(to,id){\r\n\tif(ct_close_animate){\r\n\t\tif(to==0.3){\r\n\t\t\tjQuery('#comment-'+id).fadeTo(200,to,function(){\r\n\t\t\t\tanimate_comment(1,id)\r\n\t\t\t});\r\n\t\t}else{\r\n\t\t\tjQuery('#comment-'+id).fadeTo(200,to,function(){\r\n\t\t\t\tanimate_comment(0.3,id)\r\n\t\t\t});\r\n\t\t}\r\n\t}else{\r\n\t\tct_close_animate=true;\r\n\t}\r\n}\r\n\r\nfunction ct_clear_comments(){\r\n\r\n\tvar from = 0, till = 0;\r\n\tif(jQuery('#ct_allow_date_range').is(':checked')) {\r\n\t\tfrom = jQuery('#ct_date_range_from').val();\r\n\t\ttill = jQuery('#ct_date_range_till').val();\r\n\t}\r\n\tvar data = {\r\n\t\t'action' : 'ajax_clear_comments',\r\n\t\t'security' : ct_ajax_nonce,\r\n\t\t'from' : from,\r\n\t\t'till' : till\r\n\t};\r\n\r\n\tjQuery.ajax({\r\n\t\ttype: \"POST\",\r\n\t\turl: ajaxurl,\r\n\t\tdata: data,\r\n\t\tsuccess: function(msg){\r\n\t\t\tct_show_info();\r\n\t\t\tct_send_comments();\r\n\t\t}\r\n\t});\r\n}\r\n\r\n//Continues the check after cooldown time\r\n//Called by ct_send_users();\r\nfunction ct_cooling_down_toggle(){\r\n\tct_cooling_down_flag = false;\r\n\tct_send_comments();\r\n\tct_show_info();\r\n}\r\n\r\nfunction ct_send_comments(){\r\n\t\r\n\tif(ct_cooling_down_flag === true)\r\n\t\treturn;\r\n\t\r\n\tif(ct_requests_counter >= ct_max_requests){\r\n\t\tsetTimeout(ct_cooling_down_toggle, ct_cool_down_time);\r\n\t\tct_requests_counter = 0;\r\n\t\tct_cooling_down_flag = true;\r\n\t\treturn;\r\n\t}else{\r\n\t\tct_requests_counter++;\r\n\t}\r\n\t\r\n\tvar data = {\r\n\t\t'action': 'ajax_check_comments',\r\n\t\t'security': ct_ajax_nonce,\r\n\t\t'new_check': ct_new_check,\r\n\t\t'unchecked': ct_unchecked\r\n\t};\r\n\t\r\n\tif(ct_accurate_check)\r\n\t\tdata['accurate_check'] = true;\r\n\t\r\n\tif(ct_date_from && ct_date_till){\r\n\t\tdata['from'] = ct_date_from;\r\n\t\tdata['till'] = ct_date_till;\r\n\t}\r\n\t\r\n\tjQuery.ajax({\r\n\t\ttype: \"POST\",\r\n\t\turl: ajaxurl,\r\n\t\tdata: data,\r\n\t\tsuccess: function(msg){\r\n\t\t\t\r\n\t\t\tmsg = jQuery.parseJSON(msg);\r\n\t\t\t\r\n\t\t\tif(parseInt(msg.error)){\r\n\t\t\t\tct_working=false;\r\n\t\t\t\tif(!confirm(msg.error_message+\". Do you want to proceed?\")){\r\n\t\t\t\t\tvar new_href = 'edit-comments.php?page=ct_check_spam';\r\n\t\t\t\t\tif(ct_date_from != 0 && ct_date_till != 0)\r\n\t\t\t\t\t\tnew_href+='&from='+ct_date_from+'&till='+ct_date_till;\r\n\t\t\t\t\tlocation.href = new_href;\r\n\t\t\t\t}else\r\n\t\t\t\t\tct_send_comments();\r\n\t\t\t}else{\r\n\t\t\t\tct_new_check = false;\r\n\t\t\t\tif(parseInt(msg.end) == 1 || ct_pause === true){\r\n\t\t\t\t\tif(parseInt(msg.end) == 1)\r\n\t\t\t\t\t\tdocument.cookie = 'ct_paused_comments_check=0; path=/; samesite=lax';\r\n\t\t\t\t\tct_working=false;\r\n\t\t\t\t\tjQuery('#ct_working_message').hide();\r\n\t\t\t\t\tvar new_href = 'edit-comments.php?page=ct_check_spam';\r\n\t\t\t\t\tif(ct_date_from != 0 && ct_date_till != 0)\r\n\t\t\t\t\t\tnew_href+='&from='+ct_date_from+'&till='+ct_date_till;\r\n\t\t\t\t\tlocation.href = new_href;\r\n\t\t\t\t}else if(parseInt(msg.end) == 0){\r\n\t\t\t\t\tct_comments_checked += msg.checked;\r\n\t\t\t\t\tct_comments_spam += msg.spam;\r\n\t\t\t\t\tct_comments_bad += msg.bad;\r\n\t\t\t\t\tct_unchecked = ct_comments_total - ct_comments_checked - ct_comments_bad;\r\n\t\t\t\t\tvar status_string = String(ctCommentsCheck.ct_status_string);\r\n\t\t\t\t\tvar status_string = status_string.printf(ct_comments_checked, ct_comments_spam, ct_comments_bad);\r\n\t\t\t\t\tif(parseInt(ct_comments_spam) > 0)\r\n\t\t\t\t\t\tstatus_string += ctCommentsCheck.ct_status_string_warning;\r\n\t\t\t\t\tjQuery('#ct_checking_status').html(status_string);\r\n\t\t\t\t\tjQuery('#ct_error_message').hide();\r\n\t\t\t\t\t// If DB woks not properly\r\n\t\t\t\t\tif(+ct_comments_total < ct_comments_checked + ct_comments_bad){\r\n\t\t\t\t\t\tdocument.cookie = 'ct_comments_start_check=1; path=/; samesite=lax';\r\n\t\t\t\t\t\tdocument.cookie = 'ct_comments_safe_check=1; path=/; samesite=lax';\r\n\t\t\t\t\t\tlocation.href = 'edit-comments.php?page=ct_check_spam';\r\n\t\t\t\t\t}\r\n\t\t\t\t\tct_send_comments();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t},\r\n error: function(jqXHR, textStatus, errorThrown) {\r\n\t\t\tjQuery('#ct_error_message').show();\r\n\t\t\tjQuery('#cleantalk_ajax_error').html(textStatus);\r\n\t\t\tjQuery('#cleantalk_js_func').html('Check comments');\r\n\t\t\tsetTimeout(ct_send_comments(), 3000); \r\n },\r\n timeout: 25000\r\n\t});\r\n}\r\nfunction ct_show_info(){\r\n\t\r\n\tif(ct_working){\r\n\t\t\r\n\t\tif(ct_cooling_down_flag == true){\r\n\t\t\tjQuery('#ct_cooling_notice').html('Waiting for API to cool down. (About a minute)');\r\n\t\t\tjQuery('#ct_cooling_notice').show();\r\n\t\t\treturn;\t\t\t\r\n\t\t}else{\r\n\t\t\tjQuery('#ct_cooling_notice').hide();\r\n\t\t}\r\n\t\t\r\n\t\tif(!ct_comments_total){\r\n\t\t\t\r\n\t\t\tvar data = {\r\n\t\t\t\t'action': 'ajax_info_comments',\r\n\t\t\t\t'security': ct_ajax_nonce\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tif(ct_date_from && ct_date_till){\r\n\t\t\t\tdata['from'] = ct_date_from;\r\n\t\t\t\tdata['till'] = ct_date_till;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tjQuery.ajax({\r\n\t\t\t\ttype: \"POST\",\r\n\t\t\t\turl: ajaxurl,\r\n\t\t\t\tdata: data,\r\n\t\t\t\tsuccess: function(msg){\r\n\t\t\t\t\tmsg = jQuery.parseJSON(msg);\r\n\t\t\t\t\tjQuery('#ct_checking_status').html(msg.message);\r\n\t\t\t\t\tct_comments_total = msg.total;\r\n\t\t\t\t\tct_comments_spam = msg.spam;\r\n\t\t\t\t\tct_comments_checked = msg.checked;\r\n\t\t\t\t\tct_comments_bad = msg.bad;\r\n\t\t\t\t},\r\n\t\t\t\terror: function(jqXHR, textStatus, errorThrown) {\r\n\t\t\t\t\tjQuery('#ct_error_message').show();\r\n\t\t\t\t\tjQuery('#cleantalk_ajax_error').html(textStatus);\r\n\t\t\t\t\tjQuery('#cleantalk_js_func').html('Check comments');\r\n\t\t\t\t\tsetTimeout(ct_show_info(), 3000); \r\n\t\t\t\t},\r\n\t\t\t\ttimeout: 15000\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// Function to toggle dependences\r\nfunction ct_toggle_depended(obj, secondary){\r\n\r\n secondary = secondary || null;\r\n\r\n\tvar depended = jQuery(obj.data('depended')),\r\n\t\tstate = obj.data('state');\r\n\t\t\r\n\tif(!state && !secondary){\r\n\t\tobj.data('state', true);\r\n\t\tdepended.removeProp('disabled');\r\n\t}else{\r\n\t\tobj.data('state', false);\r\n\t\tdepended.prop('disabled', true);\r\n\t\tdepended.removeProp('checked');\r\n\t\tif(depended.data('depended'))\r\n\t\t\tct_toggle_depended(depended, true);\r\n\t}\r\n}\r\n\r\nfunction ct_delete_all( e ) {\r\n\r\n\tvar data = {\r\n\t\t'action': 'ajax_delete_all',\r\n\t\t'security': ct_ajax_nonce\r\n\t};\r\n\r\n\tjQuery('.' + e.target.id).addClass('disabled');\r\n\tjQuery('.spinner').css('visibility', 'visible');\r\n\tjQuery.ajax({\r\n\t\ttype: \"POST\",\r\n\t\turl: ajaxurl,\r\n\t\tdata: data,\r\n\t\tsuccess: function( msg ){\r\n\t\t\tif( msg > 0 ){\r\n\t\t\t\tjQuery('#cleantalk_comments_left').html(msg);\r\n\t\t\t\tct_delete_all( e );\r\n\t\t\t}else{\r\n\t\t\t\tjQuery('.' + e.target.id).removeClass('disabled');\r\n\t\t\t\tjQuery('.spinner').css('visibility', 'hidden');\r\n\t\t\t\tlocation.href='edit-comments.php?page=ct_check_spam_total';\r\n\t\t\t}\r\n\t\t},\r\n\t\terror: function(jqXHR, textStatus, errorThrown) {\r\n\t\t\tjQuery('#ct_error_message').show();\r\n\t\t\tjQuery('#cleantalk_ajax_error').html(textStatus);\r\n\t\t\tjQuery('#cleantalk_js_func').html('Check comments');\r\n\t\t\tsetTimeout(ct_delete_all( e ), 3000);\r\n\t\t},\r\n\t\ttimeout: 25000\r\n\t});\r\n\r\n}\r\n\r\njQuery(document).ready(function(){\r\n\r\n\t// Setting dependences\r\n\t// jQuery('#ct_accurate_check') .data({'depended': '#ct_allow_date_range', 'state': false});\r\n\tjQuery('#ct_allow_date_range').data({'depended': '.ct_date', 'state': false});\r\n\t\r\n\t// Prev check parameters\r\n\tif(ct_prev_accurate){\r\n\t\tjQuery(\"#ct_accurate_check\").prop('checked', true);\r\n\t}\r\n\tif(ct_prev_from){\r\n\t\tjQuery(\"#ct_allow_date_range\").prop('checked', true).data('state', true);\r\n\t\tjQuery(\"#ct_date_range_from\").removeProp('disabled').val(ct_prev_from);\r\n\t\tjQuery(\"#ct_date_range_till\").removeProp('disabled').val(ct_prev_till);\r\n\t}\r\n\t\r\n\t// Toggle dependences\r\n\tjQuery(\"#ct_allow_date_range, #ct_accurate_check\").on('change', function(){\r\n\t\tct_toggle_depended(jQuery(this));\r\n\t});\r\n\r\n jQuery.datepicker.setDefaults(jQuery.datepicker.regional['en']);\r\n\tvar dates = jQuery('#ct_date_range_from, #ct_date_range_till').datepicker(\r\n\t\t{\r\n\t\t\tdateFormat: 'M d yy',\r\n\t\t\tmaxDate:\"+0D\",\r\n\t\t\tchangeMonth:true,\r\n\t\t\tchangeYear:true,\r\n\t\t\tshowAnim: 'slideDown',\r\n\t\t\tonSelect: function(selectedDate){\r\n\t\t\tvar option = this.id == \"ct_date_range_from\" ? \"minDate\" : \"maxDate\",\r\n\t\t\t\tinstance = jQuery( this ).data( \"datepicker\" ),\r\n\t\t\t\tdate = jQuery.datepicker.parseDate(\r\n\t\t\t\t\tinstance.settings.dateFormat || jQuery.datepicker._defaults.dateFormat,\r\n\t\t\t\t\tselectedDate, instance.settings);\r\n\t\t\t\tdates.not(this).datepicker(\"option\", option, date);\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n\t\r\n\tfunction ct_start_check(continue_check){\r\n\r\n continue_check = continue_check || null;\r\n\r\n\t\tif(jQuery('#ct_allow_date_range').is(':checked')){\r\n\t\t\t\r\n\t\t\tct_date_from = jQuery('#ct_date_range_from').val(),\r\n\t\t\tct_date_till = jQuery('#ct_date_range_till').val();\r\n\t\t\t\t\t\t\r\n\t\t\tif(!(ct_date_from != '' && ct_date_till != '')){\r\n\t\t\t\talert('Please, specify a date range.');\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif(jQuery('#ct_accurate_check').is(':checked')){\r\n\t\t\tct_accurate_check = true;\r\n\t\t}\r\n\t\t\r\n\t\tjQuery('.ct_to_hide').hide();\r\n\t\tjQuery('#ct_working_message').show();\r\n\t\tjQuery('#ct_preloader').show();\r\n\t\tjQuery('#ct_pause').show();\r\n\r\n\t\tct_working=true;\r\n\t\t\r\n\t\tif(continue_check){\r\n\t\t\tct_show_info();\r\n\t\t\tct_send_comments();\r\n\t\t}else\r\n\t\t\tct_clear_comments();\r\n\t\t\r\n\t}\r\n\t\r\n\t// Check comments\r\n\tjQuery(\"#ct_check_spam_button\").click(function(){\r\n\t\tdocument.cookie = 'ct_paused_comments_check=0; path=/; samesite=lax';\r\n\t\tct_start_check(false);\r\n\t});\r\n\tjQuery(\"#ct_proceed_check_button\").click(function(){\r\n\t\tct_start_check(true);\r\n\t});\r\n\r\n\t// Pause the check\r\n\tjQuery('#ct_pause').on('click', function(){\r\n\t\tct_pause = true;\r\n\t\tvar ct_check = {\r\n\t\t\t'accurate': ct_accurate_check,\r\n\t\t\t'from' : ct_date_from,\r\n\t\t\t'till' : ct_date_till\r\n\t\t};\r\n\t\tdocument.cookie = 'ct_paused_comments_check=' + JSON.stringify(ct_check) + '; path=/; samesite=lax';\r\n\t});\r\n\r\n\r\n\tif(ctCommentsCheck.start === '1'){\r\n\t\tdocument.cookie = 'ct_comments_start_check=0; expires=' + new Date(0).toUTCString() + '; path=/; samesite=lax';\r\n\t\tjQuery('#ct_check_spam_button').click();\t\r\n\t}\r\n\r\n\t// Delete all spam comments\r\n\tjQuery(\".ct_delete_all\").click(function( e ){\r\n\r\n\t\tif (!confirm(ctCommentsCheck.ct_confirm_deletion_all))\r\n\t\t\treturn false;\r\n\r\n\t\tct_delete_all( e );\r\n\r\n\t});\r\n\r\n});"],"names":["ct_working","String","prototype","printf","formatted","this","arg","arguments","before_formatted","substring","indexOf","after_formatted","length","ct_new_check","ct_cooling_down_flag","ct_close_animate","ct_accurate_check","ct_pause","ct_prev_accurate","ctCommentsCheck","ct_prev_from","ct_prev_till","ct_cool_down_time","ct_requests_counter","ct_max_requests","ct_ajax_nonce","ct_comments_total","ct_comments_checked","ct_comments_spam","ct_comments_bad","ct_unchecked","ct_date_from","ct_date_till","animate_comment","to","id","jQuery","fadeTo","ct_clear_comments","from","till","is","val","data","action","security","ajax","type","url","ajaxurl","success","msg","ct_show_info","ct_send_comments","ct_cooling_down_toggle","setTimeout","new_check","unchecked","new_href","status_string","parseJSON","parseInt","error","confirm","error_message","location","href","end","document","cookie","hide","checked","spam","bad","ct_status_string","ct_status_string_warning","html","jqXHR","textStatus","errorThrown","show","timeout","message","total","ct_toggle_depended","obj","secondary","depended","prop","removeProp","ct_delete_all","e","target","addClass","css","removeClass","ready","state","on","datepicker","setDefaults","regional","dates","dateFormat","maxDate","changeMonth","changeYear","showAnim","onSelect","selectedDate","option","instance","date","parseDate","settings","_defaults","not","ct_start_check","continue_check","alert","click","ct_check","accurate","JSON","stringify","start","Date","toUTCString","ct_confirm_deletion_all"],"mappings":"AAYA,IAAIA,aAXJC,OAAOC,UAAUC,OAAS,WACtB,IAAIC,EAAYC,KAChB,IAAK,IAAIC,KAAOC,UAClB,IAAIC,EAAmBJ,EAAUK,UAAU,EAAGL,EAAUM,QAAQ,KAAM,IAClEC,EAAmBP,EAAUK,UAAUL,EAAUM,QAAQ,KAAM,GAAG,EAAGN,EAAUQ,QACnFR,EAAYI,EAAmBD,UAAUD,GAAOK,EAE9C,OAAOP,IAKVS,cAAe,EACfC,sBAAuB,EACvBC,kBAAmB,EACnBC,mBAAoB,EACpBC,UAAW,EACXC,iBAAmBC,gBAAgBD,iBACnCE,aAAeD,gBAAgBC,aAC/BC,aAAeF,gBAAgBE,aAE5BC,kBAAoB,IACvBC,oBAAsB,EACtBC,gBAAkB,GAEfC,cAAgBN,gBAAgBM,cACnCC,kBAAoB,EACpBC,oBAAsB,EACtBC,iBAAmB,EACnBC,gBAAkB,EAClBC,aAAe,QACfC,aAAe,EACfC,aAAe,EAEhB,SAASC,gBAAgBC,EAAGC,GACxBpB,iBACK,IAAJmB,EACFE,OAAO,YAAYD,GAAIE,OAAO,IAAIH,EAAG,WACpCD,gBAAgB,EAAEE,KAGnBC,OAAO,YAAYD,GAAIE,OAAO,IAAIH,EAAG,WACpCD,gBAAgB,GAAIE,KAItBpB,kBAAiB,EAInB,SAASuB,oBAER,IAAIC,EAAO,EAAGC,EAAO,EAClBJ,OAAO,wBAAwBK,GAAG,cACpCF,EAAOH,OAAO,uBAAuBM,MACrCF,EAAOJ,OAAO,uBAAuBM,OAEtC,IAAIC,EAAO,CACVC,OAAa,sBACbC,SAAapB,cACbc,KAAaA,EACbC,KAAaA,GAGdJ,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAASC,GACjBC,eACAC,sBAOH,SAASC,yBACRxC,sBAAuB,EACvBuC,mBACAD,eAGD,SAASC,mBAER,IAA4B,IAAzBvC,qBAAH,CAGA,GAA0BU,iBAAvBD,oBAIF,OAHAgC,WAAWD,uBAAwBhC,wBAEnCR,uBADAS,oBAAsB,IAItBA,sBAGD,IAAIoB,EAAO,CACVC,OAAU,sBACVC,SAAYpB,cACZ+B,UAAa3C,aACb4C,UAAa3B,cAGXd,oBACF2B,EAAqB,gBAAI,GAEvBZ,cAAgBC,eAClBW,EAAW,KAAIZ,aACfY,EAAW,KAAIX,cAGhBI,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAASC,GAIjB,IAgBMO,EAUAC,EA5BNR,EAAMf,OAAOwB,UAAUT,GAEpBU,SAASV,EAAIW,QACf9D,YAAW,EACP+D,QAAQZ,EAAIa,cAAc,6BAM7BX,oBALIK,EAAW,uCACI,GAAhB3B,cAAqC,GAAhBC,eACvB0B,GAAU,SAAS3B,aAAa,SAASC,cAC1CiC,SAASC,KAAOR,KAIjB7C,cAAe,EACS,GAArBgD,SAASV,EAAIgB,OAA0B,IAAblD,UACJ,GAArB4C,SAASV,EAAIgB,OACfC,SAASC,OAAS,oDACnBrE,YAAW,EACXoC,OAAO,uBAAuBkC,OAC1BZ,EAAW,uCACI,GAAhB3B,cAAqC,GAAhBC,eACvB0B,GAAU,SAAS3B,aAAa,SAASC,cAC1CiC,SAASC,KAAOR,GACa,GAArBG,SAASV,EAAIgB,OACrBxC,qBAAuBwB,EAAIoB,QAC3B3C,kBAAoBuB,EAAIqB,KACxB3C,iBAAmBsB,EAAIsB,IACvB3C,aAAeJ,kBAAoBC,oBAAsBE,gBAErD8B,GADAA,EAAgB1D,OAAOkB,gBAAgBuD,mBACTvE,OAAOwB,oBAAqBC,iBAAkBC,iBAChD,EAA7BgC,SAASjC,oBACX+B,GAAiBxC,gBAAgBwD,0BAClCvC,OAAO,uBAAuBwC,KAAKjB,GACnCvB,OAAO,qBAAqBkC,QAExB5C,kBAAoBC,oBAAsBE,kBAC7CuC,SAASC,OAAS,kDAClBD,SAASC,OAAS,iDAClBJ,SAASC,KAAO,wCAEjBb,sBAIGS,MAAO,SAASe,EAAOC,EAAYC,GACxC3C,OAAO,qBAAqB4C,OAC5B5C,OAAO,yBAAyBwC,KAAKE,GACrC1C,OAAO,sBAAsBwC,KAAK,kBAClCrB,WAAWF,mBAAoB,MAE1B4B,QAAS,QAGjB,SAAS7B,eAER,GAAGpD,WAAW,CAEb,GAA2B,GAAxBc,qBAGF,OAFAsB,OAAO,sBAAsBwC,KAAK,uDAClCxC,OAAO,sBAAsB4C,OAM9B,IAEKrC,EALJP,OAAO,sBAAsBkC,OAG1B5C,oBAECiB,EAAO,CACVC,OAAU,qBACVC,SAAYpB,eAGVM,cAAgBC,eAClBW,EAAW,KAAIZ,aACfY,EAAW,KAAIX,cAGhBI,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAASC,GACjBA,EAAMf,OAAOwB,UAAUT,GACvBf,OAAO,uBAAuBwC,KAAKzB,EAAI+B,SACvCxD,kBAAsByB,EAAIgC,MAC1BvD,iBAAsBuB,EAAIqB,KAC1B7C,oBAAsBwB,EAAIoB,QAC1B1C,gBAAsBsB,EAAIsB,KAE3BX,MAAO,SAASe,EAAOC,EAAYC,GAClC3C,OAAO,qBAAqB4C,OAC5B5C,OAAO,yBAAyBwC,KAAKE,GACrC1C,OAAO,sBAAsBwC,KAAK,kBAClCrB,WAAWH,eAAgB,MAE5B6B,QAAS,SAOb,SAASG,mBAAmBC,EAAKC,GAE7BA,EAAYA,GAAa,KAE5B,IAAIC,EAAWnD,OAAOiD,EAAI1C,KAAK,aACtB0C,EAAI1C,KAAK,UAEJ2C,GAIbD,EAAI1C,KAAK,SAAS,GAClB4C,EAASC,KAAK,YAAY,GAC1BD,EAASE,WAAW,WACjBF,EAAS5C,KAAK,aAChByC,mBAAmBG,GAAU,KAP9BF,EAAI1C,KAAK,SAAS,GAClB4C,EAASE,WAAW,aAUtB,SAASC,cAAeC,GAEvB,IAAIhD,EAAO,CACVC,OAAU,kBACVC,SAAYpB,eAGbW,OAAO,IAAMuD,EAAEC,OAAOzD,IAAI0D,SAAS,YACnCzD,OAAO,YAAY0D,IAAI,aAAc,WACrC1D,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAAUC,GACR,EAANA,GACHf,OAAO,4BAA4BwC,KAAKzB,GACxCuC,cAAeC,KAEfvD,OAAO,IAAMuD,EAAEC,OAAOzD,IAAI4D,YAAY,YACtC3D,OAAO,YAAY0D,IAAI,aAAc,UACrC7B,SAASC,KAAK,+CAGhBJ,MAAO,SAASe,EAAOC,EAAYC,GAClC3C,OAAO,qBAAqB4C,OAC5B5C,OAAO,yBAAyBwC,KAAKE,GACrC1C,OAAO,sBAAsBwC,KAAK,kBAClCrB,WAAWmC,cAAeC,GAAK,MAEhCV,QAAS,OAKX7C,OAAOgC,UAAU4B,MAAM,WAItB5D,OAAO,wBAAwBO,KAAK,CAAC4C,SAAY,WAAYU,OAAS,IAGnE/E,kBACFkB,OAAO,sBAAsBoD,KAAK,WAAW,GAE3CpE,eACFgB,OAAO,wBAAwBoD,KAAK,WAAW,GAAM7C,KAAK,SAAS,GACnEP,OAAO,uBAAuBqD,WAAW,YAAY/C,IAAItB,cACzDgB,OAAO,uBAAuBqD,WAAW,YAAY/C,IAAIrB,eAI1De,OAAO,4CAA4C8D,GAAG,SAAU,WAC/Dd,mBAAmBhD,OAAO/B,SAGxB+B,OAAO+D,WAAWC,YAAYhE,OAAO+D,WAAWE,SAAa,IAChE,IAAIC,EAAQlE,OAAO,4CAA4C+D,WAC9D,CACCI,WAAY,SACZC,QAAQ,MACRC,aAAY,EACZC,YAAW,EACXC,SAAU,YACVC,SAAU,SAASC,GACnB,IAAIC,EAAoB,sBAAXzG,KAAK8B,GAA6B,UAAY,UAC1D4E,EAAW3E,OAAQ/B,MAAOsC,KAAM,cAChCqE,EAAO5E,OAAO+D,WAAWc,UACxBF,EAASG,SAASX,YAAcnE,OAAO+D,WAAWgB,UAAUZ,WAC5DM,EAAcE,EAASG,UACxBZ,EAAMc,IAAI/G,MAAM8F,WAAW,SAAUW,EAAQE,MAKhD,SAASK,EAAeC,GAEjBA,EAAiBA,GAAkB,KAEtClF,OAAO,wBAAwBK,GAAG,cAEpCV,aAAeK,OAAO,uBAAuBM,MAC7CV,aAAeI,OAAO,uBAAuBM,MAExB,IAAhBX,cAAsC,IAAhBC,cAC1BuF,MAAM,kCAKLnF,OAAO,sBAAsBK,GAAG,cAClCzB,mBAAoB,GAGrBoB,OAAO,eAAekC,OACtBlC,OAAO,uBAAuB4C,OAC9B5C,OAAO,iBAAiB4C,OACxB5C,OAAO,aAAa4C,OAEpBhF,YAAW,EAERsH,GACFlE,eACAC,oBAEAf,qBAKFF,OAAO,yBAAyBoF,MAAM,WAErCH,IADAjD,SAASC,OAAS,uDAGnBjC,OAAO,4BAA4BoF,MAAM,WACxCH,GAAe,KAIhBjF,OAAO,aAAa8D,GAAG,QAAS,WAC/BjF,UAAW,EACX,IAAIwG,EAAW,CACdC,SAAY1G,kBACZuB,KAAYR,aACZS,KAAYR,cAEboC,SAASC,OAAS,4BAA8BsD,KAAKC,UAAUH,GAAY,2BAI/C,MAA1BtG,gBAAgB0G,QAClBzD,SAASC,OAAS,sCAAwC,IAAIyD,KAAK,GAAGC,cAAgB,yBACtF3F,OAAO,yBAAyBoF,SAIjCpF,OAAO,kBAAkBoF,MAAM,SAAU7B,GAExC,QAAK5B,QAAQ5C,gBAAgB6G,+BAG7BtC,cAAeC"}
1
+ {"version":3,"file":"cleantalk-comments-checkspam.min.js","sources":["cleantalk-comments-checkspam.js"],"sourcesContent":["// Printf for JS\r\nString.prototype.printf = function(){\r\n var formatted = this;\r\n for( var arg in arguments ) {\r\n\t\tvar before_formatted = formatted.substring(0, formatted.indexOf(\"%s\", 0));\r\n\t\tvar after_formatted = formatted.substring(formatted.indexOf(\"%s\", 0)+2, formatted.length);\r\n\t\tformatted = before_formatted + arguments[arg] + after_formatted;\r\n }\r\n return formatted;\r\n};\r\n\r\n// Flags\r\nvar ct_working = false,\r\n\tct_new_check = true,\r\n\tct_cooling_down_flag = false,\r\n\tct_close_animate = true,\r\n\tct_accurate_check = false,\r\n\tct_pause = false,\r\n\tct_prev_accurate = ctCommentsCheck.ct_prev_accurate,\r\n\tct_prev_from = ctCommentsCheck.ct_prev_from,\t\r\n\tct_prev_till = ctCommentsCheck.ct_prev_till;\r\n// Settings\r\nvar ct_cool_down_time = 90000,\r\n\tct_requests_counter = 0,\r\n\tct_max_requests = 60;\r\n// Variables\r\nvar ct_ajax_nonce = ctCommentsCheck.ct_ajax_nonce,\r\n\tct_comments_total = 0,\r\n\tct_comments_checked = 0,\r\n\tct_comments_spam = 0,\r\n\tct_comments_bad = 0,\r\n\tct_unchecked = 'unset',\r\n\tct_date_from = 0,\r\n\tct_date_till = 0;\r\n\r\nfunction animate_comment(to,id){\r\n\tif(ct_close_animate){\r\n\t\tif(to==0.3){\r\n\t\t\tjQuery('#comment-'+id).fadeTo(200,to,function(){\r\n\t\t\t\tanimate_comment(1,id)\r\n\t\t\t});\r\n\t\t}else{\r\n\t\t\tjQuery('#comment-'+id).fadeTo(200,to,function(){\r\n\t\t\t\tanimate_comment(0.3,id)\r\n\t\t\t});\r\n\t\t}\r\n\t}else{\r\n\t\tct_close_animate=true;\r\n\t}\r\n}\r\n\r\nfunction ct_clear_comments(){\r\n\r\n\tvar from = 0, till = 0;\r\n\tif(jQuery('#ct_allow_date_range').is(':checked')) {\r\n\t\tfrom = jQuery('#ct_date_range_from').val();\r\n\t\ttill = jQuery('#ct_date_range_till').val();\r\n\t}\r\n\tvar data = {\r\n\t\t'action' : 'ajax_clear_comments',\r\n\t\t'security' : ct_ajax_nonce,\r\n\t\t'from' : from,\r\n\t\t'till' : till\r\n\t};\r\n\r\n\tjQuery.ajax({\r\n\t\ttype: \"POST\",\r\n\t\turl: ajaxurl,\r\n\t\tdata: data,\r\n\t\tsuccess: function(msg){\r\n\t\t\tct_show_info();\r\n\t\t\tct_send_comments();\r\n\t\t}\r\n\t});\r\n}\r\n\r\n//Continues the check after cooldown time\r\n//Called by ct_send_users();\r\nfunction ct_cooling_down_toggle(){\r\n\tct_cooling_down_flag = false;\r\n\tct_send_comments();\r\n\tct_show_info();\r\n}\r\n\r\nfunction ct_send_comments(){\r\n\t\r\n\tif(ct_cooling_down_flag === true)\r\n\t\treturn;\r\n\t\r\n\tif(ct_requests_counter >= ct_max_requests){\r\n\t\tsetTimeout(ct_cooling_down_toggle, ct_cool_down_time);\r\n\t\tct_requests_counter = 0;\r\n\t\tct_cooling_down_flag = true;\r\n\t\treturn;\r\n\t}else{\r\n\t\tct_requests_counter++;\r\n\t}\r\n\t\r\n\tvar data = {\r\n\t\t'action': 'ajax_check_comments',\r\n\t\t'security': ct_ajax_nonce,\r\n\t\t'new_check': ct_new_check,\r\n\t\t'unchecked': ct_unchecked\r\n\t};\r\n\t\r\n\tif(ct_accurate_check)\r\n\t\tdata['accurate_check'] = true;\r\n\t\r\n\tif(ct_date_from && ct_date_till){\r\n\t\tdata['from'] = ct_date_from;\r\n\t\tdata['till'] = ct_date_till;\r\n\t}\r\n\t\r\n\tjQuery.ajax({\r\n\t\ttype: \"POST\",\r\n\t\turl: ajaxurl,\r\n\t\tdata: data,\r\n\t\tsuccess: function(msg){\r\n\t\t\t\r\n\t\t\tmsg = jQuery.parseJSON(msg);\r\n\t\t\t\r\n\t\t\tif(parseInt(msg.error)){\r\n\t\t\t\tct_working=false;\r\n\t\t\t\tif(!confirm(msg.error_message+\". Do you want to proceed?\")){\r\n\t\t\t\t\tvar new_href = 'edit-comments.php?page=ct_check_spam';\r\n\t\t\t\t\tif(ct_date_from != 0 && ct_date_till != 0)\r\n\t\t\t\t\t\tnew_href+='&from='+ct_date_from+'&till='+ct_date_till;\r\n\t\t\t\t\tlocation.href = new_href;\r\n\t\t\t\t}else\r\n\t\t\t\t\tct_send_comments();\r\n\t\t\t}else{\r\n\t\t\t\tct_new_check = false;\r\n\t\t\t\tif(parseInt(msg.end) == 1 || ct_pause === true){\r\n\t\t\t\t\tif(parseInt(msg.end) == 1)\r\n\t\t\t\t\t\tdocument.cookie = 'ct_paused_spam_check=0; path=/; samesite=lax';\r\n\t\t\t\t\tct_working=false;\r\n\t\t\t\t\tjQuery('#ct_working_message').hide();\r\n\t\t\t\t\tvar new_href = 'edit-comments.php?page=ct_check_spam';\r\n\t\t\t\t\tif(ct_date_from != 0 && ct_date_till != 0)\r\n\t\t\t\t\t\tnew_href+='&from='+ct_date_from+'&till='+ct_date_till;\r\n\t\t\t\t\tlocation.href = new_href;\r\n\t\t\t\t}else if(parseInt(msg.end) == 0){\r\n\t\t\t\t\tct_comments_checked += msg.checked;\r\n\t\t\t\t\tct_comments_spam += msg.spam;\r\n\t\t\t\t\tct_comments_bad += msg.bad;\r\n\t\t\t\t\tct_unchecked = ct_comments_total - ct_comments_checked - ct_comments_bad;\r\n\t\t\t\t\tvar status_string = String(ctCommentsCheck.ct_status_string);\r\n\t\t\t\t\tvar status_string = status_string.printf(ct_comments_checked, ct_comments_spam, ct_comments_bad);\r\n\t\t\t\t\tif(parseInt(ct_comments_spam) > 0)\r\n\t\t\t\t\t\tstatus_string += ctCommentsCheck.ct_status_string_warning;\r\n\t\t\t\t\tjQuery('#ct_checking_status').html(status_string);\r\n\t\t\t\t\tjQuery('#ct_error_message').hide();\r\n\t\t\t\t\t// If DB woks not properly\r\n\t\t\t\t\tif(+ct_comments_total < ct_comments_checked + ct_comments_bad){\r\n\t\t\t\t\t\tdocument.cookie = 'ct_comments_start_check=1; path=/; samesite=lax';\r\n\t\t\t\t\t\tdocument.cookie = 'ct_comments_safe_check=1; path=/; samesite=lax';\r\n\t\t\t\t\t\tlocation.href = 'edit-comments.php?page=ct_check_spam';\r\n\t\t\t\t\t}\r\n\t\t\t\t\tct_send_comments();\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t},\r\n error: function(jqXHR, textStatus, errorThrown) {\r\n\t\t\tjQuery('#ct_error_message').show();\r\n\t\t\tjQuery('#cleantalk_ajax_error').html(textStatus);\r\n\t\t\tjQuery('#cleantalk_js_func').html('Check comments');\r\n\t\t\tsetTimeout(ct_send_comments(), 3000); \r\n },\r\n timeout: 25000\r\n\t});\r\n}\r\nfunction ct_show_info(){\r\n\t\r\n\tif(ct_working){\r\n\t\t\r\n\t\tif(ct_cooling_down_flag == true){\r\n\t\t\tjQuery('#ct_cooling_notice').html('Waiting for API to cool down. (About a minute)');\r\n\t\t\tjQuery('#ct_cooling_notice').show();\r\n\t\t\treturn;\t\t\t\r\n\t\t}else{\r\n\t\t\tjQuery('#ct_cooling_notice').hide();\r\n\t\t}\r\n\t\t\r\n\t\tif(!ct_comments_total){\r\n\t\t\t\r\n\t\t\tvar data = {\r\n\t\t\t\t'action': 'ajax_info_comments',\r\n\t\t\t\t'security': ct_ajax_nonce\r\n\t\t\t};\r\n\t\t\t\r\n\t\t\tif(ct_date_from && ct_date_till){\r\n\t\t\t\tdata['from'] = ct_date_from;\r\n\t\t\t\tdata['till'] = ct_date_till;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tjQuery.ajax({\r\n\t\t\t\ttype: \"POST\",\r\n\t\t\t\turl: ajaxurl,\r\n\t\t\t\tdata: data,\r\n\t\t\t\tsuccess: function(msg){\r\n\t\t\t\t\tmsg = jQuery.parseJSON(msg);\r\n\t\t\t\t\tjQuery('#ct_checking_status').html(msg.message);\r\n\t\t\t\t\tct_comments_total = msg.total;\r\n\t\t\t\t\tct_comments_spam = msg.spam;\r\n\t\t\t\t\tct_comments_checked = msg.checked;\r\n\t\t\t\t\tct_comments_bad = msg.bad;\r\n\t\t\t\t},\r\n\t\t\t\terror: function(jqXHR, textStatus, errorThrown) {\r\n\t\t\t\t\tjQuery('#ct_error_message').show();\r\n\t\t\t\t\tjQuery('#cleantalk_ajax_error').html(textStatus);\r\n\t\t\t\t\tjQuery('#cleantalk_js_func').html('Check comments');\r\n\t\t\t\t\tsetTimeout(ct_show_info(), 3000); \r\n\t\t\t\t},\r\n\t\t\t\ttimeout: 15000\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n}\r\n\r\n// Function to toggle dependences\r\nfunction ct_toggle_depended(obj, secondary){\r\n\r\n secondary = secondary || null;\r\n\r\n\tvar depended = jQuery(obj.data('depended')),\r\n\t\tstate = obj.data('state');\r\n\t\t\r\n\tif(!state && !secondary){\r\n\t\tobj.data('state', true);\r\n\t\tdepended.removeProp('disabled');\r\n\t}else{\r\n\t\tobj.data('state', false);\r\n\t\tdepended.prop('disabled', true);\r\n\t\tdepended.removeProp('checked');\r\n\t\tif(depended.data('depended'))\r\n\t\t\tct_toggle_depended(depended, true);\r\n\t}\r\n}\r\n\r\nfunction ct_delete_all( e ) {\r\n\r\n\tvar data = {\r\n\t\t'action': 'ajax_delete_all',\r\n\t\t'security': ct_ajax_nonce\r\n\t};\r\n\r\n\tjQuery('.' + e.target.id).addClass('disabled');\r\n\tjQuery('.spinner').css('visibility', 'visible');\r\n\tjQuery.ajax({\r\n\t\ttype: \"POST\",\r\n\t\turl: ajaxurl,\r\n\t\tdata: data,\r\n\t\tsuccess: function( msg ){\r\n\t\t\tif( msg > 0 ){\r\n\t\t\t\tjQuery('#cleantalk_comments_left').html(msg);\r\n\t\t\t\tct_delete_all( e );\r\n\t\t\t}else{\r\n\t\t\t\tjQuery('.' + e.target.id).removeClass('disabled');\r\n\t\t\t\tjQuery('.spinner').css('visibility', 'hidden');\r\n\t\t\t\tlocation.href='edit-comments.php?page=ct_check_spam_total';\r\n\t\t\t}\r\n\t\t},\r\n\t\terror: function(jqXHR, textStatus, errorThrown) {\r\n\t\t\tjQuery('#ct_error_message').show();\r\n\t\t\tjQuery('#cleantalk_ajax_error').html(textStatus);\r\n\t\t\tjQuery('#cleantalk_js_func').html('Check comments');\r\n\t\t\tsetTimeout(ct_delete_all( e ), 3000);\r\n\t\t},\r\n\t\ttimeout: 25000\r\n\t});\r\n\r\n}\r\n\r\njQuery(document).ready(function(){\r\n\r\n\t// Setting dependences\r\n\t// jQuery('#ct_accurate_check') .data({'depended': '#ct_allow_date_range', 'state': false});\r\n\tjQuery('#ct_allow_date_range').data({'depended': '.ct_date', 'state': false});\r\n\t\r\n\t// Prev check parameters\r\n\tif(ct_prev_accurate){\r\n\t\tjQuery(\"#ct_accurate_check\").prop('checked', true);\r\n\t}\r\n\tif(ct_prev_from){\r\n\t\tjQuery(\"#ct_allow_date_range\").prop('checked', true).data('state', true);\r\n\t\tjQuery(\"#ct_date_range_from\").removeProp('disabled').val(ct_prev_from);\r\n\t\tjQuery(\"#ct_date_range_till\").removeProp('disabled').val(ct_prev_till);\r\n\t}\r\n\t\r\n\t// Toggle dependences\r\n\tjQuery(\"#ct_allow_date_range, #ct_accurate_check\").on('change', function(){\r\n\t\tct_toggle_depended(jQuery(this));\r\n\t});\r\n\r\n jQuery.datepicker.setDefaults(jQuery.datepicker.regional['en']);\r\n\tvar dates = jQuery('#ct_date_range_from, #ct_date_range_till').datepicker(\r\n\t\t{\r\n\t\t\tdateFormat: 'M d yy',\r\n\t\t\tmaxDate:\"+0D\",\r\n\t\t\tchangeMonth:true,\r\n\t\t\tchangeYear:true,\r\n\t\t\tshowAnim: 'slideDown',\r\n\t\t\tonSelect: function(selectedDate){\r\n\t\t\tvar option = this.id == \"ct_date_range_from\" ? \"minDate\" : \"maxDate\",\r\n\t\t\t\tinstance = jQuery( this ).data( \"datepicker\" ),\r\n\t\t\t\tdate = jQuery.datepicker.parseDate(\r\n\t\t\t\t\tinstance.settings.dateFormat || jQuery.datepicker._defaults.dateFormat,\r\n\t\t\t\t\tselectedDate, instance.settings);\r\n\t\t\t\tdates.not(this).datepicker(\"option\", option, date);\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n\t\r\n\tfunction ct_start_check(continue_check){\r\n\r\n continue_check = continue_check || null;\r\n\r\n\t\tif(jQuery('#ct_allow_date_range').is(':checked')){\r\n\t\t\t\r\n\t\t\tct_date_from = jQuery('#ct_date_range_from').val(),\r\n\t\t\tct_date_till = jQuery('#ct_date_range_till').val();\r\n\t\t\t\t\t\t\r\n\t\t\tif(!(ct_date_from != '' && ct_date_till != '')){\r\n\t\t\t\talert('Please, specify a date range.');\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif(jQuery('#ct_accurate_check').is(':checked')){\r\n\t\t\tct_accurate_check = true;\r\n\t\t}\r\n\t\t\r\n\t\tjQuery('.ct_to_hide').hide();\r\n\t\tjQuery('#ct_working_message').show();\r\n\t\tjQuery('#ct_preloader').show();\r\n\t\tjQuery('#ct_pause').show();\r\n\r\n\t\tct_working=true;\r\n\t\t\r\n\t\tif(continue_check){\r\n\t\t\tct_show_info();\r\n\t\t\tct_send_comments();\r\n\t\t}else\r\n\t\t\tct_clear_comments();\r\n\t\t\r\n\t}\r\n\t\r\n\t// Check comments\r\n\tjQuery(\"#ct_check_spam_button\").click(function(){\r\n\t\tdocument.cookie = 'ct_paused_spam_check=0; path=/; samesite=lax';\r\n\t\tct_start_check(false);\r\n\t});\r\n\tjQuery(\"#ct_proceed_check_button\").click(function(){\r\n\t\tct_start_check(true);\r\n\t});\r\n\r\n\t// Pause the check\r\n\tjQuery('#ct_pause').on('click', function(){\r\n\t\tct_pause = true;\r\n\t\tvar ct_check = {\r\n\t\t\t'accurate': ct_accurate_check,\r\n\t\t\t'from' : ct_date_from,\r\n\t\t\t'till' : ct_date_till\r\n\t\t};\r\n\t\tdocument.cookie = 'ct_paused_spam_check=' + JSON.stringify(ct_check) + '; path=/; samesite=lax';\r\n\t});\r\n\r\n\r\n\tif(ctCommentsCheck.start === '1'){\r\n\t\tdocument.cookie = 'ct_comments_start_check=0; expires=' + new Date(0).toUTCString() + '; path=/; samesite=lax';\r\n\t\tjQuery('#ct_check_spam_button').click();\t\r\n\t}\r\n\r\n\t// Delete all spam comments\r\n\tjQuery(\".ct_delete_all\").click(function( e ){\r\n\r\n\t\tif (!confirm(ctCommentsCheck.ct_confirm_deletion_all))\r\n\t\t\treturn false;\r\n\r\n\t\tct_delete_all( e );\r\n\r\n\t});\r\n\r\n});"],"names":["ct_working","String","prototype","printf","formatted","this","arg","arguments","before_formatted","substring","indexOf","after_formatted","length","ct_new_check","ct_cooling_down_flag","ct_close_animate","ct_accurate_check","ct_pause","ct_prev_accurate","ctCommentsCheck","ct_prev_from","ct_prev_till","ct_cool_down_time","ct_requests_counter","ct_max_requests","ct_ajax_nonce","ct_comments_total","ct_comments_checked","ct_comments_spam","ct_comments_bad","ct_unchecked","ct_date_from","ct_date_till","animate_comment","to","id","jQuery","fadeTo","ct_clear_comments","from","till","is","val","data","action","security","ajax","type","url","ajaxurl","success","msg","ct_show_info","ct_send_comments","ct_cooling_down_toggle","setTimeout","new_check","unchecked","new_href","status_string","parseJSON","parseInt","error","confirm","error_message","location","href","end","document","cookie","hide","checked","spam","bad","ct_status_string","ct_status_string_warning","html","jqXHR","textStatus","errorThrown","show","timeout","message","total","ct_toggle_depended","obj","secondary","depended","prop","removeProp","ct_delete_all","e","target","addClass","css","removeClass","ready","state","on","datepicker","setDefaults","regional","dates","dateFormat","maxDate","changeMonth","changeYear","showAnim","onSelect","selectedDate","option","instance","date","parseDate","settings","_defaults","not","ct_start_check","continue_check","alert","click","ct_check","accurate","JSON","stringify","start","Date","toUTCString","ct_confirm_deletion_all"],"mappings":"AAYA,IAAIA,aAXJC,OAAOC,UAAUC,OAAS,WACtB,IAAIC,EAAYC,KAChB,IAAK,IAAIC,KAAOC,UAClB,IAAIC,EAAmBJ,EAAUK,UAAU,EAAGL,EAAUM,QAAQ,KAAM,IAClEC,EAAmBP,EAAUK,UAAUL,EAAUM,QAAQ,KAAM,GAAG,EAAGN,EAAUQ,QACnFR,EAAYI,EAAmBD,UAAUD,GAAOK,EAE9C,OAAOP,IAKVS,cAAe,EACfC,sBAAuB,EACvBC,kBAAmB,EACnBC,mBAAoB,EACpBC,UAAW,EACXC,iBAAmBC,gBAAgBD,iBACnCE,aAAeD,gBAAgBC,aAC/BC,aAAeF,gBAAgBE,aAE5BC,kBAAoB,IACvBC,oBAAsB,EACtBC,gBAAkB,GAEfC,cAAgBN,gBAAgBM,cACnCC,kBAAoB,EACpBC,oBAAsB,EACtBC,iBAAmB,EACnBC,gBAAkB,EAClBC,aAAe,QACfC,aAAe,EACfC,aAAe,EAEhB,SAASC,gBAAgBC,EAAGC,GACxBpB,iBACK,IAAJmB,EACFE,OAAO,YAAYD,GAAIE,OAAO,IAAIH,EAAG,WACpCD,gBAAgB,EAAEE,KAGnBC,OAAO,YAAYD,GAAIE,OAAO,IAAIH,EAAG,WACpCD,gBAAgB,GAAIE,KAItBpB,kBAAiB,EAInB,SAASuB,oBAER,IAAIC,EAAO,EAAGC,EAAO,EAClBJ,OAAO,wBAAwBK,GAAG,cACpCF,EAAOH,OAAO,uBAAuBM,MACrCF,EAAOJ,OAAO,uBAAuBM,OAEtC,IAAIC,EAAO,CACVC,OAAa,sBACbC,SAAapB,cACbc,KAAaA,EACbC,KAAaA,GAGdJ,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAASC,GACjBC,eACAC,sBAOH,SAASC,yBACRxC,sBAAuB,EACvBuC,mBACAD,eAGD,SAASC,mBAER,IAA4B,IAAzBvC,qBAAH,CAGA,GAA0BU,iBAAvBD,oBAIF,OAHAgC,WAAWD,uBAAwBhC,wBAEnCR,uBADAS,oBAAsB,IAItBA,sBAGD,IAAIoB,EAAO,CACVC,OAAU,sBACVC,SAAYpB,cACZ+B,UAAa3C,aACb4C,UAAa3B,cAGXd,oBACF2B,EAAqB,gBAAI,GAEvBZ,cAAgBC,eAClBW,EAAW,KAAIZ,aACfY,EAAW,KAAIX,cAGhBI,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAASC,GAIjB,IAgBMO,EAUAC,EA5BNR,EAAMf,OAAOwB,UAAUT,GAEpBU,SAASV,EAAIW,QACf9D,YAAW,EACP+D,QAAQZ,EAAIa,cAAc,6BAM7BX,oBALIK,EAAW,uCACI,GAAhB3B,cAAqC,GAAhBC,eACvB0B,GAAU,SAAS3B,aAAa,SAASC,cAC1CiC,SAASC,KAAOR,KAIjB7C,cAAe,EACS,GAArBgD,SAASV,EAAIgB,OAA0B,IAAblD,UACJ,GAArB4C,SAASV,EAAIgB,OACfC,SAASC,OAAS,gDACnBrE,YAAW,EACXoC,OAAO,uBAAuBkC,OAC1BZ,EAAW,uCACI,GAAhB3B,cAAqC,GAAhBC,eACvB0B,GAAU,SAAS3B,aAAa,SAASC,cAC1CiC,SAASC,KAAOR,GACa,GAArBG,SAASV,EAAIgB,OACrBxC,qBAAuBwB,EAAIoB,QAC3B3C,kBAAoBuB,EAAIqB,KACxB3C,iBAAmBsB,EAAIsB,IACvB3C,aAAeJ,kBAAoBC,oBAAsBE,gBAErD8B,GADAA,EAAgB1D,OAAOkB,gBAAgBuD,mBACTvE,OAAOwB,oBAAqBC,iBAAkBC,iBAChD,EAA7BgC,SAASjC,oBACX+B,GAAiBxC,gBAAgBwD,0BAClCvC,OAAO,uBAAuBwC,KAAKjB,GACnCvB,OAAO,qBAAqBkC,QAExB5C,kBAAoBC,oBAAsBE,kBAC7CuC,SAASC,OAAS,kDAClBD,SAASC,OAAS,iDAClBJ,SAASC,KAAO,wCAEjBb,sBAIGS,MAAO,SAASe,EAAOC,EAAYC,GACxC3C,OAAO,qBAAqB4C,OAC5B5C,OAAO,yBAAyBwC,KAAKE,GACrC1C,OAAO,sBAAsBwC,KAAK,kBAClCrB,WAAWF,mBAAoB,MAE1B4B,QAAS,QAGjB,SAAS7B,eAER,GAAGpD,WAAW,CAEb,GAA2B,GAAxBc,qBAGF,OAFAsB,OAAO,sBAAsBwC,KAAK,uDAClCxC,OAAO,sBAAsB4C,OAM9B,IAEKrC,EALJP,OAAO,sBAAsBkC,OAG1B5C,oBAECiB,EAAO,CACVC,OAAU,qBACVC,SAAYpB,eAGVM,cAAgBC,eAClBW,EAAW,KAAIZ,aACfY,EAAW,KAAIX,cAGhBI,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAASC,GACjBA,EAAMf,OAAOwB,UAAUT,GACvBf,OAAO,uBAAuBwC,KAAKzB,EAAI+B,SACvCxD,kBAAsByB,EAAIgC,MAC1BvD,iBAAsBuB,EAAIqB,KAC1B7C,oBAAsBwB,EAAIoB,QAC1B1C,gBAAsBsB,EAAIsB,KAE3BX,MAAO,SAASe,EAAOC,EAAYC,GAClC3C,OAAO,qBAAqB4C,OAC5B5C,OAAO,yBAAyBwC,KAAKE,GACrC1C,OAAO,sBAAsBwC,KAAK,kBAClCrB,WAAWH,eAAgB,MAE5B6B,QAAS,SAOb,SAASG,mBAAmBC,EAAKC,GAE7BA,EAAYA,GAAa,KAE5B,IAAIC,EAAWnD,OAAOiD,EAAI1C,KAAK,aACtB0C,EAAI1C,KAAK,UAEJ2C,GAIbD,EAAI1C,KAAK,SAAS,GAClB4C,EAASC,KAAK,YAAY,GAC1BD,EAASE,WAAW,WACjBF,EAAS5C,KAAK,aAChByC,mBAAmBG,GAAU,KAP9BF,EAAI1C,KAAK,SAAS,GAClB4C,EAASE,WAAW,aAUtB,SAASC,cAAeC,GAEvB,IAAIhD,EAAO,CACVC,OAAU,kBACVC,SAAYpB,eAGbW,OAAO,IAAMuD,EAAEC,OAAOzD,IAAI0D,SAAS,YACnCzD,OAAO,YAAY0D,IAAI,aAAc,WACrC1D,OAAOU,KAAK,CACXC,KAAM,OACNC,IAAKC,QACLN,KAAMA,EACNO,QAAS,SAAUC,GACR,EAANA,GACHf,OAAO,4BAA4BwC,KAAKzB,GACxCuC,cAAeC,KAEfvD,OAAO,IAAMuD,EAAEC,OAAOzD,IAAI4D,YAAY,YACtC3D,OAAO,YAAY0D,IAAI,aAAc,UACrC7B,SAASC,KAAK,+CAGhBJ,MAAO,SAASe,EAAOC,EAAYC,GAClC3C,OAAO,qBAAqB4C,OAC5B5C,OAAO,yBAAyBwC,KAAKE,GACrC1C,OAAO,sBAAsBwC,KAAK,kBAClCrB,WAAWmC,cAAeC,GAAK,MAEhCV,QAAS,OAKX7C,OAAOgC,UAAU4B,MAAM,WAItB5D,OAAO,wBAAwBO,KAAK,CAAC4C,SAAY,WAAYU,OAAS,IAGnE/E,kBACFkB,OAAO,sBAAsBoD,KAAK,WAAW,GAE3CpE,eACFgB,OAAO,wBAAwBoD,KAAK,WAAW,GAAM7C,KAAK,SAAS,GACnEP,OAAO,uBAAuBqD,WAAW,YAAY/C,IAAItB,cACzDgB,OAAO,uBAAuBqD,WAAW,YAAY/C,IAAIrB,eAI1De,OAAO,4CAA4C8D,GAAG,SAAU,WAC/Dd,mBAAmBhD,OAAO/B,SAGxB+B,OAAO+D,WAAWC,YAAYhE,OAAO+D,WAAWE,SAAa,IAChE,IAAIC,EAAQlE,OAAO,4CAA4C+D,WAC9D,CACCI,WAAY,SACZC,QAAQ,MACRC,aAAY,EACZC,YAAW,EACXC,SAAU,YACVC,SAAU,SAASC,GACnB,IAAIC,EAAoB,sBAAXzG,KAAK8B,GAA6B,UAAY,UAC1D4E,EAAW3E,OAAQ/B,MAAOsC,KAAM,cAChCqE,EAAO5E,OAAO+D,WAAWc,UACxBF,EAASG,SAASX,YAAcnE,OAAO+D,WAAWgB,UAAUZ,WAC5DM,EAAcE,EAASG,UACxBZ,EAAMc,IAAI/G,MAAM8F,WAAW,SAAUW,EAAQE,MAKhD,SAASK,EAAeC,GAEjBA,EAAiBA,GAAkB,KAEtClF,OAAO,wBAAwBK,GAAG,cAEpCV,aAAeK,OAAO,uBAAuBM,MAC7CV,aAAeI,OAAO,uBAAuBM,MAExB,IAAhBX,cAAsC,IAAhBC,cAC1BuF,MAAM,kCAKLnF,OAAO,sBAAsBK,GAAG,cAClCzB,mBAAoB,GAGrBoB,OAAO,eAAekC,OACtBlC,OAAO,uBAAuB4C,OAC9B5C,OAAO,iBAAiB4C,OACxB5C,OAAO,aAAa4C,OAEpBhF,YAAW,EAERsH,GACFlE,eACAC,oBAEAf,qBAKFF,OAAO,yBAAyBoF,MAAM,WAErCH,IADAjD,SAASC,OAAS,mDAGnBjC,OAAO,4BAA4BoF,MAAM,WACxCH,GAAe,KAIhBjF,OAAO,aAAa8D,GAAG,QAAS,WAC/BjF,UAAW,EACX,IAAIwG,EAAW,CACdC,SAAY1G,kBACZuB,KAAYR,aACZS,KAAYR,cAEboC,SAASC,OAAS,wBAA0BsD,KAAKC,UAAUH,GAAY,2BAI3C,MAA1BtG,gBAAgB0G,QAClBzD,SAASC,OAAS,sCAAwC,IAAIyD,KAAK,GAAGC,cAAgB,yBACtF3F,OAAO,yBAAyBoF,SAIjCpF,OAAO,kBAAkBoF,MAAM,SAAU7B,GAExC,QAAK5B,QAAQ5C,gBAAgB6G,+BAG7BtC,cAAeC"}
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php CHANGED
@@ -1,182 +1,182 @@
1
- <?php
2
-
3
- namespace Cleantalk\ApbctWP\Firewall;
4
-
5
-
6
- use Cleantalk\Common\Helper as Helper;
7
- use Cleantalk\Variables\Cookie;
8
- use Cleantalk\Variables\Server;
9
-
10
- class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
11
-
12
- public $module_name = 'ANTICRAWLER';
13
-
14
- private $db__table__ac_logs;
15
- private $api_key = '';
16
- private $apbct = false;
17
- private $store_interval = 60;
18
-
19
- /**
20
- * AntiBot constructor.
21
- *
22
- * @param $log_table
23
- * @param $ac_logs_table
24
- * @param array $params
25
- */
26
- public function __construct( $log_table, $ac_logs_table, $params = array() ) {
27
-
28
- $this->db__table__logs = $log_table ?: null;
29
- $this->db__table__ac_logs = $ac_logs_table ?: null;
30
-
31
- foreach( $params as $param_name => $param ){
32
- $this->$param_name = isset( $this->$param_name ) ? $param : false;
33
- }
34
-
35
- }
36
-
37
- /**
38
- * Use this method to execute main logic of the module.
39
- *
40
- * @return array Array of the check results
41
- */
42
- public function check() {
43
-
44
- $results = array();
45
-
46
- foreach( $this->ip_array as $ip_origin => $current_ip ){
47
-
48
- // @todo Rename ip column to sign. Use IP + UserAgent for it.
49
-
50
- $result = $this->db->fetch(
51
- "SELECT ip"
52
- . ' FROM `' . $this->db__table__ac_logs . '`'
53
- . " WHERE ip = '$current_ip'"
54
- . " LIMIT 1;"
55
- );
56
-
57
- if( ! empty( $result ) && isset( $result['ip'] ) ){
58
-
59
- if( Cookie::get('apbct_antibot') !== md5( $this->api_key . $current_ip ) ){
60
-
61
- $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTICRAWLER', );
62
-
63
- }else{
64
-
65
- if( Cookie::get( 'apbct_anticrawler_passed' ) === '1' ){
66
-
67
- if( ! headers_sent() )
68
- \Cleantalk\Common\Helper::apbct_cookie__set( 'apbct_anticrawler_passed', '0', time() - 86400, '/', null, false, true, 'Lax' );
69
-
70
- $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTICRAWLER', );
71
-
72
- return $results;
73
- }
74
- }
75
-
76
- }else{
77
-
78
- $this->update_ac_log();
79
-
80
- add_action( 'wp_head', array( '\Cleantalk\ApbctWP\Firewall\AntiCrawler', 'set_cookie' ) );
81
- global $apbct_anticrawler_ip;
82
- $apbct_anticrawler_ip = $current_ip;
83
-
84
- }
85
- }
86
-
87
- return $results;
88
-
89
- }
90
-
91
- private function update_ac_log() {
92
-
93
- $interval_time = Helper::time__get_interval_start( $this->store_interval );
94
-
95
- // @todo Rename ip column to sign. Use IP + UserAgent for it.
96
-
97
- foreach( $this->ip_array as $ip_origin => $current_ip ){
98
- $id = md5( $current_ip . $interval_time );
99
- $this->db->execute(
100
- "INSERT INTO " . $this->db__table__ac_logs . " SET
101
- id = '$id',
102
- ip = '$current_ip',
103
- entries = 1,
104
- interval_start = $interval_time
105
- ON DUPLICATE KEY UPDATE
106
- ip = ip,
107
- entries = entries + 1,
108
- interval_start = $interval_time;"
109
- );
110
- }
111
-
112
- }
113
-
114
-
115
- public static function set_cookie(){
116
- global $apbct, $apbct_anticrawler_ip;
117
- echo '<script>document.cookie = "apbct_antibot=' . md5( $apbct->api_key . $apbct_anticrawler_ip ) . '; path=/; expires=0; samesite=lax";</script>';
118
- }
119
-
120
- /**
121
- * Add entry to SFW log.
122
- * Writes to database.
123
- *
124
- * @param string $ip
125
- * @param $status
126
- */
127
- public function update_log( $ip, $status ) {
128
-
129
- $id = md5( $ip );
130
- $time = time();
131
-
132
- $query = "INSERT INTO " . $this->db__table__logs . "
133
- SET
134
- id = '$id',
135
- ip = '$ip',
136
- status = '$status',
137
- all_entries = 1,
138
- blocked_entries = 1,
139
- entries_timestamp = '" . intval( $time ) . "'
140
- ON DUPLICATE KEY
141
- UPDATE
142
- status = '$status',
143
- all_entries = all_entries + 1,
144
- blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
145
- entries_timestamp = '" . intval( $time ) . "'";
146
-
147
- $this->db->execute( $query );
148
- }
149
-
150
- public function _die( $result ){
151
-
152
- // File exists?
153
- if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__AntiCrawler.html")){
154
-
155
- $sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__AntiCrawler.html");
156
-
157
- // Translation
158
- $replaces = array(
159
- '{SFW_DIE_NOTICE_IP}' => __('Anti-Crawler Protection is activated for your IP ', 'cleantalk-spam-protect'),
160
- '{SFW_DIE_MAKE_SURE_JS_ENABLED}' => __( 'To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect' ),
161
- '{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => sprintf( __( 'You will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect' ), 30 ),
162
- '{CLEANTALK_TITLE}' => __( 'Antispam by CleanTalk', 'cleantalk-spam-protect' ),
163
- '{REMOTE_ADDRESS}' => $result['ip'],
164
- '{SERVICE_ID}' => $this->apbct->data['service_id'],
165
- '{HOST}' => Server::get( 'HTTP_HOST' ),
166
- '{COOKIE_ANTICRAWLER}' => md5( $this->api_key . $result['ip'] ),
167
- '{COOKIE_ANTICRAWLER_PASSED}' => '1',
168
- '{GENERATED}' => '<p>The page was generated at&nbsp;' . date( 'D, d M Y H:i:s' ) . "</p>",
169
- );
170
-
171
- foreach( $replaces as $place_holder => $replace ){
172
- $sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
173
- }
174
-
175
- wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
176
-
177
- }else{
178
- wp_die("IP BLACKLISTED", "Blacklisted", Array('response'=>403));
179
- }
180
-
181
- }
182
  }
1
+ <?php
2
+
3
+ namespace Cleantalk\ApbctWP\Firewall;
4
+
5
+
6
+ use Cleantalk\Common\Helper as Helper;
7
+ use Cleantalk\Variables\Cookie;
8
+ use Cleantalk\Variables\Server;
9
+
10
+ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
11
+
12
+ public $module_name = 'ANTICRAWLER';
13
+
14
+ private $db__table__ac_logs;
15
+ private $api_key = '';
16
+ private $apbct = false;
17
+ private $store_interval = 60;
18
+
19
+ /**
20
+ * AntiBot constructor.
21
+ *
22
+ * @param $log_table
23
+ * @param $ac_logs_table
24
+ * @param array $params
25
+ */
26
+ public function __construct( $log_table, $ac_logs_table, $params = array() ) {
27
+
28
+ $this->db__table__logs = $log_table ?: null;
29
+ $this->db__table__ac_logs = $ac_logs_table ?: null;
30
+
31
+ foreach( $params as $param_name => $param ){
32
+ $this->$param_name = isset( $this->$param_name ) ? $param : false;
33
+ }
34
+
35
+ }
36
+
37
+ /**
38
+ * Use this method to execute main logic of the module.
39
+ *
40
+ * @return array Array of the check results
41
+ */
42
+ public function check() {
43
+
44
+ $results = array();
45
+
46
+ foreach( $this->ip_array as $ip_origin => $current_ip ){
47
+
48
+ // @todo Rename ip column to sign. Use IP + UserAgent for it.
49
+
50
+ $result = $this->db->fetch(
51
+ "SELECT ip"
52
+ . ' FROM `' . $this->db__table__ac_logs . '`'
53
+ . " WHERE ip = '$current_ip'"
54
+ . " LIMIT 1;"
55
+ );
56
+
57
+ if( ! empty( $result ) && isset( $result['ip'] ) ){
58
+
59
+ if( Cookie::get('apbct_antibot') !== md5( $this->api_key . $current_ip ) ){
60
+
61
+ $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTICRAWLER', );
62
+
63
+ }else{
64
+
65
+ if( Cookie::get( 'apbct_anticrawler_passed' ) === '1' ){
66
+
67
+ if( ! headers_sent() )
68
+ \Cleantalk\Common\Helper::apbct_cookie__set( 'apbct_anticrawler_passed', '0', time() - 86400, '/', null, false, true, 'Lax' );
69
+
70
+ $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTICRAWLER', );
71
+
72
+ return $results;
73
+ }
74
+ }
75
+
76
+ }else{
77
+
78
+ $this->update_ac_log();
79
+
80
+ add_action( 'wp_head', array( '\Cleantalk\ApbctWP\Firewall\AntiCrawler', 'set_cookie' ) );
81
+ global $apbct_anticrawler_ip;
82
+ $apbct_anticrawler_ip = $current_ip;
83
+
84
+ }
85
+ }
86
+
87
+ return $results;
88
+
89
+ }
90
+
91
+ private function update_ac_log() {
92
+
93
+ $interval_time = Helper::time__get_interval_start( $this->store_interval );
94
+
95
+ // @todo Rename ip column to sign. Use IP + UserAgent for it.
96
+
97
+ foreach( $this->ip_array as $ip_origin => $current_ip ){
98
+ $id = md5( $current_ip . $interval_time );
99
+ $this->db->execute(
100
+ "INSERT INTO " . $this->db__table__ac_logs . " SET
101
+ id = '$id',
102
+ ip = '$current_ip',
103
+ entries = 1,
104
+ interval_start = $interval_time
105
+ ON DUPLICATE KEY UPDATE
106
+ ip = ip,
107
+ entries = entries + 1,
108
+ interval_start = $interval_time;"
109
+ );
110
+ }
111
+
112
+ }
113
+
114
+
115
+ public static function set_cookie(){
116
+ global $apbct, $apbct_anticrawler_ip;
117
+ echo '<script>document.cookie = "apbct_antibot=' . md5( $apbct->api_key . $apbct_anticrawler_ip ) . '; path=/; expires=0; samesite=lax";</script>';
118
+ }
119
+
120
+ /**
121
+ * Add entry to SFW log.
122
+ * Writes to database.
123
+ *
124
+ * @param string $ip
125
+ * @param $status
126
+ */
127
+ public function update_log( $ip, $status ) {
128
+
129
+ $id = md5( $ip );
130
+ $time = time();
131
+
132
+ $query = "INSERT INTO " . $this->db__table__logs . "
133
+ SET
134
+ id = '$id',
135
+ ip = '$ip',
136
+ status = '$status',
137
+ all_entries = 1,
138
+ blocked_entries = 1,
139
+ entries_timestamp = '" . intval( $time ) . "'
140
+ ON DUPLICATE KEY
141
+ UPDATE
142
+ status = '$status',
143
+ all_entries = all_entries + 1,
144
+ blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
145
+ entries_timestamp = '" . intval( $time ) . "'";
146
+
147
+ $this->db->execute( $query );
148
+ }
149
+
150
+ public function _die( $result ){
151
+
152
+ // File exists?
153
+ if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__anticrawler.html")){
154
+
155
+ $sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__anticrawler.html");
156
+
157
+ // Translation
158
+ $replaces = array(
159
+ '{SFW_DIE_NOTICE_IP}' => __('Anti-Crawler Protection is activated for your IP ', 'cleantalk-spam-protect'),
160
+ '{SFW_DIE_MAKE_SURE_JS_ENABLED}' => __( 'To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect' ),
161
+ '{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => sprintf( __( 'You will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect' ), 30 ),
162
+ '{CLEANTALK_TITLE}' => __( 'Antispam by CleanTalk', 'cleantalk-spam-protect' ),
163
+ '{REMOTE_ADDRESS}' => $result['ip'],
164
+ '{SERVICE_ID}' => $this->apbct->data['service_id'],
165
+ '{HOST}' => Server::get( 'HTTP_HOST' ),
166
+ '{COOKIE_ANTICRAWLER}' => md5( $this->api_key . $result['ip'] ),
167
+ '{COOKIE_ANTICRAWLER_PASSED}' => '1',
168
+ '{GENERATED}' => '<p>The page was generated at&nbsp;' . date( 'D, d M Y H:i:s' ) . "</p>",
169
+ );
170
+
171
+ foreach( $replaces as $place_holder => $replace ){
172
+ $sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
173
+ }
174
+
175
+ wp_die($sfw_die_page, "Blacklisted", Array('response'=>403));
176
+
177
+ }else{
178
+ wp_die("IP BLACKLISTED", "Blacklisted", Array('response'=>403));
179
+ }
180
+
181
+ }
182
  }
lib/Cleantalk/ApbctWP/Firewall/AntiFlood.php CHANGED
@@ -1,191 +1,191 @@
1
- <?php
2
-
3
- namespace Cleantalk\ApbctWP\Firewall;
4
-
5
- use Cleantalk\Common\Helper as Helper;
6
- use Cleantalk\Variables\Cookie;
7
- use Cleantalk\Variables\Server;
8
-
9
- class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
10
-
11
- public $module_name = 'ANTIFLOOD';
12
-
13
- private $db__table__ac_logs;
14
-
15
- private $api_key = '';
16
- private $view_limit = 10;
17
- private $apbct = array();
18
- private $store_interval = 60;
19
- private $block_period = 30;
20
- private $chance_to_clean = 200;
21
-
22
- /**
23
- * AntiCrawler constructor.
24
- *
25
- * @param $log_table
26
- * @param $ac_logs_table
27
- * @param array $params
28
- */
29
- public function __construct( $log_table, $ac_logs_table, $params = array() ) {
30
-
31
- $this->db__table__logs = $log_table ?: null;
32
- $this->db__table__ac_logs = $ac_logs_table ?: null;
33
-
34
- foreach( $params as $param_name => $param ){
35
- $this->$param_name = isset( $this->$param_name ) ? $param : false;
36
- }
37
- }
38
-
39
- /**
40
- * Use this method to execute main logic of the module.
41
- * @return array
42
- */
43
- public function check() {
44
-
45
- $results = array();
46
-
47
- $this->clear_table();
48
-
49
- $time = time() - $this->store_interval;
50
-
51
- foreach( $this->ip_array as $ip_origin => $current_ip ){
52
-
53
- // Passed
54
- if( Cookie::get( 'apbct_antiflood_passed' ) === md5( $current_ip . $this->api_key ) ){
55
-
56
- if( ! headers_sent() ){
57
- \Cleantalk\Common\Helper::apbct_cookie__set( 'apbct_antiflood_passed', '0', time() - 86400, '/', null, false, true, 'Lax' );
58
- }
59
-
60
- $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTIFLOOD', );
61
-
62
- return $results;
63
- }
64
-
65
-
66
- // @todo Rename ip column to sign. Use IP + UserAgent for it.
67
-
68
- $result = $this->db->fetch_all(
69
- "SELECT SUM(entries) as total_count"
70
- . ' FROM `' . $this->db__table__ac_logs . '`'
71
- . " WHERE ip = '$current_ip' AND interval_start > '$time';"
72
- );
73
-
74
- if( ! empty( $result ) && isset( $result[0]['total_count'] ) && $result[0]['total_count'] >= $this->view_limit ){
75
- $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTIFLOOD', );
76
- }
77
- }
78
-
79
- if( ! empty( $results ) ){
80
- // Do block page
81
- return $results;
82
- } else{
83
- // Do logging entries
84
- $this->update_ac_log();
85
- }
86
-
87
- return $results;
88
-
89
- }
90
-
91
- private function update_ac_log() {
92
-
93
- $interval_time = Helper::time__get_interval_start( $this->store_interval );
94
-
95
- // @todo Rename ip column to sign. Use IP + UserAgent for it.
96
-
97
- foreach( $this->ip_array as $ip_origin => $current_ip ){
98
- $id = md5( $current_ip . $interval_time );
99
- $this->db->execute(
100
- "INSERT INTO " . $this->db__table__ac_logs . " SET
101
- id = '$id',
102
- ip = '$current_ip',
103
- entries = 1,
104
- interval_start = $interval_time
105
- ON DUPLICATE KEY UPDATE
106
- ip = ip,
107
- entries = entries + 1,
108
- interval_start = $interval_time;"
109
- );
110
- }
111
-
112
- }
113
-
114
- private function clear_table() {
115
-
116
- if( rand( 0, 1000 ) < $this->chance_to_clean ){
117
- $interval_start = \Cleantalk\ApbctWP\Helper::time__get_interval_start( $this->store_interval );
118
- $this->db->execute(
119
- 'DELETE
120
- FROM ' . $this->db__table__ac_logs . '
121
- WHERE interval_start < '. $interval_start .'
122
- LIMIT 100000;'
123
- );
124
- }
125
- }
126
-
127
- /**
128
- * Add entry to SFW log.
129
- * Writes to database.
130
- *
131
- * @param string $ip
132
- * @param $status
133
- */
134
- public function update_log( $ip, $status ) {
135
-
136
- $id = md5( $ip );
137
- $time = time();
138
-
139
- $query = "INSERT INTO " . $this->db__table__logs . "
140
- SET
141
- id = '$id',
142
- ip = '$ip',
143
- status = '$status',
144
- all_entries = 1,
145
- blocked_entries = 1,
146
- entries_timestamp = '" . intval( $time ) . "'
147
- ON DUPLICATE KEY
148
- UPDATE
149
- status = '$status',
150
- all_entries = all_entries + 1,
151
- blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
152
- entries_timestamp = '" . intval( $time ) . "'";
153
-
154
- $this->db->execute( $query );
155
- }
156
-
157
- public function _die( $result ) {
158
-
159
- parent::_die( $result );
160
-
161
- // File exists?
162
- if( file_exists( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page__AntiFlood.html' ) ){
163
-
164
- $sfw_die_page = file_get_contents( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page__AntiFlood.html' );
165
-
166
- // Translation
167
- $replaces = array(
168
- '{SFW_DIE_NOTICE_IP}' => __( 'Anti-Flood is activated for your IP', 'cleantalk-spam-protect' ),
169
- '{SFW_DIE_MAKE_SURE_JS_ENABLED}' => __( 'To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect' ),
170
- '{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => sprintf( __( 'You will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect' ), 30 ),
171
- '{CLEANTALK_TITLE}' => __( 'Antispam by CleanTalk', 'cleantalk-spam-protect' ),
172
- '{REMOTE_ADDRESS}' => $result['ip'],
173
- '{REQUEST_URI}' => Server::get( 'REQUEST_URI' ),
174
- '{SERVICE_ID}' => $this->apbct->data['service_id'],
175
- '{HOST}' => Server::get( 'HTTP_HOST' ),
176
- '{GENERATED}' => '<p>The page was generated at&nbsp;' . date( 'D, d M Y H:i:s' ) . "</p>",
177
- '{COOKIE_ANTIFLOOD_PASSED}' => md5( $this->api_key . $result['ip'] ),
178
- );
179
-
180
- foreach( $replaces as $place_holder => $replace ){
181
- $sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
182
- }
183
-
184
- wp_die( $sfw_die_page, 'Blacklisted', array( 'response' => 403 ) );
185
-
186
- } else{
187
- wp_die( 'IP BLACKLISTED', 'Blacklisted', array( 'response' => 403 ) );
188
- }
189
-
190
- }
191
  }
1
+ <?php
2
+
3
+ namespace Cleantalk\ApbctWP\Firewall;
4
+
5
+ use Cleantalk\Common\Helper as Helper;
6
+ use Cleantalk\Variables\Cookie;
7
+ use Cleantalk\Variables\Server;
8
+
9
+ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
10
+
11
+ public $module_name = 'ANTIFLOOD';
12
+
13
+ private $db__table__ac_logs;
14
+
15
+ private $api_key = '';
16
+ private $view_limit = 10;
17
+ private $apbct = array();
18
+ private $store_interval = 60;
19
+ private $block_period = 30;
20
+ private $chance_to_clean = 20;
21
+
22
+ /**
23
+ * AntiCrawler constructor.
24
+ *
25
+ * @param $log_table
26
+ * @param $ac_logs_table
27
+ * @param array $params
28
+ */
29
+ public function __construct( $log_table, $ac_logs_table, $params = array() ) {
30
+
31
+ $this->db__table__logs = $log_table ?: null;
32
+ $this->db__table__ac_logs = $ac_logs_table ?: null;
33
+
34
+ foreach( $params as $param_name => $param ){
35
+ $this->$param_name = isset( $this->$param_name ) ? $param : false;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Use this method to execute main logic of the module.
41
+ * @return array
42
+ */
43
+ public function check() {
44
+
45
+ $results = array();
46
+
47
+ $this->clear_table();
48
+
49
+ $time = time() - $this->store_interval;
50
+
51
+ foreach( $this->ip_array as $ip_origin => $current_ip ){
52
+
53
+ // Passed
54
+ if( Cookie::get( 'apbct_antiflood_passed' ) === md5( $current_ip . $this->api_key ) ){
55
+
56
+ if( ! headers_sent() ){
57
+ \Cleantalk\Common\Helper::apbct_cookie__set( 'apbct_antiflood_passed', '0', time() - 86400, '/', null, false, true, 'Lax' );
58
+ }
59
+
60
+ $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTIFLOOD', );
61
+
62
+ return $results;
63
+ }
64
+
65
+
66
+ // @todo Rename ip column to sign. Use IP + UserAgent for it.
67
+
68
+ $result = $this->db->fetch_all(
69
+ "SELECT SUM(entries) as total_count"
70
+ . ' FROM `' . $this->db__table__ac_logs . '`'
71
+ . " WHERE ip = '$current_ip' AND interval_start > '$time';"
72
+ );
73
+
74
+ if( ! empty( $result ) && isset( $result[0]['total_count'] ) && $result[0]['total_count'] >= $this->view_limit ){
75
+ $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTIFLOOD', );
76
+ }
77
+ }
78
+
79
+ if( ! empty( $results ) ){
80
+ // Do block page
81
+ return $results;
82
+ } else{
83
+ // Do logging entries
84
+ $this->update_ac_log();
85
+ }
86
+
87
+ return $results;
88
+
89
+ }
90
+
91
+ private function update_ac_log() {
92
+
93
+ $interval_time = Helper::time__get_interval_start( $this->store_interval );
94
+
95
+ // @todo Rename ip column to sign. Use IP + UserAgent for it.
96
+
97
+ foreach( $this->ip_array as $ip_origin => $current_ip ){
98
+ $id = md5( $current_ip . $interval_time );
99
+ $this->db->execute(
100
+ "INSERT INTO " . $this->db__table__ac_logs . " SET
101
+ id = '$id',
102
+ ip = '$current_ip',
103
+ entries = 1,
104
+ interval_start = $interval_time
105
+ ON DUPLICATE KEY UPDATE
106
+ ip = ip,
107
+ entries = entries + 1,
108
+ interval_start = $interval_time;"
109
+ );
110
+ }
111
+
112
+ }
113
+
114
+ public function clear_table() {
115
+
116
+ if( rand( 0, 100 ) < $this->chance_to_clean ){
117
+ $interval_start = \Cleantalk\ApbctWP\Helper::time__get_interval_start( $this->store_interval );
118
+ $this->db->execute(
119
+ 'DELETE
120
+ FROM ' . $this->db__table__ac_logs . '
121
+ WHERE interval_start < '. $interval_start .'
122
+ LIMIT 100000;'
123
+ );
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Add entry to SFW log.
129
+ * Writes to database.
130
+ *
131
+ * @param string $ip
132
+ * @param $status
133
+ */
134
+ public function update_log( $ip, $status ) {
135
+
136
+ $id = md5( $ip );
137
+ $time = time();
138
+
139
+ $query = "INSERT INTO " . $this->db__table__logs . "
140
+ SET
141
+ id = '$id',
142
+ ip = '$ip',
143
+ status = '$status',
144
+ all_entries = 1,
145
+ blocked_entries = 1,
146
+ entries_timestamp = '" . intval( $time ) . "'
147
+ ON DUPLICATE KEY
148
+ UPDATE
149
+ status = '$status',
150
+ all_entries = all_entries + 1,
151
+ blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
152
+ entries_timestamp = '" . intval( $time ) . "'";
153
+
154
+ $this->db->execute( $query );
155
+ }
156
+
157
+ public function _die( $result ) {
158
+
159
+ parent::_die( $result );
160
+
161
+ // File exists?
162
+ if( file_exists( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page__AntiFlood.html' ) ){
163
+
164
+ $sfw_die_page = file_get_contents( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page__AntiFlood.html' );
165
+
166
+ // Translation
167
+ $replaces = array(
168
+ '{SFW_DIE_NOTICE_IP}' => __( 'Anti-Flood is activated for your IP', 'cleantalk-spam-protect' ),
169
+ '{SFW_DIE_MAKE_SURE_JS_ENABLED}' => __( 'To continue working with web site, please make sure that you have enabled JavaScript.', 'cleantalk-spam-protect' ),
170
+ '{SFW_DIE_YOU_WILL_BE_REDIRECTED}' => sprintf( __( 'You will be automatically redirected to the requested page after %d seconds.', 'cleantalk-spam-protect' ), 30 ),
171
+ '{CLEANTALK_TITLE}' => __( 'Antispam by CleanTalk', 'cleantalk-spam-protect' ),
172
+ '{REMOTE_ADDRESS}' => $result['ip'],
173
+ '{REQUEST_URI}' => Server::get( 'REQUEST_URI' ),
174
+ '{SERVICE_ID}' => $this->apbct->data['service_id'],
175
+ '{HOST}' => Server::get( 'HTTP_HOST' ),
176
+ '{GENERATED}' => '<p>The page was generated at&nbsp;' . date( 'D, d M Y H:i:s' ) . "</p>",
177
+ '{COOKIE_ANTIFLOOD_PASSED}' => md5( $this->api_key . $result['ip'] ),
178
+ );
179
+
180
+ foreach( $replaces as $place_holder => $replace ){
181
+ $sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
182
+ }
183
+
184
+ wp_die( $sfw_die_page, 'Blacklisted', array( 'response' => 403 ) );
185
+
186
+ } else{
187
+ wp_die( 'IP BLACKLISTED', 'Blacklisted', array( 'response' => 403 ) );
188
+ }
189
+
190
+ }
191
  }
lib/Cleantalk/ApbctWP/Firewall/SFW.php CHANGED
@@ -74,28 +74,39 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
74
  public function check(){
75
 
76
  $results = array();
 
77
 
78
  // Skip by cookie
79
  foreach( $this->ip_array as $current_ip ){
80
-
81
- if( Cookie::get( 'ct_sfw_pass_key' ) == md5( $current_ip . $this->api_key ) ){
82
-
83
- if( Cookie::get( 'ct_sfw_passed' ) ){
84
-
85
- if( ! headers_sent() ){
86
- \Cleantalk\Common\Helper::apbct_cookie__set( 'ct_sfw_passed', '0', time() + 86400 * 3, '/', null, false, true, 'Lax' );
87
- }
88
-
89
- $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_SFW__BY_COOKIE', );
90
-
91
- if( $this->sfw_counter ){
92
- $this->apbct->data['sfw_counter']['all'] ++;
93
- $this->apbct->saveData();
94
- }
95
-
96
- }
 
 
 
 
 
 
 
 
 
 
97
 
98
- return $results;
99
  }
100
  }
101
 
@@ -180,8 +191,11 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
180
  }
181
 
182
  public function actions_for_passed( $result ){
183
- if( $this->set_cookies && ! headers_sent() )
184
- \Cleantalk\ApbctWP\Helper::apbct_cookie__set( 'ct_sfw_pass_key', md5( $result['ip'] . $this->api_key ), time() + 86400 * 30, '/', null, false );
 
 
 
185
  }
186
 
187
  /**
@@ -206,7 +220,10 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
206
  if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__SFW.html")){
207
 
208
  $sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__SFW.html");
209
-
 
 
 
210
  // Translation
211
  $replaces = array(
212
  '{SFW_DIE_NOTICE_IP}' => __('SpamFireWall is activated for your IP ', 'cleantalk-spam-protect'),
@@ -223,7 +240,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
223
  // Cookie
224
  '{COOKIE_PREFIX}' => '',
225
  '{COOKIE_DOMAIN}' => $this->cookie_domain,
226
- '{COOKIE_SFW}' => $this->test ? $this->test_ip : md5( $result['ip'] . $this->api_key ),
227
  '{COOKIE_ANTICRAWLER}' => md5( $this->api_key . $result['ip'] ),
228
 
229
  // Test
74
  public function check(){
75
 
76
  $results = array();
77
+ $status = 0;
78
 
79
  // Skip by cookie
80
  foreach( $this->ip_array as $current_ip ){
81
+
82
+ if( substr( Cookie::get( 'ct_sfw_pass_key' ), 0, 32 ) == md5( $current_ip . $this->api_key ) ){
83
+
84
+ if( Cookie::get( 'ct_sfw_passed' ) ){
85
+
86
+ if( ! headers_sent() ){
87
+ \Cleantalk\Common\Helper::apbct_cookie__set( 'ct_sfw_passed', '0', time() + 86400 * 3, '/', null, false, true, 'Lax' );
88
+ }
89
+
90
+ else {
91
+ $results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_SFW__BY_COOKIE', );
92
+ }
93
+
94
+ if( $this->sfw_counter ){
95
+ $this->apbct->data['sfw_counter']['all'] ++;
96
+ $this->apbct->saveData();
97
+ }
98
+
99
+ }
100
+
101
+ if( strlen( Cookie::get( 'ct_sfw_pass_key' ) ) > 32 ) {
102
+ $status = substr( Cookie::get( 'ct_sfw_pass_key' ), -1 );
103
+ }
104
+
105
+ if( $status ) {
106
+ $results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_SFW__BY_WHITELIST',);
107
+ }
108
 
109
+ return $results;
110
  }
111
  }
112
 
191
  }
192
 
193
  public function actions_for_passed( $result ){
194
+ if( $this->set_cookies && ! headers_sent() ) {
195
+ $status = $result['status'] == 'PASS_SFW__BY_WHITELIST' ? '1' : '0';
196
+ $cookie_val = md5( $result['ip'] . $this->api_key ) . $status;
197
+ \Cleantalk\ApbctWP\Helper::apbct_cookie__set( 'ct_sfw_pass_key', $cookie_val, time() + 86400 * 30, '/', null, false );
198
+ }
199
  }
200
 
201
  /**
220
  if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__SFW.html")){
221
 
222
  $sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page__SFW.html");
223
+
224
+ $status = $result['status'] == 'PASS_SFW__BY_WHITELIST' ? '1' : '0';
225
+ $cookie_val = md5( $result['ip'] . $this->api_key ) . $status;
226
+
227
  // Translation
228
  $replaces = array(
229
  '{SFW_DIE_NOTICE_IP}' => __('SpamFireWall is activated for your IP ', 'cleantalk-spam-protect'),
240
  // Cookie
241
  '{COOKIE_PREFIX}' => '',
242
  '{COOKIE_DOMAIN}' => $this->cookie_domain,
243
+ '{COOKIE_SFW}' => $this->test ? $this->test_ip : $cookie_val,
244
  '{COOKIE_ANTICRAWLER}' => md5( $this->api_key . $result['ip'] ),
245
 
246
  // Test
lib/Cleantalk/Common/Firewall.php CHANGED
@@ -1,199 +1,200 @@
1
- <?php
2
-
3
- namespace Cleantalk\Common;
4
-
5
- use Cleantalk\Common\Helper as Helper;
6
- use Cleantalk\Variables\Get;
7
-
8
- /**
9
- * CleanTalk SpamFireWall base class.
10
- * Compatible with any CMS.
11
- *
12
- * @depends \Cleantalk\Antispam\Helper class
13
- * @depends \Cleantalk\Antispam\API class
14
- * @depends \Cleantalk\Antispam\DB class
15
- *
16
- * @version 3.3
17
- * @author Cleantalk team (welcome@cleantalk.org)
18
- * @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
19
- * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
20
- * @see https://github.com/CleanTalk/php-antispam
21
- */
22
- class Firewall
23
- {
24
-
25
- public $ip_array = Array();
26
-
27
- // Database
28
- protected $db;
29
-
30
- //Debug
31
- public $debug;
32
- public $debug_data = '';
33
-
34
- private $statuses_priority = array(
35
- // Lowest
36
- 'PASS_SFW',
37
- 'DENY_SFW',
38
- 'PASS_SFW__BY_COOKIE',
39
- 'DENY_ANTIFLOOD',
40
- 'PASS_ANTIFLOOD',
41
- 'DENY_ANTICRAWLER',
42
- 'PASS_ANTICRAWLER',
43
- 'PASS_SFW__BY_WHITELIST',
44
- // Highest
45
- );
46
-
47
- private $fw_modules = array();
48
- private $module_names = array();
49
-
50
- /**
51
- * Creates Database driver instance.
52
- *
53
- * @param $db
54
- */
55
- public function __construct( $db ){
56
- $this->db = $db;
57
- $this->debug = !! Get::get( 'debug' );
58
- $this->ip_array = $this->ip__get( array('real'), true );
59
- }
60
-
61
- /**
62
- * Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)
63
- *
64
- * @param array $ips_input type of IP you want to receive
65
- * @param bool $v4_only
66
- *
67
- * @return array|mixed|null
68
- */
69
- public function ip__get( $ips_input = array( 'real', 'remote_addr', 'x_forwarded_for', 'x_real_ip', 'cloud_flare' ), $v4_only = true ){
70
-
71
- $result = Helper::ip__get( $ips_input, $v4_only );
72
-
73
- return ! empty( $result ) ? array( 'real' => $result ) : array();
74
-
75
- }
76
-
77
- /**
78
- * Loads the FireWall module to the array.
79
- * For inner usage only.
80
- * Not returns anything, the result is private storage of the modules.
81
- *
82
- * @param \Cleantalk\Common\Firewall\FirewallModule $module
83
- */
84
- public function load_fw_module( \Cleantalk\Common\Firewall\FirewallModule $module ) {
85
-
86
- if( ! in_array( $module, $this->fw_modules ) ) {
87
- $module->setDb( $this->db );
88
- $module->ip__append_additional( $this->ip_array );
89
- $this->fw_modules[ $module->module_name ] = $module;
90
- $module->setIpArray( $this->ip_array );
91
- }
92
-
93
- }
94
-
95
- /**
96
- * Do main logic of the module.
97
- *
98
- * @return void returns die page or set cookies
99
- */
100
- public function run() {
101
-
102
- $this->module_names = array_keys( $this->fw_modules );
103
-
104
- $results = array();
105
-
106
- foreach ( $this->fw_modules as $module ) {
107
-
108
- $module_results = $module->check();
109
- if( ! empty( $module_results ) ) {
110
- $results[] = $this->prioritize( $module_results );
111
- }
112
-
113
- if( $this->is_whitelisted( $results ) ) {
114
- // Break protection logic if it whitelisted or trusted network.
115
- break;
116
- }
117
-
118
- }
119
-
120
- $result = $this->prioritize( $results );
121
-
122
- // Blacklisted in DB
123
-
124
- foreach( $this->module_names as $module_name ){
125
-
126
- if( strpos( $result['status'], $module_name ) ){
127
-
128
- $this->fw_modules[ $module_name ]->update_log( $result['ip'], $result['status'] );
129
-
130
- // Blocked
131
- if( strpos( $result['status'], 'DENY' ) !== false ){
132
- $this->fw_modules[ $module_name ]->actions_for_denied( $result );
133
- $this->fw_modules[ $module_name ]->_die( $result );
134
-
135
- // Allowed
136
- }else{
137
- $this->fw_modules[ $module_name ]->actions_for_passed( $result );
138
- }
139
- }
140
-
141
- }
142
-
143
- }
144
-
145
- /**
146
- * Sets priorities for firewall results.
147
- * It generates one main result from multi-level results array.
148
- *
149
- * @param array $results
150
- *
151
- * @return array Single element array of result
152
- */
153
- private function prioritize( $results ){
154
-
155
- $current_fw_result_priority = 0;
156
- $result = array( 'status' => 'PASS', 'passed_ip' => '' );
157
-
158
- if( is_array( $results ) ) {
159
- foreach ( $results as $fw_result ) {
160
- $priority = array_search( $fw_result['status'], $this->statuses_priority ) + ( isset($fw_result['is_personal']) && $fw_result['is_personal'] ? count ( $this->statuses_priority ) : 0 );
161
- if( $priority >= $current_fw_result_priority ){
162
- $current_fw_result_priority = $priority;
163
- $result['status'] = $fw_result['status'];
164
- $result['passed_ip'] = isset( $fw_result['ip'] ) ? $fw_result['ip'] : $fw_result['passed_ip'];
165
- $result['blocked_ip'] = isset( $fw_result['ip'] ) ? $fw_result['ip'] : $fw_result['blocked_ip'];
166
- $result['pattern'] = isset( $fw_result['pattern'] ) ? $fw_result['pattern'] : array();
167
- }
168
- }
169
- }
170
-
171
- $result['ip'] = strpos( $result['status'], 'PASS' ) !== false ? $result['passed_ip'] : $result['blocked_ip'];
172
- $result['passed'] = strpos( $result['status'], 'PASS' ) !== false;
173
-
174
- return $result;
175
-
176
- }
177
-
178
- /**
179
- * Check the result if it whitelisted or trusted network
180
- *
181
- * @param array $results
182
- *
183
- * @return bool
184
- */
185
- private function is_whitelisted( $results ) {
186
-
187
- foreach ( $results as $fw_result ) {
188
- if (
189
- strpos( $fw_result['status'], 'PASS_BY_TRUSTED_NETWORK' ) !== false ||
190
- strpos( $fw_result['status'], 'PASS_BY_WHITELIST' ) !== false
191
- ) {
192
- return true;
193
- }
194
- }
195
- return false;
196
-
197
- }
198
-
199
- }
 
1
+ <?php
2
+
3
+ namespace Cleantalk\Common;
4
+
5
+ use Cleantalk\Common\Helper as Helper;
6
+ use Cleantalk\Variables\Get;
7
+
8
+ /**
9
+ * CleanTalk SpamFireWall base class.
10
+ * Compatible with any CMS.
11
+ *
12
+ * @depends \Cleantalk\Antispam\Helper class
13
+ * @depends \Cleantalk\Antispam\API class
14
+ * @depends \Cleantalk\Antispam\DB class
15
+ *
16
+ * @version 3.3
17
+ * @author Cleantalk team (welcome@cleantalk.org)
18
+ * @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
19
+ * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
20
+ * @see https://github.com/CleanTalk/php-antispam
21
+ */
22
+ class Firewall
23
+ {
24
+
25
+ public $ip_array = Array();
26
+
27
+ // Database
28
+ protected $db;
29
+
30
+ //Debug
31
+ public $debug;
32
+ public $debug_data = '';
33
+
34
+ private $statuses_priority = array(
35
+ // Lowest
36
+ 'PASS_SFW',
37
+ 'DENY_SFW',
38
+ 'PASS_SFW__BY_COOKIE',
39
+ 'DENY_ANTIFLOOD',
40
+ 'PASS_ANTIFLOOD',
41
+ 'DENY_ANTICRAWLER',
42
+ 'PASS_ANTICRAWLER',
43
+ 'PASS_SFW__BY_WHITELIST',
44
+ // Highest
45
+ );
46
+
47
+ private $fw_modules = array();
48
+ private $module_names = array();
49
+
50
+ /**
51
+ * Creates Database driver instance.
52
+ *
53
+ * @param $db
54
+ */
55
+ public function __construct( $db ){
56
+ $this->db = $db;
57
+ $this->debug = !! Get::get( 'debug' );
58
+ $this->ip_array = $this->ip__get( array('real'), true );
59
+ }
60
+
61
+ /**
62
+ * Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)
63
+ *
64
+ * @param array $ips_input type of IP you want to receive
65
+ * @param bool $v4_only
66
+ *
67
+ * @return array|mixed|null
68
+ */
69
+ public function ip__get( $ips_input = array( 'real', 'remote_addr', 'x_forwarded_for', 'x_real_ip', 'cloud_flare' ), $v4_only = true ){
70
+
71
+ $result = Helper::ip__get( $ips_input, $v4_only );
72
+
73
+ return ! empty( $result ) ? array( 'real' => $result ) : array();
74
+
75
+ }
76
+
77
+ /**
78
+ * Loads the FireWall module to the array.
79
+ * For inner usage only.
80
+ * Not returns anything, the result is private storage of the modules.
81
+ *
82
+ * @param \Cleantalk\Common\Firewall\FirewallModule $module
83
+ */
84
+ public function load_fw_module( \Cleantalk\Common\Firewall\FirewallModule $module ) {
85
+
86
+ if( ! in_array( $module, $this->fw_modules ) ) {
87
+ $module->setDb( $this->db );
88
+ $module->ip__append_additional( $this->ip_array );
89
+ $this->fw_modules[ $module->module_name ] = $module;
90
+ $module->setIpArray( $this->ip_array );
91
+ }
92
+
93
+ }
94
+
95
+ /**
96
+ * Do main logic of the module.
97
+ *
98
+ * @return void returns die page or set cookies
99
+ */
100
+ public function run() {
101
+
102
+ $this->module_names = array_keys( $this->fw_modules );
103
+
104
+ $results = array();
105
+
106
+ foreach ( $this->fw_modules as $module ) {
107
+
108
+ $module_results = $module->check();
109
+ if( ! empty( $module_results ) ) {
110
+ $results[] = $this->prioritize( $module_results );
111
+ }
112
+
113
+ if( $this->is_whitelisted( $results ) ) {
114
+ // Break protection logic if it whitelisted or trusted network.
115
+ break;
116
+ }
117
+
118
+ }
119
+
120
+ $result = $this->prioritize( $results );
121
+
122
+ // Blacklisted in DB
123
+
124
+ foreach( $this->module_names as $module_name ){
125
+
126
+ if( strpos( $result['status'], $module_name ) ){
127
+
128
+ $this->fw_modules[ $module_name ]->update_log( $result['ip'], $result['status'] );
129
+
130
+ // Blocked
131
+ if( strpos( $result['status'], 'DENY' ) !== false ){
132
+ $this->fw_modules[ $module_name ]->actions_for_denied( $result );
133
+ $this->fw_modules[ $module_name ]->_die( $result );
134
+
135
+ // Allowed
136
+ }else{
137
+ $this->fw_modules[ $module_name ]->actions_for_passed( $result );
138
+ }
139
+ }
140
+
141
+ }
142
+
143
+ }
144
+
145
+ /**
146
+ * Sets priorities for firewall results.
147
+ * It generates one main result from multi-level results array.
148
+ *
149
+ * @param array $results
150
+ *
151
+ * @return array Single element array of result
152
+ */
153
+ private function prioritize( $results ){
154
+
155
+ $current_fw_result_priority = 0;
156
+ $result = array( 'status' => 'PASS', 'passed_ip' => '' );
157
+
158
+ if( is_array( $results ) ) {
159
+ foreach ( $results as $fw_result ) {
160
+ $priority = array_search( $fw_result['status'], $this->statuses_priority ) + ( isset($fw_result['is_personal']) && $fw_result['is_personal'] ? count ( $this->statuses_priority ) : 0 );
161
+ if( $priority >= $current_fw_result_priority ){
162
+ $current_fw_result_priority = $priority;
163
+ $result['status'] = $fw_result['status'];
164
+ $result['passed_ip'] = isset( $fw_result['ip'] ) ? $fw_result['ip'] : $fw_result['passed_ip'];
165
+ $result['blocked_ip'] = isset( $fw_result['ip'] ) ? $fw_result['ip'] : $fw_result['blocked_ip'];
166
+ $result['pattern'] = isset( $fw_result['pattern'] ) ? $fw_result['pattern'] : array();
167
+ }
168
+ }
169
+ }
170
+
171
+ $result['ip'] = strpos( $result['status'], 'PASS' ) !== false ? $result['passed_ip'] : $result['blocked_ip'];
172
+ $result['passed'] = strpos( $result['status'], 'PASS' ) !== false;
173
+
174
+ return $result;
175
+
176
+ }
177
+
178
+ /**
179
+ * Check the result if it whitelisted or trusted network
180
+ *
181
+ * @param array $results
182
+ *
183
+ * @return bool
184
+ */
185
+ private function is_whitelisted( $results ) {
186
+
187
+ foreach ( $results as $fw_result ) {
188
+ if (
189
+ strpos( $fw_result['status'], 'PASS_BY_TRUSTED_NETWORK' ) !== false ||
190
+ strpos( $fw_result['status'], 'PASS_BY_WHITELIST' ) !== false ||
191
+ strpos( $fw_result['status'], 'PASS_SFW__BY_WHITELIST' ) !== false
192
+ ) {
193
+ return true;
194
+ }
195
+ }
196
+ return false;
197
+
198
+ }
199
+
200
+ }
lib/Cleantalk/Variables/ServerVariables.php CHANGED
@@ -1,84 +1,85 @@
1
- <?php
2
-
3
- namespace Cleantalk\Variables;
4
-
5
- /**
6
- * Class ServerVariables
7
- * Safety handler for ${_SOMETHING}
8
- *
9
- * @usage \Cleantalk\Variables\{SOMETHING}::get( $name );
10
- *
11
- * @package Cleantalk\Variables
12
- */
13
- class ServerVariables{
14
-
15
- static $instance;
16
- public $variables = [];
17
-
18
- public function __construct(){}
19
- public function __wakeup(){}
20
- public function __clone(){}
21
-
22
- /**
23
- * Constructor
24
- * @return $this
25
- */
26
- public static function getInstance(){
27
- if (!isset(static::$instance)) {
28
- static::$instance = new static;
29
- static::$instance->init();
30
- }
31
- return static::$instance;
32
- }
33
-
34
- /**
35
- * Alternative constructor
36
- */
37
- protected function init(){
38
-
39
- }
40
-
41
- /**
42
- * Gets variable from ${_SOMETHING}
43
- *
44
- * @param $name
45
- *
46
- * @return string ${_SOMETHING}[ $name ]
47
- */
48
- public static function get( $name ){
49
- return static::getInstance()->get_variable( $name );
50
- }
51
-
52
- /**
53
- * BLUEPRINT
54
- * Gets given ${_SOMETHING} variable and seva it to memory
55
- * @param $name
56
- *
57
- * @return mixed|string
58
- */
59
- protected function get_variable( $name ){
60
- return true;
61
- }
62
-
63
- /**
64
- * Save variable to $this->variables[]
65
- *
66
- * @param string $name
67
- * @param string $value
68
- */
69
- protected function remebmer_variable( $name, $value ){
70
- static::$instance->variables[$name] = $value;
71
- }
72
-
73
- /**
74
- * Checks if variable contains given string
75
- *
76
- * @param string $var Haystack to search in
77
- * @param string $string Needle to search
78
- *
79
- * @return bool|int
80
- */
81
- static function has_string( $var, $string ){
82
- return stripos( self::get( $var ), $string ) !== false;
83
- }
 
84
  }
1
+ <?php
2
+
3
+ namespace Cleantalk\Variables;
4
+
5
+ /**
6
+ * Class ServerVariables
7
+ * Safety handler for ${_SOMETHING}
8
+ *
9
+ * @usage \Cleantalk\Variables\{SOMETHING}::get( $name );
10
+ *
11
+ * @package Cleantalk\Variables
12
+ */
13
+ class ServerVariables{
14
+
15
+ static $instance;
16
+
17
+ public $variables = array();
18
+
19
+ public function __construct(){}
20
+ public function __wakeup(){}
21
+ public function __clone(){}
22
+
23
+ /**
24
+ * Constructor
25
+ * @return $this
26
+ */
27
+ public static function getInstance(){
28
+ if (!isset(static::$instance)) {
29
+ static::$instance = new static;
30
+ static::$instance->init();
31
+ }
32
+ return static::$instance;
33
+ }
34
+
35
+ /**
36
+ * Alternative constructor
37
+ */
38
+ protected function init(){
39
+
40
+ }
41
+
42
+ /**
43
+ * Gets variable from ${_SOMETHING}
44
+ *
45
+ * @param $name
46
+ *
47
+ * @return string ${_SOMETHING}[ $name ]
48
+ */
49
+ public static function get( $name ){
50
+ return static::getInstance()->get_variable( $name );
51
+ }
52
+
53
+ /**
54
+ * BLUEPRINT
55
+ * Gets given ${_SOMETHING} variable and seva it to memory
56
+ * @param $name
57
+ *
58
+ * @return mixed|string
59
+ */
60
+ protected function get_variable( $name ){
61
+ return true;
62
+ }
63
+
64
+ /**
65
+ * Save variable to $this->variables[]
66
+ *
67
+ * @param string $name
68
+ * @param string $value
69
+ */
70
+ protected function remebmer_variable( $name, $value ){
71
+ static::$instance->variables[$name] = $value;
72
+ }
73
+
74
+ /**
75
+ * Checks if variable contains given string
76
+ *
77
+ * @param string $var Haystack to search in
78
+ * @param string $string Needle to search
79
+ *
80
+ * @return bool|int
81
+ */
82
+ static function has_string( $var, $string ){
83
+ return stripos( self::get( $var ), $string ) !== false;
84
+ }
85
  }
lib/autoloader.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
-
3
- /**
4
- * Autoloader for \Cleantalk\* classes
5
- *
6
- * @param string $class
7
- *
8
- * @return void
9
- */
10
- spl_autoload_register( function( $class ){
11
-
12
- // Register class auto loader
13
- // Custom modules1
14
- if(strpos($class, 'Cleantalk') !== false){
15
- $class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
16
- $class_file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php';
17
- if(file_exists($class_file)){
18
- require_once($class_file);
19
- }
20
- }
21
- });
22
-
23
-
1
+ <?php
2
+
3
+ /**
4
+ * Autoloader for \Cleantalk\* classes
5
+ *
6
+ * @param string $class
7
+ *
8
+ * @return void
9
+ */
10
+ spl_autoload_register( function( $class ){
11
+
12
+ // Register class auto loader
13
+ // Custom modules1
14
+ if(strpos($class, 'Cleantalk') !== false){
15
+ $class = str_replace('\\', DIRECTORY_SEPARATOR, $class);
16
+ $class_file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php';
17
+ if(file_exists($class_file)){
18
+ require_once($class_file);
19
+ }
20
+ }
21
+ });
22
+
23
+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: spam, antispam, woocommerce, comments, firewall
4
  Requires at least: 3.0
5
  Tested up to: 5.5
6
  Requires PHP: 5.4
7
- Stable tag: 5.143.1
8
  License: GPLv2
9
 
10
  Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
@@ -579,6 +579,20 @@ If your website has forms that send data to external sources, you can enable opt
579
 
580
  == Changelog ==
581
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
  = 5.143.1 Aug 06 2020 =
583
  * Fix: Recursion fixed.
584
  * Fix: Rebuild url for SFW updating process.
4
  Requires at least: 3.0
5
  Tested up to: 5.5
6
  Requires PHP: 5.4
7
+ Stable tag: 5.144
8
  License: GPLv2
9
 
10
  Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
579
 
580
  == Changelog ==
581
 
582
+ = 5.144 Aug 13 2020 =
583
+ * Fix: WPMS setting updating fixed.
584
+ * Fix: Text domain added for some options name.
585
+ * Fix: AntiCrowler die page fixed.
586
+ * Fix: Pause button for comments check fixed.
587
+ * Fix: Delete Anti-Flood table when subsite is deleted.
588
+ * New: Clear Anti-Flood table each 10 minutes.
589
+ * Fix: FW checking for whitelisted skipped.
590
+ * Fix: WP 5.5 JS errors fixed.
591
+ * New: Debug message for auto updating error.
592
+ * Fix: Array declaration fixed.
593
+ * Fix: Skip anti-flood checking for authorized users.
594
+ * Fix: Is whitelisted checking fixed.
595
+
596
  = 5.143.1 Aug 06 2020 =
597
  * Fix: Recursion fixed.
598
  * Fix: Rebuild url for SFW updating process.