2024-11-26 23:37:16 -05:00
|
|
|
<?php
|
|
|
|
require("../libs/page.php");
|
2024-12-06 08:26:03 -05:00
|
|
|
require("../libs/form.php");
|
|
|
|
require("../libs/comment.php");
|
|
|
|
|
2024-12-02 07:59:45 -05:00
|
|
|
$roles = array();
|
|
|
|
|
2024-11-26 23:37:16 -05:00
|
|
|
page_header();
|
|
|
|
|
|
|
|
// this is a mess
|
|
|
|
function get_handler() {
|
|
|
|
global $db;
|
|
|
|
global $username;
|
|
|
|
global $user;
|
|
|
|
global $bio;
|
|
|
|
global $followers;
|
|
|
|
global $following;
|
2024-12-02 07:59:45 -05:00
|
|
|
global $roles;
|
2024-11-26 23:37:16 -05:00
|
|
|
|
|
|
|
// there is 100% a better way to do this but i need to test
|
|
|
|
if (!array_key_exists('id',$_GET)) {
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = $_GET['id'];
|
|
|
|
|
|
|
|
if (array_key_exists('type',$_GET)) {
|
2024-12-02 07:59:45 -05:00
|
|
|
$type = $_GET['type'];
|
2024-11-26 23:37:16 -05:00
|
|
|
if ($type == 'follow') {
|
|
|
|
follow();
|
|
|
|
} else if ($type == 'settings') {
|
|
|
|
settings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$stmt = $db->prepare("SELECT * FROM main.user WHERE UPPER(username) LIKE UPPER(?)"); //weirdly, this requires a schema name
|
|
|
|
$stmt->execute([$user]);
|
|
|
|
|
|
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$bio = isset($result) ? $result['bio'] : 'This user has not set a bio.';
|
|
|
|
|
2024-12-02 07:59:45 -05:00
|
|
|
$stmt = $db->prepare("SELECT * FROM main.follow WHERE target = ?");
|
2024-11-26 23:37:16 -05:00
|
|
|
$stmt->execute([$user]);
|
|
|
|
|
|
|
|
$following = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
|
|
|
|
2024-12-02 07:59:45 -05:00
|
|
|
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ?");
|
2024-11-26 23:37:16 -05:00
|
|
|
$stmt->execute([$user]);
|
|
|
|
|
|
|
|
$followers = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
|
|
|
|
2024-12-02 07:59:45 -05:00
|
|
|
$stmt = $db->prepare("SELECT * FROM main.role WHERE username = ?");
|
|
|
|
$stmt->execute([$user]);
|
|
|
|
|
|
|
|
$roles = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
2024-11-26 23:37:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function follow() {
|
|
|
|
global $db;
|
|
|
|
global $username;
|
|
|
|
global $user;
|
|
|
|
|
|
|
|
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ? AND target = ?");
|
|
|
|
$stmt->execute([$user,$username]);
|
|
|
|
|
|
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
if (is_null($username)) return;
|
|
|
|
|
|
|
|
if ($result) {
|
|
|
|
$stmt = $db->prepare("DELETE FROM main.follow WHERE username = ? AND target = ?");
|
|
|
|
$stmt->execute([$user,$username]);
|
|
|
|
} else {
|
|
|
|
$stmt = $db->prepare("INSERT INTO main.follow (username,target) VALUES (?,?)");
|
|
|
|
$stmt->execute([$user,$username]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function settings() {
|
|
|
|
global $db;
|
|
|
|
global $username;
|
|
|
|
global $user;
|
|
|
|
|
|
|
|
if (is_null($username)) return;
|
|
|
|
|
|
|
|
$stmt = $db->prepare("DELETE FROM main.user WHERE username = ?");
|
|
|
|
$stmt->execute([$username]);
|
|
|
|
|
|
|
|
$stmt = $db->prepare("INSERT INTO main.user (username,bio) VALUES (?,?)");
|
|
|
|
$stmt->execute([$username,$_POST['desc']]);
|
|
|
|
|
|
|
|
move_uploaded_file($_FILES['avatar']['tmp_name'], $_SERVER["DOCUMENT_ROOT"] . '/../docs/pfp/' . $username . '.png');
|
|
|
|
}
|
|
|
|
|
|
|
|
get_handler();
|
|
|
|
?>
|
|
|
|
<form class="banner" enctype="multipart/form-data" method="POST" action="/user.php?id=<?php echo $user ?>&type=follow">
|
2024-11-29 17:15:08 -05:00
|
|
|
<img class="banner-background" src="/pfp/<?php echo $user ?>.png">
|
2024-11-26 23:37:16 -05:00
|
|
|
<div class="banner-content">
|
|
|
|
<div class="form-message"></div>
|
|
|
|
<div class="avatar">
|
2024-11-29 17:15:08 -05:00
|
|
|
<img src="/pfp/<?php echo $user ?>.png" class="avatar-img">
|
|
|
|
<b>@<?php echo $user ?></b>
|
2024-12-02 07:59:45 -05:00
|
|
|
<?php foreach ($roles as $role) { ?>
|
|
|
|
[<?php echo htmlspecialchars($role['role']); ?>]
|
|
|
|
<?php } ?>
|
2024-11-26 23:37:16 -05:00
|
|
|
<input class="form-button" type="submit" value="Follow">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="avatar">
|
|
|
|
<b><?php echo count($followers) ?> followers</b>
|
|
|
|
<b><?php echo count($following) ?> following</b>
|
|
|
|
</div>
|
2024-11-29 17:15:08 -05:00
|
|
|
<input name="target" hidden="" value="<?php echo $user ?>">
|
2024-11-26 23:37:16 -05:00
|
|
|
|
|
|
|
<pre><?php echo htmlspecialchars($bio) ?></pre>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
<?php
|
|
|
|
if ($user == $username) {
|
|
|
|
form("Your Settings", $form_message, array(
|
|
|
|
array('key' => 'Bio', 'type' => 'textarea', 'name' => 'desc', 'default' => $bio),
|
|
|
|
array('key' => 'Avatar', 'type' => 'file', 'name' => 'avatar', 'default' => '')
|
|
|
|
),'/user.php?id=' . $user . '&type=settings');
|
|
|
|
}
|
|
|
|
|
2024-12-06 08:26:03 -05:00
|
|
|
comments('user',$user);
|
|
|
|
|
2024-11-26 23:37:16 -05:00
|
|
|
page_footer();
|
2024-12-06 08:26:03 -05:00
|
|
|
?>
|