Version Description
Jul 29 2021 = * New: SFW. SFW alternative cookie implemented. * New: SFW. AC alternative cookie implemented. * New: SFW. AF alternative cookie implemented. * New: Helper. Curl multi wrapper added. * New: Queue class implemented. * Mod: Changed the processing of the honeypot_field for standard comment. * Mod: Added integration for Wishlist Members registration form. * Mod: Store visited URLs amount reduces to 5 with 128 symbols by URL. * Upd: Public js scripts separated. * Upd: SFW. Updating process modified. * Fix: Moderate rotating fixed. * Fix: SFW. Process file errors handling fixed. * Fix: Pluggable. Expression fixed. * Fix: Ajax. User detection fixed.. * Fix: Ajax. Ajax handlers fixed. * Fix: IP-detection for Cloudflare CDN. * Fix: Skip test for ajax alt_session request. * Fix: Set cookies on dashboard pages even if the setting is off. * Fix: Ajax. Ajax class fixed. * Fix: Users scanner. Remove redundant menu. * Fix: Added an exception for the action edd_process_checkout Easy Didgital Downloads plugi * Fix: SFW. Changed method for getting addr ip. * Fix: Integration. WPForms names gathering fixed. * Fix: SFW. Min update interval decreased to 14400 seconds. * Fix: Integration. WPForms names gathering fixed. * Fix: Cleantalk.php. dns_get_record() error handling. * Fix: Search form integration. PHP Notice. * Fix: Default value for "Alternative Cookie Type" setting. * Fix: SpamFirewall. Omit SFW_IS_DISABLED error. * Fix: SpamFirewall. Updating percent output. * Fix. Settings templates. Sync after template loading. * Fix. SFW. Updating process percents fixed. * Fix. Antispam. All headers parameter fixed.
Release Info
Developer | Safronik |
Plugin | Spam protection, AntiSpam, FireWall by CleanTalk |
Version | 5.160 |
Comparing to | |
See all releases |
Code changes from version 5.159.9 to 5.160
- cleantalk.php +1071 -1101
- inc/cleantalk-admin.php +3 -3
- inc/cleantalk-ajax-handlers.php +5 -1
- inc/cleantalk-ajax.php +1 -0
- inc/cleantalk-autoloader.php +21 -21
- inc/cleantalk-common.php +67 -57
- inc/cleantalk-find-spam.php +1 -0
- inc/cleantalk-pluggable.php +13 -4
- inc/cleantalk-public-integrations.php +498 -335
- inc/cleantalk-public-validate.php +5 -3
- inc/cleantalk-public.php +203 -162
- inc/cleantalk-settings.php +30 -8
- inc/cleantalk-updater.php +9 -1
- js/apbct-public--functions.min.js +2 -0
- js/apbct-public--functions.min.js.map +1 -0
- js/apbct-public.min.js +1 -1
- js/apbct-public.min.js.map +1 -1
- lib/Cleantalk/Antispam/Cleantalk.php +178 -136
- lib/Cleantalk/Antispam/CleantalkRequest.php +39 -29
- lib/Cleantalk/Antispam/CleantalkResponse.php +55 -59
- lib/Cleantalk/Antispam/DisableComments.php +29 -18
- lib/Cleantalk/Antispam/Integrations.php +13 -11
- lib/Cleantalk/Antispam/Integrations/ContactBank.php +2 -2
- lib/Cleantalk/Antispam/Integrations/EaelLoginRegister.php +4 -0
- lib/Cleantalk/Antispam/Integrations/ElfsightContactForm.php +3 -3
- lib/Cleantalk/Antispam/Integrations/EstimationForm.php +2 -2
- lib/Cleantalk/Antispam/Integrations/FluentForm.php +30 -30
- lib/Cleantalk/Antispam/Integrations/Forminator.php +3 -3
- lib/Cleantalk/Antispam/Integrations/LandingPageBuilder.php +3 -3
- lib/Cleantalk/Antispam/Integrations/Rafflepress.php +2 -2
- lib/Cleantalk/Antispam/Integrations/SimpleMembership.php +6 -2
- lib/Cleantalk/Antispam/Integrations/WpMembers.php +6 -2
- lib/Cleantalk/Antispam/Integrations/Wpdiscuz.php +2 -2
- lib/Cleantalk/ApbctWP/API.php +6 -6
- lib/Cleantalk/ApbctWP/Activator.php +119 -0
- lib/Cleantalk/ApbctWP/AdminNotices.php +7 -2
- lib/Cleantalk/ApbctWP/Ajax.php +8 -8
- lib/Cleantalk/ApbctWP/CleantalkSettingsTemplates.php +2 -2
- lib/Cleantalk/ApbctWP/CleantalkUpgrader.php +7 -1
- lib/Cleantalk/ApbctWP/CleantalkUpgraderSkin.php +6 -6
- lib/Cleantalk/ApbctWP/CleantalkUpgraderSkin_Deprecated.php +8 -6
- lib/Cleantalk/ApbctWP/DB.php +19 -15
- lib/Cleantalk/ApbctWP/Deactivator.php +110 -0
- lib/Cleantalk/ApbctWP/FindSpam/Checker.php +11 -1
- lib/Cleantalk/ApbctWP/FindSpam/CommentsChecker.php +89 -76
- lib/Cleantalk/ApbctWP/FindSpam/ListTable/BadUsers.php +10 -8
- lib/Cleantalk/ApbctWP/FindSpam/ListTable/Comments.php +106 -45
- lib/Cleantalk/ApbctWP/FindSpam/ListTable/CommentsLogs.php +12 -8
- lib/Cleantalk/ApbctWP/FindSpam/ListTable/Users.php +70 -28
- lib/Cleantalk/ApbctWP/FindSpam/ListTable/UsersLogs.php +12 -8
- lib/Cleantalk/ApbctWP/FindSpam/Page.php +1 -0
- lib/Cleantalk/ApbctWP/FindSpam/UsersChecker.php +120 -111
- lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php +128 -102
- lib/Cleantalk/ApbctWP/Firewall/AntiFlood.php +61 -19
- lib/Cleantalk/ApbctWP/Firewall/SFW.php +124 -170
- lib/Cleantalk/ApbctWP/Firewall/die_page_anticrawler.html +6 -3
- lib/Cleantalk/ApbctWP/Firewall/die_page_antiflood.html +6 -3
- lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html +6 -3
- lib/Cleantalk/ApbctWP/GetFieldsAny.php +4 -5
- lib/Cleantalk/ApbctWP/Helper.php +3 -3
- lib/Cleantalk/ApbctWP/Queue.php +25 -0
- lib/Cleantalk/ApbctWP/RemoteCalls.php +30 -25
- lib/Cleantalk/ApbctWP/State.php +26 -18
- lib/Cleantalk/ApbctWP/Variables/AltSessions.php +11 -11
- lib/Cleantalk/ApbctWP/Variables/Cookie.php +21 -15
- lib/Cleantalk/Common/API.php +115 -65
- lib/Cleantalk/Common/Arr.php +73 -40
- lib/Cleantalk/Common/Compatibility.php +3 -0
- lib/Cleantalk/Common/Cron.php +5 -3
- lib/Cleantalk/Common/DB.php +23 -12
- lib/Cleantalk/Common/DNS.php +7 -4
- lib/Cleantalk/Common/Firewall.php +13 -8
- lib/Cleantalk/Common/Firewall/FirewallModule.php +18 -20
- lib/Cleantalk/Common/Firewall/FirewallModule_abstract.php +9 -2
- lib/Cleantalk/Common/Helper.php +208 -96
- lib/Cleantalk/Common/Queue.php +139 -0
- lib/Cleantalk/Common/Schema.php +4 -2
- lib/Cleantalk/Templates/Singleton.php +2 -2
- lib/Cleantalk/Variables/Cookie.php +22 -17
- lib/Cleantalk/Variables/Get.php +19 -15
- lib/Cleantalk/Variables/Post.php +19 -15
- lib/Cleantalk/Variables/Request.php +6 -5
- lib/Cleantalk/Variables/Server.php +29 -7
- lib/Cleantalk/Variables/ServerVariables.php +15 -13
- lib/cleantalk-php-patch.php +2 -2
- readme.txt +36 -1
@@ -3,28 +3,38 @@
|
|
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.
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: https://cleantalk.org
|
9 |
Text Domain: cleantalk-spam-protect
|
10 |
Domain Path: /i18n
|
11 |
*/
|
12 |
|
|
|
13 |
use Cleantalk\ApbctWP\AdminNotices;
|
|
|
14 |
use Cleantalk\ApbctWP\CleantalkUpgrader;
|
15 |
use Cleantalk\ApbctWP\CleantalkUpgraderSkin;
|
16 |
use Cleantalk\ApbctWP\CleantalkUpgraderSkin_Deprecated;
|
17 |
use Cleantalk\ApbctWP\Cron;
|
18 |
use Cleantalk\ApbctWP\DB;
|
|
|
19 |
use Cleantalk\ApbctWP\Firewall\AntiCrawler;
|
|
|
20 |
use Cleantalk\ApbctWP\Firewall\SFW;
|
21 |
use Cleantalk\ApbctWP\Helper;
|
22 |
use Cleantalk\ApbctWP\RemoteCalls;
|
23 |
use Cleantalk\ApbctWP\RestController;
|
|
|
|
|
|
|
|
|
24 |
use Cleantalk\Common\Schema;
|
25 |
use Cleantalk\Variables\Get;
|
26 |
use Cleantalk\Variables\Server;
|
27 |
|
|
|
|
|
28 |
$cleantalk_executed = false;
|
29 |
|
30 |
// Getting version form main file (look above)
|
@@ -46,7 +56,7 @@ define('APBCT_CASERT_PATH', file_exists(ABSPATH . WPINC . '/certificates/ca
|
|
46 |
|
47 |
// API params
|
48 |
define('APBCT_AGENT', 'wordpress-' . $plugin_version__agent );
|
49 |
-
define('APBCT_MODERATE_URL', '
|
50 |
|
51 |
// Option names
|
52 |
define('APBCT_DATA', 'cleantalk_data'); //Option name with different plugin data.
|
@@ -60,425 +70,426 @@ define('APBCT_WPMS', (is_multisite() ? true : false)); // WMPS is enabled
|
|
60 |
// Different params
|
61 |
define('APBCT_REMOTE_CALL_SLEEP', 5); // Minimum time between remote call
|
62 |
|
63 |
-
if( !defined( 'CLEANTALK_PLUGIN_DIR' ) ){
|
64 |
-
|
65 |
define('CLEANTALK_PLUGIN_DIR', dirname(__FILE__ ) . '/');
|
66 |
-
|
67 |
-
// PHP functions patches
|
68 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'lib/cleantalk-php-patch.php'); // Pathces fpr different functions which not exists
|
69 |
-
|
70 |
-
// Base classes
|
71 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'lib/autoloader.php'); // Autoloader
|
72 |
-
|
73 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-pluggable.php'); // Pluggable functions
|
74 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
|
75 |
-
|
76 |
-
// Global ArrayObject with settings and other global varables
|
77 |
-
global $apbct;
|
78 |
-
$apbct = new \Cleantalk\ApbctWP\State('cleantalk', array('settings', 'data', 'debug', 'errors', 'remote_calls', 'stats', 'fw_stats'));
|
79 |
-
|
80 |
-
$apbct->base_name = 'cleantalk-spam-protect/cleantalk.php';
|
81 |
-
|
82 |
-
$apbct->plugin_request_id = md5( microtime() ); // Identify plugin execution
|
83 |
-
|
84 |
-
$apbct->logo = plugin_dir_url(__FILE__) . 'inc/images/logo.png';
|
85 |
-
$apbct->logo__small = plugin_dir_url(__FILE__) . 'inc/images/logo_small.png';
|
86 |
-
$apbct->logo__small__colored = plugin_dir_url(__FILE__) . 'inc/images/logo_color.png';
|
87 |
-
|
88 |
-
// Customize \Cleantalk\ApbctWP\State
|
89 |
-
// Account status
|
90 |
-
|
91 |
-
$apbct->white_label = $apbct->network_settings['multisite__white_label'];
|
92 |
-
$apbct->allow_custom_key = $apbct->network_settings['multisite__allow_custom_key'];
|
93 |
-
$apbct->plugin_name = $apbct->network_settings['multisite__white_label__plugin_name'] ? $apbct->network_settings['multisite__white_label__plugin_name'] : APBCT_NAME;
|
94 |
-
$apbct->api_key = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->settings['apikey'] : $apbct->network_settings['apikey'];
|
95 |
-
$apbct->key_is_ok = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['key_is_ok'] : $apbct->network_data['key_is_ok'];
|
96 |
-
$apbct->moderate = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $apbct->data['moderate'] : $apbct->network_data['moderate'];
|
97 |
-
|
98 |
-
$apbct->data['user_counter']['since'] = isset($apbct->data['user_counter']['since']) ? $apbct->data['user_counter']['since'] : date('d M');
|
99 |
-
$apbct->data['connection_reports']['since'] = isset($apbct->data['connection_reports']['since']) ? $apbct->data['user_counter']['since'] : date('d M');
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
$apbct->settings_link = is_network_admin() ? 'settings.php?page=cleantalk' : 'options-general.php?page=cleantalk';
|
104 |
-
|
105 |
-
if(!$apbct->white_label){
|
106 |
-
require_once( CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-widget.php');
|
107 |
-
}
|
108 |
-
|
109 |
-
// Disabling comments
|
110 |
-
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']){
|
111 |
-
\Cleantalk\Antispam\DisableComments::getInstance();
|
112 |
-
}
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
$controller = new RestController();
|
117 |
-
$controller->register_routes();
|
118 |
-
}
|
119 |
-
|
120 |
-
// Database prefix
|
121 |
-
global $wpdb;
|
122 |
-
$apbct->db_prefix = !APBCT_WPMS || $apbct->allow_custom_key || $apbct->white_label ? $wpdb->prefix : $wpdb->base_prefix;
|
123 |
-
$apbct->db_prefix = !$apbct->white_label && defined('CLEANTALK_ACCESS_KEY') ? $wpdb->base_prefix : $wpdb->prefix;
|
124 |
|
125 |
-
|
126 |
-
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
$apbct->plugin_version = '5.100';
|
131 |
-
|
132 |
-
// Do update actions if version is changed
|
133 |
-
apbct_update_actions();
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
}
|
155 |
}
|
156 |
}
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
)
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
}
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
}
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
){
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
$ct_check_post_result=false;
|
196 |
-
ct_registration_errors(null);
|
197 |
-
}
|
198 |
-
|
199 |
-
}
|
200 |
|
201 |
-
|
202 |
-
'ContactBank' => array( 'hook' => 'contact_bank_frontend_ajax_call', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
|
203 |
-
'FluentForm' => array( 'hook' => 'fluentform_before_insert_submission', 'setting' => 'forms__contact_forms_test', 'ajax' => false ),
|
204 |
-
'ElfsightContactForm' => array( 'hook' => 'elfsight_contact_form_mail', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
|
205 |
-
'EstimationForm' => array( 'hook' => 'send_email', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
|
206 |
-
'LandingPageBuilder' => array( 'hook' => 'ulpb_formBuilderEmail_ajax', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
|
207 |
-
'Rafflepress' => array( 'hook' => 'rafflepress_lite_giveaway_api', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
|
208 |
-
'SimpleMembership' => array( 'hook' => 'swpm_front_end_registration_complete_user_data', 'setting' => 'forms__registrations_test', 'ajax' => false ),
|
209 |
-
'WpMembers' => array( 'hook' => 'wpmem_pre_register_data', 'setting' => 'forms__registrations_test', 'ajax' => false ),
|
210 |
-
'Wpdiscuz' => array( 'hook' => array( 'wpdAddComment', 'wpdAddInlineComment' ), 'setting' => 'forms__comments_test', 'ajax' => true ),
|
211 |
-
'Forminator' => array( 'hook' => 'forminator_submit_form_custom-forms', 'setting' => 'forms__contact_forms_test', 'ajax' => true ),
|
212 |
-
'HappyForm' => array( 'hook' => 'happyforms_validate_submission', 'setting' => 'forms__contact_forms_test', 'ajax' => false ),
|
213 |
-
'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 ),
|
214 |
-
);
|
215 |
-
new \Cleantalk\Antispam\Integrations( $apbct_active_integrations, (array) $apbct->settings );
|
216 |
-
|
217 |
-
// Ninja Forms. Making GET action to POST action
|
218 |
-
if( apbct_is_in_uri( 'admin-ajax.php' ) && sizeof($_POST) > 0 && isset($_GET['action']) && $_GET['action']=='ninja_forms_ajax_submit' )
|
219 |
-
$_POST['action']='ninja_forms_ajax_submit';
|
220 |
-
|
221 |
-
add_action( 'wp_ajax_nopriv_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
|
222 |
-
add_action( 'wp_ajax_ninja_forms_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
|
223 |
-
add_action( 'wp_ajax_nopriv_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
|
224 |
-
add_action( 'wp_ajax_nf_ajax_submit', 'apbct_form__ninjaForms__testSpam', 1);
|
225 |
-
add_action( 'ninja_forms_process', 'apbct_form__ninjaForms__testSpam', 1); // Depricated ?
|
226 |
-
|
227 |
-
// SeedProd Coming Soon Page Pro integration
|
228 |
-
add_action( 'wp_ajax_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
|
229 |
-
add_action( 'wp_ajax_nopriv_seed_cspv5_subscribe_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
|
230 |
-
add_action( 'wp_ajax_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
|
231 |
-
add_action( 'wp_ajax_nopriv_seed_cspv5_contactform_callback', 'apbct_form__seedprod_coming_soon__testSpam', 1 );
|
232 |
-
|
233 |
-
// The 7 theme contact form integration
|
234 |
-
add_action( 'wp_ajax_nopriv_dt_send_mail', 'apbct_form__the7_contact_form', 1 );
|
235 |
-
add_action( 'wp_ajax_dt_send_mail', 'apbct_form__the7_contact_form', 1 );
|
236 |
-
|
237 |
-
// Elementor Pro page builder forms
|
238 |
-
add_action( 'wp_ajax_elementor_pro_forms_send_form', 'apbct_form__elementor_pro__testSpam' );
|
239 |
-
add_action( 'wp_ajax_nopriv_elementor_pro_forms_send_form', 'apbct_form__elementor_pro__testSpam' );
|
240 |
-
|
241 |
-
// Custom register form (ticket_id=13668)
|
242 |
-
add_action('website_neotrends_signup_fields_check',function( $username, $fields ){
|
243 |
-
$ip = Helper::ip__get( 'real', false );
|
244 |
-
$ct_result = ct_test_registration( $username, $fields['email'], $ip );
|
245 |
-
if( $ct_result['allow'] == 0 ) {
|
246 |
-
ct_die_extended( $ct_result['comment'] );
|
247 |
-
}
|
248 |
-
}, 1, 2);
|
249 |
|
250 |
-
|
251 |
-
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
-
|
255 |
-
|
256 |
|
257 |
-
|
258 |
-
|
|
|
259 |
|
260 |
-
|
261 |
-
|
|
|
262 |
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
// Hook for newly added blog
|
297 |
-
add_action('wpmu_new_blog', 'apbct_activation__new_blog', 10, 6);
|
298 |
-
|
299 |
-
// Async loading for JavaScript
|
300 |
-
add_filter('script_loader_tag', 'apbct_add_async_attribute', 10, 3);
|
301 |
-
|
302 |
-
// Redirect admin to plugin settings.
|
303 |
-
if( ! defined('WP_ALLOW_MULTISITE') || ( defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == false ) )
|
304 |
-
add_action('admin_init', 'apbct_plugin_redirect');
|
305 |
-
|
306 |
-
// Deleting SFW tables when deleting websites
|
307 |
-
if(defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE === true)
|
308 |
-
add_action( 'delete_blog', 'apbct_sfw__delete_tables', 10, 2 );
|
309 |
-
|
310 |
-
// After plugin loaded - to load locale as described in manual
|
311 |
-
add_action('plugins_loaded', 'apbct_plugin_loaded' );
|
312 |
-
|
313 |
-
if( !empty($apbct->settings['data__use_ajax']) &&
|
314 |
-
! apbct_is_in_uri( '.xml' ) &&
|
315 |
-
! apbct_is_in_uri( '.xsl' ) )
|
316 |
-
{
|
317 |
-
add_action( 'wp_ajax_nopriv_ct_get_cookie', 'ct_get_cookie',1 );
|
318 |
-
add_action( 'wp_ajax_ct_get_cookie', 'ct_get_cookie',1 );
|
319 |
}
|
320 |
-
|
321 |
-
// Admin panel actions
|
322 |
-
if (is_admin() || is_network_admin()){
|
323 |
|
324 |
-
|
325 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-admin.php');
|
326 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-settings.php');
|
327 |
|
328 |
-
|
|
|
329 |
|
330 |
-
|
331 |
-
|
|
|
|
|
332 |
|
333 |
-
|
334 |
-
|
335 |
-
add_action('
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
|
|
|
|
|
|
343 |
}
|
344 |
-
|
345 |
-
if(apbct_is_ajax() || isset($_POST['cma-action'])){
|
346 |
-
|
347 |
-
$_cleantalk_hooked_actions = array();
|
348 |
-
$_cleantalk_ajax_actions_to_check = array();
|
349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
350 |
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
|
351 |
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
|
352 |
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
|
353 |
-
|
354 |
-
|
355 |
-
// Feedback for comments
|
356 |
-
if(isset($_POST['action']) && $_POST['action'] == 'ct_feedback_comment'){
|
357 |
-
add_action( 'wp_ajax_nopriv_ct_feedback_comment', 'apbct_comment__send_feedback',1 );
|
358 |
-
add_action( 'wp_ajax_ct_feedback_comment', 'apbct_comment__send_feedback',1 );
|
359 |
-
}
|
360 |
-
if(isset($_POST['action']) && $_POST['action'] == 'ct_feedback_user'){
|
361 |
-
add_action( 'wp_ajax_nopriv_ct_feedback_user', 'apbct_user__send_feedback',1 );
|
362 |
-
add_action( 'wp_ajax_ct_feedback_user', 'apbct_user__send_feedback',1 );
|
363 |
-
}
|
364 |
-
|
365 |
-
// Check AJAX requests
|
366 |
-
// if User is not logged in
|
367 |
-
// if Unknown action or Known action with mandatory check
|
368 |
-
if( ( ! apbct_is_user_logged_in() || $apbct->settings['data__protect_logged_in'] == 1) &&
|
369 |
-
isset( $_POST['action'] ) &&
|
370 |
-
( ! in_array( $_POST['action'], $_cleantalk_hooked_actions ) || in_array( $_POST['action'], $_cleantalk_ajax_actions_to_check ) ) &&
|
371 |
-
! array_search( $_POST['action'], array_column( $apbct_active_integrations, 'hook' ) )
|
372 |
-
){
|
373 |
-
ct_ajax_hook();
|
374 |
-
}
|
375 |
-
|
376 |
-
//QAEngine Theme answers
|
377 |
-
if (intval($apbct->settings['forms__general_contact_forms_test']))
|
378 |
-
add_filter('et_pre_insert_question', 'ct_ajax_hook', 1, 1); // Questions
|
379 |
-
add_filter('et_pre_insert_answer', 'ct_ajax_hook', 1, 1); // Answers
|
380 |
-
|
381 |
-
// Formidable
|
382 |
-
add_filter( 'frm_entries_before_create', 'apbct_form__formidable__testSpam', 10, 2 );
|
383 |
-
add_action( 'frm_entries_footer_scripts', 'apbct_form__formidable__footerScripts', 20, 2 );
|
384 |
-
|
385 |
-
// Some of plugins to register a users use AJAX context.
|
386 |
-
add_filter('registration_errors', 'ct_registration_errors', 1, 3);
|
387 |
-
add_filter('registration_errors', 'ct_check_registration_erros', 999999, 3);
|
388 |
-
add_action('user_register', 'apbct_user_register');
|
389 |
-
|
390 |
-
if(class_exists('BuddyPress')){
|
391 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-validate.php');
|
392 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
|
393 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
|
394 |
-
add_filter('bp_activity_is_spam_before_save', 'apbct_integration__buddyPres__activityWall', 999 ,2); /* ActivityWall */
|
395 |
-
add_action('bp_locate_template', 'apbct_integration__buddyPres__getTemplateName', 10, 6);
|
396 |
-
}
|
397 |
-
|
398 |
}
|
399 |
|
400 |
-
|
401 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
|
402 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
|
403 |
-
//Bitrix24 contact form
|
404 |
-
if ($apbct->settings['forms__general_contact_forms_test'] == 1 &&
|
405 |
-
!empty($_POST['your-phone']) &&
|
406 |
-
!empty($_POST['your-email']) &&
|
407 |
-
!empty($_POST['your-message'])
|
408 |
-
){
|
409 |
-
$ct_check_post_result=false;
|
410 |
-
ct_contact_form_validate();
|
411 |
-
}
|
412 |
-
|
413 |
-
// Sends feedback to the cloud about comments
|
414 |
-
// add_action('wp_set_comment_status', 'ct_comment_send_feedback', 10, 2);
|
415 |
-
|
416 |
-
// Sends feedback to the cloud about deleted users
|
417 |
-
global $pagenow;
|
418 |
-
if($pagenow=='users.php')
|
419 |
-
add_action('delete_user', 'apbct_user__delete__hook', 10, 2);
|
420 |
|
421 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
423 |
-
|
424 |
-
|
425 |
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
}else{
|
431 |
|
432 |
-
|
433 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public.php');
|
434 |
-
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-public-integrations.php');
|
435 |
|
436 |
-
|
437 |
-
|
438 |
-
// Init action.
|
439 |
-
add_action('plugins_loaded', 'apbct_init', 1);
|
440 |
-
|
441 |
-
// Comments
|
442 |
-
add_filter('preprocess_comment', 'ct_preprocess_comment', 1, 1); // param - comment data array
|
443 |
-
add_filter('comment_text', 'ct_comment_text' );
|
444 |
-
add_filter('wp_die_handler', 'apbct_comment__sanitize_data__before_wp_die', 1); // Check comments after validation
|
445 |
-
|
446 |
-
// Registrations
|
447 |
-
if(!isset($_POST['wp-submit'])){
|
448 |
-
add_action('login_form_register', 'apbct_cookie');
|
449 |
-
add_action('login_form_register', 'apbct_store__urls');
|
450 |
-
}
|
451 |
-
add_action('login_enqueue_scripts', 'apbct_login__scripts');
|
452 |
-
add_action('register_form', 'ct_register_form');
|
453 |
-
add_filter('registration_errors', 'ct_registration_errors', 1, 3);
|
454 |
-
add_filter('registration_errors', 'ct_check_registration_erros', 999999, 3);
|
455 |
-
add_action('user_register', 'apbct_user_register');
|
456 |
|
457 |
-
|
458 |
-
|
459 |
-
add_filter('wpmu_validate_user_signup', 'ct_registration_errors_wpmu', 10, 3);
|
460 |
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
//
|
477 |
-
if($apbct->settings['gdpr__enabled'])
|
478 |
-
add_shortcode('cleantalk_gdpr_form', 'apbct_shrotcode_handler__GDPR_public_notice__form');
|
479 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
480 |
}
|
481 |
|
|
|
|
|
|
|
482 |
|
483 |
/**
|
484 |
* Function for SpamFireWall check
|
@@ -503,17 +514,18 @@ function apbct_sfw__check()
|
|
503 |
$spbc_key = !empty($spbc_settings['spbc_key']) ? $spbc_settings['spbc_key'] : false;
|
504 |
if($_GET['access'] === $apbct->api_key || ($spbc_key !== false && $_GET['access'] === $spbc_key)){
|
505 |
\Cleantalk\Variables\Cookie::set('spbc_firewall_pass_key', md5(apbct_get_server_variable( 'REMOTE_ADDR' ) . $spbc_key), time()+1200, '/', '');
|
506 |
-
\Cleantalk\Variables\Cookie::set('ct_sfw_pass_key', md5(apbct_get_server_variable( 'REMOTE_ADDR' ) . $apbct->api_key), time()+1200, '/',
|
507 |
return;
|
508 |
}
|
509 |
unset($spbc_settings, $spbc_key);
|
510 |
}
|
511 |
|
512 |
// Turn off the SpamFireWall if Remote Call is in progress
|
513 |
-
if($apbct->rc_running || (!empty($spbc) && $spbc->rc_running))
|
514 |
return;
|
|
|
515 |
|
516 |
-
$firewall = new
|
517 |
DB::getInstance()
|
518 |
);
|
519 |
|
@@ -541,7 +553,7 @@ function apbct_sfw__check()
|
|
541 |
}
|
542 |
|
543 |
if( $apbct->settings['sfw__anti_flood'] && is_null( apbct_wp_get_current_user() ) ){
|
544 |
-
$firewall->load_fw_module( new
|
545 |
APBCT_TBL_FIREWALL_LOG,
|
546 |
APBCT_TBL_AC_LOG,
|
547 |
array(
|
@@ -557,230 +569,21 @@ function apbct_sfw__check()
|
|
557 |
}
|
558 |
|
559 |
/**
|
560 |
-
*
|
561 |
-
*
|
|
|
|
|
|
|
|
|
|
|
562 |
*/
|
563 |
-
function apbct_activation( $network = false ) {
|
564 |
-
|
565 |
-
global $wpdb, $apbct;
|
566 |
-
|
567 |
-
$apbct->stats['plugin']['activation_previous__timestamp'] = $apbct->stats['plugin']['activation__timestamp'];
|
568 |
-
$apbct->stats['plugin']['activation__timestamp'] = time();
|
569 |
-
$apbct->stats['plugin']['activation__times'] += 1;
|
570 |
-
$apbct->save('stats');
|
571 |
-
|
572 |
-
$sqls = Schema::getSchema();
|
573 |
-
$ct_cron = new Cron();
|
574 |
-
|
575 |
-
if($network && !defined('CLEANTALK_ACCESS_KEY')){
|
576 |
-
$initial_blog = get_current_blog_id();
|
577 |
-
$blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
|
578 |
-
foreach ($blogs as $blog) {
|
579 |
-
switch_to_blog($blog);
|
580 |
-
apbct_activation__create_tables($sqls);
|
581 |
-
// Cron tasks
|
582 |
-
|
583 |
-
$ct_cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
|
584 |
-
$ct_cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
585 |
-
$ct_cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
586 |
-
$ct_cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400 ); // SFW update
|
587 |
-
$ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
|
588 |
-
$ct_cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
|
589 |
-
$ct_cron->addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
|
590 |
-
$ct_cron->addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400, time() + 300); // Clear Anti-Flood table
|
591 |
-
}
|
592 |
-
switch_to_blog($initial_blog);
|
593 |
-
}else{
|
594 |
-
|
595 |
-
// Cron tasks
|
596 |
-
$ct_cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
|
597 |
-
$ct_cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
598 |
-
$ct_cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
599 |
-
$ct_cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400 ); // SFW update
|
600 |
-
$ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
|
601 |
-
$ct_cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
|
602 |
-
$ct_cron->addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
|
603 |
-
$ct_cron->addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400, time() + 300); // Clear Anti-Flood table
|
604 |
-
|
605 |
-
apbct_activation__create_tables($sqls);
|
606 |
-
ct_account_status_check(null, false);
|
607 |
-
}
|
608 |
-
|
609 |
-
// Additional options
|
610 |
-
add_option( 'ct_plugin_do_activation_redirect', true );
|
611 |
-
apbct_add_admin_ip_to_swf_whitelist( null, null );
|
612 |
-
|
613 |
-
}
|
614 |
-
|
615 |
function apbct_activation__create_tables( $sqls, $db_prefix = '' ) {
|
616 |
-
|
617 |
-
if( ! is_array( $sqls ) && empty( $sqls ) ) {
|
618 |
-
return;
|
619 |
-
}
|
620 |
-
|
621 |
-
global $wpdb;
|
622 |
-
|
623 |
-
$db_prefix = $db_prefix ? $db_prefix : $wpdb->prefix;
|
624 |
-
|
625 |
-
$wpdb->show_errors = false;
|
626 |
-
foreach($sqls as $sql){
|
627 |
-
$sql = sprintf($sql, $db_prefix); // Adding current blog prefix
|
628 |
-
$result = $wpdb->query($sql);
|
629 |
-
if($result === false)
|
630 |
-
$errors[] = "Failed.\nQuery: {$wpdb->last_query}\nError: {$wpdb->last_error}";
|
631 |
-
}
|
632 |
-
$wpdb->show_errors = true;
|
633 |
-
|
634 |
-
// Logging errors
|
635 |
-
if(!empty($errors))
|
636 |
-
apbct_log($errors);
|
637 |
}
|
638 |
|
639 |
/**
|
640 |
-
*
|
641 |
-
* @
|
642 |
-
*/
|
643 |
-
function apbct_activation__new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) {
|
644 |
-
if (apbct_is_plugin_active_for_network('cleantalk-spam-protect/cleantalk.php')){
|
645 |
-
|
646 |
-
$settings = get_option('cleantalk_settings');
|
647 |
-
|
648 |
-
switch_to_blog($blog_id);
|
649 |
-
|
650 |
-
$sqls = Schema::getSchema();
|
651 |
-
|
652 |
-
$ct_cron = new Cron();
|
653 |
-
|
654 |
-
// Cron tasks
|
655 |
-
$ct_cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
|
656 |
-
$ct_cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
657 |
-
$ct_cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
658 |
-
$ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
|
659 |
-
$ct_cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
|
660 |
-
$ct_cron->addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
|
661 |
-
$ct_cron->addTask('antiflood__clear_table', 'apbct_antiflood__clear_table', 86400, time() + 300); // Clear Anti-Flood table
|
662 |
-
apbct_activation__create_tables($sqls);
|
663 |
-
apbct_sfw_update__init( 3 ); // Updating SFW
|
664 |
-
ct_account_status_check(null, false);
|
665 |
-
|
666 |
-
if (isset($settings['multisite__use_settings_template_apply_for_new']) && $settings['multisite__use_settings_template_apply_for_new'] == 1) {
|
667 |
-
update_option('cleantalk_settings', $settings);
|
668 |
-
}
|
669 |
-
restore_current_blog();
|
670 |
-
}
|
671 |
-
}
|
672 |
-
|
673 |
-
/**
|
674 |
-
* On deactivation, clear schedule.
|
675 |
-
*/
|
676 |
-
function apbct_deactivation( $network ) {
|
677 |
-
|
678 |
-
global $apbct, $wpdb;
|
679 |
-
|
680 |
-
// Deactivation for network
|
681 |
-
if(is_multisite() && $network){
|
682 |
-
|
683 |
-
$initial_blog = get_current_blog_id();
|
684 |
-
$blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
|
685 |
-
foreach ($blogs as $blog) {
|
686 |
-
switch_to_blog($blog);
|
687 |
-
apbct_deactivation__delete_blog_tables();
|
688 |
-
delete_option('cleantalk_cron'); // Deleting cron entries
|
689 |
-
|
690 |
-
if($apbct->settings['misc__complete_deactivation']){
|
691 |
-
apbct_deactivation__delete_all_options();
|
692 |
-
apbct_deactivation__delete_meta();
|
693 |
-
apbct_deactivation__delete_all_options__in_network();
|
694 |
-
}
|
695 |
-
|
696 |
-
}
|
697 |
-
switch_to_blog($initial_blog);
|
698 |
-
|
699 |
-
// Deactivation for blog
|
700 |
-
}elseif(is_multisite()){
|
701 |
-
|
702 |
-
apbct_deactivation__delete_common_tables();
|
703 |
-
delete_option('cleantalk_cron'); // Deleting cron entries
|
704 |
-
|
705 |
-
if($apbct->settings['misc__complete_deactivation']) {
|
706 |
-
apbct_deactivation__delete_all_options();
|
707 |
-
apbct_deactivation__delete_meta();
|
708 |
-
}
|
709 |
-
|
710 |
-
// Deactivation on standalone blog
|
711 |
-
}elseif(!is_multisite()){
|
712 |
-
|
713 |
-
apbct_deactivation__delete_common_tables();
|
714 |
-
delete_option('cleantalk_cron'); // Deleting cron entries
|
715 |
-
|
716 |
-
if($apbct->settings['misc__complete_deactivation']) {
|
717 |
-
apbct_deactivation__delete_all_options();
|
718 |
-
apbct_deactivation__delete_meta();
|
719 |
-
}
|
720 |
-
|
721 |
-
}
|
722 |
-
}
|
723 |
-
|
724 |
-
/**
|
725 |
-
* Delete all cleantalk_* entries from _options table
|
726 |
-
*/
|
727 |
-
function apbct_deactivation__delete_all_options(){
|
728 |
-
delete_option('cleantalk_settings');
|
729 |
-
delete_option('cleantalk_data');
|
730 |
-
delete_option('cleantalk_cron');
|
731 |
-
delete_option('cleantalk_errors');
|
732 |
-
delete_option('cleantalk_remote_calls');
|
733 |
-
delete_option('cleantalk_server');
|
734 |
-
delete_option('cleantalk_stats');
|
735 |
-
delete_option('cleantalk_timelabel_reg');
|
736 |
-
delete_option('cleantalk_debug');
|
737 |
-
delete_option('cleantalk_plugin_request_ids');
|
738 |
-
delete_option('cleantalk_fw_stats');
|
739 |
-
delete_option( 'ct_plugin_do_activation_redirect' );
|
740 |
-
foreach( AdminNotices::NOTICES as $notice ) {
|
741 |
-
delete_option( 'cleantalk_' . $notice . '_dismissed' );
|
742 |
-
}
|
743 |
-
}
|
744 |
-
|
745 |
-
/**
|
746 |
-
* Delete all cleantalk_* entries from _sitemeta table
|
747 |
-
*/
|
748 |
-
function apbct_deactivation__delete_all_options__in_network(){
|
749 |
-
delete_site_option('cleantalk_network_settings');
|
750 |
-
delete_site_option('cleantalk_network_data');
|
751 |
-
}
|
752 |
-
|
753 |
-
function apbct_deactivation__delete_common_tables() {
|
754 |
-
global $wpdb;
|
755 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_sfw`;'); // Deleting SFW data
|
756 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_sfw_logs`;'); // Deleting SFW logs
|
757 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_sfw__flood_logs`;'); // Deleting SFW logs
|
758 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_ac_log`;'); // Deleting SFW logs
|
759 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_sessions`;'); // Deleting session table
|
760 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_spamscan_logs`;'); // Deleting user/comments scan result table
|
761 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_ua_bl`;'); // Deleting AC UA black lists
|
762 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->base_prefix.'cleantalk_sfw_temp`;'); // Deleting temporary SFW data
|
763 |
-
}
|
764 |
-
|
765 |
-
function apbct_deactivation__delete_blog_tables() {
|
766 |
-
global $wpdb;
|
767 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw`;'); // Deleting SFW data
|
768 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw_logs`;'); // Deleting SFW logs
|
769 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw__flood_logs`;'); // Deleting SFW logs
|
770 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_ac_log`;'); // Deleting SFW logs
|
771 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sessions`;'); // Deleting session table
|
772 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_spamscan_logs`;'); // Deleting user/comments scan result table
|
773 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_ua_bl`;'); // Deleting AC UA black lists
|
774 |
-
$wpdb->query('DROP TABLE IF EXISTS `'. $wpdb->prefix.'cleantalk_sfw_temp`;'); // Deleting temporary SFW data
|
775 |
-
}
|
776 |
-
|
777 |
-
function apbct_deactivation__delete_meta(){
|
778 |
-
global $wpdb;
|
779 |
-
$wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ('ct_bad', 'ct_checked', 'ct_checked_now', 'ct_marked_as_spam', 'ct_hash');");
|
780 |
-
}
|
781 |
-
|
782 |
-
/**
|
783 |
-
* Redirects admin to plugin settings after activation.
|
784 |
*/
|
785 |
function apbct_plugin_redirect()
|
786 |
{
|
@@ -793,6 +596,10 @@ function apbct_plugin_redirect()
|
|
793 |
}
|
794 |
}
|
795 |
|
|
|
|
|
|
|
|
|
796 |
function ct_add_event($event_type)
|
797 |
{
|
798 |
global $apbct, $cleantalk_executed;
|
@@ -805,7 +612,7 @@ function ct_add_event($event_type)
|
|
805 |
case '1': $event_type = 'yes';break;
|
806 |
}
|
807 |
|
808 |
-
$current_hour =
|
809 |
|
810 |
// Updating current hour
|
811 |
if($current_hour!=$apbct->data['current_hour']){
|
@@ -815,12 +622,12 @@ function ct_add_event($event_type)
|
|
815 |
}
|
816 |
|
817 |
//Add 1 to counters
|
818 |
-
if($event_type
|
819 |
$apbct->data['array_accepted'][$current_hour]++;
|
820 |
$apbct->data['admin_bar__all_time_counter']['accepted']++;
|
821 |
$apbct->data['user_counter']['accepted']++;
|
822 |
}
|
823 |
-
if($event_type
|
824 |
$apbct->data['array_blocked'][$current_hour]++;
|
825 |
$apbct->data['admin_bar__all_time_counter']['blocked']++;
|
826 |
$apbct->data['user_counter']['blocked']++;
|
@@ -836,7 +643,6 @@ function ct_add_event($event_type)
|
|
836 |
*/
|
837 |
function ct_get_cookie()
|
838 |
{
|
839 |
-
global $ct_checkjs_def;
|
840 |
$ct_checkjs_key = ct_get_checkjs_value();
|
841 |
print $ct_checkjs_key;
|
842 |
die();
|
@@ -857,7 +663,6 @@ function apbct_sfw__clear(){
|
|
857 |
// This action triggered by wp_schedule_single_event( time() + 900, 'ct_sfw_update' );
|
858 |
add_action( 'apbct_sfw_update__init', 'apbct_sfw_update__init' );
|
859 |
|
860 |
-
|
861 |
/**
|
862 |
* Called by sfw_update remote call
|
863 |
* Starts SFW update and could use a delay before start
|
@@ -867,20 +672,25 @@ add_action( 'apbct_sfw_update__init', 'apbct_sfw_update__init' );
|
|
867 |
* @return bool|string|string[]
|
868 |
*/
|
869 |
function apbct_sfw_update__init( $delay = 0 ){
|
|
|
870 |
global $apbct;
|
871 |
-
|
872 |
-
// Prevent start an update if update is already running and started less than
|
873 |
if(
|
874 |
-
! $apbct->settings['sfw__enabled'] &&
|
875 |
$apbct->fw_stats['firewall_updating_id'] &&
|
876 |
-
time() - $apbct->fw_stats['firewall_updating_last_start'] <
|
|
|
877 |
){
|
878 |
return false;
|
879 |
}
|
|
|
|
|
|
|
|
|
880 |
|
881 |
// Key is empty
|
882 |
-
if( ! $apbct->
|
883 |
-
return array( 'error' => 'SFW UPDATE INIT:
|
884 |
}
|
885 |
|
886 |
if( ! $apbct->data['key_is_ok'] ){
|
@@ -888,7 +698,7 @@ function apbct_sfw_update__init( $delay = 0 ){
|
|
888 |
}
|
889 |
|
890 |
// Set a new update ID and an update time start
|
891 |
-
$apbct->fw_stats['firewall_updating_id'] = md5( rand( 0, 100000 ) );
|
892 |
$apbct->fw_stats['firewall_updating_last_start'] = time();
|
893 |
$apbct->save( 'fw_stats' );
|
894 |
|
@@ -896,270 +706,346 @@ function apbct_sfw_update__init( $delay = 0 ){
|
|
896 |
$apbct->error_delete( 'sfw_update', 'save_data' );
|
897 |
$apbct->error_delete( 'sfw_update', 'save_data', 'cron' );
|
898 |
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
906 |
);
|
907 |
-
|
908 |
-
if( ! empty( $result['error'] ) ){
|
909 |
-
|
910 |
-
if( strpos( $result['error'], 'WRONG_SITE_RESPONSE' ) !== false ){
|
911 |
-
|
912 |
-
$result = apbct_sfw_update__worker( $apbct->fw_stats['firewall_updating_id'] );
|
913 |
-
if( ! empty( $result['error'] ) ){
|
914 |
-
apbct_sfw_update__cleanData();
|
915 |
-
}
|
916 |
-
|
917 |
-
return $result;
|
918 |
-
}
|
919 |
-
}
|
920 |
-
|
921 |
-
return $result;
|
922 |
-
}
|
923 |
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
*
|
928 |
-
* @param string $updating_id
|
929 |
-
* @param string $multifile_url
|
930 |
-
* @param string $url_count
|
931 |
-
* @param string $current_url
|
932 |
-
* @param string $useragent_url
|
933 |
-
*
|
934 |
-
* @return array|bool|int|string[]
|
935 |
-
* @throws Exception
|
936 |
-
*/
|
937 |
-
function apbct_sfw_update__worker(
|
938 |
-
$updating_id = null,
|
939 |
-
$multifile_url = null,
|
940 |
-
$url_count = null,
|
941 |
-
$current_url = null,
|
942 |
-
$useragent_url = null) {
|
943 |
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
$updating_id = $updating_id ?: Get::get( 'firewall_updating_id' );
|
949 |
-
$multifile_url = $multifile_url ?: Get::get( 'multifile_url' );
|
950 |
-
$url_count = $url_count ?: Get::get( 'url_count' );
|
951 |
-
$useragent_url = $useragent_url ?: Get::get( 'useragent_url' );
|
952 |
-
$current_url = isset( $current_url ) ? $current_url : Get::get( 'current_url' );
|
953 |
-
|
954 |
-
$api_key = $apbct->api_key;
|
955 |
|
956 |
-
|
957 |
-
return array( 'error' => 'KEY_IS_NOT_VALID' );
|
958 |
-
}
|
959 |
|
960 |
-
|
961 |
-
// This was done to make sure that we won't have multiple updates at a time
|
962 |
-
if( $updating_id !== $apbct->fw_stats['firewall_updating_id'] ){
|
963 |
-
return array( 'error' => 'WRONG_UPDATE_ID' );
|
964 |
-
}
|
965 |
|
966 |
-
|
967 |
-
if( ! $multifile_url ){
|
968 |
-
|
969 |
-
// Preparing database infrastructure
|
970 |
-
// Creating SFW tables to make sure that they are exist
|
971 |
-
apbct_activation__create_tables( Schema::getSchema( 'sfw' ), $apbct->db_prefix );
|
972 |
-
|
973 |
-
// Preparing temporary tables
|
974 |
-
$result = SFW::create_temp_tables( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
|
975 |
-
if( ! empty( $result['error'] ) )
|
976 |
-
return $result;
|
977 |
-
|
978 |
-
return apbct_sfw_update__get_multifiles( $api_key, $updating_id );
|
979 |
-
|
980 |
-
// User-Agents blacklist
|
981 |
-
}elseif( $useragent_url && ( $apbct->settings['sfw__anti_crawler'] || $apbct->settings['sfw__anti_flood'] ) ){
|
982 |
-
|
983 |
-
$apbct->fw_stats['firewall_update_percent'] = 10;
|
984 |
-
$apbct->save( 'fw_stats' );
|
985 |
-
|
986 |
-
return apbct_sfw_update__process_ua( $multifile_url, $url_count, $current_url, $updating_id, $useragent_url );
|
987 |
-
|
988 |
-
// Writing data form URL gz file
|
989 |
-
}elseif( $url_count && $url_count > $current_url ){
|
990 |
-
|
991 |
-
// Maximum is 90% because there are User-Agents to update. Leaving them 10% of all percents.
|
992 |
-
$apbct->fw_stats['firewall_update_percent'] = round( ( ( (int) $current_url + 1 ) / (int) $url_count ), 2 ) * 90 + 10;
|
993 |
-
$apbct->save( 'fw_stats' );
|
994 |
-
|
995 |
-
return apbct_sfw_update__process_file( $multifile_url, $url_count, $current_url, $updating_id );
|
996 |
-
|
997 |
-
// Main update is complete. Adding exclusions.
|
998 |
-
}elseif( $url_count && $url_count === $current_url ){
|
999 |
-
|
1000 |
-
return apbct_sfw_update__process_exclusions( $multifile_url, $updating_id );
|
1001 |
-
|
1002 |
-
// End of update
|
1003 |
-
}else{
|
1004 |
|
1005 |
-
|
1006 |
|
1007 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1008 |
}
|
1009 |
|
1010 |
-
function
|
1011 |
|
1012 |
-
|
1013 |
|
1014 |
-
|
1015 |
-
|
1016 |
-
if( ! empty( $result['error'] ) ){
|
1017 |
-
return array( 'error' => 'GET MULTIFILE: ' . $result['error'] );
|
1018 |
-
}
|
1019 |
-
|
1020 |
-
// Save expected_networks_count and expected_ua_count if exists
|
1021 |
-
$file_ck_url__data = Helper::http__get_data_from_remote_gz__and_parse_csv( $result['file_ck_url'] );
|
1022 |
|
1023 |
-
|
1024 |
-
return array( 'error' => 'GET EXPECTED RECORDS COUNT DATA: ' . $file_ck_url__data['error'] );
|
1025 |
-
}
|
1026 |
|
1027 |
-
|
1028 |
-
$expected_ua_count = 0;
|
1029 |
|
1030 |
-
|
1031 |
-
if( trim( $value[0], '"' ) === 'networks_count' ){
|
1032 |
-
$expected_networks_count = $value[1];
|
1033 |
-
}
|
1034 |
-
if( trim( $value[0], '"' ) === 'ua_count' ) {
|
1035 |
-
$expected_ua_count = $value[1];
|
1036 |
-
}
|
1037 |
-
}
|
1038 |
|
1039 |
-
|
1040 |
-
$apbct->fw_stats['expected_ua_count'] = $expected_ua_count;
|
1041 |
-
$apbct->save( 'fw_stats' );
|
1042 |
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
'multifile_url' => str_replace( array( 'http://', 'https://' ), '', $result['multifile_url'] ),
|
1047 |
-
'url_count' => count( $result['file_urls'] ),
|
1048 |
-
'useragent_url' => str_replace( array( 'http://', 'https://' ), '', $result['useragent_url'] ),
|
1049 |
-
'current_url' => 0,
|
1050 |
-
'firewall_updating_id' => $updating_id,
|
1051 |
-
),
|
1052 |
-
array( 'async' )
|
1053 |
-
);
|
1054 |
-
|
1055 |
-
if( ! empty( $rc_result['error'] ) ){
|
1056 |
-
|
1057 |
-
if( strpos( $rc_result['error'], 'WRONG_SITE_RESPONSE' ) !== false ){
|
1058 |
-
|
1059 |
-
return apbct_sfw_update__worker(
|
1060 |
-
$updating_id,
|
1061 |
-
str_replace( array( 'http://', 'https://' ), '', $result['multifile_url'] ),
|
1062 |
-
count( $result['file_urls'] ),
|
1063 |
-
0,
|
1064 |
-
str_replace( array( 'http://', 'https://' ), '', $result['useragent_url'] )
|
1065 |
-
);
|
1066 |
-
}
|
1067 |
-
|
1068 |
-
return array( 'error' => 'GET MULTIFILE: ' . $result['error'] );
|
1069 |
-
}
|
1070 |
-
|
1071 |
-
return $result;
|
1072 |
-
}
|
1073 |
|
1074 |
-
|
1075 |
-
|
1076 |
-
$result = AntiCrawler::update( 'https://' . $useragent_url );
|
1077 |
-
|
1078 |
-
if( ! empty( $result['error'] ) ){
|
1079 |
-
return array( 'error' => 'UPDATING UA LIST: ' . $result['error'] );
|
1080 |
-
}
|
1081 |
-
|
1082 |
-
if( ! is_int( $result ) ){
|
1083 |
-
return array( 'error' => 'UPDATING UA LIST: : WRONG_RESPONSE AntiCrawler::update' );
|
1084 |
-
}
|
1085 |
-
|
1086 |
-
$rc_result = Helper::http__request__rc_to_host(
|
1087 |
-
'sfw_update__worker',
|
1088 |
-
array(
|
1089 |
-
'multifile_url' => str_replace( array( 'http://', 'https://' ), '', $multifile_url ),
|
1090 |
-
'url_count' => $url_count,
|
1091 |
-
'current_url' => $current_url,
|
1092 |
-
'firewall_updating_id' => $updating_id,
|
1093 |
-
),
|
1094 |
-
array( 'async' )
|
1095 |
-
);
|
1096 |
-
|
1097 |
-
if( ! empty( $rc_result['error'] ) ){
|
1098 |
-
|
1099 |
-
if( strpos( $rc_result['error'], 'WRONG_SITE_RESPONSE' ) !== false ){
|
1100 |
-
|
1101 |
-
return apbct_sfw_update__worker(
|
1102 |
-
$updating_id,
|
1103 |
-
str_replace( array( 'http://', 'https://' ), '', $multifile_url ),
|
1104 |
-
$url_count,
|
1105 |
-
$current_url
|
1106 |
-
);
|
1107 |
-
}
|
1108 |
-
|
1109 |
-
return array( 'error' => 'UPDATE UA LIST: ' . $result['error'] );
|
1110 |
-
}
|
1111 |
-
|
1112 |
-
return $result;
|
1113 |
-
}
|
1114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1115 |
|
1116 |
-
function apbct_sfw_update__process_file( $multifile_url, $url_count, $current_url, $updating_id ){
|
1117 |
-
|
1118 |
-
$result = SFW::update__write_to_db(
|
1119 |
-
DB::getInstance(),
|
1120 |
-
APBCT_TBL_FIREWALL_DATA . '_temp',
|
1121 |
-
'https://' . str_replace( 'multifiles', $current_url, $multifile_url )
|
1122 |
-
);
|
1123 |
-
|
1124 |
-
if( ! empty( $result['error'] ) ){
|
1125 |
-
return array( 'error' => 'PROCESS FILE: ' . $result['error'] );
|
1126 |
-
}
|
1127 |
-
|
1128 |
-
if( ! is_int( $result ) ){
|
1129 |
-
return array( 'error' => 'PROCESS FILE: WRONG RESPONSE FROM update__write_to_db' );
|
1130 |
-
}
|
1131 |
-
|
1132 |
-
$rc_result = Helper::http__request__rc_to_host(
|
1133 |
-
'sfw_update__worker',
|
1134 |
-
array(
|
1135 |
-
'multifile_url' => str_replace( array( 'http://', 'https://' ), '', $multifile_url ),
|
1136 |
-
'url_count' => $url_count,
|
1137 |
-
'current_url' => $current_url + 1,
|
1138 |
-
'firewall_updating_id' => $updating_id,
|
1139 |
-
),
|
1140 |
-
array( 'async' )
|
1141 |
-
);
|
1142 |
-
|
1143 |
-
if( ! empty( $rc_result['error'] ) ){
|
1144 |
-
|
1145 |
-
if( strpos( $rc_result['error'], 'WRONG_SITE_RESPONSE' ) !== false ){
|
1146 |
-
|
1147 |
-
return apbct_sfw_update__worker(
|
1148 |
-
$updating_id,
|
1149 |
-
str_replace( array( 'http://', 'https://' ), '', $multifile_url ),
|
1150 |
-
$url_count,
|
1151 |
-
$current_url + 1
|
1152 |
-
);
|
1153 |
-
}
|
1154 |
-
|
1155 |
-
return array( 'error' => 'PROCESS FILE: ' . $result['error'] );
|
1156 |
-
}
|
1157 |
-
|
1158 |
-
return $result;
|
1159 |
-
|
1160 |
}
|
1161 |
|
1162 |
-
function apbct_sfw_update__process_exclusions(
|
1163 |
global $apbct;
|
1164 |
|
1165 |
$result = SFW::update__write_to_db__exclusions(
|
@@ -1182,30 +1068,13 @@ function apbct_sfw_update__process_exclusions( $multifile_url, $updating_id ){
|
|
1182 |
$apbct->fw_stats['expected_networks_count'] += $result;
|
1183 |
$apbct->save( 'fw_stats' );
|
1184 |
}
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
-
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
1192 |
-
array( 'async' )
|
1193 |
-
);
|
1194 |
-
|
1195 |
-
if( ! empty( $rc_result['error'] ) ){
|
1196 |
-
|
1197 |
-
if( strpos( $rc_result['error'], 'WRONG_SITE_RESPONSE' ) !== false ){
|
1198 |
-
|
1199 |
-
return apbct_sfw_update__worker(
|
1200 |
-
$updating_id,
|
1201 |
-
str_replace( array( 'http://', 'https://' ), '', $multifile_url )
|
1202 |
-
);
|
1203 |
-
}
|
1204 |
-
|
1205 |
-
return array( 'error' => 'EXCLUSIONS: ' . $result['error'] );
|
1206 |
-
}
|
1207 |
-
|
1208 |
-
return $result;
|
1209 |
}
|
1210 |
|
1211 |
function apbct_sfw_update__end_of_update() {
|
@@ -1214,11 +1083,13 @@ function apbct_sfw_update__end_of_update() {
|
|
1214 |
|
1215 |
// REMOVE AND RENAME
|
1216 |
$result = SFW::data_tables__delete( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
|
1217 |
-
if( ! empty( $result['error'] ) )
|
1218 |
return $result;
|
|
|
1219 |
$result = SFW::rename_data_tables__from_temp_to_main( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
|
1220 |
-
if( ! empty( $result['error'] ) )
|
1221 |
return $result;
|
|
|
1222 |
|
1223 |
// Increment firewall entries
|
1224 |
$apbct->fw_stats['firewall_update_percent'] = 0;
|
@@ -1241,11 +1112,13 @@ function apbct_sfw_update__end_of_update() {
|
|
1241 |
/**
|
1242 |
* Checking the integrity of the sfw database update
|
1243 |
*/
|
|
|
1244 |
global $ct_cron;
|
1245 |
|
1246 |
if( $apbct->stats['sfw']['entries'] != $apbct->fw_stats['expected_networks_count'] ) {
|
1247 |
|
1248 |
# call manually
|
|
|
1249 |
if( ! $ct_cron ){
|
1250 |
return array(
|
1251 |
'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']);
|
@@ -1272,11 +1145,12 @@ function apbct_sfw_update__end_of_update() {
|
|
1272 |
$apbct->error_delete( 'sfw_update', 'save_settings' );
|
1273 |
|
1274 |
// Get update period for server
|
1275 |
-
$update_period =
|
1276 |
$update_period = isset( $update_period['txt'] ) ? $update_period['txt'] : 0;
|
1277 |
-
$update_period = (int) $update_period >
|
1278 |
$cron = new Cron();
|
1279 |
$cron->updateTask('sfw_update', 'apbct_sfw_update__init', $update_period );
|
|
|
1280 |
|
1281 |
/**
|
1282 |
* Update fw data if update completed
|
@@ -1290,6 +1164,48 @@ function apbct_sfw_update__end_of_update() {
|
|
1290 |
|
1291 |
}
|
1292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1293 |
function apbct_sfw_update__cleanData(){
|
1294 |
|
1295 |
global $apbct;
|
@@ -1341,7 +1257,7 @@ function apbct_antiflood__clear_table(){
|
|
1341 |
|
1342 |
if( $apbct->settings['sfw__anti_flood'] || $apbct->settings['sfw__anti_crawler'] ){
|
1343 |
|
1344 |
-
$anti_flood = new
|
1345 |
APBCT_TBL_FIREWALL_LOG,
|
1346 |
APBCT_TBL_AC_LOG,
|
1347 |
array(
|
@@ -1354,69 +1270,19 @@ function apbct_antiflood__clear_table(){
|
|
1354 |
}
|
1355 |
}
|
1356 |
|
1357 |
-
/**
|
1358 |
-
* Wrapper for Cleantalk's remote calls
|
1359 |
-
*
|
1360 |
-
* @param string $action What you want to do?
|
1361 |
-
* @param array $additional_params Additional GET parameters for RC
|
1362 |
-
* @param string $presets Presets for \Cleantalk\ApbctWP\Helper::http__request(). 'async' maybe?
|
1363 |
-
* @param string $plugin_name Plugin name 'antispam' by default
|
1364 |
-
* @param string $call_token RC securirty token
|
1365 |
-
* @param string $url Current site URL by default
|
1366 |
-
*
|
1367 |
-
* @return array|bool
|
1368 |
-
*/
|
1369 |
-
function apbct_rc__send($action, $additional_params = array(), $presets = 'get', $plugin_name = 'antispam', $call_token = '', $url = ''){
|
1370 |
-
|
1371 |
-
global $apbct;
|
1372 |
-
|
1373 |
-
$default_params = array(
|
1374 |
-
'plugin_name' => $plugin_name,
|
1375 |
-
'spbc_remote_call_token' => $call_token ? $call_token : md5($apbct->api_key),
|
1376 |
-
'spbc_remote_call_action' => $action,
|
1377 |
-
);
|
1378 |
-
|
1379 |
-
$params = array_merge($additional_params, $default_params);
|
1380 |
-
|
1381 |
-
return apbct_rc__parse_result(
|
1382 |
-
Helper::http__request(
|
1383 |
-
$url ? $url : get_option('siteurl'),
|
1384 |
-
$params,
|
1385 |
-
$presets
|
1386 |
-
)
|
1387 |
-
);
|
1388 |
-
}
|
1389 |
-
|
1390 |
-
/**
|
1391 |
-
* Parse different types of remote call results
|
1392 |
-
*
|
1393 |
-
* @param array|string $rc_result
|
1394 |
-
* string - 'FAIL {"some":"result}'
|
1395 |
-
* string - 'OK {"some":"result}'
|
1396 |
-
*
|
1397 |
-
* @return array|string
|
1398 |
-
*/
|
1399 |
-
function apbct_rc__parse_result($rc_result){
|
1400 |
-
if(is_string($rc_result)){
|
1401 |
-
$rc_result = preg_replace('/^(OK\s?|FAIL\s?)(.*)/', '$2', $rc_result, 1);
|
1402 |
-
$rc_result = json_decode($rc_result, true);
|
1403 |
-
$rc_result = $rc_result
|
1404 |
-
? $rc_result
|
1405 |
-
: array('error' => 'FAIL_TO_PARSE_RC_RESULT');
|
1406 |
-
}
|
1407 |
-
return $rc_result;
|
1408 |
-
}
|
1409 |
-
|
1410 |
/**
|
1411 |
* Install plugin from wordpress catalog
|
1412 |
*
|
1413 |
-
* @param WP
|
1414 |
-
* @param string $
|
|
|
1415 |
*/
|
1416 |
-
function apbct_rc__install_plugin($
|
1417 |
global $wp_version;
|
1418 |
|
1419 |
-
|
|
|
|
|
1420 |
|
1421 |
if($plugin){
|
1422 |
|
@@ -1431,7 +1297,7 @@ function apbct_rc__install_plugin($wp = null, $plugin = null){
|
|
1431 |
'plugin_information',
|
1432 |
array(
|
1433 |
'slug' => $plugin_slug,
|
1434 |
-
'
|
1435 |
)
|
1436 |
);
|
1437 |
|
@@ -1453,21 +1319,30 @@ function apbct_rc__install_plugin($wp = null, $plugin = null){
|
|
1453 |
if($installer->apbct_result === 'OK'){
|
1454 |
die('OK');
|
1455 |
|
1456 |
-
}else
|
1457 |
-
die('FAIL '. json_encode(array('error' => $installer->apbct_result)));
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
-
|
1465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1466 |
}
|
1467 |
|
1468 |
function apbct_rc__activate_plugin($plugin){
|
1469 |
-
|
1470 |
-
|
|
|
|
|
1471 |
|
1472 |
if($plugin){
|
1473 |
|
@@ -1479,31 +1354,38 @@ function apbct_rc__activate_plugin($plugin){
|
|
1479 |
|
1480 |
if($result && !is_wp_error($result)){
|
1481 |
return array('success' => true);
|
1482 |
-
}else
|
1483 |
-
return array('error'
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
|
|
|
|
|
|
|
|
|
|
1488 |
}
|
1489 |
|
1490 |
/**
|
1491 |
* Uninstall plugin from wordpress catalog
|
1492 |
*
|
1493 |
-
* @param null $
|
1494 |
*/
|
1495 |
function apbct_rc__deactivate_plugin($plugin = null){
|
1496 |
|
1497 |
global $apbct;
|
1498 |
-
|
1499 |
-
|
|
|
|
|
1500 |
|
1501 |
if($plugin){
|
1502 |
|
1503 |
// Switching complete deactivation for security
|
1504 |
-
if($plugin
|
1505 |
$spbc_settings = get_option('spbc_settings');
|
1506 |
-
$spbc_settings['misc__complete_deactivation'] =
|
1507 |
update_option('spbc_settings', $spbc_settings);
|
1508 |
}
|
1509 |
|
@@ -1512,21 +1394,23 @@ function apbct_rc__deactivate_plugin($plugin = null){
|
|
1512 |
if(is_plugin_active( $plugin )){
|
1513 |
// Hook to set flag if the plugin is deactivated
|
1514 |
add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
|
1515 |
-
deactivate_plugins($plugin, false, is_multisite()
|
1516 |
}else{
|
1517 |
$apbct->plugin_deactivated = true;
|
1518 |
}
|
1519 |
|
1520 |
// Hook to set flag if the plugin is deactivated
|
1521 |
add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
|
1522 |
-
deactivate_plugins($plugin, false, is_multisite()
|
1523 |
|
1524 |
if($apbct->plugin_deactivated){
|
1525 |
die('OK');
|
1526 |
-
}else
|
1527 |
-
die('FAIL '. json_encode(array('error' => 'PLUGIN_STILL_ACTIVE')));
|
1528 |
-
|
1529 |
-
|
|
|
|
|
1530 |
}
|
1531 |
|
1532 |
|
@@ -1538,15 +1422,17 @@ function apbct_rc__deactivate_plugin($plugin = null){
|
|
1538 |
function apbct_rc__uninstall_plugin($plugin = null){
|
1539 |
|
1540 |
global $apbct;
|
1541 |
-
|
1542 |
-
|
|
|
|
|
1543 |
|
1544 |
if($plugin){
|
1545 |
|
1546 |
// Switching complete deactivation for security
|
1547 |
-
if($plugin
|
1548 |
$spbc_settings = get_option('spbc_settings');
|
1549 |
-
$spbc_settings['misc__complete_deactivation'] =
|
1550 |
update_option('spbc_settings', $spbc_settings);
|
1551 |
}
|
1552 |
|
@@ -1555,7 +1441,7 @@ function apbct_rc__uninstall_plugin($plugin = null){
|
|
1555 |
if(is_plugin_active( $plugin )){
|
1556 |
// Hook to set flag if the plugin is deactivated
|
1557 |
add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
|
1558 |
-
deactivate_plugins($plugin, false, is_multisite()
|
1559 |
}else{
|
1560 |
$apbct->plugin_deactivated = true;
|
1561 |
}
|
@@ -1568,12 +1454,18 @@ function apbct_rc__uninstall_plugin($plugin = null){
|
|
1568 |
|
1569 |
if($result && !is_wp_error($result)){
|
1570 |
die('OK');
|
1571 |
-
}else
|
1572 |
-
die('FAIL '. json_encode(array(
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1577 |
}
|
1578 |
|
1579 |
function apbct_rc__uninstall_plugin__check_deactivate(){
|
@@ -1581,6 +1473,10 @@ function apbct_rc__uninstall_plugin__check_deactivate(){
|
|
1581 |
$apbct->plugin_deactivated = true;
|
1582 |
}
|
1583 |
|
|
|
|
|
|
|
|
|
1584 |
function apbct_rc__update(){
|
1585 |
global $wp_version;
|
1586 |
|
@@ -1602,7 +1498,7 @@ function apbct_rc__update(){
|
|
1602 |
include_once( ABSPATH . 'wp-admin/includes/file.php' );
|
1603 |
include_once( ABSPATH . 'wp-admin/includes/misc.php' );
|
1604 |
|
1605 |
-
|
1606 |
|
1607 |
if (version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0){
|
1608 |
$upgrader = new CleantalkUpgrader( new CleantalkUpgraderSkin( compact('title', 'nonce', 'url', 'plugin') ) );
|
@@ -1613,37 +1509,40 @@ function apbct_rc__update(){
|
|
1613 |
$upgrader_result = $upgrader->upgrade( $plugin );
|
1614 |
if( is_wp_error( $upgrader_result ) ){
|
1615 |
error_log('CleanTalk debug message:');
|
1616 |
-
error_log( var_export( $upgrader_result->get_error_message(),
|
1617 |
}
|
1618 |
|
1619 |
-
|
1620 |
|
1621 |
$result = activate_plugins( $plugin, '', $activate_for_network );
|
1622 |
|
1623 |
// Changing response UP_TO_DATE to OK
|
1624 |
-
if($upgrader->apbct_result === 'UP_TO_DATE')
|
1625 |
$upgrader->apbct_result = 'OK';
|
|
|
1626 |
|
1627 |
if($upgrader->apbct_result === 'OK'){
|
1628 |
|
1629 |
if(is_wp_error($result)){
|
1630 |
-
die('FAIL '. json_encode(array('error' => 'COULD_NOT_ACTIVATE', 'wp_error' => $result->get_error_message())));
|
1631 |
}
|
1632 |
|
1633 |
$httpResponseCode = Helper::http__request(get_option('siteurl'), array(), 'get_code');
|
1634 |
|
1635 |
if( strpos($httpResponseCode, '200') === false ){
|
1636 |
|
1637 |
-
|
1638 |
|
1639 |
// Rollback
|
1640 |
-
if (version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0)
|
1641 |
-
$rollback = new CleantalkUpgrader( new CleantalkUpgraderSkin( compact('title', 'nonce', 'url', 'plugin_slug', 'prev_version') ) );
|
1642 |
-
|
1643 |
-
|
|
|
|
|
1644 |
$rollback->rollback($plugin);
|
1645 |
|
1646 |
-
|
1647 |
|
1648 |
// @todo add execution time
|
1649 |
|
@@ -1654,20 +1553,25 @@ function apbct_rc__update(){
|
|
1654 |
'rollback_result' => $rollback->apbct_result,
|
1655 |
);
|
1656 |
|
1657 |
-
die('FAIL '.json_encode($response));
|
1658 |
}
|
1659 |
|
1660 |
$plugin_data = get_plugin_data(__FILE__);
|
1661 |
$apbct_agent = 'wordpress-'.str_replace('.', '', $plugin_data['Version']);
|
1662 |
ct_send_feedback('0:' . $apbct_agent);
|
1663 |
|
1664 |
-
die('OK '.json_encode(array('agent' => $apbct_agent)));
|
1665 |
|
1666 |
-
}else{
|
1667 |
-
die('FAIL '. json_encode(array('error' => $upgrader->apbct_result)));
|
1668 |
}
|
|
|
|
|
1669 |
}
|
1670 |
|
|
|
|
|
|
|
|
|
|
|
1671 |
function apbct_rc__update_settings($source) {
|
1672 |
|
1673 |
global $apbct;
|
@@ -1677,8 +1581,9 @@ function apbct_rc__update_settings($source) {
|
|
1677 |
$var = $source[$setting];
|
1678 |
$type = gettype($def_value);
|
1679 |
settype($var, $type);
|
1680 |
-
if($type
|
1681 |
-
$var = preg_replace(array('/=/', '/`/'), '', $var);
|
|
|
1682 |
$apbct->settings[$setting] = $var;
|
1683 |
}
|
1684 |
}
|
@@ -1688,10 +1593,14 @@ function apbct_rc__update_settings($source) {
|
|
1688 |
return true;
|
1689 |
}
|
1690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1691 |
function apbct_rc__insert_auth_key($key, $plugin){
|
1692 |
|
1693 |
-
global $apbct;
|
1694 |
-
|
1695 |
if($plugin === 'security-malware-firewall/security-malware-firewall.php'){
|
1696 |
|
1697 |
require_once (ABSPATH .'/wp-admin/includes/plugin.php');
|
@@ -1702,7 +1611,7 @@ function apbct_rc__insert_auth_key($key, $plugin){
|
|
1702 |
|
1703 |
if($key && preg_match('/^[a-z\d]{3,15}$/', $key)){
|
1704 |
|
1705 |
-
$result =
|
1706 |
$key,
|
1707 |
preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1), // Site URL
|
1708 |
'security'
|
@@ -1733,16 +1642,21 @@ function apbct_rc__insert_auth_key($key, $plugin){
|
|
1733 |
update_option('spbc_settings', $settings);
|
1734 |
|
1735 |
return 'OK';
|
1736 |
-
}else
|
1737 |
-
return array('error' => 'KEY_IS_NOT_VALID');
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
|
|
|
|
|
|
|
|
|
|
1746 |
}
|
1747 |
|
1748 |
/**
|
@@ -1753,8 +1667,8 @@ function apbct_rc__insert_auth_key($key, $plugin){
|
|
1753 |
*
|
1754 |
* @return bool
|
1755 |
*/
|
1756 |
-
function
|
1757 |
-
|
1758 |
$content = "<?php\n\n"
|
1759 |
. '$upgrading = ' . (time() - ( 60 * 10 ) + $duration) . ';';
|
1760 |
|
@@ -1766,20 +1680,25 @@ function apbct_maintance_mode__enable( $duration ) {
|
|
1766 |
*
|
1767 |
* @return void
|
1768 |
*/
|
1769 |
-
function
|
1770 |
$maintenance_file = ABSPATH . '.maintenance';
|
1771 |
if ( file_exists( $maintenance_file ) ) {
|
1772 |
unlink( $maintenance_file );
|
1773 |
}
|
1774 |
}
|
1775 |
|
|
|
|
|
|
|
|
|
|
|
1776 |
function cleantalk_get_brief_data( $api_key = null ){
|
1777 |
|
1778 |
global $apbct;
|
1779 |
|
1780 |
$api_key = is_null( $api_key ) ? $apbct->api_key : $api_key;
|
1781 |
|
1782 |
-
$apbct->data['brief_data'] =
|
1783 |
|
1784 |
# expanding data about the country
|
1785 |
if(isset($apbct->data['brief_data']['top5_spam_ip']) && !empty($apbct->data['brief_data']['top5_spam_ip'])) {
|
@@ -1791,7 +1710,7 @@ function cleantalk_get_brief_data( $api_key = null ){
|
|
1791 |
);
|
1792 |
|
1793 |
if(isset($ip)) {
|
1794 |
-
$country_data =
|
1795 |
$country_data_clear = current($country_data);
|
1796 |
|
1797 |
if(is_array($country_data_clear) && isset($country_data_clear['country_name']) && isset($country_data_clear['country_code'])) {
|
@@ -1810,12 +1729,21 @@ function cleantalk_get_brief_data( $api_key = null ){
|
|
1810 |
|
1811 |
}
|
1812 |
|
1813 |
-
|
|
|
|
|
1814 |
function apbct__hook__wp_logout__delete_trial_notice_cookie(){
|
1815 |
-
if(!headers_sent())
|
1816 |
-
|
|
|
1817 |
}
|
1818 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1819 |
function apbct_store__urls(){
|
1820 |
|
1821 |
global $apbct;
|
@@ -1825,30 +1753,33 @@ function apbct_store__urls(){
|
|
1825 |
// URLs HISTORY
|
1826 |
// Get current url
|
1827 |
$current_url = Server::get( 'HTTP_HOST' ) . Server::get( 'REQUEST_URI' );
|
1828 |
-
$current_url = $current_url ? substr($current_url, 0,
|
|
|
1829 |
|
1830 |
// Get already stored URLs
|
1831 |
-
$urls =
|
|
|
1832 |
$urls[$current_url][] = time();
|
1833 |
|
1834 |
// Rotating. Saving only latest 10
|
1835 |
-
|
1836 |
-
$urls
|
|
|
1837 |
|
1838 |
// Saving
|
1839 |
-
|
1840 |
|
1841 |
// REFERER
|
1842 |
-
// Get current
|
1843 |
$new_site_referer = apbct_get_server_variable( 'HTTP_REFERER' );
|
1844 |
-
$new_site_referer = $new_site_referer
|
1845 |
|
1846 |
// Get already stored referer
|
1847 |
-
$site_referer =
|
1848 |
|
1849 |
// Save if empty
|
1850 |
-
if(
|
1851 |
-
|
1852 |
}
|
1853 |
|
1854 |
$apbct->flags__url_stored = true;
|
@@ -1856,10 +1787,11 @@ function apbct_store__urls(){
|
|
1856 |
}
|
1857 |
}
|
1858 |
|
1859 |
-
|
1860 |
* Set Cookies test for cookie test
|
1861 |
-
* Sets cookies with
|
1862 |
* Sets test cookie with all other cookies
|
|
|
1863 |
*/
|
1864 |
function apbct_cookie(){
|
1865 |
|
@@ -1869,8 +1801,9 @@ function apbct_cookie(){
|
|
1869 |
empty($apbct->settings['data__set_cookies']) || // Do not set cookies if option is disabled (for Varnish cache).
|
1870 |
!empty($apbct->flags__cookies_setuped) || // Cookies already set
|
1871 |
!empty($apbct->headers_sent) // Headers sent
|
1872 |
-
)
|
1873 |
return false;
|
|
|
1874 |
|
1875 |
// Prevent headers sent error
|
1876 |
if(headers_sent($file, $line)){
|
@@ -1888,56 +1821,60 @@ function apbct_cookie(){
|
|
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
|
1895 |
$apbct_timestamp = time();
|
1896 |
-
|
1897 |
$cookie_test_value['cookies_names'][] = 'apbct_timestamp';
|
1898 |
$cookie_test_value['check_value'] .= $apbct_timestamp;
|
1899 |
}
|
1900 |
|
1901 |
-
//
|
1902 |
if( Server::get( 'HTTP_REFERER' ) ){
|
1903 |
-
|
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 =
|
1910 |
if(!$site_landing_timestamp){
|
1911 |
$site_landing_timestamp = time();
|
1912 |
-
|
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 =
|
1920 |
// Set / Increase
|
1921 |
-
$page_hits =
|
1922 |
|
1923 |
-
|
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 |
-
|
|
|
1932 |
|
1933 |
$apbct->flags__cookies_setuped = true;
|
|
|
|
|
1934 |
|
1935 |
}
|
1936 |
|
1937 |
/**
|
1938 |
-
* Cookies test for sender
|
1939 |
* Also checks for valid timestamp in $_COOKIE['apbct_timestamp'] and other apbct_ COOKIES
|
1940 |
-
* @return null|0|1
|
|
|
1941 |
*/
|
1942 |
function apbct_cookies_test()
|
1943 |
{
|
@@ -1949,34 +1886,36 @@ function apbct_cookies_test()
|
|
1949 |
|
1950 |
if(isset($_COOKIE['apbct_cookies_test'])){
|
1951 |
|
1952 |
-
$cookie_test = json_decode(urldecode($_COOKIE['apbct_cookies_test']),true);
|
1953 |
|
1954 |
-
if(!is_array($cookie_test))
|
1955 |
return 0;
|
|
|
1956 |
|
1957 |
-
$
|
1958 |
foreach($cookie_test['cookies_names'] as $cookie_name){
|
1959 |
-
$
|
1960 |
-
}
|
1961 |
|
1962 |
-
if($cookie_test['check_value'] == md5($
|
1963 |
return 1;
|
1964 |
-
}else{
|
1965 |
-
return 0;
|
1966 |
}
|
1967 |
-
|
1968 |
-
return
|
1969 |
}
|
|
|
|
|
1970 |
}
|
1971 |
|
1972 |
/**
|
1973 |
* Gets submit time
|
1974 |
* Uses Cookies with check via apbct_cookies_test()
|
1975 |
-
* @return null|int
|
|
|
1976 |
*/
|
1977 |
function apbct_get_submit_time()
|
1978 |
{
|
1979 |
-
$apbct_timestamp = (int)
|
1980 |
return apbct_cookies_test() === 1 && $apbct_timestamp !== 0 ? time() - $apbct_timestamp : null;
|
1981 |
}
|
1982 |
|
@@ -1988,8 +1927,8 @@ function ct_account_status_check($api_key = null, $process_errors = true){
|
|
1988 |
|
1989 |
global $apbct;
|
1990 |
|
1991 |
-
$api_key = $api_key
|
1992 |
-
$result =
|
1993 |
$api_key,
|
1994 |
preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
|
1995 |
! is_main_site() && $apbct->white_label ? 'anti-spam-hosting' : 'antispam'
|
@@ -2047,7 +1986,7 @@ function ct_mail_send_connection_report() {
|
|
2047 |
$to = "welcome@cleantalk.org" ;
|
2048 |
$subject = "Connection report for " . apbct_get_server_variable( 'HTTP_HOST' );
|
2049 |
$message = '
|
2050 |
-
<html>
|
2051 |
<head>
|
2052 |
<title></title>
|
2053 |
</head>
|
@@ -2074,7 +2013,7 @@ function ct_mail_send_connection_report() {
|
|
2074 |
}
|
2075 |
$message.='</table></body></html>';
|
2076 |
|
2077 |
-
$headers =
|
2078 |
$headers .= 'From: '.get_option('admin_email');
|
2079 |
mail($to, $subject, $message, $headers);
|
2080 |
}
|
@@ -2084,30 +2023,47 @@ function ct_mail_send_connection_report() {
|
|
2084 |
$apbct->saveData();
|
2085 |
}
|
2086 |
|
2087 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2088 |
function apbct_log($message = 'empty', $func = null, $params = array())
|
2089 |
{
|
2090 |
global $apbct;
|
2091 |
|
2092 |
$debug = get_option( APBCT_DEBUG );
|
2093 |
|
2094 |
-
$function = $func
|
2095 |
-
$cron = in_array('cron', $params)
|
2096 |
-
$data = in_array('data', $params)
|
2097 |
-
$settings = in_array('settings', $params)
|
2098 |
|
2099 |
-
if(is_array($message)
|
2100 |
-
$message = print_r($message, true);
|
|
|
2101 |
|
2102 |
-
if($message)
|
2103 |
-
|
2104 |
-
|
2105 |
-
if($
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2106 |
|
2107 |
update_option(APBCT_DEBUG, $debug);
|
2108 |
}
|
2109 |
|
2110 |
-
function apbct_sfw__delete_tables( $blog_id, $
|
2111 |
|
2112 |
global $wpdb;
|
2113 |
|
@@ -2129,11 +2085,11 @@ function apbct_sfw__delete_tables( $blog_id, $drop ) {
|
|
2129 |
*
|
2130 |
* @return boolean
|
2131 |
*/
|
2132 |
-
function apbct_is_user_enable($user = null) {
|
2133 |
|
2134 |
global $current_user;
|
2135 |
|
2136 |
-
$user =
|
2137 |
|
2138 |
return apbct_is_user_role_in(array('administrator', 'editor', 'author'), $user)
|
2139 |
? false
|
@@ -2150,24 +2106,36 @@ function apbct_is_user_enable($user = null) {
|
|
2150 |
*/
|
2151 |
function apbct_is_user_role_in( $roles, $user = false ){
|
2152 |
|
2153 |
-
if( is_numeric($user) && function_exists('get_userdata'))
|
2154 |
-
|
2155 |
-
|
2156 |
-
if(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2157 |
|
2158 |
-
if( empty($user->ID) )
|
2159 |
return false;
|
|
|
2160 |
|
2161 |
foreach( (array) $roles as $role ){
|
2162 |
-
if( isset($user->caps[ strtolower($role) ]) || in_array(strtolower($role), $user->roles) )
|
2163 |
return true;
|
|
|
2164 |
}
|
2165 |
|
2166 |
return false;
|
2167 |
}
|
2168 |
|
2169 |
/**
|
2170 |
-
* Update and rotate statistics with requests
|
2171 |
*
|
2172 |
* @param $exec_time
|
2173 |
*/
|
@@ -2176,17 +2144,19 @@ function apbct_statistics__rotate($exec_time){
|
|
2176 |
global $apbct;
|
2177 |
|
2178 |
// Delete old stats
|
2179 |
-
if(min(array_keys($apbct->stats['requests'])) < time() - (86400 * 7))
|
2180 |
-
unset($apbct->stats['requests'][min(array_keys($apbct->stats['requests']))]);
|
|
|
2181 |
|
2182 |
// Create new if newest older than 1 day
|
2183 |
-
if(empty($apbct->stats['requests']) || max(array_keys($apbct->stats['requests'])) < time() - (86400 * 1))
|
2184 |
-
$apbct->stats['requests'][time()] = array('amount' => 0, 'average_time' => 0);
|
|
|
2185 |
|
2186 |
// Update all existing stats
|
2187 |
foreach($apbct->stats['requests'] as &$weak_stat){
|
2188 |
$weak_stat['average_time'] = ($weak_stat['average_time'] * $weak_stat['amount'] + $exec_time) / ++$weak_stat['amount'];
|
2189 |
-
}
|
2190 |
|
2191 |
$apbct->save('stats');
|
2192 |
}
|
@@ -2194,14 +2164,14 @@ function apbct_statistics__rotate($exec_time){
|
|
2194 |
/**
|
2195 |
* Runs update actions for new version.
|
2196 |
*
|
2197 |
-
* @global
|
2198 |
*/
|
2199 |
function apbct_update_actions(){
|
2200 |
|
2201 |
global $apbct;
|
2202 |
|
2203 |
// Update logic
|
2204 |
-
if($apbct->plugin_version
|
2205 |
|
2206 |
// Main blog
|
2207 |
if(is_main_site()){
|
@@ -2210,9 +2180,10 @@ function apbct_update_actions(){
|
|
2210 |
|
2211 |
$result = apbct_run_update_actions($apbct->plugin_version, APBCT_VERSION);
|
2212 |
|
2213 |
-
//If update is
|
2214 |
-
if($result === true)
|
2215 |
-
apbct_update__set_version__from_plugin('from_plugin');
|
|
|
2216 |
|
2217 |
ct_send_feedback('0:' . APBCT_AGENT ); // Send feedback to let cloud know about updated version.
|
2218 |
|
@@ -2230,7 +2201,7 @@ function apbct_update_actions(){
|
|
2230 |
* @param string $ver
|
2231 |
*
|
2232 |
* @return bool
|
2233 |
-
* @global
|
2234 |
*
|
2235 |
*/
|
2236 |
function apbct_update__set_version__from_plugin($ver){
|
@@ -2244,7 +2215,6 @@ function apbct_update__set_version__from_plugin($ver){
|
|
2244 |
break;
|
2245 |
default:
|
2246 |
return false;
|
2247 |
-
break;
|
2248 |
}
|
2249 |
$apbct->saveData();
|
2250 |
return true;
|
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.160
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: https://cleantalk.org
|
9 |
Text Domain: cleantalk-spam-protect
|
10 |
Domain Path: /i18n
|
11 |
*/
|
12 |
|
13 |
+
use Cleantalk\ApbctWP\Activator;
|
14 |
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;
|
22 |
use Cleantalk\ApbctWP\Firewall\AntiCrawler;
|
23 |
+
use Cleantalk\ApbctWP\Firewall\AntiFlood;
|
24 |
use Cleantalk\ApbctWP\Firewall\SFW;
|
25 |
use Cleantalk\ApbctWP\Helper;
|
26 |
use Cleantalk\ApbctWP\RemoteCalls;
|
27 |
use Cleantalk\ApbctWP\RestController;
|
28 |
+
use Cleantalk\ApbctWP\State;
|
29 |
+
use Cleantalk\ApbctWP\Variables\Cookie;
|
30 |
+
use Cleantalk\Common\DNS;
|
31 |
+
use Cleantalk\Common\Firewall;
|
32 |
use Cleantalk\Common\Schema;
|
33 |
use Cleantalk\Variables\Get;
|
34 |
use Cleantalk\Variables\Server;
|
35 |
|
36 |
+
global $apbct, $wpdb, $pagenow;
|
37 |
+
|
38 |
$cleantalk_executed = false;
|
39 |
|
40 |
// Getting version form main file (look above)
|
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.
|
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
|
78 |
+
require_once(CLEANTALK_PLUGIN_DIR . 'lib/cleantalk-php-patch.php'); // Pathces fpr different functions which not exists
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
// Base classes
|
81 |
+
require_once(CLEANTALK_PLUGIN_DIR . 'lib/autoloader.php'); // Autoloader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
+
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-pluggable.php'); // Pluggable functions
|
84 |
+
require_once(CLEANTALK_PLUGIN_DIR . 'inc/cleantalk-common.php');
|
85 |
|
86 |
+
// Global ArrayObject with settings and other global variables
|
87 |
+
$apbct = new State('cleantalk', array('settings', 'data', 'debug', 'errors', 'remote_calls', 'stats', 'fw_stats'));
|
|
|
|
|
|
|
|
|
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';
|
95 |
+
$apbct->logo__small__colored = plugin_dir_url(__FILE__) . 'inc/images/logo_color.png';
|
96 |
+
|
97 |
+
// Customize \Cleantalk\ApbctWP\State
|
98 |
+
// Account status
|
99 |
+
|
100 |
+
$apbct->white_label = $apbct->network_settings['multisite__white_label'];
|
101 |
+
$apbct->allow_custom_key = $apbct->network_settings['multisite__allow_custom_key'];
|
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 doing 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
|
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 |
+
$firewall = new Firewall(
|
529 |
DB::getInstance()
|
530 |
);
|
531 |
|
553 |
}
|
554 |
|
555 |
if( $apbct->settings['sfw__anti_flood'] && is_null( apbct_wp_get_current_user() ) ){
|
556 |
+
$firewall->load_fw_module( new AntiFlood(
|
557 |
APBCT_TBL_FIREWALL_LOG,
|
558 |
APBCT_TBL_AC_LOG,
|
559 |
array(
|
569 |
}
|
570 |
|
571 |
/**
|
572 |
+
* Creating specific tables
|
573 |
+
*
|
574 |
+
* @param $sqls
|
575 |
+
* @param string $db_prefix
|
576 |
+
*
|
577 |
+
* @return void
|
578 |
+
* @depreacted Use Activator::create_tables() instead
|
579 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
function apbct_activation__create_tables( $sqls, $db_prefix = '' ) {
|
581 |
+
Activator::create_tables( $sqls, $db_prefix );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
582 |
}
|
583 |
|
584 |
/**
|
585 |
+
* Redirects admin to plugin settings after activation.
|
586 |
+
* @psalm-suppress UnusedVariable
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
587 |
*/
|
588 |
function apbct_plugin_redirect()
|
589 |
{
|
596 |
}
|
597 |
}
|
598 |
|
599 |
+
/**
|
600 |
+
* @param $event_type
|
601 |
+
* @psalm-suppress UnusedVariable
|
602 |
+
*/
|
603 |
function ct_add_event($event_type)
|
604 |
{
|
605 |
global $apbct, $cleantalk_executed;
|
612 |
case '1': $event_type = 'yes';break;
|
613 |
}
|
614 |
|
615 |
+
$current_hour = (int) date( 'G' );
|
616 |
|
617 |
// Updating current hour
|
618 |
if($current_hour!=$apbct->data['current_hour']){
|
622 |
}
|
623 |
|
624 |
//Add 1 to counters
|
625 |
+
if( $event_type === 'yes'){
|
626 |
$apbct->data['array_accepted'][$current_hour]++;
|
627 |
$apbct->data['admin_bar__all_time_counter']['accepted']++;
|
628 |
$apbct->data['user_counter']['accepted']++;
|
629 |
}
|
630 |
+
if( $event_type === 'no'){
|
631 |
$apbct->data['array_blocked'][$current_hour]++;
|
632 |
$apbct->data['admin_bar__all_time_counter']['blocked']++;
|
633 |
$apbct->data['user_counter']['blocked']++;
|
643 |
*/
|
644 |
function ct_get_cookie()
|
645 |
{
|
|
|
646 |
$ct_checkjs_key = ct_get_checkjs_value();
|
647 |
print $ct_checkjs_key;
|
648 |
die();
|
663 |
// This action triggered by wp_schedule_single_event( time() + 900, 'ct_sfw_update' );
|
664 |
add_action( 'apbct_sfw_update__init', 'apbct_sfw_update__init' );
|
665 |
|
|
|
666 |
/**
|
667 |
* Called by sfw_update remote call
|
668 |
* Starts SFW update and could use a delay before start
|
672 |
* @return bool|string|string[]
|
673 |
*/
|
674 |
function apbct_sfw_update__init( $delay = 0 ){
|
675 |
+
|
676 |
global $apbct;
|
677 |
+
|
678 |
+
// Prevent start an update if update is already running and started less than 10 minutes ago
|
679 |
if(
|
|
|
680 |
$apbct->fw_stats['firewall_updating_id'] &&
|
681 |
+
time() - $apbct->fw_stats['firewall_updating_last_start'] < 600 &&
|
682 |
+
apbct_sfw_update__is_in_progress()
|
683 |
){
|
684 |
return false;
|
685 |
}
|
686 |
+
|
687 |
+
if( ! $apbct->settings['sfw__enabled'] ) {
|
688 |
+
return array( 'error' => 'SFW UPDATE INIT: SFW_IS_DISABLED' );
|
689 |
+
}
|
690 |
|
691 |
// Key is empty
|
692 |
+
if( ! $apbct->api_key && ! $apbct->ip_license){
|
693 |
+
return array( 'error' => 'SFW UPDATE INIT: KEY_IS_EMPTY' );
|
694 |
}
|
695 |
|
696 |
if( ! $apbct->data['key_is_ok'] ){
|
698 |
}
|
699 |
|
700 |
// Set a new update ID and an update time start
|
701 |
+
$apbct->fw_stats['firewall_updating_id'] = md5( (string) rand( 0, 100000 ) );
|
702 |
$apbct->fw_stats['firewall_updating_last_start'] = time();
|
703 |
$apbct->save( 'fw_stats' );
|
704 |
|
706 |
$apbct->error_delete( 'sfw_update', 'save_data' );
|
707 |
$apbct->error_delete( 'sfw_update', 'save_data', 'cron' );
|
708 |
|
709 |
+
\Cleantalk\ApbctWP\Queue::clearQueue();
|
710 |
+
|
711 |
+
$queue = new \Cleantalk\ApbctWP\Queue();
|
712 |
+
$queue->addStage( 'apbct_sfw_update__get_multifiles' );
|
713 |
+
|
714 |
+
apbct_prepare_upd_dir();
|
715 |
+
|
716 |
+
$cron = new Cron();
|
717 |
+
$cron->addTask('sfw_update_checker', 'apbct_sfw_update__checker', 15, time() + 15 );
|
718 |
+
|
719 |
+
return Helper::http__request__rc_to_host(
|
720 |
+
'sfw_update__worker',
|
721 |
+
array( 'delay' => $delay ),
|
722 |
+
array( 'async' )
|
723 |
+
);
|
724 |
+
}
|
725 |
+
|
726 |
+
/**
|
727 |
+
* Called by sfw_update__worker remote call
|
728 |
+
* gather all process about SFW updating
|
729 |
+
*
|
730 |
+
* @param null|string $updating_id
|
731 |
+
* @param null|string $multifile_url
|
732 |
+
* @param null|string|int $url_count
|
733 |
+
* @param null|string|int $current_url
|
734 |
+
* @param string $useragent_url
|
735 |
+
*
|
736 |
+
* @return array|bool|int|string[]
|
737 |
+
*/
|
738 |
+
function apbct_sfw_update__worker() {
|
739 |
+
|
740 |
+
global $apbct;
|
741 |
+
|
742 |
+
if( ! $apbct->data['key_is_ok'] ){
|
743 |
+
return array( 'error' => 'Worker: KEY_IS_NOT_VALID' );
|
744 |
+
}
|
745 |
+
|
746 |
+
$queue = new \Cleantalk\ApbctWP\Queue();
|
747 |
+
|
748 |
+
if( count( $queue->queue['stages'] ) === 0 ) {
|
749 |
+
// Queue is already empty. Exit.
|
750 |
+
return true;
|
751 |
+
}
|
752 |
+
|
753 |
+
$result = $queue->executeStage();
|
754 |
+
|
755 |
+
if( isset( $result['error'] ) ) {
|
756 |
+
$apbct->error_add('sfw_update', $result['error'] );
|
757 |
+
$apbct->saveErrors();
|
758 |
+
return $result['error'];
|
759 |
+
}
|
760 |
+
|
761 |
+
if( $queue->isQueueFinished() ) {
|
762 |
+
|
763 |
+
$queue->queue['finished'] = time();
|
764 |
+
$queue->saveQueue( $queue->queue );
|
765 |
+
foreach( $queue->queue['stages'] as $stage ) {
|
766 |
+
if( isset( $stage['error'] ) ) {
|
767 |
+
$apbct->error_add('sfw_update', $stage['error'] );
|
768 |
+
}
|
769 |
+
}
|
770 |
+
// Do logging the queue process here
|
771 |
+
return true;
|
772 |
+
|
773 |
+
}
|
774 |
+
|
775 |
+
if( stripos( Get::get('stage'), 'Repeat' ) !== false ) {
|
776 |
+
// This is the repeat stage request, do not generate any new RC
|
777 |
+
return true;
|
778 |
+
}
|
779 |
+
|
780 |
+
$cron = new Cron();
|
781 |
+
if( ! $cron->updateTask('sfw_update_checker', 'apbct_sfw_update__checker', 15, time() + 15 ) ) {
|
782 |
+
$cron->addTask('sfw_update_checker', 'apbct_sfw_update__checker', 15, time() + 15 );
|
783 |
+
}
|
784 |
+
|
785 |
+
return Helper::http__request__rc_to_host(
|
786 |
+
'sfw_update__worker',
|
787 |
+
array(),
|
788 |
+
array( 'async' )
|
789 |
+
);
|
790 |
+
|
791 |
+
}
|
792 |
+
|
793 |
+
function apbct_sfw_update__get_multifiles(){
|
794 |
+
|
795 |
+
global $apbct;
|
796 |
+
|
797 |
+
if( ! $apbct->data['key_is_ok'] ){
|
798 |
+
return array( 'error' => 'Get multifiles: KEY_IS_NOT_VALID' );
|
799 |
+
}
|
800 |
+
|
801 |
+
// Getting remote file name
|
802 |
+
$result = API::method__get_2s_blacklists_db( $apbct->api_key, 'multifiles', '3_1' );
|
803 |
+
|
804 |
+
if( empty( $result['error'] ) ){
|
805 |
+
|
806 |
+
if( ! empty( $result['file_url'] ) ) {
|
807 |
+
$file_urls = Helper::http__get_data_from_remote_gz__and_parse_csv( $result['file_url'] );
|
808 |
+
if( empty( $file_urls['error'] ) ){
|
809 |
+
if( ! empty( $result['file_ua_url'] ) ) {
|
810 |
+
$file_urls[][0] = $result['file_ua_url'];
|
811 |
+
}
|
812 |
+
if( ! empty( $result['file_ck_url'] ) ) {
|
813 |
+
$file_urls[][0] = $result['file_ck_url'];
|
814 |
+
}
|
815 |
+
$urls = array();
|
816 |
+
foreach ( $file_urls as $value ) {
|
817 |
+
$urls[] = $value[0];
|
818 |
+
}
|
819 |
+
|
820 |
+
$apbct->fw_stats['firewall_update_percent'] = 100 / count( $urls );
|
821 |
+
$apbct->save( 'fw_stats' );
|
822 |
+
|
823 |
+
return array(
|
824 |
+
'next_stage' => array(
|
825 |
+
'name' => 'apbct_sfw_update__download_files',
|
826 |
+
'args' => $urls,
|
827 |
+
'is_last' => '0'
|
828 |
+
)
|
829 |
+
);
|
830 |
+
|
831 |
+
}
|
832 |
+
|
833 |
+
return array( 'error' => $file_urls['error'] );
|
834 |
+
}
|
835 |
+
|
836 |
+
}else {
|
837 |
+
return $result;
|
838 |
+
}
|
839 |
+
}
|
840 |
+
|
841 |
+
function apbct_sfw_update__download_files( $urls ) {
|
842 |
+
|
843 |
+
sleep(3);
|
844 |
+
|
845 |
+
//Reset keys
|
846 |
+
$urls = array_values( $urls );
|
847 |
+
$results = Helper::http__multi_request( $urls, APBCT_DIR_PATH . '/fw_files/' );
|
848 |
+
$count_urls = count( $urls );
|
849 |
+
$count_results = count( $results );
|
850 |
+
|
851 |
+
if ( empty( $results['error'] ) && ( $count_urls === $count_results ) ) {
|
852 |
+
$download_again = array();
|
853 |
+
for( $i = 0; $i < $count_results; $i++ ) {
|
854 |
+
if( $results[$i] === 'error' ) {
|
855 |
+
$download_again[] = $urls[$i];
|
856 |
+
}
|
857 |
+
}
|
858 |
+
|
859 |
+
if( count( $download_again ) !== 0 ) {
|
860 |
+
return array(
|
861 |
+
'error' => 'Files download not completed.',
|
862 |
+
'update_args' => array(
|
863 |
+
'args' => $download_again
|
864 |
+
)
|
865 |
+
);
|
866 |
+
}
|
867 |
+
|
868 |
+
return array(
|
869 |
+
'next_stage' => array(
|
870 |
+
'name' => 'apbct_sfw_update__create_tables'
|
871 |
+
)
|
872 |
+
);
|
873 |
+
}
|
874 |
+
|
875 |
+
if ( ! empty( $results['error'] ) ) {
|
876 |
+
return $results;
|
877 |
+
}
|
878 |
+
|
879 |
+
return array( 'error' => 'Files download not completed.' );
|
880 |
+
|
881 |
+
}
|
882 |
+
|
883 |
+
function apbct_sfw_update__create_tables() {
|
884 |
+
global $apbct;
|
885 |
+
// Preparing database infrastructure
|
886 |
+
// Creating SFW tables to make sure that they are exist
|
887 |
+
apbct_activation__create_tables( Schema::getSchema( 'sfw' ), $apbct->db_prefix );
|
888 |
+
return array(
|
889 |
+
'next_stage' => array(
|
890 |
+
'name' => 'apbct_sfw_update__create_temp_tables',
|
891 |
+
)
|
892 |
+
);
|
893 |
+
}
|
894 |
+
|
895 |
+
function apbct_sfw_update__create_temp_tables() {
|
896 |
+
// Preparing temporary tables
|
897 |
+
$result = SFW::create_temp_tables( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
|
898 |
+
if( ! empty( $result['error'] ) ) {
|
899 |
+
return $result;
|
900 |
+
}
|
901 |
+
return array(
|
902 |
+
'next_stage' => array(
|
903 |
+
'name' => 'apbct_sfw_update__process_files',
|
904 |
+
)
|
905 |
+
);
|
906 |
+
}
|
907 |
+
|
908 |
+
/**
|
909 |
+
* @psalm-suppress UnusedParam
|
910 |
+
*/
|
911 |
+
function apbct_sfw_update__process_files( $concrete_file = null ) {
|
912 |
+
|
913 |
+
global $apbct;
|
914 |
+
|
915 |
+
$dir_name = APBCT_DIR_PATH . '/fw_files/';
|
916 |
+
$files = glob( $dir_name . '/*' );
|
917 |
+
$files = array_filter( $files, static function( $element ) {
|
918 |
+
return strpos( $element, 'list' ) !== false;
|
919 |
+
} );
|
920 |
+
|
921 |
+
if( count( $files ) ) {
|
922 |
+
|
923 |
+
reset( $files );
|
924 |
+
$concrete_file = current( $files );
|
925 |
+
|
926 |
+
if( strpos( $concrete_file, 'bl_list' ) !== false ) {
|
927 |
+
$result = apbct_sfw_update__process_file( $concrete_file );
|
928 |
+
}
|
929 |
+
|
930 |
+
if( strpos( $concrete_file, 'ua_list' ) !== false ) {
|
931 |
+
$result = apbct_sfw_update__process_ua( $concrete_file );
|
932 |
+
}
|
933 |
+
|
934 |
+
if( strpos( $concrete_file, 'ck_list' ) !== false ) {
|
935 |
+
$result = apbct_sfw_update__process_ck( $concrete_file );
|
936 |
+
}
|
937 |
+
|
938 |
+
if( ! empty( $result['error'] ) ) {
|
939 |
+
return $result;
|
940 |
+
}
|
941 |
+
|
942 |
+
$apbct->fw_stats['firewall_update_percent'] = round( 100 / count( $files ), 2 ) * 100;
|
943 |
+
$apbct->save( 'fw_stats' );
|
944 |
+
|
945 |
+
return array(
|
946 |
+
'next_stage' => array(
|
947 |
+
'name' => 'apbct_sfw_update__process_files',
|
948 |
+
'args' => $concrete_file
|
949 |
+
)
|
950 |
+
);
|
951 |
+
}
|
952 |
+
|
953 |
+
return array(
|
954 |
+
'next_stage' => array(
|
955 |
+
'name' => 'apbct_sfw_update__process_exclusions',
|
956 |
+
)
|
957 |
+
);
|
958 |
+
|
959 |
+
}
|
960 |
+
|
961 |
+
function apbct_sfw_update__process_file( $file_path ){
|
962 |
+
|
963 |
+
if( ! file_exists( $file_path ) ) {
|
964 |
+
return array( 'error' => 'PROCESS FILE: ' . $file_path . ' is not exists.' );
|
965 |
+
}
|
966 |
+
|
967 |
+
$result = SFW::update__write_to_db(
|
968 |
+
DB::getInstance(),
|
969 |
+
APBCT_TBL_FIREWALL_DATA . '_temp',
|
970 |
+
$file_path
|
971 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
972 |
|
973 |
+
if( ! empty( $result['error'] ) ){
|
974 |
+
return array( 'error' => 'PROCESS FILE: ' . $result['error'] );
|
975 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
976 |
|
977 |
+
if( ! is_int( $result ) ){
|
978 |
+
return array( 'error' => 'PROCESS FILE: WRONG RESPONSE FROM update__write_to_db' );
|
979 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
980 |
|
981 |
+
return $result;
|
|
|
|
|
982 |
|
983 |
+
}
|
|
|
|
|
|
|
|
|
984 |
|
985 |
+
function apbct_sfw_update__process_ua( $file_path ){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
986 |
|
987 |
+
$result = AntiCrawler::update( $file_path );
|
988 |
|
989 |
+
if( ! empty( $result['error'] ) ){
|
990 |
+
return array( 'error' => 'UPDATING UA LIST: ' . $result['error'] );
|
991 |
+
}
|
992 |
+
|
993 |
+
if( ! is_int( $result ) ){
|
994 |
+
return array( 'error' => 'UPDATING UA LIST: : WRONG_RESPONSE AntiCrawler::update' );
|
995 |
+
}
|
996 |
+
|
997 |
+
return $result;
|
998 |
}
|
999 |
|
1000 |
+
function apbct_sfw_update__process_ck( $file_path ) {
|
1001 |
|
1002 |
+
global $apbct;
|
1003 |
|
1004 |
+
// Save expected_networks_count and expected_ua_count if exists
|
1005 |
+
$file_content = file_get_contents( $file_path );
|
|
|
|
|
|
|
|
|
|
|
|
|
1006 |
|
1007 |
+
if(function_exists('gzdecode')) {
|
|
|
|
|
1008 |
|
1009 |
+
$unzipped_content = gzdecode( $file_content );
|
|
|
1010 |
|
1011 |
+
if ( $unzipped_content !== false ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1012 |
|
1013 |
+
$file_ck_url__data = Helper::buffer__parse__csv( $unzipped_content );
|
|
|
|
|
1014 |
|
1015 |
+
if( ! empty( $file_ck_url__data['error'] ) ){
|
1016 |
+
return array( 'error' => 'GET EXPECTED RECORDS COUNT DATA: ' . $file_ck_url__data['error'] );
|
1017 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1018 |
|
1019 |
+
$expected_networks_count = 0;
|
1020 |
+
$expected_ua_count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1021 |
|
1022 |
+
foreach( $file_ck_url__data as $value ) {
|
1023 |
+
if( trim( $value[0], '"' ) === 'networks_count' ){
|
1024 |
+
$expected_networks_count = $value[1];
|
1025 |
+
}
|
1026 |
+
if( trim( $value[0], '"' ) === 'ua_count' ) {
|
1027 |
+
$expected_ua_count = $value[1];
|
1028 |
+
}
|
1029 |
+
}
|
1030 |
+
|
1031 |
+
$apbct->fw_stats['expected_networks_count'] = $expected_networks_count;
|
1032 |
+
$apbct->fw_stats['expected_ua_count'] = $expected_ua_count;
|
1033 |
+
$apbct->save( 'fw_stats' );
|
1034 |
+
|
1035 |
+
if( file_exists( $file_path ) ) {
|
1036 |
+
unlink($file_path);
|
1037 |
+
}
|
1038 |
+
|
1039 |
+
} else {
|
1040 |
+
return array( 'error' => 'Can not unpack datafile');
|
1041 |
+
}
|
1042 |
+
} else {
|
1043 |
+
return array( 'error' => 'Function gzdecode not exists. Please update your PHP at least to version 5.4 ' );
|
1044 |
+
}
|
1045 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1046 |
}
|
1047 |
|
1048 |
+
function apbct_sfw_update__process_exclusions(){
|
1049 |
global $apbct;
|
1050 |
|
1051 |
$result = SFW::update__write_to_db__exclusions(
|
1068 |
$apbct->fw_stats['expected_networks_count'] += $result;
|
1069 |
$apbct->save( 'fw_stats' );
|
1070 |
}
|
1071 |
+
|
1072 |
+
return array(
|
1073 |
+
'next_stage' => array(
|
1074 |
+
'name' => 'apbct_sfw_update__end_of_update'
|
1075 |
+
)
|
1076 |
+
);
|
1077 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1078 |
}
|
1079 |
|
1080 |
function apbct_sfw_update__end_of_update() {
|
1083 |
|
1084 |
// REMOVE AND RENAME
|
1085 |
$result = SFW::data_tables__delete( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
|
1086 |
+
if( ! empty( $result['error'] ) ) {
|
1087 |
return $result;
|
1088 |
+
}
|
1089 |
$result = SFW::rename_data_tables__from_temp_to_main( DB::getInstance(), APBCT_TBL_FIREWALL_DATA );
|
1090 |
+
if( ! empty( $result['error'] ) ) {
|
1091 |
return $result;
|
1092 |
+
}
|
1093 |
|
1094 |
// Increment firewall entries
|
1095 |
$apbct->fw_stats['firewall_update_percent'] = 0;
|
1112 |
/**
|
1113 |
* Checking the integrity of the sfw database update
|
1114 |
*/
|
1115 |
+
//@ToDo NEED TO BE REVIEWED
|
1116 |
global $ct_cron;
|
1117 |
|
1118 |
if( $apbct->stats['sfw']['entries'] != $apbct->fw_stats['expected_networks_count'] ) {
|
1119 |
|
1120 |
# call manually
|
1121 |
+
/** @psalm-suppress TypeDoesNotContainType */
|
1122 |
if( ! $ct_cron ){
|
1123 |
return array(
|
1124 |
'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']);
|
1145 |
$apbct->error_delete( 'sfw_update', 'save_settings' );
|
1146 |
|
1147 |
// Get update period for server
|
1148 |
+
$update_period = DNS::getRecord( 'spamfirewall-ttl-txt.cleantalk.org', true, DNS_TXT );
|
1149 |
$update_period = isset( $update_period['txt'] ) ? $update_period['txt'] : 0;
|
1150 |
+
$update_period = (int) $update_period > 14400 ? (int) $update_period : 14400;
|
1151 |
$cron = new Cron();
|
1152 |
$cron->updateTask('sfw_update', 'apbct_sfw_update__init', $update_period );
|
1153 |
+
$cron->updateTask('sfw_update_checker', 'apbct_sfw_update__checker', 0 );
|
1154 |
|
1155 |
/**
|
1156 |
* Update fw data if update completed
|
1164 |
|
1165 |
}
|
1166 |
|
1167 |
+
|
1168 |
+
function apbct_sfw_update__is_in_progress() {
|
1169 |
+
$queue = new \Cleantalk\ApbctWP\Queue();
|
1170 |
+
return $queue->isQueueInProgress();
|
1171 |
+
}
|
1172 |
+
|
1173 |
+
function apbct_prepare_upd_dir() {
|
1174 |
+
$dir_name = APBCT_DIR_PATH . '/fw_files/';
|
1175 |
+
if( ! is_dir( $dir_name ) ) {
|
1176 |
+
if( ! mkdir( $dir_name ) && ! is_dir( $dir_name ) ) {
|
1177 |
+
return array( 'error', 'Can not to make FW dir.' );
|
1178 |
+
}
|
1179 |
+
} else {
|
1180 |
+
$files = glob( $dir_name . '/*' );
|
1181 |
+
if( $files === false ) {
|
1182 |
+
return array( 'error', 'Can not find FW files.' );
|
1183 |
+
}
|
1184 |
+
if( count( $files ) === 0 ) {
|
1185 |
+
return (bool) file_put_contents( $dir_name . 'index.php', '<?php' . PHP_EOL );
|
1186 |
+
}
|
1187 |
+
foreach( $files as $file ){
|
1188 |
+
if( is_file( $file ) ) {
|
1189 |
+
if( unlink( $file ) === false ) {
|
1190 |
+
return array( 'error', 'Can not delete the FW file: ' . $file );
|
1191 |
+
}
|
1192 |
+
}
|
1193 |
+
}
|
1194 |
+
}
|
1195 |
+
return (bool) file_put_contents( $dir_name . 'index.php', '<?php' );
|
1196 |
+
}
|
1197 |
+
|
1198 |
+
function apbct_sfw_update__checker() {
|
1199 |
+
$queue = new \Cleantalk\ApbctWP\Queue();
|
1200 |
+
if( count( $queue->queue['stages'] ) ) {
|
1201 |
+
foreach( $queue->queue['stages'] as $stage ) {
|
1202 |
+
if ( $stage['status'] === 'NULL' ) {
|
1203 |
+
return apbct_sfw_update__worker();
|
1204 |
+
}
|
1205 |
+
}
|
1206 |
+
}
|
1207 |
+
}
|
1208 |
+
|
1209 |
function apbct_sfw_update__cleanData(){
|
1210 |
|
1211 |
global $apbct;
|
1257 |
|
1258 |
if( $apbct->settings['sfw__anti_flood'] || $apbct->settings['sfw__anti_crawler'] ){
|
1259 |
|
1260 |
+
$anti_flood = new AntiFlood(
|
1261 |
APBCT_TBL_FIREWALL_LOG,
|
1262 |
APBCT_TBL_AC_LOG,
|
1263 |
array(
|
1270 |
}
|
1271 |
}
|
1272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1273 |
/**
|
1274 |
* Install plugin from wordpress catalog
|
1275 |
*
|
1276 |
+
* @param null|WP $_wp
|
1277 |
+
* @param null|string|array $plugin
|
1278 |
+
* @psalm-suppress UndefinedClass
|
1279 |
*/
|
1280 |
+
function apbct_rc__install_plugin($_wp = null, $plugin = null){
|
1281 |
global $wp_version;
|
1282 |
|
1283 |
+
if( is_null( $plugin ) ) {
|
1284 |
+
$plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
|
1285 |
+
}
|
1286 |
|
1287 |
if($plugin){
|
1288 |
|
1297 |
'plugin_information',
|
1298 |
array(
|
1299 |
'slug' => $plugin_slug,
|
1300 |
+
'fields' => array('version' => true, 'download_link' => true,),
|
1301 |
)
|
1302 |
);
|
1303 |
|
1319 |
if($installer->apbct_result === 'OK'){
|
1320 |
die('OK');
|
1321 |
|
1322 |
+
}else {
|
1323 |
+
die( 'FAIL ' . json_encode( array( 'error' => $installer->apbct_result ) ) );
|
1324 |
+
}
|
1325 |
+
}else {
|
1326 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'FAIL_TO_GET_LATEST_VERSION',
|
1327 |
+
'details' => $result->get_error_message(),
|
1328 |
+
) ) );
|
1329 |
+
}
|
1330 |
+
}else {
|
1331 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_SLUG_INCORRECT' ) ) );
|
1332 |
+
}
|
1333 |
+
}else {
|
1334 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_INCORRECT' ) ) );
|
1335 |
+
}
|
1336 |
+
}else {
|
1337 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_UNSET' ) ) );
|
1338 |
+
}
|
1339 |
}
|
1340 |
|
1341 |
function apbct_rc__activate_plugin($plugin){
|
1342 |
+
|
1343 |
+
if( ! $plugin ) {
|
1344 |
+
$plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
|
1345 |
+
}
|
1346 |
|
1347 |
if($plugin){
|
1348 |
|
1354 |
|
1355 |
if($result && !is_wp_error($result)){
|
1356 |
return array('success' => true);
|
1357 |
+
}else {
|
1358 |
+
return array( 'error' => 'FAIL_TO_ACTIVATE',
|
1359 |
+
'details' => ( is_wp_error( $result ) ? ' ' . $result->get_error_message() : '' )
|
1360 |
+
);
|
1361 |
+
}
|
1362 |
+
}else {
|
1363 |
+
return array( 'error' => 'PLUGIN_NAME_IS_INCORRECT' );
|
1364 |
+
}
|
1365 |
+
}else {
|
1366 |
+
return array( 'error' => 'PLUGIN_NAME_IS_UNSET' );
|
1367 |
+
}
|
1368 |
}
|
1369 |
|
1370 |
/**
|
1371 |
* Uninstall plugin from wordpress catalog
|
1372 |
*
|
1373 |
+
* @param null $plugin
|
1374 |
*/
|
1375 |
function apbct_rc__deactivate_plugin($plugin = null){
|
1376 |
|
1377 |
global $apbct;
|
1378 |
+
|
1379 |
+
if( is_null( $plugin ) ) {
|
1380 |
+
$plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
|
1381 |
+
}
|
1382 |
|
1383 |
if($plugin){
|
1384 |
|
1385 |
// Switching complete deactivation for security
|
1386 |
+
if( $plugin === 'security-malware-firewall/security-malware-firewall.php' && !empty($_GET['misc__complete_deactivation'])){
|
1387 |
$spbc_settings = get_option('spbc_settings');
|
1388 |
+
$spbc_settings['misc__complete_deactivation'] = (int) $_GET['misc__complete_deactivation'];
|
1389 |
update_option('spbc_settings', $spbc_settings);
|
1390 |
}
|
1391 |
|
1394 |
if(is_plugin_active( $plugin )){
|
1395 |
// Hook to set flag if the plugin is deactivated
|
1396 |
add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
|
1397 |
+
deactivate_plugins($plugin, false, is_multisite() );
|
1398 |
}else{
|
1399 |
$apbct->plugin_deactivated = true;
|
1400 |
}
|
1401 |
|
1402 |
// Hook to set flag if the plugin is deactivated
|
1403 |
add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
|
1404 |
+
deactivate_plugins($plugin, false, is_multisite() );
|
1405 |
|
1406 |
if($apbct->plugin_deactivated){
|
1407 |
die('OK');
|
1408 |
+
}else {
|
1409 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_STILL_ACTIVE' ) ) );
|
1410 |
+
}
|
1411 |
+
}else {
|
1412 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_UNSET' ) ) );
|
1413 |
+
}
|
1414 |
}
|
1415 |
|
1416 |
|
1422 |
function apbct_rc__uninstall_plugin($plugin = null){
|
1423 |
|
1424 |
global $apbct;
|
1425 |
+
|
1426 |
+
if( is_null( $plugin ) ) {
|
1427 |
+
$plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : null;
|
1428 |
+
}
|
1429 |
|
1430 |
if($plugin){
|
1431 |
|
1432 |
// Switching complete deactivation for security
|
1433 |
+
if( $plugin === 'security-malware-firewall/security-malware-firewall.php' && !empty($_GET['misc__complete_deactivation'])){
|
1434 |
$spbc_settings = get_option('spbc_settings');
|
1435 |
+
$spbc_settings['misc__complete_deactivation'] = (int) $_GET['misc__complete_deactivation'];
|
1436 |
update_option('spbc_settings', $spbc_settings);
|
1437 |
}
|
1438 |
|
1441 |
if(is_plugin_active( $plugin )){
|
1442 |
// Hook to set flag if the plugin is deactivated
|
1443 |
add_action( 'deactivate_'.$plugin, 'apbct_rc__uninstall_plugin__check_deactivate' );
|
1444 |
+
deactivate_plugins($plugin, false, is_multisite() );
|
1445 |
}else{
|
1446 |
$apbct->plugin_deactivated = true;
|
1447 |
}
|
1454 |
|
1455 |
if($result && !is_wp_error($result)){
|
1456 |
die('OK');
|
1457 |
+
}else {
|
1458 |
+
die( 'FAIL ' . json_encode( array(
|
1459 |
+
'error' => 'PLUGIN_STILL_EXISTS',
|
1460 |
+
'details' => ( is_wp_error( $result ) ? ' ' . $result->get_error_message() : '' )
|
1461 |
+
) ) );
|
1462 |
+
}
|
1463 |
+
}else {
|
1464 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_STILL_ACTIVE' ) ) );
|
1465 |
+
}
|
1466 |
+
}else {
|
1467 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'PLUGIN_NAME_IS_UNSET' ) ) );
|
1468 |
+
}
|
1469 |
}
|
1470 |
|
1471 |
function apbct_rc__uninstall_plugin__check_deactivate(){
|
1473 |
$apbct->plugin_deactivated = true;
|
1474 |
}
|
1475 |
|
1476 |
+
/**
|
1477 |
+
* @throws JsonException
|
1478 |
+
* @psalm-suppress UndefinedClass
|
1479 |
+
*/
|
1480 |
function apbct_rc__update(){
|
1481 |
global $wp_version;
|
1482 |
|
1498 |
include_once( ABSPATH . 'wp-admin/includes/file.php' );
|
1499 |
include_once( ABSPATH . 'wp-admin/includes/misc.php' );
|
1500 |
|
1501 |
+
apbct_maintenance_mode__enable( 30 );
|
1502 |
|
1503 |
if (version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0){
|
1504 |
$upgrader = new CleantalkUpgrader( new CleantalkUpgraderSkin( compact('title', 'nonce', 'url', 'plugin') ) );
|
1509 |
$upgrader_result = $upgrader->upgrade( $plugin );
|
1510 |
if( is_wp_error( $upgrader_result ) ){
|
1511 |
error_log('CleanTalk debug message:');
|
1512 |
+
error_log( var_export( $upgrader_result->get_error_message(), true) );
|
1513 |
}
|
1514 |
|
1515 |
+
apbct_maintenance_mode__disable();
|
1516 |
|
1517 |
$result = activate_plugins( $plugin, '', $activate_for_network );
|
1518 |
|
1519 |
// Changing response UP_TO_DATE to OK
|
1520 |
+
if($upgrader->apbct_result === 'UP_TO_DATE') {
|
1521 |
$upgrader->apbct_result = 'OK';
|
1522 |
+
}
|
1523 |
|
1524 |
if($upgrader->apbct_result === 'OK'){
|
1525 |
|
1526 |
if(is_wp_error($result)){
|
1527 |
+
die( 'FAIL ' . json_encode( array( 'error' => 'COULD_NOT_ACTIVATE', 'wp_error' => $result->get_error_message() ) ) );
|
1528 |
}
|
1529 |
|
1530 |
$httpResponseCode = Helper::http__request(get_option('siteurl'), array(), 'get_code');
|
1531 |
|
1532 |
if( strpos($httpResponseCode, '200') === false ){
|
1533 |
|
1534 |
+
apbct_maintenance_mode__enable( 30 );
|
1535 |
|
1536 |
// Rollback
|
1537 |
+
if (version_compare(PHP_VERSION, '5.6.0') >= 0 && version_compare($wp_version, '5.3') >= 0) {
|
1538 |
+
$rollback = new CleantalkUpgrader( new CleantalkUpgraderSkin( compact( 'title', 'nonce', 'url', 'plugin_slug', 'prev_version' ) ) );
|
1539 |
+
}
|
1540 |
+
else {
|
1541 |
+
$rollback = new CleantalkUpgrader( new CleantalkUpgraderSkin_Deprecated( compact( 'title', 'nonce', 'url', 'plugin_slug', 'prev_version' ) ) );
|
1542 |
+
}
|
1543 |
$rollback->rollback($plugin);
|
1544 |
|
1545 |
+
apbct_maintenance_mode__disable();
|
1546 |
|
1547 |
// @todo add execution time
|
1548 |
|
1553 |
'rollback_result' => $rollback->apbct_result,
|
1554 |
);
|
1555 |
|
1556 |
+
die( 'FAIL ' . json_encode( $response ) );
|
1557 |
}
|
1558 |
|
1559 |
$plugin_data = get_plugin_data(__FILE__);
|
1560 |
$apbct_agent = 'wordpress-'.str_replace('.', '', $plugin_data['Version']);
|
1561 |
ct_send_feedback('0:' . $apbct_agent);
|
1562 |
|
1563 |
+
die( 'OK ' . json_encode( array( 'agent' => $apbct_agent ) ) );
|
1564 |
|
|
|
|
|
1565 |
}
|
1566 |
+
|
1567 |
+
die( 'FAIL ' . json_encode( array( 'error' => $upgrader->apbct_result ) ) );
|
1568 |
}
|
1569 |
|
1570 |
+
/**
|
1571 |
+
* @param $source
|
1572 |
+
*
|
1573 |
+
* @return bool
|
1574 |
+
*/
|
1575 |
function apbct_rc__update_settings($source) {
|
1576 |
|
1577 |
global $apbct;
|
1581 |
$var = $source[$setting];
|
1582 |
$type = gettype($def_value);
|
1583 |
settype($var, $type);
|
1584 |
+
if( $type === 'string') {
|
1585 |
+
$var = preg_replace( array( '/=/', '/`/' ), '', $var );
|
1586 |
+
}
|
1587 |
$apbct->settings[$setting] = $var;
|
1588 |
}
|
1589 |
}
|
1593 |
return true;
|
1594 |
}
|
1595 |
|
1596 |
+
/**
|
1597 |
+
* @param string $key
|
1598 |
+
* @param string $plugin
|
1599 |
+
*
|
1600 |
+
* @return array|string
|
1601 |
+
*/
|
1602 |
function apbct_rc__insert_auth_key($key, $plugin){
|
1603 |
|
|
|
|
|
1604 |
if($plugin === 'security-malware-firewall/security-malware-firewall.php'){
|
1605 |
|
1606 |
require_once (ABSPATH .'/wp-admin/includes/plugin.php');
|
1611 |
|
1612 |
if($key && preg_match('/^[a-z\d]{3,15}$/', $key)){
|
1613 |
|
1614 |
+
$result = API::method__notice_paid_till(
|
1615 |
$key,
|
1616 |
preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1), // Site URL
|
1617 |
'security'
|
1642 |
update_option('spbc_settings', $settings);
|
1643 |
|
1644 |
return 'OK';
|
1645 |
+
}else {
|
1646 |
+
return array( 'error' => 'KEY_IS_NOT_VALID' );
|
1647 |
+
}
|
1648 |
+
}else {
|
1649 |
+
return array( 'error' => $result );
|
1650 |
+
}
|
1651 |
+
}else {
|
1652 |
+
return array( 'error' => 'KEY_IS_NOT_CORRECT' );
|
1653 |
+
}
|
1654 |
+
}else {
|
1655 |
+
return array( 'error' => 'PLUGIN_IS_NOT_ACTIVE_OR_NOT_INSTALLED' );
|
1656 |
+
}
|
1657 |
+
}else {
|
1658 |
+
return array( 'error' => 'PLUGIN_SLUG_INCORRECT' );
|
1659 |
+
}
|
1660 |
}
|
1661 |
|
1662 |
/**
|
1667 |
*
|
1668 |
* @return bool
|
1669 |
*/
|
1670 |
+
function apbct_maintenance_mode__enable( $duration ) {
|
1671 |
+
apbct_maintenance_mode__disable();
|
1672 |
$content = "<?php\n\n"
|
1673 |
. '$upgrading = ' . (time() - ( 60 * 10 ) + $duration) . ';';
|
1674 |
|
1680 |
*
|
1681 |
* @return void
|
1682 |
*/
|
1683 |
+
function apbct_maintenance_mode__disable() {
|
1684 |
$maintenance_file = ABSPATH . '.maintenance';
|
1685 |
if ( file_exists( $maintenance_file ) ) {
|
1686 |
unlink( $maintenance_file );
|
1687 |
}
|
1688 |
}
|
1689 |
|
1690 |
+
/**
|
1691 |
+
* Getting brief data
|
1692 |
+
*
|
1693 |
+
* @param null|string $api_key
|
1694 |
+
*/
|
1695 |
function cleantalk_get_brief_data( $api_key = null ){
|
1696 |
|
1697 |
global $apbct;
|
1698 |
|
1699 |
$api_key = is_null( $api_key ) ? $apbct->api_key : $api_key;
|
1700 |
|
1701 |
+
$apbct->data['brief_data'] = API::method__get_antispam_report_breif( $api_key );
|
1702 |
|
1703 |
# expanding data about the country
|
1704 |
if(isset($apbct->data['brief_data']['top5_spam_ip']) && !empty($apbct->data['brief_data']['top5_spam_ip'])) {
|
1710 |
);
|
1711 |
|
1712 |
if(isset($ip)) {
|
1713 |
+
$country_data = API::method__ip_info($ip);
|
1714 |
$country_data_clear = current($country_data);
|
1715 |
|
1716 |
if(is_array($country_data_clear) && isset($country_data_clear['country_name']) && isset($country_data_clear['country_code'])) {
|
1729 |
|
1730 |
}
|
1731 |
|
1732 |
+
/**
|
1733 |
+
* Delete cookie for admin trial notice
|
1734 |
+
*/
|
1735 |
function apbct__hook__wp_logout__delete_trial_notice_cookie(){
|
1736 |
+
if(!headers_sent()) {
|
1737 |
+
Cookie::setNativeCookie( 'ct_trial_banner_closed', '', time() - 3600 );
|
1738 |
+
}
|
1739 |
}
|
1740 |
|
1741 |
+
/**
|
1742 |
+
* Store URLs
|
1743 |
+
*
|
1744 |
+
* @throws JsonException
|
1745 |
+
* @ToDo need to be refactored psalm notices about InvalidArrayOffset
|
1746 |
+
*/
|
1747 |
function apbct_store__urls(){
|
1748 |
|
1749 |
global $apbct;
|
1753 |
// URLs HISTORY
|
1754 |
// Get current url
|
1755 |
$current_url = Server::get( 'HTTP_HOST' ) . Server::get( 'REQUEST_URI' );
|
1756 |
+
$current_url = $current_url ? substr($current_url, 0,128) : 'UNKNOWN';
|
1757 |
+
$site_url = parse_url(get_option('siteurl'),PHP_URL_HOST);
|
1758 |
|
1759 |
// Get already stored URLs
|
1760 |
+
$urls = Cookie::get( 'apbct_urls', array(), 'array' );
|
1761 |
+
/** @psalm-suppress InvalidArrayOffset */
|
1762 |
$urls[$current_url][] = time();
|
1763 |
|
1764 |
// Rotating. Saving only latest 10
|
1765 |
+
/** @psalm-suppress InvalidArrayOffset */
|
1766 |
+
$urls[$current_url] = count($urls[$current_url]) > 5 ? array_slice($urls[$current_url], 1, 5) : $urls[$current_url];
|
1767 |
+
$urls = count($urls) > 5 ? array_slice($urls, 1, 5) : $urls;
|
1768 |
|
1769 |
// Saving
|
1770 |
+
Cookie::set('apbct_urls', json_encode( $urls ), time() + 86400 * 3, '/', $site_url, null, true, 'Lax');
|
1771 |
|
1772 |
// REFERER
|
1773 |
+
// Get current referer
|
1774 |
$new_site_referer = apbct_get_server_variable( 'HTTP_REFERER' );
|
1775 |
+
$new_site_referer = $new_site_referer ?: 'UNKNOWN';
|
1776 |
|
1777 |
// Get already stored referer
|
1778 |
+
$site_referer = Cookie::get('apbct_site_referer' );
|
1779 |
|
1780 |
// Save if empty
|
1781 |
+
if( $site_url && ( ! $site_referer || parse_url($new_site_referer, PHP_URL_HOST) !== apbct_get_server_variable( 'HTTP_HOST' ) ) ){
|
1782 |
+
Cookie::set('apbct_site_referer', $new_site_referer, time()+86400*3, '/', $site_url, null, true, 'Lax');
|
1783 |
}
|
1784 |
|
1785 |
$apbct->flags__url_stored = true;
|
1787 |
}
|
1788 |
}
|
1789 |
|
1790 |
+
/**
|
1791 |
* Set Cookies test for cookie test
|
1792 |
+
* Sets cookies with params timestamp && landing_timestamp && previous_referer
|
1793 |
* Sets test cookie with all other cookies
|
1794 |
+
* @return bool
|
1795 |
*/
|
1796 |
function apbct_cookie(){
|
1797 |
|
1801 |
empty($apbct->settings['data__set_cookies']) || // Do not set cookies if option is disabled (for Varnish cache).
|
1802 |
!empty($apbct->flags__cookies_setuped) || // Cookies already set
|
1803 |
!empty($apbct->headers_sent) // Headers sent
|
1804 |
+
) {
|
1805 |
return false;
|
1806 |
+
}
|
1807 |
|
1808 |
// Prevent headers sent error
|
1809 |
if(headers_sent($file, $line)){
|
1821 |
);
|
1822 |
|
1823 |
// We need to skip the domain attribute for prevent including the dot to the cookie's domain on the client.
|
1824 |
+
$domain = '';
|
1825 |
|
1826 |
+
// Submit time
|
1827 |
+
if(empty($_POST['ct_multipage_form'])){ // Do not start/reset page timer if it is multi page form (Gravity forms))
|
1828 |
$apbct_timestamp = time();
|
1829 |
+
Cookie::set('apbct_timestamp', (string) $apbct_timestamp, 0, '/', $domain, null, true );
|
1830 |
$cookie_test_value['cookies_names'][] = 'apbct_timestamp';
|
1831 |
$cookie_test_value['check_value'] .= $apbct_timestamp;
|
1832 |
}
|
1833 |
|
1834 |
+
// Previous referer
|
1835 |
if( Server::get( 'HTTP_REFERER' ) ){
|
1836 |
+
Cookie::set('apbct_prev_referer', Server::get( 'HTTP_REFERER' ), 0, '/', $domain, null, true );
|
1837 |
$cookie_test_value['cookies_names'][] = 'apbct_prev_referer';
|
1838 |
$cookie_test_value['check_value'] .= apbct_get_server_variable( 'HTTP_REFERER' );
|
1839 |
}
|
1840 |
|
1841 |
+
// Landing time
|
1842 |
+
$site_landing_timestamp = Cookie::get( 'apbct_site_landing_ts' );
|
1843 |
if(!$site_landing_timestamp){
|
1844 |
$site_landing_timestamp = time();
|
1845 |
+
Cookie::set('apbct_site_landing_ts', (string) $site_landing_timestamp, 0, '/', $domain, null, true );
|
1846 |
}
|
1847 |
$cookie_test_value['cookies_names'][] = 'apbct_site_landing_ts';
|
1848 |
$cookie_test_value['check_value'] .= $site_landing_timestamp;
|
1849 |
|
1850 |
+
// Page hits
|
1851 |
// Get
|
1852 |
+
$page_hits = Cookie::get( 'apbct_page_hits' );
|
1853 |
// Set / Increase
|
1854 |
+
$page_hits = (int) $page_hits ? (int) $page_hits + 1 : 1;
|
1855 |
|
1856 |
+
Cookie::set('apbct_page_hits', (string) $page_hits, 0, '/', $domain, null, true );
|
1857 |
|
1858 |
$cookie_test_value['cookies_names'][] = 'apbct_page_hits';
|
1859 |
$cookie_test_value['check_value'] .= $page_hits;
|
1860 |
|
1861 |
// Cookies test
|
1862 |
$cookie_test_value['check_value'] = md5($cookie_test_value['check_value']);
|
1863 |
+
if( $apbct->settings['data__set_cookies'] == 1 ) {
|
1864 |
+
Cookie::set( 'apbct_cookies_test', urlencode( json_encode( $cookie_test_value ) ), 0, '/', $domain, null, true );
|
1865 |
+
}
|
1866 |
|
1867 |
$apbct->flags__cookies_setuped = true;
|
1868 |
+
|
1869 |
+
return $apbct->flags__cookies_setuped;
|
1870 |
|
1871 |
}
|
1872 |
|
1873 |
/**
|
1874 |
+
* Cookies test for sender
|
1875 |
* Also checks for valid timestamp in $_COOKIE['apbct_timestamp'] and other apbct_ COOKIES
|
1876 |
+
* @return null|int null|0|1
|
1877 |
+
* @throws JsonException
|
1878 |
*/
|
1879 |
function apbct_cookies_test()
|
1880 |
{
|
1886 |
|
1887 |
if(isset($_COOKIE['apbct_cookies_test'])){
|
1888 |
|
1889 |
+
$cookie_test = json_decode( urldecode( $_COOKIE['apbct_cookies_test'] ), true );
|
1890 |
|
1891 |
+
if(!is_array($cookie_test)) {
|
1892 |
return 0;
|
1893 |
+
}
|
1894 |
|
1895 |
+
$check_string = $apbct->api_key;
|
1896 |
foreach($cookie_test['cookies_names'] as $cookie_name){
|
1897 |
+
$check_string .= isset($_COOKIE[$cookie_name]) ? $_COOKIE[$cookie_name] : '';
|
1898 |
+
}
|
1899 |
|
1900 |
+
if($cookie_test['check_value'] == md5($check_string)){
|
1901 |
return 1;
|
|
|
|
|
1902 |
}
|
1903 |
+
|
1904 |
+
return 0;
|
1905 |
}
|
1906 |
+
|
1907 |
+
return null;
|
1908 |
}
|
1909 |
|
1910 |
/**
|
1911 |
* Gets submit time
|
1912 |
* Uses Cookies with check via apbct_cookies_test()
|
1913 |
+
* @return null|int
|
1914 |
+
* @throws JsonException
|
1915 |
*/
|
1916 |
function apbct_get_submit_time()
|
1917 |
{
|
1918 |
+
$apbct_timestamp = (int) Cookie::get( 'apbct_timestamp' );
|
1919 |
return apbct_cookies_test() === 1 && $apbct_timestamp !== 0 ? time() - $apbct_timestamp : null;
|
1920 |
}
|
1921 |
|
1927 |
|
1928 |
global $apbct;
|
1929 |
|
1930 |
+
$api_key = $api_key ?: $apbct->api_key;
|
1931 |
+
$result = API::method__notice_paid_till(
|
1932 |
$api_key,
|
1933 |
preg_replace('/http[s]?:\/\//', '', get_option('siteurl'), 1),
|
1934 |
! is_main_site() && $apbct->white_label ? 'anti-spam-hosting' : 'antispam'
|
1986 |
$to = "welcome@cleantalk.org" ;
|
1987 |
$subject = "Connection report for " . apbct_get_server_variable( 'HTTP_HOST' );
|
1988 |
$message = '
|
1989 |
+
<html lang="en">
|
1990 |
<head>
|
1991 |
<title></title>
|
1992 |
</head>
|
2013 |
}
|
2014 |
$message.='</table></body></html>';
|
2015 |
|
2016 |
+
$headers = "Content-type: text/html; charset=windows-1251 \r\n";
|
2017 |
$headers .= 'From: '.get_option('admin_email');
|
2018 |
mail($to, $subject, $message, $headers);
|
2019 |
}
|
2023 |
$apbct->saveData();
|
2024 |
}
|
2025 |
|
2026 |
+
/**
|
2027 |
+
* Write $message to the plugin's debug option
|
2028 |
+
*
|
2029 |
+
* @param string|array|object $message
|
2030 |
+
* @param null|string $func
|
2031 |
+
* @param array $params
|
2032 |
+
*
|
2033 |
+
* @return void
|
2034 |
+
*/
|
2035 |
function apbct_log($message = 'empty', $func = null, $params = array())
|
2036 |
{
|
2037 |
global $apbct;
|
2038 |
|
2039 |
$debug = get_option( APBCT_DEBUG );
|
2040 |
|
2041 |
+
$function = $func ?: '';
|
2042 |
+
$cron = in_array('cron', $params);
|
2043 |
+
$data = in_array('data', $params);
|
2044 |
+
$settings = in_array('settings', $params);
|
2045 |
|
2046 |
+
if( is_array($message) || is_object($message) ) {
|
2047 |
+
$message = print_r( $message, true );
|
2048 |
+
}
|
2049 |
|
2050 |
+
if($message) {
|
2051 |
+
$debug[ date( "H:i:s", (int) microtime() ) . "_ACTION_" . current_filter() . "_FUNCTION_" . $function ] = $message;
|
2052 |
+
}
|
2053 |
+
if($cron) {
|
2054 |
+
$debug[ date( "H:i:s", (int) microtime() ) . "_ACTION_" . current_filter() . "_FUNCTION_" . $function . '_cron' ] = $apbct->cron;
|
2055 |
+
}
|
2056 |
+
if($data) {
|
2057 |
+
$debug[ date( "H:i:s", (int) microtime() ) . "_ACTION_" . current_filter() . "_FUNCTION_" . $function . '_data' ] = $apbct->data;
|
2058 |
+
}
|
2059 |
+
if($settings) {
|
2060 |
+
$debug[ date( "H:i:s", (int) microtime() ) . "_ACTION_" . current_filter() . "_FUNCTION_" . $function . '_settings' ] = $apbct->settings;
|
2061 |
+
}
|
2062 |
|
2063 |
update_option(APBCT_DEBUG, $debug);
|
2064 |
}
|
2065 |
|
2066 |
+
function apbct_sfw__delete_tables( $blog_id, $_drop ) {
|
2067 |
|
2068 |
global $wpdb;
|
2069 |
|
2085 |
*
|
2086 |
* @return boolean
|
2087 |
*/
|
2088 |
+
function apbct_is_user_enable( $user = null ) {
|
2089 |
|
2090 |
global $current_user;
|
2091 |
|
2092 |
+
$user = $user !== null ? $user : $current_user;
|
2093 |
|
2094 |
return apbct_is_user_role_in(array('administrator', 'editor', 'author'), $user)
|
2095 |
? false
|
2106 |
*/
|
2107 |
function apbct_is_user_role_in( $roles, $user = false ){
|
2108 |
|
2109 |
+
if( is_numeric($user) && function_exists('get_userdata')) {
|
2110 |
+
$user = get_userdata( (int) $user );
|
2111 |
+
}
|
2112 |
+
if( is_string($user) && function_exists('get_user_by')) {
|
2113 |
+
$user = get_user_by( 'login', $user );
|
2114 |
+
}
|
2115 |
+
|
2116 |
+
if( ! $user && function_exists('wp_get_current_user')) {
|
2117 |
+
$user = wp_get_current_user();
|
2118 |
+
}
|
2119 |
+
|
2120 |
+
if( ! $user ) {
|
2121 |
+
$user = apbct_wp_get_current_user();
|
2122 |
+
}
|
2123 |
|
2124 |
+
if( empty($user->ID) ) {
|
2125 |
return false;
|
2126 |
+
}
|
2127 |
|
2128 |
foreach( (array) $roles as $role ){
|
2129 |
+
if( isset($user->caps[ strtolower($role) ]) || in_array(strtolower($role), $user->roles) ) {
|
2130 |
return true;
|
2131 |
+
}
|
2132 |
}
|
2133 |
|
2134 |
return false;
|
2135 |
}
|
2136 |
|
2137 |
/**
|
2138 |
+
* Update and rotate statistics with requests execution time
|
2139 |
*
|
2140 |
* @param $exec_time
|
2141 |
*/
|
2144 |
global $apbct;
|
2145 |
|
2146 |
// Delete old stats
|
2147 |
+
if(min(array_keys($apbct->stats['requests'])) < time() - (86400 * 7)) {
|
2148 |
+
unset( $apbct->stats['requests'][ min( array_keys( $apbct->stats['requests'] ) ) ] );
|
2149 |
+
}
|
2150 |
|
2151 |
// Create new if newest older than 1 day
|
2152 |
+
if(empty($apbct->stats['requests']) || max(array_keys($apbct->stats['requests'])) < time() - (86400 * 1)) {
|
2153 |
+
$apbct->stats['requests'][ time() ] = array( 'amount' => 0, 'average_time' => 0 );
|
2154 |
+
}
|
2155 |
|
2156 |
// Update all existing stats
|
2157 |
foreach($apbct->stats['requests'] as &$weak_stat){
|
2158 |
$weak_stat['average_time'] = ($weak_stat['average_time'] * $weak_stat['amount'] + $exec_time) / ++$weak_stat['amount'];
|
2159 |
+
}unset($weak_stat);
|
2160 |
|
2161 |
$apbct->save('stats');
|
2162 |
}
|
2164 |
/**
|
2165 |
* Runs update actions for new version.
|
2166 |
*
|
2167 |
+
* @global State $apbct
|
2168 |
*/
|
2169 |
function apbct_update_actions(){
|
2170 |
|
2171 |
global $apbct;
|
2172 |
|
2173 |
// Update logic
|
2174 |
+
if( $apbct->plugin_version !== APBCT_VERSION ){
|
2175 |
|
2176 |
// Main blog
|
2177 |
if(is_main_site()){
|
2180 |
|
2181 |
$result = apbct_run_update_actions($apbct->plugin_version, APBCT_VERSION);
|
2182 |
|
2183 |
+
//If update is successful
|
2184 |
+
if($result === true) {
|
2185 |
+
apbct_update__set_version__from_plugin( 'from_plugin' );
|
2186 |
+
}
|
2187 |
|
2188 |
ct_send_feedback('0:' . APBCT_AGENT ); // Send feedback to let cloud know about updated version.
|
2189 |
|
2201 |
* @param string $ver
|
2202 |
*
|
2203 |
* @return bool
|
2204 |
+
* @global State $apbct
|
2205 |
*
|
2206 |
*/
|
2207 |
function apbct_update__set_version__from_plugin($ver){
|
2215 |
break;
|
2216 |
default:
|
2217 |
return false;
|
|
|
2218 |
}
|
2219 |
$apbct->saveData();
|
2220 |
return true;
|
@@ -828,10 +828,10 @@ function apbct_comment__unmark_red($message) {
|
|
828 |
/**
|
829 |
* Ajax action feedback form comments page.
|
830 |
*
|
831 |
-
* @param null $comment_id
|
832 |
-
* @param null $comment_status
|
833 |
* @param bool $change_status
|
834 |
-
* @param null $direct_call
|
835 |
*/
|
836 |
function apbct_comment__send_feedback($comment_id = null, $comment_status = null, $change_status = false, $direct_call = null){
|
837 |
|
828 |
/**
|
829 |
* Ajax action feedback form comments page.
|
830 |
*
|
831 |
+
* @param null|int $comment_id
|
832 |
+
* @param null|string $comment_status
|
833 |
* @param bool $change_status
|
834 |
+
* @param null|bool $direct_call
|
835 |
*/
|
836 |
function apbct_comment__send_feedback($comment_id = null, $comment_status = null, $change_status = false, $direct_call = null){
|
837 |
|
@@ -1,5 +1,10 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
|
|
|
|
3 |
// If this file is called directly, abort.
|
4 |
if ( ! defined( 'DOING_AJAX' ) ) {
|
5 |
http_response_code( 403 );
|
@@ -13,7 +18,6 @@ if( !defined( 'APBCT_VERSION' ) ) {
|
|
13 |
define( 'APBCT_VERSION', $plugin_info['Version'] );
|
14 |
}
|
15 |
|
16 |
-
global $apbct;
|
17 |
$apbct = new \Cleantalk\ApbctWP\State('cleantalk', array('settings', 'data'));
|
18 |
$apbct->white_label = $apbct->network_settings['multisite__white_label'];
|
19 |
$apbct->allow_custom_key = $apbct->network_settings['multisite__allow_custom_key'];
|
1 |
<?php
|
2 |
|
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 );
|
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__allow_custom_key'];
|
@@ -324,6 +324,7 @@ function ct_ajax_hook( $message_obj = null )
|
|
324 |
'wl_out_of_stock_notify', // Sumo Waitlist
|
325 |
'rac_preadd_guest', //Rac internal request
|
326 |
'apbct_email_check_before_post', //Interal request
|
|
|
327 |
/* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
|
328 |
);
|
329 |
|
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 |
|
@@ -1,21 +1,21 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Autoloader for \Cleantalk\* classes
|
5 |
-
*
|
6 |
-
* @param string $class
|
7 |
-
*
|
8 |
-
* @return void
|
9 |
-
*/
|
10 |
-
function apbct_autoloader( $class ){
|
11 |
-
// Register class auto loader
|
12 |
-
// Custom modules
|
13 |
-
if( strpos( $class, 'cleantalk-spam-protect') !== false && ! class_exists( '\\' . $class )) {
|
14 |
-
$class_file = CLEANTALK_PLUGIN_DIR . 'lib' . DIRECTORY_SEPARATOR . $class . '.php';
|
15 |
-
if( file_exists( $class_file ) ){
|
16 |
-
require_once( $class_file );
|
17 |
-
}
|
18 |
-
}
|
19 |
-
}
|
20 |
-
|
21 |
-
spl_autoload_register( 'apbct_autoloader' );
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Autoloader for \Cleantalk\* classes
|
5 |
+
*
|
6 |
+
* @param string $class
|
7 |
+
*
|
8 |
+
* @return void
|
9 |
+
*/
|
10 |
+
function apbct_autoloader( $class ){
|
11 |
+
// Register class auto loader
|
12 |
+
// Custom modules
|
13 |
+
if( strpos( $class, 'cleantalk-spam-protect') !== false && ! class_exists( '\\' . $class )) {
|
14 |
+
$class_file = CLEANTALK_PLUGIN_DIR . 'lib' . DIRECTORY_SEPARATOR . $class . '.php';
|
15 |
+
if( file_exists( $class_file ) ){
|
16 |
+
require_once( $class_file );
|
17 |
+
}
|
18 |
+
}
|
19 |
+
}
|
20 |
+
|
21 |
+
spl_autoload_register( 'apbct_autoloader' );
|
@@ -4,6 +4,7 @@ use Cleantalk\Antispam\Cleantalk;
|
|
4 |
use Cleantalk\Antispam\CleantalkRequest;
|
5 |
use Cleantalk\Antispam\CleantalkResponse;
|
6 |
use Cleantalk\ApbctWP\API;
|
|
|
7 |
use Cleantalk\ApbctWP\GetFieldsAny;
|
8 |
use Cleantalk\ApbctWP\Helper;
|
9 |
use Cleantalk\ApbctWP\Variables\Cookie;
|
@@ -63,9 +64,6 @@ $ct_admin_notoice_period = 21600;
|
|
63 |
// It uses for BuddyPress registrations to avoid double checks
|
64 |
$ct_negative_comment = null;
|
65 |
|
66 |
-
// Set globals to NULL to avoid massive DB requests. Globals will be set when needed only and by accessors only.
|
67 |
-
$ct_server = NULL;
|
68 |
-
$admin_email = NULL;
|
69 |
|
70 |
add_action( 'wp_login', 'apbct_add_admin_ip_to_swf_whitelist', 10, 2 );
|
71 |
|
@@ -74,7 +72,7 @@ add_action( 'wp_login', 'apbct_add_admin_ip_to_swf_whitelist', 10, 2 );
|
|
74 |
*/
|
75 |
function apbct_plugin_loaded() {
|
76 |
$dir=plugin_basename( dirname( __FILE__ ) ) . '/../i18n';
|
77 |
-
|
78 |
}
|
79 |
|
80 |
/**
|
@@ -91,7 +89,7 @@ function apbct_plugin_loaded() {
|
|
91 |
*/
|
92 |
function apbct_base_call($params = array(), $reg_flag = false){
|
93 |
|
94 |
-
global $
|
95 |
|
96 |
/* Exclusions */
|
97 |
if( $cleantalk_executed ){
|
@@ -110,7 +108,9 @@ function apbct_base_call($params = array(), $reg_flag = false){
|
|
110 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
111 |
return array( 'ct_result' => new CleantalkResponse() );
|
112 |
}
|
113 |
-
|
|
|
|
|
114 |
// Fields exclusions
|
115 |
if( ! empty( $params['message'] ) && is_array( $params['message'] ) ){
|
116 |
$params['message'] = apbct_array( $params['message'] )
|
@@ -151,12 +151,6 @@ function apbct_base_call($params = array(), $reg_flag = false){
|
|
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 |
-
$honeypot_field = null;
|
155 |
-
|
156 |
-
if(isset($params['honeypot_field'])) {
|
157 |
-
$honeypot_field = $params['honeypot_field'];
|
158 |
-
}
|
159 |
-
|
160 |
$default_params = array(
|
161 |
|
162 |
// IPs
|
@@ -172,10 +166,16 @@ function apbct_base_call($params = array(), $reg_flag = false){
|
|
172 |
|
173 |
'agent' => APBCT_AGENT,
|
174 |
'sender_info' => $sender_info,
|
175 |
-
'submit_time' => apbct_get_submit_time()
|
176 |
-
'honeypot_field' => $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;
|
@@ -193,7 +193,7 @@ function apbct_base_call($params = array(), $reg_flag = false){
|
|
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('/
|
197 |
$ct->server_ttl = $config['ct_server_ttl'];
|
198 |
$ct->server_changed = $config['ct_server_changed'];
|
199 |
|
@@ -238,6 +238,8 @@ function apbct_base_call($params = array(), $reg_flag = false){
|
|
238 |
'ct_server_changed' => time(),
|
239 |
)
|
240 |
);
|
|
|
|
|
241 |
}
|
242 |
|
243 |
$ct_result = ct_change_plugin_resonse($ct_result, $ct_request->js_on);
|
@@ -261,6 +263,21 @@ function apbct_base_call($params = array(), $reg_flag = false){
|
|
261 |
|
262 |
}
|
263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
function apbct_exclusions_check($func = null){
|
265 |
|
266 |
global $apbct;
|
@@ -290,7 +307,6 @@ function apbct_exclusions_check($func = null){
|
|
290 |
break;
|
291 |
default:
|
292 |
return false;
|
293 |
-
break;
|
294 |
}
|
295 |
|
296 |
return false;
|
@@ -328,7 +344,7 @@ function apbct_exclusions_check__url() {
|
|
328 |
// Fix for AJAX and WP REST API forms
|
329 |
$haystack = ( apbct_get_server_variable( 'REQUEST_URI' ) === '/wp-admin/admin-ajax.php' || stripos( apbct_get_server_variable( 'REQUEST_URI' ), '/wp-json/' ) === 0 )
|
330 |
&& apbct_get_server_variable( 'HTTP_REFERER' )
|
331 |
-
? str_ireplace( array( 'http://', 'https://', Server::get('HTTP_HOST')
|
332 |
: apbct_get_server_variable( 'REQUEST_URI' );
|
333 |
|
334 |
foreach ( $exclusions as $exclusion ) {
|
@@ -341,6 +357,8 @@ function apbct_exclusions_check__url() {
|
|
341 |
}
|
342 |
return false;
|
343 |
}
|
|
|
|
|
344 |
}
|
345 |
/**
|
346 |
* @deprecated 5.128 Using IP white-lists instead
|
@@ -376,9 +394,7 @@ function apbct_exclusions_check__ip(){
|
|
376 |
* @return array
|
377 |
*/
|
378 |
function apbct_get_sender_info() {
|
379 |
-
|
380 |
-
global $apbct;
|
381 |
-
|
382 |
// Validate cookie from the backend
|
383 |
$cookie_is_ok = apbct_cookies_test();
|
384 |
|
@@ -400,6 +416,8 @@ function apbct_get_sender_info() {
|
|
400 |
// Visible fields processing
|
401 |
$visible_fields = apbct_visible_fields__process( Cookie::get( 'apbct_visible_fields' , array(), 'array' ) );
|
402 |
|
|
|
|
|
403 |
return array(
|
404 |
'plugin_request_id' => $apbct->plugin_request_id,
|
405 |
'wpms' => is_multisite() ? 'yes' : 'no',
|
@@ -421,8 +439,8 @@ function apbct_get_sender_info() {
|
|
421 |
'site_landing_ts' => Cookie::get( 'apbct_site_landing_ts' ) && $cookie_is_ok ? Cookie::get( 'apbct_site_landing_ts' ) : null,
|
422 |
'page_hits' => Cookie::get( 'apbct_page_hits' ) ?: null,
|
423 |
// JS cookies
|
424 |
-
'js_info' => Cookie::get( 'ct_user_info'
|
425 |
-
'mouse_cursor_positions' => Cookie::get( 'ct_pointer_data'
|
426 |
'js_timezone' => Cookie::get( 'ct_timezone' ) ?: null,
|
427 |
'key_press_timestamp' => Cookie::get( 'ct_fkp_timestamp' ) ?: null,
|
428 |
'page_set_timestamp' => Cookie::get( 'ct_ps_timestamp' ) ?: null,
|
@@ -477,7 +495,7 @@ function apbct_visible_fields__process( $visible_fields ) {
|
|
477 |
if( count( array_intersect( array_keys($fields_to_check), $fields ) ) > 0 ) {
|
478 |
// WP Forms visible fields formatting
|
479 |
if(strpos($visible_fields, 'wpforms') !== false){
|
480 |
-
$
|
481 |
array('/\[/', '/\]/'),
|
482 |
'',
|
483 |
str_replace(
|
@@ -622,36 +640,23 @@ function apbct_is_cache_plugins_exists(){
|
|
622 |
* @return string Admin e-mail
|
623 |
*/
|
624 |
function ct_get_admin_email() {
|
625 |
-
|
626 |
-
if(!isset($admin_email))
|
627 |
-
{
|
628 |
-
$admin_email = get_option('admin_email');
|
629 |
-
}
|
630 |
-
return $admin_email;
|
631 |
}
|
632 |
|
633 |
/**
|
634 |
* Inner function - Current Cleantalk working server info
|
635 |
-
* @return
|
636 |
*/
|
637 |
-
function ct_get_server(
|
638 |
-
|
639 |
-
if
|
640 |
-
|
641 |
-
return $ct_server;
|
642 |
-
|
643 |
-
}else{
|
644 |
-
|
645 |
-
$ct_server = get_option('cleantalk_server');
|
646 |
-
if (!is_array($ct_server)){
|
647 |
-
$ct_server = array(
|
648 |
'ct_work_url' => NULL,
|
649 |
'ct_server_ttl' => NULL,
|
650 |
'ct_server_changed' => NULL
|
651 |
);
|
652 |
-
}
|
653 |
-
return $ct_server;
|
654 |
}
|
|
|
655 |
}
|
656 |
|
657 |
/**
|
@@ -688,6 +693,8 @@ function ct_feedback($hash, $allow) {
|
|
688 |
$apbct->data['feedback_request'] .= $ct_feedback;
|
689 |
|
690 |
$apbct->saveData();
|
|
|
|
|
691 |
}
|
692 |
|
693 |
/**
|
@@ -724,7 +731,7 @@ function ct_send_feedback($feedback_request = null) {
|
|
724 |
$ct->server_ttl = $config['ct_server_ttl'];
|
725 |
$ct->server_changed = $config['ct_server_changed'];
|
726 |
|
727 |
-
$ct->sendFeedback($ct_request);
|
728 |
|
729 |
if ($ct->server_change) {
|
730 |
update_option(
|
@@ -735,9 +742,12 @@ function ct_send_feedback($feedback_request = null) {
|
|
735 |
'ct_server_changed' => time(),
|
736 |
)
|
737 |
);
|
|
|
|
|
738 |
}
|
739 |
-
|
740 |
-
|
|
|
741 |
}
|
742 |
|
743 |
return false;
|
@@ -756,7 +766,7 @@ function ct_delete_spam_comments() {
|
|
756 |
$last_comments = get_comments(array('status' => 'spam', 'number' => 1000, 'order' => 'ASC'));
|
757 |
foreach ($last_comments as $c) {
|
758 |
$comment_date_gmt = strtotime($c->comment_date_gmt);
|
759 |
-
if ($comment_date_gmt
|
760 |
if (time() - $comment_date_gmt > 86400 * $apbct->data['spam_store_days']) {
|
761 |
// Force deletion old spam comments
|
762 |
wp_delete_comment($c->comment_ID, true);
|
@@ -773,7 +783,7 @@ function ct_delete_spam_comments() {
|
|
773 |
*
|
774 |
* @param $arr
|
775 |
* @param array $message
|
776 |
-
* @param null $email
|
777 |
* @param array $nickname
|
778 |
* @param null $subject
|
779 |
* @param bool $contact
|
@@ -782,7 +792,7 @@ function ct_delete_spam_comments() {
|
|
782 |
* @return array
|
783 |
* @deprecated Use ct_gfa()
|
784 |
*/
|
785 |
-
function ct_get_fields_any($arr, $
|
786 |
|
787 |
if ( is_array( $nickname ) )
|
788 |
{
|
@@ -844,7 +854,7 @@ function ct_get_fields_any_postdata($arr, $message=array()){
|
|
844 |
* @return bool
|
845 |
*/
|
846 |
function apbct_is_regexp($regexp){
|
847 |
-
return @preg_match('/' . $regexp . '/',
|
848 |
}
|
849 |
|
850 |
function cleantalk_debug($key,$value)
|
@@ -890,7 +900,7 @@ function ct_change_plugin_resonse($ct_result = null, $checkjs = null) {
|
|
890 |
|
891 |
/**
|
892 |
* Does ey has correct symbols? Checks against regexp ^[a-z\d]{3,15}$
|
893 |
-
* @param api_key
|
894 |
* @return bool
|
895 |
*/
|
896 |
function apbct_api_key__is_correct($api_key = null)
|
@@ -900,7 +910,7 @@ function apbct_api_key__is_correct($api_key = null)
|
|
900 |
return $api_key && preg_match('/^[a-z\d]{3,15}$/', $api_key) ? true : false;
|
901 |
}
|
902 |
|
903 |
-
function apbct_add_async_attribute($tag, $handle
|
904 |
|
905 |
global $apbct;
|
906 |
|
@@ -923,7 +933,7 @@ function apbct_add_async_attribute($tag, $handle, $src) {
|
|
923 |
return $tag;
|
924 |
}
|
925 |
|
926 |
-
function apbct_add_admin_ip_to_swf_whitelist( $
|
927 |
|
928 |
global $apbct;
|
929 |
|
@@ -945,7 +955,7 @@ function apbct_add_admin_ip_to_swf_whitelist( $user_login, $user ) {
|
|
945 |
md5( $ip . $apbct->api_key ),
|
946 |
time() + 86400 * 30,
|
947 |
'/',
|
948 |
-
|
949 |
null,
|
950 |
true,
|
951 |
'Lax'
|
@@ -972,11 +982,11 @@ function apbct_private_list_add( $ip ){
|
|
972 |
add_filter( 'comment_form_default_fields', 'apbct__change_type_website_field' );
|
973 |
function apbct__change_type_website_field( $fields ){
|
974 |
|
975 |
-
global $apbct
|
976 |
|
977 |
if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
|
978 |
if(isset($fields['url']) && $fields['url']) {
|
979 |
-
$fields['url'] = '<input id="honeypot-field-url" name="url" type="text" value="
|
980 |
}
|
981 |
}
|
982 |
|
4 |
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;
|
64 |
// It uses for BuddyPress registrations to avoid double checks
|
65 |
$ct_negative_comment = null;
|
66 |
|
|
|
|
|
|
|
67 |
|
68 |
add_action( 'wp_login', 'apbct_add_admin_ip_to_swf_whitelist', 10, 2 );
|
69 |
|
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 |
/**
|
89 |
*/
|
90 |
function apbct_base_call($params = array(), $reg_flag = false){
|
91 |
|
92 |
+
global $cleantalk_executed;
|
93 |
|
94 |
/* Exclusions */
|
95 |
if( $cleantalk_executed ){
|
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'] )
|
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
|
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;
|
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 |
|
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);
|
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;
|
307 |
break;
|
308 |
default:
|
309 |
return false;
|
|
|
310 |
}
|
311 |
|
312 |
return false;
|
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 ) {
|
357 |
}
|
358 |
return false;
|
359 |
}
|
360 |
+
|
361 |
+
return false;
|
362 |
}
|
363 |
/**
|
364 |
* @deprecated 5.128 Using IP white-lists instead
|
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 |
|
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',
|
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,
|
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 |
'',
|
501 |
str_replace(
|
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 |
/**
|
693 |
$apbct->data['feedback_request'] .= $ct_feedback;
|
694 |
|
695 |
$apbct->saveData();
|
696 |
+
|
697 |
+
return $ct_feedback;
|
698 |
}
|
699 |
|
700 |
/**
|
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(
|
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;
|
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);
|
783 |
*
|
784 |
* @param $arr
|
785 |
* @param array $message
|
786 |
+
* @param null|string $email
|
787 |
* @param array $nickname
|
788 |
* @param null $subject
|
789 |
* @param bool $contact
|
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 |
{
|
854 |
* @return bool
|
855 |
*/
|
856 |
function apbct_is_regexp($regexp){
|
857 |
+
return @preg_match('/' . $regexp . '/', '') !== false;
|
858 |
}
|
859 |
|
860 |
function cleantalk_debug($key,$value)
|
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)
|
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 |
|
933 |
return $tag;
|
934 |
}
|
935 |
|
936 |
+
function apbct_add_admin_ip_to_swf_whitelist( $user ) {
|
937 |
|
938 |
global $apbct;
|
939 |
|
955 |
md5( $ip . $apbct->api_key ),
|
956 |
time() + 86400 * 30,
|
957 |
'/',
|
958 |
+
'',
|
959 |
null,
|
960 |
true,
|
961 |
'Lax'
|
982 |
add_filter( 'comment_form_default_fields', 'apbct__change_type_website_field' );
|
983 |
function apbct__change_type_website_field( $fields ){
|
984 |
|
985 |
+
global $apbct;
|
986 |
|
987 |
if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
|
988 |
if(isset($fields['url']) && $fields['url']) {
|
989 |
+
$fields['url'] = '<input id="honeypot-field-url" autocomplete="off" name="url" type="text" value="" size="30" maxlength="200" />';
|
990 |
}
|
991 |
}
|
992 |
|
@@ -15,6 +15,7 @@ function ct_add_find_spam_pages(){
|
|
15 |
|
16 |
// Remove some pages from main menu
|
17 |
remove_submenu_page( 'users.php', 'ct_check_users_logs' );
|
|
|
18 |
remove_submenu_page( 'edit-comments.php', 'ct_check_spam_logs' );
|
19 |
|
20 |
// Set screen option for every pages
|
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
|
@@ -530,7 +530,16 @@ function apbct_is_skip_request( $ajax = false ) {
|
|
530 |
Post::get( 'action' ) === 'active_step' )
|
531 |
{
|
532 |
return 'fluentform_skip';
|
533 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
534 |
} else {
|
535 |
|
536 |
/*****************************************/
|
@@ -567,8 +576,8 @@ function apbct_is_skip_request( $ajax = false ) {
|
|
567 |
return 'mylisting_theme_service_requests_skip';
|
568 |
}
|
569 |
// HappyForms skip every requests. HappyForms have the direct integration
|
570 |
-
if( apbct_is_plugin_active( 'happyforms-upgrade/happyforms-upgrade.php' ) ||
|
571 |
-
apbct_is_plugin_active( 'happyforms/happyforms.php' ) &&
|
572 |
( Post::get('happyforms_message_nonce') !== '' ) )
|
573 |
{
|
574 |
return 'happyform_skipped';
|
@@ -589,7 +598,7 @@ function apbct_is_skip_request( $ajax = false ) {
|
|
589 |
//Skip wforms because of direct integration
|
590 |
if ( apbct_is_plugin_active( 'wpforms/wpforms.php' ) && isset( $_POST['wpforms'] ) ) {
|
591 |
return 'wp_forms';
|
592 |
-
}
|
593 |
}
|
594 |
|
595 |
return false;
|
530 |
Post::get( 'action' ) === 'active_step' )
|
531 |
{
|
532 |
return 'fluentform_skip';
|
533 |
+
}
|
534 |
+
|
535 |
+
// W2DC - https://codecanyon.net/item/web-20-directory-plugin-for-wordpress/6463373
|
536 |
+
if( apbct_is_plugin_active( 'w2dc/w2dc.php' ) &&
|
537 |
+
isset( $_POST['action'] ) &&
|
538 |
+
$_POST['action'] === 'vp_w2dc_ajax_vpt_option_save' &&
|
539 |
+
is_admin() )
|
540 |
+
{
|
541 |
+
return 'w2dc_skipped';
|
542 |
+
}
|
543 |
} else {
|
544 |
|
545 |
/*****************************************/
|
576 |
return 'mylisting_theme_service_requests_skip';
|
577 |
}
|
578 |
// HappyForms skip every requests. HappyForms have the direct integration
|
579 |
+
if( ( apbct_is_plugin_active( 'happyforms-upgrade/happyforms-upgrade.php' ) ||
|
580 |
+
apbct_is_plugin_active( 'happyforms/happyforms.php' ) ) &&
|
581 |
( Post::get('happyforms_message_nonce') !== '' ) )
|
582 |
{
|
583 |
return 'happyform_skipped';
|
598 |
//Skip wforms because of direct integration
|
599 |
if ( apbct_is_plugin_active( 'wpforms/wpforms.php' ) && isset( $_POST['wpforms'] ) ) {
|
600 |
return 'wp_forms';
|
601 |
+
}
|
602 |
}
|
603 |
|
604 |
return false;
|
@@ -1,6 +1,9 @@
|
|
1 |
<?php
|
2 |
|
3 |
use Cleantalk\ApbctWP\Helper;
|
|
|
|
|
|
|
4 |
use Cleantalk\Variables\Server;
|
5 |
|
6 |
// MailChimp Premium for Wordpress
|
@@ -14,22 +17,29 @@ function ct_add_mc4wp_error_message($messages){
|
|
14 |
}
|
15 |
add_filter( 'mc4wp_form_messages', 'ct_add_mc4wp_error_message' );
|
16 |
|
17 |
-
|
18 |
-
* Function to set validate
|
19 |
-
* Input -
|
20 |
* Returns - String. Validate function
|
21 |
*/
|
22 |
-
function ct_ccf($
|
23 |
return 'ct_validate_ccf_submission';
|
24 |
}
|
25 |
|
26 |
-
|
27 |
-
|
|
|
28 |
* Input - void. Global $ct_global_temporary_data
|
29 |
* Returns - String. CleanTalk comment.
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
global $ct_global_temporary_data, $apbct;
|
34 |
|
35 |
//If the check for contact forms enabled
|
@@ -62,20 +72,19 @@ function ct_validate_ccf_submission($value, $field_id, $required){
|
|
62 |
|
63 |
unset($ct_global_temporary_data);
|
64 |
|
65 |
-
$sender_email =
|
66 |
-
$sender_nickname =
|
67 |
-
$subject =
|
68 |
-
$message =
|
69 |
|
70 |
-
if ($subject
|
71 |
$message['subject'] = $subject;
|
|
|
72 |
|
73 |
$post_info['comment_type'] = 'feedback_custom_contact_forms';
|
74 |
$post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
|
75 |
|
76 |
-
$checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
|
77 |
-
? apbct_js_test('ct_checkjs', $_COOKIE, true)
|
78 |
-
: apbct_js_test('ct_checkjs', $_POST);
|
79 |
|
80 |
//Making a call
|
81 |
$base_call_result = apbct_base_call(
|
@@ -91,7 +100,7 @@ function ct_validate_ccf_submission($value, $field_id, $required){
|
|
91 |
|
92 |
$ct_result = $base_call_result['ct_result'];
|
93 |
|
94 |
-
return $ct_result->allow == 0 ? $ct_result->comment : true
|
95 |
}
|
96 |
|
97 |
function ct_woocommerce_wishlist_check($args){
|
@@ -117,17 +126,16 @@ function ct_woocommerce_wishlist_check($args){
|
|
117 |
$message = '';
|
118 |
$subject = '';
|
119 |
$email = $args['wishlist_owner_email'];
|
120 |
-
if($args['wishlist_first_name']
|
121 |
-
$nickname = trim($args['wishlist_first_name']." "
|
122 |
-
else
|
123 |
$nickname = '';
|
|
|
124 |
|
125 |
$post_info['comment_type'] = 'feedback';
|
126 |
$post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
|
127 |
|
128 |
-
$checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
|
129 |
-
? apbct_js_test('ct_checkjs', $_COOKIE, true)
|
130 |
-
: apbct_js_test('ct_checkjs', $_POST);
|
131 |
|
132 |
//Making a call
|
133 |
$base_call_result = apbct_base_call(
|
@@ -143,13 +151,17 @@ function ct_woocommerce_wishlist_check($args){
|
|
143 |
|
144 |
$ct_result = $base_call_result['ct_result'];
|
145 |
|
146 |
-
if ($ct_result->allow == 0)
|
147 |
-
wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>"
|
148 |
-
|
|
|
|
|
|
|
149 |
return $args;
|
|
|
150 |
}
|
151 |
|
152 |
-
function apbct_integration__buddyPres__getTemplateName( $located, $
|
153 |
global $apbct;
|
154 |
preg_match("/\/([a-z-_]+)\/buddypress-functions\.php$/", $located, $matches);
|
155 |
$apbct->buddy_press_tmpl = isset($matches[1]) ? $matches[1] : 'unknown';
|
@@ -158,10 +170,11 @@ function apbct_integration__buddyPres__getTemplateName( $located, $template_name
|
|
158 |
/**
|
159 |
* Test BuddyPress activity for spam (post update only)
|
160 |
*
|
161 |
-
* @global
|
162 |
* @param bool $is_spam
|
163 |
-
* @param
|
164 |
* @return boolean Spam flag
|
|
|
165 |
*/
|
166 |
function apbct_integration__buddyPres__activityWall( $is_spam, $activity_obj = null ){
|
167 |
|
@@ -169,9 +182,9 @@ function apbct_integration__buddyPres__activityWall( $is_spam, $activity_obj = n
|
|
169 |
|
170 |
$allowed_post_actions = array('post_update', 'new_activity_comment');
|
171 |
|
172 |
-
if( ! in_array(
|
173 |
$activity_obj === null ||
|
174 |
-
!
|
175 |
$activity_obj->privacy == 'media' ||
|
176 |
apbct_exclusions_check()
|
177 |
) {
|
@@ -202,24 +215,25 @@ function apbct_integration__buddyPres__activityWall( $is_spam, $activity_obj = n
|
|
202 |
add_action('bp_activity_after_save', 'apbct_integration__buddyPres__activityWall_showResponse', 1, 1);
|
203 |
$apbct->spam_notification = $ct_result->comment;
|
204 |
return true;
|
205 |
-
}else
|
206 |
return $is_spam;
|
|
|
207 |
}
|
208 |
|
209 |
/**
|
210 |
* Outputs message to AJAX frontend handler
|
211 |
*
|
212 |
-
* @global
|
213 |
-
* @param
|
214 |
*/
|
215 |
-
function apbct_integration__buddyPres__activityWall_showResponse( $
|
216 |
|
217 |
global $apbct;
|
218 |
|
219 |
// Legacy template
|
220 |
if($apbct->buddy_press_tmpl === 'bp-legacy'){
|
221 |
die('<div id="message" class="error bp-ajax-message"><p>'. $apbct->spam_notification .'</p></div>');
|
222 |
-
// Nouveau
|
223 |
}else{
|
224 |
@header( 'Content-Type: application/json; charset=' . get_option('blog_charset'));
|
225 |
die(json_encode(array(
|
@@ -232,9 +246,11 @@ function apbct_integration__buddyPres__activityWall_showResponse( $activity_obj
|
|
232 |
/**
|
233 |
* Public function - Tests new private messages (dialogs)
|
234 |
*
|
235 |
-
* @global
|
236 |
-
* @param
|
237 |
-
* @return void
|
|
|
|
|
238 |
*/
|
239 |
function apbct_integration__buddyPres__private_msg_check( $bp_message_obj){
|
240 |
|
@@ -291,21 +307,23 @@ function apbct_integration__buddyPres__private_msg_check( $bp_message_obj){
|
|
291 |
'comment_type' => 'buddypress_comment',
|
292 |
'post_url' => apbct_get_server_variable( 'HTTP_REFERER' ),
|
293 |
),
|
294 |
-
'js_on' => apbct_js_test('ct_checkjs', $_COOKIE, true)
|
295 |
-
? apbct_js_test('ct_checkjs', $_COOKIE, true)
|
296 |
-
: apbct_js_test('ct_checkjs', $_POST),
|
297 |
'sender_info' => array('sender_url' => null),
|
298 |
)
|
299 |
);
|
300 |
|
301 |
$ct_result = $base_call_result['ct_result'];
|
302 |
|
303 |
-
if ($ct_result->allow == 0)
|
304 |
-
wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>"
|
|
|
|
|
|
|
|
|
305 |
}
|
306 |
|
307 |
/**
|
308 |
-
* Adds
|
309 |
*
|
310 |
* @param $form string
|
311 |
* @return string
|
@@ -339,16 +357,14 @@ function apbct_forms__search__testSpam( $search ){
|
|
339 |
return $search;
|
340 |
}
|
341 |
|
342 |
-
|
343 |
-
$user = wp_get_current_user();
|
344 |
|
345 |
$base_call_result = apbct_base_call(
|
346 |
array(
|
347 |
'message' => $search,
|
348 |
-
'sender_email' =>
|
349 |
-
'sender_nickname' =>
|
350 |
'post_info' => array('comment_type' => 'site_search_wordpress'),
|
351 |
-
//'js_on' => apbct_js_test('ct_checkjs_search_default', $_GET, true),
|
352 |
)
|
353 |
);
|
354 |
$ct_result = $base_call_result['ct_result'];
|
@@ -381,7 +397,7 @@ function apbct_search_add_noindex() {
|
|
381 |
|
382 |
/**
|
383 |
* Test woocommerce checkout form for spam
|
384 |
-
*
|
385 |
*/
|
386 |
function ct_woocommerce_checkout_check() {
|
387 |
|
@@ -390,13 +406,14 @@ function ct_woocommerce_checkout_check() {
|
|
390 |
//Getting request params
|
391 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
392 |
|
393 |
-
$sender_email =
|
394 |
-
$sender_nickname =
|
395 |
-
$subject =
|
396 |
-
$message =
|
397 |
|
398 |
-
if($subject != '')
|
399 |
-
$message = array_merge(array('subject' => $subject), $message);
|
|
|
400 |
|
401 |
$post_info['comment_type'] = 'order';
|
402 |
$post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
|
@@ -442,7 +459,7 @@ function ct_woocommerce_checkout_check() {
|
|
442 |
* @return void
|
443 |
*/
|
444 |
|
445 |
-
function apbct_wc__add_to_cart_unlogged_user($
|
446 |
global $apbct;
|
447 |
|
448 |
if(! apbct_is_user_logged_in() && $apbct->settings['forms__wc_add_to_cart']) {
|
@@ -486,7 +503,7 @@ function apbct_wc__add_to_cart_unlogged_user($cart_item_key, $product_id, $quant
|
|
486 |
}
|
487 |
|
488 |
/**
|
489 |
-
* Public function - Tests for Pirate contact
|
490 |
* return NULL
|
491 |
*/
|
492 |
function apbct_form__piratesForm__testSpam(){
|
@@ -502,13 +519,14 @@ function apbct_form__piratesForm__testSpam(){
|
|
502 |
//Getting request params
|
503 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
504 |
|
505 |
-
$sender_email =
|
506 |
-
$sender_nickname =
|
507 |
-
$subject =
|
508 |
-
$message =
|
509 |
|
510 |
-
if($subject
|
511 |
-
$message = array_merge(array('subject' => $subject), $message);
|
|
|
512 |
|
513 |
$post_info['comment_type'] = 'contact_form_wordpress_feedback_pirate';
|
514 |
$post_info['post_url'] = apbct_get_server_variable( 'HTTP_REFERER' );
|
@@ -527,14 +545,18 @@ function apbct_form__piratesForm__testSpam(){
|
|
527 |
|
528 |
$ct_result = $base_call_result['ct_result'];
|
529 |
|
530 |
-
if ($ct_result->allow == 0)
|
531 |
-
wp_die("<h1>".__('Spam protection by CleanTalk', 'cleantalk-spam-protect')."</h1><h2>"
|
|
|
|
|
|
|
|
|
532 |
}
|
533 |
|
534 |
/**
|
535 |
* Adds hidden filed to comment form
|
536 |
*/
|
537 |
-
function ct_comment_form($
|
538 |
|
539 |
global $apbct;
|
540 |
|
@@ -546,22 +568,26 @@ function ct_comment_form($post_id){
|
|
546 |
return false;
|
547 |
}
|
548 |
|
549 |
-
ct_add_hidden_fields(
|
550 |
|
551 |
return null;
|
552 |
}
|
553 |
|
554 |
-
|
555 |
/**
|
556 |
* Public function - Insert JS code for spam tests
|
557 |
-
*
|
|
|
|
|
|
|
|
|
558 |
*/
|
559 |
-
function apbct_form__formidable__footerScripts($
|
560 |
|
561 |
global $apbct, $ct_checkjs_frm;
|
562 |
|
563 |
-
if ( !$apbct->settings['forms__contact_forms_test'])
|
564 |
return false;
|
|
|
565 |
|
566 |
$ct_checkjs_key = ct_get_checkjs_value();
|
567 |
$ct_frm_base_name = 'form_';
|
@@ -586,8 +612,9 @@ function apbct_form__formidable__footerScripts($fields, $form) {
|
|
586 |
* @param $form
|
587 |
*
|
588 |
* @return array with errors if spam has found
|
|
|
589 |
*/
|
590 |
-
function apbct_form__formidable__testSpam ( $errors, $
|
591 |
|
592 |
global $apbct;
|
593 |
|
@@ -631,13 +658,12 @@ function apbct_form__formidable__testSpam ( $errors, $form ) {
|
|
631 |
foreach($tmp_message as &$value){
|
632 |
$value = 'item_meta['.$value.']';
|
633 |
} unset($value);
|
|
|
634 |
$tmp_message = array_flip($tmp_message);
|
635 |
// Combine it with non-scalar values
|
636 |
$message = array_merge( $tmp_message, $tmp_message2 );
|
637 |
|
638 |
-
$checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
|
639 |
-
? apbct_js_test('ct_checkjs', $_COOKIE, true)
|
640 |
-
: apbct_js_test('ct_checkjs', $_POST);
|
641 |
|
642 |
$base_call_result = apbct_base_call(
|
643 |
array(
|
@@ -661,6 +687,7 @@ function apbct_form__formidable__testSpam ( $errors, $form ) {
|
|
661 |
* Public filter 'bbp_*' - Get new topic name to global $ct_bbp_topic
|
662 |
* @param mixed[] $comment Comment string
|
663 |
* @return mixed[] $comment Comment string
|
|
|
664 |
*/
|
665 |
function ct_bbp_get_topic($topic){
|
666 |
global $ct_bbp_topic;
|
@@ -674,6 +701,7 @@ function ct_bbp_get_topic($topic){
|
|
674 |
* Public filter 'bbp_*' - Checks topics, replies by cleantalk
|
675 |
* @param mixed[] $comment Comment string
|
676 |
* @return mixed[] $comment Comment string
|
|
|
677 |
*/
|
678 |
function ct_bbp_new_pre_content ($comment) {
|
679 |
|
@@ -685,16 +713,12 @@ function ct_bbp_new_pre_content ($comment) {
|
|
685 |
}
|
686 |
|
687 |
// Skip processing for logged in users and admin.
|
688 |
-
if ( !$apbct->settings['data__protect_logged_in'] && is_user_logged_in() ||
|
689 |
-
apbct_exclusions_check()
|
690 |
-
) {
|
691 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
692 |
return $comment;
|
693 |
}
|
694 |
|
695 |
-
$checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
|
696 |
-
? apbct_js_test('ct_checkjs', $_COOKIE, true)
|
697 |
-
: apbct_js_test('ct_checkjs', $_POST);
|
698 |
|
699 |
$post_info['comment_type'] = 'bbpress_comment';
|
700 |
$post_info['post_url'] = bbp_get_topic_permalink();
|
@@ -737,11 +761,11 @@ function apbct_comment__sanitize_data__before_wp_die($function){
|
|
737 |
$comment_type = '';
|
738 |
|
739 |
$comment_content = isset($comment_data['comment']) ? (string) $comment_data['comment'] : null;
|
740 |
-
$comment_parent = isset($comment_data['comment_parent']) ?
|
741 |
|
742 |
-
$comment_author = isset($comment_data['author']) ?
|
743 |
-
$comment_author_email = isset($comment_data['email']) ?
|
744 |
-
$comment_author_url = isset($comment_data['url']) ?
|
745 |
$comment_post_ID = isset($comment_data['comment_post_ID']) ? (int) $comment_data['comment_post_ID'] : null;
|
746 |
|
747 |
if(isset($comment_content, $comment_parent)){
|
@@ -774,8 +798,8 @@ function apbct_comment__sanitize_data__before_wp_die($function){
|
|
774 |
}
|
775 |
|
776 |
function apbct_comment__check_via_wp_die($message, $title, $args){
|
|
|
777 |
if($title == __('Comment Submission Failure')){
|
778 |
-
global $apbct;
|
779 |
$apbct->validation_error = $message;
|
780 |
ct_preprocess_comment($apbct->comment_data);
|
781 |
}
|
@@ -786,12 +810,13 @@ function apbct_comment__check_via_wp_die($message, $title, $args){
|
|
786 |
* Public filter 'preprocess_comment' - Checks comment by cleantalk server
|
787 |
* @param mixed[] $comment Comment data array
|
788 |
* @return mixed[] New data array of comment
|
|
|
789 |
*/
|
790 |
function ct_preprocess_comment($comment) {
|
791 |
// this action is called just when WP process POST request (adds new comment)
|
792 |
// this action is called by wp-comments-post.php
|
793 |
// after processing WP makes redirect to post page with comment's form by GET request (see above)
|
794 |
-
global $current_user, $comment_post_id, $ct_comment_done, $ct_jp_comments, $apbct;
|
795 |
|
796 |
// Send email notification for chosen groups of users
|
797 |
if($apbct->settings['wp__comment_notify'] && !empty($apbct->settings['wp__comment_notify__roles']) && $apbct->data['moderate']){
|
@@ -833,7 +858,7 @@ function ct_preprocess_comment($comment) {
|
|
833 |
}
|
834 |
|
835 |
if (
|
836 |
-
($comment['comment_type']
|
837 |
(
|
838 |
apbct_is_user_enable() === false ||
|
839 |
$apbct->settings['forms__comments_test'] == 0 ||
|
@@ -858,7 +883,7 @@ function ct_preprocess_comment($comment) {
|
|
858 |
);
|
859 |
|
860 |
// Go out if author in local blacklists
|
861 |
-
if ($comment['comment_type']
|
862 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
863 |
return $comment;
|
864 |
}
|
@@ -874,9 +899,7 @@ function ct_preprocess_comment($comment) {
|
|
874 |
// Comment type
|
875 |
$post_info['comment_type'] = empty($post_info['comment_type']) ? 'general_comment' : $post_info['comment_type'];
|
876 |
|
877 |
-
$checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true)
|
878 |
-
? apbct_js_test('ct_checkjs', $_COOKIE, true)
|
879 |
-
: apbct_js_test('ct_checkjs', $_POST);
|
880 |
|
881 |
$example = null;
|
882 |
if ($apbct->data['relevance_test']) {
|
@@ -901,35 +924,39 @@ function ct_preprocess_comment($comment) {
|
|
901 |
}
|
902 |
}
|
903 |
|
904 |
-
|
905 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
906 |
|
|
|
|
|
|
|
907 |
if(isset($apbct->settings['comments__hide_website_field']) && $apbct->settings['comments__hide_website_field']) {
|
|
|
|
|
908 |
if(isset($_POST['url']) && !empty($_POST['url']) && $post_info['comment_type'] === 'comment' && isset($_POST['comment_post_ID'])) {
|
909 |
$honeypot_field = 0;
|
910 |
}
|
|
|
|
|
911 |
}
|
912 |
|
913 |
-
$base_call_result = apbct_base_call(
|
914 |
-
|
915 |
-
'message' => $comment['comment_content'],
|
916 |
-
'example' => $example,
|
917 |
-
'sender_email' => $comment['comment_author_email'],
|
918 |
-
'sender_nickname' => $comment['comment_author'],
|
919 |
-
'post_info' => $post_info,
|
920 |
-
'js_on' => $checkjs,
|
921 |
-
'sender_info' => array(
|
922 |
-
'sender_url' => @$comment['comment_author_url'],
|
923 |
-
'form_validation' => !isset($apbct->validation_error)
|
924 |
-
? null
|
925 |
-
: json_encode(array(
|
926 |
-
'validation_notice' => $apbct->validation_error,
|
927 |
-
'page_url' => apbct_get_server_variable( 'HTTP_HOST' ) . apbct_get_server_variable( 'REQUEST_URI' ),
|
928 |
-
))
|
929 |
-
),
|
930 |
-
'honeypot_field' => $honeypot_field
|
931 |
-
)
|
932 |
-
);
|
933 |
$ct_result = $base_call_result['ct_result'];
|
934 |
|
935 |
ct_hash($ct_result->id);
|
@@ -941,20 +968,21 @@ function ct_preprocess_comment($comment) {
|
|
941 |
}
|
942 |
|
943 |
// Change comment flow only for new authors
|
944 |
-
if (!empty($new_user) || $ct_result->stop_words !== null || $ct_result->spam == 1)
|
945 |
-
add_action('comment_post', 'ct_set_meta', 10, 2);
|
|
|
946 |
|
947 |
if($ct_result->allow){ // Pass if allowed
|
948 |
if(get_option('comment_moderation') === '1') // Wordpress moderation flag
|
949 |
-
|
950 |
-
|
951 |
-
|
|
|
|
|
952 |
// Modify the email notification
|
953 |
add_filter('comment_notification_text', 'apbct_comment__wordpress__show_blacklists', 100, 2); // Add two blacklist links: by email and IP
|
954 |
}else{
|
955 |
|
956 |
-
global $ct_comment, $ct_stop_words;
|
957 |
-
|
958 |
$ct_comment = $ct_result->comment;
|
959 |
$ct_stop_words = $ct_result->stop_words;
|
960 |
|
@@ -964,12 +992,14 @@ function ct_preprocess_comment($comment) {
|
|
964 |
}
|
965 |
|
966 |
// Terminate. Definitely spam.
|
967 |
-
if($ct_result->stop_queue == 1)
|
968 |
-
wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments ));
|
|
|
969 |
|
970 |
// Terminate by user's setting.
|
971 |
-
if($ct_result->spam == 3)
|
972 |
-
wp_die($err_text, 'Blacklisted', array('response' => 200, 'back_link' => ! $ct_jp_comments));
|
|
|
973 |
|
974 |
// Trash comment.
|
975 |
if($ct_result->spam == 2){
|
@@ -997,7 +1027,7 @@ function ct_preprocess_comment($comment) {
|
|
997 |
// Change mail notification if license is out of date
|
998 |
if($apbct->data['moderate'] == 0){
|
999 |
$apbct->sender_email = $comment['comment_author_email'];
|
1000 |
-
$apbct->sender_ip =
|
1001 |
add_filter('comment_moderation_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment sent to moderation
|
1002 |
add_filter('comment_notification_text', 'apbct_comment__Wordpress__changeMailNotification', 100, 2); // Comment approved
|
1003 |
}
|
@@ -1007,7 +1037,7 @@ function ct_preprocess_comment($comment) {
|
|
1007 |
|
1008 |
/**
|
1009 |
* Insert a hidden field to registration form
|
1010 |
-
* @return null
|
1011 |
*/
|
1012 |
function ct_register_form() {
|
1013 |
|
@@ -1045,9 +1075,9 @@ function ct_login_message($message) {
|
|
1045 |
|
1046 |
/**
|
1047 |
* Test users registration for pPress
|
1048 |
-
* @return
|
1049 |
*/
|
1050 |
-
function ct_registration_errors_ppress($reg_errors, $
|
1051 |
|
1052 |
$email = $_POST['reg_email'];
|
1053 |
$login = $_POST['reg_username'];
|
@@ -1058,14 +1088,12 @@ function ct_registration_errors_ppress($reg_errors, $form_id) {
|
|
1058 |
}
|
1059 |
|
1060 |
/**
|
1061 |
-
* Test users registration for multisite
|
1062 |
-
* @return array with errors
|
1063 |
*/
|
1064 |
function ct_registration_errors_wpmu($errors) {
|
1065 |
|
1066 |
-
//
|
1067 |
// Multisite actions
|
1068 |
-
//
|
1069 |
$sanitized_user_login = null;
|
1070 |
if (isset($errors['user_name'])) {
|
1071 |
$sanitized_user_login = $errors['user_name'];
|
@@ -1110,8 +1138,7 @@ function ct_register_post($sanitized_user_login, $user_email, $errors) {
|
|
1110 |
* Check messages for external plugins
|
1111 |
* @return array with checking result;
|
1112 |
*/
|
1113 |
-
|
1114 |
-
function ct_test_message($nickname, $email, $ip, $text){
|
1115 |
|
1116 |
$base_call_result = apbct_base_call(
|
1117 |
array(
|
@@ -1125,11 +1152,10 @@ function ct_test_message($nickname, $email, $ip, $text){
|
|
1125 |
|
1126 |
$ct_result = $base_call_result['ct_result'];
|
1127 |
|
1128 |
-
|
1129 |
'allow' => $ct_result->allow,
|
1130 |
'comment' => $ct_result->comment,
|
1131 |
);
|
1132 |
-
return $result;
|
1133 |
}
|
1134 |
|
1135 |
/**
|
@@ -1144,7 +1170,7 @@ function ct_test_registration($nickname, $email, $ip = null){
|
|
1144 |
$checkjs = apbct_js_test($ct_checkjs_register_form, $_POST);
|
1145 |
$sender_info['post_checkjs_passed'] = $checkjs;
|
1146 |
}else{
|
1147 |
-
$checkjs =
|
1148 |
$sender_info['cookie_checkjs_passed'] = $checkjs;
|
1149 |
}
|
1150 |
|
@@ -1172,16 +1198,17 @@ function ct_test_registration($nickname, $email, $ip = null){
|
|
1172 |
* Test users registration
|
1173 |
*
|
1174 |
* @param $errors
|
1175 |
-
* @param null $sanitized_user_login
|
1176 |
-
* @param null $user_email
|
1177 |
*
|
1178 |
* @return void|WP_Error
|
|
|
1179 |
*/
|
1180 |
function ct_registration_errors($errors, $sanitized_user_login = null, $user_email = null) {
|
1181 |
|
1182 |
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;
|
1183 |
|
1184 |
-
// Go out if a
|
1185 |
if (apbct_is_user_enable() === false) {
|
1186 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
1187 |
return $errors;
|
@@ -1199,6 +1226,7 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
|
|
1199 |
return $errors;
|
1200 |
}
|
1201 |
|
|
|
1202 |
// Facebook registration
|
1203 |
if ($sanitized_user_login === null && isset($_POST['FB_userdata'])){
|
1204 |
$sanitized_user_login = $_POST['FB_userdata']['name'];
|
@@ -1220,9 +1248,7 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
|
|
1220 |
$buddypress = true;
|
1221 |
}
|
1222 |
|
1223 |
-
//
|
1224 |
// Break tests because we already have servers response
|
1225 |
-
//
|
1226 |
if ($buddypress && $ct_signup_done) {
|
1227 |
if ($ct_negative_comment) {
|
1228 |
$bp->signup->errors['signup_username'] = $ct_negative_comment;
|
@@ -1232,15 +1258,15 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
|
|
1232 |
}
|
1233 |
|
1234 |
|
1235 |
-
if(current_filter()
|
1236 |
$checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
|
1237 |
$checkjs_post = null;
|
1238 |
$checkjs_cookie = $checkjs;
|
1239 |
}else{
|
1240 |
-
// This hack can be
|
1241 |
$checkjs_post = apbct_js_test($ct_checkjs_register_form, $_POST);
|
1242 |
$checkjs_cookie = apbct_js_test('ct_checkjs', $_COOKIE, true);
|
1243 |
-
$checkjs = $checkjs_cookie
|
1244 |
}
|
1245 |
|
1246 |
$sender_info = array(
|
@@ -1270,7 +1296,7 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
|
|
1270 |
($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
|
1271 |
){
|
1272 |
$apbct->sender_email = $user_email;
|
1273 |
-
$apbct->sender_ip =
|
1274 |
add_filter('wp_new_user_notification_email_admin', 'apbct_registration__Wordpress__changeMailNotification', 100, 3);
|
1275 |
}
|
1276 |
|
@@ -1289,15 +1315,16 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
|
|
1289 |
|
1290 |
if ($buddypress === true) {
|
1291 |
$bp->signup->errors['signup_username'] = $ct_result->comment;
|
1292 |
-
}elseif(
|
1293 |
$_POST['FB_userdata']['email'] = '';
|
1294 |
$_POST['FB_userdata']['name'] = '';
|
1295 |
return;
|
1296 |
}elseif(defined('MGM_PLUGIN_NAME')) {
|
1297 |
ct_die_extended($ct_result->comment);
|
1298 |
}else{
|
1299 |
-
if(is_wp_error($errors))
|
1300 |
-
$errors->add('ct_error', $ct_result->comment);
|
|
|
1301 |
$ct_negative_comment = $ct_result->comment;
|
1302 |
}
|
1303 |
|
@@ -1306,8 +1333,8 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
|
|
1306 |
} else {
|
1307 |
if ($ct_result->id !== null) {
|
1308 |
$apbct_cookie_request_id = $ct_result->id;
|
1309 |
-
|
1310 |
-
|
1311 |
}
|
1312 |
}
|
1313 |
|
@@ -1315,14 +1342,15 @@ function ct_registration_errors($errors, $sanitized_user_login = null, $user_ema
|
|
1315 |
}
|
1316 |
|
1317 |
/**
|
1318 |
-
* Changes email notification for newly
|
1319 |
*
|
1320 |
-
* @param
|
1321 |
-
* @param
|
1322 |
-
* @param
|
1323 |
-
*
|
|
|
1324 |
*/
|
1325 |
-
function apbct_registration__Wordpress__changeMailNotification($wp_new_user_notification_email_admin, $
|
1326 |
|
1327 |
global $apbct;
|
1328 |
|
@@ -1350,26 +1378,26 @@ function apbct_registration__Wordpress__changeMailNotification($wp_new_user_noti
|
|
1350 |
/**
|
1351 |
* Checks Ultimate Members registration for spam
|
1352 |
*
|
1353 |
-
* @param $args forms arguments with names and values
|
1354 |
*
|
1355 |
* @return mixed
|
1356 |
-
*
|
|
|
1357 |
*/
|
1358 |
function apbct_registration__UltimateMembers__check( $args ){
|
1359 |
|
|
|
|
|
1360 |
if ( isset( UM()->form()->errors ) ) {
|
1361 |
$sender_info['previous_form_validation'] = true;
|
1362 |
$sender_info['validation_notice'] = json_encode( UM()->form()->errors );
|
1363 |
}
|
1364 |
|
1365 |
-
global $apbct, $cleantalk_executed;
|
1366 |
-
|
1367 |
if ($apbct->settings['forms__registrations_test'] == 0) {
|
1368 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
1369 |
return $args;
|
1370 |
}
|
1371 |
|
1372 |
-
|
1373 |
$checkjs = apbct_js_test('ct_checkjs_register_form', $args);
|
1374 |
$sender_info['post_checkjs_passed'] = $checkjs;
|
1375 |
|
@@ -1397,33 +1425,48 @@ function apbct_registration__UltimateMembers__check( $args ){
|
|
1397 |
return $args;
|
1398 |
}
|
1399 |
|
1400 |
-
if ($ct_result->allow == 0)
|
1401 |
-
UM()->form()->add_error('user_password', $ct_result->comment );
|
|
|
1402 |
|
1403 |
return $args;
|
1404 |
}
|
1405 |
|
1406 |
/**
|
1407 |
* Checks registration error and set it if it was dropped
|
1408 |
-
*
|
|
|
|
|
|
|
|
|
|
|
1409 |
*/
|
1410 |
-
function ct_check_registration_erros($errors, $
|
1411 |
global $bp, $ct_registration_error_comment;
|
1412 |
|
1413 |
if($ct_registration_error_comment){
|
1414 |
|
1415 |
-
if(isset($bp))
|
1416 |
-
if(method_exists($bp, 'signup'))
|
1417 |
-
if(method_exists($bp->signup, 'errors'))
|
1418 |
-
if(isset($bp->signup->errors['signup_username']))
|
1419 |
-
if($bp->signup->errors['signup_username'] != $ct_registration_error_comment)
|
1420 |
$bp->signup->errors['signup_username'] = $ct_registration_error_comment;
|
|
|
|
|
|
|
|
|
|
|
1421 |
|
1422 |
-
if(isset($errors))
|
1423 |
-
if(method_exists($errors, 'errors'))
|
1424 |
-
if(isset($errors->errors['ct_error']))
|
1425 |
-
if($errors->errors['ct_error'][0] != $ct_registration_error_comment)
|
1426 |
-
$errors->add('ct_error', $ct_registration_error_comment);
|
|
|
|
|
|
|
|
|
1427 |
|
1428 |
}
|
1429 |
return $errors;
|
@@ -1431,8 +1474,7 @@ function ct_check_registration_erros($errors, $sanitized_user_login = null, $use
|
|
1431 |
|
1432 |
|
1433 |
/**
|
1434 |
-
* Set user meta (ct_hash) for
|
1435 |
-
* @return null
|
1436 |
*/
|
1437 |
function apbct_user_register($user_id) {
|
1438 |
|
@@ -1445,18 +1487,16 @@ function apbct_user_register($user_id) {
|
|
1445 |
|
1446 |
if ( isset($_COOKIE[$apbct_cookie_request_id_label]) ) {
|
1447 |
if(update_user_meta($user_id, 'ct_hash', $_COOKIE[$apbct_cookie_request_id_label])){
|
1448 |
-
|
1449 |
}
|
1450 |
-
return;
|
1451 |
}
|
1452 |
-
|
1453 |
}
|
1454 |
|
1455 |
|
1456 |
/**
|
1457 |
* Test for JetPack contact form
|
1458 |
*/
|
1459 |
-
function ct_grunion_contact_form_field_html($r, $
|
1460 |
|
1461 |
global $ct_checkjs_jpcf, $ct_jpcf_patched, $ct_jpcf_fields, $apbct;
|
1462 |
|
@@ -1479,10 +1519,11 @@ function ct_grunion_contact_form_field_html($r, $field_label) {
|
|
1479 |
}
|
1480 |
/**
|
1481 |
* Test for JetPack contact form
|
|
|
1482 |
*/
|
1483 |
function ct_contact_form_is_spam($form) {
|
1484 |
|
1485 |
-
global $ct_checkjs_jpcf, $apbct;
|
1486 |
|
1487 |
if ($apbct->settings['forms__contact_forms_test'] == 0) {
|
1488 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
@@ -1490,22 +1531,26 @@ function ct_contact_form_is_spam($form) {
|
|
1490 |
}
|
1491 |
|
1492 |
$js_field_name = $ct_checkjs_jpcf;
|
1493 |
-
foreach ($_POST as $k => $
|
1494 |
-
if (preg_match("/^.+$ct_checkjs_jpcf$/", $k))
|
1495 |
$js_field_name = $k;
|
|
|
1496 |
}
|
1497 |
|
1498 |
$sender_email = null;
|
1499 |
$sender_nickname = null;
|
1500 |
$message = '';
|
1501 |
-
if (isset($form['comment_author_email']))
|
1502 |
$sender_email = $form['comment_author_email'];
|
|
|
1503 |
|
1504 |
-
if (isset($form['comment_author']))
|
1505 |
$sender_nickname = $form['comment_author'];
|
|
|
1506 |
|
1507 |
-
if (isset($form['comment_content']))
|
1508 |
$message = $form['comment_content'];
|
|
|
1509 |
|
1510 |
$base_call_result = apbct_base_call(
|
1511 |
array(
|
@@ -1520,7 +1565,6 @@ function ct_contact_form_is_spam($form) {
|
|
1520 |
$ct_result = $base_call_result['ct_result'];
|
1521 |
|
1522 |
if ($ct_result->allow == 0) {
|
1523 |
-
global $ct_comment;
|
1524 |
$ct_comment = $ct_result->comment;
|
1525 |
ct_die(null, null);
|
1526 |
exit;
|
@@ -1529,8 +1573,15 @@ function ct_contact_form_is_spam($form) {
|
|
1529 |
return ! $ct_result->allow;
|
1530 |
}
|
1531 |
|
1532 |
-
|
1533 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1534 |
|
1535 |
if ($apbct->settings['forms__contact_forms_test'] == 0) {
|
1536 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
@@ -1549,13 +1600,12 @@ function ct_contact_form_is_spam_jetpack($is_spam,$form) {
|
|
1549 |
$ct_result = $base_call_result['ct_result'];
|
1550 |
|
1551 |
if ($ct_result->allow == 0) {
|
1552 |
-
global $ct_comment;
|
1553 |
$ct_comment = $ct_result->comment;
|
1554 |
ct_die(null, null);
|
1555 |
exit;
|
1556 |
}
|
1557 |
|
1558 |
-
return
|
1559 |
}
|
1560 |
|
1561 |
/**
|
@@ -1571,8 +1621,6 @@ function apbct_form__wpmm__addField(){
|
|
1571 |
function apbct_form__contactForm7__addField($html) {
|
1572 |
global $ct_checkjs_cf7, $apbct;
|
1573 |
|
1574 |
-
|
1575 |
-
|
1576 |
if ($apbct->settings['forms__contact_forms_test'] == 0) {
|
1577 |
return $html;
|
1578 |
}
|
@@ -1583,17 +1631,17 @@ function apbct_form__contactForm7__addField($html) {
|
|
1583 |
}
|
1584 |
|
1585 |
/**
|
1586 |
-
* Test spam for Contact
|
|
|
|
|
|
|
1587 |
*
|
1588 |
-
* @global
|
1589 |
-
* @param type $result
|
1590 |
-
* @param type $tags
|
1591 |
-
* @return type
|
1592 |
*/
|
1593 |
-
function apbct_form__contactForm7__tesSpam__before_validate($result = null, $
|
1594 |
global $apbct;
|
1595 |
|
1596 |
-
if ($result && method_exists($result, 'get_invalid_fields')){
|
1597 |
$invalid_fields = $result->get_invalid_fields();
|
1598 |
if(!empty($invalid_fields) && is_array($invalid_fields)){
|
1599 |
$apbct->validation_error = $invalid_fields[key($invalid_fields)]['reason'];
|
@@ -1606,16 +1654,17 @@ function apbct_form__contactForm7__tesSpam__before_validate($result = null, $tag
|
|
1606 |
|
1607 |
/**
|
1608 |
* Test CF7 message for spam
|
|
|
1609 |
*/
|
1610 |
-
function apbct_form__contactForm7__testSpam( $spam, $
|
1611 |
|
1612 |
-
global $ct_checkjs_cf7, $apbct;
|
1613 |
|
1614 |
if(
|
1615 |
$apbct->settings['forms__contact_forms_test'] == 0 ||
|
1616 |
-
$spam
|
1617 |
-
$spam === true && WPCF7_VERSION >= '3.0.0' ||
|
1618 |
-
$apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() || // Skip processing for logged in users.
|
1619 |
apbct_exclusions_check__url() ||
|
1620 |
apbct_exclusions_check__ip() ||
|
1621 |
isset($apbct->cf7_checked)
|
@@ -1624,17 +1673,15 @@ function apbct_form__contactForm7__testSpam( $spam, $submission = null ) {
|
|
1624 |
return $spam;
|
1625 |
}
|
1626 |
|
1627 |
-
$checkjs = apbct_js_test($ct_checkjs_cf7, $_POST)
|
1628 |
-
? apbct_js_test($ct_checkjs_cf7, $_POST)
|
1629 |
-
: apbct_js_test('ct_checkjs', $_COOKIE, true);
|
1630 |
|
1631 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
1632 |
|
1633 |
-
$sender_email =
|
1634 |
-
$sender_nickname =
|
1635 |
-
$subject =
|
1636 |
-
$message =
|
1637 |
-
if ($subject
|
1638 |
$message = array_merge(array('subject' => $subject), $message);
|
1639 |
}
|
1640 |
|
@@ -1663,18 +1710,17 @@ function apbct_form__contactForm7__testSpam( $spam, $submission = null ) {
|
|
1663 |
($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
|
1664 |
){
|
1665 |
$apbct->sender_email = $sender_email;
|
1666 |
-
$apbct->sender_ip =
|
1667 |
add_filter('wpcf7_mail_components', 'apbct_form__contactForm7__changeMailNotification');
|
1668 |
}
|
1669 |
|
1670 |
if ($ct_result->allow == 0) {
|
1671 |
|
1672 |
-
global $ct_cf7_comment;
|
1673 |
$ct_cf7_comment = $ct_result->comment;
|
1674 |
|
1675 |
add_filter('wpcf7_display_message', 'apbct_form__contactForm7__showResponse', 10, 2);
|
1676 |
|
1677 |
-
$spam = WPCF7_VERSION >= '3.0.0'
|
1678 |
|
1679 |
}
|
1680 |
|
@@ -1685,12 +1731,16 @@ function apbct_form__contactForm7__testSpam( $spam, $submission = null ) {
|
|
1685 |
|
1686 |
/**
|
1687 |
* Changes CF7 status message
|
1688 |
-
*
|
|
|
|
|
|
|
|
|
1689 |
*/
|
1690 |
function apbct_form__contactForm7__showResponse($message, $status = 'spam') {
|
1691 |
global $ct_cf7_comment;
|
1692 |
|
1693 |
-
if ($status
|
1694 |
$message = $ct_cf7_comment;
|
1695 |
}
|
1696 |
|
@@ -1698,7 +1748,7 @@ function apbct_form__contactForm7__showResponse($message, $status = 'spam') {
|
|
1698 |
}
|
1699 |
|
1700 |
/**
|
1701 |
-
* Changes email notification for
|
1702 |
*
|
1703 |
* @param array $component Arguments for email notification
|
1704 |
* @return array Arguments for email notification
|
@@ -1725,7 +1775,7 @@ function apbct_form__contactForm7__changeMailNotification($component){
|
|
1725 |
/**
|
1726 |
* Test Ninja Forms message for spam
|
1727 |
*
|
1728 |
-
* @global
|
1729 |
* @return void
|
1730 |
*/
|
1731 |
function apbct_form__ninjaForms__testSpam() {
|
@@ -1751,18 +1801,19 @@ function apbct_form__ninjaForms__testSpam() {
|
|
1751 |
// Choosing between POST and GET
|
1752 |
$params = ct_get_fields_any(isset($_GET['ninja_forms_ajax_submit']) || isset($_GET['nf_ajax_submit']) ? $_GET : $_POST);
|
1753 |
|
1754 |
-
$sender_email =
|
1755 |
-
$sender_nickname =
|
1756 |
-
$subject =
|
1757 |
-
$message =
|
1758 |
if ($subject != '') {
|
1759 |
$message = array_merge(array('subject' => $subject), $message);
|
1760 |
}
|
1761 |
|
1762 |
//Ninja Forms xml fix
|
1763 |
foreach ($message as $key => $value){
|
1764 |
-
if (strpos($value, '<xml>') !== false)
|
1765 |
-
unset($message[$key]);
|
|
|
1766 |
}
|
1767 |
|
1768 |
$base_call_result = apbct_base_call(
|
@@ -1781,7 +1832,7 @@ function apbct_form__ninjaForms__testSpam() {
|
|
1781 |
($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
|
1782 |
){
|
1783 |
$apbct->sender_email = $sender_email;
|
1784 |
-
$apbct->sender_ip =
|
1785 |
add_filter('ninja_forms_action_email_message', 'apbct_form__ninjaForms__changeMailNotification', 1, 3);
|
1786 |
}
|
1787 |
|
@@ -1795,15 +1846,29 @@ function apbct_form__ninjaForms__testSpam() {
|
|
1795 |
}
|
1796 |
}
|
1797 |
|
1798 |
-
function apbct_form__ninjaForms__preventSubmission($
|
1799 |
return false;
|
1800 |
}
|
1801 |
|
1802 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1803 |
global $apbct;
|
1804 |
throw new Exception($apbct->response);
|
1805 |
}
|
1806 |
|
|
|
|
|
|
|
|
|
1807 |
function apbct_form__ninjaForms__changeResponse( $data ) {
|
1808 |
|
1809 |
global $apbct;
|
@@ -1831,9 +1896,12 @@ function apbct_form__ninjaForms__changeResponse( $data ) {
|
|
1831 |
|
1832 |
}
|
1833 |
|
|
|
|
|
|
|
1834 |
function apbct_form__seedprod_coming_soon__testSpam() {
|
1835 |
|
1836 |
-
global $apbct;
|
1837 |
|
1838 |
if(
|
1839 |
$apbct->settings['forms__contact_forms_test'] == 0
|
@@ -1846,10 +1914,10 @@ function apbct_form__seedprod_coming_soon__testSpam() {
|
|
1846 |
|
1847 |
$ct_temp_msg_data = ct_get_fields_any($_REQUEST);
|
1848 |
|
1849 |
-
$sender_email =
|
1850 |
-
$sender_nickname =
|
1851 |
-
$subject =
|
1852 |
-
$message =
|
1853 |
if ($subject != '') {
|
1854 |
$message = array_merge(array('subject' => $subject), $message);
|
1855 |
}
|
@@ -1867,7 +1935,6 @@ function apbct_form__seedprod_coming_soon__testSpam() {
|
|
1867 |
|
1868 |
$ct_result = $base_call_result['ct_result'];
|
1869 |
if ($ct_result->allow == 0) {
|
1870 |
-
global $ct_comment;
|
1871 |
$ct_comment = $ct_result->comment;
|
1872 |
|
1873 |
$response = array(
|
@@ -1882,12 +1949,12 @@ function apbct_form__seedprod_coming_soon__testSpam() {
|
|
1882 |
}
|
1883 |
|
1884 |
/**
|
1885 |
-
* Changes email notification for
|
1886 |
*
|
1887 |
* @param string $message Body of email notification
|
1888 |
* @return string Body for email notification
|
1889 |
*/
|
1890 |
-
function apbct_form__ninjaForms__changeMailNotification($message, $
|
1891 |
|
1892 |
global $apbct;
|
1893 |
|
@@ -1911,15 +1978,16 @@ function apbct_form__ninjaForms__changeMailNotification($message, $data, $action
|
|
1911 |
/**
|
1912 |
* Inserts anti-spam hidden to WPForms
|
1913 |
*
|
1914 |
-
* @global
|
1915 |
* @return void
|
1916 |
*/
|
1917 |
-
function apbct_form__WPForms__addField($
|
1918 |
|
1919 |
global $apbct;
|
1920 |
|
1921 |
-
if($apbct->settings['forms__contact_forms_test'] == 1)
|
1922 |
-
ct_add_hidden_fields('ct_checkjs_wpforms'
|
|
|
1923 |
|
1924 |
}
|
1925 |
|
@@ -1930,7 +1998,7 @@ function apbct_form__WPForms__addField($form_data, $some, $title, $description,
|
|
1930 |
* @param $form
|
1931 |
*
|
1932 |
* @return array
|
1933 |
-
* @global
|
1934 |
*/
|
1935 |
function apbct_from__WPForms__gatherData($entry, $form){
|
1936 |
|
@@ -1959,20 +2027,18 @@ function apbct_from__WPForms__gatherData($entry, $form){
|
|
1959 |
|
1960 |
# search name
|
1961 |
if($field_type === 'name') {
|
1962 |
-
if(
|
1963 |
-
|
1964 |
-
|
1965 |
-
|
1966 |
-
$handled_result['name'] = array('nick' => $entry_field_value, 'first' => '', 'last' => '');
|
1967 |
-
}
|
1968 |
-
continue;
|
1969 |
}
|
|
|
1970 |
}
|
1971 |
|
1972 |
# Add field label as key for result array
|
1973 |
# add unique key if key exist
|
1974 |
if($field_label) {
|
1975 |
-
$field_label = trim(
|
1976 |
$field_label = str_replace(' ', '_', $field_label);
|
1977 |
$field_label = preg_replace('/\W/u', '', $field_label);
|
1978 |
|
@@ -2007,8 +2073,9 @@ function apbct_form__WPForms__showResponse($errors, $form_data) {
|
|
2007 |
? key($form_data['fields'])
|
2008 |
: 0;
|
2009 |
|
2010 |
-
if($spam_comment)
|
2011 |
$errors[ $form_data['id'] ][ $filed_id ] = $spam_comment;
|
|
|
2012 |
|
2013 |
}
|
2014 |
|
@@ -2020,10 +2087,8 @@ function apbct_form__WPForms__showResponse($errors, $form_data) {
|
|
2020 |
* Doesn't hooked anywhere.
|
2021 |
* Called directly from apbct_form__WPForms__showResponse()
|
2022 |
*
|
2023 |
-
* @
|
2024 |
-
* @global
|
2025 |
-
* @param array $errors Array of errors to write false result in
|
2026 |
-
* @return void|array|null
|
2027 |
*/
|
2028 |
function apbct_form__WPForms__testSpam() {
|
2029 |
|
@@ -2031,7 +2096,7 @@ function apbct_form__WPForms__testSpam() {
|
|
2031 |
|
2032 |
if(
|
2033 |
$apbct->settings['forms__contact_forms_test'] == 0 ||
|
2034 |
-
$apbct->settings['data__protect_logged_in'] != 1 && is_user_logged_in() // Skip processing for logged in users.
|
2035 |
){
|
2036 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
2037 |
return;
|
@@ -2040,7 +2105,7 @@ function apbct_form__WPForms__testSpam() {
|
|
2040 |
$checkjs = apbct_js_test('ct_checkjs_wpforms', $_POST);
|
2041 |
|
2042 |
$email = $apbct->form_data['email'] ?: null;
|
2043 |
-
$nickname = $apbct->form_data['name']
|
2044 |
$form_data = $apbct->form_data;
|
2045 |
|
2046 |
if($email) {
|
@@ -2050,17 +2115,17 @@ function apbct_form__WPForms__testSpam() {
|
|
2050 |
unset($form_data['name']);
|
2051 |
}
|
2052 |
|
2053 |
-
$params = ct_get_fields_any($apbct->form_data,
|
2054 |
|
2055 |
if(is_array($params['nickname'])) {
|
2056 |
$params['nickname'] = implode(' ', $params['nickname']);
|
2057 |
}
|
2058 |
|
2059 |
-
$sender_email =
|
2060 |
-
$sender_nickname =
|
2061 |
-
$subject =
|
2062 |
-
$message =
|
2063 |
-
if ($subject
|
2064 |
$message = array_merge(array('subject' => $subject), $message);
|
2065 |
}
|
2066 |
|
@@ -2080,7 +2145,7 @@ function apbct_form__WPForms__testSpam() {
|
|
2080 |
($ct_result->fast_submit == 1 || $ct_result->blacklisted == 1 || $ct_result->js_disabled == 1)
|
2081 |
){
|
2082 |
$apbct->sender_email = $sender_email;
|
2083 |
-
$apbct->sender_ip =
|
2084 |
add_filter('wpforms_email_message', 'apbct_form__WPForms__changeMailNotification', 100, 2);
|
2085 |
}
|
2086 |
|
@@ -2096,15 +2161,14 @@ function apbct_form__WPForms__testSpam() {
|
|
2096 |
* Changes email notification for succes subscription for Ninja Forms
|
2097 |
*
|
2098 |
* @param string $message Body of email notification
|
2099 |
-
* @param
|
2100 |
* @return string Body for email notification
|
2101 |
*/
|
2102 |
-
function apbct_form__WPForms__changeMailNotification($message, $
|
2103 |
|
2104 |
global $apbct;
|
2105 |
|
2106 |
-
$message = str_replace('</html>', '', $message);
|
2107 |
-
$message = str_replace('</body>', '', $message);
|
2108 |
$message .= wpautop(PHP_EOL . '---'
|
2109 |
.PHP_EOL
|
2110 |
.__('CleanTalk AntiSpam: This message is spam.', 'cleantalk-spam-protect')
|
@@ -2122,11 +2186,17 @@ function apbct_form__WPForms__changeMailNotification($message, $wpforms_email){
|
|
2122 |
|
2123 |
}
|
2124 |
|
2125 |
-
|
2126 |
-
|
2127 |
-
*
|
2128 |
-
*
|
2129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2130 |
function ct_quform_post_validate($result, $form) {
|
2131 |
|
2132 |
if ( $form->hasPages() ) {
|
@@ -2137,7 +2207,7 @@ function ct_quform_post_validate($result, $form) {
|
|
2137 |
|
2138 |
$ct_temp_msg_data = ct_get_fields_any( $form->getValues() );
|
2139 |
// @ToDo If we have several emails at the form - will be used only the first detected!
|
2140 |
-
$sender_email =
|
2141 |
|
2142 |
$checkjs = apbct_js_test('ct_checkjs', $_COOKIE, true);
|
2143 |
$base_call_result = apbct_base_call(
|
@@ -2152,8 +2222,6 @@ function ct_quform_post_validate($result, $form) {
|
|
2152 |
$ct_result = $base_call_result['ct_result'];
|
2153 |
if ($ct_result->allow == 0) {
|
2154 |
die(json_encode(array('type' => 'error', 'apbct' => array('blocked' => true, 'comment' => $ct_result->comment)), JSON_HEX_QUOT | JSON_HEX_TAG));
|
2155 |
-
} else {
|
2156 |
-
return $result;
|
2157 |
}
|
2158 |
|
2159 |
return $result;
|
@@ -2163,23 +2231,22 @@ function ct_quform_post_validate($result, $form) {
|
|
2163 |
/**
|
2164 |
* Inserts anti-spam hidden to Fast Secure contact form
|
2165 |
*/
|
2166 |
-
function ct_si_contact_display_after_fields($string = '', $
|
2167 |
$string .= ct_add_hidden_fields('ct_checkjs', true);
|
2168 |
return $string;
|
2169 |
}
|
2170 |
|
2171 |
/**
|
2172 |
* Test for Fast Secure contact form
|
|
|
2173 |
*/
|
2174 |
-
function ct_si_contact_form_validate($form_errors = array(), $
|
2175 |
-
global $apbct, $cleantalk_executed;
|
2176 |
-
|
2177 |
if (!empty($form_errors)) {
|
2178 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
2179 |
return $form_errors;
|
2180 |
}
|
2181 |
|
2182 |
-
|
2183 |
if ($apbct->settings['forms__contact_forms_test'] == 0) {
|
2184 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
2185 |
return $form_errors;
|
@@ -2194,11 +2261,11 @@ function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
|
|
2194 |
//getting info from custom fields
|
2195 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
2196 |
|
2197 |
-
$sender_email =
|
2198 |
-
$sender_nickname =
|
2199 |
-
$subject =
|
2200 |
-
$message =
|
2201 |
-
if($subject
|
2202 |
$message['subject'] = $subject;
|
2203 |
}
|
2204 |
|
@@ -2217,7 +2284,7 @@ function ct_si_contact_form_validate($form_errors = array(), $form_id_num = 0) {
|
|
2217 |
$cleantalk_executed = true;
|
2218 |
|
2219 |
if ($ct_result->allow == 0) {
|
2220 |
-
|
2221 |
$ct_comment = $ct_result->comment;
|
2222 |
ct_die(null, null);
|
2223 |
exit;
|
@@ -2259,11 +2326,6 @@ function ct_check_wplp(){
|
|
2259 |
return;
|
2260 |
}
|
2261 |
|
2262 |
-
$post_info['comment_type'] = 'feedback';
|
2263 |
-
$post_info = json_encode($post_info);
|
2264 |
-
if ($post_info === false)
|
2265 |
-
$post_info = '';
|
2266 |
-
|
2267 |
$sender_email = '';
|
2268 |
foreach ($_POST as $v) {
|
2269 |
if (preg_match("/^\S+@\S+\.\S+$/", $v)) {
|
@@ -2297,7 +2359,7 @@ function ct_check_wplp(){
|
|
2297 |
$cleantalk_comment = 'OK';
|
2298 |
}
|
2299 |
|
2300 |
-
|
2301 |
} else {
|
2302 |
// Next POST/AJAX submit(s) of same WPLP form
|
2303 |
$cleantalk_comment = $_COOKIE[$ct_wplp_result_label];
|
@@ -2307,7 +2369,7 @@ function ct_check_wplp(){
|
|
2307 |
}
|
2308 |
|
2309 |
/**
|
2310 |
-
* Places a
|
2311 |
* @return string
|
2312 |
*/
|
2313 |
function apbct_form__gravityForms__addField($form_string, $form){
|
@@ -2334,6 +2396,7 @@ function apbct_form__gravityForms__addField($form_string, $form){
|
|
2334 |
/**
|
2335 |
* Gravity forms anti-spam test.
|
2336 |
* @return boolean
|
|
|
2337 |
*/
|
2338 |
function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
|
2339 |
|
@@ -2348,24 +2411,79 @@ function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
|
|
2348 |
}
|
2349 |
|
2350 |
$form_fields_for_ct = array();
|
2351 |
-
|
2352 |
-
|
2353 |
-
|
2354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2355 |
|
2356 |
-
$ct_temp_msg_data = ct_get_fields_any(
|
2357 |
|
2358 |
-
$sender_email =
|
2359 |
-
$sender_nickname =
|
2360 |
-
$subject =
|
2361 |
-
$message =
|
2362 |
|
2363 |
-
if($subject
|
2364 |
$message['subject'] = $subject;
|
|
|
2365 |
|
2366 |
-
$checkjs = apbct_js_test('ct_checkjs', $_POST)
|
2367 |
-
? apbct_js_test('ct_checkjs', $_POST)
|
2368 |
-
: apbct_js_test('ct_checkjs', $_COOKIE, true);
|
2369 |
|
2370 |
$base_call_result = apbct_base_call(
|
2371 |
array(
|
@@ -2387,7 +2505,7 @@ function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
|
|
2387 |
return $is_spam;
|
2388 |
}
|
2389 |
|
2390 |
-
function apbct_form__gravityForms__showResponse( $confirmation, $form, $
|
2391 |
|
2392 |
global $ct_gform_is_spam, $ct_gform_response;
|
2393 |
|
@@ -2400,7 +2518,7 @@ function apbct_form__gravityForms__showResponse( $confirmation, $form, $entry, $
|
|
2400 |
|
2401 |
/**
|
2402 |
* Test S2member registration
|
2403 |
-
* @return
|
2404 |
*/
|
2405 |
function ct_s2member_registration_test($post_key) {
|
2406 |
|
@@ -2431,22 +2549,26 @@ function ct_s2member_registration_test($post_key) {
|
|
2431 |
return true;
|
2432 |
}
|
2433 |
|
|
|
|
|
|
|
|
|
2434 |
function apbct_form__the7_contact_form() {
|
2435 |
|
2436 |
global $cleantalk_executed;
|
2437 |
|
2438 |
-
if ( check_ajax_referer( 'dt_contact_form', 'nonce', false ) &&
|
2439 |
|
2440 |
$post_info['comment_type'] = 'contact_the7_theme_contact_form';
|
2441 |
|
2442 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
2443 |
|
2444 |
-
$sender_email =
|
2445 |
-
$sender_nickname =
|
2446 |
-
$subject =
|
2447 |
-
$contact_form =
|
2448 |
-
$message =
|
2449 |
-
if ($subject
|
2450 |
$message = array_merge(array('subject' => $subject), $message);
|
2451 |
}
|
2452 |
|
@@ -2488,6 +2610,7 @@ function apbct_form__the7_contact_form() {
|
|
2488 |
|
2489 |
}
|
2490 |
|
|
|
2491 |
}
|
2492 |
|
2493 |
function apbct_form__elementor_pro__testSpam() {
|
@@ -2505,11 +2628,11 @@ function apbct_form__elementor_pro__testSpam() {
|
|
2505 |
|
2506 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
2507 |
|
2508 |
-
$sender_email =
|
2509 |
-
$sender_nickname =
|
2510 |
-
$subject =
|
2511 |
-
$message =
|
2512 |
-
if ($subject
|
2513 |
$message = array_merge(array('subject' => $subject), $message);
|
2514 |
}
|
2515 |
|
@@ -2583,7 +2706,7 @@ function apbct_form__inevio__testSpam() {
|
|
2583 |
|
2584 |
/**
|
2585 |
* Filters the 'status' array before register the user
|
2586 |
-
* using only by
|
2587 |
*
|
2588 |
* @param $success array array( 'status' => 'success' )
|
2589 |
* @param $data array ['username'] ['password'] ['email']
|
@@ -2597,8 +2720,18 @@ function apbct_wilcity_reg_validation( $success, $data ) {
|
|
2597 |
return $success;
|
2598 |
}
|
2599 |
|
2600 |
-
|
2601 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2602 |
|
2603 |
global $cleantalk_executed;
|
2604 |
|
@@ -2633,12 +2766,21 @@ function apbct_form__enfold_contact_form__test_spam( $send, $new_post, $form_par
|
|
2633 |
|
2634 |
}
|
2635 |
|
2636 |
-
|
2637 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2638 |
|
2639 |
-
|
2640 |
|
2641 |
-
|
2642 |
|
2643 |
$data = ct_get_fields_any( $global_request );
|
2644 |
|
@@ -2676,7 +2818,14 @@ function apbct_form_profile_builder__error_message() {
|
|
2676 |
return '<p id="wppb_form_general_message" class="wppb-error">'. $GLOBALS['global_profile_builder_error'] .'</p>';
|
2677 |
}
|
2678 |
|
2679 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2680 |
function wpforo_create_profile__check_register( $user_fields ) {
|
2681 |
|
2682 |
global $ct_signup_done;
|
@@ -2690,3 +2839,17 @@ function wpforo_create_profile__check_register( $user_fields ) {
|
|
2690 |
$ct_signup_done = true;
|
2691 |
return $user_fields;
|
2692 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
|
3 |
use Cleantalk\ApbctWP\Helper;
|
4 |
+
use Cleantalk\ApbctWP\State;
|
5 |
+
use Cleantalk\ApbctWP\Variables\Cookie;
|
6 |
+
use Cleantalk\Variables\Post;
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
9 |
// MailChimp Premium for Wordpress
|
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();
|
30 |
+
/**
|
31 |
+
* Validate function for CCF form. Gathering data. Multiple calls.
|
32 |
* Input - void. Global $ct_global_temporary_data
|
33 |
* Returns - String. CleanTalk comment.
|
34 |
+
*
|
35 |
+
* @param $value
|
36 |
+
* @param $_field_id
|
37 |
+
* @param $_required
|
38 |
+
*
|
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
|
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(
|
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){
|
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(
|
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';
|
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 |
|
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 |
) {
|
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(
|
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 |
|
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
|
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'];
|
397 |
|
398 |
/**
|
399 |
* Test woocommerce checkout form for spam
|
400 |
+
* @psalm-suppress UnusedVariable
|
401 |
*/
|
402 |
function ct_woocommerce_checkout_check() {
|
403 |
|
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' );
|
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']) {
|
503 |
}
|
504 |
|
505 |
/**
|
506 |
+
* Public function - Tests for Pirate contact forms
|
507 |
* return NULL
|
508 |
*/
|
509 |
function apbct_form__piratesForm__testSpam(){
|
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' );
|
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 |
|
568 |
return false;
|
569 |
}
|
570 |
|
571 |
+
ct_add_hidden_fields();
|
572 |
|
573 |
return null;
|
574 |
}
|
575 |
|
|
|
576 |
/**
|
577 |
* Public function - Insert JS code for spam tests
|
578 |
+
*
|
579 |
+
* @param $_fields
|
580 |
+
* @param $form
|
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_';
|
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 |
|
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(
|
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;
|
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 |
|
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();
|
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)){
|
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 |
}
|
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']){
|
858 |
}
|
859 |
|
860 |
if (
|
861 |
+
($comment['comment_type']!=='trackback') &&
|
862 |
(
|
863 |
apbct_is_user_enable() === false ||
|
864 |
$apbct->settings['forms__comments_test'] == 0 ||
|
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 |
}
|
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']) {
|
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);
|
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 |
|
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){
|
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 |
}
|
1037 |
|
1038 |
/**
|
1039 |
* Insert a hidden field to registration form
|
1040 |
+
* @return null|bool
|
1041 |
*/
|
1042 |
function ct_register_form() {
|
1043 |
|
1075 |
|
1076 |
/**
|
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'];
|
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'];
|
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(
|
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 |
/**
|
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 |
|
1198 |
* Test users registration
|
1199 |
*
|
1200 |
* @param $errors
|
1201 |
+
* @param null|mixed $sanitized_user_login
|
1202 |
+
* @param null|mixed $user_email
|
1203 |
*
|
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;
|
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'];
|
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;
|
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(
|
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 |
|
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 |
|
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 |
|
1342 |
}
|
1343 |
|
1344 |
/**
|
1345 |
+
* Changes email notification for newly registered user
|
1346 |
*
|
1347 |
+
* @param array $wp_new_user_notification_email_admin Body of email notification
|
1348 |
+
* @param $_user
|
1349 |
+
* @param $_blogname
|
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 |
|
1378 |
/**
|
1379 |
* Checks Ultimate Members registration for spam
|
1380 |
*
|
1381 |
+
* @param array $args forms arguments with names and values
|
1382 |
*
|
1383 |
* @return mixed
|
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 |
|
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 |
/**
|
1436 |
* Checks registration error and set it if it was dropped
|
1437 |
+
*
|
1438 |
+
* @param $errors
|
1439 |
+
* @param null $_sanitized_user_login
|
1440 |
+
* @param null $_user_email
|
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;
|
1474 |
|
1475 |
|
1476 |
/**
|
1477 |
+
* Set user meta (ct_hash) for successes registration
|
|
|
1478 |
*/
|
1479 |
function apbct_user_register($user_id) {
|
1480 |
|
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 |
|
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 );
|
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(
|
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;
|
1573 |
return ! $ct_result->allow;
|
1574 |
}
|
1575 |
|
1576 |
+
/**
|
1577 |
+
* @param $_is_spam
|
1578 |
+
* @param $form
|
1579 |
+
*
|
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 );
|
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 |
/**
|
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 |
}
|
1631 |
}
|
1632 |
|
1633 |
/**
|
1634 |
+
* Test spam for Contact Form 7 (CF7) right before validation
|
1635 |
+
*
|
1636 |
+
* @param null|object $result
|
1637 |
+
* @param null $_tags
|
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'];
|
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)
|
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 |
|
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 |
|
1731 |
|
1732 |
/**
|
1733 |
* Changes CF7 status message
|
1734 |
+
*
|
1735 |
+
* @param $message
|
1736 |
+
* @param string $status
|
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 |
|
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
|
1775 |
/**
|
1776 |
* Test Ninja Forms message for spam
|
1777 |
*
|
1778 |
+
* @global State $apbct
|
1779 |
* @return void
|
1780 |
*/
|
1781 |
function apbct_form__ninjaForms__testSpam() {
|
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(
|
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 |
|
1846 |
}
|
1847 |
}
|
1848 |
|
1849 |
+
function apbct_form__ninjaForms__preventSubmission($_some, $_form_id){
|
1850 |
return false;
|
1851 |
}
|
1852 |
|
1853 |
+
|
1854 |
+
/**
|
1855 |
+
* @param $_some
|
1856 |
+
* @param $_action_settings
|
1857 |
+
* @param $_message
|
1858 |
+
* @param $_headers
|
1859 |
+
* @param $_attachments
|
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;
|
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
|
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 |
}
|
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(
|
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 |
|
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 |
|
1998 |
* @param $form
|
1999 |
*
|
2000 |
* @return array
|
2001 |
+
* @global State $apbct
|
2002 |
*/
|
2003 |
function apbct_from__WPForms__gatherData($entry, $form){
|
2004 |
|
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 |
|
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 |
|
2087 |
* Doesn't hooked anywhere.
|
2088 |
* Called directly from apbct_form__WPForms__showResponse()
|
2089 |
*
|
2090 |
+
* @return string|void
|
2091 |
+
* @global State $apbct
|
|
|
|
|
2092 |
*/
|
2093 |
function apbct_form__WPForms__testSpam() {
|
2094 |
|
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;
|
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) {
|
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 |
|
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 |
|
2161 |
* Changes email notification for succes subscription for Ninja Forms
|
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')
|
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() ) {
|
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(
|
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;
|
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;
|
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 |
|
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;
|
2326 |
return;
|
2327 |
}
|
2328 |
|
|
|
|
|
|
|
|
|
|
|
2329 |
$sender_email = '';
|
2330 |
foreach ($_POST as $v) {
|
2331 |
if (preg_match("/^\S+@\S+\.\S+$/", $v)) {
|
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];
|
2369 |
}
|
2370 |
|
2371 |
/**
|
2372 |
+
* Places a hiding field to Gravity forms.
|
2373 |
* @return string
|
2374 |
*/
|
2375 |
function apbct_form__gravityForms__addField($form_string, $form){
|
2396 |
/**
|
2397 |
* Gravity forms anti-spam test.
|
2398 |
* @return boolean
|
2399 |
+
* @psalm-suppress UnusedVariable
|
2400 |
*/
|
2401 |
function apbct_form__gravityForms__testSpam($is_spam, $form, $entry) {
|
2402 |
|
2411 |
}
|
2412 |
|
2413 |
$form_fields_for_ct = array();
|
2414 |
+
$form_fields = (isset($form['fields'])) ? $form['fields'] : false;
|
2415 |
+
$form_fields_intermediate = array();
|
2416 |
+
$email = '';
|
2417 |
+
$nickname = array();
|
2418 |
+
|
2419 |
+
if($form_fields) {
|
2420 |
+
foreach ($form_fields as $field) {
|
2421 |
+
$field_id = $field['id'];
|
2422 |
+
$field_visibility = $field['visibility'];
|
2423 |
+
$field_type = $field['type'];
|
2424 |
+
$field_inputs = $field['inputs'];
|
2425 |
+
|
2426 |
+
if($field_inputs) {
|
2427 |
+
foreach ($field_inputs as $input) {
|
2428 |
+
$input_id = $input['id'];
|
2429 |
+
|
2430 |
+
if(isset($entry[$input_id]) && $entry[$input_id]) {
|
2431 |
+
$form_fields_intermediate[] = array(
|
2432 |
+
'f_name' => 'input_' . $input_id,
|
2433 |
+
'f_visibility' => $field_visibility,
|
2434 |
+
'f_type' => $field_type,
|
2435 |
+
'f_data' => $entry[$input_id]
|
2436 |
+
);
|
2437 |
+
$form_fields_for_ct['input_' . $input_id] = $entry[$input_id];
|
2438 |
+
}
|
2439 |
+
}
|
2440 |
+
} else {
|
2441 |
+
if(isset($entry[$field_id]) && $entry[$field_id]) {
|
2442 |
+
$form_fields_intermediate[] = array(
|
2443 |
+
'f_name' => 'input_' . $field_id,
|
2444 |
+
'f_visibility' => $field_visibility,
|
2445 |
+
'f_type' => $field_type,
|
2446 |
+
'f_data' => $entry[$field_id]
|
2447 |
+
);
|
2448 |
+
$form_fields_for_ct['input_' . $field_id] = $entry[$field_id];
|
2449 |
+
}
|
2450 |
+
}
|
2451 |
+
}
|
2452 |
+
}
|
2453 |
+
|
2454 |
+
# Search nickname and email
|
2455 |
+
if($form_fields_intermediate) {
|
2456 |
+
foreach ($form_fields_intermediate as $field) {
|
2457 |
+
if($field['f_type'] === 'email') {
|
2458 |
+
$email = $field['f_data'];
|
2459 |
+
}
|
2460 |
+
|
2461 |
+
if($field['f_type'] === 'name') {
|
2462 |
+
$nickname[] = $field['f_data'];
|
2463 |
+
}
|
2464 |
+
}
|
2465 |
+
}
|
2466 |
+
|
2467 |
+
if(!$form_fields_for_ct) {
|
2468 |
+
foreach($entry as $key => $value){
|
2469 |
+
if(is_numeric($key)) {
|
2470 |
+
$form_fields_for_ct[ 'input_' . $key ] = $value;
|
2471 |
+
}
|
2472 |
+
} unset($key, $value);
|
2473 |
+
}
|
2474 |
|
2475 |
+
$ct_temp_msg_data = ct_get_fields_any($form_fields_for_ct, $email, array_shift($nickname));
|
2476 |
|
2477 |
+
$sender_email = $ct_temp_msg_data['email'] ?: '';
|
2478 |
+
$sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
|
2479 |
+
$subject = $ct_temp_msg_data['subject'] ?: '';
|
2480 |
+
$message = $ct_temp_msg_data['message'] ?: array();
|
2481 |
|
2482 |
+
if($subject !== '') {
|
2483 |
$message['subject'] = $subject;
|
2484 |
+
}
|
2485 |
|
2486 |
+
$checkjs = apbct_js_test( 'ct_checkjs', $_POST ) ?: apbct_js_test( 'ct_checkjs', $_COOKIE, true );
|
|
|
|
|
2487 |
|
2488 |
$base_call_result = apbct_base_call(
|
2489 |
array(
|
2505 |
return $is_spam;
|
2506 |
}
|
2507 |
|
2508 |
+
function apbct_form__gravityForms__showResponse( $confirmation, $form, $_entry, $_ajax ){
|
2509 |
|
2510 |
global $ct_gform_is_spam, $ct_gform_response;
|
2511 |
|
2518 |
|
2519 |
/**
|
2520 |
* Test S2member registration
|
2521 |
+
* @return bool|null with errors
|
2522 |
*/
|
2523 |
function ct_s2member_registration_test($post_key) {
|
2524 |
|
2549 |
return true;
|
2550 |
}
|
2551 |
|
2552 |
+
/**
|
2553 |
+
* @return false
|
2554 |
+
* @psalm-suppress UnusedVariable
|
2555 |
+
*/
|
2556 |
function apbct_form__the7_contact_form() {
|
2557 |
|
2558 |
global $cleantalk_executed;
|
2559 |
|
2560 |
+
if ( check_ajax_referer( 'dt_contact_form', 'nonce', false ) && ! empty($_POST) ) {
|
2561 |
|
2562 |
$post_info['comment_type'] = 'contact_the7_theme_contact_form';
|
2563 |
|
2564 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
2565 |
|
2566 |
+
$sender_email = $ct_temp_msg_data['email'] ?: '';
|
2567 |
+
$sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
|
2568 |
+
$subject = $ct_temp_msg_data['subject'] ?: '';
|
2569 |
+
$contact_form = $ct_temp_msg_data['contact'] ?: true;
|
2570 |
+
$message = $ct_temp_msg_data['message'] ?: array();
|
2571 |
+
if ($subject !== '') {
|
2572 |
$message = array_merge(array('subject' => $subject), $message);
|
2573 |
}
|
2574 |
|
2610 |
|
2611 |
}
|
2612 |
|
2613 |
+
return false;
|
2614 |
}
|
2615 |
|
2616 |
function apbct_form__elementor_pro__testSpam() {
|
2628 |
|
2629 |
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
2630 |
|
2631 |
+
$sender_email = $ct_temp_msg_data['email'] ?: '';
|
2632 |
+
$sender_nickname = $ct_temp_msg_data['nickname'] ?: '';
|
2633 |
+
$subject = $ct_temp_msg_data['subject'] ?: '';
|
2634 |
+
$message = $ct_temp_msg_data['message'] ?: array();
|
2635 |
+
if ($subject !== '') {
|
2636 |
$message = array_merge(array('subject' => $subject), $message);
|
2637 |
}
|
2638 |
|
2706 |
|
2707 |
/**
|
2708 |
* Filters the 'status' array before register the user
|
2709 |
+
* using only by WILCITY theme
|
2710 |
*
|
2711 |
* @param $success array array( 'status' => 'success' )
|
2712 |
* @param $data array ['username'] ['password'] ['email']
|
2720 |
return $success;
|
2721 |
}
|
2722 |
|
2723 |
+
/**
|
2724 |
+
* Enfold Theme contact form
|
2725 |
+
*
|
2726 |
+
* @param $send
|
2727 |
+
* @param $new_post
|
2728 |
+
* @param $_form_params
|
2729 |
+
* @param $obj
|
2730 |
+
*
|
2731 |
+
* @return mixed|null
|
2732 |
+
* @psalm-suppress UnusedVariable
|
2733 |
+
*/
|
2734 |
+
function apbct_form__enfold_contact_form__test_spam( $send, $new_post, $_form_params, $obj ){
|
2735 |
|
2736 |
global $cleantalk_executed;
|
2737 |
|
2766 |
|
2767 |
}
|
2768 |
|
2769 |
+
/**
|
2770 |
+
* Profile Builder integration
|
2771 |
+
*
|
2772 |
+
* @param $errors
|
2773 |
+
* @param $_fields
|
2774 |
+
* @param $global_request
|
2775 |
+
*
|
2776 |
+
* @return mixed
|
2777 |
+
* @psalm-suppress UnusedVariable
|
2778 |
+
*/
|
2779 |
+
function apbct_form_profile_builder__check_register ( $errors, $_fields, $global_request ){
|
2780 |
|
2781 |
+
global $cleantalk_executed;
|
2782 |
|
2783 |
+
if( isset( $global_request['action'] ) && $global_request['action'] === 'register' ) {
|
2784 |
|
2785 |
$data = ct_get_fields_any( $global_request );
|
2786 |
|
2818 |
return '<p id="wppb_form_general_message" class="wppb-error">'. $GLOBALS['global_profile_builder_error'] .'</p>';
|
2819 |
}
|
2820 |
|
2821 |
+
/**
|
2822 |
+
* WP Foro register system integration
|
2823 |
+
*
|
2824 |
+
* @param $user_fields
|
2825 |
+
*
|
2826 |
+
* @return array|mixed
|
2827 |
+
* @psalm-suppress UnusedVariable
|
2828 |
+
*/
|
2829 |
function wpforo_create_profile__check_register( $user_fields ) {
|
2830 |
|
2831 |
global $ct_signup_done;
|
2839 |
$ct_signup_done = true;
|
2840 |
return $user_fields;
|
2841 |
}
|
2842 |
+
|
2843 |
+
/**
|
2844 |
+
* Function checks for signs in the post request to perform validation and returns true|false
|
2845 |
+
*/
|
2846 |
+
function apbct_custom_forms_trappings() {
|
2847 |
+
global $apbct;
|
2848 |
+
|
2849 |
+
// Registration form of Wishlist Members plugin
|
2850 |
+
if($apbct->settings['forms__registrations_test'] && isset($_POST['action']) && $_POST['action'] === 'wpm_register') {
|
2851 |
+
return true;
|
2852 |
+
}
|
2853 |
+
|
2854 |
+
return false;
|
2855 |
+
}
|
@@ -75,7 +75,7 @@ function ct_contact_form_validate() {
|
|
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']) || // 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
|
@@ -101,7 +101,8 @@ function ct_contact_form_validate() {
|
|
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 |
/* !! Do not add actions here. Use apbct_is_skip_request() function below !! */
|
106 |
) {
|
107 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
@@ -342,7 +343,8 @@ function ct_contact_form_validate_postdata() {
|
|
342 |
isset($_POST['gform_submit']) || //Skip gravity checking because of direct integration
|
343 |
(isset($_POST['lrm_action']) && $_POST['lrm_action'] == 'login') || //Skip login form
|
344 |
apbct_is_in_uri( 'xmlrpc.php?for=jetpack' ) ||
|
345 |
-
apbct_is_in_uri( 'connector=bridge&task=put_sql' )
|
|
|
346 |
) {
|
347 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
348 |
return null;
|
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
|
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 );
|
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 |
) {
|
349 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, $_POST );
|
350 |
return null;
|
@@ -1,10 +1,13 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
use Cleantalk\Variables\
|
|
|
4 |
|
5 |
/**
|
6 |
* Init functions
|
7 |
-
*
|
|
|
|
|
8 |
*/
|
9 |
function apbct_init() {
|
10 |
|
@@ -14,22 +17,19 @@ function apbct_init() {
|
|
14 |
if( $apbct->settings['data__pixel'] ){
|
15 |
|
16 |
$pixel_hash = md5(
|
17 |
-
|
18 |
. $apbct->api_key
|
19 |
-
.
|
20 |
);
|
21 |
|
22 |
-
|
23 |
-
$
|
24 |
-
$
|
25 |
-
$
|
26 |
-
|
27 |
-
$apbct->pixel_url = 'https://' . $pixel_server . '/pixel/' . $pixel_hash . '.gif';
|
28 |
-
|
29 |
}
|
30 |
|
31 |
//Check internal forms with such "action" http://wordpress.loc/contact-us/some_script.php
|
32 |
-
if((isset($_POST['action']) && $_POST['action']
|
33 |
$apbct->settings['forms__check_internal']
|
34 |
){
|
35 |
$ct_result = ct_contact_form_validate();
|
@@ -87,7 +87,7 @@ function apbct_init() {
|
|
87 |
unset($_POST['cleantalk_hidden_method']);
|
88 |
ct_contact_form_validate();
|
89 |
if(!apbct_is_ajax()){
|
90 |
-
print "<html><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"' : '' ) . ">
|
@@ -114,12 +114,12 @@ function apbct_init() {
|
|
114 |
}
|
115 |
|
116 |
//hook for Anonymous Post
|
117 |
-
if($apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7']))
|
118 |
-
|
|
|
119 |
|
120 |
if($apbct->settings['forms__general_contact_forms_test'] == 1 && empty($_POST['ct_checkjs_cf7'])){
|
121 |
add_action('CMA_custom_post_type_nav', 'ct_contact_form_validate_postdata',1);
|
122 |
-
//add_action('init','ct_contact_form_validate',1);
|
123 |
ct_contact_form_validate();
|
124 |
if(isset($_POST['reg_redirect_link'])&&isset($_POST['tmpl_registration_nonce_field']))
|
125 |
{
|
@@ -128,10 +128,9 @@ function apbct_init() {
|
|
128 |
}
|
129 |
}
|
130 |
|
131 |
-
if($apbct->settings['data__general_postdata_test'] == 1 && empty($_POST['ct_checkjs_cf7']))
|
132 |
-
|
133 |
-
|
134 |
-
//add_action('wp_footer','ct_ajaxurl');
|
135 |
|
136 |
// Fast Secure contact form
|
137 |
if(defined('FSCF_VERSION')){
|
@@ -145,7 +144,7 @@ function apbct_init() {
|
|
145 |
if ($apbct->settings['forms__wc_checkout_test'] == 1) {
|
146 |
add_filter('woocommerce_checkout_process', 'ct_woocommerce_checkout_check', 1, 3);
|
147 |
}
|
148 |
-
if( isset($_REQUEST['wc-ajax']) && $_REQUEST['wc-ajax']
|
149 |
remove_filter( 'woocommerce_registration_errors', 'ct_registration_errors', 1 );
|
150 |
}
|
151 |
|
@@ -154,20 +153,21 @@ function apbct_init() {
|
|
154 |
}
|
155 |
|
156 |
// WooCommerce whishlist
|
157 |
-
if(class_exists('WC_Wishlists_Wishlist'))
|
158 |
-
add_filter('wc_wishlists_create_list_args', 'ct_woocommerce_wishlist_check', 1, 1);
|
|
|
159 |
|
160 |
|
161 |
// JetPack Contact form
|
162 |
if(defined('JETPACK__VERSION'))
|
163 |
{
|
164 |
// Checking Jetpack contact form
|
165 |
-
if(isset($_POST['action']) && $_POST['action']
|
166 |
-
if(JETPACK__VERSION
|
167 |
{
|
168 |
add_filter('contact_form_is_spam', 'ct_contact_form_is_spam');
|
169 |
}
|
170 |
-
else if(JETPACK__VERSION
|
171 |
{
|
172 |
add_filter('jetpack_contact_form_is_spam', 'ct_contact_form_is_spam_jetpack',50,2);
|
173 |
}
|
@@ -189,7 +189,7 @@ function apbct_init() {
|
|
189 |
|
190 |
}
|
191 |
|
192 |
-
// WP Maintenance Mode (
|
193 |
add_action('wpmm_head', 'apbct_form__wpmm__addField', 1);
|
194 |
|
195 |
// Contact Form7
|
@@ -217,7 +217,6 @@ function apbct_init() {
|
|
217 |
add_filter('pp_registration_validation', 'ct_registration_errors_ppress', 11, 2);
|
218 |
}
|
219 |
|
220 |
-
|
221 |
// bbPress
|
222 |
if(class_exists('bbPress')){
|
223 |
add_filter('bbp_new_topic_pre_title', 'ct_bbp_get_topic', 1);
|
@@ -228,8 +227,9 @@ function apbct_init() {
|
|
228 |
}
|
229 |
|
230 |
//Custom Contact Forms
|
231 |
-
if(defined('CCF_VERSION'))
|
232 |
-
add_filter('ccf_field_validator', 'ct_ccf', 1, 4);
|
|
|
233 |
|
234 |
add_action('comment_form', 'ct_comment_form');
|
235 |
|
@@ -246,7 +246,6 @@ function apbct_init() {
|
|
246 |
if (defined('WS_PLUGIN__S2MEMBER_PRO_VERSION')){
|
247 |
$post_keys = array_keys($_POST);
|
248 |
foreach($post_keys as $post_key){
|
249 |
-
|
250 |
// Detect POST keys like /s2member_pro.*registration/
|
251 |
if(strpos($post_key, 's2member') !== false && strpos($post_key, 'registration') !== false){
|
252 |
ct_s2member_registration_test($post_key);
|
@@ -273,13 +272,14 @@ function apbct_init() {
|
|
273 |
|
274 |
//Pirate forms
|
275 |
if(defined('PIRATE_FORMS_VERSION')){
|
276 |
-
if(isset($_POST['pirate-forms-contact-name']) && $_POST['pirate-forms-contact-name'] && isset($_POST['pirate-forms-contact-email']) && $_POST['pirate-forms-contact-email'])
|
277 |
apbct_form__piratesForm__testSpam();
|
|
|
278 |
}
|
279 |
|
280 |
// WPForms
|
281 |
// Adding fields
|
282 |
-
|
283 |
// Gathering data to validate
|
284 |
add_filter('wpforms_process_before_filter', 'apbct_from__WPForms__gatherData', 100, 2);
|
285 |
// Do spam check
|
@@ -304,7 +304,7 @@ function apbct_init() {
|
|
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 ) {
|
308 |
pmpro_setMessage( $check['comment'], 'pmpro_error' );
|
309 |
}
|
310 |
}
|
@@ -339,6 +339,13 @@ function apbct_init() {
|
|
339 |
ct_contact_form_validate_postdata();
|
340 |
}
|
341 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
}
|
343 |
|
344 |
function apbct_buffer__start(){
|
@@ -364,8 +371,9 @@ function apbct_buffer__output(){
|
|
364 |
|
365 |
global $apbct;
|
366 |
|
367 |
-
if( empty( $apbct->buffer ) )
|
368 |
return;
|
|
|
369 |
|
370 |
if( apbct_is_plugin_active( 'flow-flow/flow-flow.php' ) ) {
|
371 |
$output = apbct_buffer_modify_by_string();
|
@@ -428,14 +436,14 @@ function apbct_buffer_modify_by_dom() {
|
|
428 |
foreach($forms as $form){
|
429 |
|
430 |
$action = $form->getAttribute('action');
|
431 |
-
$action = $action
|
432 |
$action__host = parse_url($action, PHP_URL_HOST);
|
433 |
|
434 |
// Check if the form directed to the third party site
|
435 |
if($site__host != $action__host){
|
436 |
|
437 |
$method = $form->getAttribute('method');
|
438 |
-
$method = $method
|
439 |
// Directs form to our site
|
440 |
$form->setAttribute('method', 'POST');
|
441 |
$form->setAttribute('action', home_url(add_query_arg(array(), $wp->request)));
|
@@ -460,7 +468,7 @@ function apbct_buffer_modify_by_dom() {
|
|
460 |
|
461 |
$html = $dom->getElementsByTagName('html');
|
462 |
|
463 |
-
return is_object( $html ) && isset( $html[0], $html[0]->childNodes
|
464 |
? $dom->saveHTML()
|
465 |
: $apbct->buffer;
|
466 |
|
@@ -478,11 +486,17 @@ function apbct_hook__wp_head__set_cookie__ct_checkjs() {
|
|
478 |
|
479 |
/**
|
480 |
* Adds check_js script to the footer
|
|
|
481 |
*/
|
482 |
function apbct_hook__wp_footer() {
|
483 |
|
484 |
global $apbct;
|
485 |
|
|
|
|
|
|
|
|
|
|
|
486 |
// Pixel
|
487 |
if(
|
488 |
$apbct->settings['data__pixel'] === '1' ||
|
@@ -505,7 +519,7 @@ function apbct_hook__wp_footer() {
|
|
505 |
{ callback: apbct_js_keys__set_input_value }
|
506 |
)
|
507 |
}
|
508 |
-
},". $timeout .")
|
509 |
});
|
510 |
</script>";
|
511 |
} else {
|
@@ -518,7 +532,7 @@ function apbct_hook__wp_footer() {
|
|
518 |
{ callback: apbct_js_keys__set_input_value, apbct_ajax: 1 }
|
519 |
);
|
520 |
}
|
521 |
-
},". $timeout .")
|
522 |
});
|
523 |
</script>";
|
524 |
}
|
@@ -529,15 +543,29 @@ function apbct_hook__wp_footer() {
|
|
529 |
}
|
530 |
|
531 |
/**
|
532 |
-
* Adds hidden filed to define
|
533 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
534 |
*/
|
535 |
function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false, $cookie_check = false, $no_print = false, $ajax = true) {
|
536 |
|
|
|
|
|
|
|
|
|
|
|
537 |
global $ct_checkjs_def, $apbct;
|
538 |
|
539 |
$ct_checkjs_key = ct_get_checkjs_value();
|
540 |
-
$field_id_hash = md5(rand(0, 1000));
|
541 |
|
542 |
// Using only cookies
|
543 |
if ($cookie_check && $apbct->settings['data__set_cookies'] ) {
|
@@ -555,8 +583,9 @@ function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false
|
|
555 |
}elseif($apbct->settings['data__use_ajax'] && $ajax){
|
556 |
|
557 |
// Fix only for wp_footer -> apbct_hook__wp_head__set_cookie__ct_checkjs()
|
558 |
-
if($no_print)
|
559 |
return;
|
|
|
560 |
|
561 |
$field_id = $field_name . '_' . $field_id_hash;
|
562 |
$html = "<input type=\"hidden\" id=\"{$field_id}\" name=\"{$field_name}\" value=\"{$ct_checkjs_def}\" />";
|
@@ -564,8 +593,9 @@ function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false
|
|
564 |
// Set KEY from backend
|
565 |
}else{
|
566 |
// Fix only for wp_footer -> apbct_hook__wp_head__set_cookie__ct_checkjs()
|
567 |
-
if($no_print)
|
568 |
return;
|
|
|
569 |
|
570 |
$ct_input_challenge = sprintf("'%s'", $ct_checkjs_key);
|
571 |
$field_id = $field_name . '_' . $field_id_hash;
|
@@ -598,7 +628,7 @@ function ct_add_hidden_fields($field_name = 'ct_checkjs', $return_string = false
|
|
598 |
* @param int $comment_ID Comment id
|
599 |
* @return bool flag
|
600 |
*/
|
601 |
-
function apbct_comment__Wordpress__doNotify($
|
602 |
return true;
|
603 |
}
|
604 |
|
@@ -610,7 +640,7 @@ function apbct_comment__Wordpress__doNotify($maybe_notify, $comment_ID){
|
|
610 |
*
|
611 |
* @return string
|
612 |
*/
|
613 |
-
function apbct_comment__Wordpress__changeMailNotificationGroups($notify_message, $
|
614 |
return $notify_message
|
615 |
.PHP_EOL
|
616 |
.'---'.PHP_EOL
|
@@ -624,9 +654,9 @@ function apbct_comment__Wordpress__changeMailNotificationGroups($notify_message,
|
|
624 |
* @param integer $comment_id
|
625 |
*
|
626 |
* @return array
|
627 |
-
* @global
|
628 |
*/
|
629 |
-
function apbct_comment__Wordpress__changeMailNotificationRecipients($emails, $
|
630 |
global $apbct;
|
631 |
return array_unique(array_merge($emails, (array)json_decode($apbct->comment_notification_recipients, true)));
|
632 |
}
|
@@ -635,33 +665,31 @@ function apbct_comment__Wordpress__changeMailNotificationRecipients($emails, $co
|
|
635 |
* Changes email notification for spam comment for native Wordpress comment system
|
636 |
*
|
637 |
* @param string $notify_message Body of email notification
|
638 |
-
* @param
|
|
|
639 |
* @return string Body for email notification
|
640 |
*/
|
641 |
-
function apbct_comment__Wordpress__changeMailNotification($notify_message, $
|
642 |
|
643 |
global $apbct;
|
644 |
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
: ''
|
657 |
-
)
|
658 |
)
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
return $notify_message;
|
665 |
|
666 |
}
|
667 |
|
@@ -694,11 +722,11 @@ function apbct_comment__wordpress__show_blacklists( $notify_message, $comment_id
|
|
694 |
|
695 |
/**
|
696 |
* Set die page with Cleantalk comment.
|
697 |
-
* @global
|
698 |
-
|
699 |
-
* @param
|
700 |
*/
|
701 |
-
function ct_die($
|
702 |
|
703 |
global $ct_comment, $ct_jp_comments;
|
704 |
|
@@ -746,7 +774,7 @@ function ct_die($comment_id, $comment_status) {
|
|
746 |
|
747 |
/**
|
748 |
* Set die page with Cleantalk comment from parameter.
|
749 |
-
* @param
|
750 |
*/
|
751 |
function ct_die_extended($comment_body) {
|
752 |
|
@@ -793,8 +821,8 @@ function ct_die_extended($comment_body) {
|
|
793 |
* Validates JavaScript anti-spam test
|
794 |
*
|
795 |
* @param string $field_name filed to serach in data
|
796 |
-
* @param array|null
|
797 |
-
* @param bool
|
798 |
*
|
799 |
* @return int|null
|
800 |
*/
|
@@ -806,11 +834,11 @@ function apbct_js_test($field_name = 'ct_checkjs', $data = null, $is_cookie = fa
|
|
806 |
|
807 |
if(
|
808 |
($data && isset($data[$field_name])) ||
|
809 |
-
($is_cookie && $apbct->settings['data__set_cookies'] == 2 &&
|
810 |
){
|
811 |
|
812 |
$js_key = $is_cookie && $apbct->settings['data__set_cookies'] == 2
|
813 |
-
?
|
814 |
: trim($data[$field_name]);
|
815 |
|
816 |
// Check static key
|
@@ -835,14 +863,17 @@ function apbct_js_test($field_name = 'ct_checkjs', $data = null, $is_cookie = fa
|
|
835 |
|
836 |
/**
|
837 |
* Get post url
|
838 |
-
*
|
|
|
839 |
* @param int $comment_post_id
|
840 |
-
*
|
|
|
841 |
*/
|
842 |
function ct_post_url( $comment_id, $comment_post_id ){
|
843 |
|
844 |
-
if (empty($comment_post_id))
|
845 |
-
|
|
|
846 |
|
847 |
if ($comment_id === null) {
|
848 |
$last_comment = get_comments('number=1');
|
@@ -851,8 +882,9 @@ function ct_post_url( $comment_id, $comment_post_id ){
|
|
851 |
$permalink = get_permalink($comment_post_id);
|
852 |
|
853 |
$post_url = null;
|
854 |
-
if ($permalink !== null)
|
855 |
-
|
|
|
856 |
|
857 |
return $post_url;
|
858 |
}
|
@@ -866,21 +898,24 @@ function ct_set_not_approved() {
|
|
866 |
}
|
867 |
|
868 |
/**
|
869 |
-
* @author Artem Leontiev
|
870 |
* Public filter 'pre_comment_approved' - Mark comment approved if it's not 'spam' only
|
871 |
-
*
|
|
|
|
|
|
|
|
|
872 |
*/
|
873 |
-
function ct_set_approved($approved, $
|
874 |
-
if ($approved
|
875 |
return $approved;
|
876 |
-
} else {
|
877 |
-
return 1;
|
878 |
}
|
|
|
|
|
879 |
}
|
880 |
|
881 |
/**
|
882 |
* Public filter 'pre_comment_approved' - Mark comment unapproved always
|
883 |
-
* @return
|
884 |
*/
|
885 |
function ct_set_comment_spam() {
|
886 |
return 'spam';
|
@@ -896,12 +931,10 @@ function ct_set_meta($comment_id, $comment_status) {
|
|
896 |
$hash1 = ct_hash();
|
897 |
if (!empty($hash1)) {
|
898 |
update_comment_meta($comment_id, 'ct_hash', $hash1);
|
899 |
-
if (function_exists('base64_encode') && isset($comment_status) && $comment_status
|
900 |
$post_url = ct_post_url($comment_id, $comment_post_id);
|
901 |
$post_url = base64_encode($post_url);
|
902 |
-
|
903 |
-
return false;
|
904 |
-
// 01 - URL to approved comment
|
905 |
$feedback_request = $hash1 . ':' . '01' . ':' . $post_url . ';';
|
906 |
ct_send_feedback($feedback_request);
|
907 |
}
|
@@ -914,8 +947,10 @@ function ct_set_meta($comment_id, $comment_status) {
|
|
914 |
* @global string $ct_stop_words
|
915 |
* @param int $comment_id
|
916 |
* @param int $comment_status Not use
|
|
|
|
|
917 |
*/
|
918 |
-
function ct_mark_red($comment_id, $
|
919 |
global $ct_stop_words;
|
920 |
|
921 |
$comment = get_comment($comment_id, 'ARRAY_A');
|
@@ -932,7 +967,7 @@ function ct_mark_red($comment_id, $comment_status) {
|
|
932 |
//
|
933 |
//Send post to trash
|
934 |
//
|
935 |
-
function ct_wp_trash_comment($comment_id, $
|
936 |
wp_trash_comment($comment_id);
|
937 |
}
|
938 |
|
@@ -941,43 +976,29 @@ function ct_wp_trash_comment($comment_id, $comment_status){
|
|
941 |
* @return bool
|
942 |
*/
|
943 |
function ct_plugin_active($plugin_name){
|
944 |
-
foreach (get_option('active_plugins') as $
|
945 |
-
if ($plugin_name == $v)
|
946 |
return true;
|
|
|
947 |
}
|
948 |
return false;
|
949 |
}
|
950 |
|
951 |
-
|
952 |
-
|
|
|
953 |
function apbct_login__scripts(){
|
|
|
954 |
global $apbct;
|
955 |
|
956 |
-
|
957 |
-
wp_enqueue_script( 'ct_public', APBCT_URL_PATH . '/js/apbct-public.min.js', array( 'jquery' ), APBCT_VERSION, false /*in header*/ );
|
958 |
-
wp_enqueue_script('cleantalk-modal', plugins_url( '/cleantalk-spam-protect/js/cleantalk-modal.min.js' ), array(), APBCT_VERSION, false );
|
959 |
-
|
960 |
-
wp_localize_script('ct_public', 'ctPublic', array(
|
961 |
-
'_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
|
962 |
-
'_rest_nonce' => wp_create_nonce('wp_rest'),
|
963 |
-
'_ajax_url' => admin_url('admin-ajax.php', 'relative'),
|
964 |
-
'_rest_url' => esc_url( get_rest_url() ),
|
965 |
-
'_apbct_ajax_url' => APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php',
|
966 |
-
'pixel__setting' => $apbct->settings['data__pixel'],
|
967 |
-
'pixel__enabled' => $apbct->settings['data__pixel'] === '2' ||
|
968 |
-
( $apbct->settings['data__pixel'] === '3' && apbct_is_cache_plugins_exists() ),
|
969 |
-
'pixel__url' => $apbct->pixel_url,
|
970 |
-
'data__set_cookies' => $apbct->settings['data__set_cookies'],
|
971 |
-
'data__set_cookies__alt_sessions_type' => $apbct->settings['data__set_cookies__alt_sessions_type'],
|
972 |
-
'data__email_check_before_post' =>$apbct->settings['data__email_check_before_post'],
|
973 |
-
));
|
974 |
|
975 |
$apbct->public_script_loaded = true;
|
976 |
}
|
977 |
|
978 |
/**
|
979 |
* Inner function - Finds and returns pattern in string
|
980 |
-
* @return
|
981 |
*/
|
982 |
function ct_get_data_from_submit($value = null, $field_name = null) {
|
983 |
if (!$value || !$field_name || !is_string($value)) {
|
@@ -986,6 +1007,7 @@ function ct_get_data_from_submit($value = null, $field_name = null) {
|
|
986 |
if (preg_match("/[a-z0-9_\-]*" . $field_name. "[a-z0-9_\-]*$/", $value)) {
|
987 |
return true;
|
988 |
}
|
|
|
989 |
}
|
990 |
|
991 |
/**
|
@@ -1045,8 +1067,9 @@ function ct_print_form( $arr, $k ){
|
|
1045 |
|
1046 |
/**
|
1047 |
* Attaches public scripts and styles.
|
|
|
1048 |
*/
|
1049 |
-
function ct_enqueue_scripts_public($
|
1050 |
|
1051 |
global $current_user, $apbct;
|
1052 |
|
@@ -1068,24 +1091,8 @@ function ct_enqueue_scripts_public($hook){
|
|
1068 |
|
1069 |
if( ! $apbct->public_script_loaded ) {
|
1070 |
|
1071 |
-
|
1072 |
-
|
1073 |
-
wp_enqueue_script('cleantalk-modal', plugins_url( '/cleantalk-spam-protect/js/cleantalk-modal.min.js' ), array(), APBCT_VERSION, false );
|
1074 |
-
|
1075 |
-
wp_localize_script('ct_public', 'ctPublic', array(
|
1076 |
-
'_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
|
1077 |
-
'_rest_nonce' => wp_create_nonce('wp_rest'),
|
1078 |
-
'_ajax_url' => admin_url('admin-ajax.php', 'relative'),
|
1079 |
-
'_rest_url' => esc_url( get_rest_url() ),
|
1080 |
-
'_apbct_ajax_url' => APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php',
|
1081 |
-
'data__set_cookies' => $apbct->settings['data__set_cookies'],
|
1082 |
-
'data__set_cookies__alt_sessions_type' => $apbct->settings['data__set_cookies__alt_sessions_type'],
|
1083 |
-
'pixel__setting' => $apbct->settings['data__pixel'],
|
1084 |
-
'pixel__enabled' => $apbct->settings['data__pixel'] === '2' ||
|
1085 |
-
( $apbct->settings['data__pixel'] === '3' && apbct_is_cache_plugins_exists() ),
|
1086 |
-
'pixel__url' => $apbct->pixel_url,
|
1087 |
-
'data__email_check_before_post' =>$apbct->settings['data__email_check_before_post'],
|
1088 |
-
));
|
1089 |
}
|
1090 |
|
1091 |
// ct_nocache
|
@@ -1122,7 +1129,7 @@ function ct_enqueue_scripts_public($hook){
|
|
1122 |
|
1123 |
wp_localize_script('ct_public_gdpr', 'ctPublicGDPR', array(
|
1124 |
'gdpr_forms' => array(),
|
1125 |
-
'gdpr_text' => $apbct->settings['gdpr__text']
|
1126 |
));
|
1127 |
}
|
1128 |
|
@@ -1170,6 +1177,35 @@ function ct_enqueue_scripts_public($hook){
|
|
1170 |
}
|
1171 |
}
|
1172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1173 |
/**
|
1174 |
* Reassign callbackback function for the bootom of comment output.
|
1175 |
*/
|
@@ -1189,9 +1225,9 @@ function ct_wp_list_comments_args($options){
|
|
1189 |
}
|
1190 |
|
1191 |
/**
|
1192 |
-
* Callback function for the
|
1193 |
*/
|
1194 |
-
function ct_comments_output($curr_comment, $
|
1195 |
|
1196 |
global $apbct;
|
1197 |
|
@@ -1210,23 +1246,27 @@ function ct_comments_output($curr_comment, $param2, $wp_list_comments_args){
|
|
1210 |
." <a href='{$settings_link}' target='_blank'>CleanTalk</a>"
|
1211 |
."</p></div>";
|
1212 |
// Outputs email if exists
|
1213 |
-
if($email)
|
1214 |
echo "<a href='https://cleantalk.org/blacklists/$email' target='_blank' title='https://cleantalk.org/blacklists/$email'>"
|
1215 |
-
|
1216 |
-
|
1217 |
-
|
1218 |
-
|
1219 |
-
|
|
|
|
|
1220 |
echo " | ";
|
1221 |
|
1222 |
// Outputs IP if exists
|
1223 |
-
if($ip)
|
1224 |
echo "<a href='https://cleantalk.org/blacklists/$ip' target='_blank' title='https://cleantalk.org/blacklists/$ip'>"
|
1225 |
-
|
1226 |
-
|
1227 |
-
|
1228 |
-
|
1229 |
-
|
|
|
|
|
1230 |
echo ' | ';
|
1231 |
|
1232 |
echo "<span commentid='$id' class='ct_this_is ct_this_is_spam' href='#'>".__('Mark as spam', 'cleantalk-spam-protect')."</span>";
|
@@ -1250,7 +1290,7 @@ function ct_comments_output($curr_comment, $param2, $wp_list_comments_args){
|
|
1250 |
}
|
1251 |
|
1252 |
/**
|
1253 |
-
* Callback function for the
|
1254 |
*
|
1255 |
* attrs = array()
|
1256 |
*/
|
@@ -1258,12 +1298,13 @@ function apbct_shrotcode_handler__GDPR_public_notice__form( $attrs ){
|
|
1258 |
|
1259 |
$out = '';
|
1260 |
|
1261 |
-
if(isset($attrs['id']))
|
1262 |
-
$out .= 'ctPublicGDPR.gdpr_forms.push("'
|
|
|
1263 |
|
1264 |
-
if(isset($attrs['text']))
|
1265 |
-
$out .= 'ctPublicGDPR.gdpr_text = "'
|
|
|
1266 |
|
1267 |
-
|
1268 |
-
return $out;
|
1269 |
}
|
1 |
<?php
|
2 |
|
3 |
+
use Cleantalk\ApbctWP\Variables\Cookie;
|
4 |
+
use Cleantalk\Common\Helper;
|
5 |
|
6 |
/**
|
7 |
* Init functions
|
8 |
+
*
|
9 |
+
* @throws Exception
|
10 |
+
* @psalm-suppress UnusedVariable
|
11 |
*/
|
12 |
function apbct_init() {
|
13 |
|
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();
|
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"' : '' ) . ">
|
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 |
{
|
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')){
|
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 |
|
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 |
}
|
189 |
|
190 |
}
|
191 |
|
192 |
+
// WP Maintenance Mode (wpms)
|
193 |
add_action('wpmm_head', 'apbct_form__wpmm__addField', 1);
|
194 |
|
195 |
// Contact Form7
|
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);
|
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 |
|
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);
|
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
|
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 |
}
|
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(){
|
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();
|
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)));
|
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 |
|
486 |
|
487 |
/**
|
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' ||
|
519 |
{ callback: apbct_js_keys__set_input_value }
|
520 |
)
|
521 |
}
|
522 |
+
},". $timeout . ")
|
523 |
});
|
524 |
</script>";
|
525 |
} else {
|
532 |
{ callback: apbct_js_keys__set_input_value, apbct_ajax: 1 }
|
533 |
);
|
534 |
}
|
535 |
+
},". $timeout . ")
|
536 |
});
|
537 |
</script>";
|
538 |
}
|
543 |
}
|
544 |
|
545 |
/**
|
546 |
+
* Adds hidden filed to define availability of client's JavaScript
|
547 |
+
*
|
548 |
+
* @param string $field_name
|
549 |
+
* @param bool $return_string
|
550 |
+
* @param bool $cookie_check
|
551 |
+
* @param bool $no_print
|
552 |
+
* @param bool $ajax
|
553 |
+
*
|
554 |
+
* @return array|false|string|string[]|void
|
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'] ) {
|
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}\" />";
|
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;
|
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 |
|
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
|
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 |
}
|
665 |
* Changes email notification for spam comment for native Wordpress comment system
|
666 |
*
|
667 |
* @param string $notify_message Body of email notification
|
668 |
+
* @param $_comment_id
|
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 |
|
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 |
|
774 |
|
775 |
/**
|
776 |
* Set die page with Cleantalk comment from parameter.
|
777 |
+
* @param $comment_body
|
778 |
*/
|
779 |
function ct_die_extended($comment_body) {
|
780 |
|
821 |
* Validates JavaScript anti-spam test
|
822 |
*
|
823 |
* @param string $field_name filed to serach in data
|
824 |
+
* @param array|null $data Data to search in
|
825 |
+
* @param bool $is_cookie
|
826 |
*
|
827 |
* @return int|null
|
828 |
*/
|
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
|
863 |
|
864 |
/**
|
865 |
* Get post url
|
866 |
+
*
|
867 |
+
* @param int|null $comment_id
|
868 |
* @param int $comment_post_id
|
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');
|
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;
|
890 |
}
|
898 |
}
|
899 |
|
900 |
/**
|
|
|
901 |
* Public filter 'pre_comment_approved' - Mark comment approved if it's not 'spam' only
|
902 |
+
*
|
903 |
+
* @param $approved
|
904 |
+
* @param $_comment
|
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';
|
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 |
}
|
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');
|
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 |
|
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 |
}
|
998 |
|
999 |
/**
|
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)) {
|
1007 |
if (preg_match("/[a-z0-9_\-]*" . $field_name. "[a-z0-9_\-]*$/", $value)) {
|
1008 |
return true;
|
1009 |
}
|
1010 |
+
return false;
|
1011 |
}
|
1012 |
|
1013 |
/**
|
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 |
|
1091 |
|
1092 |
if( ! $apbct->public_script_loaded ) {
|
1093 |
|
1094 |
+
apbct_enqueue_and_localize_public_scripts();
|
1095 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1096 |
}
|
1097 |
|
1098 |
// ct_nocache
|
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 |
|
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( 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 |
*/
|
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 |
|
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 |
+
. " <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 " | ";
|
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 |
+
. " <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 ' | ';
|
1271 |
|
1272 |
echo "<span commentid='$id' class='ct_this_is ct_this_is_spam' href='#'>".__('Mark as spam', 'cleantalk-spam-protect')."</span>";
|
1290 |
}
|
1291 |
|
1292 |
/**
|
1293 |
+
* Callback function for the bottom comment output.
|
1294 |
*
|
1295 |
* attrs = array()
|
1296 |
*/
|
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 |
}
|
@@ -328,8 +328,8 @@ function apbct_settings__set_fileds( ){
|
|
328 |
'class' => 'apbct_settings-field_wrapper--sub',
|
329 |
'input_type' => 'radio',
|
330 |
'options' => array(
|
331 |
-
array( 'val' =>
|
332 |
-
array( 'val' =>
|
333 |
),
|
334 |
'parent' => 'data__set_cookies',
|
335 |
'disabled' => $apbct->settings['data__set_cookies'] != 2,
|
@@ -466,7 +466,7 @@ function apbct_settings__set_fileds( ){
|
|
466 |
'misc__store_urls' => array(
|
467 |
'type' => 'checkbox',
|
468 |
'title' => __('Store visited URLs', 'cleantalk-spam-protect'),
|
469 |
-
'description' => __("Plugin stores last
|
470 |
),
|
471 |
'wp__comment_notify' => array(
|
472 |
'type' => 'checkbox',
|
@@ -869,6 +869,11 @@ function apbct_settings__error__output($return = false){
|
|
869 |
if(is_array(current($error))){
|
870 |
|
871 |
foreach($error as $sub_type => $sub_error){
|
|
|
|
|
|
|
|
|
|
|
872 |
$errors_out[$sub_type] = '';
|
873 |
if(isset($sub_error['error_time']))
|
874 |
$errors_out[$sub_type] .= date('Y-m-d H:i:s', $sub_error['error_time']) . ': ';
|
@@ -877,12 +882,25 @@ function apbct_settings__error__output($return = false){
|
|
877 |
}
|
878 |
continue;
|
879 |
}
|
880 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
881 |
continue;
|
882 |
-
}
|
|
|
|
|
|
|
|
|
|
|
883 |
$errors_out[$type] = '';
|
884 |
-
|
|
|
885 |
$errors_out[$type] .= date('Y-m-d H:i:s', $error['error_time']) . ': ';
|
|
|
886 |
$errors_out[$type] .= (isset($error_texts[$type]) ? $error_texts[$type] : $error_texts['unknown']) . ' ' . (isset($error['error']) ? $error['error'] : '');
|
887 |
|
888 |
}
|
@@ -1302,7 +1320,7 @@ function apbct_settings__field__draw($params = array()){
|
|
1302 |
|
1303 |
// Radio type
|
1304 |
case 'radio':
|
1305 |
-
|
1306 |
// Title
|
1307 |
echo isset($params['title'])
|
1308 |
? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
|
@@ -1442,8 +1460,12 @@ function apbct_settings__validate($settings) {
|
|
1442 |
global $apbct;
|
1443 |
|
1444 |
// If user is not allowed to manage settings. Get settings from the storage
|
1445 |
-
if( ! is_main_site() &&
|
1446 |
foreach ($apbct->settings as $key => $setting){
|
|
|
|
|
|
|
|
|
1447 |
$settings[ $key ] = $setting;
|
1448 |
}
|
1449 |
}
|
328 |
'class' => 'apbct_settings-field_wrapper--sub',
|
329 |
'input_type' => 'radio',
|
330 |
'options' => array(
|
331 |
+
array( 'val' => 0, 'label' => __( 'Use REST API', 'cleantalk-spam-protect' ), ),
|
332 |
+
array( 'val' => 1, 'label' => __( 'Use AJAX handler', 'cleantalk-spam-protect' ), ),
|
333 |
),
|
334 |
'parent' => 'data__set_cookies',
|
335 |
'disabled' => $apbct->settings['data__set_cookies'] != 2,
|
466 |
'misc__store_urls' => array(
|
467 |
'type' => 'checkbox',
|
468 |
'title' => __('Store visited URLs', 'cleantalk-spam-protect'),
|
469 |
+
'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'),
|
470 |
),
|
471 |
'wp__comment_notify' => array(
|
472 |
'type' => 'checkbox',
|
869 |
if(is_array(current($error))){
|
870 |
|
871 |
foreach($error as $sub_type => $sub_error){
|
872 |
+
|
873 |
+
if( isset($sub_error['error']) && strpos( $sub_error['error'], 'SFW_IS_DISABLED' ) !== false ){
|
874 |
+
continue;
|
875 |
+
}
|
876 |
+
|
877 |
$errors_out[$sub_type] = '';
|
878 |
if(isset($sub_error['error_time']))
|
879 |
$errors_out[$sub_type] .= date('Y-m-d H:i:s', $sub_error['error_time']) . ': ';
|
882 |
}
|
883 |
continue;
|
884 |
}
|
885 |
+
|
886 |
+
if (
|
887 |
+
! empty($type) &&
|
888 |
+
$apbct->white_label &&
|
889 |
+
!is_main_site() &&
|
890 |
+
in_array( $type, array( 'sfw_update', 'key_invalid', 'account_check') )
|
891 |
+
){
|
892 |
continue;
|
893 |
+
}
|
894 |
+
|
895 |
+
if( isset($error['error']) && strpos( $error['error'], 'SFW_IS_DISABLED' ) !== false ){
|
896 |
+
continue;
|
897 |
+
}
|
898 |
+
|
899 |
$errors_out[$type] = '';
|
900 |
+
|
901 |
+
if( isset( $error['error_time'] ) )
|
902 |
$errors_out[$type] .= date('Y-m-d H:i:s', $error['error_time']) . ': ';
|
903 |
+
|
904 |
$errors_out[$type] .= (isset($error_texts[$type]) ? $error_texts[$type] : $error_texts['unknown']) . ' ' . (isset($error['error']) ? $error['error'] : '');
|
905 |
|
906 |
}
|
1320 |
|
1321 |
// Radio type
|
1322 |
case 'radio':
|
1323 |
+
|
1324 |
// Title
|
1325 |
echo isset($params['title'])
|
1326 |
? '<h4 class="apbct_settings-field_title apbct_settings-field_title--'.$params['type'].'">'.$params['title'].'</h4>'
|
1460 |
global $apbct;
|
1461 |
|
1462 |
// If user is not allowed to manage settings. Get settings from the storage
|
1463 |
+
if( ! is_main_site() && ! $apbct->network_settings['multisite__allow_custom_settings'] ){
|
1464 |
foreach ($apbct->settings as $key => $setting){
|
1465 |
+
// Do not reset apikey to default is allow_custom_key is active
|
1466 |
+
if( $key === 'apikey' && $apbct->allow_custom_key ) {
|
1467 |
+
continue;
|
1468 |
+
}
|
1469 |
$settings[ $key ] = $setting;
|
1470 |
}
|
1471 |
}
|
@@ -1103,7 +1103,7 @@ function apbct_update_to_5_157_0(){
|
|
1103 |
if( ! empty( $apbct->settings['data__set_cookies__sessions'] ) ){
|
1104 |
$apbct->settings['data__set_cookies'] = 2;
|
1105 |
}
|
1106 |
-
$apbct->settings['data__set_cookies__alt_sessions_type'] =
|
1107 |
|
1108 |
$apbct->save( 'settings' );
|
1109 |
|
@@ -1286,3 +1286,11 @@ function apbct_update_to_5_159_7() {
|
|
1286 |
}
|
1287 |
|
1288 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1103 |
if( ! empty( $apbct->settings['data__set_cookies__sessions'] ) ){
|
1104 |
$apbct->settings['data__set_cookies'] = 2;
|
1105 |
}
|
1106 |
+
$apbct->settings['data__set_cookies__alt_sessions_type'] = 0;
|
1107 |
|
1108 |
$apbct->save( 'settings' );
|
1109 |
|
1286 |
}
|
1287 |
|
1288 |
}
|
1289 |
+
|
1290 |
+
/**
|
1291 |
+
* @return void
|
1292 |
+
*/
|
1293 |
+
function apbct_update_to_5_159_9() {
|
1294 |
+
$cron = new Cron();
|
1295 |
+
$cron->addTask('rotate_moderate', 'apbct_rotate_moderate', 86400, time() + 3500); // Rotate moderate server
|
1296 |
+
}
|
@@ -0,0 +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||(1==+ctPublicFunctions.data__set_cookies__alt_sessions_type?apbct_public_sendREST("alt_sessions",{method:"POST",data:{cookies:o}}):2==+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/"))}})}
|
2 |
+
//# sourceMappingURL=apbct-public--functions.min.js.map
|
@@ -0,0 +1 @@
|
|
|
1 |
+
{"version":3,"file":"apbct-public--functions.min.js","sources":["apbct-public--functions.js"],"sourcesContent":["function ctSetCookie( cookies, value, expires ){\n\n if( typeof cookies === 'string' && typeof value === 'string' || typeof value === 'number'){\n var skip_alt = cookies === 'ct_pointer_data' || cookies === 'ct_user_info';\n cookies = [ [ cookies, value, expires ] ];\n }\n\n // Cookies disabled\n if( +ctPublicFunctions.data__set_cookies === 0 ){\n return;\n\n // Using traditional cookies\n }else if( +ctPublicFunctions.data__set_cookies === 1 ){\n cookies.forEach( function (item, i, arr\t) {\n var expires = typeof item[2] !== 'undefined' ? \"expires=\" + expires + '; ' : '';\n var ctSecure = location.protocol === 'https:' ? '; secure' : '';\n document.cookie = item[0] + \"=\" + encodeURIComponent(item[1]) + \"; \" + expires + \"path=/; samesite=lax\" + ctSecure;\n });\n\n // Using alternative cookies\n }else if( +ctPublicFunctions.data__set_cookies === 2 && ! skip_alt ){\n\n // Using REST API handler\n if( +ctPublicFunctions.data__set_cookies__alt_sessions_type === 1 ){\n apbct_public_sendREST(\n 'alt_sessions',\n {\n method: 'POST',\n data: { cookies: cookies }\n }\n );\n\n // Using AJAX request and handler\n }else if( +ctPublicFunctions.data__set_cookies__alt_sessions_type === 2 ) {\n apbct_public_sendAJAX(\n {\n action: 'apbct_alt_session__save__AJAX',\n cookies: cookies,\n },\n {\n apbct_ajax: 1,\n notJson: 1,\n }\n );\n }\n }\n}\n\nfunction apbct_public_sendAJAX(data, params, obj){\n\n // Default params\n var callback = params.callback || null;\n var callback_context = params.callback_context || null;\n var callback_params = params.callback_params || null;\n var async = params.async || true;\n var notJson = params.notJson || null;\n var timeout = params.timeout || 15000;\n var obj = obj || null;\n var button = params.button || null;\n var spinner = params.spinner || null;\n var progressbar = params.progressbar || null;\n var silent = params.silent || null;\n var no_nonce = params.no_nonce || null;\n var apbct_ajax = params.apbct_ajax || null;\n\n if(typeof (data) === 'string') {\n if( ! no_nonce )\n data = data + '&_ajax_nonce=' + ctPublicFunctions._ajax_nonce;\n data = data + '&no_cache=' + Math.random()\n } else {\n if( ! no_nonce )\n data._ajax_nonce = ctPublicFunctions._ajax_nonce;\n data.no_cache = Math.random();\n }\n // Button and spinner\n if(button) {button.setAttribute('disabled', 'disabled'); button.style.cursor = 'not-allowed'; }\n if(spinner) jQuery(spinner).css('display', 'inline');\n\n jQuery.ajax({\n type: \"POST\",\n url: apbct_ajax ? ctPublicFunctions._apbct_ajax_url : ctPublicFunctions._ajax_url,\n data: data,\n async: async,\n success: function(result){\n if(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n if(spinner) jQuery(spinner).css('display', 'none');\n if(!notJson) result = JSON.parse(result);\n if(result.error){\n setTimeout(function(){ if(progressbar) progressbar.fadeOut('slow'); }, 1000);\n console.log('Error happens: ' + (result.error || 'Unkown'));\n }else{\n if(callback) {\n if (callback_params)\n callback.apply( callback_context, callback_params.concat( result, data, params, obj ) );\n else\n callback(result, data, params, obj);\n }\n }\n },\n error: function(jqXHR, textStatus, errorThrown){\n if(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n if(spinner) jQuery(spinner).css('display', 'none');\n if( errorThrown && ! silent ) {\n console.log('APBCT_AJAX_ERROR');\n console.log(jqXHR);\n console.log(textStatus);\n console.log('Anti-spam by Cleantalk plugin error: ' + errorThrown + 'Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n }\n },\n timeout: timeout,\n });\n}\n\nfunction apbct_public_sendREST( route, params ) {\n\n var callback = params.callback || null;\n var data = params.data || [];\n var method = params.method || 'POST';\n\n jQuery.ajax({\n type: method,\n url: ctPublicFunctions._rest_url + 'cleantalk-antispam/v1/' + route,\n data: data,\n beforeSend : function ( xhr ) {\n xhr.setRequestHeader( 'X-WP-Nonce', ctPublicFunctions._rest_nonce );\n },\n success: function(result){\n if(result.error){\n console.log('Error happens: ' + (result.error || 'Unknown'));\n }else{\n if(callback) {\n var obj = null;\n callback(result, route, params, obj);\n }\n }\n },\n error: function(jqXHR, textStatus, errorThrown){\n if( errorThrown ) {\n console.log('APBCT_REST_ERROR');\n console.log(jqXHR);\n console.log(textStatus);\n console.log('Anti-spam by Cleantalk plugin REST API error: ' + errorThrown + ' Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n }\n },\n });\n\n}\n"],"names":["ctSetCookie","cookies","value","expires","skip_alt","ctPublicFunctions","data__set_cookies","forEach","item","i","arr","ctSecure","location","protocol","document","cookie","encodeURIComponent","data__set_cookies__alt_sessions_type","apbct_public_sendREST","method","data","apbct_public_sendAJAX","action","apbct_ajax","notJson","params","obj","callback","callback_context","callback_params","async","timeout","button","spinner","progressbar","silent","no_nonce","_ajax_nonce","Math","random","no_cache","setAttribute","style","cursor","jQuery","css","ajax","type","url","_apbct_ajax_url","_ajax_url","success","result","removeAttribute","JSON","parse","error","setTimeout","fadeOut","console","log","apply","concat","jqXHR","textStatus","errorThrown","route","_rest_url","beforeSend","xhr","setRequestHeader","_rest_nonce"],"mappings":"AAAA,SAASA,YAAaC,EAASC,EAAOC,GAElC,IACQC,GADe,iBAAZH,GAAyC,iBAAVC,GAAuC,iBAAVA,KAC/DE,EAAuB,oBAAZH,GAA6C,iBAAZA,EAChDA,EAAU,CAAE,CAAEA,EAASC,EAAOC,KAIW,IAAxCE,kBAAkBC,oBAI4B,IAAxCD,kBAAkBC,kBACzBL,EAAQM,QAAS,SAAUC,EAAMC,EAAGC,GAChC,IAAIP,OAA6B,IAAZK,EAAK,GAAqB,WAAaL,EAAU,KAAO,GACzEQ,EAAiC,WAAtBC,SAASC,SAAwB,WAAa,GAC7DC,SAASC,OAASP,EAAK,GAAK,IAAMQ,mBAAmBR,EAAK,IAAM,KAAOL,EAAU,uBAAyBQ,IAI/D,IAAxCN,kBAAkBC,mBAA6BF,IAGU,IAA3DC,kBAAkBY,qCACnBC,sBACI,eACA,CACIC,OAAQ,OACRC,KAAM,CAAEnB,QAASA,KAKyC,IAA3DI,kBAAkBY,sCACzBI,sBACI,CACIC,OAAQ,gCACRrB,QAASA,GAEb,CACIsB,WAAY,EACZC,QAAS,MAO7B,SAASH,sBAAsBD,EAAMK,EAAQC,GAGzC,IAAIC,EAAcF,EAAOE,UAAe,KACpCC,EAAmBH,EAAOG,kBAAoB,KAC9CC,EAAkBJ,EAAOI,iBAAmB,KAC5CC,EAAQL,EAAOK,QAAS,EACxBN,EAAcC,EAAOD,SAAe,KACpCO,EAAcN,EAAOM,SAAe,KACpCL,EAAcA,GAAsB,KACpCM,EAAcP,EAAOO,QAAe,KACpCC,EAAcR,EAAOQ,SAAe,KACpCC,EAAcT,EAAOS,aAAe,KACpCC,EAAcV,EAAOU,QAAe,KACpCC,EAAcX,EAAOW,UAAe,KACpCb,EAAcE,EAAOF,YAAe,KAEnB,iBAAX,GACAa,IACFhB,EAAOA,EAAO,gBAAkBf,kBAAkBgC,aACtDjB,EAAOA,EAAO,aAAekB,KAAKC,WAE5BH,IACFhB,EAAKiB,YAAchC,kBAAkBgC,aACzCjB,EAAKoB,SAAWF,KAAKC,UAGtBP,IAAUA,EAAOS,aAAa,WAAY,YAAaT,EAAOU,MAAMC,OAAS,eAC7EV,GAASW,OAAOX,GAASY,IAAI,UAAW,UAE3CD,OAAOE,KAAK,CACRC,KAAM,OACNC,IAAKzB,EAAalB,kBAAkB4C,gBAAkB5C,kBAAkB6C,UACxE9B,KAAMA,EACNU,MAAOA,EACPqB,QAAS,SAASC,GACXpB,IAAUA,EAAOqB,gBAAgB,YAAarB,EAAOU,MAAMC,OAAS,WACpEV,GAAUW,OAAOX,GAASY,IAAI,UAAW,QACxCrB,IAAS4B,EAASE,KAAKC,MAAMH,IAC9BA,EAAOI,OACNC,WAAW,WAAevB,GAAaA,EAAYwB,QAAQ,SAAY,KACvEC,QAAQC,IAAI,mBAAqBR,EAAOI,OAAS,YAE9C7B,IACKE,EACAF,EAASkC,MAAOjC,EAAkBC,EAAgBiC,OAAQV,EAAQhC,EAAMK,EAAQC,IAEhFC,EAASyB,EAAQhC,EAAMK,EAAQC,KAI/C8B,MAAO,SAASO,EAAOC,EAAYC,GAC5BjC,IAAUA,EAAOqB,gBAAgB,YAAarB,EAAOU,MAAMC,OAAS,WACpEV,GAASW,OAAOX,GAASY,IAAI,UAAW,QACvCoB,IAAiB9B,IACjBwB,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,wCAA0CK,EAAc,yGAG5ElC,QAASA,IAIjB,SAASb,sBAAuBgD,EAAOzC,GAEnC,IAAIE,EAAWF,EAAOE,UAAY,KAC9BP,EAAWK,EAAOL,MAAQ,GAC1BD,EAAWM,EAAON,QAAU,OAEhCyB,OAAOE,KAAK,CACRC,KAAM5B,EACN6B,IAAK3C,kBAAkB8D,UAAY,yBAA2BD,EAC9D9C,KAAMA,EACNgD,WAAa,SAAWC,GACpBA,EAAIC,iBAAkB,aAAcjE,kBAAkBkE,cAE1DpB,QAAS,SAASC,GACXA,EAAOI,MACNG,QAAQC,IAAI,mBAAqBR,EAAOI,OAAS,YAE9C7B,GAECA,EAASyB,EAAQc,EAAOzC,EADd,OAKtB+B,MAAO,SAASO,EAAOC,EAAYC,GAC3BA,IACAN,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,iDAAmDK,EAAc"}
|
@@ -1,2 +1,2 @@
|
|
1 |
-
function
|
2 |
//# sourceMappingURL=apbct-public.min.js.map
|
1 |
+
function apbct_collect_visible_fields(e){var t=[],n="",o=0,c="",l=0,i=[];for(var a in e.elements)isNaN(+a)||(t[a]=e.elements[a]);return(t=t.filter(function(e){return-1===i.indexOf(e.getAttribute("name"))&&(-1===["radio","checkbox"].indexOf(e.getAttribute("type"))||(i.push(e.getAttribute("name")),!1))})).forEach(function(e,t,i){"submit"!==e.getAttribute("type")&&null!==e.getAttribute("name")&&"ct_checkjs"!==e.getAttribute("name")&&("none"!==getComputedStyle(e).display&&"hidden"!==getComputedStyle(e).visibility&&"0"!==getComputedStyle(e).opacity&&"hidden"!==e.getAttribute("type")||e.classList.contains("wp-editor-area")?(n+=" "+e.getAttribute("name"),o++):(c+=" "+e.getAttribute("name"),l++))}),c=c.trim(),{visible_fields:n=n.trim(),visible_fields_count:o,invisible_fields:c,invisible_fields_count:l}}function apbct_visible_fields_set_cookie(e){var t="object"==typeof e&&null!==e?e:{};ctSetCookie("apbct_visible_fields",JSON.stringify(t))}function apbct_js_keys__set_input_value(e,t,i,n){if(0<document.querySelectorAll("[name^=ct_checkjs]").length)for(var o=document.querySelectorAll("[name^=ct_checkjs]"),c=0;c<o.length;c++)o[c].value=e.js_key}function apbctGetScreenInfo(){return JSON.stringify({fullWidth:document.documentElement.scrollWidth,fullHeight:Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight),visibleWidth:document.documentElement.clientWidth,visibleHeight:document.documentElement.clientHeight})}!function(){var e=new Date,t=(new Date).getTime(),i=!0,n=[],o=0,c={},l=!1;function a(e,t,i){"function"==typeof window.addEventListener?e.addEventListener(t,i):e.attachEvent(t,i)}function s(e,t,i){"function"==typeof window.removeEventListener?e.removeEventListener(t,i):e.detachEvent(t,i)}ctSetCookie([["ct_ps_timestamp",Math.floor((new Date).getTime()/1e3)],["ct_fkp_timestamp","0"],["ct_pointer_data","0"],["ct_timezone",e.getTimezoneOffset()/60*-1],["apbct_visible_fields","0"]]);var r=function(){var e=Math.floor((new Date).getTime()/1e3);ctSetCookie("ct_fkp_timestamp",e),s(window,"mousedown",r),s(window,"keydown",r)},u=setInterval(function(){i=!0},150),d=setInterval(function(){ctSetCookie("ct_pointer_data",JSON.stringify(n))},1200),m=function(e){!0===i&&(n.push([Math.round(e.clientY),Math.round(e.clientX),Math.round((new Date).getTime()-t)]),i=!1,50<=++o&&(s(window,"mousemove",m),clearInterval(u),clearInterval(d)))};function _(e){var t=e.target.value;!t||t in c||apbct_public_sendAJAX({action:"apbct_email_check_before_post",data:{email:t}},{apbct_ajax:1,callback:function(e){e.result&&(c[t]={result:e.result,timestamp:Date.now()/1e3|0},ctSetCookie("ct_checked_emails",JSON.stringify(c)))}})}a(window,"mousemove",m),a(window,"mousedown",r),a(window,"keydown",r),a(window,"scroll",function(){l||(ctSetCookie("ct_has_scrolled",JSON.stringify(!0)),l=!0)}),a(window,"DOMContentLoaded",function(){+ctPublic.pixel__setting&&(ctSetCookie("apbct_pixel_url",ctPublic.pixel__url),+ctPublic.pixel__enabled&&jQuery("body").append('<img style="display: none; left: 99999px;" src="'+ctPublic.pixel__url+'">')),+ctPublic.data__email_check_before_post&&(ctSetCookie("ct_checked_emails","0"),jQuery("input[type = 'email'], #email").blur(_)),ctSetCookie("ct_screen_info",apbctGetScreenInfo()),ctSetCookie("ct_has_scrolled",JSON.stringify(!1)),setTimeout(function(){for(var e={},t=0;t<document.forms.length;t++){var i=document.forms[t];i.classList.contains("slp_search_form")||i.parentElement.classList.contains("mec-booking")||-1!==i.action.toString().indexOf("activehosted.com")||i.id&&"caspioform"==i.id||i.name.classList&&i.name.classList.contains("tinkoffPayRow")||i.name.classList&&i.name.classList.contains("give-form")||(e[t]=apbct_collect_visible_fields(i),i.onsubmit_prev=i.onsubmit,i.onsubmit=function(e){var t={};t[0]=apbct_collect_visible_fields(this),apbct_visible_fields_set_cookie(t),e.target.onsubmit_prev instanceof Function&&setTimeout(function(){e.target.onsubmit_prev.call(e.target,e)},500)})}apbct_visible_fields_set_cookie(e)},1e3)})}(),"undefined"!=typeof jQuery&&jQuery(document).ajaxComplete(function(e,t,i){var n;!t.responseText||-1===t.responseText.indexOf('"apbct')||void 0!==(n=JSON.parse(t.responseText)).apbct&&(n=n.apbct).blocked&&(document.dispatchEvent(new CustomEvent("apbctAjaxBockAlert",{bubbles:!0,detail:{message:n.comment}})),cleantalkModal.loaded=n.comment,cleantalkModal.open(),1==+n.stop_script&&window.stop())});
|
2 |
//# sourceMappingURL=apbct-public.min.js.map
|
@@ -1 +1 @@
|
|
1 |
-
{"version":3,"file":"apbct-public.min.js","sources":["apbct-public.js"],"sourcesContent":["(function() {\n\n\tvar ct_date = new Date(),\n\t\tctTimeMs = new Date().getTime(),\n\t\tctMouseEventTimerFlag = true, //Reading interval flag\n\t\tctMouseData = [],\n\t\tctMouseDataCounter = 0,\n\t\tctCheckedEmails = {},\n\t\tctScrollCollected = false;\n\n\tfunction apbct_attach_event_handler(elem, event, callback){\n\t\tif(typeof window.addEventListener === \"function\") elem.addEventListener(event, callback);\n\t\telse elem.attachEvent(event, callback);\n\t}\n\n\tfunction apbct_remove_event_handler(elem, event, callback){\n\t\tif(typeof window.removeEventListener === \"function\") elem.removeEventListener(event, callback);\n\t\telse elem.detachEvent(event, callback);\n\t}\n\n\tctSetCookie(\n\t\t[\n\t\t\t[ \"ct_ps_timestamp\", Math.floor(new Date().getTime() / 1000) ],\n\t\t\t[ \"ct_fkp_timestamp\", \"0\" ],\n\t\t\t[ \"ct_pointer_data\", \"0\" ],\n\t\t\t[ \"ct_timezone\", ct_date.getTimezoneOffset()/60*(-1) ],\n\t\t\t[ \"apbct_visible_fields\", \"0\" ],\n\t\t]\n\t);\n\n\t//Writing first key press timestamp\n\tvar ctFunctionFirstKey = function output(event){\n\t\tvar KeyTimestamp = Math.floor(new Date().getTime()/1000);\n\t\tctSetCookie(\"ct_fkp_timestamp\", KeyTimestamp);\n\t\tctKeyStopStopListening();\n\t};\n\n\t//Reading interval\n\tvar ctMouseReadInterval = setInterval(function(){\n\t\tctMouseEventTimerFlag = true;\n\t}, 150);\n\n\t//Writting interval\n\tvar ctMouseWriteDataInterval = setInterval(function(){\n\t\tctSetCookie(\"ct_pointer_data\", JSON.stringify(ctMouseData));\n\t}, 1200);\n\n\t//Logging mouse position each 150 ms\n\tvar ctFunctionMouseMove = function output(event){\n\t\tif(ctMouseEventTimerFlag === true){\n\n\t\t\tctMouseData.push([\n\t\t\t\tMath.round(event.clientY),\n\t\t\t\tMath.round(event.clientX),\n\t\t\t\tMath.round(new Date().getTime() - ctTimeMs)\n\t\t\t]);\n\n\t\t\tctMouseDataCounter++;\n\t\t\tctMouseEventTimerFlag = false;\n\t\t\tif(ctMouseDataCounter >= 50){\n\t\t\t\tctMouseStopData();\n\t\t\t}\n\t\t}\n\t};\n\n\t//Stop mouse observing function\n\tfunction ctMouseStopData(){\n\t\tapbct_remove_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\t\tclearInterval(ctMouseReadInterval);\n\t\tclearInterval(ctMouseWriteDataInterval);\n\t}\n\n\t//Stop key listening function\n\tfunction ctKeyStopStopListening(){\n\t\tapbct_remove_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\t\tapbct_remove_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\t}\n\n\tfunction checkEmail(e) {\n\t\tvar current_email = e.target.value;\n\t\tif (current_email && !(current_email in ctCheckedEmails)) {\n\t\t\tapbct_public_sendAJAX(\n\t\t\t\t{action: 'apbct_email_check_before_post', data : {'email' : current_email}},\n\t\t\t\t{\n\t\t\t\t\tapbct_ajax: 1,\n\t\t\t\t\tcallback: function (result) {\n\t\t\t\t\t\tif (result.result) {\n\t\t\t\t\t\t\tctCheckedEmails[current_email] = {'result' : result.result, 'timestamp': Date.now() / 1000 |0};\n\t\t\t\t\t\t\tctSetCookie('ct_checked_emails', JSON.stringify(ctCheckedEmails));\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\t\t\n\t\t}\n\t}\n\n\tfunction ctSetHasScrolled() {\n\t\tif( ! ctScrollCollected ) {\n\t\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( true ) );\n\t\t\tctScrollCollected = true;\n\t\t}\n\t}\n\n\tapbct_attach_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\tapbct_attach_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"scroll\", ctSetHasScrolled);\n\n\t// Ready function\n\tfunction apbct_ready(){\n\n\t\tif( +ctPublic.pixel__setting ){\n\t\t\tctSetCookie( 'apbct_pixel_url', ctPublic.pixel__url );\n\t\t\tif( +ctPublic.pixel__enabled ){\n\t\t\t\tjQuery('body').append( '<img style=\"display: none; left: 99999px;\" src=\"' + ctPublic.pixel__url + '\">' );\n\t\t\t}\n\t\t}\n\n\t\tif ( +ctPublic.data__email_check_before_post) {\n\t\t\tctSetCookie( 'ct_checked_emails', '0');\n\t\t\tjQuery(\"input[type = 'email'], #email\").blur(checkEmail);\n\t\t}\n\n\t\t// Collect scrolling info\n\t\tctSetCookie( 'ct_screen_info', apbctGetScreenInfo() );\n\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( false ) );\n\n\t\tsetTimeout(function(){\n\n\t\t\tvar visible_fields_collection = {};\n\n\t\t\tfor(var i = 0; i < document.forms.length; i++){\n\t\t\t\tvar form = document.forms[i];\n\n\t\t\t\t//Exclusion for forms\n\t\t\t\tif (\n\t\t\t\t\tform.classList.contains('slp_search_form') || //StoreLocatorPlus form\n\t\t\t\t\tform.parentElement.classList.contains('mec-booking') ||\n\t\t\t\t\tform.action.toString().indexOf('activehosted.com') !== -1 || // Active Campaign\n\t\t\t\t\t(form.id && form.id == 'caspioform') || //Caspio Form\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('tinkoffPayRow')) || // TinkoffPayForm\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('give-form')) // GiveWP\n\t\t\t\t)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tvisible_fields_collection[i] = apbct_collect_visible_fields( form );\n\n\t\t\t\tform.onsubmit_prev = form.onsubmit;\n\t\t\t\tform.onsubmit = function (event) {\n\n\t\t\t\t\tvar visible_fields = {};\n\t\t\t\t\tvisible_fields[0] = apbct_collect_visible_fields(this);\n\t\t\t\t\tapbct_visible_fields_set_cookie( visible_fields );\n\n\t\t\t\t\t// Call previous submit action\n\t\t\t\t\tif (event.target.onsubmit_prev instanceof Function) {\n\t\t\t\t\t\tsetTimeout(function () {\n\t\t\t\t\t\t\tevent.target.onsubmit_prev.call(event.target, event);\n\t\t\t\t\t\t}, 500);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tapbct_visible_fields_set_cookie( visible_fields_collection );\n\n\t\t}, 1000);\n\t}\n\tapbct_attach_event_handler(window, \"DOMContentLoaded\", apbct_ready);\n\n}());\n\nfunction ctSetCookie( cookies, value, expires ){\n\n\tif( typeof cookies === 'string' && typeof value === 'string' || typeof value === 'number'){\n\t\tvar skip_alt = cookies === 'ct_pointer_data' || cookies === 'ct_user_info';\n\t\tcookies = [ [ cookies, value, expires ] ];\n\t}\n\n\t// Cookies disabled\n\tif( +ctPublic.data__set_cookies === 0 ){\n\t\treturn;\n\n\t// Using traditional cookies\n\t}else if( +ctPublic.data__set_cookies === 1 ){\n\t\tcookies.forEach( function (item, i, arr\t) {\n\t\t\tvar expires = typeof item[2] !== 'undefined' ? \"expires=\" + expires + '; ' : '';\n\t\t\tvar ctSecure = location.protocol === 'https:' ? '; secure' : '';\n\t\t\tdocument.cookie = item[0] + \"=\" + encodeURIComponent(item[1]) + \"; \" + expires + \"path=/; samesite=lax\" + ctSecure;\n\t\t});\n\n\t// Using alternative cookies\n\t}else if( +ctPublic.data__set_cookies === 2 && ! skip_alt ){\n\n\t\t// Using REST API handler\n\t\tif( +ctPublic.data__set_cookies__alt_sessions_type === 1 ){\n\t\t\tapbct_public_sendREST(\n\t\t\t\t'alt_sessions',\n\t\t\t\t{\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: { cookies: cookies }\n\t\t\t\t}\n\t\t\t);\n\n\t\t// Using AJAX request and handler\n\t\t}else if( +ctPublic.data__set_cookies__alt_sessions_type === 2 ) {\n\t\t\tapbct_public_sendAJAX(\n\t\t\t\t{\n\t\t\t\t\taction: 'apbct_alt_session__save__AJAX',\n\t\t\t\t\tcookies: cookies,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tapbct_ajax: 1,\n\t\t\t\t\tnotJson: 1,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction apbct_collect_visible_fields( form ) {\n\n\t// Get only fields\n\tvar inputs = [],\n\t\tinputs_visible = '',\n\t\tinputs_visible_count = 0,\n\t\tinputs_invisible = '',\n\t\tinputs_invisible_count = 0,\n\t\tinputs_with_duplicate_names = [];\n\n\tfor(var key in form.elements){\n\t\tif(!isNaN(+key))\n\t\t\tinputs[key] = form.elements[key];\n\t}\n\n\t// Filter fields\n\tinputs = inputs.filter(function(elem){\n\n\t\t// Filter already added fields\n\t\tif( inputs_with_duplicate_names.indexOf( elem.getAttribute('name') ) !== -1 ){\n\t\t\treturn false;\n\t\t}\n\t\t// Filter inputs with same names for type == radio\n\t\tif( -1 !== ['radio', 'checkbox'].indexOf( elem.getAttribute(\"type\") )){\n\t\t\tinputs_with_duplicate_names.push( elem.getAttribute('name') );\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Visible fields\n\tinputs.forEach(function(elem, i, elements){\n\t\t// Unnecessary fields\n\t\tif(\n\t\t\telem.getAttribute(\"type\") === \"submit\" || // type == submit\n\t\t\telem.getAttribute('name') === null ||\n\t\t\telem.getAttribute('name') === 'ct_checkjs'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\t// Invisible fields\n\t\tif(\n\t\t\tgetComputedStyle(elem).display === \"none\" || // hidden\n\t\t\tgetComputedStyle(elem).visibility === \"hidden\" || // hidden\n\t\t\tgetComputedStyle(elem).opacity === \"0\" || // hidden\n\t\t\telem.getAttribute(\"type\") === \"hidden\" // type == hidden\n\t\t) {\n\t\t\tif( elem.classList.contains(\"wp-editor-area\") ) {\n\t\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_visible_count++;\n\t\t\t} else {\n\t\t\t\tinputs_invisible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_invisible_count++;\n\t\t\t}\n\t\t}\n\t\t// Visible fields\n\t\telse {\n\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\tinputs_visible_count++;\n\t\t}\n\n\t});\n\n\tinputs_invisible = inputs_invisible.trim();\n\tinputs_visible = inputs_visible.trim();\n\n\treturn {\n\t\tvisible_fields : inputs_visible,\n\t\tvisible_fields_count : inputs_visible_count,\n\t\tinvisible_fields : inputs_invisible,\n\t\tinvisible_fields_count : inputs_invisible_count,\n\t}\n\n}\n\nfunction apbct_visible_fields_set_cookie( visible_fields_collection ) {\n\n\tvar collection = typeof visible_fields_collection === 'object' && visible_fields_collection !== null ? visible_fields_collection : {};\n\n\tctSetCookie(\"apbct_visible_fields\", JSON.stringify( collection ) );\n\n}\n\nfunction apbct_js_keys__set_input_value(result, data, params, obj){\n\tif( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {\n\t\tvar elements = document.querySelectorAll('[name^=ct_checkjs]');\n\t\tfor ( var i = 0; i < elements.length; i++ ) {\n\t\t\telements[i].value = result.js_key;\n\t\t}\n\t}\n}\n\nfunction apbct_public_sendAJAX(data, params, obj){\n\n\t// Default params\n\tvar callback = params.callback || null;\n\tvar callback_context = params.callback_context || null;\n\tvar callback_params = params.callback_params || null;\n\tvar async = params.async || true;\n\tvar notJson = params.notJson || null;\n\tvar timeout = params.timeout || 15000;\n\tvar obj = obj || null;\n\tvar button = params.button || null;\n\tvar spinner = params.spinner || null;\n\tvar progressbar = params.progressbar || null;\n\tvar silent = params.silent || null;\n\tvar no_nonce = params.no_nonce || null;\n\tvar apbct_ajax = params.apbct_ajax || null;\n\n\tif(typeof (data) === 'string') {\n\t\tif( ! no_nonce )\n\t\t\tdata = data + '&_ajax_nonce=' + ctPublic._ajax_nonce;\n\t\tdata = data + '&no_cache=' + Math.random()\n\t} else {\n\t\tif( ! no_nonce )\n\t\t\tdata._ajax_nonce = ctPublic._ajax_nonce;\n\t\tdata.no_cache = Math.random();\n\t}\n\t// Button and spinner\n\tif(button) {button.setAttribute('disabled', 'disabled'); button.style.cursor = 'not-allowed'; }\n\tif(spinner) jQuery(spinner).css('display', 'inline');\n\n\tjQuery.ajax({\n\t\ttype: \"POST\",\n\t\turl: apbct_ajax ? ctPublic._apbct_ajax_url : ctPublic._ajax_url,\n\t\tdata: data,\n\t\tasync: async,\n\t\tsuccess: function(result){\n\t\t\tif(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n\t\t\tif(spinner) jQuery(spinner).css('display', 'none');\n\t\t\tif(!notJson) result = JSON.parse(result);\n\t\t\tif(result.error){\n\t\t\t\tsetTimeout(function(){ if(progressbar) progressbar.fadeOut('slow'); }, 1000);\n\t\t\t\tconsole.log('Error happens: ' + (result.error || 'Unkown'));\n\t\t\t}else{\n\t\t\t\tif(callback) {\n\t\t\t\t\tif (callback_params)\n\t\t\t\t\t\tcallback.apply( callback_context, callback_params.concat( result, data, params, obj ) );\n\t\t\t\t\telse\n\t\t\t\t\t\tcallback(result, data, params, obj);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\terror: function(jqXHR, textStatus, errorThrown){\n\t\t\tif(button){ button.removeAttribute('disabled'); button.style.cursor = 'pointer'; }\n\t\t\tif(spinner) jQuery(spinner).css('display', 'none');\n\t\t\tif( errorThrown && ! silent ) {\n\t\t\t\tconsole.log('APBCT_AJAX_ERROR');\n\t\t\t\tconsole.log(jqXHR);\n\t\t\t\tconsole.log(textStatus);\n\t\t\t\tconsole.log('Anti-spam by Cleantalk plugin error: ' + errorThrown + 'Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n\t\t\t}\n\t\t},\n\t\ttimeout: timeout,\n\t});\n}\n\nfunction apbct_public_sendREST( route, params ) {\n\n\tvar callback = params.callback || null;\n\tvar data = params.data || [];\n\tvar method = params.method || 'POST';\n\n\tjQuery.ajax({\n\t\ttype: method,\n\t\turl: ctPublic._rest_url + 'cleantalk-antispam/v1/' + route,\n\t\tdata: data,\n\t\tbeforeSend : function ( xhr ) {\n\t\t\txhr.setRequestHeader( 'X-WP-Nonce', ctPublic._rest_nonce );\n\t\t},\n\t\tsuccess: function(result){\n\t\t\tif(result.error){\n\t\t\t\tconsole.log('Error happens: ' + (result.error || 'Unknown'));\n\t\t\t}else{\n\t\t\t\tif(callback) {\n\t\t\t\t\tvar obj = null;\n\t\t\t\t\tcallback(result, route, params, obj);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\terror: function(jqXHR, textStatus, errorThrown){\n\t\t\tif( errorThrown ) {\n\t\t\t\tconsole.log('APBCT_REST_ERROR');\n\t\t\t\tconsole.log(jqXHR);\n\t\t\t\tconsole.log(textStatus);\n\t\t\t\tconsole.log('Anti-spam by Cleantalk plugin REST API error: ' + errorThrown + ' Please, contact Cleantalk tech support https://wordpress.org/support/plugin/cleantalk-spam-protect/');\n\t\t\t}\n\t\t},\n\t});\n\n}\n\nfunction apbctGetScreenInfo() {\n\treturn JSON.stringify({\n\t\tfullWidth : document.documentElement.scrollWidth,\n\t\tfullHeight : Math.max(\n\t\t\tdocument.body.scrollHeight, document.documentElement.scrollHeight,\n\t\t\tdocument.body.offsetHeight, document.documentElement.offsetHeight,\n\t\t\tdocument.body.clientHeight, document.documentElement.clientHeight\n\t\t),\n\t\tvisibleWidth : document.documentElement.clientWidth,\n\t\tvisibleHeight : document.documentElement.clientHeight,\n\t});\n}\n\nif(typeof jQuery !== 'undefined') {\n\n\t// Capturing responses and output block message for unknown AJAX forms\n\tjQuery(document).ajaxComplete(function (event, xhr, settings) {\n\t\tif (xhr.responseText && xhr.responseText.indexOf('\"apbct') !== -1) {\n\t\t\tvar response = JSON.parse(xhr.responseText);\n\t\t\tif (typeof response.apbct !== 'undefined') {\n\t\t\t\tresponse = response.apbct;\n\t\t\t\tif (response.blocked) {\n\t\t\t\t\tdocument.dispatchEvent(\n\t\t\t\t\t\tnew CustomEvent( \"apbctAjaxBockAlert\", {\n\t\t\t\t\t\t\tbubbles: true,\n\t\t\t\t\t\t\tdetail: { message: response.comment }\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\n\t\t\t\t\t// Show the result by modal\n\t\t\t\t\tcleantalkModal.loaded = response.comment;\n\t\t\t\t\tcleantalkModal.open();\n\n\t\t\t\t\tif(+response.stop_script == 1)\n\t\t\t\t\t\twindow.stop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n}"],"names":["ctSetCookie","cookies","value","expires","skip_alt","ctPublic","data__set_cookies","forEach","item","i","arr","ctSecure","location","protocol","document","cookie","encodeURIComponent","data__set_cookies__alt_sessions_type","apbct_public_sendREST","method","data","apbct_public_sendAJAX","action","apbct_ajax","notJson","apbct_collect_visible_fields","form","key","inputs","inputs_visible","inputs_visible_count","inputs_invisible","inputs_invisible_count","inputs_with_duplicate_names","elements","isNaN","filter","elem","indexOf","getAttribute","push","getComputedStyle","display","visibility","opacity","classList","contains","trim","visible_fields","visible_fields_count","invisible_fields","invisible_fields_count","apbct_visible_fields_set_cookie","visible_fields_collection","collection","JSON","stringify","apbct_js_keys__set_input_value","result","params","obj","querySelectorAll","length","js_key","callback","callback_context","callback_params","async","timeout","button","spinner","progressbar","silent","no_nonce","_ajax_nonce","Math","random","no_cache","setAttribute","style","cursor","jQuery","css","ajax","type","url","_apbct_ajax_url","_ajax_url","success","removeAttribute","parse","error","setTimeout","fadeOut","console","log","apply","concat","jqXHR","textStatus","errorThrown","route","_rest_url","beforeSend","xhr","setRequestHeader","_rest_nonce","apbctGetScreenInfo","fullWidth","documentElement","scrollWidth","fullHeight","max","body","scrollHeight","offsetHeight","clientHeight","visibleWidth","clientWidth","visibleHeight","ct_date","Date","ctTimeMs","getTime","ctMouseEventTimerFlag","ctMouseData","ctMouseDataCounter","ctCheckedEmails","ctScrollCollected","apbct_attach_event_handler","event","window","addEventListener","attachEvent","apbct_remove_event_handler","removeEventListener","detachEvent","floor","getTimezoneOffset","ctFunctionFirstKey","ctMouseReadInterval","setInterval","ctMouseWriteDataInterval","ctFunctionMouseMove","round","clientY","clientX","clearInterval","checkEmail","e","current_email","target","email","timestamp","now","pixel__setting","pixel__url","pixel__enabled","append","data__email_check_before_post","blur","forms","parentElement","toString","id","name","onsubmit_prev","onsubmit","this","Function","call","ajaxComplete","settings","responseText","response","apbct","blocked","dispatchEvent","CustomEvent","bubbles","detail","message","comment","cleantalkModal","loaded","open","stop_script","stop"],"mappings":"AA2KA,SAASA,YAAaC,EAASC,EAAOC,GAErC,IACKC,GADkB,iBAAZH,GAAyC,iBAAVC,GAAuC,iBAAVA,KAClEE,EAAuB,oBAAZH,GAA6C,iBAAZA,EAChDA,EAAU,CAAE,CAAEA,EAASC,EAAOC,KAIK,IAA/BE,SAASC,oBAI4B,IAA/BD,SAASC,kBACnBL,EAAQM,QAAS,SAAUC,EAAMC,EAAGC,GACnC,IAAIP,OAA6B,IAAZK,EAAK,GAAqB,WAAaL,EAAU,KAAO,GACzEQ,EAAiC,WAAtBC,SAASC,SAAwB,WAAa,GAC7DC,SAASC,OAASP,EAAK,GAAK,IAAMQ,mBAAmBR,EAAK,IAAM,KAAOL,EAAU,uBAAyBQ,IAIlE,IAA/BN,SAASC,mBAA6BF,IAGO,IAAlDC,SAASY,qCACbC,sBACC,eACA,CACCC,OAAQ,OACRC,KAAM,CAAEnB,QAASA,KAKyC,IAAlDI,SAASY,sCACnBI,sBACC,CACCC,OAAQ,gCACRrB,QAASA,GAEV,CACCsB,WAAY,EACZC,QAAS,MAOd,SAASC,6BAA8BC,GAGtC,IAOQC,EAPJC,EAAS,GACZC,EAAiB,GACjBC,EAAuB,EACvBC,EAAmB,GACnBC,EAAyB,EACzBC,EAA8B,GAE/B,IAAQN,KAAOD,EAAKQ,SACfC,OAAOR,KACVC,EAAOD,GAAOD,EAAKQ,SAASP,IAsD9B,OAlDAC,EAASA,EAAOQ,OAAO,SAASC,GAG/B,OAA0E,IAAtEJ,EAA4BK,QAASD,EAAKE,aAAa,YAItD,IAAM,CAAC,QAAS,YAAYD,QAASD,EAAKE,aAAa,WAC3DN,EAA4BO,KAAMH,EAAKE,aAAa,UAC7C,OAMFhC,QAAQ,SAAS8B,EAAM5B,EAAGyB,GAGO,WAAtCG,EAAKE,aAAa,SACoB,OAAtCF,EAAKE,aAAa,SACoB,eAAtCF,EAAKE,aAAa,UAMoB,SAAtCE,iBAAiBJ,GAAMK,SACe,WAAtCD,iBAAiBJ,GAAMM,YACe,MAAtCF,iBAAiBJ,GAAMO,SACe,WAAtCP,EAAKE,aAAa,SAEdF,EAAKQ,UAAUC,SAAS,mBAU5BjB,GAAkB,IAAMQ,EAAKE,aAAa,QAC1CT,MAPCC,GAAoB,IAAMM,EAAKE,aAAa,QAC5CP,QAWHD,EAAmBA,EAAiBgB,OAG7B,CACNC,eAHDnB,EAAiBA,EAAekB,OAI/BE,qBAAuBnB,EACvBoB,iBAAmBnB,EACnBoB,uBAAyBnB,GAK3B,SAASoB,gCAAiCC,GAErCC,EAAkD,iBAA9BD,GAAwE,OAA9BA,EAAsCA,EAA4B,GAEpIrD,YAAY,uBAAwBuD,KAAKC,UAAWF,IAIrD,SAASG,+BAA+BC,EAAQtC,EAAMuC,EAAQC,GAC7D,GAA6D,EAAzD9C,SAAS+C,iBAAiB,sBAAsBC,OAEnD,IADA,IAAI5B,EAAWpB,SAAS+C,iBAAiB,sBAC/BpD,EAAI,EAAGA,EAAIyB,EAAS4B,OAAQrD,IACrCyB,EAASzB,GAAGP,MAAQwD,EAAOK,OAK9B,SAAS1C,sBAAsBD,EAAMuC,EAAQC,GAG5C,IAAII,EAAcL,EAAOK,UAAe,KACpCC,EAAmBN,EAAOM,kBAAoB,KAC9CC,EAAkBP,EAAOO,iBAAmB,KAC5CC,EAAQR,EAAOQ,QAAS,EACxB3C,EAAcmC,EAAOnC,SAAe,KACpC4C,EAAcT,EAAOS,SAAe,KACpCR,EAAcA,GAAsB,KACpCS,EAAcV,EAAOU,QAAe,KACpCC,EAAcX,EAAOW,SAAe,KACpCC,EAAcZ,EAAOY,aAAe,KACpCC,EAAcb,EAAOa,QAAe,KACpCC,EAAcd,EAAOc,UAAe,KACpClD,EAAcoC,EAAOpC,YAAe,KAEnB,iBAAX,EAGTH,GADCA,GADKqD,EACErD,EAAO,gBAAkBf,SAASqE,YACnCtD,GAAO,aAAeuD,KAAKC,UAE5BH,IACLrD,EAAKsD,YAAcrE,SAASqE,aAC7BtD,EAAKyD,SAAWF,KAAKC,UAGnBP,IAAUA,EAAOS,aAAa,WAAY,YAAaT,EAAOU,MAAMC,OAAS,eAC7EV,GAASW,OAAOX,GAASY,IAAI,UAAW,UAE3CD,OAAOE,KAAK,CACXC,KAAM,OACNC,IAAK9D,EAAalB,SAASiF,gBAAkBjF,SAASkF,UACtDnE,KAAMA,EACN+C,MAAOA,EACPqB,QAAS,SAAS9B,GACdW,IAAUA,EAAOoB,gBAAgB,YAAapB,EAAOU,MAAMC,OAAS,WACpEV,GAAUW,OAAOX,GAASY,IAAI,UAAW,SAC/BxB,GAATlC,EAAkB+B,KAAKmC,MAAMhC,GAC9BA,GAAOiC,OACTC,WAAW,WAAerB,GAAaA,EAAYsB,QAAQ,SAAY,KACvEC,QAAQC,IAAI,mBAAqBrC,EAAOiC,OAAS,YAE9C3B,IACEE,EACHF,EAASgC,MAAO/B,EAAkBC,EAAgB+B,OAAQvC,EAAQtC,EAAMuC,EAAQC,IAEhFI,EAASN,EAAQtC,EAAMuC,EAAQC,KAInC+B,MAAO,SAASO,EAAOC,EAAYC,GAC/B/B,IAAUA,EAAOoB,gBAAgB,YAAapB,EAAOU,MAAMC,OAAS,WACpEV,GAASW,OAAOX,GAASY,IAAI,UAAW,QACvCkB,IAAiB5B,IACpBsB,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,wCAA0CK,EAAc,yGAGtEhC,QAASA,IAIX,SAASlD,sBAAuBmF,EAAO1C,GAEtC,IAAIK,EAAWL,EAAOK,UAAY,KAC9B5C,EAAWuC,EAAOvC,MAAQ,GAC1BD,EAAWwC,EAAOxC,QAAU,OAEhC8D,OAAOE,KAAK,CACXC,KAAMjE,EACNkE,IAAKhF,SAASiG,UAAY,yBAA2BD,EACrDjF,KAAMA,EACNmF,WAAa,SAAWC,GACvBA,EAAIC,iBAAkB,aAAcpG,SAASqG,cAE9ClB,QAAS,SAAS9B,GACdA,EAAOiC,MACTG,QAAQC,IAAI,mBAAqBrC,EAAOiC,OAAS,YAE9C3B,GAEFA,EAASN,EAAQ2C,EAAO1C,EADd,OAKbgC,MAAO,SAASO,EAAOC,EAAYC,GAC9BA,IACHN,QAAQC,IAAI,oBACZD,QAAQC,IAAIG,GACZJ,QAAQC,IAAII,GACZL,QAAQC,IAAI,iDAAmDK,EAAc,4GAOjF,SAASO,qBACR,OAAOpD,KAAKC,UAAU,CACrBoD,UAAY9F,SAAS+F,gBAAgBC,YACrCC,WAAapC,KAAKqC,IACjBlG,SAASmG,KAAKC,aAAcpG,SAAS+F,gBAAgBK,aACrDpG,SAASmG,KAAKE,aAAcrG,SAAS+F,gBAAgBM,aACrDrG,SAASmG,KAAKG,aAActG,SAAS+F,gBAAgBO,cAEtDC,aAAevG,SAAS+F,gBAAgBS,YACxCC,cAAgBzG,SAAS+F,gBAAgBO,gBApa1C,WAEA,IAAII,EAAU,IAAIC,KACjBC,GAAW,IAAID,MAAOE,UACtBC,GAAwB,EACxBC,EAAc,GACdC,EAAqB,EACrBC,EAAkB,GAClBC,GAAoB,EAErB,SAASC,EAA2B5F,EAAM6F,EAAOlE,GACV,mBAA5BmE,OAAOC,iBAAiC/F,EAAK+F,iBAAiBF,EAAOlE,GAC7B3B,EAAKgG,YAAYH,EAAOlE,GAG3E,SAASsE,EAA2BjG,EAAM6F,EAAOlE,GACP,mBAA/BmE,OAAOI,oBAAoClG,EAAKkG,oBAAoBL,EAAOlE,GAChC3B,EAAKmG,YAAYN,EAAOlE,GAG9EhE,YACC,CACC,CAAE,kBAAmB2E,KAAK8D,OAAM,IAAIhB,MAAOE,UAAY,MACvD,CAAE,mBAAoB,KACtB,CAAE,kBAAmB,KACrB,CAAE,cAAeH,EAAQkB,oBAAoB,IAAK,GAClD,CAAE,uBAAwB,OAK5B,IAAIC,EAAqB,SAAgBT,GAExClI,YAAY,mBADO2E,KAAK8D,OAAM,IAAIhB,MAAOE,UAAU,MA0CnDW,EAA2BH,OAAQ,YAAaQ,GAChDL,EAA2BH,OAAQ,UAAWQ,IArC3CC,EAAsBC,YAAY,WACrCjB,GAAwB,GACtB,KAGCkB,EAA2BD,YAAY,WAC1C7I,YAAY,kBAAmBuD,KAAKC,UAAUqE,KAC5C,MAGCkB,EAAsB,SAAgBb,IACZ,IAA1BN,IAEFC,EAAYrF,KAAK,CAChBmC,KAAKqE,MAAMd,EAAMe,SACjBtE,KAAKqE,MAAMd,EAAMgB,SACjBvE,KAAKqE,OAAM,IAAIvB,MAAOE,UAAYD,KAInCE,GAAwB,EACC,MAFzBE,IAUDQ,EAA2BH,OAAQ,YAAaY,GAChDI,cAAcP,GACdO,cAAcL,MASf,SAASM,EAAWC,GACnB,IAAIC,EAAgBD,EAAEE,OAAOrJ,OACzBoJ,GAAmBA,KAAiBvB,GACvC1G,sBACC,CAACC,OAAQ,gCAAiCF,KAAO,CAACoI,MAAUF,IAC5D,CACC/H,WAAY,EACZyC,SAAU,SAAUN,GACfA,EAAOA,SACVqE,EAAgBuB,GAAiB,CAAC5F,OAAWA,EAAOA,OAAQ+F,UAAahC,KAAKiC,MAAQ,IAAM,GAC5F1J,YAAY,oBAAqBuD,KAAKC,UAAUuE,QAetDE,EAA2BE,OAAQ,YAAaY,GAChDd,EAA2BE,OAAQ,YAAaQ,GAChDV,EAA2BE,OAAQ,UAAWQ,GAC9CV,EAA2BE,OAAQ,SAVnC,WACOH,IACLhI,YAAY,kBAAmBuD,KAAKC,WAAW,IAC/CwE,GAAoB,KAoEtBC,EAA2BE,OAAQ,mBA1DnC,YAEM9H,SAASsJ,iBACb3J,YAAa,kBAAmBK,SAASuJ,aACpCvJ,SAASwJ,gBACb5E,OAAO,QAAQ6E,OAAQ,mDAAqDzJ,SAASuJ,WAAa,QAI9FvJ,SAAS0J,gCACd/J,YAAa,oBAAqB,KAClCiF,OAAO,iCAAiC+E,KAAKZ,IAI9CpJ,YAAa,iBAAkB2G,sBAC/B3G,YAAY,kBAAmBuD,KAAKC,WAAW,IAE/CoC,WAAW,WAIV,IAFA,IAAIvC,EAA4B,GAExB5C,EAAI,EAAGA,EAAIK,SAASmJ,MAAMnG,OAAQrD,IAAI,CAC7C,IAAIiB,EAAOZ,SAASmJ,MAAMxJ,GAIzBiB,EAAKmB,UAAUC,SAAS,oBACxBpB,EAAKwI,cAAcrH,UAAUC,SAAS,iBACkB,IAAxDpB,EAAKJ,OAAO6I,WAAW7H,QAAQ,qBAC9BZ,EAAK0I,IAAiB,cAAX1I,EAAK0I,IAChB1I,EAAK2I,KAAKxH,WAAanB,EAAK2I,KAAKxH,UAAUC,SAAS,kBACpDpB,EAAK2I,KAAKxH,WAAanB,EAAK2I,KAAKxH,UAAUC,SAAS,eAItDO,EAA0B5C,GAAKgB,6BAA8BC,GAE7DA,EAAK4I,cAAgB5I,EAAK6I,SAC1B7I,EAAK6I,SAAW,SAAUrC,GAEzB,IAAIlF,EAAiB,GACrBA,EAAe,GAAKvB,6BAA6B+I,MACjDpH,gCAAiCJ,GAG7BkF,EAAMqB,OAAOe,yBAAyBG,UACzC7E,WAAW,WACVsC,EAAMqB,OAAOe,cAAcI,KAAKxC,EAAMqB,OAAQrB,IAC5C,OAKN9E,gCAAiCC,IAE/B,OArKL,GAwaqB,oBAAX4B,QAGTA,OAAOnE,UAAU6J,aAAa,SAAUzC,EAAO1B,EAAKoE,IAC/CpE,EAAIqE,eAAwD,IAAxCrE,EAAIqE,aAAavI,QAAQ,gBAElB,KAD1BwI,EAAWvH,KAAKmC,MAAMc,EAAIqE,eACVE,QACnBD,EAAWA,EAASC,OACPC,UACZlK,SAASmK,cACR,IAAIC,YAAa,qBAAsB,CACtCC,SAAS,EACTC,OAAQ,CAAEC,QAASP,EAASQ,YAK9BC,eAAeC,OAASV,EAASQ,QACjCC,eAAeE,OAEa,IAAxBX,EAASY,aACZvD,OAAOwD"}
|
1 |
+
{"version":3,"file":"apbct-public.min.js","sources":["apbct-public.js"],"sourcesContent":["(function() {\n\n\tvar ct_date = new Date(),\n\t\tctTimeMs = new Date().getTime(),\n\t\tctMouseEventTimerFlag = true, //Reading interval flag\n\t\tctMouseData = [],\n\t\tctMouseDataCounter = 0,\n\t\tctCheckedEmails = {},\n\t\tctScrollCollected = false;\n\n\tfunction apbct_attach_event_handler(elem, event, callback){\n\t\tif(typeof window.addEventListener === \"function\") elem.addEventListener(event, callback);\n\t\telse elem.attachEvent(event, callback);\n\t}\n\n\tfunction apbct_remove_event_handler(elem, event, callback){\n\t\tif(typeof window.removeEventListener === \"function\") elem.removeEventListener(event, callback);\n\t\telse elem.detachEvent(event, callback);\n\t}\n\n\tctSetCookie(\n\t\t[\n\t\t\t[ \"ct_ps_timestamp\", Math.floor(new Date().getTime() / 1000) ],\n\t\t\t[ \"ct_fkp_timestamp\", \"0\" ],\n\t\t\t[ \"ct_pointer_data\", \"0\" ],\n\t\t\t[ \"ct_timezone\", ct_date.getTimezoneOffset()/60*(-1) ],\n\t\t\t[ \"apbct_visible_fields\", \"0\" ],\n\t\t]\n\t);\n\n\t//Writing first key press timestamp\n\tvar ctFunctionFirstKey = function output(event){\n\t\tvar KeyTimestamp = Math.floor(new Date().getTime()/1000);\n\t\tctSetCookie(\"ct_fkp_timestamp\", KeyTimestamp);\n\t\tctKeyStopStopListening();\n\t};\n\n\t//Reading interval\n\tvar ctMouseReadInterval = setInterval(function(){\n\t\tctMouseEventTimerFlag = true;\n\t}, 150);\n\n\t//Writting interval\n\tvar ctMouseWriteDataInterval = setInterval(function(){\n\t\tctSetCookie(\"ct_pointer_data\", JSON.stringify(ctMouseData));\n\t}, 1200);\n\n\t//Logging mouse position each 150 ms\n\tvar ctFunctionMouseMove = function output(event){\n\t\tif(ctMouseEventTimerFlag === true){\n\n\t\t\tctMouseData.push([\n\t\t\t\tMath.round(event.clientY),\n\t\t\t\tMath.round(event.clientX),\n\t\t\t\tMath.round(new Date().getTime() - ctTimeMs)\n\t\t\t]);\n\n\t\t\tctMouseDataCounter++;\n\t\t\tctMouseEventTimerFlag = false;\n\t\t\tif(ctMouseDataCounter >= 50){\n\t\t\t\tctMouseStopData();\n\t\t\t}\n\t\t}\n\t};\n\n\t//Stop mouse observing function\n\tfunction ctMouseStopData(){\n\t\tapbct_remove_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\t\tclearInterval(ctMouseReadInterval);\n\t\tclearInterval(ctMouseWriteDataInterval);\n\t}\n\n\t//Stop key listening function\n\tfunction ctKeyStopStopListening(){\n\t\tapbct_remove_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\t\tapbct_remove_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\t}\n\n\tfunction checkEmail(e) {\n\t\tvar current_email = e.target.value;\n\t\tif (current_email && !(current_email in ctCheckedEmails)) {\n\t\t\tapbct_public_sendAJAX(\n\t\t\t\t{action: 'apbct_email_check_before_post', data : {'email' : current_email}},\n\t\t\t\t{\n\t\t\t\t\tapbct_ajax: 1,\n\t\t\t\t\tcallback: function (result) {\n\t\t\t\t\t\tif (result.result) {\n\t\t\t\t\t\t\tctCheckedEmails[current_email] = {'result' : result.result, 'timestamp': Date.now() / 1000 |0};\n\t\t\t\t\t\t\tctSetCookie('ct_checked_emails', JSON.stringify(ctCheckedEmails));\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t);\t\t\n\t\t}\n\t}\n\n\tfunction ctSetHasScrolled() {\n\t\tif( ! ctScrollCollected ) {\n\t\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( true ) );\n\t\t\tctScrollCollected = true;\n\t\t}\n\t}\n\n\tapbct_attach_event_handler(window, \"mousemove\", ctFunctionMouseMove);\n\tapbct_attach_event_handler(window, \"mousedown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"keydown\", ctFunctionFirstKey);\n\tapbct_attach_event_handler(window, \"scroll\", ctSetHasScrolled);\n\n\t// Ready function\n\tfunction apbct_ready(){\n\n\t\tif( +ctPublic.pixel__setting ){\n\t\t\tctSetCookie( 'apbct_pixel_url', ctPublic.pixel__url );\n\t\t\tif( +ctPublic.pixel__enabled ){\n\t\t\t\tjQuery('body').append( '<img style=\"display: none; left: 99999px;\" src=\"' + ctPublic.pixel__url + '\">' );\n\t\t\t}\n\t\t}\n\n\t\tif ( +ctPublic.data__email_check_before_post) {\n\t\t\tctSetCookie( 'ct_checked_emails', '0');\n\t\t\tjQuery(\"input[type = 'email'], #email\").blur(checkEmail);\n\t\t}\n\n\t\t// Collect scrolling info\n\t\tctSetCookie( 'ct_screen_info', apbctGetScreenInfo() );\n\t\tctSetCookie(\"ct_has_scrolled\", JSON.stringify( false ) );\n\n\t\tsetTimeout(function(){\n\n\t\t\tvar visible_fields_collection = {};\n\n\t\t\tfor(var i = 0; i < document.forms.length; i++){\n\t\t\t\tvar form = document.forms[i];\n\n\t\t\t\t//Exclusion for forms\n\t\t\t\tif (\n\t\t\t\t\tform.classList.contains('slp_search_form') || //StoreLocatorPlus form\n\t\t\t\t\tform.parentElement.classList.contains('mec-booking') ||\n\t\t\t\t\tform.action.toString().indexOf('activehosted.com') !== -1 || // Active Campaign\n\t\t\t\t\t(form.id && form.id == 'caspioform') || //Caspio Form\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('tinkoffPayRow')) || // TinkoffPayForm\n\t\t\t\t\t(form.name.classList && form.name.classList.contains('give-form')) // GiveWP\n\t\t\t\t)\n\t\t\t\t\tcontinue;\n\n\t\t\t\tvisible_fields_collection[i] = apbct_collect_visible_fields( form );\n\n\t\t\t\tform.onsubmit_prev = form.onsubmit;\n\t\t\t\tform.onsubmit = function (event) {\n\n\t\t\t\t\tvar visible_fields = {};\n\t\t\t\t\tvisible_fields[0] = apbct_collect_visible_fields(this);\n\t\t\t\t\tapbct_visible_fields_set_cookie( visible_fields );\n\n\t\t\t\t\t// Call previous submit action\n\t\t\t\t\tif (event.target.onsubmit_prev instanceof Function) {\n\t\t\t\t\t\tsetTimeout(function () {\n\t\t\t\t\t\t\tevent.target.onsubmit_prev.call(event.target, event);\n\t\t\t\t\t\t}, 500);\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tapbct_visible_fields_set_cookie( visible_fields_collection );\n\n\t\t}, 1000);\n\t}\n\tapbct_attach_event_handler(window, \"DOMContentLoaded\", apbct_ready);\n\n}());\n\nfunction apbct_collect_visible_fields( form ) {\n\n\t// Get only fields\n\tvar inputs = [],\n\t\tinputs_visible = '',\n\t\tinputs_visible_count = 0,\n\t\tinputs_invisible = '',\n\t\tinputs_invisible_count = 0,\n\t\tinputs_with_duplicate_names = [];\n\n\tfor(var key in form.elements){\n\t\tif(!isNaN(+key))\n\t\t\tinputs[key] = form.elements[key];\n\t}\n\n\t// Filter fields\n\tinputs = inputs.filter(function(elem){\n\n\t\t// Filter already added fields\n\t\tif( inputs_with_duplicate_names.indexOf( elem.getAttribute('name') ) !== -1 ){\n\t\t\treturn false;\n\t\t}\n\t\t// Filter inputs with same names for type == radio\n\t\tif( -1 !== ['radio', 'checkbox'].indexOf( elem.getAttribute(\"type\") )){\n\t\t\tinputs_with_duplicate_names.push( elem.getAttribute('name') );\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\n\t// Visible fields\n\tinputs.forEach(function(elem, i, elements){\n\t\t// Unnecessary fields\n\t\tif(\n\t\t\telem.getAttribute(\"type\") === \"submit\" || // type == submit\n\t\t\telem.getAttribute('name') === null ||\n\t\t\telem.getAttribute('name') === 'ct_checkjs'\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\t// Invisible fields\n\t\tif(\n\t\t\tgetComputedStyle(elem).display === \"none\" || // hidden\n\t\t\tgetComputedStyle(elem).visibility === \"hidden\" || // hidden\n\t\t\tgetComputedStyle(elem).opacity === \"0\" || // hidden\n\t\t\telem.getAttribute(\"type\") === \"hidden\" // type == hidden\n\t\t) {\n\t\t\tif( elem.classList.contains(\"wp-editor-area\") ) {\n\t\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_visible_count++;\n\t\t\t} else {\n\t\t\t\tinputs_invisible += \" \" + elem.getAttribute(\"name\");\n\t\t\t\tinputs_invisible_count++;\n\t\t\t}\n\t\t}\n\t\t// Visible fields\n\t\telse {\n\t\t\tinputs_visible += \" \" + elem.getAttribute(\"name\");\n\t\t\tinputs_visible_count++;\n\t\t}\n\n\t});\n\n\tinputs_invisible = inputs_invisible.trim();\n\tinputs_visible = inputs_visible.trim();\n\n\treturn {\n\t\tvisible_fields : inputs_visible,\n\t\tvisible_fields_count : inputs_visible_count,\n\t\tinvisible_fields : inputs_invisible,\n\t\tinvisible_fields_count : inputs_invisible_count,\n\t}\n\n}\n\nfunction apbct_visible_fields_set_cookie( visible_fields_collection ) {\n\n\tvar collection = typeof visible_fields_collection === 'object' && visible_fields_collection !== null ? visible_fields_collection : {};\n\n\tctSetCookie(\"apbct_visible_fields\", JSON.stringify( collection ) );\n\n}\n\nfunction apbct_js_keys__set_input_value(result, data, params, obj){\n\tif( document.querySelectorAll('[name^=ct_checkjs]').length > 0 ) {\n\t\tvar elements = document.querySelectorAll('[name^=ct_checkjs]');\n\t\tfor ( var i = 0; i < elements.length; i++ ) {\n\t\t\telements[i].value = result.js_key;\n\t\t}\n\t}\n}\n\nfunction apbctGetScreenInfo() {\n\treturn JSON.stringify({\n\t\tfullWidth : document.documentElement.scrollWidth,\n\t\tfullHeight : Math.max(\n\t\t\tdocument.body.scrollHeight, document.documentElement.scrollHeight,\n\t\t\tdocument.body.offsetHeight, document.documentElement.offsetHeight,\n\t\t\tdocument.body.clientHeight, document.documentElement.clientHeight\n\t\t),\n\t\tvisibleWidth : document.documentElement.clientWidth,\n\t\tvisibleHeight : document.documentElement.clientHeight,\n\t});\n}\n\nif(typeof jQuery !== 'undefined') {\n\n\t// Capturing responses and output block message for unknown AJAX forms\n\tjQuery(document).ajaxComplete(function (event, xhr, settings) {\n\t\tif (xhr.responseText && xhr.responseText.indexOf('\"apbct') !== -1) {\n\t\t\tvar response = JSON.parse(xhr.responseText);\n\t\t\tif (typeof response.apbct !== 'undefined') {\n\t\t\t\tresponse = response.apbct;\n\t\t\t\tif (response.blocked) {\n\t\t\t\t\tdocument.dispatchEvent(\n\t\t\t\t\t\tnew CustomEvent( \"apbctAjaxBockAlert\", {\n\t\t\t\t\t\t\tbubbles: true,\n\t\t\t\t\t\t\tdetail: { message: response.comment }\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\n\t\t\t\t\t// Show the result by modal\n\t\t\t\t\tcleantalkModal.loaded = response.comment;\n\t\t\t\t\tcleantalkModal.open();\n\n\t\t\t\t\tif(+response.stop_script == 1)\n\t\t\t\t\t\twindow.stop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t});\n}"],"names":["apbct_collect_visible_fields","form","inputs","inputs_visible","inputs_visible_count","inputs_invisible","inputs_invisible_count","inputs_with_duplicate_names","key","elements","isNaN","filter","elem","indexOf","getAttribute","push","forEach","i","getComputedStyle","display","visibility","opacity","classList","contains","trim","visible_fields","visible_fields_count","invisible_fields","invisible_fields_count","apbct_visible_fields_set_cookie","visible_fields_collection","collection","ctSetCookie","JSON","stringify","apbct_js_keys__set_input_value","result","data","params","obj","document","querySelectorAll","length","value","js_key","apbctGetScreenInfo","fullWidth","documentElement","scrollWidth","fullHeight","Math","max","body","scrollHeight","offsetHeight","clientHeight","visibleWidth","clientWidth","visibleHeight","ct_date","Date","ctTimeMs","getTime","ctMouseEventTimerFlag","ctMouseData","ctMouseDataCounter","ctCheckedEmails","ctScrollCollected","apbct_attach_event_handler","event","callback","window","addEventListener","attachEvent","apbct_remove_event_handler","removeEventListener","detachEvent","floor","getTimezoneOffset","ctFunctionFirstKey","KeyTimestamp","ctMouseReadInterval","setInterval","ctMouseWriteDataInterval","ctFunctionMouseMove","round","clientY","clientX","clearInterval","checkEmail","e","current_email","target","apbct_public_sendAJAX","action","email","apbct_ajax","timestamp","now","ctPublic","pixel__setting","pixel__url","pixel__enabled","jQuery","append","data__email_check_before_post","blur","setTimeout","forms","parentElement","toString","id","name","onsubmit_prev","onsubmit","this","Function","call","ajaxComplete","xhr","settings","response","responseText","parse","apbct","blocked","dispatchEvent","CustomEvent","bubbles","detail","message","comment","cleantalkModal","loaded","open","stop_script","stop"],"mappings":"AA2KA,SAASA,6BAA8BC,GAGtC,IAAIC,EAAS,GACZC,EAAiB,GACjBC,EAAuB,EACvBC,EAAmB,GACnBC,EAAyB,EACzBC,EAA8B,GAE/B,IAAI,IAAIC,KAAOP,EAAKQ,SACfC,OAAOF,KACVN,EAAOM,GAAOP,EAAKQ,SAASD,IAsD9B,OAlDAN,EAASA,EAAOS,OAAO,SAASC,GAG/B,OAA0E,IAAtEL,EAA4BM,QAASD,EAAKE,aAAa,YAItD,IAAM,CAAC,QAAS,YAAYD,QAASD,EAAKE,aAAa,WAC3DP,EAA4BQ,KAAMH,EAAKE,aAAa,UAC7C,OAMFE,QAAQ,SAASJ,EAAMK,EAAGR,GAGO,WAAtCG,EAAKE,aAAa,SACoB,OAAtCF,EAAKE,aAAa,SACoB,eAAtCF,EAAKE,aAAa,UAMoB,SAAtCI,iBAAiBN,GAAMO,SACe,WAAtCD,iBAAiBN,GAAMQ,YACe,MAAtCF,iBAAiBN,GAAMS,SACe,WAAtCT,EAAKE,aAAa,SAEdF,EAAKU,UAAUC,SAAS,mBAU5BpB,GAAkB,IAAMS,EAAKE,aAAa,QAC1CV,MAPCC,GAAoB,IAAMO,EAAKE,aAAa,QAC5CR,QAWHD,EAAmBA,EAAiBmB,OAG7B,CACNC,eAHDtB,EAAiBA,EAAeqB,OAI/BE,qBAAuBtB,EACvBuB,iBAAmBtB,EACnBuB,uBAAyBtB,GAK3B,SAASuB,gCAAiCC,GAEzC,IAAIC,EAAkD,iBAA9BD,GAAwE,OAA9BA,EAAsCA,EAA4B,GAEpIE,YAAY,uBAAwBC,KAAKC,UAAWH,IAIrD,SAASI,+BAA+BC,EAAQC,EAAMC,EAAQC,GAC7D,GAA6D,EAAzDC,SAASC,iBAAiB,sBAAsBC,OAEnD,IADA,IAAIjC,EAAW+B,SAASC,iBAAiB,sBAC/BxB,EAAI,EAAGA,EAAIR,EAASiC,OAAQzB,IACrCR,EAASQ,GAAG0B,MAAQP,EAAOQ,OAK9B,SAASC,qBACR,OAAOZ,KAAKC,UAAU,CACrBY,UAAYN,SAASO,gBAAgBC,YACrCC,WAAaC,KAAKC,IACjBX,SAASY,KAAKC,aAAcb,SAASO,gBAAgBM,aACrDb,SAASY,KAAKE,aAAcd,SAASO,gBAAgBO,aACrDd,SAASY,KAAKG,aAAcf,SAASO,gBAAgBQ,cAEtDC,aAAehB,SAASO,gBAAgBU,YACxCC,cAAgBlB,SAASO,gBAAgBQ,gBAhR1C,WAEA,IAAII,EAAU,IAAIC,KACjBC,GAAW,IAAID,MAAOE,UACtBC,GAAwB,EACxBC,EAAc,GACdC,EAAqB,EACrBC,EAAkB,GAClBC,GAAoB,EAErB,SAASC,EAA2BxD,EAAMyD,EAAOC,GACV,mBAA5BC,OAAOC,iBAAiC5D,EAAK4D,iBAAiBH,EAAOC,GAC7B1D,EAAK6D,YAAYJ,EAAOC,GAG3E,SAASI,EAA2B9D,EAAMyD,EAAOC,GACP,mBAA/BC,OAAOI,oBAAoC/D,EAAK+D,oBAAoBN,EAAOC,GAChC1D,EAAKgE,YAAYP,EAAOC,GAG9EtC,YACC,CACC,CAAE,kBAAmBkB,KAAK2B,OAAM,IAAIjB,MAAOE,UAAY,MACvD,CAAE,mBAAoB,KACtB,CAAE,kBAAmB,KACrB,CAAE,cAAeH,EAAQmB,oBAAoB,IAAK,GAClD,CAAE,uBAAwB,OAK5B,IAAIC,EAAqB,WACxB,IAAIC,EAAe9B,KAAK2B,OAAM,IAAIjB,MAAOE,UAAU,KACnD9B,YAAY,mBAAoBgD,GAyChCN,EAA2BH,OAAQ,YAAaQ,GAChDL,EAA2BH,OAAQ,UAAWQ,IArC3CE,EAAsBC,YAAY,WACrCnB,GAAwB,GACtB,KAGCoB,EAA2BD,YAAY,WAC1ClD,YAAY,kBAAmBC,KAAKC,UAAU8B,KAC5C,MAGCoB,EAAsB,SAAgBf,IACZ,IAA1BN,IAEFC,EAAYjD,KAAK,CAChBmC,KAAKmC,MAAMhB,EAAMiB,SACjBpC,KAAKmC,MAAMhB,EAAMkB,SACjBrC,KAAKmC,OAAM,IAAIzB,MAAOE,UAAYD,KAInCE,GAAwB,EACC,MAFzBE,IAUDS,EAA2BH,OAAQ,YAAaa,GAChDI,cAAcP,GACdO,cAAcL,MASf,SAASM,EAAWC,GACnB,IAAIC,EAAgBD,EAAEE,OAAOjD,OACzBgD,GAAmBA,KAAiBzB,GACvC2B,sBACC,CAACC,OAAQ,gCAAiCzD,KAAO,CAAC0D,MAAUJ,IAC5D,CACCK,WAAY,EACZ1B,SAAU,SAAUlC,GACfA,EAAOA,SACV8B,EAAgByB,GAAiB,CAACvD,OAAWA,EAAOA,OAAQ6D,UAAarC,KAAKsC,MAAQ,IAAM,GAC5FlE,YAAY,oBAAqBC,KAAKC,UAAUgC,QAetDE,EAA2BG,OAAQ,YAAaa,GAChDhB,EAA2BG,OAAQ,YAAaQ,GAChDX,EAA2BG,OAAQ,UAAWQ,GAC9CX,EAA2BG,OAAQ,SAVnC,WACOJ,IACLnC,YAAY,kBAAmBC,KAAKC,WAAW,IAC/CiC,GAAoB,KAoEtBC,EAA2BG,OAAQ,mBA1DnC,YAEM4B,SAASC,iBACbpE,YAAa,kBAAmBmE,SAASE,aACpCF,SAASG,gBACbC,OAAO,QAAQC,OAAQ,mDAAqDL,SAASE,WAAa,QAI9FF,SAASM,gCACdzE,YAAa,oBAAqB,KAClCuE,OAAO,iCAAiCG,KAAKjB,IAI9CzD,YAAa,iBAAkBa,sBAC/Bb,YAAY,kBAAmBC,KAAKC,WAAW,IAE/CyE,WAAW,WAIV,IAFA,IAAI7E,EAA4B,GAExBb,EAAI,EAAGA,EAAIuB,SAASoE,MAAMlE,OAAQzB,IAAI,CAC7C,IAAIhB,EAAOuC,SAASoE,MAAM3F,GAIzBhB,EAAKqB,UAAUC,SAAS,oBACxBtB,EAAK4G,cAAcvF,UAAUC,SAAS,iBACkB,IAAxDtB,EAAK6F,OAAOgB,WAAWjG,QAAQ,qBAC9BZ,EAAK8G,IAAiB,cAAX9G,EAAK8G,IAChB9G,EAAK+G,KAAK1F,WAAarB,EAAK+G,KAAK1F,UAAUC,SAAS,kBACpDtB,EAAK+G,KAAK1F,WAAarB,EAAK+G,KAAK1F,UAAUC,SAAS,eAItDO,EAA0Bb,GAAKjB,6BAA8BC,GAE7DA,EAAKgH,cAAgBhH,EAAKiH,SAC1BjH,EAAKiH,SAAW,SAAU7C,GAEzB,IAAI5C,EAAiB,GACrBA,EAAe,GAAKzB,6BAA6BmH,MACjDtF,gCAAiCJ,GAG7B4C,EAAMuB,OAAOqB,yBAAyBG,UACzCT,WAAW,WACVtC,EAAMuB,OAAOqB,cAAcI,KAAKhD,EAAMuB,OAAQvB,IAC5C,OAKNxC,gCAAiCC,IAE/B,OArKL,GAoRqB,oBAAXyE,QAGTA,OAAO/D,UAAU8E,aAAa,SAAUjD,EAAOkD,EAAKC,GACnD,IACKC,GADDF,EAAIG,eAAwD,IAAxCH,EAAIG,aAAa7G,QAAQ,gBAElB,KAD1B4G,EAAWxF,KAAK0F,MAAMJ,EAAIG,eACVE,QACnBH,EAAWA,EAASG,OACPC,UACZrF,SAASsF,cACR,IAAIC,YAAa,qBAAsB,CACtCC,SAAS,EACTC,OAAQ,CAAEC,QAAST,EAASU,YAK9BC,eAAeC,OAASZ,EAASU,QACjCC,eAAeE,OAEa,IAAxBb,EAASc,aACZhE,OAAOiE"}
|
@@ -2,6 +2,8 @@
|
|
2 |
|
3 |
namespace Cleantalk\Antispam;
|
4 |
|
|
|
|
|
5 |
/**
|
6 |
* Cleantalk base class
|
7 |
*
|
@@ -18,6 +20,7 @@ class Cleantalk {
|
|
18 |
|
19 |
/*
|
20 |
* Use Wordpress built-in API
|
|
|
21 |
*/
|
22 |
public $use_bultin_api = false;
|
23 |
|
@@ -43,25 +46,25 @@ class Cleantalk {
|
|
43 |
* Cleantalk server url
|
44 |
* @var string
|
45 |
*/
|
46 |
-
public $server_url
|
47 |
|
48 |
/**
|
49 |
* Last work url
|
50 |
* @var string
|
51 |
*/
|
52 |
-
public $work_url
|
53 |
|
54 |
/**
|
55 |
-
*
|
56 |
* @var int
|
57 |
*/
|
58 |
-
public $server_ttl
|
59 |
|
60 |
/**
|
61 |
-
* Time
|
62 |
* @var int
|
63 |
*/
|
64 |
-
public $server_changed
|
65 |
|
66 |
/**
|
67 |
* Flag is change server url
|
@@ -71,9 +74,9 @@ class Cleantalk {
|
|
71 |
|
72 |
/**
|
73 |
* Codepage of the data
|
74 |
-
* @var
|
75 |
*/
|
76 |
-
public $data_codepage =
|
77 |
|
78 |
/**
|
79 |
* API version to use
|
@@ -94,25 +97,33 @@ class Cleantalk {
|
|
94 |
public $ssl_path = '';
|
95 |
|
96 |
/**
|
97 |
-
* Minimal server response in
|
98 |
-
*
|
99 |
*/
|
100 |
public $min_server_timeout = 50;
|
101 |
|
102 |
/**
|
103 |
-
* Maximal server response in
|
104 |
-
*
|
105 |
*/
|
106 |
public $max_server_timeout = 1500;
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
* Function checks whether it is possible to publish the message
|
110 |
*
|
111 |
* @param CleantalkRequest $request
|
112 |
*
|
113 |
* @return bool|CleantalkResponse
|
114 |
*/
|
115 |
-
public function isAllowMessage(CleantalkRequest $request) {
|
116 |
$msg = $this->createMsg('check_message', $request);
|
117 |
return $this->httpRequest($msg);
|
118 |
}
|
@@ -124,7 +135,7 @@ class Cleantalk {
|
|
124 |
*
|
125 |
* @return bool|CleantalkResponse
|
126 |
*/
|
127 |
-
public function isAllowUser(CleantalkRequest $request) {
|
128 |
$msg = $this->createMsg('check_newuser', $request);
|
129 |
return $this->httpRequest($msg);
|
130 |
}
|
@@ -136,7 +147,7 @@ class Cleantalk {
|
|
136 |
*
|
137 |
* @return bool|CleantalkResponse
|
138 |
*/
|
139 |
-
public function sendFeedback(CleantalkRequest $request) {
|
140 |
$msg = $this->createMsg('send_feedback', $request);
|
141 |
return $this->httpRequest($msg);
|
142 |
}
|
@@ -147,23 +158,23 @@ class Cleantalk {
|
|
147 |
* @param CleantalkRequest $request
|
148 |
* @return CleantalkRequest
|
149 |
*/
|
150 |
-
private function createMsg($method, CleantalkRequest $request) {
|
151 |
|
152 |
switch ($method) {
|
153 |
case 'check_message':
|
154 |
// Convert strings to UTF8
|
155 |
-
$request->message =
|
156 |
-
$request->example =
|
157 |
-
$request->sender_email =
|
158 |
-
$request->sender_nickname =
|
159 |
-
$request->message
|
160 |
-
$request->example
|
161 |
break;
|
162 |
|
163 |
case 'check_newuser':
|
164 |
// Convert strings to UTF8
|
165 |
-
$request->sender_email =
|
166 |
-
$request->sender_nickname =
|
167 |
break;
|
168 |
|
169 |
case 'send_feedback':
|
@@ -175,42 +186,48 @@ class Cleantalk {
|
|
175 |
|
176 |
// Removing non UTF8 characters from request, because non UTF8 or malformed characters break json_encode().
|
177 |
foreach ($request as $param => $value) {
|
178 |
-
if(is_array($request->$param) || is_string($request->$param))
|
179 |
-
|
|
|
180 |
}
|
181 |
|
182 |
$request->method_name = $method;
|
183 |
$request->message = is_array($request->message) ? json_encode($request->message) : $request->message;
|
184 |
|
185 |
// Wiping cleantalk's headers but, not for send_feedback
|
186 |
-
if($request->method_name
|
187 |
|
188 |
$ct_tmp = apache_request_headers();
|
189 |
|
190 |
-
if(isset($ct_tmp['Cookie']))
|
191 |
$cookie_name = 'Cookie';
|
192 |
-
|
|
|
193 |
$cookie_name = 'cookie';
|
194 |
-
|
|
|
195 |
$cookie_name = 'COOKIE';
|
|
|
196 |
|
197 |
-
if( $ct_tmp
|
198 |
-
$ct_tmp[$cookie_name]
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
214 |
$request->all_headers = json_encode($ct_tmp);
|
215 |
}
|
216 |
|
@@ -221,24 +238,20 @@ class Cleantalk {
|
|
221 |
|
222 |
/**
|
223 |
* Compress data and encode to base64
|
224 |
-
* @param
|
225 |
-
* @return string
|
226 |
*/
|
227 |
-
private function compressData($data = null){
|
228 |
|
229 |
if (strlen($data) > $this->dataMaxSise && function_exists('\gzencode') && function_exists('base64_encode')){
|
230 |
|
231 |
$localData = \gzencode($data, $this->compressRate, FORCE_GZIP);
|
232 |
|
233 |
-
if ($localData === false)
|
234 |
-
return $data;
|
235 |
-
|
236 |
-
$localData = base64_encode($localData);
|
237 |
-
|
238 |
-
if ($localData === false)
|
239 |
return $data;
|
240 |
-
|
241 |
-
|
|
|
242 |
}
|
243 |
|
244 |
return $data;
|
@@ -247,75 +260,101 @@ class Cleantalk {
|
|
247 |
/**
|
248 |
* httpRequest
|
249 |
* @param $msg
|
250 |
-
* @return
|
251 |
*/
|
252 |
-
private function httpRequest($msg) {
|
253 |
|
254 |
// Using current server without changing it
|
255 |
-
$result = !empty($this->work_url) &&
|
256 |
-
? $this->sendRequest($msg, $this->work_url, $this->server_timeout)
|
257 |
: false;
|
258 |
|
259 |
-
// Changing server
|
260 |
-
if ($result === false || (is_object($result) && $result->errno != 0)) {
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
$servers = $this->get_servers_ip($url_host);
|
270 |
-
|
271 |
-
// Loop until find work server
|
272 |
-
foreach ($servers as $server) {
|
273 |
-
|
274 |
-
$dns = \Cleantalk\ApbctWP\Helper::ip__resolve__cleantalks($server['ip']);
|
275 |
-
if(!$dns)
|
276 |
-
continue;
|
277 |
-
|
278 |
-
$this->work_url = $url_protocol.$dns.$url_suffix;
|
279 |
-
$this->server_ttl = $server['ttl'];
|
280 |
-
|
281 |
-
$result = $this->sendRequest($msg, $this->work_url, $this->server_timeout);
|
282 |
-
|
283 |
-
if ($result !== false && $result->errno === 0) {
|
284 |
-
$this->server_change = true;
|
285 |
-
break;
|
286 |
-
}
|
287 |
-
}
|
288 |
}
|
|
|
289 |
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
if (!empty($response->sms_error_text))
|
298 |
-
|
|
|
299 |
}
|
300 |
|
301 |
return $response;
|
302 |
}
|
303 |
|
304 |
/**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
* Function DNS request
|
306 |
* @param $host
|
307 |
-
* @return array
|
308 |
*/
|
309 |
-
public function get_servers_ip($host)
|
310 |
{
|
311 |
-
if (!isset($host))
|
312 |
-
|
|
|
313 |
|
314 |
$servers = array();
|
315 |
|
316 |
// Get DNS records about URL
|
317 |
if (function_exists('dns_get_record')) {
|
318 |
-
$records = dns_get_record($host, DNS_A);
|
319 |
if ($records !== FALSE) {
|
320 |
foreach ($records as $server) {
|
321 |
$servers[] = $server;
|
@@ -324,7 +363,7 @@ class Cleantalk {
|
|
324 |
}
|
325 |
|
326 |
// Another try if first failed
|
327 |
-
if (count($servers)
|
328 |
$records = gethostbynamel($host);
|
329 |
if ($records !== FALSE) {
|
330 |
foreach ($records as $server) {
|
@@ -338,7 +377,7 @@ class Cleantalk {
|
|
338 |
}
|
339 |
|
340 |
// If couldn't get records
|
341 |
-
if (count($servers)
|
342 |
|
343 |
$servers[] = array(
|
344 |
"ip" => null,
|
@@ -346,10 +385,10 @@ class Cleantalk {
|
|
346 |
"ttl" => $this->server_ttl
|
347 |
);
|
348 |
|
349 |
-
// If records
|
350 |
} else {
|
351 |
|
352 |
-
$tmp =
|
353 |
$fast_server_found = false;
|
354 |
|
355 |
foreach ($servers as $server) {
|
@@ -358,12 +397,12 @@ class Cleantalk {
|
|
358 |
$ping = $this->max_server_timeout;
|
359 |
} else {
|
360 |
$ping = $this->httpPing($server['ip']);
|
361 |
-
$ping
|
362 |
}
|
363 |
|
364 |
-
$tmp[$ping] = $server;
|
365 |
|
366 |
-
$fast_server_found = $ping < $this->min_server_timeout
|
367 |
|
368 |
}
|
369 |
|
@@ -379,15 +418,16 @@ class Cleantalk {
|
|
379 |
|
380 |
/**
|
381 |
* Function to check response time
|
382 |
-
* param string
|
383 |
-
* @return int
|
384 |
*/
|
385 |
-
function httpPing($host){
|
386 |
|
387 |
// Skip localhost ping cause it raise error at fsockopen.
|
388 |
-
// And return
|
389 |
-
if ($host
|
390 |
-
|
|
|
391 |
|
392 |
$starttime = microtime(true);
|
393 |
$file = @fsockopen ($host, 80, $errno, $errstr, $this->max_server_timeout/1000);
|
@@ -403,12 +443,16 @@ class Cleantalk {
|
|
403 |
|
404 |
return $status;
|
405 |
}
|
406 |
-
|
407 |
/**
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
|
|
|
|
|
|
|
|
412 |
private function sendRequest($data, $url, $server_timeout = 3)
|
413 |
{
|
414 |
$original_args = func_get_args();
|
@@ -428,7 +472,7 @@ class Cleantalk {
|
|
428 |
$data = json_encode($data);
|
429 |
|
430 |
if (isset($this->api_version)) {
|
431 |
-
$url
|
432 |
}
|
433 |
|
434 |
$result = false;
|
@@ -450,10 +494,9 @@ class Cleantalk {
|
|
450 |
$result = wp_remote_post($url, $args);
|
451 |
|
452 |
if( is_wp_error( $result ) ) {
|
453 |
-
$errors = $result->get_error_message();
|
454 |
$result = false;
|
455 |
}else{
|
456 |
-
|
457 |
}
|
458 |
|
459 |
}else{
|
@@ -470,7 +513,7 @@ class Cleantalk {
|
|
470 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // resolve 'Expect: 100-continue' issue
|
471 |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // see http://stackoverflow.com/a/23322368
|
472 |
|
473 |
-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disabling CA cert
|
474 |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // Disabling common name verification
|
475 |
|
476 |
if ($this->ssl_on && $this->ssl_path != '') {
|
@@ -493,7 +536,7 @@ class Cleantalk {
|
|
493 |
|
494 |
if (!$result) {
|
495 |
$allow_url_fopen = ini_get('allow_url_fopen');
|
496 |
-
if (function_exists('file_get_contents') &&
|
497 |
$opts = array('http' =>
|
498 |
array(
|
499 |
'method' => 'POST',
|
@@ -511,7 +554,7 @@ class Cleantalk {
|
|
511 |
if (!$result) {
|
512 |
$response = null;
|
513 |
$response['errno'] = 2;
|
514 |
-
if (
|
515 |
$response['errstr'] = 'Wrong server response format: ' . substr( $result, 100 );
|
516 |
}
|
517 |
else {
|
@@ -520,14 +563,13 @@ class Cleantalk {
|
|
520 |
: 'No CURL support compiled in';
|
521 |
$response['errstr'] .= ' or disabled allow_url_fopen in php.ini.';
|
522 |
}
|
523 |
-
|
524 |
-
|
525 |
-
return $response;
|
526 |
}
|
527 |
|
528 |
$errstr = null;
|
529 |
-
$response = json_decode($result);
|
530 |
-
if ($result !== false && is_object($response)) {
|
531 |
$response->errno = 0;
|
532 |
$response->errstr = $errstr;
|
533 |
} else {
|
2 |
|
3 |
namespace Cleantalk\Antispam;
|
4 |
|
5 |
+
use Cleantalk\ApbctWP\Helper;
|
6 |
+
|
7 |
/**
|
8 |
* Cleantalk base class
|
9 |
*
|
20 |
|
21 |
/*
|
22 |
* Use Wordpress built-in API
|
23 |
+
* @var bool
|
24 |
*/
|
25 |
public $use_bultin_api = false;
|
26 |
|
46 |
* Cleantalk server url
|
47 |
* @var string
|
48 |
*/
|
49 |
+
public $server_url;
|
50 |
|
51 |
/**
|
52 |
* Last work url
|
53 |
* @var string
|
54 |
*/
|
55 |
+
public $work_url;
|
56 |
|
57 |
/**
|
58 |
+
* Work url ttl
|
59 |
* @var int
|
60 |
*/
|
61 |
+
public $server_ttl;
|
62 |
|
63 |
/**
|
64 |
+
* Time work_url changed
|
65 |
* @var int
|
66 |
*/
|
67 |
+
public $server_changed;
|
68 |
|
69 |
/**
|
70 |
* Flag is change server url
|
74 |
|
75 |
/**
|
76 |
* Codepage of the data
|
77 |
+
* @var string
|
78 |
*/
|
79 |
+
public $data_codepage = '';
|
80 |
|
81 |
/**
|
82 |
* API version to use
|
97 |
public $ssl_path = '';
|
98 |
|
99 |
/**
|
100 |
+
* Minimal server response in milliseconds to catch the server
|
101 |
+
* @var int
|
102 |
*/
|
103 |
public $min_server_timeout = 50;
|
104 |
|
105 |
/**
|
106 |
+
* Maximal server response in milliseconds to catch the server
|
107 |
+
* @var int
|
108 |
*/
|
109 |
public $max_server_timeout = 1500;
|
110 |
+
|
111 |
+
/**
|
112 |
+
* List of the down servers.
|
113 |
+
* Non responsible moderate servers list
|
114 |
+
*
|
115 |
+
* @var array
|
116 |
+
*/
|
117 |
+
private $downServers;
|
118 |
+
|
119 |
+
/**
|
120 |
* Function checks whether it is possible to publish the message
|
121 |
*
|
122 |
* @param CleantalkRequest $request
|
123 |
*
|
124 |
* @return bool|CleantalkResponse
|
125 |
*/
|
126 |
+
public function isAllowMessage( CleantalkRequest $request ) {
|
127 |
$msg = $this->createMsg('check_message', $request);
|
128 |
return $this->httpRequest($msg);
|
129 |
}
|
135 |
*
|
136 |
* @return bool|CleantalkResponse
|
137 |
*/
|
138 |
+
public function isAllowUser( CleantalkRequest $request ) {
|
139 |
$msg = $this->createMsg('check_newuser', $request);
|
140 |
return $this->httpRequest($msg);
|
141 |
}
|
147 |
*
|
148 |
* @return bool|CleantalkResponse
|
149 |
*/
|
150 |
+
public function sendFeedback( CleantalkRequest $request ) {
|
151 |
$msg = $this->createMsg('send_feedback', $request);
|
152 |
return $this->httpRequest($msg);
|
153 |
}
|
158 |
* @param CleantalkRequest $request
|
159 |
* @return CleantalkRequest
|
160 |
*/
|
161 |
+
private function createMsg( $method, CleantalkRequest $request ) {
|
162 |
|
163 |
switch ($method) {
|
164 |
case 'check_message':
|
165 |
// Convert strings to UTF8
|
166 |
+
$request->message = Helper::toUTF8($request->message, $this->data_codepage);
|
167 |
+
$request->example = Helper::toUTF8($request->example, $this->data_codepage);
|
168 |
+
$request->sender_email = Helper::toUTF8($request->sender_email, $this->data_codepage);
|
169 |
+
$request->sender_nickname = Helper::toUTF8($request->sender_nickname, $this->data_codepage);
|
170 |
+
$request->message = $this->compressData($request->message);
|
171 |
+
$request->example = $this->compressData($request->example);
|
172 |
break;
|
173 |
|
174 |
case 'check_newuser':
|
175 |
// Convert strings to UTF8
|
176 |
+
$request->sender_email = Helper::toUTF8($request->sender_email, $this->data_codepage);
|
177 |
+
$request->sender_nickname = Helper::toUTF8($request->sender_nickname, $this->data_codepage);
|
178 |
break;
|
179 |
|
180 |
case 'send_feedback':
|
186 |
|
187 |
// Removing non UTF8 characters from request, because non UTF8 or malformed characters break json_encode().
|
188 |
foreach ($request as $param => $value) {
|
189 |
+
if(is_array($request->$param) || is_string($request->$param)) {
|
190 |
+
$request->$param = Helper::removeNonUTF8( $value );
|
191 |
+
}
|
192 |
}
|
193 |
|
194 |
$request->method_name = $method;
|
195 |
$request->message = is_array($request->message) ? json_encode($request->message) : $request->message;
|
196 |
|
197 |
// Wiping cleantalk's headers but, not for send_feedback
|
198 |
+
if( $request->method_name !== 'send_feedback'){
|
199 |
|
200 |
$ct_tmp = apache_request_headers();
|
201 |
|
202 |
+
if(isset($ct_tmp['Cookie'])) {
|
203 |
$cookie_name = 'Cookie';
|
204 |
+
}
|
205 |
+
elseif(isset($ct_tmp['cookie'])) {
|
206 |
$cookie_name = 'cookie';
|
207 |
+
}
|
208 |
+
else {
|
209 |
$cookie_name = 'COOKIE';
|
210 |
+
}
|
211 |
|
212 |
+
if( $ct_tmp ) {
|
213 |
+
if( isset( $ct_tmp[$cookie_name] ) ) {
|
214 |
+
$ct_tmp[$cookie_name] = preg_replace(array(
|
215 |
+
'/\s?ct_checkjs=[a-z0-9]*[^;]*;?/',
|
216 |
+
'/\s?ct_timezone=.{0,1}\d{1,2}[^;]*;?/',
|
217 |
+
'/\s?ct_pointer_data=.*5D[^;]*;?/',
|
218 |
+
'/\s?apbct_timestamp=\d*[^;]*;?/',
|
219 |
+
'/\s?apbct_site_landing_ts=\d*[^;]*;?/',
|
220 |
+
'/\s?apbct_cookies_test=%7B.*%7D[^;]*;?/',
|
221 |
+
'/\s?apbct_prev_referer=http.*?[^;]*;?/',
|
222 |
+
'/\s?ct_cookies_test=.*?[^;]*;?/',
|
223 |
+
'/\s?ct_ps_timestamp=.*?[^;]*;?/',
|
224 |
+
'/\s?ct_fkp_timestamp=\d*?[^;]*;?/',
|
225 |
+
'/\s?wordpress_ct_sfw_pass_key=\d*?[^;]*;?/',
|
226 |
+
'/\s?apbct_page_hits=\d*?[^;]*;?/',
|
227 |
+
'/\s?apbct_visible_fields_count=\d*?[^;]*;?/',
|
228 |
+
'/\s?apbct_visible_fields=%7B.*%7D[^;]*;?/',
|
229 |
+
), '', $ct_tmp[$cookie_name]);
|
230 |
+
}
|
231 |
$request->all_headers = json_encode($ct_tmp);
|
232 |
}
|
233 |
|
238 |
|
239 |
/**
|
240 |
* Compress data and encode to base64
|
241 |
+
* @param string $data
|
242 |
+
* @return null|string
|
243 |
*/
|
244 |
+
private function compressData( $data = null ){
|
245 |
|
246 |
if (strlen($data) > $this->dataMaxSise && function_exists('\gzencode') && function_exists('base64_encode')){
|
247 |
|
248 |
$localData = \gzencode($data, $this->compressRate, FORCE_GZIP);
|
249 |
|
250 |
+
if ( $localData === false ) {
|
|
|
|
|
|
|
|
|
|
|
251 |
return $data;
|
252 |
+
}
|
253 |
+
|
254 |
+
return base64_encode( $localData );
|
255 |
}
|
256 |
|
257 |
return $data;
|
260 |
/**
|
261 |
* httpRequest
|
262 |
* @param $msg
|
263 |
+
* @return CleantalkResponse
|
264 |
*/
|
265 |
+
private function httpRequest( $msg ) {
|
266 |
|
267 |
// Using current server without changing it
|
268 |
+
$result = ! empty( $this->work_url ) && $this->server_changed + 86400 > time()
|
269 |
+
? $this->sendRequest( $msg, $this->work_url, $this->server_timeout )
|
270 |
: false;
|
271 |
|
272 |
+
// Changing server if no work_url or request has an error
|
273 |
+
if ( $result === false || ( is_object( $result ) && $result->errno != 0 ) ) {
|
274 |
+
if( ! empty( $this->work_url ) ) {
|
275 |
+
$this->downServers[] = $this->work_url;
|
276 |
+
}
|
277 |
+
$this->rotateModerate();
|
278 |
+
$result = $this->sendRequest( $msg, $this->work_url );
|
279 |
+
if ($result !== false && $result->errno === 0) {
|
280 |
+
$this->server_change = true;
|
281 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
}
|
283 |
+
$response = new CleantalkResponse( $result );
|
284 |
|
285 |
+
if ( ! empty( $this->data_codepage ) && $this->data_codepage !== 'UTF-8' ) {
|
286 |
+
if ( ! empty( $response->comment ) ) {
|
287 |
+
$response->comment = Helper::fromUTF8( $response->comment, $this->data_codepage );
|
288 |
+
}
|
289 |
+
if ( ! empty( $response->errstr ) ) {
|
290 |
+
$response->errstr = Helper::fromUTF8( $response->errstr, $this->data_codepage );
|
291 |
+
}
|
292 |
+
if ( ! empty($response->sms_error_text ) ) {
|
293 |
+
$response->sms_error_text = Helper::fromUTF8( $response->sms_error_text, $this->data_codepage );
|
294 |
+
}
|
295 |
}
|
296 |
|
297 |
return $response;
|
298 |
}
|
299 |
|
300 |
/**
|
301 |
+
* * @todo Refactor / fix logic errors
|
302 |
+
*/
|
303 |
+
public function rotateModerate()
|
304 |
+
{
|
305 |
+
// Split server url to parts
|
306 |
+
preg_match("/^(https?:\/\/)([^\/:]+)(.*)/i", $this->server_url, $matches);
|
307 |
+
|
308 |
+
$url_protocol = isset($matches[1]) ? $matches[1] : '';
|
309 |
+
$url_host = isset($matches[2]) ? $matches[2] : '';
|
310 |
+
$url_suffix = isset($matches[3]) ? $matches[3] : '';
|
311 |
+
|
312 |
+
$servers = $this->get_servers_ip($url_host);
|
313 |
+
|
314 |
+
if( ! $servers ){
|
315 |
+
return;
|
316 |
+
}
|
317 |
+
|
318 |
+
// Loop until find work server
|
319 |
+
foreach ( $servers as $server ) {
|
320 |
+
|
321 |
+
$dns = Helper::ip__resolve__cleantalks($server['ip']);
|
322 |
+
if( ! $dns ) {
|
323 |
+
continue;
|
324 |
+
}
|
325 |
+
|
326 |
+
$this->work_url = $url_protocol.$dns.$url_suffix;
|
327 |
+
|
328 |
+
// Do not checking previous down server
|
329 |
+
if( ! empty( $this->downServers ) && in_array( $this->work_url, $this->downServers ) ) {
|
330 |
+
continue;
|
331 |
+
}
|
332 |
+
|
333 |
+
$this->server_ttl = $server['ttl'];
|
334 |
+
$this->server_change = true;
|
335 |
+
break;
|
336 |
+
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
/**
|
341 |
+
* * @todo Refactor / fix logic errors
|
342 |
+
*
|
343 |
* Function DNS request
|
344 |
* @param $host
|
345 |
+
* @return array|null
|
346 |
*/
|
347 |
+
public function get_servers_ip( $host )
|
348 |
{
|
349 |
+
if (!isset($host)) {
|
350 |
+
return null;
|
351 |
+
}
|
352 |
|
353 |
$servers = array();
|
354 |
|
355 |
// Get DNS records about URL
|
356 |
if (function_exists('dns_get_record')) {
|
357 |
+
$records = @dns_get_record($host, DNS_A);
|
358 |
if ($records !== FALSE) {
|
359 |
foreach ($records as $server) {
|
360 |
$servers[] = $server;
|
363 |
}
|
364 |
|
365 |
// Another try if first failed
|
366 |
+
if (count($servers) === 0 && function_exists('gethostbynamel')) {
|
367 |
$records = gethostbynamel($host);
|
368 |
if ($records !== FALSE) {
|
369 |
foreach ($records as $server) {
|
377 |
}
|
378 |
|
379 |
// If couldn't get records
|
380 |
+
if (count($servers) === 0){
|
381 |
|
382 |
$servers[] = array(
|
383 |
"ip" => null,
|
385 |
"ttl" => $this->server_ttl
|
386 |
);
|
387 |
|
388 |
+
// If records received
|
389 |
} else {
|
390 |
|
391 |
+
$tmp = array();
|
392 |
$fast_server_found = false;
|
393 |
|
394 |
foreach ($servers as $server) {
|
397 |
$ping = $this->max_server_timeout;
|
398 |
} else {
|
399 |
$ping = $this->httpPing($server['ip']);
|
400 |
+
$ping *= 1000;
|
401 |
}
|
402 |
|
403 |
+
$tmp[(int)$ping] = $server;
|
404 |
|
405 |
+
$fast_server_found = $ping < $this->min_server_timeout;
|
406 |
|
407 |
}
|
408 |
|
418 |
|
419 |
/**
|
420 |
* Function to check response time
|
421 |
+
* @param string $host
|
422 |
+
* @return float|int
|
423 |
*/
|
424 |
+
public function httpPing($host){
|
425 |
|
426 |
// Skip localhost ping cause it raise error at fsockopen.
|
427 |
+
// And return minimum value
|
428 |
+
if ( $host === 'localhost') {
|
429 |
+
return 0.001;
|
430 |
+
}
|
431 |
|
432 |
$starttime = microtime(true);
|
433 |
$file = @fsockopen ($host, 80, $errno, $errstr, $this->max_server_timeout/1000);
|
443 |
|
444 |
return $status;
|
445 |
}
|
446 |
+
|
447 |
/**
|
448 |
+
* Send JSON request to servers
|
449 |
+
*
|
450 |
+
* @param string|array $data
|
451 |
+
* @param string $url
|
452 |
+
* @param int $server_timeout
|
453 |
+
*
|
454 |
+
* @return boolean|CleantalkResponse
|
455 |
+
*/
|
456 |
private function sendRequest($data, $url, $server_timeout = 3)
|
457 |
{
|
458 |
$original_args = func_get_args();
|
472 |
$data = json_encode($data);
|
473 |
|
474 |
if (isset($this->api_version)) {
|
475 |
+
$url .= $this->api_version;
|
476 |
}
|
477 |
|
478 |
$result = false;
|
494 |
$result = wp_remote_post($url, $args);
|
495 |
|
496 |
if( is_wp_error( $result ) ) {
|
|
|
497 |
$result = false;
|
498 |
}else{
|
499 |
+
$result = wp_remote_retrieve_body($result);
|
500 |
}
|
501 |
|
502 |
}else{
|
513 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); // resolve 'Expect: 100-continue' issue
|
514 |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // see http://stackoverflow.com/a/23322368
|
515 |
|
516 |
+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disabling CA cert verification and
|
517 |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // Disabling common name verification
|
518 |
|
519 |
if ($this->ssl_on && $this->ssl_path != '') {
|
536 |
|
537 |
if (!$result) {
|
538 |
$allow_url_fopen = ini_get('allow_url_fopen');
|
539 |
+
if ( function_exists('file_get_contents') && $allow_url_fopen ) {
|
540 |
$opts = array('http' =>
|
541 |
array(
|
542 |
'method' => 'POST',
|
554 |
if (!$result) {
|
555 |
$response = null;
|
556 |
$response['errno'] = 2;
|
557 |
+
if (! Helper::is_json($result)) {
|
558 |
$response['errstr'] = 'Wrong server response format: ' . substr( $result, 100 );
|
559 |
}
|
560 |
else {
|
563 |
: 'No CURL support compiled in';
|
564 |
$response['errstr'] .= ' or disabled allow_url_fopen in php.ini.';
|
565 |
}
|
566 |
+
|
567 |
+
return json_decode( json_encode( $response ) );
|
|
|
568 |
}
|
569 |
|
570 |
$errstr = null;
|
571 |
+
$response = is_string( $result ) ? json_decode( $result ) : false;
|
572 |
+
if ( $result !== false && is_object($response) ) {
|
573 |
$response->errno = 0;
|
574 |
$response->errstr = $errstr;
|
575 |
} else {
|
@@ -4,6 +4,7 @@ namespace Cleantalk\Antispam;
|
|
4 |
|
5 |
/**
|
6 |
* Request class
|
|
|
7 |
*/
|
8 |
class CleantalkRequest {
|
9 |
|
@@ -11,114 +12,120 @@ class CleantalkRequest {
|
|
11 |
* All http request headers
|
12 |
* @var string
|
13 |
*/
|
14 |
-
public $all_headers
|
15 |
|
16 |
/**
|
17 |
* IP address of connection
|
18 |
* @var string
|
19 |
*/
|
20 |
-
//public $remote_addr = null;
|
21 |
|
22 |
/**
|
23 |
* Last error number
|
24 |
* @var integer
|
25 |
*/
|
26 |
-
public $last_error_no
|
27 |
|
28 |
/**
|
29 |
* Last error time
|
30 |
* @var integer
|
31 |
*/
|
32 |
-
public $last_error_time
|
33 |
|
34 |
/**
|
35 |
* Last error text
|
36 |
* @var string
|
37 |
*/
|
38 |
-
public $last_error_text
|
39 |
|
40 |
/**
|
41 |
* User message
|
42 |
* @var string
|
43 |
*/
|
44 |
-
public $message
|
45 |
|
46 |
/**
|
47 |
* Post example with last comments
|
48 |
* @var string
|
49 |
*/
|
50 |
-
public $example
|
51 |
|
52 |
/**
|
53 |
* Auth key
|
54 |
* @var string
|
55 |
*/
|
56 |
-
public $auth_key
|
57 |
|
58 |
/**
|
59 |
* Engine
|
60 |
* @var string
|
61 |
*/
|
62 |
-
public $agent
|
63 |
|
64 |
/**
|
65 |
* Is check for stoplist,
|
66 |
* valid are 0|1
|
67 |
* @var int
|
68 |
*/
|
69 |
-
public $stoplist_check
|
70 |
|
71 |
/**
|
72 |
* Language server response,
|
73 |
* valid are 'en' or 'ru'
|
74 |
* @var string
|
75 |
*/
|
76 |
-
public $response_lang
|
77 |
|
78 |
/**
|
79 |
* User IP
|
80 |
-
* @var
|
81 |
*/
|
82 |
-
public $sender_ip
|
83 |
|
84 |
/**
|
85 |
* User email
|
86 |
-
* @var
|
87 |
*/
|
88 |
-
public $sender_email
|
89 |
|
90 |
/**
|
91 |
* User nickname
|
92 |
* @var string
|
93 |
*/
|
94 |
-
public $sender_nickname
|
95 |
|
96 |
/**
|
97 |
* Sender info JSON string
|
98 |
* @var string
|
99 |
*/
|
100 |
-
public $sender_info
|
101 |
|
102 |
/**
|
103 |
* Post info JSON string
|
104 |
* @var string
|
105 |
*/
|
106 |
-
public $post_info
|
107 |
|
108 |
/**
|
109 |
* Is allow links, email and icq,
|
110 |
* valid are 1|0
|
111 |
* @var int
|
112 |
*/
|
113 |
-
public $allow_links
|
114 |
|
115 |
/**
|
116 |
* Time form filling
|
117 |
* @var int
|
118 |
*/
|
119 |
-
public $submit_time
|
120 |
-
|
|
|
|
|
|
|
121 |
public $x_forwarded_for = '';
|
|
|
|
|
|
|
|
|
122 |
public $x_real_ip = '';
|
123 |
|
124 |
/**
|
@@ -130,26 +137,26 @@ class CleantalkRequest {
|
|
130 |
* 1 - JS enabled at the client broswer
|
131 |
* @var int
|
132 |
*/
|
133 |
-
public $js_on
|
134 |
|
135 |
/**
|
136 |
* user time zone
|
137 |
* @var string
|
138 |
*/
|
139 |
-
public $tz
|
140 |
|
141 |
/**
|
142 |
* Feedback string,
|
143 |
* valid are 'requset_id:(1|0)'
|
144 |
* @var string
|
145 |
*/
|
146 |
-
public $feedback
|
147 |
|
148 |
/**
|
149 |
* Phone number
|
150 |
-
* @var
|
151 |
*/
|
152 |
-
public $phone
|
153 |
|
154 |
/**
|
155 |
* Method name
|
@@ -164,7 +171,9 @@ class CleantalkRequest {
|
|
164 |
|
165 |
/**
|
166 |
* Fill params with constructor
|
167 |
-
* @param
|
|
|
|
|
168 |
*/
|
169 |
public function __construct($params = null) {
|
170 |
|
@@ -180,8 +189,9 @@ class CleantalkRequest {
|
|
180 |
|
181 |
// crunch for "PHP Notice: Array to string conversion". Error appears only on Gravity forms
|
182 |
// @todo fix gat_fields_any
|
183 |
-
if( isset( $params['sender_nickname'] ) && is_array( $params['sender_nickname'] ) )
|
184 |
-
|
|
|
185 |
|
186 |
$this->sender_nickname = !empty($params['sender_nickname']) ? (string)$params['sender_nickname'] : null;
|
187 |
$this->phone = !empty($params['phone']) ? (string)$params['phone'] : null;
|
4 |
|
5 |
/**
|
6 |
* Request class
|
7 |
+
* @psalm-suppress PossiblyUnusedProperty
|
8 |
*/
|
9 |
class CleantalkRequest {
|
10 |
|
12 |
* All http request headers
|
13 |
* @var string
|
14 |
*/
|
15 |
+
public $all_headers;
|
16 |
|
17 |
/**
|
18 |
* IP address of connection
|
19 |
* @var string
|
20 |
*/
|
|
|
21 |
|
22 |
/**
|
23 |
* Last error number
|
24 |
* @var integer
|
25 |
*/
|
26 |
+
public $last_error_no;
|
27 |
|
28 |
/**
|
29 |
* Last error time
|
30 |
* @var integer
|
31 |
*/
|
32 |
+
public $last_error_time;
|
33 |
|
34 |
/**
|
35 |
* Last error text
|
36 |
* @var string
|
37 |
*/
|
38 |
+
public $last_error_text;
|
39 |
|
40 |
/**
|
41 |
* User message
|
42 |
* @var string
|
43 |
*/
|
44 |
+
public $message;
|
45 |
|
46 |
/**
|
47 |
* Post example with last comments
|
48 |
* @var string
|
49 |
*/
|
50 |
+
public $example;
|
51 |
|
52 |
/**
|
53 |
* Auth key
|
54 |
* @var string
|
55 |
*/
|
56 |
+
public $auth_key;
|
57 |
|
58 |
/**
|
59 |
* Engine
|
60 |
* @var string
|
61 |
*/
|
62 |
+
public $agent;
|
63 |
|
64 |
/**
|
65 |
* Is check for stoplist,
|
66 |
* valid are 0|1
|
67 |
* @var int
|
68 |
*/
|
69 |
+
public $stoplist_check;
|
70 |
|
71 |
/**
|
72 |
* Language server response,
|
73 |
* valid are 'en' or 'ru'
|
74 |
* @var string
|
75 |
*/
|
76 |
+
public $response_lang;
|
77 |
|
78 |
/**
|
79 |
* User IP
|
80 |
+
* @var string
|
81 |
*/
|
82 |
+
public $sender_ip;
|
83 |
|
84 |
/**
|
85 |
* User email
|
86 |
+
* @var string
|
87 |
*/
|
88 |
+
public $sender_email;
|
89 |
|
90 |
/**
|
91 |
* User nickname
|
92 |
* @var string
|
93 |
*/
|
94 |
+
public $sender_nickname;
|
95 |
|
96 |
/**
|
97 |
* Sender info JSON string
|
98 |
* @var string
|
99 |
*/
|
100 |
+
public $sender_info;
|
101 |
|
102 |
/**
|
103 |
* Post info JSON string
|
104 |
* @var string
|
105 |
*/
|
106 |
+
public $post_info;
|
107 |
|
108 |
/**
|
109 |
* Is allow links, email and icq,
|
110 |
* valid are 1|0
|
111 |
* @var int
|
112 |
*/
|
113 |
+
public $allow_links;
|
114 |
|
115 |
/**
|
116 |
* Time form filling
|
117 |
* @var int
|
118 |
*/
|
119 |
+
public $submit_time;
|
120 |
+
|
121 |
+
/**
|
122 |
+
* @var string|null
|
123 |
+
*/
|
124 |
public $x_forwarded_for = '';
|
125 |
+
|
126 |
+
/**
|
127 |
+
* @var string|null
|
128 |
+
*/
|
129 |
public $x_real_ip = '';
|
130 |
|
131 |
/**
|
137 |
* 1 - JS enabled at the client broswer
|
138 |
* @var int
|
139 |
*/
|
140 |
+
public $js_on;
|
141 |
|
142 |
/**
|
143 |
* user time zone
|
144 |
* @var string
|
145 |
*/
|
146 |
+
public $tz;
|
147 |
|
148 |
/**
|
149 |
* Feedback string,
|
150 |
* valid are 'requset_id:(1|0)'
|
151 |
* @var string
|
152 |
*/
|
153 |
+
public $feedback;
|
154 |
|
155 |
/**
|
156 |
* Phone number
|
157 |
+
* @var string
|
158 |
*/
|
159 |
+
public $phone;
|
160 |
|
161 |
/**
|
162 |
* Method name
|
171 |
|
172 |
/**
|
173 |
* Fill params with constructor
|
174 |
+
* @param array $params
|
175 |
+
* @psalm-suppress PossiblyUnusedMethod
|
176 |
+
* @psalm-suppress InvalidPropertyAssignmentValue
|
177 |
*/
|
178 |
public function __construct($params = null) {
|
179 |
|
189 |
|
190 |
// crunch for "PHP Notice: Array to string conversion". Error appears only on Gravity forms
|
191 |
// @todo fix gat_fields_any
|
192 |
+
if( isset( $params['sender_nickname'] ) && is_array( $params['sender_nickname'] ) ) {
|
193 |
+
$params['sender_nickname'] = current( $params['sender_nickname'] );
|
194 |
+
}
|
195 |
|
196 |
$this->sender_nickname = !empty($params['sender_nickname']) ? (string)$params['sender_nickname'] : null;
|
197 |
$this->phone = !empty($params['phone']) ? (string)$params['phone'] : null;
|
@@ -4,110 +4,111 @@ namespace Cleantalk\Antispam;
|
|
4 |
|
5 |
/**
|
6 |
* Response class
|
|
|
7 |
*/
|
8 |
class CleantalkResponse {
|
9 |
|
10 |
/**
|
11 |
-
* Received feedback
|
12 |
* @var int
|
13 |
*/
|
14 |
-
public $received
|
15 |
|
16 |
/**
|
17 |
* Is stop words
|
18 |
-
* @var
|
19 |
*/
|
20 |
-
public $stop_words
|
21 |
|
22 |
/**
|
23 |
* Cleantalk comment
|
24 |
-
* @var string
|
25 |
*/
|
26 |
-
public $comment
|
27 |
|
28 |
/**
|
29 |
* Is blacklisted
|
30 |
* @var int
|
31 |
*/
|
32 |
-
public $blacklisted
|
33 |
|
34 |
/**
|
35 |
* Is allow, 1|0
|
36 |
* @var int
|
37 |
*/
|
38 |
-
public $allow
|
39 |
|
40 |
/**
|
41 |
* Request ID
|
42 |
* @var int
|
43 |
*/
|
44 |
-
public $id
|
45 |
|
46 |
/**
|
47 |
* Request errno
|
48 |
* @var int
|
49 |
*/
|
50 |
-
public $errno
|
51 |
|
52 |
/**
|
53 |
* Error string
|
54 |
* @var string
|
55 |
*/
|
56 |
-
public $errstr
|
57 |
|
58 |
/**
|
59 |
* Is fast submit, 1|0
|
60 |
* @var string
|
61 |
*/
|
62 |
-
public $fast_submit
|
63 |
|
64 |
/**
|
65 |
* Is spam comment
|
66 |
* @var string
|
67 |
*/
|
68 |
-
public $spam
|
69 |
|
70 |
/**
|
71 |
* Is JS
|
72 |
-
* @var
|
73 |
*/
|
74 |
-
public $js_disabled
|
75 |
|
76 |
/**
|
77 |
* Sms check
|
78 |
-
* @var
|
79 |
*/
|
80 |
-
public $sms_allow
|
81 |
|
82 |
/**
|
83 |
* Sms code result
|
84 |
-
* @var
|
85 |
*/
|
86 |
-
public $sms
|
87 |
|
88 |
/**
|
89 |
* Sms error code
|
90 |
-
* @var
|
91 |
*/
|
92 |
-
public $sms_error_code
|
93 |
|
94 |
/**
|
95 |
* Sms error code
|
96 |
-
* @var
|
97 |
*/
|
98 |
-
public $sms_error_text
|
99 |
|
100 |
/**
|
101 |
* Stop queue message, 1|0
|
102 |
* @var int
|
103 |
*/
|
104 |
-
public $stop_queue
|
105 |
|
106 |
/**
|
107 |
-
* Account
|
108 |
* @var int
|
109 |
*/
|
110 |
-
public $inactive
|
111 |
|
112 |
/**
|
113 |
* Account status
|
@@ -123,38 +124,33 @@ class CleantalkResponse {
|
|
123 |
/**
|
124 |
* Create server response
|
125 |
*
|
126 |
-
* @param
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
$this->codes = (isset($obj->codes)) ? explode(' ', $obj->codes) : array();
|
155 |
-
|
156 |
-
if ($this->errno !== 0 && $this->errstr !== null && $this->comment === null)
|
157 |
-
$this->comment = '*** ' . $this->errstr . ' Antispam service cleantalk.org ***';
|
158 |
-
}
|
159 |
}
|
160 |
}
|
4 |
|
5 |
/**
|
6 |
* Response class
|
7 |
+
* @psalm-suppress PossiblyUnusedProperty
|
8 |
*/
|
9 |
class CleantalkResponse {
|
10 |
|
11 |
/**
|
12 |
+
* Received feedback number
|
13 |
* @var int
|
14 |
*/
|
15 |
+
public $received;
|
16 |
|
17 |
/**
|
18 |
* Is stop words
|
19 |
+
* @var null|string
|
20 |
*/
|
21 |
+
public $stop_words;
|
22 |
|
23 |
/**
|
24 |
* Cleantalk comment
|
25 |
+
* @var null|string
|
26 |
*/
|
27 |
+
public $comment;
|
28 |
|
29 |
/**
|
30 |
* Is blacklisted
|
31 |
* @var int
|
32 |
*/
|
33 |
+
public $blacklisted;
|
34 |
|
35 |
/**
|
36 |
* Is allow, 1|0
|
37 |
* @var int
|
38 |
*/
|
39 |
+
public $allow;
|
40 |
|
41 |
/**
|
42 |
* Request ID
|
43 |
* @var int
|
44 |
*/
|
45 |
+
public $id;
|
46 |
|
47 |
/**
|
48 |
* Request errno
|
49 |
* @var int
|
50 |
*/
|
51 |
+
public $errno;
|
52 |
|
53 |
/**
|
54 |
* Error string
|
55 |
* @var string
|
56 |
*/
|
57 |
+
public $errstr;
|
58 |
|
59 |
/**
|
60 |
* Is fast submit, 1|0
|
61 |
* @var string
|
62 |
*/
|
63 |
+
public $fast_submit;
|
64 |
|
65 |
/**
|
66 |
* Is spam comment
|
67 |
* @var string
|
68 |
*/
|
69 |
+
public $spam;
|
70 |
|
71 |
/**
|
72 |
* Is JS
|
73 |
+
* @var int
|
74 |
*/
|
75 |
+
public $js_disabled;
|
76 |
|
77 |
/**
|
78 |
* Sms check
|
79 |
+
* @var int
|
80 |
*/
|
81 |
+
public $sms_allow;
|
82 |
|
83 |
/**
|
84 |
* Sms code result
|
85 |
+
* @var int
|
86 |
*/
|
87 |
+
public $sms;
|
88 |
|
89 |
/**
|
90 |
* Sms error code
|
91 |
+
* @var int
|
92 |
*/
|
93 |
+
public $sms_error_code;
|
94 |
|
95 |
/**
|
96 |
* Sms error code
|
97 |
+
* @var string
|
98 |
*/
|
99 |
+
public $sms_error_text;
|
100 |
|
101 |
/**
|
102 |
* Stop queue message, 1|0
|
103 |
* @var int
|
104 |
*/
|
105 |
+
public $stop_queue;
|
106 |
|
107 |
/**
|
108 |
+
* Account should by deactivated after registration, 1|0
|
109 |
* @var int
|
110 |
*/
|
111 |
+
public $inactive;
|
112 |
|
113 |
/**
|
114 |
* Account status
|
124 |
/**
|
125 |
* Create server response
|
126 |
*
|
127 |
+
* @param object $obj
|
128 |
+
*/
|
129 |
+
public function __construct( $obj = null ) {
|
130 |
+
|
131 |
+
$this->errno = isset($obj->errno) ? $obj->errno : 0;
|
132 |
+
$this->errstr = isset($obj->errstr) ? preg_replace("/.+(\*\*\*.+\*\*\*).+/", "$1", $obj->errstr) : null;
|
133 |
+
|
134 |
+
$this->stop_words = isset($obj->stop_words) ? utf8_decode($obj->stop_words) : null;
|
135 |
+
$this->comment = isset($obj->comment) ? utf8_decode($obj->comment) : null;
|
136 |
+
$this->blacklisted = isset($obj->blacklisted) ? $obj->blacklisted : null;
|
137 |
+
$this->allow = isset($obj->allow) ? $obj->allow : 1;
|
138 |
+
$this->id = isset($obj->id) ? $obj->id : null;
|
139 |
+
$this->fast_submit = isset($obj->fast_submit) ? $obj->fast_submit : 0;
|
140 |
+
$this->spam = isset($obj->spam) ? $obj->spam : 0;
|
141 |
+
$this->js_disabled = isset($obj->js_disabled) ? $obj->js_disabled : 0;
|
142 |
+
$this->sms_allow = isset($obj->sms_allow) ? $obj->sms_allow : null;
|
143 |
+
$this->sms = isset($obj->sms) ? $obj->sms : null;
|
144 |
+
$this->sms_error_code = isset($obj->sms_error_code) ? $obj->sms_error_code : null;
|
145 |
+
$this->sms_error_text = isset($obj->sms_error_text) ? $obj->sms_error_text : null;
|
146 |
+
$this->stop_queue = isset($obj->stop_queue) ? $obj->stop_queue : 0;
|
147 |
+
$this->inactive = isset($obj->inactive) ? $obj->inactive : 0;
|
148 |
+
$this->account_status = isset($obj->account_status) ? $obj->account_status : -1;
|
149 |
+
$this->received = isset($obj->received) ? $obj->received : -1;
|
150 |
+
$this->codes = isset($obj->codes) ? explode(' ', $obj->codes) : array();
|
151 |
+
|
152 |
+
if ($this->errno !== 0 && $this->errstr !== null && $this->comment === null) {
|
153 |
+
$this->comment = '*** ' . $this->errstr . ' Antispam service cleantalk.org ***';
|
154 |
+
}
|
|
|
|
|
|
|
|
|
|
|
155 |
}
|
156 |
}
|
@@ -2,6 +2,8 @@
|
|
2 |
|
3 |
namespace Cleantalk\Antispam;
|
4 |
|
|
|
|
|
5 |
/**
|
6 |
* Class DisableComments
|
7 |
* Discribes functions needed to use disable comments functionality
|
@@ -14,7 +16,7 @@ namespace Cleantalk\Antispam;
|
|
14 |
*/
|
15 |
class DisableComments{
|
16 |
|
17 |
-
use
|
18 |
|
19 |
/**
|
20 |
* Determs is Wordpress Multisite is enabled
|
@@ -31,7 +33,7 @@ class DisableComments{
|
|
31 |
private $types_to_disable;
|
32 |
|
33 |
/**
|
34 |
-
* @var
|
35 |
*/
|
36 |
private $apbct;
|
37 |
|
@@ -49,10 +51,12 @@ class DisableComments{
|
|
49 |
if( $this->apbct->settings['comments__disable_comments__all'] ){
|
50 |
$types_to_disable = array( 'page', 'post', 'media', 'attachment' );
|
51 |
}else{
|
52 |
-
if( $this->apbct->settings['comments__disable_comments__posts'] )
|
53 |
$types_to_disable[] = 'post';
|
54 |
-
|
|
|
55 |
$types_to_disable[] = 'page';
|
|
|
56 |
if( $this->apbct->settings['comments__disable_comments__media'] ){
|
57 |
$types_to_disable[] = 'media';
|
58 |
$types_to_disable[] = 'attachment';
|
@@ -71,9 +75,14 @@ class DisableComments{
|
|
71 |
add_action( 'enqueue_block_editor_assets', array( $this, 'filter__gutenberg_blocks' ) );
|
72 |
|
73 |
}
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
public function is_current_type_to_disable( $type = '' ){
|
76 |
-
$type = $type
|
77 |
return in_array( $type, $this->types_to_disable );
|
78 |
}
|
79 |
|
@@ -86,7 +95,6 @@ class DisableComments{
|
|
86 |
foreach ( $this->types_to_disable as $type ){
|
87 |
// we need to know what native support was for later
|
88 |
if( post_type_supports( $type, 'comments' ) ){
|
89 |
-
// $this->modified_types[] = $type;
|
90 |
remove_post_type_support( $type, 'comments' );
|
91 |
remove_post_type_support( $type, 'trackbacks' );
|
92 |
}
|
@@ -118,7 +126,7 @@ class DisableComments{
|
|
118 |
unregister_widget( 'WP_Widget_Recent_Comments' );
|
119 |
}
|
120 |
|
121 |
-
function admin__filter_css(){
|
122 |
echo '<style>
|
123 |
#dashboard_right_now .comment-count,
|
124 |
#dashboard_right_now .comment-mod-count,
|
@@ -137,14 +145,15 @@ class DisableComments{
|
|
137 |
public function admin__filter_menu(){
|
138 |
global $pagenow;
|
139 |
|
140 |
-
if( in_array( $pagenow, array( 'comment.php', 'edit-comments.php', 'options-discussion.php' ) ) )
|
141 |
wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
|
|
|
142 |
|
143 |
remove_menu_page( 'edit-comments.php' );
|
144 |
remove_submenu_page( 'options-general.php', 'options-discussion.php' );
|
145 |
}
|
146 |
|
147 |
-
public function template__check( $count, $
|
148 |
if( is_singular() && $this->is_current_type_to_disable() ){
|
149 |
add_filter( 'comments_template', array( $this, 'template__replace' ), 20 );
|
150 |
wp_deregister_script( 'comment-reply' );
|
@@ -161,9 +170,10 @@ class DisableComments{
|
|
161 |
return $headers;
|
162 |
}
|
163 |
|
164 |
-
public function filter__query( $
|
165 |
-
if( is_comment_feed() )
|
166 |
wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
|
|
|
167 |
}
|
168 |
|
169 |
public function filter__admin_bar(){
|
@@ -178,14 +188,14 @@ class DisableComments{
|
|
178 |
/**
|
179 |
* Determines if scripts should be enqueued
|
180 |
*/
|
181 |
-
public function filter__gutenberg_blocks( $
|
182 |
if( $this->is_current_type_to_disable() ){
|
183 |
wp_enqueue_script(
|
184 |
'cleantalk-disable-comments-gutenberg',
|
185 |
plugin_dir_url( __FILE__ ) . 'assets/apbct-disable-comments.js',
|
186 |
array(),
|
187 |
APBCT_VERSION,
|
188 |
-
|
189 |
);
|
190 |
wp_localize_script(
|
191 |
'cleantalk-disable-comments-gutenberg',
|
@@ -197,15 +207,15 @@ class DisableComments{
|
|
197 |
}
|
198 |
}
|
199 |
|
200 |
-
public function filter__existing_comments( $comments, $
|
201 |
return $this->is_current_type_to_disable() ? array() : $comments;
|
202 |
}
|
203 |
|
204 |
-
public function filter__comment_status( $open, $
|
205 |
return $this->is_current_type_to_disable() ? false : $open;
|
206 |
}
|
207 |
|
208 |
-
public function filter__comments_number( $count, $
|
209 |
return $this->is_current_type_to_disable() ? 0 : $count;
|
210 |
}
|
211 |
|
@@ -216,8 +226,9 @@ class DisableComments{
|
|
216 |
$wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' );
|
217 |
}
|
218 |
|
219 |
-
}else
|
220 |
$wp_admin_bar->remove_menu( 'blog-' . get_current_blog_id() . '-c' );
|
|
|
221 |
|
222 |
}
|
223 |
}
|
2 |
|
3 |
namespace Cleantalk\Antispam;
|
4 |
|
5 |
+
use Cleantalk\Templates\Singleton;
|
6 |
+
|
7 |
/**
|
8 |
* Class DisableComments
|
9 |
* Discribes functions needed to use disable comments functionality
|
16 |
*/
|
17 |
class DisableComments{
|
18 |
|
19 |
+
use Singleton;
|
20 |
|
21 |
/**
|
22 |
* Determs is Wordpress Multisite is enabled
|
33 |
private $types_to_disable;
|
34 |
|
35 |
/**
|
36 |
+
* @var \Cleantalk\ApbctWP\State antispam instance
|
37 |
*/
|
38 |
private $apbct;
|
39 |
|
51 |
if( $this->apbct->settings['comments__disable_comments__all'] ){
|
52 |
$types_to_disable = array( 'page', 'post', 'media', 'attachment' );
|
53 |
}else{
|
54 |
+
if( $this->apbct->settings['comments__disable_comments__posts'] ) {
|
55 |
$types_to_disable[] = 'post';
|
56 |
+
}
|
57 |
+
if( $this->apbct->settings['comments__disable_comments__pages'] ) {
|
58 |
$types_to_disable[] = 'page';
|
59 |
+
}
|
60 |
if( $this->apbct->settings['comments__disable_comments__media'] ){
|
61 |
$types_to_disable[] = 'media';
|
62 |
$types_to_disable[] = 'attachment';
|
75 |
add_action( 'enqueue_block_editor_assets', array( $this, 'filter__gutenberg_blocks' ) );
|
76 |
|
77 |
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @param string|bool $type
|
81 |
+
*
|
82 |
+
* @return bool
|
83 |
+
*/
|
84 |
public function is_current_type_to_disable( $type = '' ){
|
85 |
+
$type = $type ?: get_post_type();
|
86 |
return in_array( $type, $this->types_to_disable );
|
87 |
}
|
88 |
|
95 |
foreach ( $this->types_to_disable as $type ){
|
96 |
// we need to know what native support was for later
|
97 |
if( post_type_supports( $type, 'comments' ) ){
|
|
|
98 |
remove_post_type_support( $type, 'comments' );
|
99 |
remove_post_type_support( $type, 'trackbacks' );
|
100 |
}
|
126 |
unregister_widget( 'WP_Widget_Recent_Comments' );
|
127 |
}
|
128 |
|
129 |
+
public function admin__filter_css(){
|
130 |
echo '<style>
|
131 |
#dashboard_right_now .comment-count,
|
132 |
#dashboard_right_now .comment-mod-count,
|
145 |
public function admin__filter_menu(){
|
146 |
global $pagenow;
|
147 |
|
148 |
+
if( in_array( $pagenow, array( 'comment.php', 'edit-comments.php', 'options-discussion.php' ) ) ) {
|
149 |
wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
|
150 |
+
}
|
151 |
|
152 |
remove_menu_page( 'edit-comments.php' );
|
153 |
remove_submenu_page( 'options-general.php', 'options-discussion.php' );
|
154 |
}
|
155 |
|
156 |
+
public function template__check( $count, $_post_id ){
|
157 |
if( is_singular() && $this->is_current_type_to_disable() ){
|
158 |
add_filter( 'comments_template', array( $this, 'template__replace' ), 20 );
|
159 |
wp_deregister_script( 'comment-reply' );
|
170 |
return $headers;
|
171 |
}
|
172 |
|
173 |
+
public function filter__query( $_headers ){
|
174 |
+
if( is_comment_feed() ) {
|
175 |
wp_die( __( 'Comments are closed.' ), '', array( 'response' => 403 ) );
|
176 |
+
}
|
177 |
}
|
178 |
|
179 |
public function filter__admin_bar(){
|
188 |
/**
|
189 |
* Determines if scripts should be enqueued
|
190 |
*/
|
191 |
+
public function filter__gutenberg_blocks( $_hook ){
|
192 |
if( $this->is_current_type_to_disable() ){
|
193 |
wp_enqueue_script(
|
194 |
'cleantalk-disable-comments-gutenberg',
|
195 |
plugin_dir_url( __FILE__ ) . 'assets/apbct-disable-comments.js',
|
196 |
array(),
|
197 |
APBCT_VERSION,
|
198 |
+
true
|
199 |
);
|
200 |
wp_localize_script(
|
201 |
'cleantalk-disable-comments-gutenberg',
|
207 |
}
|
208 |
}
|
209 |
|
210 |
+
public function filter__existing_comments( $comments, $_post_id ){
|
211 |
return $this->is_current_type_to_disable() ? array() : $comments;
|
212 |
}
|
213 |
|
214 |
+
public function filter__comment_status( $open, $_post_id ){
|
215 |
return $this->is_current_type_to_disable() ? false : $open;
|
216 |
}
|
217 |
|
218 |
+
public function filter__comments_number( $count, $_post_id ){
|
219 |
return $this->is_current_type_to_disable() ? 0 : $count;
|
220 |
}
|
221 |
|
226 |
$wp_admin_bar->remove_menu( 'blog-' . $blog->userblog_id . '-c' );
|
227 |
}
|
228 |
|
229 |
+
}else {
|
230 |
$wp_admin_bar->remove_menu( 'blog-' . get_current_blog_id() . '-c' );
|
231 |
+
}
|
232 |
|
233 |
}
|
234 |
}
|
@@ -7,11 +7,9 @@ namespace Cleantalk\Antispam;
|
|
7 |
class Integrations
|
8 |
{
|
9 |
|
10 |
-
private $integrations
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
/**
|
15 |
* Integrations constructor.
|
16 |
*
|
17 |
* @param array $integrations
|
@@ -21,7 +19,7 @@ class Integrations
|
|
21 |
{
|
22 |
$this->integrations = $integrations;
|
23 |
|
24 |
-
foreach( $this->integrations as $
|
25 |
|
26 |
if( empty( $settings[ $integration_info['setting'] ] ) )
|
27 |
continue;
|
@@ -49,6 +47,10 @@ class Integrations
|
|
49 |
}
|
50 |
}
|
51 |
|
|
|
|
|
|
|
|
|
52 |
public function checkSpam( $argument )
|
53 |
{
|
54 |
global $cleantalk_executed;
|
@@ -59,14 +61,14 @@ class Integrations
|
|
59 |
// Instantiate the integration object
|
60 |
$class = '\\Cleantalk\\Antispam\\Integrations\\' . $current_integration;
|
61 |
if( class_exists( $class )) {
|
62 |
-
$
|
63 |
-
if( ! ( $
|
64 |
// @ToDo have to handle an error
|
65 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, array('Integration is not instanse of IntegrationBase class.') );
|
66 |
return;
|
67 |
}
|
68 |
// Run data collecting for spam checking
|
69 |
-
$data = $
|
70 |
if( ! is_null( $data ) ) {
|
71 |
// Go spam checking
|
72 |
$base_call_result = apbct_base_call(
|
@@ -88,11 +90,11 @@ class Integrations
|
|
88 |
|
89 |
if ($ct_result->allow == 0) {
|
90 |
// Do blocking if it is a spam
|
91 |
-
return $
|
92 |
}
|
93 |
|
94 |
-
if($ct_result->allow != 0 && method_exists($
|
95 |
-
return $
|
96 |
}
|
97 |
} else {
|
98 |
// @ToDo have to handle an error
|
7 |
class Integrations
|
8 |
{
|
9 |
|
10 |
+
private $integrations;
|
11 |
|
12 |
+
/**
|
|
|
|
|
13 |
* Integrations constructor.
|
14 |
*
|
15 |
* @param array $integrations
|
19 |
{
|
20 |
$this->integrations = $integrations;
|
21 |
|
22 |
+
foreach( $this->integrations as $_integration_name => $integration_info ){
|
23 |
|
24 |
if( empty( $settings[ $integration_info['setting'] ] ) )
|
25 |
continue;
|
47 |
}
|
48 |
}
|
49 |
|
50 |
+
/**
|
51 |
+
* @param $argument
|
52 |
+
* @psalm-suppress UnusedVariable
|
53 |
+
*/
|
54 |
public function checkSpam( $argument )
|
55 |
{
|
56 |
global $cleantalk_executed;
|
61 |
// Instantiate the integration object
|
62 |
$class = '\\Cleantalk\\Antispam\\Integrations\\' . $current_integration;
|
63 |
if( class_exists( $class )) {
|
64 |
+
$integration = new $class();
|
65 |
+
if( ! ( $integration instanceof \Cleantalk\Antispam\Integrations\IntegrationBase ) ) {
|
66 |
// @ToDo have to handle an error
|
67 |
do_action( 'apbct_skipped_request', __FILE__ . ' -> ' . __FUNCTION__ . '():' . __LINE__, array('Integration is not instanse of IntegrationBase class.') );
|
68 |
return;
|
69 |
}
|
70 |
// Run data collecting for spam checking
|
71 |
+
$data = $integration->getDataForChecking( $argument );
|
72 |
if( ! is_null( $data ) ) {
|
73 |
// Go spam checking
|
74 |
$base_call_result = apbct_base_call(
|
90 |
|
91 |
if ($ct_result->allow == 0) {
|
92 |
// Do blocking if it is a spam
|
93 |
+
return $integration->doBlock( $ct_result->comment );
|
94 |
}
|
95 |
|
96 |
+
if($ct_result->allow != 0 && method_exists( $integration, 'allow')) {
|
97 |
+
return $integration->allow();
|
98 |
}
|
99 |
} else {
|
100 |
// @ToDo have to handle an error
|
@@ -7,7 +7,7 @@ namespace Cleantalk\Antispam\Integrations;
|
|
7 |
class ContactBank extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
-
function getDataForChecking( $argument )
|
11 |
{
|
12 |
if( isset( $_REQUEST['param'] ) ) {
|
13 |
parse_str( isset( $_REQUEST['data'] ) ? base64_decode( $_REQUEST['data'] ) : '', $form_data );
|
@@ -16,7 +16,7 @@ class ContactBank extends IntegrationBase
|
|
16 |
return null;
|
17 |
}
|
18 |
|
19 |
-
function doBlock( $message )
|
20 |
{
|
21 |
die(json_encode(array('apbct' => array('blocked' => true, 'comment' => $message,)), JSON_HEX_QUOT | JSON_HEX_TAG));
|
22 |
}
|
7 |
class ContactBank extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
+
public function getDataForChecking( $argument )
|
11 |
{
|
12 |
if( isset( $_REQUEST['param'] ) ) {
|
13 |
parse_str( isset( $_REQUEST['data'] ) ? base64_decode( $_REQUEST['data'] ) : '', $form_data );
|
16 |
return null;
|
17 |
}
|
18 |
|
19 |
+
public function doBlock( $message )
|
20 |
{
|
21 |
die(json_encode(array('apbct' => array('blocked' => true, 'comment' => $message,)), JSON_HEX_QUOT | JSON_HEX_TAG));
|
22 |
}
|
@@ -12,6 +12,10 @@ class EaelLoginRegister extends IntegrationBase {
|
|
12 |
return $data;
|
13 |
}
|
14 |
|
|
|
|
|
|
|
|
|
15 |
public function doBlock( $message ) {
|
16 |
global $ct_comment;
|
17 |
$ct_comment = $message;
|
12 |
return $data;
|
13 |
}
|
14 |
|
15 |
+
/**
|
16 |
+
* @param $message
|
17 |
+
* @psalm-suppress UnusedVariable
|
18 |
+
*/
|
19 |
public function doBlock( $message ) {
|
20 |
global $ct_comment;
|
21 |
$ct_comment = $message;
|
@@ -7,15 +7,15 @@ namespace Cleantalk\Antispam\Integrations;
|
|
7 |
class ElfsightContactForm extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
-
function getDataForChecking( $argument )
|
11 |
{
|
12 |
-
if( isset( $_POST
|
13 |
return ct_get_fields_any( $_POST['fields'] );
|
14 |
}
|
15 |
return null;
|
16 |
}
|
17 |
|
18 |
-
function doBlock( $message )
|
19 |
{
|
20 |
header( 'Content-type: application/json; charset=utf-8' );
|
21 |
exit( json_encode( array( 400, $message ) ) );
|
7 |
class ElfsightContactForm extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
+
public function getDataForChecking( $argument )
|
11 |
{
|
12 |
+
if( isset( $_POST['fields'] ) ) {
|
13 |
return ct_get_fields_any( $_POST['fields'] );
|
14 |
}
|
15 |
return null;
|
16 |
}
|
17 |
|
18 |
+
public function doBlock( $message )
|
19 |
{
|
20 |
header( 'Content-type: application/json; charset=utf-8' );
|
21 |
exit( json_encode( array( 400, $message ) ) );
|
@@ -7,7 +7,7 @@ namespace Cleantalk\Antispam\Integrations;
|
|
7 |
class EstimationForm extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
-
function getDataForChecking( $argument )
|
11 |
{
|
12 |
if( isset( $_POST['customerInfos'] ) ) {
|
13 |
return ct_get_fields_any( $_POST['customerInfos'] );
|
@@ -15,7 +15,7 @@ class EstimationForm extends IntegrationBase
|
|
15 |
return null;
|
16 |
}
|
17 |
|
18 |
-
function doBlock( $message )
|
19 |
{
|
20 |
die(json_encode(array( 'apbct' => array(
|
21 |
'blocked' => true,
|
7 |
class EstimationForm extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
+
public function getDataForChecking( $argument )
|
11 |
{
|
12 |
if( isset( $_POST['customerInfos'] ) ) {
|
13 |
return ct_get_fields_any( $_POST['customerInfos'] );
|
15 |
return null;
|
16 |
}
|
17 |
|
18 |
+
public function doBlock( $message )
|
19 |
{
|
20 |
die(json_encode(array( 'apbct' => array(
|
21 |
'blocked' => true,
|
@@ -1,31 +1,31 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
namespace Cleantalk\Antispam\Integrations;
|
5 |
-
|
6 |
-
|
7 |
-
class FluentForm extends IntegrationBase
|
8 |
-
{
|
9 |
-
|
10 |
-
function getDataForChecking( $argument )
|
11 |
-
{
|
12 |
-
if( isset( $_POST['data'] ) ) {
|
13 |
-
parse_str( $_POST['data'], $form_data );
|
14 |
-
return ct_get_fields_any($form_data);
|
15 |
-
}
|
16 |
-
return null;
|
17 |
-
}
|
18 |
-
|
19 |
-
function doBlock($message)
|
20 |
-
{
|
21 |
-
wp_send_json(
|
22 |
-
array(
|
23 |
-
'errors' => array(
|
24 |
-
'restricted' => array(
|
25 |
-
$message
|
26 |
-
)
|
27 |
-
)
|
28 |
-
), 422
|
29 |
-
);
|
30 |
-
}
|
31 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
namespace Cleantalk\Antispam\Integrations;
|
5 |
+
|
6 |
+
|
7 |
+
class FluentForm extends IntegrationBase
|
8 |
+
{
|
9 |
+
|
10 |
+
public function getDataForChecking( $argument )
|
11 |
+
{
|
12 |
+
if( isset( $_POST['data'] ) ) {
|
13 |
+
parse_str( $_POST['data'], $form_data );
|
14 |
+
return ct_get_fields_any($form_data);
|
15 |
+
}
|
16 |
+
return null;
|
17 |
+
}
|
18 |
+
|
19 |
+
public function doBlock($message)
|
20 |
+
{
|
21 |
+
wp_send_json(
|
22 |
+
array(
|
23 |
+
'errors' => array(
|
24 |
+
'restricted' => array(
|
25 |
+
$message
|
26 |
+
)
|
27 |
+
)
|
28 |
+
), 422
|
29 |
+
);
|
30 |
+
}
|
31 |
}
|
@@ -6,14 +6,14 @@ namespace Cleantalk\Antispam\Integrations;
|
|
6 |
|
7 |
class Forminator extends IntegrationBase {
|
8 |
|
9 |
-
function getDataForChecking( $argument ) {
|
10 |
-
if(
|
11 |
return ct_get_fields_any( $_POST );
|
12 |
}
|
13 |
return null;
|
14 |
}
|
15 |
|
16 |
-
function doBlock( $message ) {
|
17 |
wp_send_json_error(
|
18 |
array(
|
19 |
'message' => $message,
|
6 |
|
7 |
class Forminator extends IntegrationBase {
|
8 |
|
9 |
+
public function getDataForChecking( $argument ) {
|
10 |
+
if( ! empty( $_POST ) ) {
|
11 |
return ct_get_fields_any( $_POST );
|
12 |
}
|
13 |
return null;
|
14 |
}
|
15 |
|
16 |
+
public function doBlock( $message ) {
|
17 |
wp_send_json_error(
|
18 |
array(
|
19 |
'message' => $message,
|
@@ -7,15 +7,15 @@ namespace Cleantalk\Antispam\Integrations;
|
|
7 |
class LandingPageBuilder extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
-
function getDataForChecking( $argument )
|
11 |
{
|
12 |
-
if(
|
13 |
return ct_get_fields_any( $_POST );
|
14 |
}
|
15 |
return null;
|
16 |
}
|
17 |
|
18 |
-
function doBlock( $message )
|
19 |
{
|
20 |
$return['Error'] = $message;
|
21 |
$return['database'] = 'false';
|
7 |
class LandingPageBuilder extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
+
public function getDataForChecking( $argument )
|
11 |
{
|
12 |
+
if( ! empty( $_POST ) ) {
|
13 |
return ct_get_fields_any( $_POST );
|
14 |
}
|
15 |
return null;
|
16 |
}
|
17 |
|
18 |
+
public function doBlock( $message )
|
19 |
{
|
20 |
$return['Error'] = $message;
|
21 |
$return['database'] = 'false';
|
@@ -7,12 +7,12 @@ namespace Cleantalk\Antispam\Integrations;
|
|
7 |
class Rafflepress extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
-
function getDataForChecking( $argument )
|
11 |
{
|
12 |
return ct_get_fields_any( $_POST );
|
13 |
}
|
14 |
|
15 |
-
function doBlock( $message )
|
16 |
{
|
17 |
wp_send_json(
|
18 |
array(
|
7 |
class Rafflepress extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
+
public function getDataForChecking( $argument )
|
11 |
{
|
12 |
return ct_get_fields_any( $_POST );
|
13 |
}
|
14 |
|
15 |
+
public function doBlock( $message )
|
16 |
{
|
17 |
wp_send_json(
|
18 |
array(
|
@@ -9,7 +9,7 @@ class SimpleMembership extends IntegrationBase
|
|
9 |
|
10 |
protected $member_info = array();
|
11 |
|
12 |
-
function getDataForChecking( $member_info )
|
13 |
{
|
14 |
$this->member_info = $member_info;
|
15 |
|
@@ -21,7 +21,11 @@ class SimpleMembership extends IntegrationBase
|
|
21 |
);
|
22 |
}
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
{
|
26 |
global $ct_comment;
|
27 |
$ct_comment = $message;
|
9 |
|
10 |
protected $member_info = array();
|
11 |
|
12 |
+
public function getDataForChecking( $member_info )
|
13 |
{
|
14 |
$this->member_info = $member_info;
|
15 |
|
21 |
);
|
22 |
}
|
23 |
|
24 |
+
/**
|
25 |
+
* @param $message
|
26 |
+
* @psalm-suppress UnusedVariable
|
27 |
+
*/
|
28 |
+
public function doBlock( $message )
|
29 |
{
|
30 |
global $ct_comment;
|
31 |
$ct_comment = $message;
|
@@ -7,14 +7,18 @@ namespace Cleantalk\Antispam\Integrations;
|
|
7 |
class WpMembers extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
-
function getDataForChecking( $argument )
|
11 |
{
|
12 |
$data = ct_get_fields_any( $argument );
|
13 |
$data['register'] = true;
|
14 |
return $data;
|
15 |
}
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
{
|
19 |
global $wpmem_themsg;
|
20 |
$wpmem_themsg = $message;
|
7 |
class WpMembers extends IntegrationBase
|
8 |
{
|
9 |
|
10 |
+
public function getDataForChecking( $argument )
|
11 |
{
|
12 |
$data = ct_get_fields_any( $argument );
|
13 |
$data['register'] = true;
|
14 |
return $data;
|
15 |
}
|
16 |
|
17 |
+
/**
|
18 |
+
* @param $message
|
19 |
+
* @psalm-suppress UnusedVariable
|
20 |
+
*/
|
21 |
+
public function doBlock( $message )
|
22 |
{
|
23 |
global $wpmem_themsg;
|
24 |
$wpmem_themsg = $message;
|
@@ -6,13 +6,13 @@ namespace Cleantalk\Antispam\Integrations;
|
|
6 |
|
7 |
class Wpdiscuz extends IntegrationBase {
|
8 |
|
9 |
-
function getDataForChecking( $argument ) {
|
10 |
|
11 |
return ct_get_fields_any( $_POST );
|
12 |
|
13 |
}
|
14 |
|
15 |
-
function doBlock( $message ) {
|
16 |
|
17 |
wp_send_json_error( 'wc_error_email_text' );
|
18 |
|
6 |
|
7 |
class Wpdiscuz extends IntegrationBase {
|
8 |
|
9 |
+
public function getDataForChecking( $argument ) {
|
10 |
|
11 |
return ct_get_fields_any( $_POST );
|
12 |
|
13 |
}
|
14 |
|
15 |
+
public function doBlock( $message ) {
|
16 |
|
17 |
wp_send_json_error( 'wc_error_email_text' );
|
18 |
|
@@ -27,6 +27,7 @@ class API extends \Cleantalk\Common\API
|
|
27 |
* @param $status
|
28 |
*
|
29 |
* @return array|bool|mixed|string[]
|
|
|
30 |
*/
|
31 |
public static function method__private_list_add__sfw_wl( $user_token, $service_id, $ip ) {
|
32 |
|
@@ -53,9 +54,9 @@ class API extends \Cleantalk\Common\API
|
|
53 |
* @param int $timeout
|
54 |
* @param bool Do we need to use SSL
|
55 |
*
|
56 |
-
* @return array|
|
57 |
*/
|
58 |
-
static
|
59 |
{
|
60 |
global $apbct;
|
61 |
|
@@ -88,13 +89,12 @@ class API extends \Cleantalk\Common\API
|
|
88 |
// Call CURL version if disabled
|
89 |
}else{
|
90 |
$ssl_path = $ssl_path
|
91 |
-
?
|
92 |
-
: (defined('APBCT_CASERT_PATH') ? APBCT_CASERT_PATH : '');
|
93 |
$result = parent::send_request($data, $url, $timeout, $ssl, $ssl_path);
|
94 |
}
|
95 |
|
96 |
return empty($result) || !empty($errors)
|
97 |
-
? array(
|
98 |
: $result;
|
99 |
}
|
100 |
-
}
|
27 |
* @param $status
|
28 |
*
|
29 |
* @return array|bool|mixed|string[]
|
30 |
+
* @psalm-suppress PossiblyUnusedMethod
|
31 |
*/
|
32 |
public static function method__private_list_add__sfw_wl( $user_token, $service_id, $ip ) {
|
33 |
|
54 |
* @param int $timeout
|
55 |
* @param bool Do we need to use SSL
|
56 |
*
|
57 |
+
* @return array|string
|
58 |
*/
|
59 |
+
public static function send_request($data, $url = self::URL, $timeout = 10, $ssl = false, $ssl_path = '')
|
60 |
{
|
61 |
global $apbct;
|
62 |
|
89 |
// Call CURL version if disabled
|
90 |
}else{
|
91 |
$ssl_path = $ssl_path
|
92 |
+
?: (defined('APBCT_CASERT_PATH') ? APBCT_CASERT_PATH : '');
|
|
|
93 |
$result = parent::send_request($data, $url, $timeout, $ssl, $ssl_path);
|
94 |
}
|
95 |
|
96 |
return empty($result) || !empty($errors)
|
97 |
+
? array( 'error' => $errors )
|
98 |
: $result;
|
99 |
}
|
100 |
+
}
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
namespace Cleantalk\ApbctWP;
|
5 |
+
|
6 |
+
|
7 |
+
use Cleantalk\Common\Schema;
|
8 |
+
|
9 |
+
class Activator {
|
10 |
+
|
11 |
+
public static function activation( $network_wide, $concrete_blog_id = null )
|
12 |
+
{
|
13 |
+
global $wpdb, $apbct;
|
14 |
+
|
15 |
+
if( is_null( $concrete_blog_id ) ) {
|
16 |
+
// Do actions for the all blogs on activation
|
17 |
+
$apbct->stats['plugin']['activation_previous__timestamp'] = $apbct->stats['plugin']['activation__timestamp'];
|
18 |
+
$apbct->stats['plugin']['activation__timestamp'] = time();
|
19 |
+
$apbct->stats['plugin']['activation__times'] += 1;
|
20 |
+
$apbct->save('stats');
|
21 |
+
|
22 |
+
if( $network_wide && ! defined( 'CLEANTALK_ACCESS_KEY' ) ){
|
23 |
+
$initial_blog = get_current_blog_id();
|
24 |
+
$blogs = array_keys( $wpdb->get_results( 'SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K ) );
|
25 |
+
foreach ( $blogs as $blog ) {
|
26 |
+
switch_to_blog( $blog );
|
27 |
+
self::create_tables( Schema::getSchema() );
|
28 |
+
self::setCronJobs();
|
29 |
+
}
|
30 |
+
switch_to_blog( $initial_blog );
|
31 |
+
}else{
|
32 |
+
self::setCronJobs();
|
33 |
+
apbct_activation__create_tables( Schema::getSchema() );
|
34 |
+
ct_account_status_check(null, false);
|
35 |
+
}
|
36 |
+
|
37 |
+
// Additional options
|
38 |
+
add_option( 'ct_plugin_do_activation_redirect', true );
|
39 |
+
apbct_add_admin_ip_to_swf_whitelist( null );
|
40 |
+
|
41 |
+
} else {
|
42 |
+
// Do actions for the new blog created
|
43 |
+
if ( apbct_is_plugin_active_for_network('cleantalk-spam-protect/cleantalk.php') ){
|
44 |
+
|
45 |
+
$settings = get_option('cleantalk_settings');
|
46 |
+
|
47 |
+
switch_to_blog( $concrete_blog_id );
|
48 |
+
|
49 |
+
self::setCronJobs( false );
|
50 |
+
apbct_activation__create_tables( Schema::getSchema() );
|
51 |
+
apbct_sfw_update__init( 3 ); // Updating SFW
|
52 |
+
ct_account_status_check(null, false);
|
53 |
+
|
54 |
+
if (isset($settings['multisite__use_settings_template_apply_for_new']) && $settings['multisite__use_settings_template_apply_for_new'] == 1) {
|
55 |
+
update_option('cleantalk_settings', $settings);
|
56 |
+
}
|
57 |
+
restore_current_blog();
|
58 |
+
}
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Creating specific tables
|
64 |
+
*
|
65 |
+
* @param $sqls
|
66 |
+
* @param string $db_prefix
|
67 |
+
*
|
68 |
+
* @return void
|
69 |
+
*/
|
70 |
+
public static function create_tables( $sqls, $db_prefix = '' )
|
71 |
+
{
|
72 |
+
|
73 |
+
if( ! is_array( $sqls ) && empty( $sqls ) ) {
|
74 |
+
return;
|
75 |
+
}
|
76 |
+
|
77 |
+
global $wpdb;
|
78 |
+
|
79 |
+
$db_prefix = $db_prefix ?: $wpdb->prefix;
|
80 |
+
|
81 |
+
$wpdb->show_errors = false;
|
82 |
+
foreach( $sqls as $sql ){
|
83 |
+
$sql = sprintf( $sql, $db_prefix ); // Adding current blog prefix
|
84 |
+
$result = $wpdb->query( $sql );
|
85 |
+
if( $result === false ) {
|
86 |
+
$errors[] = "Failed.\nQuery: $wpdb->last_query\nError: $wpdb->last_error";
|
87 |
+
}
|
88 |
+
}
|
89 |
+
$wpdb->show_errors = true;
|
90 |
+
|
91 |
+
// Logging errors
|
92 |
+
if(!empty($errors)) {
|
93 |
+
apbct_log( $errors );
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Set CRON jobs
|
99 |
+
*
|
100 |
+
* @param bool $sfw_update_include
|
101 |
+
*/
|
102 |
+
public static function setCronJobs( $sfw_update_include = true )
|
103 |
+
{
|
104 |
+
$ct_cron = new Cron();
|
105 |
+
|
106 |
+
// Cron tasks
|
107 |
+
if( $sfw_update_include ) {
|
108 |
+
$ct_cron->addTask('sfw_update', 'apbct_sfw_update__init', 86400 ); // SFW update
|
109 |
+
}
|
110 |
+
$ct_cron->addTask('check_account_status', 'ct_account_status_check', 3600, time() + 1800); // Checks account status
|
111 |
+
$ct_cron->addTask('delete_spam_comments', 'ct_delete_spam_comments', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
112 |
+
$ct_cron->addTask('send_feedback', 'ct_send_feedback', 3600, time() + 3500); // Formerly ct_hourly_event_hook()
|
113 |
+
$ct_cron->addTask('send_sfw_logs', 'ct_sfw_send_logs', 3600, time() + 1800); // SFW send logs
|
114 |
+
$ct_cron->addTask('get_brief_data', 'cleantalk_get_brief_data', 86400, time() + 3500); // Get data for dashboard widget
|
115 |
+
$ct_cron->addTask('send_connection_report','ct_mail_send_connection_report', 86400, time() + 3500); // Send connection report to welcome@cleantalk.org
|
116 |
+
$ct_cron->addTask('antiflood__clear_table','apbct_antiflood__clear_table', 86400, time() + 300); // Clear Anti-Flood table
|
117 |
+
$ct_cron->addTask('rotate_moderate', 'apbct_rotate_moderate', 86400, time() + 3500); // Rotate moderate server
|
118 |
+
}
|
119 |
+
}
|
@@ -7,7 +7,7 @@ namespace Cleantalk\ApbctWP;
|
|
7 |
class AdminNotices {
|
8 |
|
9 |
/**
|
10 |
-
* @var AdminNotices
|
11 |
*/
|
12 |
private static $instance;
|
13 |
|
@@ -86,7 +86,7 @@ class AdminNotices {
|
|
86 |
*/
|
87 |
private static function get_instance()
|
88 |
{
|
89 |
-
if (
|
90 |
self::$instance = new static();
|
91 |
}
|
92 |
return self::$instance;
|
@@ -110,6 +110,7 @@ class AdminNotices {
|
|
110 |
|
111 |
/**
|
112 |
* Callback for the notice hook
|
|
|
113 |
*/
|
114 |
public function notice_get_key_error()
|
115 |
{
|
@@ -124,6 +125,7 @@ class AdminNotices {
|
|
124 |
|
125 |
/**
|
126 |
* Callback for the notice hook
|
|
|
127 |
*/
|
128 |
public function notice_key_is_incorrect()
|
129 |
{
|
@@ -137,6 +139,7 @@ class AdminNotices {
|
|
137 |
|
138 |
/**
|
139 |
* Callback for the notice hook
|
|
|
140 |
*/
|
141 |
public function notice_trial()
|
142 |
{
|
@@ -154,6 +157,7 @@ class AdminNotices {
|
|
154 |
/**
|
155 |
* Callback for the notice hook
|
156 |
* @deprecated
|
|
|
157 |
*/
|
158 |
public function notice_renew()
|
159 |
{
|
@@ -172,6 +176,7 @@ class AdminNotices {
|
|
172 |
|
173 |
/**
|
174 |
* Callback for the notice hook
|
|
|
175 |
*/
|
176 |
public function notice_incompatibility()
|
177 |
{
|
7 |
class AdminNotices {
|
8 |
|
9 |
/**
|
10 |
+
* @var null|AdminNotices
|
11 |
*/
|
12 |
private static $instance;
|
13 |
|
86 |
*/
|
87 |
private static function get_instance()
|
88 |
{
|
89 |
+
if ( is_null( self::$instance ) ) {
|
90 |
self::$instance = new static();
|
91 |
}
|
92 |
return self::$instance;
|
110 |
|
111 |
/**
|
112 |
* Callback for the notice hook
|
113 |
+
* @psalm-suppress PossiblyUnusedMethod
|
114 |
*/
|
115 |
public function notice_get_key_error()
|
116 |
{
|
125 |
|
126 |
/**
|
127 |
* Callback for the notice hook
|
128 |
+
* @psalm-suppress PossiblyUnusedMethod
|
129 |
*/
|
130 |
public function notice_key_is_incorrect()
|
131 |
{
|
139 |
|
140 |
/**
|
141 |
* Callback for the notice hook
|
142 |
+
* @psalm-suppress PossiblyUnusedMethod
|
143 |
*/
|
144 |
public function notice_trial()
|
145 |
{
|
157 |
/**
|
158 |
* Callback for the notice hook
|
159 |
* @deprecated
|
160 |
+
* @psalm-suppress PossiblyUnusedMethod
|
161 |
*/
|
162 |
public function notice_renew()
|
163 |
{
|
176 |
|
177 |
/**
|
178 |
* Callback for the notice hook
|
179 |
+
* @psalm-suppress PossiblyUnusedMethod
|
180 |
*/
|
181 |
public function notice_incompatibility()
|
182 |
{
|
@@ -6,11 +6,6 @@ namespace Cleantalk\ApbctWP;
|
|
6 |
|
7 |
class Ajax {
|
8 |
|
9 |
-
/**
|
10 |
-
* string
|
11 |
-
*/
|
12 |
-
private $table_prefix;
|
13 |
-
|
14 |
public function __construct()
|
15 |
{
|
16 |
define( 'DOING_AJAX', true );
|
@@ -18,12 +13,16 @@ class Ajax {
|
|
18 |
|
19 |
require_once( '../../../../../../wp-load.php' );
|
20 |
require_once( '../../../../../../wp-includes/capabilities.php' );
|
|
|
|
|
21 |
require_once( '../../../../../../wp-includes/class-wp-role.php' );
|
22 |
require_once( '../../../../../../wp-includes/class-wp-roles.php' );
|
23 |
require_once( '../../../../../../wp-includes/user.php' );
|
24 |
require_once( '../../../../../../wp-includes/class-wp-user.php' );
|
25 |
require_once( '../../../../../../wp-includes/option.php' );
|
26 |
require_once( '../../../../../../wp-includes/default-constants.php' );
|
|
|
|
|
27 |
wp_plugin_directory_constants();
|
28 |
wp_cookie_constants();
|
29 |
require_once( '../../../../../../wp-includes/pluggable.php' );
|
@@ -71,13 +70,13 @@ class Ajax {
|
|
71 |
break;
|
72 |
case 'apbct_alt_session__save__AJAX':
|
73 |
// Using alternative sessions with ajax
|
74 |
-
if( $apbct->settings['data__set_cookies'] == 2 && $apbct->settings['data__set_cookies__alt_sessions_type'] ==
|
75 |
apbct_alt_session__save__AJAX();
|
76 |
}
|
77 |
break;
|
78 |
case 'apbct_alt_session__get__AJAX' :
|
79 |
// Using alternative sessions with ajax
|
80 |
-
if( $apbct->settings['data__set_cookies'] == 2 && $apbct->settings['data__set_cookies__alt_sessions_type'] ==
|
81 |
apbct_alt_session__get__AJAX();
|
82 |
}
|
83 |
break;
|
@@ -122,7 +121,7 @@ class Ajax {
|
|
122 |
private function wp_verify_nonce( $nonce, $action )
|
123 |
{
|
124 |
$nonce = (string) $nonce;
|
125 |
-
$user =
|
126 |
$uid = is_null( $user ) ? 0 : $user->ID;
|
127 |
if ( ! $uid ) {
|
128 |
/**
|
@@ -132,6 +131,7 @@ class Ajax {
|
|
132 |
*
|
133 |
* @param int $uid ID of the nonce-owning user.
|
134 |
* @param string $action The nonce action.
|
|
|
135 |
*/
|
136 |
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
137 |
}
|
6 |
|
7 |
class Ajax {
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
public function __construct()
|
10 |
{
|
11 |
define( 'DOING_AJAX', true );
|
13 |
|
14 |
require_once( '../../../../../../wp-load.php' );
|
15 |
require_once( '../../../../../../wp-includes/capabilities.php' );
|
16 |
+
require_once( '../../../../../../wp-includes/kses.php' );
|
17 |
+
require_once( '../../../../../../wp-includes/rest-api.php' );
|
18 |
require_once( '../../../../../../wp-includes/class-wp-role.php' );
|
19 |
require_once( '../../../../../../wp-includes/class-wp-roles.php' );
|
20 |
require_once( '../../../../../../wp-includes/user.php' );
|
21 |
require_once( '../../../../../../wp-includes/class-wp-user.php' );
|
22 |
require_once( '../../../../../../wp-includes/option.php' );
|
23 |
require_once( '../../../../../../wp-includes/default-constants.php' );
|
24 |
+
require_once( '../../../../../../wp-includes/class-wp-session-tokens.php' );
|
25 |
+
require_once( '../../../../../../wp-includes/class-wp-user-meta-session-tokens.php' );
|
26 |
wp_plugin_directory_constants();
|
27 |
wp_cookie_constants();
|
28 |
require_once( '../../../../../../wp-includes/pluggable.php' );
|
70 |
break;
|
71 |
case 'apbct_alt_session__save__AJAX':
|
72 |
// Using alternative sessions with ajax
|
73 |
+
if( $apbct->settings['data__set_cookies'] == 2 && $apbct->settings['data__set_cookies__alt_sessions_type'] == 1 ){
|
74 |
apbct_alt_session__save__AJAX();
|
75 |
}
|
76 |
break;
|
77 |
case 'apbct_alt_session__get__AJAX' :
|
78 |
// Using alternative sessions with ajax
|
79 |
+
if( $apbct->settings['data__set_cookies'] == 2 && $apbct->settings['data__set_cookies__alt_sessions_type'] == 1 ){
|
80 |
apbct_alt_session__get__AJAX();
|
81 |
}
|
82 |
break;
|
121 |
private function wp_verify_nonce( $nonce, $action )
|
122 |
{
|
123 |
$nonce = (string) $nonce;
|
124 |
+
$user = wp_get_current_user();
|
125 |
$uid = is_null( $user ) ? 0 : $user->ID;
|
126 |
if ( ! $uid ) {
|
127 |
/**
|
131 |
*
|
132 |
* @param int $uid ID of the nonce-owning user.
|
133 |
* @param string $action The nonce action.
|
134 |
+
* @psalm-suppress TooManyArguments
|
135 |
*/
|
136 |
$uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
|
137 |
}
|
@@ -23,7 +23,6 @@ class CleantalkSettingsTemplates {
|
|
23 |
add_action( 'wp_ajax_settings_templates_export', array( $this, 'settings_templates_export_ajax' ) );
|
24 |
add_action( 'wp_ajax_settings_templates_import', array( $this, 'settings_templates_import_ajax' ) );
|
25 |
add_action( 'wp_ajax_settings_templates_reset', array( $this, 'settings_templates_reset_ajax' ) );
|
26 |
-
add_action( 'apbct_settings_template_get', array( $this, 'open_templates_dialog' ) );
|
27 |
}
|
28 |
|
29 |
public function add_action_button( $links )
|
@@ -53,7 +52,7 @@ class CleantalkSettingsTemplates {
|
|
53 |
$template_info = $_POST['data'];
|
54 |
if( isset( $template_info['template_id'] ) ) {
|
55 |
$template_id = sanitize_text_field( $template_info['template_id'] );
|
56 |
-
$res = \Cleantalk\Common\API::method__services_templates_update( $this->api_key, $template_id, $this->get_plugin_options() );
|
57 |
if( is_array( $res ) && array_key_exists( 'operation_status', $res ) ) {
|
58 |
if( $res['operation_status'] === 'SUCCESS' ) {
|
59 |
wp_send_json_success( esc_html__('Success. Reloading...', 'cleantalk-spam-protect' ) );
|
@@ -258,6 +257,7 @@ class CleantalkSettingsTemplates {
|
|
258 |
$apbct->settings = $settings;
|
259 |
$apbct->data['current_settings_template_id'] = $template_id;
|
260 |
$apbct->data['current_settings_template_name'] = $template_name;
|
|
|
261 |
return $apbct->saveSettings() && $apbct->saveData();
|
262 |
}
|
263 |
|
23 |
add_action( 'wp_ajax_settings_templates_export', array( $this, 'settings_templates_export_ajax' ) );
|
24 |
add_action( 'wp_ajax_settings_templates_import', array( $this, 'settings_templates_import_ajax' ) );
|
25 |
add_action( 'wp_ajax_settings_templates_reset', array( $this, 'settings_templates_reset_ajax' ) );
|
|
|
26 |
}
|
27 |
|
28 |
public function add_action_button( $links )
|
52 |
$template_info = $_POST['data'];
|
53 |
if( isset( $template_info['template_id'] ) ) {
|
54 |
$template_id = sanitize_text_field( $template_info['template_id'] );
|
55 |
+
$res = \Cleantalk\Common\API::method__services_templates_update( $this->api_key, (int) $template_id, $this->get_plugin_options() );
|
56 |
if( is_array( $res ) && array_key_exists( 'operation_status', $res ) ) {
|
57 |
if( $res['operation_status'] === 'SUCCESS' ) {
|
58 |
wp_send_json_success( esc_html__('Success. Reloading...', 'cleantalk-spam-protect' ) );
|
257 |
$apbct->settings = $settings;
|
258 |
$apbct->data['current_settings_template_id'] = $template_id;
|
259 |
$apbct->data['current_settings_template_name'] = $template_name;
|
260 |
+
$apbct->data['key_changed'] = 1;
|
261 |
return $apbct->saveSettings() && $apbct->saveData();
|
262 |
}
|
263 |
|
@@ -75,7 +75,12 @@ class CleantalkUpgrader extends \Plugin_Upgrader
|
|
75 |
|
76 |
return true;
|
77 |
}
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
79 |
public function run( $options ) {
|
80 |
|
81 |
$defaults = array(
|
@@ -109,6 +114,7 @@ class CleantalkUpgrader extends \Plugin_Upgrader
|
|
109 |
$this->skin->before();
|
110 |
|
111 |
if ( is_wp_error($res) ) {
|
|
|
112 |
$this->skin->error($res);
|
113 |
$this->skin->after();
|
114 |
if ( ! $options['is_multi'] ) {
|
75 |
|
76 |
return true;
|
77 |
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @param array|object $options
|
81 |
+
*
|
82 |
+
* @return array|bool|string|\WP_Error
|
83 |
+
*/
|
84 |
public function run( $options ) {
|
85 |
|
86 |
$defaults = array(
|
114 |
$this->skin->before();
|
115 |
|
116 |
if ( is_wp_error($res) ) {
|
117 |
+
/** @psalm-suppress InvalidScalarArgument */
|
118 |
$this->skin->error($res);
|
119 |
$this->skin->after();
|
120 |
if ( ! $options['is_multi'] ) {
|
@@ -6,17 +6,17 @@ class CleantalkUpgraderSkin extends \WP_Upgrader_Skin
|
|
6 |
{
|
7 |
|
8 |
public $upgrader;
|
9 |
-
public $done_header
|
10 |
-
public $done_footer
|
11 |
|
12 |
/**
|
13 |
* Holds the result of an upgrade.
|
14 |
*
|
15 |
* @since 2.8.0
|
16 |
-
* @var string|bool
|
17 |
*/
|
18 |
-
public $result
|
19 |
-
public $options
|
20 |
|
21 |
/**
|
22 |
*/
|
@@ -34,7 +34,7 @@ class CleantalkUpgraderSkin extends \WP_Upgrader_Skin
|
|
34 |
|
35 |
/**
|
36 |
*
|
37 |
-
* @param string
|
38 |
*/
|
39 |
public function error($errors) {
|
40 |
if(is_wp_error($errors)){
|
6 |
{
|
7 |
|
8 |
public $upgrader;
|
9 |
+
public $done_header;
|
10 |
+
public $done_footer;
|
11 |
|
12 |
/**
|
13 |
* Holds the result of an upgrade.
|
14 |
*
|
15 |
* @since 2.8.0
|
16 |
+
* @var string|bool|\WP_Error
|
17 |
*/
|
18 |
+
public $result;
|
19 |
+
public $options;
|
20 |
|
21 |
/**
|
22 |
*/
|
34 |
|
35 |
/**
|
36 |
*
|
37 |
+
* @param string|\WP_Error $errors
|
38 |
*/
|
39 |
public function error($errors) {
|
40 |
if(is_wp_error($errors)){
|
@@ -6,17 +6,18 @@ class CleantalkUpgraderSkin_Deprecated extends \WP_Upgrader_Skin
|
|
6 |
{
|
7 |
|
8 |
public $upgrader;
|
9 |
-
public $done_header
|
10 |
-
public $done_footer
|
11 |
|
12 |
/**
|
13 |
* Holds the result of an upgrade.
|
14 |
*
|
15 |
* @since 2.8.0
|
16 |
-
* @var string|bool
|
17 |
*/
|
18 |
-
public $result
|
19 |
-
|
|
|
20 |
|
21 |
/**
|
22 |
*/
|
@@ -29,12 +30,13 @@ class CleantalkUpgraderSkin_Deprecated extends \WP_Upgrader_Skin
|
|
29 |
/**
|
30 |
*
|
31 |
* @param string $string
|
|
|
32 |
*/
|
33 |
public function feedback($string) { }
|
34 |
|
35 |
/**
|
36 |
*
|
37 |
-
* @param string
|
38 |
*/
|
39 |
public function error($errors) {
|
40 |
if(is_wp_error($errors)){
|
6 |
{
|
7 |
|
8 |
public $upgrader;
|
9 |
+
public $done_header;
|
10 |
+
public $done_footer;
|
11 |
|
12 |
/**
|
13 |
* Holds the result of an upgrade.
|
14 |
*
|
15 |
* @since 2.8.0
|
16 |
+
* @var string|bool|\WP_Error
|
17 |
*/
|
18 |
+
public $result;
|
19 |
+
|
20 |
+
public $options;
|
21 |
|
22 |
/**
|
23 |
*/
|
30 |
/**
|
31 |
*
|
32 |
* @param string $string
|
33 |
+
* @psalm-suppress MethodSignatureMismatch
|
34 |
*/
|
35 |
public function feedback($string) { }
|
36 |
|
37 |
/**
|
38 |
*
|
39 |
+
* @param string|\WP_Error $errors
|
40 |
*/
|
41 |
public function error($errors) {
|
42 |
if(is_wp_error($errors)){
|
@@ -27,7 +27,7 @@ class DB extends \Cleantalk\Common\DB
|
|
27 |
private $query;
|
28 |
|
29 |
/**
|
30 |
-
* @var wpdb result
|
31 |
*/
|
32 |
private $db_result;
|
33 |
|
@@ -94,8 +94,8 @@ class DB extends \Cleantalk\Common\DB
|
|
94 |
{
|
95 |
global $wpdb;
|
96 |
|
97 |
-
$query = $query
|
98 |
-
$vars = $vars
|
99 |
array_unshift($vars, $query);
|
100 |
|
101 |
$this->query = call_user_func_array(array($wpdb, 'prepare'), $vars);
|
@@ -120,20 +120,20 @@ class DB extends \Cleantalk\Common\DB
|
|
120 |
}
|
121 |
|
122 |
/**
|
123 |
-
*
|
124 |
* May receive raw or prepared query.
|
125 |
*
|
126 |
-
* @param
|
127 |
-
* @param bool $response_type
|
128 |
*
|
129 |
* @return array|object|void|null
|
130 |
*/
|
131 |
-
public function fetch($query =
|
132 |
{
|
133 |
global $wpdb;
|
134 |
|
135 |
-
$query = $query
|
136 |
-
$response_type = $response_type
|
137 |
|
138 |
$this->result = $wpdb->get_row($query, $response_type);
|
139 |
|
@@ -141,26 +141,30 @@ class DB extends \Cleantalk\Common\DB
|
|
141 |
}
|
142 |
|
143 |
/**
|
144 |
-
*
|
145 |
* May receive raw or prepared query.
|
146 |
*
|
147 |
-
* @param
|
148 |
-
* @param bool $response_type
|
149 |
*
|
150 |
* @return array|object|null
|
151 |
*/
|
152 |
-
public function fetch_all($query =
|
153 |
{
|
154 |
global $wpdb;
|
155 |
|
156 |
-
$query = $query
|
157 |
-
$response_type = $response_type
|
158 |
|
159 |
$this->result = $wpdb->get_results($query, $response_type);
|
160 |
|
161 |
return $this->result;
|
162 |
}
|
163 |
|
|
|
|
|
|
|
|
|
164 |
public function get_last_error() {
|
165 |
global $wpdb;
|
166 |
return $wpdb->last_error;
|
27 |
private $query;
|
28 |
|
29 |
/**
|
30 |
+
* @var \wpdb result
|
31 |
*/
|
32 |
private $db_result;
|
33 |
|
94 |
{
|
95 |
global $wpdb;
|
96 |
|
97 |
+
$query = $query ?: $this->query;
|
98 |
+
$vars = $vars ?: array();
|
99 |
array_unshift($vars, $query);
|
100 |
|
101 |
$this->query = call_user_func_array(array($wpdb, 'prepare'), $vars);
|
120 |
}
|
121 |
|
122 |
/**
|
123 |
+
* Fetch first column from query.
|
124 |
* May receive raw or prepared query.
|
125 |
*
|
126 |
+
* @param string $query
|
127 |
+
* @param bool|string $response_type
|
128 |
*
|
129 |
* @return array|object|void|null
|
130 |
*/
|
131 |
+
public function fetch($query = '', $response_type = false)
|
132 |
{
|
133 |
global $wpdb;
|
134 |
|
135 |
+
$query = $query ?: $this->query;
|
136 |
+
$response_type = $response_type ?: ARRAY_A;
|
137 |
|
138 |
$this->result = $wpdb->get_row($query, $response_type);
|
139 |
|
141 |
}
|
142 |
|
143 |
/**
|
144 |
+
* Fetch all result from query.
|
145 |
* May receive raw or prepared query.
|
146 |
*
|
147 |
+
* @param string $query
|
148 |
+
* @param bool|string $response_type
|
149 |
*
|
150 |
* @return array|object|null
|
151 |
*/
|
152 |
+
public function fetch_all($query = '', $response_type = false)
|
153 |
{
|
154 |
global $wpdb;
|
155 |
|
156 |
+
$query = $query ?: $this->query;
|
157 |
+
$response_type = $response_type ?: ARRAY_A;
|
158 |
|
159 |
$this->result = $wpdb->get_results($query, $response_type);
|
160 |
|
161 |
return $this->result;
|
162 |
}
|
163 |
|
164 |
+
/**
|
165 |
+
* @return string
|
166 |
+
* @psalm-suppress PossiblyUnusedMethod
|
167 |
+
*/
|
168 |
public function get_last_error() {
|
169 |
global $wpdb;
|
170 |
return $wpdb->last_error;
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
namespace Cleantalk\ApbctWP;
|
5 |
+
|
6 |
+
|
7 |
+
class Deactivator {
|
8 |
+
|
9 |
+
public static function deactivation( $network_wide )
|
10 |
+
{
|
11 |
+
global $apbct, $wpdb;
|
12 |
+
|
13 |
+
if( ! is_multisite() ){
|
14 |
+
// Deactivation on standalone blog
|
15 |
+
|
16 |
+
self::delete_tables( $wpdb->prefix );
|
17 |
+
delete_option('cleantalk_cron'); // Deleting cron entries
|
18 |
+
|
19 |
+
if($apbct->settings['misc__complete_deactivation']) {
|
20 |
+
self::delete_all_options();
|
21 |
+
self::delete_meta();
|
22 |
+
}
|
23 |
+
|
24 |
+
} elseif( $network_wide ) {
|
25 |
+
// Deactivation for network
|
26 |
+
|
27 |
+
$initial_blog = get_current_blog_id();
|
28 |
+
$blogs = array_keys($wpdb->get_results('SELECT blog_id FROM '. $wpdb->blogs, OBJECT_K));
|
29 |
+
foreach ( $blogs as $blog ) {
|
30 |
+
switch_to_blog($blog);
|
31 |
+
self::delete_tables( $wpdb->get_blog_prefix( $blog ) );
|
32 |
+
delete_option('cleantalk_cron'); // Deleting cron entries
|
33 |
+
|
34 |
+
if($apbct->settings['misc__complete_deactivation']){
|
35 |
+
self::delete_all_options();
|
36 |
+
self::delete_meta();
|
37 |
+
self::delete_all_options__in_network();
|
38 |
+
}
|
39 |
+
|
40 |
+
}
|
41 |
+
switch_to_blog($initial_blog);
|
42 |
+
|
43 |
+
} else {
|
44 |
+
// Deactivation for blog
|
45 |
+
|
46 |
+
self::delete_tables( $wpdb->prefix );
|
47 |
+
delete_option('cleantalk_cron'); // Deleting cron entries
|
48 |
+
|
49 |
+
if($apbct->settings['misc__complete_deactivation']) {
|
50 |
+
self::delete_all_options();
|
51 |
+
self::delete_meta();
|
52 |
+
}
|
53 |
+
|
54 |
+
}
|
55 |
+
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Delete all cleantalk_* entries from _options table
|
60 |
+
*/
|
61 |
+
public static function delete_all_options(){
|
62 |
+
delete_option('cleantalk_settings');
|
63 |
+
delete_option('cleantalk_data');
|
64 |
+
delete_option('cleantalk_cron');
|
65 |
+
delete_option('cleantalk_errors');
|
66 |
+
delete_option('cleantalk_remote_calls');
|
67 |
+
delete_option('cleantalk_server');
|
68 |
+
delete_option('cleantalk_stats');
|
69 |
+
delete_option('cleantalk_timelabel_reg');
|
70 |
+
delete_option('cleantalk_debug');
|
71 |
+
delete_option('cleantalk_plugin_request_ids');
|
72 |
+
delete_option('cleantalk_fw_stats');
|
73 |
+
delete_option( 'ct_plugin_do_activation_redirect' );
|
74 |
+
foreach( AdminNotices::NOTICES as $notice ) {
|
75 |
+
delete_option( 'cleantalk_' . $notice . '_dismissed' );
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Delete all cleantalk_* entries from _sitemeta table
|
81 |
+
*/
|
82 |
+
public static function delete_all_options__in_network(){
|
83 |
+
delete_site_option('cleantalk_network_settings');
|
84 |
+
delete_site_option('cleantalk_network_data');
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Delete tables from DB
|
89 |
+
*/
|
90 |
+
public static function delete_tables( $prefix ) {
|
91 |
+
global $wpdb;
|
92 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_sfw`;'); // Deleting SFW data
|
93 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_sfw_logs`;'); // Deleting SFW logs
|
94 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_sfw__flood_logs`;'); // Deleting SFW logs
|
95 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_ac_log`;'); // Deleting SFW logs
|
96 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_sessions`;'); // Deleting session table
|
97 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_spamscan_logs`;'); // Deleting user/comments scan result table
|
98 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_ua_bl`;'); // Deleting AC UA black lists
|
99 |
+
$wpdb->query('DROP TABLE IF EXISTS `'. $prefix .'cleantalk_sfw_temp`;'); // Deleting temporary SFW data
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Clear all meta
|
104 |
+
*/
|
105 |
+
public static function delete_meta(){
|
106 |
+
global $wpdb;
|
107 |
+
$wpdb->query("DELETE FROM $wpdb->usermeta WHERE meta_key IN ('ct_bad', 'ct_checked', 'ct_checked_now', 'ct_marked_as_spam', 'ct_hash');");
|
108 |
+
}
|
109 |
+
|
110 |
+
}
|
@@ -32,12 +32,20 @@ abstract class Checker
|
|
32 |
|
33 |
}
|
34 |
|
|
|
|
|
|
|
|
|
35 |
public function getPageTitle() {
|
36 |
|
37 |
return $this->page_title;
|
38 |
|
39 |
}
|
40 |
|
|
|
|
|
|
|
|
|
41 |
public function getPageScriptName() {
|
42 |
|
43 |
return $this->page_script_name;
|
@@ -46,6 +54,7 @@ abstract class Checker
|
|
46 |
|
47 |
/**
|
48 |
* @return mixed
|
|
|
49 |
*/
|
50 |
public function getPageSlug()
|
51 |
{
|
@@ -54,6 +63,7 @@ abstract class Checker
|
|
54 |
|
55 |
/**
|
56 |
* @return mixed
|
|
|
57 |
*/
|
58 |
public function getApbct()
|
59 |
{
|
@@ -148,7 +158,7 @@ abstract class Checker
|
|
148 |
APBCT_SPAMSCAN_LOGS,
|
149 |
array(
|
150 |
'scan_type' => $scan_type,
|
151 |
-
'start_time' => $scan_date, //@ToDo this is the END date. Need to place both: start and
|
152 |
'count_to_scan' => $cnt_checked,
|
153 |
'found_spam' => $cnt_spam,
|
154 |
'found_bad' => $cnt_bad
|
32 |
|
33 |
}
|
34 |
|
35 |
+
/**
|
36 |
+
* @return string
|
37 |
+
* @psalm-suppress PossiblyUnusedMethod
|
38 |
+
*/
|
39 |
public function getPageTitle() {
|
40 |
|
41 |
return $this->page_title;
|
42 |
|
43 |
}
|
44 |
|
45 |
+
/**
|
46 |
+
* @return mixed
|
47 |
+
* @psalm-suppress PossiblyUnusedMethod
|
48 |
+
*/
|
49 |
public function getPageScriptName() {
|
50 |
|
51 |
return $this->page_script_name;
|
54 |
|
55 |
/**
|
56 |
* @return mixed
|
57 |
+
* @psalm-suppress PossiblyUnusedMethod
|
58 |
*/
|
59 |
public function getPageSlug()
|
60 |
{
|
63 |
|
64 |
/**
|
65 |
* @return mixed
|
66 |
+
* @psalm-suppress PossiblyUnusedMethod
|
67 |
*/
|
68 |
public function getApbct()
|
69 |
{
|
158 |
APBCT_SPAMSCAN_LOGS,
|
159 |
array(
|
160 |
'scan_type' => $scan_type,
|
161 |
+
'start_time' => $scan_date, //@ToDo this is the END date. Need to place both: start and end of scanning
|
162 |
'count_to_scan' => $cnt_checked,
|
163 |
'found_spam' => $cnt_spam,
|
164 |
'found_bad' => $cnt_bad
|
@@ -2,6 +2,8 @@
|
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\FindSpam;
|
4 |
|
|
|
|
|
5 |
class CommentsChecker extends Checker
|
6 |
{
|
7 |
|
@@ -60,6 +62,7 @@ class CommentsChecker extends Checker
|
|
60 |
* Getting a count of total comments of the website and return formatted string about this.
|
61 |
*
|
62 |
* @return string
|
|
|
63 |
*/
|
64 |
public static function get_count_text() {
|
65 |
|
@@ -117,7 +120,7 @@ class CommentsChecker extends Checker
|
|
117 |
$till_date = date('Y-m-d', intval(strtotime($_POST['till'])));
|
118 |
}
|
119 |
|
120 |
-
//
|
121 |
if(isset($_COOKIE['ct_comments_safe_check'])){
|
122 |
$c = $wpdb->get_results("
|
123 |
SELECT comment_ID, comment_date_gmt, comment_author_IP, comment_author_email
|
@@ -173,13 +176,13 @@ class CommentsChecker extends Checker
|
|
173 |
'error' => 0
|
174 |
);
|
175 |
|
176 |
-
if(
|
177 |
|
178 |
-
//
|
179 |
if(is_array($c[0])){
|
180 |
foreach($c as $key => $value){
|
181 |
$c[$key] = (object)$value;
|
182 |
-
}
|
183 |
}
|
184 |
|
185 |
if(!empty($_POST['accurate_check'])){
|
@@ -187,83 +190,89 @@ class CommentsChecker extends Checker
|
|
187 |
|
188 |
foreach($c as $comment_index => $comment){
|
189 |
|
190 |
-
if(!isset($curr_date))
|
191 |
-
|
|
|
192 |
|
193 |
-
if(substr($comment->comment_date_gmt, 0, 10) != $curr_date)
|
194 |
-
|
|
|
195 |
|
196 |
}
|
197 |
-
unset($comment_index, $comment);
|
198 |
}
|
199 |
|
200 |
// Checking comments IP/Email. Gathering $data for check.
|
201 |
-
$data =
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
229 |
$c = array_values($c);
|
230 |
|
231 |
// Drop if data empty and there's no comments to check
|
232 |
-
if(count($data)
|
233 |
-
if($_POST['unchecked'] === 0)
|
234 |
-
|
|
|
235 |
print json_encode($check_result);
|
236 |
die();
|
237 |
}
|
238 |
|
239 |
-
$result =
|
240 |
|
241 |
if(empty($result['error'])){
|
242 |
|
243 |
-
|
244 |
|
245 |
-
|
246 |
-
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
|
252 |
-
|
253 |
-
|
254 |
|
255 |
-
|
256 |
-
|
|
|
257 |
|
258 |
-
|
259 |
-
|
|
|
260 |
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
|
268 |
}else{
|
269 |
$check_result['error'] = 1;
|
@@ -286,8 +295,11 @@ class CommentsChecker extends Checker
|
|
286 |
|
287 |
public static function ct_ajax_info($direct_call = false){
|
288 |
|
289 |
-
|
290 |
-
|
|
|
|
|
|
|
291 |
|
292 |
// Checked comments
|
293 |
$params_checked = array(
|
@@ -347,8 +359,6 @@ class CommentsChecker extends Checker
|
|
347 |
);
|
348 |
} else {
|
349 |
|
350 |
-
global $wpdb;
|
351 |
-
|
352 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'comments' ORDER BY start_time DESC";
|
353 |
$res = $wpdb->get_row( $query, ARRAY_A );
|
354 |
|
@@ -388,9 +398,10 @@ class CommentsChecker extends Checker
|
|
388 |
|
389 |
public static function ct_ajax_clear_comments(){
|
390 |
|
|
|
|
|
391 |
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
392 |
|
393 |
-
global $wpdb;
|
394 |
$wpdb->query("DELETE FROM {$wpdb->commentmeta} WHERE meta_key IN ('ct_checked_now')");
|
395 |
|
396 |
if ( isset($_POST['from']) && isset($_POST['till']) ) {
|
@@ -493,10 +504,11 @@ class CommentsChecker extends Checker
|
|
493 |
);
|
494 |
$cnt_all = get_comments($args_spam);
|
495 |
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
|
|
500 |
print $cnt_all;
|
501 |
die();
|
502 |
}
|
@@ -527,14 +539,15 @@ class CommentsChecker extends Checker
|
|
527 |
)
|
528 |
)
|
529 |
);
|
530 |
-
$cnt_all = get_comments($args_spam);
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
|
|
537 |
die();
|
538 |
}
|
539 |
|
540 |
-
}
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\FindSpam;
|
4 |
|
5 |
+
use Cleantalk\ApbctWP\API;
|
6 |
+
|
7 |
class CommentsChecker extends Checker
|
8 |
{
|
9 |
|
62 |
* Getting a count of total comments of the website and return formatted string about this.
|
63 |
*
|
64 |
* @return string
|
65 |
+
* @psalm-suppress PossiblyUnusedMethod
|
66 |
*/
|
67 |
public static function get_count_text() {
|
68 |
|
120 |
$till_date = date('Y-m-d', intval(strtotime($_POST['till'])));
|
121 |
}
|
122 |
|
123 |
+
// Getting comments 100 unchecked comments
|
124 |
if(isset($_COOKIE['ct_comments_safe_check'])){
|
125 |
$c = $wpdb->get_results("
|
126 |
SELECT comment_ID, comment_date_gmt, comment_author_IP, comment_author_email
|
176 |
'error' => 0
|
177 |
);
|
178 |
|
179 |
+
if( count($c) > 0){
|
180 |
|
181 |
+
// Converting $c to objects
|
182 |
if(is_array($c[0])){
|
183 |
foreach($c as $key => $value){
|
184 |
$c[$key] = (object)$value;
|
185 |
+
}
|
186 |
}
|
187 |
|
188 |
if(!empty($_POST['accurate_check'])){
|
190 |
|
191 |
foreach($c as $comment_index => $comment){
|
192 |
|
193 |
+
if(!isset($curr_date)) {
|
194 |
+
$curr_date = ( substr( $comment->comment_date_gmt, 0, 10 ) ?: '' );
|
195 |
+
}
|
196 |
|
197 |
+
if(substr($comment->comment_date_gmt, 0, 10) != $curr_date) {
|
198 |
+
unset( $c[ $comment_index ] );
|
199 |
+
}
|
200 |
|
201 |
}
|
|
|
202 |
}
|
203 |
|
204 |
// Checking comments IP/Email. Gathering $data for check.
|
205 |
+
$data = array();
|
206 |
+
foreach ( $c as $i => $iValue ) {
|
207 |
+
|
208 |
+
$curr_ip = $iValue->comment_author_IP;
|
209 |
+
$curr_email = $iValue->comment_author_email;
|
210 |
+
|
211 |
+
// Check for identity
|
212 |
+
$curr_ip = preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $curr_ip) === 1 ? $curr_ip : null;
|
213 |
+
$curr_email = preg_match('/^\S+@\S+\.\S+$/', $curr_email) === 1 ? $curr_email : null;
|
214 |
+
|
215 |
+
if(empty($curr_ip) && empty($curr_email)){
|
216 |
+
$check_result['bad']++;
|
217 |
+
update_comment_meta( $iValue->comment_ID,'ct_bad','1');
|
218 |
+
update_comment_meta( $iValue->comment_ID,'ct_checked','1');
|
219 |
+
update_comment_meta( $iValue->comment_ID,'ct_checked_now','1');
|
220 |
+
unset($c[$i]);
|
221 |
+
}else{
|
222 |
+
if(!empty($curr_ip)) {
|
223 |
+
$data[] = $curr_ip;
|
224 |
+
}
|
225 |
+
if(!empty($curr_email)) {
|
226 |
+
$data[] = $curr_email;
|
227 |
+
}
|
228 |
+
// Patch for empty IP/Email
|
229 |
+
$iValue->comment_author_IP = empty($curr_ip) ? 'none' : $curr_ip;
|
230 |
+
$iValue->comment_author_email = empty($curr_email) ? 'none' : $curr_email;
|
231 |
+
}
|
232 |
+
}
|
233 |
+
|
234 |
+
// Recombining after checking and unsetting
|
235 |
$c = array_values($c);
|
236 |
|
237 |
// Drop if data empty and there's no comments to check
|
238 |
+
if(count($data) === 0){
|
239 |
+
if($_POST['unchecked'] === 0) {
|
240 |
+
$check_result['end'] = 1;
|
241 |
+
}
|
242 |
print json_encode($check_result);
|
243 |
die();
|
244 |
}
|
245 |
|
246 |
+
$result = API::method__spam_check_cms($apbct->api_key, $data, !empty($_POST['accurate_check']) ? $curr_date : null);
|
247 |
|
248 |
if(empty($result['error'])){
|
249 |
|
250 |
+
foreach ( $c as $iValue ) {
|
251 |
|
252 |
+
$mark_spam_ip = false;
|
253 |
+
$mark_spam_email = false;
|
254 |
|
255 |
+
$check_result['checked']++;
|
256 |
+
update_comment_meta( $iValue->comment_ID,'ct_checked',date("Y-m-d H:m:s"));
|
257 |
+
update_comment_meta( $iValue->comment_ID, 'ct_checked_now', date("Y-m-d H:m:s"), true) ;
|
258 |
|
259 |
+
$uip= $iValue->comment_author_IP;
|
260 |
+
$uim= $iValue->comment_author_email;
|
261 |
|
262 |
+
if(isset($result[$uip]) && isset( $result[$uim]['appears'] ) && $result[$uip]['appears'] == 1) {
|
263 |
+
$mark_spam_ip = true;
|
264 |
+
}
|
265 |
|
266 |
+
if(isset($result[$uim]) && isset( $result[$uim]['appears'] ) && $result[$uim]['appears'] == 1) {
|
267 |
+
$mark_spam_email = true;
|
268 |
+
}
|
269 |
|
270 |
+
if ($mark_spam_ip || $mark_spam_email){
|
271 |
+
$check_result['spam']++;
|
272 |
+
update_comment_meta( $iValue->comment_ID,'ct_marked_as_spam','1');
|
273 |
+
}
|
274 |
+
}
|
275 |
+
print json_encode($check_result);
|
276 |
|
277 |
}else{
|
278 |
$check_result['error'] = 1;
|
295 |
|
296 |
public static function ct_ajax_info($direct_call = false){
|
297 |
|
298 |
+
global $wpdb;
|
299 |
+
|
300 |
+
if (!$direct_call) {
|
301 |
+
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
302 |
+
}
|
303 |
|
304 |
// Checked comments
|
305 |
$params_checked = array(
|
359 |
);
|
360 |
} else {
|
361 |
|
|
|
|
|
362 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'comments' ORDER BY start_time DESC";
|
363 |
$res = $wpdb->get_row( $query, ARRAY_A );
|
364 |
|
398 |
|
399 |
public static function ct_ajax_clear_comments(){
|
400 |
|
401 |
+
global $wpdb;
|
402 |
+
|
403 |
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
404 |
|
|
|
405 |
$wpdb->query("DELETE FROM {$wpdb->commentmeta} WHERE meta_key IN ('ct_checked_now')");
|
406 |
|
407 |
if ( isset($_POST['from']) && isset($_POST['till']) ) {
|
504 |
);
|
505 |
$cnt_all = get_comments($args_spam);
|
506 |
|
507 |
+
foreach ( $c_spam as $iValue ) {
|
508 |
+
wp_trash_comment( $iValue->comment_ID );
|
509 |
+
usleep(10000);
|
510 |
+
}
|
511 |
+
/** @psalm-suppress InvalidArgument */
|
512 |
print $cnt_all;
|
513 |
die();
|
514 |
}
|
539 |
)
|
540 |
)
|
541 |
);
|
542 |
+
$cnt_all = get_comments( $args_spam );
|
543 |
+
|
544 |
+
foreach ( $c_spam as $iValue ) {
|
545 |
+
wp_spam_comment( $iValue->comment_ID );
|
546 |
+
usleep(10000);
|
547 |
+
}
|
548 |
+
/** @psalm-suppress InvalidArgument */
|
549 |
+
print $cnt_all;
|
550 |
die();
|
551 |
}
|
552 |
|
553 |
+
}
|
@@ -11,7 +11,7 @@ class BadUsers extends Users {
|
|
11 |
$columns = $this->get_columns();
|
12 |
$this->_column_headers = array( $columns, array(), array() );
|
13 |
|
14 |
-
$per_page_option = ! is_null( get_current_screen() ) ? get_current_screen()->get_option( 'per_page', 'option' ) : 10;
|
15 |
$per_page = get_user_meta( get_current_user_id(), $per_page_option, true );
|
16 |
if( ! $per_page ) {
|
17 |
$per_page = 10;
|
@@ -24,7 +24,7 @@ class BadUsers extends Users {
|
|
24 |
'per_page' => $per_page,
|
25 |
) );
|
26 |
|
27 |
-
$current_page =
|
28 |
|
29 |
$scanned_users_to_show = array_slice( $scanned_users->get_results(), ( ( $current_page - 1 ) * $per_page ), $per_page );
|
30 |
|
@@ -81,10 +81,12 @@ class BadUsers extends Users {
|
|
81 |
." <img src='" . APBCT_URL_PATH . "/inc/images/new_window.gif' alt='Ico: open in new window' border='0' style='float:none' />"
|
82 |
."</a>"
|
83 |
: '');
|
84 |
-
}else
|
85 |
-
$column_content .= esc_html__( 'No IP adress', 'cleantalk-spam-protect');
|
86 |
-
|
87 |
-
|
|
|
|
|
88 |
|
89 |
return $column_content;
|
90 |
|
@@ -97,10 +99,10 @@ class BadUsers extends Users {
|
|
97 |
}
|
98 |
|
99 |
function get_bulk_actions() {
|
100 |
-
return
|
101 |
}
|
102 |
|
103 |
function no_items() {
|
104 |
esc_html_e( 'No non-checkable users found.', 'cleantalk-spam-protect');
|
105 |
}
|
106 |
-
}
|
11 |
$columns = $this->get_columns();
|
12 |
$this->_column_headers = array( $columns, array(), array() );
|
13 |
|
14 |
+
$per_page_option = ! is_null( get_current_screen() ) ? get_current_screen()->get_option( 'per_page', 'option' ) : '10';
|
15 |
$per_page = get_user_meta( get_current_user_id(), $per_page_option, true );
|
16 |
if( ! $per_page ) {
|
17 |
$per_page = 10;
|
24 |
'per_page' => $per_page,
|
25 |
) );
|
26 |
|
27 |
+
$current_page = $this->get_pagenum();
|
28 |
|
29 |
$scanned_users_to_show = array_slice( $scanned_users->get_results(), ( ( $current_page - 1 ) * $per_page ), $per_page );
|
30 |
|
81 |
." <img src='" . APBCT_URL_PATH . "/inc/images/new_window.gif' alt='Ico: open in new window' border='0' style='float:none' />"
|
82 |
."</a>"
|
83 |
: '');
|
84 |
+
}else {
|
85 |
+
$column_content .= esc_html__( 'No IP adress', 'cleantalk-spam-protect' );
|
86 |
+
}
|
87 |
+
}else {
|
88 |
+
$column_content .= esc_html__( 'No IP adress', 'cleantalk-spam-protect' );
|
89 |
+
}
|
90 |
|
91 |
return $column_content;
|
92 |
|
99 |
}
|
100 |
|
101 |
function get_bulk_actions() {
|
102 |
+
return array();
|
103 |
}
|
104 |
|
105 |
function no_items() {
|
106 |
esc_html_e( 'No non-checkable users found.', 'cleantalk-spam-protect');
|
107 |
}
|
108 |
+
}
|
@@ -23,7 +23,12 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
23 |
$this->apbct = $apbct;
|
24 |
|
25 |
}
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
function get_columns(){
|
28 |
return array(
|
29 |
'cb' => '<input type="checkbox" />',
|
@@ -33,12 +38,24 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
33 |
);
|
34 |
}
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
function column_cb( $item ){
|
38 |
echo '<input type="checkbox" name="spamids[]" id="cb-select-'. $item['ct_id'] .'" value="'. $item['ct_id'] .'" />';
|
39 |
}
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
function column_ct_author( $item ) {
|
43 |
|
44 |
$column_content = '';
|
@@ -78,6 +95,12 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
78 |
|
79 |
}
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
function column_ct_comment( $item ){
|
82 |
|
83 |
$id = $item['ct_id'];
|
@@ -108,6 +131,10 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
108 |
|
109 |
}
|
110 |
|
|
|
|
|
|
|
|
|
111 |
function column_ct_response_to( $item ) {
|
112 |
$post_id = $item['ct_response_to'];
|
113 |
?>
|
@@ -127,7 +154,15 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
127 |
<?php
|
128 |
}
|
129 |
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
function column_default( $item, $column_name ) {
|
132 |
switch( $column_name ) {
|
133 |
case 'ct_author':
|
@@ -144,27 +179,31 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
144 |
}
|
145 |
|
146 |
function get_bulk_actions() {
|
147 |
-
|
148 |
'spam' => esc_html__( 'Mark as spam', 'cleantalk-spam-protect' ),
|
149 |
'trash' => esc_html__( 'Move to trash', 'cleantalk-spam-protect' ),
|
150 |
);
|
151 |
-
return $actions;
|
152 |
}
|
153 |
|
154 |
function bulk_actions_handler() {
|
155 |
|
156 |
-
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) )
|
|
|
|
|
157 |
|
158 |
-
if ( ! $action = $this->current_action() )
|
|
|
|
|
159 |
|
160 |
-
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) )
|
161 |
-
|
|
|
162 |
|
163 |
-
if( 'trash'
|
164 |
$this->moveToTrash( $_POST['spamids'] );
|
165 |
}
|
166 |
|
167 |
-
if( 'spam'
|
168 |
$this->moveToSpam( $_POST['spamids'] );
|
169 |
}
|
170 |
|
@@ -172,23 +211,25 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
172 |
|
173 |
function row_actions_handler() {
|
174 |
|
175 |
-
if( empty($_GET['action']) )
|
|
|
|
|
176 |
|
177 |
-
if( $_GET['action']
|
178 |
|
179 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
180 |
$this->approveSpam( $id );
|
181 |
|
182 |
}
|
183 |
|
184 |
-
if( $_GET['action']
|
185 |
|
186 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
187 |
$this->moveToTrash( array( $id ) );
|
188 |
|
189 |
}
|
190 |
|
191 |
-
if( $_GET['action']
|
192 |
|
193 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
194 |
$this->moveToSpam( array( $id ) );
|
@@ -207,16 +248,11 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
207 |
|
208 |
function approveSpam( $id ) {
|
209 |
|
210 |
-
$comment_meta = delete_comment_meta( $id, 'ct_marked_as_spam' );
|
211 |
|
212 |
if( $comment_meta ) {
|
213 |
-
|
214 |
-
|
215 |
-
$comment['comment_approved'] = 1;
|
216 |
-
|
217 |
-
wp_update_comment( $comment );
|
218 |
-
apbct_comment__send_feedback( $id, 'approve', false, true );
|
219 |
-
|
220 |
}
|
221 |
|
222 |
}
|
@@ -225,8 +261,8 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
225 |
|
226 |
if( ! empty( $ids ) ) {
|
227 |
foreach ( $ids as $id) {
|
228 |
-
delete_comment_meta( $id, 'ct_marked_as_spam' );
|
229 |
-
$comment = get_comment( $id );
|
230 |
wp_trash_comment( $comment );
|
231 |
}
|
232 |
}
|
@@ -237,54 +273,73 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
237 |
|
238 |
if( ! empty( $ids ) ) {
|
239 |
foreach ( $ids as $id) {
|
240 |
-
delete_comment_meta( $id, 'ct_marked_as_spam' );
|
241 |
-
$comment = get_comment( $id );
|
242 |
wp_spam_comment( $comment );
|
243 |
}
|
244 |
}
|
245 |
|
246 |
}
|
247 |
|
|
|
|
|
|
|
|
|
248 |
public function getTotal() {
|
249 |
|
250 |
-
|
251 |
-
return $total_comments;
|
252 |
|
253 |
}
|
254 |
|
|
|
|
|
|
|
|
|
255 |
public function getChecked() {
|
256 |
|
257 |
$params_spam = array(
|
258 |
'meta_key' => 'ct_checked',
|
259 |
);
|
260 |
-
|
261 |
-
|
262 |
|
263 |
}
|
264 |
|
|
|
|
|
|
|
|
|
265 |
public function getCheckedNow() {
|
266 |
|
267 |
$params_spam = array(
|
268 |
'meta_key' => 'ct_checked_now',
|
269 |
);
|
270 |
-
|
271 |
-
|
272 |
|
273 |
}
|
274 |
|
|
|
|
|
|
|
|
|
275 |
public function getSpam() {
|
276 |
|
277 |
$params_spam = array(
|
278 |
'meta_key' => 'ct_marked_as_spam',
|
279 |
);
|
280 |
-
|
281 |
-
|
282 |
|
283 |
}
|
284 |
|
|
|
|
|
|
|
|
|
|
|
285 |
public function getSpamNow() {
|
286 |
|
287 |
-
// Spam comments
|
288 |
$params_spam = array(
|
289 |
'meta_query' => array(
|
290 |
'relation' => 'AND',
|
@@ -298,18 +353,24 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
298 |
),
|
299 |
)
|
300 |
);
|
301 |
-
|
302 |
-
|
303 |
|
304 |
}
|
305 |
|
306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
$params_bad = array(
|
309 |
'meta_key' => 'ct_bad',
|
310 |
);
|
311 |
-
|
312 |
-
|
313 |
|
314 |
}
|
315 |
|
@@ -317,8 +378,8 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
317 |
|
318 |
global $wpdb;
|
319 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'comments'";
|
320 |
-
|
321 |
-
|
322 |
|
323 |
}
|
324 |
|
@@ -332,4 +393,4 @@ class Comments extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
332 |
|
333 |
}
|
334 |
|
335 |
-
}
|
23 |
$this->apbct = $apbct;
|
24 |
|
25 |
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Set columns
|
29 |
+
*
|
30 |
+
* @return array
|
31 |
+
*/
|
32 |
function get_columns(){
|
33 |
return array(
|
34 |
'cb' => '<input type="checkbox" />',
|
38 |
);
|
39 |
}
|
40 |
|
41 |
+
/**
|
42 |
+
* CheckBox column
|
43 |
+
*
|
44 |
+
* @param object $item
|
45 |
+
* @psalm-suppress InvalidArrayAccess
|
46 |
+
*/
|
47 |
function column_cb( $item ){
|
48 |
echo '<input type="checkbox" name="spamids[]" id="cb-select-'. $item['ct_id'] .'" value="'. $item['ct_id'] .'" />';
|
49 |
}
|
50 |
|
51 |
+
/**
|
52 |
+
* Author (first) column
|
53 |
+
*
|
54 |
+
* @param $item
|
55 |
+
*
|
56 |
+
* @return string
|
57 |
+
* @psalm-suppress PossiblyUnusedMethod
|
58 |
+
*/
|
59 |
function column_ct_author( $item ) {
|
60 |
|
61 |
$column_content = '';
|
95 |
|
96 |
}
|
97 |
|
98 |
+
/**
|
99 |
+
* @param $item
|
100 |
+
*
|
101 |
+
* @return string
|
102 |
+
* @psalm-suppress PossiblyUnusedMethod
|
103 |
+
*/
|
104 |
function column_ct_comment( $item ){
|
105 |
|
106 |
$id = $item['ct_id'];
|
131 |
|
132 |
}
|
133 |
|
134 |
+
/**
|
135 |
+
* @param $item
|
136 |
+
* @psalm-suppress PossiblyUnusedMethod
|
137 |
+
*/
|
138 |
function column_ct_response_to( $item ) {
|
139 |
$post_id = $item['ct_response_to'];
|
140 |
?>
|
154 |
<?php
|
155 |
}
|
156 |
|
157 |
+
/**
|
158 |
+
* Rest of columns
|
159 |
+
*
|
160 |
+
* @param object $item
|
161 |
+
* @param string $column_name
|
162 |
+
*
|
163 |
+
* @return bool|string|void
|
164 |
+
* @psalm-suppress InvalidArrayAccess
|
165 |
+
*/
|
166 |
function column_default( $item, $column_name ) {
|
167 |
switch( $column_name ) {
|
168 |
case 'ct_author':
|
179 |
}
|
180 |
|
181 |
function get_bulk_actions() {
|
182 |
+
return array(
|
183 |
'spam' => esc_html__( 'Mark as spam', 'cleantalk-spam-protect' ),
|
184 |
'trash' => esc_html__( 'Move to trash', 'cleantalk-spam-protect' ),
|
185 |
);
|
|
|
186 |
}
|
187 |
|
188 |
function bulk_actions_handler() {
|
189 |
|
190 |
+
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) ) {
|
191 |
+
return;
|
192 |
+
}
|
193 |
|
194 |
+
if ( ! $action = $this->current_action() ) {
|
195 |
+
return;
|
196 |
+
}
|
197 |
|
198 |
+
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) ) {
|
199 |
+
wp_die( 'nonce error' );
|
200 |
+
}
|
201 |
|
202 |
+
if( 'trash' === $action ) {
|
203 |
$this->moveToTrash( $_POST['spamids'] );
|
204 |
}
|
205 |
|
206 |
+
if( 'spam' === $action ) {
|
207 |
$this->moveToSpam( $_POST['spamids'] );
|
208 |
}
|
209 |
|
211 |
|
212 |
function row_actions_handler() {
|
213 |
|
214 |
+
if( empty($_GET['action']) ) {
|
215 |
+
return;
|
216 |
+
}
|
217 |
|
218 |
+
if( $_GET['action'] === 'approve' ) {
|
219 |
|
220 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
221 |
$this->approveSpam( $id );
|
222 |
|
223 |
}
|
224 |
|
225 |
+
if( $_GET['action'] === 'trash' ) {
|
226 |
|
227 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
228 |
$this->moveToTrash( array( $id ) );
|
229 |
|
230 |
}
|
231 |
|
232 |
+
if( $_GET['action'] === 'spam' ) {
|
233 |
|
234 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
235 |
$this->moveToSpam( array( $id ) );
|
248 |
|
249 |
function approveSpam( $id ) {
|
250 |
|
251 |
+
$comment_meta = delete_comment_meta( (int) $id, 'ct_marked_as_spam' );
|
252 |
|
253 |
if( $comment_meta ) {
|
254 |
+
wp_set_comment_status( (int) $id, '1' );
|
255 |
+
apbct_comment__send_feedback( (int) $id, 'approve', false, true );
|
|
|
|
|
|
|
|
|
|
|
256 |
}
|
257 |
|
258 |
}
|
261 |
|
262 |
if( ! empty( $ids ) ) {
|
263 |
foreach ( $ids as $id) {
|
264 |
+
delete_comment_meta( (int) $id, 'ct_marked_as_spam' );
|
265 |
+
$comment = get_comment( (int) $id );
|
266 |
wp_trash_comment( $comment );
|
267 |
}
|
268 |
}
|
273 |
|
274 |
if( ! empty( $ids ) ) {
|
275 |
foreach ( $ids as $id) {
|
276 |
+
delete_comment_meta( (int) $id, 'ct_marked_as_spam' );
|
277 |
+
$comment = get_comment( (int) $id );
|
278 |
wp_spam_comment( $comment );
|
279 |
}
|
280 |
}
|
281 |
|
282 |
}
|
283 |
|
284 |
+
/**
|
285 |
+
* @return \WP_Comment_Query
|
286 |
+
* @psalm-suppress PossiblyUnusedMethod
|
287 |
+
*/
|
288 |
public function getTotal() {
|
289 |
|
290 |
+
return new \WP_Comment_Query();
|
|
|
291 |
|
292 |
}
|
293 |
|
294 |
+
/**
|
295 |
+
* @return \WP_Comment_Query
|
296 |
+
* @psalm-suppress PossiblyUnusedMethod
|
297 |
+
*/
|
298 |
public function getChecked() {
|
299 |
|
300 |
$params_spam = array(
|
301 |
'meta_key' => 'ct_checked',
|
302 |
);
|
303 |
+
|
304 |
+
return new \WP_Comment_Query($params_spam);
|
305 |
|
306 |
}
|
307 |
|
308 |
+
/**
|
309 |
+
* @return \WP_Comment_Query
|
310 |
+
* @psalm-suppress PossiblyUnusedMethod
|
311 |
+
*/
|
312 |
public function getCheckedNow() {
|
313 |
|
314 |
$params_spam = array(
|
315 |
'meta_key' => 'ct_checked_now',
|
316 |
);
|
317 |
+
|
318 |
+
return new \WP_Comment_Query($params_spam);
|
319 |
|
320 |
}
|
321 |
|
322 |
+
/**
|
323 |
+
* @return \WP_Comment_Query
|
324 |
+
* @psalm-suppress PossiblyUnusedMethod
|
325 |
+
*/
|
326 |
public function getSpam() {
|
327 |
|
328 |
$params_spam = array(
|
329 |
'meta_key' => 'ct_marked_as_spam',
|
330 |
);
|
331 |
+
|
332 |
+
return new \WP_Comment_Query($params_spam);
|
333 |
|
334 |
}
|
335 |
|
336 |
+
/**
|
337 |
+
* Spam comments
|
338 |
+
*
|
339 |
+
* @return \WP_Comment_Query
|
340 |
+
*/
|
341 |
public function getSpamNow() {
|
342 |
|
|
|
343 |
$params_spam = array(
|
344 |
'meta_query' => array(
|
345 |
'relation' => 'AND',
|
353 |
),
|
354 |
)
|
355 |
);
|
356 |
+
|
357 |
+
return new \WP_Comment_Query($params_spam);
|
358 |
|
359 |
}
|
360 |
|
361 |
+
/**
|
362 |
+
* Without IP and EMAIL
|
363 |
+
*
|
364 |
+
* @return \WP_Comment_Query
|
365 |
+
* @psalm-suppress PossiblyUnusedMethod
|
366 |
+
*/
|
367 |
+
public function getBad() {
|
368 |
|
369 |
$params_bad = array(
|
370 |
'meta_key' => 'ct_bad',
|
371 |
);
|
372 |
+
|
373 |
+
return new \WP_Comment_Query($params_bad);
|
374 |
|
375 |
}
|
376 |
|
378 |
|
379 |
global $wpdb;
|
380 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'comments'";
|
381 |
+
|
382 |
+
return $wpdb->get_results( $query, ARRAY_A );
|
383 |
|
384 |
}
|
385 |
|
393 |
|
394 |
}
|
395 |
|
396 |
+
}
|
@@ -38,20 +38,24 @@ class CommentsLogs extends Comments
|
|
38 |
}
|
39 |
|
40 |
function get_bulk_actions() {
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
return $actions;
|
45 |
}
|
46 |
|
47 |
function bulk_actions_handler() {
|
48 |
|
49 |
-
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) )
|
|
|
|
|
50 |
|
51 |
-
if ( ! $
|
|
|
|
|
52 |
|
53 |
-
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) )
|
54 |
-
|
|
|
55 |
|
56 |
$this->removeLogs( $_POST['spamids'] );
|
57 |
|
38 |
}
|
39 |
|
40 |
function get_bulk_actions() {
|
41 |
+
return array(
|
42 |
+
'delete' => 'Delete'
|
43 |
+
);
|
|
|
44 |
}
|
45 |
|
46 |
function bulk_actions_handler() {
|
47 |
|
48 |
+
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) ) {
|
49 |
+
return;
|
50 |
+
}
|
51 |
|
52 |
+
if ( ! $this->current_action() ) {
|
53 |
+
return;
|
54 |
+
}
|
55 |
|
56 |
+
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) ) {
|
57 |
+
wp_die( 'nonce error' );
|
58 |
+
}
|
59 |
|
60 |
$this->removeLogs( $_POST['spamids'] );
|
61 |
|
@@ -48,12 +48,24 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
48 |
return $columns;
|
49 |
}
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
function column_cb( $item ){
|
53 |
echo '<input type="checkbox" name="spamids[]" id="cb-select-'. $item['ct_id'] .'" value="'. $item['ct_id'] .'" />';
|
54 |
}
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
function column_ct_username( $item ) {
|
58 |
$user_obj = $item['ct_username'];
|
59 |
$email = $user_obj->user_email;
|
@@ -101,7 +113,15 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
101 |
|
102 |
}
|
103 |
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
function column_default( $item, $column_name ) {
|
106 |
switch( $column_name ) {
|
107 |
case 'ct_name':
|
@@ -121,20 +141,24 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
121 |
}
|
122 |
|
123 |
function get_bulk_actions() {
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
return $actions;
|
128 |
}
|
129 |
|
130 |
function bulk_actions_handler() {
|
131 |
|
132 |
-
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) )
|
|
|
|
|
133 |
|
134 |
-
if ( ! $
|
|
|
|
|
135 |
|
136 |
-
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) )
|
137 |
-
|
|
|
138 |
|
139 |
$this->removeSpam( $_POST['spamids'] );
|
140 |
|
@@ -142,9 +166,11 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
142 |
|
143 |
function row_actions_handler() {
|
144 |
|
145 |
-
if( empty($_GET['action']) )
|
|
|
|
|
146 |
|
147 |
-
if( $_GET['action']
|
148 |
|
149 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
150 |
$this->removeSpam( array( $id ) );
|
@@ -165,7 +191,7 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
165 |
|
166 |
foreach( $ids as $id ) {
|
167 |
|
168 |
-
$user_id = sanitize_key( $id ) ;
|
169 |
|
170 |
//Send feedback
|
171 |
$hash = get_user_meta($user_id, 'ct_hash', true);
|
@@ -180,6 +206,10 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
180 |
|
181 |
}
|
182 |
|
|
|
|
|
|
|
|
|
183 |
public function getTotal() {
|
184 |
|
185 |
$params_total = array(
|
@@ -187,11 +217,15 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
187 |
'count'=>true,
|
188 |
'orderby' => 'user_registered'
|
189 |
);
|
190 |
-
|
191 |
-
|
192 |
|
193 |
}
|
194 |
|
|
|
|
|
|
|
|
|
195 |
public function getChecked() {
|
196 |
|
197 |
$params_spam = array(
|
@@ -199,11 +233,15 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
199 |
'meta_key' => 'ct_checked',
|
200 |
'count_total' => true,
|
201 |
);
|
202 |
-
|
203 |
-
|
204 |
|
205 |
}
|
206 |
|
|
|
|
|
|
|
|
|
207 |
public function getCheckedNow() {
|
208 |
|
209 |
$params_spam = array(
|
@@ -211,11 +249,15 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
211 |
'meta_key' => 'ct_checked_now',
|
212 |
'count_total' => true,
|
213 |
);
|
214 |
-
|
215 |
-
|
216 |
|
217 |
}
|
218 |
|
|
|
|
|
|
|
|
|
219 |
public function getSpam() {
|
220 |
|
221 |
$params_spam = array(
|
@@ -223,8 +265,8 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
223 |
'meta_key' => 'ct_marked_as_spam',
|
224 |
'count_total' => true,
|
225 |
);
|
226 |
-
|
227 |
-
|
228 |
|
229 |
}
|
230 |
|
@@ -245,8 +287,8 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
245 |
),
|
246 |
'count_total' => true,
|
247 |
);
|
248 |
-
|
249 |
-
|
250 |
|
251 |
}
|
252 |
|
@@ -257,8 +299,8 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
257 |
'meta_key' => 'ct_bad',
|
258 |
'count_total' => true,
|
259 |
);
|
260 |
-
|
261 |
-
|
262 |
|
263 |
}
|
264 |
|
@@ -266,8 +308,8 @@ class Users extends \Cleantalk\ApbctWP\CleantalkListTable
|
|
266 |
|
267 |
global $wpdb;
|
268 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'users'";
|
269 |
-
|
270 |
-
|
271 |
|
272 |
}
|
273 |
|
48 |
return $columns;
|
49 |
}
|
50 |
|
51 |
+
/**
|
52 |
+
* CheckBox column
|
53 |
+
*
|
54 |
+
* @param object $item
|
55 |
+
* @psalm-suppress InvalidArrayAccess
|
56 |
+
*/
|
57 |
function column_cb( $item ){
|
58 |
echo '<input type="checkbox" name="spamids[]" id="cb-select-'. $item['ct_id'] .'" value="'. $item['ct_id'] .'" />';
|
59 |
}
|
60 |
|
61 |
+
/**
|
62 |
+
* Username (first) column
|
63 |
+
*
|
64 |
+
* @param $item
|
65 |
+
*
|
66 |
+
* @return string
|
67 |
+
* @psalm-suppress PossiblyUnusedMethod
|
68 |
+
*/
|
69 |
function column_ct_username( $item ) {
|
70 |
$user_obj = $item['ct_username'];
|
71 |
$email = $user_obj->user_email;
|
113 |
|
114 |
}
|
115 |
|
116 |
+
/**
|
117 |
+
* Rest of columns
|
118 |
+
*
|
119 |
+
* @param object $item
|
120 |
+
* @param string $column_name
|
121 |
+
*
|
122 |
+
* @return bool|string|void
|
123 |
+
* @psalm-suppress InvalidArrayAccess
|
124 |
+
*/
|
125 |
function column_default( $item, $column_name ) {
|
126 |
switch( $column_name ) {
|
127 |
case 'ct_name':
|
141 |
}
|
142 |
|
143 |
function get_bulk_actions() {
|
144 |
+
return array(
|
145 |
+
'delete' => 'Delete'
|
146 |
+
);
|
|
|
147 |
}
|
148 |
|
149 |
function bulk_actions_handler() {
|
150 |
|
151 |
+
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) ) {
|
152 |
+
return;
|
153 |
+
}
|
154 |
|
155 |
+
if ( ! $this->current_action() ) {
|
156 |
+
return;
|
157 |
+
}
|
158 |
|
159 |
+
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) ) {
|
160 |
+
wp_die( 'nonce error' );
|
161 |
+
}
|
162 |
|
163 |
$this->removeSpam( $_POST['spamids'] );
|
164 |
|
166 |
|
167 |
function row_actions_handler() {
|
168 |
|
169 |
+
if( empty($_GET['action']) ) {
|
170 |
+
return;
|
171 |
+
}
|
172 |
|
173 |
+
if( $_GET['action'] === 'delete' ) {
|
174 |
|
175 |
$id = filter_input( INPUT_GET, 'spam', FILTER_SANITIZE_NUMBER_INT );
|
176 |
$this->removeSpam( array( $id ) );
|
191 |
|
192 |
foreach( $ids as $id ) {
|
193 |
|
194 |
+
$user_id = (int) sanitize_key( $id ) ;
|
195 |
|
196 |
//Send feedback
|
197 |
$hash = get_user_meta($user_id, 'ct_hash', true);
|
206 |
|
207 |
}
|
208 |
|
209 |
+
/**
|
210 |
+
* @return \WP_User_Query
|
211 |
+
* @psalm-suppress PossiblyUnusedMethod
|
212 |
+
*/
|
213 |
public function getTotal() {
|
214 |
|
215 |
$params_total = array(
|
217 |
'count'=>true,
|
218 |
'orderby' => 'user_registered'
|
219 |
);
|
220 |
+
|
221 |
+
return new \WP_User_Query($params_total);
|
222 |
|
223 |
}
|
224 |
|
225 |
+
/**
|
226 |
+
* @return \WP_User_Query
|
227 |
+
* @psalm-suppress PossiblyUnusedMethod
|
228 |
+
*/
|
229 |
public function getChecked() {
|
230 |
|
231 |
$params_spam = array(
|
233 |
'meta_key' => 'ct_checked',
|
234 |
'count_total' => true,
|
235 |
);
|
236 |
+
|
237 |
+
return new \WP_User_Query($params_spam);
|
238 |
|
239 |
}
|
240 |
|
241 |
+
/**
|
242 |
+
* @return \WP_User_Query
|
243 |
+
* @psalm-suppress PossiblyUnusedMethod
|
244 |
+
*/
|
245 |
public function getCheckedNow() {
|
246 |
|
247 |
$params_spam = array(
|
249 |
'meta_key' => 'ct_checked_now',
|
250 |
'count_total' => true,
|
251 |
);
|
252 |
+
|
253 |
+
return new \WP_User_Query($params_spam);
|
254 |
|
255 |
}
|
256 |
|
257 |
+
/**
|
258 |
+
* @return \WP_User_Query
|
259 |
+
* @psalm-suppress PossiblyUnusedMethod
|
260 |
+
*/
|
261 |
public function getSpam() {
|
262 |
|
263 |
$params_spam = array(
|
265 |
'meta_key' => 'ct_marked_as_spam',
|
266 |
'count_total' => true,
|
267 |
);
|
268 |
+
|
269 |
+
return new \WP_User_Query($params_spam);
|
270 |
|
271 |
}
|
272 |
|
287 |
),
|
288 |
'count_total' => true,
|
289 |
);
|
290 |
+
|
291 |
+
return new \WP_User_Query($params_spam);
|
292 |
|
293 |
}
|
294 |
|
299 |
'meta_key' => 'ct_bad',
|
300 |
'count_total' => true,
|
301 |
);
|
302 |
+
|
303 |
+
return new \WP_User_Query($params_bad);
|
304 |
|
305 |
}
|
306 |
|
308 |
|
309 |
global $wpdb;
|
310 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'users'";
|
311 |
+
|
312 |
+
return $wpdb->get_results( $query, ARRAY_A );
|
313 |
|
314 |
}
|
315 |
|
@@ -38,20 +38,24 @@ class UsersLogs extends Users
|
|
38 |
}
|
39 |
|
40 |
function get_bulk_actions() {
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
return $actions;
|
45 |
}
|
46 |
|
47 |
function bulk_actions_handler() {
|
48 |
|
49 |
-
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) )
|
|
|
|
|
50 |
|
51 |
-
if ( ! $
|
|
|
|
|
52 |
|
53 |
-
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) )
|
54 |
-
|
|
|
55 |
|
56 |
$this->removeLogs( $_POST['spamids'] );
|
57 |
|
38 |
}
|
39 |
|
40 |
function get_bulk_actions() {
|
41 |
+
return array(
|
42 |
+
'delete' => 'Delete'
|
43 |
+
);
|
|
|
44 |
}
|
45 |
|
46 |
function bulk_actions_handler() {
|
47 |
|
48 |
+
if( empty($_POST['spamids']) || empty($_POST['_wpnonce']) ) {
|
49 |
+
return;
|
50 |
+
}
|
51 |
|
52 |
+
if ( ! $this->current_action() ) {
|
53 |
+
return;
|
54 |
+
}
|
55 |
|
56 |
+
if( ! wp_verify_nonce( $_POST['_wpnonce'], 'bulk-' . $this->_args['plural'] ) ) {
|
57 |
+
wp_die( 'nonce error' );
|
58 |
+
}
|
59 |
|
60 |
$this->removeLogs( $_POST['spamids'] );
|
61 |
|
@@ -32,6 +32,7 @@ class Page
|
|
32 |
case 'users_page_ct_check_users_bad' :
|
33 |
$this->current_tab = 2;
|
34 |
$this->generatePageHeader();
|
|
|
35 |
$this->spam_checker->getBadUsersPage();
|
36 |
break;
|
37 |
|
32 |
case 'users_page_ct_check_users_bad' :
|
33 |
$this->current_tab = 2;
|
34 |
$this->generatePageHeader();
|
35 |
+
/** @psalm-suppress UndefinedMethod */
|
36 |
$this->spam_checker->getBadUsersPage();
|
37 |
break;
|
38 |
|
@@ -59,6 +59,9 @@ class UsersChecker extends Checker
|
|
59 |
|
60 |
}
|
61 |
|
|
|
|
|
|
|
62 |
public function getBadUsersPage(){
|
63 |
|
64 |
$this->list_table = new \Cleantalk\ApbctWP\FindSpam\ListTable\BadUsers();
|
@@ -74,6 +77,8 @@ class UsersChecker extends Checker
|
|
74 |
* Getting a count of total users of the website and return formatted string about this.
|
75 |
*
|
76 |
* @return string
|
|
|
|
|
77 |
*/
|
78 |
public static function get_count_text() {
|
79 |
|
@@ -159,7 +164,7 @@ class UsersChecker extends Checker
|
|
159 |
}
|
160 |
|
161 |
$amount = !empty($_POST['amount']) && intval($_POST['amount'])
|
162 |
-
?
|
163 |
: 100;
|
164 |
|
165 |
$skip_roles = array(
|
@@ -210,57 +215,62 @@ class UsersChecker extends Checker
|
|
210 |
// Leaving users only with first comment's date. Unsetting others.
|
211 |
foreach( $u as $user_index => $user ){
|
212 |
|
213 |
-
if( ! isset( $curr_date ) )
|
214 |
-
|
|
|
215 |
|
216 |
-
if( substr( $user->user_registered, 0, 10 ) != $curr_date )
|
217 |
-
|
|
|
218 |
|
219 |
}
|
220 |
-
unset( $user_index, $user );
|
221 |
}
|
222 |
|
223 |
// Checking comments IP/Email. Gathering $data for check.
|
224 |
$data = array();
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
|
|
|
|
258 |
$u = array_values( $u );
|
259 |
|
260 |
// Drop if data empty and there's no users to check
|
261 |
-
if( count( $data )
|
262 |
-
if( $_POST['unchecked'] === 0 )
|
263 |
-
|
|
|
264 |
print json_encode( $check_result );
|
265 |
die();
|
266 |
}
|
@@ -269,50 +279,48 @@ class UsersChecker extends Checker
|
|
269 |
|
270 |
if( empty( $result['error'] ) ){
|
271 |
|
272 |
-
|
273 |
-
|
274 |
-
$check_result['checked']++;
|
275 |
-
update_user_meta( $u[$i]->ID, 'ct_checked', date("Y-m-d H:m:s"), true) ;
|
276 |
-
update_user_meta( $u[$i]->ID, 'ct_checked_now', date("Y-m-d H:m:s"), true) ;
|
277 |
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
$user_roles = $user_meta->roles;
|
282 |
-
if ( in_array( $role, $user_roles ) ){
|
283 |
-
delete_user_meta( $u[$i]->ID, 'ct_marked_as_spam' );
|
284 |
-
continue 2;
|
285 |
-
}
|
286 |
-
}
|
287 |
|
288 |
-
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
|
291 |
-
|
292 |
-
|
293 |
|
294 |
-
|
295 |
-
|
296 |
|
297 |
-
|
298 |
-
|
|
|
299 |
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
}
|
304 |
|
305 |
-
|
|
|
|
|
|
|
306 |
|
307 |
-
|
308 |
|
309 |
} else {
|
310 |
|
311 |
$check_result['error'] = 1;
|
312 |
$check_result['error_message'] = $result['error'];
|
313 |
|
314 |
-
echo json_encode( $check_result );
|
315 |
-
|
316 |
}
|
317 |
} else {
|
318 |
|
@@ -321,11 +329,10 @@ class UsersChecker extends Checker
|
|
321 |
$log_data = static::get_log_data();
|
322 |
static::writeSpamLog( 'users', date("Y-m-d H:i:s"), $log_data['checked'], $log_data['spam'], $log_data['bad'] );
|
323 |
|
324 |
-
echo json_encode( $check_result );
|
325 |
-
|
326 |
}
|
|
|
327 |
|
328 |
-
|
329 |
|
330 |
}
|
331 |
|
@@ -364,8 +371,9 @@ class UsersChecker extends Checker
|
|
364 |
|
365 |
public static function ct_ajax_info($direct_call = false) {
|
366 |
|
367 |
-
if (!$direct_call)
|
368 |
-
|
|
|
369 |
|
370 |
global $wpdb;
|
371 |
|
@@ -414,8 +422,6 @@ class UsersChecker extends Checker
|
|
414 |
);
|
415 |
} else {
|
416 |
|
417 |
-
global $wpdb;
|
418 |
-
|
419 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'users' ORDER BY start_time DESC";
|
420 |
$res = $wpdb->get_row( $query, ARRAY_A );
|
421 |
|
@@ -515,17 +521,18 @@ class UsersChecker extends Checker
|
|
515 |
|
516 |
$u = get_users( $params );
|
517 |
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
|
|
527 |
|
528 |
-
|
529 |
|
530 |
if( $filename !== false ) {
|
531 |
header('Content-Type: text/csv');
|
@@ -539,47 +546,47 @@ class UsersChecker extends Checker
|
|
539 |
|
540 |
public static function ct_ajax_insert_users()
|
541 |
{
|
542 |
-
|
543 |
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
|
|
|
|
544 |
|
545 |
-
//* DELETION
|
546 |
if(!empty($_POST['delete'])){
|
547 |
$users = get_users(array('search' => 'user_*', 'search_columns' => array('login', 'nicename')));
|
548 |
$deleted = 0;
|
549 |
$amount_to_delete = 1000;
|
550 |
foreach($users as $user){
|
551 |
-
if($deleted >= $amount_to_delete)
|
552 |
break;
|
553 |
-
|
554 |
-
|
|
|
|
|
555 |
}
|
556 |
print "$deleted";
|
557 |
die();
|
558 |
}
|
559 |
-
|
560 |
-
|
561 |
-
//* INSERTION
|
562 |
-
global $wpdb;
|
563 |
$to_insert = 500;
|
564 |
$result = $wpdb->get_results('SELECT network FROM `'. APBCT_TBL_FIREWALL_DATA .'` LIMIT '. $to_insert .';', ARRAY_A);
|
565 |
|
566 |
-
if($result){
|
567 |
-
$
|
568 |
foreach($result as $value){
|
569 |
$ips[] = long2ip($value['network']);
|
570 |
}
|
571 |
-
unset($value);
|
572 |
|
573 |
$inserted = 0;
|
574 |
-
for($i=0; $i
|
575 |
-
$rnd=mt_rand(1,10000000);
|
576 |
|
577 |
$user_name = "user_$rnd";
|
578 |
$email="stop_email_$rnd@example.com";
|
579 |
|
580 |
$user_id = wp_create_user(
|
581 |
$user_name,
|
582 |
-
rand(),
|
583 |
$email
|
584 |
);
|
585 |
|
@@ -587,30 +594,30 @@ class UsersChecker extends Checker
|
|
587 |
|
588 |
update_user_meta($curr_user->ID, 'session_tokens', array($rnd => array('ip' => $ips[$i])));
|
589 |
|
590 |
-
if (is_int($user_id))
|
591 |
-
$inserted++;
|
|
|
592 |
|
593 |
}
|
594 |
}else{
|
595 |
$inserted = '0';
|
596 |
}
|
597 |
-
//*/
|
598 |
|
599 |
print "$inserted";
|
600 |
die();
|
601 |
}
|
602 |
|
603 |
-
public static function ct_ajax_delete_all_users($count_all = 0)
|
604 |
{
|
605 |
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
606 |
|
607 |
global $wpdb;
|
608 |
|
609 |
-
$r = $wpdb->
|
610 |
|
611 |
-
if(!
|
612 |
|
613 |
-
$count_all =
|
614 |
|
615 |
$args = array(
|
616 |
'meta_key' => 'ct_marked_as_spam',
|
@@ -628,7 +635,7 @@ class UsersChecker extends Checker
|
|
628 |
}
|
629 |
}
|
630 |
|
631 |
-
die($count_all);
|
632 |
}
|
633 |
|
634 |
/**
|
@@ -636,6 +643,8 @@ class UsersChecker extends Checker
|
|
636 |
*
|
637 |
* @param $columns
|
638 |
* @return mixed
|
|
|
|
|
639 |
*/
|
640 |
public static function ct_manage_users_columns( $columns ) {
|
641 |
|
59 |
|
60 |
}
|
61 |
|
62 |
+
/**
|
63 |
+
* @psalm-suppress PossiblyUnusedMethod
|
64 |
+
*/
|
65 |
public function getBadUsersPage(){
|
66 |
|
67 |
$this->list_table = new \Cleantalk\ApbctWP\FindSpam\ListTable\BadUsers();
|
77 |
* Getting a count of total users of the website and return formatted string about this.
|
78 |
*
|
79 |
* @return string
|
80 |
+
*
|
81 |
+
* @psalm-suppress PossiblyUnusedMethod
|
82 |
*/
|
83 |
public static function get_count_text() {
|
84 |
|
164 |
}
|
165 |
|
166 |
$amount = !empty($_POST['amount']) && intval($_POST['amount'])
|
167 |
+
? (int) $_POST['amount']
|
168 |
: 100;
|
169 |
|
170 |
$skip_roles = array(
|
215 |
// Leaving users only with first comment's date. Unsetting others.
|
216 |
foreach( $u as $user_index => $user ){
|
217 |
|
218 |
+
if( ! isset( $curr_date ) ) {
|
219 |
+
$curr_date = ( substr( $user->user_registered, 0, 10 ) ?: '' );
|
220 |
+
}
|
221 |
|
222 |
+
if( substr( $user->user_registered, 0, 10 ) != $curr_date ) {
|
223 |
+
unset( $u[ $user_index ] );
|
224 |
+
}
|
225 |
|
226 |
}
|
|
|
227 |
}
|
228 |
|
229 |
// Checking comments IP/Email. Gathering $data for check.
|
230 |
$data = array();
|
231 |
|
232 |
+
foreach ( $u as $i => $iValue ) {
|
233 |
+
|
234 |
+
$user_meta = get_user_meta( $iValue->ID, 'session_tokens', true );
|
235 |
+
if( is_array( $user_meta ) ) {
|
236 |
+
$user_meta = array_values( $user_meta );
|
237 |
+
}
|
238 |
+
|
239 |
+
$curr_ip = !empty( $user_meta[0]['ip' ]) ? trim( $user_meta[0]['ip'] ) : '';
|
240 |
+
$curr_email = !empty( $iValue->user_email ) ? trim( $iValue->user_email ) : '';
|
241 |
+
|
242 |
+
// Check for identity
|
243 |
+
$curr_ip = preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $curr_ip) === 1 ? $curr_ip : null;
|
244 |
+
$curr_email = preg_match('/^\S+@\S+\.\S+$/', $curr_email) === 1 ? $curr_email : null;
|
245 |
+
|
246 |
+
if( empty( $curr_ip ) && empty( $curr_email ) ){
|
247 |
+
$check_result['bad']++;
|
248 |
+
update_user_meta( $iValue->ID,'ct_bad','1',true );
|
249 |
+
update_user_meta( $iValue->ID, 'ct_checked', date("Y-m-d H:m:s"), true) ;
|
250 |
+
update_user_meta( $iValue->ID, 'ct_checked_now', '1', true) ;
|
251 |
+
unset( $u[$i] );
|
252 |
+
}else{
|
253 |
+
if( !empty( $curr_ip ) ) {
|
254 |
+
$data[] = $curr_ip;
|
255 |
+
}
|
256 |
+
if( !empty( $curr_email ) ) {
|
257 |
+
$data[] = $curr_email;
|
258 |
+
}
|
259 |
+
// Patch for empty IP/Email
|
260 |
+
$iValue->data = new \stdClass();
|
261 |
+
$iValue->user_ip = empty($curr_ip) ? 'none' : $curr_ip;
|
262 |
+
$iValue->user_email = empty($curr_email) ? 'none' : $curr_email;
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
// Recombining after checking and unsetting
|
267 |
$u = array_values( $u );
|
268 |
|
269 |
// Drop if data empty and there's no users to check
|
270 |
+
if( count( $data ) === 0 ){
|
271 |
+
if( $_POST['unchecked'] === 0 ) {
|
272 |
+
$check_result['end'] = 1;
|
273 |
+
}
|
274 |
print json_encode( $check_result );
|
275 |
die();
|
276 |
}
|
279 |
|
280 |
if( empty( $result['error'] ) ){
|
281 |
|
282 |
+
foreach ( $u as $iValue ) {
|
|
|
|
|
|
|
|
|
283 |
|
284 |
+
$check_result['checked']++;
|
285 |
+
update_user_meta( $iValue->ID, 'ct_checked', date("Y-m-d H:m:s"), true) ;
|
286 |
+
update_user_meta( $iValue->ID, 'ct_checked_now', date("Y-m-d H:m:s"), true) ;
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
+
// Do not display forbidden roles.
|
289 |
+
foreach ( $skip_roles as $role ) {
|
290 |
+
$user_meta = get_userdata( $iValue->ID);
|
291 |
+
$user_roles = $user_meta->roles;
|
292 |
+
if ( in_array( $role, $user_roles ) ){
|
293 |
+
delete_user_meta( $iValue->ID, 'ct_marked_as_spam' );
|
294 |
+
continue 2;
|
295 |
+
}
|
296 |
+
}
|
297 |
|
298 |
+
$mark_spam_ip = false;
|
299 |
+
$mark_spam_email = false;
|
300 |
|
301 |
+
$uip = $iValue->user_ip;
|
302 |
+
$uim = $iValue->user_email;
|
303 |
|
304 |
+
if( isset( $result[$uip] ) && $result[$uip]['appears'] == 1 ) {
|
305 |
+
$mark_spam_ip = true;
|
306 |
+
}
|
307 |
|
308 |
+
if( isset($result[$uim]) && $result[$uim]['appears'] == 1 ) {
|
309 |
+
$mark_spam_email = true;
|
310 |
+
}
|
|
|
311 |
|
312 |
+
if ( $mark_spam_ip || $mark_spam_email ){
|
313 |
+
$check_result['spam']++;
|
314 |
+
update_user_meta( $iValue->ID, 'ct_marked_as_spam', '1', true );
|
315 |
+
}
|
316 |
|
317 |
+
}
|
318 |
|
319 |
} else {
|
320 |
|
321 |
$check_result['error'] = 1;
|
322 |
$check_result['error_message'] = $result['error'];
|
323 |
|
|
|
|
|
324 |
}
|
325 |
} else {
|
326 |
|
329 |
$log_data = static::get_log_data();
|
330 |
static::writeSpamLog( 'users', date("Y-m-d H:i:s"), $log_data['checked'], $log_data['spam'], $log_data['bad'] );
|
331 |
|
|
|
|
|
332 |
}
|
333 |
+
echo json_encode( $check_result );
|
334 |
|
335 |
+
die;
|
336 |
|
337 |
}
|
338 |
|
371 |
|
372 |
public static function ct_ajax_info($direct_call = false) {
|
373 |
|
374 |
+
if (!$direct_call) {
|
375 |
+
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
376 |
+
}
|
377 |
|
378 |
global $wpdb;
|
379 |
|
422 |
);
|
423 |
} else {
|
424 |
|
|
|
|
|
425 |
$query = "SELECT * FROM " . APBCT_SPAMSCAN_LOGS . " WHERE scan_type = 'users' ORDER BY start_time DESC";
|
426 |
$res = $wpdb->get_row( $query, ARRAY_A );
|
427 |
|
521 |
|
522 |
$u = get_users( $params );
|
523 |
|
524 |
+
foreach ( $u as $iValue ) {
|
525 |
+
$user_meta = get_user_meta( $iValue->ID, 'session_tokens', true );
|
526 |
+
if( is_array( $user_meta ) ) {
|
527 |
+
$user_meta = array_values( $user_meta );
|
528 |
+
}
|
529 |
+
$text .= $iValue->user_login . ',';
|
530 |
+
$text .= $iValue->data->user_email . ',';
|
531 |
+
$text .= ! empty( $user_meta[0]['ip']) ? trim( $user_meta[0]['ip'] ) : '';
|
532 |
+
$text .= PHP_EOL;
|
533 |
+
}
|
534 |
|
535 |
+
$filename = ! empty( $_POST['filename'] ) ? $_POST['filename'] : false;
|
536 |
|
537 |
if( $filename !== false ) {
|
538 |
header('Content-Type: text/csv');
|
546 |
|
547 |
public static function ct_ajax_insert_users()
|
548 |
{
|
|
|
549 |
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
550 |
+
|
551 |
+
global $wpdb;
|
552 |
|
553 |
+
//* TEST DELETION
|
554 |
if(!empty($_POST['delete'])){
|
555 |
$users = get_users(array('search' => 'user_*', 'search_columns' => array('login', 'nicename')));
|
556 |
$deleted = 0;
|
557 |
$amount_to_delete = 1000;
|
558 |
foreach($users as $user){
|
559 |
+
if($deleted >= $amount_to_delete) {
|
560 |
break;
|
561 |
+
}
|
562 |
+
if(wp_delete_user($user->ID)) {
|
563 |
+
$deleted ++;
|
564 |
+
}
|
565 |
}
|
566 |
print "$deleted";
|
567 |
die();
|
568 |
}
|
569 |
+
|
570 |
+
// TEST INSERTION
|
|
|
|
|
571 |
$to_insert = 500;
|
572 |
$result = $wpdb->get_results('SELECT network FROM `'. APBCT_TBL_FIREWALL_DATA .'` LIMIT '. $to_insert .';', ARRAY_A);
|
573 |
|
574 |
+
if( $result ){
|
575 |
+
$ips = array();
|
576 |
foreach($result as $value){
|
577 |
$ips[] = long2ip($value['network']);
|
578 |
}
|
|
|
579 |
|
580 |
$inserted = 0;
|
581 |
+
for( $i=0; $i < $to_insert; $i++ ){
|
582 |
+
$rnd = mt_rand(1,10000000);
|
583 |
|
584 |
$user_name = "user_$rnd";
|
585 |
$email="stop_email_$rnd@example.com";
|
586 |
|
587 |
$user_id = wp_create_user(
|
588 |
$user_name,
|
589 |
+
(string) rand(),
|
590 |
$email
|
591 |
);
|
592 |
|
594 |
|
595 |
update_user_meta($curr_user->ID, 'session_tokens', array($rnd => array('ip' => $ips[$i])));
|
596 |
|
597 |
+
if (is_int($user_id)) {
|
598 |
+
$inserted ++;
|
599 |
+
}
|
600 |
|
601 |
}
|
602 |
}else{
|
603 |
$inserted = '0';
|
604 |
}
|
|
|
605 |
|
606 |
print "$inserted";
|
607 |
die();
|
608 |
}
|
609 |
|
610 |
+
public static function ct_ajax_delete_all_users( $count_all = 0 )
|
611 |
{
|
612 |
check_ajax_referer( 'ct_secret_nonce', 'security' );
|
613 |
|
614 |
global $wpdb;
|
615 |
|
616 |
+
$r = $wpdb->get_var( "select count(*) as cnt from $wpdb->usermeta where meta_key='ct_marked_as_spam';" );
|
617 |
|
618 |
+
if( ! is_null( $r ) ){
|
619 |
|
620 |
+
$count_all = (int) $r;
|
621 |
|
622 |
$args = array(
|
623 |
'meta_key' => 'ct_marked_as_spam',
|
635 |
}
|
636 |
}
|
637 |
|
638 |
+
die( $count_all );
|
639 |
}
|
640 |
|
641 |
/**
|
643 |
*
|
644 |
* @param $columns
|
645 |
* @return mixed
|
646 |
+
*
|
647 |
+
* @psalm-suppress PossiblyUnusedMethod
|
648 |
*/
|
649 |
public static function ct_manage_users_columns( $columns ) {
|
650 |
|
@@ -2,18 +2,24 @@
|
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\Firewall;
|
4 |
|
5 |
-
use Cleantalk\Common\Helper
|
6 |
-
use Cleantalk\Variables\Cookie;
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
10 |
|
11 |
public $module_name = 'ANTICRAWLER';
|
12 |
|
13 |
-
private $db__table__ac_logs
|
14 |
-
private $db__table__ac_ua_bl
|
15 |
private $api_key = '';
|
16 |
-
private $apbct
|
17 |
private $store_interval = 60;
|
18 |
private $sign; //Signature - User-Agent + Protocol
|
19 |
private $ua_id = 'null'; //User-Agent
|
@@ -21,6 +27,11 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
21 |
private $ac_log_result = '';
|
22 |
|
23 |
public $isExcluded = false;
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
/**
|
26 |
* AntiBot constructor.
|
@@ -46,102 +57,74 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
46 |
|
47 |
}
|
48 |
|
49 |
-
public static function update( $
|
50 |
-
|
51 |
-
$lines = \Cleantalk\ApbctWP\Helper::http__get_data_from_remote_gz__and_parse_csv( $file_url_ua );
|
52 |
-
|
53 |
-
if( empty( $lines['errors'] ) ){
|
54 |
-
|
55 |
-
$result__clear_db = self::clear_data_table( \Cleantalk\ApbctWP\DB::getInstance(), APBCT_TBL_AC_UA_BL );
|
56 |
-
|
57 |
-
if( empty( $result__clear_db['error'] ) ){
|
58 |
-
|
59 |
-
for( $count_result = 0; current($lines) !== false; ) {
|
60 |
-
|
61 |
-
$query = "INSERT INTO " . APBCT_TBL_AC_UA_BL . " (id, ua_template, ua_status) VALUES ";
|
62 |
|
63 |
-
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
continue;
|
69 |
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
continue;
|
74 |
-
}
|
75 |
|
76 |
-
|
77 |
-
$ua_id = preg_replace('/[^\d]*/', '', $entry[0]);
|
78 |
-
$ua_template = isset($entry[1]) && apbct_is_regexp($entry[1]) ? Helper::db__prepare_param( $entry[1] ) : 0;
|
79 |
-
$ua_status = isset($entry[2]) ? $entry[2] : 0;
|
80 |
|
81 |
-
|
82 |
-
continue;
|
83 |
-
}
|
84 |
-
}
|
85 |
-
|
86 |
-
$values[] = '('. $ua_id .','. $ua_template .','. $ua_status .')';
|
87 |
|
88 |
-
|
89 |
|
90 |
-
|
91 |
-
$query = $query . implode( ',', $values ) . ';';
|
92 |
-
\Cleantalk\ApbctWP\DB::getInstance()->execute( $query );
|
93 |
-
}
|
94 |
|
95 |
-
|
96 |
-
return $count_result;
|
97 |
-
}else
|
98 |
-
return $result__clear_db;
|
99 |
-
}else
|
100 |
-
return array('error' => 'UAL_UPDATE_ERROR: '. $lines['error'] );
|
101 |
-
}
|
102 |
|
103 |
-
|
104 |
|
105 |
-
|
106 |
|
107 |
-
|
|
|
|
|
108 |
|
109 |
-
|
|
|
|
|
|
|
110 |
|
111 |
-
|
|
|
|
|
112 |
|
113 |
-
|
114 |
|
115 |
-
|
116 |
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
$values[] = '('. $ua_id .','. $ua_template .','. $ua_status .')';
|
131 |
-
|
132 |
-
}
|
133 |
-
|
134 |
-
if( ! empty( $values ) ){
|
135 |
-
$query = $query . implode( ',', $values ) . ';';
|
136 |
-
\Cleantalk\ApbctWP\DB::getInstance()->execute( $query );
|
137 |
-
}
|
138 |
-
|
139 |
-
}
|
140 |
-
return $count_result;
|
141 |
-
}else
|
142 |
-
return $result__clear_db;
|
143 |
-
|
144 |
-
}
|
145 |
|
146 |
private static function clear_data_table($db, $db__table__data) {
|
147 |
|
@@ -167,7 +150,7 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
167 |
|
168 |
$results = array();
|
169 |
|
170 |
-
foreach( $this->ip_array as $
|
171 |
|
172 |
// Skip by 301 response code
|
173 |
if( $this->is_redirected() ){
|
@@ -194,7 +177,6 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
194 |
// Whitelisted
|
195 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTICRAWLER_UA',);
|
196 |
return $results;
|
197 |
-
break;
|
198 |
} else {
|
199 |
// Blacklisted
|
200 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTICRAWLER_UA',);
|
@@ -215,8 +197,9 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
215 |
// Skip by cookie
|
216 |
if( Cookie::get('wordpress_apbct_antibot') == hash( 'sha256', $this->api_key . $this->apbct->data['salt'] ) ) {
|
217 |
if( Cookie::get( 'apbct_anticrawler_passed' ) == 1 ){
|
218 |
-
if( ! headers_sent() )
|
219 |
-
|
|
|
220 |
|
221 |
// Do logging an one passed request
|
222 |
$this->update_log( $current_ip, 'PASS_ANTICRAWLER' );
|
@@ -230,7 +213,7 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
230 |
}
|
231 |
|
232 |
// Common check
|
233 |
-
foreach( $this->ip_array as $
|
234 |
|
235 |
// IP check
|
236 |
$result = $this->db->fetch(
|
@@ -249,8 +232,9 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
249 |
|
250 |
if( Cookie::get( 'apbct_anticrawler_passed' ) === '1' ){
|
251 |
|
252 |
-
if( ! headers_sent() )
|
253 |
-
\Cleantalk\ApbctWP\Variables\Cookie::set( 'apbct_anticrawler_passed', '0', time() - 86400, '/',
|
|
|
254 |
|
255 |
$results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTICRAWLER', );
|
256 |
|
@@ -278,9 +262,7 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
278 |
public function update_ac_log() {
|
279 |
$interval_time = Helper::time__get_interval_start( $this->store_interval );
|
280 |
|
281 |
-
|
282 |
-
|
283 |
-
foreach( $this->ip_array as $ip_origin => $current_ip ){
|
284 |
$id = md5( $current_ip . $this->sign . $interval_time );
|
285 |
$this->db->execute(
|
286 |
"INSERT INTO " . $this->db__table__ac_logs . " SET
|
@@ -301,7 +283,13 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
301 |
|
302 |
public static function set_cookie(){
|
303 |
global $apbct;
|
304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
}
|
306 |
|
307 |
/**
|
@@ -313,6 +301,8 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
313 |
*/
|
314 |
public function update_log( $ip, $status ) {
|
315 |
|
|
|
|
|
316 |
if( strpos( '_UA', $status ) !== false ) {
|
317 |
$id_str = $ip . $this->module_name . '_UA';
|
318 |
} else {
|
@@ -328,7 +318,7 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
328 |
status = '$status',
|
329 |
all_entries = 1,
|
330 |
blocked_entries = " . ( strpos( $status, 'DENY' ) !== false ? 1 : 0 ) . ",
|
331 |
-
entries_timestamp = '" .
|
332 |
ua_id = " . $this->ua_id . ",
|
333 |
ua_name = %s,
|
334 |
first_url = %s,
|
@@ -338,7 +328,7 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
338 |
status = '$status',
|
339 |
all_entries = all_entries + 1,
|
340 |
blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
|
341 |
-
entries_timestamp = '" .
|
342 |
ua_id = " . $this->ua_id . ",
|
343 |
ua_name = %s,
|
344 |
last_url = %s";
|
@@ -364,7 +354,9 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
364 |
// File exists?
|
365 |
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_anticrawler.html")){
|
366 |
|
367 |
-
$sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_anticrawler.html");
|
|
|
|
|
368 |
|
369 |
$net_count = $apbct->stats['sfw']['entries'];
|
370 |
|
@@ -380,10 +372,11 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
380 |
'{COOKIE_ANTICRAWLER}' => hash( 'sha256', $apbct->api_key . $apbct->data['salt'] ),
|
381 |
'{COOKIE_ANTICRAWLER_PASSED}' => '1',
|
382 |
'{GENERATED}' => '<p>The page was generated at ' . date( 'D, d M Y H:i:s' ) . "</p>",
|
|
|
383 |
);
|
384 |
|
385 |
foreach( $replaces as $place_holder => $replace ){
|
386 |
-
$sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
|
387 |
}
|
388 |
|
389 |
if( isset( $_GET['debug'] ) ){
|
@@ -398,18 +391,51 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
398 |
}else{
|
399 |
$debug = '';
|
400 |
}
|
401 |
-
$sfw_die_page = str_replace( "{DEBUG}", $debug, $sfw_die_page );
|
402 |
|
403 |
-
http_response_code(403);
|
404 |
-
die($sfw_die_page);
|
405 |
|
406 |
-
}else{
|
407 |
-
http_response_code(403);
|
408 |
-
die("IP BLACKLISTED. Blocked by AntiCrawler " . $result['ip']);
|
409 |
}
|
|
|
|
|
410 |
|
411 |
}
|
412 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
413 |
private function check_exclusions() {
|
414 |
|
415 |
$allowed_roles = array( 'administrator', 'editor' );
|
@@ -445,4 +471,4 @@ class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
445 |
{
|
446 |
return Server::get('HTTP_CF_RAY') && Server::get('HTTP_CF_CONNECTING_IP') && Server::get('HTTP_CF_REQUEST_ID');
|
447 |
}
|
448 |
-
}
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\Firewall;
|
4 |
|
5 |
+
use Cleantalk\Common\Helper;
|
6 |
+
use Cleantalk\ApbctWP\Variables\Cookie;
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
9 |
+
/**
|
10 |
+
* Class AntiCrawler
|
11 |
+
* @package Cleantalk\ApbctWP\Firewall
|
12 |
+
*
|
13 |
+
* @psalm-suppress PossiblyUnusedProperty
|
14 |
+
*/
|
15 |
class AntiCrawler extends \Cleantalk\Common\Firewall\FirewallModule{
|
16 |
|
17 |
public $module_name = 'ANTICRAWLER';
|
18 |
|
19 |
+
private $db__table__ac_logs;
|
20 |
+
private $db__table__ac_ua_bl;
|
21 |
private $api_key = '';
|
22 |
+
private $apbct;
|
23 |
private $store_interval = 60;
|
24 |
private $sign; //Signature - User-Agent + Protocol
|
25 |
private $ua_id = 'null'; //User-Agent
|
27 |
private $ac_log_result = '';
|
28 |
|
29 |
public $isExcluded = false;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* @var string Content of the die page
|
33 |
+
*/
|
34 |
+
private $sfw_die_page;
|
35 |
|
36 |
/**
|
37 |
* AntiBot constructor.
|
57 |
|
58 |
}
|
59 |
|
60 |
+
public static function update( $file_path_ua ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
$file_content = file_get_contents( $file_path_ua );
|
63 |
|
64 |
+
if(function_exists('gzdecode')) {
|
65 |
|
66 |
+
$unzipped_content = gzdecode( $file_content );
|
|
|
67 |
|
68 |
+
if ( $unzipped_content !== false ) {
|
69 |
|
70 |
+
$lines = \Cleantalk\ApbctWP\Helper::buffer__parse__csv( $unzipped_content );
|
|
|
|
|
71 |
|
72 |
+
if( empty( $lines['errors'] ) ){
|
|
|
|
|
|
|
73 |
|
74 |
+
$result__clear_db = self::clear_data_table( \Cleantalk\ApbctWP\DB::getInstance(), APBCT_TBL_AC_UA_BL );
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
if( empty( $result__clear_db['error'] ) ){
|
77 |
|
78 |
+
for( $count_result = 0; current($lines) !== false; ) {
|
|
|
|
|
|
|
79 |
|
80 |
+
$query = "INSERT INTO " . APBCT_TBL_AC_UA_BL . " (id, ua_template, ua_status) VALUES ";
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
+
for( $i = 0, $values = array(); APBCT_WRITE_LIMIT !== $i && current( $lines ) !== false; $i ++, $count_result ++, next( $lines ) ){
|
83 |
|
84 |
+
$entry = current($lines);
|
85 |
|
86 |
+
if( empty($entry) || ! isset( $entry[0], $entry[1] ) ) {
|
87 |
+
continue;
|
88 |
+
}
|
89 |
|
90 |
+
// Cast result to int
|
91 |
+
$ua_id = preg_replace('/[^\d]*/', '', $entry[0]);
|
92 |
+
$ua_template = isset($entry[1]) && apbct_is_regexp($entry[1]) ? Helper::db__prepare_param( $entry[1] ) : 0;
|
93 |
+
$ua_status = isset($entry[2]) ? $entry[2] : 0;
|
94 |
|
95 |
+
if( ! $ua_id || ! $ua_template ){
|
96 |
+
continue;
|
97 |
+
}
|
98 |
|
99 |
+
$values[] = '('. $ua_id .','. $ua_template .','. $ua_status .')';
|
100 |
|
101 |
+
}
|
102 |
|
103 |
+
if( ! empty( $values ) ){
|
104 |
+
$query = $query . implode( ',', $values ) . ';';
|
105 |
+
\Cleantalk\ApbctWP\DB::getInstance()->execute( $query );
|
106 |
+
if( file_exists( $file_path_ua ) ) {
|
107 |
+
unlink($file_path_ua);
|
108 |
+
}
|
109 |
+
}
|
110 |
|
111 |
+
}
|
112 |
+
return $count_result;
|
113 |
+
}else {
|
114 |
+
return $result__clear_db;
|
115 |
+
}
|
116 |
+
}else {
|
117 |
+
return array( 'error' => 'UAL_UPDATE_ERROR: ' . $lines['error'] );
|
118 |
+
}
|
119 |
|
120 |
+
} else {
|
121 |
+
return array( 'error' => 'Can not unpack datafile');
|
122 |
+
}
|
123 |
+
} else {
|
124 |
+
return array( 'error' => 'Function gzdecode not exists. Please update your PHP at least to version 5.4 ' );
|
125 |
+
}
|
126 |
|
127 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
private static function clear_data_table($db, $db__table__data) {
|
130 |
|
150 |
|
151 |
$results = array();
|
152 |
|
153 |
+
foreach( $this->ip_array as $_ip_origin => $current_ip ) {
|
154 |
|
155 |
// Skip by 301 response code
|
156 |
if( $this->is_redirected() ){
|
177 |
// Whitelisted
|
178 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTICRAWLER_UA',);
|
179 |
return $results;
|
|
|
180 |
} else {
|
181 |
// Blacklisted
|
182 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'DENY_ANTICRAWLER_UA',);
|
197 |
// Skip by cookie
|
198 |
if( Cookie::get('wordpress_apbct_antibot') == hash( 'sha256', $this->api_key . $this->apbct->data['salt'] ) ) {
|
199 |
if( Cookie::get( 'apbct_anticrawler_passed' ) == 1 ){
|
200 |
+
if( ! headers_sent() ) {
|
201 |
+
Cookie::set( 'apbct_anticrawler_passed', '0', time() - 86400, '/', '', null, true, 'Lax' );
|
202 |
+
}
|
203 |
|
204 |
// Do logging an one passed request
|
205 |
$this->update_log( $current_ip, 'PASS_ANTICRAWLER' );
|
213 |
}
|
214 |
|
215 |
// Common check
|
216 |
+
foreach( $this->ip_array as $_ip_origin => $current_ip ){
|
217 |
|
218 |
// IP check
|
219 |
$result = $this->db->fetch(
|
232 |
|
233 |
if( Cookie::get( 'apbct_anticrawler_passed' ) === '1' ){
|
234 |
|
235 |
+
if( ! headers_sent() ) {
|
236 |
+
\Cleantalk\ApbctWP\Variables\Cookie::set( 'apbct_anticrawler_passed', '0', time() - 86400, '/', '', false, true, 'Lax' );
|
237 |
+
}
|
238 |
|
239 |
$results[] = array( 'ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTICRAWLER', );
|
240 |
|
262 |
public function update_ac_log() {
|
263 |
$interval_time = Helper::time__get_interval_start( $this->store_interval );
|
264 |
|
265 |
+
foreach( $this->ip_array as $_ip_origin => $current_ip ){
|
|
|
|
|
266 |
$id = md5( $current_ip . $this->sign . $interval_time );
|
267 |
$this->db->execute(
|
268 |
"INSERT INTO " . $this->db__table__ac_logs . " SET
|
283 |
|
284 |
public static function set_cookie(){
|
285 |
global $apbct;
|
286 |
+
|
287 |
+
if( $apbct->settings['data__set_cookies'] == 0 && ! is_admin() ){
|
288 |
+
return;
|
289 |
+
}
|
290 |
+
|
291 |
+
echo '<script>ctSetCookie( "wordpress_apbct_antibot", "' . hash( 'sha256', $apbct->api_key . $apbct->data['salt'] ) . '", 0 );</script>';
|
292 |
+
|
293 |
}
|
294 |
|
295 |
/**
|
301 |
*/
|
302 |
public function update_log( $ip, $status ) {
|
303 |
|
304 |
+
/** @psalm-suppress InvalidLiteralArgument */
|
305 |
+
|
306 |
if( strpos( '_UA', $status ) !== false ) {
|
307 |
$id_str = $ip . $this->module_name . '_UA';
|
308 |
} else {
|
318 |
status = '$status',
|
319 |
all_entries = 1,
|
320 |
blocked_entries = " . ( strpos( $status, 'DENY' ) !== false ? 1 : 0 ) . ",
|
321 |
+
entries_timestamp = '" . $time . "',
|
322 |
ua_id = " . $this->ua_id . ",
|
323 |
ua_name = %s,
|
324 |
first_url = %s,
|
328 |
status = '$status',
|
329 |
all_entries = all_entries + 1,
|
330 |
blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
|
331 |
+
entries_timestamp = '" . $time . "',
|
332 |
ua_id = " . $this->ua_id . ",
|
333 |
ua_name = %s,
|
334 |
last_url = %s";
|
354 |
// File exists?
|
355 |
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_anticrawler.html")){
|
356 |
|
357 |
+
$this->sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_anticrawler.html");
|
358 |
+
|
359 |
+
$js_url = APBCT_URL_PATH . '/js/apbct-public--functions.min.js?' . APBCT_VERSION;
|
360 |
|
361 |
$net_count = $apbct->stats['sfw']['entries'];
|
362 |
|
372 |
'{COOKIE_ANTICRAWLER}' => hash( 'sha256', $apbct->api_key . $apbct->data['salt'] ),
|
373 |
'{COOKIE_ANTICRAWLER_PASSED}' => '1',
|
374 |
'{GENERATED}' => '<p>The page was generated at ' . date( 'D, d M Y H:i:s' ) . "</p>",
|
375 |
+
'{SCRIPT_URL}' => $js_url
|
376 |
);
|
377 |
|
378 |
foreach( $replaces as $place_holder => $replace ){
|
379 |
+
$this->sfw_die_page = str_replace( $place_holder, $replace, $this->sfw_die_page );
|
380 |
}
|
381 |
|
382 |
if( isset( $_GET['debug'] ) ){
|
391 |
}else{
|
392 |
$debug = '';
|
393 |
}
|
394 |
+
$this->sfw_die_page = str_replace( "{DEBUG}", $debug, $this->sfw_die_page );
|
395 |
|
|
|
|
|
396 |
|
|
|
|
|
|
|
397 |
}
|
398 |
+
|
399 |
+
add_action( 'init', array( $this, 'print_die_page' ) );
|
400 |
|
401 |
}
|
402 |
|
403 |
+
public function print_die_page() {
|
404 |
+
|
405 |
+
global $apbct;
|
406 |
+
|
407 |
+
$localize_js = array(
|
408 |
+
'_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
|
409 |
+
'_rest_nonce' => wp_create_nonce('wp_rest'),
|
410 |
+
'_ajax_url' => admin_url('admin-ajax.php', 'relative'),
|
411 |
+
'_rest_url' => esc_url( get_rest_url() ),
|
412 |
+
'_apbct_ajax_url' => APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php',
|
413 |
+
'data__set_cookies' => $apbct->settings['data__set_cookies'],
|
414 |
+
'data__set_cookies__alt_sessions_type' => $apbct->settings['data__set_cookies__alt_sessions_type'],
|
415 |
+
);
|
416 |
+
|
417 |
+
$js_jquery_url = includes_url() . 'js/jquery/jquery.min.js';
|
418 |
+
|
419 |
+
$replaces = array(
|
420 |
+
'{JQUERY_SCRIPT_URL}'=> $js_jquery_url,
|
421 |
+
'{LOCALIZE_SCRIPT}' => 'var ctPublicFunctions = ' . json_encode( $localize_js ),
|
422 |
+
);
|
423 |
+
|
424 |
+
foreach( $replaces as $place_holder => $replace ){
|
425 |
+
$this->sfw_die_page = str_replace( $place_holder, $replace, $this->sfw_die_page );
|
426 |
+
}
|
427 |
+
|
428 |
+
http_response_code(403);
|
429 |
+
|
430 |
+
// File exists?
|
431 |
+
if(file_exists( CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html")){
|
432 |
+
die($this->sfw_die_page);
|
433 |
+
|
434 |
+
}
|
435 |
+
|
436 |
+
die("IP BLACKLISTED. Blocked by AntiCrawler " . $this->apbct->stats['last_sfw_block']['ip']);
|
437 |
+
}
|
438 |
+
|
439 |
private function check_exclusions() {
|
440 |
|
441 |
$allowed_roles = array( 'administrator', 'editor' );
|
471 |
{
|
472 |
return Server::get('HTTP_CF_RAY') && Server::get('HTTP_CF_CONNECTING_IP') && Server::get('HTTP_CF_REQUEST_ID');
|
473 |
}
|
474 |
+
}
|
@@ -2,10 +2,16 @@
|
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\Firewall;
|
4 |
|
5 |
-
use Cleantalk\Common\Helper
|
6 |
-
use Cleantalk\Variables\Cookie;
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
10 |
|
11 |
public $module_name = 'ANTIFLOOD';
|
@@ -17,11 +23,15 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
17 |
private $view_limit = 20;
|
18 |
private $apbct = array();
|
19 |
private $store_interval = 60;
|
20 |
-
private $block_period = 30;
|
21 |
private $chance_to_clean = 20;
|
22 |
|
23 |
public $isExcluded = false;
|
24 |
|
|
|
|
|
|
|
|
|
|
|
25 |
/**
|
26 |
* AntiCrawler constructor.
|
27 |
*
|
@@ -54,7 +64,7 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
54 |
|
55 |
$time = time() - $this->store_interval;
|
56 |
|
57 |
-
foreach( $this->ip_array as $
|
58 |
|
59 |
// UA check
|
60 |
$ua_bl_results = $this->db->fetch_all(
|
@@ -67,13 +77,10 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
67 |
|
68 |
if( ! empty( $ua_bl_result['ua_template'] ) && preg_match( "%". str_replace( '"', '', $ua_bl_result['ua_template'] ) ."%i", Server::get('HTTP_USER_AGENT') ) ) {
|
69 |
|
70 |
-
$this->ua_id = $ua_bl_result['id'];
|
71 |
-
|
72 |
if( $ua_bl_result['ua_status'] == 1 ) {
|
73 |
// Whitelisted
|
74 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTIFLOOD_UA',);
|
75 |
return $results;
|
76 |
-
break;
|
77 |
}
|
78 |
|
79 |
}
|
@@ -86,7 +93,7 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
86 |
if( Cookie::get( 'apbct_antiflood_passed' ) === md5( $current_ip . $this->api_key ) ){
|
87 |
|
88 |
if( ! headers_sent() ){
|
89 |
-
Cookie::set( 'apbct_antiflood_passed', '0', time() - 86400, '/',
|
90 |
}
|
91 |
|
92 |
// Do logging an one passed request
|
@@ -129,7 +136,7 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
129 |
|
130 |
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
131 |
|
132 |
-
foreach( $this->ip_array as $
|
133 |
$id = md5( $current_ip . $interval_time );
|
134 |
$this->db->execute(
|
135 |
"INSERT INTO " . $this->db__table__ac_logs . " SET
|
@@ -179,14 +186,14 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
179 |
status = '$status',
|
180 |
all_entries = 1,
|
181 |
blocked_entries = " . ( strpos( $status, 'DENY' ) !== false ? 1 : 0 ) . ",
|
182 |
-
entries_timestamp = '" .
|
183 |
ua_name = %s
|
184 |
ON DUPLICATE KEY
|
185 |
UPDATE
|
186 |
status = '$status',
|
187 |
all_entries = all_entries + 1,
|
188 |
blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
|
189 |
-
entries_timestamp = '" .
|
190 |
ua_name = %s";
|
191 |
|
192 |
$this->db->prepare( $query, array( Server::get('HTTP_USER_AGENT'), Server::get('HTTP_USER_AGENT') ) );
|
@@ -202,7 +209,9 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
202 |
// File exists?
|
203 |
if( file_exists( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page_antiflood.html' ) ){
|
204 |
|
205 |
-
$sfw_die_page = file_get_contents( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page_antiflood.html' );
|
|
|
|
|
206 |
|
207 |
$net_count = $apbct->stats['sfw']['entries'];
|
208 |
|
@@ -218,22 +227,55 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
218 |
'{HOST}' => get_home_url() . ', ' . APBCT_VERSION,
|
219 |
'{GENERATED}' => '<p>The page was generated at ' . date( 'D, d M Y H:i:s' ) . "</p>",
|
220 |
'{COOKIE_ANTIFLOOD_PASSED}' => md5( $this->api_key . $result['ip'] ),
|
|
|
221 |
);
|
222 |
|
223 |
foreach( $replaces as $place_holder => $replace ){
|
224 |
-
$sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
|
225 |
}
|
226 |
|
227 |
-
|
228 |
-
die($sfw_die_page);
|
229 |
|
230 |
-
} else{
|
231 |
-
http_response_code(403);
|
232 |
-
die("IP BLACKLISTED. Blocked by AntiFlood " . $result['ip']);
|
233 |
}
|
234 |
|
235 |
}
|
236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
private function check_exclusions() {
|
238 |
|
239 |
$allowed_roles = array( 'administrator', 'editor' );
|
@@ -252,4 +294,4 @@ class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
|
252 |
return false;
|
253 |
|
254 |
}
|
255 |
-
}
|
2 |
|
3 |
namespace Cleantalk\ApbctWP\Firewall;
|
4 |
|
5 |
+
use Cleantalk\Common\Helper;
|
6 |
+
use Cleantalk\ApbctWP\Variables\Cookie;
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
9 |
+
/**
|
10 |
+
* Class AntiFlood
|
11 |
+
* @package Cleantalk\ApbctWP\Firewall
|
12 |
+
*
|
13 |
+
* @psalm-suppress PossiblyUnusedProperty
|
14 |
+
*/
|
15 |
class AntiFlood extends \Cleantalk\Common\Firewall\FirewallModule{
|
16 |
|
17 |
public $module_name = 'ANTIFLOOD';
|
23 |
private $view_limit = 20;
|
24 |
private $apbct = array();
|
25 |
private $store_interval = 60;
|
|
|
26 |
private $chance_to_clean = 20;
|
27 |
|
28 |
public $isExcluded = false;
|
29 |
|
30 |
+
/**
|
31 |
+
* @var string Content of the die page
|
32 |
+
*/
|
33 |
+
private $sfw_die_page;
|
34 |
+
|
35 |
/**
|
36 |
* AntiCrawler constructor.
|
37 |
*
|
64 |
|
65 |
$time = time() - $this->store_interval;
|
66 |
|
67 |
+
foreach( $this->ip_array as $_ip_origin => $current_ip ){
|
68 |
|
69 |
// UA check
|
70 |
$ua_bl_results = $this->db->fetch_all(
|
77 |
|
78 |
if( ! empty( $ua_bl_result['ua_template'] ) && preg_match( "%". str_replace( '"', '', $ua_bl_result['ua_template'] ) ."%i", Server::get('HTTP_USER_AGENT') ) ) {
|
79 |
|
|
|
|
|
80 |
if( $ua_bl_result['ua_status'] == 1 ) {
|
81 |
// Whitelisted
|
82 |
$results[] = array('ip' => $current_ip, 'is_personal' => false, 'status' => 'PASS_ANTIFLOOD_UA',);
|
83 |
return $results;
|
|
|
84 |
}
|
85 |
|
86 |
}
|
93 |
if( Cookie::get( 'apbct_antiflood_passed' ) === md5( $current_ip . $this->api_key ) ){
|
94 |
|
95 |
if( ! headers_sent() ){
|
96 |
+
Cookie::set( 'apbct_antiflood_passed', '0', time() - 86400, '/', '', null, true );
|
97 |
}
|
98 |
|
99 |
// Do logging an one passed request
|
136 |
|
137 |
// @todo Rename ip column to sign. Use IP + UserAgent for it.
|
138 |
|
139 |
+
foreach( $this->ip_array as $_ip_origin => $current_ip ){
|
140 |
$id = md5( $current_ip . $interval_time );
|
141 |
$this->db->execute(
|
142 |
"INSERT INTO " . $this->db__table__ac_logs . " SET
|
186 |
status = '$status',
|
187 |
all_entries = 1,
|
188 |
blocked_entries = " . ( strpos( $status, 'DENY' ) !== false ? 1 : 0 ) . ",
|
189 |
+
entries_timestamp = '" . $time . "',
|
190 |
ua_name = %s
|
191 |
ON DUPLICATE KEY
|
192 |
UPDATE
|
193 |
status = '$status',
|
194 |
all_entries = all_entries + 1,
|
195 |
blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
|
196 |
+
entries_timestamp = '" . $time . "',
|
197 |
ua_name = %s";
|
198 |
|
199 |
$this->db->prepare( $query, array( Server::get('HTTP_USER_AGENT'), Server::get('HTTP_USER_AGENT') ) );
|
209 |
// File exists?
|
210 |
if( file_exists( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page_antiflood.html' ) ){
|
211 |
|
212 |
+
$this->sfw_die_page = file_get_contents( CLEANTALK_PLUGIN_DIR . 'lib/Cleantalk/ApbctWP/Firewall/die_page_antiflood.html' );
|
213 |
+
|
214 |
+
$js_url = APBCT_URL_PATH . '/js/apbct-public--functions.min.js?' . APBCT_VERSION;
|
215 |
|
216 |
$net_count = $apbct->stats['sfw']['entries'];
|
217 |
|
227 |
'{HOST}' => get_home_url() . ', ' . APBCT_VERSION,
|
228 |
'{GENERATED}' => '<p>The page was generated at ' . date( 'D, d M Y H:i:s' ) . "</p>",
|
229 |
'{COOKIE_ANTIFLOOD_PASSED}' => md5( $this->api_key . $result['ip'] ),
|
230 |
+
'{SCRIPT_URL}' => $js_url
|
231 |
);
|
232 |
|
233 |
foreach( $replaces as $place_holder => $replace ){
|
234 |
+
$this->sfw_die_page = str_replace( $place_holder, $replace, $this->sfw_die_page );
|
235 |
}
|
236 |
|
237 |
+
add_action( 'init', array( $this, 'print_die_page' ) );
|
|
|
238 |
|
|
|
|
|
|
|
239 |
}
|
240 |
|
241 |
}
|
242 |
|
243 |
+
public function print_die_page() {
|
244 |
+
|
245 |
+
global $apbct;
|
246 |
+
|
247 |
+
$localize_js = array(
|
248 |
+
'_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
|
249 |
+
'_rest_nonce' => wp_create_nonce('wp_rest'),
|
250 |
+
'_ajax_url' => admin_url('admin-ajax.php', 'relative'),
|
251 |
+
'_rest_url' => esc_url( get_rest_url() ),
|
252 |
+
'_apbct_ajax_url' => APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php',
|
253 |
+
'data__set_cookies' => $apbct->settings['data__set_cookies'],
|
254 |
+
'data__set_cookies__alt_sessions_type' => $apbct->settings['data__set_cookies__alt_sessions_type'],
|
255 |
+
);
|
256 |
+
|
257 |
+
$js_jquery_url = includes_url() . 'js/jquery/jquery.min.js';
|
258 |
+
|
259 |
+
$replaces = array(
|
260 |
+
'{JQUERY_SCRIPT_URL}'=> $js_jquery_url,
|
261 |
+
'{LOCALIZE_SCRIPT}' => 'var ctPublicFunctions = ' . json_encode( $localize_js ),
|
262 |
+
);
|
263 |
+
|
264 |
+
foreach( $replaces as $place_holder => $replace ){
|
265 |
+
$this->sfw_die_page = str_replace( $place_holder, $replace, $this->sfw_die_page );
|
266 |
+
}
|
267 |
+
|
268 |
+
http_response_code(403);
|
269 |
+
|
270 |
+
// File exists?
|
271 |
+
if(file_exists( CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html")){
|
272 |
+
die($this->sfw_die_page);
|
273 |
+
|
274 |
+
}
|
275 |
+
|
276 |
+
die("IP BLACKLISTED. Blocked by AntiFlood " . $this->apbct->stats['last_sfw_block']['ip']);
|
277 |
+
}
|
278 |
+
|
279 |
private function check_exclusions() {
|
280 |
|
281 |
$allowed_roles = array( 'administrator', 'editor' );
|
294 |
return false;
|
295 |
|
296 |
}
|
297 |
+
}
|
@@ -5,7 +5,7 @@ namespace Cleantalk\ApbctWP\Firewall;
|
|
5 |
use Cleantalk\ApbctWP\API;
|
6 |
use Cleantalk\ApbctWP\DB;
|
7 |
use Cleantalk\ApbctWP\Helper;
|
8 |
-
use Cleantalk\Variables\Cookie;
|
9 |
use Cleantalk\Variables\Get;
|
10 |
use Cleantalk\Variables\Server;
|
11 |
|
@@ -28,7 +28,12 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
28 |
private $real_ip;
|
29 |
private $debug;
|
30 |
private $debug_data = '';
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
/**
|
33 |
* FireWall_module constructor.
|
34 |
* Use this method to prepare any data for the module working.
|
@@ -86,15 +91,14 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
86 |
if( Cookie::get( 'ct_sfw_passed' ) ){
|
87 |
|
88 |
if( ! headers_sent() ){
|
89 |
-
|
90 |
'ct_sfw_passed',
|
91 |
'0',
|
92 |
time() + 86400 * 3,
|
93 |
'/',
|
|
|
94 |
null,
|
95 |
-
|
96 |
-
true,
|
97 |
-
'Lax' );
|
98 |
} else {
|
99 |
$results[] = array(
|
100 |
'ip' => $current_ip,
|
@@ -130,7 +134,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
130 |
}
|
131 |
|
132 |
// Common check
|
133 |
-
foreach($this->ip_array as $
|
134 |
|
135 |
$current_ip_v4 = sprintf("%u", ip2long($current_ip));
|
136 |
for ( $needles = array(), $m = 6; $m <= 32; $m ++ ) {
|
@@ -213,7 +217,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
213 |
source = $source,
|
214 |
all_entries = all_entries + 1,
|
215 |
blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
|
216 |
-
entries_timestamp = '" .
|
217 |
ua_name = %s,
|
218 |
network = %s,
|
219 |
last_url = %s",
|
@@ -242,15 +246,13 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
242 |
|
243 |
public function actions_for_passed( $result ){
|
244 |
if( $this->data__set_cookies == 1 && ! headers_sent() ) {
|
245 |
-
$status = $result['status']
|
246 |
$cookie_val = md5( $result['ip'] . $this->api_key ) . $status;
|
247 |
-
|
248 |
'ct_sfw_pass_key',
|
249 |
$cookie_val,
|
250 |
time() + 86400 * 30,
|
251 |
-
'/'
|
252 |
-
null,
|
253 |
-
null );
|
254 |
}
|
255 |
}
|
256 |
|
@@ -276,12 +278,14 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
276 |
|
277 |
// File exists?
|
278 |
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html")){
|
279 |
-
|
280 |
-
$sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html");
|
|
|
|
|
281 |
|
282 |
$net_count = $apbct->stats['sfw']['entries'];
|
283 |
|
284 |
-
$status = $result['status']
|
285 |
$cookie_val = md5( $result['ip'] . $this->api_key ) . $status;
|
286 |
|
287 |
// Translation
|
@@ -309,6 +313,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
309 |
'{TEST_IP__HEADER}' => '',
|
310 |
'{TEST_IP}' => '',
|
311 |
'{REAL_IP}' => '',
|
|
|
312 |
);
|
313 |
|
314 |
// Test
|
@@ -336,30 +341,62 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
336 |
$replaces['{DEBUG}'] = isset( $debug ) ? $debug : '';
|
337 |
|
338 |
foreach( $replaces as $place_holder => $replace ){
|
339 |
-
$sfw_die_page = str_replace( $place_holder, $replace, $sfw_die_page );
|
340 |
}
|
341 |
|
342 |
-
http_response_code(403);
|
343 |
-
die($sfw_die_page);
|
344 |
-
|
345 |
-
}else{
|
346 |
-
http_response_code(403);
|
347 |
-
die("IP BLACKLISTED. Blocked by SFW " . $result['ip']);
|
348 |
}
|
|
|
|
|
349 |
|
350 |
}
|
351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
/**
|
353 |
* Sends and wipe SFW log
|
354 |
*
|
355 |
* @param $db
|
356 |
* @param $log_table
|
357 |
* @param string $ct_key API key
|
358 |
-
* @param bool $
|
359 |
*
|
360 |
* @return array|bool array('error' => STRING)
|
361 |
*/
|
362 |
-
public static function send_log( $db, $log_table, $ct_key, $
|
363 |
|
364 |
//Getting logs
|
365 |
$query = "SELECT * FROM $log_table ORDER BY entries_timestamp DESC LIMIT 0," . APBCT_SFW_SEND_LOGS_LIMIT .";";
|
@@ -372,7 +409,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
372 |
//Compile logs
|
373 |
$ids_to_delete = array();
|
374 |
$data = array();
|
375 |
-
foreach( $logs as $
|
376 |
|
377 |
$ids_to_delete[] = $value['id'];
|
378 |
|
@@ -417,7 +454,7 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
417 |
);
|
418 |
|
419 |
}
|
420 |
-
unset( $
|
421 |
|
422 |
//Sending the request
|
423 |
$result = API::method__sfw_logs( $ct_key, $data );
|
@@ -441,167 +478,83 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
441 |
return array( 'rows' => 0 );
|
442 |
}
|
443 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
|
445 |
-
|
446 |
-
* Gets multifile with data to update Firewall.
|
447 |
-
*
|
448 |
-
* @param string $api_key API key
|
449 |
-
*
|
450 |
-
* @return array
|
451 |
-
*/
|
452 |
-
public static function direct_update__get_db( $api_key ){
|
453 |
-
|
454 |
-
// Getting remote file name
|
455 |
-
$result = API::method__get_2s_blacklists_db( $api_key, null, '3_0' );
|
456 |
-
|
457 |
-
if( empty( $result['error'] ) ){
|
458 |
-
|
459 |
-
return array(
|
460 |
-
'blacklist' => $result['data'],
|
461 |
-
'useragents' => $result['data_user_agents'],
|
462 |
-
);
|
463 |
-
|
464 |
-
}else
|
465 |
-
return $result;
|
466 |
-
}
|
467 |
|
468 |
-
|
469 |
|
470 |
-
|
471 |
|
472 |
-
|
473 |
|
474 |
-
|
475 |
|
476 |
-
|
477 |
|
478 |
-
|
479 |
|
480 |
-
|
481 |
-
continue;
|
482 |
|
483 |
-
|
484 |
|
485 |
-
|
486 |
-
$ip = preg_replace('/[^\d]*/', '', $entry[0]);
|
487 |
-
$mask = preg_replace('/[^\d]*/', '', $entry[1]);
|
488 |
-
$private = isset($entry[2]) ? $entry[2] : 0;
|
489 |
|
490 |
-
|
491 |
|
492 |
-
|
|
|
|
|
493 |
|
494 |
-
|
|
|
|
|
|
|
|
|
495 |
|
496 |
-
|
497 |
-
$query .= implode( ',', $values ) . ';';
|
498 |
-
$db->execute( $query );
|
499 |
-
}
|
500 |
|
501 |
-
|
502 |
|
503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
|
505 |
-
|
506 |
-
|
507 |
-
/**
|
508 |
-
* Gets multifile with data to update Firewall.
|
509 |
-
*
|
510 |
-
* @param string $api_key API key
|
511 |
-
*
|
512 |
-
* @return array
|
513 |
-
*/
|
514 |
-
public static function update__get_multifile( $api_key ){
|
515 |
-
|
516 |
-
// Getting remote file name
|
517 |
-
$result = API::method__get_2s_blacklists_db( $api_key, 'multifiles', '3_1' );
|
518 |
|
519 |
-
|
520 |
-
|
521 |
-
if( empty( $result['file_url'] ) )
|
522 |
-
return array( 'error' => 'No file_url parameter provided.' );
|
523 |
-
if( empty( $result['file_ua_url'] ) )
|
524 |
-
return array( 'error' => 'No file_ua_url parameter provided.' );
|
525 |
-
if( empty( $result['file_ck_url'] ) )
|
526 |
-
return array( 'error' => 'No file_ck_url parameter provided.' );
|
527 |
-
|
528 |
-
$data = Helper::http__get_data_from_remote_gz__and_parse_csv( $result['file_url'] );
|
529 |
-
|
530 |
-
if( empty( $data['error'] ) ){
|
531 |
-
|
532 |
-
return array(
|
533 |
-
'multifile_url' => trim( $result['file_url'] ),
|
534 |
-
'useragent_url' => trim( $result['file_ua_url'] ),
|
535 |
-
'file_urls' => $data,
|
536 |
-
'file_ck_url' => trim( $result['file_ck_url'] ),
|
537 |
-
);
|
538 |
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
return $result;
|
543 |
-
}
|
544 |
-
|
545 |
-
/**
|
546 |
-
* Updates SFW local base
|
547 |
-
*
|
548 |
-
* @param $db
|
549 |
-
* @param $db__table__data
|
550 |
-
* @param null|string $file_url File URL with SFW data.
|
551 |
-
*
|
552 |
-
* @return array|bool array('error' => STRING)
|
553 |
-
*/
|
554 |
-
public static function update__write_to_db( $db, $db__table__data, $file_url = null ){
|
555 |
-
|
556 |
-
$data = Helper::http__get_data_from_remote_gz__and_parse_csv( $file_url );
|
557 |
-
|
558 |
-
if( empty( $data['errors'] ) ){
|
559 |
|
560 |
-
|
|
|
|
|
|
|
|
|
|
|
561 |
|
562 |
-
for( $count_result = 0; current($data) !== false; ) {
|
563 |
-
|
564 |
-
$query = "INSERT INTO ".$db__table__data." (network, mask, status, source) VALUES ";
|
565 |
-
|
566 |
-
for( $i = 0, $values = array(); APBCT_WRITE_LIMIT !== $i && current( $data ) !== false; $i ++, $count_result ++, next( $data ) ){
|
567 |
-
|
568 |
-
$entry = current($data);
|
569 |
-
|
570 |
-
if(empty($entry))
|
571 |
-
continue;
|
572 |
-
|
573 |
-
if ( APBCT_WRITE_LIMIT !== $i ) {
|
574 |
-
|
575 |
-
if( empty( $entry[0] ) || empty ($entry[1] ) ){
|
576 |
-
continue;
|
577 |
-
}
|
578 |
-
|
579 |
-
// Cast result to int
|
580 |
-
$ip = preg_replace( '/[^\d]*/', '', $entry[0] );
|
581 |
-
$mask = preg_replace( '/[^\d]*/', '', $entry[1] );
|
582 |
-
$status = isset( $entry[2] ) ? $entry[2] : 0;
|
583 |
-
$source = isset( $entry[3] ) ? (int) $entry[3] : 'NULL';
|
584 |
-
|
585 |
-
$values[] = "($ip, $mask, $status, $source)";
|
586 |
-
}
|
587 |
-
|
588 |
-
}
|
589 |
-
|
590 |
-
if( ! empty( $values ) ){
|
591 |
-
$query .= implode( ',', $values ) . ';';
|
592 |
-
$db->execute( $query );
|
593 |
-
}
|
594 |
-
|
595 |
-
}
|
596 |
-
|
597 |
-
return $count_result;
|
598 |
-
|
599 |
-
}else
|
600 |
-
return $data;
|
601 |
}
|
602 |
|
603 |
public static function update__write_to_db__exclusions( $db, $db__table__data, $exclusions = array() ) {
|
604 |
|
|
|
|
|
605 |
$query = 'INSERT INTO `' . $db__table__data . '` (network, mask, status) VALUES ';
|
606 |
|
607 |
//Exclusion for servers IP (SERVER_ADDR)
|
@@ -614,7 +567,6 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
614 |
|
615 |
// And delete all 127.0.0.1 entries for local hosts
|
616 |
}else{
|
617 |
-
global $wpdb, $apbct;
|
618 |
$wpdb->query( 'DELETE FROM ' . $db__table__data . ' WHERE network = ' . ip2long( '127.0.0.1' ) . ';' );
|
619 |
if( $wpdb->rows_affected > 0 ) {
|
620 |
$apbct->fw_stats['expected_networks_count'] -= $wpdb->rows_affected;
|
@@ -713,11 +665,13 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
713 |
|
714 |
$table_name__temp = $table_name . '_temp';
|
715 |
|
716 |
-
if( ! $db->isTableExists( $table_name__temp ) )
|
717 |
-
|
|
|
718 |
|
719 |
-
if( $db->isTableExists( $table_name ) )
|
720 |
-
|
|
|
721 |
|
722 |
$db->execute( 'ALTER TABLE `' . $table_name__temp . '` RENAME `' . $table_name . '`;' );
|
723 |
|
@@ -726,4 +680,4 @@ class SFW extends \Cleantalk\Common\Firewall\FirewallModule {
|
|
726 |
return true;
|
727 |
}
|
728 |
|
729 |
-
}
|
5 |
use Cleantalk\ApbctWP\API;
|
6 |
use Cleantalk\ApbctWP\DB;
|
7 |
use Cleantalk\ApbctWP\Helper;
|
8 |
+
use Cleantalk\ApbctWP\Variables\Cookie;
|
9 |
use Cleantalk\Variables\Get;
|
10 |
use Cleantalk\Variables\Server;
|
11 |
|
28 |
private $real_ip;
|
29 |
private $debug;
|
30 |
private $debug_data = '';
|
31 |
+
|
32 |
+
/**
|
33 |
+
* @var string Content of the die page
|
34 |
+
*/
|
35 |
+
private $sfw_die_page;
|
36 |
+
|
37 |
/**
|
38 |
* FireWall_module constructor.
|
39 |
* Use this method to prepare any data for the module working.
|
91 |
if( Cookie::get( 'ct_sfw_passed' ) ){
|
92 |
|
93 |
if( ! headers_sent() ){
|
94 |
+
Cookie::set(
|
95 |
'ct_sfw_passed',
|
96 |
'0',
|
97 |
time() + 86400 * 3,
|
98 |
'/',
|
99 |
+
'',
|
100 |
null,
|
101 |
+
true );
|
|
|
|
|
102 |
} else {
|
103 |
$results[] = array(
|
104 |
'ip' => $current_ip,
|
134 |
}
|
135 |
|
136 |
// Common check
|
137 |
+
foreach($this->ip_array as $_origin => $current_ip){
|
138 |
|
139 |
$current_ip_v4 = sprintf("%u", ip2long($current_ip));
|
140 |
for ( $needles = array(), $m = 6; $m <= 32; $m ++ ) {
|
217 |
source = $source,
|
218 |
all_entries = all_entries + 1,
|
219 |
blocked_entries = blocked_entries" . ( strpos( $status, 'DENY' ) !== false ? ' + 1' : '' ) . ",
|
220 |
+
entries_timestamp = '" . $time . "',
|
221 |
ua_name = %s,
|
222 |
network = %s,
|
223 |
last_url = %s",
|
246 |
|
247 |
public function actions_for_passed( $result ){
|
248 |
if( $this->data__set_cookies == 1 && ! headers_sent() ) {
|
249 |
+
$status = $result['status'] === 'PASS_SFW__BY_WHITELIST' ? '1' : '0';
|
250 |
$cookie_val = md5( $result['ip'] . $this->api_key ) . $status;
|
251 |
+
Cookie::setNativeCookie(
|
252 |
'ct_sfw_pass_key',
|
253 |
$cookie_val,
|
254 |
time() + 86400 * 30,
|
255 |
+
'/' );
|
|
|
|
|
256 |
}
|
257 |
}
|
258 |
|
278 |
|
279 |
// File exists?
|
280 |
if(file_exists(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html")){
|
281 |
+
|
282 |
+
$this->sfw_die_page = file_get_contents(CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html");
|
283 |
+
|
284 |
+
$js_url = APBCT_URL_PATH . '/js/apbct-public--functions.min.js?' . APBCT_VERSION;
|
285 |
|
286 |
$net_count = $apbct->stats['sfw']['entries'];
|
287 |
|
288 |
+
$status = $result['status'] === 'PASS_SFW__BY_WHITELIST' ? '1' : '0';
|
289 |
$cookie_val = md5( $result['ip'] . $this->api_key ) . $status;
|
290 |
|
291 |
// Translation
|
313 |
'{TEST_IP__HEADER}' => '',
|
314 |
'{TEST_IP}' => '',
|
315 |
'{REAL_IP}' => '',
|
316 |
+
'{SCRIPT_URL}' => $js_url
|
317 |
);
|
318 |
|
319 |
// Test
|
341 |
$replaces['{DEBUG}'] = isset( $debug ) ? $debug : '';
|
342 |
|
343 |
foreach( $replaces as $place_holder => $replace ){
|
344 |
+
$this->sfw_die_page = str_replace( $place_holder, $replace, $this->sfw_die_page );
|
345 |
}
|
346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
}
|
348 |
+
|
349 |
+
add_action( 'init', array( $this, 'print_die_page' ) );
|
350 |
|
351 |
}
|
352 |
+
|
353 |
+
public function print_die_page() {
|
354 |
+
|
355 |
+
global $apbct;
|
356 |
+
|
357 |
+
$localize_js = array(
|
358 |
+
'_ajax_nonce' => wp_create_nonce('ct_secret_stuff'),
|
359 |
+
'_rest_nonce' => wp_create_nonce('wp_rest'),
|
360 |
+
'_ajax_url' => admin_url('admin-ajax.php', 'relative'),
|
361 |
+
'_rest_url' => esc_url( get_rest_url() ),
|
362 |
+
'_apbct_ajax_url' => APBCT_URL_PATH . '/lib/Cleantalk/ApbctWP/Ajax.php',
|
363 |
+
'data__set_cookies' => $apbct->settings['data__set_cookies'],
|
364 |
+
'data__set_cookies__alt_sessions_type' => $apbct->settings['data__set_cookies__alt_sessions_type'],
|
365 |
+
);
|
366 |
+
|
367 |
+
$js_jquery_url = includes_url() . 'js/jquery/jquery.min.js';
|
368 |
+
|
369 |
+
$replaces = array(
|
370 |
+
'{JQUERY_SCRIPT_URL}'=> $js_jquery_url,
|
371 |
+
'{LOCALIZE_SCRIPT}' => 'var ctPublicFunctions = ' . json_encode( $localize_js ),
|
372 |
+
);
|
373 |
+
|
374 |
+
foreach( $replaces as $place_holder => $replace ){
|
375 |
+
$this->sfw_die_page = str_replace( $place_holder, $replace, $this->sfw_die_page );
|
376 |
+
}
|
377 |
+
|
378 |
+
http_response_code(403);
|
379 |
+
|
380 |
+
// File exists?
|
381 |
+
if(file_exists( CLEANTALK_PLUGIN_DIR . "lib/Cleantalk/ApbctWP/Firewall/die_page_sfw.html")){
|
382 |
+
die($this->sfw_die_page);
|
383 |
+
|
384 |
+
}
|
385 |
+
|
386 |
+
die("IP BLACKLISTED. Blocked by SFW " . $this->apbct->stats['last_sfw_block']['ip']);
|
387 |
+
}
|
388 |
+
|
389 |
/**
|
390 |
* Sends and wipe SFW log
|
391 |
*
|
392 |
* @param $db
|
393 |
* @param $log_table
|
394 |
* @param string $ct_key API key
|
395 |
+
* @param bool $_use_delete_command Determs whether use DELETE or TRUNCATE to delete the logs table data
|
396 |
*
|
397 |
* @return array|bool array('error' => STRING)
|
398 |
*/
|
399 |
+
public static function send_log( $db, $log_table, $ct_key, $_use_delete_command ) {
|
400 |
|
401 |
//Getting logs
|
402 |
$query = "SELECT * FROM $log_table ORDER BY entries_timestamp DESC LIMIT 0," . APBCT_SFW_SEND_LOGS_LIMIT .";";
|
409 |
//Compile logs
|
410 |
$ids_to_delete = array();
|
411 |
$data = array();
|
412 |
+
foreach( $logs as $_key => &$value ){
|
413 |
|
414 |
$ids_to_delete[] = $value['id'];
|
415 |
|
454 |
);
|
455 |
|
456 |
}
|
457 |
+
unset( $value );
|
458 |
|
459 |
//Sending the request
|
460 |
$result = API::method__sfw_logs( $ct_key, $data );
|
478 |
return array( 'rows' => 0 );
|
479 |
}
|
480 |
}
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Updates SFW local base
|
484 |
+
*
|
485 |
+
* @param $db
|
486 |
+
* @param $db__table__data
|
487 |
+
* @param null|string $file_url File URL with SFW data.
|
488 |
+
*
|
489 |
+
* @return array|int array('error' => STRING)
|
490 |
+
*/
|
491 |
+
public static function update__write_to_db( $db, $db__table__data, $file_url = null ){
|
492 |
|
493 |
+
$file_content = file_get_contents( $file_url );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
|
495 |
+
if(function_exists('gzdecode')) {
|
496 |
|
497 |
+
$unzipped_content = gzdecode( $file_content );
|
498 |
|
499 |
+
if ( $unzipped_content !== false ) {
|
500 |
|
501 |
+
$data = Helper::buffer__parse__csv( $unzipped_content );
|
502 |
|
503 |
+
if( empty( $data['errors'] ) ){
|
504 |
|
505 |
+
reset($data);
|
506 |
|
507 |
+
for( $count_result = 0; current($data) !== false; ) {
|
|
|
508 |
|
509 |
+
$query = "INSERT INTO ".$db__table__data." (network, mask, status, source) VALUES ";
|
510 |
|
511 |
+
for( $i = 0, $values = array(); APBCT_WRITE_LIMIT !== $i && current( $data ) !== false; $i ++, $count_result ++, next( $data ) ){
|
|
|
|
|
|
|
512 |
|
513 |
+
$entry = current($data);
|
514 |
|
515 |
+
if( empty( $entry ) || empty( $entry[0] ) || empty ($entry[1] ) ) {
|
516 |
+
continue;
|
517 |
+
}
|
518 |
|
519 |
+
// Cast result to int
|
520 |
+
$ip = preg_replace( '/[^\d]*/', '', $entry[0] );
|
521 |
+
$mask = preg_replace( '/[^\d]*/', '', $entry[1] );
|
522 |
+
$status = isset( $entry[2] ) ? $entry[2] : 0;
|
523 |
+
$source = isset( $entry[3] ) ? (int) $entry[3] : 'NULL';
|
524 |
|
525 |
+
$values[] = "($ip, $mask, $status, $source)";
|
|
|
|
|
|
|
526 |
|
527 |
+
}
|
528 |
|
529 |
+
if( ! empty( $values ) ){
|
530 |
+
$query .= implode( ',', $values ) . ';';
|
531 |
+
$db->execute( $query );
|
532 |
+
if( file_exists( $file_url ) ) {
|
533 |
+
unlink($file_url);
|
534 |
+
}
|
535 |
+
}
|
536 |
|
537 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
|
539 |
+
return $count_result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
540 |
|
541 |
+
}else {
|
542 |
+
return $data;
|
543 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
|
545 |
+
} else {
|
546 |
+
return array( 'error' => 'Can not unpack datafile');
|
547 |
+
}
|
548 |
+
} else {
|
549 |
+
return array( 'error' => 'Function gzdecode not exists. Please update your PHP at least to version 5.4 ');
|
550 |
+
}
|
551 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
552 |
}
|
553 |
|
554 |
public static function update__write_to_db__exclusions( $db, $db__table__data, $exclusions = array() ) {
|
555 |
|
556 |
+
global $wpdb, $apbct;
|
557 |
+
|
558 |
$query = 'INSERT INTO `' . $db__table__data . '` (network, mask, status) VALUES ';
|
559 |
|
560 |
//Exclusion for servers IP (SERVER_ADDR)
|
567 |
|
568 |
// And delete all 127.0.0.1 entries for local hosts
|
569 |
}else{
|
|
|
570 |
$wpdb->query( 'DELETE FROM ' . $db__table__data . ' WHERE network = ' . ip2long( '127.0.0.1' ) . ';' );
|
571 |
if( $wpdb->rows_affected > 0 ) {
|
572 |
$apbct->fw_stats['expected_networks_count'] -= $wpdb->rows_affected;
|
665 |
|
666 |
$table_name__temp = $table_name . '_temp';
|
667 |
|
668 |
+
if( ! $db->isTableExists( $table_name__temp ) ) {
|
669 |
+
return array( 'error' => 'RENAME TABLE: TEMPORARY TABLE IS NOT EXISTS: ' . $table_name__temp );
|
670 |
+
}
|
671 |
|
672 |
+
if( $db->isTableExists( $table_name ) ) {
|
673 |
+
return array( 'error' => 'RENAME TABLE: MAIN TABLE IS STILL EXISTS: ' . $table_name );
|
674 |
+
}
|
675 |
|
676 |
$db->execute( 'ALTER TABLE `' . $table_name__temp . '` RENAME `' . $table_name . '`;' );
|
677 |
|
680 |
return true;
|
681 |
}
|
682 |
|
683 |
+
}
|
@@ -177,15 +177,18 @@
|
|
177 |
box-shadow: none;
|
178 |
}
|
179 |
</style>
|
|
|
|
|
|
|
|
|
|
|
180 |
<script>
|
181 |
var ct_date = new Date;
|
182 |
|
183 |
function set_spamFireWallCookie(cookie_name, cookie_value) {
|
184 |
var date = new Date;
|
185 |
date.setDate(date.getDate() + 30);
|
186 |
-
|
187 |
-
document.cookie = cookie_name + '=' + escape(cookie_value) + '; path=/; expires=' + date.toUTCString() + '; samesite=lax' + ctSecure;
|
188 |
-
return null;
|
189 |
}
|
190 |
|
191 |
function get_current_url() {
|
177 |
box-shadow: none;
|
178 |
}
|
179 |
</style>
|
180 |
+
<script src='{JQUERY_SCRIPT_URL}'></script>
|
181 |
+
<script>
|
182 |
+
{LOCALIZE_SCRIPT}
|
183 |
+
</script>
|
184 |
+
<script src='{SCRIPT_URL}'></script>
|
185 |
<script>
|
186 |
var ct_date = new Date;
|
187 |
|
188 |
function set_spamFireWallCookie(cookie_name, cookie_value) {
|
189 |
var date = new Date;
|
190 |
date.setDate(date.getDate() + 30);
|
191 |
+
ctSetCookie( cookie_name, escape(cookie_value), date.toUTCString() );
|
|
|
|
|
192 |
}
|
193 |
|
194 |
function get_current_url() {
|
@@ -177,15 +177,18 @@
|
|
177 |
box-shadow: none;
|
178 |
}
|
179 |
</style>
|
|
|
|
|
|
|
|
|
|
|
180 |
<script>
|
181 |
var ct_date = new Date;
|
182 |
|
183 |
function set_spamFireWallCookie(cookie_name, cookie_value) {
|
184 |
var date = new Date;
|
185 |
date.setDate(date.getDate() + 30);
|
186 |
-
|
187 |
-
document.cookie = cookie_name + '=' + escape(cookie_value) + '; path=/; expires=' + date.toUTCString() + '; samesite=lax' + ctSecure;
|
188 |
-
return null;
|
189 |
}
|
190 |
|
191 |
function get_current_url() {
|
177 |
box-shadow: none;
|
178 |
}
|
179 |
</style>
|
180 |
+
<script src='{JQUERY_SCRIPT_URL}'></script>
|
181 |
+
<script>
|
182 |
+
{LOCALIZE_SCRIPT}
|
183 |
+
</script>
|
184 |
+
<script src='{SCRIPT_URL}'></script>
|
185 |
<script>
|
186 |
var ct_date = new Date;
|
187 |
|
188 |
function set_spamFireWallCookie(cookie_name, cookie_value) {
|
189 |
var date = new Date;
|
190 |
date.setDate(date.getDate() + 30);
|
191 |
+
ctSetCookie( cookie_name, escape(cookie_value), date.toUTCString() );
|
|
|
|
|
192 |
}
|
193 |
|
194 |
function get_current_url() {
|
@@ -177,15 +177,18 @@
|
|
177 |
box-shadow: none;
|
178 |
}
|
179 |
</style>
|
|
|
|
|
|
|
|
|
|
|
180 |
<script>
|
181 |
var ct_date = new Date;
|
182 |
|
183 |
function set_spamFireWallCookie(cookie_name, cookie_value) {
|
184 |
var date = new Date;
|
185 |
date.setDate(date.getDate() + 30);
|
186 |
-
|
187 |
-
document.cookie = cookie_name + '=' + escape(cookie_value) + '; path=/; expires=' + date.toUTCString() + '; samesite=lax' + ctSecure;
|
188 |
-
return null;
|
189 |
}
|
190 |
|
191 |
function get_current_url() {
|
177 |
box-shadow: none;
|
178 |
}
|
179 |
</style>
|
180 |
+
<script src='{JQUERY_SCRIPT_URL}'></script>
|
181 |
+
<script>
|
182 |
+
{LOCALIZE_SCRIPT}
|
183 |
+
</script>
|
184 |
+
<script src='{SCRIPT_URL}'></script>
|
185 |
<script>
|
186 |
var ct_date = new Date;
|
187 |
|
188 |
function set_spamFireWallCookie(cookie_name, cookie_value) {
|
189 |
var date = new Date;
|
190 |
date.setDate(date.getDate() + 30);
|
191 |
+
ctSetCookie( cookie_name, escape(cookie_value), date.toUTCString() );
|
|
|
|
|
192 |
}
|
193 |
|
194 |
function get_current_url() {
|
@@ -173,7 +173,7 @@ class GetFieldsAny {
|
|
173 |
|
174 |
foreach ($this->skip_message_post as $v) {
|
175 |
if (isset($_POST[$v])) {
|
176 |
-
$message = null;
|
177 |
break;
|
178 |
}
|
179 |
}
|
@@ -271,7 +271,6 @@ class GetFieldsAny {
|
|
271 |
foreach( $this->obfuscate_params as $needle ){
|
272 |
if ( strpos($key, $needle) !== false ) {
|
273 |
$value = $this->obfuscate_param( $value );
|
274 |
-
continue(2);
|
275 |
}
|
276 |
}
|
277 |
|
@@ -327,7 +326,7 @@ class GetFieldsAny {
|
|
327 |
|
328 |
}elseif(!is_object($value)){
|
329 |
|
330 |
-
if( $value
|
331 |
continue;
|
332 |
}
|
333 |
|
@@ -369,12 +368,12 @@ class GetFieldsAny {
|
|
369 |
/**
|
370 |
* Masks a value with asterisks (*)
|
371 |
*
|
372 |
-
* @param null $value
|
373 |
*
|
374 |
* @return string|null
|
375 |
*/
|
376 |
private function obfuscate_param($value = null) {
|
377 |
-
if
|
378 |
$length = strlen($value);
|
379 |
$value = str_repeat('*', $length);
|
380 |
}
|
173 |
|
174 |
foreach ($this->skip_message_post as $v) {
|
175 |
if (isset($_POST[$v])) {
|
176 |
+
$this->processed_data['message'] = null;
|
177 |
break;
|
178 |
}
|
179 |
}
|
271 |
foreach( $this->obfuscate_params as $needle ){
|
272 |
if ( strpos($key, $needle) !== false ) {
|
273 |
$value = $this->obfuscate_param( $value );
|
|
|
274 |
}
|
275 |
}
|
276 |
|
326 |
|
327 |
}elseif(!is_object($value)){
|
328 |
|
329 |
+
if( empty( $value ) ) {
|
330 |
continue;
|
331 |
}
|
332 |
|
368 |
/**
|
369 |
* Masks a value with asterisks (*)
|
370 |
*
|
371 |
+
* @param null|string $value
|
372 |
*
|
373 |
* @return string|null
|
374 |
*/
|
375 |
private function obfuscate_param($value = null) {
|
376 |
+
if( $value ) {
|
377 |
$length = strlen($value);
|
378 |
$value = str_repeat('*', $length);
|
379 |
}
|
@@ -29,11 +29,11 @@ class Helper extends \Cleantalk\Common\Helper
|
|
29 |
* ssl - use SSL
|
30 |
*
|
31 |
* @param string $url URL
|
32 |
-
* @param array
|
33 |
* @param string|array $presets String or Array with presets: get_code, async, get, ssl, dont_split_to_array
|
34 |
* @param array $opts Optional option for CURL connection
|
35 |
*
|
36 |
-
* @return array|bool (array || array('error' => true))
|
37 |
*/
|
38 |
public static function http__request($url, $data = array(), $presets = null, $opts = array())
|
39 |
{
|
@@ -207,7 +207,7 @@ class Helper extends \Cleantalk\Common\Helper
|
|
207 |
*
|
208 |
* @param string $url
|
209 |
*
|
210 |
-
* @return array|
|
211 |
*/
|
212 |
public static function http__get_data_from_remote_gz__and_parse_csv( $url ){
|
213 |
|
29 |
* ssl - use SSL
|
30 |
*
|
31 |
* @param string $url URL
|
32 |
+
* @param array|string|int $data POST|GET indexed array with data to send
|
33 |
* @param string|array $presets String or Array with presets: get_code, async, get, ssl, dont_split_to_array
|
34 |
* @param array $opts Optional option for CURL connection
|
35 |
*
|
36 |
+
* @return array|bool|string (array || array('error' => true))
|
37 |
*/
|
38 |
public static function http__request($url, $data = array(), $presets = null, $opts = array())
|
39 |
{
|
207 |
*
|
208 |
* @param string $url
|
209 |
*
|
210 |
+
* @return array|string
|
211 |
*/
|
212 |
public static function http__get_data_from_remote_gz__and_parse_csv( $url ){
|
213 |
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
namespace Cleantalk\ApbctWP;
|
5 |
+
|
6 |
+
|
7 |
+
class Queue extends \Cleantalk\Common\Queue {
|
8 |
+
|
9 |
+
const QUEUE_NAME = 'cleantalk_sfw_update_queue';
|
10 |
+
|
11 |
+
public function getQueue()
|
12 |
+
{
|
13 |
+
return get_option( self::QUEUE_NAME );
|
14 |
+
}
|
15 |
+
|
16 |
+
public static function clearQueue()
|
17 |
+
{
|
18 |
+
return delete_option( self::QUEUE_NAME );
|
19 |
+
}
|
20 |
+
|
21 |
+
function saveQueue( $queue )
|
22 |
+
{
|
23 |
+
return update_option( self::QUEUE_NAME, $queue );
|
24 |
+
}
|
25 |
+
}
|
@@ -3,7 +3,6 @@
|
|
3 |
|
4 |
namespace Cleantalk\ApbctWP;
|
5 |
|
6 |
-
use Cleantalk\ApbctWP\Firewall\SFW;
|
7 |
use Cleantalk\Variables\Get;
|
8 |
|
9 |
class RemoteCalls
|
@@ -27,7 +26,7 @@ class RemoteCalls
|
|
27 |
/**
|
28 |
* Execute corresponding method of RemoteCalls if exists
|
29 |
*
|
30 |
-
* @return
|
31 |
*/
|
32 |
public static function perform(){
|
33 |
|
@@ -58,11 +57,11 @@ class RemoteCalls
|
|
58 |
|
59 |
$action = 'action__'.$action;
|
60 |
|
61 |
-
if( method_exists(
|
62 |
|
63 |
// Delay before perform action;
|
64 |
if ( Get::get( 'delay' ) ){
|
65 |
-
sleep( Get::get( 'delay' ) );
|
66 |
$params = $_GET;
|
67 |
unset( $params['delay'] );
|
68 |
return Helper::http__request__rc_to_host(
|
@@ -73,22 +72,27 @@ class RemoteCalls
|
|
73 |
);
|
74 |
}
|
75 |
|
76 |
-
$out =
|
77 |
|
78 |
// Every remote call action handler should implement output or
|
79 |
// If out is empty(), the execution will continue
|
80 |
|
81 |
-
}else
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
|
94 |
/**
|
@@ -112,7 +116,9 @@ class RemoteCalls
|
|
112 |
/**
|
113 |
* SFW update
|
114 |
*
|
115 |
-
* @return
|
|
|
|
|
116 |
*/
|
117 |
public static function action__sfw_update(){
|
118 |
global $apbct;
|
@@ -125,14 +131,13 @@ class RemoteCalls
|
|
125 |
* SFW update
|
126 |
*
|
127 |
* @return string
|
|
|
|
|
128 |
*/
|
129 |
public static function action__sfw_update__worker(){
|
130 |
-
|
131 |
-
global $apbct;
|
132 |
$result = apbct_sfw_update__worker();
|
133 |
-
|
134 |
-
$apbct->error_toggle( ! empty( $result['error'] ), 'sfw_update', $result);
|
135 |
-
|
136 |
if( ! empty( $result['error'] ) ){
|
137 |
|
138 |
apbct_sfw_update__cleanData();
|
@@ -214,12 +219,12 @@ class RemoteCalls
|
|
214 |
$out['cron'] = $apbct->cron;
|
215 |
$out['errors'] = $apbct->errors;
|
216 |
|
217 |
-
array_walk( $out, function(&$val, $
|
218 |
$val = (array) $val;
|
219 |
});
|
220 |
|
221 |
-
array_walk_recursive( $out, function(&$val, $
|
222 |
-
if( is_int( $val ) && preg_match( '@^\d{9,11}$@', $val ) ){
|
223 |
$val = date( 'Y-m-d H:i:s', $val );
|
224 |
}
|
225 |
});
|
3 |
|
4 |
namespace Cleantalk\ApbctWP;
|
5 |
|
|
|
6 |
use Cleantalk\Variables\Get;
|
7 |
|
8 |
class RemoteCalls
|
26 |
/**
|
27 |
* Execute corresponding method of RemoteCalls if exists
|
28 |
*
|
29 |
+
* @return bool|string|string[]|null
|
30 |
*/
|
31 |
public static function perform(){
|
32 |
|
57 |
|
58 |
$action = 'action__'.$action;
|
59 |
|
60 |
+
if( method_exists( __CLASS__, $action ) ){
|
61 |
|
62 |
// Delay before perform action;
|
63 |
if ( Get::get( 'delay' ) ){
|
64 |
+
sleep( (int) Get::get( 'delay' ) );
|
65 |
$params = $_GET;
|
66 |
unset( $params['delay'] );
|
67 |
return Helper::http__request__rc_to_host(
|
72 |
);
|
73 |
}
|
74 |
|
75 |
+
$out = self::$action();
|
76 |
|
77 |
// Every remote call action handler should implement output or
|
78 |
// If out is empty(), the execution will continue
|
79 |
|
80 |
+
}else {
|
81 |
+
$out = 'FAIL ' . json_encode( array( 'error' => 'UNKNOWN_ACTION_METHOD' ) );
|
82 |
+
}
|
83 |
+
}else {
|
84 |
+
$out = 'FAIL ' . json_encode( array( 'error' => 'WRONG_TOKEN' ) );
|
85 |
+
}
|
86 |
+
}else {
|
87 |
+
$out = 'FAIL ' . json_encode( array( 'error' => 'TOO_MANY_ATTEMPTS' ) );
|
88 |
+
}
|
89 |
+
}else {
|
90 |
+
$out = 'FAIL ' . json_encode( array( 'error' => 'UNKNOWN_ACTION' ) );
|
91 |
+
}
|
92 |
+
|
93 |
+
if( $out ) {
|
94 |
+
die( $out );
|
95 |
+
}
|
96 |
}
|
97 |
|
98 |
/**
|
116 |
/**
|
117 |
* SFW update
|
118 |
*
|
119 |
+
* @return void
|
120 |
+
*
|
121 |
+
* @psalm-suppress UnusedVariable
|
122 |
*/
|
123 |
public static function action__sfw_update(){
|
124 |
global $apbct;
|
131 |
* SFW update
|
132 |
*
|
133 |
* @return string
|
134 |
+
*
|
135 |
+
* @psalm-suppress UnusedVariable
|
136 |
*/
|
137 |
public static function action__sfw_update__worker(){
|
138 |
+
|
|
|
139 |
$result = apbct_sfw_update__worker();
|
140 |
+
|
|
|
|
|
141 |
if( ! empty( $result['error'] ) ){
|
142 |
|
143 |
apbct_sfw_update__cleanData();
|
219 |
$out['cron'] = $apbct->cron;
|
220 |
$out['errors'] = $apbct->errors;
|
221 |
|
222 |
+
array_walk( $out, function(&$val, $_key){
|
223 |
$val = (array) $val;
|
224 |
});
|
225 |
|
226 |
+
array_walk_recursive( $out, function(&$val, $_key){
|
227 |
+
if( is_int( $val ) && preg_match( '@^\d{9,11}$@', (string) $val ) ){
|
228 |
$val = date( 'Y-m-d H:i:s', $val );
|
229 |
}
|
230 |
});
|
@@ -51,14 +51,14 @@ use ArrayObject;
|
|
51 |
*
|
52 |
* MISC
|
53 |
*
|
|
|
54 |
*/
|
55 |
class State
|
56 |
{
|
57 |
-
public $user
|
58 |
public $use_rest_api = 0;
|
59 |
public $option_prefix = 'cleantalk';
|
60 |
public $storage = array();
|
61 |
-
public $integrations = array();
|
62 |
public $def_settings = array(
|
63 |
|
64 |
'apikey' => '',
|
@@ -102,7 +102,7 @@ class State
|
|
102 |
'data__use_static_js_key' => -1,
|
103 |
'data__general_postdata_test' => 0, //CAPD
|
104 |
'data__set_cookies' => 1, // Set cookies: Disable - 0 / Enable - 1 / Use Alternative cookies - 2.
|
105 |
-
'data__set_cookies__alt_sessions_type' =>
|
106 |
'data__ssl_on' => 0, // Secure connection to servers
|
107 |
'data__pixel' => '3',
|
108 |
'data__email_check_before_post' => 1,
|
@@ -344,7 +344,7 @@ class State
|
|
344 |
$option = is_array($option) ? array_merge($this->def_data, $option) : $this->def_data;
|
345 |
// Generate salt
|
346 |
$option['salt'] = empty($option['salt'])
|
347 |
-
? str_pad(rand(0, getrandmax()), 6, '0').str_pad(rand(0, getrandmax()), 6, '0')
|
348 |
: $option['salt'];
|
349 |
}
|
350 |
|
@@ -433,7 +433,7 @@ class State
|
|
433 |
{
|
434 |
$option = get_option('cleantalk_'.$option_name, null);
|
435 |
|
436 |
-
$this->$option_name =
|
437 |
? new ArrayObject($option)
|
438 |
: $option;
|
439 |
}
|
@@ -529,8 +529,9 @@ class State
|
|
529 |
if( ($type == 'send_logs' && $error == 'NO_LOGS_TO_SEND') ||
|
530 |
($type == 'send_firewall_logs' && $error == 'NO_LOGS_TO_SEND') ||
|
531 |
$error == 'LOG_FILE_NOT_EXISTS'
|
532 |
-
)
|
533 |
return;
|
|
|
534 |
|
535 |
$error = array(
|
536 |
'error' => $error,
|
@@ -558,22 +559,26 @@ class State
|
|
558 |
public function error_delete($type, $save_flag = false, $major_type = null)
|
559 |
{
|
560 |
/** @noinspection DuplicatedCode */
|
561 |
-
if(is_string($type))
|
562 |
-
$type = explode(' ', $type);
|
|
|
563 |
|
564 |
foreach($type as $val){
|
565 |
if($major_type){
|
566 |
-
if(isset($this->errors[$major_type][$val]))
|
567 |
-
unset($this->errors[$major_type][$val]);
|
|
|
568 |
}else{
|
569 |
-
if(isset($this->errors[$val]))
|
570 |
-
unset($this->errors[$val]);
|
|
|
571 |
}
|
572 |
}
|
573 |
|
574 |
// Save if flag is set and there are changes
|
575 |
-
if($save_flag)
|
576 |
$this->saveErrors();
|
|
|
577 |
}
|
578 |
|
579 |
/**
|
@@ -586,8 +591,9 @@ class State
|
|
586 |
public function error_delete_all($save_flag = false)
|
587 |
{
|
588 |
$this->errors = array();
|
589 |
-
if($save_flag)
|
590 |
$this->saveErrors();
|
|
|
591 |
}
|
592 |
|
593 |
/**
|
@@ -601,10 +607,12 @@ class State
|
|
601 |
* @param bool $save_flag
|
602 |
*/
|
603 |
public function error_toggle($add_error, $type, $error, $major_type = null, $set_time = true, $save_flag = true ){
|
604 |
-
if( $add_error )
|
605 |
-
|
606 |
-
|
607 |
-
|
|
|
|
|
608 |
}
|
609 |
|
610 |
/**
|
51 |
*
|
52 |
* MISC
|
53 |
*
|
54 |
+
* @psalm-suppress PossiblyUnusedProperty
|
55 |
*/
|
56 |
class State
|
57 |
{
|
58 |
+
public $user;
|
59 |
public $use_rest_api = 0;
|
60 |
public $option_prefix = 'cleantalk';
|
61 |
public $storage = array();
|
|
|
62 |
public $def_settings = array(
|
63 |
|
64 |
'apikey' => '',
|
102 |
'data__use_static_js_key' => -1,
|
103 |
'data__general_postdata_test' => 0, //CAPD
|
104 |
'data__set_cookies' => 1, // Set cookies: Disable - 0 / Enable - 1 / Use Alternative cookies - 2.
|
105 |
+
'data__set_cookies__alt_sessions_type' => 0, // Alternative cookies handler type: REST API - 0 / AJAX - 1
|
106 |
'data__ssl_on' => 0, // Secure connection to servers
|
107 |
'data__pixel' => '3',
|
108 |
'data__email_check_before_post' => 1,
|
344 |
$option = is_array($option) ? array_merge($this->def_data, $option) : $this->def_data;
|
345 |
// Generate salt
|
346 |
$option['salt'] = empty($option['salt'])
|
347 |
+
? str_pad((string)rand(0, getrandmax()), 6, '0').str_pad((string)rand(0, getrandmax()), 6, '0')
|
348 |
: $option['salt'];
|
349 |
}
|
350 |
|
433 |
{
|
434 |
$option = get_option('cleantalk_'.$option_name, null);
|
435 |
|
436 |
+
$this->$option_name = is_array( $option )
|
437 |
? new ArrayObject($option)
|
438 |
: $option;
|
439 |
}
|
529 |
if( ($type == 'send_logs' && $error == 'NO_LOGS_TO_SEND') ||
|
530 |
($type == 'send_firewall_logs' && $error == 'NO_LOGS_TO_SEND') ||
|
531 |
$error == 'LOG_FILE_NOT_EXISTS'
|
532 |
+
) {
|
533 |
return;
|
534 |
+
}
|
535 |
|
536 |
$error = array(
|
537 |
'error' => $error,
|
559 |
public function error_delete($type, $save_flag = false, $major_type = null)
|
560 |
{
|
561 |
/** @noinspection DuplicatedCode */
|
562 |
+
if(is_string($type)) {
|
563 |
+
$type = explode( ' ', $type );
|
564 |
+
}
|
565 |
|
566 |
foreach($type as $val){
|
567 |
if($major_type){
|
568 |
+
if(isset($this->errors[$major_type][$val])) {
|
569 |
+
unset( $this->errors[ $major_type ][ $val ] );
|
570 |
+
}
|
571 |
}else{
|
572 |
+
if(isset($this->errors[$val])) {
|
573 |
+
unset( $this->errors[ $val ] );
|
574 |
+
}
|
575 |
}
|
576 |
}
|
577 |
|
578 |
// Save if flag is set and there are changes
|
579 |
+
if($save_flag) {
|
580 |
$this->saveErrors();
|
581 |
+
}
|
582 |
}
|
583 |
|
584 |
/**
|
591 |
public function error_delete_all($save_flag = false)
|
592 |
{
|
593 |
$this->errors = array();
|
594 |
+
if($save_flag) {
|
595 |
$this->saveErrors();
|
596 |
+
}
|
597 |
}
|
598 |
|
599 |
/**
|
607 |
* @param bool $save_flag
|
608 |
*/
|
609 |
public function error_toggle($add_error, $type, $error, $major_type = null, $set_time = true, $save_flag = true ){
|
610 |
+
if( $add_error ) {
|
611 |
+
$this->error_add( $type, $error, $major_type, $set_time );
|
612 |
+
}
|
613 |
+
else {
|
614 |
+
$this->error_delete( $type, $save_flag, $major_type );
|
615 |
+
}
|
616 |
}
|
617 |
|
618 |
/**
|
@@ -1,10 +1,9 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
|
4 |
namespace Cleantalk\ApbctWP\Variables;
|
5 |
|
6 |
-
|
7 |
use Cleantalk\ApbctWP\Helper;
|
|
|
8 |
use Cleantalk\Variables\Server;
|
9 |
|
10 |
class AltSessions {
|
@@ -12,7 +11,7 @@ class AltSessions {
|
|
12 |
public static $sessions_already_cleaned = false;
|
13 |
|
14 |
public static function getID(){
|
15 |
-
$id = Helper::ip__get(
|
16 |
. Server::get( 'HTTP_USER_AGENT' )
|
17 |
. Server::get( 'HTTP_ACCEPT_LANGUAGE' );
|
18 |
return hash('sha256', $id);
|
@@ -48,13 +47,13 @@ class AltSessions {
|
|
48 |
public static function set_fromRemote( $request = null ){
|
49 |
|
50 |
if( ! $request ){
|
51 |
-
$cookies_to_set = (array)
|
52 |
}else{
|
53 |
$cookies_to_set = $request->get_param( 'cookies' );
|
54 |
}
|
55 |
|
56 |
foreach( $cookies_to_set as $cookie_to_set ){
|
57 |
-
|
58 |
}
|
59 |
|
60 |
wp_send_json( array( 'success' => true ) );
|
@@ -66,7 +65,7 @@ class AltSessions {
|
|
66 |
|
67 |
// Bad incoming data
|
68 |
if( ! $name ){
|
69 |
-
return;
|
70 |
}
|
71 |
|
72 |
global $wpdb;
|
@@ -87,19 +86,20 @@ class AltSessions {
|
|
87 |
|
88 |
public static function get_fromRemote( $request = null ){
|
89 |
|
90 |
-
$value =
|
91 |
? $request->get_param( 'cookies' )
|
92 |
-
:
|
93 |
);
|
94 |
|
95 |
wp_send_json( array( 'success' => true, 'value' => $value ) );
|
96 |
}
|
97 |
|
98 |
public static function cleanFromOld(){
|
99 |
-
|
|
|
|
|
100 |
if( ! self::$sessions_already_cleaned && rand(0, 1000) < APBCT_SEESION__CHANCE_TO_CLEAN){
|
101 |
|
102 |
-
global $wpdb;
|
103 |
self::$sessions_already_cleaned = true;
|
104 |
|
105 |
$wpdb->query(
|
@@ -111,7 +111,7 @@ class AltSessions {
|
|
111 |
}
|
112 |
}
|
113 |
|
114 |
-
public static function wipe(
|
115 |
global $wpdb;
|
116 |
return $wpdb->query(
|
117 |
'TRUNCATE TABLE '. APBCT_TBL_SESSIONS .';'
|
1 |
<?php
|
2 |
|
|
|
3 |
namespace Cleantalk\ApbctWP\Variables;
|
4 |
|
|
|
5 |
use Cleantalk\ApbctWP\Helper;
|
6 |
+
use Cleantalk\Variables\Post;
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
9 |
class AltSessions {
|
11 |
public static $sessions_already_cleaned = false;
|
12 |
|
13 |
public static function getID(){
|
14 |
+
$id = Helper::ip__get()
|
15 |
. Server::get( 'HTTP_USER_AGENT' )
|
16 |
. Server::get( 'HTTP_ACCEPT_LANGUAGE' );
|
17 |
return hash('sha256', $id);
|
47 |
public static function set_fromRemote( $request = null ){
|
48 |
|
49 |
if( ! $request ){
|
50 |
+
$cookies_to_set = (array) Post::get( 'cookies' );
|
51 |
}else{
|
52 |
$cookies_to_set = $request->get_param( 'cookies' );
|
53 |
}
|
54 |
|
55 |
foreach( $cookies_to_set as $cookie_to_set ){
|
56 |
+
Cookie::set( $cookie_to_set[0], $cookie_to_set[1] );
|
57 |
}
|
58 |
|
59 |
wp_send_json( array( 'success' => true ) );
|
65 |
|
66 |
// Bad incoming data
|
67 |
if( ! $name ){
|
68 |
+
return false;
|
69 |
}
|
70 |
|
71 |
global $wpdb;
|
86 |
|
87 |
public static function get_fromRemote( $request = null ){
|
88 |
|
89 |
+
$value = Cookie::get( $request
|
90 |
? $request->get_param( 'cookies' )
|
91 |
+
: Post::get( 'name' )
|
92 |
);
|
93 |
|
94 |
wp_send_json( array( 'success' => true, 'value' => $value ) );
|
95 |
}
|
96 |
|
97 |
public static function cleanFromOld(){
|
98 |
+
|
99 |
+
global $wpdb;
|
100 |
+
|
101 |
if( ! self::$sessions_already_cleaned && rand(0, 1000) < APBCT_SEESION__CHANCE_TO_CLEAN){
|
102 |
|
|
|
103 |
self::$sessions_already_cleaned = true;
|
104 |
|
105 |
$wpdb->query(
|
111 |
}
|
112 |
}
|
113 |
|
114 |
+
public static function wipe() {
|
115 |
global $wpdb;
|
116 |
return $wpdb->query(
|
117 |
'TRUNCATE TABLE '. APBCT_TBL_SESSIONS .';'
|
@@ -7,8 +7,16 @@ use Cleantalk\ApbctWP\Helper;
|
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
9 |
class Cookie extends \Cleantalk\Variables\Cookie {
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
global $apbct;
|
14 |
|
@@ -57,12 +65,12 @@ class Cookie extends \Cleantalk\Variables\Cookie {
|
|
57 |
* Universal method to adding cookies
|
58 |
* Using Alternative Sessions or native cookies depends on settings
|
59 |
*
|
60 |
-
* @param $name
|
61 |
* @param string $value
|
62 |
* @param int $expires
|
63 |
* @param string $path
|
64 |
-
* @param
|
65 |
-
* @param bool $secure
|
66 |
* @param bool $httponly
|
67 |
* @param string $samesite
|
68 |
*/
|
@@ -70,21 +78,21 @@ class Cookie extends \Cleantalk\Variables\Cookie {
|
|
70 |
|
71 |
global $apbct;
|
72 |
|
73 |
-
if( $apbct->settings['data__set_cookies'] == 0 ){
|
74 |
return;
|
75 |
|
76 |
-
}elseif( $apbct->settings['data__set_cookies'] == 1 ){
|
77 |
-
self::setNativeCookie( $name, $value, $expires, $path, $domain, $secure, $httponly, $samesite );
|
78 |
-
|
79 |
}elseif( $apbct->settings['data__set_cookies'] == 2 ){
|
80 |
AltSessions::set( $name, $value );
|
|
|
|
|
|
|
81 |
}
|
82 |
|
83 |
}
|
84 |
|
85 |
/**
|
86 |
* Universal method to adding cookies
|
87 |
-
* Wrapper for setcookie()
|
88 |
*
|
89 |
* @see https://www.php.net/manual/ru/function.setcookie.php
|
90 |
*
|
@@ -92,7 +100,7 @@ class Cookie extends \Cleantalk\Variables\Cookie {
|
|
92 |
* @param string $value Cookie value
|
93 |
* @param int $expires Expiration timestamp. 0 - expiration with session
|
94 |
* @param string $path
|
95 |
-
* @param
|
96 |
* @param bool $secure
|
97 |
* @param bool $httponly
|
98 |
* @param string $samesite
|
@@ -125,7 +133,5 @@ class Cookie extends \Cleantalk\Variables\Cookie {
|
|
125 |
}
|
126 |
|
127 |
}
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
}
|
7 |
use Cleantalk\Variables\Server;
|
8 |
|
9 |
class Cookie extends \Cleantalk\Variables\Cookie {
|
10 |
+
|
11 |
+
/**
|
12 |
+
* @param string $name
|
13 |
+
* @param string|array $default
|
14 |
+
* @param null|string $cast_to
|
15 |
+
* @param false $raw
|
16 |
+
*
|
17 |
+
* @return string|array
|
18 |
+
*/
|
19 |
+
public static function get( $name, $default = '', $cast_to = null, $raw = false ){
|
20 |
|
21 |
global $apbct;
|
22 |
|
65 |
* Universal method to adding cookies
|
66 |
* Using Alternative Sessions or native cookies depends on settings
|
67 |
*
|
68 |
+
* @param string $name
|
69 |
* @param string $value
|
70 |
* @param int $expires
|
71 |
* @param string $path
|
72 |
+
* @param string $domain
|
73 |
+
* @param bool|null $secure
|
74 |
* @param bool $httponly
|
75 |
* @param string $samesite
|
76 |
*/
|
78 |
|
79 |
global $apbct;
|
80 |
|
81 |
+
if( $apbct->settings['data__set_cookies'] == 0 && ! is_admin() ){
|
82 |
return;
|
83 |
|
|
|
|
|
|
|
84 |
}elseif( $apbct->settings['data__set_cookies'] == 2 ){
|
85 |
AltSessions::set( $name, $value );
|
86 |
+
|
87 |
+
}else/*if( $apbct->settings['data__set_cookies'] == 1 )*/{
|
88 |
+
self::setNativeCookie( $name, $value, $expires, $path, $domain, $secure, $httponly, $samesite );
|
89 |
}
|
90 |
|
91 |
}
|
92 |
|
93 |
/**
|
94 |
* Universal method to adding cookies
|
95 |
+
* Wrapper for setcookie() Considering PHP version
|
96 |
*
|
97 |
* @see https://www.php.net/manual/ru/function.setcookie.php
|
98 |
*
|
100 |
* @param string $value Cookie value
|
101 |
* @param int $expires Expiration timestamp. 0 - expiration with session
|
102 |
* @param string $path
|
103 |
+
* @param string $domain
|
104 |
* @param bool $secure
|
105 |
* @param bool $httponly
|
106 |
* @param string $samesite
|
133 |
}
|
134 |
|
135 |
}
|
136 |
+
|
137 |
+
}
|
|
|
|
@@ -4,10 +4,10 @@ namespace Cleantalk\Common;
|
|
4 |
|
5 |
/**
|
6 |
* CleanTalk API class.
|
7 |
-
* Mostly contains wrappers for API methods. Check and send
|
8 |
* Compatible with any CMS.
|
9 |
*
|
10 |
-
* @version
|
11 |
* @author Cleantalk team (welcome@cleantalk.org)
|
12 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
13 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
@@ -28,9 +28,11 @@ class API
|
|
28 |
* @param string $version API method version
|
29 |
* @param boolean $do_check
|
30 |
*
|
31 |
-
* @return
|
|
|
|
|
32 |
*/
|
33 |
-
static
|
34 |
{
|
35 |
$request = array(
|
36 |
'method_name' => '2s_blacklists_db',
|
@@ -62,8 +64,10 @@ class API
|
|
62 |
* @param bool $do_check
|
63 |
*
|
64 |
* @return array|bool|mixed
|
|
|
|
|
65 |
*/
|
66 |
-
static
|
67 |
{
|
68 |
$request = array(
|
69 |
'method_name' => 'get_api_key',
|
@@ -93,8 +97,10 @@ class API
|
|
93 |
* @param boolean $do_check
|
94 |
*
|
95 |
* @return array|bool|mixed
|
|
|
|
|
96 |
*/
|
97 |
-
static
|
98 |
{
|
99 |
$request = Array(
|
100 |
'method_name' => 'get_antispam_report',
|
@@ -116,8 +122,10 @@ class API
|
|
116 |
* @param bool $do_check
|
117 |
*
|
118 |
* @return array|bool|mixed
|
|
|
|
|
119 |
*/
|
120 |
-
static
|
121 |
{
|
122 |
$request = array(
|
123 |
'method_name' => 'get_antispam_report_breif',
|
@@ -140,8 +148,10 @@ class API
|
|
140 |
* @param bool $do_check
|
141 |
*
|
142 |
* @return array|bool|mixed
|
|
|
|
|
143 |
*/
|
144 |
-
static
|
145 |
{
|
146 |
$request = array(
|
147 |
'method_name' => 'notice_paid_till',
|
@@ -166,8 +176,10 @@ class API
|
|
166 |
* @param bool $do_check
|
167 |
*
|
168 |
* @return array|bool|mixed
|
|
|
|
|
169 |
*/
|
170 |
-
static
|
171 |
{
|
172 |
$request = array(
|
173 |
'method_name' => 'ip_info',
|
@@ -189,8 +201,10 @@ class API
|
|
189 |
* @param bool $do_check
|
190 |
*
|
191 |
* @return array|bool|mixed
|
|
|
|
|
192 |
*/
|
193 |
-
static
|
194 |
{
|
195 |
$request = Array(
|
196 |
'method_name' => 'spam_check_cms',
|
@@ -198,7 +212,9 @@ class API
|
|
198 |
'data' => is_array($data) ? implode(',', $data) : $data,
|
199 |
);
|
200 |
|
201 |
-
if($date)
|
|
|
|
|
202 |
|
203 |
$result = static::send_request($request, self::URL, 20);
|
204 |
$result = $do_check ? static::check_response($result, 'spam_check_cms') : $result;
|
@@ -216,8 +232,10 @@ class API
|
|
216 |
* @param bool $do_check
|
217 |
*
|
218 |
* @return array|bool|mixed
|
|
|
|
|
219 |
*/
|
220 |
-
static
|
221 |
{
|
222 |
$request = array(
|
223 |
'method_name' => 'email_check',
|
@@ -241,8 +259,10 @@ class API
|
|
241 |
* @param bool $do_check
|
242 |
*
|
243 |
* @return array|bool|mixed
|
|
|
|
|
244 |
*/
|
245 |
-
static
|
246 |
{
|
247 |
$request = Array(
|
248 |
'method_name' => 'spam_check',
|
@@ -266,9 +286,11 @@ class API
|
|
266 |
* @param array $data
|
267 |
* @param bool $do_check
|
268 |
*
|
269 |
-
* @return array|bool
|
|
|
|
|
270 |
*/
|
271 |
-
static
|
272 |
{
|
273 |
|
274 |
$request = array(
|
@@ -296,8 +318,10 @@ class API
|
|
296 |
* @param bool $do_check
|
297 |
*
|
298 |
* @return array|bool|mixed
|
|
|
|
|
299 |
*/
|
300 |
-
static
|
301 |
{
|
302 |
$request = array(
|
303 |
'auth_key' => $api_key,
|
@@ -322,8 +346,10 @@ class API
|
|
322 |
* @param bool $do_check
|
323 |
*
|
324 |
* @return array|bool|mixed
|
|
|
|
|
325 |
*/
|
326 |
-
static
|
327 |
{
|
328 |
|
329 |
$request = array(
|
@@ -348,8 +374,10 @@ class API
|
|
348 |
* @param bool $do_check
|
349 |
*
|
350 |
* @return array|bool|mixed
|
|
|
|
|
351 |
*/
|
352 |
-
static
|
353 |
{
|
354 |
$request = array(
|
355 |
'auth_key' => $api_key,
|
@@ -371,8 +399,10 @@ class API
|
|
371 |
* @param bool $do_check
|
372 |
*
|
373 |
* @return array|bool|mixed
|
|
|
|
|
374 |
*/
|
375 |
-
static
|
376 |
{
|
377 |
|
378 |
$request = array(
|
@@ -394,8 +424,10 @@ class API
|
|
394 |
* @param bool $do_check
|
395 |
*
|
396 |
* @return array|bool|mixed
|
|
|
|
|
397 |
*/
|
398 |
-
static
|
399 |
{
|
400 |
|
401 |
$request = array(
|
@@ -421,8 +453,10 @@ class API
|
|
421 |
* @param bool $do_check
|
422 |
*
|
423 |
* @return array|bool|mixed
|
|
|
|
|
424 |
*/
|
425 |
-
static
|
426 |
{
|
427 |
$request = array(
|
428 |
'auth_key' => $api_key,
|
@@ -453,8 +487,10 @@ class API
|
|
453 |
* @param bool $do_check
|
454 |
*
|
455 |
* @return array|bool|mixed
|
|
|
|
|
456 |
*/
|
457 |
-
static
|
458 |
{
|
459 |
$request = array(
|
460 |
'method_name' => 'security_mscan_logs',
|
@@ -492,8 +528,10 @@ class API
|
|
492 |
* @param bool $do_check
|
493 |
*
|
494 |
* @return array|bool|mixed
|
|
|
|
|
495 |
*/
|
496 |
-
static
|
497 |
{
|
498 |
$request = array(
|
499 |
'method_name' => 'security_mscan_files',
|
@@ -520,8 +558,10 @@ class API
|
|
520 |
* @param bool $do_check
|
521 |
*
|
522 |
* @return array|bool|mixed
|
|
|
|
|
523 |
*/
|
524 |
-
static
|
525 |
{
|
526 |
$request = array(
|
527 |
'method_name' => 'backlinks_check_cms',
|
@@ -529,7 +569,9 @@ class API
|
|
529 |
'data' => is_array($data) ? implode(',', $data) : $data,
|
530 |
);
|
531 |
|
532 |
-
if($date)
|
|
|
|
|
533 |
|
534 |
$result = static::send_request($request);
|
535 |
$result = $do_check ? static::check_response($result, 'backlinks_check_cms') : $result;
|
@@ -546,8 +588,10 @@ class API
|
|
546 |
* @param bool $do_check
|
547 |
*
|
548 |
* @return array|bool|mixed
|
|
|
|
|
549 |
*/
|
550 |
-
static
|
551 |
{
|
552 |
$request = array(
|
553 |
'method_name' => 'security_backend_logs',
|
@@ -575,8 +619,10 @@ class API
|
|
575 |
* @param bool $do_check
|
576 |
*
|
577 |
* @return array|bool|mixed
|
|
|
|
|
578 |
*/
|
579 |
-
static
|
580 |
{
|
581 |
$request = array(
|
582 |
'method_name' => 'security_mscan_repairs',
|
@@ -604,8 +650,10 @@ class API
|
|
604 |
* @param bool $do_check
|
605 |
*
|
606 |
* @return array|bool|mixed
|
|
|
|
|
607 |
*/
|
608 |
-
static
|
609 |
{
|
610 |
$request = array(
|
611 |
'method_name' => 'request_checksums',
|
@@ -626,8 +674,10 @@ class API
|
|
626 |
* @param bool $do_check
|
627 |
*
|
628 |
* @return array|bool|mixed
|
|
|
|
|
629 |
*/
|
630 |
-
static
|
631 |
{
|
632 |
$request = array(
|
633 |
'method_name' => 'services_templates_get',
|
@@ -645,12 +695,14 @@ class API
|
|
645 |
* Settings templates add API method wrapper
|
646 |
*
|
647 |
* @param string $api_key
|
648 |
-
* @param null $template_name
|
649 |
* @param bool $do_check
|
650 |
*
|
651 |
* @return array|bool|mixed
|
|
|
|
|
652 |
*/
|
653 |
-
static
|
654 |
{
|
655 |
$request = array(
|
656 |
'method_name' => 'services_templates_add',
|
@@ -671,12 +723,15 @@ class API
|
|
671 |
*
|
672 |
* @param string $api_key
|
673 |
* @param int $template_id
|
674 |
-
* @param
|
|
|
675 |
* @param bool $do_check
|
676 |
*
|
677 |
* @return array|bool|mixed
|
|
|
|
|
678 |
*/
|
679 |
-
static
|
680 |
{
|
681 |
$request = array(
|
682 |
'method_name' => 'services_templates_update',
|
@@ -708,6 +763,8 @@ class API
|
|
708 |
* @param bool $do_check
|
709 |
*
|
710 |
* @return array|bool|bool[]|mixed|string[]
|
|
|
|
|
711 |
*/
|
712 |
public static function method__private_list_add(
|
713 |
$user_token,
|
@@ -748,20 +805,23 @@ class API
|
|
748 |
$product_id = $product_name === 'security' ? 4 : $product_id;
|
749 |
return $product_id;
|
750 |
}
|
751 |
-
|
752 |
/**
|
753 |
* Function sends raw request to API server
|
754 |
*
|
755 |
-
* @param array
|
756 |
-
* @param string
|
757 |
* @param integer $timeout timeout in seconds
|
758 |
-
* @param boolean $ssl
|
|
|
759 |
*
|
760 |
-
* @return array|
|
761 |
*/
|
762 |
-
static
|
763 |
{
|
764 |
-
|
|
|
|
|
765 |
$data['agent'] = !empty($data['agent'])
|
766 |
? $data['agent']
|
767 |
: (defined('CLEANTALK_AGENT') ? CLEANTALK_AGENT : self::AGENT);
|
@@ -772,13 +832,12 @@ class API
|
|
772 |
|
773 |
// For debug purposes
|
774 |
if(defined('CLEANTALK_DEBUG') && CLEANTALK_DEBUG){
|
775 |
-
global $apbct_debug;
|
776 |
$apbct_debug['sent_data'] = $data;
|
777 |
$apbct_debug['request_string'] = $data_string;
|
778 |
}
|
779 |
|
780 |
// Possibility to switch API url
|
781 |
-
$url = defined('CLEANTALK_API_URL') ? CLEANTALK_API_URL : $
|
782 |
|
783 |
if(function_exists('curl_init')){
|
784 |
|
@@ -792,9 +851,7 @@ class API
|
|
792 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
793 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
|
794 |
|
795 |
-
$ssl_path = $ssl_path
|
796 |
-
? $ssl_path
|
797 |
-
: (defined('CLEANTALK_CASERT_PATH') ? CLEANTALK_CASERT_PATH : '');
|
798 |
|
799 |
// Switch on/off SSL
|
800 |
if($ssl && $ssl_path){
|
@@ -826,7 +883,7 @@ class API
|
|
826 |
),
|
827 |
);
|
828 |
$context = stream_context_create($opts);
|
829 |
-
$result = @file_get_contents($url,
|
830 |
|
831 |
$errors = $result === false
|
832 |
? $errors . '_FAILED_TO_USE_FILE_GET_CONTENTS'
|
@@ -850,16 +907,16 @@ class API
|
|
850 |
*
|
851 |
* @return mixed (array || array('error' => true))
|
852 |
*/
|
853 |
-
static
|
854 |
{
|
855 |
// Errors handling
|
856 |
// Bad connection
|
857 |
if(is_array($result) && isset($result['error'])){
|
858 |
$last = error_get_last();
|
859 |
-
|
|
|
860 |
? array( 'error' => 'CONNECTION_ERROR : "' . $result['error'] . '"' )
|
861 |
: array( 'error' => 'CONNECTION_ERROR : "Unknown Error. Last error: ' . $last['message'] );
|
862 |
-
return $out;
|
863 |
}
|
864 |
|
865 |
// JSON decode errors
|
@@ -882,7 +939,7 @@ class API
|
|
882 |
}
|
883 |
}
|
884 |
|
885 |
-
//
|
886 |
switch($method_name){
|
887 |
|
888 |
// notice_paid_till
|
@@ -897,16 +954,15 @@ class API
|
|
897 |
)
|
898 |
)
|
899 |
$result['valid'] = 0;
|
900 |
-
else
|
901 |
$result['valid'] = 1;
|
|
|
902 |
|
903 |
return $result;
|
904 |
-
|
905 |
-
break;
|
906 |
case 'email_check':
|
907 |
-
|
908 |
-
|
909 |
-
break;
|
910 |
// get_antispam_report_breif
|
911 |
case 'get_antispam_report_breif':
|
912 |
|
@@ -917,37 +973,31 @@ class API
|
|
917 |
for($tmp = array(), $i = 0; $i < 7; $i++){
|
918 |
$tmp[date('Y-m-d', time() - 86400 * 7 + 86400 * $i)] = 0;
|
919 |
}
|
920 |
-
$out['spam_stat'] =
|
921 |
$out['top5_spam_ip'] = isset($out['top5_spam_ip']) ? array_slice($out['top5_spam_ip'], 0, 5) : array();
|
922 |
|
923 |
return $out;
|
924 |
-
|
925 |
-
break;
|
926 |
|
927 |
case 'services_templates_add' :
|
928 |
case 'services_templates_update' :
|
929 |
return isset( $result['data'] ) && is_array( $result['data'] ) && count( $result['data'] ) === 1
|
930 |
? $result['data'][0]
|
931 |
: array('error' => 'NO_DATA');
|
932 |
-
break;
|
933 |
|
934 |
case 'private_list_add':
|
935 |
-
return isset( $
|
936 |
? true
|
937 |
: array( 'error' => 'COULDNT_ADD_WL_IP');
|
938 |
-
break;
|
939 |
|
940 |
case '2s_blacklists_db':
|
941 |
return isset( $result['data'] ) && isset( $result['data_user_agents'] )
|
942 |
? $result
|
943 |
: $result['data'];
|
944 |
-
break;
|
945 |
|
946 |
default:
|
947 |
return isset($result['data']) && is_array($result['data'])
|
948 |
? $result['data']
|
949 |
: array('error' => 'NO_DATA');
|
950 |
-
break;
|
951 |
}
|
952 |
}
|
953 |
-
}
|
4 |
|
5 |
/**
|
6 |
* CleanTalk API class.
|
7 |
+
* Mostly contains wrappers for API methods. Check and send methods.
|
8 |
* Compatible with any CMS.
|
9 |
*
|
10 |
+
* @version 4.0
|
11 |
* @author Cleantalk team (welcome@cleantalk.org)
|
12 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
13 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
28 |
* @param string $version API method version
|
29 |
* @param boolean $do_check
|
30 |
*
|
31 |
+
* @return string|array ('error' => STRING)
|
32 |
+
*
|
33 |
+
* @psalm-suppress PossiblyUnusedMethod
|
34 |
*/
|
35 |
+
public static function method__get_2s_blacklists_db($api_key, $out = null, $version = '1_0', $do_check = true)
|
36 |
{
|
37 |
$request = array(
|
38 |
'method_name' => '2s_blacklists_db',
|
64 |
* @param bool $do_check
|
65 |
*
|
66 |
* @return array|bool|mixed
|
67 |
+
*
|
68 |
+
* @psalm-suppress PossiblyUnusedMethod
|
69 |
*/
|
70 |
+
public static function method__get_api_key($product_name, $email, $website, $platform, $timezone = null, $language = null, $user_ip = null, $wpms = false, $white_label = false, $do_check = true)
|
71 |
{
|
72 |
$request = array(
|
73 |
'method_name' => 'get_api_key',
|
97 |
* @param boolean $do_check
|
98 |
*
|
99 |
* @return array|bool|mixed
|
100 |
+
*
|
101 |
+
* @psalm-suppress PossiblyUnusedMethod
|
102 |
*/
|
103 |
+
public static function method__get_antispam_report($host, $period = 1, $do_check = true)
|
104 |
{
|
105 |
$request = Array(
|
106 |
'method_name' => 'get_antispam_report',
|
122 |
* @param bool $do_check
|
123 |
*
|
124 |
* @return array|bool|mixed
|
125 |
+
*
|
126 |
+
* @psalm-suppress PossiblyUnusedMethod
|
127 |
*/
|
128 |
+
public static function method__get_antispam_report_breif($api_key, $do_check = true)
|
129 |
{
|
130 |
$request = array(
|
131 |
'method_name' => 'get_antispam_report_breif',
|
148 |
* @param bool $do_check
|
149 |
*
|
150 |
* @return array|bool|mixed
|
151 |
+
*
|
152 |
+
* @psalm-suppress PossiblyUnusedMethod
|
153 |
*/
|
154 |
+
public static function method__notice_paid_till($api_key, $path_to_cms, $product_name = 'antispam', $do_check = true)
|
155 |
{
|
156 |
$request = array(
|
157 |
'method_name' => 'notice_paid_till',
|
176 |
* @param bool $do_check
|
177 |
*
|
178 |
* @return array|bool|mixed
|
179 |
+
*
|
180 |
+
* @psalm-suppress PossiblyUnusedMethod
|
181 |
*/
|
182 |
+
public static function method__ip_info($data, $do_check = true)
|
183 |
{
|
184 |
$request = array(
|
185 |
'method_name' => 'ip_info',
|
201 |
* @param bool $do_check
|
202 |
*
|
203 |
* @return array|bool|mixed
|
204 |
+
*
|
205 |
+
* @psalm-suppress PossiblyUnusedMethod
|
206 |
*/
|
207 |
+
public static function method__spam_check_cms($api_key, $data, $date = null, $do_check = true)
|
208 |
{
|
209 |
$request = Array(
|
210 |
'method_name' => 'spam_check_cms',
|
212 |
'data' => is_array($data) ? implode(',', $data) : $data,
|
213 |
);
|
214 |
|
215 |
+
if($date) {
|
216 |
+
$request['date'] = $date;
|
217 |
+
}
|
218 |
|
219 |
$result = static::send_request($request, self::URL, 20);
|
220 |
$result = $do_check ? static::check_response($result, 'spam_check_cms') : $result;
|
232 |
* @param bool $do_check
|
233 |
*
|
234 |
* @return array|bool|mixed
|
235 |
+
*
|
236 |
+
* @psalm-suppress PossiblyUnusedMethod
|
237 |
*/
|
238 |
+
public static function method__email_check($email, $cache_only = true, $do_check = true)
|
239 |
{
|
240 |
$request = array(
|
241 |
'method_name' => 'email_check',
|
259 |
* @param bool $do_check
|
260 |
*
|
261 |
* @return array|bool|mixed
|
262 |
+
*
|
263 |
+
* @psalm-suppress PossiblyUnusedMethod
|
264 |
*/
|
265 |
+
public static function method__spam_check($api_key, $data, $date = null, $do_check = true)
|
266 |
{
|
267 |
$request = Array(
|
268 |
'method_name' => 'spam_check',
|
286 |
* @param array $data
|
287 |
* @param bool $do_check
|
288 |
*
|
289 |
+
* @return array|bool
|
290 |
+
*
|
291 |
+
* @psalm-suppress PossiblyUnusedMethod
|
292 |
*/
|
293 |
+
public static function method__sfw_logs($api_key, $data, $do_check = true)
|
294 |
{
|
295 |
|
296 |
$request = array(
|
318 |
* @param bool $do_check
|
319 |
*
|
320 |
* @return array|bool|mixed
|
321 |
+
*
|
322 |
+
* @psalm-suppress PossiblyUnusedMethod
|
323 |
*/
|
324 |
+
public static function method__security_logs($api_key, $data, $do_check = true)
|
325 |
{
|
326 |
$request = array(
|
327 |
'auth_key' => $api_key,
|
346 |
* @param bool $do_check
|
347 |
*
|
348 |
* @return array|bool|mixed
|
349 |
+
*
|
350 |
+
* @psalm-suppress PossiblyUnusedMethod
|
351 |
*/
|
352 |
+
public static function method__security_logs__sendFWData($api_key, $data, $do_check = true)
|
353 |
{
|
354 |
|
355 |
$request = array(
|
374 |
* @param bool $do_check
|
375 |
*
|
376 |
* @return array|bool|mixed
|
377 |
+
*
|
378 |
+
* @psalm-suppress PossiblyUnusedMethod
|
379 |
*/
|
380 |
+
public static function method__security_logs__feedback($api_key, $do_check = true)
|
381 |
{
|
382 |
$request = array(
|
383 |
'auth_key' => $api_key,
|
399 |
* @param bool $do_check
|
400 |
*
|
401 |
* @return array|bool|mixed
|
402 |
+
*
|
403 |
+
* @psalm-suppress PossiblyUnusedMethod
|
404 |
*/
|
405 |
+
public static function method__security_firewall_data($api_key, $do_check = true)
|
406 |
{
|
407 |
|
408 |
$request = array(
|
424 |
* @param bool $do_check
|
425 |
*
|
426 |
* @return array|bool|mixed
|
427 |
+
*
|
428 |
+
* @psalm-suppress PossiblyUnusedMethod
|
429 |
*/
|
430 |
+
public static function method__security_firewall_data_file($api_key, $do_check = true)
|
431 |
{
|
432 |
|
433 |
$request = array(
|
453 |
* @param bool $do_check
|
454 |
*
|
455 |
* @return array|bool|mixed
|
456 |
+
*
|
457 |
+
* @psalm-suppress PossiblyUnusedMethod
|
458 |
*/
|
459 |
+
public static function method__security_linksscan_logs($api_key, $scan_time, $scan_result, $links_total, $links_list, $do_check = true)
|
460 |
{
|
461 |
$request = array(
|
462 |
'auth_key' => $api_key,
|
487 |
* @param bool $do_check
|
488 |
*
|
489 |
* @return array|bool|mixed
|
490 |
+
*
|
491 |
+
* @psalm-suppress PossiblyUnusedMethod
|
492 |
*/
|
493 |
+
public static function method__security_mscan_logs($api_key, $service_id, $scan_time, $scan_result, $scanned_total, $modified, $unknown, $do_check = true)
|
494 |
{
|
495 |
$request = array(
|
496 |
'method_name' => 'security_mscan_logs',
|
528 |
* @param bool $do_check
|
529 |
*
|
530 |
* @return array|bool|mixed
|
531 |
+
*
|
532 |
+
* @psalm-suppress PossiblyUnusedMethod
|
533 |
*/
|
534 |
+
public static function method__security_mscan_files($api_key, $file_path, $file, $file_md5, $weak_spots, $do_check = true)
|
535 |
{
|
536 |
$request = array(
|
537 |
'method_name' => 'security_mscan_files',
|
558 |
* @param bool $do_check
|
559 |
*
|
560 |
* @return array|bool|mixed
|
561 |
+
*
|
562 |
+
* @psalm-suppress PossiblyUnusedMethod
|
563 |
*/
|
564 |
+
public static function method__backlinks_check_cms($api_key, $data, $date = null, $do_check = true)
|
565 |
{
|
566 |
$request = array(
|
567 |
'method_name' => 'backlinks_check_cms',
|
569 |
'data' => is_array($data) ? implode(',', $data) : $data,
|
570 |
);
|
571 |
|
572 |
+
if($date) {
|
573 |
+
$request['date'] = $date;
|
574 |
+
}
|
575 |
|
576 |
$result = static::send_request($request);
|
577 |
$result = $do_check ? static::check_response($result, 'backlinks_check_cms') : $result;
|
588 |
* @param bool $do_check
|
589 |
*
|
590 |
* @return array|bool|mixed
|
591 |
+
*
|
592 |
+
* @psalm-suppress PossiblyUnusedMethod
|
593 |
*/
|
594 |
+
public static function method__security_backend_logs($api_key, $logs, $do_check = true)
|
595 |
{
|
596 |
$request = array(
|
597 |
'method_name' => 'security_backend_logs',
|
619 |
* @param bool $do_check
|
620 |
*
|
621 |
* @return array|bool|mixed
|
622 |
+
*
|
623 |
+
* @psalm-suppress PossiblyUnusedMethod
|
624 |
*/
|
625 |
+
public static function method__security_mscan_repairs($api_key, $repair_result, $repair_comment, $repaired_processed_files, $repaired_total_files_proccessed, $backup_id, $do_check = true)
|
626 |
{
|
627 |
$request = array(
|
628 |
'method_name' => 'security_mscan_repairs',
|
650 |
* @param bool $do_check
|
651 |
*
|
652 |
* @return array|bool|mixed
|
653 |
+
*
|
654 |
+
* @psalm-suppress PossiblyUnusedMethod
|
655 |
*/
|
656 |
+
public static function method__request_checksums($api_key, $plugins_and_themes_to_refresh, $do_check = true)
|
657 |
{
|
658 |
$request = array(
|
659 |
'method_name' => 'request_checksums',
|
674 |
* @param bool $do_check
|
675 |
*
|
676 |
* @return array|bool|mixed
|
677 |
+
*
|
678 |
+
* @psalm-suppress PossiblyUnusedMethod
|
679 |
*/
|
680 |
+
public static function method__services_templates_get( $api_key, $product_name = 'antispam', $do_check = true)
|
681 |
{
|
682 |
$request = array(
|
683 |
'method_name' => 'services_templates_get',
|
695 |
* Settings templates add API method wrapper
|
696 |
*
|
697 |
* @param string $api_key
|
698 |
+
* @param null|string $template_name
|
699 |
* @param bool $do_check
|
700 |
*
|
701 |
* @return array|bool|mixed
|
702 |
+
*
|
703 |
+
* @psalm-suppress PossiblyUnusedMethod
|
704 |
*/
|
705 |
+
public static function method__services_templates_add( $api_key, $template_name = null, $options = '', $product_name = 'antispam', $do_check = true)
|
706 |
{
|
707 |
$request = array(
|
708 |
'method_name' => 'services_templates_add',
|
723 |
*
|
724 |
* @param string $api_key
|
725 |
* @param int $template_id
|
726 |
+
* @param string $options
|
727 |
+
* @param string $product_name
|
728 |
* @param bool $do_check
|
729 |
*
|
730 |
* @return array|bool|mixed
|
731 |
+
*
|
732 |
+
* @psalm-suppress PossiblyUnusedMethod
|
733 |
*/
|
734 |
+
public static function method__services_templates_update( $api_key, $template_id, $options = '', $product_name = 'antispam', $do_check = true)
|
735 |
{
|
736 |
$request = array(
|
737 |
'method_name' => 'services_templates_update',
|
763 |
* @param bool $do_check
|
764 |
*
|
765 |
* @return array|bool|bool[]|mixed|string[]
|
766 |
+
*
|
767 |
+
* @psalm-suppress PossiblyUnusedMethod
|
768 |
*/
|
769 |
public static function method__private_list_add(
|
770 |
$user_token,
|
805 |
$product_id = $product_name === 'security' ? 4 : $product_id;
|
806 |
return $product_id;
|
807 |
}
|
808 |
+
|
809 |
/**
|
810 |
* Function sends raw request to API server
|
811 |
*
|
812 |
+
* @param array $data to send
|
813 |
+
* @param string $_url
|
814 |
* @param integer $timeout timeout in seconds
|
815 |
+
* @param boolean $ssl use ssl on not
|
816 |
+
* @param string $ssl_path
|
817 |
*
|
818 |
+
* @return array|string
|
819 |
*/
|
820 |
+
public static function send_request($data, $_url = self::URL, $timeout = 10, $ssl = false, $ssl_path = '')
|
821 |
{
|
822 |
+
global $apbct_debug;
|
823 |
+
|
824 |
+
// Possibility to switch agent version
|
825 |
$data['agent'] = !empty($data['agent'])
|
826 |
? $data['agent']
|
827 |
: (defined('CLEANTALK_AGENT') ? CLEANTALK_AGENT : self::AGENT);
|
832 |
|
833 |
// For debug purposes
|
834 |
if(defined('CLEANTALK_DEBUG') && CLEANTALK_DEBUG){
|
|
|
835 |
$apbct_debug['sent_data'] = $data;
|
836 |
$apbct_debug['request_string'] = $data_string;
|
837 |
}
|
838 |
|
839 |
// Possibility to switch API url
|
840 |
+
$url = defined('CLEANTALK_API_URL') ? CLEANTALK_API_URL : $_url;
|
841 |
|
842 |
if(function_exists('curl_init')){
|
843 |
|
851 |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
852 |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
|
853 |
|
854 |
+
$ssl_path = $ssl_path ?: ( defined( 'CLEANTALK_CASERT_PATH' ) ? CLEANTALK_CASERT_PATH : '' );
|
|
|
|
|
855 |
|
856 |
// Switch on/off SSL
|
857 |
if($ssl && $ssl_path){
|
883 |
),
|
884 |
);
|
885 |
$context = stream_context_create($opts);
|
886 |
+
$result = @file_get_contents($url, false, $context);
|
887 |
|
888 |
$errors = $result === false
|
889 |
? $errors . '_FAILED_TO_USE_FILE_GET_CONTENTS'
|
907 |
*
|
908 |
* @return mixed (array || array('error' => true))
|
909 |
*/
|
910 |
+
public static function check_response($result, $method_name = null)
|
911 |
{
|
912 |
// Errors handling
|
913 |
// Bad connection
|
914 |
if(is_array($result) && isset($result['error'])){
|
915 |
$last = error_get_last();
|
916 |
+
|
917 |
+
return ! empty( $result['error'] )
|
918 |
? array( 'error' => 'CONNECTION_ERROR : "' . $result['error'] . '"' )
|
919 |
: array( 'error' => 'CONNECTION_ERROR : "Unknown Error. Last error: ' . $last['message'] );
|
|
|
920 |
}
|
921 |
|
922 |
// JSON decode errors
|
939 |
}
|
940 |
}
|
941 |
|
942 |
+
// Patches for different methods
|
943 |
switch($method_name){
|
944 |
|
945 |
// notice_paid_till
|
954 |
)
|
955 |
)
|
956 |
$result['valid'] = 0;
|
957 |
+
else {
|
958 |
$result['valid'] = 1;
|
959 |
+
}
|
960 |
|
961 |
return $result;
|
962 |
+
|
|
|
963 |
case 'email_check':
|
964 |
+
return isset($result['data']) ? $result : array( 'error' => 'NO_DATA');
|
965 |
+
|
|
|
966 |
// get_antispam_report_breif
|
967 |
case 'get_antispam_report_breif':
|
968 |
|
973 |
for($tmp = array(), $i = 0; $i < 7; $i++){
|
974 |
$tmp[date('Y-m-d', time() - 86400 * 7 + 86400 * $i)] = 0;
|
975 |
}
|
976 |
+
$out['spam_stat'] = array_merge($tmp, isset($out['spam_stat']) ? $out['spam_stat'] : array());
|
977 |
$out['top5_spam_ip'] = isset($out['top5_spam_ip']) ? array_slice($out['top5_spam_ip'], 0, 5) : array();
|
978 |
|
979 |
return $out;
|
|
|
|
|
980 |
|
981 |
case 'services_templates_add' :
|
982 |
case 'services_templates_update' :
|
983 |
return isset( $result['data'] ) && is_array( $result['data'] ) && count( $result['data'] ) === 1
|
984 |
? $result['data'][0]
|
985 |
: array('error' => 'NO_DATA');
|
|
|
986 |
|
987 |
case 'private_list_add':
|
988 |
+
return isset( $result['records'][0]['operation_status'] ) && $result['records'][0]['operation_status'] === 'SUCCESS'
|
989 |
? true
|
990 |
: array( 'error' => 'COULDNT_ADD_WL_IP');
|
|
|
991 |
|
992 |
case '2s_blacklists_db':
|
993 |
return isset( $result['data'] ) && isset( $result['data_user_agents'] )
|
994 |
? $result
|
995 |
: $result['data'];
|
|
|
996 |
|
997 |
default:
|
998 |
return isset($result['data']) && is_array($result['data'])
|
999 |
? $result['data']
|
1000 |
: array('error' => 'NO_DATA');
|
|
|
1001 |
}
|
1002 |
}
|
1003 |
+
}
|
@@ -9,21 +9,27 @@ namespace Cleantalk\Common;
|
|
9 |
* Allows to work with multi dimensional arrays
|
10 |
*
|
11 |
* @package Cleantalk
|
|
|
|
|
12 |
*/
|
13 |
class Arr
|
14 |
{
|
15 |
|
16 |
-
private $array
|
17 |
private $found = array();
|
18 |
private $result = array();
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
public function __construct( $array )
|
21 |
{
|
22 |
$this->array = is_array( $array )
|
23 |
? $array
|
24 |
: array();
|
25 |
-
|
26 |
-
return $this;
|
27 |
}
|
28 |
|
29 |
/**
|
@@ -36,14 +42,16 @@ class Arr
|
|
36 |
* @param array $array
|
37 |
*
|
38 |
* @return Arr
|
|
|
39 |
*/
|
40 |
public function get_keys( $keys = array(), $regexp = false, $array = array() )
|
41 |
{
|
42 |
-
$array = $array
|
43 |
$keys = is_array( $keys ) ? $keys : explode( ',', $keys );
|
44 |
|
45 |
-
if( empty( $array ) || empty( $keys ) )
|
46 |
return $this;
|
|
|
47 |
|
48 |
$this->found = $keys === array('all')
|
49 |
? $this->array
|
@@ -59,7 +67,7 @@ class Arr
|
|
59 |
|
60 |
/**
|
61 |
* Recursive
|
62 |
-
* Check if Array has
|
63 |
* Save found keys in $this->found
|
64 |
*
|
65 |
* @param array|string $values
|
@@ -67,14 +75,16 @@ class Arr
|
|
67 |
* @param array $array
|
68 |
*
|
69 |
* @return $this
|
|
|
70 |
*/
|
71 |
public function get_values( $values = array(), $regexp = false, $array = array() )
|
72 |
{
|
73 |
-
$array = $array
|
74 |
$keys = is_array( $values ) ? $values : explode( ',', $values );
|
75 |
|
76 |
-
if( empty( $array ) || empty( $values ) )
|
77 |
return $this;
|
|
|
78 |
|
79 |
$this->found = $values === array('all')
|
80 |
? $this->array
|
@@ -87,14 +97,23 @@ class Arr
|
|
87 |
|
88 |
return $this;
|
89 |
}
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
public function get_array( $searched = array(), $regexp = false, $array = array() ){
|
92 |
|
93 |
-
$array = $array
|
94 |
|
95 |
|
96 |
-
if( empty( $array ) || empty( $searched ) )
|
97 |
return $this;
|
|
|
98 |
|
99 |
$this->found = $searched === array('all')
|
100 |
? $this->array
|
@@ -118,12 +137,13 @@ class Arr
|
|
118 |
* @param array $array
|
119 |
* @param array $found
|
120 |
*
|
121 |
-
* @return bool
|
|
|
122 |
*/
|
123 |
public function is( $type, $array = array(), $found = array() )
|
124 |
{
|
125 |
-
$array = $array
|
126 |
-
$found = $found
|
127 |
|
128 |
foreach ( $array as $key => $value ){
|
129 |
|
@@ -136,7 +156,7 @@ class Arr
|
|
136 |
switch ( $type ){
|
137 |
case 'regexp':
|
138 |
$value = preg_match( '/\/.*\//', $value ) === 1 ? $value : '/' . $value . '/';
|
139 |
-
if( @preg_match( $value,
|
140 |
return false;
|
141 |
}
|
142 |
break;
|
@@ -165,31 +185,37 @@ class Arr
|
|
165 |
// Recursion
|
166 |
if( is_array( $value ) ){
|
167 |
$result = $this->search( $type, $value, $searched, $regexp, array() );
|
168 |
-
if($result)
|
169 |
-
$found[$key] = $result;
|
|
|
170 |
|
171 |
-
|
172 |
}else{
|
173 |
foreach ( $searched as $searched_key => $searched_val ){
|
174 |
switch ($type){
|
175 |
case 'key':
|
176 |
-
if( $key === $searched_val || ($regexp && preg_match( '/' . $searched_val . '/', $key) === 1) )
|
177 |
-
$found[$key] = true;
|
|
|
178 |
break;
|
179 |
case 'value':
|
180 |
-
if( stripos($value, $searched_val) !== false || ($regexp && preg_match( '/' . $searched_val . '/', $value) === 1) )
|
181 |
-
$found[$key] = true;
|
|
|
182 |
break;
|
183 |
case 'array':
|
184 |
-
if( stripos($key, $searched_key) !== false || ($regexp && preg_match( '/' . $searched_key . '/', $key) === 1) )
|
185 |
-
if( is_array( $value )
|
|
|
|
|
186 |
$result = $this->search( 'array', $value, $searched_key, $regexp, array() );
|
187 |
-
if( $result ){
|
188 |
$found[ $key ] = $result;
|
189 |
}
|
190 |
-
}else{
|
191 |
-
$found[$key] = $value;
|
192 |
}
|
|
|
193 |
break;
|
194 |
}
|
195 |
}
|
@@ -198,15 +224,16 @@ class Arr
|
|
198 |
|
199 |
return $found;
|
200 |
}
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
202 |
public function compare( $arr1, $arr2 ){
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
if( $arr1 === $arr2 ){
|
207 |
-
if(is_array($arr1) && is_array($arr2)){
|
208 |
-
$result = $this->compare( $arr1, $arr2 );
|
209 |
-
}
|
210 |
}
|
211 |
}
|
212 |
}
|
@@ -221,19 +248,21 @@ class Arr
|
|
221 |
* @param array $found
|
222 |
*
|
223 |
* @return array
|
|
|
224 |
*/
|
225 |
public function delete( $searched = 'arr_special_param', $array = array(), $found =array() )
|
226 |
{
|
227 |
-
$array = $array
|
228 |
-
$found = $found
|
229 |
|
230 |
foreach($array as $key => $value){
|
231 |
|
232 |
if(array_key_exists($key, $found)){
|
233 |
if( is_array( $found[ $key ] ) ){
|
234 |
$array[ $key ] = $this->delete( $searched, $value, $found[ $key ] );
|
235 |
-
if( empty( $array[ $key ] ) )
|
236 |
unset( $array[ $key ] );
|
|
|
237 |
}else{
|
238 |
if( $searched === 'arr_special_param' || $searched === $value ){
|
239 |
unset( $array[ $key ] );
|
@@ -246,7 +275,11 @@ class Arr
|
|
246 |
$this->result = $array;
|
247 |
return $array;
|
248 |
}
|
249 |
-
|
|
|
|
|
|
|
|
|
250 |
public function result(){
|
251 |
return (boolean) $this->found;
|
252 |
}
|
9 |
* Allows to work with multi dimensional arrays
|
10 |
*
|
11 |
* @package Cleantalk
|
12 |
+
*
|
13 |
+
* @psalm-suppress UnusedProperty
|
14 |
*/
|
15 |
class Arr
|
16 |
{
|
17 |
|
18 |
+
private $array;
|
19 |
private $found = array();
|
20 |
private $result = array();
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Arr constructor.
|
24 |
+
*
|
25 |
+
* @param $array
|
26 |
+
* @psalm-suppress PossiblyUnusedMethod
|
27 |
+
*/
|
28 |
public function __construct( $array )
|
29 |
{
|
30 |
$this->array = is_array( $array )
|
31 |
? $array
|
32 |
: array();
|
|
|
|
|
33 |
}
|
34 |
|
35 |
/**
|
42 |
* @param array $array
|
43 |
*
|
44 |
* @return Arr
|
45 |
+
* @psalm-suppress PossiblyUnusedMethod
|
46 |
*/
|
47 |
public function get_keys( $keys = array(), $regexp = false, $array = array() )
|
48 |
{
|
49 |
+
$array = $array ?: $this->array;
|
50 |
$keys = is_array( $keys ) ? $keys : explode( ',', $keys );
|
51 |
|
52 |
+
if( empty( $array ) || empty( $keys ) ) {
|
53 |
return $this;
|
54 |
+
}
|
55 |
|
56 |
$this->found = $keys === array('all')
|
57 |
? $this->array
|
67 |
|
68 |
/**
|
69 |
* Recursive
|
70 |
+
* Check if Array has values given values
|
71 |
* Save found keys in $this->found
|
72 |
*
|
73 |
* @param array|string $values
|
75 |
* @param array $array
|
76 |
*
|
77 |
* @return $this
|
78 |
+
* @psalm-suppress PossiblyUnusedMethod
|
79 |
*/
|
80 |
public function get_values( $values = array(), $regexp = false, $array = array() )
|
81 |
{
|
82 |
+
$array = $array ?: $this->array;
|
83 |
$keys = is_array( $values ) ? $values : explode( ',', $values );
|
84 |
|
85 |
+
if( empty( $array ) || empty( $values ) ) {
|
86 |
return $this;
|
87 |
+
}
|
88 |
|
89 |
$this->found = $values === array('all')
|
90 |
? $this->array
|
97 |
|
98 |
return $this;
|
99 |
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* @param array $searched
|
103 |
+
* @param false $regexp
|
104 |
+
* @param array $array
|
105 |
+
*
|
106 |
+
* @return $this
|
107 |
+
* @psalm-suppress PossiblyUnusedMethod
|
108 |
+
*/
|
109 |
public function get_array( $searched = array(), $regexp = false, $array = array() ){
|
110 |
|
111 |
+
$array = $array ?: $this->array;
|
112 |
|
113 |
|
114 |
+
if( empty( $array ) || empty( $searched ) ) {
|
115 |
return $this;
|
116 |
+
}
|
117 |
|
118 |
$this->found = $searched === array('all')
|
119 |
? $this->array
|
137 |
* @param array $array
|
138 |
* @param array $found
|
139 |
*
|
140 |
+
* @return bool
|
141 |
+
* @psalm-suppress PossiblyUnusedMethod
|
142 |
*/
|
143 |
public function is( $type, $array = array(), $found = array() )
|
144 |
{
|
145 |
+
$array = $array ?: $this->array;
|
146 |
+
$found = $found ?: $this->found;
|
147 |
|
148 |
foreach ( $array as $key => $value ){
|
149 |
|
156 |
switch ( $type ){
|
157 |
case 'regexp':
|
158 |
$value = preg_match( '/\/.*\//', $value ) === 1 ? $value : '/' . $value . '/';
|
159 |
+
if( @preg_match( $value, '' ) === false ){
|
160 |
return false;
|
161 |
}
|
162 |
break;
|
185 |
// Recursion
|
186 |
if( is_array( $value ) ){
|
187 |
$result = $this->search( $type, $value, $searched, $regexp, array() );
|
188 |
+
if($result) {
|
189 |
+
$found[ $key ] = $result;
|
190 |
+
}
|
191 |
|
192 |
+
// Execution
|
193 |
}else{
|
194 |
foreach ( $searched as $searched_key => $searched_val ){
|
195 |
switch ($type){
|
196 |
case 'key':
|
197 |
+
if( $key === $searched_val || ($regexp && preg_match( '/' . $searched_val . '/', $key) === 1) ) {
|
198 |
+
$found[ $key ] = true;
|
199 |
+
}
|
200 |
break;
|
201 |
case 'value':
|
202 |
+
if( stripos($value, $searched_val) !== false || ($regexp && preg_match( '/' . $searched_val . '/', $value) === 1) ) {
|
203 |
+
$found[ $key ] = true;
|
204 |
+
}
|
205 |
break;
|
206 |
case 'array':
|
207 |
+
if( stripos($key, $searched_key) !== false || ($regexp && preg_match( '/' . $searched_key . '/', $key) === 1) ) {
|
208 |
+
if ( is_array( $value ) ) {
|
209 |
+
/** @psalm-suppress InvalidArgument */
|
210 |
+
//@ToDo maybe $searched_key need to be replaced by $searched_val?
|
211 |
$result = $this->search( 'array', $value, $searched_key, $regexp, array() );
|
212 |
+
if ( $result ) {
|
213 |
$found[ $key ] = $result;
|
214 |
}
|
215 |
+
} else {
|
216 |
+
$found[ $key ] = $value;
|
217 |
}
|
218 |
+
}
|
219 |
break;
|
220 |
}
|
221 |
}
|
224 |
|
225 |
return $found;
|
226 |
}
|
227 |
+
|
228 |
+
/**
|
229 |
+
* @param array $arr1
|
230 |
+
* @param array $arr2
|
231 |
+
* @psalm-suppress PossiblyUnusedMethod
|
232 |
+
*/
|
233 |
public function compare( $arr1, $arr2 ){
|
234 |
+
foreach ( $arr1 as $_value ){
|
235 |
+
if( ( $arr1 === $arr2 ) && is_array( $arr1 ) && is_array( $arr2 ) ) {
|
236 |
+
$this->compare( $arr1, $arr2 );
|
|
|
|
|
|
|
|
|
237 |
}
|
238 |
}
|
239 |
}
|
248 |
* @param array $found
|
249 |
*
|
250 |
* @return array
|
251 |
+
* @psalm-suppress PossiblyUnusedMethod
|
252 |
*/
|
253 |
public function delete( $searched = 'arr_special_param', $array = array(), $found =array() )
|
254 |
{
|
255 |
+
$array = $array ?: $this->array;
|
256 |
+
$found = $found ?: $this->found;
|
257 |
|
258 |
foreach($array as $key => $value){
|
259 |
|
260 |
if(array_key_exists($key, $found)){
|
261 |
if( is_array( $found[ $key ] ) ){
|
262 |
$array[ $key ] = $this->delete( $searched, $value, $found[ $key ] );
|
263 |
+
if( empty( $array[ $key ] ) ) {
|
264 |
unset( $array[ $key ] );
|
265 |
+
}
|
266 |
}else{
|
267 |
if( $searched === 'arr_special_param' || $searched === $value ){
|
268 |
unset( $array[ $key ] );
|
275 |
$this->result = $array;
|
276 |
return $array;
|
277 |
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* @return bool
|
281 |
+
* @psalm-suppress PossiblyUnusedMethod
|
282 |
+
*/
|
283 |
public function result(){
|
284 |
return (boolean) $this->found;
|
285 |
}
|
@@ -12,6 +12,8 @@ namespace Cleantalk\Common;
|
|
12 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
13 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
14 |
* @see https://github.com/CleanTalk/php-antispam
|
|
|
|
|
15 |
*/
|
16 |
class Compatibility
|
17 |
{
|
@@ -61,6 +63,7 @@ class Compatibility
|
|
61 |
* W3 Total Cache check late init option
|
62 |
*
|
63 |
* @return boolean
|
|
|
64 |
*/
|
65 |
public function w3tcCheckLateInit__callback(){
|
66 |
|
12 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
13 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
14 |
* @see https://github.com/CleanTalk/php-antispam
|
15 |
+
*
|
16 |
+
* @psalm-suppress UnusedProperty
|
17 |
*/
|
18 |
class Compatibility
|
19 |
{
|
63 |
* W3 Total Cache check late init option
|
64 |
*
|
65 |
* @return boolean
|
66 |
+
* @psalm-suppress PossiblyUnusedMethod
|
67 |
*/
|
68 |
public function w3tcCheckLateInit__callback(){
|
69 |
|
@@ -125,6 +125,7 @@ abstract class Cron
|
|
125 |
* @param string $task
|
126 |
*
|
127 |
* @return bool
|
|
|
128 |
*/
|
129 |
public function removeTask( $task )
|
130 |
{
|
@@ -169,6 +170,7 @@ abstract class Cron
|
|
169 |
* Get cron option name
|
170 |
*
|
171 |
* @return string
|
|
|
172 |
*/
|
173 |
public function getCronOptionName() {
|
174 |
return $this->cron_option_name;
|
@@ -242,14 +244,14 @@ abstract class Cron
|
|
242 |
if( is_callable( $this->tasks[$task]['handler'] ) ){
|
243 |
|
244 |
if( $this->debug ) {
|
245 |
-
error_log( var_export( 'Task ' . $task . ' will be run.',
|
246 |
}
|
247 |
|
248 |
$result = call_user_func_array( $this->tasks[$task]['handler'], isset( $this->tasks[$task]['params'] ) ? $this->tasks[$task]['params'] : array() );
|
249 |
|
250 |
if( $this->debug ) {
|
251 |
-
error_log( var_export( 'Result:',
|
252 |
-
error_log( var_export( $result,
|
253 |
}
|
254 |
|
255 |
if( empty( $result['error'] ) ){
|
125 |
* @param string $task
|
126 |
*
|
127 |
* @return bool
|
128 |
+
* @psalm-suppress PossiblyUnusedReturnValue
|
129 |
*/
|
130 |
public function removeTask( $task )
|
131 |
{
|
170 |
* Get cron option name
|
171 |
*
|
172 |
* @return string
|
173 |
+
* @psalm-suppress PossiblyUnusedMethod
|
174 |
*/
|
175 |
public function getCronOptionName() {
|
176 |
return $this->cron_option_name;
|
244 |
if( is_callable( $this->tasks[$task]['handler'] ) ){
|
245 |
|
246 |
if( $this->debug ) {
|
247 |
+
error_log( var_export( 'Task ' . $task . ' will be run.', true ) );
|
248 |
}
|
249 |
|
250 |
$result = call_user_func_array( $this->tasks[$task]['handler'], isset( $this->tasks[$task]['params'] ) ? $this->tasks[$task]['params'] : array() );
|
251 |
|
252 |
if( $this->debug ) {
|
253 |
+
error_log( var_export( 'Result:', true ) );
|
254 |
+
error_log( var_export( $result, true ) );
|
255 |
}
|
256 |
|
257 |
if( empty( $result['error'] ) ){
|
@@ -12,6 +12,9 @@ namespace Cleantalk\Common;
|
|
12 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
13 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
14 |
* @see https://github.com/CleanTalk/php-antispam
|
|
|
|
|
|
|
15 |
*/
|
16 |
|
17 |
class DB
|
@@ -25,7 +28,7 @@ class DB
|
|
25 |
private $query;
|
26 |
|
27 |
/**
|
28 |
-
* @var wpdb result
|
29 |
*/
|
30 |
private $db_result;
|
31 |
|
@@ -55,7 +58,7 @@ class DB
|
|
55 |
|
56 |
/**
|
57 |
* Alternative constructor.
|
58 |
-
*
|
59 |
* Set tables prefix.
|
60 |
*/
|
61 |
private function init(){ }
|
@@ -64,7 +67,8 @@ class DB
|
|
64 |
* Set $this->query string for next uses
|
65 |
*
|
66 |
* @param $query
|
67 |
-
* @return $this
|
|
|
68 |
*/
|
69 |
public function set_query($query){ }
|
70 |
|
@@ -75,15 +79,19 @@ class DB
|
|
75 |
* @param array $vars
|
76 |
*
|
77 |
* @return $this
|
|
|
78 |
*/
|
79 |
-
public function prepare($query, $vars = array()){
|
|
|
|
|
80 |
|
81 |
/**
|
82 |
* Run any raw request
|
83 |
*
|
84 |
* @param $query
|
85 |
*
|
86 |
-
* @return bool|int Raw result
|
|
|
87 |
*/
|
88 |
public function execute($query){ }
|
89 |
|
@@ -91,23 +99,25 @@ class DB
|
|
91 |
* Fetchs first column from query.
|
92 |
* May receive raw or prepared query.
|
93 |
*
|
94 |
-
* @param
|
95 |
-
* @param bool $response_type
|
96 |
*
|
97 |
* @return array|object|void|null
|
|
|
98 |
*/
|
99 |
-
public function fetch($query =
|
100 |
|
101 |
/**
|
102 |
* Fetchs all result from query.
|
103 |
* May receive raw or prepared query.
|
104 |
*
|
105 |
-
* @param
|
106 |
-
* @param bool $response_type
|
107 |
*
|
108 |
-
* @return array|object|null
|
|
|
109 |
*/
|
110 |
-
public function fetch_all($query =
|
111 |
|
112 |
/**
|
113 |
* Checks if the table exists
|
@@ -115,6 +125,7 @@ class DB
|
|
115 |
* @param $table_name
|
116 |
*
|
117 |
* @return bool
|
|
|
118 |
*/
|
119 |
public function isTableExists( $table_name ){
|
120 |
return (bool) $this->execute( 'SHOW TABLES LIKE "' . $table_name . '"' );
|
12 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
13 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
14 |
* @see https://github.com/CleanTalk/php-antispam
|
15 |
+
*
|
16 |
+
* @psalm-suppress UnusedProperty
|
17 |
+
* @psalm-suppress PossiblyUnusedProperty
|
18 |
*/
|
19 |
|
20 |
class DB
|
28 |
private $query;
|
29 |
|
30 |
/**
|
31 |
+
* @var \wpdb result
|
32 |
*/
|
33 |
private $db_result;
|
34 |
|
58 |
|
59 |
/**
|
60 |
* Alternative constructor.
|
61 |
+
* Initialize Database object and write it to property.
|
62 |
* Set tables prefix.
|
63 |
*/
|
64 |
private function init(){ }
|
67 |
* Set $this->query string for next uses
|
68 |
*
|
69 |
* @param $query
|
70 |
+
* @return $this|void
|
71 |
+
* @psalm-suppress PossiblyUnusedMethod
|
72 |
*/
|
73 |
public function set_query($query){ }
|
74 |
|
79 |
* @param array $vars
|
80 |
*
|
81 |
* @return $this
|
82 |
+
* @psalm-suppress PossiblyUnusedMethod
|
83 |
*/
|
84 |
+
public function prepare($query, $vars = array()){
|
85 |
+
return $this;
|
86 |
+
}
|
87 |
|
88 |
/**
|
89 |
* Run any raw request
|
90 |
*
|
91 |
* @param $query
|
92 |
*
|
93 |
+
* @return bool|int|void Raw result
|
94 |
+
* @psalm-suppress PossiblyUnusedParam
|
95 |
*/
|
96 |
public function execute($query){ }
|
97 |
|
99 |
* Fetchs first column from query.
|
100 |
* May receive raw or prepared query.
|
101 |
*
|
102 |
+
* @param string $query
|
103 |
+
* @param bool|string $response_type
|
104 |
*
|
105 |
* @return array|object|void|null
|
106 |
+
* @psalm-suppress PossiblyUnusedMethod
|
107 |
*/
|
108 |
+
public function fetch($query = '', $response_type = false){ }
|
109 |
|
110 |
/**
|
111 |
* Fetchs all result from query.
|
112 |
* May receive raw or prepared query.
|
113 |
*
|
114 |
+
* @param string $query
|
115 |
+
* @param bool|string $response_type
|
116 |
*
|
117 |
+
* @return array|object|null|void
|
118 |
+
* @psalm-suppress PossiblyUnusedMethod
|
119 |
*/
|
120 |
+
public function fetch_all($query = '', $response_type = false){ }
|
121 |
|
122 |
/**
|
123 |
* Checks if the table exists
|
125 |
* @param $table_name
|
126 |
*
|
127 |
* @return bool
|
128 |
+
* @psalm-suppress PossiblyUnusedMethod
|
129 |
*/
|
130 |
public function isTableExists( $table_name ){
|
131 |
return (bool) $this->execute( 'SHOW TABLES LIKE "' . $table_name . '"' );
|
@@ -18,6 +18,7 @@ class DNS {
|
|
18 |
* @param null|int $type DNS type name
|
19 |
*
|
20 |
* @return array
|
|
|
21 |
*/
|
22 |
public static function getRecord( $host, $return_first = false, $type = null ){
|
23 |
|
@@ -64,11 +65,12 @@ class DNS {
|
|
64 |
/**
|
65 |
* @param $servers
|
66 |
*
|
67 |
-
* @return null
|
|
|
68 |
*/
|
69 |
public static function findFastestServer( $servers ){
|
70 |
|
71 |
-
$tmp =
|
72 |
$fast_server_found = false;
|
73 |
|
74 |
foreach( $servers as $server ){
|
@@ -97,7 +99,7 @@ class DNS {
|
|
97 |
/**
|
98 |
* Function to check response time
|
99 |
* @param string URL
|
100 |
-
* @return int Response time
|
101 |
*/
|
102 |
public static function getResponseTime( $host ){
|
103 |
|
@@ -129,6 +131,7 @@ class DNS {
|
|
129 |
* @param $host
|
130 |
*
|
131 |
* @return int|false
|
|
|
132 |
*/
|
133 |
public static function getServerTTL( $host ){
|
134 |
|
@@ -136,5 +139,5 @@ class DNS {
|
|
136 |
|
137 |
return $server['ttl'];
|
138 |
}
|
139 |
-
|
140 |
}
|
18 |
* @param null|int $type DNS type name
|
19 |
*
|
20 |
* @return array
|
21 |
+
* @psalm-suppress NullableReturnStatement
|
22 |
*/
|
23 |
public static function getRecord( $host, $return_first = false, $type = null ){
|
24 |
|
65 |
/**
|
66 |
* @param $servers
|
67 |
*
|
68 |
+
* @return array|null
|
69 |
+
* @psalm-suppress PossiblyUnusedMethod
|
70 |
*/
|
71 |
public static function findFastestServer( $servers ){
|
72 |
|
73 |
+
$tmp = array();
|
74 |
$fast_server_found = false;
|
75 |
|
76 |
foreach( $servers as $server ){
|
99 |
/**
|
100 |
* Function to check response time
|
101 |
* @param string URL
|
102 |
+
* @return int|float Response time
|
103 |
*/
|
104 |
public static function getResponseTime( $host ){
|
105 |
|
131 |
* @param $host
|
132 |
*
|
133 |
* @return int|false
|
134 |
+
* @psalm-suppress PossiblyUnusedMethod
|
135 |
*/
|
136 |
public static function getServerTTL( $host ){
|
137 |
|
139 |
|
140 |
return $server['ttl'];
|
141 |
}
|
142 |
+
|
143 |
}
|
@@ -2,6 +2,8 @@
|
|
2 |
|
3 |
namespace Cleantalk\Common;
|
4 |
|
|
|
|
|
5 |
use Cleantalk\Common\Helper as Helper;
|
6 |
use Cleantalk\Variables\Get;
|
7 |
|
@@ -18,6 +20,8 @@ use Cleantalk\Variables\Get;
|
|
18 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
19 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
20 |
* @see https://github.com/CleanTalk/php-antispam
|
|
|
|
|
21 |
*/
|
22 |
class Firewall
|
23 |
{
|
@@ -49,8 +53,9 @@ class Firewall
|
|
49 |
);
|
50 |
|
51 |
private $fw_modules = array();
|
|
|
52 |
private $module_names = array();
|
53 |
-
|
54 |
/**
|
55 |
* Creates Database driver instance.
|
56 |
*
|
@@ -58,8 +63,8 @@ class Firewall
|
|
58 |
*/
|
59 |
public function __construct( $db ){
|
60 |
$this->db = $db;
|
61 |
-
$this->debug =
|
62 |
-
$this->ip_array = $this->ip__get(
|
63 |
}
|
64 |
|
65 |
/**
|
@@ -68,7 +73,7 @@ class Firewall
|
|
68 |
* @param string $ips_input type of IP you want to receive
|
69 |
* @param bool $v4_only
|
70 |
*
|
71 |
-
* @return array
|
72 |
*/
|
73 |
public function ip__get( $ips_input = 'real', $v4_only = true ){
|
74 |
|
@@ -83,9 +88,9 @@ class Firewall
|
|
83 |
* For inner usage only.
|
84 |
* Not returns anything, the result is private storage of the modules.
|
85 |
*
|
86 |
-
* @param
|
87 |
*/
|
88 |
-
public function load_fw_module(
|
89 |
|
90 |
if( ! in_array( $module, $this->fw_modules ) ) {
|
91 |
$module->setDb( $this->db );
|
@@ -102,7 +107,7 @@ class Firewall
|
|
102 |
* @return void returns die page or set cookies
|
103 |
*/
|
104 |
public function run() {
|
105 |
-
|
106 |
$this->module_names = array_keys( $this->fw_modules );
|
107 |
|
108 |
$results = array();
|
@@ -223,7 +228,7 @@ class Firewall
|
|
223 |
) {
|
224 |
if( ! headers_sent() ) {
|
225 |
$cookie_val = md5( $fw_result['ip'] . $apbct->api_key );
|
226 |
-
|
227 |
}
|
228 |
return true;
|
229 |
}
|
2 |
|
3 |
namespace Cleantalk\Common;
|
4 |
|
5 |
+
use Cleantalk\ApbctWP\Variables\Cookie;
|
6 |
+
use Cleantalk\Common\Firewall\FirewallModule;
|
7 |
use Cleantalk\Common\Helper as Helper;
|
8 |
use Cleantalk\Variables\Get;
|
9 |
|
20 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
21 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
22 |
* @see https://github.com/CleanTalk/php-antispam
|
23 |
+
*
|
24 |
+
* @psalm-suppress PossiblyUnusedProperty
|
25 |
*/
|
26 |
class Firewall
|
27 |
{
|
53 |
);
|
54 |
|
55 |
private $fw_modules = array();
|
56 |
+
|
57 |
private $module_names = array();
|
58 |
+
|
59 |
/**
|
60 |
* Creates Database driver instance.
|
61 |
*
|
63 |
*/
|
64 |
public function __construct( $db ){
|
65 |
$this->db = $db;
|
66 |
+
$this->debug = (bool) Get::get( 'debug' );
|
67 |
+
$this->ip_array = $this->ip__get();
|
68 |
}
|
69 |
|
70 |
/**
|
73 |
* @param string $ips_input type of IP you want to receive
|
74 |
* @param bool $v4_only
|
75 |
*
|
76 |
+
* @return array
|
77 |
*/
|
78 |
public function ip__get( $ips_input = 'real', $v4_only = true ){
|
79 |
|
88 |
* For inner usage only.
|
89 |
* Not returns anything, the result is private storage of the modules.
|
90 |
*
|
91 |
+
* @param FirewallModule $module
|
92 |
*/
|
93 |
+
public function load_fw_module( FirewallModule $module ) {
|
94 |
|
95 |
if( ! in_array( $module, $this->fw_modules ) ) {
|
96 |
$module->setDb( $this->db );
|
107 |
* @return void returns die page or set cookies
|
108 |
*/
|
109 |
public function run() {
|
110 |
+
|
111 |
$this->module_names = array_keys( $this->fw_modules );
|
112 |
|
113 |
$results = array();
|
228 |
) {
|
229 |
if( ! headers_sent() ) {
|
230 |
$cookie_val = md5( $fw_result['ip'] . $apbct->api_key );
|
231 |
+
Cookie::set( 'ct_sfw_ip_wl', $cookie_val, time() + 86400 * 30, '/', '', null, true, 'Lax' );
|
232 |
}
|
233 |
return true;
|
234 |
}
|
@@ -21,6 +21,7 @@ class FirewallModule extends FirewallModule_abstract {
|
|
21 |
* @param $log_table
|
22 |
* @param $data_table
|
23 |
* @param array $params
|
|
|
24 |
*/
|
25 |
public function __construct( $log_table, $data_table, $params = array() ){
|
26 |
|
@@ -32,11 +33,22 @@ class FirewallModule extends FirewallModule_abstract {
|
|
32 |
* Use this method to execute main logic of the module.
|
33 |
*
|
34 |
* @return array Array of the check results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
*/
|
36 |
-
public function check(){}
|
37 |
-
|
38 |
public function actions_for_denied( $result ){}
|
39 |
-
|
|
|
|
|
|
|
|
|
40 |
public function actions_for_passed( $result ){}
|
41 |
|
42 |
/**
|
@@ -52,25 +64,11 @@ class FirewallModule extends FirewallModule_abstract {
|
|
52 |
public function setIpArray( $ip_array ) {
|
53 |
$this->ip_array = $ip_array;
|
54 |
}
|
55 |
-
|
56 |
-
public function getIpArray() {
|
57 |
-
return $this->ip_array;
|
58 |
-
}
|
59 |
-
|
60 |
-
/**
|
61 |
-
* @param mixed $db__table__data
|
62 |
-
*/
|
63 |
-
public function setDbTableData( $db__table__data ) {
|
64 |
-
$this->db__table__data = $db__table__data;
|
65 |
-
}
|
66 |
-
|
67 |
/**
|
68 |
-
* @param
|
|
|
69 |
*/
|
70 |
-
public function setDbTableLogs( $db__table__logs ) {
|
71 |
-
$this->db__table__logs = $db__table__logs;
|
72 |
-
}
|
73 |
-
|
74 |
public function _die( $result ){
|
75 |
|
76 |
// Headers
|
21 |
* @param $log_table
|
22 |
* @param $data_table
|
23 |
* @param array $params
|
24 |
+
* @psalm-suppress PossiblyUnusedMethod
|
25 |
*/
|
26 |
public function __construct( $log_table, $data_table, $params = array() ){
|
27 |
|
33 |
* Use this method to execute main logic of the module.
|
34 |
*
|
35 |
* @return array Array of the check results
|
36 |
+
* @psalm-suppress PossiblyUnusedMethod
|
37 |
+
*/
|
38 |
+
public function check(){
|
39 |
+
return array();
|
40 |
+
}
|
41 |
+
|
42 |
+
/**
|
43 |
+
* @param $result
|
44 |
+
* @psalm-suppress PossiblyUnusedMethod
|
45 |
*/
|
|
|
|
|
46 |
public function actions_for_denied( $result ){}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @param $result
|
50 |
+
* @psalm-suppress PossiblyUnusedMethod
|
51 |
+
*/
|
52 |
public function actions_for_passed( $result ){}
|
53 |
|
54 |
/**
|
64 |
public function setIpArray( $ip_array ) {
|
65 |
$this->ip_array = $ip_array;
|
66 |
}
|
67 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
/**
|
69 |
+
* @param $result
|
70 |
+
* @psalm-suppress PossiblyUnusedMethod
|
71 |
*/
|
|
|
|
|
|
|
|
|
72 |
public function _die( $result ){
|
73 |
|
74 |
// Headers
|
@@ -2,7 +2,9 @@
|
|
2 |
|
3 |
namespace Cleantalk\Common\Firewall;
|
4 |
|
5 |
-
|
|
|
|
|
6 |
* The abstract class for any FireWall modules.
|
7 |
* Compatible with any CMS.
|
8 |
*
|
@@ -11,13 +13,16 @@ namespace Cleantalk\Common\Firewall;
|
|
11 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
12 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
13 |
* @since 2.49
|
|
|
|
|
|
|
14 |
*/
|
15 |
abstract class FirewallModule_abstract {
|
16 |
|
17 |
public $module_name;
|
18 |
|
19 |
/**
|
20 |
-
* @var
|
21 |
*/
|
22 |
protected $db;
|
23 |
protected $db__table__logs;
|
@@ -42,6 +47,7 @@ abstract class FirewallModule_abstract {
|
|
42 |
* @param $log_table
|
43 |
* @param $data_table
|
44 |
* @param array $params
|
|
|
45 |
*/
|
46 |
abstract public function __construct( $log_table, $data_table, $params = array() );
|
47 |
|
@@ -49,6 +55,7 @@ abstract class FirewallModule_abstract {
|
|
49 |
* Use this method to execute main logic of the module.
|
50 |
*
|
51 |
* @return array Array of the check results
|
|
|
52 |
*/
|
53 |
abstract public function check();
|
54 |
|
2 |
|
3 |
namespace Cleantalk\Common\Firewall;
|
4 |
|
5 |
+
use Cleantalk\ApbctWP\DB;
|
6 |
+
|
7 |
+
/**
|
8 |
* The abstract class for any FireWall modules.
|
9 |
* Compatible with any CMS.
|
10 |
*
|
13 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
14 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
15 |
* @since 2.49
|
16 |
+
* @package Cleantalk\Common\Firewall
|
17 |
+
*
|
18 |
+
* @psalm-suppress PossiblyUnusedProperty
|
19 |
*/
|
20 |
abstract class FirewallModule_abstract {
|
21 |
|
22 |
public $module_name;
|
23 |
|
24 |
/**
|
25 |
+
* @var DB
|
26 |
*/
|
27 |
protected $db;
|
28 |
protected $db__table__logs;
|
47 |
* @param $log_table
|
48 |
* @param $data_table
|
49 |
* @param array $params
|
50 |
+
* @psalm-suppress PossiblyUnusedMethod
|
51 |
*/
|
52 |
abstract public function __construct( $log_table, $data_table, $params = array() );
|
53 |
|
55 |
* Use this method to execute main logic of the module.
|
56 |
*
|
57 |
* @return array Array of the check results
|
58 |
+
* @psalm-suppress PossiblyUnusedMethod
|
59 |
*/
|
60 |
abstract public function check();
|
61 |
|
@@ -10,7 +10,7 @@ use Cleantalk\Variables\Server;
|
|
10 |
*
|
11 |
* @package PHP Antispam by CleanTalk
|
12 |
* @subpackage Helper
|
13 |
-
* @Version
|
14 |
* @author Cleantalk team (welcome@cleantalk.org)
|
15 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
16 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
@@ -21,7 +21,7 @@ class Helper
|
|
21 |
/**
|
22 |
* Default user agent for HTTP requests
|
23 |
*/
|
24 |
-
const AGENT = 'Cleantalk-Helper/
|
25 |
|
26 |
/**
|
27 |
* @var array Set of private networks IPv4 and IPv6
|
@@ -39,19 +39,6 @@ class Helper
|
|
39 |
'0:0:0:0:0:0:a:1/128', // ::ffff:127.0.0.1
|
40 |
),
|
41 |
);
|
42 |
-
|
43 |
-
public static $cleantalks_moderate_servers = array(
|
44 |
-
// MODERATE
|
45 |
-
'moderate1.cleantalk.org' => '162.243.144.175',
|
46 |
-
'moderate2.cleantalk.org' => '159.203.121.181',
|
47 |
-
'moderate3.cleantalk.org' => '88.198.153.60',
|
48 |
-
'moderate4.cleantalk.org' => '159.69.51.30',
|
49 |
-
'moderate5.cleantalk.org' => '95.216.200.119',
|
50 |
-
'moderate6.cleantalk.org' => '138.68.234.8',
|
51 |
-
// 'moderate7.cleantalk.org' => '168.119.82.149',
|
52 |
-
'moderate8.cleantalk.org' => '188.34.154.26',
|
53 |
-
'moderate9.cleantalk.org' => '51.81.55.251',
|
54 |
-
);
|
55 |
|
56 |
/**
|
57 |
* @var array Set of CleanTalk servers
|
@@ -64,7 +51,6 @@ class Helper
|
|
64 |
'moderate4.cleantalk.org' => '159.69.51.30',
|
65 |
'moderate5.cleantalk.org' => '95.216.200.119',
|
66 |
'moderate6.cleantalk.org' => '138.68.234.8',
|
67 |
-
// 'moderate7.cleantalk.org' => '168.119.82.149',
|
68 |
'moderate8.cleantalk.org' => '188.34.154.26',
|
69 |
'moderate9.cleantalk.org' => '51.81.55.251',
|
70 |
|
@@ -87,6 +73,9 @@ class Helper
|
|
87 |
* @param bool $v4_only
|
88 |
*
|
89 |
* @return string|null
|
|
|
|
|
|
|
90 |
*/
|
91 |
public static function ip__get( $ip_type_to_get = 'real', $v4_only = true, $headers = array() )
|
92 |
{
|
@@ -97,10 +86,19 @@ class Helper
|
|
97 |
// Cloud Flare
|
98 |
case 'cloud_flare':
|
99 |
$headers = $headers ?: self::http__get_headers();
|
100 |
-
if(
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
$ip_version = self::ip__validate( trim( $tmp[0] ) );
|
105 |
if( $ip_version ){
|
106 |
$out = $ip_version === 'v6' && ! $v4_only ? self::ip__v6_normalize( trim( $tmp[0] ) ) : trim( $tmp[0] );
|
@@ -250,15 +248,15 @@ class Helper
|
|
250 |
// Is private network
|
251 |
if(
|
252 |
! $out ||
|
253 |
-
($out &&
|
254 |
(
|
|
|
255 |
self::ip__is_private_network( $out, $ip_version ) ||
|
256 |
self::ip__mask_match(
|
257 |
$out,
|
258 |
Server::get( 'SERVER_ADDR' ) . '/24',
|
259 |
$ip_version
|
260 |
-
)
|
261 |
-
)
|
262 |
){
|
263 |
//@todo Remove local IP from x-forwarded-for and x-real-ip
|
264 |
$out = $out ?: self::ip__get( 'x_forwarded_for', $v4_only, $headers );
|
@@ -295,7 +293,7 @@ class Helper
|
|
295 |
*
|
296 |
* @return bool
|
297 |
*/
|
298 |
-
static function ip__is_private_network($ip, $ip_type = 'v4')
|
299 |
{
|
300 |
return self::ip__mask_match($ip, self::$private_networks[$ip_type], $ip_type);
|
301 |
}
|
@@ -306,11 +304,12 @@ class Helper
|
|
306 |
* Hextet by hextet for IPv6
|
307 |
*
|
308 |
* @param string $ip
|
309 |
-
* @param string $cidr work to compare with
|
310 |
* @param string $ip_type IPv6 or IPv4
|
311 |
* @param int $xtet_count Recursive counter. Determs current part of address to check.
|
312 |
*
|
313 |
* @return bool
|
|
|
314 |
*/
|
315 |
public static function ip__mask_match($ip, $cidr, $ip_type = 'v4', $xtet_count = 0)
|
316 |
{
|
@@ -321,7 +320,6 @@ class Helper
|
|
321 |
return true;
|
322 |
}
|
323 |
}
|
324 |
-
unset($curr_mask);
|
325 |
return false;
|
326 |
}
|
327 |
|
@@ -329,28 +327,29 @@ class Helper
|
|
329 |
return false;
|
330 |
}
|
331 |
|
332 |
-
$xtet_base = ($ip_type
|
333 |
|
334 |
// Calculate mask
|
335 |
$exploded = explode('/', $cidr);
|
336 |
$net_ip = $exploded[0];
|
337 |
-
$mask = $exploded[1];
|
338 |
|
339 |
// Exit condition
|
340 |
$xtet_end = ceil($mask / $xtet_base);
|
341 |
-
if($xtet_count == $xtet_end)
|
342 |
return true;
|
|
|
343 |
|
344 |
-
//
|
345 |
$mask = $mask - $xtet_base * $xtet_count >= $xtet_base ? $xtet_base : $mask - $xtet_base * $xtet_count;
|
346 |
|
347 |
// Explode by octets/hextets from IP and Net
|
348 |
-
$net_ip_xtets = explode($ip_type
|
349 |
-
$ip_xtets = explode($ip_type
|
350 |
|
351 |
// Standartizing. Getting current octets/hextets. Adding leading zeros.
|
352 |
-
$net_xtet = str_pad(decbin($ip_type
|
353 |
-
$ip_xtet = str_pad(decbin($ip_type
|
354 |
|
355 |
// Comparing bit by bit
|
356 |
for($i = 0, $result = true; $mask != 0; $mask--, $i++){
|
@@ -361,8 +360,9 @@ class Helper
|
|
361 |
}
|
362 |
|
363 |
// Recursing. Moving to next octet/hextet.
|
364 |
-
if($result)
|
365 |
-
$result = self::ip__mask_match($ip, $cidr, $ip_type, $xtet_count + 1);
|
|
|
366 |
|
367 |
return $result;
|
368 |
|
@@ -374,10 +374,11 @@ class Helper
|
|
374 |
* @param int $long_mask
|
375 |
*
|
376 |
* @return int
|
|
|
377 |
*/
|
378 |
-
static function ip__mask__long_to_number($long_mask)
|
379 |
{
|
380 |
-
$num_mask = strpos(
|
381 |
return $num_mask === false ? 32 : $num_mask;
|
382 |
}
|
383 |
|
@@ -390,9 +391,15 @@ class Helper
|
|
390 |
*/
|
391 |
public static function ip__validate($ip)
|
392 |
{
|
393 |
-
if(!$ip)
|
394 |
-
|
395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
return false; // Unknown
|
397 |
}
|
398 |
|
@@ -420,7 +427,7 @@ class Helper
|
|
420 |
$ip = trim($ip);
|
421 |
// Searching for ::ffff:xx.xx.xx.xx patterns and turn it to IPv6
|
422 |
if(preg_match('/^::ffff:([0-9]{1,3}\.?){4}$/', $ip)){
|
423 |
-
$ip = dechex(sprintf("%u", ip2long(substr($ip, 7))));
|
424 |
$ip = '0:0:0:0:0:0:' . (strlen($ip) > 4 ? substr('abcde', 0, -4) : '0') . ':' . substr($ip, -4, 4);
|
425 |
// Normalizing hextets number
|
426 |
}elseif(strpos($ip, '::') !== false){
|
@@ -448,7 +455,7 @@ class Helper
|
|
448 |
if(strpos($ip, ':') !== false){
|
449 |
$ip = preg_replace('/:0{1,4}/', ':', $ip);
|
450 |
$ip = preg_replace('/:{2,}/', '::', $ip);
|
451 |
-
$ip = strpos($ip, '0') === 0 ? substr($ip, 1) : $ip;
|
452 |
}
|
453 |
return $ip;
|
454 |
}
|
@@ -458,17 +465,17 @@ class Helper
|
|
458 |
*
|
459 |
* @param string $ip
|
460 |
*
|
461 |
-
* @return
|
|
|
462 |
*/
|
463 |
public static function ip__is_cleantalks($ip)
|
464 |
{
|
465 |
if(self::ip__validate($ip)){
|
466 |
$url = array_search($ip, self::$cleantalks_servers);
|
467 |
-
return $url
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
return false;
|
472 |
}
|
473 |
|
474 |
/**
|
@@ -476,17 +483,17 @@ class Helper
|
|
476 |
*
|
477 |
* @param $ip
|
478 |
*
|
479 |
-
* @return false|int|string
|
480 |
*/
|
481 |
public static function ip__resolve__cleantalks($ip)
|
482 |
{
|
483 |
if(self::ip__validate($ip)){
|
484 |
$url = array_search($ip, self::$cleantalks_servers);
|
485 |
return $url
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
}
|
491 |
|
492 |
/**
|
@@ -496,12 +503,13 @@ class Helper
|
|
496 |
*
|
497 |
* @return string
|
498 |
*/
|
499 |
-
static
|
500 |
{
|
501 |
if(self::ip__validate($ip)){
|
502 |
$url = gethostbyaddr($ip);
|
503 |
-
if($url)
|
504 |
return $url;
|
|
|
505 |
}
|
506 |
return $ip;
|
507 |
}
|
@@ -513,6 +521,7 @@ class Helper
|
|
513 |
* @param bool $out
|
514 |
*
|
515 |
* @return bool
|
|
|
516 |
*/
|
517 |
public static function dns__resolve($host, $out = false)
|
518 |
{
|
@@ -547,11 +556,11 @@ class Helper
|
|
547 |
* ssl - use SSL
|
548 |
*
|
549 |
* @param string $url URL
|
550 |
-
* @param array $data POST|GET indexed array with data to send
|
551 |
* @param string|array $presets String or Array with presets: get_code, async, get, ssl, dont_split_to_array
|
552 |
* @param array $opts Optional option for CURL connection
|
553 |
*
|
554 |
-
* @return array|bool (array || array('error' => true))
|
555 |
*/
|
556 |
public static function http__request($url, $data = array(), $presets = array(), $opts = array())
|
557 |
{
|
@@ -639,7 +648,7 @@ class Helper
|
|
639 |
|
640 |
if( $result !== false ){
|
641 |
|
642 |
-
if( strpos( $result, PHP_EOL ) !== false && ! in_array( 'dont_split_to_array', $presets ) ){
|
643 |
$result = explode( PHP_EOL, $result );
|
644 |
}
|
645 |
|
@@ -650,16 +659,18 @@ class Helper
|
|
650 |
}
|
651 |
curl_close($ch);
|
652 |
$out = $result;
|
653 |
-
}else
|
654 |
-
$out = array('error' => curl_error($ch));
|
655 |
-
|
656 |
-
|
|
|
|
|
657 |
|
658 |
/**
|
659 |
* Getting HTTP-response code without cURL
|
660 |
*/
|
661 |
if( in_array( 'get_code', $presets, true ) &&
|
662 |
-
isset( $out['error'] ) && $out['error']
|
663 |
){
|
664 |
$headers = get_headers($url);
|
665 |
$out = (int)preg_replace('/.*(\d{3}).*/', '$1', $headers[0]);
|
@@ -667,12 +678,80 @@ class Helper
|
|
667 |
|
668 |
return $out;
|
669 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
670 |
|
671 |
/**
|
672 |
-
* Merging arrays without
|
673 |
*
|
674 |
-
* @param array $arr1 One-
|
675 |
-
* @param array $arr2 One-
|
676 |
*
|
677 |
* @return array Merged array
|
678 |
*/
|
@@ -691,6 +770,7 @@ class Helper
|
|
691 |
* @param array $arr2 One-dimentional array
|
692 |
*
|
693 |
* @return array Merged array
|
|
|
694 |
*/
|
695 |
public static function array_merge__save_numeric_keys__recursive($arr1, $arr2)
|
696 |
{
|
@@ -729,43 +809,45 @@ class Helper
|
|
729 |
{
|
730 |
// Array || object
|
731 |
if(is_array($data) || is_object($data)){
|
732 |
-
foreach($data as $
|
733 |
$val = self::removeNonUTF8($val);
|
734 |
}
|
735 |
-
unset($
|
736 |
|
737 |
//String
|
738 |
}else{
|
739 |
-
if(!preg_match('//u', $data))
|
740 |
$data = 'Nulled. Not UTF8 encoded or malformed.';
|
|
|
741 |
}
|
742 |
return $data;
|
743 |
}
|
744 |
-
|
745 |
/**
|
746 |
* Function convert anything to UTF8 and removes non UTF8 characters
|
747 |
*
|
748 |
* @param array|object|string $obj
|
749 |
-
* @param string
|
750 |
*
|
751 |
-
* @return
|
752 |
*/
|
753 |
public static function toUTF8($obj, $data_codepage = null)
|
754 |
{
|
755 |
// Array || object
|
756 |
if(is_array($obj) || is_object($obj)){
|
757 |
-
foreach($obj as $
|
758 |
$val = self::toUTF8($val, $data_codepage);
|
759 |
}
|
760 |
-
unset($
|
761 |
|
762 |
//String
|
763 |
}else{
|
764 |
if(!preg_match('//u', $obj) && function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')){
|
765 |
$encoding = mb_detect_encoding($obj);
|
766 |
-
$encoding = $encoding
|
767 |
-
if($encoding)
|
768 |
-
$obj = mb_convert_encoding($obj, 'UTF-8', $encoding);
|
|
|
769 |
}
|
770 |
}
|
771 |
return $obj;
|
@@ -783,15 +865,16 @@ class Helper
|
|
783 |
{
|
784 |
// Array || object
|
785 |
if(is_array($obj) || is_object($obj)){
|
786 |
-
foreach($obj as $
|
787 |
$val = self::fromUTF8($val, $data_codepage);
|
788 |
}
|
789 |
-
unset($
|
790 |
|
791 |
//String
|
792 |
}else{
|
793 |
-
if(preg_match('u', $obj) && function_exists('mb_convert_encoding') && $data_codepage !== null)
|
794 |
-
$obj = mb_convert_encoding($obj, $data_codepage, 'UTF-8');
|
|
|
795 |
}
|
796 |
return $obj;
|
797 |
}
|
@@ -799,7 +882,7 @@ class Helper
|
|
799 |
/**
|
800 |
* Checks if the string is JSON type
|
801 |
*
|
802 |
-
* @param string
|
803 |
*
|
804 |
* @return bool
|
805 |
*/
|
@@ -807,7 +890,13 @@ class Helper
|
|
807 |
|
808 |
return is_string( $string ) && is_array( json_decode( $string, true ) );
|
809 |
}
|
810 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
811 |
public static function time__get_interval_start( $interval = 300 ){
|
812 |
return time() - ( ( time() - strtotime( date( 'd F Y' ) ) ) % $interval );
|
813 |
}
|
@@ -819,6 +908,7 @@ class Helper
|
|
819 |
* @param string $type Default mime type. Returns if we failed to detect type
|
820 |
*
|
821 |
* @return string
|
|
|
822 |
*/
|
823 |
public static function get_mime_type( $data, $type = '' )
|
824 |
{
|
@@ -842,7 +932,13 @@ class Helper
|
|
842 |
}
|
843 |
return $buffer;
|
844 |
}
|
845 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
846 |
public static function buffer__parse__csv( $buffer ){
|
847 |
$buffer = explode( "\n", $buffer );
|
848 |
$buffer = self::buffer__trim_and_clear_from_empty_lines( $buffer );
|
@@ -867,12 +963,13 @@ class Helper
|
|
867 |
}
|
868 |
|
869 |
/**
|
870 |
-
* Pops line from the csv buffer and
|
871 |
*
|
872 |
* @param $csv
|
873 |
* @param array $map
|
874 |
*
|
875 |
* @return array|false
|
|
|
876 |
*/
|
877 |
public static function buffer__csv__get_map( &$csv ){
|
878 |
$line = static::buffer__csv__pop_line( $csv );
|
@@ -880,47 +977,50 @@ class Helper
|
|
880 |
}
|
881 |
|
882 |
/**
|
883 |
-
* Pops line from the csv buffer and
|
884 |
*
|
885 |
* @param $csv
|
886 |
* @param array $map
|
887 |
*
|
888 |
* @return array|false
|
|
|
889 |
*/
|
890 |
public static function buffer__csv__pop_line_to_array( &$csv, $map = array() ){
|
891 |
$line = trim( static::buffer__csv__pop_line( $csv ) );
|
892 |
$line = strpos( $line, '\'' ) === 0
|
893 |
? str_getcsv($line, ',', '\'')
|
894 |
: explode( ',', $line );
|
895 |
-
if( $map )
|
896 |
$line = array_combine( $map, $line );
|
|
|
897 |
return $line;
|
898 |
}
|
899 |
|
900 |
/**
|
901 |
* Escapes MySQL params
|
902 |
*
|
903 |
-
* @param string|int $param
|
904 |
* @param string $quotes
|
905 |
*
|
906 |
-
* @return int|string
|
|
|
907 |
*/
|
908 |
public static function db__prepare_param($param, $quotes = '\'')
|
909 |
{
|
|
|
910 |
if(is_array($param)){
|
911 |
foreach($param as &$par){
|
912 |
$par = self::db__prepare_param($par);
|
913 |
-
}
|
914 |
}
|
915 |
switch(true){
|
916 |
case is_numeric($param):
|
917 |
-
$param =
|
918 |
break;
|
919 |
-
case is_string($param) && strtolower($param)
|
920 |
$param = 'NULL';
|
921 |
break;
|
922 |
case is_string($param):
|
923 |
-
global $wpdb;
|
924 |
$param = $quotes . $wpdb->_real_escape($param) . $quotes;
|
925 |
break;
|
926 |
}
|
@@ -942,10 +1042,10 @@ class Helper
|
|
942 |
if( 0 === stripos( $key, 'http_' ) ){
|
943 |
$server_key = preg_replace('/^http_/i', '', $key);
|
944 |
$key_parts = explode('_', $server_key);
|
945 |
-
if(
|
946 |
foreach($key_parts as $part_index => $part){
|
947 |
|
948 |
-
if( $
|
949 |
continue;
|
950 |
}
|
951 |
|
@@ -964,6 +1064,7 @@ class Helper
|
|
964 |
* Its own implementation of the native method long2ip()
|
965 |
*
|
966 |
* @return string
|
|
|
967 |
*/
|
968 |
public static function ip__long2ip( $ipl32 ) {
|
969 |
$ip[0] = ( $ipl32 >> 24 ) & 255;
|
@@ -973,4 +1074,15 @@ class Helper
|
|
973 |
|
974 |
return implode( '.', $ip );
|
975 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
976 |
}
|
10 |
*
|
11 |
* @package PHP Antispam by CleanTalk
|
12 |
* @subpackage Helper
|
13 |
+
* @Version 4.0
|
14 |
* @author Cleantalk team (welcome@cleantalk.org)
|
15 |
* @copyright (C) 2014 CleanTalk team (http://cleantalk.org)
|
16 |
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
|
21 |
/**
|
22 |
* Default user agent for HTTP requests
|
23 |
*/
|
24 |
+
const AGENT = 'Cleantalk-Helper/4.0';
|
25 |
|
26 |
/**
|
27 |
* @var array Set of private networks IPv4 and IPv6
|
39 |
'0:0:0:0:0:0:a:1/128', // ::ffff:127.0.0.1
|
40 |
),
|
41 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
/**
|
44 |
* @var array Set of CleanTalk servers
|
51 |
'moderate4.cleantalk.org' => '159.69.51.30',
|
52 |
'moderate5.cleantalk.org' => '95.216.200.119',
|
53 |
'moderate6.cleantalk.org' => '138.68.234.8',
|
|
|
54 |
'moderate8.cleantalk.org' => '188.34.154.26',
|
55 |
'moderate9.cleantalk.org' => '51.81.55.251',
|
56 |
|
73 |
* @param bool $v4_only
|
74 |
*
|
75 |
* @return string|null
|
76 |
+
*
|
77 |
+
* @psalm-suppress InvalidReturnStatement
|
78 |
+
* @psalm-suppress ComplexMethod
|
79 |
*/
|
80 |
public static function ip__get( $ip_type_to_get = 'real', $v4_only = true, $headers = array() )
|
81 |
{
|
86 |
// Cloud Flare
|
87 |
case 'cloud_flare':
|
88 |
$headers = $headers ?: self::http__get_headers();
|
89 |
+
if(
|
90 |
+
isset( $headers['Cf-Connecting-Ip'] ) &&
|
91 |
+
( isset( $headers['Cf-Ray'] ) || isset( $headers['X-Wpe-Request-Id'] ) ) &&
|
92 |
+
! isset( $headers['X-Gt-Clientip'] )
|
93 |
+
){
|
94 |
+
if( isset( $headers['Cf-Pseudo-Ipv4'], $headers['Cf-Pseudo-Ipv6'] ) ){
|
95 |
+
$source = $headers['Cf-Pseudo-Ipv6'];
|
96 |
+
}else{
|
97 |
+
$source = $headers['Cf-Connecting-Ip'];
|
98 |
+
}
|
99 |
+
$tmp = strpos( $source, ',' ) !== false
|
100 |
+
? explode( ',', $source )
|
101 |
+
: (array) $source;
|
102 |
$ip_version = self::ip__validate( trim( $tmp[0] ) );
|
103 |
if( $ip_version ){
|
104 |
$out = $ip_version === 'v6' && ! $v4_only ? self::ip__v6_normalize( trim( $tmp[0] ) ) : trim( $tmp[0] );
|
248 |
// Is private network
|
249 |
if(
|
250 |
! $out ||
|
|
|
251 |
(
|
252 |
+
is_string( $ip_version ) && (
|
253 |
self::ip__is_private_network( $out, $ip_version ) ||
|
254 |
self::ip__mask_match(
|
255 |
$out,
|
256 |
Server::get( 'SERVER_ADDR' ) . '/24',
|
257 |
$ip_version
|
258 |
+
) )
|
259 |
+
)
|
260 |
){
|
261 |
//@todo Remove local IP from x-forwarded-for and x-real-ip
|
262 |
$out = $out ?: self::ip__get( 'x_forwarded_for', $v4_only, $headers );
|
293 |
*
|
294 |
* @return bool
|
295 |
*/
|
296 |
+
public static function ip__is_private_network($ip, $ip_type = 'v4')
|
297 |
{
|
298 |
return self::ip__mask_match($ip, self::$private_networks[$ip_type], $ip_type);
|
299 |
}
|
304 |
* Hextet by hextet for IPv6
|
305 |
*
|
306 |
* @param string $ip
|
307 |
+
* @param string|array $cidr work to compare with
|
308 |
* @param string $ip_type IPv6 or IPv4
|
309 |
* @param int $xtet_count Recursive counter. Determs current part of address to check.
|
310 |
*
|
311 |
* @return bool
|
312 |
+
* @psalm-suppress InvalidScalarArgument
|
313 |
*/
|
314 |
public static function ip__mask_match($ip, $cidr, $ip_type = 'v4', $xtet_count = 0)
|
315 |
{
|
320 |
return true;
|
321 |
}
|
322 |
}
|
|
|
323 |
return false;
|
324 |
}
|
325 |
|
327 |
return false;
|
328 |
}
|
329 |
|
330 |
+
$xtet_base = ($ip_type === 'v4') ? 8 : 16;
|
331 |
|
332 |
// Calculate mask
|
333 |
$exploded = explode('/', $cidr);
|
334 |
$net_ip = $exploded[0];
|
335 |
+
$mask = (int) $exploded[1];
|
336 |
|
337 |
// Exit condition
|
338 |
$xtet_end = ceil($mask / $xtet_base);
|
339 |
+
if($xtet_count == $xtet_end) {
|
340 |
return true;
|
341 |
+
}
|
342 |
|
343 |
+
// Length of bits for comparison
|
344 |
$mask = $mask - $xtet_base * $xtet_count >= $xtet_base ? $xtet_base : $mask - $xtet_base * $xtet_count;
|
345 |
|
346 |
// Explode by octets/hextets from IP and Net
|
347 |
+
$net_ip_xtets = explode( $ip_type === 'v4' ? '.' : ':', $net_ip);
|
348 |
+
$ip_xtets = explode( $ip_type === 'v4' ? '.' : ':', $ip);
|
349 |
|
350 |
// Standartizing. Getting current octets/hextets. Adding leading zeros.
|
351 |
+
$net_xtet = str_pad(decbin( $ip_type === 'v4' ? $net_ip_xtets[$xtet_count] : @hexdec($net_ip_xtets[$xtet_count])), $xtet_base, 0, STR_PAD_LEFT);
|
352 |
+
$ip_xtet = str_pad(decbin( $ip_type === 'v4' ? $ip_xtets[$xtet_count] : @hexdec($ip_xtets[$xtet_count])), $xtet_base, 0, STR_PAD_LEFT);
|
353 |
|
354 |
// Comparing bit by bit
|
355 |
for($i = 0, $result = true; $mask != 0; $mask--, $i++){
|
360 |
}
|
361 |
|
362 |
// Recursing. Moving to next octet/hextet.
|
363 |
+
if($result) {
|
364 |
+
$result = self::ip__mask_match( $ip, $cidr, $ip_type, $xtet_count + 1 );
|
365 |
+
}
|
366 |
|
367 |
return $result;
|
368 |
|
374 |
* @param int $long_mask
|
375 |
*
|
376 |
* @return int
|
377 |
+
* @psalm-suppress PossiblyUnusedMethod
|
378 |
*/
|
379 |
+
public static function ip__mask__long_to_number($long_mask)
|
380 |
{
|
381 |
+
$num_mask = strpos( decbin($long_mask), '0');
|
382 |
return $num_mask === false ? 32 : $num_mask;
|
383 |
}
|
384 |
|
391 |
*/
|
392 |
public static function ip__validate($ip)
|
393 |
{
|
394 |
+
if(!$ip) { // NULL || FALSE || '' || so on...
|
395 |
+
return false;
|
396 |
+
}
|
397 |
+
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && $ip != '0.0.0.0') { // IPv4
|
398 |
+
return 'v4';
|
399 |
+
}
|
400 |
+
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) && self::ip__v6_reduce($ip) != '0::0') { // IPv6
|
401 |
+
return 'v6';
|
402 |
+
}
|
403 |
return false; // Unknown
|
404 |
}
|
405 |
|
427 |
$ip = trim($ip);
|
428 |
// Searching for ::ffff:xx.xx.xx.xx patterns and turn it to IPv6
|
429 |
if(preg_match('/^::ffff:([0-9]{1,3}\.?){4}$/', $ip)){
|
430 |
+
$ip = dechex((int)sprintf("%u", ip2long(substr($ip, 7))));
|
431 |
$ip = '0:0:0:0:0:0:' . (strlen($ip) > 4 ? substr('abcde', 0, -4) : '0') . ':' . substr($ip, -4, 4);
|
432 |
// Normalizing hextets number
|
433 |
}elseif(strpos($ip, '::') !== false){
|
455 |
if(strpos($ip, ':') !== false){
|
456 |
$ip = preg_replace('/:0{1,4}/', ':', $ip);
|
457 |
$ip = preg_replace('/:{2,}/', '::', $ip);
|
458 |
+
$ip = strpos($ip, '0') === 0 && substr($ip, 1) !== false ? substr($ip, 1) : $ip;
|
459 |
}
|
460 |
return $ip;
|
461 |
}
|
465 |
*
|
466 |
* @param string $ip
|
467 |
*
|
468 |
+
* @return bool
|
469 |
+
* @psalm-suppress PossiblyUnusedMethod
|
470 |
*/
|
471 |
public static function ip__is_cleantalks($ip)
|
472 |
{
|
473 |
if(self::ip__validate($ip)){
|
474 |
$url = array_search($ip, self::$cleantalks_servers);
|
475 |
+
return (bool) $url;
|
476 |
+
}
|
477 |
+
|
478 |
+
return false;
|
|
|
479 |
}
|
480 |
|
481 |
/**
|
483 |
*
|
484 |
* @param $ip
|
485 |
*
|
486 |
+
* @return false|int|string|bool
|
487 |
*/
|
488 |
public static function ip__resolve__cleantalks($ip)
|
489 |
{
|
490 |
if(self::ip__validate($ip)){
|
491 |
$url = array_search($ip, self::$cleantalks_servers);
|
492 |
return $url
|
493 |
+
?: self::ip__resolve($ip);
|
494 |
+
}
|
495 |
+
|
496 |
+
return $ip;
|
497 |
}
|
498 |
|
499 |
/**
|
503 |
*
|
504 |
* @return string
|
505 |
*/
|
506 |
+
public static function ip__resolve($ip)
|
507 |
{
|
508 |
if(self::ip__validate($ip)){
|
509 |
$url = gethostbyaddr($ip);
|
510 |
+
if($url) {
|
511 |
return $url;
|
512 |
+
}
|
513 |
}
|
514 |
return $ip;
|
515 |
}
|
521 |
* @param bool $out
|
522 |
*
|
523 |
* @return bool
|
524 |
+
* @psalm-suppress PossiblyUnusedMethod
|
525 |
*/
|
526 |
public static function dns__resolve($host, $out = false)
|
527 |
{
|
556 |
* ssl - use SSL
|
557 |
*
|
558 |
* @param string $url URL
|
559 |
+
* @param array|string|int $data POST|GET indexed array with data to send
|
560 |
* @param string|array $presets String or Array with presets: get_code, async, get, ssl, dont_split_to_array
|
561 |
* @param array $opts Optional option for CURL connection
|
562 |
*
|
563 |
+
* @return array|bool|string (array || array('error' => true))
|
564 |
*/
|
565 |
public static function http__request($url, $data = array(), $presets = array(), $opts = array())
|
566 |
{
|
648 |
|
649 |
if( $result !== false ){
|
650 |
|
651 |
+
if( is_string( $result ) && strpos( $result, PHP_EOL ) !== false && ! in_array( 'dont_split_to_array', $presets ) ){
|
652 |
$result = explode( PHP_EOL, $result );
|
653 |
}
|
654 |
|
659 |
}
|
660 |
curl_close($ch);
|
661 |
$out = $result;
|
662 |
+
}else {
|
663 |
+
$out = array( 'error' => curl_error( $ch ) );
|
664 |
+
}
|
665 |
+
}else {
|
666 |
+
$out = array( 'error' => 'CURL_NOT_INSTALLED' );
|
667 |
+
}
|
668 |
|
669 |
/**
|
670 |
* Getting HTTP-response code without cURL
|
671 |
*/
|
672 |
if( in_array( 'get_code', $presets, true ) &&
|
673 |
+
isset( $out['error'] ) && $out['error'] === 'CURL_NOT_INSTALLED'
|
674 |
){
|
675 |
$headers = get_headers($url);
|
676 |
$out = (int)preg_replace('/.*(\d{3}).*/', '$1', $headers[0]);
|
678 |
|
679 |
return $out;
|
680 |
}
|
681 |
+
|
682 |
+
/**
|
683 |
+
* Do multi curl requests.
|
684 |
+
*
|
685 |
+
* @param array $urls Array of URLs to requests
|
686 |
+
* @param string $write_to Path to the writing files dir
|
687 |
+
*
|
688 |
+
* @return array
|
689 |
+
* @psalm-suppress PossiblyUnusedMethod
|
690 |
+
*/
|
691 |
+
public static function http__multi_request( $urls, $write_to = '' )
|
692 |
+
{
|
693 |
+
if( ! is_array( $urls ) || empty( $urls ) ) {
|
694 |
+
return array( 'error' => 'CURL_MULTI: Parameter is not an array.' );
|
695 |
+
}
|
696 |
+
|
697 |
+
foreach( $urls as $url ) {
|
698 |
+
if( ! is_string( $url ) ) {
|
699 |
+
return array( 'error' => 'CURL_MULTI: Parameter elements must be strings.' );
|
700 |
+
}
|
701 |
+
}
|
702 |
+
|
703 |
+
$urls_count = count( $urls );
|
704 |
+
$curl_arr = array();
|
705 |
+
$master = curl_multi_init();
|
706 |
+
|
707 |
+
for($i = 0; $i < $urls_count; $i++)
|
708 |
+
{
|
709 |
+
$url =$urls[$i];
|
710 |
+
$curl_arr[$i] = curl_init($url);
|
711 |
+
$opts = array(
|
712 |
+
CURLOPT_RETURNTRANSFER => true,
|
713 |
+
CURLOPT_CONNECTTIMEOUT_MS => 10000,
|
714 |
+
CURLOPT_FORBID_REUSE => true,
|
715 |
+
CURLOPT_USERAGENT => self::AGENT . '; ' . ( isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : 'UNKNOWN_HOST' ),
|
716 |
+
CURLOPT_HTTPHEADER => array('Expect:'), // Fix for large data and old servers http://php.net/manual/ru/function.curl-setopt.php#82418
|
717 |
+
CURLOPT_FOLLOWLOCATION => true,
|
718 |
+
CURLOPT_MAXREDIRS => 5,
|
719 |
+
);
|
720 |
+
curl_setopt_array($curl_arr[$i], $opts);
|
721 |
+
curl_multi_add_handle($master, $curl_arr[$i]);
|
722 |
+
}
|
723 |
+
|
724 |
+
do {
|
725 |
+
curl_multi_exec($master,$running);
|
726 |
+
// @ToDo place here sleep(500) to avoid possible CPU overusing
|
727 |
+
} while($running > 0);
|
728 |
+
|
729 |
+
$results = array();
|
730 |
+
|
731 |
+
for($i = 0; $i < $urls_count; $i++)
|
732 |
+
{
|
733 |
+
$info = curl_getinfo($curl_arr[$i], CURLINFO_HTTP_CODE);
|
734 |
+
if( 200 == $info ) {
|
735 |
+
if( ! empty( $write_to ) && is_dir( $write_to ) && is_writable( $write_to ) ) {
|
736 |
+
// @ToDo have to handle writing errors
|
737 |
+
file_put_contents( $write_to . self::getFilenameFromUrl( $urls[$i] ), curl_multi_getcontent( $curl_arr[$i] ) );
|
738 |
+
$results[] = 'success';
|
739 |
+
} else {
|
740 |
+
$results[] = curl_multi_getcontent( $curl_arr[$i] );
|
741 |
+
}
|
742 |
+
|
743 |
+
} else {
|
744 |
+
$results[] = 'error';
|
745 |
+
}
|
746 |
+
}
|
747 |
+
return $results;
|
748 |
+
}
|
749 |
|
750 |
/**
|
751 |
+
* Merging arrays without resetting numeric keys
|
752 |
*
|
753 |
+
* @param array $arr1 One-dimensional array
|
754 |
+
* @param array $arr2 One-dimensional array
|
755 |
*
|
756 |
* @return array Merged array
|
757 |
*/
|
770 |
* @param array $arr2 One-dimentional array
|
771 |
*
|
772 |
* @return array Merged array
|
773 |
+
* @psalm-suppress PossiblyUnusedMethod
|
774 |
*/
|
775 |
public static function array_merge__save_numeric_keys__recursive($arr1, $arr2)
|
776 |
{
|
809 |
{
|
810 |
// Array || object
|
811 |
if(is_array($data) || is_object($data)){
|
812 |
+
foreach($data as $_key => &$val){
|
813 |
$val = self::removeNonUTF8($val);
|
814 |
}
|
815 |
+
unset($val);
|
816 |
|
817 |
//String
|
818 |
}else{
|
819 |
+
if(!preg_match('//u', $data)) {
|
820 |
$data = 'Nulled. Not UTF8 encoded or malformed.';
|
821 |
+
}
|
822 |
}
|
823 |
return $data;
|
824 |
}
|
825 |
+
|
826 |
/**
|
827 |
* Function convert anything to UTF8 and removes non UTF8 characters
|
828 |
*
|
829 |
* @param array|object|string $obj
|
830 |
+
* @param null|string $data_codepage
|
831 |
*
|
832 |
+
* @return array|false|mixed|string|string[]|null
|
833 |
*/
|
834 |
public static function toUTF8($obj, $data_codepage = null)
|
835 |
{
|
836 |
// Array || object
|
837 |
if(is_array($obj) || is_object($obj)){
|
838 |
+
foreach($obj as $_key => &$val){
|
839 |
$val = self::toUTF8($val, $data_codepage);
|
840 |
}
|
841 |
+
unset($val);
|
842 |
|
843 |
//String
|
844 |
}else{
|
845 |
if(!preg_match('//u', $obj) && function_exists('mb_detect_encoding') && function_exists('mb_convert_encoding')){
|
846 |
$encoding = mb_detect_encoding($obj);
|
847 |
+
$encoding = $encoding ?: $data_codepage;
|
848 |
+
if($encoding) {
|
849 |
+
$obj = mb_convert_encoding( $obj, 'UTF-8', $encoding );
|
850 |
+
}
|
851 |
}
|
852 |
}
|
853 |
return $obj;
|
865 |
{
|
866 |
// Array || object
|
867 |
if(is_array($obj) || is_object($obj)){
|
868 |
+
foreach($obj as $_key => &$val){
|
869 |
$val = self::fromUTF8($val, $data_codepage);
|
870 |
}
|
871 |
+
unset($val);
|
872 |
|
873 |
//String
|
874 |
}else{
|
875 |
+
if(preg_match('u', $obj) && function_exists('mb_convert_encoding') && $data_codepage !== null) {
|
876 |
+
$obj = mb_convert_encoding( $obj, $data_codepage, 'UTF-8' );
|
877 |
+
}
|
878 |
}
|
879 |
return $obj;
|
880 |
}
|
882 |
/**
|
883 |
* Checks if the string is JSON type
|
884 |
*
|
885 |
+
* @param string $string
|
886 |
*
|
887 |
* @return bool
|
888 |
*/
|
890 |
|
891 |
return is_string( $string ) && is_array( json_decode( $string, true ) );
|
892 |
}
|
893 |
+
|
894 |
+
/**
|
895 |
+
* @param int $interval
|
896 |
+
*
|
897 |
+
* @return int
|
898 |
+
* @psalm-suppress PossiblyUnusedMethod
|
899 |
+
*/
|
900 |
public static function time__get_interval_start( $interval = 300 ){
|
901 |
return time() - ( ( time() - strtotime( date( 'd F Y' ) ) ) % $interval );
|
902 |
}
|
908 |
* @param string $type Default mime type. Returns if we failed to detect type
|
909 |
*
|
910 |
* @return string
|
911 |
+
* @psalm-suppress PossiblyUnusedMethod
|
912 |
*/
|
913 |
public static function get_mime_type( $data, $type = '' )
|
914 |
{
|
932 |
}
|
933 |
return $buffer;
|
934 |
}
|
935 |
+
|
936 |
+
/**
|
937 |
+
* @param $buffer
|
938 |
+
*
|
939 |
+
* @return array
|
940 |
+
* @psalm-suppress PossiblyUnusedMethod
|
941 |
+
*/
|
942 |
public static function buffer__parse__csv( $buffer ){
|
943 |
$buffer = explode( "\n", $buffer );
|
944 |
$buffer = self::buffer__trim_and_clear_from_empty_lines( $buffer );
|
963 |
}
|
964 |
|
965 |
/**
|
966 |
+
* Pops line from the csv buffer and format it by map to array
|
967 |
*
|
968 |
* @param $csv
|
969 |
* @param array $map
|
970 |
*
|
971 |
* @return array|false
|
972 |
+
* @psalm-suppress PossiblyUnusedMethod
|
973 |
*/
|
974 |
public static function buffer__csv__get_map( &$csv ){
|
975 |
$line = static::buffer__csv__pop_line( $csv );
|
977 |
}
|
978 |
|
979 |
/**
|
980 |
+
* Pops line from the csv buffer and format it by map to array
|
981 |
*
|
982 |
* @param $csv
|
983 |
* @param array $map
|
984 |
*
|
985 |
* @return array|false
|
986 |
+
* @psalm-suppress PossiblyUnusedMethod
|
987 |
*/
|
988 |
public static function buffer__csv__pop_line_to_array( &$csv, $map = array() ){
|
989 |
$line = trim( static::buffer__csv__pop_line( $csv ) );
|
990 |
$line = strpos( $line, '\'' ) === 0
|
991 |
? str_getcsv($line, ',', '\'')
|
992 |
: explode( ',', $line );
|
993 |
+
if( $map ) {
|
994 |
$line = array_combine( $map, $line );
|
995 |
+
}
|
996 |
return $line;
|
997 |
}
|
998 |
|
999 |
/**
|
1000 |
* Escapes MySQL params
|
1001 |
*
|
1002 |
+
* @param string|int|array $param
|
1003 |
* @param string $quotes
|
1004 |
*
|
1005 |
+
* @return int|string|array
|
1006 |
+
* @psalm-suppress PossiblyUnusedMethod
|
1007 |
*/
|
1008 |
public static function db__prepare_param($param, $quotes = '\'')
|
1009 |
{
|
1010 |
+
global $wpdb;
|
1011 |
if(is_array($param)){
|
1012 |
foreach($param as &$par){
|
1013 |
$par = self::db__prepare_param($par);
|
1014 |
+
}unset($par);
|
1015 |
}
|
1016 |
switch(true){
|
1017 |
case is_numeric($param):
|
1018 |
+
$param = (int) $param;
|
1019 |
break;
|
1020 |
+
case is_string($param) && strtolower($param) === 'null':
|
1021 |
$param = 'NULL';
|
1022 |
break;
|
1023 |
case is_string($param):
|
|
|
1024 |
$param = $quotes . $wpdb->_real_escape($param) . $quotes;
|
1025 |
break;
|
1026 |
}
|
1042 |
if( 0 === stripos( $key, 'http_' ) ){
|
1043 |
$server_key = preg_replace('/^http_/i', '', $key);
|
1044 |
$key_parts = explode('_', $server_key);
|
1045 |
+
if(strlen($server_key) > 2){
|
1046 |
foreach($key_parts as $part_index => $part){
|
1047 |
|
1048 |
+
if( $part === '' ){
|
1049 |
continue;
|
1050 |
}
|
1051 |
|
1064 |
* Its own implementation of the native method long2ip()
|
1065 |
*
|
1066 |
* @return string
|
1067 |
+
* @psalm-suppress PossiblyUnusedMethod
|
1068 |
*/
|
1069 |
public static function ip__long2ip( $ipl32 ) {
|
1070 |
$ip[0] = ( $ipl32 >> 24 ) & 255;
|
1074 |
|
1075 |
return implode( '.', $ip );
|
1076 |
}
|
1077 |
+
|
1078 |
+
/**
|
1079 |
+
* @param $url string
|
1080 |
+
*
|
1081 |
+
* @return string
|
1082 |
+
*/
|
1083 |
+
private static function getFilenameFromUrl( $url )
|
1084 |
+
{
|
1085 |
+
$array = explode( '/', $url );
|
1086 |
+
return end( $array );
|
1087 |
+
}
|
1088 |
}
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
|
4 |
+
namespace Cleantalk\Common;
|
5 |
+
|
6 |
+
|
7 |
+
abstract class Queue {
|
8 |
+
|
9 |
+
const QUEUE_NAME = 'sfw_update_queue';
|
10 |
+
|
11 |
+
public $queue;
|
12 |
+
|
13 |
+
function __construct()
|
14 |
+
{
|
15 |
+
$queue = $this->getQueue();
|
16 |
+
if( $queue !== false && isset( $queue['stages'] ) ) {
|
17 |
+
$this->queue = $queue;
|
18 |
+
} else {
|
19 |
+
$this->queue = array(
|
20 |
+
'started' => time(),
|
21 |
+
'finished' => '',
|
22 |
+
'stages' => array(),
|
23 |
+
);
|
24 |
+
}
|
25 |
+
}
|
26 |
+
|
27 |
+
abstract function getQueue();
|
28 |
+
|
29 |
+
abstract static function clearQueue();
|
30 |
+
|
31 |
+
abstract function saveQueue( $queue );
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @param string $stage_name
|
35 |
+
*/
|
36 |
+
public function addStage( $stage_name, $args = array() )
|
37 |
+
{
|
38 |
+
$this->queue['stages'][] = array(
|
39 |
+
'name' => $stage_name,
|
40 |
+
'status' => 'NULL',
|
41 |
+
'tries' => '0',
|
42 |
+
'args' => $args
|
43 |
+
);
|
44 |
+
$this->saveQueue( $this->queue );
|
45 |
+
}
|
46 |
+
|
47 |
+
public function executeStage()
|
48 |
+
{
|
49 |
+
if( count( $this->queue['stages'] ) > 0 ) {
|
50 |
+
foreach ( $this->queue['stages'] as & $stage ) {
|
51 |
+
if( ( $stage['status'] === 'NULL' ) ) {
|
52 |
+
|
53 |
+
$stage['status'] = 'IN_PROGRESS';
|
54 |
+
|
55 |
+
if( is_callable( $stage['name'] ) ) {
|
56 |
+
|
57 |
+
++$stage['tries'];
|
58 |
+
|
59 |
+
if( ! empty( $stage['args'] ) ) {
|
60 |
+
$result = $stage['name']( $stage['args'] );
|
61 |
+
} else {
|
62 |
+
$result = $stage['name']();
|
63 |
+
}
|
64 |
+
|
65 |
+
if( isset( $result['error'] ) ) {
|
66 |
+
$stage['status'] = 'NULL';
|
67 |
+
if( isset( $result['update_args']['args'] ) ) {
|
68 |
+
$stage['args'] = $result['update_args']['args'];
|
69 |
+
}
|
70 |
+
$this->saveQueue( $this->queue );
|
71 |
+
if( $stage['tries'] >= 3 ) {
|
72 |
+
$stage['status'] = 'FINISHED';
|
73 |
+
$stage['error'] = $result['error'];
|
74 |
+
$this->saveQueue( $this->queue );
|
75 |
+
return $result;
|
76 |
+
}
|
77 |
+
return \Cleantalk\ApbctWP\Helper::http__request__rc_to_host(
|
78 |
+
'sfw_update__worker',
|
79 |
+
array( 'stage' => 'Repeat ' . $stage['name'] ),
|
80 |
+
array( 'async' )
|
81 |
+
);
|
82 |
+
}
|
83 |
+
|
84 |
+
if( isset( $result['next_stage'] ) ) {
|
85 |
+
$this->addStage(
|
86 |
+
$result['next_stage']['name'],
|
87 |
+
isset( $result['next_stage']['args'] ) ? $result['next_stage']['args'] : array()
|
88 |
+
);
|
89 |
+
}
|
90 |
+
|
91 |
+
if( isset( $result['next_stages'] ) && count( $result['next_stages'] ) ) {
|
92 |
+
foreach( $result['next_stages'] as $next_stage ) {
|
93 |
+
$this->addStage(
|
94 |
+
$next_stage['name'],
|
95 |
+
isset( $next_stage['args'] ) ? $next_stage['args'] : array()
|
96 |
+
);
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
$stage['status'] = 'FINISHED';
|
101 |
+
$this->saveQueue( $this->queue );
|
102 |
+
|
103 |
+
return $result;
|
104 |
+
|
105 |
+
}
|
106 |
+
|
107 |
+
return array( 'error' => $stage['name'] . ' is not a callable function.' );
|
108 |
+
|
109 |
+
}
|
110 |
+
} unset( $stage );
|
111 |
+
}
|
112 |
+
}
|
113 |
+
|
114 |
+
public function isQueueInProgress()
|
115 |
+
{
|
116 |
+
if( count( $this->queue['stages'] ) > 0 ) {
|
117 |
+
foreach ( $this->queue['stages'] as $stage ) {
|
118 |
+
if( $stage['status'] === 'FINISHED' ) {
|
119 |
+
continue;
|
120 |
+
}
|
121 |
+
return true;
|
122 |
+
}
|
123 |
+
}
|
124 |
+
return false;
|
125 |
+
}
|
126 |
+
|
127 |
+
public function isQueueFinished()
|
128 |
+
{
|
129 |
+
if( count( $this->queue['stages'] ) > 0 ) {
|
130 |
+
foreach ( $this->queue['stages'] as $stage ) {
|
131 |
+
if( $stage['status'] !== 'FINISHED' ) {
|
132 |
+
return false;
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
return true;
|
137 |
+
}
|
138 |
+
|
139 |
+
}
|
@@ -2,6 +2,8 @@
|
|
2 |
|
3 |
namespace Cleantalk\Common;
|
4 |
|
|
|
|
|
5 |
class Schema
|
6 |
{
|
7 |
/**
|
@@ -67,7 +69,7 @@ class Schema
|
|
67 |
/**
|
68 |
* @param null|string $table Name of called table
|
69 |
* @return array Array of schemas
|
70 |
-
* @throws
|
71 |
*/
|
72 |
public static function getSchema( $table = null )
|
73 |
{
|
@@ -79,7 +81,7 @@ class Schema
|
|
79 |
return array( self::$schemas[$table] );
|
80 |
}
|
81 |
|
82 |
-
throw new
|
83 |
}
|
84 |
|
85 |
}
|
2 |
|
3 |
namespace Cleantalk\Common;
|
4 |
|
5 |
+
use Exception;
|
6 |
+
|
7 |
class Schema
|
8 |
{
|
9 |
/**
|
69 |
/**
|
70 |
* @param null|string $table Name of called table
|
71 |
* @return array Array of schemas
|
72 |
+
* @throws Exception Throws if calling un-existed schema
|
73 |
*/
|
74 |
public static function getSchema( $table = null )
|
75 |
{
|
81 |
return array( self::$schemas[$table] );
|
82 |
}
|
83 |
|
84 |
+
throw new Exception( 'Called table scheme not exist.' );
|
85 |
}
|
86 |
|
87 |
}
|
@@ -2,11 +2,11 @@
|
|
2 |
|
3 |
namespace Cleantalk\Templates;
|
4 |
|
5 |
-
if(!trait_exists('Cleantalk\Templates\Singleton')) {
|
6 |
|
7 |
trait Singleton{
|
8 |
|
9 |
-
static $instance;
|
10 |
|
11 |
public function __construct(){}
|
12 |
public function __wakeup(){}
|
2 |
|
3 |
namespace Cleantalk\Templates;
|
4 |
|
5 |
+
if( ! trait_exists( 'Cleantalk\Templates\Singleton' ) ) {
|
6 |
|
7 |
trait Singleton{
|
8 |
|
9 |
+
public static $instance;
|
10 |
|
11 |
public function __construct(){}
|
12 |
public function __wakeup(){}
|
@@ -12,7 +12,7 @@ namespace Cleantalk\Variables;
|
|
12 |
*/
|
13 |
class Cookie extends ServerVariables{
|
14 |
|
15 |
-
static $instance;
|
16 |
|
17 |
/**
|
18 |
* Constructor
|
@@ -27,7 +27,7 @@ class Cookie extends ServerVariables{
|
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
-
* Gets given $_COOKIE variable and
|
31 |
* @param $name
|
32 |
*
|
33 |
* @return mixed|string
|
@@ -35,19 +35,23 @@ class Cookie extends ServerVariables{
|
|
35 |
protected function get_variable( $name ){
|
36 |
|
37 |
// Return from memory. From $this->variables
|
38 |
-
if(isset(static::$instance->variables[$name]))
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
|
53 |
/**
|
@@ -60,14 +64,15 @@ class Cookie extends ServerVariables{
|
|
60 |
* @param string $value Cookie value
|
61 |
* @param int $expires Expiration timestamp. 0 - expiration with session
|
62 |
* @param string $path
|
63 |
-
* @param
|
64 |
* @param bool $secure
|
65 |
* @param bool $httponly
|
66 |
* @param string $samesite
|
67 |
*
|
68 |
* @return void
|
|
|
69 |
*/
|
70 |
-
public static function set
|
71 |
|
72 |
$secure = ! is_null( $secure ) ? $secure : Server::get('HTTPS') !== 'off' || Server::get('SERVER_PORT') == 443;
|
73 |
|
12 |
*/
|
13 |
class Cookie extends ServerVariables{
|
14 |
|
15 |
+
public static $instance;
|
16 |
|
17 |
/**
|
18 |
* Constructor
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
+
* Gets given $_COOKIE variable and save it to memory
|
31 |
* @param $name
|
32 |
*
|
33 |
* @return mixed|string
|
35 |
protected function get_variable( $name ){
|
36 |
|
37 |
// Return from memory. From $this->variables
|
38 |
+
if( ! isset( static::$instance->variables[ $name ] ) ) {
|
39 |
+
if ( function_exists( 'filter_input' ) ) {
|
40 |
+
$value = filter_input( INPUT_COOKIE, $name );
|
41 |
+
}
|
42 |
+
|
43 |
+
if ( empty( $value ) ) {
|
44 |
+
$value = isset( $_COOKIE[ $name ] ) ? $_COOKIE[ $name ] : '';
|
45 |
+
}
|
46 |
+
|
47 |
+
// Remember for further calls
|
48 |
+
static::getInstance()->remember_variable( $name, $value );
|
49 |
+
|
50 |
+
return $value;
|
51 |
+
}
|
52 |
+
|
53 |
+
return static::$instance->variables[ $name ];
|
54 |
+
|
55 |
}
|
56 |
|
57 |
/**
|
64 |
* @param string $value Cookie value
|
65 |
* @param int $expires Expiration timestamp. 0 - expiration with session
|
66 |
* @param string $path
|
67 |
+
* @param string $domain
|
68 |
* @param bool $secure
|
69 |
* @param bool $httponly
|
70 |
* @param string $samesite
|
71 |
*
|
72 |
* @return void
|
73 |
+
* @psalm-suppress PossiblyUnusedMethod
|
74 |
*/
|
75 |
+
public static function set( $name, $value = '', $expires = 0, $path = '', $domain = '', $secure = null, $httponly = false, $samesite = 'Lax' ) {
|
76 |
|
77 |
$secure = ! is_null( $secure ) ? $secure : Server::get('HTTPS') !== 'off' || Server::get('SERVER_PORT') == 443;
|
78 |
|
@@ -12,7 +12,7 @@ namespace Cleantalk\Variables;
|
|
12 |
*/
|
13 |
class Get extends ServerVariables{
|
14 |
|
15 |
-
static $instance;
|
16 |
|
17 |
/**
|
18 |
* Constructor
|
@@ -27,7 +27,7 @@ class Get extends ServerVariables{
|
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
-
* Gets given $_GET variable and
|
31 |
* @param $name
|
32 |
*
|
33 |
* @return mixed|string
|
@@ -35,18 +35,22 @@ class Get extends ServerVariables{
|
|
35 |
protected function get_variable( $name ){
|
36 |
|
37 |
// Return from memory. From $this->variables
|
38 |
-
if(isset(static::$instance->variables[$name]))
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
}
|
12 |
*/
|
13 |
class Get extends ServerVariables{
|
14 |
|
15 |
+
public static $instance;
|
16 |
|
17 |
/**
|
18 |
* Constructor
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
+
* Gets given $_GET variable and save it to memory
|
31 |
* @param $name
|
32 |
*
|
33 |
* @return mixed|string
|
35 |
protected function get_variable( $name ){
|
36 |
|
37 |
// Return from memory. From $this->variables
|
38 |
+
if( ! isset( static::$instance->variables[ $name ] ) ) {
|
39 |
+
if ( function_exists( 'filter_input' ) ) {
|
40 |
+
$value = filter_input( INPUT_GET, $name );
|
41 |
+
}
|
42 |
+
|
43 |
+
if ( empty( $value ) ) {
|
44 |
+
$value = isset( $_GET[ $name ] ) ? $_GET[ $name ] : '';
|
45 |
+
}
|
46 |
+
|
47 |
+
// Remember for further calls
|
48 |
+
static::getInstance()->remember_variable( $name, $value );
|
49 |
+
|
50 |
+
return $value;
|
51 |
+
}
|
52 |
+
|
53 |
+
return static::$instance->variables[ $name ];
|
54 |
+
|
55 |
}
|
56 |
}
|
@@ -13,7 +13,7 @@ namespace Cleantalk\Variables;
|
|
13 |
*/
|
14 |
class Post extends ServerVariables{
|
15 |
|
16 |
-
static $instance;
|
17 |
|
18 |
/**
|
19 |
* Constructor
|
@@ -28,7 +28,7 @@ class Post extends ServerVariables{
|
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
-
* Gets given $_POST variable and
|
32 |
* @param $name
|
33 |
*
|
34 |
* @return mixed|string
|
@@ -36,18 +36,22 @@ class Post extends ServerVariables{
|
|
36 |
protected function get_variable( $name ){
|
37 |
|
38 |
// Return from memory. From $this->variables
|
39 |
-
if(isset(static::$instance->variables[$name]))
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
52 |
}
|
53 |
}
|
13 |
*/
|
14 |
class Post extends ServerVariables{
|
15 |
|
16 |
+
public static $instance;
|
17 |
|
18 |
/**
|
19 |
* Constructor
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
+
* Gets given $_POST variable and save it to memory
|
32 |
* @param $name
|
33 |
*
|
34 |
* @return mixed|string
|
36 |
protected function get_variable( $name ){
|
37 |
|
38 |
// Return from memory. From $this->variables
|
39 |
+
if( ! isset( static::$instance->variables[ $name ] ) ) {
|
40 |
+
if ( function_exists( 'filter_input' ) ) {
|
41 |
+
$value = filter_input( INPUT_POST, $name );
|
42 |
+
}
|
43 |
+
|
44 |
+
if ( empty( $value ) ) {
|
45 |
+
$value = isset( $_POST[ $name ] ) ? $_POST[ $name ] : '';
|
46 |
+
}
|
47 |
+
|
48 |
+
// Remember for further calls
|
49 |
+
static::getInstance()->remember_variable( $name, $value );
|
50 |
+
|
51 |
+
return $value;
|
52 |
+
}
|
53 |
+
|
54 |
+
return static::$instance->variables[ $name ];
|
55 |
+
|
56 |
}
|
57 |
}
|
@@ -12,7 +12,7 @@ namespace Cleantalk\Variables;
|
|
12 |
*/
|
13 |
class Request extends ServerVariables{
|
14 |
|
15 |
-
static $instance;
|
16 |
|
17 |
/**
|
18 |
* Constructor
|
@@ -27,7 +27,7 @@ class Request extends ServerVariables{
|
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
-
* Gets given $_REQUEST variable and
|
31 |
* @param $name
|
32 |
*
|
33 |
* @return mixed|string
|
@@ -35,12 +35,13 @@ class Request extends ServerVariables{
|
|
35 |
protected function get_variable( $name ){
|
36 |
|
37 |
// Return from memory. From $this->variables
|
38 |
-
if(isset(static::$instance->variables[$name]))
|
39 |
-
return static::$instance->variables[$name];
|
|
|
40 |
|
41 |
$value = isset( $_REQUEST[ $name ] ) ? $_REQUEST[ $name ] : '';
|
42 |
|
43 |
-
// Remember for
|
44 |
static::getInstance()->remember_variable( $name, $value );
|
45 |
|
46 |
return $value;
|
12 |
*/
|
13 |
class Request extends ServerVariables{
|
14 |
|
15 |
+
public static $instance;
|
16 |
|
17 |
/**
|
18 |
* Constructor
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
+
* Gets given $_REQUEST variable and save it to memory
|
31 |
* @param $name
|
32 |
*
|
33 |
* @return mixed|string
|
35 |
protected function get_variable( $name ){
|
36 |
|
37 |
// Return from memory. From $this->variables
|
38 |
+
if(isset(static::$instance->variables[$name])) {
|
39 |
+
return static::$instance->variables[ $name ];
|
40 |
+
}
|
41 |
|
42 |
$value = isset( $_REQUEST[ $name ] ) ? $_REQUEST[ $name ] : '';
|
43 |
|
44 |
+
// Remember for further calls
|
45 |
static::getInstance()->remember_variable( $name, $value );
|
46 |
|
47 |
return $value;
|
@@ -12,7 +12,7 @@ namespace Cleantalk\Variables;
|
|
12 |
*/
|
13 |
class Server extends ServerVariables {
|
14 |
|
15 |
-
static $instance;
|
16 |
|
17 |
/**
|
18 |
* Gets given $_SERVER variable and save it to memory
|
@@ -29,21 +29,25 @@ class Server extends ServerVariables {
|
|
29 |
|
30 |
$name = strtoupper( $name );
|
31 |
|
32 |
-
if( function_exists( 'filter_input' ) )
|
33 |
$value = filter_input( INPUT_SERVER, $name );
|
|
|
34 |
|
35 |
-
if( empty( $value ) )
|
36 |
-
$value = isset( $_SERVER[ $name ] ) ? $_SERVER[ $name ]
|
|
|
37 |
|
38 |
// Convert to upper case for REQUEST_METHOD
|
39 |
-
if(
|
40 |
$value = strtoupper( $value );
|
|
|
41 |
|
42 |
// Convert HTML chars for HTTP_USER_AGENT, HTTP_USER_AGENT, SERVER_NAME
|
43 |
-
if( in_array( $name, array( 'HTTP_USER_AGENT', 'HTTP_USER_AGENT', 'SERVER_NAME' ) ) )
|
44 |
$value = htmlspecialchars( $value );
|
|
|
45 |
|
46 |
-
// Remember for
|
47 |
static::getInstance()->remember_variable( $name, $value );
|
48 |
|
49 |
return $value;
|
@@ -55,15 +59,30 @@ class Server extends ServerVariables {
|
|
55 |
* @param string $needle
|
56 |
*
|
57 |
* @return bool
|
|
|
58 |
*/
|
59 |
public static function in_uri( $needle ){
|
60 |
return self::has_string( 'REQUEST_URI', $needle );
|
61 |
}
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
public static function in_host( $needle ){
|
64 |
return self::has_string( 'HTTP_HOST', $needle );
|
65 |
}
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
public static function get_domain(){
|
68 |
preg_match( '@\.(\S+)\/?$@', self::get( 'HTTP_HOST' ), $matches );
|
69 |
return isset( $matches[1] ) ? $matches[1] : false;
|
@@ -75,6 +94,7 @@ class Server extends ServerVariables {
|
|
75 |
* @param string $needle needle
|
76 |
*
|
77 |
* @return bool
|
|
|
78 |
*/
|
79 |
public static function in_referer( $needle ){
|
80 |
return self::has_string( 'HTTP_REFERER', $needle );
|
@@ -84,6 +104,7 @@ class Server extends ServerVariables {
|
|
84 |
* Checks if the current request method is POST
|
85 |
*
|
86 |
* @return bool
|
|
|
87 |
*/
|
88 |
public static function isPost(){
|
89 |
return self::get( 'REQUEST_METHOD' ) === 'POST';
|
@@ -93,6 +114,7 @@ class Server extends ServerVariables {
|
|
93 |
* Checks if the current request method is GET
|
94 |
*
|
95 |
* @return bool
|
|
|
96 |
*/
|
97 |
public static function isGet(){
|
98 |
return self::get( 'REQUEST_METHOD' ) === 'GET';
|
12 |
*/
|
13 |
class Server extends ServerVariables {
|
14 |
|
15 |
+
public static $instance;
|
16 |
|
17 |
/**
|
18 |
* Gets given $_SERVER variable and save it to memory
|
29 |
|
30 |
$name = strtoupper( $name );
|
31 |
|
32 |
+
if( function_exists( 'filter_input' ) ) {
|
33 |
$value = filter_input( INPUT_SERVER, $name );
|
34 |
+
}
|
35 |
|
36 |
+
if( empty( $value ) || ($name === 'REMOTE_ADDR' && $value === '127.0.0.1')) {
|
37 |
+
$value = isset( $_SERVER[ $name ] ) ? $_SERVER[ $name ] : '';
|
38 |
+
}
|
39 |
|
40 |
// Convert to upper case for REQUEST_METHOD
|
41 |
+
if( $name === 'REQUEST_METHOD' ) {
|
42 |
$value = strtoupper( $value );
|
43 |
+
}
|
44 |
|
45 |
// Convert HTML chars for HTTP_USER_AGENT, HTTP_USER_AGENT, SERVER_NAME
|
46 |
+
if( in_array( $name, array( 'HTTP_USER_AGENT', 'HTTP_USER_AGENT', 'SERVER_NAME' ) ) ) {
|
47 |
$value = htmlspecialchars( $value );
|
48 |
+
}
|
49 |
|
50 |
+
// Remember for further calls
|
51 |
static::getInstance()->remember_variable( $name, $value );
|
52 |
|
53 |
return $value;
|
59 |
* @param string $needle
|
60 |
*
|
61 |
* @return bool
|
62 |
+
* @psalm-suppress PossiblyUnusedMethod
|
63 |
*/
|
64 |
public static function in_uri( $needle ){
|
65 |
return self::has_string( 'REQUEST_URI', $needle );
|
66 |
}
|
67 |
|
68 |
+
/**
|
69 |
+
* Is the host contains the string
|
70 |
+
*
|
71 |
+
* @param string $needle
|
72 |
+
*
|
73 |
+
* @return bool
|
74 |
+
* @psalm-suppress PossiblyUnusedMethod
|
75 |
+
*/
|
76 |
public static function in_host( $needle ){
|
77 |
return self::has_string( 'HTTP_HOST', $needle );
|
78 |
}
|
79 |
|
80 |
+
/**
|
81 |
+
* Getting domain name
|
82 |
+
*
|
83 |
+
* @return false|string
|
84 |
+
* @psalm-suppress PossiblyUnusedMethod
|
85 |
+
*/
|
86 |
public static function get_domain(){
|
87 |
preg_match( '@\.(\S+)\/?$@', self::get( 'HTTP_HOST' ), $matches );
|
88 |
return isset( $matches[1] ) ? $matches[1] : false;
|
94 |
* @param string $needle needle
|
95 |
*
|
96 |
* @return bool
|
97 |
+
* @psalm-suppress PossiblyUnusedMethod
|
98 |
*/
|
99 |
public static function in_referer( $needle ){
|
100 |
return self::has_string( 'HTTP_REFERER', $needle );
|
104 |
* Checks if the current request method is POST
|
105 |
*
|
106 |
* @return bool
|
107 |
+
* @psalm-suppress PossiblyUnusedMethod
|
108 |
*/
|
109 |
public static function isPost(){
|
110 |
return self::get( 'REQUEST_METHOD' ) === 'POST';
|
114 |
* Checks if the current request method is GET
|
115 |
*
|
116 |
* @return bool
|
117 |
+
* @psalm-suppress PossiblyUnusedMethod
|
118 |
*/
|
119 |
public static function isGet(){
|
120 |
return self::get( 'REQUEST_METHOD' ) === 'GET';
|
@@ -2,6 +2,8 @@
|
|
2 |
|
3 |
namespace Cleantalk\Variables;
|
4 |
|
|
|
|
|
5 |
/**
|
6 |
* Class ServerVariables
|
7 |
* Safety handler for ${_SOMETHING}
|
@@ -9,22 +11,23 @@ namespace Cleantalk\Variables;
|
|
9 |
* @usage \Cleantalk\Variables\{SOMETHING}::get( $name );
|
10 |
*
|
11 |
* @package Cleantalk\Variables
|
|
|
12 |
*/
|
13 |
-
class ServerVariables{
|
14 |
|
15 |
-
use
|
16 |
|
17 |
/**
|
18 |
* @var array Contains saved variables
|
19 |
*/
|
20 |
-
public $variables =
|
21 |
|
22 |
/**
|
23 |
* Gets variable from ${_SOMETHING}
|
24 |
*
|
25 |
* @param string $name Variable name
|
26 |
*
|
27 |
-
* @return string
|
28 |
*/
|
29 |
public static function get( $name ){
|
30 |
return static::getInstance()->get_variable( $name );
|
@@ -32,14 +35,12 @@ class ServerVariables{
|
|
32 |
|
33 |
/**
|
34 |
* BLUEPRINT
|
35 |
-
* Gets given ${_SOMETHING} variable and
|
36 |
* @param $name
|
37 |
*
|
38 |
* @return mixed|string
|
39 |
*/
|
40 |
-
protected function get_variable( $name )
|
41 |
-
return true;
|
42 |
-
}
|
43 |
|
44 |
/**
|
45 |
* Save variable to $this->variables[]
|
@@ -57,9 +58,9 @@ class ServerVariables{
|
|
57 |
* @param string $var Haystack to search in
|
58 |
* @param string $string Needle to search
|
59 |
*
|
60 |
-
* @return bool
|
61 |
*/
|
62 |
-
static function has_string( $var, $string ){
|
63 |
return stripos( self::get( $var ), $string ) !== false;
|
64 |
}
|
65 |
|
@@ -69,9 +70,10 @@ class ServerVariables{
|
|
69 |
* @param string $var Variable to compare
|
70 |
* @param string $param Param to compare
|
71 |
*
|
72 |
-
* @return bool
|
|
|
73 |
*/
|
74 |
-
static function equal( $var, $param ){
|
75 |
-
return self::get( $var )
|
76 |
}
|
77 |
}
|
2 |
|
3 |
namespace Cleantalk\Variables;
|
4 |
|
5 |
+
use Cleantalk\Templates\Singleton;
|
6 |
+
|
7 |
/**
|
8 |
* Class ServerVariables
|
9 |
* Safety handler for ${_SOMETHING}
|
11 |
* @usage \Cleantalk\Variables\{SOMETHING}::get( $name );
|
12 |
*
|
13 |
* @package Cleantalk\Variables
|
14 |
+
* @psalm-suppress PossiblyUnusedProperty
|
15 |
*/
|
16 |
+
abstract class ServerVariables{
|
17 |
|
18 |
+
use Singleton;
|
19 |
|
20 |
/**
|
21 |
* @var array Contains saved variables
|
22 |
*/
|
23 |
+
public $variables = array();
|
24 |
|
25 |
/**
|
26 |
* Gets variable from ${_SOMETHING}
|
27 |
*
|
28 |
* @param string $name Variable name
|
29 |
*
|
30 |
+
* @return string|array
|
31 |
*/
|
32 |
public static function get( $name ){
|
33 |
return static::getInstance()->get_variable( $name );
|
35 |
|
36 |
/**
|
37 |
* BLUEPRINT
|
38 |
+
* Gets given ${_SOMETHING} variable and save it to memory
|
39 |
* @param $name
|
40 |
*
|
41 |
* @return mixed|string
|
42 |
*/
|
43 |
+
abstract protected function get_variable( $name );
|
|
|
|
|
44 |
|
45 |
/**
|
46 |
* Save variable to $this->variables[]
|
58 |
* @param string $var Haystack to search in
|
59 |
* @param string $string Needle to search
|
60 |
*
|
61 |
+
* @return bool
|
62 |
*/
|
63 |
+
public static function has_string( $var, $string ){
|
64 |
return stripos( self::get( $var ), $string ) !== false;
|
65 |
}
|
66 |
|
70 |
* @param string $var Variable to compare
|
71 |
* @param string $param Param to compare
|
72 |
*
|
73 |
+
* @return bool
|
74 |
+
* @psalm-suppress PossiblyUnusedMethod
|
75 |
*/
|
76 |
+
public static function equal( $var, $param ){
|
77 |
+
return self::get( $var ) === $param;
|
78 |
}
|
79 |
}
|
@@ -12,7 +12,7 @@ if( !function_exists('apache_request_headers') ){
|
|
12 |
if(preg_match('/\AHTTP_/', $key)){
|
13 |
$server_key = preg_replace('/\AHTTP_/', '', $key);
|
14 |
$key_parts = explode('_', $server_key);
|
15 |
-
if(
|
16 |
foreach($key_parts as $part_index => $part){
|
17 |
$key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part);
|
18 |
$key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
|
@@ -31,7 +31,7 @@ if( !function_exists('apache_request_headers') ){
|
|
31 |
* For old PHP versions
|
32 |
*/
|
33 |
if( !function_exists('locale_get_display_region') ){
|
34 |
-
function locale_get_display_region($locale, $
|
35 |
|
36 |
return 'Unkonwn' . ($locale ? ': ' . $locale : '');
|
37 |
}
|
12 |
if(preg_match('/\AHTTP_/', $key)){
|
13 |
$server_key = preg_replace('/\AHTTP_/', '', $key);
|
14 |
$key_parts = explode('_', $server_key);
|
15 |
+
if(strlen($server_key) > 2){
|
16 |
foreach($key_parts as $part_index => $part){
|
17 |
$key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part);
|
18 |
$key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
|
31 |
* For old PHP versions
|
32 |
*/
|
33 |
if( !function_exists('locale_get_display_region') ){
|
34 |
+
function locale_get_display_region($locale, $_in_locale = 'EN'){
|
35 |
|
36 |
return 'Unkonwn' . ($locale ? ': ' . $locale : '');
|
37 |
}
|
@@ -4,7 +4,7 @@ Tags: spam, antispam, anti-spam, comments, firewall
|
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 5.8
|
6 |
Requires PHP: 5.6
|
7 |
-
Stable tag: 5.
|
8 |
License: GPLv2
|
9 |
|
10 |
Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
|
@@ -573,6 +573,41 @@ If your website has forms that send data to external sources, you can enable opt
|
|
573 |
|
574 |
== Changelog ==
|
575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
576 |
= 5.159.9 Jul 15 2021 =
|
577 |
* Fix. SFW. Updating cooldown increased up to 15 min.
|
578 |
* Fix. Cron. Next call time set by task updating fixed.
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 5.8
|
6 |
Requires PHP: 5.6
|
7 |
+
Stable tag: 5.160
|
8 |
License: GPLv2
|
9 |
|
10 |
Spam protection, anti-spam, firewall, premium plugin. No spam comments & users, no spam contact form & WooCommerce anti-spam.
|
573 |
|
574 |
== Changelog ==
|
575 |
|
576 |
+
= 5.160 Jul 29 2021 =
|
577 |
+
* New: SFW. SFW alternative cookie implemented.
|
578 |
+
* New: SFW. AC alternative cookie implemented.
|
579 |
+
* New: SFW. AF alternative cookie implemented.
|
580 |
+
* New: Helper. Curl multi wrapper added.
|
581 |
+
* New: Queue class implemented.
|
582 |
+
* Mod: Changed the processing of the honeypot_field for standard comment.
|
583 |
+
* Mod: Added integration for Wishlist Members registration form.
|
584 |
+
* Mod: Store visited URLs amount reduces to 5 with 128 symbols by URL.
|
585 |
+
* Upd: Public js scripts separated.
|
586 |
+
* Upd: SFW. Updating process modified.
|
587 |
+
* Fix: Moderate rotating fixed.
|
588 |
+
* Fix: SFW. Process file errors handling fixed.
|
589 |
+
* Fix: Pluggable. Expression fixed.
|
590 |
+
* Fix: Ajax. User detection fixed..
|
591 |
+
* Fix: Ajax. Ajax handlers fixed.
|
592 |
+
* Fix: IP-detection for Cloudflare CDN.
|
593 |
+
* Fix: Skip test for ajax alt_session request.
|
594 |
+
* Fix: Set cookies on dashboard pages even if the setting is off.
|
595 |
+
* Fix: Ajax. Ajax class fixed.
|
596 |
+
* Fix: Users scanner. Remove redundant menu.
|
597 |
+
* Fix: Added an exception for the action edd_process_checkout Easy Didgital Downloads plugi
|
598 |
+
* Fix: SFW. Changed method for getting addr ip.
|
599 |
+
* Fix: Integration. WPForms names gathering fixed.
|
600 |
+
* Fix: SFW. Min update interval decreased to 14400 seconds.
|
601 |
+
* Fix: Integration. WPForms names gathering fixed.
|
602 |
+
* Fix: Cleantalk.php. dns_get_record() error handling.
|
603 |
+
* Fix: Search form integration. PHP Notice.
|
604 |
+
* Fix: Default value for "Alternative Cookie Type" setting.
|
605 |
+
* Fix: SpamFirewall. Omit SFW_IS_DISABLED error.
|
606 |
+
* Fix: SpamFirewall. Updating percent output.
|
607 |
+
* Fix. Settings templates. Sync after template loading.
|
608 |
+
* Fix. SFW. Updating process percents fixed.
|
609 |
+
* Fix. Antispam. All headers parameter fixed.
|
610 |
+
|
611 |
= 5.159.9 Jul 15 2021 =
|
612 |
* Fix. SFW. Updating cooldown increased up to 15 min.
|
613 |
* Fix. Cron. Next call time set by task updating fixed.
|