Maps the class names the raid bot returns (a mix of English icon filenames and German in-game terms like "Magier"/"Jäger") to the icon files under assets/images/Classes via class_icon_url(), case- and whitespace-insensitive. Classes without a matching file (e.g. "Templer", or the "Ausstehend" placeholder) just keep the plain text label instead of showing a broken image. Verified against live signup data from the API. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
110 lines
3.8 KiB
PHP
110 lines
3.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
function e(?string $value): string
|
|
{
|
|
return htmlspecialchars($value ?? '', ENT_QUOTES, 'UTF-8');
|
|
}
|
|
|
|
function redirect(string $path): void
|
|
{
|
|
header('Location: ' . $path);
|
|
exit;
|
|
}
|
|
|
|
function csrf_token(): string
|
|
{
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
}
|
|
return $_SESSION['csrf_token'];
|
|
}
|
|
|
|
function csrf_field(): string
|
|
{
|
|
return '<input type="hidden" name="csrf_token" value="' . e(csrf_token()) . '">';
|
|
}
|
|
|
|
function verify_csrf(): void
|
|
{
|
|
$token = $_POST['csrf_token'] ?? '';
|
|
if (!is_string($token) || !hash_equals($_SESSION['csrf_token'] ?? '', $token)) {
|
|
http_response_code(400);
|
|
exit('Ungültige Anfrage (CSRF-Token fehlt oder ist abgelaufen). Bitte Seite neu laden und erneut versuchen.');
|
|
}
|
|
}
|
|
|
|
function set_flash(string $type, string $message): void
|
|
{
|
|
$_SESSION['flash'][] = ['type' => $type, 'message' => $message];
|
|
}
|
|
|
|
function get_flashes(): array
|
|
{
|
|
$flashes = $_SESSION['flash'] ?? [];
|
|
unset($_SESSION['flash']);
|
|
return $flashes;
|
|
}
|
|
|
|
function generate_temp_password(int $length = 12): string
|
|
{
|
|
// Ohne visuell mehrdeutige Zeichen (0/O, 1/l/I, ...), damit sich das
|
|
// Einmalpasswort leicht von Hand abtippen lässt.
|
|
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789';
|
|
$max = strlen($chars) - 1;
|
|
$password = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$password .= $chars[random_int(0, $max)];
|
|
}
|
|
return $password;
|
|
}
|
|
|
|
// Kleine, abhängigkeitsfreie Icon-Sammlung (Strichgrafiken, angelehnt an
|
|
// Feather Icons) für die Sidebar-Navigation.
|
|
function icon(string $name): string
|
|
{
|
|
$paths = [
|
|
'home' => '<path d="M3 9.5 12 3l9 6.5V20a1 1 0 0 1-1 1h-5v-7H9v7H4a1 1 0 0 1-1-1z"/>',
|
|
'users' => '<path d="M16 19v-1.5a3.5 3.5 0 0 0-3.5-3.5h-5A3.5 3.5 0 0 0 4 17.5V19"/><circle cx="9" cy="8" r="3"/><path d="M20 19v-1.5a3.5 3.5 0 0 0-2.5-3.36"/><path d="M14.5 4.6a3 3 0 0 1 0 5.8"/>',
|
|
'shield' => '<path d="M12 21c4.5-1.8 7-5.2 7-9.5V6l-7-3-7 3v5.5c0 4.3 2.5 7.7 7 9.5z"/>',
|
|
'log-out' => '<path d="M9 20H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h3"/><path d="m14 16 4-4-4-4"/><path d="M18 12H9"/>',
|
|
'lock' => '<rect x="4" y="11" width="16" height="9" rx="2"/><path d="M7.5 11V7.5a4.5 4.5 0 0 1 9 0V11"/>',
|
|
'calendar' => '<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M16 3v4"/><path d="M8 3v4"/><path d="M3 10h18"/>',
|
|
];
|
|
|
|
$path = $paths[$name] ?? '';
|
|
|
|
return '<svg class="icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" '
|
|
. 'stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' . $path . '</svg>';
|
|
}
|
|
|
|
// Ordnet die (teils deutschen) Klassennamen aus dem Raid-Bot den Icon-Dateien
|
|
// unter assets/images/Classes zu. Gibt null zurück, wenn keine passende
|
|
// Datei existiert (z.B. bei "Templer" oder "Ausstehend").
|
|
function class_icon_url(string $className): ?string
|
|
{
|
|
static $map = [
|
|
'assassin' => 'Assassin_ICO.png',
|
|
'assassine' => 'Assassin_ICO.png',
|
|
'chanter' => 'Chanter_ICO.png',
|
|
'barde' => 'Chanter_ICO.png',
|
|
'gesangsmeister' => 'Chanter_ICO.png',
|
|
'cleric' => 'Cleric_ICO.png',
|
|
'kleriker' => 'Cleric_ICO.png',
|
|
'gladiator' => 'Gladiator_ICO.png',
|
|
'ranger' => 'Ranger_ICO.png',
|
|
'waldläufer' => 'Ranger_ICO.png',
|
|
'jäger' => 'Ranger_ICO.png',
|
|
'sorcerer' => 'Sorcerer_ICO.png',
|
|
'magier' => 'Sorcerer_ICO.png',
|
|
'spiritmaster' => 'Spiritmaster_ICO.png',
|
|
'geisterbeschwörer' => 'Spiritmaster_ICO.png',
|
|
];
|
|
|
|
$key = mb_strtolower(trim($className), 'UTF-8');
|
|
if (!isset($map[$key])) {
|
|
return null;
|
|
}
|
|
|
|
return '/assets/images/Classes/' . $map[$key];
|
|
}
|