-
Notifications
You must be signed in to change notification settings - Fork 638
/
TypoScriptFrontendController.php
4796 lines (4489 loc) · 199 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
namespace TYPO3\CMS\Frontend\Controller;
/*
* 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!
*/
use Doctrine\DBAL\Exception\ConnectionException;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Charset\CharsetConverter;
use TYPO3\CMS\Core\Controller\ErrorPageController;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\Localization\Locales;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
use TYPO3\CMS\Core\Locking\LockFactory;
use TYPO3\CMS\Core\Locking\LockingStrategyInterface;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Http\UrlHandlerInterface;
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
use TYPO3\CMS\Frontend\Page\PageGenerator;
use TYPO3\CMS\Frontend\Page\PageRepository;
use TYPO3\CMS\Frontend\View\AdminPanelView;
/**
* Class for the built TypoScript based frontend. Instantiated in
* \TYPO3\CMS\Frontend\Http\RequestHandler as the global object TSFE.
*
* Main frontend class, instantiated in \TYPO3\CMS\Frontend\Http\RequestHandler
* as the global object TSFE.
*
* This class has a lot of functions and internal variable which are used from
* \TYPO3\CMS\Frontend\Http\RequestHandler
*
* The class is instantiated as $GLOBALS['TSFE'] in \TYPO3\CMS\Frontend\Http\RequestHandler.
*
* The use of this class should be inspired by the order of function calls as
* found in \TYPO3\CMS\Frontend\Http\RequestHandler.
*/
class TypoScriptFrontendController
{
/**
* The page id (int)
* @var string
*/
public $id = '';
/**
* The type (read-only)
* @var int
*/
public $type = '';
/**
* The submitted cHash
* @var string
*/
public $cHash = '';
/**
* Page will not be cached. Write only TRUE. Never clear value (some other
* code might have reasons to set it TRUE).
* @var bool
*/
public $no_cache = false;
/**
* The rootLine (all the way to tree root, not only the current site!)
* @var array
*/
public $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.
* @var int
*/
public $contentPid = 0;
/**
* Gets set when we are processing a page of type mounpoint with enabled overlay in getPageAndRootline()
* Used later in checkPageForMountpointRedirect() to determine the final target URL where the user
* should be redirected to.
*
* @var array|NULL
*/
protected $originalMountPointPage = null;
/**
* Gets set when we are processing a page of type shortcut in the early stages
* of the request when we do not know about languages yet, used later in the request
* to determine the correct shortcut in case a translation changes the shortcut
* target
* @var array|NULL
* @see checkTranslatedShortcut()
*/
protected $originalShortcutPage = null;
/**
* sys_page-object, pagefunctions
*
* @var PageRepository
*/
public $sys_page = '';
/**
* Contains all URL handler instances that are active for the current request.
*
* The methods isGeneratePage(), isOutputting() and isINTincScript() depend on this property.
*
* @var \TYPO3\CMS\Frontend\Http\UrlHandlerInterface[]
* @see initializeRedirectUrlHandlers()
*/
protected $activeUrlHandlers = [];
/**
* Is set to 1 if a pageNotFound handler could have been called.
* @var int
*/
public $pageNotFound = 0;
/**
* Domain start page
* @var int
*/
public $domainStartPage = 0;
/**
* Array containing a history of why a requested page was not accessible.
* @var array
*/
public $pageAccessFailureHistory = [];
/**
* @var string
*/
public $MP = '';
/**
* @var string
*/
public $RDCT = '';
/**
* This can be set from applications as a way to tag cached versions of a page
* and later perform some external cache management, like clearing only a part
* of the cache of a page...
* @var int
*/
public $page_cache_reg1 = 0;
/**
* Contains the value of the current script path that activated the frontend.
* Typically "index.php" but by rewrite rules it could be something else! Used
* for Speaking Urls / Simulate Static Documents.
* @var string
*/
public $siteScript = '';
/**
* The frontend user
*
* @var FrontendUserAuthentication
*/
public $fe_user = '';
/**
* Global flag indicating that a frontend user is logged in. This is set only if
* a user really IS logged in. The group-list may show other groups (like added
* by IP filter or so) even though there is no user.
* @var bool
*/
public $loginUser = false;
/**
* (RO=readonly) The group list, sorted numerically. Group '0,-1' is the default
* group, but other groups may be added by other means than a user being logged
* in though...
* @var string
*/
public $gr_list = '';
/**
* Flag that indicates if a backend user is logged in!
* @var bool
*/
public $beUserLogin = false;
/**
* Integer, that indicates which workspace is being previewed.
* @var int
*/
public $workspacePreview = 0;
/**
* Shows whether logins are allowed in branch
* @var bool
*/
public $loginAllowedInBranch = true;
/**
* Shows specific mode (all or groups)
* @var string
*/
public $loginAllowedInBranch_mode = '';
/**
* Set to backend user ID to initialize when keyword-based preview is used
* @var int
*/
public $ADMCMD_preview_BEUSER_uid = 0;
/**
* Flag indication that preview is active. This is based on the login of a
* backend user and whether the backend user has read access to the current
* page. A value of 1 means ordinary preview, 2 means preview of a non-live
* workspace
* @var int
*/
public $fePreview = 0;
/**
* Flag indicating that hidden pages should be shown, selected and so on. This
* goes for almost all selection of pages!
* @var bool
*/
public $showHiddenPage = false;
/**
* Flag indicating that hidden records should be shown. This includes
* sys_template, pages_language_overlay and even fe_groups in addition to all
* other regular content. So in effect, this includes everything except pages.
* @var bool
*/
public $showHiddenRecords = false;
/**
* Value that contains the simulated usergroup if any
* @var int
*/
public $simUserGroup = 0;
/**
* "CONFIG" object from TypoScript. Array generated based on the TypoScript
* configuration of the current page. Saved with the cached pages.
* @var array
*/
public $config = '';
/**
* The TypoScript template object. Used to parse the TypoScript template
*
* @var TemplateService
*/
public $tmpl = null;
/**
* Is set to the time-to-live time of cached pages. If FALSE, default is
* 60*60*24, which is 24 hours.
* @var bool|int
*/
public $cacheTimeOutDefault = false;
/**
* Set internally if cached content is fetched from the database
* @var bool
* @internal
*/
public $cacheContentFlag = false;
/**
* Set to the expire time of cached content
* @var int
*/
public $cacheExpires = 0;
/**
* Set if cache headers allowing caching are sent.
* @var bool
*/
public $isClientCachable = false;
/**
* Used by template fetching system. This array is an identification of
* the template. If $this->all is empty it's because the template-data is not
* cached, which it must be.
* @var array
*/
public $all = [];
/**
* Toplevel - objArrayName, eg 'page'
* @var string
*/
public $sPre = '';
/**
* TypoScript configuration of the page-object pointed to by sPre.
* $this->tmpl->setup[$this->sPre.'.']
* @var array
*/
public $pSetup = '';
/**
* This hash is unique to the template, the $this->id and $this->type vars and
* the gr_list (list of groups). Used to get and later store the cached data
* @var string
*/
public $newHash = '';
/**
* If config.ftu (Frontend Track User) is set in TypoScript for the current
* page, the string value of this var is substituted in the rendered source-code
* with the string, '&ftu=[token...]' which enables GET-method usertracking as
* opposed to cookie based
* @var string
*/
public $getMethodUrlIdToken = '';
/**
* This flag is set before inclusion of pagegen.php IF no_cache is set. If this
* flag is set after the inclusion of pagegen.php, no_cache is forced to be set.
* This is done in order to make sure that php-code from pagegen does not falsely
* clear the no_cache flag.
* @var bool
*/
public $no_cacheBeforePageGen = false;
/**
* This flag indicates if temporary content went into the cache during
* page-generation.
* @var mixed
*/
public $tempContent = false;
/**
* Passed to TypoScript template class and tells it to force template rendering
* @var bool
*/
public $forceTemplateParsing = false;
/**
* The array which cHash_calc is based on, see ->makeCacheHash().
* @var array
*/
public $cHash_array = [];
/**
* May be set to the pagesTSconfig
* @var array
*/
public $pagesTSconfig = '';
/**
* Eg. insert JS-functions in this array ($additionalHeaderData) to include them
* once. Use associative keys.
*
* Keys in use:
*
* JSFormValidate: <script type="text/javascript" src="'.$GLOBALS["TSFE"]->absRefPrefix.'typo3/sysext/frontend/Resources/Public/JavaScript/jsfunc.validateform.js"></script>
* JSMenuCode, JSMenuCode_menu: JavaScript for the JavaScript menu
* JSCode: reserved
*
* 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 = [];
/**
* Used to accumulate additional JavaScript-code. Works like
* additionalHeaderData. Reserved keys at 'openPic' and 'mouseOver'
*
* @var array
*/
public $additionalJavaScript = [];
/**
* Used to accumulate additional Style code. Works like additionalHeaderData.
*
* @var array
*/
public $additionalCSS = [];
/**
* @var string
*/
public $JSCode;
/**
* @var string
*/
public $inlineJS;
/**
* Used to accumulate DHTML-layers.
* @var string
*/
public $divSection = '';
/**
* Debug flag. If TRUE special debug-output maybe be shown (which includes html-formatting).
* @var bool
*/
public $debug = false;
/**
* Default internal target
* @var string
*/
public $intTarget = '';
/**
* Default external target
* @var string
*/
public $extTarget = '';
/**
* Default file link target
* @var string
*/
public $fileTarget = '';
/**
* Keys are page ids and values are default &MP (mount point) values to set
* when using the linking features...)
* @var array
*/
public $MP_defaults = [];
/**
* If set, typolink() function encrypts email addresses. Is set in pagegen-class.
* @var string|int
*/
public $spamProtectEmailAddresses = 0;
/**
* Absolute Reference prefix
* @var string
*/
public $absRefPrefix = '';
/**
* Factor for form-field widths compensation
* @var string
*/
public $compensateFieldWidth = '';
/**
* Lock file path
* @var string
*/
public $lockFilePath = '';
/**
* <A>-tag parameters
* @var string
*/
public $ATagParams = '';
/**
* Search word regex, calculated if there has been search-words send. This is
* used to mark up the found search words on a page when jumped to from a link
* in a search-result.
* @var string
*/
public $sWordRegEx = '';
/**
* Is set to the incoming array sword_list in case of a page-view jumped to from
* a search-result.
* @var string
*/
public $sWordList = '';
/**
* A string prepared for insertion in all links on the page as url-parameters.
* Based on configuration in TypoScript where you defined which GET_VARS you
* would like to pass on.
* @var string
*/
public $linkVars = '';
/**
* A string set with a comma list of additional GET vars which should NOT be
* included in the cHash calculation. These vars should otherwise be detected
* and involved in caching, eg. through a condition in TypoScript.
* @var string
*/
public $excludeCHashVars = '';
/**
* If set, edit icons are rendered aside content records. Must be set only if
* the ->beUserLogin flag is set and set_no_cache() must be called as well.
* @var string
*/
public $displayEditIcons = '';
/**
* If set, edit icons are rendered aside individual fields of content. Must be
* set only if the ->beUserLogin flag is set and set_no_cache() must be called as
* well.
* @var string
*/
public $displayFieldEditIcons = '';
/**
* Site language, 0 (zero) is default, int+ is uid pointing to a sys_language
* record. Should reflect which language menus, templates etc is displayed in
* (master language) - but not necessarily the content which could be falling
* back to default (see sys_language_content)
* @var int
*/
public $sys_language_uid = 0;
/**
* Site language mode for content fall back.
* @var string
*/
public $sys_language_mode = '';
/**
* Site content selection uid (can be different from sys_language_uid if content
* is to be selected from a fall-back language. Depends on sys_language_mode)
* @var int
*/
public $sys_language_content = 0;
/**
* Site content overlay flag; If set - and sys_language_content is > 0 - ,
* records selected will try to look for a translation pointing to their uid. (If
* configured in [ctrl][languageField] / [ctrl][transOrigP...]
* @var int
*/
public $sys_language_contentOL = 0;
/**
* Is set to the iso code of the sys_language_content if that is properly defined
* by the sys_language record representing the sys_language_uid.
* @var string
*/
public $sys_language_isocode = '';
/**
* 'Global' Storage for various applications. Keys should be 'tx_'.extKey for
* extensions.
* @var array
*/
public $applicationData = [];
/**
* @var array
*/
public $register = [];
/**
* Stack used for storing array and retrieving register arrays (see
* LOAD_REGISTER and RESTORE_REGISTER)
* @var array
*/
public $registerStack = [];
/**
* Checking that the function is not called eternally. This is done by
* interrupting at a depth of 50
* @var int
*/
public $cObjectDepthCounter = 50;
/**
* Used by RecordContentObject and ContentContentObject to ensure the a records is NOT
* rendered twice through it!
* @var array
*/
public $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
* @var string
*/
public $currentRecord = '';
/**
* Used by class \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
* to keep track of access-keys.
* @var array
*/
public $accessKey = [];
/**
* Numerical array where image filenames are added if they are referenced in the
* rendered document. This includes only TYPO3 generated/inserted images.
* @var array
*/
public $imagesOnPage = [];
/**
* Is set in ContentObjectRenderer->cImage() function to the info-array of the
* most recent rendered image. The information is used in ImageTextContentObject
* @var array
*/
public $lastImageInfo = [];
/**
* Used to generate page-unique keys. Point is that uniqid() functions is very
* slow, so a unikey key is made based on this, see function uniqueHash()
* @var int
*/
public $uniqueCounter = 0;
/**
* @var string
*/
public $uniqueString = '';
/**
* This value will be used as the title for the page in the indexer (if
* indexing happens)
* @var string
*/
public $indexedDocTitle = '';
/**
* Alternative page title (normally the title of the page record). Can be set
* from applications you make.
* @var string
*/
public $altPageTitle = '';
/**
* The base URL set for the page header.
* @var string
*/
public $baseUrl = '';
/**
* IDs we already rendered for this page (to make sure they are unique)
* @var array
*/
private $usedUniqueIds = [];
/**
* Page content render object
*
* @var ContentObjectRenderer
*/
public $cObj = '';
/**
* All page content is accumulated in this variable. See pagegen.php
* @var string
*/
public $content = '';
/**
* @var int
*/
public $scriptParseTime = 0;
/**
* Character set (charset) conversion object:
* charset conversion class. May be used by any application.
*
* @var CharsetConverter
* @deprecated since TYPO3 v8, will be removed in TYPO3 v9, instantiate CharsetConverter on your own if you need it
*/
public $csConvObj;
/**
* The default charset used in the frontend if nothing else is set.
* @deprecated since TYPO3 v8, will be removed in TYPO3 v9
* @var string
*/
public $defaultCharSet = 'utf-8';
/**
* Internal charset of the frontend during rendering. (Default: UTF-8)
* @deprecated since TYPO3 v8, will be removed in TYPO3 v9
* @var string
*/
public $renderCharset = 'utf-8';
/**
* Output charset of the websites content. This is the charset found in the
* header, meta tag etc. If different than utf-8 a conversion
* happens before output to browser. Defaults to utf-8.
* @var string
*/
public $metaCharset = 'utf-8';
/**
* Set to the system language key (used on the site)
* @var string
*/
public $lang = '';
/**
* @var array
*/
public $LL_labels_cache = [];
/**
* @var array
*/
public $LL_files_cache = [];
/**
* List of language dependencies for actual language. This is used for local
* variants of a language that depend on their "main" language, like Brazilian,
* Portuguese or Canadian French.
*
* @var array
*/
protected $languageDependencies = [];
/**
* @var LockingStrategyInterface[][]
*/
protected $locks = [];
/**
* @var PageRenderer
*/
protected $pageRenderer = null;
/**
* The page cache object, use this to save pages to the cache and to
* retrieve them again
*
* @var \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
*/
protected $pageCache;
/**
* @var array
*/
protected $pageCacheTags = [];
/**
* The cHash Service class used for cHash related functionality
*
* @var CacheHashCalculator
*/
protected $cacheHash;
/**
* Runtime cache of domains per processed page ids.
*
* @var array
*/
protected $domainDataCache = [];
/**
* 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
*
* @var string
*/
protected $contentType = 'text/html';
/**
* Doctype to use
*
* Currently set via PageGenerator
*
* @var string
*/
public $xhtmlDoctype = '';
/**
* @var int
*/
public $xhtmlVersion;
/**
* Originally requested id from the initial $_GET variable
*
* @var int
*/
protected $requestedId;
/**
* @var bool
*/
public $dtdAllowsFrames;
/**
* Class constructor
* Takes a number of GET/POST input variable as arguments and stores them internally.
* The processing of these variables goes on later in this class.
* Also sets a unique string (->uniqueString) for this script instance; A md5 hash of the microtime()
*
* @param array $_ unused, previously defined to set TYPO3_CONF_VARS
* @param mixed $id The value of GeneralUtility::_GP('id')
* @param int $type The value of GeneralUtility::_GP('type')
* @param bool|string $no_cache The value of GeneralUtility::_GP('no_cache'), evaluated to 1/0
* @param string $cHash The value of GeneralUtility::_GP('cHash')
* @param string $_2 previously was used to define the jumpURL
* @param string $MP The value of GeneralUtility::_GP('MP')
* @param string $RDCT The value of GeneralUtility::_GP('RDCT')
* @see \TYPO3\CMS\Frontend\Http\RequestHandler
*/
public function __construct($_ = null, $id, $type, $no_cache = '', $cHash = '', $_2 = null, $MP = '', $RDCT = '')
{
// Setting some variables:
$this->id = $id;
$this->type = $type;
if ($no_cache) {
if ($GLOBALS['TYPO3_CONF_VARS']['FE']['disableNoCacheParameter']) {
$warning = '&no_cache=1 has been ignored because $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set!';
$this->getTimeTracker()->setTSlogMessage($warning, 2);
} else {
$warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '"';
$this->disableCache();
}
GeneralUtility::sysLog($warning, 'cms', GeneralUtility::SYSLOG_SEVERITY_WARNING);
}
$this->cHash = $cHash;
$this->MP = $GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'] ? (string)$MP : '';
$this->RDCT = $RDCT;
$this->uniqueString = md5(microtime());
$this->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
$this->initPageRenderer();
// Call post processing function for constructor:
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'])) {
$_params = ['pObj' => &$this];
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'] as $_funcRef) {
GeneralUtility::callUserFunction($_funcRef, $_params, $this);
}
}
$this->cacheHash = GeneralUtility::makeInstance(CacheHashCalculator::class);
$this->initCaches();
}
/**
* 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');
}
/**
* @param string $contentType
* @internal Should only be used by TYPO3 core for now
*/
public function setContentType($contentType)
{
$this->contentType = $contentType;
}
/**
* Connect to SQL database. May exit after outputting an error message
* or some JavaScript redirecting to the install tool.
*
* @throws \RuntimeException
* @throws ServiceUnavailableException
* @return void
*/
public function connectToDB()
{
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
try {
$connection->connect();
} catch (ConnectionException $exception) {
// Cannot connect to current database
$message = 'Cannot connect to the configured database "' . $connection->getDatabase() . '"';
if ($this->checkPageUnavailableHandler()) {
$this->pageUnavailableAndExit($message);
} else {
GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
throw new ServiceUnavailableException($message, 1301648782);
}
}
// Call post processing function for DB connection:
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'])) {
$_params = ['pObj' => &$this];
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef) {
GeneralUtility::callUserFunction($_funcRef, $_params, $this);
}
}
}
/**
* Looks up the value of $this->RDCT in the database and if it is
* found to be associated with a redirect URL then the redirection
* is carried out with a 'Location:' header
* May exit after sending a location-header.
*
* @return void
*/
public function sendRedirect()
{
if ($this->RDCT) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('cache_md5params');
$row = $queryBuilder
->select('params')
->from('cache_md5params')
->where(
$queryBuilder->expr()->eq('md5hash', $queryBuilder->createNamedParameter($this->RDCT))
)
->execute()
->fetch();
if ($row) {
$this->updateMD5paramsRecord($this->RDCT);
header('Location: ' . $row['params']);
die;
}
}
}
/********************************************
*
* Initializing, resolving page id
*
********************************************/
/**
* Initializes the caching system.
*
* @return void
*/
protected function initCaches()
{
$this->pageCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_pages');
}
/**
* Initializes the front-end login user.
*
* @return void
*/
public function initFEuser()
{
$this->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
$this->fe_user->lockIP = $GLOBALS['TYPO3_CONF_VARS']['FE']['lockIP'];
$this->fe_user->checkPid = $GLOBALS['TYPO3_CONF_VARS']['FE']['checkFeUserPid'];
$this->fe_user->lifetime = (int)$GLOBALS['TYPO3_CONF_VARS']['FE']['lifetime'];
// List of pid's acceptable
$pid = GeneralUtility::_GP('pid');
$this->fe_user->checkPid_value = $pid ? implode(',', GeneralUtility::intExplode(',', $pid)) : 0;
// Check if a session is transferred:
if (GeneralUtility::_GP('FE_SESSION_KEY')) {