Skip to content

Commit d18dd34

Browse files
authored
Merge pull request #58 from mediaessenz/v13-compat
Add TYPO3 13 compatibility
2 parents ec0d529 + 9060fb6 commit d18dd34

11 files changed

+82
-387
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ jobs:
3737
fast_finish: true
3838
include:
3939
- stage: test
40-
php: 7.2
41-
env: TYPO3=^8.7
40+
php: 8.2
41+
env: TYPO3=^12.4
4242
- stage: test
43-
php: 7.2
44-
env: TYPO3=^9.5
43+
php: 8.2
44+
env: TYPO3=^13.4
4545

4646
- stage: publish to ter
4747
if: tag IS present
48-
php: 7.2
48+
php: 8.2
4949
before_install: skip
5050
install: skip
5151
before_script: skip

Classes/JumpUrlProcessor.php

-222
This file was deleted.

Classes/Middleware/JumpUrlHandler.php

+35-13
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@
1919
use Psr\Http\Message\ServerRequestInterface;
2020
use Psr\Http\Server\MiddlewareInterface;
2121
use Psr\Http\Server\RequestHandlerInterface;
22+
use TYPO3\CMS\Core\Cache\CacheManager;
2223
use TYPO3\CMS\Core\Core\Environment;
2324
use TYPO3\CMS\Core\Http\RedirectResponse;
2425
use TYPO3\CMS\Core\Information\Typo3Version;
2526
use TYPO3\CMS\Core\Resource\ResourceFactory;
2627
use TYPO3\CMS\Core\Resource\Security\FileNameValidator;
28+
use TYPO3\CMS\Core\Site\Entity\NullSite;
2729
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
30+
use TYPO3\CMS\Core\TypoScript\PageTsConfig;
31+
use TYPO3\CMS\Core\TypoScript\PageTsConfigFactory;
2832
use TYPO3\CMS\Core\Utility\GeneralUtility;
2933
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
3034

@@ -69,7 +73,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6973
}
7074
// Regular jump URL
7175
$this->validateIfJumpUrlRedirectIsAllowed($jumpUrl, $juHash);
72-
return $this->redirectToJumpUrl($jumpUrl);
76+
return $this->redirectToJumpUrl($jumpUrl, $request);
7377
}
7478
return $handler->handle($request);
7579
}
@@ -81,9 +85,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
8185
* @throws \Exception
8286
* @return ResponseInterface
8387
*/
84-
protected function redirectToJumpUrl(string $jumpUrl): ResponseInterface
88+
protected function redirectToJumpUrl(string $jumpUrl, ServerRequestInterface $request): ResponseInterface
8589
{
86-
$pageTSconfig = $this->getTypoScriptFrontendController()->getPagesTSconfig();
90+
$pageTSconfig = $this->getPageTsConfig($request);
8791
$pageTSconfig = array_key_exists('TSFE.', $pageTSconfig) && is_array($pageTSconfig['TSFE.'] ?? false) ? $pageTSconfig['TSFE.'] : [];
8892

8993
// Allow sections in links
@@ -94,6 +98,30 @@ protected function redirectToJumpUrl(string $jumpUrl): ResponseInterface
9498
return new RedirectResponse($jumpUrl, $statusCode);
9599
}
96100

101+
/**
102+
* @param ServerRequestInterface $request
103+
* @return array
104+
* @throws \JsonException
105+
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
106+
*/
107+
protected function getPageTsConfig(ServerRequestInterface $request): array
108+
{
109+
$pageInformation = $request->getAttribute('frontend.page.information');
110+
$id = $pageInformation->getId();
111+
$runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
112+
$pageTsConfig = $runtimeCache->get('pageTsConfig-' . $id);
113+
if ($pageTsConfig instanceof PageTsConfig) {
114+
return $pageTsConfig->getPageTsConfigArray();
115+
}
116+
$fullRootLine = $pageInformation->getRootLine();
117+
ksort($fullRootLine);
118+
$site = $request->getAttribute('site') ?? new NullSite();
119+
$pageTsConfigFactory = GeneralUtility::makeInstance(PageTsConfigFactory::class);
120+
$pageTsConfig = $pageTsConfigFactory->create($fullRootLine, $site);
121+
$runtimeCache->set('pageTsConfig-' . $id, $pageTsConfig);
122+
return $pageTsConfig->getPageTsConfigArray();
123+
}
124+
97125
/**
98126
* If the submitted hash is correct and the user has access to the
99127
* related content element the contents of the submitted file will
@@ -126,15 +154,9 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio
126154

127155
// Check if requested file accessable
128156
$fileAccessAllowed = false;
129-
if ((new Typo3Version())->getMajorVersion() < 11) {
130-
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
131-
&& GeneralUtility::verifyFilenameAgainstDenyPattern($absoluteFileName)
132-
&& !GeneralUtility::isFirstPartOfStr($absoluteFileName, Environment::getLegacyConfigPath());
133-
} else {
134-
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
135-
&& GeneralUtility::makeInstance(FileNameValidator::class)->isValid($absoluteFileName)
136-
&& !str_starts_with($absoluteFileName, Environment::getLegacyConfigPath());
137-
}
157+
$fileAccessAllowed = GeneralUtility::isAllowedAbsPath($absoluteFileName)
158+
&& GeneralUtility::makeInstance(FileNameValidator::class)->isValid($absoluteFileName)
159+
&& !str_starts_with($absoluteFileName, Environment::getLegacyConfigPath());
138160
if (!$fileAccessAllowed) {
139161
throw new \Exception('The requested file was not allowed to be accessed through Jump URL. The path or file is not allowed.', 1294585194);
140162
}
@@ -157,7 +179,7 @@ protected function forwardJumpUrlSecureFileData(string $jumpUrl, string $locatio
157179
protected function isLocationDataValid(string $locationData): bool
158180
{
159181
$isValidLocationData = false;
160-
list($pageUid, $table, $recordUid) = explode(':', $locationData);
182+
[$pageUid, $table, $recordUid] = explode(':', $locationData);
161183
$pageRepository = $this->getTypoScriptFrontendController()->sys_page;
162184
if (empty($table) || $pageRepository->checkRecord($table, $recordUid, true)) {
163185
// This check means that a record is checked only if the locationData has a value for a

0 commit comments

Comments
 (0)