129 lines
4 KiB
PHP
129 lines
4 KiB
PHP
<?php
|
|
require(__DIR__ . "/markdown.php");
|
|
function comments($typer, $idr, $disable = false)
|
|
{
|
|
$ref = 1732684297;
|
|
global $username;
|
|
global $db;
|
|
$page = array_key_exists('page', $_GET) ? ($_GET['page']) : 0;
|
|
$mode = array_key_exists('mode', $_GET) ? ($_GET['mode']) : 'all';
|
|
if ($username && !$disable) {
|
|
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),
|
|
array('key' => 'Attachments', 'type' => 'file', 'name' => 'file', 'default' => '')
|
|
), '/api/comment.php');
|
|
}
|
|
|
|
$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);
|
|
$qss['page'] = $page;
|
|
|
|
$qss['mode'] = 'all';
|
|
$qs_1 = http_build_query($qss);
|
|
|
|
$qss['mode'] = 'followers';
|
|
$qs_2 = http_build_query($qss);
|
|
?>
|
|
|
|
<div>
|
|
<a class="form-button" href="?<?php echo $qs_1 ?>">Everyone</a>
|
|
<a class="form-button" href="?<?php echo $qs_2 ?>">Following</a>
|
|
</div>
|
|
<div>
|
|
<?php if ($page > 0) { ?>
|
|
<a class="form-button" href="?<?php echo $qs_prev ?>">Previous</a>
|
|
<?php } ?>
|
|
<a class="form-button" href="?<?php echo $qs_next ?>">Next</a>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
$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);
|
|
}
|
|
|
|
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
|
|
]);
|
|
}
|
|
|
|
$posts2 = $stmt->fetchAll(PDO::FETCH_DEFAULT);
|
|
|
|
$edge = count($posts);
|
|
$posts = array_merge($posts, $posts2);
|
|
|
|
?>
|
|
<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]" ?>" />
|
|
<meta property="og:description" content="<?php echo htmlspecialchars($posts[$edge - 1]['content']) ?>" />
|
|
<meta property="og:image" content="https://nbg.dervland.net/img/newlogo.svg" />
|
|
<?php
|
|
foreach ($posts as $key => $post) {
|
|
if ($key == $edge) { ?>
|
|
<h2>Replies</h2>
|
|
<?php } ?>
|
|
<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>
|
|
<a class='link' href='/comment.php?id=<?php echo $post['id'] ?>'>
|
|
<?php echo date(DATE_RFC2822, $post['date'] + $ref) ?>
|
|
</a>
|
|
</b></div>
|
|
</div>
|
|
</div>
|
|
<pre><?php echo markdown(htmlspecialchars($post['content'])) ?></pre>
|
|
<a class="clickie" href="/comment.php?id=<?php echo $post['id']?>"><img class="header-img header-link" src="/img/mail.svg">Replies</a>
|
|
</div>
|
|
<?php }
|
|
}
|
|
?>
|