The lead of a premade (or the leadership with premades.manage) picks one of the landscapes or uploads an own image in edit mode under "Banner" and moves the crop with a slider (live preview). - Shown on top of the premade card (name on the banner), above the roster under "Meine Premade" on the dashboard, and behind the heading of the raid group that carries the premade's name (invited premade groups are named after it). - New table premade_banners (per premade ID of the bot, with the name for the raid groups, the choice and the crop; schema 54, also in sql/schema.sql). Own images are member_gallery rows with is_background = 1 and the new column premade_id, so they go through the same moderation (badge "Premade-Banner"), data export and account deletion as gallery pictures. The own profile background and the profile reset ignore banner rows. - premade_action.php: banner_save, banner_upload, banner_delete_upload; renaming updates the name, dissolving removes banner and upload. premade_banners_sync() on premades.php cleans up banners of premades that no longer exist. Leadership changes to other premades are logged. - Live updates of the premades page include banner changes; privacy policy, patch notes and README mention the banners. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
3.3 KiB
PHP
99 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Live-Aktualisierung der Raid-Seite (assets/js/raids.js fragt hier regelmaessig nach).
|
|
*
|
|
* GET /raids_live.php?status=active&known=<raid_id>:<rev>,<raid_id>:<rev>,...
|
|
*
|
|
* Antwort: Reihenfolge der Raids, ihr aktueller Fingerabdruck (rev) und fertig gerenderte Karten
|
|
* fuer alle Raids, deren Fingerabdruck sich gegenueber "known" geaendert hat. Aenderungen aus dem
|
|
* Discord kommen so ebenfalls an, weil die Daten wie auf der Seite live von der Raid-API stammen.
|
|
*/
|
|
require_once __DIR__ . '/includes/bootstrap.php';
|
|
require_once __DIR__ . '/includes/raid_card.php';
|
|
|
|
// Wird per fetch() aufgerufen - Fehler deshalb als JSON statt Weiterleitung auf die Login-Seite.
|
|
if (!current_user()) {
|
|
http_response_code(401);
|
|
json_response(false, 'Bitte neu anmelden.');
|
|
}
|
|
if (!user_has_permission('raids.view')) {
|
|
http_response_code(403);
|
|
json_response(false, 'Dir fehlt die Berechtigung, Raids zu sehen.');
|
|
}
|
|
|
|
$status = (string) ($_GET['status'] ?? 'active');
|
|
if (!in_array($status, RAID_STATUSES, true)) {
|
|
$status = 'active';
|
|
}
|
|
$known = [];
|
|
foreach (explode(',', (string) ($_GET['known'] ?? '')) as $pair) {
|
|
$parts = explode(':', trim($pair), 2);
|
|
if (count($parts) === 2 && ctype_digit($parts[0])) {
|
|
$known[$parts[0]] = $parts[1];
|
|
}
|
|
}
|
|
|
|
$currentUser = current_user();
|
|
$canManageRaids = user_has_permission('raids.manage');
|
|
$canSetRaidPoints = $canManageRaids && user_has_permission('raids.points');
|
|
$canCreateRaids = $canManageRaids || user_has_permission('raids.create');
|
|
// Die Formulare in den Karten brauchen das CSRF-Token der Sitzung - danach die Sitzung freigeben,
|
|
// damit eine langsame Raid-API andere Tabs derselben Person nicht blockiert.
|
|
csrf_token();
|
|
session_write_close();
|
|
|
|
try {
|
|
$raids = fetch_raids($status);
|
|
} catch (Throwable $e) {
|
|
http_response_code(502);
|
|
json_response(false, 'Raid-Daten konnten nicht geladen werden.');
|
|
}
|
|
try {
|
|
$raidSettings = raid_settings_all();
|
|
} catch (PDOException $e) {
|
|
$raidSettings = [];
|
|
}
|
|
|
|
$order = [];
|
|
$revs = [];
|
|
$changed = [];
|
|
foreach ($raids as $raid) {
|
|
$raidId = (string) (int) ($raid['raid_id'] ?? 0);
|
|
$rev = raid_card_rev($raid, $raidSettings[$raidId] ?? null);
|
|
$order[] = $raidId;
|
|
$revs[$raidId] = $rev;
|
|
if (isset($known[$raidId]) && $known[$raidId] !== $rev) {
|
|
$changed[$raidId] = $raid;
|
|
}
|
|
}
|
|
|
|
$cards = [];
|
|
if (!empty($changed)) {
|
|
$premades = [];
|
|
if ($canCreateRaids) {
|
|
try {
|
|
$premades = fetch_premades();
|
|
} catch (Throwable $e) {
|
|
$premades = [];
|
|
}
|
|
}
|
|
$context = [
|
|
'status' => $status,
|
|
'current_discord_id' => $currentUser['discord_id'] ?? null,
|
|
'current_user_id' => (int) $currentUser['id'],
|
|
'can_manage' => $canManageRaids,
|
|
'can_set_points' => $canSetRaidPoints,
|
|
'settings' => $raidSettings,
|
|
'premades' => $premades,
|
|
'premade_banners' => premade_banners_by_name(),
|
|
'new_since' => isset($_SESSION['raids_new_since']) ? (int) $_SESSION['raids_new_since'] : null,
|
|
];
|
|
foreach ($changed as $raidId => $raid) {
|
|
ob_start();
|
|
render_raid_card($raid, $context);
|
|
$cards[$raidId] = trim((string) ob_get_clean());
|
|
}
|
|
}
|
|
|
|
header('Cache-Control: no-store');
|
|
json_response(true, '', ['order' => $order, 'revs' => $revs, 'cards' => (object) $cards]);
|