Group icons: groups get an icon in front of their name, like the role icons in Discord
In Berechtigungsgruppen -> Gruppe bearbeiten the new field "Symbol" takes an uploaded image or a link to one, with a checkbox to remove it and a live preview in the tag. - A link is downloaded once when saving (includes/role_icons.php): public http(s) addresses only, nothing in the local network (redirects checked one by one, the checked IP is pinned), at most 2 MB, PNG/JPG/GIF/WEBP. Like uploads the image is re-encoded, scaled to 128 px and stored under assets/uploads/roles/ (with .htaccess), so visitors never load anything from other servers and expiring links (Discord attachments) don't break the icon. - Shown in the group tags (member list, profile, group admin), the group filter chips and the rank section headings of the member list, and the group badges on the dashboard. - Replaced or removed icons and the icon of a deleted group are deleted from disk; the new file is only stored once all other fields are valid and removed again if saving fails. - New column roles.tag_icon (schema version 55, also in sql/schema.sql); README. - file-input.js: "Entfernen" fires a change event, so previews of other scripts clear too. - Live updates of the member list also react to changes of tag_bg2 and tag_icon. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
944935075a
commit
3fa3a7310d
17 changed files with 373 additions and 35 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -17,6 +17,9 @@ assets/uploads/gear/*
|
||||||
assets/uploads/skills/*
|
assets/uploads/skills/*
|
||||||
!assets/uploads/skills/.htaccess
|
!assets/uploads/skills/.htaccess
|
||||||
!assets/uploads/skills/.gitkeep
|
!assets/uploads/skills/.gitkeep
|
||||||
|
assets/uploads/roles/*
|
||||||
|
!assets/uploads/roles/.htaccess
|
||||||
|
!assets/uploads/roles/.gitkeep
|
||||||
# Kacheln, Marker und Icons der Karte (~230 MB) - werden per FTP hochgeladen, siehe README
|
# Kacheln, Marker und Icons der Karte (~230 MB) - werden per FTP hochgeladen, siehe README
|
||||||
assets/map/data/
|
assets/map/data/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
|
||||||
|
|
@ -916,6 +916,14 @@ eine eigene Hintergrund- und Textfarbe wählen, dazu wie bei Discord ein Verlauf
|
||||||
läuft von links nach rechts in eine zweite Farbe über (mit Vorschau; Spalten `roles.tag_bg`,
|
läuft von links nach rechts in eine zweite Farbe über (mit Vorschau; Spalten `roles.tag_bg`,
|
||||||
`roles.tag_bg2`, `roles.tag_color`). Ohne Farbe bleibt das Standard-Tag.
|
`roles.tag_bg2`, `roles.tag_color`). Ohne Farbe bleibt das Standard-Tag.
|
||||||
|
|
||||||
|
Dazu kann jede Gruppe ein Symbol bekommen, das wie die Rollen-Symbole bei Discord vor ihrem Namen
|
||||||
|
steht: im Tag, in der Überschrift ihres Abschnitts und im Gruppenfilter der Mitgliederliste sowie im
|
||||||
|
Dashboard. Es wird hochgeladen oder als Link angegeben. Einen Link lädt die Website beim Speichern
|
||||||
|
einmal herunter (nur öffentliche http(s)-Adressen, keine im eigenen Netz, höchstens 2 MB), Besucher
|
||||||
|
laden also nie etwas von fremden Servern. Das Bild wird wie ein Upload neu gerechnet, auf 128 px
|
||||||
|
verkleinert und unter `assets/uploads/roles/` abgelegt (Spalte `roles.tag_icon`). Der Ordner muss
|
||||||
|
für den Webserver beschreibbar sein, seine `.htaccess` verhindert, dass dort etwas als PHP läuft.
|
||||||
|
|
||||||
Falls die Datenbank schon vor diesem Update existierte, fehlt die Spalte `roster_order`:
|
Falls die Datenbank schon vor diesem Update existierte, fehlt die Spalte `roster_order`:
|
||||||
```sql
|
```sql
|
||||||
ALTER TABLE roles ADD COLUMN roster_order INT NULL DEFAULT NULL AFTER is_system;
|
ALTER TABLE roles ADD COLUMN roster_order INT NULL DEFAULT NULL AFTER is_system;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/bootstrap.php';
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
||||||
|
require_once __DIR__ . '/../includes/role_icons.php';
|
||||||
require_permission('roles.manage');
|
require_permission('roles.manage');
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
|
@ -11,7 +12,7 @@ verify_csrf();
|
||||||
$id = (int) ($_POST['id'] ?? 0);
|
$id = (int) ($_POST['id'] ?? 0);
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
|
|
||||||
$stmt = $pdo->prepare('SELECT is_system FROM roles WHERE id = ?');
|
$stmt = $pdo->prepare('SELECT is_system, tag_icon FROM roles WHERE id = ?');
|
||||||
$stmt->execute([$id]);
|
$stmt->execute([$id]);
|
||||||
$role = $stmt->fetch();
|
$role = $stmt->fetch();
|
||||||
|
|
||||||
|
|
@ -29,6 +30,7 @@ if (!$role) {
|
||||||
$nameStmt->execute([$id]);
|
$nameStmt->execute([$id]);
|
||||||
$roleName = (string) $nameStmt->fetchColumn();
|
$roleName = (string) $nameStmt->fetchColumn();
|
||||||
$pdo->prepare('DELETE FROM roles WHERE id = ?')->execute([$id]);
|
$pdo->prepare('DELETE FROM roles WHERE id = ?')->execute([$id]);
|
||||||
|
role_icon_delete($role['tag_icon']);
|
||||||
admin_log('🗑️ Berechtigungsgruppe gelöscht', ['Gruppe' => $roleName], 'danger');
|
admin_log('🗑️ Berechtigungsgruppe gelöscht', ['Gruppe' => $roleName], 'danger');
|
||||||
sync_role_assign_permissions(); // Vergabe-Recht der Gruppe entfernen
|
sync_role_assign_permissions(); // Vergabe-Recht der Gruppe entfernen
|
||||||
set_flash('success', 'Berechtigungsgruppe wurde gelöscht.');
|
set_flash('success', 'Berechtigungsgruppe wurde gelöscht.');
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require_once __DIR__ . '/../includes/bootstrap.php';
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
||||||
require_once __DIR__ . '/../includes/events_api.php';
|
require_once __DIR__ . '/../includes/events_api.php';
|
||||||
|
require_once __DIR__ . '/../includes/role_icons.php';
|
||||||
require_permission('roles.manage');
|
require_permission('roles.manage');
|
||||||
|
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
|
|
@ -9,11 +10,11 @@ $editId = isset($_GET['id']) ? (int) $_GET['id'] : null;
|
||||||
$isEdit = $editId !== null;
|
$isEdit = $editId !== null;
|
||||||
|
|
||||||
$role = ['id' => null, 'name' => '', 'display_name' => '', 'description' => '', 'is_system' => 0, 'roster_order' => null, 'discord_role_id' => null,
|
$role = ['id' => null, 'name' => '', 'display_name' => '', 'description' => '', 'is_system' => 0, 'roster_order' => null, 'discord_role_id' => null,
|
||||||
'tag_bg' => null, 'tag_bg2' => null, 'tag_color' => null];
|
'tag_bg' => null, 'tag_bg2' => null, 'tag_color' => null, 'tag_icon' => null];
|
||||||
$selectedPermissionIds = [];
|
$selectedPermissionIds = [];
|
||||||
|
|
||||||
if ($isEdit) {
|
if ($isEdit) {
|
||||||
$stmt = $pdo->prepare('SELECT id, name, display_name, description, is_system, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color FROM roles WHERE id = ?');
|
$stmt = $pdo->prepare('SELECT id, name, display_name, description, is_system, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color, tag_icon FROM roles WHERE id = ?');
|
||||||
$stmt->execute([$editId]);
|
$stmt->execute([$editId]);
|
||||||
$found = $stmt->fetch();
|
$found = $stmt->fetch();
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
|
|
@ -28,6 +29,9 @@ if ($isEdit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = null;
|
$error = null;
|
||||||
|
// Symbol-Felder: bleiben nach einem Fehler stehen (eine gewaehlte Datei kann der Browser nicht behalten)
|
||||||
|
$iconUrl = '';
|
||||||
|
$iconRemove = false;
|
||||||
|
|
||||||
/** Tag-Farben fuers Log: "#aa0000 / #ffffff" oder "Verlauf #aa0000–#0000aa / Standard". */
|
/** Tag-Farben fuers Log: "#aa0000 / #ffffff" oder "Verlauf #aa0000–#0000aa / Standard". */
|
||||||
$tagColorsText = static fn (?string $bg, ?string $bg2, ?string $text): string =>
|
$tagColorsText = static fn (?string $bg, ?string $bg2, ?string $text): string =>
|
||||||
|
|
@ -71,6 +75,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
// Verlauf nur zusammen mit dem Hintergrund (von dessen Farbe zur zweiten)
|
// Verlauf nur zusammen mit dem Hintergrund (von dessen Farbe zur zweiten)
|
||||||
$tagBg2 = $tagBg !== null && !empty($_POST['tag_bg2_on']) ? role_tag_color_input((string) ($_POST['tag_bg2'] ?? '')) : null;
|
$tagBg2 = $tagBg !== null && !empty($_POST['tag_bg2_on']) ? role_tag_color_input((string) ($_POST['tag_bg2'] ?? '')) : null;
|
||||||
$tagColor = !empty($_POST['tag_color_on']) ? role_tag_color_input((string) ($_POST['tag_color'] ?? '')) : null;
|
$tagColor = !empty($_POST['tag_color_on']) ? role_tag_color_input((string) ($_POST['tag_color'] ?? '')) : null;
|
||||||
|
// Symbol: neu hochgeladen oder per Link, sonst bleibt das bisherige - ausser es soll weg
|
||||||
|
$iconFile = is_array($_FILES['icon_file'] ?? null) && ($_FILES['icon_file']['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_NO_FILE
|
||||||
|
? $_FILES['icon_file'] : null;
|
||||||
|
$iconUrl = trim((string) ($_POST['icon_url'] ?? ''));
|
||||||
|
$iconRemove = !empty($_POST['icon_remove']);
|
||||||
|
$oldIcon = $isEdit ? ($role['tag_icon'] ?? null) : null;
|
||||||
|
$newIcon = null;
|
||||||
|
|
||||||
if ($name === '') {
|
if ($name === '') {
|
||||||
$error = 'Bitte einen Namen für die Gruppe angeben.';
|
$error = 'Bitte einen Namen für die Gruppe angeben.';
|
||||||
|
|
@ -80,17 +91,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$error = 'Die Reihenfolge muss eine ganze Zahl sein (z.B. 1).';
|
$error = 'Die Reihenfolge muss eine ganze Zahl sein (z.B. 1).';
|
||||||
} elseif ($discordRoleId !== null && !preg_match('/^[0-9]{5,19}$/', $discordRoleId)) {
|
} elseif ($discordRoleId !== null && !preg_match('/^[0-9]{5,19}$/', $discordRoleId)) {
|
||||||
$error = 'Die Discord-Rollen-ID besteht nur aus Ziffern (Rechtsklick auf die Rolle in Discord → "Rollen-ID kopieren").';
|
$error = 'Die Discord-Rollen-ID besteht nur aus Ziffern (Rechtsklick auf die Rolle in Discord → "Rollen-ID kopieren").';
|
||||||
|
} elseif (mb_strlen($iconUrl) > 1000) {
|
||||||
|
$error = 'Der Link zum Symbol ist zu lang (höchstens 1000 Zeichen).';
|
||||||
} else {
|
} else {
|
||||||
|
// Das neue Symbol erst speichern, wenn alles andere passt - sonst bliebe eine Datei ohne Gruppe liegen
|
||||||
|
try {
|
||||||
|
if ($iconFile !== null) {
|
||||||
|
$newIcon = role_icon_store_upload($iconFile);
|
||||||
|
} elseif ($iconUrl !== '') {
|
||||||
|
$newIcon = role_icon_store_from_url($iconUrl);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException $e) {
|
||||||
|
$error = $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error === null) {
|
||||||
|
$tagIcon = $newIcon ?? ($iconRemove ? null : $oldIcon);
|
||||||
try {
|
try {
|
||||||
$pdo->beginTransaction();
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
if ($isEdit) {
|
if ($isEdit) {
|
||||||
$pdo->prepare('UPDATE roles SET name = ?, display_name = ?, description = ?, roster_order = ?, discord_role_id = ?, tag_bg = ?, tag_bg2 = ?, tag_color = ? WHERE id = ?')
|
$pdo->prepare('UPDATE roles SET name = ?, display_name = ?, description = ?, roster_order = ?, discord_role_id = ?, tag_bg = ?, tag_bg2 = ?, tag_color = ?, tag_icon = ? WHERE id = ?')
|
||||||
->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor, $editId]);
|
->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor, $tagIcon, $editId]);
|
||||||
$roleId = $editId;
|
$roleId = $editId;
|
||||||
} else {
|
} else {
|
||||||
$pdo->prepare('INSERT INTO roles (name, display_name, description, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')
|
$pdo->prepare('INSERT INTO roles (name, display_name, description, roster_order, discord_role_id, tag_bg, tag_bg2, tag_color, tag_icon) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)')
|
||||||
->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor]);
|
->execute([$name, $displayName, $description, $rosterOrder, $discordRoleId, $tagBg, $tagBg2, $tagColor, $tagIcon]);
|
||||||
$roleId = (int) $pdo->lastInsertId();
|
$roleId = (int) $pdo->lastInsertId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,6 +136,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
}
|
}
|
||||||
|
|
||||||
$pdo->commit();
|
$pdo->commit();
|
||||||
|
// Ersetztes oder entferntes Symbol: die alte Datei braucht niemand mehr
|
||||||
|
if ($oldIcon !== null && $oldIcon !== $tagIcon) {
|
||||||
|
role_icon_delete($oldIcon);
|
||||||
|
}
|
||||||
sync_role_assign_permissions(); // neue Gruppe bzw. neuer Name
|
sync_role_assign_permissions(); // neue Gruppe bzw. neuer Name
|
||||||
|
|
||||||
// Discord-Log: welche Berechtigungen dazu- bzw. weggekommen sind.
|
// Discord-Log: welche Berechtigungen dazu- bzw. weggekommen sind.
|
||||||
|
|
@ -130,6 +161,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$tagColorsText($isEdit ? $role['tag_bg'] : null, $isEdit ? $role['tag_bg2'] : null, $isEdit ? $role['tag_color'] : null),
|
$tagColorsText($isEdit ? $role['tag_bg'] : null, $isEdit ? $role['tag_bg2'] : null, $isEdit ? $role['tag_color'] : null),
|
||||||
$tagColorsText($tagBg, $tagBg2, $tagColor)
|
$tagColorsText($tagBg, $tagBg2, $tagColor)
|
||||||
),
|
),
|
||||||
|
'Symbol' => $newIcon !== null ? ($iconFile !== null ? 'hochgeladen' : 'von ' . $iconUrl)
|
||||||
|
: ($oldIcon !== null && $tagIcon === null ? 'entfernt' : ''),
|
||||||
'Berechtigungen hinzugefügt' => $permList(array_diff($submittedPermissionIds, $selectedPermissionIds)),
|
'Berechtigungen hinzugefügt' => $permList(array_diff($submittedPermissionIds, $selectedPermissionIds)),
|
||||||
'Berechtigungen entfernt' => $permList(array_diff($selectedPermissionIds, $submittedPermissionIds)),
|
'Berechtigungen entfernt' => $permList(array_diff($selectedPermissionIds, $submittedPermissionIds)),
|
||||||
], $isEdit ? 'info' : 'success');
|
], $isEdit ? 'info' : 'success');
|
||||||
|
|
@ -137,6 +170,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
redirect('/admin/roles.php');
|
redirect('/admin/roles.php');
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$pdo->rollBack();
|
$pdo->rollBack();
|
||||||
|
role_icon_delete($newIcon); // nicht gespeichert - das neue Symbol gehoert zu keiner Gruppe
|
||||||
$error = 'Eine Gruppe mit diesem Namen existiert bereits.';
|
$error = 'Eine Gruppe mit diesem Namen existiert bereits.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -189,7 +223,7 @@ include __DIR__ . '/../includes/header.php';
|
||||||
<?php if ($error): ?>
|
<?php if ($error): ?>
|
||||||
<div class="flash flash-error"><?= e($error) ?></div>
|
<div class="flash flash-error"><?= e($error) ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<form method="post" action="/admin/role_form.php<?= $isEdit ? '?id=' . (int) $editId : '' ?>">
|
<form method="post" action="/admin/role_form.php<?= $isEdit ? '?id=' . (int) $editId : '' ?>" enctype="multipart/form-data">
|
||||||
<?= csrf_field() ?>
|
<?= csrf_field() ?>
|
||||||
<div>
|
<div>
|
||||||
<label for="name">Name (interner Identifizierer)</label>
|
<label for="name">Name (interner Identifizierer)</label>
|
||||||
|
|
@ -201,6 +235,17 @@ include __DIR__ . '/../includes/header.php';
|
||||||
<input type="text" id="display_name" name="display_name" maxlength="100" value="<?= e($role['display_name']) ?>" placeholder="z.B. Legionsleitung">
|
<input type="text" id="display_name" name="display_name" maxlength="100" value="<?= e($role['display_name']) ?>" placeholder="z.B. Legionsleitung">
|
||||||
<div class="field-hint">Wird überall angezeigt, wo diese Gruppe im Mitgliederbereich auftaucht (Dashboard, Mitgliederliste, ...). Ohne Angabe wird stattdessen der Name oben verwendet.</div>
|
<div class="field-hint">Wird überall angezeigt, wo diese Gruppe im Mitgliederbereich auftaucht (Dashboard, Mitgliederliste, ...). Ohne Angabe wird stattdessen der Name oben verwendet.</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="icon_file">Symbol (optional)</label>
|
||||||
|
<div class="role-icon-field">
|
||||||
|
<input type="file" id="icon_file" name="icon_file" accept="image/png,image/jpeg,image/gif,image/webp">
|
||||||
|
<input type="url" id="icon_url" name="icon_url" maxlength="1000" value="<?= e($iconUrl) ?>" placeholder="oder Link zum Bild, z.B. https://…/symbol.png" aria-label="Link zum Bild">
|
||||||
|
<?php if (!empty($role['tag_icon'])): ?>
|
||||||
|
<label class="role-icon-remove"><input type="checkbox" name="icon_remove" value="1"<?= $iconRemove ? ' checked' : '' ?>> <?= role_icon_html(role_icon_url($role['tag_icon'])) ?>Symbol entfernen</label>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<div class="field-hint">Steht vor dem Namen der Gruppe, wie die Rollen-Symbole bei Discord (Vorschau unten bei den Farben). PNG, JPG, GIF oder WEBP, am besten quadratisch, höchstens 2 MB. Einen Link lädt die Website beim Speichern einmal herunter und speichert das Bild selbst – der Link muss danach nicht mehr funktionieren.</div>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="description">Beschreibung</label>
|
<label for="description">Beschreibung</label>
|
||||||
<input type="text" id="description" name="description" maxlength="255" value="<?= e($role['description']) ?>">
|
<input type="text" id="description" name="description" maxlength="255" value="<?= e($role['description']) ?>">
|
||||||
|
|
@ -224,7 +269,7 @@ include __DIR__ . '/../includes/header.php';
|
||||||
<input type="color" name="tag_color" value="<?= e($role['tag_color'] ?: '#ffffff') ?>" aria-label="Textfarbe des Tags">
|
<input type="color" name="tag_color" value="<?= e($role['tag_color'] ?: '#ffffff') ?>" aria-label="Textfarbe des Tags">
|
||||||
</label>
|
</label>
|
||||||
<span class="role-tag-preview">
|
<span class="role-tag-preview">
|
||||||
Vorschau: <?= role_tag_html($role['display_name'] !== '' ? $role['display_name'] : ($role['name'] !== '' ? $role['name'] : 'Gruppe'), role_tag_css($role['tag_bg'], $role['tag_color'], $role['tag_bg2'])) ?>
|
Vorschau: <?= role_tag_html($role['display_name'] !== '' ? $role['display_name'] : ($role['name'] !== '' ? $role['name'] : 'Gruppe'), role_tag_css($role['tag_bg'], $role['tag_color'], $role['tag_bg2']), '', role_icon_url($role['tag_icon'])) ?>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="field-hint">So erscheint die Gruppe als Tag in der Mitgliederliste und auf den Profilseiten. Ohne Haken gilt die Standardfarbe. Mit „Verlauf zu“ läuft der Hintergrund von links nach rechts in die zweite Farbe über (wie bei Discord).</div>
|
<div class="field-hint">So erscheint die Gruppe als Tag in der Mitgliederliste und auf den Profilseiten. Ohne Haken gilt die Standardfarbe. Mit „Verlauf zu“ läuft der Hintergrund von links nach rechts in die zweite Farbe über (wie bei Discord).</div>
|
||||||
|
|
@ -299,12 +344,18 @@ include __DIR__ . '/../includes/header.php';
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Vorschau des Tags: Farben mit Haken, Name aus Anzeigename bzw. Name. Eine Farbe waehlen setzt ihren Haken.
|
// Vorschau des Tags: Farben mit Haken, Name aus Anzeigename bzw. Name. Eine Farbe waehlen setzt ihren Haken.
|
||||||
|
// Das Symbol: ein gewaehltes Bild gleich, "entfernen" blendet es aus - ein Link erscheint erst nach dem Speichern.
|
||||||
(function () {
|
(function () {
|
||||||
var box = document.getElementById('role-tag-colors');
|
var box = document.getElementById('role-tag-colors');
|
||||||
if (!box) return;
|
if (!box) return;
|
||||||
var tag = box.querySelector('.member-role');
|
var tag = box.querySelector('.member-role');
|
||||||
var nameField = document.getElementById('name');
|
var nameField = document.getElementById('name');
|
||||||
var displayField = document.getElementById('display_name');
|
var displayField = document.getElementById('display_name');
|
||||||
|
var iconFile = document.getElementById('icon_file');
|
||||||
|
var iconRemove = document.querySelector('input[name="icon_remove"]');
|
||||||
|
var icon = tag.querySelector('.role-icon');
|
||||||
|
var savedIcon = icon ? icon.getAttribute('src') : '';
|
||||||
|
var chosenIcon = '';
|
||||||
function field(name) { return box.querySelector('input[name="' + name + '"]'); }
|
function field(name) { return box.querySelector('input[name="' + name + '"]'); }
|
||||||
function update() {
|
function update() {
|
||||||
var bgOn = field('tag_bg_on').checked;
|
var bgOn = field('tag_bg_on').checked;
|
||||||
|
|
@ -321,7 +372,23 @@ include __DIR__ . '/../includes/header.php';
|
||||||
}
|
}
|
||||||
if (textOn) tag.style.setProperty('--tag-color', field('tag_color').value); else tag.style.removeProperty('--tag-color');
|
if (textOn) tag.style.setProperty('--tag-color', field('tag_color').value); else tag.style.removeProperty('--tag-color');
|
||||||
tag.textContent = (displayField.value.trim() || nameField.value.trim() || 'Gruppe');
|
tag.textContent = (displayField.value.trim() || nameField.value.trim() || 'Gruppe');
|
||||||
|
var src = chosenIcon || (iconRemove && iconRemove.checked ? '' : savedIcon);
|
||||||
|
if (src) {
|
||||||
|
if (!icon) {
|
||||||
|
icon = document.createElement('img');
|
||||||
|
icon.className = 'role-icon';
|
||||||
|
icon.alt = '';
|
||||||
}
|
}
|
||||||
|
icon.src = src;
|
||||||
|
tag.prepend(icon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iconFile) iconFile.addEventListener('change', function () {
|
||||||
|
if (chosenIcon) URL.revokeObjectURL(chosenIcon);
|
||||||
|
chosenIcon = iconFile.files && iconFile.files[0] ? URL.createObjectURL(iconFile.files[0]) : '';
|
||||||
|
update();
|
||||||
|
});
|
||||||
|
if (iconRemove) iconRemove.addEventListener('change', update);
|
||||||
box.querySelectorAll('input[type="color"]').forEach(function (input) {
|
box.querySelectorAll('input[type="color"]').forEach(function (input) {
|
||||||
input.addEventListener('input', function () {
|
input.addEventListener('input', function () {
|
||||||
field(input.name + '_on').checked = true;
|
field(input.name + '_on').checked = true;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ require_once __DIR__ . '/../includes/events_api.php';
|
||||||
require_permission('roles.manage');
|
require_permission('roles.manage');
|
||||||
|
|
||||||
$roles = db()->query(
|
$roles = db()->query(
|
||||||
'SELECT r.id, r.name, r.display_name, r.description, r.is_system, r.roster_order, r.discord_role_id, r.tag_bg, r.tag_bg2, r.tag_color,
|
'SELECT r.id, r.name, r.display_name, r.description, r.is_system, r.roster_order, r.discord_role_id, r.tag_bg, r.tag_bg2, r.tag_color, r.tag_icon,
|
||||||
COUNT(DISTINCT ur.user_id) AS user_count,
|
COUNT(DISTINCT ur.user_id) AS user_count,
|
||||||
COUNT(DISTINCT rp.permission_id) AS permission_count
|
COUNT(DISTINCT rp.permission_id) AS permission_count
|
||||||
FROM roles r
|
FROM roles r
|
||||||
|
|
@ -62,7 +62,7 @@ include __DIR__ . '/../includes/header.php';
|
||||||
<?php foreach ($roles as $r): ?>
|
<?php foreach ($roles as $r): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= e($r['name']) ?> <?php if ($r['is_system']): ?><span class="badge">System</span><?php endif; ?></td>
|
<td><?= e($r['name']) ?> <?php if ($r['is_system']): ?><span class="badge">System</span><?php endif; ?></td>
|
||||||
<td><?= role_tag_html($r['display_name'] !== '' ? $r['display_name'] : $r['name'], role_tag_css($r['tag_bg'], $r['tag_color'], $r['tag_bg2'])) ?></td>
|
<td><?= role_tag_html($r['display_name'] !== '' ? $r['display_name'] : $r['name'], role_tag_css($r['tag_bg'], $r['tag_color'], $r['tag_bg2']), '', role_icon_url($r['tag_icon'])) ?></td>
|
||||||
<td><?= e($r['description']) ?></td>
|
<td><?= e($r['description']) ?></td>
|
||||||
<td>
|
<td>
|
||||||
<?php if ($r['discord_role_id'] !== null): ?>
|
<?php if ($r['discord_role_id'] !== null): ?>
|
||||||
|
|
|
||||||
|
|
@ -4603,6 +4603,20 @@ body.home-page .navbar {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Symbol einer Gruppe vor ihrem Namen (Tags, Abschnitte und Filter der Mitgliederliste, Dashboard) -
|
||||||
|
wie die Rollen-Symbole bei Discord */
|
||||||
|
.role-icon {
|
||||||
|
height: 1.3em;
|
||||||
|
width: auto;
|
||||||
|
max-width: 2.6em;
|
||||||
|
object-fit: contain;
|
||||||
|
margin-right: 0.35em;
|
||||||
|
vertical-align: -0.3em;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
.member-role:has(.role-icon) { padding-left: 0.3rem; }
|
||||||
|
.members-chip .role-icon { margin-right: 0; }
|
||||||
|
|
||||||
/* Mitgliederliste nach Rang: die Gruppen mit Reihenfolge sind die Abschnitte - ihre Tags entfallen dort */
|
/* Mitgliederliste nach Rang: die Gruppen mit Reihenfolge sind die Abschnitte - ihre Tags entfallen dort */
|
||||||
#members-list.is-sectioned .member-role-rank { display: none; }
|
#members-list.is-sectioned .member-role-rank { display: none; }
|
||||||
#members-list.is-sectioned .member-roles:not(:has(.member-role:not(.member-role-rank))) { display: none; }
|
#members-list.is-sectioned .member-roles:not(:has(.member-role:not(.member-role-rank))) { display: none; }
|
||||||
|
|
@ -4615,6 +4629,12 @@ body.home-page .navbar {
|
||||||
.role-tag-color:has(input[type="checkbox"]:not(:checked)) input[type="color"] { opacity: 0.45; }
|
.role-tag-color:has(input[type="checkbox"]:not(:checked)) input[type="color"] { opacity: 0.45; }
|
||||||
.role-tag-preview { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--text-muted); font-size: 0.85rem; }
|
.role-tag-preview { display: inline-flex; align-items: center; gap: 0.45rem; color: var(--text-muted); font-size: 0.85rem; }
|
||||||
|
|
||||||
|
/* Berechtigungsgruppe bearbeiten: Symbol hochladen oder per Link */
|
||||||
|
.role-icon-field { display: grid; gap: 0.6rem; margin-top: 0.3rem; }
|
||||||
|
.role-icon-field .file-drop { margin-top: 0; }
|
||||||
|
.role-icon-remove { display: inline-flex; align-items: center; gap: 0.45rem; margin: 0; font-weight: 400; cursor: pointer; }
|
||||||
|
.role-icon-remove input { width: auto; margin: 0; accent-color: var(--gold); }
|
||||||
|
|
||||||
/* Profil: Klassen laut Discord-Klassenrollen, Main-Klasse per Auswahl (profile.php) */
|
/* Profil: Klassen laut Discord-Klassenrollen, Main-Klasse per Auswahl (profile.php) */
|
||||||
.profile-classes { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
|
.profile-classes { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
|
||||||
.profile-class {
|
.profile-class {
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,9 @@
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
input.value = '';
|
input.value = '';
|
||||||
trimmed = 0;
|
trimmed = 0;
|
||||||
render();
|
// Wie eine neue Auswahl melden (zeichnet die Flaeche neu) - so raeumen auch Vorschauen
|
||||||
|
// anderer Skripte mit auf, z.B. das Symbol einer Berechtigungsgruppe
|
||||||
|
input.dispatchEvent(new Event('change', { bubbles: true }));
|
||||||
});
|
});
|
||||||
list.appendChild(clear);
|
list.appendChild(clear);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
var cards = Array.prototype.slice.call(list.querySelectorAll('.member-card'));
|
var cards = Array.prototype.slice.call(list.querySelectorAll('.member-card'));
|
||||||
var sections = JSON.parse(list.dataset.sections || '[]');
|
var sections = JSON.parse(list.dataset.sections || '[]');
|
||||||
|
var sectionIcons = JSON.parse(list.dataset.sectionIcons || '[]');
|
||||||
var search = document.getElementById('members-search');
|
var search = document.getElementById('members-search');
|
||||||
var empty = document.getElementById('members-empty');
|
var empty = document.getElementById('members-empty');
|
||||||
var count = document.getElementById('members-count');
|
var count = document.getElementById('members-count');
|
||||||
|
|
@ -78,7 +79,7 @@
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
function section(title, items) {
|
function section(title, items, icon) {
|
||||||
var panel = document.createElement('div');
|
var panel = document.createElement('div');
|
||||||
// Gruppe mit nur einer Person (z.B. die Leitung): Karte mittig statt links in der ersten Spalte
|
// Gruppe mit nur einer Person (z.B. die Leitung): Karte mittig statt links in der ersten Spalte
|
||||||
panel.className = 'panel' + (items.length === 1 ? ' member-section-single' : '');
|
panel.className = 'panel' + (items.length === 1 ? ' member-section-single' : '');
|
||||||
|
|
@ -86,6 +87,14 @@
|
||||||
head.className = 'raid-header';
|
head.className = 'raid-header';
|
||||||
var h2 = document.createElement('h2');
|
var h2 = document.createElement('h2');
|
||||||
h2.textContent = title;
|
h2.textContent = title;
|
||||||
|
// Symbol der Gruppe vor dem Namen, wie in ihrem Tag
|
||||||
|
if (icon) {
|
||||||
|
var img = document.createElement('img');
|
||||||
|
img.className = 'role-icon';
|
||||||
|
img.src = icon;
|
||||||
|
img.alt = '';
|
||||||
|
h2.prepend(img);
|
||||||
|
}
|
||||||
var badge = document.createElement('span');
|
var badge = document.createElement('span');
|
||||||
badge.className = 'badge';
|
badge.className = 'badge';
|
||||||
badge.textContent = items.length;
|
badge.textContent = items.length;
|
||||||
|
|
@ -119,7 +128,7 @@
|
||||||
if (state.sort === 'rank') {
|
if (state.sort === 'rank') {
|
||||||
sections.forEach(function (title, index) {
|
sections.forEach(function (title, index) {
|
||||||
var items = visible.filter(function (c) { return Number(c.dataset.rank) === index; });
|
var items = visible.filter(function (c) { return Number(c.dataset.rank) === index; });
|
||||||
if (items.length) list.appendChild(section(title, items));
|
if (items.length) list.appendChild(section(title, items, sectionIcons[index]));
|
||||||
});
|
});
|
||||||
} else if (visible.length) {
|
} else if (visible.length) {
|
||||||
var panel = document.createElement('div');
|
var panel = document.createElement('div');
|
||||||
|
|
|
||||||
0
assets/uploads/roles/.gitkeep
Normal file
0
assets/uploads/roles/.gitkeep
Normal file
17
assets/uploads/roles/.htaccess
Normal file
17
assets/uploads/roles/.htaccess
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Symbole der Berechtigungsgruppen (hochgeladen oder per Link geladen) duerfen niemals als Skript
|
||||||
|
# ausgefuehrt werden - auch wenn eine Datei die Typpruefung in includes/role_icons.php umgehen sollte.
|
||||||
|
<IfModule mod_php.c>
|
||||||
|
php_flag engine off
|
||||||
|
</IfModule>
|
||||||
|
<IfModule mod_php7.c>
|
||||||
|
php_flag engine off
|
||||||
|
</IfModule>
|
||||||
|
|
||||||
|
<FilesMatch "\.(php|phtml|php[0-9]?|phar|cgi|pl)$">
|
||||||
|
<IfModule mod_authz_core.c>
|
||||||
|
Require all denied
|
||||||
|
</IfModule>
|
||||||
|
<IfModule !mod_authz_core.c>
|
||||||
|
Deny from all
|
||||||
|
</IfModule>
|
||||||
|
</FilesMatch>
|
||||||
|
|
@ -146,7 +146,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
<p class="text-muted">Hier ist dein Überblick über die Legion.</p>
|
<p class="text-muted">Hier ist dein Überblick über die Legion.</p>
|
||||||
<div class="badge-group">
|
<div class="badge-group">
|
||||||
<?php foreach ($roleNames as $roleName): ?>
|
<?php foreach ($roleNames as $roleName): ?>
|
||||||
<span class="badge"><?= e($roleName) ?></span>
|
<span class="badge"><?= role_icon_html(role_icon_for($roleName)) ?><?= e($roleName) ?></span>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ($discordId): ?>
|
<?php if ($discordId): ?>
|
||||||
<span class="badge badge-active">Discord verbunden</span>
|
<span class="badge badge-active">Discord verbunden</span>
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,7 @@ function live_fingerprint_parts(string $path, array $params, int $userId): ?arra
|
||||||
$sum("SELECT COUNT(*), " . $crc('id, username, display_name, avatar_filename, class_name, classes, main_class, discord_joined_at') . " FROM users WHERE status = 'active'"),
|
$sum("SELECT COUNT(*), " . $crc('id, username, display_name, avatar_filename, class_name, classes, main_class, discord_joined_at') . " FROM users WHERE status = 'active'"),
|
||||||
$sum('SELECT COUNT(*), ' . $crc('user_id, role_id') . ' FROM user_roles'),
|
$sum('SELECT COUNT(*), ' . $crc('user_id, role_id') . ' FROM user_roles'),
|
||||||
$sum('SELECT COUNT(*), ' . $crc('id, user_id, name, class_name, level, is_main') . ' FROM member_characters'),
|
$sum('SELECT COUNT(*), ' . $crc('id, user_id, name, class_name, level, is_main') . ' FROM member_characters'),
|
||||||
$sum('SELECT ' . $crc('id, name, display_name, roster_order, tag_bg, tag_color') . ' FROM roles'),
|
$sum('SELECT ' . $crc('id, name, display_name, roster_order, tag_bg, tag_bg2, tag_color, tag_icon') . ' FROM roles'),
|
||||||
];
|
];
|
||||||
|
|
||||||
case '/calendar.php':
|
case '/calendar.php':
|
||||||
|
|
|
||||||
|
|
@ -290,36 +290,65 @@ function role_tag_css(?string $background, ?string $text, ?string $background2 =
|
||||||
return implode(';', $parts);
|
return implode(';', $parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Eigene Tag-Farben aller Gruppen: [Anzeigename => Style-Angabe]. */
|
// Symbole der Gruppen (vor dem Namen, wie die Rollen-Symbole bei Discord) - speichern: includes/role_icons.php
|
||||||
function role_tag_styles(): array
|
const ROLE_ICON_DIR = __DIR__ . '/../assets/uploads/roles/';
|
||||||
|
const ROLE_ICON_URL = '/assets/uploads/roles/';
|
||||||
|
|
||||||
|
/** URL eines Gruppen-Symbols (Dateiname aus roles.tag_icon) oder null. */
|
||||||
|
function role_icon_url(?string $filename): ?string
|
||||||
{
|
{
|
||||||
static $styles = null;
|
return $filename !== null && $filename !== '' && strpos($filename, '/') === false
|
||||||
if ($styles === null) {
|
? ROLE_ICON_URL . rawurlencode($filename) : null;
|
||||||
$styles = [];
|
}
|
||||||
|
|
||||||
|
/** Das Symbol als Bild vor einem Gruppennamen - leer ohne Symbol. */
|
||||||
|
function role_icon_html(?string $url): string
|
||||||
|
{
|
||||||
|
return $url !== null ? '<img class="role-icon" src="' . e($url) . '" alt="" loading="lazy" decoding="async">' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Eigene Tag-Farben und Symbole aller Gruppen: [Anzeigename => ['style' => Style-Angabe, 'icon' => URL|null]]. */
|
||||||
|
function role_tag_info(): array
|
||||||
|
{
|
||||||
|
static $info = null;
|
||||||
|
if ($info === null) {
|
||||||
|
$info = [];
|
||||||
try {
|
try {
|
||||||
$rows = db()->query("SELECT COALESCE(NULLIF(display_name, ''), name) AS label, tag_bg, tag_bg2, tag_color FROM roles ORDER BY id")->fetchAll();
|
$rows = db()->query("SELECT COALESCE(NULLIF(display_name, ''), name) AS label, tag_bg, tag_bg2, tag_color, tag_icon FROM roles ORDER BY id")->fetchAll();
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$rows = []; // Spalten kommen erst mit dem naechsten Schema-Abgleich
|
$rows = []; // Spalten kommen erst mit dem naechsten Schema-Abgleich
|
||||||
}
|
}
|
||||||
|
// Mehrere Gruppen mit demselben Anzeigenamen: jeweils die erste, die Farben bzw. ein Symbol hat
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
$css = role_tag_css($row['tag_bg'], $row['tag_color'], $row['tag_bg2']);
|
$entry = $info[$row['label']] ?? ['style' => '', 'icon' => null];
|
||||||
if ($css !== '' && !isset($styles[$row['label']])) {
|
if ($entry['style'] === '') {
|
||||||
$styles[$row['label']] = $css;
|
$entry['style'] = role_tag_css($row['tag_bg'], $row['tag_color'], $row['tag_bg2']);
|
||||||
|
}
|
||||||
|
$entry['icon'] ??= role_icon_url($row['tag_icon']);
|
||||||
|
$info[$row['label']] = $entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return $info;
|
||||||
return $styles;
|
}
|
||||||
|
|
||||||
|
/** URL des Symbols einer Gruppe, nach ihrem Anzeigenamen - oder null. */
|
||||||
|
function role_icon_for(string $label): ?string
|
||||||
|
{
|
||||||
|
return role_tag_info()[$label]['icon'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag einer Gruppe, mit ihren eigenen Farben, falls sie welche hat ($style = null: nach Namen
|
* Tag einer Gruppe, mit ihren eigenen Farben und ihrem Symbol, falls sie welche hat ($style = null: beides
|
||||||
* nachschlagen). $extraClass z.B. "member-role-rank" (Mitgliederliste).
|
* nach Namen nachschlagen, sonst gilt $icon). $extraClass z.B. "member-role-rank" (Mitgliederliste).
|
||||||
*/
|
*/
|
||||||
function role_tag_html(string $label, ?string $style = null, string $extraClass = ''): string
|
function role_tag_html(string $label, ?string $style = null, string $extraClass = '', ?string $icon = null): string
|
||||||
{
|
{
|
||||||
$style ??= role_tag_styles()[$label] ?? '';
|
if ($style === null) {
|
||||||
|
$style = role_tag_info()[$label]['style'] ?? '';
|
||||||
|
$icon = role_icon_for($label);
|
||||||
|
}
|
||||||
return '<span class="member-role' . ($extraClass !== '' ? ' ' . e($extraClass) : '') . '"'
|
return '<span class="member-role' . ($extraClass !== '' ? ' ' . e($extraClass) : '') . '"'
|
||||||
. ($style !== '' ? ' style="' . e($style) . '"' : '') . '>' . e($label) . '</span>';
|
. ($style !== '' ? ' style="' . e($style) . '"' : '') . '>' . role_icon_html($icon) . e($label) . '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function require_permission(string $key): void
|
function require_permission(string $key): void
|
||||||
|
|
|
||||||
173
includes/role_icons.php
Normal file
173
includes/role_icons.php
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symbole der Berechtigungsgruppen speichern: hochgeladen oder per Link. Einen Link laedt die Website
|
||||||
|
* beim Speichern einmal herunter und legt das Bild selbst ab - Besucher laden so nichts von fremden
|
||||||
|
* Servern, und ein Link, der spaeter nicht mehr geht (z.B. abgelaufene Discord-Anhaenge), macht das
|
||||||
|
* Symbol nicht kaputt. Angezeigt werden die Symbole ueber role_tag_html() in includes/permissions.php.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const ROLE_ICON_MAX_BYTES = 2 * 1024 * 1024;
|
||||||
|
// Laengste Seite in Pixeln: angezeigt wird das Symbol mit gut 20 px, so bleibt es auch auf
|
||||||
|
// hochaufloesenden Bildschirmen scharf
|
||||||
|
const ROLE_ICON_MAX_SIDE = 128;
|
||||||
|
// Weiterleitungen, denen ein Link hoechstens folgt (jede wird wie der Link selbst geprueft)
|
||||||
|
const ROLE_ICON_MAX_REDIRECTS = 3;
|
||||||
|
const ROLE_ICON_TYPES = [IMAGETYPE_PNG => 'png', IMAGETYPE_JPEG => 'jpg', IMAGETYPE_GIF => 'gif', IMAGETYPE_WEBP => 'webp'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hochgeladenes Symbol speichern.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $file Eintrag aus $_FILES
|
||||||
|
* @return string Dateiname
|
||||||
|
* @throws RuntimeException mit verstaendlicher Meldung
|
||||||
|
*/
|
||||||
|
function role_icon_store_upload(array $file): string
|
||||||
|
{
|
||||||
|
$error = (int) ($file['error'] ?? UPLOAD_ERR_NO_FILE);
|
||||||
|
if ($error !== UPLOAD_ERR_OK) {
|
||||||
|
throw new RuntimeException(in_array($error, [UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE], true)
|
||||||
|
? 'Das Symbol ist zu groß (höchstens 2 MB).' : 'Das Symbol konnte nicht hochgeladen werden.');
|
||||||
|
}
|
||||||
|
if ((int) ($file['size'] ?? 0) > ROLE_ICON_MAX_BYTES) {
|
||||||
|
throw new RuntimeException('Das Symbol ist zu groß (höchstens 2 MB).');
|
||||||
|
}
|
||||||
|
return role_icon_store((string) $file['tmp_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Symbol von einem Link laden und speichern.
|
||||||
|
*
|
||||||
|
* @return string Dateiname
|
||||||
|
* @throws RuntimeException mit verstaendlicher Meldung
|
||||||
|
*/
|
||||||
|
function role_icon_store_from_url(string $url): string
|
||||||
|
{
|
||||||
|
$body = role_icon_download($url);
|
||||||
|
$info = @getimagesizefromstring($body);
|
||||||
|
if ($info === false || !isset(ROLE_ICON_TYPES[$info[2]])) {
|
||||||
|
throw new RuntimeException('Hinter dem Link steckt kein Bild (PNG, JPG, GIF oder WEBP). Nimm den direkten Link zum Bild: Rechtsklick aufs Bild → „Bildadresse kopieren“.');
|
||||||
|
}
|
||||||
|
// Zwischendatei im Symbol-Ordner - der ist sicher beschreibbar, das temporaere Verzeichnis des Servers nicht immer
|
||||||
|
role_icon_ensure_dir();
|
||||||
|
$tmp = ROLE_ICON_DIR . 'download_' . bin2hex(random_bytes(8)) . '.tmp';
|
||||||
|
if (@file_put_contents($tmp, $body) === false) {
|
||||||
|
throw new RuntimeException('Das Symbol konnte nicht gespeichert werden (Schreibrechte auf dem Server prüfen).');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return role_icon_store($tmp);
|
||||||
|
} finally {
|
||||||
|
@unlink($tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bild pruefen, neu rechnen (zu grosse verkleinert, angehaengter Code und EXIF-Daten fallen weg, siehe
|
||||||
|
* store_uploaded_image) und unter einem neuen Namen ablegen.
|
||||||
|
*
|
||||||
|
* @return string Dateiname
|
||||||
|
* @throws RuntimeException mit verstaendlicher Meldung
|
||||||
|
*/
|
||||||
|
function role_icon_store(string $path): string
|
||||||
|
{
|
||||||
|
$info = @getimagesize($path);
|
||||||
|
if ($info === false || !isset(ROLE_ICON_TYPES[$info[2]])) {
|
||||||
|
throw new RuntimeException('Das Symbol muss ein Bild sein: PNG, JPG, GIF oder WEBP.');
|
||||||
|
}
|
||||||
|
role_icon_ensure_dir();
|
||||||
|
$name = 'role_' . bin2hex(random_bytes(8)) . '.' . ROLE_ICON_TYPES[$info[2]];
|
||||||
|
$error = store_uploaded_image($path, ROLE_ICON_DIR . $name, $info[2], ROLE_ICON_MAX_SIDE);
|
||||||
|
if ($error !== null) {
|
||||||
|
throw new RuntimeException($error);
|
||||||
|
}
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function role_icon_ensure_dir(): void
|
||||||
|
{
|
||||||
|
if (!is_dir(ROLE_ICON_DIR)) {
|
||||||
|
@mkdir(ROLE_ICON_DIR, 0755, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Symbol-Datei loeschen (ersetzt, entfernt oder mit der Gruppe geloescht). */
|
||||||
|
function role_icon_delete(?string $filename): void
|
||||||
|
{
|
||||||
|
if ($filename !== null && $filename !== '' && strpos($filename, '/') === false && is_file(ROLE_ICON_DIR . $filename)) {
|
||||||
|
@unlink(ROLE_ICON_DIR . $filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Laedt ein Bild von einem Link: nur http(s), hoechstens ROLE_ICON_MAX_BYTES, Weiterleitungen werden einzeln
|
||||||
|
* geprueft. Adressen im eigenen Netz (localhost, 192.168.…) sind gesperrt - sonst liesse sich der Webserver
|
||||||
|
* ueber das Formular auf Dienste ansetzen, die nur von innen erreichbar sind.
|
||||||
|
*
|
||||||
|
* @throws RuntimeException mit verstaendlicher Meldung
|
||||||
|
*/
|
||||||
|
function role_icon_download(string $url): string
|
||||||
|
{
|
||||||
|
if (!function_exists('curl_init')) {
|
||||||
|
throw new RuntimeException('Links gehen auf diesem Server nicht (die PHP-cURL-Erweiterung fehlt) - bitte das Bild hochladen.');
|
||||||
|
}
|
||||||
|
for ($redirects = 0; $redirects <= ROLE_ICON_MAX_REDIRECTS; $redirects++) {
|
||||||
|
$parts = parse_url($url);
|
||||||
|
$scheme = strtolower((string) ($parts['scheme'] ?? ''));
|
||||||
|
$host = strtolower(trim((string) ($parts['host'] ?? ''), '[]'));
|
||||||
|
if (!in_array($scheme, ['http', 'https'], true) || $host === '') {
|
||||||
|
throw new RuntimeException('Der Link zum Symbol muss mit https:// (oder http://) beginnen.');
|
||||||
|
}
|
||||||
|
$isIp = filter_var($host, FILTER_VALIDATE_IP) !== false;
|
||||||
|
$ips = $isIp ? [$host] : (gethostbynamel($host) ?: []);
|
||||||
|
if (!$ips) {
|
||||||
|
throw new RuntimeException('Den Server „' . $host . '“ aus dem Link gibt es nicht.');
|
||||||
|
}
|
||||||
|
foreach ($ips as $ip) {
|
||||||
|
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
|
||||||
|
throw new RuntimeException('Links auf Adressen im eigenen Netz sind nicht erlaubt.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = '';
|
||||||
|
$options = [
|
||||||
|
CURLOPT_FOLLOWLOCATION => false,
|
||||||
|
CURLOPT_TIMEOUT => 10,
|
||||||
|
CURLOPT_CONNECTTIMEOUT => 5,
|
||||||
|
CURLOPT_USERAGENT => 'LuminaAscendens/1.0 (+Legion-Website, Gruppensymbol)',
|
||||||
|
CURLOPT_HTTPHEADER => ['Accept: image/webp,image/png,image/jpeg,image/gif,*/*;q=0.8'],
|
||||||
|
// Groesse schon beim Laden begrenzen: 0 zurueckgeben bricht die Uebertragung ab
|
||||||
|
CURLOPT_WRITEFUNCTION => static function ($ch, string $chunk) use (&$body): int {
|
||||||
|
$body .= $chunk;
|
||||||
|
return strlen($body) > ROLE_ICON_MAX_BYTES ? 0 : strlen($chunk);
|
||||||
|
},
|
||||||
|
];
|
||||||
|
if (!$isIp) {
|
||||||
|
// Genau die gepruefte Adresse verbinden - ein zweites Nachschlagen koennte woanders hin zeigen
|
||||||
|
$port = (int) ($parts['port'] ?? ($scheme === 'https' ? 443 : 80));
|
||||||
|
$options[CURLOPT_RESOLVE] = [$host . ':' . $port . ':' . $ips[0]];
|
||||||
|
}
|
||||||
|
$ch = curl_init($url);
|
||||||
|
curl_setopt_array($ch, $options);
|
||||||
|
$ok = curl_exec($ch);
|
||||||
|
$status = (int) curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
||||||
|
$location = (string) curl_getinfo($ch, CURLINFO_REDIRECT_URL);
|
||||||
|
$curlError = curl_error($ch);
|
||||||
|
|
||||||
|
if (strlen($body) > ROLE_ICON_MAX_BYTES) {
|
||||||
|
throw new RuntimeException('Das Bild hinter dem Link ist zu groß (höchstens 2 MB).');
|
||||||
|
}
|
||||||
|
if ($ok === false) {
|
||||||
|
throw new RuntimeException('Der Link ließ sich nicht laden (' . $curlError . ').');
|
||||||
|
}
|
||||||
|
if (in_array($status, [301, 302, 303, 307, 308], true) && $location !== '') {
|
||||||
|
$url = $location;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($status !== 200) {
|
||||||
|
throw new RuntimeException('Der Link antwortet mit Status ' . $status . ' - ist das Bild öffentlich erreichbar?');
|
||||||
|
}
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
throw new RuntimeException('Der Link leitet zu oft weiter.');
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ declare(strict_types=1);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu.
|
// Hochzaehlen, sobald unten eine Aenderung dazukommt - dann pruefen alle Sitzungen neu.
|
||||||
const SCHEMA_VERSION = 54;
|
const SCHEMA_VERSION = 55;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql).
|
* Tabellen, die nachtraeglich dazugekommen sind: Tabelle => CREATE-Befehl (wie in sql/schema.sql).
|
||||||
|
|
@ -790,6 +790,8 @@ function schema_column_upgrades(): array
|
||||||
'tag_color' => "ALTER TABLE roles ADD COLUMN tag_color VARCHAR(7) NULL AFTER tag_bg",
|
'tag_color' => "ALTER TABLE roles ADD COLUMN tag_color VARCHAR(7) NULL AFTER tag_bg",
|
||||||
// Zweite Hintergrundfarbe: Verlauf von tag_bg (links) nach tag_bg2 (rechts), wie bei Discord
|
// Zweite Hintergrundfarbe: Verlauf von tag_bg (links) nach tag_bg2 (rechts), wie bei Discord
|
||||||
'tag_bg2' => "ALTER TABLE roles ADD COLUMN tag_bg2 VARCHAR(7) NULL AFTER tag_bg",
|
'tag_bg2' => "ALTER TABLE roles ADD COLUMN tag_bg2 VARCHAR(7) NULL AFTER tag_bg",
|
||||||
|
// Symbol vor dem Namen im Tag (Dateiname unter assets/uploads/roles/), wie die Rollen-Symbole bei Discord
|
||||||
|
'tag_icon' => "ALTER TABLE roles ADD COLUMN tag_icon VARCHAR(40) NULL AFTER tag_color",
|
||||||
],
|
],
|
||||||
// Freigabe von Galeriebildern (Moderation) - vorhandene Bilder bleiben sichtbar
|
// Freigabe von Galeriebildern (Moderation) - vorhandene Bilder bleiben sichtbar
|
||||||
'member_gallery' => [
|
'member_gallery' => [
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ require_permission('members.view');
|
||||||
// Rollen, die in der Mitgliederliste eine eigene Gruppe bekommen, aufsteigend
|
// Rollen, die in der Mitgliederliste eine eigene Gruppe bekommen, aufsteigend
|
||||||
// nach ihrer konfigurierten Reihenfolge (siehe Berechtigungsgruppen-Verwaltung).
|
// nach ihrer konfigurierten Reihenfolge (siehe Berechtigungsgruppen-Verwaltung).
|
||||||
$rankRoles = db()->query(
|
$rankRoles = db()->query(
|
||||||
"SELECT id, COALESCE(NULLIF(display_name, ''), name) AS name
|
"SELECT id, COALESCE(NULLIF(display_name, ''), name) AS name, tag_icon
|
||||||
FROM roles WHERE roster_order IS NOT NULL ORDER BY roster_order ASC, name ASC"
|
FROM roles WHERE roster_order IS NOT NULL ORDER BY roster_order ASC, name ASC"
|
||||||
)->fetchAll();
|
)->fetchAll();
|
||||||
|
|
||||||
|
|
@ -38,6 +38,9 @@ try {
|
||||||
// Rollen hat; ohne passende Rolle landet es in der allgemeinen Gruppe "Mitglieder".
|
// Rollen hat; ohne passende Rolle landet es in der allgemeinen Gruppe "Mitglieder".
|
||||||
$sectionNames = array_column($rankRoles, 'name');
|
$sectionNames = array_column($rankRoles, 'name');
|
||||||
$sectionNames[] = 'Mitglieder';
|
$sectionNames[] = 'Mitglieder';
|
||||||
|
// Symbole vor den Abschnitts-Ueberschriften (die Tags dieser Gruppen sind dort ausgeblendet)
|
||||||
|
$sectionIcons = array_map(static fn (array $role): ?string => role_icon_url($role['tag_icon']), $rankRoles);
|
||||||
|
$sectionIcons[] = null;
|
||||||
foreach ($members as &$member) {
|
foreach ($members as &$member) {
|
||||||
$member['rank'] = count($rankRoles);
|
$member['rank'] = count($rankRoles);
|
||||||
foreach ($rankRoles as $index => $role) {
|
foreach ($rankRoles as $index => $role) {
|
||||||
|
|
@ -164,7 +167,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
<div class="members-chips" data-filter="group" role="group" aria-label="Nach Gruppe filtern">
|
<div class="members-chips" data-filter="group" role="group" aria-label="Nach Gruppe filtern">
|
||||||
<button type="button" class="members-chip active" data-value="">Alle</button>
|
<button type="button" class="members-chip active" data-value="">Alle</button>
|
||||||
<?php foreach (array_keys($allGroups) as $group): ?>
|
<?php foreach (array_keys($allGroups) as $group): ?>
|
||||||
<button type="button" class="members-chip" data-value="<?= e($group) ?>"><?= e($group) ?></button>
|
<button type="button" class="members-chip" data-value="<?= e($group) ?>"><?= role_icon_html(role_icon_for($group)) ?><?= e($group) ?></button>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -194,7 +197,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="members-list" data-sections="<?= e(json_encode($sectionNames, JSON_UNESCAPED_UNICODE)) ?>">
|
<div id="members-list" data-sections="<?= e(json_encode($sectionNames, JSON_UNESCAPED_UNICODE)) ?>" data-section-icons="<?= e(json_encode($sectionIcons)) ?>">
|
||||||
<div class="member-grid">
|
<div class="member-grid">
|
||||||
<?php foreach ($members as $member): ?>
|
<?php foreach ($members as $member): ?>
|
||||||
<?= member_card($member, array_column($rankRoles, 'name')) ?>
|
<?= member_card($member, array_column($rankRoles, 'name')) ?>
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,9 @@ CREATE TABLE IF NOT EXISTS roles (
|
||||||
tag_bg VARCHAR(7) NULL,
|
tag_bg VARCHAR(7) NULL,
|
||||||
tag_bg2 VARCHAR(7) NULL,
|
tag_bg2 VARCHAR(7) NULL,
|
||||||
tag_color VARCHAR(7) NULL,
|
tag_color VARCHAR(7) NULL,
|
||||||
|
-- Symbol vor dem Namen im Tag (Dateiname unter assets/uploads/roles/), wie die Rollen-Symbole
|
||||||
|
-- bei Discord - NULL = kein Symbol
|
||||||
|
tag_icon VARCHAR(40) NULL,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue