Commit cc853247 authored by Christian Kuhn's avatar Christian Kuhn Committed by Benni Mack
Browse files

[TASK] Drop usages of TYPO3_MODE and TYPO3_REQUESTTYPE

Drop all usages of TYPO3_MODE and TYPO3_REQUESTTYPE by
using the ApplicationType helper class when frontend
or backend is detected, and by directly using the
applicationType attribute of the request object in a
couple of special cases that check for backend ajax
or install tool.

Resolves: #92953
Related: #92951
Related: #92947
Releases: master
Change-Id: I98c9d5ef0e7a6409b01188ddd0bbcf94f159cbcd
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66895


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Simon Gilli's avatarSimon Gilli <typo3@gilbertsoft.org>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Simon Gilli's avatarSimon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 970d9bf8
......@@ -17,8 +17,10 @@ declare(strict_types=1);
namespace TYPO3\CMS\Backend\Resource\Processing;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Imaging\ImageDimension;
use TYPO3\CMS\Core\Resource\ProcessedFileRepository;
use TYPO3\CMS\Core\Resource\Processing\ProcessorInterface;
......@@ -33,14 +35,15 @@ class DeferredBackendImageProcessor implements ProcessorInterface
public function canProcessTask(TaskInterface $task): bool
{
$context = GeneralUtility::makeInstance(Context::class);
return TYPO3_MODE === 'BE'
&& $task->getType() === 'Image'
&& in_array($task->getName(), ['Preview', 'CropScaleMask'], true)
&& (!$context->hasAspect('fileProcessing') || $context->getPropertyFromAspect('fileProcessing', 'deferProcessing'))
&& $task->getSourceFile()->getProperty('width') > 0
&& $task->getSourceFile()->getProperty('height') > 0
// Let the local image processor update the properties in case the target file exists already
&& !$task->getSourceFile()->getStorage()->getProcessingFolder()->hasFile($task->getTargetFileName());
return ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
&& $task->getType() === 'Image'
&& in_array($task->getName(), ['Preview', 'CropScaleMask'], true)
&& (!$context->hasAspect('fileProcessing') || $context->getPropertyFromAspect('fileProcessing', 'deferProcessing'))
&& $task->getSourceFile()->getProperty('width') > 0
&& $task->getSourceFile()->getProperty('height') > 0
// Let the local image processor update the properties in case the target file exists already
&& !$task->getSourceFile()->getStorage()->getProcessingFolder()->hasFile($task->getTargetFileName());
}
public function processTask(TaskInterface $task): void
......
......@@ -15,10 +15,12 @@
namespace TYPO3\CMS\Backend\Security;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Tree\TreeNode;
use TYPO3\CMS\Backend\Tree\TreeNodeCollection;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Tree\Event\ModifyTreeDataEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -58,7 +60,9 @@ final class CategoryPermissionsAspect
public function addUserPermissionsToCategoryTreeData(ModifyTreeDataEvent $event): void
{
// Only evaluate this in the backend
if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE)) {
if (!($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
|| ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
) {
return;
}
......
......@@ -15,6 +15,7 @@
namespace TYPO3\CMS\Backend\Tree\View;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
......@@ -474,7 +475,9 @@ class FolderTreeView extends AbstractTreeView
$invertedDepthOfAjaxRequestedItem = 0;
$out = '<ul class="list-tree list-tree-root">';
// Evaluate AJAX request
if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ((int)$GLOBALS['TYPO3_REQUEST']->getAttribute('applicationType') & TYPO3_REQUESTTYPE_AJAX)
) {
[, $expandCollapseCommand, $expandedFolderHash, ] = $this->evaluateExpandCollapseParameter();
if ($expandCollapseCommand == 1) {
$doExpand = true;
......
......@@ -448,8 +448,7 @@ abstract class AbstractUserAuthentication implements LoggerAwareInterface
{
$result = '';
$cookieDomain = $GLOBALS['TYPO3_CONF_VARS']['SYS']['cookieDomain'];
// If a specific cookie domain is defined for a given TYPO3_MODE,
// use that domain
// If a specific cookie domain is defined for a given application type, use that domain
if (!empty($GLOBALS['TYPO3_CONF_VARS'][$this->loginType]['cookieDomain'])) {
$cookieDomain = $GLOBALS['TYPO3_CONF_VARS'][$this->loginType]['cookieDomain'];
}
......
......@@ -15,6 +15,7 @@
namespace TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\ExpressionLanguage\SyntaxError;
......@@ -22,6 +23,7 @@ use TYPO3\CMS\Core\Configuration\TypoScript\Exception\InvalidTypoScriptCondition
use TYPO3\CMS\Core\Error\Exception;
use TYPO3\CMS\Core\Exception\MissingTsfeException;
use TYPO3\CMS\Core\ExpressionLanguage\Resolver;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
......@@ -215,7 +217,8 @@ abstract class AbstractConditionMatcher implements LoggerAwareInterface, Conditi
'expression' => $expression,
'exception' => $exception
]);
if (TYPO3_MODE === 'FE'
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
&& $exception instanceof Exception
&& strpos($exception->getMessage(), 'in_array() expects parameter 2 to be array') !== false
) {
......
......@@ -385,13 +385,13 @@ class Bootstrap
$displayErrors = 1;
break;
default:
if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
// Throw exception if an invalid option is set.
throw new \RuntimeException(
'The option $TYPO3_CONF_VARS[SYS][displayErrors] is not set to "-1", "0" or "1".',
1476046290
);
}
// Throw exception if an invalid option is set. A default for displayErrors is set
// in very early install tool, coming from DefaultConfiguration.php. It is safe here
// to just throw if there is no value for whatever reason.
throw new \RuntimeException(
'The option $TYPO3_CONF_VARS[SYS][displayErrors] is not set to "-1", "0" or "1".',
1476046290
);
}
@ini_set('display_errors', (string)$displayErrors);
......
......@@ -15,9 +15,11 @@
namespace TYPO3\CMS\Core\Error;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\SysLog\Action as SystemLogGenericAction;
use TYPO3\CMS\Core\SysLog\Error as SystemLogErrorClassification;
......@@ -80,8 +82,11 @@ abstract class AbstractExceptionHandler implements ExceptionHandlerInterface, Si
// otherwise this will lead into recurring exceptions.
try {
if ($this->logger) {
// 'FE' if in FrontendApplication, else 'BE' (also in CLI without request object)
$applicationType = ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() ? 'FE' : 'BE';
$this->logger->critical($logTitle . ': ' . $logMessage, [
'TYPO3_MODE' => TYPO3_MODE,
'TYPO3_MODE' => $applicationType,
'exception' => $exception
]);
}
......
......@@ -15,9 +15,11 @@
namespace TYPO3\CMS\Core\Error;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Messaging\FlashMessage;
......@@ -96,8 +98,8 @@ class ErrorHandler implements ErrorHandlerInterface, LoggerAwareInterface
* Handles an error.
* If the error is registered as exceptionalError it will by converted into an exception, to be handled
* by the configured exceptionhandler. Additionally the error message is written to the configured logs.
* If TYPO3_MODE is 'BE' the error message is also added to the flashMessageQueue, in FE the error message
* is displayed in the admin panel (as TsLog message)
* If application is backend, the error message is also added to the flashMessageQueue, in frontend the
* error message is displayed in the admin panel (as TsLog message).
*
* @param int $errorLevel The error level - one of the E_* constants
* @param string $errorMessage The error message
......@@ -144,7 +146,11 @@ class ErrorHandler implements ErrorHandlerInterface, LoggerAwareInterface
$flashMessageSeverity = FlashMessage::NOTICE;
$severity = 0;
}
$logTitle = 'Core: Error handler (' . TYPO3_MODE . ')';
// String 'FE' if in FrontendApplication, else 'BE' (also in CLI without request object)
$applicationType = ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() ? 'FE' : 'BE';
$logTitle = 'Core: Error handler (' . $applicationType . ')';
$message = $logTitle . ': ' . $message;
if ($errorLevel === E_USER_DEPRECATED) {
......
......@@ -40,8 +40,8 @@ interface ErrorHandlerInterface
* Handles an error.
* If the error is registered as exceptionalError it will by converted into an exception, to be handled
* by the configured exceptionhandler. Additionally the error message is written to the configured logs.
* If TYPO3_MODE is 'BE' the error message is also added to the flashMessageQueue, in FE the error message
* is displayed in the admin panel (as TsLog message)
* If application is backend, the error message is also added to the flashMessageQueue, in frontend the
* error message is displayed in the admin panel (as TsLog message).
*
* @param int $errorLevel The error level - one of the E_* constants
* @param string $errorMessage The error message
......
......@@ -15,6 +15,7 @@
namespace TYPO3\CMS\Core\FormProtection;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
......@@ -105,6 +106,13 @@ class FormProtectionFactory
$GLOBALS['TSFE']->fe_user
];
} elseif (self::isBackendSession() && ($type === 'default' || $type === 'backend')) {
$isAjaxCall = false;
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if ($request instanceof ServerRequestInterface
&& (bool)((int)$request->getAttribute('applicationType') & TYPO3_REQUESTTYPE_AJAX)
) {
$isAjaxCall = true;
}
$classNameAndConstructorArguments = [
BackendFormProtection::class,
$GLOBALS['BE_USER'],
......@@ -112,7 +120,7 @@ class FormProtectionFactory
self::getMessageClosure(
$GLOBALS['LANG'],
GeneralUtility::makeInstance(FlashMessageService::class)->getMessageQueueByIdentifier(),
(bool)(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)
$isAjaxCall
)
];
} else {
......@@ -131,7 +139,14 @@ class FormProtectionFactory
*/
protected static function isInstallToolSession()
{
return TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL;
$isInstallTool = false;
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if ($request instanceof ServerRequestInterface
&& (bool)((int)$request->getAttribute('applicationType') & TYPO3_REQUESTTYPE_INSTALL)
) {
$isInstallTool = true;
}
return $isInstallTool;
}
/**
......
......@@ -18,6 +18,8 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Messaging;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer;
use TYPO3\CMS\Core\Messaging\Renderer\FlashMessageRendererInterface;
use TYPO3\CMS\Core\Messaging\Renderer\ListRenderer;
......@@ -86,11 +88,12 @@ class FlashMessageRendererResolver
protected function resolveContext(): string
{
$context = '';
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if (Environment::isCli()) {
$context = 'CLI';
} elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE) {
} elseif ($request instanceof ServerRequest && ApplicationType::fromRequest($request)->isBackend()) {
$context = 'BE';
} elseif (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_FE) {
} elseif ($request instanceof ServerRequest && ApplicationType::fromRequest($request)->isFrontend()) {
$context = 'FE';
}
return $context;
......
......@@ -15,11 +15,13 @@
namespace TYPO3\CMS\Core\Page;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\Router;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
......@@ -328,6 +330,11 @@ class PageRenderer implements SingletonInterface
*/
protected $metaTagRegistry;
/**
* @var string 'FE' if a frontend request, else 'BE'
*/
protected string $applicationType;
/**
* @var FrontendInterface
*/
......@@ -352,6 +359,10 @@ class PageRenderer implements SingletonInterface
'-->' . LF . '/*]]>*/' . LF . '</style>' . LF
];
// String 'FE' if in FrontendApplication, else 'BE' (also in CLI without request object)
// @todo: Usually, the PageRenderer does not make sense if there is no Request object ... restrict this?
$this->applicationType = ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() ? 'FE' : 'BE';
$this->metaTagRegistry = GeneralUtility::makeInstance(MetaTagManagerRegistry::class);
$this->setMetaTag('name', 'generator', 'TYPO3 CMS');
}
......@@ -1449,7 +1460,7 @@ class PageRenderer implements SingletonInterface
*/
public function addRequireJsConfiguration(array $configuration)
{
if (TYPO3_MODE === 'BE') {
if ($this->applicationType === 'BE') {
// Load RequireJS in backend context at first. Doing this in FE could break the output
$this->loadRequireJs();
}
......@@ -1465,20 +1476,21 @@ class PageRenderer implements SingletonInterface
protected function getRequireJsLoader(): string
{
$html = '';
$backendRequest = TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_BE;
$backendUserLoggedIn = !empty($GLOBALS['BE_USER']->user['uid']);
// no backend request - basically frontend
if (!$backendRequest) {
if (!($GLOBALS['TYPO3_REQUEST']) instanceof ServerRequestInterface
|| !ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
) {
// no backend request - basically frontend
$requireJsConfig = $this->getRequireJsConfig(static::REQUIREJS_SCOPE_CONFIG);
$requireJsConfig['typo3BaseUrl'] = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH') . '?eID=requirejs';
// backend request, but no backend user logged in
} elseif (!$backendUserLoggedIn) {
// backend request, but no backend user logged in
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$requireJsConfig = $this->getRequireJsConfig(static::REQUIREJS_SCOPE_CONFIG);
$requireJsConfig['typo3BaseUrl'] = (string)$uriBuilder->buildUriFromRoute('ajax_core_requirejs');
// backend request, having backend user logged in
} else {
// backend request, having backend user logged in
$requireJsConfig = array_replace_recursive(
$this->publicRequireJsConfig,
$this->requireJsConfig
......@@ -1964,7 +1976,7 @@ class PageRenderer implements SingletonInterface
}
$this->loadJavaScriptLanguageStrings();
if (TYPO3_MODE === 'BE') {
if ($this->applicationType === 'BE') {
$noBackendUserLoggedIn = empty($GLOBALS['BE_USER']->user['uid']);
$this->addAjaxUrlsToInlineSettings($noBackendUserLoggedIn);
}
......@@ -2388,7 +2400,7 @@ class PageRenderer implements SingletonInterface
protected function doConcatenateJavaScript()
{
if ($this->concatenateJavascript) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'])) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['jsConcatenateHandler'])) {
// use external concatenation routine
$params = [
'jsLibs' => &$this->jsLibs,
......@@ -2397,7 +2409,7 @@ class PageRenderer implements SingletonInterface
'headerData' => &$this->headerData,
'footerData' => &$this->footerData
];
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsConcatenateHandler'], $params, $this);
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['jsConcatenateHandler'], $params, $this);
} else {
$this->jsLibs = $this->getCompressor()->concatenateJsFiles($this->jsLibs);
$this->jsFiles = $this->getCompressor()->concatenateJsFiles($this->jsFiles);
......@@ -2412,7 +2424,7 @@ class PageRenderer implements SingletonInterface
protected function doConcatenateCss()
{
if ($this->concatenateCss) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'])) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['cssConcatenateHandler'])) {
// use external concatenation routine
$params = [
'cssFiles' => &$this->cssFiles,
......@@ -2420,7 +2432,7 @@ class PageRenderer implements SingletonInterface
'headerData' => &$this->headerData,
'footerData' => &$this->footerData
];
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssConcatenateHandler'], $params, $this);
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['cssConcatenateHandler'], $params, $this);
} else {
$this->cssLibs = $this->getCompressor()->concatenateCssFiles($this->cssLibs);
$this->cssFiles = $this->getCompressor()->concatenateCssFiles($this->cssFiles);
......@@ -2443,7 +2455,7 @@ class PageRenderer implements SingletonInterface
protected function doCompressCss()
{
if ($this->compressCss) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'])) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['cssCompressHandler'])) {
// Use external compression routine
$params = [
'cssInline' => &$this->cssInline,
......@@ -2452,7 +2464,7 @@ class PageRenderer implements SingletonInterface
'headerData' => &$this->headerData,
'footerData' => &$this->footerData
];
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['cssCompressHandler'], $params, $this);
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['cssCompressHandler'], $params, $this);
} else {
$this->cssLibs = $this->getCompressor()->compressCssFiles($this->cssLibs);
$this->cssFiles = $this->getCompressor()->compressCssFiles($this->cssFiles);
......@@ -2466,7 +2478,7 @@ class PageRenderer implements SingletonInterface
protected function doCompressJavaScript()
{
if ($this->compressJavascript) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'])) {
if (!empty($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['jsCompressHandler'])) {
// Use external compression routine
$params = [
'jsInline' => &$this->jsInline,
......@@ -2477,7 +2489,7 @@ class PageRenderer implements SingletonInterface
'headerData' => &$this->headerData,
'footerData' => &$this->footerData
];
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['jsCompressHandler'], $params, $this);
GeneralUtility::callUserFunction($GLOBALS['TYPO3_CONF_VARS'][$this->applicationType]['jsCompressHandler'], $params, $this);
} else {
// Traverse the arrays, compress files
if (!empty($this->jsInline)) {
......@@ -2524,7 +2536,7 @@ class PageRenderer implements SingletonInterface
$filename = $this->getStreamlinedFileName($filename, false);
if ($this->compressJavascript) {
$filename = $this->getCompressor()->compressJsFile($filename);
} elseif (TYPO3_MODE === 'FE') {
} elseif ($this->applicationType === 'FE') {
$filename = GeneralUtility::createVersionNumberedFilename($filename);
}
return $this->getAbsoluteWebPath($filename);
......@@ -2570,7 +2582,7 @@ class PageRenderer implements SingletonInterface
*/
protected function getAbsoluteWebPath(string $file): string
{
if (TYPO3_MODE === 'FE') {
if ($this->applicationType === 'FE') {
return $file;
}
return PathUtility::getAbsoluteWebPath($file);
......
......@@ -293,7 +293,7 @@ abstract class AbstractRepository implements RepositoryInterface, SingletonInter
}
/**
* Function to return the current TYPO3_MODE based on $GLOBALS['TSFE'].
* Function to return the current application type based on $GLOBALS['TSFE'].
* This function can be mocked in unit tests to be able to test frontend behaviour.
*
* @return string
......
......@@ -134,7 +134,7 @@ class FileCollectionRepository
}
/**
* Function to return the current TYPO3_MODE (FE/BE) based on $GLOBALS[TSFE].
* Function to return the current application (FE/BE) based on $GLOBALS[TSFE].
* This function can be mocked in unit tests to be able to test frontend behaviour.
*
* @return string
......
......@@ -15,7 +15,9 @@
namespace TYPO3\CMS\Core\Resource;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
......@@ -38,7 +40,7 @@ class ResourceCompressor
protected $rootPath = '';
/**
* gzipped versions are only created if $TYPO3_CONF_VARS[TYPO3_MODE]['compressionLevel'] is set
* gzipped versions are only created if $TYPO3_CONF_VARS['BE' or 'FE']['compressionLevel'] is set
*
* @var bool
*/
......@@ -77,8 +79,13 @@ class ResourceCompressor
GeneralUtility::writeFile($htaccessPath, $this->htaccessTemplate);
}
}
// String 'FE' if in FrontendApplication, else 'BE' (also in CLI without request object)
// @todo: Usually, the ResourceCompressor similar to PageRenderer does not make sense if there is no request object ... restrict this?
$applicationType = ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend() ? 'FE' : 'BE';
// decide whether we should create gzipped versions or not
$compressionLevel = $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['compressionLevel'];
$compressionLevel = $GLOBALS['TYPO3_CONF_VARS'][$applicationType]['compressionLevel'];
// we need zlib for gzencode()
if (extension_loaded('zlib') && $compressionLevel) {
$this->createGzipped = true;
......@@ -87,7 +94,7 @@ class ResourceCompressor
$this->gzipCompressionLevel = (int)$compressionLevel;
}
}
$this->setRootPath(TYPO3_MODE === 'BE' ? Environment::getBackendPath() . '/' : Environment::getPublicPath() . '/');
$this->setRootPath($applicationType === 'BE' ? Environment::getBackendPath() . '/' : Environment::getPublicPath() . '/');
}
/**
......@@ -669,11 +676,11 @@ class ResourceCompressor
*/
protected function getJavaScriptFileType(): string
{
if (TYPO3_MODE === 'BE' || !isset($GLOBALS['TSFE']) || !($GLOBALS['TSFE'] instanceof TypoScriptFrontendController)) {
// Backend (or at least no TSFE), always HTML5
return '';
}
if (($GLOBALS['TSFE']->config['config']['doctype'] ?? 'html5') === 'html5') {
if (!isset($GLOBALS['TSFE'])
|| !($GLOBALS['TSFE'] instanceof TypoScriptFrontendController)
|| ($GLOBALS['TSFE']->config['config']['doctype'] ?? 'html5') === 'html5'
) {
// Backend, no TSFE, or doctype set to html5
return '';
}
return 'text/javascript';
......
......@@ -15,11 +15,13 @@
namespace TYPO3\CMS\Core\Resource;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Collection\CollectionInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Resource\Collection\FileCollectionRegistry;
use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
......@@ -476,7 +478,10 @@ class ResourceFactory implements SingletonInterface
*/
protected function getFileReferenceData($uid, $raw = false)
{
if (!$raw && TYPO3_MODE === 'BE') {
if (!$raw
&& ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
) {
$fileReferenceData = BackendUtility::getRecordWSOL('sys_file_reference', $uid);
} elseif (!$raw && is_object($GLOBALS['TSFE'])) {
$fileReferenceData = $GLOBALS['TSFE']->sys_page->checkRecord('sys_file_reference', $uid);
......
......@@ -17,8 +17,10 @@ namespace TYPO3\CMS\Core\Resource;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Http\FalDumpFileContentsDecoratorStream;
use TYPO3\CMS\Core\Http\Response;
use TYPO3\CMS\Core\Log\LogManager;
......@@ -476,8 +478,10 @@ class ResourceStorage implements ResourceStorageInterface
$this->isOnline = false;
}
if ($this->isOnline !== false) {
// all files are ALWAYS available in the frontend
if (TYPO3_MODE === 'FE') {
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
) {
// All files are ALWAYS available in the frontend
$this->isOnline = true;
} else {
// check if the storage is disabled temporary for now
......