2024-02-15 01:08:04 +00:00
< ? php
declare ( strict_types = 1 );
/**
2024-06-03 08:23:34 +00:00
* SPDX - FileCopyrightText : 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2024-02-15 01:08:04 +00:00
*/
namespace OCA\Settings\SetupChecks ;
use OCP\Http\Client\IClientService ;
use OCP\IConfig ;
use OCP\IL10N ;
use OCP\IURLGenerator ;
2024-09-13 12:18:25 +00:00
use OCP\SetupCheck\CheckServerResponseTrait ;
2024-02-15 01:08:04 +00:00
use OCP\SetupCheck\ISetupCheck ;
use OCP\SetupCheck\SetupResult ;
use Psr\Log\LoggerInterface ;
/**
2024-09-16 07:58:54 +00:00
* Check whether the OTF and WOFF2 URLs works
2024-02-15 01:08:04 +00:00
*/
class Woff2Loading implements ISetupCheck {
use CheckServerResponseTrait ;
public function __construct (
protected IL10N $l10n ,
protected IConfig $config ,
protected IURLGenerator $urlGenerator ,
protected IClientService $clientService ,
protected LoggerInterface $logger ,
) {
}
public function getCategory () : string {
return 'network' ;
}
public function getName () : string {
2024-09-16 07:58:54 +00:00
return $this -> l10n -> t ( 'Font file loading' );
2024-02-15 01:08:04 +00:00
}
public function run () : SetupResult {
2024-09-16 07:58:54 +00:00
$result = $this -> checkFont ( 'otf' , $this -> urlGenerator -> linkTo ( 'theming' , 'fonts/OpenDyslexic-Regular.otf' ));
if ( $result -> getSeverity () !== SetupResult :: SUCCESS ) {
return $result ;
}
return $this -> checkFont ( 'woff2' , $this -> urlGenerator -> linkTo ( '' , 'core/fonts/NotoSans-Regular-latin.woff2' ));
}
protected function checkFont ( string $fileExtension , string $url ) : SetupResult {
2024-02-15 01:08:04 +00:00
$noResponse = true ;
2024-09-13 12:18:25 +00:00
$responses = $this -> runRequest ( 'HEAD' , $url );
2024-02-15 01:08:04 +00:00
foreach ( $responses as $response ) {
$noResponse = false ;
if ( $response -> getStatusCode () === 200 ) {
return SetupResult :: success ();
}
}
if ( $noResponse ) {
return SetupResult :: info (
2024-09-16 07:58:54 +00:00
str_replace (
'{extension}' ,
$fileExtension ,
$this -> l10n -> t ( 'Could not check for {extension} loading support. Please check manually if your webserver serves `.{extension}` files.' ) . " \n " . $this -> serverConfigHelp (),
),
2024-02-15 01:08:04 +00:00
$this -> urlGenerator -> linkToDocs ( 'admin-nginx' ),
);
}
return SetupResult :: warning (
2024-09-16 07:58:54 +00:00
str_replace (
'{extension}' ,
$fileExtension ,
$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.' ),
),
2024-02-15 01:08:04 +00:00
$this -> urlGenerator -> linkToDocs ( 'admin-nginx' ),
);
2024-09-16 07:58:54 +00:00
2024-02-15 01:08:04 +00:00
}
}