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