Plugin-System; Neuigkeiten und Termine als mitgelieferte Plugins

- Plugins nach WordPress-Prinzip: plugin.json-Manifest mit Versions- und
  Abhängigkeitsprüfung, eigenes PSR-4-Autoloading, register()/boot(),
  activate()/deactivate()/uninstall(), Migrationen, Routen und Views je Plugin
- plugins-core/ (mitgeliefert, aktiv bis zur Deaktivierung) und plugins/
  (Kunden-Plugins, geschützt vor Updates, inaktiv bis zur Aktivierung)
- Zustand in storage/app/plugins.json – Laden ohne Datenbankabfrage
- Wiederherstellungsmodus: Ausnahmen und Fatal Errors beim Laden
  deaktivieren das Plugin, das Portal bleibt erreichbar
- Hooks (Actions/Filter mit Prioritäten) und Registries für Navigation,
  Startseiten-Kacheln, Rechte und Admin-Seiten (Filament-Discovery)
- Admin-Seite „Plugins“: aktivieren, deaktivieren, per ZIP installieren
  (ZIP-Slip-Schutz), löschen mit oder ohne Daten; abschaltbar per
  INHAUS_DISALLOW_FILE_MODS
- Startseite komplett aus Kacheln; Plugin-Seiten als „slug::Seite“
- Version 0.3.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 07:06:16 +00:00
parent cc0020458f
commit 28ef1e4a20
155 changed files with 2762 additions and 573 deletions

View file

@ -0,0 +1,102 @@
<?php
namespace App\Filament\Pages;
use App\Plugins\PluginInstaller;
use App\Plugins\PluginManager;
use App\Plugins\PluginManifest;
use BackedEnum;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
use Filament\Support\Icons\Heroicon;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Livewire\WithFileUploads;
use Throwable;
use UnitEnum;
class Plugins extends Page
{
use WithFileUploads;
protected string $view = 'filament.pages.plugins';
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedPuzzlePiece;
protected static string|UnitEnum|null $navigationGroup = 'System';
protected static ?int $navigationSort = 5;
protected static ?string $title = 'Plugins';
protected static ?string $slug = 'plugins';
/** @var TemporaryUploadedFile|null */
public $archive = null;
public static function canAccess(): bool
{
return auth()->user()?->can('plugins.manage') ?? false;
}
public function activate(string $slug, PluginManager $plugins): void
{
$this->run(fn () => $plugins->activate($slug), 'Plugin aktiviert', 'Die Änderungen sind ab dem nächsten Seitenaufruf sichtbar.');
}
public function deactivate(string $slug, PluginManager $plugins): void
{
$this->run(fn () => $plugins->deactivate($slug), 'Plugin deaktiviert', 'Die Daten bleiben erhalten und stehen nach erneuter Aktivierung wieder zur Verfügung.');
}
public function delete(string $slug, bool $removeData, PluginManager $plugins): void
{
$this->run(fn () => $plugins->delete($slug, $removeData), 'Plugin gelöscht', $removeData ? 'Das Plugin und seine Daten wurden entfernt.' : 'Die Daten des Plugins sind noch in der Datenbank.');
}
public function upload(PluginInstaller $installer): void
{
$this->validate(['archive' => ['required', 'file', 'mimes:zip', 'max:51200']], attributes: ['archive' => 'ZIP-Archiv']);
try {
$manifest = $installer->install($this->archive->getRealPath());
$this->archive = null;
Notification::make()
->success()
->title("„{$manifest->name}“ {$manifest->version} installiert")
->body('Das Plugin kann jetzt aktiviert werden.')
->send();
} catch (Throwable $e) {
$this->addError('archive', $e->getMessage());
}
}
private function run(callable $action, string $title, string $body): void
{
try {
$action();
Notification::make()->success()->title($title)->body($body)->send();
$this->redirect(static::getUrl());
} catch (Throwable $e) {
Notification::make()->danger()->title('Nicht möglich')->body($e->getMessage())->send();
}
}
/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
$plugins = app(PluginManager::class);
return [
'plugins' => collect($plugins->all())->map(fn (PluginManifest $m) => [
'manifest' => $m,
'enabled' => $plugins->isEnabled($m->slug),
'problem' => $plugins->problem($m->slug) ?? (($issues = $m->incompatibilities()) ? implode(', ', $issues) : null),
'dependents' => $plugins->dependents($m->slug),
])->sortBy(fn (array $p) => [$p['manifest']->core ? 0 : 1, $p['manifest']->name])->values(),
'uploadsAllowed' => PluginInstaller::uploadsAllowed(),
];
}
}

