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:
parent
cc0020458f
commit
28ef1e4a20
155 changed files with 2762 additions and 573 deletions
87
app/Support/Abilities.php
Normal file
87
app/Support/Abilities.php
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
/**
|
||||
* Registry der Rechte (Abilities). Kern und Plugins melden hier an, welche
|
||||
* Rechte es gibt – das Rollen-Formular und der Rechte-Prüfer bauen darauf auf.
|
||||
*
|
||||
* Globale Rechte gelten überall („Benutzer verwalten“). Objekt-Rechte gelten für
|
||||
* einzelne Objekte eines Typs („Beiträge schreiben in Kategorie MAV-Info“).
|
||||
*/
|
||||
class Abilities
|
||||
{
|
||||
/** @var array<string, array{label: string, group: string, resource: string|null}> */
|
||||
private array $abilities = [];
|
||||
|
||||
/** @var array<string, array{label: string, options: callable}> */
|
||||
private array $resourceTypes = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->define('admin.access', 'Administrationsbereich öffnen', 'System');
|
||||
$this->define('users.manage', 'Benutzer verwalten', 'System');
|
||||
$this->define('roles.manage', 'Rollen und Rechte verwalten', 'System');
|
||||
$this->define('plugins.manage', 'Plugins verwalten und installieren', 'System');
|
||||
$this->define('appearance.manage', 'Erscheinungsbild und Schnellzugriffe', 'System');
|
||||
$this->define('updates.manage', 'Aktualisierungen, Lizenz und Systemzustand', 'System');
|
||||
$this->define('feedback.send', 'Rückmeldungen an den Hersteller senden', 'System');
|
||||
}
|
||||
|
||||
public function define(string $ability, string $label, string $group, ?string $resource = null): void
|
||||
{
|
||||
$this->abilities[$ability] = ['label' => $label, 'group' => $group, 'resource' => $resource];
|
||||
}
|
||||
|
||||
/**
|
||||
* Objekttyp, auf den sich Rechte beziehen können (z. B. „news_category“).
|
||||
*
|
||||
* @param callable(): array<int|string, string> $options ID => Bezeichnung
|
||||
*/
|
||||
public function resourceType(string $type, string $label, callable $options): void
|
||||
{
|
||||
$this->resourceTypes[$type] = ['label' => $label, 'options' => $options];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{label: string, group: string, resource: string|null}>
|
||||
*/
|
||||
public function all(): array
|
||||
{
|
||||
return $this->abilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{label: string, group: string, resource: string|null}>
|
||||
*/
|
||||
public function global(): array
|
||||
{
|
||||
return array_filter($this->abilities, fn (array $a) => $a['resource'] === null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{label: string, group: string, resource: string|null}>
|
||||
*/
|
||||
public function forResource(string $type): array
|
||||
{
|
||||
return array_filter($this->abilities, fn (array $a) => $a['resource'] === $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{label: string, options: callable}>
|
||||
*/
|
||||
public function resourceTypes(): array
|
||||
{
|
||||
return $this->resourceTypes;
|
||||
}
|
||||
|
||||
public function exists(string $ability): bool
|
||||
{
|
||||
return isset($this->abilities[$ability]);
|
||||
}
|
||||
|
||||
public function label(string $ability): string
|
||||
{
|
||||
return $this->abilities[$ability]['label'] ?? $ability;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,24 +2,56 @@
|
|||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Hooks;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Hauptnavigation des Portals. Wird ab Phase 2 zu einer Registry, in die
|
||||
* Plugins eigene Einträge eintragen.
|
||||
* Hauptnavigation des Portals als Registry: Kern und Plugins tragen Einträge ein.
|
||||
*
|
||||
* app(Navigation::class)->add('news', 'Neuigkeiten', '/neuigkeiten', active: 'news.*', sort: 20);
|
||||
*/
|
||||
class Navigation
|
||||
{
|
||||
/**
|
||||
* @return list<array{label: string, href: string, active: bool}>
|
||||
*/
|
||||
public function items(Request $request): array
|
||||
/** @var array<string, array{label: string, href: string, active: list<string>, sort: int, ability: string|null}> */
|
||||
private array $items = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
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.*')],
|
||||
];
|
||||
$this->add('home', 'Startseite', '/', active: 'dashboard', sort: 0);
|
||||
$this->add('people', 'Personen', '/personen', active: 'people.*', sort: 90);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|list<string> $active Routennamen (mit *), bei denen der Eintrag aktiv ist
|
||||
*/
|
||||
public function add(string $key, string $label, string $href, string|array $active = [], int $sort = 50, ?string $ability = null): void
|
||||
{
|
||||
$this->items[$key] = ['label' => $label, 'href' => $href, 'active' => (array) $active, 'sort' => $sort, 'ability' => $ability];
|
||||
}
|
||||
|
||||
public function remove(string $key): void
|
||||
{
|
||||
unset($this->items[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{key: string, label: string, href: string, active: bool}>
|
||||
*/
|
||||
public function items(Request $request, ?User $user = null): array
|
||||
{
|
||||
$items = collect($this->items)
|
||||
->filter(fn (array $item) => $item['ability'] === null || ($user?->can($item['ability']) ?? false))
|
||||
->sortBy('sort')
|
||||
->map(fn (array $item, string $key) => [
|
||||
'key' => $key,
|
||||
'label' => $item['label'],
|
||||
'href' => $item['href'],
|
||||
'active' => $item['active'] !== [] && $request->routeIs(...$item['active']),
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return Hooks::apply('navigation.items', $items, $request, $user);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,52 @@ use RecursiveIteratorIterator;
|
|||
|
||||
final class Filesystem
|
||||
{
|
||||
/**
|
||||
* Verzeichnis verschieben – per rename(), bei Dateisystemgrenzen per Kopie.
|
||||
*/
|
||||
public static function moveDirectory(string $from, string $to): bool
|
||||
{
|
||||
if (@rename($from, $to)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! self::copyDirectory($from, $to)) {
|
||||
self::deleteDirectory($to);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
self::deleteDirectory($from);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function copyDirectory(string $from, string $to): bool
|
||||
{
|
||||
if (! is_dir($to) && ! @mkdir($to, 0775, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$items = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($from, FilesystemIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::SELF_FIRST,
|
||||
);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$target = $to.'/'.substr($item->getPathname(), strlen(rtrim($from, '/')) + 1);
|
||||
|
||||
if ($item->isDir()) {
|
||||
if (! is_dir($target) && ! @mkdir($target, 0775, true)) {
|
||||
return false;
|
||||
}
|
||||
} elseif (! @copy($item->getPathname(), $target)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function deleteDirectory(string $dir): void
|
||||
{
|
||||
if (! is_dir($dir)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue