diff --git a/app/Domain/Cms/Catalog/CardSubject.php b/app/Domain/Cms/Catalog/CardSubject.php index 902a185..d75a52f 100644 --- a/app/Domain/Cms/Catalog/CardSubject.php +++ b/app/Domain/Cms/Catalog/CardSubject.php @@ -15,6 +15,8 @@ * Redaktionsvorschau (Route editorial.card, nur für angemeldete Redaktion); öffentlich nie ausgegeben, weil es * keine Freigabe für die Website hat. * - missing: was für eine vollständige Karte fehlt, als Hinweis nur in der Redaktionsvorschau. + * - texts: die zentralen Texte des Fachobjekts, aus denen die Karte einen wählen kann (teaser, summary, description). + * summary bleibt der Text der Vorgabe („Automatisch“); texts wird nur gelesen, wenn die Redaktion einen wählt. */ final readonly class CardSubject { @@ -36,24 +38,39 @@ public function __construct( public ?string $previewImage = null, public array $missing = [], public ?string $style = null, + public array $texts = [], ) {} public function withText(?string $title, ?string $summary): self { - return new self( - title: $title ?? $this->title, - summary: $summary ?? $this->summary, - kind: $this->kind, - badge: $this->badge, - meta: $this->meta, - url: $this->url, - public: $this->public, - notice: $this->notice, - visual: $this->visual, - visualLabel: $this->visualLabel, - previewImage: $this->previewImage, - missing: $this->missing, - style: $this->style, - ); + return $this->copy(['title' => $title ?? $this->title, 'summary' => $summary ?? $this->summary]); + } + + /** + * Text der Karte aus einem zentralen Text des Fachobjekts. Ist er nicht gepflegt, bleibt die Karte ohne Text + * (kein stiller Ersatz aus einem anderen Feld); in der Redaktionsvorschau steht dann ein Hinweis. + */ + public function withTextChoice(string $field, string $missingHint): self + { + if (! array_key_exists($field, $this->texts)) { + return $this; + } + + $text = $this->texts[$field]; + $missing = array_values(array_filter($this->missing, fn (string $hint): bool => ! str_contains($hint, 'Kurzbeschreibung'))); + + if ($text === null) { + $missing[] = $missingHint; + } + + return $this->copy(['summary' => $text, 'missing' => $missing]); + } + + /** + * @param array $changes + */ + private function copy(array $changes): self + { + return new self(...array_merge(get_object_vars($this), $changes)); } } diff --git a/app/Domain/Cms/Catalog/PublicMaterialReader.php b/app/Domain/Cms/Catalog/PublicMaterialReader.php index 4e6b8fc..46aa0d7 100644 --- a/app/Domain/Cms/Catalog/PublicMaterialReader.php +++ b/app/Domain/Cms/Catalog/PublicMaterialReader.php @@ -20,9 +20,12 @@ * öffentlich, mit Verweis auf diese Programmseite, und nur mit bereitgestellter Fassung. Traineranleitungen erscheinen * nie öffentlich (vertraulich für Trainerinnen und Trainer). * - * Öffentlich gelesen werden Anzeigetitel (sonst Arbeitstitel), Kurzbeschreibung, Inhaltsart und Ausgabeart. Nie: - * Beschreibung, Einsatzhinweis, Lizenzvermerk, Dateien, Lehrtexte, Ausgabeadressen. Das Vorschaubild (Filmstandbild) - * der Bibliothek ist nicht für die Website freigegeben; es erscheint nur in der Redaktionsvorschau. + * Öffentlich gelesen werden Anzeigetitel (sonst Arbeitstitel), Inhaltsart und Ausgabeart sowie einer der Texte + * Teaser, Kurzbeschreibung oder ausführliche Beschreibung. Welcher Text erscheint, entscheidet die Redaktion je Karte + * (Einstellung „Text der Karte“); ohne Wahl gilt die Kurzbeschreibung, sonst der Teaser. Die ausführliche Beschreibung + * erscheint nur, wenn die Redaktion sie ausdrücklich wählt. Nie: Einsatzhinweis, Lizenzvermerk, Dateien, Lehrtexte, + * Ausgabeadressen. Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben; es erscheint nur in der + * Redaktionsvorschau und kann in der Karte ausdrücklich als Website-Bild übernommen werden (FilmStill). * Eine Karte spielt nichts ab, bietet keinen Download und gibt kein Medium frei. */ class PublicMaterialReader @@ -124,7 +127,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ? $shown = clone $element; - foreach (['working_title', 'display_title', 'summary', 'thumbnail_path', 'thumbnail_alt'] as $field) { + foreach (['working_title', 'display_title', 'teaser', 'summary', 'description', 'thumbnail_path', 'thumbnail_alt'] as $field) { if (! array_key_exists($field, $draft)) { continue; } @@ -146,6 +149,18 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ? $summary = trim((string) $shown->teaser); } + $texts = []; + + foreach (['teaser', 'summary', 'description'] as $field) { + $own = filled($shown->getAttribute($field)) ? trim((string) $shown->getAttribute($field)) : null; + + if (! array_key_exists($field, $draft) && $profile->origin($field) === 'variante') { + $own = $profile->value($field); + } + + $texts[$field] = $own; + } + $title = (string) ($shown->display_title ?: $shown->working_title); if (! array_key_exists('display_title', $draft) && $profile->origin('display_title') === 'variante') { @@ -184,6 +199,7 @@ public function subject(mixed $id, bool $includeNonPublic, array $draft = []): ? previewImage: $previewImage, missing: $missing, style: $film ? 'media' : 'material', + texts: $texts, ); } diff --git a/app/Domain/Cms/Widgets/Types/MediaCardWidget.php b/app/Domain/Cms/Widgets/Types/MediaCardWidget.php index 39851d6..1a92418 100644 --- a/app/Domain/Cms/Widgets/Types/MediaCardWidget.php +++ b/app/Domain/Cms/Widgets/Types/MediaCardWidget.php @@ -7,6 +7,9 @@ use App\Domain\Cms\Catalog\CardSubject; use App\Domain\Cms\Catalog\PublicMaterialReader; use App\Domain\Cms\Widgets\RenderContext; +use App\Domain\Media\FilmStill; +use Filament\Forms\Components\ViewField; +use Filament\Schemas\Components\Utilities\Get; /** * Medien- und Materialkarte (Kit v1.7 „media“): ein Inhaltselement mit Anzeigetitel, Kurzbeschreibung, Inhaltsart und @@ -53,7 +56,7 @@ protected function refLabel(): string protected function refHelp(): string { - return 'Wählbar sind alle nicht archivierten, nicht gesperrten Filme und Materialien. Öffentlich erscheint die Karte nur mit bereitgestellter Fassung und wenn der Inhalt zu einem öffentlich gezeigten Programm gehört; Traineranleitungen nie. Titel und Kurzbeschreibung pflegen Sie im Medium.'; + return 'Wählbar sind alle nicht archivierten, nicht gesperrten Filme und Materialien. Öffentlich erscheint die Karte nur mit bereitgestellter Fassung und wenn der Inhalt zu einem öffentlich gezeigten Programm gehört; Traineranleitungen nie. Titel, Teaser, Kurzbeschreibung und Beschreibung pflegen Sie im Medium; welcher Text auf der Karte erscheint, wählen Sie unter „Darstellung“.'; } protected function searchSubjects(?string $term): array @@ -90,6 +93,51 @@ protected function cardStyle(): string return 'media'; } + /** + * Bei einem Film: das Vorschaubild des Films oder eine Stelle des Films als Kartenbild übernehmen. Das Bild wird + * einmal als Bild-Medium abgelegt (FilmStill) und wie jedes andere Bild ausgewählt; die Karte liest nur diese Datei. + */ + protected function imageSourceFields(): array + { + return [ + ViewField::make('_filmbild') + ->label('Bild aus dem Film') + ->view('filament.cms.filmbild-feld') + ->dehydrated(false) + ->visible(fn (Get $get): bool => $this->filmFor($get('element')) !== null) + ->viewData(function (Get $get): array { + $film = $this->filmFor($get('element')); + $stills = app(FilmStill::class); + $version = $film instanceof ContentElement ? $stills->version($film) : null; + + return [ + 'film' => $film, + 'filmTitle' => $film instanceof ContentElement ? (string) ($film->display_title ?: $film->working_title) : '', + 'filmVersionId' => $version?->id, + 'filmHasThumbnail' => $film instanceof ContentElement && is_string($film->thumbnail_path) && $film->thumbnail_path !== '', + 'filmStartSecond' => $film instanceof ContentElement ? ($stills->thumbnailSecond($film) ?? '0') : '0', + ]; + }), + ]; + } + + private function filmFor(mixed $id): ?ContentElement + { + $element = is_numeric($id) ? ContentElement::query()->with('editorialContentKind')->find((int) $id) : null; + + return $element instanceof ContentElement && app(FilmStill::class)->refusal($element) === null ? $element : null; + } + + protected function textChoices(): array + { + return [ + 'auto' => 'Automatisch (Kurzbeschreibung, sonst Teaser)', + 'teaser' => 'Teaser', + 'summary' => 'Kurzbeschreibung', + 'description' => 'Ausführliche Beschreibung (erscheint öffentlich)', + ]; + } + protected function centralCoverId(mixed $id): ?int { $element = is_numeric($id) ? ContentElement::query()->find((int) $id) : null; diff --git a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php index d6fc682..1d44430 100644 --- a/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php +++ b/app/Domain/Cms/Widgets/Types/PremiumCardWidget.php @@ -10,6 +10,7 @@ use App\Domain\Cms\Widgets\Support\WebsiteImage; use App\Domain\Cms\Widgets\WidgetErrors; use App\Domain\Cms\Widgets\WidgetType; +use Filament\Forms\Components\Field; use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Schemas\Components\Group; @@ -32,6 +33,13 @@ abstract class PremiumCardWidget extends WidgetType { public const SHOW = ['yes' => 'Anzeigen', 'no' => 'Ausblenden']; + /** Hinweise der Redaktionsvorschau, wenn der gewählte zentrale Text nicht gepflegt ist. */ + public const TEXT_MISSING = [ + 'teaser' => 'Kein Teaser gepflegt (Medium bearbeiten → Teaser).', + 'summary' => 'Keine Kurzbeschreibung gepflegt (Medium bearbeiten → Kurzbeschreibung).', + 'description' => 'Keine ausführliche Beschreibung gepflegt (Medium bearbeiten → Beschreibung).', + ]; + /** Schlüssel des Fachobjekts in refs, zum Beispiel 'pillar'. */ abstract protected function refKey(): string; @@ -56,6 +64,27 @@ abstract protected function defaultActionLabel(): string; /** Gestaltungsvariante des Kits: editorial, media oder catalog. */ abstract protected function cardStyle(): string; + /** + * Weitere Wege zum Kartenbild im Reiter „Medien“, zum Beispiel ein Bild aus dem Film. Standard: keine. + * + * @return list + */ + protected function imageSourceFields(): array + { + return []; + } + + /** + * Zentrale Texte des Fachobjekts, aus denen die Redaktion den Kartentext wählen kann: Wert => Bezeichnung. + * Leer: keine Wahl (die Karte nimmt den Text ihrer Vorgabe). Mit Wahl gilt „auto“ als Vorgabe. + * + * @return array + */ + protected function textChoices(): array + { + return []; + } + public function view(): string { return 'widgets.premium_card'; @@ -110,7 +139,9 @@ public function optionIcons(): array public function settings(): array { - return [ + $choices = $this->textChoices(); + + return ($choices === [] ? [] : ['text_source' => $choices]) + [ 'format' => ['landscape' => 'Querformat 16:9', 'square' => 'Quadrat 1:1', 'portrait' => 'Hochformat 3:4'], 'fit' => ['cover' => 'Ausschnitt füllt die Fläche', 'contain' => 'Ganzes Bild zeigen (Dokument, Poster)'], 'heading_level' => ['h3' => 'H3', 'h2' => 'H2', 'h4' => 'H4'], @@ -124,10 +155,11 @@ public function settings(): array public function settingLabels(): array { return [ + 'text_source' => ['Text der Karte', 'Welche Angabe aus der Redaktion die Karte zeigt. Vorgabe: Automatisch. Der gewählte Text erscheint öffentlich, wenn die Karte öffentlich ist; ist er nicht gepflegt, bleibt die Karte ohne Text.'], 'format' => ['Bildformat', 'Vorgabe: Querformat 16:9. Gilt auch neben dem Text; das Motiv wird nicht nachträglich hochkant beschnitten.'], 'fit' => ['Bilddarstellung', 'Vorgabe: Ausschnitt. „Ganzes Bild“ zeigt Dokumente und Poster vollständig auf ruhiger Fläche.'], 'heading_level' => ['Überschriftenebene', 'Vorgabe: H3, passend unter einer Abschnittsüberschrift (H2).'], - 'show_summary' => ['Kurzbeschreibung', 'Aus den Fachdaten. Vorgabe: anzeigen.'], + 'show_summary' => ['Text anzeigen', 'Aus den Fachdaten. Vorgabe: anzeigen.'], 'show_kind' => ['Art oder Label', 'Zum Beispiel „Thema“ oder „Merkblatt“. Vorgabe: anzeigen.'], 'show_meta' => ['Zusatzangaben', 'Aus den Fachdaten, zum Beispiel Ausgabeart oder Programmzugehörigkeit. Vorgabe: anzeigen.'], 'show_action' => ['Aktion', 'Verweis auf die öffentliche Seite des Fachobjekts, falls es eine gibt. Vorgabe: anzeigen.'], @@ -195,13 +227,13 @@ public function editorSchema(): array ->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray') ->helperText('Leer übernimmt den Anzeigenamen des Fachobjekts. Eine Eintragung gilt nur für diese Karte und ändert die Quelle nicht.'), TextInput::make('summary') - ->label('Teaser nur für diese Karte') + ->label('Text nur für diese Karte') ->maxLength(500) ->live(onBlur: true) - ->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'summary') ?? 'Zentraler Teaser oder Kurzbeschreibung') + ->placeholder(fn (Get $get): string => $this->centralText($get('../refs.'.$this->refKey()), 'summary', $get('../settings.text_source')) ?? 'Zentraler Text aus der Redaktion') ->hint(fn (?string $state): string => filled($state) ? 'Eigene Angabe für diese Karte' : 'Aus der Redaktion') ->hintColor(fn (?string $state): string => filled($state) ? 'warning' : 'gray') - ->helperText('Leer übernimmt Teaser oder Kurzbeschreibung. Lehrinhalt, Rechte und Preise bleiben unberührt.'), + ->helperText('Leer übernimmt den Text, den „Text der Karte“ (Darstellung) wählt. Lehrinhalt, Rechte und Preise bleiben unberührt.'), ])->statePath('data'), ]; } @@ -211,7 +243,7 @@ public function mediaSchema(): array [, , $alt, $focusX, $focusY] = $this->dataFields(); return [ - Group::make(ImageRefFields::fields('Kartenbild', live: true))->statePath('refs'), + Group::make([...ImageRefFields::fields('Kartenbild', live: true), ...$this->imageSourceFields()])->statePath('refs'), Group::make([$alt, $focusX, $focusY])->statePath('data'), ]; } @@ -248,6 +280,12 @@ public function resolve(array $widget, RenderContext $context): array $data = $widget['data']; $subject = $this->subject($widget['refs'][$this->refKey()] ?? null, $context); + $textSource = $option('text_source', 'auto'); + + if ($subject instanceof CardSubject && $textSource !== 'auto' && isset($this->textChoices()[$textSource])) { + $subject = $subject->withTextChoice($textSource, self::TEXT_MISSING[$textSource] ?? ''); + } + $heading = filled($data['heading'] ?? null) ? trim((string) $data['heading']) : null; $lead = filled($data['summary'] ?? null) ? trim((string) $data['summary']) : null; @@ -302,7 +340,7 @@ protected function centralCoverId(mixed $id): ?int /** * Zentraler Anzeigename oder Teaser des gewählten Objekts (Redaktionsstand) für Platzhalter im Editor. */ - private function centralText(mixed $id, string $field): ?string + private function centralText(mixed $id, string $field, mixed $textSource = null): ?string { if (blank($id)) { return null; @@ -314,6 +352,10 @@ private function centralText(mixed $id, string $field): ?string return null; } + if ($subject instanceof CardSubject && is_string($textSource) && isset($this->textChoices()[$textSource]) && $textSource !== 'auto') { + $subject = $subject->withTextChoice($textSource, self::TEXT_MISSING[$textSource] ?? ''); + } + $text = $subject?->{$field}; return is_string($text) && trim($text) !== '' ? Str::limit(trim($text), 120) : null; diff --git a/app/Domain/Media/FilmStill.php b/app/Domain/Media/FilmStill.php new file mode 100644 index 0000000..f3d013f --- /dev/null +++ b/app/Domain/Media/FilmStill.php @@ -0,0 +1,199 @@ +output_class !== 'film') { + return 'Nur aus einem Film lässt sich ein Bild übernehmen.'; + } + + if ($film->archived_at !== null) { + return 'Der Film ist archiviert.'; + } + + $slug = $film->editorialContentKind?->slug; + + if (in_array($slug, PublicMaterialReader::CONFIDENTIAL_KINDS, true)) { + return 'Aus Traineranleitungen werden keine Bilder für die Website übernommen.'; + } + + return null; + } + + /** Die bereitgestellte Fassung, aus der Stellen gezogen werden (die höchste). */ + public function version(ContentElement $film): ?ContentElementVersion + { + return $film->versions() + ->where('status', ContentVersionStatus::Bereit->value) + ->orderByDesc('number') + ->first(); + } + + /** Sekunde der Stelle, aus der das aktuelle Vorschaubild des Films stammt, sonst null. */ + public function thumbnailSecond(ContentElement $film): ?string + { + $source = $film->thumbnail_source; + + return is_string($source) && preg_match('/^frame:\d+@([\d.]+)$/', $source, $match) === 1 ? $match[1] : null; + } + + public function fromSecond(ContentElement $film, float $seconds, ?User $actor = null): ContentElement + { + $this->guard($film); + + if ($seconds < 0 || $seconds > 7200) { + throw new DomainRuleException('Die Zeitposition liegt außerhalb des Films.'); + } + + $version = $this->version($film); + + if (! $version instanceof ContentElementVersion) { + throw new DomainRuleException('Der Film hat noch keine bereitgestellte Fassung.'); + } + + return $this->fromFrame($film, $version, $seconds, $actor); + } + + public function fromThumbnail(ContentElement $film, ?User $actor = null): ContentElement + { + $this->guard($film); + + // Stammt das Vorschaubild aus einer Filmstelle, wird dieselbe Stelle in voller Auflösung gezogen. + $second = $this->thumbnailSecond($film); + + if ($second !== null && preg_match('/^frame:(\d+)@/', (string) $film->thumbnail_source, $match) === 1) { + $version = ContentElementVersion::query()->find((int) $match[1]); + + if ($version instanceof ContentElementVersion + && (int) $version->content_element_id === (int) $film->id + && $version->status !== ContentVersionStatus::Gesperrt) { + try { + return $this->fromFrame($film, $version, (float) $second, $actor); + } catch (DomainRuleException) { + // Die Stelle lässt sich nicht mehr ziehen: das gespeicherte Vorschaubild selbst übernehmen. + } + } + } + + $path = $film->thumbnail_path; + + if (! is_string($path) || ! str_starts_with($path, 'vorschau/') || str_contains($path, '..') || ! Storage::disk('media_derived')->exists($path)) { + throw new DomainRuleException('Dieser Film hat noch kein Vorschaubild. Setzen Sie es im Medienmanager oder wählen Sie eine Stelle.'); + } + + $bytes = Storage::disk('media_derived')->get($path); + + if (! is_string($bytes) || $bytes === '') { + throw new DomainRuleException('Das Vorschaubild ließ sich nicht lesen.'); + } + + $key = 'file:'.hash('sha256', $bytes); + + return $this->existing($film, $key) ?? $this->store($film, $key, $bytes, 'Vorschaubild', $actor); + } + + private function fromFrame(ContentElement $film, ContentElementVersion $version, float $seconds, ?User $actor): ContentElement + { + $second = $this->secondText($seconds); + $key = 'frame:'.$version->id.'@'.$second; + $existing = $this->existing($film, $key); + + if ($existing instanceof ContentElement) { + return $existing; + } + + $bytes = $this->deriver->frameJpeg($version, (float) $second, self::WIDTH, original: true); + + if (! is_string($bytes)) { + throw new DomainRuleException('Aus dieser Filmstelle ließ sich kein Bild erzeugen.'); + } + + return $this->store($film, $key, $bytes, 'Fassung '.$version->number.', '.str_replace('.', ',', $second).' s', $actor); + } + + private function guard(ContentElement $film): void + { + $refusal = $this->refusal($film); + + if ($refusal !== null) { + throw new DomainRuleException($refusal); + } + } + + private function existing(ContentElement $film, string $key): ?ContentElement + { + $source = FilmStillSource::query()->with('still')->where('film_element_id', $film->id)->where('source_key', $key)->first(); + $still = $source?->still; + + return $still instanceof ContentElement && $still->archived_at === null ? $still : null; + } + + private function store(ContentElement $film, string $key, string $bytes, string $label, ?User $actor): ContentElement + { + $title = (string) ($film->display_title ?: $film->working_title); + $path = 'cms/standbild-'.$film->id.'-'.Str::lower(Str::random(8)).'.jpg'; + Storage::disk('cms_incoming')->put($path, $bytes); + + $still = $this->intake->acceptImage( + $path, + 'Standbild: '.$title.' ('.$label.')', + filled($film->website_credit) ? (string) $film->website_credit : null, + 'Szene aus dem Film „'.$title.'“', + $actor, + ); + + try { + FilmStillSource::query()->create([ + 'film_element_id' => $film->id, + 'still_element_id' => $still->id, + 'source_key' => $key, + 'actor_id' => $actor?->id, + ]); + } catch (QueryException) { + // Gleichzeitige Übernahme derselben Stelle: das zuerst angelegte Bild gilt. + return $this->existing($film, $key) ?? $still; + } + + return $still; + } + + private function secondText(float $seconds): string + { + $text = number_format(max(0, min(7200, $seconds)), 3, '.', ''); + + return rtrim(rtrim($text, '0'), '.') ?: '0'; + } +} diff --git a/app/Domain/Media/FilmStillSource.php b/app/Domain/Media/FilmStillSource.php new file mode 100644 index 0000000..fb8a559 --- /dev/null +++ b/app/Domain/Media/FilmStillSource.php @@ -0,0 +1,26 @@ +belongsTo(ContentElement::class, 'film_element_id'); + } + + public function still(): BelongsTo + { + return $this->belongsTo(ContentElement::class, 'still_element_id'); + } +} diff --git a/app/Domain/Media/ThumbnailDeriver.php b/app/Domain/Media/ThumbnailDeriver.php index 6db8103..e03f8a4 100644 --- a/app/Domain/Media/ThumbnailDeriver.php +++ b/app/Domain/Media/ThumbnailDeriver.php @@ -138,8 +138,20 @@ public function forCompositionFrame(Composition $composition, ContentElementVers $this->rememberChoice($composition, 'frame:'.$version->id.'@'.$this->secondText($seconds)); } - public function frameInput(ContentElementVersion $version): ?string + /** + * Datei, aus der ein Bild gezogen wird. Vorgabe: die kleine Filmstufe (schnell, für die Vorschau). Mit $original + * zuerst die Mediendatei selbst, damit ein übernommenes Standbild nicht aus der kleinen Stufe hochgerechnet wird. + */ + public function frameInput(ContentElementVersion $version, bool $original = false): ?string { + if ($original) { + $master = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null; + + if ($this->readableDerived($master, 'inhalte/')) { + return $master; + } + } + $proxy = MediaRendition::query() ->where('content_element_version_id', $version->id) ->where('role', 'variant') @@ -155,13 +167,25 @@ public function frameInput(ContentElementVersion $version): ?string return $this->readableDerived($file, 'inhalte/') ? $file : null; } + /** + * Einzelbild einer Filmstelle als JPEG, 640 px breit aus der kleinen Stufe (Vorschau im Editor und Vorschaubild). + */ public function jpegAtVersion(ContentElementVersion $version, float $seconds): ?string + { + return $this->frameJpeg($version, $seconds); + } + + /** + * Einzelbild einer Filmstelle als JPEG. Ein übernommenes Standbild (FilmStill) wird mit $width und $original aus der + * Mediendatei gezogen statt aus der kleinen Stufe und dabei nie über die Breite der Quelle hinaus vergrößert. + */ + public function frameJpeg(ContentElementVersion $version, float $seconds, int $width = 640, bool $original = false): ?string { if ($seconds < 0 || $seconds > 7200) { return null; } - $file = $this->frameInput($version); + $file = $this->frameInput($version, $original); if ($file === null) { return null; @@ -186,7 +210,7 @@ public function jpegAtVersion(ContentElementVersion $version, float $seconds): ? '-frames:v', '1', '-vf', - 'scale=640:-2', + $width === 640 ? 'scale=640:-2' : 'scale=min('.max(160, min(2400, $width)).'\,iw):-2', '-f', 'image2pipe', '-vcodec', diff --git a/app/Filament/Support/ChoosesWebsiteImages.php b/app/Filament/Support/ChoosesWebsiteImages.php index 790f088..90b08da 100644 --- a/app/Filament/Support/ChoosesWebsiteImages.php +++ b/app/Filament/Support/ChoosesWebsiteImages.php @@ -3,7 +3,10 @@ namespace App\Filament\Support; use App\Domain\Catalog\ContentElement; +use App\Domain\Catalog\DomainRuleException; use App\Domain\Cms\Widgets\Support\WebsiteImage; +use App\Domain\Media\FilmStill; +use App\Filament\Resources\ContentElements\ContentElementResource; use Filament\Notifications\Notification; /** @@ -31,6 +34,62 @@ public function openWebsiteImagePicker(string $pfad): void $this->forceRenderForPicker(); } + /** + * Medien- und Materialkarte: das Vorschaubild des Films als Bild für die Website übernehmen. Es entsteht ein Bild + * im Medienmanager (einmal gespeichert), das im Bildfeld ausgewählt wird. Die Datei des Films bleibt geschützt. + */ + public function adoptFilmThumbnail(string $pfad, int $elementId): void + { + $this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromThumbnail($film, auth('staff')->user())); + } + + /** + * Medien- und Materialkarte: eine Stelle des Films wählen und als Bild für die Website übernehmen. + */ + public function adoptFilmFrame(string $pfad, int $elementId, string $sekunde): void + { + if (! is_numeric($sekunde)) { + Notification::make()->danger()->title('Bitte eine Zeitposition in Sekunden angeben.')->send(); + + return; + } + + $this->adoptFilmStill($pfad, $elementId, fn (FilmStill $stills, ContentElement $film): ContentElement => $stills->fromSecond($film, (float) $sekunde, auth('staff')->user())); + } + + /** + * @param callable(FilmStill, ContentElement): ContentElement $make + */ + private function adoptFilmStill(string $pfad, int $elementId, callable $make): void + { + abort_unless(ContentElementResource::editor(), 403); + + if (preg_match('/^(data|mountedActions\.\d+\.data)(\.[A-Za-z0-9_-]+)+\.image$/', $pfad) !== 1) { + return; + } + + $film = ContentElement::query()->with('editorialContentKind')->find($elementId); + + if (! $film instanceof ContentElement) { + return; + } + + try { + $still = $make(app(FilmStill::class), $film); + } catch (DomainRuleException $exception) { + Notification::make()->danger()->title($exception->getMessage())->send(); + + return; + } + + data_set($this, $pfad, $still->id); + Notification::make() + ->success() + ->title('Im Medienmanager angelegt: „'.($still->display_title ?: $still->working_title).'“') + ->body('Das Bild ist als Kartenbild ausgewählt. Nach der Verarbeitung wird es für die Website freigegeben; dort lässt sich die Freigabe auch zurücknehmen.') + ->send(); + } + /** * Filament rendert bei offenen Aktionsdialogen nur den Dialogteil neu; der Picker liegt darüber und braucht die * ganze Seite. diff --git a/database/migrations/2026_11_21_120000_create_film_still_sources.php b/database/migrations/2026_11_21_120000_create_film_still_sources.php new file mode 100644 index 0000000..9d49c01 --- /dev/null +++ b/database/migrations/2026_11_21_120000_create_film_still_sources.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId('film_element_id')->constrained('content_elements')->restrictOnDelete(); + $table->foreignId('still_element_id')->constrained('content_elements')->restrictOnDelete(); + $table->string('source_key', 120); + $table->unsignedBigInteger('actor_id')->nullable(); + $table->timestamps(); + + $table->unique(['film_element_id', 'source_key']); + }); + } + + public function down(): void + { + Schema::dropIfExists('film_still_sources'); + } +}; diff --git a/resources/css/components/lf-premium-card.css b/resources/css/components/lf-premium-card.css index 3af6783..9a83ca9 100644 --- a/resources/css/components/lf-premium-card.css +++ b/resources/css/components/lf-premium-card.css @@ -120,6 +120,7 @@ .lf-pc .lf-pc__title { } .lf-pc__summary { + white-space: pre-line; margin: 0; color: var(--color-text-muted); } diff --git a/resources/views/filament/cms/filmbild-feld.blade.php b/resources/views/filament/cms/filmbild-feld.blade.php new file mode 100644 index 0000000..bd726e6 --- /dev/null +++ b/resources/views/filament/cms/filmbild-feld.blade.php @@ -0,0 +1,49 @@ +{{-- + Medien- und Materialkarte, Reiter „Medien“: ein Bild aus dem Film als Kartenbild übernehmen. + - „Vorschaubild des Films übernehmen“ und „Dieses Bild übernehmen“ legen das Bild einmal als Bild-Medium im + Medienmanager ab (FilmStill) und wählen es im Bildfeld aus. Seitenaufrufe lesen nur diese Datei. + - Die Vorschau der gewählten Stelle zieht ein Bild über die Redaktionsroute editorial.frame (nur angemeldete + Redaktion) und startet erst nach „Anzeigen“, nicht bei jeder Eingabe. + Die Datei des Films bleibt geschützt; übernommen wird nur ein Einzelbild bis 1600 px Breite. +--}} +@php + $pfad = $getStatePath(); + $ziel = preg_replace('/[^.]+$/', 'image', $pfad); + $framePfad = $filmVersionId !== null ? route('editorial.frame', ['version' => $filmVersionId]) : null; +@endphp + +
+

+ Aus dem Film „{{ $filmTitle }}“ ein Bild für die Website übernehmen. Das Bild wird einmal gespeichert und im + Medienmanager als Bild angelegt. Der Film selbst wird nicht veröffentlicht; die Karte spielt nichts ab. +

+ @if ($filmHasThumbnail) + + Vorschaubild des Films übernehmen + + @endif + @if ($framePfad !== null) +
+ + + Anzeigen + + +
+ @else +

Der Film hat noch keine bereitgestellte Fassung; eine Stelle lässt sich erst danach wählen.

+ @endif +
+
diff --git a/resources/views/filament/cms/styles.blade.php b/resources/views/filament/cms/styles.blade.php index e24e5cb..df32cc3 100644 --- a/resources/views/filament/cms/styles.blade.php +++ b/resources/views/filament/cms/styles.blade.php @@ -86,6 +86,14 @@ .luf-media-badge-warn { background: #fff1c7; color: #6b4b00; } .luf-media-badge-wait { background: #e5eef8; color: #18456f; } .luf-media-badge-quiet { background: #eceff1; color: #3e4c5c; } + /* Medien- und Materialkarte: Bild aus dem Film übernehmen. */ + .luf-filmbild { display: flex; flex-direction: column; gap: .75rem; padding: .75rem; border: 1px solid #d5ddd6; border-radius: .5rem; } + .luf-filmbild-lead { margin: 0; font-size: .875rem; } + .luf-filmbild-frame { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; } + .luf-filmbild-label { display: flex; flex-direction: column; gap: .25rem; font-size: .875rem; } + .luf-filmbild-second { width: 8rem; padding: .35rem .5rem; border: 1px solid #b9c4bd; border-radius: .375rem; } + .luf-filmbild-preview { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; width: 100%; } + .luf-filmbild-preview img { width: 100%; max-width: 28rem; height: auto; border-radius: .375rem; background: #eef1ee; } .luf-media-status { display: flex; gap: 1rem; align-items: flex-start; padding: .75rem; border: 1px solid #d5ddd6; border-radius: .5rem; } .luf-media-status img { width: 10rem; height: auto; border-radius: .375rem; } .luf-media-status strong { display: block; } diff --git a/resources/views/widgets/premium_card.blade.php b/resources/views/widgets/premium_card.blade.php index 87542b7..24a922b 100644 --- a/resources/views/widgets/premium_card.blade.php +++ b/resources/views/widgets/premium_card.blade.php @@ -24,7 +24,7 @@ $panelName = ['catalog' => 'die Navy-Tafel', 'film' => 'die Filmtafel', 'material' => 'das Materialsymbol'][$subject->visual] ?? 'die Karte ohne Bild'; if ($context->preview && $imageUrl === null) { $hints[] = $subject->previewImage !== null - ? 'Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben; öffentlich erscheint stattdessen '.$panelName.'. Ein freigegebenes Motiv kann im Reiter „Medien“ als Kartenbild gewählt werden.' + ? 'Das Vorschaubild der Bibliothek ist nicht für die Website freigegeben; öffentlich erscheint stattdessen '.$panelName.'. Ein freigegebenes Motiv kann im Reiter „Medien“ als Kartenbild gewählt werden'.($subject->visual === 'film' ? '; bei einem Film genügt „Vorschaubild des Films übernehmen“.' : '.') : 'Kein Kartenbild gewählt; öffentlich erscheint '.$panelName.' (Kartenbild im Reiter „Medien“).'; } @endphp diff --git a/tests/Feature/CmsMediaCardTextTest.php b/tests/Feature/CmsMediaCardTextTest.php new file mode 100644 index 0000000..5e5c37f --- /dev/null +++ b/tests/Feature/CmsMediaCardTextTest.php @@ -0,0 +1,174 @@ +publicFilm(); + + $this->publish('/textwahl', [ + $this->card($film, []), + $this->card($film, ['text_source' => 'auto']), + $this->card($film, ['text_source' => 'teaser']), + $this->card($film, ['text_source' => 'summary']), + $this->card($film, ['text_source' => 'description']), + ]); + + $cards = $this->cards($this->get('/textwahl')->assertOk()->getContent()); + $this->assertCount(5, $cards); + $this->assertStringContainsString('KURZ-TEXT', $cards[0]); + $this->assertStringContainsString('KURZ-TEXT', $cards[1]); + $this->assertStringContainsString('TEASER-TEXT', $cards[2]); + $this->assertStringNotContainsString('KURZ-TEXT', $cards[2]); + $this->assertStringContainsString('KURZ-TEXT', $cards[3]); + $this->assertStringContainsString('LANG-TEXT', $cards[4]); + $this->assertStringContainsString('zweiter Absatz', $cards[4]); + + foreach ($cards as $index => $card) { + foreach (['EINSATZ-INTERN', 'LIZENZ-INTERN'] as $internal) { + $this->assertStringNotContainsString($internal, $card, "Karte $index: Einsatzhinweis und Lizenzvermerk bleiben intern."); + } + } + + foreach ([0, 1, 2, 3] as $index) { + $this->assertStringNotContainsString('LANG-TEXT', $cards[$index], 'Die ausführliche Beschreibung erscheint nur auf ausdrückliche Wahl.'); + } + } + + public function test_the_default_falls_back_to_the_teaser_but_an_explicit_choice_does_not(): void + { + $film = $this->publicFilm(['summary' => null]); + + $revision = $this->publish('/textwahl-ersatz', [ + $this->card($film, []), + $this->card($film, ['text_source' => 'summary']), + ]); + + $cards = $this->cards($this->get('/textwahl-ersatz')->assertOk()->getContent()); + $this->assertStringContainsString('TEASER-TEXT', $cards[0], 'Vorgabe: ohne Kurzbeschreibung der Teaser, wie bisher.'); + $this->assertStringNotContainsString('lf-pc__summary', $cards[1], 'Gewählte, nicht gepflegte Kurzbeschreibung: kein stiller Ersatz.'); + $this->assertStringNotContainsString('TEASER-TEXT', $cards[1]); + + $this->assertStringNotContainsString('Keine Kurzbeschreibung gepflegt', $this->get('/textwahl-ersatz')->getContent(), 'Hinweise erscheinen öffentlich nie.'); + $this->assertStringNotContainsString('Für eine vollständige Karte', $this->get('/textwahl-ersatz')->getContent()); + + $preview = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->get(route('pages.preview', $revision))->assertOk()->getContent(); + $this->assertStringContainsString('Keine Kurzbeschreibung gepflegt (Medium bearbeiten → Kurzbeschreibung).', $preview); + } + + public function test_the_own_text_of_the_card_wins_over_the_chosen_central_text(): void + { + $film = $this->publicFilm(); + + $this->publish('/textwahl-eigen', [ + $this->card($film, ['text_source' => 'description'], ['summary' => 'EIGENER-KARTENTEXT']), + ]); + + $card = $this->cards($this->get('/textwahl-eigen')->assertOk()->getContent())[0]; + $this->assertStringContainsString('EIGENER-KARTENTEXT', $card); + $this->assertStringNotContainsString('LANG-TEXT', $card); + } + + public function test_the_choice_is_limited_to_the_three_central_texts_and_to_the_media_card(): void + { + $film = $this->publicFilm(); + $registry = app(WidgetRegistry::class); + + $this->assertSame(['auto', 'teaser', 'summary', 'description'], array_keys($registry->get('media_card')->settingOptions()['text_source'])); + $this->assertArrayNotHasKey('text_source', $registry->get('program_card')->settingOptions()); + $this->assertArrayNotHasKey('text_source', $registry->get('topic_card')->settingOptions()); + + foreach (['usage_note', 'license_note', 'working_title'] as $internal) { + try { + $registry->normalize([['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => ['text_source' => $internal], 'data' => [], 'refs' => ['element' => $film->id]]]); + $this->fail("Der interne Text $internal wurde als Kartentext angenommen."); + } catch (ValidationException $exception) { + $this->assertArrayHasKey('blocks.0.settings.text_source', $exception->errors()); + } + } + } + + /** + * @param array $extra + */ + private function publicFilm(array $extra = []): ContentElement + { + $content = app(ContentService::class); + $kind = fn (string $slug) => EditorialContentKind::query()->where('slug', $slug)->value('id'); + $film = $content->createElement('film', 'film', 'Denkpause Rohschnitt'); + $film->update($extra + [ + 'display_title' => 'Eine Pause, die stark macht', + 'teaser' => 'TEASER-TEXT', + 'summary' => 'KURZ-TEXT', + 'description' => "LANG-TEXT erster Absatz\n\nzweiter Absatz", + 'usage_note' => 'EINSATZ-INTERN', + 'license_note' => 'LIZENZ-INTERN', + ]); + $version = $content->publishElementVersion($film, 'Film'); + $composition = $content->createComposition('Programm Denkpause'); + $composition->editorial_content_kind_id = $kind('programm'); + $composition->save(); + $shown = $content->publishComposition($composition, [['role' => 'Film', 'target' => $version]]); + app(CompositionDisplayRelease::class)->release($shown, User::factory()->create()); + + return $film->refresh(); + } + + /** + * @param array $settings + * @param array $data + * @return array + */ + private function card(ContentElement $film, array $settings, array $data = []): array + { + return ['layout' => 'u4', 'style' => [], 'slots' => [ + ['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => $settings, 'data' => $data, 'refs' => ['element' => $film->id]], + ]]; + } + + /** + * @param list> $sections + */ + private function publish(string $path, array $sections): PageRevision + { + $page = Page::query()->create(['path' => $path]); + $service = app(PageService::class); + $revision = $service->saveRevision($page, $sections, null, null, null); + $service->publish($page, $revision); + + return $revision; + } + + /** + * @return list + */ + private function cards(string $html): array + { + preg_match_all('#
assertStringContainsString($message, $exception->getMessage()); + } + } + + $this->extractor->fail = true; + + try { + app(FilmStill::class)->fromSecond($noThumbnail, 5); + $this->fail('Eine nicht ziehbare Stelle wurde angenommen.'); + } catch (DomainRuleException $exception) { + $this->assertStringContainsString('kein Bild erzeugen', $exception->getMessage()); + } + + $this->assertSame(0, ContentElement::query()->where('output_class', 'bild')->count(), 'Bei einer Ablehnung entsteht kein Medium.'); + $this->assertSame(0, FilmStillSource::query()->count()); + } + + public function test_the_card_shows_the_stored_image_and_a_page_view_never_extracts_a_frame(): void + { + $film = $this->film(); + $still = app(FilmStill::class)->fromSecond($film, 41.5)->refresh(); + $this->assertCount(1, $this->extractor->calls); + $this->publishInProgram($film); + + $page = Page::query()->create(['path' => '/filmkarte']); + $service = app(PageService::class); + $service->publish($page, $service->saveRevision($page, [ + ['layout' => 'u4', 'style' => [], 'slots' => [ + ['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id, 'image' => $still->id]], + ]], + ], null, null, null)); + + for ($i = 0; $i < 3; $i++) { + $html = $this->get('/filmkarte')->assertOk()->getContent(); + } + + $this->assertStringContainsString('src="'.route('website.media', $still).'"', $html); + $this->assertStringContainsString('alt="Szene aus dem Film „Lara im Park“"', htmlspecialchars_decode($html)); + $this->assertStringNotContainsString('lf-pc__panel--film', $html, 'Mit freigegebenem Bild erscheint keine Filmtafel.'); + $this->assertStringNotContainsString('/redaktion/', $html); + $this->assertCount(1, $this->extractor->calls, 'Seitenaufrufe lesen nur die gespeicherte Datei und starten keine Bildextraktion.'); + + app(WebsiteRelease::class)->withdraw($still); + $this->app->forgetScopedInstances(); + $this->assertStringNotContainsString('main($this->get('/filmkarte')->getContent()), 'Zurückgenommen: das Bild entfällt, die Karte bleibt (Filmtafel).'); + } + + public function test_the_editor_adopts_a_frame_into_the_image_field_and_rejects_foreign_targets(): void + { + $film = $this->film(); + $film->forceFill(['thumbnail_path' => 'vorschau/element-'.$film->id.'.jpg', 'thumbnail_source' => 'eigen'])->save(); + Storage::disk('media_derived')->put($film->thumbnail_path, $this->jpeg(640, 360)); + $editor = User::factory()->redakteur()->create(); + $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); + $page = Page::query()->create(['path' => '/filmbild-editor']); + app(PageService::class)->saveRevision($page, [ + ['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'media_card', 'v' => 1, 'variant' => 'adaptive', 'settings' => [], 'data' => [], 'refs' => ['element' => $film->id]]]], + ], null, null, null); + + $component = Livewire::actingAs($editor, 'staff')->test(EditPage::class, ['record' => $page->id]); + + $component->call('adoptFilmFrame', 'data.ziel.image', $film->id, '12.5'); + $frame = ContentElement::query()->where('output_class', 'bild')->latest('id')->firstOrFail(); + $this->assertSame($frame->id, $component->get('data.ziel.image')); + $this->assertSame('Standbild: Lara im Park (Fassung 1, 12,5 s)', $frame->display_title); + + $component->call('adoptFilmThumbnail', 'data.ziel2.image', $film->id); + $this->assertNotNull($component->get('data.ziel2.image')); + + $before = ContentElement::query()->count(); + $component->call('adoptFilmFrame', 'data.ziel3.image', $film->id, 'abc'); + $component->call('adoptFilmFrame', 'umgebung.geheim', $film->id, '5'); + $component->call('adoptFilmFrame', 'data.ziel4.bild', $film->id, '5'); + $component->call('adoptFilmFrame', 'data.ziel5.image', 999999, '5'); + $this->assertSame($before, ContentElement::query()->count(), 'Fremde Ziele, falsche Eingaben und fehlende Filme legen nichts an.'); + $this->assertNull($component->get('data.ziel3.image')); + } + + private function film(string $title = 'Lara im Park'): ContentElement + { + $content = app(ContentService::class); + $film = $content->createElement('film', 'film', $title); + $film->update(['website_credit' => 'Foto: Lara und Felix']); + $content->publishElementVersion($film, 'Film'); + + return $film->refresh(); + } + + private function publishInProgram(ContentElement $film): void + { + $content = app(ContentService::class); + $composition = $content->createComposition('Programm Park'); + $composition->editorial_content_kind_id = EditorialContentKind::query()->where('slug', 'programm')->value('id'); + $composition->save(); + $version = $content->publishComposition($composition, [['role' => 'Film', 'target' => $film->versions()->firstOrFail()]]); + app(CompositionDisplayRelease::class)->release($version, User::factory()->create()); + } + + private function main(string $html): string + { + preg_match('#]*>(.*)#s', $html, $match); + + return $match[1] ?? ''; + } + + private function jpeg(int $width, int $height): string + { + $image = imagecreatetruecolor($width, $height); + imagefill($image, 0, 0, imagecolorallocate($image, 40, 120, 90)); + ob_start(); + imagejpeg($image); + + return (string) ob_get_clean(); + } +}