WebOrbiton
v2.0.0.1

Publisium

52 lines · 1.8 KB
  1. <?php
  2. declare(strict_types=1);
  3. function renderArticleCard(array $article): string
  4. {
  5. $html = '<article class="article-card">';
  6. $html .= '<a href="' . htmlspecialchars(SiteFront::articleUrl($article['slug']), ENT_QUOTES) . '">';
  7. if (!empty($article['cover_image_path'])) {
  8. $html .= '<img src="' . htmlspecialchars($article['cover_image_path']) . '" alt="" class="article-card-image">';
  9. }
  10. $html .= '<div class="article-card-body">';
  11. if (!empty($article['category_name'])) {
  12. $html .= '<span class="article-card-category">' . htmlspecialchars($article['category_name']) . '</span>';
  13. }
  14. $html .= '<h3>' . htmlspecialchars($article['title']) . '</h3>';
  15. $html .= '<p>' . htmlspecialchars((string) ($article['excerpt'] ?? '')) . '</p>';
  16. if (($article['access_type'] ?? '') === 'paid') {
  17. $html .= '<span class="badge-paid">' . htmlspecialchars(Language::get('article_paid_label', 'Paid article')) . '</span>';
  18. }
  19. $html .= '</div></a></article>';
  20. return $html;
  21. }
  22. function renderFeaturedBanner(array $articles): string
  23. {
  24. if (empty($articles)) {
  25. return '';
  26. }
  27. $html = '<div class="featured-banner">';
  28. foreach ($articles as $index => $article) {
  29. $sizeClass = $index === 0 ? ' featured-banner-item-large' : ' featured-banner-item-small';
  30. $html .= '<a class="featured-banner-item' . $sizeClass . '" href="' . htmlspecialchars(SiteFront::articleUrl($article['slug']), ENT_QUOTES) . '">';
  31. if (!empty($article['cover_image_path'])) {
  32. $html .= '<img src="' . htmlspecialchars($article['cover_image_path']) . '" alt="">';
  33. }
  34. $html .= '<span class="featured-banner-title">' . htmlspecialchars($article['title']) . '</span>';
  35. $html .= '</a>';
  36. }
  37. $html .= '</div>';
  38. return $html;
  39. }
  40. ​