Mediathek: zentrale Bildverwaltung mit Verwendungsnachweis und Bildauswahl
- Tabellen media und media_usages, Modelle Media/MediaUsage - App\Media\MediaLibrary (store/register/replace/delete/rebuild) und Registry App\Media\MediaUsages (Quellen: Seiten, Neuigkeiten inkl. künftiger content-Spalte, Termine, Startseiten-Kacheln), ImagePaths-Extraktor - Alle Uploads landen in der Mediathek (Seiten-Editor direkt, übrige über Beobachter beim Speichern); Daten-Migration und media:rebuild übernehmen bestehende Bilder - Recht media.manage, Zugang media.use für alle Redaktionsbereiche - /redaktion/mediathek (Suche, Filter, Upload mit Fortschritt, Details, Eingebunden in, Ersetzen, Löschen mit Warnung, Mehrfachauswahl), Abschnitt in der Redaktion und Menüpunkt im Admin-Bereich - MediaPicker (Hochladen/Mediathek) im Pagebuilder: Bildfelder und Galerie (Mehrfachauswahl), editor.pickMedia im provide-API - Bild-URLs mit ?v=Änderungszeit, null bei fehlender Datei; Modelle löschen geteilte Bilder nicht mehr selbst Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3b72b5327e
commit
694ccf6ae0
46 changed files with 3101 additions and 89 deletions
|
|
@ -3,6 +3,8 @@
|
|||
namespace Inhaus\Plugins\Events;
|
||||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Media\ImagePaths;
|
||||
use App\Media\MediaUsages;
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\BlockType;
|
||||
|
|
@ -26,6 +28,14 @@ class EventsPlugin extends Plugin
|
|||
$this->app->make(Abilities::class)->define('events.manage', 'Termine verwalten', 'Termine');
|
||||
Gate::policy(Event::class, EventPolicy::class);
|
||||
|
||||
// Mediathek „Eingebunden in“
|
||||
$usages = $this->app->make(MediaUsages::class);
|
||||
$usages->add('events', 'Termine', fn (Event $event) => [
|
||||
['context' => 'Titelbild', 'label' => $event->title, 'url' => route('events.show', $event, false), 'draft' => $event->is_published === false, 'paths' => [$event->image_path]],
|
||||
['context' => ImagePaths::HTML_CONTEXT, 'label' => $event->title, 'url' => route('events.show', $event, false), 'draft' => $event->is_published === false, 'paths' => ImagePaths::fromHtml($event->description_html)],
|
||||
], fn (callable $each) => Event::query()->chunkById(100, fn ($events) => $events->each($each)));
|
||||
$usages->watch('events', Event::class, ['image_path', 'description_html', 'title', 'is_published']);
|
||||
|
||||
$this->app->make(Widgets::class)->add('events.upcoming', 'events::Upcoming', 'aside', sort: 20, props: fn (User $user) => [
|
||||
'events' => EventResource::collection(Event::query()->upcoming()->visibleTo($user)->limit(4)->get())->resolve(),
|
||||
], label: 'Termine', mobileSort: 30);
|
||||
|
|
|
|||
|
|
@ -34,24 +34,17 @@ class Event extends Model
|
|||
}
|
||||
});
|
||||
|
||||
// Bildvarianten erzeugen bzw. beim Austausch die alten Dateien entfernen.
|
||||
// Bildvarianten erzeugen. Alte Bilder bleiben in der Mediathek (sie können
|
||||
// auch anderswo eingebunden sein) und lassen sich dort als „nicht verwendet“ aufräumen.
|
||||
static::saved(function (Event $event): void {
|
||||
if (! $event->wasRecentlyCreated && ! $event->wasChanged('image_path')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$previous = $event->wasRecentlyCreated ? null : $event->getOriginal('image_path');
|
||||
|
||||
if ($previous && $previous !== $event->image_path) {
|
||||
app(Images::class)->deleteWithVariants($previous);
|
||||
}
|
||||
|
||||
if ($event->image_path) {
|
||||
app(Images::class)->createVariants($event->image_path);
|
||||
}
|
||||
});
|
||||
|
||||
static::deleted(fn (Event $event) => app(Images::class)->deleteWithVariants($event->image_path));
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
|
|
|
|||
|
|
@ -54,24 +54,17 @@ class NewsPost extends Model
|
|||
}
|
||||
});
|
||||
|
||||
// Bildvarianten erzeugen bzw. beim Austausch die alten Dateien entfernen.
|
||||
// Bildvarianten erzeugen. Alte Bilder bleiben in der Mediathek (sie können
|
||||
// auch anderswo eingebunden sein) und lassen sich dort als „nicht verwendet“ aufräumen.
|
||||
static::saved(function (NewsPost $post): void {
|
||||
if (! $post->wasRecentlyCreated && ! $post->wasChanged('cover_path')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$previous = $post->wasRecentlyCreated ? null : $post->getOriginal('cover_path');
|
||||
|
||||
if ($previous && $previous !== $post->cover_path) {
|
||||
app(Images::class)->deleteWithVariants($previous);
|
||||
}
|
||||
|
||||
if ($post->cover_path) {
|
||||
app(Images::class)->createVariants($post->cover_path);
|
||||
}
|
||||
});
|
||||
|
||||
static::deleted(fn (NewsPost $post) => app(Images::class)->deleteWithVariants($post->cover_path));
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ namespace Inhaus\Plugins\News;
|
|||
|
||||
use App\Dashboard\Widgets;
|
||||
use App\Editorial\Editorial;
|
||||
use App\Media\ImagePaths;
|
||||
use App\Media\MediaUsages;
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\BlockType;
|
||||
|
|
@ -15,6 +17,7 @@ use App\Support\Navigation;
|
|||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Inhaus\Plugins\News\Http\Resources\NewsPostResource;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
|
|
@ -39,6 +42,7 @@ class NewsPlugin extends Plugin
|
|||
Gate::policy(NewsPost::class, NewsPostPolicy::class);
|
||||
|
||||
$this->registerWidgets($this->app->make(Widgets::class));
|
||||
$this->registerMediaUsages($this->app->make(MediaUsages::class));
|
||||
|
||||
$this->app->make(Editorial::class)->add(
|
||||
'news',
|
||||
|
|
@ -69,6 +73,41 @@ class NewsPlugin extends Plugin
|
|||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Mediathek „Eingebunden in“: Titelbild, Bilder im Text und – sobald Beiträge
|
||||
* mit dem Pagebuilder geschrieben werden – Bilder in der Spalte „content“.
|
||||
*/
|
||||
private function registerMediaUsages(MediaUsages $usages): void
|
||||
{
|
||||
$usages->add('news', 'Neuigkeiten', function (NewsPost $post) {
|
||||
$base = ['label' => $post->title, 'url' => route('news.editor.edit', $post, false), 'draft' => $post->status !== NewsPost::PUBLISHED];
|
||||
$entries = [
|
||||
[...$base, 'context' => 'Titelbild', 'paths' => [$post->cover_path]],
|
||||
[...$base, 'context' => ImagePaths::HTML_CONTEXT, 'paths' => [...ImagePaths::fromHtml($post->body_html), ...ImagePaths::fromHtml($post->body)]],
|
||||
];
|
||||
|
||||
if (self::hasContentColumn()) {
|
||||
$content = $post->getAttribute('content');
|
||||
$content = is_string($content) ? json_decode($content, true) : $content;
|
||||
|
||||
foreach (ImagePaths::fromContent(is_array($content) ? $content : null) as $context => $paths) {
|
||||
$entries[] = [...$base, 'context' => $context, 'paths' => $paths];
|
||||
}
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}, fn (callable $each) => NewsPost::query()->chunkById(100, fn ($posts) => $posts->each($each)));
|
||||
|
||||
$usages->watch('news', NewsPost::class);
|
||||
}
|
||||
|
||||
private static function hasContentColumn(): bool
|
||||
{
|
||||
static $has;
|
||||
|
||||
return $has ??= Schema::hasColumn('news_posts', 'content');
|
||||
}
|
||||
|
||||
private function registerWidgets(Widgets $widgets): void
|
||||
{
|
||||
// Slider: hervorgehobene Beiträge mit Bild, sonst die neuesten mit Bild.
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ import BlockSettings from '@/pagebuilder/editor/BlockSettings.vue';
|
|||
import EditorBlockList from '@/pagebuilder/editor/EditorBlockList.vue';
|
||||
import { clone, createBlock, duplicate as duplicateBlock, locate, walk } from '@/pagebuilder/editor/tree';
|
||||
import { http } from '@/lib/http';
|
||||
import MediaPickerHost from '@/components/media/MediaPickerHost.vue';
|
||||
import { collectImagePaths, uploadWithProgress } from '@/components/media/api';
|
||||
import { useMediaPicker } from '@/components/media/useMediaPicker';
|
||||
import { formatTime } from '@/lib/format';
|
||||
import PublishDialog from '../components/PublishDialog.vue';
|
||||
import RevisionsDialog from '../components/RevisionsDialog.vue';
|
||||
|
|
@ -133,14 +136,18 @@ function containsActive(item) {
|
|||
return candidates.some((block) => block.items?.includes(item) || locate(item.blocks, block.id));
|
||||
}
|
||||
|
||||
// ——— Hochladen ———
|
||||
async function uploadImage(file) {
|
||||
const body = new FormData();
|
||||
body.append('image', file);
|
||||
|
||||
return http.post(`${base}/bilder`, body);
|
||||
// ——— Hochladen und Mediathek ———
|
||||
// Bilder landen im Verzeichnis der Seite und zugleich in der Mediathek.
|
||||
async function uploadImage(file, onProgress) {
|
||||
return uploadWithProgress(`${base}/bilder`, file, { onProgress });
|
||||
}
|
||||
|
||||
const mediaPicker = useMediaPicker({
|
||||
upload: uploadImage,
|
||||
contextLabel: 'Auf dieser Seite',
|
||||
contextPaths: () => collectImagePaths(working.content),
|
||||
});
|
||||
|
||||
async function uploadFile(file) {
|
||||
const body = new FormData();
|
||||
body.append('file', file);
|
||||
|
|
@ -170,6 +177,8 @@ provide('pagebuilder:editor', {
|
|||
containsActive,
|
||||
uploadImage,
|
||||
uploadFile,
|
||||
// Bildauswahl „Aus der Mediathek“: ({ multiple?, title? }) => Promise<[{ id, path, url, alt, caption, width, height }] | null>
|
||||
pickMedia: (options) => mediaPicker.pick(options),
|
||||
imageUrl: (path) => `${props.uploadsUrl}/${path}`,
|
||||
});
|
||||
provide('pagebuilder:list', EditorBlockList);
|
||||
|
|
@ -632,5 +641,6 @@ const canvasWidth = computed(() => devices.find((d) => d.key === device.value).w
|
|||
<NewPageDialog v-model:open="dialogs.newPage" :parent-id="page.id" :parent-title="page.title" @before-create="save" />
|
||||
</div>
|
||||
|
||||
<MediaPickerHost :picker="mediaPicker" />
|
||||
<Toaster position="bottom-left" />
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
namespace Inhaus\Plugins\Pages\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Media\MediaLibrary;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\Content;
|
||||
use App\Support\Audit;
|
||||
use App\Support\Images;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -312,14 +312,15 @@ class PageEditorController extends Controller
|
|||
return response()->json(['ok' => true]);
|
||||
}
|
||||
|
||||
public function uploadImage(Request $request, Page $page, Images $images): JsonResponse
|
||||
public function uploadImage(Request $request, Page $page, MediaLibrary $library): JsonResponse
|
||||
{
|
||||
Gate::authorize('update', $page);
|
||||
$request->validate(['image' => ['required', File::image()->types(['jpg', 'jpeg', 'png', 'webp', 'gif'])->max(15 * 1024)]]);
|
||||
|
||||
$path = $images->storeContentImage($request->file('image'), 'pagebuilder/pages/'.$page->id);
|
||||
// Landet zugleich in der Mediathek.
|
||||
$media = $library->store($request->file('image'), 'pagebuilder/pages/'.$page->id, $request->user());
|
||||
|
||||
return response()->json(['path' => $path, 'url' => Blocks::imageUrl($path)]);
|
||||
return response()->json(['path' => $media->path, 'url' => Blocks::imageUrl($media->path), 'media' => $media->toLibraryArray()]);
|
||||
}
|
||||
|
||||
public function uploadFile(Request $request, Page $page): JsonResponse
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
namespace Inhaus\Plugins\Pages;
|
||||
|
||||
use App\Editorial\Editorial;
|
||||
use App\Media\ImagePaths;
|
||||
use App\Media\MediaUsages;
|
||||
use App\Models\User;
|
||||
use App\Pagebuilder\Blocks;
|
||||
use App\Pagebuilder\BlockType;
|
||||
|
|
@ -88,6 +90,7 @@ class PagesPlugin extends Plugin
|
|||
);
|
||||
|
||||
$this->registerBlocks($this->app->make(Blocks::class));
|
||||
$this->registerMediaUsages($this->app->make(MediaUsages::class));
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
|
|
@ -98,6 +101,33 @@ class PagesPlugin extends Plugin
|
|||
})->everyMinute()->name('pages-scheduled')->withoutOverlapping(5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mediathek „Eingebunden in“: veröffentlichter Inhalt, Entwurf und geplanter Stand.
|
||||
*/
|
||||
private function registerMediaUsages(MediaUsages $usages): void
|
||||
{
|
||||
$usages->add('pages', 'Seiten', function (Page $page) {
|
||||
$entries = [];
|
||||
$url = route('pages.editor', $page, false);
|
||||
|
||||
foreach (['content' => false, 'scheduled_content' => true, 'draft' => true] as $column => $draft) {
|
||||
$title = match ($column) {
|
||||
'draft' => $page->draft_title ?? $page->title,
|
||||
'scheduled_content' => $page->scheduled_title ?? $page->title,
|
||||
default => $page->title,
|
||||
};
|
||||
|
||||
foreach (ImagePaths::fromContent($page->{$column}) as $context => $paths) {
|
||||
$entries[] = ['context' => $context, 'label' => $title, 'url' => $url, 'draft' => $draft, 'paths' => $paths];
|
||||
}
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}, fn (callable $each) => Page::query()->chunkById(50, fn ($pages) => $pages->each($each)));
|
||||
|
||||
$usages->watch('pages', Page::class, ['content', 'draft', 'scheduled_content', 'title', 'draft_title', 'scheduled_title']);
|
||||
}
|
||||
|
||||
private function registerBlocks(Blocks $blocks): void
|
||||
{
|
||||
$blocks->add(BlockType::make('downloads', 'Downloads', 'file-down', 'media', 'pages::Downloads')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue