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:
1 parent
6e71008d00
commit
3bb7fb0ba6
4 files changed
+87
-177
No files matched your search
@@ -44,7 +44,7 @@ class IPGeo {
|
||||
}
|
||||
}
|
||||
|
||||
$provider = sanitize_key((string) ($config['ip_addr_sdk'] ?? ($config['ip_geo_provider'] ?? 'null')));
|
||||
$provider = sanitize_key((string) ($config['ip_addr_sdk'] ?? 'null'));
|
||||
$result = $this->query_provider($provider, $ip, $config);
|
||||
|
||||
if (!empty($result['province']) || !empty($result['city']) || !empty($result['country'])) {
|
||||
@@ -66,7 +66,7 @@ class IPGeo {
|
||||
*/
|
||||
public function get_status(): array {
|
||||
$config = $this->get_config();
|
||||
$provider = sanitize_key((string) ($config['ip_addr_sdk'] ?? ($config['ip_geo_provider'] ?? 'null')));
|
||||
$provider = sanitize_key((string) ($config['ip_addr_sdk'] ?? 'null'));
|
||||
$enabled = !empty($config['ip_geo_enabled']);
|
||||
|
||||
$missing = [];
|
||||
@@ -88,7 +88,7 @@ class IPGeo {
|
||||
'transport' => 'http_api',
|
||||
'missing_fields' => $missing,
|
||||
'cache_ttl' => (int) ($config['ip_geo_cache_ttl'] ?? 86400),
|
||||
'display' => (array) ($config['ip_geo_display'] ?? ['comment']),
|
||||
'display' => (array) ($config['ip_geo_display'] ?? ['comment', 'user_home', 'user_center', 'post']),
|
||||
'format' => (string) ($config['ip_geo_format'] ?? 'province_city'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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