new-bigly-chat/docs/index.php

98 lines
3.3 KiB
PHP
Raw Permalink 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");
2024-12-06 08:26:03 -05:00
require("../libs/comment.php");
2024-11-27 00:13:33 -05:00
$ref = 1732684297;
2024-12-06 08:26:03 -05:00
function getOut($typer, $idr) {
2024-12-11 23:51:42 -05:00
if ($typer == 'user' || $typer == 'comment') {
header("Location: " . '/' . $typer . '.php?id=' . htmlspecialchars($idr));
2024-12-06 08:26:03 -05:00
die();
}
header("Location: " . $_SERVER["REQUEST_URI"]);
die();
}
2024-11-27 00:13:33 -05:00
function post_handler() {
global $ref;
global $username;
global $db;
2024-12-06 10:19:57 -05:00
if (!$username || !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-12-06 08:26:03 -05:00
$postType = (array_key_exists('type',$_POST)) ? $_POST['type'] : 'root';
$postId = (array_key_exists('id',$_POST)) ? $_POST['id'] : 'root';
2024-11-30 17:20:46 -05:00
if (strlen($postie) < 1 || strlen($postie) > 1024) {
2024-12-06 08:26:03 -05:00
getOut($postType,$postId);
}
2024-12-07 17:51:05 -05:00
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
$fid = bin2hex(random_bytes(16));
2024-12-13 20:57:10 -05:00
$type = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
$type = strtolower($type);
$mime = mime_content_type('test' . $type);
$legal = ['png','gif','jpeg','jpg','mp4','webm','mp3','wav'];
if (in_array($type, $legal)) {
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER["DOCUMENT_ROOT"] . '/../docs/pic/' . $fid . '.' . $type);
$postie .= "\nhttps://" . $_SERVER['HTTP_HOST'] . '/pic/' . $fid . '.' . $type;
}
2024-12-07 17:51:05 -05:00
}
2024-12-18 23:13:54 -05:00
$poid = bin2hex(random_bytes(16));
2024-12-07 17:51:05 -05:00
2024-11-27 00:13:33 -05:00
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
2024-12-18 23:13:54 -05:00
$stmt->execute([$username,$postType,$postId,microtime(true) - $ref,$postie,$poid]);
$postieP = "https://nbg.dervland.net/comment.php?id=" . $poid;
$user10 = '%system';
if ($postType == 'user') {
$postie = "A user commented on your wall: " . $postieP;
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
$stmt->execute([$user10,'notification',$postId,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
} else if ($postType == 'comment') {
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC");
$stmt->execute([
$poid
]);
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
$posts2 = $posts1[0]['username'];
$postie = "A user replied to your post: " . $postieP;
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
$stmt->execute([$user10,'notification',$posts2,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
}
2024-12-07 17:51:05 -05:00
2024-12-06 08:26:03 -05:00
getOut($postType,$postId);
}
post_handler();
2024-11-26 11:38:28 -05:00
2024-11-27 00:13:33 -05:00
page_header();
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>
<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-12-06 08:26:03 -05:00
<?php
comments("root","root");
page_footer();
2024-12-02 23:02:11 -05:00
?>