Spam protection, AntiSpam, FireWall by CleanTalk - Version 5.162

Version Description

Sep 23 2021 = * New. SFW. Fall back updating system implemented. * New: Integration. Added honeypot wc. * New: SFW. Added new status PASS_SFW_BY_STATUS for showing die_page. * Upd: Cookies. Alternative cookies types was updated. * Upd: Ajax. Finding the right WP directory implemented. * Fix: Updater fixed. * Fix: Firewall update. Not existing FW table. * Fix: State. DB prefix fixed. * Fix: WPForms. Excluding from the custom contact forms check. * Fix. State. DB prefix definition fixed. * Fix: SpamFirewall update. Increasing delay in queue transactions, adding time of the queue task start * Fix: State. Show notices fixed. * Fix: State. Some logic moved from a loop. * Fix: Adding a error if Common/Helper::http_request() couldn't get HTTP code via get_headers(). * Fix: SFW. Do not AC checking, if cookies were disabled. * Fix: http_request() with preset 'get_code' using GET HTTP method instead of HEAD now. * Fix: SFW. Direct update DB errors handled. * Fix: SFW. Direct update creating temp table errors handled. * Fix: SpamFirewall update. SFWIS_DISABLED is not a error. apbct_sfw_update_init() returns false in this case. * Fix: Extended header. Cache-Control: max-age=0 in the /Common/Helper::httpRequest() * Fix: Updater. Fixed data_use_static_js_key settings name. * Fix: Updater. start ct_account_status_check() if main site in 5.127+ versions * Fix: Adding error handling to DB::execute() in ApbctWP\SFW. * Fix: Cron. Cron last start flag improved. * Fix: Cron. Cron execution cooldown decreased to 2 min. * Fix: Adding more info in 'Unknown' type error. * Fix: Exclude Forminator double requests on multipage form. * Fix: Settings. Alt cookies types validating fixed. * Fix: Ajax. WP core dir parsing fixed. * Fix: Settings. Ajax handler title fixed.

Download this release

Release Info

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

Code changes from version 5.161.1 to 5.162

cleantalk.php CHANGED
@@ -1,9 +1,10 @@
1
  <?php
 
2
  /*
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.161.1
7
  Author: СleanTalk <welcome@cleantalk.org>
8
  Author URI: https://cleantalk.org
9
  Text Domain: cleantalk-spam-protect
@@ -15,7 +16,7 @@ use Cleantalk\ApbctWP\AdminNotices;
15
  use Cleantalk\ApbctWP\API;
16
  use Cleantalk\ApbctWP\CleantalkUpgrader;
17
  use Cleantalk\ApbctWP\CleantalkUpgraderSkin;
18
- use Cleantalk\ApbctWP\CleantalkUpgraderSkin_Deprecated;
19
  use Cleantalk\ApbctWP\Cron;
20
  use Cleantalk\ApbctWP\DB;
21
  use Cleantalk\ApbctWP\Deactivator;
@@ -38,31 +39,40 @@ global $apbct, $wpdb, $pagenow;
38
  $cleantalk_executed = false;
39
 
40
  // Getting version form main file (look above)
41
- $plugin_info = get_file_data(__FILE__, array('Version' => 'Version', 'Name' => 'Plugin Name',));
42
  $plugin_version__agent = $plugin_info['Version'];
43
  // Converts xxx.xxx.xx-dev to xxx.xxx.2xx
44
  // And xxx.xxx.xx-fix to xxx.xxx.1xx
45
- if( preg_match( '@^(\d+)\.(\d+)\.(\d{1,2})-(dev|fix)$@', $plugin_version__agent, $m ) ){
46
- $plugin_version__agent = $m[1] . '.' . $m[2] . '.' . ( $m[4] === 'dev' ? '2' : '1' ) . str_pad( $m[3], 2, '0', STR_PAD_LEFT );
 
 
 
 
 
 
47
  }
48
 
49
  // Common params
50
- define('APBCT_NAME', $plugin_info['Name']);
51
- define('APBCT_VERSION', $plugin_info['Version']);
52
- define('APBCT_URL_PATH', plugins_url('', __FILE__)); //HTTP path. Plugin root folder without '/'.
53
- define('APBCT_DIR_PATH', dirname(__FILE__ ) . '/'); //System path. Plugin root folder with '/'.
54
  define('APBCT_PLUGIN_BASE_NAME', plugin_basename(__FILE__)); //Plugin base name.
55
- define('APBCT_CASERT_PATH', file_exists(ABSPATH . WPINC . '/certificates/ca-bundle.crt') ? ABSPATH . WPINC . '/certificates/ca-bundle.crt' : ''); // SSL Serttificate path
 
 
 
56
 
57
  // API params
58
- define('APBCT_AGENT', 'wordpress-' . $plugin_version__agent );
59
  define('APBCT_MODERATE_URL', 'https://moderate.cleantalk.org'); //Api URL
60
 
61
  // Option names
62
- define('APBCT_DATA', 'cleantalk_data'); //Option name with different plugin data.
63
- define('APBCT_SETTINGS', 'cleantalk_settings'); //Option name with plugin settings.
64
  define('APBCT_NETWORK_SETTINGS', 'cleantalk_network_settings'); //Option name with plugin network settings.
65
- define('APBCT_DEBUG', 'cleantalk_debug'); //Option name with a debug data. Empty by default.
66
 
67
  // Multisite
68
  define('APBCT_WPMS', (is_multisite() ? true : false)); // WMPS is enabled
@@ -70,8 +80,8 @@ define('APBCT_WPMS', (is_multisite() ? true : false)); // WMPS is enabled
70
  // Different params
71
  define('APBCT_REMOTE_CALL_SLEEP', 5); // Minimum time between remote call
72
 
73
- if( ! defined( 'CLEANTALK_PLUGIN_DIR' ) ){
74
- define('CLEANTALK_PLUGIN_DIR', dirname(__FILE__ ) . '/');
75
  }
76
 
77
  // PHP functions patches
@@ -88,7 +98,7 @@ $apbct = new State('cleantalk', array('settings', 'data', 'debug', 'errors', 're
88
 
89
  $apbct->base_name = 'cleantalk-spam-protect/cleantalk.php';
90
 
91
- $apbct->plugin_request_id = md5( microtime() ); // Identify plugin execution
92
 
93
  $apbct->logo = plugin_dir_url(__FILE__) . 'inc/images/logo.png';
94
  $apbct->logo__small = plugin_dir_url(__FILE__) . 'inc/images/logo_small.png';
@@ -100,477 +110,580 @@ $apbct->logo__small__colored = plugin_dir_url(__FILE__) . 'inc/images/logo_color
100
  $apbct->white_label = $apbct->network_settings['multisite__white_label'];
101
  $apbct->allow_custom_key = $apbct->network_settings['multisite__work_mode'] != 2;
102
  $apbct->plugin_name = $apbct->network_settings['multisite__white_label__plugin_name'] ? $apbct->network_settings['multisite__white_label__plugin_name'] : APBCT_NAME;
103
- $apbct->api_key = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->settings['apikey'] : $apbct->network_settings['apikey'];
104
- $apbct->key_is_ok = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['key_is_ok'] : $apbct->network_data['key_is_ok'];
105
- $apbct->moderate = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['moderate'] : $apbct->network_data['moderate'];
106
 
107
- $apbct->data['user_counter']['since'] = isset($apbct->data['user_counter']['since']) ? $apbct->data['user_counter']['since'] : date('d M');
108
- $apbct->data['connection_reports']['since'] = isset($apbct->data['connection_reports']['since']) ? $apbct->data['user_counter']['since'] : date('d M');
 
 
 
 
109
 
110
- $apbct->firewall_updating = (bool) $apbct->fw_stats['firewall_updating_id'];
111
 
112
  $apbct->settings_link = is_network_admin() ? 'settings.php?page=cleantalk' : 'options-general.php?page=cleantalk';
113
 
114
- if(!$apbct->white_label){
115
- require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
116
  }
117
 
118
  // Disabling comments
119
- if($apbct->settings['comments__disable_comments__all'] || $apbct->settings['comments__disable_comments__posts'] || $apbct->settings['comments__disable_comments__pages'] || $apbct->settings['comments__disable_comments__media']){
120
- \Cleantalk\Antispam\DisableComments::getInstance();
121
  }
122
 
123
- add_action( 'rest_api_init', 'apbct_register_my_rest_routes' );
124
- function apbct_register_my_rest_routes() {
125
- $controller = new RestController();
126
- $controller->register_routes();
 
 
 
 
 
 
 
 
 
127
  }
128
 
129
  // Database prefix
130
  global $wpdb;
131
- $apbct->db_prefix = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $wpdb->prefix : $wpdb->base_prefix;
132
- $apbct->db_prefix = !$apbct->white_label && defined('CLEANTALK_ACCESS_KEY') ? $wpdb->base_prefix : $wpdb->prefix;
133
 
134
  // Set some defines
135
  State::setDefinitions();
136
 
137
  /** @todo HARDCODE FIX */
138
- if($apbct->plugin_version === '1.0.0')
139
- $apbct->plugin_version = '5.100';
 
140
 
141
  // Do update actions if version is changed
142
  apbct_update_actions();
143
 
144
- // Self cron
145
- $ct_cron = new Cron();
146
- $tasks_to_run = $ct_cron->checkTasks(); // Check for current tasks. Drop tasks inner counters.
147
- if(
148
- $tasks_to_run && // There is tasks to run
149
- ! RemoteCalls::check() && // Do not do CRON in remote call action
150
- (
151
- ! defined( 'DOING_CRON' ) ||
152
- ( defined( 'DOING_CRON' ) && DOING_CRON !== true )
153
- )
154
- ){
155
- $cron_res = $ct_cron->runTasks( $tasks_to_run );
156
- if( is_array( $cron_res ) ) {
157
- foreach( $cron_res as $task => $res ) {
158
- if( $res === true ) {
159
- $apbct->error_delete( $task, 'save_data', 'cron' );
160
- } else {
161
- $apbct->error_add( $task, $res, 'cron' );
162
- }
163
- }
 
 
 
164
  }
165
- }
166
 
167
  //Delete cookie for admin trial notice
168
  add_action('wp_logout', 'apbct__hook__wp_logout__delete_trial_notice_cookie');
169
 
170
  // Set cookie only for public pages and for non-AJAX requests
171
- if (!is_admin() && !apbct_is_ajax() && !defined('DOING_CRON')
172
- && empty($_POST['ct_checkjs_register_form']) // Buddy press registration fix
173
- && empty($_GET['ct_checkjs_search_default']) // Search form fix
174
- && empty($_POST['action']) //bbPress
175
- ){
176
- add_action('template_redirect','apbct_cookie', 2);
177
- add_action('template_redirect','apbct_store__urls', 2);
178
- if (empty($_POST) && empty($_GET)){
179
- apbct_cookie();
180
- apbct_store__urls();
181
- }
182
  }
183
 
184
  // Early checks
185
 
186
  // Iphorm
187
- if( isset( $_POST['iphorm_ajax'], $_POST['iphorm_id'], $_POST['iphorm_uid'] ) ){
188
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
189
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
190
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
191
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
192
- ct_ajax_hook();
193
  }
194
 
195
  // Facebook
196
- if ($apbct->settings['forms__general_contact_forms_test'] == 1
197
- && (!empty($_POST['action']) && $_POST['action'] === 'fb_intialize')
198
- && !empty($_POST['FB_userdata'])
199
- ){
200
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
201
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
202
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
203
- if (apbct_is_user_enable()){
204
- ct_registration_errors(null);
205
- }
206
-
207
  }
208
 
209
  $apbct_active_integrations = array(
210
- 'ContactBank' => array( 'hook' => 'contact_bank_frontend_ajax_call', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
211
- 'FluentForm' => array( 'hook' => 'fluentform_before_insert_submission', 'setting' => 'forms__contact_forms_test', 'ajax' => false ),
212
- 'ElfsightContactForm' => array( 'hook' => 'elfsight_contact_form_mail', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
213
- 'EstimationForm' => array( 'hook' => 'send_email', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
214
- 'LandingPageBuilder' => array( 'hook' => 'ulpb_formBuilderEmail_ajax', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
215
- 'Rafflepress' => array( 'hook' => 'rafflepress_lite_giveaway_api', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
216
- 'SimpleMembership' => array( 'hook' => 'swpm_front_end_registration_complete_user_data', 'setting' => 'forms__registrations_test', 'ajax' => false ),
217
- 'WpMembers' => array( 'hook' => 'wpmem_pre_register_data', 'setting' => 'forms__registrations_test', 'ajax' => false ),
218
- 'Wpdiscuz' => array( 'hook' => array( 'wpdAddComment', 'wpdAddInlineComment' ), 'setting' => 'forms__comments_test', 'ajax' => true ),
219
- 'Forminator' => array( 'hook' => 'forminator_submit_form_custom-forms', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
220
- 'HappyForm' => array( 'hook' => 'happyforms_validate_submission', 'setting' => 'forms__contact_forms_test', 'ajax' => false ),
221
- 'EaelLoginRegister' => array( 'hook' => array ('eael/login-register/before-register', 'wp_ajax_nopriv_eael/login-register/before-register' , 'wp_ajax_eael/login-register/before-register'), 'setting' => 'forms__registrations_test', 'ajax' => false ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  );
223
- new \Cleantalk\Antispam\Integrations( $apbct_active_integrations, (array) $apbct->settings );
224
 
225
  // Ninja Forms. Making GET action to POST action
226
- if( apbct_is_in_uri( 'admin-ajax.php' ) && sizeof($_POST) > 0 && isset($_GET['action']) && $_GET['action']=='ninja_forms_ajax_submit' )
227
- $_POST['action']='ninja_forms_ajax_submit';
 
 
 
 
 
 
228
 
229
- add_action( 'wp_ajax_nopriv_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
230
- add_action( 'wp_ajax_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
231
- add_action( 'wp_ajax_nopriv_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
232
- add_action( 'wp_ajax_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
233
- add_action( 'ninja_forms_process', 'apbct_form__ninjaForms__testSpam', 1); // Depricated ?
234
 
235
  // SeedProd Coming Soon Page Pro integration
236
- add_action( 'wp_ajax_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
237
- add_action( 'wp_ajax_nopriv_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
238
- add_action( 'wp_ajax_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
239
- add_action( 'wp_ajax_nopriv_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
240
 
241
  // The 7 theme contact form integration
242
- add_action( 'wp_ajax_nopriv_dt_send_mail', 'apbct_form__the7_contact_form', 1 );
243
- add_action( 'wp_ajax_dt_send_mail', 'apbct_form__the7_contact_form', 1 );
244
 
245
  // Elementor Pro page builder forms
246
- add_action( 'wp_ajax_elementor_pro_forms_send_form', 'apbct_form__elementor_pro__testSpam' );
247
- add_action( 'wp_ajax_nopriv_elementor_pro_forms_send_form', 'apbct_form__elementor_pro__testSpam' );
248
 
249
  // Custom register form (ticket_id=13668)
250
- add_action('website_neotrends_signup_fields_check',function( $username, $fields ){
251
- $ip = Helper::ip__get( 'real', false );
252
- $ct_result = ct_test_registration( $username, $fields['email'], $ip );
253
- if( $ct_result['allow'] == 0 ) {
254
- ct_die_extended( $ct_result['comment'] );
255
  }
256
  }, 1, 2);
257
 
258
  // INEVIO theme integration
259
- add_action( 'wp_ajax_contact_form_handler', 'apbct_form__inevio__testSpam', 1 );
260
- add_action( 'wp_ajax_nopriv_contact_form_handler', 'apbct_form__inevio__testSpam', 1 );
261
 
262
  // Enfold Theme contact form
263
- add_filter( 'avf_form_send', 'apbct_form__enfold_contact_form__test_spam', 4, 10 );
264
 
265
  // Profile Builder integration
266
- add_filter( 'wppb_output_field_errors_filter', 'apbct_form_profile_builder__check_register', 1, 3 );
267
 
268
  // WP Foro register system integration
269
- add_filter( 'wpforo_create_profile', 'wpforo_create_profile__check_register', 1, 1 );
270
 
271
  // Public actions
272
- if( ! is_admin() && ! apbct_is_ajax() && ! apbct_is_customize_preview() ){
273
-
274
- // Default search
275
- //add_filter( 'get_search_form', 'apbct_forms__search__addField' );
276
- add_filter( 'get_search_query', 'apbct_forms__search__testSpam' );
277
- add_action( 'wp_head', 'apbct_search_add_noindex', 1 );
278
-
279
- // Remote calls
280
- if( RemoteCalls::check() )
281
  RemoteCalls::perform();
282
-
283
- // SpamFireWall check
284
- if( $apbct->plugin_version == APBCT_VERSION && // Do not call with first start
285
- $apbct->settings['sfw__enabled'] == 1 &&
286
- apbct_is_get() &&
287
- ! apbct_wp_doing_cron() &&
288
- ! \Cleantalk\Variables\Server::in_uri( '/favicon.ico' ) &&
289
- ! apbct_is_cli()
290
- ){
291
- wp_suspend_cache_addition( true );
292
- apbct_sfw__check();
293
- wp_suspend_cache_addition( false );
294
  }
295
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  }
297
 
298
  // Activation/deactivation functions must be in main plugin file.
299
  // http://codex.wordpress.org/Function_Reference/register_activation_hook
300
- register_activation_hook( __FILE__, 'apbct_activation' );
301
- function apbct_activation( $network_wide ) {
302
- Activator::activation( $network_wide );
 
303
  }
304
- register_deactivation_hook( __FILE__, 'apbct_deactivation' );
305
- function apbct_deactivation( $network_wide ) {
306
- Deactivator::deactivation( $network_wide );
 
 
307
  }
 
308
  // Hook for newly added blog
309
  add_action('wpmu_new_blog', 'apbct_activation__new_blog', 10, 6);
310
- function apbct_activation__new_blog( $blog_id, $_user_id, $_domain, $_path, $_site_id, $_meta ) {
311
- Activator::activation( false, $blog_id );
 
312
  }
313
 
314
  // Async loading for JavaScript
315
  add_filter('script_loader_tag', 'apbct_add_async_attribute', 10, 3);
316
 
317
  // Redirect admin to plugin settings.
318
- if( ! defined('WP_ALLOW_MULTISITE') || ( defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == false ) )
319
  add_action('admin_init', 'apbct_plugin_redirect');
 
320
 
321
  // Deleting SFW tables when deleting websites
322
- if(defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE === true)
323
- add_action( 'delete_blog', 'apbct_sfw__delete_tables', 10, 2 );
 
324
 
325
  // After plugin loaded - to load locale as described in manual
326
- add_action('plugins_loaded', 'apbct_plugin_loaded' );
327
 
328
- if( !empty($apbct->settings['data__use_ajax']) &&
329
- ! apbct_is_in_uri( '.xml' ) &&
330
- ! apbct_is_in_uri( '.xsl' ) )
331
- {
332
- add_action( 'wp_ajax_nopriv_ct_get_cookie', 'ct_get_cookie',1 );
333
- add_action( 'wp_ajax_ct_get_cookie', 'ct_get_cookie',1 );
334
  }
335
 
336
  // Admin panel actions
337
- if (is_admin() || is_network_admin()){
338
-
339
- require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-find-spam.php' );
340
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-admin.php');
341
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-settings.php');
342
 
343
- add_action( 'admin_init', 'apbct_admin__init', 1 );
344
 
345
  // Show notices
346
- add_action( 'admin_init', array( AdminNotices::class, 'show_admin_notices' ) );
347
-
348
- if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)){
349
-
350
- add_action('admin_enqueue_scripts', 'apbct_admin__enqueue_scripts');
351
-
352
- add_action('admin_menu', 'apbct_settings_add_page');
353
- add_action('network_admin_menu', 'apbct_settings_add_page');
354
-
355
- //Show widget only if enables and not IP license
356
- if( $apbct->settings['wp__dashboard_widget__show'] && ! $apbct->moderate_ip )
357
- add_action('wp_dashboard_setup', 'ct_dashboard_statistics_widget' );
358
- }
359
-
360
- if(apbct_is_ajax() || isset($_POST['cma-action'])){
361
-
362
- $_cleantalk_hooked_actions = array();
363
- $_cleantalk_ajax_actions_to_check = array();
364
-
365
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
366
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
367
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
368
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
369
-
370
- // Feedback for comments
371
- if(isset($_POST['action']) && $_POST['action'] == 'ct_feedback_comment'){
372
- add_action( 'wp_ajax_nopriv_ct_feedback_comment', 'apbct_comment__send_feedback',1 );
373
- add_action( 'wp_ajax_ct_feedback_comment', 'apbct_comment__send_feedback',1 );
374
- }
375
- if(isset($_POST['action']) && $_POST['action'] == 'ct_feedback_user'){
376
- add_action( 'wp_ajax_nopriv_ct_feedback_user', 'apbct_user__send_feedback',1 );
377
- add_action( 'wp_ajax_ct_feedback_user', 'apbct_user__send_feedback',1 );
378
- }
379
-
380
- // Check AJAX requests
381
- // if User is not logged in
382
- // if Unknown action or Known action with mandatory check
383
- if( ( ! apbct_is_user_logged_in() || $apbct->settings['data__protect_logged_in'] == 1) &&
384
- isset( $_POST['action'] ) &&
385
- ( ! in_array( $_POST['action'], $_cleantalk_hooked_actions ) || in_array( $_POST['action'], $_cleantalk_ajax_actions_to_check ) ) &&
386
- ! array_search( $_POST['action'], array_column( $apbct_active_integrations, 'hook' ) )
387
- ){
388
- ct_ajax_hook();
389
- }
390
-
391
- //QAEngine Theme answers
392
- if (intval($apbct->settings['forms__general_contact_forms_test']))
393
- add_filter('et_pre_insert_question', 'ct_ajax_hook', 1, 1); // Questions
394
- add_filter('et_pre_insert_answer', 'ct_ajax_hook', 1, 1); // Answers
395
-
396
- // Formidable
397
- add_filter( 'frm_entries_before_create', 'apbct_form__formidable__testSpam', 10, 2 );
398
- add_action( 'frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2 );
399
 
400
- // Some of plugins to register a users use AJAX context.
401
- add_filter('registration_errors', 'ct_registration_errors', 1, 3);
402
- add_filter('registration_errors', 'ct_check_registration_erros', 999999, 3);
403
- add_action('user_register', 'apbct_user_register');
404
 
405
- if(class_exists('BuddyPress')){
406
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
407
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
408
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
409
- add_filter('bp_activity_is_spam_before_save', 'apbct_integration__buddyPres__activityWall', 999 ,2); /* ActivityWall */
410
- add_action('bp_locate_template', 'apbct_integration__buddyPres__getTemplateName', 10, 6);
411
- }
412
 
413
- }
 
 
 
 
414
 
415
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
416
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
417
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
418
- //Bitrix24 contact form
419
- if ($apbct->settings['forms__general_contact_forms_test'] == 1 &&
420
- !empty($_POST['your-phone']) &&
421
- !empty($_POST['your-email']) &&
422
- !empty($_POST['your-message'])
423
- ){
424
- ct_contact_form_validate();
425
- }
426
 
427
- // Sends feedback to the cloud about comments
428
- // add_action('wp_set_comment_status', 'ct_comment_send_feedback', 10, 2);
 
 
429
 
430
- // Sends feedback to the cloud about deleted users
431
- if( $pagenow === 'users.php') {
432
- add_action( 'delete_user', 'apbct_user__delete__hook', 10, 2 );
433
- }
 
 
 
 
 
434
 
435
- if( $pagenow === 'plugins.php' || apbct_is_in_uri( 'plugins.php' ) ){
 
 
 
 
 
 
 
 
 
 
 
 
 
436
 
437
- add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'apbct_admin__plugin_action_links', 10, 2);
438
- add_filter('network_admin_plugin_action_links_'.plugin_basename(__FILE__), 'apbct_admin__plugin_action_links', 10, 2);
 
 
 
439
 
440
- add_filter('plugin_row_meta', 'apbct_admin__register_plugin_links', 10, 2);
441
- }
 
442
 
443
- // Public pages actions
444
- }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
 
446
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
447
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
448
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
 
 
 
 
 
 
 
 
449
 
450
- add_action('wp_enqueue_scripts', 'ct_enqueue_scripts_public');
 
451
 
452
- // Init action.
453
- add_action('plugins_loaded', 'apbct_init', 1);
 
 
454
 
455
- // Comments
456
- add_filter('preprocess_comment', 'ct_preprocess_comment', 1, 1); // param - comment data array
457
- add_filter('comment_text', 'ct_comment_text' );
458
- add_filter('wp_die_handler', 'apbct_comment__sanitize_data__before_wp_die', 1); // Check comments after validation
 
 
 
 
459
 
460
- // Registrations
461
- if(!isset($_POST['wp-submit'])){
462
- add_action('login_form_register', 'apbct_cookie');
463
- add_action('login_form_register', 'apbct_store__urls');
464
  }
465
- add_action('login_enqueue_scripts', 'apbct_login__scripts');
466
- add_action('register_form', 'ct_register_form');
467
- add_filter('registration_errors', 'ct_registration_errors', 1, 3);
468
- add_filter('registration_errors', 'ct_check_registration_erros', 999999, 3);
469
- add_action('user_register', 'apbct_user_register');
470
 
471
- // Multisite registrations
472
- add_action('signup_extra_fields','ct_register_form');
473
- add_filter('wpmu_validate_user_signup', 'ct_registration_errors_wpmu', 10, 3);
474
 
475
- // Login form - for notifications only
476
- add_filter('login_message', 'ct_login_message');
477
 
478
- // Comments output hook
479
- add_filter('wp_list_comments_args', 'ct_wp_list_comments_args');
 
 
480
 
481
- // Ait-Themes fix
482
- if(isset($_GET['ait-action']) && $_GET['ait-action'] === 'register'){
483
- $tmp=$_POST['redirect_to'];
484
- unset($_POST['redirect_to']);
485
- ct_contact_form_validate();
486
- $_POST['redirect_to']=$tmp;
487
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  }
489
 
490
  // Short code for GDPR
491
- if($apbct->settings['gdpr__enabled'])
492
- add_shortcode('cleantalk_gdpr_form', 'apbct_shrotcode_handler__GDPR_public_notice__form');
 
493
 
494
  /**
495
- * Function for SpamFireWall check
496
- */
497
  function apbct_sfw__check()
498
  {
499
- global $apbct, $spbc, $cleantalk_url_exclusions;
500
-
501
- // Turn off the SpamFireWall if current url in the exceptions list and WordPress core pages
502
- if (!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)) {
503
- $core_page_to_skip_check = array('/feed');
504
- foreach (array_merge($cleantalk_url_exclusions, $core_page_to_skip_check) as $v) {
505
- if ( apbct_is_in_uri( $v ) ) {
506
- return;
507
- }
508
- }
509
- }
510
-
511
- // Skip the check
512
- if(!empty($_GET['access'])){
513
- $spbc_settings = get_option('spbc_settings');
514
- $spbc_key = !empty($spbc_settings['spbc_key']) ? $spbc_settings['spbc_key'] : false;
515
- if($_GET['access'] === $apbct->api_key || ($spbc_key !== false && $_GET['access'] === $spbc_key)){
516
- \Cleantalk\Variables\Cookie::set('spbc_firewall_pass_key', md5(apbct_get_server_variable( 'REMOTE_ADDR' ) . $spbc_key), time()+1200, '/', '');
517
- \Cleantalk\Variables\Cookie::set('ct_sfw_pass_key', md5(apbct_get_server_variable( 'REMOTE_ADDR' ) . $apbct->api_key), time()+1200, '/', '');
518
- return;
519
- }
520
- unset($spbc_settings, $spbc_key);
521
- }
522
-
523
- // Turn off the SpamFireWall if Remote Call is in progress
524
- if($apbct->rc_running || (!empty($spbc) && $spbc->rc_running)) {
525
- return;
526
- }
527
-
528
- // update mode - skip checking
529
- if(isset($apbct->fw_stats['update_mode']) && $apbct->fw_stats['update_mode'] === 1) {
 
 
 
 
 
 
 
 
530
  return;
531
  }
532
 
533
- $firewall = new Firewall(
534
- DB::getInstance()
535
- );
536
-
537
- $firewall->load_fw_module( new SFW(
538
- APBCT_TBL_FIREWALL_LOG,
539
- APBCT_TBL_FIREWALL_DATA,
540
- array(
541
- 'sfw_counter' => $apbct->settings['admin_bar__sfw_counter'],
542
- 'api_key' => $apbct->api_key,
543
- 'apbct' => $apbct,
544
- 'cookie_domain' => parse_url( get_option( 'siteurl' ), PHP_URL_HOST ),
545
- 'data__set_cookies' => $apbct->settings['data__set_cookies'],
546
- )
547
- ) );
548
-
549
- if( $apbct->settings['sfw__anti_crawler'] && $apbct->stats['sfw']['entries'] > 50 ){
550
- $firewall->load_fw_module( new \Cleantalk\ApbctWP\Firewall\AntiCrawler(
551
- APBCT_TBL_FIREWALL_LOG,
552
- APBCT_TBL_AC_LOG,
553
- array(
554
- 'api_key' => $apbct->api_key,
555
- 'apbct' => $apbct,
556
- )
557
- ) );
558
- }
559
-
560
- if( $apbct->settings['sfw__anti_flood'] && is_null( apbct_wp_get_current_user() ) ){
561
- $firewall->load_fw_module( new AntiFlood(
562
- APBCT_TBL_FIREWALL_LOG,
563
- APBCT_TBL_AC_LOG,
564
- array(
565
- 'api_key' => $apbct->api_key,
566
- 'view_limit' => $apbct->settings['sfw__anti_flood__view_limit'],
567
- 'apbct' => $apbct,
568
- )
569
- ) );
570
- }
571
-
572
- $firewall->run();
 
 
 
 
 
 
 
 
 
573
 
 
574
  }
575
 
576
  /**
@@ -582,8 +695,9 @@ function apbct_sfw__check()
582
  * @return void
583
  * @depreacted Use Activator::create_tables() instead
584
  */
585
- function apbct_activation__create_tables( $sqls, $db_prefix = '' ) {
586
- Activator::create_tables( $sqls, $db_prefix );
 
587
  }
588
 
589
  /**
@@ -592,55 +706,60 @@ function apbct_activation__create_tables( $sqls, $db_prefix = '' ) {
592
  */
593
  function apbct_plugin_redirect()
594
  {
595
- global $apbct;
596
- if (get_option('ct_plugin_do_activation_redirect', false) && !isset($_GET['activate-multi'])){
597
- delete_option('ct_plugin_do_activation_redirect');
598
  ct_account_status_check(null, false);
599
- apbct_sfw_update__init( 3 ); // Updating SFW
600
- wp_redirect($apbct->settings_link);
601
- }
602
  }
603
 
604
  /**
605
  * @param $event_type
 
606
  * @psalm-suppress UnusedVariable
607
  */
608
  function ct_add_event($event_type)
609
  {
610
- global $apbct, $cleantalk_executed;
611
 
612
  //
613
  // To migrate on the new version of ct_add_event().
614
  //
615
- switch ($event_type) {
616
- case '0': $event_type = 'no';break;
617
- case '1': $event_type = 'yes';break;
 
 
 
 
618
  }
619
 
620
- $current_hour = (int) date( 'G' );
621
 
622
- // Updating current hour
623
- if($current_hour!=$apbct->data['current_hour']){
624
- $apbct->data['current_hour'] = $current_hour;
625
- $apbct->data['array_accepted'][$current_hour] = 0;
626
- $apbct->data['array_blocked'][$current_hour] = 0;
627
- }
628
 
629
- //Add 1 to counters
630
- if( $event_type === 'yes'){
631
- $apbct->data['array_accepted'][$current_hour]++;
632
- $apbct->data['admin_bar__all_time_counter']['accepted']++;
633
- $apbct->data['user_counter']['accepted']++;
634
- }
635
- if( $event_type === 'no'){
636
- $apbct->data['array_blocked'][$current_hour]++;
637
- $apbct->data['admin_bar__all_time_counter']['blocked']++;
638
- $apbct->data['user_counter']['blocked']++;
639
- }
640
 
641
- $apbct->saveData();
642
 
643
- $cleantalk_executed=true;
644
  }
645
 
646
  /**
@@ -648,25 +767,24 @@ function ct_add_event($event_type)
648
  */
649
  function ct_get_cookie()
650
  {
651
- $ct_checkjs_key = ct_get_checkjs_value();
652
- print $ct_checkjs_key;
653
- die();
654
  }
655
 
656
  // Clears
657
- function apbct_sfw__clear(){
658
-
659
  global $apbct, $wpdb;
660
 
661
- $wpdb->query( 'DELETE FROM ' . APBCT_TBL_FIREWALL_DATA . ';' );
662
 
663
  $apbct->stats['sfw']['entries'] = 0;
664
  $apbct->save('stats');
665
-
666
  }
667
 
668
  // This action triggered by wp_schedule_single_event( time() + 900, 'ct_sfw_update' );
669
- add_action( 'apbct_sfw_update__init', 'apbct_sfw_update__init' );
670
 
671
  /**
672
  * Called by sfw_update remote call
@@ -676,65 +794,65 @@ add_action( 'apbct_sfw_update__init', 'apbct_sfw_update__init' );
676
  *
677
  * @return bool|string|string[]
678
  */
679
- function apbct_sfw_update__init( $delay = 0 ){
680
-
681
  global $apbct;
682
 
683
  // Prevent start an update if update is already running and started less than 10 minutes ago
684
- if(
685
  $apbct->fw_stats['firewall_updating_id'] &&
686
  time() - $apbct->fw_stats['firewall_updating_last_start'] < 600 &&
687
- apbct_sfw_update__is_in_progress()
688
- ){
689
  return false;
690
  }
691
 
692
- if( ! $apbct->settings['sfw__enabled'] ) {
693
- return array( 'error' => 'SFW UPDATE INIT: SFW_IS_DISABLED' );
694
  }
695
 
696
  // Key is empty
697
- if( ! $apbct->api_key && ! $apbct->ip_license){
698
- return array( 'error' => 'SFW UPDATE INIT: KEY_IS_EMPTY' );
699
  }
700
 
701
- if( ! $apbct->data['key_is_ok'] ){
702
- return array( 'error' => 'SFW UPDATE INIT: KEY_IS_NOT_VALID' );
703
  }
704
 
705
  $apbct->fw_stats['updating_folder'] = APBCT_DIR_PATH . DIRECTORY_SEPARATOR . 'fw_files_for_blog_' . get_current_blog_id() . DIRECTORY_SEPARATOR;
706
 
707
  $prepare_dir__result = apbct_prepare_upd_dir();
708
- if( ! empty( $prepare_dir__result['error'] ) ){
709
- return $prepare_dir__result;
710
  }
711
 
712
  // Set a new update ID and an update time start
713
- $apbct->fw_stats['calls'] = 0;
714
- $apbct->fw_stats['firewall_updating_id'] = md5( (string) rand( 0, 100000 ) );
715
  $apbct->fw_stats['firewall_updating_last_start'] = time();
716
- $apbct->save( 'fw_stats' );
717
 
718
- // Delete update errors
719
- $apbct->error_delete( 'sfw_update', 'save_data' );
720
- $apbct->error_delete( 'sfw_update', 'save_data', 'cron' );
721
 
722
  \Cleantalk\ApbctWP\Queue::clearQueue();
723
 
724
- $queue = new \Cleantalk\ApbctWP\Queue();
725
- $queue->addStage( 'apbct_sfw_update__get_multifiles' );
726
 
727
- $cron = new Cron();
728
- $cron->addTask('sfw_update_checker', 'apbct_sfw_update__checker', 15 );
729
 
730
- return Helper::http__request__rc_to_host(
731
  'sfw_update__worker',
732
- array(
733
  'firewall_updating_id' => $apbct->fw_stats['firewall_updating_id'],
734
- 'delay' => $delay
735
  ),
736
- array( 'async' )
737
- );
738
  }
739
 
740
  /**
@@ -749,399 +867,397 @@ function apbct_sfw_update__init( $delay = 0 ){
749
  *
750
  * @return array|bool|int|string|string[]
751
  */
752
- function apbct_sfw_update__worker( $checker_work = false ) {
753
-
754
  global $apbct;
755
 
756
- usleep( 10000 );
757
 
758
- if( ! $apbct->data['key_is_ok'] ){
759
- return array( 'error' => 'Worker: KEY_IS_NOT_VALID' );
760
  }
761
 
762
- if( ! $checker_work ){
763
- if(
764
- Get::equal( 'firewall_updating_id', '' ) ||
765
- ! Get::equal( 'firewall_updating_id', $apbct->fw_stats['firewall_updating_id'] )
766
- ){
767
- return array( 'error' => 'Worker: WRONG_UPDATE_ID' );
768
- }
769
- }
770
 
771
- if( ! isset( $apbct->fw_stats['calls'] ) ){
772
  $apbct->fw_stats['calls'] = 0;
773
  }
774
 
775
  $apbct->fw_stats['calls']++;
776
  $apbct->save('fw_stats');
777
 
778
- if( $apbct->fw_stats['calls'] > 600 ){
779
- $apbct->error_add('sfw_update', 'WORKER_CALL_LIMIT_EXCEEDED' );
780
  $apbct->saveErrors();
 
781
  return 'WORKER_CALL_LIMIT_EXCEEDED';
782
  }
783
 
784
- $queue = new \Cleantalk\ApbctWP\Queue();
 
 
 
 
 
785
 
786
- if( count( $queue->queue['stages'] ) === 0 ) {
787
- // Queue is already empty. Exit.
788
- return true;
789
- }
790
 
791
- $result = $queue->executeStage();
 
 
792
 
793
- if( isset( $result['error'] ) ) {
794
- $apbct->error_add('sfw_update', $result['error'] );
795
- $apbct->saveErrors();
796
- return $result['error'];
797
- }
798
 
799
- if( $queue->isQueueFinished() ) {
 
 
 
 
 
 
 
800
 
801
- $queue->queue['finished'] = time();
802
- $queue->saveQueue( $queue->queue );
803
- foreach( $queue->queue['stages'] as $stage ) {
804
- if( isset( $stage['error'] ) ) {
805
- $apbct->error_add('sfw_update', $stage['error'] );
806
- }
807
- }
808
- // Do logging the queue process here
809
- return true;
810
- }
811
 
812
  // This is the repeat stage request, do not generate any new RC
813
- if( stripos( Get::get('stage'), 'Repeat' ) !== false ) {
814
- return true;
815
- }
816
-
817
- return Helper::http__request__rc_to_host(
818
- 'sfw_update__worker',
819
- array( 'firewall_updating_id' => $apbct->fw_stats['firewall_updating_id'] ),
820
- array( 'async' )
821
- );
822
 
 
 
 
 
 
823
  }
824
 
825
- function apbct_sfw_update__get_multifiles(){
826
-
827
  global $apbct;
828
 
829
- if( ! $apbct->data['key_is_ok'] ){
830
- return array( 'error' => 'Get multifiles: KEY_IS_NOT_VALID' );
831
- }
832
-
833
- // Getting remote file name
834
- $result = API::method__get_2s_blacklists_db( $apbct->api_key, 'multifiles', '3_1' );
835
-
836
- if( empty( $result['error'] ) ){
837
-
838
- if( ! empty( $result['file_url'] ) ) {
839
- $file_urls = Helper::http__get_data_from_remote_gz__and_parse_csv( $result['file_url'] );
840
- if( empty( $file_urls['error'] ) ){
841
- if( ! empty( $result['file_ua_url'] ) ) {
842
- $file_urls[][0] = $result['file_ua_url'];
843
- }
844
- if( ! empty( $result['file_ck_url'] ) ) {
845
- $file_urls[][0] = $result['file_ck_url'];
846
- }
847
- $urls = array();
848
- foreach ( $file_urls as $value ) {
849
- $urls[] = $value[0];
850
- }
851
-
852
- $apbct->fw_stats['firewall_update_percent'] = 100 / count( $urls );
853
- $apbct->save( 'fw_stats' );
854
-
855
- return array(
856
- 'next_stage' => array(
857
- 'name' => 'apbct_sfw_update__download_files',
858
- 'args' => $urls,
859
- 'is_last' => '0'
860
- )
861
- );
862
-
863
- }
864
-
865
- return array( 'error' => $file_urls['error'] );
866
- }
867
-
868
- }else {
869
- return $result;
870
- }
871
- }
872
-
873
- function apbct_sfw_update__download_files( $urls ) {
874
-
875
- global $apbct;
876
-
877
- sleep(3);
878
-
879
- //Reset keys
880
- $urls = array_values( $urls );
881
- $results = Helper::http__multi_request( $urls, $apbct->fw_stats['updating_folder'] );
882
- $count_urls = count( $urls );
883
- $count_results = count( $results );
884
-
885
- if ( empty( $results['error'] ) && ( $count_urls === $count_results ) ) {
886
- $download_again = array();
887
- for( $i = 0; $i < $count_results; $i++ ) {
888
- if( $results[$i] === 'error' ) {
889
- $download_again[] = $urls[$i];
890
- }
891
- }
892
-
893
- if( count( $download_again ) !== 0 ) {
894
- return array(
895
- 'error' => 'Files download not completed.',
896
- 'update_args' => array(
897
- 'args' => $download_again
898
- )
899
- );
900
- }
901
-
902
- return array(
903
- 'next_stage' => array(
904
- 'name' => 'apbct_sfw_update__create_tables'
905
- )
906
- );
907
- }
908
-
909
- if ( ! empty( $results['error'] ) ) {
910
- return $results;
911
- }
912
-
913
- return array( 'error' => 'Files download not completed.' );
914
 
915
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
916
 
917
- function apbct_sfw_update__create_tables() {
918
- global $apbct;
919
- // Preparing database infrastructure
920
- // Creating SFW tables to make sure that they are exist
921
- apbct_activation__create_tables( Schema::getSchema( 'sfw' ), $apbct->db_prefix );
922
- return array(
923
- 'next_stage' => array(
924
- 'name' => 'apbct_sfw_update__create_temp_tables',
925
- )
926
- );
927
  }
928
 
929
- function apbct_sfw_update__create_temp_tables() {
930
- // Preparing temporary tables
931
- $result = SFW::create_temp_tables( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
932
- if( ! empty( $result['error'] ) ) {
933
- return $result;
934
- }
935
- return array(
936
- 'next_stage' => array(
937
- 'name' => 'apbct_sfw_update__process_files',
938
- )
939
- );
940
- }
941
 
942
- function apbct_sfw_update__process_files() {
943
 
944
- global $apbct;
 
 
 
 
945
 
946
- $files = glob( $apbct->fw_stats['updating_folder'] . '/*csv.gz' );
947
- $files = array_filter( $files, static function( $element ) {
948
- return strpos( $element, 'list' ) !== false;
949
- } );
 
 
 
950
 
951
- if( count( $files ) ) {
 
 
 
 
 
 
 
952
 
953
- reset( $files );
954
- $concrete_file = current( $files );
 
 
 
 
955
 
956
- if( strpos( $concrete_file, 'bl_list' ) !== false ) {
957
- $result = apbct_sfw_update__process_file( $concrete_file );
958
- }
959
 
960
- if( strpos( $concrete_file, 'ua_list' ) !== false ) {
961
- $result = apbct_sfw_update__process_ua( $concrete_file );
962
- }
963
 
964
- if( strpos( $concrete_file, 'ck_list' ) !== false ) {
965
- $result = apbct_sfw_update__process_ck( $concrete_file );
966
- }
 
 
 
 
 
 
 
 
 
 
967
 
968
- if( ! empty( $result['error'] ) ) {
969
- return $result;
970
- }
 
 
 
 
971
 
972
- $apbct->fw_stats['firewall_update_percent'] = round( 100 / count( $files ), 2 ) * 100;
973
- $apbct->save( 'fw_stats' );
 
 
 
 
974
 
975
- return array(
976
- 'next_stage' => array(
977
- 'name' => 'apbct_sfw_update__process_files',
978
- )
979
- );
980
- }
981
 
982
- return array(
983
- 'next_stage' => array(
984
- 'name' => 'apbct_sfw_update__process_exclusions',
985
- )
986
- );
987
 
988
- }
 
 
989
 
990
- function apbct_sfw_update__process_file( $file_path ){
 
 
991
 
992
- if( ! file_exists( $file_path ) ) {
993
- return array( 'error' => 'PROCESS FILE: ' . $file_path . ' is not exists.' );
994
- }
995
 
996
- $result = SFW::update__write_to_db(
997
- DB::getInstance(),
998
- APBCT_TBL_FIREWALL_DATA . '_temp',
999
- $file_path
1000
- );
1001
 
1002
- if( ! empty( $result['error'] ) ){
1003
- return array( 'error' => 'PROCESS FILE: ' . $result['error'] );
1004
- }
1005
 
1006
- if( ! is_int( $result ) ){
1007
- return array( 'error' => 'PROCESS FILE: WRONG RESPONSE FROM update__write_to_db' );
1008
- }
1009
 
1010
- return $result;
 
 
 
 
 
1011
 
 
 
 
 
 
1012
  }
1013
 
1014
- function apbct_sfw_update__process_ua( $file_path ){
 
 
 
 
1015
 
1016
- $result = AntiCrawler::update( $file_path );
 
 
 
 
1017
 
1018
- if( ! empty( $result['error'] ) ){
1019
- return array( 'error' => 'UPDATING UA LIST: ' . $result['error'] );
1020
- }
1021
 
1022
- if( ! is_int( $result ) ){
1023
- return array( 'error' => 'UPDATING UA LIST: : WRONG_RESPONSE AntiCrawler::update' );
1024
- }
1025
 
1026
- return $result;
1027
  }
1028
 
1029
- function apbct_sfw_update__process_ck( $file_path ) {
1030
-
1031
- global $apbct;
1032
 
1033
- // Save expected_networks_count and expected_ua_count if exists
1034
- $file_content = file_get_contents( $file_path );
 
1035
 
1036
- if(function_exists('gzdecode')) {
 
 
1037
 
1038
- $unzipped_content = gzdecode( $file_content );
 
1039
 
1040
- if ( $unzipped_content !== false ) {
 
 
1041
 
1042
- $file_ck_url__data = Helper::buffer__parse__csv( $unzipped_content );
 
1043
 
1044
- if( ! empty( $file_ck_url__data['error'] ) ){
1045
- return array( 'error' => 'GET EXPECTED RECORDS COUNT DATA: ' . $file_ck_url__data['error'] );
1046
- }
1047
 
1048
- $expected_networks_count = 0;
1049
- $expected_ua_count = 0;
1050
 
1051
- foreach( $file_ck_url__data as $value ) {
1052
- if( trim( $value[0], '"' ) === 'networks_count' ){
1053
- $expected_networks_count = $value[1];
1054
- }
1055
- if( trim( $value[0], '"' ) === 'ua_count' ) {
1056
- $expected_ua_count = $value[1];
1057
- }
1058
- }
1059
 
1060
- $apbct->fw_stats['expected_networks_count'] = $expected_networks_count;
1061
- $apbct->fw_stats['expected_ua_count'] = $expected_ua_count;
1062
- $apbct->save( 'fw_stats' );
1063
 
1064
- if( file_exists( $file_path ) ) {
1065
- unlink($file_path);
1066
- }
 
 
 
 
 
1067
 
1068
- } else {
1069
- return array( 'error' => 'Can not unpack datafile');
1070
- }
1071
- } else {
1072
- return array( 'error' => 'Function gzdecode not exists. Please update your PHP at least to version 5.4 ' );
1073
- }
1074
 
 
 
 
 
 
 
 
 
 
1075
  }
1076
 
1077
- function apbct_sfw_update__process_exclusions(){
 
1078
  global $apbct;
1079
 
1080
- $result = SFW::update__write_to_db__exclusions(
1081
  DB::getInstance(),
1082
  APBCT_TBL_FIREWALL_DATA . '_temp'
1083
  );
1084
 
1085
- if( ! empty( $result['error'] ) ){
1086
- return array( 'error' => 'EXCLUSIONS: ' . $result['error'] );
1087
  }
1088
 
1089
- if( ! is_int( $result ) ){
1090
- return array( 'error' => 'EXCLUSIONS: WRONG_RESPONSE update__write_to_db__exclusions' );
1091
  }
1092
 
1093
  /**
1094
  * Update expected_networks_count
1095
  */
1096
- if( $result > 0 ) {
1097
  $apbct->fw_stats['expected_networks_count'] += $result;
1098
- $apbct->save( 'fw_stats' );
1099
  }
1100
 
1101
- return array(
1102
- 'next_stage' => array(
1103
- 'name' => 'apbct_sfw_update__end_of_update'
1104
- )
1105
- );
1106
-
1107
  }
1108
 
1109
- function apbct_sfw_update__end_of_update() {
 
 
1110
 
1111
- global $apbct, $wpdb;
 
 
1112
 
1113
- $apbct->fw_stats['update_mode'] = 1;
1114
- $apbct->save('fw_stats');
1115
 
1116
- // REMOVE AND RENAME
1117
- $result = SFW::data_tables__delete( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
1118
- if( empty( $result['error'] ) ) {
1119
- $result = SFW::rename_data_tables__from_temp_to_main( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
1120
  }
1121
- if( ! empty( $result['error'] ) ) {
1122
  $apbct->fw_stats['update_mode'] = 0;
1123
  $apbct->save('fw_stats');
1124
- return $result;
1125
- }
1126
 
1127
- // Increment firewall entries
1128
- $apbct->fw_stats['firewall_update_percent'] = 0;
1129
- $apbct->fw_stats['firewall_updating_id'] = null;
1130
- $apbct->fw_stats['last_firewall_updated'] = time();
1131
- $apbct->fw_stats['update_mode'] = 0;
1132
- $apbct->save( 'fw_stats' );
 
 
 
1133
 
1134
- $apbct->stats['sfw']['entries'] = $wpdb->get_var('SELECT COUNT(*) FROM ' . APBCT_TBL_FIREWALL_DATA );
1135
 
1136
- // Running sfw update once again in 12 min if entries is < 4000
1137
- if( ! $apbct->stats['sfw']['last_update_time'] &&
1138
- $apbct->stats['sfw']['entries'] < 4000
1139
- ){
1140
- wp_schedule_single_event( time() + 720, 'apbct_sfw_update__init' );
1141
- }
1142
 
1143
- $apbct->stats['sfw']['last_update_time'] = time();
1144
- $apbct->save( 'stats' );
 
1145
 
1146
  /**
1147
  * Checking the integrity of the sfw database update
@@ -1149,42 +1265,44 @@ function apbct_sfw_update__end_of_update() {
1149
  //@ToDo NEED TO BE REVIEWED
1150
  global $ct_cron;
1151
 
1152
- if( $apbct->stats['sfw']['entries'] != $apbct->fw_stats['expected_networks_count'] ) {
1153
-
1154
  # call manually
1155
- /** @psalm-suppress TypeDoesNotContainType */
1156
- if( ! $ct_cron ){
1157
  return array(
1158
- 'error' => 'The discrepancy between the amount of data received for the update and in the final table: ' . APBCT_TBL_FIREWALL_DATA . '. RECEIVED: ' . $apbct->fw_stats['expected_networks_count'] . '. ADDED: ' . $apbct->stats['sfw']['entries']);
 
1159
  }
1160
 
1161
  #call cron
1162
- if( $apbct->fw_stats['failed_update_attempt'] ) {
1163
  return array(
1164
- 'error' => 'The discrepancy between the amount of data received for the update and in the final table: ' . APBCT_TBL_FIREWALL_DATA . '. RECEIVED: ' . $apbct->fw_stats['expected_networks_count'] . '. ADDED: ' . $apbct->stats['sfw']['entries']);
 
1165
  }
1166
 
1167
  $apbct->fw_stats['failed_update_attempt'] = true;
1168
- $apbct->save( 'fw_stats' );
1169
 
1170
  $cron = new Cron();
1171
- $cron->updateTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 180 );
 
1172
  return false;
1173
  }
1174
 
1175
  $apbct->data['last_firewall_updated'] = current_time('timestamp');
1176
- $apbct->save('data'); // Unused
1177
 
1178
- // Delete update errors
1179
- $apbct->error_delete( 'sfw_update', 'save_settings' );
1180
 
1181
- // Get update period for server
1182
- $update_period = DNS::getRecord( 'spamfirewall-ttl-txt.cleantalk.org', true, DNS_TXT );
1183
- $update_period = isset( $update_period['txt'] ) ? $update_period['txt'] : 0;
1184
- $update_period = (int) $update_period > 14400 ? (int) $update_period : 14400;
1185
- $cron = new Cron();
1186
- $cron->updateTask('sfw_update', 'apbct_sfw_update__init', $update_period );
1187
- $cron->removeTask('sfw_update_checker' );
1188
 
1189
  /**
1190
  * Update fw data if update completed
@@ -1192,149 +1310,233 @@ function apbct_sfw_update__end_of_update() {
1192
  $apbct->fw_stats['failed_update_attempt'] = false;
1193
  $apbct->fw_stats['expected_networks_count'] = false;
1194
 
1195
- apbct_remove_upd_folder( $apbct->fw_stats['updating_folder'] );
1196
 
1197
- $apbct->save( 'fw_stats' );
1198
-
1199
- return true;
1200
 
 
1201
  }
1202
 
1203
 
1204
- function apbct_sfw_update__is_in_progress() {
1205
- $queue = new \Cleantalk\ApbctWP\Queue();
1206
- return $queue->isQueueInProgress();
 
 
1207
  }
1208
 
1209
- function apbct_prepare_upd_dir() {
 
 
1210
 
1211
- global $apbct;
1212
 
1213
- $dir_name = $apbct->fw_stats['updating_folder'];
 
 
1214
 
1215
- if( $dir_name === '' ) {
1216
- return array( 'error' => 'FW dir can not be blank.' );
1217
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1218
 
1219
- if( ! is_dir( $dir_name ) ) {
1220
- if( ! mkdir( $dir_name ) && ! is_dir( $dir_name ) ) {
1221
- return array( 'error' => 'Can not to make FW dir.' );
1222
- }
1223
- } else {
1224
- $files = glob( $dir_name . '/*' );
1225
- if( $files === false ) {
1226
- return array( 'error' => 'Can not find FW files.' );
1227
- }
1228
- if( count( $files ) === 0 ) {
1229
- return (bool) file_put_contents( $dir_name . 'index.php', '<?php' . PHP_EOL );
1230
- }
1231
- foreach( $files as $file ){
1232
- if( is_file( $file ) && unlink( $file ) === false ){
1233
- return array( 'error' => 'Can not delete the FW file: ' . $file );
 
1234
  }
1235
- }
1236
- }
1237
- return (bool) file_put_contents( $dir_name . 'index.php', '<?php' );
 
1238
  }
1239
 
1240
- function apbct_remove_upd_folder( $dir_name ) {
 
 
 
 
 
 
 
 
 
1241
 
1242
- if( is_dir( $dir_name ) ) {
 
1243
 
1244
- $files = glob( $dir_name . '/*' );
 
 
1245
 
1246
- if( ! empty( $files ) ) {
1247
- foreach( $files as $file ){
1248
- if( is_file( $file ) ){
1249
- unlink( $file );
1250
- }
1251
- if( is_dir( $file ) ) {
1252
- apbct_remove_upd_folder( $file );
1253
- }
1254
- }
1255
- }
1256
 
1257
- rmdir( $dir_name );
 
 
 
1258
 
1259
- }
 
1260
 
1261
- }
 
 
 
 
 
 
 
 
 
 
1262
 
1263
- function apbct_sfw_update__checker() {
1264
- $queue = new \Cleantalk\ApbctWP\Queue();
1265
- if( count( $queue->queue['stages'] ) ) {
1266
- foreach( $queue->queue['stages'] as $stage ) {
1267
- if ( $stage['status'] === 'NULL' ) {
1268
- return apbct_sfw_update__worker( true );
1269
- }
1270
- }
1271
- }
1272
 
1273
- return true;
1274
- }
 
 
 
 
 
 
 
 
1275
 
1276
- function apbct_sfw_update__cleanData(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1277
 
 
 
1278
  global $apbct;
1279
 
1280
- SFW::data_tables__delete( DB::getInstance(), APBCT_TBL_FIREWALL_DATA . '_temp' );
1281
 
1282
  $apbct->fw_stats['firewall_update_percent'] = 0;
1283
- $apbct->fw_stats['firewall_updating_id'] = null;
1284
- $apbct->save( 'fw_stats' );
1285
  }
1286
 
1287
  function ct_sfw_send_logs($api_key = '')
1288
  {
1289
- global $apbct;
1290
 
1291
- $api_key = !empty($apbct->api_key) ? $apbct->api_key : $api_key;
1292
 
1293
- if(
1294
  time() - $apbct->stats['sfw']['sending_logs__timestamp'] < 180 ||
1295
- empty( $api_key ) ||
1296
  $apbct->settings['sfw__enabled'] != 1
1297
- ){
1298
  return true;
1299
  }
1300
 
1301
  $apbct->stats['sfw']['sending_logs__timestamp'] = time();
1302
  $apbct->save('stats');
1303
 
1304
- $result = SFW::send_log(
1305
  DB::getInstance(),
1306
  APBCT_TBL_FIREWALL_LOG,
1307
  $api_key,
1308
- (bool) $apbct->settings['sfw__use_delete_to_clear_table']
1309
  );
1310
 
1311
- if(empty($result['error'])){
1312
- $apbct->stats['sfw']['last_send_time'] = time();
1313
- $apbct->stats['sfw']['last_send_amount'] = $result['rows'];
1314
- $apbct->error_delete( 'sfw_send_logs', 'save_settings' );
1315
  $apbct->save('stats');
1316
  }
1317
 
1318
  return $result;
1319
  }
1320
 
1321
- function apbct_antiflood__clear_table(){
1322
-
1323
- global $apbct;
1324
-
1325
- if( $apbct->settings['sfw__anti_flood'] || $apbct->settings['sfw__anti_crawler'] ){
1326
 
1327
- $anti_flood = new AntiFlood(
1328
- APBCT_TBL_FIREWALL_LOG,
1329
- APBCT_TBL_AC_LOG,
1330
- array(
1331
- 'chance_to_clean' => 100,
1332
- )
1333
- );
1334
- $anti_flood->setDb( DB::getInstance() );
1335
- $anti_flood->clear_table();
1336
- unset( $anti_flood );
1337
- }
 
1338
  }
1339
 
1340
  /**
@@ -1342,96 +1544,95 @@ function apbct_antiflood__clear_table(){
1342
  *
1343
  * @param null|WP $_wp
1344
  * @param null|string|array $plugin
 
1345
  * @psalm-suppress UndefinedClass
1346
  */
1347
- function apbct_rc__install_plugin($_wp = null, $plugin = null){
1348
- global $wp_version;
1349
-
1350
- if( is_null( $plugin ) ) {
1351
- $plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
1352
- }
1353
-
1354
- if($plugin){
1355
-
1356
- if(preg_match('/[a-zA-Z-\d]+[\/\\][a-zA-Z-\d]+\.php/', $plugin)){
1357
-
1358
- $plugin_slug = preg_replace('@([a-zA-Z-\d]+)[\\\/].*@', '$1', $plugin);
1359
-
1360
- if($plugin_slug){
1361
-
1362
- require_once(ABSPATH.'wp-admin/includes/plugin-install.php');
1363
- $result = plugins_api(
1364
- 'plugin_information',
1365
- array(
1366
- 'slug' => $plugin_slug,
1367
- 'fields' => array('version' => true, 'download_link' => true,),
1368
- )
1369
- );
1370
-
1371
- if(!is_wp_error($result)){
1372
 
1373
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1374
- include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
1375
- include_once( ABSPATH . 'wp-admin/includes/file.php' );
1376
- include_once( ABSPATH . 'wp-admin/includes/misc.php' );
1377
 
1378
- if (version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0) {
1379
- $installer= new CleantalkUpgrader( new CleantalkUpgraderSkin() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1380
  } else {
1381
- $installer= new CleantalkUpgrader( new CleantalkUpgraderSkin_Deprecated() );
1382
  }
1383
 
1384
- $installer->install($result->download_link);
1385
 
1386
- if($installer->apbct_result === 'OK'){
1387
- die('OK');
1388
-
1389
- }else {
1390
- die( 'FAIL ' . json_encode( array( 'error' => $installer->apbct_result ) ) );
1391
- }
1392
- }else {
1393
- die( 'FAIL ' . json_encode( array( 'error' => 'FAIL_TO_GET_LATEST_VERSION',
1394
- 'details' => $result->get_error_message(),
1395
- ) ) );
1396
- }
1397
- }else {
1398
- die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_SLUG_INCORRECT' ) ) );
1399
- }
1400
- }else {
1401
- die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_INCORRECT' ) ) );
1402
- }
1403
- }else {
1404
- die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_UNSET' ) ) );
1405
- }
 
 
1406
  }
1407
 
1408
- function apbct_rc__activate_plugin($plugin){
1409
-
1410
- if( ! $plugin ) {
1411
- $plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
1412
- }
1413
-
1414
- if($plugin){
1415
-
1416
- if(preg_match('@[a-zA-Z-\d]+[\\\/][a-zA-Z-\d]+\.php@', $plugin)){
1417
 
1418
- require_once (ABSPATH .'/wp-admin/includes/plugin.php');
 
 
1419
 
1420
- $result = activate_plugins($plugin);
1421
 
1422
- if($result && !is_wp_error($result)){
1423
- return array('success' => true);
1424
- }else {
1425
- return array( 'error' => 'FAIL_TO_ACTIVATE',
1426
- 'details' => ( is_wp_error( $result ) ? ' ' . $result->get_error_message() : '' )
1427
- );
1428
- }
1429
- }else {
1430
- return array( 'error' => 'PLUGIN_NAME_IS_INCORRECT' );
1431
- }
1432
- }else {
1433
- return array( 'error' => 'PLUGIN_NAME_IS_UNSET' );
1434
- }
 
1435
  }
1436
 
1437
  /**
@@ -1439,45 +1640,44 @@ function apbct_rc__activate_plugin($plugin){
1439
  *
1440
  * @param null $plugin
1441
  */
1442
- function apbct_rc__deactivate_plugin($plugin = null){
1443
-
1444
- global $apbct;
1445
-
1446
- if( is_null( $plugin ) ) {
1447
- $plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
1448
- }
1449
 
1450
- if($plugin){
 
 
1451
 
1452
- // Switching complete deactivation for security
1453
- if( $plugin === 'security-malware-firewall/security-malware-firewall.php' && !empty($_GET['misc__complete_deactivation'])){
1454
- $spbc_settings = get_option('spbc_settings');
1455
- $spbc_settings['misc__complete_deactivation'] = (int) $_GET['misc__complete_deactivation'];
1456
- update_option('spbc_settings', $spbc_settings);
1457
- }
 
1458
 
1459
- require_once (ABSPATH .'/wp-admin/includes/plugin.php');
1460
 
1461
- if(is_plugin_active( $plugin )){
1462
- // Hook to set flag if the plugin is deactivated
1463
- add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
1464
- deactivate_plugins($plugin, false, is_multisite() );
1465
- }else{
1466
- $apbct->plugin_deactivated = true;
1467
- }
1468
 
1469
- // Hook to set flag if the plugin is deactivated
1470
- add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
1471
- deactivate_plugins($plugin, false, is_multisite() );
1472
 
1473
- if($apbct->plugin_deactivated){
1474
- die('OK');
1475
- }else {
1476
- die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_STILL_ACTIVE' ) ) );
1477
- }
1478
- }else {
1479
- die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_UNSET' ) ) );
1480
- }
1481
  }
1482
 
1483
 
@@ -1486,152 +1686,163 @@ function apbct_rc__deactivate_plugin($plugin = null){
1486
  *
1487
  * @param null $plugin
1488
  */
1489
- function apbct_rc__uninstall_plugin($plugin = null){
1490
-
1491
- global $apbct;
1492
-
1493
- if( is_null( $plugin ) ) {
1494
- $plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
1495
- }
1496
-
1497
- if($plugin){
1498
 
1499
- // Switching complete deactivation for security
1500
- if( $plugin === 'security-malware-firewall/security-malware-firewall.php' && !empty($_GET['misc__complete_deactivation'])){
1501
- $spbc_settings = get_option('spbc_settings');
1502
- $spbc_settings['misc__complete_deactivation'] = (int) $_GET['misc__complete_deactivation'];
1503
- update_option('spbc_settings', $spbc_settings);
1504
- }
1505
 
1506
- require_once (ABSPATH .'/wp-admin/includes/plugin.php');
 
 
 
 
 
 
1507
 
1508
- if(is_plugin_active( $plugin )){
1509
- // Hook to set flag if the plugin is deactivated
1510
- add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
1511
- deactivate_plugins($plugin, false, is_multisite() );
1512
- }else{
1513
- $apbct->plugin_deactivated = true;
1514
- }
1515
 
1516
- if($apbct->plugin_deactivated){
 
 
 
 
 
 
1517
 
1518
- require_once (ABSPATH .'/wp-admin/includes/file.php');
 
1519
 
1520
- $result = delete_plugins(array($plugin));
1521
 
1522
- if($result && !is_wp_error($result)){
1523
- die('OK');
1524
- }else {
1525
- die( 'FAIL ' . json_encode( array(
1526
- 'error' => 'PLUGIN_STILL_EXISTS',
1527
- 'details' => ( is_wp_error( $result ) ? ' ' . $result->get_error_message() : '' )
1528
- ) ) );
1529
- }
1530
- }else {
1531
- die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_STILL_ACTIVE' ) ) );
1532
- }
1533
- }else {
1534
- die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_UNSET' ) ) );
1535
- }
 
 
1536
  }
1537
 
1538
- function apbct_rc__uninstall_plugin__check_deactivate(){
1539
- global $apbct;
1540
- $apbct->plugin_deactivated = true;
 
1541
  }
1542
 
1543
  /**
1544
  * @throws JsonException
1545
  * @psalm-suppress UndefinedClass
1546
  */
1547
- function apbct_rc__update(){
1548
- global $wp_version;
1549
-
1550
- //Upgrade params
1551
- $plugin = 'cleantalk-spam-protect/cleantalk.php';
1552
- $plugin_slug = 'cleantalk-spam-protect';
1553
- $title = __('Update Plugin');
1554
- $nonce = 'upgrade-plugin_' . $plugin;
1555
- $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
 
1556
  $activate_for_network = false;
1557
- if( APBCT_WPMS && is_main_site() && array_key_exists( $plugin, get_site_option( 'active_sitewide_plugins' ) ) ) {
1558
  $activate_for_network = true;
1559
  }
1560
 
1561
- $prev_version = APBCT_VERSION;
1562
 
1563
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1564
- include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
1565
- include_once( ABSPATH . 'wp-admin/includes/file.php' );
1566
- include_once( ABSPATH . 'wp-admin/includes/misc.php' );
1567
 
1568
- apbct_maintenance_mode__enable( 30 );
1569
 
1570
- if (version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0){
1571
- $upgrader = new CleantalkUpgrader( new CleantalkUpgraderSkin( compact('title', 'nonce', 'url', 'plugin') ) );
1572
- }else{
1573
- $upgrader = new CleantalkUpgrader( new CleantalkUpgraderSkin_Deprecated( compact('title', 'nonce', 'url', 'plugin') ) );
1574
- }
 
 
1575
 
1576
- $upgrader_result = $upgrader->upgrade( $plugin );
1577
- if( is_wp_error( $upgrader_result ) ){
1578
  error_log('CleanTalk debug message:');
1579
- error_log( var_export( $upgrader_result->get_error_message(), true) );
1580
  }
1581
 
1582
- apbct_maintenance_mode__disable();
1583
-
1584
- $result = activate_plugins( $plugin, '', $activate_for_network );
1585
-
1586
- // Changing response UP_TO_DATE to OK
1587
- if($upgrader->apbct_result === 'UP_TO_DATE') {
1588
- $upgrader->apbct_result = 'OK';
1589
- }
1590
 
1591
- if($upgrader->apbct_result === 'OK'){
1592
 
1593
- if(is_wp_error($result)){
1594
- die( 'FAIL ' . json_encode( array( 'error' => 'COULD_NOT_ACTIVATE', 'wp_error' => $result->get_error_message() ) ) );
1595
- }
1596
-
1597
- $httpResponseCode = Helper::http__request(get_option('siteurl'), array(), 'get_code');
1598
 
1599
- if( strpos($httpResponseCode, '200') === false ){
 
 
 
 
 
 
 
 
 
 
1600
 
1601
- apbct_maintenance_mode__enable( 30 );
1602
 
1603
- // Rollback
1604
- if (version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0) {
1605
- $rollback = new CleantalkUpgrader( new CleantalkUpgraderSkin( compact( 'title', 'nonce', 'url', 'plugin_slug', 'prev_version' ) ) );
1606
- }
1607
- else {
1608
- $rollback = new CleantalkUpgrader( new CleantalkUpgraderSkin_Deprecated( compact( 'title', 'nonce', 'url', 'plugin_slug', 'prev_version' ) ) );
1609
- }
1610
- $rollback->rollback($plugin);
1611
 
1612
- apbct_maintenance_mode__disable();
 
 
 
 
 
 
 
 
 
 
1613
 
1614
- // @todo add execution time
1615
 
1616
- $response = array(
1617
- 'error' => 'BAD_HTTP_CODE',
1618
- 'http_code' => $httpResponseCode,
1619
- 'output' => substr(file_get_contents(get_option('siteurl')), 0, 900),
1620
- 'rollback_result' => $rollback->apbct_result,
1621
- );
1622
 
1623
- die( 'FAIL ' . json_encode( $response ) );
1624
- }
 
 
 
 
1625
 
1626
- $plugin_data = get_plugin_data(__FILE__);
1627
- $apbct_agent = 'wordpress-'.str_replace('.', '', $plugin_data['Version']);
1628
- ct_send_feedback('0:' . $apbct_agent);
1629
 
1630
- die( 'OK ' . json_encode( array( 'agent' => $apbct_agent ) ) );
 
 
1631
 
1632
- }
 
1633
 
1634
- die( 'FAIL ' . json_encode( array( 'error' => $upgrader->apbct_result ) ) );
1635
  }
1636
 
1637
  /**
@@ -1639,25 +1850,25 @@ function apbct_rc__update(){
1639
  *
1640
  * @return bool
1641
  */
1642
- function apbct_rc__update_settings($source) {
1643
-
1644
- global $apbct;
1645
 
1646
- foreach($apbct->def_settings as $setting => $def_value){
1647
- if(array_key_exists($setting, $source)){
1648
- $var = $source[$setting];
1649
- $type = gettype($def_value);
1650
- settype($var, $type);
1651
- if( $type === 'string') {
1652
- $var = preg_replace( array( '/=/', '/`/' ), '', $var );
1653
- }
1654
- $apbct->settings[$setting] = $var;
1655
- }
1656
- }
1657
 
1658
- $apbct->save('settings');
1659
 
1660
- return true;
1661
  }
1662
 
1663
  /**
@@ -1666,64 +1877,59 @@ function apbct_rc__update_settings($source) {
1666
  *
1667
  * @return array|string
1668
  */
1669
- function apbct_rc__insert_auth_key($key, $plugin){
1670
-
1671
- if($plugin === 'security-malware-firewall/security-malware-firewall.php'){
1672
-
1673
- require_once (ABSPATH .'/wp-admin/includes/plugin.php');
1674
-
1675
- if(is_plugin_active( $plugin )){
1676
-
1677
- $key = trim($key);
1678
-
1679
- if($key && preg_match('/^[a-z\d]{3,15}$/', $key)){
1680
-
1681
- $result = API::method__notice_paid_till(
1682
- $key,
1683
- preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1), // Site URL
1684
- 'security'
1685
- );
1686
-
1687
- if( empty( $result['error'] ) ) {
1688
-
1689
- if( $result['valid'] ){
1690
-
1691
- // Set account params
1692
- $data = get_option('spbc_data', array());
1693
- $data['user_token'] = $result['user_token'];
1694
- $data['notice_show'] = $result['show_notice'];
1695
- $data['notice_renew'] = $result['renew'];
1696
- $data['notice_trial'] = $result['trial'];
1697
- $data['auto_update_app'] = isset($result['show_auto_update_notice']) ? $result['show_auto_update_notice'] : 0;
1698
- $data['service_id'] = $result['service_id'];
1699
- $data['moderate'] = $result['moderate'];
1700
- $data['auto_update_app '] = isset($result['auto_update_app']) ? $result['auto_update_app'] : 0;
1701
- $data['license_trial'] = isset($result['license_trial']) ? $result['license_trial'] : 0;
1702
- $data['account_name_ob'] = isset($result['account_name_ob']) ? $result['account_name_ob'] : '';
1703
- $data['key_is_ok'] = true;
1704
- update_option('spbc_data', $data);
1705
-
1706
- // Set key
1707
- $settings = get_option('spbc_settings', array());
1708
- $settings['spbc_key'] = $key;
1709
- update_option('spbc_settings', $settings);
1710
-
1711
- return 'OK';
1712
- }else {
1713
- return array( 'error' => 'KEY_IS_NOT_VALID' );
1714
- }
1715
- }else {
1716
- return array( 'error' => $result );
1717
- }
1718
- }else {
1719
- return array( 'error' => 'KEY_IS_NOT_CORRECT' );
1720
- }
1721
- }else {
1722
- return array( 'error' => 'PLUGIN_IS_NOT_ACTIVE_OR_NOT_INSTALLED' );
1723
- }
1724
- }else {
1725
- return array( 'error' => 'PLUGIN_SLUG_INCORRECT' );
1726
- }
1727
  }
1728
 
1729
  /**
@@ -1734,12 +1940,13 @@ function apbct_rc__insert_auth_key($key, $plugin){
1734
  *
1735
  * @return bool
1736
  */
1737
- function apbct_maintenance_mode__enable( $duration ) {
1738
- apbct_maintenance_mode__disable();
1739
- $content = "<?php\n\n"
1740
- . '$upgrading = ' . (time() - ( 60 * 10 ) + $duration) . ';';
 
1741
 
1742
- return (bool)file_put_contents( ABSPATH . '.maintenance', $content );
1743
  }
1744
 
1745
  /**
@@ -1747,11 +1954,12 @@ function apbct_maintenance_mode__enable( $duration ) {
1747
  *
1748
  * @return void
1749
  */
1750
- function apbct_maintenance_mode__disable() {
1751
- $maintenance_file = ABSPATH . '.maintenance';
1752
- if ( file_exists( $maintenance_file ) ) {
1753
- unlink( $maintenance_file );
1754
- }
 
1755
  }
1756
 
1757
  /**
@@ -1759,50 +1967,57 @@ function apbct_maintenance_mode__disable() {
1759
  *
1760
  * @param null|string $api_key
1761
  */
1762
- function cleantalk_get_brief_data( $api_key = null ){
1763
-
1764
  global $apbct;
1765
 
1766
- $api_key = is_null( $api_key ) ? $apbct->api_key : $api_key;
1767
-
1768
- $apbct->data['brief_data'] = API::method__get_antispam_report_breif( $api_key );
1769
-
1770
- # expanding data about the country
1771
- if(isset($apbct->data['brief_data']['top5_spam_ip']) && !empty($apbct->data['brief_data']['top5_spam_ip'])) {
1772
- foreach ($apbct->data['brief_data']['top5_spam_ip'] as $key => $ip_data) {
1773
- $ip = $ip_data[0];
1774
- $ip_data[1] = array(
1775
- 'country_name' => 'Unknown',
1776
- 'country_code' => 'cleantalk'
1777
- );
1778
-
1779
- if(isset($ip)) {
1780
- $country_data = API::method__ip_info($ip);
1781
- $country_data_clear = current($country_data);
1782
-
1783
- if(is_array($country_data_clear) && isset($country_data_clear['country_name']) && isset($country_data_clear['country_code'])) {
1784
- $ip_data[1] = array(
1785
- 'country_name' => $country_data_clear['country_name'],
1786
- 'country_code' => (!preg_match('/[^A-Za-z0-9]/', $country_data_clear['country_code'])) ? $country_data_clear['country_code'] : 'cleantalk'
1787
- );
1788
- }
1789
- }
1790
-
1791
- $apbct->data['brief_data']['top5_spam_ip'][$key] = $ip_data;
1792
- }
1793
- }
 
 
 
1794
 
1795
- $apbct->saveData();
 
 
1796
 
 
1797
  }
1798
 
1799
  /**
1800
  * Delete cookie for admin trial notice
1801
  */
1802
- function apbct__hook__wp_logout__delete_trial_notice_cookie(){
1803
- if(!headers_sent()) {
1804
- Cookie::setNativeCookie( 'ct_trial_banner_closed', '', time() - 3600 );
1805
- }
 
1806
  }
1807
 
1808
  /**
@@ -1811,47 +2026,55 @@ function apbct__hook__wp_logout__delete_trial_notice_cookie(){
1811
  * @throws JsonException
1812
  * @ToDo need to be refactored psalm notices about InvalidArrayOffset
1813
  */
1814
- function apbct_store__urls(){
1815
-
1816
  global $apbct;
1817
 
1818
- if($apbct->settings['misc__store_urls'] && empty($apbct->flags__url_stored) && !headers_sent()){
1819
-
1820
- // URLs HISTORY
1821
- // Get current url
1822
- $current_url = Server::get( 'HTTP_HOST' ) . Server::get( 'REQUEST_URI' );
1823
- $current_url = $current_url ? substr($current_url, 0,128) : 'UNKNOWN';
1824
- $site_url = parse_url(get_option('siteurl'),PHP_URL_HOST);
1825
-
1826
- // Get already stored URLs
1827
- $urls = Cookie::get( 'apbct_urls', array(), 'array' );
1828
- /** @psalm-suppress InvalidArrayOffset */
1829
- $urls[$current_url][] = time();
1830
-
1831
- // Rotating. Saving only latest 10
1832
- /** @psalm-suppress InvalidArrayOffset */
1833
- $urls[$current_url] = count($urls[$current_url]) > 5 ? array_slice($urls[$current_url], 1, 5) : $urls[$current_url];
1834
- $urls = count($urls) > 5 ? array_slice($urls, 1, 5) : $urls;
1835
-
1836
- // Saving
1837
- Cookie::set('apbct_urls', json_encode( $urls ), time() + 86400 * 3, '/', $site_url, null, true, 'Lax');
1838
-
1839
- // REFERER
1840
- // Get current referer
1841
- $new_site_referer = apbct_get_server_variable( 'HTTP_REFERER' );
1842
- $new_site_referer = $new_site_referer ?: 'UNKNOWN';
1843
-
1844
- // Get already stored referer
1845
- $site_referer = Cookie::get('apbct_site_referer' );
1846
-
1847
- // Save if empty
1848
- if( $site_url && ( ! $site_referer || parse_url($new_site_referer, PHP_URL_HOST) !== apbct_get_server_variable( 'HTTP_HOST' ) ) ){
1849
- Cookie::set('apbct_site_referer', $new_site_referer, time()+86400*3, '/', $site_url, null, true, 'Lax');
1850
- }
1851
-
1852
- $apbct->flags__url_stored = true;
 
 
 
 
 
 
 
1853
 
1854
- }
 
1855
  }
1856
 
1857
  /**
@@ -1860,81 +2083,81 @@ function apbct_store__urls(){
1860
  * Sets test cookie with all other cookies
1861
  * @return bool
1862
  */
1863
- function apbct_cookie(){
 
 
1864
 
1865
- global $apbct;
 
 
 
 
 
 
1866
 
1867
- if(
1868
- empty($apbct->settings['data__set_cookies']) || // Do not set cookies if option is disabled (for Varnish cache).
1869
- !empty($apbct->flags__cookies_setuped) || // Cookies already set
1870
- !empty($apbct->headers_sent) // Headers sent
1871
- ) {
1872
- return false;
1873
- }
1874
 
1875
- // Prevent headers sent error
1876
- if(headers_sent($file, $line)){
1877
- $apbct->headers_sent = true;
1878
- $apbct->headers_sent__hook = current_filter();
1879
- $apbct->headers_sent__where = $file.':'.$line;
1880
- return false;
1881
- }
1882
 
1883
 
1884
  // Cookie names to validate
1885
- $cookie_test_value = array(
1886
- 'cookies_names' => array(),
1887
- 'check_value' => $apbct->api_key,
1888
- );
1889
 
1890
- // We need to skip the domain attribute for prevent including the dot to the cookie's domain on the client.
1891
  $domain = '';
1892
 
1893
- // Submit time
1894
- if(empty($_POST['ct_multipage_form'])){ // Do not start/reset page timer if it is multi page form (Gravity forms))
1895
- $apbct_timestamp = time();
1896
- Cookie::set('apbct_timestamp', (string) $apbct_timestamp, 0, '/', $domain, null, true );
1897
- $cookie_test_value['cookies_names'][] = 'apbct_timestamp';
1898
- $cookie_test_value['check_value'] .= $apbct_timestamp;
1899
- }
1900
-
1901
- // Previous referer
1902
- if( Server::get( 'HTTP_REFERER' ) ){
1903
- Cookie::set('apbct_prev_referer', Server::get( 'HTTP_REFERER' ), 0, '/', $domain, null, true );
1904
- $cookie_test_value['cookies_names'][] = 'apbct_prev_referer';
1905
- $cookie_test_value['check_value'] .= apbct_get_server_variable( 'HTTP_REFERER' );
1906
- }
1907
-
1908
- // Landing time
1909
- $site_landing_timestamp = Cookie::get( 'apbct_site_landing_ts' );
1910
- if(!$site_landing_timestamp){
1911
- $site_landing_timestamp = time();
1912
- Cookie::set('apbct_site_landing_ts', (string) $site_landing_timestamp, 0, '/', $domain, null, true );
1913
- }
1914
- $cookie_test_value['cookies_names'][] = 'apbct_site_landing_ts';
1915
- $cookie_test_value['check_value'] .= $site_landing_timestamp;
1916
-
1917
- // Page hits
1918
- // Get
1919
- $page_hits = Cookie::get( 'apbct_page_hits' );
1920
- // Set / Increase
1921
- $page_hits = (int) $page_hits ? (int) $page_hits + 1 : 1;
1922
-
1923
- Cookie::set('apbct_page_hits', (string) $page_hits, 0, '/', $domain, null, true );
1924
-
1925
- $cookie_test_value['cookies_names'][] = 'apbct_page_hits';
1926
- $cookie_test_value['check_value'] .= $page_hits;
1927
-
1928
- // Cookies test
1929
- $cookie_test_value['check_value'] = md5($cookie_test_value['check_value']);
1930
- if( $apbct->settings['data__set_cookies'] == 1 ) {
1931
- Cookie::set( 'apbct_cookies_test', urlencode( json_encode( $cookie_test_value ) ), 0, '/', $domain, null, true );
1932
- }
1933
-
1934
- $apbct->flags__cookies_setuped = true;
1935
 
1936
- return $apbct->flags__cookies_setuped;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1937
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1938
  }
1939
 
1940
  /**
@@ -1945,33 +2168,32 @@ function apbct_cookie(){
1945
  */
1946
  function apbct_cookies_test()
1947
  {
1948
- global $apbct;
1949
 
1950
- if( $apbct->settings['data__set_cookies'] == 2 ){
1951
  return 1;
1952
  }
1953
 
1954
- if(isset($_COOKIE['apbct_cookies_test'])){
1955
-
1956
- $cookie_test = json_decode( urldecode( $_COOKIE['apbct_cookies_test'] ), true );
1957
 
1958
- if(!is_array($cookie_test)) {
1959
- return 0;
1960
- }
1961
 
1962
- $check_string = $apbct->api_key;
1963
- foreach($cookie_test['cookies_names'] as $cookie_name){
1964
- $check_string .= isset($_COOKIE[$cookie_name]) ? $_COOKIE[$cookie_name] : '';
1965
- }
1966
 
1967
- if($cookie_test['check_value'] == md5($check_string)){
1968
- return 1;
1969
- }
1970
 
1971
- return 0;
1972
- }
1973
 
1974
- return null;
1975
  }
1976
 
1977
  /**
@@ -1982,83 +2204,87 @@ function apbct_cookies_test()
1982
  */
1983
  function apbct_get_submit_time()
1984
  {
1985
- $apbct_timestamp = (int) Cookie::get( 'apbct_timestamp' );
1986
- return apbct_cookies_test() === 1 && $apbct_timestamp !== 0 ? time() - $apbct_timestamp : null;
 
1987
  }
1988
 
1989
  /*
1990
  * Inner function - Account status check
1991
  * Scheduled in 1800 seconds for default!
1992
  */
1993
- function ct_account_status_check($api_key = null, $process_errors = true){
1994
-
1995
- global $apbct;
1996
-
1997
- $api_key = $api_key ?: $apbct->api_key;
1998
- $result = API::method__notice_paid_till(
1999
- $api_key,
2000
- preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
2001
- ! is_main_site() && $apbct->white_label ? 'anti-spam-hosting' : 'antispam'
2002
- );
2003
-
2004
- if(empty($result['error']) || !empty($result['valid'])){
2005
-
2006
- // Notices
2007
- $apbct->data['notice_show'] = isset($result['show_notice']) ? (int)$result['show_notice'] : 0;
2008
- $apbct->data['notice_renew'] = isset($result['renew']) ? (int)$result['renew'] : 0;
2009
- $apbct->data['notice_trial'] = isset($result['trial']) ? (int)$result['trial'] : 0;
2010
- $apbct->data['notice_review'] = isset($result['show_review']) ? (int)$result['show_review'] : 0;
2011
- $apbct->data['notice_auto_update'] = isset($result['show_auto_update_notice']) ? (int)$result['show_auto_update_notice'] : 0;
2012
 
2013
- // Other
2014
- $apbct->data['service_id'] = isset($result['service_id']) ? (int)$result['service_id'] : 0;
2015
- $apbct->data['valid'] = isset($result['valid']) ? (int)$result['valid'] : 0;
2016
- $apbct->data['moderate'] = isset($result['moderate']) ? (int)$result['moderate'] : 0;
2017
- $apbct->data['ip_license'] = isset($result['ip_license']) ? (int)$result['ip_license'] : 0;
2018
- $apbct->data['moderate_ip'] = isset($result['moderate_ip'], $result['ip_license']) ? (int)$result['moderate_ip'] : 0;
2019
- $apbct->data['spam_count'] = isset($result['spam_count']) ? (int)$result['spam_count'] : 0;
2020
- $apbct->data['auto_update'] = isset($result['auto_update_app']) ? (int)$result['auto_update_app'] : 0;
2021
- $apbct->data['user_token'] = isset($result['user_token']) ? (string)$result['user_token'] : '';
2022
- $apbct->data['license_trial'] = isset($result['license_trial']) ? (int)$result['license_trial'] : 0;
2023
- $apbct->data['account_name_ob'] = isset($result['account_name_ob']) ? (string)$result['account_name_ob'] : '';
2024
 
2025
- $cron = new Cron();
2026
- $cron->updateTask('check_account_status', 'ct_account_status_check', 86400);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2027
 
2028
- $apbct->error_delete('account_check', 'save');
 
2029
 
2030
- $apbct->saveData();
2031
 
2032
- }elseif($process_errors){
2033
- $apbct->error_add('account_check', $result);
2034
- }
 
2035
 
2036
- if(!empty($result['valid'])){
2037
- $apbct->data['key_is_ok'] = true;
2038
- $result = true;
2039
- }else{
2040
- $apbct->data['key_is_ok'] = false;
2041
- $result = false;
2042
- }
2043
 
2044
- return $result;
2045
  }
2046
 
2047
- function ct_mail_send_connection_report() {
2048
-
2049
- global $apbct;
2050
 
2051
- if (($apbct->settings['misc__send_connection_reports'] == 1 && $apbct->connection_reports['negative'] > 0) || !empty($_GET['ct_send_connection_report']))
2052
- {
2053
- $to = "welcome@cleantalk.org" ;
2054
- $subject = "Connection report for " . apbct_get_server_variable( 'HTTP_HOST' );
2055
- $message = '
2056
  <html lang="en">
2057
  <head>
2058
  <title></title>
2059
  </head>
2060
  <body>
2061
- <p>From '.$apbct->connection_reports['since'].' to '.date('d M').' has been made '.($apbct->connection_reports['success']+$apbct->connection_reports['negative']).' calls, where '.$apbct->connection_reports['success'].' were success and '.$apbct->connection_reports['negative'].' were negative</p>
 
 
 
 
 
 
2062
  <p>Negative report:</p>
2063
  <table> <tr>
2064
  <td>&nbsp;</td>
@@ -2068,26 +2294,25 @@ function ct_mail_send_connection_report() {
2068
  <td><b>Server IP</b></td>
2069
  </tr>
2070
  ';
2071
- foreach ($apbct->connection_reports['negative_report'] as $key => $report)
2072
- {
2073
- $message.= '<tr>'
2074
- . '<td>'.($key+1).'.</td>'
2075
- . '<td>'.$report['date'].'</td>'
2076
- . '<td>'.$report['page_url'].'</td>'
2077
- . '<td>'.$report['lib_report'].'</td>'
2078
- . '<td>'.$report['work_url'].'</td>'
2079
- . '</tr>';
2080
- }
2081
- $message.='</table></body></html>';
2082
 
2083
- $headers = "Content-type: text/html; charset=windows-1251 \r\n";
2084
- $headers .= 'From: '.get_option('admin_email');
2085
- mail($to, $subject, $message, $headers);
2086
  }
2087
 
2088
- $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
2089
- $apbct->data['connection_reports']['since'] = date('d M');
2090
- $apbct->saveData();
2091
  }
2092
 
2093
  /**
@@ -2101,48 +2326,51 @@ function ct_mail_send_connection_report() {
2101
  */
2102
  function apbct_log($message = 'empty', $func = null, $params = array())
2103
  {
2104
- global $apbct;
2105
 
2106
- $debug = get_option( APBCT_DEBUG );
2107
 
2108
- $function = $func ?: '';
2109
- $cron = in_array('cron', $params);
2110
- $data = in_array('data', $params);
2111
- $settings = in_array('settings', $params);
2112
 
2113
- if( is_array($message) || is_object($message) ) {
2114
- $message = print_r( $message, true );
2115
- }
2116
 
2117
- if($message) {
2118
- $debug[ date( "H:i:s" ) . (int) microtime() . "_ACTION_" . current_filter() . "_FUNCTION_" . $function ] = $message;
2119
- }
2120
- if($cron) {
2121
- $debug[ date( "H:i:s" ) . (int) microtime() . "_ACTION_" . current_filter() . "_FUNCTION_" . $function . '_cron' ] = $apbct->cron;
2122
- }
2123
- if($data) {
2124
- $debug[ date( "H:i:s" ) . (int) microtime() . "_ACTION_" . current_filter() . "_FUNCTION_" . $function . '_data' ] = $apbct->data;
2125
- }
2126
- if($settings) {
2127
- $debug[ date( "H:i:s" ) . (int) microtime() . "_ACTION_" . current_filter() . "_FUNCTION_" . $function . '_settings' ] = $apbct->settings;
2128
- }
 
 
 
2129
 
2130
- update_option(APBCT_DEBUG, $debug);
2131
  }
2132
 
2133
- function apbct_sfw__delete_tables( $blog_id, $_drop ) {
2134
-
2135
- global $wpdb;
2136
 
2137
- $initial_blog = get_current_blog_id();
2138
 
2139
- switch_to_blog($blog_id);
2140
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw`;'); // Deleting SFW data
2141
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw_logs`;'); // Deleting SFW logs
2142
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_ac_log`;'); // Deleting SFW logs
2143
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_ua_bl`;'); // Deleting AC UA black lists
2144
 
2145
- switch_to_blog($initial_blog);
2146
  }
2147
 
2148
  /**
@@ -2152,15 +2380,15 @@ function apbct_sfw__delete_tables( $blog_id, $_drop ) {
2152
  *
2153
  * @return boolean
2154
  */
2155
- function apbct_is_user_enable( $user = null ) {
2156
-
2157
- global $current_user;
2158
 
2159
- $user = $user !== null ? $user : $current_user;
2160
 
2161
- return apbct_is_user_role_in(array('administrator', 'editor', 'author'), $user)
2162
- ? false
2163
- : true;
2164
  }
2165
 
2166
  /**
@@ -2171,34 +2399,34 @@ function apbct_is_user_enable( $user = null ) {
2171
  *
2172
  * @return boolean Does the user has this role|roles
2173
  */
2174
- function apbct_is_user_role_in( $roles, $user = false ){
2175
-
2176
- if( is_numeric($user) && function_exists('get_userdata')) {
2177
- $user = get_userdata( (int) $user );
2178
- }
2179
- if( is_string($user) && function_exists('get_user_by')) {
2180
- $user = get_user_by( 'login', $user );
2181
- }
2182
 
2183
- if( ! $user && function_exists('wp_get_current_user')) {
2184
- $user = wp_get_current_user();
2185
- }
2186
 
2187
- if( ! $user ) {
2188
- $user = apbct_wp_get_current_user();
2189
- }
2190
 
2191
- if( empty($user->ID) ) {
2192
- return false;
2193
- }
2194
 
2195
- foreach( (array) $roles as $role ){
2196
- if( isset($user->caps[ strtolower($role) ]) || in_array(strtolower($role), $user->roles) ) {
2197
- return true;
2198
- }
2199
- }
2200
 
2201
- return false;
2202
  }
2203
 
2204
  /**
@@ -2206,26 +2434,27 @@ function apbct_is_user_role_in( $roles, $user = false ){
2206
  *
2207
  * @param $exec_time
2208
  */
2209
- function apbct_statistics__rotate($exec_time){
2210
-
2211
- global $apbct;
2212
 
2213
- // Delete old stats
2214
- if(min(array_keys($apbct->stats['requests'])) < time() - (86400 * 7)) {
2215
- unset( $apbct->stats['requests'][ min( array_keys( $apbct->stats['requests'] ) ) ] );
2216
- }
2217
 
2218
- // Create new if newest older than 1 day
2219
- if(empty($apbct->stats['requests']) || max(array_keys($apbct->stats['requests'])) < time() - (86400 * 1)) {
2220
- $apbct->stats['requests'][ time() ] = array( 'amount' => 0, 'average_time' => 0 );
2221
- }
2222
 
2223
- // Update all existing stats
2224
- foreach($apbct->stats['requests'] as &$weak_stat){
2225
- $weak_stat['average_time'] = ($weak_stat['average_time'] * $weak_stat['amount'] + $exec_time) / ++$weak_stat['amount'];
2226
- }unset($weak_stat);
 
2227
 
2228
- $apbct->save('stats');
2229
  }
2230
 
2231
  /**
@@ -2233,58 +2462,57 @@ function apbct_statistics__rotate($exec_time){
2233
  *
2234
  * @global State $apbct
2235
  */
2236
- function apbct_update_actions(){
2237
-
2238
- global $apbct;
2239
-
2240
- // Update logic
2241
- if( $apbct->plugin_version !== APBCT_VERSION ){
2242
-
2243
- // Main blog
2244
- if(is_main_site()){
2245
-
2246
- require_once(CLEANTALK_PLUGIN_DIR.'inc/cleantalk-updater.php');
2247
 
2248
- $result = apbct_run_update_actions($apbct->plugin_version, APBCT_VERSION);
 
 
 
 
2249
 
2250
- //If update is successful
2251
- if($result === true) {
2252
- apbct_update__set_version__from_plugin( 'from_plugin' );
2253
- }
2254
 
2255
- ct_send_feedback('0:' . APBCT_AGENT ); // Send feedback to let cloud know about updated version.
 
 
 
2256
 
2257
- // Side blogs
2258
- }else{
2259
- apbct_update__set_version__from_plugin('from_plugin');
2260
- }
2261
- }
2262
 
 
 
 
 
 
2263
  }
2264
 
2265
  /**
2266
  * Set version of plugin in database
2267
  *
2268
- * @param string $ver
2269
  *
2270
  * @return bool
2271
  * @global State $apbct
2272
  *
2273
  */
2274
- function apbct_update__set_version__from_plugin($ver){
2275
- global $apbct;
2276
- switch (true){
2277
- case $ver === 'from_plugin':
2278
- $apbct->data['plugin_version'] = APBCT_VERSION;
2279
- break;
2280
- case preg_match('/^\d+\.\d+(\.\d+)?(-[a-zA-Z0-9-_]+)?$/', $ver) === 1;
2281
- $apbct->data['plugin_version'] = $ver;
2282
- break;
2283
- default:
2284
- return false;
2285
- }
2286
- $apbct->saveData();
2287
- return true;
 
 
2288
  }
2289
 
2290
  /**
@@ -2292,20 +2520,19 @@ function apbct_update__set_version__from_plugin($ver){
2292
  *
2293
  * @return array
2294
  */
2295
- function apbct_test_connection(){
2296
-
2297
- $out = array();
2298
- $url_to_test = array_keys( \Cleantalk\Common\Helper::$cleantalks_servers );
2299
-
2300
- foreach($url_to_test as $url){
2301
 
2302
- $start = microtime(true);
2303
- $result = \Cleantalk\ApbctWP\Helper::http__request__get_content($url);
 
2304
 
2305
  $out[$url] = array(
2306
- 'result' => !empty($result['error']) ? $result['error'] : 'OK',
2307
  'exec_time' => microtime(true) - $start,
2308
- ) ;
2309
  }
2310
 
2311
  return $out;
1
  <?php
2
+
3
  /*
4
  Plugin Name: Anti-Spam by CleanTalk
5
  Plugin URI: https://cleantalk.org
6
  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.
7
+ Version: 5.162
8
  Author: СleanTalk <welcome@cleantalk.org>
9
  Author URI: https://cleantalk.org
10
  Text Domain: cleantalk-spam-protect
16
  use Cleantalk\ApbctWP\API;
17
  use Cleantalk\ApbctWP\CleantalkUpgrader;
18
  use Cleantalk\ApbctWP\CleantalkUpgraderSkin;
19
+ use Cleantalk\ApbctWP\CleantalkUpgraderSkinDeprecated;
20
  use Cleantalk\ApbctWP\Cron;
21
  use Cleantalk\ApbctWP\DB;
22
  use Cleantalk\ApbctWP\Deactivator;
39
  $cleantalk_executed = false;
40
 
41
  // Getting version form main file (look above)
42
+ $plugin_info = get_file_data(__FILE__, array('Version' => 'Version', 'Name' => 'Plugin Name',));
43
  $plugin_version__agent = $plugin_info['Version'];
44
  // Converts xxx.xxx.xx-dev to xxx.xxx.2xx
45
  // And xxx.xxx.xx-fix to xxx.xxx.1xx
46
+ if ( preg_match('@^(\d+)\.(\d+)\.(\d{1,2})-(dev|fix)$@', $plugin_version__agent, $m) ) {
47
+ $plugin_version__agent =
48
+ $m[1]
49
+ . '.'
50
+ . $m[2]
51
+ . '.'
52
+ . ($m[4] === 'dev' ? '2' : '1')
53
+ . str_pad($m[3], 2, '0', STR_PAD_LEFT);
54
  }
55
 
56
  // Common params
57
+ define('APBCT_NAME', $plugin_info['Name']);
58
+ define('APBCT_VERSION', $plugin_info['Version']);
59
+ define('APBCT_URL_PATH', plugins_url('', __FILE__)); //HTTP path. Plugin root folder without '/'.
60
+ define('APBCT_DIR_PATH', dirname(__FILE__) . '/'); //System path. Plugin root folder with '/'.
61
  define('APBCT_PLUGIN_BASE_NAME', plugin_basename(__FILE__)); //Plugin base name.
62
+ define(
63
+ 'APBCT_CASERT_PATH',
64
+ file_exists(ABSPATH . WPINC . '/certificates/ca-bundle.crt') ? ABSPATH . WPINC . '/certificates/ca-bundle.crt' : ''
65
+ ); // SSL Serttificate path
66
 
67
  // API params
68
+ define('APBCT_AGENT', 'wordpress-' . $plugin_version__agent);
69
  define('APBCT_MODERATE_URL', 'https://moderate.cleantalk.org'); //Api URL
70
 
71
  // Option names
72
+ define('APBCT_DATA', 'cleantalk_data'); //Option name with different plugin data.
73
+ define('APBCT_SETTINGS', 'cleantalk_settings'); //Option name with plugin settings.
74
  define('APBCT_NETWORK_SETTINGS', 'cleantalk_network_settings'); //Option name with plugin network settings.
75
+ define('APBCT_DEBUG', 'cleantalk_debug'); //Option name with a debug data. Empty by default.
76
 
77
  // Multisite
78
  define('APBCT_WPMS', (is_multisite() ? true : false)); // WMPS is enabled
80
  // Different params
81
  define('APBCT_REMOTE_CALL_SLEEP', 5); // Minimum time between remote call
82
 
83
+ if ( ! defined('CLEANTALK_PLUGIN_DIR') ) {
84
+ define('CLEANTALK_PLUGIN_DIR', dirname(__FILE__) . '/');
85
  }
86
 
87
  // PHP functions patches
98
 
99
  $apbct->base_name = 'cleantalk-spam-protect/cleantalk.php';
100
 
101
+ $apbct->plugin_request_id = md5(microtime()); // Identify plugin execution
102
 
103
  $apbct->logo = plugin_dir_url(__FILE__) . 'inc/images/logo.png';
104
  $apbct->logo__small = plugin_dir_url(__FILE__) . 'inc/images/logo_small.png';
110
  $apbct->white_label = $apbct->network_settings['multisite__white_label'];
111
  $apbct->allow_custom_key = $apbct->network_settings['multisite__work_mode'] != 2;
112
  $apbct->plugin_name = $apbct->network_settings['multisite__white_label__plugin_name'] ? $apbct->network_settings['multisite__white_label__plugin_name'] : APBCT_NAME;
113
+ $apbct->api_key = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->settings['apikey'] : $apbct->network_settings['apikey'];
114
+ $apbct->key_is_ok = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['key_is_ok'] : $apbct->network_data['key_is_ok'];
115
+ $apbct->moderate = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['moderate'] : $apbct->network_data['moderate'];
116
 
117
+ $apbct->data['user_counter']['since'] = isset($apbct->data['user_counter']['since']) ? $apbct->data['user_counter']['since'] : date(
118
+ 'd M'
119
+ );
120
+ $apbct->data['connection_reports']['since'] = isset($apbct->data['connection_reports']['since']) ? $apbct->data['user_counter']['since'] : date(
121
+ 'd M'
122
+ );
123
 
124
+ $apbct->firewall_updating = (bool)$apbct->fw_stats['firewall_updating_id'];
125
 
126
  $apbct->settings_link = is_network_admin() ? 'settings.php?page=cleantalk' : 'options-general.php?page=cleantalk';
127
 
128
+ if ( ! $apbct->white_label ) {
129
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalkWidget.php');
130
  }
131
 
132
  // Disabling comments
133
+ if ( $apbct->settings['comments__disable_comments__all'] || $apbct->settings['comments__disable_comments__posts'] || $apbct->settings['comments__disable_comments__pages'] || $apbct->settings['comments__disable_comments__media'] ) {
134
+ \Cleantalk\Antispam\DisableComments::getInstance();
135
  }
136
 
137
+ add_action('rest_api_init', 'apbct_register_my_rest_routes');
138
+ function apbct_register_my_rest_routes()
139
+ {
140
+ $controller = new RestController();
141
+ $controller->register_routes();
142
+ }
143
+
144
+ // Alt cookies via WP ajax handler
145
+ add_action('wp_ajax_nopriv_apbct_alt_session__save__AJAX', 'apbct_alt_session__save__WP_AJAX');
146
+ add_action('wp_ajax_apbct_alt_session__save__AJAX', 'apbct_alt_session__save__WP_AJAX');
147
+ function apbct_alt_session__save__WP_AJAX()
148
+ {
149
+ Cleantalk\ApbctWP\Variables\AltSessions::setFromRemote();
150
  }
151
 
152
  // Database prefix
153
  global $wpdb;
154
+ $apbct->db_prefix = ! APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $wpdb->prefix : $wpdb->base_prefix;
155
+ $apbct->db_prefix = ! $apbct->white_label && defined('CLEANTALK_ACCESS_KEY') ? $wpdb->base_prefix : $wpdb->prefix;
156
 
157
  // Set some defines
158
  State::setDefinitions();
159
 
160
  /** @todo HARDCODE FIX */
161
+ if ( $apbct->plugin_version === '1.0.0' ) {
162
+ $apbct->plugin_version = '5.100';
163
+ }
164
 
165
  // Do update actions if version is changed
166
  apbct_update_actions();
167
 
168
+ add_action('init', function () {
169
+ global $apbct;
170
+ // Self cron
171
+ $ct_cron = new Cron();
172
+ $tasks_to_run = $ct_cron->checkTasks(); // Check for current tasks. Drop tasks inner counters.
173
+ if (
174
+ $tasks_to_run && // There is tasks to run
175
+ ! RemoteCalls::check() && // Do not do CRON in remote call action
176
+ (
177
+ ! defined('DOING_CRON') ||
178
+ (defined('DOING_CRON') && DOING_CRON !== true)
179
+ )
180
+ ) {
181
+ $cron_res = $ct_cron->runTasks($tasks_to_run);
182
+ if ( is_array($cron_res) ) {
183
+ foreach ( $cron_res as $task => $res ) {
184
+ if ( $res === true ) {
185
+ $apbct->errorDelete($task, 'save_data', 'cron');
186
+ } else {
187
+ $apbct->errorAdd($task, $res, 'cron');
188
+ }
189
+ }
190
+ }
191
  }
192
+ });
193
 
194
  //Delete cookie for admin trial notice
195
  add_action('wp_logout', 'apbct__hook__wp_logout__delete_trial_notice_cookie');
196
 
197
  // Set cookie only for public pages and for non-AJAX requests
198
+ if ( ! is_admin() && ! apbct_is_ajax() && ! defined('DOING_CRON')
199
+ && empty($_POST['ct_checkjs_register_form']) // Buddy press registration fix
200
+ && empty($_GET['ct_checkjs_search_default']) // Search form fix
201
+ && empty($_POST['action']) //bbPress
202
+ ) {
203
+ add_action('template_redirect', 'apbct_cookie', 2);
204
+ add_action('template_redirect', 'apbct_store__urls', 2);
205
+ if ( empty($_POST) && empty($_GET) ) {
206
+ apbct_cookie();
207
+ apbct_store__urls();
208
+ }
209
  }
210
 
211
  // Early checks
212
 
213
  // Iphorm
214
+ if ( isset($_POST['iphorm_ajax'], $_POST['iphorm_id'], $_POST['iphorm_uid']) ) {
215
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
216
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
217
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
218
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
219
+ ct_ajax_hook();
220
  }
221
 
222
  // Facebook
223
+ if ( $apbct->settings['forms__general_contact_forms_test'] == 1
224
+ && ( ! empty($_POST['action']) && $_POST['action'] === 'fb_intialize')
225
+ && ! empty($_POST['FB_userdata'])
226
+ ) {
227
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
228
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
229
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
230
+ if ( apbct_is_user_enable() ) {
231
+ ct_registration_errors(null);
232
+ }
 
233
  }
234
 
235
  $apbct_active_integrations = array(
236
+ 'ContactBank' => array(
237
+ 'hook' => 'contact_bank_frontend_ajax_call',
238
+ 'setting' => 'forms__contact_forms_test',
239
+ 'ajax' => true
240
+ ),
241
+ 'FluentForm' => array(
242
+ 'hook' => 'fluentform_before_insert_submission',
243
+ 'setting' => 'forms__contact_forms_test',
244
+ 'ajax' => false
245
+ ),
246
+ 'ElfsightContactForm' => array(
247
+ 'hook' => 'elfsight_contact_form_mail',
248
+ 'setting' => 'forms__contact_forms_test',
249
+ 'ajax' => true
250
+ ),
251
+ 'EstimationForm' => array('hook' => 'send_email', 'setting' => 'forms__contact_forms_test', 'ajax' => true),
252
+ 'LandingPageBuilder' => array(
253
+ 'hook' => 'ulpb_formBuilderEmail_ajax',
254
+ 'setting' => 'forms__contact_forms_test',
255
+ 'ajax' => true
256
+ ),
257
+ 'Rafflepress' => array(
258
+ 'hook' => 'rafflepress_lite_giveaway_api',
259
+ 'setting' => 'forms__contact_forms_test',
260
+ 'ajax' => true
261
+ ),
262
+ 'SimpleMembership' => array(
263
+ 'hook' => 'swpm_front_end_registration_complete_user_data',
264
+ 'setting' => 'forms__registrations_test',
265
+ 'ajax' => false
266
+ ),
267
+ 'WpMembers' => array(
268
+ 'hook' => 'wpmem_pre_register_data',
269
+ 'setting' => 'forms__registrations_test',
270
+ 'ajax' => false
271
+ ),
272
+ 'Wpdiscuz' => array(
273
+ 'hook' => array('wpdAddComment', 'wpdAddInlineComment'),
274
+ 'setting' => 'forms__comments_test',
275
+ 'ajax' => true
276
+ ),
277
+ 'Forminator' => array(
278
+ 'hook' => 'forminator_submit_form_custom-forms',
279
+ 'setting' => 'forms__contact_forms_test',
280
+ 'ajax' => true
281
+ ),
282
+ 'HappyForm' => array(
283
+ 'hook' => 'happyforms_validate_submission',
284
+ 'setting' => 'forms__contact_forms_test',
285
+ 'ajax' => false
286
+ ),
287
+ 'EaelLoginRegister' => array(
288
+ 'hook' => array(
289
+ 'eael/login-register/before-register',
290
+ 'wp_ajax_nopriv_eael/login-register/before-register',
291
+ 'wp_ajax_eael/login-register/before-register'
292
+ ),
293
+ 'setting' => 'forms__registrations_test',
294
+ 'ajax' => false
295
+ ),
296
  );
297
+ new \Cleantalk\Antispam\Integrations($apbct_active_integrations, (array)$apbct->settings);
298
 
299
  // Ninja Forms. Making GET action to POST action
300
+ if (
301
+ apbct_is_in_uri('admin-ajax.php') &&
302
+ sizeof($_POST) > 0 &&
303
+ isset($_GET['action']) &&
304
+ $_GET['action'] === 'ninja_forms_ajax_submit'
305
+ ) {
306
+ $_POST['action'] = 'ninja_forms_ajax_submit';
307
+ }
308
 
309
+ add_action('wp_ajax_nopriv_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
310
+ add_action('wp_ajax_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
311
+ add_action('wp_ajax_nopriv_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
312
+ add_action('wp_ajax_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
313
+ add_action('ninja_forms_process', 'apbct_form__ninjaForms__testSpam', 1); // Depricated ?
314
 
315
  // SeedProd Coming Soon Page Pro integration
316
+ add_action('wp_ajax_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
317
+ add_action('wp_ajax_nopriv_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
318
+ add_action('wp_ajax_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
319
+ add_action('wp_ajax_nopriv_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1);
320
 
321
  // The 7 theme contact form integration
322
+ add_action('wp_ajax_nopriv_dt_send_mail', 'apbct_form__the7_contact_form', 1);
323
+ add_action('wp_ajax_dt_send_mail', 'apbct_form__the7_contact_form', 1);
324
 
325
  // Elementor Pro page builder forms
326
+ add_action('wp_ajax_elementor_pro_forms_send_form', 'apbct_form__elementor_pro__testSpam');
327
+ add_action('wp_ajax_nopriv_elementor_pro_forms_send_form', 'apbct_form__elementor_pro__testSpam');
328
 
329
  // Custom register form (ticket_id=13668)
330
+ add_action('website_neotrends_signup_fields_check', function ($username, $fields) {
331
+ $ip = Helper::ipGet('real', false);
332
+ $ct_result = ct_test_registration($username, $fields['email'], $ip);
333
+ if ( $ct_result['allow'] == 0 ) {
334
+ ct_die_extended($ct_result['comment']);
335
  }
336
  }, 1, 2);
337
 
338
  // INEVIO theme integration
339
+ add_action('wp_ajax_contact_form_handler', 'apbct_form__inevio__testSpam', 1);
340
+ add_action('wp_ajax_nopriv_contact_form_handler', 'apbct_form__inevio__testSpam', 1);
341
 
342
  // Enfold Theme contact form
343
+ add_filter('avf_form_send', 'apbct_form__enfold_contact_form__test_spam', 4, 10);
344
 
345
  // Profile Builder integration
346
+ add_filter('wppb_output_field_errors_filter', 'apbct_form_profile_builder__check_register', 1, 3);
347
 
348
  // WP Foro register system integration
349
+ add_filter('wpforo_create_profile', 'wpforo_create_profile__check_register', 1, 1);
350
 
351
  // Public actions
352
+ if ( ! is_admin() && ! apbct_is_ajax() && ! apbct_is_customize_preview() ) {
353
+ // Default search
354
+ //add_filter( 'get_search_form', 'apbct_forms__search__addField' );
355
+ add_filter('get_search_query', 'apbct_forms__search__testSpam');
356
+ add_action('wp_head', 'apbct_search_add_noindex', 1);
357
+
358
+ // Remote calls
359
+ if ( RemoteCalls::check() ) {
 
360
  RemoteCalls::perform();
 
 
 
 
 
 
 
 
 
 
 
 
361
  }
362
 
363
+ // SpamFireWall check
364
+ if ( $apbct->plugin_version == APBCT_VERSION && // Do not call with first start
365
+ $apbct->settings['sfw__enabled'] == 1 &&
366
+ apbct_is_get() &&
367
+ ! apbct_wp_doing_cron() &&
368
+ ! \Cleantalk\Variables\Server::inUri('/favicon.ico') &&
369
+ ! apbct_is_cli()
370
+ ) {
371
+ wp_suspend_cache_addition(true);
372
+ apbct_sfw__check();
373
+ wp_suspend_cache_addition(false);
374
+ }
375
  }
376
 
377
  // Activation/deactivation functions must be in main plugin file.
378
  // http://codex.wordpress.org/Function_Reference/register_activation_hook
379
+ register_activation_hook(__FILE__, 'apbct_activation');
380
+ function apbct_activation($network_wide)
381
+ {
382
+ Activator::activation($network_wide);
383
  }
384
+
385
+ register_deactivation_hook(__FILE__, 'apbct_deactivation');
386
+ function apbct_deactivation($network_wide)
387
+ {
388
+ Deactivator::deactivation($network_wide);
389
  }
390
+
391
  // Hook for newly added blog
392
  add_action('wpmu_new_blog', 'apbct_activation__new_blog', 10, 6);
393
+ function apbct_activation__new_blog($blog_id, $_user_id, $_domain, $_path, $_site_id, $_meta)
394
+ {
395
+ Activator::activation(false, $blog_id);
396
  }
397
 
398
  // Async loading for JavaScript
399
  add_filter('script_loader_tag', 'apbct_add_async_attribute', 10, 3);
400
 
401
  // Redirect admin to plugin settings.
402
+ if ( ! defined('WP_ALLOW_MULTISITE') || (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == false) ) {
403
  add_action('admin_init', 'apbct_plugin_redirect');
404
+ }
405
 
406
  // Deleting SFW tables when deleting websites
407
+ if ( defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE === true ) {
408
+ add_action('delete_blog', 'apbct_sfw__delete_tables', 10, 2);
409
+ }
410
 
411
  // After plugin loaded - to load locale as described in manual
412
+ add_action('plugins_loaded', 'apbct_plugin_loaded');
413
 
414
+ if ( ! empty($apbct->settings['data__use_ajax']) &&
415
+ ! apbct_is_in_uri('.xml') &&
416
+ ! apbct_is_in_uri('.xsl') ) {
417
+ add_action('wp_ajax_nopriv_ct_get_cookie', 'ct_get_cookie', 1);
418
+ add_action('wp_ajax_ct_get_cookie', 'ct_get_cookie', 1);
 
419
  }
420
 
421
  // Admin panel actions
422
+ if ( is_admin() || is_network_admin() ) {
423
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-find-spam.php');
424
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-admin.php');
425
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-settings.php');
 
426
 
427
+ add_action('admin_init', 'apbct_admin__init', 1);
428
 
429
  // Show notices
430
+ add_action('admin_init', array(AdminNotices::class, 'showAdminNotices'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
431
 
432
+ if ( ! (defined('DOING_AJAX') && DOING_AJAX) ) {
433
+ add_action('admin_enqueue_scripts', 'apbct_admin__enqueue_scripts');
 
 
434
 
435
+ add_action('admin_menu', 'apbct_settings_add_page');
436
+ add_action('network_admin_menu', 'apbct_settings_add_page');
 
 
 
 
 
437
 
438
+ //Show widget only if enables and not IP license
439
+ if ( $apbct->settings['wp__dashboard_widget__show'] && ! $apbct->moderate_ip ) {
440
+ add_action('wp_dashboard_setup', 'ct_dashboard_statistics_widget');
441
+ }
442
+ }
443
 
444
+ if ( apbct_is_ajax() || isset($_POST['cma-action']) ) {
445
+ $_cleantalk_hooked_actions = array();
446
+ $_cleantalk_ajax_actions_to_check = array();
 
 
 
 
 
 
 
 
447
 
448
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
449
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
450
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
451
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
452
 
453
+ // Feedback for comments
454
+ if ( isset($_POST['action']) && $_POST['action'] == 'ct_feedback_comment' ) {
455
+ add_action('wp_ajax_nopriv_ct_feedback_comment', 'apbct_comment__send_feedback', 1);
456
+ add_action('wp_ajax_ct_feedback_comment', 'apbct_comment__send_feedback', 1);
457
+ }
458
+ if ( isset($_POST['action']) && $_POST['action'] == 'ct_feedback_user' ) {
459
+ add_action('wp_ajax_nopriv_ct_feedback_user', 'apbct_user__send_feedback', 1);
460
+ add_action('wp_ajax_ct_feedback_user', 'apbct_user__send_feedback', 1);
461
+ }
462
 
463
+ // Check AJAX requests
464
+ // if User is not logged in
465
+ // if Unknown action or Known action with mandatory check
466
+ if (
467
+ ( ! apbct_is_user_logged_in() || $apbct->settings['data__protect_logged_in'] == 1) &&
468
+ isset($_POST['action']) &&
469
+ (
470
+ ! in_array($_POST['action'], $_cleantalk_hooked_actions) ||
471
+ in_array($_POST['action'], $_cleantalk_ajax_actions_to_check)
472
+ ) &&
473
+ ! in_array($_POST['action'], array_column($apbct_active_integrations, 'hook'))
474
+ ) {
475
+ ct_ajax_hook();
476
+ }
477
 
478
+ //QAEngine Theme answers
479
+ if ( intval($apbct->settings['forms__general_contact_forms_test']) ) {
480
+ add_filter('et_pre_insert_question', 'ct_ajax_hook', 1, 1);
481
+ } // Questions
482
+ add_filter('et_pre_insert_answer', 'ct_ajax_hook', 1, 1); // Answers
483
 
484
+ // Formidable
485
+ add_filter('frm_entries_before_create', 'apbct_form__formidable__testSpam', 10, 2);
486
+ add_action('frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2);
487
 
488
+ // Some of plugins to register a users use AJAX context.
489
+ add_filter('registration_errors', 'ct_registration_errors', 1, 3);
490
+ add_filter('registration_errors', 'ct_check_registration_erros', 999999, 3);
491
+ add_action('user_register', 'apbct_user_register');
492
+
493
+ if ( class_exists('BuddyPress') ) {
494
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
495
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
496
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
497
+ add_filter(
498
+ 'bp_activity_is_spam_before_save',
499
+ 'apbct_integration__buddyPres__activityWall',
500
+ 999,
501
+ 2
502
+ ); /* ActivityWall */
503
+ add_action('bp_locate_template', 'apbct_integration__buddyPres__getTemplateName', 10, 6);
504
+ }
505
+ }
506
 
507
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
508
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
509
  require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
510
+ //Bitrix24 contact form
511
+ if ( $apbct->settings['forms__general_contact_forms_test'] == 1 &&
512
+ ! empty($_POST['your-phone']) &&
513
+ ! empty($_POST['your-email']) &&
514
+ ! empty($_POST['your-message'])
515
+ ) {
516
+ ct_contact_form_validate();
517
+ }
518
 
519
+ // Sends feedback to the cloud about comments
520
+ // add_action('wp_set_comment_status', 'ct_comment_send_feedback', 10, 2);
521
 
522
+ // Sends feedback to the cloud about deleted users
523
+ if ( $pagenow === 'users.php' ) {
524
+ add_action('delete_user', 'apbct_user__delete__hook', 10, 2);
525
+ }
526
 
527
+ if ( $pagenow === 'plugins.php' || apbct_is_in_uri('plugins.php') ) {
528
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'apbct_admin__plugin_action_links', 10, 2);
529
+ add_filter(
530
+ 'network_admin_plugin_action_links_' . plugin_basename(__FILE__),
531
+ 'apbct_admin__plugin_action_links',
532
+ 10,
533
+ 2
534
+ );
535
 
536
+ add_filter('plugin_row_meta', 'apbct_admin__register_plugin_links', 10, 2);
 
 
 
537
  }
538
+ // Public pages actions
539
+ } else {
540
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
541
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
542
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
543
 
544
+ add_action('wp_enqueue_scripts', 'ct_enqueue_scripts_public');
 
 
545
 
546
+ // Init action.
547
+ add_action('plugins_loaded', 'apbct_init', 1);
548
 
549
+ // Comments
550
+ add_filter('preprocess_comment', 'ct_preprocess_comment', 1, 1); // param - comment data array
551
+ add_filter('comment_text', 'ct_comment_text');
552
+ add_filter('wp_die_handler', 'apbct_comment__sanitize_data__before_wp_die', 1); // Check comments after validation
553
 
554
+ // Registrations
555
+ if ( ! isset($_POST['wp-submit']) ) {
556
+ add_action('login_form_register', 'apbct_cookie');
557
+ add_action('login_form_register', 'apbct_store__urls');
558
+ }
559
+ add_action('login_enqueue_scripts', 'apbct_login__scripts');
560
+ add_action('register_form', 'ct_register_form');
561
+ add_filter('registration_errors', 'ct_registration_errors', 1, 3);
562
+ add_filter('registration_errors', 'ct_check_registration_erros', 999999, 3);
563
+ add_action('user_register', 'apbct_user_register');
564
+
565
+ // Multisite registrations
566
+ add_action('signup_extra_fields', 'ct_register_form');
567
+ add_filter('wpmu_validate_user_signup', 'ct_registration_errors_wpmu', 10, 3);
568
+
569
+ // Login form - for notifications only
570
+ add_filter('login_message', 'ct_login_message');
571
+
572
+ // Comments output hook
573
+ add_filter('wp_list_comments_args', 'ct_wp_list_comments_args');
574
+
575
+ // Ait-Themes fix
576
+ if ( isset($_GET['ait-action']) && $_GET['ait-action'] === 'register' ) {
577
+ $tmp = $_POST['redirect_to'];
578
+ unset($_POST['redirect_to']);
579
+ ct_contact_form_validate();
580
+ $_POST['redirect_to'] = $tmp;
581
+ }
582
  }
583
 
584
  // Short code for GDPR
585
+ if ( $apbct->settings['gdpr__enabled'] ) {
586
+ add_shortcode('cleantalk_gdpr_form', 'apbct_shrotcode_handler__GDPR_public_notice__form');
587
+ }
588
 
589
  /**
590
+ * Function for SpamFireWall check
591
+ */
592
  function apbct_sfw__check()
593
  {
594
+ global $apbct, $spbc, $cleantalk_url_exclusions;
595
+
596
+ // Turn off the SpamFireWall if current url in the exceptions list and WordPress core pages
597
+ if ( ! empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions) ) {
598
+ $core_page_to_skip_check = array('/feed');
599
+ foreach ( array_merge($cleantalk_url_exclusions, $core_page_to_skip_check) as $v ) {
600
+ if ( apbct_is_in_uri($v) ) {
601
+ return;
602
+ }
603
+ }
604
+ }
605
+
606
+ // Skip the check
607
+ if ( ! empty($_GET['access']) ) {
608
+ $spbc_settings = get_option('spbc_settings');
609
+ $spbc_key = ! empty($spbc_settings['spbc_key']) ? $spbc_settings['spbc_key'] : false;
610
+ if ( $_GET['access'] === $apbct->api_key || ($spbc_key !== false && $_GET['access'] === $spbc_key) ) {
611
+ \Cleantalk\Variables\Cookie::set(
612
+ 'spbc_firewall_pass_key',
613
+ md5(apbct_get_server_variable('REMOTE_ADDR') . $spbc_key),
614
+ time() + 1200,
615
+ '/',
616
+ ''
617
+ );
618
+ \Cleantalk\Variables\Cookie::set(
619
+ 'ct_sfw_pass_key',
620
+ md5(apbct_get_server_variable('REMOTE_ADDR') . $apbct->api_key),
621
+ time() + 1200,
622
+ '/',
623
+ ''
624
+ );
625
+
626
+ return;
627
+ }
628
+ unset($spbc_settings, $spbc_key);
629
+ }
630
+
631
+ // Turn off the SpamFireWall if Remote Call is in progress
632
+ if ( $apbct->rc_running || ( ! empty($spbc) && $spbc->rc_running) ) {
633
  return;
634
  }
635
 
636
+ // update mode - skip checking
637
+ if ( isset($apbct->fw_stats['update_mode']) && $apbct->fw_stats['update_mode'] === 1 ) {
638
+ return;
639
+ }
640
+
641
+ $firewall = new Firewall(
642
+ DB::getInstance()
643
+ );
644
+
645
+ $firewall->loadFwModule(
646
+ new SFW(
647
+ APBCT_TBL_FIREWALL_LOG,
648
+ APBCT_TBL_FIREWALL_DATA,
649
+ array(
650
+ 'sfw_counter' => $apbct->settings['admin_bar__sfw_counter'],
651
+ 'api_key' => $apbct->api_key,
652
+ 'apbct' => $apbct,
653
+ 'cookie_domain' => parse_url(get_option('siteurl'), PHP_URL_HOST),
654
+ 'data__set_cookies' => $apbct->settings['data__set_cookies'],
655
+ )
656
+ )
657
+ );
658
+
659
+ if ( $apbct->settings['sfw__anti_crawler'] && $apbct->stats['sfw']['entries'] > 50 && $apbct->settings['data__set_cookies'] != 0 ) {
660
+ $firewall->loadFwModule(
661
+ new \Cleantalk\ApbctWP\Firewall\AntiCrawler(
662
+ APBCT_TBL_FIREWALL_LOG,
663
+ APBCT_TBL_AC_LOG,
664
+ array(
665
+ 'api_key' => $apbct->api_key,
666
+ 'apbct' => $apbct,
667
+ )
668
+ )
669
+ );
670
+ }
671
+
672
+ if ( $apbct->settings['sfw__anti_flood'] && is_null(apbct_wp_get_current_user()) ) {
673
+ $firewall->loadFwModule(
674
+ new AntiFlood(
675
+ APBCT_TBL_FIREWALL_LOG,
676
+ APBCT_TBL_AC_LOG,
677
+ array(
678
+ 'api_key' => $apbct->api_key,
679
+ 'view_limit' => $apbct->settings['sfw__anti_flood__view_limit'],
680
+ 'apbct' => $apbct,
681
+ )
682
+ )
683
+ );
684
+ }
685
 
686
+ $firewall->run();
687
  }
688
 
689
  /**
695
  * @return void
696
  * @depreacted Use Activator::create_tables() instead
697
  */
698
+ function apbct_activation__create_tables($sqls, $db_prefix = '')
699
+ {
700
+ Activator::createTables($sqls, $db_prefix);
701
  }
702
 
703
  /**
706
  */
707
  function apbct_plugin_redirect()
708
  {
709
+ global $apbct;
710
+ if ( get_option('ct_plugin_do_activation_redirect', false) && ! isset($_GET['activate-multi']) ) {
711
+ delete_option('ct_plugin_do_activation_redirect');
712
  ct_account_status_check(null, false);
713
+ apbct_sfw_update__init(3); // Updating SFW
714
+ wp_redirect($apbct->settings_link);
715
+ }
716
  }
717
 
718
  /**
719
  * @param $event_type
720
+ *
721
  * @psalm-suppress UnusedVariable
722
  */
723
  function ct_add_event($event_type)
724
  {
725
+ global $apbct, $cleantalk_executed;
726
 
727
  //
728
  // To migrate on the new version of ct_add_event().
729
  //
730
+ switch ( $event_type ) {
731
+ case '0':
732
+ $event_type = 'no';
733
+ break;
734
+ case '1':
735
+ $event_type = 'yes';
736
+ break;
737
  }
738
 
739
+ $current_hour = (int)date('G');
740
 
741
+ // Updating current hour
742
+ if ( $current_hour != $apbct->data['current_hour'] ) {
743
+ $apbct->data['current_hour'] = $current_hour;
744
+ $apbct->data['array_accepted'][$current_hour] = 0;
745
+ $apbct->data['array_blocked'][$current_hour] = 0;
746
+ }
747
 
748
+ //Add 1 to counters
749
+ if ( $event_type === 'yes' ) {
750
+ $apbct->data['array_accepted'][$current_hour]++;
751
+ $apbct->data['admin_bar__all_time_counter']['accepted']++;
752
+ $apbct->data['user_counter']['accepted']++;
753
+ }
754
+ if ( $event_type === 'no' ) {
755
+ $apbct->data['array_blocked'][$current_hour]++;
756
+ $apbct->data['admin_bar__all_time_counter']['blocked']++;
757
+ $apbct->data['user_counter']['blocked']++;
758
+ }
759
 
760
+ $apbct->saveData();
761
 
762
+ $cleantalk_executed = true;
763
  }
764
 
765
  /**
767
  */
768
  function ct_get_cookie()
769
  {
770
+ $ct_checkjs_key = ct_get_checkjs_value();
771
+ print $ct_checkjs_key;
772
+ die();
773
  }
774
 
775
  // Clears
776
+ function apbct_sfw__clear()
777
+ {
778
  global $apbct, $wpdb;
779
 
780
+ $wpdb->query('DELETE FROM ' . APBCT_TBL_FIREWALL_DATA . ';');
781
 
782
  $apbct->stats['sfw']['entries'] = 0;
783
  $apbct->save('stats');
 
784
  }
785
 
786
  // This action triggered by wp_schedule_single_event( time() + 900, 'ct_sfw_update' );
787
+ add_action('apbct_sfw_update__init', 'apbct_sfw_update__init');
788
 
789
  /**
790
  * Called by sfw_update remote call
794
  *
795
  * @return bool|string|string[]
796
  */
797
+ function apbct_sfw_update__init($delay = 0)
798
+ {
799
  global $apbct;
800
 
801
  // Prevent start an update if update is already running and started less than 10 minutes ago
802
+ if (
803
  $apbct->fw_stats['firewall_updating_id'] &&
804
  time() - $apbct->fw_stats['firewall_updating_last_start'] < 600 &&
805
+ apbct_sfw_update__is_in_progress()
806
+ ) {
807
  return false;
808
  }
809
 
810
+ if ( ! $apbct->settings['sfw__enabled'] ) {
811
+ return false;
812
  }
813
 
814
  // Key is empty
815
+ if ( ! $apbct->api_key && ! $apbct->ip_license ) {
816
+ return array('error' => 'SFW UPDATE INIT: KEY_IS_EMPTY');
817
  }
818
 
819
+ if ( ! $apbct->data['key_is_ok'] ) {
820
+ return array('error' => 'SFW UPDATE INIT: KEY_IS_NOT_VALID');
821
  }
822
 
823
  $apbct->fw_stats['updating_folder'] = APBCT_DIR_PATH . DIRECTORY_SEPARATOR . 'fw_files_for_blog_' . get_current_blog_id() . DIRECTORY_SEPARATOR;
824
 
825
  $prepare_dir__result = apbct_prepare_upd_dir();
826
+ if ( ! empty($prepare_dir__result['error']) ) {
827
+ return apbct_sfw_direct_update();
828
  }
829
 
830
  // Set a new update ID and an update time start
831
+ $apbct->fw_stats['calls'] = 0;
832
+ $apbct->fw_stats['firewall_updating_id'] = md5((string)rand(0, 100000));
833
  $apbct->fw_stats['firewall_updating_last_start'] = time();
834
+ $apbct->save('fw_stats');
835
 
836
+ // Delete update errors
837
+ $apbct->errorDelete('sfw_update', 'save_data');
838
+ $apbct->errorDelete('sfw_update', 'save_data', 'cron');
839
 
840
  \Cleantalk\ApbctWP\Queue::clearQueue();
841
 
842
+ $queue = new \Cleantalk\ApbctWP\Queue();
843
+ $queue->addStage('apbct_sfw_update__get_multifiles');
844
 
845
+ $cron = new Cron();
846
+ $cron->addTask('sfw_update_checker', 'apbct_sfw_update__checker', 15);
847
 
848
+ return Helper::httpRequestRcToHost(
849
  'sfw_update__worker',
850
+ array(
851
  'firewall_updating_id' => $apbct->fw_stats['firewall_updating_id'],
852
+ 'delay' => $delay
853
  ),
854
+ array('async')
855
+ );
856
  }
857
 
858
  /**
867
  *
868
  * @return array|bool|int|string|string[]
869
  */
870
+ function apbct_sfw_update__worker($checker_work = false)
871
+ {
872
  global $apbct;
873
 
874
+ usleep(10000);
875
 
876
+ if ( ! $apbct->data['key_is_ok'] ) {
877
+ return array('error' => 'Worker: KEY_IS_NOT_VALID');
878
  }
879
 
880
+ if ( ! $checker_work ) {
881
+ if (
882
+ Get::equal('firewall_updating_id', '') ||
883
+ ! Get::equal('firewall_updating_id', $apbct->fw_stats['firewall_updating_id'])
884
+ ) {
885
+ return array('error' => 'Worker: WRONG_UPDATE_ID');
886
+ }
887
+ }
888
 
889
+ if ( ! isset($apbct->fw_stats['calls']) ) {
890
  $apbct->fw_stats['calls'] = 0;
891
  }
892
 
893
  $apbct->fw_stats['calls']++;
894
  $apbct->save('fw_stats');
895
 
896
+ if ( $apbct->fw_stats['calls'] > 600 ) {
897
+ $apbct->errorAdd('sfw_update', 'WORKER_CALL_LIMIT_EXCEEDED');
898
  $apbct->saveErrors();
899
+
900
  return 'WORKER_CALL_LIMIT_EXCEEDED';
901
  }
902
 
903
+ $queue = new \Cleantalk\ApbctWP\Queue();
904
+
905
+ if ( count($queue->queue['stages']) === 0 ) {
906
+ // Queue is already empty. Exit.
907
+ return true;
908
+ }
909
 
910
+ $result = $queue->executeStage();
 
 
 
911
 
912
+ if ( isset($result['error']) ) {
913
+ $apbct->errorAdd('sfw_update', $result['error']);
914
+ $apbct->saveErrors();
915
 
916
+ return $result['error'];
917
+ }
 
 
 
918
 
919
+ if ( $queue->isQueueFinished() ) {
920
+ $queue->queue['finished'] = time();
921
+ $queue->saveQueue($queue->queue);
922
+ foreach ( $queue->queue['stages'] as $stage ) {
923
+ if ( isset($stage['error']) ) {
924
+ $apbct->errorAdd('sfw_update', $stage['error']);
925
+ }
926
+ }
927
 
928
+ // Do logging the queue process here
929
+ return true;
930
+ }
 
 
 
 
 
 
 
931
 
932
  // This is the repeat stage request, do not generate any new RC
933
+ if ( stripos(Get::get('stage'), 'Repeat') !== false ) {
934
+ return true;
935
+ }
 
 
 
 
 
 
936
 
937
+ return Helper::httpRequestRcToHost(
938
+ 'sfw_update__worker',
939
+ array('firewall_updating_id' => $apbct->fw_stats['firewall_updating_id']),
940
+ array('async')
941
+ );
942
  }
943
 
944
+ function apbct_sfw_update__get_multifiles()
945
+ {
946
  global $apbct;
947
 
948
+ if ( ! $apbct->data['key_is_ok'] ) {
949
+ return array('error' => 'Get multifiles: KEY_IS_NOT_VALID');
950
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
951
 
952
+ // Getting remote file name
953
+ $result = API::methodGet2sBlacklistsDb($apbct->api_key, 'multifiles', '3_1');
954
+
955
+ if ( empty($result['error']) ) {
956
+ if ( ! empty($result['file_url']) ) {
957
+ $file_urls = Helper::httpGetDataFromRemoteGzAndParseCsv($result['file_url']);
958
+ if ( empty($file_urls['error']) ) {
959
+ if ( ! empty($result['file_ua_url']) ) {
960
+ $file_urls[][0] = $result['file_ua_url'];
961
+ }
962
+ if ( ! empty($result['file_ck_url']) ) {
963
+ $file_urls[][0] = $result['file_ck_url'];
964
+ }
965
+ $urls = array();
966
+ foreach ( $file_urls as $value ) {
967
+ $urls[] = $value[0];
968
+ }
969
+
970
+ $apbct->fw_stats['firewall_update_percent'] = 100 / count($urls);
971
+ $apbct->save('fw_stats');
972
+
973
+ return array(
974
+ 'next_stage' => array(
975
+ 'name' => 'apbct_sfw_update__download_files',
976
+ 'args' => $urls,
977
+ 'is_last' => '0'
978
+ )
979
+ );
980
+ }
981
 
982
+ return array('error' => $file_urls['error']);
983
+ }
984
+ } else {
985
+ return $result;
986
+ }
 
 
 
 
 
987
  }
988
 
989
+ function apbct_sfw_update__download_files($urls)
990
+ {
991
+ global $apbct;
 
 
 
 
 
 
 
 
 
992
 
993
+ sleep(3);
994
 
995
+ //Reset keys
996
+ $urls = array_values($urls);
997
+ $results = Helper::httpMultiRequest($urls, $apbct->fw_stats['updating_folder']);
998
+ $count_urls = count($urls);
999
+ $count_results = count($results);
1000
 
1001
+ if ( empty($results['error']) && ($count_urls === $count_results) ) {
1002
+ $download_again = array();
1003
+ for ( $i = 0; $i < $count_results; $i++ ) {
1004
+ if ( $results[$i] === 'error' ) {
1005
+ $download_again[] = $urls[$i];
1006
+ }
1007
+ }
1008
 
1009
+ if ( count($download_again) !== 0 ) {
1010
+ return array(
1011
+ 'error' => 'Files download not completed.',
1012
+ 'update_args' => array(
1013
+ 'args' => $download_again
1014
+ )
1015
+ );
1016
+ }
1017
 
1018
+ return array(
1019
+ 'next_stage' => array(
1020
+ 'name' => 'apbct_sfw_update__create_tables'
1021
+ )
1022
+ );
1023
+ }
1024
 
1025
+ if ( ! empty($results['error']) ) {
1026
+ return $results;
1027
+ }
1028
 
1029
+ return array('error' => 'Files download not completed.');
1030
+ }
 
1031
 
1032
+ function apbct_sfw_update__create_tables()
1033
+ {
1034
+ global $apbct;
1035
+ // Preparing database infrastructure
1036
+ // Creating SFW tables to make sure that they are exist
1037
+ apbct_activation__create_tables(Schema::getSchema('sfw'), $apbct->db_prefix);
1038
+
1039
+ return array(
1040
+ 'next_stage' => array(
1041
+ 'name' => 'apbct_sfw_update__create_temp_tables',
1042
+ )
1043
+ );
1044
+ }
1045
 
1046
+ function apbct_sfw_update__create_temp_tables()
1047
+ {
1048
+ // Preparing temporary tables
1049
+ $result = SFW::createTempTables(DB::getInstance(), APBCT_TBL_FIREWALL_DATA);
1050
+ if ( ! empty($result['error']) ) {
1051
+ return $result;
1052
+ }
1053
 
1054
+ return array(
1055
+ 'next_stage' => array(
1056
+ 'name' => 'apbct_sfw_update__process_files',
1057
+ )
1058
+ );
1059
+ }
1060
 
1061
+ function apbct_sfw_update__process_files()
1062
+ {
1063
+ global $apbct;
 
 
 
1064
 
1065
+ $files = glob($apbct->fw_stats['updating_folder'] . '/*csv.gz');
1066
+ $files = array_filter($files, static function ($element) {
1067
+ return strpos($element, 'list') !== false;
1068
+ });
 
1069
 
1070
+ if ( count($files) ) {
1071
+ reset($files);
1072
+ $concrete_file = current($files);
1073
 
1074
+ if ( strpos($concrete_file, 'bl_list') !== false ) {
1075
+ $result = apbct_sfw_update__process_file($concrete_file);
1076
+ }
1077
 
1078
+ if ( strpos($concrete_file, 'ua_list') !== false ) {
1079
+ $result = apbct_sfw_update__process_ua($concrete_file);
1080
+ }
1081
 
1082
+ if ( strpos($concrete_file, 'ck_list') !== false ) {
1083
+ $result = apbct_sfw_update__process_ck($concrete_file);
1084
+ }
 
 
1085
 
1086
+ if ( ! empty($result['error']) ) {
1087
+ return $result;
1088
+ }
1089
 
1090
+ $apbct->fw_stats['firewall_update_percent'] = round(100 / count($files), 2) * 100;
1091
+ $apbct->save('fw_stats');
 
1092
 
1093
+ return array(
1094
+ 'next_stage' => array(
1095
+ 'name' => 'apbct_sfw_update__process_files',
1096
+ )
1097
+ );
1098
+ }
1099
 
1100
+ return array(
1101
+ 'next_stage' => array(
1102
+ 'name' => 'apbct_sfw_update__process_exclusions',
1103
+ )
1104
+ );
1105
  }
1106
 
1107
+ function apbct_sfw_update__process_file($file_path)
1108
+ {
1109
+ if ( ! file_exists($file_path) ) {
1110
+ return array('error' => 'PROCESS FILE: ' . $file_path . ' is not exists.');
1111
+ }
1112
 
1113
+ $result = SFW::updateWriteToDb(
1114
+ DB::getInstance(),
1115
+ APBCT_TBL_FIREWALL_DATA . '_temp',
1116
+ $file_path
1117
+ );
1118
 
1119
+ if ( ! empty($result['error']) ) {
1120
+ return array('error' => 'PROCESS FILE: ' . $result['error']);
1121
+ }
1122
 
1123
+ if ( ! is_int($result) ) {
1124
+ return array('error' => 'PROCESS FILE: WRONG RESPONSE FROM update__write_to_db');
1125
+ }
1126
 
1127
+ return $result;
1128
  }
1129
 
1130
+ function apbct_sfw_update__process_ua($file_path)
1131
+ {
1132
+ $result = AntiCrawler::update($file_path);
1133
 
1134
+ if ( ! empty($result['error']) ) {
1135
+ return array('error' => 'UPDATING UA LIST: ' . $result['error']);
1136
+ }
1137
 
1138
+ if ( ! is_int($result) ) {
1139
+ return array('error' => 'UPDATING UA LIST: : WRONG_RESPONSE AntiCrawler::update');
1140
+ }
1141
 
1142
+ return $result;
1143
+ }
1144
 
1145
+ function apbct_sfw_update__process_ck($file_path)
1146
+ {
1147
+ global $apbct;
1148
 
1149
+ // Save expected_networks_count and expected_ua_count if exists
1150
+ $file_content = file_get_contents($file_path);
1151
 
1152
+ if ( function_exists('gzdecode') ) {
1153
+ $unzipped_content = gzdecode($file_content);
 
1154
 
1155
+ if ( $unzipped_content !== false ) {
1156
+ $file_ck_url__data = Helper::bufferParseCsv($unzipped_content);
1157
 
1158
+ if ( ! empty($file_ck_url__data['error']) ) {
1159
+ return array('error' => 'GET EXPECTED RECORDS COUNT DATA: ' . $file_ck_url__data['error']);
1160
+ }
 
 
 
 
 
1161
 
1162
+ $expected_networks_count = 0;
1163
+ $expected_ua_count = 0;
 
1164
 
1165
+ foreach ( $file_ck_url__data as $value ) {
1166
+ if ( trim($value[0], '"') === 'networks_count' ) {
1167
+ $expected_networks_count = $value[1];
1168
+ }
1169
+ if ( trim($value[0], '"') === 'ua_count' ) {
1170
+ $expected_ua_count = $value[1];
1171
+ }
1172
+ }
1173
 
1174
+ $apbct->fw_stats['expected_networks_count'] = $expected_networks_count;
1175
+ $apbct->fw_stats['expected_ua_count'] = $expected_ua_count;
1176
+ $apbct->save('fw_stats');
 
 
 
1177
 
1178
+ if ( file_exists($file_path) ) {
1179
+ unlink($file_path);
1180
+ }
1181
+ } else {
1182
+ return array('error' => 'Can not unpack datafile');
1183
+ }
1184
+ } else {
1185
+ return array('error' => 'Function gzdecode not exists. Please update your PHP at least to version 5.4 ');
1186
+ }
1187
  }
1188
 
1189
+ function apbct_sfw_update__process_exclusions()
1190
+ {
1191
  global $apbct;
1192
 
1193
+ $result = SFW::updateWriteToDbExclusions(
1194
  DB::getInstance(),
1195
  APBCT_TBL_FIREWALL_DATA . '_temp'
1196
  );
1197
 
1198
+ if ( ! empty($result['error']) ) {
1199
+ return array('error' => 'EXCLUSIONS: ' . $result['error']);
1200
  }
1201
 
1202
+ if ( ! is_int($result) ) {
1203
+ return array('error' => 'EXCLUSIONS: WRONG_RESPONSE update__write_to_db__exclusions');
1204
  }
1205
 
1206
  /**
1207
  * Update expected_networks_count
1208
  */
1209
+ if ( $result > 0 ) {
1210
  $apbct->fw_stats['expected_networks_count'] += $result;
1211
+ $apbct->save('fw_stats');
1212
  }
1213
 
1214
+ return array(
1215
+ 'next_stage' => array(
1216
+ 'name' => 'apbct_sfw_update__end_of_update'
1217
+ )
1218
+ );
 
1219
  }
1220
 
1221
+ function apbct_sfw_update__end_of_update($is_direct_update = false)
1222
+ {
1223
+ global $apbct, $wpdb;
1224
 
1225
+ $apbct->fw_stats['update_mode'] = 1;
1226
+ $apbct->save('fw_stats');
1227
+ usleep(100000);
1228
 
 
 
1229
 
1230
+ // REMOVE AND RENAME
1231
+ $result = SFW::dataTablesDelete(DB::getInstance(), APBCT_TBL_FIREWALL_DATA);
1232
+ if ( empty($result['error']) ) {
1233
+ $result = SFW::renameDataTablesFromTempToMain(DB::getInstance(), APBCT_TBL_FIREWALL_DATA);
1234
  }
1235
+ if ( ! empty($result['error']) ) {
1236
  $apbct->fw_stats['update_mode'] = 0;
1237
  $apbct->save('fw_stats');
 
 
1238
 
1239
+ return $result;
1240
+ }
1241
+
1242
+ // Increment firewall entries
1243
+ $apbct->fw_stats['firewall_update_percent'] = 0;
1244
+ $apbct->fw_stats['firewall_updating_id'] = null;
1245
+ $apbct->fw_stats['last_firewall_updated'] = time();
1246
+ $apbct->fw_stats['update_mode'] = 0;
1247
+ $apbct->save('fw_stats');
1248
 
1249
+ $apbct->stats['sfw']['entries'] = $wpdb->get_var('SELECT COUNT(*) FROM ' . APBCT_TBL_FIREWALL_DATA);
1250
 
1251
+ // Running sfw update once again in 12 min if entries is < 4000
1252
+ if ( ! $apbct->stats['sfw']['last_update_time'] &&
1253
+ $apbct->stats['sfw']['entries'] < 4000
1254
+ ) {
1255
+ wp_schedule_single_event(time() + 720, 'apbct_sfw_update__init');
1256
+ }
1257
 
1258
+ $apbct->stats['sfw']['last_update_time'] = time();
1259
+ $apbct->stats['sfw']['last_update_way'] = $is_direct_update ? 'Direct update' : 'Queue update';
1260
+ $apbct->save('stats');
1261
 
1262
  /**
1263
  * Checking the integrity of the sfw database update
1265
  //@ToDo NEED TO BE REVIEWED
1266
  global $ct_cron;
1267
 
1268
+ if ( $apbct->stats['sfw']['entries'] != $apbct->fw_stats['expected_networks_count'] ) {
 
1269
  # call manually
1270
+ /** @psalm-suppress TypeDoesNotContainType */
1271
+ if ( ! $ct_cron ) {
1272
  return array(
1273
+ 'error' => 'The discrepancy between the amount of data received for the update and in the final table: ' . APBCT_TBL_FIREWALL_DATA . '. RECEIVED: ' . $apbct->fw_stats['expected_networks_count'] . '. ADDED: ' . $apbct->stats['sfw']['entries']
1274
+ );
1275
  }
1276
 
1277
  #call cron
1278
+ if ( $apbct->fw_stats['failed_update_attempt'] ) {
1279
  return array(
1280
+ 'error' => 'The discrepancy between the amount of data received for the update and in the final table: ' . APBCT_TBL_FIREWALL_DATA . '. RECEIVED: ' . $apbct->fw_stats['expected_networks_count'] . '. ADDED: ' . $apbct->stats['sfw']['entries']
1281
+ );
1282
  }
1283
 
1284
  $apbct->fw_stats['failed_update_attempt'] = true;
1285
+ $apbct->save('fw_stats');
1286
 
1287
  $cron = new Cron();
1288
+ $cron->updateTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 180);
1289
+
1290
  return false;
1291
  }
1292
 
1293
  $apbct->data['last_firewall_updated'] = current_time('timestamp');
1294
+ $apbct->save('data'); // Unused
1295
 
1296
+ // Delete update errors
1297
+ $apbct->errorDelete('sfw_update', 'save_settings');
1298
 
1299
+ // Get update period for server
1300
+ $update_period = DNS::getRecord('spamfirewall-ttl-txt.cleantalk.org', true, DNS_TXT);
1301
+ $update_period = isset($update_period['txt']) ? $update_period['txt'] : 0;
1302
+ $update_period = (int)$update_period > 14400 ? (int)$update_period : 14400;
1303
+ $cron = new Cron();
1304
+ $cron->updateTask('sfw_update', 'apbct_sfw_update__init', $update_period);
1305
+ $cron->removeTask('sfw_update_checker');
1306
 
1307
  /**
1308
  * Update fw data if update completed
1310
  $apbct->fw_stats['failed_update_attempt'] = false;
1311
  $apbct->fw_stats['expected_networks_count'] = false;
1312
 
1313
+ apbct_remove_upd_folder($apbct->fw_stats['updating_folder']);
1314
 
1315
+ $apbct->save('fw_stats');
 
 
1316
 
1317
+ return true;
1318
  }
1319
 
1320
 
1321
+ function apbct_sfw_update__is_in_progress()
1322
+ {
1323
+ $queue = new \Cleantalk\ApbctWP\Queue();
1324
+
1325
+ return $queue->isQueueInProgress();
1326
  }
1327
 
1328
+ function apbct_prepare_upd_dir()
1329
+ {
1330
+ global $apbct;
1331
 
1332
+ $dir_name = $apbct->fw_stats['updating_folder'];
1333
 
1334
+ if ( $dir_name === '' ) {
1335
+ return array('error' => 'FW dir can not be blank.');
1336
+ }
1337
 
1338
+ if ( ! is_dir($dir_name) ) {
1339
+ if ( ! mkdir($dir_name) && ! is_dir($dir_name) ) {
1340
+ return array('error' => 'Can not to make FW dir.');
1341
+ }
1342
+ } else {
1343
+ $files = glob($dir_name . '/*');
1344
+ if ( $files === false ) {
1345
+ return array('error' => 'Can not find FW files.');
1346
+ }
1347
+ if ( count($files) === 0 ) {
1348
+ return (bool)file_put_contents($dir_name . 'index.php', '<?php' . PHP_EOL);
1349
+ }
1350
+ foreach ( $files as $file ) {
1351
+ if ( is_file($file) && unlink($file) === false ) {
1352
+ return array('error' => 'Can not delete the FW file: ' . $file);
1353
+ }
1354
+ }
1355
+ }
1356
 
1357
+ return (bool)file_put_contents($dir_name . 'index.php', '<?php');
1358
+ }
1359
+
1360
+ function apbct_remove_upd_folder($dir_name)
1361
+ {
1362
+ if ( is_dir($dir_name) ) {
1363
+ $files = glob($dir_name . '/*');
1364
+
1365
+ if ( ! empty($files) ) {
1366
+ foreach ( $files as $file ) {
1367
+ if ( is_file($file) ) {
1368
+ unlink($file);
1369
+ }
1370
+ if ( is_dir($file) ) {
1371
+ apbct_remove_upd_folder($file);
1372
+ }
1373
  }
1374
+ }
1375
+
1376
+ rmdir($dir_name);
1377
+ }
1378
  }
1379
 
1380
+ function apbct_sfw_update__checker()
1381
+ {
1382
+ $queue = new \Cleantalk\ApbctWP\Queue();
1383
+ if ( count($queue->queue['stages']) ) {
1384
+ foreach ( $queue->queue['stages'] as $stage ) {
1385
+ if ( $stage['status'] === 'NULL' ) {
1386
+ return apbct_sfw_update__worker(true);
1387
+ }
1388
+ }
1389
+ }
1390
 
1391
+ return true;
1392
+ }
1393
 
1394
+ function apbct_sfw_direct_update()
1395
+ {
1396
+ global $apbct;
1397
 
1398
+ $api_key = $apbct->api_key;
 
 
 
 
 
 
 
 
 
1399
 
1400
+ // Key is empty
1401
+ if ( empty($api_key) ) {
1402
+ return array('error' => 'SFW DIRECT UPDATE: KEY_IS_EMPTY');
1403
+ }
1404
 
1405
+ // Getting BL
1406
+ $result = SFW::directUpdateGetBlackLists($api_key);
1407
 
1408
+ if ( empty($result['error']) ) {
1409
+ $blacklists = $result['blacklist'];
1410
+ $useragents = $result['useragents'];
1411
+ $bl_count = $result['bl_count'];
1412
+ $ua_count = $result['ua_count'];
1413
+
1414
+ if ( isset($bl_count, $ua_count) ) {
1415
+ $apbct->fw_stats['expected_networks_count'] = $bl_count;
1416
+ $apbct->fw_stats['expected_ua_count'] = $ua_count;
1417
+ $apbct->save('fw_stats');
1418
+ }
1419
 
1420
+ // Preparing database infrastructure
1421
+ // @ToDo need to implement returning result of the Activator::createTables work.
1422
+ apbct_activation__create_tables(Schema::getSchema('sfw'), $apbct->db_prefix);
 
 
 
 
 
 
1423
 
1424
+ $result__creating_tmp_table = SFW::createTempTables(DB::getInstance(), APBCT_TBL_FIREWALL_DATA);
1425
+ if ( ! empty($result__creating_tmp_table['error']) ) {
1426
+ return array('error' => 'DIRECT UPDATING CREATE TMP TABLE: ' . $result__creating_tmp_table['error']);
1427
+ }
1428
+
1429
+ /**
1430
+ * UPDATING UA LIST
1431
+ */
1432
+ if ( $useragents && ($apbct->settings['sfw__anti_crawler'] || $apbct->settings['sfw__anti_flood']) ) {
1433
+ $ua_result = AntiCrawler::directUpdate($useragents);
1434
 
1435
+ if ( ! empty($ua_result['error']) ) {
1436
+ return array('error' => 'DIRECT UPDATING UA LIST: ' . $result['error']);
1437
+ }
1438
+
1439
+ if ( ! is_int($ua_result) ) {
1440
+ return array('error' => 'DIRECT UPDATING UA LIST: : WRONG_RESPONSE AntiCrawler::directUpdate');
1441
+ }
1442
+ }
1443
+
1444
+ /**
1445
+ * UPDATING BLACK LIST
1446
+ */
1447
+ $upd_result = SFW::directUpdate(
1448
+ DB::getInstance(),
1449
+ APBCT_TBL_FIREWALL_DATA . '_temp',
1450
+ $blacklists
1451
+ );
1452
+
1453
+ if ( ! empty($upd_result['error']) ) {
1454
+ return array('error' => 'DIRECT UPDATING BLACK LIST: ' . $upd_result['error']);
1455
+ }
1456
+
1457
+ if ( ! is_int($upd_result) ) {
1458
+ return array('error' => 'DIRECT UPDATING BLACK LIST: WRONG RESPONSE FROM SFW::directUpdate');
1459
+ }
1460
+
1461
+ /**
1462
+ * UPDATING EXCLUSIONS LIST
1463
+ */
1464
+ $excl_result = apbct_sfw_update__process_exclusions();
1465
+
1466
+ if ( ! empty($excl_result['error']) ) {
1467
+ return array('error' => 'DIRECT UPDATING EXCLUSIONS: ' . $excl_result['error']);
1468
+ }
1469
+
1470
+ /**
1471
+ * END OF UPDATE
1472
+ */
1473
+ return apbct_sfw_update__end_of_update(true);
1474
+ }
1475
+
1476
+ return $result;
1477
+ }
1478
 
1479
+ function apbct_sfw_update__cleanData()
1480
+ {
1481
  global $apbct;
1482
 
1483
+ SFW::dataTablesDelete(DB::getInstance(), APBCT_TBL_FIREWALL_DATA . '_temp');
1484
 
1485
  $apbct->fw_stats['firewall_update_percent'] = 0;
1486
+ $apbct->fw_stats['firewall_updating_id'] = null;
1487
+ $apbct->save('fw_stats');
1488
  }
1489
 
1490
  function ct_sfw_send_logs($api_key = '')
1491
  {
1492
+ global $apbct;
1493
 
1494
+ $api_key = ! empty($apbct->api_key) ? $apbct->api_key : $api_key;
1495
 
1496
+ if (
1497
  time() - $apbct->stats['sfw']['sending_logs__timestamp'] < 180 ||
1498
+ empty($api_key) ||
1499
  $apbct->settings['sfw__enabled'] != 1
1500
+ ) {
1501
  return true;
1502
  }
1503
 
1504
  $apbct->stats['sfw']['sending_logs__timestamp'] = time();
1505
  $apbct->save('stats');
1506
 
1507
+ $result = SFW::sendLog(
1508
  DB::getInstance(),
1509
  APBCT_TBL_FIREWALL_LOG,
1510
  $api_key,
1511
+ (bool)$apbct->settings['sfw__use_delete_to_clear_table']
1512
  );
1513
 
1514
+ if ( empty($result['error']) ) {
1515
+ $apbct->stats['sfw']['last_send_time'] = time();
1516
+ $apbct->stats['sfw']['last_send_amount'] = $result['rows'];
1517
+ $apbct->errorDelete('sfw_send_logs', 'save_settings');
1518
  $apbct->save('stats');
1519
  }
1520
 
1521
  return $result;
1522
  }
1523
 
1524
+ function apbct_antiflood__clear_table()
1525
+ {
1526
+ global $apbct;
 
 
1527
 
1528
+ if ( $apbct->settings['sfw__anti_flood'] || $apbct->settings['sfw__anti_crawler'] ) {
1529
+ $anti_flood = new AntiFlood(
1530
+ APBCT_TBL_FIREWALL_LOG,
1531
+ APBCT_TBL_AC_LOG,
1532
+ array(
1533
+ 'chance_to_clean' => 100,
1534
+ )
1535
+ );
1536
+ $anti_flood->setDb(DB::getInstance());
1537
+ $anti_flood->clearTable();
1538
+ unset($anti_flood);
1539
+ }
1540
  }
1541
 
1542
  /**
1544
  *
1545
  * @param null|WP $_wp
1546
  * @param null|string|array $plugin
1547
+ *
1548
  * @psalm-suppress UndefinedClass
1549
  */
1550
+ function apbct_rc__install_plugin($_wp = null, $plugin = null)
1551
+ {
1552
+ global $wp_version;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1553
 
1554
+ if ( is_null($plugin) ) {
1555
+ $plugin = isset($_GET['plugin']) ? $_GET['plugin'] : null;
1556
+ }
 
1557
 
1558
+ if ( $plugin ) {
1559
+ if ( preg_match('/[a-zA-Z-\d]+[\/\\][a-zA-Z-\d]+\.php/', $plugin) ) {
1560
+ $plugin_slug = preg_replace('@([a-zA-Z-\d]+)[\\\/].*@', '$1', $plugin);
1561
+
1562
+ if ( $plugin_slug ) {
1563
+ require_once(ABSPATH . 'wp-admin/includes/plugin-install.php');
1564
+ $result = plugins_api(
1565
+ 'plugin_information',
1566
+ array(
1567
+ 'slug' => $plugin_slug,
1568
+ 'fields' => array('version' => true, 'download_link' => true,),
1569
+ )
1570
+ );
1571
+
1572
+ if ( ! is_wp_error($result) ) {
1573
+ require_once(ABSPATH . 'wp-admin/includes/plugin.php');
1574
+ include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
1575
+ include_once(ABSPATH . 'wp-admin/includes/file.php');
1576
+ include_once(ABSPATH . 'wp-admin/includes/misc.php');
1577
+
1578
+ if ( version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0 ) {
1579
+ $installer = new CleantalkUpgrader(new CleantalkUpgraderSkin());
1580
  } else {
1581
+ $installer = new CleantalkUpgrader(new CleantalkUpgraderSkinDeprecated());
1582
  }
1583
 
1584
+ $installer->install($result->download_link);
1585
 
1586
+ if ( $installer->apbct_result === 'OK' ) {
1587
+ die('OK');
1588
+ } else {
1589
+ die('FAIL ' . json_encode(array('error' => $installer->apbct_result)));
1590
+ }
1591
+ } else {
1592
+ die(
1593
+ 'FAIL ' . json_encode(array(
1594
+ 'error' => 'FAIL_TO_GET_LATEST_VERSION',
1595
+ 'details' => $result->get_error_message(),
1596
+ ))
1597
+ );
1598
+ }
1599
+ } else {
1600
+ die('FAIL ' . json_encode(array('error' => 'PLUGIN_SLUG_INCORRECT')));
1601
+ }
1602
+ } else {
1603
+ die('FAIL ' . json_encode(array('error' => 'PLUGIN_NAME_IS_INCORRECT')));
1604
+ }
1605
+ } else {
1606
+ die('FAIL ' . json_encode(array('error' => 'PLUGIN_NAME_IS_UNSET')));
1607
+ }
1608
  }
1609
 
1610
+ function apbct_rc__activate_plugin($plugin)
1611
+ {
1612
+ if ( ! $plugin ) {
1613
+ $plugin = isset($_GET['plugin']) ? $_GET['plugin'] : null;
1614
+ }
 
 
 
 
1615
 
1616
+ if ( $plugin ) {
1617
+ if ( preg_match('@[a-zA-Z-\d]+[\\\/][a-zA-Z-\d]+\.php@', $plugin) ) {
1618
+ require_once(ABSPATH . '/wp-admin/includes/plugin.php');
1619
 
1620
+ $result = activate_plugins($plugin);
1621
 
1622
+ if ( $result && ! is_wp_error($result) ) {
1623
+ return array('success' => true);
1624
+ } else {
1625
+ return array(
1626
+ 'error' => 'FAIL_TO_ACTIVATE',
1627
+ 'details' => (is_wp_error($result) ? ' ' . $result->get_error_message() : '')
1628
+ );
1629
+ }
1630
+ } else {
1631
+ return array('error' => 'PLUGIN_NAME_IS_INCORRECT');
1632
+ }
1633
+ } else {
1634
+ return array('error' => 'PLUGIN_NAME_IS_UNSET');
1635
+ }
1636
  }
1637
 
1638
  /**
1640
  *
1641
  * @param null $plugin
1642
  */
1643
+ function apbct_rc__deactivate_plugin($plugin = null)
1644
+ {
1645
+ global $apbct;
 
 
 
 
1646
 
1647
+ if ( is_null($plugin) ) {
1648
+ $plugin = isset($_GET['plugin']) ? $_GET['plugin'] : null;
1649
+ }
1650
 
1651
+ if ( $plugin ) {
1652
+ // Switching complete deactivation for security
1653
+ if ( $plugin === 'security-malware-firewall/security-malware-firewall.php' && ! empty($_GET['misc__complete_deactivation']) ) {
1654
+ $spbc_settings = get_option('spbc_settings');
1655
+ $spbc_settings['misc__complete_deactivation'] = (int)$_GET['misc__complete_deactivation'];
1656
+ update_option('spbc_settings', $spbc_settings);
1657
+ }
1658
 
1659
+ require_once(ABSPATH . '/wp-admin/includes/plugin.php');
1660
 
1661
+ if ( is_plugin_active($plugin) ) {
1662
+ // Hook to set flag if the plugin is deactivated
1663
+ add_action('deactivate_' . $plugin, 'apbct_rc__uninstall_plugin__check_deactivate');
1664
+ deactivate_plugins($plugin, false, is_multisite());
1665
+ } else {
1666
+ $apbct->plugin_deactivated = true;
1667
+ }
1668
 
1669
+ // Hook to set flag if the plugin is deactivated
1670
+ add_action('deactivate_' . $plugin, 'apbct_rc__uninstall_plugin__check_deactivate');
1671
+ deactivate_plugins($plugin, false, is_multisite());
1672
 
1673
+ if ( $apbct->plugin_deactivated ) {
1674
+ die('OK');
1675
+ } else {
1676
+ die('FAIL ' . json_encode(array('error' => 'PLUGIN_STILL_ACTIVE')));
1677
+ }
1678
+ } else {
1679
+ die('FAIL ' . json_encode(array('error' => 'PLUGIN_NAME_IS_UNSET')));
1680
+ }
1681
  }
1682
 
1683
 
1686
  *
1687
  * @param null $plugin
1688
  */
1689
+ function apbct_rc__uninstall_plugin($plugin = null)
1690
+ {
1691
+ global $apbct;
 
 
 
 
 
 
1692
 
1693
+ if ( is_null($plugin) ) {
1694
+ $plugin = isset($_GET['plugin']) ? $_GET['plugin'] : null;
1695
+ }
 
 
 
1696
 
1697
+ if ( $plugin ) {
1698
+ // Switching complete deactivation for security
1699
+ if ( $plugin === 'security-malware-firewall/security-malware-firewall.php' && ! empty($_GET['misc__complete_deactivation']) ) {
1700
+ $spbc_settings = get_option('spbc_settings');
1701
+ $spbc_settings['misc__complete_deactivation'] = (int)$_GET['misc__complete_deactivation'];
1702
+ update_option('spbc_settings', $spbc_settings);
1703
+ }
1704
 
1705
+ require_once(ABSPATH . '/wp-admin/includes/plugin.php');
 
 
 
 
 
 
1706
 
1707
+ if ( is_plugin_active($plugin) ) {
1708
+ // Hook to set flag if the plugin is deactivated
1709
+ add_action('deactivate_' . $plugin, 'apbct_rc__uninstall_plugin__check_deactivate');
1710
+ deactivate_plugins($plugin, false, is_multisite());
1711
+ } else {
1712
+ $apbct->plugin_deactivated = true;
1713
+ }
1714
 
1715
+ if ( $apbct->plugin_deactivated ) {
1716
+ require_once(ABSPATH . '/wp-admin/includes/file.php');
1717
 
1718
+ $result = delete_plugins(array($plugin));
1719
 
1720
+ if ( $result && ! is_wp_error($result) ) {
1721
+ die('OK');
1722
+ } else {
1723
+ die(
1724
+ 'FAIL ' . json_encode(array(
1725
+ 'error' => 'PLUGIN_STILL_EXISTS',
1726
+ 'details' => (is_wp_error($result) ? ' ' . $result->get_error_message() : '')
1727
+ ))
1728
+ );
1729
+ }
1730
+ } else {
1731
+ die('FAIL ' . json_encode(array('error' => 'PLUGIN_STILL_ACTIVE')));
1732
+ }
1733
+ } else {
1734
+ die('FAIL ' . json_encode(array('error' => 'PLUGIN_NAME_IS_UNSET')));
1735
+ }
1736
  }
1737
 
1738
+ function apbct_rc__uninstall_plugin__check_deactivate()
1739
+ {
1740
+ global $apbct;
1741
+ $apbct->plugin_deactivated = true;
1742
  }
1743
 
1744
  /**
1745
  * @throws JsonException
1746
  * @psalm-suppress UndefinedClass
1747
  */
1748
+ function apbct_rc__update()
1749
+ {
1750
+ global $wp_version;
1751
+
1752
+ //Upgrade params
1753
+ $plugin = 'cleantalk-spam-protect/cleantalk.php';
1754
+ $plugin_slug = 'cleantalk-spam-protect';
1755
+ $title = __('Update Plugin');
1756
+ $nonce = 'upgrade-plugin_' . $plugin;
1757
+ $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode($plugin);
1758
  $activate_for_network = false;
1759
+ if ( APBCT_WPMS && is_main_site() && array_key_exists($plugin, get_site_option('active_sitewide_plugins')) ) {
1760
  $activate_for_network = true;
1761
  }
1762
 
1763
+ $prev_version = APBCT_VERSION;
1764
 
1765
+ require_once(ABSPATH . 'wp-admin/includes/plugin.php');
1766
+ include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');
1767
+ include_once(ABSPATH . 'wp-admin/includes/file.php');
1768
+ include_once(ABSPATH . 'wp-admin/includes/misc.php');
1769
 
1770
+ apbct_maintenance_mode__enable(30);
1771
 
1772
+ if ( version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0 ) {
1773
+ $upgrader = new CleantalkUpgrader(new CleantalkUpgraderSkin(compact('title', 'nonce', 'url', 'plugin')));
1774
+ } else {
1775
+ $upgrader = new CleantalkUpgrader(
1776
+ new CleantalkUpgraderSkinDeprecated(compact('title', 'nonce', 'url', 'plugin'))
1777
+ );
1778
+ }
1779
 
1780
+ $upgrader_result = $upgrader->upgrade($plugin);
1781
+ if ( is_wp_error($upgrader_result) ) {
1782
  error_log('CleanTalk debug message:');
1783
+ error_log(var_export($upgrader_result->get_error_message(), true));
1784
  }
1785
 
1786
+ apbct_maintenance_mode__disable();
 
 
 
 
 
 
 
1787
 
1788
+ $result = activate_plugins($plugin, '', $activate_for_network);
1789
 
1790
+ // Changing response UP_TO_DATE to OK
1791
+ if ( $upgrader->apbct_result === 'UP_TO_DATE' ) {
1792
+ $upgrader->apbct_result = 'OK';
1793
+ }
 
1794
 
1795
+ if ( $upgrader->apbct_result === 'OK' ) {
1796
+ if ( is_wp_error($result) ) {
1797
+ die(
1798
+ 'FAIL ' . json_encode(
1799
+ array(
1800
+ 'error' => 'COULD_NOT_ACTIVATE',
1801
+ 'wp_error' => $result->get_error_message()
1802
+ )
1803
+ )
1804
+ );
1805
+ }
1806
 
1807
+ $httpResponseCode = Helper::httpRequest(get_option('siteurl'), array(), 'get_code');
1808
 
1809
+ if ( strpos($httpResponseCode, '200') === false ) {
1810
+ apbct_maintenance_mode__enable(30);
 
 
 
 
 
 
1811
 
1812
+ // Rollback
1813
+ if ( version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0 ) {
1814
+ $rollback = new CleantalkUpgrader(
1815
+ new CleantalkUpgraderSkin(compact('title', 'nonce', 'url', 'plugin_slug', 'prev_version'))
1816
+ );
1817
+ } else {
1818
+ $rollback = new CleantalkUpgrader(
1819
+ new CleantalkUpgraderSkinDeprecated(compact('title', 'nonce', 'url', 'plugin_slug', 'prev_version'))
1820
+ );
1821
+ }
1822
+ $rollback->rollback($plugin);
1823
 
1824
+ apbct_maintenance_mode__disable();
1825
 
1826
+ // @todo add execution time
 
 
 
 
 
1827
 
1828
+ $response = array(
1829
+ 'error' => 'BAD_HTTP_CODE',
1830
+ 'http_code' => $httpResponseCode,
1831
+ 'output' => substr(file_get_contents(get_option('siteurl')), 0, 900),
1832
+ 'rollback_result' => $rollback->apbct_result,
1833
+ );
1834
 
1835
+ die('FAIL ' . json_encode($response));
1836
+ }
 
1837
 
1838
+ $plugin_data = get_plugin_data(__FILE__);
1839
+ $apbct_agent = 'wordpress-' . str_replace('.', '', $plugin_data['Version']);
1840
+ ct_send_feedback('0:' . $apbct_agent);
1841
 
1842
+ die('OK ' . json_encode(array('agent' => $apbct_agent)));
1843
+ }
1844
 
1845
+ die('FAIL ' . json_encode(array('error' => $upgrader->apbct_result)));
1846
  }
1847
 
1848
  /**
1850
  *
1851
  * @return bool
1852
  */
1853
+ function apbct_rc__update_settings($source)
1854
+ {
1855
+ global $apbct;
1856
 
1857
+ foreach ( $apbct->def_settings as $setting => $def_value ) {
1858
+ if ( array_key_exists($setting, $source) ) {
1859
+ $var = $source[$setting];
1860
+ $type = gettype($def_value);
1861
+ settype($var, $type);
1862
+ if ( $type === 'string' ) {
1863
+ $var = preg_replace(array('/=/', '/`/'), '', $var);
1864
+ }
1865
+ $apbct->settings[$setting] = $var;
1866
+ }
1867
+ }
1868
 
1869
+ $apbct->save('settings');
1870
 
1871
+ return true;
1872
  }
1873
 
1874
  /**
1877
  *
1878
  * @return array|string
1879
  */
1880
+ function apbct_rc__insert_auth_key($key, $plugin)
1881
+ {
1882
+ if ( $plugin === 'security-malware-firewall/security-malware-firewall.php' ) {
1883
+ require_once(ABSPATH . '/wp-admin/includes/plugin.php');
1884
+
1885
+ if ( is_plugin_active($plugin) ) {
1886
+ $key = trim($key);
1887
+
1888
+ if ( $key && preg_match('/^[a-z\d]{3,15}$/', $key) ) {
1889
+ $result = API::methodNoticePaidTill(
1890
+ $key,
1891
+ preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1), // Site URL
1892
+ 'security'
1893
+ );
1894
+
1895
+ if ( empty($result['error']) ) {
1896
+ if ( $result['valid'] ) {
1897
+ // Set account params
1898
+ $data = get_option('spbc_data', array());
1899
+ $data['user_token'] = $result['user_token'];
1900
+ $data['notice_show'] = $result['show_notice'];
1901
+ $data['notice_renew'] = $result['renew'];
1902
+ $data['notice_trial'] = $result['trial'];
1903
+ $data['auto_update_app'] = isset($result['show_auto_update_notice']) ? $result['show_auto_update_notice'] : 0;
1904
+ $data['service_id'] = $result['service_id'];
1905
+ $data['moderate'] = $result['moderate'];
1906
+ $data['auto_update_app '] = isset($result['auto_update_app']) ? $result['auto_update_app'] : 0;
1907
+ $data['license_trial'] = isset($result['license_trial']) ? $result['license_trial'] : 0;
1908
+ $data['account_name_ob'] = isset($result['account_name_ob']) ? $result['account_name_ob'] : '';
1909
+ $data['key_is_ok'] = true;
1910
+ update_option('spbc_data', $data);
1911
+
1912
+ // Set key
1913
+ $settings = get_option('spbc_settings', array());
1914
+ $settings['spbc_key'] = $key;
1915
+ update_option('spbc_settings', $settings);
1916
+
1917
+ return 'OK';
1918
+ } else {
1919
+ return array('error' => 'KEY_IS_NOT_VALID');
1920
+ }
1921
+ } else {
1922
+ return array('error' => $result);
1923
+ }
1924
+ } else {
1925
+ return array('error' => 'KEY_IS_NOT_CORRECT');
1926
+ }
1927
+ } else {
1928
+ return array('error' => 'PLUGIN_IS_NOT_ACTIVE_OR_NOT_INSTALLED');
1929
+ }
1930
+ } else {
1931
+ return array('error' => 'PLUGIN_SLUG_INCORRECT');
1932
+ }
 
 
 
 
 
1933
  }
1934
 
1935
  /**
1940
  *
1941
  * @return bool
1942
  */
1943
+ function apbct_maintenance_mode__enable($duration)
1944
+ {
1945
+ apbct_maintenance_mode__disable();
1946
+ $content = "<?php\n\n"
1947
+ . '$upgrading = ' . (time() - (60 * 10) + $duration) . ';';
1948
 
1949
+ return (bool)file_put_contents(ABSPATH . '.maintenance', $content);
1950
  }
1951
 
1952
  /**
1954
  *
1955
  * @return void
1956
  */
1957
+ function apbct_maintenance_mode__disable()
1958
+ {
1959
+ $maintenance_file = ABSPATH . '.maintenance';
1960
+ if ( file_exists($maintenance_file) ) {
1961
+ unlink($maintenance_file);
1962
+ }
1963
  }
1964
 
1965
  /**
1967
  *
1968
  * @param null|string $api_key
1969
  */
1970
+ function cleantalk_get_brief_data($api_key = null)
1971
+ {
1972
  global $apbct;
1973
 
1974
+ $api_key = is_null($api_key) ? $apbct->api_key : $api_key;
1975
+
1976
+ $apbct->data['brief_data'] = API::methodGetAntispamReportBreif($api_key);
1977
+
1978
+ # expanding data about the country
1979
+ if ( isset($apbct->data['brief_data']['top5_spam_ip']) && ! empty($apbct->data['brief_data']['top5_spam_ip']) ) {
1980
+ foreach ( $apbct->data['brief_data']['top5_spam_ip'] as $key => $ip_data ) {
1981
+ $ip = $ip_data[0];
1982
+ $ip_data[1] = array(
1983
+ 'country_name' => 'Unknown',
1984
+ 'country_code' => 'cleantalk'
1985
+ );
1986
+
1987
+ if ( isset($ip) ) {
1988
+ $country_data = API::methodIpInfo($ip);
1989
+ $country_data_clear = current($country_data);
1990
+
1991
+ if (
1992
+ is_array($country_data_clear) &&
1993
+ isset($country_data_clear['country_name']) &&
1994
+ isset($country_data_clear['country_code'])
1995
+ ) {
1996
+ $ip_data[1] = array(
1997
+ 'country_name' => $country_data_clear['country_name'],
1998
+ 'country_code' => ( ! preg_match(
1999
+ '/[^A-Za-z0-9]/',
2000
+ $country_data_clear['country_code']
2001
+ )) ? $country_data_clear['country_code'] : 'cleantalk'
2002
+ );
2003
+ }
2004
+ }
2005
 
2006
+ $apbct->data['brief_data']['top5_spam_ip'][$key] = $ip_data;
2007
+ }
2008
+ }
2009
 
2010
+ $apbct->saveData();
2011
  }
2012
 
2013
  /**
2014
  * Delete cookie for admin trial notice
2015
  */
2016
+ function apbct__hook__wp_logout__delete_trial_notice_cookie()
2017
+ {
2018
+ if ( ! headers_sent() ) {
2019
+ Cookie::setNativeCookie('ct_trial_banner_closed', '', time() - 3600);
2020
+ }
2021
  }
2022
 
2023
  /**
2026
  * @throws JsonException
2027
  * @ToDo need to be refactored psalm notices about InvalidArrayOffset
2028
  */
2029
+ function apbct_store__urls()
2030
+ {
2031
  global $apbct;
2032
 
2033
+ if ( $apbct->settings['misc__store_urls'] && empty($apbct->flags__url_stored) && ! headers_sent() ) {
2034
+ // URLs HISTORY
2035
+ // Get current url
2036
+ $current_url = Server::get('HTTP_HOST') . Server::get('REQUEST_URI');
2037
+ $current_url = $current_url ? substr($current_url, 0, 128) : 'UNKNOWN';
2038
+ $site_url = parse_url(get_option('siteurl'), PHP_URL_HOST);
2039
+
2040
+ // Get already stored URLs
2041
+ $urls = Cookie::get('apbct_urls', array(), 'array');
2042
+ /** @psalm-suppress InvalidArrayOffset */
2043
+ $urls[$current_url][] = time();
2044
+
2045
+ // Rotating. Saving only latest 10
2046
+ /** @psalm-suppress InvalidArrayOffset */
2047
+ $urls[$current_url] = count($urls[$current_url]) > 5 ? array_slice(
2048
+ $urls[$current_url],
2049
+ 1,
2050
+ 5
2051
+ ) : $urls[$current_url];
2052
+ $urls = count($urls) > 5 ? array_slice($urls, 1, 5) : $urls;
2053
+
2054
+ // Saving
2055
+ Cookie::set('apbct_urls', json_encode($urls), time() + 86400 * 3, '/', $site_url, null, true, 'Lax');
2056
+
2057
+ // REFERER
2058
+ // Get current referer
2059
+ $new_site_referer = apbct_get_server_variable('HTTP_REFERER');
2060
+ $new_site_referer = $new_site_referer ?: 'UNKNOWN';
2061
+
2062
+ // Get already stored referer
2063
+ $site_referer = Cookie::get('apbct_site_referer');
2064
+
2065
+ // Save if empty
2066
+ if (
2067
+ $site_url &&
2068
+ (
2069
+ ! $site_referer ||
2070
+ parse_url($new_site_referer, PHP_URL_HOST) !== apbct_get_server_variable('HTTP_HOST')
2071
+ )
2072
+ ) {
2073
+ Cookie::set('apbct_site_referer', $new_site_referer, time() + 86400 * 3, '/', $site_url, null, true, 'Lax');
2074
+ }
2075
 
2076
+ $apbct->flags__url_stored = true;
2077
+ }
2078
  }
2079
 
2080
  /**
2083
  * Sets test cookie with all other cookies
2084
  * @return bool
2085
  */
2086
+ function apbct_cookie()
2087
+ {
2088
+ global $apbct;
2089
 
2090
+ if (
2091
+ empty($apbct->settings['data__set_cookies']) || // Do not set cookies if option is disabled (for Varnish cache).
2092
+ ! empty($apbct->flags__cookies_setuped) || // Cookies already set
2093
+ ! empty($apbct->headers_sent) // Headers sent
2094
+ ) {
2095
+ return false;
2096
+ }
2097
 
2098
+ // Prevent headers sent error
2099
+ if ( headers_sent($file, $line) ) {
2100
+ $apbct->headers_sent = true;
2101
+ $apbct->headers_sent__hook = current_filter();
2102
+ $apbct->headers_sent__where = $file . ':' . $line;
 
 
2103
 
2104
+ return false;
2105
+ }
 
 
 
 
 
2106
 
2107
 
2108
  // Cookie names to validate
2109
+ $cookie_test_value = array(
2110
+ 'cookies_names' => array(),
2111
+ 'check_value' => $apbct->api_key,
2112
+ );
2113
 
2114
+ // We need to skip the domain attribute for prevent including the dot to the cookie's domain on the client.
2115
  $domain = '';
2116
 
2117
+ // Submit time
2118
+ if ( empty($_POST['ct_multipage_form']) ) { // Do not start/reset page timer if it is multi page form (Gravity forms))
2119
+ $apbct_timestamp = time();
2120
+ Cookie::set('apbct_timestamp', (string)$apbct_timestamp, 0, '/', $domain, null, true);
2121
+ $cookie_test_value['cookies_names'][] = 'apbct_timestamp';
2122
+ $cookie_test_value['check_value'] .= $apbct_timestamp;
2123
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2124
 
2125
+ // Previous referer
2126
+ if ( Server::get('HTTP_REFERER') ) {
2127
+ Cookie::set('apbct_prev_referer', Server::get('HTTP_REFERER'), 0, '/', $domain, null, true);
2128
+ $cookie_test_value['cookies_names'][] = 'apbct_prev_referer';
2129
+ $cookie_test_value['check_value'] .= apbct_get_server_variable('HTTP_REFERER');
2130
+ }
2131
+
2132
+ // Landing time
2133
+ $site_landing_timestamp = Cookie::get('apbct_site_landing_ts');
2134
+ if ( ! $site_landing_timestamp ) {
2135
+ $site_landing_timestamp = time();
2136
+ Cookie::set('apbct_site_landing_ts', (string)$site_landing_timestamp, 0, '/', $domain, null, true);
2137
+ }
2138
+ $cookie_test_value['cookies_names'][] = 'apbct_site_landing_ts';
2139
+ $cookie_test_value['check_value'] .= $site_landing_timestamp;
2140
 
2141
+ // Page hits
2142
+ // Get
2143
+ $page_hits = Cookie::get('apbct_page_hits');
2144
+ // Set / Increase
2145
+ $page_hits = (int)$page_hits ? (int)$page_hits + 1 : 1;
2146
+
2147
+ Cookie::set('apbct_page_hits', (string)$page_hits, 0, '/', $domain, null, true);
2148
+
2149
+ $cookie_test_value['cookies_names'][] = 'apbct_page_hits';
2150
+ $cookie_test_value['check_value'] .= $page_hits;
2151
+
2152
+ // Cookies test
2153
+ $cookie_test_value['check_value'] = md5($cookie_test_value['check_value']);
2154
+ if ( $apbct->settings['data__set_cookies'] == 1 ) {
2155
+ Cookie::set('apbct_cookies_test', urlencode(json_encode($cookie_test_value)), 0, '/', $domain, null, true);
2156
+ }
2157
+
2158
+ $apbct->flags__cookies_setuped = true;
2159
+
2160
+ return $apbct->flags__cookies_setuped;
2161
  }
2162
 
2163
  /**
2168
  */
2169
  function apbct_cookies_test()
2170
  {
2171
+ global $apbct;
2172
 
2173
+ if ( $apbct->settings['data__set_cookies'] == 2 ) {
2174
  return 1;
2175
  }
2176
 
2177
+ if ( isset($_COOKIE['apbct_cookies_test']) ) {
2178
+ $cookie_test = json_decode(urldecode($_COOKIE['apbct_cookies_test']), true);
 
2179
 
2180
+ if ( ! is_array($cookie_test) ) {
2181
+ return 0;
2182
+ }
2183
 
2184
+ $check_string = $apbct->api_key;
2185
+ foreach ( $cookie_test['cookies_names'] as $cookie_name ) {
2186
+ $check_string .= isset($_COOKIE[$cookie_name]) ? $_COOKIE[$cookie_name] : '';
2187
+ }
2188
 
2189
+ if ( $cookie_test['check_value'] == md5($check_string) ) {
2190
+ return 1;
2191
+ }
2192
 
2193
+ return 0;
2194
+ }
2195
 
2196
+ return null;
2197
  }
2198
 
2199
  /**
2204
  */
2205
  function apbct_get_submit_time()
2206
  {
2207
+ $apbct_timestamp = (int)Cookie::get('apbct_timestamp');
2208
+
2209
+ return apbct_cookies_test() === 1 && $apbct_timestamp !== 0 ? time() - $apbct_timestamp : null;
2210
  }
2211
 
2212
  /*
2213
  * Inner function - Account status check
2214
  * Scheduled in 1800 seconds for default!
2215
  */
2216
+ function ct_account_status_check($api_key = null, $process_errors = true)
2217
+ {
2218
+ global $apbct;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2219
 
2220
+ $api_key = $api_key ?: $apbct->api_key;
2221
+ $result = API::methodNoticePaidTill(
2222
+ $api_key,
2223
+ preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
2224
+ ! is_main_site() && $apbct->white_label ? 'anti-spam-hosting' : 'antispam'
2225
+ );
 
 
 
 
 
2226
 
2227
+ if ( empty($result['error']) || ! empty($result['valid']) ) {
2228
+ // Notices
2229
+ $apbct->data['notice_show'] = isset($result['show_notice']) ? (int)$result['show_notice'] : 0;
2230
+ $apbct->data['notice_renew'] = isset($result['renew']) ? (int)$result['renew'] : 0;
2231
+ $apbct->data['notice_trial'] = isset($result['trial']) ? (int)$result['trial'] : 0;
2232
+ $apbct->data['notice_review'] = isset($result['show_review']) ? (int)$result['show_review'] : 0;
2233
+ $apbct->data['notice_auto_update'] = isset($result['show_auto_update_notice']) ? (int)$result['show_auto_update_notice'] : 0;
2234
+
2235
+ // Other
2236
+ $apbct->data['service_id'] = isset($result['service_id']) ? (int)$result['service_id'] : 0;
2237
+ $apbct->data['valid'] = isset($result['valid']) ? (int)$result['valid'] : 0;
2238
+ $apbct->data['moderate'] = isset($result['moderate']) ? (int)$result['moderate'] : 0;
2239
+ $apbct->data['ip_license'] = isset($result['ip_license']) ? (int)$result['ip_license'] : 0;
2240
+ $apbct->data['moderate_ip'] = isset($result['moderate_ip'], $result['ip_license']) ? (int)$result['moderate_ip'] : 0;
2241
+ $apbct->data['spam_count'] = isset($result['spam_count']) ? (int)$result['spam_count'] : 0;
2242
+ $apbct->data['auto_update'] = isset($result['auto_update_app']) ? (int)$result['auto_update_app'] : 0;
2243
+ $apbct->data['user_token'] = isset($result['user_token']) ? (string)$result['user_token'] : '';
2244
+ $apbct->data['license_trial'] = isset($result['license_trial']) ? (int)$result['license_trial'] : 0;
2245
+ $apbct->data['account_name_ob'] = isset($result['account_name_ob']) ? (string)$result['account_name_ob'] : '';
2246
 
2247
+ $cron = new Cron();
2248
+ $cron->updateTask('check_account_status', 'ct_account_status_check', 86400);
2249
 
2250
+ $apbct->errorDelete('account_check', 'save');
2251
 
2252
+ $apbct->saveData();
2253
+ } elseif ( $process_errors ) {
2254
+ $apbct->errorAdd('account_check', $result);
2255
+ }
2256
 
2257
+ if ( ! empty($result['valid']) ) {
2258
+ $apbct->data['key_is_ok'] = true;
2259
+ $result = true;
2260
+ } else {
2261
+ $apbct->data['key_is_ok'] = false;
2262
+ $result = false;
2263
+ }
2264
 
2265
+ return $result;
2266
  }
2267
 
2268
+ function ct_mail_send_connection_report()
2269
+ {
2270
+ global $apbct;
2271
 
2272
+ if ( ($apbct->settings['misc__send_connection_reports'] == 1 && $apbct->connection_reports['negative'] > 0) || ! empty($_GET['ct_send_connection_report']) ) {
2273
+ $to = "welcome@cleantalk.org";
2274
+ $subject = "Connection report for " . apbct_get_server_variable('HTTP_HOST');
2275
+ $message = '
 
2276
  <html lang="en">
2277
  <head>
2278
  <title></title>
2279
  </head>
2280
  <body>
2281
+ <p>From '
2282
+ . $apbct->connection_reports['since']
2283
+ . ' to ' . date('d M') . ' has been made '
2284
+ . ($apbct->connection_reports['success'] + $apbct->connection_reports['negative'])
2285
+ . ' calls, where ' . $apbct->connection_reports['success'] . ' were success and '
2286
+ . $apbct->connection_reports['negative'] . ' were negative
2287
+ </p>
2288
  <p>Negative report:</p>
2289
  <table> <tr>
2290
  <td>&nbsp;</td>
2294
  <td><b>Server IP</b></td>
2295
  </tr>
2296
  ';
2297
+ foreach ( $apbct->connection_reports['negative_report'] as $key => $report ) {
2298
+ $message .= '<tr>'
2299
+ . '<td>' . ($key + 1) . '.</td>'
2300
+ . '<td>' . $report['date'] . '</td>'
2301
+ . '<td>' . $report['page_url'] . '</td>'
2302
+ . '<td>' . $report['lib_report'] . '</td>'
2303
+ . '<td>' . $report['work_url'] . '</td>'
2304
+ . '</tr>';
2305
+ }
2306
+ $message .= '</table></body></html>';
 
2307
 
2308
+ $headers = "Content-type: text/html; charset=windows-1251 \r\n";
2309
+ $headers .= 'From: ' . get_option('admin_email');
2310
+ mail($to, $subject, $message, $headers);
2311
  }
2312
 
2313
+ $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
2314
+ $apbct->data['connection_reports']['since'] = date('d M');
2315
+ $apbct->saveData();
2316
  }
2317
 
2318
  /**
2326
  */
2327
  function apbct_log($message = 'empty', $func = null, $params = array())
2328
  {
2329
+ global $apbct;
2330
 
2331
+ $debug = get_option(APBCT_DEBUG);
2332
 
2333
+ $function = $func ?: '';
2334
+ $cron = in_array('cron', $params);
2335
+ $data = in_array('data', $params);
2336
+ $settings = in_array('settings', $params);
2337
 
2338
+ if ( is_array($message) || is_object($message) ) {
2339
+ $message = print_r($message, true);
2340
+ }
2341
 
2342
+ if ( $message ) {
2343
+ $debug[date("H:i:s") . (int)microtime() . "_ACTION_" . current_filter() . "_FUNCTION_" . $function] = $message;
2344
+ }
2345
+ if ( $cron ) {
2346
+ $debug[date("H:i:s") . (int)microtime() . "_ACTION_" . current_filter(
2347
+ ) . "_FUNCTION_" . $function . '_cron'] = $apbct->cron;
2348
+ }
2349
+ if ( $data ) {
2350
+ $debug[date("H:i:s") . (int)microtime() . "_ACTION_" . current_filter(
2351
+ ) . "_FUNCTION_" . $function . '_data'] = $apbct->data;
2352
+ }
2353
+ if ( $settings ) {
2354
+ $debug[date("H:i:s") . (int)microtime() . "_ACTION_" . current_filter(
2355
+ ) . "_FUNCTION_" . $function . '_settings'] = $apbct->settings;
2356
+ }
2357
 
2358
+ update_option(APBCT_DEBUG, $debug);
2359
  }
2360
 
2361
+ function apbct_sfw__delete_tables($blog_id, $_drop)
2362
+ {
2363
+ global $wpdb;
2364
 
2365
+ $initial_blog = get_current_blog_id();
2366
 
2367
+ switch_to_blog($blog_id);
2368
+ $wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->prefix . 'cleantalk_sfw`;'); // Deleting SFW data
2369
+ $wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->prefix . 'cleantalk_sfw_logs`;'); // Deleting SFW logs
2370
+ $wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->prefix . 'cleantalk_ac_log`;'); // Deleting SFW logs
2371
+ $wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->prefix . 'cleantalk_ua_bl`;'); // Deleting AC UA black lists
2372
 
2373
+ switch_to_blog($initial_blog);
2374
  }
2375
 
2376
  /**
2380
  *
2381
  * @return boolean
2382
  */
2383
+ function apbct_is_user_enable($user = null)
2384
+ {
2385
+ global $current_user;
2386
 
2387
+ $user = $user !== null ? $user : $current_user;
2388
 
2389
+ return apbct_is_user_role_in(array('administrator', 'editor', 'author'), $user)
2390
+ ? false
2391
+ : true;
2392
  }
2393
 
2394
  /**
2399
  *
2400
  * @return boolean Does the user has this role|roles
2401
  */
2402
+ function apbct_is_user_role_in($roles, $user = false)
2403
+ {
2404
+ if ( is_numeric($user) && function_exists('get_userdata') ) {
2405
+ $user = get_userdata((int)$user);
2406
+ }
2407
+ if ( is_string($user) && function_exists('get_user_by') ) {
2408
+ $user = get_user_by('login', $user);
2409
+ }
2410
 
2411
+ if ( ! $user && function_exists('wp_get_current_user') ) {
2412
+ $user = wp_get_current_user();
2413
+ }
2414
 
2415
+ if ( ! $user ) {
2416
+ $user = apbct_wp_get_current_user();
2417
+ }
2418
 
2419
+ if ( empty($user->ID) ) {
2420
+ return false;
2421
+ }
2422
 
2423
+ foreach ( (array)$roles as $role ) {
2424
+ if ( isset($user->caps[strtolower($role)]) || in_array(strtolower($role), $user->roles) ) {
2425
+ return true;
2426
+ }
2427
+ }
2428
 
2429
+ return false;
2430
  }
2431
 
2432
  /**
2434
  *
2435
  * @param $exec_time
2436
  */
2437
+ function apbct_statistics__rotate($exec_time)
2438
+ {
2439
+ global $apbct;
2440
 
2441
+ // Delete old stats
2442
+ if ( min(array_keys($apbct->stats['requests'])) < time() - (86400 * 7) ) {
2443
+ unset($apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]);
2444
+ }
2445
 
2446
+ // Create new if newest older than 1 day
2447
+ if ( empty($apbct->stats['requests']) || max(array_keys($apbct->stats['requests'])) < time() - (86400 * 1) ) {
2448
+ $apbct->stats['requests'][time()] = array('amount' => 0, 'average_time' => 0);
2449
+ }
2450
 
2451
+ // Update all existing stats
2452
+ foreach ( $apbct->stats['requests'] as &$weak_stat ) {
2453
+ $weak_stat['average_time'] = ($weak_stat['average_time'] * $weak_stat['amount'] + $exec_time) / ++$weak_stat['amount'];
2454
+ }
2455
+ unset($weak_stat);
2456
 
2457
+ $apbct->save('stats');
2458
  }
2459
 
2460
  /**
2462
  *
2463
  * @global State $apbct
2464
  */
2465
+ function apbct_update_actions()
2466
+ {
2467
+ global $apbct;
 
 
 
 
 
 
 
 
2468
 
2469
+ // Update logic
2470
+ if ( $apbct->plugin_version !== APBCT_VERSION ) {
2471
+ // Main blog
2472
+ if ( is_main_site() ) {
2473
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-updater.php');
2474
 
2475
+ $result = apbct_run_update_actions($apbct->plugin_version, APBCT_VERSION);
 
 
 
2476
 
2477
+ //If update is successful
2478
+ if ( $result === true ) {
2479
+ apbct_update__set_version__from_plugin('from_plugin');
2480
+ }
2481
 
2482
+ ct_send_feedback('0:' . APBCT_AGENT); // Send feedback to let cloud know about updated version.
 
 
 
 
2483
 
2484
+ // Side blogs
2485
+ } else {
2486
+ apbct_update__set_version__from_plugin('from_plugin');
2487
+ }
2488
+ }
2489
  }
2490
 
2491
  /**
2492
  * Set version of plugin in database
2493
  *
2494
+ * @param string $ver
2495
  *
2496
  * @return bool
2497
  * @global State $apbct
2498
  *
2499
  */
2500
+ function apbct_update__set_version__from_plugin($ver)
2501
+ {
2502
+ global $apbct;
2503
+ switch ( true ) {
2504
+ case $ver === 'from_plugin':
2505
+ $apbct->data['plugin_version'] = APBCT_VERSION;
2506
+ break;
2507
+ case preg_match('/^\d+\.\d+(\.\d+)?(-[a-zA-Z0-9-_]+)?$/', $ver) === 1:
2508
+ $apbct->data['plugin_version'] = $ver;
2509
+ break;
2510
+ default:
2511
+ return false;
2512
+ }
2513
+ $apbct->saveData();
2514
+
2515
+ return true;
2516
  }
2517
 
2518
  /**
2520
  *
2521
  * @return array
2522
  */
2523
+ function apbct_test_connection()
2524
+ {
2525
+ $out = array();
2526
+ $url_to_test = array_keys(\Cleantalk\Common\Helper::$cleantalks_servers);
 
 
2527
 
2528
+ foreach ( $url_to_test as $url ) {
2529
+ $start = microtime(true);
2530
+ $result = \Cleantalk\ApbctWP\Helper::httpRequestGetContent($url);
2531
 
2532
  $out[$url] = array(
2533
+ 'result' => ! empty($result['error']) ? $result['error'] : 'OK',
2534
  'exec_time' => microtime(true) - $start,
2535
+ );
2536
  }
2537
 
2538
  return $out;
css/jquery-ui.min.css CHANGED
@@ -1,7 +1,7 @@
1
- /*! jQuery UI - v1.12.1 - 2020-01-10
2
- * http://jqueryui.com
3
- * Includes: draggable.css, core.css, resizable.css, selectable.css, sortable.css, accordion.css, autocomplete.css, menu.css, button.css, controlgroup.css, checkboxradio.css, datepicker.css, dialog.css, progressbar.css, selectmenu.css, slider.css, spinner.css, tabs.css, tooltip.css, theme.css
4
- * To view and modify this theme, visit http://jqueryui.com/themeroller/?scope=&folderName=base&cornerRadiusShadow=8px&offsetLeftShadow=0px&offsetTopShadow=0px&thicknessShadow=5px&opacityShadow=30&bgImgOpacityShadow=0&bgTextureShadow=flat&bgColorShadow=666666&opacityOverlay=30&bgImgOpacityOverlay=0&bgTextureOverlay=flat&bgColorOverlay=aaaaaa&iconColorError=cc0000&fcError=5f3f3f&borderColorError=f1a899&bgTextureError=flat&bgColorError=fddfdf&iconColorHighlight=777620&fcHighlight=777620&borderColorHighlight=dad55e&bgTextureHighlight=flat&bgColorHighlight=fffa90&iconColorActive=ffffff&fcActive=ffffff&borderColorActive=003eff&bgTextureActive=flat&bgColorActive=007fff&iconColorHover=555555&fcHover=2b2b2b&borderColorHover=cccccc&bgTextureHover=flat&bgColorHover=ededed&iconColorDefault=777777&fcDefault=454545&borderColorDefault=c5c5c5&bgTextureDefault=flat&bgColorDefault=f6f6f6&iconColorContent=444444&fcContent=333333&borderColorContent=dddddd&bgTextureContent=flat&bgColorContent=ffffff&iconColorHeader=444444&fcHeader=333333&borderColorHeader=dddddd&bgTextureHeader=flat&bgColorHeader=e9e9e9&cornerRadius=3px&fwDefault=normal&fsDefault=1em&ffDefault=Arial%2CHelvetica%2Csans-serif
5
- * Copyright jQuery Foundation and other contributors; Licensed MIT */
6
-
7
  .ui-draggable-handle{-ms-touch-action:none;touch-action:none}.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important;pointer-events:none}.ui-icon{display:inline-block;vertical-align:middle;margin-top:-.25em;position:relative;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-icon-block{left:50%;margin-left:-8px;display:block}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-resizable{position:relative}.ui-resizable-handle{position:absolute;font-size:0.1px;display:block;-ms-touch-action:none;touch-action:none}.ui-resizable-disabled .ui-resizable-handle,.ui-resizable-autohide .ui-resizable-handle{display:none}.ui-resizable-n{cursor:n-resize;height:7px;width:100%;top:-5px;left:0}.ui-resizable-s{cursor:s-resize;height:7px;width:100%;bottom:-5px;left:0}.ui-resizable-e{cursor:e-resize;width:7px;right:-5px;top:0;height:100%}.ui-resizable-w{cursor:w-resize;width:7px;left:-5px;top:0;height:100%}.ui-resizable-se{cursor:se-resize;width:12px;height:12px;right:1px;bottom:1px}.ui-resizable-sw{cursor:sw-resize;width:9px;height:9px;left:-5px;bottom:-5px}.ui-resizable-nw{cursor:nw-resize;width:9px;height:9px;left:-5px;top:-5px}.ui-resizable-ne{cursor:ne-resize;width:9px;height:9px;right:-5px;top:-5px}.ui-selectable{-ms-touch-action:none;touch-action:none}.ui-selectable-helper{position:absolute;z-index:100;border:1px dotted black}.ui-sortable-handle{-ms-touch-action:none;touch-action:none}.ui-accordion .ui-accordion-header{display:block;cursor:pointer;position:relative;margin:2px 0 0 0;padding:.5em .5em .5em .7em;font-size:100%}.ui-accordion .ui-accordion-content{padding:1em 2.2em;border-top:0;overflow:auto}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{margin:0;cursor:pointer;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")}.ui-menu .ui-menu-item-wrapper{position:relative;padding:3px 1em 3px .4em}.ui-menu .ui-menu-divider{margin:5px 0;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-state-focus,.ui-menu .ui-state-active{margin:-1px}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item-wrapper{padding-left:2em}.ui-menu .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-button{padding:.4em 1em;display:inline-block;position:relative;line-height:normal;margin-right:.1em;cursor:pointer;vertical-align:middle;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;overflow:visible}.ui-button,.ui-button:link,.ui-button:visited,.ui-button:hover,.ui-button:active{text-decoration:none}.ui-button-icon-only{width:2em;box-sizing:border-box;text-indent:-9999px;white-space:nowrap}input.ui-button.ui-button-icon-only{text-indent:0}.ui-button-icon-only .ui-icon{position:absolute;top:50%;left:50%;margin-top:-8px;margin-left:-8px}.ui-button.ui-icon-notext .ui-icon{padding:0;width:2.1em;height:2.1em;text-indent:-9999px;white-space:nowrap}input.ui-button.ui-icon-notext .ui-icon{width:auto;height:auto;text-indent:0;white-space:normal;padding:.4em 1em}input.ui-button::-moz-focus-inner,button.ui-button::-moz-focus-inner{border:0;padding:0}.ui-controlgroup{vertical-align:middle;display:inline-block}.ui-controlgroup > .ui-controlgroup-item{float:left;margin-left:0;margin-right:0}.ui-controlgroup > .ui-controlgroup-item:focus,.ui-controlgroup > .ui-controlgroup-item.ui-visual-focus{z-index:9999}.ui-controlgroup-vertical > .ui-controlgroup-item{display:block;float:none;width:100%;margin-top:0;margin-bottom:0;text-align:left}.ui-controlgroup-vertical .ui-controlgroup-item{box-sizing:border-box}.ui-controlgroup .ui-controlgroup-label{padding:.4em 1em}.ui-controlgroup .ui-controlgroup-label span{font-size:80%}.ui-controlgroup-horizontal .ui-controlgroup-label + .ui-controlgroup-item{border-left:none}.ui-controlgroup-vertical .ui-controlgroup-label + .ui-controlgroup-item{border-top:none}.ui-controlgroup-horizontal .ui-controlgroup-label.ui-widget-content{border-right:none}.ui-controlgroup-vertical .ui-controlgroup-label.ui-widget-content{border-bottom:none}.ui-controlgroup-vertical .ui-spinner-input{width:75%;width:calc( 100% - 2.4em )}.ui-controlgroup-vertical .ui-spinner .ui-spinner-up{border-top-style:solid}.ui-checkboxradio-label .ui-icon-background{box-shadow:inset 1px 1px 1px #ccc;border-radius:.12em;border:none}.ui-checkboxradio-radio-label .ui-icon-background{width:16px;height:16px;border-radius:1em;overflow:visible;border:none}.ui-checkboxradio-radio-label.ui-checkboxradio-checked .ui-icon,.ui-checkboxradio-radio-label.ui-checkboxradio-checked:hover .ui-icon{background-image:none;width:8px;height:8px;border-width:4px;border-style:solid}.ui-checkboxradio-disabled{pointer-events:none}.ui-datepicker{width:17em;padding:.2em .2em 0;display:none}.ui-datepicker .ui-datepicker-header{position:relative;padding:.2em 0}.ui-datepicker .ui-datepicker-prev,.ui-datepicker .ui-datepicker-next{position:absolute;top:2px;width:1.8em;height:1.8em}.ui-datepicker .ui-datepicker-prev-hover,.ui-datepicker .ui-datepicker-next-hover{top:1px}.ui-datepicker .ui-datepicker-prev{left:2px}.ui-datepicker .ui-datepicker-next{right:2px}.ui-datepicker .ui-datepicker-prev-hover{left:1px}.ui-datepicker .ui-datepicker-next-hover{right:1px}.ui-datepicker .ui-datepicker-prev span,.ui-datepicker .ui-datepicker-next span{display:block;position:absolute;left:50%;margin-left:-8px;top:50%;margin-top:-8px}.ui-datepicker .ui-datepicker-title{margin:0 2.3em;line-height:1.8em;text-align:center}.ui-datepicker .ui-datepicker-title select{font-size:1em;margin:1px 0}.ui-datepicker select.ui-datepicker-month,.ui-datepicker select.ui-datepicker-year{width:45%}.ui-datepicker table{width:100%;font-size:.9em;border-collapse:collapse;margin:0 0 .4em}.ui-datepicker th{padding:.7em .3em;text-align:center;font-weight:bold;border:0}.ui-datepicker td{border:0;padding:1px}.ui-datepicker td span,.ui-datepicker td a{display:block;padding:.2em;text-align:right;text-decoration:none}.ui-datepicker .ui-datepicker-buttonpane{background-image:none;margin:.7em 0 0 0;padding:0 .2em;border-left:0;border-right:0;border-bottom:0}.ui-datepicker .ui-datepicker-buttonpane button{float:right;margin:.5em .2em .4em;cursor:pointer;padding:.2em .6em .3em .6em;width:auto;overflow:visible}.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current{float:left}.ui-datepicker.ui-datepicker-multi{width:auto}.ui-datepicker-multi .ui-datepicker-group{float:left}.ui-datepicker-multi .ui-datepicker-group table{width:95%;margin:0 auto .4em}.ui-datepicker-multi-2 .ui-datepicker-group{width:50%}.ui-datepicker-multi-3 .ui-datepicker-group{width:33.3%}.ui-datepicker-multi-4 .ui-datepicker-group{width:25%}.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header{border-left-width:0}.ui-datepicker-multi .ui-datepicker-buttonpane{clear:left}.ui-datepicker-row-break{clear:both;width:100%;font-size:0}.ui-datepicker-rtl{direction:rtl}.ui-datepicker-rtl .ui-datepicker-prev{right:2px;left:auto}.ui-datepicker-rtl .ui-datepicker-next{left:2px;right:auto}.ui-datepicker-rtl .ui-datepicker-prev:hover{right:1px;left:auto}.ui-datepicker-rtl .ui-datepicker-next:hover{left:1px;right:auto}.ui-datepicker-rtl .ui-datepicker-buttonpane{clear:right}.ui-datepicker-rtl .ui-datepicker-buttonpane button{float:left}.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current,.ui-datepicker-rtl .ui-datepicker-group{float:right}.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header{border-right-width:0;border-left-width:1px}.ui-datepicker .ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat;left:.5em;top:.3em}.ui-dialog{position:absolute;top:0;left:0;padding:.2em;outline:0}.ui-dialog .ui-dialog-titlebar{padding:.4em 1em;position:relative}.ui-dialog .ui-dialog-title{float:left;margin:.1em 0;white-space:nowrap;width:90%;overflow:hidden;text-overflow:ellipsis}.ui-dialog .ui-dialog-titlebar-close{position:absolute;right:.3em;top:50%;width:20px;margin:-10px 0 0 0;padding:1px;height:20px}.ui-dialog .ui-dialog-content{position:relative;border:0;padding:.5em 1em;background:none;overflow:auto}.ui-dialog .ui-dialog-buttonpane{text-align:left;border-width:1px 0 0 0;background-image:none;margin-top:.5em;padding:.3em 1em .5em .4em}.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset{float:right}.ui-dialog .ui-dialog-buttonpane button{margin:.5em .4em .5em 0;cursor:pointer}.ui-dialog .ui-resizable-n{height:2px;top:0}.ui-dialog .ui-resizable-e{width:2px;right:0}.ui-dialog .ui-resizable-s{height:2px;bottom:0}.ui-dialog .ui-resizable-w{width:2px;left:0}.ui-dialog .ui-resizable-se,.ui-dialog .ui-resizable-sw,.ui-dialog .ui-resizable-ne,.ui-dialog .ui-resizable-nw{width:7px;height:7px}.ui-dialog .ui-resizable-se{right:0;bottom:0}.ui-dialog .ui-resizable-sw{left:0;bottom:0}.ui-dialog .ui-resizable-ne{right:0;top:0}.ui-dialog .ui-resizable-nw{left:0;top:0}.ui-draggable .ui-dialog-titlebar{cursor:move}.ui-progressbar{height:2em;text-align:left;overflow:hidden}.ui-progressbar .ui-progressbar-value{margin:-1px;height:100%}.ui-progressbar .ui-progressbar-overlay{background:url("data:image/gif;base64,R0lGODlhKAAoAIABAAAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQJAQABACwAAAAAKAAoAAACkYwNqXrdC52DS06a7MFZI+4FHBCKoDeWKXqymPqGqxvJrXZbMx7Ttc+w9XgU2FB3lOyQRWET2IFGiU9m1frDVpxZZc6bfHwv4c1YXP6k1Vdy292Fb6UkuvFtXpvWSzA+HycXJHUXiGYIiMg2R6W459gnWGfHNdjIqDWVqemH2ekpObkpOlppWUqZiqr6edqqWQAAIfkECQEAAQAsAAAAACgAKAAAApSMgZnGfaqcg1E2uuzDmmHUBR8Qil95hiPKqWn3aqtLsS18y7G1SzNeowWBENtQd+T1JktP05nzPTdJZlR6vUxNWWjV+vUWhWNkWFwxl9VpZRedYcflIOLafaa28XdsH/ynlcc1uPVDZxQIR0K25+cICCmoqCe5mGhZOfeYSUh5yJcJyrkZWWpaR8doJ2o4NYq62lAAACH5BAkBAAEALAAAAAAoACgAAAKVDI4Yy22ZnINRNqosw0Bv7i1gyHUkFj7oSaWlu3ovC8GxNso5fluz3qLVhBVeT/Lz7ZTHyxL5dDalQWPVOsQWtRnuwXaFTj9jVVh8pma9JjZ4zYSj5ZOyma7uuolffh+IR5aW97cHuBUXKGKXlKjn+DiHWMcYJah4N0lYCMlJOXipGRr5qdgoSTrqWSq6WFl2ypoaUAAAIfkECQEAAQAsAAAAACgAKAAAApaEb6HLgd/iO7FNWtcFWe+ufODGjRfoiJ2akShbueb0wtI50zm02pbvwfWEMWBQ1zKGlLIhskiEPm9R6vRXxV4ZzWT2yHOGpWMyorblKlNp8HmHEb/lCXjcW7bmtXP8Xt229OVWR1fod2eWqNfHuMjXCPkIGNileOiImVmCOEmoSfn3yXlJWmoHGhqp6ilYuWYpmTqKUgAAIfkECQEAAQAsAAAAACgAKAAAApiEH6kb58biQ3FNWtMFWW3eNVcojuFGfqnZqSebuS06w5V80/X02pKe8zFwP6EFWOT1lDFk8rGERh1TTNOocQ61Hm4Xm2VexUHpzjymViHrFbiELsefVrn6XKfnt2Q9G/+Xdie499XHd2g4h7ioOGhXGJboGAnXSBnoBwKYyfioubZJ2Hn0RuRZaflZOil56Zp6iioKSXpUAAAh+QQJAQABACwAAAAAKAAoAAACkoQRqRvnxuI7kU1a1UU5bd5tnSeOZXhmn5lWK3qNTWvRdQxP8qvaC+/yaYQzXO7BMvaUEmJRd3TsiMAgswmNYrSgZdYrTX6tSHGZO73ezuAw2uxuQ+BbeZfMxsexY35+/Qe4J1inV0g4x3WHuMhIl2jXOKT2Q+VU5fgoSUI52VfZyfkJGkha6jmY+aaYdirq+lQAACH5BAkBAAEALAAAAAAoACgAAAKWBIKpYe0L3YNKToqswUlvznigd4wiR4KhZrKt9Upqip61i9E3vMvxRdHlbEFiEXfk9YARYxOZZD6VQ2pUunBmtRXo1Lf8hMVVcNl8JafV38aM2/Fu5V16Bn63r6xt97j09+MXSFi4BniGFae3hzbH9+hYBzkpuUh5aZmHuanZOZgIuvbGiNeomCnaxxap2upaCZsq+1kAACH5BAkBAAEALAAAAAAoACgAAAKXjI8By5zf4kOxTVrXNVlv1X0d8IGZGKLnNpYtm8Lr9cqVeuOSvfOW79D9aDHizNhDJidFZhNydEahOaDH6nomtJjp1tutKoNWkvA6JqfRVLHU/QUfau9l2x7G54d1fl995xcIGAdXqMfBNadoYrhH+Mg2KBlpVpbluCiXmMnZ2Sh4GBqJ+ckIOqqJ6LmKSllZmsoq6wpQAAAh+QQJAQABACwAAAAAKAAoAAAClYx/oLvoxuJDkU1a1YUZbJ59nSd2ZXhWqbRa2/gF8Gu2DY3iqs7yrq+xBYEkYvFSM8aSSObE+ZgRl1BHFZNr7pRCavZ5BW2142hY3AN/zWtsmf12p9XxxFl2lpLn1rseztfXZjdIWIf2s5dItwjYKBgo9yg5pHgzJXTEeGlZuenpyPmpGQoKOWkYmSpaSnqKileI2FAAACH5BAkBAAEALAAAAAAoACgAAAKVjB+gu+jG4kORTVrVhRlsnn2dJ3ZleFaptFrb+CXmO9OozeL5VfP99HvAWhpiUdcwkpBH3825AwYdU8xTqlLGhtCosArKMpvfa1mMRae9VvWZfeB2XfPkeLmm18lUcBj+p5dnN8jXZ3YIGEhYuOUn45aoCDkp16hl5IjYJvjWKcnoGQpqyPlpOhr3aElaqrq56Bq7VAAAOw==");height:100%;filter:alpha(opacity=25);opacity:0.25}.ui-progressbar-indeterminate .ui-progressbar-value{background-image:none}.ui-selectmenu-menu{padding:0;margin:0;position:absolute;top:0;left:0;display:none}.ui-selectmenu-menu .ui-menu{overflow:auto;overflow-x:hidden;padding-bottom:1px}.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup{font-size:1em;font-weight:bold;line-height:1.5;padding:2px 0.4em;margin:0.5em 0 0 0;height:auto;border:0}.ui-selectmenu-open{display:block}.ui-selectmenu-text{display:block;margin-right:20px;overflow:hidden;text-overflow:ellipsis}.ui-selectmenu-button.ui-button{text-align:left;white-space:nowrap;width:14em}.ui-selectmenu-icon.ui-icon{float:right;margin-top:0}.ui-slider{position:relative;text-align:left}.ui-slider .ui-slider-handle{position:absolute;z-index:2;width:1.2em;height:1.2em;cursor:default;-ms-touch-action:none;touch-action:none}.ui-slider .ui-slider-range{position:absolute;z-index:1;font-size:.7em;display:block;border:0;background-position:0 0}.ui-slider.ui-state-disabled .ui-slider-handle,.ui-slider.ui-state-disabled .ui-slider-range{filter:inherit}.ui-slider-horizontal{height:.8em}.ui-slider-horizontal .ui-slider-handle{top:-.3em;margin-left:-.6em}.ui-slider-horizontal .ui-slider-range{top:0;height:100%}.ui-slider-horizontal .ui-slider-range-min{left:0}.ui-slider-horizontal .ui-slider-range-max{right:0}.ui-slider-vertical{width:.8em;height:100px}.ui-slider-vertical .ui-slider-handle{left:-.3em;margin-left:0;margin-bottom:-.6em}.ui-slider-vertical .ui-slider-range{left:0;width:100%}.ui-slider-vertical .ui-slider-range-min{bottom:0}.ui-slider-vertical .ui-slider-range-max{top:0}.ui-spinner{position:relative;display:inline-block;overflow:hidden;padding:0;vertical-align:middle}.ui-spinner-input{border:none;background:none;color:inherit;padding:.222em 0;margin:.2em 0;vertical-align:middle;margin-left:.4em;margin-right:2em}.ui-spinner-button{width:1.6em;height:50%;font-size:.5em;padding:0;margin:0;text-align:center;position:absolute;cursor:default;display:block;overflow:hidden;right:0}.ui-spinner a.ui-spinner-button{border-top-style:none;border-bottom-style:none;border-right-style:none}.ui-spinner-up{top:0}.ui-spinner-down{bottom:0}.ui-tabs{position:relative;padding:.2em}.ui-tabs .ui-tabs-nav{margin:0;padding:.2em .2em 0}.ui-tabs .ui-tabs-nav li{list-style:none;float:left;position:relative;top:0;margin:1px .2em 0 0;border-bottom-width:0;padding:0;white-space:nowrap}.ui-tabs .ui-tabs-nav .ui-tabs-anchor{float:left;padding:.5em 1em;text-decoration:none}.ui-tabs .ui-tabs-nav li.ui-tabs-active{margin-bottom:-1px;padding-bottom:1px}.ui-tabs .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor,.ui-tabs .ui-tabs-nav li.ui-state-disabled .ui-tabs-anchor,.ui-tabs .ui-tabs-nav li.ui-tabs-loading .ui-tabs-anchor{cursor:text}.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor{cursor:pointer}.ui-tabs .ui-tabs-panel{display:block;border-width:0;padding:1em 1.4em;background:none}.ui-tooltip{padding:8px;position:absolute;z-index:9999;max-width:300px}body .ui-tooltip{border-width:2px}.ui-widget{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget.ui-widget-content{border:1px solid #c5c5c5}.ui-widget-content{border:1px solid #ddd;background:#fff;color:#333}.ui-widget-content a{color:#333}.ui-widget-header{border:1px solid #ddd;background:#e9e9e9;color:#333;font-weight:bold}.ui-widget-header a{color:#333}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default,.ui-button,html .ui-button.ui-state-disabled:hover,html .ui-button.ui-state-disabled:active{border:1px solid #c5c5c5;background:#f6f6f6;font-weight:normal;color:#454545}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited,a.ui-button,a:link.ui-button,a:visited.ui-button,.ui-button{color:#454545;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus,.ui-button:hover,.ui-button:focus{border:1px solid #ccc;background:#ededed;font-weight:normal;color:#2b2b2b}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited,.ui-state-focus a,.ui-state-focus a:hover,.ui-state-focus a:link,.ui-state-focus a:visited,a.ui-button:hover,a.ui-button:focus{color:#2b2b2b;text-decoration:none}.ui-visual-focus{box-shadow:0 0 3px 1px rgb(94,158,214)}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active,a.ui-button:active,.ui-button:active,.ui-button.ui-state-active:hover{border:1px solid #003eff;background:#007fff;font-weight:normal;color:#fff}.ui-icon-background,.ui-state-active .ui-icon-background{border:#003eff;background-color:#fff}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#fff;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #dad55e;background:#fffa90;color:#777620}.ui-state-checked{border:1px solid #dad55e;background:#fffa90}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#777620}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #f1a899;background:#fddfdf;color:#5f3f3f}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#5f3f3f}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#5f3f3f}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-widget-header .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button:hover .ui-icon,.ui-button:focus .ui-icon{background-image:url("images/ui-icons_555555_256x240.png")}.ui-state-active .ui-icon,.ui-button:active .ui-icon{background-image:url("images/ui-icons_ffffff_256x240.png")}.ui-state-highlight .ui-icon,.ui-button .ui-state-highlight.ui-icon{background-image:url("images/ui-icons_777620_256x240.png")}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url("images/ui-icons_cc0000_256x240.png")}.ui-button .ui-icon{background-image:url("images/ui-icons_777777_256x240.png")}.ui-icon-blank{background-position:16px 16px}.ui-icon-caret-1-n{background-position:0 0}.ui-icon-caret-1-ne{background-position:-16px 0}.ui-icon-caret-1-e{background-position:-32px 0}.ui-icon-caret-1-se{background-position:-48px 0}.ui-icon-caret-1-s{background-position:-65px 0}.ui-icon-caret-1-sw{background-position:-80px 0}.ui-icon-caret-1-w{background-position:-96px 0}.ui-icon-caret-1-nw{background-position:-112px 0}.ui-icon-caret-2-n-s{background-position:-128px 0}.ui-icon-caret-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-65px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-65px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:1px -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:3px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:3px}.ui-widget-overlay{background:#aaa;opacity:.3;filter:Alpha(Opacity=30)}.ui-widget-shadow{-webkit-box-shadow:0 0 5px #666;box-shadow:0 0 5px #666}
1
+ /*! jQuery UI - v1.12.1 - 2020-01-10
2
+ * http://jqueryui.com
3
+ * Includes: draggable.css, core.css, resizable.css, selectable.css, sortable.css, accordion.css, autocomplete.css, menu.css, button.css, controlgroup.css, checkboxradio.css, datepicker.css, dialog.css, progressbar.css, selectmenu.css, slider.css, spinner.css, tabs.css, tooltip.css, theme.css
4
+ * To view and modify this theme, visit http://jqueryui.com/themeroller/?scope=&folderName=base&cornerRadiusShadow=8px&offsetLeftShadow=0px&offsetTopShadow=0px&thicknessShadow=5px&opacityShadow=30&bgImgOpacityShadow=0&bgTextureShadow=flat&bgColorShadow=666666&opacityOverlay=30&bgImgOpacityOverlay=0&bgTextureOverlay=flat&bgColorOverlay=aaaaaa&iconColorError=cc0000&fcError=5f3f3f&borderColorError=f1a899&bgTextureError=flat&bgColorError=fddfdf&iconColorHighlight=777620&fcHighlight=777620&borderColorHighlight=dad55e&bgTextureHighlight=flat&bgColorHighlight=fffa90&iconColorActive=ffffff&fcActive=ffffff&borderColorActive=003eff&bgTextureActive=flat&bgColorActive=007fff&iconColorHover=555555&fcHover=2b2b2b&borderColorHover=cccccc&bgTextureHover=flat&bgColorHover=ededed&iconColorDefault=777777&fcDefault=454545&borderColorDefault=c5c5c5&bgTextureDefault=flat&bgColorDefault=f6f6f6&iconColorContent=444444&fcContent=333333&borderColorContent=dddddd&bgTextureContent=flat&bgColorContent=ffffff&iconColorHeader=444444&fcHeader=333333&borderColorHeader=dddddd&bgTextureHeader=flat&bgColorHeader=e9e9e9&cornerRadius=3px&fwDefault=normal&fsDefault=1em&ffDefault=Arial%2CHelvetica%2Csans-serif
5
+ * Copyright jQuery Foundation and other contributors; Licensed MIT */
6
+
7
  .ui-draggable-handle{-ms-touch-action:none;touch-action:none}.ui-helper-hidden{display:none}.ui-helper-hidden-accessible{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px}.ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none}.ui-helper-clearfix:before,.ui-helper-clearfix:after{content:"";display:table;border-collapse:collapse}.ui-helper-clearfix:after{clear:both}.ui-helper-zfix{width:100%;height:100%;top:0;left:0;position:absolute;opacity:0;filter:Alpha(Opacity=0)}.ui-front{z-index:100}.ui-state-disabled{cursor:default!important;pointer-events:none}.ui-icon{display:inline-block;vertical-align:middle;margin-top:-.25em;position:relative;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat}.ui-widget-icon-block{left:50%;margin-left:-8px;display:block}.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-resizable{position:relative}.ui-resizable-handle{position:absolute;font-size:0.1px;display:block;-ms-touch-action:none;touch-action:none}.ui-resizable-disabled .ui-resizable-handle,.ui-resizable-autohide .ui-resizable-handle{display:none}.ui-resizable-n{cursor:n-resize;height:7px;width:100%;top:-5px;left:0}.ui-resizable-s{cursor:s-resize;height:7px;width:100%;bottom:-5px;left:0}.ui-resizable-e{cursor:e-resize;width:7px;right:-5px;top:0;height:100%}.ui-resizable-w{cursor:w-resize;width:7px;left:-5px;top:0;height:100%}.ui-resizable-se{cursor:se-resize;width:12px;height:12px;right:1px;bottom:1px}.ui-resizable-sw{cursor:sw-resize;width:9px;height:9px;left:-5px;bottom:-5px}.ui-resizable-nw{cursor:nw-resize;width:9px;height:9px;left:-5px;top:-5px}.ui-resizable-ne{cursor:ne-resize;width:9px;height:9px;right:-5px;top:-5px}.ui-selectable{-ms-touch-action:none;touch-action:none}.ui-selectable-helper{position:absolute;z-index:100;border:1px dotted black}.ui-sortable-handle{-ms-touch-action:none;touch-action:none}.ui-accordion .ui-accordion-header{display:block;cursor:pointer;position:relative;margin:2px 0 0 0;padding:.5em .5em .5em .7em;font-size:100%}.ui-accordion .ui-accordion-content{padding:1em 2.2em;border-top:0;overflow:auto}.ui-autocomplete{position:absolute;top:0;left:0;cursor:default}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{margin:0;cursor:pointer;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")}.ui-menu .ui-menu-item-wrapper{position:relative;padding:3px 1em 3px .4em}.ui-menu .ui-menu-divider{margin:5px 0;height:0;font-size:0;line-height:0;border-width:1px 0 0 0}.ui-menu .ui-state-focus,.ui-menu .ui-state-active{margin:-1px}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item-wrapper{padding-left:2em}.ui-menu .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-button{padding:.4em 1em;display:inline-block;position:relative;line-height:normal;margin-right:.1em;cursor:pointer;vertical-align:middle;text-align:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;overflow:visible}.ui-button,.ui-button:link,.ui-button:visited,.ui-button:hover,.ui-button:active{text-decoration:none}.ui-button-icon-only{width:2em;box-sizing:border-box;text-indent:-9999px;white-space:nowrap}input.ui-button.ui-button-icon-only{text-indent:0}.ui-button-icon-only .ui-icon{position:absolute;top:50%;left:50%;margin-top:-8px;margin-left:-8px}.ui-button.ui-icon-notext .ui-icon{padding:0;width:2.1em;height:2.1em;text-indent:-9999px;white-space:nowrap}input.ui-button.ui-icon-notext .ui-icon{width:auto;height:auto;text-indent:0;white-space:normal;padding:.4em 1em}input.ui-button::-moz-focus-inner,button.ui-button::-moz-focus-inner{border:0;padding:0}.ui-controlgroup{vertical-align:middle;display:inline-block}.ui-controlgroup > .ui-controlgroup-item{float:left;margin-left:0;margin-right:0}.ui-controlgroup > .ui-controlgroup-item:focus,.ui-controlgroup > .ui-controlgroup-item.ui-visual-focus{z-index:9999}.ui-controlgroup-vertical > .ui-controlgroup-item{display:block;float:none;width:100%;margin-top:0;margin-bottom:0;text-align:left}.ui-controlgroup-vertical .ui-controlgroup-item{box-sizing:border-box}.ui-controlgroup .ui-controlgroup-label{padding:.4em 1em}.ui-controlgroup .ui-controlgroup-label span{font-size:80%}.ui-controlgroup-horizontal .ui-controlgroup-label + .ui-controlgroup-item{border-left:none}.ui-controlgroup-vertical .ui-controlgroup-label + .ui-controlgroup-item{border-top:none}.ui-controlgroup-horizontal .ui-controlgroup-label.ui-widget-content{border-right:none}.ui-controlgroup-vertical .ui-controlgroup-label.ui-widget-content{border-bottom:none}.ui-controlgroup-vertical .ui-spinner-input{width:75%;width:calc( 100% - 2.4em )}.ui-controlgroup-vertical .ui-spinner .ui-spinner-up{border-top-style:solid}.ui-checkboxradio-label .ui-icon-background{box-shadow:inset 1px 1px 1px #ccc;border-radius:.12em;border:none}.ui-checkboxradio-radio-label .ui-icon-background{width:16px;height:16px;border-radius:1em;overflow:visible;border:none}.ui-checkboxradio-radio-label.ui-checkboxradio-checked .ui-icon,.ui-checkboxradio-radio-label.ui-checkboxradio-checked:hover .ui-icon{background-image:none;width:8px;height:8px;border-width:4px;border-style:solid}.ui-checkboxradio-disabled{pointer-events:none}.ui-datepicker{width:17em;padding:.2em .2em 0;display:none}.ui-datepicker .ui-datepicker-header{position:relative;padding:.2em 0}.ui-datepicker .ui-datepicker-prev,.ui-datepicker .ui-datepicker-next{position:absolute;top:2px;width:1.8em;height:1.8em}.ui-datepicker .ui-datepicker-prev-hover,.ui-datepicker .ui-datepicker-next-hover{top:1px}.ui-datepicker .ui-datepicker-prev{left:2px}.ui-datepicker .ui-datepicker-next{right:2px}.ui-datepicker .ui-datepicker-prev-hover{left:1px}.ui-datepicker .ui-datepicker-next-hover{right:1px}.ui-datepicker .ui-datepicker-prev span,.ui-datepicker .ui-datepicker-next span{display:block;position:absolute;left:50%;margin-left:-8px;top:50%;margin-top:-8px}.ui-datepicker .ui-datepicker-title{margin:0 2.3em;line-height:1.8em;text-align:center}.ui-datepicker .ui-datepicker-title select{font-size:1em;margin:1px 0}.ui-datepicker select.ui-datepicker-month,.ui-datepicker select.ui-datepicker-year{width:45%}.ui-datepicker table{width:100%;font-size:.9em;border-collapse:collapse;margin:0 0 .4em}.ui-datepicker th{padding:.7em .3em;text-align:center;font-weight:bold;border:0}.ui-datepicker td{border:0;padding:1px}.ui-datepicker td span,.ui-datepicker td a{display:block;padding:.2em;text-align:right;text-decoration:none}.ui-datepicker .ui-datepicker-buttonpane{background-image:none;margin:.7em 0 0 0;padding:0 .2em;border-left:0;border-right:0;border-bottom:0}.ui-datepicker .ui-datepicker-buttonpane button{float:right;margin:.5em .2em .4em;cursor:pointer;padding:.2em .6em .3em .6em;width:auto;overflow:visible}.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current{float:left}.ui-datepicker.ui-datepicker-multi{width:auto}.ui-datepicker-multi .ui-datepicker-group{float:left}.ui-datepicker-multi .ui-datepicker-group table{width:95%;margin:0 auto .4em}.ui-datepicker-multi-2 .ui-datepicker-group{width:50%}.ui-datepicker-multi-3 .ui-datepicker-group{width:33.3%}.ui-datepicker-multi-4 .ui-datepicker-group{width:25%}.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header{border-left-width:0}.ui-datepicker-multi .ui-datepicker-buttonpane{clear:left}.ui-datepicker-row-break{clear:both;width:100%;font-size:0}.ui-datepicker-rtl{direction:rtl}.ui-datepicker-rtl .ui-datepicker-prev{right:2px;left:auto}.ui-datepicker-rtl .ui-datepicker-next{left:2px;right:auto}.ui-datepicker-rtl .ui-datepicker-prev:hover{right:1px;left:auto}.ui-datepicker-rtl .ui-datepicker-next:hover{left:1px;right:auto}.ui-datepicker-rtl .ui-datepicker-buttonpane{clear:right}.ui-datepicker-rtl .ui-datepicker-buttonpane button{float:left}.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current,.ui-datepicker-rtl .ui-datepicker-group{float:right}.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header,.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header{border-right-width:0;border-left-width:1px}.ui-datepicker .ui-icon{display:block;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat;left:.5em;top:.3em}.ui-dialog{position:absolute;top:0;left:0;padding:.2em;outline:0}.ui-dialog .ui-dialog-titlebar{padding:.4em 1em;position:relative}.ui-dialog .ui-dialog-title{float:left;margin:.1em 0;white-space:nowrap;width:90%;overflow:hidden;text-overflow:ellipsis}.ui-dialog .ui-dialog-titlebar-close{position:absolute;right:.3em;top:50%;width:20px;margin:-10px 0 0 0;padding:1px;height:20px}.ui-dialog .ui-dialog-content{position:relative;border:0;padding:.5em 1em;background:none;overflow:auto}.ui-dialog .ui-dialog-buttonpane{text-align:left;border-width:1px 0 0 0;background-image:none;margin-top:.5em;padding:.3em 1em .5em .4em}.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset{float:right}.ui-dialog .ui-dialog-buttonpane button{margin:.5em .4em .5em 0;cursor:pointer}.ui-dialog .ui-resizable-n{height:2px;top:0}.ui-dialog .ui-resizable-e{width:2px;right:0}.ui-dialog .ui-resizable-s{height:2px;bottom:0}.ui-dialog .ui-resizable-w{width:2px;left:0}.ui-dialog .ui-resizable-se,.ui-dialog .ui-resizable-sw,.ui-dialog .ui-resizable-ne,.ui-dialog .ui-resizable-nw{width:7px;height:7px}.ui-dialog .ui-resizable-se{right:0;bottom:0}.ui-dialog .ui-resizable-sw{left:0;bottom:0}.ui-dialog .ui-resizable-ne{right:0;top:0}.ui-dialog .ui-resizable-nw{left:0;top:0}.ui-draggable .ui-dialog-titlebar{cursor:move}.ui-progressbar{height:2em;text-align:left;overflow:hidden}.ui-progressbar .ui-progressbar-value{margin:-1px;height:100%}.ui-progressbar .ui-progressbar-overlay{background:url("data:image/gif;base64,R0lGODlhKAAoAIABAAAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQJAQABACwAAAAAKAAoAAACkYwNqXrdC52DS06a7MFZI+4FHBCKoDeWKXqymPqGqxvJrXZbMx7Ttc+w9XgU2FB3lOyQRWET2IFGiU9m1frDVpxZZc6bfHwv4c1YXP6k1Vdy292Fb6UkuvFtXpvWSzA+HycXJHUXiGYIiMg2R6W459gnWGfHNdjIqDWVqemH2ekpObkpOlppWUqZiqr6edqqWQAAIfkECQEAAQAsAAAAACgAKAAAApSMgZnGfaqcg1E2uuzDmmHUBR8Qil95hiPKqWn3aqtLsS18y7G1SzNeowWBENtQd+T1JktP05nzPTdJZlR6vUxNWWjV+vUWhWNkWFwxl9VpZRedYcflIOLafaa28XdsH/ynlcc1uPVDZxQIR0K25+cICCmoqCe5mGhZOfeYSUh5yJcJyrkZWWpaR8doJ2o4NYq62lAAACH5BAkBAAEALAAAAAAoACgAAAKVDI4Yy22ZnINRNqosw0Bv7i1gyHUkFj7oSaWlu3ovC8GxNso5fluz3qLVhBVeT/Lz7ZTHyxL5dDalQWPVOsQWtRnuwXaFTj9jVVh8pma9JjZ4zYSj5ZOyma7uuolffh+IR5aW97cHuBUXKGKXlKjn+DiHWMcYJah4N0lYCMlJOXipGRr5qdgoSTrqWSq6WFl2ypoaUAAAIfkECQEAAQAsAAAAACgAKAAAApaEb6HLgd/iO7FNWtcFWe+ufODGjRfoiJ2akShbueb0wtI50zm02pbvwfWEMWBQ1zKGlLIhskiEPm9R6vRXxV4ZzWT2yHOGpWMyorblKlNp8HmHEb/lCXjcW7bmtXP8Xt229OVWR1fod2eWqNfHuMjXCPkIGNileOiImVmCOEmoSfn3yXlJWmoHGhqp6ilYuWYpmTqKUgAAIfkECQEAAQAsAAAAACgAKAAAApiEH6kb58biQ3FNWtMFWW3eNVcojuFGfqnZqSebuS06w5V80/X02pKe8zFwP6EFWOT1lDFk8rGERh1TTNOocQ61Hm4Xm2VexUHpzjymViHrFbiELsefVrn6XKfnt2Q9G/+Xdie499XHd2g4h7ioOGhXGJboGAnXSBnoBwKYyfioubZJ2Hn0RuRZaflZOil56Zp6iioKSXpUAAAh+QQJAQABACwAAAAAKAAoAAACkoQRqRvnxuI7kU1a1UU5bd5tnSeOZXhmn5lWK3qNTWvRdQxP8qvaC+/yaYQzXO7BMvaUEmJRd3TsiMAgswmNYrSgZdYrTX6tSHGZO73ezuAw2uxuQ+BbeZfMxsexY35+/Qe4J1inV0g4x3WHuMhIl2jXOKT2Q+VU5fgoSUI52VfZyfkJGkha6jmY+aaYdirq+lQAACH5BAkBAAEALAAAAAAoACgAAAKWBIKpYe0L3YNKToqswUlvznigd4wiR4KhZrKt9Upqip61i9E3vMvxRdHlbEFiEXfk9YARYxOZZD6VQ2pUunBmtRXo1Lf8hMVVcNl8JafV38aM2/Fu5V16Bn63r6xt97j09+MXSFi4BniGFae3hzbH9+hYBzkpuUh5aZmHuanZOZgIuvbGiNeomCnaxxap2upaCZsq+1kAACH5BAkBAAEALAAAAAAoACgAAAKXjI8By5zf4kOxTVrXNVlv1X0d8IGZGKLnNpYtm8Lr9cqVeuOSvfOW79D9aDHizNhDJidFZhNydEahOaDH6nomtJjp1tutKoNWkvA6JqfRVLHU/QUfau9l2x7G54d1fl995xcIGAdXqMfBNadoYrhH+Mg2KBlpVpbluCiXmMnZ2Sh4GBqJ+ckIOqqJ6LmKSllZmsoq6wpQAAAh+QQJAQABACwAAAAAKAAoAAAClYx/oLvoxuJDkU1a1YUZbJ59nSd2ZXhWqbRa2/gF8Gu2DY3iqs7yrq+xBYEkYvFSM8aSSObE+ZgRl1BHFZNr7pRCavZ5BW2142hY3AN/zWtsmf12p9XxxFl2lpLn1rseztfXZjdIWIf2s5dItwjYKBgo9yg5pHgzJXTEeGlZuenpyPmpGQoKOWkYmSpaSnqKileI2FAAACH5BAkBAAEALAAAAAAoACgAAAKVjB+gu+jG4kORTVrVhRlsnn2dJ3ZleFaptFrb+CXmO9OozeL5VfP99HvAWhpiUdcwkpBH3825AwYdU8xTqlLGhtCosArKMpvfa1mMRae9VvWZfeB2XfPkeLmm18lUcBj+p5dnN8jXZ3YIGEhYuOUn45aoCDkp16hl5IjYJvjWKcnoGQpqyPlpOhr3aElaqrq56Bq7VAAAOw==");height:100%;filter:alpha(opacity=25);opacity:0.25}.ui-progressbar-indeterminate .ui-progressbar-value{background-image:none}.ui-selectmenu-menu{padding:0;margin:0;position:absolute;top:0;left:0;display:none}.ui-selectmenu-menu .ui-menu{overflow:auto;overflow-x:hidden;padding-bottom:1px}.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup{font-size:1em;font-weight:bold;line-height:1.5;padding:2px 0.4em;margin:0.5em 0 0 0;height:auto;border:0}.ui-selectmenu-open{display:block}.ui-selectmenu-text{display:block;margin-right:20px;overflow:hidden;text-overflow:ellipsis}.ui-selectmenu-button.ui-button{text-align:left;white-space:nowrap;width:14em}.ui-selectmenu-icon.ui-icon{float:right;margin-top:0}.ui-slider{position:relative;text-align:left}.ui-slider .ui-slider-handle{position:absolute;z-index:2;width:1.2em;height:1.2em;cursor:default;-ms-touch-action:none;touch-action:none}.ui-slider .ui-slider-range{position:absolute;z-index:1;font-size:.7em;display:block;border:0;background-position:0 0}.ui-slider.ui-state-disabled .ui-slider-handle,.ui-slider.ui-state-disabled .ui-slider-range{filter:inherit}.ui-slider-horizontal{height:.8em}.ui-slider-horizontal .ui-slider-handle{top:-.3em;margin-left:-.6em}.ui-slider-horizontal .ui-slider-range{top:0;height:100%}.ui-slider-horizontal .ui-slider-range-min{left:0}.ui-slider-horizontal .ui-slider-range-max{right:0}.ui-slider-vertical{width:.8em;height:100px}.ui-slider-vertical .ui-slider-handle{left:-.3em;margin-left:0;margin-bottom:-.6em}.ui-slider-vertical .ui-slider-range{left:0;width:100%}.ui-slider-vertical .ui-slider-range-min{bottom:0}.ui-slider-vertical .ui-slider-range-max{top:0}.ui-spinner{position:relative;display:inline-block;overflow:hidden;padding:0;vertical-align:middle}.ui-spinner-input{border:none;background:none;color:inherit;padding:.222em 0;margin:.2em 0;vertical-align:middle;margin-left:.4em;margin-right:2em}.ui-spinner-button{width:1.6em;height:50%;font-size:.5em;padding:0;margin:0;text-align:center;position:absolute;cursor:default;display:block;overflow:hidden;right:0}.ui-spinner a.ui-spinner-button{border-top-style:none;border-bottom-style:none;border-right-style:none}.ui-spinner-up{top:0}.ui-spinner-down{bottom:0}.ui-tabs{position:relative;padding:.2em}.ui-tabs .ui-tabs-nav{margin:0;padding:.2em .2em 0}.ui-tabs .ui-tabs-nav li{list-style:none;float:left;position:relative;top:0;margin:1px .2em 0 0;border-bottom-width:0;padding:0;white-space:nowrap}.ui-tabs .ui-tabs-nav .ui-tabs-anchor{float:left;padding:.5em 1em;text-decoration:none}.ui-tabs .ui-tabs-nav li.ui-tabs-active{margin-bottom:-1px;padding-bottom:1px}.ui-tabs .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor,.ui-tabs .ui-tabs-nav li.ui-state-disabled .ui-tabs-anchor,.ui-tabs .ui-tabs-nav li.ui-tabs-loading .ui-tabs-anchor{cursor:text}.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor{cursor:pointer}.ui-tabs .ui-tabs-panel{display:block;border-width:0;padding:1em 1.4em;background:none}.ui-tooltip{padding:8px;position:absolute;z-index:9999;max-width:300px}body .ui-tooltip{border-width:2px}.ui-widget{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget.ui-widget-content{border:1px solid #c5c5c5}.ui-widget-content{border:1px solid #ddd;background:#fff;color:#333}.ui-widget-content a{color:#333}.ui-widget-header{border:1px solid #ddd;background:#e9e9e9;color:#333;font-weight:bold}.ui-widget-header a{color:#333}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default,.ui-button,html .ui-button.ui-state-disabled:hover,html .ui-button.ui-state-disabled:active{border:1px solid #c5c5c5;background:#f6f6f6;font-weight:normal;color:#454545}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited,a.ui-button,a:link.ui-button,a:visited.ui-button,.ui-button{color:#454545;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus,.ui-button:hover,.ui-button:focus{border:1px solid #ccc;background:#ededed;font-weight:normal;color:#2b2b2b}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited,.ui-state-focus a,.ui-state-focus a:hover,.ui-state-focus a:link,.ui-state-focus a:visited,a.ui-button:hover,a.ui-button:focus{color:#2b2b2b;text-decoration:none}.ui-visual-focus{box-shadow:0 0 3px 1px rgb(94,158,214)}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active,a.ui-button:active,.ui-button:active,.ui-button.ui-state-active:hover{border:1px solid #003eff;background:#007fff;font-weight:normal;color:#fff}.ui-icon-background,.ui-state-active .ui-icon-background{border:#003eff;background-color:#fff}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#fff;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #dad55e;background:#fffa90;color:#777620}.ui-state-checked{border:1px solid #dad55e;background:#fffa90}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#777620}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #f1a899;background:#fddfdf;color:#5f3f3f}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#5f3f3f}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#5f3f3f}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-widget-header .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button:hover .ui-icon,.ui-button:focus .ui-icon{background-image:url("images/ui-icons_555555_256x240.png")}.ui-state-active .ui-icon,.ui-button:active .ui-icon{background-image:url("images/ui-icons_ffffff_256x240.png")}.ui-state-highlight .ui-icon,.ui-button .ui-state-highlight.ui-icon{background-image:url("images/ui-icons_777620_256x240.png")}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url("images/ui-icons_cc0000_256x240.png")}.ui-button .ui-icon{background-image:url("images/ui-icons_777777_256x240.png")}.ui-icon-blank{background-position:16px 16px}.ui-icon-caret-1-n{background-position:0 0}.ui-icon-caret-1-ne{background-position:-16px 0}.ui-icon-caret-1-e{background-position:-32px 0}.ui-icon-caret-1-se{background-position:-48px 0}.ui-icon-caret-1-s{background-position:-65px 0}.ui-icon-caret-1-sw{background-position:-80px 0}.ui-icon-caret-1-w{background-position:-96px 0}.ui-icon-caret-1-nw{background-position:-112px 0}.ui-icon-caret-2-n-s{background-position:-128px 0}.ui-icon-caret-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-65px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-65px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:1px -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:3px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:3px}.ui-widget-overlay{background:#aaa;opacity:.3;filter:Alpha(Opacity=30)}.ui-widget-shadow{-webkit-box-shadow:0 0 5px #666;box-shadow:0 0 5px #666}
css/jquery-ui.theme.min.css CHANGED
@@ -1,5 +1,5 @@
1
- /*! jQuery UI - v1.12.1 - 2020-01-10
2
- * http://jqueryui.com
3
- * Copyright jQuery Foundation and other contributors; Licensed MIT */
4
-
5
  .ui-widget{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget.ui-widget-content{border:1px solid #c5c5c5}.ui-widget-content{border:1px solid #ddd;background:#fff;color:#333}.ui-widget-content a{color:#333}.ui-widget-header{border:1px solid #ddd;background:#e9e9e9;color:#333;font-weight:bold}.ui-widget-header a{color:#333}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default,.ui-button,html .ui-button.ui-state-disabled:hover,html .ui-button.ui-state-disabled:active{border:1px solid #c5c5c5;background:#f6f6f6;font-weight:normal;color:#454545}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited,a.ui-button,a:link.ui-button,a:visited.ui-button,.ui-button{color:#454545;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus,.ui-button:hover,.ui-button:focus{border:1px solid #ccc;background:#ededed;font-weight:normal;color:#2b2b2b}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited,.ui-state-focus a,.ui-state-focus a:hover,.ui-state-focus a:link,.ui-state-focus a:visited,a.ui-button:hover,a.ui-button:focus{color:#2b2b2b;text-decoration:none}.ui-visual-focus{box-shadow:0 0 3px 1px rgb(94,158,214)}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active,a.ui-button:active,.ui-button:active,.ui-button.ui-state-active:hover{border:1px solid #003eff;background:#007fff;font-weight:normal;color:#fff}.ui-icon-background,.ui-state-active .ui-icon-background{border:#003eff;background-color:#fff}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#fff;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #dad55e;background:#fffa90;color:#777620}.ui-state-checked{border:1px solid #dad55e;background:#fffa90}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#777620}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #f1a899;background:#fddfdf;color:#5f3f3f}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#5f3f3f}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#5f3f3f}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-widget-header .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button:hover .ui-icon,.ui-button:focus .ui-icon{background-image:url("images/ui-icons_555555_256x240.png")}.ui-state-active .ui-icon,.ui-button:active .ui-icon{background-image:url("images/ui-icons_ffffff_256x240.png")}.ui-state-highlight .ui-icon,.ui-button .ui-state-highlight.ui-icon{background-image:url("images/ui-icons_777620_256x240.png")}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url("images/ui-icons_cc0000_256x240.png")}.ui-button .ui-icon{background-image:url("images/ui-icons_777777_256x240.png")}.ui-icon-blank{background-position:16px 16px}.ui-icon-caret-1-n{background-position:0 0}.ui-icon-caret-1-ne{background-position:-16px 0}.ui-icon-caret-1-e{background-position:-32px 0}.ui-icon-caret-1-se{background-position:-48px 0}.ui-icon-caret-1-s{background-position:-65px 0}.ui-icon-caret-1-sw{background-position:-80px 0}.ui-icon-caret-1-w{background-position:-96px 0}.ui-icon-caret-1-nw{background-position:-112px 0}.ui-icon-caret-2-n-s{background-position:-128px 0}.ui-icon-caret-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-65px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-65px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:1px -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:3px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:3px}.ui-widget-overlay{background:#aaa;opacity:.3;filter:Alpha(Opacity=30)}.ui-widget-shadow{-webkit-box-shadow:0 0 5px #666;box-shadow:0 0 5px #666}
1
+ /*! jQuery UI - v1.12.1 - 2020-01-10
2
+ * http://jqueryui.com
3
+ * Copyright jQuery Foundation and other contributors; Licensed MIT */
4
+
5
  .ui-widget{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget .ui-widget{font-size:1em}.ui-widget input,.ui-widget select,.ui-widget textarea,.ui-widget button{font-family:Arial,Helvetica,sans-serif;font-size:1em}.ui-widget.ui-widget-content{border:1px solid #c5c5c5}.ui-widget-content{border:1px solid #ddd;background:#fff;color:#333}.ui-widget-content a{color:#333}.ui-widget-header{border:1px solid #ddd;background:#e9e9e9;color:#333;font-weight:bold}.ui-widget-header a{color:#333}.ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default,.ui-button,html .ui-button.ui-state-disabled:hover,html .ui-button.ui-state-disabled:active{border:1px solid #c5c5c5;background:#f6f6f6;font-weight:normal;color:#454545}.ui-state-default a,.ui-state-default a:link,.ui-state-default a:visited,a.ui-button,a:link.ui-button,a:visited.ui-button,.ui-button{color:#454545;text-decoration:none}.ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus,.ui-button:hover,.ui-button:focus{border:1px solid #ccc;background:#ededed;font-weight:normal;color:#2b2b2b}.ui-state-hover a,.ui-state-hover a:hover,.ui-state-hover a:link,.ui-state-hover a:visited,.ui-state-focus a,.ui-state-focus a:hover,.ui-state-focus a:link,.ui-state-focus a:visited,a.ui-button:hover,a.ui-button:focus{color:#2b2b2b;text-decoration:none}.ui-visual-focus{box-shadow:0 0 3px 1px rgb(94,158,214)}.ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active,a.ui-button:active,.ui-button:active,.ui-button.ui-state-active:hover{border:1px solid #003eff;background:#007fff;font-weight:normal;color:#fff}.ui-icon-background,.ui-state-active .ui-icon-background{border:#003eff;background-color:#fff}.ui-state-active a,.ui-state-active a:link,.ui-state-active a:visited{color:#fff;text-decoration:none}.ui-state-highlight,.ui-widget-content .ui-state-highlight,.ui-widget-header .ui-state-highlight{border:1px solid #dad55e;background:#fffa90;color:#777620}.ui-state-checked{border:1px solid #dad55e;background:#fffa90}.ui-state-highlight a,.ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a{color:#777620}.ui-state-error,.ui-widget-content .ui-state-error,.ui-widget-header .ui-state-error{border:1px solid #f1a899;background:#fddfdf;color:#5f3f3f}.ui-state-error a,.ui-widget-content .ui-state-error a,.ui-widget-header .ui-state-error a{color:#5f3f3f}.ui-state-error-text,.ui-widget-content .ui-state-error-text,.ui-widget-header .ui-state-error-text{color:#5f3f3f}.ui-priority-primary,.ui-widget-content .ui-priority-primary,.ui-widget-header .ui-priority-primary{font-weight:bold}.ui-priority-secondary,.ui-widget-content .ui-priority-secondary,.ui-widget-header .ui-priority-secondary{opacity:.7;filter:Alpha(Opacity=70);font-weight:normal}.ui-state-disabled,.ui-widget-content .ui-state-disabled,.ui-widget-header .ui-state-disabled{opacity:.35;filter:Alpha(Opacity=35);background-image:none}.ui-state-disabled .ui-icon{filter:Alpha(Opacity=35)}.ui-icon{width:16px;height:16px}.ui-icon,.ui-widget-content .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-widget-header .ui-icon{background-image:url("images/ui-icons_444444_256x240.png")}.ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button:hover .ui-icon,.ui-button:focus .ui-icon{background-image:url("images/ui-icons_555555_256x240.png")}.ui-state-active .ui-icon,.ui-button:active .ui-icon{background-image:url("images/ui-icons_ffffff_256x240.png")}.ui-state-highlight .ui-icon,.ui-button .ui-state-highlight.ui-icon{background-image:url("images/ui-icons_777620_256x240.png")}.ui-state-error .ui-icon,.ui-state-error-text .ui-icon{background-image:url("images/ui-icons_cc0000_256x240.png")}.ui-button .ui-icon{background-image:url("images/ui-icons_777777_256x240.png")}.ui-icon-blank{background-position:16px 16px}.ui-icon-caret-1-n{background-position:0 0}.ui-icon-caret-1-ne{background-position:-16px 0}.ui-icon-caret-1-e{background-position:-32px 0}.ui-icon-caret-1-se{background-position:-48px 0}.ui-icon-caret-1-s{background-position:-65px 0}.ui-icon-caret-1-sw{background-position:-80px 0}.ui-icon-caret-1-w{background-position:-96px 0}.ui-icon-caret-1-nw{background-position:-112px 0}.ui-icon-caret-2-n-s{background-position:-128px 0}.ui-icon-caret-2-e-w{background-position:-144px 0}.ui-icon-triangle-1-n{background-position:0 -16px}.ui-icon-triangle-1-ne{background-position:-16px -16px}.ui-icon-triangle-1-e{background-position:-32px -16px}.ui-icon-triangle-1-se{background-position:-48px -16px}.ui-icon-triangle-1-s{background-position:-65px -16px}.ui-icon-triangle-1-sw{background-position:-80px -16px}.ui-icon-triangle-1-w{background-position:-96px -16px}.ui-icon-triangle-1-nw{background-position:-112px -16px}.ui-icon-triangle-2-n-s{background-position:-128px -16px}.ui-icon-triangle-2-e-w{background-position:-144px -16px}.ui-icon-arrow-1-n{background-position:0 -32px}.ui-icon-arrow-1-ne{background-position:-16px -32px}.ui-icon-arrow-1-e{background-position:-32px -32px}.ui-icon-arrow-1-se{background-position:-48px -32px}.ui-icon-arrow-1-s{background-position:-65px -32px}.ui-icon-arrow-1-sw{background-position:-80px -32px}.ui-icon-arrow-1-w{background-position:-96px -32px}.ui-icon-arrow-1-nw{background-position:-112px -32px}.ui-icon-arrow-2-n-s{background-position:-128px -32px}.ui-icon-arrow-2-ne-sw{background-position:-144px -32px}.ui-icon-arrow-2-e-w{background-position:-160px -32px}.ui-icon-arrow-2-se-nw{background-position:-176px -32px}.ui-icon-arrowstop-1-n{background-position:-192px -32px}.ui-icon-arrowstop-1-e{background-position:-208px -32px}.ui-icon-arrowstop-1-s{background-position:-224px -32px}.ui-icon-arrowstop-1-w{background-position:-240px -32px}.ui-icon-arrowthick-1-n{background-position:1px -48px}.ui-icon-arrowthick-1-ne{background-position:-16px -48px}.ui-icon-arrowthick-1-e{background-position:-32px -48px}.ui-icon-arrowthick-1-se{background-position:-48px -48px}.ui-icon-arrowthick-1-s{background-position:-64px -48px}.ui-icon-arrowthick-1-sw{background-position:-80px -48px}.ui-icon-arrowthick-1-w{background-position:-96px -48px}.ui-icon-arrowthick-1-nw{background-position:-112px -48px}.ui-icon-arrowthick-2-n-s{background-position:-128px -48px}.ui-icon-arrowthick-2-ne-sw{background-position:-144px -48px}.ui-icon-arrowthick-2-e-w{background-position:-160px -48px}.ui-icon-arrowthick-2-se-nw{background-position:-176px -48px}.ui-icon-arrowthickstop-1-n{background-position:-192px -48px}.ui-icon-arrowthickstop-1-e{background-position:-208px -48px}.ui-icon-arrowthickstop-1-s{background-position:-224px -48px}.ui-icon-arrowthickstop-1-w{background-position:-240px -48px}.ui-icon-arrowreturnthick-1-w{background-position:0 -64px}.ui-icon-arrowreturnthick-1-n{background-position:-16px -64px}.ui-icon-arrowreturnthick-1-e{background-position:-32px -64px}.ui-icon-arrowreturnthick-1-s{background-position:-48px -64px}.ui-icon-arrowreturn-1-w{background-position:-64px -64px}.ui-icon-arrowreturn-1-n{background-position:-80px -64px}.ui-icon-arrowreturn-1-e{background-position:-96px -64px}.ui-icon-arrowreturn-1-s{background-position:-112px -64px}.ui-icon-arrowrefresh-1-w{background-position:-128px -64px}.ui-icon-arrowrefresh-1-n{background-position:-144px -64px}.ui-icon-arrowrefresh-1-e{background-position:-160px -64px}.ui-icon-arrowrefresh-1-s{background-position:-176px -64px}.ui-icon-arrow-4{background-position:0 -80px}.ui-icon-arrow-4-diag{background-position:-16px -80px}.ui-icon-extlink{background-position:-32px -80px}.ui-icon-newwin{background-position:-48px -80px}.ui-icon-refresh{background-position:-64px -80px}.ui-icon-shuffle{background-position:-80px -80px}.ui-icon-transfer-e-w{background-position:-96px -80px}.ui-icon-transferthick-e-w{background-position:-112px -80px}.ui-icon-folder-collapsed{background-position:0 -96px}.ui-icon-folder-open{background-position:-16px -96px}.ui-icon-document{background-position:-32px -96px}.ui-icon-document-b{background-position:-48px -96px}.ui-icon-note{background-position:-64px -96px}.ui-icon-mail-closed{background-position:-80px -96px}.ui-icon-mail-open{background-position:-96px -96px}.ui-icon-suitcase{background-position:-112px -96px}.ui-icon-comment{background-position:-128px -96px}.ui-icon-person{background-position:-144px -96px}.ui-icon-print{background-position:-160px -96px}.ui-icon-trash{background-position:-176px -96px}.ui-icon-locked{background-position:-192px -96px}.ui-icon-unlocked{background-position:-208px -96px}.ui-icon-bookmark{background-position:-224px -96px}.ui-icon-tag{background-position:-240px -96px}.ui-icon-home{background-position:0 -112px}.ui-icon-flag{background-position:-16px -112px}.ui-icon-calendar{background-position:-32px -112px}.ui-icon-cart{background-position:-48px -112px}.ui-icon-pencil{background-position:-64px -112px}.ui-icon-clock{background-position:-80px -112px}.ui-icon-disk{background-position:-96px -112px}.ui-icon-calculator{background-position:-112px -112px}.ui-icon-zoomin{background-position:-128px -112px}.ui-icon-zoomout{background-position:-144px -112px}.ui-icon-search{background-position:-160px -112px}.ui-icon-wrench{background-position:-176px -112px}.ui-icon-gear{background-position:-192px -112px}.ui-icon-heart{background-position:-208px -112px}.ui-icon-star{background-position:-224px -112px}.ui-icon-link{background-position:-240px -112px}.ui-icon-cancel{background-position:0 -128px}.ui-icon-plus{background-position:-16px -128px}.ui-icon-plusthick{background-position:-32px -128px}.ui-icon-minus{background-position:-48px -128px}.ui-icon-minusthick{background-position:-64px -128px}.ui-icon-close{background-position:-80px -128px}.ui-icon-closethick{background-position:-96px -128px}.ui-icon-key{background-position:-112px -128px}.ui-icon-lightbulb{background-position:-128px -128px}.ui-icon-scissors{background-position:-144px -128px}.ui-icon-clipboard{background-position:-160px -128px}.ui-icon-copy{background-position:-176px -128px}.ui-icon-contact{background-position:-192px -128px}.ui-icon-image{background-position:-208px -128px}.ui-icon-video{background-position:-224px -128px}.ui-icon-script{background-position:-240px -128px}.ui-icon-alert{background-position:0 -144px}.ui-icon-info{background-position:-16px -144px}.ui-icon-notice{background-position:-32px -144px}.ui-icon-help{background-position:-48px -144px}.ui-icon-check{background-position:-64px -144px}.ui-icon-bullet{background-position:-80px -144px}.ui-icon-radio-on{background-position:-96px -144px}.ui-icon-radio-off{background-position:-112px -144px}.ui-icon-pin-w{background-position:-128px -144px}.ui-icon-pin-s{background-position:-144px -144px}.ui-icon-play{background-position:0 -160px}.ui-icon-pause{background-position:-16px -160px}.ui-icon-seek-next{background-position:-32px -160px}.ui-icon-seek-prev{background-position:-48px -160px}.ui-icon-seek-end{background-position:-64px -160px}.ui-icon-seek-start{background-position:-80px -160px}.ui-icon-seek-first{background-position:-80px -160px}.ui-icon-stop{background-position:-96px -160px}.ui-icon-eject{background-position:-112px -160px}.ui-icon-volume-off{background-position:-128px -160px}.ui-icon-volume-on{background-position:-144px -160px}.ui-icon-power{background-position:0 -176px}.ui-icon-signal-diag{background-position:-16px -176px}.ui-icon-signal{background-position:-32px -176px}.ui-icon-battery-0{background-position:-48px -176px}.ui-icon-battery-1{background-position:-64px -176px}.ui-icon-battery-2{background-position:-80px -176px}.ui-icon-battery-3{background-position:-96px -176px}.ui-icon-circle-plus{background-position:0 -192px}.ui-icon-circle-minus{background-position:-16px -192px}.ui-icon-circle-close{background-position:-32px -192px}.ui-icon-circle-triangle-e{background-position:-48px -192px}.ui-icon-circle-triangle-s{background-position:-64px -192px}.ui-icon-circle-triangle-w{background-position:-80px -192px}.ui-icon-circle-triangle-n{background-position:-96px -192px}.ui-icon-circle-arrow-e{background-position:-112px -192px}.ui-icon-circle-arrow-s{background-position:-128px -192px}.ui-icon-circle-arrow-w{background-position:-144px -192px}.ui-icon-circle-arrow-n{background-position:-160px -192px}.ui-icon-circle-zoomin{background-position:-176px -192px}.ui-icon-circle-zoomout{background-position:-192px -192px}.ui-icon-circle-check{background-position:-208px -192px}.ui-icon-circlesmall-plus{background-position:0 -208px}.ui-icon-circlesmall-minus{background-position:-16px -208px}.ui-icon-circlesmall-close{background-position:-32px -208px}.ui-icon-squaresmall-plus{background-position:-48px -208px}.ui-icon-squaresmall-minus{background-position:-64px -208px}.ui-icon-squaresmall-close{background-position:-80px -208px}.ui-icon-grip-dotted-vertical{background-position:0 -224px}.ui-icon-grip-dotted-horizontal{background-position:-16px -224px}.ui-icon-grip-solid-vertical{background-position:-32px -224px}.ui-icon-grip-solid-horizontal{background-position:-48px -224px}.ui-icon-gripsmall-diagonal-se{background-position:-64px -224px}.ui-icon-grip-diagonal-se{background-position:-80px -224px}.ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:3px}.ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:3px}.ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:3px}.ui-widget-overlay{background:#aaa;opacity:.3;filter:Alpha(Opacity=30)}.ui-widget-shadow{-webkit-box-shadow:0 0 5px #666;box-shadow:0 0 5px #666}
inc/cleantalk-admin.php CHANGED
@@ -5,22 +5,27 @@ use Cleantalk\ApbctWP\CleantalkSettingsTemplates;
5
  require_once('cleantalk-settings.php');
6
 
7
  // Add buttons to comments list table
8
- add_action( 'manage_comments_nav', 'apbct_add_buttons_to_comments_and_users', 10, 1 );
9
- add_action( 'manage_users_extra_tablenav', 'apbct_add_buttons_to_comments_and_users', 10, 1 );
10
 
11
  // Check renew banner
12
- add_action( 'wp_ajax_apbct_settings__check_renew_banner', 'apbct_settings__check_renew_banner');
13
 
14
  // Crunch for Anti-Bot
15
- add_action( 'admin_head','apbct_admin_set_cookie_for_anti_bot' );
16
 
17
  /**
18
  * Crunch for Anti-Bot
19
  * Hooked by 'admin_head'
20
  */
21
- function apbct_admin_set_cookie_for_anti_bot(){
22
- global $apbct;
23
- echo '<script ' . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . '>var ctSecure = location.protocol === "https:" ? "; secure" : ""; document.cookie = "wordpress_apbct_antibot=' . hash( 'sha256', $apbct->api_key . $apbct->data['salt'] ) . '; path=/; expires=0; samesite=lax" + ctSecure;</script>';
 
 
 
 
 
24
  }
25
 
26
 
@@ -30,19 +35,19 @@ function apbct_admin_set_cookie_for_anti_bot(){
30
  *
31
  * @param $_unused_argument
32
  */
33
- function apbct_add_buttons_to_comments_and_users( $_unused_argument ) {
34
-
35
  global $apbct;
36
 
37
- if( is_null( $current_screen = get_current_screen() ) ) {
38
  return;
39
  }
40
 
41
- if( 'users' === $current_screen->base ) {
42
- $button_url__check = $current_screen->base . '.php?page=ct_check_users';
43
  $button_description = 'users';
44
  } elseif ( 'edit-comments' === $current_screen->base ) {
45
- $button_url__check = $current_screen->base . '.php?page=ct_check_spam';
46
  $button_description = 'comments';
47
  } else {
48
  return;
@@ -51,27 +56,26 @@ function apbct_add_buttons_to_comments_and_users( $_unused_argument ) {
51
  echo '
52
  <a href="' . $button_url__check . '" class="button" style="margin:1px 0 0 0; display: inline-block;">
53
  <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
54
- ' . sprintf(__( 'Find spam %s', 'cleantalk-spam-protect'), $button_description ) . '
55
  </a>
56
  ';
57
-
58
  }
59
 
60
  /**
61
  * Adding widget
62
  * Hooked by 'wp_dashboard_setup'
63
  */
64
- function ct_dashboard_statistics_widget() {
65
-
66
- global $apbct;
67
-
68
- if(apbct_is_user_role_in(array('administrator'))){
69
- wp_add_dashboard_widget(
70
- 'ct_dashboard_statistics_widget',
71
- $apbct->plugin_name,
72
- 'ct_dashboard_statistics_widget_output'
73
- );
74
- }
75
  }
76
 
77
  /**
@@ -80,113 +84,158 @@ function ct_dashboard_statistics_widget() {
80
  * @param $_post
81
  * @param $_callback_args
82
  */
83
- function ct_dashboard_statistics_widget_output( $_post, $_callback_args ) {
84
-
85
- global $apbct, $current_user;
86
-
87
- echo "<div id='ct_widget_wrapper'>";
88
- ?>
89
- <div class='ct_widget_top_links'>
90
- <img src="<?php echo plugins_url('/cleantalk-spam-protect/inc/images/preloader.gif'); ?>" class='ct_preloader'>
91
- <?php echo sprintf(__("%sRefresh%s", 'cleantalk-spam-protect'), "<a href='#ct_widget' class='ct_widget_refresh_link'>", "</a>"); ?>
92
- <?php echo sprintf(__("%sConfigure%s", 'cleantalk-spam-protect'), "<a href='{$apbct->settings_link}' class='ct_widget_settings_link'>", "</a>"); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  </div>
94
- <form id='ct_refresh_form' method='POST' action='#ct_widget'>
95
- <input type='hidden' name='ct_brief_refresh' value='1'>
96
- </form>
97
- <h4 class='ct_widget_block_header' style='margin-left: 12px;'><?php _e('7 days anti-spam stats', 'cleantalk-spam-protect'); ?></h4>
98
- <div class='ct_widget_block ct_widget_chart_wrapper'>
99
- <div id='ct_widget_chart'></div>
100
- </div>
101
- <h4 class='ct_widget_block_header'><?php _e('Top 5 spam IPs blocked', 'cleantalk-spam-protect'); ?></h4>
102
- <hr class='ct_widget_hr'>
103
- <?php
104
- if(!apbct_api_key__is_correct() || (isset($apbct->data['brief_data']['error_no']) && $apbct->data['brief_data']['error_no'] == 6)){
105
- ?> <div class='ct_widget_block'>
106
- <form action='<? echo $apbct->settings_link; ?>' method='POST'>
107
- <h2 class='ct_widget_activate_header'><?php _e('Get Access key to activate Anti-Spam protection!', 'cleantalk-spam-protect'); ?></h2>
108
- <input class='ct_widget_button ct_widget_activate_button' type='submit' name='get_apikey_auto' value='ACTIVATE' />
109
- </form>
110
- </div>
111
- <?php
112
- }elseif(!empty($apbct->data['brief_data']['error'])){
113
- echo '<div class="ct_widget_block">'
114
- .'<h2 class="ct_widget_activate_header">'
115
- .sprintf(__('Something went wrong! Error: "%s".', 'cleantalk-spam-protect'), "<u>{$apbct->brief_data['error']}</u>")
116
- .'</h2>';
117
- if($apbct->user_token && !$apbct->white_label){
118
- echo '<h2 class="ct_widget_activate_header">'
119
- .__('Please, visit your dashboard.', 'cleantalk-spam-protect')
120
- .'</h2>'
121
- .'<a target="_blank" href="https://cleantalk.org/my?user_token='.$apbct->user_token.'&cp_mode=antispam">'
122
- .'<input class="ct_widget_button ct_widget_activate_button ct_widget_resolve_button" type="button" value="VISIT CONTROL PANEL">'
123
- .'</a>';
124
- }
125
- echo '</div>';
126
- }
127
-
128
- if(apbct_api_key__is_correct() && empty($apbct->data['brief_data']['error'])){
129
- ?>
130
- <div class='ct_widget_block'>
131
- <table cellspacing="0">
132
- <tr>
133
- <th><?php _e('IP', 'cleantalk-spam-protect'); ?></th>
134
- <th><?php _e('Country', 'cleantalk-spam-protect'); ?></th>
135
- <th><?php _e('Block Count', 'cleantalk-spam-protect'); ?></th>
136
- </tr>
137
- <?php foreach($apbct->brief_data['top5_spam_ip'] as $val){ ?>
138
- <tr>
139
- <td><?php echo $val[0]; ?></td>
140
-
141
- <td class="ct_widget_block__country_cell">
142
- <?php echo $val[1] ? "<img src='" . APBCT_URL_PATH . "/inc/images/flags/".strtolower( isset( $val[1]['country_code'] ) ? $val[1]['country_code'] : 'a1' ).".png'>" : ''; ?>
143
- <?php echo isset( $val[1]['country_name'] ) ? $val[1]['country_name'] : 'Unknown'; ?>
144
  </td>
145
 
146
- <td style='text-align: center;'><?php echo $val[2]; ?></td>
147
- </tr>
148
- <?php } ?>
149
- </table>
150
- <?php if($apbct->user_token){ ?>
151
- <a target='_blank' href='https://cleantalk.org/my?user_token=<?php echo $apbct->user_token; ?>&cp_mode=antispam'>
152
- <input class='ct_widget_button' id='ct_widget_button_view_all' type='button' value='View all'>
153
- </a>
154
- <?php } ?>
155
- </div>
 
 
 
 
 
156
 
157
- <?php
158
- }
159
- // Notice at the bottom
160
- if(isset($current_user) && in_array('administrator', $current_user->roles)){
161
-
162
- if($apbct->spam_count && $apbct->spam_count > 0){
163
- echo '<div class="ct_widget_wprapper_total_blocked">'
164
- .'<img src="'.$apbct->logo__small__colored.'" class="ct_widget_small_logo"/>'
165
- .'<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)
166
- .sprintf(
167
- /* translators: %s: Number of spam messages */
168
- __( '%s%s%s has blocked %s spam for all time. The statistics are automatically updated every 24 hours.', 'cleantalk-spam-protect'),
169
- !$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">' : '',
170
- $apbct->plugin_name,
171
- !$apbct->white_label ? '</a>' : '',
172
- number_format($apbct->data['spam_count'], 0, ',', ' ')
173
- )
174
- .'</span>'
175
- .(!$apbct->white_label
176
- ? '<br><br>'
177
- .'<b style="font-size: 16px;">'
178
- .sprintf(
179
- __('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'),
180
- '<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">',
181
- '</a></u>'
182
- )
183
- .'</b>'
184
- : ''
185
- )
186
- .'</div>';
187
- }
188
- }
189
- echo '</div>';
 
 
 
 
 
 
 
 
190
  }
191
 
192
  /**
@@ -194,66 +243,76 @@ function ct_dashboard_statistics_widget_output( $_post, $_callback_args ) {
194
  *
195
  * @psalm-suppress UndefinedFunction
196
  */
197
- function apbct_admin__init(){
198
-
199
- global $apbct, $spbc;
200
-
201
  // Admin bar
202
- $apbct->admin_bar_enabled = $apbct->settings['admin_bar__show'] &&
203
- current_user_can( 'activate_plugins' );
204
-
205
- if( $apbct->admin_bar_enabled ){
206
- if(
207
- ! has_action('admin_bar_menu', 'apbct_admin__admin_bar__add_structure' ) &&
208
- ! has_action('admin_bar_menu', 'spbc_admin__admin_bar__add_structure' )
209
- ){
210
- add_action( 'admin_bar_menu', 'apbct_admin__admin_bar__add_structure', 999 );
211
  }
212
-
213
- add_filter( 'cleantalk_admin_bar__parent_node__before', 'apbct_admin__admin_bar__prepare_counters' );
214
- add_filter( 'cleantalk_admin_bar__add_icon_to_parent_node', 'apbct_admin__admin_bar__prepare_counters' );
215
  // Temporary disable the icon
216
  //add_filter( 'cleantalk_admin_bar__parent_node__before', 'apbct_admin__admin_bar__add_parent_icon', 10, 1 );
217
- add_filter( 'cleantalk_admin_bar__parent_node__after', 'apbct_admin__admin_bar__add_counter', 10, 1 );
218
-
219
- add_action( 'admin_bar_menu', 'apbct_admin__admin_bar__add_child_nodes', 1000 );
220
- if( ! $spbc ){
221
- add_filter( 'admin_bar_menu', 'apbct_spbc_admin__admin_bar__add_child_nodes', 1001 );
222
  }
223
  }
224
-
225
- // Getting dashboard widget statistics
226
- if(!empty($_POST['ct_brief_refresh'])){
227
- cleantalk_get_brief_data( $apbct->api_key );
228
- }
229
-
230
- // Getting key like hoster. Only once!
231
- if(!is_main_site() && $apbct->white_label && ( empty($apbct->api_key) || $apbct->settings['apikey'] == $apbct->network_settings['apikey'] ) ){
232
- $res = apbct_settings__get_key_auto( true );
233
- if( isset( $res['auth_key'], $res['user_token'] ) ) {
234
- $settings = apbct_settings__validate(array(
235
- 'apikey' => $res['auth_key'],
 
 
 
 
236
  ));
237
- $apbct->api_key = $settings['apikey'];
238
- $apbct->save('settings');
239
  }
240
  }
241
 
242
- // Settings
243
- add_action('wp_ajax_apbct_settings__get__long_description', 'apbct_settings__get__long_description'); // Long description
 
 
 
244
 
245
- add_action( 'wp_ajax_apbct_sync', 'apbct_settings__sync' );
246
 
247
- add_action( 'wp_ajax_apbct_get_key_auto', 'apbct_settings__get_key_auto' );
248
 
249
- // Settings Templates
250
- if( ! is_multisite() || is_main_site() || ( ! is_main_site() && $apbct->network_settings['multisite__allow_custom_settings'] ) ) {
251
- new CleantalkSettingsTemplates( $apbct->api_key );
 
 
 
 
252
  }
253
-
254
  // Check compatibility
255
- do_action( 'apbct__check_compatibility' );
256
-
257
  }
258
 
259
  /**
@@ -264,14 +323,15 @@ function apbct_admin__init(){
264
  *
265
  * @return array
266
  */
267
- function apbct_admin__plugin_action_links($links, $_file) {
268
-
269
- global $apbct;
270
-
271
- $settings_link = '<a href="' . $apbct->settings_link . '">' . __( 'Settings' ) . '</a>';
272
-
273
- array_unshift( $links, $settings_link ); // before other links
274
- return $links;
 
275
  }
276
 
277
  /**
@@ -282,134 +342,230 @@ function apbct_admin__plugin_action_links($links, $_file) {
282
  *
283
  * @return array
284
  */
285
- function apbct_admin__register_plugin_links($links, $file){
286
-
287
- global $apbct;
288
-
289
- //Return if it's not our plugin
290
- if ($file != $apbct->base_name)
291
- return $links;
292
-
293
- if($apbct->white_label){
294
- $links = array_slice($links, 0, 1);
295
- $links[] = "<script " . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . ">jQuery('.plugin-title strong').each(function(i, item){
 
296
  if(jQuery(item).html() == 'Anti-Spam by CleanTalk')
297
  jQuery(item).html('{$apbct->plugin_name}');
298
  });</script>";
299
- return $links;
300
- }
301
-
302
- if(substr(get_locale(), 0, 2) != 'en')
303
- $links[] = '<a class="ct_meta_links ct_translate_links" href="'
304
- .sprintf('https://translate.wordpress.org/locale/%s/default/wp-plugins/cleantalk-spam-protect', substr(get_locale(), 0, 2))
305
- .'" target="_blank">'
306
- .__('Translate', 'cleantalk-spam-protect')
307
- .'</a>';
308
-
309
- $links[] = '<a class="ct_meta_links" href="'.$apbct->settings_link.'" target="_blank">' . __( 'Start here','cleantalk-spam-protect') . '</a>';
310
- $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>';
311
- $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>';
312
- $trial = apbct_admin__badge__get_premium(false);
313
- if(!empty($trial))
314
- $links[] = apbct_admin__badge__get_premium(false);
315
-
316
- return $links;
 
 
 
 
 
 
 
 
 
317
  }
318
 
319
  /**
320
  * Admin action 'admin_enqueue_scripts' - Enqueue admin script of reloading admin page after needed AJAX events
321
- * @param string $hook URL of hooked page
 
322
  */
323
- function apbct_admin__enqueue_scripts( $hook ){
324
-
325
- global $apbct;
326
-
327
- // Scripts to all admin pages
328
- wp_enqueue_script('ct_admin_js_notices', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin.min.js'), array(), APBCT_VERSION);
329
- wp_enqueue_style ('ct_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin.min.css'), array(), APBCT_VERSION, 'all');
330
- wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
331
-
332
- wp_localize_script( 'ct_admin_js_notices', 'ctAdminCommon', array(
333
- '_ajax_nonce' => wp_create_nonce( 'ct_secret_nonce' ),
334
- '_ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),
335
- 'plugin_name' => $apbct->plugin_name,
336
- 'logo' => '<img src="' . $apbct->logo . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
337
- 'logo_small' => '<img src="' . $apbct->logo__small . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
338
- 'logo_small_colored' => '<img src="' . $apbct->logo__small__colored . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
339
- ) );
340
-
341
- // DASHBOARD page JavaScript and CSS
342
- if($hook == 'index.php' && apbct_is_user_role_in(array('administrator'))){
343
-
344
- wp_enqueue_style('ct_admin_css_widget_dashboard', plugins_url('/cleantalk-spam-protect/css/cleantalk-dashboard-widget.min.css'), array(), APBCT_VERSION, 'all');
345
- wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
346
-
347
- wp_enqueue_script('ct_gstatic_charts_loader', plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget--google-charts.min.js'), array(), APBCT_VERSION);
348
- 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);
349
-
350
- // Preparing widget data
351
- // 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"]]
352
- $to_chart = array();
353
-
354
- // Crunch. Response contains error.
355
- if(!empty($apbct->data['brief_data']['error']))
356
- $apbct->data['brief_data'] = array_merge($apbct->data['brief_data'], $apbct->def_data['brief_data']);
357
-
358
- if (isset($apbct->data['brief_data']['spam_stat']) && is_array($apbct->data['brief_data']['spam_stat'])) {
359
- foreach( $apbct->data['brief_data']['spam_stat'] as $key => $value ){
360
- $to_chart[] = array( $key, $value );
361
- } unset( $key, $value );
362
- }
363
-
364
- wp_localize_script( 'ct_admin_js_widget_dashboard', 'apbctDashboardWidget', array(
365
- 'data' => $to_chart,
366
- ));
367
- }
368
-
369
- // SETTINGS's page JavaScript and CSS
370
- if( $hook == 'settings_page_cleantalk' ){
371
-
372
- // jQueryUI
373
- wp_enqueue_script('jqueryui', plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'), array('jquery'), '1.12.1' );
374
- wp_enqueue_style('jqueryui_css', plugins_url('/cleantalk-spam-protect/css/jquery-ui.min.css'),array(), '1.21.1', 'all');
375
-
376
- wp_enqueue_script('cleantalk_admin_js_settings_page', plugins_url('/cleantalk-spam-protect/js/cleantalk-admin-settings-page.min.js'), array(), APBCT_VERSION);
377
- wp_enqueue_style('cleantalk_admin_css_settings_page', plugins_url('/cleantalk-spam-protect/css/cleantalk-admin-settings-page.min.css'), array(), APBCT_VERSION, 'all');
378
-
379
- wp_localize_script( 'cleantalk_admin_js_settings_page', 'ctSettingsPage', array(
380
- 'ct_subtitle' => $apbct->ip_license ? __('Hosting AntiSpam', 'cleantalk-spam-protect') : '',
381
- 'ip_license' => $apbct->ip_license ? true : false,
382
- 'key_changed' => ! empty( $apbct->data['key_changed'] ) ? true : false,
383
- ));
384
-
385
- wp_enqueue_script('cleantalk-modal', plugins_url( '/cleantalk-spam-protect/js/cleantalk-modal.min.js' ), array(), APBCT_VERSION);
386
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
 
388
  // COMMENTS page JavaScript
389
- if($hook == 'edit-comments.php'){
390
- wp_enqueue_script('ct_comments_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-editscreen.min.js'), array(), APBCT_VERSION);
391
- wp_localize_script( 'ct_comments_editscreen', 'ctCommentsScreen', array(
 
 
 
 
 
392
  'ct_ajax_nonce' => wp_create_nonce('ct_secret_nonce'),
393
  'spambutton_text' => __("Find spam comments", 'cleantalk-spam-protect'),
394
  'ct_feedback_msg_whitelisted' => __("The sender has been whitelisted.", 'cleantalk-spam-protect'),
395
  'ct_feedback_msg_blacklisted' => __("The sender has been blacklisted.", 'cleantalk-spam-protect'),
396
- '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>" : ''),
397
- 'ct_show_check_links' => (bool)$apbct->settings['comments__show_check_links'],
398
- 'ct_img_src_new_tab' => plugin_dir_url(__FILE__)."images/new_window.gif",
 
 
 
 
399
  ));
400
  }
401
 
402
  // USERS page JavaScript
403
- if($hook == 'users.php'){
404
- wp_enqueue_style ('ct_icons', plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'), array(), APBCT_VERSION, 'all');
405
- wp_enqueue_script('ct_users_editscreen', plugins_url('/cleantalk-spam-protect/js/cleantalk-users-editscreen.min.js'), array(), APBCT_VERSION);
406
- wp_localize_script( 'ct_users_editscreen', 'ctUsersScreen', array(
407
- 'spambutton_text' => __("Find spam-users", 'cleantalk-spam-protect'),
408
- 'ct_show_check_links' => (bool)$apbct->settings['comments__show_check_links'],
409
- 'ct_img_src_new_tab' => plugin_dir_url(__FILE__)."images/new_window.gif"
 
 
 
 
 
 
 
 
 
 
 
410
  ));
411
  }
412
-
413
  }
414
 
415
  /**
@@ -420,25 +576,26 @@ function apbct_admin__enqueue_scripts( $hook ){
420
  *
421
  * @return null|string
422
  */
423
- function apbct_admin__badge__get_premium($print = true, $out = ''){
424
-
425
- global $apbct;
426
-
427
- if($apbct->license_trial == 1 && $apbct->user_token){
428
- $out .= '<b style="display: inline-block; margin-top: 10px;">'
429
- .($print ? __('Make it right!', 'cleantalk-spam-protect').' ' : '')
430
- .sprintf(
431
- __('%sGet premium%s', 'cleantalk-spam-protect'),
432
- '<a href="https://cleantalk.org/my/bill/recharge?user_token='.$apbct->user_token.'" target="_blank">',
433
- '</a>'
434
- )
435
- .'</b>';
436
- }
437
-
438
- if($print)
439
- echo $out;
440
- else
441
- return $out;
 
442
  }
443
 
444
  /**
@@ -446,57 +603,63 @@ function apbct_admin__badge__get_premium($print = true, $out = ''){
446
  *
447
  * @param $wp_admin_bar
448
  */
449
- function apbct_admin__admin_bar__add_structure( $wp_admin_bar ) {
450
-
451
  global $spbc, $apbct;
452
-
453
- do_action( 'cleantalk_admin_bar__prepare_counters' );
454
-
455
  // Adding parent node
456
- $wp_admin_bar->add_node( array(
457
  'id' => 'cleantalk_admin_bar__parent_node',
458
  'title' =>
459
- apply_filters('cleantalk_admin_bar__add_icon_to_parent_node', '' ) . // @deprecated
460
- apply_filters('cleantalk_admin_bar__parent_node__before', '' ) .
461
  '<span class="cleantalk_admin_bar__title">' . __('CleanTalk', 'cleantalk-spam-protect') . '</span>' .
462
- apply_filters('cleantalk_admin_bar__parent_node__after', '' ),
463
- 'meta' => array( 'class' => 'cleantalk-admin_bar--list_wrapper'),
464
- ) );
465
-
466
  // Security
467
  $title = $apbct->notice_trial
468
- ? "<span><a 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', 'cleantalk-spam-protect') . '</a></span>'
469
- : '<span><a>' . __( 'Anti-Spam', 'cleantalk-spam-protect' ) . '</a></span>';
 
 
 
470
 
471
- $attention_mark = $apbct->notice_show ? '<i class="icon-attention-alt"></i>' : '';
472
- $title = $title . $attention_mark;
473
 
474
- $wp_admin_bar->add_node( array(
475
  'parent' => 'cleantalk_admin_bar__parent_node',
476
- 'id' => 'apbct__parent_node',
477
- 'title' => '<div class="cleantalk-admin_bar__parent">'
478
- . $title
479
- . '</div>',
480
- ) );
481
-
482
  // Antispam
483
  // Install link
484
- if( ! $spbc ){
485
- $spbc_title = '<a>' . __( 'Security', 'security-malware-firewall' ) . '</a>';
486
- }elseif( $spbc->admin_bar_enabled ){
487
  $spbc_title = $spbc->trial == 1
488
- ? "<span><a style='color: red;' href='https://cleantalk.org/my/bill/security?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20renew_security&user_token={$spbc->user_token}&cp_mode=security' target='_blank'>" . __( 'Renew Security', 'security-malware-firewall' ) . '</a></span>'
489
- : '<a>' . __( 'Security', 'security-malware-firewall' ) . '</a>';
 
 
 
490
  }
491
-
492
- if( isset( $spbc_title ) ){
493
- $wp_admin_bar->add_node( array(
494
  'parent' => 'cleantalk_admin_bar__parent_node',
495
- 'id' => 'spbc__parent_node',
496
- 'title' => '<div class="cleantalk-admin_bar__parent">'
497
- . $spbc_title
498
- . '</div>'
499
- ) );
500
  }
501
  }
502
 
@@ -506,57 +669,62 @@ function apbct_admin__admin_bar__add_structure( $wp_admin_bar ) {
506
  *
507
  * @return void
508
  */
509
- function apbct_admin__admin_bar__prepare_counters(){
510
-
511
  global $apbct;
512
-
513
  //Reset or create user counter
514
- if(!empty($_GET['ct_reset_user_counter'])){
515
  $apbct->data['user_counter']['accepted'] = 0;
516
- $apbct->data['user_counter']['blocked'] = 0;
517
- $apbct->data['user_counter']['since'] = date('d M');
518
  $apbct->saveData();
519
  }
520
  //Reset or create all counters
521
- if(!empty($_GET['ct_reset_all_counters'])){
522
  $apbct->data['admin_bar__sfw_counter'] = array('all' => 0, 'blocked' => 0);
523
  $apbct->data['admin_bar__all_time_counter'] = array('accepted' => 0, 'blocked' => 0);
524
- $apbct->data['user_counter'] = array('all' => 0, 'accepted' => 0, 'blocked' => 0, 'since' => date('d M'));
525
- $apbct->data['array_accepted'] = array();
526
- $apbct->data['array_blocked'] = array();
527
- $apbct->data['current_hour'] = '';
 
 
 
 
 
528
  $apbct->saveData();
529
  }
530
-
531
  $apbct->counter__sum = 0;
532
-
533
  $apbct->counter__user = array(
534
  'accepted' => $apbct->data['user_counter']['accepted'],
535
  'blocked' => $apbct->data['user_counter']['blocked'],
536
  'all' => $apbct->data['user_counter']['accepted'] + $apbct->data['user_counter']['blocked'],
537
  'since' => $apbct->data['user_counter']['since']
538
  );
539
- $apbct->counter__sum += $apbct->counter__user['all'];
540
-
541
- if( $apbct->settings['admin_bar__all_time_counter'] ){
542
  $apbct->counter__all_time = array(
543
  'accepted' => $apbct->data['admin_bar__all_time_counter']['accepted'],
544
  'blocked' => $apbct->data['admin_bar__all_time_counter']['blocked'],
545
  'all' => $apbct->data['admin_bar__all_time_counter']['accepted'] + $apbct->data['admin_bar__all_time_counter']['blocked']
546
  );
547
- $apbct->counter__sum += $apbct->counter__all_time['all'];
548
  }
549
-
550
- if( $apbct->settings['admin_bar__daily_counter'] ){
551
  $apbct->counter__daily = array(
552
- 'accepted' => array_sum( $apbct->data['array_accepted'] ),
553
- 'blocked' => array_sum( $apbct->data['array_blocked'] ),
554
- 'all' => array_sum( $apbct->data['array_accepted'] ) + array_sum( $apbct->data['array_blocked'] )
555
  );
556
- $apbct->counter__sum += $apbct->counter__daily['all'];
557
  }
558
-
559
- if( $apbct->settings['admin_bar__sfw_counter'] && $apbct->settings['sfw__enabled'] ){
560
  $apbct->counter__sfw = array(
561
  'all' => $apbct->data['admin_bar__sfw_counter']['all'],
562
  'blocked' => $apbct->data['admin_bar__sfw_counter']['blocked']
@@ -565,268 +733,315 @@ function apbct_admin__admin_bar__prepare_counters(){
565
  }
566
  }
567
 
568
- function apbct_admin__admin_bar__add_parent_icon( $icon ){
569
-
570
  return $icon
571
- . '<img class="cleantalk_admin_bar__apbct_icon" src="' . APBCT_URL_PATH . '/inc/images/logo.png" alt="">&nbsp;';
572
  }
573
 
574
- function apbct_admin__admin_bar__add_counter( $after ){
575
-
576
  global $apbct;
577
-
578
- $counter__sum__layout = ( $after ? ' / ' : '<div class="cleantalk_admin_bar__sum_counter">' ) .
579
- '<span title="' . __( 'All anti-spam events', 'cleantalk-spam-protect' ) . '">' . $apbct->counter__sum . '</span>' .
580
- '</div>';
581
-
582
- return ( $after ? substr( $after, 0, -6 ) : $after )
583
- . $counter__sum__layout;
584
-
 
 
585
  }
586
 
587
- function apbct_admin__admin_bar__add_child_nodes( $wp_admin_bar ) {
588
-
589
- global $apbct;
590
 
591
- $attention_mark = $apbct->notice_show ? '<i class="icon-attention-alt"></i>' : '';
592
-
593
- $wp_admin_bar->add_node( array(
594
  'parent' => 'apbct__parent_node',
595
  'id' => 'apbct_admin_bar__counter_header',
596
- 'title' => __( 'Counters:', 'cleantalk-spam-protect' ),
597
- ) );
598
-
599
  // User's counter
600
- $wp_admin_bar->add_node( array(
601
  'parent' => 'apbct__parent_node',
602
- 'id' => 'apbct_admin_bar__counter__user',
603
  'title' => '<a>'
604
- . __('Since', 'cleantalk-spam-protect') . '&nbsp;' . $apbct->counter__user['since'] . ': '
605
- . '<span style="color: green;">' . $apbct->counter__user['accepted']. '</span> / '
606
- . '<span style="color: red;">' . $apbct->counter__user['blocked'] . '</span>'
607
- . '<i class="icon-help-circled" title="'
608
- . __( 'Shows amount of alllowed and blocked requests since the date.', 'cleantalk-spam-protect' ) . '"></i>'
609
- .'</a>',
610
- ) );
611
-
 
 
 
612
  // All-time counter
613
- if($apbct->settings['admin_bar__all_time_counter'] ){
614
- $wp_admin_bar->add_node( array(
615
  'parent' => 'apbct__parent_node',
616
  'id' => 'apbct_admin_bar__counter__all_time',
617
  'title' => '<a>'
618
- . '<span>'
619
- . __('Since activation', 'cleantalk-spam-protect') . ': '
620
- . '<span style="color: white;">' . $apbct->counter__all_time['all']. '</span> / '
621
- . '<span style="color: green;">' . $apbct->counter__all_time['accepted']. '</span> / '
622
- . '<span style="color: red;">' .$apbct->counter__all_time['blocked']. '</span>'
623
- . '</span>'
624
- . '<i class="icon-help-circled" title="' . __('All / Allowed / Blocked submissions. The number of submissions is being counted since CleanTalk plugin installation.', 'cleantalk-spam-protect').'"></i>'
625
- . '</a>',
626
- ) );
627
- }
628
-
 
 
 
629
  // Daily counter
630
- if( $apbct->settings['admin_bar__daily_counter'] ){
631
- $wp_admin_bar->add_node( array(
632
  'parent' => 'apbct__parent_node',
633
- 'id' => 'apbct_admin_bar__counter__daily',
634
  'title' => '<a>'
635
- . '<span>'
636
- . __('Day', 'cleantalk-spam-protect') . ': '
637
- . '<span style="color: green;">' .$apbct->counter__daily['accepted']. '</span> / '
638
- . '<span style="color: red;">' .$apbct->counter__daily['blocked']. '</span>'
639
- . '</span>'
640
- . '<i class="icon-help-circled" title="'.__('Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk-spam-protect').'"></i>'
641
- . '</a>',
642
- ) );
643
- }
644
-
 
 
 
645
  // SFW counter
646
- if( $apbct->settings['admin_bar__sfw_counter'] && $apbct->settings['sfw__enabled'] ){
647
- $wp_admin_bar->add_node( array(
648
  'parent' => 'apbct__parent_node',
649
- 'id' => 'apbct_admin_bar__counter__sfw',
650
  'title' => '<a>'
651
- . '<span>'
652
- . __('SpamFireWall', 'cleantalk-spam-protect' ) . ': '
653
- . '<span style="color: white;">'. $apbct->counter__sfw['all']. '</span> / '
654
- . '<span style="color: red;">' .$apbct->counter__sfw['blocked']. '</span>'
655
- . '</span>'
656
- . '<i class="icon-help-circled" title="'.__('All / Blocked events. Access attempts triggered by SpamFireWall counted since the last plugin activation.', 'cleantalk-spam-protect').'"></i>'
657
- . '</a>',
658
- ) );
659
- }
660
-
 
 
 
661
  // User counter reset.
662
- $wp_admin_bar->add_node( array(
663
  'parent' => 'apbct__parent_node',
664
- 'id' => 'ct_reset_counter',
665
- 'title' => '<hr style="margin-top: 7px; border: 1px solid #888;"><a href="?' . http_build_query(array_merge( $_GET, array( 'ct_reset_user_counter' => 1 ) ) ) . '" title="Reset your personal counter of submissions.">' . __('Reset first counter', 'cleantalk-spam-protect') . '</a>',
666
- ) );
667
-
 
 
 
 
668
  // Reset ALL counter
669
- $wp_admin_bar->add_node( array(
670
  'parent' => 'apbct__parent_node',
671
- 'id' => 'ct_reset_counters_all',
672
- 'title' => '<a href="?' . http_build_query(array_merge( $_GET, array( 'ct_reset_all_counters' => 1 ) ) ). '" title="' . __('Reset all counters', 'cleantalk-spam-protect') . '">'.__('Reset all counters', 'cleantalk-spam-protect').'</a>',
673
- ) );
674
-
 
 
 
675
  // Counter separator
676
- if( $apbct->counter__sum ){
677
- $wp_admin_bar->add_node( array(
678
  'parent' => 'apbct__parent_node',
679
  'id' => 'apbct_admin_bar__separator',
680
- 'title' =>'<hr style="margin-top: 7px;" />',
681
- 'meta' => array( 'class' => 'cleantalk_admin_bar__separator')
682
- ) );
683
  }
684
 
685
- $wp_admin_bar->add_node( array(
686
  'parent' => 'apbct__parent_node',
687
- 'id' => 'ct_settings_link',
688
- 'title' => '<a href="'.$apbct->settings_link.'">'.__('Settings', 'cleantalk-spam-protect').'</a>' . $attention_mark,
 
689
  ));
690
-
691
  // Add a child item to our parent item. Bulk checks.
692
- if(!is_network_admin()){
693
- $wp_admin_bar->add_node( array(
694
- 'parent' => 'apbct__parent_node',
695
- 'id' => 'ct_settings_bulk_comments',
696
- '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>',
697
- ) );
 
 
 
 
698
  }
699
-
700
  // Add a child item to our parent item. Bulk checks.
701
- if(!is_network_admin()){
702
- $wp_admin_bar->add_node( array(
703
- 'parent' => 'apbct__parent_node',
704
- 'id' => 'ct_settings_bulk_users',
705
- 'title' => '<a href="users.php?page=ct_check_users" title="Bulk spam users removal tool.">'.__('Check users for spam', 'cleantalk-spam-protect').'</a>',
706
- ) );
 
 
 
707
  }
708
-
709
  // Support link
710
- if(!$apbct->white_label){
711
- $wp_admin_bar->add_node( array(
712
- 'parent' => 'apbct__parent_node',
713
- 'id' => 'ct_admin_bar_support_link',
714
- 'title' => '<hr style="margin-top: 7px;" /><a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">'.__('Support', 'cleantalk-spam-protect').'</a>',
715
- ));
 
 
 
716
  }
717
  }
718
 
719
- function apbct_spbc_admin__admin_bar__add_child_nodes( $wp_admin_bar ){
720
-
721
  // Installation link
722
- $wp_admin_bar->add_node( array(
723
- 'parent' => 'spbc__parent_node',
724
- 'id' => 'apbct_admin_bar__install',
725
- 'title' => '<a target="_blank" href="plugin-install.php?s=Security%20and%20Malware%20scan%20by%20CleanTalk%20&tab=search">' . __( 'Install Security by CleanTalk', 'cleantalk-spam-protect' ) . '</a>',
726
- ) );
727
-
728
- $wp_admin_bar->add_node( array(
 
 
 
729
  'parent' => 'spbc__parent_node',
730
  'id' => 'install_separator',
731
- 'title' =>'<hr style="margin-top: 7px;" />',
732
- 'meta' => array( 'class' => 'cleantalk_admin_bar__separator' )
733
- ) );
734
-
735
  // Counter header
736
- $wp_admin_bar->add_node( array(
737
  'parent' => 'spbc__parent_node',
738
  'id' => 'spbc_admin_bar__counter_header',
739
- 'title' => '<a>' . __( 'Counters:', 'security-malware-firewall' ) . '</a>',
740
- 'meta' => array( 'class' => 'cleantalk_admin_bar__blocked' ),
741
- ) );
742
-
743
  // Failed / success login attempts counter
744
- $wp_admin_bar->add_node( array(
745
  'parent' => 'spbc__parent_node',
746
  'id' => 'spbc_admin_bar__counter__logins',
747
  'title' => '<a>'
748
- . '<span>' . __('Logins:', 'cleantalk-spam-protect') . '</span>&nbsp;'
749
- . '<span style="color: white;">'
750
- . '<b style="color: green;">' . 0 . '</b> / '
751
- . '<b style="color: red;">' . 0 . '</b>'
752
- . '</span>'
753
- . '<i class="icon-help-circled" title="' . __('Blocked login attempts in the local database for past 24 hours.', 'cleantalk-spam-protect') . '"></i>'
754
- . '</a>',
755
- 'meta' => array( 'class' => 'cleantalk_admin_bar__blocked' ),
756
- ) );
757
-
 
 
 
758
  // Firewall blocked / allowed counter
759
- $wp_admin_bar->add_node( array(
760
  'parent' => 'spbc__parent_node',
761
  'id' => 'spbc_admin_bar__counter__firewall',
762
  'title' => '<a>'
763
- .'<b>' .__( 'Security Firewall: ', 'cleantalk-spam-protect' ) .'</b>&nbsp;'
764
- . '<b style="color: white;">'
765
- . '<b style="color: green;">' . 0 . '</b> / '
766
- . '<b style="color: red;">' . 0 . '</b>'
767
- . '</b>'
768
- . '<i class="icon-help-circled" title="'.__('Passed / Blocked requests by Security Firewall for past 24 hours.', 'cleantalk-spam-protect').'"></i>'
769
- . '</a>',
770
- 'meta' => array( 'class' => 'cleantalk_admin_bar__blocked' ),
771
- ) );
772
-
 
 
 
773
  // Users online counter
774
- $wp_admin_bar->add_node( array(
775
  'parent' => 'spbc__parent_node',
776
  'id' => 'spbc_admin_bar__counter__online',
777
  'title' => '<a>'
778
- . '<span>' . __( 'Users online:', 'cleantalk-spam-protect' ) . '</span>'
779
- . '&nbsp;<b class="spbc-admin_bar--user_counter">' . 0 . '</b>'
780
- . '<i class="icon-help-circled" title="' . __( 'Shows amount of currently logged in administrators. Updates each 10 seconds.', 'cleantalk-spam-protect' ) . '"></i>'
781
- . '</a>',
782
- 'meta' => array( 'class' => 'cleantalk_admin_bar__blocked' ),
783
- ) );
784
-
 
 
 
785
  // Counter separator
786
- $wp_admin_bar->add_node( array(
787
  'parent' => 'spbc__parent_node',
788
  'id' => 'spbc_admin_bar__separator',
789
- 'title' =>'<hr style="margin-top: 7px;" />',
790
- 'meta' => array( 'class' => 'cleantalk_admin_bar__separator')
791
- ) );
792
-
793
  // Settings
794
- $wp_admin_bar->add_node( array(
795
  'parent' => 'spbc__parent_node',
796
  'id' => 'spbc_admin_bar__settings_link',
797
- 'title' => '<a>' . __( 'Settings', 'cleantalk-spam-protect' ) . '</a>',
798
- 'meta' => array( 'class' => 'cleantalk_admin_bar__blocked' ),
799
- ) );
800
-
801
  // Scanner
802
- $wp_admin_bar->add_node( array(
803
  'parent' => 'spbc__parent_node',
804
  'id' => 'spbc_admin_bar__scanner_link',
805
- 'title' => '<a style="display:inline">' . __( 'Scanner', 'cleantalk-spam-protect' ) . '</a>'
806
- . '/'
807
- . '<a style="display:inline">' . __( 'Start scan', 'cleantalk-spam-protect' ) . '</a>',
808
- 'meta' => array( 'class' => 'cleantalk_admin_bar__blocked' ),
809
- ) );
810
-
811
  // Support link
812
- $wp_admin_bar->add_node( array(
813
  'parent' => 'spbc__parent_node',
814
- 'title' => '<hr style="margin-top: 7px;" /><a>' . __( 'Support', 'cleantalk-spam-protect' ) . '</a>',
815
  'id' => 'spbc_admin_bar__support_link',
816
- 'meta' => array( 'class' => 'cleantalk_admin_bar__blocked' ),
817
- ) );
818
  }
819
 
820
 
821
  /**
822
  * Unmark bad words
 
823
  * @param string $message
 
824
  * @return string Cleat comment
825
  */
826
- function apbct_comment__unmark_red($message) {
827
- $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
 
828
 
829
- return $message;
830
  }
831
 
832
  /**
@@ -837,54 +1052,58 @@ function apbct_comment__unmark_red($message) {
837
  * @param bool $change_status
838
  * @param null|bool $direct_call
839
  */
840
- function apbct_comment__send_feedback($comment_id = null, $comment_status = null, $change_status = false, $direct_call = null){
841
-
842
- // For AJAX call
843
- if( ! $direct_call ){
 
 
 
 
844
  check_ajax_referer('ct_secret_nonce', 'security');
845
  }
846
-
847
- $comment_id = ! $comment_id && isset( $_POST['comment_id'] ) ? $_POST['comment_id'] : false;
848
- $comment_status = ! $comment_status && isset( $_POST['comment_status'] ) ? $_POST['comment_status'] : false;
849
- $change_status = ! $change_status && isset( $_POST['change_status'] ) ? $_POST['change_status'] : false;
850
-
851
- // If enter params is empty exit
852
- if( ! $comment_id || ! $comment_status )
853
- die();
854
-
855
- // $comment = get_comment($comment_id, 'ARRAY_A');
856
- $hash = get_comment_meta($comment_id, 'ct_hash', true);
857
-
858
- // If we can send the feedback
859
- if($hash){
860
-
861
- // Approving
862
- if($comment_status == '1' || $comment_status == 'approve'){
863
- $result = ct_send_feedback($hash.":1");
864
- // $comment['comment_content'] = apbct_comment__unmark_red($comment['comment_content']);
865
- // wp_update_comment($comment);
866
- $result === true ? 1 : 0;
867
- }
868
-
869
- // Disapproving
870
- if($comment_status == 'spam'){
871
- $result = ct_send_feedback($hash.":0");
872
- $result === true ? 1 : 0;
873
- }
874
- }else{
875
- $result = 'no_hash';
876
- }
877
-
878
- // Changing comment status(folder) if flag is set. spam || approve
879
- if($change_status !== false)
880
- wp_set_comment_status($comment_id, $comment_status);
881
-
882
- if(!$direct_call){
883
- echo !empty($result) ? $result : 0;
884
- die();
885
- }else{
886
-
887
- }
888
  }
889
 
890
  /**
@@ -894,37 +1113,35 @@ function apbct_comment__send_feedback($comment_id = null, $comment_status = null
894
  * @param null $status
895
  * @param null $direct_call
896
  */
897
- function apbct_user__send_feedback($user_id = null, $status = null, $direct_call = null){
898
-
899
- check_ajax_referer('ct_secret_nonce', 'security');
900
-
901
- if(!$direct_call){
902
- $user_id = $_POST['user_id'];
903
- $status = $_POST['status'];
904
- }
905
-
906
- $hash = get_user_meta($user_id, 'ct_hash', true);
907
-
908
- if($hash){
909
- if($status == 'approve' || $status == 1){
910
- $result = ct_send_feedback($hash.":1");
911
- $result === true ? 1 : 0;
912
- }
913
- if($status == 'spam' || $status == 'disapprove' || $status == 0){
914
- $result = ct_send_feedback($hash.":0");
915
- $result === true ? 1 : 0;
916
- }
917
- }else{
918
- $result = 'no_hash';
919
- }
920
-
921
- if(!$direct_call){
922
- echo !empty($result) ? $result : 0;
923
- die();
924
- }else{
925
-
926
- }
927
-
928
  }
929
 
930
  /**
@@ -935,18 +1152,19 @@ function apbct_user__send_feedback($user_id = null, $status = null, $direct_call
935
  *
936
  * @return null
937
  */
938
- function apbct_user__delete__hook($user_id, $_reassign = null){
939
-
940
- $hash = get_user_meta($user_id, 'ct_hash', true);
941
- if ($hash !== '') {
942
- ct_feedback($hash, 0);
943
- }
944
  }
945
 
946
  /**
947
  * Check compatibility action
948
  */
949
  add_action('apbct__check_compatibility', 'apbct__check_compatibility_handler');
950
- function apbct__check_compatibility_handler() {
 
951
  new \Cleantalk\Common\Compatibility();
952
- }
5
  require_once('cleantalk-settings.php');
6
 
7
  // Add buttons to comments list table
8
+ add_action('manage_comments_nav', 'apbct_add_buttons_to_comments_and_users', 10, 1);
9
+ add_action('manage_users_extra_tablenav', 'apbct_add_buttons_to_comments_and_users', 10, 1);
10
 
11
  // Check renew banner
12
+ add_action('wp_ajax_apbct_settings__check_renew_banner', 'apbct_settings__check_renew_banner');
13
 
14
  // Crunch for Anti-Bot
15
+ add_action('admin_head', 'apbct_admin_set_cookie_for_anti_bot');
16
 
17
  /**
18
  * Crunch for Anti-Bot
19
  * Hooked by 'admin_head'
20
  */
21
+ function apbct_admin_set_cookie_for_anti_bot()
22
+ {
23
+ global $apbct;
24
+ echo
25
+ '<script ' . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '') . '>
26
+ var ctSecure = location.protocol === "https:" ? "; secure" : "";
27
+ document.cookie = "wordpress_apbct_antibot=' . hash('sha256', $apbct->api_key . $apbct->data['salt']) . '; path=/; expires=0; samesite=lax" + ctSecure;
28
+ </script>';
29
  }
30
 
31
 
35
  *
36
  * @param $_unused_argument
37
  */
38
+ function apbct_add_buttons_to_comments_and_users($_unused_argument)
39
+ {
40
  global $apbct;
41
 
42
+ if ( is_null($current_screen = get_current_screen()) ) {
43
  return;
44
  }
45
 
46
+ if ( 'users' === $current_screen->base ) {
47
+ $button_url__check = $current_screen->base . '.php?page=ct_check_users';
48
  $button_description = 'users';
49
  } elseif ( 'edit-comments' === $current_screen->base ) {
50
+ $button_url__check = $current_screen->base . '.php?page=ct_check_spam';
51
  $button_description = 'comments';
52
  } else {
53
  return;
56
  echo '
57
  <a href="' . $button_url__check . '" class="button" style="margin:1px 0 0 0; display: inline-block;">
58
  <img src="' . $apbct->logo__small__colored . '" alt="Cleantalk Antispam logo" height="" style="width: 17px; vertical-align: text-bottom;" />
59
+ ' . sprintf(__('Find spam %s', 'cleantalk-spam-protect'), $button_description) . '
60
  </a>
61
  ';
 
62
  }
63
 
64
  /**
65
  * Adding widget
66
  * Hooked by 'wp_dashboard_setup'
67
  */
68
+ function ct_dashboard_statistics_widget()
69
+ {
70
+ global $apbct;
71
+
72
+ if ( apbct_is_user_role_in(array('administrator')) ) {
73
+ wp_add_dashboard_widget(
74
+ 'ct_dashboard_statistics_widget',
75
+ $apbct->plugin_name,
76
+ 'ct_dashboard_statistics_widget_output'
77
+ );
78
+ }
79
  }
80
 
81
  /**
84
  * @param $_post
85
  * @param $_callback_args
86
  */
87
+ function ct_dashboard_statistics_widget_output($_post, $_callback_args)
88
+ {
89
+ global $apbct, $current_user;
90
+
91
+ echo "<div id='ct_widget_wrapper'>";
92
+ ?>
93
+ <div class='ct_widget_top_links'>
94
+ <img src="<?php
95
+ echo plugins_url('/cleantalk-spam-protect/inc/images/preloader.gif'); ?>" class='ct_preloader'>
96
+ <?php
97
+ echo sprintf(
98
+ __("%sRefresh%s", 'cleantalk-spam-protect'),
99
+ "<a href='#ct_widget' class='ct_widget_refresh_link'>",
100
+ "</a>"
101
+ ); ?>
102
+ <?php
103
+ echo sprintf(
104
+ __("%sConfigure%s", 'cleantalk-spam-protect'),
105
+ "<a href='{$apbct->settings_link}' class='ct_widget_settings_link'>",
106
+ "</a>"
107
+ ); ?>
108
+ </div>
109
+ <form id='ct_refresh_form' method='POST' action='#ct_widget'>
110
+ <input type='hidden' name='ct_brief_refresh' value='1'>
111
+ </form>
112
+ <h4 class='ct_widget_block_header' style='margin-left: 12px;'><?php
113
+ _e('7 days anti-spam stats', 'cleantalk-spam-protect'); ?></h4>
114
+ <div class='ct_widget_block ct_widget_chart_wrapper'>
115
+ <div id='ct_widget_chart'></div>
116
+ </div>
117
+ <h4 class='ct_widget_block_header'><?php
118
+ _e('Top 5 spam IPs blocked', 'cleantalk-spam-protect'); ?></h4>
119
+ <hr class='ct_widget_hr'>
120
+ <?php
121
+ if (
122
+ ! apbct_api_key__is_correct() ||
123
+ (isset($apbct->data['brief_data']['error_no']) && $apbct->data['brief_data']['error_no'] == 6)
124
+ ) {
125
+ ?>
126
+ <div class='ct_widget_block'>
127
+ <form action='<?php
128
+ echo $apbct->settings_link; ?>' method='POST'>
129
+ <h2 class='ct_widget_activate_header'><?php
130
+ _e('Get Access key to activate Anti-Spam protection!', 'cleantalk-spam-protect'); ?></h2>
131
+ <input class='ct_widget_button ct_widget_activate_button' type='submit' name='get_apikey_auto'
132
+ value='ACTIVATE'/>
133
+ </form>
134
  </div>
135
+ <?php
136
+ } elseif ( ! empty($apbct->data['brief_data']['error']) ) {
137
+ echo '<div class="ct_widget_block">'
138
+ . '<h2 class="ct_widget_activate_header">'
139
+ . sprintf(
140
+ __('Something went wrong! Error: "%s".', 'cleantalk-spam-protect'),
141
+ "<u>{$apbct->brief_data['error']}</u>"
142
+ )
143
+ . '</h2>';
144
+ if ( $apbct->user_token && ! $apbct->white_label ) {
145
+ echo '<h2 class="ct_widget_activate_header">'
146
+ . __('Please, visit your dashboard.', 'cleantalk-spam-protect')
147
+ . '</h2>'
148
+ . '<a target="_blank" href="https://cleantalk.org/my?user_token=' . $apbct->user_token . '&cp_mode=antispam">'
149
+ . '<input class="ct_widget_button ct_widget_activate_button ct_widget_resolve_button" type="button" value="VISIT CONTROL PANEL">'
150
+ . '</a>';
151
+ }
152
+ echo '</div>';
153
+ }
154
+
155
+ if ( apbct_api_key__is_correct() && empty($apbct->data['brief_data']['error']) ) {
156
+ ?>
157
+ <div class='ct_widget_block'>
158
+ <table cellspacing="0">
159
+ <tr>
160
+ <th><?php
161
+ _e('IP', 'cleantalk-spam-protect'); ?></th>
162
+ <th><?php
163
+ _e('Country', 'cleantalk-spam-protect'); ?></th>
164
+ <th><?php
165
+ _e('Block Count', 'cleantalk-spam-protect'); ?></th>
166
+ </tr>
167
+ <?php
168
+ foreach ( $apbct->brief_data['top5_spam_ip'] as $val ) { ?>
169
+ <tr>
170
+ <td><?php
171
+ echo $val[0]; ?></td>
172
+
173
+ <td class="ct_widget_block__country_cell">
174
+ <?php
175
+ echo $val[1] ? "<img src='" . APBCT_URL_PATH . "/inc/images/flags/" . strtolower(
176
+ isset($val[1]['country_code']) ? $val[1]['country_code'] : 'a1'
177
+ ) . ".png'>" : ''; ?>
178
+ <?php
179
+ echo isset($val[1]['country_name']) ? $val[1]['country_name'] : 'Unknown'; ?>
 
 
 
 
 
180
  </td>
181
 
182
+ <td style='text-align: center;'><?php
183
+ echo $val[2]; ?></td>
184
+ </tr>
185
+ <?php
186
+ } ?>
187
+ </table>
188
+ <?php
189
+ if ( $apbct->user_token ) { ?>
190
+ <a target='_blank' href='https://cleantalk.org/my?user_token=<?php
191
+ echo $apbct->user_token; ?>&cp_mode=antispam'>
192
+ <input class='ct_widget_button' id='ct_widget_button_view_all' type='button' value='View all'>
193
+ </a>
194
+ <?php
195
+ } ?>
196
+ </div>
197
 
198
+ <?php
199
+ }
200
+ // Notice at the bottom
201
+ if ( isset($current_user) && in_array('administrator', $current_user->roles) ) {
202
+ if ( $apbct->spam_count && $apbct->spam_count > 0 ) {
203
+ echo '<div class="ct_widget_wprapper_total_blocked">'
204
+ . '<img src="' . $apbct->logo__small__colored . '" class="ct_widget_small_logo"/>'
205
+ . '<span title="' . sprintf(
206
+ __(
207
+ 'This is the count from the %s\'s cloud and could be different to admin bar counters',
208
+ 'cleantalk-spam-protect'
209
+ ) . '">',
210
+ $apbct->plugin_name
211
+ )
212
+ . sprintf(
213
+ /* translators: %s: Number of spam messages */
214
+ __(
215
+ '%s%s%s has blocked %s spam for all time. The statistics are automatically updated every 24 hours.',
216
+ 'cleantalk-spam-protect'
217
+ ),
218
+ ! $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">' : '',
219
+ $apbct->plugin_name,
220
+ ! $apbct->white_label ? '</a>' : '',
221
+ number_format($apbct->data['spam_count'], 0, ',', ' ')
222
+ )
223
+ . '</span>'
224
+ . (! $apbct->white_label
225
+ ? '<br><br>'
226
+ . '<b style="font-size: 16px;">'
227
+ . sprintf(
228
+ __('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'),
229
+ '<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">',
230
+ '</a></u>'
231
+ )
232
+ . '</b>'
233
+ : ''
234
+ )
235
+ . '</div>';
236
+ }
237
+ }
238
+ echo '</div>';
239
  }
240
 
241
  /**
243
  *
244
  * @psalm-suppress UndefinedFunction
245
  */
246
+ function apbct_admin__init()
247
+ {
248
+ global $apbct, $spbc;
249
+
250
  // Admin bar
251
+ $apbct->admin_bar_enabled = $apbct->settings['admin_bar__show'] &&
252
+ current_user_can('activate_plugins');
253
+
254
+ if ( $apbct->admin_bar_enabled ) {
255
+ if (
256
+ ! has_action('admin_bar_menu', 'apbct_admin__admin_bar__add_structure') &&
257
+ ! has_action('admin_bar_menu', 'spbc_admin__admin_bar__add_structure')
258
+ ) {
259
+ add_action('admin_bar_menu', 'apbct_admin__admin_bar__add_structure', 999);
260
  }
261
+
262
+ add_filter('cleantalk_admin_bar__parent_node__before', 'apbct_admin__admin_bar__prepare_counters');
263
+ add_filter('cleantalk_admin_bar__add_icon_to_parent_node', 'apbct_admin__admin_bar__prepare_counters');
264
  // Temporary disable the icon
265
  //add_filter( 'cleantalk_admin_bar__parent_node__before', 'apbct_admin__admin_bar__add_parent_icon', 10, 1 );
266
+ add_filter('cleantalk_admin_bar__parent_node__after', 'apbct_admin__admin_bar__add_counter', 10, 1);
267
+
268
+ add_action('admin_bar_menu', 'apbct_admin__admin_bar__add_child_nodes', 1000);
269
+ if ( ! $spbc ) {
270
+ add_filter('admin_bar_menu', 'apbct_spbc_admin__admin_bar__add_child_nodes', 1001);
271
  }
272
  }
273
+
274
+ // Getting dashboard widget statistics
275
+ if ( ! empty($_POST['ct_brief_refresh']) ) {
276
+ cleantalk_get_brief_data($apbct->api_key);
277
+ }
278
+
279
+ // Getting key like hoster. Only once!
280
+ if (
281
+ ! is_main_site() &&
282
+ $apbct->white_label &&
283
+ (empty($apbct->api_key) || $apbct->settings['apikey'] == $apbct->network_settings['apikey'])
284
+ ) {
285
+ $res = apbct_settings__get_key_auto(true);
286
+ if ( isset($res['auth_key'], $res['user_token']) ) {
287
+ $settings = apbct_settings__validate(array(
288
+ 'apikey' => $res['auth_key'],
289
  ));
290
+ $apbct->api_key = $settings['apikey'];
291
+ $apbct->save('settings');
292
  }
293
  }
294
 
295
+ // Settings
296
+ add_action(
297
+ 'wp_ajax_apbct_settings__get__long_description',
298
+ 'apbct_settings__get__long_description'
299
+ ); // Long description
300
 
301
+ add_action('wp_ajax_apbct_sync', 'apbct_settings__sync');
302
 
303
+ add_action('wp_ajax_apbct_get_key_auto', 'apbct_settings__get_key_auto');
304
 
305
+ // Settings Templates
306
+ if (
307
+ ! is_multisite() ||
308
+ is_main_site() ||
309
+ ( ! is_main_site() && $apbct->network_settings['multisite__allow_custom_settings'])
310
+ ) {
311
+ new CleantalkSettingsTemplates($apbct->api_key);
312
  }
313
+
314
  // Check compatibility
315
+ do_action('apbct__check_compatibility');
 
316
  }
317
 
318
  /**
323
  *
324
  * @return array
325
  */
326
+ function apbct_admin__plugin_action_links($links, $_file)
327
+ {
328
+ global $apbct;
329
+
330
+ $settings_link = '<a href="' . $apbct->settings_link . '">' . __('Settings') . '</a>';
331
+
332
+ array_unshift($links, $settings_link); // before other links
333
+
334
+ return $links;
335
  }
336
 
337
  /**
342
  *
343
  * @return array
344
  */
345
+ function apbct_admin__register_plugin_links($links, $file)
346
+ {
347
+ global $apbct;
348
+
349
+ //Return if it's not our plugin
350
+ if ( $file != $apbct->base_name ) {
351
+ return $links;
352
+ }
353
+
354
+ if ( $apbct->white_label ) {
355
+ $links = array_slice($links, 0, 1);
356
+ $links[] = "<script " . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '') . ">jQuery('.plugin-title strong').each(function(i, item){
357
  if(jQuery(item).html() == 'Anti-Spam by CleanTalk')
358
  jQuery(item).html('{$apbct->plugin_name}');
359
  });</script>";
360
+
361
+ return $links;
362
+ }
363
+
364
+ if ( substr(get_locale(), 0, 2) != 'en' ) {
365
+ $links[] = '<a class="ct_meta_links ct_translate_links" href="'
366
+ . sprintf(
367
+ 'https://translate.wordpress.org/locale/%s/default/wp-plugins/cleantalk-spam-protect',
368
+ substr(get_locale(), 0, 2)
369
+ )
370
+ . '" target="_blank">'
371
+ . __('Translate', 'cleantalk-spam-protect')
372
+ . '</a>';
373
+ }
374
+
375
+ $links[] = '<a class="ct_meta_links" href="' . $apbct->settings_link . '" target="_blank">'
376
+ . __('Start here', 'cleantalk-spam-protect') . '</a>';
377
+ $links[] = '<a class="ct_meta_links ct_faq_links" href="https://wordpress.org/plugins/cleantalk-spam-protect/faq/" target="_blank">'
378
+ . __('FAQ', 'cleantalk-spam-protect') . '</a>';
379
+ $links[] = '<a class="ct_meta_links ct_support_links" href="https://wordpress.org/support/plugin/cleantalk-spam-protect" target="_blank">'
380
+ . __('Support', 'cleantalk-spam-protect') . '</a>';
381
+ $trial = apbct_admin__badge__get_premium(false);
382
+ if ( ! empty($trial) ) {
383
+ $links[] = apbct_admin__badge__get_premium(false);
384
+ }
385
+
386
+ return $links;
387
  }
388
 
389
  /**
390
  * Admin action 'admin_enqueue_scripts' - Enqueue admin script of reloading admin page after needed AJAX events
391
+ *
392
+ * @param string $hook URL of hooked page
393
  */
394
+ function apbct_admin__enqueue_scripts($hook)
395
+ {
396
+ global $apbct;
397
+
398
+ // Scripts to all admin pages
399
+ wp_enqueue_script(
400
+ 'ct_admin_js_notices',
401
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-admin.min.js'),
402
+ array(),
403
+ APBCT_VERSION
404
+ );
405
+ wp_enqueue_style(
406
+ 'ct_admin_css',
407
+ plugins_url('/cleantalk-spam-protect/css/cleantalk-admin.min.css'),
408
+ array(),
409
+ APBCT_VERSION,
410
+ 'all'
411
+ );
412
+ wp_enqueue_style(
413
+ 'ct_icons',
414
+ plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'),
415
+ array(),
416
+ APBCT_VERSION,
417
+ 'all'
418
+ );
419
+
420
+ wp_localize_script('ct_admin_js_notices', 'ctAdminCommon', array(
421
+ '_ajax_nonce' => wp_create_nonce('ct_secret_nonce'),
422
+ '_ajax_url' => admin_url('admin-ajax.php', 'relative'),
423
+ 'plugin_name' => $apbct->plugin_name,
424
+ 'logo' => '<img src="' . $apbct->logo . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
425
+ 'logo_small' => '<img src="' . $apbct->logo__small . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
426
+ 'logo_small_colored' => '<img src="' . $apbct->logo__small__colored . '" alt="" height="" style="width: 17px; vertical-align: text-bottom;" />',
427
+ ));
428
+
429
+ // DASHBOARD page JavaScript and CSS
430
+ if ( $hook == 'index.php' && apbct_is_user_role_in(array('administrator')) ) {
431
+ wp_enqueue_style(
432
+ 'ct_admin_css_widget_dashboard',
433
+ plugins_url('/cleantalk-spam-protect/css/cleantalk-dashboard-widget.min.css'),
434
+ array(),
435
+ APBCT_VERSION,
436
+ 'all'
437
+ );
438
+ wp_enqueue_style(
439
+ 'ct_icons',
440
+ plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'),
441
+ array(),
442
+ APBCT_VERSION,
443
+ 'all'
444
+ );
445
+
446
+ wp_enqueue_script(
447
+ 'ct_gstatic_charts_loader',
448
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget--google-charts.min.js'),
449
+ array(),
450
+ APBCT_VERSION
451
+ );
452
+ wp_enqueue_script(
453
+ 'ct_admin_js_widget_dashboard',
454
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-dashboard-widget.min.js'),
455
+ array('ct_gstatic_charts_loader'),
456
+ APBCT_VERSION
457
+ );
458
+
459
+ // Preparing widget data
460
+ // 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"]]
461
+ $to_chart = array();
462
+
463
+ // Crunch. Response contains error.
464
+ if ( ! empty($apbct->data['brief_data']['error']) ) {
465
+ $apbct->data['brief_data'] = array_merge($apbct->data['brief_data'], $apbct->def_data['brief_data']);
466
+ }
467
+
468
+ if ( isset($apbct->data['brief_data']['spam_stat']) && is_array($apbct->data['brief_data']['spam_stat']) ) {
469
+ foreach ( $apbct->data['brief_data']['spam_stat'] as $key => $value ) {
470
+ $to_chart[] = array($key, $value);
471
+ }
472
+ unset($key, $value);
473
+ }
474
+
475
+ wp_localize_script('ct_admin_js_widget_dashboard', 'apbctDashboardWidget', array(
476
+ 'data' => $to_chart,
477
+ ));
478
+ }
479
+
480
+ // SETTINGS's page JavaScript and CSS
481
+ if ( $hook == 'settings_page_cleantalk' ) {
482
+ // jQueryUI
483
+ wp_enqueue_script(
484
+ 'jqueryui',
485
+ plugins_url('/cleantalk-spam-protect/js/jquery-ui.min.js'),
486
+ array('jquery'),
487
+ '1.12.1'
488
+ );
489
+ wp_enqueue_style(
490
+ 'jqueryui_css',
491
+ plugins_url('/cleantalk-spam-protect/css/jquery-ui.min.css'),
492
+ array(),
493
+ '1.21.1',
494
+ 'all'
495
+ );
496
+
497
+ wp_enqueue_script(
498
+ 'cleantalk_admin_js_settings_page',
499
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-admin-settings-page.min.js'),
500
+ array(),
501
+ APBCT_VERSION
502
+ );
503
+ wp_enqueue_style(
504
+ 'cleantalk_admin_css_settings_page',
505
+ plugins_url('/cleantalk-spam-protect/css/cleantalk-admin-settings-page.min.css'),
506
+ array(),
507
+ APBCT_VERSION,
508
+ 'all'
509
+ );
510
+
511
+ wp_localize_script('cleantalk_admin_js_settings_page', 'ctSettingsPage', array(
512
+ 'ct_subtitle' => $apbct->ip_license ? __('Hosting AntiSpam', 'cleantalk-spam-protect') : '',
513
+ 'ip_license' => $apbct->ip_license ? true : false,
514
+ 'key_changed' => ! empty($apbct->data['key_changed']) ? true : false,
515
+ ));
516
+
517
+ wp_enqueue_script(
518
+ 'cleantalk-modal',
519
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-modal.min.js'),
520
+ array(),
521
+ APBCT_VERSION
522
+ );
523
+ }
524
 
525
  // COMMENTS page JavaScript
526
+ if ( $hook == 'edit-comments.php' ) {
527
+ wp_enqueue_script(
528
+ 'ct_comments_editscreen',
529
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-comments-editscreen.min.js'),
530
+ array(),
531
+ APBCT_VERSION
532
+ );
533
+ wp_localize_script('ct_comments_editscreen', 'ctCommentsScreen', array(
534
  'ct_ajax_nonce' => wp_create_nonce('ct_secret_nonce'),
535
  'spambutton_text' => __("Find spam comments", 'cleantalk-spam-protect'),
536
  'ct_feedback_msg_whitelisted' => __("The sender has been whitelisted.", 'cleantalk-spam-protect'),
537
  'ct_feedback_msg_blacklisted' => __("The sender has been blacklisted.", 'cleantalk-spam-protect'),
538
+ 'ct_feedback_msg' => sprintf(
539
+ __("Feedback has been sent to %sCleanTalk Dashboard%s.", 'cleantalk-spam-protect'),
540
+ $apbct->user_token ? "<a target='_blank' href=https://cleantalk.org/my?user_token={$apbct->user_token}&cp_mode=antispam>" : '',
541
+ $apbct->user_token ? "</a>" : ''
542
+ ),
543
+ 'ct_show_check_links' => (bool)$apbct->settings['comments__show_check_links'],
544
+ 'ct_img_src_new_tab' => plugin_dir_url(__FILE__) . "images/new_window.gif",
545
  ));
546
  }
547
 
548
  // USERS page JavaScript
549
+ if ( $hook == 'users.php' ) {
550
+ wp_enqueue_style(
551
+ 'ct_icons',
552
+ plugins_url('/cleantalk-spam-protect/css/cleantalk-icons.min.css'),
553
+ array(),
554
+ APBCT_VERSION,
555
+ 'all'
556
+ );
557
+ wp_enqueue_script(
558
+ 'ct_users_editscreen',
559
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-users-editscreen.min.js'),
560
+ array(),
561
+ APBCT_VERSION
562
+ );
563
+ wp_localize_script('ct_users_editscreen', 'ctUsersScreen', array(
564
+ 'spambutton_text' => __("Find spam-users", 'cleantalk-spam-protect'),
565
+ 'ct_show_check_links' => (bool)$apbct->settings['comments__show_check_links'],
566
+ 'ct_img_src_new_tab' => plugin_dir_url(__FILE__) . "images/new_window.gif"
567
  ));
568
  }
 
569
  }
570
 
571
  /**
576
  *
577
  * @return null|string
578
  */
579
+ function apbct_admin__badge__get_premium($print = true, $out = '')
580
+ {
581
+ global $apbct;
582
+
583
+ if ( $apbct->license_trial == 1 && $apbct->user_token ) {
584
+ $out .= '<b style="display: inline-block; margin-top: 10px;">'
585
+ . ($print ? __('Make it right!', 'cleantalk-spam-protect') . ' ' : '')
586
+ . sprintf(
587
+ __('%sGet premium%s', 'cleantalk-spam-protect'),
588
+ '<a href="https://cleantalk.org/my/bill/recharge?user_token=' . $apbct->user_token . '" target="_blank">',
589
+ '</a>'
590
+ )
591
+ . '</b>';
592
+ }
593
+
594
+ if ( $print ) {
595
+ echo $out;
596
+ } else {
597
+ return $out;
598
+ }
599
  }
600
 
601
  /**
603
  *
604
  * @param $wp_admin_bar
605
  */
606
+ function apbct_admin__admin_bar__add_structure($wp_admin_bar)
607
+ {
608
  global $spbc, $apbct;
609
+
610
+ do_action('cleantalk_admin_bar__prepare_counters');
611
+
612
  // Adding parent node
613
+ $wp_admin_bar->add_node(array(
614
  'id' => 'cleantalk_admin_bar__parent_node',
615
  'title' =>
616
+ apply_filters('cleantalk_admin_bar__add_icon_to_parent_node', '') . // @deprecated
617
+ apply_filters('cleantalk_admin_bar__parent_node__before', '') .
618
  '<span class="cleantalk_admin_bar__title">' . __('CleanTalk', 'cleantalk-spam-protect') . '</span>' .
619
+ apply_filters('cleantalk_admin_bar__parent_node__after', ''),
620
+ 'meta' => array('class' => 'cleantalk-admin_bar--list_wrapper'),
621
+ ));
622
+
623
  // Security
624
  $title = $apbct->notice_trial
625
+ ? "<span><a 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'>" . __(
626
+ 'Renew Anti-Spam',
627
+ 'cleantalk-spam-protect'
628
+ ) . '</a></span>'
629
+ : '<span><a>' . __('Anti-Spam', 'cleantalk-spam-protect') . '</a></span>';
630
 
631
+ $attention_mark = $apbct->notice_show ? '<i class="icon-attention-alt"></i>' : '';
632
+ $title = $title . $attention_mark;
633
 
634
+ $wp_admin_bar->add_node(array(
635
  'parent' => 'cleantalk_admin_bar__parent_node',
636
+ 'id' => 'apbct__parent_node',
637
+ 'title' => '<div class="cleantalk-admin_bar__parent">'
638
+ . $title
639
+ . '</div>',
640
+ ));
641
+
642
  // Antispam
643
  // Install link
644
+ if ( ! $spbc ) {
645
+ $spbc_title = '<a>' . __('Security', 'security-malware-firewall') . '</a>';
646
+ } elseif ( $spbc->admin_bar_enabled ) {
647
  $spbc_title = $spbc->trial == 1
648
+ ? "<span><a style='color: red;' href='https://cleantalk.org/my/bill/security?utm_source=wp-backend&utm_medium=cpc&utm_campaign=WP%20backend%20renew_security&user_token={$spbc->user_token}&cp_mode=security' target='_blank'>" . __(
649
+ 'Renew Security',
650
+ 'security-malware-firewall'
651
+ ) . '</a></span>'
652
+ : '<a>' . __('Security', 'security-malware-firewall') . '</a>';
653
  }
654
+
655
+ if ( isset($spbc_title) ) {
656
+ $wp_admin_bar->add_node(array(
657
  'parent' => 'cleantalk_admin_bar__parent_node',
658
+ 'id' => 'spbc__parent_node',
659
+ 'title' => '<div class="cleantalk-admin_bar__parent">'
660
+ . $spbc_title
661
+ . '</div>'
662
+ ));
663
  }
664
  }
665
 
669
  *
670
  * @return void
671
  */
672
+ function apbct_admin__admin_bar__prepare_counters()
673
+ {
674
  global $apbct;
675
+
676
  //Reset or create user counter
677
+ if ( ! empty($_GET['ct_reset_user_counter']) ) {
678
  $apbct->data['user_counter']['accepted'] = 0;
679
+ $apbct->data['user_counter']['blocked'] = 0;
680
+ $apbct->data['user_counter']['since'] = date('d M');
681
  $apbct->saveData();
682
  }
683
  //Reset or create all counters
684
+ if ( ! empty($_GET['ct_reset_all_counters']) ) {
685
  $apbct->data['admin_bar__sfw_counter'] = array('all' => 0, 'blocked' => 0);
686
  $apbct->data['admin_bar__all_time_counter'] = array('accepted' => 0, 'blocked' => 0);
687
+ $apbct->data['user_counter'] = array(
688
+ 'all' => 0,
689
+ 'accepted' => 0,
690
+ 'blocked' => 0,
691
+ 'since' => date('d M')
692
+ );
693
+ $apbct->data['array_accepted'] = array();
694
+ $apbct->data['array_blocked'] = array();
695
+ $apbct->data['current_hour'] = '';
696
  $apbct->saveData();
697
  }
698
+
699
  $apbct->counter__sum = 0;
700
+
701
  $apbct->counter__user = array(
702
  'accepted' => $apbct->data['user_counter']['accepted'],
703
  'blocked' => $apbct->data['user_counter']['blocked'],
704
  'all' => $apbct->data['user_counter']['accepted'] + $apbct->data['user_counter']['blocked'],
705
  'since' => $apbct->data['user_counter']['since']
706
  );
707
+ $apbct->counter__sum += $apbct->counter__user['all'];
708
+
709
+ if ( $apbct->settings['admin_bar__all_time_counter'] ) {
710
  $apbct->counter__all_time = array(
711
  'accepted' => $apbct->data['admin_bar__all_time_counter']['accepted'],
712
  'blocked' => $apbct->data['admin_bar__all_time_counter']['blocked'],
713
  'all' => $apbct->data['admin_bar__all_time_counter']['accepted'] + $apbct->data['admin_bar__all_time_counter']['blocked']
714
  );
715
+ $apbct->counter__sum += $apbct->counter__all_time['all'];
716
  }
717
+
718
+ if ( $apbct->settings['admin_bar__daily_counter'] ) {
719
  $apbct->counter__daily = array(
720
+ 'accepted' => array_sum($apbct->data['array_accepted']),
721
+ 'blocked' => array_sum($apbct->data['array_blocked']),
722
+ 'all' => array_sum($apbct->data['array_accepted']) + array_sum($apbct->data['array_blocked'])
723
  );
724
+ $apbct->counter__sum += $apbct->counter__daily['all'];
725
  }
726
+
727
+ if ( $apbct->settings['admin_bar__sfw_counter'] && $apbct->settings['sfw__enabled'] ) {
728
  $apbct->counter__sfw = array(
729
  'all' => $apbct->data['admin_bar__sfw_counter']['all'],
730
  'blocked' => $apbct->data['admin_bar__sfw_counter']['blocked']
733
  }
734
  }
735
 
736
+ function apbct_admin__admin_bar__add_parent_icon($icon)
737
+ {
738
  return $icon
739
+ . '<img class="cleantalk_admin_bar__apbct_icon" src="' . APBCT_URL_PATH . '/inc/images/logo.png" alt="">&nbsp;';
740
  }
741
 
742
+ function apbct_admin__admin_bar__add_counter($after)
743
+ {
744
  global $apbct;
745
+
746
+ $counter__sum__layout = ($after ? ' / ' : '<div class="cleantalk_admin_bar__sum_counter">') .
747
+ '<span title="' . __(
748
+ 'All anti-spam events',
749
+ 'cleantalk-spam-protect'
750
+ ) . '">' . $apbct->counter__sum . '</span>' .
751
+ '</div>';
752
+
753
+ return ($after ? substr($after, 0, -6) : $after)
754
+ . $counter__sum__layout;
755
  }
756
 
757
+ function apbct_admin__admin_bar__add_child_nodes($wp_admin_bar)
758
+ {
759
+ global $apbct;
760
 
761
+ $attention_mark = $apbct->notice_show ? '<i class="icon-attention-alt"></i>' : '';
762
+
763
+ $wp_admin_bar->add_node(array(
764
  'parent' => 'apbct__parent_node',
765
  'id' => 'apbct_admin_bar__counter_header',
766
+ 'title' => __('Counters:', 'cleantalk-spam-protect'),
767
+ ));
768
+
769
  // User's counter
770
+ $wp_admin_bar->add_node(array(
771
  'parent' => 'apbct__parent_node',
772
+ 'id' => 'apbct_admin_bar__counter__user',
773
  'title' => '<a>'
774
+ . __('Since', 'cleantalk-spam-protect') . '&nbsp;' . $apbct->counter__user['since'] . ': '
775
+ . '<span style="color: green;">' . $apbct->counter__user['accepted'] . '</span> / '
776
+ . '<span style="color: red;">' . $apbct->counter__user['blocked'] . '</span>'
777
+ . '<i class="icon-help-circled" title="'
778
+ . __(
779
+ 'Shows amount of alllowed and blocked requests since the date.',
780
+ 'cleantalk-spam-protect'
781
+ ) . '"></i>'
782
+ . '</a>',
783
+ ));
784
+
785
  // All-time counter
786
+ if ( $apbct->settings['admin_bar__all_time_counter'] ) {
787
+ $wp_admin_bar->add_node(array(
788
  'parent' => 'apbct__parent_node',
789
  'id' => 'apbct_admin_bar__counter__all_time',
790
  'title' => '<a>'
791
+ . '<span>'
792
+ . __('Since activation', 'cleantalk-spam-protect') . ': '
793
+ . '<span style="color: white;">' . $apbct->counter__all_time['all'] . '</span> / '
794
+ . '<span style="color: green;">' . $apbct->counter__all_time['accepted'] . '</span> / '
795
+ . '<span style="color: red;">' . $apbct->counter__all_time['blocked'] . '</span>'
796
+ . '</span>'
797
+ . '<i class="icon-help-circled" title="' . __(
798
+ 'All / Allowed / Blocked submissions. The number of submissions is being counted since CleanTalk plugin installation.',
799
+ 'cleantalk-spam-protect'
800
+ ) . '"></i>'
801
+ . '</a>',
802
+ ));
803
+ }
804
+
805
  // Daily counter
806
+ if ( $apbct->settings['admin_bar__daily_counter'] ) {
807
+ $wp_admin_bar->add_node(array(
808
  'parent' => 'apbct__parent_node',
809
+ 'id' => 'apbct_admin_bar__counter__daily',
810
  'title' => '<a>'
811
+ . '<span>'
812
+ . __('Day', 'cleantalk-spam-protect') . ': '
813
+ . '<span style="color: green;">' . $apbct->counter__daily['accepted'] . '</span> / '
814
+ . '<span style="color: red;">' . $apbct->counter__daily['blocked'] . '</span>'
815
+ . '</span>'
816
+ . '<i class="icon-help-circled" title="' . __(
817
+ 'Allowed / Blocked submissions. The number of submissions for past 24 hours. ',
818
+ 'cleantalk-spam-protect'
819
+ ) . '"></i>'
820
+ . '</a>',
821
+ ));
822
+ }
823
+
824
  // SFW counter
825
+ if ( $apbct->settings['admin_bar__sfw_counter'] && $apbct->settings['sfw__enabled'] ) {
826
+ $wp_admin_bar->add_node(array(
827
  'parent' => 'apbct__parent_node',
828
+ 'id' => 'apbct_admin_bar__counter__sfw',
829
  'title' => '<a>'
830
+ . '<span>'
831
+ . __('SpamFireWall', 'cleantalk-spam-protect') . ': '
832
+ . '<span style="color: white;">' . $apbct->counter__sfw['all'] . '</span> / '
833
+ . '<span style="color: red;">' . $apbct->counter__sfw['blocked'] . '</span>'
834
+ . '</span>'
835
+ . '<i class="icon-help-circled" title="' . __(
836
+ 'All / Blocked events. Access attempts triggered by SpamFireWall counted since the last plugin activation.',
837
+ 'cleantalk-spam-protect'
838
+ ) . '"></i>'
839
+ . '</a>',
840
+ ));
841
+ }
842
+
843
  // User counter reset.
844
+ $wp_admin_bar->add_node(array(
845
  'parent' => 'apbct__parent_node',
846
+ 'id' => 'ct_reset_counter',
847
+ 'title' =>
848
+ '<hr style="margin-top: 7px; border: 1px solid #888;">'
849
+ . '<a href="?' . http_build_query(array_merge($_GET, array('ct_reset_user_counter' => 1)))
850
+ . '" title="Reset your personal counter of submissions.">'
851
+ . __('Reset first counter', 'cleantalk-spam-protect') . '</a>',
852
+ ));
853
+
854
  // Reset ALL counter
855
+ $wp_admin_bar->add_node(array(
856
  'parent' => 'apbct__parent_node',
857
+ 'id' => 'ct_reset_counters_all',
858
+ 'title' =>
859
+ '<a href="?' . http_build_query(array_merge($_GET, array('ct_reset_all_counters' => 1)))
860
+ . '" title="' . __('Reset all counters', 'cleantalk-spam-protect') . '">'
861
+ . __('Reset all counters', 'cleantalk-spam-protect') . '</a>',
862
+ ));
863
+
864
  // Counter separator
865
+ if ( $apbct->counter__sum ) {
866
+ $wp_admin_bar->add_node(array(
867
  'parent' => 'apbct__parent_node',
868
  'id' => 'apbct_admin_bar__separator',
869
+ 'title' => '<hr style="margin-top: 7px;" />',
870
+ 'meta' => array('class' => 'cleantalk_admin_bar__separator')
871
+ ));
872
  }
873
 
874
+ $wp_admin_bar->add_node(array(
875
  'parent' => 'apbct__parent_node',
876
+ 'id' => 'ct_settings_link',
877
+ 'title' => '<a href="' . $apbct->settings_link . '">'
878
+ . __('Settings', 'cleantalk-spam-protect') . '</a>' . $attention_mark,
879
  ));
880
+
881
  // Add a child item to our parent item. Bulk checks.
882
+ if ( ! is_network_admin() ) {
883
+ $wp_admin_bar->add_node(
884
+ array(
885
+ 'parent' => 'apbct__parent_node',
886
+ 'id' => 'ct_settings_bulk_comments',
887
+ 'title' => '<hr style="margin-top: 7px;" /><a href="edit-comments.php?page=ct_check_spam" title="'
888
+ . __('Bulk spam comments removal tool.', 'cleantalk-spam-protect') . '">'
889
+ . __('Check comments for spam', 'cleantalk-spam-protect') . '</a>',
890
+ )
891
+ );
892
  }
893
+
894
  // Add a child item to our parent item. Bulk checks.
895
+ if ( ! is_network_admin() ) {
896
+ $wp_admin_bar->add_node(
897
+ array(
898
+ 'parent' => 'apbct__parent_node',
899
+ 'id' => 'ct_settings_bulk_users',
900
+ 'title' => '<a href="users.php?page=ct_check_users" title="Bulk spam users removal tool.">'
901
+ . __('Check users for spam', 'cleantalk-spam-protect') . '</a>',
902
+ )
903
+ );
904
  }
905
+
906
  // Support link
907
+ if ( ! $apbct->white_label ) {
908
+ $wp_admin_bar->add_node(
909
+ array(
910
+ 'parent' => 'apbct__parent_node',
911
+ 'id' => 'ct_admin_bar_support_link',
912
+ 'title' => '<hr style="margin-top: 7px;" /><a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">'
913
+ . __('Support', 'cleantalk-spam-protect') . '</a>',
914
+ )
915
+ );
916
  }
917
  }
918
 
919
+ function apbct_spbc_admin__admin_bar__add_child_nodes($wp_admin_bar)
920
+ {
921
  // Installation link
922
+ $wp_admin_bar->add_node(
923
+ array(
924
+ 'parent' => 'spbc__parent_node',
925
+ 'id' => 'apbct_admin_bar__install',
926
+ 'title' => '<a target="_blank" href="plugin-install.php?s=Security%20and%20Malware%20scan%20by%20CleanTalk%20&tab=search">'
927
+ . __('Install Security by CleanTalk', 'cleantalk-spam-protect') . '</a>',
928
+ )
929
+ );
930
+
931
+ $wp_admin_bar->add_node(array(
932
  'parent' => 'spbc__parent_node',
933
  'id' => 'install_separator',
934
+ 'title' => '<hr style="margin-top: 7px;" />',
935
+ 'meta' => array('class' => 'cleantalk_admin_bar__separator')
936
+ ));
937
+
938
  // Counter header
939
+ $wp_admin_bar->add_node(array(
940
  'parent' => 'spbc__parent_node',
941
  'id' => 'spbc_admin_bar__counter_header',
942
+ 'title' => '<a>' . __('Counters:', 'security-malware-firewall') . '</a>',
943
+ 'meta' => array('class' => 'cleantalk_admin_bar__blocked'),
944
+ ));
945
+
946
  // Failed / success login attempts counter
947
+ $wp_admin_bar->add_node(array(
948
  'parent' => 'spbc__parent_node',
949
  'id' => 'spbc_admin_bar__counter__logins',
950
  'title' => '<a>'
951
+ . '<span>' . __('Logins:', 'cleantalk-spam-protect') . '</span>&nbsp;'
952
+ . '<span style="color: white;">'
953
+ . '<b style="color: green;">' . 0 . '</b> / '
954
+ . '<b style="color: red;">' . 0 . '</b>'
955
+ . '</span>'
956
+ . '<i class="icon-help-circled" title="' . __(
957
+ 'Blocked login attempts in the local database for past 24 hours.',
958
+ 'cleantalk-spam-protect'
959
+ ) . '"></i>'
960
+ . '</a>',
961
+ 'meta' => array('class' => 'cleantalk_admin_bar__blocked'),
962
+ ));
963
+
964
  // Firewall blocked / allowed counter
965
+ $wp_admin_bar->add_node(array(
966
  'parent' => 'spbc__parent_node',
967
  'id' => 'spbc_admin_bar__counter__firewall',
968
  'title' => '<a>'
969
+ . '<b>' . __('Security Firewall: ', 'cleantalk-spam-protect') . '</b>&nbsp;'
970
+ . '<b style="color: white;">'
971
+ . '<b style="color: green;">' . 0 . '</b> / '
972
+ . '<b style="color: red;">' . 0 . '</b>'
973
+ . '</b>'
974
+ . '<i class="icon-help-circled" title="' . __(
975
+ 'Passed / Blocked requests by Security Firewall for past 24 hours.',
976
+ 'cleantalk-spam-protect'
977
+ ) . '"></i>'
978
+ . '</a>',
979
+ 'meta' => array('class' => 'cleantalk_admin_bar__blocked'),
980
+ ));
981
+
982
  // Users online counter
983
+ $wp_admin_bar->add_node(array(
984
  'parent' => 'spbc__parent_node',
985
  'id' => 'spbc_admin_bar__counter__online',
986
  'title' => '<a>'
987
+ . '<span>' . __('Users online:', 'cleantalk-spam-protect') . '</span>'
988
+ . '&nbsp;<b class="spbc-admin_bar--user_counter">' . 0 . '</b>'
989
+ . '<i class="icon-help-circled" title="' . __(
990
+ 'Shows amount of currently logged in administrators. Updates each 10 seconds.',
991
+ 'cleantalk-spam-protect'
992
+ ) . '"></i>'
993
+ . '</a>',
994
+ 'meta' => array('class' => 'cleantalk_admin_bar__blocked'),
995
+ ));
996
+
997
  // Counter separator
998
+ $wp_admin_bar->add_node(array(
999
  'parent' => 'spbc__parent_node',
1000
  'id' => 'spbc_admin_bar__separator',
1001
+ 'title' => '<hr style="margin-top: 7px;" />',
1002
+ 'meta' => array('class' => 'cleantalk_admin_bar__separator')
1003
+ ));
1004
+
1005
  // Settings
1006
+ $wp_admin_bar->add_node(array(
1007
  'parent' => 'spbc__parent_node',
1008
  'id' => 'spbc_admin_bar__settings_link',
1009
+ 'title' => '<a>' . __('Settings', 'cleantalk-spam-protect') . '</a>',
1010
+ 'meta' => array('class' => 'cleantalk_admin_bar__blocked'),
1011
+ ));
1012
+
1013
  // Scanner
1014
+ $wp_admin_bar->add_node(array(
1015
  'parent' => 'spbc__parent_node',
1016
  'id' => 'spbc_admin_bar__scanner_link',
1017
+ 'title' => '<a style="display:inline">' . __('Scanner', 'cleantalk-spam-protect') . '</a>'
1018
+ . '/'
1019
+ . '<a style="display:inline">' . __('Start scan', 'cleantalk-spam-protect') . '</a>',
1020
+ 'meta' => array('class' => 'cleantalk_admin_bar__blocked'),
1021
+ ));
1022
+
1023
  // Support link
1024
+ $wp_admin_bar->add_node(array(
1025
  'parent' => 'spbc__parent_node',
1026
+ 'title' => '<hr style="margin-top: 7px;" /><a>' . __('Support', 'cleantalk-spam-protect') . '</a>',
1027
  'id' => 'spbc_admin_bar__support_link',
1028
+ 'meta' => array('class' => 'cleantalk_admin_bar__blocked'),
1029
+ ));
1030
  }
1031
 
1032
 
1033
  /**
1034
  * Unmark bad words
1035
+ *
1036
  * @param string $message
1037
+ *
1038
  * @return string Cleat comment
1039
  */
1040
+ function apbct_comment__unmark_red($message)
1041
+ {
1042
+ $message = preg_replace("/\<font rel\=\"cleantalk\" color\=\"\#FF1000\"\>(\S+)\<\/font>/iu", '$1', $message);
1043
 
1044
+ return $message;
1045
  }
1046
 
1047
  /**
1052
  * @param bool $change_status
1053
  * @param null|bool $direct_call
1054
  */
1055
+ function apbct_comment__send_feedback(
1056
+ $comment_id = null,
1057
+ $comment_status = null,
1058
+ $change_status = false,
1059
+ $direct_call = null
1060
+ ) {
1061
+ // For AJAX call
1062
+ if ( ! $direct_call ) {
1063
  check_ajax_referer('ct_secret_nonce', 'security');
1064
  }
1065
+
1066
+ $comment_id = ! $comment_id && isset($_POST['comment_id']) ? $_POST['comment_id'] : false;
1067
+ $comment_status = ! $comment_status && isset($_POST['comment_status']) ? $_POST['comment_status'] : false;
1068
+ $change_status = ! $change_status && isset($_POST['change_status']) ? $_POST['change_status'] : false;
1069
+
1070
+ // If enter params is empty exit
1071
+ if ( ! $comment_id || ! $comment_status ) {
1072
+ die();
1073
+ }
1074
+
1075
+ // $comment = get_comment($comment_id, 'ARRAY_A');
1076
+ $hash = get_comment_meta($comment_id, 'ct_hash', true);
1077
+
1078
+ // If we can send the feedback
1079
+ if ( $hash ) {
1080
+ // Approving
1081
+ if ( $comment_status == '1' || $comment_status == 'approve' ) {
1082
+ $result = ct_send_feedback($hash . ":1");
1083
+ // $comment['comment_content'] = apbct_comment__unmark_red($comment['comment_content']);
1084
+ // wp_update_comment($comment);
1085
+ $result === true ? 1 : 0;
1086
+ }
1087
+
1088
+ // Disapproving
1089
+ if ( $comment_status == 'spam' ) {
1090
+ $result = ct_send_feedback($hash . ":0");
1091
+ $result === true ? 1 : 0;
1092
+ }
1093
+ } else {
1094
+ $result = 'no_hash';
1095
+ }
1096
+
1097
+ // Changing comment status(folder) if flag is set. spam || approve
1098
+ if ( $change_status !== false ) {
1099
+ wp_set_comment_status($comment_id, $comment_status);
1100
+ }
1101
+
1102
+ if ( ! $direct_call ) {
1103
+ echo ! empty($result) ? $result : 0;
1104
+ die();
1105
+ } else {
1106
+ }
1107
  }
1108
 
1109
  /**
1113
  * @param null $status
1114
  * @param null $direct_call
1115
  */
1116
+ function apbct_user__send_feedback($user_id = null, $status = null, $direct_call = null)
1117
+ {
1118
+ check_ajax_referer('ct_secret_nonce', 'security');
1119
+
1120
+ if ( ! $direct_call ) {
1121
+ $user_id = $_POST['user_id'];
1122
+ $status = $_POST['status'];
1123
+ }
1124
+
1125
+ $hash = get_user_meta($user_id, 'ct_hash', true);
1126
+
1127
+ if ( $hash ) {
1128
+ if ( $status == 'approve' || $status == 1 ) {
1129
+ $result = ct_send_feedback($hash . ":1");
1130
+ $result === true ? 1 : 0;
1131
+ }
1132
+ if ( $status == 'spam' || $status == 'disapprove' || $status == 0 ) {
1133
+ $result = ct_send_feedback($hash . ":0");
1134
+ $result === true ? 1 : 0;
1135
+ }
1136
+ } else {
1137
+ $result = 'no_hash';
1138
+ }
1139
+
1140
+ if ( ! $direct_call ) {
1141
+ echo ! empty($result) ? $result : 0;
1142
+ die();
1143
+ } else {
1144
+ }
 
 
1145
  }
1146
 
1147
  /**
1152
  *
1153
  * @return null
1154
  */
1155
+ function apbct_user__delete__hook($user_id, $_reassign = null)
1156
+ {
1157
+ $hash = get_user_meta($user_id, 'ct_hash', true);
1158
+ if ( $hash !== '' ) {
1159
+ ct_feedback($hash, 0);
1160
+ }
1161
  }
1162
 
1163
  /**
1164
  * Check compatibility action
1165
  */
1166
  add_action('apbct__check_compatibility', 'apbct__check_compatibility_handler');
1167
+ function apbct__check_compatibility_handler()
1168
+ {
1169
  new \Cleantalk\Common\Compatibility();
1170
+ }
inc/cleantalk-ajax-handlers.php CHANGED
@@ -3,52 +3,58 @@
3
  /**
4
  * @psalm-suppress InvalidGlobal
5
  */
 
6
  global $apbct;
7
 
8
  // If this file is called directly, abort.
9
- if ( ! defined( 'DOING_AJAX' ) ) {
10
- http_response_code( 403 );
11
- die('Not allowed.');
12
  }
13
 
14
- require_once( __DIR__ . '/../lib/autoloader.php' );
15
 
16
- $plugin_info = get_file_data( __DIR__ . '/../cleantalk.php', array('Version' => 'Version', 'Name' => 'Plugin Name') );
17
- if( !defined( 'APBCT_VERSION' ) ) {
18
- define( 'APBCT_VERSION', $plugin_info['Version'] );
19
  }
20
 
21
- $apbct = new \Cleantalk\ApbctWP\State('cleantalk', array('settings', 'data'));
22
  $apbct->white_label = $apbct->network_settings['multisite__white_label'];
23
  $apbct->allow_custom_key = $apbct->network_settings['multisite__work_mode'] != 2;
24
- $apbct->api_key = ! is_multisite() || $apbct->allow_custom_key || $apbct->white_label ? $apbct->settings['apikey'] : $apbct->network_settings['apikey'];
 
25
  \Cleantalk\ApbctWP\State::setDefinitions();
26
 
27
  /*******************************************************************/
28
  /******************* H A N D L E R S H E R E *******************/
29
  /*******************************************************************/
30
- function apbct_js_keys__get() {
31
- require_once( __DIR__ . '/cleantalk-common.php' );
32
- require_once( __DIR__ . '/cleantalk-pluggable.php' );
33
- apbct_js_keys__get__ajax();
 
34
  }
35
 
36
- function apbct_email_check_before_post() {
37
- if (count($_POST) && isset($_POST['data']['email']) && !empty($_POST['data']['email'])) {
38
- $email = trim($_POST['data']['email']);
39
- $result = \Cleantalk\ApbctWP\API::method__email_check($email);
40
- if (isset($result['data'])) {
41
- die(json_encode(array('result' => $result['data'])));
42
- }
43
- die(json_encode(array('error' => 'ERROR_CHECKING_EMAIL')));
44
- }
45
- die(json_encode(array('error' => 'EMPTY_DATA')));
 
46
  }
47
 
48
- function apbct_alt_session__save__AJAX() {
49
- Cleantalk\ApbctWP\Variables\AltSessions::set_fromRemote();
 
50
  }
51
 
52
- function apbct_alt_session__get__AJAX() {
53
- Cleantalk\ApbctWP\Variables\AltSessions::get_fromRemote();
54
- }
 
3
  /**
4
  * @psalm-suppress InvalidGlobal
5
  */
6
+
7
  global $apbct;
8
 
9
  // If this file is called directly, abort.
10
+ if ( ! defined('DOING_AJAX') ) {
11
+ http_response_code(403);
12
+ die('Not allowed.');
13
  }
14
 
15
+ require_once(__DIR__ . '/../lib/autoloader.php');
16
 
17
+ $plugin_info = get_file_data(__DIR__ . '/../cleantalk.php', array('Version' => 'Version', 'Name' => 'Plugin Name'));
18
+ if ( ! defined('APBCT_VERSION') ) {
19
+ define('APBCT_VERSION', $plugin_info['Version']);
20
  }
21
 
22
+ $apbct = new \Cleantalk\ApbctWP\State('cleantalk', array('settings', 'data'));
23
  $apbct->white_label = $apbct->network_settings['multisite__white_label'];
24
  $apbct->allow_custom_key = $apbct->network_settings['multisite__work_mode'] != 2;
25
+ $apbct->api_key = ! is_multisite(
26
+ ) || $apbct->allow_custom_key || $apbct->white_label ? $apbct->settings['apikey'] : $apbct->network_settings['apikey'];
27
  \Cleantalk\ApbctWP\State::setDefinitions();
28
 
29
  /*******************************************************************/
30
  /******************* H A N D L E R S H E R E *******************/
31
  /*******************************************************************/
32
+ function apbct_js_keys__get()
33
+ {
34
+ require_once(__DIR__ . '/cleantalk-common.php');
35
+ require_once(__DIR__ . '/cleantalk-pluggable.php');
36
+ apbct_js_keys__get__ajax();
37
  }
38
 
39
+ function apbct_email_check_before_post()
40
+ {
41
+ if ( count($_POST) && isset($_POST['data']['email']) && ! empty($_POST['data']['email']) ) {
42
+ $email = trim($_POST['data']['email']);
43
+ $result = \Cleantalk\ApbctWP\API::methodEmailCheck($email);
44
+ if ( isset($result['data']) ) {
45
+ die(json_encode(array('result' => $result['data'])));
46
+ }
47
+ die(json_encode(array('error' => 'ERROR_CHECKING_EMAIL')));
48
+ }
49
+ die(json_encode(array('error' => 'EMPTY_DATA')));
50
  }
51
 
52
+ function apbct_alt_session__save__AJAX()
53
+ {
54
+ Cleantalk\ApbctWP\Variables\AltSessions::setFromRemote();
55
  }
56
 
57
+ function apbct_alt_session__get__AJAX()
58
+ {
59
+ Cleantalk\ApbctWP\Variables\AltSessions::getFromRemote();
60
+ }
inc/cleantalk-ajax.php CHANGED
@@ -1,12 +1,13 @@
1
  <?php
2
- /*
3
- AJAX functions
4
- */
 
5
 
6
  use Cleantalk\Variables\Post;
7
 
8
- $_cleantalk_ajax_actions_to_check[] = 'qcf_validate_form'; //Quick Contact Form
9
- $_cleantalk_ajax_actions_to_check[] = 'amoforms_submit'; //amoForms
10
 
11
  $_cleantalk_hooked_actions[] = 'rwp_ajax_action_rating'; //Don't check Reviewer plugin
12
 
@@ -16,102 +17,102 @@ $_cleantalk_hooked_actions[] = 'ct_feedback_comment';
16
  add_filter('mc4wp_form_errors', 'ct_mc4wp_ajax_hook');
17
 
18
  /*hooks for Usernoise Form*/
19
- add_action('un_feedback_form_body', 'ct_add_hidden_fields',1);
20
  add_filter('un_validate_feedback', 'ct_ajax_hook', 1, 2);
21
 
22
  /*hooks for AJAX Login & Register email validation*/
23
- add_action( 'wp_ajax_nopriv_validate_email', 'ct_validate_email_ajaxlogin',1 );
24
- add_action( 'wp_ajax_validate_email', 'ct_validate_email_ajaxlogin',1 );
25
- $_cleantalk_hooked_actions[]='validate_email';
26
 
27
  /*hooks for user registration*/
28
- add_action( 'user_register', 'ct_user_register_ajaxlogin',1 );
29
 
30
  /*hooks for WPUF pro */
31
- add_action( 'wp_ajax_nopriv_wpuf_submit_register', 'ct_ajax_hook',1 );
32
- add_action( 'wp_ajax_wpuf_submit_register', 'ct_ajax_hook',1 );
33
- $_cleantalk_hooked_actions[]='submit_register';
34
 
35
  /*hooks for MyMail */
36
- add_action( 'wp_ajax_nopriv_mymail_form_submit', 'ct_ajax_hook',1 );
37
- add_action( 'wp_ajax_mymail_form_submit', 'ct_ajax_hook',1 );
38
- $_cleantalk_hooked_actions[]='form_submit';
39
 
40
  /*hooks for MailPoet */
41
- add_action( 'wp_ajax_nopriv_wysija_ajax', 'ct_ajax_hook',1 );
42
- add_action( 'wp_ajax_wysija_ajax', 'ct_ajax_hook',1 );
43
- $_cleantalk_hooked_actions[]='wysija_ajax';
44
 
45
  /*hooks for cs_registration_validation */
46
- add_action( 'wp_ajax_nopriv_cs_registration_validation', 'ct_ajax_hook',1 );
47
- add_action( 'wp_ajax_cs_registration_validation', 'ct_ajax_hook',1 );
48
- $_cleantalk_hooked_actions[]='cs_registration_validation';
49
 
50
  /*hooks for send_message and request_appointment */
51
- add_action( 'wp_ajax_nopriv_send_message', 'ct_ajax_hook',1 );
52
- add_action( 'wp_ajax_send_message', 'ct_ajax_hook',1 );
53
- add_action( 'wp_ajax_nopriv_request_appointment', 'ct_ajax_hook',1 );
54
- add_action( 'wp_ajax_request_appointment', 'ct_ajax_hook',1 );
55
- $_cleantalk_hooked_actions[]='send_message';
56
- $_cleantalk_hooked_actions[]='request_appointment';
57
 
58
  /*hooks for zn_do_login */
59
- add_action( 'wp_ajax_nopriv_zn_do_login', 'ct_ajax_hook',1 );
60
- add_action( 'wp_ajax_zn_do_login', 'ct_ajax_hook',1 );
61
- $_cleantalk_hooked_actions[]='zn_do_login';
62
 
63
  /*hooks for zn_do_login */
64
- if(isset($_POST['action']) && $_POST['action'] === 'cscf-submitform'){
65
- add_filter('preprocess_comment', 'ct_ajax_hook', 1);
66
- $_cleantalk_hooked_actions[]='cscf-submitform';
67
  }
68
 
69
 
70
  /*hooks for visual form builder */
71
- add_action( 'wp_ajax_nopriv_vfb_submit', 'ct_ajax_hook',1 );
72
- add_action( 'wp_ajax_vfb_submit', 'ct_ajax_hook',1 );
73
- $_cleantalk_hooked_actions[]='vfb_submit';
74
 
75
  /*hooks for woocommerce_checkout*/
76
- add_action( 'wp_ajax_nopriv_woocommerce_checkout', 'ct_ajax_hook',1 );
77
- add_action( 'wp_ajax_woocommerce_checkout', 'ct_ajax_hook',1 );
78
- $_cleantalk_hooked_actions[]='woocommerce_checkout';
79
- $_cleantalk_hooked_actions[]='wcfm_ajax_controller';
80
 
81
  /*hooks for frm_action*/
82
- add_action( 'wp_ajax_nopriv_frm_entries_create', 'ct_ajax_hook',1 );
83
- add_action( 'wp_ajax_frm_entries_create', 'ct_ajax_hook',1 );
84
- $_cleantalk_hooked_actions[]='frm_entries_create';
85
 
86
- add_action( 'wp_ajax_nopriv_td_mod_register', 'ct_ajax_hook',1 );
87
- add_action( 'wp_ajax_td_mod_register', 'ct_ajax_hook',1 );
88
- $_cleantalk_hooked_actions[]='td_mod_register';
89
 
90
  /*hooks for tevolution theme*/
91
- add_action( 'wp_ajax_nopriv_tmpl_ajax_check_user_email', 'ct_ajax_hook',1 );
92
- add_action( 'wp_ajax_tmpl_ajax_check_user_email', 'ct_ajax_hook',1 );
93
- add_action( 'wp_ajax_nopriv_tevolution_submit_from_preview', 'ct_ajax_hook',1 );
94
- add_action( 'wp_ajax_tevolution_submit_from_preview', 'ct_ajax_hook',1 );
95
- add_action( 'wp_ajax_nopriv_submit_form_recaptcha_validation', 'ct_ajax_hook',1 );
96
- add_action( 'wp_ajax_tmpl_submit_form_recaptcha_validation', 'ct_ajax_hook',1 );
97
- $_cleantalk_hooked_actions[]='tmpl_ajax_check_user_email';
98
- $_cleantalk_hooked_actions[]='tevolution_submit_from_preview';
99
- $_cleantalk_hooked_actions[]='submit_form_recaptcha_validation';
100
 
101
  /* hooks for contact forms by web settler ajax*/
102
- add_action( 'wp_ajax_nopriv_smuzform-storage', 'ct_ajax_hook',1 );
103
- $_cleantalk_hooked_actions[]='smuzform_form_submit';
104
 
105
  /* hooks for reviewer plugin*/
106
- add_action( 'wp_ajax_nopriv_rwp_ajax_action_rating', 'ct_ajax_hook',1 );
107
- $_cleantalk_hooked_actions[]='rwp-submit-wrap';
108
 
109
- $_cleantalk_hooked_actions[]='post_update';
110
 
111
  /* Ninja Forms hoocked actions */
112
- $_cleantalk_hooked_actions[]='ninja_forms_ajax_submit';
113
- $_cleantalk_hooked_actions[]='nf_ajax_submit';
114
- $_cleantalk_hooked_actions[]='ninja_forms_process'; // Deprecated ?
115
 
116
  /* Follow-Up Emails */
117
  $_cleantalk_hooked_actions[] = 'fue_wc_set_cart_email'; // Don't check email via this plugin
@@ -123,7 +124,7 @@ $_cleantalk_hooked_actions[] = 'fue_wc_set_cart_email'; // Don't check email vi
123
  $_cleantalk_hooked_actions[] = 'fluentform_submit';
124
 
125
  /* Estimation Forms have the direct integration */
126
- if( class_exists('LFB_Core') ) {
127
  $_cleantalk_hooked_actions[] = 'send_email';
128
  }
129
 
@@ -132,56 +133,55 @@ if( class_exists('LFB_Core') ) {
132
  *
133
  * @param null $email
134
  */
135
- function ct_validate_email_ajaxlogin( $email=null ){
136
-
137
- $email = is_null( $email ) ? $email : $_POST['email'];
138
- $email = sanitize_email($email);
139
- $is_good = ! ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) || email_exists( $email ) );
140
-
141
- if( class_exists('AjaxLogin') && isset($_POST['action']) && $_POST['action'] === 'validate_email' ){
142
-
143
- $checkjs = apbct_js_test('ct_checkjs', $_POST);
144
- $sender_info['post_checkjs_passed'] = $checkjs;
145
- if ($checkjs === null){
146
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
147
- $sender_info['cookie_checkjs_passed'] = $checkjs;
148
- }
149
-
150
- //Making a call
151
- $base_call_result = apbct_base_call(
152
- array(
153
- 'sender_email' => $email,
154
- 'sender_nickname' => '',
155
- 'sender_info' => $sender_info,
156
- 'js_on' => $checkjs,
157
- ),
158
- true
159
- );
160
-
161
- $ct_result = $base_call_result['ct_result'];
162
-
163
- if ($ct_result->allow===0){
164
- $is_good=false;
165
- }
166
- }
167
-
168
- if($is_good){
169
- $ajaxresult=array(
170
  'description' => null,
171
- 'cssClass' => 'noon',
172
- 'code' => 'success'
173
- );
174
- }else{
175
- $ajaxresult=array(
176
  'description' => 'Invalid Email',
177
- 'cssClass' => 'error-container',
178
- 'code' => 'error'
179
- );
180
- }
181
-
182
- $ajaxresult = json_encode($ajaxresult);
183
- print $ajaxresult;
184
- wp_die();
185
  }
186
 
187
  /**
@@ -191,37 +191,35 @@ function ct_validate_email_ajaxlogin( $email=null ){
191
  *
192
  * @return mixed
193
  */
194
- function ct_user_register_ajaxlogin( $user_id )
195
  {
196
- if( class_exists('AjaxLogin') && isset($_POST['action']) && $_POST['action'] === 'register_submit' )
197
- {
198
-
199
- $checkjs = apbct_js_test('ct_checkjs', $_POST);
200
- $sender_info['post_checkjs_passed'] = $checkjs;
201
- if ($checkjs === null){
202
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
203
- $sender_info['cookie_checkjs_passed'] = $checkjs;
204
- }
205
-
206
- //Making a call
207
- $base_call_result = apbct_base_call(
208
- array(
209
- 'sender_email' => sanitize_email($_POST['email']),
210
- 'sender_nickname' => sanitize_email($_POST['login']),
211
- 'sender_info' => $sender_info,
212
- 'js_on' => $checkjs,
213
- ),
214
- true
215
- );
216
-
217
- $ct_result = $base_call_result['ct_result'];
218
-
219
- if ($ct_result->allow === 0)
220
- {
221
- wp_delete_user($user_id);
222
- }
223
- }
224
- return $user_id;
225
  }
226
 
227
  /**
@@ -232,16 +230,16 @@ function ct_user_register_ajaxlogin( $user_id )
232
  * @return array
233
  * @throws Exception
234
  */
235
- function ct_mc4wp_ajax_hook( array $errors )
236
  {
237
- $result = ct_ajax_hook();
238
 
239
- // only return modified errors array when function returned a string value (the message key)
240
- if( is_string( $result ) ) {
241
- $errors[] = $result;
242
- }
243
 
244
- return $errors;
245
  }
246
 
247
  /**
@@ -253,576 +251,667 @@ function ct_mc4wp_ajax_hook( array $errors )
253
  *
254
  * @throws Exception
255
  */
256
- function ct_ajax_hook( $message_obj = null )
257
  {
258
- global $current_user;
259
-
260
- $message_obj = (array) $message_obj;
261
-
262
- // Get current_user and set it globally
263
- apbct_wp_set_current_user($current_user instanceof WP_User ? $current_user : apbct_wp_get_current_user() );
264
-
265
  // $_REQUEST['action'] to skip. Go out because of not spam data
266
  $skip_post = array(
267
- 'apbct_js_keys__get', // Our service code
268
- 'gmaps_display_info_window', // Geo My WP pop-up windows.
269
- 'gmw_ps_display_info_window', // Geo My WP pop-up windows.
270
- 'the_champ_user_auth', // Super Socializer
271
- 'simbatfa-init-otp', //Two-Factor Auth
272
- 'wppb_msf_check_required_fields', //ProfileBuilder skip step checking
273
- 'boss_we_login', //Login form
274
- 'sidebar_login_process', // Login CF7
275
- 'cp_update_style_settings', // Convert Pro. Saving settings
276
- 'updraft_savesettings', // UpdraftPlus
277
- 'wpdUpdateAutomatically', //Comments update
278
- 'upload-attachment', // Skip ulpload attachments
279
- 'iwj_update_profile', //Skip profile page checker
280
- 'st_partner_create_service', //Skip add hotel via admin
281
- 'vp_ajax_vpt_option_save', // https://themeforest.net/item/motor-vehicles-parts-equipments-accessories-wordpress-woocommerce-theme/16829946
282
- 'mailster_send_test', //Mailster send test admin
283
- 'acf/validate_save_post', //ACF validate post admin
284
- 'admin:saveThemeOptions', //Ait-theme admin checking
285
- 'save_tourmaster_option', //Tourmaster admin save
286
- 'validate_register_email', // Service id #313320
287
- 'elementor_pro_forms_send_form', //Elementor Pro
288
- 'phone-orders-for-woocommerce', //Phone orders for woocommerce backend
289
- 'ihc_check_reg_field_ajax', //Ajax check required fields
290
- 'OSTC_lostPassword', //Lost password ajax form
291
- 'check_retina_image_availability', //There are too many ajax requests from mobile
292
- 'uap_check_reg_field_ajax', // Ultimate Affiliate Pro. Form validation.
293
- 'edit-comment', // Edit comments by admin ??? that shouldn't happen
294
- 'formcraft3_save_form_progress', // FormCraft Contact Form Builder for WordPress. Save progress.
295
- 'wpdmpp_save_settings', // PayPal save settings.
296
- 'iwj_login', // Fix for unknown plugin for user #133315
297
- 'custom_user_login', // Fix for unknown plugin for user #466875
298
- 'wordfence_ls_authenticate', //Fix for wordfence auth
299
- 'frm_strp_amount', //Admin stripe form
300
- 'wouCheckOnlineUsers', //Skip updraft admin checking users
301
- 'et_fb_get_shortcode_from_fb_object', //Skip generate shortcode
302
- 'pp_lf_process_login', //Skip login form
303
- 'check_email', //Ajax email checking
304
- 'dflg_do_sign_in_user', // Unknown plugin
305
- 'cartflows_save_cart_abandonment_data', // WooCommerce cartflow
306
- 'rcp_process_register_form', // WordPress Membership Plugin – Restrict Content
307
- 'give_process_donation', // GiveWP
308
- 'apus_ajax_login', // ???? plugin authorization
309
- 'bookly_save_customer', //bookly
310
- 'postmark_test', //Avocet
311
- 'postmark_save', //Avocet
312
- 'ck_get_subscriber', //ConvertKit checking the subscriber
313
- 'metorik_send_cart', //Metorik skip
314
- 'ppom_ajax_validation', // PPOM add to cart validation
315
- 'wpforms_form_abandonment', // WPForms. Quiting without submitting
316
- 'post_woo_ml_email_cookie', //Woocommerce system
317
- 'ig_es_draft_broadcast', //Icegram broadcast ajax
318
- 'simplefilelistpro_edit_job', //Simple File List editing current job
319
- 'wfu_ajax_action_ask_server', //WFU skip ask server
320
- 'wcap_save_guest_data', //WooCommerce skip
321
- 'ajaxlogin', //Skip ajax login redirect
322
- 'heartbeat', //Gravity multipage
323
- 'erforms_field_change_command', //ERForms internal request
324
- 'wl_out_of_stock_notify', // Sumo Waitlist
325
- 'rac_preadd_guest', //Rac internal request
326
- 'apbct_email_check_before_post', //Interal request
327
- 'edd_process_checkout', // Easy Digital Downloads ajax skip
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  /* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
 
 
329
  );
330
 
331
  global $apbct;
332
  // Skip test if
333
- if( !$apbct->settings['forms__general_contact_forms_test'] || // Test disabled
334
- !apbct_is_user_enable($apbct->user) || // User is admin, editor, author
335
- // (function_exists('get_current_user_id') && get_current_user_id() != 0) || // Check with default wp_* function if it's admin
336
- (!$apbct->settings['data__protect_logged_in'] && ($apbct->user instanceof WP_User) && $apbct->user->ID !== 0 ) || // Logged in user
337
- apbct_exclusions_check__url() || // url exclusions
338
- (isset($_POST['action']) && in_array($_POST['action'], $skip_post)) || // Special params
339
- (isset($_GET['action']) && in_array($_GET['action'], $skip_post)) || // Special params
340
- isset($_POST['quform_submit']) || //QForms multi-paged form skip
341
- // QAEngine Theme fix
342
- ( (string) current_filter() !== 'et_pre_insert_answer' &&
343
  (
344
- ( isset($message_obj['author']) && (int) $message_obj['author'] === 0) ||
345
- ( isset($message_obj['post_author']) && (int) $message_obj['post_author'] === 0)
346
- )
347
- ) ||
348
- (isset($_POST['action'], $_POST['arm_action']) && $_POST['action'] === 'arm_shortcode_form_ajax_action' && $_POST['arm_action'] === 'please-login') || //arm forms skip login
349
- ( isset($_POST['action']) && $_POST['action'] === 'erf_login_user' && in_array( 'easy-registration-forms/erforms.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) || //Easy Registration Forms login form skip
350
- (isset($_POST['action'], $_POST['endpoint'], $_POST['method']) && $_POST['action'] === 'mailpoet' && $_POST['endpoint'] === 'ImportExport' && $_POST['method'] === 'processImport') //Mailpoet import
351
- )
352
- {
353
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
354
  return false;
355
  }
356
 
357
- if( apbct_is_skip_request( true ) ) {
358
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . '(' . apbct_is_skip_request() . ')', $_POST );
 
 
 
 
 
359
  return false;
360
  }
361
-
362
  //General post_info for all ajax calls
363
- $post_info = array(
364
- 'comment_type' => 'feedback_ajax',
365
- 'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ), // Page URL must be an previous page
366
  );
367
- if( Post::get('action') === 'cleantalk_force_ajax_check' ) {
368
  $post_info['comment_type'] = 'feedback_ajax_external_form';
369
  }
370
 
371
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
372
-
373
- //QAEngine Theme answers
374
- if( !empty($message_obj) && isset($message_obj['post_type'], $message_obj['post_content']) ){
375
- $curr_user = get_user_by('id', $message_obj['author']);
376
- if (!$curr_user)
377
- $curr_user = get_user_by('id', $message_obj['post_author']);
378
- $ct_post_temp['comment'] = $message_obj['post_content'];
379
- $ct_post_temp['email'] = $curr_user->data->user_email;
380
- $ct_post_temp['name'] = $curr_user->data->user_login;
 
381
  }
382
-
383
  //CSCF fix
384
- if(isset($_POST['action']) && $_POST['action'] === 'cscf-submitform'){
385
- $ct_post_temp[] = $message_obj['comment_author'];
386
  $ct_post_temp[] = $message_obj['comment_author_email'];
387
- $ct_post_temp[] = $message_obj['comment_content'];
388
  }
389
-
390
- //??? fix
391
- if(isset($_POST['action'], $_POST['target']) && ( $_POST['action'] === 'request_appointment' || $_POST['action'] === 'send_message')){
392
- $ct_post_temp=$_POST;
393
- $ct_post_temp['target']=1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  }
395
-
396
- //UserPro fix
397
- if(isset($_POST['action'], $_POST['template']) && $_POST['action'] === 'userpro_process_form' && $_POST['template'] === 'register'){
398
- $ct_post_temp = $_POST;
399
- $ct_post_temp['shortcode'] = '';
400
- }
401
- //Pre-filled form 426869223
402
- if (isset($_POST['action'], $_POST['response-email-address'], $_POST['response-email-sender-address']) && $_POST['action'] === 'contact-owner:send') {
403
- unset($_POST['response-email-address']);
404
- unset($_POST['response-email-sender-address']);
405
- }
406
- //Reviewer fix
407
- if(isset($_POST['action']) && $_POST['action'] === 'rwp_ajax_action_rating')
408
- {
409
- $ct_post_temp['name'] = $_POST['user_name'];
410
- $ct_post_temp['email'] = $_POST['user_email'];
411
- $ct_post_temp['comment'] = $_POST['comment'];
412
- }
413
- //Woocommerce checkout
414
- if( Post::get( 'action' ) === 'woocommerce_checkout' || Post::get( 'action' ) === 'save_data' ){
415
- $post_info['comment_type'] = 'order';
416
- if( empty( $apbct->settings['forms__wc_checkout_test'] ) ){
417
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
418
- return false;
419
- }
420
- }
421
- //Easy Forms for Mailchimp
422
- if( Post::get('action') === 'process_form_submission' ){
423
- $post_info['comment_type'] = 'contact_enquire_wordpress_easy_forms_for_mailchimp';
424
- if( Post::get('form_data') ) {
425
- $form_data = explode( '&', urldecode( Post::get('form_data') ) );
426
- $form_data_arr = array();
427
- foreach ( $form_data as $val ) {
428
- $form_data_element = explode( '=', $val );
429
- $form_data_arr[$form_data_element[0]] = @$form_data_element[1];
430
- }
431
- if( isset( $form_data_arr['EMAIL'] ) )
432
- $ct_post_temp['email'] = $form_data_arr['EMAIL'];
433
- if( isset( $form_data_arr['FNAME'] ) )
434
- $ct_post_temp['nickname'] = $form_data_arr['FNAME'];
435
- }
436
- }
437
- if (isset($_POST['action']) && $_POST['action'] === 'ufbl_front_form_action'){
438
- $ct_post_temp = $_POST;
439
- foreach ($ct_post_temp as $key => $_value) {
440
- if (preg_match('/form_data_\d_name/', $key))
441
- unset($ct_post_temp[$key]);
442
- }
443
- }
444
-
445
- $ct_temp_msg_data = isset($ct_post_temp)
446
- ? ct_get_fields_any($ct_post_temp)
447
- : ct_get_fields_any($_POST);
448
-
449
- $sender_email = $ct_temp_msg_data['email'] ?: '';
450
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
451
- $subject = $ct_temp_msg_data['subject'] ?: '';
452
- $contact_form = $ct_temp_msg_data['contact'] ?: true;
453
- $message = $ct_temp_msg_data['message'] ?: array();
454
- if( $subject !== '' ) {
455
  $message['subject'] = $subject;
456
  }
457
-
458
  // Skip submission if no data found
459
- if ( $sender_email === ''|| $contact_form === false ) {
460
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
461
- return false;
 
462
  }
463
-
464
- // Mailpoet fix
465
- if (isset($message['wysijaData'], $message['wysijaplugin'], $message['task'], $message['controller']) && $message['wysijaplugin'] === 'wysija-newsletters' && $message['controller'] === 'campaigns') {
466
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
467
- return false;
 
468
  }
469
 
470
  // Mailpoet3 admin skip fix
471
- if (isset($_POST['action'], $_POST['method']) && $_POST['action'] === 'mailpoet' && $_POST['method'] === 'save') {
472
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
473
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  }
475
 
476
-
477
- // WP Foto Vote Fix
478
- if (!empty($_FILES)){
479
- foreach($message as $key => $_value){
480
- if(strpos($key, 'oje') !== false) {
481
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
482
- return false;
483
- }
484
- }
485
- }
486
-
487
- /**
488
- * @todo Contact form detect
489
- */
490
- // Detect contact form an set it's name to $contact_form to use later
491
- $contact_form = null;
492
- foreach($_POST as $param => $_value){
493
- if(strpos($param, 'et_pb_contactform_submit') === 0){
494
- $contact_form = 'contact_form_divi_theme';
495
- }
496
- if(strpos($param, 'avia_generated_form') === 0){
497
- $contact_form = 'contact_form_enfold_theme';
498
- }
499
- if(!empty($contact_form)) {
500
- break;
501
- }
502
- }
503
-
504
- $base_call_result = apbct_base_call(
505
- array(
506
- 'message' => $message,
507
- 'sender_email' => $sender_email,
508
- 'sender_nickname' => $sender_nickname,
509
- 'sender_info' => array('post_checkjs_passed' => $checkjs),
510
- 'post_info' => $post_info,
511
- 'js_on' => $checkjs,
512
- )
513
- );
514
- $ct_result = $base_call_result['ct_result'];
515
-
516
- if ($ct_result->allow == 0)
517
- {
518
- if ( isset($_POST['action']) && $_POST['action'] === 'wpuf_submit_register' ) {
519
- $result=array('success'=>false,'error'=>$ct_result->comment);
520
- @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
521
- print json_encode($result);
522
- die();
523
- }
524
-
525
- if( isset($_POST['action']) && $_POST['action'] === 'mymail_form_submit' ) {
526
- $result=array('success'=>false,'html'=>$ct_result->comment);
527
- @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
528
- print json_encode($result);
529
- die();
530
- }
531
-
532
- if(isset($_POST['action'], $_POST['task']) && $_POST['action'] === 'wysija_ajax' && $_POST['task'] !== 'send_preview' && $_POST['task'] !== 'send_test_mail') {
533
- $result=Array('result'=>false,'msgs'=>Array('updated'=>Array($ct_result->comment)));
534
- print $_GET['callback'].'('.json_encode($result).');';
535
- die();
536
- }
537
-
538
- if(isset($_POST['action']) && $_POST['action'] === 'cs_registration_validation') {
539
- $result=Array("type"=>"error","message"=>$ct_result->comment);
540
- print json_encode($result);
541
- die();
542
- }
543
-
544
- if(isset($_POST['action']) && ( $_POST['action'] === 'request_appointment' || $_POST['action'] === 'send_message')) {
545
- print $ct_result->comment;
546
- die();
547
- }
548
-
549
- if(isset($_POST['action']) && $_POST['action'] === 'zn_do_login') {
550
- print '<div id="login_error">'.$ct_result->comment.'</div>';
551
- die();
552
- }
553
-
554
- if(isset($_POST['action']) && $_POST['action'] === 'vfb_submit') {
555
- $result=Array('result'=>false,'message'=>$ct_result->comment);
556
- @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) );
557
- print json_encode($result);
558
- die();
559
- }
560
-
561
- if(isset($_POST['action']) && $_POST['action'] === 'woocommerce_checkout') {
562
- print $ct_result->comment;
563
- die();
564
- }
565
-
566
- if(isset($_POST['action']) && $_POST['action'] === 'frm_entries_create') {
567
- $result=Array('112'=>$ct_result->comment);
568
- print json_encode($result);
569
- die();
570
- }
571
-
572
- if(isset($_POST['cma-action']) && $_POST['cma-action'] === 'add') {
573
- $result=Array('success'=>0, 'thread_id'=>null,'messages'=>Array($ct_result->comment));
574
- print json_encode($result);
575
- die();
576
- }
577
-
578
- if(isset($_POST['action']) && $_POST['action'] === 'td_mod_register') {
579
- print json_encode(array('register', 0, $ct_result->comment));
580
- die();
581
- }
582
-
583
- if(isset($_POST['action']) && $_POST['action'] === 'tmpl_ajax_check_user_email') {
584
- print "17,email";
585
- die();
586
- }
587
-
588
- if(isset($_POST['action']) && ( $_POST['action'] === 'tevolution_submit_from_preview' || $_POST['action'] === 'submit_form_recaptcha_validation')) {
589
- print $ct_result->comment;
590
- die();
591
- }
592
-
593
- // WooWaitList
594
- // http://codecanyon.net/item/woowaitlist-woocommerce-back-in-stock-notifier/7103373
595
- if(isset($_POST['action']) && $_POST['action'] === 'wew_save_to_db_callback') {
596
- $result = array();
597
- $result['error'] = 1;
598
- $result['message'] = $ct_result->comment;
599
- $result['code'] = 5; // Unused code number in WooWaitlist
600
- print json_encode($result);
601
- die();
602
- }
603
-
604
- // UserPro
605
- if(isset($_POST['action'], $_POST['template']) && $_POST['action'] === 'userpro_process_form' && $_POST['template'] === 'register') {
606
- foreach($_POST as $key => $value) {
607
- $output[ $key ] = $value;
608
- }
609
- $output['template'] = $ct_result->comment;
610
- $output=json_encode($output);
611
- print_r($output);
612
- die;
613
- }
614
-
615
- // Quick event manager
616
- if(isset($_POST['action']) && $_POST['action'] === 'qem_validate_form') {
617
- $errors[] = 'registration_forbidden';
618
- $result = Array(
619
- 'success' => 'false',
620
- 'errors' => $errors,
621
- 'title' => $ct_result->comment
622
- );
623
- print json_encode($result);
624
- die();
625
- }
626
-
627
- // Quick Contact Form
628
- if(isset($_POST['action']) && $_POST['action'] === 'qcf_validate_form') {
629
- $result = Array(
630
- 'blurb' => "<h1>".$ct_result->comment."</h1>",
631
- 'display' => "Oops, got a few problems here",
632
- 'errors' => array(
633
- 0 => array(
634
- 'error' => 'error',
635
- 'name' => 'name'
636
- ),
637
- ),
638
- 'success' => 'false',
639
- );
640
- print json_encode($result);
641
- die();
642
- }
643
-
644
- // Usernoise Contact Form
645
- if(isset($_POST['title'], $_POST['email'], $_POST['type'], $_POST['ct_checkjs'])) {
646
- return array($ct_result->comment);
647
- }
648
-
649
- // amoForms
650
- if(isset($_POST['action']) && $_POST['action'] === 'amoforms_submit') {
651
- $result = Array(
652
- 'result' => true,
653
- 'type' => "html",
654
- 'value' => "<h1 style='font-size: 25px; color: red;'>".$ct_result->comment."</h1>",
655
- 'fast' => false
656
- );
657
- print json_encode($result);
658
- die();
659
- }
660
-
661
- // MailChimp for Wordpress Premium
662
- if(!empty($_POST['_mc4wp_form_id'])) {
663
- return 'ct_mc4wp_response';
664
- }
665
-
666
- // QAEngine Theme answers
667
- if ( !empty($message_obj) && isset($message_obj['post_type'], $message_obj['post_content']) ){
668
- throw new Exception($ct_result->comment);
669
- }
670
-
671
- //ES Add subscriber
672
- if(isset($_POST['action']) && $_POST['action'] === 'es_add_subscriber') {
673
- $result = Array(
674
- 'error' => 'unexpected-error',
675
- );
676
- print json_encode($result);
677
- die();
678
- }
679
-
680
- //Convertplug. Strpos because action value dynamically changes and depends on mailing service
681
- if (isset($_POST['action']) && strpos($_POST['action'], '_add_subscriber') !== false){
682
- $result = Array(
683
- 'action' => "message",
684
- 'detailed_msg' => "",
685
- 'email_status' => false,
686
- 'message' => "<h1 style='font-size: 25px; color: red;'>".$ct_result->comment."</h1>",
687
- 'status' => "error",
688
- 'url' => "none"
689
- );
690
- print json_encode($result);
691
- die();
692
- }
693
-
694
- // Ultimate Form Builder
695
- if (isset($_POST['action']) && $_POST['action'] === 'ufbl_front_form_action'){
696
- $result = Array(
697
- 'error_keys' => array(),
698
- 'error_flag' => 1,
699
- 'response_message' => $ct_result->comment
700
- );
701
- print json_encode($result);
702
- die();
703
- }
704
-
705
- // Smart Forms
706
- if (isset($_POST['action']) && $_POST['action'] === 'rednao_smart_forms_save_form_values'){
707
- $result = Array(
708
- 'message' => $ct_result->comment,
709
- 'refreshCaptcha' => 'n',
710
- 'success' => 'n'
711
- );
712
- print json_encode($result);
713
- die();
714
- }
715
-
716
- //cFormsII
717
- if(isset($_POST['action']) && $_POST['action'] === 'submitcform') {
718
- header('Content-Type: application/json');
719
- $result = Array(
720
- 'no' => isset($_POST['cforms_id']) ? $_POST['cforms_id'] : '',
721
- 'result' => 'failure',
722
- 'html' =>$ct_result->comment,
723
- 'hide' => false,
724
- 'redirection' => null
725
- );
726
- print json_encode($result);
727
- die();
728
- }
729
-
730
- //Contact Form by Web-Settler
731
- if(isset($_POST['smFieldData'])) {
732
- $result = Array(
733
- 'signal' => true,
734
- 'code' => 0,
735
- 'thanksMsg' => $ct_result->comment,
736
- 'errors' => array(),
737
- 'isMsg' => true,
738
- 'redirectUrl' => null
739
- );
740
- print json_encode($result);
741
- die();
742
- }
743
-
744
- //Reviewer
745
- if(isset($_POST['action']) && $_POST['action'] == 'rwp_ajax_action_rating') {
746
- $result = Array(
747
- 'success' => false,
748
- 'data' => array(0=>$ct_result->comment)
749
- );
750
- print json_encode($result);
751
- die();
752
- }
753
-
754
- // CouponXXL Theme
755
- if(isset($_POST['_wp_http_referer'], $_POST['register_field'], $_POST['action']) && strpos($_POST['_wp_http_referer'],'/register/account') !== false && $_POST['action'] === 'register'){
756
- $result = array(
757
- 'message' => '<div class="alert alert-error">'.$ct_result->comment.'</div>',
758
- );
759
- die(json_encode($result));
760
- }
761
-
762
- //ConvertPro
763
- if( isset( $_POST['action'] ) && ( $_POST['action'] === 'cp_v2_notify_admin' || $_POST['action'] === 'cpro_notify_via_email' ) ) {
764
- $result = Array(
765
- 'success' => false,
766
- 'data' => array('error'=>$ct_result->comment,'style_slug'=>'convertprot-form'),
767
- );
768
- print json_encode($result);
769
- die();
770
- }
771
-
772
- //Easy Forms for Mailchimp
773
- if( isset($_POST['action']) && $_POST['action'] === 'process_form_submission' ) {
774
- wp_send_json_error(
775
- array(
776
- 'error' => 1,
777
- 'response' => $ct_result->comment
778
- )
779
- );
780
- }
781
-
782
- //Optin wheel
783
- if( isset($_POST['action']) && ( $_POST['action'] === 'wof-lite-email-optin' || $_POST['action'] === 'wof-email-optin')) {
784
- wp_send_json_error(__($ct_result->comment, 'wp-optin-wheel'));
785
- }
786
-
787
- // Forminator
788
- if( isset($_POST['action']) && strpos($_POST['action'], 'forminator_submit') !== false ){
789
- wp_send_json_error(
790
- array(
791
- 'message' => $ct_result->comment,
792
- 'success' => false,
793
- 'errors' => array(),
794
- 'behav' => 'behaviour-thankyou',
795
- )
796
- );
797
- }
798
-
799
- // Easy Registration Form
800
- if( isset( $_POST['action'] ) && strpos($_POST['action'], 'erf_submit_form') !== false ) {
801
- wp_send_json_error( array( 0 => array( 'username_error', $ct_result->comment ) ) );
802
  }
803
 
804
  // Regular block output
805
- die(json_encode(array( 'apbct' => array(
806
- 'blocked' => true,
807
- 'comment' => $ct_result->comment,
808
- 'stop_script' => Post::has_string('action', 'tve_leads_ajax_')
809
- ? 1
810
- : 0
811
- ))));
812
- }
813
-
814
- // Allow == 1
815
- //QAEngine Theme answers
816
- if ( !empty($message_obj) && isset($message_obj['post_type'], $message_obj['post_content']) ){
817
- return $message_obj;
818
- }
819
- // Force AJAX check
820
- if( Post::get('action') === 'cleantalk_force_ajax_check' ){
821
- die(json_encode(array( 'apbct' => array(
822
- 'blocked' => false,
823
- 'allow' => true,
824
- ))));
825
- }
826
-
827
- return null;
 
 
 
 
 
 
 
 
 
 
 
 
828
  }
1
  <?php
2
+
3
+ /**
4
+ * AJAX functions
5
+ */
6
 
7
  use Cleantalk\Variables\Post;
8
 
9
+ $_cleantalk_ajax_actions_to_check[] = 'qcf_validate_form'; //Quick Contact Form
10
+ $_cleantalk_ajax_actions_to_check[] = 'amoforms_submit'; //amoForms
11
 
12
  $_cleantalk_hooked_actions[] = 'rwp_ajax_action_rating'; //Don't check Reviewer plugin
13
 
17
  add_filter('mc4wp_form_errors', 'ct_mc4wp_ajax_hook');
18
 
19
  /*hooks for Usernoise Form*/
20
+ add_action('un_feedback_form_body', 'ct_add_hidden_fields', 1);
21
  add_filter('un_validate_feedback', 'ct_ajax_hook', 1, 2);
22
 
23
  /*hooks for AJAX Login & Register email validation*/
24
+ add_action('wp_ajax_nopriv_validate_email', 'ct_validate_email_ajaxlogin', 1);
25
+ add_action('wp_ajax_validate_email', 'ct_validate_email_ajaxlogin', 1);
26
+ $_cleantalk_hooked_actions[] = 'validate_email';
27
 
28
  /*hooks for user registration*/
29
+ add_action('user_register', 'ct_user_register_ajaxlogin', 1);
30
 
31
  /*hooks for WPUF pro */
32
+ add_action('wp_ajax_nopriv_wpuf_submit_register', 'ct_ajax_hook', 1);
33
+ add_action('wp_ajax_wpuf_submit_register', 'ct_ajax_hook', 1);
34
+ $_cleantalk_hooked_actions[] = 'submit_register';
35
 
36
  /*hooks for MyMail */
37
+ add_action('wp_ajax_nopriv_mymail_form_submit', 'ct_ajax_hook', 1);
38
+ add_action('wp_ajax_mymail_form_submit', 'ct_ajax_hook', 1);
39
+ $_cleantalk_hooked_actions[] = 'form_submit';
40
 
41
  /*hooks for MailPoet */
42
+ add_action('wp_ajax_nopriv_wysija_ajax', 'ct_ajax_hook', 1);
43
+ add_action('wp_ajax_wysija_ajax', 'ct_ajax_hook', 1);
44
+ $_cleantalk_hooked_actions[] = 'wysija_ajax';
45
 
46
  /*hooks for cs_registration_validation */
47
+ add_action('wp_ajax_nopriv_cs_registration_validation', 'ct_ajax_hook', 1);
48
+ add_action('wp_ajax_cs_registration_validation', 'ct_ajax_hook', 1);
49
+ $_cleantalk_hooked_actions[] = 'cs_registration_validation';
50
 
51
  /*hooks for send_message and request_appointment */
52
+ add_action('wp_ajax_nopriv_send_message', 'ct_ajax_hook', 1);
53
+ add_action('wp_ajax_send_message', 'ct_ajax_hook', 1);
54
+ add_action('wp_ajax_nopriv_request_appointment', 'ct_ajax_hook', 1);
55
+ add_action('wp_ajax_request_appointment', 'ct_ajax_hook', 1);
56
+ $_cleantalk_hooked_actions[] = 'send_message';
57
+ $_cleantalk_hooked_actions[] = 'request_appointment';
58
 
59
  /*hooks for zn_do_login */
60
+ add_action('wp_ajax_nopriv_zn_do_login', 'ct_ajax_hook', 1);
61
+ add_action('wp_ajax_zn_do_login', 'ct_ajax_hook', 1);
62
+ $_cleantalk_hooked_actions[] = 'zn_do_login';
63
 
64
  /*hooks for zn_do_login */
65
+ if ( isset($_POST['action']) && $_POST['action'] === 'cscf-submitform' ) {
66
+ add_filter('preprocess_comment', 'ct_ajax_hook', 1);
67
+ $_cleantalk_hooked_actions[] = 'cscf-submitform';
68
  }
69
 
70
 
71
  /*hooks for visual form builder */
72
+ add_action('wp_ajax_nopriv_vfb_submit', 'ct_ajax_hook', 1);
73
+ add_action('wp_ajax_vfb_submit', 'ct_ajax_hook', 1);
74
+ $_cleantalk_hooked_actions[] = 'vfb_submit';
75
 
76
  /*hooks for woocommerce_checkout*/
77
+ add_action('wp_ajax_nopriv_woocommerce_checkout', 'ct_ajax_hook', 1);
78
+ add_action('wp_ajax_woocommerce_checkout', 'ct_ajax_hook', 1);
79
+ $_cleantalk_hooked_actions[] = 'woocommerce_checkout';
80
+ $_cleantalk_hooked_actions[] = 'wcfm_ajax_controller';
81
 
82
  /*hooks for frm_action*/
83
+ add_action('wp_ajax_nopriv_frm_entries_create', 'ct_ajax_hook', 1);
84
+ add_action('wp_ajax_frm_entries_create', 'ct_ajax_hook', 1);
85
+ $_cleantalk_hooked_actions[] = 'frm_entries_create';
86
 
87
+ add_action('wp_ajax_nopriv_td_mod_register', 'ct_ajax_hook', 1);
88
+ add_action('wp_ajax_td_mod_register', 'ct_ajax_hook', 1);
89
+ $_cleantalk_hooked_actions[] = 'td_mod_register';
90
 
91
  /*hooks for tevolution theme*/
92
+ add_action('wp_ajax_nopriv_tmpl_ajax_check_user_email', 'ct_ajax_hook', 1);
93
+ add_action('wp_ajax_tmpl_ajax_check_user_email', 'ct_ajax_hook', 1);
94
+ add_action('wp_ajax_nopriv_tevolution_submit_from_preview', 'ct_ajax_hook', 1);
95
+ add_action('wp_ajax_tevolution_submit_from_preview', 'ct_ajax_hook', 1);
96
+ add_action('wp_ajax_nopriv_submit_form_recaptcha_validation', 'ct_ajax_hook', 1);
97
+ add_action('wp_ajax_tmpl_submit_form_recaptcha_validation', 'ct_ajax_hook', 1);
98
+ $_cleantalk_hooked_actions[] = 'tmpl_ajax_check_user_email';
99
+ $_cleantalk_hooked_actions[] = 'tevolution_submit_from_preview';
100
+ $_cleantalk_hooked_actions[] = 'submit_form_recaptcha_validation';
101
 
102
  /* hooks for contact forms by web settler ajax*/
103
+ add_action('wp_ajax_nopriv_smuzform-storage', 'ct_ajax_hook', 1);
104
+ $_cleantalk_hooked_actions[] = 'smuzform_form_submit';
105
 
106
  /* hooks for reviewer plugin*/
107
+ add_action('wp_ajax_nopriv_rwp_ajax_action_rating', 'ct_ajax_hook', 1);
108
+ $_cleantalk_hooked_actions[] = 'rwp-submit-wrap';
109
 
110
+ $_cleantalk_hooked_actions[] = 'post_update';
111
 
112
  /* Ninja Forms hoocked actions */
113
+ $_cleantalk_hooked_actions[] = 'ninja_forms_ajax_submit';
114
+ $_cleantalk_hooked_actions[] = 'nf_ajax_submit';
115
+ $_cleantalk_hooked_actions[] = 'ninja_forms_process'; // Deprecated ?
116
 
117
  /* Follow-Up Emails */
118
  $_cleantalk_hooked_actions[] = 'fue_wc_set_cart_email'; // Don't check email via this plugin
124
  $_cleantalk_hooked_actions[] = 'fluentform_submit';
125
 
126
  /* Estimation Forms have the direct integration */
127
+ if ( class_exists('LFB_Core') ) {
128
  $_cleantalk_hooked_actions[] = 'send_email';
129
  }
130
 
133
  *
134
  * @param null $email
135
  */
136
+ function ct_validate_email_ajaxlogin($email = null)
137
+ {
138
+ $email = is_null($email) ? $email : $_POST['email'];
139
+ $email = sanitize_email($email);
140
+ $is_good = ! ( ! filter_var($email, FILTER_VALIDATE_EMAIL) || email_exists($email));
141
+
142
+ if ( class_exists('AjaxLogin') && isset($_POST['action']) && $_POST['action'] === 'validate_email' ) {
143
+ $checkjs = apbct_js_test('ct_checkjs', $_POST);
144
+ $sender_info['post_checkjs_passed'] = $checkjs;
145
+ if ( $checkjs === null ) {
146
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
147
+ $sender_info['cookie_checkjs_passed'] = $checkjs;
148
+ }
149
+
150
+ //Making a call
151
+ $base_call_result = apbct_base_call(
152
+ array(
153
+ 'sender_email' => $email,
154
+ 'sender_nickname' => '',
155
+ 'sender_info' => $sender_info,
156
+ 'js_on' => $checkjs,
157
+ ),
158
+ true
159
+ );
160
+
161
+ $ct_result = $base_call_result['ct_result'];
162
+
163
+ if ( $ct_result->allow === 0 ) {
164
+ $is_good = false;
165
+ }
166
+ }
167
+
168
+ if ( $is_good ) {
169
+ $ajaxresult = array(
 
170
  'description' => null,
171
+ 'cssClass' => 'noon',
172
+ 'code' => 'success'
173
+ );
174
+ } else {
175
+ $ajaxresult = array(
176
  'description' => 'Invalid Email',
177
+ 'cssClass' => 'error-container',
178
+ 'code' => 'error'
179
+ );
180
+ }
181
+
182
+ $ajaxresult = json_encode($ajaxresult);
183
+ print $ajaxresult;
184
+ wp_die();
185
  }
186
 
187
  /**
191
  *
192
  * @return mixed
193
  */
194
+ function ct_user_register_ajaxlogin($user_id)
195
  {
196
+ if ( class_exists('AjaxLogin') && isset($_POST['action']) && $_POST['action'] === 'register_submit' ) {
197
+ $checkjs = apbct_js_test('ct_checkjs', $_POST);
198
+ $sender_info['post_checkjs_passed'] = $checkjs;
199
+ if ( $checkjs === null ) {
200
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
201
+ $sender_info['cookie_checkjs_passed'] = $checkjs;
202
+ }
203
+
204
+ //Making a call
205
+ $base_call_result = apbct_base_call(
206
+ array(
207
+ 'sender_email' => sanitize_email($_POST['email']),
208
+ 'sender_nickname' => sanitize_email($_POST['login']),
209
+ 'sender_info' => $sender_info,
210
+ 'js_on' => $checkjs,
211
+ ),
212
+ true
213
+ );
214
+
215
+ $ct_result = $base_call_result['ct_result'];
216
+
217
+ if ( $ct_result->allow === 0 ) {
218
+ wp_delete_user($user_id);
219
+ }
220
+ }
221
+
222
+ return $user_id;
 
 
223
  }
224
 
225
  /**
230
  * @return array
231
  * @throws Exception
232
  */
233
+ function ct_mc4wp_ajax_hook(array $errors)
234
  {
235
+ $result = ct_ajax_hook();
236
 
237
+ // only return modified errors array when function returned a string value (the message key)
238
+ if ( is_string($result) ) {
239
+ $errors[] = $result;
240
+ }
241
 
242
+ return $errors;
243
  }
244
 
245
  /**
251
  *
252
  * @throws Exception
253
  */
254
+ function ct_ajax_hook($message_obj = null)
255
  {
256
+ global $current_user;
257
+
258
+ $message_obj = (array)$message_obj;
259
+
260
+ // Get current_user and set it globally
261
+ apbct_wp_set_current_user($current_user instanceof WP_User ? $current_user : apbct_wp_get_current_user());
262
+
263
  // $_REQUEST['action'] to skip. Go out because of not spam data
264
  $skip_post = array(
265
+ 'apbct_js_keys__get',
266
+ // Our service code
267
+ 'gmaps_display_info_window',
268
+ // Geo My WP pop-up windows.
269
+ 'gmw_ps_display_info_window',
270
+ // Geo My WP pop-up windows.
271
+ 'the_champ_user_auth',
272
+ // Super Socializer
273
+ 'simbatfa-init-otp',
274
+ //Two-Factor Auth
275
+ 'wppb_msf_check_required_fields',
276
+ //ProfileBuilder skip step checking
277
+ 'boss_we_login',
278
+ //Login form
279
+ 'sidebar_login_process',
280
+ // Login CF7
281
+ 'cp_update_style_settings',
282
+ // Convert Pro. Saving settings
283
+ 'updraft_savesettings',
284
+ // UpdraftPlus
285
+ 'wpdUpdateAutomatically',
286
+ //Comments update
287
+ 'upload-attachment',
288
+ // Skip ulpload attachments
289
+ 'iwj_update_profile',
290
+ //Skip profile page checker
291
+ 'st_partner_create_service',
292
+ //Skip add hotel via admin
293
+ 'vp_ajax_vpt_option_save',
294
+ // https://themeforest.net/item/motor-vehicles-parts-equipments-accessories-wordpress-woocommerce-theme/16829946
295
+ 'mailster_send_test',
296
+ //Mailster send test admin
297
+ 'acf/validate_save_post',
298
+ //ACF validate post admin
299
+ 'admin:saveThemeOptions',
300
+ //Ait-theme admin checking
301
+ 'save_tourmaster_option',
302
+ //Tourmaster admin save
303
+ 'validate_register_email',
304
+ // Service id #313320
305
+ 'elementor_pro_forms_send_form',
306
+ //Elementor Pro
307
+ 'phone-orders-for-woocommerce',
308
+ //Phone orders for woocommerce backend
309
+ 'ihc_check_reg_field_ajax',
310
+ //Ajax check required fields
311
+ 'OSTC_lostPassword',
312
+ //Lost password ajax form
313
+ 'check_retina_image_availability',
314
+ //There are too many ajax requests from mobile
315
+ 'uap_check_reg_field_ajax',
316
+ // Ultimate Affiliate Pro. Form validation.
317
+ 'edit-comment',
318
+ // Edit comments by admin ??? that shouldn't happen
319
+ 'formcraft3_save_form_progress',
320
+ // FormCraft – Contact Form Builder for WordPress. Save progress.
321
+ 'wpdmpp_save_settings',
322
+ // PayPal save settings.
323
+ 'iwj_login',
324
+ // Fix for unknown plugin for user #133315
325
+ 'custom_user_login',
326
+ // Fix for unknown plugin for user #466875
327
+ 'wordfence_ls_authenticate',
328
+ //Fix for wordfence auth
329
+ 'frm_strp_amount',
330
+ //Admin stripe form
331
+ 'wouCheckOnlineUsers',
332
+ //Skip updraft admin checking users
333
+ 'et_fb_get_shortcode_from_fb_object',
334
+ //Skip generate shortcode
335
+ 'pp_lf_process_login',
336
+ //Skip login form
337
+ 'check_email',
338
+ //Ajax email checking
339
+ 'dflg_do_sign_in_user',
340
+ // Unknown plugin
341
+ 'cartflows_save_cart_abandonment_data',
342
+ // WooCommerce cartflow
343
+ 'rcp_process_register_form',
344
+ // WordPress Membership Plugin – Restrict Content
345
+ 'give_process_donation',
346
+ // GiveWP
347
+ 'apus_ajax_login',
348
+ // ???? plugin authorization
349
+ 'bookly_save_customer',
350
+ //bookly
351
+ 'postmark_test',
352
+ //Avocet
353
+ 'postmark_save',
354
+ //Avocet
355
+ 'ck_get_subscriber',
356
+ //ConvertKit checking the subscriber
357
+ 'metorik_send_cart',
358
+ //Metorik skip
359
+ 'ppom_ajax_validation',
360
+ // PPOM add to cart validation
361
+ 'wpforms_form_abandonment',
362
+ // WPForms. Quiting without submitting
363
+ 'post_woo_ml_email_cookie',
364
+ //Woocommerce system
365
+ 'ig_es_draft_broadcast',
366
+ //Icegram broadcast ajax
367
+ 'simplefilelistpro_edit_job',
368
+ //Simple File List editing current job
369
+ 'wfu_ajax_action_ask_server',
370
+ //WFU skip ask server
371
+ 'wcap_save_guest_data',
372
+ //WooCommerce skip
373
+ 'ajaxlogin',
374
+ //Skip ajax login redirect
375
+ 'heartbeat',
376
+ //Gravity multipage
377
+ 'erforms_field_change_command',
378
+ //ERForms internal request
379
+ 'wl_out_of_stock_notify',
380
+ // Sumo Waitlist
381
+ 'rac_preadd_guest',
382
+ //Rac internal request
383
+ 'apbct_email_check_before_post',
384
+ //Interal request
385
+ 'edd_process_checkout',
386
+ // Easy Digital Downloads ajax skip
387
  /* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
388
+ //Unknown plugin Ticket #25047
389
+ 'alhbrmeu',
390
  );
391
 
392
  global $apbct;
393
  // Skip test if
394
+ if ( ! $apbct->settings['forms__general_contact_forms_test'] || // Test disabled
395
+ ! apbct_is_user_enable($apbct->user) || // User is admin, editor, author
396
+ // (function_exists('get_current_user_id') && get_current_user_id() != 0) || // Check with default wp_* function if it's admin
397
+ ( ! $apbct->settings['data__protect_logged_in'] && ($apbct->user instanceof WP_User) && $apbct->user->ID !== 0) || // Logged in user
398
+ apbct_exclusions_check__url() || // url exclusions
399
+ (isset($_POST['action']) && in_array($_POST['action'], $skip_post)) || // Special params
400
+ (isset($_GET['action']) && in_array($_GET['action'], $skip_post)) || // Special params
401
+ isset($_POST['quform_submit']) || //QForms multi-paged form skip
402
+ // QAEngine Theme fix
403
+ ((string)current_filter() !== 'et_pre_insert_answer' &&
404
  (
405
+ (isset($message_obj['author']) && (int)$message_obj['author'] === 0) ||
406
+ (isset($message_obj['post_author']) && (int)$message_obj['post_author'] === 0)
407
+ )
408
+ ) ||
409
+ (isset($_POST['action'], $_POST['arm_action']) && $_POST['action'] === 'arm_shortcode_form_ajax_action' && $_POST['arm_action'] === 'please-login') || //arm forms skip login
410
+ (isset($_POST['action']) && $_POST['action'] === 'erf_login_user' && in_array('easy-registration-forms/erforms.php', apply_filters('active_plugins', get_option('active_plugins')))) || //Easy Registration Forms login form skip
411
+ (isset($_POST['action'], $_POST['endpoint'], $_POST['method']) && $_POST['action'] === 'mailpoet' && $_POST['endpoint'] === 'ImportExport' && $_POST['method'] === 'processImport') //Mailpoet import
412
+ ) {
413
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
414
+
415
  return false;
416
  }
417
 
418
+ if ( apbct_is_skip_request(true) ) {
419
+ do_action(
420
+ 'apbct_skipped_request',
421
+ __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . '(' . apbct_is_skip_request() . ')',
422
+ $_POST
423
+ );
424
+
425
  return false;
426
  }
427
+
428
  //General post_info for all ajax calls
429
+ $post_info = array(
430
+ 'comment_type' => 'feedback_ajax',
431
+ 'post_url' => apbct_get_server_variable('HTTP_REFERER'), // Page URL must be an previous page
432
  );
433
+ if ( Post::get('action') === 'cleantalk_force_ajax_check' ) {
434
  $post_info['comment_type'] = 'feedback_ajax_external_form';
435
  }
436
 
437
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
438
+
439
+ //QAEngine Theme answers
440
+ if ( ! empty($message_obj) && isset($message_obj['post_type'], $message_obj['post_content']) ) {
441
+ $curr_user = get_user_by('id', $message_obj['author']);
442
+ if ( ! $curr_user ) {
443
+ $curr_user = get_user_by('id', $message_obj['post_author']);
444
+ }
445
+ $ct_post_temp['comment'] = $message_obj['post_content'];
446
+ $ct_post_temp['email'] = $curr_user->data->user_email;
447
+ $ct_post_temp['name'] = $curr_user->data->user_login;
448
  }
449
+
450
  //CSCF fix
451
+ if ( isset($_POST['action']) && $_POST['action'] === 'cscf-submitform' ) {
452
+ $ct_post_temp[] = $message_obj['comment_author'];
453
  $ct_post_temp[] = $message_obj['comment_author_email'];
454
+ $ct_post_temp[] = $message_obj['comment_content'];
455
  }
456
+
457
+ //??? fix
458
+ if ( isset($_POST['action'], $_POST['target']) && ($_POST['action'] === 'request_appointment' || $_POST['action'] === 'send_message') ) {
459
+ $ct_post_temp = $_POST;
460
+ $ct_post_temp['target'] = 1;
461
+ }
462
+
463
+ //UserPro fix
464
+ if ( isset($_POST['action'], $_POST['template']) && $_POST['action'] === 'userpro_process_form' && $_POST['template'] === 'register' ) {
465
+ $ct_post_temp = $_POST;
466
+ $ct_post_temp['shortcode'] = '';
467
+ }
468
+ //Pre-filled form 426869223
469
+ if ( isset($_POST['action'], $_POST['response-email-address'], $_POST['response-email-sender-address']) && $_POST['action'] === 'contact-owner:send' ) {
470
+ unset($_POST['response-email-address']);
471
+ unset($_POST['response-email-sender-address']);
472
+ }
473
+ //Reviewer fix
474
+ if ( isset($_POST['action']) && $_POST['action'] === 'rwp_ajax_action_rating' ) {
475
+ $ct_post_temp['name'] = $_POST['user_name'];
476
+ $ct_post_temp['email'] = $_POST['user_email'];
477
+ $ct_post_temp['comment'] = $_POST['comment'];
478
  }
479
+ //Woocommerce checkout
480
+ if ( Post::get('action') === 'woocommerce_checkout' || Post::get('action') === 'save_data' ) {
481
+ $post_info['comment_type'] = 'order';
482
+ if ( empty($apbct->settings['forms__wc_checkout_test']) ) {
483
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
484
+
485
+ return false;
486
+ }
487
+ }
488
+ //Easy Forms for Mailchimp
489
+ if ( Post::get('action') === 'process_form_submission' ) {
490
+ $post_info['comment_type'] = 'contact_enquire_wordpress_easy_forms_for_mailchimp';
491
+ if ( Post::get('form_data') ) {
492
+ $form_data = explode('&', urldecode(Post::get('form_data')));
493
+ $form_data_arr = array();
494
+ foreach ( $form_data as $val ) {
495
+ $form_data_element = explode('=', $val);
496
+ $form_data_arr[$form_data_element[0]] = @$form_data_element[1];
497
+ }
498
+ if ( isset($form_data_arr['EMAIL']) ) {
499
+ $ct_post_temp['email'] = $form_data_arr['EMAIL'];
500
+ }
501
+ if ( isset($form_data_arr['FNAME']) ) {
502
+ $ct_post_temp['nickname'] = $form_data_arr['FNAME'];
503
+ }
504
+ }
505
+ }
506
+ if ( isset($_POST['action']) && $_POST['action'] === 'ufbl_front_form_action' ) {
507
+ $ct_post_temp = $_POST;
508
+ foreach ( $ct_post_temp as $key => $_value ) {
509
+ if ( preg_match('/form_data_\d_name/', $key) ) {
510
+ unset($ct_post_temp[$key]);
511
+ }
512
+ }
513
+ }
514
+
515
+ $ct_temp_msg_data = isset($ct_post_temp)
516
+ ? ct_get_fields_any($ct_post_temp)
517
+ : ct_get_fields_any($_POST);
518
+
519
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
520
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
521
+ $subject = $ct_temp_msg_data['subject'] ?: '';
522
+ $contact_form = $ct_temp_msg_data['contact'] ?: true;
523
+ $message = $ct_temp_msg_data['message'] ?: array();
524
+ if ( $subject !== '' ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
525
  $message['subject'] = $subject;
526
  }
527
+
528
  // Skip submission if no data found
529
+ if ( $sender_email === '' || $contact_form === false ) {
530
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
531
+
532
+ return false;
533
  }
534
+
535
+ // Mailpoet fix
536
+ if ( isset($message['wysijaData'], $message['wysijaplugin'], $message['task'], $message['controller']) && $message['wysijaplugin'] === 'wysija-newsletters' && $message['controller'] === 'campaigns' ) {
537
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
538
+
539
+ return false;
540
  }
541
 
542
  // Mailpoet3 admin skip fix
543
+ if ( isset($_POST['action'], $_POST['method']) && $_POST['action'] === 'mailpoet' && $_POST['method'] === 'save' ) {
544
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
545
+
546
+ return false;
547
+ }
548
+
549
+
550
+ // WP Foto Vote Fix
551
+ if ( ! empty($_FILES) ) {
552
+ foreach ( $message as $key => $_value ) {
553
+ if ( strpos($key, 'oje') !== false ) {
554
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
555
+
556
+ return false;
557
+ }
558
+ }
559
  }
560
 
561
+ /**
562
+ * @todo Contact form detect
563
+ */
564
+ // Detect contact form an set it's name to $contact_form to use later
565
+ $contact_form = null;
566
+ foreach ( $_POST as $param => $_value ) {
567
+ if ( strpos($param, 'et_pb_contactform_submit') === 0 ) {
568
+ $contact_form = 'contact_form_divi_theme';
569
+ }
570
+ if ( strpos($param, 'avia_generated_form') === 0 ) {
571
+ $contact_form = 'contact_form_enfold_theme';
572
+ }
573
+ if ( ! empty($contact_form) ) {
574
+ break;
575
+ }
576
+ }
577
+
578
+ $base_call_result = apbct_base_call(
579
+ array(
580
+ 'message' => $message,
581
+ 'sender_email' => $sender_email,
582
+ 'sender_nickname' => $sender_nickname,
583
+ 'sender_info' => array('post_checkjs_passed' => $checkjs),
584
+ 'post_info' => $post_info,
585
+ 'js_on' => $checkjs,
586
+ )
587
+ );
588
+ $ct_result = $base_call_result['ct_result'];
589
+
590
+ if ( $ct_result->allow == 0 ) {
591
+ if ( isset($_POST['action']) && $_POST['action'] === 'wpuf_submit_register' ) {
592
+ $result = array('success' => false, 'error' => $ct_result->comment);
593
+ @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
594
+ print json_encode($result);
595
+ die();
596
+ }
597
+
598
+ if ( isset($_POST['action']) && $_POST['action'] === 'mymail_form_submit' ) {
599
+ $result = array('success' => false, 'html' => $ct_result->comment);
600
+ @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
601
+ print json_encode($result);
602
+ die();
603
+ }
604
+
605
+ if ( isset($_POST['action'], $_POST['task']) && $_POST['action'] === 'wysija_ajax' && $_POST['task'] !== 'send_preview' && $_POST['task'] !== 'send_test_mail' ) {
606
+ $result = array('result' => false, 'msgs' => array('updated' => array($ct_result->comment)));
607
+ print $_GET['callback'] . '(' . json_encode($result) . ');';
608
+ die();
609
+ }
610
+
611
+ if ( isset($_POST['action']) && $_POST['action'] === 'cs_registration_validation' ) {
612
+ $result = array("type" => "error", "message" => $ct_result->comment);
613
+ print json_encode($result);
614
+ die();
615
+ }
616
+
617
+ if ( isset($_POST['action']) && ($_POST['action'] === 'request_appointment' || $_POST['action'] === 'send_message') ) {
618
+ print $ct_result->comment;
619
+ die();
620
+ }
621
+
622
+ if ( isset($_POST['action']) && $_POST['action'] === 'zn_do_login' ) {
623
+ print '<div id="login_error">' . $ct_result->comment . '</div>';
624
+ die();
625
+ }
626
+
627
+ if ( isset($_POST['action']) && $_POST['action'] === 'vfb_submit' ) {
628
+ $result = array('result' => false, 'message' => $ct_result->comment);
629
+ @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
630
+ print json_encode($result);
631
+ die();
632
+ }
633
+
634
+ if ( isset($_POST['action']) && $_POST['action'] === 'woocommerce_checkout' ) {
635
+ print $ct_result->comment;
636
+ die();
637
+ }
638
+
639
+ if ( isset($_POST['action']) && $_POST['action'] === 'frm_entries_create' ) {
640
+ $result = array('112' => $ct_result->comment);
641
+ print json_encode($result);
642
+ die();
643
+ }
644
+
645
+ if ( isset($_POST['cma-action']) && $_POST['cma-action'] === 'add' ) {
646
+ $result = array('success' => 0, 'thread_id' => null, 'messages' => array($ct_result->comment));
647
+ print json_encode($result);
648
+ die();
649
+ }
650
+
651
+ if ( isset($_POST['action']) && $_POST['action'] === 'td_mod_register' ) {
652
+ print json_encode(array('register', 0, $ct_result->comment));
653
+ die();
654
+ }
655
+
656
+ if ( isset($_POST['action']) && $_POST['action'] === 'tmpl_ajax_check_user_email' ) {
657
+ print "17,email";
658
+ die();
659
+ }
660
+
661
+ if ( isset($_POST['action']) && ($_POST['action'] === 'tevolution_submit_from_preview' || $_POST['action'] === 'submit_form_recaptcha_validation') ) {
662
+ print $ct_result->comment;
663
+ die();
664
+ }
665
+
666
+ // WooWaitList
667
+ // http://codecanyon.net/item/woowaitlist-woocommerce-back-in-stock-notifier/7103373
668
+ if ( isset($_POST['action']) && $_POST['action'] === 'wew_save_to_db_callback' ) {
669
+ $result = array();
670
+ $result['error'] = 1;
671
+ $result['message'] = $ct_result->comment;
672
+ $result['code'] = 5; // Unused code number in WooWaitlist
673
+ print json_encode($result);
674
+ die();
675
+ }
676
+
677
+ // UserPro
678
+ if ( isset($_POST['action'], $_POST['template']) && $_POST['action'] === 'userpro_process_form' && $_POST['template'] === 'register' ) {
679
+ foreach ( $_POST as $key => $value ) {
680
+ $output[$key] = $value;
681
+ }
682
+ $output['template'] = $ct_result->comment;
683
+ $output = json_encode($output);
684
+ print_r($output);
685
+ die;
686
+ }
687
+
688
+ // Quick event manager
689
+ if ( isset($_POST['action']) && $_POST['action'] === 'qem_validate_form' ) {
690
+ $errors[] = 'registration_forbidden';
691
+ $result = array(
692
+ 'success' => 'false',
693
+ 'errors' => $errors,
694
+ 'title' => $ct_result->comment
695
+ );
696
+ print json_encode($result);
697
+ die();
698
+ }
699
+
700
+ // Quick Contact Form
701
+ if ( isset($_POST['action']) && $_POST['action'] === 'qcf_validate_form' ) {
702
+ $result = array(
703
+ 'blurb' => "<h1>" . $ct_result->comment . "</h1>",
704
+ 'display' => "Oops, got a few problems here",
705
+ 'errors' => array(
706
+ 0 => array(
707
+ 'error' => 'error',
708
+ 'name' => 'name'
709
+ ),
710
+ ),
711
+ 'success' => 'false',
712
+ );
713
+ print json_encode($result);
714
+ die();
715
+ }
716
+
717
+ // Usernoise Contact Form
718
+ if ( isset($_POST['title'], $_POST['email'], $_POST['type'], $_POST['ct_checkjs']) ) {
719
+ return array($ct_result->comment);
720
+ }
721
+
722
+ // amoForms
723
+ if ( isset($_POST['action']) && $_POST['action'] === 'amoforms_submit' ) {
724
+ $result = array(
725
+ 'result' => true,
726
+ 'type' => "html",
727
+ 'value' => "<h1 style='font-size: 25px; color: red;'>" . $ct_result->comment . "</h1>",
728
+ 'fast' => false
729
+ );
730
+ print json_encode($result);
731
+ die();
732
+ }
733
+
734
+ // MailChimp for Wordpress Premium
735
+ if ( ! empty($_POST['_mc4wp_form_id']) ) {
736
+ return 'ct_mc4wp_response';
737
+ }
738
+
739
+ // QAEngine Theme answers
740
+ if ( ! empty($message_obj) && isset($message_obj['post_type'], $message_obj['post_content']) ) {
741
+ throw new Exception($ct_result->comment);
742
+ }
743
+
744
+ //ES Add subscriber
745
+ if ( isset($_POST['action']) && $_POST['action'] === 'es_add_subscriber' ) {
746
+ $result = array(
747
+ 'error' => 'unexpected-error',
748
+ );
749
+ print json_encode($result);
750
+ die();
751
+ }
752
+
753
+ //Convertplug. Strpos because action value dynamically changes and depends on mailing service
754
+ if ( isset($_POST['action']) && strpos($_POST['action'], '_add_subscriber') !== false ) {
755
+ $result = array(
756
+ 'action' => "message",
757
+ 'detailed_msg' => "",
758
+ 'email_status' => false,
759
+ 'message' => "<h1 style='font-size: 25px; color: red;'>" . $ct_result->comment . "</h1>",
760
+ 'status' => "error",
761
+ 'url' => "none"
762
+ );
763
+ print json_encode($result);
764
+ die();
765
+ }
766
+
767
+ // Ultimate Form Builder
768
+ if ( isset($_POST['action']) && $_POST['action'] === 'ufbl_front_form_action' ) {
769
+ $result = array(
770
+ 'error_keys' => array(),
771
+ 'error_flag' => 1,
772
+ 'response_message' => $ct_result->comment
773
+ );
774
+ print json_encode($result);
775
+ die();
776
+ }
777
+
778
+ // Smart Forms
779
+ if ( isset($_POST['action']) && $_POST['action'] === 'rednao_smart_forms_save_form_values' ) {
780
+ $result = array(
781
+ 'message' => $ct_result->comment,
782
+ 'refreshCaptcha' => 'n',
783
+ 'success' => 'n'
784
+ );
785
+ print json_encode($result);
786
+ die();
787
+ }
788
+
789
+ //cFormsII
790
+ if ( isset($_POST['action']) && $_POST['action'] === 'submitcform' ) {
791
+ header('Content-Type: application/json');
792
+ $result = array(
793
+ 'no' => isset($_POST['cforms_id']) ? $_POST['cforms_id'] : '',
794
+ 'result' => 'failure',
795
+ 'html' => $ct_result->comment,
796
+ 'hide' => false,
797
+ 'redirection' => null
798
+ );
799
+ print json_encode($result);
800
+ die();
801
+ }
802
+
803
+ //Contact Form by Web-Settler
804
+ if ( isset($_POST['smFieldData']) ) {
805
+ $result = array(
806
+ 'signal' => true,
807
+ 'code' => 0,
808
+ 'thanksMsg' => $ct_result->comment,
809
+ 'errors' => array(),
810
+ 'isMsg' => true,
811
+ 'redirectUrl' => null
812
+ );
813
+ print json_encode($result);
814
+ die();
815
+ }
816
+
817
+ //Reviewer
818
+ if ( isset($_POST['action']) && $_POST['action'] == 'rwp_ajax_action_rating' ) {
819
+ $result = array(
820
+ 'success' => false,
821
+ 'data' => array(0 => $ct_result->comment)
822
+ );
823
+ print json_encode($result);
824
+ die();
825
+ }
826
+
827
+ // CouponXXL Theme
828
+ if (
829
+ isset($_POST['_wp_http_referer'], $_POST['register_field'], $_POST['action']) &&
830
+ strpos($_POST['_wp_http_referer'], '/register/account') !== false &&
831
+ $_POST['action'] === 'register'
832
+ ) {
833
+ $result = array(
834
+ 'message' => '<div class="alert alert-error">' . $ct_result->comment . '</div>',
835
+ );
836
+ die(json_encode($result));
837
+ }
838
+
839
+ //ConvertPro
840
+ if ( isset($_POST['action']) && ($_POST['action'] === 'cp_v2_notify_admin' || $_POST['action'] === 'cpro_notify_via_email') ) {
841
+ $result = array(
842
+ 'success' => false,
843
+ 'data' => array('error' => $ct_result->comment, 'style_slug' => 'convertprot-form'),
844
+ );
845
+ print json_encode($result);
846
+ die();
847
+ }
848
+
849
+ //Easy Forms for Mailchimp
850
+ if ( isset($_POST['action']) && $_POST['action'] === 'process_form_submission' ) {
851
+ wp_send_json_error(
852
+ array(
853
+ 'error' => 1,
854
+ 'response' => $ct_result->comment
855
+ )
856
+ );
857
+ }
858
+
859
+ //Optin wheel
860
+ if ( isset($_POST['action']) && ($_POST['action'] === 'wof-lite-email-optin' || $_POST['action'] === 'wof-email-optin') ) {
861
+ wp_send_json_error(__($ct_result->comment, 'wp-optin-wheel'));
862
+ }
863
+
864
+ // Forminator
865
+ if ( isset($_POST['action']) && strpos($_POST['action'], 'forminator_submit') !== false ) {
866
+ wp_send_json_error(
867
+ array(
868
+ 'message' => $ct_result->comment,
869
+ 'success' => false,
870
+ 'errors' => array(),
871
+ 'behav' => 'behaviour-thankyou',
872
+ )
873
+ );
874
+ }
875
+
876
+ // Easy Registration Form
877
+ if ( isset($_POST['action']) && strpos($_POST['action'], 'erf_submit_form') !== false ) {
878
+ wp_send_json_error(array(0 => array('username_error', $ct_result->comment)));
 
 
 
 
 
 
 
 
879
  }
880
 
881
  // Regular block output
882
+ die(
883
+ json_encode(
884
+ array(
885
+ 'apbct' => array(
886
+ 'blocked' => true,
887
+ 'comment' => $ct_result->comment,
888
+ 'stop_script' => Post::hasString('action', 'tve_leads_ajax_')
889
+ ? 1
890
+ : 0
891
+ )
892
+ )
893
+ )
894
+ );
895
+ }
896
+
897
+ // Allow == 1
898
+ //QAEngine Theme answers
899
+ if ( ! empty($message_obj) && isset($message_obj['post_type'], $message_obj['post_content']) ) {
900
+ return $message_obj;
901
+ }
902
+ // Force AJAX check
903
+ if ( Post::get('action') === 'cleantalk_force_ajax_check' ) {
904
+ die(
905
+ json_encode(
906
+ array(
907
+ 'apbct' => array(
908
+ 'blocked' => false,
909
+ 'allow' => true,
910
+ )
911
+ )
912
+ )
913
+ );
914
+ }
915
+
916
+ return null;
917
  }
inc/cleantalk-common.php CHANGED
@@ -5,16 +5,19 @@ use Cleantalk\Antispam\CleantalkRequest;
5
  use Cleantalk\Antispam\CleantalkResponse;
6
  use Cleantalk\ApbctWP\API;
7
  use Cleantalk\ApbctWP\Cron;
 
8
  use Cleantalk\ApbctWP\GetFieldsAny;
9
  use Cleantalk\ApbctWP\Helper;
10
  use Cleantalk\ApbctWP\Variables\Cookie;
 
11
  use Cleantalk\Variables\Server;
12
 
13
- function apbct_array( $array ){
14
- return new \Cleantalk\Common\Arr( $array );
 
15
  }
16
 
17
- $ct_checkjs_frm = 'ct_checkjs_frm';
18
  $ct_checkjs_register_form = 'ct_checkjs_register_form';
19
 
20
  $apbct_cookie_request_id_label = 'request_id';
@@ -24,8 +27,8 @@ $ct_checkjs_cf7 = 'ct_checkjs_cf7';
24
  $ct_cf7_comment = '';
25
 
26
  $ct_checkjs_jpcf = 'ct_checkjs_jpcf';
27
- $ct_jpcf_patched = false;
28
- $ct_jpcf_fields = array('name', 'email');
29
 
30
  // Comment already proccessed
31
  $ct_comment_done = false;
@@ -39,10 +42,10 @@ $ct_registration_error_comment = false;
39
  // Default value for JS test
40
  $ct_checkjs_def = 0;
41
 
42
- // COOKIE label to store request id for last approved
43
  $ct_approved_request_id_label = 'ct_approved_request_id';
44
 
45
- // Last request id approved for publication
46
  $ct_approved_request_id = null;
47
 
48
  // Trial notice show time in minutes
@@ -54,7 +57,7 @@ $renew_notice_showtime = 10;
54
  // COOKIE label for WP Landing Page proccessing result
55
  $ct_wplp_result_label = 'ct_wplp_result';
56
 
57
- // Flag indicates active JetPack comments
58
  $ct_jp_comments = false;
59
 
60
  // WP admin email notice interval in seconds
@@ -65,18 +68,20 @@ $ct_admin_notoice_period = 21600;
65
  $ct_negative_comment = null;
66
 
67
 
68
- add_action( 'wp_login', 'apbct_add_admin_ip_to_swf_whitelist', 10, 2 );
69
 
70
  /**
71
  * Public action 'plugins_loaded' - Loads locale, see http://codex.wordpress.org/Function_Reference/load_plugin_textdomain
72
  */
73
- function apbct_plugin_loaded() {
74
- $dir=plugin_basename( dirname( __FILE__ ) ) . '/../i18n';
 
75
  load_plugin_textdomain('cleantalk-spam-protect', false, $dir);
76
  }
77
 
78
  /**
79
  * Inner function - Request's wrapper for anything
 
80
  * @param array Array of parameters:
81
  * 'message' - string
82
  * 'example' - string
@@ -85,231 +90,249 @@ function apbct_plugin_loaded() {
85
  * 'sender_nickname' - string
86
  * 'sender_info' - array
87
  * 'post_info' - string
 
88
  * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
89
  */
90
- function apbct_base_call($params = array(), $reg_flag = false){
91
-
92
- global $cleantalk_executed;
93
-
94
- /* Exclusions */
95
- if( $cleantalk_executed ){
96
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
97
- return array( 'ct_result' => new CleantalkResponse() );
 
98
  }
99
-
100
  // URL, IP, Role exclusions
101
- if( apbct_exclusions_check() ){
102
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
103
- return array( 'ct_result' => new CleantalkResponse() );
 
104
  }
105
-
106
  // Reversed url exclusions. Pass everything except one.
107
- if( apbct_exclusions_check__url__reversed() ){
108
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
109
- return array( 'ct_result' => new CleantalkResponse() );
 
110
  }
111
 
112
  global $apbct;
113
 
114
  // Fields exclusions
115
- if( ! empty( $params['message'] ) && is_array( $params['message'] ) ){
116
- $params['message'] = apbct_array( $params['message'] )
117
- ->get_keys( $apbct->settings['exclusions__fields'], $apbct->settings['exclusions__fields__use_regexp'] )
118
  ->delete();
119
  }
120
  /* End of Exclusions */
121
-
122
- $cleantalk_executed = true;
123
-
124
  /* Request ID rotation */
125
- $tmp = array();
126
- if ($apbct->plugin_request_ids && !empty($apbct->plugin_request_ids)) {
127
- $plugin_request_id__lifetime = 2;
128
- foreach( $apbct->plugin_request_ids as $request_id => $request_time ){
129
- if( time() - $request_time < $plugin_request_id__lifetime )
130
- $tmp[ $request_id ] = $request_time;
131
- }
 
132
  }
133
- $apbct->plugin_request_ids = $tmp;
134
- $apbct->save('plugin_request_ids');
135
-
136
  // Skip duplicate requests
137
- if( key_exists( $apbct->plugin_request_id, $apbct->plugin_request_ids ) &&
 
138
  current_filter() !== 'woocommerce_registration_errors' && // Prevent skip checking woocommerce registration during checkout
139
- current_filter() !== 'um_submit_form_register' ) // Prevent skip checking UltimateMember register
140
- {
141
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
142
- return array( 'ct_result' => new CleantalkResponse() );
 
143
  }
144
-
145
- $apbct->plugin_request_ids = array_merge($apbct->plugin_request_ids, array($apbct->plugin_request_id => time() ) );
146
- $apbct->save('plugin_request_ids');
147
  /* End of Request ID rotation */
148
-
149
-
150
- $sender_info = !empty($params['sender_info'])
151
- ? \Cleantalk\ApbctWP\Helper::array_merge__save_numeric_keys__recursive(apbct_get_sender_info(), (array)$params['sender_info'])
152
- : apbct_get_sender_info();
153
-
154
- $default_params = array(
155
-
156
- // IPs
157
- 'sender_ip' => defined('CT_TEST_IP')
 
 
 
158
  ? CT_TEST_IP
159
- : \Cleantalk\ApbctWP\Helper::ip__get('remote_addr', false),
160
- 'x_forwarded_for' => \Cleantalk\ApbctWP\Helper::ip__get('x_forwarded_for', false),
161
- 'x_real_ip' => \Cleantalk\ApbctWP\Helper::ip__get('x_real_ip', false),
162
-
163
- // Misc
164
- 'auth_key' => $apbct->api_key,
165
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true) ? 1 : apbct_js_test('ct_checkjs', $_POST),
166
-
167
- 'agent' => APBCT_AGENT,
168
- 'sender_info' => $sender_info,
169
- 'submit_time' => apbct_get_submit_time()
170
- );
171
-
172
- /**
173
- * Add honeypot_field if exists in params
174
- */
175
- if(isset($params['honeypot_field'])) {
176
- $default_params['honeypot_field'] = $params['honeypot_field'];
177
- }
178
-
179
- // Send $_SERVER if couldn't find IP
180
- if(empty($default_params['sender_ip']))
181
- $default_params['sender_info']['server_info'] = $_SERVER;
182
-
183
- $ct_request = new CleantalkRequest(
184
- \Cleantalk\ApbctWP\Helper::array_merge__save_numeric_keys__recursive($default_params, $params)
185
- );
186
-
187
- $ct = new Cleantalk();
188
-
189
- $ct->use_bultin_api = $apbct->settings['wp__use_builtin_http_api'] ? true : false;
190
- $ct->ssl_on = $apbct->settings['data__ssl_on'];
191
- $ct->ssl_path = APBCT_CASERT_PATH;
192
-
193
- // Options store url without shceme because of DB error with ''://'
194
- $config = ct_get_server();
195
- $ct->server_url = APBCT_MODERATE_URL;
196
- $ct->work_url = preg_match('/https:\/\/.+/', $config['ct_work_url']) ? $config['ct_work_url'] : null;
197
- $ct->server_ttl = $config['ct_server_ttl'];
198
- $ct->server_changed = $config['ct_server_changed'];
199
-
200
- $start = microtime(true);
201
- $ct_result = $reg_flag
202
- ? @$ct->isAllowUser($ct_request)
203
- : @$ct->isAllowMessage($ct_request);
204
- $exec_time = microtime(true) - $start;
205
-
206
- // Statistics
207
- // Average request time
208
- apbct_statistics__rotate($exec_time);
209
- // Last request
210
- $apbct->stats['last_request']['time'] = time();
211
- $apbct->stats['last_request']['server'] = $ct->work_url;
212
- $apbct->save('stats');
213
-
214
- // Connection reports
215
- if ($ct_result->errno === 0 && empty($ct_result->errstr))
 
216
  $apbct->data['connection_reports']['success']++;
217
- else
218
- {
219
  $apbct->data['connection_reports']['negative']++;
220
  $apbct->data['connection_reports']['negative_report'][] = array(
221
- 'date' => date("Y-m-d H:i:s"),
222
- 'page_url' => apbct_get_server_variable( 'REQUEST_URI' ),
223
- 'lib_report' => $ct_result->errstr,
224
- 'work_url' => $ct->work_url,
225
- );
226
-
227
- if(count($apbct->data['connection_reports']['negative_report']) > 20)
228
- $apbct->data['connection_reports']['negative_report'] = array_slice($apbct->data['connection_reports']['negative_report'], -20, 20);
229
-
 
 
 
 
230
  }
231
 
232
- if ($ct->server_change) {
233
- update_option(
234
- 'cleantalk_server',
235
- array(
236
- 'ct_work_url' => $ct->work_url,
237
- 'ct_server_ttl' => $ct->server_ttl,
238
- 'ct_server_changed' => time(),
239
- )
240
- );
241
- $cron = new Cron();
242
- $cron->updateTask( 'rotate_moderate', 'apbct_rotate_moderate', 86400 ); // Rotate moderate server
243
  }
244
 
245
  $ct_result = ct_change_plugin_resonse($ct_result, $ct_request->js_on);
246
 
247
- // Restart submit form counter for failed requests
248
- if ($ct_result->allow == 0){
249
- apbct_cookie(); // Setting page timer and cookies
250
- ct_add_event('no');
251
- }else{
252
- ct_add_event('yes');
253
  }
254
 
255
  //Strip tags from comment
256
- $ct_result->comment = strip_tags($ct_result->comment, '<p><a><br>');
257
 
258
- // Set cookies if it's not.
259
- if(empty($apbct->flags__cookies_setuped))
260
- apbct_cookie();
 
261
 
262
  return array('ct' => $ct, 'ct_result' => $ct_result);
263
-
264
  }
265
 
266
- function apbct_rotate_moderate() {
267
- $ct = new Cleantalk();
268
- $ct->rotateModerate();
269
- if ($ct->server_change) {
270
- update_option(
271
- 'cleantalk_server',
272
- array(
273
- 'ct_work_url' => $ct->work_url,
274
- 'ct_server_ttl' => $ct->server_ttl,
275
- 'ct_server_changed' => time(),
276
- )
277
- );
278
- }
 
279
  }
280
 
281
- function apbct_exclusions_check($func = null){
282
-
283
- global $apbct;
284
-
285
- // Common exclusions
286
- if(
287
- apbct_exclusions_check__ip() ||
288
- apbct_exclusions_check__url() ||
289
- apbct_is_user_role_in( $apbct->settings['exclusions__roles'] )
290
- )
291
- return true;
292
-
293
- // Personal exclusions
294
- switch ($func){
295
- case 'ct_contact_form_validate_postdata':
296
- if(
297
- (defined( 'DOING_AJAX' ) && DOING_AJAX) ||
298
- apbct_array( $_POST )->get_keys( 'members_search_submit' )->result()
299
- )
300
- return true;
301
- break;
302
- case 'ct_contact_form_validate':
303
- if(
304
- apbct_array( $_POST )->get_keys( 'members_search_submit' )->result()
305
- )
306
- return true;
307
- break;
308
- default:
309
- return false;
310
- }
311
-
312
- return false;
 
 
 
313
  }
314
 
315
  /**
@@ -317,9 +340,10 @@ function apbct_exclusions_check($func = null){
317
  *
318
  * @return bool
319
  */
320
- function apbct_exclusions_check__url__reversed(){
321
- return defined( 'APBCT_URL_EXCLUSIONS__REVERSED' ) &&
322
- ! Server::has_string( 'REQUEST_URI', APBCT_URL_EXCLUSIONS__REVERSED );
 
323
  }
324
 
325
  /**
@@ -327,174 +351,195 @@ function apbct_exclusions_check__url__reversed(){
327
  *
328
  * @return bool
329
  */
330
- function apbct_exclusions_check__url() {
331
-
332
- global $apbct;
333
-
334
- if ( ! empty( $apbct->settings['exclusions__urls'] ) ) {
335
-
336
- if( strpos( $apbct->settings['exclusions__urls'], "\r\n" ) !== false ) {
337
- $exclusions = explode( "\r\n", $apbct->settings['exclusions__urls'] );
338
- } elseif( strpos( $apbct->settings['exclusions__urls'], "\n" ) !== false ) {
339
- $exclusions = explode( "\n", $apbct->settings['exclusions__urls'] );
340
  } else {
341
- $exclusions = explode( ',', $apbct->settings['exclusions__urls'] );
342
  }
343
 
344
- // Fix for AJAX and WP REST API forms
345
- $haystack = ( apbct_get_server_variable( 'REQUEST_URI' ) === '/wp-admin/admin-ajax.php' || stripos( apbct_get_server_variable( 'REQUEST_URI' ), '/wp-json/' ) === 0 )
346
- && apbct_get_server_variable( 'HTTP_REFERER' )
347
- ? str_ireplace( array( 'http://', 'https://', strval(Server::get('HTTP_HOST'))), '', apbct_get_server_variable( 'HTTP_REFERER' ) )
348
- : apbct_get_server_variable( 'REQUEST_URI' );
349
-
350
- foreach ( $exclusions as $exclusion ) {
351
- if (
352
- ($apbct->settings['exclusions__urls__use_regexp'] && preg_match( '@' . $exclusion . '@', $haystack ) === 1) ||
353
- stripos( $haystack, $exclusion ) !== false
354
- ){
355
- return true;
356
- }
357
- }
358
- return false;
359
- }
 
 
 
 
 
 
 
 
 
 
 
 
360
 
361
- return false;
362
  }
 
363
  /**
364
- * @deprecated 5.128 Using IP white-lists instead
365
  * @deprecated since 18.09.2019
366
  * Checks if sender_ip is in exclusion list
367
  *
368
- * @return bool
369
  */
370
- function apbct_exclusions_check__ip(){
371
-
372
- global $cleantalk_ip_exclusions;
373
-
374
- if( apbct_get_server_variable( 'REMOTE_ADDR' ) ){
375
-
376
- if( \Cleantalk\ApbctWP\Helper::ip__is_cleantalks( apbct_get_server_variable( 'REMOTE_ADDR' ) ) ){
377
- return true;
378
- }
379
-
380
- if( ! empty( $cleantalk_ip_exclusions ) && is_array( $cleantalk_ip_exclusions ) ){
381
- foreach ( $cleantalk_ip_exclusions as $exclusion ){
382
- if( stripos( apbct_get_server_variable( 'REMOTE_ADDR' ), $exclusion ) !== false ){
383
- return true;
384
- }
385
- }
386
- }
387
- }
388
-
389
- return false;
390
  }
391
 
392
  /**
393
- * Inner function - Default data array for senders
394
- * @return array
395
  */
396
- function apbct_get_sender_info() {
397
-
398
- // Validate cookie from the backend
399
- $cookie_is_ok = apbct_cookies_test();
400
-
401
- if (count($_POST) > 0) {
402
- foreach ($_POST as $k => $v) {
403
- if (preg_match("/^(ct_check|checkjs).+/", $k)) {
404
- $checkjs_data_post = $v;
405
- }
406
- }
407
- }
408
-
409
- // AMP check
410
- $amp_detected = apbct_get_server_variable( 'HTTP_REFERER' )
411
- ? strpos(apbct_get_server_variable( 'HTTP_REFERER' ), '/amp/') !== false || strpos(apbct_get_server_variable( 'HTTP_REFERER' ), '?amp=1') !== false || strpos(apbct_get_server_variable( 'HTTP_REFERER' ), '&amp=1') !== false
412
- ? 1
413
- : 0
414
- : null;
415
-
416
- // Visible fields processing
417
- $visible_fields = apbct_visible_fields__process( Cookie::get( 'apbct_visible_fields' , array(), 'array' ) );
418
-
419
- global $apbct;
420
-
421
- return array(
422
- 'plugin_request_id' => $apbct->plugin_request_id,
423
- 'wpms' => is_multisite() ? 'yes' : 'no',
424
- 'remote_addr' => \Cleantalk\ApbctWP\Helper::ip__get('remote_addr', false),
425
- 'REFFERRER' => apbct_get_server_variable( 'HTTP_REFERER' ),
426
- 'USER_AGENT' => apbct_get_server_variable( 'HTTP_USER_AGENT' ),
427
- 'page_url' => apbct_get_server_variable( 'SERVER_NAME' ) . apbct_get_server_variable( 'REQUEST_URI' ),
 
 
 
 
 
428
  'cms_lang' => substr(get_locale(), 0, 2),
429
  'ct_options' => json_encode($apbct->settings),
430
  'fields_number' => sizeof($_POST),
431
  'direct_post' => $cookie_is_ok === null && apbct_is_post() ? 1 : 0,
432
- // Raw data to validated JavaScript test in the cloud
433
- 'checkjs_data_cookies' => Cookie::get( 'ct_checkjs' ) ?: null,
434
- 'checkjs_data_post' => !empty($checkjs_data_post) ? $checkjs_data_post : null,
435
- // PHP cookies
436
  'cookies_enabled' => $cookie_is_ok,
437
  'data__set_cookies' => $apbct->settings['data__set_cookies'],
438
- 'REFFERRER_PREVIOUS' => Cookie::get( 'apbct_prev_referer' ) && $cookie_is_ok ? Cookie::get( 'apbct_prev_referer' ) : null,
439
- 'site_landing_ts' => Cookie::get( 'apbct_site_landing_ts' ) && $cookie_is_ok ? Cookie::get( 'apbct_site_landing_ts' ) : null,
440
- 'page_hits' => Cookie::get( 'apbct_page_hits' ) ?: null,
441
- // JS cookies
442
- 'js_info' => Cookie::get( 'ct_user_info' ),
443
- 'mouse_cursor_positions' => Cookie::get( 'ct_pointer_data' ),
444
- 'js_timezone' => Cookie::get( 'ct_timezone' ) ?: null,
445
- 'key_press_timestamp' => Cookie::get( 'ct_fkp_timestamp' ) ?: null,
446
- 'page_set_timestamp' => Cookie::get( 'ct_ps_timestamp' ) ?: null,
447
- 'form_visible_inputs' => !empty($visible_fields['visible_fields_count']) ? $visible_fields['visible_fields_count'] : null,
448
- 'apbct_visible_fields' => !empty($visible_fields['visible_fields']) ? $visible_fields['visible_fields'] : null,
449
- 'form_invisible_inputs' => !empty($visible_fields['invisible_fields_count']) ? $visible_fields['invisible_fields_count'] : null,
450
- 'apbct_invisible_fields' => !empty($visible_fields['invisible_fields']) ? $visible_fields['invisible_fields'] : null,
451
- // Misc
452
- 'site_referer' => Cookie::get( 'apbct_site_referer' ) ?: null,
453
- 'source_url' => Cookie::get( 'apbct_urls' ) ? json_encode( Cookie::get( 'apbct_urls' ) ) : null,
454
- 'pixel_url' => Cookie::get('apbct_pixel_url'),
455
- 'pixel_setting' => $apbct->settings['data__pixel'],
456
- // Debug stuff
457
- 'amp_detected' => $amp_detected,
458
- 'hook' => current_filter() ? current_filter() : 'no_hook',
459
- 'headers_sent' => !empty($apbct->headers_sent) ? $apbct->headers_sent : false,
460
- 'headers_sent__hook' => !empty($apbct->headers_sent__hook) ? $apbct->headers_sent__hook : 'no_hook',
461
- 'headers_sent__where' => !empty($apbct->headers_sent__where) ? $apbct->headers_sent__where : false,
462
- 'request_type' => apbct_get_server_variable('REQUEST_METHOD') ? apbct_get_server_variable('REQUEST_METHOD') : 'UNKNOWN',
463
- 'email_check' => Cookie::get( 'ct_checked_emails' ) ? json_encode(Cookie::get( 'ct_checked_emails' )) : null,
464
- 'screen_info' => Cookie::get( 'ct_screen_info' ) ? json_encode(Cookie::get( 'ct_screen_info' )) : null,
465
- 'has_scrolled' => Cookie::get( 'ct_has_scrolled' ) ? json_encode(Cookie::get( 'ct_has_scrolled' )) : null,
466
- );
 
 
 
 
 
 
 
 
467
  }
468
 
469
  /**
470
  * Process visible fields for specific form to match the fields from request
471
- *
472
  * @param string|array $visible_fields JSON string
473
- *
474
  * @return array
475
  */
476
- function apbct_visible_fields__process( $visible_fields ) {
477
-
478
- $visible_fields = is_array( $visible_fields )
479
- ? json_encode( $visible_fields )
480
  : $visible_fields;
481
-
482
  // Do not decode if it's already decoded
483
- $fields_collection = json_decode( $visible_fields, true );
484
-
485
- if( ! empty( $fields_collection ) ) {
486
-
487
- foreach ($fields_collection as $current_fields) {
488
-
489
- if( isset( $current_fields['visible_fields'], $current_fields['visible_fields_count'] ) ) {
490
 
491
- $fields = explode( ' ', $current_fields['visible_fields'] );
 
 
 
492
 
493
  // This fields belong this request
494
  $fields_to_check = apbct_get_fields_to_check();
495
- if( count( array_intersect( array_keys($fields_to_check), $fields ) ) > 0 ) {
496
  // WP Forms visible fields formatting
497
- if(strpos($visible_fields, 'wpforms') !== false){
498
  $current_fields = preg_replace(
499
  array('/\[/', '/\]/'),
500
  '',
@@ -511,13 +556,12 @@ function apbct_visible_fields__process( $visible_fields ) {
511
  }
512
 
513
  return $current_fields;
514
-
515
  }
516
  }
517
  }
518
  }
519
-
520
- return array();
521
  }
522
 
523
  /**
@@ -525,25 +569,28 @@ function apbct_visible_fields__process( $visible_fields ) {
525
  *
526
  * @return array
527
  */
528
- function apbct_get_fields_to_check() {
529
- //Formidable fields
530
- if( isset( $_POST['item_meta'] ) && is_array( $_POST['item_meta'] ) ) {
531
- $fields = array();
532
- foreach ( $_POST['item_meta'] as $key => $item ) {
533
- $fields['item_meta['. $key .']'] = $item;
534
- }
535
- return $fields;
536
- }
537
- // @ToDo we have to implement a logic to find form fields (fields names, fields count) in serialized/nested/encoded items. not only $_POST.
538
- return $_POST;
 
 
 
539
  }
540
 
541
  /*
542
  * Outputs JS key for AJAX-use only. Stops script.
543
  */
544
- function apbct_js_keys__get__ajax(){
545
-
546
- die( json_encode( array( 'js_key' => ct_get_checkjs_value() ) ) );
547
  }
548
 
549
  /**
@@ -553,229 +600,243 @@ function apbct_js_keys__get__ajax(){
553
  *
554
  * @return int|string|null
555
  */
556
- function ct_get_checkjs_value(){
557
-
558
  global $apbct;
559
-
560
  // Use static JS keys
561
- if($apbct->settings['data__use_static_js_key'] == 1){
562
-
563
- $key = hash('sha256', $apbct->api_key.ct_get_admin_email().$apbct->salt);
564
-
565
- // Auto detecting. Detected.
566
- }elseif(
567
- $apbct->settings['data__use_static_js_key'] == - 1 &&
568
- ( apbct_is_cache_plugins_exists() ||
569
- ( apbct_is_post() && $apbct->data['cache_detected'] == 1 )
570
- )
571
- ){
572
- $key = hash('sha256', $apbct->api_key.ct_get_admin_email().$apbct->salt);
573
- if( apbct_is_cache_plugins_exists() )
574
- $apbct->data['cache_detected'] = 1;
575
-
576
- $apbct->saveData();
577
-
578
- // Using dynamic JS keys
579
- }else{
580
-
581
- $keys = $apbct->data['js_keys'];
582
  $keys_checksum = md5(json_encode($keys));
583
-
584
- $key = null;
585
  $latest_key_time = 0;
586
-
587
- foreach ($keys as $k => $t) {
588
 
 
589
  // Removing key if it's to old
590
- if (time() - $t > $apbct->data['js_keys_store_days'] * 86400 * 7) {
591
  unset($keys[$k]);
592
  continue;
593
  }
594
 
595
- if ($t > $latest_key_time) {
596
  $latest_key_time = $t;
597
- $key = $k;
598
  }
599
  }
600
-
601
  // Set new key if the latest key is too old
602
- if (time() - $latest_key_time > $apbct->data['js_key_lifetime']) {
603
- $key = rand();
604
  $keys[$key] = time();
605
  }
606
-
607
  // Save keys if they were changed
608
- if (md5(json_encode($keys)) != $keys_checksum) {
609
  $apbct->data['js_keys'] = $keys;
610
  // $apbct->saveData();
611
  }
612
-
613
- $apbct->data['cache_detected'] = 0;
614
 
615
- $apbct->saveData();
616
 
 
617
  }
618
-
619
- return $key;
620
  }
621
 
622
- function apbct_is_cache_plugins_exists(){
623
- return
624
- defined('WP_ROCKET_VERSION') || // WPRocket
625
- defined('LSCWP_DIR') || // LiteSpeed Cache
626
- defined('WPFC_WP_CONTENT_BASENAME') || // WP Fastest Cache
627
- defined('W3TC') || // W3 Total Cache
628
- defined('WPO_VERSION') || // WP-Optimize Clean, Compress, Cache
629
- defined('AUTOPTIMIZE_PLUGIN_VERSION') || // Autoptimize
630
- defined('WPCACHEHOME') || // WP Super Cache
631
- defined('WPHB_VERSION') || // Hummingbird Speed up, Cache, Optimize Your CSS and JS
632
- defined('CE_FILE') || // Cache Enabler – WordPress Cache
633
- class_exists('\RedisObjectCache') || // Redis Object Cache
634
- defined('SiteGround_Optimizer\VERSION') || // SG Optimizer
635
- class_exists('\WP_Rest_Cache_Plugin\Includes\Plugin'); // WP REST Cache
 
 
 
636
  }
637
 
638
  /**
639
  * Inner function - Current site admin e-mail
640
- * @return string Admin e-mail
641
  */
642
- function ct_get_admin_email() {
643
- return get_option('admin_email');
 
644
  }
645
 
646
  /**
647
  * Inner function - Current Cleantalk working server info
648
- * @return array Array of server data
649
  */
650
- function ct_get_server() {
651
- $ct_server = get_option('cleantalk_server');
652
- if (!is_array($ct_server)){
653
- $ct_server = array(
654
- 'ct_work_url' => NULL,
655
- 'ct_server_ttl' => NULL,
656
- 'ct_server_changed' => NULL
657
- );
658
- }
659
- return $ct_server;
 
 
660
  }
661
 
662
  /**
663
  * Inner function - Stores ang returns cleantalk hash of current comment
664
- * @param string New hash or NULL
665
- * @return string New hash or current hash depending on parameter
 
 
666
  */
667
- function ct_hash($new_hash = '') {
 
668
  /**
669
  * Current hash
670
  */
671
  static $hash;
672
 
673
- if (!empty($new_hash)) {
674
  $hash = $new_hash;
675
  }
 
676
  return $hash;
677
  }
678
 
679
  /**
680
- * Inner function - Write manual moderation results to PHP sessions
681
- * @param string $hash Cleantalk comment hash
682
- * @param string $message comment_content
683
- * @param int $allow flag good comment (1) or bad (0)
684
- * @return string comment_content w\o cleantalk resume
 
 
685
  */
686
- function ct_feedback($hash, $allow) {
687
- global $apbct;
688
-
 
689
  $ct_feedback = $hash . ':' . $allow . ';';
690
- if( ! $apbct->data['feedback_request'] )
691
- $apbct->data['feedback_request'] = $ct_feedback;
692
- else
693
- $apbct->data['feedback_request'] .= $ct_feedback;
694
-
695
- $apbct->saveData();
696
-
697
- return $ct_feedback;
 
698
  }
699
 
700
  /**
701
  * Inner function - Sends the results of moderation
702
  * Scheduled in 3600 seconds!
 
703
  * @param string $feedback_request
 
704
  * @return bool
705
  */
706
- function ct_send_feedback($feedback_request = null) {
707
-
708
- global $apbct;
709
-
710
- if (empty($feedback_request) && isset($apbct->data['feedback_request']) && preg_match("/^[a-z0-9\;\:]+$/", $apbct->data['feedback_request'])){
711
- $feedback_request = $apbct->data['feedback_request'];
712
- $apbct->data['feedback_request'] = '';
713
- $apbct->saveData();
 
 
 
 
714
  }
715
-
716
- if ($feedback_request !== null) {
717
-
718
  $ct_request = new CleantalkRequest(array(
719
- // General
720
- 'auth_key' => $apbct->api_key,
721
- // Additional
722
- 'feedback' => $feedback_request,
723
- ));
724
-
725
  $ct = new Cleantalk();
726
-
727
- // Server URL handling
728
- $config = ct_get_server();
729
- $ct->server_url = APBCT_MODERATE_URL;
730
- $ct->work_url = preg_match('/http:\/\/.+/', $config['ct_work_url']) ? $config['ct_work_url'] : null;
731
- $ct->server_ttl = $config['ct_server_ttl'];
732
- $ct->server_changed = $config['ct_server_changed'];
733
-
734
  $ct_result = $ct->sendFeedback($ct_request);
735
-
736
- if ($ct->server_change) {
737
  update_option(
738
  'cleantalk_server',
739
- array(
740
- 'ct_work_url' => $ct->work_url,
741
- 'ct_server_ttl' => $ct->server_ttl,
742
- 'ct_server_changed' => time(),
743
  )
744
  );
745
- $cron = new Cron();
746
- $cron->updateTask( 'rotate_moderate', 'apbct_rotate_moderate', 86400 ); // Rotate moderate server
 
 
 
747
  }
748
- if ($ct_result) {
749
- return true;
750
- }
751
  }
752
 
753
  return false;
754
  }
755
 
756
  /**
757
- * Delete old spam comments
758
  * Scheduled in 3600 seconds!
759
- * @return null
760
  */
761
- function ct_delete_spam_comments() {
762
-
763
  global $apbct;
764
-
765
- if ($apbct->settings['comments__remove_old_spam'] == 1) {
766
  $last_comments = get_comments(array('status' => 'spam', 'number' => 1000, 'order' => 'ASC'));
767
- foreach ($last_comments as $c) {
768
- $comment_date_gmt = strtotime($c->comment_date_gmt);
769
- if ($comment_date_gmt) {
770
- if (time() - $comment_date_gmt > 86400 * $apbct->data['spam_store_days']) {
771
- // Force deletion old spam comments
772
- wp_delete_comment($c->comment_ID, true);
773
- }
774
- }
775
  }
776
  }
777
 
778
- return null;
779
  }
780
 
781
  /**
@@ -792,20 +853,17 @@ function ct_delete_spam_comments() {
792
  * @return array
793
  * @deprecated Use ct_gfa()
794
  */
795
- function ct_get_fields_any($arr, $email = null, $nickname = array('nick' => '', 'first' => '', 'last' => '')){
796
-
797
- if ( is_array( $nickname ) )
798
- {
799
- $nickname_str = '';
800
- foreach ( $nickname as $value )
801
- {
802
- $nickname_str .= ($value ? $value . " " : "");
803
- }
804
- $nickname = trim( $nickname_str );
805
- }
806
-
807
- return ct_gfa( $arr, $email, $nickname );
808
 
 
809
  }
810
 
811
  /**
@@ -817,33 +875,37 @@ function ct_get_fields_any($arr, $email = null, $nickname = array('nick' => '',
817
  *
818
  * @return array
819
  */
820
- function ct_gfa( $input_array, $email = '', $nickname = '' ) {
821
-
822
- $gfa = new GetFieldsAny( $input_array );
823
- return $gfa->getFields( $email, $nickname );
824
 
 
825
  }
826
 
827
  //New ct_get_fields_any_postdata
828
- function ct_get_fields_any_postdata($arr, $message=array()){
829
- $skip_params = array(
830
- 'ipn_track_id', // PayPal IPN #
831
- 'txn_type', // PayPal transaction type
832
- 'payment_status', // PayPal payment status
 
833
  );
834
-
835
- foreach($arr as $key => $value){
836
- if(!is_array($value)){
837
- if($value == '')
838
- continue;
839
- if (!(in_array($key, $skip_params) || preg_match("/^ct_checkjs/", $key)) && $value!='')
840
- $message[$key] = $value;
841
- }else{
842
- $temp = ct_get_fields_any_postdata($value);
843
- $message = (count($temp) == 0 ? $message : array_merge($message, $temp));
844
- }
845
- }
846
- return $message;
 
 
 
847
  }
848
 
849
  /**
@@ -853,67 +915,67 @@ function ct_get_fields_any_postdata($arr, $message=array()){
853
  *
854
  * @return bool
855
  */
856
- function apbct_is_regexp($regexp){
857
- return @preg_match('/' . $regexp . '/', '') !== false;
 
858
  }
859
 
860
- function cleantalk_debug($key,$value)
861
  {
862
- if(isset($_COOKIE) && isset($_COOKIE['cleantalk_debug']))
863
- {
864
- @header($key.": ".$value);
865
- }
866
  }
867
 
868
  /**
869
- * Function changes CleanTalk result object if an error occurred.
870
- * @return object
871
- */
872
- function ct_change_plugin_resonse($ct_result = null, $checkjs = null) {
873
-
874
- global $apbct;
875
-
876
- if (!$ct_result) {
877
  return $ct_result;
878
  }
879
-
880
- if(@intval($ct_result->errno) != 0)
881
- {
882
- if($checkjs === null || $checkjs != 1)
883
- {
884
- $ct_result->allow = 0;
885
- $ct_result->spam = 1;
886
- $ct_result->comment = sprintf('We\'ve got an issue: %s. Forbidden. Please, enable Javascript. %s.',
887
  $ct_result->comment,
888
  $apbct->plugin_name
889
  );
890
- }
891
- else
892
- {
893
- $ct_result->allow = 1;
894
- $ct_result->comment = 'Allow';
895
- }
896
  }
897
 
898
  return $ct_result;
899
  }
900
 
901
  /**
902
- * Does ey has correct symbols? Checks against regexp ^[a-z\d]{3,15}$
903
- * @param string api_key
904
- * @return bool
905
- */
 
 
906
  function apbct_api_key__is_correct($api_key = null)
907
  {
908
- global $apbct;
909
- $api_key = $api_key !== null ? $api_key : $apbct->api_key;
 
910
  return $api_key && preg_match('/^[a-z\d]{3,15}$/', $api_key) ? true : false;
911
  }
912
 
913
- function apbct_add_async_attribute($tag, $handle) {
914
-
915
- global $apbct;
916
-
917
  $scripts_handles_names = array(
918
  'ct_public',
919
  'ct_public_functions',
@@ -926,87 +988,90 @@ function apbct_add_async_attribute($tag, $handle) {
926
  'ct_collect_details',
927
  'cleantalk-modal',
928
  );
929
-
930
- if (in_array($handle, $scripts_handles_names, true)) {
931
- if( $apbct->settings['misc__async_js'] )
932
- $tag = str_replace( ' src', ' async="async" src', $tag );
933
-
934
- if( class_exists('Cookiebot_WP') )
935
- $tag = str_replace( ' src', ' data-cookieconsent="ignore" src', $tag );
 
 
936
  }
937
-
938
  return $tag;
939
  }
940
 
941
- function apbct_add_admin_ip_to_swf_whitelist( $user ) {
 
 
942
 
943
- global $apbct;
944
-
945
- $user = ! $user instanceof WP_User ? apbct_wp_get_current_user() : $user;
946
- $ip = Helper::ip__get( 'real', true );
947
-
948
- if(
949
  $apbct->settings['sfw__enabled'] && // Break if the SpamFireWall is inactive
950
  Server::isGet() &&
951
  ! apbct_wp_doing_cron() &&
952
- in_array( 'administrator', (array) $user->roles, true ) &&
953
- Cookie::get( 'ct_sfw_ip_wl' ) !== md5( $ip . $apbct->api_key ) &&
954
- \Cleantalk\ApbctWP\Firewall\SFW::update__write_to_db__exclusions( \Cleantalk\Common\DB::getInstance(), APBCT_TBL_FIREWALL_DATA, array( $ip ) ) &&
955
- apbct_private_list_add( $ip ) &&
956
  ! headers_sent()
957
  ) {
958
- \Cleantalk\ApbctWP\Variables\Cookie::set(
959
- 'ct_sfw_ip_wl',
960
- md5( $ip . $apbct->api_key ),
961
- time() + 86400 * 30,
962
- '/',
963
- '',
964
- null,
965
- true,
966
- 'Lax'
967
- );
968
  }
969
-
970
  }
971
 
972
- function apbct_private_list_add( $ip ){
973
-
974
  global $apbct;
975
-
976
- if( Helper::ip__validate( $ip ) ){
977
- $result = API::method__private_list_add__sfw_wl( $apbct->data['user_token'], $ip, $apbct->data['service_id'] );
978
- return empty( $result['error'] );
 
979
  }
980
-
981
  return false;
982
  }
983
 
984
  /**
985
  * Hide website field from standard comments form
986
  */
987
- add_filter( 'comment_form_default_fields', 'apbct__change_type_website_field' , 999, 1);
988
- function apbct__change_type_website_field( $fields ){
989
-
990
- global $apbct;
991
 
992
- if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
993
- if(isset($fields['url']) && $fields['url']) {
994
- $fields['url'] = '<input id="honeypot-field-url" autocomplete="off" name="url" type="text" value="" size="30" maxlength="200" />';
995
- }
996
- }
997
 
998
- return $fields;
999
  }
1000
 
1001
  /**
1002
  * Add styles if website field hidden
1003
  */
1004
- add_action( 'wp_print_styles', 'apbct__styles_if_website_hidden' );
1005
- function apbct__styles_if_website_hidden() {
1006
- global $apbct;
 
1007
 
1008
- if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
1009
- $styles = "
1010
  <style>
1011
  #honeypot-field-url {
1012
  display: none !important;
@@ -1025,6 +1090,41 @@ function apbct__styles_if_website_hidden() {
1025
  }
1026
  </style>";
1027
 
1028
- echo $styles;
1029
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1030
  }
5
  use Cleantalk\Antispam\CleantalkResponse;
6
  use Cleantalk\ApbctWP\API;
7
  use Cleantalk\ApbctWP\Cron;
8
+ use Cleantalk\ApbctWP\Firewall\SFW;
9
  use Cleantalk\ApbctWP\GetFieldsAny;
10
  use Cleantalk\ApbctWP\Helper;
11
  use Cleantalk\ApbctWP\Variables\Cookie;
12
+ use Cleantalk\Common\DB;
13
  use Cleantalk\Variables\Server;
14
 
15
+ function apbct_array($array)
16
+ {
17
+ return new \Cleantalk\Common\Arr($array);
18
  }
19
 
20
+ $ct_checkjs_frm = 'ct_checkjs_frm';
21
  $ct_checkjs_register_form = 'ct_checkjs_register_form';
22
 
23
  $apbct_cookie_request_id_label = 'request_id';
27
  $ct_cf7_comment = '';
28
 
29
  $ct_checkjs_jpcf = 'ct_checkjs_jpcf';
30
+ $ct_jpcf_patched = false;
31
+ $ct_jpcf_fields = array('name', 'email');
32
 
33
  // Comment already proccessed
34
  $ct_comment_done = false;
42
  // Default value for JS test
43
  $ct_checkjs_def = 0;
44
 
45
+ // COOKIE label to store request id for last approved
46
  $ct_approved_request_id_label = 'ct_approved_request_id';
47
 
48
+ // Last request id approved for publication
49
  $ct_approved_request_id = null;
50
 
51
  // Trial notice show time in minutes
57
  // COOKIE label for WP Landing Page proccessing result
58
  $ct_wplp_result_label = 'ct_wplp_result';
59
 
60
+ // Flag indicates active JetPack comments
61
  $ct_jp_comments = false;
62
 
63
  // WP admin email notice interval in seconds
68
  $ct_negative_comment = null;
69
 
70
 
71
+ add_action('wp_login', 'apbct_add_admin_ip_to_swf_whitelist', 10, 2);
72
 
73
  /**
74
  * Public action 'plugins_loaded' - Loads locale, see http://codex.wordpress.org/Function_Reference/load_plugin_textdomain
75
  */
76
+ function apbct_plugin_loaded()
77
+ {
78
+ $dir = plugin_basename(dirname(__FILE__)) . '/../i18n';
79
  load_plugin_textdomain('cleantalk-spam-protect', false, $dir);
80
  }
81
 
82
  /**
83
  * Inner function - Request's wrapper for anything
84
+ *
85
  * @param array Array of parameters:
86
  * 'message' - string
87
  * 'example' - string
90
  * 'sender_nickname' - string
91
  * 'sender_info' - array
92
  * 'post_info' - string
93
+ *
94
  * @return array array('ct'=> Cleantalk, 'ct_result' => CleantalkResponse)
95
  */
96
+ function apbct_base_call($params = array(), $reg_flag = false)
97
+ {
98
+ global $cleantalk_executed;
99
+
100
+ /* Exclusions */
101
+ if ( $cleantalk_executed ) {
102
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
103
+
104
+ return array('ct_result' => new CleantalkResponse());
105
  }
106
+
107
  // URL, IP, Role exclusions
108
+ if ( apbct_exclusions_check() ) {
109
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
110
+
111
+ return array('ct_result' => new CleantalkResponse());
112
  }
113
+
114
  // Reversed url exclusions. Pass everything except one.
115
+ if ( apbct_exclusions_check__url__reversed() ) {
116
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
117
+
118
+ return array('ct_result' => new CleantalkResponse());
119
  }
120
 
121
  global $apbct;
122
 
123
  // Fields exclusions
124
+ if ( ! empty($params['message']) && is_array($params['message']) ) {
125
+ $params['message'] = apbct_array($params['message'])
126
+ ->getKeys($apbct->settings['exclusions__fields'], $apbct->settings['exclusions__fields__use_regexp'])
127
  ->delete();
128
  }
129
  /* End of Exclusions */
130
+
131
+ $cleantalk_executed = true;
132
+
133
  /* Request ID rotation */
134
+ $tmp = array();
135
+ if ( $apbct->plugin_request_ids && ! empty($apbct->plugin_request_ids) ) {
136
+ $plugin_request_id__lifetime = 2;
137
+ foreach ( $apbct->plugin_request_ids as $request_id => $request_time ) {
138
+ if ( time() - $request_time < $plugin_request_id__lifetime ) {
139
+ $tmp[$request_id] = $request_time;
140
+ }
141
+ }
142
  }
143
+ $apbct->plugin_request_ids = $tmp;
144
+ $apbct->save('plugin_request_ids');
145
+
146
  // Skip duplicate requests
147
+ if (
148
+ key_exists($apbct->plugin_request_id, $apbct->plugin_request_ids) &&
149
  current_filter() !== 'woocommerce_registration_errors' && // Prevent skip checking woocommerce registration during checkout
150
+ current_filter() !== 'um_submit_form_register' // Prevent skip checking UltimateMember register
151
+ ) {
152
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
153
+
154
+ return array('ct_result' => new CleantalkResponse());
155
  }
156
+
157
+ $apbct->plugin_request_ids = array_merge($apbct->plugin_request_ids, array($apbct->plugin_request_id => time()));
158
+ $apbct->save('plugin_request_ids');
159
  /* End of Request ID rotation */
160
+
161
+
162
+ $sender_info = ! empty($params['sender_info'])
163
+ ? \Cleantalk\ApbctWP\Helper::arrayMergeSaveNumericKeysRecursive(
164
+ apbct_get_sender_info(),
165
+ (array)$params['sender_info']
166
+ )
167
+ : apbct_get_sender_info();
168
+
169
+ $default_params = array(
170
+
171
+ // IPs
172
+ 'sender_ip' => defined('CT_TEST_IP')
173
  ? CT_TEST_IP
174
+ : \Cleantalk\ApbctWP\Helper::ipGet('remote_addr', false),
175
+ 'x_forwarded_for' => \Cleantalk\ApbctWP\Helper::ipGet('x_forwarded_for', false),
176
+ 'x_real_ip' => \Cleantalk\ApbctWP\Helper::ipGet('x_real_ip', false),
177
+
178
+ // Misc
179
+ 'auth_key' => $apbct->api_key,
180
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true) ? 1 : apbct_js_test('ct_checkjs', $_POST),
181
+
182
+ 'agent' => APBCT_AGENT,
183
+ 'sender_info' => $sender_info,
184
+ 'submit_time' => apbct_get_submit_time()
185
+ );
186
+
187
+ /**
188
+ * Add honeypot_field if exists in params
189
+ */
190
+ if ( isset($params['honeypot_field']) ) {
191
+ $default_params['honeypot_field'] = $params['honeypot_field'];
192
+ }
193
+
194
+ // Send $_SERVER if couldn't find IP
195
+ if ( empty($default_params['sender_ip']) ) {
196
+ $default_params['sender_info']['server_info'] = $_SERVER;
197
+ }
198
+
199
+ $ct_request = new CleantalkRequest(
200
+ \Cleantalk\ApbctWP\Helper::arrayMergeSaveNumericKeysRecursive($default_params, $params)
201
+ );
202
+
203
+ $ct = new Cleantalk();
204
+
205
+ $ct->use_bultin_api = $apbct->settings['wp__use_builtin_http_api'] ? true : false;
206
+ $ct->ssl_on = $apbct->settings['data__ssl_on'];
207
+ $ct->ssl_path = APBCT_CASERT_PATH;
208
+
209
+ // Options store url without shceme because of DB error with ''://'
210
+ $config = ct_get_server();
211
+ $ct->server_url = APBCT_MODERATE_URL;
212
+ $ct->work_url = preg_match('/https:\/\/.+/', $config['ct_work_url']) ? $config['ct_work_url'] : null;
213
+ $ct->server_ttl = $config['ct_server_ttl'];
214
+ $ct->server_changed = $config['ct_server_changed'];
215
+
216
+ $start = microtime(true);
217
+ $ct_result = $reg_flag
218
+ ? @$ct->isAllowUser($ct_request)
219
+ : @$ct->isAllowMessage($ct_request);
220
+ $exec_time = microtime(true) - $start;
221
+
222
+ // Statistics
223
+ // Average request time
224
+ apbct_statistics__rotate($exec_time);
225
+ // Last request
226
+ $apbct->stats['last_request']['time'] = time();
227
+ $apbct->stats['last_request']['server'] = $ct->work_url;
228
+ $apbct->save('stats');
229
+
230
+ // Connection reports
231
+ if ( $ct_result->errno === 0 && empty($ct_result->errstr) ) {
232
  $apbct->data['connection_reports']['success']++;
233
+ } else {
 
234
  $apbct->data['connection_reports']['negative']++;
235
  $apbct->data['connection_reports']['negative_report'][] = array(
236
+ 'date' => date("Y-m-d H:i:s"),
237
+ 'page_url' => apbct_get_server_variable('REQUEST_URI'),
238
+ 'lib_report' => $ct_result->errstr,
239
+ 'work_url' => $ct->work_url,
240
+ );
241
+
242
+ if ( count($apbct->data['connection_reports']['negative_report']) > 20 ) {
243
+ $apbct->data['connection_reports']['negative_report'] = array_slice(
244
+ $apbct->data['connection_reports']['negative_report'],
245
+ -20,
246
+ 20
247
+ );
248
+ }
249
  }
250
 
251
+ if ( $ct->server_change ) {
252
+ update_option(
253
+ 'cleantalk_server',
254
+ array(
255
+ 'ct_work_url' => $ct->work_url,
256
+ 'ct_server_ttl' => $ct->server_ttl,
257
+ 'ct_server_changed' => time(),
258
+ )
259
+ );
260
+ $cron = new Cron();
261
+ $cron->updateTask('rotate_moderate', 'apbct_rotate_moderate', 86400); // Rotate moderate server
262
  }
263
 
264
  $ct_result = ct_change_plugin_resonse($ct_result, $ct_request->js_on);
265
 
266
+ // Restart submit form counter for failed requests
267
+ if ( $ct_result->allow == 0 ) {
268
+ apbct_cookie(); // Setting page timer and cookies
269
+ ct_add_event('no');
270
+ } else {
271
+ ct_add_event('yes');
272
  }
273
 
274
  //Strip tags from comment
275
+ $ct_result->comment = strip_tags($ct_result->comment, '<p><a><br>');
276
 
277
+ // Set cookies if it's not.
278
+ if ( empty($apbct->flags__cookies_setuped) ) {
279
+ apbct_cookie();
280
+ }
281
 
282
  return array('ct' => $ct, 'ct_result' => $ct_result);
 
283
  }
284
 
285
+ function apbct_rotate_moderate()
286
+ {
287
+ $ct = new Cleantalk();
288
+ $ct->rotateModerate();
289
+ if ( $ct->server_change ) {
290
+ update_option(
291
+ 'cleantalk_server',
292
+ array(
293
+ 'ct_work_url' => $ct->work_url,
294
+ 'ct_server_ttl' => $ct->server_ttl,
295
+ 'ct_server_changed' => time(),
296
+ )
297
+ );
298
+ }
299
  }
300
 
301
+ function apbct_exclusions_check($func = null)
302
+ {
303
+ global $apbct;
304
+
305
+ // Common exclusions
306
+ if (
307
+ apbct_exclusions_check__ip() ||
308
+ apbct_exclusions_check__url() ||
309
+ apbct_is_user_role_in($apbct->settings['exclusions__roles'])
310
+ ) {
311
+ return true;
312
+ }
313
+
314
+ // Personal exclusions
315
+ switch ( $func ) {
316
+ case 'ct_contact_form_validate_postdata':
317
+ if (
318
+ (defined('DOING_AJAX') && DOING_AJAX) ||
319
+ apbct_array($_POST)->getKeys('members_search_submit')->result()
320
+ ) {
321
+ return true;
322
+ }
323
+ break;
324
+ case 'ct_contact_form_validate':
325
+ if (
326
+ apbct_array($_POST)->getKeys('members_search_submit')->result()
327
+ ) {
328
+ return true;
329
+ }
330
+ break;
331
+ default:
332
+ return false;
333
+ }
334
+
335
+ return false;
336
  }
337
 
338
  /**
340
  *
341
  * @return bool
342
  */
343
+ function apbct_exclusions_check__url__reversed()
344
+ {
345
+ return defined('APBCT_URL_EXCLUSIONS__REVERSED') &&
346
+ ! Server::hasString('REQUEST_URI', APBCT_URL_EXCLUSIONS__REVERSED);
347
  }
348
 
349
  /**
351
  *
352
  * @return bool
353
  */
354
+ function apbct_exclusions_check__url()
355
+ {
356
+ global $apbct;
357
+
358
+ if ( ! empty($apbct->settings['exclusions__urls']) ) {
359
+ if ( strpos($apbct->settings['exclusions__urls'], "\r\n") !== false ) {
360
+ $exclusions = explode("\r\n", $apbct->settings['exclusions__urls']);
361
+ } elseif ( strpos($apbct->settings['exclusions__urls'], "\n") !== false ) {
362
+ $exclusions = explode("\n", $apbct->settings['exclusions__urls']);
 
363
  } else {
364
+ $exclusions = explode(',', $apbct->settings['exclusions__urls']);
365
  }
366
 
367
+ // Fix for AJAX and WP REST API forms
368
+ $haystack =
369
+ (
370
+ apbct_get_server_variable('REQUEST_URI') === '/wp-admin/admin-ajax.php' ||
371
+ stripos(apbct_get_server_variable('REQUEST_URI'), '/wp-json/') === 0
372
+ ) &&
373
+ apbct_get_server_variable('HTTP_REFERER')
374
+ ? str_ireplace(
375
+ array('http://', 'https://', strval(Server::get('HTTP_HOST'))),
376
+ '',
377
+ apbct_get_server_variable('HTTP_REFERER')
378
+ )
379
+ : apbct_get_server_variable('REQUEST_URI');
380
+
381
+ foreach ( $exclusions as $exclusion ) {
382
+ if (
383
+ (
384
+ $apbct->settings['exclusions__urls__use_regexp'] &&
385
+ preg_match('@' . $exclusion . '@', $haystack) === 1
386
+ ) ||
387
+ stripos($haystack, $exclusion) !== false
388
+ ) {
389
+ return true;
390
+ }
391
+ }
392
+
393
+ return false;
394
+ }
395
 
396
+ return false;
397
  }
398
+
399
  /**
400
+ * @return bool
401
  * @deprecated since 18.09.2019
402
  * Checks if sender_ip is in exclusion list
403
  *
404
+ * @deprecated 5.128 Using IP white-lists instead
405
  */
406
+ function apbct_exclusions_check__ip()
407
+ {
408
+ global $cleantalk_ip_exclusions;
409
+
410
+ if ( apbct_get_server_variable('REMOTE_ADDR') ) {
411
+ if ( \Cleantalk\ApbctWP\Helper::ipIsCleantalks(apbct_get_server_variable('REMOTE_ADDR')) ) {
412
+ return true;
413
+ }
414
+
415
+ if ( ! empty($cleantalk_ip_exclusions) && is_array($cleantalk_ip_exclusions) ) {
416
+ foreach ( $cleantalk_ip_exclusions as $exclusion ) {
417
+ if ( stripos(apbct_get_server_variable('REMOTE_ADDR'), $exclusion) !== false ) {
418
+ return true;
419
+ }
420
+ }
421
+ }
422
+ }
423
+
424
+ return false;
 
425
  }
426
 
427
  /**
428
+ * Inner function - Default data array for senders
429
+ * @return array
430
  */
431
+ function apbct_get_sender_info()
432
+ {
433
+ // Validate cookie from the backend
434
+ $cookie_is_ok = apbct_cookies_test();
435
+
436
+ if ( count($_POST) > 0 ) {
437
+ foreach ( $_POST as $k => $v ) {
438
+ if ( preg_match("/^(ct_check|checkjs).+/", $k) ) {
439
+ $checkjs_data_post = $v;
440
+ }
441
+ }
442
+ }
443
+
444
+ // AMP check
445
+ $amp_detected =
446
+ apbct_get_server_variable('HTTP_REFERER')
447
+ ? (
448
+ strpos(apbct_get_server_variable('HTTP_REFERER'), '/amp/') !== false ||
449
+ strpos(apbct_get_server_variable('HTTP_REFERER'), '?amp=1') !== false ||
450
+ strpos(apbct_get_server_variable('HTTP_REFERER'), '&amp=1') !== false
451
+ ? 1
452
+ : 0
453
+ )
454
+ : null;
455
+
456
+ // Visible fields processing
457
+ $visible_fields = apbct_visible_fields__process(Cookie::get('apbct_visible_fields', array(), 'array'));
458
+
459
+ global $apbct;
460
+
461
+ return array(
462
+ 'plugin_request_id' => $apbct->plugin_request_id,
463
+ 'wpms' => is_multisite() ? 'yes' : 'no',
464
+ 'remote_addr' => \Cleantalk\ApbctWP\Helper::ipGet('remote_addr', false),
465
+ 'REFFERRER' => apbct_get_server_variable('HTTP_REFERER'),
466
+ 'USER_AGENT' => apbct_get_server_variable('HTTP_USER_AGENT'),
467
+ 'page_url' => apbct_get_server_variable('SERVER_NAME') . apbct_get_server_variable('REQUEST_URI'),
468
  'cms_lang' => substr(get_locale(), 0, 2),
469
  'ct_options' => json_encode($apbct->settings),
470
  'fields_number' => sizeof($_POST),
471
  'direct_post' => $cookie_is_ok === null && apbct_is_post() ? 1 : 0,
472
+ // Raw data to validated JavaScript test in the cloud
473
+ 'checkjs_data_cookies' => Cookie::get('ct_checkjs') ?: null,
474
+ 'checkjs_data_post' => ! empty($checkjs_data_post) ? $checkjs_data_post : null,
475
+ // PHP cookies
476
  'cookies_enabled' => $cookie_is_ok,
477
  'data__set_cookies' => $apbct->settings['data__set_cookies'],
478
+ 'REFFERRER_PREVIOUS' => Cookie::get('apbct_prev_referer') && $cookie_is_ok ? Cookie::get(
479
+ 'apbct_prev_referer'
480
+ ) : null,
481
+ 'site_landing_ts' => Cookie::get('apbct_site_landing_ts') && $cookie_is_ok ? Cookie::get(
482
+ 'apbct_site_landing_ts'
483
+ ) : null,
484
+ 'page_hits' => Cookie::get('apbct_page_hits') ?: null,
485
+ // JS cookies
486
+ 'js_info' => Cookie::get('ct_user_info'),
487
+ 'mouse_cursor_positions' => Cookie::get('ct_pointer_data'),
488
+ 'js_timezone' => Cookie::get('ct_timezone') ?: null,
489
+ 'key_press_timestamp' => Cookie::get('ct_fkp_timestamp') ?: null,
490
+ 'page_set_timestamp' => Cookie::get('ct_ps_timestamp') ?: null,
491
+ 'form_visible_inputs' => ! empty($visible_fields['visible_fields_count']) ? $visible_fields['visible_fields_count'] : null,
492
+ 'apbct_visible_fields' => ! empty($visible_fields['visible_fields']) ? $visible_fields['visible_fields'] : null,
493
+ 'form_invisible_inputs' => ! empty($visible_fields['invisible_fields_count']) ? $visible_fields['invisible_fields_count'] : null,
494
+ 'apbct_invisible_fields' => ! empty($visible_fields['invisible_fields']) ? $visible_fields['invisible_fields'] : null,
495
+ // Misc
496
+ 'site_referer' => Cookie::get('apbct_site_referer') ?: null,
497
+ 'source_url' => Cookie::get('apbct_urls') ? json_encode(Cookie::get('apbct_urls')) : null,
498
+ 'pixel_url' => Cookie::get('apbct_pixel_url'),
499
+ 'pixel_setting' => $apbct->settings['data__pixel'],
500
+ // Debug stuff
501
+ 'amp_detected' => $amp_detected,
502
+ 'hook' => current_filter() ? current_filter() : 'no_hook',
503
+ 'headers_sent' => ! empty($apbct->headers_sent) ? $apbct->headers_sent : false,
504
+ 'headers_sent__hook' => ! empty($apbct->headers_sent__hook) ? $apbct->headers_sent__hook : 'no_hook',
505
+ 'headers_sent__where' => ! empty($apbct->headers_sent__where) ? $apbct->headers_sent__where : false,
506
+ 'request_type' => apbct_get_server_variable('REQUEST_METHOD') ? apbct_get_server_variable(
507
+ 'REQUEST_METHOD'
508
+ ) : 'UNKNOWN',
509
+ 'email_check' => Cookie::get('ct_checked_emails') ? json_encode(
510
+ Cookie::get('ct_checked_emails')
511
+ ) : null,
512
+ 'screen_info' => Cookie::get('ct_screen_info') ? json_encode(Cookie::get('ct_screen_info')) : null,
513
+ 'has_scrolled' => Cookie::get('ct_has_scrolled') ? json_encode(Cookie::get('ct_has_scrolled')) : null,
514
+ );
515
  }
516
 
517
  /**
518
  * Process visible fields for specific form to match the fields from request
519
+ *
520
  * @param string|array $visible_fields JSON string
521
+ *
522
  * @return array
523
  */
524
+ function apbct_visible_fields__process($visible_fields)
525
+ {
526
+ $visible_fields = is_array($visible_fields)
527
+ ? json_encode($visible_fields)
528
  : $visible_fields;
529
+
530
  // Do not decode if it's already decoded
531
+ $fields_collection = json_decode($visible_fields, true);
 
 
 
 
 
 
532
 
533
+ if ( ! empty($fields_collection) ) {
534
+ foreach ( $fields_collection as $current_fields ) {
535
+ if ( isset($current_fields['visible_fields'], $current_fields['visible_fields_count']) ) {
536
+ $fields = explode(' ', $current_fields['visible_fields']);
537
 
538
  // This fields belong this request
539
  $fields_to_check = apbct_get_fields_to_check();
540
+ if ( count(array_intersect(array_keys($fields_to_check), $fields)) > 0 ) {
541
  // WP Forms visible fields formatting
542
+ if ( strpos($visible_fields, 'wpforms') !== false ) {
543
  $current_fields = preg_replace(
544
  array('/\[/', '/\]/'),
545
  '',
556
  }
557
 
558
  return $current_fields;
 
559
  }
560
  }
561
  }
562
  }
563
+
564
+ return array();
565
  }
566
 
567
  /**
569
  *
570
  * @return array
571
  */
572
+ function apbct_get_fields_to_check()
573
+ {
574
+ //Formidable fields
575
+ if ( isset($_POST['item_meta']) && is_array($_POST['item_meta']) ) {
576
+ $fields = array();
577
+ foreach ( $_POST['item_meta'] as $key => $item ) {
578
+ $fields['item_meta[' . $key . ']'] = $item;
579
+ }
580
+
581
+ return $fields;
582
+ }
583
+
584
+ // @ToDo we have to implement a logic to find form fields (fields names, fields count) in serialized/nested/encoded items. not only $_POST.
585
+ return $_POST;
586
  }
587
 
588
  /*
589
  * Outputs JS key for AJAX-use only. Stops script.
590
  */
591
+ function apbct_js_keys__get__ajax()
592
+ {
593
+ die(json_encode(array('js_key' => ct_get_checkjs_value())));
594
  }
595
 
596
  /**
600
  *
601
  * @return int|string|null
602
  */
603
+ function ct_get_checkjs_value()
604
+ {
605
  global $apbct;
606
+
607
  // Use static JS keys
608
+ if ( $apbct->settings['data__use_static_js_key'] == 1 ) {
609
+ $key = hash('sha256', $apbct->api_key . ct_get_admin_email() . $apbct->salt);
610
+ // Auto detecting. Detected.
611
+ } elseif (
612
+ $apbct->settings['data__use_static_js_key'] == -1 &&
613
+ (apbct_is_cache_plugins_exists() ||
614
+ (apbct_is_post() && $apbct->data['cache_detected'] == 1)
615
+ )
616
+ ) {
617
+ $key = hash('sha256', $apbct->api_key . ct_get_admin_email() . $apbct->salt);
618
+ if ( apbct_is_cache_plugins_exists() ) {
619
+ $apbct->data['cache_detected'] = 1;
620
+ }
621
+
622
+ $apbct->saveData();
623
+ // Using dynamic JS keys
624
+ } else {
625
+ $keys = $apbct->data['js_keys'];
 
 
 
626
  $keys_checksum = md5(json_encode($keys));
627
+
628
+ $key = null;
629
  $latest_key_time = 0;
 
 
630
 
631
+ foreach ( $keys as $k => $t ) {
632
  // Removing key if it's to old
633
+ if ( time() - $t > $apbct->data['js_keys_store_days'] * 86400 * 7 ) {
634
  unset($keys[$k]);
635
  continue;
636
  }
637
 
638
+ if ( $t > $latest_key_time ) {
639
  $latest_key_time = $t;
640
+ $key = $k;
641
  }
642
  }
643
+
644
  // Set new key if the latest key is too old
645
+ if ( time() - $latest_key_time > $apbct->data['js_key_lifetime'] ) {
646
+ $key = rand();
647
  $keys[$key] = time();
648
  }
649
+
650
  // Save keys if they were changed
651
+ if ( md5(json_encode($keys)) != $keys_checksum ) {
652
  $apbct->data['js_keys'] = $keys;
653
  // $apbct->saveData();
654
  }
 
 
655
 
656
+ $apbct->data['cache_detected'] = 0;
657
 
658
+ $apbct->saveData();
659
  }
660
+
661
+ return $key;
662
  }
663
 
664
+ function apbct_is_cache_plugins_exists()
665
+ {
666
+ return
667
+ defined('WP_ROCKET_VERSION') || // WPRocket
668
+ defined('LSCWP_DIR') || // LiteSpeed Cache
669
+ defined('WPFC_WP_CONTENT_BASENAME') || // WP Fastest Cache
670
+ defined('W3TC') || // W3 Total Cache
671
+ defined('WPO_VERSION') || // WP-Optimize – Clean, Compress, Cache
672
+ defined('AUTOPTIMIZE_PLUGIN_VERSION') || // Autoptimize
673
+ defined('WPCACHEHOME') || // WP Super Cache
674
+ defined(
675
+ 'WPHB_VERSION'
676
+ ) || // Hummingbird – Speed up, Cache, Optimize Your CSS and JS
677
+ defined('CE_FILE') || // Cache Enabler – WordPress Cache
678
+ class_exists('\RedisObjectCache') || // Redis Object Cache
679
+ defined('SiteGround_Optimizer\VERSION') || // SG Optimizer
680
+ class_exists('\WP_Rest_Cache_Plugin\Includes\Plugin'); // WP REST Cache
681
  }
682
 
683
  /**
684
  * Inner function - Current site admin e-mail
685
+ * @return string Admin e-mail
686
  */
687
+ function ct_get_admin_email()
688
+ {
689
+ return get_option('admin_email');
690
  }
691
 
692
  /**
693
  * Inner function - Current Cleantalk working server info
694
+ * @return array Array of server data
695
  */
696
+ function ct_get_server()
697
+ {
698
+ $ct_server = get_option('cleantalk_server');
699
+ if ( ! is_array($ct_server) ) {
700
+ $ct_server = array(
701
+ 'ct_work_url' => null,
702
+ 'ct_server_ttl' => null,
703
+ 'ct_server_changed' => null
704
+ );
705
+ }
706
+
707
+ return $ct_server;
708
  }
709
 
710
  /**
711
  * Inner function - Stores ang returns cleantalk hash of current comment
712
+ *
713
+ * @param string New hash or NULL
714
+ *
715
+ * @return string New hash or current hash depending on parameter
716
  */
717
+ function ct_hash($new_hash = '')
718
+ {
719
  /**
720
  * Current hash
721
  */
722
  static $hash;
723
 
724
+ if ( ! empty($new_hash) ) {
725
  $hash = $new_hash;
726
  }
727
+
728
  return $hash;
729
  }
730
 
731
  /**
732
+ * Inner function - Write manual moderation results to PHP sessions
733
+ *
734
+ * @param string $hash Cleantalk comment hash
735
+ * @param string $message comment_content
736
+ * @param int $allow flag good comment (1) or bad (0)
737
+ *
738
+ * @return string comment_content w\o cleantalk resume
739
  */
740
+ function ct_feedback($hash, $allow)
741
+ {
742
+ global $apbct;
743
+
744
  $ct_feedback = $hash . ':' . $allow . ';';
745
+ if ( ! $apbct->data['feedback_request'] ) {
746
+ $apbct->data['feedback_request'] = $ct_feedback;
747
+ } else {
748
+ $apbct->data['feedback_request'] .= $ct_feedback;
749
+ }
750
+
751
+ $apbct->saveData();
752
+
753
+ return $ct_feedback;
754
  }
755
 
756
  /**
757
  * Inner function - Sends the results of moderation
758
  * Scheduled in 3600 seconds!
759
+ *
760
  * @param string $feedback_request
761
+ *
762
  * @return bool
763
  */
764
+ function ct_send_feedback($feedback_request = null)
765
+ {
766
+ global $apbct;
767
+
768
+ if (
769
+ empty($feedback_request) &&
770
+ isset($apbct->data['feedback_request']) &&
771
+ preg_match("/^[a-z0-9\;\:]+$/", $apbct->data['feedback_request'])
772
+ ) {
773
+ $feedback_request = $apbct->data['feedback_request'];
774
+ $apbct->data['feedback_request'] = '';
775
+ $apbct->saveData();
776
  }
777
+
778
+ if ( $feedback_request !== null ) {
 
779
  $ct_request = new CleantalkRequest(array(
780
+ // General
781
+ 'auth_key' => $apbct->api_key,
782
+ // Additional
783
+ 'feedback' => $feedback_request,
784
+ ));
785
+
786
  $ct = new Cleantalk();
787
+
788
+ // Server URL handling
789
+ $config = ct_get_server();
790
+ $ct->server_url = APBCT_MODERATE_URL;
791
+ $ct->work_url = preg_match('/http:\/\/.+/', $config['ct_work_url']) ? $config['ct_work_url'] : null;
792
+ $ct->server_ttl = $config['ct_server_ttl'];
793
+ $ct->server_changed = $config['ct_server_changed'];
794
+
795
  $ct_result = $ct->sendFeedback($ct_request);
796
+
797
+ if ( $ct->server_change ) {
798
  update_option(
799
  'cleantalk_server',
800
+ array(
801
+ 'ct_work_url' => $ct->work_url,
802
+ 'ct_server_ttl' => $ct->server_ttl,
803
+ 'ct_server_changed' => time(),
804
  )
805
  );
806
+ $cron = new Cron();
807
+ $cron->updateTask('rotate_moderate', 'apbct_rotate_moderate', 86400); // Rotate moderate server
808
+ }
809
+ if ( $ct_result ) {
810
+ return true;
811
  }
 
 
 
812
  }
813
 
814
  return false;
815
  }
816
 
817
  /**
818
+ * Delete old spam comments
819
  * Scheduled in 3600 seconds!
820
+ * @return null
821
  */
822
+ function ct_delete_spam_comments()
823
+ {
824
  global $apbct;
825
+
826
+ if ( $apbct->settings['comments__remove_old_spam'] == 1 ) {
827
  $last_comments = get_comments(array('status' => 'spam', 'number' => 1000, 'order' => 'ASC'));
828
+ foreach ( $last_comments as $c ) {
829
+ $comment_date_gmt = strtotime($c->comment_date_gmt);
830
+ if ( $comment_date_gmt ) {
831
+ if ( time() - $comment_date_gmt > 86400 * $apbct->data['spam_store_days'] ) {
832
+ // Force deletion old spam comments
833
+ wp_delete_comment($c->comment_ID, true);
834
+ }
835
+ }
836
  }
837
  }
838
 
839
+ return null;
840
  }
841
 
842
  /**
853
  * @return array
854
  * @deprecated Use ct_gfa()
855
  */
856
+ function ct_get_fields_any($arr, $email = null, $nickname = array('nick' => '', 'first' => '', 'last' => ''))
857
+ {
858
+ if ( is_array($nickname) ) {
859
+ $nickname_str = '';
860
+ foreach ( $nickname as $value ) {
861
+ $nickname_str .= ($value ? $value . " " : "");
862
+ }
863
+ $nickname = trim($nickname_str);
864
+ }
 
 
 
 
865
 
866
+ return ct_gfa($arr, $email, $nickname);
867
  }
868
 
869
  /**
875
  *
876
  * @return array
877
  */
878
+ function ct_gfa($input_array, $email = '', $nickname = '')
879
+ {
880
+ $gfa = new GetFieldsAny($input_array);
 
881
 
882
+ return $gfa->getFields($email, $nickname);
883
  }
884
 
885
  //New ct_get_fields_any_postdata
886
+ function ct_get_fields_any_postdata($arr, $message = array())
887
+ {
888
+ $skip_params = array(
889
+ 'ipn_track_id', // PayPal IPN #
890
+ 'txn_type', // PayPal transaction type
891
+ 'payment_status', // PayPal payment status
892
  );
893
+
894
+ foreach ( $arr as $key => $value ) {
895
+ if ( ! is_array($value) ) {
896
+ if ( $value == '' ) {
897
+ continue;
898
+ }
899
+ if ( ! (in_array($key, $skip_params) || preg_match("/^ct_checkjs/", $key)) && $value != '' ) {
900
+ $message[$key] = $value;
901
+ }
902
+ } else {
903
+ $temp = ct_get_fields_any_postdata($value);
904
+ $message = (count($temp) == 0 ? $message : array_merge($message, $temp));
905
+ }
906
+ }
907
+
908
+ return $message;
909
  }
910
 
911
  /**
915
  *
916
  * @return bool
917
  */
918
+ function apbct_is_regexp($regexp)
919
+ {
920
+ return @preg_match('/' . $regexp . '/', '') !== false;
921
  }
922
 
923
+ function cleantalk_debug($key, $value)
924
  {
925
+ if ( isset($_COOKIE) && isset($_COOKIE['cleantalk_debug']) ) {
926
+ @header($key . ": " . $value);
927
+ }
 
928
  }
929
 
930
  /**
931
+ * Function changes CleanTalk result object if an error occurred.
932
+ * @return object
933
+ */
934
+ function ct_change_plugin_resonse($ct_result = null, $checkjs = null)
935
+ {
936
+ global $apbct;
937
+
938
+ if ( ! $ct_result ) {
939
  return $ct_result;
940
  }
941
+
942
+ if ( @intval($ct_result->errno) != 0 ) {
943
+ if ( $checkjs === null || $checkjs != 1 ) {
944
+ $ct_result->allow = 0;
945
+ $ct_result->spam = 1;
946
+ $ct_result->comment = sprintf(
947
+ 'We\'ve got an issue: %s. Forbidden. Please, enable Javascript. %s.',
 
948
  $ct_result->comment,
949
  $apbct->plugin_name
950
  );
951
+ } else {
952
+ $ct_result->allow = 1;
953
+ $ct_result->comment = 'Allow';
954
+ }
 
 
955
  }
956
 
957
  return $ct_result;
958
  }
959
 
960
  /**
961
+ * Does ey has correct symbols? Checks against regexp ^[a-z\d]{3,15}$
962
+ *
963
+ * @param string api_key
964
+ *
965
+ * @return bool
966
+ */
967
  function apbct_api_key__is_correct($api_key = null)
968
  {
969
+ global $apbct;
970
+ $api_key = $api_key !== null ? $api_key : $apbct->api_key;
971
+
972
  return $api_key && preg_match('/^[a-z\d]{3,15}$/', $api_key) ? true : false;
973
  }
974
 
975
+ function apbct_add_async_attribute($tag, $handle)
976
+ {
977
+ global $apbct;
978
+
979
  $scripts_handles_names = array(
980
  'ct_public',
981
  'ct_public_functions',
988
  'ct_collect_details',
989
  'cleantalk-modal',
990
  );
991
+
992
+ if ( in_array($handle, $scripts_handles_names, true) ) {
993
+ if ( $apbct->settings['misc__async_js'] ) {
994
+ $tag = str_replace(' src', ' async="async" src', $tag);
995
+ }
996
+
997
+ if ( class_exists('Cookiebot_WP') ) {
998
+ $tag = str_replace(' src', ' data-cookieconsent="ignore" src', $tag);
999
+ }
1000
  }
1001
+
1002
  return $tag;
1003
  }
1004
 
1005
+ function apbct_add_admin_ip_to_swf_whitelist($user)
1006
+ {
1007
+ global $apbct;
1008
 
1009
+ $user = ! $user instanceof WP_User ? apbct_wp_get_current_user() : $user;
1010
+ $ip = Helper::ipGet('real', true);
1011
+
1012
+ if (
 
 
1013
  $apbct->settings['sfw__enabled'] && // Break if the SpamFireWall is inactive
1014
  Server::isGet() &&
1015
  ! apbct_wp_doing_cron() &&
1016
+ in_array('administrator', (array)$user->roles, true) &&
1017
+ Cookie::get('ct_sfw_ip_wl') !== md5($ip . $apbct->api_key) &&
1018
+ SFW::updateWriteToDbExclusions(DB::getInstance(), APBCT_TBL_FIREWALL_DATA, array($ip)) &&
1019
+ apbct_private_list_add($ip) &&
1020
  ! headers_sent()
1021
  ) {
1022
+ \Cleantalk\ApbctWP\Variables\Cookie::set(
1023
+ 'ct_sfw_ip_wl',
1024
+ md5($ip . $apbct->api_key),
1025
+ time() + 86400 * 30,
1026
+ '/',
1027
+ '',
1028
+ null,
1029
+ true,
1030
+ 'Lax'
1031
+ );
1032
  }
 
1033
  }
1034
 
1035
+ function apbct_private_list_add($ip)
1036
+ {
1037
  global $apbct;
1038
+
1039
+ if ( Helper::ipValidate($ip) ) {
1040
+ $result = API::methodPrivateListAddSfwWl($apbct->data['user_token'], $ip, $apbct->data['service_id']);
1041
+
1042
+ return empty($result['error']);
1043
  }
1044
+
1045
  return false;
1046
  }
1047
 
1048
  /**
1049
  * Hide website field from standard comments form
1050
  */
1051
+ add_filter('comment_form_default_fields', 'apbct__change_type_website_field', 999, 1);
1052
+ function apbct__change_type_website_field($fields)
1053
+ {
1054
+ global $apbct;
1055
 
1056
+ if ( isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field'] ) {
1057
+ if ( isset($fields['url']) && $fields['url'] ) {
1058
+ $fields['url'] = '<input id="honeypot-field-url" autocomplete="off" name="url" type="text" value="" size="30" maxlength="200" />';
1059
+ }
1060
+ }
1061
 
1062
+ return $fields;
1063
  }
1064
 
1065
  /**
1066
  * Add styles if website field hidden
1067
  */
1068
+ add_action('wp_print_styles', 'apbct__styles_if_website_hidden');
1069
+ function apbct__styles_if_website_hidden()
1070
+ {
1071
+ global $apbct;
1072
 
1073
+ if ( $apbct->settings['comments__hide_website_field'] ) {
1074
+ $styles = "
1075
  <style>
1076
  #honeypot-field-url {
1077
  display: none !important;
1090
  }
1091
  </style>";
1092
 
1093
+ echo $styles;
1094
+ }
1095
+
1096
+ if ( $apbct->settings['forms__wc_honeypot'] ) {
1097
+ $styles = "
1098
+ <style>
1099
+ .apbct_wc_honeypot {
1100
+ display: none !important;
1101
+ }
1102
+ </style>";
1103
+
1104
+ echo $styles;
1105
+ }
1106
+ }
1107
+
1108
+ /**
1109
+ * Woocommerce honeypot
1110
+ */
1111
+ add_filter('woocommerce_checkout_fields', 'apbct__wc_add_honeypot_field');
1112
+ function apbct__wc_add_honeypot_field($fields)
1113
+ {
1114
+ global $apbct;
1115
+
1116
+ if ( $apbct->settings['forms__wc_honeypot'] ) {
1117
+ $fields['billing']['apbct_wc_honeypot'] = array(
1118
+ 'id' => 'apbct_wc_honeypot',
1119
+ 'type' => 'text',
1120
+ 'label' => '',
1121
+ 'placeholder' => '',
1122
+ 'required' => false,
1123
+ 'class' => array('form-row-wide', 'apbct_wc_honeypot'),
1124
+ 'clear' => true,
1125
+ 'autocomplete' => 'off'
1126
+ );
1127
+ }
1128
+
1129
+ return $fields;
1130
  }
inc/cleantalk-find-spam.php CHANGED
@@ -1,55 +1,89 @@
1
  <?php
2
 
3
  // Adding menu items for USERS and COMMENTS spam checking pages
4
- add_action( 'admin_menu', 'ct_add_find_spam_pages' );
5
- function ct_add_find_spam_pages(){
6
-
7
  // Check users pages
8
- $ct_check_users = add_users_page( __( "Check for spam", 'cleantalk-spam-protect'), __( "Find spam users", 'cleantalk-spam-protect'), 'activate_plugins', 'ct_check_users', array( '\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage' ) );
9
- $ct_check_users_logs = add_users_page( __( "Scan logs", 'cleantalk-spam-protect'), '', 'activate_plugins', 'ct_check_users_logs', array( '\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage' ) );
10
- $ct_bad_users = add_users_page( __( "Non-checkable users", 'cleantalk-spam-protect'), '', 'activate_plugins', 'ct_check_users_bad', array( '\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  // Check comments pages
13
- $ct_check_spam = add_comments_page( __( "Check for spam", 'cleantalk-spam-protect'), __( "Find spam comments", 'cleantalk-spam-protect'), 'activate_plugins', 'ct_check_spam', array( '\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage' ) );
14
- $ct_check_spam_logs = add_comments_page( __( "Scan logs", 'cleantalk-spam-protect'), '', 'activate_plugins', 'ct_check_spam_logs', array( '\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage' ) );
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  // Remove some pages from main menu
17
- remove_submenu_page( 'users.php', 'ct_check_users_logs' );
18
- remove_submenu_page( 'users.php', 'ct_check_users_bad' );
19
- remove_submenu_page( 'edit-comments.php', 'ct_check_spam_logs' );
20
 
21
  // Set screen option for every pages
22
- add_action( "load-$ct_check_users", array( '\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption' ) );
23
- add_action( "load-$ct_check_users_logs", array( '\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption' ) );
24
- add_action( "load-$ct_check_spam", array( '\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption' ) );
25
- add_action( "load-$ct_check_spam_logs", array( '\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption' ) );
26
- add_action( "load-$ct_bad_users", array( '\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption' ) );
27
-
28
  }
29
 
30
  // Set AJAX actions
31
- add_action( 'wp_ajax_ajax_clear_users', array( '\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ct_ajax_clear_users' ) );
32
- add_action( 'wp_ajax_ajax_check_users', array( '\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ct_ajax_check_users' ) );
33
- add_action( 'wp_ajax_ajax_info_users', array( '\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ct_ajax_info' ) );
34
- add_action( 'wp_ajax_ajax_ct_get_csv_file', array( '\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ct_get_csv_file' ) );
35
- add_action( 'wp_ajax_ajax_delete_all_users', array( '\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ct_ajax_delete_all_users' ) );
36
-
37
- add_action( 'wp_ajax_ajax_clear_comments', array( '\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ct_ajax_clear_comments' ) );
38
- add_action( 'wp_ajax_ajax_check_comments', array( '\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ct_ajax_check_comments' ) );
39
- add_action( 'wp_ajax_ajax_info_comments', array( '\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ct_ajax_info' ) );
40
- add_action( 'wp_ajax_ajax_trash_all', array( '\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ct_ajax_trash_all' ) );
41
- add_action( 'wp_ajax_ajax_spam_all', array( '\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ct_ajax_spam_all' ) );
 
 
 
 
 
 
42
 
43
  // Debug
44
- add_action( 'wp_ajax_ajax_insert_users', array( '\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ct_ajax_insert_users' ) );
45
 
46
  // Hook for saving "per_page" option
47
- add_action( 'wp_loaded', 'ct_save_screen_option' );
48
- function ct_save_screen_option() {
49
-
50
  // Saving screen option for the pagination (per page option)
51
- add_filter( 'set-screen-option', function( $status, $option, $value ){
52
- return ( $option === 'spam_per_page' ) ? (int) $value : $status;
53
- }, 10, 3 );
54
-
55
- }
1
  <?php
2
 
3
  // Adding menu items for USERS and COMMENTS spam checking pages
4
+ add_action('admin_menu', 'ct_add_find_spam_pages');
5
+ function ct_add_find_spam_pages()
6
+ {
7
  // Check users pages
8
+ $ct_check_users = add_users_page(
9
+ __("Check for spam", 'cleantalk-spam-protect'),
10
+ __("Find spam users", 'cleantalk-spam-protect'),
11
+ 'activate_plugins',
12
+ 'ct_check_users',
13
+ array('\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage')
14
+ );
15
+ $ct_check_users_logs = add_users_page(
16
+ __("Scan logs", 'cleantalk-spam-protect'),
17
+ '',
18
+ 'activate_plugins',
19
+ 'ct_check_users_logs',
20
+ array('\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage')
21
+ );
22
+ $ct_bad_users = add_users_page(
23
+ __("Non-checkable users", 'cleantalk-spam-protect'),
24
+ '',
25
+ 'activate_plugins',
26
+ 'ct_check_users_bad',
27
+ array('\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage')
28
+ );
29
 
30
  // Check comments pages
31
+ $ct_check_spam = add_comments_page(
32
+ __("Check for spam", 'cleantalk-spam-protect'),
33
+ __("Find spam comments", 'cleantalk-spam-protect'),
34
+ 'activate_plugins',
35
+ 'ct_check_spam',
36
+ array('\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage')
37
+ );
38
+ $ct_check_spam_logs = add_comments_page(
39
+ __("Scan logs", 'cleantalk-spam-protect'),
40
+ '',
41
+ 'activate_plugins',
42
+ 'ct_check_spam_logs',
43
+ array('\Cleantalk\ApbctWP\FindSpam\Page', 'showFindSpamPage')
44
+ );
45
 
46
  // Remove some pages from main menu
47
+ remove_submenu_page('users.php', 'ct_check_users_logs');
48
+ remove_submenu_page('users.php', 'ct_check_users_bad');
49
+ remove_submenu_page('edit-comments.php', 'ct_check_spam_logs');
50
 
51
  // Set screen option for every pages
52
+ add_action("load-$ct_check_users", array('\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption'));
53
+ add_action("load-$ct_check_users_logs", array('\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption'));
54
+ add_action("load-$ct_check_spam", array('\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption'));
55
+ add_action("load-$ct_check_spam_logs", array('\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption'));
56
+ add_action("load-$ct_bad_users", array('\Cleantalk\ApbctWP\FindSpam\Page', 'setScreenOption'));
 
57
  }
58
 
59
  // Set AJAX actions
60
+ add_action('wp_ajax_ajax_clear_users', array('\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ctAjaxClearUsers'));
61
+ add_action('wp_ajax_ajax_check_users', array('\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ctAjaxCheckUsers'));
62
+ add_action('wp_ajax_ajax_info_users', array('\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ctAjaxInfo'));
63
+ add_action('wp_ajax_ajax_ct_get_csv_file', array('\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ctGetCsvFile'));
64
+ add_action('wp_ajax_ajax_delete_all_users', array('\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ctAjaxDeleteAllUsers'));
65
+
66
+ add_action('wp_ajax_ajax_clear_comments', array(
67
+ '\Cleantalk\ApbctWP\FindSpam\CommentsChecker',
68
+ 'ctAjaxClearComments'
69
+ ));
70
+ add_action('wp_ajax_ajax_check_comments', array(
71
+ '\Cleantalk\ApbctWP\FindSpam\CommentsChecker',
72
+ 'ctAjaxCheckComments'
73
+ ));
74
+ add_action('wp_ajax_ajax_info_comments', array('\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ctAjaxInfo'));
75
+ add_action('wp_ajax_ajax_trash_all', array('\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ctAjaxTrashAll'));
76
+ add_action('wp_ajax_ajax_spam_all', array('\Cleantalk\ApbctWP\FindSpam\CommentsChecker', 'ctAjaxSpamAll'));
77
 
78
  // Debug
79
+ add_action('wp_ajax_ajax_insert_users', array('\Cleantalk\ApbctWP\FindSpam\UsersChecker', 'ctAjaxInsertUsers'));
80
 
81
  // Hook for saving "per_page" option
82
+ add_action('wp_loaded', 'ct_save_screen_option');
83
+ function ct_save_screen_option()
84
+ {
85
  // Saving screen option for the pagination (per page option)
86
+ add_filter('set-screen-option', function ($status, $option, $value) {
87
+ return ($option === 'spam_per_page') ? (int)$value : $status;
88
+ }, 10, 3);
89
+ }
 
inc/cleantalk-pluggable.php CHANGED
@@ -9,43 +9,42 @@ use Cleantalk\Variables\Server;
9
  *
10
  * @return WP_User|null
11
  */
12
- function apbct_wp_get_current_user(){
13
-
14
- global $apbct, $current_user;
15
-
16
- $user = null;
17
-
18
- if(!(defined('XMLRPC_REQUEST') && XMLRPC_REQUEST)){
19
-
20
- if(!empty($apbct->user)){
21
- $user_id = is_object($current_user) && isset($current_user->ID) && !($current_user instanceof WP_User)
22
- ? $current_user->ID
23
- : null;
24
- }else{
25
- $user_id = defined('LOGGED_IN_COOKIE') && !empty($_COOKIE[LOGGED_IN_COOKIE])
26
- ? apbct_wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in')
27
- : null;
28
- }
29
-
30
- if($user_id){
31
- $user = new WP_User($user_id);
32
- }
33
-
34
- }
35
-
36
- return $user ? $user : $current_user;
37
  }
38
 
39
- function apbct_wp_set_current_user($user = null){
40
-
41
- global $apbct;
42
-
43
- if( $user instanceof WP_User ){
44
- $apbct->user = $user;
45
- return true;
46
- }
47
-
48
- return false;
 
49
  }
50
 
51
  /**
@@ -61,49 +60,54 @@ function apbct_wp_set_current_user($user = null){
61
  * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
62
  *
63
  * @return false|int False if invalid cookie, User ID if valid.
64
- * @global int $login_grace_period
65
  *
66
  */
67
- function apbct_wp_validate_auth_cookie( $cookie = '', $scheme = '' ) {
68
-
69
- $cookie_elements = apbct_wp_parse_auth_cookie($cookie, $scheme);
70
-
71
- $scheme = $cookie_elements['scheme'];
72
- $username = $cookie_elements['username'];
73
- $hmac = $cookie_elements['hmac'];
74
- $token = $cookie_elements['token'];
75
- $expiration = $cookie_elements['expiration'];
76
-
77
- // Allow a grace period for POST and Ajax requests
78
- $expired = apbct_is_ajax() || apbct_is_post()
79
- ? $expiration + HOUR_IN_SECONDS
80
- : $cookie_elements['expiration'];
81
-
82
- // Quick check to see if an honest cookie has expired
83
- if($expired >= time()){
84
- $user = apbct_wp_get_user_by('login', $username);
85
- if($user){
86
- $pass_frag = substr($user->user_pass, 8, 4);
87
- $key = apbct_wp_hash($username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme);
88
- // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
89
- $algo = function_exists('hash') ? 'sha256' : 'sha1';
90
- $hash = hash_hmac($algo, $username . '|' . $expiration . '|' . $token, $key);
91
- if(hash_equals($hash, $hmac)){
92
- $sessions = get_user_meta($user->ID, 'session_tokens', true);
93
- $sessions = is_array($sessions) ? current($sessions) : $sessions;
94
- if(is_array($sessions)){
95
- if(is_int($sessions['expiration']) && $sessions['expiration'] > time()){
96
- return $user->ID;
97
- }else
98
- return false;
99
- }else
100
- return false;
101
- }else
102
- return false;
103
- }else
104
- return false;
105
- }else
106
- return false;
 
 
 
 
 
107
  }
108
 
109
  /**
@@ -115,65 +119,66 @@ function apbct_wp_validate_auth_cookie( $cookie = '', $scheme = '' ) {
115
  *
116
  * @return string
117
  */
118
- function apbct_get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
119
-
120
- global $wp_rewrite;
121
 
122
- if ( empty( $path ) ) {
123
  $path = '/';
124
  }
125
-
126
- $path = '/' . ltrim( $path, '/' );
127
-
128
- if ( is_multisite() && ( get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) ) {
129
  if ( $wp_rewrite->using_index_permalinks() ) {
130
- $url = get_home_url( $blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix(), $scheme );
131
  } else {
132
- $url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
133
  }
134
-
135
  $url .= $path;
136
  } else {
137
- $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
138
  // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php.
139
  // To work around this, we manually add index.php to the URL, avoiding the redirect.
140
- if ( 'index.php' !== substr( $url, 9 ) ) {
141
  $url .= 'index.php';
142
  }
143
-
144
- $url = add_query_arg( 'rest_route', $path, $url );
145
  }
146
-
147
- if ( is_ssl() && isset( $_SERVER['SERVER_NAME'] ) ) {
148
  // If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.
149
- if ( parse_url( get_home_url( $blog_id ), PHP_URL_HOST ) === $_SERVER['SERVER_NAME'] ) {
150
- $url = set_url_scheme( $url, 'https' );
151
  }
152
  }
153
-
154
  if ( is_admin() && force_ssl_admin() ) {
155
  /*
156
  * In this situation the home URL may be http:, and `is_ssl()` may be false,
157
  * but the admin is served over https: (one way or another), so REST API usage
158
  * will be blocked by browsers unless it is also served over HTTPS.
159
  */
160
- $url = set_url_scheme( $url, 'https' );
161
  }
162
-
163
  /**
164
  * Filters the REST URL.
165
  *
166
  * Use this filter to adjust the url returned by the get_rest_url() function.
167
  *
168
- * @since 4.4.0
169
- *
170
- * @param string $url REST URL.
171
- * @param string $path REST route.
172
  * @param int|null $blog_id Blog ID.
173
- * @param string $scheme Sanitization scheme.
 
174
  * @psalm-suppress TooManyArguments
 
 
175
  */
176
- return apply_filters( 'rest_url', $url, $path, $blog_id, $scheme );
177
  }
178
 
179
  /**
@@ -184,48 +189,50 @@ function apbct_get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
184
  *
185
  * @return bool|WP_User
186
  */
187
- function apbct_wp_get_user_by($field, $value){
188
-
189
- $userdata = WP_User::get_data_by($field, $value);
190
-
191
- if(!$userdata)
192
- return false;
193
-
194
- $user = new WP_User;
195
- $user->init($userdata);
196
-
197
- return $user;
 
198
  }
199
 
200
  /**
201
  * Get hash of given string.
202
  *
203
- * @param string $data Plain text to hash
204
  * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce)
 
205
  * @return string Hash of $data
206
  */
207
- function apbct_wp_hash( $data, $scheme = 'auth' ) {
208
-
209
- $values = array(
210
- 'key' => '',
211
- 'salt' => '',
212
- );
213
-
214
- foreach(array('key', 'salt') as $type){
215
- $const = strtoupper( "{$scheme}_{$type}");
216
- if ( defined($const) && constant($const)){
217
- $values[$type] = constant($const);
218
- }elseif(!$values[$type]){
219
- $values[$type] = get_site_option( "{$scheme}_{$type}");
220
- if (!$values[$type]){
221
- $values[$type] = '';
222
- }
223
- }
224
- }
225
-
226
- $salt = $values['key'] . $values['salt'];
227
-
228
- return hash_hmac('md5', $data, $salt);
229
  }
230
 
231
  /**
@@ -239,14 +246,14 @@ function apbct_wp_hash( $data, $scheme = 'auth' ) {
239
  */
240
  function apbct_wp_parse_auth_cookie($cookie = '', $scheme = '')
241
  {
242
- $cookie_elements = explode('|', $cookie);
243
- if(count($cookie_elements) !== 4){
244
- return false;
245
- }
246
-
247
- list($username, $expiration, $token, $hmac) = $cookie_elements;
248
-
249
- return compact('username', 'expiration', 'token', 'hmac', 'scheme');
250
  }
251
 
252
  /**
@@ -256,8 +263,9 @@ function apbct_wp_parse_auth_cookie($cookie = '', $scheme = '')
256
  *
257
  * @return bool
258
  */
259
- function apbct_is_plugin_active( $plugin ) {
260
- return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || apbct_is_plugin_active_for_network( $plugin );
 
261
  }
262
 
263
  /**
@@ -267,8 +275,9 @@ function apbct_is_plugin_active( $plugin ) {
267
  *
268
  * @return bool
269
  */
270
- function apbct_is_theme_active ( $theme_name) {
271
- return get_option( 'template' ) == $theme_name ? true : false;
 
272
  }
273
 
274
  /**
@@ -278,16 +287,17 @@ function apbct_is_theme_active ( $theme_name) {
278
  *
279
  * @return bool
280
  */
281
- function apbct_is_plugin_active_for_network( $plugin ){
282
-
283
- if ( ! APBCT_WPMS )
284
- return false;
285
-
286
- $plugins = get_site_option( 'active_sitewide_plugins' );
287
-
288
- return isset( $plugins[ $plugin ] )
289
- ? true
290
- : false;
 
291
  }
292
 
293
  /**
@@ -295,14 +305,16 @@ function apbct_is_plugin_active_for_network( $plugin ){
295
  *
296
  * @return boolean
297
  */
298
- function apbct_is_ajax() {
299
-
300
- return
301
- (defined( 'DOING_AJAX' ) && DOING_AJAX) || // by standart WP functions
302
- (apbct_get_server_variable( 'HTTP_X_REQUESTED_WITH' ) && strtolower(apbct_get_server_variable( 'HTTP_X_REQUESTED_WITH' )) == 'xmlhttprequest') || // by Request type
303
- !empty($_POST['quform_ajax']) || // special. QForms
304
- !empty($_POST['iphorm_ajax']); // special. IPHorm
305
-
 
 
306
  }
307
 
308
  /**
@@ -310,8 +322,9 @@ function apbct_is_ajax() {
310
  *
311
  * @return boolean
312
  */
313
- function apbct_is_rest() {
314
- return defined( 'REST_REQUEST' ) && REST_REQUEST;
 
315
  }
316
 
317
  /**
@@ -319,8 +332,9 @@ function apbct_is_rest() {
319
  *
320
  * @return boolean
321
  */
322
- function apbct_is_cli() {
323
- return PHP_SAPI === "cli";
 
324
  }
325
 
326
  /**
@@ -328,50 +342,60 @@ function apbct_is_cli() {
328
  *
329
  * @return bool
330
  */
331
- function apbct_is_user_logged_in(){
332
- $siteurl = get_site_option( 'siteurl' );
333
- $cookiehash = $siteurl ? md5( $siteurl ) : '';
334
- return count($_COOKIE) && isset($_COOKIE['wordpress_logged_in_'.$cookiehash]);
 
 
335
  }
336
 
337
  /*
338
  * GETTING SERVER VARIABLES BY VARIOUS WAYS
339
  */
340
- function apbct_get_server_variable( $server_variable_name ){
341
-
342
- $var_name = strtoupper( $server_variable_name );
343
-
344
- if( function_exists( 'filter_input' ) )
345
- $value = filter_input( INPUT_SERVER, $var_name );
346
-
347
- if( empty( $value ) )
348
- $value = isset( $_SERVER[ $var_name ] ) ? $_SERVER[ $var_name ] : '';
349
-
350
- // Convert to upper case for REQUEST_METHOD
351
- if( in_array( $server_variable_name, array( 'REQUEST_METHOD' ) ) )
352
- $value = strtoupper( $value );
353
-
354
- // Convert HTML chars for HTTP_USER_AGENT, HTTP_USER_AGENT, SERVER_NAME
355
- if( in_array( $server_variable_name, array( 'HTTP_USER_AGENT', 'HTTP_USER_AGENT', 'SERVER_NAME' ) ) )
356
- $value = htmlspecialchars( $value );
357
-
358
- return $value;
 
 
 
 
359
  }
360
 
361
- function apbct_is_post(){
 
362
  return apbct_get_server_variable('REQUEST_METHOD') === 'POST';
363
  }
364
 
365
- function apbct_is_get(){
 
366
  return apbct_get_server_variable('REQUEST_METHOD') === 'GET';
367
  }
368
 
369
- function apbct_is_in_referer( $str ){
370
- return stripos( apbct_get_server_variable('HTTP_REFERER'), $str ) !== false;
 
371
  }
372
 
373
- function apbct_is_in_uri( $str ){
374
- return stripos( apbct_get_server_variable('REQUEST_URI'), $str ) !== false;
 
375
  }
376
 
377
  /*
@@ -380,14 +404,13 @@ function apbct_is_in_uri( $str ){
380
  *
381
  * @return bool
382
  */
383
- function apbct_wp_doing_cron() {
384
-
385
- if( function_exists( 'wp_doing_cron' ) ) {
386
  return wp_doing_cron();
387
  } else {
388
- return ( defined( 'DOING_CRON' ) && DOING_CRON );
389
  }
390
-
391
  }
392
 
393
  /**
@@ -399,18 +422,18 @@ function apbct_wp_doing_cron() {
399
  * @param $comment
400
  * @param $user_ip
401
  * @param $user_agent
 
402
  * @return bool
403
  */
404
- function apbct_wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent ) {
405
-
406
  global $wp_version;
407
 
408
- if( version_compare($wp_version, '5.5.0', '>=') ) {
409
- return wp_check_comment_disallowed_list( $author, $email, $url, $comment, $user_ip, $user_agent );
410
  } else {
411
- return wp_blacklist_check( $author, $email, $url, $comment, $user_ip, $user_agent );
412
  }
413
-
414
  }
415
 
416
  /**
@@ -419,11 +442,12 @@ function apbct_wp_blacklist_check($author, $email, $url, $comment, $user_ip, $us
419
  *
420
  * @return bool
421
  */
422
- function apbct_is_customize_preview() {
423
-
424
  // Maybe not enough to check the Customizer preview
425
  $uri = parse_url(Server::get('REQUEST_URI'));
426
- return $uri && isset( $uri['query'] ) && strpos( $uri['query'], 'customize_changeset_uuid' ) !== false;
 
427
  }
428
 
429
 
@@ -434,275 +458,256 @@ function apbct_is_customize_preview() {
434
  *
435
  * @return bool|string false or request name for logging
436
  */
437
- function apbct_is_skip_request( $ajax = false ) {
438
-
439
  /* !!! Have to use more than one factor to detect the request - is_plugin active() && $_POST['action'] !!! */
440
  //@ToDo Implement direct integration checking - if have the direct integration will be returned false
441
 
442
- if ($ajax) {
443
  /*****************************************/
444
  /* Here is ajax requests skipping */
445
  /*****************************************/
446
 
447
  // Paid Memberships Pro - Login Form
448
- if(
449
- apbct_is_plugin_active( 'paid-memberships-pro/paid-memberships-pro.php' ) &&
450
- Post::get( 'rm_slug' ) === 'rm_login_form' &&
451
- Post::get( 'rm_form_sub_id' )
452
- ){
453
  return 'paid_memberships_pro__login_form';
454
  }
455
-
456
  // Thrive Ultimatum
457
- if(
458
- apbct_is_plugin_active( 'thrive-ultimatum/thrive-ultimatum.php' ) &&
459
- Post::get( 'action' ) === 'tve_dash_front_ajax'
460
- ){
461
  return 'thrive-ultimatum__links_from_email';
462
  }
463
-
464
  // wpDiscuz - Online Users Addon for wpDiscuz
465
- if(
466
- apbct_is_plugin_active( 'wpdiscuz-online-users/wpdiscuz-ou.php' ) &&
467
- Post::get( 'action' ) === 'wouPushNotification'
468
- ){
469
  return 'wpdiscuz_online_users__push_notification';
470
  }
471
-
472
  // Bookly Plugin admin actions skip
473
- if( apbct_is_plugin_active( 'bookly-responsive-appointment-booking-tool/main.php' ) &&
474
- isset( $_POST['action'] ) &&
475
- strpos( $_POST['action'], 'bookly' ) !== false &&
476
- is_admin() )
477
- {
478
  return 'bookly_pro_update_staff_advanced';
479
  }
480
  // Youzier login form skip
481
- if( apbct_is_plugin_active( 'youzer/youzer.php' ) &&
482
- isset( $_POST['action'] ) &&
483
- $_POST['action'] === 'yz_ajax_login' )
484
- {
485
  return 'youzier_login_form';
486
  }
487
  // Youzify login form skip
488
- if( apbct_is_plugin_active( 'youzify/youzify.php' ) &&
489
- isset( $_POST['action'] ) &&
490
- $_POST['action'] === 'youzify_ajax_login' )
491
- {
492
- return 'youzify_login_form';
493
  }
494
  // InJob theme lost password skip
495
- if( apbct_is_plugin_active( 'iwjob/iwjob.php' ) &&
496
- isset( $_POST['action'] ) &&
497
- $_POST['action'] === 'iwj_lostpass' )
498
- {
499
  return 'injob_theme_plugin';
500
  }
501
  // Divi builder skip
502
- if ( apbct_is_theme_active( 'Divi' ) &&
503
- isset( $_POST['action'] ) &&
504
- ( $_POST['action'] === 'save_epanel' || $_POST['action'] === 'et_fb_ajax_save' ) )
505
- {
506
- return 'divi_builder_skip';
507
  }
508
  // Email Before Download plugin https://wordpress.org/plugins/email-before-download/ action skip
509
- if ( apbct_is_plugin_active( 'email-before-download/email-before-download.php' ) &&
510
- isset( $_POST['action'] ) &&
511
- $_POST['action'] === 'ebd_inline_links' )
512
- {
513
- return 'ebd_inline_links';
514
  }
515
  // WP Discuz skip service requests. The plugin have the direct integration
516
- if ( apbct_is_plugin_active( 'wpdiscuz/class.WpdiscuzCore.php' ) &&
517
- isset( $_POST['action'] ) &&
518
- strpos( $_POST['action'], 'wpd' ) !== false )
519
- {
520
- return 'ebd_inline_links';
521
  }
522
  // Exception for plugin https://ru.wordpress.org/plugins/easy-login-woocommerce/ login form
523
- if(
524
- apbct_is_plugin_active( 'easy-login-woocommerce/xoo-el-main.php' ) &&
525
- Post::get( '_xoo_el_form' ) === 'login'
526
- ){
527
  return 'xoo_login';
528
  }
529
  // Emails & Newsletters with Jackmail: skip all admin-side actions
530
- if(
531
- apbct_is_plugin_active( 'jackmail-newsletters/jackmail-newsletters.php' ) &&
532
- is_admin() &&
533
- strpos( Server::get('HTTP_REFERER'), 'jackmail_' ) !== false
534
- ){
535
- return 'jackmail_admin_actions';
536
  }
537
  // Newspaper theme login form
538
- if ( apbct_is_theme_active( 'Newspaper' ) &&
539
- isset( $_POST['action'] ) &&
540
- ( $_POST['action'] == 'td_mod_login' || $_POST['action'] == 'td_mod_remember_pass' ) )
541
- {
542
- return 'Newspaper_theme_login_form';
543
  }
544
  // Save abandoned cart checking skip
545
- if ( apbct_is_plugin_active( 'woo-save-abandoned-carts/cartbounty-abandoned-carts.php' ) &&
546
- Post::get( 'action' ) === 'cartbounty_save' )
547
- {
548
- return 'cartbounty_save';
549
  }
550
  // SUMODISCOUNT discout request skip
551
- if ( apbct_is_plugin_active( 'sumodiscounts/sumodiscounts.php' ) &&
552
- Post::get( 'action' ) === 'fp_apply_discount_for_first_purchase' )
553
- {
554
- return 'fp_apply_discount_for_first_purchase';
555
  }
556
  // WP eMember login form skip
557
- if ( apbct_is_plugin_active( 'wp-eMember/wp_eMember.php' ) &&
558
- Post::get( 'action' ) === 'emember_ajax_login' )
559
- {
560
- return 'emember_ajax_login';
561
  }
562
  // Avada theme saving settings
563
- if ( apbct_is_theme_active( 'Avada' ) &&
564
- Post::get('action') === 'fusion_options_ajax_save' )
565
- {
566
- return 'Avada_theme_saving_settings';
567
  }
568
  // Formidable skip - this is the durect integration
569
- if ( apbct_is_plugin_active( 'formidable/formidable.php' ) &&
570
- Post::get( 'action' ) === 'frm_entries_update' )
571
- {
572
- return 'formidable_skip';
573
  }
574
  // Artbees Jupiter theme saving settings
575
- if ( Post::get( 'action' ) === 'mk_theme_save' && strpos( get_template(), 'jupiter' ) !== false ){
576
- return 'artbees_jupiter_6_skip';
577
  }
578
  // fix conflict with wiloke theme and unknown plugin, that removes standard authorization cookies
579
- if ( Post::get( 'action' ) === 'wiloke_themeoptions_ajax_save' && apbct_is_theme_active( 'wilcity' ) ){
580
  return 'wiloke_themeoptions_ajax_save_skip';
581
  }
582
  // Essentials addons for elementor - light and pro
583
- if(
584
- ( apbct_is_plugin_active( 'essential-addons-for-elementor-lite/essential_adons_elementor.php' ) ||
585
- apbct_is_plugin_active( 'essential-addons-elementor/essential_adons_elementor.php' ) ) &&
586
- ( Post::get('eael-login-submit') !== '' && Post::get('eael-user-login') !== '' ) )
587
- {
588
- return 'eael_login_skipped';
589
  }
590
  // WPForms check restricted email skipped
591
- if(
592
- ( apbct_is_plugin_active( 'wpforms/wpforms.php' ) ) &&
593
- ( Post::get('action') === 'wpforms_restricted_email' && Post::get('token') !== '' )
594
- )
595
- {
596
- return 'wpforms_check_restricted_email';
597
- }
598
- // FluentForm multistep skip
599
- if ( ( apbct_is_plugin_active( 'fluentformpro/fluentformpro.php' ) || apbct_is_plugin_active( 'fluentform/fluentform.php' ) ) &&
600
- Post::get( 'action' ) === 'active_step' )
601
- {
602
- return 'fluentform_skip';
603
- }
604
-
605
- // W2DC - https://codecanyon.net/item/web-20-directory-plugin-for-wordpress/6463373
606
- if( apbct_is_plugin_active( 'w2dc/w2dc.php' ) &&
607
- isset( $_POST['action'] ) &&
608
- $_POST['action'] === 'vp_w2dc_ajax_vpt_option_save' &&
609
- is_admin() )
610
- {
611
- return 'w2dc_skipped';
612
- }
613
- if ( apbct_is_plugin_active( 'elementor/elementor.php' ) &&
614
- isset( $_POST['actions_save_builder_action'] ) &&
615
- $_POST['actions_save_builder_action'] === 'save_builder' &&
616
- is_admin() ) {
617
  return 'elementor_skip';
618
  }
619
- // Enfold theme saving settings
620
- if ( apbct_is_theme_active( 'Enfold' ) &&
621
- Post::get('action') === 'avia_ajax_save_options_page' )
622
- {
623
- return 'Enfold_theme_saving_settings';
624
- }
625
  //SiteOrigin pagebuilder skip save
626
- if ( apbct_is_plugin_active('siteorigin-panels/siteorigin-panels.php') && Post::get('action') === 'save-widget') {
 
 
 
627
  return 'SiteOrigin pagebuilder';
628
  }
629
  //Skip classfields email check
630
- if ( apbct_is_theme_active('Classfields') && Post::get('action') === 'tmpl_ajax_check_user_email') {
631
- return 'ClassFields checkemail';
 
 
 
632
  }
633
  } else {
634
-
635
  /*****************************************/
636
  /* Here is non-ajax requests skipping */
637
  /*****************************************/
638
- // WC payment APIs
639
- if( apbct_is_plugin_active( 'woocommerce/woocommerce.php' ) &&
640
- apbct_is_in_uri( 'wc-api=2checkout_ipn_convert_plus') )
641
- {
642
- return 'wc-payment-api';
643
- }
644
  // BuddyPress edit profile checking skip
645
- if( apbct_is_plugin_active( 'buddypress/bp-loader.php' ) &&
646
- array_key_exists( 'profile-group-edit-submit', $_POST ) )
647
- {
648
  return 'buddypress_profile_edit';
649
  }
650
  // UltimateMember password reset skip
651
- if( apbct_is_plugin_active( 'ultimate-member/ultimate-member.php' ) &&
652
- isset( $_POST['_um_password_reset'] ) && $_POST['_um_password_reset'] == 1 )
653
- {
654
  return 'ultimatemember_password_reset';
655
  }
656
- // UltimateMember password reset skip
657
- if( apbct_is_plugin_active( 'gravityformspaypal/paypal.php' ) &&
658
- ( apbct_is_in_uri('page=gf_paypal_ipn') || apbct_is_in_uri('callback=gravityformspaypal') ) )
659
- {
660
- return 'gravityformspaypal_processing_skipped';
661
- }
662
- // MyListing theme service requests skip
663
- if ( ( apbct_is_theme_active( 'My Listing Child' ) || apbct_is_theme_active( 'My Listing' ) ) &&
664
- Get::get('mylisting-ajax') === '1' )
665
- {
666
- return 'mylisting_theme_service_requests_skip';
667
- }
668
- // HappyForms skip every requests. HappyForms have the direct integration
669
- if( ( apbct_is_plugin_active( 'happyforms-upgrade/happyforms-upgrade.php' ) ||
670
- apbct_is_plugin_active( 'happyforms/happyforms.php' ) ) &&
671
- ( Post::get('happyforms_message_nonce') !== '' ) )
672
- {
673
- return 'happyform_skipped';
674
- }
675
- // Essentials addons for elementor - light and pro
676
- if(
677
- ( apbct_is_plugin_active( 'essential-addons-for-elementor-lite/essential_adons_elementor.php' ) ||
678
- apbct_is_plugin_active( 'essential-addons-elementor/essential_adons_elementor.php' ) ) &&
679
- ( Post::get('eael-login-submit') !== '' && Post::get('eael-user-login') !== '' ) )
680
- {
681
- return 'eael_login_skipped';
682
- }
683
- // Autonami Marketing Automations service request
684
- if( apbct_is_rest() && Post::get('automation_id') !== '' && Post::get('unique_key') !== '' )
685
- {
686
- return 'autonami-rest';
687
- }
688
- //Skip wforms because of direct integration
689
- if ( apbct_is_plugin_active( 'wpforms/wpforms.php' ) && isset( $_POST['wpforms'] ) ) {
690
- return 'wp_forms';
691
- }
692
  // Formidable skip - this is the durect integration
693
- if ( apbct_is_plugin_active( 'formidable/formidable.php' ) &&
694
- Post::get( 'frm_action' ) === 'update' )
695
- {
696
  return 'formidable_skip';
697
  }
698
- // WC payment APIs
699
- if( apbct_is_plugin_active( 'woocommerce/woocommerce.php' ) &&
700
- apbct_is_in_uri( 'wc-ajax=iwd_opc_update_order_review') )
701
- {
702
- return 'cartflows_save_cart';
703
- }
704
  }
705
 
706
  return false;
707
  }
708
-
9
  *
10
  * @return WP_User|null
11
  */
12
+ function apbct_wp_get_current_user()
13
+ {
14
+ global $apbct, $current_user;
15
+
16
+ $user = null;
17
+
18
+ if ( ! (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) ) {
19
+ if ( ! empty($apbct->user) ) {
20
+ $user_id = is_object($current_user) && isset($current_user->ID) && ! ($current_user instanceof WP_User)
21
+ ? $current_user->ID
22
+ : null;
23
+ } else {
24
+ $user_id = defined('LOGGED_IN_COOKIE') && ! empty($_COOKIE[LOGGED_IN_COOKIE])
25
+ ? apbct_wp_validate_auth_cookie($_COOKIE[LOGGED_IN_COOKIE], 'logged_in')
26
+ : null;
27
+ }
28
+
29
+ if ( $user_id ) {
30
+ $user = new WP_User($user_id);
31
+ }
32
+ }
33
+
34
+ return $user ? $user : $current_user;
 
 
35
  }
36
 
37
+ function apbct_wp_set_current_user($user = null)
38
+ {
39
+ global $apbct;
40
+
41
+ if ( $user instanceof WP_User ) {
42
+ $apbct->user = $user;
43
+
44
+ return true;
45
+ }
46
+
47
+ return false;
48
  }
49
 
50
  /**
60
  * @param string $scheme Optional. The cookie scheme to use: auth, secure_auth, or logged_in
61
  *
62
  * @return false|int False if invalid cookie, User ID if valid.
63
+ * @global int $login_grace_period
64
  *
65
  */
66
+ function apbct_wp_validate_auth_cookie($cookie = '', $scheme = '')
67
+ {
68
+ $cookie_elements = apbct_wp_parse_auth_cookie($cookie, $scheme);
69
+
70
+ $scheme = $cookie_elements['scheme'];
71
+ $username = $cookie_elements['username'];
72
+ $hmac = $cookie_elements['hmac'];
73
+ $token = $cookie_elements['token'];
74
+ $expiration = $cookie_elements['expiration'];
75
+
76
+ // Allow a grace period for POST and Ajax requests
77
+ $expired = apbct_is_ajax() || apbct_is_post()
78
+ ? $expiration + HOUR_IN_SECONDS
79
+ : $cookie_elements['expiration'];
80
+
81
+ // Quick check to see if an honest cookie has expired
82
+ if ( $expired >= time() ) {
83
+ $user = apbct_wp_get_user_by('login', $username);
84
+ if ( $user ) {
85
+ $pass_frag = substr($user->user_pass, 8, 4);
86
+ $key = apbct_wp_hash($username . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme);
87
+ // If ext/hash is not present, compat.php's hash_hmac() does not support sha256.
88
+ $algo = function_exists('hash') ? 'sha256' : 'sha1';
89
+ $hash = hash_hmac($algo, $username . '|' . $expiration . '|' . $token, $key);
90
+ if ( hash_equals($hash, $hmac) ) {
91
+ $sessions = get_user_meta($user->ID, 'session_tokens', true);
92
+ $sessions = is_array($sessions) ? current($sessions) : $sessions;
93
+ if ( is_array($sessions) ) {
94
+ if ( is_int($sessions['expiration']) && $sessions['expiration'] > time() ) {
95
+ return $user->ID;
96
+ } else {
97
+ return false;
98
+ }
99
+ } else {
100
+ return false;
101
+ }
102
+ } else {
103
+ return false;
104
+ }
105
+ } else {
106
+ return false;
107
+ }
108
+ } else {
109
+ return false;
110
+ }
111
  }
112
 
113
  /**
119
  *
120
  * @return string
121
  */
122
+ function apbct_get_rest_url($blog_id = null, $path = '/', $scheme = 'rest')
123
+ {
124
+ global $wp_rewrite;
125
 
126
+ if ( empty($path) ) {
127
  $path = '/';
128
  }
129
+
130
+ $path = '/' . ltrim($path, '/');
131
+
132
+ if ( is_multisite() && (get_blog_option($blog_id, 'permalink_structure') || get_option('permalink_structure')) ) {
133
  if ( $wp_rewrite->using_index_permalinks() ) {
134
+ $url = get_home_url($blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix(), $scheme);
135
  } else {
136
+ $url = get_home_url($blog_id, rest_get_url_prefix(), $scheme);
137
  }
138
+
139
  $url .= $path;
140
  } else {
141
+ $url = trailingslashit(get_home_url($blog_id, '', $scheme));
142
  // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php.
143
  // To work around this, we manually add index.php to the URL, avoiding the redirect.
144
+ if ( 'index.php' !== substr($url, 9) ) {
145
  $url .= 'index.php';
146
  }
147
+
148
+ $url = add_query_arg('rest_route', $path, $url);
149
  }
150
+
151
+ if ( is_ssl() && isset($_SERVER['SERVER_NAME']) ) {
152
  // If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.
153
+ if ( parse_url(get_home_url($blog_id), PHP_URL_HOST) === $_SERVER['SERVER_NAME'] ) {
154
+ $url = set_url_scheme($url, 'https');
155
  }
156
  }
157
+
158
  if ( is_admin() && force_ssl_admin() ) {
159
  /*
160
  * In this situation the home URL may be http:, and `is_ssl()` may be false,
161
  * but the admin is served over https: (one way or another), so REST API usage
162
  * will be blocked by browsers unless it is also served over HTTPS.
163
  */
164
+ $url = set_url_scheme($url, 'https');
165
  }
166
+
167
  /**
168
  * Filters the REST URL.
169
  *
170
  * Use this filter to adjust the url returned by the get_rest_url() function.
171
  *
172
+ * @param string $url REST URL.
173
+ * @param string $path REST route.
 
 
174
  * @param int|null $blog_id Blog ID.
175
+ * @param string $scheme Sanitization scheme.
176
+ *
177
  * @psalm-suppress TooManyArguments
178
+ * @since 4.4.0
179
+ *
180
  */
181
+ return apply_filters('rest_url', $url, $path, $blog_id, $scheme);
182
  }
183
 
184
  /**
189
  *
190
  * @return bool|WP_User
191
  */
192
+ function apbct_wp_get_user_by($field, $value)
193
+ {
194
+ $userdata = WP_User::get_data_by($field, $value);
195
+
196
+ if ( ! $userdata ) {
197
+ return false;
198
+ }
199
+
200
+ $user = new WP_User();
201
+ $user->init($userdata);
202
+
203
+ return $user;
204
  }
205
 
206
  /**
207
  * Get hash of given string.
208
  *
209
+ * @param string $data Plain text to hash
210
  * @param string $scheme Authentication scheme (auth, secure_auth, logged_in, nonce)
211
+ *
212
  * @return string Hash of $data
213
  */
214
+ function apbct_wp_hash($data, $scheme = 'auth')
215
+ {
216
+ $values = array(
217
+ 'key' => '',
218
+ 'salt' => '',
219
+ );
220
+
221
+ foreach ( array('key', 'salt') as $type ) {
222
+ $const = strtoupper("{$scheme}_{$type}");
223
+ if ( defined($const) && constant($const) ) {
224
+ $values[$type] = constant($const);
225
+ } elseif ( ! $values[$type] ) {
226
+ $values[$type] = get_site_option("{$scheme}_{$type}");
227
+ if ( ! $values[$type] ) {
228
+ $values[$type] = '';
229
+ }
230
+ }
231
+ }
232
+
233
+ $salt = $values['key'] . $values['salt'];
234
+
235
+ return hash_hmac('md5', $data, $salt);
236
  }
237
 
238
  /**
246
  */
247
  function apbct_wp_parse_auth_cookie($cookie = '', $scheme = '')
248
  {
249
+ $cookie_elements = explode('|', $cookie);
250
+ if ( count($cookie_elements) !== 4 ) {
251
+ return false;
252
+ }
253
+
254
+ list($username, $expiration, $token, $hmac) = $cookie_elements;
255
+
256
+ return compact('username', 'expiration', 'token', 'hmac', 'scheme');
257
  }
258
 
259
  /**
263
  *
264
  * @return bool
265
  */
266
+ function apbct_is_plugin_active($plugin)
267
+ {
268
+ return in_array($plugin, (array)get_option('active_plugins', array())) || apbct_is_plugin_active_for_network($plugin);
269
  }
270
 
271
  /**
275
  *
276
  * @return bool
277
  */
278
+ function apbct_is_theme_active($theme_name)
279
+ {
280
+ return get_option('template') == $theme_name ? true : false;
281
  }
282
 
283
  /**
287
  *
288
  * @return bool
289
  */
290
+ function apbct_is_plugin_active_for_network($plugin)
291
+ {
292
+ if ( ! APBCT_WPMS ) {
293
+ return false;
294
+ }
295
+
296
+ $plugins = get_site_option('active_sitewide_plugins');
297
+
298
+ return isset($plugins[$plugin])
299
+ ? true
300
+ : false;
301
  }
302
 
303
  /**
305
  *
306
  * @return boolean
307
  */
308
+ function apbct_is_ajax()
309
+ {
310
+ return
311
+ (defined('DOING_AJAX') && DOING_AJAX) || // by standart WP functions
312
+ (
313
+ apbct_get_server_variable('HTTP_X_REQUESTED_WITH') &&
314
+ strtolower(apbct_get_server_variable('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'
315
+ ) || // by Request type
316
+ ! empty($_POST['quform_ajax']) || // special. QForms
317
+ ! empty($_POST['iphorm_ajax']); // special. IPHorm
318
  }
319
 
320
  /**
322
  *
323
  * @return boolean
324
  */
325
+ function apbct_is_rest()
326
+ {
327
+ return defined('REST_REQUEST') && REST_REQUEST;
328
  }
329
 
330
  /**
332
  *
333
  * @return boolean
334
  */
335
+ function apbct_is_cli()
336
+ {
337
+ return PHP_SAPI === "cli";
338
  }
339
 
340
  /**
342
  *
343
  * @return bool
344
  */
345
+ function apbct_is_user_logged_in()
346
+ {
347
+ $siteurl = get_site_option('siteurl');
348
+ $cookiehash = $siteurl ? md5($siteurl) : '';
349
+
350
+ return count($_COOKIE) && isset($_COOKIE['wordpress_logged_in_' . $cookiehash]);
351
  }
352
 
353
  /*
354
  * GETTING SERVER VARIABLES BY VARIOUS WAYS
355
  */
356
+ function apbct_get_server_variable($server_variable_name)
357
+ {
358
+ $var_name = strtoupper($server_variable_name);
359
+
360
+ if ( function_exists('filter_input') ) {
361
+ $value = filter_input(INPUT_SERVER, $var_name);
362
+ }
363
+
364
+ if ( empty($value) ) {
365
+ $value = isset($_SERVER[$var_name]) ? $_SERVER[$var_name] : '';
366
+ }
367
+
368
+ // Convert to upper case for REQUEST_METHOD
369
+ if ( in_array($server_variable_name, array('REQUEST_METHOD')) ) {
370
+ $value = strtoupper($value);
371
+ }
372
+
373
+ // Convert HTML chars for HTTP_USER_AGENT, HTTP_USER_AGENT, SERVER_NAME
374
+ if ( in_array($server_variable_name, array('HTTP_USER_AGENT', 'HTTP_USER_AGENT', 'SERVER_NAME')) ) {
375
+ $value = htmlspecialchars($value);
376
+ }
377
+
378
+ return $value;
379
  }
380
 
381
+ function apbct_is_post()
382
+ {
383
  return apbct_get_server_variable('REQUEST_METHOD') === 'POST';
384
  }
385
 
386
+ function apbct_is_get()
387
+ {
388
  return apbct_get_server_variable('REQUEST_METHOD') === 'GET';
389
  }
390
 
391
+ function apbct_is_in_referer($str)
392
+ {
393
+ return stripos(apbct_get_server_variable('HTTP_REFERER'), $str) !== false;
394
  }
395
 
396
+ function apbct_is_in_uri($str)
397
+ {
398
+ return stripos(apbct_get_server_variable('REQUEST_URI'), $str) !== false;
399
  }
400
 
401
  /*
404
  *
405
  * @return bool
406
  */
407
+ function apbct_wp_doing_cron()
408
+ {
409
+ if ( function_exists('wp_doing_cron') ) {
410
  return wp_doing_cron();
411
  } else {
412
+ return (defined('DOING_CRON') && DOING_CRON);
413
  }
 
414
  }
415
 
416
  /**
422
  * @param $comment
423
  * @param $user_ip
424
  * @param $user_agent
425
+ *
426
  * @return bool
427
  */
428
+ function apbct_wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent)
429
+ {
430
  global $wp_version;
431
 
432
+ if ( version_compare($wp_version, '5.5.0', '>=') ) {
433
+ return wp_check_comment_disallowed_list($author, $email, $url, $comment, $user_ip, $user_agent);
434
  } else {
435
+ return wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent);
436
  }
 
437
  }
438
 
439
  /**
442
  *
443
  * @return bool
444
  */
445
+ function apbct_is_customize_preview()
446
+ {
447
  // Maybe not enough to check the Customizer preview
448
  $uri = parse_url(Server::get('REQUEST_URI'));
449
+
450
+ return $uri && isset($uri['query']) && strpos($uri['query'], 'customize_changeset_uuid') !== false;
451
  }
452
 
453
 
458
  *
459
  * @return bool|string false or request name for logging
460
  */
461
+ function apbct_is_skip_request($ajax = false)
462
+ {
463
  /* !!! Have to use more than one factor to detect the request - is_plugin active() && $_POST['action'] !!! */
464
  //@ToDo Implement direct integration checking - if have the direct integration will be returned false
465
 
466
+ if ( $ajax ) {
467
  /*****************************************/
468
  /* Here is ajax requests skipping */
469
  /*****************************************/
470
 
471
  // Paid Memberships Pro - Login Form
472
+ if (
473
+ apbct_is_plugin_active('paid-memberships-pro/paid-memberships-pro.php') &&
474
+ Post::get('rm_slug') === 'rm_login_form' &&
475
+ Post::get('rm_form_sub_id')
476
+ ) {
477
  return 'paid_memberships_pro__login_form';
478
  }
479
+
480
  // Thrive Ultimatum
481
+ if (
482
+ apbct_is_plugin_active('thrive-ultimatum/thrive-ultimatum.php') &&
483
+ Post::get('action') === 'tve_dash_front_ajax'
484
+ ) {
485
  return 'thrive-ultimatum__links_from_email';
486
  }
487
+
488
  // wpDiscuz - Online Users Addon for wpDiscuz
489
+ if (
490
+ apbct_is_plugin_active('wpdiscuz-online-users/wpdiscuz-ou.php') &&
491
+ Post::get('action') === 'wouPushNotification'
492
+ ) {
493
  return 'wpdiscuz_online_users__push_notification';
494
  }
495
+
496
  // Bookly Plugin admin actions skip
497
+ if ( apbct_is_plugin_active('bookly-responsive-appointment-booking-tool/main.php') &&
498
+ isset($_POST['action']) &&
499
+ strpos($_POST['action'], 'bookly') !== false &&
500
+ is_admin() ) {
 
501
  return 'bookly_pro_update_staff_advanced';
502
  }
503
  // Youzier login form skip
504
+ if ( apbct_is_plugin_active('youzer/youzer.php') &&
505
+ isset($_POST['action']) &&
506
+ $_POST['action'] === 'yz_ajax_login' ) {
 
507
  return 'youzier_login_form';
508
  }
509
  // Youzify login form skip
510
+ if ( apbct_is_plugin_active('youzify/youzify.php') &&
511
+ isset($_POST['action']) &&
512
+ $_POST['action'] === 'youzify_ajax_login' ) {
513
+ return 'youzify_login_form';
 
514
  }
515
  // InJob theme lost password skip
516
+ if ( apbct_is_plugin_active('iwjob/iwjob.php') &&
517
+ isset($_POST['action']) &&
518
+ $_POST['action'] === 'iwj_lostpass' ) {
 
519
  return 'injob_theme_plugin';
520
  }
521
  // Divi builder skip
522
+ if ( apbct_is_theme_active('Divi') &&
523
+ isset($_POST['action']) &&
524
+ ($_POST['action'] === 'save_epanel' || $_POST['action'] === 'et_fb_ajax_save') ) {
525
+ return 'divi_builder_skip';
 
526
  }
527
  // Email Before Download plugin https://wordpress.org/plugins/email-before-download/ action skip
528
+ if ( apbct_is_plugin_active('email-before-download/email-before-download.php') &&
529
+ isset($_POST['action']) &&
530
+ $_POST['action'] === 'ebd_inline_links' ) {
531
+ return 'ebd_inline_links';
 
532
  }
533
  // WP Discuz skip service requests. The plugin have the direct integration
534
+ if ( apbct_is_plugin_active('wpdiscuz/class.WpdiscuzCore.php') &&
535
+ isset($_POST['action']) &&
536
+ strpos($_POST['action'], 'wpd') !== false ) {
537
+ return 'ebd_inline_links';
 
538
  }
539
  // Exception for plugin https://ru.wordpress.org/plugins/easy-login-woocommerce/ login form
540
+ if (
541
+ apbct_is_plugin_active('easy-login-woocommerce/xoo-el-main.php') &&
542
+ Post::get('_xoo_el_form') === 'login'
543
+ ) {
544
  return 'xoo_login';
545
  }
546
  // Emails & Newsletters with Jackmail: skip all admin-side actions
547
+ if (
548
+ apbct_is_plugin_active('jackmail-newsletters/jackmail-newsletters.php') &&
549
+ is_admin() &&
550
+ strpos(Server::get('HTTP_REFERER'), 'jackmail_') !== false
551
+ ) {
552
+ return 'jackmail_admin_actions';
553
  }
554
  // Newspaper theme login form
555
+ if ( apbct_is_theme_active('Newspaper') &&
556
+ isset($_POST['action']) &&
557
+ ($_POST['action'] == 'td_mod_login' || $_POST['action'] == 'td_mod_remember_pass') ) {
558
+ return 'Newspaper_theme_login_form';
 
559
  }
560
  // Save abandoned cart checking skip
561
+ if ( apbct_is_plugin_active('woo-save-abandoned-carts/cartbounty-abandoned-carts.php') &&
562
+ Post::get('action') === 'cartbounty_save' ) {
563
+ return 'cartbounty_save';
 
564
  }
565
  // SUMODISCOUNT discout request skip
566
+ if ( apbct_is_plugin_active('sumodiscounts/sumodiscounts.php') &&
567
+ Post::get('action') === 'fp_apply_discount_for_first_purchase' ) {
568
+ return 'fp_apply_discount_for_first_purchase';
 
569
  }
570
  // WP eMember login form skip
571
+ if ( apbct_is_plugin_active('wp-eMember/wp_eMember.php') &&
572
+ Post::get('action') === 'emember_ajax_login' ) {
573
+ return 'emember_ajax_login';
 
574
  }
575
  // Avada theme saving settings
576
+ if ( apbct_is_theme_active('Avada') &&
577
+ Post::get('action') === 'fusion_options_ajax_save' ) {
578
+ return 'Avada_theme_saving_settings';
 
579
  }
580
  // Formidable skip - this is the durect integration
581
+ if ( apbct_is_plugin_active('formidable/formidable.php') &&
582
+ Post::get('action') === 'frm_entries_update' ) {
583
+ return 'formidable_skip';
 
584
  }
585
  // Artbees Jupiter theme saving settings
586
+ if ( Post::get('action') === 'mk_theme_save' && strpos(get_template(), 'jupiter') !== false ) {
587
+ return 'artbees_jupiter_6_skip';
588
  }
589
  // fix conflict with wiloke theme and unknown plugin, that removes standard authorization cookies
590
+ if ( Post::get('action') === 'wiloke_themeoptions_ajax_save' && apbct_is_theme_active('wilcity') ) {
591
  return 'wiloke_themeoptions_ajax_save_skip';
592
  }
593
  // Essentials addons for elementor - light and pro
594
+ if (
595
+ (apbct_is_plugin_active('essential-addons-for-elementor-lite/essential_adons_elementor.php') ||
596
+ apbct_is_plugin_active('essential-addons-elementor/essential_adons_elementor.php')) &&
597
+ (Post::get('eael-login-submit') !== '' && Post::get('eael-user-login') !== '') ) {
598
+ return 'eael_login_skipped';
 
599
  }
600
  // WPForms check restricted email skipped
601
+ if (
602
+ (apbct_is_plugin_active('wpforms/wpforms.php')) &&
603
+ (Post::get('action') === 'wpforms_restricted_email' && Post::get('token') !== '')
604
+ ) {
605
+ return 'wpforms_check_restricted_email';
606
+ }
607
+ // FluentForm multistep skip
608
+ if (
609
+ (apbct_is_plugin_active('fluentformpro/fluentformpro.php') || apbct_is_plugin_active('fluentform/fluentform.php')) &&
610
+ Post::get('action') === 'active_step'
611
+ ) {
612
+ return 'fluentform_skip';
613
+ }
614
+
615
+ // W2DC - https://codecanyon.net/item/web-20-directory-plugin-for-wordpress/6463373
616
+ if ( apbct_is_plugin_active('w2dc/w2dc.php') &&
617
+ isset($_POST['action']) &&
618
+ $_POST['action'] === 'vp_w2dc_ajax_vpt_option_save' &&
619
+ is_admin() ) {
620
+ return 'w2dc_skipped';
621
+ }
622
+ if ( apbct_is_plugin_active('elementor/elementor.php') &&
623
+ isset($_POST['actions_save_builder_action']) &&
624
+ $_POST['actions_save_builder_action'] === 'save_builder' &&
625
+ is_admin() ) {
 
626
  return 'elementor_skip';
627
  }
628
+ // Enfold theme saving settings
629
+ if ( apbct_is_theme_active('Enfold') &&
630
+ Post::get('action') === 'avia_ajax_save_options_page' ) {
631
+ return 'Enfold_theme_saving_settings';
632
+ }
 
633
  //SiteOrigin pagebuilder skip save
634
+ if (
635
+ apbct_is_plugin_active('siteorigin-panels/siteorigin-panels.php') &&
636
+ Post::get('action') === 'save-widget'
637
+ ) {
638
  return 'SiteOrigin pagebuilder';
639
  }
640
  //Skip classfields email check
641
+ if (
642
+ (apbct_is_theme_active('classified-child') || apbct_is_theme_active('classified'))
643
+ && Post::get('action') === 'tmpl_ajax_check_user_email'
644
+ ) {
645
+ return 'Classified checkemail';
646
  }
647
  } else {
 
648
  /*****************************************/
649
  /* Here is non-ajax requests skipping */
650
  /*****************************************/
651
+ // WC payment APIs
652
+ if ( apbct_is_plugin_active('woocommerce/woocommerce.php') &&
653
+ apbct_is_in_uri('wc-api=2checkout_ipn_convert_plus') ) {
654
+ return 'wc-payment-api';
655
+ }
 
656
  // BuddyPress edit profile checking skip
657
+ if ( apbct_is_plugin_active('buddypress/bp-loader.php') &&
658
+ array_key_exists('profile-group-edit-submit', $_POST) ) {
 
659
  return 'buddypress_profile_edit';
660
  }
661
  // UltimateMember password reset skip
662
+ if ( apbct_is_plugin_active('ultimate-member/ultimate-member.php') &&
663
+ isset($_POST['_um_password_reset']) && $_POST['_um_password_reset'] == 1 ) {
 
664
  return 'ultimatemember_password_reset';
665
  }
666
+ // UltimateMember password reset skip
667
+ if ( apbct_is_plugin_active('gravityformspaypal/paypal.php') &&
668
+ (apbct_is_in_uri('page=gf_paypal_ipn') || apbct_is_in_uri('callback=gravityformspaypal')) ) {
669
+ return 'gravityformspaypal_processing_skipped';
670
+ }
671
+ // MyListing theme service requests skip
672
+ if ( (apbct_is_theme_active('My Listing Child') || apbct_is_theme_active('My Listing')) &&
673
+ Get::get('mylisting-ajax') === '1' ) {
674
+ return 'mylisting_theme_service_requests_skip';
675
+ }
676
+ // HappyForms skip every requests. HappyForms have the direct integration
677
+ if ( (apbct_is_plugin_active('happyforms-upgrade/happyforms-upgrade.php') ||
678
+ apbct_is_plugin_active('happyforms/happyforms.php')) &&
679
+ (Post::get('happyforms_message_nonce') !== '') ) {
680
+ return 'happyform_skipped';
681
+ }
682
+ // Essentials addons for elementor - light and pro
683
+ if (
684
+ (apbct_is_plugin_active('essential-addons-for-elementor-lite/essential_adons_elementor.php') ||
685
+ apbct_is_plugin_active('essential-addons-elementor/essential_adons_elementor.php')) &&
686
+ (Post::get('eael-login-submit') !== '' && Post::get('eael-user-login') !== '') ) {
687
+ return 'eael_login_skipped';
688
+ }
689
+ // Autonami Marketing Automations service request
690
+ if ( apbct_is_rest() && Post::get('automation_id') !== '' && Post::get('unique_key') !== '' ) {
691
+ return 'autonami-rest';
692
+ }
693
+ //Skip wforms because of direct integration
694
+ if (
695
+ apbct_is_plugin_active('wpforms/wpforms.php') &&
696
+ (Post::get('wpforms') || Post::get('actions') === 'wpforms_submit')
697
+ ) {
698
+ return 'wp_forms';
699
+ }
 
 
700
  // Formidable skip - this is the durect integration
701
+ if ( apbct_is_plugin_active('formidable/formidable.php') &&
702
+ Post::get('frm_action') === 'update' ) {
 
703
  return 'formidable_skip';
704
  }
705
+ // WC payment APIs
706
+ if ( apbct_is_plugin_active('woocommerce/woocommerce.php') &&
707
+ apbct_is_in_uri('wc-ajax=iwd_opc_update_order_review') ) {
708
+ return 'cartflows_save_cart';
709
+ }
 
710
  }
711
 
712
  return false;
713
  }
 
inc/cleantalk-public-integrations.php CHANGED
@@ -7,23 +7,26 @@ use Cleantalk\Variables\Post;
7
  use Cleantalk\Variables\Server;
8
 
9
  // MailChimp Premium for Wordpress
10
- function ct_add_mc4wp_error_message($messages){
 
 
 
 
 
11
 
12
- $messages['ct_mc4wp_response'] = array(
13
- 'type' => 'error',
14
- 'text' => 'Your message looks like spam.'
15
- );
16
- return $messages;
17
  }
18
- add_filter( 'mc4wp_form_messages', 'ct_add_mc4wp_error_message' );
 
19
 
20
  /**
21
  * Function to set validate function for CCF form
22
  * Input - Consistently each form field
23
  * Returns - String. Validate function
24
- */
25
- function ct_ccf($_callback, $_value, $_field_id, $_type){
26
- return 'ct_validate_ccf_submission';
 
27
  }
28
 
29
  $ct_global_temporary_data = array();
@@ -39,411 +42,467 @@ $ct_global_temporary_data = array();
39
  * @return bool|string|null
40
  * @psalm-suppress InvalidArrayOffset
41
  */
42
- function ct_validate_ccf_submission($value, $_field_id, $_required){
43
- global $ct_global_temporary_data, $apbct;
44
-
45
- //If the check for contact forms enabled
46
- if(!$apbct->settings['forms__contact_forms_test']) {
47
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
48
- return true;
49
- }
50
-
51
- //If the check for logged in users enabled
52
- if($apbct->settings['data__protect_logged_in'] == 1 && is_user_logged_in()) {
53
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
54
- return true;
55
- }
56
-
57
- //Accumulate data
58
- $ct_global_temporary_data[] = $value;
59
-
60
- //If it's the last field of the form
61
- (!isset($ct_global_temporary_data['count']) ? $ct_global_temporary_data['count'] = 1 : $ct_global_temporary_data['count']++);
62
- $form_id = $_POST['form_id'];
63
- if($ct_global_temporary_data['count'] != count(get_post_meta( $form_id, 'ccf_attached_fields', true ))) {
64
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
65
- return true;
66
- }
67
-
68
- unset($ct_global_temporary_data['count']);
69
-
70
- //Getting request params
71
- $ct_temp_msg_data = ct_get_fields_any($_POST);
72
-
73
- unset($ct_global_temporary_data);
74
-
75
- $sender_email = $ct_temp_msg_data['email'] ?: '';
76
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
77
- $subject = $ct_temp_msg_data['subject'] ?: '';
78
- $message = $ct_temp_msg_data['message'] ?: array();
79
-
80
- if ($subject !== '') {
81
- $message['subject'] = $subject;
82
- }
83
-
84
- $post_info['comment_type'] = 'feedback_custom_contact_forms';
85
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
86
-
87
- $checkjs = apbct_js_test( 'ct_checkjs', $_COOKIE, true ) ?: apbct_js_test( 'ct_checkjs', $_POST );
88
-
89
- //Making a call
90
- $base_call_result = apbct_base_call(
91
- array(
92
- 'message' => $message,
93
- 'sender_email' => $sender_email,
94
- 'sender_nickname' => $sender_nickname,
95
- 'post_info' => $post_info,
96
- 'js_on' => $checkjs,
97
- 'sender_info' => array('sender_url' => null),
98
- )
99
- );
100
-
101
- $ct_result = $base_call_result['ct_result'];
102
-
103
- return $ct_result->allow == 0 ? $ct_result->comment : true;
104
- }
105
-
106
- function ct_woocommerce_wishlist_check($args){
107
- global $apbct;
108
-
109
- //Protect logged in users
110
- if($args['wishlist_status']) {
111
- if ( $apbct->settings['data__protect_logged_in'] == 0 ) {
112
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
113
-
114
- return $args;
115
- }
116
- }
117
-
118
- //If the IP is a Google bot
119
- $hostname = gethostbyaddr( apbct_get_server_variable( 'REMOTE_ADDR' ) );
120
- if(!strpos($hostname, 'googlebot.com')) {
121
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
122
- return $args;
123
- }
124
-
125
- //Getting request params
126
- $message = '';
127
- $subject = '';
128
- $email = $args['wishlist_owner_email'];
129
- if( $args['wishlist_first_name']!=='' || $args['wishlist_last_name']!=='' ) {
130
- $nickname = trim( $args['wishlist_first_name'] . " " . $args['wishlist_last_name'] );
131
- } else {
132
- $nickname = '';
133
- }
134
-
135
- $post_info['comment_type'] = 'feedback';
136
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
137
-
138
- $checkjs = apbct_js_test( 'ct_checkjs', $_COOKIE, true ) ?: apbct_js_test( 'ct_checkjs', $_POST );
139
-
140
- //Making a call
141
- $base_call_result = apbct_base_call(
142
- array(
143
- 'message' => $subject." ".$message,
144
- 'sender_email' => $email,
145
- 'sender_nickname' => $nickname,
146
- 'post_info' => $post_info,
147
- 'js_on' => $checkjs,
148
- 'sender_info' => array('sender_url' => null),
149
- )
150
- );
151
-
152
- $ct_result = $base_call_result['ct_result'];
153
-
154
- if ($ct_result->allow == 0) {
155
- wp_die( "<h1>" . __( 'Spam protection by CleanTalk', 'cleantalk-spam-protect' ) . "</h1><h2>" . $ct_result->comment . "</h2>",
156
- '',
157
- array( 'response' => 403, "back_link" => true, "text_direction" => 'ltr'
158
- ) );
159
- } else {
160
- return $args;
161
- }
162
- }
163
-
164
- function apbct_integration__buddyPres__getTemplateName( $located, $_template_name, $_template_names, $_template_locations, $_load, $_require_once ) {
165
- global $apbct;
166
- preg_match("/\/([a-z-_]+)\/buddypress-functions\.php$/", $located, $matches);
167
- $apbct->buddy_press_tmpl = isset($matches[1]) ? $matches[1] : 'unknown';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
 
170
  /**
171
  * Test BuddyPress activity for spam (post update only)
172
  *
173
- * @global State $apbct
174
  * @param bool $is_spam
175
  * @param object $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
 
176
  * @return boolean Spam flag
177
  * @psalm-suppress UnusedVariable
 
178
  */
179
- function apbct_integration__buddyPres__activityWall( $is_spam, $activity_obj = null ){
180
-
181
- global $apbct;
182
-
183
- $allowed_post_actions = array('post_update', 'new_activity_comment');
184
-
185
- if( ! in_array( Post::get('action'), $allowed_post_actions) ||
186
- $activity_obj === null ||
187
- ! Post::get('action') ||
188
- $activity_obj->privacy == 'media' ||
189
- apbct_exclusions_check()
190
- ) {
191
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
192
- return false;
193
- }
194
-
195
- $curr_user = get_user_by('id', $activity_obj->user_id);
196
-
197
- //Making a call
198
- $base_call_result = apbct_base_call(
199
- array(
200
- 'message' => is_string($activity_obj->content) ? $activity_obj->content : '',
201
- 'sender_email' => $curr_user->data->user_email,
202
- 'sender_nickname' => $curr_user->data->user_login,
203
- 'post_info' => array(
204
- 'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ),
205
- 'comment_type' => 'buddypress_activitywall',
206
- ),
207
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
208
- 'sender_info' => array('sender_url' => null),
209
- )
210
- );
211
-
212
- $ct_result = $base_call_result['ct_result'];
213
-
214
- if ($ct_result->allow == 0){
215
- add_action('bp_activity_after_save', 'apbct_integration__buddyPres__activityWall_showResponse', 1, 1);
216
- $apbct->spam_notification = $ct_result->comment;
217
- return true;
218
- }else {
219
- return $is_spam;
220
- }
 
 
221
  }
222
 
223
  /**
224
  * Outputs message to AJAX frontend handler
225
  *
226
- * @global State $apbct
227
  * @param object $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
 
 
228
  */
229
- function apbct_integration__buddyPres__activityWall_showResponse( $_activity_obj ){
230
-
231
- global $apbct;
232
-
233
- // Legacy template
234
- if($apbct->buddy_press_tmpl === 'bp-legacy'){
235
- die('<div id="message" class="error bp-ajax-message"><p>'. $apbct->spam_notification .'</p></div>');
236
- // Nouveau template and others
237
- }else{
238
- @header( 'Content-Type: application/json; charset=' . get_option('blog_charset'));
239
- die(json_encode(array(
240
- 'success' => false,
241
- 'data' => array('message' => $apbct->spam_notification),
242
- )));
243
- }
 
 
 
 
244
  }
245
 
246
  /**
247
  * Public function - Tests new private messages (dialogs)
248
  *
249
- * @global State $apbct
250
  * @param object $bp_message_obj
 
251
  * @return void with errors if spam has found
252
  * @psalm-suppress UndefinedClass
253
  * @psalm-suppress UnusedVariable
 
254
  */
255
- function apbct_integration__buddyPres__private_msg_check( $bp_message_obj){
256
-
257
- global $apbct;
258
-
259
- //Check for enabled option
260
- if(
261
- $apbct->settings['comments__bp_private_messages'] == 0 ||
262
- apbct_exclusions_check()
263
- ) {
264
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
265
- return;
266
- }
267
-
268
- //Check for quantity of comments
269
- $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER')
270
- ? CLEANTALK_CHECK_COMMENTS_NUMBER
271
- : 3;
272
-
273
- if($apbct->settings['comments__check_comments_number']){
274
- $args = array(
275
- 'user_id' => $bp_message_obj->sender_id,
276
- 'box' => 'sentbox',
277
- 'type' => 'all',
278
- 'limit' => $comments_check_number,
279
- 'page' => null,
280
- 'search_terms' => '',
281
- 'meta_query' => array()
282
- );
283
- $sentbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
284
- $cnt_sentbox_msgs = $sentbox_msgs['total'];
285
- $args['box'] = 'inbox';
286
- $inbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
287
- $cnt_inbox_msgs = $inbox_msgs['total'];
288
-
289
- if(($cnt_inbox_msgs + $cnt_sentbox_msgs) >= $comments_check_number)
290
- $is_max_comments = true;
291
- }
292
-
293
- if(!empty($is_max_comments)) {
294
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
295
- return;
296
- }
297
-
298
- $sender_user_obj = get_user_by('id', $bp_message_obj->sender_id);
299
-
300
- //Making a call
301
- $base_call_result = apbct_base_call(
302
- array(
303
- 'message' => $bp_message_obj->subject." ".$bp_message_obj->message,
304
- 'sender_email' => $sender_user_obj->data->user_email,
305
- 'sender_nickname' => $sender_user_obj->data->user_login,
306
- 'post_info' => array(
307
- 'comment_type' => 'buddypress_comment',
308
- 'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ),
309
- ),
310
- 'js_on' => apbct_js_test( 'ct_checkjs', $_COOKIE, true ) ?: apbct_js_test( 'ct_checkjs', $_POST ),
311
- 'sender_info' => array('sender_url' => null),
312
- )
313
- );
314
-
315
- $ct_result = $base_call_result['ct_result'];
316
-
317
- if ($ct_result->allow == 0) {
318
- wp_die( "<h1>" . __( 'Spam protection by CleanTalk', 'cleantalk-spam-protect' ) . "</h1><h2>" . $ct_result->comment . "</h2>",
319
- '',
320
- array( 'response' => 403, "back_link" => true, "text_direction" => 'ltr'
321
- ) );
322
- }
 
 
 
 
 
 
 
 
 
 
323
  }
324
 
325
  /**
326
  * Adds hidden filed to default search form
327
  *
328
  * @param $form string
 
329
  * @return string
330
  */
331
- function apbct_forms__search__addField( $form ){
332
- global $apbct;
333
- if($apbct->settings['forms__search_test'] == 1){
334
- $js_filed = ct_add_hidden_fields('ct_checkjs_search_default', true, false, false, false);
335
- $form = str_replace('</form>', $js_filed, $form);
336
- }
337
- return $form;
 
 
338
  }
339
 
340
  /**
341
  * Test default search string for spam
342
  *
343
  * @param $search string
 
344
  * @return string
345
  */
346
- function apbct_forms__search__testSpam( $search ){
 
 
347
 
348
- global $apbct, $cleantalk_executed;
 
 
 
 
 
 
349
 
350
- if(
351
- empty($search) ||
352
- $cleantalk_executed ||
353
- $apbct->settings['forms__search_test'] == 0 ||
354
- ( $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() ) // Skip processing for logged in users.
355
- ){
356
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
357
- return $search;
358
- }
359
 
360
  $user = apbct_is_user_logged_in() ? wp_get_current_user() : null;
361
 
362
- $base_call_result = apbct_base_call(
363
- array(
364
- 'message' => $search,
365
- 'sender_email' => $user !== null ? $user->user_email : null,
366
- 'sender_nickname' => $user !== null ? $user->user_login : null,
367
- 'post_info' => array('comment_type' => 'site_search_wordpress'),
368
- )
369
- );
370
- $ct_result = $base_call_result['ct_result'];
371
 
372
- $cleantalk_executed = true;
373
 
374
- if ($ct_result->allow == 0){
375
- die($ct_result->comment);
376
- }
377
 
378
- return $search;
379
  }
380
 
381
- function apbct_search_add_noindex() {
382
-
383
- global $apbct;
384
-
385
- if(
386
- ! is_search() || // If it is search results
387
- $apbct->settings['forms__search_test'] == 0 ||
388
- ( $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() ) // Skip processing for logged in users.
389
- ){
390
- return ;
391
- }
392
 
393
- echo '<!-- meta by Cleantalk AntiSpam Protection plugin -->' . "\n";
394
- echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
 
 
 
 
 
395
 
 
 
396
  }
397
 
398
  /**
399
  * Test woocommerce checkout form for spam
400
  * @psalm-suppress UnusedVariable
401
  */
402
- function ct_woocommerce_checkout_check() {
403
-
404
- global $apbct, $cleantalk_executed;
405
-
406
- //Getting request params
407
- $ct_temp_msg_data = ct_get_fields_any($_POST);
408
-
409
- $sender_email = $ct_temp_msg_data['email'] ?: '';
410
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
411
- $subject = $ct_temp_msg_data['subject'] ?: '';
412
- $message = $ct_temp_msg_data['message'] ?: array();
413
-
414
- if($subject != '') {
415
- $message = array_merge( array( 'subject' => $subject ), $message );
416
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
 
418
- $post_info['comment_type'] = 'order';
419
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
420
 
421
- //Making a call
422
- $base_call_result = apbct_base_call(
423
- array(
424
- 'message' => $message,
425
- 'sender_email' => $sender_email,
426
- 'sender_nickname' => $sender_nickname,
427
- 'post_info' => $post_info,
428
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
429
- 'sender_info' => array('sender_url' => null),
430
- )
431
- );
432
 
433
- if( $apbct->settings['forms__wc_register_from_order'] ) {
434
- $cleantalk_executed = false;
435
- }
436
 
437
- $ct_result = $base_call_result['ct_result'];
438
 
439
- if ($ct_result->allow == 0) {
440
- wp_send_json(array(
441
- 'result' => 'failure',
442
- 'messages' => "<ul class=\"woocommerce-error\"><li>".$ct_result->comment."</li></ul>",
443
- 'refresh' => 'false',
444
- 'reload' => 'false'
445
- ));
446
- }
447
  }
448
 
449
  /**
@@ -456,121 +515,137 @@ function ct_woocommerce_checkout_check() {
456
  * @param $variation_id
457
  * @param $variation
458
  * @param $cart_item_data
 
459
  * @return void
460
  */
461
 
462
- function apbct_wc__add_to_cart_unlogged_user($_cart_item_key, $_product_id, $_quantity, $_variation_id, $_variation, $_cart_item_data) {
463
- global $apbct;
464
-
465
- if(! apbct_is_user_logged_in() && $apbct->settings['forms__wc_add_to_cart']) {
466
- /**
467
- * Getting request params
468
- * POST contains an array of product information
469
- * Example: Array
470
- *(
471
- * [product_sku] => woo-beanie
472
- * [product_id] => 15
473
- * [quantity] => 1
474
- *)
475
- */
476
- $message = $_POST ?: array();
477
-
478
- $post_info['comment_type'] = 'order__add_to_cart';
479
- $post_info['post_url'] = Server::get('HTTP_REFERER');
480
-
481
- //Making a call
482
- $base_call_result = apbct_base_call(
483
- array(
484
- 'message' => $message,
485
- 'post_info' => $post_info,
486
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
487
- 'sender_info' => array('sender_url' => null),
488
- )
489
- );
490
-
491
- $ct_result = $base_call_result['ct_result'];
492
-
493
- if ($ct_result->allow == 0) {
494
- wp_send_json(array(
495
- 'result' => 'failure',
496
- 'messages' => "<ul class=\"woocommerce-error\"><li>" . $ct_result->comment . "</li></ul>",
497
- 'refresh' => 'false',
498
- 'reload' => 'false',
499
- 'response_type' => 'wc_add_to_cart_block'
500
- ));
501
- }
502
- }
 
 
 
 
 
 
 
503
  }
504
 
505
  /**
506
  * Public function - Tests for Pirate contact forms
507
  * return NULL
508
  */
509
- function apbct_form__piratesForm__testSpam(){
510
-
511
- global $apbct;
512
-
513
- //Check for enabled option
514
- if( !$apbct->settings['forms__contact_forms_test']) {
515
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
516
- return;
517
- }
518
-
519
- //Getting request params
520
- $ct_temp_msg_data = ct_get_fields_any($_POST);
521
-
522
- $sender_email = $ct_temp_msg_data['email'] ?: '';
523
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
524
- $subject = $ct_temp_msg_data['subject'] ?: '';
525
- $message = $ct_temp_msg_data['message'] ?: array();
526
-
527
- if($subject !== '') {
528
- $message = array_merge( array( 'subject' => $subject ), $message );
529
- }
530
-
531
- $post_info['comment_type'] = 'contact_form_wordpress_feedback_pirate';
532
- $post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
533
-
534
- //Making a call
535
- $base_call_result = apbct_base_call(
536
- array(
537
- 'message' => $message,
538
- 'sender_email' => $sender_email,
539
- 'sender_nickname' => $sender_nickname,
540
- 'post_info' => $post_info,
541
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
542
- 'sender_info' => array('sender_url' => null),
543
- )
544
- );
545
-
546
- $ct_result = $base_call_result['ct_result'];
547
-
548
- if ($ct_result->allow == 0) {
549
- wp_die( "<h1>" . __( 'Spam protection by CleanTalk', 'cleantalk-spam-protect' ) . "</h1><h2>" . $ct_result->comment . "</h2>",
550
- '',
551
- array( 'response' => 403, "back_link" => true, "text_direction" => 'ltr'
552
- ) );
553
- }
 
 
 
 
 
 
 
 
554
  }
555
 
556
  /**
557
  * Adds hidden filed to comment form
558
  */
559
- function ct_comment_form($_post_id){
 
 
560
 
561
- global $apbct;
 
 
562
 
563
- if (apbct_is_user_enable() === false) {
564
- return false;
565
- }
566
 
567
- if ( !$apbct->settings['forms__comments_test']) {
568
- return false;
569
- }
570
 
571
- ct_add_hidden_fields();
572
-
573
- return null;
574
  }
575
 
576
  /**
@@ -581,19 +656,19 @@ function ct_comment_form($_post_id){
581
  *
582
  * @return false|null
583
  */
584
- function apbct_form__formidable__footerScripts($_fields, $form) {
585
-
586
- global $apbct, $ct_checkjs_frm;
587
 
588
- if ( !$apbct->settings['forms__contact_forms_test']) {
589
- return false;
590
- }
591
 
592
- $ct_checkjs_key = ct_get_checkjs_value();
593
- $ct_frm_base_name = 'form_';
594
- $ct_frm_name = $ct_frm_base_name . $form->form_key;
595
 
596
- echo "var input = document.createElement('input');
597
  input.setAttribute('type', 'hidden');
598
  input.setAttribute('name', '$ct_checkjs_frm');
599
  input.setAttribute('value', '$ct_checkjs_key');
@@ -608,468 +683,524 @@ function apbct_form__formidable__footerScripts($_fields, $form) {
608
 
609
  /**
610
  * Public function - Test Formidable data for spam activity
 
611
  * @param $errors
612
  * @param $form
613
  *
614
  * @return array with errors if spam has found
615
  * @psalm-suppress InvalidScalarArgument
616
  */
617
- function apbct_form__formidable__testSpam ( $errors, $_form ) {
618
-
619
- global $apbct;
620
-
621
- if ( !$apbct->settings['forms__contact_forms_test']) {
622
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
623
- return $errors;
624
- }
625
-
626
- // Skip processing for logged in users.
627
- if ( !$apbct->settings['data__protect_logged_in'] && is_user_logged_in()) {
628
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
629
- return $errors;
630
- }
631
-
632
- $form_data = array();
633
- foreach( $_POST['item_meta'] as $key => $value ) {
634
- $form_data['item_meta[' . $key . ']'] = $value;
635
- }
636
-
637
- $ct_temp_msg_data = ct_get_fields_any( $form_data );
638
-
639
- $sender_email = $ct_temp_msg_data['email'] ?: '';
640
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
641
- $message = $ct_temp_msg_data['message'] ?: array();
642
-
643
- // @todo convert key 'NUM' to 'input_meta[NUM]'
644
- // Adding 'input_meta[]' to every field /Formidable fix/
645
- // because filed names is 'input_meta[NUM]'
646
- // Get all scalar values
647
- $tmp_message = array();
648
- $tmp_message2 = array();
649
- foreach( $message as $key => $value ){
650
- if( is_scalar( $value ) ){
651
- $tmp_message[ $key ] = $value;
652
- }else{
653
- $tmp_message2[ $key ] = $value;
654
- }
655
- }
656
- // Replacing key to input_meta[NUM] for scalar values
657
- $tmp_message = array_flip($tmp_message);
658
- foreach($tmp_message as &$value){
659
- $value = 'item_meta['.$value.']';
660
- } unset($value);
661
- // @ToDO Need to be solved psalm notice about InvalidScalarArgument
662
- $tmp_message = array_flip($tmp_message);
663
- // Combine it with non-scalar values
664
- $message = array_merge( $tmp_message, $tmp_message2 );
665
-
666
- $checkjs = apbct_js_test( 'ct_checkjs', $_COOKIE, true ) ?: apbct_js_test( 'ct_checkjs', $_POST );
667
-
668
- $base_call_result = apbct_base_call(
669
- array(
670
- 'message' => $message,
671
- 'sender_email' => $sender_email,
672
- 'sender_nickname' => $sender_nickname,
673
- 'post_info' => array('comment_type' => 'contact_form_wordpress_formidable'),
674
- 'js_on' => $checkjs
675
- )
676
- );
677
- $ct_result = $base_call_result['ct_result'];
678
-
679
- if ($ct_result->allow == 0) {
680
- $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
681
- }
682
-
683
- return $errors;
 
 
 
684
  }
685
 
686
  /**
687
  * Public filter 'bbp_*' - Get new topic name to global $ct_bbp_topic
688
- * @param mixed[] $comment Comment string
 
 
689
  * @return mixed[] $comment Comment string
690
  * @psalm-suppress UnusedVariable
691
  */
692
- function ct_bbp_get_topic($topic){
693
- global $ct_bbp_topic;
 
694
 
695
- $ct_bbp_topic=$topic;
696
 
697
- return $topic;
698
  }
699
 
700
  /**
701
  * Public filter 'bbp_*' - Checks topics, replies by cleantalk
702
- * @param mixed[] $comment Comment string
 
 
703
  * @return mixed[] $comment Comment string
704
  * @psalm-suppress UndefinedFunction
705
  */
706
- function ct_bbp_new_pre_content ($comment) {
707
-
708
- global $apbct, $current_user;
709
-
710
- if ( !$apbct->settings['forms__comments_test']) {
711
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
712
- return $comment;
713
- }
714
 
715
- // Skip processing for logged in users and admin.
716
- if ( !$apbct->settings['data__protect_logged_in'] && ( is_user_logged_in() || apbct_exclusions_check() )) {
717
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
718
- return $comment;
719
- }
720
 
721
- $checkjs = apbct_js_test( 'ct_checkjs', $_COOKIE, true ) ?: apbct_js_test( 'ct_checkjs', $_POST );
 
722
 
723
- $post_info['comment_type'] = 'bbpress_comment';
724
- $post_info['post_url'] = bbp_get_topic_permalink();
 
725
 
726
- if( is_user_logged_in() ) {
727
- $sender_email = $current_user->user_email;
728
- $sender_nickname = $current_user->display_name;
729
- } else {
730
- $sender_email = isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null;
731
- $sender_nickname = isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null;
732
- }
733
 
734
- $base_call_result = apbct_base_call(
735
- array(
736
- 'message' => $comment,
737
- 'sender_email' => $sender_email,
738
- 'sender_nickname' => $sender_nickname,
739
- 'post_info' => $post_info,
740
- 'js_on' => $checkjs,
741
- 'sender_info' => array('sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null),
742
- )
743
- );
744
- $ct_result = $base_call_result['ct_result'];
745
 
746
- if ($ct_result->allow == 0) {
747
- bbp_add_error('bbp_reply_content', $ct_result->comment);
748
- }
749
 
750
- return $comment;
751
- }
 
 
 
 
 
752
 
753
- function apbct_comment__sanitize_data__before_wp_die($function){
 
 
 
 
 
 
 
 
 
 
754
 
755
- global $apbct;
 
 
756
 
757
- $comment_data = wp_unslash($_POST);
 
758
 
759
- $user_ID = 0;
 
 
760
 
761
- $comment_type = '';
762
 
763
- $comment_content = isset($comment_data['comment']) ? (string) $comment_data['comment'] : null;
764
- $comment_parent = isset($comment_data['comment_parent']) ? absint($comment_data['comment_parent']) : null;
765
 
766
- $comment_author = isset($comment_data['author']) ? trim(strip_tags($comment_data['author'])) : null;
767
- $comment_author_email = isset($comment_data['email']) ? trim($comment_data['email']) : null;
768
- $comment_author_url = isset($comment_data['url']) ? trim($comment_data['url']) : null;
769
- $comment_post_ID = isset($comment_data['comment_post_ID']) ? (int) $comment_data['comment_post_ID'] : null;
770
 
771
- if(isset($comment_content, $comment_parent)){
 
772
 
773
- $user = function_exists('apbct_wp_get_current_user') ? apbct_wp_get_current_user() : null;
 
 
 
774
 
775
- if($user && $user->exists()){
776
- $comment_author = empty($user->display_name) ? $user->user_login : $user->display_name;
777
- $comment_author_email = $user->user_email;
778
- $comment_author_url = $user->user_url;
779
- $user_ID = $user->ID;
780
- }
781
 
782
- $apbct->comment_data = compact(
783
- 'comment_post_ID',
784
- 'comment_author',
785
- 'comment_author_email',
786
- 'comment_author_url',
787
- 'comment_content',
788
- 'comment_type',
789
- 'comment_parent',
790
- 'user_ID'
791
- );
792
 
793
- $function = 'apbct_comment__check_via_wp_die';
 
 
 
 
 
 
 
 
 
794
 
795
- }
 
796
 
797
- return $function;
798
  }
799
 
800
- function apbct_comment__check_via_wp_die($message, $title, $args){
801
- global $apbct;
802
- if($title == __('Comment Submission Failure')){
803
- $apbct->validation_error = $message;
804
- ct_preprocess_comment($apbct->comment_data);
805
- }
806
- _default_wp_die_handler($message, $title, $args);
 
807
  }
808
 
809
  /**
810
  * Public filter 'preprocess_comment' - Checks comment by cleantalk server
811
- * @param mixed[] $comment Comment data array
812
- * @return mixed[] New data array of comment
 
 
813
  * @psalm-suppress UnusedVariable
814
  */
815
- function ct_preprocess_comment($comment) {
816
- // this action is called just when WP process POST request (adds new comment)
817
- // this action is called by wp-comments-post.php
818
- // after processing WP makes redirect to post page with comment's form by GET request (see above)
819
- global $current_user, $comment_post_id, $ct_comment_done, $ct_jp_comments, $apbct, $ct_comment, $ct_stop_words;
820
-
821
- // Send email notification for chosen groups of users
822
- if($apbct->settings['wp__comment_notify'] && !empty($apbct->settings['wp__comment_notify__roles']) && $apbct->data['moderate']){
823
-
824
- add_filter('notify_post_author', 'apbct_comment__Wordpress__doNotify', 100, 2);
825
-
826
- $users = get_users(array(
827
- 'role__in' => $apbct->settings['wp__comment_notify__roles'],
828
- 'fileds' => array('user_email')
829
- ));
830
-
831
- if($users){
832
- add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotificationGroups', 100, 2);
833
- add_filter('comment_notification_recipients', 'apbct_comment__Wordpress__changeMailNotificationRecipients', 100, 2);
834
- foreach($users as $user){
835
- $emails[] = $user->user_email;
836
- }
837
- $apbct->comment_notification_recipients = json_encode($emails);
838
- }
839
- }
840
-
841
- // Skip processing admin.
842
- if (in_array("administrator", $current_user->roles)){
843
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
844
- return $comment;
845
- }
846
-
847
- $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3;
848
-
849
- if($apbct->settings['comments__check_comments_number'] && $comment['comment_author_email']){
850
- $args = array(
851
- 'author_email' => $comment['comment_author_email'],
852
- 'status' => 'approve',
853
- 'count' => false,
854
- 'number' => $comments_check_number,
855
- );
856
- $cnt = count(get_comments($args));
857
- $is_max_comments = $cnt >= $comments_check_number ? true : false;
858
- }
859
-
860
- if (
861
- ($comment['comment_type']!=='trackback') &&
862
- (
863
- apbct_is_user_enable() === false ||
864
- $apbct->settings['forms__comments_test'] == 0 ||
865
- $ct_comment_done ||
866
- (isset($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'],'page=wysija_campaigns&action=editTemplate')!==false) ||
867
- (isset($is_max_comments) && $is_max_comments) ||
868
- (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['REQUEST_URI'],'/wp-admin/')!==false)
869
- )
870
- )
871
- {
872
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
873
- return $comment;
874
- }
875
-
876
- $local_blacklists = apbct_wp_blacklist_check(
877
- $comment['comment_author'],
878
- $comment['comment_author_email'],
879
- $comment['comment_author_url'],
880
- $comment['comment_content'],
881
- apbct_get_server_variable( 'REMOTE_ADDR' ),
882
- apbct_get_server_variable( 'HTTP_USER_AGENT' )
883
- );
884
-
885
- // Go out if author in local blacklists
886
- if ($comment['comment_type']!=='trackback' && $local_blacklists === true) {
887
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
888
- return $comment;
889
- }
890
-
891
- $ct_comment_done = true;
892
-
893
- $comment_post_id = $comment['comment_post_ID'];
894
-
895
- // JetPack comments logic
896
- $post_info['comment_type'] = $ct_jp_comments ? 'jetpack_comment' : $comment['comment_type'];
897
- $post_info['post_url'] = ct_post_url(null, $comment_post_id);
898
-
899
- // Comment type
900
- $post_info['comment_type'] = empty($post_info['comment_type']) ? 'general_comment' : $post_info['comment_type'];
901
-
902
- $checkjs = apbct_js_test( 'ct_checkjs', $_COOKIE, true ) ?: apbct_js_test( 'ct_checkjs', $_POST );
903
-
904
- $example = null;
905
- if ($apbct->data['relevance_test']) {
906
- $post = get_post($comment_post_id);
907
- if ($post !== null){
908
- $example['title'] = $post->post_title;
909
- $example['body'] = $post->post_content;
910
- $example['comments'] = null;
911
-
912
- $last_comments = get_comments(array('status' => 'approve', 'number' => 10, 'post_id' => $comment_post_id));
913
- foreach ($last_comments as $post_comment){
914
- $example['comments'] .= "\n\n" . $post_comment->comment_content;
915
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
916
 
917
- $example = json_encode($example);
918
- }
919
-
920
- // Use plain string format if've failed with JSON
921
- if ($example === false || $example === null){
922
- $example = ($post->post_title !== null) ? $post->post_title : '';
923
- $example .= ($post->post_content !== null) ? "\n\n" . $post->post_content : '';
924
- }
925
- }
926
-
927
- $base_call_data = array(
928
- 'message' => $comment['comment_content'],
929
- 'example' => $example,
930
- 'sender_email' => $comment['comment_author_email'],
931
- 'sender_nickname' => $comment['comment_author'],
932
- 'post_info' => $post_info,
933
- 'js_on' => $checkjs,
934
- 'sender_info' => array(
935
- 'sender_url' => @$comment['comment_author_url'],
936
- 'form_validation' => !isset($apbct->validation_error)
937
- ? null
938
- : json_encode(array(
939
- 'validation_notice' => $apbct->validation_error,
940
- 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
941
- ))
942
- )
943
- );
944
-
945
- /**
946
- * Add honeypot_field to $base_call_data is comments__hide_website_field on
947
- */
948
- if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
949
- $honeypot_field = 1;
950
-
951
- if(isset($_POST['url']) && !empty($_POST['url']) && $post_info['comment_type'] === 'comment' && isset($_POST['comment_post_ID'])) {
952
- $honeypot_field = 0;
953
- }
954
-
955
- $base_call_data['honeypot_field'] = $honeypot_field;
956
- }
957
-
958
- $base_call_result = apbct_base_call($base_call_data);
959
-
960
- $ct_result = $base_call_result['ct_result'];
961
-
962
- ct_hash($ct_result->id);
963
-
964
- //Don't check trusted users
965
- if (isset($comment['comment_author_email'])){
966
- $approved_comments = get_comments(array('status' => 'approve', 'count' => true, 'author_email' => $comment['comment_author_email']));
967
- $new_user = $approved_comments == 0 ? true : false;
968
- }
969
-
970
- // Change comment flow only for new authors
971
- if (!empty($new_user) || $ct_result->stop_words !== null || $ct_result->spam == 1) {
972
- add_action( 'comment_post', 'ct_set_meta', 10, 2 );
973
- }
974
-
975
- if($ct_result->allow){ // Pass if allowed
976
- if(get_option('comment_moderation') === '1') // Wordpress moderation flag
977
- {
978
- add_filter( 'pre_comment_approved', 'ct_set_not_approved', 999, 2 );
979
- } else {
980
- add_filter( 'pre_comment_approved', 'ct_set_approved', 999, 2 );
981
- }
982
- // Modify the email notification
983
- add_filter('comment_notification_text', 'apbct_comment__wordpress__show_blacklists', 100, 2); // Add two blacklist links: by email and IP
984
- }else{
985
-
986
- $ct_comment = $ct_result->comment;
987
- $ct_stop_words = $ct_result->stop_words;
988
-
989
- $err_text = '<center>' . ((defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE == true) ? '' : '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ') . __('Spam protection', 'cleantalk-spam-protect') . "</center><br><br>\n" . $ct_result->comment;
990
- if( ! $ct_jp_comments ) {
991
- $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
992
- }
993
-
994
- // Terminate. Definitely spam.
995
- if($ct_result->stop_queue == 1) {
996
- wp_die( $err_text, 'Blacklisted', array( 'response' => 200, 'back_link' => ! $ct_jp_comments ) );
997
- }
998
-
999
- // Terminate by user's setting.
1000
- if($ct_result->spam == 3) {
1001
- wp_die( $err_text, 'Blacklisted', array( 'response' => 200, 'back_link' => ! $ct_jp_comments ) );
1002
- }
1003
-
1004
- // Trash comment.
1005
- if($ct_result->spam == 2){
1006
- add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
1007
- add_action('comment_post', 'ct_wp_trash_comment', 997, 2);
1008
- }
1009
-
1010
- // Spam comment
1011
- if($ct_result->spam == 1)
1012
- add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
1013
-
1014
- // Move to pending folder. Contains stop_words.
1015
- if($ct_result->stop_words){
1016
- add_filter('pre_comment_approved', 'ct_set_not_approved', 998, 2);
1017
- add_action('comment_post', 'ct_mark_red', 998, 2);
1018
- }
1019
-
1020
- add_action('comment_post', 'ct_die', 999, 2);
1021
- }
1022
-
1023
- if($apbct->settings['comments__remove_comments_links'] == 1){
1024
- $comment['comment_content'] = preg_replace("~(http|https|ftp|ftps)://(.*?)(\s|\n|[,.?!](\s|\n)|$)~", '[Link deleted]', $comment['comment_content']);
1025
- }
1026
-
1027
- // Change mail notification if license is out of date
1028
- if($apbct->data['moderate'] == 0){
1029
- $apbct->sender_email = $comment['comment_author_email'];
1030
- $apbct->sender_ip = Helper::ip__get('real');
1031
- add_filter('comment_moderation_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment sent to moderation
1032
- add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment approved
1033
- }
1034
-
1035
- return $comment;
1036
  }
1037
 
1038
  /**
1039
  * Insert a hidden field to registration form
1040
  * @return null|bool
1041
  */
1042
- function ct_register_form() {
 
 
1043
 
1044
- global $ct_checkjs_register_form, $apbct;
 
 
1045
 
1046
- if ($apbct->settings['forms__registrations_test'] == 0) {
1047
- return false;
1048
- }
1049
 
1050
- ct_add_hidden_fields($ct_checkjs_register_form, false, false, false, false);
1051
-
1052
- return null;
1053
  }
1054
 
1055
  /**
1056
  * Adds notification text to login form - to inform about approved registration
1057
  * @return null
1058
  */
1059
- function ct_login_message($message) {
1060
-
1061
- global $errors, $apbct, $apbct_cookie_register_ok_label;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1062
 
1063
- if ($apbct->settings['forms__registrations_test'] != 0){
1064
- if( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ){
1065
- if (isset($_COOKIE[$apbct_cookie_register_ok_label])){
1066
- if(is_wp_error($errors)){
1067
- $errors->add('ct_message',sprintf(__('Registration approved by %s.', 'cleantalk-spam-protect'), '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk</b>'), 'message');
1068
- }
1069
- }
1070
- }
1071
- }
1072
- return $message;
1073
  }
1074
 
1075
 
@@ -1077,47 +1208,47 @@ function ct_login_message($message) {
1077
  * Test users registration for pPress
1078
  * @return void|WP_Error with errors
1079
  */
1080
- function ct_registration_errors_ppress($reg_errors, $_form_id) {
 
 
 
1081
 
1082
- $email = $_POST['reg_email'];
1083
- $login = $_POST['reg_username'];
1084
 
1085
- $reg_errors = ct_registration_errors($reg_errors, $login, $email);
1086
-
1087
- return $reg_errors;
1088
  }
1089
 
1090
  /**
1091
  * Test users registration for multisite environment
1092
  * @return array|mixed with errors
1093
  */
1094
- function ct_registration_errors_wpmu($errors) {
1095
-
1096
- // Multisite actions
1097
- $sanitized_user_login = null;
1098
- if (isset($errors['user_name'])) {
1099
- $sanitized_user_login = $errors['user_name'];
1100
- $wpmu = true;
1101
- }
1102
- $user_email = null;
1103
- if (isset($errors['user_email'])) {
1104
- $user_email = $errors['user_email'];
1105
- $wpmu = true;
1106
- }
1107
-
1108
- if ($wpmu && isset($errors['errors']->errors) && count($errors['errors']->errors) > 0) {
1109
- return $errors;
1110
- }
1111
-
1112
- $errors['errors'] = ct_registration_errors($errors['errors'], $sanitized_user_login, $user_email);
1113
-
1114
- // Show CleanTalk errors in user_name field
1115
- if (isset($errors['errors']->errors['ct_error'])) {
1116
- $errors['errors']->errors['user_name'] = $errors['errors']->errors['ct_error'];
1117
- unset($errors['errors']->errors['ct_error']);
1118
- }
1119
-
1120
- return $errors;
1121
  }
1122
 
1123
  /**
@@ -1129,8 +1260,9 @@ function ct_registration_errors_wpmu($errors) {
1129
  *
1130
  * @return void|WP_Error
1131
  */
1132
- function ct_register_post($sanitized_user_login, $user_email, $errors) {
1133
- return ct_registration_errors($errors, $sanitized_user_login, $user_email);
 
1134
  }
1135
 
1136
 
@@ -1138,60 +1270,61 @@ function ct_register_post($sanitized_user_login, $user_email, $errors) {
1138
  * Check messages for external plugins
1139
  * @return array with checking result;
1140
  */
1141
- function ct_test_message($nickname, $email, $_ip, $text){
1142
-
1143
- $base_call_result = apbct_base_call(
1144
- array(
1145
- 'message' => $text,
1146
- 'sender_email' => $email,
1147
- 'sender_nickname' => $nickname,
1148
- 'post_info' => array('comment_type' => 'feedback_plugin_check'),
1149
- 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
1150
- )
1151
- );
1152
-
1153
- $ct_result = $base_call_result['ct_result'];
1154
-
1155
- return array(
1156
- 'allow' => $ct_result->allow,
1157
- 'comment' => $ct_result->comment,
1158
- );
1159
  }
1160
 
1161
  /**
1162
  * Check registrations for external plugins
1163
  * @return array with checking result;
1164
  */
1165
- function ct_test_registration($nickname, $email, $ip = null){
1166
-
1167
- global $ct_checkjs_register_form;
1168
-
1169
- if(apbct_js_test($ct_checkjs_register_form, $_POST)){
1170
- $checkjs = apbct_js_test($ct_checkjs_register_form, $_POST);
1171
- $sender_info['post_checkjs_passed'] = $checkjs;
1172
- }else{
1173
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1174
- $sender_info['cookie_checkjs_passed'] = $checkjs;
1175
- }
1176
-
1177
- //Making a call
1178
- $base_call_result = apbct_base_call(
1179
- array(
1180
- 'sender_ip' => $ip,
1181
- 'sender_email' => $email,
1182
- 'sender_nickname' => $nickname,
1183
- 'sender_info' => $sender_info,
1184
- 'js_on' => $checkjs,
1185
- ),
1186
- true
1187
- );
1188
- $ct_result = $base_call_result['ct_result'];
1189
-
1190
- $result = array(
1191
- 'allow' => $ct_result->allow,
1192
- 'comment' => $ct_result->comment,
1193
- );
1194
- return $result;
 
1195
  }
1196
 
1197
  /**
@@ -1204,141 +1337,152 @@ function ct_test_registration($nickname, $email, $ip = null){
1204
  * @return void|WP_Error
1205
  * @psalm-suppress UnusedVariable
1206
  */
1207
- function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
1208
-
1209
- global $ct_checkjs_register_form, $apbct_cookie_request_id_label, $apbct_cookie_register_ok_label, $apbct_cookie_request_id, $bp, $ct_signup_done, $ct_negative_comment, $apbct, $ct_registration_error_comment, $cleantalk_executed;
1210
-
1211
- // Go out if a registered user action
1212
- if (apbct_is_user_enable() === false) {
1213
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1214
- return $errors;
1215
- }
1216
-
1217
- if ($apbct->settings['forms__registrations_test'] == 0) {
1218
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1219
- return $errors;
1220
- }
1221
-
1222
- // The function already executed
1223
- // It happens when used ct_register_post();
1224
- if ($ct_signup_done && is_object($errors) && count($errors->errors) > 0) {
1225
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1226
- return $errors;
1227
- }
1228
-
1229
- $facebook = false;
1230
- // Facebook registration
1231
- if ($sanitized_user_login === null && isset($_POST['FB_userdata'])){
1232
- $sanitized_user_login = $_POST['FB_userdata']['name'];
1233
- $facebook = true;
1234
- }
1235
- if ($user_email === null && isset($_POST['FB_userdata'])){
1236
- $user_email = $_POST['FB_userdata']['email'];
1237
- $facebook = true;
1238
- }
1239
-
1240
- // BuddyPress actions
1241
- $buddypress = false;
1242
- if ($sanitized_user_login === null && isset($_POST['signup_username'])) {
1243
- $sanitized_user_login = $_POST['signup_username'];
1244
- $buddypress = true;
1245
- }
1246
- if ($user_email === null && isset($_POST['signup_email'])) {
1247
- $user_email = $_POST['signup_email'];
1248
- $buddypress = true;
1249
- }
1250
-
1251
- // Break tests because we already have servers response
1252
- if ($buddypress && $ct_signup_done) {
1253
- if ($ct_negative_comment) {
1254
- $bp->signup->errors['signup_username'] = $ct_negative_comment;
1255
- }
1256
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1257
- return $errors;
1258
- }
1259
-
1260
-
1261
- if(current_filter() === 'woocommerce_registration_errors'){
1262
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1263
- $checkjs_post = null;
1264
- $checkjs_cookie = $checkjs;
1265
- }else{
1266
- // This hack can be helpful when plugin uses with untested themes&signups plugins.
1267
- $checkjs_post = apbct_js_test($ct_checkjs_register_form, $_POST);
1268
- $checkjs_cookie = apbct_js_test('ct_checkjs', $_COOKIE, true);
1269
- $checkjs = $checkjs_cookie ?: $checkjs_post;
1270
- }
1271
-
1272
- $sender_info = array(
1273
- 'post_checkjs_passed' => $checkjs_post,
1274
- 'cookie_checkjs_passed' => $checkjs_cookie,
1275
- 'form_validation' => ! empty( $errors )
1276
- ? json_encode( array(
1277
- 'validation_notice' => $errors->get_error_message(),
1278
- 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
1279
- ) )
1280
- : null,
1281
- );
1282
-
1283
- $base_call_result = apbct_base_call(
1284
- array(
1285
- 'sender_email' => $user_email,
1286
- 'sender_nickname' => $sanitized_user_login,
1287
- 'sender_info' => $sender_info,
1288
- 'js_on' => $checkjs,
1289
- ),
1290
- true
1291
- );
1292
- $ct_result = $base_call_result['ct_result'];
1293
-
1294
- // Change mail notification if license is out of date
1295
- if($apbct->data['moderate'] == 0 &&
1296
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1297
- ){
1298
- $apbct->sender_email = $user_email;
1299
- $apbct->sender_ip = Helper::ip__get('real');
1300
- add_filter('wp_new_user_notification_email_admin', 'apbct_registration__Wordpress__changeMailNotification', 100, 3);
1301
- }
1302
-
1303
- $ct_signup_done = true;
1304
-
1305
- $ct_result = ct_change_plugin_resonse($ct_result, $checkjs);
1306
-
1307
- $cleantalk_executed = true;
1308
-
1309
- if ($ct_result->inactive != 0) {
1310
- ct_send_error_notice($ct_result->comment);
1311
- return $errors;
1312
- }
1313
-
1314
- if ($ct_result->allow == 0) {
1315
-
1316
- if ($buddypress === true) {
1317
- $bp->signup->errors['signup_username'] = $ct_result->comment;
1318
- }elseif($facebook){
1319
- $_POST['FB_userdata']['email'] = '';
1320
- $_POST['FB_userdata']['name'] = '';
1321
- return;
1322
- }elseif(defined('MGM_PLUGIN_NAME')) {
1323
- ct_die_extended($ct_result->comment);
1324
- }else{
1325
- if(is_wp_error($errors)) {
1326
- $errors->add( 'ct_error', $ct_result->comment );
1327
- }
1328
- $ct_negative_comment = $ct_result->comment;
1329
- }
1330
-
1331
- $ct_registration_error_comment = $ct_result->comment;
 
 
 
 
 
 
 
 
 
 
1332
 
1333
- } else {
1334
- if ($ct_result->id !== null) {
1335
- $apbct_cookie_request_id = $ct_result->id;
1336
- Cookie::set($apbct_cookie_register_ok_label, $ct_result->id, time()+10, '/');
1337
- Cookie::set($apbct_cookie_request_id_label, $ct_result->id, time()+10, '/');
1338
- }
1339
- }
 
1340
 
1341
- return $errors;
1342
  }
1343
 
1344
  /**
@@ -1350,29 +1494,39 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
1350
  *
1351
  * @return array Body for email notification
1352
  */
1353
- function apbct_registration__Wordpress__changeMailNotification($wp_new_user_notification_email_admin, $_user, $_blogname){
1354
-
1355
- global $apbct;
1356
-
1357
- $wp_new_user_notification_email_admin['message'] = PHP_EOL
1358
- .__('CleanTalk AntiSpam: This registration is spam.', 'cleantalk-spam-protect')
1359
- ."\n" . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
1360
- ."\n" . 'IP: ' . $apbct->sender_ip
1361
- ."\n" . 'Email: ' . $apbct->sender_email
1362
- .PHP_EOL . PHP_EOL .
1363
- __('Activate protection in your Anti-Spam Dashboard: ', 'clentalk')
1364
- .'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wp_spam_registration_passed'
1365
- .($apbct->data['user_token']
1366
- ? '&iser_token='.$apbct->data['user_token']
1367
- : ''
1368
- )
1369
- .PHP_EOL . '---'
1370
- .PHP_EOL
1371
- .$wp_new_user_notification_email_admin['message'];
1372
-
1373
- return $wp_new_user_notification_email_admin;
1374
-
1375
-
 
 
 
 
 
 
 
 
 
 
1376
  }
1377
 
1378
  /**
@@ -1384,52 +1538,54 @@ function apbct_registration__Wordpress__changeMailNotification($wp_new_user_noti
1384
  * @psalm-suppress UndefinedFunction
1385
  * @psalm-suppress UnusedVariable
1386
  */
1387
- function apbct_registration__UltimateMembers__check( $args ){
 
 
 
 
 
 
 
1388
 
1389
- global $apbct, $cleantalk_executed;
 
1390
 
1391
- if ( isset( UM()->form()->errors ) ) {
1392
- $sender_info['previous_form_validation'] = true;
1393
- $sender_info['validation_notice'] = json_encode( UM()->form()->errors );
1394
- }
1395
 
1396
- if ($apbct->settings['forms__registrations_test'] == 0) {
1397
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1398
- return $args;
1399
- }
1400
 
1401
- $checkjs = apbct_js_test('ct_checkjs_register_form', $args);
1402
- $sender_info['post_checkjs_passed'] = $checkjs;
 
 
 
1403
 
1404
- // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1405
- if ($checkjs == 0) {
1406
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1407
- $sender_info['cookie_checkjs_passed'] = $checkjs;
1408
- }
 
 
 
 
 
1409
 
1410
- $base_call_result = apbct_base_call(
1411
- array(
1412
- 'sender_email' => $args['user_email'],
1413
- 'sender_nickname' => $args['user_login'],
1414
- 'sender_info' => $sender_info,
1415
- 'js_on' => $checkjs,
1416
- ),
1417
- true
1418
- );
1419
- $ct_result = $base_call_result['ct_result'];
1420
 
1421
- $cleantalk_executed = true;
 
1422
 
1423
- if ($ct_result->inactive != 0) {
1424
- ct_send_error_notice($ct_result->comment);
1425
- return $args;
1426
- }
1427
 
1428
- if ($ct_result->allow == 0) {
1429
- UM()->form()->add_error( 'user_password', $ct_result->comment );
1430
- }
1431
 
1432
- return $args;
1433
  }
1434
 
1435
  /**
@@ -1441,136 +1597,142 @@ function apbct_registration__UltimateMembers__check( $args ){
1441
  *
1442
  * @return mixed
1443
  */
1444
- function ct_check_registration_erros($errors, $_sanitized_user_login = null, $_user_email = null) {
1445
- global $bp, $ct_registration_error_comment;
1446
-
1447
- if($ct_registration_error_comment){
1448
-
1449
- if(isset($bp)) {
1450
- if ( method_exists( $bp, 'signup' ) ) {
1451
- if ( method_exists( $bp->signup, 'errors' ) ) {
1452
- if ( isset( $bp->signup->errors['signup_username'] ) ) {
1453
- if ( $bp->signup->errors['signup_username'] != $ct_registration_error_comment ) {
1454
- $bp->signup->errors['signup_username'] = $ct_registration_error_comment;
1455
- }
1456
- }
1457
- }
1458
- }
1459
- }
1460
-
1461
- if(isset($errors)) {
1462
- if ( method_exists( $errors, 'errors' ) ) {
1463
- if ( isset( $errors->errors['ct_error'] ) ) {
1464
- if ( $errors->errors['ct_error'][0] != $ct_registration_error_comment ) {
1465
- $errors->add( 'ct_error', $ct_registration_error_comment );
1466
- }
1467
- }
1468
- }
1469
- }
 
1470
 
1471
- }
1472
- return $errors;
1473
  }
1474
 
1475
 
1476
  /**
1477
  * Set user meta (ct_hash) for successes registration
1478
  */
1479
- function apbct_user_register($user_id) {
 
 
1480
 
1481
- global $apbct_cookie_request_id_label, $apbct_cookie_request_id;
 
1482
 
1483
- if ( ! empty( $apbct_cookie_request_id ) ) {
1484
- update_user_meta($user_id, 'ct_hash', $apbct_cookie_request_id);
1485
- return;
1486
- }
1487
 
1488
- if ( isset($_COOKIE[$apbct_cookie_request_id_label]) ) {
1489
- if(update_user_meta($user_id, 'ct_hash', $_COOKIE[$apbct_cookie_request_id_label])){
1490
- Cookie::set($apbct_cookie_request_id_label, '0', 1, '/');
1491
- }
1492
- }
1493
  }
1494
 
1495
 
1496
  /**
1497
  * Test for JetPack contact form
1498
  */
1499
- function ct_grunion_contact_form_field_html($r, $_field_label) {
1500
-
1501
- global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $apbct;
1502
-
1503
- if ($apbct->settings['forms__contact_forms_test'] == 1 && $ct_jpcf_patched === false && preg_match( "/(text|email)/i", $r)) {
1504
-
1505
- // Looking for element name prefix
1506
- $name_patched = false;
1507
- foreach ($ct_jpcf_fields as $v) {
1508
- if ($name_patched === false && preg_match("/(g\d-)$v/", $r, $matches)) {
1509
- $ct_checkjs_jpcf = $matches[1] . $ct_checkjs_jpcf;
1510
- $name_patched = true;
1511
- }
1512
- }
 
 
 
1513
 
1514
- $r .= ct_add_hidden_fields($ct_checkjs_jpcf, true);
1515
- $ct_jpcf_patched = true;
1516
- }
1517
 
1518
- return $r;
1519
  }
 
1520
  /**
1521
  * Test for JetPack contact form
1522
  * @psalm-suppress UnusedVariable
1523
  */
1524
- function ct_contact_form_is_spam($form) {
1525
-
1526
- global $ct_checkjs_jpcf, $apbct, $ct_comment;
1527
-
1528
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
1529
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1530
- return null;
1531
- }
1532
-
1533
- $js_field_name = $ct_checkjs_jpcf;
1534
- foreach ($_POST as $k => $_v) {
1535
- if (preg_match("/^.+$ct_checkjs_jpcf$/", $k)) {
1536
- $js_field_name = $k;
1537
- }
1538
- }
1539
-
1540
- $sender_email = null;
1541
- $sender_nickname = null;
1542
- $message = '';
1543
- if (isset($form['comment_author_email'])) {
1544
- $sender_email = $form['comment_author_email'];
1545
- }
1546
-
1547
- if (isset($form['comment_author'])) {
1548
- $sender_nickname = $form['comment_author'];
1549
- }
1550
-
1551
- if (isset($form['comment_content'])) {
1552
- $message = $form['comment_content'];
1553
- }
1554
-
1555
- $base_call_result = apbct_base_call(
1556
- array(
1557
- 'message' => $message,
1558
- 'sender_email' => $sender_email,
1559
- 'sender_nickname' => $sender_nickname,
1560
- 'post_info' => array('comment_type' => 'contact_form_wordpress_grunion'),
1561
- 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1562
- 'js_on' => apbct_js_test($js_field_name, $_POST),
1563
- )
1564
- );
1565
- $ct_result = $base_call_result['ct_result'];
1566
-
1567
- if ($ct_result->allow == 0) {
1568
- $ct_comment = $ct_result->comment;
1569
- ct_die(null, null);
1570
- exit;
1571
- }
1572
-
1573
- return ! $ct_result->allow;
 
1574
  }
1575
 
1576
  /**
@@ -1580,54 +1742,58 @@ function ct_contact_form_is_spam($form) {
1580
  * @return bool|null
1581
  * @psalm-suppress UnusedVariable
1582
  */
1583
- function ct_contact_form_is_spam_jetpack($_is_spam,$form) {
1584
- global $apbct, $ct_comment;
1585
-
1586
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
1587
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1588
- return null;
1589
- }
1590
-
1591
- $base_call_result = apbct_base_call(
1592
- array(
1593
- 'message' => isset($form['comment_content']) ? $form['comment_content'] : '',
1594
- 'sender_email' => isset($form['comment_author_email']) ? $form['comment_author_email'] : null,
1595
- 'sender_nickname' => isset($form['comment_author']) ? $form['comment_author'] : null,
1596
- 'post_info' => array('comment_type' => 'contact_form_wordpress_grunion'),
1597
- 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1598
- )
1599
- );
1600
- $ct_result = $base_call_result['ct_result'];
1601
-
1602
- if ($ct_result->allow == 0) {
1603
- $ct_comment = $ct_result->comment;
1604
- ct_die(null, null);
1605
- exit;
1606
- }
1607
-
1608
- return ! $ct_result->allow;
 
 
1609
  }
1610
 
1611
  /**
1612
  * Inserts anti-spam hidden to WP Maintenance Mode (wpmm)
1613
  */
1614
- function apbct_form__wpmm__addField(){
1615
- ct_add_hidden_fields('ct_checkjs', false, true, true);
 
1616
  }
1617
 
1618
  /**
1619
  * Inserts anti-spam hidden to CF7
1620
  */
1621
- function apbct_form__contactForm7__addField($html) {
1622
- global $ct_checkjs_cf7, $apbct;
 
1623
 
1624
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
1625
- return $html;
1626
- }
1627
 
1628
- $html .= ct_add_hidden_fields($ct_checkjs_cf7, true);
1629
 
1630
- return $html;
1631
  }
1632
 
1633
  /**
@@ -1638,95 +1804,95 @@ function apbct_form__contactForm7__addField($html) {
1638
  *
1639
  * @global State $apbct
1640
  */
1641
- function apbct_form__contactForm7__tesSpam__before_validate($result = null, $_tags = null) {
1642
- global $apbct;
1643
-
1644
- if ( $result && method_exists($result, 'get_invalid_fields') ){
1645
- $invalid_fields = $result->get_invalid_fields();
1646
- if(!empty($invalid_fields) && is_array($invalid_fields)){
1647
- $apbct->validation_error = $invalid_fields[key($invalid_fields)]['reason'];
1648
- apbct_form__contactForm7__testSpam( false );
1649
- }
1650
- }
 
1651
 
1652
- return $result;
1653
  }
1654
 
1655
  /**
1656
  * Test CF7 message for spam
1657
  * @psalm-suppress UnusedVariable
1658
  */
1659
- function apbct_form__contactForm7__testSpam( $spam, $_submission = null ) {
1660
-
1661
- global $ct_checkjs_cf7, $apbct, $ct_cf7_comment;
1662
-
1663
- if(
1664
- $apbct->settings['forms__contact_forms_test'] == 0 ||
1665
- ( $spam === false && defined( 'WPCF7_VERSION' ) && WPCF7_VERSION < '3.0.0' ) ||
1666
- ( $spam === true && defined( 'WPCF7_VERSION' ) && WPCF7_VERSION >= '3.0.0' ) ||
1667
- ( $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() ) || // Skip processing for logged in users.
1668
- apbct_exclusions_check__url() ||
1669
- apbct_exclusions_check__ip() ||
1670
- isset($apbct->cf7_checked)
1671
- ){
1672
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1673
- return $spam;
1674
- }
1675
-
1676
- $checkjs = apbct_js_test( $ct_checkjs_cf7, $_POST ) ?: apbct_js_test( 'ct_checkjs', $_COOKIE, true );
1677
-
1678
- $ct_temp_msg_data = ct_get_fields_any($_POST);
1679
-
1680
- $sender_email = $ct_temp_msg_data['email'] ?: '';
1681
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
1682
- $subject = $ct_temp_msg_data['subject'] ?: '';
1683
- $message = $ct_temp_msg_data['message'] ?: array();
1684
- if ($subject !== '') {
1685
- $message = array_merge(array('subject' => $subject), $message);
1686
- }
1687
-
1688
- $base_call_result = apbct_base_call(
1689
- array(
1690
- 'message' => $message,
1691
- 'sender_email' => $sender_email,
1692
- 'sender_nickname' => $sender_nickname,
1693
- 'js_on' => $checkjs,
1694
- 'post_info' => array('comment_type' => 'contact_form_wordpress_cf7'),
1695
- 'sender_info' => array(
1696
- 'form_validation' => !isset($apbct->validation_error)
1697
- ? null
1698
- : json_encode(array(
1699
- 'validation_notice' => $apbct->validation_error,
1700
- 'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
1701
- ))
1702
- ),
1703
- )
1704
- );
1705
-
1706
- $ct_result = $base_call_result['ct_result'];
1707
-
1708
- // Change mail notification if license is out of date
1709
- if($apbct->data['moderate'] == 0 &&
1710
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1711
- ){
1712
- $apbct->sender_email = $sender_email;
1713
- $apbct->sender_ip = Helper::ip__get();
1714
- add_filter('wpcf7_mail_components', 'apbct_form__contactForm7__changeMailNotification');
1715
- }
1716
-
1717
- if ($ct_result->allow == 0) {
1718
-
1719
- $ct_cf7_comment = $ct_result->comment;
1720
-
1721
- add_filter('wpcf7_display_message', 'apbct_form__contactForm7__showResponse', 10, 2);
1722
-
1723
- $spam = defined( 'WPCF7_VERSION' ) && WPCF7_VERSION >= '3.0.0';
1724
-
1725
- }
1726
-
1727
- $apbct->cf7_checked = true;
1728
-
1729
- return $spam;
1730
  }
1731
 
1732
  /**
@@ -1737,117 +1903,133 @@ function apbct_form__contactForm7__testSpam( $spam, $_submission = null ) {
1737
  *
1738
  * @return mixed|string
1739
  */
1740
- function apbct_form__contactForm7__showResponse($message, $status = 'spam') {
1741
- global $ct_cf7_comment;
 
1742
 
1743
- if ($status === 'spam') {
1744
- $message = $ct_cf7_comment;
1745
- }
1746
 
1747
- return $message;
1748
  }
1749
 
1750
  /**
1751
  * Changes email notification for success subscription for Contact Form 7
1752
  *
1753
  * @param array $component Arguments for email notification
 
1754
  * @return array Arguments for email notification
1755
  */
1756
- function apbct_form__contactForm7__changeMailNotification($component){
 
 
1757
 
1758
- global $apbct;
 
 
 
 
 
 
 
 
 
 
1759
 
1760
- $component['body'] =
1761
- __('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
1762
- .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
1763
- .PHP_EOL . 'IP: ' . $apbct->sender_ip
1764
- .PHP_EOL . 'Email: ' . $apbct->sender_email
1765
- .PHP_EOL . sprintf(
1766
- __('Activate protection in your Anti-Spam Dashboard: %s.', 'clentalk'),
1767
- 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=cf7_activate_antispam&user_token='.$apbct->user_token
1768
- )
1769
- .PHP_EOL . '---' . PHP_EOL . PHP_EOL
1770
- .$component['body'];
1771
-
1772
- return (array) $component;
1773
  }
1774
 
1775
  /**
1776
  * Test Ninja Forms message for spam
1777
  *
1778
- * @global State $apbct
1779
  * @return void
 
1780
  */
1781
- function apbct_form__ninjaForms__testSpam() {
1782
-
1783
- global $apbct, $cleantalk_executed;
1784
-
1785
- if( $cleantalk_executed ){
1786
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1787
- return;
1788
- }
1789
-
1790
- if(
1791
- $apbct->settings['forms__contact_forms_test'] == 0
1792
- || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
1793
- || apbct_exclusions_check__url()
1794
- ){
1795
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1796
- return;
1797
- }
1798
-
1799
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1800
-
1801
- // Choosing between POST and GET
1802
- $params = ct_get_fields_any(isset($_GET['ninja_forms_ajax_submit']) || isset($_GET['nf_ajax_submit']) ? $_GET : $_POST);
1803
-
1804
- $sender_email = $params['email'] ?: '';
1805
- $sender_nickname = $params['nickname'] ?: '';
1806
- $subject = $params['subject'] ?: '';
1807
- $message = $params['message'] ?: array();
1808
- if ($subject != '') {
1809
- $message = array_merge(array('subject' => $subject), $message);
1810
- }
1811
-
1812
- //Ninja Forms xml fix
1813
- foreach ($message as $key => $value){
1814
- if (strpos($value, '<xml>') !== false) {
1815
- unset( $message[ $key ] );
1816
- }
1817
- }
1818
-
1819
- $base_call_result = apbct_base_call(
1820
- array(
1821
- 'message' => $message,
1822
- 'sender_email' => $sender_email,
1823
- 'sender_nickname' => $sender_nickname,
1824
- 'post_info' => array('comment_type' => 'contact_form_wordpress_ninja_froms'),
1825
- 'js_on' => $checkjs,
1826
- )
1827
- );
1828
- $ct_result = $base_call_result['ct_result'];
1829
-
1830
- // Change mail notification if license is out of date
1831
- if($apbct->data['moderate'] == 0 &&
1832
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1833
- ){
1834
- $apbct->sender_email = $sender_email;
1835
- $apbct->sender_ip = Helper::ip__get('real');
1836
- add_filter('ninja_forms_action_email_message', 'apbct_form__ninjaForms__changeMailNotification', 1, 3);
1837
- }
1838
-
1839
- if ($ct_result->allow == 0) {
1840
-
1841
- // We have to use GLOBAL variable to transfer the comment to apbct_form__ninjaForms__changeResponse() function :(
1842
- $apbct->response = $ct_result->comment;
1843
- add_action( 'ninja_forms_before_response', 'apbct_form__ninjaForms__changeResponse', 10, 1 );
1844
- add_action( 'ninja_forms_action_email_send', 'apbct_form__ninjaForms__stopEmail', 1, 5 ); // Prevent mail notification
1845
- add_action( 'ninja_forms_save_submission', 'apbct_form__ninjaForms__preventSubmission', 1, 2 ); // Prevent mail notification
1846
- }
1847
- }
1848
-
1849
- function apbct_form__ninjaForms__preventSubmission($_some, $_form_id){
1850
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1851
  }
1852
 
1853
 
@@ -1860,199 +2042,203 @@ function apbct_form__ninjaForms__preventSubmission($_some, $_form_id){
1860
  *
1861
  * @throws Exception
1862
  */
1863
- function apbct_form__ninjaForms__stopEmail($_some, $_action_settings, $_message, $_headers, $_attachments){
1864
- global $apbct;
1865
- throw new Exception($apbct->response);
 
1866
  }
1867
 
1868
  /**
1869
  * @param $data
 
1870
  * @psalm-suppress InvalidArrayOffset
1871
  */
1872
- function apbct_form__ninjaForms__changeResponse( $data ) {
1873
-
1874
- global $apbct;
1875
-
1876
- // Show error message below field found by ID
1877
- if(array_key_exists('email', $data['fields_by_key'])){
1878
- // Find ID of EMAIL field
1879
- $nf_field_id = $data['fields_by_key']['email']['id'];
1880
- }else{
1881
- // Find ID of last field (usually SUBMIT)
1882
- $fields_keys = array_keys($data['fields']);
1883
- $nf_field_id = array_pop($fields_keys);
1884
- }
1885
 
1886
- // Below is modified NJ logic
1887
- $error = array(
1888
- 'fields' => array(
1889
- $nf_field_id => $apbct->response,
1890
- ),
1891
- );
 
 
 
1892
 
1893
- $response = array( 'data' => $data, 'errors' => $error, 'debug' => '' );
 
 
 
 
 
1894
 
1895
- die(wp_json_encode( $response, JSON_FORCE_OBJECT ));
1896
 
 
1897
  }
1898
 
1899
  /**
1900
  * @psalm-suppress UnusedVariable
1901
  */
1902
- function apbct_form__seedprod_coming_soon__testSpam() {
1903
-
1904
- global $apbct, $ct_comment;
1905
-
1906
- if(
1907
- $apbct->settings['forms__contact_forms_test'] == 0
1908
- || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
1909
- || apbct_exclusions_check__url()
1910
- ){
1911
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
1912
- return;
1913
- }
1914
-
1915
- $ct_temp_msg_data = ct_get_fields_any($_REQUEST);
1916
-
1917
- $sender_email = $ct_temp_msg_data['email'] ?: '';
1918
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
1919
- $subject = $ct_temp_msg_data['subject'] ?: '';
1920
- $message = $ct_temp_msg_data['message'] ?: array();
1921
- if ($subject != '') {
1922
- $message = array_merge(array('subject' => $subject), $message);
1923
- }
1924
-
1925
- $post_info['comment_type'] = 'contact_form_wordpress_seedprod_coming_soon';
1926
-
1927
- $base_call_result = apbct_base_call(
1928
- array(
1929
- 'message' => $message,
1930
- 'sender_email' => $sender_email,
1931
- 'sender_nickname' => $sender_nickname,
1932
- 'post_info' => $post_info,
1933
- )
1934
- );
1935
-
1936
- $ct_result = $base_call_result['ct_result'];
1937
- if ($ct_result->allow == 0) {
1938
- $ct_comment = $ct_result->comment;
1939
-
1940
- $response = array(
1941
- 'status' => 200,
1942
- 'html' => "<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>"
1943
- );
1944
-
1945
- echo sanitize_text_field($_GET['callback']) . '(' . json_encode($response) . ')';
1946
- exit();
1947
- }
1948
-
 
 
 
1949
  }
1950
 
1951
  /**
1952
  * Changes email notification for success subscription for Ninja Forms
1953
  *
1954
  * @param string $message Body of email notification
 
1955
  * @return string Body for email notification
1956
  */
1957
- function apbct_form__ninjaForms__changeMailNotification($message, $_data, $action_settings){
1958
-
1959
- global $apbct;
1960
-
1961
- if($action_settings['to'] !== $apbct->sender_email){
1962
-
1963
- $message .= wpautop(PHP_EOL . '---'
1964
- .PHP_EOL
1965
- .__('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
1966
- .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
1967
- .PHP_EOL . 'IP: ' . $apbct->sender_ip
1968
- .PHP_EOL . 'Email: ' . $apbct->sender_email
1969
- .PHP_EOL .
1970
- __('Activate protection in your Anti-Spam Dashboard: ', 'clentalk').
1971
- 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=ninjaform_activate_antispam'.$apbct->user_token
1972
- );
1973
- }
1974
-
1975
- return $message;
1976
  }
1977
 
1978
  /**
1979
  * Inserts anti-spam hidden to WPForms
1980
  *
1981
- * @global State $apbct
1982
  * @return void
 
1983
  */
1984
- function apbct_form__WPForms__addField($_form_data, $_some, $_title, $_description, $_errors) {
1985
-
1986
- global $apbct;
1987
-
1988
- if($apbct->settings['forms__contact_forms_test'] == 1) {
1989
- ct_add_hidden_fields( 'ct_checkjs_wpforms' );
1990
- }
1991
 
 
 
 
1992
  }
1993
 
1994
  /**
1995
  * Gather fields data from submission and store it
1996
  *
1997
- * @param array $entry
1998
  * @param $form
1999
  *
2000
  * @return array
2001
  * @global State $apbct
2002
  */
2003
- function apbct_from__WPForms__gatherData($entry, $form){
2004
-
2005
- global $apbct;
2006
- $handled_result = array();
2007
-
2008
- $entry_fields_data = $entry['fields'] ?: array();
2009
- $form_fields_info = $form['fields'] ?: array();
2010
-
2011
- foreach ($form_fields_info as $form_field) {
2012
- $field_id = $form_field['id'];
2013
- $field_type = $form_field['type'];
2014
- $field_label = $form_field['label'] ?: '';
2015
- if( ! isset( $entry_fields_data[$field_id] ) ){
2016
- continue;
2017
- }
2018
- $entry_field_value = $entry_fields_data[$field_id];
2019
-
2020
- # search email field
2021
- if($field_type === 'email') {
2022
- if( ! isset($handled_result['email']) || empty($handled_result['email'])) {
2023
- $handled_result['email'] = $entry_field_value;
2024
- continue;
2025
- }
2026
- }
2027
-
2028
- # search name
2029
- if($field_type === 'name') {
2030
- if(is_array($entry_field_value)) {
2031
- $handled_result['name'][] = implode(' ', array_slice($entry_field_value, 0, 3));
2032
- } else {
2033
- $handled_result['name'][] = array('nick' => $entry_field_value, 'first' => '', 'last' => '');
2034
- }
2035
- continue;
2036
- }
2037
-
2038
- # Add field label as key for result array
2039
- # add unique key if key exist
2040
- if($field_label) {
2041
- $field_label = mb_strtolower( trim( $field_label ) );
2042
- $field_label = str_replace(' ', '_', $field_label);
2043
- $field_label = preg_replace('/\W/u', '', $field_label);
2044
-
2045
- if( ! isset($handled_result[$field_label]) || empty($handled_result[$field_label])) {
2046
- $handled_result[$field_label] = $entry_field_value;
2047
- } else {
2048
- $handled_result[$field_label . rand(0, 100)] = $entry_field_value;
2049
- }
2050
- }
2051
- }
2052
 
2053
- $apbct->form_data = $handled_result;
2054
 
2055
- return $entry;
2056
  }
2057
 
2058
  /**
@@ -2061,25 +2247,27 @@ function apbct_from__WPForms__gatherData($entry, $form){
2061
  *
2062
  * @param array $errors
2063
  * @param array $form_data
 
2064
  * @return array
2065
  */
2066
- function apbct_form__WPForms__showResponse($errors, $form_data) {
2067
-
2068
- if(empty($errors) || ( isset($form_data['id'], $errors[$form_data['id']]) && !count($errors[$form_data['id']]) ) ){
2069
-
2070
- $spam_comment = apbct_form__WPForms__testSpam();
2071
-
2072
- $filed_id = $form_data && !empty($form_data['fields']) && is_array($form_data['fields'])
2073
- ? key($form_data['fields'])
2074
- : 0;
2075
-
2076
- if($spam_comment) {
2077
- $errors[ $form_data['id'] ][ $filed_id ] = $spam_comment;
2078
- }
2079
-
2080
- }
 
2081
 
2082
- return $errors;
2083
  }
2084
 
2085
  /**
@@ -2090,71 +2278,73 @@ function apbct_form__WPForms__showResponse($errors, $form_data) {
2090
  * @return string|void
2091
  * @global State $apbct
2092
  */
2093
- function apbct_form__WPForms__testSpam() {
2094
-
2095
- global $apbct;
2096
-
2097
- if(
2098
- $apbct->settings['forms__contact_forms_test'] == 0 ||
2099
- ( $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() ) // Skip processing for logged in users.
2100
- ){
2101
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2102
- return;
2103
- }
2104
-
2105
- $checkjs = apbct_js_test('ct_checkjs_wpforms', $_POST);
2106
-
2107
- $email = $apbct->form_data['email'] ?: null;
2108
- $nickname = $apbct->form_data['name'] && is_array( $apbct->form_data['name'] ) ? array_shift( $apbct->form_data['name'] ) : null;
2109
- $form_data = $apbct->form_data;
2110
-
2111
- if($email) {
2112
- unset($form_data['email']);
2113
- }
2114
- if($nickname) {
2115
- unset($form_data['name']);
2116
- }
2117
-
2118
- $params = ct_get_fields_any($apbct->form_data, $email, $nickname );
2119
-
2120
- if(is_array($params['nickname'])) {
2121
- $params['nickname'] = implode(' ', $params['nickname']);
2122
- }
2123
-
2124
- $sender_email = $params['email'] ?: '';
2125
- $sender_nickname = $params['nickname'] ?: '';
2126
- $subject = $params['subject'] ?: '';
2127
- $message = $params['message'] ?: array();
2128
- if ($subject !== '') {
2129
- $message = array_merge(array('subject' => $subject), $message);
2130
- }
2131
-
2132
- $base_call_result = apbct_base_call(
2133
- array(
2134
- 'message' => $message,
2135
- 'sender_email' => $sender_email,
2136
- 'sender_nickname' => $sender_nickname,
2137
- 'post_info' => array('comment_type' => 'contact_form_wordpress_wp_forms'),
2138
- 'js_on' => $checkjs,
2139
- )
2140
- );
2141
- $ct_result = $base_call_result['ct_result'];
2142
-
2143
- // Change mail notification if license is out of date
2144
- if($apbct->data['moderate'] == 0 &&
2145
- ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
2146
- ){
2147
- $apbct->sender_email = $sender_email;
2148
- $apbct->sender_ip = Helper::ip__get('real');
2149
- add_filter('wpforms_email_message', 'apbct_form__WPForms__changeMailNotification', 100, 2);
2150
- }
2151
-
2152
- if ($ct_result->allow == 0){
2153
- return $ct_result->comment;
2154
- }
2155
-
2156
- return null;
2157
-
 
 
2158
  }
2159
 
2160
  /**
@@ -2162,235 +2352,261 @@ function apbct_form__WPForms__testSpam() {
2162
  *
2163
  * @param string $message Body of email notification
2164
  * @param object $wpforms_email WPForms email class object
 
2165
  * @return string Body for email notification
2166
  */
2167
- function apbct_form__WPForms__changeMailNotification($message, $_wpforms_email){
2168
-
2169
- global $apbct;
2170
-
2171
- $message = str_replace( array( '</html>', '</body>' ), '', $message );
2172
- $message .= wpautop(PHP_EOL . '---'
2173
- .PHP_EOL
2174
- .__('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
2175
- .PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
2176
- .PHP_EOL . 'IP: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_ip . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_ip . '</a>'
2177
- .PHP_EOL . 'Email: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_email . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_email . '</a>'
2178
- .PHP_EOL . sprintf(
2179
- __('Activate protection in your %sAnti-Spam Dashboard%s.', 'clentalk'),
2180
- '<a href="https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_activate_antispam" target="_blank">',
2181
- '</a>'
2182
- ))
2183
- .'</body></html>';
2184
-
2185
- return $message;
2186
-
 
 
 
 
2187
  }
2188
 
2189
 
2190
  /**
2191
  * QuForms check spam
2192
- * works with single-paged forms
2193
- * and with multi-paged forms - check only last step of the forms
2194
  *
2195
  * @param $result
2196
  * @param $form
2197
  *
2198
  * @return mixed
2199
  */
2200
- function ct_quform_post_validate($result, $form) {
2201
-
2202
- if ( $form->hasPages() ) {
2203
- $comment_type = 'contact_form_wordpress_quforms_multipage';
2204
- } else {
2205
- $comment_type = 'contact_form_wordpress_quforms_singlepage';
2206
- }
2207
-
2208
- $ct_temp_msg_data = ct_get_fields_any( $form->getValues() );
2209
- // @ToDo If we have several emails at the form - will be used only the first detected!
2210
- $sender_email = $ct_temp_msg_data['email'] ?: '';
2211
-
2212
- $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
2213
- $base_call_result = apbct_base_call(
2214
- array(
2215
- 'message' => $form->getValues(),
2216
- 'sender_email' => $sender_email,
2217
- 'post_info' => array('comment_type' => $comment_type),
2218
- 'js_on' => $checkjs,
2219
- )
2220
- );
2221
-
2222
- $ct_result = $base_call_result['ct_result'];
2223
- if ($ct_result->allow == 0) {
2224
- die(json_encode(array('type' => 'error', 'apbct' => array('blocked' => true, 'comment' => $ct_result->comment)), JSON_HEX_QUOT | JSON_HEX_TAG));
2225
- }
2226
-
2227
- return $result;
2228
-
 
 
 
 
2229
  }
2230
 
2231
  /**
2232
  * Inserts anti-spam hidden to Fast Secure contact form
2233
  */
2234
- function ct_si_contact_display_after_fields($string = '', $_style = '', $_form_errors = array(), $_form_id_num = 0) {
2235
- $string .= ct_add_hidden_fields('ct_checkjs', true);
2236
- return $string;
 
 
2237
  }
2238
 
2239
  /**
2240
  * Test for Fast Secure contact form
2241
  * @psalm-suppress UnusedVariable
2242
  */
2243
- function ct_si_contact_form_validate($form_errors = array(), $_form_id_num = 0) {
2244
- global $apbct, $cleantalk_executed, $ct_comment;
2245
- if (!empty($form_errors)) {
2246
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2247
- return $form_errors;
2248
- }
2249
-
2250
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
2251
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2252
- return $form_errors;
2253
- }
2254
-
2255
- // Skip processing because data already processed.
2256
- if ($cleantalk_executed) {
2257
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2258
- return $form_errors;
2259
- }
2260
-
2261
- //getting info from custom fields
2262
- $ct_temp_msg_data = ct_get_fields_any($_POST);
2263
-
2264
- $sender_email = $ct_temp_msg_data['email'] ?: '';
2265
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2266
- $subject = $ct_temp_msg_data['subject'] ?: '';
2267
- $message = $ct_temp_msg_data['message'] ?: array();
2268
- if($subject !== '') {
2269
- $message['subject'] = $subject;
2270
- }
2271
-
2272
- $base_call_result = apbct_base_call(
2273
- array(
2274
- 'message' => $message,
2275
- 'sender_email' => $sender_email,
2276
- 'sender_nickname' => $sender_nickname,
2277
- 'post_info' => array('comment_type' => 'contact_form_wordpress_fscf'),
2278
- 'js_on' => apbct_js_test('ct_checkjs', $_POST),
2279
- )
2280
- );
2281
-
2282
- $ct_result = $base_call_result['ct_result'];
2283
-
2284
- $cleantalk_executed = true;
2285
-
2286
- if ($ct_result->allow == 0) {
2287
-
2288
- $ct_comment = $ct_result->comment;
2289
- ct_die(null, null);
2290
- exit;
2291
- }
2292
-
2293
- return $form_errors;
 
 
 
2294
  }
2295
 
2296
  /**
2297
  * Notice for commentators which comment has automatically approved by plugin
2298
- * @param string $hook URL of hooked page
 
2299
  */
2300
- function ct_comment_text($comment_text) {
2301
- global $comment, $ct_approved_request_id_label;
2302
-
2303
- if (isset($_COOKIE[$ct_approved_request_id_label]) && isset($comment->comment_ID)) {
2304
- $ct_hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
2305
-
2306
- if ($ct_hash !== '' && $_COOKIE[$ct_approved_request_id_label] == $ct_hash) {
2307
- $comment_text .= '<br /><br /> <em class="comment-awaiting-moderation">' . __('Comment approved. Anti-spam by CleanTalk.', 'cleantalk-spam-protect') . '</em>';
2308
- }
2309
- }
 
 
 
 
 
 
 
2310
 
2311
- return $comment_text;
2312
  }
2313
 
2314
 
2315
  /**
2316
  * Checks WordPress Landing Pages raw $_POST values
2317
  */
2318
- function ct_check_wplp(){
2319
-
2320
- global $ct_wplp_result_label, $apbct;
2321
-
2322
- if (!isset($_COOKIE[$ct_wplp_result_label])) {
2323
- // First AJAX submit of WPLP form
2324
- if ($apbct->settings['forms__contact_forms_test'] == 0) {
2325
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2326
- return;
2327
- }
2328
-
2329
- $sender_email = '';
2330
- foreach ($_POST as $v) {
2331
- if (preg_match("/^\S+@\S+\.\S+$/", $v)) {
2332
- $sender_email = $v;
2333
- break;
2334
- }
2335
- }
2336
-
2337
- $message = '';
2338
- if(array_key_exists('form_input_values', $_POST)){
2339
- $form_input_values = json_decode(stripslashes($_POST['form_input_values']), true);
2340
- if (is_array($form_input_values) && array_key_exists('null', $form_input_values))
2341
- $message = $form_input_values['null'];
2342
- } else if (array_key_exists('null', $_POST)) {
2343
- $message = $_POST['null'];
2344
- }
2345
-
2346
- $base_call_result = apbct_base_call(
2347
- array(
2348
- 'message' => $message,
2349
- 'sender_email' => $sender_email,
2350
- 'post_info' => array('comment_type' => 'contact_form_wordpress_wplp'),
2351
- )
2352
- );
2353
-
2354
- $ct_result = $base_call_result['ct_result'];
2355
-
2356
- if ($ct_result->allow == 0) {
2357
- $cleantalk_comment = $ct_result->comment;
2358
- } else {
2359
- $cleantalk_comment = 'OK';
2360
- }
2361
-
2362
- Cookie::set($ct_wplp_result_label, $cleantalk_comment, strtotime("+5 seconds"), '/');
2363
- } else {
2364
- // Next POST/AJAX submit(s) of same WPLP form
2365
- $cleantalk_comment = $_COOKIE[$ct_wplp_result_label];
2366
- }
2367
- if ($cleantalk_comment !== 'OK')
2368
- ct_die_extended($cleantalk_comment);
 
 
 
2369
  }
2370
 
2371
  /**
2372
  * Places a hiding field to Gravity forms.
2373
  * @return string
2374
  */
2375
- function apbct_form__gravityForms__addField($form_string, $form){
2376
- $ct_hidden_field = 'ct_checkjs';
 
2377
 
2378
- // Do not add a hidden field twice.
2379
- if (preg_match("/$ct_hidden_field/", $form_string)) {
2380
- return $form_string;
2381
- }
2382
 
2383
- $search = "</form>";
2384
 
2385
- // Adding JS code
2386
- $js_code = ct_add_hidden_fields($ct_hidden_field, true, false);
2387
- $form_string = str_replace($search, $js_code . $search, $form_string);
2388
 
2389
- // Adding field for multipage form. Look for cleantalk.php -> apbct_cookie();
2390
- $append_string = isset($form['lastPageButton']) ? "<input type='hidden' name='ct_multipage_form' value='yes'>" : '';
2391
- $form_string = str_replace($search, $append_string.$search, $form_string);
2392
 
2393
- return $form_string;
2394
  }
2395
 
2396
  /**
@@ -2398,326 +2614,338 @@ function apbct_form__gravityForms__addField($form_string, $form){
2398
  * @return boolean
2399
  * @psalm-suppress UnusedVariable
2400
  */
2401
- function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
2402
-
2403
- global $apbct, $cleantalk_executed, $ct_gform_is_spam, $ct_gform_response;
2404
-
2405
- if (
2406
- $is_spam ||
2407
- $apbct->settings['forms__contact_forms_test'] == 0 ||
2408
- $cleantalk_executed // Return unchanged result if the submission was already tested.
2409
- ) {
2410
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2411
- return $is_spam;
2412
- }
2413
-
2414
- $form_fields_for_ct = array();
2415
- $form_fields = (isset($form['fields'])) ? $form['fields'] : false;
2416
- $form_fields_intermediate = array();
2417
- $email = '';
2418
- $nickname = array();
2419
-
2420
- if($form_fields) {
2421
- foreach ($form_fields as $field) {
2422
- $field_id = $field['id'];
2423
- $field_visibility = $field['visibility'];
2424
- $field_type = $field['type'];
2425
- $field_inputs = $field['inputs'];
2426
-
2427
- if($field_inputs) {
2428
- foreach ($field_inputs as $input) {
2429
- $input_id = $input['id'];
2430
-
2431
- if(isset($entry[$input_id]) && $entry[$input_id]) {
2432
- $form_fields_intermediate[] = array(
2433
- 'f_name' => 'input_' . $input_id,
2434
- 'f_visibility' => $field_visibility,
2435
- 'f_type' => $field_type,
2436
- 'f_data' => $entry[$input_id]
2437
- );
2438
- $form_fields_for_ct['input_' . $input_id] = $entry[$input_id];
2439
- }
2440
- }
2441
- } else {
2442
- if(isset($entry[$field_id]) && $entry[$field_id]) {
2443
- $form_fields_intermediate[] = array(
2444
- 'f_name' => 'input_' . $field_id,
2445
- 'f_visibility' => $field_visibility,
2446
- 'f_type' => $field_type,
2447
- 'f_data' => $entry[$field_id]
2448
- );
2449
- $form_fields_for_ct['input_' . $field_id] = $entry[$field_id];
2450
- }
2451
- }
2452
- }
2453
- }
2454
-
2455
- # Search nickname and email
2456
- if($form_fields_intermediate) {
2457
- foreach ($form_fields_intermediate as $field) {
2458
- if($field['f_type'] === 'email') {
2459
- $email = $field['f_data'];
2460
- }
2461
-
2462
- if($field['f_type'] === 'name') {
2463
- $nickname[] = $field['f_data'];
2464
- }
2465
- }
2466
- }
 
2467
 
2468
- if(!$form_fields_for_ct) {
2469
- foreach($entry as $key => $value){
2470
- if(is_numeric($key)) {
2471
- $form_fields_for_ct[ 'input_' . $key ] = $value;
2472
- }
2473
- } unset($key, $value);
2474
- }
 
2475
 
2476
- $ct_temp_msg_data = ct_get_fields_any($form_fields_for_ct, $email, array_shift($nickname));
2477
 
2478
- $sender_email = $ct_temp_msg_data['email'] ?: '';
2479
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2480
- $subject = $ct_temp_msg_data['subject'] ?: '';
2481
- $message = $ct_temp_msg_data['message'] ?: array();
2482
 
2483
- if($subject !== '') {
2484
- $message['subject'] = $subject;
2485
- }
2486
 
2487
- $checkjs = apbct_js_test( 'ct_checkjs', $_POST ) ?: apbct_js_test( 'ct_checkjs', $_COOKIE, true );
2488
 
2489
- $base_call_result = apbct_base_call(
2490
- array(
2491
- 'message' => $message,
2492
- 'sender_email' => $sender_email,
2493
- 'sender_nickname' => $sender_nickname,
2494
- 'post_info' => array('comment_type' => 'contact_form_wordpress_gravity_forms'),
2495
- 'js_on' => $checkjs,
2496
- )
2497
- );
2498
 
2499
- $ct_result = $base_call_result['ct_result'];
2500
- if ($ct_result->allow == 0) {
2501
- $is_spam = true;
2502
- $ct_gform_is_spam = true;
2503
- $ct_gform_response = $ct_result->comment;
2504
- add_action( 'gform_entry_created', 'apbct_form__gravityForms__add_entry_note' );
2505
- }
2506
 
2507
- return $is_spam;
2508
  }
2509
 
2510
- function apbct_form__gravityForms__showResponse( $confirmation, $form, $_entry, $_ajax ){
 
 
2511
 
2512
- global $ct_gform_is_spam, $ct_gform_response;
 
 
2513
 
2514
- if(!empty($ct_gform_is_spam)){
2515
- $confirmation = '<a id="gf_'.$form['id'].'" class="gform_anchor" ></a><div id="gform_confirmation_wrapper_'.$form['id'].'" class="gform_confirmation_wrapper "><div id="gform_confirmation_message_'.$form['id'].'" class="gform_confirmation_message_'.$form['id'].' gform_confirmation_message"><font style="color: red">'.$ct_gform_response.'</font></div></div>';
2516
- }
2517
-
2518
- return $confirmation;
2519
  }
2520
 
2521
  /**
2522
  * Adds a note to the entry once the spam status is set (GF 2.4.18+).
2523
  *
2524
  * @param array $entry The entry that was created.
 
2525
  * @psalm-suppress UndefinedClass
2526
  * @psalm-suppress UndefinedFunction
2527
  */
2528
- function apbct_form__gravityForms__add_entry_note( $entry ) {
2529
- if ( rgar( $entry, 'status' ) !== 'spam' || ! method_exists( 'GFAPI', 'add_note' ) ) {
2530
- return;
2531
- }
2532
-
2533
- GFAPI::add_note( $entry['id'], 0, 'CleanTalk', __( 'This entry has been marked as spam.', 'cleantalk-spam-protect' ), 'cleantalk', 'success' );
 
 
 
 
 
 
 
 
2534
  }
2535
 
2536
  /**
2537
  * Test S2member registration
2538
  * @return bool|null with errors
2539
  */
2540
- function ct_s2member_registration_test($post_key) {
 
 
2541
 
2542
- global $apbct;
 
2543
 
2544
- if ($apbct->settings['forms__registrations_test'] == 0) {
2545
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2546
- return null;
2547
- }
2548
 
2549
- $sender_email = isset($_POST[$post_key]['email']) ? sanitize_email($_POST[$post_key]['email']) : null;
2550
- $sender_nickname = isset($_POST[$post_key]['username']) ? sanitize_email($_POST[$post_key]['username']) : null;
2551
 
2552
- //Making a call
2553
- $base_call_result = apbct_base_call(
2554
- array(
2555
- 'sender_email' => $sender_email,
2556
- 'sender_nickname' => $sender_nickname,
2557
- ),
2558
- true
2559
- );
2560
- $ct_result = $base_call_result['ct_result'];
2561
 
2562
- if ($ct_result->allow == 0) {
2563
- ct_die_extended($ct_result->comment);
2564
- }
2565
 
2566
- return true;
2567
  }
2568
 
2569
  /**
2570
  * @return false
2571
  * @psalm-suppress UnusedVariable
2572
  */
2573
- function apbct_form__the7_contact_form() {
2574
-
2575
- global $cleantalk_executed;
2576
-
2577
- if ( check_ajax_referer( 'dt_contact_form', 'nonce', false ) && ! empty($_POST) ) {
2578
-
2579
- $post_info['comment_type'] = 'contact_the7_theme_contact_form';
2580
-
2581
- $ct_temp_msg_data = ct_get_fields_any($_POST);
2582
-
2583
- $sender_email = $ct_temp_msg_data['email'] ?: '';
2584
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2585
- $subject = $ct_temp_msg_data['subject'] ?: '';
2586
- $contact_form = ! $ct_temp_msg_data['contact'];
2587
- $message = $ct_temp_msg_data['message'] ?: array();
2588
- if ($subject !== '') {
2589
- $message = array_merge(array('subject' => $subject), $message);
2590
- }
2591
-
2592
- // Skip submission if no data found
2593
- if ( $sender_email === ''|| ! $contact_form ) {
2594
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2595
- return false;
2596
- }
2597
- $cleantalk_executed = true;
2598
-
2599
- $base_call_result = apbct_base_call(
2600
- array(
2601
- 'message' => $message,
2602
- 'sender_email' => $sender_email,
2603
- 'sender_nickname' => $sender_nickname,
2604
- 'post_info' => $post_info,
2605
- )
2606
- );
2607
-
2608
- $ct_result = $base_call_result['ct_result'];
2609
- if ($ct_result->allow == 0) {
2610
-
2611
- $response = json_encode(
2612
- array(
2613
- 'success' => false ,
2614
- 'errors' => $ct_result->comment,
2615
- 'nonce' => wp_create_nonce( 'dt_contact_form' )
2616
- )
2617
- );
2618
-
2619
- // response output
2620
- header( "Content-Type: application/json" );
2621
- echo $response;
2622
-
2623
- // IMPORTANT: don't forget to "exit"
2624
- exit;
2625
 
2626
- }
 
 
2627
 
2628
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2629
 
2630
- return false;
2631
  }
2632
 
2633
- function apbct_form__elementor_pro__testSpam() {
 
 
2634
 
2635
- global $apbct;
 
 
 
 
 
2636
 
2637
- if(
2638
- $apbct->settings['forms__contact_forms_test'] == 0
2639
- || ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
2640
- || apbct_exclusions_check__url()
2641
- ){
2642
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2643
- return;
2644
- }
2645
 
2646
- $ct_temp_msg_data = ct_get_fields_any($_POST);
2647
 
2648
- $sender_email = $ct_temp_msg_data['email'] ?: '';
2649
- $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2650
- $subject = $ct_temp_msg_data['subject'] ?: '';
2651
- $message = $ct_temp_msg_data['message'] ?: array();
2652
- if ($subject !== '') {
2653
- $message = array_merge(array('subject' => $subject), $message);
2654
- }
2655
 
2656
- $post_info['comment_type'] = 'contact_form_wordpress_elementor_pro';
2657
 
2658
- $base_call_result = apbct_base_call(
2659
- array(
2660
- 'message' => $message,
2661
- 'sender_email' => $sender_email,
2662
- 'sender_nickname' => $sender_nickname,
2663
- 'post_info' => $post_info,
2664
- )
2665
- );
2666
 
2667
- $ct_result = $base_call_result['ct_result'];
2668
-
2669
- if ($ct_result->allow == 0) {
2670
-
2671
- wp_send_json_error( array(
2672
- 'message' => $ct_result->comment,
2673
- 'data' => array()
2674
- ) );
2675
-
2676
- }
2677
 
 
 
 
 
 
 
2678
  }
2679
 
2680
  // INEVIO theme integration
2681
- function apbct_form__inevio__testSpam() {
2682
-
2683
- global $apbct;
2684
-
2685
- $theme = wp_get_theme();
2686
- if(
2687
- stripos( $theme->get( 'Name' ), 'INEVIO' ) === false ||
2688
- $apbct->settings['forms__contact_forms_test'] == 0 ||
2689
- ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
2690
- apbct_exclusions_check__url()
2691
- ) {
2692
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
2693
- return false;
2694
- }
2695
- $form_data = array();
2696
- parse_str($_POST['data'], $form_data);
2697
-
2698
- $name = isset($form_data['name']) ? $form_data['name'] : '';
2699
- $email = isset($form_data['email']) ? $form_data['email'] : '';
2700
- $message = isset($form_data['message']) ? $form_data['message'] : '';
2701
-
2702
- $post_info['comment_type'] = 'contact_form_wordpress_inevio_theme';
2703
-
2704
- $base_call_result = apbct_base_call(
2705
- array(
2706
- 'message' => $message,
2707
- 'sender_email' => $email,
2708
- 'sender_nickname' => $name,
2709
- 'post_info' => $post_info,
2710
- )
2711
- );
2712
-
2713
- $ct_result = $base_call_result['ct_result'];
2714
-
2715
- if ( $ct_result->allow == 0 ) {
2716
- die(json_encode(array('apbct' => array('blocked' => true, 'comment' => $ct_result->comment,)), JSON_HEX_QUOT | JSON_HEX_TAG));
2717
- }
2718
-
2719
- return true;
2720
-
 
 
 
 
 
2721
  }
2722
 
2723
 
@@ -2727,14 +2955,17 @@ function apbct_form__inevio__testSpam() {
2727
  *
2728
  * @param $success array array( 'status' => 'success' )
2729
  * @param $data array ['username'] ['password'] ['email']
 
2730
  * @return array array( 'status' => 'error' ) or array( 'status' => 'success' ) by default
2731
  */
2732
- function apbct_wilcity_reg_validation( $success, $data ) {
2733
- $check = ct_test_registration( $data['username'], $data['email'], '' );
2734
- if( $check['allow'] == 0 ) {
2735
- return array( 'status' => 'error' );
2736
- }
2737
- return $success;
 
 
2738
  }
2739
 
2740
  /**
@@ -2748,39 +2979,39 @@ function apbct_wilcity_reg_validation( $success, $data ) {
2748
  * @return mixed|null
2749
  * @psalm-suppress UnusedVariable
2750
  */
2751
- function apbct_form__enfold_contact_form__test_spam( $send, $new_post, $_form_params, $obj ){
 
 
2752
 
2753
- global $cleantalk_executed;
 
 
 
2754
 
2755
- $url_decoded_data = array();
2756
- foreach( $new_post as $key => $value ) {
2757
- $url_decoded_data[$key] = urldecode($value);
2758
- }
2759
 
2760
- $data = ct_get_fields_any( $url_decoded_data );
 
 
 
 
 
 
 
 
 
2761
 
2762
- $base_call_result = apbct_base_call(
2763
- array(
2764
- 'message' => !empty( $data['message'] ) ? json_encode( $data['message'] ) : '',
2765
- 'sender_email' => !empty( $data['email'] ) ? $data['email'] : '',
2766
- 'sender_nickname' => !empty( $data['nickname'] ) ? $data['nickname'] : '',
2767
- 'post_info' => array(
2768
- 'comment_type' => 'contact_form_wordpress_enfold'
2769
- ),
2770
- )
2771
- );
2772
 
2773
- $ct_result = $base_call_result['ct_result'];
2774
 
2775
- $cleantalk_executed = true;
 
2776
 
2777
- if( $ct_result->allow == 0 ) {
2778
- $obj->submit_error = $ct_result->comment;
2779
- return null;
2780
- }
2781
-
2782
- return $send;
2783
 
 
2784
  }
2785
 
2786
  /**
@@ -2793,46 +3024,46 @@ function apbct_form__enfold_contact_form__test_spam( $send, $new_post, $_form_pa
2793
  * @return mixed
2794
  * @psalm-suppress UnusedVariable
2795
  */
2796
- function apbct_form_profile_builder__check_register ( $errors, $_fields, $global_request ){
2797
-
2798
- global $cleantalk_executed;
2799
-
2800
- if( isset( $global_request['action'] ) && $global_request['action'] === 'register' ) {
2801
-
2802
- $data = ct_get_fields_any( $global_request );
2803
-
2804
- $base_call_result = apbct_base_call(
2805
- array(
2806
- 'message' => !empty( $data['message'] ) ? json_encode( $data['message'] ) : '',
2807
- 'sender_email' => !empty( $data['email'] ) ? $data['email'] : '',
2808
- 'sender_nickname' => !empty( $data['nickname'] ) ? $data['nickname'] : '',
2809
- 'post_info' => array(
2810
- 'comment_type' => 'register_profile_builder'
2811
- ),
2812
- ), true
2813
- );
2814
-
2815
- $ct_result = $base_call_result['ct_result'];
2816
-
2817
- $cleantalk_executed = true;
2818
-
2819
- if( $ct_result->allow == 0 ) {
2820
- $errors['error'] = $ct_result->comment;
2821
- $GLOBALS['global_profile_builder_error'] = $ct_result->comment;
2822
-
2823
- add_filter( 'wppb_general_top_error_message', 'apbct_form_profile_builder__error_message', 1 );
2824
- }
2825
-
2826
- }
2827
- return $errors;
2828
 
 
2829
  }
2830
 
2831
  /**
2832
  * Profile Builder Integration - add error message in response
2833
  */
2834
- function apbct_form_profile_builder__error_message() {
2835
- return '<p id="wppb_form_general_message" class="wppb-error">'. $GLOBALS['global_profile_builder_error'] .'</p>';
 
2836
  }
2837
 
2838
  /**
@@ -2843,30 +3074,32 @@ function apbct_form_profile_builder__error_message() {
2843
  * @return array|mixed
2844
  * @psalm-suppress UnusedVariable
2845
  */
2846
- function wpforo_create_profile__check_register( $user_fields ) {
 
 
2847
 
2848
- global $ct_signup_done;
 
 
 
 
2849
 
2850
- $ip = Helper::ip__get( 'real', false );
2851
- $check = ct_test_registration( $user_fields['user_login'], $user_fields['user_email'], $ip );
2852
- if( $check['allow'] == 0 ) {
2853
- return array( 'error' => $check['comment'] );
2854
- }
2855
 
2856
- $ct_signup_done = true;
2857
- return $user_fields;
2858
  }
2859
 
2860
  /**
2861
  * Function checks for signs in the post request to perform validation and returns true|false
2862
  */
2863
- function apbct_custom_forms_trappings() {
2864
- global $apbct;
 
2865
 
2866
- // Registration form of Wishlist Members plugin
2867
- if($apbct->settings['forms__registrations_test'] && isset($_POST['action']) && $_POST['action'] === 'wpm_register') {
2868
- return true;
2869
- }
2870
 
2871
- return false;
2872
- }
7
  use Cleantalk\Variables\Server;
8
 
9
  // MailChimp Premium for Wordpress
10
+ function ct_add_mc4wp_error_message($messages)
11
+ {
12
+ $messages['ct_mc4wp_response'] = array(
13
+ 'type' => 'error',
14
+ 'text' => 'Your message looks like spam.'
15
+ );
16
 
17
+ return $messages;
 
 
 
 
18
  }
19
+
20
+ add_filter('mc4wp_form_messages', 'ct_add_mc4wp_error_message');
21
 
22
  /**
23
  * Function to set validate function for CCF form
24
  * Input - Consistently each form field
25
  * Returns - String. Validate function
26
+ */
27
+ function ct_ccf($_callback, $_value, $_field_id, $_type)
28
+ {
29
+ return 'ct_validate_ccf_submission';
30
  }
31
 
32
  $ct_global_temporary_data = array();
42
  * @return bool|string|null
43
  * @psalm-suppress InvalidArrayOffset
44
  */
45
+ function ct_validate_ccf_submission($value, $_field_id, $_required)
46
+ {
47
+ global $ct_global_temporary_data, $apbct;
48
+
49
+ //If the check for contact forms enabled
50
+ if ( ! $apbct->settings['forms__contact_forms_test'] ) {
51
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
52
+
53
+ return true;
54
+ }
55
+
56
+ //If the check for logged in users enabled
57
+ if ( $apbct->settings['data__protect_logged_in'] == 1 && is_user_logged_in() ) {
58
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
59
+
60
+ return true;
61
+ }
62
+
63
+ //Accumulate data
64
+ $ct_global_temporary_data[] = $value;
65
+
66
+ //If it's the last field of the form
67
+ (! isset($ct_global_temporary_data['count']) ? $ct_global_temporary_data['count'] = 1 : $ct_global_temporary_data['count']++);
68
+ $form_id = $_POST['form_id'];
69
+ if ( $ct_global_temporary_data['count'] != count(get_post_meta($form_id, 'ccf_attached_fields', true)) ) {
70
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
71
+
72
+ return true;
73
+ }
74
+
75
+ unset($ct_global_temporary_data['count']);
76
+
77
+ //Getting request params
78
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
79
+
80
+ unset($ct_global_temporary_data);
81
+
82
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
83
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
84
+ $subject = $ct_temp_msg_data['subject'] ?: '';
85
+ $message = $ct_temp_msg_data['message'] ?: array();
86
+
87
+ if ( $subject !== '' ) {
88
+ $message['subject'] = $subject;
89
+ }
90
+
91
+ $post_info['comment_type'] = 'feedback_custom_contact_forms';
92
+ $post_info['post_url'] = apbct_get_server_variable('HTTP_REFERER');
93
+
94
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true) ?: apbct_js_test('ct_checkjs', $_POST);
95
+
96
+ //Making a call
97
+ $base_call_result = apbct_base_call(
98
+ array(
99
+ 'message' => $message,
100
+ 'sender_email' => $sender_email,
101
+ 'sender_nickname' => $sender_nickname,
102
+ 'post_info' => $post_info,
103
+ 'js_on' => $checkjs,
104
+ 'sender_info' => array('sender_url' => null),
105
+ )
106
+ );
107
+
108
+ $ct_result = $base_call_result['ct_result'];
109
+
110
+ return $ct_result->allow == 0 ? $ct_result->comment : true;
111
+ }
112
+
113
+ function ct_woocommerce_wishlist_check($args)
114
+ {
115
+ global $apbct;
116
+
117
+ //Protect logged in users
118
+ if ( $args['wishlist_status'] ) {
119
+ if ( $apbct->settings['data__protect_logged_in'] == 0 ) {
120
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
121
+
122
+ return $args;
123
+ }
124
+ }
125
+
126
+ //If the IP is a Google bot
127
+ $hostname = gethostbyaddr(apbct_get_server_variable('REMOTE_ADDR'));
128
+ if ( ! strpos($hostname, 'googlebot.com') ) {
129
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
130
+
131
+ return $args;
132
+ }
133
+
134
+ //Getting request params
135
+ $message = '';
136
+ $subject = '';
137
+ $email = $args['wishlist_owner_email'];
138
+ if ( $args['wishlist_first_name'] !== '' || $args['wishlist_last_name'] !== '' ) {
139
+ $nickname = trim($args['wishlist_first_name'] . " " . $args['wishlist_last_name']);
140
+ } else {
141
+ $nickname = '';
142
+ }
143
+
144
+ $post_info['comment_type'] = 'feedback';
145
+ $post_info['post_url'] = apbct_get_server_variable('HTTP_REFERER');
146
+
147
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true) ?: apbct_js_test('ct_checkjs', $_POST);
148
+
149
+ //Making a call
150
+ $base_call_result = apbct_base_call(
151
+ array(
152
+ 'message' => $subject . " " . $message,
153
+ 'sender_email' => $email,
154
+ 'sender_nickname' => $nickname,
155
+ 'post_info' => $post_info,
156
+ 'js_on' => $checkjs,
157
+ 'sender_info' => array('sender_url' => null),
158
+ )
159
+ );
160
+
161
+ $ct_result = $base_call_result['ct_result'];
162
+
163
+ if ( $ct_result->allow == 0 ) {
164
+ wp_die(
165
+ "<h1>"
166
+ . __('Spam protection by CleanTalk', 'cleantalk-spam-protect')
167
+ . "</h1><h2>" . $ct_result->comment . "</h2>",
168
+ '',
169
+ array(
170
+ 'response' => 403,
171
+ "back_link" => true,
172
+ "text_direction" => 'ltr'
173
+ )
174
+ );
175
+ } else {
176
+ return $args;
177
+ }
178
+ }
179
+
180
+ function apbct_integration__buddyPres__getTemplateName(
181
+ $located,
182
+ $_template_name,
183
+ $_template_names,
184
+ $_template_locations,
185
+ $_load,
186
+ $_require_once
187
+ ) {
188
+ global $apbct;
189
+ preg_match("/\/([a-z-_]+)\/buddypress-functions\.php$/", $located, $matches);
190
+ $apbct->buddy_press_tmpl = isset($matches[1]) ? $matches[1] : 'unknown';
191
  }
192
 
193
  /**
194
  * Test BuddyPress activity for spam (post update only)
195
  *
 
196
  * @param bool $is_spam
197
  * @param object $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
198
+ *
199
  * @return boolean Spam flag
200
  * @psalm-suppress UnusedVariable
201
+ * @global State $apbct
202
  */
203
+ function apbct_integration__buddyPres__activityWall($is_spam, $activity_obj = null)
204
+ {
205
+ global $apbct;
206
+
207
+ $allowed_post_actions = array('post_update', 'new_activity_comment');
208
+
209
+ if ( ! in_array(Post::get('action'), $allowed_post_actions) ||
210
+ $activity_obj === null ||
211
+ ! Post::get('action') ||
212
+ $activity_obj->privacy == 'media' ||
213
+ apbct_exclusions_check()
214
+ ) {
215
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
216
+
217
+ return false;
218
+ }
219
+
220
+ $curr_user = get_user_by('id', $activity_obj->user_id);
221
+
222
+ //Making a call
223
+ $base_call_result = apbct_base_call(
224
+ array(
225
+ 'message' => is_string($activity_obj->content) ? $activity_obj->content : '',
226
+ 'sender_email' => $curr_user->data->user_email,
227
+ 'sender_nickname' => $curr_user->data->user_login,
228
+ 'post_info' => array(
229
+ 'post_url' => apbct_get_server_variable('HTTP_REFERER'),
230
+ 'comment_type' => 'buddypress_activitywall',
231
+ ),
232
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
233
+ 'sender_info' => array('sender_url' => null),
234
+ )
235
+ );
236
+
237
+ $ct_result = $base_call_result['ct_result'];
238
+
239
+ if ( $ct_result->allow == 0 ) {
240
+ add_action('bp_activity_after_save', 'apbct_integration__buddyPres__activityWall_showResponse', 1, 1);
241
+ $apbct->spam_notification = $ct_result->comment;
242
+
243
+ return true;
244
+ } else {
245
+ return $is_spam;
246
+ }
247
  }
248
 
249
  /**
250
  * Outputs message to AJAX frontend handler
251
  *
 
252
  * @param object $activity_obj Activity object (\plugins\buddypress\bp-activity\classes\class-bp-activity-activity.php)
253
+ *
254
+ * @global State $apbct
255
  */
256
+ function apbct_integration__buddyPres__activityWall_showResponse($_activity_obj)
257
+ {
258
+ global $apbct;
259
+
260
+ // Legacy template
261
+ if ( $apbct->buddy_press_tmpl === 'bp-legacy' ) {
262
+ die('<div id="message" class="error bp-ajax-message"><p>' . $apbct->spam_notification . '</p></div>');
263
+ // Nouveau template and others
264
+ } else {
265
+ @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
266
+ die(
267
+ json_encode(
268
+ array(
269
+ 'success' => false,
270
+ 'data' => array('message' => $apbct->spam_notification),
271
+ )
272
+ )
273
+ );
274
+ }
275
  }
276
 
277
  /**
278
  * Public function - Tests new private messages (dialogs)
279
  *
 
280
  * @param object $bp_message_obj
281
+ *
282
  * @return void with errors if spam has found
283
  * @psalm-suppress UndefinedClass
284
  * @psalm-suppress UnusedVariable
285
+ * @global State $apbct
286
  */
287
+ function apbct_integration__buddyPres__private_msg_check($bp_message_obj)
288
+ {
289
+ global $apbct;
290
+
291
+ //Check for enabled option
292
+ if (
293
+ $apbct->settings['comments__bp_private_messages'] == 0 ||
294
+ apbct_exclusions_check()
295
+ ) {
296
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
297
+
298
+ return;
299
+ }
300
+
301
+ //Check for quantity of comments
302
+ $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER')
303
+ ? CLEANTALK_CHECK_COMMENTS_NUMBER
304
+ : 3;
305
+
306
+ if ( $apbct->settings['comments__check_comments_number'] ) {
307
+ $args = array(
308
+ 'user_id' => $bp_message_obj->sender_id,
309
+ 'box' => 'sentbox',
310
+ 'type' => 'all',
311
+ 'limit' => $comments_check_number,
312
+ 'page' => null,
313
+ 'search_terms' => '',
314
+ 'meta_query' => array()
315
+ );
316
+ $sentbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
317
+ $cnt_sentbox_msgs = $sentbox_msgs['total'];
318
+ $args['box'] = 'inbox';
319
+ $inbox_msgs = BP_Messages_Thread::get_current_threads_for_user($args);
320
+ $cnt_inbox_msgs = $inbox_msgs['total'];
321
+
322
+ if ( ($cnt_inbox_msgs + $cnt_sentbox_msgs) >= $comments_check_number ) {
323
+ $is_max_comments = true;
324
+ }
325
+ }
326
+
327
+ if ( ! empty($is_max_comments) ) {
328
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
329
+
330
+ return;
331
+ }
332
+
333
+ $sender_user_obj = get_user_by('id', $bp_message_obj->sender_id);
334
+
335
+ //Making a call
336
+ $base_call_result = apbct_base_call(
337
+ array(
338
+ 'message' => $bp_message_obj->subject . " " . $bp_message_obj->message,
339
+ 'sender_email' => $sender_user_obj->data->user_email,
340
+ 'sender_nickname' => $sender_user_obj->data->user_login,
341
+ 'post_info' => array(
342
+ 'comment_type' => 'buddypress_comment',
343
+ 'post_url' => apbct_get_server_variable('HTTP_REFERER'),
344
+ ),
345
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true) ?: apbct_js_test('ct_checkjs', $_POST),
346
+ 'sender_info' => array('sender_url' => null),
347
+ )
348
+ );
349
+
350
+ $ct_result = $base_call_result['ct_result'];
351
+
352
+ if ( $ct_result->allow == 0 ) {
353
+ wp_die(
354
+ "<h1>"
355
+ . __('Spam protection by CleanTalk', 'cleantalk-spam-protect')
356
+ . "</h1><h2>" . $ct_result->comment . "</h2>",
357
+ '',
358
+ array(
359
+ 'response' => 403,
360
+ "back_link" => true,
361
+ "text_direction" => 'ltr'
362
+ )
363
+ );
364
+ }
365
  }
366
 
367
  /**
368
  * Adds hidden filed to default search form
369
  *
370
  * @param $form string
371
+ *
372
  * @return string
373
  */
374
+ function apbct_forms__search__addField($form)
375
+ {
376
+ global $apbct;
377
+ if ( $apbct->settings['forms__search_test'] == 1 ) {
378
+ $js_filed = ct_add_hidden_fields('ct_checkjs_search_default', true, false, false, false);
379
+ $form = str_replace('</form>', $js_filed, $form);
380
+ }
381
+
382
+ return $form;
383
  }
384
 
385
  /**
386
  * Test default search string for spam
387
  *
388
  * @param $search string
389
+ *
390
  * @return string
391
  */
392
+ function apbct_forms__search__testSpam($search)
393
+ {
394
+ global $apbct, $cleantalk_executed;
395
 
396
+ if (
397
+ empty($search) ||
398
+ $cleantalk_executed ||
399
+ $apbct->settings['forms__search_test'] == 0 ||
400
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
401
+ ) {
402
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
403
 
404
+ return $search;
405
+ }
 
 
 
 
 
 
 
406
 
407
  $user = apbct_is_user_logged_in() ? wp_get_current_user() : null;
408
 
409
+ $base_call_result = apbct_base_call(
410
+ array(
411
+ 'message' => $search,
412
+ 'sender_email' => $user !== null ? $user->user_email : null,
413
+ 'sender_nickname' => $user !== null ? $user->user_login : null,
414
+ 'post_info' => array('comment_type' => 'site_search_wordpress'),
415
+ )
416
+ );
417
+ $ct_result = $base_call_result['ct_result'];
418
 
419
+ $cleantalk_executed = true;
420
 
421
+ if ( $ct_result->allow == 0 ) {
422
+ die($ct_result->comment);
423
+ }
424
 
425
+ return $search;
426
  }
427
 
428
+ function apbct_search_add_noindex()
429
+ {
430
+ global $apbct;
 
 
 
 
 
 
 
 
431
 
432
+ if (
433
+ ! is_search() || // If it is search results
434
+ $apbct->settings['forms__search_test'] == 0 ||
435
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
436
+ ) {
437
+ return;
438
+ }
439
 
440
+ echo '<!-- meta by Cleantalk AntiSpam Protection plugin -->' . "\n";
441
+ echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
442
  }
443
 
444
  /**
445
  * Test woocommerce checkout form for spam
446
  * @psalm-suppress UnusedVariable
447
  */
448
+ function ct_woocommerce_checkout_check()
449
+ {
450
+ global $apbct, $cleantalk_executed;
451
+
452
+ //Getting request params
453
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
454
+
455
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
456
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
457
+ $subject = $ct_temp_msg_data['subject'] ?: '';
458
+ $message = $ct_temp_msg_data['message'] ?: array();
459
+
460
+ if ( $subject != '' ) {
461
+ $message = array_merge(array('subject' => $subject), $message);
462
+ }
463
+
464
+ $post_info['comment_type'] = 'order';
465
+ $post_info['post_url'] = apbct_get_server_variable('HTTP_REFERER');
466
+
467
+ $base_call_data = array(
468
+ 'message' => $message,
469
+ 'sender_email' => $sender_email,
470
+ 'sender_nickname' => $sender_nickname,
471
+ 'post_info' => $post_info,
472
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
473
+ 'sender_info' => array('sender_url' => null)
474
+ );
475
+
476
+ /**
477
+ * Add honeypot_field to $base_call_data is forms__wc_honeypot on
478
+ */
479
+ if ( $apbct->settings['forms__wc_honeypot'] ) {
480
+ $honeypot_field = 1;
481
+
482
+ if ( Post::get('apbct_wc_honeypot') ) {
483
+ $honeypot_field = 0;
484
+ }
485
 
486
+ $base_call_data['honeypot_field'] = $honeypot_field;
487
+ }
488
 
489
+ //Making a call
490
+ $base_call_result = apbct_base_call($base_call_data);
 
 
 
 
 
 
 
 
 
491
 
492
+ if ( $apbct->settings['forms__wc_register_from_order'] ) {
493
+ $cleantalk_executed = false;
494
+ }
495
 
496
+ $ct_result = $base_call_result['ct_result'];
497
 
498
+ if ( $ct_result->allow == 0 ) {
499
+ wp_send_json(array(
500
+ 'result' => 'failure',
501
+ 'messages' => "<ul class=\"woocommerce-error\"><li>" . $ct_result->comment . "</li></ul>",
502
+ 'refresh' => 'false',
503
+ 'reload' => 'false'
504
+ ));
505
+ }
506
  }
507
 
508
  /**
515
  * @param $variation_id
516
  * @param $variation
517
  * @param $cart_item_data
518
+ *
519
  * @return void
520
  */
521
 
522
+ function apbct_wc__add_to_cart_unlogged_user(
523
+ $_cart_item_key,
524
+ $_product_id,
525
+ $_quantity,
526
+ $_variation_id,
527
+ $_variation,
528
+ $_cart_item_data
529
+ ) {
530
+ global $apbct;
531
+
532
+ if ( ! apbct_is_user_logged_in() && $apbct->settings['forms__wc_add_to_cart'] ) {
533
+ /**
534
+ * Getting request params
535
+ * POST contains an array of product information
536
+ * Example: Array
537
+ *(
538
+ * [product_sku] => woo-beanie
539
+ * [product_id] => 15
540
+ * [quantity] => 1
541
+ *)
542
+ */
543
+ $message = $_POST ?: array();
544
+
545
+ $post_info['comment_type'] = 'order__add_to_cart';
546
+ $post_info['post_url'] = Server::get('HTTP_REFERER');
547
+
548
+ //Making a call
549
+ $base_call_result = apbct_base_call(
550
+ array(
551
+ 'message' => $message,
552
+ 'post_info' => $post_info,
553
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
554
+ 'sender_info' => array('sender_url' => null),
555
+ )
556
+ );
557
+
558
+ $ct_result = $base_call_result['ct_result'];
559
+
560
+ if ( $ct_result->allow == 0 ) {
561
+ wp_send_json(array(
562
+ 'result' => 'failure',
563
+ 'messages' => "<ul class=\"woocommerce-error\"><li>" . $ct_result->comment . "</li></ul>",
564
+ 'refresh' => 'false',
565
+ 'reload' => 'false',
566
+ 'response_type' => 'wc_add_to_cart_block'
567
+ ));
568
+ }
569
+ }
570
  }
571
 
572
  /**
573
  * Public function - Tests for Pirate contact forms
574
  * return NULL
575
  */
576
+ function apbct_form__piratesForm__testSpam()
577
+ {
578
+ global $apbct;
579
+
580
+ //Check for enabled option
581
+ if ( ! $apbct->settings['forms__contact_forms_test'] ) {
582
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
583
+
584
+ return;
585
+ }
586
+
587
+ //Getting request params
588
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
589
+
590
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
591
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
592
+ $subject = $ct_temp_msg_data['subject'] ?: '';
593
+ $message = $ct_temp_msg_data['message'] ?: array();
594
+
595
+ if ( $subject !== '' ) {
596
+ $message = array_merge(array('subject' => $subject), $message);
597
+ }
598
+
599
+ $post_info['comment_type'] = 'contact_form_wordpress_feedback_pirate';
600
+ $post_info['post_url'] = apbct_get_server_variable('HTTP_REFERER');
601
+
602
+ //Making a call
603
+ $base_call_result = apbct_base_call(
604
+ array(
605
+ 'message' => $message,
606
+ 'sender_email' => $sender_email,
607
+ 'sender_nickname' => $sender_nickname,
608
+ 'post_info' => $post_info,
609
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
610
+ 'sender_info' => array('sender_url' => null),
611
+ )
612
+ );
613
+
614
+ $ct_result = $base_call_result['ct_result'];
615
+
616
+ if ( $ct_result->allow == 0 ) {
617
+ wp_die(
618
+ "<h1>"
619
+ . __('Spam protection by CleanTalk', 'cleantalk-spam-protect')
620
+ . "</h1><h2>" . $ct_result->comment . "</h2>",
621
+ '',
622
+ array(
623
+ 'response' => 403,
624
+ "back_link" => true,
625
+ "text_direction" => 'ltr'
626
+ )
627
+ );
628
+ }
629
  }
630
 
631
  /**
632
  * Adds hidden filed to comment form
633
  */
634
+ function ct_comment_form($_post_id)
635
+ {
636
+ global $apbct;
637
 
638
+ if ( apbct_is_user_enable() === false ) {
639
+ return false;
640
+ }
641
 
642
+ if ( ! $apbct->settings['forms__comments_test'] ) {
643
+ return false;
644
+ }
645
 
646
+ ct_add_hidden_fields();
 
 
647
 
648
+ return null;
 
 
649
  }
650
 
651
  /**
656
  *
657
  * @return false|null
658
  */
659
+ function apbct_form__formidable__footerScripts($_fields, $form)
660
+ {
661
+ global $apbct, $ct_checkjs_frm;
662
 
663
+ if ( ! $apbct->settings['forms__contact_forms_test'] ) {
664
+ return false;
665
+ }
666
 
667
+ $ct_checkjs_key = ct_get_checkjs_value();
668
+ $ct_frm_base_name = 'form_';
669
+ $ct_frm_name = $ct_frm_base_name . $form->form_key;
670
 
671
+ echo "var input = document.createElement('input');
672
  input.setAttribute('type', 'hidden');
673
  input.setAttribute('name', '$ct_checkjs_frm');
674
  input.setAttribute('value', '$ct_checkjs_key');
683
 
684
  /**
685
  * Public function - Test Formidable data for spam activity
686
+ *
687
  * @param $errors
688
  * @param $form
689
  *
690
  * @return array with errors if spam has found
691
  * @psalm-suppress InvalidScalarArgument
692
  */
693
+ function apbct_form__formidable__testSpam($errors, $_form)
694
+ {
695
+ global $apbct;
696
+
697
+ if ( ! $apbct->settings['forms__contact_forms_test'] ) {
698
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
699
+
700
+ return $errors;
701
+ }
702
+
703
+ // Skip processing for logged in users.
704
+ if ( ! $apbct->settings['data__protect_logged_in'] && is_user_logged_in() ) {
705
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
706
+
707
+ return $errors;
708
+ }
709
+
710
+ $form_data = array();
711
+ foreach ( $_POST['item_meta'] as $key => $value ) {
712
+ $form_data['item_meta[' . $key . ']'] = $value;
713
+ }
714
+
715
+ $ct_temp_msg_data = ct_get_fields_any($form_data);
716
+
717
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
718
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
719
+ $message = $ct_temp_msg_data['message'] ?: array();
720
+
721
+ // @todo convert key 'NUM' to 'input_meta[NUM]'
722
+ // Adding 'input_meta[]' to every field /Formidable fix/
723
+ // because filed names is 'input_meta[NUM]'
724
+ // Get all scalar values
725
+ $tmp_message = array();
726
+ $tmp_message2 = array();
727
+ foreach ( $message as $key => $value ) {
728
+ if ( is_scalar($value) ) {
729
+ $tmp_message[$key] = $value;
730
+ } else {
731
+ $tmp_message2[$key] = $value;
732
+ }
733
+ }
734
+ // Replacing key to input_meta[NUM] for scalar values
735
+ $tmp_message = array_flip($tmp_message);
736
+ foreach ( $tmp_message as &$value ) {
737
+ $value = 'item_meta[' . $value . ']';
738
+ }
739
+ unset($value);
740
+ // @ToDO Need to be solved psalm notice about InvalidScalarArgument
741
+ $tmp_message = array_flip($tmp_message);
742
+ // Combine it with non-scalar values
743
+ $message = array_merge($tmp_message, $tmp_message2);
744
+
745
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true) ?: apbct_js_test('ct_checkjs', $_POST);
746
+
747
+ $base_call_result = apbct_base_call(
748
+ array(
749
+ 'message' => $message,
750
+ 'sender_email' => $sender_email,
751
+ 'sender_nickname' => $sender_nickname,
752
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_formidable'),
753
+ 'js_on' => $checkjs
754
+ )
755
+ );
756
+ $ct_result = $base_call_result['ct_result'];
757
+
758
+ if ( $ct_result->allow == 0 ) {
759
+ $errors['ct_error'] = '<br /><b>' . $ct_result->comment . '</b><br /><br />';
760
+ }
761
+
762
+ return $errors;
763
  }
764
 
765
  /**
766
  * Public filter 'bbp_*' - Get new topic name to global $ct_bbp_topic
767
+ *
768
+ * @param mixed[] $comment Comment string
769
+ *
770
  * @return mixed[] $comment Comment string
771
  * @psalm-suppress UnusedVariable
772
  */
773
+ function ct_bbp_get_topic($topic)
774
+ {
775
+ global $ct_bbp_topic;
776
 
777
+ $ct_bbp_topic = $topic;
778
 
779
+ return $topic;
780
  }
781
 
782
  /**
783
  * Public filter 'bbp_*' - Checks topics, replies by cleantalk
784
+ *
785
+ * @param mixed[] $comment Comment string
786
+ *
787
  * @return mixed[] $comment Comment string
788
  * @psalm-suppress UndefinedFunction
789
  */
790
+ function ct_bbp_new_pre_content($comment)
791
+ {
792
+ global $apbct, $current_user;
 
 
 
 
 
793
 
794
+ if ( ! $apbct->settings['forms__comments_test'] ) {
795
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
 
 
 
796
 
797
+ return $comment;
798
+ }
799
 
800
+ // Skip processing for logged in users and admin.
801
+ if ( ! $apbct->settings['data__protect_logged_in'] && (is_user_logged_in() || apbct_exclusions_check()) ) {
802
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
803
 
804
+ return $comment;
805
+ }
 
 
 
 
 
806
 
807
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true) ?: apbct_js_test('ct_checkjs', $_POST);
 
 
 
 
 
 
 
 
 
 
808
 
809
+ $post_info['comment_type'] = 'bbpress_comment';
810
+ $post_info['post_url'] = bbp_get_topic_permalink();
 
811
 
812
+ if ( is_user_logged_in() ) {
813
+ $sender_email = $current_user->user_email;
814
+ $sender_nickname = $current_user->display_name;
815
+ } else {
816
+ $sender_email = isset($_POST['bbp_anonymous_email']) ? $_POST['bbp_anonymous_email'] : null;
817
+ $sender_nickname = isset($_POST['bbp_anonymous_name']) ? $_POST['bbp_anonymous_name'] : null;
818
+ }
819
 
820
+ $base_call_result = apbct_base_call(
821
+ array(
822
+ 'message' => $comment,
823
+ 'sender_email' => $sender_email,
824
+ 'sender_nickname' => $sender_nickname,
825
+ 'post_info' => $post_info,
826
+ 'js_on' => $checkjs,
827
+ 'sender_info' => array('sender_url' => isset($_POST['bbp_anonymous_website']) ? $_POST['bbp_anonymous_website'] : null),
828
+ )
829
+ );
830
+ $ct_result = $base_call_result['ct_result'];
831
 
832
+ if ( $ct_result->allow == 0 ) {
833
+ bbp_add_error('bbp_reply_content', $ct_result->comment);
834
+ }
835
 
836
+ return $comment;
837
+ }
838
 
839
+ function apbct_comment__sanitize_data__before_wp_die($function)
840
+ {
841
+ global $apbct;
842
 
843
+ $comment_data = wp_unslash($_POST);
844
 
845
+ $user_ID = 0;
 
846
 
847
+ $comment_type = '';
 
 
 
848
 
849
+ $comment_content = isset($comment_data['comment']) ? (string)$comment_data['comment'] : null;
850
+ $comment_parent = isset($comment_data['comment_parent']) ? absint($comment_data['comment_parent']) : null;
851
 
852
+ $comment_author = isset($comment_data['author']) ? trim(strip_tags($comment_data['author'])) : null;
853
+ $comment_author_email = isset($comment_data['email']) ? trim($comment_data['email']) : null;
854
+ $comment_author_url = isset($comment_data['url']) ? trim($comment_data['url']) : null;
855
+ $comment_post_ID = isset($comment_data['comment_post_ID']) ? (int)$comment_data['comment_post_ID'] : null;
856
 
857
+ if ( isset($comment_content, $comment_parent) ) {
858
+ $user = function_exists('apbct_wp_get_current_user') ? apbct_wp_get_current_user() : null;
 
 
 
 
859
 
860
+ if ( $user && $user->exists() ) {
861
+ $comment_author = empty($user->display_name) ? $user->user_login : $user->display_name;
862
+ $comment_author_email = $user->user_email;
863
+ $comment_author_url = $user->user_url;
864
+ $user_ID = $user->ID;
865
+ }
 
 
 
 
866
 
867
+ $apbct->comment_data = compact(
868
+ 'comment_post_ID',
869
+ 'comment_author',
870
+ 'comment_author_email',
871
+ 'comment_author_url',
872
+ 'comment_content',
873
+ 'comment_type',
874
+ 'comment_parent',
875
+ 'user_ID'
876
+ );
877
 
878
+ $function = 'apbct_comment__check_via_wp_die';
879
+ }
880
 
881
+ return $function;
882
  }
883
 
884
+ function apbct_comment__check_via_wp_die($message, $title, $args)
885
+ {
886
+ global $apbct;
887
+ if ( $title == __('Comment Submission Failure') ) {
888
+ $apbct->validation_error = $message;
889
+ ct_preprocess_comment($apbct->comment_data);
890
+ }
891
+ _default_wp_die_handler($message, $title, $args);
892
  }
893
 
894
  /**
895
  * Public filter 'preprocess_comment' - Checks comment by cleantalk server
896
+ *
897
+ * @param mixed[] $comment Comment data array
898
+ *
899
+ * @return mixed[] New data array of comment
900
  * @psalm-suppress UnusedVariable
901
  */
902
+ function ct_preprocess_comment($comment)
903
+ {
904
+ // this action is called just when WP process POST request (adds new comment)
905
+ // this action is called by wp-comments-post.php
906
+ // after processing WP makes redirect to post page with comment's form by GET request (see above)
907
+ global $current_user, $comment_post_id, $ct_comment_done, $ct_jp_comments, $apbct, $ct_comment, $ct_stop_words;
908
+
909
+ // Send email notification for chosen groups of users
910
+ if ( $apbct->settings['wp__comment_notify'] && ! empty($apbct->settings['wp__comment_notify__roles']) && $apbct->data['moderate'] ) {
911
+ add_filter('notify_post_author', 'apbct_comment__Wordpress__doNotify', 100, 2);
912
+
913
+ $users = get_users(array(
914
+ 'role__in' => $apbct->settings['wp__comment_notify__roles'],
915
+ 'fileds' => array('user_email')
916
+ ));
917
+
918
+ if ( $users ) {
919
+ add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotificationGroups', 100, 2);
920
+ add_filter(
921
+ 'comment_notification_recipients',
922
+ 'apbct_comment__Wordpress__changeMailNotificationRecipients',
923
+ 100,
924
+ 2
925
+ );
926
+ foreach ( $users as $user ) {
927
+ $emails[] = $user->user_email;
928
+ }
929
+ $apbct->comment_notification_recipients = json_encode($emails);
930
+ }
931
+ }
932
+
933
+ // Skip processing admin.
934
+ if ( in_array("administrator", $current_user->roles) ) {
935
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
936
+
937
+ return $comment;
938
+ }
939
+
940
+ $comments_check_number = defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3;
941
+
942
+ if ( $apbct->settings['comments__check_comments_number'] && $comment['comment_author_email'] ) {
943
+ $args = array(
944
+ 'author_email' => $comment['comment_author_email'],
945
+ 'status' => 'approve',
946
+ 'count' => false,
947
+ 'number' => $comments_check_number,
948
+ );
949
+ $cnt = count(get_comments($args));
950
+ $is_max_comments = $cnt >= $comments_check_number ? true : false;
951
+ }
952
+
953
+ if (
954
+ ($comment['comment_type'] !== 'trackback') &&
955
+ (
956
+ apbct_is_user_enable() === false ||
957
+ $apbct->settings['forms__comments_test'] == 0 ||
958
+ $ct_comment_done ||
959
+ (isset($_SERVER['HTTP_REFERER']) && stripos($_SERVER['HTTP_REFERER'], 'page=wysija_campaigns&action=editTemplate') !== false) ||
960
+ (isset($is_max_comments) && $is_max_comments) ||
961
+ (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['REQUEST_URI'], '/wp-admin/') !== false)
962
+ )
963
+ ) {
964
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
965
+
966
+ return $comment;
967
+ }
968
+
969
+ $local_blacklists = apbct_wp_blacklist_check(
970
+ $comment['comment_author'],
971
+ $comment['comment_author_email'],
972
+ $comment['comment_author_url'],
973
+ $comment['comment_content'],
974
+ apbct_get_server_variable('REMOTE_ADDR'),
975
+ apbct_get_server_variable('HTTP_USER_AGENT')
976
+ );
977
+
978
+ // Go out if author in local blacklists
979
+ if ( $comment['comment_type'] !== 'trackback' && $local_blacklists === true ) {
980
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
981
+
982
+ return $comment;
983
+ }
984
+
985
+ $ct_comment_done = true;
986
+
987
+ $comment_post_id = $comment['comment_post_ID'];
988
+
989
+ // JetPack comments logic
990
+ $post_info['comment_type'] = $ct_jp_comments ? 'jetpack_comment' : $comment['comment_type'];
991
+ $post_info['post_url'] = ct_post_url(null, $comment_post_id);
992
+
993
+ // Comment type
994
+ $post_info['comment_type'] = empty($post_info['comment_type']) ? 'general_comment' : $post_info['comment_type'];
995
+
996
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true) ?: apbct_js_test('ct_checkjs', $_POST);
997
+
998
+ $example = null;
999
+ if ( $apbct->data['relevance_test'] ) {
1000
+ $post = get_post($comment_post_id);
1001
+ if ( $post !== null ) {
1002
+ $example['title'] = $post->post_title;
1003
+ $example['body'] = $post->post_content;
1004
+ $example['comments'] = null;
1005
+
1006
+ $last_comments = get_comments(array('status' => 'approve', 'number' => 10, 'post_id' => $comment_post_id));
1007
+ foreach ( $last_comments as $post_comment ) {
1008
+ $example['comments'] .= "\n\n" . $post_comment->comment_content;
1009
+ }
1010
+
1011
+ $example = json_encode($example);
1012
+ }
1013
+
1014
+ // Use plain string format if've failed with JSON
1015
+ if ( $example === false || $example === null ) {
1016
+ $example = ($post->post_title !== null) ? $post->post_title : '';
1017
+ $example .= ($post->post_content !== null) ? "\n\n" . $post->post_content : '';
1018
+ }
1019
+ }
1020
+
1021
+ $base_call_data = array(
1022
+ 'message' => $comment['comment_content'],
1023
+ 'example' => $example,
1024
+ 'sender_email' => $comment['comment_author_email'],
1025
+ 'sender_nickname' => $comment['comment_author'],
1026
+ 'post_info' => $post_info,
1027
+ 'js_on' => $checkjs,
1028
+ 'sender_info' => array(
1029
+ 'sender_url' => @$comment['comment_author_url'],
1030
+ 'form_validation' => ! isset($apbct->validation_error)
1031
+ ? null
1032
+ : json_encode(
1033
+ array(
1034
+ 'validation_notice' => $apbct->validation_error,
1035
+ 'page_url' => apbct_get_server_variable('HTTP_HOST') . apbct_get_server_variable('REQUEST_URI'),
1036
+ )
1037
+ )
1038
+ )
1039
+ );
1040
+
1041
+ /**
1042
+ * Add honeypot_field to $base_call_data is comments__hide_website_field on
1043
+ */
1044
+ if ( isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field'] ) {
1045
+ $honeypot_field = 1;
1046
+
1047
+ if ( isset($_POST['url']) && ! empty($_POST['url']) && $post_info['comment_type'] === 'comment' && isset($_POST['comment_post_ID']) ) {
1048
+ $honeypot_field = 0;
1049
+ }
1050
+
1051
+ $base_call_data['honeypot_field'] = $honeypot_field;
1052
+ }
1053
 
1054
+ $base_call_result = apbct_base_call($base_call_data);
1055
+
1056
+ $ct_result = $base_call_result['ct_result'];
1057
+
1058
+ ct_hash($ct_result->id);
1059
+
1060
+ //Don't check trusted users
1061
+ if ( isset($comment['comment_author_email']) ) {
1062
+ $approved_comments = get_comments(
1063
+ array('status' => 'approve', 'count' => true, 'author_email' => $comment['comment_author_email'])
1064
+ );
1065
+ $new_user = $approved_comments == 0 ? true : false;
1066
+ }
1067
+
1068
+ // Change comment flow only for new authors
1069
+ if ( ! empty($new_user) || $ct_result->stop_words !== null || $ct_result->spam == 1 ) {
1070
+ add_action('comment_post', 'ct_set_meta', 10, 2);
1071
+ }
1072
+
1073
+ if ( $ct_result->allow ) { // Pass if allowed
1074
+ if ( get_option('comment_moderation') === '1' ) { // Wordpress moderation flag
1075
+ add_filter('pre_comment_approved', 'ct_set_not_approved', 999, 2);
1076
+ } else {
1077
+ add_filter('pre_comment_approved', 'ct_set_approved', 999, 2);
1078
+ }
1079
+ // Modify the email notification
1080
+ add_filter(
1081
+ 'comment_notification_text',
1082
+ 'apbct_comment__wordpress__show_blacklists',
1083
+ 100,
1084
+ 2
1085
+ ); // Add two blacklist links: by email and IP
1086
+ } else {
1087
+ $ct_comment = $ct_result->comment;
1088
+ $ct_stop_words = $ct_result->stop_words;
1089
+
1090
+ $err_text =
1091
+ '<center>'
1092
+ . ((defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE == true)
1093
+ ? ''
1094
+ : '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ')
1095
+ . __('Spam protection', 'cleantalk-spam-protect')
1096
+ . "</center><br><br>\n"
1097
+ . $ct_result->comment;
1098
+ if ( ! $ct_jp_comments ) {
1099
+ $err_text .= '<script>setTimeout("history.back()", 5000);</script>';
1100
+ }
1101
+
1102
+ // Terminate. Definitely spam.
1103
+ if ( $ct_result->stop_queue == 1 ) {
1104
+ wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments));
1105
+ }
1106
+
1107
+ // Terminate by user's setting.
1108
+ if ( $ct_result->spam == 3 ) {
1109
+ wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments));
1110
+ }
1111
+
1112
+ // Trash comment.
1113
+ if ( $ct_result->spam == 2 ) {
1114
+ add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
1115
+ add_action('comment_post', 'ct_wp_trash_comment', 997, 2);
1116
+ }
1117
+
1118
+ // Spam comment
1119
+ if ( $ct_result->spam == 1 ) {
1120
+ add_filter('pre_comment_approved', 'ct_set_comment_spam', 997, 2);
1121
+ }
1122
+
1123
+ // Move to pending folder. Contains stop_words.
1124
+ if ( $ct_result->stop_words ) {
1125
+ add_filter('pre_comment_approved', 'ct_set_not_approved', 998, 2);
1126
+ add_action('comment_post', 'ct_mark_red', 998, 2);
1127
+ }
1128
+
1129
+ add_action('comment_post', 'ct_die', 999, 2);
1130
+ }
1131
+
1132
+ if ( $apbct->settings['comments__remove_comments_links'] == 1 ) {
1133
+ $comment['comment_content'] = preg_replace(
1134
+ "~(http|https|ftp|ftps)://(.*?)(\s|\n|[,.?!](\s|\n)|$)~",
1135
+ '[Link deleted]',
1136
+ $comment['comment_content']
1137
+ );
1138
+ }
1139
+
1140
+ // Change mail notification if license is out of date
1141
+ if ( $apbct->data['moderate'] == 0 ) {
1142
+ $apbct->sender_email = $comment['comment_author_email'];
1143
+ $apbct->sender_ip = Helper::ipGet('real');
1144
+ add_filter(
1145
+ 'comment_moderation_text',
1146
+ 'apbct_comment__Wordpress__changeMailNotification',
1147
+ 100,
1148
+ 2
1149
+ ); // Comment sent to moderation
1150
+ add_filter(
1151
+ 'comment_notification_text',
1152
+ 'apbct_comment__Wordpress__changeMailNotification',
1153
+ 100,
1154
+ 2
1155
+ ); // Comment approved
1156
+ }
1157
+
1158
+ return $comment;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1159
  }
1160
 
1161
  /**
1162
  * Insert a hidden field to registration form
1163
  * @return null|bool
1164
  */
1165
+ function ct_register_form()
1166
+ {
1167
+ global $ct_checkjs_register_form, $apbct;
1168
 
1169
+ if ( $apbct->settings['forms__registrations_test'] == 0 ) {
1170
+ return false;
1171
+ }
1172
 
1173
+ ct_add_hidden_fields($ct_checkjs_register_form, false, false, false, false);
 
 
1174
 
1175
+ return null;
 
 
1176
  }
1177
 
1178
  /**
1179
  * Adds notification text to login form - to inform about approved registration
1180
  * @return null
1181
  */
1182
+ function ct_login_message($message)
1183
+ {
1184
+ global $errors, $apbct, $apbct_cookie_register_ok_label;
1185
+
1186
+ if ( $apbct->settings['forms__registrations_test'] != 0 ) {
1187
+ if ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] ) {
1188
+ if ( isset($_COOKIE[$apbct_cookie_register_ok_label]) ) {
1189
+ if ( is_wp_error($errors) ) {
1190
+ $errors->add(
1191
+ 'ct_message',
1192
+ sprintf(
1193
+ __('Registration approved by %s.', 'cleantalk-spam-protect'),
1194
+ '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk</b>'
1195
+ ),
1196
+ 'message'
1197
+ );
1198
+ }
1199
+ }
1200
+ }
1201
+ }
1202
 
1203
+ return $message;
 
 
 
 
 
 
 
 
 
1204
  }
1205
 
1206
 
1208
  * Test users registration for pPress
1209
  * @return void|WP_Error with errors
1210
  */
1211
+ function ct_registration_errors_ppress($reg_errors, $_form_id)
1212
+ {
1213
+ $email = $_POST['reg_email'];
1214
+ $login = $_POST['reg_username'];
1215
 
1216
+ $reg_errors = ct_registration_errors($reg_errors, $login, $email);
 
1217
 
1218
+ return $reg_errors;
 
 
1219
  }
1220
 
1221
  /**
1222
  * Test users registration for multisite environment
1223
  * @return array|mixed with errors
1224
  */
1225
+ function ct_registration_errors_wpmu($errors)
1226
+ {
1227
+ // Multisite actions
1228
+ $sanitized_user_login = null;
1229
+ if ( isset($errors['user_name']) ) {
1230
+ $sanitized_user_login = $errors['user_name'];
1231
+ $wpmu = true;
1232
+ }
1233
+ $user_email = null;
1234
+ if ( isset($errors['user_email']) ) {
1235
+ $user_email = $errors['user_email'];
1236
+ $wpmu = true;
1237
+ }
1238
+
1239
+ if ( $wpmu && isset($errors['errors']->errors) && count($errors['errors']->errors) > 0 ) {
1240
+ return $errors;
1241
+ }
1242
+
1243
+ $errors['errors'] = ct_registration_errors($errors['errors'], $sanitized_user_login, $user_email);
1244
+
1245
+ // Show CleanTalk errors in user_name field
1246
+ if ( isset($errors['errors']->errors['ct_error']) ) {
1247
+ $errors['errors']->errors['user_name'] = $errors['errors']->errors['ct_error'];
1248
+ unset($errors['errors']->errors['ct_error']);
1249
+ }
1250
+
1251
+ return $errors;
1252
  }
1253
 
1254
  /**
1260
  *
1261
  * @return void|WP_Error
1262
  */
1263
+ function ct_register_post($sanitized_user_login, $user_email, $errors)
1264
+ {
1265
+ return ct_registration_errors($errors, $sanitized_user_login, $user_email);
1266
  }
1267
 
1268
 
1270
  * Check messages for external plugins
1271
  * @return array with checking result;
1272
  */
1273
+ function ct_test_message($nickname, $email, $_ip, $text)
1274
+ {
1275
+ $base_call_result = apbct_base_call(
1276
+ array(
1277
+ 'message' => $text,
1278
+ 'sender_email' => $email,
1279
+ 'sender_nickname' => $nickname,
1280
+ 'post_info' => array('comment_type' => 'feedback_plugin_check'),
1281
+ 'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true),
1282
+ )
1283
+ );
1284
+
1285
+ $ct_result = $base_call_result['ct_result'];
1286
+
1287
+ return array(
1288
+ 'allow' => $ct_result->allow,
1289
+ 'comment' => $ct_result->comment,
1290
+ );
1291
  }
1292
 
1293
  /**
1294
  * Check registrations for external plugins
1295
  * @return array with checking result;
1296
  */
1297
+ function ct_test_registration($nickname, $email, $ip = null)
1298
+ {
1299
+ global $ct_checkjs_register_form;
1300
+
1301
+ if ( apbct_js_test($ct_checkjs_register_form, $_POST) ) {
1302
+ $checkjs = apbct_js_test($ct_checkjs_register_form, $_POST);
1303
+ $sender_info['post_checkjs_passed'] = $checkjs;
1304
+ } else {
1305
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1306
+ $sender_info['cookie_checkjs_passed'] = $checkjs;
1307
+ }
1308
+
1309
+ //Making a call
1310
+ $base_call_result = apbct_base_call(
1311
+ array(
1312
+ 'sender_ip' => $ip,
1313
+ 'sender_email' => $email,
1314
+ 'sender_nickname' => $nickname,
1315
+ 'sender_info' => $sender_info,
1316
+ 'js_on' => $checkjs,
1317
+ ),
1318
+ true
1319
+ );
1320
+ $ct_result = $base_call_result['ct_result'];
1321
+
1322
+ $result = array(
1323
+ 'allow' => $ct_result->allow,
1324
+ 'comment' => $ct_result->comment,
1325
+ );
1326
+
1327
+ return $result;
1328
  }
1329
 
1330
  /**
1337
  * @return void|WP_Error
1338
  * @psalm-suppress UnusedVariable
1339
  */
1340
+ function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null)
1341
+ {
1342
+ global $ct_checkjs_register_form, $apbct_cookie_request_id_label, $apbct_cookie_register_ok_label, $apbct_cookie_request_id, $bp, $ct_signup_done, $ct_negative_comment, $apbct, $ct_registration_error_comment, $cleantalk_executed;
1343
+
1344
+ // Go out if a registered user action
1345
+ if ( apbct_is_user_enable() === false ) {
1346
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1347
+
1348
+ return $errors;
1349
+ }
1350
+
1351
+ if ( $apbct->settings['forms__registrations_test'] == 0 ) {
1352
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1353
+
1354
+ return $errors;
1355
+ }
1356
+
1357
+ // The function already executed
1358
+ // It happens when used ct_register_post();
1359
+ if ( $ct_signup_done && is_object($errors) && count($errors->errors) > 0 ) {
1360
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1361
+
1362
+ return $errors;
1363
+ }
1364
+
1365
+ $facebook = false;
1366
+ // Facebook registration
1367
+ if ( $sanitized_user_login === null && isset($_POST['FB_userdata']) ) {
1368
+ $sanitized_user_login = $_POST['FB_userdata']['name'];
1369
+ $facebook = true;
1370
+ }
1371
+ if ( $user_email === null && isset($_POST['FB_userdata']) ) {
1372
+ $user_email = $_POST['FB_userdata']['email'];
1373
+ $facebook = true;
1374
+ }
1375
+
1376
+ // BuddyPress actions
1377
+ $buddypress = false;
1378
+ if ( $sanitized_user_login === null && isset($_POST['signup_username']) ) {
1379
+ $sanitized_user_login = $_POST['signup_username'];
1380
+ $buddypress = true;
1381
+ }
1382
+ if ( $user_email === null && isset($_POST['signup_email']) ) {
1383
+ $user_email = $_POST['signup_email'];
1384
+ $buddypress = true;
1385
+ }
1386
+
1387
+ // Break tests because we already have servers response
1388
+ if ( $buddypress && $ct_signup_done ) {
1389
+ if ( $ct_negative_comment ) {
1390
+ $bp->signup->errors['signup_username'] = $ct_negative_comment;
1391
+ }
1392
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1393
+
1394
+ return $errors;
1395
+ }
1396
+
1397
+
1398
+ if ( current_filter() === 'woocommerce_registration_errors' ) {
1399
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1400
+ $checkjs_post = null;
1401
+ $checkjs_cookie = $checkjs;
1402
+ } else {
1403
+ // This hack can be helpful when plugin uses with untested themes&signups plugins.
1404
+ $checkjs_post = apbct_js_test($ct_checkjs_register_form, $_POST);
1405
+ $checkjs_cookie = apbct_js_test('ct_checkjs', $_COOKIE, true);
1406
+ $checkjs = $checkjs_cookie ?: $checkjs_post;
1407
+ }
1408
+
1409
+ $sender_info = array(
1410
+ 'post_checkjs_passed' => $checkjs_post,
1411
+ 'cookie_checkjs_passed' => $checkjs_cookie,
1412
+ 'form_validation' => ! empty($errors)
1413
+ ? json_encode(
1414
+ array(
1415
+ 'validation_notice' => $errors->get_error_message(),
1416
+ 'page_url' => apbct_get_server_variable('HTTP_HOST') . apbct_get_server_variable('REQUEST_URI'),
1417
+ )
1418
+ )
1419
+ : null,
1420
+ );
1421
+
1422
+ $base_call_result = apbct_base_call(
1423
+ array(
1424
+ 'sender_email' => $user_email,
1425
+ 'sender_nickname' => $sanitized_user_login,
1426
+ 'sender_info' => $sender_info,
1427
+ 'js_on' => $checkjs,
1428
+ ),
1429
+ true
1430
+ );
1431
+ $ct_result = $base_call_result['ct_result'];
1432
+
1433
+ // Change mail notification if license is out of date
1434
+ if ( $apbct->data['moderate'] == 0 &&
1435
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1436
+ ) {
1437
+ $apbct->sender_email = $user_email;
1438
+ $apbct->sender_ip = Helper::ipGet('real');
1439
+ add_filter(
1440
+ 'wp_new_user_notification_email_admin',
1441
+ 'apbct_registration__Wordpress__changeMailNotification',
1442
+ 100,
1443
+ 3
1444
+ );
1445
+ }
1446
+
1447
+ $ct_signup_done = true;
1448
+
1449
+ $ct_result = ct_change_plugin_resonse($ct_result, $checkjs);
1450
+
1451
+ $cleantalk_executed = true;
1452
+
1453
+ if ( $ct_result->inactive != 0 ) {
1454
+ ct_send_error_notice($ct_result->comment);
1455
+
1456
+ return $errors;
1457
+ }
1458
+
1459
+ if ( $ct_result->allow == 0 ) {
1460
+ if ( $buddypress === true ) {
1461
+ $bp->signup->errors['signup_username'] = $ct_result->comment;
1462
+ } elseif ( $facebook ) {
1463
+ $_POST['FB_userdata']['email'] = '';
1464
+ $_POST['FB_userdata']['name'] = '';
1465
+
1466
+ return;
1467
+ } elseif ( defined('MGM_PLUGIN_NAME') ) {
1468
+ ct_die_extended($ct_result->comment);
1469
+ } else {
1470
+ if ( is_wp_error($errors) ) {
1471
+ $errors->add('ct_error', $ct_result->comment);
1472
+ }
1473
+ $ct_negative_comment = $ct_result->comment;
1474
+ }
1475
 
1476
+ $ct_registration_error_comment = $ct_result->comment;
1477
+ } else {
1478
+ if ( $ct_result->id !== null ) {
1479
+ $apbct_cookie_request_id = $ct_result->id;
1480
+ Cookie::set($apbct_cookie_register_ok_label, $ct_result->id, time() + 10, '/');
1481
+ Cookie::set($apbct_cookie_request_id_label, $ct_result->id, time() + 10, '/');
1482
+ }
1483
+ }
1484
 
1485
+ return $errors;
1486
  }
1487
 
1488
  /**
1494
  *
1495
  * @return array Body for email notification
1496
  */
1497
+ function apbct_registration__Wordpress__changeMailNotification(
1498
+ $wp_new_user_notification_email_admin,
1499
+ $_user,
1500
+ $_blogname
1501
+ ) {
1502
+ global $apbct;
1503
+
1504
+ $wp_new_user_notification_email_admin['message'] = PHP_EOL
1505
+ . __(
1506
+ 'CleanTalk AntiSpam: This registration is spam.',
1507
+ 'cleantalk-spam-protect'
1508
+ )
1509
+ . "\n" . __(
1510
+ 'CleanTalk\'s anti-spam database:',
1511
+ 'cleantalk-spam-protect'
1512
+ )
1513
+ . "\n" . 'IP: ' . $apbct->sender_ip
1514
+ . "\n" . 'Email: ' . $apbct->sender_email
1515
+ . PHP_EOL . PHP_EOL .
1516
+ __(
1517
+ 'Activate protection in your Anti-Spam Dashboard: ',
1518
+ 'clentalk'
1519
+ )
1520
+ . 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wp_spam_registration_passed'
1521
+ . ($apbct->data['user_token']
1522
+ ? '&iser_token=' . $apbct->data['user_token']
1523
+ : ''
1524
+ )
1525
+ . PHP_EOL . '---'
1526
+ . PHP_EOL
1527
+ . $wp_new_user_notification_email_admin['message'];
1528
+
1529
+ return $wp_new_user_notification_email_admin;
1530
  }
1531
 
1532
  /**
1538
  * @psalm-suppress UndefinedFunction
1539
  * @psalm-suppress UnusedVariable
1540
  */
1541
+ function apbct_registration__UltimateMembers__check($args)
1542
+ {
1543
+ global $apbct, $cleantalk_executed;
1544
+
1545
+ if ( isset(UM()->form()->errors) ) {
1546
+ $sender_info['previous_form_validation'] = true;
1547
+ $sender_info['validation_notice'] = json_encode(UM()->form()->errors);
1548
+ }
1549
 
1550
+ if ( $apbct->settings['forms__registrations_test'] == 0 ) {
1551
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1552
 
1553
+ return $args;
1554
+ }
 
 
1555
 
1556
+ $checkjs = apbct_js_test('ct_checkjs_register_form', $args);
1557
+ $sender_info['post_checkjs_passed'] = $checkjs;
 
 
1558
 
1559
+ // This hack can be helpfull when plugin uses with untested themes&signups plugins.
1560
+ if ( $checkjs == 0 ) {
1561
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1562
+ $sender_info['cookie_checkjs_passed'] = $checkjs;
1563
+ }
1564
 
1565
+ $base_call_result = apbct_base_call(
1566
+ array(
1567
+ 'sender_email' => $args['user_email'],
1568
+ 'sender_nickname' => $args['user_login'],
1569
+ 'sender_info' => $sender_info,
1570
+ 'js_on' => $checkjs,
1571
+ ),
1572
+ true
1573
+ );
1574
+ $ct_result = $base_call_result['ct_result'];
1575
 
1576
+ $cleantalk_executed = true;
 
 
 
 
 
 
 
 
 
1577
 
1578
+ if ( $ct_result->inactive != 0 ) {
1579
+ ct_send_error_notice($ct_result->comment);
1580
 
1581
+ return $args;
1582
+ }
 
 
1583
 
1584
+ if ( $ct_result->allow == 0 ) {
1585
+ UM()->form()->add_error('user_password', $ct_result->comment);
1586
+ }
1587
 
1588
+ return $args;
1589
  }
1590
 
1591
  /**
1597
  *
1598
  * @return mixed
1599
  */
1600
+ function ct_check_registration_erros($errors, $_sanitized_user_login = null, $_user_email = null)
1601
+ {
1602
+ global $bp, $ct_registration_error_comment;
1603
+
1604
+ if ( $ct_registration_error_comment ) {
1605
+ if ( isset($bp) ) {
1606
+ if ( method_exists($bp, 'signup') ) {
1607
+ if ( method_exists($bp->signup, 'errors') ) {
1608
+ if ( isset($bp->signup->errors['signup_username']) ) {
1609
+ if ( $bp->signup->errors['signup_username'] != $ct_registration_error_comment ) {
1610
+ $bp->signup->errors['signup_username'] = $ct_registration_error_comment;
1611
+ }
1612
+ }
1613
+ }
1614
+ }
1615
+ }
1616
+
1617
+ if ( isset($errors) ) {
1618
+ if ( method_exists($errors, 'errors') ) {
1619
+ if ( isset($errors->errors['ct_error']) ) {
1620
+ if ( $errors->errors['ct_error'][0] != $ct_registration_error_comment ) {
1621
+ $errors->add('ct_error', $ct_registration_error_comment);
1622
+ }
1623
+ }
1624
+ }
1625
+ }
1626
+ }
1627
 
1628
+ return $errors;
 
1629
  }
1630
 
1631
 
1632
  /**
1633
  * Set user meta (ct_hash) for successes registration
1634
  */
1635
+ function apbct_user_register($user_id)
1636
+ {
1637
+ global $apbct_cookie_request_id_label, $apbct_cookie_request_id;
1638
 
1639
+ if ( ! empty($apbct_cookie_request_id) ) {
1640
+ update_user_meta($user_id, 'ct_hash', $apbct_cookie_request_id);
1641
 
1642
+ return;
1643
+ }
 
 
1644
 
1645
+ if ( isset($_COOKIE[$apbct_cookie_request_id_label]) ) {
1646
+ if ( update_user_meta($user_id, 'ct_hash', $_COOKIE[$apbct_cookie_request_id_label]) ) {
1647
+ Cookie::set($apbct_cookie_request_id_label, '0', 1, '/');
1648
+ }
1649
+ }
1650
  }
1651
 
1652
 
1653
  /**
1654
  * Test for JetPack contact form
1655
  */
1656
+ function ct_grunion_contact_form_field_html($r, $_field_label)
1657
+ {
1658
+ global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $apbct;
1659
+
1660
+ if (
1661
+ $apbct->settings['forms__contact_forms_test'] == 1 &&
1662
+ $ct_jpcf_patched === false &&
1663
+ preg_match("/(text|email)/i", $r)
1664
+ ) {
1665
+ // Looking for element name prefix
1666
+ $name_patched = false;
1667
+ foreach ( $ct_jpcf_fields as $v ) {
1668
+ if ( $name_patched === false && preg_match("/(g\d-)$v/", $r, $matches) ) {
1669
+ $ct_checkjs_jpcf = $matches[1] . $ct_checkjs_jpcf;
1670
+ $name_patched = true;
1671
+ }
1672
+ }
1673
 
1674
+ $r .= ct_add_hidden_fields($ct_checkjs_jpcf, true);
1675
+ $ct_jpcf_patched = true;
1676
+ }
1677
 
1678
+ return $r;
1679
  }
1680
+
1681
  /**
1682
  * Test for JetPack contact form
1683
  * @psalm-suppress UnusedVariable
1684
  */
1685
+ function ct_contact_form_is_spam($form)
1686
+ {
1687
+ global $ct_checkjs_jpcf, $apbct, $ct_comment;
1688
+
1689
+ if ( $apbct->settings['forms__contact_forms_test'] == 0 ) {
1690
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1691
+
1692
+ return null;
1693
+ }
1694
+
1695
+ $js_field_name = $ct_checkjs_jpcf;
1696
+ foreach ( $_POST as $k => $_v ) {
1697
+ if ( preg_match("/^.+$ct_checkjs_jpcf$/", $k) ) {
1698
+ $js_field_name = $k;
1699
+ }
1700
+ }
1701
+
1702
+ $sender_email = null;
1703
+ $sender_nickname = null;
1704
+ $message = '';
1705
+ if ( isset($form['comment_author_email']) ) {
1706
+ $sender_email = $form['comment_author_email'];
1707
+ }
1708
+
1709
+ if ( isset($form['comment_author']) ) {
1710
+ $sender_nickname = $form['comment_author'];
1711
+ }
1712
+
1713
+ if ( isset($form['comment_content']) ) {
1714
+ $message = $form['comment_content'];
1715
+ }
1716
+
1717
+ $base_call_result = apbct_base_call(
1718
+ array(
1719
+ 'message' => $message,
1720
+ 'sender_email' => $sender_email,
1721
+ 'sender_nickname' => $sender_nickname,
1722
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_grunion'),
1723
+ 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1724
+ 'js_on' => apbct_js_test($js_field_name, $_POST),
1725
+ )
1726
+ );
1727
+ $ct_result = $base_call_result['ct_result'];
1728
+
1729
+ if ( $ct_result->allow == 0 ) {
1730
+ $ct_comment = $ct_result->comment;
1731
+ ct_die(null, null);
1732
+ exit;
1733
+ }
1734
+
1735
+ return ! $ct_result->allow;
1736
  }
1737
 
1738
  /**
1742
  * @return bool|null
1743
  * @psalm-suppress UnusedVariable
1744
  */
1745
+ function ct_contact_form_is_spam_jetpack($_is_spam, $form)
1746
+ {
1747
+ global $apbct, $ct_comment;
1748
+
1749
+ if ( $apbct->settings['forms__contact_forms_test'] == 0 ) {
1750
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1751
+
1752
+ return null;
1753
+ }
1754
+
1755
+ $base_call_result = apbct_base_call(
1756
+ array(
1757
+ 'message' => isset($form['comment_content']) ? $form['comment_content'] : '',
1758
+ 'sender_email' => isset($form['comment_author_email']) ? $form['comment_author_email'] : null,
1759
+ 'sender_nickname' => isset($form['comment_author']) ? $form['comment_author'] : null,
1760
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_grunion'),
1761
+ 'sender_info' => array('sender_url' => @$form['comment_author_url']),
1762
+ )
1763
+ );
1764
+ $ct_result = $base_call_result['ct_result'];
1765
+
1766
+ if ( $ct_result->allow == 0 ) {
1767
+ $ct_comment = $ct_result->comment;
1768
+ ct_die(null, null);
1769
+ exit;
1770
+ }
1771
+
1772
+ return ! $ct_result->allow;
1773
  }
1774
 
1775
  /**
1776
  * Inserts anti-spam hidden to WP Maintenance Mode (wpmm)
1777
  */
1778
+ function apbct_form__wpmm__addField()
1779
+ {
1780
+ ct_add_hidden_fields('ct_checkjs', false, true, true);
1781
  }
1782
 
1783
  /**
1784
  * Inserts anti-spam hidden to CF7
1785
  */
1786
+ function apbct_form__contactForm7__addField($html)
1787
+ {
1788
+ global $ct_checkjs_cf7, $apbct;
1789
 
1790
+ if ( $apbct->settings['forms__contact_forms_test'] == 0 ) {
1791
+ return $html;
1792
+ }
1793
 
1794
+ $html .= ct_add_hidden_fields($ct_checkjs_cf7, true);
1795
 
1796
+ return $html;
1797
  }
1798
 
1799
  /**
1804
  *
1805
  * @global State $apbct
1806
  */
1807
+ function apbct_form__contactForm7__tesSpam__before_validate($result = null, $_tags = null)
1808
+ {
1809
+ global $apbct;
1810
+
1811
+ if ( $result && method_exists($result, 'get_invalid_fields') ) {
1812
+ $invalid_fields = $result->get_invalid_fields();
1813
+ if ( ! empty($invalid_fields) && is_array($invalid_fields) ) {
1814
+ $apbct->validation_error = $invalid_fields[key($invalid_fields)]['reason'];
1815
+ apbct_form__contactForm7__testSpam(false);
1816
+ }
1817
+ }
1818
 
1819
+ return $result;
1820
  }
1821
 
1822
  /**
1823
  * Test CF7 message for spam
1824
  * @psalm-suppress UnusedVariable
1825
  */
1826
+ function apbct_form__contactForm7__testSpam($spam, $_submission = null)
1827
+ {
1828
+ global $ct_checkjs_cf7, $apbct, $ct_cf7_comment;
1829
+
1830
+ if (
1831
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
1832
+ ($spam === false && defined('WPCF7_VERSION') && WPCF7_VERSION < '3.0.0') ||
1833
+ ($spam === true && defined('WPCF7_VERSION') && WPCF7_VERSION >= '3.0.0') ||
1834
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
1835
+ apbct_exclusions_check__url() ||
1836
+ apbct_exclusions_check__ip() ||
1837
+ isset($apbct->cf7_checked)
1838
+ ) {
1839
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1840
+
1841
+ return $spam;
1842
+ }
1843
+
1844
+ $checkjs = apbct_js_test($ct_checkjs_cf7, $_POST) ?: apbct_js_test('ct_checkjs', $_COOKIE, true);
1845
+
1846
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
1847
+
1848
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
1849
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
1850
+ $subject = $ct_temp_msg_data['subject'] ?: '';
1851
+ $message = $ct_temp_msg_data['message'] ?: array();
1852
+ if ( $subject !== '' ) {
1853
+ $message = array_merge(array('subject' => $subject), $message);
1854
+ }
1855
+
1856
+ $base_call_result = apbct_base_call(
1857
+ array(
1858
+ 'message' => $message,
1859
+ 'sender_email' => $sender_email,
1860
+ 'sender_nickname' => $sender_nickname,
1861
+ 'js_on' => $checkjs,
1862
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_cf7'),
1863
+ 'sender_info' => array(
1864
+ 'form_validation' => ! isset($apbct->validation_error)
1865
+ ? null
1866
+ : json_encode(array(
1867
+ 'validation_notice' => $apbct->validation_error,
1868
+ 'page_url' => apbct_get_server_variable('HTTP_HOST') . apbct_get_server_variable('REQUEST_URI'),
1869
+ ))
1870
+ ),
1871
+ )
1872
+ );
1873
+
1874
+ $ct_result = $base_call_result['ct_result'];
1875
+
1876
+ // Change mail notification if license is out of date
1877
+ if ( $apbct->data['moderate'] == 0 &&
1878
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
1879
+ ) {
1880
+ $apbct->sender_email = $sender_email;
1881
+ $apbct->sender_ip = Helper::ipGet();
1882
+ add_filter('wpcf7_mail_components', 'apbct_form__contactForm7__changeMailNotification');
1883
+ }
1884
+
1885
+ if ( $ct_result->allow == 0 ) {
1886
+ $ct_cf7_comment = $ct_result->comment;
1887
+
1888
+ add_filter('wpcf7_display_message', 'apbct_form__contactForm7__showResponse', 10, 2);
1889
+
1890
+ $spam = defined('WPCF7_VERSION') && WPCF7_VERSION >= '3.0.0';
1891
+ }
1892
+
1893
+ $apbct->cf7_checked = true;
1894
+
1895
+ return $spam;
 
1896
  }
1897
 
1898
  /**
1903
  *
1904
  * @return mixed|string
1905
  */
1906
+ function apbct_form__contactForm7__showResponse($message, $status = 'spam')
1907
+ {
1908
+ global $ct_cf7_comment;
1909
 
1910
+ if ( $status === 'spam' ) {
1911
+ $message = $ct_cf7_comment;
1912
+ }
1913
 
1914
+ return $message;
1915
  }
1916
 
1917
  /**
1918
  * Changes email notification for success subscription for Contact Form 7
1919
  *
1920
  * @param array $component Arguments for email notification
1921
+ *
1922
  * @return array Arguments for email notification
1923
  */
1924
+ function apbct_form__contactForm7__changeMailNotification($component)
1925
+ {
1926
+ global $apbct;
1927
 
1928
+ $component['body'] =
1929
+ __('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
1930
+ . PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
1931
+ . PHP_EOL . 'IP: ' . $apbct->sender_ip
1932
+ . PHP_EOL . 'Email: ' . $apbct->sender_email
1933
+ . PHP_EOL . sprintf(
1934
+ __('Activate protection in your Anti-Spam Dashboard: %s.', 'clentalk'),
1935
+ 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=cf7_activate_antispam&user_token=' . $apbct->user_token
1936
+ )
1937
+ . PHP_EOL . '---' . PHP_EOL . PHP_EOL
1938
+ . $component['body'];
1939
 
1940
+ return (array)$component;
 
 
 
 
 
 
 
 
 
 
 
 
1941
  }
1942
 
1943
  /**
1944
  * Test Ninja Forms message for spam
1945
  *
 
1946
  * @return void
1947
+ * @global State $apbct
1948
  */
1949
+ function apbct_form__ninjaForms__testSpam()
1950
+ {
1951
+ global $apbct, $cleantalk_executed;
1952
+
1953
+ if ( $cleantalk_executed ) {
1954
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1955
+
1956
+ return;
1957
+ }
1958
+
1959
+ if (
1960
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
1961
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
1962
+ apbct_exclusions_check__url()
1963
+ ) {
1964
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
1965
+
1966
+ return;
1967
+ }
1968
+
1969
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
1970
+
1971
+ // Choosing between POST and GET
1972
+ $params = ct_get_fields_any(
1973
+ isset($_GET['ninja_forms_ajax_submit']) || isset($_GET['nf_ajax_submit']) ? $_GET : $_POST
1974
+ );
1975
+
1976
+ $sender_email = $params['email'] ?: '';
1977
+ $sender_nickname = $params['nickname'] ?: '';
1978
+ $subject = $params['subject'] ?: '';
1979
+ $message = $params['message'] ?: array();
1980
+ if ( $subject != '' ) {
1981
+ $message = array_merge(array('subject' => $subject), $message);
1982
+ }
1983
+
1984
+ //Ninja Forms xml fix
1985
+ foreach ( $message as $key => $value ) {
1986
+ if ( strpos($value, '<xml>') !== false ) {
1987
+ unset($message[$key]);
1988
+ }
1989
+ }
1990
+
1991
+ $base_call_result = apbct_base_call(
1992
+ array(
1993
+ 'message' => $message,
1994
+ 'sender_email' => $sender_email,
1995
+ 'sender_nickname' => $sender_nickname,
1996
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_ninja_froms'),
1997
+ 'js_on' => $checkjs,
1998
+ )
1999
+ );
2000
+ $ct_result = $base_call_result['ct_result'];
2001
+
2002
+ // Change mail notification if license is out of date
2003
+ if ( $apbct->data['moderate'] == 0 &&
2004
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
2005
+ ) {
2006
+ $apbct->sender_email = $sender_email;
2007
+ $apbct->sender_ip = Helper::ipGet('real');
2008
+ add_filter('ninja_forms_action_email_message', 'apbct_form__ninjaForms__changeMailNotification', 1, 3);
2009
+ }
2010
+
2011
+ if ( $ct_result->allow == 0 ) {
2012
+ // We have to use GLOBAL variable to transfer the comment to apbct_form__ninjaForms__changeResponse() function :(
2013
+ $apbct->response = $ct_result->comment;
2014
+ add_action('ninja_forms_before_response', 'apbct_form__ninjaForms__changeResponse', 10, 1);
2015
+ add_action(
2016
+ 'ninja_forms_action_email_send',
2017
+ 'apbct_form__ninjaForms__stopEmail',
2018
+ 1,
2019
+ 5
2020
+ ); // Prevent mail notification
2021
+ add_action(
2022
+ 'ninja_forms_save_submission',
2023
+ 'apbct_form__ninjaForms__preventSubmission',
2024
+ 1,
2025
+ 2
2026
+ ); // Prevent mail notification
2027
+ }
2028
+ }
2029
+
2030
+ function apbct_form__ninjaForms__preventSubmission($_some, $_form_id)
2031
+ {
2032
+ return false;
2033
  }
2034
 
2035
 
2042
  *
2043
  * @throws Exception
2044
  */
2045
+ function apbct_form__ninjaForms__stopEmail($_some, $_action_settings, $_message, $_headers, $_attachments)
2046
+ {
2047
+ global $apbct;
2048
+ throw new Exception($apbct->response);
2049
  }
2050
 
2051
  /**
2052
  * @param $data
2053
+ *
2054
  * @psalm-suppress InvalidArrayOffset
2055
  */
2056
+ function apbct_form__ninjaForms__changeResponse($data)
2057
+ {
2058
+ global $apbct;
 
 
 
 
 
 
 
 
 
 
2059
 
2060
+ // Show error message below field found by ID
2061
+ if ( array_key_exists('email', $data['fields_by_key']) ) {
2062
+ // Find ID of EMAIL field
2063
+ $nf_field_id = $data['fields_by_key']['email']['id'];
2064
+ } else {
2065
+ // Find ID of last field (usually SUBMIT)
2066
+ $fields_keys = array_keys($data['fields']);
2067
+ $nf_field_id = array_pop($fields_keys);
2068
+ }
2069
 
2070
+ // Below is modified NJ logic
2071
+ $error = array(
2072
+ 'fields' => array(
2073
+ $nf_field_id => $apbct->response,
2074
+ ),
2075
+ );
2076
 
2077
+ $response = array('data' => $data, 'errors' => $error, 'debug' => '');
2078
 
2079
+ die(wp_json_encode($response, JSON_FORCE_OBJECT));
2080
  }
2081
 
2082
  /**
2083
  * @psalm-suppress UnusedVariable
2084
  */
2085
+ function apbct_form__seedprod_coming_soon__testSpam()
2086
+ {
2087
+ global $apbct, $ct_comment;
2088
+
2089
+ if (
2090
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2091
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
2092
+ apbct_exclusions_check__url()
2093
+ ) {
2094
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2095
+
2096
+ return;
2097
+ }
2098
+
2099
+ $ct_temp_msg_data = ct_get_fields_any($_REQUEST);
2100
+
2101
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
2102
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2103
+ $subject = $ct_temp_msg_data['subject'] ?: '';
2104
+ $message = $ct_temp_msg_data['message'] ?: array();
2105
+ if ( $subject != '' ) {
2106
+ $message = array_merge(array('subject' => $subject), $message);
2107
+ }
2108
+
2109
+ $post_info['comment_type'] = 'contact_form_wordpress_seedprod_coming_soon';
2110
+
2111
+ $base_call_result = apbct_base_call(
2112
+ array(
2113
+ 'message' => $message,
2114
+ 'sender_email' => $sender_email,
2115
+ 'sender_nickname' => $sender_nickname,
2116
+ 'post_info' => $post_info,
2117
+ )
2118
+ );
2119
+
2120
+ $ct_result = $base_call_result['ct_result'];
2121
+ if ( $ct_result->allow == 0 ) {
2122
+ $ct_comment = $ct_result->comment;
2123
+
2124
+ $response = array(
2125
+ 'status' => 200,
2126
+ 'html' =>
2127
+ "<h1>"
2128
+ . __('Spam protection by CleanTalk', 'cleantalk-spam-protect')
2129
+ . "</h1><h2>" . $ct_result->comment . "</h2>"
2130
+ );
2131
+
2132
+ echo sanitize_text_field($_GET['callback']) . '(' . json_encode($response) . ')';
2133
+ exit();
2134
+ }
2135
  }
2136
 
2137
  /**
2138
  * Changes email notification for success subscription for Ninja Forms
2139
  *
2140
  * @param string $message Body of email notification
2141
+ *
2142
  * @return string Body for email notification
2143
  */
2144
+ function apbct_form__ninjaForms__changeMailNotification($message, $_data, $action_settings)
2145
+ {
2146
+ global $apbct;
2147
+
2148
+ if ( $action_settings['to'] !== $apbct->sender_email ) {
2149
+ $message .= wpautop(
2150
+ PHP_EOL . '---'
2151
+ . PHP_EOL
2152
+ . __('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
2153
+ . PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
2154
+ . PHP_EOL . 'IP: ' . $apbct->sender_ip
2155
+ . PHP_EOL . 'Email: ' . $apbct->sender_email
2156
+ . PHP_EOL .
2157
+ __('Activate protection in your Anti-Spam Dashboard: ', 'clentalk') .
2158
+ 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=ninjaform_activate_antispam' . $apbct->user_token
2159
+ );
2160
+ }
2161
+
2162
+ return $message;
2163
  }
2164
 
2165
  /**
2166
  * Inserts anti-spam hidden to WPForms
2167
  *
 
2168
  * @return void
2169
+ * @global State $apbct
2170
  */
2171
+ function apbct_form__WPForms__addField($_form_data, $_some, $_title, $_description, $_errors)
2172
+ {
2173
+ global $apbct;
 
 
 
 
2174
 
2175
+ if ( $apbct->settings['forms__contact_forms_test'] == 1 ) {
2176
+ ct_add_hidden_fields('ct_checkjs_wpforms');
2177
+ }
2178
  }
2179
 
2180
  /**
2181
  * Gather fields data from submission and store it
2182
  *
2183
+ * @param array $entry
2184
  * @param $form
2185
  *
2186
  * @return array
2187
  * @global State $apbct
2188
  */
2189
+ function apbct_from__WPForms__gatherData($entry, $form)
2190
+ {
2191
+ global $apbct;
2192
+ $handled_result = array();
2193
+
2194
+ $entry_fields_data = $entry['fields'] ?: array();
2195
+ $form_fields_info = $form['fields'] ?: array();
2196
+
2197
+ foreach ( $form_fields_info as $form_field ) {
2198
+ $field_id = $form_field['id'];
2199
+ $field_type = $form_field['type'];
2200
+ $field_label = $form_field['label'] ?: '';
2201
+ if ( ! isset($entry_fields_data[$field_id]) ) {
2202
+ continue;
2203
+ }
2204
+ $entry_field_value = $entry_fields_data[$field_id];
2205
+
2206
+ # search email field
2207
+ if ( $field_type === 'email' ) {
2208
+ if ( ! isset($handled_result['email']) || empty($handled_result['email']) ) {
2209
+ $handled_result['email'] = $entry_field_value;
2210
+ continue;
2211
+ }
2212
+ }
2213
+
2214
+ # search name
2215
+ if ( $field_type === 'name' ) {
2216
+ if ( is_array($entry_field_value) ) {
2217
+ $handled_result['name'][] = implode(' ', array_slice($entry_field_value, 0, 3));
2218
+ } else {
2219
+ $handled_result['name'][] = array('nick' => $entry_field_value, 'first' => '', 'last' => '');
2220
+ }
2221
+ continue;
2222
+ }
2223
+
2224
+ # Add field label as key for result array
2225
+ # add unique key if key exist
2226
+ if ( $field_label ) {
2227
+ $field_label = mb_strtolower(trim($field_label));
2228
+ $field_label = str_replace(' ', '_', $field_label);
2229
+ $field_label = preg_replace('/\W/u', '', $field_label);
2230
+
2231
+ if ( ! isset($handled_result[$field_label]) || empty($handled_result[$field_label]) ) {
2232
+ $handled_result[$field_label] = $entry_field_value;
2233
+ } else {
2234
+ $handled_result[$field_label . rand(0, 100)] = $entry_field_value;
2235
+ }
2236
+ }
2237
+ }
2238
 
2239
+ $apbct->form_data = $handled_result;
2240
 
2241
+ return $entry;
2242
  }
2243
 
2244
  /**
2247
  *
2248
  * @param array $errors
2249
  * @param array $form_data
2250
+ *
2251
  * @return array
2252
  */
2253
+ function apbct_form__WPForms__showResponse($errors, $form_data)
2254
+ {
2255
+ if (
2256
+ empty($errors) ||
2257
+ (isset($form_data['id'], $errors[$form_data['id']]) && ! count($errors[$form_data['id']]))
2258
+ ) {
2259
+ $spam_comment = apbct_form__WPForms__testSpam();
2260
+
2261
+ $filed_id = $form_data && ! empty($form_data['fields']) && is_array($form_data['fields'])
2262
+ ? key($form_data['fields'])
2263
+ : 0;
2264
+
2265
+ if ( $spam_comment ) {
2266
+ $errors[$form_data['id']][$filed_id] = $spam_comment;
2267
+ }
2268
+ }
2269
 
2270
+ return $errors;
2271
  }
2272
 
2273
  /**
2278
  * @return string|void
2279
  * @global State $apbct
2280
  */
2281
+ function apbct_form__WPForms__testSpam()
2282
+ {
2283
+ global $apbct;
2284
+
2285
+ if (
2286
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2287
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) // Skip processing for logged in users.
2288
+ ) {
2289
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2290
+
2291
+ return;
2292
+ }
2293
+
2294
+ $checkjs = apbct_js_test('ct_checkjs_wpforms', $_POST);
2295
+
2296
+ $email = $apbct->form_data['email'] ?: null;
2297
+ $nickname = $apbct->form_data['name'] && is_array($apbct->form_data['name']) ? array_shift(
2298
+ $apbct->form_data['name']
2299
+ ) : null;
2300
+ $form_data = $apbct->form_data;
2301
+
2302
+ if ( $email ) {
2303
+ unset($form_data['email']);
2304
+ }
2305
+ if ( $nickname ) {
2306
+ unset($form_data['name']);
2307
+ }
2308
+
2309
+ $params = ct_get_fields_any($apbct->form_data, $email, $nickname);
2310
+
2311
+ if ( is_array($params['nickname']) ) {
2312
+ $params['nickname'] = implode(' ', $params['nickname']);
2313
+ }
2314
+
2315
+ $sender_email = $params['email'] ?: '';
2316
+ $sender_nickname = $params['nickname'] ?: '';
2317
+ $subject = $params['subject'] ?: '';
2318
+ $message = $params['message'] ?: array();
2319
+ if ( $subject !== '' ) {
2320
+ $message = array_merge(array('subject' => $subject), $message);
2321
+ }
2322
+
2323
+ $base_call_result = apbct_base_call(
2324
+ array(
2325
+ 'message' => $message,
2326
+ 'sender_email' => $sender_email,
2327
+ 'sender_nickname' => $sender_nickname,
2328
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_wp_forms'),
2329
+ 'js_on' => $checkjs,
2330
+ )
2331
+ );
2332
+ $ct_result = $base_call_result['ct_result'];
2333
+
2334
+ // Change mail notification if license is out of date
2335
+ if ( $apbct->data['moderate'] == 0 &&
2336
+ ($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
2337
+ ) {
2338
+ $apbct->sender_email = $sender_email;
2339
+ $apbct->sender_ip = Helper::ipGet('real');
2340
+ add_filter('wpforms_email_message', 'apbct_form__WPForms__changeMailNotification', 100, 2);
2341
+ }
2342
+
2343
+ if ( $ct_result->allow == 0 ) {
2344
+ return $ct_result->comment;
2345
+ }
2346
+
2347
+ return null;
2348
  }
2349
 
2350
  /**
2352
  *
2353
  * @param string $message Body of email notification
2354
  * @param object $wpforms_email WPForms email class object
2355
+ *
2356
  * @return string Body for email notification
2357
  */
2358
+ function apbct_form__WPForms__changeMailNotification($message, $_wpforms_email)
2359
+ {
2360
+ global $apbct;
2361
+
2362
+ $message = str_replace(array('</html>', '</body>'), '', $message);
2363
+ $message .=
2364
+ wpautop(
2365
+ PHP_EOL
2366
+ . '---'
2367
+ . PHP_EOL
2368
+ . __('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
2369
+ . PHP_EOL . __('CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
2370
+ . PHP_EOL . 'IP: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_ip . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_ip . '</a>'
2371
+ . PHP_EOL . 'Email: ' . '<a href="https://cleantalk.org/blacklists/' . $apbct->sender_email . '?utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_spam_passed" target="_blank">' . $apbct->sender_email . '</a>'
2372
+ . PHP_EOL
2373
+ . sprintf(
2374
+ __('Activate protection in your %sAnti-Spam Dashboard%s.', 'clentalk'),
2375
+ '<a href="https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wpforms_activate_antispam" target="_blank">',
2376
+ '</a>'
2377
+ )
2378
+ )
2379
+ . '</body></html>';
2380
+
2381
+ return $message;
2382
  }
2383
 
2384
 
2385
  /**
2386
  * QuForms check spam
2387
+ * works with single-paged forms
2388
+ * and with multi-paged forms - check only last step of the forms
2389
  *
2390
  * @param $result
2391
  * @param $form
2392
  *
2393
  * @return mixed
2394
  */
2395
+ function ct_quform_post_validate($result, $form)
2396
+ {
2397
+ if ( $form->hasPages() ) {
2398
+ $comment_type = 'contact_form_wordpress_quforms_multipage';
2399
+ } else {
2400
+ $comment_type = 'contact_form_wordpress_quforms_singlepage';
2401
+ }
2402
+
2403
+ $ct_temp_msg_data = ct_get_fields_any($form->getValues());
2404
+ // @ToDo If we have several emails at the form - will be used only the first detected!
2405
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
2406
+
2407
+ $checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
2408
+ $base_call_result = apbct_base_call(
2409
+ array(
2410
+ 'message' => $form->getValues(),
2411
+ 'sender_email' => $sender_email,
2412
+ 'post_info' => array('comment_type' => $comment_type),
2413
+ 'js_on' => $checkjs,
2414
+ )
2415
+ );
2416
+
2417
+ $ct_result = $base_call_result['ct_result'];
2418
+ if ( $ct_result->allow == 0 ) {
2419
+ die(
2420
+ json_encode(
2421
+ array('type' => 'error', 'apbct' => array('blocked' => true, 'comment' => $ct_result->comment)),
2422
+ JSON_HEX_QUOT | JSON_HEX_TAG
2423
+ )
2424
+ );
2425
+ }
2426
+
2427
+ return $result;
2428
  }
2429
 
2430
  /**
2431
  * Inserts anti-spam hidden to Fast Secure contact form
2432
  */
2433
+ function ct_si_contact_display_after_fields($string = '', $_style = '', $_form_errors = array(), $_form_id_num = 0)
2434
+ {
2435
+ $string .= ct_add_hidden_fields('ct_checkjs', true);
2436
+
2437
+ return $string;
2438
  }
2439
 
2440
  /**
2441
  * Test for Fast Secure contact form
2442
  * @psalm-suppress UnusedVariable
2443
  */
2444
+ function ct_si_contact_form_validate($form_errors = array(), $_form_id_num = 0)
2445
+ {
2446
+ global $apbct, $cleantalk_executed, $ct_comment;
2447
+ if ( ! empty($form_errors) ) {
2448
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2449
+
2450
+ return $form_errors;
2451
+ }
2452
+
2453
+ if ( $apbct->settings['forms__contact_forms_test'] == 0 ) {
2454
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2455
+
2456
+ return $form_errors;
2457
+ }
2458
+
2459
+ // Skip processing because data already processed.
2460
+ if ( $cleantalk_executed ) {
2461
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2462
+
2463
+ return $form_errors;
2464
+ }
2465
+
2466
+ //getting info from custom fields
2467
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
2468
+
2469
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
2470
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2471
+ $subject = $ct_temp_msg_data['subject'] ?: '';
2472
+ $message = $ct_temp_msg_data['message'] ?: array();
2473
+ if ( $subject !== '' ) {
2474
+ $message['subject'] = $subject;
2475
+ }
2476
+
2477
+ $base_call_result = apbct_base_call(
2478
+ array(
2479
+ 'message' => $message,
2480
+ 'sender_email' => $sender_email,
2481
+ 'sender_nickname' => $sender_nickname,
2482
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_fscf'),
2483
+ 'js_on' => apbct_js_test('ct_checkjs', $_POST),
2484
+ )
2485
+ );
2486
+
2487
+ $ct_result = $base_call_result['ct_result'];
2488
+
2489
+ $cleantalk_executed = true;
2490
+
2491
+ if ( $ct_result->allow == 0 ) {
2492
+ $ct_comment = $ct_result->comment;
2493
+ ct_die(null, null);
2494
+ exit;
2495
+ }
2496
+
2497
+ return $form_errors;
2498
  }
2499
 
2500
  /**
2501
  * Notice for commentators which comment has automatically approved by plugin
2502
+ *
2503
+ * @param string $hook URL of hooked page
2504
  */
2505
+ function ct_comment_text($comment_text)
2506
+ {
2507
+ global $comment, $ct_approved_request_id_label;
2508
+
2509
+ if ( isset($_COOKIE[$ct_approved_request_id_label]) && isset($comment->comment_ID) ) {
2510
+ $ct_hash = get_comment_meta($comment->comment_ID, 'ct_hash', true);
2511
+
2512
+ if ( $ct_hash !== '' && $_COOKIE[$ct_approved_request_id_label] == $ct_hash ) {
2513
+ $comment_text .=
2514
+ '<br /><br /> <em class="comment-awaiting-moderation">'
2515
+ . __(
2516
+ 'Comment approved. Anti-spam by CleanTalk.',
2517
+ 'cleantalk-spam-protect'
2518
+ )
2519
+ . '</em>';
2520
+ }
2521
+ }
2522
 
2523
+ return $comment_text;
2524
  }
2525
 
2526
 
2527
  /**
2528
  * Checks WordPress Landing Pages raw $_POST values
2529
  */
2530
+ function ct_check_wplp()
2531
+ {
2532
+ global $ct_wplp_result_label, $apbct;
2533
+
2534
+ if ( ! isset($_COOKIE[$ct_wplp_result_label]) ) {
2535
+ // First AJAX submit of WPLP form
2536
+ if ( $apbct->settings['forms__contact_forms_test'] == 0 ) {
2537
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2538
+
2539
+ return;
2540
+ }
2541
+
2542
+ $sender_email = '';
2543
+ foreach ( $_POST as $v ) {
2544
+ if ( preg_match("/^\S+@\S+\.\S+$/", $v) ) {
2545
+ $sender_email = $v;
2546
+ break;
2547
+ }
2548
+ }
2549
+
2550
+ $message = '';
2551
+ if ( array_key_exists('form_input_values', $_POST) ) {
2552
+ $form_input_values = json_decode(stripslashes($_POST['form_input_values']), true);
2553
+ if ( is_array($form_input_values) && array_key_exists('null', $form_input_values) ) {
2554
+ $message = $form_input_values['null'];
2555
+ }
2556
+ } elseif ( array_key_exists('null', $_POST) ) {
2557
+ $message = $_POST['null'];
2558
+ }
2559
+
2560
+ $base_call_result = apbct_base_call(
2561
+ array(
2562
+ 'message' => $message,
2563
+ 'sender_email' => $sender_email,
2564
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_wplp'),
2565
+ )
2566
+ );
2567
+
2568
+ $ct_result = $base_call_result['ct_result'];
2569
+
2570
+ if ( $ct_result->allow == 0 ) {
2571
+ $cleantalk_comment = $ct_result->comment;
2572
+ } else {
2573
+ $cleantalk_comment = 'OK';
2574
+ }
2575
+
2576
+ Cookie::set($ct_wplp_result_label, $cleantalk_comment, strtotime("+5 seconds"), '/');
2577
+ } else {
2578
+ // Next POST/AJAX submit(s) of same WPLP form
2579
+ $cleantalk_comment = $_COOKIE[$ct_wplp_result_label];
2580
+ }
2581
+ if ( $cleantalk_comment !== 'OK' ) {
2582
+ ct_die_extended($cleantalk_comment);
2583
+ }
2584
  }
2585
 
2586
  /**
2587
  * Places a hiding field to Gravity forms.
2588
  * @return string
2589
  */
2590
+ function apbct_form__gravityForms__addField($form_string, $form)
2591
+ {
2592
+ $ct_hidden_field = 'ct_checkjs';
2593
 
2594
+ // Do not add a hidden field twice.
2595
+ if ( preg_match("/$ct_hidden_field/", $form_string) ) {
2596
+ return $form_string;
2597
+ }
2598
 
2599
+ $search = "</form>";
2600
 
2601
+ // Adding JS code
2602
+ $js_code = ct_add_hidden_fields($ct_hidden_field, true, false);
2603
+ $form_string = str_replace($search, $js_code . $search, $form_string);
2604
 
2605
+ // Adding field for multipage form. Look for cleantalk.php -> apbct_cookie();
2606
+ $append_string = isset($form['lastPageButton']) ? "<input type='hidden' name='ct_multipage_form' value='yes'>" : '';
2607
+ $form_string = str_replace($search, $append_string . $search, $form_string);
2608
 
2609
+ return $form_string;
2610
  }
2611
 
2612
  /**
2614
  * @return boolean
2615
  * @psalm-suppress UnusedVariable
2616
  */
2617
+ function apbct_form__gravityForms__testSpam($is_spam, $form, $entry)
2618
+ {
2619
+ global $apbct, $cleantalk_executed, $ct_gform_is_spam, $ct_gform_response;
2620
+
2621
+ if (
2622
+ $is_spam ||
2623
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2624
+ $cleantalk_executed // Return unchanged result if the submission was already tested.
2625
+ ) {
2626
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2627
+
2628
+ return $is_spam;
2629
+ }
2630
+
2631
+ $form_fields_for_ct = array();
2632
+ $form_fields = (isset($form['fields'])) ? $form['fields'] : false;
2633
+ $form_fields_intermediate = array();
2634
+ $email = '';
2635
+ $nickname = array();
2636
+
2637
+ if ( $form_fields ) {
2638
+ foreach ( $form_fields as $field ) {
2639
+ $field_id = $field['id'];
2640
+ $field_visibility = $field['visibility'];
2641
+ $field_type = $field['type'];
2642
+ $field_inputs = $field['inputs'];
2643
+
2644
+ if ( $field_inputs ) {
2645
+ foreach ( $field_inputs as $input ) {
2646
+ $input_id = $input['id'];
2647
+
2648
+ if ( isset($entry[$input_id]) && $entry[$input_id] ) {
2649
+ $form_fields_intermediate[] = array(
2650
+ 'f_name' => 'input_' . $input_id,
2651
+ 'f_visibility' => $field_visibility,
2652
+ 'f_type' => $field_type,
2653
+ 'f_data' => $entry[$input_id]
2654
+ );
2655
+ $form_fields_for_ct['input_' . $input_id] = $entry[$input_id];
2656
+ }
2657
+ }
2658
+ } else {
2659
+ if ( isset($entry[$field_id]) && $entry[$field_id] ) {
2660
+ $form_fields_intermediate[] = array(
2661
+ 'f_name' => 'input_' . $field_id,
2662
+ 'f_visibility' => $field_visibility,
2663
+ 'f_type' => $field_type,
2664
+ 'f_data' => $entry[$field_id]
2665
+ );
2666
+ $form_fields_for_ct['input_' . $field_id] = $entry[$field_id];
2667
+ }
2668
+ }
2669
+ }
2670
+ }
2671
+
2672
+ # Search nickname and email
2673
+ if ( $form_fields_intermediate ) {
2674
+ foreach ( $form_fields_intermediate as $field ) {
2675
+ if ( $field['f_type'] === 'email' ) {
2676
+ $email = $field['f_data'];
2677
+ }
2678
+
2679
+ if ( $field['f_type'] === 'name' ) {
2680
+ $nickname[] = $field['f_data'];
2681
+ }
2682
+ }
2683
+ }
2684
 
2685
+ if ( ! $form_fields_for_ct ) {
2686
+ foreach ( $entry as $key => $value ) {
2687
+ if ( is_numeric($key) ) {
2688
+ $form_fields_for_ct['input_' . $key] = $value;
2689
+ }
2690
+ }
2691
+ unset($key, $value);
2692
+ }
2693
 
2694
+ $ct_temp_msg_data = ct_get_fields_any($form_fields_for_ct, $email, array_shift($nickname));
2695
 
2696
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
2697
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2698
+ $subject = $ct_temp_msg_data['subject'] ?: '';
2699
+ $message = $ct_temp_msg_data['message'] ?: array();
2700
 
2701
+ if ( $subject !== '' ) {
2702
+ $message['subject'] = $subject;
2703
+ }
2704
 
2705
+ $checkjs = apbct_js_test('ct_checkjs', $_POST) ?: apbct_js_test('ct_checkjs', $_COOKIE, true);
2706
 
2707
+ $base_call_result = apbct_base_call(
2708
+ array(
2709
+ 'message' => $message,
2710
+ 'sender_email' => $sender_email,
2711
+ 'sender_nickname' => $sender_nickname,
2712
+ 'post_info' => array('comment_type' => 'contact_form_wordpress_gravity_forms'),
2713
+ 'js_on' => $checkjs,
2714
+ )
2715
+ );
2716
 
2717
+ $ct_result = $base_call_result['ct_result'];
2718
+ if ( $ct_result->allow == 0 ) {
2719
+ $is_spam = true;
2720
+ $ct_gform_is_spam = true;
2721
+ $ct_gform_response = $ct_result->comment;
2722
+ add_action('gform_entry_created', 'apbct_form__gravityForms__add_entry_note');
2723
+ }
2724
 
2725
+ return $is_spam;
2726
  }
2727
 
2728
+ function apbct_form__gravityForms__showResponse($confirmation, $form, $_entry, $_ajax)
2729
+ {
2730
+ global $ct_gform_is_spam, $ct_gform_response;
2731
 
2732
+ if ( ! empty($ct_gform_is_spam) ) {
2733
+ $confirmation = '<a id="gf_' . $form['id'] . '" class="gform_anchor" ></a><div id="gform_confirmation_wrapper_' . $form['id'] . '" class="gform_confirmation_wrapper "><div id="gform_confirmation_message_' . $form['id'] . '" class="gform_confirmation_message_' . $form['id'] . ' gform_confirmation_message"><font style="color: red">' . $ct_gform_response . '</font></div></div>';
2734
+ }
2735
 
2736
+ return $confirmation;
 
 
 
 
2737
  }
2738
 
2739
  /**
2740
  * Adds a note to the entry once the spam status is set (GF 2.4.18+).
2741
  *
2742
  * @param array $entry The entry that was created.
2743
+ *
2744
  * @psalm-suppress UndefinedClass
2745
  * @psalm-suppress UndefinedFunction
2746
  */
2747
+ function apbct_form__gravityForms__add_entry_note($entry)
2748
+ {
2749
+ if ( rgar($entry, 'status') !== 'spam' || ! method_exists('GFAPI', 'add_note') ) {
2750
+ return;
2751
+ }
2752
+
2753
+ GFAPI::add_note(
2754
+ $entry['id'],
2755
+ 0,
2756
+ 'CleanTalk',
2757
+ __('This entry has been marked as spam.', 'cleantalk-spam-protect'),
2758
+ 'cleantalk',
2759
+ 'success'
2760
+ );
2761
  }
2762
 
2763
  /**
2764
  * Test S2member registration
2765
  * @return bool|null with errors
2766
  */
2767
+ function ct_s2member_registration_test($post_key)
2768
+ {
2769
+ global $apbct;
2770
 
2771
+ if ( $apbct->settings['forms__registrations_test'] == 0 ) {
2772
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2773
 
2774
+ return null;
2775
+ }
 
 
2776
 
2777
+ $sender_email = isset($_POST[$post_key]['email']) ? sanitize_email($_POST[$post_key]['email']) : null;
2778
+ $sender_nickname = isset($_POST[$post_key]['username']) ? sanitize_email($_POST[$post_key]['username']) : null;
2779
 
2780
+ //Making a call
2781
+ $base_call_result = apbct_base_call(
2782
+ array(
2783
+ 'sender_email' => $sender_email,
2784
+ 'sender_nickname' => $sender_nickname,
2785
+ ),
2786
+ true
2787
+ );
2788
+ $ct_result = $base_call_result['ct_result'];
2789
 
2790
+ if ( $ct_result->allow == 0 ) {
2791
+ ct_die_extended($ct_result->comment);
2792
+ }
2793
 
2794
+ return true;
2795
  }
2796
 
2797
  /**
2798
  * @return false
2799
  * @psalm-suppress UnusedVariable
2800
  */
2801
+ function apbct_form__the7_contact_form()
2802
+ {
2803
+ global $cleantalk_executed;
2804
+
2805
+ if ( check_ajax_referer('dt_contact_form', 'nonce', false) && ! empty($_POST) ) {
2806
+ $post_info['comment_type'] = 'contact_the7_theme_contact_form';
2807
+
2808
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
2809
+
2810
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
2811
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2812
+ $subject = $ct_temp_msg_data['subject'] ?: '';
2813
+ $contact_form = ! $ct_temp_msg_data['contact'];
2814
+ $message = $ct_temp_msg_data['message'] ?: array();
2815
+ if ( $subject !== '' ) {
2816
+ $message = array_merge(array('subject' => $subject), $message);
2817
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2818
 
2819
+ // Skip submission if no data found
2820
+ if ( $sender_email === '' || ! $contact_form ) {
2821
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2822
 
2823
+ return false;
2824
+ }
2825
+ $cleantalk_executed = true;
2826
+
2827
+ $base_call_result = apbct_base_call(
2828
+ array(
2829
+ 'message' => $message,
2830
+ 'sender_email' => $sender_email,
2831
+ 'sender_nickname' => $sender_nickname,
2832
+ 'post_info' => $post_info,
2833
+ )
2834
+ );
2835
+
2836
+ $ct_result = $base_call_result['ct_result'];
2837
+ if ( $ct_result->allow == 0 ) {
2838
+ $response = json_encode(
2839
+ array(
2840
+ 'success' => false,
2841
+ 'errors' => $ct_result->comment,
2842
+ 'nonce' => wp_create_nonce('dt_contact_form')
2843
+ )
2844
+ );
2845
+
2846
+ // response output
2847
+ header("Content-Type: application/json");
2848
+ echo $response;
2849
+
2850
+ // IMPORTANT: don't forget to "exit"
2851
+ exit;
2852
+ }
2853
+ }
2854
 
2855
+ return false;
2856
  }
2857
 
2858
+ function apbct_form__elementor_pro__testSpam()
2859
+ {
2860
+ global $apbct;
2861
 
2862
+ if (
2863
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2864
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
2865
+ apbct_exclusions_check__url()
2866
+ ) {
2867
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2868
 
2869
+ return;
2870
+ }
 
 
 
 
 
 
2871
 
2872
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
2873
 
2874
+ $sender_email = $ct_temp_msg_data['email'] ?: '';
2875
+ $sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
2876
+ $subject = $ct_temp_msg_data['subject'] ?: '';
2877
+ $message = $ct_temp_msg_data['message'] ?: array();
2878
+ if ( $subject !== '' ) {
2879
+ $message = array_merge(array('subject' => $subject), $message);
2880
+ }
2881
 
2882
+ $post_info['comment_type'] = 'contact_form_wordpress_elementor_pro';
2883
 
2884
+ $base_call_result = apbct_base_call(
2885
+ array(
2886
+ 'message' => $message,
2887
+ 'sender_email' => $sender_email,
2888
+ 'sender_nickname' => $sender_nickname,
2889
+ 'post_info' => $post_info,
2890
+ )
2891
+ );
2892
 
2893
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
 
 
 
 
2894
 
2895
+ if ( $ct_result->allow == 0 ) {
2896
+ wp_send_json_error(array(
2897
+ 'message' => $ct_result->comment,
2898
+ 'data' => array()
2899
+ ));
2900
+ }
2901
  }
2902
 
2903
  // INEVIO theme integration
2904
+ function apbct_form__inevio__testSpam()
2905
+ {
2906
+ global $apbct;
2907
+
2908
+ $theme = wp_get_theme();
2909
+ if (
2910
+ stripos($theme->get('Name'), 'INEVIO') === false ||
2911
+ $apbct->settings['forms__contact_forms_test'] == 0 ||
2912
+ ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) || // Skip processing for logged in users.
2913
+ apbct_exclusions_check__url()
2914
+ ) {
2915
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
2916
+
2917
+ return false;
2918
+ }
2919
+ $form_data = array();
2920
+ parse_str($_POST['data'], $form_data);
2921
+
2922
+ $name = isset($form_data['name']) ? $form_data['name'] : '';
2923
+ $email = isset($form_data['email']) ? $form_data['email'] : '';
2924
+ $message = isset($form_data['message']) ? $form_data['message'] : '';
2925
+
2926
+ $post_info['comment_type'] = 'contact_form_wordpress_inevio_theme';
2927
+
2928
+ $base_call_result = apbct_base_call(
2929
+ array(
2930
+ 'message' => $message,
2931
+ 'sender_email' => $email,
2932
+ 'sender_nickname' => $name,
2933
+ 'post_info' => $post_info,
2934
+ )
2935
+ );
2936
+
2937
+ $ct_result = $base_call_result['ct_result'];
2938
+
2939
+ if ( $ct_result->allow == 0 ) {
2940
+ die(
2941
+ json_encode(
2942
+ array('apbct' => array('blocked' => true, 'comment' => $ct_result->comment,)),
2943
+ JSON_HEX_QUOT | JSON_HEX_TAG
2944
+ )
2945
+ );
2946
+ }
2947
+
2948
+ return true;
2949
  }
2950
 
2951
 
2955
  *
2956
  * @param $success array array( 'status' => 'success' )
2957
  * @param $data array ['username'] ['password'] ['email']
2958
+ *
2959
  * @return array array( 'status' => 'error' ) or array( 'status' => 'success' ) by default
2960
  */
2961
+ function apbct_wilcity_reg_validation($success, $data)
2962
+ {
2963
+ $check = ct_test_registration($data['username'], $data['email'], '');
2964
+ if ( $check['allow'] == 0 ) {
2965
+ return array('status' => 'error');
2966
+ }
2967
+
2968
+ return $success;
2969
  }
2970
 
2971
  /**
2979
  * @return mixed|null
2980
  * @psalm-suppress UnusedVariable
2981
  */
2982
+ function apbct_form__enfold_contact_form__test_spam($send, $new_post, $_form_params, $obj)
2983
+ {
2984
+ global $cleantalk_executed;
2985
 
2986
+ $url_decoded_data = array();
2987
+ foreach ( $new_post as $key => $value ) {
2988
+ $url_decoded_data[$key] = urldecode($value);
2989
+ }
2990
 
2991
+ $data = ct_get_fields_any($url_decoded_data);
 
 
 
2992
 
2993
+ $base_call_result = apbct_base_call(
2994
+ array(
2995
+ 'message' => ! empty($data['message']) ? json_encode($data['message']) : '',
2996
+ 'sender_email' => ! empty($data['email']) ? $data['email'] : '',
2997
+ 'sender_nickname' => ! empty($data['nickname']) ? $data['nickname'] : '',
2998
+ 'post_info' => array(
2999
+ 'comment_type' => 'contact_form_wordpress_enfold'
3000
+ ),
3001
+ )
3002
+ );
3003
 
3004
+ $ct_result = $base_call_result['ct_result'];
 
 
 
 
 
 
 
 
 
3005
 
3006
+ $cleantalk_executed = true;
3007
 
3008
+ if ( $ct_result->allow == 0 ) {
3009
+ $obj->submit_error = $ct_result->comment;
3010
 
3011
+ return null;
3012
+ }
 
 
 
 
3013
 
3014
+ return $send;
3015
  }
3016
 
3017
  /**
3024
  * @return mixed
3025
  * @psalm-suppress UnusedVariable
3026
  */
3027
+ function apbct_form_profile_builder__check_register($errors, $_fields, $global_request)
3028
+ {
3029
+ global $cleantalk_executed;
3030
+
3031
+ if ( isset($global_request['action']) && $global_request['action'] === 'register' ) {
3032
+ $data = ct_get_fields_any($global_request);
3033
+
3034
+ $base_call_result = apbct_base_call(
3035
+ array(
3036
+ 'message' => ! empty($data['message']) ? json_encode($data['message']) : '',
3037
+ 'sender_email' => ! empty($data['email']) ? $data['email'] : '',
3038
+ 'sender_nickname' => ! empty($data['nickname']) ? $data['nickname'] : '',
3039
+ 'post_info' => array(
3040
+ 'comment_type' => 'register_profile_builder'
3041
+ ),
3042
+ ),
3043
+ true
3044
+ );
3045
+
3046
+ $ct_result = $base_call_result['ct_result'];
3047
+
3048
+ $cleantalk_executed = true;
3049
+
3050
+ if ( $ct_result->allow == 0 ) {
3051
+ $errors['error'] = $ct_result->comment;
3052
+ $GLOBALS['global_profile_builder_error'] = $ct_result->comment;
3053
+
3054
+ add_filter('wppb_general_top_error_message', 'apbct_form_profile_builder__error_message', 1);
3055
+ }
3056
+ }
 
 
3057
 
3058
+ return $errors;
3059
  }
3060
 
3061
  /**
3062
  * Profile Builder Integration - add error message in response
3063
  */
3064
+ function apbct_form_profile_builder__error_message()
3065
+ {
3066
+ return '<p id="wppb_form_general_message" class="wppb-error">' . $GLOBALS['global_profile_builder_error'] . '</p>';
3067
  }
3068
 
3069
  /**
3074
  * @return array|mixed
3075
  * @psalm-suppress UnusedVariable
3076
  */
3077
+ function wpforo_create_profile__check_register($user_fields)
3078
+ {
3079
+ global $ct_signup_done;
3080
 
3081
+ $ip = Helper::ipGet('real', false);
3082
+ $check = ct_test_registration($user_fields['user_login'], $user_fields['user_email'], $ip);
3083
+ if ( $check['allow'] == 0 ) {
3084
+ return array('error' => $check['comment']);
3085
+ }
3086
 
3087
+ $ct_signup_done = true;
 
 
 
 
3088
 
3089
+ return $user_fields;
 
3090
  }
3091
 
3092
  /**
3093
  * Function checks for signs in the post request to perform validation and returns true|false
3094
  */
3095
+ function apbct_custom_forms_trappings()
3096
+ {
3097
+ global $apbct;
3098
 
3099
+ // Registration form of Wishlist Members plugin
3100
+ if ( $apbct->settings['forms__registrations_test'] && isset($_POST['action']) && $_POST['action'] === 'wpm_register' ) {
3101
+ return true;
3102
+ }
3103
 
3104
+ return false;
3105
+ }
inc/cleantalk-public-validate.php CHANGED
@@ -5,406 +5,419 @@ use Cleantalk\Variables\Server;
5
  /**
6
  * General test for any contact form
7
  */
8
- function ct_contact_form_validate() {
9
-
10
- global $pagenow ,$apbct, $ct_checkjs_frm;
11
-
12
- // Exclusios common function
13
- if ( apbct_exclusions_check(__FUNCTION__) ) {
14
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
15
- return null;
16
- }
17
-
18
- if (@sizeof($_POST)==0 ||
19
- (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
20
- (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
21
- (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action']=='lostpassword') ||
22
- apbct_is_in_referer( 'lostpassword' ) ||
23
- apbct_is_in_referer( 'lost-password' ) || //Skip lost-password form check
24
- (apbct_is_in_uri('/wp-admin/') && (empty($_POST['your-phone']) && empty($_POST['your-email']) && empty($_POST['your-message']))) || //Bitrix24 Contact
25
- apbct_is_in_uri('wp-login.php') ||
26
- apbct_is_in_uri('wp-comments-post.php') ||
27
- apbct_is_in_uri('?provider=facebook&') ||
28
- apbct_is_in_uri('reset-password/') || // Ticket #13668. Password reset.
29
- apbct_is_in_referer( '/wp-admin/') ||
30
- apbct_is_in_uri('/login/') ||
31
- apbct_is_in_uri( '/my-account/edit-account/') || // WooCommerce edit account page
32
- apbct_is_in_uri( '/my-account/edit-address/') || // WooCommerce edit account page
33
- (isset($_POST['action']) && $_POST['action'] == 'save_account_details') || // WooCommerce edit account action
34
- apbct_is_in_uri( '/peepsoajax/profilefieldsajax.validate_register') ||
35
- isset($_GET['ptype']) && $_GET['ptype']=='login' ||
36
- isset($_POST['ct_checkjs_register_form']) ||
37
- (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit']) ) ||
38
- $apbct->settings['forms__general_contact_forms_test'] == 0 ||
39
- isset($_POST['bbp_topic_content']) ||
40
- isset($_POST['bbp_reply_content']) ||
41
- isset($_POST['fscf_submitted']) ||
42
- apbct_is_in_uri('/wc-api') ||
43
- isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit']) ||
44
- isset($_POST[$ct_checkjs_frm]) && $apbct->settings['forms__contact_forms_test'] == 1 ||// Formidable forms
45
- ( isset($_POST['comment_post_ID']) && ! isset($_POST['comment-submit'] ) ) || // The comment form && ! DW Question & Answer
46
- isset($_GET['for']) ||
47
- (isset($_POST['log'], $_POST['pwd'])) || //WooCommerce Sensei login form fix
48
- (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || // WooCommerce recovery password form
49
- ((isset($_POST['woocommerce-login-nonce']) || isset($_POST['_wpnonce'])) && isset($_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || // WooCommerce login form
50
- (isset($_POST['wc-api']) && strtolower($_POST['wc-api']) == 'wc_gateway_systempay') || // Woo Systempay payment plugin
51
- apbct_is_in_uri( 'wc-api=WC_Gateway_Realex_Redirect') || // Woo Realex payment Gateway plugin
52
- apbct_is_in_uri( 'wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
53
- (isset($_POST['_wpcf7'], $_POST['_wpcf7_version'], $_POST['_wpcf7_locale'])) || //CF7 fix)
54
- (isset($_POST['hash'], $_POST['device_unique_id'], $_POST['device_name'])) ||//Mobile Assistant Connector fix
55
- isset($_POST['gform_submit']) || //Gravity form
56
- apbct_is_in_uri( 'wc-ajax=get_refreshed_fragments') ||
57
- (isset($_POST['ccf_form']) && intval($_POST['ccf_form']) == 1) ||
58
- (isset($_POST['contact_tags']) && strpos($_POST['contact_tags'], 'MBR:') !== false) ||
59
- (apbct_is_in_uri( 'bizuno.php') && !empty($_POST['bizPass'])) ||
60
- apbct_is_in_referer( 'my-dashboard/' ) || // ticket_id=7885
61
- isset($_POST['slm_action'], $_POST['license_key'], $_POST['secret_key'], $_POST['registered_domain']) || // ticket_id=9122
62
- (isset($_POST['wpforms']['submit']) && $_POST['wpforms']['submit'] == 'wpforms-submit') || // WPForms
63
- (isset($_POST['action']) && $_POST['action'] == 'grunion-contact-form') || // JetPack
64
- (isset($_POST['action']) && $_POST['action'] == 'bbp-update-user') || //BBP update user info page
65
- apbct_is_in_referer( '?wc-api=WC_Gateway_Transferuj' ) || //WC Gateway
66
- (isset($_GET['mbr'], $_GET['amp;appname'], $_GET['amp;master'])) || // ticket_id=10773
67
- (isset($_POST['call_function']) && $_POST['call_function'] == 'push_notification_settings') || // Skip mobile requests (push settings)
68
- apbct_is_in_uri('membership-login') || // Skip login form
69
- (isset($_GET['cookie-state-change'])) || //skip GDPR plugin
70
- ( apbct_get_server_variable( 'HTTP_USER_AGENT' ) == 'MailChimp' && apbct_is_in_uri( 'mc4wp-sync-api/webhook-listener') ) || // Mailchimp webhook skip
71
- apbct_is_in_uri('researcher-log-in') || // Skip login form
72
- apbct_is_in_uri('admin_aspcms/_system/AspCms_SiteSetting.asp?action=saves') || // Skip admin save callback
73
- apbct_is_in_uri('?profile_tab=postjobs') || // Skip post vacancies
74
- (isset($_POST['btn_insert_post_type_hotel']) && $_POST['btn_insert_post_type_hotel'] == 'SUBMIT HOTEL') || // Skip adding hotel
75
- (isset($_POST['action']) && $_POST['action'] == 'updraft_savesettings') || // Updraft save settings
76
- isset($_POST['quform_submit']) || //QForms multi-paged form skip
77
- (isset($_POST['wpum_form']) && $_POST['wpum_form'] == 'login') || //WPUM login skip
78
- (isset($_POST['password']) && !apbct_custom_forms_trappings()) || // Exception for login form. From Analysis uid=406596
79
- (isset($_POST['action']) && $_POST['action'] == 'wilcity_reset_password') || // Exception for reset password form. From Analysis uid=430898
80
- (isset($_POST['action']) && $_POST['action'] == 'wilcity_login') || // Exception for login form. From Analysis uid=430898
81
- (isset($_POST['qcfsubmit'])) || //Exception for submit quick forms - duplicates with qcfvalidate
82
- apbct_is_in_uri('tin-canny-learndash-reporting/src/h5p-xapi/process-xapi-statement.php?v=asd') || //Skip Tin Canny plugin
83
- ( isset( $_POST['na'], $_POST['ts'], $_POST['nhr'] ) && !apbct_is_in_uri( '?na=s' ) ) || // The Newsletter Plugin double requests fix. Ticket #14772
84
- (isset($_POST['spl_action']) && $_POST['spl_action'] == 'register') || //Skip interal action with empty params
85
- (isset($_POST['action']) && $_POST['action'] == 'bwfan_insert_abandoned_cart' && apbct_is_in_uri( 'my-account/edit-address' )) || //Skip edit account
86
- apbct_is_in_uri('login-1') || //Skip login form
87
- apbct_is_in_uri('recuperacao-de-senha-2') || //Skip form reset password
88
- apbct_is_in_uri('membermouse/api/request.php') && isset($_POST['membership_level_id'],$_POST['apikey'],$_POST['apisecret']) || // Membermouse API
89
- ( isset( $_POST['AppKey'] ) && ( isset( $_POST['cbAP'] ) && $_POST['cbAP'] == 'Caspio' ) ) || // Caspio exclusion (ticket #16444)
90
- isset($_POST['wpforms_id'], $_POST['wpforms_author']) || //Skip wpforms
91
- ( isset( $_POST['somfrp_action'], $_POST['submitted'] ) && $_POST['somfrp_action'] == 'somfrp_lost_pass' ) || // Frontend Reset Password exclusion
92
- ( isset( $_POST['action'] ) && $_POST['action'] == 'dokan_save_account_details' ) ||
93
- \Cleantalk\Variables\Post::get('action') === 'frm_get_lookup_text_value' || // Exception for Formidable multilevel form
94
- ( isset( $_POST['ihcaction'] ) && $_POST['ihcaction'] == 'reset_pass') || //Reset pass exclusion
95
- ( isset( $_POST['action'], $_POST['register_unspecified_nonce_field'] ) && $_POST['action'] == 'register' ) || // Profile Builder have a direct integration
96
- ( isset( $_POST['_wpmem_register_nonce'] ) && wp_verify_nonce( $_POST['_wpmem_register_nonce'], 'wpmem_longform_nonce' ) ) || // WP Members have a direct integration
97
- apbct_is_in_uri('/settings/') && isset($_POST['submit']) || // Buddypress integration
98
- apbct_is_in_uri('/settings/notifications/') && isset($_POST['submit']) || // Buddypress integration
99
- apbct_is_in_uri('/settings/profile/') && isset($_POST['submit']) || // Buddypress integration
100
- apbct_is_in_uri('/settings/data/') && isset($_POST['submit']) || // Buddypress integration
101
- apbct_is_in_uri('/settings/delete-account/') && isset($_POST['submit']) || // Buddypress integration
102
- apbct_is_in_uri('/profile/') && isset($_POST['submit']) || // Buddypress integration
103
- ( isset( $_POST['action'] ) && $_POST['action'] == 'bwfan_insert_abandoned_cart' ) || // Autonami Marketing Automations - WC Plugin - integration
104
- ( isset( $_POST['action'] ) && $_POST['action'] == 'check_email_exists' ) || // Handling an unknown action check_email_exists
105
- Server::in_uri( 'cleantalk-antispam/v1/alt_sessions') // Skip test for alt sessions
106
- /* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
107
- ) {
108
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
109
- return null;
110
- }
111
-
112
- // Skip REST API requests
113
- if ( Server::isPost() && Server::in_uri( 'rest_route') )
114
- {
115
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
116
- return null;
117
- }
118
-
119
- //Skip woocommerce checkout
120
- if (apbct_is_in_uri('wc-ajax=update_order_review') ||
121
- apbct_is_in_uri('wc-ajax=checkout') ||
122
- !empty($_POST['woocommerce_checkout_place_order']) ||
123
- apbct_is_in_uri('wc-ajax=wc_ppec_start_checkout') ||
124
- apbct_is_in_referer('wc-ajax=update_order_review')
125
- )
126
- {
127
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
128
- return null;
129
- }
130
-
131
- //Skip woocommerce add_to_cart
132
- if( ! empty( $_POST['add-to-cart'] ) )
133
- {
134
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
135
- return null;
136
- }
137
-
138
- // Do not execute anti-spam test for logged in users.
139
- if (isset($_COOKIE[LOGGED_IN_COOKIE]) && $apbct->settings['data__protect_logged_in'] != 1) {
140
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
141
- return null;
142
- }
143
- //Skip WP Fusion web hooks
144
- if ( apbct_is_in_uri('wpf_action') && apbct_is_in_uri('access_key') && isset( $_GET['access_key'] ) ) {
145
- if( function_exists( 'wp_fusion' ) ) {
146
- $key = wp_fusion()->settings->get('access_key');
147
- if ( $key == $_GET['access_key'] ) {
148
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
149
- return null;
150
- }
151
- }
152
- }
153
- //Skip system fields for divi
154
- if (strpos( \Cleantalk\Variables\Post::get('action'), 'et_pb_contactform_submit') === 0) {
155
- foreach ($_POST as $key => $value) {
156
- if (strpos($key, 'et_pb_contact_email_fields') === 0) {
157
- unset($_POST[$key]);
158
- }
159
- }
160
- }
161
-
162
- if( apbct_is_skip_request( false ) ) {
163
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . '(' . apbct_is_skip_request() . ')', $_POST );
164
- return false;
165
- }
166
-
167
- $post_info['comment_type'] = 'feedback_general_contact_form';
168
-
169
- $ct_temp_msg_data = ct_get_fields_any($_POST);
170
-
171
- $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
172
- $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
173
- $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
174
- $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
175
- $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
176
- if ($subject != '') {
177
- $message = array_merge(array('subject' => $subject), $message);
178
- }
179
-
180
- // Skip submission if no data found
181
- if ($sender_email === ''|| !$contact_form) {
182
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
183
- return false;
184
- }
185
-
186
- if(isset($_POST['TellAFriend_Link'])){
187
- $tmp = $_POST['TellAFriend_Link'];
188
- unset($_POST['TellAFriend_Link']);
189
- }
190
-
191
- $base_call_result = apbct_base_call(
192
- array(
193
- 'message' => $message,
194
- 'sender_email' => $sender_email,
195
- 'sender_nickname' => $sender_nickname,
196
- 'post_info' => $post_info,
197
- 'sender_info' => array( 'sender_email' => urlencode( $sender_email ) ),
198
- )
199
- );
200
-
201
- if(isset($_POST['TellAFriend_Link'])){
202
- $_POST['TellAFriend_Link']=$tmp;
203
- }
204
-
205
- $ct_result = $base_call_result['ct_result'];
206
- if ($ct_result->allow == 0) {
207
-
208
- // Recognize contact form an set it's name to $contact_form to use later
209
- $contact_form = null;
210
- foreach($_POST as $param => $value){
211
- if(strpos($param, 'et_pb_contactform_submit') === 0){
212
- $contact_form = 'contact_form_divi_theme';
213
- $contact_form_additional = str_replace('et_pb_contactform_submit', '', $param);
214
- }
215
- if(strpos($param, 'avia_generated_form') === 0){
216
- $contact_form = 'contact_form_enfold_theme';
217
- $contact_form_additional = str_replace('avia_generated_form', '', $param);
218
- }
219
- if(!empty($contact_form))
220
- break;
221
- }
222
-
223
- $ajax_call = false;
224
- if ((defined( 'DOING_AJAX' ) && DOING_AJAX)
225
- ) {
226
- $ajax_call = true;
227
- }
228
- if ($ajax_call) {
229
- echo $ct_result->comment;
230
- } else {
231
-
232
- global $ct_comment;
233
- $ct_comment = $ct_result->comment;
234
- if(isset($_POST['cma-action'])&&$_POST['cma-action']=='add'){
235
- $result=Array('success'=>0, 'thread_id'=>null,'messages'=>Array($ct_result->comment));
236
- header("Content-Type: application/json");
237
- print json_encode($result);
238
- die();
239
-
240
- }else if(isset($_POST['TellAFriend_email'])){
241
- echo $ct_result->comment;
242
- die();
243
-
244
- }else if(isset($_POST['gform_submit'])){ // Gravity forms submission
245
- $response = sprintf("<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'><div id='gform_confirmation_wrapper_1' class='gform_confirmation_wrapper '><div id='gform_confirmation_message_1' class='gform_confirmation_message_1
 
 
 
 
 
 
 
 
246
  gform_confirmation_message'>%s</div></div></body></html>",
247
- $ct_result->comment
248
- );
249
- echo $response;
250
- die();
251
-
252
- }elseif(isset($_POST['action']) && $_POST['action'] == 'ct_check_internal'){
253
- return $ct_result->comment;
254
-
255
- }elseif(isset($_POST['vfb-submit']) && defined('VFB_VERSION')){
256
- wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
257
- // Caldera Contact Forms
258
- }elseif(isset($_POST['action']) && $_POST['action'] == 'cf_process_ajax_submit'){
259
- print "<h3 style='color: red;'><red>".$ct_result->comment."</red></h3>";
260
- die();
261
- // Mailster
262
- }elseif(isset($_POST['_referer'], $_POST['formid'], $_POST['email'])){
263
- $return = array(
264
- 'success' => false,
265
- 'html' => '<p>' . $ct_result->comment . '</p>',
266
- );
267
- print json_encode($return);
268
- die();
269
- // Divi Theme Contact Form. Using $contact_form
270
- }elseif(!empty($contact_form) && $contact_form == 'contact_form_divi_theme'){
271
- echo "<div id='et_pb_contact_form{$contact_form_additional}'><h1>Your request looks like spam.</h1><div><p>{$ct_result->comment}</p></div></div>";
272
- die();
273
- // Enfold Theme Contact Form. Using $contact_form
274
- }elseif(!empty($contact_form) && $contact_form == 'contact_form_enfold_theme'){
275
- echo "<div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1' style='display: block;'><div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1'><h3 class='avia-form-success'>Antispam by CleanTalk: ".$ct_result->comment."</h3><a href='.'><-Back</a></div></div>";
276
- die();
277
- }else{
278
- ct_die(null, null);
279
- }
280
- }
281
- exit;
282
- }
283
-
284
- return null;
 
 
 
 
 
285
  }
286
 
287
  /**
288
  * General test for any post data
289
  */
290
- function ct_contact_form_validate_postdata() {
291
-
292
- global $apbct, $pagenow,$cleantalk_executed;
293
-
294
- // Exclusios common function
295
- if ( apbct_exclusions_check(__FUNCTION__) ) {
296
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
297
- return null;
298
- }
299
-
300
- if (@sizeof($_POST)==0 ||
301
- (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
302
- (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
303
- (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action']=='lostpassword') ||
304
- apbct_is_in_uri('/checkout/') ||
305
- /* WooCommerce Service Requests - skip them */
306
- isset($_GET['wc-ajax']) && (
307
- $_GET['wc-ajax']=='checkout' ||
308
- $_GET['wc-ajax']=='get_refreshed_fragments' ||
309
- $_GET['wc-ajax']=='apply_coupon' ||
310
- $_GET['wc-ajax']=='remove_coupon' ||
311
- $_GET['wc-ajax']=='update_shipping_method' ||
312
- $_GET['wc-ajax']=='get_cart_totals' ||
313
- $_GET['wc-ajax']=='update_order_review' ||
314
- $_GET['wc-ajax']=='add_to_cart' ||
315
- $_GET['wc-ajax']=='remove_from_cart' ||
316
- $_GET['wc-ajax']=='get_variation' ||
317
- $_GET['wc-ajax']=='get_customer_location'
318
- ) ||
319
- /* END: WooCommerce Service Requests */
320
- apbct_is_in_uri('/wp-admin/') ||
321
- apbct_is_in_uri('wp-login.php') ||
322
- apbct_is_in_uri('wp-comments-post.php') ||
323
- apbct_is_in_referer('/wp-admin/') ||
324
- apbct_is_in_uri('/login/') ||
325
- apbct_is_in_uri('?provider=facebook&') ||
326
- isset($_GET['ptype']) && $_GET['ptype']=='login' ||
327
- isset($_POST['ct_checkjs_register_form']) ||
328
- (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit']) ) ||
329
- $apbct->settings['forms__general_contact_forms_test']==0 ||
330
- isset($_POST['bbp_topic_content']) ||
331
- isset($_POST['bbp_reply_content']) ||
332
- isset($_POST['fscf_submitted']) ||
333
- isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit'])||
334
- apbct_is_in_uri('/wc-api') ||
335
- apbct_is_in_uri( 'wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
336
- (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || //WooCommerce recovery password form
337
- (isset($_POST['woocommerce-login-nonce'], $_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || //WooCommerce login form
338
- (isset($_POST['provider'], $_POST['authcode']) && $_POST['provider'] == 'Two_Factor_Totp') || //TwoFactor authorization
339
- (isset($_GET['wc-ajax']) && $_GET['wc-ajax'] == 'sa_wc_buy_now_get_ajax_buy_now_button') || //BuyNow add to cart
340
- apbct_is_in_uri('/wp-json/wpstatistics/v1/hit') || //WPStatistics
341
- (isset($_POST['ihcaction']) && $_POST['ihcaction'] == 'login') || //Skip login form
342
- (isset($_POST['action']) && $_POST['action'] == 'infinite_scroll') || //Scroll
343
- isset($_POST['gform_submit']) || //Skip gravity checking because of direct integration
344
- (isset($_POST['lrm_action']) && $_POST['lrm_action'] == 'login') || //Skip login form
345
- apbct_is_in_uri( 'xmlrpc.php?for=jetpack' ) ||
346
- apbct_is_in_uri( 'connector=bridge&task=put_sql' ) ||
347
- Server::in_uri( 'cleantalk-antispam/v1/alt_sessions') || // Skip test for alt sessions
348
- ( apbct_is_in_uri( 'bvMethod=' ) && apbct_is_in_uri( 'bvVersion=' ) && isset($_POST['apipage']) && $_POST['apipage'] === 'blogvault' )
349
- ) {
350
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
351
- return null;
352
- }
353
-
354
- $message = ct_get_fields_any_postdata($_POST);
355
-
356
- // ???
357
- if(strlen(json_encode($message))<10) {
358
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
359
- return null;
360
- }
361
-
362
-
363
- // Skip if request contains params
364
- $skip_params = array(
365
- 'ipn_track_id', // PayPal IPN #
366
- 'txn_type', // PayPal transaction type
367
- 'payment_status', // PayPal payment status
368
- );
369
- foreach($skip_params as $key=>$value){
370
- if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST)) {
371
- do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
372
- return null;
373
- }
374
- }
375
-
376
- $base_call_result = apbct_base_call(
377
- array(
378
- 'message' => $message,
379
- 'post_info' => array('comment_type' => 'feedback_general_postdata'),
380
- )
381
- );
382
-
383
- $cleantalk_executed=true;
384
-
385
- $ct_result = $base_call_result['ct_result'];
386
-
387
- if ($ct_result->allow == 0) {
388
-
389
- if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
390
- global $ct_comment;
391
- $ct_comment = $ct_result->comment;
392
- if(isset($_POST['cma-action'])&&$_POST['cma-action']=='add')
393
- {
394
- $result=Array('success'=>0, 'thread_id'=>null,'messages'=>Array($ct_result->comment));
395
- header("Content-Type: application/json");
396
- print json_encode($result);
397
- die();
398
- }
399
- else
400
- {
401
- ct_die(null, null);
402
- }
403
- } else {
404
- echo $ct_result->comment;
405
- }
406
- exit;
407
- }
408
-
409
- return null;
410
- }
5
  /**
6
  * General test for any contact form
7
  */
8
+ function ct_contact_form_validate()
9
+ {
10
+ global $pagenow, $apbct, $ct_checkjs_frm;
11
+
12
+ // Exclusios common function
13
+ if ( apbct_exclusions_check(__FUNCTION__) ) {
14
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
15
+
16
+ return null;
17
+ }
18
+
19
+ if ( @sizeof($_POST) == 0 ||
20
+ (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
21
+ (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
22
+ (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action'] == 'lostpassword') ||
23
+ apbct_is_in_referer('lostpassword') ||
24
+ apbct_is_in_referer('lost-password') || //Skip lost-password form check
25
+ (apbct_is_in_uri('/wp-admin/') && (empty($_POST['your-phone']) && empty($_POST['your-email']) && empty($_POST['your-message']))) || //Bitrix24 Contact
26
+ apbct_is_in_uri('wp-login.php') ||
27
+ apbct_is_in_uri('wp-comments-post.php') ||
28
+ apbct_is_in_uri('?provider=facebook&') ||
29
+ apbct_is_in_uri('reset-password/') || // Ticket #13668. Password reset.
30
+ apbct_is_in_referer('/wp-admin/') ||
31
+ apbct_is_in_uri('/login/') ||
32
+ apbct_is_in_uri('/my-account/edit-account/') || // WooCommerce edit account page
33
+ apbct_is_in_uri('/my-account/edit-address/') || // WooCommerce edit account page
34
+ (isset($_POST['action']) && $_POST['action'] == 'save_account_details') || // WooCommerce edit account action
35
+ apbct_is_in_uri('/peepsoajax/profilefieldsajax.validate_register') ||
36
+ (isset($_GET['ptype']) && $_GET['ptype'] == 'login') ||
37
+ isset($_POST['ct_checkjs_register_form']) ||
38
+ (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit'])) ||
39
+ $apbct->settings['forms__general_contact_forms_test'] == 0 ||
40
+ isset($_POST['bbp_topic_content']) ||
41
+ isset($_POST['bbp_reply_content']) ||
42
+ isset($_POST['fscf_submitted']) ||
43
+ apbct_is_in_uri('/wc-api') ||
44
+ (isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit'])) ||
45
+ (isset($_POST[$ct_checkjs_frm]) && $apbct->settings['forms__contact_forms_test'] == 1) || // Formidable forms
46
+ (isset($_POST['comment_post_ID']) && ! isset($_POST['comment-submit'])) || // The comment form && ! DW Question & Answer
47
+ isset($_GET['for']) ||
48
+ (isset($_POST['log'], $_POST['pwd'])) || //WooCommerce Sensei login form fix
49
+ (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || // WooCommerce recovery password form
50
+ ((isset($_POST['woocommerce-login-nonce']) || isset($_POST['_wpnonce'])) && isset($_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || // WooCommerce login form
51
+ (isset($_POST['wc-api']) && strtolower($_POST['wc-api']) === 'wc_gateway_systempay') || // Woo Systempay payment plugin
52
+ apbct_is_in_uri('wc-api=WC_Gateway_Realex_Redirect') || // Woo Realex payment Gateway plugin
53
+ apbct_is_in_uri('wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
54
+ (isset($_POST['_wpcf7'], $_POST['_wpcf7_version'], $_POST['_wpcf7_locale'])) || //CF7 fix)
55
+ (isset($_POST['hash'], $_POST['device_unique_id'], $_POST['device_name'])) || //Mobile Assistant Connector fix
56
+ isset($_POST['gform_submit']) || //Gravity form
57
+ apbct_is_in_uri('wc-ajax=get_refreshed_fragments') ||
58
+ (isset($_POST['ccf_form']) && intval($_POST['ccf_form']) == 1) ||
59
+ (isset($_POST['contact_tags']) && strpos($_POST['contact_tags'], 'MBR:') !== false) ||
60
+ (apbct_is_in_uri('bizuno.php') && ! empty($_POST['bizPass'])) ||
61
+ apbct_is_in_referer('my-dashboard/') || // ticket_id=7885
62
+ isset($_POST['slm_action'], $_POST['license_key'], $_POST['secret_key'], $_POST['registered_domain']) || // ticket_id=9122
63
+ (isset($_POST['wpforms']['submit']) && $_POST['wpforms']['submit'] == 'wpforms-submit') || // WPForms
64
+ (isset($_POST['action']) && $_POST['action'] == 'grunion-contact-form') || // JetPack
65
+ (isset($_POST['action']) && $_POST['action'] == 'bbp-update-user') || //BBP update user info page
66
+ apbct_is_in_referer('?wc-api=WC_Gateway_Transferuj') || //WC Gateway
67
+ (isset($_GET['mbr'], $_GET['amp;appname'], $_GET['amp;master'])) || // ticket_id=10773
68
+ (isset($_POST['call_function']) && $_POST['call_function'] == 'push_notification_settings') || // Skip mobile requests (push settings)
69
+ apbct_is_in_uri('membership-login') || // Skip login form
70
+ (isset($_GET['cookie-state-change'])) || //skip GDPR plugin
71
+ (apbct_get_server_variable('HTTP_USER_AGENT') == 'MailChimp' && apbct_is_in_uri('mc4wp-sync-api/webhook-listener')) || // Mailchimp webhook skip
72
+ apbct_is_in_uri('researcher-log-in') || // Skip login form
73
+ apbct_is_in_uri('admin_aspcms/_system/AspCms_SiteSetting.asp?action=saves') || // Skip admin save callback
74
+ apbct_is_in_uri('?profile_tab=postjobs') || // Skip post vacancies
75
+ (isset($_POST['btn_insert_post_type_hotel']) && $_POST['btn_insert_post_type_hotel'] == 'SUBMIT HOTEL') || // Skip adding hotel
76
+ (isset($_POST['action']) && $_POST['action'] == 'updraft_savesettings') || // Updraft save settings
77
+ isset($_POST['quform_submit']) || //QForms multi-paged form skip
78
+ (isset($_POST['wpum_form']) && $_POST['wpum_form'] == 'login') || //WPUM login skip
79
+ (isset($_POST['password']) && ! apbct_custom_forms_trappings()) || // Exception for login form. From Analysis uid=406596
80
+ (isset($_POST['action']) && $_POST['action'] == 'wilcity_reset_password') || // Exception for reset password form. From Analysis uid=430898
81
+ (isset($_POST['action']) && $_POST['action'] == 'wilcity_login') || // Exception for login form. From Analysis uid=430898
82
+ (isset($_POST['qcfsubmit'])) || //Exception for submit quick forms - duplicates with qcfvalidate
83
+ apbct_is_in_uri('tin-canny-learndash-reporting/src/h5p-xapi/process-xapi-statement.php?v=asd') || //Skip Tin Canny plugin
84
+ (isset($_POST['na'], $_POST['ts'], $_POST['nhr']) && ! apbct_is_in_uri('?na=s')) || // The Newsletter Plugin double requests fix. Ticket #14772
85
+ (isset($_POST['spl_action']) && $_POST['spl_action'] == 'register') || //Skip interal action with empty params
86
+ (isset($_POST['action']) && $_POST['action'] == 'bwfan_insert_abandoned_cart' && apbct_is_in_uri('my-account/edit-address')) || //Skip edit account
87
+ apbct_is_in_uri('login-1') || //Skip login form
88
+ apbct_is_in_uri('recuperacao-de-senha-2') || //Skip form reset password
89
+ (apbct_is_in_uri('membermouse/api/request.php') && isset($_POST['membership_level_id'], $_POST['apikey'], $_POST['apisecret'])) || // Membermouse API
90
+ (isset($_POST['AppKey']) && (isset($_POST['cbAP']) && $_POST['cbAP'] == 'Caspio')) || // Caspio exclusion (ticket #16444)
91
+ isset($_POST['wpforms_id'], $_POST['wpforms_author']) || //Skip wpforms
92
+ (isset($_POST['somfrp_action'], $_POST['submitted']) && $_POST['somfrp_action'] == 'somfrp_lost_pass') || // Frontend Reset Password exclusion
93
+ (isset($_POST['action']) && $_POST['action'] == 'dokan_save_account_details') ||
94
+ \Cleantalk\Variables\Post::get('action') === 'frm_get_lookup_text_value' || // Exception for Formidable multilevel form
95
+ (isset($_POST['ihcaction']) && $_POST['ihcaction'] == 'reset_pass') || //Reset pass exclusion
96
+ (isset($_POST['action'], $_POST['register_unspecified_nonce_field']) && $_POST['action'] == 'register') || // Profile Builder have a direct integration
97
+ (isset($_POST['_wpmem_register_nonce']) && wp_verify_nonce($_POST['_wpmem_register_nonce'], 'wpmem_longform_nonce')) || // WP Members have a direct integration
98
+ (apbct_is_in_uri('/settings/') && isset($_POST['submit'])) || // Buddypress integration
99
+ (apbct_is_in_uri('/settings/notifications/') && isset($_POST['submit'])) || // Buddypress integration
100
+ (apbct_is_in_uri('/settings/profile/') && isset($_POST['submit'])) || // Buddypress integration
101
+ (apbct_is_in_uri('/settings/data/') && isset($_POST['submit'])) || // Buddypress integration
102
+ (apbct_is_in_uri('/settings/delete-account/') && isset($_POST['submit'])) || // Buddypress integration
103
+ (apbct_is_in_uri('/profile/') && isset($_POST['submit'])) || // Buddypress integration
104
+ (isset($_POST['action']) && $_POST['action'] == 'bwfan_insert_abandoned_cart') || // Autonami Marketing Automations - WC Plugin - integration
105
+ (isset($_POST['action']) && $_POST['action'] == 'check_email_exists') || // Handling an unknown action check_email_exists
106
+ Server::inUri('cleantalk-antispam/v1/alt_sessions') // Skip test for alt sessions
107
+ /* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
108
+ ) {
109
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
110
+
111
+ return null;
112
+ }
113
+
114
+ // Skip REST API requests
115
+ if ( Server::isPost() && Server::inUri('rest_route') ) {
116
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
117
+
118
+ return null;
119
+ }
120
+
121
+ //Skip woocommerce checkout
122
+ if ( apbct_is_in_uri('wc-ajax=update_order_review') ||
123
+ apbct_is_in_uri('wc-ajax=checkout') ||
124
+ ! empty($_POST['woocommerce_checkout_place_order']) ||
125
+ apbct_is_in_uri('wc-ajax=wc_ppec_start_checkout') ||
126
+ apbct_is_in_referer('wc-ajax=update_order_review')
127
+ ) {
128
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
129
+
130
+ return null;
131
+ }
132
+
133
+ //Skip woocommerce add_to_cart
134
+ if ( ! empty($_POST['add-to-cart']) ) {
135
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
136
+
137
+ return null;
138
+ }
139
+
140
+ // Do not execute anti-spam test for logged in users.
141
+ if ( isset($_COOKIE[LOGGED_IN_COOKIE]) && $apbct->settings['data__protect_logged_in'] != 1 ) {
142
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
143
+
144
+ return null;
145
+ }
146
+ //Skip WP Fusion web hooks
147
+ if ( apbct_is_in_uri('wpf_action') && apbct_is_in_uri('access_key') && isset($_GET['access_key']) ) {
148
+ if ( function_exists('wp_fusion') ) {
149
+ $key = wp_fusion()->settings->get('access_key');
150
+ if ( $key == $_GET['access_key'] ) {
151
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
152
+
153
+ return null;
154
+ }
155
+ }
156
+ }
157
+ //Skip system fields for divi
158
+ if ( strpos(\Cleantalk\Variables\Post::get('action'), 'et_pb_contactform_submit') === 0 ) {
159
+ foreach ( $_POST as $key => $value ) {
160
+ if ( strpos($key, 'et_pb_contact_email_fields') === 0 ) {
161
+ unset($_POST[$key]);
162
+ }
163
+ }
164
+ }
165
+
166
+ if ( apbct_is_skip_request(false) ) {
167
+ do_action(
168
+ 'apbct_skipped_request',
169
+ __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__ . '(' . apbct_is_skip_request() . ')',
170
+ $_POST
171
+ );
172
+
173
+ return false;
174
+ }
175
+
176
+ $post_info['comment_type'] = 'feedback_general_contact_form';
177
+
178
+ $ct_temp_msg_data = ct_get_fields_any($_POST);
179
+
180
+ $sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
181
+ $sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
182
+ $subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
183
+ $contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
184
+ $message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
185
+ if ( $subject != '' ) {
186
+ $message = array_merge(array('subject' => $subject), $message);
187
+ }
188
+
189
+ // Skip submission if no data found
190
+ if ( $sender_email === '' || ! $contact_form ) {
191
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
192
+
193
+ return false;
194
+ }
195
+
196
+ if ( isset($_POST['TellAFriend_Link']) ) {
197
+ $tmp = $_POST['TellAFriend_Link'];
198
+ unset($_POST['TellAFriend_Link']);
199
+ }
200
+
201
+ $base_call_result = apbct_base_call(
202
+ array(
203
+ 'message' => $message,
204
+ 'sender_email' => $sender_email,
205
+ 'sender_nickname' => $sender_nickname,
206
+ 'post_info' => $post_info,
207
+ 'sender_info' => array('sender_email' => urlencode($sender_email)),
208
+ )
209
+ );
210
+
211
+ if ( isset($_POST['TellAFriend_Link']) ) {
212
+ $_POST['TellAFriend_Link'] = $tmp;
213
+ }
214
+
215
+ $ct_result = $base_call_result['ct_result'];
216
+ if ( $ct_result->allow == 0 ) {
217
+ // Recognize contact form an set it's name to $contact_form to use later
218
+ $contact_form = null;
219
+ foreach ( $_POST as $param => $value ) {
220
+ if ( strpos($param, 'et_pb_contactform_submit') === 0 ) {
221
+ $contact_form = 'contact_form_divi_theme';
222
+ $contact_form_additional = str_replace('et_pb_contactform_submit', '', $param);
223
+ }
224
+ if ( strpos($param, 'avia_generated_form') === 0 ) {
225
+ $contact_form = 'contact_form_enfold_theme';
226
+ $contact_form_additional = str_replace('avia_generated_form', '', $param);
227
+ }
228
+ if ( ! empty($contact_form) ) {
229
+ break;
230
+ }
231
+ }
232
+
233
+ $ajax_call = false;
234
+ if ( (defined('DOING_AJAX') && DOING_AJAX)
235
+ ) {
236
+ $ajax_call = true;
237
+ }
238
+ if ( $ajax_call ) {
239
+ echo $ct_result->comment;
240
+ } else {
241
+ global $ct_comment;
242
+ $ct_comment = $ct_result->comment;
243
+ if ( isset($_POST['cma-action']) && $_POST['cma-action'] == 'add' ) {
244
+ $result = array('success' => 0, 'thread_id' => null, 'messages' => array($ct_result->comment));
245
+ header("Content-Type: application/json");
246
+ print json_encode($result);
247
+ die();
248
+ } elseif ( isset($_POST['TellAFriend_email']) ) {
249
+ echo $ct_result->comment;
250
+ die();
251
+ } elseif ( isset($_POST['gform_submit']) ) { // Gravity forms submission
252
+ $response = sprintf(
253
+ "<!DOCTYPE html><html><head><meta charset='UTF-8' /></head><body class='GF_AJAX_POSTBACK'><div id='gform_confirmation_wrapper_1' class='gform_confirmation_wrapper '><div id='gform_confirmation_message_1' class='gform_confirmation_message_1
254
  gform_confirmation_message'>%s</div></div></body></html>",
255
+ $ct_result->comment
256
+ );
257
+ echo $response;
258
+ die();
259
+ } elseif ( isset($_POST['action']) && $_POST['action'] == 'ct_check_internal' ) {
260
+ return $ct_result->comment;
261
+ } elseif ( isset($_POST['vfb-submit']) && defined('VFB_VERSION') ) {
262
+ wp_die(
263
+ "<h1>" . __(
264
+ 'Spam protection by CleanTalk',
265
+ 'cleantalk-spam-protect'
266
+ ) . "</h1><h2>" . $ct_result->comment . "</h2>",
267
+ '',
268
+ array('response' => 403, "back_link" => true, "text_direction" => 'ltr')
269
+ );
270
+ // Caldera Contact Forms
271
+ } elseif ( isset($_POST['action']) && $_POST['action'] == 'cf_process_ajax_submit' ) {
272
+ print "<h3 style='color: red;'><red>" . $ct_result->comment . "</red></h3>";
273
+ die();
274
+ // Mailster
275
+ } elseif ( isset($_POST['_referer'], $_POST['formid'], $_POST['email']) ) {
276
+ $return = array(
277
+ 'success' => false,
278
+ 'html' => '<p>' . $ct_result->comment . '</p>',
279
+ );
280
+ print json_encode($return);
281
+ die();
282
+ // Divi Theme Contact Form. Using $contact_form
283
+ } elseif ( ! empty($contact_form) && $contact_form == 'contact_form_divi_theme' ) {
284
+ echo "<div id='et_pb_contact_form{$contact_form_additional}'><h1>Your request looks like spam.</h1><div><p>{$ct_result->comment}</p></div></div>";
285
+ die();
286
+ // Enfold Theme Contact Form. Using $contact_form
287
+ } elseif ( ! empty($contact_form) && $contact_form == 'contact_form_enfold_theme' ) {
288
+ echo "<div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1' style='display: block;'><div id='ajaxresponse_1' class='ajaxresponse ajaxresponse_1'><h3 class='avia-form-success'>Antispam by CleanTalk: " . $ct_result->comment . "</h3><a href='.'><-Back</a></div></div>";
289
+ die();
290
+ } else {
291
+ ct_die(null, null);
292
+ }
293
+ }
294
+ exit;
295
+ }
296
+
297
+ return null;
298
  }
299
 
300
  /**
301
  * General test for any post data
302
  */
303
+ function ct_contact_form_validate_postdata()
304
+ {
305
+ global $apbct, $pagenow, $cleantalk_executed;
306
+
307
+ // Exclusios common function
308
+ if ( apbct_exclusions_check(__FUNCTION__) ) {
309
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
310
+
311
+ return null;
312
+ }
313
+
314
+ if ( @sizeof($_POST) == 0 ||
315
+ (isset($_POST['signup_username']) && isset($_POST['signup_email']) && isset($_POST['signup_password'])) ||
316
+ (isset($pagenow) && $pagenow == 'wp-login.php') || // WordPress log in form
317
+ (isset($pagenow) && $pagenow == 'wp-login.php' && isset($_GET['action']) && $_GET['action'] == 'lostpassword') ||
318
+ apbct_is_in_uri('/checkout/') ||
319
+ /* WooCommerce Service Requests - skip them */
320
+ isset($_GET['wc-ajax']) && (
321
+ $_GET['wc-ajax'] == 'checkout' ||
322
+ $_GET['wc-ajax'] == 'get_refreshed_fragments' ||
323
+ $_GET['wc-ajax'] == 'apply_coupon' ||
324
+ $_GET['wc-ajax'] == 'remove_coupon' ||
325
+ $_GET['wc-ajax'] == 'update_shipping_method' ||
326
+ $_GET['wc-ajax'] == 'get_cart_totals' ||
327
+ $_GET['wc-ajax'] == 'update_order_review' ||
328
+ $_GET['wc-ajax'] == 'add_to_cart' ||
329
+ $_GET['wc-ajax'] == 'remove_from_cart' ||
330
+ $_GET['wc-ajax'] == 'get_variation' ||
331
+ $_GET['wc-ajax'] == 'get_customer_location'
332
+ ) ||
333
+ /* END: WooCommerce Service Requests */
334
+ apbct_is_in_uri('/wp-admin/') ||
335
+ apbct_is_in_uri('wp-login.php') ||
336
+ apbct_is_in_uri('wp-comments-post.php') ||
337
+ apbct_is_in_referer('/wp-admin/') ||
338
+ apbct_is_in_uri('/login/') ||
339
+ apbct_is_in_uri('?provider=facebook&') ||
340
+ isset($_GET['ptype']) && $_GET['ptype'] == 'login' ||
341
+ isset($_POST['ct_checkjs_register_form']) ||
342
+ (isset($_POST['signup_username']) && isset($_POST['signup_password_confirm']) && isset($_POST['signup_submit'])) ||
343
+ $apbct->settings['forms__general_contact_forms_test'] == 0 ||
344
+ isset($_POST['bbp_topic_content']) ||
345
+ isset($_POST['bbp_reply_content']) ||
346
+ isset($_POST['fscf_submitted']) ||
347
+ isset($_POST['log']) && isset($_POST['pwd']) && isset($_POST['wp-submit']) ||
348
+ apbct_is_in_uri('/wc-api') ||
349
+ apbct_is_in_uri('wc-api=WC_Gateway_Tpay_Basic') || // Tpay payment Gateway plugin
350
+ (isset($_POST['wc_reset_password'], $_POST['_wpnonce'], $_POST['_wp_http_referer'])) || //WooCommerce recovery password form
351
+ (isset($_POST['woocommerce-login-nonce'], $_POST['login'], $_POST['password'], $_POST['_wp_http_referer'])) || //WooCommerce login form
352
+ (isset($_POST['provider'], $_POST['authcode']) && $_POST['provider'] == 'Two_Factor_Totp') || //TwoFactor authorization
353
+ (isset($_GET['wc-ajax']) && $_GET['wc-ajax'] == 'sa_wc_buy_now_get_ajax_buy_now_button') || //BuyNow add to cart
354
+ apbct_is_in_uri('/wp-json/wpstatistics/v1/hit') || //WPStatistics
355
+ (isset($_POST['ihcaction']) && $_POST['ihcaction'] == 'login') || //Skip login form
356
+ (isset($_POST['action']) && $_POST['action'] == 'infinite_scroll') || //Scroll
357
+ isset($_POST['gform_submit']) || //Skip gravity checking because of direct integration
358
+ (isset($_POST['lrm_action']) && $_POST['lrm_action'] == 'login') || //Skip login form
359
+ apbct_is_in_uri('xmlrpc.php?for=jetpack') ||
360
+ apbct_is_in_uri('connector=bridge&task=put_sql') ||
361
+ Server::inUri('cleantalk-antispam/v1/alt_sessions') || // Skip test for alt sessions
362
+ (apbct_is_in_uri('bvMethod=') && apbct_is_in_uri('bvVersion=') && isset($_POST['apipage']) && $_POST['apipage'] === 'blogvault')
363
+ ) {
364
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
365
+
366
+ return null;
367
+ }
368
+
369
+ $message = ct_get_fields_any_postdata($_POST);
370
+
371
+ // ???
372
+ if ( strlen(json_encode($message)) < 10 ) {
373
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
374
+
375
+ return null;
376
+ }
377
+
378
+
379
+ // Skip if request contains params
380
+ $skip_params = array(
381
+ 'ipn_track_id', // PayPal IPN #
382
+ 'txn_type', // PayPal transaction type
383
+ 'payment_status', // PayPal payment status
384
+ );
385
+ foreach ( $skip_params as $key => $value ) {
386
+ if ( @array_key_exists($value, $_GET) || @array_key_exists($value, $_POST) ) {
387
+ do_action('apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST);
388
+
389
+ return null;
390
+ }
391
+ }
392
+
393
+ $base_call_result = apbct_base_call(
394
+ array(
395
+ 'message' => $message,
396
+ 'post_info' => array('comment_type' => 'feedback_general_postdata'),
397
+ )
398
+ );
399
+
400
+ $cleantalk_executed = true;
401
+
402
+ $ct_result = $base_call_result['ct_result'];
403
+
404
+ if ( $ct_result->allow == 0 ) {
405
+ if ( ! (defined('DOING_AJAX') && DOING_AJAX) ) {
406
+ global $ct_comment;
407
+ $ct_comment = $ct_result->comment;
408
+ if ( isset($_POST['cma-action']) && $_POST['cma-action'] == 'add' ) {
409
+ $result = array('success' => 0, 'thread_id' => null, 'messages' => array($ct_result->comment));
410
+ header("Content-Type: application/json");
411
+ print json_encode($result);
412
+ die();
413
+ } else {
414
+ ct_die(null, null);
415
+ }
416
+ } else {
417
+ echo $ct_result->comment;
418
+ }
419
+ exit;
420
+ }
421
+
422
+ return null;
423
+ }
inc/cleantalk-public.php CHANGED
@@ -9,88 +9,95 @@ use Cleantalk\Common\Helper;
9
  * @throws Exception
10
  * @psalm-suppress UnusedVariable
11
  */
12
- function apbct_init() {
13
-
14
  global $ct_jp_comments, $apbct;
15
 
16
  // Pixel
17
- if( $apbct->settings['data__pixel'] ){
18
-
19
  $pixel_hash = md5(
20
- Helper::ip__get()
21
- . $apbct->api_key
22
- . Helper::time__get_interval_start( 3600 * 3 ) // Unique for every 3 hours
23
  );
24
 
25
- $server = get_option('cleantalk_server');
26
- $server_url = isset( $server['ct_work_url'] ) ? $apbct->server['ct_work_url'] : APBCT_MODERATE_URL;
27
- $pixel = '/pixel/' . $pixel_hash . '.gif';
28
- $apbct->pixel_url = str_replace( 'http://', 'https://', $server_url ) . $pixel;
29
  }
30
 
31
  //Check internal forms with such "action" http://wordpress.loc/contact-us/some_script.php
32
- if( (isset($_POST['action']) && $_POST['action'] === 'ct_check_internal') &&
33
- $apbct->settings['forms__check_internal']
34
- ){
35
  $ct_result = ct_contact_form_validate();
36
- if($ct_result == null){
37
  echo 'true';
38
  die();
39
- }else{
40
  echo $ct_result;
41
  die();
42
  }
43
  }
44
 
45
  //fix for EPM registration form
46
- if(isset($_POST) && isset($_POST['reg_email']) && shortcode_exists( 'epm_registration_form' ))
47
- {
48
- unset($_POST['ct_checkjs_register_form']);
49
  }
50
 
51
- if(isset($_POST['_wpnonce-et-pb-contact-form-submitted']))
52
- {
53
- add_shortcode( 'et_pb_contact_form', 'ct_contact_form_validate' );
54
  }
55
 
56
- if($apbct->settings['forms__check_external']){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- // Fixing form and directs it this site
59
- if($apbct->settings['forms__check_external__capture_buffer'] && !is_admin() && !apbct_is_ajax() && !apbct_is_post() && apbct_is_user_enable() && !(defined('DOING_CRON') && DOING_CRON) && !(defined('XMLRPC_REQUEST') && XMLRPC_REQUEST)){
 
 
 
 
60
 
61
- if (defined('CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL') && is_string(CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL)) {
62
- $catch_buffer = false;
63
- $urls = explode(',', CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL);
64
- foreach ($urls as $url) {
65
- if (apbct_is_in_uri($url))
66
- $catch_buffer = true;
67
- }
68
- }else{
69
- $catch_buffer = true;
70
- }
71
-
72
- if( $catch_buffer ){
73
- add_action('wp', 'apbct_buffer__start');
74
- add_action('shutdown', 'apbct_buffer__end', 0);
75
- add_action('shutdown', 'apbct_buffer__output', 2);
76
- }
77
- }
78
-
79
- // Check and redirecct
80
- if( apbct_is_post()
81
- && isset($_POST['cleantalk_hidden_method'])
82
- && isset($_POST['cleantalk_hidden_action'])
83
- ){
84
- $action = htmlspecialchars($_POST['cleantalk_hidden_action']);
85
- $method = htmlspecialchars($_POST['cleantalk_hidden_method']);
86
- unset($_POST['cleantalk_hidden_action']);
87
- unset($_POST['cleantalk_hidden_method']);
88
- ct_contact_form_validate();
89
- if(!apbct_is_ajax()){
90
- print "<html lang=''><body><form method='$method' action='$action'>";
91
- ct_print_form($_POST, '');
92
- print "</form></body></html>";
93
- print "<script " . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . ">
94
  if(document.forms[0].submit !== 'undefined'){
95
  var objects = document.getElementsByName('submit');
96
  if(objects.length > 0)
@@ -98,268 +105,273 @@ function apbct_init() {
98
  }
99
  document.forms[0].submit();
100
  </script>";
101
- die();
102
- }
103
- }
104
- }
105
 
106
- if(isset($_POST['quform_ajax'], $_POST['quform_csrf_token'], $_POST['quform_form_id'])){
107
- require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
108
- ct_ajax_hook();
109
- }
110
 
111
- /**hooks for cm answers pro */
112
- if(defined('CMA_PLUGIN_FILE')){
113
- add_action( 'wp', 'ct_ajax_hook',1 );
114
- }
115
 
116
- //hook for Anonymous Post
117
- if($apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7'])) {
118
- add_action( 'wp', 'ct_contact_form_validate_postdata', 1 );
119
  }
120
 
121
- if($apbct->settings['forms__general_contact_forms_test'] == 1 && empty($_POST['ct_checkjs_cf7'])){
122
- add_action('CMA_custom_post_type_nav', 'ct_contact_form_validate_postdata',1);
123
- ct_contact_form_validate();
124
- if(isset($_POST['reg_redirect_link'])&&isset($_POST['tmpl_registration_nonce_field']))
125
- {
126
- unset($_POST['ct_checkjs_register_form']);
127
- ct_contact_form_validate();
128
- }
129
- }
130
 
131
- if($apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7'])) {
132
- add_action( 'CMA_custom_post_type_nav', 'ct_contact_form_validate_postdata', 1 );
133
  }
134
 
135
  // Fast Secure contact form
136
- if(defined('FSCF_VERSION')){
137
- add_filter('si_contact_display_after_fields', 'ct_si_contact_display_after_fields');
138
- add_filter('si_contact_form_validate', 'ct_si_contact_form_validate');
139
- }
140
 
141
  // WooCommerce registration
142
- if(class_exists('WooCommerce')){
143
- add_filter( 'woocommerce_registration_errors', 'ct_registration_errors', 1, 3 );
144
- if ($apbct->settings['forms__wc_checkout_test'] == 1) {
145
- add_filter('woocommerce_checkout_process', 'ct_woocommerce_checkout_check', 1, 3);
146
  }
147
- if( isset($_REQUEST['wc-ajax']) && $_REQUEST['wc-ajax'] === 'checkout' && empty( $apbct->settings['forms__wc_register_from_order'] ) ){
148
- remove_filter( 'woocommerce_registration_errors', 'ct_registration_errors', 1 );
149
  }
150
 
151
- //Woocommerce add_to_cart action
152
- add_action( 'woocommerce_add_to_cart', 'apbct_wc__add_to_cart_unlogged_user', 10, 6 );
153
  }
154
 
155
- // WooCommerce whishlist
156
- if(class_exists('WC_Wishlists_Wishlist')) {
157
- add_filter( 'wc_wishlists_create_list_args', 'ct_woocommerce_wishlist_check', 1, 1 );
158
- }
159
 
160
 
161
  // JetPack Contact form
162
- if(defined('JETPACK__VERSION'))
163
- {
164
  // Checking Jetpack contact form
165
- if(isset($_POST['action']) && $_POST['action'] === 'grunion-contact-form' ){
166
- if( JETPACK__VERSION === '3.4-beta')
167
- {
168
  add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
169
- }
170
- else if( JETPACK__VERSION === '3.4-beta2' || JETPACK__VERSION >= '3.4')
171
- {
172
- add_filter('jetpack_contact_form_is_spam', 'ct_contact_form_is_spam_jetpack',50,2);
173
- }
174
- else
175
- {
176
  add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
177
  }
178
-
179
- }else {
180
  add_filter('grunion_contact_form_field_html', 'ct_grunion_contact_form_field_html', 10, 2);
181
  }
182
 
183
  // Checking Jetpack comments form
184
  $jetpack_active_modules = get_option('jetpack_active_modules');
185
- if ((class_exists( 'Jetpack', false) && $jetpack_active_modules && in_array('comments', $jetpack_active_modules)))
186
- {
 
 
 
187
  $ct_jp_comments = true;
188
  }
189
-
190
  }
191
 
192
- // WP Maintenance Mode (wpms)
193
- add_action('wpmm_head', 'apbct_form__wpmm__addField', 1);
194
 
195
  // Contact Form7
196
- if(defined('WPCF7_VERSION')){
197
- add_filter('wpcf7_form_elements', 'apbct_form__contactForm7__addField');
198
- add_filter('wpcf7_validate', 'apbct_form__contactForm7__tesSpam__before_validate', 999, 2);
199
- $hook = WPCF7_VERSION >= '3.0.0' ? 'wpcf7_spam' : 'wpcf7_acceptance';
200
- $num_arg = WPCF7_VERSION >= '5.3.0' ? 2 : 1;
201
- add_filter( $hook, 'apbct_form__contactForm7__testSpam', 9999, $num_arg );
202
- }
203
 
204
  // Formidable
205
- add_filter( 'frm_entries_before_create', 'apbct_form__formidable__testSpam', 10, 2 );
206
- add_action( 'frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2 );
207
 
208
  // BuddyPress
209
- if(class_exists('BuddyPress')){
210
- add_action('bp_before_registration_submit_buttons','ct_register_form',1);
211
- add_action('messages_message_before_save', 'apbct_integration__buddyPres__private_msg_check', 1);
212
- add_filter('bp_signup_validate', 'ct_registration_errors',1);
213
- add_filter('bp_signup_validate', 'ct_check_registration_erros', 999999);
214
- }
215
 
216
- if(defined('PROFILEPRESS_SYSTEM_FILE_PATH')){
217
- add_filter('pp_registration_validation', 'ct_registration_errors_ppress', 11, 2);
218
- }
219
 
220
  // bbPress
221
- if(class_exists('bbPress')){
222
- add_filter('bbp_new_topic_pre_title', 'ct_bbp_get_topic', 1);
223
- add_filter('bbp_new_topic_pre_content', 'ct_bbp_new_pre_content', 1);
224
- add_filter('bbp_new_reply_pre_content', 'ct_bbp_new_pre_content', 1);
225
- add_action('bbp_theme_before_topic_form_content', 'ct_comment_form');
226
- add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
227
- }
228
-
229
- //Custom Contact Forms
230
- if(defined('CCF_VERSION')) {
231
- add_filter( 'ccf_field_validator', 'ct_ccf', 1, 4 );
232
- }
233
 
234
  add_action('comment_form', 'ct_comment_form');
235
 
236
  // intercept WordPress Landing Pages POST
237
- if (defined('LANDINGPAGES_CURRENT_VERSION') && !empty($_POST)){
238
- if(array_key_exists('action', $_POST) && $_POST['action'] === 'inbound_store_lead'){ // AJAX action(s)
239
  ct_check_wplp();
240
- }else if(array_key_exists('inbound_submitted', $_POST) && $_POST['inbound_submitted'] == '1'){ // Final submit
 
 
 
 
241
  ct_check_wplp();
242
  }
243
  }
244
 
245
  // S2member. intercept POST
246
- if (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION')){
247
- $post_keys = array_keys($_POST);
248
- foreach($post_keys as $post_key){
249
- // Detect POST keys like /s2member_pro.*registration/
250
- if(strpos($post_key, 's2member') !== false && strpos($post_key, 'registration') !== false){
251
- ct_s2member_registration_test($post_key);
252
- break;
253
- }
254
- }
255
- }
256
 
257
  // New user approve hack
258
  // https://wordpress.org/plugins/new-user-approve/
259
- if (ct_plugin_active('new-user-approve/new-user-approve.php')) {
260
  add_action('register_post', 'ct_register_post', 1, 3);
261
  }
262
 
263
- // Wilcity theme registration validation fix
264
- add_filter( 'wilcity/filter/wiloke-listing-tools/validate-before-insert-account', 'apbct_wilcity_reg_validation', 10, 2 );
 
 
 
 
 
265
 
266
  // Gravity forms
267
- if (defined('GF_MIN_WP_VERSION')) {
268
- add_filter('gform_get_form_filter', 'apbct_form__gravityForms__addField', 10, 2);
269
- add_filter('gform_entry_is_spam', 'apbct_form__gravityForms__testSpam', 999, 3);
270
- add_filter('gform_confirmation', 'apbct_form__gravityForms__showResponse', 999, 4 );
271
- }
272
-
273
- //Pirate forms
274
- if(defined('PIRATE_FORMS_VERSION')){
275
- if(isset($_POST['pirate-forms-contact-name']) && $_POST['pirate-forms-contact-name'] && isset($_POST['pirate-forms-contact-email']) && $_POST['pirate-forms-contact-email']) {
276
- apbct_form__piratesForm__testSpam();
277
- }
278
- }
279
-
280
- // WPForms
281
- // Adding fields
282
- add_action('wpforms_frontend_output', 'apbct_form__WPForms__addField', 1000, 5);
283
- // Gathering data to validate
284
- add_filter('wpforms_process_before_filter', 'apbct_from__WPForms__gatherData', 100, 2);
285
- // Do spam check
286
- add_filter('wpforms_process_initial_errors', 'apbct_form__WPForms__showResponse', 100, 2);
287
-
288
- // QForms integration
289
- add_filter( 'quform_post_validate', 'ct_quform_post_validate', 10, 2 );
290
-
291
- // Ultimate Members
292
- if (class_exists('UM')) {
293
- add_action('um_main_register_fields','ct_register_form',100); // Add hidden fileds
294
- add_action( 'um_submit_form_register', 'apbct_registration__UltimateMembers__check', 9, 1 ); // Check submition
295
- }
296
-
297
- // Paid Memberships Pro integration
298
- add_filter( 'pmpro_required_user_fields', function( $pmpro_required_user_fields ){
299
-
300
- if(
301
- ! empty( $pmpro_required_user_fields['username'] ) &&
302
- ! empty( $pmpro_required_user_fields['bemail'] ) &&
303
- ! empty( $pmpro_required_user_fields['bconfirmemail'] ) &&
304
  $pmpro_required_user_fields['bemail'] == $pmpro_required_user_fields['bconfirmemail']
305
  ) {
306
- $check = ct_test_registration( $pmpro_required_user_fields['username'], $pmpro_required_user_fields['bemail'] );
307
- if( $check['allow'] == 0 && function_exists('pmpro_setMessage') ) {
308
- pmpro_setMessage( $check['comment'], 'pmpro_error' );
 
 
 
309
  }
310
  }
311
 
312
  return $pmpro_required_user_fields;
313
-
314
- } );
315
 
316
  //
317
  // Load JS code to website footer
318
  //
319
- if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
320
- add_action('wp_head', 'apbct_hook__wp_head__set_cookie__ct_checkjs', 1);
321
  add_action('wp_footer', 'apbct_hook__wp_footer', 1);
322
  }
323
 
324
- if ($apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in()) {
325
  ct_contact_form_validate();
326
  }
327
 
328
  if ( apbct_is_user_enable() ) {
329
-
330
- if ($apbct->settings['forms__general_contact_forms_test'] == 1 && !isset($_POST['comment_post_ID']) && !isset($_GET['for'])){
331
- add_action( 'init', 'ct_contact_form_validate', 999 );
332
  }
333
- if( apbct_is_post() &&
334
- $apbct->settings['data__general_postdata_test'] == 1 &&
335
- !isset($_POST['ct_checkjs_cf7']) &&
336
- !is_admin() &&
337
- !apbct_is_user_role_in(array('administrator', 'moderator'))
338
- ){
339
- ct_contact_form_validate_postdata();
340
- }
341
- }
342
-
343
- /**
344
- * Integration with custom forms
345
- */
346
- if(!empty($_POST) && apbct_custom_forms_trappings()) {
347
- ct_contact_form_validate();
348
- }
349
- }
350
 
351
- function apbct_buffer__start(){
352
- ob_start();
 
 
 
 
353
  }
354
 
355
- function apbct_buffer__end(){
 
 
 
356
 
357
- if(!ob_get_level())
358
- return;
 
 
 
359
 
360
- global $apbct;
361
- $apbct->buffer = ob_get_contents();
362
- ob_end_clean();
363
  }
364
 
365
  /**
@@ -367,118 +379,117 @@ function apbct_buffer__end(){
367
  *
368
  * @global $apbct
369
  */
370
- function apbct_buffer__output(){
371
-
372
- global $apbct;
373
 
374
- if( empty( $apbct->buffer ) ) {
375
- return;
376
- }
377
 
378
- if( apbct_is_plugin_active( 'flow-flow/flow-flow.php' ) ) {
379
- $output = apbct_buffer_modify_by_string();
380
- } else {
381
- $output = apbct_buffer_modify_by_dom();
382
- }
383
 
384
- echo $output;
385
- die();
386
  }
387
 
388
- function apbct_buffer_modify_by_string() {
389
-
390
- global $apbct, $wp;
391
-
392
- $site_url = get_option('siteurl');
393
- $site__host = parse_url($site_url, PHP_URL_HOST);
394
 
395
- preg_match_all( '/<form\s*.*>\s*.*<\/form>/', $apbct->buffer, $matches, PREG_SET_ORDER );
 
396
 
397
- if( count( $matches ) > 0 ) {
398
- foreach( $matches as $match ) {
399
 
400
- preg_match( '/action="(\S*)"/', $match[0], $group_action );
401
- $action = count( $group_action ) > 0 ? $group_action[1] : $site_url;
 
 
402
 
403
- $action__host = parse_url($action, PHP_URL_HOST);
404
- if( $site__host != $action__host ) {
 
 
405
 
406
- preg_match( '/method="(\S*)"/', $match[0], $group_method );
407
- $method = count( $group_method ) > 0 ? $group_method[1] : 'get';
408
 
409
- $hidden_fields = '<input type="hidden" name="cleantalk_hidden_action" value="' . $action . '">';
410
- $hidden_fields .= '<input type="hidden" name="cleantalk_hidden_method" value="' . $method . '">';
411
-
412
- $modified_match = preg_replace( '/action="\S*"/', 'action="' . home_url(add_query_arg(array(), $wp->request)) . '"', $match[0] );
413
- $modified_match = preg_replace( '/method="\S*"/', 'method="POST"', $modified_match );
414
- $modified_match = str_replace( '</form>', $hidden_fields . '</form>', $modified_match );
415
- $apbct->buffer = str_replace( $match[0], $modified_match, $apbct->buffer );
416
- }
417
- }
418
- }
419
-
420
- return $apbct->buffer;
421
 
 
422
  }
423
 
424
- function apbct_buffer_modify_by_dom() {
425
-
426
- global $apbct, $wp;
427
-
428
- $site_url = get_option('siteurl');
429
- $site__host = parse_url($site_url, PHP_URL_HOST);
430
-
431
- $dom = new DOMDocument();
432
- @$dom->loadHTML($apbct->buffer, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
433
-
434
- $forms = $dom->getElementsByTagName('form');
435
-
436
- foreach($forms as $form){
437
-
438
- $action = $form->getAttribute('action');
439
- $action = $action ?: $site_url;
440
- $action__host = parse_url($action, PHP_URL_HOST);
441
-
442
- // Check if the form directed to the third party site
443
- if($site__host != $action__host){
444
-
445
- $method = $form->getAttribute('method');
446
- $method = $method ?: 'get';
447
- // Directs form to our site
448
- $form->setAttribute('method', 'POST');
449
- $form->setAttribute('action', home_url(add_query_arg(array(), $wp->request)));
450
-
451
- // Add cleantalk_hidden_action
452
- $new_input = $dom->createElement('input');
453
- $new_input->setAttribute('type', 'hidden');
454
- $new_input->setAttribute('name', 'cleantalk_hidden_action');
455
- $new_input->setAttribute('value', $action);
456
- $form->appendChild($new_input);
457
-
458
- // Add cleantalk_hidden_method
459
- $new_input = $dom->createElement('input');
460
- $new_input->setAttribute('type', 'hidden');
461
- $new_input->setAttribute('name', 'cleantalk_hidden_method');
462
- $new_input->setAttribute('value', $method);
463
- $form->appendChild($new_input);
464
-
465
- }
466
-
467
- } unset($form);
468
-
469
- $html = $dom->getElementsByTagName('html');
470
 
471
- return is_object( $html ) && isset( $html[0], $html[0]->childNodes[0] ) && $dom->getElementsByTagName( 'rss' )->length == 0
472
- ? $dom->saveHTML()
473
- : $apbct->buffer;
474
 
 
 
 
 
 
475
  }
476
 
477
  /**
478
  * Adds cookie script filed to head
479
  */
480
- function apbct_hook__wp_head__set_cookie__ct_checkjs() {
481
-
482
  ct_add_hidden_fields('ct_checkjs', false, true, true);
483
 
484
  return null;
@@ -488,58 +499,60 @@ function apbct_hook__wp_head__set_cookie__ct_checkjs() {
488
  * Adds check_js script to the footer
489
  * @psalm-suppress UnusedVariable
490
  */
491
- function apbct_hook__wp_footer() {
492
-
493
- global $apbct;
494
 
495
- # Return false if page is excluded
496
- if (apbct_exclusions_check__url()) {
497
- return;
498
- }
499
 
500
- // Pixel
501
- if(
502
  $apbct->settings['data__pixel'] === '1' ||
503
- ( $apbct->settings['data__pixel'] === '3' && apbct_is_cache_plugins_exists() )
504
- ){
505
- echo '<img alt="Cleantalk Pixel" id="apbct_pixel" style="display: none;" src="' . $apbct->pixel_url . '">';
506
- }
507
-
508
- if( $apbct->settings['data__use_ajax'] ){
509
-
510
- $timeout = $apbct->settings['misc__async_js'] ? 1000 : 0;
511
-
512
- if( $apbct->use_rest_api ) {
513
- $html = "<script type=\"text/javascript\" " . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . ">
514
- window.addEventListener('DOMContentLoaded', function () {
515
- setTimeout(function(){
516
- if( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {
517
- apbct_public_sendREST(
518
- 'js_keys__get',
519
- { callback: apbct_js_keys__set_input_value }
520
- )
521
- }
522
- },". $timeout . ")
523
- });
524
- </script>";
525
- } else {
526
- $html = "<script type=\"text/javascript\" " . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . ">
527
- window.addEventListener('DOMContentLoaded', function () {
528
- setTimeout(function(){
529
- if( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {
530
- apbct_public_sendAJAX(
531
- { action: 'apbct_js_keys__get' },
532
- { callback: apbct_js_keys__set_input_value, apbct_ajax: 1 }
533
- );
534
- }
535
- },". $timeout . ")
536
- });
537
- </script>";
538
- }
539
-
540
- echo $html;
541
-
542
- }
 
 
543
  }
544
 
545
  /**
@@ -555,52 +568,57 @@ function apbct_hook__wp_footer() {
555
  *
556
  * @psalm-suppress UnusedVariable
557
  */
558
- function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false, $cookie_check = false, $no_print = false, $ajax = true) {
559
-
560
- # Return false if page is excluded
561
- if (apbct_exclusions_check__url()) {
562
- return false;
563
- }
 
 
 
 
 
564
 
565
  global $ct_checkjs_def, $apbct;
566
 
567
  $ct_checkjs_key = ct_get_checkjs_value();
568
- $field_id_hash = md5((string)rand(0, 1000));
569
-
570
- // Using only cookies
571
- if ($cookie_check && $apbct->settings['data__set_cookies'] ) {
572
- $html = "<script type=\"text/javascript\" " . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . ">
573
- function apbct_attach_event_handler__backend(elem, event, callback){
574
- if(typeof window.addEventListener === \"function\") elem.addEventListener(event, callback);
575
- else elem.attachEvent(event, callback);
576
- }
577
- apbct_attach_event_handler__backend(window, 'load', function(){
578
- ctSetCookie('{$field_name}', '{$ct_checkjs_key}' );
579
- });
580
- </script>";
581
-
582
- // Using AJAX to get key
583
- }elseif($apbct->settings['data__use_ajax'] && $ajax){
584
-
585
- // Fix only for wp_footer -> apbct_hook__wp_head__set_cookie__ct_checkjs()
586
- if($no_print) {
587
- return;
588
- }
589
-
590
- $field_id = $field_name . '_' . $field_id_hash;
591
- $html = "<input type=\"hidden\" id=\"{$field_id}\" name=\"{$field_name}\" value=\"{$ct_checkjs_def}\" />";
592
 
593
- // Set KEY from backend
594
- }else{
595
- // Fix only for wp_footer -> apbct_hook__wp_head__set_cookie__ct_checkjs()
596
- if($no_print) {
597
- return;
598
- }
 
 
599
 
600
  $ct_input_challenge = sprintf("'%s'", $ct_checkjs_key);
601
- $field_id = $field_name . '_' . $field_id_hash;
602
- $html = "<input type=\"hidden\" id=\"{$field_id}\" name=\"{$field_name}\" value=\"{$ct_checkjs_def}\" />
603
- <script type=\"text/javascript\" " . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . ">
604
  setTimeout(function(){
605
  var ct_input_name = \"{$field_id}\";
606
  if (document.getElementById(ct_input_name) !== null) {
@@ -609,12 +627,12 @@ function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false
609
  }
610
  }, 1000);
611
  </script>";
612
- }
613
 
614
  // Simplify JS code and Fixing issue with wpautop()
615
- $html = str_replace(array("\n","\r","\t"),'', $html);
616
 
617
- if ($return_string === true) {
618
  return $html;
619
  } else {
620
  echo $html;
@@ -626,39 +644,44 @@ function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false
626
  *
627
  * @param bool $maybe_notify notify flag
628
  * @param int $comment_ID Comment id
 
629
  * @return bool flag
630
  */
631
- function apbct_comment__Wordpress__doNotify($_maybe_notify, $_comment_ID){
632
- return true;
 
633
  }
634
 
635
  /**
636
  * Add notification setting link
637
  *
638
- * @param string $notify_message
639
  * @param integer $comment_id
640
  *
641
  * @return string
642
  */
643
- function apbct_comment__Wordpress__changeMailNotificationGroups($notify_message, $_comment_id){
644
- return $notify_message
645
- .PHP_EOL
646
- .'---'.PHP_EOL
647
- .'Manage notifications settings: '.get_site_url().'/wp-admin/options-general.php?page=cleantalk';
 
648
  }
649
 
650
  /**
651
  * Change email notification recipients
652
  *
653
- * @param array $emails
654
- * @param integer $comment_id
655
  *
656
  * @return array
657
  * @global \Cleantalk\ApbctWP\State $apbct
658
  */
659
- function apbct_comment__Wordpress__changeMailNotificationRecipients($emails, $_comment_id){
660
- global $apbct;
661
- return array_unique(array_merge($emails, (array)json_decode($apbct->comment_notification_recipients, true)));
 
 
662
  }
663
 
664
  /**
@@ -669,132 +692,129 @@ function apbct_comment__Wordpress__changeMailNotificationRecipients($emails, $_c
669
  *
670
  * @return string Body for email notification
671
  */
672
- function apbct_comment__Wordpress__changeMailNotification($notify_message, $_comment_id){
673
-
674
- global $apbct;
675
-
676
- return PHP_EOL
677
- . __('CleanTalk AntiSpam: This message is possible spam.', 'cleantalk-spam-protect')
678
- . "\n" . __('You could check it in CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
679
- . "\n" . 'IP: https://cleantalk.org/blacklists/' . $apbct->sender_ip
680
- . "\n" . 'Email: https://cleantalk.org/blacklists/' . $apbct->sender_email
681
- . "\n" . PHP_EOL . sprintf(
682
- __('Activate protection in your Anti-Spam Dashboard: %s.', 'clentalk'),
683
- 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wp_spam_comment_passed'
684
- .($apbct->data['user_token']
685
- ? '&iser_token='.$apbct->data['user_token']
686
- : ''
687
- )
688
- )
689
- . PHP_EOL . '---'
690
- . PHP_EOL
691
- . PHP_EOL
692
- . $notify_message;
693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
694
  }
695
 
696
- function apbct_comment__wordpress__show_blacklists( $notify_message, $comment_id ) {
697
-
698
- $comment_details = get_comments( array( 'comment__in' => $comment_id ) );
699
  $comment_details = $comment_details[0];
700
 
701
- if( isset( $comment_details->comment_author_email ) ) {
702
-
703
  $black_list_link = 'https://cleantalk.org/blacklists/';
704
 
705
  $links = PHP_EOL;
706
- $links .= esc_html__( 'Check for spam:', 'cleantalk-spam-protect');
707
  $links .= PHP_EOL;
708
  $links .= $black_list_link . $comment_details->comment_author_email;
709
  $links .= PHP_EOL;
710
- if( ! empty( $comment_details->comment_author_IP ) ) {
711
  $links .= $black_list_link . $comment_details->comment_author_IP;
712
  $links .= PHP_EOL;
713
  }
714
 
715
  return $notify_message . $links;
716
-
717
  }
718
 
719
  return $notify_message;
720
-
721
  }
722
 
723
  /**
724
  * Set die page with Cleantalk comment.
 
 
 
725
  * @global null $ct_comment
726
  * $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk-spam-protect') . "</center><br><br>\n" . $ct_comment;
727
- * @param null $comment_status
728
  */
729
- function ct_die($_comment_id, $_comment_status) {
730
-
731
  global $ct_comment, $ct_jp_comments;
732
 
733
- do_action( 'apbct_pre_block_page', $ct_comment );
734
 
735
  $message_title = __('Spam protection', 'cleantalk-spam-protect');
736
- if(defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE != true) {
737
- $message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
738
  }
739
- if(isset($_POST['et_pb_contact_email'])) {
740
- $message_title = 'Blacklisted';
741
  }
742
 
743
- $back_link = '';
744
- $back_script = '';
745
- if( ! $ct_jp_comments ) {
746
- $back_script = '<script>setTimeout("history.back()", 5000);</script>';
747
- } else if( isset( $_SERVER['HTTP_REFERER'] ) ) {
748
- $back_link = '<a href="' . $_SERVER['HTTP_REFERER'] . '">' . __('Back') . '</a>';
749
- }
750
-
751
- if(file_exists(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html")){
752
 
753
- $ct_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html");
 
754
 
755
- // Translation
756
- $replaces = array(
757
- '{MESSAGE_TITLE}' => $message_title,
758
- '{MESSAGE}' => $ct_comment,
759
- '{BACK_LINK}' => $back_link,
760
- '{BACK_SCRIPT}' => $back_script
761
- );
762
 
763
- foreach( $replaces as $place_holder => $replace ){
764
- $ct_die_page = str_replace( $place_holder, $replace, $ct_die_page );
765
- }
766
 
767
- http_response_code(200);
768
- die($ct_die_page);
769
- }
770
 
771
- http_response_code(200);
772
- die("Forbidden. Sender blacklisted. Blocked by Cleantalk");
773
  }
774
 
775
  /**
776
  * Set die page with Cleantalk comment from parameter.
 
777
  * @param $comment_body
778
  */
779
- function ct_die_extended($comment_body) {
780
-
781
  global $ct_jp_comments;
782
 
783
  $message_title = __('Spam protection', 'cleantalk-spam-protect');
784
- if(defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE != true) {
785
  $message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
786
  }
787
 
788
- $back_link = '';
789
  $back_script = '';
790
- if( ! $ct_jp_comments ) {
791
  $back_script = '<script>setTimeout("history.back()", 5000);</script>';
792
  } else {
793
  $back_link = '<a href="' . $_SERVER['HTTP_REFERER'] . '">' . __('Back') . '</a>';
794
  }
795
 
796
- if(file_exists(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html")){
797
-
798
  $ct_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html");
799
 
800
  // Translation
@@ -805,8 +825,8 @@ function ct_die_extended($comment_body) {
805
  '{BACK_SCRIPT}' => $back_script
806
  );
807
 
808
- foreach( $replaces as $place_holder => $replace ){
809
- $ct_die_page = str_replace( $place_holder, $replace, $ct_die_page );
810
  }
811
 
812
  http_response_code(200);
@@ -826,36 +846,34 @@ function ct_die_extended($comment_body) {
826
  *
827
  * @return int|null
828
  */
829
- function apbct_js_test($field_name = 'ct_checkjs', $data = null, $is_cookie = false ) {
830
-
831
  global $apbct;
832
 
833
  $out = null;
834
 
835
- if(
836
  ($data && isset($data[$field_name])) ||
837
- ($is_cookie && $apbct->settings['data__set_cookies'] == 2 && Cookie::get( $field_name ))
838
- ){
839
-
840
- $js_key = $is_cookie && $apbct->settings['data__set_cookies'] == 2
841
- ? Cookie::get( $field_name )
842
  : trim($data[$field_name]);
843
 
844
- // Check static key
845
- if(
846
- $apbct->settings['data__use_static_js_key'] == 1 ||
847
- ( $apbct->settings['data__use_static_js_key'] == - 1 &&
848
- ( apbct_is_cache_plugins_exists() ||
849
- ( apbct_is_post() && isset($apbct->data['cache_detected']) && $apbct->data['cache_detected'] == 1 )
850
- )
851
- )
852
- ){
853
- $out = ct_get_checkjs_value() === $js_key ? 1 : 0;
854
-
855
- // Random key check
856
- }else{
857
- $out = array_key_exists( $js_key, $apbct->js_keys ) ? 1 : 0;
858
- }
859
  }
860
 
861
  return $out;
@@ -869,21 +887,21 @@ function apbct_js_test($field_name = 'ct_checkjs', $data = null, $is_cookie = fa
869
  *
870
  * @return string|null
871
  */
872
- function ct_post_url( $comment_id, $comment_post_id ){
873
-
874
- if (empty($comment_post_id)) {
875
- return null;
876
  }
877
 
878
- if ($comment_id === null) {
879
- $last_comment = get_comments('number=1');
880
- $comment_id = isset($last_comment[0]->comment_ID) ? (int) $last_comment[0]->comment_ID + 1 : 1;
881
  }
882
  $permalink = get_permalink($comment_post_id);
883
 
884
  $post_url = null;
885
- if ($permalink !== null) {
886
- $post_url = $permalink . '#comment-' . $comment_id;
887
  }
888
 
889
  return $post_url;
@@ -891,9 +909,10 @@ function ct_post_url( $comment_id, $comment_post_id ){
891
 
892
  /**
893
  * Public filter 'pre_comment_approved' - Mark comment unapproved always
894
- * @return int Zero
895
  */
896
- function ct_set_not_approved() {
 
897
  return 0;
898
  }
899
 
@@ -905,59 +924,65 @@ function ct_set_not_approved() {
905
  *
906
  * @return int|string "spam"|1
907
  */
908
- function ct_set_approved($approved, $_comment) {
909
- if ( $approved === 'spam'){
 
910
  return $approved;
911
  }
912
 
913
- return 1;
914
  }
915
 
916
  /**
917
  * Public filter 'pre_comment_approved' - Mark comment unapproved always
918
- * @return string
919
  */
920
- function ct_set_comment_spam() {
 
921
  return 'spam';
922
  }
923
 
924
  /**
925
  * Public action 'comment_post' - Store cleantalk hash in comment meta 'ct_hash'
926
- * @param int $comment_id Comment ID
927
- * @param mixed $comment_status Approval status ("spam", or 0/1), not used
 
928
  */
929
- function ct_set_meta($comment_id, $comment_status) {
 
930
  global $comment_post_id;
931
  $hash1 = ct_hash();
932
- if (!empty($hash1)) {
933
  update_comment_meta($comment_id, 'ct_hash', $hash1);
934
- if (function_exists('base64_encode') && isset($comment_status) && $comment_status !== 'spam') {
935
- $post_url = ct_post_url($comment_id, $comment_post_id);
936
- $post_url = base64_encode($post_url);
937
- // 01 - URL to approved comment
938
- $feedback_request = $hash1 . ':' . '01' . ':' . $post_url . ';';
939
- ct_send_feedback($feedback_request);
940
- }
941
  }
 
942
  return true;
943
  }
944
 
945
  /**
946
  * Mark bad words
947
- * @global string $ct_stop_words
948
  * @param int $comment_id
949
  * @param int $comment_status Not use
950
  *
951
  * @psalm-suppress UndefinedMethod
 
952
  */
953
- function ct_mark_red($comment_id, $_comment_status) {
 
954
  global $ct_stop_words;
955
 
956
  $comment = get_comment($comment_id, 'ARRAY_A');
957
  $message = $comment['comment_content'];
958
- foreach (explode(':', $ct_stop_words) as $word) {
959
  $message = preg_replace("/($word)/ui", '<font rel="cleantalk" color="#FF1000">' . "$1" . '</font>', $message);
960
-
961
  }
962
  $comment['comment_content'] = $message;
963
  kses_remove_filters();
@@ -967,31 +992,34 @@ function ct_mark_red($comment_id, $_comment_status) {
967
  //
968
  //Send post to trash
969
  //
970
- function ct_wp_trash_comment($comment_id, $_comment_status){
971
- wp_trash_comment($comment_id);
 
972
  }
973
 
974
  /**
975
- * Tests plugin activation status
976
- * @return bool
977
- */
978
- function ct_plugin_active($plugin_name){
979
- foreach (get_option('active_plugins') as $_k => $v) {
980
- if ($plugin_name == $v) {
981
- return true;
982
- }
983
- }
984
- return false;
 
 
985
  }
986
 
987
  /**
988
  * @psalm-suppress UnusedVariable
989
  */
990
- function apbct_login__scripts(){
991
-
992
  global $apbct;
993
 
994
- apbct_enqueue_and_localize_public_scripts();
995
 
996
  $apbct->public_script_loaded = true;
997
  }
@@ -1000,32 +1028,51 @@ function apbct_login__scripts(){
1000
  * Inner function - Finds and returns pattern in string
1001
  * @return bool
1002
  */
1003
- function ct_get_data_from_submit($value = null, $field_name = null) {
1004
- if (!$value || !$field_name || !is_string($value)) {
 
1005
  return false;
1006
  }
1007
- if (preg_match("/[a-z0-9_\-]*" . $field_name. "[a-z0-9_\-]*$/", $value)) {
1008
  return true;
1009
  }
1010
- return false;
 
1011
  }
1012
 
1013
  /**
1014
  * Sends error notice to admin
1015
  * @return null
1016
  */
1017
- function ct_send_error_notice ($comment = '') {
 
1018
  global $ct_admin_notoice_period, $apbct;
1019
 
1020
- $timelabel_reg = intval( get_option('cleantalk_timelabel_reg') );
1021
- if(time() - $ct_admin_notoice_period > $timelabel_reg){
1022
  update_option('cleantalk_timelabel_reg', time());
1023
 
1024
  $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1025
  $message = __('Attention, please!', 'cleantalk-spam-protect') . "\r\n\r\n";
1026
- $message .= sprintf(__('"%s" plugin error on your site "%s":', 'cleantalk-spam-protect'), $apbct->plugin_name, $blogname) . "\r\n\r\n";
1027
- $message .= preg_replace('/^(.*?)<a.*?"(.*?)".*?>(.*?)<.a>(.*)$/', '$1. $3: $2?user_token='. $apbct->user_token .' $4', $comment) . "\r\n\r\n";
1028
- @wp_mail(ct_get_admin_email(), sprintf(__('[%s] "%s" error!', 'cleantalk-spam-protect'), $apbct->plugin_name, $blogname), $message);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1029
  }
1030
 
1031
  return null;
@@ -1037,48 +1084,45 @@ function ct_send_error_notice ($comment = '') {
1037
  * @param $arr
1038
  * @param $k
1039
  */
1040
- function ct_print_form( $arr, $k ){
1041
-
1042
- // Fix for pages04.net forms
1043
- if( isset( $arr['formSourceName'] ) ){
1044
- $tmp = array();
1045
- foreach( $arr as $key => $val ){
1046
- $tmp_key = str_replace( '_', '+', $key );
1047
- $tmp[$tmp_key] = $val;
1048
- }
1049
- $arr = $tmp;
1050
- unset( $tmp, $key, $tmp_key, $val );
1051
- }
1052
-
1053
- foreach( $arr as $key => $value ){
1054
-
1055
- if( ! is_array( $value ) ){
1056
- print '<textarea
1057
- name="' . ( $k == '' ? $key : $k . '[' . $key . ']' ) . '"
1058
- style="display:none;">' . htmlspecialchars( $value )
1059
- . '</textarea>';
1060
- }else{
1061
- ct_print_form( $value, $k == '' ? $key : $k . '[' . $key . ']' );
1062
- }
1063
-
1064
- }
1065
 
 
 
 
 
 
 
 
 
 
 
1066
  }
1067
 
1068
  /**
1069
  * Attaches public scripts and styles.
1070
  * @psalm-suppress UnusedVariable
1071
  */
1072
- function ct_enqueue_scripts_public($_hook){
 
 
1073
 
1074
- global $current_user, $apbct;
1075
-
1076
- if (apbct_exclusions_check__url()) {
1077
- return;
1078
- }
1079
 
1080
- if(
1081
- $apbct->settings['forms__registrations_test'] ||
1082
  $apbct->settings['forms__comments_test'] ||
1083
  $apbct->settings['forms__contact_forms_test'] ||
1084
  $apbct->settings['forms__general_contact_forms_test'] ||
@@ -1087,206 +1131,293 @@ function ct_enqueue_scripts_public($_hook){
1087
  $apbct->settings['forms__check_internal'] ||
1088
  $apbct->settings['comments__bp_private_messages'] ||
1089
  $apbct->settings['data__general_postdata_test']
1090
- ){
1091
-
1092
- if( ! $apbct->public_script_loaded ) {
1093
-
1094
- apbct_enqueue_and_localize_public_scripts();
1095
-
1096
- }
1097
 
1098
- // ct_nocache
1099
  // @todo needs to be refactored
1100
- if(
1101
- ( !defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') || (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') && CLEANTALK_AJAX_USE_FOOTER_HEADER) ) &&
 
 
 
1102
  $apbct->settings['data__use_ajax'] && // Use AJAX for JavaScript check
1103
- ! apbct_is_in_uri( '.xml' ) &&
1104
- ! apbct_is_in_uri( '.xsl' ) &&
1105
- ! apbct_is_in_uri( 'jm-ajax' )
1106
- ){
1107
-
1108
  // Collect details about browsers
1109
- if($apbct->settings['misc__collect_details']){
1110
- wp_enqueue_script('ct_collect_details', plugins_url('/cleantalk-spam-protect/js/cleantalk_collect_details.min.js'), array(), APBCT_VERSION, false /*in header*/);
 
 
 
 
 
 
1111
  wp_localize_script('ct_collect_details', 'ctCollectDetails', array(
1112
  'set_cookies_flag' => $apbct->settings['data__set_cookies'] ? false : true,
1113
  ));
1114
  }
1115
 
1116
- wp_enqueue_script('ct_nocache', plugins_url('/cleantalk-spam-protect/js/cleantalk_nocache.min.js'), array(), APBCT_VERSION, false /*in header*/);
 
 
 
 
 
 
1117
  wp_localize_script('ct_nocache', 'ctNocache', array(
1118
- 'ajaxurl' => admin_url('admin-ajax.php', 'relative'),
1119
- 'info_flag' => $apbct->settings['misc__collect_details'] && $apbct->settings['data__set_cookies'],
1120
- 'set_cookies_flag' => (bool) $apbct->settings['data__set_cookies'],
1121
- 'blog_home' => get_home_url().'/',
1122
  ));
1123
  }
1124
 
1125
- // GDPR script
1126
- if($apbct->settings['gdpr__enabled']){
1127
-
1128
- wp_enqueue_script('ct_public_gdpr', APBCT_URL_PATH.'/js/apbct-public--gdpr.min.js', array('jquery', 'ct_public'), APBCT_VERSION, false /*in header*/);
1129
-
1130
- wp_localize_script('ct_public_gdpr', 'ctPublicGDPR', array(
1131
- 'gdpr_forms' => array(),
1132
- 'gdpr_text' => $apbct->settings['gdpr__text'] ?: __( 'By using this form you agree with the storage and processing of your data by using the Privacy Policy on this website.', 'cleantalk-spam-protect' ),
1133
- ));
1134
- }
1135
-
1136
- }
 
 
 
 
 
 
 
1137
 
1138
  // External forms check
1139
- if($apbct->settings['forms__check_external']){
1140
- wp_enqueue_script( 'ct_external', plugins_url( '/cleantalk-spam-protect/js/cleantalk_external.min.js' ), array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
 
 
 
 
 
 
1141
  }
1142
 
1143
  // Internal forms check
1144
- if($apbct->settings['forms__check_internal']){
1145
- wp_enqueue_script( 'ct_internal', plugins_url( '/cleantalk-spam-protect/js/cleantalk_internal.min.js' ), array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
 
 
 
 
 
 
1146
  }
1147
 
1148
- // Show controls for commentaries
1149
- if(in_array("administrator", $current_user->roles)){
1150
-
1151
- if($apbct->settings['comments__manage_comments_on_public_page']){
1152
-
1153
- $ajax_nonce = wp_create_nonce( "ct_secret_nonce" );
1154
-
1155
- wp_enqueue_style ('ct_public_admin_css', plugins_url('/cleantalk-spam-protect/css/cleantalk-public-admin.min.css'), array(), APBCT_VERSION, 'all');
1156
- wp_enqueue_script('ct_public_admin_js', plugins_url('/cleantalk-spam-protect/js/cleantalk-public-admin.min.js'), array('jquery'), APBCT_VERSION, false /*in header*/);
1157
-
1158
- wp_localize_script('ct_public_admin_js', 'ctPublicAdmin', array(
1159
- 'ct_ajax_nonce' => $ajax_nonce,
1160
- 'ajaxurl' => admin_url('admin-ajax.php', 'relative'),
1161
- 'ct_feedback_error' => __('Error occurred while sending feedback.', 'cleantalk-spam-protect'),
1162
- 'ct_feedback_no_hash' => __('Feedback wasn\'t sent. There is no associated request.', 'cleantalk-spam-protect'),
1163
- '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/show_requests?user_token={$apbct->user_token}&cp_mode=antispam>" : '', $apbct->user_token ? "</a>" : ''),
1164
- ));
1165
-
1166
- }
1167
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1168
 
1169
- // Debug
1170
- if($apbct->settings['misc__debug_ajax']){
1171
- wp_enqueue_script('ct_debug_js', plugins_url('/cleantalk-spam-protect/js/cleantalk-debug-ajax.min.js'), array('jquery'), APBCT_VERSION, false /*in header*/);
 
 
 
 
 
 
1172
 
1173
- wp_localize_script('ct_debug_js', 'apbctDebug', array(
1174
- 'reload' => false,
1175
- 'reload_time' => 10000,
1176
- ));
1177
- }
1178
  }
1179
 
1180
- function apbct_enqueue_and_localize_public_scripts() {
1181
-
1182
- global $apbct;
1183
-
1184
- // Different JS params
1185
- wp_enqueue_script( 'ct_public_functions', APBCT_URL_PATH . '/js/apbct-public--functions.min.js', array( 'jquery' ), APBCT_VERSION );
1186
- wp_enqueue_script( 'ct_public', APBCT_URL_PATH . '/js/apbct-public.min.js', array( 'jquery', 'ct_public_functions' ), APBCT_VERSION );
1187
- wp_enqueue_script('cleantalk-modal', plugins_url( '/cleantalk-spam-protect/js/cleantalk-modal.min.js' ), array(), APBCT_VERSION );
1188
-
1189
- wp_localize_script('ct_public_functions', 'ctPublicFunctions', array(
1190
- '_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
1191
- '_rest_nonce' => wp_create_nonce('wp_rest'),
1192
- '_ajax_url' => admin_url('admin-ajax.php', 'relative'),
1193
- '_rest_url' => esc_url( apbct_get_rest_url() ),
1194
- '_apbct_ajax_url' => APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php',
1195
- 'data__set_cookies' => $apbct->settings['data__set_cookies'],
1196
- 'data__set_cookies__alt_sessions_type' => $apbct->settings['data__set_cookies__alt_sessions_type'],
1197
- ));
1198
-
1199
- wp_localize_script('ct_public', 'ctPublic', array(
1200
- 'pixel__setting' => $apbct->settings['data__pixel'],
1201
- 'pixel__enabled' => $apbct->settings['data__pixel'] === '2' ||
1202
- ( $apbct->settings['data__pixel'] === '3' && apbct_is_cache_plugins_exists() ),
1203
- 'pixel__url' => $apbct->pixel_url,
1204
- 'data__email_check_before_post' =>$apbct->settings['data__email_check_before_post'],
1205
- ));
1206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1207
  }
1208
 
1209
  /**
1210
  * Reassign callbackback function for the bootom of comment output.
1211
  */
1212
- function ct_wp_list_comments_args($options){
1213
-
1214
- global $current_user, $apbct;
1215
-
1216
- if(in_array("administrator", $current_user->roles)){
1217
- if($apbct->settings['comments__manage_comments_on_public_page']) {
1218
- $theme = wp_get_theme();
1219
- $apbct->active_theme = $theme->get( 'Name' );
1220
- $options['end-callback'] = 'ct_comments_output';
1221
- }
1222
- }
1223
 
1224
- return $options;
1225
  }
1226
 
1227
  /**
1228
  * Callback function for the bottom comment output.
1229
  */
1230
- function ct_comments_output($curr_comment, $_param2, $wp_list_comments_args){
1231
-
1232
- global $apbct;
1233
-
1234
- $email = $curr_comment->comment_author_email;
1235
- $ip = $curr_comment->comment_author_IP;
1236
- $id = $curr_comment->comment_ID;
1237
-
1238
- $settings_link = '/wp-admin/'.(is_network_admin() ? "settings.php?page=cleantalk" : "options-general.php?page=cleantalk");
1239
-
1240
- echo "<div class='ct_comment_info'><div class ='ct_comment_titles'>";
1241
- echo "<p class='ct_comment_info_title'>".__('Sender info', 'cleantalk-spam-protect')."</p>";
1242
-
1243
- echo "<p class='ct_comment_logo_title'>
1244
- ".__('by', 'cleantalk-spam-protect')
1245
- ." <a href='{$settings_link}' target='_blank'><img class='ct_comment_logo_img' src='".plugins_url()."/cleantalk-spam-protect/inc/images/logo_color.png'></a>"
1246
- ." <a href='{$settings_link}' target='_blank'>CleanTalk</a>"
1247
- ."</p></div>";
1248
- // Outputs email if exists
1249
- if($email) {
1250
- echo "<a href='https://cleantalk.org/blacklists/$email' target='_blank' title='https://cleantalk.org/blacklists/$email'>"
1251
- . "$email"
1252
- . "&nbsp;<img src='" . plugins_url() . "/cleantalk-spam-protect/inc/images/new_window.gif' border='0' style='float:none; box-shadow: transparent 0 0 0 !important;'/>"
1253
- . "</a>";
1254
- }
1255
- else {
1256
- echo __( 'No email', 'cleantalk-spam-protect' );
1257
- }
1258
- echo "&nbsp;|&nbsp;";
1259
-
1260
- // Outputs IP if exists
1261
- if($ip) {
1262
- echo "<a href='https://cleantalk.org/blacklists/$ip' target='_blank' title='https://cleantalk.org/blacklists/$ip'>"
1263
- . "$ip"
1264
- . "&nbsp;<img src='" . plugins_url() . "/cleantalk-spam-protect/inc/images/new_window.gif' border='0' style='float:none; box-shadow: transparent 0 0 0 !important;'/>"
1265
- . "</a>";
1266
- }
1267
- else {
1268
- echo __( 'No IP', 'cleantalk-spam-protect' );
1269
- }
1270
- echo '&nbsp;|&nbsp;';
1271
-
1272
- echo "<span commentid='$id' class='ct_this_is ct_this_is_spam' href='#'>".__('Mark as spam', 'cleantalk-spam-protect')."</span>";
1273
- echo "<span commentid='$id' class='ct_this_is ct_this_is_not_spam ct_hidden' href='#'>".__('Unspam', 'cleantalk-spam-protect')."</span>";
1274
- echo "<p class='ct_feedback_wrap'>";
1275
- echo "<span class='ct_feedback_result ct_feedback_result_spam'>".__('Marked as spam.', 'cleantalk-spam-protect')."</span>";
1276
- echo "<span class='ct_feedback_result ct_feedback_result_not_spam'>".__('Marked as not spam.', 'cleantalk-spam-protect')."</span>";
1277
- echo "&nbsp;<span class='ct_feedback_msg'><span>";
1278
- echo "</p>";
1279
-
1280
- echo "</div>";
1281
-
1282
- // @todo research what such themes and make exception for them
1283
- $ending_tag = isset( $wp_list_comments_args['style'] ) ? $wp_list_comments_args['style'] : null ;
1284
- if( in_array( $apbct->active_theme, array( 'Paperio', 'Twenty Twenty' ) ) ){
1285
- $ending_tag = is_null($wp_list_comments_args['style']) ? 'div' : $wp_list_comments_args['style'];
1286
- };
1287
-
1288
- // Ending comment output
1289
- echo "</{$ending_tag}>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1290
  }
1291
 
1292
  /**
@@ -1294,17 +1425,17 @@ function ct_comments_output($curr_comment, $_param2, $wp_list_comments_args){
1294
  *
1295
  * attrs = array()
1296
  */
1297
- function apbct_shrotcode_handler__GDPR_public_notice__form( $attrs ){
 
 
1298
 
1299
- $out = '';
1300
-
1301
- if(isset($attrs['id'])) {
1302
- $out .= 'ctPublicGDPR.gdpr_forms.push("' . $attrs['id'] . '");';
1303
- }
1304
 
1305
- if(isset($attrs['text'])) {
1306
- $out .= 'ctPublicGDPR.gdpr_text = "' . $attrs['text'] . '";';
1307
- }
1308
 
1309
- return '<script ' . ( class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '' ) . '>' . $out . '</script>';
1310
  }
9
  * @throws Exception
10
  * @psalm-suppress UnusedVariable
11
  */
12
+ function apbct_init()
13
+ {
14
  global $ct_jp_comments, $apbct;
15
 
16
  // Pixel
17
+ if ( $apbct->settings['data__pixel'] ) {
 
18
  $pixel_hash = md5(
19
+ Helper::ipGet()
20
+ . $apbct->api_key
21
+ . Helper::timeGetIntervalStart(3600 * 3) // Unique for every 3 hours
22
  );
23
 
24
+ $server = get_option('cleantalk_server');
25
+ $server_url = isset($server['ct_work_url']) ? $apbct->server['ct_work_url'] : APBCT_MODERATE_URL;
26
+ $pixel = '/pixel/' . $pixel_hash . '.gif';
27
+ $apbct->pixel_url = str_replace('http://', 'https://', $server_url) . $pixel;
28
  }
29
 
30
  //Check internal forms with such "action" http://wordpress.loc/contact-us/some_script.php
31
+ if ( (isset($_POST['action']) && $_POST['action'] === 'ct_check_internal') &&
32
+ $apbct->settings['forms__check_internal']
33
+ ) {
34
  $ct_result = ct_contact_form_validate();
35
+ if ( $ct_result == null ) {
36
  echo 'true';
37
  die();
38
+ } else {
39
  echo $ct_result;
40
  die();
41
  }
42
  }
43
 
44
  //fix for EPM registration form
45
+ if ( isset($_POST) && isset($_POST['reg_email']) && shortcode_exists('epm_registration_form') ) {
46
+ unset($_POST['ct_checkjs_register_form']);
 
47
  }
48
 
49
+ if ( isset($_POST['_wpnonce-et-pb-contact-form-submitted']) ) {
50
+ add_shortcode('et_pb_contact_form', 'ct_contact_form_validate');
 
51
  }
52
 
53
+ if ( $apbct->settings['forms__check_external'] ) {
54
+ // Fixing form and directs it this site
55
+ if (
56
+ $apbct->settings['forms__check_external__capture_buffer'] &&
57
+ ! is_admin() &&
58
+ ! apbct_is_ajax() &&
59
+ ! apbct_is_post() &&
60
+ apbct_is_user_enable() &&
61
+ ! (defined('DOING_CRON') && DOING_CRON) &&
62
+ ! (defined('XMLRPC_REQUEST') && XMLRPC_REQUEST)
63
+ ) {
64
+ if (
65
+ defined('CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL') &&
66
+ is_string(CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL)
67
+ ) {
68
+ $catch_buffer = false;
69
+ $urls = explode(',', CLEANTALK_CAPTURE_BUFFER_SPECIFIC_URL);
70
+ foreach ( $urls as $url ) {
71
+ if ( apbct_is_in_uri($url) ) {
72
+ $catch_buffer = true;
73
+ }
74
+ }
75
+ } else {
76
+ $catch_buffer = true;
77
+ }
78
 
79
+ if ( $catch_buffer ) {
80
+ add_action('wp', 'apbct_buffer__start');
81
+ add_action('shutdown', 'apbct_buffer__end', 0);
82
+ add_action('shutdown', 'apbct_buffer__output', 2);
83
+ }
84
+ }
85
 
86
+ // Check and redirecct
87
+ if ( apbct_is_post()
88
+ && isset($_POST['cleantalk_hidden_method'])
89
+ && isset($_POST['cleantalk_hidden_action'])
90
+ ) {
91
+ $action = htmlspecialchars($_POST['cleantalk_hidden_action']);
92
+ $method = htmlspecialchars($_POST['cleantalk_hidden_method']);
93
+ unset($_POST['cleantalk_hidden_action']);
94
+ unset($_POST['cleantalk_hidden_method']);
95
+ ct_contact_form_validate();
96
+ if ( ! apbct_is_ajax() ) {
97
+ print "<html lang=''><body><form method='$method' action='$action'>";
98
+ ct_print_form($_POST, '');
99
+ print "</form></body></html>";
100
+ print "<script " . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '') . ">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  if(document.forms[0].submit !== 'undefined'){
102
  var objects = document.getElementsByName('submit');
103
  if(objects.length > 0)
105
  }
106
  document.forms[0].submit();
107
  </script>";
108
+ die();
109
+ }
110
+ }
111
+ }
112
 
113
+ if ( isset($_POST['quform_ajax'], $_POST['quform_csrf_token'], $_POST['quform_form_id']) ) {
114
+ require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-ajax.php');
115
+ ct_ajax_hook();
116
+ }
117
 
118
+ /**hooks for cm answers pro */
119
+ if ( defined('CMA_PLUGIN_FILE') ) {
120
+ add_action('wp', 'ct_ajax_hook', 1);
121
+ }
122
 
123
+ //hook for Anonymous Post
124
+ if ( $apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7']) ) {
125
+ add_action('wp', 'ct_contact_form_validate_postdata', 1);
126
  }
127
 
128
+ if ( $apbct->settings['forms__general_contact_forms_test'] == 1 && empty($_POST['ct_checkjs_cf7']) ) {
129
+ add_action('CMA_custom_post_type_nav', 'ct_contact_form_validate_postdata', 1);
130
+ ct_contact_form_validate();
131
+ if ( isset($_POST['reg_redirect_link']) && isset($_POST['tmpl_registration_nonce_field']) ) {
132
+ unset($_POST['ct_checkjs_register_form']);
133
+ ct_contact_form_validate();
134
+ }
135
+ }
 
136
 
137
+ if ( $apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7']) ) {
138
+ add_action('CMA_custom_post_type_nav', 'ct_contact_form_validate_postdata', 1);
139
  }
140
 
141
  // Fast Secure contact form
142
+ if ( defined('FSCF_VERSION') ) {
143
+ add_filter('si_contact_display_after_fields', 'ct_si_contact_display_after_fields');
144
+ add_filter('si_contact_form_validate', 'ct_si_contact_form_validate');
145
+ }
146
 
147
  // WooCommerce registration
148
+ if ( class_exists('WooCommerce') ) {
149
+ add_filter('woocommerce_registration_errors', 'ct_registration_errors', 1, 3);
150
+ if ( $apbct->settings['forms__wc_checkout_test'] == 1 ) {
151
+ add_filter('woocommerce_checkout_process', 'ct_woocommerce_checkout_check', 1, 3);
152
  }
153
+ if ( isset($_REQUEST['wc-ajax']) && $_REQUEST['wc-ajax'] === 'checkout' && empty($apbct->settings['forms__wc_register_from_order']) ) {
154
+ remove_filter('woocommerce_registration_errors', 'ct_registration_errors', 1);
155
  }
156
 
157
+ //Woocommerce add_to_cart action
158
+ add_action('woocommerce_add_to_cart', 'apbct_wc__add_to_cart_unlogged_user', 10, 6);
159
  }
160
 
161
+ // WooCommerce whishlist
162
+ if ( class_exists('WC_Wishlists_Wishlist') ) {
163
+ add_filter('wc_wishlists_create_list_args', 'ct_woocommerce_wishlist_check', 1, 1);
164
+ }
165
 
166
 
167
  // JetPack Contact form
168
+ if ( defined('JETPACK__VERSION') ) {
 
169
  // Checking Jetpack contact form
170
+ if ( isset($_POST['action']) && $_POST['action'] === 'grunion-contact-form' ) {
171
+ if ( JETPACK__VERSION === '3.4-beta' ) {
 
172
  add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
173
+ } elseif ( JETPACK__VERSION === '3.4-beta2' || JETPACK__VERSION >= '3.4' ) {
174
+ add_filter('jetpack_contact_form_is_spam', 'ct_contact_form_is_spam_jetpack', 50, 2);
175
+ } else {
 
 
 
 
176
  add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
177
  }
178
+ } else {
 
179
  add_filter('grunion_contact_form_field_html', 'ct_grunion_contact_form_field_html', 10, 2);
180
  }
181
 
182
  // Checking Jetpack comments form
183
  $jetpack_active_modules = get_option('jetpack_active_modules');
184
+ if (
185
+ class_exists('Jetpack', false) &&
186
+ $jetpack_active_modules &&
187
+ in_array('comments', $jetpack_active_modules)
188
+ ) {
189
  $ct_jp_comments = true;
190
  }
 
191
  }
192
 
193
+ // WP Maintenance Mode (wpms)
194
+ add_action('wpmm_head', 'apbct_form__wpmm__addField', 1);
195
 
196
  // Contact Form7
197
+ if ( defined('WPCF7_VERSION') ) {
198
+ add_filter('wpcf7_form_elements', 'apbct_form__contactForm7__addField');
199
+ add_filter('wpcf7_validate', 'apbct_form__contactForm7__tesSpam__before_validate', 999, 2);
200
+ $hook = WPCF7_VERSION >= '3.0.0' ? 'wpcf7_spam' : 'wpcf7_acceptance';
201
+ $num_arg = WPCF7_VERSION >= '5.3.0' ? 2 : 1;
202
+ add_filter($hook, 'apbct_form__contactForm7__testSpam', 9999, $num_arg);
203
+ }
204
 
205
  // Formidable
206
+ add_filter('frm_entries_before_create', 'apbct_form__formidable__testSpam', 10, 2);
207
+ add_action('frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2);
208
 
209
  // BuddyPress
210
+ if ( class_exists('BuddyPress') ) {
211
+ add_action('bp_before_registration_submit_buttons', 'ct_register_form', 1);
212
+ add_action('messages_message_before_save', 'apbct_integration__buddyPres__private_msg_check', 1);
213
+ add_filter('bp_signup_validate', 'ct_registration_errors', 1);
214
+ add_filter('bp_signup_validate', 'ct_check_registration_erros', 999999);
215
+ }
216
 
217
+ if ( defined('PROFILEPRESS_SYSTEM_FILE_PATH') ) {
218
+ add_filter('pp_registration_validation', 'ct_registration_errors_ppress', 11, 2);
219
+ }
220
 
221
  // bbPress
222
+ if ( class_exists('bbPress') ) {
223
+ add_filter('bbp_new_topic_pre_title', 'ct_bbp_get_topic', 1);
224
+ add_filter('bbp_new_topic_pre_content', 'ct_bbp_new_pre_content', 1);
225
+ add_filter('bbp_new_reply_pre_content', 'ct_bbp_new_pre_content', 1);
226
+ add_action('bbp_theme_before_topic_form_content', 'ct_comment_form');
227
+ add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
228
+ }
229
+
230
+ //Custom Contact Forms
231
+ if ( defined('CCF_VERSION') ) {
232
+ add_filter('ccf_field_validator', 'ct_ccf', 1, 4);
233
+ }
234
 
235
  add_action('comment_form', 'ct_comment_form');
236
 
237
  // intercept WordPress Landing Pages POST
238
+ if ( defined('LANDINGPAGES_CURRENT_VERSION') && ! empty($_POST) ) {
239
+ if ( array_key_exists('action', $_POST) && $_POST['action'] === 'inbound_store_lead' ) { // AJAX action(s)
240
  ct_check_wplp();
241
+ } elseif (
242
+ array_key_exists('inbound_submitted', $_POST) &&
243
+ $_POST['inbound_submitted'] == '1'
244
+ ) {
245
+ // Final submit
246
  ct_check_wplp();
247
  }
248
  }
249
 
250
  // S2member. intercept POST
251
+ if ( defined('WS_PLUGIN__S2MEMBER_PRO_VERSION') ) {
252
+ $post_keys = array_keys($_POST);
253
+ foreach ( $post_keys as $post_key ) {
254
+ // Detect POST keys like /s2member_pro.*registration/
255
+ if ( strpos($post_key, 's2member') !== false && strpos($post_key, 'registration') !== false ) {
256
+ ct_s2member_registration_test($post_key);
257
+ break;
258
+ }
259
+ }
260
+ }
261
 
262
  // New user approve hack
263
  // https://wordpress.org/plugins/new-user-approve/
264
+ if ( ct_plugin_active('new-user-approve/new-user-approve.php') ) {
265
  add_action('register_post', 'ct_register_post', 1, 3);
266
  }
267
 
268
+ // Wilcity theme registration validation fix
269
+ add_filter(
270
+ 'wilcity/filter/wiloke-listing-tools/validate-before-insert-account',
271
+ 'apbct_wilcity_reg_validation',
272
+ 10,
273
+ 2
274
+ );
275
 
276
  // Gravity forms
277
+ if ( defined('GF_MIN_WP_VERSION') ) {
278
+ add_filter('gform_get_form_filter', 'apbct_form__gravityForms__addField', 10, 2);
279
+ add_filter('gform_entry_is_spam', 'apbct_form__gravityForms__testSpam', 999, 3);
280
+ add_filter('gform_confirmation', 'apbct_form__gravityForms__showResponse', 999, 4);
281
+ }
282
+
283
+ //Pirate forms
284
+ if ( defined('PIRATE_FORMS_VERSION') ) {
285
+ if ( isset($_POST['pirate-forms-contact-name']) && $_POST['pirate-forms-contact-name'] && isset($_POST['pirate-forms-contact-email']) && $_POST['pirate-forms-contact-email'] ) {
286
+ apbct_form__piratesForm__testSpam();
287
+ }
288
+ }
289
+
290
+ // WPForms
291
+ // Adding fields
292
+ add_action('wpforms_frontend_output', 'apbct_form__WPForms__addField', 1000, 5);
293
+ // Gathering data to validate
294
+ add_filter('wpforms_process_before_filter', 'apbct_from__WPForms__gatherData', 100, 2);
295
+ // Do spam check
296
+ add_filter('wpforms_process_initial_errors', 'apbct_form__WPForms__showResponse', 100, 2);
297
+
298
+ // QForms integration
299
+ add_filter('quform_post_validate', 'ct_quform_post_validate', 10, 2);
300
+
301
+ // Ultimate Members
302
+ if ( class_exists('UM') ) {
303
+ add_action('um_main_register_fields', 'ct_register_form', 100); // Add hidden fileds
304
+ add_action('um_submit_form_register', 'apbct_registration__UltimateMembers__check', 9, 1); // Check submition
305
+ }
306
+
307
+ // Paid Memberships Pro integration
308
+ add_filter('pmpro_required_user_fields', function ($pmpro_required_user_fields) {
309
+ if (
310
+ ! empty($pmpro_required_user_fields['username']) &&
311
+ ! empty($pmpro_required_user_fields['bemail']) &&
312
+ ! empty($pmpro_required_user_fields['bconfirmemail']) &&
 
313
  $pmpro_required_user_fields['bemail'] == $pmpro_required_user_fields['bconfirmemail']
314
  ) {
315
+ $check = ct_test_registration(
316
+ $pmpro_required_user_fields['username'],
317
+ $pmpro_required_user_fields['bemail']
318
+ );
319
+ if ( $check['allow'] == 0 && function_exists('pmpro_setMessage') ) {
320
+ pmpro_setMessage($check['comment'], 'pmpro_error');
321
  }
322
  }
323
 
324
  return $pmpro_required_user_fields;
325
+ });
 
326
 
327
  //
328
  // Load JS code to website footer
329
  //
330
+ if ( ! (defined('DOING_AJAX') && DOING_AJAX) ) {
331
+ add_action('wp_head', 'apbct_hook__wp_head__set_cookie__ct_checkjs', 1);
332
  add_action('wp_footer', 'apbct_hook__wp_footer', 1);
333
  }
334
 
335
+ if ( $apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() ) {
336
  ct_contact_form_validate();
337
  }
338
 
339
  if ( apbct_is_user_enable() ) {
340
+ if ( $apbct->settings['forms__general_contact_forms_test'] == 1 && ! isset($_POST['comment_post_ID']) && ! isset($_GET['for']) ) {
341
+ add_action('init', 'ct_contact_form_validate', 999);
 
342
  }
343
+ if ( apbct_is_post() &&
344
+ $apbct->settings['data__general_postdata_test'] == 1 &&
345
+ ! isset($_POST['ct_checkjs_cf7']) &&
346
+ ! is_admin() &&
347
+ ! apbct_is_user_role_in(array('administrator', 'moderator'))
348
+ ) {
349
+ ct_contact_form_validate_postdata();
350
+ }
351
+ }
 
 
 
 
 
 
 
 
352
 
353
+ /**
354
+ * Integration with custom forms
355
+ */
356
+ if ( ! empty($_POST) && apbct_custom_forms_trappings() ) {
357
+ ct_contact_form_validate();
358
+ }
359
  }
360
 
361
+ function apbct_buffer__start()
362
+ {
363
+ ob_start();
364
+ }
365
 
366
+ function apbct_buffer__end()
367
+ {
368
+ if ( ! ob_get_level() ) {
369
+ return;
370
+ }
371
 
372
+ global $apbct;
373
+ $apbct->buffer = ob_get_contents();
374
+ ob_end_clean();
375
  }
376
 
377
  /**
379
  *
380
  * @global $apbct
381
  */
382
+ function apbct_buffer__output()
383
+ {
384
+ global $apbct;
385
 
386
+ if ( empty($apbct->buffer) ) {
387
+ return;
388
+ }
389
 
390
+ if ( apbct_is_plugin_active('flow-flow/flow-flow.php') ) {
391
+ $output = apbct_buffer_modify_by_string();
392
+ } else {
393
+ $output = apbct_buffer_modify_by_dom();
394
+ }
395
 
396
+ echo $output;
397
+ die();
398
  }
399
 
400
+ function apbct_buffer_modify_by_string()
401
+ {
402
+ global $apbct, $wp;
 
 
 
403
 
404
+ $site_url = get_option('siteurl');
405
+ $site__host = parse_url($site_url, PHP_URL_HOST);
406
 
407
+ preg_match_all('/<form\s*.*>\s*.*<\/form>/', $apbct->buffer, $matches, PREG_SET_ORDER);
 
408
 
409
+ if ( count($matches) > 0 ) {
410
+ foreach ( $matches as $match ) {
411
+ preg_match('/action="(\S*)"/', $match[0], $group_action);
412
+ $action = count($group_action) > 0 ? $group_action[1] : $site_url;
413
 
414
+ $action__host = parse_url($action, PHP_URL_HOST);
415
+ if ( $site__host != $action__host ) {
416
+ preg_match('/method="(\S*)"/', $match[0], $group_method);
417
+ $method = count($group_method) > 0 ? $group_method[1] : 'get';
418
 
419
+ $hidden_fields = '<input type="hidden" name="cleantalk_hidden_action" value="' . $action . '">';
420
+ $hidden_fields .= '<input type="hidden" name="cleantalk_hidden_method" value="' . $method . '">';
421
 
422
+ $modified_match = preg_replace(
423
+ '/action="\S*"/',
424
+ 'action="' . home_url(add_query_arg(array(), $wp->request)) . '"',
425
+ $match[0]
426
+ );
427
+ $modified_match = preg_replace('/method="\S*"/', 'method="POST"', $modified_match);
428
+ $modified_match = str_replace('</form>', $hidden_fields . '</form>', $modified_match);
429
+ $apbct->buffer = str_replace($match[0], $modified_match, $apbct->buffer);
430
+ }
431
+ }
432
+ }
 
433
 
434
+ return $apbct->buffer;
435
  }
436
 
437
+ function apbct_buffer_modify_by_dom()
438
+ {
439
+ global $apbct, $wp;
440
+
441
+ $site_url = get_option('siteurl');
442
+ $site__host = parse_url($site_url, PHP_URL_HOST);
443
+
444
+ $dom = new DOMDocument();
445
+ @$dom->loadHTML($apbct->buffer, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
446
+
447
+ $forms = $dom->getElementsByTagName('form');
448
+
449
+ foreach ( $forms as $form ) {
450
+ $action = $form->getAttribute('action');
451
+ $action = $action ?: $site_url;
452
+ $action__host = parse_url($action, PHP_URL_HOST);
453
+
454
+ // Check if the form directed to the third party site
455
+ if ( $site__host != $action__host ) {
456
+ $method = $form->getAttribute('method');
457
+ $method = $method ?: 'get';
458
+ // Directs form to our site
459
+ $form->setAttribute('method', 'POST');
460
+ $form->setAttribute('action', home_url(add_query_arg(array(), $wp->request)));
461
+
462
+ // Add cleantalk_hidden_action
463
+ $new_input = $dom->createElement('input');
464
+ $new_input->setAttribute('type', 'hidden');
465
+ $new_input->setAttribute('name', 'cleantalk_hidden_action');
466
+ $new_input->setAttribute('value', $action);
467
+ $form->appendChild($new_input);
468
+
469
+ // Add cleantalk_hidden_method
470
+ $new_input = $dom->createElement('input');
471
+ $new_input->setAttribute('type', 'hidden');
472
+ $new_input->setAttribute('name', 'cleantalk_hidden_method');
473
+ $new_input->setAttribute('value', $method);
474
+ $form->appendChild($new_input);
475
+ }
476
+ }
477
+ unset($form);
 
 
 
 
 
478
 
479
+ $html = $dom->getElementsByTagName('html');
 
 
480
 
481
+ return is_object($html) && isset($html[0], $html[0]->childNodes[0]) && $dom->getElementsByTagName(
482
+ 'rss'
483
+ )->length == 0
484
+ ? $dom->saveHTML()
485
+ : $apbct->buffer;
486
  }
487
 
488
  /**
489
  * Adds cookie script filed to head
490
  */
491
+ function apbct_hook__wp_head__set_cookie__ct_checkjs()
492
+ {
493
  ct_add_hidden_fields('ct_checkjs', false, true, true);
494
 
495
  return null;
499
  * Adds check_js script to the footer
500
  * @psalm-suppress UnusedVariable
501
  */
502
+ function apbct_hook__wp_footer()
503
+ {
504
+ global $apbct;
505
 
506
+ # Return false if page is excluded
507
+ if ( apbct_exclusions_check__url() ) {
508
+ return;
509
+ }
510
 
511
+ // Pixel
512
+ if (
513
  $apbct->settings['data__pixel'] === '1' ||
514
+ ($apbct->settings['data__pixel'] === '3' && apbct_is_cache_plugins_exists())
515
+ ) {
516
+ echo '<img alt="Cleantalk Pixel" id="apbct_pixel" style="display: none;" src="' . $apbct->pixel_url . '">';
517
+ }
518
+
519
+ if ( $apbct->settings['data__use_ajax'] ) {
520
+ $timeout = $apbct->settings['misc__async_js'] ? 1000 : 0;
521
+
522
+ if ( $apbct->use_rest_api ) {
523
+ $html =
524
+ "<script type=\"text/javascript\" " . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '')
525
+ . ">
526
+ window.addEventListener('DOMContentLoaded', function () {
527
+ setTimeout(function(){
528
+ if( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {
529
+ apbct_public_sendREST(
530
+ 'js_keys__get',
531
+ { callback: apbct_js_keys__set_input_value }
532
+ )
533
+ }
534
+ }," . $timeout . ")
535
+ });
536
+ </script>";
537
+ } else {
538
+ $html =
539
+ "<script type=\"text/javascript\" " . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '')
540
+ . ">
541
+ window.addEventListener('DOMContentLoaded', function () {
542
+ setTimeout(function(){
543
+ if( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {
544
+ apbct_public_sendAJAX(
545
+ { action: 'apbct_js_keys__get' },
546
+ { callback: apbct_js_keys__set_input_value, apbct_ajax: 1 }
547
+ );
548
+ }
549
+ }," . $timeout . ")
550
+ });
551
+ </script>";
552
+ }
553
+
554
+ echo $html;
555
+ }
556
  }
557
 
558
  /**
568
  *
569
  * @psalm-suppress UnusedVariable
570
  */
571
+ function ct_add_hidden_fields(
572
+ $field_name = 'ct_checkjs',
573
+ $return_string = false,
574
+ $cookie_check = false,
575
+ $no_print = false,
576
+ $ajax = true
577
+ ) {
578
+ # Return false if page is excluded
579
+ if ( apbct_exclusions_check__url() ) {
580
+ return false;
581
+ }
582
 
583
  global $ct_checkjs_def, $apbct;
584
 
585
  $ct_checkjs_key = ct_get_checkjs_value();
586
+ $field_id_hash = md5((string)rand(0, 1000));
587
+
588
+ // Using only cookies
589
+ if ( $cookie_check && $apbct->settings['data__set_cookies'] ) {
590
+ $html =
591
+ "<script type=\"text/javascript\" "
592
+ . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '')
593
+ . ">
594
+ function apbct_attach_event_handler__backend(elem, event, callback){
595
+ if(typeof window.addEventListener === \"function\") elem.addEventListener(event, callback);
596
+ else elem.attachEvent(event, callback);
597
+ }
598
+ apbct_attach_event_handler__backend(window, 'load', function(){
599
+ ctSetCookie('{$field_name}', '{$ct_checkjs_key}' );
600
+ });
601
+ </script>";
602
+ // Using AJAX to get key
603
+ } elseif ( $apbct->settings['data__use_ajax'] && $ajax ) {
604
+ // Fix only for wp_footer -> apbct_hook__wp_head__set_cookie__ct_checkjs()
605
+ if ( $no_print ) {
606
+ return;
607
+ }
 
 
608
 
609
+ $field_id = $field_name . '_' . $field_id_hash;
610
+ $html = "<input type=\"hidden\" id=\"{$field_id}\" name=\"{$field_name}\" value=\"{$ct_checkjs_def}\" />";
611
+ // Set KEY from backend
612
+ } else {
613
+ // Fix only for wp_footer -> apbct_hook__wp_head__set_cookie__ct_checkjs()
614
+ if ( $no_print ) {
615
+ return;
616
+ }
617
 
618
  $ct_input_challenge = sprintf("'%s'", $ct_checkjs_key);
619
+ $field_id = $field_name . '_' . $field_id_hash;
620
+ $html = "<input type=\"hidden\" id=\"{$field_id}\" name=\"{$field_name}\" value=\"{$ct_checkjs_def}\" />
621
+ <script type=\"text/javascript\" " . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '') . ">
622
  setTimeout(function(){
623
  var ct_input_name = \"{$field_id}\";
624
  if (document.getElementById(ct_input_name) !== null) {
627
  }
628
  }, 1000);
629
  </script>";
630
+ }
631
 
632
  // Simplify JS code and Fixing issue with wpautop()
633
+ $html = str_replace(array("\n", "\r", "\t"), '', $html);
634
 
635
+ if ( $return_string === true ) {
636
  return $html;
637
  } else {
638
  echo $html;
644
  *
645
  * @param bool $maybe_notify notify flag
646
  * @param int $comment_ID Comment id
647
+ *
648
  * @return bool flag
649
  */
650
+ function apbct_comment__Wordpress__doNotify($_maybe_notify, $_comment_ID)
651
+ {
652
+ return true;
653
  }
654
 
655
  /**
656
  * Add notification setting link
657
  *
658
+ * @param string $notify_message
659
  * @param integer $comment_id
660
  *
661
  * @return string
662
  */
663
+ function apbct_comment__Wordpress__changeMailNotificationGroups($notify_message, $_comment_id)
664
+ {
665
+ return $notify_message
666
+ . PHP_EOL
667
+ . '---' . PHP_EOL
668
+ . 'Manage notifications settings: ' . get_site_url() . '/wp-admin/options-general.php?page=cleantalk';
669
  }
670
 
671
  /**
672
  * Change email notification recipients
673
  *
674
+ * @param array $emails
675
+ * @param integer $comment_id
676
  *
677
  * @return array
678
  * @global \Cleantalk\ApbctWP\State $apbct
679
  */
680
+ function apbct_comment__Wordpress__changeMailNotificationRecipients($emails, $_comment_id)
681
+ {
682
+ global $apbct;
683
+
684
+ return array_unique(array_merge($emails, (array)json_decode($apbct->comment_notification_recipients, true)));
685
  }
686
 
687
  /**
692
  *
693
  * @return string Body for email notification
694
  */
695
+ function apbct_comment__Wordpress__changeMailNotification($notify_message, $_comment_id)
696
+ {
697
+ global $apbct;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
698
 
699
+ return PHP_EOL
700
+ . __('CleanTalk AntiSpam: This message is possible spam.', 'cleantalk-spam-protect')
701
+ . "\n" . __('You could check it in CleanTalk\'s anti-spam database:', 'cleantalk-spam-protect')
702
+ . "\n" . 'IP: https://cleantalk.org/blacklists/' . $apbct->sender_ip
703
+ . "\n" . 'Email: https://cleantalk.org/blacklists/' . $apbct->sender_email
704
+ . "\n" . PHP_EOL . sprintf(
705
+ __('Activate protection in your Anti-Spam Dashboard: %s.', 'clentalk'),
706
+ 'https://cleantalk.org/my/?cp_mode=antispam&utm_source=newsletter&utm_medium=email&utm_campaign=wp_spam_comment_passed'
707
+ . ($apbct->data['user_token']
708
+ ? '&iser_token=' . $apbct->data['user_token']
709
+ : ''
710
+ )
711
+ )
712
+ . PHP_EOL . '---'
713
+ . PHP_EOL
714
+ . PHP_EOL
715
+ . $notify_message;
716
  }
717
 
718
+ function apbct_comment__wordpress__show_blacklists($notify_message, $comment_id)
719
+ {
720
+ $comment_details = get_comments(array('comment__in' => $comment_id));
721
  $comment_details = $comment_details[0];
722
 
723
+ if ( isset($comment_details->comment_author_email) ) {
 
724
  $black_list_link = 'https://cleantalk.org/blacklists/';
725
 
726
  $links = PHP_EOL;
727
+ $links .= esc_html__('Check for spam:', 'cleantalk-spam-protect');
728
  $links .= PHP_EOL;
729
  $links .= $black_list_link . $comment_details->comment_author_email;
730
  $links .= PHP_EOL;
731
+ if ( ! empty($comment_details->comment_author_IP) ) {
732
  $links .= $black_list_link . $comment_details->comment_author_IP;
733
  $links .= PHP_EOL;
734
  }
735
 
736
  return $notify_message . $links;
 
737
  }
738
 
739
  return $notify_message;
 
740
  }
741
 
742
  /**
743
  * Set die page with Cleantalk comment.
744
+ *
745
+ * @param null $comment_status
746
+ *
747
  * @global null $ct_comment
748
  * $err_text = '<center><b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . __('Spam protection', 'cleantalk-spam-protect') . "</center><br><br>\n" . $ct_comment;
 
749
  */
750
+ function ct_die($_comment_id, $_comment_status)
751
+ {
752
  global $ct_comment, $ct_jp_comments;
753
 
754
+ do_action('apbct_pre_block_page', $ct_comment);
755
 
756
  $message_title = __('Spam protection', 'cleantalk-spam-protect');
757
+ if ( defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE != true ) {
758
+ $message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
759
  }
760
+ if ( isset($_POST['et_pb_contact_email']) ) {
761
+ $message_title = 'Blacklisted';
762
  }
763
 
764
+ $back_link = '';
765
+ $back_script = '';
766
+ if ( ! $ct_jp_comments ) {
767
+ $back_script = '<script>setTimeout("history.back()", 5000);</script>';
768
+ } elseif ( isset($_SERVER['HTTP_REFERER']) ) {
769
+ $back_link = '<a href="' . $_SERVER['HTTP_REFERER'] . '">' . __('Back') . '</a>';
770
+ }
 
 
771
 
772
+ if ( file_exists(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html") ) {
773
+ $ct_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html");
774
 
775
+ // Translation
776
+ $replaces = array(
777
+ '{MESSAGE_TITLE}' => $message_title,
778
+ '{MESSAGE}' => $ct_comment,
779
+ '{BACK_LINK}' => $back_link,
780
+ '{BACK_SCRIPT}' => $back_script
781
+ );
782
 
783
+ foreach ( $replaces as $place_holder => $replace ) {
784
+ $ct_die_page = str_replace($place_holder, $replace, $ct_die_page);
785
+ }
786
 
787
+ http_response_code(200);
788
+ die($ct_die_page);
789
+ }
790
 
791
+ http_response_code(200);
792
+ die("Forbidden. Sender blacklisted. Blocked by Cleantalk");
793
  }
794
 
795
  /**
796
  * Set die page with Cleantalk comment from parameter.
797
+ *
798
  * @param $comment_body
799
  */
800
+ function ct_die_extended($comment_body)
801
+ {
802
  global $ct_jp_comments;
803
 
804
  $message_title = __('Spam protection', 'cleantalk-spam-protect');
805
+ if ( defined('CLEANTALK_DISABLE_BLOCKING_TITLE') && CLEANTALK_DISABLE_BLOCKING_TITLE != true ) {
806
  $message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
807
  }
808
 
809
+ $back_link = '';
810
  $back_script = '';
811
+ if ( ! $ct_jp_comments ) {
812
  $back_script = '<script>setTimeout("history.back()", 5000);</script>';
813
  } else {
814
  $back_link = '<a href="' . $_SERVER['HTTP_REFERER'] . '">' . __('Back') . '</a>';
815
  }
816
 
817
+ if ( file_exists(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html") ) {
 
818
  $ct_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "templates/lock-pages/lock-page-ct-die.html");
819
 
820
  // Translation
825
  '{BACK_SCRIPT}' => $back_script
826
  );
827
 
828
+ foreach ( $replaces as $place_holder => $replace ) {
829
+ $ct_die_page = str_replace($place_holder, $replace, $ct_die_page);
830
  }
831
 
832
  http_response_code(200);
846
  *
847
  * @return int|null
848
  */
849
+ function apbct_js_test($field_name = 'ct_checkjs', $data = null, $is_cookie = false)
850
+ {
851
  global $apbct;
852
 
853
  $out = null;
854
 
855
+ if (
856
  ($data && isset($data[$field_name])) ||
857
+ ($is_cookie && $apbct->settings['data__set_cookies'] == 2 && Cookie::get($field_name))
858
+ ) {
859
+ $js_key = $is_cookie && $apbct->settings['data__set_cookies'] == 2
860
+ ? Cookie::get($field_name)
 
861
  : trim($data[$field_name]);
862
 
863
+ // Check static key
864
+ if (
865
+ $apbct->settings['data__use_static_js_key'] == 1 ||
866
+ ($apbct->settings['data__use_static_js_key'] == -1 &&
867
+ (apbct_is_cache_plugins_exists() ||
868
+ (apbct_is_post() && isset($apbct->data['cache_detected']) && $apbct->data['cache_detected'] == 1)
869
+ )
870
+ )
871
+ ) {
872
+ $out = ct_get_checkjs_value() === $js_key ? 1 : 0;
873
+ // Random key check
874
+ } else {
875
+ $out = array_key_exists($js_key, $apbct->js_keys) ? 1 : 0;
876
+ }
 
877
  }
878
 
879
  return $out;
887
  *
888
  * @return string|null
889
  */
890
+ function ct_post_url($comment_id, $comment_post_id)
891
+ {
892
+ if ( empty($comment_post_id) ) {
893
+ return null;
894
  }
895
 
896
+ if ( $comment_id === null ) {
897
+ $last_comment = get_comments('number=1');
898
+ $comment_id = isset($last_comment[0]->comment_ID) ? (int)$last_comment[0]->comment_ID + 1 : 1;
899
  }
900
  $permalink = get_permalink($comment_post_id);
901
 
902
  $post_url = null;
903
+ if ( $permalink !== null ) {
904
+ $post_url = $permalink . '#comment-' . $comment_id;
905
  }
906
 
907
  return $post_url;
909
 
910
  /**
911
  * Public filter 'pre_comment_approved' - Mark comment unapproved always
912
+ * @return int Zero
913
  */
914
+ function ct_set_not_approved()
915
+ {
916
  return 0;
917
  }
918
 
924
  *
925
  * @return int|string "spam"|1
926
  */
927
+ function ct_set_approved($approved, $_comment)
928
+ {
929
+ if ( $approved === 'spam' ) {
930
  return $approved;
931
  }
932
 
933
+ return 1;
934
  }
935
 
936
  /**
937
  * Public filter 'pre_comment_approved' - Mark comment unapproved always
938
+ * @return string
939
  */
940
+ function ct_set_comment_spam()
941
+ {
942
  return 'spam';
943
  }
944
 
945
  /**
946
  * Public action 'comment_post' - Store cleantalk hash in comment meta 'ct_hash'
947
+ *
948
+ * @param int $comment_id Comment ID
949
+ * @param mixed $comment_status Approval status ("spam", or 0/1), not used
950
  */
951
+ function ct_set_meta($comment_id, $comment_status)
952
+ {
953
  global $comment_post_id;
954
  $hash1 = ct_hash();
955
+ if ( ! empty($hash1) ) {
956
  update_comment_meta($comment_id, 'ct_hash', $hash1);
957
+ if ( function_exists('base64_encode') && isset($comment_status) && $comment_status !== 'spam' ) {
958
+ $post_url = ct_post_url($comment_id, $comment_post_id);
959
+ $post_url = base64_encode($post_url);
960
+ // 01 - URL to approved comment
961
+ $feedback_request = $hash1 . ':' . '01' . ':' . $post_url . ';';
962
+ ct_send_feedback($feedback_request);
963
+ }
964
  }
965
+
966
  return true;
967
  }
968
 
969
  /**
970
  * Mark bad words
971
+ *
972
  * @param int $comment_id
973
  * @param int $comment_status Not use
974
  *
975
  * @psalm-suppress UndefinedMethod
976
+ * @global string $ct_stop_words
977
  */
978
+ function ct_mark_red($comment_id, $_comment_status)
979
+ {
980
  global $ct_stop_words;
981
 
982
  $comment = get_comment($comment_id, 'ARRAY_A');
983
  $message = $comment['comment_content'];
984
+ foreach ( explode(':', $ct_stop_words) as $word ) {
985
  $message = preg_replace("/($word)/ui", '<font rel="cleantalk" color="#FF1000">' . "$1" . '</font>', $message);
 
986
  }
987
  $comment['comment_content'] = $message;
988
  kses_remove_filters();
992
  //
993
  //Send post to trash
994
  //
995
+ function ct_wp_trash_comment($comment_id, $_comment_status)
996
+ {
997
+ wp_trash_comment($comment_id);
998
  }
999
 
1000
  /**
1001
+ * Tests plugin activation status
1002
+ * @return bool
1003
+ */
1004
+ function ct_plugin_active($plugin_name)
1005
+ {
1006
+ foreach ( get_option('active_plugins') as $_k => $v ) {
1007
+ if ( $plugin_name == $v ) {
1008
+ return true;
1009
+ }
1010
+ }
1011
+
1012
+ return false;
1013
  }
1014
 
1015
  /**
1016
  * @psalm-suppress UnusedVariable
1017
  */
1018
+ function apbct_login__scripts()
1019
+ {
1020
  global $apbct;
1021
 
1022
+ apbct_enqueue_and_localize_public_scripts();
1023
 
1024
  $apbct->public_script_loaded = true;
1025
  }
1028
  * Inner function - Finds and returns pattern in string
1029
  * @return bool
1030
  */
1031
+ function ct_get_data_from_submit($value = null, $field_name = null)
1032
+ {
1033
+ if ( ! $value || ! $field_name || ! is_string($value) ) {
1034
  return false;
1035
  }
1036
+ if ( preg_match("/[a-z0-9_\-]*" . $field_name . "[a-z0-9_\-]*$/", $value) ) {
1037
  return true;
1038
  }
1039
+
1040
+ return false;
1041
  }
1042
 
1043
  /**
1044
  * Sends error notice to admin
1045
  * @return null
1046
  */
1047
+ function ct_send_error_notice($comment = '')
1048
+ {
1049
  global $ct_admin_notoice_period, $apbct;
1050
 
1051
+ $timelabel_reg = intval(get_option('cleantalk_timelabel_reg'));
1052
+ if ( time() - $ct_admin_notoice_period > $timelabel_reg ) {
1053
  update_option('cleantalk_timelabel_reg', time());
1054
 
1055
  $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
1056
  $message = __('Attention, please!', 'cleantalk-spam-protect') . "\r\n\r\n";
1057
+ $message .=
1058
+ sprintf(
1059
+ __('"%s" plugin error on your site "%s":', 'cleantalk-spam-protect'),
1060
+ $apbct->plugin_name,
1061
+ $blogname
1062
+ )
1063
+ . "\r\n\r\n";
1064
+ $message .=
1065
+ preg_replace(
1066
+ '/^(.*?)<a.*?"(.*?)".*?>(.*?)<.a>(.*)$/',
1067
+ '$1. $3: $2?user_token=' . $apbct->user_token . ' $4',
1068
+ $comment
1069
+ )
1070
+ . "\r\n\r\n";
1071
+ @wp_mail(
1072
+ ct_get_admin_email(),
1073
+ sprintf(__('[%s] "%s" error!', 'cleantalk-spam-protect'), $apbct->plugin_name, $blogname),
1074
+ $message
1075
+ );
1076
  }
1077
 
1078
  return null;
1084
  * @param $arr
1085
  * @param $k
1086
  */
1087
+ function ct_print_form($arr, $k)
1088
+ {
1089
+ // Fix for pages04.net forms
1090
+ if ( isset($arr['formSourceName']) ) {
1091
+ $tmp = array();
1092
+ foreach ( $arr as $key => $val ) {
1093
+ $tmp_key = str_replace('_', '+', $key);
1094
+ $tmp[$tmp_key] = $val;
1095
+ }
1096
+ $arr = $tmp;
1097
+ unset($tmp, $key, $tmp_key, $val);
1098
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
1099
 
1100
+ foreach ( $arr as $key => $value ) {
1101
+ if ( ! is_array($value) ) {
1102
+ print '<textarea
1103
+ name="' . ($k == '' ? $key : $k . '[' . $key . ']') . '"
1104
+ style="display:none;">' . htmlspecialchars($value)
1105
+ . '</textarea>';
1106
+ } else {
1107
+ ct_print_form($value, $k == '' ? $key : $k . '[' . $key . ']');
1108
+ }
1109
+ }
1110
  }
1111
 
1112
  /**
1113
  * Attaches public scripts and styles.
1114
  * @psalm-suppress UnusedVariable
1115
  */
1116
+ function ct_enqueue_scripts_public($_hook)
1117
+ {
1118
+ global $current_user, $apbct;
1119
 
1120
+ if ( apbct_exclusions_check__url() ) {
1121
+ return;
1122
+ }
 
 
1123
 
1124
+ if (
1125
+ $apbct->settings['forms__registrations_test'] ||
1126
  $apbct->settings['forms__comments_test'] ||
1127
  $apbct->settings['forms__contact_forms_test'] ||
1128
  $apbct->settings['forms__general_contact_forms_test'] ||
1131
  $apbct->settings['forms__check_internal'] ||
1132
  $apbct->settings['comments__bp_private_messages'] ||
1133
  $apbct->settings['data__general_postdata_test']
1134
+ ) {
1135
+ if ( ! $apbct->public_script_loaded ) {
1136
+ apbct_enqueue_and_localize_public_scripts();
1137
+ }
 
 
 
1138
 
1139
+ // ct_nocache
1140
  // @todo needs to be refactored
1141
+ if (
1142
+ (
1143
+ ! defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') ||
1144
+ (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') && CLEANTALK_AJAX_USE_FOOTER_HEADER)
1145
+ ) &&
1146
  $apbct->settings['data__use_ajax'] && // Use AJAX for JavaScript check
1147
+ ! apbct_is_in_uri('.xml') &&
1148
+ ! apbct_is_in_uri('.xsl') &&
1149
+ ! apbct_is_in_uri('jm-ajax')
1150
+ ) {
 
1151
  // Collect details about browsers
1152
+ if ( $apbct->settings['misc__collect_details'] ) {
1153
+ wp_enqueue_script(
1154
+ 'ct_collect_details',
1155
+ plugins_url('/cleantalk-spam-protect/js/cleantalk_collect_details.min.js'),
1156
+ array(),
1157
+ APBCT_VERSION,
1158
+ false /*in header*/
1159
+ );
1160
  wp_localize_script('ct_collect_details', 'ctCollectDetails', array(
1161
  'set_cookies_flag' => $apbct->settings['data__set_cookies'] ? false : true,
1162
  ));
1163
  }
1164
 
1165
+ wp_enqueue_script(
1166
+ 'ct_nocache',
1167
+ plugins_url('/cleantalk-spam-protect/js/cleantalk_nocache.min.js'),
1168
+ array(),
1169
+ APBCT_VERSION,
1170
+ false /*in header*/
1171
+ );
1172
  wp_localize_script('ct_nocache', 'ctNocache', array(
1173
+ 'ajaxurl' => admin_url('admin-ajax.php', 'relative'),
1174
+ 'info_flag' => $apbct->settings['misc__collect_details'] && $apbct->settings['data__set_cookies'],
1175
+ 'set_cookies_flag' => (bool)$apbct->settings['data__set_cookies'],
1176
+ 'blog_home' => get_home_url() . '/',
1177
  ));
1178
  }
1179
 
1180
+ // GDPR script
1181
+ if ( $apbct->settings['gdpr__enabled'] ) {
1182
+ wp_enqueue_script(
1183
+ 'ct_public_gdpr',
1184
+ APBCT_URL_PATH . '/js/apbct-public--gdpr.min.js',
1185
+ array('jquery', 'ct_public'),
1186
+ APBCT_VERSION,
1187
+ false /*in header*/
1188
+ );
1189
+
1190
+ wp_localize_script('ct_public_gdpr', 'ctPublicGDPR', array(
1191
+ 'gdpr_forms' => array(),
1192
+ 'gdpr_text' => $apbct->settings['gdpr__text'] ?: __(
1193
+ 'By using this form you agree with the storage and processing of your data by using the Privacy Policy on this website.',
1194
+ 'cleantalk-spam-protect'
1195
+ ),
1196
+ ));
1197
+ }
1198
+ }
1199
 
1200
  // External forms check
1201
+ if ( $apbct->settings['forms__check_external'] ) {
1202
+ wp_enqueue_script(
1203
+ 'ct_external',
1204
+ plugins_url('/cleantalk-spam-protect/js/cleantalk_external.min.js'),
1205
+ array('jquery'),
1206
+ APBCT_VERSION,
1207
+ false /*in header*/
1208
+ );
1209
  }
1210
 
1211
  // Internal forms check
1212
+ if ( $apbct->settings['forms__check_internal'] ) {
1213
+ wp_enqueue_script(
1214
+ 'ct_internal',
1215
+ plugins_url('/cleantalk-spam-protect/js/cleantalk_internal.min.js'),
1216
+ array('jquery'),
1217
+ APBCT_VERSION,
1218
+ false /*in header*/
1219
+ );
1220
  }
1221
 
1222
+ // Show controls for commentaries
1223
+ if ( in_array("administrator", $current_user->roles) ) {
1224
+ if ( $apbct->settings['comments__manage_comments_on_public_page'] ) {
1225
+ $ajax_nonce = wp_create_nonce("ct_secret_nonce");
1226
+
1227
+ wp_enqueue_style(
1228
+ 'ct_public_admin_css',
1229
+ plugins_url('/cleantalk-spam-protect/css/cleantalk-public-admin.min.css'),
1230
+ array(),
1231
+ APBCT_VERSION,
1232
+ 'all'
1233
+ );
1234
+ wp_enqueue_script(
1235
+ 'ct_public_admin_js',
1236
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-public-admin.min.js'),
1237
+ array('jquery'),
1238
+ APBCT_VERSION,
1239
+ false /*in header*/
1240
+ );
1241
+
1242
+ wp_localize_script('ct_public_admin_js', 'ctPublicAdmin', array(
1243
+ 'ct_ajax_nonce' => $ajax_nonce,
1244
+ 'ajaxurl' => admin_url('admin-ajax.php', 'relative'),
1245
+ 'ct_feedback_error' => __('Error occurred while sending feedback.', 'cleantalk-spam-protect'),
1246
+ 'ct_feedback_no_hash' => __(
1247
+ 'Feedback wasn\'t sent. There is no associated request.',
1248
+ 'cleantalk-spam-protect'
1249
+ ),
1250
+ 'ct_feedback_msg' => sprintf(
1251
+ __("Feedback has been sent to %sCleanTalk Dashboard%s.", 'cleantalk-spam-protect'),
1252
+ $apbct->user_token ? "<a target='_blank' href=https://cleantalk.org/my/show_requests?user_token={$apbct->user_token}&cp_mode=antispam>" : '',
1253
+ $apbct->user_token ? "</a>" : ''
1254
+ ),
1255
+ ));
1256
+ }
1257
+ }
1258
 
1259
+ // Debug
1260
+ if ( $apbct->settings['misc__debug_ajax'] ) {
1261
+ wp_enqueue_script(
1262
+ 'ct_debug_js',
1263
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-debug-ajax.min.js'),
1264
+ array('jquery'),
1265
+ APBCT_VERSION,
1266
+ false /*in header*/
1267
+ );
1268
 
1269
+ wp_localize_script('ct_debug_js', 'apbctDebug', array(
1270
+ 'reload' => false,
1271
+ 'reload_time' => 10000,
1272
+ ));
1273
+ }
1274
  }
1275
 
1276
+ function apbct_enqueue_and_localize_public_scripts()
1277
+ {
1278
+ global $apbct;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1279
 
1280
+ // Different JS params
1281
+ wp_enqueue_script(
1282
+ 'ct_public_functions',
1283
+ APBCT_URL_PATH . '/js/apbct-public--functions.min.js',
1284
+ array('jquery'),
1285
+ APBCT_VERSION
1286
+ );
1287
+ wp_enqueue_script(
1288
+ 'ct_public',
1289
+ APBCT_URL_PATH . '/js/apbct-public.min.js',
1290
+ array('jquery', 'ct_public_functions'),
1291
+ APBCT_VERSION
1292
+ );
1293
+ wp_enqueue_script(
1294
+ 'cleantalk-modal',
1295
+ plugins_url('/cleantalk-spam-protect/js/cleantalk-modal.min.js'),
1296
+ array(),
1297
+ APBCT_VERSION
1298
+ );
1299
+
1300
+ wp_localize_script('ct_public_functions', 'ctPublicFunctions', array(
1301
+ '_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
1302
+ '_rest_nonce' => wp_create_nonce('wp_rest'),
1303
+ '_ajax_url' => admin_url('admin-ajax.php', 'relative'),
1304
+ '_rest_url' => esc_url(apbct_get_rest_url()),
1305
+ '_apbct_ajax_url' => APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php',
1306
+ 'data__set_cookies' => $apbct->settings['data__set_cookies'],
1307
+ 'data__set_cookies__alt_sessions_type' => $apbct->settings['data__set_cookies__alt_sessions_type'],
1308
+ ));
1309
+
1310
+ wp_localize_script('ct_public', 'ctPublic', array(
1311
+ 'pixel__setting' => $apbct->settings['data__pixel'],
1312
+ 'pixel__enabled' => $apbct->settings['data__pixel'] === '2' ||
1313
+ ($apbct->settings['data__pixel'] === '3' && apbct_is_cache_plugins_exists()),
1314
+ 'pixel__url' => $apbct->pixel_url,
1315
+ 'data__email_check_before_post' => $apbct->settings['data__email_check_before_post'],
1316
+ ));
1317
  }
1318
 
1319
  /**
1320
  * Reassign callbackback function for the bootom of comment output.
1321
  */
1322
+ function ct_wp_list_comments_args($options)
1323
+ {
1324
+ global $current_user, $apbct;
1325
+
1326
+ if ( in_array("administrator", $current_user->roles) ) {
1327
+ if ( $apbct->settings['comments__manage_comments_on_public_page'] ) {
1328
+ $theme = wp_get_theme();
1329
+ $apbct->active_theme = $theme->get('Name');
1330
+ $options['end-callback'] = 'ct_comments_output';
1331
+ }
1332
+ }
1333
 
1334
+ return $options;
1335
  }
1336
 
1337
  /**
1338
  * Callback function for the bottom comment output.
1339
  */
1340
+ function ct_comments_output($curr_comment, $_param2, $wp_list_comments_args)
1341
+ {
1342
+ global $apbct;
1343
+
1344
+ $email = $curr_comment->comment_author_email;
1345
+ $ip = $curr_comment->comment_author_IP;
1346
+ $id = $curr_comment->comment_ID;
1347
+
1348
+ $settings_link = '/wp-admin/' . (is_network_admin() ? "settings.php?page=cleantalk" : "options-general.php?page=cleantalk");
1349
+
1350
+ echo "<div class='ct_comment_info'><div class ='ct_comment_titles'>";
1351
+ echo "<p class='ct_comment_info_title'>" . __('Sender info', 'cleantalk-spam-protect') . "</p>";
1352
+
1353
+ echo "<p class='ct_comment_logo_title'>
1354
+ " . __('by', 'cleantalk-spam-protect')
1355
+ . " <a href='{$settings_link}' target='_blank'><img class='ct_comment_logo_img' src='" . plugins_url(
1356
+ ) . "/cleantalk-spam-protect/inc/images/logo_color.png'></a>"
1357
+ . " <a href='{$settings_link}' target='_blank'>CleanTalk</a>"
1358
+ . "</p></div>";
1359
+ // Outputs email if exists
1360
+ if ( $email ) {
1361
+ echo "<a href='https://cleantalk.org/blacklists/$email' target='_blank' title='https://cleantalk.org/blacklists/$email'>"
1362
+ . "$email"
1363
+ . "&nbsp;<img src='" . plugins_url(
1364
+ ) . "/cleantalk-spam-protect/inc/images/new_window.gif' border='0' style='float:none; box-shadow: transparent 0 0 0 !important;'/>"
1365
+ . "</a>";
1366
+ } else {
1367
+ echo __('No email', 'cleantalk-spam-protect');
1368
+ }
1369
+ echo "&nbsp;|&nbsp;";
1370
+
1371
+ // Outputs IP if exists
1372
+ if ( $ip ) {
1373
+ echo "<a href='https://cleantalk.org/blacklists/$ip' target='_blank' title='https://cleantalk.org/blacklists/$ip'>"
1374
+ . "$ip"
1375
+ . "&nbsp;<img src='" . plugins_url(
1376
+ ) . "/cleantalk-spam-protect/inc/images/new_window.gif' border='0' style='float:none; box-shadow: transparent 0 0 0 !important;'/>"
1377
+ . "</a>";
1378
+ } else {
1379
+ echo __('No IP', 'cleantalk-spam-protect');
1380
+ }
1381
+ echo '&nbsp;|&nbsp;';
1382
+
1383
+ echo "<span commentid='$id' class='ct_this_is ct_this_is_spam' href='#'>"
1384
+ . __(
1385
+ 'Mark as spam',
1386
+ 'cleantalk-spam-protect'
1387
+ )
1388
+ . "</span>";
1389
+ echo "<span commentid='$id' class='ct_this_is ct_this_is_not_spam ct_hidden' href='#'>"
1390
+ . __(
1391
+ 'Unspam',
1392
+ 'cleantalk-spam-protect'
1393
+ )
1394
+ . "</span>";
1395
+ echo "<p class='ct_feedback_wrap'>";
1396
+ echo "<span class='ct_feedback_result ct_feedback_result_spam'>"
1397
+ . __(
1398
+ 'Marked as spam.',
1399
+ 'cleantalk-spam-protect'
1400
+ )
1401
+ . "</span>";
1402
+ echo "<span class='ct_feedback_result ct_feedback_result_not_spam'>"
1403
+ . __(
1404
+ 'Marked as not spam.',
1405
+ 'cleantalk-spam-protect'
1406
+ )
1407
+ . "</span>";
1408
+ echo "&nbsp;<span class='ct_feedback_msg'><span>";
1409
+ echo "</p>";
1410
+
1411
+ echo "</div>";
1412
+
1413
+ // @todo research what such themes and make exception for them
1414
+ $ending_tag = isset($wp_list_comments_args['style']) ? $wp_list_comments_args['style'] : null;
1415
+ if ( in_array($apbct->active_theme, array('Paperio', 'Twenty Twenty')) ) {
1416
+ $ending_tag = is_null($wp_list_comments_args['style']) ? 'div' : $wp_list_comments_args['style'];
1417
+ };
1418
+
1419
+ // Ending comment output
1420
+ echo "</{$ending_tag}>";
1421
  }
1422
 
1423
  /**
1425
  *
1426
  * attrs = array()
1427
  */
1428
+ function apbct_shrotcode_handler__GDPR_public_notice__form($attrs)
1429
+ {
1430
+ $out = '';
1431
 
1432
+ if ( isset($attrs['id']) ) {
1433
+ $out .= 'ctPublicGDPR.gdpr_forms.push("' . $attrs['id'] . '");';
1434
+ }
 
 
1435
 
1436
+ if ( isset($attrs['text']) ) {
1437
+ $out .= 'ctPublicGDPR.gdpr_text = "' . $attrs['text'] . '";';
1438
+ }
1439
 
1440
+ return '<script ' . (class_exists('Cookiebot_WP') ? 'data-cookieconsent="ignore"' : '') . '>' . $out . '</script>';
1441
  }
inc/cleantalk-settings.php CHANGED
@@ -1,1266 +1,1648 @@
1
  <?php
2
 
 
3
  use Cleantalk\Variables\Post;
4
 
5
  /**
6
  * Admin action 'admin_menu' - Add the admin options page
7
  */
8
- function apbct_settings_add_page() {
9
-
10
- global $apbct, $pagenow;
11
-
12
- $parent_slug = is_network_admin() ? 'settings.php' : 'options-general.php';
13
- $callback = is_network_admin() ? 'apbct_settings__display__network' : 'apbct_settings__display';
14
-
15
- // Adding settings page
16
- add_submenu_page(
17
- $parent_slug,
18
- $apbct->plugin_name.' '.__('settings'),
19
- $apbct->plugin_name,
20
- 'manage_options',
21
- 'cleantalk',
22
- $callback
23
- );
24
-
25
- if(!in_array($pagenow, array('options.php', 'options-general.php', 'settings.php', 'admin.php')))
26
- return;
27
-
28
- register_setting('cleantalk_settings', 'cleantalk_settings', array('type' => 'string', 'sanitize_callback' => 'apbct_settings__validate', 'default' => null));
29
-
30
- $fields = apbct_settings__set_fileds();
31
- $fields = APBCT_WPMS && is_main_site() ? apbct_settings__set_fileds__network($fields) : $fields;
32
- apbct_settings__add_groups_and_fields($fields);
33
-
 
 
 
 
34
  }
35
 
36
- function apbct_settings__set_fileds( ){
37
- global $apbct;
 
38
 
39
  $additional_ac_title = '';
40
- if( $apbct->api_key && is_null( $apbct->fw_stats['firewall_updating_id'] ) ) {
41
- if( $apbct->settings['sfw__enabled'] && ! $apbct->stats['sfw']['entries'] ) {
42
- $additional_ac_title = ' <span style="color:red">' . esc_html__( 'The functionality was disabled because SpamFireWall database is empty. Please, do the synchronization or', 'cleantalk-spam-protect' ) . ' ' . '<a href="https://cleantalk.org/my/support/open" target="_blank" style="color:red">'. esc_html__( 'contact to our support.', 'cleantalk-spam-protect' ) .'</a></span>';
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
  }
45
- $additional_sfw_description = '';
46
- if( ! empty( $apbct->data['notice_incompatibility'] ) ){
47
- $additional_sfw_description .= '<br>';
48
- foreach( $apbct->data['notice_incompatibility'] as $notice ) {
49
- $additional_sfw_description .= '<span style="color:red">' . $notice . '</span><br>';
50
- }
51
- }
52
-
53
- $fields = array(
54
-
55
- 'main' => array(
56
- 'title' => '',
57
- 'default_params' => array(),
58
- 'description' => '',
59
- 'html_before' => '',
60
- 'html_after' => '',
61
- 'fields' => array(
62
- 'action_buttons' => array(
63
- 'callback' => 'apbct_settings__field__action_buttons',
64
- ),
65
- 'connection_reports' => array(
66
- 'callback' => 'apbct_settings__field__statistics',
67
- ),
68
- 'api_key' => array(
69
- 'callback' => 'apbct_settings__field__apikey',
70
- ),
71
- ),
72
- ),
73
-
74
- 'state' => array(
75
- 'title' => '',
76
- 'default_params' => array(),
77
- 'description' => '',
78
- 'html_before' => '<hr style="width: 100%;">',
79
- 'html_after' => '',
80
- 'fields' => array(
81
- 'state' => array(
82
- 'callback' => 'apbct_settings__field__state',
83
- ),
84
- ),
85
- ),
86
-
87
- 'debug' => array(
88
- 'title' => '',
89
- 'default_params' => array(),
90
- 'description' => '',
91
- 'html_before' => '',
92
- 'html_after' => '',
93
- 'fields' => array(
94
- 'state' => array(
95
- 'callback' => 'apbct_settings__field__debug',
96
- ),
97
- ),
98
- ),
99
-
100
- // Different
101
- 'different' => array(
102
- 'title' => '',
103
- 'default_params' => array(),
104
- 'description' => '',
105
- 'html_before' => '<hr>',
106
- 'html_after' => '',
107
- 'fields' => array(
108
- 'sfw__enabled' => array(
109
- 'type' => 'checkbox',
110
- 'title' => __('SpamFireWall', 'cleantalk-spam-protect'),
111
- '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') . '<br>' .esc_html__( 'If the setting is turned on, plugin will automatically add IP address for each session with administration rights to Personal list in the cloud.', 'cleantalk-spam-protect' )
112
- . $additional_sfw_description,
113
- 'childrens' => array('sfw__anti_flood', 'sfw__anti_crawler', 'sfw__use_delete_to_clear_table'),
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
- 'forms__registrations_test' => array(
133
- 'title' => __('Registration Forms', 'cleantalk-spam-protect'),
134
- 'description' => __('WordPress, BuddyPress, bbPress, S2Member, WooCommerce.', 'cleantalk-spam-protect'),
135
- ),
136
- 'forms__comments_test' => array(
137
- 'title' => __('Comments form', 'cleantalk-spam-protect'),
138
- 'description' => __('WordPress, JetPack, WooCommerce.', 'cleantalk-spam-protect'),
139
- ),
140
- 'forms__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
- 'forms__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
- 'forms__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
- 'forms__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('forms__check_external__capture_buffer'),
163
- ),
164
- 'forms__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' => 'forms__check_external',
169
- ),
170
- 'forms__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
- 'forms__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('forms__wc_register_from_order'),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  'reverse_trigger' => true,
186
- 'options' => array(
187
- array( 'val' => 1, 'label' => __( 'On' ), 'childrens_enable' => 0, ),
188
- array( 'val' => 0, 'label' => __( 'Off' ), 'childrens_enable' => 1, ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  ),
190
- ),
191
- 'forms__wc_register_from_order' => array(
192
- 'title' => __('Spam test for registration during checkout', 'cleantalk-spam-protect'),
193
- 'description' => __('Enable anti spam test for registration process which during woocommerce\'s checkout.', 'cleantalk-spam-protect'),
194
- 'parent' => 'forms__wc_checkout_test',
195
- 'class' => 'apbct_settings-field_wrapper--sub',
196
- 'reverse_trigger' => true,
197
- ),
198
- 'forms__wc_add_to_cart' => array(
199
- 'title' => __('Check anonymous users when they add new items to the cart', 'cleantalk-spam-protect'),
200
- 'description' => __('All anonymous users will be checked for spam if they add a new item to their shopping cart.', 'cleantalk-spam-protect'),
201
- 'reverse_trigger' => false,
202
- 'class' => 'apbct_settings-field_wrapper--sub',
203
- 'options' => array(
204
- array( 'val' => 1, 'label' => __( 'On' ) ),
205
- array( 'val' => 0, 'label' => __( 'Off' ) ),
206
- ),
207
- ),
208
- ),
209
- ),
210
-
211
- // Comments and Messages
212
- 'comments_and_messages' => array(
213
- 'title' => __('Comments and Messages', 'cleantalk-spam-protect'),
214
- 'fields' => array(
215
- 'comments__disable_comments__all' => array(
216
- 'title' => __( 'Disable all comments', 'cleantalk-spam-protect'),
217
- 'description' => __( 'Disabling comments for all types of content.', 'cleantalk-spam-protect'),
218
- 'childrens' => array(
219
- 'comments__disable_comments__posts',
220
- 'comments__disable_comments__pages',
221
- 'comments__disable_comments__media',
222
- ),
223
- 'options' => array(
224
- array( 'val' => 1, 'label' => __( 'On' ), 'childrens_enable' => 0, ),
225
- array( 'val' => 0, 'label' => __( 'Off' ), 'childrens_enable' => 1, ),
226
- ),
227
- ),
228
- 'comments__disable_comments__posts' => array(
229
- 'title' => __( 'Disable comments for all posts', 'cleantalk-spam-protect'),
230
- 'class' => 'apbct_settings-field_wrapper--sub',
231
- // 'parent' => 'comments__disable_comments__all',
232
- 'reverse_trigger' => true,
233
- ),
234
- 'comments__disable_comments__pages' => array(
235
- 'title' => __( 'Disable comments for all pages', 'cleantalk-spam-protect'),
236
- 'class' => 'apbct_settings-field_wrapper--sub',
237
- // 'parent' => 'comments__disable_comments__all',
238
- 'reverse_trigger' => true,
239
- ),
240
- 'comments__disable_comments__media' => array(
241
- 'title' => __( 'Disable comments for all media', 'cleantalk-spam-protect'),
242
- 'class' => 'apbct_settings-field_wrapper--sub',
243
- // 'parent' => 'comments__disable_comments__all',
244
- 'reverse_trigger' => true,
245
- ),
246
- 'comments__bp_private_messages' => array(
247
- 'title' => __('BuddyPress Private Messages', 'cleantalk-spam-protect'),
248
- 'description' => __('Check buddyPress private messages.', 'cleantalk-spam-protect'),
249
- ),
250
- 'comments__remove_old_spam' => array(
251
- 'title' => __('Automatically delete spam comments', 'cleantalk-spam-protect'),
252
- 'description' => sprintf(__('Delete spam comments older than %d days.', 'cleantalk-spam-protect'), $apbct->data['spam_store_days']),
253
- ),
254
- 'comments__remove_comments_links' => array(
255
- 'title' => __('Remove links from approved comments', 'cleantalk-spam-protect'),
256
- 'description' => __('Remove links from approved comments. Replace it with "[Link deleted]"', 'cleantalk-spam-protect'),
257
- ),
258
- 'comments__show_check_links' => array(
259
- 'title' => __('Show links to check Emails, IPs for spam', 'cleantalk-spam-protect'),
260
- 'description' => __('Shows little icon near IP addresses and Emails allowing you to check it via CleanTalk\'s database.', 'cleantalk-spam-protect'),
261
- 'display' => !$apbct->white_label,
262
- ),
263
- 'comments__manage_comments_on_public_page' => array(
264
- 'title' => __('Manage comments on public pages', 'cleantalk-spam-protect'),
265
- 'description' => __('Allows administrators to manage comments on public post\'s pages with small interactive menu.', 'cleantalk-spam-protect'),
266
- 'display' => !$apbct->white_label,
267
- ),
268
- 'comments__hide_website_field' => array(
269
- 'title' => __('Hide the "Website" field', 'cleantalk-spam-protect'),
270
- 'description' => __('This option hides the "Website" field on the comment form.', 'cleantalk-spam-protect'),
271
- 'display' => !$apbct->white_label,
272
- ),
273
- ),
274
- ),
275
-
276
- // Data Processing
277
- 'data_processing' => array(
278
- 'title' => __('Data Processing', 'cleantalk-spam-protect'),
279
- 'fields' => array(
280
- 'data__protect_logged_in' => array(
281
- 'title' => __("Protect logged in Users", 'cleantalk-spam-protect'),
282
- 'description' => __('Turn this option on to check for spam any submissions (comments, contact forms and etc.) from registered Users.', 'cleantalk-spam-protect'),
283
- ),
284
- 'comments__check_comments_number' => array(
285
- 'title' => __("Don't check trusted user's comments", 'cleantalk-spam-protect'),
286
- '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),
287
- ),
288
- 'data__use_ajax' => array(
289
- 'title' => __('Use AJAX for JavaScript check', 'cleantalk-spam-protect'),
290
- 'description' => __('Options helps protect WordPress against spam with any caching plugins. Turn this option on to avoid issues with caching plugins. Turn off this option and SpamFireWall to be compatible with Accelerated mobile pages (AMP).', 'cleantalk-spam-protect'),
291
- ),
292
- 'data__use_static_js_key' => array(
293
- 'title' => __('Use static keys for JavaScript check', 'cleantalk-spam-protect'),
294
- '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'),
295
- 'options' => array(
296
- array('val' => 1, 'label' => __('On'), ),
297
- array('val' => 0, 'label' => __('Off'), ),
298
- array('val' => -1, 'label' => __('Auto'),),
299
- ),
300
- ),
301
- 'data__general_postdata_test' => array(
302
- 'title' => __('Check all post data', 'cleantalk-spam-protect'),
303
- 'description' => __('Check all POST submissions from website visitors. Enable this option if you have spam misses on website.', 'cleantalk-spam-protect')
304
- .(!$apbct->white_label
305
- ? __(' 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>.'
306
- : ''
307
- )
308
- .'<br />' . __('СAUTION! Option can catch POST requests in WordPress backend', 'cleantalk-spam-protect'),
309
- ),
310
- 'data__set_cookies' => array(
311
- 'title' => __( "Set cookies", 'cleantalk-spam-protect' ),
312
- 'description' => __( 'Turn this option off or use alternative mechanism for cookies to forbid the plugin generate any cookies on website\'s front-end.', 'cleantalk-spam-protect' )
313
- . '<br>' . __( 'This option is helpful if you are using Varnish. Most contact forms will have poor protection if the option is turned off!', 'cleantalk-spam-protect' )
314
- . '<br>' . __( 'Alternative mechanism will store data in database and will not set cookies in browser, so the cache solutions will work just fine.', 'cleantalk-spam-protect' )
315
- . '<br><b>' . __( 'Warning: We strongly recommend you keep the setting on, otherwise it could cause false positives spam detection.', 'cleantalk-spam-protect' ) . '</b>',
316
- 'input_type' => 'radio',
317
  'options' => array(
318
- array( 'val' => 1, 'label' => __( 'On', 'cleantalk-spam-protect' ), 'childrens_enable' => 0, ),
319
- array( 'val' => 0, 'label' => __( 'Off', 'cleantalk-spam-protect' ), 'childrens_enable' => 0, ),
320
- array( 'val' => 2, 'label' => __( 'Use alternative mechanism for cookies', 'cleantalk-spam-protect' ), 'childrens_enable' => 1, ),
321
  ),
322
- 'childrens' => array( 'data__set_cookies__alt_sessions_type' )
323
  ),
324
- 'data__set_cookies__alt_sessions_type' => array(
325
- 'title' => __( 'Alternative cookies handler type', 'cleantalk-spam-protect' ),
326
- 'description' => __( 'This could be helpful if you are using alternative mechanism for cookies and have REST API disabled. REST works faster.', 'cleantalk-spam-protect' ),
327
- 'class' => 'apbct_settings-field_wrapper--sub',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  'input_type' => 'radio',
329
  'options' => array(
330
- array( 'val' => 0, 'label' => __( 'Use REST API', 'cleantalk-spam-protect' ), ),
331
- array( 'val' => 1, 'label' => __( 'Use AJAX handler', 'cleantalk-spam-protect' ), ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  ),
333
- 'parent' => 'data__set_cookies',
334
- 'disabled' => $apbct->settings['data__set_cookies'] != 2,
335
- ),
336
- 'data__ssl_on' => array(
337
- 'title' => __("Use SSL", 'cleantalk-spam-protect'),
338
- 'description' => __('Turn this option on to use encrypted (SSL) connection with servers.', 'cleantalk-spam-protect'),
339
- ),
340
- 'wp__use_builtin_http_api' => array(
341
- 'title' => __("Use Wordpress HTTP API", 'cleantalk-spam-protect'),
342
- 'description' => __('Alternative way to connect the Cloud. Use this if you have connection problems.', 'cleantalk-spam-protect'),
343
- ),
344
- 'sfw__use_delete_to_clear_table' => array(
345
- 'title' => __("Use DELETE SQL-command instead TRUNCATE to clear tables", 'cleantalk-spam-protect'),
346
- 'description' => __('Could help if you have blocked SpamFireWall tables in your database.', 'cleantalk-spam-protect'),
347
- 'parent' => 'sfw__enabled',
348
- ),
349
- 'data__pixel' => array(
 
 
 
350
  'title' => __('Add a CleanTalk Pixel to improve IP-detection', 'cleantalk-spam-protect'),
351
- 'description' => __('Upload small graphic file from Cleantalk\'s server to improve IP-detection.', 'cleantalk-spam-protect')
352
- . '<br>' . __('"Auto" use JavaScript option if cache solutions are found.', 'cleantalk-spam-protect'),
 
 
 
 
 
 
 
 
353
  'options' => array(
354
- array( 'val' => 1, 'label' => __( 'Via direct output', 'cleantalk-spam-protect' ), ),
355
- array( 'val' => 2, 'label' => __( 'Via JavaScript', 'cleantalk-spam-protect' ), ),
356
- array( 'val' => 3, 'label' => __( 'Auto', 'cleantalk-spam-protect' ), ),
357
- array( 'val' => 0, 'label' => __( 'Off', 'cleantalk-spam-protect' ), ),
358
  ),
359
  ),
360
- 'data__email_check_before_post' => array(
361
- 'title' => __('Check email before POST request', 'cleantalk-spam-protect'),
362
- 'description' => __('Check email address before sending form data', 'cleantalk-spam-protect'),
363
- ),
364
- ),
365
- ),
366
-
367
- // Exclusions
368
- 'exclusions' => array(
369
- 'title' => __('Exclusions', 'cleantalk-spam-protect'),
370
- 'fields' => array(
371
- 'exclusions__urls' => array(
372
- 'type' => 'textarea',
373
- 'title' => __('URL exclusions', 'cleantalk-spam-protect'),
374
- 'description' => __('You could type here URL you want to exclude. Use comma or new lines as separator.', 'cleantalk-spam-protect'),
375
- ),
376
- 'exclusions__urls__use_regexp' => array(
377
- 'type' => 'checkbox',
378
- 'title' => __('Use Regular Expression in URL Exclusions', 'cleantalk-spam-protect'),
379
- ),
380
- 'exclusions__fields' => array(
381
- 'type' => 'text',
382
- 'title' => __('Field name exclusions', 'cleantalk-spam-protect'),
383
- 'description' => __('You could type here fields names you want to exclude. Use comma as separator.', 'cleantalk-spam-protect'),
384
- ),
385
- 'exclusions__fields__use_regexp' => array(
386
- 'type' => 'checkbox',
387
- 'title' => __('Use Regular Expression in Field Exclusions', 'cleantalk-spam-protect'),
388
- ),
389
- 'exclusions__roles' => array(
390
- 'type' => 'select',
391
- 'multiple' => true,
392
- 'options_callback' => 'apbct_get_all_roles',
393
- 'options_callback_params' => array(true),
394
- 'description' => __('Roles which bypass spam test. Hold CTRL to select multiple roles.', 'cleantalk-spam-protect'),
395
- ),
396
- ),
397
- ),
398
-
399
- // Admin bar
400
- 'admin_bar' => array(
401
- 'title' => __('Admin bar', 'cleantalk-spam-protect'),
402
- 'default_params' => array(),
403
- 'description' => '',
404
- 'html_before' => '',
405
- 'html_after' => '',
406
- 'fields' => array(
407
- 'admin_bar__show' => array(
408
- 'title' => __('Show statistics in admin bar', 'cleantalk-spam-protect'),
409
- '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'),
410
- 'childrens' => array('admin_bar__all_time_counter','admin_bar__daily_counter','admin_bar__sfw_counter'),
411
- ),
412
- 'admin_bar__all_time_counter' => array(
413
- 'title' => __('Show All-time counter', 'cleantalk-spam-protect'),
414
- 'description' => __('Display all-time requests counter in the admin bar. Counter displays number of requests since plugin installation.', 'cleantalk-spam-protect'),
415
- 'parent' => 'admin_bar__show',
416
- 'class' => 'apbct_settings-field_wrapper--sub',
417
- ),
418
- 'admin_bar__daily_counter' => array(
419
- 'title' => __('Show 24 hours counter', 'cleantalk-spam-protect'),
420
- 'description' => __('Display daily requests counter in the admin bar. Counter displays number of requests of the past 24 hours.', 'cleantalk-spam-protect'),
421
- 'parent' => 'admin_bar__show',
422
- 'class' => 'apbct_settings-field_wrapper--sub',
423
- ),
424
- 'admin_bar__sfw_counter' => array(
425
- 'title' => __('SpamFireWall counter', 'cleantalk-spam-protect'),
426
- 'description' => __('Display SpamFireWall requests in the admin bar. Counter displays number of requests since plugin installation.', 'cleantalk-spam-protect'),
427
- 'parent' => 'admin_bar__show',
428
- 'class' => 'apbct_settings-field_wrapper--sub',
429
- ),
430
- ),
431
- ),
432
-
433
- // SFW features
434
- 'sfw_features' => array(
435
- 'title' => __('SpamFireWall features', 'cleantalk-spam-protect'),
436
- 'default_params' => array(),
437
- 'description' => '',
438
- 'html_before' => '',
439
- 'html_after' => '',
440
- 'fields' => array(
441
- 'sfw__random_get' => array(
442
- 'type' => 'radio',
443
- 'options' => array(
444
- array('val' => 1, 'label' => __('On'), ),
445
- array('val' => 0, 'label' => __('Off'), ),
446
- array('val' => -1, 'label' => __('Auto'),),
447
- ),
448
- 'title' => __('Uniq GET option', 'cleantalk-spam-protect'),
449
- 'class' => 'apbct_settings-field_wrapper',
450
- 'parent' => 'sfw__enabled',
451
- 'description' => __('If a visitor gets the SpamFireWall page, the plugin will put a unique GET variable in the URL to avoid issues with caching plugins. Example: https://SITE.COM/?sfw=pass1629985735', 'cleantalk-spam-protect'),
452
- ),
453
- 'sfw__anti_crawler' => array(
454
- 'type' => 'checkbox',
455
- 'title' => __('Anti-Crawler', 'cleantalk-spam-protect') . $additional_ac_title,
456
- 'class' => 'apbct_settings-field_wrapper',
457
- 'parent' => 'sfw__enabled',
458
- 'description' => __('Plugin shows SpamFireWall stop page for any bot, except allowed bots (Google, Yahoo and etc).', 'cleantalk-spam-protect')
459
- . '<br>'
460
- . __( 'Anti-Crawler includes blocking bots by the User-Agent. Use Personal lists in the Dashboard to filter specific User-Agents.', 'cleantalk-spam-protect' ),
461
- ),
462
- 'sfw__anti_flood' => array(
463
- 'type' => 'checkbox',
464
- 'title' => __('Anti-Flood', 'cleantalk-spam-protect'),
465
- 'class' => 'apbct_settings-field_wrapper',
466
- 'parent' => 'sfw__enabled',
467
- 'childrens' => array('sfw__anti_flood__view_limit',),
468
- 'description' => __('Shows the SpamFireWall page for bots trying to crawl your site. Look at the page limit setting below.', 'cleantalk-spam-protect'),
469
- ),
470
- 'sfw__anti_flood__view_limit' => array(
471
- 'type' => 'text',
472
- 'title' => __('Anti-Flood Page Views Limit', 'cleantalk-spam-protect'),
473
- 'class' => 'apbct_settings-field_wrapper--sub',
474
- 'parent' => 'sfw__anti_flood',
475
- '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'),
476
- ),
477
- ),
478
- ),
479
-
480
- // Misc
481
- 'misc' => array(
482
- 'title' => __('Miscellaneous', 'cleantalk-spam-protect'),
483
- 'html_after' => '</div><br>',
484
- 'fields' => array(
485
- 'misc__collect_details' => array(
486
- 'type' => 'checkbox',
487
- 'title' => __('Collect details about browsers', 'cleantalk-spam-protect'),
488
- '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'),
489
- ),
490
- 'misc__send_connection_reports' => array(
491
- 'type' => 'checkbox',
492
- 'title' => __('Send connection reports', 'cleantalk-spam-protect'),
493
- 'description' => __("Checking this box you allow plugin to send the information about your connection. The option in a beta state.", 'cleantalk-spam-protect'),
494
- ),
495
- 'misc__async_js' => array(
496
- 'type' => 'checkbox',
497
- 'title' => __('Async JavaScript loading', 'cleantalk-spam-protect'),
498
- 'description' => __('Use async loading for scripts. Warning: This could reduce filtration quality.', 'cleantalk-spam-protect'),
499
- ),
500
- 'gdpr__enabled' => array(
501
- 'type' => 'checkbox',
502
- 'title' => __('Allow to add GDPR notice via shortcode', 'cleantalk-spam-protect'),
503
- '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'),
504
- 'childrens' => array('gdpr__text'),
505
- ),
506
- 'gdpr__text' => array(
507
- 'type' => 'text',
508
- 'title' => __('GDPR text notice', 'cleantalk-spam-protect'),
509
- 'description' => __('This text will be added as a description to the GDPR checkbox.', 'cleantalk-spam-protect'),
510
- 'parent' => 'gdpr__enabled',
511
- 'class' => 'apbct_settings-field_wrapper--sub',
512
- ),
513
- 'misc__store_urls' => array(
514
- 'type' => 'checkbox',
515
- 'title' => __('Store visited URLs', 'cleantalk-spam-protect'),
516
- 'description' => __("Plugin stores last 5 visited URLs (HTTP REFERRERS) 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'),
517
- ),
518
- 'wp__comment_notify' => array(
519
- 'type' => 'checkbox',
520
- 'title' => __('Notify users with selected roles about new approved comments. Hold CTRL to select multiple roles.', 'cleantalk-spam-protect'),
521
- 'description' => sprintf(__("If enabled, overrides similar Wordpress %sdiscussion settings%s.", 'cleantalk-spam-protect'), '<a href="options-discussion.php">','</a>'),
522
- 'childrens' => array('wp__comment_notify__roles'),
523
- ),
524
- 'wp__comment_notify__roles' => array(
525
- 'type' => 'select',
526
- 'multiple' => true,
527
- 'parent' => 'wp__comment_notify',
528
- 'options_callback' => 'apbct_get_all_roles',
529
- 'options_callback_params' => array(true),
530
- 'class' => 'apbct_settings-field_wrapper--sub',
531
- ),
532
- 'wp__dashboard_widget__show' => array(
533
- 'type' => 'checkbox',
534
- 'title' => __('Show Dashboard Widget', 'cleantalk-spam-protect'),
535
- ),
536
- 'misc__complete_deactivation' => array(
537
- 'type' => 'checkbox',
538
- 'title' => __('Complete deactivation', 'cleantalk-spam-protect'),
539
- 'description' => __('Leave no trace in the system after deactivation.', 'cleantalk-spam-protect'),
540
- ),
541
-
542
- ),
543
- ),
544
- );
545
-
546
- return $fields;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  }
548
 
549
- function apbct_settings__set_fileds__network( $fields ){
550
- global $apbct;
551
- $additional_fields = array(
552
- 'wpms_settings' => array(
553
- 'default_params' => array(),
554
- 'description' => '',
555
- 'html_before' => '<br>'
556
- .'<span id="ct_adv_showhide">'
557
- .'<a href="#" class="apbct_color--gray" onclick="event.preventDefault(); apbct_show_hide_elem(\'apbct_settings__dwpms_settings\');">'
558
- .__('WordPress Multisite (WPMS) settings', 'cleantalk-spam-protect')
559
- .'</a>'
560
- .'</span>'
561
- .'<div id="apbct_settings__dwpms_settings" style="display: none;">',
562
- 'html_after' => '</div><br>',
563
- 'fields' => array(
564
- 'multisite__work_mode' => array(
565
- 'type' => 'select',
566
- 'options' => array(
567
- array( 'val' => 1, 'label' => __('Mutual Account, Individual Access Keys', 'cleantalk-spam-protect'), 'children_enable' => 1, ),
568
- array( 'val' => 2, 'label' => __('Mutual Account, Mutual Access Key', 'cleantalk-spam-protect'), 'children_enable' => 0, ),
569
- array( 'val' => 3, 'label' => __('Individual accounts, individual Access keys', 'cleantalk-spam-protect'), 'children_enable' => 0, ),
570
- ),
571
- 'title' => __( 'Wordpress Multisite Work Mode', 'cleantalk-spam-protect' ),
572
- 'description' => __( 'You can choose the work mode here for the child blogs and how they will operate with the CleanTalk Cloud. Press "?" for the detailed description.', 'cleantalk-spam-protect' ),
573
- 'long_description' => true,
574
- 'display' => APBCT_WPMS && is_main_site(),
575
- 'childrens' => array( 'multisite__hoster_api_key', 'multisite__white_label' ),
576
- 'network' => true,
577
- ),
578
- 'multisite__hoster_api_key' => array(
579
- 'type' => 'text',
580
- 'required' => true,
581
- 'title' => __( 'Hoster API key', 'cleantalk-spam-protect' ),
582
- 'description' => sprintf( __( 'Copy the key from your %sCleantalk Profile%s', 'cleantalk-spam-protect' ), '<a href="https://cleantalk.org/my/profile#api_keys" target="_blank">', '</a>' ),
583
- 'class' => 'apbct_settings-field_wrapper--sub',
584
- 'long_description' => true,
585
- 'display' => APBCT_WPMS && is_main_site(),
586
- 'disabled' => ! isset( $apbct->network_settings['multisite__work_mode'] ) || $apbct->network_settings['multisite__work_mode'] != 1,
587
- 'parent' => 'multisite__work_mode',
588
- 'network' => true,
589
- ),
590
- 'multisite__service_utilization' => array(
591
- 'type' => 'field',
592
- 'class' => 'apbct_settings-field_wrapper--sub',
593
- 'callback' => 'apbct_field_service_utilization',
594
- 'display' => APBCT_WPMS && is_main_site() && $apbct->network_settings['multisite__work_mode'] == 1,
595
- ),
596
- 'multisite__white_label' => array(
597
- 'type' => 'checkbox',
598
- 'title' => __('Enable White Label Mode', 'cleantalk-spam-protect'),
599
- 'description' => sprintf(__("Learn more information %shere%s.", 'cleantalk-spam-protect'), '<a target="_blank" href="https://cleantalk.org/ru/help/hosting-white-label">', '</a>'),
600
- 'childrens' => array( 'multisite__white_label__plugin_name' ),
601
- 'disabled' => defined('CLEANTALK_ACCESS_KEY') || ! isset( $apbct->network_settings['multisite__work_mode'] ) || $apbct->network_settings['multisite__work_mode'] != 1,
602
- 'parent' => 'multisite__work_mode',
603
- 'class' => 'apbct_settings-field_wrapper--sub',
604
- 'network' => true,
605
- ),
606
- 'multisite__white_label__plugin_name' => array(
607
- 'title' => __('Plugin name', 'cleantalk-spam-protect'),
608
- 'description' => sprintf(__("Specify plugin name. Leave empty for deafult %sAntispam by Cleantalk%s", 'cleantalk-spam-protect'), '<b>', '</b>'),
609
- 'type' => 'text',
610
- 'parent' => 'multisite__white_label',
611
- 'class' => 'apbct_settings-field_wrapper--sub',
612
- 'network' => true,
613
- ),
614
- 'multisite__allow_custom_settings' => array(
615
- 'type' => 'checkbox',
616
- 'title' => __('Allow users to manage plugin settings', 'cleantalk-spam-protect'),
617
- 'description' => __('Allow to change settings on child sites.', 'cleantalk-spam-protect'),
618
- 'display' => APBCT_WPMS && is_main_site(),
619
- 'network' => true,
620
- ),
621
- 'multisite__use_settings_template' => array(
622
- 'type' => 'checkbox',
623
- 'title' => __('Use settings template', 'cleantalk-spam-protect'),
624
- 'description' => __("Use the current settings template for child sites.", 'cleantalk-spam-protect'),
625
- 'childrens' => array( 'multisite__use_settings_template_apply_for_new', 'multisite__use_settings_template_apply_for_current'),
626
- 'network' => true,
627
- ),
628
- 'multisite__use_settings_template_apply_for_new' => array(
629
- 'type' => 'checkbox',
630
- 'title' => __('Apply for newly added sites.', 'cleantalk-spam-protect'),
631
- 'description' => __("The newly added site will have the same preset settings template.", 'cleantalk-spam-protect'),
632
- 'parent' => 'multisite__use_settings_template',
633
- 'class' => 'apbct_settings-field_wrapper--sub',
634
- 'network' => true,
635
- ),
636
- 'multisite__use_settings_template_apply_for_current' => array(
637
- 'type' => 'checkbox',
638
- 'title' => __('Apply for current sites.', 'cleantalk-spam-protect'),
639
- 'description' => __("Apply current settings template for selected sites.", 'cleantalk-spam-protect'),
640
- 'parent' => 'multisite__use_settings_template',
641
- 'childrens' => array( 'multisite__use_settings_template_apply_for_current_list_sites'),
642
- 'class' => 'apbct_settings-field_wrapper--sub',
643
- 'network' => true,
644
- ),
645
- 'multisite__use_settings_template_apply_for_current_list_sites' => array(
646
- 'type' => 'select',
647
- 'multiple' => true,
648
- 'options_callback' => 'apbct_get_all_child_domains',
649
- 'options_callback_params' => array(true),
650
- 'class' => 'apbct_settings-field_wrapper--sub',
651
- 'parent' => 'multisite__use_settings_template_apply_for_current',
652
- 'description' => __('Sites to apply settings. Hold CTRL to select multiple sites.', 'cleantalk-spam-protect'),
653
- 'network' => true,
654
- ),
655
- )
656
- )
657
- );
658
-
659
- $fields = array_merge_recursive($fields, $additional_fields);
660
-
661
- return $fields;
662
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
663
  }
664
 
665
- function apbct_settings__add_groups_and_fields( $fields ){
666
-
667
- global $apbct;
668
-
669
- $apbct->settings_fields_in_groups = $fields;
670
-
671
- $field_default_params = array(
672
- 'callback' => 'apbct_settings__field__draw',
673
- 'type' => 'radio',
674
- 'options' => array(
675
- array('val' => 1, 'label' => __('On', 'cleantalk-spam-protect'), 'childrens_enable' => 1, ),
676
- array('val' => 0, 'label' => __('Off', 'cleantalk-spam-protect'), 'childrens_enable' => 0, ),
677
- ),
678
- 'def_class' => 'apbct_settings-field_wrapper',
679
- 'class' => '',
680
- 'parent' => '',
681
- 'childrens' => array(),
682
- 'hide' => array(),
683
- // 'title' => 'Default title',
684
- // 'description' => 'Default description',
685
- 'display' => true, // Draw settings or not
686
- 'reverse_trigger' => false, // How to allow child settings. Childrens are opened when the parent triggered "ON". This is overrides by this option
687
- 'multiple' => false,
688
- 'description' => '',
689
- 'network' => false,
690
- 'disabled' => false,
691
- 'required' => false,
692
- );
693
-
694
- foreach($apbct->settings_fields_in_groups as $group_name => $group){
695
-
696
- add_settings_section('apbct_section__'.$group_name, '', '', 'cleantalk-spam-protect');
697
-
698
- foreach($group['fields'] as $field_name => $field){
699
-
700
- // Normalize $field['options'] from callback function to this type array( array( 'val' => 1, 'label' => __('On'), ), )
701
- if(!empty($field['options_callback'])){
702
- $options = call_user_func_array($field['options_callback'], !empty($field['options_callback_params']) ? $field['options_callback_params'] : array());
703
- foreach ($options as &$option){
704
- if( is_array( $option ) ) {
705
- $option = array(
706
- 'val' => isset($option['val']) ? $option['val'] : current( $option ),
707
- 'label' => isset($option['label']) ? $option['label'] : end( $option )
708
- );
709
- } else {
710
- $option = array('val' => $option, 'label' => $option);
711
- }
712
- } unset($option);
713
- $field['options'] = $options;
714
- }
715
-
716
- $params = !empty($group['default_params'])
717
- ? array_merge($group['default_params'], $field)
718
- : array_merge($field_default_params, $field);
719
-
720
- $params['name'] = $field_name;
721
-
722
- if(!$params['display'])
723
- continue;
724
-
725
- add_settings_field(
726
- 'apbct_field__'.$field_name,
727
- '',
728
- $params['callback'],
729
- 'cleantalk',
730
- 'apbct_section__'.$group_name,
731
- $params
732
- );
733
-
734
- }
735
- }
 
 
 
 
736
  }
737
 
738
  /**
739
  * Admin callback function - Displays plugin options page
740
  */
741
- function apbct_settings__display() {
742
-
743
- global $apbct;
744
-
745
- // Title
746
- echo '<h2 class="apbct_settings-title">'.__($apbct->plugin_name, 'cleantalk-spam-protect').'</h2>';
747
-
748
- // Subtitle for IP license
749
- if($apbct->moderate_ip)
750
- echo '<h4 class="apbct_settings-subtitle apbct_color--gray">'. __('Hosting AntiSpam', 'cleantalk-spam-protect').'</h4>';
751
-
752
- echo '<form action="options.php" method="post">';
753
-
754
- apbct_settings__error__output();
755
-
756
- // Top info
757
- if(!$apbct->white_label){
758
- echo '<div style="float: right; padding: 15px 15px 5px 15px; font-size: 13px; position: relative; background: #f1f1f1;">';
759
-
760
- echo __('CleanTalk\'s tech support:', 'cleantalk-spam-protect')
761
- .'&nbsp;'
762
- .'<a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">Wordpress.org</a>.'
763
- // .' <a href="https://community.cleantalk.org/viewforum.php?f=25" target="_blank">'.__("Tech forum", 'cleantalk-spam-protect').'</a>'
764
- // .($user_token ? ", <a href='https://cleantalk.org/my/support?user_token=$user_token&cp_mode=antispam' target='_blank'>".__("Service support ", 'cleantalk-spam-protect').'</a>' : '').
765
- .'<br>';
766
- echo __('Plugin Homepage at', 'cleantalk-spam-protect').' <a href="https://cleantalk.org" target="_blank">cleantalk.org</a>.<br/>';
767
- echo '<span id="apbct_gdpr_open_modal" style="text-decoration: underline;">'.__('GDPR compliance', 'cleantalk-spam-protect').'</span><br/>';
768
- echo __('Use s@cleantalk.org to test plugin in any WordPress form.', 'cleantalk-spam-protect').'<br>';
769
- echo __('CleanTalk is registered Trademark. All rights reserved.', 'cleantalk-spam-protect').'<br/>';
770
- if($apbct->key_is_ok)
771
- 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 />';
772
- apbct_admin__badge__get_premium();
773
- echo '<div id="gdpr_dialog" style="display: none; padding: 7px;">';
774
- apbct_settings_show_gdpr_text('print');
775
- echo '</div>';
776
- echo '</div>';
777
- }
778
-
779
- // Output spam count
780
- if($apbct->key_is_ok && apbct_api_key__is_correct()){
781
- if( $apbct->spam_count > 0 ){
782
- echo '<div class="apbct_settings-subtitle" style="top: 0; margin-bottom: 10px; width: 200px;">'
783
- . '<br>'
784
- . '<span>'
785
- . sprintf(
786
- __( '%s has blocked <b>%s</b> spam.', 'cleantalk-spam-protect' ),
787
- $apbct->plugin_name,
788
- number_format( $apbct->spam_count, 0, ',', ' ' )
789
- )
790
- . '</span>'
791
- . '<br>'
792
- . '<br>'
793
- . '</div>';
794
- }
795
- }
796
-
797
-
798
- // Output spam count
799
- if( $apbct->key_is_ok && apbct_api_key__is_correct() ){
800
- if( $apbct->network_settings['multisite__work_mode'] != 2 || is_main_site() ){
801
-
802
- // CP button
803
- echo '<a class="cleantalk_link cleantalk_link-manual" target="__blank" href="https://cleantalk.org/my?user_token='.$apbct->user_token.'&cp_mode=antispam">'
804
- .__('Click here to get anti-spam statistics', 'cleantalk-spam-protect')
805
- .'</a>';
806
- echo '&nbsp;&nbsp;';
807
-
808
- }
809
- }
810
-
811
- if( apbct_api_key__is_correct() && ( $apbct->network_settings['multisite__work_mode'] != 2 || is_main_site() ) ){
812
- // Sync button
813
- echo '<button type="button" class="cleantalk_link cleantalk_link-auto" id="apbct_button__sync" title="Synchronizing account status, SpamFireWall database, all kind of journals.">'
814
- . '<i class="icon-upload-cloud"></i>&nbsp;&nbsp;'
815
- . __( 'Synchronize with Cloud', 'cleantalk-spam-protect' )
816
- . '<img style="margin-left: 10px;" class="apbct_preloader_button" src="' . APBCT_URL_PATH . '/inc/images/preloader2.gif" />'
817
- . '<img style="margin-left: 10px;" class="apbct_success --hide" src="' . APBCT_URL_PATH . '/inc/images/yes.png" />'
818
- . '</button>';
819
- echo '&nbsp;&nbsp;';
820
- }
821
-
822
- // Output spam count
823
- if($apbct->key_is_ok && apbct_api_key__is_correct()){
824
- if( $apbct->network_settings['multisite__work_mode'] != 2 || is_main_site() ){
825
-
826
- // Support button
827
- echo '<a class="cleantalk_link cleantalk_link-auto" target="__blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">'.__('Support', 'cleantalk-spam-protect').'</a>';
828
- echo '&nbsp;&nbsp;';
829
- echo '<br>'
830
- . '<br>';
831
- }
832
- }
833
-
834
- settings_fields('cleantalk_settings');
835
- do_settings_fields('cleantalk', 'cleantalk_section_settings_main');
836
-
837
- foreach($apbct->settings_fields_in_groups as $group_name => $group){
838
-
839
- echo !empty($group['html_before']) ? $group['html_before'] : '';
840
- echo !empty($group['title']) ? '<h3 style="margin-left: 220px;">'.$group['title'].'</h3>' : '';
841
-
842
- do_settings_fields('cleantalk', 'apbct_section__'.$group_name);
843
-
844
- echo !empty($group['html_after']) ? $group['html_after'] : '';
845
-
846
- }
847
-
848
- echo '<br>';
849
- echo '<button name="submit" class="cleantalk_link cleantalk_link-manual" value="save_changes">'.__('Save Changes').'</button>';
850
-
851
- echo "</form>";
852
-
853
- if(!$apbct->white_label){
854
- // Translate banner for non EN locale
855
- if(substr(get_locale(), 0, 2) != 'en'){
856
- require_once(CLEANTALK_PLUGIN_DIR.'templates/translate_banner.php');
857
- printf($ct_translate_banner_template, substr(get_locale(), 0, 2));
858
- }
859
- }
 
 
 
 
 
 
860
  }
861
 
862
- function apbct_settings__display__network(){
863
- // If it's network admin dashboard
864
- if(is_network_admin()){
865
- $site_url = get_site_option('siteurl');
866
- $site_url = preg_match( '/\/$/', $site_url ) ? $site_url : $site_url . '/';
867
- $link = $site_url . 'wp-admin/options-general.php?page=cleantalk';
868
- printf("<h2>" . __("Please, enter the %splugin settings%s in main site dashboard.", 'cleantalk-spam-protect') . "</h2>", "<a href='$link'>", "</a>");
869
- return;
870
- }
 
 
 
 
 
 
 
 
 
871
  }
872
 
873
- function apbct_settings__error__output($return = false){
874
-
875
- global $apbct;
876
-
877
- // If have error message output error block.
878
-
879
- $out = '';
880
-
881
- if(!empty($apbct->errors) && !defined('CLEANTALK_ACCESS_KEY')){
882
-
883
- $errors = $apbct->errors;
884
-
885
- $error_texts = array(
886
- // Misc
887
- 'key_invalid' => __('Error occurred while API key validating. Error: ', 'cleantalk-spam-protect'),
888
- 'key_get' => __('Error occurred while automatically gettings access key. Error: ', 'cleantalk-spam-protect'),
889
- 'sfw_send_logs' => __('Error occurred while sending SpamFireWall logs. Error: ', 'cleantalk-spam-protect'),
890
- 'sfw_update' => __('Error occurred while updating SpamFireWall local base. Error: ', 'cleantalk-spam-protect'),
891
- 'ua_update' => __('Error occurred while updating User-Agents local base. Error: ', 'cleantalk-spam-protect'),
892
- 'account_check' => __('Error occurred while checking account status. Error: ', 'cleantalk-spam-protect'),
893
- 'api' => __('Error occurred while excuting API call. Error: ', 'cleantalk-spam-protect'),
894
-
895
- // Validating settings
896
- 'settings_validate' => 'Validate Settings',
897
- 'exclusions_urls' => 'URL Exclusions',
898
- 'exclusions_fields' => 'Field Exclusions',
899
-
900
- // Unknown
901
- 'unknown' => __('Unknown error. Error: ', 'cleantalk-spam-protect'),
902
- );
903
-
904
- $errors_out = array();
905
-
906
- foreach($errors as $type => $error){
907
-
908
- if(!empty($error)){
909
-
910
- if(is_array(current($error))){
911
-
912
- foreach($error as $sub_type => $sub_error){
913
-
914
- if( isset($sub_error['error']) && strpos( $sub_error['error'], 'SFW_IS_DISABLED' ) !== false ){
 
 
 
 
 
 
 
 
 
 
915
  continue;
916
  }
917
-
918
- $errors_out[$sub_type] = '';
919
- if(isset($sub_error['error_time']))
920
- $errors_out[$sub_type] .= date('Y-m-d H:i:s', $sub_error['error_time']) . ': ';
921
- $errors_out[$sub_type] .= (isset($error_texts[$type]) ? $error_texts[$type] : ucfirst($type)) . ': ';
922
- $errors_out[$sub_type] .= (isset($error_texts[$sub_type]) ? $error_texts[$sub_type] : $error_texts['unknown']) . ' ' . $sub_error['error'];
923
- }
924
- continue;
925
- }
926
-
927
- if (
928
- ! empty($type) &&
 
929
  $apbct->white_label &&
930
- !is_main_site() &&
931
- in_array( $type, array( 'sfw_update', 'key_invalid', 'account_check') )
932
- ){
933
- continue;
934
- }
935
-
936
- if( isset($error['error']) && strpos( $error['error'], 'SFW_IS_DISABLED' ) !== false ){
937
- continue;
938
  }
939
-
940
- $errors_out[$type] = '';
941
-
942
- if( isset( $error['error_time'] ) )
943
- $errors_out[$type] .= date('Y-m-d H:i:s', $error['error_time']) . ': ';
944
-
945
- $errors_out[$type] .= (isset($error_texts[$type]) ? $error_texts[$type] : $error_texts['unknown']) . ' ' . (isset($error['error']) ? $error['error'] : '');
946
-
947
- }
948
- }
949
-
950
- if(!empty($errors_out)){
951
- $out .= '<div id="apbctTopWarning" class="error" style="position: relative;">'
952
- .'<h3 style="display: inline-block;">'.__('Errors:', 'cleantalk-spam-protect').'</h3>';
953
- foreach($errors_out as $value){
954
- $out .= '<h4>'.$value.'</h4>';
955
- }
956
- $out .= !$apbct->white_label
957
- ? '<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>'
958
- : '';
959
- $out .= '</div>';
960
- }
961
- }
962
-
963
- if($return) return $out; else echo $out;
 
 
 
 
 
 
 
 
 
 
 
964
  }
965
 
966
- function apbct_settings__field__debug(){
967
-
968
- global $apbct;
969
-
970
- if($apbct->debug){
971
-
972
- echo '<hr /><h2>Debug:</h2>';
973
- echo '<h4>Constants:</h4>';
974
- echo 'CLEANTALK_AJAX_USE_BUFFER '. (defined('CLEANTALK_AJAX_USE_BUFFER') ? (CLEANTALK_AJAX_USE_BUFFER ? 'true' : 'flase') : 'NOT_DEFINED')."<br>";
975
- echo 'CLEANTALK_AJAX_USE_FOOTER_HEADER '. (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') ? (CLEANTALK_AJAX_USE_FOOTER_HEADER ? 'true' : 'flase') : 'NOT_DEFINED')."<br>";
976
- echo 'CLEANTALK_ACCESS_KEY '. (defined('CLEANTALK_ACCESS_KEY') ? (CLEANTALK_ACCESS_KEY ? CLEANTALK_ACCESS_KEY : 'flase') : 'NOT_DEFINED')."<br>";
977
- echo 'CLEANTALK_CHECK_COMMENTS_NUMBER '. (defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? (CLEANTALK_CHECK_COMMENTS_NUMBER ? CLEANTALK_CHECK_COMMENTS_NUMBER : 0) : 'NOT_DEFINED')."<br>";
978
- echo 'CLEANTALK_CHECK_MESSAGES_NUMBER '. (defined('CLEANTALK_CHECK_MESSAGES_NUMBER') ? (CLEANTALK_CHECK_MESSAGES_NUMBER ? CLEANTALK_CHECK_MESSAGES_NUMBER : 0) : 'NOT_DEFINED')."<br>";
979
- echo 'CLEANTALK_PLUGIN_DIR '. (defined('CLEANTALK_PLUGIN_DIR') ? (CLEANTALK_PLUGIN_DIR ? CLEANTALK_PLUGIN_DIR : 'flase') : 'NOT_DEFINED')."<br>";
980
- echo 'WP_ALLOW_MULTISITE '. (defined('WP_ALLOW_MULTISITE') ? (WP_ALLOW_MULTISITE ? 'true' : 'flase') : 'NOT_DEFINED');
981
-
982
- echo '<h4><button type="submit" name="apbct_debug__check_connection" value="1">Check connection to API servers</button></h4>';
983
- echo "<h4>Debug log: <button type='submit' value='debug_drop' name='submit' style='font-size: 11px; padding: 1px;'>Drop debug data</button></h4>";
984
- echo "<div style='height: 500px; width: 80%; overflow: auto;'>";
985
-
986
- $output = print_r($apbct->debug, true);
987
- $output = str_replace("\n", "<br>", $output);
988
- $output = preg_replace("/[^\S]{4}/", "&nbsp;&nbsp;&nbsp;&nbsp;", $output);
989
- echo "$output";
990
-
991
- echo "</div>";
992
-
993
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
994
  }
995
 
996
- function apbct_settings__field__state(){
997
-
998
- global $apbct;
999
-
1000
- $path_to_img = plugin_dir_url(__FILE__) . "images/";
1001
-
1002
- $img = $path_to_img."yes.png";
1003
- $img_no = $path_to_img."no.png";
1004
- $img_no_gray = $path_to_img."no_gray.png";
1005
- $color="black";
1006
-
1007
- if( ! $apbct->key_is_ok ){
1008
- $img=$path_to_img."no.png";
1009
- $img_no=$path_to_img."no.png";
1010
- $color="black";
1011
- }
1012
-
1013
- if(!apbct_api_key__is_correct($apbct->api_key)){
1014
- $img = $path_to_img."yes_gray.png";
1015
- $img_no = $path_to_img."no_gray.png";
1016
- $color="gray";
1017
- }
1018
-
1019
- if($apbct->moderate_ip){
1020
- $img = $path_to_img."yes.png";
1021
- $img_no = $path_to_img."no.png";
1022
- $color="black";
1023
- }
1024
-
1025
- if( $apbct->moderate == 0 ){
1026
- $img = $path_to_img."no.png";
1027
- $img_no = $path_to_img."no.png";
1028
- $color="black";
1029
- }
1030
-
1031
- print '<div class="apbct_settings-field_wrapper" style="color:'.$color.'">';
1032
-
1033
- print '<h2>'.__('Protection is active', 'cleantalk-spam-protect').'</h2>';
1034
-
1035
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['forms__registrations_test'] == 1 ? $img : $img_no).'"/>'.__('Registration forms', 'cleantalk-spam-protect');
1036
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['forms__comments_test'] == 1 ? $img : $img_no).'"/>'.__('Comments forms', 'cleantalk-spam-protect');
1037
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['forms__contact_forms_test'] == 1 ? $img : $img_no).'"/>'.__('Contact forms', 'cleantalk-spam-protect');
1038
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['forms__general_contact_forms_test'] == 1 ? $img : $img_no).'"/>'.__('Custom contact forms', 'cleantalk-spam-protect');
1039
- if(!$apbct->white_label || is_main_site())
1040
- echo '<img class="apbct_status_icon" src="'.($apbct->data['moderate'] == 1 ? $img : $img_no).'"/>'
1041
- .'<a style="color: black" href="https://blog.cleantalk.org/real-time-email-address-existence-validation/">'.__('Validate email for existence', 'cleantalk-spam-protect').'</a>';
1042
- // Autoupdate status
1043
- if($apbct->notice_auto_update && (!$apbct->white_label || is_main_site())){
1044
- 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')
1045
- .' <sup><a href="https://cleantalk.org/help/cleantalk-auto-update" target="_blank">?</a></sup>';
1046
- }
1047
-
1048
- // WooCommerce
1049
- if(class_exists('WooCommerce'))
1050
- echo '<img class="apbct_status_icon" src="'.($apbct->settings['forms__wc_checkout_test'] == 1 ? $img : $img_no).'"/>'.__('WooCommerce checkout form', 'cleantalk-spam-protect');
1051
- if($apbct->moderate_ip)
1052
- print "<br /><br />The anti-spam service is paid by your hosting provider. License #".$apbct->data['ip_license'].".<br />";
1053
-
1054
- print "</div>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1055
  }
1056
 
1057
  /**
1058
  * Admin callback function - Displays inputs of 'apikey' plugin parameter
1059
  */
1060
- function apbct_settings__field__apikey(){
1061
-
1062
- global $apbct;
1063
-
1064
- echo '<div id="cleantalk_apikey_wrapper" class="apbct_settings-field_wrapper">';
1065
-
1066
- // Using key from Main site, or from CLEANTALK_ACCESS_KEY constant
1067
- if(APBCT_WPMS && !is_main_site() && (!$apbct->allow_custom_key || defined('CLEANTALK_ACCESS_KEY'))){
1068
- _e('<h3>Access key is provided by network administrator</h3>', 'cleantalk-spam-protect');
1069
- return;
1070
- }
1071
-
1072
- echo '<label class="apbct_settings__label" for="cleantalk_apkey">' . __('Access key', 'cleantalk-spam-protect') . '</label>';
1073
-
1074
- echo '<input
 
 
 
 
1075
  id="apbct_setting_apikey"
1076
  class="apbct_setting_text apbct_setting---apikey"
1077
  type="text"
1078
  name="cleantalk_settings[apikey]"
1079
  value="'
1080
- . ($apbct->key_is_ok
1081
- ? str_repeat('*', strlen($apbct->api_key))
1082
- : $apbct->api_key
1083
- )
1084
- . '"
1085
  key="' . $apbct->api_key . '"
1086
  size="20"
1087
  placeholder="' . __('Enter the key', 'cleantalk-spam-protect') . '"'
1088
- . ' />';
1089
-
1090
- // Show account name associated with key
1091
- if(!empty($apbct->data['account_name_ob'])){
1092
- echo '<div class="apbct_display--none">'
1093
- . sprintf( __('Account at cleantalk.org is %s.', 'cleantalk-spam-protect'),
1094
- '<b>'.$apbct->data['account_name_ob'].'</b>'
1095
- )
1096
- . '</div>';
1097
- };
1098
-
1099
- // Show key button
1100
- if((apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok)){
1101
- echo '<a id="apbct_showApiKey" class="ct_support_link" style="display: block" href="#">'
1102
- . __('Show the access key', 'cleantalk-spam-protect')
1103
- . '</a>';
1104
-
1105
- // "Auto Get Key" buttons. License agreement
1106
- }else{
1107
-
1108
- echo '<br /><br />';
1109
-
1110
- // Auto get key
1111
- if(!$apbct->ip_license){
1112
- echo '<button class="cleantalk_link cleantalk_link-manual apbct_setting---get_key_auto" id="apbct_button__get_key_auto" name="submit" type="button" value="get_key_auto">'
1113
- .__('Get Access Key Automatically', 'cleantalk-spam-protect')
1114
- . '<img style="margin-left: 10px;" class="apbct_preloader_button" src="' . APBCT_URL_PATH . '/inc/images/preloader2.gif" />'
1115
- . '<img style="margin-left: 10px;" class="apbct_success --hide" src="' . APBCT_URL_PATH . '/inc/images/yes.png" />'
1116
- .'</button>';
1117
- echo '<input type="hidden" id="ct_admin_timezone" name="ct_admin_timezone" value="null" />';
1118
- echo '<br />';
1119
- echo '<br />';
1120
- }
1121
-
1122
- // Warnings and GDPR
1123
- 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'),
1124
- ct_get_admin_email(),
1125
- '<a class="apbct_color--gray" target="__blank" href="'
1126
- . sprintf( 'https://cleantalk.org/register?platform=wordpress&email=%s&website=%s',
1127
- urlencode(ct_get_admin_email()),
1128
- urlencode(get_bloginfo('url'))
1129
- )
1130
- . '">',
1131
- '</a>'
1132
- );
1133
-
1134
- // License agreement
1135
- if(!$apbct->ip_license){
1136
- echo '<div>';
1137
- echo '<input checked type="checkbox" id="license_agreed" onclick="apbctSettingsDependencies(\'apbct_setting---get_key_auto\');"/>';
1138
- echo '<label for="spbc_license_agreed">';
1139
- printf( __('I accept %sLicense Agreement%s.', 'cleantalk-spam-protect'),
1140
- '<a class = "apbct_color--gray" href="https://cleantalk.org/publicoffer" target="_blank">',
1141
- '</a>'
1142
- );
1143
- echo "</label>";
1144
- echo '</div>';
1145
- }
1146
- }
1147
-
1148
- echo '</div>';
1149
- }
1150
-
1151
- function apbct_field_service_utilization(){
1152
-
1153
- global $apbct;
1154
-
1155
- echo '<div class="apbct_wrapper_field">';
1156
-
1157
- if( $apbct->services_count && $apbct->services_max && $apbct->services_utilization ){
1158
 
1159
- echo sprintf(
1160
- __( 'Hoster account utilization: %s%% ( %s of %s websites ).', 'cleantalk-spam-protect' ),
1161
- $apbct->services_utilization * 100,
1162
- $apbct->services_count,
1163
- $apbct->services_max
1164
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1165
 
1166
- // Link to the dashboard, so user could extend your subscription for more sites
1167
- if( $apbct->services_utilization * 100 >= 90 ){
1168
- echo '&nbsp';
1169
- echo sprintf(
1170
- __( 'You could extend your subscription %shere%s.', 'cleantalk-spam-protect' ),
1171
- '<a href="' . $apbct->dashboard_link . '" target="_blank">',
1172
- '</a>'
1173
- );
1174
- }
1175
 
1176
- }else{
1177
- _e( 'Enter the Hoster API key and synchronize with cloud to find out your hoster account utilization.', 'cleantalk-spam-protect' );
1178
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1179
 
1180
- echo '</div>';
1181
  }
1182
 
1183
- function apbct_settings__field__action_buttons(){
1184
-
1185
- global $apbct;
1186
-
1187
- $links = apply_filters(
1188
- 'apbct_settings_action_buttons',
1189
- array(
1190
- '<a href="edit-comments.php?page=ct_check_spam" class="ct_support_link">' . __('Check comments for spam', 'cleantalk-spam-protect') . '</a>',
1191
- '<a href="users.php?page=ct_check_users" class="ct_support_link">' . __('Check users for spam', 'cleantalk-spam-protect') . '</a>',
1192
- '<a href="#" class="ct_support_link" onclick="apbct_show_hide_elem(\'apbct_statistics\')">' . __('Statistics & Reports', 'cleantalk-spam-protect') . '</a>',
1193
- )
1194
- );
1195
-
1196
- echo '<div class="apbct_settings-field_wrapper">';
1197
-
1198
- if( apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok ){
1199
- echo '<div>';
1200
- foreach( $links as $link ) {
1201
- echo $link . '&nbsp;&nbsp;&nbsp;&nbsp;';
1202
- }
1203
- echo '</div>';
1204
- }
1205
-
1206
- echo '</div>';
 
 
 
 
 
 
 
 
 
1207
  }
1208
 
1209
- function apbct_settings__field__statistics() {
1210
-
1211
- global $apbct;
1212
-
1213
- echo '<div id="apbct_statistics" class="apbct_settings-field_wrapper" style="display: none;">';
1214
-
1215
- // Last request
1216
- printf(
1217
- __('Last spam check request to %s server was at %s.', 'cleantalk-spam-protect'),
1218
- $apbct->stats['last_request']['server'] ? $apbct->stats['last_request']['server'] : __('unknown', 'cleantalk-spam-protect'),
1219
- $apbct->stats['last_request']['time'] ? date('M d Y H:i:s', $apbct->stats['last_request']['time']) : __('unknown', 'cleantalk-spam-protect')
1220
- );
1221
- echo '<br>';
1222
-
1223
- // Avarage time request
1224
- printf(
1225
- __('Average request time for past 7 days: %s seconds.', 'cleantalk-spam-protect'),
1226
- $apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time']
1227
- ? round($apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time'], 3)
1228
- : __('unknown', 'cleantalk-spam-protect')
1229
- );
1230
- echo '<br>';
1231
-
1232
- // SFW last die
1233
- printf(
1234
- __('Last time SpamFireWall was triggered for %s IP at %s', 'cleantalk-spam-protect'),
1235
- $apbct->stats['last_sfw_block']['ip'] ? $apbct->stats['last_sfw_block']['ip'] : __('unknown', 'cleantalk-spam-protect'),
1236
- $apbct->stats['last_sfw_block']['time'] ? date('M d Y H:i:s', $apbct->stats['last_sfw_block']['time']) : __('unknown', 'cleantalk-spam-protect')
1237
- );
1238
- echo '<br>';
1239
-
1240
- // SFW last update
1241
- printf(
1242
- __('SpamFireWall was updated %s. Now contains %s entries.', 'cleantalk-spam-protect'),
1243
- $apbct->stats['sfw']['last_update_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_update_time']) : __('unknown', 'cleantalk-spam-protect'),
1244
- $apbct->stats['sfw']['entries']
1245
- );
1246
- echo $apbct->fw_stats['firewall_updating_id'] ? ' ' . __('Under updating now:', 'cleantalk-spam-protect') . ' ' . $apbct->fw_stats['firewall_update_percent'] . '%' : '';
1247
- echo '<br>';
1248
-
1249
- // SFW last sent logs
1250
- printf(
1251
- __('SpamFireWall sent %s events at %s.', 'cleantalk-spam-protect'),
1252
- $apbct->stats['sfw']['last_send_amount'] ? $apbct->stats['sfw']['last_send_amount'] : __('unknown', 'cleantalk-spam-protect'),
1253
- $apbct->stats['sfw']['last_send_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_send_time']) : __('unknown', 'cleantalk-spam-protect')
1254
- );
1255
- echo '<br>';
1256
-
1257
- // Connection reports
1258
- if ($apbct->connection_reports){
1259
-
1260
- if ($apbct->connection_reports['negative'] == 0){
1261
- _e('There are no failed connections to server.', 'cleantalk-spam-protect');
1262
- }else{
1263
- echo "<table id='negative_reports_table''>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1264
  <tr>
1265
  <td>#</td>
1266
  <td><b>Date</b></td>
@@ -1268,57 +1650,62 @@ function apbct_settings__field__statistics() {
1268
  <td><b>Report</b></td>
1269
  <td><b>Server IP</b></td>
1270
  </tr>";
1271
- foreach($apbct->connection_reports['negative_report'] as $key => $report){
1272
- echo '<tr>'
1273
- . '<td>'.($key+1).'.</td>'
1274
- . '<td>'.$report['date'].'</td>'
1275
- . '<td>'.$report['page_url'].'</td>'
1276
- . '<td>'.$report['lib_report'].'</td>'
1277
- . '<td>'.$report['work_url'].'</td>'
1278
- . '</tr>';
1279
- }
1280
- echo "</table>";
1281
- echo '<br/>';
1282
- echo '<button'
1283
- . ' name="submit"'
1284
- . ' class="cleantalk_link cleantalk_link-manual"'
1285
- . ' value="ct_send_connection_report"'
1286
- . (!$apbct->settings['misc__send_connection_reports'] ? ' disabled="disabled"' : '')
1287
- . '>'
1288
- .__('Send report', 'cleantalk-spam-protect')
1289
- .'</button>';
1290
- if (!$apbct->settings['misc__send_connection_reports']){
1291
- echo '<br><br>';
1292
- _e('Please, enable "Send connection reports" setting to be able to send reports', 'cleantalk-spam-protect');
1293
- }
1294
- }
1295
-
1296
- }
 
 
1297
 
1298
  echo '<br/>';
1299
- echo 'Plugin version: ' . APBCT_VERSION;
1300
-
1301
- echo '</div>';
1302
 
 
1303
  }
1304
- function apbct_get_all_child_domains($except_main_site = false) {
1305
- global $wpdb;
1306
- $blogs = array();
1307
- $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM '. $wpdb->blogs, OBJECT_K);
1308
-
1309
- if ($except_main_site) {
1310
- foreach ($wp_blogs as $blog) {
1311
- if ($blog->blog_id != $blog->site_id){
1312
- $blog_details = get_blog_details( array( 'blog_id' => $blog->blog_id ) );
1313
- $blogs[] = array(
1314
- 'val' => $blog_details->id,
1315
- 'label' => '#' . $blog_details->id . ' ' . $blog_details->blogname
1316
- );
1317
- }
1318
- }
1319
- }
1320
- return $blogs;
 
 
 
1321
  }
 
1322
  /**
1323
  * Get all current Wordpress roles, could except 'subscriber' role
1324
  *
@@ -1326,594 +1713,622 @@ function apbct_get_all_child_domains($except_main_site = false) {
1326
  *
1327
  * @return array
1328
  */
1329
- function apbct_get_all_roles($except_subscriber = false) {
1330
-
1331
- $wp_roles = new WP_Roles();
1332
- $roles = $wp_roles->get_names();
1333
-
1334
- if($except_subscriber) {
1335
- $key = array_search( 'Subscriber', $roles );
1336
- if ( $key !== false ) {
1337
- unset( $roles[ $key ] );
1338
- }
1339
- }
1340
-
1341
- return $roles;
1342
  }
1343
 
1344
- function apbct_settings__field__draw($params = array()){
1345
-
1346
- global $apbct;
1347
-
1348
- $value = $params['network'] ? $apbct->network_settings[$params['name']] : $apbct->settings[$params['name']];
1349
- $value_parent = $params['parent']
1350
- ? ($params['network'] ? $apbct->network_settings[$params['parent']] : $apbct->settings[$params['parent']])
1351
- : false;
1352
-
1353
- // Is element is disabled
1354
- $disabled = $params['parent'] && !$value_parent ? ' disabled="disabled"' : ''; // Strait
1355
- $disabled = $params['parent'] && $params['reverse_trigger'] && !$value_parent ? '' : $disabled; // Reverse logic
1356
- $disabled = $params['disabled'] ? ' disabled="disabled"' : $disabled; // Direct disable from params
1357
- $disabled = ! is_main_site() && $apbct->network_settings && ! $apbct->network_settings['multisite__allow_custom_settings'] ? ' disabled="disabled"' : $disabled; // Disabled by super admin on sub-sites
1358
-
1359
- $childrens = $params['childrens'] ? 'apbct_setting---' . implode(",apbct_setting---",$params['childrens']) : '';
1360
- $hide = $params['hide'] ? implode(",",$params['hide']) : '';
1361
-
1362
- echo '<div class="'.$params['def_class'].(isset($params['class']) ? ' '.$params['class'] : '').'">';
1363
-
1364
- switch($params['type']){
1365
-
1366
- // Checkbox type
1367
- case 'checkbox':
1368
- echo '<input
1369
  type="checkbox"
1370
- name="cleantalk_settings['.$params['name'].']"
1371
- id="apbct_setting_'.$params['name'].'"
1372
  value="1" '
1373
- ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1374
- .($value == '1' ? ' checked' : '')
1375
- .$disabled
1376
- .($params['required'] ? ' required="required"' : '')
1377
- .($params['childrens'] ? ' apbct_children="'. $childrens .'"' : '')
1378
- .' onchange="'
1379
- . ($params['childrens'] ? ' apbctSettingsDependencies(\''. $childrens .'\');' : '')
1380
- . ($params['hide'] ? ' apbct_show_hide_elem(\''. $hide . '\');' : '')
1381
- . '"'
1382
- .' />'
1383
- .'<label for="apbct_setting_'.$params['name'].'" class="apbct_setting-field_title--'.$params['type'].'">'
1384
- .$params['title']
1385
- .'</label>';
1386
- echo isset($params['long_description'])
1387
- ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1388
- : '';
1389
- echo '<div class="apbct_settings-field_description">'
1390
- .$params['description']
1391
- .'</div>';
1392
- break;
1393
-
1394
- // Radio type
1395
- case 'radio':
1396
-
1397
- // Title
1398
- echo isset($params['title'])
1399
- ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
1400
- : '';
1401
-
1402
- // Popup description
1403
- echo isset($params['long_description'])
1404
- ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1405
- : '';
1406
-
1407
- echo '<div class="apbct_settings-field_content apbct_settings-field_content--'.$params['type'].'">';
1408
-
1409
- echo '<div class="apbct_switchers" style="direction: ltr">';
1410
- foreach($params['options'] as $option){
1411
- echo '<input'
1412
- .' type="radio"'
1413
- ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1414
- ." id='apbct_setting_{$params['name']}__{$option['label']}'"
1415
- .' name="cleantalk_settings['.$params['name'].']"'
1416
- .' value="'.$option['val'].'"'
1417
- . $disabled
1418
- .($params['childrens']
1419
- ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\', ' . $option['childrens_enable'] . ')"'
1420
- : ''
1421
- )
1422
- .($value == $option['val'] ? ' checked' : '')
1423
- .($params['required'] ? ' required="required"' : '')
1424
- .' />';
1425
- echo '<label for="apbct_setting_'.$params['name'].'__'.$option['label'].'"> ' . $option['label'] . '</label>';
1426
- echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1427
- }
1428
- echo '</div>';
1429
-
1430
- echo isset($params['description'])
1431
- ? '<div class="apbct_settings-field_description">'.$params['description'].'</div>'
1432
- : '';
1433
-
1434
- echo '</div>';
1435
- break;
1436
-
1437
- // Dropdown list type
1438
- case 'select':
1439
- echo isset($params['title'])
1440
- ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
1441
- : '';
1442
- echo '<select'
1443
- . ' id="apbct_setting_'.$params['name'].'"'
1444
- . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1445
- . ' name="cleantalk_settings['.$params['name'].']'.($params['multiple'] ? '[]"' : '"')
1446
- . ($params['multiple'] ? ' size="'. count($params['options']). '""' : '')
1447
- . ($params['multiple'] ? ' multiple="multiple"' : '')
1448
- . ( $params['childrens']
1449
- ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\', jQuery(this).find(\'option:selected\').data(\'children_enable\'))"'
1450
- : ''
1451
- )
1452
- . $disabled
1453
- . ($params['required'] ? ' required="required"' : '')
1454
- . ' >';
1455
-
1456
- foreach($params['options'] as $option){
1457
- echo '<option'
1458
- . ' value="' . $option['val'] . '"'
1459
- . (isset( $option['children_enable'] ) ? ' data-children_enable=' . $option['children_enable'] . ' ' : ' ')
1460
- . ($params['multiple']
1461
- ? (!empty($value) && in_array($option['val'], $value) ? ' selected="selected"' : '')
1462
- : ($value == $option['val'] ? 'selected="selected"' : '')
1463
- )
1464
- .'>'
1465
- . $option['label']
1466
- . '</option>';
1467
- }
1468
-
1469
- echo '</select>';
1470
- echo isset($params['long_description'])
1471
- ? '<i setting="'.$params['name'].'" class="apbct_settings-long_description---show icon-help-circled"></i>'
1472
- : '';
1473
- echo isset($params['description'])
1474
- ? '<div class="apbct_settings-field_description">'.$params['description'].'</div>'
1475
- : '';
1476
-
1477
- break;
1478
-
1479
- // Text type
1480
- case 'text':
1481
-
1482
- echo '<input
1483
  type="text"
1484
- id="apbct_setting_'.$params['name'].'"
1485
- name="cleantalk_settings['.$params['name'].']"'
1486
- ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1487
- .' value="'. $value .'" '
1488
- .$disabled
1489
- .($params['required'] ? ' required="required"' : '')
1490
- .($params['childrens'] ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\')"' : '')
1491
- .' />'
1492
- . '&nbsp;'
1493
- .'<label for="apbct_setting_'.$params['name'].'" class="apbct_setting-field_title--'.$params['type'].'">'
1494
- .$params['title']
1495
- .'</label>';
1496
- echo '<div class="apbct_settings-field_description">'
1497
- .$params['description']
1498
- .'</div>';
1499
- break;
1500
-
1501
- // Textarea type
1502
- case 'textarea':
1503
-
1504
- echo '<label for="apbct_setting_'.$params['name'].'" class="apbct_setting-field_title--'.$params['type'].'">'
1505
- .$params['title']
1506
- .'</label></br>';
1507
- echo '<textarea
1508
- id="apbct_setting_'.$params['name'].'"
1509
- name="cleantalk_settings['.$params['name'].']"'
1510
- ." class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1511
- .$disabled
1512
- .($params['required'] ? ' required="required"' : '')
1513
- .($params['childrens'] ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\')"' : '')
1514
- .'>'. $value .'</textarea>'
1515
- . '&nbsp;';
1516
- echo '<div class="apbct_settings-field_description">'
1517
- .$params['description']
1518
- .'</div>';
1519
- break;
1520
-
1521
- }
1522
-
1523
- echo '</div>';
1524
  }
1525
 
1526
  /**
1527
  * Admin callback function - Plugin parameters validator
1528
- *
1529
- * @global \Cleantalk\ApbctWP\State $apbct
1530
  * @param array $settings Array with passed settings
 
1531
  * @return array Array with processed settings
 
1532
  */
1533
- function apbct_settings__validate($settings) {
1534
-
1535
- global $apbct;
1536
-
1537
- // If user is not allowed to manage settings. Get settings from the storage
1538
- if( ! is_main_site() && ! $apbct->network_settings['multisite__allow_custom_settings'] ){
1539
- foreach ($apbct->settings as $key => $setting){
1540
- // Do not reset apikey to default is allow_custom_key is active
1541
- if( $key === 'apikey' && $apbct->allow_custom_key ) {
1542
- continue;
1543
- }
1544
- $settings[ $key ] = $setting;
1545
- }
1546
- }
1547
-
1548
- // Set missing settings.
1549
- foreach($apbct->def_settings as $setting => $value){
1550
- if(!isset($settings[$setting])){
1551
- $settings[$setting] = null;
1552
- settype($settings[$setting], gettype($value));
1553
- }
1554
- } unset($setting, $value);
1555
-
1556
- // Set missing network settings.
1557
- foreach($apbct->def_network_settings as $setting => $value){
1558
- if(!isset($settings[$setting])){
1559
- $settings[$setting] = null;
1560
- settype($settings[$setting], gettype($value));
1561
- }
1562
- } unset($setting, $value);
1563
-
1564
- // Actions with toggle SFW settings
 
 
1565
  // SFW was enabled
1566
- if( ! $apbct->settings['sfw__enabled'] && $settings['sfw__enabled'] ){
1567
- apbct_sfw_update__init( 3 );
1568
-
1569
- // SFW was disabled
1570
- }elseif( $apbct->settings['sfw__enabled'] && ! $settings['sfw__enabled'] ){
1571
  apbct_sfw__clear();
1572
  }
1573
-
1574
- //Sanitizing sfw__anti_flood__view_limit setting
1575
- $settings['sfw__anti_flood__view_limit'] = floor( intval( $settings['sfw__anti_flood__view_limit'] ) );
1576
- $settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] == 0 ? 20 : $settings['sfw__anti_flood__view_limit'] ); // Default if 0 passed
1577
- $settings['sfw__anti_flood__view_limit'] = ( $settings['sfw__anti_flood__view_limit'] < 5 ? 5 : $settings['sfw__anti_flood__view_limit'] ); //
1578
-
1579
- // Validating API key
1580
- $settings['apikey'] = strpos($settings['apikey'], '*') === false ? $settings['apikey'] : $apbct->settings['apikey'];
1581
-
1582
- $apbct->data['key_changed'] = $settings['apikey'] !== $apbct->settings['apikey'];
1583
-
1584
- $settings['apikey'] = !empty($settings['apikey']) ? trim($settings['apikey']) : '';
1585
- $settings['apikey'] = defined( 'CLEANTALK_ACCESS_KEY') ? CLEANTALK_ACCESS_KEY : $settings['apikey'];
1586
- $settings['apikey'] = ! is_main_site() && $apbct->white_label && $apbct->settings['apikey'] ? $apbct->settings['apikey'] : $settings['apikey'];
1587
- $settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $settings['apikey'] : $apbct->network_settings['apikey'];
1588
- $settings['apikey'] = is_main_site() || !$settings['multisite__white_label'] ? $settings['apikey'] : $apbct->settings['apikey'];
1589
-
1590
- // Show notice if the api key is empty
1591
- if( ! apbct_api_key__is_correct() ) {
1592
- $apbct->data['key_is_ok'] = false;
1593
- $apbct->data['notice_show'] = 1;
1594
- } else {
1595
- // Key is good by default
1596
- $apbct->data['key_is_ok'] = true;
1597
- }
1598
-
1599
- // Sanitize setting values
1600
- foreach ($settings as &$setting ){
1601
- if( is_string( $setting ) )
1602
- $setting = preg_replace( '/[<"\'>]/', '', trim( $setting ) ); // Make HTML code inactive
1603
- }
1604
-
1605
- // Validate Exclusions
1606
- // URLs
1607
- $result = apbct_settings__sanitize__exclusions($settings['exclusions__urls'], $settings['exclusions__urls__use_regexp']);
1608
- $result === false
1609
- ? $apbct->error_add( 'exclusions_urls', 'is not valid: "' . $settings['exclusions__urls'] . '"', 'settings_validate' )
1610
- : $apbct->error_delete( 'exclusions_urls', true, 'settings_validate' );
1611
- $settings['exclusions__urls'] = $result ? $result: '';
1612
-
1613
- // Fields
1614
- $result = apbct_settings__sanitize__exclusions($settings['exclusions__fields'], $settings['exclusions__fields__use_regexp']);
1615
- $result === false
1616
- ? $apbct->error_add( 'exclusions_fields', 'is not valid: "' . $settings['exclusions__fields'] . '"', 'settings_validate' )
1617
- : $apbct->error_delete( 'exclusions_fields', true, 'settings_validate' );
1618
- $settings['exclusions__fields'] = $result ? $result: '';
1619
-
1620
- // WPMS Logic.
1621
- if( APBCT_WPMS && is_main_site() ){
1622
- $network_settings = array(
1623
- 'multisite__allow_custom_settings' => $settings['multisite__allow_custom_settings'],
1624
- 'multisite__white_label' => $settings['multisite__white_label'],
1625
- 'multisite__white_label__plugin_name' => $settings['multisite__white_label__plugin_name'],
1626
- 'multisite__use_settings_template' => $settings['multisite__use_settings_template'],
1627
- 'multisite__use_settings_template_apply_for_new' => $settings['multisite__use_settings_template_apply_for_new'],
1628
- 'multisite__use_settings_template_apply_for_current' => $settings['multisite__use_settings_template_apply_for_current'],
1629
- 'multisite__use_settings_template_apply_for_current_list_sites' => $settings['multisite__use_settings_template_apply_for_current_list_sites'],
1630
- );
1631
- unset( $settings['multisite__white_label'], $settings['multisite__white_label__plugin_name'] );
1632
-
1633
- if( isset( $settings['multisite__hoster_api_key'] ) ){
1634
- $network_settings['multisite__hoster_api_key'] = $settings['multisite__hoster_api_key'];
1635
- unset( $settings['multisite__hoster_api_key'] );
1636
- }
1637
-
1638
- if( isset( $settings['multisite__work_mode'] ) ){
1639
- $network_settings['multisite__work_mode'] = $settings['multisite__work_mode'];
1640
- unset( $settings['multisite__work_mode'] );
1641
- }
1642
- }
1643
-
1644
- // Drop debug data
1645
- if( Post::get( 'submit' ) === 'debug_drop' ){
1646
- $apbct->debug = false;
1647
- delete_option('cleantalk_debug');
1648
- return $settings;
1649
- }
1650
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1651
  // Test connections to servers
1652
- if( Post::get('apbct_debug__check_connection') ){
1653
  $result = apbct_test_connection();
1654
  apbct_log($result);
1655
  }
1656
-
1657
- // Send connection reports
1658
- if( Post::get( 'submit' ) === 'ct_send_connection_report' ){
1659
- ct_mail_send_connection_report();
1660
- return $settings;
1661
- }
1662
-
1663
- $apbct->save('data');
1664
-
1665
- // WPMS Logic.
1666
- if(APBCT_WPMS){
1667
- if(is_main_site()){
1668
-
1669
- // Network settings
1670
- $network_settings['apikey'] = $settings['apikey'];
1671
- $apbct->network_settings = $network_settings;
1672
- $apbct->saveNetworkSettings();
1673
-
1674
- // Network data
1675
- $apbct->network_data = array(
1676
- 'key_is_ok' => $apbct->data['key_is_ok'],
1677
- 'moderate' => $apbct->data['moderate'],
1678
- 'valid' => isset( $apbct->data['valid'] ) ? $apbct->data['valid'] : 0,
1679
- 'auto_update' => $apbct->data['auto_update'],
1680
- 'user_token' => $apbct->data['user_token'],
1681
- 'service_id' => $apbct->data['service_id'],
1682
- );
1683
- $apbct->saveNetworkData();
1684
- if (isset($settings['multisite__use_settings_template_apply_for_current_list_sites']) && !empty($settings['multisite__use_settings_template_apply_for_current_list_sites'])) {
1685
- apbct_update_blogs_options( $settings );
1686
- }
1687
- }
1688
- if(!$apbct->white_label && !is_main_site() && !$apbct->allow_custom_key){
1689
- $settings['apikey'] = '';
1690
- }
1691
- }
1692
-
1693
- // Alt sessions table clearing
1694
- if( $settings['data__set_cookies'] != 2 ) {
1695
  \Cleantalk\ApbctWP\Variables\AltSessions::wipe();
1696
  }
1697
-
1698
- return $settings;
 
 
 
 
 
 
 
 
 
 
 
1699
  }
1700
 
1701
- function apbct_settings__sync( $direct_call = false ){
1702
-
1703
- if( ! $direct_call )
1704
- check_ajax_referer('ct_secret_nonce' );
1705
-
1706
- global $apbct;
1707
-
1708
- //Clearing all errors
1709
- $apbct->error_delete_all('and_save_data');
1710
-
1711
- // Feedback with app_agent
1712
- ct_send_feedback('0:' . APBCT_AGENT); // 0 - request_id, agent version.
1713
-
1714
- // Key is good by default
1715
- $apbct->data['key_is_ok'] = true;
1716
-
1717
- // Checking account status
1718
- $result = ct_account_status_check( $apbct->settings['apikey'] );
1719
-
1720
- // Is key valid?
1721
- if( $result ){
1722
-
1723
- // Deleting errors about invalid key
1724
- $apbct->error_delete( 'key_invalid key_get', 'save' );
1725
-
1726
- // SFW actions
1727
- if( $apbct->settings['sfw__enabled'] == 1 ){
1728
-
1729
- $result = apbct_sfw_update__init( 5 );
1730
- if( ! empty( $result['error'] ) )
1731
- $apbct->error_add( 'sfw_update', $result['error'] );
1732
-
1733
- $result = ct_sfw_send_logs( $apbct->settings['apikey'] );
1734
- if( ! empty( $result['error'] ) )
1735
- $apbct->error_add( 'sfw_send_logs', $result['error'] );
1736
-
1737
- }
1738
-
1739
- // Updating brief data for dashboard widget
1740
- cleantalk_get_brief_data( $apbct->settings['apikey'] );
1741
-
1742
- // Key is not valid
1743
- }else{
1744
- $apbct->data['key_is_ok'] = false;
1745
- $apbct->error_add( 'key_invalid', __( 'Testing is failed. Please check the Access key.', 'cleantalk-spam-protect' ) );
1746
- }
1747
-
1748
- // WPMS Logic.
1749
- if(APBCT_WPMS){
1750
- if(is_main_site()){
1751
-
1752
- // Network settings
1753
- $apbct->network_settings['apikey'] = $apbct->settings['apikey'];
1754
- $apbct->saveNetworkSettings();
1755
-
1756
- // Network data
1757
- $apbct->network_data = array(
1758
- 'key_is_ok' => $apbct->data['key_is_ok'],
1759
- 'moderate' => $apbct->data['moderate'],
1760
- 'valid' => $apbct->data['valid'],
1761
- 'auto_update' => $apbct->data['auto_update'],
1762
- 'user_token' => $apbct->data['user_token'],
1763
- 'service_id' => $apbct->data['service_id'],
1764
- );
1765
-
1766
- if( $apbct->network_settings['multisite__work_mode'] == 1 ){
1767
- $apbct->data['services_count '] = isset( $result['services_count'] ) ? $result['services_count'] : '';
1768
- $apbct->data['services_max'] = isset( $result['services_max'] ) ? $result['services_max'] : '';
1769
- $apbct->data['services_utilization'] = isset( $result['services_utilization'] ) ? $result['services_utilization'] : '';
1770
- }
1771
-
1772
- $apbct->saveNetworkData();
1773
- if (isset($apbct->settings['multisite__use_settings_template_apply_for_current_list_sites']) && !empty($apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'])) {
1774
- apbct_update_blogs_options( $apbct->settings );
1775
- }
1776
- }
1777
- if(!$apbct->white_label && !is_main_site() && !$apbct->allow_custom_key){
1778
- $apbct->settings['apikey'] = '';
1779
- }
1780
- }
1781
-
1782
- if($apbct->data['key_is_ok'] == false && $apbct->data['moderate_ip'] == 0){
1783
-
1784
- // Notices
1785
- $apbct->data['notice_show'] = 1;
1786
- $apbct->data['notice_renew'] = 0;
1787
- $apbct->data['notice_trial'] = 0;
1788
- $apbct->data['notice_review'] = 0;
1789
- $apbct->data['notice_auto_update'] = 0;
1790
-
1791
- // Other
1792
- $apbct->data['service_id'] = 0;
1793
- $apbct->data['valid'] = 0;
1794
- $apbct->data['moderate'] = 0;
1795
- $apbct->data['ip_license'] = 0;
1796
- $apbct->data['moderate_ip'] = 0;
1797
- $apbct->data['spam_count'] = 0;
1798
- $apbct->data['auto_update'] = 0;
1799
- $apbct->data['user_token'] = '';
1800
- $apbct->data['license_trial'] = 0;
1801
- $apbct->data['account_name_ob'] = '';
1802
- }
1803
-
1804
- $out = array(
1805
- 'success' => true,
1806
- 'reload' => isset( $apbct->data['key_changed'] ) ? $apbct->data['key_changed'] : 0,
1807
- );
1808
-
1809
- $apbct->data['key_changed'] = false;
1810
-
1811
- $apbct->saveData();
1812
-
1813
- die( json_encode( $out ) );
1814
  }
1815
 
1816
- function apbct_settings__get_key_auto( $direct_call = false ) {
1817
-
1818
- if( ! $direct_call )
1819
- check_ajax_referer('ct_secret_nonce' );
1820
-
1821
- global $apbct;
1822
-
1823
- $website = parse_url(get_option('siteurl'), PHP_URL_HOST).parse_url(get_option('siteurl'), PHP_URL_PATH);
1824
- $platform = 'wordpress';
1825
- $user_ip = \Cleantalk\ApbctWP\Helper::ip__get('real', false);
1826
- $timezone = filter_input(INPUT_POST, 'ct_admin_timezone');
1827
- $language = apbct_get_server_variable( 'HTTP_ACCEPT_LANGUAGE' );
1828
- $wpms = APBCT_WPMS && defined('SUBDOMAIN_INSTALL') && !SUBDOMAIN_INSTALL ? true : false;
1829
- $white_label = $apbct->network_settings['multisite__white_label'] ? true : false;
1830
- $hoster_api_key = $apbct->network_settings['multisite__hoster_api_key'];
1831
- $admin_email = $apbct->network_settings['multisite__work_mode'] == 1 ? get_site_option( 'admin_email' ) : get_option( 'admin_email' );
1832
- if (function_exists('is_multisite') && is_multisite() && $apbct->white_label) {
1833
- $admin_email = get_site_option( 'admin_email' );
1834
- }
1835
- $result = \Cleantalk\ApbctWP\API::method__get_api_key('antispam',
1836
- $admin_email,
1837
- $website,
1838
- $platform,
1839
- $timezone,
1840
- $language,
1841
- $user_ip,
1842
- $wpms,
1843
- $white_label,
1844
- $hoster_api_key
1845
- );
1846
-
1847
- if(empty($result['error'])){
1848
-
1849
- if(isset($result['user_token'])){
1850
- $apbct->data['user_token'] = $result['user_token'];
1851
- }
1852
-
1853
- if(!empty($result['auth_key'])){
1854
- // @ToDo we have to sanitize only api key. Not need to sanitize every settings here.
1855
- $settings = apbct_settings__validate(array(
1856
- 'apikey' => $result['auth_key'],
1857
- ));
1858
- $apbct->settings['apikey'] = $settings['apikey'];
1859
- }
1860
-
1861
- $templates = \Cleantalk\ApbctWP\CleantalkSettingsTemplates::get_options_template( $result['auth_key'] );
1862
-
1863
- if( ! empty( $templates ) ) {
1864
- $templatesObj = new \Cleantalk\ApbctWP\CleantalkSettingsTemplates( $result['auth_key'] );
1865
- $out = array(
1866
- 'success' => true,
1867
- 'getTemplates' => $templatesObj->getHtmlContent( true ),
1868
- );
1869
- } else {
1870
- $out = array(
1871
- 'success' => true,
1872
- 'reload' => true,
1873
- );
1874
- }
1875
-
1876
- }else{
1877
- $apbct->error_add(
1878
- 'key_get',
1879
- $result['error']
1880
- . ($apbct->white_label
1881
- ? ' <button name="submit" type="button" id="apbct_button__get_key_auto" class="cleantalk_link cleantalk_link-manual" value="get_key_auto">'
1882
- : ''
1883
- )
1884
- );
1885
- $apbct->saveErrors();
1886
- $out = array(
1887
- 'success' => true,
1888
- 'reload' => false,
1889
- );
1890
- }
1891
-
1892
- $apbct->saveSettings();
1893
- $apbct->saveData();
1894
-
1895
- if( $direct_call ) {
1896
- return $result;
1897
- } else {
1898
- die( json_encode( $out ) );
1899
- }
 
 
1900
  }
1901
 
1902
- function apbct_update_blogs_options( $settings ){
1903
-
1904
- global $wpdb;
1905
-
1906
  $blog_names = $settings['multisite__use_settings_template_apply_for_current_list_sites'] ?: array();
1907
-
1908
- $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM '. $wpdb->blogs, OBJECT_K);
1909
-
1910
- foreach ($wp_blogs as $blog) {
1911
- $blog_name = get_blog_details( array( 'blog_id' => $blog->blog_id ) )->blogname;
1912
- if (in_array($blog_name, $blog_names)) {
1913
- update_blog_option ($blog->blog_id, 'cleantalk_settings', $settings);
1914
- }
1915
- }
1916
  }
 
1917
  /**
1918
  * Sanitize and validate exclusions.
1919
  * Explode given string by commas and trim each string.
@@ -1923,95 +2338,166 @@ function apbct_update_blogs_options( $settings ){
1923
  * Return sanitized string if all is ok
1924
  *
1925
  * @param string $exclusions
1926
- * @param bool $regexp
1927
  *
1928
  * @return bool|string
1929
  */
1930
- function apbct_settings__sanitize__exclusions($exclusions, $regexp = false){
1931
- $result = array();
1932
- $type = 0;
1933
- if( ! empty( $exclusions ) ){
1934
- if( strpos( $exclusions, "\r\n" ) !== false ) {
1935
- $exclusions = explode( "\r\n", $exclusions );
1936
- $type = 2;
1937
- } elseif( strpos( $exclusions, "\n" ) !== false ) {
1938
- $exclusions = explode( "\n", $exclusions );
1939
- $type = 1;
 
1940
  } else {
1941
- $exclusions = explode( ',', $exclusions );
1942
  }
1943
- foreach ( $exclusions as $exclusion ){
1944
- $sanitized_exclusion = trim( $exclusion, " \t\n\r\0\x0B/\/" );
1945
- if ( ! empty( $sanitized_exclusion ) ) {
1946
- if( $regexp && ! apbct_is_regexp( $exclusion ) )
1947
- return false;
1948
- $result[] = $sanitized_exclusion;
1949
- }
1950
- }
1951
- }
1952
- switch ( $type ) {
1953
- case 0 :
1954
- default :
1955
- return implode( ',', $result );
1956
- case 1 :
1957
- return implode( "\n", $result );
1958
- case 2 :
1959
- return implode( "\r\n", $result );
 
1960
  }
1961
  }
1962
 
1963
- function apbct_settings_show_gdpr_text($print = false){
1964
-
1965
- $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.
1966
  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.
1967
  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).
1968
  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).
1969
  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.
1970
  They have to be appointed:')
1971
- .'<ul style="padding: 0px 25px; list-style: disc;">'
1972
- .'<li>for all public authorities, except for courts acting in their judicial capacity</li>'
1973
- .'<li>if the core activities of the controller or the processor are:</li>'
1974
- .'<ul style="padding: 0px 25px; list-style: disc;">'
1975
- .'<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>'
1976
- .'<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>'
1977
- .'</ul>'
1978
- .'</li>'
1979
- .'</ul>';
1980
-
1981
- if($print) echo $out; else return $out;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1982
  }
1983
 
1984
- function apbct_settings__get__long_description(){
1985
-
1986
- check_ajax_referer('ct_secret_nonce' );
1987
-
1988
- $setting_id = $_POST['setting_id'] ?: '';
1989
-
1990
- $descriptions = array(
1991
- 'multisite__work_mode' => array(
1992
- 'title' => __( 'Wordpress Multisite Work Mode', 'cleantalk-spam-protect' ),
1993
- 'desc' => __(
1994
- '<h4>Mutual Account, Individual Access Keys</h4>'
1995
- . '<span>Each blog uses a separate key from the network administrator account. Each blog has its own separate security log, settings, personal lists. Key will be provided automatically to each blog once it is created or during the plugin activation process. The key could be changed only by the network administrator.</span>'
1996
- . '<h4>Mutual Account, Mutual Access Key</h4>'
1997
- . '<span>All blogs use one mutual key. They also share security logs, settings and personal lists with each other. Network administrator holds the key.</span>'
1998
- . '<h4>Individual accounts, individual Access keys</h4>'
1999
- . '<span>Each blog uses its own account and its own key. Separate security logs, settings, personal lists. Blog administrator can change the key on his own.</span>'
2000
- , 'cleantalk-spam-protect' )
2001
- ),
2002
- 'multisite__hoster_api_key' => array(
2003
- 'title' => __( 'Hoster API key', 'cleantalk-spam-protect' ),
2004
- 'desc' => __( 'You could find it here:<br><a href ="https://cleantalk-screenshots.s3.amazonaws.com/help/hosting-antispam/hapi-ru.png"><img src="https://cleantalk-screenshots.s3.amazonaws.com/help/hosting-antispam/hapi-ru.png"></a><br>Press on the screenshot to zoom.', 'cleantalk-spam-protect' )
2005
- ),
2006
- );
2007
-
2008
- die(json_encode($descriptions[$setting_id]));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2009
  }
2010
 
2011
- function apbct_settings__check_renew_banner() {
2012
- global $apbct;
2013
-
2014
- check_ajax_referer('ct_secret_nonce' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2015
 
2016
- die(json_encode(array('close_renew_banner' => ($apbct->data['notice_trial'] == 0 && $apbct->data['notice_renew'] == 0) ? true : false)));
2017
- }
 
 
 
 
 
 
1
  <?php
2
 
3
+ use Cleantalk\ApbctWP\Helper;
4
  use Cleantalk\Variables\Post;
5
 
6
  /**
7
  * Admin action 'admin_menu' - Add the admin options page
8
  */
9
+ function apbct_settings_add_page()
10
+ {
11
+ global $apbct, $pagenow;
12
+
13
+ $parent_slug = is_network_admin() ? 'settings.php' : 'options-general.php';
14
+ $callback = is_network_admin() ? 'apbct_settings__display__network' : 'apbct_settings__display';
15
+
16
+ // Adding settings page
17
+ add_submenu_page(
18
+ $parent_slug,
19
+ $apbct->plugin_name . ' ' . __('settings'),
20
+ $apbct->plugin_name,
21
+ 'manage_options',
22
+ 'cleantalk',
23
+ $callback
24
+ );
25
+
26
+ if ( ! in_array($pagenow, array('options.php', 'options-general.php', 'settings.php', 'admin.php')) ) {
27
+ return;
28
+ }
29
+
30
+ register_setting(
31
+ 'cleantalk_settings',
32
+ 'cleantalk_settings',
33
+ array('type' => 'string', 'sanitize_callback' => 'apbct_settings__validate', 'default' => null)
34
+ );
35
+
36
+ $fields = apbct_settings__set_fileds();
37
+ $fields = APBCT_WPMS && is_main_site() ? apbct_settings__set_fileds__network($fields) : $fields;
38
+ apbct_settings__add_groups_and_fields($fields);
39
  }
40
 
41
+ function apbct_settings__set_fileds()
42
+ {
43
+ global $apbct;
44
 
45
  $additional_ac_title = '';
46
+ if ( $apbct->api_key && is_null($apbct->fw_stats['firewall_updating_id']) ) {
47
+ if ( $apbct->settings['sfw__enabled'] && ! $apbct->stats['sfw']['entries'] ) {
48
+ $additional_ac_title =
49
+ ' <span style="color:red">'
50
+ . esc_html__(
51
+ 'The functionality was disabled because SpamFireWall database is empty. Please, do the synchronization or',
52
+ 'cleantalk-spam-protect'
53
+ )
54
+ . ' '
55
+ . '<a href="https://cleantalk.org/my/support/open" target="_blank" style="color:red">'
56
+ . esc_html__(
57
+ 'contact to our support.',
58
+ 'cleantalk-spam-protect'
59
+ )
60
+ . '</a></span>';
61
  }
62
  }
63
+ $additional_sfw_description = '';
64
+ if ( ! empty($apbct->data['notice_incompatibility']) ) {
65
+ $additional_sfw_description .= '<br>';
66
+ foreach ( $apbct->data['notice_incompatibility'] as $notice ) {
67
+ $additional_sfw_description .= '<span style="color:red">' . $notice . '</span><br>';
68
+ }
69
+ }
70
+
71
+ $fields = array(
72
+
73
+ 'main' => array(
74
+ 'title' => '',
75
+ 'default_params' => array(),
76
+ 'description' => '',
77
+ 'html_before' => '',
78
+ 'html_after' => '',
79
+ 'fields' => array(
80
+ 'action_buttons' => array(
81
+ 'callback' => 'apbct_settings__field__action_buttons',
82
+ ),
83
+ 'connection_reports' => array(
84
+ 'callback' => 'apbct_settings__field__statistics',
85
+ ),
86
+ 'api_key' => array(
87
+ 'callback' => 'apbct_settings__field__apikey',
88
+ ),
89
+ ),
90
+ ),
91
+
92
+ 'state' => array(
93
+ 'title' => '',
94
+ 'default_params' => array(),
95
+ 'description' => '',
96
+ 'html_before' => '<hr style="width: 100%;">',
97
+ 'html_after' => '',
98
+ 'fields' => array(
99
+ 'state' => array(
100
+ 'callback' => 'apbct_settings__field__state',
101
+ ),
102
+ ),
103
+ ),
104
+
105
+ 'debug' => array(
106
+ 'title' => '',
107
+ 'default_params' => array(),
108
+ 'description' => '',
109
+ 'html_before' => '',
110
+ 'html_after' => '',
111
+ 'fields' => array(
112
+ 'state' => array(
113
+ 'callback' => 'apbct_settings__field__debug',
114
+ ),
115
+ ),
116
+ ),
117
+
118
+ // Different
119
+ 'different' => array(
120
+ 'title' => '',
121
+ 'default_params' => array(),
122
+ 'description' => '',
123
+ 'html_before' => '<hr>',
124
+ 'html_after' => '',
125
+ 'fields' => array(
126
+ 'sfw__enabled' => array(
127
+ 'type' => 'checkbox',
128
+ 'title' => __('SpamFireWall', 'cleantalk-spam-protect'),
129
+ 'description' =>
130
+ __(
131
+ "This option allows to filter spam bots before they access website. Also reduces CPU usage on hosting server and accelerates pages load time.",
132
+ 'cleantalk-spam-protect'
133
+ )
134
+ . '<br>'
135
+ . esc_html__(
136
+ 'If the setting is turned on, plugin will automatically add IP address for each session with administration rights to Personal list in the cloud.',
137
+ 'cleantalk-spam-protect'
138
+ )
139
+ . $additional_sfw_description,
140
+ 'childrens' => array('sfw__anti_flood', 'sfw__anti_crawler', 'sfw__use_delete_to_clear_table'),
141
+ ),
142
+ ),
143
+ ),
144
+
145
+ // Forms protection
146
+ 'forms_protection' => array(
147
+ 'title' => __('Forms to protect', 'cleantalk-spam-protect'),
148
+ 'default_params' => array(),
149
+ 'description' => '',
150
+ 'html_before' => '<hr><br>'
151
+ . '<span id="ct_adv_showhide">'
152
+ . '<a href="#" class="apbct_color--gray" onclick="event.preventDefault(); apbct_show_hide_elem(\'apbct_settings__davanced_settings\');">'
153
+ . __('Advanced settings', 'cleantalk-spam-protect')
154
+ . '</a>'
155
+ . '</span>'
156
+ . '<div id="apbct_settings__davanced_settings" style="display: none;">',
157
+ 'html_after' => '',
158
+ 'fields' => array(
159
+ 'forms__registrations_test' => array(
160
+ 'title' => __('Registration Forms', 'cleantalk-spam-protect'),
161
+ 'description' => __(
162
+ 'WordPress, BuddyPress, bbPress, S2Member, WooCommerce.',
163
+ 'cleantalk-spam-protect'
164
+ ),
165
+ ),
166
+ 'forms__comments_test' => array(
167
+ 'title' => __('Comments form', 'cleantalk-spam-protect'),
168
+ 'description' => __('WordPress, JetPack, WooCommerce.', 'cleantalk-spam-protect'),
169
+ ),
170
+ 'forms__contact_forms_test' => array(
171
+ 'title' => __('Contact forms', 'cleantalk-spam-protect'),
172
+ 'description' => __(
173
+ 'Contact Form 7, Formidable forms, JetPack, Fast Secure Contact Form, WordPress Landing Pages, Gravity Forms.',
174
+ 'cleantalk-spam-protect'
175
+ ),
176
+ ),
177
+ 'forms__general_contact_forms_test' => array(
178
+ 'title' => __('Custom contact forms', 'cleantalk-spam-protect'),
179
+ 'description' => __(
180
+ 'Anti spam test for any WordPress themes or contacts forms.',
181
+ 'cleantalk-spam-protect'
182
+ ),
183
+ ),
184
+ 'forms__search_test' => array(
185
+ 'title' => __('Test default Wordpress search form for spam', 'cleantalk-spam-protect'),
186
+ 'description' =>
187
+ __('Spam protection for Search form.', 'cleantalk-spam-protect')
188
+ . (! $apbct->white_label || is_main_site() ?
189
+ sprintf(
190
+ __('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'),
191
+ '<a href="https://blog.cleantalk.org/how-to-protect-website-search-from-spambots/" target="_blank">',
192
+ '</a>'
193
+ ) : '')
194
+ ),
195
+ 'forms__check_external' => array(
196
+ 'title' => __('Protect external forms', 'cleantalk-spam-protect'),
197
+ 'description' => __(
198
+ 'Turn this option on to protect forms on your WordPress that send data to third-part servers (like MailChimp).',
199
+ 'cleantalk-spam-protect'
200
+ ),
201
+ 'childrens' => array('forms__check_external__capture_buffer'),
202
+ ),
203
+ 'forms__check_external__capture_buffer' => array(
204
+ 'title' => __('Capture buffer', 'cleantalk-spam-protect'),
205
+ 'description' => __(
206
+ 'This setting gives you more sophisticated and strengthened protection for external forms. But it could break plugins which use a buffer like Ninja Forms.',
207
+ 'cleantalk-spam-protect'
208
+ ),
209
+ 'class' => 'apbct_settings-field_wrapper--sub',
210
+ 'parent' => 'forms__check_external',
211
+ ),
212
+ 'forms__check_internal' => array(
213
+ 'title' => __('Protect internal forms', 'cleantalk-spam-protect'),
214
+ 'description' => __(
215
+ 'This option will enable protection for custom (hand-made) AJAX forms with PHP scripts handlers on your WordPress.',
216
+ 'cleantalk-spam-protect'
217
+ ),
218
+ ),
219
+ ),
220
+ ),
221
+
222
+ // Comments and Messages
223
+ 'wc' => array(
224
+ 'title' => __('WooCommerce', 'cleantalk-spam-protect'),
225
+ 'fields' => array(
226
+ 'forms__wc_checkout_test' => array(
227
+ 'title' => __('WooCommerce checkout form', 'cleantalk-spam-protect'),
228
+ 'description' => __('Anti spam test for WooCommerce checkout form.', 'cleantalk-spam-protect'),
229
+ 'childrens' => array('forms__wc_register_from_order'),
230
  'reverse_trigger' => true,
231
+ 'options' => array(
232
+ array('val' => 1, 'label' => __('On'), 'childrens_enable' => 0,),
233
+ array('val' => 0, 'label' => __('Off'), 'childrens_enable' => 1,),
234
+ ),
235
+ ),
236
+ 'forms__wc_register_from_order' => array(
237
+ 'title' => __('Spam test for registration during checkout', 'cleantalk-spam-protect'),
238
+ 'description' => __(
239
+ 'Enable anti spam test for registration process which during woocommerce\'s checkout.',
240
+ 'cleantalk-spam-protect'
241
+ ),
242
+ 'parent' => 'forms__wc_checkout_test',
243
+ 'class' => 'apbct_settings-field_wrapper--sub',
244
+ 'reverse_trigger' => true,
245
+ ),
246
+ 'forms__wc_add_to_cart' => array(
247
+ 'title' => __(
248
+ 'Check anonymous users when they add new items to the cart',
249
+ 'cleantalk-spam-protect'
250
+ ),
251
+ 'description' => __(
252
+ 'All anonymous users will be checked for spam if they add a new item to their shopping cart.',
253
+ 'cleantalk-spam-protect'
254
+ ),
255
+ 'reverse_trigger' => false,
256
+ 'class' => 'apbct_settings-field_wrapper--sub',
257
+ 'options' => array(
258
+ array('val' => 1, 'label' => __('On')),
259
+ array('val' => 0, 'label' => __('Off')),
260
+ ),
261
+ ),
262
+ 'forms__wc_honeypot' => array(
263
+ 'title' => __(
264
+ 'Add a honeypot field',
265
+ 'cleantalk-spam-protect'
266
+ ),
267
+ 'description' => __(
268
+ 'This option adds a honeypot to the order form to improve spam protection. Enable this option if you have passed spam on the order form.',
269
+ 'cleantalk-spam-protect'
270
+ ),
271
+ 'class' => 'apbct_settings-field_wrapper--sub',
272
+ 'options' => array(
273
+ array('val' => 1, 'label' => __('On')),
274
+ array('val' => 0, 'label' => __('Off')),
275
+ ),
276
+ ),
277
+ ),
278
+ ),
279
+
280
+ // Comments and Messages
281
+ 'comments_and_messages' => array(
282
+ 'title' => __('Comments and Messages', 'cleantalk-spam-protect'),
283
+ 'fields' => array(
284
+ 'comments__disable_comments__all' => array(
285
+ 'title' => __('Disable all comments', 'cleantalk-spam-protect'),
286
+ 'description' => __('Disabling comments for all types of content.', 'cleantalk-spam-protect'),
287
+ 'childrens' => array(
288
+ 'comments__disable_comments__posts',
289
+ 'comments__disable_comments__pages',
290
+ 'comments__disable_comments__media',
291
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  'options' => array(
293
+ array('val' => 1, 'label' => __('On'), 'childrens_enable' => 0,),
294
+ array('val' => 0, 'label' => __('Off'), 'childrens_enable' => 1,),
 
295
  ),
 
296
  ),
297
+ 'comments__disable_comments__posts' => array(
298
+ 'title' => __('Disable comments for all posts', 'cleantalk-spam-protect'),
299
+ 'class' => 'apbct_settings-field_wrapper--sub',
300
+ 'reverse_trigger' => true,
301
+ ),
302
+ 'comments__disable_comments__pages' => array(
303
+ 'title' => __('Disable comments for all pages', 'cleantalk-spam-protect'),
304
+ 'class' => 'apbct_settings-field_wrapper--sub',
305
+ 'reverse_trigger' => true,
306
+ ),
307
+ 'comments__disable_comments__media' => array(
308
+ 'title' => __('Disable comments for all media', 'cleantalk-spam-protect'),
309
+ 'class' => 'apbct_settings-field_wrapper--sub',
310
+ 'reverse_trigger' => true,
311
+ ),
312
+ 'comments__bp_private_messages' => array(
313
+ 'title' => __('BuddyPress Private Messages', 'cleantalk-spam-protect'),
314
+ 'description' => __('Check buddyPress private messages.', 'cleantalk-spam-protect'),
315
+ ),
316
+ 'comments__remove_old_spam' => array(
317
+ 'title' => __('Automatically delete spam comments', 'cleantalk-spam-protect'),
318
+ 'description' => sprintf(
319
+ __('Delete spam comments older than %d days.', 'cleantalk-spam-protect'),
320
+ $apbct->data['spam_store_days']
321
+ ),
322
+ ),
323
+ 'comments__remove_comments_links' => array(
324
+ 'title' => __('Remove links from approved comments', 'cleantalk-spam-protect'),
325
+ 'description' => __(
326
+ 'Remove links from approved comments. Replace it with "[Link deleted]"',
327
+ 'cleantalk-spam-protect'
328
+ ),
329
+ ),
330
+ 'comments__show_check_links' => array(
331
+ 'title' => __('Show links to check Emails, IPs for spam', 'cleantalk-spam-protect'),
332
+ 'description' => __(
333
+ 'Shows little icon near IP addresses and Emails allowing you to check it via CleanTalk\'s database.',
334
+ 'cleantalk-spam-protect'
335
+ ),
336
+ 'display' => ! $apbct->white_label,
337
+ ),
338
+ 'comments__manage_comments_on_public_page' => array(
339
+ 'title' => __('Manage comments on public pages', 'cleantalk-spam-protect'),
340
+ 'description' => __(
341
+ 'Allows administrators to manage comments on public post\'s pages with small interactive menu.',
342
+ 'cleantalk-spam-protect'
343
+ ),
344
+ 'display' => ! $apbct->white_label,
345
+ ),
346
+ 'comments__hide_website_field' => array(
347
+ 'title' => __('Hide the "Website" field', 'cleantalk-spam-protect'),
348
+ 'description' => __(
349
+ 'This option hides the "Website" field on the comment form.',
350
+ 'cleantalk-spam-protect'
351
+ ),
352
+ 'display' => ! $apbct->white_label,
353
+ ),
354
+ ),
355
+ ),
356
+
357
+ // Data Processing
358
+ 'data_processing' => array(
359
+ 'title' => __('Data Processing', 'cleantalk-spam-protect'),
360
+ 'fields' => array(
361
+ 'data__protect_logged_in' => array(
362
+ 'title' => __("Protect logged in Users", 'cleantalk-spam-protect'),
363
+ 'description' => __(
364
+ 'Turn this option on to check for spam any submissions (comments, contact forms and etc.) from registered Users.',
365
+ 'cleantalk-spam-protect'
366
+ ),
367
+ ),
368
+ 'comments__check_comments_number' => array(
369
+ 'title' => __("Don't check trusted user's comments", 'cleantalk-spam-protect'),
370
+ 'description' => sprintf(
371
+ __("Don't check comments for users with above %d comments.", 'cleantalk-spam-protect'),
372
+ defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ? CLEANTALK_CHECK_COMMENTS_NUMBER : 3
373
+ ),
374
+ ),
375
+ 'data__use_ajax' => array(
376
+ 'title' => __('Use AJAX for JavaScript check', 'cleantalk-spam-protect'),
377
+ 'description' => __(
378
+ 'Options helps protect WordPress against spam with any caching plugins. Turn this option on to avoid issues with caching plugins. Turn off this option and SpamFireWall to be compatible with Accelerated mobile pages (AMP).',
379
+ 'cleantalk-spam-protect'
380
+ ),
381
+ ),
382
+ 'data__use_static_js_key' => array(
383
+ 'title' => __('Use static keys for JavaScript check', 'cleantalk-spam-protect'),
384
+ 'description' => __(
385
+ '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.',
386
+ 'cleantalk-spam-protect'
387
+ ),
388
+ 'options' => array(
389
+ array('val' => 1, 'label' => __('On'),),
390
+ array('val' => 0, 'label' => __('Off'),),
391
+ array('val' => -1, 'label' => __('Auto'),),
392
+ ),
393
+ ),
394
+ 'data__general_postdata_test' => array(
395
+ 'title' => __('Check all post data', 'cleantalk-spam-protect'),
396
+ 'description' =>
397
+ __('Check all POST submissions from website visitors. Enable this option if you have spam misses on website.', 'cleantalk-spam-protect')
398
+ . (! $apbct->white_label ?
399
+ __(' Or you don`t have records about missed spam here:', 'cleantalk-spam-protect')
400
+ . '&nbsp;'
401
+ . '<a href="https://cleantalk.org/my/?user_token='
402
+ . $apbct->user_token . '&utm_source=wp-backend&utm_medium=admin-bar&cp_mode=antispam" target="_blank">'
403
+ . __('CleanTalk dashboard', 'cleantalk-spam-protect')
404
+ . '</a>.' : '')
405
+ . '<br />'
406
+ . __('СAUTION! Option can catch POST requests in WordPress backend', 'cleantalk-spam-protect'),
407
+ ),
408
+ 'data__set_cookies' => array(
409
+ 'title' => __("Set cookies", 'cleantalk-spam-protect'),
410
+ 'description' =>
411
+ __(
412
+ 'Turn this option off or use alternative mechanism for cookies to forbid the plugin generate any cookies on website\'s front-end.',
413
+ 'cleantalk-spam-protect'
414
+ )
415
+ . '<br>'
416
+ . __(
417
+ 'This option is helpful if you are using Varnish. Most contact forms will have poor protection if the option is turned off!',
418
+ 'cleantalk-spam-protect'
419
+ )
420
+ . '<br>'
421
+ . __(
422
+ 'Alternative mechanism will store data in database and will not set cookies in browser, so the cache solutions will work just fine.',
423
+ 'cleantalk-spam-protect'
424
+ )
425
+ . '<br><b>'
426
+ . __(
427
+ 'Warning: We strongly recommend you keep the setting on, otherwise it could cause false positives spam detection.',
428
+ 'cleantalk-spam-protect'
429
+ )
430
+ . '</b>',
431
  'input_type' => 'radio',
432
  'options' => array(
433
+ array('val' => 1, 'label' => __('On', 'cleantalk-spam-protect'), 'childrens_enable' => 0,),
434
+ array('val' => 0, 'label' => __('Off', 'cleantalk-spam-protect'), 'childrens_enable' => 0,),
435
+ array(
436
+ 'val' => 2,
437
+ 'label' => __(
438
+ 'Use alternative mechanism for cookies',
439
+ 'cleantalk-spam-protect'
440
+ ),
441
+ 'childrens_enable' => 1,
442
+ ),
443
+ ),
444
+ 'childrens' => array('data__set_cookies__alt_sessions_type')
445
+ ),
446
+ 'data__set_cookies__alt_sessions_type' => array(
447
+ 'display' => $apbct->settings['data__set_cookies'] == 2,
448
+ 'callback' => 'apbct_settings__check_alt_cookies_types'
449
+ ),
450
+ 'data__ssl_on' => array(
451
+ 'title' => __("Use SSL", 'cleantalk-spam-protect'),
452
+ 'description' => __(
453
+ 'Turn this option on to use encrypted (SSL) connection with servers.',
454
+ 'cleantalk-spam-protect'
455
  ),
456
+ ),
457
+ 'wp__use_builtin_http_api' => array(
458
+ 'title' => __("Use Wordpress HTTP API", 'cleantalk-spam-protect'),
459
+ 'description' => __(
460
+ 'Alternative way to connect the Cloud. Use this if you have connection problems.',
461
+ 'cleantalk-spam-protect'
462
+ ),
463
+ ),
464
+ 'sfw__use_delete_to_clear_table' => array(
465
+ 'title' => __(
466
+ "Use DELETE SQL-command instead TRUNCATE to clear tables",
467
+ 'cleantalk-spam-protect'
468
+ ),
469
+ 'description' => __(
470
+ 'Could help if you have blocked SpamFireWall tables in your database.',
471
+ 'cleantalk-spam-protect'
472
+ ),
473
+ 'parent' => 'sfw__enabled',
474
+ ),
475
+ 'data__pixel' => array(
476
  'title' => __('Add a CleanTalk Pixel to improve IP-detection', 'cleantalk-spam-protect'),
477
+ 'description' =>
478
+ __(
479
+ 'Upload small graphic file from Cleantalk\'s server to improve IP-detection.',
480
+ 'cleantalk-spam-protect'
481
+ )
482
+ . '<br>'
483
+ . __(
484
+ '"Auto" use JavaScript option if cache solutions are found.',
485
+ 'cleantalk-spam-protect'
486
+ ),
487
  'options' => array(
488
+ array('val' => 1, 'label' => __('Via direct output', 'cleantalk-spam-protect'),),
489
+ array('val' => 2, 'label' => __('Via JavaScript', 'cleantalk-spam-protect'),),
490
+ array('val' => 3, 'label' => __('Auto', 'cleantalk-spam-protect'),),
491
+ array('val' => 0, 'label' => __('Off', 'cleantalk-spam-protect'),),
492
  ),
493
  ),
494
+ 'data__email_check_before_post' => array(
495
+ 'title' => __('Check email before POST request', 'cleantalk-spam-protect'),
496
+ 'description' => __('Check email address before sending form data', 'cleantalk-spam-protect'),
497
+ ),
498
+ ),
499
+ ),
500
+
501
+ // Exclusions
502
+ 'exclusions' => array(
503
+ 'title' => __('Exclusions', 'cleantalk-spam-protect'),
504
+ 'fields' => array(
505
+ 'exclusions__urls' => array(
506
+ 'type' => 'textarea',
507
+ 'title' => __('URL exclusions', 'cleantalk-spam-protect'),
508
+ 'description' => __(
509
+ 'You could type here URL you want to exclude. Use comma or new lines as separator.',
510
+ 'cleantalk-spam-protect'
511
+ ),
512
+ ),
513
+ 'exclusions__urls__use_regexp' => array(
514
+ 'type' => 'checkbox',
515
+ 'title' => __('Use Regular Expression in URL Exclusions', 'cleantalk-spam-protect'),
516
+ ),
517
+ 'exclusions__fields' => array(
518
+ 'type' => 'text',
519
+ 'title' => __('Field name exclusions', 'cleantalk-spam-protect'),
520
+ 'description' => __(
521
+ 'You could type here fields names you want to exclude. Use comma as separator.',
522
+ 'cleantalk-spam-protect'
523
+ ),
524
+ ),
525
+ 'exclusions__fields__use_regexp' => array(
526
+ 'type' => 'checkbox',
527
+ 'title' => __('Use Regular Expression in Field Exclusions', 'cleantalk-spam-protect'),
528
+ ),
529
+ 'exclusions__roles' => array(
530
+ 'type' => 'select',
531
+ 'multiple' => true,
532
+ 'options_callback' => 'apbct_get_all_roles',
533
+ 'options_callback_params' => array(true),
534
+ 'description' => __(
535
+ 'Roles which bypass spam test. Hold CTRL to select multiple roles.',
536
+ 'cleantalk-spam-protect'
537
+ ),
538
+ ),
539
+ ),
540
+ ),
541
+
542
+ // Admin bar
543
+ 'admin_bar' => array(
544
+ 'title' => __('Admin bar', 'cleantalk-spam-protect'),
545
+ 'default_params' => array(),
546
+ 'description' => '',
547
+ 'html_before' => '',
548
+ 'html_after' => '',
549
+ 'fields' => array(
550
+ 'admin_bar__show' => array(
551
+ 'title' => __('Show statistics in admin bar', 'cleantalk-spam-protect'),
552
+ 'description' => __(
553
+ 'Show/hide icon in top level menu in WordPress backend. The number of submissions is being counted for past 24 hours.',
554
+ 'cleantalk-spam-protect'
555
+ ),
556
+ 'childrens' => array(
557
+ 'admin_bar__all_time_counter',
558
+ 'admin_bar__daily_counter',
559
+ 'admin_bar__sfw_counter'
560
+ ),
561
+ ),
562
+ 'admin_bar__all_time_counter' => array(
563
+ 'title' => __('Show All-time counter', 'cleantalk-spam-protect'),
564
+ 'description' => __(
565
+ 'Display all-time requests counter in the admin bar. Counter displays number of requests since plugin installation.',
566
+ 'cleantalk-spam-protect'
567
+ ),
568
+ 'parent' => 'admin_bar__show',
569
+ 'class' => 'apbct_settings-field_wrapper--sub',
570
+ ),
571
+ 'admin_bar__daily_counter' => array(
572
+ 'title' => __('Show 24 hours counter', 'cleantalk-spam-protect'),
573
+ 'description' => __(
574
+ 'Display daily requests counter in the admin bar. Counter displays number of requests of the past 24 hours.',
575
+ 'cleantalk-spam-protect'
576
+ ),
577
+ 'parent' => 'admin_bar__show',
578
+ 'class' => 'apbct_settings-field_wrapper--sub',
579
+ ),
580
+ 'admin_bar__sfw_counter' => array(
581
+ 'title' => __('SpamFireWall counter', 'cleantalk-spam-protect'),
582
+ 'description' => __(
583
+ 'Display SpamFireWall requests in the admin bar. Counter displays number of requests since plugin installation.',
584
+ 'cleantalk-spam-protect'
585
+ ),
586
+ 'parent' => 'admin_bar__show',
587
+ 'class' => 'apbct_settings-field_wrapper--sub',
588
+ ),
589
+ ),
590
+ ),
591
+
592
+ // SFW features
593
+ 'sfw_features' => array(
594
+ 'title' => __('SpamFireWall features', 'cleantalk-spam-protect'),
595
+ 'default_params' => array(),
596
+ 'description' => '',
597
+ 'html_before' => '',
598
+ 'html_after' => '',
599
+ 'fields' => array(
600
+ 'sfw__random_get' => array(
601
+ 'type' => 'radio',
602
+ 'options' => array(
603
+ array('val' => 1, 'label' => __('On'),),
604
+ array('val' => 0, 'label' => __('Off'),),
605
+ array('val' => -1, 'label' => __('Auto'),),
606
+ ),
607
+ 'title' => __('Uniq GET option', 'cleantalk-spam-protect'),
608
+ 'class' => 'apbct_settings-field_wrapper',
609
+ 'parent' => 'sfw__enabled',
610
+ 'description' => __(
611
+ 'If a visitor gets the SpamFireWall page, the plugin will put a unique GET variable in the URL to avoid issues with caching plugins. Example: https://SITE.COM/?sfw=pass1629985735',
612
+ 'cleantalk-spam-protect'
613
+ ),
614
+ ),
615
+ 'sfw__anti_crawler' => array(
616
+ 'type' => 'checkbox',
617
+ 'title' => __('Anti-Crawler', 'cleantalk-spam-protect') . $additional_ac_title,
618
+ 'class' => 'apbct_settings-field_wrapper',
619
+ 'parent' => 'sfw__enabled',
620
+ 'description' =>
621
+ __(
622
+ 'Plugin shows SpamFireWall stop page for any bot, except allowed bots (Google, Yahoo and etc).',
623
+ 'cleantalk-spam-protect'
624
+ )
625
+ . '<br>'
626
+ . __(
627
+ 'Anti-Crawler includes blocking bots by the User-Agent. Use Personal lists in the Dashboard to filter specific User-Agents.',
628
+ 'cleantalk-spam-protect'
629
+ ),
630
+ ),
631
+ 'sfw__anti_flood' => array(
632
+ 'type' => 'checkbox',
633
+ 'title' => __('Anti-Flood', 'cleantalk-spam-protect'),
634
+ 'class' => 'apbct_settings-field_wrapper',
635
+ 'parent' => 'sfw__enabled',
636
+ 'childrens' => array('sfw__anti_flood__view_limit',),
637
+ 'description' => __(
638
+ 'Shows the SpamFireWall page for bots trying to crawl your site. Look at the page limit setting below.',
639
+ 'cleantalk-spam-protect'
640
+ ),
641
+ ),
642
+ 'sfw__anti_flood__view_limit' => array(
643
+ 'type' => 'text',
644
+ 'title' => __('Anti-Flood Page Views Limit', 'cleantalk-spam-protect'),
645
+ 'class' => 'apbct_settings-field_wrapper--sub',
646
+ 'parent' => 'sfw__anti_flood',
647
+ 'description' => __(
648
+ '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.',
649
+ 'cleantalk-spam-protect'
650
+ ),
651
+ ),
652
+ ),
653
+ ),
654
+
655
+ // Misc
656
+ 'misc' => array(
657
+ 'title' => __('Miscellaneous', 'cleantalk-spam-protect'),
658
+ 'html_after' => '</div><br>',
659
+ 'fields' => array(
660
+ 'misc__collect_details' => array(
661
+ 'type' => 'checkbox',
662
+ 'title' => __('Collect details about browsers', 'cleantalk-spam-protect'),
663
+ 'description' => __(
664
+ "Checking this box you allow plugin store information about screen size and browser plugins of website visitors. The option in a beta state.",
665
+ 'cleantalk-spam-protect'
666
+ ),
667
+ ),
668
+ 'misc__send_connection_reports' => array(
669
+ 'type' => 'checkbox',
670
+ 'title' => __('Send connection reports', 'cleantalk-spam-protect'),
671
+ 'description' => __(
672
+ "Checking this box you allow plugin to send the information about your connection. The option in a beta state.",
673
+ 'cleantalk-spam-protect'
674
+ ),
675
+ ),
676
+ 'misc__async_js' => array(
677
+ 'type' => 'checkbox',
678
+ 'title' => __('Async JavaScript loading', 'cleantalk-spam-protect'),
679
+ 'description' => __(
680
+ 'Use async loading for scripts. Warning: This could reduce filtration quality.',
681
+ 'cleantalk-spam-protect'
682
+ ),
683
+ ),
684
+ 'gdpr__enabled' => array(
685
+ 'type' => 'checkbox',
686
+ 'title' => __('Allow to add GDPR notice via shortcode', 'cleantalk-spam-protect'),
687
+ 'description' => __(
688
+ ' 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"]',
689
+ 'cleantalk-spam-protect'
690
+ ),
691
+ 'childrens' => array('gdpr__text'),
692
+ ),
693
+ 'gdpr__text' => array(
694
+ 'type' => 'text',
695
+ 'title' => __('GDPR text notice', 'cleantalk-spam-protect'),
696
+ 'description' => __(
697
+ 'This text will be added as a description to the GDPR checkbox.',
698
+ 'cleantalk-spam-protect'
699
+ ),
700
+ 'parent' => 'gdpr__enabled',
701
+ 'class' => 'apbct_settings-field_wrapper--sub',
702
+ ),
703
+ 'misc__store_urls' => array(
704
+ 'type' => 'checkbox',
705
+ 'title' => __('Store visited URLs', 'cleantalk-spam-protect'),
706
+ 'description' => __(
707
+ "Plugin stores last 5 visited URLs (HTTP REFERRERS) 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.",
708
+ 'cleantalk-spam-protect'
709
+ ),
710
+ ),
711
+ 'wp__comment_notify' => array(
712
+ 'type' => 'checkbox',
713
+ 'title' => __(
714
+ 'Notify users with selected roles about new approved comments. Hold CTRL to select multiple roles.',
715
+ 'cleantalk-spam-protect'
716
+ ),
717
+ 'description' => sprintf(
718
+ __(
719
+ "If enabled, overrides similar Wordpress %sdiscussion settings%s.",
720
+ 'cleantalk-spam-protect'
721
+ ),
722
+ '<a href="options-discussion.php">',
723
+ '</a>'
724
+ ),
725
+ 'childrens' => array('wp__comment_notify__roles'),
726
+ ),
727
+ 'wp__comment_notify__roles' => array(
728
+ 'type' => 'select',
729
+ 'multiple' => true,
730
+ 'parent' => 'wp__comment_notify',
731
+ 'options_callback' => 'apbct_get_all_roles',
732
+ 'options_callback_params' => array(true),
733
+ 'class' => 'apbct_settings-field_wrapper--sub',
734
+ ),
735
+ 'wp__dashboard_widget__show' => array(
736
+ 'type' => 'checkbox',
737
+ 'title' => __('Show Dashboard Widget', 'cleantalk-spam-protect'),
738
+ ),
739
+ 'misc__complete_deactivation' => array(
740
+ 'type' => 'checkbox',
741
+ 'title' => __('Complete deactivation', 'cleantalk-spam-protect'),
742
+ 'description' => __('Leave no trace in the system after deactivation.', 'cleantalk-spam-protect'),
743
+ ),
744
+
745
+ ),
746
+ ),
747
+ );
748
+
749
+ return $fields;
750
  }
751
 
752
+ function apbct_settings__set_fileds__network($fields)
753
+ {
754
+ global $apbct;
755
+ $additional_fields = array(
756
+ 'wpms_settings' => array(
757
+ 'default_params' => array(),
758
+ 'description' => '',
759
+ 'html_before' => '<br>'
760
+ . '<span id="ct_adv_showhide">'
761
+ . '<a href="#" class="apbct_color--gray" onclick="event.preventDefault(); apbct_show_hide_elem(\'apbct_settings__dwpms_settings\');">'
762
+ . __('WordPress Multisite (WPMS) settings', 'cleantalk-spam-protect')
763
+ . '</a>'
764
+ . '</span>'
765
+ . '<div id="apbct_settings__dwpms_settings" style="display: none;">',
766
+ 'html_after' => '</div><br>',
767
+ 'fields' => array(
768
+ 'multisite__work_mode' => array(
769
+ 'type' => 'select',
770
+ 'options' => array(
771
+ array(
772
+ 'val' => 1,
773
+ 'label' => __(
774
+ 'Mutual Account, Individual Access Keys',
775
+ 'cleantalk-spam-protect'
776
+ ),
777
+ 'children_enable' => 1,
778
+ ),
779
+ array(
780
+ 'val' => 2,
781
+ 'label' => __('Mutual Account, Mutual Access Key', 'cleantalk-spam-protect'),
782
+ 'children_enable' => 0,
783
+ ),
784
+ array(
785
+ 'val' => 3,
786
+ 'label' => __(
787
+ 'Individual accounts, individual Access keys',
788
+ 'cleantalk-spam-protect'
789
+ ),
790
+ 'children_enable' => 0,
791
+ ),
792
+ ),
793
+ 'title' => __('Wordpress Multisite Work Mode', 'cleantalk-spam-protect'),
794
+ 'description' => __(
795
+ 'You can choose the work mode here for the child blogs and how they will operate with the CleanTalk Cloud. Press "?" for the detailed description.',
796
+ 'cleantalk-spam-protect'
797
+ ),
798
+ 'long_description' => true,
799
+ 'display' => APBCT_WPMS && is_main_site(),
800
+ 'childrens' => array('multisite__hoster_api_key', 'multisite__white_label'),
801
+ 'network' => true,
802
+ ),
803
+ 'multisite__hoster_api_key' => array(
804
+ 'type' => 'text',
805
+ 'required' => true,
806
+ 'title' => __('Hoster API key', 'cleantalk-spam-protect'),
807
+ 'description' => sprintf(
808
+ __('Copy the key from your %sCleantalk Profile%s', 'cleantalk-spam-protect'),
809
+ '<a href="https://cleantalk.org/my/profile#api_keys" target="_blank">',
810
+ '</a>'
811
+ ),
812
+ 'class' => 'apbct_settings-field_wrapper--sub',
813
+ 'long_description' => true,
814
+ 'display' => APBCT_WPMS && is_main_site(),
815
+ 'disabled' => ! isset($apbct->network_settings['multisite__work_mode']) || $apbct->network_settings['multisite__work_mode'] != 1,
816
+ 'parent' => 'multisite__work_mode',
817
+ 'network' => true,
818
+ ),
819
+ 'multisite__service_utilization' => array(
820
+ 'type' => 'field',
821
+ 'class' => 'apbct_settings-field_wrapper--sub',
822
+ 'callback' => 'apbct_field_service_utilization',
823
+ 'display' => APBCT_WPMS && is_main_site() && $apbct->network_settings['multisite__work_mode'] == 1,
824
+ ),
825
+ 'multisite__white_label' => array(
826
+ 'type' => 'checkbox',
827
+ 'title' => __('Enable White Label Mode', 'cleantalk-spam-protect'),
828
+ 'description' => sprintf(
829
+ __("Learn more information %shere%s.", 'cleantalk-spam-protect'),
830
+ '<a target="_blank" href="https://cleantalk.org/ru/help/hosting-white-label">',
831
+ '</a>'
832
+ ),
833
+ 'childrens' => array('multisite__white_label__plugin_name'),
834
+ 'disabled' => defined('CLEANTALK_ACCESS_KEY') ||
835
+ ! isset($apbct->network_settings['multisite__work_mode']) ||
836
+ $apbct->network_settings['multisite__work_mode'] != 1,
837
+ 'parent' => 'multisite__work_mode',
838
+ 'class' => 'apbct_settings-field_wrapper--sub',
839
+ 'network' => true,
840
+ ),
841
+ 'multisite__white_label__plugin_name' => array(
842
+ 'title' => __('Plugin name', 'cleantalk-spam-protect'),
843
+ 'description' => sprintf(
844
+ __(
845
+ "Specify plugin name. Leave empty for deafult %sAntispam by Cleantalk%s",
846
+ 'cleantalk-spam-protect'
847
+ ),
848
+ '<b>',
849
+ '</b>'
850
+ ),
851
+ 'type' => 'text',
852
+ 'parent' => 'multisite__white_label',
853
+ 'class' => 'apbct_settings-field_wrapper--sub',
854
+ 'network' => true,
855
+ ),
856
+ 'multisite__allow_custom_settings' => array(
857
+ 'type' => 'checkbox',
858
+ 'title' => __('Allow users to manage plugin settings', 'cleantalk-spam-protect'),
859
+ 'description' => __('Allow to change settings on child sites.', 'cleantalk-spam-protect'),
860
+ 'display' => APBCT_WPMS && is_main_site(),
861
+ 'network' => true,
862
+ ),
863
+ 'multisite__use_settings_template' => array(
864
+ 'type' => 'checkbox',
865
+ 'title' => __('Use settings template', 'cleantalk-spam-protect'),
866
+ 'description' => __("Use the current settings template for child sites.", 'cleantalk-spam-protect'),
867
+ 'childrens' => array(
868
+ 'multisite__use_settings_template_apply_for_new',
869
+ 'multisite__use_settings_template_apply_for_current'
870
+ ),
871
+ 'network' => true,
872
+ ),
873
+ 'multisite__use_settings_template_apply_for_new' => array(
874
+ 'type' => 'checkbox',
875
+ 'title' => __('Apply for newly added sites.', 'cleantalk-spam-protect'),
876
+ 'description' => __(
877
+ "The newly added site will have the same preset settings template.",
878
+ 'cleantalk-spam-protect'
879
+ ),
880
+ 'parent' => 'multisite__use_settings_template',
881
+ 'class' => 'apbct_settings-field_wrapper--sub',
882
+ 'network' => true,
883
+ ),
884
+ 'multisite__use_settings_template_apply_for_current' => array(
885
+ 'type' => 'checkbox',
886
+ 'title' => __('Apply for current sites.', 'cleantalk-spam-protect'),
887
+ 'description' => __(
888
+ "Apply current settings template for selected sites.",
889
+ 'cleantalk-spam-protect'
890
+ ),
891
+ 'parent' => 'multisite__use_settings_template',
892
+ 'childrens' => array('multisite__use_settings_template_apply_for_current_list_sites'),
893
+ 'class' => 'apbct_settings-field_wrapper--sub',
894
+ 'network' => true,
895
+ ),
896
+ 'multisite__use_settings_template_apply_for_current_list_sites' => array(
897
+ 'type' => 'select',
898
+ 'multiple' => true,
899
+ 'options_callback' => 'apbct_get_all_child_domains',
900
+ 'options_callback_params' => array(true),
901
+ 'class' => 'apbct_settings-field_wrapper--sub',
902
+ 'parent' => 'multisite__use_settings_template_apply_for_current',
903
+ 'description' => __(
904
+ 'Sites to apply settings. Hold CTRL to select multiple sites.',
905
+ 'cleantalk-spam-protect'
906
+ ),
907
+ 'network' => true,
908
+ ),
909
+ )
910
+ )
911
+ );
912
+
913
+ $fields = array_merge_recursive($fields, $additional_fields);
914
+
915
+ return $fields;
916
  }
917
 
918
+ function apbct_settings__add_groups_and_fields($fields)
919
+ {
920
+ global $apbct;
921
+
922
+ $apbct->settings_fields_in_groups = $fields;
923
+
924
+ $field_default_params = array(
925
+ 'callback' => 'apbct_settings__field__draw',
926
+ 'type' => 'radio',
927
+ 'options' => array(
928
+ array('val' => 1, 'label' => __('On', 'cleantalk-spam-protect'), 'childrens_enable' => 1,),
929
+ array('val' => 0, 'label' => __('Off', 'cleantalk-spam-protect'), 'childrens_enable' => 0,),
930
+ ),
931
+ 'def_class' => 'apbct_settings-field_wrapper',
932
+ 'class' => '',
933
+ 'parent' => '',
934
+ 'childrens' => array(),
935
+ 'hide' => array(),
936
+ // 'title' => 'Default title',
937
+ // 'description' => 'Default description',
938
+ 'display' => true,
939
+ // Draw settings or not
940
+ 'reverse_trigger' => false,
941
+ // How to allow child settings. Childrens are opened when the parent triggered "ON". This is overrides by this option
942
+ 'multiple' => false,
943
+ 'description' => '',
944
+ 'network' => false,
945
+ 'disabled' => false,
946
+ 'required' => false,
947
+ );
948
+
949
+ foreach ( $apbct->settings_fields_in_groups as $group_name => $group ) {
950
+ add_settings_section('apbct_section__' . $group_name, '', '', 'cleantalk-spam-protect');
951
+
952
+ foreach ( $group['fields'] as $field_name => $field ) {
953
+ // Normalize $field['options'] from callback function to this type array( array( 'val' => 1, 'label' => __('On'), ), )
954
+ if ( ! empty($field['options_callback']) ) {
955
+ $options = call_user_func_array(
956
+ $field['options_callback'],
957
+ ! empty($field['options_callback_params']) ? $field['options_callback_params'] : array()
958
+ );
959
+ foreach ( $options as &$option ) {
960
+ if ( is_array($option) ) {
961
+ $option = array(
962
+ 'val' => isset($option['val']) ? $option['val'] : current($option),
963
+ 'label' => isset($option['label']) ? $option['label'] : end($option)
964
+ );
965
+ } else {
966
+ $option = array('val' => $option, 'label' => $option);
967
+ }
968
+ }
969
+ unset($option);
970
+ $field['options'] = $options;
971
+ }
972
+
973
+ $params = ! empty($group['default_params'])
974
+ ? array_merge($group['default_params'], $field)
975
+ : array_merge($field_default_params, $field);
976
+
977
+ $params['name'] = $field_name;
978
+
979
+ if ( ! $params['display'] ) {
980
+ continue;
981
+ }
982
+
983
+ add_settings_field(
984
+ 'apbct_field__' . $field_name,
985
+ '',
986
+ $params['callback'],
987
+ 'cleantalk',
988
+ 'apbct_section__' . $group_name,
989
+ $params
990
+ );
991
+ }
992
+ }
993
  }
994
 
995
  /**
996
  * Admin callback function - Displays plugin options page
997
  */
998
+ function apbct_settings__display()
999
+ {
1000
+ global $apbct;
1001
+
1002
+ // Title
1003
+ echo '<h2 class="apbct_settings-title">' . __($apbct->plugin_name, 'cleantalk-spam-protect') . '</h2>';
1004
+
1005
+ // Subtitle for IP license
1006
+ if ( $apbct->moderate_ip ) {
1007
+ echo '<h4 class="apbct_settings-subtitle apbct_color--gray">' .
1008
+ __('Hosting AntiSpam', 'cleantalk-spam-protect') . '</h4>';
1009
+ }
1010
+
1011
+ echo '<form action="options.php" method="post">';
1012
+
1013
+ apbct_settings__error__output();
1014
+
1015
+ // Top info
1016
+ if ( ! $apbct->white_label ) {
1017
+ echo '<div style="float: right; padding: 15px 15px 5px 15px; font-size: 13px; position: relative; background: #f1f1f1;">';
1018
+
1019
+ echo __('CleanTalk\'s tech support:', 'cleantalk-spam-protect')
1020
+ . '&nbsp;'
1021
+ . '<a target="_blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">Wordpress.org</a>.'
1022
+ . '<br>';
1023
+ echo __('Plugin Homepage at', 'cleantalk-spam-protect') .
1024
+ ' <a href="https://cleantalk.org" target="_blank">cleantalk.org</a>.<br/>';
1025
+ echo '<span id="apbct_gdpr_open_modal" style="text-decoration: underline;">' . __(
1026
+ 'GDPR compliance',
1027
+ 'cleantalk-spam-protect'
1028
+ ) . '</span><br/>';
1029
+ echo __('Use s@cleantalk.org to test plugin in any WordPress form.', 'cleantalk-spam-protect') . '<br>';
1030
+ echo __('CleanTalk is registered Trademark. All rights reserved.', 'cleantalk-spam-protect') . '<br/>';
1031
+ if ( $apbct->key_is_ok ) {
1032
+ echo '<b style="display: inline-block; margin-top: 10px;">' . sprintf(
1033
+ __('Do you like CleanTalk? %sPost your feedback here%s.', 'cleantalk-spam-protect'),
1034
+ '<a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank">',
1035
+ '</a>'
1036
+ ) . '</b><br />';
1037
+ }
1038
+ apbct_admin__badge__get_premium();
1039
+ echo '<div id="gdpr_dialog" style="display: none; padding: 7px;">';
1040
+ apbct_settings_show_gdpr_text('print');
1041
+ echo '</div>';
1042
+ echo '</div>';
1043
+ }
1044
+
1045
+ // Output spam count
1046
+ if ( $apbct->key_is_ok && apbct_api_key__is_correct() ) {
1047
+ if ( $apbct->spam_count > 0 ) {
1048
+ echo '<div class="apbct_settings-subtitle" style="top: 0; margin-bottom: 10px; width: 200px;">'
1049
+ . '<br>'
1050
+ . '<span>'
1051
+ . sprintf(
1052
+ __('%s has blocked <b>%s</b> spam.', 'cleantalk-spam-protect'),
1053
+ $apbct->plugin_name,
1054
+ number_format($apbct->spam_count, 0, ',', ' ')
1055
+ )
1056
+ . '</span>'
1057
+ . '<br>'
1058
+ . '<br>'
1059
+ . '</div>';
1060
+ }
1061
+ }
1062
+
1063
+
1064
+ // Output spam count
1065
+ if ( $apbct->key_is_ok && apbct_api_key__is_correct() ) {
1066
+ if ( $apbct->network_settings['multisite__work_mode'] != 2 || is_main_site() ) {
1067
+ // CP button
1068
+ echo '<a class="cleantalk_link cleantalk_link-manual" target="__blank" href="https://cleantalk.org/my?user_token=' . $apbct->user_token . '&cp_mode=antispam">'
1069
+ . __('Click here to get anti-spam statistics', 'cleantalk-spam-protect')
1070
+ . '</a>';
1071
+ echo '&nbsp;&nbsp;';
1072
+ }
1073
+ }
1074
+
1075
+ if ( apbct_api_key__is_correct() && ($apbct->network_settings['multisite__work_mode'] != 2 || is_main_site()) ) {
1076
+ // Sync button
1077
+ echo '<button type="button" class="cleantalk_link cleantalk_link-auto" id="apbct_button__sync" title="Synchronizing account status, SpamFireWall database, all kind of journals.">'
1078
+ . '<i class="icon-upload-cloud"></i>&nbsp;&nbsp;'
1079
+ . __('Synchronize with Cloud', 'cleantalk-spam-protect')
1080
+ . '<img style="margin-left: 10px;" class="apbct_preloader_button" src="' . APBCT_URL_PATH . '/inc/images/preloader2.gif" />'
1081
+ . '<img style="margin-left: 10px;" class="apbct_success --hide" src="' . APBCT_URL_PATH . '/inc/images/yes.png" />'
1082
+ . '</button>';
1083
+ echo '&nbsp;&nbsp;';
1084
+ }
1085
+
1086
+ // Output spam count
1087
+ if ( $apbct->key_is_ok && apbct_api_key__is_correct() ) {
1088
+ if ( $apbct->network_settings['multisite__work_mode'] != 2 || is_main_site() ) {
1089
+ // Support button
1090
+ echo '<a class="cleantalk_link cleantalk_link-auto" target="__blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">' .
1091
+ __('Support', 'cleantalk-spam-protect') . '</a>';
1092
+ echo '&nbsp;&nbsp;';
1093
+ echo '<br>'
1094
+ . '<br>';
1095
+ }
1096
+ }
1097
+
1098
+ settings_fields('cleantalk_settings');
1099
+ do_settings_fields('cleantalk', 'cleantalk_section_settings_main');
1100
+
1101
+ foreach ( $apbct->settings_fields_in_groups as $group_name => $group ) {
1102
+ echo ! empty($group['html_before']) ? $group['html_before'] : '';
1103
+ echo ! empty($group['title']) ? '<h3 style="margin-left: 220px;">' . $group['title'] . '</h3>' : '';
1104
+
1105
+ do_settings_fields('cleantalk', 'apbct_section__' . $group_name);
1106
+
1107
+ echo ! empty($group['html_after']) ? $group['html_after'] : '';
1108
+ }
1109
+
1110
+ echo '<br>';
1111
+ echo '<button name="submit" class="cleantalk_link cleantalk_link-manual" value="save_changes">' .
1112
+ __('Save Changes') . '</button>';
1113
+
1114
+ echo "</form>";
1115
+
1116
+ if ( ! $apbct->white_label ) {
1117
+ // Translate banner for non EN locale
1118
+ if ( substr(get_locale(), 0, 2) != 'en' ) {
1119
+ require_once(CLEANTALK_PLUGIN_DIR . 'templates/translate_banner.php');
1120
+ printf($ct_translate_banner_template, substr(get_locale(), 0, 2));
1121
+ }
1122
+ }
1123
  }
1124
 
1125
+ function apbct_settings__display__network()
1126
+ {
1127
+ // If it's network admin dashboard
1128
+ if ( is_network_admin() ) {
1129
+ $site_url = get_site_option('siteurl');
1130
+ $site_url = preg_match('/\/$/', $site_url) ? $site_url : $site_url . '/';
1131
+ $link = $site_url . 'wp-admin/options-general.php?page=cleantalk';
1132
+ printf(
1133
+ "<h2>" . __(
1134
+ "Please, enter the %splugin settings%s in main site dashboard.",
1135
+ 'cleantalk-spam-protect'
1136
+ ) . "</h2>",
1137
+ "<a href='$link'>",
1138
+ "</a>"
1139
+ );
1140
+
1141
+ return;
1142
+ }
1143
  }
1144
 
1145
+ function apbct_settings__error__output($return = false)
1146
+ {
1147
+ global $apbct;
1148
+
1149
+ // If have error message output error block.
1150
+
1151
+ $out = '';
1152
+
1153
+ if ( ! empty($apbct->errors) && ! defined('CLEANTALK_ACCESS_KEY') ) {
1154
+ $errors = $apbct->errors;
1155
+
1156
+ $error_texts = array(
1157
+ // Misc
1158
+ 'key_invalid' => __('Error occurred while API key validating. Error: ', 'cleantalk-spam-protect'),
1159
+ 'key_get' => __(
1160
+ 'Error occurred while automatically gettings access key. Error: ',
1161
+ 'cleantalk-spam-protect'
1162
+ ),
1163
+ 'sfw_send_logs' => __(
1164
+ 'Error occurred while sending SpamFireWall logs. Error: ',
1165
+ 'cleantalk-spam-protect'
1166
+ ),
1167
+ 'sfw_update' => __(
1168
+ 'Error occurred while updating SpamFireWall local base. Error: ',
1169
+ 'cleantalk-spam-protect'
1170
+ ),
1171
+ 'ua_update' => __(
1172
+ 'Error occurred while updating User-Agents local base. Error: ',
1173
+ 'cleantalk-spam-protect'
1174
+ ),
1175
+ 'account_check' => __(
1176
+ 'Error occurred while checking account status. Error: ',
1177
+ 'cleantalk-spam-protect'
1178
+ ),
1179
+ 'api' => __('Error occurred while excuting API call. Error: ', 'cleantalk-spam-protect'),
1180
+
1181
+ // Validating settings
1182
+ 'settings_validate' => 'Validate Settings',
1183
+ 'exclusions_urls' => 'URL Exclusions',
1184
+ 'exclusions_fields' => 'Field Exclusions',
1185
+
1186
+ // Unknown
1187
+ 'unknown' => __('Unknown error type: ', 'cleantalk-spam-protect'),
1188
+ );
1189
+
1190
+ $errors_out = array();
1191
+
1192
+ foreach ( $errors as $type => $error ) {
1193
+ if ( ! empty($error) ) {
1194
+ if ( is_array(current($error)) ) {
1195
+ foreach ( $error as $sub_type => $sub_error ) {
1196
+ if ( isset($sub_error['error']) && strpos($sub_error['error'], 'SFW_IS_DISABLED') !== false ) {
1197
  continue;
1198
  }
1199
+
1200
+ $errors_out[$sub_type] = '';
1201
+ if ( isset($sub_error['error_time']) ) {
1202
+ $errors_out[$sub_type] .= date('Y-m-d H:i:s', $sub_error['error_time']) . ': ';
1203
+ }
1204
+ $errors_out[$sub_type] .= (isset($error_texts[$type]) ? $error_texts[$type] : ucfirst($type)) . ': ';
1205
+ $errors_out[$sub_type] .= (isset($error_texts[$sub_type]) ? $error_texts[$sub_type] : ( $error_texts['unknown'] . $sub_type . ' ' . __('Error: ', 'cleantalk-spam-protect') ) . ' ' . $sub_error['error'] );
1206
+ }
1207
+ continue;
1208
+ }
1209
+
1210
+ if (
1211
+ ! empty($type) &&
1212
  $apbct->white_label &&
1213
+ ! is_main_site() &&
1214
+ in_array($type, array('sfw_update', 'key_invalid', 'account_check'))
1215
+ ) {
1216
+ continue;
 
 
 
 
1217
  }
1218
+
1219
+ if ( isset($error['error']) && strpos($error['error'], 'SFW_IS_DISABLED') !== false ) {
1220
+ continue;
1221
+ }
1222
+
1223
+ $errors_out[$type] = '';
1224
+
1225
+ if ( isset($error['error_time']) ) {
1226
+ $errors_out[$type] .= date('Y-m-d H:i:s', $error['error_time']) . ': ';
1227
+ }
1228
+
1229
+ $errors_out[$type] .= (isset($error_texts[$type]) ? $error_texts[$type] : $error_texts['unknown']) . ' ' . (isset($error['error']) ? $error['error'] : '');
1230
+ }
1231
+ }
1232
+
1233
+ if ( ! empty($errors_out) ) {
1234
+ $out .= '<div id="apbctTopWarning" class="error" style="position: relative;">'
1235
+ . '<h3 style="display: inline-block;">' . __('Errors:', 'cleantalk-spam-protect') . '</h3>';
1236
+ foreach ( $errors_out as $value ) {
1237
+ $out .= '<h4>' . $value . '</h4>';
1238
+ }
1239
+ $out .= ! $apbct->white_label
1240
+ ? '<h4 style="text-align: unset;">' . sprintf(
1241
+ __('You can get support any time here: %s.', 'cleantalk-spam-protect'),
1242
+ '<a target="blank" href="https://wordpress.org/support/plugin/cleantalk-spam-protect">https://wordpress.org/support/plugin/cleantalk-spam-protect</a>'
1243
+ ) . '</h4>'
1244
+ : '';
1245
+ $out .= '</div>';
1246
+ }
1247
+ }
1248
+
1249
+ if ( $return ) {
1250
+ return $out;
1251
+ } else {
1252
+ echo $out;
1253
+ }
1254
  }
1255
 
1256
+ function apbct_settings__field__debug()
1257
+ {
1258
+ global $apbct;
1259
+
1260
+ if ( $apbct->debug ) {
1261
+ echo '<hr /><h2>Debug:</h2>';
1262
+ echo '<h4>Constants:</h4>';
1263
+ echo 'CLEANTALK_AJAX_USE_BUFFER ' .
1264
+ (defined('CLEANTALK_AJAX_USE_BUFFER') ?
1265
+ var_export(CLEANTALK_AJAX_USE_BUFFER, true) :
1266
+ 'NOT_DEFINED') .
1267
+ "<br>";
1268
+ echo 'CLEANTALK_AJAX_USE_FOOTER_HEADER ' .
1269
+ (defined('CLEANTALK_AJAX_USE_FOOTER_HEADER') ?
1270
+ var_export(CLEANTALK_AJAX_USE_FOOTER_HEADER, true) :
1271
+ 'NOT_DEFINED') .
1272
+ "<br>";
1273
+ echo 'CLEANTALK_ACCESS_KEY ' .
1274
+ (defined('CLEANTALK_ACCESS_KEY') ?
1275
+ var_export(CLEANTALK_ACCESS_KEY, true) :
1276
+ 'NOT_DEFINED') .
1277
+ "<br>";
1278
+ echo 'CLEANTALK_CHECK_COMMENTS_NUMBER ' .
1279
+ (defined('CLEANTALK_CHECK_COMMENTS_NUMBER') ?
1280
+ var_export(CLEANTALK_CHECK_COMMENTS_NUMBER, true) :
1281
+ 'NOT_DEFINED') .
1282
+ "<br>";
1283
+ echo 'CLEANTALK_CHECK_MESSAGES_NUMBER ' .
1284
+ (defined('CLEANTALK_CHECK_MESSAGES_NUMBER') ?
1285
+ var_export(CLEANTALK_CHECK_MESSAGES_NUMBER, true) :
1286
+ 'NOT_DEFINED') .
1287
+ "<br>";
1288
+ echo 'CLEANTALK_PLUGIN_DIR ' .
1289
+ (defined('CLEANTALK_PLUGIN_DIR') ?
1290
+ var_export(CLEANTALK_PLUGIN_DIR, true) :
1291
+ 'NOT_DEFINED') .
1292
+ "<br>";
1293
+ echo 'WP_ALLOW_MULTISITE ' .
1294
+ (defined('WP_ALLOW_MULTISITE') ?
1295
+ var_export(WP_ALLOW_MULTISITE, true) :
1296
+ 'NOT_DEFINED') .
1297
+ "<br>";
1298
+
1299
+ echo '<h4><button type="submit" name="apbct_debug__check_connection" value="1">Check connection to API servers</button></h4>';
1300
+ echo "<h4>Debug log: <button type='submit' value='debug_drop' name='submit' style='font-size: 11px; padding: 1px;'>Drop debug data</button></h4>";
1301
+ echo "<div style='height: 500px; width: 80%; overflow: auto;'>";
1302
+
1303
+ $output = print_r($apbct->debug, true);
1304
+ $output = str_replace("\n", "<br>", $output);
1305
+ $output = preg_replace("/[^\S]{4}/", "&nbsp;&nbsp;&nbsp;&nbsp;", $output);
1306
+ echo "$output";
1307
+
1308
+ echo "</div>";
1309
+ }
1310
  }
1311
 
1312
+ function apbct_settings__field__state()
1313
+ {
1314
+ global $apbct;
1315
+
1316
+ $path_to_img = plugin_dir_url(__FILE__) . "images/";
1317
+
1318
+ $img = $path_to_img . "yes.png";
1319
+ $img_no = $path_to_img . "no.png";
1320
+ $img_no_gray = $path_to_img . "no_gray.png";
1321
+ $color = "black";
1322
+
1323
+ if ( ! $apbct->key_is_ok ) {
1324
+ $img = $path_to_img . "no.png";
1325
+ $img_no = $path_to_img . "no.png";
1326
+ $color = "black";
1327
+ }
1328
+
1329
+ if ( ! apbct_api_key__is_correct($apbct->api_key) ) {
1330
+ $img = $path_to_img . "yes_gray.png";
1331
+ $img_no = $path_to_img . "no_gray.png";
1332
+ $color = "gray";
1333
+ }
1334
+
1335
+ if ( $apbct->moderate_ip ) {
1336
+ $img = $path_to_img . "yes.png";
1337
+ $img_no = $path_to_img . "no.png";
1338
+ $color = "black";
1339
+ }
1340
+
1341
+ if ( $apbct->moderate == 0 ) {
1342
+ $img = $path_to_img . "no.png";
1343
+ $img_no = $path_to_img . "no.png";
1344
+ $color = "black";
1345
+ }
1346
+
1347
+ print '<div class="apbct_settings-field_wrapper" style="color:' . $color . '">';
1348
+
1349
+ print '<h2>' . __('Protection is active', 'cleantalk-spam-protect') . '</h2>';
1350
+
1351
+ echo '<img class="apbct_status_icon" src="' . ($apbct->settings['forms__registrations_test'] == 1 ? $img : $img_no) . '"/>' . __(
1352
+ 'Registration forms',
1353
+ 'cleantalk-spam-protect'
1354
+ );
1355
+ echo '<img class="apbct_status_icon" src="' . ($apbct->settings['forms__comments_test'] == 1 ? $img : $img_no) . '"/>' . __(
1356
+ 'Comments forms',
1357
+ 'cleantalk-spam-protect'
1358
+ );
1359
+ echo '<img class="apbct_status_icon" src="' . ($apbct->settings['forms__contact_forms_test'] == 1 ? $img : $img_no) . '"/>' . __(
1360
+ 'Contact forms',
1361
+ 'cleantalk-spam-protect'
1362
+ );
1363
+ echo '<img class="apbct_status_icon" src="' . ($apbct->settings['forms__general_contact_forms_test'] == 1 ? $img : $img_no) . '"/>' . __(
1364
+ 'Custom contact forms',
1365
+ 'cleantalk-spam-protect'
1366
+ );
1367
+ if ( ! $apbct->white_label || is_main_site() ) {
1368
+ echo '<img class="apbct_status_icon" src="' . ($apbct->data['moderate'] == 1 ? $img : $img_no) . '"/>'
1369
+ . '<a style="color: black" href="https://blog.cleantalk.org/real-time-email-address-existence-validation/">' . __(
1370
+ 'Validate email for existence',
1371
+ 'cleantalk-spam-protect'
1372
+ ) . '</a>';
1373
+ }
1374
+ // Autoupdate status
1375
+ if ( $apbct->notice_auto_update && ( ! $apbct->white_label || is_main_site()) ) {
1376
+ echo '<img class="apbct_status_icon" src="' . ($apbct->auto_update == 1 ? $img : ($apbct->auto_update == -1 ? $img_no : $img_no_gray)) . '"/>' . __(
1377
+ 'Auto update',
1378
+ 'cleantalk-spam-protect'
1379
+ )
1380
+ . ' <sup><a href="https://cleantalk.org/help/cleantalk-auto-update" target="_blank">?</a></sup>';
1381
+ }
1382
+
1383
+ // WooCommerce
1384
+ if ( class_exists('WooCommerce') ) {
1385
+ echo '<img class="apbct_status_icon" src="' . ($apbct->settings['forms__wc_checkout_test'] == 1 ? $img : $img_no) . '"/>' . __(
1386
+ 'WooCommerce checkout form',
1387
+ 'cleantalk-spam-protect'
1388
+ );
1389
+ }
1390
+ if ( $apbct->moderate_ip ) {
1391
+ print "<br /><br />The anti-spam service is paid by your hosting provider. License #" . $apbct->data['ip_license'] . ".<br />";
1392
+ }
1393
+
1394
+ print "</div>";
1395
  }
1396
 
1397
  /**
1398
  * Admin callback function - Displays inputs of 'apikey' plugin parameter
1399
  */
1400
+ function apbct_settings__field__apikey()
1401
+ {
1402
+ global $apbct;
1403
+
1404
+ echo '<div id="cleantalk_apikey_wrapper" class="apbct_settings-field_wrapper">';
1405
+
1406
+ // Using key from Main site, or from CLEANTALK_ACCESS_KEY constant
1407
+ if ( APBCT_WPMS && ! is_main_site() && ( ! $apbct->allow_custom_key || defined('CLEANTALK_ACCESS_KEY')) ) {
1408
+ _e('<h3>Access key is provided by network administrator</h3>', 'cleantalk-spam-protect');
1409
+
1410
+ return;
1411
+ }
1412
+
1413
+ echo '<label class="apbct_settings__label" for="cleantalk_apkey">' . __(
1414
+ 'Access key',
1415
+ 'cleantalk-spam-protect'
1416
+ ) . '</label>';
1417
+
1418
+ echo '<input
1419
  id="apbct_setting_apikey"
1420
  class="apbct_setting_text apbct_setting---apikey"
1421
  type="text"
1422
  name="cleantalk_settings[apikey]"
1423
  value="'
1424
+ . ($apbct->key_is_ok
1425
+ ? str_repeat('*', strlen($apbct->api_key))
1426
+ : $apbct->api_key
1427
+ )
1428
+ . '"
1429
  key="' . $apbct->api_key . '"
1430
  size="20"
1431
  placeholder="' . __('Enter the key', 'cleantalk-spam-protect') . '"'
1432
+ . ' />';
1433
+
1434
+ // Show account name associated with key
1435
+ if ( ! empty($apbct->data['account_name_ob']) ) {
1436
+ echo '<div class="apbct_display--none">'
1437
+ . sprintf(
1438
+ __('Account at cleantalk.org is %s.', 'cleantalk-spam-protect'),
1439
+ '<b>' . $apbct->data['account_name_ob'] . '</b>'
1440
+ )
1441
+ . '</div>';
1442
+ };
1443
+
1444
+ // Show key button
1445
+ if ( (apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok) ) {
1446
+ echo '<a id="apbct_showApiKey" class="ct_support_link" style="display: block" href="#">'
1447
+ . __('Show the access key', 'cleantalk-spam-protect')
1448
+ . '</a>';
1449
+ // "Auto Get Key" buttons. License agreement
1450
+ } else {
1451
+ echo '<br /><br />';
1452
+
1453
+ // Auto get key
1454
+ if ( ! $apbct->ip_license ) {
1455
+ echo '<button class="cleantalk_link cleantalk_link-manual apbct_setting---get_key_auto" id="apbct_button__get_key_auto" name="submit" type="button" value="get_key_auto">'
1456
+ . __('Get Access Key Automatically', 'cleantalk-spam-protect')
1457
+ . '<img style="margin-left: 10px;" class="apbct_preloader_button" src="' . APBCT_URL_PATH . '/inc/images/preloader2.gif" />'
1458
+ . '<img style="margin-left: 10px;" class="apbct_success --hide" src="' . APBCT_URL_PATH . '/inc/images/yes.png" />'
1459
+ . '</button>';
1460
+ echo '<input type="hidden" id="ct_admin_timezone" name="ct_admin_timezone" value="null" />';
1461
+ echo '<br />';
1462
+ echo '<br />';
1463
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1464
 
1465
+ // Warnings and GDPR
1466
+ printf(
1467
+ __(
1468
+ 'Admin e-mail (%s) will be used for registration, if you want to use other email please %sGet Access Key Manually%s.',
1469
+ 'cleantalk-spam-protect'
1470
+ ),
1471
+ ct_get_admin_email(),
1472
+ '<a class="apbct_color--gray" target="__blank" href="'
1473
+ . sprintf(
1474
+ 'https://cleantalk.org/register?platform=wordpress&email=%s&website=%s',
1475
+ urlencode(ct_get_admin_email()),
1476
+ urlencode(get_bloginfo('url'))
1477
+ )
1478
+ . '">',
1479
+ '</a>'
1480
+ );
1481
+
1482
+ // License agreement
1483
+ if ( ! $apbct->ip_license ) {
1484
+ echo '<div>';
1485
+ echo '<input checked type="checkbox" id="license_agreed" onclick="apbctSettingsDependencies(\'apbct_setting---get_key_auto\');"/>';
1486
+ echo '<label for="spbc_license_agreed">';
1487
+ printf(
1488
+ __('I accept %sLicense Agreement%s.', 'cleantalk-spam-protect'),
1489
+ '<a class = "apbct_color--gray" href="https://cleantalk.org/publicoffer" target="_blank">',
1490
+ '</a>'
1491
+ );
1492
+ echo "</label>";
1493
+ echo '</div>';
1494
+ }
1495
+ }
1496
 
1497
+ echo '</div>';
1498
+ }
 
 
 
 
 
 
 
1499
 
1500
+ function apbct_field_service_utilization()
1501
+ {
1502
+ global $apbct;
1503
+
1504
+ echo '<div class="apbct_wrapper_field">';
1505
+
1506
+ if ( $apbct->services_count && $apbct->services_max && $apbct->services_utilization ) {
1507
+ echo sprintf(
1508
+ __('Hoster account utilization: %s%% ( %s of %s websites ).', 'cleantalk-spam-protect'),
1509
+ $apbct->services_utilization * 100,
1510
+ $apbct->services_count,
1511
+ $apbct->services_max
1512
+ );
1513
+
1514
+ // Link to the dashboard, so user could extend your subscription for more sites
1515
+ if ( $apbct->services_utilization * 100 >= 90 ) {
1516
+ echo '&nbsp';
1517
+ echo sprintf(
1518
+ __('You could extend your subscription %shere%s.', 'cleantalk-spam-protect'),
1519
+ '<a href="' . $apbct->dashboard_link . '" target="_blank">',
1520
+ '</a>'
1521
+ );
1522
+ }
1523
+ } else {
1524
+ _e(
1525
+ 'Enter the Hoster API key and synchronize with cloud to find out your hoster account utilization.',
1526
+ 'cleantalk-spam-protect'
1527
+ );
1528
+ }
1529
 
1530
+ echo '</div>';
1531
  }
1532
 
1533
+ function apbct_settings__field__action_buttons()
1534
+ {
1535
+ global $apbct;
1536
+
1537
+ $links = apply_filters(
1538
+ 'apbct_settings_action_buttons',
1539
+ array(
1540
+ '<a href="edit-comments.php?page=ct_check_spam" class="ct_support_link">' . __(
1541
+ 'Check comments for spam',
1542
+ 'cleantalk-spam-protect'
1543
+ ) . '</a>',
1544
+ '<a href="users.php?page=ct_check_users" class="ct_support_link">' . __(
1545
+ 'Check users for spam',
1546
+ 'cleantalk-spam-protect'
1547
+ ) . '</a>',
1548
+ '<a href="#" class="ct_support_link" onclick="apbct_show_hide_elem(\'apbct_statistics\')">' . __(
1549
+ 'Statistics & Reports',
1550
+ 'cleantalk-spam-protect'
1551
+ ) . '</a>',
1552
+ )
1553
+ );
1554
+
1555
+ echo '<div class="apbct_settings-field_wrapper">';
1556
+
1557
+ if ( apbct_api_key__is_correct($apbct->api_key) && $apbct->key_is_ok ) {
1558
+ echo '<div>';
1559
+ foreach ( $links as $link ) {
1560
+ echo $link . '&nbsp;&nbsp;&nbsp;&nbsp;';
1561
+ }
1562
+ echo '</div>';
1563
+ }
1564
+
1565
+ echo '</div>';
1566
  }
1567
 
1568
+ function apbct_settings__field__statistics()
1569
+ {
1570
+ global $apbct;
1571
+
1572
+ echo '<div id="apbct_statistics" class="apbct_settings-field_wrapper" style="display: none;">';
1573
+
1574
+ // Last request
1575
+ printf(
1576
+ __('Last spam check request to %s server was at %s.', 'cleantalk-spam-protect'),
1577
+ $apbct->stats['last_request']['server'] ? $apbct->stats['last_request']['server'] : __(
1578
+ 'unknown',
1579
+ 'cleantalk-spam-protect'
1580
+ ),
1581
+ $apbct->stats['last_request']['time'] ? date('M d Y H:i:s', $apbct->stats['last_request']['time']) : __(
1582
+ 'unknown',
1583
+ 'cleantalk-spam-protect'
1584
+ )
1585
+ );
1586
+ echo '<br>';
1587
+
1588
+ // Avarage time request
1589
+ printf(
1590
+ __('Average request time for past 7 days: %s seconds.', 'cleantalk-spam-protect'),
1591
+ $apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time']
1592
+ ? round($apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]['average_time'], 3)
1593
+ : __('unknown', 'cleantalk-spam-protect')
1594
+ );
1595
+ echo '<br>';
1596
+
1597
+ // SFW last die
1598
+ printf(
1599
+ __('Last time SpamFireWall was triggered for %s IP at %s', 'cleantalk-spam-protect'),
1600
+ $apbct->stats['last_sfw_block']['ip'] ? $apbct->stats['last_sfw_block']['ip'] : __(
1601
+ 'unknown',
1602
+ 'cleantalk-spam-protect'
1603
+ ),
1604
+ $apbct->stats['last_sfw_block']['time'] ? date('M d Y H:i:s', $apbct->stats['last_sfw_block']['time']) : __(
1605
+ 'unknown',
1606
+ 'cleantalk-spam-protect'
1607
+ )
1608
+ );
1609
+ echo '<br>';
1610
+
1611
+ // SFW last update
1612
+ printf(
1613
+ __('SpamFireWall was updated %s. Now contains %s entries.', 'cleantalk-spam-protect'),
1614
+ $apbct->stats['sfw']['last_update_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_update_time']) : __(
1615
+ 'unknown',
1616
+ 'cleantalk-spam-protect'
1617
+ ),
1618
+ $apbct->stats['sfw']['entries']
1619
+ );
1620
+ echo $apbct->fw_stats['firewall_updating_id'] ? ' ' . __(
1621
+ 'Under updating now:',
1622
+ 'cleantalk-spam-protect'
1623
+ ) . ' ' . $apbct->fw_stats['firewall_update_percent'] . '%' : '';
1624
+ echo '<br>';
1625
+
1626
+ // SFW last sent logs
1627
+ printf(
1628
+ __('SpamFireWall sent %s events at %s.', 'cleantalk-spam-protect'),
1629
+ $apbct->stats['sfw']['last_send_amount'] ? $apbct->stats['sfw']['last_send_amount'] : __(
1630
+ 'unknown',
1631
+ 'cleantalk-spam-protect'
1632
+ ),
1633
+ $apbct->stats['sfw']['last_send_time'] ? date('M d Y H:i:s', $apbct->stats['sfw']['last_send_time']) : __(
1634
+ 'unknown',
1635
+ 'cleantalk-spam-protect'
1636
+ )
1637
+ );
1638
+ echo '<br>';
1639
+
1640
+ // Connection reports
1641
+ if ( $apbct->connection_reports ) {
1642
+ if ( $apbct->connection_reports['negative'] == 0 ) {
1643
+ _e('There are no failed connections to server.', 'cleantalk-spam-protect');
1644
+ } else {
1645
+ echo "<table id='negative_reports_table''>
1646
  <tr>
1647
  <td>#</td>
1648
  <td><b>Date</b></td>
1650
  <td><b>Report</b></td>
1651
  <td><b>Server IP</b></td>
1652
  </tr>";
1653
+ foreach ( $apbct->connection_reports['negative_report'] as $key => $report ) {
1654
+ echo '<tr>'
1655
+ . '<td>' . ($key + 1) . '.</td>'
1656
+ . '<td>' . $report['date'] . '</td>'
1657
+ . '<td>' . $report['page_url'] . '</td>'
1658
+ . '<td>' . $report['lib_report'] . '</td>'
1659
+ . '<td>' . $report['work_url'] . '</td>'
1660
+ . '</tr>';
1661
+ }
1662
+ echo "</table>";
1663
+ echo '<br/>';
1664
+ echo '<button'
1665
+ . ' name="submit"'
1666
+ . ' class="cleantalk_link cleantalk_link-manual"'
1667
+ . ' value="ct_send_connection_report"'
1668
+ . (! $apbct->settings['misc__send_connection_reports'] ? ' disabled="disabled"' : '')
1669
+ . '>'
1670
+ . __('Send report', 'cleantalk-spam-protect')
1671
+ . '</button>';
1672
+ if ( ! $apbct->settings['misc__send_connection_reports'] ) {
1673
+ echo '<br><br>';
1674
+ _e(
1675
+ 'Please, enable "Send connection reports" setting to be able to send reports',
1676
+ 'cleantalk-spam-protect'
1677
+ );
1678
+ }
1679
+ }
1680
+ }
1681
 
1682
  echo '<br/>';
1683
+ echo 'Plugin version: ' . APBCT_VERSION;
 
 
1684
 
1685
+ echo '</div>';
1686
  }
1687
+
1688
+ function apbct_get_all_child_domains($except_main_site = false)
1689
+ {
1690
+ global $wpdb;
1691
+ $blogs = array();
1692
+ $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM ' . $wpdb->blogs, OBJECT_K);
1693
+
1694
+ if ( $except_main_site ) {
1695
+ foreach ( $wp_blogs as $blog ) {
1696
+ if ( $blog->blog_id != $blog->site_id ) {
1697
+ $blog_details = get_blog_details(array('blog_id' => $blog->blog_id));
1698
+ $blogs[] = array(
1699
+ 'val' => $blog_details->id,
1700
+ 'label' => '#' . $blog_details->id . ' ' . $blog_details->blogname
1701
+ );
1702
+ }
1703
+ }
1704
+ }
1705
+
1706
+ return $blogs;
1707
  }
1708
+
1709
  /**
1710
  * Get all current Wordpress roles, could except 'subscriber' role
1711
  *
1713
  *
1714
  * @return array
1715
  */
1716
+ function apbct_get_all_roles($except_subscriber = false)
1717
+ {
1718
+ $wp_roles = new WP_Roles();
1719
+ $roles = $wp_roles->get_names();
1720
+
1721
+ if ( $except_subscriber ) {
1722
+ $key = array_search('Subscriber', $roles);
1723
+ if ( $key !== false ) {
1724
+ unset($roles[$key]);
1725
+ }
1726
+ }
1727
+
1728
+ return $roles;
1729
  }
1730
 
1731
+ function apbct_settings__field__draw($params = array())
1732
+ {
1733
+ global $apbct;
1734
+
1735
+ $value = $params['network'] ? $apbct->network_settings[$params['name']] : $apbct->settings[$params['name']];
1736
+ $value_parent = $params['parent']
1737
+ ? ($params['network'] ? $apbct->network_settings[$params['parent']] : $apbct->settings[$params['parent']])
1738
+ : false;
1739
+
1740
+ // Is element is disabled
1741
+ $disabled = $params['parent'] && ! $value_parent ? ' disabled="disabled"' : ''; // Strait
1742
+ $disabled = $params['parent'] && $params['reverse_trigger'] && ! $value_parent ? '' : $disabled; // Reverse logic
1743
+ $disabled = $params['disabled'] ? ' disabled="disabled"' : $disabled; // Direct disable from params
1744
+ $disabled = ! is_main_site(
1745
+ ) && $apbct->network_settings && ! $apbct->network_settings['multisite__allow_custom_settings'] ? ' disabled="disabled"' : $disabled; // Disabled by super admin on sub-sites
1746
+
1747
+ $childrens = $params['childrens'] ? 'apbct_setting---' . implode(",apbct_setting---", $params['childrens']) : '';
1748
+ $hide = $params['hide'] ? implode(",", $params['hide']) : '';
1749
+
1750
+ echo '<div class="' . $params['def_class'] . (isset($params['class']) ? ' ' . $params['class'] : '') . '">';
1751
+
1752
+ switch ( $params['type'] ) {
1753
+ // Checkbox type
1754
+ case 'checkbox':
1755
+ echo '<input
1756
  type="checkbox"
1757
+ name="cleantalk_settings[' . $params['name'] . ']"
1758
+ id="apbct_setting_' . $params['name'] . '"
1759
  value="1" '
1760
+ . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1761
+ . ($value == '1' ? ' checked' : '')
1762
+ . $disabled
1763
+ . ($params['required'] ? ' required="required"' : '')
1764
+ . ($params['childrens'] ? ' apbct_children="' . $childrens . '"' : '')
1765
+ . ' onchange="'
1766
+ . ($params['childrens'] ? ' apbctSettingsDependencies(\'' . $childrens . '\');' : '')
1767
+ . ($params['hide'] ? ' apbct_show_hide_elem(\'' . $hide . '\');' : '')
1768
+ . '"'
1769
+ . ' />'
1770
+ . '<label for="apbct_setting_' . $params['name'] . '" class="apbct_setting-field_title--' . $params['type'] . '">'
1771
+ . $params['title']
1772
+ . '</label>';
1773
+ echo isset($params['long_description'])
1774
+ ? '<i setting="' . $params['name'] . '" class="apbct_settings-long_description---show icon-help-circled"></i>'
1775
+ : '';
1776
+ echo '<div class="apbct_settings-field_description">'
1777
+ . $params['description']
1778
+ . '</div>';
1779
+ break;
1780
+
1781
+ // Radio type
1782
+ case 'radio':
1783
+ // Title
1784
+ echo isset($params['title'])
1785
+ ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--' . $params['type'] . '">' . $params['title'] . '</h4>'
1786
+ : '';
1787
+
1788
+ // Popup description
1789
+ echo isset($params['long_description'])
1790
+ ? '<i setting="' . $params['name'] . '" class="apbct_settings-long_description---show icon-help-circled"></i>'
1791
+ : '';
1792
+
1793
+ echo '<div class="apbct_settings-field_content apbct_settings-field_content--' . $params['type'] . '">';
1794
+
1795
+ echo '<div class="apbct_switchers" style="direction: ltr">';
1796
+ foreach ( $params['options'] as $option ) {
1797
+ echo '<input'
1798
+ . ' type="radio"'
1799
+ . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1800
+ . " id='apbct_setting_{$params['name']}__{$option['label']}'"
1801
+ . ' name="cleantalk_settings[' . $params['name'] . ']"'
1802
+ . ' value="' . $option['val'] . '"'
1803
+ . $disabled
1804
+ . ($params['childrens']
1805
+ ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\', ' . $option['childrens_enable'] . ')"'
1806
+ : ''
1807
+ )
1808
+ . ($value == $option['val'] ? ' checked' : '')
1809
+ . ($params['required'] ? ' required="required"' : '')
1810
+ . ' />';
1811
+ echo '<label for="apbct_setting_' . $params['name'] . '__' . $option['label'] . '"> ' . $option['label'] . '</label>';
1812
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1813
+ }
1814
+ echo '</div>';
1815
+
1816
+ echo isset($params['description'])
1817
+ ? '<div class="apbct_settings-field_description">' . $params['description'] . '</div>'
1818
+ : '';
1819
+
1820
+ echo '</div>';
1821
+ break;
1822
+
1823
+ // Dropdown list type
1824
+ case 'select':
1825
+ echo isset($params['title'])
1826
+ ? '<h4 class="apbct_settings-field_title apbct_settings-field_title--' . $params['type'] . '">' . $params['title'] . '</h4>'
1827
+ : '';
1828
+ echo '<select'
1829
+ . ' id="apbct_setting_' . $params['name'] . '"'
1830
+ . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1831
+ . ' name="cleantalk_settings[' . $params['name'] . ']' . ($params['multiple'] ? '[]"' : '"')
1832
+ . ($params['multiple'] ? ' size="' . count($params['options']) . '""' : '')
1833
+ . ($params['multiple'] ? ' multiple="multiple"' : '')
1834
+ . ($params['childrens']
1835
+ ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\', jQuery(this).find(\'option:selected\').data(\'children_enable\'))"'
1836
+ : ''
1837
+ )
1838
+ . $disabled
1839
+ . ($params['required'] ? ' required="required"' : '')
1840
+ . ' >';
1841
+
1842
+ foreach ( $params['options'] as $option ) {
1843
+ echo '<option'
1844
+ . ' value="' . $option['val'] . '"'
1845
+ . (isset($option['children_enable']) ? ' data-children_enable=' . $option['children_enable'] . ' ' : ' ')
1846
+ . ($params['multiple']
1847
+ ? (! empty($value) && in_array($option['val'], $value) ? ' selected="selected"' : '')
1848
+ : ($value == $option['val'] ? 'selected="selected"' : '')
1849
+ )
1850
+ . '>'
1851
+ . $option['label']
1852
+ . '</option>';
1853
+ }
1854
+
1855
+ echo '</select>';
1856
+ echo isset($params['long_description'])
1857
+ ? '<i setting="' . $params['name'] . '" class="apbct_settings-long_description---show icon-help-circled"></i>'
1858
+ : '';
1859
+ echo isset($params['description'])
1860
+ ? '<div class="apbct_settings-field_description">' . $params['description'] . '</div>'
1861
+ : '';
1862
+
1863
+ break;
1864
+
1865
+ // Text type
1866
+ case 'text':
1867
+ echo '<input
 
 
1868
  type="text"
1869
+ id="apbct_setting_' . $params['name'] . '"
1870
+ name="cleantalk_settings[' . $params['name'] . ']"'
1871
+ . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1872
+ . ' value="' . $value . '" '
1873
+ . $disabled
1874
+ . ($params['required'] ? ' required="required"' : '')
1875
+ . ($params['childrens'] ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\')"' : '')
1876
+ . ' />'
1877
+ . '&nbsp;'
1878
+ . '<label for="apbct_setting_' . $params['name'] . '" class="apbct_setting-field_title--' . $params['type'] . '">'
1879
+ . $params['title']
1880
+ . '</label>';
1881
+ echo '<div class="apbct_settings-field_description">'
1882
+ . $params['description']
1883
+ . '</div>';
1884
+ break;
1885
+
1886
+ // Textarea type
1887
+ case 'textarea':
1888
+ echo '<label for="apbct_setting_' . $params['name'] . '" class="apbct_setting-field_title--' . $params['type'] . '">'
1889
+ . $params['title']
1890
+ . '</label></br>';
1891
+ echo '<textarea
1892
+ id="apbct_setting_' . $params['name'] . '"
1893
+ name="cleantalk_settings[' . $params['name'] . ']"'
1894
+ . " class='apbct_setting_{$params['type']} apbct_setting---{$params['name']}'"
1895
+ . $disabled
1896
+ . ($params['required'] ? ' required="required"' : '')
1897
+ . ($params['childrens'] ? ' onchange="apbctSettingsDependencies(\'' . $childrens . '\')"' : '')
1898
+ . '>' . $value . '</textarea>'
1899
+ . '&nbsp;';
1900
+ echo '<div class="apbct_settings-field_description">'
1901
+ . $params['description']
1902
+ . '</div>';
1903
+ break;
1904
+ }
1905
+
1906
+ echo '</div>';
 
 
1907
  }
1908
 
1909
  /**
1910
  * Admin callback function - Plugin parameters validator
1911
+ *
 
1912
  * @param array $settings Array with passed settings
1913
+ *
1914
  * @return array Array with processed settings
1915
+ * @global \Cleantalk\ApbctWP\State $apbct
1916
  */
1917
+ function apbct_settings__validate($settings)
1918
+ {
1919
+ global $apbct;
1920
+
1921
+ // If user is not allowed to manage settings. Get settings from the storage
1922
+ if ( ! is_main_site() && ! $apbct->network_settings['multisite__allow_custom_settings'] ) {
1923
+ foreach ( $apbct->settings as $key => $setting ) {
1924
+ // Do not reset apikey to default is allow_custom_key is active
1925
+ if ( $key === 'apikey' && $apbct->allow_custom_key ) {
1926
+ continue;
1927
+ }
1928
+ $settings[$key] = $setting;
1929
+ }
1930
+ }
1931
+
1932
+ // Set missing settings.
1933
+ foreach ( $apbct->def_settings as $setting => $value ) {
1934
+ if ( ! isset($settings[$setting]) ) {
1935
+ $settings[$setting] = null;
1936
+ settype($settings[$setting], gettype($value));
1937
+ }
1938
+ }
1939
+ unset($setting, $value);
1940
+
1941
+ // Set missing network settings.
1942
+ foreach ( $apbct->def_network_settings as $setting => $value ) {
1943
+ if ( ! isset($settings[$setting]) ) {
1944
+ $settings[$setting] = null;
1945
+ settype($settings[$setting], gettype($value));
1946
+ }
1947
+ }
1948
+ unset($setting, $value);
1949
+
1950
+ // Actions with toggle SFW settings
1951
  // SFW was enabled
1952
+ if ( ! $apbct->settings['sfw__enabled'] && $settings['sfw__enabled'] ) {
1953
+ apbct_sfw_update__init(3);
1954
+ // SFW was disabled
1955
+ } elseif ( $apbct->settings['sfw__enabled'] && ! $settings['sfw__enabled'] ) {
 
1956
  apbct_sfw__clear();
1957
  }
1958
+
1959
+ //Sanitizing sfw__anti_flood__view_limit setting
1960
+ $settings['sfw__anti_flood__view_limit'] = floor(intval($settings['sfw__anti_flood__view_limit']));
1961
+ $settings['sfw__anti_flood__view_limit'] = ($settings['sfw__anti_flood__view_limit'] == 0 ? 20 : $settings['sfw__anti_flood__view_limit']); // Default if 0 passed
1962
+ $settings['sfw__anti_flood__view_limit'] = ($settings['sfw__anti_flood__view_limit'] < 5 ? 5 : $settings['sfw__anti_flood__view_limit']); //
1963
+
1964
+ // Validating API key
1965
+ $settings['apikey'] = strpos($settings['apikey'], '*') === false ? $settings['apikey'] : $apbct->settings['apikey'];
1966
+
1967
+ $apbct->data['key_changed'] = $settings['apikey'] !== $apbct->settings['apikey'];
1968
+
1969
+ $settings['apikey'] = ! empty($settings['apikey']) ? trim($settings['apikey']) : '';
1970
+ $settings['apikey'] = defined('CLEANTALK_ACCESS_KEY') ? CLEANTALK_ACCESS_KEY : $settings['apikey'];
1971
+ $settings['apikey'] = ! is_main_site() && $apbct->white_label && $apbct->settings['apikey'] ? $apbct->settings['apikey'] : $settings['apikey'];
1972
+ $settings['apikey'] = is_main_site() || $apbct->allow_custom_key || $apbct->white_label ? $settings['apikey'] : $apbct->network_settings['apikey'];
1973
+ $settings['apikey'] = is_main_site() || ! $settings['multisite__white_label'] ? $settings['apikey'] : $apbct->settings['apikey'];
1974
+
1975
+ // Show notice if the api key is empty
1976
+ if ( ! apbct_api_key__is_correct() ) {
1977
+ $apbct->data['key_is_ok'] = false;
1978
+ $apbct->data['notice_show'] = 1;
1979
+ } else {
1980
+ // Key is good by default
1981
+ $apbct->data['key_is_ok'] = true;
1982
+ }
1983
+
1984
+ // Sanitize setting values
1985
+ foreach ( $settings as &$setting ) {
1986
+ if ( is_string($setting) ) {
1987
+ $setting = preg_replace('/[<"\'>]/', '', trim($setting));
1988
+ } // Make HTML code inactive
1989
+ }
1990
+
1991
+ // Validate Exclusions
1992
+ // URLs
1993
+ $result = apbct_settings__sanitize__exclusions(
1994
+ $settings['exclusions__urls'],
1995
+ $settings['exclusions__urls__use_regexp']
1996
+ );
1997
+ $result === false
1998
+ ? $apbct->errorAdd(
1999
+ 'exclusions_urls',
2000
+ 'is not valid: "' . $settings['exclusions__urls'] . '"',
2001
+ 'settings_validate'
2002
+ )
2003
+ : $apbct->errorDelete('exclusions_urls', true, 'settings_validate');
2004
+ $settings['exclusions__urls'] = $result ? $result : '';
2005
+
2006
+ // Fields
2007
+ $result = apbct_settings__sanitize__exclusions(
2008
+ $settings['exclusions__fields'],
2009
+ $settings['exclusions__fields__use_regexp']
2010
+ );
2011
+ $result === false
2012
+ ? $apbct->errorAdd(
2013
+ 'exclusions_fields',
2014
+ 'is not valid: "' . $settings['exclusions__fields'] . '"',
2015
+ 'settings_validate'
2016
+ )
2017
+ : $apbct->errorDelete('exclusions_fields', true, 'settings_validate');
2018
+ $settings['exclusions__fields'] = $result ? $result : '';
2019
+
2020
+ // WPMS Logic.
2021
+ if ( APBCT_WPMS && is_main_site() ) {
2022
+ $network_settings = array(
2023
+ 'multisite__allow_custom_settings' => $settings['multisite__allow_custom_settings'],
2024
+ 'multisite__white_label' => $settings['multisite__white_label'],
2025
+ 'multisite__white_label__plugin_name' => $settings['multisite__white_label__plugin_name'],
2026
+ 'multisite__use_settings_template' => $settings['multisite__use_settings_template'],
2027
+ 'multisite__use_settings_template_apply_for_new' => $settings['multisite__use_settings_template_apply_for_new'],
2028
+ 'multisite__use_settings_template_apply_for_current' => $settings['multisite__use_settings_template_apply_for_current'],
2029
+ 'multisite__use_settings_template_apply_for_current_list_sites' => $settings['multisite__use_settings_template_apply_for_current_list_sites'],
2030
+ );
2031
+ unset($settings['multisite__white_label'], $settings['multisite__white_label__plugin_name']);
2032
+
2033
+ if ( isset($settings['multisite__hoster_api_key']) ) {
2034
+ $network_settings['multisite__hoster_api_key'] = $settings['multisite__hoster_api_key'];
2035
+ unset($settings['multisite__hoster_api_key']);
2036
+ }
2037
+
2038
+ if ( isset($settings['multisite__work_mode']) ) {
2039
+ $network_settings['multisite__work_mode'] = $settings['multisite__work_mode'];
2040
+ unset($settings['multisite__work_mode']);
2041
+ }
2042
+ }
2043
+
2044
+ // Drop debug data
2045
+ if ( Post::get('submit') === 'debug_drop' ) {
2046
+ $apbct->debug = false;
2047
+ delete_option('cleantalk_debug');
2048
+
2049
+ return $settings;
2050
+ }
2051
+
2052
  // Test connections to servers
2053
+ if ( Post::get('apbct_debug__check_connection') ) {
2054
  $result = apbct_test_connection();
2055
  apbct_log($result);
2056
  }
2057
+
2058
+ // Send connection reports
2059
+ if ( Post::get('submit') === 'ct_send_connection_report' ) {
2060
+ ct_mail_send_connection_report();
2061
+
2062
+ return $settings;
2063
+ }
2064
+
2065
+ $apbct->save('data');
2066
+
2067
+ // WPMS Logic.
2068
+ if ( APBCT_WPMS ) {
2069
+ if ( is_main_site() ) {
2070
+ // Network settings
2071
+ $network_settings['apikey'] = $settings['apikey'];
2072
+ $apbct->network_settings = $network_settings;
2073
+ $apbct->saveNetworkSettings();
2074
+
2075
+ // Network data
2076
+ $apbct->network_data = array(
2077
+ 'key_is_ok' => $apbct->data['key_is_ok'],
2078
+ 'moderate' => $apbct->data['moderate'],
2079
+ 'valid' => isset($apbct->data['valid']) ? $apbct->data['valid'] : 0,
2080
+ 'auto_update' => $apbct->data['auto_update'],
2081
+ 'user_token' => $apbct->data['user_token'],
2082
+ 'service_id' => $apbct->data['service_id'],
2083
+ );
2084
+ $apbct->saveNetworkData();
2085
+ if ( isset($settings['multisite__use_settings_template_apply_for_current_list_sites']) && ! empty($settings['multisite__use_settings_template_apply_for_current_list_sites']) ) {
2086
+ apbct_update_blogs_options($settings);
2087
+ }
2088
+ }
2089
+ if ( ! $apbct->white_label && ! is_main_site() && ! $apbct->allow_custom_key ) {
2090
+ $settings['apikey'] = '';
2091
+ }
2092
+ }
2093
+
2094
+ // Alt sessions table clearing
2095
+ if ( $settings['data__set_cookies'] != 2 ) {
2096
  \Cleantalk\ApbctWP\Variables\AltSessions::wipe();
2097
  }
2098
+
2099
+ // Set type of the alt cookies
2100
+ if ( $apbct->settings['data__set_cookies'] != 2 && $settings['data__set_cookies'] == 2 ) {
2101
+ $alt_cookies_type = apbct_settings__get_alt_cookies_type();
2102
+ if ( $alt_cookies_type === false ) {
2103
+ // There is no available alt cookies types. Cookies will be disabled.
2104
+ $settings['data__set_cookies'] = 0;
2105
+ } else {
2106
+ $settings['data__set_cookies__alt_sessions_type'] = $alt_cookies_type;
2107
+ }
2108
+ }
2109
+
2110
+ return $settings;
2111
  }
2112
 
2113
+ function apbct_settings__sync($direct_call = false)
2114
+ {
2115
+ if ( ! $direct_call ) {
2116
+ check_ajax_referer('ct_secret_nonce');
2117
+ }
2118
+
2119
+ global $apbct;
2120
+
2121
+ //Clearing all errors
2122
+ $apbct->errorDeleteAll('and_save_data');
2123
+
2124
+ // Feedback with app_agent
2125
+ ct_send_feedback('0:' . APBCT_AGENT); // 0 - request_id, agent version.
2126
+
2127
+ // Key is good by default
2128
+ $apbct->data['key_is_ok'] = true;
2129
+
2130
+ // Checking account status
2131
+ $result = ct_account_status_check($apbct->settings['apikey']);
2132
+
2133
+ // Is key valid?
2134
+ if ( $result ) {
2135
+ // Deleting errors about invalid key
2136
+ $apbct->errorDelete('key_invalid key_get', 'save');
2137
+
2138
+ // SFW actions
2139
+ if ( $apbct->settings['sfw__enabled'] == 1 ) {
2140
+ $result = apbct_sfw_update__init(5);
2141
+ if ( ! empty($result['error']) ) {
2142
+ $apbct->errorAdd('sfw_update', $result['error']);
2143
+ }
2144
+
2145
+ $result = ct_sfw_send_logs($apbct->settings['apikey']);
2146
+ if ( ! empty($result['error']) ) {
2147
+ $apbct->errorAdd('sfw_send_logs', $result['error']);
2148
+ }
2149
+ }
2150
+
2151
+ // Updating brief data for dashboard widget
2152
+ cleantalk_get_brief_data($apbct->settings['apikey']);
2153
+ // Key is not valid
2154
+ } else {
2155
+ $apbct->data['key_is_ok'] = false;
2156
+ $apbct->errorAdd(
2157
+ 'key_invalid',
2158
+ __('Testing is failed. Please check the Access key.', 'cleantalk-spam-protect')
2159
+ );
2160
+ }
2161
+
2162
+ // WPMS Logic.
2163
+ if ( APBCT_WPMS ) {
2164
+ if ( is_main_site() ) {
2165
+ // Network settings
2166
+ $apbct->network_settings['apikey'] = $apbct->settings['apikey'];
2167
+ $apbct->saveNetworkSettings();
2168
+
2169
+ // Network data
2170
+ $apbct->network_data = array(
2171
+ 'key_is_ok' => $apbct->data['key_is_ok'],
2172
+ 'moderate' => $apbct->data['moderate'],
2173
+ 'valid' => $apbct->data['valid'],
2174
+ 'auto_update' => $apbct->data['auto_update'],
2175
+ 'user_token' => $apbct->data['user_token'],
2176
+ 'service_id' => $apbct->data['service_id'],
2177
+ );
2178
+
2179
+ if ( $apbct->network_settings['multisite__work_mode'] == 1 ) {
2180
+ $apbct->data['services_count '] = isset($result['services_count']) ? $result['services_count'] : '';
2181
+ $apbct->data['services_max'] = isset($result['services_max']) ? $result['services_max'] : '';
2182
+ $apbct->data['services_utilization'] = isset($result['services_utilization']) ? $result['services_utilization'] : '';
2183
+ }
2184
+
2185
+ $apbct->saveNetworkData();
2186
+ if ( isset($apbct->settings['multisite__use_settings_template_apply_for_current_list_sites']) && ! empty($apbct->settings['multisite__use_settings_template_apply_for_current_list_sites']) ) {
2187
+ apbct_update_blogs_options($apbct->settings);
2188
+ }
2189
+ }
2190
+ if ( ! $apbct->white_label && ! is_main_site() && ! $apbct->allow_custom_key ) {
2191
+ $apbct->settings['apikey'] = '';
2192
+ }
2193
+ }
2194
+
2195
+ if ( $apbct->data['key_is_ok'] == false && $apbct->data['moderate_ip'] == 0 ) {
2196
+ // Notices
2197
+ $apbct->data['notice_show'] = 1;
2198
+ $apbct->data['notice_renew'] = 0;
2199
+ $apbct->data['notice_trial'] = 0;
2200
+ $apbct->data['notice_review'] = 0;
2201
+ $apbct->data['notice_auto_update'] = 0;
2202
+
2203
+ // Other
2204
+ $apbct->data['service_id'] = 0;
2205
+ $apbct->data['valid'] = 0;
2206
+ $apbct->data['moderate'] = 0;
2207
+ $apbct->data['ip_license'] = 0;
2208
+ $apbct->data['moderate_ip'] = 0;
2209
+ $apbct->data['spam_count'] = 0;
2210
+ $apbct->data['auto_update'] = 0;
2211
+ $apbct->data['user_token'] = '';
2212
+ $apbct->data['license_trial'] = 0;
2213
+ $apbct->data['account_name_ob'] = '';
2214
+ }
2215
+
2216
+ $out = array(
2217
+ 'success' => true,
2218
+ 'reload' => isset($apbct->data['key_changed']) ? $apbct->data['key_changed'] : 0,
2219
+ );
2220
+
2221
+ $apbct->data['key_changed'] = false;
2222
+
2223
+ $apbct->saveData();
2224
+
2225
+ die(json_encode($out));
2226
  }
2227
 
2228
+ function apbct_settings__get_key_auto($direct_call = false)
2229
+ {
2230
+ if ( ! $direct_call ) {
2231
+ check_ajax_referer('ct_secret_nonce');
2232
+ }
2233
+
2234
+ global $apbct;
2235
+
2236
+ $website = parse_url(get_option('siteurl'), PHP_URL_HOST) . parse_url(get_option('siteurl'), PHP_URL_PATH);
2237
+ $platform = 'wordpress';
2238
+ $user_ip = \Cleantalk\ApbctWP\Helper::ipGet('real', false);
2239
+ $timezone = filter_input(INPUT_POST, 'ct_admin_timezone');
2240
+ $language = apbct_get_server_variable('HTTP_ACCEPT_LANGUAGE');
2241
+ $wpms = APBCT_WPMS && defined('SUBDOMAIN_INSTALL') && ! SUBDOMAIN_INSTALL ? true : false;
2242
+ $white_label = $apbct->network_settings['multisite__white_label'] ? true : false;
2243
+ $hoster_api_key = $apbct->network_settings['multisite__hoster_api_key'];
2244
+ $admin_email = $apbct->network_settings['multisite__work_mode'] == 1 ? get_site_option(
2245
+ 'admin_email'
2246
+ ) : get_option('admin_email');
2247
+ if ( function_exists('is_multisite') && is_multisite() && $apbct->white_label ) {
2248
+ $admin_email = get_site_option('admin_email');
2249
+ }
2250
+ $result = \Cleantalk\ApbctWP\API::methodGetApiKey(
2251
+ 'antispam',
2252
+ $admin_email,
2253
+ $website,
2254
+ $platform,
2255
+ $timezone,
2256
+ $language,
2257
+ $user_ip,
2258
+ $wpms,
2259
+ $white_label,
2260
+ $hoster_api_key
2261
+ );
2262
+
2263
+ if ( empty($result['error']) ) {
2264
+ if ( isset($result['user_token']) ) {
2265
+ $apbct->data['user_token'] = $result['user_token'];
2266
+ }
2267
+
2268
+ if ( ! empty($result['auth_key']) ) {
2269
+ // @ToDo we have to sanitize only api key. Not need to sanitize every settings here.
2270
+ $settings = apbct_settings__validate(array(
2271
+ 'apikey' => $result['auth_key'],
2272
+ ));
2273
+ $apbct->settings['apikey'] = $settings['apikey'];
2274
+ }
2275
+
2276
+ $templates = \Cleantalk\ApbctWP\CleantalkSettingsTemplates::getOptionsTemplate($result['auth_key']);
2277
+
2278
+ if ( ! empty($templates) ) {
2279
+ $templatesObj = new \Cleantalk\ApbctWP\CleantalkSettingsTemplates($result['auth_key']);
2280
+ $out = array(
2281
+ 'success' => true,
2282
+ 'getTemplates' => $templatesObj->getHtmlContent(true),
2283
+ );
2284
+ } else {
2285
+ $out = array(
2286
+ 'success' => true,
2287
+ 'reload' => true,
2288
+ );
2289
+ }
2290
+ } else {
2291
+ $apbct->errorAdd(
2292
+ 'key_get',
2293
+ $result['error']
2294
+ . ($apbct->white_label
2295
+ ? ' <button name="submit" type="button" id="apbct_button__get_key_auto" class="cleantalk_link cleantalk_link-manual" value="get_key_auto">'
2296
+ : ''
2297
+ )
2298
+ );
2299
+ $apbct->saveErrors();
2300
+ $out = array(
2301
+ 'success' => true,
2302
+ 'reload' => false,
2303
+ );
2304
+ }
2305
+
2306
+ $apbct->saveSettings();
2307
+ $apbct->saveData();
2308
+
2309
+ if ( $direct_call ) {
2310
+ return $result;
2311
+ } else {
2312
+ die(json_encode($out));
2313
+ }
2314
  }
2315
 
2316
+ function apbct_update_blogs_options($settings)
2317
+ {
2318
+ global $wpdb;
2319
+
2320
  $blog_names = $settings['multisite__use_settings_template_apply_for_current_list_sites'] ?: array();
2321
+
2322
+ $wp_blogs = $wpdb->get_results('SELECT blog_id, site_id FROM ' . $wpdb->blogs, OBJECT_K);
2323
+
2324
+ foreach ( $wp_blogs as $blog ) {
2325
+ $blog_name = get_blog_details(array('blog_id' => $blog->blog_id))->blogname;
2326
+ if ( in_array($blog_name, $blog_names) ) {
2327
+ update_blog_option($blog->blog_id, 'cleantalk_settings', $settings);
2328
+ }
2329
+ }
2330
  }
2331
+
2332
  /**
2333
  * Sanitize and validate exclusions.
2334
  * Explode given string by commas and trim each string.
2338
  * Return sanitized string if all is ok
2339
  *
2340
  * @param string $exclusions
2341
+ * @param bool $regexp
2342
  *
2343
  * @return bool|string
2344
  */
2345
+ function apbct_settings__sanitize__exclusions($exclusions, $regexp = false)
2346
+ {
2347
+ $result = array();
2348
+ $type = 0;
2349
+ if ( ! empty($exclusions) ) {
2350
+ if ( strpos($exclusions, "\r\n") !== false ) {
2351
+ $exclusions = explode("\r\n", $exclusions);
2352
+ $type = 2;
2353
+ } elseif ( strpos($exclusions, "\n") !== false ) {
2354
+ $exclusions = explode("\n", $exclusions);
2355
+ $type = 1;
2356
  } else {
2357
+ $exclusions = explode(',', $exclusions);
2358
  }
2359
+ foreach ( $exclusions as $exclusion ) {
2360
+ $sanitized_exclusion = trim($exclusion, " \t\n\r\0\x0B/\/");
2361
+ if ( ! empty($sanitized_exclusion) ) {
2362
+ if ( $regexp && ! apbct_is_regexp($exclusion) ) {
2363
+ return false;
2364
+ }
2365
+ $result[] = $sanitized_exclusion;
2366
+ }
2367
+ }
2368
+ }
2369
+ switch ( $type ) {
2370
+ case 0:
2371
+ default:
2372
+ return implode(',', $result);
2373
+ case 1:
2374
+ return implode("\n", $result);
2375
+ case 2:
2376
+ return implode("\r\n", $result);
2377
  }
2378
  }
2379
 
2380
+ function apbct_settings_show_gdpr_text($print = false)
2381
+ {
2382
+ $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.
2383
  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.
2384
  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).
2385
  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).
2386
  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.
2387
  They have to be appointed:')
2388
+ . '<ul style="padding: 0px 25px; list-style: disc;">'
2389
+ . '<li>for all public authorities, except for courts acting in their judicial capacity</li>'
2390
+ . '<li>if the core activities of the controller or the processor are:</li>'
2391
+ . '<ul style="padding: 0px 25px; list-style: disc;">'
2392
+ . '<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>'
2393
+ . '<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>'
2394
+ . '</ul>'
2395
+ . '</li>'
2396
+ . '</ul>';
2397
+
2398
+ if ( $print ) {
2399
+ echo $out;
2400
+ } else {
2401
+ return $out;
2402
+ }
2403
+ }
2404
+
2405
+ function apbct_settings__get__long_description()
2406
+ {
2407
+ check_ajax_referer('ct_secret_nonce');
2408
+
2409
+ $setting_id = $_POST['setting_id'] ?: '';
2410
+
2411
+ $descriptions = array(
2412
+ 'multisite__work_mode' => array(
2413
+ 'title' => __('Wordpress Multisite Work Mode', 'cleantalk-spam-protect'),
2414
+ 'desc' => __(
2415
+ '<h4>Mutual Account, Individual Access Keys</h4>'
2416
+ . '<span>Each blog uses a separate key from the network administrator account. Each blog has its own separate security log, settings, personal lists. Key will be provided automatically to each blog once it is created or during the plugin activation process. The key could be changed only by the network administrator.</span>'
2417
+ . '<h4>Mutual Account, Mutual Access Key</h4>'
2418
+ . '<span>All blogs use one mutual key. They also share security logs, settings and personal lists with each other. Network administrator holds the key.</span>'
2419
+ . '<h4>Individual accounts, individual Access keys</h4>'
2420
+ . '<span>Each blog uses its own account and its own key. Separate security logs, settings, personal lists. Blog administrator can change the key on his own.</span>',
2421
+ 'cleantalk-spam-protect'
2422
+ )
2423
+ ),
2424
+ 'multisite__hoster_api_key' => array(
2425
+ 'title' => __('Hoster API key', 'cleantalk-spam-protect'),
2426
+ 'desc' => __(
2427
+ 'You could find it here:<br><a href ="https://cleantalk-screenshots.s3.amazonaws.com/help/hosting-antispam/hapi-ru.png"><img src="https://cleantalk-screenshots.s3.amazonaws.com/help/hosting-antispam/hapi-ru.png"></a><br>Press on the screenshot to zoom.',
2428
+ 'cleantalk-spam-protect'
2429
+ )
2430
+ ),
2431
+ );
2432
+
2433
+ die(json_encode($descriptions[$setting_id]));
2434
  }
2435
 
2436
+ function apbct_settings__check_renew_banner()
2437
+ {
2438
+ global $apbct;
2439
+
2440
+ check_ajax_referer('ct_secret_nonce');
2441
+
2442
+ die(
2443
+ json_encode(
2444
+ array('close_renew_banner' => ($apbct->data['notice_trial'] == 0 && $apbct->data['notice_renew'] == 0) ? true : false)
2445
+ )
2446
+ );
2447
+ }
2448
+
2449
+ /**
2450
+ * Checking availability of the handlers and return alt cookies type
2451
+ *
2452
+ * @return int|false
2453
+ */
2454
+ function apbct_settings__get_alt_cookies_type()
2455
+ {
2456
+ // Check custom ajax availability
2457
+ $res_custom_ajax = Helper::httpRequestGetResponseCode(esc_url(APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php'));
2458
+ if ( $res_custom_ajax == 400 ) {
2459
+ return 1;
2460
+ }
2461
+
2462
+ // Check rest availability
2463
+ $res_rest = Helper::httpRequestGetResponseCode(esc_url(apbct_get_rest_url()));
2464
+ if ( $res_rest == 200 ) {
2465
+ return 0;
2466
+ }
2467
+
2468
+ // Check WP ajax availability
2469
+ $res_ajax = Helper::httpRequestGetResponseCode(admin_url('admin-ajax.php'));
2470
+ if ( $res_ajax == 400 ) {
2471
+ return 2;
2472
+ }
2473
+
2474
+ return false;
2475
  }
2476
 
2477
+ function apbct_settings__check_alt_cookies_types()
2478
+ {
2479
+ global $apbct;
2480
+
2481
+ switch ( $apbct->settings['data__set_cookies__alt_sessions_type'] ) {
2482
+ case '0':
2483
+ $alt_cookies_type = esc_html__('REST API', 'cleantalk-spam-protect');
2484
+ break;
2485
+ case '1':
2486
+ $alt_cookies_type = esc_html__('CleanTalk AJAX handler', 'cleantalk-spam-protect');
2487
+ break;
2488
+ case '2':
2489
+ $alt_cookies_type = esc_html__('WP AJAX handler', 'cleantalk-spam-protect');
2490
+ break;
2491
+ default:
2492
+ $alt_cookies_type = esc_html__('UNKNOWN', 'cleantalk-spam-protect');
2493
+ break;
2494
+ }
2495
 
2496
+ echo '<div class="apbct_settings-field_wrapper apbct_settings-field_wrapper--sub">';
2497
+ echo sprintf(
2498
+ esc_html__('Alternative cookies type was set on %s', 'cleantalk-spam-protect'),
2499
+ '<strong>' . $alt_cookies_type . '</strong><br>'
2500
+ );
2501
+
2502
+ echo '</div>';
2503
+ }
inc/cleantalk-updater.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
 
3
  use Cleantalk\ApbctWP\Cron;
 
4
  use Cleantalk\Common\Schema;
5
  use Cleantalk\Variables\Server;
6
 
@@ -14,46 +15,43 @@ use Cleantalk\Variables\Server;
14
  *
15
  * @psalm-suppress PossiblyUndefinedIntArrayOffset
16
  */
17
- function apbct_run_update_actions( $current_version, $new_version ){
18
-
19
- $current_version_arr = apbct_version_standardization( $current_version );
20
- $new_version_arr = apbct_version_standardization( $new_version );
21
-
22
- $current_version_str = implode( '.', $current_version_arr );
23
- $new_version_str = implode( '.', $new_version_arr );
24
-
25
- for( $ver_major = $current_version_arr[0]; $ver_major <= $current_version_arr[0]; $ver_major++ ){
26
- for($ver_minor = 0; $ver_minor <= 300; $ver_minor++){
27
- for($ver_fix = 0; $ver_fix <= 10; $ver_fix++){
28
-
29
- if( version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $current_version_str, '<=') ) {
30
- continue;
31
- }
32
-
33
- if(function_exists("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}")){
34
- $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}");
35
- if(!empty($result['error'])) {
36
- break;
37
- }
38
- }
39
-
40
- if( $ver_fix == 0 && function_exists("apbct_update_to_{$ver_major}_{$ver_minor}") ){
41
- $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}");
42
- if(!empty($result['error'])) {
43
- break;
44
- }
45
- }
46
-
47
- if(version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $new_version_str, '>=')) {
48
- break( 2 );
49
- }
50
-
51
- }
52
- }
53
- }
54
-
55
- return true;
56
-
57
  }
58
 
59
  /**
@@ -63,15 +61,15 @@ function apbct_run_update_actions( $current_version, $new_version ){
63
  *
64
  * @return array
65
  */
66
- function apbct_version_standardization( $version ){
67
-
68
- $parsed_version = explode( '.', $version );
69
 
70
- $parsed_version[0] = !empty($parsed_version[0]) ? (int)$parsed_version[0] : 0;
71
- $parsed_version[1] = !empty($parsed_version[1]) ? (int)$parsed_version[1] : 0;
72
- $parsed_version[2] = !empty($parsed_version[2]) ? (int)$parsed_version[2] : 0;
73
 
74
- return $parsed_version;
75
  }
76
 
77
  /**
@@ -81,434 +79,480 @@ function apbct_version_standardization( $version ){
81
  *
82
  * @return array
83
  */
84
- function apbct_get_table_columns( $table_name ) {
85
- global $wpdb;
86
- $query = 'SHOW COLUMNS FROM ' . $table_name;
87
- $res = $wpdb->get_results( $query, ARRAY_A );
88
- $columns_names = array();
89
- foreach ( $res as $column ) {
90
- $columns_names[] = $column['Field'];
91
- }
92
- return $columns_names;
 
 
93
  }
94
 
95
  /**
96
  * @return void
97
  */
98
- function apbct_update_to_5_50_0(){
99
- global $wpdb;
100
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_DATA .'` (
 
 
101
  `network` int(11) unsigned NOT NULL,
102
  `mask` int(11) unsigned NOT NULL,
103
  INDEX ( `network` , `mask` )
104
- );');
105
-
106
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_FIREWALL_LOG .'` (
 
 
107
  `ip` VARCHAR(15) NOT NULL ,
108
  `all` INT NOT NULL ,
109
  `blocked` INT NOT NULL ,
110
  `timestamp` INT NOT NULL ,
111
- PRIMARY KEY (`ip`));');
 
112
  }
113
 
114
  /**
115
  * @return void
116
  */
117
- function apbct_update_to_5_56_0(){
118
- if (!wp_next_scheduled('cleantalk_update_sfw_hook'))
119
- wp_schedule_event(time()+1800, 'daily', 'cleantalk_update_sfw_hook' );
 
 
120
  }
121
 
122
  /**
123
  * @return void
124
  */
125
- function apbct_update_to_5_70_0(){
126
-
127
- global $wpdb;
128
-
129
- if(!in_array('all_entries', $wpdb->get_col('DESC '. APBCT_TBL_FIREWALL_LOG, 0))){
130
- $wpdb->query('ALTER TABLE `'. APBCT_TBL_FIREWALL_LOG .'`
 
131
  CHANGE `all` `all_entries` INT(11) NOT NULL,
132
  CHANGE `blocked` `blocked_entries` INT(11) NOT NULL,
133
  CHANGE `timestamp` `entries_timestamp` INT(11) NOT NULL;'
134
- );
135
- }
136
-
137
- // Deleting usless data
138
- delete_option('cleantalk_sends_reports_till');
139
- delete_option('cleantalk_activation_timestamp');
140
-
141
- // Disabling WP_Cron tasks
142
- wp_clear_scheduled_hook('cleantalk_send_daily_report_hook');
143
- wp_clear_scheduled_hook('ct_hourly_event_hook');
144
- wp_clear_scheduled_hook('ct_send_sfw_log');
145
- wp_clear_scheduled_hook('cleantalk_update_sfw_hook');
146
- wp_clear_scheduled_hook('cleantalk_get_brief_data_hook');
147
-
148
- // Adding Self cron system tasks
149
- $cron = new Cron();
150
- $cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // New
151
- $cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500);
152
- $cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500);
153
- $cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 43200);
154
- $cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // New
155
- $cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500);
156
  }
157
 
158
  /**
159
  * @return void
160
  */
161
- function apbct_update_to_5_74_0(){
162
- $cron = new Cron();
163
- $cron->removeTask('send_daily_request');
 
164
  }
165
 
166
  /**
167
  * @return void
168
  */
169
- function apbct_update_to_5_97_0(){
170
-
171
- global $apbct;
172
-
173
- if(count($apbct->data['connection_reports']['negative_report']) >= 20)
174
- $apbct->data['connection_reports']['negative_report'] = array_slice($apbct->data['connection_reports']['negative_report'], -20, 20);
175
-
176
- $apbct->saveData();
 
 
 
 
 
177
  }
178
 
179
  /**
180
  * @return void
181
  */
182
- function apbct_update_to_5_109_0(){
183
-
184
- global $apbct, $wpdb;
185
-
186
- if(apbct_is_plugin_active_for_network($apbct->base_name) && !defined('CLEANTALK_ACCESS_KEY')){
187
-
188
- $sfw_data_query = 'CREATE TABLE IF NOT EXISTS `%s` (
189
  `network` int(11) unsigned NOT NULL,
190
  `mask` int(11) unsigned NOT NULL,
191
  INDEX ( `network` , `mask` )
192
  );';
193
 
194
- $sfw_log_query = 'CREATE TABLE IF NOT EXISTS `%s` (
195
  `ip` VARCHAR(15) NOT NULL,
196
  `all_entries` INT NOT NULL,
197
  `blocked_entries` INT NOT NULL,
198
  `entries_timestamp` INT NOT NULL,
199
  PRIMARY KEY (`ip`));';
200
 
201
- $initial_blog = get_current_blog_id();
202
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
203
- foreach ($blogs as $blog) {
204
- switch_to_blog($blog);
205
- $wpdb->query(sprintf($sfw_data_query, $wpdb->prefix . 'cleantalk_sfw')); // Table for SpamFireWall data
206
- $wpdb->query(sprintf($sfw_log_query, $wpdb->prefix . 'cleantalk_sfw_logs')); // Table for SpamFireWall logs
207
- // Cron tasks
208
- $cron = new Cron();
209
- $cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
210
- $cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
211
- $cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
212
- $cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 300); // SFW update
213
- $cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
214
- $cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
215
- $cron->addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
216
- }
217
- switch_to_blog($initial_blog);
218
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
  }
220
 
221
  /**
222
  * @return void
223
  */
224
- function apbct_update_to_5_110_0(){
225
- global $apbct;
226
- unset($apbct->data['last_remote_call']);
227
- $apbct->saveData;
228
- $apbct->save('remote_calls');
 
229
  }
230
 
231
  /**
232
  * @return void
233
  */
234
- function apbct_update_to_5_115_1(){
235
- apbct_sfw_update__init();
236
- }
237
 
238
- /**
239
- * @return void
240
- */
241
- function apbct_update_to_5_116_0(){
242
-
243
- global $apbct, $wpdb;
244
-
245
- $apbct->settings['store_urls'] = 0;
246
- $apbct->settings['store_urls__sessions'] = 0;
247
- $apbct->saveSettings();
248
-
249
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
250
  `id` VARCHAR(64) NOT NULL,
251
  `name` TEXT NOT NULL,
252
  `value` TEXT NULL,
253
  `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
254
  PRIMARY KEY (`id`, `name`(10)));'
255
- );
256
  }
257
 
258
  /**
259
  * @return void
260
  */
261
- function apbct_update_to_5_116_1(){
262
-
263
- global $wpdb;
264
-
265
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
 
266
  `id` VARCHAR(64) NOT NULL,
267
  `name` TEXT NOT NULL,
268
  `value` TEXT NULL,
269
  `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
270
  PRIMARY KEY (`id`, `name`(10)));'
271
- );
272
  }
273
 
274
  /**
275
  * @return void
276
  */
277
- function apbct_update_to_5_116_2(){
278
-
279
- global $wpdb;
280
-
281
- $wpdb->query('CREATE TABLE IF NOT EXISTS `'. APBCT_TBL_SESSIONS .'` (
 
282
  `id` VARCHAR(64) NOT NULL,
283
  `name` TEXT NOT NULL,
284
  `value` TEXT NULL DEFAULT NULL,
285
  `last_update` DATETIME NULL DEFAULT NULL,
286
  PRIMARY KEY (`id`, `name`(10)));'
287
- );
288
  }
289
 
290
  /**
291
  * @return void
292
  */
293
- function apbct_update_to_5_118_0(){
294
- global $wpdb;
295
- $wpdb->query(
296
- 'DELETE
297
- FROM `'. APBCT_TBL_SESSIONS .'`
298
- WHERE last_update < NOW() - INTERVAL '. APBCT_SEESION__LIVE_TIME .' SECOND;'
299
- );
300
- delete_option('cleantalk_server');
 
301
  }
302
 
303
  /**
304
  * @return void
305
  */
306
- function apbct_update_to_5_118_2(){
307
- global $apbct;
308
- $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
309
- $apbct->data['connection_reports']['since'] = date('d M');
310
- $apbct->saveData();
 
311
  }
312
 
313
  /**
314
  * @return void
315
  */
316
- function apbct_update_to_5_119_0(){
317
-
318
- global $wpdb;
319
-
320
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
321
 
322
- $sqls = array();
323
 
324
- // SFW data
325
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
 
 
326
  `network` int(11) unsigned NOT NULL,
327
  `mask` int(11) unsigned NOT NULL,
328
  INDEX ( `network` , `mask` )
329
  );';
330
-
331
- // SFW log
332
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
333
  `ip` VARCHAR(15) NOT NULL,
334
  `all_entries` INT NOT NULL,
335
  `blocked_entries` INT NOT NULL,
336
  `entries_timestamp` INT NOT NULL,
337
  PRIMARY KEY (`ip`));';
338
-
339
- // Sessions
340
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sessions` (
341
  `id` VARCHAR(64) NOT NULL,
342
  `name` VARCHAR(64) NOT NULL,
343
  `value` TEXT NULL DEFAULT NULL,
344
  `last_update` DATETIME NULL DEFAULT NULL,
345
  PRIMARY KEY (`id`(64), `name`(64)));';
346
-
347
- apbct_activation__create_tables($sqls);
348
-
349
- // WPMS
350
- if( is_multisite() ){
351
-
352
- $initial_blog = get_current_blog_id();
353
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
354
- foreach ($blogs as $blog) {
355
- switch_to_blog($blog);
356
- $wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
357
- apbct_activation__create_tables($sqls);
358
- }
359
- switch_to_blog($initial_blog);
360
- }
361
-
362
- // Drop work url
363
- update_option(
364
- 'cleantalk_server',
365
- array(
366
- 'ct_work_url' => null,
367
- 'ct_server_ttl' => 0,
368
- 'ct_server_changed' => 0,
369
- )
370
- );
371
  }
372
 
373
  /**
374
  * @return void
375
  */
376
- function apbct_update_to_5_124_0(){
377
- global $apbct;
378
- // Deleting error in database because format were changed
379
- $apbct->errors = array();
380
- $apbct->saveErrors();
 
381
  }
382
 
383
  /**
384
  * @return void
385
  */
386
- function apbct_update_to_5_126_0(){
387
- global $apbct;
388
- // Enable storing URLs
389
- $apbct->settings['store_urls'] = 1;
390
- $apbct->settings['store_urls__sessions'] = 1;
391
- $apbct->saveSettings();
 
392
  }
393
 
394
  /**
395
  * @return void
396
  */
397
- function apbct_update_to_5_127_0(){
398
-
399
- global $apbct, $wpdb;
400
-
401
- // Move exclusions from variable to settins
402
- global $cleantalk_url_exclusions, $cleantalk_key_exclusions;
403
- // URLs
404
- if(!empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions)){
405
- $apbct->settings['exclusions__urls'] = implode(',', $cleantalk_url_exclusions);
406
- if( APBCT_WPMS ){
407
- $initial_blog = get_current_blog_id();
408
- switch_to_blog( 1 );
409
- $apbct->saveSettings();
410
- switch_to_blog($initial_blog);
411
- } else {
412
- $apbct->saveSettings();
413
- }
414
- }
415
- // Fields
416
- if(!empty($cleantalk_key_exclusions) && is_array($cleantalk_key_exclusions)){
417
- $apbct->settings['exclusions__fields'] = implode(',', $cleantalk_key_exclusions);
418
- if( APBCT_WPMS ){
419
- $initial_blog = get_current_blog_id();
420
- switch_to_blog( 1 );
421
- $apbct->saveSettings();
422
- switch_to_blog($initial_blog);
423
- } else {
424
- $apbct->saveSettings();
425
- }
426
- }
427
-
428
- // Deleting legacy
429
- if(isset($apbct->data['testing_failed'])){
430
- unset($apbct->data['testing_failed']);
431
- $apbct->saveData();
432
- }
433
-
434
- if(APBCT_WPMS){
435
-
436
- // Whitelabel
437
- // Reset "api_key_is_received" flag
438
- $initial_blog = get_current_blog_id();
439
- $blogs = array_keys( $wpdb->get_results( 'SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K ) );
440
- foreach ( $blogs as $blog ){
441
- switch_to_blog( $blog );
442
-
443
- $settings = get_option( 'cleantalk_settings' );
444
- if( isset( $settings['use_static_js_key'] ) ){
445
- $settings['use_static_js_key'] = $settings['use_static_js_key'] === 0
446
- ? - 1
447
- : $settings['use_static_js_key'];
448
- update_option( 'cleantalk_settings', $settings );
449
-
450
- $data = get_option( 'cleantalk_data' );
451
- if( isset( $data['white_label_data']['is_key_recieved'] ) ){
452
- unset( $data['white_label_data']['is_key_recieved'] );
453
- update_option( 'cleantalk_data', $data );
454
- }
455
- }
456
- switch_to_blog( $initial_blog );
457
-
458
- if( defined( 'APBCT_WHITELABEL' ) ){
459
- $apbct->network_settings = array(
460
- 'white_label' => defined( 'APBCT_WHITELABEL' ) && APBCT_WHITELABEL == true ? 1 : 0,
461
- 'white_label__plugin_name' => defined( 'APBCT_WHITELABEL_NAME' ) ? APBCT_WHITELABEL_NAME : APBCT_NAME,
462
- );
463
- }elseif( defined( 'CLEANTALK_ACCESS_KEY' ) ){
464
- $apbct->network_settings = array(
465
- 'allow_custom_key' => 0,
466
- 'apikey' => CLEANTALK_ACCESS_KEY,
467
- );
468
- }
469
- $apbct->saveNetworkSettings();
470
- }
471
- }else{
472
- // Switch use_static_js_key to Auto if it was disabled
473
- $apbct->settings['use_static_js_key'] = $apbct->settings['use_static_js_key'] === 0
474
- ? -1
475
- : $apbct->settings['use_static_js_key'];
476
- $apbct->saveSettings();
477
- }
478
  }
479
 
480
  /**
481
  * @return void
482
  */
483
- function apbct_update_to_5_127_1(){
484
- global $apbct;
485
- if(APBCT_WPMS && is_main_site()){
486
- $network_settings = get_site_option( 'cleantalk_network_settings' );
487
- if( $network_settings !== false && empty( $network_settings['allow_custom_key'] ) && empty( $network_settings['white_label'] ) ){
488
- $network_settings['allow_custom_key'] = 1;
489
- update_site_option( 'cleantalk_network_settings', $network_settings );
490
- }
491
- if( $network_settings !== false && $network_settings['white_label'] == 1 && $apbct->data['moderate'] == 0 ){
492
- ct_account_status_check( $network_settings['apikey'] ? $network_settings['apikey'] : $apbct->settings['apikey'], false);
493
- }
494
- }
 
 
 
 
 
 
 
 
 
495
  }
496
 
497
  /**
498
  * @return void
499
  */
500
- function apbct_update_to_5_128_0(){
501
- global $apbct;
502
- $apbct->remote_calls = array();
503
- $apbct->save('remote_calls');
 
504
  }
505
 
506
  /**
507
  * @return void
508
  */
509
- function apbct_update_to_5_133_0() {
510
-
511
- $sqls = array();
512
 
513
  // Scan comment/user log
514
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
@@ -522,7 +566,6 @@ function apbct_update_to_5_133_0() {
522
  PRIMARY KEY (`id`));';
523
 
524
  apbct_activation__create_tables($sqls);
525
-
526
  }
527
 
528
  /**
@@ -530,16 +573,16 @@ function apbct_update_to_5_133_0() {
530
  *
531
  * @psalm-suppress PossiblyUndefinedStringArrayOffset
532
  */
533
- function apbct_update_to_5_138_0() {
534
-
535
- global $wpdb;
536
- // change name for prevent psalm false positive
537
- $_wpdb = $wpdb;
538
 
539
- $sqls = array();
540
 
541
- // SQL queries for each blog
542
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
543
  `id` int(11) NOT NULL AUTO_INCREMENT,
544
  `scan_type` varchar(11) NOT NULL,
545
  `start_time` datetime NOT NULL,
@@ -548,171 +591,161 @@ function apbct_update_to_5_138_0() {
548
  `found_spam` int(11) DEFAULT NULL,
549
  `found_bad` int(11) DEFAULT NULL,
550
  PRIMARY KEY (`id`));';
551
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
552
  `network` int(11) unsigned NOT NULL,
553
  `mask` int(11) unsigned NOT NULL,
554
  INDEX ( `network` , `mask` )
555
  );';
556
 
557
- $table_sfw_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_DATA );
558
- if( ! in_array( 'status', $table_sfw_columns ) ) {
559
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN status TINYINT(1) NOT NULL DEFAULT 0 AFTER mask;';
560
- }
561
-
562
- // Actions for WPMS
563
- if( APBCT_WPMS ){
564
-
565
- // Getting all blog ids
566
- $initial_blog = get_current_blog_id();
567
- $blogs = $_wpdb->get_results('SELECT blog_id FROM '. $_wpdb->blogs, OBJECT_K);
568
- $blogs_ids = array_keys( $blogs );
569
-
570
- // Getting main blog setting
571
- switch_to_blog( 1 );
572
- $main_blog_settings = get_option( 'cleantalk_settings' );
573
- switch_to_blog( $initial_blog );
574
-
575
- // Getting network settings
576
- $net_settings = get_site_option('cleantalk_network_settings');
577
-
578
- foreach ($blogs_ids as $blog) {
579
-
580
- // Update time limit to prevent exec time error
581
- set_time_limit(20);
582
-
583
- switch_to_blog($blog);
584
-
585
- // Update SQL structure
586
- apbct_activation__create_tables($sqls);
587
-
588
- // Getting key
589
- $settings = $net_settings['allow_custom_key']
590
- ? get_option('cleantalk_settings')
591
- : $main_blog_settings;
592
-
593
- // Update plugin status
594
- if( ! empty( $settings['apikey'] ) ){
595
-
596
- $data = get_option( 'cleantalk_data', array() );
597
-
598
- $result = \Cleantalk\ApbctWP\API::method__notice_paid_till(
599
- $settings['api_key'],
600
- preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
601
- ! is_main_site() && $net_settings['white_label'] ? 'anti-spam-hosting' : 'antispam'
602
- );
603
-
604
- if( empty( $result['error'] ) || ! empty( $result['valid'] ) ){
605
-
606
- // Notices
607
- $data['notice_show'] = isset($result['show_notice']) ? (int)$result['show_notice'] : 0;
608
- $data['notice_renew'] = isset($result['renew']) ? (int)$result['renew'] : 0;
609
- $data['notice_trial'] = isset($result['trial']) ? (int)$result['trial'] : 0;
610
- $data['notice_review'] = isset($result['show_review']) ? (int)$result['show_review'] : 0;
611
- $data['notice_auto_update'] = isset($result['show_auto_update_notice']) ? (int)$result['show_auto_update_notice'] : 0;
612
-
613
- // Other
614
- $data['service_id'] = isset($result['service_id']) ? (int)$result['service_id'] : 0;
615
- $data['valid'] = isset($result['valid']) ? (int)$result['valid'] : 0;
616
- $data['moderate'] = isset($result['moderate']) ? (int)$result['moderate'] : 0;
617
- $data['ip_license'] = isset($result['ip_license']) ? (int)$result['ip_license'] : 0;
618
- $data['moderate_ip'] = isset($result['moderate_ip'], $result['ip_license']) ? (int)$result['moderate_ip'] : 0;
619
- $data['spam_count'] = isset($result['spam_count']) ? (int)$result['spam_count'] : 0;
620
- $data['auto_update'] = isset($result['auto_update_app']) ? (int)$result['auto_update_app'] : 0;
621
- $data['user_token'] = isset($result['user_token']) ? (string)$result['user_token'] : '';
622
- $data['license_trial'] = isset($result['license_trial']) ? (int)$result['license_trial'] : 0;
623
- $data['account_name_ob'] = isset($result['account_name_ob']) ? (string)$result['account_name_ob'] : '';
624
-
625
- }
626
-
627
- $data['key_is_ok'] = ! empty( $result['valid'] )
628
- ? true
629
- : false;
630
-
631
- update_option( 'cleantalk_data', $data );
632
-
633
- }
634
-
635
- }
636
-
637
- // Restoring initial blog
638
- switch_to_blog($initial_blog);
639
-
640
- // Actions for stand alone blog
641
- }else{
642
- apbct_activation__create_tables($sqls);
643
- }
644
-
645
  }
646
 
647
  /**
648
  * @return void
649
  */
650
- function apbct_update_to_5_142_0() {
651
-
652
- $sqls = array();
653
 
654
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
655
  `id` VARCHAR(40) NOT NULL,
656
  `ip` VARCHAR(40) NOT NULL,
657
  `entries` INT DEFAULT 0,
658
  `interval_start` INT NOT NULL,
659
  PRIMARY KEY (`id`));';
660
 
661
- $table_sfw_logs_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_LOG );
662
- if( ! in_array( 'id', $table_sfw_logs_columns ) ) {
663
- $status = ! in_array( 'status', $table_sfw_logs_columns ) ? ' ADD COLUMN `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTIBOT\',\'DENY_ANTICRAWLER\') NOT NULL AFTER `ip`,' : '';
664
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
 
 
 
665
  ADD COLUMN `id` VARCHAR(40) NOT NULL FIRST,
666
  ' . $status . '
667
  DROP PRIMARY KEY,
668
  ADD PRIMARY KEY (`id`);';
669
- }
670
 
671
 
672
-
673
- apbct_activation__create_tables( $sqls );
674
-
675
  }
676
 
677
  /**
678
  * @return void
679
  */
680
- function apbct_update_to_5_142_1() {
 
 
 
681
 
682
- $sqls = array();
683
- $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
684
-
685
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
686
  CHANGE `status` `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTICRAWLER\',\'DENY_ANTIFLOOD\') NOT NULL AFTER `ip`;';
687
-
688
- apbct_activation__create_tables( $sqls );
689
-
690
  }
691
 
692
  /**
693
  * @return void
694
  */
695
- function apbct_update_to_5_142_2() {
 
 
 
696
 
697
- $sqls = array();
698
- $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
699
-
700
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
701
  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`;';
702
-
703
- apbct_activation__create_tables( $sqls );
704
-
705
  }
706
 
707
  /**
708
  * @return void
709
  */
710
- function apbct_update_to_5_142_3() {
711
-
712
- global $apbct;
713
 
714
- $sqls = array();
715
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
716
  `id` VARCHAR(40) NOT NULL,
717
  `ip` VARCHAR(15) NOT NULL,
718
  `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,
@@ -720,22 +753,21 @@ function apbct_update_to_5_142_3() {
720
  `blocked_entries` INT NOT NULL,
721
  `entries_timestamp` INT NOT NULL,
722
  PRIMARY KEY (`id`));';
723
-
724
- apbct_activation__create_tables( $sqls, $apbct->db_prefix );
725
-
726
  }
727
 
728
  /**
729
  * @return void
730
  */
731
- function apbct_update_to_5_143_2() {
732
-
733
- global $apbct;
734
-
735
- $sqls = array();
736
- $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
737
-
738
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
739
  `id` VARCHAR(40) NOT NULL,
740
  `ip` VARCHAR(15) NOT NULL,
741
  `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,
@@ -743,19 +775,18 @@ function apbct_update_to_5_143_2() {
743
  `blocked_entries` INT NOT NULL,
744
  `entries_timestamp` INT NOT NULL,
745
  PRIMARY KEY (`id`));';
746
-
747
- apbct_activation__create_tables( $sqls, $apbct->db_prefix );
748
-
749
  }
750
 
751
  /**
752
  * @return void
753
  */
754
- function apbct_update_to_5_146_1() {
755
-
756
  global $apbct;
757
 
758
- $sqls = array();
759
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ac_log`;';
760
 
761
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
@@ -766,33 +797,34 @@ function apbct_update_to_5_146_1() {
766
  `interval_start` INT NOT NULL,
767
  PRIMARY KEY (`id`));';
768
 
769
- apbct_activation__create_tables( $sqls, $apbct->db_prefix );
770
-
771
  }
772
 
773
  /**
774
  * @return void
775
  */
776
- function apbct_update_to_5_146_3() {
777
- update_option( 'cleantalk_plugin_request_ids', array() );
 
778
  }
779
 
780
  /**
781
  * @return void
782
  */
783
- function apbct_update_to_5_148_0() {
784
- $cron = new Cron();
785
- $cron->updateTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400);
 
786
  }
787
 
788
  /**
789
  * @return void
790
  */
791
- function apbct_update_to_5_149_2() {
792
-
793
  global $apbct;
794
 
795
- $sqls = array();
796
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
797
  `id` INT(11) NOT NULL,
798
  `ua_template` VARCHAR(255) NULL DEFAULT NULL,
@@ -814,44 +846,40 @@ function apbct_update_to_5_149_2() {
814
  `ua_name` VARCHAR(1024) NOT NULL,
815
  PRIMARY KEY (`id`));';
816
 
817
- apbct_activation__create_tables( $sqls, $apbct->db_prefix );
818
-
819
  }
820
 
821
  /**
822
  * @return void
823
  */
824
- function apbct_update_to_5_150_0() {
825
-
826
- global $wpdb;
827
-
828
- // Actions for WPMS
829
- if( APBCT_WPMS ){
830
- // Getting all blog ids
831
- $initial_blog = get_current_blog_id();
832
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
833
-
834
- foreach ($blogs as $blog) {
835
-
836
- switch_to_blog($blog);
837
 
838
- update_option( 'cleantalk_plugin_request_ids', array() );
 
 
 
 
839
 
840
- }
 
841
 
842
- // Restoring initial blog
843
- switch_to_blog($initial_blog);
844
- }
845
 
 
 
 
846
  }
847
 
848
  /**
849
  * @return void
850
  */
851
- function apbct_update_to_5_150_1() {
852
-
853
  global $apbct;
854
- $sqls = array();
855
  // UA BL with default charset
856
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ua_bl`;';
857
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
@@ -862,21 +890,22 @@ function apbct_update_to_5_150_1() {
862
  INDEX ( `ua_template` )
863
  ) DEFAULT CHARSET=utf8;'; // Don't remove the default charset!
864
 
865
- apbct_activation__create_tables( $sqls, $apbct->db_prefix );
866
  }
867
 
868
  /**
869
  * @return void
870
  */
871
- function apbct_update_to_5_151_1 () {
 
872
  global $apbct;
873
- $apbct->fw_stats['firewall_updating_id'] = isset( $apbct->data['firewall_updating_id'] )
874
  ? $apbct->data['firewall_updating_id']
875
  : '';
876
- $apbct->fw_stats['firewall_update_percent'] = isset( $apbct->data['firewall_update_percent'] )
877
  ? $apbct->data['firewall_update_percent']
878
  : 0;
879
- $apbct->fw_stats['firewall_updating_last_start'] = isset( $apbct->data['firewall_updating_last_start'] )
880
  ? $apbct->data['firewall_updating_last_start']
881
  : 0;
882
  $apbct->save('fw_stats');
@@ -886,181 +915,174 @@ function apbct_update_to_5_151_1 () {
886
  * @return void
887
  * @throws Exception
888
  */
889
- function apbct_update_to_5_151_3 ()
890
  {
891
  global $wpdb, $apbct;
892
- $sql = 'SHOW TABLES LIKE "%scleantalk_sfw";';
893
- $sql = sprintf( $sql, $wpdb->prefix ); // Adding current blog prefix
894
- $result = $wpdb->get_var( $sql );
895
- if( ! $result ){
896
- apbct_activation__create_tables( Schema::getSchema('sfw'), $apbct->db_prefix );
897
  }
898
  $apbct->fw_stats['firewall_updating_last_start'] = 0;
899
  $apbct->save('fw_stats');
900
  $apbct->stats['sfw']['entries'] = 0;
901
  $apbct->save('stats');
902
- apbct_sfw_update__init();
903
  }
904
 
905
  /**
906
  * @return void
907
  */
908
- function apbct_update_to_5_151_6 ()
909
  {
910
- global $apbct;
911
- $apbct->error_delete( 'sfw_update', true );
912
  }
913
 
914
  /**
915
  * @return void
916
  */
917
- function apbct_update_to_5_153_4(){
918
-
919
  // Adding cooldown to sending SFW logs
920
  global $apbct;
921
  $apbct->stats['sfw']['sending_logs__timestamp'] = 0;
922
  $apbct->save('stats');
923
-
924
  }
925
 
926
  /**
927
  * @return void
928
  */
929
- function apbct_update_to_5_154_0(){
930
-
931
- global $apbct, $wpdb;
932
-
933
- // Old setting name => New setting name
934
- $keys_map = array(
935
- 'spam_firewall' => 'sfw__enabled',
936
- 'registrations_test' => 'forms__registrations_test',
937
- 'comments_test' => 'forms__comments_test',
938
- 'contact_forms_test' => 'forms__contact_forms_test',
939
- 'general_contact_forms_test' => 'forms__general_contact_forms_test',
940
- 'wc_checkout_test' => 'forms__wc_checkout_test',
941
- 'wc_register_from_order' => 'forms__wc_register_from_order',
942
- 'search_test' => 'forms__search_test',
943
- 'check_external' => 'forms__check_external',
944
- 'check_external__capture_buffer' => 'forms__check_external__capture_buffer',
945
- 'check_internal' => 'forms__check_internal',
946
- 'disable_comments__all' => 'comments__disable_comments__all',
947
- 'disable_comments__posts' => 'comments__disable_comments__posts',
948
- 'disable_comments__pages' => 'comments__disable_comments__pages',
949
- 'disable_comments__media' => 'comments__disable_comments__media',
950
- 'bp_private_messages' => 'comments__bp_private_messages',
951
- 'check_comments_number' => 'comments__check_comments_number',
952
- 'remove_old_spam' => 'comments__remove_old_spam',
953
- 'remove_comments_links' => 'comments__remove_comments_links',
954
- 'show_check_links' => 'comments__show_check_links',
955
- 'manage_comments_on_public_page' => 'comments__manage_comments_on_public_page',
956
- 'protect_logged_in' => 'data__protect_logged_in',
957
- 'use_ajax' => 'data__use_ajax',
958
- 'use_static_js_key' => 'data__use_static_js_key',
959
- 'general_postdata_test' => 'data__general_postdata_test',
960
- 'set_cookies' => 'data__set_cookies',
961
- 'set_cookies__sessions' => 'data__set_cookies__sessions',
962
- 'ssl_on' => 'data__ssl_on',
963
- 'show_adminbar' => 'admin_bar__show',
964
- 'all_time_counter' => 'admin_bar__all_time_counter',
965
- 'daily_counter' => 'admin_bar__daily_counter',
966
- 'sfw_counter' => 'admin_bar__sfw_counter',
967
- 'gdpr_enabled' => 'gdpr__enabled',
968
- 'gdpr_text' => 'gdpr__text',
969
- 'collect_details' => 'misc__collect_details',
970
- 'send_connection_reports' => 'misc__send_connection_reports',
971
- 'async_js' => 'misc__async_js',
972
- 'debug_ajax' => 'misc__debug_ajax',
973
- 'store_urls' => 'misc__store_urls',
974
- 'store_urls__sessions' => 'misc__store_urls__sessions',
975
- 'complete_deactivation' => 'misc__complete_deactivation',
976
- 'use_buitin_http_api' => 'wp__use_builtin_http_api',
977
- 'comment_notify' => 'wp__comment_notify',
978
- 'comment_notify__roles' => 'wp__comment_notify__roles',
979
- 'dashboard_widget__show' => 'wp__dashboard_widget__show',
980
- 'allow_custom_key' => 'multisite__allow_custom_key',
981
- 'allow_custom_settings' => 'multisite__allow_custom_settings',
982
- 'white_label' => 'multisite__white_label',
983
- 'white_label__plugin_name' => 'multisite__white_label__plugin_name',
984
- 'use_settings_template' => 'multisite__use_settings_template',
985
- 'use_settings_template_apply_for_new' => 'multisite__use_settings_template_apply_for_new',
986
- 'use_settings_template_apply_for_current' => 'multisite__use_settings_template_apply_for_current',
987
- 'use_settings_template_apply_for_current_list_sites' => 'multisite__use_settings_template_apply_for_current_list_sites',
988
- );
989
-
990
- if( is_multisite() ){
991
-
992
- $network_settings = get_site_option( 'cleantalk_network_settings' );
993
-
994
- if( $network_settings ) {
995
- $_network_settings = array();
996
- // replacing old key to new keys
997
- foreach( $network_settings as $key => $value ){
998
- if( array_key_exists( $key, $keys_map ) ) {
999
- $_network_settings[$keys_map[$key]] = $value;
1000
- } else {
1001
- $_network_settings[$key] = $value;
1002
- }
1003
- }
1004
- if( ! empty( $_network_settings ) ) {
1005
- update_site_option( 'cleantalk_network_settings', $_network_settings );
1006
- }
1007
- }
1008
-
1009
- $initial_blog = get_current_blog_id();
1010
- $blogs = array_keys( $wpdb->get_results( 'SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K ) );
1011
- foreach ( $blogs as $blog ) {
1012
- switch_to_blog( $blog );
1013
-
1014
- $settings = get_option( 'cleantalk_settings' );
1015
-
1016
- if( $settings ) {
1017
- // replacing old key to new keys
1018
- $_settings = array();
1019
- foreach( $settings as $key => $value ){
1020
- if( array_key_exists( $key, $keys_map ) ) {
1021
- $_settings[$keys_map[$key]] = $value;
1022
- } else {
1023
- $_settings[$key] = $value;
1024
- }
1025
- }
1026
- if( ! empty( $_settings ) ){
1027
- update_option( 'cleantalk_settings', $_settings );
1028
- }
1029
- }
1030
-
1031
- }
1032
- switch_to_blog( $initial_blog );
1033
-
1034
- } else {
1035
-
1036
- $apbct->data['current_settings_template_id'] = null;
1037
- $apbct->data['current_settings_template_name'] = null;
1038
- $apbct->saveData();
1039
-
1040
- $settings = (array) $apbct->settings;
1041
-
1042
- if( $settings ) {
1043
- $_settings = array();
1044
- // replacing old key to new keys
1045
- foreach( $settings as $key => $value ){
1046
- if( array_key_exists( $key, $keys_map ) ) {
1047
- $_settings[$keys_map[$key]] = $value;
1048
- } else {
1049
- $_settings[$key] = $value;
1050
- }
1051
- }
1052
-
1053
- $apbct->settings = $_settings;
1054
- $apbct->saveSettings();
1055
- }
1056
-
1057
- }
1058
-
1059
- $sqls = array();
1060
-
1061
- $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
1062
-
1063
- $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
1064
  `id` VARCHAR(40) NOT NULL,
1065
  `ip` VARCHAR(15) NOT NULL,
1066
  `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW__BY_WHITELIST\',\'PASS_SFW__BY_COOKIE\',\'DENY_ANTICRAWLER\',\'PASS_ANTICRAWLER\',\'DENY_ANTICRAWLER_UA\',\'PASS_ANTICRAWLER_UA\',\'DENY_ANTIFLOOD\',\'PASS_ANTIFLOOD\',\'DENY_ANTIFLOOD_UA\',\'PASS_ANTIFLOOD_UA\') NULL DEFAULT NULL,
@@ -1071,121 +1093,122 @@ function apbct_update_to_5_154_0(){
1071
  `ua_name` VARCHAR(1024) NOT NULL,
1072
  PRIMARY KEY (`id`));';
1073
 
1074
- apbct_activation__create_tables( $sqls, $apbct->db_prefix );
1075
-
1076
  }
1077
 
1078
  /**
1079
  * @return void
1080
  */
1081
- function apbct_update_to_5_156_0(){
1082
-
1083
  global $apbct;
1084
-
1085
- $apbct->remote_calls['debug'] = array( 'last_call' => 0, 'cooldown' => 0 );
1086
- $apbct->remote_calls['debug_sfw'] = array( 'last_call' => 0, 'cooldown' => 0 );
1087
  $apbct->save('remote_calls');
1088
 
1089
  $cron = new Cron();
1090
- $cron->updateTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 42300 );
1091
-
1092
  }
1093
 
1094
  /**
1095
  * @return void
1096
  */
1097
- function apbct_update_to_5_157_0(){
1098
-
1099
  global $apbct;
1100
-
1101
- $apbct->remote_calls['sfw_update__worker'] = array( 'last_call' => 0, 'cooldown' => 0 );
1102
- $apbct->save( 'remote_calls' );
1103
-
1104
- if( ! empty( $apbct->settings['data__set_cookies__sessions'] ) ){
1105
  $apbct->settings['data__set_cookies'] = 2;
1106
  }
1107
  $apbct->settings['data__set_cookies__alt_sessions_type'] = 0;
1108
-
1109
- $apbct->save( 'settings' );
1110
 
1111
- cleantalk_get_brief_data( $apbct->api_key );
1112
-
 
1113
  }
1114
 
1115
  /**
1116
  * @return void
1117
  */
1118
- function apbct_update_to_5_158_0(){
1119
-
1120
  global $apbct, $wpdb;
1121
- // change name for prevent psalm false positive
1122
- $_wpdb = $wpdb;
 
 
1123
 
1124
- $sqls = array();
 
1125
 
1126
- $table_sfw_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_DATA );
1127
- $table_sfw_logs_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_LOG );
 
1128
 
1129
- if( ! in_array( 'source', $table_sfw_columns ) ) {
1130
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `status`;';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1131
  }
1132
 
1133
- if( ! in_array( 'source', $table_sfw_logs_columns ) ) {
1134
- $network = ! in_array( 'network', $table_sfw_logs_columns ) ? ' ADD COLUMN `network` VARCHAR(20) NULL DEFAULT NULL AFTER `source`,' : '';
1135
- $first_url = ! in_array( 'first_url', $table_sfw_logs_columns ) ? ' ADD COLUMN `first_url` VARCHAR(100) NULL DEFAULT NULL AFTER `network`,' : '';
1136
- $last_url = ! in_array( 'last_url', $table_sfw_logs_columns ) ? ' ADD COLUMN `last_url` VARCHAR(100) NULL DEFAULT NULL AFTER `first_url`' : '';
1137
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`'
1138
- . ' ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `ua_name`,'
1139
- . $network
1140
- . $first_url
1141
- . $last_url
1142
- . ';';
1143
- }
1144
-
1145
- if( APBCT_WPMS ){
1146
  // Getting all blog ids
1147
- $initial_blog = get_current_blog_id();
1148
- $blogs = array_keys($_wpdb->get_results('SELECT blog_id FROM '. $_wpdb->blogs, OBJECT_K));
1149
-
1150
- foreach ($blogs as $blog) {
1151
-
1152
  switch_to_blog($blog);
1153
  apbct_activation__create_tables($sqls);
1154
  }
1155
-
1156
  // Restoring initial blog
1157
  switch_to_blog($initial_blog);
1158
-
1159
- }else{
1160
  apbct_activation__create_tables($sqls);
1161
  }
1162
-
1163
  // Update from fix branch
1164
- if(APBCT_WPMS && is_main_site()){
1165
-
1166
- $wp_blogs = $_wpdb->get_results('SELECT blog_id, site_id FROM '. $_wpdb->blogs, OBJECT_K);
1167
  $current_sites_list = $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'];
1168
-
1169
- if( is_array( $wp_blogs ) && is_array( $current_sites_list ) ) {
1170
- foreach ($wp_blogs as $blog) {
1171
- $blog_details = get_blog_details( array( 'blog_id' => $blog->blog_id ) );
1172
- if( $blog_details ) {
1173
- $site_list_index = array_search( $blog_details->blogname, $current_sites_list, true );
1174
- if( $site_list_index !== false ) {
1175
- $current_sites_list[$site_list_index] = $blog_details->id;
1176
- }
1177
- }
1178
 
 
 
 
 
 
 
 
 
 
1179
  }
1180
  $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'] = $current_sites_list;
1181
- $apbct->settings['comments__hide_website_field'] = '0';
1182
- $apbct->settings['data__pixel'] = '0';
1183
  $apbct->saveSettings();
1184
  }
1185
-
1186
- }else{
1187
  $apbct->settings['comments__hide_website_field'] = '0';
1188
- $apbct->settings['data__pixel'] = '0';
1189
  $apbct->saveSettings();
1190
  }
1191
  }
@@ -1193,130 +1216,244 @@ function apbct_update_to_5_158_0(){
1193
  /**
1194
  * @return void
1195
  */
1196
- function apbct_update_to_5_158_2() {
1197
- global $apbct;
1198
- $apbct->stats['cron']['last_start'] = 0;
1199
- $apbct->save('stats');
 
1200
  }
1201
 
1202
  /**
1203
  * @return void
1204
  */
1205
- function apbct_update_to_5_159_6() {
1206
-
1207
- global $wpdb;
1208
-
1209
- $ct_cron = new Cron();
1210
-
1211
- if( is_multisite() ){
1212
- $initial_blog = get_current_blog_id();
1213
- $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
1214
- foreach ($blogs as $blog) {
1215
- switch_to_blog($blog);
1216
- // Cron tasks
1217
- $ct_cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
1218
- $ct_cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
1219
- $ct_cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
1220
- $ct_cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400 ); // SFW update
1221
- $ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
1222
- $ct_cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
1223
- $ct_cron->addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
1224
- $ct_cron->addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400, time() + 300); // Clear Anti-Flood table
1225
- }
1226
- switch_to_blog($initial_blog);
1227
- }else{
1228
- // Cron tasks
1229
- $ct_cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
1230
- $ct_cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
1231
- $ct_cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
1232
- $ct_cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400 ); // SFW update
1233
- $ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
1234
- $ct_cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
1235
- $ct_cron->addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
1236
- $ct_cron->addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400, time() + 300); // Clear Anti-Flood table
1237
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1238
  }
1239
 
1240
  /**
1241
  * @return void
1242
  */
1243
- function apbct_update_to_5_159_7() {
1244
- global $wpdb;
1245
- // change name for prevent psalm false positive
1246
- $_wpdb = $wpdb;
1247
-
1248
- $sqls = array();
1249
-
1250
- $table_sfw_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_DATA );
1251
- $table_sfw_logs_columns = apbct_get_table_columns( APBCT_TBL_FIREWALL_LOG );
1252
-
1253
- if( ! in_array( 'source', $table_sfw_columns ) ) {
1254
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `status`;';
1255
- }
1256
-
1257
- if( ! in_array( 'source', $table_sfw_logs_columns ) ) {
1258
- $network = ! in_array( 'network', $table_sfw_logs_columns ) ? ' ADD COLUMN `network` VARCHAR(20) NULL DEFAULT NULL AFTER `source`,' : '';
1259
- $first_url = ! in_array( 'first_url', $table_sfw_logs_columns ) ? ' ADD COLUMN `first_url` VARCHAR(100) NULL DEFAULT NULL AFTER `network`,' : '';
1260
- $last_url = ! in_array( 'last_url', $table_sfw_logs_columns ) ? ' ADD COLUMN `last_url` VARCHAR(100) NULL DEFAULT NULL AFTER `first_url`' : '';
1261
- $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`'
1262
- . ' ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `ua_name`,'
1263
- . $network
1264
- . $first_url
1265
- . $last_url
1266
- . ';';
1267
- }
1268
-
1269
- if( ! empty( $sqls ) ) {
1270
- if( APBCT_WPMS ){
1271
- // Getting all blog ids
1272
- $initial_blog = get_current_blog_id();
1273
- $blogs = array_keys($_wpdb->get_results('SELECT blog_id FROM '. $_wpdb->blogs, OBJECT_K));
1274
-
1275
- foreach ($blogs as $blog) {
1276
-
1277
- switch_to_blog($blog);
1278
- apbct_activation__create_tables($sqls);
1279
- }
1280
-
1281
- // Restoring initial blog
1282
- switch_to_blog($initial_blog);
1283
-
1284
- }else{
1285
- apbct_activation__create_tables($sqls);
1286
- }
1287
- }
1288
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1289
  }
1290
 
1291
  /**
1292
  * @return void
1293
  */
1294
- function apbct_update_to_5_159_9() {
1295
- $cron = new Cron();
1296
- $cron->addTask('rotate_moderate', 'apbct_rotate_moderate', 86400, time() + 3500); // Rotate moderate server
 
1297
  }
1298
 
1299
  /**
1300
  * @return void
1301
  */
1302
- function apbct_update_to_5_160_4() {
 
 
 
 
 
1303
 
1304
- global $apbct;
1305
 
1306
- $apbct->settings['sfw__random_get'] = '1';
1307
- $apbct->saveSettings();
 
 
 
 
 
 
 
 
 
 
1308
 
1309
- apbct_remove_upd_folder( APBCT_DIR_PATH . '/fw_files' );
 
 
1310
 
1311
- if( $apbct->is_multisite ){
1312
- $apbct->network_settings = array_merge( (array) $apbct->network_settings, $apbct->default_network_settings );
1313
- $apbct->save('network_settings');
1314
- }
 
1315
 
1316
- apbct_remove_upd_folder( ABSPATH . '/wp-admin/fw_files' );
1317
- apbct_remove_upd_folder( Server::get('DOCUMENT_ROOT') . '/fw_files' );
1318
- $file_path = Server::get('DOCUMENT_ROOT') . '/fw_filesindex.php';
1319
- if( is_file( $file_path ) && is_writable( $file_path ) ){
1320
- unlink( $file_path );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1321
  }
1322
  }
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
  use Cleantalk\ApbctWP\Cron;
4
+ use Cleantalk\ApbctWP\Helper;
5
  use Cleantalk\Common\Schema;
6
  use Cleantalk\Variables\Server;
7
 
15
  *
16
  * @psalm-suppress PossiblyUndefinedIntArrayOffset
17
  */
18
+ function apbct_run_update_actions($current_version, $new_version)
19
+ {
20
+ $current_version_arr = apbct_version_standardization($current_version);
21
+ $new_version_arr = apbct_version_standardization($new_version);
22
+
23
+ $current_version_str = implode('.', $current_version_arr);
24
+ $new_version_str = implode('.', $new_version_arr);
25
+
26
+ for ( $ver_major = $current_version_arr[0]; $ver_major <= $current_version_arr[0]; $ver_major++ ) {
27
+ for ( $ver_minor = 0; $ver_minor <= 300; $ver_minor++ ) {
28
+ for ( $ver_fix = 0; $ver_fix <= 10; $ver_fix++ ) {
29
+ if ( version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $current_version_str, '<=') ) {
30
+ continue;
31
+ }
32
+
33
+ if ( function_exists("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}") ) {
34
+ $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}_{$ver_fix}");
35
+ if ( ! empty($result['error']) ) {
36
+ break;
37
+ }
38
+ }
39
+
40
+ if ( $ver_fix == 0 && function_exists("apbct_update_to_{$ver_major}_{$ver_minor}") ) {
41
+ $result = call_user_func("apbct_update_to_{$ver_major}_{$ver_minor}");
42
+ if ( ! empty($result['error']) ) {
43
+ break;
44
+ }
45
+ }
46
+
47
+ if ( version_compare("{$ver_major}.{$ver_minor}.{$ver_fix}", $new_version_str, '>=') ) {
48
+ break(2);
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ return true;
 
 
 
55
  }
56
 
57
  /**
61
  *
62
  * @return array
63
  */
64
+ function apbct_version_standardization($version)
65
+ {
66
+ $parsed_version = explode('.', $version);
67
 
68
+ $parsed_version[0] = ! empty($parsed_version[0]) ? (int)$parsed_version[0] : 0;
69
+ $parsed_version[1] = ! empty($parsed_version[1]) ? (int)$parsed_version[1] : 0;
70
+ $parsed_version[2] = ! empty($parsed_version[2]) ? (int)$parsed_version[2] : 0;
71
 
72
+ return $parsed_version;
73
  }
74
 
75
  /**
79
  *
80
  * @return array
81
  */
82
+ function apbct_get_table_columns($table_name)
83
+ {
84
+ global $wpdb;
85
+ $query = 'SHOW COLUMNS FROM ' . $table_name;
86
+ $res = $wpdb->get_results($query, ARRAY_A);
87
+ $columns_names = array();
88
+ foreach ( $res as $column ) {
89
+ $columns_names[] = $column['Field'];
90
+ }
91
+
92
+ return $columns_names;
93
  }
94
 
95
  /**
96
  * @return void
97
  */
98
+ function apbct_update_to_5_50_0()
99
+ {
100
+ global $wpdb;
101
+ $wpdb->query(
102
+ 'CREATE TABLE IF NOT EXISTS `' . APBCT_TBL_FIREWALL_DATA . '` (
103
  `network` int(11) unsigned NOT NULL,
104
  `mask` int(11) unsigned NOT NULL,
105
  INDEX ( `network` , `mask` )
106
+ );'
107
+ );
108
+
109
+ $wpdb->query(
110
+ 'CREATE TABLE IF NOT EXISTS `' . APBCT_TBL_FIREWALL_LOG . '` (
111
  `ip` VARCHAR(15) NOT NULL ,
112
  `all` INT NOT NULL ,
113
  `blocked` INT NOT NULL ,
114
  `timestamp` INT NOT NULL ,
115
+ PRIMARY KEY (`ip`));'
116
+ );
117
  }
118
 
119
  /**
120
  * @return void
121
  */
122
+ function apbct_update_to_5_56_0()
123
+ {
124
+ if ( ! wp_next_scheduled('cleantalk_update_sfw_hook') ) {
125
+ wp_schedule_event(time() + 1800, 'daily', 'cleantalk_update_sfw_hook');
126
+ }
127
  }
128
 
129
  /**
130
  * @return void
131
  */
132
+ function apbct_update_to_5_70_0()
133
+ {
134
+ global $wpdb;
135
+
136
+ if ( ! in_array('all_entries', $wpdb->get_col('DESC ' . APBCT_TBL_FIREWALL_LOG, 0)) ) {
137
+ $wpdb->query(
138
+ 'ALTER TABLE `' . APBCT_TBL_FIREWALL_LOG . '`
139
  CHANGE `all` `all_entries` INT(11) NOT NULL,
140
  CHANGE `blocked` `blocked_entries` INT(11) NOT NULL,
141
  CHANGE `timestamp` `entries_timestamp` INT(11) NOT NULL;'
142
+ );
143
+ }
144
+
145
+ // Deleting usless data
146
+ delete_option('cleantalk_sends_reports_till');
147
+ delete_option('cleantalk_activation_timestamp');
148
+
149
+ // Disabling WP_Cron tasks
150
+ wp_clear_scheduled_hook('cleantalk_send_daily_report_hook');
151
+ wp_clear_scheduled_hook('ct_hourly_event_hook');
152
+ wp_clear_scheduled_hook('ct_send_sfw_log');
153
+ wp_clear_scheduled_hook('cleantalk_update_sfw_hook');
154
+ wp_clear_scheduled_hook('cleantalk_get_brief_data_hook');
155
+
156
+ // Adding Self cron system tasks
157
+ $cron = new Cron();
158
+ $cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // New
159
+ $cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500);
160
+ $cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500);
161
+ $cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 43200);
162
+ $cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // New
163
+ $cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500);
164
  }
165
 
166
  /**
167
  * @return void
168
  */
169
+ function apbct_update_to_5_74_0()
170
+ {
171
+ $cron = new Cron();
172
+ $cron->removeTask('send_daily_request');
173
  }
174
 
175
  /**
176
  * @return void
177
  */
178
+ function apbct_update_to_5_97_0()
179
+ {
180
+ global $apbct;
181
+
182
+ if ( count($apbct->data['connection_reports']['negative_report']) >= 20 ) {
183
+ $apbct->data['connection_reports']['negative_report'] = array_slice(
184
+ $apbct->data['connection_reports']['negative_report'],
185
+ -20,
186
+ 20
187
+ );
188
+ }
189
+
190
+ $apbct->saveData();
191
  }
192
 
193
  /**
194
  * @return void
195
  */
196
+ function apbct_update_to_5_109_0()
197
+ {
198
+ global $apbct, $wpdb;
199
+
200
+ if ( apbct_is_plugin_active_for_network($apbct->base_name) && ! defined('CLEANTALK_ACCESS_KEY') ) {
201
+ $sfw_data_query = 'CREATE TABLE IF NOT EXISTS `%s` (
 
202
  `network` int(11) unsigned NOT NULL,
203
  `mask` int(11) unsigned NOT NULL,
204
  INDEX ( `network` , `mask` )
205
  );';
206
 
207
+ $sfw_log_query = 'CREATE TABLE IF NOT EXISTS `%s` (
208
  `ip` VARCHAR(15) NOT NULL,
209
  `all_entries` INT NOT NULL,
210
  `blocked_entries` INT NOT NULL,
211
  `entries_timestamp` INT NOT NULL,
212
  PRIMARY KEY (`ip`));';
213
 
214
+ $initial_blog = get_current_blog_id();
215
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
216
+ foreach ( $blogs as $blog ) {
217
+ switch_to_blog($blog);
218
+ $wpdb->query(
219
+ sprintf($sfw_data_query, $wpdb->prefix . 'cleantalk_sfw')
220
+ ); // Table for SpamFireWall data
221
+ $wpdb->query(sprintf($sfw_log_query, $wpdb->prefix . 'cleantalk_sfw_logs')); // Table for SpamFireWall logs
222
+ // Cron tasks
223
+ $cron = new Cron();
224
+ $cron->addTask(
225
+ 'check_account_status',
226
+ 'ct_account_status_check',
227
+ 3600,
228
+ time() + 1800
229
+ ); // Checks account status
230
+ $cron->addTask(
231
+ 'delete_spam_comments',
232
+ 'ct_delete_spam_comments',
233
+ 3600,
234
+ time() + 3500
235
+ ); // Formerly ct_hourly_event_hook()
236
+ $cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
237
+ $cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 300); // SFW update
238
+ $cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
239
+ $cron->addTask(
240
+ 'get_brief_data',
241
+ 'cleantalk_get_brief_data',
242
+ 86400,
243
+ time() + 3500
244
+ ); // Get data for dashboard widget
245
+ $cron->addTask(
246
+ 'send_connection_report',
247
+ 'ct_mail_send_connection_report',
248
+ 86400,
249
+ time() + 3500
250
+ ); // Send connection report to welcome@cleantalk.org
251
+ }
252
+ switch_to_blog($initial_blog);
253
+ }
254
  }
255
 
256
  /**
257
  * @return void
258
  */
259
+ function apbct_update_to_5_110_0()
260
+ {
261
+ global $apbct;
262
+ unset($apbct->data['last_remote_call']);
263
+ $apbct->saveData;
264
+ $apbct->save('remote_calls');
265
  }
266
 
267
  /**
268
  * @return void
269
  */
270
+ function apbct_update_to_5_116_0()
271
+ {
272
+ global $apbct, $wpdb;
273
 
274
+ $apbct->settings['store_urls'] = 0;
275
+ $apbct->settings['store_urls__sessions'] = 0;
276
+ $apbct->saveSettings();
277
+
278
+ $wpdb->query(
279
+ 'CREATE TABLE IF NOT EXISTS `' . APBCT_TBL_SESSIONS . '` (
 
 
 
 
 
 
280
  `id` VARCHAR(64) NOT NULL,
281
  `name` TEXT NOT NULL,
282
  `value` TEXT NULL,
283
  `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
284
  PRIMARY KEY (`id`, `name`(10)));'
285
+ );
286
  }
287
 
288
  /**
289
  * @return void
290
  */
291
+ function apbct_update_to_5_116_1()
292
+ {
293
+ global $wpdb;
294
+
295
+ $wpdb->query(
296
+ 'CREATE TABLE IF NOT EXISTS `' . APBCT_TBL_SESSIONS . '` (
297
  `id` VARCHAR(64) NOT NULL,
298
  `name` TEXT NOT NULL,
299
  `value` TEXT NULL,
300
  `last_update` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
301
  PRIMARY KEY (`id`, `name`(10)));'
302
+ );
303
  }
304
 
305
  /**
306
  * @return void
307
  */
308
+ function apbct_update_to_5_116_2()
309
+ {
310
+ global $wpdb;
311
+
312
+ $wpdb->query(
313
+ 'CREATE TABLE IF NOT EXISTS `' . APBCT_TBL_SESSIONS . '` (
314
  `id` VARCHAR(64) NOT NULL,
315
  `name` TEXT NOT NULL,
316
  `value` TEXT NULL DEFAULT NULL,
317
  `last_update` DATETIME NULL DEFAULT NULL,
318
  PRIMARY KEY (`id`, `name`(10)));'
319
+ );
320
  }
321
 
322
  /**
323
  * @return void
324
  */
325
+ function apbct_update_to_5_118_0()
326
+ {
327
+ global $wpdb;
328
+ $wpdb->query(
329
+ 'DELETE
330
+ FROM `' . APBCT_TBL_SESSIONS . '`
331
+ WHERE last_update < NOW() - INTERVAL ' . APBCT_SEESION__LIVE_TIME . ' SECOND;'
332
+ );
333
+ delete_option('cleantalk_server');
334
  }
335
 
336
  /**
337
  * @return void
338
  */
339
+ function apbct_update_to_5_118_2()
340
+ {
341
+ global $apbct;
342
+ $apbct->data['connection_reports'] = $apbct->def_data['connection_reports'];
343
+ $apbct->data['connection_reports']['since'] = date('d M');
344
+ $apbct->saveData();
345
  }
346
 
347
  /**
348
  * @return void
349
  */
350
+ function apbct_update_to_5_119_0()
351
+ {
352
+ global $wpdb;
 
 
353
 
354
+ $wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->prefix . 'cleantalk_sessions`;'); // Deleting session table
355
 
356
+ $sqls = array();
357
+
358
+ // SFW data
359
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
360
  `network` int(11) unsigned NOT NULL,
361
  `mask` int(11) unsigned NOT NULL,
362
  INDEX ( `network` , `mask` )
363
  );';
364
+
365
+ // SFW log
366
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
367
  `ip` VARCHAR(15) NOT NULL,
368
  `all_entries` INT NOT NULL,
369
  `blocked_entries` INT NOT NULL,
370
  `entries_timestamp` INT NOT NULL,
371
  PRIMARY KEY (`ip`));';
372
+
373
+ // Sessions
374
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sessions` (
375
  `id` VARCHAR(64) NOT NULL,
376
  `name` VARCHAR(64) NOT NULL,
377
  `value` TEXT NULL DEFAULT NULL,
378
  `last_update` DATETIME NULL DEFAULT NULL,
379
  PRIMARY KEY (`id`(64), `name`(64)));';
380
+
381
+ apbct_activation__create_tables($sqls);
382
+
383
+ // WPMS
384
+ if ( is_multisite() ) {
385
+ $initial_blog = get_current_blog_id();
386
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
387
+ foreach ( $blogs as $blog ) {
388
+ switch_to_blog($blog);
389
+ $wpdb->query('DROP TABLE IF EXISTS `' . $wpdb->prefix . 'cleantalk_sessions`;'); // Deleting session table
390
+ apbct_activation__create_tables($sqls);
391
+ }
392
+ switch_to_blog($initial_blog);
393
+ }
394
+
395
+ // Drop work url
396
+ update_option(
397
+ 'cleantalk_server',
398
+ array(
399
+ 'ct_work_url' => null,
400
+ 'ct_server_ttl' => 0,
401
+ 'ct_server_changed' => 0,
402
+ )
403
+ );
 
404
  }
405
 
406
  /**
407
  * @return void
408
  */
409
+ function apbct_update_to_5_124_0()
410
+ {
411
+ global $apbct;
412
+ // Deleting error in database because format were changed
413
+ $apbct->errors = array();
414
+ $apbct->saveErrors();
415
  }
416
 
417
  /**
418
  * @return void
419
  */
420
+ function apbct_update_to_5_126_0()
421
+ {
422
+ global $apbct;
423
+ // Enable storing URLs
424
+ $apbct->settings['store_urls'] = 1;
425
+ $apbct->settings['store_urls__sessions'] = 1;
426
+ $apbct->saveSettings();
427
  }
428
 
429
  /**
430
  * @return void
431
  */
432
+ function apbct_update_to_5_127_0()
433
+ {
434
+ global $apbct, $wpdb;
435
+
436
+ // Move exclusions from variable to settins
437
+ global $cleantalk_url_exclusions, $cleantalk_key_exclusions;
438
+ // URLs
439
+ if ( ! empty($cleantalk_url_exclusions) && is_array($cleantalk_url_exclusions) ) {
440
+ $apbct->settings['exclusions__urls'] = implode(',', $cleantalk_url_exclusions);
441
+ if ( APBCT_WPMS ) {
442
+ $initial_blog = get_current_blog_id();
443
+ switch_to_blog(1);
444
+ $apbct->saveSettings();
445
+ switch_to_blog($initial_blog);
446
+ } else {
447
+ $apbct->saveSettings();
448
+ }
449
+ }
450
+ // Fields
451
+ if ( ! empty($cleantalk_key_exclusions) && is_array($cleantalk_key_exclusions) ) {
452
+ $apbct->settings['exclusions__fields'] = implode(',', $cleantalk_key_exclusions);
453
+ if ( APBCT_WPMS ) {
454
+ $initial_blog = get_current_blog_id();
455
+ switch_to_blog(1);
456
+ $apbct->saveSettings();
457
+ switch_to_blog($initial_blog);
458
+ } else {
459
+ $apbct->saveSettings();
460
+ }
461
+ }
462
+
463
+ // Deleting legacy
464
+ if ( isset($apbct->data['testing_failed']) ) {
465
+ unset($apbct->data['testing_failed']);
466
+ $apbct->saveData();
467
+ }
468
+
469
+ if ( APBCT_WPMS ) {
470
+ // Whitelabel
471
+ // Reset "api_key_is_received" flag
472
+ $initial_blog = get_current_blog_id();
473
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
474
+ foreach ( $blogs as $blog ) {
475
+ switch_to_blog($blog);
476
+
477
+ $settings = get_option('cleantalk_settings');
478
+ if ( isset($settings['data__use_static_js_key']) ) {
479
+ $settings['data__use_static_js_key'] = $settings['data__use_static_js_key'] === 0
480
+ ? -1
481
+ : $settings['data__use_static_js_key'];
482
+ update_option('cleantalk_settings', $settings);
483
+
484
+ $data = get_option('cleantalk_data');
485
+ if ( isset($data['white_label_data']['is_key_recieved']) ) {
486
+ unset($data['white_label_data']['is_key_recieved']);
487
+ update_option('cleantalk_data', $data);
488
+ }
489
+ }
490
+ switch_to_blog($initial_blog);
491
+
492
+ if ( defined('APBCT_WHITELABEL') ) {
493
+ $apbct->network_settings = array(
494
+ 'white_label' => defined('APBCT_WHITELABEL') && APBCT_WHITELABEL == true ? 1 : 0,
495
+ 'white_label__plugin_name' => defined('APBCT_WHITELABEL_NAME') ? APBCT_WHITELABEL_NAME : APBCT_NAME,
496
+ );
497
+ } elseif ( defined('CLEANTALK_ACCESS_KEY') ) {
498
+ $apbct->network_settings = array(
499
+ 'allow_custom_key' => 0,
500
+ 'apikey' => CLEANTALK_ACCESS_KEY,
501
+ );
502
+ }
503
+ $apbct->saveNetworkSettings();
504
+ }
505
+ } else {
506
+ // Switch data__use_static_js_key to Auto if it was disabled
507
+ $apbct->settings['data__use_static_js_key'] = $apbct->settings['data__use_static_js_key'] === 0
508
+ ? -1
509
+ : $apbct->settings['data__use_static_js_key'];
510
+ $apbct->saveSettings();
511
+ }
 
512
  }
513
 
514
  /**
515
  * @return void
516
  */
517
+ function apbct_update_to_5_127_1()
518
+ {
519
+ global $apbct;
520
+ if ( APBCT_WPMS && is_main_site() ) {
521
+ $network_settings = get_site_option('cleantalk_network_settings');
522
+ if ( $network_settings !== false && empty($network_settings['allow_custom_key']) && empty($network_settings['white_label']) ) {
523
+ $network_settings['allow_custom_key'] = 1;
524
+ update_site_option('cleantalk_network_settings', $network_settings);
525
+ }
526
+ if ( $network_settings !== false && $network_settings['white_label'] == 1 && $apbct->data['moderate'] == 0 ) {
527
+ ct_account_status_check(
528
+ $network_settings['apikey'] ? $network_settings['apikey'] : $apbct->settings['apikey'],
529
+ false
530
+ );
531
+ }
532
+ } elseif ( is_main_site() ) {
533
+ ct_account_status_check(
534
+ $apbct->settings['apikey'],
535
+ false
536
+ );
537
+ }
538
  }
539
 
540
  /**
541
  * @return void
542
  */
543
+ function apbct_update_to_5_128_0()
544
+ {
545
+ global $apbct;
546
+ $apbct->remote_calls = array();
547
+ $apbct->save('remote_calls');
548
  }
549
 
550
  /**
551
  * @return void
552
  */
553
+ function apbct_update_to_5_133_0()
554
+ {
555
+ $sqls = array();
556
 
557
  // Scan comment/user log
558
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
566
  PRIMARY KEY (`id`));';
567
 
568
  apbct_activation__create_tables($sqls);
 
569
  }
570
 
571
  /**
573
  *
574
  * @psalm-suppress PossiblyUndefinedStringArrayOffset
575
  */
576
+ function apbct_update_to_5_138_0()
577
+ {
578
+ global $wpdb;
579
+ // change name for prevent psalm false positive
580
+ $_wpdb = $wpdb;
581
 
582
+ $sqls = array();
583
 
584
+ // SQL queries for each blog
585
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_spamscan_logs` (
586
  `id` int(11) NOT NULL AUTO_INCREMENT,
587
  `scan_type` varchar(11) NOT NULL,
588
  `start_time` datetime NOT NULL,
591
  `found_spam` int(11) DEFAULT NULL,
592
  `found_bad` int(11) DEFAULT NULL,
593
  PRIMARY KEY (`id`));';
594
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw` (
595
  `network` int(11) unsigned NOT NULL,
596
  `mask` int(11) unsigned NOT NULL,
597
  INDEX ( `network` , `mask` )
598
  );';
599
 
600
+ $table_sfw_columns = apbct_get_table_columns(APBCT_TBL_FIREWALL_DATA);
601
+ if ( ! in_array('status', $table_sfw_columns) ) {
602
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN status TINYINT(1) NOT NULL DEFAULT 0 AFTER mask;';
603
+ }
604
+
605
+ // Actions for WPMS
606
+ if ( APBCT_WPMS ) {
607
+ // Getting all blog ids
608
+ $initial_blog = get_current_blog_id();
609
+ $blogs = $_wpdb->get_results('SELECT blog_id FROM ' . $_wpdb->blogs, OBJECT_K);
610
+ $blogs_ids = array_keys($blogs);
611
+
612
+ // Getting main blog setting
613
+ switch_to_blog(1);
614
+ $main_blog_settings = get_option('cleantalk_settings');
615
+ switch_to_blog($initial_blog);
616
+
617
+ // Getting network settings
618
+ $net_settings = get_site_option('cleantalk_network_settings');
619
+
620
+ foreach ( $blogs_ids as $blog ) {
621
+ // Update time limit to prevent exec time error
622
+ set_time_limit(20);
623
+
624
+ switch_to_blog($blog);
625
+
626
+ // Update SQL structure
627
+ apbct_activation__create_tables($sqls);
628
+
629
+ // Getting key
630
+ $settings = $net_settings['allow_custom_key']
631
+ ? get_option('cleantalk_settings')
632
+ : $main_blog_settings;
633
+
634
+ // Update plugin status
635
+ if ( ! empty($settings['apikey']) ) {
636
+ $data = get_option('cleantalk_data', array());
637
+
638
+ $result = \Cleantalk\ApbctWP\API::methodNoticePaidTill(
639
+ $settings['api_key'],
640
+ preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
641
+ ! is_main_site() && $net_settings['white_label'] ? 'anti-spam-hosting' : 'antispam'
642
+ );
643
+
644
+ if ( empty($result['error']) || ! empty($result['valid']) ) {
645
+ // Notices
646
+ $data['notice_show'] = isset($result['show_notice']) ? (int)$result['show_notice'] : 0;
647
+ $data['notice_renew'] = isset($result['renew']) ? (int)$result['renew'] : 0;
648
+ $data['notice_trial'] = isset($result['trial']) ? (int)$result['trial'] : 0;
649
+ $data['notice_review'] = isset($result['show_review']) ? (int)$result['show_review'] : 0;
650
+ $data['notice_auto_update'] = isset($result['show_auto_update_notice']) ? (int)$result['show_auto_update_notice'] : 0;
651
+
652
+ // Other
653
+ $data['service_id'] = isset($result['service_id']) ? (int)$result['service_id'] : 0;
654
+ $data['valid'] = isset($result['valid']) ? (int)$result['valid'] : 0;
655
+ $data['moderate'] = isset($result['moderate']) ? (int)$result['moderate'] : 0;
656
+ $data['ip_license'] = isset($result['ip_license']) ? (int)$result['ip_license'] : 0;
657
+ $data['moderate_ip'] = isset($result['moderate_ip'], $result['ip_license']) ? (int)$result['moderate_ip'] : 0;
658
+ $data['spam_count'] = isset($result['spam_count']) ? (int)$result['spam_count'] : 0;
659
+ $data['auto_update'] = isset($result['auto_update_app']) ? (int)$result['auto_update_app'] : 0;
660
+ $data['user_token'] = isset($result['user_token']) ? (string)$result['user_token'] : '';
661
+ $data['license_trial'] = isset($result['license_trial']) ? (int)$result['license_trial'] : 0;
662
+ $data['account_name_ob'] = isset($result['account_name_ob']) ? (string)$result['account_name_ob'] : '';
663
+ }
664
+
665
+ $data['key_is_ok'] = ! empty($result['valid'])
666
+ ? true
667
+ : false;
668
+
669
+ update_option('cleantalk_data', $data);
670
+ }
671
+ }
672
+
673
+ // Restoring initial blog
674
+ switch_to_blog($initial_blog);
675
+ // Actions for stand alone blog
676
+ } else {
677
+ apbct_activation__create_tables($sqls);
678
+ }
 
 
 
 
 
 
 
 
 
679
  }
680
 
681
  /**
682
  * @return void
683
  */
684
+ function apbct_update_to_5_142_0()
685
+ {
686
+ $sqls = array();
687
 
688
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
689
  `id` VARCHAR(40) NOT NULL,
690
  `ip` VARCHAR(40) NOT NULL,
691
  `entries` INT DEFAULT 0,
692
  `interval_start` INT NOT NULL,
693
  PRIMARY KEY (`id`));';
694
 
695
+ $table_sfw_logs_columns = apbct_get_table_columns(APBCT_TBL_FIREWALL_LOG);
696
+ if ( ! in_array('id', $table_sfw_logs_columns) ) {
697
+ $status = ! in_array(
698
+ 'status',
699
+ $table_sfw_logs_columns
700
+ ) ? ' ADD COLUMN `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTIBOT\',\'DENY_ANTICRAWLER\') NOT NULL AFTER `ip`,' : '';
701
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
702
  ADD COLUMN `id` VARCHAR(40) NOT NULL FIRST,
703
  ' . $status . '
704
  DROP PRIMARY KEY,
705
  ADD PRIMARY KEY (`id`);';
706
+ }
707
 
708
 
709
+ apbct_activation__create_tables($sqls);
 
 
710
  }
711
 
712
  /**
713
  * @return void
714
  */
715
+ function apbct_update_to_5_142_1()
716
+ {
717
+ $sqls = array();
718
+ $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
719
 
720
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
 
 
 
721
  CHANGE `status` `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW_BY_WHITELIST\',\'PASS_SFW_BY_COOKIE\',\'DENY_ANTICRAWLER\',\'DENY_ANTIFLOOD\') NOT NULL AFTER `ip`;';
722
+
723
+ apbct_activation__create_tables($sqls);
 
724
  }
725
 
726
  /**
727
  * @return void
728
  */
729
+ function apbct_update_to_5_142_2()
730
+ {
731
+ $sqls = array();
732
+ $sqls[] = 'DELETE FROM `%scleantalk_sfw_logs` WHERE 1=1';
733
 
734
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`
 
 
 
735
  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`;';
736
+
737
+ apbct_activation__create_tables($sqls);
 
738
  }
739
 
740
  /**
741
  * @return void
742
  */
743
+ function apbct_update_to_5_142_3()
744
+ {
745
+ global $apbct;
746
 
747
+ $sqls = array();
748
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
749
  `id` VARCHAR(40) NOT NULL,
750
  `ip` VARCHAR(15) NOT NULL,
751
  `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,
753
  `blocked_entries` INT NOT NULL,
754
  `entries_timestamp` INT NOT NULL,
755
  PRIMARY KEY (`id`));';
756
+
757
+ apbct_activation__create_tables($sqls, $apbct->db_prefix);
 
758
  }
759
 
760
  /**
761
  * @return void
762
  */
763
+ function apbct_update_to_5_143_2()
764
+ {
765
+ global $apbct;
766
+
767
+ $sqls = array();
768
+ $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
769
+
770
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
771
  `id` VARCHAR(40) NOT NULL,
772
  `ip` VARCHAR(15) NOT NULL,
773
  `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,
775
  `blocked_entries` INT NOT NULL,
776
  `entries_timestamp` INT NOT NULL,
777
  PRIMARY KEY (`id`));';
778
+
779
+ apbct_activation__create_tables($sqls, $apbct->db_prefix);
 
780
  }
781
 
782
  /**
783
  * @return void
784
  */
785
+ function apbct_update_to_5_146_1()
786
+ {
787
  global $apbct;
788
 
789
+ $sqls = array();
790
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ac_log`;';
791
 
792
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ac_log` (
797
  `interval_start` INT NOT NULL,
798
  PRIMARY KEY (`id`));';
799
 
800
+ apbct_activation__create_tables($sqls, $apbct->db_prefix);
 
801
  }
802
 
803
  /**
804
  * @return void
805
  */
806
+ function apbct_update_to_5_146_3()
807
+ {
808
+ update_option('cleantalk_plugin_request_ids', array());
809
  }
810
 
811
  /**
812
  * @return void
813
  */
814
+ function apbct_update_to_5_148_0()
815
+ {
816
+ $cron = new Cron();
817
+ $cron->updateTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400);
818
  }
819
 
820
  /**
821
  * @return void
822
  */
823
+ function apbct_update_to_5_149_2()
824
+ {
825
  global $apbct;
826
 
827
+ $sqls = array();
828
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
829
  `id` INT(11) NOT NULL,
830
  `ua_template` VARCHAR(255) NULL DEFAULT NULL,
846
  `ua_name` VARCHAR(1024) NOT NULL,
847
  PRIMARY KEY (`id`));';
848
 
849
+ apbct_activation__create_tables($sqls, $apbct->db_prefix);
 
850
  }
851
 
852
  /**
853
  * @return void
854
  */
855
+ function apbct_update_to_5_150_0()
856
+ {
857
+ global $wpdb;
 
 
 
 
 
 
 
 
 
 
858
 
859
+ // Actions for WPMS
860
+ if ( APBCT_WPMS ) {
861
+ // Getting all blog ids
862
+ $initial_blog = get_current_blog_id();
863
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
864
 
865
+ foreach ( $blogs as $blog ) {
866
+ switch_to_blog($blog);
867
 
868
+ update_option('cleantalk_plugin_request_ids', array());
869
+ }
 
870
 
871
+ // Restoring initial blog
872
+ switch_to_blog($initial_blog);
873
+ }
874
  }
875
 
876
  /**
877
  * @return void
878
  */
879
+ function apbct_update_to_5_150_1()
880
+ {
881
  global $apbct;
882
+ $sqls = array();
883
  // UA BL with default charset
884
  $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_ua_bl`;';
885
  $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_ua_bl` (
890
  INDEX ( `ua_template` )
891
  ) DEFAULT CHARSET=utf8;'; // Don't remove the default charset!
892
 
893
+ apbct_activation__create_tables($sqls, $apbct->db_prefix);
894
  }
895
 
896
  /**
897
  * @return void
898
  */
899
+ function apbct_update_to_5_151_1()
900
+ {
901
  global $apbct;
902
+ $apbct->fw_stats['firewall_updating_id'] = isset($apbct->data['firewall_updating_id'])
903
  ? $apbct->data['firewall_updating_id']
904
  : '';
905
+ $apbct->fw_stats['firewall_update_percent'] = isset($apbct->data['firewall_update_percent'])
906
  ? $apbct->data['firewall_update_percent']
907
  : 0;
908
+ $apbct->fw_stats['firewall_updating_last_start'] = isset($apbct->data['firewall_updating_last_start'])
909
  ? $apbct->data['firewall_updating_last_start']
910
  : 0;
911
  $apbct->save('fw_stats');
915
  * @return void
916
  * @throws Exception
917
  */
918
+ function apbct_update_to_5_151_3()
919
  {
920
  global $wpdb, $apbct;
921
+ $sql = 'SHOW TABLES LIKE "%scleantalk_sfw";';
922
+ $sql = sprintf($sql, $wpdb->prefix); // Adding current blog prefix
923
+ $result = $wpdb->get_var($sql);
924
+ if ( ! $result ) {
925
+ apbct_activation__create_tables(Schema::getSchema('sfw'), $apbct->db_prefix);
926
  }
927
  $apbct->fw_stats['firewall_updating_last_start'] = 0;
928
  $apbct->save('fw_stats');
929
  $apbct->stats['sfw']['entries'] = 0;
930
  $apbct->save('stats');
 
931
  }
932
 
933
  /**
934
  * @return void
935
  */
936
+ function apbct_update_to_5_151_6()
937
  {
938
+ global $apbct;
939
+ $apbct->errorDelete('sfw_update', true);
940
  }
941
 
942
  /**
943
  * @return void
944
  */
945
+ function apbct_update_to_5_153_4()
946
+ {
947
  // Adding cooldown to sending SFW logs
948
  global $apbct;
949
  $apbct->stats['sfw']['sending_logs__timestamp'] = 0;
950
  $apbct->save('stats');
 
951
  }
952
 
953
  /**
954
  * @return void
955
  */
956
+ function apbct_update_to_5_154_0()
957
+ {
958
+ global $apbct, $wpdb;
959
+
960
+ // Old setting name => New setting name
961
+ $keys_map = array(
962
+ 'spam_firewall' => 'sfw__enabled',
963
+ 'registrations_test' => 'forms__registrations_test',
964
+ 'comments_test' => 'forms__comments_test',
965
+ 'contact_forms_test' => 'forms__contact_forms_test',
966
+ 'general_contact_forms_test' => 'forms__general_contact_forms_test',
967
+ 'wc_checkout_test' => 'forms__wc_checkout_test',
968
+ 'wc_register_from_order' => 'forms__wc_register_from_order',
969
+ 'search_test' => 'forms__search_test',
970
+ 'check_external' => 'forms__check_external',
971
+ 'check_external__capture_buffer' => 'forms__check_external__capture_buffer',
972
+ 'check_internal' => 'forms__check_internal',
973
+ 'disable_comments__all' => 'comments__disable_comments__all',
974
+ 'disable_comments__posts' => 'comments__disable_comments__posts',
975
+ 'disable_comments__pages' => 'comments__disable_comments__pages',
976
+ 'disable_comments__media' => 'comments__disable_comments__media',
977
+ 'bp_private_messages' => 'comments__bp_private_messages',
978
+ 'check_comments_number' => 'comments__check_comments_number',
979
+ 'remove_old_spam' => 'comments__remove_old_spam',
980
+ 'remove_comments_links' => 'comments__remove_comments_links',
981
+ 'show_check_links' => 'comments__show_check_links',
982
+ 'manage_comments_on_public_page' => 'comments__manage_comments_on_public_page',
983
+ 'protect_logged_in' => 'data__protect_logged_in',
984
+ 'use_ajax' => 'data__use_ajax',
985
+ 'use_static_js_key' => 'data__use_static_js_key',
986
+ 'general_postdata_test' => 'data__general_postdata_test',
987
+ 'set_cookies' => 'data__set_cookies',
988
+ 'set_cookies__sessions' => 'data__set_cookies__sessions',
989
+ 'ssl_on' => 'data__ssl_on',
990
+ 'show_adminbar' => 'admin_bar__show',
991
+ 'all_time_counter' => 'admin_bar__all_time_counter',
992
+ 'daily_counter' => 'admin_bar__daily_counter',
993
+ 'sfw_counter' => 'admin_bar__sfw_counter',
994
+ 'gdpr_enabled' => 'gdpr__enabled',
995
+ 'gdpr_text' => 'gdpr__text',
996
+ 'collect_details' => 'misc__collect_details',
997
+ 'send_connection_reports' => 'misc__send_connection_reports',
998
+ 'async_js' => 'misc__async_js',
999
+ 'debug_ajax' => 'misc__debug_ajax',
1000
+ 'store_urls' => 'misc__store_urls',
1001
+ 'store_urls__sessions' => 'misc__store_urls__sessions',
1002
+ 'complete_deactivation' => 'misc__complete_deactivation',
1003
+ 'use_buitin_http_api' => 'wp__use_builtin_http_api',
1004
+ 'comment_notify' => 'wp__comment_notify',
1005
+ 'comment_notify__roles' => 'wp__comment_notify__roles',
1006
+ 'dashboard_widget__show' => 'wp__dashboard_widget__show',
1007
+ 'allow_custom_key' => 'multisite__allow_custom_key',
1008
+ 'allow_custom_settings' => 'multisite__allow_custom_settings',
1009
+ 'white_label' => 'multisite__white_label',
1010
+ 'white_label__plugin_name' => 'multisite__white_label__plugin_name',
1011
+ 'use_settings_template' => 'multisite__use_settings_template',
1012
+ 'use_settings_template_apply_for_new' => 'multisite__use_settings_template_apply_for_new',
1013
+ 'use_settings_template_apply_for_current' => 'multisite__use_settings_template_apply_for_current',
1014
+ 'use_settings_template_apply_for_current_list_sites' => 'multisite__use_settings_template_apply_for_current_list_sites',
1015
+ );
1016
+
1017
+ if ( is_multisite() ) {
1018
+ $network_settings = get_site_option('cleantalk_network_settings');
1019
+
1020
+ if ( $network_settings ) {
1021
+ $_network_settings = array();
1022
+ // replacing old key to new keys
1023
+ foreach ( $network_settings as $key => $value ) {
1024
+ if ( array_key_exists($key, $keys_map) ) {
1025
+ $_network_settings[$keys_map[$key]] = $value;
1026
+ } else {
1027
+ $_network_settings[$key] = $value;
1028
+ }
1029
+ }
1030
+ if ( ! empty($_network_settings) ) {
1031
+ update_site_option('cleantalk_network_settings', $_network_settings);
1032
+ }
1033
+ }
1034
+
1035
+ $initial_blog = get_current_blog_id();
1036
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
1037
+ foreach ( $blogs as $blog ) {
1038
+ switch_to_blog($blog);
1039
+
1040
+ $settings = get_option('cleantalk_settings');
1041
+
1042
+ if ( $settings ) {
1043
+ // replacing old key to new keys
1044
+ $_settings = array();
1045
+ foreach ( $settings as $key => $value ) {
1046
+ if ( array_key_exists($key, $keys_map) ) {
1047
+ $_settings[$keys_map[$key]] = $value;
1048
+ } else {
1049
+ $_settings[$key] = $value;
1050
+ }
1051
+ }
1052
+ if ( ! empty($_settings) ) {
1053
+ update_option('cleantalk_settings', $_settings);
1054
+ }
1055
+ }
1056
+ }
1057
+ switch_to_blog($initial_blog);
1058
+ } else {
1059
+ $apbct->data['current_settings_template_id'] = null;
1060
+ $apbct->data['current_settings_template_name'] = null;
1061
+ $apbct->saveData();
1062
+
1063
+ $settings = (array)$apbct->settings;
1064
+
1065
+ if ( $settings ) {
1066
+ $_settings = array();
1067
+ // replacing old key to new keys
1068
+ foreach ( $settings as $key => $value ) {
1069
+ if ( array_key_exists($key, $keys_map) ) {
1070
+ $_settings[$keys_map[$key]] = $value;
1071
+ } else {
1072
+ $_settings[$key] = $value;
1073
+ }
1074
+ }
1075
+
1076
+ $apbct->settings = $_settings;
1077
+ $apbct->saveSettings();
1078
+ }
1079
+ }
1080
+
1081
+ $sqls = array();
1082
+
1083
+ $sqls[] = 'DROP TABLE IF EXISTS `%scleantalk_sfw_logs`;';
1084
+
1085
+ $sqls[] = 'CREATE TABLE IF NOT EXISTS `%scleantalk_sfw_logs` (
 
 
 
 
 
1086
  `id` VARCHAR(40) NOT NULL,
1087
  `ip` VARCHAR(15) NOT NULL,
1088
  `status` ENUM(\'PASS_SFW\',\'DENY_SFW\',\'PASS_SFW__BY_WHITELIST\',\'PASS_SFW__BY_COOKIE\',\'DENY_ANTICRAWLER\',\'PASS_ANTICRAWLER\',\'DENY_ANTICRAWLER_UA\',\'PASS_ANTICRAWLER_UA\',\'DENY_ANTIFLOOD\',\'PASS_ANTIFLOOD\',\'DENY_ANTIFLOOD_UA\',\'PASS_ANTIFLOOD_UA\') NULL DEFAULT NULL,
1093
  `ua_name` VARCHAR(1024) NOT NULL,
1094
  PRIMARY KEY (`id`));';
1095
 
1096
+ apbct_activation__create_tables($sqls, $apbct->db_prefix);
 
1097
  }
1098
 
1099
  /**
1100
  * @return void
1101
  */
1102
+ function apbct_update_to_5_156_0()
1103
+ {
1104
  global $apbct;
1105
+
1106
+ $apbct->remote_calls['debug'] = array('last_call' => 0, 'cooldown' => 0);
1107
+ $apbct->remote_calls['debug_sfw'] = array('last_call' => 0, 'cooldown' => 0);
1108
  $apbct->save('remote_calls');
1109
 
1110
  $cron = new Cron();
1111
+ $cron->updateTask('sfw_update', 'apbct_sfw_update__init', 86400, time() + 42300);
 
1112
  }
1113
 
1114
  /**
1115
  * @return void
1116
  */
1117
+ function apbct_update_to_5_157_0()
1118
+ {
1119
  global $apbct;
1120
+
1121
+ $apbct->remote_calls['sfw_update__worker'] = array('last_call' => 0, 'cooldown' => 0);
1122
+ $apbct->save('remote_calls');
1123
+
1124
+ if ( ! empty($apbct->settings['data__set_cookies__sessions']) ) {
1125
  $apbct->settings['data__set_cookies'] = 2;
1126
  }
1127
  $apbct->settings['data__set_cookies__alt_sessions_type'] = 0;
 
 
1128
 
1129
+ $apbct->save('settings');
1130
+
1131
+ cleantalk_get_brief_data($apbct->api_key);
1132
  }
1133
 
1134
  /**
1135
  * @return void
1136
  */
1137
+ function apbct_update_to_5_158_0()
1138
+ {
1139
  global $apbct, $wpdb;
1140
+ // change name for prevent psalm false positive
1141
+ $_wpdb = $wpdb;
1142
+
1143
+ $sqls = array();
1144
 
1145
+ $table_sfw_columns = apbct_get_table_columns(APBCT_TBL_FIREWALL_DATA);
1146
+ $table_sfw_logs_columns = apbct_get_table_columns(APBCT_TBL_FIREWALL_LOG);
1147
 
1148
+ if ( ! in_array('source', $table_sfw_columns) ) {
1149
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `status`;';
1150
+ }
1151
 
1152
+ if ( ! in_array('source', $table_sfw_logs_columns) ) {
1153
+ $network = ! in_array(
1154
+ 'network',
1155
+ $table_sfw_logs_columns
1156
+ ) ? ' ADD COLUMN `network` VARCHAR(20) NULL DEFAULT NULL AFTER `source`,' : '';
1157
+ $first_url = ! in_array(
1158
+ 'first_url',
1159
+ $table_sfw_logs_columns
1160
+ ) ? ' ADD COLUMN `first_url` VARCHAR(100) NULL DEFAULT NULL AFTER `network`,' : '';
1161
+ $last_url = ! in_array(
1162
+ 'last_url',
1163
+ $table_sfw_logs_columns
1164
+ ) ? ' ADD COLUMN `last_url` VARCHAR(100) NULL DEFAULT NULL AFTER `first_url`' : '';
1165
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`'
1166
+ . ' ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `ua_name`,'
1167
+ . $network
1168
+ . $first_url
1169
+ . $last_url
1170
+ . ';';
1171
  }
1172
 
1173
+ if ( APBCT_WPMS ) {
 
 
 
 
 
 
 
 
 
 
 
 
1174
  // Getting all blog ids
1175
+ $initial_blog = get_current_blog_id();
1176
+ $blogs = array_keys($_wpdb->get_results('SELECT blog_id FROM ' . $_wpdb->blogs, OBJECT_K));
1177
+
1178
+ foreach ( $blogs as $blog ) {
 
1179
  switch_to_blog($blog);
1180
  apbct_activation__create_tables($sqls);
1181
  }
1182
+
1183
  // Restoring initial blog
1184
  switch_to_blog($initial_blog);
1185
+ } else {
 
1186
  apbct_activation__create_tables($sqls);
1187
  }
1188
+
1189
  // Update from fix branch
1190
+ if ( APBCT_WPMS && is_main_site() ) {
1191
+ $wp_blogs = $_wpdb->get_results('SELECT blog_id, site_id FROM ' . $_wpdb->blogs, OBJECT_K);
 
1192
  $current_sites_list = $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'];
 
 
 
 
 
 
 
 
 
 
1193
 
1194
+ if ( is_array($wp_blogs) && is_array($current_sites_list) ) {
1195
+ foreach ( $wp_blogs as $blog ) {
1196
+ $blog_details = get_blog_details(array('blog_id' => $blog->blog_id));
1197
+ if ( $blog_details ) {
1198
+ $site_list_index = array_search($blog_details->blogname, $current_sites_list, true);
1199
+ if ( $site_list_index !== false ) {
1200
+ $current_sites_list[$site_list_index] = $blog_details->id;
1201
+ }
1202
+ }
1203
  }
1204
  $apbct->settings['multisite__use_settings_template_apply_for_current_list_sites'] = $current_sites_list;
1205
+ $apbct->settings['comments__hide_website_field'] = '0';
1206
+ $apbct->settings['data__pixel'] = '0';
1207
  $apbct->saveSettings();
1208
  }
1209
+ } else {
 
1210
  $apbct->settings['comments__hide_website_field'] = '0';
1211
+ $apbct->settings['data__pixel'] = '0';
1212
  $apbct->saveSettings();
1213
  }
1214
  }
1216
  /**
1217
  * @return void
1218
  */
1219
+ function apbct_update_to_5_158_2()
1220
+ {
1221
+ global $apbct;
1222
+ $apbct->stats['cron']['last_start'] = 0;
1223
+ $apbct->save('stats');
1224
  }
1225
 
1226
  /**
1227
  * @return void
1228
  */
1229
+ function apbct_update_to_5_159_6()
1230
+ {
1231
+ global $wpdb;
1232
+
1233
+ $ct_cron = new Cron();
1234
+
1235
+ if ( is_multisite() ) {
1236
+ $initial_blog = get_current_blog_id();
1237
+ $blogs = array_keys($wpdb->get_results('SELECT blog_id FROM ' . $wpdb->blogs, OBJECT_K));
1238
+ foreach ( $blogs as $blog ) {
1239
+ switch_to_blog($blog);
1240
+ // Cron tasks
1241
+ $ct_cron->addTask(
1242
+ 'check_account_status',
1243
+ 'ct_account_status_check',
1244
+ 3600,
1245
+ time() + 1800
1246
+ ); // Checks account status
1247
+ $ct_cron->addTask(
1248
+ 'delete_spam_comments',
1249
+ 'ct_delete_spam_comments',
1250
+ 3600,
1251
+ time() + 3500
1252
+ ); // Formerly ct_hourly_event_hook()
1253
+ $ct_cron->addTask(
1254
+ 'send_feedback',
1255
+ 'ct_send_feedback',
1256
+ 3600,
1257
+ time() + 3500
1258
+ ); // Formerly ct_hourly_event_hook()
1259
+ $ct_cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400); // SFW update
1260
+ $ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
1261
+ $ct_cron->addTask(
1262
+ 'get_brief_data',
1263
+ 'cleantalk_get_brief_data',
1264
+ 86400,
1265
+ time() + 3500
1266
+ ); // Get data for dashboard widget
1267
+ $ct_cron->addTask(
1268
+ 'send_connection_report',
1269
+ 'ct_mail_send_connection_report',
1270
+ 86400,
1271
+ time() + 3500
1272
+ ); // Send connection report to welcome@cleantalk.org
1273
+ $ct_cron->addTask(
1274
+ 'antiflood__clear_table',
1275
+ 'apbct_antiflood__clear_table',
1276
+ 86400,
1277
+ time() + 300
1278
+ ); // Clear Anti-Flood table
1279
+ }
1280
+ switch_to_blog($initial_blog);
1281
+ } else {
1282
+ // Cron tasks
1283
+ $ct_cron->addTask(
1284
+ 'check_account_status',
1285
+ 'ct_account_status_check',
1286
+ 3600,
1287
+ time() + 1800
1288
+ ); // Checks account status
1289
+ $ct_cron->addTask(
1290
+ 'delete_spam_comments',
1291
+ 'ct_delete_spam_comments',
1292
+ 3600,
1293
+ time() + 3500
1294
+ ); // Formerly ct_hourly_event_hook()
1295
+ $ct_cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
1296
+ $ct_cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400); // SFW update
1297
+ $ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
1298
+ $ct_cron->addTask(
1299
+ 'get_brief_data',
1300
+ 'cleantalk_get_brief_data',
1301
+ 86400,
1302
+ time() + 3500
1303
+ ); // Get data for dashboard widget
1304
+ $ct_cron->addTask(
1305
+ 'send_connection_report',
1306
+ 'ct_mail_send_connection_report',
1307
+ 86400,
1308
+ time() + 3500
1309
+ ); // Send connection report to welcome@cleantalk.org
1310
+ $ct_cron->addTask(
1311
+ 'antiflood__clear_table',
1312
+ 'apbct_antiflood__clear_table',
1313
+ 86400,
1314
+ time() + 300
1315
+ ); // Clear Anti-Flood table
1316
+ }
1317
  }
1318
 
1319
  /**
1320
  * @return void
1321
  */
1322
+ function apbct_update_to_5_159_7()
1323
+ {
1324
+ global $wpdb;
1325
+ // change name for prevent psalm false positive
1326
+ $_wpdb = $wpdb;
1327
+
1328
+ $sqls = array();
1329
+
1330
+ $table_sfw_columns = apbct_get_table_columns(APBCT_TBL_FIREWALL_DATA);
1331
+ $table_sfw_logs_columns = apbct_get_table_columns(APBCT_TBL_FIREWALL_LOG);
1332
+
1333
+ if ( ! in_array('source', $table_sfw_columns) ) {
1334
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw` ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `status`;';
1335
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1336
 
1337
+ if ( ! in_array('source', $table_sfw_logs_columns) ) {
1338
+ $network = ! in_array(
1339
+ 'network',
1340
+ $table_sfw_logs_columns
1341
+ ) ? ' ADD COLUMN `network` VARCHAR(20) NULL DEFAULT NULL AFTER `source`,' : '';
1342
+ $first_url = ! in_array(
1343
+ 'first_url',
1344
+ $table_sfw_logs_columns
1345
+ ) ? ' ADD COLUMN `first_url` VARCHAR(100) NULL DEFAULT NULL AFTER `network`,' : '';
1346
+ $last_url = ! in_array(
1347
+ 'last_url',
1348
+ $table_sfw_logs_columns
1349
+ ) ? ' ADD COLUMN `last_url` VARCHAR(100) NULL DEFAULT NULL AFTER `first_url`' : '';
1350
+ $sqls[] = 'ALTER TABLE `%scleantalk_sfw_logs`'
1351
+ . ' ADD COLUMN `source` TINYINT(1) NULL DEFAULT NULL AFTER `ua_name`,'
1352
+ . $network
1353
+ . $first_url
1354
+ . $last_url
1355
+ . ';';
1356
+ }
1357
+
1358
+ if ( ! empty($sqls) ) {
1359
+ if ( APBCT_WPMS ) {
1360
+ // Getting all blog ids
1361
+ $initial_blog = get_current_blog_id();
1362
+ $blogs = array_keys($_wpdb->get_results('SELECT blog_id FROM ' . $_wpdb->blogs, OBJECT_K));
1363
+
1364
+ foreach ( $blogs as $blog ) {
1365
+ switch_to_blog($blog);
1366
+ apbct_activation__create_tables($sqls);
1367
+ }
1368
+
1369
+ // Restoring initial blog
1370
+ switch_to_blog($initial_blog);
1371
+ } else {
1372
+ apbct_activation__create_tables($sqls);
1373
+ }
1374
+ }
1375
  }
1376
 
1377
  /**
1378
  * @return void
1379
  */
1380
+ function apbct_update_to_5_159_9()
1381
+ {
1382
+ $cron = new Cron();
1383
+ $cron->addTask('rotate_moderate', 'apbct_rotate_moderate', 86400, time() + 3500); // Rotate moderate server
1384
  }
1385
 
1386
  /**
1387
  * @return void
1388
  */
1389
+ function apbct_update_to_5_160_4()
1390
+ {
1391
+ global $apbct;
1392
+
1393
+ $apbct->settings['sfw__random_get'] = '1';
1394
+ $apbct->saveSettings();
1395
 
1396
+ apbct_remove_upd_folder(APBCT_DIR_PATH . '/fw_files');
1397
 
1398
+ if ( $apbct->is_multisite ) {
1399
+ $apbct->network_settings = array_merge((array)$apbct->network_settings, $apbct->default_network_settings);
1400
+ $apbct->save('network_settings');
1401
+ }
1402
+
1403
+ apbct_remove_upd_folder(ABSPATH . '/wp-admin/fw_files');
1404
+ apbct_remove_upd_folder(Server::get('DOCUMENT_ROOT') . '/fw_files');
1405
+ $file_path = Server::get('DOCUMENT_ROOT') . '/fw_filesindex.php';
1406
+ if ( is_file($file_path) && is_writable($file_path) ) {
1407
+ unlink($file_path);
1408
+ }
1409
+ }
1410
 
1411
+ function apbct_update_to_5_161_1()
1412
+ {
1413
+ global $apbct;
1414
 
1415
+ if ( $apbct->is_multisite ) {
1416
+ $apbct->network_settings = array_merge((array)$apbct->network_settings, $apbct->default_network_settings);
1417
+ $apbct->saveNetworkSettings();
1418
+ }
1419
+ }
1420
 
1421
+ function apbct_update_to_5_161_2()
1422
+ {
1423
+ global $apbct;
1424
+ // Set type of the alt cookies
1425
+ if ( $apbct->settings['data__set_cookies'] == 2 ) {
1426
+ // Check custom ajax availability
1427
+ $res_custom_ajax = Helper::httpRequestGetResponseCode(esc_url(APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php'));
1428
+ if ( $res_custom_ajax != 400 ) {
1429
+ // Check rest availability
1430
+ $res_rest = Helper::httpRequestGetResponseCode(esc_url(apbct_get_rest_url()));
1431
+ if ( $res_rest != 200 ) {
1432
+ // Check WP ajax availability
1433
+ $res_ajax = Helper::httpRequestGetResponseCode(admin_url('admin-ajax.php'));
1434
+ if ( $res_ajax != 400 ) {
1435
+ // There is no available alt cookies types. Cookies will be disabled.
1436
+ $apbct->settings['data__set_cookies'] = 0;
1437
+ } else {
1438
+ $apbct->settings['data__set_cookies__alt_sessions_type'] = 2;
1439
+ }
1440
+ } else {
1441
+ $apbct->settings['data__set_cookies__alt_sessions_type'] = 0;
1442
+ }
1443
+ } else {
1444
+ $apbct->settings['data__set_cookies__alt_sessions_type'] = 1;
1445
+ }
1446
+ $apbct->saveSettings();
1447
  }
1448
  }
1449
+
1450
+ /**
1451
+ * 5.162
1452
+ */
1453
+ function apbct_update_to_5_162_0()
1454
+ {
1455
+ global $apbct;
1456
+
1457
+ $apbct->settings['forms__wc_honeypot'] = '1';
1458
+ $apbct->saveSettings();
1459
+ }
inc/cleantalkWidget.php ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Hooks on widget loads
4
+ add_action('widgets_init', 'cleantalk_load_widget');
5
+
6
+ /**
7
+ * Register and load the widget
8
+ */
9
+ function cleantalk_load_widget()
10
+ {
11
+ register_widget('CleantalkWidget');
12
+ }
13
+
14
+ /**
15
+ * @psalm-suppress UnusedClass
16
+ */
17
+ class CleantalkWidget extends WP_Widget // phpcs:ignore PSR1.Classes.ClassDeclaration.MissingNamespace
18
+ {
19
+ public function __construct()
20
+ {
21
+ parent::__construct(
22
+ // Base ID of your widget
23
+ 'cleantalk_widget',
24
+ // Widget name will appear in UI
25
+ __('CleanTalk Widget', 'cleantalk-spam-protect'),
26
+ // Widget description
27
+ array('description' => __('CleanTalk widget', 'cleantalk-spam-protect'),)
28
+ );
29
+ }
30
+
31
+ // Creating widget front-end
32
+ // This is where the action happens
33
+ public function widget($args, $instance)
34
+ {
35
+ global $apbct;
36
+
37
+ $instance['title'] = isset($instance['title']) ? $instance['title'] : __(
38
+ 'Spam blocked',
39
+ 'cleantalk-spam-protect'
40
+ );
41
+ $title = apply_filters('widget_title', $instance['title']);
42
+ echo $args['before_widget'];
43
+
44
+ // Showing title
45
+ if ( ! empty($title) ) {
46
+ echo $args['before_title'] . $title . $args['after_title'];
47
+ }
48
+
49
+ // Parsing incoming params
50
+ $blocked = number_format($apbct->data['spam_count'], 0, ',', ' ');
51
+
52
+ $a_style = 'cursor: pointer; display: block; padding: 5px 0 5px; text-align: center; text-decoration: none; border-radius: 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; font-weight: normal; width: 100%; ';
53
+ $strong_style = 'display: block; font-size: 15px; line-height: 16px; padding: 0 13px; white-space: nowrap; ';
54
+
55
+ if ( ! isset($instance['style']) ) {
56
+ $instance['style'] = 'cleantalk';
57
+ }
58
+
59
+ switch ( $instance['style'] ) {
60
+ case 'cleantalk':
61
+ $a_style .= 'background: #3090C7; background-image: -moz-linear-gradient(0% 100% 90deg,#2060a7,#3090C7); background-image: -webkit-gradient(linear,0% 0,0% 100%,from(#3090C7),to(#2060A7)); border: 1px solid #33eeee; color: #AFCA63;';
62
+ $strong_style .= 'color: #FFF;';
63
+ break;
64
+ case 'light':
65
+ $a_style .= 'background: #fafafa; background-image: -moz-linear-gradient(0% 100% 90deg,#ddd,#fff); background-image: -webkit-gradient(linear,0% 0,0% 100%,from(#fff),to(#ddd)); border: 1px solid #ddd; color: #000;';
66
+ $strong_style .= 'color: #000;';
67
+ break;
68
+ case 'ex_light':
69
+ $a_style .= 'background: #fff; border: 1px solid #ddd; color: #777;';
70
+ $strong_style .= 'color: #555;';
71
+ break;
72
+ case 'dark':
73
+ $a_style .= 'background: #333; background-image: -moz-linear-gradient(0% 100% 90deg,#555,#000); background-image: -webkit-gradient(linear,0% 0,0% 100%,from(#000),to(#555)); border: 1px solid #999; color: #fff;';
74
+ $strong_style .= 'color: #FFF;';
75
+ break;
76
+ }
77
+
78
+ // This is where you run the code and display the output
79
+ echo '<div style="width:auto;">'
80
+ . '<a href="https://cleantalk.org' . (! empty($instance['refid']) ? '?pid=' . $instance['refid'] : '') . '" target="_blank" title="' . __(
81
+ 'CleanTalk\'s main page',
82
+ 'cleantalk-spam-protect'
83
+ ) . '" style="' . $a_style . '">'
84
+ . '<strong style="' . $strong_style . '"><b>' . $blocked . '</b> ' . __(
85
+ 'spam',
86
+ 'cleantalk-spam-protect'
87
+ ) . '</strong> ' . __('blocked by', 'cleantalk-spam-protect') . ' <strong>CleanTalk</strong>'
88
+ . '</a>'
89
+ . '</div>';
90
+
91
+ echo $args['after_widget'];
92
+ }
93
+
94
+ // Widget Backend
95
+ public function form($instance)
96
+ {
97
+ // Widget admin form
98
+
99
+ $title = isset($instance['title']) ? $instance['title'] : __('Spam blocked', 'cleantalk-spam-protect');
100
+ $style = isset($instance['style']) ? $instance['style'] : 'ct_style';
101
+ $refid = isset($instance['refid']) ? $instance['refid'] : '';
102
+ // Title field
103
+ echo '<p>'
104
+ . '<label for="' . $this->get_field_id('title') . '">' . __(
105
+ 'Title:',
106
+ 'cleantalk-spam-protect'
107
+ ) . '</label>'
108
+ . '<input
109
+ class="widefat"
110
+ id="' . $this->get_field_id('title') . '"
111
+ name="' . $this->get_field_name('title') . '"
112
+ type="text"
113
+ value="' . esc_attr($title) . '" />'
114
+ . '</p>';
115
+ // Style
116
+ echo '<p>'
117
+ . '<label for="' . $this->get_field_id('style') . '">' . __(
118
+ 'Style:',
119
+ 'cleantalk-spam-protect'
120
+ ) . '</label>'
121
+ . '<select id="' . $this->get_field_id('style') . '" class="widefat" name="' . $this->get_field_name('style') . '">'
122
+ . '<option ' . ($style === 'cleantalk' ? 'selected' : '') . ' value="cleantalk">' . __(
123
+ 'CleanTalk\'s Style',
124
+ 'cleantalk-spam-protect'
125
+ ) . '</option>'
126
+ . '<option ' . ($style === 'light' ? 'selected' : '') . ' value="light">' . __(
127
+ 'Light',
128
+ 'cleantalk-spam-protect'
129
+ ) . '</option>'
130
+ . '<option ' . ($style === 'ex_light' ? 'selected' : '') . ' value="ex_light">' . __(
131
+ 'Extremely Light',
132
+ 'cleantalk-spam-protect'
133
+ ) . '</option>'
134
+ . '<option ' . ($style === 'dark' ? 'selected' : '') . ' value="dark">' . __(
135
+ 'Dark',
136
+ 'cleantalk-spam-protect'
137
+ ) . '</option>'
138
+ . '</select>'
139
+ . '</p>';
140
+ // Ref ID
141
+ echo '<p>'
142
+ . '<label for="' . $this->get_field_id('refid') . '">' .
143
+ __('Referal link ID:', 'cleantalk-spam-protect') .
144
+ '</label>'
145
+ . '<input
146
+ class="widefat"
147
+ id="' . $this->get_field_id('refid') . '"
148
+ name="' . $this->get_field_name('refid') . '"
149
+ type="text"
150
+ value="' . $refid . '" />'
151
+ . '</p>';
152
+
153
+ return 'noform';
154
+ }
155
+
156
+ // Updating widget replacing old instances with new
157
+ public function update($new_instance, $old_instance)
158
+ {
159
+ $instance = array();
160
+ $instance['title'] = ( ! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
161
+ $instance['style'] = ( ! empty($new_instance['style'])) ? strip_tags($new_instance['style']) : '';
162
+ $instance['refid'] = ( ! empty($new_instance['refid'])) ? strip_tags($new_instance['refid']) : '';
163
+
164
+ return $instance;
165
+ }
166
+ }
js/apbct-public--functions.min.js CHANGED
@@ -1,2 +1,2 @@
1
- function ctSetCookie(o,t,n){var e;("string"==typeof o&&"string"==typeof t||"number"==typeof t)&&(e="ct_pointer_data"===o||"ct_user_info"===o,o=[[o,t,n]]),0!=+ctPublicFunctions.data__set_cookies&&(1==+ctPublicFunctions.data__set_cookies?o.forEach(function(o,t,n){var e=void 0!==o[2]?"expires="+e+"; ":"",c="https:"===location.protocol?"; secure":"";document.cookie=o[0]+"="+encodeURIComponent(o[1])+"; "+e+"path=/; samesite=lax"+c}):2!=+ctPublicFunctions.data__set_cookies||e||(0==+ctPublicFunctions.data__set_cookies__alt_sessions_type?apbct_public_sendREST("alt_sessions",{method:"POST",data:{cookies:o}}):1==+ctPublicFunctions.data__set_cookies__alt_sessions_type&&apbct_public_sendAJAX({action:"apbct_alt_session__save__AJAX",cookies:o},{apbct_ajax:1,notJson:1})))}function apbct_public_sendAJAX(t,n,e){var c=n.callback||null,s=n.callback_context||null,a=n.callback_params||null,o=n.async||!0,l=n.notJson||null,r=n.timeout||15e3,e=e||null,i=n.button||null,u=n.spinner||null,_=n.progressbar||null,p=n.silent||null,b=n.no_nonce||null,d=n.apbct_ajax||null;"string"==typeof t?(b||(t=t+"&_ajax_nonce="+ctPublicFunctions._ajax_nonce),t=t+"&no_cache="+Math.random()):(b||(t._ajax_nonce=ctPublicFunctions._ajax_nonce),t.no_cache=Math.random()),i&&(i.setAttribute("disabled","disabled"),i.style.cursor="not-allowed"),u&&jQuery(u).css("display","inline"),jQuery.ajax({type:"POST",url:d?ctPublicFunctions._apbct_ajax_url:ctPublicFunctions._ajax_url,data:t,async:o,success:function(o){i&&(i.removeAttribute("disabled"),i.style.cursor="pointer"),u&&jQuery(u).css("display","none"),l||(o=JSON.parse(o)),o.error?(setTimeout(function(){_&&_.fadeOut("slow")},1e3),console.log("Error happens: "+(o.error||"Unkown"))):c&&(a?c.apply(s,a.concat(o,t,n,e)):c(o,t,n,e))},error:function(o,t,n){i&&(i.removeAttribute("disabled"),i.style.cursor="pointer"),u&&jQuery(u).css("display","none"),n&&!p&&(console.log("APBCT_AJAX_ERROR"),console.log(o),console.log(t),console.log("Anti-spam by Cleantalk plugin error: "+n+"Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/"))},timeout:r})}function apbct_public_sendREST(t,n){var e=n.callback||null,o=n.data||[],c=n.method||"POST";jQuery.ajax({type:c,url:ctPublicFunctions._rest_url+"cleantalk-antispam/v1/"+t,data:o,beforeSend:function(o){o.setRequestHeader("X-WP-Nonce",ctPublicFunctions._rest_nonce)},success:function(o){o.error?console.log("Error happens: "+(o.error||"Unknown")):e&&e(o,t,n,null)},error:function(o,t,n){n&&(console.log("APBCT_REST_ERROR"),console.log(o),console.log(t),console.log("Anti-spam by Cleantalk plugin REST API error: "+n+" Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/"))}})}
1
+ function ctSetCookie(o,t,n){var e;("string"==typeof o&&"string"==typeof t||"number"==typeof t)&&(e="ct_pointer_data"===o||"ct_user_info"===o,o=[[o,t,n]]),0==+ctPublicFunctions.data__set_cookies||(1==+ctPublicFunctions.data__set_cookies?o.forEach(function(o,t,n){var e=void 0!==o[2]?"expires="+e+"; ":"",c="https:"===location.protocol?"; secure":"";document.cookie=o[0]+"="+encodeURIComponent(o[1])+"; "+e+"path=/; samesite=lax"+c}):2!=+ctPublicFunctions.data__set_cookies||e||(0==+ctPublicFunctions.data__set_cookies__alt_sessions_type?apbct_public_sendREST("alt_sessions",{method:"POST",data:{cookies:o}}):1==+ctPublicFunctions.data__set_cookies__alt_sessions_type?apbct_public_sendAJAX({action:"apbct_alt_session__save__AJAX",cookies:o},{apbct_ajax:1,notJson:1}):2==+ctPublicFunctions.data__set_cookies__alt_sessions_type&&apbct_public_sendAJAX({action:"apbct_alt_session__save__AJAX",cookies:o},{notJson:1})))}function apbct_public_sendAJAX(t,n,e){var c=n.callback||null,s=n.callback_context||null,a=n.callback_params||null,o=n.async||!0,l=n.notJson||null,i=n.timeout||15e3,e=e||null,r=n.button||null,u=n.spinner||null,_=n.progressbar||null,p=n.silent||null,b=n.no_nonce||null,d=n.apbct_ajax||null;"string"==typeof t?t=(t=!b?t+"&_ajax_nonce="+ctPublicFunctions._ajax_nonce:t)+"&no_cache="+Math.random():(b||(t._ajax_nonce=ctPublicFunctions._ajax_nonce),t.no_cache=Math.random()),r&&(r.setAttribute("disabled","disabled"),r.style.cursor="not-allowed"),u&&jQuery(u).css("display","inline"),jQuery.ajax({type:"POST",url:d?ct