From 4eba8d1fef15b1cc1681c5b0deb1e4771a5099a9 Mon Sep 17 00:00:00 2001 From: Maaxxs <61059039+MaaxxsDev@users.noreply.github.com> Date: Sat, 19 Sep 2026 07:20:33 +0200 Subject: [PATCH] Add onerror fallback for avatars and show a large one on Mein Profil The Discord CDN image is now paired with a hidden letter-placeholder sibling; if the fails to load (stale avatar hash, a tracking blocker on cdn.discordapp.com, etc.) it swaps to the placeholder instead of leaving a broken image icon. Also adds the same avatar, at a larger size, next to the heading on the Mein Profil page. Co-Authored-By: Claude Sonnet 5 --- assets/css/style.css | 11 ++++++++++- includes/functions.php | 35 ++++++++++++++++++++++++----------- profile.php | 9 +++++++-- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/assets/css/style.css b/assets/css/style.css index dc9204a..21c2897 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -173,7 +173,10 @@ a:hover { color: var(--gold-hover); text-decoration: underline; } border: 1px solid rgba(255, 255, 255, 0.15); } -.hero .avatar { margin-bottom: 1rem; } +.avatar-wrap { display: inline-flex; } + +.hero .avatar, +.hero .avatar-wrap { margin-bottom: 1rem; } .app-content { flex: 1; @@ -520,6 +523,12 @@ input:focus, select:focus, textarea:focus { color: var(--gold); } +.profile-header { + display: flex; + align-items: center; + gap: 1.25rem; +} + .profile-grid { display: grid; grid-template-columns: 1fr 1fr; diff --git a/includes/functions.php b/includes/functions.php index 0597d46..09a9d4a 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -135,17 +135,12 @@ function discord_logo(int $size = 24): string // Profilbild: Discord-Avatar, falls verknuepft und gesetzt, sonst ein // Platzhalter mit dem Anfangsbuchstaben des Anzeigenamens auf einem // nutzerfest zugeordneten Hintergrund aus einer zur Lumina-Optik passenden Palette. +// Der Platzhalter wird zusaetzlich immer mitgerendert (nur unsichtbar), damit +// bei einem fehlschlagenden Discord-Bild (abgelaufener Hash, Netzwerk-/ +// Trackingblocker o.ae.) per onerror automatisch darauf zurueckgefallen wird, +// statt ein kaputtes Bild-Icon anzuzeigen. function avatar_html(array $user, int $size = 40): string { - if (!empty($user['discord_id']) && !empty($user['discord_avatar'])) { - $ext = str_starts_with((string) $user['discord_avatar'], 'a_') ? 'gif' : 'png'; - $url = 'https://cdn.discordapp.com/avatars/' . rawurlencode((string) $user['discord_id']) - . '/' . rawurlencode((string) $user['discord_avatar']) . '.' . $ext . '?size=' . ($size * 2); - - return ''; - } - static $palette = ['#4f6f52', '#6a4c93', '#1b6ca8', '#b5533c', '#8a6d3b', '#3f6c86', '#4a5568', '#a4443a']; $name = trim((string) ($user['display_name'] ?? '')) !== '' ? $user['display_name'] : (string) ($user['username'] ?? ''); @@ -158,8 +153,26 @@ function avatar_html(array $user, int $size = 40): string $color = $palette[crc32($seed) % count($palette)]; $fontSize = round($size * 0.42, 1); - return '' . e($letter) . ''; + $hasDiscordAvatar = !empty($user['discord_id']) && !empty($user['discord_avatar']); + + $placeholderStyle = 'width:' . $size . 'px;height:' . $size . 'px;background:' . e($color) . ';font-size:' . $fontSize . 'px;' + . ($hasDiscordAvatar ? 'display:none;' : ''); + $placeholder = '' . e($letter) . ''; + + if (!$hasDiscordAvatar) { + return $placeholder; + } + + $ext = str_starts_with((string) $user['discord_avatar'], 'a_') ? 'gif' : 'png'; + $url = 'https://cdn.discordapp.com/avatars/' . rawurlencode((string) $user['discord_id']) + . '/' . rawurlencode((string) $user['discord_avatar']) . '.' . $ext . '?size=' . ($size * 2); + + return '' + . '" + . $placeholder + . ''; } // Ordnet die (teils deutschen) Klassennamen aus dem Raid-Bot den Icon-Dateien diff --git a/profile.php b/profile.php index b6383cd..f253a3e 100644 --- a/profile.php +++ b/profile.php @@ -41,8 +41,13 @@ $pageTitle = 'Mein Profil'; include __DIR__ . '/includes/header.php'; ?> - Mein Profil - Benutzername: = e($user['username']) ?> + + = avatar_html($user, 72) ?> + + Mein Profil + Benutzername: = e($user['username']) ?> + +
Benutzername: = e($user['username']) ?>