[!!!][TASK] Remove various TSFE properties
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Controller / TypoScriptFrontendController.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Doctrine\DBAL\Exception\ConnectionException;
18 use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Cache\CacheManager;
21 use TYPO3\CMS\Core\Charset\CharsetConverter;
22 use TYPO3\CMS\Core\Database\ConnectionPool;
23 use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
24 use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
25 use TYPO3\CMS\Core\Localization\Locales;
26 use TYPO3\CMS\Core\Localization\LocalizationFactory;
27 use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
28 use TYPO3\CMS\Core\Locking\LockFactory;
29 use TYPO3\CMS\Core\Locking\LockingStrategyInterface;
30 use TYPO3\CMS\Core\Messaging\ErrorpageMessage;
31 use TYPO3\CMS\Core\Page\PageRenderer;
32 use TYPO3\CMS\Core\Resource\StorageRepository;
33 use TYPO3\CMS\Core\Service\DependencyOrderingService;
34 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
35 use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
36 use TYPO3\CMS\Core\TypoScript\TemplateService;
37 use TYPO3\CMS\Core\Utility\ArrayUtility;
38 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
39 use TYPO3\CMS\Core\Utility\GeneralUtility;
40 use TYPO3\CMS\Core\Utility\HttpUtility;
41 use TYPO3\CMS\Core\Utility\MathUtility;
42 use TYPO3\CMS\Core\Utility\StringUtility;
43 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
44 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
45 use TYPO3\CMS\Frontend\Http\UrlHandlerInterface;
46 use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
47 use TYPO3\CMS\Frontend\Page\PageGenerator;
48 use TYPO3\CMS\Frontend\Page\PageRepository;
49 use TYPO3\CMS\Frontend\View\AdminPanelView;
50
51 /**
52 * Class for the built TypoScript based frontend. Instantiated in
53 * \TYPO3\CMS\Frontend\Http\RequestHandler as the global object TSFE.
54 *
55 * Main frontend class, instantiated in \TYPO3\CMS\Frontend\Http\RequestHandler
56 * as the global object TSFE.
57 *
58 * This class has a lot of functions and internal variable which are used from
59 * \TYPO3\CMS\Frontend\Http\RequestHandler
60 *
61 * The class is instantiated as $GLOBALS['TSFE'] in \TYPO3\CMS\Frontend\Http\RequestHandler.
62 *
63 * The use of this class should be inspired by the order of function calls as
64 * found in \TYPO3\CMS\Frontend\Http\RequestHandler.
65 */
66 class TypoScriptFrontendController
67 {
68 /**
69 * The page id (int)
70 * @var string
71 */
72 public $id = '';
73
74 /**
75 * The type (read-only)
76 * @var int
77 */
78 public $type = '';
79
80 /**
81 * The submitted cHash
82 * @var string
83 */
84 public $cHash = '';
85
86 /**
87 * Page will not be cached. Write only TRUE. Never clear value (some other
88 * code might have reasons to set it TRUE).
89 * @var bool
90 */
91 public $no_cache = false;
92
93 /**
94 * The rootLine (all the way to tree root, not only the current site!)
95 * @var array
96 */
97 public $rootLine = '';
98
99 /**
100 * The pagerecord
101 * @var array
102 */
103 public $page = '';
104
105 /**
106 * This will normally point to the same value as id, but can be changed to
107 * point to another page from which content will then be displayed instead.
108 * @var int
109 */
110 public $contentPid = 0;
111
112 /**
113 * Gets set when we are processing a page of type mounpoint with enabled overlay in getPageAndRootline()
114 * Used later in checkPageForMountpointRedirect() to determine the final target URL where the user
115 * should be redirected to.
116 *
117 * @var array|NULL
118 */
119 protected $originalMountPointPage = null;
120
121 /**
122 * Gets set when we are processing a page of type shortcut in the early stages
123 * of the request when we do not know about languages yet, used later in the request
124 * to determine the correct shortcut in case a translation changes the shortcut
125 * target
126 * @var array|NULL
127 * @see checkTranslatedShortcut()
128 */
129 protected $originalShortcutPage = null;
130
131 /**
132 * sys_page-object, pagefunctions
133 *
134 * @var PageRepository
135 */
136 public $sys_page = '';
137
138 /**
139 * Contains all URL handler instances that are active for the current request.
140 *
141 * The methods isGeneratePage(), isOutputting() and isINTincScript() depend on this property.
142 *
143 * @var \TYPO3\CMS\Frontend\Http\UrlHandlerInterface[]
144 * @see initializeRedirectUrlHandlers()
145 */
146 protected $activeUrlHandlers = [];
147
148 /**
149 * Is set to 1 if a pageNotFound handler could have been called.
150 * @var int
151 */
152 public $pageNotFound = 0;
153
154 /**
155 * Domain start page
156 * @var int
157 */
158 public $domainStartPage = 0;
159
160 /**
161 * Array containing a history of why a requested page was not accessible.
162 * @var array
163 */
164 public $pageAccessFailureHistory = array();
165
166 /**
167 * @var string
168 */
169 public $MP = '';
170
171 /**
172 * @var string
173 */
174 public $RDCT = '';
175
176 /**
177 * This can be set from applications as a way to tag cached versions of a page
178 * and later perform some external cache management, like clearing only a part
179 * of the cache of a page...
180 * @var int
181 */
182 public $page_cache_reg1 = 0;
183
184 /**
185 * Contains the value of the current script path that activated the frontend.
186 * Typically "index.php" but by rewrite rules it could be something else! Used
187 * for Speaking Urls / Simulate Static Documents.
188 * @var string
189 */
190 public $siteScript = '';
191
192 /**
193 * The frontend user
194 *
195 * @var FrontendUserAuthentication
196 */
197 public $fe_user = '';
198
199 /**
200 * Global flag indicating that a frontend user is logged in. This is set only if
201 * a user really IS logged in. The group-list may show other groups (like added
202 * by IP filter or so) even though there is no user.
203 * @var bool
204 */
205 public $loginUser = false;
206
207 /**
208 * (RO=readonly) The group list, sorted numerically. Group '0,-1' is the default
209 * group, but other groups may be added by other means than a user being logged
210 * in though...
211 * @var string
212 */
213 public $gr_list = '';
214
215 /**
216 * Flag that indicates if a backend user is logged in!
217 * @var bool
218 */
219 public $beUserLogin = false;
220
221 /**
222 * Integer, that indicates which workspace is being previewed.
223 * @var int
224 */
225 public $workspacePreview = 0;
226
227 /**
228 * Shows whether logins are allowed in branch
229 * @var bool
230 */
231 public $loginAllowedInBranch = true;
232
233 /**
234 * Shows specific mode (all or groups)
235 * @var string
236 */
237 public $loginAllowedInBranch_mode = '';
238
239 /**
240 * Set to backend user ID to initialize when keyword-based preview is used
241 * @var int
242 */
243 public $ADMCMD_preview_BEUSER_uid = 0;
244
245 /**
246 * Flag indication that preview is active. This is based on the login of a
247 * backend user and whether the backend user has read access to the current
248 * page. A value of 1 means ordinary preview, 2 means preview of a non-live
249 * workspace
250 * @var int
251 */
252 public $fePreview = 0;
253
254 /**
255 * Flag indicating that hidden pages should be shown, selected and so on. This
256 * goes for almost all selection of pages!
257 * @var bool
258 */
259 public $showHiddenPage = false;
260
261 /**
262 * Flag indicating that hidden records should be shown. This includes
263 * sys_template, pages_language_overlay and even fe_groups in addition to all
264 * other regular content. So in effect, this includes everything except pages.
265 * @var bool
266 */
267 public $showHiddenRecords = false;
268
269 /**
270 * Value that contains the simulated usergroup if any
271 * @var int
272 */
273 public $simUserGroup = 0;
274
275 /**
276 * "CONFIG" object from TypoScript. Array generated based on the TypoScript
277 * configuration of the current page. Saved with the cached pages.
278 * @var array
279 */
280 public $config = '';
281
282 /**
283 * The TypoScript template object. Used to parse the TypoScript template
284 *
285 * @var TemplateService
286 */
287 public $tmpl = null;
288
289 /**
290 * Is set to the time-to-live time of cached pages. If FALSE, default is
291 * 60*60*24, which is 24 hours.
292 * @var bool|int
293 */
294 public $cacheTimeOutDefault = false;
295
296 /**
297 * Set internally if cached content is fetched from the database
298 * @var bool
299 * @internal
300 */
301 public $cacheContentFlag = false;
302
303 /**
304 * Set to the expire time of cached content
305 * @var int
306 */
307 public $cacheExpires = 0;
308
309 /**
310 * Set if cache headers allowing caching are sent.
311 * @var bool
312 */
313 public $isClientCachable = false;
314
315 /**
316 * Used by template fetching system. This array is an identification of
317 * the template. If $this->all is empty it's because the template-data is not
318 * cached, which it must be.
319 * @var array
320 */
321 public $all = array();
322
323 /**
324 * Toplevel - objArrayName, eg 'page'
325 * @var string
326 */
327 public $sPre = '';
328
329 /**
330 * TypoScript configuration of the page-object pointed to by sPre.
331 * $this->tmpl->setup[$this->sPre.'.']
332 * @var array
333 */
334 public $pSetup = '';
335
336 /**
337 * This hash is unique to the template, the $this->id and $this->type vars and
338 * the gr_list (list of groups). Used to get and later store the cached data
339 * @var string
340 */
341 public $newHash = '';
342
343 /**
344 * If config.ftu (Frontend Track User) is set in TypoScript for the current
345 * page, the string value of this var is substituted in the rendered source-code
346 * with the string, '&ftu=[token...]' which enables GET-method usertracking as
347 * opposed to cookie based
348 * @var string
349 */
350 public $getMethodUrlIdToken = '';
351
352 /**
353 * This flag is set before inclusion of pagegen.php IF no_cache is set. If this
354 * flag is set after the inclusion of pagegen.php, no_cache is forced to be set.
355 * This is done in order to make sure that php-code from pagegen does not falsely
356 * clear the no_cache flag.
357 * @var bool
358 */
359 public $no_cacheBeforePageGen = false;
360
361 /**
362 * This flag indicates if temporary content went into the cache during
363 * page-generation.
364 * @var mixed
365 */
366 public $tempContent = false;
367
368 /**
369 * Passed to TypoScript template class and tells it to force template rendering
370 * @var bool
371 */
372 public $forceTemplateParsing = false;
373
374 /**
375 * The array which cHash_calc is based on, see ->makeCacheHash().
376 * @var array
377 */
378 public $cHash_array = array();
379
380 /**
381 * May be set to the pagesTSconfig
382 * @var array
383 */
384 public $pagesTSconfig = '';
385
386 /**
387 * Eg. insert JS-functions in this array ($additionalHeaderData) to include them
388 * once. Use associative keys.
389 *
390 * Keys in use:
391 *
392 * JSFormValidate: <script type="text/javascript" src="'.$GLOBALS["TSFE"]->absRefPrefix.'typo3/sysext/frontend/Resources/Public/JavaScript/jsfunc.validateform.js"></script>
393 * JSMenuCode, JSMenuCode_menu: JavaScript for the JavaScript menu
394 * JSCode: reserved
395 *
396 * used to accumulate additional HTML-code for the header-section,
397 * <head>...</head>. Insert either associative keys (like
398 * additionalHeaderData['myStyleSheet'], see reserved keys above) or num-keys
399 * (like additionalHeaderData[] = '...')
400 *
401 * @var array
402 */
403 public $additionalHeaderData = array();
404
405 /**
406 * Used to accumulate additional HTML-code for the footer-section of the template
407 * @var array
408 */
409 public $additionalFooterData = array();
410
411 /**
412 * Used to accumulate additional JavaScript-code. Works like
413 * additionalHeaderData. Reserved keys at 'openPic' and 'mouseOver'
414 *
415 * @var array
416 */
417 public $additionalJavaScript = array();
418
419 /**
420 * Used to accumulate additional Style code. Works like additionalHeaderData.
421 *
422 * @var array
423 */
424 public $additionalCSS = array();
425
426 /**
427 * @var string
428 */
429 public $JSCode;
430
431 /**
432 * @var string
433 */
434 public $inlineJS;
435
436 /**
437 * Used to accumulate DHTML-layers.
438 * @var string
439 */
440 public $divSection = '';
441
442 /**
443 * Debug flag. If TRUE special debug-output maybe be shown (which includes html-formatting).
444 * @var bool
445 */
446 public $debug = false;
447
448 /**
449 * Default internal target
450 * @var string
451 */
452 public $intTarget = '';
453
454 /**
455 * Default external target
456 * @var string
457 */
458 public $extTarget = '';
459
460 /**
461 * Default file link target
462 * @var string
463 */
464 public $fileTarget = '';
465
466 /**
467 * Keys are page ids and values are default &MP (mount point) values to set
468 * when using the linking features...)
469 * @var array
470 */
471 public $MP_defaults = array();
472
473 /**
474 * If set, typolink() function encrypts email addresses. Is set in pagegen-class.
475 * @var string|int
476 */
477 public $spamProtectEmailAddresses = 0;
478
479 /**
480 * Absolute Reference prefix
481 * @var string
482 */
483 public $absRefPrefix = '';
484
485 /**
486 * Factor for form-field widths compensation
487 * @var string
488 */
489 public $compensateFieldWidth = '';
490
491 /**
492 * Lock file path
493 * @var string
494 */
495 public $lockFilePath = '';
496
497 /**
498 * <A>-tag parameters
499 * @var string
500 */
501 public $ATagParams = '';
502
503 /**
504 * Search word regex, calculated if there has been search-words send. This is
505 * used to mark up the found search words on a page when jumped to from a link
506 * in a search-result.
507 * @var string
508 */
509 public $sWordRegEx = '';
510
511 /**
512 * Is set to the incoming array sword_list in case of a page-view jumped to from
513 * a search-result.
514 * @var string
515 */
516 public $sWordList = '';
517
518 /**
519 * A string prepared for insertion in all links on the page as url-parameters.
520 * Based on configuration in TypoScript where you defined which GET_VARS you
521 * would like to pass on.
522 * @var string
523 */
524 public $linkVars = '';
525
526 /**
527 * A string set with a comma list of additional GET vars which should NOT be
528 * included in the cHash calculation. These vars should otherwise be detected
529 * and involved in caching, eg. through a condition in TypoScript.
530 * @var string
531 */
532 public $excludeCHashVars = '';
533
534 /**
535 * If set, edit icons are rendered aside content records. Must be set only if
536 * the ->beUserLogin flag is set and set_no_cache() must be called as well.
537 * @var string
538 */
539 public $displayEditIcons = '';
540
541 /**
542 * If set, edit icons are rendered aside individual fields of content. Must be
543 * set only if the ->beUserLogin flag is set and set_no_cache() must be called as
544 * well.
545 * @var string
546 */
547 public $displayFieldEditIcons = '';
548
549 /**
550 * Site language, 0 (zero) is default, int+ is uid pointing to a sys_language
551 * record. Should reflect which language menus, templates etc is displayed in
552 * (master language) - but not necessarily the content which could be falling
553 * back to default (see sys_language_content)
554 * @var int
555 */
556 public $sys_language_uid = 0;
557
558 /**
559 * Site language mode for content fall back.
560 * @var string
561 */
562 public $sys_language_mode = '';
563
564 /**
565 * Site content selection uid (can be different from sys_language_uid if content
566 * is to be selected from a fall-back language. Depends on sys_language_mode)
567 * @var int
568 */
569 public $sys_language_content = 0;
570
571 /**
572 * Site content overlay flag; If set - and sys_language_content is > 0 - ,
573 * records selected will try to look for a translation pointing to their uid. (If
574 * configured in [ctrl][languageField] / [ctrl][transOrigP...]
575 * @var int
576 */
577 public $sys_language_contentOL = 0;
578
579 /**
580 * Is set to the iso code of the sys_language_content if that is properly defined
581 * by the sys_language record representing the sys_language_uid.
582 * @var string
583 */
584 public $sys_language_isocode = '';
585
586 /**
587 * 'Global' Storage for various applications. Keys should be 'tx_'.extKey for
588 * extensions.
589 * @var array
590 */
591 public $applicationData = array();
592
593 /**
594 * @var array
595 */
596 public $register = array();
597
598 /**
599 * Stack used for storing array and retrieving register arrays (see
600 * LOAD_REGISTER and RESTORE_REGISTER)
601 * @var array
602 */
603 public $registerStack = array();
604
605 /**
606 * Checking that the function is not called eternally. This is done by
607 * interrupting at a depth of 50
608 * @var int
609 */
610 public $cObjectDepthCounter = 50;
611
612 /**
613 * Used by RecordContentObject and ContentContentObject to ensure the a records is NOT
614 * rendered twice through it!
615 * @var array
616 */
617 public $recordRegister = array();
618
619 /**
620 * This is set to the [table]:[uid] of the latest record rendered. Note that
621 * class ContentObjectRenderer has an equal value, but that is pointing to the
622 * record delivered in the $data-array of the ContentObjectRenderer instance, if
623 * the cObjects CONTENT or RECORD created that instance
624 * @var string
625 */
626 public $currentRecord = '';
627
628 /**
629 * Used by class \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
630 * to keep track of access-keys.
631 * @var array
632 */
633 public $accessKey = array();
634
635 /**
636 * Numerical array where image filenames are added if they are referenced in the
637 * rendered document. This includes only TYPO3 generated/inserted images.
638 * @var array
639 */
640 public $imagesOnPage = array();
641
642 /**
643 * Is set in ContentObjectRenderer->cImage() function to the info-array of the
644 * most recent rendered image. The information is used in ImageTextContentObject
645 * @var array
646 */
647 public $lastImageInfo = array();
648
649 /**
650 * Used to generate page-unique keys. Point is that uniqid() functions is very
651 * slow, so a unikey key is made based on this, see function uniqueHash()
652 * @var int
653 */
654 public $uniqueCounter = 0;
655
656 /**
657 * @var string
658 */
659 public $uniqueString = '';
660
661 /**
662 * This value will be used as the title for the page in the indexer (if
663 * indexing happens)
664 * @var string
665 */
666 public $indexedDocTitle = '';
667
668 /**
669 * Alternative page title (normally the title of the page record). Can be set
670 * from applications you make.
671 * @var string
672 */
673 public $altPageTitle = '';
674
675 /**
676 * The base URL set for the page header.
677 * @var string
678 */
679 public $baseUrl = '';
680
681 /**
682 * IDs we already rendered for this page (to make sure they are unique)
683 * @var array
684 */
685 private $usedUniqueIds = array();
686
687 /**
688 * Page content render object
689 *
690 * @var ContentObjectRenderer
691 */
692 public $cObj = '';
693
694 /**
695 * All page content is accumulated in this variable. See pagegen.php
696 * @var string
697 */
698 public $content = '';
699
700 /**
701 * @var int
702 */
703 public $scriptParseTime = 0;
704
705 /**
706 * Character set (charset) conversion object:
707 * charset conversion class. May be used by any application.
708 *
709 * @var CharsetConverter
710 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, instantiate CharsetConverter on your own if you need it
711 */
712 public $csConvObj;
713
714 /**
715 * The default charset used in the frontend if nothing else is set.
716 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
717 * @var string
718 */
719 public $defaultCharSet = 'utf-8';
720
721 /**
722 * Internal charset of the frontend during rendering. (Default: UTF-8)
723 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
724 * @var string
725 */
726 public $renderCharset = 'utf-8';
727
728 /**
729 * Output charset of the websites content. This is the charset found in the
730 * header, meta tag etc. If different than utf-8 a conversion
731 * happens before output to browser. Defaults to utf-8.
732 * @var string
733 */
734 public $metaCharset = 'utf-8';
735
736 /**
737 * Set to the system language key (used on the site)
738 * @var string
739 */
740 public $lang = '';
741
742 /**
743 * @var array
744 */
745 public $LL_labels_cache = array();
746
747 /**
748 * @var array
749 */
750 public $LL_files_cache = array();
751
752 /**
753 * List of language dependencies for actual language. This is used for local
754 * variants of a language that depend on their "main" language, like Brazilian,
755 * Portuguese or Canadian French.
756 *
757 * @var array
758 */
759 protected $languageDependencies = array();
760
761 /**
762 * @var LockingStrategyInterface[][]
763 */
764 protected $locks = [];
765
766 /**
767 * @var PageRenderer
768 */
769 protected $pageRenderer = null;
770
771 /**
772 * The page cache object, use this to save pages to the cache and to
773 * retrieve them again
774 *
775 * @var \TYPO3\CMS\Core\Cache\Backend\AbstractBackend
776 */
777 protected $pageCache;
778
779 /**
780 * @var array
781 */
782 protected $pageCacheTags = array();
783
784 /**
785 * The cHash Service class used for cHash related functionality
786 *
787 * @var CacheHashCalculator
788 */
789 protected $cacheHash;
790
791 /**
792 * Runtime cache of domains per processed page ids.
793 *
794 * @var array
795 */
796 protected $domainDataCache = array();
797
798 /**
799 * Content type HTTP header being sent in the request.
800 * @todo Ticket: #63642 Should be refactored to a request/response model later
801 * @internal Should only be used by TYPO3 core for now
802 *
803 * @var string
804 */
805 protected $contentType = 'text/html';
806
807 /**
808 * Doctype to use
809 *
810 * Currently set via PageGenerator
811 *
812 * @var string
813 */
814 public $xhtmlDoctype = '';
815
816 /**
817 * @var int
818 */
819 public $xhtmlVersion;
820
821 /**
822 * Originally requested id from the initial $_GET variable
823 *
824 * @var int
825 */
826 protected $requestedId;
827
828 /**
829 * @var bool
830 */
831 public $dtdAllowsFrames;
832
833 /**
834 * Class constructor
835 * Takes a number of GET/POST input variable as arguments and stores them internally.
836 * The processing of these variables goes on later in this class.
837 * Also sets a unique string (->uniqueString) for this script instance; A md5 hash of the microtime()
838 *
839 * @param array $_ unused, previously defined to set TYPO3_CONF_VARS
840 * @param mixed $id The value of GeneralUtility::_GP('id')
841 * @param int $type The value of GeneralUtility::_GP('type')
842 * @param bool|string $no_cache The value of GeneralUtility::_GP('no_cache'), evaluated to 1/0
843 * @param string $cHash The value of GeneralUtility::_GP('cHash')
844 * @param string $_2 previously was used to define the jumpURL
845 * @param string $MP The value of GeneralUtility::_GP('MP')
846 * @param string $RDCT The value of GeneralUtility::_GP('RDCT')
847 * @see \TYPO3\CMS\Frontend\Http\RequestHandler
848 */
849 public function __construct($_ = null, $id, $type, $no_cache = '', $cHash = '', $_2 = null, $MP = '', $RDCT = '')
850 {
851 // Setting some variables:
852 $this->id = $id;
853 $this->type = $type;
854 if ($no_cache) {
855 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['disableNoCacheParameter']) {
856 $warning = '&no_cache=1 has been ignored because $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set!';
857 $this->getTimeTracker()->setTSlogMessage($warning, 2);
858 } else {
859 $warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '"';
860 $this->disableCache();
861 }
862 GeneralUtility::sysLog($warning, 'cms', GeneralUtility::SYSLOG_SEVERITY_WARNING);
863 }
864 $this->cHash = $cHash;
865 $this->MP = $GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'] ? (string)$MP : '';
866 $this->RDCT = $RDCT;
867 $this->uniqueString = md5(microtime());
868 $this->csConvObj = GeneralUtility::makeInstance(CharsetConverter::class);
869 $this->initPageRenderer();
870 // Call post processing function for constructor:
871 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'])) {
872 $_params = array('pObj' => &$this);
873 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'] as $_funcRef) {
874 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
875 }
876 }
877 $this->cacheHash = GeneralUtility::makeInstance(CacheHashCalculator::class);
878 $this->initCaches();
879 }
880
881 /**
882 * Initializes the page renderer object
883 */
884 protected function initPageRenderer()
885 {
886 if ($this->pageRenderer !== null) {
887 return;
888 }
889 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
890 $this->pageRenderer->setTemplateFile('EXT:frontend/Resources/Private/Templates/MainPage.html');
891 }
892
893 /**
894 * @param string $contentType
895 * @internal Should only be used by TYPO3 core for now
896 */
897 public function setContentType($contentType)
898 {
899 $this->contentType = $contentType;
900 }
901
902 /**
903 * Connect to SQL database. May exit after outputting an error message
904 * or some JavaScript redirecting to the install tool.
905 *
906 * @throws \RuntimeException
907 * @throws ServiceUnavailableException
908 * @return void
909 */
910 public function connectToDB()
911 {
912 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
913 try {
914 $connection->connect();
915 } catch (ConnectionException $exception) {
916 // Cannot connect to current database
917 $message = 'Cannot connect to the configured database "' . $connection->getDatabase() . '"';
918 if ($this->checkPageUnavailableHandler()) {
919 $this->pageUnavailableAndExit($message);
920 } else {
921 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
922 throw new ServiceUnavailableException($message, 1301648782);
923 }
924 }
925 // Call post processing function for DB connection:
926 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'])) {
927 $_params = array('pObj' => &$this);
928 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef) {
929 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
930 }
931 }
932 }
933
934 /**
935 * Looks up the value of $this->RDCT in the database and if it is
936 * found to be associated with a redirect URL then the redirection
937 * is carried out with a 'Location:' header
938 * May exit after sending a location-header.
939 *
940 * @return void
941 */
942 public function sendRedirect()
943 {
944 if ($this->RDCT) {
945 $db = $this->getDatabaseConnection();
946 $row = $db->exec_SELECTgetSingleRow('params', 'cache_md5params', 'md5hash=' . $db->fullQuoteStr($this->RDCT, 'cache_md5params'));
947 if ($row) {
948 $this->updateMD5paramsRecord($this->RDCT);
949 header('Location: ' . $row['params']);
950 die;
951 }
952 }
953 }
954
955 /********************************************
956 *
957 * Initializing, resolving page id
958 *
959 ********************************************/
960 /**
961 * Initializes the caching system.
962 *
963 * @return void
964 */
965 protected function initCaches()
966 {
967 $this->pageCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_pages');
968 }
969
970 /**
971 * Initializes the front-end login user.
972 *
973 * @return void
974 */
975 public function initFEuser()
976 {
977 $this->fe_user = GeneralUtility::makeInstance(FrontendUserAuthentication::class);
978 $this->fe_user->lockIP = $GLOBALS['TYPO3_CONF_VARS']['FE']['lockIP'];
979 $this->fe_user->checkPid = $GLOBALS['TYPO3_CONF_VARS']['FE']['checkFeUserPid'];
980 $this->fe_user->lifetime = (int)$GLOBALS['TYPO3_CONF_VARS']['FE']['lifetime'];
981 // List of pid's acceptable
982 $pid = GeneralUtility::_GP('pid');
983 $this->fe_user->checkPid_value = $pid ? $this->getDatabaseConnection()->cleanIntList($pid) : 0;
984 // Check if a session is transferred:
985 if (GeneralUtility::_GP('FE_SESSION_KEY')) {
986 $fe_sParts = explode('-', GeneralUtility::_GP('FE_SESSION_KEY'));
987 // If the session key hash check is OK:
988 if (md5(($fe_sParts[0] . '/' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) === (string)$fe_sParts[1]) {
989 $cookieName = FrontendUserAuthentication::getCookieName();
990 $_COOKIE[$cookieName] = $fe_sParts[0];
991 if (isset($_SERVER['HTTP_COOKIE'])) {
992 // See http://forge.typo3.org/issues/27740
993 $_SERVER['HTTP_COOKIE'] .= ';' . $cookieName . '=' . $fe_sParts[0];
994 }
995 $this->fe_user->forceSetCookie = 1;
996 $this->fe_user->dontSetCookie = false;
997 unset($cookieName);
998 }
999 }
1000 $this->fe_user->start();
1001 $this->fe_user->unpack_uc('');
1002 // Gets session data
1003 $this->fe_user->fetchSessionData();
1004 $recs = GeneralUtility::_GP('recs');
1005 // If any record registration is submitted, register the record.
1006 if (is_array($recs)) {
1007 $this->fe_user->record_registration($recs, $GLOBALS['TYPO3_CONF_VARS']['FE']['maxSessionDataSize']);
1008 }
1009 // Call hook for possible manipulation of frontend user object
1010 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'])) {
1011 $_params = array('pObj' => &$this);
1012 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'] as $_funcRef) {
1013 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1014 }
1015 }
1016 // For every 60 seconds the is_online timestamp is updated.
1017 if (is_array($this->fe_user->user) && $this->fe_user->user['uid'] && $this->fe_user->user['is_online'] < $GLOBALS['EXEC_TIME'] - 60) {
1018 $this->getDatabaseConnection()->exec_UPDATEquery('fe_users', 'uid=' . (int)$this->fe_user->user['uid'], array('is_online' => $GLOBALS['EXEC_TIME']));
1019 }
1020 }
1021
1022 /**
1023 * Initializes the front-end user groups.
1024 * Sets ->loginUser and ->gr_list based on front-end user status.
1025 *
1026 * @return void
1027 */
1028 public function initUserGroups()
1029 {
1030 // This affects the hidden-flag selecting the fe_groups for the user!
1031 $this->fe_user->showHiddenRecords = $this->showHiddenRecords;
1032 // no matter if we have an active user we try to fetch matching groups which can be set without an user (simulation for instance!)
1033 $this->fe_user->fetchGroupData();
1034 if (is_array($this->fe_user->user) && !empty($this->fe_user->groupData['uid'])) {
1035 // global flag!
1036 $this->loginUser = true;
1037 // group -2 is not an existing group, but denotes a 'default' group when a user IS logged in. This is used to let elements be shown for all logged in users!
1038 $this->gr_list = '0,-2';
1039 $gr_array = $this->fe_user->groupData['uid'];
1040 } else {
1041 $this->loginUser = false;
1042 // group -1 is not an existing group, but denotes a 'default' group when not logged in. This is used to let elements be hidden, when a user is logged in!
1043 $this->gr_list = '0,-1';
1044 if ($this->loginAllowedInBranch) {
1045 // For cases where logins are not banned from a branch usergroups can be set based on IP masks so we should add the usergroups uids.
1046 $gr_array = $this->fe_user->groupData['uid'];
1047 } else {
1048 // Set to blank since we will NOT risk any groups being set when no logins are allowed!
1049 $gr_array = array();
1050 }
1051 }
1052 // Clean up.
1053 // Make unique...
1054 $gr_array = array_unique($gr_array);
1055 // sort
1056 sort($gr_array);
1057 if (!empty($gr_array) && !$this->loginAllowedInBranch_mode) {
1058 $this->gr_list .= ',' . implode(',', $gr_array);
1059 }
1060 if ($this->fe_user->writeDevLog) {
1061 GeneralUtility::devLog('Valid usergroups for TSFE: ' . $this->gr_list, __CLASS__);
1062 }
1063 }
1064
1065 /**
1066 * Checking if a user is logged in or a group constellation different from "0,-1"
1067 *
1068 * @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!)
1069 */
1070 public function isUserOrGroupSet()
1071 {
1072 return is_array($this->fe_user->user) || $this->gr_list !== '0,-1';
1073 }
1074
1075 /**
1076 * Provides ways to bypass the '?id=[xxx]&type=[xx]' format, using either PATH_INFO or virtual HTML-documents (using Apache mod_rewrite)
1077 *
1078 * Two options:
1079 * 1) Use PATH_INFO (also Apache) to extract id and type from that var. Does not require any special modules compiled with apache. (less typical)
1080 * 2) Using hook which enables features like those provided from "realurl" extension (AKA "Speaking URLs")
1081 *
1082 * @return void
1083 */
1084 public function checkAlternativeIdMethods()
1085 {
1086 $this->siteScript = GeneralUtility::getIndpEnv('TYPO3_SITE_SCRIPT');
1087 // Call post processing function for custom URL methods.
1088 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'])) {
1089 $_params = array('pObj' => &$this);
1090 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'] as $_funcRef) {
1091 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1092 }
1093 }
1094 }
1095
1096 /**
1097 * Clears the preview-flags, sets sim_exec_time to current time.
1098 * Hidden pages must be hidden as default, $GLOBALS['SIM_EXEC_TIME'] is set to $GLOBALS['EXEC_TIME']
1099 * in bootstrap initializeGlobalTimeVariables(). Alter it by adding or subtracting seconds.
1100 *
1101 * @return void
1102 */
1103 public function clear_preview()
1104 {
1105 $this->showHiddenPage = false;
1106 $this->showHiddenRecords = false;
1107 $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
1108 $GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
1109 $this->fePreview = 0;
1110 }
1111
1112 /**
1113 * Checks if a backend user is logged in
1114 *
1115 * @return bool whether a backend user is logged in
1116 */
1117 public function isBackendUserLoggedIn()
1118 {
1119 return (bool)$this->beUserLogin;
1120 }
1121
1122 /**
1123 * Creates the backend user object and returns it.
1124 *
1125 * @return FrontendBackendUserAuthentication the backend user object
1126 */
1127 public function initializeBackendUser()
1128 {
1129 // PRE BE_USER HOOK
1130 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
1131 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
1132 $_params = array();
1133 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1134 }
1135 }
1136 /** @var $BE_USER FrontendBackendUserAuthentication */
1137 $BE_USER = null;
1138 // If the backend cookie is set,
1139 // we proceed and check if a backend user is logged in.
1140 if ($_COOKIE[BackendUserAuthentication::getCookieName()]) {
1141 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = microtime(true);
1142 $this->getTimeTracker()->push('Back End user initialized', '');
1143 // @todo validate the comment below: is this necessary? if so,
1144 // formfield_status should be set to "" in \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
1145 // which is a subclass of \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1146 // ----
1147 // the value this->formfield_status is set to empty in order to
1148 // disable login-attempts to the backend account through this script
1149 // New backend user object
1150 $BE_USER = GeneralUtility::makeInstance(FrontendBackendUserAuthentication::class);
1151 $BE_USER->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
1152 // Object is initialized
1153 $BE_USER->start();
1154 $BE_USER->unpack_uc('');
1155 if (!empty($BE_USER->user['uid'])) {
1156 $BE_USER->fetchGroupData();
1157 $this->beUserLogin = true;
1158 }
1159 // Unset the user initialization.
1160 if (!$BE_USER->checkLockToIP() || !$BE_USER->checkBackendAccessSettingsFromInitPhp() || empty($BE_USER->user['uid'])) {
1161 $BE_USER = null;
1162 $this->beUserLogin = false;
1163 }
1164 $this->getTimeTracker()->pull();
1165 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = microtime(true);
1166 }
1167 // POST BE_USER HOOK
1168 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['postBeUser'])) {
1169 $_params = array(
1170 'BE_USER' => &$BE_USER
1171 );
1172 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['postBeUser'] as $_funcRef) {
1173 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1174 }
1175 }
1176 return $BE_USER;
1177 }
1178
1179 /**
1180 * Determines the id and evaluates any preview settings
1181 * Basically this function is about determining whether a backend user is logged in,
1182 * if he has read access to the page and if he's previewing the page.
1183 * That all determines which id to show and how to initialize the id.
1184 *
1185 * @return void
1186 */
1187 public function determineId()
1188 {
1189 // Call pre processing function for id determination
1190 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PreProcessing'])) {
1191 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PreProcessing'] as $functionReference) {
1192 $parameters = array('parentObject' => $this);
1193 GeneralUtility::callUserFunction($functionReference, $parameters, $this);
1194 }
1195 }
1196 // If there is a Backend login we are going to check for any preview settings:
1197 $this->getTimeTracker()->push('beUserLogin', '');
1198 $originalFrontendUser = null;
1199 $backendUser = $this->getBackendUser();
1200 if ($this->beUserLogin || $this->doWorkspacePreview()) {
1201 // Backend user preview features:
1202 if ($this->beUserLogin && $backendUser->adminPanel instanceof AdminPanelView) {
1203 $this->fePreview = (int)$backendUser->adminPanel->extGetFeAdminValue('preview');
1204 // If admin panel preview is enabled...
1205 if ($this->fePreview) {
1206 if ($this->fe_user->user) {
1207 $originalFrontendUser = $this->fe_user->user;
1208 }
1209 $this->showHiddenPage = (bool)$backendUser->adminPanel->extGetFeAdminValue('preview', 'showHiddenPages');
1210 $this->showHiddenRecords = (bool)$backendUser->adminPanel->extGetFeAdminValue('preview', 'showHiddenRecords');
1211 // Simulate date
1212 $simTime = $backendUser->adminPanel->extGetFeAdminValue('preview', 'simulateDate');
1213 if ($simTime) {
1214 $GLOBALS['SIM_EXEC_TIME'] = $simTime;
1215 $GLOBALS['SIM_ACCESS_TIME'] = $simTime - $simTime % 60;
1216 }
1217 // simulate user
1218 $simUserGroup = $backendUser->adminPanel->extGetFeAdminValue('preview', 'simulateUserGroup');
1219 $this->simUserGroup = $simUserGroup;
1220 if ($simUserGroup) {
1221 if ($this->fe_user->user) {
1222 $this->fe_user->user[$this->fe_user->usergroup_column] = $simUserGroup;
1223 } else {
1224 $this->fe_user->user = array(
1225 $this->fe_user->usergroup_column => $simUserGroup
1226 );
1227 }
1228 }
1229 if (!$simUserGroup && !$simTime && !$this->showHiddenPage && !$this->showHiddenRecords) {
1230 $this->fePreview = 0;
1231 }
1232 }
1233 }
1234 if ($this->id) {
1235 if ($this->determineIdIsHiddenPage()) {
1236 // The preview flag is set only if the current page turns out to actually be hidden!
1237 $this->fePreview = 1;
1238 $this->showHiddenPage = true;
1239 }
1240 // For Live workspace: Check root line for proper connection to tree root (done because of possible preview of page / branch versions)
1241 if (!$this->fePreview && $this->whichWorkspace() === 0) {
1242 // Initialize the page-select functions to check rootline:
1243 $temp_sys_page = GeneralUtility::makeInstance(PageRepository::class);
1244 $temp_sys_page->init($this->showHiddenPage);
1245 // If root line contained NO records and ->error_getRootLine_failPid tells us that it was because of a pid=-1 (indicating a "version" record)...:
1246 if (empty($temp_sys_page->getRootLine($this->id, $this->MP)) && $temp_sys_page->error_getRootLine_failPid == -1) {
1247 // Setting versioningPreview flag and try again:
1248 $temp_sys_page->versioningPreview = true;
1249 if (!empty($temp_sys_page->getRootLine($this->id, $this->MP))) {
1250 // Finally, we got a root line (meaning that it WAS due to versioning preview of a page somewhere) and we set the fePreview flag which in itself will allow sys_page class to display previews of versionized records.
1251 $this->fePreview = 1;
1252 }
1253 }
1254 }
1255 }
1256 // The preview flag will be set if a backend user is in an offline workspace
1257 if (
1258 (
1259 $backendUser->user['workspace_preview']
1260 || GeneralUtility::_GP('ADMCMD_view')
1261 || $this->doWorkspacePreview()
1262 )
1263 && (
1264 $this->whichWorkspace() === -1
1265 || $this->whichWorkspace() > 0
1266 )
1267 && !GeneralUtility::_GP('ADMCMD_noBeUser')
1268 ) {
1269 // Will show special preview message.
1270 $this->fePreview = 2;
1271 }
1272 // If the front-end is showing a preview, caching MUST be disabled.
1273 if ($this->fePreview) {
1274 $this->disableCache();
1275 }
1276 }
1277 $this->getTimeTracker()->pull();
1278 // Now, get the id, validate access etc:
1279 $this->fetch_the_id();
1280 // Check if backend user has read access to this page. If not, recalculate the id.
1281 if ($this->beUserLogin && $this->fePreview) {
1282 if (!$backendUser->doesUserHaveAccess($this->page, 1)) {
1283 // Resetting
1284 $this->clear_preview();
1285 $this->fe_user->user = $originalFrontendUser;
1286 // Fetching the id again, now with the preview settings reset.
1287 $this->fetch_the_id();
1288 }
1289 }
1290 // Checks if user logins are blocked for a certain branch and if so, will unset user login and re-fetch ID.
1291 $this->loginAllowedInBranch = $this->checkIfLoginAllowedInBranch();
1292 // Logins are not allowed:
1293 if (!$this->loginAllowedInBranch) {
1294 // Only if there is a login will we run this...
1295 if ($this->isUserOrGroupSet()) {
1296 if ($this->loginAllowedInBranch_mode == 'all') {
1297 // Clear out user and group:
1298 $this->fe_user->hideActiveLogin();
1299 $this->gr_list = '0,-1';
1300 } else {
1301 $this->gr_list = '0,-2';
1302 }
1303 // Fetching the id again, now with the preview settings reset.
1304 $this->fetch_the_id();
1305 }
1306 }
1307 // Final cleaning.
1308 // Make sure it's an integer
1309 $this->id = ($this->contentPid = (int)$this->id);
1310 // Make sure it's an integer
1311 $this->type = (int)$this->type;
1312 // Call post processing function for id determination:
1313 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'])) {
1314 $_params = array('pObj' => &$this);
1315 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'] as $_funcRef) {
1316 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1317 }
1318 }
1319 }
1320
1321 /**
1322 * Checks if the page is hidden in the active workspace.
1323 * If it is hidden, preview flags will be set.
1324 *
1325 * @return bool
1326 */
1327 protected function determineIdIsHiddenPage()
1328 {
1329 $field = MathUtility::canBeInterpretedAsInteger($this->id) ? 'uid' : 'alias';
1330 $pageSelectCondition = $field . '=' . $this->getDatabaseConnection()->fullQuoteStr($this->id, 'pages');
1331 $page = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid,hidden,starttime,endtime', 'pages', $pageSelectCondition . ' AND pid>=0 AND deleted=0');
1332 $workspace = $this->whichWorkspace();
1333 if ($workspace !== 0 && $workspace !== false) {
1334 // Fetch overlay of page if in workspace and check if it is hidden
1335 $pageSelectObject = GeneralUtility::makeInstance(PageRepository::class);
1336 $pageSelectObject->versioningPreview = true;
1337 $pageSelectObject->init(false);
1338 $targetPage = $pageSelectObject->getWorkspaceVersionOfRecord($this->whichWorkspace(), 'pages', $page['uid']);
1339 $result = $targetPage === -1 || $targetPage === -2;
1340 } else {
1341 $result = is_array($page) && ($page['hidden'] || $page['starttime'] > $GLOBALS['SIM_EXEC_TIME'] || $page['endtime'] != 0 && $page['endtime'] <= $GLOBALS['SIM_EXEC_TIME']);
1342 }
1343 return $result;
1344 }
1345
1346 /**
1347 * Get The Page ID
1348 * This gets the id of the page, checks if the page is in the domain and if the page is accessible
1349 * Sets variables such as $this->sys_page, $this->loginUser, $this->gr_list, $this->id, $this->type, $this->domainStartPage
1350 *
1351 * @throws ServiceUnavailableException
1352 * @return void
1353 * @access private
1354 */
1355 public function fetch_the_id()
1356 {
1357 $timeTracker = $this->getTimeTracker();
1358 $timeTracker->push('fetch_the_id initialize/', '');
1359 // Initialize the page-select functions.
1360 $this->sys_page = GeneralUtility::makeInstance(PageRepository::class);
1361 $this->sys_page->versioningPreview = $this->fePreview === 2 || (int)$this->workspacePreview || (bool)GeneralUtility::_GP('ADMCMD_view');
1362 $this->sys_page->versioningWorkspaceId = $this->whichWorkspace();
1363 $this->sys_page->init($this->showHiddenPage);
1364 // Set the valid usergroups for FE
1365 $this->initUserGroups();
1366 // Sets sys_page where-clause
1367 $this->setSysPageWhereClause();
1368 // Splitting $this->id by a period (.).
1369 // First part is 'id' and second part (if exists) will overrule the &type param
1370 $idParts = explode('.', $this->id, 2);
1371 $this->id = $idParts[0];
1372 if (isset($idParts[1])) {
1373 $this->type = $idParts[1];
1374 }
1375
1376 // If $this->id is a string, it's an alias
1377 $this->checkAndSetAlias();
1378 // The id and type is set to the integer-value - just to be sure...
1379 $this->id = (int)$this->id;
1380 $this->type = (int)$this->type;
1381 $timeTracker->pull();
1382 // We find the first page belonging to the current domain
1383 $timeTracker->push('fetch_the_id domain/', '');
1384 // The page_id of the current domain
1385 $this->domainStartPage = $this->findDomainRecord($GLOBALS['TYPO3_CONF_VARS']['SYS']['recursiveDomainSearch']);
1386 if (!$this->id) {
1387 if ($this->domainStartPage) {
1388 // If the id was not previously set, set it to the id of the domain.
1389 $this->id = $this->domainStartPage;
1390 } else {
1391 // Find the first 'visible' page in that domain
1392 $theFirstPage = $this->sys_page->getFirstWebPage($this->id);
1393 if ($theFirstPage) {
1394 $this->id = $theFirstPage['uid'];
1395 } else {
1396 $message = 'No pages are found on the rootlevel!';
1397 if ($this->checkPageUnavailableHandler()) {
1398 $this->pageUnavailableAndExit($message);
1399 } else {
1400 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
1401 throw new ServiceUnavailableException($message, 1301648975);
1402 }
1403 }
1404 }
1405 }
1406 $timeTracker->pull();
1407 $timeTracker->push('fetch_the_id rootLine/', '');
1408 // We store the originally requested id
1409 $this->requestedId = $this->id;
1410 $this->getPageAndRootlineWithDomain($this->domainStartPage);
1411 $timeTracker->pull();
1412 if ($this->pageNotFound && $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling']) {
1413 $pNotFoundMsg = array(
1414 1 => 'ID was not an accessible page',
1415 2 => 'Subsection was found and not accessible',
1416 3 => 'ID was outside the domain',
1417 4 => 'The requested page alias does not exist'
1418 );
1419 $this->pageNotFoundAndExit($pNotFoundMsg[$this->pageNotFound]);
1420 }
1421 if ($this->page['url_scheme'] > 0) {
1422 $newUrl = '';
1423 $requestUrlScheme = parse_url(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), PHP_URL_SCHEME);
1424 if ((int)$this->page['url_scheme'] === HttpUtility::SCHEME_HTTP && $requestUrlScheme == 'https') {
1425 $newUrl = 'http://' . substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 8);
1426 } elseif ((int)$this->page['url_scheme'] === HttpUtility::SCHEME_HTTPS && $requestUrlScheme == 'http') {
1427 $newUrl = 'https://' . substr(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 7);
1428 }
1429 if ($newUrl !== '') {
1430 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
1431 $headerCode = HttpUtility::HTTP_STATUS_303;
1432 } else {
1433 $headerCode = HttpUtility::HTTP_STATUS_301;
1434 }
1435 HttpUtility::redirect($newUrl, $headerCode);
1436 }
1437 }
1438 // Set no_cache if set
1439 if ($this->page['no_cache']) {
1440 $this->set_no_cache('no_cache is set in page properties');
1441 }
1442 // Init SYS_LASTCHANGED
1443 $this->register['SYS_LASTCHANGED'] = (int)$this->page['tstamp'];
1444 if ($this->register['SYS_LASTCHANGED'] < (int)$this->page['SYS_LASTCHANGED']) {
1445 $this->register['SYS_LASTCHANGED'] = (int)$this->page['SYS_LASTCHANGED'];
1446 }
1447 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['fetchPageId-PostProcessing'])) {
1448 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['fetchPageId-PostProcessing'] as $functionReference) {
1449 $parameters = array('parentObject' => $this);
1450 GeneralUtility::callUserFunction($functionReference, $parameters, $this);
1451 }
1452 }
1453 }
1454
1455 /**
1456 * Gets the page and rootline arrays based on the id, $this->id
1457 *
1458 * If the id does not correspond to a proper page, the 'previous' valid page in the rootline is found
1459 * If the page is a shortcut (doktype=4), the ->id is loaded with that id
1460 *
1461 * Whether or not the ->id is changed to the shortcut id or the previous id in rootline (eg if a page is hidden), the ->page-array and ->rootline is found and must also be valid.
1462 *
1463 * Sets or manipulates internal variables such as: $this->id, $this->page, $this->rootLine, $this->MP, $this->pageNotFound
1464 *
1465 * @throws ServiceUnavailableException
1466 * @throws PageNotFoundException
1467 * @return void
1468 * @access private
1469 */
1470 public function getPageAndRootline()
1471 {
1472 $this->page = $this->sys_page->getPage($this->id);
1473 if (empty($this->page)) {
1474 // If no page, we try to find the page before in the rootLine.
1475 // Page is 'not found' in case the id itself was not an accessible page. code 1
1476 $this->pageNotFound = 1;
1477 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1478 if (!empty($this->rootLine)) {
1479 $c = count($this->rootLine) - 1;
1480 while ($c > 0) {
1481 // Add to page access failure history:
1482 $this->pageAccessFailureHistory['direct_access'][] = $this->rootLine[$c];
1483 // Decrease to next page in rootline and check the access to that, if OK, set as page record and ID value.
1484 $c--;
1485 $this->id = $this->rootLine[$c]['uid'];
1486 $this->page = $this->sys_page->getPage($this->id);
1487 if (!empty($this->page)) {
1488 break;
1489 }
1490 }
1491 }
1492 // If still no page...
1493 if (empty($this->page)) {
1494 $message = 'The requested page does not exist!';
1495 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling']) {
1496 $this->pageNotFoundAndExit($message);
1497 } else {
1498 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
1499 throw new PageNotFoundException($message, 1301648780);
1500 }
1501 }
1502 }
1503 // Spacer is not accessible in frontend
1504 if ($this->page['doktype'] == PageRepository::DOKTYPE_SPACER) {
1505 $message = 'The requested page does not exist!';
1506 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling']) {
1507 $this->pageNotFoundAndExit($message);
1508 } else {
1509 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
1510 throw new PageNotFoundException($message, 1301648781);
1511 }
1512 }
1513 // Is the ID a link to another page??
1514 if ($this->page['doktype'] == PageRepository::DOKTYPE_SHORTCUT) {
1515 // We need to clear MP if the page is a shortcut. Reason is if the short cut goes to another page, then we LEAVE the rootline which the MP expects.
1516 $this->MP = '';
1517 // saving the page so that we can check later - when we know
1518 // about languages - whether we took the correct shortcut or
1519 // whether a translation of the page overwrites the shortcut
1520 // target and we need to follow the new target
1521 $this->originalShortcutPage = $this->page;
1522 $this->page = $this->getPageShortcut($this->page['shortcut'], $this->page['shortcut_mode'], $this->page['uid']);
1523 $this->id = $this->page['uid'];
1524 }
1525 // If the page is a mountpoint which should be overlaid with the contents of the mounted page,
1526 // it must never be accessible directly, but only in the mountpoint context. Therefore we change
1527 // the current ID and the user is redirected by checkPageForMountpointRedirect().
1528 if ($this->page['doktype'] == PageRepository::DOKTYPE_MOUNTPOINT && $this->page['mount_pid_ol']) {
1529 $this->originalMountPointPage = $this->page;
1530 $this->page = $this->sys_page->getPage($this->page['mount_pid']);
1531 if (empty($this->page)) {
1532 $message = 'This page (ID ' . $this->originalMountPointPage['uid'] . ') is of type "Mount point" and '
1533 . 'mounts a page which is not accessible (ID ' . $this->originalMountPointPage['mount_pid'] . ').';
1534 throw new PageNotFoundException($message, 1402043263);
1535 }
1536 $this->MP = $this->page['uid'] . '-' . $this->originalMountPointPage['uid'];
1537 $this->id = $this->page['uid'];
1538 }
1539 // Gets the rootLine
1540 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1541 // If not rootline we're off...
1542 if (empty($this->rootLine)) {
1543 $ws = $this->whichWorkspace();
1544 if ($this->sys_page->error_getRootLine_failPid == -1 && $ws) {
1545 $this->sys_page->versioningPreview = true;
1546 $this->sys_page->versioningWorkspaceId = $ws;
1547 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1548 }
1549 if (empty($this->rootLine)) {
1550 $message = 'The requested page didn\'t have a proper connection to the tree-root!';
1551 if ($this->checkPageUnavailableHandler()) {
1552 $this->pageUnavailableAndExit($message);
1553 } else {
1554 $rootline = '(' . $this->sys_page->error_getRootLine . ')';
1555 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
1556 throw new ServiceUnavailableException($message . '<br /><br />' . $rootline, 1301648167);
1557 }
1558 }
1559 $this->fePreview = 1;
1560 }
1561 // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
1562 if ($this->checkRootlineForIncludeSection()) {
1563 if (empty($this->rootLine)) {
1564 $message = 'The requested page was not accessible!';
1565 if ($this->checkPageUnavailableHandler()) {
1566 $this->pageUnavailableAndExit($message);
1567 } else {
1568 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
1569 throw new ServiceUnavailableException($message, 1301648234);
1570 }
1571 } else {
1572 $el = reset($this->rootLine);
1573 $this->id = $el['uid'];
1574 $this->page = $this->sys_page->getPage($this->id);
1575 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1576 }
1577 }
1578 }
1579
1580 /**
1581 * Get page shortcut; Finds the records pointed to by input value $SC (the shortcut value)
1582 *
1583 * @param int $SC The value of the "shortcut" field from the pages record
1584 * @param int $mode The shortcut mode: 1 will select first subpage, 2 a random subpage, 3 the parent page; default is the page pointed to by $SC
1585 * @param int $thisUid The current page UID of the page which is a shortcut
1586 * @param int $itera Safety feature which makes sure that the function is calling itself recursively max 20 times (since this function can find shortcuts to other shortcuts to other shortcuts...)
1587 * @param array $pageLog An array filled with previous page uids tested by the function - new page uids are evaluated against this to avoid going in circles.
1588 * @param bool $disableGroupCheck If true, the group check is disabled when fetching the target page (needed e.g. for menu generation)
1589 * @throws \RuntimeException
1590 * @throws PageNotFoundException
1591 * @return mixed Returns the page record of the page that the shortcut pointed to.
1592 * @access private
1593 * @see getPageAndRootline()
1594 */
1595 public function getPageShortcut($SC, $mode, $thisUid, $itera = 20, $pageLog = array(), $disableGroupCheck = false)
1596 {
1597 $idArray = GeneralUtility::intExplode(',', $SC);
1598 // Find $page record depending on shortcut mode:
1599 switch ($mode) {
1600 case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
1601
1602 case PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE:
1603 $pageArray = $this->sys_page->getMenu($idArray[0] ? $idArray[0] : $thisUid, '*', 'sorting', 'AND pages.doktype<199 AND pages.doktype!=' . PageRepository::DOKTYPE_BE_USER_SECTION);
1604 $pO = 0;
1605 if ($mode == PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE && !empty($pageArray)) {
1606 $randval = (int)rand(0, count($pageArray) - 1);
1607 $pO = $randval;
1608 }
1609 $c = 0;
1610 $page = array();
1611 foreach ($pageArray as $pV) {
1612 if ($c == $pO) {
1613 $page = $pV;
1614 break;
1615 }
1616 $c++;
1617 }
1618 if (empty($page)) {
1619 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a subpage. ' . 'However, this page has no accessible subpages.';
1620 throw new PageNotFoundException($message, 1301648328);
1621 }
1622 break;
1623 case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
1624 $parent = $this->sys_page->getPage($idArray[0] ? $idArray[0] : $thisUid, $disableGroupCheck);
1625 $page = $this->sys_page->getPage($parent['pid'], $disableGroupCheck);
1626 if (empty($page)) {
1627 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to its parent page. ' . 'However, the parent page is not accessible.';
1628 throw new PageNotFoundException($message, 1301648358);
1629 }
1630 break;
1631 default:
1632 $page = $this->sys_page->getPage($idArray[0], $disableGroupCheck);
1633 if (empty($page)) {
1634 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a page, which is not accessible (ID ' . $idArray[0] . ').';
1635 throw new PageNotFoundException($message, 1301648404);
1636 }
1637 }
1638 // Check if short cut page was a shortcut itself, if so look up recursively:
1639 if ($page['doktype'] == PageRepository::DOKTYPE_SHORTCUT) {
1640 if (!in_array($page['uid'], $pageLog) && $itera > 0) {
1641 $pageLog[] = $page['uid'];
1642 $page = $this->getPageShortcut($page['shortcut'], $page['shortcut_mode'], $page['uid'], $itera - 1, $pageLog, $disableGroupCheck);
1643 } else {
1644 $pageLog[] = $page['uid'];
1645 $message = 'Page shortcuts were looping in uids ' . implode(',', $pageLog) . '...!';
1646 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
1647 throw new \RuntimeException($message, 1294587212);
1648 }
1649 }
1650 // Return resulting page:
1651 return $page;
1652 }
1653
1654 /**
1655 * Checks the current rootline for defined sections.
1656 *
1657 * @return bool
1658 * @access private
1659 */
1660 public function checkRootlineForIncludeSection()
1661 {
1662 $c = count($this->rootLine);
1663 $removeTheRestFlag = 0;
1664 for ($a = 0; $a < $c; $a++) {
1665 if (!$this->checkPagerecordForIncludeSection($this->rootLine[$a])) {
1666 // Add to page access failure history:
1667 $this->pageAccessFailureHistory['sub_section'][] = $this->rootLine[$a];
1668 $removeTheRestFlag = 1;
1669 }
1670 if ($this->rootLine[$a]['doktype'] == PageRepository::DOKTYPE_BE_USER_SECTION) {
1671 // If there is a backend user logged in, check if he has read access to the page:
1672 if ($this->beUserLogin) {
1673 $row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid', 'pages', 'uid=' . (int)$this->id . ' AND ' . $this->getBackendUser()->getPagePermsClause(1));
1674 // versionOL()?
1675 if (!$row) {
1676 // If there was no page selected, the user apparently did not have read access to the current PAGE (not position in rootline) and we set the remove-flag...
1677 $removeTheRestFlag = 1;
1678 }
1679 } else {
1680 // Dont go here, if there is no backend user logged in.
1681 $removeTheRestFlag = 1;
1682 }
1683 }
1684 if ($removeTheRestFlag) {
1685 // Page is 'not found' in case a subsection was found and not accessible, code 2
1686 $this->pageNotFound = 2;
1687 unset($this->rootLine[$a]);
1688 }
1689 }
1690 return $removeTheRestFlag;
1691 }
1692
1693 /**
1694 * Checks page record for enableFields
1695 * Returns TRUE if enableFields does not disable the page record.
1696 * Takes notice of the ->showHiddenPage flag and uses SIM_ACCESS_TIME for start/endtime evaluation
1697 *
1698 * @param array $row The page record to evaluate (needs fields: hidden, starttime, endtime, fe_group)
1699 * @param bool $bypassGroupCheck Bypass group-check
1700 * @return bool TRUE, if record is viewable.
1701 * @see TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer::getTreeList(), checkPagerecordForIncludeSection()
1702 */
1703 public function checkEnableFields($row, $bypassGroupCheck = false)
1704 {
1705 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_checkEnableFields']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_checkEnableFields'])) {
1706 $_params = array('pObj' => $this, 'row' => &$row, 'bypassGroupCheck' => &$bypassGroupCheck);
1707 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_checkEnableFields'] as $_funcRef) {
1708 // Call hooks: If one returns FALSE, method execution is aborted with result "This record is not available"
1709 $return = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1710 if ($return === false) {
1711 return false;
1712 }
1713 }
1714 }
1715 if ((!$row['hidden'] || $this->showHiddenPage) && $row['starttime'] <= $GLOBALS['SIM_ACCESS_TIME'] && ($row['endtime'] == 0 || $row['endtime'] > $GLOBALS['SIM_ACCESS_TIME']) && ($bypassGroupCheck || $this->checkPageGroupAccess($row))) {
1716 return true;
1717 }
1718 return false;
1719 }
1720
1721 /**
1722 * Check group access against a page record
1723 *
1724 * @param array $row The page record to evaluate (needs field: fe_group)
1725 * @param mixed $groupList List of group id's (comma list or array). Default is $this->gr_list
1726 * @return bool TRUE, if group access is granted.
1727 * @access private
1728 */
1729 public function checkPageGroupAccess($row, $groupList = null)
1730 {
1731 if (is_null($groupList)) {
1732 $groupList = $this->gr_list;
1733 }
1734 if (!is_array($groupList)) {
1735 $groupList = explode(',', $groupList);
1736 }
1737 $pageGroupList = explode(',', $row['fe_group'] ?: 0);
1738 return count(array_intersect($groupList, $pageGroupList)) > 0;
1739 }
1740
1741 /**
1742 * Checks page record for include section
1743 *
1744 * @param array $row The page record to evaluate (needs fields: extendToSubpages + hidden, starttime, endtime, fe_group)
1745 * @return bool Returns TRUE if either extendToSubpages is not checked or if the enableFields does not disable the page record.
1746 * @access private
1747 * @see checkEnableFields(), TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer::getTreeList(), checkRootlineForIncludeSection()
1748 */
1749 public function checkPagerecordForIncludeSection($row)
1750 {
1751 return !$row['extendToSubpages'] || $this->checkEnableFields($row) ? 1 : 0;
1752 }
1753
1754 /**
1755 * Checks if logins are allowed in the current branch of the page tree. Traverses the full root line and returns TRUE if logins are OK, otherwise FALSE (and then the login user must be unset!)
1756 *
1757 * @return bool returns TRUE if logins are OK, otherwise FALSE (and then the login user must be unset!)
1758 */
1759 public function checkIfLoginAllowedInBranch()
1760 {
1761 // Initialize:
1762 $c = count($this->rootLine);
1763 $loginAllowed = true;
1764 // Traverse root line from root and outwards:
1765 for ($a = 0; $a < $c; $a++) {
1766 // If a value is set for login state:
1767 if ($this->rootLine[$a]['fe_login_mode'] > 0) {
1768 // Determine state from value:
1769 if ((int)$this->rootLine[$a]['fe_login_mode'] === 1) {
1770 $loginAllowed = false;
1771 $this->loginAllowedInBranch_mode = 'all';
1772 } elseif ((int)$this->rootLine[$a]['fe_login_mode'] === 3) {
1773 $loginAllowed = false;
1774 $this->loginAllowedInBranch_mode = 'groups';
1775 } else {
1776 $loginAllowed = true;
1777 }
1778 }
1779 }
1780 return $loginAllowed;
1781 }
1782
1783 /**
1784 * Analysing $this->pageAccessFailureHistory into a summary array telling which features disabled display and on which pages and conditions. That data can be used inside a page-not-found handler
1785 *
1786 * @return array Summary of why page access was not allowed.
1787 */
1788 public function getPageAccessFailureReasons()
1789 {
1790 $output = array();
1791 $combinedRecords = array_merge(is_array($this->pageAccessFailureHistory['direct_access']) ? $this->pageAccessFailureHistory['direct_access'] : array(array('fe_group' => 0)), is_array($this->pageAccessFailureHistory['sub_section']) ? $this->pageAccessFailureHistory['sub_section'] : array());
1792 if (!empty($combinedRecords)) {
1793 foreach ($combinedRecords as $k => $pagerec) {
1794 // If $k=0 then it is the very first page the original ID was pointing at and that will get a full check of course
1795 // If $k>0 it is parent pages being tested. They are only significant for the access to the first page IF they had the extendToSubpages flag set, hence checked only then!
1796 if (!$k || $pagerec['extendToSubpages']) {
1797 if ($pagerec['hidden']) {
1798 $output['hidden'][$pagerec['uid']] = true;
1799 }
1800 if ($pagerec['starttime'] > $GLOBALS['SIM_ACCESS_TIME']) {
1801 $output['starttime'][$pagerec['uid']] = $pagerec['starttime'];
1802 }
1803 if ($pagerec['endtime'] != 0 && $pagerec['endtime'] <= $GLOBALS['SIM_ACCESS_TIME']) {
1804 $output['endtime'][$pagerec['uid']] = $pagerec['endtime'];
1805 }
1806 if (!$this->checkPageGroupAccess($pagerec)) {
1807 $output['fe_group'][$pagerec['uid']] = $pagerec['fe_group'];
1808 }
1809 }
1810 }
1811 }
1812 return $output;
1813 }
1814
1815 /**
1816 * Gets ->page and ->rootline information based on ->id. ->id may change during this operation.
1817 * If not inside domain, then default to first page in domain.
1818 *
1819 * @param int $domainStartPage Page uid of the page where the found domain record is (pid of the domain record)
1820 * @return void
1821 * @access private
1822 */
1823 public function getPageAndRootlineWithDomain($domainStartPage)
1824 {
1825 $this->getPageAndRootline();
1826 // Checks if the $domain-startpage is in the rootLine. This is necessary so that references to page-id's from other domains are not possible.
1827 if ($domainStartPage && is_array($this->rootLine)) {
1828 $idFound = 0;
1829 foreach ($this->rootLine as $key => $val) {
1830 if ($val['uid'] == $domainStartPage) {
1831 $idFound = 1;
1832 break;
1833 }
1834 }
1835 if (!$idFound) {
1836 // Page is 'not found' in case the id was outside the domain, code 3
1837 $this->pageNotFound = 3;
1838 $this->id = $domainStartPage;
1839 // re-get the page and rootline if the id was not found.
1840 $this->getPageAndRootline();
1841 }
1842 }
1843 }
1844
1845 /**
1846 * Sets sys_page where-clause
1847 *
1848 * @return void
1849 * @access private
1850 */
1851 public function setSysPageWhereClause()
1852 {
1853 $this->sys_page->where_hid_del .= ' AND pages.doktype<200';
1854 $this->sys_page->where_groupAccess = $this->sys_page->getMultipleGroupsWhereClause('pages.fe_group', 'pages');
1855 }
1856
1857 /**
1858 * Looking up a domain record based on HTTP_HOST
1859 *
1860 * @param bool $recursive If set, it looks "recursively" meaning that a domain like "123.456.typo3.com" would find a domain record like "typo3.com" if "123.456.typo3.com" or "456.typo3.com" did not exist.
1861 * @return int Returns the page id of the page where the domain record was found.
1862 * @access private
1863 */
1864 public function findDomainRecord($recursive = false)
1865 {
1866 if ($recursive) {
1867 $pageUid = 0;
1868 $host = explode('.', GeneralUtility::getIndpEnv('HTTP_HOST'));
1869 while (count($host)) {
1870 $pageUid = $this->sys_page->getDomainStartPage(implode('.', $host), GeneralUtility::getIndpEnv('SCRIPT_NAME'), GeneralUtility::getIndpEnv('REQUEST_URI'));
1871 if ($pageUid) {
1872 return $pageUid;
1873 } else {
1874 array_shift($host);
1875 }
1876 }
1877 return $pageUid;
1878 } else {
1879 return $this->sys_page->getDomainStartPage(GeneralUtility::getIndpEnv('HTTP_HOST'), GeneralUtility::getIndpEnv('SCRIPT_NAME'), GeneralUtility::getIndpEnv('REQUEST_URI'));
1880 }
1881 }
1882
1883 /**
1884 * Page unavailable handler for use in frontend plugins from extensions.
1885 *
1886 * @param string $reason Reason text
1887 * @param string $header HTTP header to send
1888 * @return void Function exits.
1889 */
1890 public function pageUnavailableAndExit($reason = '', $header = '')
1891 {
1892 $header = $header ?: $GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling_statheader'];
1893 $this->pageUnavailableHandler($GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling'], $header, $reason);
1894 die;
1895 }
1896
1897 /**
1898 * Page-not-found handler for use in frontend plugins from extensions.
1899 *
1900 * @param string $reason Reason text
1901 * @param string $header HTTP header to send
1902 * @return void Function exits.
1903 */
1904 public function pageNotFoundAndExit($reason = '', $header = '')
1905 {
1906 $header = $header ?: $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_statheader'];
1907 $this->pageNotFoundHandler($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], $header, $reason);
1908 die;
1909 }
1910
1911 /**
1912 * Checks whether the pageUnavailableHandler should be used. To be used, pageUnavailable_handling must be set
1913 * and devIPMask must not match the current visitor's IP address.
1914 *
1915 * @return bool TRUE/FALSE whether the pageUnavailable_handler should be used.
1916 */
1917 public function checkPageUnavailableHandler()
1918 {
1919 if (
1920 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_handling']
1921 && !GeneralUtility::cmpIP(
1922 GeneralUtility::getIndpEnv('REMOTE_ADDR'),
1923 $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']
1924 )
1925 ) {
1926 $checkPageUnavailableHandler = true;
1927 } else {
1928 $checkPageUnavailableHandler = false;
1929 }
1930 return $checkPageUnavailableHandler;
1931 }
1932
1933 /**
1934 * Page unavailable handler. Acts a wrapper for the pageErrorHandler method.
1935 *
1936 * @param mixed $code Which type of handling; If a true PHP-boolean or TRUE then a \TYPO3\CMS\Core\Messaging\ErrorpageMessage is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1937 * @param string $header If set, this is passed directly to the PHP function, header()
1938 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1939 * @return void (The function exits!)
1940 */
1941 public function pageUnavailableHandler($code, $header, $reason)
1942 {
1943 $this->pageErrorHandler($code, $header, $reason);
1944 }
1945
1946 /**
1947 * Page not found handler. Acts a wrapper for the pageErrorHandler method.
1948 *
1949 * @param mixed $code Which type of handling; If a true PHP-boolean or TRUE then a \TYPO3\CMS\Core\Messaging\ErrorpageMessage is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1950 * @param string $header If set, this is passed directly to the PHP function, header()
1951 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1952 * @return void (The function exits!)
1953 */
1954 public function pageNotFoundHandler($code, $header = '', $reason = '')
1955 {
1956 $this->pageErrorHandler($code, $header, $reason);
1957 }
1958
1959 /**
1960 * Generic error page handler.
1961 * Exits.
1962 *
1963 * @param mixed $code Which type of handling; If a true PHP-boolean or TRUE then a \TYPO3\CMS\Core\Messaging\ErrorpageMessage is outputted. If integer an error message with that number is shown. Otherwise the $code value is expected to be a "Location:" header value.
1964 * @param string $header If set, this is passed directly to the PHP function, header()
1965 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1966 * @throws \RuntimeException
1967 * @return void (The function exits!)
1968 */
1969 public function pageErrorHandler($code, $header = '', $reason = '')
1970 {
1971 // Issue header in any case:
1972 if ($header) {
1973 $headerArr = preg_split('/\\r|\\n/', $header, -1, PREG_SPLIT_NO_EMPTY);
1974 foreach ($headerArr as $header) {
1975 header($header);
1976 }
1977 }
1978 // Create response:
1979 // Simply boolean; Just shows TYPO3 error page with reason:
1980 if (strtolower($code) === 'true' || (string)$code === '1' || gettype($code) === 'boolean') {
1981 $title = 'Page Not Found';
1982 $message = 'The page did not exist or was inaccessible.' . ($reason ? ' Reason: ' . htmlspecialchars($reason) : '');
1983 $messagePage = GeneralUtility::makeInstance(ErrorpageMessage::class, $message, $title);
1984 $messagePage->output();
1985 die;
1986 } elseif (GeneralUtility::isFirstPartOfStr($code, 'USER_FUNCTION:')) {
1987 $funcRef = trim(substr($code, 14));
1988 $params = array(
1989 'currentUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'),
1990 'reasonText' => $reason,
1991 'pageAccessFailureReasons' => $this->getPageAccessFailureReasons()
1992 );
1993 echo GeneralUtility::callUserFunction($funcRef, $params, $this);
1994 } elseif (GeneralUtility::isFirstPartOfStr($code, 'READFILE:')) {
1995 $readFile = GeneralUtility::getFileAbsFileName(trim(substr($code, 9)));
1996 if (@is_file($readFile)) {
1997 echo str_replace(
1998 array(
1999 '###CURRENT_URL###',
2000 '###REASON###'
2001 ),
2002 array(
2003 GeneralUtility::getIndpEnv('REQUEST_URI'),
2004 htmlspecialchars($reason)
2005 ),
2006 file_get_contents($readFile)
2007 );
2008 } else {
2009 throw new \RuntimeException('Configuration Error: 404 page "' . $readFile . '" could not be found.', 1294587214);
2010 }
2011 } elseif (GeneralUtility::isFirstPartOfStr($code, 'REDIRECT:')) {
2012 HttpUtility::redirect(substr($code, 9));
2013 } elseif ($code !== '') {
2014 // Check if URL is relative
2015 $url_parts = parse_url($code);
2016 if ($url_parts['host'] == '') {
2017 $url_parts['host'] = GeneralUtility::getIndpEnv('HTTP_HOST');
2018 if ($code[0] === '/') {
2019 $code = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . $code;
2020 } else {
2021 $code = GeneralUtility::getIndpEnv('TYPO3_REQUEST_DIR') . $code;
2022 }
2023 $checkBaseTag = false;
2024 } else {
2025 $checkBaseTag = true;
2026 }
2027 // Check recursion
2028 if ($code == GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')) {
2029 if ($reason == '') {
2030 $reason = 'Page cannot be found.';
2031 }
2032 $reason .= LF . LF . 'Additionally, ' . $code . ' was not found while trying to retrieve the error document.';
2033 throw new \RuntimeException(nl2br(htmlspecialchars($reason)), 1294587215);
2034 }
2035 // Prepare headers
2036 $headerArr = array(
2037 'User-agent: ' . GeneralUtility::getIndpEnv('HTTP_USER_AGENT'),
2038 'Referer: ' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')
2039 );
2040 $res = GeneralUtility::getUrl($code, 1, $headerArr);
2041 // Header and content are separated by an empty line
2042 list($header, $content) = explode(CRLF . CRLF, $res, 2);
2043 $content .= CRLF;
2044 if (false === $res) {
2045 // Last chance -- redirect
2046 HttpUtility::redirect($code);
2047 } else {
2048 // Forward these response headers to the client
2049 $forwardHeaders = array(
2050 'Content-Type:'
2051 );
2052 $headerArr = preg_split('/\\r|\\n/', $header, -1, PREG_SPLIT_NO_EMPTY);
2053 foreach ($headerArr as $header) {
2054 foreach ($forwardHeaders as $h) {
2055 if (preg_match('/^' . $h . '/', $header)) {
2056 header($header);
2057 }
2058 }
2059 }
2060 // Put <base> if necesary
2061 if ($checkBaseTag) {
2062 // If content already has <base> tag, we do not need to do anything
2063 if (false === stristr($content, '<base ')) {
2064 // Generate href for base tag
2065 $base = $url_parts['scheme'] . '://';
2066 if ($url_parts['user'] != '') {
2067 $base .= $url_parts['user'];
2068 if ($url_parts['pass'] != '') {
2069 $base .= ':' . $url_parts['pass'];
2070 }
2071 $base .= '@';
2072 }
2073 $base .= $url_parts['host'];
2074 // Add path portion skipping possible file name
2075 $base .= preg_replace('/(.*\\/)[^\\/]*/', '${1}', $url_parts['path']);
2076 // Put it into content (generate also <head> if necessary)
2077 $replacement = LF . '<base href="' . htmlentities($base) . '" />' . LF;
2078 if (stristr($content, '<head>')) {
2079 $content = preg_replace('/(<head>)/i', '\\1' . $replacement, $content);
2080 } else {
2081 $content = preg_replace('/(<html[^>]*>)/i', '\\1<head>' . $replacement . '</head>', $content);
2082 }
2083 }
2084 }
2085 // Output the content
2086 echo $content;
2087 }
2088 } else {
2089 $title = 'Page Not Found';
2090 $message = $reason ? 'Reason: ' . htmlspecialchars($reason) : 'Page cannot be found.';
2091 $messagePage = GeneralUtility::makeInstance(ErrorpageMessage::class, $message, $title);
2092 $messagePage->output();
2093 }
2094 die;
2095 }
2096
2097 /**
2098 * Fetches the integer page id for a page alias.
2099 * Looks if ->id is not an integer and if so it will search for a page alias and if found the page uid of that page is stored in $this->id
2100 *
2101 * @return void
2102 * @access private
2103 */
2104 public function checkAndSetAlias()
2105 {
2106 if ($this->id && !MathUtility::canBeInterpretedAsInteger($this->id)) {
2107 $aid = $this->sys_page->getPageIdFromAlias($this->id);
2108 if ($aid) {
2109 $this->id = $aid;
2110 } else {
2111 $this->pageNotFound = 4;
2112 }
2113 }
2114 }
2115
2116 /**
2117 * Merging values into the global $_GET
2118 *
2119 * @param array $GET_VARS Array of key/value pairs that will be merged into the current GET-vars. (Non-escaped values)
2120 * @return void
2121 */
2122 public function mergingWithGetVars($GET_VARS)
2123 {
2124 if (is_array($GET_VARS)) {
2125 // Getting $_GET var, unescaped.
2126 $realGet = GeneralUtility::_GET();
2127 if (!is_array($realGet)) {
2128 $realGet = array();
2129 }
2130 // Merge new values on top:
2131 ArrayUtility::mergeRecursiveWithOverrule($realGet, $GET_VARS);
2132 // Write values back to $_GET:
2133 GeneralUtility::_GETset($realGet);
2134 // Setting these specifically (like in the init-function):
2135 if (isset($GET_VARS['type'])) {
2136 $this->type = (int)$GET_VARS['type'];
2137 }
2138 if (isset($GET_VARS['cHash'])) {
2139 $this->cHash = $GET_VARS['cHash'];
2140 }
2141 if (isset($GET_VARS['MP'])) {
2142 $this->MP = $GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'] ? $GET_VARS['MP'] : '';
2143 }
2144 if (isset($GET_VARS['no_cache']) && $GET_VARS['no_cache']) {
2145 $this->set_no_cache('no_cache is requested via GET parameter');
2146 }
2147 }
2148 }
2149
2150 /********************************************
2151 *
2152 * Template and caching related functions.
2153 *
2154 *******************************************/
2155 /**
2156 * Calculates a hash string based on additional parameters in the url.
2157 *
2158 * Calculated hash is stored in $this->cHash_array.
2159 * This is used to cache pages with more parameters than just id and type.
2160 *
2161 * @return void
2162 * @see reqCHash()
2163 */
2164 public function makeCacheHash()
2165 {
2166 // No need to test anything if caching was already disabled.
2167 if ($this->no_cache && !$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFoundOnCHashError']) {
2168 return;
2169 }
2170 $GET = GeneralUtility::_GET();
2171 if ($this->cHash && is_array($GET)) {
2172 $this->cHash_array = $this->cacheHash->getRelevantParameters(GeneralUtility::implodeArrayForUrl('', $GET));
2173 $cHash_calc = $this->cacheHash->calculateCacheHash($this->cHash_array);
2174 if ($cHash_calc != $this->cHash) {
2175 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFoundOnCHashError']) {
2176 $this->pageNotFoundAndExit('Request parameters could not be validated (&cHash comparison failed)');
2177 } else {
2178 $this->disableCache();
2179 $this->getTimeTracker()->setTSlogMessage('The incoming cHash "' . $this->cHash . '" and calculated cHash "' . $cHash_calc . '" did not match, so caching was disabled. The fieldlist used was "' . implode(',', array_keys($this->cHash_array)) . '"', 2);
2180 }
2181 }
2182 } elseif (is_array($GET)) {
2183 // No cHash is set, check if that is correct
2184 if ($this->cacheHash->doParametersRequireCacheHash(GeneralUtility::implodeArrayForUrl('', $GET))) {
2185 $this->reqCHash();
2186 }
2187 }
2188 }
2189
2190 /**
2191 * Will disable caching if the cHash value was not set.
2192 * This function should be called to check the _existence_ of "&cHash" whenever a plugin generating cacheable output is using extra GET variables. If there _is_ a cHash value the validation of it automatically takes place in makeCacheHash() (see above)
2193 *
2194 * @return void
2195 * @see makeCacheHash(), \TYPO3\CMS\Frontend\Plugin\AbstractPlugin::pi_cHashCheck()
2196 */
2197 public function reqCHash()
2198 {
2199 if (!$this->cHash) {
2200 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFoundOnCHashError']) {
2201 if ($this->tempContent) {
2202 $this->clearPageCacheContent();
2203 }
2204 $this->pageNotFoundAndExit('Request parameters could not be validated (&cHash empty)');
2205 } else {
2206 $this->disableCache();
2207 $this->getTimeTracker()->setTSlogMessage('TSFE->reqCHash(): No &cHash parameter was sent for GET vars though required so caching is disabled', 2);
2208 }
2209 }
2210 }
2211
2212 /**
2213 * Initialize the TypoScript template parser
2214 *
2215 * @return void
2216 */
2217 public function initTemplate()
2218 {
2219 $this->tmpl = GeneralUtility::makeInstance(TemplateService::class);
2220 $this->tmpl->setVerbose((bool)$this->beUserLogin);
2221 $this->tmpl->init();
2222 $this->tmpl->tt_track = (bool)$this->beUserLogin;
2223 }
2224
2225 /**
2226 * See if page is in cache and get it if so
2227 * Stores the page content in $this->content if something is found.
2228 *
2229 * @throws \InvalidArgumentException
2230 * @throws \RuntimeException
2231 */
2232 public function getFromCache()
2233 {
2234 // clearing the content-variable, which will hold the pagecontent
2235 $this->content = '';
2236 // Unsetting the lowlevel config
2237 unset($this->config);
2238 $this->cacheContentFlag = false;
2239
2240 if ($this->no_cache) {
2241 return;
2242 }
2243
2244 $pageSectionCacheContent = $this->tmpl->getCurrentPageData();
2245 if (!is_array($pageSectionCacheContent)) {
2246 // Nothing in the cache, we acquire an "exclusive lock" for the key now.
2247 // We use the Registry to store this lock centrally,
2248 // but we protect the access again with a global exclusive lock to avoid race conditions
2249
2250 $this->acquireLock('pagesection', $this->id . '::' . $this->MP);
2251 //
2252 // from this point on we're the only one working on that page ($key)
2253 //
2254
2255 // query the cache again to see if the page data are there meanwhile
2256 $pageSectionCacheContent = $this->tmpl->getCurrentPageData();
2257 if (is_array($pageSectionCacheContent)) {
2258 // we have the content, nice that some other process did the work for us already
2259 $this->releaseLock('pagesection');
2260 } else {
2261 // We keep the lock set, because we are the ones generating the page now
2262 // and filling the cache.
2263 // This indicates that we have to release the lock in the Registry later in releaseLocks()
2264 }
2265 }
2266
2267 if (is_array($pageSectionCacheContent)) {
2268 // BE CAREFUL to change the content of the cc-array. This array is serialized and an md5-hash based on this is used for caching the page.
2269 // If this hash is not the same in here in this section and after page-generation, then the page will not be properly cached!
2270 // 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.
2271 $pageSectionCacheContent = $this->tmpl->matching($pageSectionCacheContent);
2272 ksort($pageSectionCacheContent);
2273 $this->all = $pageSectionCacheContent;
2274 }
2275 unset($pageSectionCacheContent);
2276
2277 // Look for page in cache only if a shift-reload is not sent to the server.
2278 $lockHash = $this->getLockHash();
2279 if (!$this->headerNoCache()) {
2280 if ($this->all) {
2281 // we got page section information
2282 $this->newHash = $this->getHash();
2283 $this->getTimeTracker()->push('Cache Row', '');
2284 $row = $this->getFromCache_queryRow();
2285 if (!is_array($row)) {
2286 // nothing in the cache, we acquire an exclusive lock now
2287
2288 $this->acquireLock('pages', $lockHash);
2289 //
2290 // from this point on we're the only one working on that page ($lockHash)
2291 //
2292
2293 // query the cache again to see if the data are there meanwhile
2294 $row = $this->getFromCache_queryRow();
2295 if (is_array($row)) {
2296 // we have the content, nice that some other process did the work for us
2297 $this->releaseLock('pages');
2298 } else {
2299 // We keep the lock set, because we are the ones generating the page now
2300 // and filling the cache.
2301 // This indicates that we have to release the lock in the Registry later in releaseLocks()
2302 }
2303 }
2304 if (is_array($row)) {
2305 // we have data from cache
2306
2307 // Call hook when a page is retrieved from cache:
2308 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'])) {
2309 $_params = array('pObj' => &$this, 'cache_pages_row' => &$row);
2310 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'] as $_funcRef) {
2311 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2312 }
2313 }
2314 // Fetches the lowlevel config stored with the cached data
2315 $this->config = $row['cache_data'];
2316 // Getting the content
2317 $this->content = $row['content'];
2318 // Flag for temp content
2319 $this->tempContent = $row['temp_content'];
2320 // Setting flag, so we know, that some cached content has been loaded
2321 $this->cacheContentFlag = true;
2322 $this->cacheExpires = $row['expires'];
2323
2324 // Restore page title information, this is needed to generate the page title for
2325 // partially cached pages.
2326 $this->page['title'] = $row['pageTitleInfo']['title'];
2327 $this->altPageTitle = $row['pageTitleInfo']['altPageTitle'];
2328 $this->indexedDocTitle = $row['pageTitleInfo']['indexedDocTitle'];
2329
2330 if (isset($this->config['config']['debug'])) {
2331 $debugCacheTime = (bool)$this->config['config']['debug'];
2332 } else {
2333 $debugCacheTime = !empty($GLOBALS['TYPO3_CONF_VARS']['FE']['debug']);
2334 }
2335 if ($debugCacheTime) {
2336 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
2337 $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
2338 $this->content .= LF . '<!-- Cached page generated ' . date(($dateFormat . ' ' . $timeFormat), $row['tstamp']) . '. Expires ' . date(($dateFormat . ' ' . $timeFormat), $row['expires']) . ' -->';
2339 }
2340 }
2341 $this->getTimeTracker()->pull();
2342
2343 return;
2344 }
2345 }
2346 // the user forced rebuilding the page cache or there was no pagesection information
2347 // get a lock for the page content so other processes will not interrupt the regeneration
2348 $this->acquireLock('pages', $lockHash);
2349 }
2350
2351 /**
2352 * Returning the cached version of page with hash = newHash
2353 *
2354 * @return array Cached row, if any. Otherwise void.
2355 */
2356 public function getFromCache_queryRow()
2357 {
2358 $this->getTimeTracker()->push('Cache Query', '');
2359 $row = $this->pageCache->get($this->newHash);
2360 $this->getTimeTracker()->pull();
2361 return $row;
2362 }
2363
2364 /**
2365 * Detecting if shift-reload has been clicked
2366 * Will not be called if re-generation of page happens by other reasons (for instance that the page is not in cache yet!)
2367 * Also, a backend user MUST be logged in for the shift-reload to be detected due to DoS-attack-security reasons.
2368 *
2369 * @return bool If shift-reload in client browser has been clicked, disable getting cached page (and regenerate it).
2370 */
2371 public function headerNoCache()
2372 {
2373 $disableAcquireCacheData = false;
2374 if ($this->beUserLogin) {
2375 if (strtolower($_SERVER['HTTP_CACHE_CONTROL']) === 'no-cache' || strtolower($_SERVER['HTTP_PRAGMA']) === 'no-cache') {
2376 $disableAcquireCacheData = true;
2377 }
2378 }
2379 // Call hook for possible by-pass of requiring of page cache (for recaching purpose)
2380 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['headerNoCache'])) {
2381 $_params = array('pObj' => &$this, 'disableAcquireCacheData' => &$disableAcquireCacheData);
2382 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['headerNoCache'] as $_funcRef) {
2383 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2384 }
2385 }
2386 return $disableAcquireCacheData;
2387 }
2388
2389 /**
2390 * Calculates the cache-hash
2391 * This hash is unique to the template, the variables ->id, ->type, ->gr_list (list of groups), ->MP (Mount Points) and cHash array
2392 * Used to get and later store the cached data.
2393 *
2394 * @return string MD5 hash of serialized hash base from createHashBase()
2395 * @access private
2396 * @see getFromCache(), getLockHash()
2397 */
2398 public function getHash()
2399 {
2400 return md5($this->createHashBase(false));
2401 }
2402
2403 /**
2404 * Calculates the lock-hash
2405 * This hash is unique to the above hash, except that it doesn't contain the template information in $this->all.
2406 *
2407 * @return string MD5 hash
2408 * @access private
2409 * @see getFromCache(), getHash()
2410 */
2411 public function getLockHash()
2412 {
2413 $lockHash = $this->createHashBase(true);
2414 return md5($lockHash);
2415 }
2416
2417 /**
2418 * Calculates the cache-hash (or the lock-hash)
2419 * This hash is unique to the template,
2420 * the variables ->id, ->type, ->gr_list (list of groups),
2421 * ->MP (Mount Points) and cHash array
2422 * Used to get and later store the cached data.
2423 *
2424 * @param bool $createLockHashBase Whether to create the lock hash, which doesn't contain the "this->all" (the template information)
2425 * @return string the serialized hash base
2426 */
2427 protected function createHashBase($createLockHashBase = false)
2428 {
2429 $hashParameters = array(
2430 'id' => (int)$this->id,
2431 'type' => (int)$this->type,
2432 'gr_list' => (string)$this->gr_list,
2433 'MP' => (string)$this->MP,
2434 'cHash' => $this->cHash_array,
2435 'domainStartPage' => $this->domainStartPage
2436 );
2437 // Include the template information if we shouldn't create a lock hash
2438 if (!$createLockHashBase) {
2439 $hashParameters['all'] = $this->all;
2440 }
2441 // Call hook to influence the hash calculation
2442 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'])) {
2443 $_params = array(
2444 'hashParameters' => &$hashParameters,
2445 'createLockHashBase' => $createLockHashBase
2446 );
2447 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'] as $_funcRef) {
2448 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2449 }
2450 }
2451 return serialize($hashParameters);
2452 }
2453
2454 /**
2455 * Checks if config-array exists already but if not, gets it
2456 *
2457 * @throws ServiceUnavailableException
2458 * @return void
2459 */
2460 public function getConfigArray()
2461 {
2462 // If config is not set by the cache (which would be a major mistake somewhere) OR if INTincScripts-include-scripts have been registered, then we must parse the template in order to get it
2463 if (!is_array($this->config) || is_array($this->config['INTincScript']) || $this->forceTemplateParsing) {
2464 $timeTracker = $this->getTimeTracker();
2465 $timeTracker->push('Parse template', '');
2466 // Force parsing, if set?:
2467 $this->tmpl->forceTemplateParsing = $this->forceTemplateParsing;
2468 // Start parsing the TS template. Might return cached version.
2469 $this->tmpl->start($this->rootLine);
2470 $timeTracker->pull();
2471 if ($this->tmpl->loaded) {
2472 $timeTracker->push('Setting the config-array', '');
2473 // toplevel - objArrayName
2474 $this->sPre = $this->tmpl->setup['types.'][$this->type];
2475 $this->pSetup = $this->tmpl->setup[$this->sPre . '.'];
2476 if (!is_array($this->pSetup)) {
2477 $message = 'The page is not configured! [type=' . $this->type . '][' . $this->sPre . '].';
2478 if ($this->checkPageUnavailableHandler()) {
2479 $this->pageUnavailableAndExit($message);
2480 } else {
2481 $explanation = 'This means that there is no TypoScript object of type PAGE with typeNum=' . $this->type . ' configured.';
2482 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
2483 throw new ServiceUnavailableException($message . ' ' . $explanation, 1294587217);
2484 }
2485 } else {
2486 if (!isset($this->config['config'])) {
2487 $this->config['config'] = array();
2488 }
2489 // Filling the config-array, first with the main "config." part
2490 if (is_array($this->tmpl->setup['config.'])) {
2491 ArrayUtility::mergeRecursiveWithOverrule($this->tmpl->setup['config.'], $this->config['config']);
2492 $this->config['config'] = $this->tmpl->setup['config.'];
2493 }
2494 // override it with the page/type-specific "config."
2495 if (is_array($this->pSetup['config.'])) {
2496 ArrayUtility::mergeRecursiveWithOverrule($this->config['config'], $this->pSetup['config.']);
2497 }
2498 if ($this->config['config']['typolinkEnableLinksAcrossDomains']) {
2499 $this->config['config']['typolinkCheckRootline'] = true;
2500 }
2501 // Set default values for removeDefaultJS and inlineStyle2TempFile so CSS and JS are externalized if compatversion is higher than 4.0
2502 if (!isset($this->config['config']['removeDefaultJS'])) {
2503 $this->config['config']['removeDefaultJS'] = 'external';
2504 }
2505 if (!isset($this->config['config']['inlineStyle2TempFile'])) {
2506 $this->config['config']['inlineStyle2TempFile'] = 1;
2507 }
2508
2509 if (!isset($this->config['config']['compressJs'])) {
2510 $this->config['config']['compressJs'] = 0;
2511 }
2512 // Processing for the config_array:
2513 $this->config['rootLine'] = $this->tmpl->rootLine;
2514 $this->config['mainScript'] = trim($this->config['config']['mainScript']) ?: 'index.php';
2515 // Class for render Header and Footer parts
2516 if ($this->pSetup['pageHeaderFooterTemplateFile']) {
2517 $file = $this->tmpl->getFileName($this->pSetup['pageHeaderFooterTemplateFile']);
2518 if ($file) {
2519 $this->pageRenderer->setTemplateFile($file);
2520 }
2521 }
2522 }
2523 $timeTracker->pull();
2524 } else {
2525 if ($this->checkPageUnavailableHandler()) {
2526 $this->pageUnavailableAndExit('No TypoScript template found!');
2527 } else {
2528 $message = 'No TypoScript template found!';
2529 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
2530 throw new ServiceUnavailableException($message, 1294587218);
2531 }
2532 }
2533 }
2534
2535 // No cache
2536 // Set $this->no_cache TRUE if the config.no_cache value is set!
2537 if ($this->config['config']['no_cache']) {
2538 $this->set_no_cache('config.no_cache is set');
2539 }
2540 // Merge GET with defaultGetVars
2541 if (!empty($this->config['config']['defaultGetVars.'])) {
2542 $modifiedGetVars = GeneralUtility::removeDotsFromTS($this->config['config']['defaultGetVars.']);
2543 ArrayUtility::mergeRecursiveWithOverrule($modifiedGetVars, GeneralUtility::_GET());
2544 GeneralUtility::_GETset($modifiedGetVars);
2545 }
2546 // Hook for postProcessing the configuration array
2547 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'])) {
2548 $params = array('config' => &$this->config['config']);
2549 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'] as $funcRef) {
2550 GeneralUtility::callUserFunction($funcRef, $params, $this);
2551 }
2552 }
2553 }
2554
2555 /********************************************
2556 *
2557 * Further initialization and data processing
2558 *
2559 *******************************************/
2560
2561 /**
2562 * Setting the language key that will be used by the current page.
2563 * In this function it should be checked, 1) that this language exists, 2) that a page_overlay_record exists, .. and if not the default language, 0 (zero), should be set.
2564 *
2565 * @return void
2566 * @access private
2567 */
2568 public function settingLanguage()
2569 {
2570 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess'])) {
2571 $_params = array();
2572 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess'] as $_funcRef) {
2573 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2574 }
2575 }
2576
2577 // Initialize charset settings etc.
2578 $this->initLLvars();
2579
2580 // Get values from TypoScript:
2581 $this->sys_language_uid = ($this->sys_language_content = (int)$this->config['config']['sys_language_uid']);
2582 list($this->sys_language_mode, $sys_language_content) = GeneralUtility::trimExplode(';', $this->config['config']['sys_language_mode']);
2583 $this->sys_language_contentOL = $this->config['config']['sys_language_overlay'];
2584 // If sys_language_uid is set to another language than default:
2585 if ($this->sys_language_uid > 0) {
2586 // check whether a shortcut is overwritten by a translated page
2587 // we can only do this now, as this is the place where we get
2588 // to know about translations
2589 $this->checkTranslatedShortcut();
2590 // Request the overlay record for the sys_language_uid:
2591 $olRec = $this->sys_page->getPageOverlay($this->id, $this->sys_language_uid);
2592 if (empty($olRec)) {
2593 // If no OL record exists and a foreign language is asked for...
2594 if ($this->sys_language_uid) {
2595 // If requested translation is not available:
2596 if (GeneralUtility::hideIfNotTranslated($this->page['l18n_cfg'])) {
2597 $this->pageNotFoundAndExit('Page is not available in the requested language.');
2598 } else {
2599 switch ((string)$this->sys_language_mode) {
2600 case 'strict':
2601 $this->pageNotFoundAndExit('Page is not available in the requested language (strict).');
2602 break;
2603 case 'content_fallback':
2604 $fallBackOrder = GeneralUtility::intExplode(',', $sys_language_content);
2605 foreach ($fallBackOrder as $orderValue) {
2606 if ((string)$orderValue === '0' || !empty($this->sys_page->getPageOverlay($this->id, $orderValue))) {
2607 $this->sys_language_content = $orderValue;
2608 // Setting content uid (but leaving the sys_language_uid)
2609 break;
2610 }
2611 }
2612 break;
2613 case 'ignore':
2614 $this->sys_language_content = $this->sys_language_uid;
2615 break;
2616 default:
2617 // Default is that everything defaults to the default language...
2618 $this->sys_language_uid = ($this->sys_language_content = 0);
2619 }
2620 }
2621 }
2622 } else {
2623 // Setting sys_language if an overlay record was found (which it is only if a language is used)
2624 $this->page = $this->sys_page->getPageOverlay($this->page, $this->sys_language_uid);
2625 }
2626 }
2627 // Setting sys_language_uid inside sys-page:
2628 $this->sys_page->sys_language_uid = $this->sys_language_uid;
2629 // If default translation is not available:
2630 if ((!$this->sys_language_uid || !$this->sys_language_content) && GeneralUtility::hideIfDefaultLanguage($this->page['l18n_cfg'])) {
2631 $message = 'Page is not available in default language.';
2632 GeneralUtility::sysLog($message, 'cms', GeneralUtility::SYSLOG_SEVERITY_ERROR);
2633 $this->pageNotFoundAndExit($message);
2634 }
2635 $this->updateRootLinesWithTranslations();
2636
2637 // Finding the ISO code for the currently selected language
2638 // fetched by the sys_language record when not fetching content from the default language
2639 if ($this->sys_language_content > 0) {
2640 // using sys_language_content because the ISO code only (currently) affect content selection from FlexForms - which should follow "sys_language_content"
2641 // Set the fourth parameter to TRUE in the next two getRawRecord() calls to
2642 // avoid versioning overlay to be applied as it generates an SQL error
2643 $sys_language_row = $this->sys_page->getRawRecord('sys_language', $this->sys_language_content, 'language_isocode,static_lang_isocode', true);
2644 if (is_array($sys_language_row) && !empty($sys_language_row['language_isocode'])) {
2645 $this->sys_language_isocode = $sys_language_row['language_isocode'];
2646 }
2647 // the DB value is overriden by TypoScript
2648 if (!empty($this->config['config']['sys_language_isocode'])) {
2649 $this->sys_language_isocode = $this->config['config']['sys_language_isocode'];
2650 }
2651 } else {
2652 // fallback to the TypoScript option when rendering with sys_language_uid=0
2653 // also: use "en" by default
2654 if (!empty($this->config['config']['sys_language_isocode_default'])) {
2655 $this->sys_language_isocode = $this->config['config']['sys_language_isocode_default'];
2656 } else {
2657 $this->sys_language_isocode = $this->lang != 'default' ? $this->lang : 'en';
2658 }
2659 }
2660
2661 // Setting softMergeIfNotBlank:
2662 $table_fields = GeneralUtility::trimExplode(',', $this->config['config']['sys_language_softMergeIfNotBlank'], true);
2663 foreach ($table_fields as $TF) {
2664 list($tN, $fN) = explode(':', $TF);
2665 $GLOBALS['TCA'][$tN]['columns'][$fN]['l10n_mode'] = 'mergeIfNotBlank';
2666 }
2667 // Setting softExclude:
2668 $table_fields = GeneralUtility::trimExplode(',', $this->config['config']['sys_language_softExclude'], true);
2669 foreach ($table_fields as $TF) {
2670 list($tN, $fN) = explode(':', $TF);
2671 $GLOBALS['TCA'][$tN]['columns'][$fN]['l10n_mode'] = 'exclude';
2672 }
2673 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess'])) {
2674 $_params = array();
2675 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess'] as $_funcRef) {
2676 GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2677 }
2678 }
2679 }
2680
2681 /**
2682 * Updating content of the two rootLines IF the language key is set!
2683 */
2684 protected function updateRootLinesWithTranslations()
2685 {
2686 if ($this->sys_language_uid) {
2687 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
2688 $this->tmpl->updateRootlineData($this->rootLine);
2689 }
2690 }
2691
2692 /**
2693 * Setting locale for frontend rendering
2694 *
2695 * @return void
2696 */
2697 public function settingLocale()
2698 {
2699 // Setting locale
2700 if ($this->config['config']['locale_all']) {
2701 $availableLocales = GeneralUtility::trimExplode(',', $this->config['config']['locale_all'], true);
2702 // If LC_NUMERIC is set e.g. to 'de_DE' PHP parses float values locale-aware resulting in strings with comma
2703 // as decimal point which causes problems with value conversions - so we set all locale types except LC_NUMERIC
2704 // @see https://bugs.php.net/bug.php?id=53711
2705 $locale = setlocale(LC_COLLATE, ...$availableLocales);
2706 if ($locale) {
2707 setlocale(LC_CTYPE, ...$availableLocales);
2708 setlocale(LC_MONETARY, ...$availableLocales);
2709 setlocale(LC_TIME, ...$availableLocales);
2710 } else {
2711 $this->getTimeTracker()->setTSlogMessage('Locale "' . htmlspecialchars($this->config['config']['locale_all']) . '" not found.', 3);
2712 }
2713 }
2714 }
2715
2716 /**
2717 * Checks whether a translated shortcut page has a different shortcut
2718 * target than the original language page.
2719 * If that is the case, things get corrected to follow that alternative
2720 * shortcut
2721 *
2722 * @return void
2723 */
2724 protected function checkTranslatedShortcut()
2725 {
2726 if (!is_null($this->originalShortcutPage)) {
2727 $originalShortcutPageOverlay = $this->sys_page->getPageOverlay($this->originalShortcutPage['uid'], $this->sys_language_uid);
2728 if (!empty($originalShortcutPageOverlay['shortcut']) && $originalShortcutPageOverlay['shortcut'] != $this->id) {
2729 // the translation of the original shortcut page has a different shortcut target!
2730 // set the correct page and id
2731 $shortcut = $this->getPageShortcut($originalShortcutPageOverlay['shortcut'], $originalShortcutPageOverlay['shortcut_mode'], $originalShortcutPageOverlay['uid']);
2732 $this->id = ($this->contentPid = $shortcut['uid']);
2733 $this->page = $this->sys_page->getPage($this->id);
2734 // Fix various effects on things like menus f.e.
2735 $this->fetch_the_id();
2736 $this->tmpl->rootLine = array_reverse($this->rootLine);
2737 }
2738 }
2739 }
2740
2741 /**
2742 * Handle data submission
2743 * This is done at this point, because we need the config values
2744 *
2745 * @return void
2746 */
2747 public function handleDataSubmission()
2748 {
2749 // Hook for processing data submission to extensions
2750 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission'])) {
2751 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission'] as $_classRef) {
2752 $_procObj = GeneralUtility::getUserObj($_classRef);
2753 $_procObj->checkDataSubmission($this);
2754 }
2755 }
2756 }
2757
2758 /**
2759 * Loops over all configured URL handlers and registers all active handlers in the redirect URL handler array.
2760 *
2761 * @see $activeRedirectUrlHandlers
2762 */
2763 public function initializeRedirectUrlHandlers()
2764 {
2765 if (
2766 empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['urlProcessing']['urlHandlers'])
2767 || !is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['urlProcessing']['urlHandlers'])
2768 ) {
2769 return;
2770 }
2771
2772 $urlHandlers = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['urlProcessing']['urlHandlers'];
2773 foreach ($urlHandlers as $identifier => $configuration) {
2774 if (empty($configuration) || !is_array($configuration)) {
2775 throw new \RuntimeException('Missing configuration for URL handler "' . $identifier . '".', 1442052263);
2776 }
2777 if (!is_string($configuration['handler']) || empty($configuration['handler']) || !class_exists($configuration['handler']) || !is_subclass_of($configuration['handler'], UrlHandlerInterface::class)) {
2778 throw new \RuntimeException('The URL handler "' . $identifier . '" defines an invalid provider. Ensure the class exists and implements the "' . UrlHandlerInterface::class . '".', 1442052249);
2779 }
2780 }
2781
2782 $orderedHandlers = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies($urlHandlers);
2783
2784 foreach ($orderedHandlers as $configuration) {
2785 /** @var UrlHandlerInterface $urlHandler */
2786 $urlHandler = GeneralUtility::makeInstance($configuration['handler']);
2787 if ($urlHandler->canHandleCurrentUrl()) {
2788 $this->activeUrlHandlers[] = $urlHandler;
2789 }
2790 }
2791 }
2792
2793 /**
2794 * Loops over all registered URL handlers and lets them process the current URL.
2795 *
2796 * If no handler has stopped the current process (e.g. by redirecting) and a
2797 * the redirectUrl propert is not empty, the user will be redirected to this URL.
2798 *
2799 * @internal Should be called by the FrontendRequestHandler only.
2800 */
2801 public function redirectToExternalUrl()
2802 {
2803 foreach ($this->activeUrlHandlers as $redirectHandler) {
2804 $redirectHandler->handle();
2805 }
2806
2807 if (!empty($this->activeUrlHandlers)) {
2808 throw new \RuntimeException('A URL handler is active but did not process the URL.', 1442305505);
2809 }
2810 }
2811
2812 /**
2813 * Sets the URL_ID_TOKEN in the internal var, $this->getMethodUrlIdToken
2814 * This feature allows sessions to use a GET-parameter instead of a cookie.
2815 *
2816 * @return void
2817 * @access private
2818 */
2819 public function setUrlIdToken()
2820 {
2821 if ($this->config['config']['ftu']) {
2822 $this->getMethodUrlIdToken = $GLOBALS['TYPO3_CONF_VARS']['FE']['get_url_id_token'];
2823 } else {
2824 $this->getMethodUrlIdToken = '';
2825 }
2826 }
2827
2828 /**
2829 * Calculates and sets the internal linkVars based upon the current
2830 * $_GET parameters and the setting "config.linkVars".
2831 *
2832 * @return void
2833 */
2834 public function calculateLinkVars()
2835 {
2836 $this->linkVars = '';
2837 $linkVars = GeneralUtility::trimExplode(',', (string)$this->config['config']['linkVars']);
2838 if (empty($linkVars)) {
2839 return;
2840 }
2841 $getData = GeneralUtility::_GET();
2842 foreach ($linkVars as $linkVar) {
2843 $test = ($value = '');
2844 if (preg_match('/^(.*)\\((.+)\\)$/', $linkVar, $match)) {
2845 $linkVar = trim($match[1]);
2846 $test = trim($match[2]);
2847 }
2848 if ($linkVar === '' || !isset($getData[$linkVar])) {
2849 continue;
2850 }
2851 if (!is_array($getData[$linkVar])) {
2852 $temp = rawurlencode($getData[$linkVar]);
2853 if ($test !== '' && !PageGenerator::isAllowedLinkVarValue($temp, $test)) {
2854 // Error: This value was not allowed for this key
2855 continue;
2856 }
2857 $value = '&' . $linkVar . '=' . $temp;
2858 } else {
2859 if ($test !== '' && $test !== 'array') {
2860 // Error: This key must not be an array!
2861 continue;
2862 }
2863 $value = GeneralUtility::implodeArrayForUrl($linkVar, $getData[$linkVar]);
2864 }
2865 $this->linkVars .= $value;
2866 }
2867 }
2868
2869 /**
2870 * Redirect to target page if the current page is an overlaid mountpoint.
2871 *
2872 * If the current page is of type mountpoint and should be overlaid with the contents of the mountpoint page
2873 * and is accessed directly, the user will be redirected to the mountpoint context.
2874 *
2875 * @return void
2876 */
2877 public function checkPageForMountpointRedirect()
2878 {
2879 if (!empty($this->originalMountPointPage) && $this->originalMountPointPage['doktype'] == PageRepository::DOKTYPE_MOUNTPOINT) {
2880 $this->redirectToCurrentPage();
2881 }
2882 }
2883
2884 /**
2885 * Redirect to target page, if the current page is a Shortcut.
2886 *
2887 * If the current page is of type shortcut and accessed directly via its URL, this function redirects to the
2888 * Shortcut target using a Location header.
2889 *
2890 * @return void If page is not a Shortcut, redirects and exits otherwise
2891 */
2892 public function checkPageForShortcutRedirect()
2893 {
2894 if (!empty($this->originalShortcutPage) && $this->originalShortcutPage['doktype'] == PageRepository::DOKTYPE_SHORTCUT) {
2895 $this->redirectToCurrentPage();
2896 }
2897 }
2898
2899 /**
2900 * Builds a typolink to the current page, appends the type paremeter if required
2901 * and redirects the user to the generated URL using a Location header.
2902 *
2903 * @return void
2904 */
2905 protected function redirectToCurrentPage()
2906 {
2907 $this->calculateLinkVars();
2908 // Instantiate \TYPO3\CMS\Frontend\ContentObject to generate the correct target URL
2909 /** @var $cObj ContentObjectRenderer */
2910 $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
2911 $parameter = $this->page['uid'];
2912 $type = GeneralUtility::_GET('type');
2913 if ($type && MathUtility::canBeInterpretedAsInteger($type)) {
2914 $parameter .= ',' . $type;
2915 }
2916 $redirectUrl = $cObj->typoLink_URL(array('parameter' => $parameter));
2917
2918 // Prevent redirection loop
2919 if (!empty($redirectUrl)) {
2920 // redirect and exit
2921 HttpUtility::redirect($redirectUrl, HttpUtility::HTTP_STATUS_307);
2922 }
2923 }
2924
2925 /********************************************
2926 *
2927 * Page generation; cache handling
2928 *
2929 *******************************************/