2024-12-06 08:26:03 -05:00
|
|
|
<?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),
|
2024-12-07 17:51:05 -05:00
|
|
|
array('key' => '','type' => 'hidden','name' => 'id', 'default' => $idr),
|
|
|
|
array('key' => 'Attachments', 'type' => 'file', 'name' => 'file', 'default' => '')
|
2024-12-11 01:54:38 -05:00
|
|
|
),'/index.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);
|
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>
|
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
|
|
|
|
2024-12-06 08:26:03 -05:00
|
|
|
$stmt = $db->prepare("SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC LIMIT ? OFFSET ?");
|
|
|
|
$stmt->execute([
|
|
|
|
$typer,
|
|
|
|
$idr,
|
|
|
|
10,
|
|
|
|
$page * 10
|
|
|
|
]);
|
|
|
|
|
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
|
|
|
|
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>
|
|
|
|
</div>
|
|
|
|
<?php }
|
|
|
|
}
|
|
|
|
?>
|