This commit is contained in:
Flatlogic Bot 2026-04-16 10:18:11 +00:00
parent be7ca2eca1
commit 8bf3a87e42

View File

@ -83,6 +83,28 @@ function sccharacters_excerpt(string $value, int $limit = 120): string
return rtrim(substr($value, 0, max(0, $limit - 1))) . '…'; return rtrim(substr($value, 0, max(0, $limit - 1))) . '…';
} }
function sccharacters_display_stat_value($value): string
{
if (!is_numeric((string) $value)) {
return '0';
}
$formatted = number_format((float) $value, 2, '.', '');
$formatted = rtrim(rtrim($formatted, '0'), '.');
return $formatted === '' ? '0' : $formatted;
}
function sccharacters_custom_stat_preview(array $stat_row): string
{
$sign = (string) ($stat_row['cl_scitemcustomstat_sign'] ?? '');
$prefix = $sign === '-' ? '-' : ($sign === '+' ? '+' : '');
$value = sccharacters_display_stat_value($stat_row['cl_scitemcustomstat_value'] ?? 0);
$unit = trim((string) ($stat_row['cl_scstatsitem_unit'] ?? ''));
return trim((string) ($stat_row['cl_scstatsitem_name'] ?? '') . ' : ' . $prefix . $value . ($unit !== '' ? ' ' . $unit : ''));
}
function sccharacters_share_url(string $token): string function sccharacters_share_url(string $token): string
{ {
$is_https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') $is_https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
@ -1381,6 +1403,7 @@ $item_panel_open = (string) ($_GET['item_panel'] ?? '') === '1';
$item_page = max(1, (int) ($_GET['item_page'] ?? 1)); $item_page = max(1, (int) ($_GET['item_page'] ?? 1));
$item_per_page = sccharacters_normalize_item_per_page($_GET['item_per_page'] ?? 50); $item_per_page = sccharacters_normalize_item_per_page($_GET['item_per_page'] ?? 50);
$item_results = []; $item_results = [];
$item_result_custom_stats = [];
$item_total_results = 0; $item_total_results = 0;
$item_total_pages = 1; $item_total_pages = 1;
$item_result_offset_start = 0; $item_result_offset_start = 0;
@ -1439,6 +1462,40 @@ if ($selected_character) {
$stmt_item_results = $db->prepare($sql); $stmt_item_results = $db->prepare($sql);
$stmt_item_results->execute($params); $stmt_item_results->execute($params);
$item_results = $stmt_item_results->fetchAll(); $item_results = $stmt_item_results->fetchAll();
$item_result_custom_ids = [];
foreach ($item_results as $item_result_row) {
$itemcustom_id = (int) ($item_result_row['cl_scitemcustom_id'] ?? 0);
if ($itemcustom_id > 0) {
$item_result_custom_ids[] = $itemcustom_id;
}
}
$item_result_custom_ids = array_values(array_unique($item_result_custom_ids));
if ($item_result_custom_ids !== []) {
$placeholders = implode(',', array_fill(0, count($item_result_custom_ids), '?'));
$stmt_item_stats = $db->prepare(
"SELECT
cs.cl_scitemcustomstat_itemcustom_id,
st.cl_scstatsitem_name,
st.cl_scstatsitem_unit,
cs.cl_scitemcustomstat_sign,
cs.cl_scitemcustomstat_value
FROM tbl_scitemcustomstat cs
INNER JOIN tbl_scstatsitem st ON st.cl_scstatsitem_id = cs.cl_scitemcustomstat_stat_id
WHERE cs.cl_scitemcustomstat_itemcustom_id IN ({$placeholders})
ORDER BY st.cl_scstatsitem_name ASC, cs.cl_scitemcustomstat_id ASC"
);
$stmt_item_stats->execute($item_result_custom_ids);
foreach ($stmt_item_stats->fetchAll() as $item_stat_row) {
$itemcustom_id = (int) ($item_stat_row['cl_scitemcustomstat_itemcustom_id'] ?? 0);
if (!isset($item_result_custom_stats[$itemcustom_id])) {
$item_result_custom_stats[$itemcustom_id] = [];
}
$item_result_custom_stats[$itemcustom_id][] = $item_stat_row;
}
}
} else { } else {
$count_sql = "SELECT COUNT(*) $count_sql = "SELECT COUNT(*)
FROM tbl_scobjs FROM tbl_scobjs
@ -2569,6 +2626,10 @@ if ($selected_character) {
.search-result strong { display: block; margin-bottom: 0.25rem; } .search-result strong { display: block; margin-bottom: 0.25rem; }
.search-result-stats {
margin-top: 0.1rem;
}
.search-result-main { .search-result-main {
min-width: 0; min-width: 0;
display: flex; display: flex;
@ -3370,6 +3431,7 @@ if ($selected_character) {
$item_id_field = $result_is_custom ? 'custom_item_id' : 'base_obj_id'; $item_id_field = $result_is_custom ? 'custom_item_id' : 'base_obj_id';
$item_uuid = (string) ($item_result_row['cl_scobjs_uuid'] ?? ''); $item_uuid = (string) ($item_result_row['cl_scobjs_uuid'] ?? '');
$item_image_url = $item_uuid !== '' ? 'https://cstone.space/uifimages/' . rawurlencode($item_uuid) . '.png' : ''; $item_image_url = $item_uuid !== '' ? 'https://cstone.space/uifimages/' . rawurlencode($item_uuid) . '.png' : '';
$result_stats = $result_is_custom ? ($item_result_custom_stats[$result_id] ?? []) : [];
?> ?>
<article class="search-result panel panel-soft"> <article class="search-result panel panel-soft">
<div class="search-result-preview"> <div class="search-result-preview">
@ -3399,6 +3461,14 @@ if ($selected_character) {
<span class="badge badge-muted"><?php echo (int) $item_result_row['cl_scitemcustom_stat_count']; ?> stat(s)</span> <span class="badge badge-muted"><?php echo (int) $item_result_row['cl_scitemcustom_stat_count']; ?> stat(s)</span>
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php if ($result_is_custom && $result_stats !== []): ?>
<div class="equip-stats search-result-stats">
<?php foreach ($result_stats as $stat_row): ?>
<span class="equip-stat"><?php echo htmlspecialchars(sccharacters_custom_stat_preview($stat_row), ENT_QUOTES, 'UTF-8'); ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div> </div>
<form method="post" class="item-attach-form"> <form method="post" class="item-attach-form">