WebOrbiton
v1.0.0.0

StocketBase

56 lines · 2.0 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. require_once __DIR__ . '/currency.php';
  6. ​
  7. function renderProductCard(array $product): string
  8. {
  9. $html = '<article class="product-card">';
  10. $html .= '<a href="' . htmlspecialchars(SiteFront::productUrl($product['slug']), ENT_QUOTES) . '">';
  11. ​
  12. if (!empty($product['cover_image_path'])) {
  13. $html .= '<img src="' . htmlspecialchars($product['cover_image_path']) . '" alt="" class="product-card-image">';
  14. }
  15. ​
  16. $html .= '<div class="product-card-body">';
  17. ​
  18. if (!empty($product['category_name'])) {
  19. $html .= '<span class="product-card-category">' . htmlspecialchars($product['category_name']) . '</span>';
  20. }
  21. ​
  22. $html .= '<h3>' . htmlspecialchars($product['title']) . '</h3>';
  23. $html .= '<p>' . htmlspecialchars($product['excerpt']) . '</p>';
  24. ​
  25. if (!empty($product['price_cents'])) {
  26. $html .= '<span class="product-card-price">' . htmlspecialchars(Currency::format((int) $product['price_cents'], (string) ($product['currency'] ?: 'USD'))) . '</span>';
  27. } elseif (!empty($product['billing_interval'])) {
  28. $html .= '<span class="product-card-price">' . htmlspecialchars(Language::get('product_subscription_label', 'Subscription')) . '</span>';
  29. }
  30. ​
  31. $html .= '</div></a></article>';
  32. ​
  33. return $html;
  34. }
  35. ​
  36. function renderFeaturedBanner(array $products): string
  37. {
  38. if (empty($products)) {
  39. return '';
  40. }
  41. ​
  42. $html = '<div class="featured-banner">';
  43. foreach ($products as $index => $product) {
  44. $sizeClass = $index === 0 ? ' featured-banner-item-large' : ' featured-banner-item-small';
  45. $html .= '<a class="featured-banner-item' . $sizeClass . '" href="' . htmlspecialchars(SiteFront::productUrl($product['slug']), ENT_QUOTES) . '">';
  46. if (!empty($product['cover_image_path'])) {
  47. $html .= '<img src="' . htmlspecialchars($product['cover_image_path']) . '" alt="">';
  48. }
  49. $html .= '<span class="featured-banner-title">' . htmlspecialchars($product['title']) . '</span>';
  50. $html .= '</a>';
  51. }
  52. $html .= '</div>';
  53. ​
  54. return $html;
  55. }
  56. ​