partials.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Shared HTML fragments for the public site and the admin backoffice.
  4. * Public pages sit in the document root and admin pages in admin/, so asset
  5. * paths differ: public pages use 'assets/...', admin pages use '../assets/...'.
  6. */
  7. declare(strict_types=1);
  8. function public_header(string $title, string $active = '', string $bodyClass = ''): void
  9. {
  10. $site = site_get();
  11. $name = $site['intro_title'] ?: config('site.name', 'Portfolio');
  12. ?><!DOCTYPE html>
  13. <html lang="en">
  14. <head>
  15. <meta charset="utf-8">
  16. <meta name="viewport" content="width=device-width, initial-scale=1">
  17. <title><?= e($title) ?></title>
  18. <link rel="stylesheet" href="assets/site.css">
  19. </head>
  20. <body class="<?= e($bodyClass) ?>">
  21. <header class="nav" id="nav">
  22. <a class="nav-brand" href="./"><?= e($name) ?></a>
  23. <nav class="nav-links">
  24. <a href="./" class="<?= $active === 'home' ? 'active' : '' ?>">Home</a>
  25. <a href="showreel.php" class="<?= $active === 'showreel' ? 'active' : '' ?>">Showreel</a>
  26. <a href="contact.php" class="<?= $active === 'contact' ? 'active' : '' ?>">Contact</a>
  27. </nav>
  28. </header>
  29. <?php
  30. }
  31. function public_footer(): void
  32. {
  33. ?><footer class="footer">
  34. <nav class="footer-links">
  35. <a href="impressum.php">Impressum</a>
  36. <a href="datenschutz.php">Datenschutz</a>
  37. </nav>
  38. <span>&copy; <?= date('Y') ?> <?= e(site_get()['intro_title'] ?: config('site.name', '')) ?></span>
  39. </footer>
  40. <script src="assets/site.js"></script>
  41. </body>
  42. </html>
  43. <?php
  44. }
  45. function admin_header(string $title, string $active = ''): void
  46. {
  47. ?><!DOCTYPE html>
  48. <html lang="en">
  49. <head>
  50. <meta charset="utf-8">
  51. <meta name="viewport" content="width=device-width, initial-scale=1">
  52. <title><?= e($title) ?> · Admin</title>
  53. <link rel="stylesheet" href="../assets/site.css">
  54. </head>
  55. <body class="admin">
  56. <header class="admin-nav">
  57. <a class="nav-brand" href="index.php">Backoffice</a>
  58. <nav class="nav-links">
  59. <a href="frontpage.php" class="<?= $active === 'frontpage' ? 'active' : '' ?>">Front page</a>
  60. <a href="showreel.php" class="<?= $active === 'showreel' ? 'active' : '' ?>">Showreel</a>
  61. <a href="galleries.php" class="<?= $active === 'galleries' ? 'active' : '' ?>">Galleries</a>
  62. <a href="contact.php" class="<?= $active === 'contact' ? 'active' : '' ?>">Contact</a>
  63. <a href="settings.php" class="<?= $active === 'settings' ? 'active' : '' ?>">Settings</a>
  64. <a href="../" target="_blank" rel="noopener">View site ↗</a>
  65. <a href="logout.php">Log out</a>
  66. </nav>
  67. </header>
  68. <main class="admin-main">
  69. <?php
  70. }
  71. function admin_footer(): void
  72. {
  73. ?></main>
  74. </body>
  75. </html>
  76. <?php
  77. }
  78. /** One-shot status message helpers (flash messages via session). */
  79. function flash_set(string $msg, string $kind = 'ok'): void
  80. {
  81. session_boot();
  82. $_SESSION['flash'] = ['msg' => $msg, 'kind' => $kind];
  83. }
  84. function flash_render(): void
  85. {
  86. session_boot();
  87. if (!empty($_SESSION['flash'])) {
  88. $f = $_SESSION['flash'];
  89. unset($_SESSION['flash']);
  90. echo '<div class="flash flash-' . e($f['kind']) . '">' . e($f['msg']) . '</div>';
  91. }
  92. }