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