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

- 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:
Friederich Loheide 2026-09-26 05:16:27 +00:00
parent f813a0fff3
commit a36752e09a
103 changed files with 2810 additions and 124 deletions

View file

@ -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
View 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
View 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";
}
}

View file

@ -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
View 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);
}
}