user walls

This commit is contained in:
biglyderv 2024-12-06 08:26:03 -05:00
parent 4734ee5d6d
commit 8abdde750c
5 changed files with 101 additions and 75 deletions

View file

@ -1,35 +1,44 @@
<?php
require("../libs/page.php");
require("../libs/form.php");
require("../libs/markdown.php");
require("../libs/comment.php");
$ref = 1732684297;
function getOut($typer, $idr) {
if ($typer == 'user') {
header("Location: " . '/user.php?id=' . htmlspecialchars($idr));
die();
}
header("Location: " . $_SERVER["REQUEST_URI"]);
die();
}
function post_handler() {
global $ref;
global $username;
global $db;
if (!$username) return;
if (!$username) getOut('root','root');
if (!array_key_exists('post',$_POST)) return;
$postie = $_POST['post'];
$postType = (array_key_exists('type',$_POST)) ? $_POST['type'] : 'root';
$postId = (array_key_exists('id',$_POST)) ? $_POST['id'] : 'root';
if (strlen($postie) < 1 || strlen($postie) > 1024) {
return 'Post is too long or short.';
}
getOut($postType,$postId);
}
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
$stmt->execute([$username,"root","root",microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
header("Location: " . $_SERVER["REQUEST_URI"]);
die();
}
$stmt->execute([$username,$postType,$postId,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
getOut($postType,$postId);
}
post_handler();
page_header();
$form_message = post_handler();
$page = array_key_exists('page',$_GET) ? ($_GET['page']) : 0;
?>
<div class="banner"><img class="banner-background" src="/img/newlogo.svg">
@ -44,47 +53,7 @@
<a class="form-button" href="https://git.dervland.net/biglyderv/new-bigly-chat">Developer Portal</a>
</div>
</div>
<?php
if ($username) {
form("Broadcast your thoughts...", $form_message, array(
array('key' => 'Your message', 'type' => 'textarea', 'name' => 'post', 'default' => '')
));
}
?>
<div>
<?php if ($page > 0) { ?>
<a class="form-button" href="?page=<?php echo $page - 1 ?>">Previous</a>
<?php } ?>
<a class="form-button" href="?page=<?php echo $page + 1 ?>">Next</a>
</div>
<?php
$stmt = $db->prepare("SELECT * FROM comment ORDER BY date DESC LIMIT ? OFFSET ?");
$stmt->execute([
10,
$page * 10
]);
$posts = $stmt->fetchAll(PDO::FETCH_DEFAULT);
foreach ($posts as $post) { ?>
<div class='comment'>
<div class='avatar'>
<img src='/pfp/<?php echo $post['username'] ?>.png' class='avatar-img'>
<div>
<div><b>
<a class='link' href='/user.php?id=<?php echo $post['username'] ?>'>
<?php echo $post['username'] ?>
</a>
</b></div>
<div><b>
<?php echo date(DATE_ATOM,$post['date'] + $ref) ?>
</b></div>
</div>
</div>
<pre><?php echo markdown(htmlspecialchars($post['content'])) ?></pre>
</div>
<?php }
page_footer();
<?php
comments("root","root");
page_footer();
?>