View file

@ -1,140 +0,0 @@
<?php
namespace App\Filament\Resources\Events;
use App\Filament\Resources\Events\Pages\CreateEvent;
use App\Filament\Resources\Events\Pages\EditEvent;
use App\Filament\Resources\Events\Pages\ListEvents;
use App\Models\Event;
use BackedEnum;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TernaryFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use UnitEnum;
class EventResource extends Resource
{
protected static ?string $model = Event::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCalendarDays;
protected static string|UnitEnum|null $navigationGroup = 'Inhalte';
protected static ?int $navigationSort = 3;
protected static ?string $modelLabel = 'Termin';
protected static ?string $pluralModelLabel = 'Termine';
protected static ?string $slug = 'termine';
protected static ?string $recordTitleAttribute = 'title';
public static function form(Schema $schema): Schema
{
return $schema
->columns(3)
->components([
Section::make('Termin')
->columnSpan(2)
->columns(2)
->schema([
TextInput::make('title')->label('Titel')->required()->maxLength(160)->columnSpanFull(),
Toggle::make('all_day')->label('Ganztägig')->live()->columnSpanFull(),
DateTimePicker::make('starts_at')
->label('Beginn')
->required()
->seconds(false)
->native(false)
->time(fn (Get $get) => ! $get('all_day'))
->displayFormat(fn (Get $get) => $get('all_day') ? 'd.m.Y' : 'd.m.Y H:i'),
DateTimePicker::make('ends_at')
->label('Ende')
->seconds(false)
->native(false)
->time(fn (Get $get) => ! $get('all_day'))
->displayFormat(fn (Get $get) => $get('all_day') ? 'd.m.Y' : 'd.m.Y H:i')
->afterOrEqual('starts_at'),
TextInput::make('location')->label('Ort')->maxLength(255),
TextInput::make('online_url')->label('Online-Link')->url()->maxLength(500)->placeholder('https://…'),
RichEditor::make('description')
->label('Beschreibung')
->toolbarButtons([
['bold', 'italic', 'link'],
['bulletList', 'orderedList'],
['undo', 'redo'],
])
->columnSpanFull(),
]),
Section::make('Anzeige')
->columnSpan(1)
->schema([
Toggle::make('is_published')->label('Veröffentlicht')->default(true),
FileUpload::make('image_path')
->label('Bild')
->helperText('Optional, Querformat.')
->image()
->disk('uploads')
->directory('events')
->visibility('public')
->imageAspectRatio('16:9')
->automaticallyCropImagesToAspectRatio()
->maxSize(10 * 1024),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('starts_at')
->columns([
TextColumn::make('starts_at')
->label('Datum')
->formatStateUsing(fn (Event $record) => $record->starts_at->format($record->all_day ? 'd.m.Y' : 'd.m.Y H:i'))
->sortable(),
TextColumn::make('title')->label('Titel')->searchable()->limit(60)->weight('medium'),
TextColumn::make('location')->label('Ort')->limit(40)->toggleable(),
IconColumn::make('is_published')->label('Veröffentlicht')->boolean(),
])
->filters([
TernaryFilter::make('upcoming')
->label('Zeitraum')
->placeholder('Alle')
->trueLabel('Anstehende')
->falseLabel('Vergangene')
->default(true)
->queries(
true: fn (Builder $query) => $query->where(fn ($q) => $q->where('ends_at', '>=', now())->orWhere(fn ($q) => $q->whereNull('ends_at')->where('starts_at', '>=', now()->startOfDay()))),
false: fn (Builder $query) => $query->where(fn ($q) => $q->where('ends_at', '<', now())->orWhere(fn ($q) => $q->whereNull('ends_at')->where('starts_at', '<', now()->startOfDay()))),
),
])
->recordActions([
EditAction::make(),
DeleteAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => ListEvents::route('/'),
'create' => CreateEvent::route('/neu'),
'edit' => EditEvent::route('/{record}/bearbeiten'),
];
}
}

View file

@ -1,18 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Pages;
use App\Filament\Resources\Events\EventResource;
use Filament\Resources\Pages\CreateRecord;
class CreateEvent extends CreateRecord
{
protected static string $resource = EventResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['author_id'] = auth()->id();
return $data;
}
}

View file

@ -1,11 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Pages;
use App\Filament\Resources\Events\EventResource;
use Filament\Resources\Pages\EditRecord;
class EditEvent extends EditRecord
{
protected static string $resource = EventResource::class;
}

View file

@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\Events\Pages;
use App\Filament\Resources\Events\EventResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListEvents extends ListRecords
{
protected static string $resource = EventResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make()->label('Neuer Termin'),
];
}
}

View file

@ -1,78 +0,0 @@
<?php
namespace App\Filament\Resources\NewsCategories;
use App\Filament\Resources\NewsCategories\Pages\ManageNewsCategories;
use App\Models\NewsCategory;
use BackedEnum;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Support\Str;
use UnitEnum;
class NewsCategoryResource extends Resource
{
protected static ?string $model = NewsCategory::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedTag;
protected static string|UnitEnum|null $navigationGroup = 'Inhalte';
protected static ?int $navigationSort = 2;
protected static ?string $modelLabel = 'Kategorie';
protected static ?string $pluralModelLabel = 'Kategorien';
protected static ?string $slug = 'kategorien';
public static function form(Schema $schema): Schema
{
return $schema->components([
TextInput::make('name')
->label('Name')
->required()
->maxLength(60)
->live(onBlur: true)
->afterStateUpdated(fn (?string $state, Set $set, string $operation) => $operation === 'create' ? $set('slug', Str::slug((string) $state, language: 'de')) : null),
TextInput::make('slug')
->label('Kürzel in der Adresse')
->required()
->maxLength(80)
->alphaDash()
->unique(ignoreRecord: true),
TextInput::make('description')->label('Beschreibung')->maxLength(500)->columnSpanFull(),
TextInput::make('sort')->label('Reihenfolge')->numeric()->default(0),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('sort')
->reorderable('sort')
->columns([
TextColumn::make('name')->label('Name')->searchable(),
TextColumn::make('slug')->label('Kürzel')->color('gray'),
TextColumn::make('posts_count')->label('Beiträge')->counts('posts'),
])
->recordActions([
EditAction::make(),
DeleteAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => ManageNewsCategories::route('/'),
];
}
}

View file

@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\NewsCategories\Pages;
use App\Filament\Resources\NewsCategories\NewsCategoryResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ManageRecords;
class ManageNewsCategories extends ManageRecords
{
protected static string $resource = NewsCategoryResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View file

@ -1,156 +0,0 @@
<?php
namespace App\Filament\Resources\NewsPosts;
use App\Filament\Resources\NewsPosts\Pages\CreateNewsPost;
use App\Filament\Resources\NewsPosts\Pages\EditNewsPost;
use App\Filament\Resources\NewsPosts\Pages\ListNewsPosts;
use App\Models\NewsPost;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use UnitEnum;
class NewsPostResource extends Resource
{
protected static ?string $model = NewsPost::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedNewspaper;
protected static string|UnitEnum|null $navigationGroup = 'Inhalte';
protected static ?int $navigationSort = 1;
protected static ?string $modelLabel = 'Beitrag';
protected static ?string $pluralModelLabel = 'Neuigkeiten';
protected static ?string $slug = 'neuigkeiten';
protected static ?string $recordTitleAttribute = 'title';
public static function form(Schema $schema): Schema
{
return $schema
->columns(3)
->components([
Section::make('Beitrag')
->columnSpan(2)
->schema([
TextInput::make('title')->label('Titel')->required()->maxLength(160),
Textarea::make('teaser')
->label('Kurztext')
->helperText('Erscheint in Listen und auf der Startseite. 1–2 Sätze.')
->rows(2)
->maxLength(300),
RichEditor::make('body')
->label('Text')
->toolbarButtons([
['bold', 'italic', 'underline', 'link'],
['h2', 'h3'],
['bulletList', 'orderedList', 'blockquote'],
['attachFiles', 'table'],
['undo', 'redo'],
])
->fileAttachmentsDisk('uploads')
->fileAttachmentsDirectory('news/inline')
->fileAttachmentsVisibility('public')
->fileAttachmentsAcceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])
->fileAttachmentsMaxSize(8 * 1024),
]),
Section::make('Veröffentlichung')
->columnSpan(1)
->schema([
Select::make('category_id')
->label('Kategorie')
->relationship('category', 'name')
->preload()
->searchable(),
DateTimePicker::make('published_at')
->label('Veröffentlichen am')
->helperText('Leer lassen = Entwurf. Ein Datum in der Zukunft plant den Beitrag.')
->seconds(false)
->native(false)
->displayFormat('d.m.Y H:i'),
Toggle::make('is_featured')
->label('Auf der Startseite hervorheben')
->helperText('Hervorgehobene Beiträge mit Titelbild erscheinen groß im Slider.'),
FileUpload::make('cover_path')
->label('Titelbild')
->helperText('Querformat, mindestens 1600 × 900 Pixel.')
->image()
->disk('uploads')
->directory('news')
->visibility('public')
->imageAspectRatio('16:9')
->automaticallyCropImagesToAspectRatio()
->maxSize(10 * 1024),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->columns([
ImageColumn::make('cover_path')->label('')->disk('uploads')->width(80)->height(45),
TextColumn::make('title')->label('Titel')->searchable()->limit(60)->weight('medium'),
TextColumn::make('category.name')->label('Kategorie')->badge()->color('gray'),
TextColumn::make('status')
->label('Status')
->badge()
->state(fn (NewsPost $record) => match (true) {
$record->published_at === null => 'Entwurf',
$record->published_at->isFuture() => 'Geplant',
default => 'Veröffentlicht',
})
->color(fn (string $state) => match ($state) {
'Veröffentlicht' => 'success',
'Geplant' => 'warning',
default => 'gray',
}),
IconColumn::make('is_featured')->label('Hervorgehoben')->boolean()->trueIcon(Heroicon::Star)->falseIcon(false)->trueColor('warning'),
TextColumn::make('published_at')->label('Veröffentlicht')->dateTime('d.m.Y H:i')->sortable(),
])
->filters([
SelectFilter::make('category_id')->label('Kategorie')->relationship('category', 'name'),
])
->recordActions([
Action::make('view')
->label('Ansehen')
->icon(Heroicon::OutlinedEye)
->url(fn (NewsPost $record) => route('news.show', $record))
->openUrlInNewTab()
->visible(fn (NewsPost $record) => $record->isPublished()),
EditAction::make(),
DeleteAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => ListNewsPosts::route('/'),
'create' => CreateNewsPost::route('/neu'),
'edit' => EditNewsPost::route('/{record}/bearbeiten'),
];
}
}

View file

@ -1,18 +0,0 @@
<?php
namespace App\Filament\Resources\NewsPosts\Pages;
use App\Filament\Resources\NewsPosts\NewsPostResource;
use Filament\Resources\Pages\CreateRecord;
class CreateNewsPost extends CreateRecord
{
protected static string $resource = NewsPostResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['author_id'] = auth()->id();
return $data;
}
}

View file

@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\NewsPosts\Pages;
use App\Filament\Resources\NewsPosts\NewsPostResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditNewsPost extends EditRecord
{
protected static string $resource = NewsPostResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}

View file

@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\NewsPosts\Pages;
use App\Filament\Resources\NewsPosts\NewsPostResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListNewsPosts extends ListRecords
{
protected static string $resource = NewsPostResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make()->label('Neuer Beitrag'),
];
}
}