Woff2Loading.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Settings\SetupChecks;
  8. use OCP\Http\Client\IClientService;
  9. use OCP\IConfig;
  10. use OCP\IL10N;
  11. use OCP\IURLGenerator;
  12. use OCP\SetupCheck\CheckServerResponseTrait;
  13. use OCP\SetupCheck\ISetupCheck;
  14. use OCP\SetupCheck\SetupResult;
  15. use Psr\Log\LoggerInterface;
  16. /**
  17. * Check whether the OTF and WOFF2 URLs works
  18. */
  19. class Woff2Loading implements ISetupCheck {
  20. use CheckServerResponseTrait;
  21. public function __construct(
  22. protected IL10N $l10n,
  23. protected IConfig $config,
  24. protected IURLGenerator $urlGenerator,
  25. protected IClientService $clientService,
  26. protected LoggerInterface $logger,
  27. ) {
  28. }
  29. public function getCategory(): string {
  30. return 'network';
  31. }
  32. public function getName(): string {
  33. return $this->l10n->t('Font file loading');
  34. }
  35. public function run(): SetupResult {
  36. $result = $this->checkFont('otf', $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.otf'));
  37. if ($result->getSeverity() !== SetupResult::SUCCESS) {
  38. return $result;
  39. }
  40. return $this->checkFont('woff2', $this->urlGenerator->linkTo('', 'core/fonts/NotoSans-Regular-latin.woff2'));
  41. }
  42. protected function checkFont(string $fileExtension, string $url): SetupResult {
  43. $noResponse = true;
  44. $responses = $this->runRequest('HEAD', $url);
  45. foreach ($responses as $response) {
  46. $noResponse = false;
  47. if ($response->getStatusCode() === 200) {
  48. return SetupResult::success();
  49. }
  50. }
  51. if ($noResponse) {
  52. return SetupResult::info(
  53. str_replace(
  54. '{extension}',
  55. $fileExtension,
  56. $this->l10n->t('Could not check for {extension} loading support. Please check manually if your webserver serves `.{extension}` files.') . "\n" . $this->serverConfigHelp(),
  57. ),
  58. $this->urlGenerator->linkToDocs('admin-nginx'),
  59. );
  60. }
  61. return SetupResult::warning(
  62. str_replace(
  63. '{extension}',
  64. $fileExtension,
  65. $this->l10n->t('Your web server is not properly set up to deliver .{extension} files. This is typically an issue with the Nginx configuration. For Nextcloud 15 it needs an adjustment to also deliver .{extension} files. Compare your Nginx configuration to the recommended configuration in our documentation.'),
  66. ),
  67. $this->urlGenerator->linkToDocs('admin-nginx'),
  68. );
  69. }
  70. }