Skip to content

Commit e4d07bf

Browse files
Merge pull request #666 from CleanTalk/beta
beta
2 parents 6c58ba4 + 37d8e55 commit e4d07bf

47 files changed

Lines changed: 2177 additions & 1076 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525
},
2626
rules: {
2727
'indent': ['error', 4],
28-
'max-len': ['error', {'code': 120}],
28+
'max-len': 'off',
2929
'prefer-const': 'off',
3030
'no-invalid-this': 'off',
3131
'require-jsdoc': 'off',

inc/spbc-admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ function spbc_admin_init()
140140
add_action('wp_ajax_spbc_settings__get_recommendation', 'spbc_settings__get_recommendation');
141141
add_action('wp_ajax_spbc_settings__check_renew_banner', 'spbc_settings__check_renew_banner');
142142
add_action('wp_ajax_spbc_get_key_auto', 'spbc_get_key_auto');
143+
add_action('wp_ajax_spbc_save_key', 'spbc_save_key');
143144
add_action('wp_ajax_spbc_update_account_email', 'spbc_settings__update_account_email');
144145
add_action('wp_ajax_spbc_create_support_user', 'spbc_settings__spbc_create_support_user');
145146

inc/spbc-settings.php

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ function spbc_field_options_overview_traffic_light()
14571457

14581458
/**
14591459
* Admin callback function - Displays field of Api Key
1460+
* @ToDo unused code?
14601461
*/
14611462
function spbc_field_key()
14621463
{
@@ -4264,14 +4265,15 @@ function spbc_get_key_auto($direct_call = false)
42644265
$wpms = SPBC_WPMS && defined('SUBDOMAIN_INSTALL') && ! SUBDOMAIN_INSTALL;
42654266
$white_label = false;
42664267
$hoster_api_key = $spbc->ms__hoster_api_key;
4267-
$admin_email = spbc_get_admin_email();
4268+
$admin_email = Post::getString('email') ? Post::getString('email') : spbc_get_admin_email();
42684269

42694270
/**
42704271
* Filters the email to get API key
42714272
*
42724273
* @param string email to get API key
42734274
*/
42744275
$filtered_admin_email = apply_filters('spbc_get_api_key_email', $admin_email);
4276+
$filtered_admin_email = filter_var($filtered_admin_email, FILTER_VALIDATE_EMAIL);
42754277

42764278
$result = API::method__get_api_key(
42774279
'security',
@@ -4291,38 +4293,30 @@ function spbc_get_key_auto($direct_call = false)
42914293
$spbc->error_add('get_key', $result);
42924294

42934295
$out = array(
4294-
'success' => true,
4295-
'reload' => false,
4296-
'msg' => $result['error']
4296+
'success' => false,
4297+
'msg' => isset($result['error_message'])
4298+
? esc_html($result['error_message'])
4299+
: $result['error']
42974300
);
42984301
} elseif (isset($result['error_no']) && $result['error_no'] == '403') {
42994302
$out = array(
4300-
'success' => true,
4301-
'reload' => false,
4302-
'error' => isset($result['error_message']) ? esc_html($result['error_message']) : esc_html('Our service is not available in your region.'),
4303+
'success' => false,
4304+
'error' => isset($result['error_message'])
4305+
? esc_html($result['error_message'])
4306+
: esc_html('Our service is not available in your region.'),
43034307
);
43044308
} elseif ( ! isset($result['auth_key'])) {
43054309
$out = array(
4306-
'success' => true,
4307-
'reload' => false,
4310+
'success' => false,
43084311
'msg' => sprintf(
43094312
__('Please, get the Access Key from %s CleanTalk Control Panel %s and insert it in the Access Key field', 'cleantalk-spam-protect'),
43104313
'<a href="https://cleantalk.org/my/?cp_mode=security" target="_blank">',
43114314
'</a>'
43124315
)
43134316
);
43144317
} else {
4315-
$settings['spbc_key'] = trim($result['auth_key']);
4316-
$settings['spbc_key'] = preg_match('/^[a-z\d]*$/', $settings['spbc_key']) ? $settings['spbc_key'] : $spbc->settings['spbc_key']; // Check key format a-z\d
4317-
$settings['spbc_key'] = is_main_site() || $spbc->ms__work_mode != 2 ? $settings['spbc_key'] : $spbc->network_settings['spbc_key'];
4318-
4319-
$spbc->settings['spbc_key'] = $settings['spbc_key'];
4320-
$spbc->save('settings');
4321-
4322-
$spbc->data['user_token'] = (! empty($result['user_token']) ? $result['user_token'] : '');
4323-
$spbc->data['key_is_ok'] = spbc_api_key__is_correct($settings['spbc_key']);
4324-
$spbc->data['key_changed'] = true;
4325-
$spbc->save('data');
4318+
$user_token = ! empty($result['user_token']) ? $result['user_token'] : '';
4319+
spbc_save_key($result['auth_key'], $user_token, true);
43264320

43274321
$templates = \CleantalkSP\SpbctWP\CleantalkSettingsTemplates::get_options_template($result['auth_key']);
43284322

@@ -4334,8 +4328,7 @@ function spbc_get_key_auto($direct_call = false)
43344328
);
43354329
} else {
43364330
$out = array(
4337-
'success' => true,
4338-
'reload' => true,
4331+
'success' => true
43394332
);
43404333
}
43414334
}
@@ -4347,6 +4340,46 @@ function spbc_get_key_auto($direct_call = false)
43474340
die(json_encode($out));
43484341
}
43494342

