bigly-chat/libs/comment.php

125 lines
3.8 KiB
PHP
Raw Normal View History

2024-12-06 08:26:03 -05:00
<?php
2025-01-07 15:19:55 -05:00
require(__DIR__ . "/markdown.php");
2025-01-05 02:47:50 -05:00
function comments($typer, $idr, $disable = false) {
2024-12-06 08:26:03 -05:00
$ref = 1732684297;
global $username;
global $db;
$page = array_key_exists('page',$_GET) ? ($_GET['page']) : 0;
2025-02-03 20:28:21 -05:00
$mode = array_key_exists('mode',$_GET) ? ($_GET['mode']) : 'all';
2025-01-05 02:47:50 -05:00
if ($username && !$disable) {
2024-12-06 08:26:03 -05:00
form("Broadcast your thoughts...", '', array(
array('key' => 'Your message', 'type' => 'textarea', 'name' => 'post', 'default' => ''),
array('key' => '','type' => 'hidden','name' => 'type', 'default' => $typer),
2024-12-07 17:51:05 -05:00
array('key' => '','type' => 'hidden','name' => 'id', 'default' => $idr),
array('key' => 'Attachments', 'type' => 'file', 'name' => 'file', 'default' => '')
2025-01-07 15:19:55 -05:00
),'/api/comment.php');
2024-12-06 08:26:03 -05:00
}
2024-12-11 01:54:38 -05:00
$qs = parse_url($_SERVER['REQUEST_URI']);
if (is_null($qs)) $qs = array('query' => '?');
$qsq = $qs['query'];
$qss = array();
parse_str($qsq,$qss);
$qss['page'] = $page + 1;
$qs_next = http_build_query($qss);
$qss['page'] = $page - 1;
$qs_prev = http_build_query($qss);
2025-02-03 20:28:21 -05:00
$qss['page'] = $page;
$qss['mode'] = 'all';
$qs_1 = http_build_query($qss);
$qss['mode'] = 'followers';
$qs_2 = http_build_query($qss);
2024-12-06 08:26:03 -05:00
?>
<div>
<?php if ($page > 0) { ?>
2024-12-11 01:54:38 -05:00
<a class="form-button" href="?<?php echo $qs_prev ?>">Previous</a>
2024-12-06 08:26:03 -05:00
<?php } ?>
2024-12-11 01:54:38 -05:00
<a class="form-button" href="?<?php echo $qs_next ?>">Next</a>
2025-02-03 20:28:21 -05:00
</div>
<div>
<a class="form-button" href="?<?php echo $qs_1 ?>">Everyone</a>
<a class="form-button" href="?<?php echo $qs_2 ?>">Following</a>
2024-12-06 08:26:03 -05:00
</div>
<?php
2024-12-12 00:08:19 -05:00
$posts = array();
$theId = $idr;
while (true) {
$stmt = $db->prepare("SELECT * FROM comment WHERE id = ? ORDER BY date DESC");
$stmt->execute([
$theId
]);
$posts1 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
if (is_null($posts1) || count($posts1) < 1) break;
$theId = $posts1[0]['targetid'];
$posts = array_merge($posts1,$posts);
}
2024-12-11 23:51:42 -05:00
2025-02-03 20:28:21 -05:00
if ($mode == 'all') {
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC LIMIT ? OFFSET ?");
$stmt->execute([
$typer,
$idr,
10,
$page * 10
]);
} else {
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? AND username IN (SELECT username FROM main.follow WHERE target = ?) ORDER BY date DESC LIMIT ? OFFSET ?");
$stmt->execute([
$typer,
$idr,
$username,
10,
$page * 10
]);
}
2024-12-06 08:26:03 -05:00
2024-12-11 23:51:42 -05:00
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
2024-12-12 00:08:19 -05:00
$edge = count($posts);
$posts = array_merge($posts,$posts2);
2024-12-06 08:26:03 -05:00
2025-01-07 22:31:48 -05:00
?>
<meta property="og:title" content="NewBiglyChat" />
<meta property="og:type" content="article" />
<meta property="og:url" content="<?php echo "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]" ?>" />
2025-01-07 22:35:08 -05:00
<meta property="og:description" content="<?php echo htmlspecialchars($posts[$edge - 1]['content']) ?>" />
2025-01-07 22:31:48 -05:00
<meta property="og:image" content="https://nbg.dervland.net/img/newlogo.svg" />
<?php
2024-12-12 00:08:19 -05:00
foreach ($posts as $key => $post) {
if ($key == $edge) { ?>
<h2>Replies</h2>
<?php } ?>
2024-12-06 08:26:03 -05:00
<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>
2024-12-11 23:51:42 -05:00
<a class='link' href='/comment.php?id=<?php echo $post['id'] ?>'>
<?php echo date(DATE_RFC2822,$post['date'] + $ref) ?>
</a>
2024-12-06 08:26:03 -05:00
</b></div>
</div>
</div>
<pre><?php echo markdown(htmlspecialchars($post['content'])) ?></pre>
2025-01-22 06:11:16 -05:00
<a class="clickie" href="/comment.php?id=<?php echo $post['id']?>"><img class="header-img header-link" src="/img/mail.svg">Replies</a>
2024-12-06 08:26:03 -05:00
</div>
<?php }
}
?>