fix(vip): preserve equity HTML instead of re-splitting into list items

This commit is contained in:
kate522 committed 2026-07-21 20:19:11 +08:00
1 parent ee5a16f9a0
commit fce5ab3088
5 files changed
+110 -102

No files matched your search

+4 -73
View File
@@ -18,72 +18,6 @@ if (empty($vip_settings['enabled'])) {
return;
}
/**
* Normalize equity HTML/plain text into a proper <ul> of <li>.
*/
$normalize_equity = static function (string $raw): string {
$raw = trim($raw);
if ($raw === '') {
return '';
}
$allowed = [
'li' => ['class' => true],
'ul' => ['class' => true],
'ol' => ['class' => true],
'strong' => [],
'b' => [],
'em' => [],
'i' => ['class' => true],
'span' => ['class' => true],
'br' => [],
];
$clean = wp_kses($raw, $allowed);
// Already has list items.
if (preg_match('/<li[\s>]/i', $clean)) {
// Strip wrapping ul/ol; we re-wrap.
$inner = preg_replace('#</?(ul|ol)[^>]*>#i', '', $clean) ?? $clean;
return '<ul class="v-equity">' . $inner . '</ul>';
}
// Plain text: split by newlines / Chinese separators / commas.
$plain = trim(wp_strip_all_tags($clean));
if ($plain === '') {
return '';
}
$parts = preg_split('/[\r\n]+|[;;,,||]+/u', $plain) ?: [];
$items = [];
foreach ($parts as $part) {
$part = trim((string) $part);
// Also split jammed Chinese phrases if still one long blob with known tokens.
if ($part === '') {
continue;
}
$items[] = $part;
}
// Heuristic: if still a single long string without separators, try common benefit chunks.
if (count($items) === 1 && mb_strlen($items[0]) > 16) {
$blob = $items[0];
$chunks = preg_split('/(?=(?:免费|会员|更高|专属|付费|下载|身份|权益|折扣|无限))/u', $blob, -1, PREG_SPLIT_NO_EMPTY) ?: [];
$chunks = array_values(array_filter(array_map('trim', $chunks)));
if (count($chunks) > 1) {
$items = $chunks;
}
}
if ($items === []) {
return '';
}
$html = '<ul class="v-equity">';
foreach ($items as $item) {
$html .= '<li>' . esc_html($item) . '</li>';
}
$html .= '</ul>';
return $html;
};
$user_id = (int) ($user_id ?? get_current_user_id());
$level = function_exists('aksrt_get_user_vip_level') ? aksrt_get_user_vip_level($user_id) : 0;
$expires = (int) get_user_meta($user_id, 'aksrt_vip_expires', true);
@@ -142,14 +76,11 @@ foreach ([1, 2] as $lv) {
}
$lv_name = (string) ($levels[$lv]['name'] ?? ('VIP' . $lv));
$lv_desc = (string) ($levels[$lv]['desc'] ?? '');
// Preserve admin equity HTML as-is (sanitize/wrap only; never re-split into items).
$equity_raw = (string) ($levels[$lv]['equity'] ?? '');
if ($equity_raw === '') {
// Fallback defaults when option empty / stripped.
$equity_raw = $lv === 1
? "免费下载部分资源\n会员专属身份标识\n付费内容会员价"
: "更高免费下载额度\n更高等级身份标识\n更多付费内容会员价";
}
$equity = $normalize_equity($equity_raw);
$equity = function_exists('aksrt_format_vip_equity_html')
? aksrt_format_vip_equity_html($equity_raw)
: '';
$cta = sprintf(__('开通%s', 'aksrt'), $lv_name);
$vip_attr = $lv;
if (str_starts_with($btn_type, 'renew_')) {