Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 9m3s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 9m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m33s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 12m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 11m58s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 50s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m13s
- PageHeader: Kopfband (Standard, kompakt), Kopfband mit Symbol, mit Symbol, kräftiger Titel – Einstellung page_header im Erscheinungsbild - Symbol vom passenden Menüpunkt (aktiv oder per Adresse), Prop icon - In Spalten (z. B. Downloads) schlichte Form statt Band - Zurück-Links als breadcrumbs (IT-Service), Profil bearbeiten mit PageHeader - Plugin-Assets: Fingerabdruck berücksichtigt Änderungszeiten der Dateien Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
208 lines
6 KiB
PHP
208 lines
6 KiB
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
use App\Support\Theme\Icons;
|
||
use App\Support\Theme\Theme;
|
||
use App\Support\Theme\ThemeCompiler;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Throwable;
|
||
|
||
/**
|
||
* Das aktive Erscheinungsbild (docs/PLAN.md, Abschnitt 12): der veröffentlichte
|
||
* Stand – oder der Entwurf, wenn eine berechtigte Person gerade die Vorschau nutzt.
|
||
*/
|
||
class Branding
|
||
{
|
||
public const DEFAULT_NAME = 'Inhaus';
|
||
|
||
public const DEFAULT_PRIMARY_COLOR = '#0F4C5C';
|
||
|
||
public const PREVIEW_SESSION_KEY = 'theme_preview';
|
||
|
||
/** @var array<string, mixed>|null */
|
||
private ?array $active = null;
|
||
|
||
private ?bool $previewing = null;
|
||
|
||
public function __construct(
|
||
private readonly Settings $settings,
|
||
private readonly Theme $theme,
|
||
private readonly ThemeCompiler $compiler,
|
||
) {}
|
||
|
||
/**
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function active(): array
|
||
{
|
||
return $this->active ??= $this->isPreviewing() ? ($this->theme->draft() ?? $this->theme->published()) : $this->theme->published();
|
||
}
|
||
|
||
public function isPreviewing(): bool
|
||
{
|
||
if ($this->previewing !== null) {
|
||
return $this->previewing;
|
||
}
|
||
|
||
try {
|
||
$request = request();
|
||
|
||
return $this->previewing = $request->hasSession()
|
||
&& $request->session()->get(self::PREVIEW_SESSION_KEY) === true
|
||
&& (bool) $request->user()?->can('appearance.manage')
|
||
&& $this->theme->hasDraft();
|
||
} catch (Throwable) {
|
||
return $this->previewing = false;
|
||
}
|
||
}
|
||
|
||
/** Nach dem Speichern eines Entwurfs oder Veröffentlichen neu lesen. */
|
||
public function refresh(): void
|
||
{
|
||
$this->active = null;
|
||
$this->previewing = null;
|
||
}
|
||
|
||
public function get(string $key): mixed
|
||
{
|
||
return $this->active()[$key] ?? null;
|
||
}
|
||
|
||
public function portalName(): string
|
||
{
|
||
return $this->get('portal_name') ?: self::DEFAULT_NAME;
|
||
}
|
||
|
||
public function primaryColor(): string
|
||
{
|
||
return $this->get('primary_color') ?: self::DEFAULT_PRIMARY_COLOR;
|
||
}
|
||
|
||
public function logoPath(): ?string
|
||
{
|
||
return $this->get('logo_light');
|
||
}
|
||
|
||
public function logoUrl(): ?string
|
||
{
|
||
return $this->url($this->get('logo_light'));
|
||
}
|
||
|
||
public function logoDarkUrl(): ?string
|
||
{
|
||
return $this->url($this->get('logo_dark')) ?? $this->logoUrl();
|
||
}
|
||
|
||
/**
|
||
* Eines der Titelbilder, zufällig je Seitenaufruf.
|
||
*
|
||
* @param array<string, mixed> $theme
|
||
*/
|
||
private function randomCover(array $theme): ?string
|
||
{
|
||
$covers = array_values(array_filter((array) ($theme['profile_covers'] ?? []), 'is_string'));
|
||
|
||
return $covers !== [] ? $covers[array_rand($covers)] : ($theme['profile_cover'] ?? null);
|
||
}
|
||
|
||
public function url(?string $path): ?string
|
||
{
|
||
return $path ? Storage::disk('uploads')->url($path) : null;
|
||
}
|
||
|
||
/**
|
||
* @return array<int, string>
|
||
*/
|
||
public function palette(): array
|
||
{
|
||
return ColorPalette::fromHex($this->primaryColor());
|
||
}
|
||
|
||
/**
|
||
* Stylesheet des veröffentlichten Stands; null = inline ausgeben (Vorschau, noch nie veröffentlicht).
|
||
*/
|
||
public function stylesheetUrl(): ?string
|
||
{
|
||
$path = $this->isPreviewing() ? null : $this->get('stylesheet');
|
||
|
||
return $path && Storage::disk('uploads')->exists($path) ? $this->url($path) : null;
|
||
}
|
||
|
||
public function inlineCss(): string
|
||
{
|
||
return $this->compiler->css($this->active());
|
||
}
|
||
|
||
/**
|
||
* @deprecated Nur noch für Übergänge – das Theme liefert alle Variablen.
|
||
*/
|
||
public function cssVariables(): string
|
||
{
|
||
return '--brand:'.$this->primaryColor();
|
||
}
|
||
|
||
public function faviconUrl(): string
|
||
{
|
||
$icons = $this->get('icons') ?? [];
|
||
|
||
return isset($icons[32]) ? $this->url($icons[32]) : Icons::monogram($this->portalName(), $this->primaryColor(), ColorPalette::foregroundFor($this->primaryColor()));
|
||
}
|
||
|
||
public function appleTouchIconUrl(): ?string
|
||
{
|
||
return isset(($this->get('icons') ?? [])[180]) ? $this->url($this->get('icons')[180]) : null;
|
||
}
|
||
|
||
/**
|
||
* Welche Darstellung gilt für eine Person? null = selbst gewählt/Systemeinstellung.
|
||
*/
|
||
public function forcedColorMode(): ?string
|
||
{
|
||
return match ($this->get('dark_mode')) {
|
||
'light' => 'light',
|
||
'dark' => 'dark',
|
||
default => null,
|
||
};
|
||
}
|
||
|
||
/**
|
||
* Für das Portal (Inertia).
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function toArray(): array
|
||
{
|
||
$theme = $this->active();
|
||
|
||
return [
|
||
'portal_name' => $this->portalName(),
|
||
'primary_color' => $this->primaryColor(),
|
||
'logo_url' => $this->logoUrl(),
|
||
'logo_dark_url' => $this->logoDarkUrl(),
|
||
'logo_mark_url' => $this->url($theme['logo_mark']),
|
||
'header_style' => $theme['header_style'],
|
||
'nav_style' => $theme['nav_style'] ?? 'bar',
|
||
'page_header' => $theme['page_header'] ?? 'band',
|
||
'color_mode' => $this->forcedColorMode(),
|
||
'login' => [
|
||
'layout' => $theme['login_layout'],
|
||
'title' => $theme['login_title'],
|
||
'text' => $theme['login_text'],
|
||
'image_url' => $this->url($theme['login_image']),
|
||
],
|
||
// Titelbild in Profil und Begrüßung: eigenes Bild der Person, sonst dieses – immer mit Farbfläche darüber
|
||
'profile_cover' => [
|
||
'image_url' => $this->url($this->randomCover($theme)),
|
||
'overlay' => $theme['profile_cover_overlay'] / 100,
|
||
],
|
||
// Platzhalter für Personen ohne Profilbild (sonst Initialen)
|
||
'avatar_placeholder_url' => $this->url($theme['avatar_placeholder']),
|
||
'footer' => [
|
||
'text' => $theme['footer_text'],
|
||
'links' => $theme['footer_links'],
|
||
],
|
||
'preview' => $this->isPreviewing(),
|
||
];
|
||
}
|
||
}
|