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 <?php
require("../libs/page.php"); require("../libs/page.php");
require("../libs/form.php"); require("../libs/form.php");
require("../libs/markdown.php"); require("../libs/comment.php");
$ref = 1732684297; $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() { function post_handler() {
global $ref; global $ref;
global $username; global $username;
global $db; global $db;
if (!$username) return; if (!$username) getOut('root','root');
if (!array_key_exists('post',$_POST)) return; if (!array_key_exists('post',$_POST)) return;
$postie = $_POST['post']; $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) { 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 = $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))]); $stmt->execute([$username,$postType,$postId,microtime(true) - $ref,$postie,bin2hex(random_bytes(16))]);
header("Location: " . $_SERVER["REQUEST_URI"]); getOut($postType,$postId);
die(); }
}
post_handler();
page_header(); 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"> <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> <a class="form-button" href="https://git.dervland.net/biglyderv/new-bigly-chat">Developer Portal</a>
</div> </div>
</div> </div>
<?php <?php
if ($username) { comments("root","root");
form("Broadcast your thoughts...", $form_message, array( page_footer();
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();
?> ?>

View file

@ -6,32 +6,31 @@
<div class="comment"> <div class="comment">
<h1 class="content-header">Terms of Use</h1> <h1 class="content-header">Terms of Use</h1>
<h2>1. Respect</h2> <h2>1. Respect</h2>
<p>Disruption to constructive discussion within BiglyChat is prohibited:</p> <p>Respect the BiglyChat community. Specifically, don't:</p>
<ol> <ol>
<li>Repeated personal attacks</li> <li>Repeatedly attack a person</li>
<li>Exposing non-public personal information</li> <li>Expose personal information</li>
<li>Illegal activity in the United States</li> <li>Encourage illegal activity with respect to United States law</li>
</ol> </ol>
<h2>2. Communication</h2> <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> misbehavior, suggestions, and bug fixes to these channels.</p>
<h2>3. Exploits</h2> <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> <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> <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> <ol>
<li>Non-historical politics</li> <li>Non-historical politics</li>
<li>Bigotry against sexuality, race, religion</li> <li>Bigotry against sexuality, race, or religion</li>
<li>Cryptocurrency or financial services</li> <li>Cryptocurrency or financial services, excluding commissions for art services</li>
<li>Channels that primarily focus on drama</li> <li>Accounts that promote external drama or mostly post drama</li>
<li>Terrorism or violent radicalism</li> <li>Terrorism or violent radicalism</li>
<li>Lewd or shock content</li> <li>Lewd or shock content</li>
</ol> </ol>
<!-- todo: guidelines for project lifecycle + stop derv killing everything-->
</div> </div>
<?php <?php
page_footer(); page_footer();
?> ?>

View file

@ -1,7 +1,8 @@
<?php <?php
require("../libs/page.php"); require("../libs/page.php");
require("../libs/form.php"); require("../libs/form.php");
require("../libs/comment.php");
$roles = array(); $roles = array();
page_header(); page_header();
@ -127,5 +128,7 @@
),'/user.php?id=' . $user . '&type=settings'); ),'/user.php?id=' . $user . '&type=settings');
} }
comments('user',$user);
page_footer(); 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' class='form-input'
type="<?php echo $kv['type'] ?>" type="<?php echo $kv['type'] ?>"
name="<?php echo $kv['name'] ?>" name="<?php echo $kv['name'] ?>"
<?php echo ($kv['type'] == 'hidden') ? 'hidden' : ''?>
value="<?php echo ($kv['type'] == 'textarea') ? '' : $kv['default'] ?>" value="<?php echo ($kv['type'] == 'textarea') ? '' : $kv['default'] ?>"
><?php echo (($kv['type'] == 'textarea') ? $kv['default'] . '</textarea>' : '') ?> ><?php echo (($kv['type'] == 'textarea') ? $kv['default'] . '</textarea>' : '') ?>
<?php } <?php }
@ -24,4 +25,4 @@
<input class='form-button' type="Submit" name="Submit"> <input class='form-button' type="Submit" name="Submit">
</form> </form>
<?php } <?php }
?> ?>