This commit is contained in:
Lanta 2025-04-15 17:12:33 +02:00
parent 1be9732279
commit 01aa843d0b
18 changed files with 4122 additions and 2393 deletions

View file

@ -1,13 +1,78 @@
<?php
// --- Configuration and Data Fetching ---
$ogDescription = "Explore detailed lifetime statistics of PUBG players in various game modes including solo, duo, and squad. Choose your favorite mode and player to view their performance stats, victories, and more, updated regularly.";
?>
// Include config if it exists
$configPath = './config/config.php';
if (file_exists($configPath)) {
include $configPath;
} else {
// Handle missing config file, maybe set defaults or show an error
// For now, we'll proceed assuming defaults or that it's not strictly required for this page structure
}
$players_data = null;
$stats = null;
$selected_player = null;
$dataError = '';
$lastUpdated = 'N/A';
$availableModes = ['solo', 'duo', 'squad', 'solo-fpp', 'duo-fpp', 'squad-fpp']; // Define available modes
// Determine selected game mode
$selected_mode = isset($_GET['game_mode']) && in_array($_GET['game_mode'], $availableModes) ? $_GET['game_mode'] : 'squad';
// Load player lifetime data
$dataPath = './data/player_lifetime_data.json';
if (file_exists($dataPath)) {
$jsonData = file_get_contents($dataPath);
$players_data = json_decode($jsonData, true);
if (!is_array($players_data)) {
$dataError = "Error decoding player lifetime data.";
$players_data = null; // Ensure it's null if decoding failed
} else {
$lastUpdated = htmlspecialchars($players_data['updated'] ?? 'N/A');
// Check if the selected mode exists in the data
if (isset($players_data[$selected_mode]) && is_array($players_data[$selected_mode])) {
// Determine selected player
$availablePlayers = array_keys($players_data[$selected_mode]);
$selected_player_from_get = $_GET['selected_player'] ?? null;
if ($selected_player_from_get && in_array($selected_player_from_get, $availablePlayers)) {
$selected_player = $selected_player_from_get;
} elseif (!empty($availablePlayers)) {
$selected_player = $availablePlayers[0]; // Default to the first player if none selected or invalid
}
// Fetch the player stats if a player is selected
if ($selected_player && isset($players_data[$selected_mode][$selected_player])) {
$account_id = array_key_first($players_data[$selected_mode][$selected_player]);
if ($account_id && isset($players_data[$selected_mode][$selected_player][$account_id])) {
$stats = $players_data[$selected_mode][$selected_player][$account_id];
} else {
$dataError = "Could not find account ID or stats for the selected player.";
}
} elseif (empty($availablePlayers)) {
$dataError = "No players found for the selected game mode: " . htmlspecialchars($selected_mode);
} else {
$dataError = "Selected player not found or no player selected for this mode.";
}
} else {
$dataError = "Selected game mode (" . htmlspecialchars($selected_mode) . ") not found in data.";
}
}
} else {
$dataError = "Player lifetime data file not found.";
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include './includes/head.php'; ?>
<?php include './includes/head.php'; // Includes $ogDescription ?>
<body>
<?php
<?php
include './includes/navigation.php';
include './includes/header.php';
?>
@ -15,53 +80,57 @@ include './includes/header.php';
<main>
<section>
<h2>User Stats</h2>
<?php
include './config/config.php';
$players_data = json_decode(file_get_contents('./data/player_lifetime_data.json'), true);
<?php if ($dataError): ?>
<p style="color: red;"><?php echo htmlspecialchars($dataError); ?></p>
<?php endif; ?>
$selected_mode = isset($_GET['game_mode']) ? $_GET['game_mode'] : 'squad';
<!-- Form to select game mode -->
<form method="get" action="">
<?php foreach ($availableModes as $mode): ?>
<input type="submit" name="game_mode" value="<?php echo htmlspecialchars($mode); ?>" class="btn<?php echo ($mode === $selected_mode) ? ' active' : ''; ?>">
<?php endforeach; ?>
<?php if ($selected_player): // Keep selected player if switching modes ?>
<input type="hidden" name="selected_player" value="<?php echo htmlspecialchars($selected_player); ?>">
<?php endif; ?>
</form>
<br>
// Form to select game mode
echo "<form method='get' action=''>
<input type='submit' name='game_mode' value='solo' class='btn'>
<input type='submit' name='game_mode' value='duo' class='btn'>
<input type='submit' name='game_mode' value='squad' class='btn'>
<?php if (isset($players_data[$selected_mode]) && is_array($players_data[$selected_mode]) && !empty($players_data[$selected_mode])): ?>
<!-- Buttons for each player -->
<form method="get" action="">
<?php foreach ($players_data[$selected_mode] as $player_name => $player_details): ?>
<button type="submit" name="selected_player" value="<?php echo htmlspecialchars($player_name); ?>" class="btn<?php echo ($player_name === $selected_player) ? ' active' : ''; ?>">
<?php echo htmlspecialchars($player_name); ?>
</button>
<?php endforeach; ?>
<input type="hidden" name="game_mode" value="<?php echo htmlspecialchars($selected_mode); ?>">
</form>
<br>
<?php endif; ?>
<input type='submit' name='game_mode' value='solo-fpp' class='btn'>
<input type='submit' name='game_mode' value='duo-fpp' class='btn'>
<input type='submit' name='game_mode' value='squad-fpp' class='btn'>
</form><br>";
<?php if ($selected_player && $stats): ?>
<h2><?php echo htmlspecialchars(ucfirst($selected_mode)); ?> Lifetime Stats for <?php echo htmlspecialchars($selected_player); ?></h2>
<table border="1">
<thead>
<tr><th>Stat Name</th><th>Value</th></tr>
</thead>
<tbody>
<?php foreach ($stats as $stat_name => $stat_value): ?>
<tr>
<td><?php echo htmlspecialchars($stat_name); ?></td>
<td><?php echo htmlspecialchars(is_scalar($stat_value) ? $stat_value : json_encode($stat_value)); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<br>
<?php elseif (!$dataError): // Only show if no major data error occurred ?>
<p>Select a player to view their stats for the <?php echo htmlspecialchars($selected_mode); ?> mode.</p>
<?php endif; ?>
// Buttons for each player
echo "<form method='get' action=''>";
foreach ($players_data[$selected_mode] as $player_name => $player_details) {
echo "<button type='submit' name='selected_player' value='$player_name' class='btn' >$player_name</button>";
}
echo "<input type='hidden' name='game_mode' value='$selected_mode'>";
echo "</form><br>";
<p>Last update: <?php echo $lastUpdated; ?></p>
$selected_player = $_GET['selected_player'] ?? array_key_first($players_data[$selected_mode]);
// Fetch the player stats based on game mode and selected player
if (isset($players_data[$selected_mode][$selected_player])) {
$account_id = array_key_first($players_data[$selected_mode][$selected_player]);
$stats = $players_data[$selected_mode][$selected_player][$account_id];
echo "<h2>" . ucfirst($selected_mode) . " Lifetime Stats for $selected_player</h2>";
echo "<table border='1'>";
echo "<tr><th>Stat Name</th><th>Value</th></tr>";
foreach ($stats as $stat_name => $stat_value) {
echo "<tr><td>$stat_name</td><td>$stat_value</td></tr>";
}
echo "</table><br>";
} else {
echo "No player data available.";
}
echo "Last update " ;
echo $players_data['updated'];
?>
</section>
</main>