Files
2026-11-18 15:40:30 +05:45

280 lines
14 KiB
PHP

<?php
require_once __DIR__ . '/includes/data.php';
$slug = isset($_GET['slug']) ? (string) $_GET['slug'] : '';
$slug = preg_replace('/[^a-z0-9-]/', '', strtolower($slug));
$post = null;
$posts = $posts ?? [];
foreach ($posts as $candidate) {
if (($candidate['slug'] ?? '') === $slug && $slug !== '') {
$post = $candidate;
break;
}
}
$activePage = 'blog';
if ($post === null) {
http_response_code(404);
$pageTitle = 'Article not found | AI Institute';
$pageDescription = 'The requested article could not be found.';
require __DIR__ . '/includes/header.php';
?>
<main id="main-content" class="blog-detail">
<section class="blog-detail__hero cert-hero section">
<div class="container">
<div class="blog-detail__hero-content reveal">
<nav class="breadcrumb blog-detail__breadcrumb" aria-label="Breadcrumb">
<ol class="breadcrumb__list">
<li class="breadcrumb__item"><a href="index.php">Home</a></li>
<li class="breadcrumb__item"><a href="blog.php">Blog</a></li>
<li class="breadcrumb__item" aria-current="page">Article not found</li>
</ol>
</nav>
<span class="eyebrow">Blog</span>
<h1 class="blog-detail__title">Article not found</h1>
<p class="blog-detail__lead">The article you are looking for may have been moved or is not available.</p>
<a class="btn btn--primary blog-detail__back" href="blog.php#posts">Back to Blog</a>
</div>
</div>
</section>
</main>
<?php require __DIR__ . '/includes/footer.php'; ?>
<?php
exit;
}
$pageTitle = ($post['title'] ?? 'Blog Article') . ' | AI Institute';
$pageDescription = $post['excerpt'] ?? 'Read practical AI insights from AI Institute.';
$sections = isset($post['sections']) && is_array($post['sections']) ? $post['sections'] : [];
$author = isset($post['author']) && is_array($post['author']) ? $post['author'] : [];
$tags = isset($post['tags']) && is_array($post['tags']) ? $post['tags'] : [];
$authorName = $author['name'] ?? 'AI Institute Editorial Team';
$authorInitials = '';
$nameParts = preg_split('/\s+/', trim($authorName));
if (is_array($nameParts)) {
foreach ($nameParts as $part) {
if ($part !== '') {
$authorInitials .= strtoupper(substr($part, 0, 1));
}
if (strlen($authorInitials) >= 2) {
break;
}
}
}
if ($authorInitials === '') {
$authorInitials = 'AI';
}
$relatedPosts = [];
foreach ($posts as $candidate) {
if (($candidate['slug'] ?? '') === ($post['slug'] ?? '')) {
continue;
}
$relatedPosts[] = $candidate;
if (count($relatedPosts) >= 3) {
break;
}
}
require __DIR__ . '/includes/header.php';
?>
<main id="main-content" class="blog-detail">
<div class="reading-progress" aria-hidden="true"><span class="reading-progress__bar"></span></div>
<!-- ===== BLOG DETAIL HERO ===== -->
<section class="blog-detail__hero cert-hero section">
<div class="container">
<div class="blog-detail__hero-content reveal">
<nav class="breadcrumb blog-detail__breadcrumb" aria-label="Breadcrumb">
<ol class="breadcrumb__list">
<li class="breadcrumb__item"><a href="index.php">Home</a></li>
<li class="breadcrumb__item"><a href="blog.php">Blog</a></li>
<li class="breadcrumb__item" aria-current="page"><?= e($post['title'] ?? '') ?></li>
</ol>
</nav>
<?php if (!empty($post['category'])): ?>
<span class="eyebrow"><?= e($post['category']) ?></span>
<?php endif; ?>
<h1 class="blog-detail__title"><?= e($post['title'] ?? '') ?></h1>
<p class="blog-detail__meta"><?= e($post['date'] ?? '') ?> · <?= (int) ($post['read_time'] ?? 0) ?> min read</p>
</div>
</div>
</section>
<!-- ===== ARTICLE ===== -->
<section class="section blog-detail__article" id="article">
<div class="container">
<div class="blog-detail__layout">
<aside class="blog-toc reveal" aria-label="Contents">
<div class="blog-toc__inner">
<p class="blog-toc__title">Contents</p>
<?php if (!empty($sections)): ?>
<nav>
<ol class="blog-toc__list">
<?php foreach ($sections as $section): ?>
<?php
$sectionId = $section['id'] ?? '';
$sectionHeading = $section['heading'] ?? '';
if ($sectionId === '' || $sectionHeading === '') {
continue;
}
?>
<li class="blog-toc__item">
<a class="blog-toc__link" href="#<?= e($sectionId) ?>"><?= e($sectionHeading) ?></a>
</li>
<?php endforeach; ?>
</ol>
</nav>
<?php else: ?>
<p class="blog-toc__empty">No sections available.</p>
<?php endif; ?>
</div>
</aside>
<article class="blog-article reveal">
<div class="blog-article__image-wrap">
<img
class="blog-article__image"
src="<?= e($post['image'] ?? '') ?>"
alt="<?= e($post['alt'] ?? '') ?>"
width="1200"
height="675"
>
</div>
<div class="blog-article__content">
<p class="blog-article__intro"><?= e($post['excerpt'] ?? '') ?></p>
<?php foreach ($sections as $section): ?>
<?php
$sectionId = $section['id'] ?? '';
$sectionHeading = $section['heading'] ?? '';
$paragraphs = isset($section['paragraphs']) && is_array($section['paragraphs']) ? $section['paragraphs'] : [];
$listItems = isset($section['list']) && is_array($section['list']) ? $section['list'] : [];
if ($sectionId === '' || $sectionHeading === '') {
continue;
}
?>
<section class="blog-article__section" id="<?= e($sectionId) ?>">
<h2 class="blog-article__heading"><?= e($sectionHeading) ?></h2>
<?php foreach ($paragraphs as $paragraph): ?>
<p><?= e((string) $paragraph) ?></p>
<?php endforeach; ?>
<?php if (!empty($listItems)): ?>
<ul class="blog-article__list">
<?php foreach ($listItems as $item): ?>
<li><?= e((string) $item) ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</section>
<?php endforeach; ?>
</div>
<section class="blog-author" aria-labelledby="blog-author-title">
<div class="blog-author__avatar" aria-hidden="true"><?= e($authorInitials) ?></div>
<div class="blog-author__body">
<p class="blog-author__label" id="blog-author-title">Written by</p>
<div class="blog-author__top">
<h2 class="blog-author__name"><?= e($authorName) ?></h2>
<?php if (!empty($author['role'])): ?>
<span class="blog-author__role"><?= e($author['role']) ?></span>
<?php endif; ?>
</div>
<?php if (!empty($author['bio'])): ?>
<p class="blog-author__bio"><?= e($author['bio']) ?></p>
<?php endif; ?>
<p class="blog-author__count"><?= (int) ($author['articles'] ?? 0) ?> articles</p>
</div>
</section>
<?php if (!empty($tags)): ?>
<div class="blog-tags" aria-label="Tags">
<?php foreach ($tags as $tag): ?>
<span class="blog-tag"><?= e((string) $tag) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<!-- ===== LEAVE A REPLY ===== -->
<section class="blog-comment" aria-labelledby="leave-a-reply-title">
<h2 class="blog-comment__title" id="leave-a-reply-title">Leave a reply</h2>
<p class="blog-comment__intro">Share your thoughts about this article.</p>
<form class="blog-comment__form" novalidate>
<!-- TODO: connect this form to a backend or comment service when available -->
<div class="blog-comment__field">
<label class="blog-comment__label" for="comment-message">Comment <span aria-hidden="true">*</span></label>
<textarea class="blog-comment__input blog-comment__textarea" id="comment-message" name="comment" rows="5" required></textarea>
</div>
<div class="blog-comment__grid">
<div class="blog-comment__field">
<label class="blog-comment__label" for="comment-name">Name <span aria-hidden="true">*</span></label>
<input class="blog-comment__input" type="text" id="comment-name" name="name" autocomplete="name" required>
</div>
<div class="blog-comment__field">
<label class="blog-comment__label" for="comment-email">Email <span aria-hidden="true">*</span></label>
<input class="blog-comment__input" type="email" id="comment-email" name="email" autocomplete="email" required>
</div>
</div>
<div class="blog-comment__field">
<label class="blog-comment__label" for="comment-website">Website</label>
<input class="blog-comment__input" type="url" id="comment-website" name="website" autocomplete="url" placeholder="https://">
</div>
<div class="blog-comment__checkbox">
<input type="checkbox" id="comment-save" name="save_details" value="1">
<label for="comment-save">Save my details for next time</label>
</div>
<button class="btn btn--primary blog-comment__submit" type="submit">Post Comment</button>
<p class="blog-comment__status" role="status" aria-live="polite"></p>
</form>
</section>
</article>
</div>
</div>
</section>
<!-- ===== RELATED POSTS ===== -->
<?php if (!empty($relatedPosts)): ?>
<section class="section blog-related">
<div class="container">
<div class="section__head reveal">
<span class="eyebrow">Keep reading</span>
<h2 class="section__title">Related posts</h2>
</div>
<div class="blog blog-related__cards">
<div class="blog-grid blog-related__grid">
<?php foreach ($relatedPosts as $related): ?>
<article class="blog-card card reveal">
<div class="blog-card__media">
<img
class="blog-card__img"
src="<?= e($related['image'] ?? '') ?>"
alt="<?= e($related['alt'] ?? '') ?>"
width="1200"
height="675"
loading="lazy"
>
</div>
<div class="blog-card__body">
<h3 class="blog-card__title">
<a class="blog-card__link" href="blog-detail.php?slug=<?= e($related['slug'] ?? '') ?>"><?= e($related['title'] ?? '') ?></a>
</h3>
<p class="blog-card__meta"><?= e($related['date'] ?? '') ?> · <?= (int) ($related['read_time'] ?? 0) ?> min read</p>
<p class="blog-card__excerpt"><?= e($related['excerpt'] ?? '') ?></p>
</div>
</article>
<?php endforeach; ?>
</div>
</div>
</div>
</section>
<?php endif; ?>
</main>
<?php require __DIR__ . '/includes/footer.php'; ?>