minor fixes

This commit is contained in:
biglyderv 2025-02-05 01:27:45 -05:00
parent daace699a6
commit 2ce4424db7
20 changed files with 674 additions and 621 deletions

View file

@ -1,9 +1,11 @@
<?php <?php
require(__DIR__ . "/../../libs/page.php"); require(__DIR__ . "/../../libs/page.php");
$ref = 1732684297; $ref = 1732684297;
function getOut($typer, $idr) { function getOut($typer, $idr)
{
if ($typer == 'user' || $typer == 'comment') { if ($typer == 'user' || $typer == 'comment') {
header("Location: " . '/' . $typer . '.php?id=' . htmlspecialchars($idr)); header("Location: " . '/' . $typer . '.php?id=' . htmlspecialchars($idr));
die(); die();
@ -13,11 +15,14 @@
die(); die();
} }
function post_handler() { function post_handler()
{
global $ref; global $ref;
global $username; global $username;
global $db; global $db;
if (!$username || !array_key_exists('post',$_POST)) return; if (!$username || !array_key_exists('post', $_POST)) {
return;
}
$postie = $_POST['post']; $postie = $_POST['post'];
$postType = (array_key_exists('type', $_POST)) ? $_POST['type'] : 'root'; $postType = (array_key_exists('type', $_POST)) ? $_POST['type'] : 'root';
@ -85,4 +90,3 @@
} }
post_handler(); post_handler();
?>

View file

@ -1,7 +1,9 @@
<?php <?php
require(__DIR__ . "/../../libs/page.php"); require(__DIR__ . "/../../libs/page.php");
function get_handler() { function get_handler()
{
global $db; global $db;
$stmt = $db->prepare("SELECT * FROM main.follow"); $stmt = $db->prepare("SELECT * FROM main.follow");
@ -13,4 +15,3 @@
} }
get_handler(); get_handler();
?>

View file

@ -1,4 +1,5 @@
<?php <?php
require(__DIR__ . "/../libs/page.php"); require(__DIR__ . "/../libs/page.php");
require(__DIR__ . "/../libs/form.php"); require(__DIR__ . "/../libs/form.php");
require(__DIR__ . "/../libs/comment.php"); require(__DIR__ . "/../libs/comment.php");
@ -8,4 +9,3 @@
page_header(); page_header();
comments("comment", $_GET['id']); comments("comment", $_GET['id']);
page_footer(); page_footer();
?>

View file

@ -134,6 +134,7 @@ pre {
padding: 10px; padding: 10px;
margin-bottom: 10px; margin-bottom: 10px;
align-items: center; align-items: center;
flex-wrap: wrap;
width: var(--elem-width); width: var(--elem-width);
border-radius: var(--border-radius); border-radius: var(--border-radius);
} }
@ -186,6 +187,10 @@ iframe {
border: none; border: none;
} }
.header a {
width: 60px;
}
.header a, .clickie { .header a, .clickie {
text-decoration: none; text-decoration: none;
color: inherit; color: inherit;

View file

@ -17,8 +17,6 @@
<h2>Community</h2> <h2>Community</h2>
<a class="form-button" href="/tou.php">Terms of Use</a> <a class="form-button" href="/tou.php">Terms of Use</a>
<a class="form-button" href="/stats.php?ref=<?php echo $username ?>">Suggested Users</a>
<a class="form-button" href="/stats.php">Top Users</a>
<a class="form-button" href="https://dervland.net/">More Projects</a> <a class="form-button" href="https://dervland.net/">More Projects</a>
</div> </div>
</div> </div>

View file

@ -1,8 +1,10 @@
<?php <?php
require(__DIR__ . "/../libs/page.php"); require(__DIR__ . "/../libs/page.php");
require(__DIR__ . "/../libs/form.php"); require(__DIR__ . "/../libs/form.php");
function post_handler() { function post_handler()
{
global $db; global $db;
// there is 100% a better way to do this but i need to test // there is 100% a better way to do this but i need to test
@ -18,11 +20,15 @@
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result) return 'Username does not exist.'; if (!$result) {
return 'Username does not exist.';
}
$verified = password_verify($pass, $result['password']); $verified = password_verify($pass, $result['password']);
if (!$verified) return 'Password is wrong.'; if (!$verified) {
return 'Password is wrong.';
}
$token = bin2hex(random_bytes(32)); $token = bin2hex(random_bytes(32));
@ -52,4 +58,3 @@
)); ));
page_footer(); page_footer();
?>

