Erlaube in PDF-Vorlagen jedes Bild des Medienmanagers, auch ohne Inhaltsfassung
Kopf-, Fuß- und Titelbild einer PDF-Vorlage sind Gestaltung und brauchen keine Inhaltsfassung. Der Picker bietet auch Präsentationsmedien und für die Website freigegebene Bilder an (Spalten *_element_id, Klasse TemplateImage); gedruckt wird die Website-Datei, sonst die Präsentationsdatei. Abgelehnt werden nur gesperrte oder archivierte Bilder, fehlende Dateien und Nicht-Bilder. Bilder im Text eines Dokuments bleiben an freigegebene Bildfassungen gebunden. Die öffentliche Eigenschaft heißt bilder, weil slots mit Livewires internem Slot-Mechanismus kollidiert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
765b8e779e
commit
58b68b768c
13 files changed
+369
-85
No files matched your search
@@ -5,7 +5,6 @@
|
||||
use App\Domain\Commerce\Receipt\PdfDocument;
|
||||
use App\Domain\Media\PdfImage;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Transliterator;
|
||||
|
||||
/**
|
||||
@@ -88,9 +87,9 @@ public function render(array $guide, string $licensee, string $copyId, ?PdfImage
|
||||
private function prepareLayout(?PdfTemplate $template): void
|
||||
{
|
||||
$this->bands = [
|
||||
'header' => $this->band($template?->headerVersion, 140.0),
|
||||
'footer' => $this->band($template?->footerVersion, 140.0),
|
||||
'cover' => $template !== null && $template->show_cover ? $this->band($template->coverVersion, self::PAGE_HEIGHT * 0.4) : null,
|
||||
'header' => $this->band($template?->target('header'), 140.0),
|
||||
'footer' => $this->band($template?->target('footer'), 140.0),
|
||||
'cover' => $template !== null && $template->show_cover ? $this->band($template->target('cover'), self::PAGE_HEIGHT * 0.4) : null,
|
||||
];
|
||||
$header = (float) ($this->bands['header']['height'] ?? 0);
|
||||
$footer = (float) ($this->bands['footer']['height'] ?? 0);
|
||||
@@ -104,10 +103,10 @@ private function prepareLayout(?PdfTemplate $template): void
|
||||
*
|
||||
* @return array{jpeg: string, pixelWidth: int, pixelHeight: int, width: float, height: float, x: float}|null
|
||||
*/
|
||||
private function band(?ContentElementVersion $version, float $maxHeight): ?array
|
||||
private function band(?string $target, float $maxHeight): ?array
|
||||
{
|
||||
$file = $version === null ? null : EmbeddedImages::file($version);
|
||||
$image = $file === null ? null : PdfImage::fromBytes((string) Storage::disk('media_derived')->get($file));
|
||||
$bytes = TemplateImage::bytes($target);
|
||||
$image = $bytes === null ? null : PdfImage::fromBytes($bytes);
|
||||
|
||||
if ($image === null) {
|
||||
return null;
|
||||
|
||||
@@ -22,6 +22,9 @@ class PdfTemplate extends Model
|
||||
'header_version_id',
|
||||
'footer_version_id',
|
||||
'cover_version_id',
|
||||
'header_element_id',
|
||||
'footer_element_id',
|
||||
'cover_element_id',
|
||||
'publisher',
|
||||
'copyright',
|
||||
];
|
||||
@@ -31,6 +34,34 @@ protected function casts(): array
|
||||
return ['show_cover' => 'boolean'];
|
||||
}
|
||||
|
||||
public const SLOTS = ['header', 'footer', 'cover'];
|
||||
|
||||
/**
|
||||
* Das Bild eines Bildfelds als Ziel des Pickers: `element:<Fassung>`, `medium:<Medium>` oder null.
|
||||
*/
|
||||
public function target(string $slot): ?string
|
||||
{
|
||||
$version = $this->getAttribute($slot.'_version_id');
|
||||
$element = $this->getAttribute($slot.'_element_id');
|
||||
|
||||
return $version !== null ? 'element:'.$version : ($element !== null ? 'medium:'.$element : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Die Spaltenwerte eines Bildfelds für ein Ziel des Pickers.
|
||||
*
|
||||
* @return array<string, int|null>
|
||||
*/
|
||||
public static function columns(string $slot, ?string $target): array
|
||||
{
|
||||
$ref = TemplateImage::parse($target);
|
||||
|
||||
return [
|
||||
$slot.'_version_id' => ($ref['type'] ?? null) === 'version' ? $ref['id'] : null,
|
||||
$slot.'_element_id' => ($ref['type'] ?? null) === 'medium' ? $ref['id'] : null,
|
||||
];
|
||||
}
|
||||
|
||||
public function headerVersion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ContentElementVersion::class, 'header_version_id');
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* Ein Bild einer PDF-Vorlage (ADR-51, Nachtrag). Es kommt aus dem Medienmanager in einer von zwei Formen, die der gemeinsame
|
||||
* Picker als Ziel liefert:
|
||||
*
|
||||
* - `element:<Fassung>`: ein Bild mit Inhaltsfassung (Datei im abgeleiteten Bestand), gleich in welchem Stand; nur ein gesperrtes Bild nicht,
|
||||
* - `medium:<Medium>`: ein Bild ohne Inhaltsfassung, also ein Präsentationsmedium oder ein für die Website freigegebenes Bild. Gedruckt wird
|
||||
* die für die Website freigegebene Datei, sonst die Präsentationsdatei.
|
||||
*
|
||||
* Jedes Bild mit vorhandener Datei lässt sich verwenden. Das Bild ist Gestaltung der Vorlage und kein lizenzierter Inhalt; es geht nicht über
|
||||
* die Rechteprüfung der Mitglieder und braucht keine Inhaltsfassung.
|
||||
*/
|
||||
final class TemplateImage
|
||||
{
|
||||
/**
|
||||
* @return array{type: 'version'|'medium', id: int}|null
|
||||
*/
|
||||
public static function parse(?string $target): ?array
|
||||
{
|
||||
if ($target !== null && preg_match('/^(element|medium):(\d+)$/', $target, $match) === 1) {
|
||||
return ['type' => $match[1] === 'element' ? 'version' : 'medium', 'id' => (int) $match[2]];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Die Bilddatei als Bytes, oder null, wenn sie nicht vorliegt. */
|
||||
public static function bytes(?string $target): ?string
|
||||
{
|
||||
$source = self::source($target);
|
||||
|
||||
return $source === null ? null : (string) Storage::disk($source['disk'])->get($source['path']);
|
||||
}
|
||||
|
||||
/** Warum sich das Bild nicht verwenden lässt; null, wenn es geht. */
|
||||
public static function problem(?string $target): ?string
|
||||
{
|
||||
$ref = self::parse($target);
|
||||
|
||||
if ($ref === null) {
|
||||
return 'Das ist kein Bild des Medienmanagers.';
|
||||
}
|
||||
|
||||
if ($ref['type'] === 'version') {
|
||||
$version = ContentElementVersion::query()->with('element')->find($ref['id']);
|
||||
|
||||
if (! $version instanceof ContentElementVersion || $version->element === null || $version->element->output_class !== 'bild') {
|
||||
return 'Das ist kein Bild des Medienmanagers.';
|
||||
}
|
||||
|
||||
// Gestaltung braucht keine Freigabe der Fassung; nur ein bewusst gesperrtes Bild bleibt außen vor.
|
||||
if ($version->status === ContentVersionStatus::Gesperrt) {
|
||||
return 'Dieses Bild ist deaktiviert.';
|
||||
}
|
||||
} else {
|
||||
$element = ContentElement::query()->find($ref['id']);
|
||||
|
||||
if (! $element instanceof ContentElement || $element->output_class !== 'bild' || $element->archived_at !== null) {
|
||||
return 'Das ist kein Bild des Medienmanagers.';
|
||||
}
|
||||
}
|
||||
|
||||
return self::source($target) === null ? 'Die Bilddatei liegt nicht vor.' : null;
|
||||
}
|
||||
|
||||
public static function title(?string $target): string
|
||||
{
|
||||
$ref = self::parse($target);
|
||||
$element = match ($ref['type'] ?? null) {
|
||||
'version' => ContentElementVersion::query()->with('element')->find($ref['id'])?->element,
|
||||
'medium' => ContentElement::query()->find($ref['id']),
|
||||
default => null,
|
||||
};
|
||||
|
||||
return $element === null ? '' : (string) ($element->display_title ?: $element->working_title);
|
||||
}
|
||||
|
||||
/** Adresse zur Ansicht in der Verwaltung (Vorschau im Formular). */
|
||||
public static function previewUrl(?string $target): ?string
|
||||
{
|
||||
$ref = self::parse($target);
|
||||
|
||||
if ($ref === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($ref['type'] === 'version') {
|
||||
return EmbeddedImages::staffSource($ref['id']);
|
||||
}
|
||||
|
||||
$element = ContentElement::query()->find($ref['id']);
|
||||
|
||||
if (! $element instanceof ContentElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($element->website_released_at !== null && $element->website_public_path !== null) {
|
||||
return route('website.media', $element);
|
||||
}
|
||||
|
||||
return app(EditorialCatalog::class)->cardUrl('element', $element->id, $element->thumbnail_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{disk: string, path: string}|null
|
||||
*/
|
||||
private static function source(?string $target): ?array
|
||||
{
|
||||
$ref = self::parse($target);
|
||||
|
||||
if ($ref === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($ref['type'] === 'version') {
|
||||
$version = ContentElementVersion::query()->find($ref['id']);
|
||||
$file = $version instanceof ContentElementVersion ? EmbeddedImages::file($version) : null;
|
||||
|
||||
return $file === null ? null : ['disk' => 'media_derived', 'path' => $file];
|
||||
}
|
||||
|
||||
$element = ContentElement::query()->find($ref['id']);
|
||||
|
||||
if (! $element instanceof ContentElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$public = (string) $element->website_public_path;
|
||||
|
||||
if ($element->website_released_at !== null && preg_match('#^website/'.$element->id.'/datei\.[a-z0-9]+$#', $public) === 1 && Storage::disk('media_public')->exists($public)) {
|
||||
return ['disk' => 'media_public', 'path' => $public];
|
||||
}
|
||||
|
||||
$preview = (string) $element->thumbnail_path;
|
||||
|
||||
if (str_starts_with($preview, 'vorschau/') && ! str_contains($preview, '..') && Storage::disk('media_derived')->exists($preview)) {
|
||||
return ['disk' => 'media_derived', 'path' => $preview];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user