36205-vm/profile.php
Flatlogic Bot 66352476cd 1
2025-11-24 13:37:24 +00:00

164 lines
7.6 KiB
PHP

<?php
$handle = htmlspecialchars($_GET['handle'] ?? 'N/A');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Profile: <?php echo $handle; ?> - CodeScore</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #f8f9fa;
}
.navbar {
box-shadow: 0 2px 4px rgba(0,0,0,.05);
}
.stat-card {
border-left: 4px solid #0d6efd;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top">
<div class="container">
<a class="navbar-brand fw-bold" href="index.php">CodeScore</a>
<a href="index.php" class="btn btn-outline-primary">Back to Search</a>
</div>
</nav>
<main class="container py-5">
<?php
require_once 'includes/scraper.php';
$profileData = getLeetCodeProfile($handle);
if (isset($profileData['error'])):
?>
<div class="alert alert-danger">
<strong>Error:</strong> <?php echo htmlspecialchars($profileData['error']); ?>
<p>Please check the handle and try again. Note that the LeetCode API might be temporarily unavailable.</p>
</div>
<?php else:
// Process data
$totalSolved = 0;
$easySolved = 0;
$mediumSolved = 0;
$hardSolved = 0;
if (isset($profileData['submitStats']['acSubmissionNum'])) {
foreach ($profileData['submitStats']['acSubmissionNum'] as $stat) {
if ($stat['difficulty'] == 'All') {
$totalSolved = $stat['count'];
} else if ($stat['difficulty'] == 'Easy') {
$easySolved = $stat['count'];
} else if ($stat['difficulty'] == 'Medium') {
$mediumSolved = $stat['count'];
} else if ($stat['difficulty'] == 'Hard') {
$hardSolved = $stat['count'];
}
}
}
?>
<div class="p-4 p-md-5 mb-4 rounded text-bg-dark d-flex align-items-center">
<?php if (!empty($profileData['profile']['userAvatar'])): ?>
<img src="<?php echo htmlspecialchars($profileData['profile']['userAvatar']); ?>" alt="User Avatar" class="rounded-circle me-4" width="80" height="80">
<?php endif; ?>
<div>
<h1 class="display-4 fst-italic"><?php echo htmlspecialchars($profileData['profile']['realName']); ?></h1>
<p class="lead my-1">@<?php echo htmlspecialchars($profileData['username']); ?> on LeetCode</p>
</div>
</div>
<div class="row g-4 mb-4">
<div class="col-md-4">
<div class="card stat-card shadow-sm h-100">
<div class="card-body">
<h5 class="card-title text-primary">Contest Rating</h5>
<p class="card-text display-4 fw-bold"><?php echo number_format($profileData['profile']['ranking']); ?></p>
<small class="text-muted">Global Rank</small>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card stat-card shadow-sm h-100" style="border-left-color: #198754;">
<div class="card-body">
<h5 class="card-title text-success">Problems Solved</h5>
<p class="card-text display-4 fw-bold"><?php echo $totalSolved; ?></p>
<small class="text-muted"><?php echo "$easySolved Easy, $mediumSolved Medium, $hardSolved Hard"; ?></small>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card stat-card shadow-sm h-100" style="border-left-color: #ffc107;">
<div class="card-body">
<h5 class="card-title text-warning">Recent Activity</h5>
<p class="card-text display-4 fw-bold"><?php echo count($profileData['recentAcSubmissionList']); ?></p>
<small class="text-muted">Accepted submissions in last 20 entries</small>
</div>
</div>
</div>
</div>
<div class="row g-4">
<div class="col-lg-6">
<div class="card shadow-sm h-100">
<div class="card-header">
<h4 class="my-0 fw-normal">Recent Submissions</h4>
</div>
<ul class="list-group list-group-flush">
<?php if (!empty($profileData['recentAcSubmissionList'])): ?>
<?php foreach (array_slice($profileData['recentAcSubmissionList'], 0, 5) as $submission): ?>
<li class="list-group-item d-flex justify-content-between align-items-center">
<a href="https://leetcode.com/problems/<?php echo $submission['titleSlug']; ?>" target="_blank" rel="noopener noreferrer">
<?php echo htmlspecialchars($submission['title']); ?>
</a>
<small class="text-muted"><?php echo date('M d, Y', $submission['timestamp']); ?></small>
</li>
<?php endforeach; ?>
<?php else: ?>
<li class="list-group-item">No recent submissions found.</li>
<?php endif; ?>
</ul>
</div>
</div>
<div class="col-lg-6">
<div class="card shadow-sm h-100">
<div class="card-header">
<h4 class="my-0 fw-normal">Languages</h4>
</div>
<div class="card-body">
<?php
if (!empty($profileData['languageProblemCount'])) {
usort($profileData['languageProblemCount'], function($a, $b) {
return $b['problemsSolved'] <=> $a['problemsSolved'];
});
foreach ($profileData['languageProblemCount'] as $lang) {
echo '<span class="badge bg-secondary m-1 p-2">'
. htmlspecialchars($lang['languageName'])
. ' <span class="badge bg-light text-dark ms-1">' . $lang['problemsSolved'] . '</span></span>';
}
} else {
echo '<p>No language stats found.</p>';
}
?>
</div>
</div>
</div>
</div>
<?php endif; ?>
</main>
<footer class="text-center py-4 text-muted">
<div class="container">
<p>&copy; <?php echo date("Y"); ?> CodeScore. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>