View file

@ -1,13 +1,12 @@
<?php <?php
require(__DIR__ . "/../libs/page.php"); require(__DIR__ . "/../libs/page.php");
page_header(); page_header();
if (isset($_COOKIE)) { if (isset($_COOKIE)) {
foreach ( $_COOKIE as $key => $value ) foreach ($_COOKIE as $key => $value) {
{ setcookie($key, false);
setcookie( $key, FALSE );
} }
header("Location: /"); header("Location: /");
die(); die();
} }
page_footer(); page_footer();
?>

View file

@ -8,7 +8,8 @@
page_header(); page_header();
// this is a mess // this is a mess
function get_handler() { function get_handler()
{
global $db; global $db;
global $username; global $username;
global $user; global $user;
@ -55,7 +56,8 @@
<h2>Following</h2> <h2>Following</h2>
<?php <?php
foreach ($following as $user) { $usern = $user['username']; ?> foreach ($following as $user) {
$usern = $user['username']; ?>
<div class='comment'> <div class='comment'>
<div class="avatar"> <div class="avatar">
<img src="/pfp/<?php echo $usern ?>.png" class="avatar-img"> <img src="/pfp/<?php echo $usern ?>.png" class="avatar-img">
@ -76,7 +78,8 @@
<h2>Followers</h2> <h2>Followers</h2>
<?php <?php
foreach ($followers as $user) { $usern = $user['target']; ?> foreach ($followers as $user) {
$usern = $user['target']; ?>
<div class='comment'> <div class='comment'>
<div class="avatar"> <div class="avatar">
<img src="/pfp/<?php echo $usern ?>.png" class="avatar-img"> <img src="/pfp/<?php echo $usern ?>.png" class="avatar-img">

View file

@ -1,4 +1,5 @@
<?php <?php
require(__DIR__ . "/../libs/page.php"); require(__DIR__ . "/../libs/page.php");
require(__DIR__ . "/../libs/form.php"); require(__DIR__ . "/../libs/form.php");
require(__DIR__ . "/../libs/comment.php"); require(__DIR__ . "/../libs/comment.php");
@ -8,4 +9,3 @@
page_header(); page_header();
comments("notification", $username, true); comments("notification", $username, true);
page_footer(); page_footer();
?>

View file

@ -1,8 +1,10 @@
<?php <?php
require(__DIR__ . "/../libs/page.php"); require(__DIR__ . "/../libs/page.php");
require(__DIR__ . "/../libs/form.php"); require(__DIR__ . "/../libs/form.php");
function post_handler() { function post_handler()
{
global $db; global $db;
// there is 100% a better way to do this but i need to test // there is 100% a better way to do this but i need to test
@ -33,7 +35,9 @@
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result) return 'Username is taken.'; if ($result) {
return 'Username is taken.';
}
$hashed = password_hash($pass, PASSWORD_DEFAULT); $hashed = password_hash($pass, PASSWORD_DEFAULT);
@ -55,4 +59,3 @@
)); ));
page_footer(); page_footer();
?>

View file

@ -3,7 +3,8 @@
require(__DIR__ . "/../libs/form.php"); require(__DIR__ . "/../libs/form.php");
require(__DIR__ . "/../libs/comment.php"); require(__DIR__ . "/../libs/comment.php");
function cmp($a, $b) { function cmp($a, $b)
{
if ($a == $b) { if ($a == $b) {
return 0; return 0;
} }
@ -11,8 +12,17 @@
} }
page_header(); page_header();
?>
function get_handler() { <div>
<a class="form-button" href="?username=<?php echo $username ?>">Local</a>
<a class="form-button" href="?">Global</a>
</div>
<?php
function get_handler()
{
$api = file_get_contents("https://nbg.dervland.net/node/top?ref=" . $_GET['ref']); $api = file_get_contents("https://nbg.dervland.net/node/top?ref=" . $_GET['ref']);
$pr = json_decode($api); $pr = json_decode($api);

View file

@ -8,7 +8,8 @@
page_header(); page_header();
// this is a mess // this is a mess
function get_handler() { function get_handler()
{
global $db; global $db;
global $username; global $username;
global $user; global $user;
@ -56,7 +57,8 @@
$roles = $stmt->fetchAll(PDO::FETCH_DEFAULT); $roles = $stmt->fetchAll(PDO::FETCH_DEFAULT);
} }
function follow() { function follow()
{
global $db; global $db;
global $username; global $username;
global $user; global $user;
@ -66,7 +68,9 @@
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
if (is_null($username)) return; if (is_null($username)) {
return;
}
if ($result) { if ($result) {
$stmt = $db->prepare("DELETE FROM main.follow WHERE username = ? AND target = ?"); $stmt = $db->prepare("DELETE FROM main.follow WHERE username = ? AND target = ?");
@ -76,12 +80,15 @@
$stmt->execute([$user,$username]); $stmt->execute([$user,$username]);
} }
} }
function settings() { function settings()
{
global $db; global $db;
global $username; global $username;
global $user; global $user;
if (is_null($username)) return; if (is_null($username)) {
return;
}
$stmt = $db->prepare("DELETE FROM main.user WHERE username = ?"); $stmt = $db->prepare("DELETE FROM main.user WHERE username = ?");
$stmt->execute([$username]); $stmt->execute([$username]);

View file

@ -1,8 +1,11 @@
<?php <?php
require(__DIR__ . "/test_secret.php"); require(__DIR__ . "/test_secret.php");
function auth($token) { function auth($token)
if (is_null($token)) return null; {
if (is_null($token)) {
return null;
}
global $db; global $db;
@ -10,7 +13,9 @@
$stmt->execute([$token]); $stmt->execute([$token]);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result) return null; if (!$result) {
return null;
}
$username = $result['username']; $username = $result['username'];
@ -18,13 +23,17 @@
$stmt->execute([$username]); $stmt->execute([$username]);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result) return null; if (!$result) {
return null;
}
$stmt = $db->prepare("SELECT * FROM main.ban WHERE username = ?"); $stmt = $db->prepare("SELECT * FROM main.ban WHERE username = ?");
$stmt->execute([$username]); $stmt->execute([$username]);
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result) return $username; if (!$result) {
return $username;
}
$reason = $result['reason']; ?> $reason = $result['reason']; ?>
<!DOCTYPE html> <!DOCTYPE html>

View file

@ -1,6 +1,7 @@
<?php <?php
require(__DIR__ . "/markdown.php"); require(__DIR__ . "/markdown.php");
function comments($typer, $idr, $disable = false) { function comments($typer, $idr, $disable = false)
{
$ref = 1732684297; $ref = 1732684297;
global $username; global $username;
global $db; global $db;
@ -17,7 +18,9 @@
$qs = parse_url($_SERVER['REQUEST_URI']); $qs = parse_url($_SERVER['REQUEST_URI']);
if (is_null($qs)) $qs = array('query' => '?'); if (is_null($qs)) {
$qs = array('query' => '?');
}
$qsq = $qs['query']; $qsq = $qs['query'];
$qss = array(); $qss = array();
@ -37,6 +40,10 @@
$qs_2 = http_build_query($qss); $qs_2 = http_build_query($qss);
?> ?>
<div>
<a class="form-button" href="?<?php echo $qs_1 ?>">Everyone</a>
<a class="form-button" href="?<?php echo $qs_2 ?>">Following</a>
</div>
<div> <div>
<?php if ($page > 0) { ?> <?php if ($page > 0) { ?>
<a class="form-button" href="?<?php echo $qs_prev ?>">Previous</a> <a class="form-button" href="?<?php echo $qs_prev ?>">Previous</a>
@ -44,10 +51,6 @@
<a class="form-button" href="?<?php echo $qs_next ?>">Next</a> <a class="form-button" href="?<?php echo $qs_next ?>">Next</a>
</div> </div>
<div>
<a class="form-button" href="?<?php echo $qs_1 ?>">Everyone</a>
<a class="form-button" href="?<?php echo $qs_2 ?>">Following</a>
</div>
<?php <?php
$posts = array(); $posts = array();
@ -60,7 +63,9 @@
$theId $theId
]); ]);
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT); $posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
if (is_null($posts1) || count($posts1) < 1) break; if (is_null($posts1) || count($posts1) < 1) {
break;
}
$theId = $posts1[0]['targetid']; $theId = $posts1[0]['targetid'];
$posts = array_merge($posts1, $posts); $posts = array_merge($posts1, $posts);
} }

View file

@ -1,5 +1,6 @@
<?php <?php
function form($title, $form_message, $inputs, $action = '') { ?> function form($title, $form_message, $inputs, $action = '')
{ ?>
<form class='form' enctype="multipart/form-data" method="POST" action="<?php echo $action ?>"> <form class='form' enctype="multipart/form-data" method="POST" action="<?php echo $action ?>">
<h1 class="form-heading"> <h1 class="form-heading">
<?php echo $title ?> <?php echo $title ?>

View file

@ -1,5 +1,6 @@
<?php <?php
function markdown($text) { function markdown($text)
{
$search = array( $search = array(
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(png|jpg|jpeg|gif))~i', '~(https://[^.]+\.dervland\.net/[^\s<]+\.(png|jpg|jpeg|gif))~i',
'~(https://[^.]+\.dervland\.net/[^\s<]+\.(mp3|wav))~i', '~(https://[^.]+\.dervland\.net/[^\s<]+\.(mp3|wav))~i',

View file

@ -1,7 +1,8 @@
<?php <?php
require(__DIR__ . "/auth.php"); require(__DIR__ . "/auth.php");
global $username; global $username;
function page_header() { function page_header()
{
global $db; global $db;
global $username; global $username;
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC"); $stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC");
@ -11,7 +12,6 @@
]); ]);
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT); $posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
$edge = count($posts2); $edge = count($posts2);
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -25,18 +25,20 @@
<body> <body>
<div class="header"> <div class="header">
<a href="/"><img class="header-img header-link" src="/img/bgc.svg">BiglyChat</a> <a href="/"><img class="header-img header-link" src="/img/bgc.svg">BiglyChat</a>
<?php <?php if (isset($username)) { ?>
if (isset($username)) { ?> <a href="/user.php?id=<?php echo $username ?>"><img class="header-img header-link" src="/pfp/<?php echo $username ?>.png">Wall</a>
<a href="/user.php?id=<?php echo $username ?>"><img class="header-img header-link" src="/img/home.svg">Home</a>
<a href="/notif.php"> <img class="header-img header-link" src="/img/mail.svg"><span>Mail<sub> <?php echo $edge?></sub></span></a> <a href="/notif.php"> <img class="header-img header-link" src="/img/mail.svg"><span>Mail<sub> <?php echo $edge?></sub></span></a>
<a href="/stats.php?username=<?php echo $username ?>"><img class="header-img header-link" src="/img/home.svg">Users</a>
<a href="/logout.php"><img class="header-img header-link" src="/img/logout.svg">Leave</a> <a href="/logout.php"><img class="header-img header-link" src="/img/logout.svg">Leave</a>
<?php } else { ?> <?php } else { ?>
<a href="/login.php"><img class="header-img header-link" src="/img/home.svg">Join</a> <a href="/login.php"><img class="header-img header-link" src="/img/home.svg">Join</a>
<a href="/stats.php"><img class="header-img header-link" src="/img/home.svg">Users</a>
<?php } <?php }
?> ?>
</div> </div>
<?php } <?php }
function page_footer() { ?> function page_footer()
{ ?>
</body> </body>
</html> </html>
<?php } <?php }

View file

@ -1,4 +1,5 @@
<?php <?php
require(__DIR__ . "/../libs/test_secret.php"); require(__DIR__ . "/../libs/test_secret.php");
global $db; global $db;
@ -8,4 +9,3 @@
$db->exec($sql); $db->exec($sql);
echo "Database was set up."; echo "Database was set up.";
?>