tkr/src/View/TicksView/TicksView.php
Greg Sarjeant d60230f975 Only show delete icon when logged in. (#73)
Check for a valid login session before showing delete icons on ticks.

Reviewed-on: https://gitea.subcultureofone.org/greg/tkr/pulls/73
Co-authored-by: Greg Sarjeant <greg@subcultureofone.org>
Co-committed-by: Greg Sarjeant <greg@subcultureofone.org>
2025-08-15 18:43:31 +00:00

52 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
class TicksView {
private $html;
public function __construct(SettingsModel $settings, array $ticks, int $page){
$this->html = $this->render($settings, $ticks, $page);
}
public function getHtml(): string {
return $this->html;
}
private function render(SettingsModel $settings, array $ticks, int $page): string{
ob_start();
?>
<ul class="tick-feed" aria-label="Recent updates">
<?php foreach ($ticks as $tick): ?>
<?php
$datetime = new DateTime($tick['timestamp'], new DateTimeZone('UTC'));
$relativeTime = Util::relative_time($tick['timestamp']);
?>
<li class="tick" tabindex="0">
<?php if (Session::isLoggedIn() && $tick['can_delete']): ?>
<form method="post"
action="<?= Util::buildRelativeUrl($settings->basePath, "tick/{$tick['id']}/delete") ?>"
class="delete-tick-form">
<input type="hidden" name="csrf_token" value="<?= Util::escape_html($_SESSION['csrf_token']) ?>">
<button type="submit" class="delete-tick-button">🗑️</button>
</form>
<?php endif ?>
<time datetime="<?php echo $datetime->format('c') ?>"><?php echo Util::escape_html($relativeTime) ?></time>
<span class="tick-text"><?php echo Util::linkify(Util::escape_html($tick['tick'])) ?></span>
</li>
<?php endforeach; ?>
</ul>
<div class="tick-pagination">
<?php if ($page > 1): ?>
<a <?php if($settings->strictAccessibility): ?>tabindex="0"<?php endif; ?>
href="?page=<?php echo $page - 1 ?>">&laquo; Newer</a>
<?php endif; ?>
<?php if (count($ticks) === $settings->itemsPerPage): ?>
<a <?php if($settings->strictAccessibility): ?>tabindex="0"<?php endif; ?>
href="?page=<?php echo $page + 1 ?>">Older &raquo;</a>
<?php endif; ?>
</div>
<?php return ob_get_clean();
}
}