Files
kate522andClaude Opus 5 35bb96e82f refactor: rename the theme brand and every identifier from AKSRT to Jio
Full-project rename. `git grep -i aksrt` is now empty apart from the
DBMigrator 3.3.0 changelog note that documents the rename itself.

Code identifiers
- PHP namespace AKSRT\ -> Jio\ (composer PSR-4 + 378 declarations)
- global constants AKSRT_* -> JIO_* (VERSION/DIR/URI, PAY_TYPE_*, CAPTCHA_*)
- procedural functions, hooks, options, meta keys, table names,
  cookies, query vars, ajax actions and nonces: aksrt_ -> jio_
- text domain aksrt -> jio; Theme Name -> Jio
- JS globals: aksrtData/aksrtAdminData/... -> jioData/jioAdminData/...,
  window.AKSRTCaptcha & friends -> window.JioCaptcha, Aksrt* -> Jio*
- Vue components Aks*.vue -> Jio*.vue (15 files renamed + imports)
- CSS classes/data-attrs/custom properties: aksrt- -> jio-
- REST namespace aksrt/v1 -> jio/v1 (incl. payment gateway callbacks)

Storage layer
- DB tables {prefix}aksrt_* -> {prefix}jio_*; SCHEMA_VERSION 3.2.0 -> 3.3.0
  so dbDelta creates the new names on install
- widget id_base aksrt_widget_* -> jio_widget_*
- uninstall.php drop list rebuilt from the actual migrator tables
  (dropped 3 stale entries, added the 17 missing ones)

Removed
- hardcoded https://api.aksrt.com/version.json default update endpoint;
  get_endpoint() now reads the 「更新端点」 setting and do_check() no-ops
  when it is empty

Files renamed: inc/helpers/aksrt-*.php -> jio-*.php (54),
assets/admin/src/components/form/Aks*.vue -> Jio*.vue (15).
Build artifacts regenerated: assets/css/build, assets/js/runtime,
assets/admin/build.

Verified: audit-psr4-paths errors=0, audit-admin-contracts errors=0
(warnings=56, unchanged baseline), 813/813 widget-system tests,
44/44 phpunit, php -l clean across all PHP.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-11-01 20:05:04 +08:00

130 lines
4.2 KiB
PHP

<?php
/**
* Comment city / IP geo helpers.
*
* Meta: jio_comment_addr {country,province,city}
* Gates: ip_geo_enabled + ip_geo_display has comment(扩展&增强 / IP归属地统一控制)
*
* @package Jio
*/
defined('ABSPATH') || exit;
if (!function_exists('jio_comment_city_enabled')) :
function jio_comment_city_enabled(): bool {
// 评论区位置显示的开关与精度统一由「扩展&增强 / IP归属地」配置提供。
return function_exists('jio_ip_geo_display_enabled') && jio_ip_geo_display_enabled('comment');
}
endif;
if (!function_exists('jio_comment_city_type')) :
function jio_comment_city_type(): string {
return function_exists('jio_ip_geo_format_key') ? jio_ip_geo_format_key() : 'province_city';
}
endif;
if (!function_exists('jio_store_comment_addr')) :
/**
* @param int $comment_id Comment ID.
* @param string|null $ip Optional IP override.
*/
function jio_store_comment_addr(int $comment_id, ?string $ip = null): void {
if ($comment_id <= 0 || !jio_comment_city_enabled()) {
return;
}
if ($ip === null || $ip === '') {
$comment = get_comment($comment_id);
$ip = $comment instanceof WP_Comment ? (string) $comment->comment_author_IP : '';
}
$ip = trim((string) $ip);
// Private / empty stored IP (CDN edge without proxy headers): resolve live client IP once.
$needs_live = ($ip === '' || $ip === '0.0.0.0');
if (!$needs_live && function_exists('filter_var')) {
$needs_live = !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
}
if ($needs_live && function_exists('jio_get_client_ip')) {
$live = trim((string) jio_get_client_ip());
if ($live !== '' && $live !== '0.0.0.0'
&& filter_var($live, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
) {
$ip = $live;
}
}
if ($ip === '') {
return;
}
if (function_exists('jio_lookup_geo_for_ip')) {
$addr = jio_lookup_geo_for_ip($ip);
} elseif (class_exists('\Jio\Extensions\IPGeo')) {
$geo = \Jio\Extensions\IPGeo::get_instance()->lookup($ip);
$addr = [
'country' => (string) ($geo['country'] ?? ''),
'province' => (string) ($geo['province'] ?? ''),
'city' => (string) ($geo['city'] ?? ''),
];
} else {
return;
}
if ($addr['country'] === '' && $addr['province'] === '' && $addr['city'] === '') {
return;
}
update_comment_meta($comment_id, 'jio_comment_addr', $addr);
}
endif;
if (!function_exists('jio_get_comment_addr')) :
/**
* @param int|WP_Comment $comment Comment.
* @return array{country:string,province:string,city:string}
*/
function jio_get_comment_addr($comment): array {
$comment_id = $comment instanceof WP_Comment ? (int) $comment->comment_ID : (int) $comment;
if ($comment_id <= 0) {
return ['country' => '', 'province' => '', 'city' => ''];
}
$raw = get_comment_meta($comment_id, 'jio_comment_addr', true);
if (function_exists('jio_normalize_geo_addr')) {
return jio_normalize_geo_addr($raw);
}
return is_array($raw) ? $raw : ['country' => '', 'province' => '', 'city' => ''];
}
endif;
if (!function_exists('jio_format_comment_city_label')) :
/**
* @param array<string,string> $addr Addr.
* @param string $type Format.
*/
function jio_format_comment_city_label(array $addr, string $type = 'province_city'): string {
if (function_exists('jio_format_geo_label')) {
return jio_format_geo_label($addr, $type);
}
return '';
}
endif;
if (!function_exists('jio_get_comment_city_badge_html')) :
function jio_get_comment_city_badge_html($comment): string {
if (!jio_comment_city_enabled()) {
return '';
}
// legacy 契约:无属地数据时不渲染徽章(不使用查询失败兜底文案)。
$addr = jio_get_comment_addr($comment);
$label = function_exists('jio_format_geo_label')
? jio_format_geo_label(is_array($addr) ? $addr : [], jio_comment_city_type())
: '';
if ($label === '') {
return '';
}
return '<span class="badg badg-sm comment-city-badge jio-ip-geo-badge" title="' . esc_attr__('IP 属地', 'jio') . '">' . esc_html($label) . '</span>';
}
endif;
add_action('comment_post', static function ($comment_id): void {
if (function_exists('jio_store_comment_addr')) {
jio_store_comment_addr((int) $comment_id);
}
}, 20, 1);