Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Abuse of storage 0 for extension resources #1100

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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