LuminaWebsite/member_edit.php
Maaxxs e4f23fcde4 Audit log, abuse protection, gallery comments with moderation, safe image uploads, 404 page
- Audit log: every admin_log entry is also stored permanently in the database (admin/audit.php, audit.view)
- Rate limits per account, login throttling per IP (not per account), emergency lock after mass deletions, force logout / lock in user management
- Comments under gallery pictures (picture page, report button, owner can disable them)
- Moderation: new members, links, reported content and a "moderate everything" switch go to the approval list (moderation.php)
- Every uploaded image is re-encoded (strips appended code and EXIF data)
- Custom 404 page, also shown for pages without permission

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 21:57:34 +02:00

197 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/member_profile.php';
require_permission('members.view');
$id = (int) ($_GET['id'] ?? current_user()['id']);
if (!profile_can_edit($id)) {
set_flash('error', 'Du darfst nur deine eigene Profilseite bearbeiten.');
redirect('/member.php?id=' . $id);
}
$stmt = db()->prepare("SELECT id, username, display_name, profile_bio, gallery_comments_enabled, status FROM users WHERE id = ?");
$stmt->execute([$id]);
$member = $stmt->fetch();
if (!$member) {
redirect('/members.php');
}
$name = $member['display_name'] !== '' ? $member['display_name'] : $member['username'];
$isOwn = (int) current_user()['id'] === $id;
$characters = profile_characters_by_user($id)[$id] ?? [];
$galleryStmt = db()->prepare('SELECT * FROM member_gallery WHERE user_id = ? ORDER BY sort_order, id');
$galleryStmt->execute([$id]);
$gallery = $galleryStmt->fetchAll();
/** Felder eines Charakters (fuer "neu" und "bearbeiten" gleich). */
function character_fields(array $c, string $prefix): void
{
?>
<div class="character-form-grid">
<div>
<label for="<?= $prefix ?>-name">Name</label>
<input type="text" id="<?= $prefix ?>-name" name="name" maxlength="60" required value="<?= e((string) ($c['name'] ?? '')) ?>" placeholder="z.B. Damaskar">
</div>
<div>
<label for="<?= $prefix ?>-class">Klasse</label>
<select id="<?= $prefix ?>-class" name="class_name">
<option value="">– wählen –</option>
<?php foreach (AION_CLASSES as $class): ?>
<option value="<?= e($class) ?>"<?= ($c['class_name'] ?? '') === $class ? ' selected' : '' ?>><?= e($class) ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="<?= $prefix ?>-level">Stufe (optional)</label>
<input type="number" id="<?= $prefix ?>-level" name="level" min="1" max="999" value="<?= e((string) ($c['level'] ?? '')) ?>">
</div>
<label class="character-main-toggle">
<input type="checkbox" name="is_main" value="1"<?= !empty($c['is_main']) ? ' checked' : '' ?>> Hauptcharakter
</label>
</div>
<div>
<label for="<?= $prefix ?>-note">Kurzbeschreibung (optional)</label>
<input type="text" id="<?= $prefix ?>-note" name="note" maxlength="255" value="<?= e((string) ($c['note'] ?? '')) ?>" placeholder="z.B. Main für Raids, Twink zum Farmen">
</div>
<div class="character-form-grid">
<div>
<label for="<?= $prefix ?>-portrait">Portrait</label>
<?php if (!empty($c['portrait_filename'])): ?>
<div class="character-current-image">
<img src="<?= e(profile_image_url($c['portrait_filename'])) ?>" alt="">
<label><input type="checkbox" name="remove_portrait" value="1"> entfernen</label>
</div>
<?php endif; ?>
<input type="file" id="<?= $prefix ?>-portrait" name="portrait" accept="image/png,image/jpeg,image/gif,image/webp" data-max-size="600">
<div class="field-hint">Am besten ein quadratischer Ausschnitt des Gesichts.</div>
</div>
<div>
<label for="<?= $prefix ?>-image">Bild</label>
<?php if (!empty($c['image_filename'])): ?>
<div class="character-current-image">
<img src="<?= e(profile_image_url($c['image_filename'])) ?>" alt="">
<label><input type="checkbox" name="remove_image" value="1"> entfernen</label>
</div>
<?php endif; ?>
<input type="file" id="<?= $prefix ?>-image" name="image" accept="image/png,image/jpeg,image/gif,image/webp" data-max-size="1600">
<div class="field-hint">Z.B. ein Screenshot des ganzen Charakters in seiner Rüstung.</div>
</div>
</div>
<?php
}
$pageTitle = 'Profilseite bearbeiten';
include __DIR__ . '/includes/header.php';
?>
<div class="panel">
<div class="raid-header">
<h1><?= $isOwn ? 'Meine Profilseite' : 'Profilseite von ' . e($name) ?></h1>
<a class="button button-secondary button-small" href="/member.php?id=<?= $id ?>">Ansehen</a>
</div>
<p class="text-muted">Alles hier sehen die anderen Mitglieder der Legion auf deiner Profilseite.</p>
</div>
<form class="panel" method="post" action="/member_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="bio_save">
<input type="hidden" name="user_id" value="<?= $id ?>">
<h2>Über mich</h2>
<textarea name="profile_bio" rows="8" maxlength="<?= PROFILE_MAX_BIO ?>" placeholder="Erzähl etwas über dich: Wie lange spielst du schon Aion? Was machst du am liebsten im Spiel? Wann bist du meistens online?"><?= e((string) $member['profile_bio']) ?></textarea>
<div class="field-hint">Formatierung: <code>**fett**</code>, <code>*kursiv*</code>, <code>- Liste</code>, <code>## Überschrift</code>, <code>[Link](https://…)</code>.</div>
<div class="actions"><button type="submit">Speichern</button></div>
</form>
<div class="panel">
<h2>Charaktere</h2>
<?php foreach ($characters as $character): ?>
<details class="character-edit">
<summary>
<?= class_badge_html($character['class_name'], 22) ?>
<strong><?= e($character['name']) ?></strong>
<span class="text-muted"><?= e($character['class_name'] ?? '') ?><?= $character['level'] ? ' · Stufe ' . (int) $character['level'] : '' ?></span>
<?php if ($character['is_main']): ?><span class="badge badge-pending">Hauptcharakter</span><?php endif; ?>
<span class="character-edit-hint">bearbeiten ▾</span>
</summary>
<form method="post" action="/member_action.php" enctype="multipart/form-data">
<?= csrf_field() ?>
<input type="hidden" name="action" value="character_save">
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="hidden" name="character_id" value="<?= (int) $character['id'] ?>">
<?php character_fields($character, 'c' . (int) $character['id']); ?>
<div class="actions">
<button type="submit">Speichern</button>
<button type="submit" name="action" value="character_delete" class="button-danger"
onclick="return confirm('<?= e($character['name']) ?> wirklich löschen?');">Löschen</button>
</div>
</form>
</details>
<?php endforeach; ?>
<?php if (count($characters) < PROFILE_MAX_CHARACTERS): ?>
<details class="character-edit character-new"<?= empty($characters) ? ' open' : '' ?>>
<summary><strong>+ Charakter hinzufügen</strong></summary>
<form method="post" action="/member_action.php" enctype="multipart/form-data">
<?= csrf_field() ?>
<input type="hidden" name="action" value="character_save">
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="hidden" name="character_id" value="0">
<?php character_fields(['is_main' => empty($characters)], 'new'); ?>
<div class="actions"><button type="submit">Charakter anlegen</button></div>
</form>
</details>
<?php else: ?>
<p class="text-muted">Mehr als <?= PROFILE_MAX_CHARACTERS ?> Charaktere gehen nicht.</p>
<?php endif; ?>
</div>
<div class="panel">
<h2>Galerie</h2>
<form class="settings-toggle" method="post" action="/member_action.php">
<?= csrf_field() ?>
<input type="hidden" name="action" value="gallery_comments_toggle">
<input type="hidden" name="user_id" value="<?= $id ?>">
<label>
<input type="checkbox" name="enabled" value="1" <?= !empty($member['gallery_comments_enabled']) ? 'checked' : '' ?> onchange="this.form.submit()">
Andere Mitglieder dürfen meine Bilder kommentieren
</label>
<noscript><button type="submit" class="button-secondary button-small">Speichern</button></noscript>
</form>
<?php if (count($gallery) < PROFILE_MAX_GALLERY): ?>
<form method="post" action="/member_action.php" enctype="multipart/form-data" class="gallery-upload">
<?= csrf_field() ?>
<input type="hidden" name="action" value="gallery_upload">
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="file" name="images[]" accept="image/png,image/jpeg,image/gif,image/webp" multiple required data-max-size="1920">
<input type="text" name="caption" maxlength="150" placeholder="Bildunterschrift (optional)">
<button type="submit">Hochladen</button>
</form>
<div class="field-hint">Screenshots, Erinnerungen an Raids, lustige Momente … bis zu <?= PROFILE_MAX_GALLERY ?> Bilder, je höchstens 8 MB. Mehrere auf einmal auswählen geht auch.</div>
<?php else: ?>
<p class="text-muted">Die Galerie ist voll (<?= PROFILE_MAX_GALLERY ?> Bilder). Lösch ein altes Bild, um ein neues hochzuladen.</p>
<?php endif; ?>
<?php if (!empty($gallery)): ?>
<div class="gallery-grid gallery-edit-grid">
<?php foreach ($gallery as $picture): ?>
<figure class="gallery-item<?= ($picture['status'] ?? 'visible') === 'pending' ? ' is-pending' : '' ?>">
<?php if (($picture['status'] ?? 'visible') === 'pending'): ?>
<span class="pending-badge" title="<?= e((string) $picture['moderation_note']) ?>">Wartet auf Freigabe</span>
<?php endif; ?>
<img src="<?= e(profile_image_url($picture['filename'])) ?>" alt="" loading="lazy">
<form method="post" action="/member_action.php" class="gallery-item-form">
<?= csrf_field() ?>
<input type="hidden" name="user_id" value="<?= $id ?>">
<input type="hidden" name="picture_id" value="<?= (int) $picture['id'] ?>">
<input type="text" name="caption" maxlength="150" value="<?= e((string) $picture['caption']) ?>" placeholder="Bildunterschrift">
<div class="gallery-item-actions">
<button type="submit" name="action" value="gallery_update" class="button-small button-secondary">Speichern</button>
<button type="submit" name="action" value="gallery_delete" class="icon-button icon-button-danger" title="Löschen"
onclick="return confirm('Dieses Bild löschen?');"><?= icon('trash') ?></button>
</div>
</form>
</figure>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<script src="<?= e(asset_url('/assets/js/image-resize.js')) ?>"></script>
<?php include __DIR__ . '/includes/footer.php'; ?>