integration-snippet.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // The lines an existing project needs.
  3. // Meant to be copied, not run directly.
  4. // ---------------------------------------------------------------------------
  5. // 1. Admin page for update and backup: <project>/admin/manage.php
  6. // ---------------------------------------------------------------------------
  7. require_once __DIR__ . "/../config.php";
  8. require_once __DIR__ . "/../includes/functions.php";
  9. // Check the project's own login first - the panel is the application's
  10. // most powerful page.
  11. if (empty($_SESSION["admin_logged_in"])) {
  12. header("Location: login.php");
  13. exit;
  14. }
  15. require __DIR__ . "/../manage-client/ui/panel.php";
  16. // ---------------------------------------------------------------------------
  17. // 2. Status block on an existing settings page
  18. // ---------------------------------------------------------------------------
  19. $manageStatusPanelUrl = "manage.php";
  20. include __DIR__ . "/../manage-client/ui/status-partial.php";
  21. // ---------------------------------------------------------------------------
  22. // 3. Automatic backup without cron, e.g. on the admin dashboard
  23. // ---------------------------------------------------------------------------
  24. require_once __DIR__ . "/../manage-client/lib/client.php";
  25. try {
  26. // Only creates one once MANAGE_BACKUP_AUTO_INTERVAL_SECONDS has elapsed.
  27. manageBackupCreateAutomaticIfDue();
  28. } catch (Throwable $exception) {
  29. // A failed backup must not block the dashboard.
  30. error_log("Automatic backup failed: " . $exception->getMessage());
  31. }
  32. // ---------------------------------------------------------------------------
  33. // 4. Update notice in the project's own navigation
  34. // ---------------------------------------------------------------------------
  35. require_once __DIR__ . "/../manage-client/lib/client.php";
  36. $manageStatus = manageClientStatus(); // never throws
  37. if ($manageStatus["update"] !== null && $manageStatus["update"]["available"]) {
  38. echo '<a href="manage.php">Update ' .
  39. htmlspecialchars($manageStatus["update"]["latest"], ENT_QUOTES, "UTF-8") .
  40. " available</a>";
  41. }