Skip to content
Merged

beta #666

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
},
rules: {
'indent': ['error', 4],
'max-len': ['error', {'code': 120}],
'max-len': 'off',
'prefer-const': 'off',
'no-invalid-this': 'off',
'require-jsdoc': 'off',
Expand Down
1 change: 1 addition & 0 deletions inc/spbc-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function spbc_admin_init()
add_action('wp_ajax_spbc_settings__get_recommendation', 'spbc_settings__get_recommendation');
add_action('wp_ajax_spbc_settings__check_renew_banner', 'spbc_settings__check_renew_banner');
add_action('wp_ajax_spbc_get_key_auto', 'spbc_get_key_auto');
add_action('wp_ajax_spbc_save_key', 'spbc_save_key');
add_action('wp_ajax_spbc_update_account_email', 'spbc_settings__update_account_email');
add_action('wp_ajax_spbc_create_support_user', 'spbc_settings__spbc_create_support_user');

Expand Down
77 changes: 55 additions & 22 deletions inc/spbc-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,7 @@ function spbc_field_options_overview_traffic_light()

/**
* Admin callback function - Displays field of Api Key
* @ToDo unused code?
*/
function spbc_field_key()
{
Expand Down Expand Up @@ -4264,14 +4265,15 @@ function spbc_get_key_auto($direct_call = false)
$wpms = SPBC_WPMS && defined('SUBDOMAIN_INSTALL') && ! SUBDOMAIN_INSTALL;
$white_label = false;
$hoster_api_key = $spbc->ms__hoster_api_key;
$admin_email = spbc_get_admin_email();
$admin_email = Post::getString('email') ? Post::getString('email') : spbc_get_admin_email();

/**
* Filters the email to get API key
*
* @param string email to get API key
*/
$filtered_admin_email = apply_filters('spbc_get_api_key_email', $admin_email);
$filtered_admin_email = filter_var($filtered_admin_email, FILTER_VALIDATE_EMAIL);

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

$out = array(
'success' => true,
'reload' => false,
'msg' => $result['error']
'success' => false,
'msg' => isset($result['error_message'])
? esc_html($result['error_message'])
: $result['error']
);
} elseif (isset($result['error_no']) && $result['error_no'] == '403') {
$out = array(
'success' => true,
'reload' => false,
'error' => isset($result['error_message']) ? esc_html($result['error_message']) : esc_html('Our service is not available in your region.'),
'success' => false,
'error' => isset($result['error_message'])
? esc_html($result['error_message'])
: esc_html('Our service is not available in your region.'),
);
} elseif ( ! isset($result['auth_key'])) {
$out = array(
'success' => true,
'reload' => false,
'success' => false,
'msg' => sprintf(
__('Please, get the Access Key from %s CleanTalk Control Panel %s and insert it in the Access Key field', 'cleantalk-spam-protect'),
'<a href="https://cleantalk.org/my/?cp_mode=security" target="_blank">',
'</a>'
)
);
} else {
$settings['spbc_key'] = trim($result['auth_key']);
$settings['spbc_key'] = preg_match('/^[a-z\d]*$/', $settings['spbc_key']) ? $settings['spbc_key'] : $spbc->settings['spbc_key']; // Check key format a-z\d
$settings['spbc_key'] = is_main_site() || $spbc->ms__work_mode != 2 ? $settings['spbc_key'] : $spbc->network_settings['spbc_key'];

$spbc->settings['spbc_key'] = $settings['spbc_key'];
$spbc->save('settings');

$spbc->data['user_token'] = (! empty($result['user_token']) ? $result['user_token'] : '');
$spbc->data['key_is_ok'] = spbc_api_key__is_correct($settings['spbc_key']);
$spbc->data['key_changed'] = true;
$spbc->save('data');
$user_token = ! empty($result['user_token']) ? $result['user_token'] : '';
spbc_save_key($result['auth_key'], $user_token, true);

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

Expand All @@ -4334,8 +4328,7 @@ function spbc_get_key_auto($direct_call = false)
);
} else {
$out = array(
'success' => true,
'reload' => true,
'success' => true
);
}
}
Expand All @@ -4347,6 +4340,46 @@ function spbc_get_key_auto($direct_call = false)
die(json_encode($out));
}

