VersionCheckController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers;
  4. use PhpMyAdmin\Core;
  5. use PhpMyAdmin\VersionInformation;
  6. use function json_encode;
  7. /**
  8. * A caching proxy for retrieving version information from https://www.phpmyadmin.net/.
  9. */
  10. class VersionCheckController extends AbstractController
  11. {
  12. public function index(): void
  13. {
  14. $_GET['ajax_request'] = 'true';
  15. // Disabling standard response.
  16. $this->response->disable();
  17. // Always send the correct headers
  18. Core::headerJSON();
  19. $versionInformation = new VersionInformation();
  20. $versionDetails = $versionInformation->getLatestVersion();
  21. if (empty($versionDetails)) {
  22. echo json_encode([]);
  23. return;
  24. }
  25. $latestCompatible = $versionInformation->getLatestCompatibleVersion(
  26. $versionDetails->releases
  27. );
  28. $version = '';
  29. $date = '';
  30. if ($latestCompatible != null) {
  31. $version = $latestCompatible['version'];
  32. $date = $latestCompatible['date'];
  33. }
  34. echo json_encode([
  35. 'version' => ! empty($version) ? $version : '',
  36. 'date' => ! empty($date) ? $date : '',
  37. ]);
  38. }
  39. }