refactor(ip-geo): drop dual-read gates; keep single meta and four surfaces
Canonical keys only (ip_geo_display defaults to all four, aksrt_user_addr / aksrt_comment_addr only). Self-view still resolves current IP on read.
This commit is contained in:
@@ -47,19 +47,25 @@ class ExtensionRuntime {
|
||||
public static function get_ip_geo_settings(): array {
|
||||
$settings = Settings::get_all();
|
||||
|
||||
$provider = sanitize_key((string) ($settings['ip_addr_sdk'] ?? ($settings['ip_geo_provider'] ?? 'null')));
|
||||
$provider = sanitize_key((string) ($settings['ip_addr_sdk'] ?? 'null'));
|
||||
$allowed = ['polling', 'qq', 'amap', 'null'];
|
||||
if (!in_array($provider, $allowed, true)) {
|
||||
$provider = 'null';
|
||||
}
|
||||
|
||||
$display_raw = $settings['ip_geo_display'] ?? ['comment', 'user_home', 'user_center', 'post'];
|
||||
$display = is_array($display_raw) ? $display_raw : [$display_raw];
|
||||
$display = array_values(array_unique(array_filter(array_map('sanitize_key', $display))));
|
||||
$display = is_array($display_raw) ? $display_raw : [];
|
||||
$allowed_display = ['comment', 'user_home', 'user_center', 'post'];
|
||||
$display = array_values(array_filter($display, static fn($v) => in_array($v, $allowed_display, true)));
|
||||
if ($display === []) {
|
||||
$display = ['comment', 'user_home', 'user_center', 'post'];
|
||||
$display_norm = [];
|
||||
foreach ($display as $item) {
|
||||
$key = sanitize_key((string) $item);
|
||||
if (in_array($key, $allowed_display, true) && !in_array($key, $display_norm, true)) {
|
||||
$display_norm[] = $key;
|
||||
}
|
||||
}
|
||||
// Empty / missing → full four surfaces (canonical default).
|
||||
if ($display_norm === []) {
|
||||
$display_norm = $allowed_display;
|
||||
}
|
||||
|
||||
$format = sanitize_key((string) ($settings['ip_geo_format'] ?? 'province_city'));
|
||||
@@ -70,9 +76,8 @@ class ExtensionRuntime {
|
||||
return [
|
||||
'ip_geo_enabled' => !empty($settings['ip_geo_enabled']),
|
||||
'ip_addr_sdk' => $provider,
|
||||
'ip_geo_provider' => $provider,
|
||||
'ip_geo_cache_ttl' => max(3600, (int) ($settings['ip_geo_cache_ttl'] ?? 86400)),
|
||||
'ip_geo_display' => $display,
|
||||
'ip_geo_display' => $display_norm,
|
||||
'ip_geo_format' => $format,
|
||||
'ip_geo_fallback_text' => (string) ($settings['ip_geo_fallback_text'] ?? ''),
|
||||
'ip_addr_sdk_qq_appkey' => (string) ($settings['ip_addr_sdk_qq_appkey'] ?? ''),
|
||||
|
||||
Reference in New Issue
Block a user