CI Feature / test (push) Successful in 31s
- Codebasiertes Widget-Register (config/cms.php) mit Vertrag
{id, type, v, variant, settings, data, refs}: Typkennung, Schemaversion,
Prüfregeln, freigegebene Varianten, Editorfelder, Blade-Ansicht,
Verweisauflösung und Medienliste je Widget-Art.
- Die sechs Bestandsbausteine bleiben als Version 1 lesbar; gespeicherte
Revisionen werden nicht umgeschrieben, sondern beim Lesen angehoben
(Bild und Text: Version 2 mit Titel, formatiertem Text, Bild links/rechts).
Wiederherstellen kopiert eine Revision unverändert.
- Neue Widgets: Einstieg (Hero) und Programm-/Modulkarten. Letztere speichern
nur Verweise; Titel und Kurzbeschreibung kommen aus den Fachdaten. Öffentlich
erscheinen nur Programme mit Anzeigefreigabe (gleiche Regel wie /programme,
jetzt in PublicCatalogReader); Module nur in der Redaktionsvorschau, bis
öffentliche Profile (ADR-29) bestehen.
- Ein Renderer für öffentliche Seite, Vorschau und Blockvorschau im Editor.
- Seiteneditor als Filament-Builder: Auswahl mit Beschreibung und Schema,
kompakte Abschnitte mit Vorschau, Bearbeitung im Dialog, Sortieren,
Duplizieren. Speichern erzeugt nur einen Entwurf.
- Vorschau einer Revision in 390/768/1440 px; Vorschauroute nutzt den
Personal-Guard (vorher war sie für Redakteure ohne Mitgliedersitzung
nicht erreichbar).
- Basislayout in Komponenten (Marke, Kopf, Fuß, Seitenvorlage).
- Navigation: bearbeiten, ausblenden, löschen, per Ziehen sortieren;
unsichere Adressen (javascript:) werden abgewiesen und nicht ausgegeben.
Ergänzende Migration is_visible (Vorgabe sichtbar).
- Pfadfehler und doppelte Pfade erscheinen am Pfadfeld statt still zu scheitern.
Tests: BlockRegistryTest geht in WidgetRegistryTest auf (gleiche Prüfungen
plus Registrierung, Versionierung, Bereinigung). Bestandsseiten werden gegen
Textfixtures aus dem Stand vor der Umstellung geprüft.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
2.9 KiB
PHP
101 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Cms\Widgets\Support;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Öffentlicher Medienbereich der Website ("cms/"). Nur Dateien aus diesem Bereich dürfen in Widgets
|
|
* verwendet werden. Geschützte Bibliotheksmedien (Inhaltsdateien, Vorschaubilder) sind hier nie wählbar.
|
|
*/
|
|
final class PublicMedia
|
|
{
|
|
public const PREFIX = 'cms/';
|
|
|
|
private const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'avif'];
|
|
|
|
public static function isPublicPath(mixed $path): bool
|
|
{
|
|
return is_string($path)
|
|
&& str_starts_with($path, self::PREFIX)
|
|
&& ! str_contains($path, '..')
|
|
&& preg_match('#^cms/[A-Za-z0-9._\-/]+$#', $path) === 1;
|
|
}
|
|
|
|
public static function url(string $path): string
|
|
{
|
|
return route('media.public', ['path' => $path]);
|
|
}
|
|
|
|
/**
|
|
* Bereits vorhandene Bilder im öffentlichen Bereich (veröffentlicht oder zur Veröffentlichung vorgemerkt).
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public static function imageOptions(): array
|
|
{
|
|
$options = [];
|
|
|
|
foreach (['media_public', 'cms_incoming'] as $disk) {
|
|
try {
|
|
$files = Storage::disk($disk)->allFiles(rtrim(self::PREFIX, '/'));
|
|
} catch (Throwable) {
|
|
$files = [];
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
$extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
|
|
|
if (self::isPublicPath($file) && in_array($extension, self::IMAGE_EXTENSIONS, true)) {
|
|
$options[$file] = substr($file, strlen(self::PREFIX));
|
|
}
|
|
}
|
|
}
|
|
|
|
ksort($options);
|
|
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* Pfad aus dem Zustand eines Upload-Felds (Zeichenkette oder Liste).
|
|
*/
|
|
public static function fromUploadState(mixed $state): ?string
|
|
{
|
|
if (is_array($state)) {
|
|
$state = array_values($state)[0] ?? null;
|
|
}
|
|
|
|
return is_string($state) && $state !== '' ? $state : null;
|
|
}
|
|
|
|
/**
|
|
* Bildadresse für Darstellung und Blockvorschau. In der Vorschau kann ein noch nicht gespeicherter Upload vorliegen.
|
|
*
|
|
* @param array<string, mixed> $refs
|
|
*/
|
|
public static function imageUrl(array $refs, string $key = 'image'): ?string
|
|
{
|
|
$upload = $refs['_upload'] ?? null;
|
|
$upload = is_array($upload) ? (array_values($upload)[0] ?? null) : $upload;
|
|
|
|
if ($upload instanceof TemporaryUploadedFile) {
|
|
try {
|
|
return $upload->temporaryUrl();
|
|
} catch (Throwable) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
if (self::isPublicPath($upload)) {
|
|
return self::url($upload);
|
|
}
|
|
|
|
$path = $refs[$key] ?? null;
|
|
|
|
return self::isPublicPath($path) ? self::url($path) : null;
|
|
}
|
|
}
|