index.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. require dirname(__DIR__) . '/app/bootstrap.php';
  3. auth_require();
  4. // Hosting without cron: the client creates a backup once
  5. // MANAGE_BACKUP_AUTO_INTERVAL_SECONDS has passed and returns immediately
  6. // otherwise, so this is the dashboard's cost for having backups at all. Off by
  7. // default (interval 0) because cron is the better place for it — see
  8. // manage-client/config.sample.php.
  9. //
  10. // Only with a config.php present: without one the client would fall back to its
  11. // own defaults and start writing weekly backups nobody asked for. A backup that
  12. // fails must never cost the operator the dashboard.
  13. if (is_file(APP_ROOT . '/manage-client/config.php')) {
  14. require_once APP_ROOT . '/manage-client/lib/client.php';
  15. try {
  16. manageBackupCreateAutomaticIfDue();
  17. } catch (Throwable $e) {
  18. error_log('Automatic backup failed: ' . $e->getMessage());
  19. }
  20. }
  21. $site = site_get();
  22. $galleries = galleries_all();
  23. $active = count(array_filter($galleries, fn($g) => !gallery_is_expired($g)));
  24. $stats = array_map(fn($g) => gallery_stats($g['slug']), $galleries);
  25. $views = array_sum(array_column($stats, 'views'));
  26. $downloads = array_sum(array_column($stats, 'downloads'));
  27. // Computed from the galleries already loaded above rather than by rescanning:
  28. // this is the page an operator lands on after an update, so it is where a
  29. // pending migration should announce itself.
  30. $pending = array_filter($galleries, fn($g) => migrate_pending_for($g) !== []);
  31. admin_header('Dashboard');
  32. flash_render();
  33. ?>
  34. <h1>Dashboard</h1>
  35. <?php if ($pending !== []): ?>
  36. <div class="flash flash-error">
  37. <?= count($pending) ?> galler<?= count($pending) === 1 ? 'y needs' : 'ies need' ?>
  38. a one-time data migration after the last software update.
  39. <a href="migrate.php">Run it now →</a>
  40. </div>
  41. <?php endif; ?>
  42. <div class="card">
  43. <table>
  44. <tr><td>Showreel images</td><td><?= count($site['showreel'] ?? []) ?></td>
  45. <td><a href="showreel.php">Manage →</a></td></tr>
  46. <tr><td>Galleries</td><td><?= count($galleries) ?> (<?= $active ?> active)</td>
  47. <td><a href="galleries.php">Manage →</a></td></tr>
  48. <tr><td>Gallery views</td><td><?= $views ?></td>
  49. <td><a href="galleries.php">Per gallery →</a></td></tr>
  50. <tr><td>Archive downloads</td><td><?= $downloads ?></td>
  51. <td><a href="galleries.php">Per gallery →</a></td></tr>
  52. <tr><td>Front page</td><td><?= e($site['intro_title']) ?></td>
  53. <td><a href="frontpage.php">Edit →</a></td></tr>
  54. <tr><td>Data format</td>
  55. <td><?= $pending === [] ? 'up to date (v' . (int)SCHEMA_VERSION . ')' : count($pending) . ' pending' ?></td>
  56. <td><a href="migrate.php">Migration →</a></td></tr>
  57. <!-- Version from the constant, never from the manage server: the
  58. dashboard must not wait on a network call to render. -->
  59. <tr><td>Software version</td><td><?= e(APP_VERSION) ?></td>
  60. <td><a href="maintenance.php">Update &amp; backup →</a></td></tr>
  61. </table>
  62. </div>
  63. <p class="help">
  64. Tip: create a gallery under <em>Galleries</em>, then share its link with your client.
  65. Password and expiry date are optional per gallery.
  66. </p>
  67. <?php admin_footer(); ?>