Files
folio/templates/author_articles.php

98 lines
4.2 KiB
PHP

<?php
require_once BASE_PATH . '/src/Parsedown.php';
$Parsedown = new Parsedown();
$_apName = $authorRow['display_name'] ?? '';
$_apSlug = $authorRow['profile_slug'] ?? '';
$_base = '/profil/' . rawurlencode($_apSlug) . '/article';
ob_start();
?>
<div class="mb-4">
<a href="/profil/<?= rawurlencode($_apSlug) ?>" class="text-muted">← <?= htmlspecialchars($_apName) ?></a>
<h1 class="mt-1">Articles de <?= htmlspecialchars($_apName) ?></h1>
</div>
<?php if (empty($posts)): ?>
<p class="text-muted">Aucun article publié.</p>
<?php else: ?>
<div class="post-grid">
<?php foreach ($posts as $post):
$html = $Parsedown->text($post['content']);
$preview = mb_strimwidth(strip_tags($html), 0, 120, '…');
$category = trim((string)($post['category'] ?? ''));
$gradient = coverGradient($category !== '' ? $category : $post['uuid'], $allCats ?? []);
$postUrl = '/post/' . rawurlencode($post['slug']);
$coverFile = $post['cover'] ?? '';
$coverStyle = $coverFile !== ''
? 'background-image: url(\'/file?uuid=' . rawurlencode($post['uuid']) . '&name=' . rawurlencode($coverFile) . '\')'
: 'background: ' . $gradient;
$isAvantPremiere = $post['published'] && strtotime((string)($post['published_at'] ?? '')) > time();
$isLocked = $isAvantPremiere && !hasCapability('view_previews');
?>
<article class="card">
<?php if ($isAvantPremiere): ?>
<div class="premiere-ribbon">Avant-première</div>
<?php endif; ?>
<div class="card-cover" style="<?= $coverStyle ?>">
<?php if ($category !== ''): ?>
<span class="cover-category"><?= htmlspecialchars($category) ?></span>
<?php endif; ?>
</div>
<div class="card-body d-flex flex-column">
<h2 class="card-title">
<?php if ($isLocked): ?>
<?= htmlspecialchars($post['title']) ?>
<?php else: ?>
<a href="<?= htmlspecialchars($postUrl) ?>"><?= htmlspecialchars($post['title']) ?></a>
<?php endif; ?>
</h2>
<p class="card-text flex-grow-1"><?= htmlspecialchars($preview) ?></p>
<div class="post-entry-meta mt-auto">
<?php if ($isAvantPremiere): ?>
<span class="text-muted">Disponible le <?= htmlspecialchars(date('d/m/Y \à H\hi', strtotime((string)($post['published_at'] ?? '')))) ?></span>
<?php else: ?>
<span><?= htmlspecialchars(date('d/m/Y', strtotime((string)($post['published_at'] ?? $post['created_at'] ?? '')))) ?></span>
<?php endif; ?>
<?php if (function_exists('isAdmin') && isAdmin()): ?>
<a href="/edit/<?= htmlspecialchars($post['uuid']) ?>" class="post-entry-edit">modifier</a>
<?php endif; ?>
<?php if (!$isLocked): ?>
<a href="<?= htmlspecialchars($postUrl) ?>" class="post-entry-read">→ lire</a>
<?php endif; ?>
</div>
</div>
<?php if (!$isLocked): ?>
<a href="<?= htmlspecialchars($postUrl) ?>" class="stretched-link"></a>
<?php endif; ?>
</article>
<?php endforeach; ?>
</div>
<?php if ($prevCursor !== null || $nextCursor !== null): ?>
<nav class="pagination-nav mt-5" aria-label="Navigation">
<?php if ($prevCursor !== null): ?>
<?php $prevHref = $prevCursor === '' ? $_base : $_base . '/cursor/' . rawurlencode($prevCursor); ?>
<a class="pagination-btn" href="<?= htmlspecialchars($prevHref) ?>">← Plus récents</a>
<?php endif; ?>
<?php if ($nextCursor !== null): ?>
<a class="pagination-btn ms-auto" href="<?= htmlspecialchars($_base . '/cursor/' . rawurlencode($nextCursor)) ?>">Plus anciens →</a>
<?php endif; ?>
</nav>
<?php endif; ?>
<?php endif; ?>
<?php
$content = ob_get_clean();
$title = 'Articles de ' . htmlspecialchars($_apName) . ' — ' . siteTitle();
$seoTitle = 'Articles de ' . $_apName . ' — ' . siteTitle();
$canonical = rtrim(APP_URL, '/') . $_base;
$ogUrl = $canonical;
if (!empty($cursor)) {
$metaRobots = 'noindex, follow';
}
$mainClass = 'container-fluid';
include __DIR__ . '/layout.php';