partials.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Shared HTML fragments for the public site and the admin backoffice.
  4. * Admin pages all sit in admin/ and hardcode '../assets/...'. Public pages sit
  5. * in the document root except the gallery viewer in gallery/, so they prefix
  6. * their links with base() — '' or '../' depending on the page (see bootstrap).
  7. */
  8. declare(strict_types=1);
  9. function public_header(string $title, string $active = '', string $bodyClass = ''): void
  10. {
  11. $site = site_get();
  12. $name = $site['intro_title'] ?: config('site.name', 'Portfolio');
  13. $base = base();
  14. ?><!DOCTYPE html>
  15. <html lang="en">
  16. <head>
  17. <meta charset="utf-8">
  18. <meta name="viewport" content="width=device-width, initial-scale=1">
  19. <title><?= e($title) ?></title>
  20. <link rel="stylesheet" href="<?= e($base) ?>assets/site.css">
  21. </head>
  22. <body class="<?= e($bodyClass) ?>">
  23. <header class="nav" id="nav">
  24. <a class="nav-brand" href="<?= e($base ?: './') ?>"><?= e($name) ?></a>
  25. <nav class="nav-links">
  26. <a href="<?= e($base ?: './') ?>" class="<?= $active === 'home' ? 'active' : '' ?>">Home</a>
  27. <a href="<?= e($base) ?>showreel.php" class="<?= $active === 'showreel' ? 'active' : '' ?>">Showreel</a>
  28. <a href="<?= e($base) ?>contact.php" class="<?= $active === 'contact' ? 'active' : '' ?>">Contact</a>
  29. </nav>
  30. </header>
  31. <?php
  32. }
  33. function public_footer(): void
  34. {
  35. $base = base();
  36. ?><footer class="footer">
  37. <nav class="footer-links">
  38. <a href="<?= e($base) ?>impressum.php">Impressum</a>
  39. <a href="<?= e($base) ?>datenschutz.php">Datenschutz</a>
  40. </nav>
  41. <span>&copy; <?= date('Y') ?> <?= e(site_get()['intro_title'] ?: config('site.name', '')) ?></span>
  42. </footer>
  43. <script src="<?= e($base) ?>assets/site.js"></script>
  44. </body>
  45. </html>
  46. <?php
  47. }
  48. function admin_header(string $title, string $active = ''): void
  49. {
  50. ?><!DOCTYPE html>
  51. <html lang="en">
  52. <head>
  53. <meta charset="utf-8">
  54. <meta name="viewport" content="width=device-width, initial-scale=1">
  55. <title><?= e($title) ?> · Admin</title>
  56. <link rel="stylesheet" href="../assets/site.css">
  57. </head>
  58. <body class="admin">
  59. <header class="admin-nav">
  60. <a class="nav-brand" href="index.php">Backoffice</a>
  61. <nav class="nav-links">
  62. <a href="frontpage.php" class="<?= $active === 'frontpage' ? 'active' : '' ?>">Front page</a>
  63. <a href="showreel.php" class="<?= $active === 'showreel' ? 'active' : '' ?>">Showreel</a>
  64. <a href="galleries.php" class="<?= $active === 'galleries' ? 'active' : '' ?>">Galleries</a>
  65. <a href="contact.php" class="<?= $active === 'contact' ? 'active' : '' ?>">Contact</a>
  66. <a href="settings.php" class="<?= $active === 'settings' ? 'active' : '' ?>">Settings</a>
  67. <a href="../" target="_blank" rel="noopener">View site ↗</a>
  68. <a href="logout.php">Log out</a>
  69. </nav>
  70. </header>
  71. <main class="admin-main">
  72. <?php
  73. }
  74. function admin_footer(): void
  75. {
  76. ?></main>
  77. </body>
  78. </html>
  79. <?php
  80. }
  81. /**
  82. * The "resize uploads to" control, shared by the gallery create and settings
  83. * forms. $current is the gallery's stored cap in pixels, or null for Original.
  84. *
  85. * The select carries pixel values, never names, so the handler
  86. * (parse_max_resolution) never has to map a label back to a number. The custom
  87. * input is revealed by a tiny delegated script emitted once per page —
  88. * assets/admin.js is the uploader and is not loaded on galleries.php.
  89. */
  90. function resolution_field(?int $current = null): void
  91. {
  92. $isPreset = $current !== null && in_array($current, RESOLUTION_PRESETS, true);
  93. $isCustom = $current !== null && !$isPreset;
  94. ?>
  95. <label for="res">Resize uploads to <span style="text-transform:none;letter-spacing:0">(longest edge)</span></label>
  96. <div class="res-field">
  97. <select id="res" name="max_resolution">
  98. <option value="" <?= $current === null ? 'selected' : '' ?>>Original — no resize</option>
  99. <?php foreach (RESOLUTION_PRESETS as $px): ?>
  100. <option value="<?= $px ?>" <?= $current === $px ? 'selected' : '' ?>><?= e(resolution_label($px)) ?></option>
  101. <?php endforeach; ?>
  102. <option value="custom" <?= $isCustom ? 'selected' : '' ?>>Custom…</option>
  103. </select>
  104. <input type="number" name="max_resolution_custom" placeholder="e.g. 3000"
  105. min="<?= RESOLUTION_MIN ?>" max="<?= RESOLUTION_MAX ?>"
  106. value="<?= $isCustom ? (int)$current : '' ?>" <?= $isCustom ? '' : 'hidden' ?>>
  107. </div>
  108. <p class="help">
  109. Images larger than this are downscaled in the browser before uploading,
  110. which also keeps them under the server's upload limit. The re-encode
  111. drops EXIF data (camera, lens, date, location) — choose Original to keep
  112. it. Files the browser cannot read, such as RAW, are always uploaded
  113. untouched.
  114. </p>
  115. <?php
  116. static $scriptDone = false;
  117. if ($scriptDone) {
  118. return;
  119. }
  120. $scriptDone = true;
  121. ?>
  122. <script>
  123. document.addEventListener('change', function (e) {
  124. var select = e.target.closest('.res-field select');
  125. if (!select) return;
  126. var custom = select.parentNode.querySelector('input[name="max_resolution_custom"]');
  127. custom.hidden = select.value !== 'custom';
  128. if (!custom.hidden) custom.focus();
  129. });
  130. </script>
  131. <?php
  132. }
  133. /** One-shot status message helpers (flash messages via session). */
  134. function flash_set(string $msg, string $kind = 'ok'): void
  135. {
  136. session_boot();
  137. $_SESSION['flash'] = ['msg' => $msg, 'kind' => $kind];
  138. }
  139. function flash_render(): void
  140. {
  141. session_boot();
  142. if (!empty($_SESSION['flash'])) {
  143. $f = $_SESSION['flash'];
  144. unset($_SESSION['flash']);
  145. echo '<div class="flash flash-' . e($f['kind']) . '">' . e($f['msg']) . '</div>';
  146. }
  147. }