Files
varlog/templates/author_profile.php
T

99 lines
4.2 KiB
PHP

<?php
require_once BASE_PATH . '/src/Parsedown.php';
$Parsedown = new Parsedown();
ob_start();
$_apName = $authorRow['display_name'] ?? '';
$_apUrl = $authorRow['profile_url'] ?? '';
$_apSlug = $authorRow['profile_slug'] ?? '';
$_apBio = $authorRow['bio'] ?? '';
$_initials = mb_strtoupper(mb_substr($_apName, 0, 1, 'UTF-8'), 'UTF-8');
?>
<div class="author-profile-hero mb-5">
<div class="author-avatar"><?= htmlspecialchars($_initials) ?></div>
<div class="author-profile-info">
<h1 class="author-profile-name"><?= htmlspecialchars($_apName) ?></h1>
<?php if ($_apUrl !== ''): ?>
<a href="<?= htmlspecialchars($_apUrl) ?>" target="_blank" rel="noopener" class="author-profile-link">
<?= htmlspecialchars(parse_url($_apUrl, PHP_URL_HOST) ?: $_apUrl) ?> ↗
</a>
<?php endif; ?>
<a href="/liens/<?= rawurlencode($_apSlug) ?>" class="liens-cta">Mes liens</a>
</div>
<?php if ($_apBio !== ''): ?>
<div class="author-bio-wrap">
<p class="author-profile-bio bio-clamped" id="author-bio"><?= nl2br(htmlspecialchars($_apBio)) ?></p>
<button class="bio-toggle" id="bio-toggle" hidden>plus</button>
</div>
<script>
(function(){
var bio = document.getElementById('author-bio');
var btn = document.getElementById('bio-toggle');
requestAnimationFrame(function() {
if (bio.scrollHeight > bio.clientHeight + 2) { btn.hidden = false; }
});
btn.addEventListener('click', function() {
var exp = btn.getAttribute('aria-expanded') === 'true';
bio.classList.toggle('bio-clamped', exp);
btn.textContent = exp ? 'plus' : 'moins';
btn.setAttribute('aria-expanded', exp ? 'false' : 'true');
});
})();
</script>
<?php endif; ?>
</div>
<?php if (empty($authorArticles)): ?>
<p class="text-muted">Aucun article publié.</p>
<?php else: ?>
<div class="post-grid">
<?php foreach (array_slice($authorArticles, 0, 6) 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;
?>
<article class="card">
<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">
<a href="<?= htmlspecialchars($postUrl) ?>"><?= htmlspecialchars($post['title']) ?></a>
</h2>
<p class="card-text flex-grow-1"><?= htmlspecialchars($preview) ?></p>
<div class="post-entry-meta mt-auto">
<span><?= htmlspecialchars(date('d/m/Y', strtotime((string)($post['published_at'] ?? $post['created_at'] ?? '')))) ?></span>
<a href="<?= htmlspecialchars($postUrl) ?>" class="post-entry-read">→ lire</a>
</div>
</div>
<a href="<?= htmlspecialchars($postUrl) ?>" class="stretched-link"></a>
</article>
<?php endforeach; ?>
</div>
<?php if (count($authorArticles) > 6): ?>
<p class="text-center mt-4">
<a href="/" class="author-profile-link">Voir tous les articles →</a>
</p>
<?php endif; ?>
<?php endif; ?>
<?php
$content = ob_get_clean();
$title = htmlspecialchars($_apName) . ' — ' . siteTitle();
$seoTitle = $_apName . ' — ' . siteTitle();
$canonical = rtrim(APP_URL, '/') . '/profil/' . rawurlencode($_apSlug);
$ogUrl = $canonical;
$mainClass = 'container-fluid';
include __DIR__ . '/layout.php';