LuminaWebsite/admin/gear_items_action.php
Maaxxs 1dec879de2 Skill tooltips with values at the planned level, page background no longer zooms, 150+ members
- Skill and stigma tooltips show their values at the reached level (own level plus Daevanion/Arcana bonus)
  and update live with - and +; values that grow with the level are green. The aion2.app import now also
  stores the description template and the values per level (from the page's React data): equal ranges
  become one value, German number format, time units (Sek./Min.), undivided ":divide1000" values fixed.
  "nur fehlende" also fetches descriptions imported before, which lack the level values.
- Page background: a fixed layer of window height behind the content instead of cover over the whole page
  height, which rescaled the image whenever the content height changed (e.g. Daevanion stats list).
- Start page: 150+ active members.

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

285 lines
16 KiB
PHP

<?php
/**
* Gear-Planer, Katalog: Gegenstaende, die Skill-Listen der Klassen und die Daten der Seiten Arcana, Pets,
* Daevanion, Pantheon und Closet (Build-Planer) von aion2hub uebernehmen und abgleichen. Antwortet als JSON
* (Aufrufe aus assets/js/gear-admin.js), nur "delete" und "skills_prune" leiten zurueck.
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/gear.php';
require_once __DIR__ . '/../includes/gear_planner.php';
require_permission('gear.manage');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
redirect('/admin/gear_items.php');
}
verify_csrf();
$userId = (int) current_user()['id'];
$action = (string) ($_POST['action'] ?? '');
/** JSON-Antwort und Ende. */
$respond = static function (array $data, int $status = 200): void {
http_response_code($status);
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($data, JSON_UNESCAPED_UNICODE);
exit;
};
/**
* Hoechstens ein Abruf pro Sekunde (pro Sitzung) - aion2hub soll von uns nicht mehr merken als
* von jemandem, der sich durch die Seiten klickt.
*/
$politePause = static function (): void {
$last = (float) ($_SESSION['gear_source_last_fetch'] ?? 0);
$wait = 1.0 - (microtime(true) - $last);
if ($wait > 0) {
usleep((int) ($wait * 1000000));
}
$_SESSION['gear_source_last_fetch'] = microtime(true);
};
try {
switch ($action) {
case 'plan':
// Was steckt hinter der Eingabe? Ein einzelner Gegenstand oder Listen je Kategorie.
$input = trim((string) ($_POST['url'] ?? ''));
$single = gear_source_parse_id($input);
if ($single !== null) {
$respond(['ok' => true, 'ids' => [$single], 'known' => gear_item($single) ? [$single] : []]);
}
$respond(['ok' => true, 'lists' => gear_source_list_urls($input)]);
case 'list':
// Eine Seite einer Liste (Adresse aus "plan") -> enthaltene IDs und Seitenzahl
$url = trim((string) ($_POST['url'] ?? ''));
$page = max(1, (int) ($_POST['page'] ?? 1));
if (!in_array($url, gear_source_list_urls($url), true)) {
$respond(['ok' => false, 'error' => 'Ungültige Listen-Adresse.'], 400);
}
$politePause();
$result = gear_source_list_page(gear_source_fetch($url . '&page=' . $page));
$known = $result['ids']
? db()->query('SELECT id FROM gear_items WHERE id IN (' . implode(',', $result['ids']) . ')')->fetchAll(PDO::FETCH_COLUMN)
: [];
$respond(['ok' => true, 'known' => array_map('intval', $known)] + $result);
case 'import':
case 'check':
$id = (int) ($_POST['id'] ?? 0);
if ($id <= 0) {
$respond(['ok' => false, 'error' => 'Ungültige ID.'], 400);
}
$politePause();
$parsed = gear_item_fetch($id);
$old = gear_item($id);
$diffs = gear_item_diff($old, $parsed);
// Abgleich ohne Uebernehmen: nur zeigen, was anders waere
$apply = $action === 'import' || !empty($_POST['apply']);
if ($apply) {
$result = gear_item_store($parsed, $userId);
} elseif ($old !== null) {
// Trotzdem als "geprueft" vermerken, wenn sich nichts geaendert hat
if (!$diffs) {
db()->prepare('UPDATE gear_items SET checked_at = NOW(), checked_by = ?, source_version = ? WHERE id = ?')
->execute([$userId, mb_substr($parsed['source_version'], 0, 120), $id]);
}
}
if (empty($_POST['batch']) && $apply) {
admin_log($old === null ? '🗡️ Gear-Planer: Gegenstand übernommen' : '🗡️ Gear-Planer: Gegenstand abgeglichen', [
'Gegenstand' => $parsed['name'] . ' (#' . $id . ')',
'Änderungen' => $old === null ? 'neu' : ($diffs ? implode(', ', array_column($diffs, 0)) : 'keine'),
], 'info', 'gear');
}
$respond([
'ok' => true,
'id' => $id,
'name' => $parsed['name'],
'new' => $old === null,
'applied' => $apply,
'diffs' => $old === null ? [] : $diffs,
]);
case 'batch_done':
// Eine Zusammenfassung pro Durchlauf statt eines Eintrags je Gegenstand
$summary = array_filter([
'Art' => (string) ($_POST['kind'] ?? '') === 'check' ? 'Abgleich' : 'Übernahme',
'Neu' => (int) ($_POST['new'] ?? 0) ?: null,
'Geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
'Unverändert' => (int) ($_POST['same'] ?? 0) ?: null,
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
'Quelle' => mb_substr((string) ($_POST['source'] ?? ''), 0, 200) ?: null,
], static fn ($value): bool => $value !== null);
admin_log('🗡️ Gear-Planer: Gegenstände von aion2hub', $summary, 'info', 'gear');
$respond(['ok' => true]);
case 'skills_class':
// Skill-Liste einer Klasse von ihrer Klassenseite uebernehmen bzw. abgleichen
$className = (string) ($_POST['class_name'] ?? '');
if (!isset(GEAR_SOURCE_CLASSES[$className])) {
$respond(['ok' => false, 'error' => 'Unbekannte Klasse.'], 400);
}
[$slug, $sourceClass] = GEAR_SOURCE_CLASSES[$className];
$politePause();
$parsed = gear_source_parse_class_skills(gear_source_fetch(GEAR_SOURCE_CLASS_URL . $slug), $sourceClass);
$respond(['ok' => true, 'class_name' => $className] + gear_skills_store($className, $parsed, $userId));
case 'skill_icon':
$skill = gear_skill((int) ($_POST['id'] ?? 0));
if (!$skill) {
$respond(['ok' => false, 'error' => 'Diesen Skill gibt es nicht (mehr).'], 404);
}
if (!empty($skill['icon']) && is_file(GEAR_SKILL_ICON_DIR . $skill['icon'])) {
$respond(['ok' => true, 'icon' => $skill['icon']]);
}
$politePause();
$icon = gear_skill_icon_download((int) $skill['id']);
if ($icon === null) {
$respond(['ok' => false, 'error' => 'Icon für „' . $skill['name'] . '“ ließ sich nicht laden (bei aion2hub fehlt es evtl. noch) - der nächste Abgleich versucht es erneut.'], 422);
}
db()->prepare('UPDATE gear_skills SET icon = ? WHERE id = ?')->execute([$icon, $skill['id']]);
$respond(['ok' => true, 'icon' => $icon]);
case 'planner_plan':
// Die JavaScript-Dateien des Build-Planers - die, in denen zuletzt Daten steckten, zuerst (die Namen
// aendern sich nur mit neuen Versionen der Seite)
$politePause();
$chunks = gear_source_planner_chunks(gear_source_fetch(GEAR_SOURCE_PLANNER_URL));
if (!$chunks) {
$respond(['ok' => false, 'error' => 'Im Build-Planer von aion2hub stehen keine Dateien mehr, in denen die Daten stecken könnten - hat sich die Seite geändert?'], 422);
}
$known = json_decode(setting_get('gear_planner_chunks'), true);
$known = array_values(array_intersect(array_merge(is_array($known) ? $known : [], [setting_get('gear_planner_chunk')]), $chunks));
$respond(['ok' => true, 'chunks' => array_values(array_unique(array_merge($known, $chunks))), 'expected' => array_merge(['specs'], array_keys(GEAR_PLANNER_PARTS))]);
case 'planner_chunk':
// Eine Datei des Build-Planers durchsuchen und alles speichern, was darin steckt
$path = (string) ($_POST['path'] ?? '');
if (!preg_match('#^/_next/static/chunks/[A-Za-z0-9_~-]+\.js$#', $path)) {
$respond(['ok' => false, 'error' => 'Ungültige Datei.'], 400);
}
$politePause();
$found = gear_planner_source_extract(gear_source_fetch('https://' . GEAR_SOURCE_HOST . $path, '*/*'));
$stored = [];
foreach ($found['parts'] as $name => $part) {
$stored[$name] = gear_planner_data_store($name, $part['data'], $part['built_at']);
}
$specs = $found['specs'] !== null ? gear_skills_store_specs($found['specs']) : null;
if ($stored || $specs !== null) {
$known = json_decode(setting_get('gear_planner_chunks'), true);
setting_set('gear_planner_chunks', json_encode(array_values(array_unique(array_merge([$path], is_array($known) ? $known : [])))));
}
$respond(['ok' => true, 'found' => array_merge(array_keys($stored), $specs !== null ? ['specs'] : []), 'stored' => $stored, 'specs' => $specs]);
case 'planner_done':
// Eine Zusammenfassung pro Durchlauf
$list = static fn (string $key): string => mb_substr(implode(', ', array_filter(explode(',', (string) ($_POST[$key] ?? '')))), 0, 300);
admin_log('🗡️ Gear-Planer: Planer-Daten von aion2hub', array_filter([
'Neu' => $list('new') ?: null,
'Geändert' => $list('changed') ?: null,
'Unverändert' => (int) ($_POST['same'] ?? 0) ?: null,
'Spezialisierungen' => mb_substr((string) ($_POST['specs'] ?? ''), 0, 200) ?: null,
'Nicht gefunden' => $list('missing') ?: null,
], static fn ($value): bool => $value !== null), 'info', 'gear');
$respond(['ok' => true]);
case 'planner_icons':
// Bilder fuer Arcana, Pets und Pantheon, die noch fehlen
$missing = array_values(array_filter(gear_planner_icon_ids(), static fn (int $id): bool => gear_planner_icon_url($id) === null));
$respond(['ok' => true, 'ids' => $missing, 'total' => count(gear_planner_icon_ids())]);
case 'planner_icon':
$id = (int) ($_POST['id'] ?? 0);
if (!in_array($id, gear_planner_icon_ids(), true)) {
$respond(['ok' => false, 'error' => 'Unbekanntes Bild.'], 400);
}
if (gear_planner_icon_url($id) === null) {
$politePause();
if (gear_icon_download($id) === null) {
$respond(['ok' => false, 'error' => 'Bild #' . $id . ' ließ sich nicht laden (bei aion2hub fehlt es evtl.) - der nächste Durchlauf versucht es erneut.'], 422);
}
}
$respond(['ok' => true]);
case 'skill_info_plan':
// Skills, deren Beschreibung von aion2.app kommen soll: alle gelisteten, die ohne Beschreibung bzw. noch
// ohne Werte je Stufe (tpl, aeltere Uebernahmen) zuerst - mit only_missing nur die
$rows = db()->query("SELECT id, (info IS NULL OR info NOT LIKE '%\"tpl\":%') AS missing FROM gear_skills WHERE is_listed = 1
ORDER BY missing DESC, class_name, kind, sort_order")->fetchAll();
if (!empty($_POST['only_missing'])) {
$rows = array_filter($rows, static fn (array $row): bool => (int) $row['missing'] === 1);
}
$respond(['ok' => true, 'ids' => array_values(array_map(static fn (array $row): int => (int) $row['id'], $rows))]);
case 'skill_info':
// Beschreibung eines Skills von aion2.app (deutscher Client) holen und speichern
$skill = gear_skill((int) ($_POST['id'] ?? 0));
if (!$skill) {
$respond(['ok' => false, 'error' => 'Diesen Skill gibt es nicht (mehr).'], 404);
}
$politePause();
$parsed = gear_source_parse_skill_info(gear_source_fetch(GEAR_SOURCE_SKILL_INFO_URL . (int) $skill['id']), (int) $skill['id']);
if ($parsed['desc'] === '') {
$respond(['ok' => false, 'error' => '„' . $skill['name'] . '“: keine Beschreibung bei aion2.app.'], 422);
}
// name/parts: ob der offizielle deutsche Name bzw. die deutschen Spezialisierungen eingetragen wurden
$respond(['ok' => true, 'skill' => $skill['name'], 'name_de' => $parsed['name'], 'class_name' => $skill['class_name']] + gear_skill_info_store($skill, $parsed));
case 'skill_info_done':
// Eine Zusammenfassung pro Durchlauf
admin_log('🗡️ Gear-Planer: Skill-Beschreibungen von aion2.app', array_filter([
'Skills' => (int) ($_POST['total'] ?? 0) ?: null,
'Neu oder geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
'Deutsche Namen eingetragen' => (int) ($_POST['names'] ?? 0) ?: null,
'Deutsche Spezialisierungen eingetragen' => (int) ($_POST['parts'] ?? 0) ?: null,
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
], static fn ($value): bool => $value !== null), 'info', 'gear');
$respond(['ok' => true]);
case 'skills_done':
// Eine Zusammenfassung pro Durchlauf
$summary = array_filter([
'Klassen' => mb_substr((string) ($_POST['classes'] ?? ''), 0, 200) ?: null,
'Skills' => (int) ($_POST['total'] ?? 0) ?: null,
'Neu' => (int) ($_POST['new'] ?? 0) ?: null,
'Geändert' => (int) ($_POST['changed'] ?? 0) ?: null,
'Nicht mehr gelistet' => (int) ($_POST['unlisted'] ?? 0) ?: null,
'Icons geladen' => (int) ($_POST['icons'] ?? 0) ?: null,
'Fehler' => (int) ($_POST['failed'] ?? 0) ?: null,
], static fn ($value): bool => $value !== null);
admin_log('🗡️ Gear-Planer: Skills von aion2hub', $summary, 'info', 'gear');
$respond(['ok' => true]);
case 'skills_prune':
// Skills, die aion2hub nicht mehr listet, samt ihrer geplanten Stufen entfernen
$gone = db()->query('SELECT id, name, class_name, icon FROM gear_skills WHERE is_listed = 0')->fetchAll();
if ($gone) {
db()->exec('DELETE FROM gear_skills WHERE is_listed = 0');
foreach ($gone as $skill) {
if (!empty($skill['icon']) && strpos((string) $skill['icon'], '/') === false) {
@unlink(GEAR_SKILL_ICON_DIR . $skill['icon']);
}
}
admin_log('🗡️ Gear-Planer: alte Skills entfernt', [
'Skills' => implode(', ', array_map(static fn (array $s): string => $s['name'] . ' (' . $s['class_name'] . ')', $gone)),
], 'danger', 'gear');
set_flash('success', count($gone) . (count($gone) === 1 ? ' alter Skill entfernt.' : ' alte Skills entfernt.'));
}
redirect('/admin/gear_items.php#skills');
case 'delete':
$item = gear_item((int) ($_POST['id'] ?? 0));
if ($item) {
db()->prepare('DELETE FROM gear_items WHERE id = ?')->execute([$item['id']]);
if (!empty($item['icon']) && strpos((string) $item['icon'], '/') === false) {
@unlink(GEAR_ICON_DIR . $item['icon']);
}
admin_log('🗡️ Gear-Planer: Gegenstand gelöscht', ['Gegenstand' => $item['name'] . ' (#' . $item['id'] . ')'], 'danger', 'gear');
set_flash('success', '„' . $item['name'] . '“ gelöscht - in Sets ist der Slot jetzt leer.');
}
redirect('/admin/gear_items.php');
}
} catch (RuntimeException $e) {
$respond(['ok' => false, 'error' => $e->getMessage()], 422);
}
$respond(['ok' => false, 'error' => 'Unbekannte Aktion.'], 400);