LuminaWebsite/raids_live.php
Maaxxs b62f1213c0 Raid count in the sidebar, member screenshots on the start page, clickable dashboard tiles
- Sidebar: number of upcoming raids next to "Raids" (all not archived, same as the dashboard
  tile). Gold while a raid was posted since the last visit of the raid page (users.raids_seen_at,
  schema v46; the posting time comes from the raid id = Discord message id). New raids are
  marked "Neu" on the raid page, also in live updates; your own new raid is not. The raid ids
  are cached in settings.raids_nav_cache: every raid fetch refreshes it, otherwise the sidebar
  asks the bot after 5 minutes with a 3 s timeout and keeps the last state if it is down.
- Start page: the group photo alternates every 6 s with gallery pictures that members released
  themselves ("Auf der Startseite zeigen", member_gallery.show_on_home, schema v47) - without
  name or caption, only visible pictures of active members, with a pause button, only while
  the photo is in view. Only the member can release a picture; leadership can only take it off
  (logged).
- Dashboard: the tiles "Mitglieder" and "Berechtigungsgruppen" link to the user management and
  the roles, like "Anstehende Raids".
- Tour: new steps for gallery, calendar, gear planner and patch notes; menu customization,
  profile page, daily reward and the raid count mentioned.
- Privacy policy (activity, start page, withdrawal), account anonymization (resets
  raids_seen_at), README and patch notes updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 23:20:32 +02:00

96 lines
3.1 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');
// 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 ($canManageRaids) {
try {
$premades = fetch_premades();
} catch (Throwable $e) {
$premades = [];
}
}
$context = [
'status' => $status,
'current_discord_id' => $currentUser['discord_id'] ?? null,
'can_manage' => $canManageRaids,
'can_set_points' => $canSetRaidPoints,
'settings' => $raidSettings,
'premades' => $premades,
'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]);