-
Notifications
You must be signed in to change notification settings - Fork 638
/
TypoScriptFrontendController.php
2806 lines (2620 loc) · 134 KB
/
TypoScriptFrontendController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Controller;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LogLevel;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Configuration\PageTsConfig;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Context\LanguageAspectFactory;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Domain\Access\RecordAccessVoter;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Error\Http\AbstractServerErrorException;
use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
use TYPO3\CMS\Core\Error\Http\ShortcutTargetPageNotFoundException;
use TYPO3\CMS\Core\Exception\Page\RootLineException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Http\ImmediateResponseException;
use TYPO3\CMS\Core\Http\NormalizedParams;
use TYPO3\CMS\Core\Http\PropagateResponseException;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Localization\Locale;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Locking\ResourceMutex;
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\PageTitle\PageTitleProviderManager;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\Type\Bitmask\PageTranslationVisibility;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Type\DocType;
use TYPO3\CMS\Core\TypoScript\AST\Node\ChildNode;
use TYPO3\CMS\Core\TypoScript\AST\Node\RootNode;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateRepository;
use TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\ConditionVerdictAwareIncludeTreeTraverser;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverser;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeAstBuilderVisitor;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeConditionIncludeListAccumulatorVisitor;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeConditionMatcherVisitor;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Visitor\IncludeTreeSetupConditionConstantSubstitutionVisitor;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\TypoScript\Tokenizer\LossyTokenizer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
use TYPO3\CMS\Frontend\Aspect\PreviewAspect;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;
use TYPO3\CMS\Frontend\Event\AfterCachedPageIsPersistedEvent;
use TYPO3\CMS\Frontend\Event\AfterPageAndLanguageIsResolvedEvent;
use TYPO3\CMS\Frontend\Event\AfterPageWithRootLineIsResolvedEvent;
use TYPO3\CMS\Frontend\Event\BeforePageIsResolvedEvent;
use TYPO3\CMS\Frontend\Event\ShouldUseCachedPageDataIfAvailableEvent;
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
use TYPO3\CMS\Frontend\Page\PageAccessFailureReasons;
use TYPO3\CMS\Frontend\Typolink\LinkVarsCalculator;
/**
* Main controller class of the TypoScript based frontend.
*
* This is prepared in Frontend middlewares and the content rendering is
* ultimately called in \TYPO3\CMS\Frontend\Http\RequestHandler.
*
* When calling a Frontend page, an instance of this object is available
* as $GLOBALS['TSFE'], even though the core development strives to get
* rid of this in the future.
*/
class TypoScriptFrontendController implements LoggerAwareInterface
{
use LoggerAwareTrait;
use PublicPropertyDeprecationTrait;
protected array $deprecatedPublicProperties = [
'intTarget' => '$TSFE->intTarget will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'intTarget\'] instead.',
'extTarget' => '$TSFE->extTarget will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'extTarget\'] instead.',
'fileTarget' => '$TSFE->fileTarget will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'fileTarget\'] instead.',
'spamProtectEmailAddresses' => '$TSFE->spamProtectEmailAddresses will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'spamProtectEmailAddresses\'] instead.',
'baseUrl' => '$TSFE->baseUrl will be removed in TYPO3 v13.0. Use $TSFE->config[\'config\'][\'baseURL\'] instead.',
'xhtmlDoctype' => '$TSFE->xhtmlDoctype will be removed in TYPO3 v13.0. Use PageRenderer->getDocType() instead.',
'xhtmlVersion' => '$TSFE->xhtmlVersion will be removed in TYPO3 v13.0. Use PageRenderer->getDocType() instead.',
'type' => '$TSFE->type will be removed in TYPO3 v13.0. Use $TSFE->getPageArguments()->getPageType() instead.',
];
/**
* The page id (int)
*/
public int $id;
/**
* The type (read-only)
* @var int|string
* @internal since TYPO3 v12. Use $TSFE->getPageArguments()->getPageType() instead
*/
protected $type = 0;
protected Site $site;
protected SiteLanguage $language;
/**
* @internal
*/
protected PageArguments $pageArguments;
/**
* Page will not be cached. Write only TRUE. Never clear value (some other
* code might have reasons to set it TRUE).
* @var bool
* @internal
*/
public $no_cache = false;
/**
* Rootline of page records all the way to the root.
*
* Both language and version overlays are applied to these page records:
* All "data" fields are set to language / version overlay values, *except* uid and
* pid, which are the default-language and live-version ids.
*
* First array row with the highest key is the deepest page (the requested page),
* then parent pages with descending keys until (but not including) the
* project root pseudo page 0.
*
* When page uid 5 is called in this example:
* [0] Project name
* |- [2] An organizational page, probably with is_siteroot=1 and a site config
* |- [3] Site root with a sys_template having "root" flag set
* |- [5] Here you are
*
* This $absoluteRootLine is:
* [3] => [uid = 5, pid = 3, title = Here you are, ...]
* [2] => [uid = 3, pid = 2, title = Site root with a sys_template having "root" flag set, ...]
* [1] => [uid = 2, pid = 0, title = An organizational page, probably with is_siteroot=1 and a site config, ...]
*
* @var array<int, array<string, mixed>>
*/
public array $rootLine = [];
/**
* The pagerecord
* @var array
*/
public $page = [];
/**
* This will normally point to the same value as id, but can be changed to
* point to another page from which content will then be displayed instead.
*/
public int $contentPid = 0;
/**
* Gets set when we are processing a page of type mountpoint with enabled overlay in getPageAndRootline()
* Used later in checkPageForMountpointRedirect() to determine the final target URL where the user
* should be redirected to.
*/
protected ?array $originalMountPointPage = null;
/**
* Gets set when we are processing a page of type shortcut in the early stages
* of the request, used later in the request to resolve the shortcut and redirect again.
*/
protected ?array $originalShortcutPage = null;
/**
* sys_page-object, pagefunctions
*
* @var PageRepository|string
*/
public $sys_page = '';
/**
* Is set to > 0 if the page could not be resolved. This will then result in early returns when resolving the page.
*/
protected int $pageNotFound = 0;
/**
* Array containing a history of why a requested page was not accessible.
*/
protected array $pageAccessFailureHistory = [];
/**
* @var string
* @internal
*/
public $MP = '';
/**
* The frontend user
*
* @var FrontendUserAuthentication
*/
public $fe_user;
/**
* A central data array consisting of various keys, initialized and
* processed at various places in the class.
*
* This array is cached along with the rendered page content and contains
* for instance a list of INT identifiers used to calculate 'dynamic' page
* parts when a page is retrieved from cache.
*
* Some sub keys:
*
* 'config': This is the TypoScript ['config.'] sub-array, with some
* settings being sanitized and merged.
*
* 'rootLine': This is the "local" rootline of a deep page that stops at the first parent
* sys_template record that has "root" flag set, in natural parent-child order.
*
* Both language and version overlays are applied to these page records:
* All "data" fields are set to language / version overlay values, *except* uid and
* pid, which are the default-language and live-version ids.
*
* When page uid 5 is called in this example:
* [0] Project name
* |- [2] An organizational page, probably with is_siteroot=1 and a site config
* |- [3] Site root with a sys_template having "root" flag set
* |- [5] Here you are
*
* This rootLine is:
* [0] => [uid = 3, pid = 2, title = Site root with a sys_template having "root" flag set, ...]
* [1] => [uid = 5, pid = 3, title = Here you are, ...]
*
* @var array<string, mixed>
*/
public $config = [];
/**
* The TypoScript template object. Used to parse the TypoScript template
*
* @var TemplateService
* @internal: Will get a proper deprecation in v12.x.
* @deprecated: TemplateService is kept for b/w compat in v12 but will be removed in v13.
*/
public $tmpl;
/**
* Is set to the time-to-live time of cached pages. Default is 60*60*24, which is 24 hours.
*
* @internal
*/
protected int $cacheTimeOutDefault = 0;
/**
* Set if cached content was fetched from the cache.
* @internal
*/
protected bool $pageContentWasLoadedFromCache = false;
/**
* Set to the expire time of cached content
* @internal
*/
protected int $cacheExpires = 0;
/**
* TypoScript configuration of the page-object.
* @var array|string
* @internal should only be used by TYPO3 Core
*/
public $pSetup = '';
/**
* This hash is unique to the template, the $this->id and $this->type vars and
* the list of groups. Used to get and later store the cached data
* @internal
*/
public string $newHash = '';
/**
* This flag is set before the page is generated IF $this->no_cache is set. If this
* flag is set after the page content was generated, $this->no_cache is forced to be set.
* This is done in order to make sure that PHP code from Plugins / USER scripts does not falsely
* clear the no_cache flag.
* @internal
*/
protected bool $no_cacheBeforePageGen = false;
/**
* May be set to the pagesTSconfig
* @internal
*/
protected ?array $pagesTSconfig = null;
/**
* Eg. insert JS-functions in this array ($additionalHeaderData) to include them
* once. Use associative keys.
*
* Keys in use:
*
* used to accumulate additional HTML-code for the header-section,
* <head>...</head>. Insert either associative keys (like
* additionalHeaderData['myStyleSheet'], see reserved keys above) or num-keys
* (like additionalHeaderData[] = '...')
*
* @var array
*/
public $additionalHeaderData = [];
/**
* Used to accumulate additional HTML-code for the footer-section of the template
* @var array
*/
public $additionalFooterData = [];
/**
* Default internal target
* @var string
* @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0.
*/
protected $intTarget = '';
/**
* Default external target
* @var string
* @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0.
*/
protected $extTarget = '';
/**
* Default file link target
* @var string
* @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0.
*/
protected $fileTarget = '';
/**
* If set, typolink() function encrypts email addresses.
* @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0.
*/
protected int $spamProtectEmailAddresses = 0;
/**
* Absolute Reference prefix
* @var string
*/
public $absRefPrefix = '';
/**
* A string prepared for insertion in all links on the page as url-parameters.
* Based on configuration in TypoScript where you defined which GET parameters you
* would like to pass on.
* @internal if needed, generate linkVars via LinkVarsCalculator
*/
public string $linkVars = '';
/**
* 'Global' Storage for various applications. Keys should be 'tx_'.extKey for
* extensions.
*/
public array $applicationData = [];
public array $register = [];
/**
* Stack used for storing array and retrieving register arrays (see
* LOAD_REGISTER and RESTORE_REGISTER)
*/
public array $registerStack = [];
/**
* Used by RecordContentObject and ContentContentObject to ensure the a records is NOT
* rendered twice through it!
*/
public array $recordRegister = [];
/**
* This is set to the [table]:[uid] of the latest record rendered. Note that
* class ContentObjectRenderer has an equal value, but that is pointing to the
* record delivered in the $data-array of the ContentObjectRenderer instance, if
* the cObjects CONTENT or RECORD created that instance
*/
public string $currentRecord = '';
/**
* Used to generate page-unique keys. Point is that uniqid() functions is very
* slow, so a unique key is made based on this, see function uniqueHash()
* @internal
*/
protected int $uniqueCounter = 0;
/**
* @internal
*/
protected string $uniqueString = '';
/**
* The base URL set for the page header.
* @var string
* @deprecated since TYPO3 v12.0. will be removed in TYPO3 v13.0.
*/
protected $baseUrl = '';
/**
* Page content render object
*
* @var ContentObjectRenderer
*/
public $cObj;
/**
* All page content is accumulated in this variable. See RequestHandler
* @var string
*/
public $content = '';
/**
* Info-array of the last resulting image resource of content object
* IMG_RESOURCE (if any), containing width, height and so on.
*/
public ?array $lastImgResourceInfo = null;
/**
* Internal calculations for labels
*/
protected ?LanguageService $languageService = null;
/**
* @internal Internal locking. May move to a middleware soon.
*/
public ?ResourceMutex $lock = null;
protected ?PageRenderer $pageRenderer = null;
/**
* The page cache object, use this to save pages to the cache and to
* retrieve them again
*
* @var FrontendInterface
*/
protected $pageCache;
protected array $pageCacheTags = [];
/**
* Content type HTTP header being sent in the request.
* @todo Ticket: #63642 Should be refactored to a request/response model later
* @internal Should only be used by TYPO3 core for now
*/
protected string $contentType = 'text/html; charset=utf-8';
/**
* Doctype to use
*
* @var string
* @deprecated since TYPO3 v12, will be removed in TYPO3 v13. Use PageRenderer->getDocType() instead.
*/
protected $xhtmlDoctype = '';
/**
* @var int
* @deprecated since TYPO3 v12, will be removed in TYPO3 v13. Use PageRenderer->getDocType() instead.
*/
protected $xhtmlVersion;
/**
* Originally requested id from PageArguments
*/
protected int $requestedId = 0;
/**
* The context for keeping the current state, mostly related to current page information,
* backend user / frontend user access, workspaceId
*/
protected Context $context;
/**
* If debug mode is enabled, this contains the information if a page is fetched from cache,
* and sent as HTTP Response Header.
*/
protected string $debugInformationHeader = '';
/**
* Since TYPO3 v10.0, TSFE is composed out of
* - Context
* - Site
* - SiteLanguage
* - PageArguments (containing ID, Type, cHash and MP arguments)
*
* Also sets a unique string (->uniqueString) for this script instance; A md5 hash of the microtime()
*
* @param Context $context the Context object to work with
* @param Site $site The resolved site to work with
* @param SiteLanguage $siteLanguage The resolved language to work with
* @param PageArguments $pageArguments The PageArguments object containing Page ID, type and GET parameters
* @param FrontendUserAuthentication $frontendUser a FrontendUserAuthentication object
*/
public function __construct(Context $context, Site $site, SiteLanguage $siteLanguage, PageArguments $pageArguments, FrontendUserAuthentication $frontendUser)
{
$this->initializeContext($context);
$this->site = $site;
$this->language = $siteLanguage;
$this->setPageArguments($pageArguments);
$this->fe_user = $frontendUser;
$this->uniqueString = md5(microtime());
$this->initPageRenderer();
$this->initCaches();
}
private function initializeContext(Context $context): void
{
$this->context = $context;
if (!$this->context->hasAspect('frontend.preview')) {
$this->context->setAspect('frontend.preview', GeneralUtility::makeInstance(PreviewAspect::class));
}
}
/**
* Initializes the page renderer object
*/
protected function initPageRenderer()
{
if ($this->pageRenderer !== null) {
return;
}
$this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$this->pageRenderer->setTemplateFile('EXT:frontend/Resources/Private/Templates/MainPage.html');
// As initPageRenderer could be called in constructor and for USER_INTs, this information is only set
// once - in order to not override any previous settings of PageRenderer.
if ($this->language->hasCustomTypo3Language()) {
$locale = GeneralUtility::makeInstance(Locales::class)->createLocale($this->language->getTypo3Language());
} else {
$locale = $this->language->getLocale();
}
$this->pageRenderer->setLanguage($locale);
}
/**
* @param string $contentType
* @internal Must only be used by TYPO3 core
*/
public function setContentType($contentType)
{
$this->contentType = $contentType;
}
/********************************************
*
* Initializing, resolving page id
*
********************************************/
/**
* Initializes the caching system.
*/
protected function initCaches()
{
$cacheManager = GeneralUtility::makeInstance(CacheManager::class);
$this->pageCache = $cacheManager->getCache('pages');
}
/**
* Initializes the front-end user groups.
* Sets frontend.user aspect based on front-end user status.
* @deprecated will be removed in TYPO3 v13.0. Use the Context API directly.
*/
public function initUserGroups()
{
trigger_error('TSFE->initUserGroups() will be removed in TYPO3 v13.0. Use the Context API directly.', E_USER_DEPRECATED);
$this->context->setAspect('frontend.user', $this->fe_user->createUserAspect());
}
/**
* Checking if a user is logged in or a group constellation different from "0,-1"
*
* @return bool TRUE if either a login user is found (array fe_user->user) OR if the gr_list is set to something else than '0,-1' (could be done even without a user being logged in!)
* @deprecated will be removed in TYPO3 v13.0. Use the Context API directly.
*/
public function isUserOrGroupSet()
{
trigger_error('TSFE->isUserOrGroupSet() will be removed in TYPO3 v13.0. Use the Context API directly.', E_USER_DEPRECATED);
/** @var UserAspect $userAspect */
$userAspect = $this->context->getAspect('frontend.user');
return $userAspect->isUserOrGroupSet();
}
/**
* Checks if a backend user is logged in
*
* @return bool whether a backend user is logged in
* @deprecated will be removed in TYPO3 v13.0. Use the Context API directly.
*/
public function isBackendUserLoggedIn()
{
trigger_error('TSFE->isBackendUserLoggedIn() will be removed in TYPO3 v13.0. Use the Context API directly.', E_USER_DEPRECATED);
return (bool)$this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false);
}
/**
* Resolves the page id and sets up several related properties.
*
* At this point, the Context object already contains relevant preview
* settings (if a backend user is logged in etc).
*
* If $this->id is not set at all, the method does its best to set the
* value to an integer. Resolving is based on this options:
*
* - Finding the domain record start page
* - First visible page
* - Relocating the id below the site if outside the site / domain
*
* The following properties may be set up or updated:
*
* - id
* - sys_page
* - sys_page->where_groupAccess
* - sys_page->where_hid_del
* - register['SYS_LASTCHANGED']
* - pageNotFound
*
* Via getPageAndRootline()
*
* - rootLine
* - page
* - MP
* - originalShortcutPage
* - originalMountPointPage
* - pageAccessFailureHistory['direct_access']
* - pageNotFound
*/
public function determineId(ServerRequestInterface $request): ?ResponseInterface
{
$this->sys_page = GeneralUtility::makeInstance(PageRepository::class, $this->context);
$eventDispatcher = GeneralUtility::makeInstance(EventDispatcherInterface::class);
$eventDispatcher->dispatch(new BeforePageIsResolvedEvent($this, $request));
$timeTracker = $this->getTimeTracker();
$timeTracker->push('determineId rootLine/');
try {
// Sets ->page and ->rootline information based on ->id. ->id may change during this operation.
// If the found Page ID is not within the site, then pageNotFound is set.
$this->getPageAndRootline($request);
// Checks if the rootPageId of the site is in the resolved rootLine.
// This is necessary so that references to page-id's via ?id=123 from other sites are not possible.
$siteRootWithinRootlineFound = false;
foreach ($this->rootLine as $pageInRootLine) {
if ((int)$pageInRootLine['uid'] === $this->site->getRootPageId()) {
$siteRootWithinRootlineFound = true;
break;
}
}
// Page is 'not found' in case the id was outside the domain, code 3
// This can only happen if there was a shortcut. So $this->page is now the shortcut target
// But the original page is in $this->originalShortcutPage.
// This only happens if people actually call TYPO3 with index.php?id=123 where 123 is in a different
// page tree. This is not allowed.
$directlyRequestedId = (int)($request->getQueryParams()['id'] ?? 0);
if (!$siteRootWithinRootlineFound && $directlyRequestedId && (int)($this->originalShortcutPage['uid'] ?? 0) !== $directlyRequestedId) {
$this->pageNotFound = 3;
$this->id = $this->site->getRootPageId();
// re-get the page and rootline if the id was not found.
$this->getPageAndRootline($request);
}
} catch (ShortcutTargetPageNotFoundException $e) {
$this->pageNotFound = 1;
}
$timeTracker->pull();
$event = new AfterPageWithRootLineIsResolvedEvent($this, $request);
$event = $eventDispatcher->dispatch($event);
if ($event->getResponse()) {
return $event->getResponse();
}
$response = null;
try {
$this->evaluatePageNotFound($this->pageNotFound, $request);
// Setting language and fetch translated page
$this->settingLanguage($request);
// Check the "content_from_pid" field of the resolved page
$this->contentPid = $this->resolveContentPid($request);
// Update SYS_LASTCHANGED at the very last, when $this->page might be changed
// by settingLanguage() and the $this->page was finally resolved
$this->setRegisterValueForSysLastChanged($this->page);
} catch (PropagateResponseException $e) {
$response = $e->getResponse();
}
$event = new AfterPageAndLanguageIsResolvedEvent($this, $request, $response);
$eventDispatcher->dispatch($event);
return $event->getResponse();
}
/**
* If $this->pageNotFound is set, then throw an exception to stop further page generation process
*/
protected function evaluatePageNotFound(int $pageNotFoundNumber, ServerRequestInterface $request): void
{
if (!$pageNotFoundNumber) {
return;
}
$response = match ($pageNotFoundNumber) {
1 => GeneralUtility::makeInstance(ErrorController::class)->accessDeniedAction(
$request,
'ID was not an accessible page',
$this->getPageAccessFailureReasons(PageAccessFailureReasons::ACCESS_DENIED_PAGE_NOT_RESOLVED)
),
2 => GeneralUtility::makeInstance(ErrorController::class)->accessDeniedAction(
$request,
'Subsection was found and not accessible',
$this->getPageAccessFailureReasons(PageAccessFailureReasons::ACCESS_DENIED_SUBSECTION_NOT_RESOLVED)
),
3 => GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
'ID was outside the domain',
$this->getPageAccessFailureReasons(PageAccessFailureReasons::ACCESS_DENIED_HOST_PAGE_MISMATCH)
),
default => GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
'Unspecified error',
$this->getPageAccessFailureReasons()
),
};
throw new PropagateResponseException($response, 1533931329);
}
/**
* Loads the page and root line records based on $this->id
*
* A final page and the matching root line are determined and loaded by
* the algorithm defined by this method.
*
* First it loads the initial page from the page repository for $this->id.
* If that can't be loaded directly, it gets the root line for $this->id.
* It walks up the root line towards the root page until the page
* repository can deliver a page record. (The loading restrictions of
* the root line records are more liberal than that of the page record.)
*
* Now the page type is evaluated and handled if necessary. If the page is
* a short cut, it is replaced by the target page. If the page is a mount
* point in overlay mode, the page is replaced by the mounted page.
*
* After this potential replacements are done, the root line is loaded
* (again) for this page record. It walks up the root line up to
* the first viewable record.
*
* (While upon the first accessibility check of the root line it was done
* by loading page by page from the page repository, this time the method
* checkRootlineForIncludeSection() is used to find the most distant
* accessible page within the root line.)
*
* Having found the final page id, the page record and the root line are
* loaded for last time by this method.
*
* Exceptions may be thrown for DOKTYPE_SPACER and not loadable page records
* or root lines.
*
* May set or update these properties:
*
* @see TypoScriptFrontendController::$id
* @see TypoScriptFrontendController::$MP
* @see TypoScriptFrontendController::$page
* @see TypoScriptFrontendController::$pageNotFound
* @see TypoScriptFrontendController::$pageAccessFailureHistory
* @see TypoScriptFrontendController::$originalMountPointPage
* @see TypoScriptFrontendController::$originalShortcutPage
*
* @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
* @throws PageNotFoundException
* @throws ShortcutTargetPageNotFoundException
*/
protected function getPageAndRootline(ServerRequestInterface $request)
{
$requestedPageRowWithoutGroupCheck = [];
$this->page = $this->sys_page->getPage($this->id);
if (empty($this->page)) {
// If no page, we try to find the page above in the rootLine.
// Page is 'not found' in case the id itself was not an accessible page. code 1
$this->pageNotFound = 1;
$requestedPageIsHidden = false;
try {
$hiddenField = $GLOBALS['TCA']['pages']['ctrl']['enablecolumns']['disabled'] ?? '';
$includeHiddenPages = $this->context->getPropertyFromAspect('visibility', 'includeHiddenPages') || $this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false);
if (!empty($hiddenField) && !$includeHiddenPages) {
// Page is "hidden" => 404 (deliberately done in default language, as this cascades to language overlays)
$rawPageRecord = $this->sys_page->getPage_noCheck($this->id);
// If page record could not be resolved throw exception
if ($rawPageRecord === []) {
$message = 'The requested page does not exist!';
try {
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
$message,
$this->getPageAccessFailureReasons(PageAccessFailureReasons::PAGE_NOT_FOUND)
);
throw new PropagateResponseException($response, 1674144383);
} catch (PageNotFoundException $e) {
throw new PageNotFoundException($message, 1674539331);
}
}
$requestedPageIsHidden = (bool)$rawPageRecord[$hiddenField];
}
$requestedPageRowWithoutGroupCheck = $this->sys_page->getPage($this->id, true);
if (!empty($requestedPageRowWithoutGroupCheck)) {
$this->pageAccessFailureHistory['direct_access'][] = $requestedPageRowWithoutGroupCheck;
}
$this->rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $this->id, $this->MP, $this->context)->get();
if (!empty($this->rootLine)) {
$c = count($this->rootLine) - 1;
while ($c > 0) {
// Add to page access failure history:
$this->pageAccessFailureHistory['direct_access'][] = $this->rootLine[$c];
// Decrease to next page in rootline and check the access to that, if OK, set as page record and ID value.
$c--;
$this->id = (int)$this->rootLine[$c]['uid'];
$this->page = $this->sys_page->getPage($this->id);
if (!empty($this->page)) {
break;
}
}
}
} catch (RootLineException $e) {
$this->rootLine = [];
}
// If still no page...
if ($requestedPageIsHidden || (empty($requestedPageRowWithoutGroupCheck) && empty($this->page))) {
$message = 'The requested page does not exist!';
try {
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
$message,
$this->getPageAccessFailureReasons(PageAccessFailureReasons::PAGE_NOT_FOUND)
);
throw new PropagateResponseException($response, 1533931330);
} catch (PageNotFoundException $e) {
throw new PageNotFoundException($message, 1301648780);
}
}
}
// Spacer and sysfolders is not accessible in frontend
$pageDoktype = (int)($this->page['doktype'] ?? 0);
$isSpacerOrSysfolder = $pageDoktype === PageRepository::DOKTYPE_SPACER || $pageDoktype === PageRepository::DOKTYPE_SYSFOLDER;
// Page itself is not accessible, but the parent page is a spacer/sysfolder
if ($isSpacerOrSysfolder && !empty($requestedPageRowWithoutGroupCheck)) {
try {
$response = GeneralUtility::makeInstance(ErrorController::class)->accessDeniedAction(
$request,
'Subsection was found and not accessible',
$this->getPageAccessFailureReasons(PageAccessFailureReasons::ACCESS_DENIED_SUBSECTION_NOT_RESOLVED)
);
throw new PropagateResponseException($response, 1633171038);
} catch (PageNotFoundException $e) {
throw new PageNotFoundException('Subsection was found and not accessible', 1633171172);
}
}
if ($isSpacerOrSysfolder) {
$message = 'The requested page does not exist!';
try {
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
$message,
$this->getPageAccessFailureReasons(PageAccessFailureReasons::ACCESS_DENIED_INVALID_PAGETYPE)
);
throw new PropagateResponseException($response, 1533931343);
} catch (PageNotFoundException $e) {
throw new PageNotFoundException($message, 1301648781);
}
}
// Is the ID a link to another page??
if ($pageDoktype === PageRepository::DOKTYPE_SHORTCUT) {
// We need to clear MP if the page is a shortcut. Reason is if the shortcut goes to another page, then we LEAVE the rootline which the MP expects.
$this->MP = '';
// saving the page so that we can check later - when we know
// about languages - whether we took the correct shortcut or
// whether a translation of the page overwrites the shortcut
// target and we need to follow the new target
$this->settingLanguage($request);
$this->originalShortcutPage = $this->page;
$this->page = $this->sys_page->resolveShortcutPage($this->page, true);
$this->id = (int)$this->page['uid'];
$pageDoktype = (int)($this->page['doktype'] ?? 0);
}
// If the page is a mountpoint which should be overlaid with the contents of the mounted page,
// it must never be accessible directly, but only in the mountpoint context. Therefore we change
// the current ID and the user is redirected by checkPageForMountpointRedirect().
if ($pageDoktype === PageRepository::DOKTYPE_MOUNTPOINT && $this->page['mount_pid_ol']) {
$this->originalMountPointPage = $this->page;
$this->page = $this->sys_page->getPage($this->page['mount_pid']);
if (empty($this->page)) {
$message = 'This page (ID ' . $this->originalMountPointPage['uid'] . ') is of type "Mount point" and '
. 'mounts a page which is not accessible (ID ' . $this->originalMountPointPage['mount_pid'] . ').';
throw new PageNotFoundException($message, 1402043263);
}
// If the current page is a shortcut, the MP parameter will be replaced
if ($this->MP === '' || !empty($this->originalShortcutPage)) {
$this->MP = $this->page['uid'] . '-' . $this->originalMountPointPage['uid'];
} else {
$this->MP .= ',' . $this->page['uid'] . '-' . $this->originalMountPointPage['uid'];
}
$this->id = (int)$this->page['uid'];
$pageDoktype = (int)($this->page['doktype'] ?? 0);
}
// Gets the rootLine
try {
$this->rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $this->id, $this->MP, $this->context)->get();
} catch (RootLineException $e) {
$this->rootLine = [];
}
// If not rootline we're off...
if (empty($this->rootLine)) {
$message = 'The requested page didn\'t have a proper connection to the tree-root!';
$this->logPageAccessFailure($message, $request);
try {
$response = GeneralUtility::makeInstance(ErrorController::class)->internalErrorAction(
$request,
$message,
$this->getPageAccessFailureReasons(PageAccessFailureReasons::ROOTLINE_BROKEN)
);
throw new PropagateResponseException($response, 1533931350);
} catch (AbstractServerErrorException $e) {
$this->logger->error($message, ['exception' => $e]);
$exceptionClass = get_class($e);
throw new $exceptionClass($message, 1301648167);
}
}
// Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
if ($this->checkRootlineForIncludeSection()) {
if (empty($this->rootLine)) {
$message = 'The requested page does not exist!';
try {
$response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
$request,
$message,
$this->getPageAccessFailureReasons(PageAccessFailureReasons::PAGE_NOT_FOUND)
);
throw new PropagateResponseException($response, 1533931351);
} catch (AbstractServerErrorException $e) {
$this->logger->warning($message);
$exceptionClass = get_class($e);
throw new $exceptionClass($message, 1301648234);
}
} else {
$el = reset($this->rootLine);
$this->id = (int)$el['uid'];
$this->page = $this->sys_page->getPage($this->id);
try {
$this->rootLine = GeneralUtility::makeInstance(RootlineUtility::class, $this->id, $this->MP, $this->context)->get();
} catch (RootLineException $e) {
$this->rootLine = [];
}
}
}
}
/**
* Checks if visibility of the page is blocked upwards in the root line.
*
* If any page in the root line is blocking visibility, true is returned.
*
* All pages from the blocking page downwards are removed from the root
* line, so that the remaining pages can be used to relocate the page up
* to lowest visible page.
*
* The blocking feature of a page must be turned on by setting the page
* record field 'extendToSubpages' to 1 in case of hidden, starttime,
* endtime or fe_group restrictions.
*
* Additionally, this method checks for backend user sections in root line
* and if found, evaluates if a backend user is logged in and has access.