id/profile.php

91 lines
2.3 KiB
PHP
Raw Normal View History

2023-11-19 12:24:38 +00:00
<link rel="stylesheet" href="/styles/profiles.css" />
2023-11-19 12:24:38 +00:00
<?php
if (!$_SESSION['auth']) {
header('Location: /signin?callback=/profile');
exit();
2023-11-19 12:24:38 +00:00
}
$profile = db_execute("SELECT * FROM `profiles` WHERE id = ? LIMIT 1", [$user['id']]);
if (empty($profile)) {
$profile = [
2024-02-20 19:49:42 +00:00
"id" => "9999999",
2023-11-19 12:24:38 +00:00
"public_display_name" => false,
"public_avatar" => false,
"description" => null,
];
}
2024-03-02 12:41:57 +00:00
$avatar = "/assets/default.png";
2023-11-19 12:24:38 +00:00
$display_name = "";
if ($_SESSION['id'] != $profile['id']) {
2024-03-02 12:41:57 +00:00
$avatar = get_avatar_url($profile['id']);
2023-11-19 12:24:38 +00:00
if ($profile['public_display_name']) {
$display_name = get_display_name($profile['id'], false);
}
} else {
$avatar = get_avatar_url($profile['id']);
$display_name = get_display_name($profile['id'], false);
}
2024-03-02 12:41:57 +00:00
// Get badges owned by this person
$badges = db_execute_all('SELECT * FROM badge_owners INNER JOIN badges b on badge_owners.badge_id = b.id; ', []);
if (!empty($badges)) {
if (!array_is_list($badges)) {
$badges = array (0 => $badges);
}
}
2023-11-19 12:24:38 +00:00
?>
<div id="profile">
<img src="<?= $avatar ?>" class="avatar" alt="Avatar">
<div class="info">
2024-03-02 12:41:57 +00:00
<div class="displayname"><?= htmlspecialchars($display_name) ?></div>
2023-11-19 12:36:49 +00:00
<div class="bcid"><?= format_bcid( $profile['id'] ); ?></div>
2023-11-19 12:24:38 +00:00
</div>
</div>
<div id="details">
<div id="badges">
<h2>Badges</h2>
2024-03-02 12:41:57 +00:00
<?php
if (empty($badges)) {
echo '<p>This profile has no badges :(</p>';
} else {
foreach ($badges as $badge) {
echo "<div class='badge'>
<img src='". $badge['image'] ."' alt='". htmlspecialchars($badge['title']) ."' />
<div class='details'>
<span class='title'>" . htmlspecialchars($badge['title']) . "</span>
<p>". htmlspecialchars($badge['description']) ."</p>
<p class='subtitle'>". htmlspecialchars($badge['description']) ."</p>
<p class='earned subtitle'>Earned " . $badge['earned'] . "</p>
</div>
</div>";
}
}
?>
2023-11-19 12:24:38 +00:00
</div>
<div id="info">
<h2>Info</h2>
<table>
<tr>
<th>Joined</th>
<td><?= $user['created_date'] ?></td>
</tr>
2024-03-02 12:41:57 +00:00
<tr>
<th>Badges earned</th>
<td><?= count($badges) ?></td>
</tr>
2023-11-19 12:24:38 +00:00
</table>
</div>
</div>