4343+
function spbc_save_key($apikey, $user_token = '', $direct_call = false)
4344+
{
4345+
global $spbc;
4346+
4347+
if ( ! $direct_call ) {
4348+
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
4349+
$apikey = Post::getString('apiKey');
4350+
if ( ! spbc_api_key__is_correct($apikey) ) {
4351+
die(
4352+
json_encode(
4353+
[
4354+
'success' => false,
4355+
'msg' => __('access key format is invalid', 'security-malware-firewall')
4356+
]
4357+
)
4358+
);
4359+
}
4360+
}
4361+
4362+
$settings['spbc_key'] = trim($apikey);
4363+
$settings['spbc_key'] = preg_match('/^[a-z\d]*$/', $settings['spbc_key']) ? $settings['spbc_key'] : $spbc->settings['spbc_key']; // Check key format a-z\d
4364+
$settings['spbc_key'] = is_main_site() || $spbc->ms__work_mode != 2 ? $settings['spbc_key'] : $spbc->network_settings['spbc_key'];
4365+
4366+
$spbc->settings['spbc_key'] = $settings['spbc_key'];
4367+
$spbc->save('settings');
4368+
4369+
$spbc->data['user_token'] = ! empty($user_token) ? $user_token : '';
4370+
$spbc->data['key_is_ok'] = spbc_api_key__is_correct($settings['spbc_key']);
4371+
$spbc->data['key_changed'] = true;
4372+
$spbc->save('data');
4373+
4374+
if ( ! $direct_call ) {
4375+
die(
4376+
json_encode(
4377+
['success' => true]
4378+
)
4379+
);
4380+
}
4381+
}
4382+
43504383
function spbc_settings__update_account_email($direct_call = false)
43514384
{
43524385
if ( ! $direct_call) {

inc/spbc-tools.php

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,39 +100,46 @@ function spbc_get_module_folder_by_type($module_type)
100100
*/
101101
function spbc_get_modules_by_type($module_type)
102102
{
103-
$output = array();
103+
static $cache = array(); // static cache
104+
if (isset($cache[$module_type])) {
105+
return $cache[$module_type];
106+
}
107+
108+
$output = array();
104109
$modules_dir = spbc_get_module_folder_by_type($module_type);
110+
$is_plugins = $module_type === 'plugins';
111+
$header_name_field = substr($module_type, 0, -1) . ' name'; // 'plugin name' / 'theme name'
112+
$plugin_dir_len = $is_plugins ? strlen(WP_PLUGIN_DIR) : 0;
105113

106-
foreach (glob($modules_dir . '/*') as $module_dir) {
107-
if (is_dir($module_dir)) {
108-
foreach (glob($module_dir . '/*') as $module_file) {
109-
if ( ! is_file($module_file) || ($module_type === 'themes' && strpos($module_file, 'style.css') === false)) {
110-
continue;
111-
}
112-
$module_type_simple = substr($module_type, 0, -1);
113-
$module = get_file_data($module_file, array('Name' => "$module_type_simple name", 'Version' => 'Version',));
114-
if ( ! empty($module['Version']) && ! empty($module['Name'])) {
115-
if ($module_type === 'plugins') {
116-
$module[ $module_type ] = substr($module_file, strlen(WP_PLUGIN_DIR) + 1);
117-
$key = preg_replace('/^(.*)(\/|\\\\).*/', '$1', substr($module_file, strlen(WP_PLUGIN_DIR) + 1));
118-
if ( empty($key) ) {
119-
continue;
120-
}
121-
$output[ $key ] = $module;
122-
}
123-
if ($module_type === 'themes') {
124-
$key = substr($module_file, strlen(get_theme_root()) + 1, - (strlen('/style.css')));
125-
if ( empty($key) ) {
126-
continue;
127-
}
128-
$module[ $module_type ] = $key;
129-
$output[ $key ] = $module;
130-
}
114+
foreach (glob($modules_dir . '/*', GLOB_ONLYDIR) as $module_dir) {
115+
$key = basename($module_dir);
116+
if (empty($key)) {
117+
continue;
118+
}
119+
120+
if ($is_plugins) {
121+
foreach (glob($module_dir . '/*.php') as $module_file) {
122+
$module = get_file_data($module_file, array('Name' => $header_name_field, 'Version' => 'Version'));
123+
if (!empty($module['Version']) && !empty($module['Name'])) {
124+
$module[$module_type] = substr($module_file, $plugin_dir_len + 1);
125+
$output[$key] = $module;
126+
break;
131127
}
132128
}
129+
} else {
130+
$style_file = $module_dir . '/style.css';
131+
if (!file_exists($style_file)) {
132+
continue;
133+
}
134+
$module = get_file_data($style_file, array('Name' => $header_name_field, 'Version' => 'Version'));
135+
if (!empty($module['Version']) && !empty($module['Name'])) {
136+
$module[$module_type] = $key;
137+
$output[$key] = $module;
138+
}
133139
}
134140
}
135141

142+
$cache[$module_type] = $output;
136143
return $output;
137144
}
138145

2.09 MB
Loading

js/public/86c330c66f7333ff6202.ttf

335 KB
Binary file not shown.

js/public/d52a01d17b566af4e096.ttf

336 KB
Binary file not shown.

js/public/f0be7d273c3543fe4c4a.ttf

336 KB
Binary file not shown.

js/public/spbc-react-bundle.js.LICENSE.txt

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)