WebOrbiton
v2.0.0.8

Publisium

428 lines · 22.8 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. require_once __DIR__ . '/includes/config.php';
  6. require_once __DIR__ . '/includes/database.php';
  7. require_once __DIR__ . '/includes/user-auth.php';
  8. require_once __DIR__ . '/includes/language.php';
  9. require_once __DIR__ . '/includes/site-front.php';
  10. require_once __DIR__ . '/includes/block-editor.php';
  11. require_once __DIR__ . '/includes/table-of-contents.php';
  12. require_once __DIR__ . '/includes/avatar.php';
  13. require_once __DIR__ . '/includes/author-profile.php';
  14. require_once __DIR__ . '/includes/tags.php';
  15. require_once __DIR__ . '/includes/auth.php';
  16. require_once __DIR__ . '/includes/read-aloud.php';
  17. require_once __DIR__ . '/includes/currency.php';
  18. require_once __DIR__ . '/includes/comments.php';
  19. ​
  20. $previewId = (int) ($_GET['preview'] ?? 0);
  21. $isPreview = $previewId > 0;
  22. ​
  23. $db = Database::site();
  24. $settings = SiteFront::settings();
  25. ​
  26. $slug = trim((string) ($_GET['slug'] ?? ''));
  27. ​
  28. if (Languages::enabled() && !isset($_GET['publisium_lang']) && preg_match('#^([a-z]{2,3}(?:-[a-z]{2,4})?)/(.*)$#', $slug, $languageMatch) === 1 && in_array($languageMatch[1], Languages::activeCodes(), true)) {
  29. $_GET['publisium_lang'] = $languageMatch[1];
  30. Languages::resetCache();
  31. SiteFront::resetSettings();
  32. $settings = SiteFront::settings();
  33. $languageRest = trim($languageMatch[2], '/');
  34. ​
  35. if ($languageRest === '') {
  36. require __DIR__ . '/index.php';
  37. exit;
  38. }
  39. ​
  40. if (preg_match('/^[a-z0-9-]+\.php$/', $languageRest) === 1 && $languageRest !== 'article.php' && is_file(__DIR__ . '/' . $languageRest)) {
  41. require __DIR__ . '/' . $languageRest;
  42. exit;
  43. }
  44. ​
  45. $slug = $languageRest;
  46. $_GET['slug'] = $languageRest;
  47. }
  48. ​
  49. if (preg_match('#^(index|index\.php|index\.html)/?$#i', $slug) === 1) {
  50. header('Location: ' . SiteFront::homeUrl(), true, 301);
  51. exit;
  52. }
  53. ​
  54. // Short links (/about, /jan-kowalski, /my-article) all arrive here; send pages and author pages on.
  55. $viaShortLink = false;
  56. if (!$isPreview && $slug !== '') {
  57. $shortTarget = CleanUrls::resolve($slug);
  58. if ($shortTarget !== null) {
  59. $viaShortLink = true;
  60. if ($shortTarget['type'] === 'page' || $shortTarget['type'] === 'author') {
  61. $_GET['slug'] = $shortTarget['slug'];
  62. define('PUBLISIUM_SHORT_LINK', true);
  63. require __DIR__ . '/' . ($shortTarget['type'] === 'page' ? 'page.php' : 'artist.php');
  64. exit;
  65. }
  66. $slug = $shortTarget['slug'];
  67. }
  68. }
  69. ​
  70. if ($isPreview) {
  71. Auth::boot();
  72. } else {
  73. UserAuth::boot();
  74. }
  75. ​
  76. $query = $isPreview
  77. ? "SELECT a.*, c.name AS category_name, c.slug AS category_slug, COALESCE(t.display_name, a.author_name, '') AS author_name
  78. FROM articles a
  79. LEFT JOIN categories c ON c.id = a.category_id
  80. LEFT JOIN team_accounts t ON t.id = a.author_id
  81. WHERE a.id = :id LIMIT 1"
  82. : "SELECT a.*, c.name AS category_name, c.slug AS category_slug, COALESCE(t.display_name, a.author_name, '') AS author_name
  83. FROM articles a
  84. LEFT JOIN categories c ON c.id = a.category_id
  85. LEFT JOIN team_accounts t ON t.id = a.author_id
  86. WHERE a.slug = :slug AND a.status = 'published' LIMIT 1";
  87. $statement = $db->prepare($query);
  88. $statement->execute($isPreview ? ['id' => $previewId] : ['slug' => $slug]);
  89. $article = $statement->fetch();
  90. ​
  91. if (!$article && !$isPreview && Languages::enabled() && in_array(strtolower($slug), Languages::activeCodes(), true)) {
  92. header('Location: ' . Languages::homeUrl(strtolower($slug)), true, 301);
  93. exit;
  94. }
  95. ​
  96. if ($article && !$isPreview && Languages::current() !== '' && !Languages::hasTranslation('article', (int) $article['id'])) {
  97. header('Location: ' . SiteFront::articleUrl((string) $article['slug'], ''), true, 302);
  98. exit;
  99. }
  100. ​
  101. if (!$article) {
  102. http_response_code(404);
  103. $pageTitle = Language::get('not_found_title', 'Not found') . ' - ' . $settings['site_name'];
  104. $showBanner = false;
  105. require __DIR__ . '/includes/front-header.php';
  106. echo '<p>' . htmlspecialchars(Language::get('article_not_found', 'We couldn’t find this article. It may have been moved or deleted.')) . '</p>';
  107. require __DIR__ . '/includes/front-footer.php';
  108. exit;
  109. }
  110. ​
  111. if (!$isPreview && !$viaShortLink && CleanUrls::slugFor('article', (string) $article['slug']) !== null) {
  112. CleanUrls::redirect(SiteFront::articleUrl((string) $article['slug']));
  113. }
  114. ​
  115. $article = Languages::article($article);
  116. SiteFront::setAdContext('article', (int) $article['id']);
  117. ​
  118. if ($isPreview) {
  119. if (!Auth::check()) {
  120. http_response_code(403);
  121. exit('Preview access requires team login.');
  122. }
  123. ​
  124. $currentTeamUser = Auth::user();
  125. $canPreview = $currentTeamUser !== null
  126. && ((int) $article['author_id'] === (int) $currentTeamUser['id']
  127. || Auth::hasRoleAtLeast(Auth::ROLE_EDITOR_IN_CHIEF)
  128. || Auth::role() === Auth::ROLE_PROOFREADER);
  129. if (!$canPreview) {
  130. http_response_code(403);
  131. exit('You do not have permission to preview this article.');
  132. }
  133. } else {
  134. $updateViews = $db->prepare('UPDATE articles SET views_count = views_count + 1, updated_at = updated_at WHERE id = :id');
  135. $updateViews->execute(['id' => $article['id']]);
  136. }
  137. ​
  138. $hasSubscription = false;
  139. if ($article['access_type'] === 'paid' && UserAuth::check()) {
  140. $hasSubscription = UserAuth::hasActiveSubscription((int) UserAuth::user()['id']);
  141. }
  142. ​
  143. $isLocked = !$isPreview && $article['access_type'] === 'paid' && !$hasSubscription;
  144. ​
  145. $relatedArticles = [];
  146. $latestArticles = [];
  147. ​
  148. if ($settings['related_articles_enabled'] === '1') {
  149. if (!empty($article['category_id'])) {
  150. $relatedStatement = $db->prepare(
  151. "SELECT a.id, a.title, a.slug, a.cover_image_path FROM articles a WHERE a.status = 'published' AND a.category_id = :category_id AND a.id != :id" . Languages::articleFilterSql('a') . " ORDER BY a.published_at DESC LIMIT 4"
  152. );
  153. $relatedStatement->execute(['category_id' => $article['category_id'], 'id' => $article['id']]);
  154. $relatedArticles = Languages::articles($relatedStatement->fetchAll());
  155. }
  156. ​
  157. $latestStatement = $db->prepare(
  158. "SELECT a.id, a.title, a.slug, a.cover_image_path FROM articles a WHERE a.status = 'published' AND a.id != :id" . Languages::articleFilterSql('a') . " ORDER BY a.published_at DESC LIMIT 4"
  159. );
  160. $latestStatement->execute(['id' => $article['id']]);
  161. $latestArticles = Languages::articles($latestStatement->fetchAll());
  162. }
  163. ​
  164. $pageTitle = ($article['seo_title'] ?: $article['title']) . ' - ' . $settings['site_name'];
  165. $pageDescription = $article['seo_description'] ?: $article['excerpt'];
  166. $showBanner = false;
  167. $ogType = 'article';
  168. $ogImagePath = !empty($article['cover_image_path']) ? $article['cover_image_path'] : null;
  169. $pageType = 'article';
  170. $authorPage = AuthorProfile::isEnabled() ? AuthorProfile::publicSummary((int) $article['author_id']) : null;
  171. $authorPageUrl = $authorPage !== null ? SiteFront::authorUrl((string) $authorPage['slug']) : null;
  172. $ogArticleMeta = [
  173. 'published' => $article['published_at'] ?? null,
  174. 'modified' => $article['updated_at'] ?? null,
  175. 'author' => $authorPageUrl !== null ? SiteFront::absoluteUrl($authorPageUrl) : (string) $article['author_name'],
  176. 'section' => (string) ($article['category_name'] ?? ''),
  177. ];
  178. $pageSchema = !$isPreview && $settings['seo_article_schema_enabled'] === '1'
  179. ? SiteFront::renderArticleSchema($article, AuthorProfile::schemaType((int) $article['author_id']), $authorPageUrl)
  180. : '';
  181. $pageNoindex = !empty($article['noindex']);
  182. $pageTitle = $isPreview ? 'Preview - ' . $pageTitle : $pageTitle;
  183. ​
  184. require __DIR__ . '/includes/front-header.php';
  185. ​
  186. ?>
  187. <article class="article-view">
  188. ​
  189. <?php if (($settings['breadcrumbs_enabled'] ?? '0') === '1'): ?>
  190. <nav class="article-breadcrumbs" aria-label="<?= htmlspecialchars(Language::get('breadcrumb_label', 'Breadcrumb')) ?>">
  191. <ol>
  192. <li><a href="<?= htmlspecialchars(SiteFront::homeUrl(), ENT_QUOTES) ?>"><?= htmlspecialchars(Language::get('nav_home', 'Home')) ?></a></li>
  193. <?php if (!empty($article['category_name'])): ?>
  194. <li><a href="category.php?slug=<?= urlencode($article['category_slug']) ?>"><?= htmlspecialchars($article['category_name']) ?></a></li>
  195. <?php endif; ?>
  196. <li aria-current="page"><span><?= htmlspecialchars($article['title']) ?></span></li>
  197. </ol>
  198. </nav>
  199. <?php endif; ?>
  200. ​
  201. <?php if (!empty($article['category_name'])): ?>
  202. <a href="category.php?slug=<?= urlencode($article['category_slug']) ?>" class="article-category-link"><?= htmlspecialchars($article['category_name']) ?></a>
  203. <?php endif; ?>
  204. ​
  205. <h1 class="article-title"><?= htmlspecialchars($article['title']) ?></h1>
  206. ​
  207. <div class="article-meta">
  208. <?php if ($article['author_name'] !== ''): ?>
  209. <?= htmlspecialchars(Language::get('article_by', 'By')) ?> <?php if ($authorPage !== null): ?><a href="<?= htmlspecialchars(SiteFront::authorUrl((string) $authorPage['slug']), ENT_QUOTES) ?>"><?= htmlspecialchars($article['author_name']) ?></a><?php else: ?><?= htmlspecialchars($article['author_name']) ?><?php endif; ?>
  210. &middot;
  211. <?php endif; ?>
  212. <?= htmlspecialchars(Language::get('article_published_on', 'Published on')) ?> <?= htmlspecialchars(SiteFront::formatDate((string) $article['published_at'], $settings['article_time_enabled'] === '1')) ?>
  213. <?php if (($settings['article_reading_time_enabled'] ?? '1') === '1'): ?>
  214. &middot; <?= htmlspecialchars(sprintf(Language::get('article_reading_time', '%d min read'), BlockEditor::readingTimeMinutes($article['content_blocks']))) ?>
  215. <?php endif; ?>
  216. <?php if (($settings['article_views_enabled'] ?? '0') === '1'): ?>
  217. &middot; <?= htmlspecialchars(str_replace('{count}', SiteFront::formatNumber((int) $article['views_count'] + ($isPreview ? 0 : 1)), Language::get('article_views', '{count} views'))) ?>
  218. <?php endif; ?>
  219. </div>
  220. ​
  221. <?php $commentsJump = ($settings['comments_enabled'] ?? '0') === '1' && ($settings['comments_jump_link'] ?? '0') === '1' && !$isLocked; ?>
  222. <?php if ($commentsJump): ?>
  223. <div class="article-actions">
  224. <?= SiteFront::renderShareControl($article) ?>
  225. <button type="button" class="share-toggle-btn comments-jump-btn" data-target="article-comments"><svg class="icon icon-sm" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path></svg><span><?= htmlspecialchars(Language::get('article_comments_title', 'Comments')) ?></span></button>
  226. </div>
  227. <?php else: ?>
  228. <?= SiteFront::renderShareControl($article) ?>
  229. <?php endif; ?>
  230. ​
  231. <?= SiteFront::renderAds('article-top') ?>
  232. ​
  233. <?php if (!empty($article['cover_image_path'])): ?>
  234. <img src="<?= htmlspecialchars($article['cover_image_path']) ?>" alt="" class="article-cover">
  235. <?php endif; ?>
  236. ​
  237. <?php foreach (SiteFront::activeAds('in-article') as $inArticleAd): ?>
  238. <?= SiteFront::renderAd($inArticleAd) ?>
  239. <?php endforeach; ?>
  240. ​
  241. <?php if ($isLocked): ?>
  242. <div class="article-content">
  243. <p class="article-excerpt-locked"><?= htmlspecialchars($article['excerpt']) ?></p>
  244. </div>
  245. <div class="paid-overlay">
  246. <div class="paid-overlay-box">
  247. <span class="badge-paid"><?= htmlspecialchars(Language::get('article_subscribers_only', 'Subscribers only')) ?></span>
  248. ​
  249. <div class="subscription-offer">
  250. <div class="subscription-offer-name"><?= htmlspecialchars($settings['subscription_name']) ?></div>
  251. <div class="subscription-offer-price">
  252. <?php
  253. $offerPrice = Currency::format((int) $settings['subscription_price_cents'], (string) $settings['subscription_currency']);
  254. $offerInterval = (string) $settings['subscription_interval'];
  255. ?>
  256. <?= htmlspecialchars($offerInterval === 'lifetime'
  257. ? $offerPrice . ' · ' . Language::get('subscription_one_time', 'one-time payment')
  258. : $offerPrice . ' / ' . ($offerInterval === 'year' ? Language::get('subscription_per_year', 'year') : Language::get('subscription_per_month', 'month'))) ?>
  259. </div>
  260. <?php if ($settings['subscription_description'] !== ''): ?>
  261. <p class="subscription-offer-description"><?= htmlspecialchars($settings['subscription_description']) ?></p>
  262. <?php endif; ?>
  263. <?php if ($settings['subscription_checkout_url'] !== ''): ?>
  264. <a href="<?= htmlspecialchars(SiteFront::subscriptionCheckoutUrl((string) (UserAuth::user()['email'] ?? ''))) ?>" class="unlock-btn"><?= htmlspecialchars(($settings['subscription_interval'] === 'lifetime' ? Language::get('article_buy_lifetime_button', 'Get lifetime access') : Language::get('article_subscribe_button', 'Subscribe'))) ?></a>
  265. <?php else: ?>
  266. <a href="user-login.php?mode=<?= UserAuth::check() ? 'login' : 'register' ?>" class="unlock-btn"><?= htmlspecialchars(($settings['subscription_interval'] === 'lifetime' ? Language::get('article_buy_lifetime_button', 'Get lifetime access') : Language::get('article_subscribe_button', 'Subscribe'))) ?></a>
  267. <?php endif; ?>
  268. </div>
  269. ​
  270. <?php if (!UserAuth::check() && ($settings['login_enabled'] ?? '1') !== '0'): ?>
  271. <div class="subscription-divider"><?= htmlspecialchars(Language::get('article_already_subscriber', 'Already a subscriber?')) ?></div>
  272. <a href="user-login.php?mode=login" class="unlock-btn unlock-btn-outline"><?= htmlspecialchars(Language::get('article_login_button', 'Log in')) ?></a>
  273. <?php endif; ?>
  274. ​
  275. </div>
  276. </div>
  277. <?php else: ?>
  278. <?php
  279. $middleAdMarker = '<!--publisium-ad-middle-->';
  280. $articleHtml = BlockEditor::renderWithMiddle($article['content_blocks'], $middleAdMarker);
  281. $tocHtml = '';
  282. if (($settings['toc_enabled'] ?? '0') === '1') {
  283. [$articleHtml, $tocItems] = TableOfContents::build($articleHtml);
  284. $tocHtml = TableOfContents::render($tocItems);
  285. }
  286. ?>
  287. <?php $articleHtml = str_replace($middleAdMarker, SiteFront::renderAds('article-middle'), $articleHtml); ?>
  288. <?php $readAloudTracks = Languages::hasTranslation('article', (int) $article['id']) ? [] : ReadAloud::tracksFor($article); ?>
  289. <?php if ($readAloudTracks !== []): ?>
  290. <div class="read-aloud" data-read-aloud data-tracks="<?= htmlspecialchars((string) json_encode($readAloudTracks, JSON_UNESCAPED_SLASHES), ENT_QUOTES) ?>"
  291. data-label-play="<?= htmlspecialchars(Language::get('read_aloud_play', 'Play'), ENT_QUOTES) ?>"
  292. data-label-pause="<?= htmlspecialchars(Language::get('read_aloud_pause', 'Pause'), ENT_QUOTES) ?>">
  293. <button type="button" class="read-aloud-toggle" aria-label="<?= htmlspecialchars(Language::get('read_aloud_play', 'Play')) ?>">
  294. <svg class="read-aloud-icon-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.5v13a1 1 0 0 0 1.5.86l10.5-6.5a1 1 0 0 0 0-1.72L9.5 4.64A1 1 0 0 0 8 5.5z" fill="currentColor"/></svg>
  295. <svg class="read-aloud-icon-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="5" width="4.2" height="14" rx="1.2" fill="currentColor"/><rect x="13.8" y="5" width="4.2" height="14" rx="1.2" fill="currentColor"/></svg>
  296. </button>
  297. <div class="read-aloud-main">
  298. <div class="read-aloud-title"><?= htmlspecialchars(Language::get('read_aloud_title', 'Listen to this article')) ?></div>
  299. <div class="read-aloud-track">
  300. <input type="range" class="read-aloud-seek" min="0" max="1000" value="0" step="1" aria-label="<?= htmlspecialchars(Language::get('read_aloud_seek', 'Seek')) ?>">
  301. <span class="read-aloud-time" aria-live="off">0:00</span>
  302. </div>
  303. </div>
  304. <button type="button" class="read-aloud-speed" aria-label="<?= htmlspecialchars(Language::get('read_aloud_speed', 'Playback speed')) ?>">1&times;</button>
  305. </div>
  306. <?= Asset::js('assets/read-aloud.js') ?>
  307. <?php endif; ?>
  308. <?= $tocHtml ?>
  309. <div class="article-content">
  310. <?= $articleHtml ?>
  311. </div>
  312. <?php endif; ?>
  313. ​
  314. <?php $articleTags = ArticleTags::isEnabled() && !$isLocked ? ArticleTags::forArticle((int) $article['id']) : []; ?>
  315. <?php if (!empty($articleTags)): ?>
  316. <div class="article-tags">
  317. <span class="article-tags-label"><?= htmlspecialchars(Language::get('article_tags_label', 'Tags:')) ?></span>
  318. <?php foreach ($articleTags as $articleTag): ?>
  319. <a href="tag.php?slug=<?= urlencode($articleTag['slug']) ?>" class="article-tag"><?= htmlspecialchars($articleTag['name']) ?></a>
  320. <?php endforeach; ?>
  321. </div>
  322. <?php endif; ?>
  323. ​
  324. <?php foreach (SiteFront::activeAds('article-bottom') as $articleBottomAd): ?>
  325. <?= SiteFront::renderAd($articleBottomAd) ?>
  326. <?php endforeach; ?>
  327. ​
  328. <?php if (($settings['author_box_enabled'] ?? '0') === '1' && !$isLocked && $article['author_name'] !== ''): ?>
  329. <?php
  330. if ($article['author_id'] !== null) {
  331. $authorCountStatement = $db->prepare("SELECT COUNT(*) FROM articles WHERE author_id = :id AND status = 'published'");
  332. $authorCountStatement->execute(['id' => $article['author_id']]);
  333. } else {
  334. $authorCountStatement = $db->prepare("SELECT COUNT(*) FROM articles WHERE author_id IS NULL AND author_name = :name AND status = 'published'");
  335. $authorCountStatement->execute(['name' => $article['author_name']]);
  336. }
  337. $authorArticleCount = (int) $authorCountStatement->fetchColumn();
  338. $authorAvatar = '';
  339. try {
  340. $authorAvatarStatement = $db->prepare('SELECT avatar_path FROM team_accounts WHERE id = :id LIMIT 1');
  341. $authorAvatarStatement->execute(['id' => $article['author_id']]);
  342. $authorAvatar = (string) $authorAvatarStatement->fetchColumn();
  343. } catch (PDOException $e) {
  344. $authorAvatar = '';
  345. }
  346. ?>
  347. <aside class="author-box">
  348. <?= Avatar::html(['avatar_path' => $authorAvatar, 'display_name' => $article['author_name']], 'author-box-avatar') ?>
  349. <div class="author-box-info">
  350. <div class="author-box-label"><?= htmlspecialchars(Language::get('article_written_by', 'Written by')) ?></div>
  351. <div class="author-box-name">
  352. <?php if ($authorPage !== null): ?>
  353. <a href="<?= htmlspecialchars(SiteFront::authorUrl((string) $authorPage['slug']), ENT_QUOTES) ?>"><?= htmlspecialchars($article['author_name']) ?></a>
  354. <?php else: ?>
  355. <?= htmlspecialchars($article['author_name']) ?>
  356. <?php endif; ?>
  357. </div>
  358. <?php if ($authorPage !== null && $authorPage['headline'] !== ''): ?>
  359. <div class="author-box-headline"><?= htmlspecialchars($authorPage['headline']) ?></div>
  360. <?php endif; ?>
  361. <div class="author-box-meta"><?= htmlspecialchars(str_replace('{count}', (string) $authorArticleCount, Language::get('author_articles_count', 'Articles: {count}'))) ?></div>
  362. </div>
  363. </aside>
  364. <?php endif; ?>
  365. ​
  366. </article>
  367. ​
  368. <?php if ($settings['related_articles_enabled'] === '1' && (!empty($relatedArticles) || !empty($latestArticles))): ?>
  369. <section class="related-section">
  370. <?php if (!empty($relatedArticles)): ?>
  371. <h2><?= htmlspecialchars(Language::get('article_related', 'Related articles')) ?></h2>
  372. <div class="article-grid article-grid-small">
  373. <?php foreach ($relatedArticles as $related): ?>
  374. <a href="<?= htmlspecialchars(SiteFront::articleUrl($related['slug'])) ?>" class="article-card">
  375. <?php if (!empty($related['cover_image_path'])): ?>
  376. <img src="<?= htmlspecialchars($related['cover_image_path']) ?>" alt="" class="article-card-image">
  377. <?php endif; ?>
  378. <div class="article-card-body">
  379. <h3><?= htmlspecialchars($related['title']) ?></h3>
  380. </div>
  381. </a>
  382. <?php endforeach; ?>
  383. </div>
  384. <?php endif; ?>
  385. ​
  386. <?php if (!empty($latestArticles)): ?>
  387. <h2><?= htmlspecialchars(Language::get('article_latest', 'More recent articles')) ?></h2>
  388. <div class="article-grid article-grid-small">
  389. <?php foreach ($latestArticles as $latest): ?>
  390. <a href="<?= htmlspecialchars(SiteFront::articleUrl($latest['slug'])) ?>" class="article-card">
  391. <?php if (!empty($latest['cover_image_path'])): ?>
  392. <img src="<?= htmlspecialchars($latest['cover_image_path']) ?>" alt="" class="article-card-image">
  393. <?php endif; ?>
  394. <div class="article-card-body">
  395. <h3><?= htmlspecialchars($latest['title']) ?></h3>
  396. </div>
  397. </a>
  398. <?php endforeach; ?>
  399. </div>
  400. <?php endif; ?>
  401. </section>
  402. <?php endif; ?>
  403. ​
  404. <?php if ($settings['comments_enabled'] === '1' && !$isLocked): ?>
  405. <section class="comments-section" id="article-comments">
  406. <h2><?= htmlspecialchars(Language::get('article_comments_title', 'Comments')) ?></h2>
  407. ​
  408. <?php $commentsRules = array_values(array_filter(array_map('trim', explode("\n", (string) ($settings['comments_rules'] ?? ''))), static fn(string $line): bool => $line !== '')); ?>
  409. <?php if ($commentsRules !== []): ?>
  410. <details class="comments-rules">
  411. <summary><?= htmlspecialchars(Language::get('comments_rules_title', 'Commenting rules')) ?></summary>
  412. <?php if (count($commentsRules) === 1): ?>
  413. <p><?= htmlspecialchars($commentsRules[0]) ?></p>
  414. <?php else: ?>
  415. <ul>
  416. <?php foreach ($commentsRules as $commentsRule): ?>
  417. <li><?= htmlspecialchars($commentsRule) ?></li>
  418. <?php endforeach; ?>
  419. </ul>
  420. <?php endif; ?>
  421. </details>
  422. <?php endif; ?>
  423. ​
  424. <?= Comments::render($settings, $article) ?>
  425. </section>
  426. <?php endif; ?>
  427. ​
  428. <?php require __DIR__ . '/includes/front-footer.php'; ?>