Skip to content

Commit

Permalink
[BUGFIX] Abuse of storage 0 for extension resources
Browse files Browse the repository at this point in the history
This patch makes sure the virtual storage 0 is not longer abused by the
StaticFilesProcessor. Therefor the StaticFilesProcessor now returns URIs
of the provided files and not longer FILE objects.

All `EXT:` references are now properly resolved through
`PathUtility::getPublicResourceWebPath()` if available (TYPO3 11.4.0 and
higher) or by providing an absolute path to
`PathUtility::getAbsoluteWebPath`.

FAL resources are resolved using `PathUtility::getAbsoluteWebPath` also
by providing an absolute path.

The new behavior is disabled by default and can be enabled by setting
"compatibilityMode" to "false".
  • Loading branch information
gilbertsoft committed Oct 11, 2021
1 parent 5bde1c5 commit 9992238
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
parameters:
ignoreErrors:
-
message: "#^Call to function method_exists\\(\\) with 'TYPO3\\\\\\\\CMS\\\\\\\\Core\\\\\\\\Utility\\\\\\\\PathUtility' and 'getPublicResourceWe…' will always evaluate to true\\.$#"
count: 1
path: ../Classes/DataProcessing/StaticFilesProcessor.php

-
message: "#^Call to an undefined static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\PathUtility::getPublicResourceWebPath\\(\\).$#"
count: 1
path: ../Classes/DataProcessing/StaticFilesProcessor.php

-
message:
"""
Expand Down
37 changes: 32 additions & 5 deletions Classes/DataProcessing/StaticFilesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;

/**
* This processor generates a set of file objects.
* This processor generates a set of file objects (deprecated) or URIs.
*
* 10 = BK2K\BootstrapPackage\DataProcessing\StaticFilesProcessor
* 10 {
Expand All @@ -24,6 +25,7 @@
* 1 = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-1.png
* circle = EXT:bootstrap_package/Resources/Public/Images/Icons/icon-circle.png
* }
* compatibilityMode = false
* as = staticFiles
* }
*/
Expand Down Expand Up @@ -55,15 +57,31 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
}
}

// Get file objects
// Get file objects (deprecated) or URI for each file
$images = [];
if (count($files) !== 0) {
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
// @todo: compat fallback, will be removed with v13
$resourceFactory = null;
if ($this->isCompatibilityMode($processorConfiguration)) {
trigger_error(
'The resolvement to FILE objects is deprecated and will stop working in Bootstrap Package 13.0. Change your Fluid templates properly and set "compatibilityMode" to "false".',
E_USER_DEPRECATED
);
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
}

foreach ($files as $key => $file) {
$absFilename = GeneralUtility::getFileAbsFileName($file);
if (file_exists($absFilename)) {
// Do not use absolute file name to ensure correct path resolution from ResourceFactory.
$images[$key] = $resourceFactory->retrieveFileOrFolderObject($file);
if ($resourceFactory instanceof ResourceFactory) {
// @todo: compat fallback, will be removed with v13
// Do not use absolute file name to ensure correct path resolution from ResourceFactory.
$images[$key] = $resourceFactory->retrieveFileOrFolderObject($file);
} elseif (str_starts_with($file, 'EXT:') && method_exists(PathUtility::class, 'getPublicResourceWebPath')) {
$images[$key] = PathUtility::getPublicResourceWebPath($file);
} else {
$images[$key] = PathUtility::getAbsoluteWebPath($absFilename);
}
}
}
}
Expand All @@ -78,4 +96,13 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu

return $processedData;
}

/**
* @param array $processorConfiguration The configuration of this processor
* @return bool
*/
private function isCompatibilityMode(array $processorConfiguration)
{
return !isset($processorConfiguration['compatibilityMode']) || $processorConfiguration['compatibilityMode'] !== 'false';
}
}
1 change: 1 addition & 0 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ page {
normal = {$page.logo.file}
inverted = {$page.logo.fileInverted}
}
compatibilityMode = false
as = logo
}
}
Expand Down
4 changes: 2 additions & 2 deletions Resources/Private/Partials/Page/Header/Logo.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<f:link.page pageUid="{rootPage}" class="navbar-brand navbar-brand-{f:if(condition: logo.normal, then: 'image', else: 'text')}" title="{settings.logo.linktitle}">
<f:if condition="{logo.normal}">
<f:then>
<img class="navbar-brand-logo-normal" src="{f:uri.image(image: logo.normal)}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
<img class="navbar-brand-logo-normal" src="{logo.normal}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
<f:if condition="{logo.inverted}">
<img class="navbar-brand-logo-inverted" src="{f:uri.image(image: logo.inverted)}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
<img class="navbar-brand-logo-inverted" src="{logo.inverted}" alt="{logoAlt}" height="{settings.logo.height}" width="{settings.logo.width}">
</f:if>
</f:then>
<f:else>
Expand Down

0 comments on commit 9992238

Please sign in to comment.