Phase 5: Erscheinungsbild mit Entwurf, Vorschau und Veröffentlichen
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m11s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m16s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m18s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m46s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m7s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m11s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m16s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m18s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m49s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m46s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s
- Theme in den Einstellungen (Entwurf/veröffentlicht), Übernahme der Einstellungen aus Phase 0; statische CSS-Datei mit Hash beim Veröffentlichen - Logos hell/dunkel, Signet, App-Symbol → Favicon, Homescreen-Symbole, Web-App-Manifest; SVG-Bereinigung - Markenfarbe exakt, zweite Akzentfarbe, Kopfleiste hell/Marke/dunkel, Kontrastprüfung (WCAG AA) mit automatisch lesbarer Linkfarbe - Lokale Schriften (Latein), Überschriften-Schrift, eigene WOFF2-Schrift, Ecken, Dichte, Dunkelmodus-Regel - Anmeldeseite (geteilt/zentriert, Bild, Texte), Fußzeile, E-Mails im Design - Admin: Live-Vorschau (Startseite, Anmeldung, Beispielseite; hell/dunkel), Veröffentlichen, Verwerfen, Export/Import, Zurücksetzen, eigenes CSS - Admin-Bereich übernimmt Logo, Farbe und Favicon; Whitelabel Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ee8dde93c0
commit
82bbeef31b
148 changed files with 2884 additions and 362 deletions
|
|
@ -2,27 +2,46 @@
|
|||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Support\Audit;
|
||||
use App\Support\Branding;
|
||||
use App\Support\Settings;
|
||||
use App\Support\Theme\Contrast;
|
||||
use App\Support\Theme\Fonts;
|
||||
use App\Support\Theme\Icons;
|
||||
use App\Support\Theme\Theme;
|
||||
use App\Support\Theme\ThemeCompiler;
|
||||
use App\Support\Theme\ThemeTransfer;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Forms\Components\ColorPicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Throwable;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Basis-Branding (Phase 0). Die vollständige Seite „Erscheinungsbild“ mit
|
||||
* Logo-Varianten, Schriften, Vorschau usw. folgt in Phase 5.
|
||||
* „Erscheinungsbild“ (docs/PLAN.md, Abschnitt 12): Entwurf bearbeiten, in der
|
||||
* Vorschau ansehen, dann für alle veröffentlichen.
|
||||
*/
|
||||
class Appearance extends Page
|
||||
{
|
||||
protected string $view = 'filament.pages.settings-form';
|
||||
protected string $view = 'filament.pages.appearance';
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPaintBrush;
|
||||
|
||||
|
|
@ -32,75 +51,194 @@ class Appearance extends Page
|
|||
|
||||
protected static ?string $title = 'Erscheinungsbild';
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('appearance.manage') ?? false;
|
||||
}
|
||||
|
||||
protected static ?string $slug = 'erscheinungsbild';
|
||||
|
||||
/** @var array<string, mixed>|null */
|
||||
public ?array $data = [];
|
||||
|
||||
public function mount(Branding $branding): void
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
$this->form->fill([
|
||||
'portal_name' => $branding->portalName(),
|
||||
'primary_color' => $branding->primaryColor(),
|
||||
'logo_path' => $branding->logoPath(),
|
||||
]);
|
||||
return auth()->user()?->can('appearance.manage') ?? false;
|
||||
}
|
||||
|
||||
public function mount(Theme $theme): void
|
||||
{
|
||||
$this->form->fill($theme->working());
|
||||
}
|
||||
|
||||
public function hasDraft(): bool
|
||||
{
|
||||
return app(Theme::class)->hasDraft();
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Portal')
|
||||
->description('Name und Logo erscheinen im Kopfbereich, auf der Anmeldeseite und im Browser-Tab.')
|
||||
->schema([
|
||||
TextInput::make('portal_name')
|
||||
->label('Name des Portals')
|
||||
->placeholder(Branding::DEFAULT_NAME)
|
||||
->maxLength(60),
|
||||
FileUpload::make('logo_path')
|
||||
->label('Logo')
|
||||
->helperText('SVG, PNG oder WebP, am besten mit transparentem Hintergrund.')
|
||||
->disk('uploads')
|
||||
->directory('branding')
|
||||
->visibility('public')
|
||||
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp'])
|
||||
->maxSize(2048),
|
||||
$image = fn (string $name, string $label, string $help) => FileUpload::make($name)->label($label)->helperText($help)
|
||||
->disk('uploads')->directory('theme')->visibility('public')->maxSize(4096);
|
||||
|
||||
return $schema->statePath('data')->components([
|
||||
Tabs::make()->persistTabInQueryString()->tabs([
|
||||
Tab::make('Identität')->icon(Heroicon::OutlinedIdentification)->columns(2)->schema([
|
||||
TextInput::make('portal_name')->label('Name des Portals')->required()->maxLength(60)
|
||||
->helperText('Erscheint im Kopfbereich, im Browser-Tab, in E-Mails und auf dem Homescreen.')->columnSpanFull(),
|
||||
$image('logo_light', 'Logo für helle Flächen', 'SVG, PNG oder WebP mit transparentem Hintergrund.')
|
||||
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']),
|
||||
$image('logo_dark', 'Logo für dunkle Flächen', 'Für den Dunkelmodus und farbige Kopfleisten, z. B. in Weiß. Leer = wie hell.')
|
||||
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']),
|
||||
$image('logo_mark', 'Signet (quadratisch)', 'Kurzform für Smartphones, z. B. nur das Bildzeichen.')
|
||||
->acceptedFileTypes(['image/svg+xml', 'image/png', 'image/webp']),
|
||||
$image('app_icon', 'App-Symbol', 'Quadratisch, mindestens 512 × 512 Pixel (PNG oder JPG). Daraus entstehen Favicon und Homescreen-Symbole.')
|
||||
->image()->acceptedFileTypes(['image/png', 'image/jpeg', 'image/webp']),
|
||||
]),
|
||||
|
||||
Tab::make('Farben')->icon(Heroicon::OutlinedSwatch)->columns(2)->schema([
|
||||
ColorPicker::make('primary_color')->label('Markenfarbe')->required()->regex('/^#[0-9a-fA-F]{6}$/')->live(onBlur: true)
|
||||
->helperText('Wird exakt übernommen: Schaltflächen, aktive Navigation, Begrüßungskarte. Die Abstufungen werden berechnet.'),
|
||||
ColorPicker::make('secondary_color')->label('Zweite Akzentfarbe (optional)')->regex('/^#[0-9a-fA-F]{6}$/')->live(onBlur: true)
|
||||
->helperText('Für Kategorien und Datumsangaben. Leer = Markenfarbe.'),
|
||||
Radio::make('header_style')->label('Kopfleiste')->options(Theme::HEADER_STYLES)->inline()->required()->columnSpanFull(),
|
||||
Section::make('Kontrastprüfung (WCAG AA)')->columnSpanFull()->compact()->schema([
|
||||
Text::make(fn (Get $get) => $this->contrastReport((string) $get('primary_color'), $get('secondary_color'))),
|
||||
]),
|
||||
Section::make('Farben')
|
||||
->description('Aus der Primärfarbe wird die komplette Farbpalette für den hellen und den dunklen Modus berechnet.')
|
||||
->schema([
|
||||
ColorPicker::make('primary_color')
|
||||
->label('Primärfarbe')
|
||||
->regex('/^#[0-9a-fA-F]{6}$/')
|
||||
->required(),
|
||||
]),
|
||||
])
|
||||
->statePath('data');
|
||||
]),
|
||||
|
||||
Tab::make('Schrift & Form')->icon(Heroicon::OutlinedLanguage)->columns(2)->schema([
|
||||
Select::make('font_body')->label('Schrift')->options(fn (Get $get) => Fonts::options((bool) $get('custom_font')))->required()->native(false),
|
||||
Select::make('font_heading')->label('Schrift für Überschriften')->options(fn (Get $get) => ['same' => 'Wie die Schrift'] + Fonts::options((bool) $get('custom_font')))->required()->native(false),
|
||||
FileUpload::make('custom_font')->label('Eigene Schrift (WOFF2)')
|
||||
->helperText('Z. B. die Hausschrift aus dem Corporate Design. Wird lokal ausgeliefert – keine Verbindung zu Google oder anderen Diensten. Bitte die Lizenz für die Nutzung im Web beachten.')
|
||||
->disk('uploads')->directory('theme/fonts')->visibility('public')->maxSize(2048)
|
||||
->acceptedFileTypes(['font/woff2', 'application/font-woff2', 'application/octet-stream'])
|
||||
->rule('extensions:woff2')->live()->columnSpanFull(),
|
||||
Radio::make('radius')->label('Ecken')->options(collect(Theme::RADII)->map(fn ($r) => $r[0])->all())->inline()->required(),
|
||||
Radio::make('density')->label('Abstände')->options(collect(Theme::DENSITIES)->map(fn ($d) => $d[0])->all())->inline()->required(),
|
||||
Radio::make('dark_mode')->label('Dunkelmodus')->options(Theme::DARK_MODES)->required()->columnSpanFull(),
|
||||
]),
|
||||
|
||||
Tab::make('Anmeldeseite')->icon(Heroicon::OutlinedArrowRightOnRectangle)->columns(2)->schema([
|
||||
Radio::make('login_layout')->label('Aufteilung')->options(Theme::LOGIN_LAYOUTS)->required()->columnSpanFull(),
|
||||
TextInput::make('login_title')->label('Begrüßung')->maxLength(200)->columnSpanFull(),
|
||||
Textarea::make('login_text')->label('Text darunter')->rows(2)->maxLength(500)->columnSpanFull(),
|
||||
$image('login_image', 'Hintergrundbild', 'Querformat, mindestens 1600 Pixel breit. Leer = Fläche in der Markenfarbe.')
|
||||
->image()->acceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])->maxSize(8192)->columnSpanFull(),
|
||||
]),
|
||||
|
||||
Tab::make('Fußzeile & E-Mails')->icon(Heroicon::OutlinedEnvelope)->schema([
|
||||
TextInput::make('footer_text')->label('Text in der Fußzeile')->placeholder('© 2027 Musterstift gGmbH')->maxLength(200),
|
||||
Repeater::make('footer_links')->label('Links in der Fußzeile')->columns(2)->defaultItems(0)->reorderable()
|
||||
->addActionLabel('Link hinzufügen')->maxItems(8)
|
||||
->schema([
|
||||
TextInput::make('label')->label('Bezeichnung')->required()->maxLength(60)->placeholder('Impressum'),
|
||||
TextInput::make('url')->label('Adresse')->required()->maxLength(500)->placeholder('https://… oder /seiten/impressum'),
|
||||
]),
|
||||
Textarea::make('email_footer')->label('Fußzeile in E-Mails')->rows(3)->maxLength(500)
|
||||
->helperText('Z. B. Anschrift und Hinweis. Logo und Markenfarbe übernehmen die E-Mails automatisch.'),
|
||||
]),
|
||||
|
||||
Tab::make('Erweitert')->icon(Heroicon::OutlinedCodeBracket)->schema([
|
||||
Textarea::make('custom_css')->label('Eigenes CSS')->rows(12)->maxLength(50000)
|
||||
->extraInputAttributes(['class' => 'font-mono text-xs', 'spellcheck' => 'false'])
|
||||
->helperText('Für Fortgeschrittene. Wird nach dem Portal-CSS geladen und bei Aktualisierungen unverändert übernommen. Klassennamen können sich mit neuen Versionen ändern – bitte nach jedem Update prüfen. Verfügbare Variablen: --brand, --brand-50 … --brand-950, --radius, --font-body, --font-heading.'),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Settings $settings, Branding $branding): void
|
||||
private function contrastReport(string $primary, ?string $secondary): HtmlString
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$previousLogo = $branding->logoPath();
|
||||
|
||||
$settings->setMany([
|
||||
'branding.portal_name' => filled($data['portal_name']) ? trim($data['portal_name']) : null,
|
||||
'branding.primary_color' => strtoupper($data['primary_color']),
|
||||
'branding.logo_path' => $data['logo_path'] ?: null,
|
||||
]);
|
||||
|
||||
if ($previousLogo && $previousLogo !== $data['logo_path']) {
|
||||
Storage::disk('uploads')->delete($previousLogo);
|
||||
if (! preg_match('/^#[0-9a-fA-F]{6}$/', $primary)) {
|
||||
return new HtmlString('');
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Erscheinungsbild gespeichert')
|
||||
->send();
|
||||
$colors = ['ok' => '#15803d', 'info' => '#0369a1', 'warning' => '#b45309'];
|
||||
$icons = ['ok' => '✓', 'info' => 'i', 'warning' => '!'];
|
||||
|
||||
return new HtmlString(collect(Contrast::report(strtoupper($primary), $secondary && preg_match('/^#[0-9a-fA-F]{6}$/', $secondary) ? strtoupper($secondary) : null))
|
||||
->map(fn ($note) => '<p style="display:flex;gap:.5rem;margin:.25rem 0"><span style="font-weight:700;color:'.$colors[$note['level']].';width:1rem;text-align:center">'.$icons[$note['level']].'</span><span>'.e($note['text']).'</span></p>')
|
||||
->implode(''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Entwurf speichern und die Vorschau aktualisieren.
|
||||
*/
|
||||
public function save(Theme $theme, Branding $branding): void
|
||||
{
|
||||
$theme->saveDraft($this->form->getState());
|
||||
session()->put(Branding::PREVIEW_SESSION_KEY, true);
|
||||
$branding->refresh();
|
||||
|
||||
$this->dispatch('theme-preview-reload');
|
||||
Notification::make()->success()->title('Entwurf gespeichert')->body('Die Vorschau zeigt jetzt den Entwurf. Für alle sichtbar wird er erst mit „Veröffentlichen“.')->send();
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('publish')->label('Veröffentlichen')->icon(Heroicon::OutlinedRocketLaunch)
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Erscheinungsbild veröffentlichen?')
|
||||
->modalDescription('Der gespeicherte Entwurf wird für alle sichtbar. Ungespeicherte Änderungen im Formular werden vorher als Entwurf gespeichert.')
|
||||
->action(function (Theme $theme, ThemeCompiler $compiler, Icons $icons, Branding $branding) {
|
||||
$theme->saveDraft($this->form->getState());
|
||||
$theme->publish($compiler, $icons);
|
||||
session()->forget(Branding::PREVIEW_SESSION_KEY);
|
||||
$branding->refresh();
|
||||
Audit::log('appearance.published');
|
||||
|
||||
$this->form->fill($theme->working());
|
||||
$this->dispatch('theme-preview-reload');
|
||||
Notification::make()->success()->title('Erscheinungsbild veröffentlicht')->send();
|
||||
}),
|
||||
Action::make('discard')->label('Entwurf verwerfen')->icon(Heroicon::OutlinedArrowUturnLeft)->color('gray')
|
||||
->visible(fn () => $this->hasDraft())
|
||||
->requiresConfirmation()
|
||||
->action(function (Theme $theme, Branding $branding) {
|
||||
$theme->discardDraft();
|
||||
session()->forget(Branding::PREVIEW_SESSION_KEY);
|
||||
$branding->refresh();
|
||||
$this->form->fill($theme->working());
|
||||
$this->dispatch('theme-preview-reload');
|
||||
}),
|
||||
ActionGroup::make([
|
||||
Action::make('export')->label('Exportieren')->icon(Heroicon::OutlinedArrowDownTray)
|
||||
->action(fn (ThemeTransfer $transfer): StreamedResponse => response()->streamDownload(
|
||||
fn () => print (json_encode($transfer->export(app(Theme::class)->working()), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)),
|
||||
'erscheinungsbild-'.now()->format('Y-m-d').'.json',
|
||||
['Content-Type' => 'application/json'],
|
||||
)),
|
||||
Action::make('import')->label('Importieren')->icon(Heroicon::OutlinedArrowUpTray)
|
||||
->modalDescription('Erscheinungsbild aus einer exportierten Datei übernehmen – als Entwurf, damit Sie es erst ansehen können.')
|
||||
->schema([
|
||||
FileUpload::make('file')->label('Datei (.json)')->disk('local')->directory('theme-import')
|
||||
->acceptedFileTypes(['application/json', 'text/plain'])->maxSize(20 * 1024)->required(),
|
||||
])
|
||||
->action(function (array $data, ThemeTransfer $transfer, Theme $theme) {
|
||||
try {
|
||||
$values = $transfer->import((string) Storage::disk('local')->get($data['file']));
|
||||
} catch (Throwable $e) {
|
||||
Notification::make()->danger()->title('Import nicht möglich')->body($e->getMessage())->send();
|
||||
|
||||
return;
|
||||
} finally {
|
||||
Storage::disk('local')->delete($data['file']);
|
||||
}
|
||||
|
||||
$theme->saveDraft($values);
|
||||
session()->put(Branding::PREVIEW_SESSION_KEY, true);
|
||||
$this->form->fill($theme->working());
|
||||
$this->dispatch('theme-preview-reload');
|
||||
Notification::make()->success()->title('Als Entwurf importiert')->send();
|
||||
}),
|
||||
Action::make('reset')->label('Auf Standard zurücksetzen')->icon(Heroicon::OutlinedArrowPath)->color('danger')
|
||||
->requiresConfirmation()
|
||||
->modalDescription('Setzt Farben, Schriften, Logos und Texte auf die Standardwerte zurück – als Entwurf. Der Portalname bleibt.')
|
||||
->action(function (Theme $theme) {
|
||||
$theme->resetToDefaults();
|
||||
session()->put(Branding::PREVIEW_SESSION_KEY, true);
|
||||
$this->form->fill($theme->working());
|
||||
$this->dispatch('theme-preview-reload');
|
||||
}),
|
||||
])->label('Mehr')->icon(Heroicon::OutlinedEllipsisVertical)->button()->color('gray'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
86
app/Http/Controllers/AppearanceController.php
Normal file
86
app/Http/Controllers/AppearanceController.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\IdentityProvider;
|
||||
use App\Pagebuilder\Content;
|
||||
use App\Support\Branding;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
/**
|
||||
* Web-App-Manifest und die Vorschauseiten für „Erscheinungsbild“.
|
||||
*/
|
||||
class AppearanceController extends Controller
|
||||
{
|
||||
public function manifest(Branding $branding): JsonResponse
|
||||
{
|
||||
$icons = collect($branding->get('icons') ?? [])
|
||||
->reject(fn ($path, $size) => (int) $size < 192)
|
||||
->map(fn ($path, $size) => ['src' => $branding->url($path), 'sizes' => "{$size}x{$size}", 'type' => 'image/png', 'purpose' => 'any'])
|
||||
->values();
|
||||
|
||||
if ($icons->isEmpty()) {
|
||||
$icons = collect([['src' => $branding->faviconUrl(), 'sizes' => 'any', 'type' => 'image/svg+xml']]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'name' => $branding->portalName(),
|
||||
'short_name' => mb_substr($branding->portalName(), 0, 12),
|
||||
'start_url' => '/',
|
||||
'scope' => '/',
|
||||
'display' => 'standalone',
|
||||
'lang' => 'de',
|
||||
'theme_color' => $branding->primaryColor(),
|
||||
'background_color' => '#F4F5F7',
|
||||
'icons' => $icons->all(),
|
||||
], 200, ['Content-Type' => 'application/manifest+json', 'Cache-Control' => 'public, max-age=3600']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Anmeldeseite im aktuellen Entwurf – für die Vorschau (Formular ohne Funktion).
|
||||
*/
|
||||
public function loginPreview(Request $request): Response
|
||||
{
|
||||
return Inertia::render('Auth/Login', [
|
||||
'canResetPassword' => true,
|
||||
'providers' => IdentityProvider::query()->where('enabled', true)->get()
|
||||
->map(fn (IdentityProvider $p) => ['slug' => $p->slug, 'type' => $p->type, 'label' => $p->buttonLabel()])->values(),
|
||||
'preview' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Beispielseite mit Boxen, Tabs, Akkordeon, Tabelle und Schaltflächen.
|
||||
*/
|
||||
public function sample(Request $request, Content $content): Response
|
||||
{
|
||||
$text = fn (string $html) => ['type' => 'text', 'data' => ['html' => $html]];
|
||||
$box = fn (string $variant, string $title, string $html) => ['type' => 'box', 'data' => ['variant' => $variant, 'title' => $title, 'show_icon' => true], 'items' => [['blocks' => [$text($html)]]]];
|
||||
|
||||
$blocks = [
|
||||
['type' => 'heading', 'data' => ['text' => 'Überschrift der Seite', 'level' => '2']],
|
||||
$text('<p>Fließtext mit einem <a href="#">Link in der Akzentfarbe</a>, <strong>Hervorhebungen</strong> und einer Liste:</p><ul><li>erster Punkt</li><li>zweiter Punkt</li></ul>'),
|
||||
['type' => 'columns', 'data' => ['layout' => '1-1'], 'items' => [
|
||||
['blocks' => [$box('info', 'Info', '<p>Sprechstunde dienstags 14–16 Uhr.</p>'), $box('warning', 'Warnung', '<p>Bitte bis Freitag einreichen.</p>')]],
|
||||
['blocks' => [$box('success', 'Erfolg', '<p>Das neue Verfahren gilt ab sofort.</p>'), $box('highlight', 'Hervorgehoben', '<p>In der Markenfarbe.</p>')]],
|
||||
]],
|
||||
['type' => 'tabs', 'items' => [
|
||||
['title' => 'Erster Tab', 'blocks' => [$text('<p>Inhalt des ersten Tabs.</p>')]],
|
||||
['title' => 'Zweiter Tab', 'blocks' => [$text('<p>Inhalt des zweiten Tabs.</p>')]],
|
||||
]],
|
||||
['type' => 'accordion', 'data' => ['first_open' => true], 'items' => [
|
||||
['title' => 'Häufige Frage', 'blocks' => [$text('<p>Die Antwort steht hier.</p>')]],
|
||||
['title' => 'Noch eine Frage', 'blocks' => [$text('<p>Noch eine Antwort.</p>')]],
|
||||
]],
|
||||
['type' => 'table', 'data' => ['header' => true, 'rows' => [['Bereich', 'Ansprechpartner', 'Durchwahl'], ['Personal', 'A. Beispiel', '123'], ['IT', 'B. Muster', '456']]]],
|
||||
['type' => 'buttons', 'data' => ['buttons' => [['label' => 'Primäre Schaltfläche', 'url' => '#', 'variant' => 'primary'], ['label' => 'Umrandet', 'url' => '#', 'variant' => 'outline']]]],
|
||||
];
|
||||
|
||||
return Inertia::render('Appearance/Sample', [
|
||||
'content' => $content->render($content->sanitize(['blocks' => $blocks]), $request->user()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
32
app/Http/Middleware/ThemePreview.php
Normal file
32
app/Http/Middleware/ThemePreview.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Support\Branding;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Vorschau des Entwurfs im Portal: ?vorschau=entwurf schaltet sie für die
|
||||
* Sitzung ein, ?vorschau=aus wieder aus. Nur mit „Erscheinungsbild“-Recht.
|
||||
*/
|
||||
class ThemePreview
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$value = $request->query('vorschau');
|
||||
|
||||
if ($value !== null && $request->hasSession()) {
|
||||
if ($value === 'entwurf' && $request->user()?->can('appearance.manage')) {
|
||||
$request->session()->put(Branding::PREVIEW_SESSION_KEY, true);
|
||||
} elseif ($value === 'aus') {
|
||||
$request->session()->forget(Branding::PREVIEW_SESSION_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
app(Branding::class)->refresh();
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ use App\Support\Permissions\Permissions;
|
|||
use App\Support\ProfileFields;
|
||||
use App\Support\QuickLinks;
|
||||
use App\Support\Settings;
|
||||
use App\Support\Theme\Theme;
|
||||
use App\Support\Theme\ThemeCompiler;
|
||||
use App\Support\Update\InstalledVersion;
|
||||
use App\Support\Update\MaintenanceFlag;
|
||||
use App\Support\Update\UpdateProgress;
|
||||
|
|
@ -45,6 +47,8 @@ class AppServiceProvider extends ServiceProvider
|
|||
$this->app->singleton(Settings::class);
|
||||
$this->app->singleton(MailSettings::class);
|
||||
$this->app->singleton(Branding::class);
|
||||
$this->app->singleton(Theme::class);
|
||||
$this->app->singleton(ThemeCompiler::class);
|
||||
$this->app->singleton(Avatars::class);
|
||||
$this->app->singleton(QuickLinks::class);
|
||||
$this->app->singleton(LicenseStore::class);
|
||||
|
|
@ -89,6 +93,13 @@ class AppServiceProvider extends ServiceProvider
|
|||
|
||||
if (Installation::isInstalled()) {
|
||||
$this->app->make(MailSettings::class)->apply();
|
||||
|
||||
// Whitelabel: Laravel nutzt app.name z. B. in Benachrichtigungs-Mails („Viele Grüße …“).
|
||||
try {
|
||||
config(['app.name' => $this->app->make(Branding::class)->portalName()]);
|
||||
} catch (\Throwable) {
|
||||
// Datenbank noch nicht bereit
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ class AdminPanelProvider extends PanelProvider
|
|||
->defaultAvatarProvider(InitialsAvatarProvider::class)
|
||||
->brandName(fn () => app(Branding::class)->portalName())
|
||||
->brandLogo(fn () => app(Branding::class)->logoUrl())
|
||||
->darkModeBrandLogo(fn () => app(Branding::class)->logoDarkUrl())
|
||||
->brandLogoHeight('2rem')
|
||||
->favicon(fn () => app(Branding::class)->faviconUrl())
|
||||
->colors(fn () => [
|
||||
'primary' => app(Branding::class)->palette(),
|
||||
])
|
||||
|
|
|
|||
|
|
@ -2,11 +2,15 @@
|
|||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Basis-Branding der Installation (Phase 0): Portalname, Logo, Primärfarbe.
|
||||
* Das vollständige Erscheinungsbild folgt in Phase 5 (docs/PLAN.md, Abschnitt 12).
|
||||
* 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
|
||||
{
|
||||
|
|
@ -14,31 +18,84 @@ class Branding
|
|||
|
||||
public const DEFAULT_PRIMARY_COLOR = '#0F4C5C';
|
||||
|
||||
public function __construct(private readonly Settings $settings) {}
|
||||
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->settings->get('branding.portal_name') ?: self::DEFAULT_NAME;
|
||||
return $this->get('portal_name') ?: self::DEFAULT_NAME;
|
||||
}
|
||||
|
||||
public function primaryColor(): string
|
||||
{
|
||||
$color = $this->settings->get('branding.primary_color');
|
||||
|
||||
return is_string($color) && preg_match('/^#[0-9a-fA-F]{6}$/', $color)
|
||||
? strtoupper($color)
|
||||
: self::DEFAULT_PRIMARY_COLOR;
|
||||
return $this->get('primary_color') ?: self::DEFAULT_PRIMARY_COLOR;
|
||||
}
|
||||
|
||||
public function logoPath(): ?string
|
||||
{
|
||||
return $this->settings->get('branding.logo_path') ?: null;
|
||||
return $this->get('logo_light');
|
||||
}
|
||||
|
||||
public function logoUrl(): ?string
|
||||
{
|
||||
$path = $this->logoPath();
|
||||
return $this->url($this->get('logo_light'));
|
||||
}
|
||||
|
||||
public function logoDarkUrl(): ?string
|
||||
{
|
||||
return $this->url($this->get('logo_dark')) ?? $this->logoUrl();
|
||||
}
|
||||
|
||||
public function url(?string $path): ?string
|
||||
{
|
||||
return $path ? Storage::disk('uploads')->url($path) : null;
|
||||
}
|
||||
|
||||
|
|
@ -51,33 +108,80 @@ class Branding
|
|||
}
|
||||
|
||||
/**
|
||||
* CSS-Variablen für das Portal. Werden serverseitig in die Seite geschrieben –
|
||||
* ohne Build und ohne Farbberechnung im Browser.
|
||||
* Stylesheet des veröffentlichten Stands; null = inline ausgeben (Vorschau, noch nie veröffentlicht).
|
||||
*/
|
||||
public function cssVariables(): string
|
||||
public function stylesheetUrl(): ?string
|
||||
{
|
||||
$color = $this->primaryColor();
|
||||
$variables = [
|
||||
'--brand' => $color,
|
||||
'--brand-foreground' => ColorPalette::foregroundFor($color),
|
||||
];
|
||||
$path = $this->isPreviewing() ? null : $this->get('stylesheet');
|
||||
|
||||
foreach ($this->palette() as $shade => $hex) {
|
||||
$variables["--brand-{$shade}"] = $hex;
|
||||
}
|
||||
return $path && Storage::disk('uploads')->exists($path) ? $this->url($path) : null;
|
||||
}
|
||||
|
||||
return collect($variables)->map(fn (string $value, string $name) => "{$name}:{$value}")->implode(';');
|
||||
public function inlineCss(): string
|
||||
{
|
||||
return $this->compiler->css($this->active());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{portal_name: string, primary_color: string, logo_url: string|null}
|
||||
* @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'],
|
||||
'color_mode' => $this->forcedColorMode(),
|
||||
'login' => [
|
||||
'layout' => $theme['login_layout'],
|
||||
'title' => $theme['login_title'],
|
||||
'text' => $theme['login_text'],
|
||||
'image_url' => $this->url($theme['login_image']),
|
||||
],
|
||||
'footer' => [
|
||||
'text' => $theme['footer_text'],
|
||||
'links' => $theme['footer_links'],
|
||||
],
|
||||
'preview' => $this->isPreviewing(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
91
app/Support/Theme/Contrast.php
Normal file
91
app/Support/Theme/Contrast.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
use App\Support\ColorPalette;
|
||||
|
||||
/**
|
||||
* Kontrastprüfung nach WCAG 2.1 (AA: 4,5:1 für Text, 3:1 für große Schrift und Bedienelemente).
|
||||
* Warnt und schlägt vor – blockiert nichts.
|
||||
*/
|
||||
final class Contrast
|
||||
{
|
||||
public const LIGHT_BACKGROUND = '#FFFFFF';
|
||||
|
||||
public const DARK_BACKGROUND = '#171A1E';
|
||||
|
||||
public const AA = 4.5;
|
||||
|
||||
/**
|
||||
* Farbe für Links und Akzenttext auf hellem Grund: die Markenfarbe selbst,
|
||||
* sonst die erste dunklere Abstufung mit ausreichendem Kontrast.
|
||||
*/
|
||||
public static function textShadeOnLight(string $hex): int
|
||||
{
|
||||
$palette = ColorPalette::fromHex($hex);
|
||||
|
||||
foreach ([600, 700, 800, 900, 950] as $shade) {
|
||||
if (ColorPalette::contrast($palette[$shade], self::LIGHT_BACKGROUND) >= self::AA) {
|
||||
return $shade;
|
||||
}
|
||||
}
|
||||
|
||||
return 950;
|
||||
}
|
||||
|
||||
/**
|
||||
* Farbe für Links und Akzenttext auf dunklem Grund.
|
||||
*/
|
||||
public static function textShadeOnDark(string $hex): int
|
||||
{
|
||||
$palette = ColorPalette::fromHex($hex);
|
||||
|
||||
foreach ([300, 200, 100, 50] as $shade) {
|
||||
if (ColorPalette::contrast($palette[$shade], self::DARK_BACKGROUND) >= self::AA) {
|
||||
return $shade;
|
||||
}
|
||||
}
|
||||
|
||||
return 50;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hinweise für die Seite „Erscheinungsbild“.
|
||||
*
|
||||
* @return list<array{level: string, text: string}>
|
||||
*/
|
||||
public static function report(string $primary, ?string $secondary = null): array
|
||||
{
|
||||
$notes = [];
|
||||
$foreground = ColorPalette::foregroundFor($primary);
|
||||
$onButton = ColorPalette::contrast($primary, $foreground);
|
||||
$onWhite = ColorPalette::contrast($primary, self::LIGHT_BACKGROUND);
|
||||
$palette = ColorPalette::fromHex($primary);
|
||||
|
||||
$notes[] = $onButton >= self::AA
|
||||
? ['level' => 'ok', 'text' => sprintf('Schrift auf Schaltflächen (%s): Kontrast %s:1 – gut lesbar.', $foreground === '#FFFFFF' ? 'weiß' : 'schwarz', self::format($onButton))]
|
||||
: ['level' => 'warning', 'text' => sprintf('Schrift auf Schaltflächen erreicht nur %s:1 (empfohlen mindestens 4,5:1). Eine etwas dunklere oder hellere Markenfarbe wäre besser lesbar, z. B. %s.', self::format($onButton), $palette[700])];
|
||||
|
||||
if ($onWhite >= self::AA) {
|
||||
$notes[] = ['level' => 'ok', 'text' => sprintf('Links auf hellem Grund: Kontrast %s:1 – die Markenfarbe wird unverändert verwendet.', self::format($onWhite))];
|
||||
} else {
|
||||
$shade = self::textShadeOnLight($primary);
|
||||
$notes[] = ['level' => 'info', 'text' => sprintf('Die Markenfarbe ist auf Weiß als Textfarbe zu hell (%s:1). Für Links und Akzenttexte wird automatisch die dunklere Abstufung %s verwendet. Schaltflächen und Flächen behalten die Markenfarbe.', self::format($onWhite), $palette[$shade])];
|
||||
}
|
||||
|
||||
if ($secondary !== null) {
|
||||
$onWhite2 = ColorPalette::contrast($secondary, self::LIGHT_BACKGROUND);
|
||||
|
||||
if ($onWhite2 < 3) {
|
||||
$notes[] = ['level' => 'info', 'text' => sprintf('Die zweite Akzentfarbe ist auf Weiß sehr hell (%s:1). Für Beschriftungen wird automatisch eine dunklere Abstufung verwendet.', self::format($onWhite2))];
|
||||
}
|
||||
}
|
||||
|
||||
return $notes;
|
||||
}
|
||||
|
||||
private static function format(float $ratio): string
|
||||
{
|
||||
return number_format($ratio, 1, ',', '');
|
||||
}
|
||||
}
|
||||
55
app/Support/Theme/Fonts.php
Normal file
55
app/Support/Theme/Fonts.php
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
/**
|
||||
* Mitgelieferte Schriften – lokal ausgeliefert (resources/css/fonts.css,
|
||||
* erzeugt von scripts/generate-fonts-css.py), nie von Google Fonts.
|
||||
*/
|
||||
final class Fonts
|
||||
{
|
||||
public const FALLBACK_SANS = 'ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif';
|
||||
|
||||
public const FALLBACK_SERIF = 'ui-serif, Georgia, Cambria, "Times New Roman", serif';
|
||||
|
||||
/** Schlüssel => [Bezeichnung, CSS-Familie, serif?] */
|
||||
public const FONTS = [
|
||||
'inter' => ['Inter', 'Inter Variable', false],
|
||||
'source-sans-3' => ['Source Sans 3', 'Source Sans 3 Variable', false],
|
||||
'open-sans' => ['Open Sans', 'Open Sans Variable', false],
|
||||
'nunito-sans' => ['Nunito Sans', 'Nunito Sans Variable', false],
|
||||
'roboto' => ['Roboto', 'Roboto Variable', false],
|
||||
'ibm-plex-sans' => ['IBM Plex Sans', 'IBM Plex Sans Variable', false],
|
||||
'figtree' => ['Figtree', 'Figtree Variable', false],
|
||||
'atkinson' => ['Atkinson Hyperlegible (besonders gut lesbar)', 'Atkinson Hyperlegible', false],
|
||||
'source-serif-4' => ['Source Serif 4 (Serifen)', 'Source Serif 4 Variable', true],
|
||||
'merriweather' => ['Merriweather (Serifen)', 'Merriweather Variable', true],
|
||||
'lora' => ['Lora (Serifen)', 'Lora Variable', true],
|
||||
'system' => ['Systemschrift des Geräts', null, false],
|
||||
];
|
||||
|
||||
/** Familienname einer hochgeladenen Schrift. */
|
||||
public const CUSTOM_FAMILY = 'Portal Eigene Schrift';
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public static function options(bool $withCustom = false): array
|
||||
{
|
||||
$options = array_map(fn (array $font) => $font[0], self::FONTS);
|
||||
|
||||
return $withCustom ? $options + ['custom' => 'Eigene Schrift (hochgeladen)'] : $options;
|
||||
}
|
||||
|
||||
public static function stack(string $key): string
|
||||
{
|
||||
if ($key === 'custom') {
|
||||
return '"'.self::CUSTOM_FAMILY.'", '.self::FALLBACK_SANS;
|
||||
}
|
||||
|
||||
[, $family, $serif] = self::FONTS[$key] ?? self::FONTS['inter'];
|
||||
$fallback = $serif ? self::FALLBACK_SERIF : self::FALLBACK_SANS;
|
||||
|
||||
return $family ? '"'.$family.'", '.$fallback : $fallback;
|
||||
}
|
||||
}
|
||||
66
app/Support/Theme/Icons.php
Normal file
66
app/Support/Theme/Icons.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
use App\Support\Images;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\Encoders\PngEncoder;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Favicon und App-Symbole (Homescreen, Web-App) aus einem quadratischen Bild –
|
||||
* in allen üblichen Größen. Ohne Bild: Monogramm in der Markenfarbe (SVG).
|
||||
*/
|
||||
class Icons
|
||||
{
|
||||
public const SIZES = [32, 180, 192, 512];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $theme
|
||||
* @return array<int, string> Größe => Pfad im Speicher „uploads“
|
||||
*/
|
||||
public function generate(array $theme): array
|
||||
{
|
||||
$source = $theme['app_icon'] ?? null;
|
||||
$disk = Storage::disk('uploads');
|
||||
|
||||
if (! $source || ! $disk->exists($source)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
Images::raiseMemoryLimitFor($disk->path($source));
|
||||
$manager = ImageManager::usingDriver(Driver::class);
|
||||
$hash = substr(sha1((string) $disk->get($source)), 0, 10);
|
||||
$result = [];
|
||||
|
||||
foreach (self::SIZES as $size) {
|
||||
$image = $manager->decodePath($disk->path($source));
|
||||
$image->cover($size, $size);
|
||||
$path = "theme/icons/icon-{$hash}-{$size}.png";
|
||||
$disk->put($path, $image->encode(new PngEncoder)->toString());
|
||||
$result[$size] = $path;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monogramm als SVG-Favicon (Daten-URL), wenn kein Symbol hochgeladen ist.
|
||||
*/
|
||||
public static function monogram(string $name, string $color, string $foreground): string
|
||||
{
|
||||
$letter = htmlspecialchars(mb_strtoupper(mb_substr(trim($name), 0, 1)) ?: 'P', ENT_XML1);
|
||||
$svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="14" fill="'.$color.'"/>'
|
||||
.'<text x="32" y="44" font-family="Arial,Helvetica,sans-serif" font-size="34" font-weight="700" text-anchor="middle" fill="'.$foreground.'">'.$letter.'</text></svg>';
|
||||
|
||||
return 'data:image/svg+xml;base64,'.base64_encode($svg);
|
||||
}
|
||||
}
|
||||
62
app/Support/Theme/SvgSanitizer.php
Normal file
62
app/Support/Theme/SvgSanitizer.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use DOMXPath;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Entfernt aus hochgeladenen SVG-Dateien alles Ausführbare (Skripte,
|
||||
* Ereignis-Attribute, javascript:-Links, eingebettetes HTML). Logos werden
|
||||
* öffentlich ausgeliefert und dürfen niemals Code enthalten.
|
||||
*/
|
||||
final class SvgSanitizer
|
||||
{
|
||||
public static function sanitizeFile(?string $path): void
|
||||
{
|
||||
if (! $path || ! str_ends_with(strtolower($path), '.svg')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$disk = Storage::disk('uploads');
|
||||
|
||||
if (! $disk->exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$clean = self::sanitize((string) $disk->get($path));
|
||||
$clean === null ? $disk->delete($path) : $disk->put($path, $clean);
|
||||
}
|
||||
|
||||
public static function sanitize(string $svg): ?string
|
||||
{
|
||||
$dom = new DOMDocument;
|
||||
|
||||
// Keine externen Entitäten, kein Netzwerkzugriff.
|
||||
if (str_contains($svg, '<!ENTITY') || ! @$dom->loadXML($svg, LIBXML_NONET) || $dom->documentElement?->localName !== 'svg') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
foreach (iterator_to_array($xpath->query('//*[local-name()="script" or local-name()="foreignObject" or local-name()="iframe" or local-name()="object" or local-name()="embed"]')) as $node) {
|
||||
$node->parentNode->removeChild($node);
|
||||
}
|
||||
|
||||
foreach (iterator_to_array($xpath->query('//*')) as $element) {
|
||||
/** @var DOMElement $element */
|
||||
foreach (iterator_to_array($element->attributes) as $attribute) {
|
||||
$name = strtolower($attribute->nodeName);
|
||||
$value = strtolower(preg_replace('/\s+/', '', $attribute->nodeValue));
|
||||
|
||||
if (str_starts_with($name, 'on') || (in_array($name, ['href', 'xlink:href', 'src'], true) && ! str_starts_with($value, '#') && ! str_starts_with($value, 'data:image/'))) {
|
||||
$element->removeAttributeNode($attribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $dom->saveXML($dom->documentElement);
|
||||
}
|
||||
}
|
||||
191
app/Support/Theme/Theme.php
Normal file
191
app/Support/Theme/Theme.php
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
/**
|
||||
* Erscheinungsbild der Installation: veröffentlichter Stand und Entwurf.
|
||||
* Gespeichert in den Einstellungen (Datenbank) – überlebt jedes Update.
|
||||
* Bilder und Schriften liegen im Speicher „uploads“ unter theme/.
|
||||
*/
|
||||
class Theme
|
||||
{
|
||||
public const DEFAULTS = [
|
||||
'portal_name' => 'Inhaus',
|
||||
'logo_light' => null,
|
||||
'logo_dark' => null,
|
||||
'logo_mark' => null,
|
||||
'app_icon' => null,
|
||||
'icons' => [],
|
||||
'primary_color' => '#0F4C5C',
|
||||
'secondary_color' => null,
|
||||
'header_style' => 'light',
|
||||
'font_body' => 'inter',
|
||||
'font_heading' => 'same',
|
||||
'custom_font' => null,
|
||||
'radius' => 'medium',
|
||||
'density' => 'normal',
|
||||
'dark_mode' => 'user',
|
||||
'login_layout' => 'split',
|
||||
'login_title' => 'Alles Wichtige für Ihren Arbeitsalltag – an einem Ort.',
|
||||
'login_text' => null,
|
||||
'login_image' => null,
|
||||
'footer_text' => null,
|
||||
'footer_links' => [],
|
||||
'email_footer' => null,
|
||||
'custom_css' => null,
|
||||
'stylesheet' => null,
|
||||
];
|
||||
|
||||
public const HEADER_STYLES = ['light' => 'Hell', 'brand' => 'In der Markenfarbe', 'dark' => 'Dunkel'];
|
||||
|
||||
public const RADII = ['none' => ['Eckig', '0rem'], 'small' => ['Leicht gerundet', '0.25rem'], 'medium' => ['Gerundet', '0.5rem'], 'large' => ['Stark gerundet', '0.75rem'], 'round' => ['Rund', '1rem']];
|
||||
|
||||
public const DENSITIES = ['compact' => ['Kompakt', '0.225rem'], 'normal' => ['Normal', '0.25rem'], 'comfortable' => ['Luftig', '0.275rem']];
|
||||
|
||||
public const DARK_MODES = [
|
||||
'user' => 'Jede Person wählt selbst (Standard: wie im System)',
|
||||
'light' => 'Immer hell',
|
||||
'dark' => 'Immer dunkel',
|
||||
];
|
||||
|
||||
public const LOGIN_LAYOUTS = ['split' => 'Geteilt: Bild bzw. Markenfarbe links, Anmeldung rechts', 'centered' => 'Zentriert: Anmeldung vor dem Hintergrundbild'];
|
||||
|
||||
private const PUBLISHED = 'theme.published';
|
||||
|
||||
private const DRAFT = 'theme.draft';
|
||||
|
||||
public function __construct(private readonly Settings $settings) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function published(): array
|
||||
{
|
||||
$stored = $this->settings->get(self::PUBLISHED);
|
||||
|
||||
return self::normalize(is_array($stored) ? $stored : $this->legacy());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function draft(): ?array
|
||||
{
|
||||
$stored = $this->settings->get(self::DRAFT);
|
||||
|
||||
return is_array($stored) ? self::normalize($stored) : null;
|
||||
}
|
||||
|
||||
public function hasDraft(): bool
|
||||
{
|
||||
return $this->draft() !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entwurf, sonst der veröffentlichte Stand – Ausgangspunkt für das Formular.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function working(): array
|
||||
{
|
||||
return $this->draft() ?? $this->published();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $values
|
||||
*/
|
||||
public function saveDraft(array $values): void
|
||||
{
|
||||
$theme = self::normalize([...$this->working(), ...$values]);
|
||||
|
||||
foreach (['logo_light', 'logo_dark', 'logo_mark'] as $logo) {
|
||||
SvgSanitizer::sanitizeFile($theme[$logo]);
|
||||
}
|
||||
|
||||
$this->settings->set(self::DRAFT, $theme);
|
||||
}
|
||||
|
||||
public function discardDraft(): void
|
||||
{
|
||||
$this->settings->set(self::DRAFT, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entwurf veröffentlichen: statische CSS-Datei erzeugen, Symbole berechnen.
|
||||
*/
|
||||
public function publish(ThemeCompiler $compiler, Icons $icons): void
|
||||
{
|
||||
$theme = $this->working();
|
||||
$theme['icons'] = $icons->generate($theme);
|
||||
$theme['stylesheet'] = $compiler->write($theme);
|
||||
|
||||
$this->settings->setMany([self::PUBLISHED => $theme, self::DRAFT => null]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auf die Standardwerte zurücksetzen – als Entwurf, damit man es erst ansehen kann.
|
||||
*/
|
||||
public function resetToDefaults(): void
|
||||
{
|
||||
$this->settings->set(self::DRAFT, self::normalize([...self::DEFAULTS, 'portal_name' => $this->published()['portal_name']]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Nur bekannte Schlüssel, gültige Werte.
|
||||
*
|
||||
* @param array<string, mixed> $theme
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function normalize(array $theme): array
|
||||
{
|
||||
$theme = [...self::DEFAULTS, ...Arr::only($theme, array_keys(self::DEFAULTS))];
|
||||
$hex = fn ($value) => is_string($value) && preg_match('/^#[0-9a-fA-F]{6}$/', $value) ? strtoupper($value) : null;
|
||||
|
||||
$theme['portal_name'] = mb_substr(trim((string) $theme['portal_name']), 0, 60) ?: self::DEFAULTS['portal_name'];
|
||||
$theme['primary_color'] = $hex($theme['primary_color']) ?? self::DEFAULTS['primary_color'];
|
||||
$theme['secondary_color'] = $hex($theme['secondary_color']);
|
||||
$theme['header_style'] = array_key_exists($theme['header_style'], self::HEADER_STYLES) ? $theme['header_style'] : 'light';
|
||||
$theme['font_body'] = array_key_exists($theme['font_body'], Fonts::FONTS) || ($theme['font_body'] === 'custom' && $theme['custom_font']) ? $theme['font_body'] : 'inter';
|
||||
$theme['font_heading'] = $theme['font_heading'] === 'same' || array_key_exists($theme['font_heading'], Fonts::FONTS) || ($theme['font_heading'] === 'custom' && $theme['custom_font']) ? $theme['font_heading'] : 'same';
|
||||
$theme['radius'] = array_key_exists($theme['radius'], self::RADII) ? $theme['radius'] : 'medium';
|
||||
$theme['density'] = array_key_exists($theme['density'], self::DENSITIES) ? $theme['density'] : 'normal';
|
||||
$theme['dark_mode'] = array_key_exists($theme['dark_mode'], self::DARK_MODES) ? $theme['dark_mode'] : 'user';
|
||||
$theme['login_layout'] = array_key_exists($theme['login_layout'], self::LOGIN_LAYOUTS) ? $theme['login_layout'] : 'split';
|
||||
$theme['footer_links'] = array_values(array_filter(array_map(
|
||||
fn ($link) => is_array($link) && filled($link['label'] ?? null) && filled($link['url'] ?? null)
|
||||
? ['label' => mb_substr(trim($link['label']), 0, 60), 'url' => mb_substr(trim($link['url']), 0, 500)]
|
||||
: null,
|
||||
(array) $theme['footer_links'],
|
||||
)));
|
||||
$theme['icons'] = is_array($theme['icons']) ? $theme['icons'] : [];
|
||||
|
||||
foreach (['login_title', 'login_text', 'footer_text', 'email_footer'] as $text) {
|
||||
$theme[$text] = filled($theme[$text]) ? mb_substr(trim((string) $theme[$text]), 0, 500) : null;
|
||||
}
|
||||
|
||||
foreach (['logo_light', 'logo_dark', 'logo_mark', 'app_icon', 'login_image', 'custom_font'] as $file) {
|
||||
$theme[$file] = is_string($theme[$file]) && preg_match('#^(theme|branding)/[A-Za-z0-9/_.-]+$#', $theme[$file]) && ! str_contains($theme[$file], '..') ? $theme[$file] : null;
|
||||
}
|
||||
|
||||
$theme['custom_css'] = filled($theme['custom_css']) ? mb_substr((string) $theme['custom_css'], 0, 50000) : null;
|
||||
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Einstellungen aus Phase 0 (Portalname, Logo, Markenfarbe) übernehmen.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function legacy(): array
|
||||
{
|
||||
return array_filter([
|
||||
'portal_name' => $this->settings->get('branding.portal_name'),
|
||||
'primary_color' => $this->settings->get('branding.primary_color'),
|
||||
'logo_light' => $this->settings->get('branding.logo_path'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
98
app/Support/Theme/ThemeCompiler.php
Normal file
98
app/Support/Theme/ThemeCompiler.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
use App\Support\ColorPalette;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Baut aus dem Theme eine CSS-Datei mit Variablen (Farben, Schriften, Form)
|
||||
* und dem eigenen CSS. Beim Veröffentlichen wird sie mit Hash im Namen
|
||||
* gespeichert – kein Build, keine Rechenarbeit pro Seitenaufruf.
|
||||
*/
|
||||
class ThemeCompiler
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $theme
|
||||
*/
|
||||
public function css(array $theme): string
|
||||
{
|
||||
$primary = $theme['primary_color'];
|
||||
$palette = ColorPalette::fromHex($primary);
|
||||
$secondary = $theme['secondary_color'] ?? $primary;
|
||||
$palette2 = ColorPalette::fromHex($secondary);
|
||||
|
||||
$light = [
|
||||
'--brand' => $primary,
|
||||
'--brand-foreground' => ColorPalette::foregroundFor($primary),
|
||||
'--brand-text' => $palette[Contrast::textShadeOnLight($primary)],
|
||||
'--accent2' => $secondary,
|
||||
'--accent2-foreground' => ColorPalette::foregroundFor($secondary),
|
||||
'--accent2-text' => $palette2[Contrast::textShadeOnLight($secondary)],
|
||||
'--radius' => Theme::RADII[$theme['radius']][1],
|
||||
'--spacing' => Theme::DENSITIES[$theme['density']][1],
|
||||
'--font-body' => Fonts::stack($theme['font_body']),
|
||||
'--font-heading' => Fonts::stack($theme['font_heading'] === 'same' ? $theme['font_body'] : $theme['font_heading']),
|
||||
];
|
||||
|
||||
foreach ($palette as $shade => $hex) {
|
||||
$light["--brand-{$shade}"] = $hex;
|
||||
}
|
||||
|
||||
foreach ($palette2 as $shade => $hex) {
|
||||
$light["--accent2-{$shade}"] = $hex;
|
||||
}
|
||||
|
||||
$dark = [
|
||||
'--brand-text' => $palette[Contrast::textShadeOnDark($primary)],
|
||||
'--accent2-text' => $palette2[Contrast::textShadeOnDark($secondary)],
|
||||
];
|
||||
|
||||
$css = ':root{'.$this->declarations($light).'}'."\n"
|
||||
.'.dark{'.$this->declarations($dark).'}'."\n";
|
||||
|
||||
if ($theme['custom_font']) {
|
||||
$url = Storage::disk('uploads')->url($theme['custom_font']);
|
||||
$css .= '@font-face{font-family:"'.Fonts::CUSTOM_FAMILY.'";src:url("'.$url.'") format("woff2");font-weight:100 900;font-display:swap}'."\n";
|
||||
}
|
||||
|
||||
if ($theme['custom_css']) {
|
||||
// Eigenes CSS steht in einer eigenen CSS-Datei; ein schließendes </style> ist dort bedeutungslos,
|
||||
// wird aber für die Vorschau (inline) trotzdem entschärft.
|
||||
$css .= "/* Eigenes CSS */\n".str_ireplace('</style', '<\/style', $theme['custom_css'])."\n";
|
||||
}
|
||||
|
||||
return $css;
|
||||
}
|
||||
|
||||
/**
|
||||
* CSS-Datei schreiben und ihren Pfad im Speicher „uploads“ liefern.
|
||||
*
|
||||
* @param array<string, mixed> $theme
|
||||
*/
|
||||
public function write(array $theme): string
|
||||
{
|
||||
$css = $this->css($theme);
|
||||
$path = 'theme/theme-'.substr(sha1($css), 0, 12).'.css';
|
||||
$disk = Storage::disk('uploads');
|
||||
|
||||
if (! $disk->exists($path)) {
|
||||
$disk->put($path, $css);
|
||||
}
|
||||
|
||||
// Ältere Fassungen aufräumen (die aktuelle und die vorherige bleiben für offene Seiten).
|
||||
$old = collect($disk->files('theme'))->filter(fn ($f) => preg_match('#^theme/theme-[0-9a-f]{12}\.css$#', $f) && $f !== $path)
|
||||
->sortByDesc(fn ($f) => $disk->lastModified($f))->slice(1);
|
||||
$disk->delete($old->all());
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $values
|
||||
*/
|
||||
private function declarations(array $values): string
|
||||
{
|
||||
return collect($values)->map(fn ($value, $name) => $name.':'.$value)->implode(';');
|
||||
}
|
||||
}
|
||||
92
app/Support/Theme/ThemeTransfer.php
Normal file
92
app/Support/Theme/ThemeTransfer.php
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Erscheinungsbild als Datei – z. B. vom Test- auf das Produktivsystem.
|
||||
* Bilder und Schrift reisen als Daten-URLs mit.
|
||||
*/
|
||||
class ThemeTransfer
|
||||
{
|
||||
public const FORMAT = 'inhaus-theme';
|
||||
|
||||
private const FILES = ['logo_light', 'logo_dark', 'logo_mark', 'app_icon', 'login_image', 'custom_font'];
|
||||
|
||||
private const MIME = [
|
||||
'image/svg+xml' => 'svg', 'image/png' => 'png', 'image/jpeg' => 'jpg', 'image/webp' => 'webp', 'font/woff2' => 'woff2',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $theme
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function export(array $theme): array
|
||||
{
|
||||
$disk = Storage::disk('uploads');
|
||||
$files = [];
|
||||
|
||||
foreach (self::FILES as $key) {
|
||||
if ($theme[$key] && $disk->exists($theme[$key])) {
|
||||
$mime = $key === 'custom_font' ? 'font/woff2' : ($disk->mimeType($theme[$key]) ?: 'application/octet-stream');
|
||||
$files[$key] = 'data:'.$mime.';base64,'.base64_encode((string) $disk->get($theme[$key]));
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'format' => self::FORMAT,
|
||||
'version' => 1,
|
||||
'exported_at' => now()->toIso8601String(),
|
||||
'theme' => collect($theme)->except([...self::FILES, 'icons', 'stylesheet'])->all(),
|
||||
'files' => $files,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed> Werte für den Entwurf
|
||||
*/
|
||||
public function import(string $json): array
|
||||
{
|
||||
$data = json_decode($json, true);
|
||||
|
||||
if (! is_array($data) || ($data['format'] ?? null) !== self::FORMAT || ! is_array($data['theme'] ?? null)) {
|
||||
throw new RuntimeException('Die Datei ist kein exportiertes Erscheinungsbild.');
|
||||
}
|
||||
|
||||
$values = collect($data['theme'])->except([...self::FILES, 'icons', 'stylesheet'])->all();
|
||||
|
||||
foreach (self::FILES as $key) {
|
||||
$values[$key] = null;
|
||||
$uri = $data['files'][$key] ?? null;
|
||||
|
||||
if (! is_string($uri) || ! preg_match('#^data:([a-z0-9.+/-]+);base64,(.+)$#i', $uri, $m)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$extension = self::MIME[strtolower($m[1])] ?? null;
|
||||
$binary = base64_decode($m[2], true);
|
||||
|
||||
if (! $extension || $binary === false || strlen($binary) > 8 * 1024 * 1024) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Inhalt prüfen: Bilder müssen sich lesen lassen, SVG wird von allem Ausführbaren befreit.
|
||||
if ($extension === 'svg' && ($binary = SvgSanitizer::sanitize($binary)) === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($extension, ['png', 'jpg', 'webp'], true) && @getimagesizefromstring($binary) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = ($key === 'custom_font' ? 'theme/fonts/' : 'theme/').'import-'.Str::random(20).'.'.$extension;
|
||||
Storage::disk('uploads')->put($path, $binary);
|
||||
$values[$key] = $path;
|
||||
}
|
||||
|
||||
return Theme::normalize([...Theme::DEFAULTS, ...$values]);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,5 +9,5 @@ namespace App;
|
|||
*/
|
||||
final class Version
|
||||
{
|
||||
public const VERSION = '0.6.0';
|
||||
public const VERSION = '0.7.0';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue