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