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