Woff2Loading.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\ISetupCheck;
  13. use OCP\SetupCheck\SetupResult;
  14. use Psr\Log\LoggerInterface;
  15. /**
  16. * Check whether the OTF and WOFF2 URLs works
  17. */
  18. class Woff2Loading implements ISetupCheck {
  19. use CheckServerResponseTrait;
  20. public function __construct(
  21. protected IL10N $l10n,
  22. protected IConfig $config,
  23. protected IURLGenerator $urlGenerator,
  24. protected IClientService $clientService,
  25. protected LoggerInterface $logger,
  26. ) {
  27. }
  28. public function getCategory(): string {
  29. return 'network';
  30. }
  31. public function getName(): string {
  32. return $this->l10n->t('Font file loading');
  33. }
  34. public function run(): SetupResult {
  35. $result = $this->checkFont('otf', $this->urlGenerator->linkTo('theming', 'fonts/OpenDyslexic-Regular.otf'));
  36. if ($result->getSeverity() !== SetupResult::SUCCESS) {
  37. return $result;
  38. }
  39. return $this->checkFont('woff2', $this->urlGenerator->linkTo('', 'core/fonts/NotoSans-Regular-latin.woff2'));
  40. }
  41. protected function checkFont(string $fileExtension, string $url): SetupResult {
  42. $noResponse = true;
  43. $responses = $this->runHEAD($url);
  44. foreach ($responses as $response) {
  45. $noResponse = false;
  46. if ($response->getStatusCode() === 200) {
  47. return SetupResult::success();
  48. }
  49. }
  50. if ($noResponse) {
  51. return SetupResult::info(
  52. str_replace(
  53. '{extension}',
  54. $fileExtension,
  55. $this->l10n->t('Could not check for {extension} loading support. Please check manually if your webserver serves `.{extension}` files.') . "\n" . $this->serverConfigHelp(),
  56. ),
  57. $this->urlGenerator->linkToDocs('admin-nginx'),
  58. );
  59. }
  60. return SetupResult::warning(
  61. str_replace(
  62. '{extension}',
  63. $fileExtension,
  64. $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.'),
  65. ),
  66. $this->urlGenerator->linkToDocs('admin-nginx'),
  67. );
  68. }
  69. }