第58批续29:PHP积分HTML污染修复+closeModal缺失修复

- adminDeduct/adminAddBonds 用 exit(json_encode()) 改为 jsonResponse()
  jsonResponse 内部清空所有缓冲区再输出,避免PHP警告污染JSON
- admin.php 添加 closeModal 函数(原本缺少,showModal 路径会调用)
This commit is contained in:
ypsdf1
2026-10-29 13:21:47 +08:00
parent 183d24ef8d
commit f6805bfd17
2 changed files with 14 additions and 9 deletions
+5
View File
@@ -2117,6 +2117,11 @@ function showModal(title, message, defaultValue, customHtml) {
});
}
// ★ 第58批续29-问题3:添加 closeModal 函数(admin.php 原本缺少)
function closeModal() {
document.querySelectorAll('[data-modal-overlay]').forEach(el => el.remove());
}
// ===== 自定义背景系统(第46批):纯色 / 图片URL / API壁纸(必应) 三模式 =====
let _wpPendingUrl = null; // 待应用的图片URL(预览/获取后暂存,点应用才生效)
+9 -9
View File
@@ -153,8 +153,8 @@ function adminDeduct() {
$player = getParam('player');
$amount = (int)getParam('amount', 0);
$reason = getParam('reason', '管理员扣减');
if (!$player) exit(json_encode(['success' => false, 'message' => 'Missing player'], JSON_UNESCAPED_UNICODE));
if ($amount <= 0) exit(json_encode(['success' => false, 'message' => 'Invalid amount'], JSON_UNESCAPED_UNICODE));
if (!$player) jsonResponse(['success' => false, 'message' => 'Missing player']);
if ($amount <= 0) jsonResponse(['success' => false, 'message' => 'Invalid amount']);
$db = getDB();
$db->exec("CREATE TABLE IF NOT EXISTS bond_cache (player_name TEXT PRIMARY KEY, amount INTEGER DEFAULT 0, updated_at INTEGER DEFAULT 0)");
try {
@@ -162,7 +162,7 @@ function adminDeduct() {
$stmt->bindValue(':name', $player, SQLITE3_TEXT);
$row = $stmt->execute()->fetchArray(SQLITE3_ASSOC);
$current = $row ? $row['amount'] : 0;
if ($current < $amount) exit(json_encode(['success' => false, 'message' => "Insufficient: $current"], JSON_UNESCAPED_UNICODE));
if ($current < $amount) jsonResponse(['success' => false, 'message' => "Insufficient: $current"]);
$newAmount = $current - $amount;
$stmt = $db->prepare("UPDATE bond_cache SET amount = :amount, updated_at = :time WHERE player_name = :name");
$stmt->bindValue(':amount', $newAmount, SQLITE3_INTEGER);
@@ -185,10 +185,10 @@ function adminDeduct() {
// ★ 通知Java插件立即拉取
notifyJavaPluginImmediatePull();
exit(json_encode(['success' => true, 'message' => 'OK', 'remaining' => $newAmount], JSON_UNESCAPED_UNICODE));
jsonResponse(['success' => true, 'message' => 'OK', 'remaining' => $newAmount]);
} catch (Exception $e) {
@error_log('[Function] Error: ' . $e->getMessage());
exit(json_encode(['success' => false, 'message' => 'Internal error'], JSON_UNESCAPED_UNICODE));
jsonResponse(['success' => false, 'message' => 'Internal error'], 500);
}
}
@@ -197,8 +197,8 @@ function adminAddBonds() {
$player = getParam('player');
$amount = (int)getParam('amount', 0);
$reason = getParam('reason', '管理员充值');
if (!$player) exit(json_encode(['success' => false, 'message' => 'Missing player'], JSON_UNESCAPED_UNICODE));
if ($amount <= 0) exit(json_encode(['success' => false, 'message' => 'Invalid amount'], JSON_UNESCAPED_UNICODE));
if (!$player) jsonResponse(['success' => false, 'message' => 'Missing player']);
if ($amount <= 0) jsonResponse(['success' => false, 'message' => 'Invalid amount']);
$db = getDB();
$db->exec("CREATE TABLE IF NOT EXISTS bond_cache (player_name TEXT PRIMARY KEY, amount INTEGER DEFAULT 0, updated_at INTEGER DEFAULT 0)");
try {
@@ -228,10 +228,10 @@ function adminAddBonds() {
// ★ 通知Java插件立即拉取
notifyJavaPluginImmediatePull();
exit(json_encode(['success' => true, 'message' => 'OK', 'new_amount' => $newAmount], JSON_UNESCAPED_UNICODE));
jsonResponse(['success' => true, 'message' => 'OK', 'new_amount' => $newAmount]);
} catch (Exception $e) {
@error_log('[Function] Error: ' . $e->getMessage());
exit(json_encode(['success' => false, 'message' => 'Internal error'], JSON_UNESCAPED_UNICODE));
jsonResponse(['success' => false, 'message' => 'Internal error'], 500);
}
}