diff --git a/database/full.sql b/database/full.sql index 7cafca0..e2361af 100644 --- a/database/full.sql +++ b/database/full.sql @@ -53,6 +53,7 @@ CREATE TABLE `tbl_scobjs` ( `cl_scobjs_uuid` varchar(100) NOT NULL, `cl_scobjs_rarity` varchar(10) DEFAULT '', `cl_scobjs_about` text DEFAULT NULL, + `cl_scobjs_description` text DEFAULT NULL, PRIMARY KEY (`cl_scobjs_id`), UNIQUE KEY `cl_scobjs_uuid` (`cl_scobjs_uuid`) ) ENGINE=InnoDB AUTO_INCREMENT=18305 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; diff --git a/database/schema.sql b/database/schema.sql index d228f2d..3d67f63 100644 --- a/database/schema.sql +++ b/database/schema.sql @@ -125,6 +125,7 @@ CREATE TABLE `tbl_scobjs` ( `cl_scobjs_uuid` varchar(100) NOT NULL, `cl_scobjs_rarity` varchar(10) DEFAULT '', `cl_scobjs_about` text DEFAULT NULL, + `cl_scobjs_description` text DEFAULT NULL, PRIMARY KEY (`cl_scobjs_id`), UNIQUE KEY `cl_scobjs_uuid` (`cl_scobjs_uuid`) ) ENGINE=InnoDB AUTO_INCREMENT=18305 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; diff --git a/db/scitems.php b/db/scitems.php new file mode 100644 index 0000000..d5646af --- /dev/null +++ b/db/scitems.php @@ -0,0 +1,45 @@ +query("SHOW COLUMNS FROM `{$table}` LIKE " . $db->quote($column)); + + return (bool) $stmt->fetch(); +} + +function scitems_bootstrap(): void +{ + static $bootstrapped = false; + + if ($bootstrapped) { + return; + } + + $db = db(); + + $db->exec( + "CREATE TABLE IF NOT EXISTS tbl_scobjs ( + cl_scobjs_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + cl_scobjs_name VARCHAR(255) NOT NULL, + cl_scobjs_type VARCHAR(100) DEFAULT NULL, + cl_scobjs_subtype VARCHAR(100) DEFAULT NULL, + cl_scobjs_uuid VARCHAR(100) NOT NULL, + cl_scobjs_rarity VARCHAR(10) DEFAULT '', + cl_scobjs_about TEXT DEFAULT NULL, + cl_scobjs_description TEXT DEFAULT NULL, + PRIMARY KEY (cl_scobjs_id), + UNIQUE KEY cl_scobjs_uuid (cl_scobjs_uuid) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" + ); + + if (!scitems_column_exists($db, 'tbl_scobjs', 'cl_scobjs_description')) { + $db->exec( + 'ALTER TABLE tbl_scobjs + ADD COLUMN cl_scobjs_description TEXT DEFAULT NULL AFTER cl_scobjs_about' + ); + } + + $bootstrapped = true; +} diff --git a/index.php b/index.php index 547a1b1..392ecf3 100644 --- a/index.php +++ b/index.php @@ -55,6 +55,20 @@ function index_itemcustom_stat_preview(?string $sign, $value, ?string $unit): st return trim($prefix . $displayValue . ($displayUnit !== '' ? ' ' . $displayUnit : '')); } +function index_vanilla_description_html(?string $description): string +{ + $description = trim((string) $description); + if ($description === '') { + return 'Aucune description.'; + } + + if ($description !== strip_tags($description)) { + return $description; + } + + return nl2br(htmlspecialchars($description, ENT_QUOTES, 'UTF-8')); +} + auth_start_session(); auth_bootstrap(); @@ -306,6 +320,7 @@ if ($has_vanilla_db_access) { OR cl_scobjs_subtype LIKE :vanilla_search OR cl_scobjs_uuid LIKE :vanilla_search OR cl_scobjs_rarity LIKE :vanilla_search + OR cl_scobjs_description LIKE :vanilla_search )"; $vanilla_db_bindings[':vanilla_search'] = '%' . $vanilla_db_search . '%'; } @@ -326,7 +341,7 @@ if ($has_vanilla_db_access) { $vanilla_db_offset = ($vanilla_db_current_page - 1) * $vanilla_db_per_page; $stmt_vanilla_db = $db->prepare( - "SELECT cl_scobjs_id, cl_scobjs_name, cl_scobjs_type, cl_scobjs_subtype, cl_scobjs_uuid, cl_scobjs_rarity + "SELECT cl_scobjs_id, cl_scobjs_name, cl_scobjs_type, cl_scobjs_subtype, cl_scobjs_uuid, cl_scobjs_rarity, cl_scobjs_description FROM tbl_scobjs" . $vanilla_db_where_sql . " ORDER BY cl_scobjs_name ASC, cl_scobjs_type ASC, cl_scobjs_subtype ASC, cl_scobjs_id ASC LIMIT :vanilla_limit OFFSET :vanilla_offset" @@ -345,6 +360,7 @@ if ($has_vanilla_db_access) { $subtype = trim((string) ($row['cl_scobjs_subtype'] ?? '')) ?: '—'; $uuid = trim((string) ($row['cl_scobjs_uuid'] ?? '')) ?: '—'; $rarity = index_scan_normalize_rarity($row['cl_scobjs_rarity'] ?? ''); + $description = trim((string) ($row['cl_scobjs_description'] ?? '')); $vanilla_db_rows[] = [ 'id' => (int) ($row['cl_scobjs_id'] ?? 0), @@ -356,6 +372,7 @@ if ($has_vanilla_db_access) { 'rarity' => $rarity !== '' ? $rarity : '—', 'rarity_label' => $rarity !== '' ? index_scan_rarity_label($rarity) : 'Non définie', 'rarity_class' => index_scan_rarity_class($rarity), + 'description_html' => index_vanilla_description_html($description), ]; } @@ -1345,12 +1362,12 @@ if ($has_vanilla_db_access) { overflow-y: auto; padding-right: 4px; } + .vanilla-db-card { + grid-template-columns: 56px minmax(260px, 380px) minmax(320px, 1fr); + align-items: stretch; + } - .vanilla-db-card { - grid-template-columns: 56px minmax(0, 1fr); - } - - .vanilla-db-card-main { + .vanilla-db-card-main { display: flex; flex-direction: column; justify-content: center; @@ -1382,15 +1399,32 @@ if ($has_vanilla_db_access) { .vanilla-db-card-meta span { word-break: break-all; } + .vanilla-db-card-details { + display: flex; + align-items: flex-start; + justify-content: flex-start; + min-width: 0; + } - .vanilla-db-card-details { - display: flex; - align-items: center; - justify-content: flex-end; - min-width: 0; - } + .vanilla-db-card-description { + width: 100%; + margin: 0; + font-size: 0.8em; + line-height: 1.45; + color: rgba(255, 255, 255, 0.8); + word-break: break-word; + overflow-wrap: anywhere; + } - .vanilla-db-muted { + .vanilla-db-card-description p { + margin: 0 0 0.45em; + } + + .vanilla-db-card-description p:last-child { + margin-bottom: 0; + } + + .vanilla-db-muted { color: rgba(255, 255, 255, 0.45); } @@ -1932,6 +1966,9 @@ if ($has_vanilla_db_access) {

UUID : UUID : —

+
+
+
diff --git a/scitems.php b/scitems.php index 6107af3..96fac61 100644 --- a/scitems.php +++ b/scitems.php @@ -1,12 +1,15 @@ prepare("SELECT cl_scobjs_id FROM tbl_scobjs WHERE cl_scobjs_uuid = :uuid"); - $stmt_insert = $db->prepare("INSERT INTO tbl_scobjs (cl_scobjs_name, cl_scobjs_type, cl_scobjs_subtype, cl_scobjs_uuid, cl_scobjs_rarity, cl_scobjs_about) VALUES (:name, :type, :subtype, :uuid, '', '')"); - $stmt_update = $db->prepare("UPDATE tbl_scobjs SET cl_scobjs_name = :name, cl_scobjs_type = :type, cl_scobjs_subtype = :subtype WHERE cl_scobjs_uuid = :uuid"); + $stmt_insert = $db->prepare("INSERT INTO tbl_scobjs (cl_scobjs_name, cl_scobjs_type, cl_scobjs_subtype, cl_scobjs_uuid, cl_scobjs_rarity, cl_scobjs_about, cl_scobjs_description) VALUES (:name, :type, :subtype, :uuid, '', '', :description)"); + $stmt_update = $db->prepare("UPDATE tbl_scobjs SET cl_scobjs_name = :name, cl_scobjs_type = :type, cl_scobjs_subtype = :subtype, cl_scobjs_description = :description WHERE cl_scobjs_uuid = :uuid"); foreach ($items as $item) { - $uuid = $item['reference'] ?? ($item['stdItem']['UUID'] ?? ''); - if (!$uuid) continue; + $uuid = trim((string) ($item['reference'] ?? ($item['stdItem']['UUID'] ?? ''))); + if ($uuid === '') continue; - $name = $item['Name'] ?? ($item['stdItem']['Name'] ?? ''); - $classification = $item['classification'] ?? ''; $parts = explode('.', $classification); $type = $parts[1] ?? ($item['type'] ?? ''); - $subtype = $parts[2] ?? ($item['subType'] ?? ''); + $name = trim((string) ($item['Name'] ?? ($item['stdItem']['Name'] ?? ''))); + $classification = trim((string) ($item['classification'] ?? '')); + $parts = $classification !== '' ? explode('.', $classification) : []; + $type = trim((string) ($parts[1] ?? ($item['type'] ?? ''))); + $subtype = trim((string) ($parts[2] ?? ($item['subType'] ?? ''))); + $description = trim((string) ($item['Description'] ?? ($item['stdItem']['Description'] ?? ''))); + + $payload = [ + 'name' => $name, + 'type' => $type, + 'subtype' => $subtype, + 'uuid' => $uuid, + 'description' => $description !== '' ? $description : null, + ]; $stmt_check->execute(['uuid' => $uuid]); if ($stmt_check->fetch()) { - $stmt_update->execute([ - 'name' => $name, - 'type' => $type, - 'subtype' => $subtype, - 'uuid' => $uuid - ]); + $stmt_update->execute($payload); $count_updated++; } else { - $stmt_insert->execute([ - 'name' => $name, - 'type' => $type, - 'subtype' => $subtype, - 'uuid' => $uuid - ]); + $stmt_insert->execute($payload); $count_new++; } }