33 lines
1.2 KiB
PHP
33 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Vereinswappen. Props: $src (lokaler Pfad relativ zu assets/, oder null/leer),
|
||
|
|
* $name (Vereinsname — für Initialen-Fallback). Das Wappen ist dekorativ (alt=""),
|
||
|
|
* weil der Vereinsname direkt daneben als Text steht. Fehlt das Bild, rendert ein
|
||
|
|
* Initialen-Kreis statt eines kaputten <img>; lädt das Bild im Browser nicht
|
||
|
|
* (z. B. 404), ersetzt assets/js/crest.js es ebenfalls durch die Initialen
|
||
|
|
* (data-club liefert den Namen). Das weiße Chip im CSS hält auch helle/weiße
|
||
|
|
* Logos auf dunklem Grund sichtbar.
|
||
|
|
*/
|
||
|
|
$src = $src ?? null;
|
||
|
|
$name = (string) ($name ?? '');
|
||
|
|
|
||
|
|
$initials = '';
|
||
|
|
foreach (preg_split('/[\s.-]+/', trim($name)) ?: [] as $word) {
|
||
|
|
if ($word !== '') {
|
||
|
|
$initials .= mb_substr($word, 0, 1);
|
||
|
|
}
|
||
|
|
if (mb_strlen($initials) >= 2) {
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$initials = mb_strtoupper($initials !== '' ? $initials : '?');
|
||
|
|
?>
|
||
|
|
<?php if (!empty($src)): ?>
|
||
|
|
<img class="crest" src="<?= e(asset($src)) ?>" alt="" width="40" height="40" loading="lazy" decoding="async" data-club="<?= e($name) ?>">
|
||
|
|
<?php else: ?>
|
||
|
|
<span class="crest crest--initials" aria-hidden="true"><?= e($initials) ?></span>
|
||
|
|
<?php endif; ?>
|