Neuigkeiten und Termine (vorgezogen)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m8s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m5s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m6s
CI / Build-Artefakte aktuell (pull_request) Failing after 43s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m8s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m5s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m6s
CI / Build-Artefakte aktuell (pull_request) Failing after 43s
- Neuigkeiten mit Kategorien, Titelbild (WebP-Varianten), Lesezeit, geplanter Veröffentlichung und Hervorhebung; Text wird beim Speichern bereinigt - Termine mit Ort, Online-Link, ganztägigen Terminen und .ics-Export - Startseite nach Intranet-Vorbild: Slider, Neuigkeiten, Termine, Aktuelles aus den Bereichen; mobil in sinnvoller Reihenfolge - Admin: Beiträge, Kategorien und Termine - Bildverarbeitung für Shared Hosting: nur eine Vollbild-Kopie im Speicher, Speicherlimit bei Bedarf auf 256 MB angehoben (wie WordPress) - Demo-Inhalte für die Entwicklung Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f813a0fff3
commit
a36752e09a
103 changed files with 2810 additions and 124 deletions
140
app/Filament/Resources/Events/EventResource.php
Normal file
140
app/Filament/Resources/Events/EventResource.php
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
18
app/Filament/Resources/Events/Pages/CreateEvent.php
Normal file
18
app/Filament/Resources/Events/Pages/CreateEvent.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Events/Pages/EditEvent.php
Normal file
11
app/Filament/Resources/Events/Pages/EditEvent.php
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?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;
|
||||
}
|
||||
19
app/Filament/Resources/Events/Pages/ListEvents.php
Normal file
19
app/Filament/Resources/Events/Pages/ListEvents.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
<?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('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
156
app/Filament/Resources/NewsPosts/NewsPostResource.php
Normal file
156
app/Filament/Resources/NewsPosts/NewsPostResource.php
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
<?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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
18
app/Filament/Resources/NewsPosts/Pages/CreateNewsPost.php
Normal file
18
app/Filament/Resources/NewsPosts/Pages/CreateNewsPost.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/NewsPosts/Pages/EditNewsPost.php
Normal file
19
app/Filament/Resources/NewsPosts/Pages/EditNewsPost.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/NewsPosts/Pages/ListNewsPosts.php
Normal file
19
app/Filament/Resources/NewsPosts/Pages/ListNewsPosts.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,11 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\EventResource;
|
||||
use App\Http\Resources\NewsPostResource;
|
||||
use App\Http\Resources\PersonResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\NewsPost;
|
||||
use App\Models\User;
|
||||
use App\Support\QuickLinks;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -15,6 +19,20 @@ class DashboardController extends Controller
|
|||
{
|
||||
$user = $request->user();
|
||||
|
||||
// Hervorgehobene Beiträge für den Slider; ohne Hervorhebung die neuesten mit Bild.
|
||||
$featured = NewsPost::query()->published()->with('category')
|
||||
->where('is_featured', true)->whereNotNull('cover_path')
|
||||
->latest('published_at')->limit(5)->get();
|
||||
|
||||
if ($featured->isEmpty()) {
|
||||
$featured = NewsPost::query()->published()->with('category')
|
||||
->whereNotNull('cover_path')->latest('published_at')->limit(3)->get();
|
||||
}
|
||||
|
||||
$recent = NewsPost::query()->published()->with('category')
|
||||
->whereKeyNot($featured->modelKeys())
|
||||
->latest('published_at')->limit(8)->get();
|
||||
|
||||
return Inertia::render('Dashboard', [
|
||||
'profile' => [
|
||||
'job_title' => $user->job_title,
|
||||
|
|
@ -23,6 +41,10 @@ class DashboardController extends Controller
|
|||
'avatar_url' => $user->avatarUrl(256),
|
||||
],
|
||||
'quickLinks' => $quickLinks->all(),
|
||||
'featuredNews' => NewsPostResource::collection($featured),
|
||||
'latestNews' => NewsPostResource::collection($recent->take(4)->values()),
|
||||
'moreNews' => NewsPostResource::collection($recent->slice(4)->values()),
|
||||
'upcomingEvents' => EventResource::collection(Event::query()->upcoming()->limit(4)->get()),
|
||||
'newColleagues' => PersonResource::collection(
|
||||
User::query()
|
||||
->active()
|
||||
|
|
|
|||
45
app/Http/Controllers/EventController.php
Normal file
45
app/Http/Controllers/EventController.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\EventResource;
|
||||
use App\Models\Event;
|
||||
use App\Support\Branding;
|
||||
use App\Support\Calendar;
|
||||
use Illuminate\Http\Response as HttpResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
return Inertia::render('Events/Index', [
|
||||
'events' => EventResource::collection(
|
||||
Event::query()->upcoming()->limit(200)->get()
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Event $event): Response
|
||||
{
|
||||
abort_unless($event->is_published, 404);
|
||||
|
||||
return Inertia::render('Events/Show', [
|
||||
'event' => [
|
||||
...(new EventResource($event))->resolve(),
|
||||
'description_html' => $event->description_html,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function ics(Event $event, Calendar $calendar, Branding $branding): HttpResponse
|
||||
{
|
||||
abort_unless($event->is_published, 404);
|
||||
|
||||
return response($calendar->toIcs($event, $branding->portalName()), 200, [
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
'Content-Disposition' => 'attachment; filename="termin-'.$event->id.'.ics"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
64
app/Http/Controllers/NewsController.php
Normal file
64
app/Http/Controllers/NewsController.php
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\NewsPostResource;
|
||||
use App\Models\NewsCategory;
|
||||
use App\Models\NewsPost;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$categories = NewsCategory::query()->orderBy('sort')->orderBy('name')->get(['id', 'name', 'slug']);
|
||||
$category = $categories->firstWhere('slug', $request->query('kategorie'));
|
||||
|
||||
$posts = NewsPost::query()
|
||||
->published()
|
||||
->with('category')
|
||||
->when($category, fn ($query) => $query->where('category_id', $category->id))
|
||||
->latest('published_at')
|
||||
->paginate(12)
|
||||
->withQueryString();
|
||||
|
||||
return Inertia::render('News/Index', [
|
||||
'posts' => NewsPostResource::collection($posts),
|
||||
'categories' => $categories->map(fn (NewsCategory $c) => ['name' => $c->name, 'slug' => $c->slug]),
|
||||
'activeCategory' => $category?->slug,
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(NewsPost $post): Response
|
||||
{
|
||||
abort_unless($post->isPublished(), 404);
|
||||
|
||||
$post->load(['category', 'author']);
|
||||
|
||||
return Inertia::render('News/Show', [
|
||||
'post' => [
|
||||
...(new NewsPostResource($post))->resolve(),
|
||||
'body_html' => $post->body_html,
|
||||
'author' => $post->author ? [
|
||||
'id' => $post->author->id,
|
||||
'name' => $post->author->name,
|
||||
'initials' => $post->author->initials,
|
||||
'job_title' => $post->author->job_title,
|
||||
'avatar_url' => $post->author->avatarUrl(96),
|
||||
] : null,
|
||||
],
|
||||
'related' => NewsPostResource::collection(
|
||||
NewsPost::query()
|
||||
->published()
|
||||
->with('category')
|
||||
->whereKeyNot($post->id)
|
||||
->when($post->category_id, fn ($query) => $query->where('category_id', $post->category_id))
|
||||
->latest('published_at')
|
||||
->limit(3)
|
||||
->get()
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
31
app/Http/Resources/EventResource.php
Normal file
31
app/Http/Resources/EventResource.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin Event
|
||||
*/
|
||||
class EventResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'location' => $this->location,
|
||||
'online_url' => $this->online_url,
|
||||
'starts_at' => $this->starts_at->toIso8601String(),
|
||||
'ends_at' => $this->ends_at?->toIso8601String(),
|
||||
'all_day' => $this->all_day,
|
||||
'image_url' => $this->imageUrl('large'),
|
||||
'thumb_url' => $this->imageUrl('thumb'),
|
||||
];
|
||||
}
|
||||
}
|
||||
34
app/Http/Resources/NewsPostResource.php
Normal file
34
app/Http/Resources/NewsPostResource.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\NewsPost;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* @mixin NewsPost
|
||||
*/
|
||||
class NewsPostResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'slug' => $this->slug,
|
||||
'teaser' => $this->teaser,
|
||||
'category' => $this->whenLoaded('category', fn () => $this->category ? [
|
||||
'name' => $this->category->name,
|
||||
'slug' => $this->category->slug,
|
||||
] : null),
|
||||
'cover_url' => $this->coverUrl('large'),
|
||||
'thumb_url' => $this->coverUrl('thumb'),
|
||||
'published_at' => $this->published_at?->toIso8601String(),
|
||||
'reading_minutes' => $this->reading_minutes,
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Models/Event.php
Normal file
85
app/Models/Event.php
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Support\Images;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'author_id', 'title', 'description', 'location', 'online_url',
|
||||
'starts_at', 'ends_at', 'all_day', 'image_path', 'is_published',
|
||||
])]
|
||||
class Event extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (Event $event): void {
|
||||
if ($event->isDirty('description') || $event->description_html === null) {
|
||||
$event->description_html = app(RichText::class)->toSafeHtml($event->description);
|
||||
}
|
||||
});
|
||||
|
||||
// Bildvarianten erzeugen bzw. beim Austausch die alten Dateien entfernen.
|
||||
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
|
||||
{
|
||||
return [
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
'all_day' => 'boolean',
|
||||
'is_published' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function author(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Veröffentlichte Termine, die noch nicht vorbei sind (laufende eingeschlossen).
|
||||
*
|
||||
* @param Builder<Event> $query
|
||||
*/
|
||||
public function scopeUpcoming(Builder $query): void
|
||||
{
|
||||
$query->where('is_published', true)
|
||||
->where(fn (Builder $q) => $q
|
||||
->where('ends_at', '>=', now())
|
||||
->orWhere(fn (Builder $q) => $q->whereNull('ends_at')->where('starts_at', '>=', now()->startOfDay())))
|
||||
->orderBy('starts_at');
|
||||
}
|
||||
|
||||
public function imageUrl(string $variant = 'large'): ?string
|
||||
{
|
||||
return app(Images::class)->url($this->image_path, $variant);
|
||||
}
|
||||
}
|
||||
22
app/Models/NewsCategory.php
Normal file
22
app/Models/NewsCategory.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['name', 'slug', 'description', 'sort'])]
|
||||
class NewsCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return HasMany<NewsPost, $this>
|
||||
*/
|
||||
public function posts(): HasMany
|
||||
{
|
||||
return $this->hasMany(NewsPost::class, 'category_id');
|
||||
}
|
||||
}
|
||||
111
app/Models/NewsPost.php
Normal file
111
app/Models/NewsPost.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Support\Images;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Fillable([
|
||||
'category_id', 'author_id', 'title', 'slug', 'teaser', 'body',
|
||||
'cover_path', 'is_featured', 'published_at',
|
||||
])]
|
||||
class NewsPost extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (NewsPost $post): void {
|
||||
if (blank($post->slug)) {
|
||||
$post->slug = static::uniqueSlug($post->title, $post->getKey());
|
||||
}
|
||||
|
||||
if ($post->isDirty('body') || $post->body_html === null) {
|
||||
$richText = app(RichText::class);
|
||||
$post->body_html = $richText->toSafeHtml($post->body);
|
||||
$post->reading_minutes = $richText->readingMinutes($post->body_html);
|
||||
}
|
||||
});
|
||||
|
||||
// Bildvarianten erzeugen bzw. beim Austausch die alten Dateien entfernen.
|
||||
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
|
||||
{
|
||||
return [
|
||||
'is_featured' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<NewsCategory, $this>
|
||||
*/
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(NewsCategory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User, $this>
|
||||
*/
|
||||
public function author(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Veröffentlicht = Veröffentlichungsdatum gesetzt und erreicht.
|
||||
*
|
||||
* @param Builder<NewsPost> $query
|
||||
*/
|
||||
public function scopePublished(Builder $query): void
|
||||
{
|
||||
$query->whereNotNull('published_at')->where('published_at', '<=', now());
|
||||
}
|
||||
|
||||
public function isPublished(): bool
|
||||
{
|
||||
return $this->published_at !== null && $this->published_at->isPast();
|
||||
}
|
||||
|
||||
public function coverUrl(string $variant = 'large'): ?string
|
||||
{
|
||||
return app(Images::class)->url($this->cover_path, $variant);
|
||||
}
|
||||
|
||||
public static function uniqueSlug(string $title, ?int $ignoreId = null): string
|
||||
{
|
||||
$base = Str::slug($title, language: 'de') ?: 'beitrag';
|
||||
$slug = $base;
|
||||
|
||||
for ($i = 2; static::query()->where('slug', $slug)->when($ignoreId, fn ($q) => $q->whereKeyNot($ignoreId))->exists(); $i++) {
|
||||
$slug = "{$base}-{$i}";
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ class AdminPanelProvider extends PanelProvider
|
|||
->colors(fn () => [
|
||||
'primary' => app(Branding::class)->palette(),
|
||||
])
|
||||
->navigationGroups(['Inhalte', 'Portal'])
|
||||
->navigationItems([
|
||||
NavigationItem::make('Zum Portal')
|
||||
->url('/')
|
||||
|
|
|
|||
|
|
@ -25,12 +25,15 @@ class Avatars
|
|||
|
||||
public function store(User $user, UploadedFile $file): void
|
||||
{
|
||||
Images::raiseMemoryLimitFor($file->getRealPath());
|
||||
$image = ImageManager::usingDriver(Driver::class)->decodePath($file->getRealPath());
|
||||
$base = 'avatars/'.$user->getKey().'/'.Str::random(12);
|
||||
|
||||
foreach (self::SIZES as $size) {
|
||||
$encoded = (clone $image)->cover($size, $size)->encode(new WebpEncoder(quality: 85));
|
||||
Storage::disk('uploads')->put("{$base}-{$size}.webp", $encoded->toString());
|
||||
// Größte Stufe zuerst und danach schrittweise verkleinern – so liegt nur eine
|
||||
// Kopie in voller Auflösung im Speicher (wichtig bei 128 MB memory_limit).
|
||||
foreach (array_reverse(self::SIZES) as $size) {
|
||||
$image->cover($size, $size);
|
||||
Storage::disk('uploads')->put("{$base}-{$size}.webp", $image->encode(new WebpEncoder(quality: 85))->toString());
|
||||
}
|
||||
|
||||
$this->delete($user);
|
||||
|
|
|
|||
86
app/Support/Calendar.php
Normal file
86
app/Support/Calendar.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\Event;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* iCalendar-Export (RFC 5545) für einzelne Termine – zum Übernehmen in Outlook & Co.
|
||||
*/
|
||||
class Calendar
|
||||
{
|
||||
public function toIcs(Event $event, string $organizer): string
|
||||
{
|
||||
$end = $event->ends_at ?? ($event->all_day ? $event->starts_at : $event->starts_at->copy()->addHour());
|
||||
|
||||
$lines = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0',
|
||||
'PRODID:-//'.$this->escape($organizer).'//Inhaus//DE',
|
||||
'CALSCALE:GREGORIAN',
|
||||
'METHOD:PUBLISH',
|
||||
'BEGIN:VEVENT',
|
||||
'UID:event-'.$event->id.'@'.(parse_url(config('app.url'), PHP_URL_HOST) ?: 'inhaus'),
|
||||
'DTSTAMP:'.now()->utc()->format('Ymd\THis\Z'),
|
||||
];
|
||||
|
||||
if ($event->all_day) {
|
||||
$lines[] = 'DTSTART;VALUE=DATE:'.$event->starts_at->format('Ymd');
|
||||
// DTEND ist bei ganztägigen Terminen exklusiv: der Tag nach dem letzten Tag.
|
||||
$lines[] = 'DTEND;VALUE=DATE:'.$end->copy()->startOfDay()->addDay()->format('Ymd');
|
||||
} else {
|
||||
$lines[] = 'DTSTART:'.$event->starts_at->copy()->utc()->format('Ymd\THis\Z');
|
||||
$lines[] = 'DTEND:'.$end->copy()->utc()->format('Ymd\THis\Z');
|
||||
}
|
||||
|
||||
$lines[] = 'SUMMARY:'.$this->escape($event->title);
|
||||
|
||||
if ($event->location) {
|
||||
$lines[] = 'LOCATION:'.$this->escape($event->location);
|
||||
}
|
||||
|
||||
$description = trim(html_entity_decode(strip_tags(str_replace(['</p>', '<br>'], "\n", (string) $event->description_html))));
|
||||
|
||||
if ($description !== '') {
|
||||
$lines[] = 'DESCRIPTION:'.$this->escape(Str::limit($description, 2000));
|
||||
}
|
||||
|
||||
if ($event->online_url) {
|
||||
$lines[] = 'URL:'.$this->escape($event->online_url);
|
||||
}
|
||||
|
||||
$lines[] = 'END:VEVENT';
|
||||
$lines[] = 'END:VCALENDAR';
|
||||
|
||||
return implode("\r\n", array_map($this->fold(...), $lines))."\r\n";
|
||||
}
|
||||
|
||||
private function escape(string $value): string
|
||||
{
|
||||
return str_replace(['\\', ';', ',', "\r\n", "\n"], ['\\\\', '\;', '\\,', '\\n', '\\n'], $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeilen nach 75 Oktetts umbrechen (Folgezeilen beginnen mit einem Leerzeichen,
|
||||
* das mitzählt), ohne UTF-8-Zeichen zu zerschneiden.
|
||||
*/
|
||||
private function fold(string $line): string
|
||||
{
|
||||
$folded = '';
|
||||
$current = '';
|
||||
$limit = 75;
|
||||
|
||||
foreach (mb_str_split($line) as $char) {
|
||||
if (strlen($current.$char) > $limit) {
|
||||
$folded .= $current."\r\n ";
|
||||
$current = '';
|
||||
$limit = 74;
|
||||
}
|
||||
|
||||
$current .= $char;
|
||||
}
|
||||
|
||||
return $folded.$current;
|
||||
}
|
||||
}
|
||||
119
app/Support/Images.php
Normal file
119
app/Support/Images.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Erzeugt aus hochgeladenen Titelbildern feste Größen im 16:9-Format (WebP),
|
||||
* damit Listen und Startseite keine Originalbilder laden müssen.
|
||||
*/
|
||||
class Images
|
||||
{
|
||||
public const VARIANTS = [
|
||||
'thumb' => [480, 270],
|
||||
'large' => [1600, 900],
|
||||
];
|
||||
|
||||
private const VARIANTS_LARGEST_FIRST = ['large', 'thumb'];
|
||||
|
||||
public function createVariants(string $path): void
|
||||
{
|
||||
$disk = Storage::disk('uploads');
|
||||
|
||||
if (! $disk->exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Nur eine Kopie in voller Auflösung im Speicher: erst auf die größte
|
||||
// Variante verkleinern, daraus dann die kleineren ableiten.
|
||||
// Wichtig bei Shared Hosting mit 128 MB memory_limit und Handyfotos.
|
||||
self::raiseMemoryLimitFor($disk->path($path));
|
||||
$image = ImageManager::usingDriver(Driver::class)->decodePath($disk->path($path));
|
||||
|
||||
foreach (self::VARIANTS_LARGEST_FIRST as $variant) {
|
||||
[$width, $height] = self::VARIANTS[$variant];
|
||||
$image->coverDown($width, $height);
|
||||
$disk->put($this->variantPath($path, $variant), $image->encode(new WebpEncoder(quality: 82))->toString());
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteWithVariants(?string $path): void
|
||||
{
|
||||
if (! $path) {
|
||||
return;
|
||||
}
|
||||
|
||||
$disk = Storage::disk('uploads');
|
||||
$disk->delete($path);
|
||||
|
||||
foreach (array_keys(self::VARIANTS) as $variant) {
|
||||
$disk->delete($this->variantPath($path, $variant));
|
||||
}
|
||||
}
|
||||
|
||||
public function url(?string $path, string $variant = 'large'): ?string
|
||||
{
|
||||
if (! $path) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$disk = Storage::disk('uploads');
|
||||
$variantPath = $this->variantPath($path, $variant);
|
||||
|
||||
return $disk->url($disk->exists($variantPath) ? $variantPath : $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* GD hält Bilder unkomprimiert im Speicher (4 Byte je Pixel) – ein Handyfoto
|
||||
* mit 12 Megapixeln braucht so allein ~48 MB. Wie WordPress heben wir das
|
||||
* Limit für die Bildverarbeitung bei Bedarf auf mindestens 256 MB an.
|
||||
*/
|
||||
public static function raiseMemoryLimitFor(string $file): void
|
||||
{
|
||||
$size = @getimagesize($file);
|
||||
$needed = $size ? (int) ($size[0] * $size[1] * 4 * 1.8) : 0;
|
||||
$current = self::bytes((string) ini_get('memory_limit'));
|
||||
|
||||
if ($current === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target = max(256 * 1024 * 1024, memory_get_usage() + $needed);
|
||||
|
||||
if ($current < $target) {
|
||||
@ini_set('memory_limit', (string) $target);
|
||||
}
|
||||
}
|
||||
|
||||
private static function bytes(string $value): int
|
||||
{
|
||||
$value = trim($value);
|
||||
|
||||
if ($value === '' || $value === '-1') {
|
||||
return -1;
|
||||
}
|
||||
|
||||
$number = (int) $value;
|
||||
|
||||
return match (strtolower(substr($value, -1))) {
|
||||
'g' => $number * 1024 ** 3,
|
||||
'm' => $number * 1024 ** 2,
|
||||
'k' => $number * 1024,
|
||||
default => $number,
|
||||
};
|
||||
}
|
||||
|
||||
private function variantPath(string $path, string $variant): string
|
||||
{
|
||||
return preg_replace('/\.[^.\/]+$/', '', $path)."-{$variant}.webp";
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,8 @@ class Navigation
|
|||
{
|
||||
return [
|
||||
['label' => 'Startseite', 'href' => '/', 'active' => $request->routeIs('dashboard')],
|
||||
['label' => 'Neuigkeiten', 'href' => '/neuigkeiten', 'active' => $request->routeIs('news.*')],
|
||||
['label' => 'Termine', 'href' => '/termine', 'active' => $request->routeIs('events.*')],
|
||||
['label' => 'Personen', 'href' => '/personen', 'active' => $request->routeIs('people.*')],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
49
app/Support/RichText.php
Normal file
49
app/Support/RichText.php
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Filament\Forms\Components\RichEditor\RichContentRenderer;
|
||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
|
||||
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
|
||||
|
||||
/**
|
||||
* Wandelt Inhalte aus dem Rich-Text-Editor in sicheres HTML für das Portal.
|
||||
* Wird beim Speichern aufgerufen; das Ergebnis liegt fertig in der Datenbank.
|
||||
*/
|
||||
class RichText
|
||||
{
|
||||
public function toSafeHtml(?string $content): string
|
||||
{
|
||||
if (blank($content)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = RichContentRenderer::make($content)
|
||||
->fileAttachmentsDisk('uploads')
|
||||
->toHtml();
|
||||
|
||||
return $this->sanitizer()->sanitize($html);
|
||||
}
|
||||
|
||||
public function readingMinutes(?string $html): int
|
||||
{
|
||||
$words = str_word_count(strip_tags((string) $html), 0, 'ÄÖÜäöüß');
|
||||
|
||||
return max(1, (int) ceil($words / 200));
|
||||
}
|
||||
|
||||
private function sanitizer(): HtmlSanitizer
|
||||
{
|
||||
$config = (new HtmlSanitizerConfig)
|
||||
->allowSafeElements()
|
||||
->allowLinkSchemes(['https', 'http', 'mailto', 'tel'])
|
||||
->allowRelativeLinks()
|
||||
->allowMediaSchemes(['https', 'http'])
|
||||
->allowRelativeMedias()
|
||||
->forceAttribute('a', 'rel', 'noopener noreferrer')
|
||||
->dropElement('iframe')
|
||||
->withMaxInputLength(500_000);
|
||||
|
||||
return new HtmlSanitizer($config);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue