|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// @todo: self::getAbsRefPrefixFromTSFE() returns false instead of string. |
|
4
|
|
|
// Solve that issue and activate strict types. |
|
5
|
|
|
//declare(strict_types=1); |
|
6
|
|
|
|
|
7
|
|
|
/* |
|
8
|
|
|
* This file is part of the TYPO3 CMS project. |
|
9
|
|
|
* |
|
10
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
11
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
12
|
|
|
* of the License, or any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, please read the |
|
15
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
16
|
|
|
* |
|
17
|
|
|
* The TYPO3 project - inspiring people to share! |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace ApacheSolrForTypo3\Solr\FrontendEnvironment; |
|
21
|
|
|
|
|
22
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationPageResolver; |
|
23
|
|
|
use Doctrine\DBAL\Driver\Exception as DBALDriverException; |
|
24
|
|
|
use Throwable; |
|
25
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
26
|
|
|
use TYPO3\CMS\Core\Context\Context; |
|
27
|
|
|
use TYPO3\CMS\Core\Context\LanguageAspectFactory; |
|
28
|
|
|
use TYPO3\CMS\Core\Context\TypoScriptAspect; |
|
29
|
|
|
use TYPO3\CMS\Core\Context\UserAspect; |
|
30
|
|
|
use TYPO3\CMS\Core\Context\VisibilityAspect; |
|
31
|
|
|
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; |
|
32
|
|
|
use TYPO3\CMS\Core\Domain\Repository\PageRepository; |
|
33
|
|
|
use TYPO3\CMS\Core\Exception\SiteNotFoundException; |
|
34
|
|
|
use TYPO3\CMS\Core\Http\ServerRequest; |
|
35
|
|
|
use TYPO3\CMS\Core\Localization\Locales; |
|
36
|
|
|
use TYPO3\CMS\Core\Routing\PageArguments; |
|
37
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
38
|
|
|
use TYPO3\CMS\Core\Site\SiteFinder; |
|
39
|
|
|
use TYPO3\CMS\Core\TypoScript\TemplateService; |
|
40
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
41
|
|
|
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; |
|
42
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Class Tsfe is a factory class for TSFE(TypoScriptFrontendController) objects. |
|
46
|
|
|
*/ |
|
47
|
|
|
class Tsfe implements SingletonInterface |
|
48
|
|
|
{ |
|
49
|
|
|
/** |
|
50
|
|
|
* @var TypoScriptFrontendController[] |
|
51
|
|
|
*/ |
|
52
|
|
|
protected array $tsfeCache = []; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var ServerRequest[] |
|
56
|
|
|
*/ |
|
57
|
|
|
protected array $serverRequestCache = []; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var SiteFinder |
|
61
|
|
|
*/ |
|
62
|
|
|
protected SiteFinder $siteFinder; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Initializes isolated TypoScriptFrontendController for Indexing and backend actions. |
|
66
|
|
|
* |
|
67
|
|
|
* @param SiteFinder|null $siteFinder |
|
68
|
|
|
*/ |
|
69
|
209 |
|
public function __construct(?SiteFinder $siteFinder = null) |
|
70
|
|
|
{ |
|
71
|
209 |
|
$this->siteFinder = $siteFinder ?? GeneralUtility::makeInstance(SiteFinder::class); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Initializes the TSFE for a given page ID and language. |
|
76
|
|
|
* |
|
77
|
|
|
* @param int $pageId |
|
78
|
|
|
* @param int $language |
|
79
|
|
|
* |
|
80
|
|
|
* @param int|null $rootPageId |
|
81
|
|
|
* |
|
82
|
|
|
* @throws DBALDriverException |
|
83
|
|
|
* @throws Exception\Exception |
|
84
|
|
|
* @throws SiteNotFoundException |
|
85
|
|
|
* |
|
86
|
|
|
* |
|
87
|
|
|
* @todo: Move whole caching stuff from this method and let return TSFE. |
|
88
|
|
|
*/ |
|
89
|
209 |
|
protected function initializeTsfe(int $pageId, int $language = 0, ?int $rootPageId = null) |
|
90
|
|
|
{ |
|
91
|
209 |
|
$cacheIdentifier = $this->getCacheIdentifier($pageId, $language, $rootPageId); |
|
92
|
|
|
|
|
93
|
|
|
// Handle spacer and sys-folders, since they are not accessible in frontend, and TSFE can not be fully initialized on them. |
|
94
|
|
|
// Apart from this, the plugin.tx_solr.index.queue.[indexConfig].additionalPageIds is handled as well. |
|
95
|
209 |
|
$pidToUse = $this->getPidToUseForTsfeInitialization($pageId, $rootPageId); |
|
96
|
209 |
|
if ($pidToUse !== $pageId) { |
|
97
|
4 |
|
$this->initializeTsfe($pidToUse, $language, $rootPageId); |
|
|
|
|
|
|
98
|
4 |
|
$reusedCacheIdentifier = $this->getCacheIdentifier($pidToUse, $language, $rootPageId); |
|
|
|
|
|
|
99
|
4 |
|
$this->serverRequestCache[$cacheIdentifier] = $this->serverRequestCache[$reusedCacheIdentifier]; |
|
100
|
4 |
|
$this->tsfeCache[$cacheIdentifier] = $this->tsfeCache[$reusedCacheIdentifier]; |
|
101
|
|
|
// if ($rootPageId === null) { |
|
102
|
|
|
// // @Todo: Resolve and set TSFE object for $rootPageId. |
|
103
|
|
|
// } |
|
104
|
4 |
|
return; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/* @var Context $context */ |
|
108
|
209 |
|
$context = clone GeneralUtility::makeInstance(Context::class); |
|
109
|
209 |
|
$site = $this->siteFinder->getSiteByPageId($pageId); |
|
110
|
|
|
// $siteLanguage and $languageAspect takes the language id into account. |
|
111
|
|
|
// See: $site->getLanguageById($language); |
|
112
|
|
|
// Therefore the whole TSFE stack is initialized and must be used as is. |
|
113
|
|
|
// Note: ServerRequest, Context, Language, cObj of TSFE MUST NOT be changed or touched in any way, |
|
114
|
|
|
// Otherwise the caching of TSFEs makes no sense anymore. |
|
115
|
|
|
// If you want something to change in TSFE object, please use cloned one! |
|
116
|
209 |
|
$siteLanguage = $site->getLanguageById($language); |
|
117
|
209 |
|
$languageAspect = LanguageAspectFactory::createFromSiteLanguage($siteLanguage); |
|
118
|
209 |
|
$context->setAspect('language', $languageAspect); |
|
119
|
|
|
|
|
120
|
209 |
|
$serverRequest = $this->serverRequestCache[$cacheIdentifier] ?? null; |
|
121
|
209 |
|
if (!isset($this->serverRequestCache[$cacheIdentifier])) { |
|
122
|
209 |
|
$serverRequest = GeneralUtility::makeInstance(ServerRequest::class); |
|
123
|
209 |
|
$this->serverRequestCache[$cacheIdentifier] = $serverRequest = |
|
124
|
209 |
|
$serverRequest->withAttribute('site', $site) |
|
125
|
209 |
|
->withAttribute('language', $siteLanguage) |
|
126
|
209 |
|
->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE) |
|
127
|
209 |
|
->withUri($site->getBase()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
209 |
|
if (!isset($this->tsfeCache[$cacheIdentifier])) { |
|
131
|
|
|
// TYPO3 by default enables a preview mode if a backend user is logged in, |
|
132
|
|
|
// the VisibilityAspect is configured to show hidden elements. |
|
133
|
|
|
// Due to this setting hidden relations/translations might be indexed |
|
134
|
|
|
// when running the Solr indexer via the TYPO3 backend. |
|
135
|
|
|
// To avoid this, the VisibilityAspect is adapted for indexing. |
|
136
|
209 |
|
$context->setAspect( |
|
137
|
|
|
'visibility', |
|
138
|
209 |
|
GeneralUtility::makeInstance( |
|
139
|
|
|
VisibilityAspect::class, |
|
140
|
|
|
false, |
|
141
|
|
|
false |
|
142
|
|
|
) |
|
143
|
|
|
); |
|
144
|
|
|
|
|
145
|
|
|
/** @var FrontendUserAuthentication $feUser */ |
|
146
|
209 |
|
$feUser = GeneralUtility::makeInstance(FrontendUserAuthentication::class); |
|
147
|
|
|
// for certain situations we need to trick TSFE into granting us |
|
148
|
|
|
// access to the page in any case to make getPageAndRootline() work |
|
149
|
|
|
// see http://forge.typo3.org/issues/42122 |
|
150
|
209 |
|
$pageRecord = BackendUtility::getRecord('pages', $pageId, 'fe_group'); |
|
151
|
209 |
|
if (!empty($pageRecord['fe_group'])) { |
|
152
|
1 |
|
$userGroups = explode(',', $pageRecord['fe_group']); |
|
153
|
|
|
} else { |
|
154
|
209 |
|
$userGroups = [0, -1]; |
|
155
|
|
|
} |
|
156
|
209 |
|
$feUser->user = ['uid' => 0, 'username' => '', 'usergroup' => implode(',', $userGroups) ]; |
|
157
|
209 |
|
$feUser->fetchGroupData(); |
|
158
|
209 |
|
$context->setAspect('frontend.user', GeneralUtility::makeInstance(UserAspect::class, $feUser, $userGroups)); |
|
159
|
|
|
|
|
160
|
|
|
/* @var PageArguments $pageArguments */ |
|
161
|
209 |
|
$pageArguments = GeneralUtility::makeInstance(PageArguments::class, $pageId, 0, []); |
|
162
|
|
|
|
|
163
|
|
|
/* @var TypoScriptFrontendController $tsfe */ |
|
164
|
209 |
|
$tsfe = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $context, $site, $siteLanguage, $pageArguments, $feUser); |
|
165
|
|
|
|
|
166
|
|
|
// @extensionScannerIgnoreLine |
|
167
|
|
|
/** Done in {@link \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::settingLanguage} */ |
|
168
|
|
|
//$tsfe->sys_page = GeneralUtility::makeInstance(PageRepository::class); |
|
169
|
|
|
|
|
170
|
209 |
|
$template = GeneralUtility::makeInstance(TemplateService::class, $context, null, $tsfe); |
|
171
|
209 |
|
$template->tt_track = false; |
|
172
|
209 |
|
$tsfe->tmpl = $template; |
|
173
|
209 |
|
$context->setAspect('typoscript', GeneralUtility::makeInstance(TypoScriptAspect::class, true)); |
|
174
|
209 |
|
$tsfe->no_cache = true; |
|
175
|
|
|
|
|
176
|
209 |
|
$backedUpBackendUser = $GLOBALS['BE_USER'] ?? null; |
|
177
|
|
|
try { |
|
178
|
209 |
|
$tsfe->determineId($serverRequest); |
|
179
|
209 |
|
$serverRequest->withAttribute('frontend.controller', $tsfe); |
|
180
|
209 |
|
$tsfe->no_cache = false; |
|
181
|
209 |
|
$tsfe->getConfigArray($serverRequest); |
|
182
|
|
|
|
|
183
|
209 |
|
$tsfe->newCObj($serverRequest); |
|
184
|
209 |
|
$tsfe->absRefPrefix = self::getAbsRefPrefixFromTSFE($tsfe); |
|
|
|
|
|
|
185
|
209 |
|
$tsfe->calculateLinkVars([]); |
|
186
|
6 |
|
} catch (Throwable $exception) { |
|
187
|
|
|
// @todo: logging |
|
188
|
6 |
|
$this->serverRequestCache[$cacheIdentifier] = null; |
|
189
|
6 |
|
$this->tsfeCache[$cacheIdentifier] = null; |
|
190
|
|
|
// Restore backend user, happens when initializeTsfe() is called from Backend context |
|
191
|
6 |
|
if ($backedUpBackendUser) { |
|
192
|
3 |
|
$GLOBALS['BE_USER'] = $backedUpBackendUser; |
|
193
|
|
|
} |
|
194
|
6 |
|
return; |
|
195
|
|
|
} |
|
196
|
|
|
// Restore backend user, happens when initializeTsfe() is called from Backend context |
|
197
|
209 |
|
if ($backedUpBackendUser) { |
|
198
|
37 |
|
$GLOBALS['BE_USER'] = $backedUpBackendUser; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
209 |
|
$this->tsfeCache[$cacheIdentifier] = $tsfe; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
// @todo: Not right place for that action, move on more convenient place: indexing a single item+id+lang. |
|
205
|
209 |
|
Locales::setSystemLocaleFromSiteLanguage($siteLanguage); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* Returns TypoScriptFrontendController with sand cast context. |
|
210
|
|
|
* |
|
211
|
|
|
* @param int $pageId |
|
212
|
|
|
* @param int $language |
|
213
|
|
|
* |
|
214
|
|
|
* @param int|null $rootPageId |
|
215
|
|
|
* |
|
216
|
|
|
* @return TypoScriptFrontendController |
|
217
|
|
|
* |
|
218
|
|
|
* @throws SiteNotFoundException |
|
219
|
|
|
* @throws DBALDriverException |
|
220
|
|
|
* @throws Exception\Exception |
|
221
|
|
|
*/ |
|
222
|
209 |
|
public function getTsfeByPageIdAndLanguageId(int $pageId, int $language = 0, ?int $rootPageId = null): ?TypoScriptFrontendController |
|
223
|
|
|
{ |
|
224
|
209 |
|
$this->assureIsInitialized($pageId, $language, $rootPageId); |
|
225
|
209 |
|
return $this->tsfeCache[$this->getCacheIdentifier($pageId, $language, $rootPageId)]; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Returns TypoScriptFrontendController for first available language id in fallback chain. |
|
230
|
|
|
* |
|
231
|
|
|
* Is usable for BE-Modules/CLI-Commands stack only, where the rendered TypoScript configuration |
|
232
|
|
|
* of EXT:solr* stack is wanted and the language id does not matter. |
|
233
|
|
|
* |
|
234
|
|
|
* NOTE: This method MUST NOT be used on indexing context. |
|
235
|
|
|
* |
|
236
|
|
|
* @param int $pageId |
|
237
|
|
|
* @param int ...$languageFallbackChain |
|
238
|
|
|
* @return TypoScriptFrontendController|null |
|
239
|
|
|
*/ |
|
240
|
207 |
|
public function getTsfeByPageIdAndLanguageFallbackChain(int $pageId, int ...$languageFallbackChain): ?TypoScriptFrontendController |
|
241
|
|
|
{ |
|
242
|
207 |
|
foreach ($languageFallbackChain as $languageId) { |
|
243
|
|
|
try { |
|
244
|
207 |
|
$tsfe = $this->getTsfeByPageIdAndLanguageId($pageId, $languageId); |
|
245
|
207 |
|
if ($tsfe instanceof TypoScriptFrontendController) { |
|
246
|
207 |
|
return $tsfe; |
|
247
|
|
|
} |
|
248
|
|
|
} catch (Throwable $e) { |
|
249
|
|
|
// no needs to log or do anything, the method MUST not return anything if it can't. |
|
250
|
|
|
continue; |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
1 |
|
return null; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Returns TSFE for first initializable site language. |
|
258
|
|
|
* |
|
259
|
|
|
* Is usable for BE-Modules/CLI-Commands stack only, where the rendered TypoScript configuration |
|
260
|
|
|
* of EXT:solr* stack is wanted and the language id does not matter. |
|
261
|
|
|
* |
|
262
|
|
|
* @param int $pageId |
|
263
|
|
|
* @return TypoScriptFrontendController|null |
|
264
|
|
|
*/ |
|
265
|
53 |
|
public function getTsfeByPageIdIgnoringLanguage(int $pageId): ?TypoScriptFrontendController |
|
266
|
|
|
{ |
|
267
|
|
|
try { |
|
268
|
53 |
|
$typo3Site = $this->siteFinder->getSiteByPageId($pageId); |
|
269
|
|
|
} catch (Throwable $e) { |
|
270
|
|
|
return null; |
|
271
|
|
|
} |
|
272
|
53 |
|
$availableLanguageIds = array_map(function ($siteLanguage) { |
|
273
|
53 |
|
return $siteLanguage->getLanguageId(); |
|
274
|
53 |
|
}, $typo3Site->getLanguages()); |
|
275
|
|
|
|
|
276
|
53 |
|
if (empty($availableLanguageIds)) { |
|
277
|
|
|
return null; |
|
278
|
|
|
} |
|
279
|
53 |
|
return $this->getTsfeByPageIdAndLanguageFallbackChain($pageId, ...$availableLanguageIds); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Returns TypoScriptFrontendController with sand cast context. |
|
284
|
|
|
* |
|
285
|
|
|
* @param int $pageId |
|
286
|
|
|
* @param int $language |
|
287
|
|
|
* |
|
288
|
|
|
* @param int|null $rootPageId |
|
289
|
|
|
* |
|
290
|
|
|
* @return ServerRequest |
|
291
|
|
|
* |
|
292
|
|
|
* @throws SiteNotFoundException |
|
293
|
|
|
* @throws DBALDriverException |
|
294
|
|
|
* @throws Exception\Exception |
|
295
|
|
|
* @noinspection PhpUnused |
|
296
|
|
|
*/ |
|
297
|
|
|
public function getServerRequestForTsfeByPageIdAndLanguageId(int $pageId, int $language = 0, ?int $rootPageId = null): ?ServerRequest |
|
298
|
|
|
{ |
|
299
|
|
|
$this->assureIsInitialized($pageId, $language, $rootPageId); |
|
300
|
|
|
return $this->serverRequestCache[$this->getCacheIdentifier($pageId, $language, $rootPageId)]; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* Initializes the TSFE, ServerRequest, Context if not already done. |
|
305
|
|
|
* |
|
306
|
|
|
* @param int $pageId |
|
307
|
|
|
* @param int $language |
|
308
|
|
|
* |
|
309
|
|
|
* @param int|null $rootPageId |
|
310
|
|
|
* |
|
311
|
|
|
* @throws DBALDriverException |
|
312
|
|
|
* @throws SiteNotFoundException |
|
313
|
|
|
* @throws Exception\Exception |
|
314
|
|
|
*/ |
|
315
|
209 |
|
protected function assureIsInitialized(int $pageId, int $language, ?int $rootPageId = null): void |
|
316
|
|
|
{ |
|
317
|
209 |
|
$cacheIdentifier = $this->getCacheIdentifier($pageId, $language, $rootPageId); |
|
318
|
209 |
|
if (!array_key_exists($cacheIdentifier, $this->tsfeCache)) { |
|
319
|
209 |
|
$this->initializeTsfe($pageId, $language, $rootPageId); |
|
320
|
209 |
|
return; |
|
321
|
|
|
} |
|
322
|
206 |
|
if ($this->tsfeCache[$cacheIdentifier] instanceof TypoScriptFrontendController) { |
|
323
|
206 |
|
$this->tsfeCache[$cacheIdentifier]->newCObj($this->serverRequestCache[$cacheIdentifier]); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
/** |
|
328
|
|
|
* Returns the cache identifier for cached TSFE and ServerRequest objects. |
|
329
|
|
|
* |
|
330
|
|
|
* @param int $pageId |
|
331
|
|
|
* @param int $language |
|
332
|
|
|
* |
|
333
|
|
|
* @param int|null $rootPageId |
|
334
|
|
|
* |
|
335
|
|
|
* @return string |
|
336
|
|
|
*/ |
|
337
|
209 |
|
protected function getCacheIdentifier(int $pageId, int $language, ?int $rootPageId = null): string |
|
338
|
|
|
{ |
|
339
|
209 |
|
return 'root:' . ($rootPageId ?? 'null') . '|page:' . $pageId . '|lang:' . $language; |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* The TSFE can not be initialized for Spacer and sys-folders. |
|
344
|
|
|
* See: "Spacer and sys folders is not accessible in frontend" on {@link \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::getPageAndRootline()} |
|
345
|
|
|
* |
|
346
|
|
|
* Note: The requested $pidToUse can be one of configured plugin.tx_solr.index.queue.[indexConfig].additionalPageIds. |
|
347
|
|
|
* |
|
348
|
|
|
* @param int $pidToUse |
|
349
|
|
|
* |
|
350
|
|
|
* @param int|null $rootPageId |
|
351
|
|
|
* |
|
352
|
|
|
* @return int |
|
353
|
|
|
* @throws DBALDriverException |
|
354
|
|
|
* @throws Exception\Exception |
|
355
|
|
|
*/ |
|
356
|
209 |
|
protected function getPidToUseForTsfeInitialization(int $pidToUse, ?int $rootPageId = null): ?int |
|
357
|
|
|
{ |
|
358
|
|
|
// handle plugin.tx_solr.index.queue.[indexConfig].additionalPageIds |
|
359
|
209 |
|
if (isset($rootPageId) && !$this->isRequestedPageAPartOfRequestedSite($pidToUse)) { |
|
360
|
20 |
|
return $rootPageId; |
|
361
|
|
|
} |
|
362
|
209 |
|
$pageRecord = BackendUtility::getRecord('pages', $pidToUse); |
|
363
|
209 |
|
$isSpacerOrSysfolder = ($pageRecord['doktype'] ?? null) == PageRepository::DOKTYPE_SPACER || ($pageRecord['doktype'] ?? null) == PageRepository::DOKTYPE_SYSFOLDER; |
|
364
|
209 |
|
if ($isSpacerOrSysfolder === false) { |
|
365
|
209 |
|
return $pidToUse; |
|
366
|
|
|
} |
|
367
|
|
|
/* @var ConfigurationPageResolver $configurationPageResolve */ |
|
368
|
3 |
|
$configurationPageResolver = GeneralUtility::makeInstance(ConfigurationPageResolver::class); |
|
369
|
3 |
|
$askedPid = $pidToUse; |
|
370
|
3 |
|
$pidToUse = $configurationPageResolver->getClosestPageIdWithActiveTemplate($pidToUse); |
|
371
|
3 |
|
if (!isset($pidToUse) && !isset($rootPageId)) { |
|
372
|
1 |
|
throw new Exception\Exception( |
|
373
|
1 |
|
"The closest page with active template to page \"$askedPid\" could not be resolved and alternative rootPageId is not provided.", |
|
374
|
|
|
1637339439 |
|
375
|
|
|
); |
|
376
|
|
|
} |
|
377
|
2 |
|
if (isset($rootPageId)) { |
|
378
|
|
|
return $rootPageId; |
|
379
|
|
|
} |
|
380
|
2 |
|
return $this->getPidToUseForTsfeInitialization($pidToUse, $rootPageId); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
/** |
|
384
|
|
|
* Checks if the requested page belongs to site of given root page. |
|
385
|
|
|
* |
|
386
|
|
|
* @param int $pageId |
|
387
|
|
|
* @param int|null $rootPageId |
|
388
|
|
|
* |
|
389
|
|
|
* @return bool |
|
390
|
|
|
*/ |
|
391
|
20 |
|
protected function isRequestedPageAPartOfRequestedSite(int $pageId, ?int $rootPageId = null): bool |
|
392
|
|
|
{ |
|
393
|
20 |
|
if (!isset($rootPageId)) { |
|
394
|
20 |
|
return false; |
|
395
|
|
|
} |
|
396
|
|
|
try { |
|
397
|
|
|
$site = $this->siteFinder->getSiteByPageId($pageId); |
|
398
|
|
|
} catch (SiteNotFoundException $e) { |
|
399
|
|
|
return false; |
|
400
|
|
|
} |
|
401
|
|
|
return $rootPageId === $site->getRootPageId(); |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
/** |
|
405
|
|
|
* Resolves the configured absRefPrefix to a valid value and resolved if absRefPrefix |
|
406
|
|
|
* is set to "auto". |
|
407
|
|
|
*/ |
|
408
|
209 |
|
private function getAbsRefPrefixFromTSFE(TypoScriptFrontendController $TSFE): string |
|
409
|
|
|
{ |
|
410
|
209 |
|
$absRefPrefix = ''; |
|
411
|
209 |
|
if (empty($TSFE->config['config']['absRefPrefix'])) { |
|
412
|
|
|
return $absRefPrefix; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
209 |
|
$absRefPrefix = trim($TSFE->config['config']['absRefPrefix']); |
|
416
|
209 |
|
if ($absRefPrefix === 'auto') { |
|
417
|
209 |
|
$absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'); |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
209 |
|
return $absRefPrefix; |
|
421
|
|
|
} |
|
422
|
|
|
} |
|
423
|
|
|
|