bibis/view/post-common.php

74 行
2.5 KiB
PHP

<?php
// Single post
function view_post($post, $options = []) {
$res_num = $options['res_num'] ?? 0;
$is_single = $options['is_single'] ?? false;
$link_to_thread = $options['link_to_thread'] ?? false;
$has_bottom_items = $options['has_bottom_items'] ?? true;
$title = htmlspecialchars($post['title'] ?? '');
$username = htmlspecialchars($post['username']);
$userid = htmlspecialchars($post['userid']);
$time = htmlspecialchars($post['time']);
$detail_url = htmlspecialchars($post['detail_url']);
$delete_url = htmlspecialchars($post['delete_url']);
$attachments = $post['attachments'] ?? [];
$user_url = htmlspecialchars($post['user_url']);
$body = $post['body']; // body is valid html
$is_guest = $post['is_guest'] ?? false;
$thread_id = $post['thread_id'] ?? '';
$thread_title = htmlspecialchars($post['thread_title'] ?? '');
$thread_url = htmlspecialchars($post['thread_url'] ?? '');
$total = ($view['total'] ?? 0) + 1;
$is_mine = $post['is_mine'] ?? false;
if ($is_guest) {
$html_user = "<b>{$username}</b>";
}
else {
$html_user = '<b><a href="' . $user_url . '">' . $username . '</a></b> @' . $userid;
}
if ($is_single || $detail_url <= '') {
$html_time = '<span class="post-time">' . $time . '</span>';
}
else {
$html_time = '<a class="post-time" href="' . $detail_url . '">' . $time . '</a>';
}
$bottom_items = [];
if ($has_bottom_items && !$is_single) {
$bottom_items[] = '<a href="' . $detail_url . '#REPLY">返信(Reply)</a>';
}
if ($has_bottom_items && $is_mine) {
$bottom_items[] = '<a href="' . $delete_url . '">削除(Delete)</a>';
}
$html_bottom_items = join(' - ', $bottom_items);
$attachment_items = [];
foreach ($attachments as $attachment) {
$attachment_items[] = '<li><a href="' . htmlspecialchars($attachment['url']) . '">' . htmlspecialchars($attachment['name']) . '</a>';
}
$html_attachment_items = join(PHP_EOL, $attachment_items);
?>
<dl<?= ($res_num > 0 ? ' id="N' . $res_num . '"' : '') ?>>
<?php if (!$is_single && $title > ''): ?>
<dt>件名:<b><?= $title ?></b></dt>
<?php endif; ?>
<dt><?= $res_num > 0 ? "{$res_num} " : '' ?><?= $html_user ?> <?= $html_time ?></dt>
<?php if ($link_to_thread && $thread_id > ''): ?>
<dd>RE: <a href="<?= $thread_url ?>"><?= $thread_title ?></a></dd>
<?php endif; ?>
<dd><?= $body ?>
<?php if (ENABLE_ATTACHMENT && $html_attachment_items > ''): ?>
<?= PHP_EOL ?>
<ul><?= $html_attachment_items ?></ul><?php endif; ?>
</dd>
<?php if ($html_bottom_items): ?>
<dd><?= $html_bottom_items ?></dd>
<?php endif; ?>
</dl>
<?php
}
?>