From 250a00bf5ad9857018764f03eff6cef583783100 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 8 Aug 2022 11:39:25 +0200 Subject: [PATCH] Use `Helper::isAjaxRequest()` --- .../lib/http/middleware/CheckForOfflineMode.class.php | 8 ++------ .../files/lib/http/middleware/CheckUserBan.class.php | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/wcfsetup/install/files/lib/http/middleware/CheckForOfflineMode.class.php b/wcfsetup/install/files/lib/http/middleware/CheckForOfflineMode.class.php index 47ef960891..9953ef652d 100644 --- a/wcfsetup/install/files/lib/http/middleware/CheckForOfflineMode.class.php +++ b/wcfsetup/install/files/lib/http/middleware/CheckForOfflineMode.class.php @@ -7,6 +7,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; +use wcf\http\Helper; use wcf\system\box\BoxHandler; use wcf\system\exception\AJAXException; use wcf\system\notice\NoticeHandler; @@ -47,7 +48,7 @@ final class CheckForOfflineMode implements MiddlewareInterface private function getOfflineResponse(ServerRequestInterface $request): ResponseInterface { - if ($this->isAjaxRequest($request)) { + if (Helper::isAjaxRequest($request)) { throw new AJAXException( WCF::getLanguage()->getDynamicVariable('wcf.ajax.error.permissionDenied'), AJAXException::INSUFFICIENT_PERMISSIONS @@ -79,9 +80,4 @@ final class CheckForOfflineMode implements MiddlewareInterface { return WCF::getSession()->getPermission('admin.general.canViewPageDuringOfflineMode'); } - - private function isAjaxRequest(ServerRequestInterface $request): bool - { - return $request->getHeaderLine('x-requested-with') === 'XMLHttpRequest'; - } } diff --git a/wcfsetup/install/files/lib/http/middleware/CheckUserBan.class.php b/wcfsetup/install/files/lib/http/middleware/CheckUserBan.class.php index 3b3ed410bc..82645b304b 100644 --- a/wcfsetup/install/files/lib/http/middleware/CheckUserBan.class.php +++ b/wcfsetup/install/files/lib/http/middleware/CheckUserBan.class.php @@ -7,6 +7,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use wcf\data\user\User; +use wcf\http\Helper; use wcf\system\exception\AJAXException; use wcf\system\exception\NamedUserException; use wcf\system\WCF; @@ -30,7 +31,7 @@ final class CheckUserBan implements MiddlewareInterface $user = WCF::getUser(); if ($this->isBanned($user)) { - if ($this->isAjaxRequest($request)) { + if (Helper::isAjaxRequest($request)) { throw new AJAXException( WCF::getLanguage()->getDynamicVariable('wcf.user.error.isBanned'), AJAXException::INSUFFICIENT_PERMISSIONS @@ -59,9 +60,4 @@ final class CheckUserBan implements MiddlewareInterface return !!$user->banned; } - - private function isAjaxRequest(ServerRequestInterface $request): bool - { - return $request->getHeaderLine('x-requested-with') === 'XMLHttpRequest'; - } } -- 2.20.1