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 post_handler() {
global $ref;
global $username;
global $db;
if (!$username) return;
if (!array_key_exists('post',$_POST)) return;
$postie = $_POST['post'];
if (strlen($postie) < 1 || strlen($postie) > 1024) {
return 'Post is too long or short.';
function getOut($typer, $idr) {
if ($typer == 'user') {
header("Location: " . '/user.php?id=' . htmlspecialchars($idr));
die();
}
$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();
}
function post_handler() {
global $ref;
global $username;
global $db;
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) {
getOut($postType,$postId);
}
$stmt = $db->prepare("INSERT INTO main.comment (username, targetType, targetId, date, content, id) VALUES (?,?,?,?,?,?)");
$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">
@ -45,46 +54,6 @@
</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 }
comments("root","root");
page_footer();
?>

View file

@ -6,30 +6,29 @@
<div class="comment">
<h1 class="content-header">Terms of Use</h1>
<h2>1. Respect</h2>
<p>Disruption to constructive discussion within BiglyChat is prohibited:</p>
<p>Respect the BiglyChat community. Specifically, don't:</p>
<ol>
<li>Repeated personal attacks</li>
<li>Exposing non-public personal information</li>
<li>Illegal activity in the United States</li>
<li>Repeatedly attack a person</li>
<li>Expose personal information</li>
<li>Encourage illegal activity with respect to United States law</li>
</ol>
<h2>2. Communication</h2>
<p>Official communications of BiglyChat are the native website and Discord. Report
<p>Official communication with BiglyChat staff is on the native website. Report
misbehavior, suggestions, and bug fixes to these channels.</p>
<h2>3. Exploits</h2>
<p>Don't exploit destructive functionality in Dervland services or hijack accounts to do so.</p>
<p>Don't exploit unintended functionality in Dervland services or hijack accounts to do so.</p>
<h2>4. Age</h2>
<p>You must be 13 years or older.</p>
<p>You must be 13 years or older to use private channels that aren't with staff members or related to computer science.</p>
<h2>5. Blanket bans</h2>
<p>Certain topics disallowed in public spaces frequently spiral to unhealthy discussion or impulsive behavior:</p>
<p>Certain topics are disallowed in public spaces that frequently spiral to unhealthy discussion or impulsive behavior:</p>
<ol>
<li>Non-historical politics</li>
<li>Bigotry against sexuality, race, religion</li>
<li>Cryptocurrency or financial services</li>
<li>Channels that primarily focus on drama</li>
<li>Bigotry against sexuality, race, or religion</li>
<li>Cryptocurrency or financial services, excluding commissions for art services</li>
<li>Accounts that promote external drama or mostly post drama</li>
<li>Terrorism or violent radicalism</li>
<li>Lewd or shock content</li>
</ol>
<!-- todo: guidelines for project lifecycle + stop derv killing everything-->
</div>
<?php

View file

@ -1,6 +1,7 @@
<?php
require("../libs/page.php");
require("../libs/form.php");
require("../libs/comment.php");
$roles = array();
@ -127,5 +128,7 @@
),'/user.php?id=' . $user . '&type=settings');
}
comments('user',$user);
page_footer();
?>

54
libs/comment.php Normal file
View file

@ -0,0 +1,54 @@
<?php
require("../libs/markdown.php");
function comments($typer, $idr) {
$ref = 1732684297;
global $username;
global $db;
$page = array_key_exists('page',$_GET) ? ($_GET['page']) : 0;
if ($username) {
form("Broadcast your thoughts...", '', array(
array('key' => 'Your message', 'type' => 'textarea', 'name' => 'post', 'default' => ''),
array('key' => '','type' => 'hidden','name' => 'type', 'default' => $typer),
array('key' => '','type' => 'hidden','name' => 'id', 'default' => $idr)
),'/index.php');
}
?>
<div>
<?php if ($page > 0) { ?>
<a class="form-button" href="?id=<?php echo htmlspecialchars($_GET['id'])?>&page=<?php echo $page - 1 ?>">Previous</a>
<?php } ?>
<a class="form-button" href="?id=<?php echo htmlspecialchars($_GET['id'])?>&page=<?php echo $page + 1 ?>">Next</a>
</div>
<?php
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC LIMIT ? OFFSET ?");
$stmt->execute([
$typer,
$idr,
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 }
}
?>

View file

@ -17,6 +17,7 @@
class='form-input'
type="<?php echo $kv['type'] ?>"
name="<?php echo $kv['name'] ?>"
<?php echo ($kv['type'] == 'hidden') ? 'hidden' : ''?>
value="<?php echo ($kv['type'] == 'textarea') ? '' : $kv['default'] ?>"
><?php echo (($kv['type'] == 'textarea') ? $kv['default'] . '</textarea>' : '') ?>
<?php }