new-bigly-chat/docs/index.php

79 lines
2.6 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;
2024-11-30 17:20:46 -05:00
2024-11-27 00:13:33 -05:00
$postie = $_POST['post'];
2024-11-30 17:20:46 -05:00
if (strlen($postie) < 1 || strlen($postie) > 1024) {
return 'Post is too long or short.';
}
2024-11-27 00:13:33 -05:00
$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-30 17:20:46 -05:00
header("Location: " . $_SERVER["REQUEST_URI"]);
die();
2024-11-27 00:13:33 -05:00
}
2024-11-26 11:38:28 -05:00
2024-11-27 00:13:33 -05:00
page_header();
$form_message = post_handler();
2024-11-30 04:48:58 -05:00
?>
<div class="banner"><img class="banner-background" src="/img/newlogo.svg">
<div class="banner-content">
<h1>BiglyChat</h1>
2024-11-30 04:52:01 -05:00
<pre>BiglyChat is a niche community for weird Dervland experiments and games.</pre>
2024-11-30 04:48:58 -05:00
<h2>Community</h2>
<a class="form-button" href="/register.php">Join the Community</a>
<br>
<a class="form-button" href="/tou.php">Terms of Use</a>
<a class="form-button" href="https://dervland.net/">More Projects</a>
<a class="form-button" href="https://git.dervland.net/biglyderv/new-bigly-chat">Developer Portal</a>
</div>
</div>
2024-11-30 04:52:01 -05:00
<?php
if ($username) {
form("Broadcast your thoughts...", $form_message, array(
array('key' => 'Your message', 'type' => 'textarea', 'name' => 'post', 'default' => '')
));
}
$stmt = $db->prepare("SELECT * FROM comment ORDER BY date DESC");
$stmt->execute([]);
$posts = $stmt->fetchAll(PDO::FETCH_DEFAULT);
2024-11-30 04:48:58 -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();
?>