minor fixes
This commit is contained in:
parent
daace699a6
commit
2ce4424db7
20 changed files with 674 additions and 621 deletions
193
docs/user.php
193
docs/user.php
|
@ -1,98 +1,105 @@
|
|||
<?php
|
||||
require(__DIR__ . "/../libs/page.php");
|
||||
require(__DIR__ . "/../libs/form.php");
|
||||
require(__DIR__ . "/../libs/comment.php");
|
||||
|
||||
$roles = array();
|
||||
|
||||
page_header();
|
||||
|
||||
// this is a mess
|
||||
function get_handler() {
|
||||
global $db;
|
||||
global $username;
|
||||
global $user;
|
||||
global $bio;
|
||||
global $followers;
|
||||
global $following;
|
||||
global $roles;
|
||||
|
||||
// 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)) {
|
||||
$type = $_GET['type'];
|
||||
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.';
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.follow WHERE target = ?");
|
||||
$stmt->execute([$user]);
|
||||
|
||||
$following = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ?");
|
||||
$stmt->execute([$user]);
|
||||
|
||||
$followers = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.role WHERE username = ?");
|
||||
$stmt->execute([$user]);
|
||||
|
||||
$roles = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
require(__DIR__ . "/../libs/page.php");
|
||||
require(__DIR__ . "/../libs/form.php");
|
||||
require(__DIR__ . "/../libs/comment.php");
|
||||
|
||||
$roles = array();
|
||||
|
||||
page_header();
|
||||
|
||||
// this is a mess
|
||||
function get_handler()
|
||||
{
|
||||
global $db;
|
||||
global $username;
|
||||
global $user;
|
||||
global $bio;
|
||||
global $followers;
|
||||
global $following;
|
||||
global $roles;
|
||||
|
||||
// there is 100% a better way to do this but i need to test
|
||||
if (!array_key_exists('id', $_GET)) {
|
||||
die();
|
||||
}
|
||||
|
||||
function follow() {
|
||||
global $db;
|
||||
global $username;
|
||||
global $user;
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ? AND target = ?");
|
||||
|
||||
$user = $_GET['id'];
|
||||
|
||||
if (array_key_exists('type', $_GET)) {
|
||||
$type = $_GET['type'];
|
||||
if ($type == 'follow') {
|
||||
follow();
|
||||
} elseif ($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.';
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.follow WHERE target = ?");
|
||||
$stmt->execute([$user]);
|
||||
|
||||
$following = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ?");
|
||||
$stmt->execute([$user]);
|
||||
|
||||
$followers = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
|
||||
$stmt = $db->prepare("SELECT * FROM main.role WHERE username = ?");
|
||||
$stmt->execute([$user]);
|
||||
|
||||
$roles = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
||||
}
|
||||
|
||||
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]);
|
||||
|
||||
$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');
|
||||
}
|
||||
function settings()
|
||||
{
|
||||
global $db;
|
||||
global $username;
|
||||
global $user;
|
||||
|
||||
if (is_null($username)) {
|
||||
return;
|
||||
}
|
||||
|
||||
get_handler();
|
||||
|
||||
$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">
|
||||
<img class="banner-background" src="/pfp/<?php echo $user ?>.png">
|
||||
|
@ -124,10 +131,10 @@
|
|||
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');
|
||||
), '/user.php?id=' . $user . '&type=settings');
|
||||
}
|
||||
|
||||
comments('user',$user);
|
||||
comments('user', $user);
|
||||
|
||||
page_footer();
|
||||
page_footer();
|
||||
?>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue