Skip to content

Commit 157052b

Browse files
committed
Upd. Settings. Custom server option refactoring.
1 parent 55a51c9 commit 157052b

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

cleantalk.antispam/include.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ public static function OnPageStartHandler()
184184
if ( $bot_detector ) {
185185
if (class_exists('COption')) {
186186
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
187-
if ($use_custom_server == '1') {
188-
Asset::getInstance()->addJs('https://moderate.cleantalk.ru/ct-bot-detector-wrapper.js');
187+
if ($use_custom_server !== '') {
188+
Asset::getInstance()->addJs('https://moderate.' . $use_custom_server . '/ct-bot-detector-wrapper.js');
189189
} else {
190190
Asset::getInstance()->addJs('https://moderate.cleantalk.org/ct-bot-detector-wrapper.js');
191191
}
@@ -1720,10 +1720,10 @@ private static function GetWorkServer() {
17201720

17211721
if (class_exists('COption')) {
17221722
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
1723-
if ($use_custom_server == '1') {
1723+
if ($use_custom_server !== '') {
17241724
return array(
1725-
'work_url' => 'http://moderate.cleantalk.ru',
1726-
'server_url' => 'http://moderate.cleantalk.ru',
1725+
'work_url' => 'http://moderate.' . $use_custom_server,
1726+
'server_url' => 'http://moderate.' . $use_custom_server,
17271727
'server_ttl' => 0,
17281728
'server_changed' => 0,
17291729
);
@@ -1775,9 +1775,9 @@ private static function SetWorkServer($work_url = 'http://moderate.cleantalk.org
17751775

17761776
if (class_exists('COption')) {
17771777
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
1778-
if ($use_custom_server == '1') {
1779-
$work_url = 'http://moderate.cleantalk.ru';
1780-
$server_url = 'http://moderate.cleantalk.ru';
1778+
if ($use_custom_server !== '') {
1779+
$work_url = 'http://moderate.' . $use_custom_server;
1780+
$server_url = 'http://moderate.' . $use_custom_server;
17811781
}
17821782
}
17831783

cleantalk.antispam/lib/Cleantalk/Common/API.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,8 @@ public static function send_request($data, $url = null, $timeout = 10, $ssl = fa
658658
if ($url == self::$URL) {
659659
if (class_exists('COption')) {
660660
$use_custom_server = \COption::GetOptionString( 'cleantalk.antispam', 'use_custom_server', '' );
661-
if ($use_custom_server == '1') {
662-
$url = 'https://api.cleantalk.ru';
661+
if ($use_custom_server !== '') {
662+
$url = 'https://api.' . $use_custom_server;
663663
}
664664
}
665665
}

cleantalk.antispam/options.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,22 @@
204204

205205
// Custom server
206206
if (isset($_POST['use_custom_server']) && $_POST['use_custom_server'] !== '') {
207-
if (strpos($_POST['use_custom_server'], 'cleantalk.ru') !== false) {
208-
if (file_get_contents('https://moderate.cleantalk.ru') === false) {
209-
Option::set( $sModuleId, 'use_custom_server', '' );
210-
CAdminNotify::Add(array(
211-
'MESSAGE' => GetMessage( 'CLEANTALK_SERVER_NOT_AVAILABLE' ),
212-
'TAG' => 'server_not_available',
213-
'MODULE_ID' => 'main',
214-
'ENABLE_CLOSE' => 'Y'));
215-
} else {
216-
Option::set( $sModuleId, 'use_custom_server', '1' );
217-
CAdminNotify::DeleteByTag('server_not_available');
218-
}
219-
} else {
207+
// Remove path, query, fragment
208+
$domain = preg_replace('/[\/\?#].*$/', '', $_POST['use_custom_server']);
209+
// Remove invalid characters (keep letters, numbers, hyphens, dots)
210+
$domain = preg_replace('/[^a-zA-Z0-9\.\-]/', '', $domain);
211+
// Convert to lowercase and trim
212+
$domain = strtolower(trim($domain));
213+
if (file_get_contents('https://moderate.' . $domain) === false) {
220214
Option::set( $sModuleId, 'use_custom_server', '' );
221215
CAdminNotify::Add(array(
222216
'MESSAGE' => GetMessage( 'CLEANTALK_SERVER_NOT_AVAILABLE' ),
223217
'TAG' => 'server_not_available',
224218
'MODULE_ID' => 'main',
225219
'ENABLE_CLOSE' => 'Y'));
220+
} else {
221+
Option::set( $sModuleId, 'use_custom_server', $domain );
222+
CAdminNotify::DeleteByTag('server_not_available');
226223
}
227224
}
228225
}
@@ -742,7 +739,7 @@ function ctDisableInputLine(ct_input_line){
742739
type="text"
743740
name="use_custom_server"
744741
id="use_custom_server"
745-
value="<?php echo $current_options['use_custom_server'] == '1' ? 'cleantalk.ru' : ''; ?>" />
742+
value="<?php echo $current_options['use_custom_server']; ?>" />
746743
<div style="padding: 10px 0 10px 0">
747744
<?php echo GetMessage( 'CLEANTALK_USE_CUSTOM_SERVER_DESCRIPTION' ); ?>
748745
</div>

0 commit comments

Comments
 (0)