new-bigly-chat/docs/index.php

52 lines
1.7 KiB
PHP
Raw Normal View History

2024-11-26 11:38:28 -05:00
<?php
require("../libs/page.php");
2024-11-27 00:13:33 -05:00
require("../libs/form.php");
$ref = 1732684297;
function post_handler() {
global $ref;
global $username;
global $db;
if (!$username) return;
if (!array_key_exists('post',$_POST)) return;
$postie = $_POST['post'];
$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))]);
}
2024-11-26 11:38:28 -05:00
2024-11-27 00:13:33 -05:00
page_header();
$form_message = post_handler();
if ($username) {
form("Broadcast your thoughts...", $form_message, array(
2024-11-27 16:53:42 -05:00
array('key' => 'Your message', 'type' => 'textarea', 'name' => 'post', 'default' => '')
2024-11-27 00:13:33 -05:00
));
}
$stmt = $db->prepare("SELECT * FROM comment ORDER BY date DESC");
$stmt->execute([]);
$posts = $stmt->fetchAll(PDO::FETCH_DEFAULT);
2024-11-26 11:38:28 -05:00
2024-11-27 00:13:33 -05:00
foreach ($posts as $post) { ?>
<div class='comment'>
<div class='avatar'>
<img src='/pfp/<?php echo $post['username'] ?>.png' class='avatar-img'>
<div>
<div><b>
2024-11-27 16:53:42 -05:00
<a class='link' href='/user.php?id=<?php echo $post['username'] ?>'>
2024-11-27 00:13:33 -05:00
<?php echo $post['username'] ?>
</a>
</b></div>
<div><b>
<?php echo date(DATE_ATOM,$post['date'] + $ref) ?>
</b></div>
</div>
</div>
2024-11-27 16:53:42 -05:00
<pre><?php echo htmlspecialchars($post['content']) ?></pre>
2024-11-27 00:13:33 -05:00
</div>
<?php }
2024-11-26 11:38:28 -05:00
page_footer();
?>