Skip to content
Merged
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
14 changes: 9 additions & 5 deletions Classes/ContentObject/JsonContentContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function render($conf = []): string
/**
* @param array<string, mixed> $contentElements
* @param array<string, mixed> $conf
* @return array<string,<array<int, mixed>>
* @return array<string, array<int, mixed>>
*/
protected function groupContentElementsByColPos(array $contentElements, array $conf): array
{
Expand All @@ -167,11 +167,12 @@ protected function groupContentElementsByColPos(array $contentElements, array $c
$element = $this->headlessUserInt->wrap($element);
}

$element = json_decode($element, true);
$decoded = json_decode($element, true);

if ($element === []) {
if (!is_array($decoded) || $decoded === []) {
continue;
}
$element = $decoded;

$colPos = $this->getColPosFromElement($groupingEnabled, $element);

Expand All @@ -184,11 +185,14 @@ protected function groupContentElementsByColPos(array $contentElements, array $c

if ($groupingEnabled && $this->isSortByBackendLayoutEnabled($conf)) {
$backendLayoutView = GeneralUtility::makeInstance(BackendLayoutView::class);
$backendLayout = $backendLayoutView->getSelectedBackendLayout($this->request->getAttribute('routing')->getPageId());
$routing = $this->request->getAttribute('routing');
$backendLayout = $routing !== null
? $backendLayoutView->getSelectedBackendLayout($routing->getPageId())
: null;

$sorted = [];
foreach ($backendLayout['__colPosList'] ?? [] as $value) {
$sorted['colPos' . $value] = $data['colPos' . $value];
$sorted['colPos' . $value] = $data['colPos' . $value] ?? [];
}

$data = $sorted;
Expand Down
8 changes: 4 additions & 4 deletions Classes/ContentObject/JsonContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public function __construct(
*/
public function render($conf = []): string
{
if (!is_array($conf)) {
$conf = [];
}

if (!empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) {
return '';
}

$data = [];

if (!is_array($conf)) {
$conf = [];
}

$this->conf = $conf;

if (isset($conf['fields.'])) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/DataProcessing/DataProcessingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function removeDataIfnotAppendInConfiguration(array $processorConfigur

protected function isMenuProcessor(): bool
{
return __CLASS__ === MenuProcessor::class;
return $this instanceof MenuProcessor;
}

/**
Expand Down
14 changes: 9 additions & 5 deletions Classes/DataProcessing/ExtractPropertyProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ public function process(

$key = GeneralUtility::trimExplode('.', $processorConfiguration['key'], true);

// Extract (nested) property
do {
$processedData = $processedData[array_shift($key)] ?? null;
} while (count($key));
$value = $processedData;
foreach ($key as $segment) {
if (!is_array($value)) {
$value = null;
break;
}
$value = $value[$segment] ?? null;
}

return [
$targetFieldName => $processedData,
$targetFieldName => $value,
];
}
}
15 changes: 15 additions & 0 deletions Classes/DataProcessing/FilesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,27 @@ public function process(
$this->defaults['as']
);

if (!$this->hasFileSources($processorConfiguration)) {
$processedData[$targetFieldName] = [];
return $this->removeDataIfnotAppendInConfiguration($processorConfiguration, $processedData);
}

$this->fileObjects = $this->fetchData();
$processedData[$targetFieldName] = $this->processFiles($properties);

return $this->removeDataIfnotAppendInConfiguration($processorConfiguration, $processedData);
}

private function hasFileSources(array $processorConfiguration): bool
{
foreach (['references', 'references.', 'files', 'files.', 'collections', 'collections.', 'folders', 'folders.'] as $key) {
if (!empty($processorConfiguration[$key])) {
return true;
}
}
return false;
}

/**
* @return array
*/
Expand Down
5 changes: 3 additions & 2 deletions Classes/DataProcessing/RootSiteProcessing/DomainSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public function process(SiteProviderInterface $provider, array $options = []): a
$result = [];

foreach ($provider->getSites() as $site) {
$urlUtility = $this->urlUtility->withSite($site);
$protocol = $site->getBase()->getScheme() . '://';
$baseUrl = $protocol . $site->getBase()->getHost();
$url = $this->urlUtility->getFrontendUrlForPage($baseUrl, $site->getRootPageId());
$url = $urlUtility->getFrontendUrlForPage($baseUrl, $site->getRootPageId());

$locales = [];

Expand All @@ -57,7 +58,7 @@ public function process(SiteProviderInterface $provider, array $options = []): a
'name' => str_replace($protocol, '', $url),
'baseURL' => $url,
'api' => [
'baseURL' => $this->urlUtility->getProxyUrl(),
'baseURL' => $urlUtility->getProxyUrl(),
],
'i18n' => [
'locales' => $locales,
Expand Down
6 changes: 2 additions & 4 deletions Classes/DataProcessing/RootSiteProcessing/SiteProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ public function prepare(array $config, int $siteUid): self
$sorting = GeneralUtility::makeInstance($customSorting, $sites, $pages, $sortingField);
$sites = $sorting->sort();
} else {
usort($sites, static function (Site $siteA, Site $siteB) use ($pages, $sortingField) {
// phpcs:ignore Generic.Files.LineLength
return (int)$pages[$siteA->getRootPageId()][$sortingField] >= (int)$pages[$siteB->getRootPageId()][$sortingField] ? 1 : -1;
});
usort($sites, static fn(Site $siteA, Site $siteB): int =>
(int)$pages[$siteA->getRootPageId()][$sortingField] <=> (int)$pages[$siteB->getRootPageId()][$sortingField]);
}

$this->sites = $sites;
Expand Down
8 changes: 4 additions & 4 deletions Classes/Event/Listener/AfterLinkIsGeneratedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,16 @@ private function resolveTypolinkParameterString(string $mixedLinkParameter, arra
)) {
// Disallow insecure scheme's like javascript: or data:
throw new UnableToLinkException(
'Insuecure scheme for linking detected with "' . $mixedLinkParameter . "'",
'Insecure scheme for linking detected with "' . $mixedLinkParameter . "'",
1641986533
);
}

// additional parameters that need to be set
if (($linkParameterParts['additionalParams'] ?? '') !== '') {
$forceParams = $linkParameterParts['additionalParams'];
// params value
$linkConfiguration['additionalParams'] = ($linkConfiguration['additionalParams'] ?? '') . $forceParams[0] === '&' ? $forceParams : '&' . $forceParams;
$forceParams = (string)$linkParameterParts['additionalParams'];
$prefix = $forceParams[0] === '&' ? '' : '&';
$linkConfiguration['additionalParams'] = ($linkConfiguration['additionalParams'] ?? '') . $prefix . $forceParams;
}

return [
Expand Down
15 changes: 9 additions & 6 deletions Classes/Event/Listener/RedirectUrlAdditionalParamsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;

use function parse_str;
use function strpos;
use function parse_url;
use function str_contains;

class RedirectUrlAdditionalParamsListener implements LoggerAwareInterface
{
Expand Down Expand Up @@ -61,14 +62,16 @@ public function __invoke(RedirectUrlEvent $event): void
);
$redirectTarget = $linkParameterParts['url'] ?? '';
$linkDetails = $this->resolveLinkDetailsFromLinkTarget($redirectTarget);
$additionalParams = (string)($linkParameterParts['additionalParams'] ?? '');

if (($linkDetails['type'] === LinkService::TYPE_PAGE) &&
strpos($linkParameterParts['additionalParams'], '[action]=') > 0 &&
strpos($linkParameterParts['additionalParams'], '[controller]=') > 0) {
if (($linkDetails['type'] ?? null) === LinkService::TYPE_PAGE &&
str_contains($additionalParams, '[action]=') &&
str_contains($additionalParams, '[controller]=')) {
try {
$site = $request->getAttribute('site');
parse_str($linkParameterParts['url'], $typolinkData);
parse_str($linkParameterParts['additionalParams'], $params);
$urlQuery = parse_url((string)($linkParameterParts['url'] ?? ''), PHP_URL_QUERY) ?? '';
parse_str($urlQuery, $typolinkData);
parse_str($additionalParams, $params);

$languageId = isset($typolinkData['L']) ? (int)$typolinkData['L'] : 0;

Expand Down
5 changes: 4 additions & 1 deletion Classes/Resource/Rendering/AudioTagRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
class AudioTagRenderer extends \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer
{
private ?FileUtility $fileUtility = null;

public function getPriority(): int
{
return 2;
Expand All @@ -39,7 +41,8 @@ public function getPriority(): int
public function render(FileInterface $file, $width, $height, array $options = []): string
{
if (($options['returnUrl'] ?? false) === true) {
return htmlspecialchars(GeneralUtility::makeInstance(FileUtility::class)->getAbsoluteUrl($file->getPublicUrl()), ENT_QUOTES | ENT_HTML5);
$fileUtility = $this->fileUtility ??= GeneralUtility::makeInstance(FileUtility::class);
return htmlspecialchars($fileUtility->getAbsoluteUrl($file->getPublicUrl()), ENT_QUOTES | ENT_HTML5);
}
return parent::render(...func_get_args());
}
Expand Down
5 changes: 4 additions & 1 deletion Classes/Resource/Rendering/VideoTagRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
class VideoTagRenderer extends \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer
{
private ?FileUtility $fileUtility = null;

public function getPriority(): int
{
return 2;
Expand All @@ -40,7 +42,8 @@ public function getPriority(): int
public function render(FileInterface $file, $width, $height, array $options = []): string
{
if (($options['returnUrl'] ?? false) === true) {
return htmlspecialchars(GeneralUtility::makeInstance(FileUtility::class)->getAbsoluteUrl($file->getPublicUrl()), ENT_QUOTES | ENT_HTML5);
$fileUtility = $this->fileUtility ??= GeneralUtility::makeInstance(FileUtility::class);
return htmlspecialchars($fileUtility->getAbsoluteUrl($file->getPublicUrl()), ENT_QUOTES | ENT_HTML5);
}
return parent::render(...func_get_args());
}
Expand Down
11 changes: 9 additions & 2 deletions Classes/Seo/MetaTag/AbstractMetaTagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
*/
abstract class AbstractMetaTagManager extends \TYPO3\CMS\Core\MetaTag\AbstractMetaTagManager
{
private ?HeadlessModeInterface $headlessMode = null;

private function getHeadlessMode(): HeadlessModeInterface
{
return $this->headlessMode ??= GeneralUtility::makeInstance(HeadlessModeInterface::class);
}

public function renderAllProperties(): string
{
if (GeneralUtility::makeInstance(HeadlessModeInterface::class)->withRequest($GLOBALS['TYPO3_REQUEST'])->isEnabled()) {
if ($this->getHeadlessMode()->withRequest($GLOBALS['TYPO3_REQUEST'])->isEnabled()) {
return $this->renderAllHeadlessProperties();
}

Expand All @@ -34,7 +41,7 @@ public function renderAllProperties(): string

public function renderProperty(string $property): string
{
if (GeneralUtility::makeInstance(HeadlessModeInterface::class)->withRequest($GLOBALS['TYPO3_REQUEST'])->isEnabled()) {
if ($this->getHeadlessMode()->withRequest($GLOBALS['TYPO3_REQUEST'])->isEnabled()) {
return $this->renderHeadlessProperty($property);
}

Expand Down
26 changes: 14 additions & 12 deletions Classes/Utility/FileUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public function process(FileInterface $fileReference, ProcessingConfiguration $p

private function onDemandProperties(ProcessingConfiguration $processingConfiguration, array $properties): array
{
$processed = [];
$props = [];

foreach ($processingConfiguration->includeProperties as $prop) {
Expand Down Expand Up @@ -246,7 +245,7 @@ private function onDemandProperties(ProcessingConfiguration $processingConfigura
}
}

return array_merge($processed, $props);
return $props;
}

private function filterProperties(ProcessingConfiguration $processingConfiguration, array $properties): array
Expand Down Expand Up @@ -329,7 +328,7 @@ public function getAbsoluteUrl(string $fileUrl): string
$siteUrl = $this->getNormalizedParams()->getSiteUrl();
$sitePath = str_replace($this->getNormalizedParams()->getRequestHost(), '', $siteUrl);
$absoluteUrl = trim($fileUrl);
if (stripos($absoluteUrl, 'http') !== 0) {
if (stripos($absoluteUrl, 'http') !== 0 && !str_starts_with($absoluteUrl, '//')) {
$fileUrl = preg_replace('#^' . preg_quote($sitePath, '#') . '#', '', $fileUrl);
$fileUrl = $siteUrl . $fileUrl;
}
Expand Down Expand Up @@ -377,9 +376,12 @@ protected function getNormalizedParams(): NormalizedParams
return $this->contentObjectRenderer->getRequest()->getAttribute('normalizedParams');
}

/** @var array<string, CropVariantCollection> */
private array $cropVariantCache = [];

protected function createCropVariant(string $cropString): CropVariantCollection
{
return CropVariantCollection::create($cropString);
return $this->cropVariantCache[$cropString] ??= CropVariantCollection::create($cropString);
}

/**
Expand All @@ -396,8 +398,8 @@ private function processAutogenerate(
array $processedFile,
ProcessingConfiguration $processingConfiguration
): array {
$originalWidth = $originalReference->getProperty('width');
$originalHeight = $originalReference->getProperty('height');
$originalWidth = $this->getCroppedDimensionalProperty($originalReference, 'width', $processingConfiguration->cropVariant);
$originalHeight = $this->getCroppedDimensionalProperty($originalReference, 'height', $processingConfiguration->cropVariant);
$targetWidth = (int)($processingConfiguration->width !== '' ? $processingConfiguration->width : $fileReference->getProperty('width'));
$targetHeight = (int)($processingConfiguration->height !== '' ? $processingConfiguration->height : $fileReference->getProperty('height'));

Expand Down Expand Up @@ -436,14 +438,14 @@ public function processCropVariants(
*/
$crop = $originalFileReference->getProperty('crop');

if ($crop !== null) {
if ($crop !== null && $crop !== '') {
if (!$processingConfiguration->legacyReturn) {
unset($processedFile['crop'], $processedFile['properties']['crop']);
}

$cropVariants = json_decode($originalFileReference->getProperty('crop'), true);
$cropVariants = json_decode($crop, true);

$collection = CropVariantCollection::create($originalFileReference->getProperty('crop'));
$collection = $this->createCropVariant($crop);

if (is_array($cropVariants) && count($cropVariants) > 1 && str_starts_with(
$originalFileReference->getMimeType(),
Expand All @@ -454,10 +456,10 @@ public function processCropVariants(
continue;
}

$processingConfiguration = $processingConfiguration->withOptions(['cropVariant' => $cropVariantName]);
$file = $this->process($originalFileReference, $processingConfiguration);
$variantConfiguration = $processingConfiguration->withOptions(['cropVariant' => $cropVariantName]);
$file = $this->process($originalFileReference, $variantConfiguration);
$processedFile['cropVariants'][$cropVariantName] = $this->cropVariant(
$processingConfiguration,
$variantConfiguration,
$file,
$cropVariants[$cropVariantName]
);
Expand Down
5 changes: 3 additions & 2 deletions Classes/Utility/HeadlessUserInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function unwrap(string $content): string

protected function buildPattern(string $primary, string $nullable): string
{
return self::$regexPatterns[$primary] ??= sprintf(
return self::$regexPatterns[$primary . '|' . $nullable] ??= sprintf(
self::REGEX,
preg_quote($nullable, '/'),
preg_quote($primary, '/')
Expand All @@ -98,7 +98,8 @@ protected function replace(array $m, bool $isNullable): string
return $rawContent;
}

return json_encode($rawContent);
$encoded = json_encode($rawContent);
return $encoded !== false ? $encoded : 'null';
}

$jsonEncoded = json_encode($rawContent);
Expand Down
Loading
Loading