function spbc_save_key($apikey, $user_token = '', $direct_call = false)
{
global $spbc;

if ( ! $direct_call ) {
spbc_check_ajax_referer('spbc_secret_nonce', 'security');
$apikey = Post::getString('apiKey');
if ( ! spbc_api_key__is_correct($apikey) ) {
die(
json_encode(
[
'success' => false,
'msg' => __('access key format is invalid', 'security-malware-firewall')
]
)
);
}
}

$settings['spbc_key'] = trim($apikey);
$settings['spbc_key'] = preg_match('/^[a-z\d]*$/', $settings['spbc_key']) ? $settings['spbc_key'] : $spbc->settings['spbc_key']; // Check key format a-z\d
$settings['spbc_key'] = is_main_site() || $spbc->ms__work_mode != 2 ? $settings['spbc_key'] : $spbc->network_settings['spbc_key'];

$spbc->settings['spbc_key'] = $settings['spbc_key'];
$spbc->save('settings');

$spbc->data['user_token'] = ! empty($user_token) ? $user_token : '';
$spbc->data['key_is_ok'] = spbc_api_key__is_correct($settings['spbc_key']);
$spbc->data['key_changed'] = true;
$spbc->save('data');

if ( ! $direct_call ) {
die(
json_encode(
['success' => true]
)
);
}
}

function spbc_settings__update_account_email($direct_call = false)
{
if ( ! $direct_call) {
Expand Down
59 changes: 33 additions & 26 deletions inc/spbc-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,39 +100,46 @@ function spbc_get_module_folder_by_type($module_type)
*/
function spbc_get_modules_by_type($module_type)
{
$output = array();
static $cache = array(); // static cache
if (isset($cache[$module_type])) {
return $cache[$module_type];
}

$output = array();
$modules_dir = spbc_get_module_folder_by_type($module_type);
$is_plugins = $module_type === 'plugins';
$header_name_field = substr($module_type, 0, -1) . ' name'; // 'plugin name' / 'theme name'
$plugin_dir_len = $is_plugins ? strlen(WP_PLUGIN_DIR) : 0;

foreach (glob($modules_dir . '/*') as $module_dir) {
if (is_dir($module_dir)) {
foreach (glob($module_dir . '/*') as $module_file) {
if ( ! is_file($module_file) || ($module_type === 'themes' && strpos($module_file, 'style.css') === false)) {
continue;
}
$module_type_simple = substr($module_type, 0, -1);
$module = get_file_data($module_file, array('Name' => "$module_type_simple name", 'Version' => 'Version',));
if ( ! empty($module['Version']) && ! empty($module['Name'])) {
if ($module_type === 'plugins') {
$module[ $module_type ] = substr($module_file, strlen(WP_PLUGIN_DIR) + 1);
$key = preg_replace('/^(.*)(\/|\\\\).*/', '$1', substr($module_file, strlen(WP_PLUGIN_DIR) + 1));
if ( empty($key) ) {
continue;
}
$output[ $key ] = $module;
}
if ($module_type === 'themes') {
$key = substr($module_file, strlen(get_theme_root()) + 1, - (strlen('/style.css')));
if ( empty($key) ) {
continue;
}
$module[ $module_type ] = $key;
$output[ $key ] = $module;
}
foreach (glob($modules_dir . '/*', GLOB_ONLYDIR) as $module_dir) {
$key = basename($module_dir);
if (empty($key)) {
continue;
}

if ($is_plugins) {
foreach (glob($module_dir . '/*.php') as $module_file) {
$module = get_file_data($module_file, array('Name' => $header_name_field, 'Version' => 'Version'));
if (!empty($module['Version']) && !empty($module['Name'])) {
$module[$module_type] = substr($module_file, $plugin_dir_len + 1);
$output[$key] = $module;
break;
}
}
} else {
$style_file = $module_dir . '/style.css';
if (!file_exists($style_file)) {
continue;
}
$module = get_file_data($style_file, array('Name' => $header_name_field, 'Version' => 'Version'));
if (!empty($module['Version']) && !empty($module['Name'])) {
$module[$module_type] = $key;
$output[$key] = $module;
}
}
}

$cache[$module_type] = $output;
return $output;
}

Expand Down
Binary file added js/public/0d64245e1e499ba792592d23fa64fe91.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added js/public/86c330c66f7333ff6202.ttf
Binary file not shown.
Binary file added js/public/d52a01d17b566af4e096.ttf
Binary file not shown.
Binary file added js/public/f0be7d273c3543fe4c4a.ttf
Binary file not shown.
29 changes: 0 additions & 29 deletions js/public/spbc-react-bundle.js.LICENSE.txt

This file was deleted.

Loading
Loading