[BUGFIX] INTincScript_loadJSCode() causes PHP warnings
[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\FrontendUserAuthtenication
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 * Locking object for accessing "cache_pagesection"
717 *
718 * @var \TYPO3\CMS\Core\Locking\Locker
719 * @todo Define visibility
720 */
721 public $pagesection_lockObj;
722
723 /**
724 * Locking object for accessing "cache_pages"
725 *
726 * @var \TYPO3\CMS\Core\Locking\Locker
727 * @todo Define visibility
728 */
729 public $pages_lockObj;
730
731 /**
732 * @var \TYPO3\CMS\Core\Page\PageRenderer
733 */
734 protected $pageRenderer;
735
736 /**
737 * the page cache object, use this to save pages to the cache and to
738 * retrieve them again
739 *
740 * @var t3lib_cache_AbstractBackend
741 */
742 protected $pageCache;
743
744 protected $pageCacheTags = array();
745
746 /**
747 * @var t3lib_cacheHash The cHash Service class used for cHash related functionality
748 */
749 protected $cacheHash;
750
751 /**
752 * Class constructor
753 * Takes a number of GET/POST input variable as arguments and stores them internally.
754 * The processing of these variables goes on later in this class.
755 * Also sets internal clientInfo array (browser information) and a unique string (->uniqueString) for this script instance; A md5 hash of the microtime()
756 *
757 * @param array $TYPO3_CONF_VARS The global $TYPO3_CONF_VARS array. Will be set internally in ->TYPO3_CONF_VARS
758 * @param mixed $id The value of t3lib_div::_GP('id')
759 * @param integer $type The value of t3lib_div::_GP('type')
760 * @param boolean $no_cache The value of t3lib_div::_GP('no_cache'), evaluated to 1/0
761 * @param string $cHash The value of t3lib_div::_GP('cHash')
762 * @param string $jumpurl The value of t3lib_div::_GP('jumpurl')
763 * @param string $MP The value of t3lib_div::_GP('MP')
764 * @param string $RDCT The value of t3lib_div::_GP('RDCT')
765 * @see index_ts.php
766 * @todo Define visibility
767 */
768 public function __construct($TYPO3_CONF_VARS, $id, $type, $no_cache = '', $cHash = '', $jumpurl = '', $MP = '', $RDCT = '') {
769 // Setting some variables:
770 $this->TYPO3_CONF_VARS = $TYPO3_CONF_VARS;
771 $this->id = $id;
772 $this->type = $type;
773 if ($no_cache) {
774 if ($this->TYPO3_CONF_VARS['FE']['disableNoCacheParameter']) {
775 $warning = '&no_cache=1 has been ignored because $TYPO3_CONF_VARS[\'FE\'][\'disableNoCacheParameter\'] is set!';
776 $GLOBALS['TT']->setTSlogMessage($warning, 2);
777 } else {
778 $warning = '&no_cache=1 has been supplied, so caching is disabled! URL: "' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') . '"';
779 $this->disableCache();
780 }
781 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($warning, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_WARNING);
782 }
783 $this->cHash = $cHash;
784 $this->jumpurl = $jumpurl;
785 $this->MP = $this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? (string) $MP : '';
786 $this->RDCT = $RDCT;
787 $this->clientInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::clientInfo();
788 $this->uniqueString = md5(microtime());
789 $this->csConvObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
790 // Call post processing function for constructor:
791 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'])) {
792 $_params = array('pObj' => &$this);
793 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['tslib_fe-PostProc'] as $_funcRef) {
794 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
795 }
796 }
797 $this->cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator');
798 $this->initCaches();
799 }
800
801 /**
802 * Connect to SQL database. May exit after outputting an error message
803 * or some JavaScript redirecting to the install tool.
804 *
805 * @return void
806 */
807 public function connectToDB() {
808 try {
809 $GLOBALS['TYPO3_DB']->connectDB();
810 } catch (\RuntimeException $exception) {
811 switch ($exception->getCode()) {
812 case 1270853882:
813 // No database selected: Redirect to Install Tool 1-2-3 mode (fresh installation)
814 \TYPO3\CMS\Core\Utility\HttpUtility::redirect(TYPO3_mainDir . 'install/index.php?mode=123&step=1&password=joh316');
815 break;
816 case 1270853883:
817 // Cannot connect to current database
818 $message = 'Cannot connect to the configured database "' . TYPO3_db . '"';
819 if ($this->checkPageUnavailableHandler()) {
820 $this->pageUnavailableAndExit($message);
821 } else {
822 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
823 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1301648782);
824 }
825 break;
826 case 1270853884:
827 // Username / password not accepted
828 $message = 'The current username, password or host was not accepted when' . ' the connection to the database was attempted to be established!';
829 if ($this->checkPageUnavailableHandler()) {
830 $this->pageUnavailableAndExit($message);
831 } else {
832 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
833 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException('Database Error: ' . $message, 1301648945);
834 }
835 break;
836 default:
837 throw $exception;
838 }
839 }
840 // Call post processing function for DB connection:
841 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'])) {
842 $_params = array('pObj' => &$this);
843 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB'] as $_funcRef) {
844 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
845 }
846 }
847 }
848
849 /**
850 * Looks up the value of $this->RDCT in the database and if it is
851 * found to be associated with a redirect URL then the redirection
852 * is carried out with a 'Location:' header
853 * May exit after sending a location-header.
854 *
855 * @return void
856 */
857 public function sendRedirect() {
858 if ($this->RDCT) {
859 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('params', 'cache_md5params', 'md5hash=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->RDCT, 'cache_md5params'));
860 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
861 $this->updateMD5paramsRecord($this->RDCT);
862 header('Location: ' . $row['params']);
863 die;
864 }
865 }
866 }
867
868 /**
869 * Gets instance of PageRenderer
870 *
871 * @return \TYPO3\CMS\Core\Page\PageRenderer
872 */
873 public function getPageRenderer() {
874 if (!isset($this->pageRenderer)) {
875 $this->pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Page\\PageRenderer');
876 $this->pageRenderer->setTemplateFile(PATH_tslib . 'templates/tslib_page_frontend.html');
877 $this->pageRenderer->setBackPath(TYPO3_mainDir);
878 }
879 return $this->pageRenderer;
880 }
881
882 /**
883 * This is needed for USER_INT processing
884 *
885 * @param \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer
886 */
887 protected function setPageRenderer(\TYPO3\CMS\Core\Page\PageRenderer $pageRenderer) {
888 $this->pageRenderer = $pageRenderer;
889 }
890
891 /********************************************
892 *
893 * Initializing, resolving page id
894 *
895 ********************************************/
896 /**
897 * Initializes the caching system.
898 *
899 * @return void
900 */
901 protected function initCaches() {
902 $this->pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
903 }
904
905 /**
906 * Initializes the front-end login user.
907 *
908 * @return void
909 * @todo Define visibility
910 */
911 public function initFEuser() {
912 $this->fe_user = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Authentication\\FrontendUserAuthtenication');
913 $this->fe_user->lockIP = $this->TYPO3_CONF_VARS['FE']['lockIP'];
914 $this->fe_user->checkPid = $this->TYPO3_CONF_VARS['FE']['checkFeUserPid'];
915 $this->fe_user->lifetime = intval($this->TYPO3_CONF_VARS['FE']['lifetime']);
916 // List of pid's acceptable
917 $this->fe_user->checkPid_value = $GLOBALS['TYPO3_DB']->cleanIntList(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pid'));
918 // Check if a session is transferred:
919 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('FE_SESSION_KEY')) {
920 $fe_sParts = explode('-', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('FE_SESSION_KEY'));
921 // If the session key hash check is OK:
922 if (!strcmp(md5(($fe_sParts[0] . '/' . $this->TYPO3_CONF_VARS['SYS']['encryptionKey'])), $fe_sParts[1])) {
923 $cookieName = \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthtenication::getCookieName();
924 $_COOKIE[$cookieName] = $fe_sParts[0];
925 if (isset($_SERVER['HTTP_COOKIE'])) {
926 // See http://forge.typo3.org/issues/27740
927 $_SERVER['HTTP_COOKIE'] .= ';' . $cookieName . '=' . $fe_sParts[0];
928 }
929 $this->fe_user->forceSetCookie = 1;
930 unset($cookieName);
931 }
932 }
933 if ($this->TYPO3_CONF_VARS['FE']['dontSetCookie']) {
934 $this->fe_user->dontSetCookie = 1;
935 }
936 $this->fe_user->start();
937 $this->fe_user->unpack_uc('');
938 // Gets session data
939 $this->fe_user->fetchSessionData();
940 $recs = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('recs');
941 // If any record registration is submitted, register the record.
942 if (is_array($recs)) {
943 $this->fe_user->record_registration($recs, $this->TYPO3_CONF_VARS['FE']['maxSessionDataSize']);
944 }
945 // Call hook for possible manipulation of frontend user object
946 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'])) {
947 $_params = array('pObj' => &$this);
948 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser'] as $_funcRef) {
949 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
950 }
951 }
952 // For every 60 seconds the is_online timestamp is updated.
953 if (is_array($this->fe_user->user) && $this->fe_user->user['uid'] && $this->fe_user->user['is_online'] < $GLOBALS['EXEC_TIME'] - 60) {
954 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('fe_users', 'uid=' . intval($this->fe_user->user['uid']), array('is_online' => $GLOBALS['EXEC_TIME']));
955 }
956 }
957
958 /**
959 * Initializes the front-end user groups.
960 * Sets ->loginUser and ->gr_list based on front-end user status.
961 *
962 * @return void
963 * @todo Define visibility
964 */
965 public function initUserGroups() {
966 // This affects the hidden-flag selecting the fe_groups for the user!
967 $this->fe_user->showHiddenRecords = $this->showHiddenRecords;
968 // no matter if we have an active user we try to fetch matching groups which can be set without an user (simulation for instance!)
969 $this->fe_user->fetchGroupData();
970 if (is_array($this->fe_user->user) && count($this->fe_user->groupData['uid'])) {
971 // global flag!
972 $this->loginUser = 1;
973 // 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!
974 $this->gr_list = '0,-2';
975 $gr_array = $this->fe_user->groupData['uid'];
976 } else {
977 $this->loginUser = 0;
978 // 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!
979 $this->gr_list = '0,-1';
980 if ($this->loginAllowedInBranch) {
981 // 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.
982 $gr_array = $this->fe_user->groupData['uid'];
983 } else {
984 // Set to blank since we will NOT risk any groups being set when no logins are allowed!
985 $gr_array = array();
986 }
987 }
988 // Clean up.
989 // Make unique...
990 $gr_array = array_unique($gr_array);
991 // sort
992 sort($gr_array);
993 if (count($gr_array) && !$this->loginAllowedInBranch_mode) {
994 $this->gr_list .= ',' . implode(',', $gr_array);
995 }
996 if ($this->fe_user->writeDevLog) {
997 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Valid usergroups for TSFE: ' . $this->gr_list, 'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController');
998 }
999 }
1000
1001 /**
1002 * Checking if a user is logged in or a group constellation different from "0,-1"
1003 *
1004 * @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!)
1005 * @todo Define visibility
1006 */
1007 public function isUserOrGroupSet() {
1008 return is_array($this->fe_user->user) || $this->gr_list !== '0,-1';
1009 }
1010
1011 /**
1012 * Provides ways to bypass the '?id=[xxx]&type=[xx]' format, using either PATH_INFO or virtual HTML-documents (using Apache mod_rewrite)
1013 *
1014 * Two options:
1015 * 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)
1016 * 2) Using hook which enables features like those provided from "realurl" extension (AKA "Speaking URLs")
1017 *
1018 * @return void
1019 * @todo Define visibility
1020 */
1021 public function checkAlternativeIdMethods() {
1022 $this->siteScript = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_SCRIPT');
1023 // Call post processing function for custom URL methods.
1024 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'])) {
1025 $_params = array('pObj' => &$this);
1026 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'] as $_funcRef) {
1027 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1028 }
1029 }
1030 }
1031
1032 /**
1033 * Clears the preview-flags, sets sim_exec_time to current time.
1034 * Hidden pages must be hidden as default, $GLOBALS['SIM_EXEC_TIME'] is set to $GLOBALS['EXEC_TIME']
1035 * in bootstrap initializeGlobalTimeVariables(). Alter it by adding or subtracting seconds.
1036 *
1037 * @return void
1038 * @todo Define visibility
1039 */
1040 public function clear_preview() {
1041 $this->showHiddenPage = 0;
1042 $this->showHiddenRecords = 0;
1043 $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
1044 $GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
1045 $this->fePreview = 0;
1046 }
1047
1048 /**
1049 * Checks if a backend user is logged in
1050 *
1051 * @return boolean whether a backend user is logged in
1052 */
1053 public function isBackendUserLoggedIn() {
1054 return $this->beUserLogin ? TRUE : FALSE;
1055 }
1056
1057 /**
1058 * Creates the backend user object and returns it.
1059 *
1060 * @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication the backend user object
1061 */
1062 public function initializeBackendUser() {
1063 // PRE BE_USER HOOK
1064 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
1065 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
1066 $_params = array();
1067 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1068 }
1069 }
1070 /** @var $BE_USER \TYPO3\CMS\Backend\FrontendBackendUserAuthentication */
1071 $BE_USER = NULL;
1072 // If the backend cookie is set,
1073 // we proceed and check if a backend user is logged in.
1074 if ($_COOKIE[\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName()]) {
1075 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_start'] = microtime(TRUE);
1076 $GLOBALS['TT']->push('Back End user initialized', '');
1077 // TODO: validate the comment below: is this necessary? if so,
1078 // formfield_status should be set to "" in t3lib_tsfeBeUserAuth
1079 // which is a subclass of t3lib_beUserAuth
1080 // ----
1081 // the value this->formfield_status is set to empty in order to
1082 // disable login-attempts to the backend account through this script
1083 // New backend user object
1084 $BE_USER = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\FrontendBackendUserAuthentication');
1085 $BE_USER->OS = TYPO3_OS;
1086 $BE_USER->lockIP = $this->TYPO3_CONF_VARS['BE']['lockIP'];
1087 // Object is initialized
1088 $BE_USER->start();
1089 $BE_USER->unpack_uc('');
1090 if ($BE_USER->user['uid']) {
1091 $BE_USER->fetchGroupData();
1092 $this->beUserLogin = 1;
1093 }
1094 // Unset the user initialization.
1095 if (!$BE_USER->checkLockToIP() || !$BE_USER->checkBackendAccessSettingsFromInitPhp() || !$BE_USER->user['uid']) {
1096 $BE_USER = NULL;
1097 $this->beUserLogin = 0;
1098 $_SESSION['TYPO3-TT-start'] = FALSE;
1099 }
1100 $GLOBALS['TT']->pull();
1101 $GLOBALS['TYPO3_MISC']['microtime_BE_USER_end'] = microtime(TRUE);
1102 }
1103 // POST BE_USER HOOK
1104 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['postBeUser'])) {
1105 $_params = array(
1106 'BE_USER' => &$BE_USER
1107 );
1108 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['postBeUser'] as $_funcRef) {
1109 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1110 }
1111 }
1112 return $BE_USER;
1113 }
1114
1115 /**
1116 * Determines the id and evaluates any preview settings
1117 * 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.
1118 *
1119 * @return void
1120 * @todo Define visibility
1121 */
1122 public function determineId() {
1123 // Call pre processing function for id determination
1124 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PreProcessing'])) {
1125 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PreProcessing'] as $functionReference) {
1126 $parameters = array('parentObject' => $this);
1127 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($functionReference, $parameters, $this);
1128 }
1129 }
1130 // Getting ARG-v values if some
1131 $this->setIDfromArgV();
1132 // If there is a Backend login we are going to check for any preview settings:
1133 $GLOBALS['TT']->push('beUserLogin', '');
1134 if ($this->beUserLogin || $this->doWorkspacePreview()) {
1135 // Backend user preview features:
1136 if ($this->beUserLogin && $GLOBALS['BE_USER']->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
1137 $this->fePreview = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview') ? TRUE : FALSE;
1138 // If admin panel preview is enabled...
1139 if ($this->fePreview) {
1140 $fe_user_OLD_USERGROUP = $this->fe_user->user['usergroup'];
1141 $this->showHiddenPage = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'showHiddenPages');
1142 $this->showHiddenRecords = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'showHiddenRecords');
1143 // Simulate date
1144 $simTime = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'simulateDate');
1145 if ($simTime) {
1146 $GLOBALS['SIM_EXEC_TIME'] = $simTime;
1147 $GLOBALS['SIM_ACCESS_TIME'] = $simTime - $simTime % 60;
1148 }
1149 // simulate user
1150 $simUserGroup = $GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('preview', 'simulateUserGroup');
1151 $this->simUserGroup = $simUserGroup;
1152 if ($simUserGroup) {
1153 $this->fe_user->user['usergroup'] = $simUserGroup;
1154 }
1155 if (!$simUserGroup && !$simTime && !$this->showHiddenPage && !$this->showHiddenRecords) {
1156 $this->fePreview = 0;
1157 }
1158 }
1159 }
1160 if ($this->id) {
1161 if ($this->determineIdIsHiddenPage()) {
1162 // The preview flag is set only if the current page turns out to actually be hidden!
1163 $this->fePreview = 1;
1164 $this->showHiddenPage = 1;
1165 }
1166 // For Live workspace: Check root line for proper connection to tree root (done because of possible preview of page / branch versions)
1167 if (!$this->fePreview && $this->whichWorkspace() === 0) {
1168 // Initialize the page-select functions to check rootline:
1169 $temp_sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1170 $temp_sys_page->init($this->showHiddenPage);
1171 // If root line contained NO records and ->error_getRootLine_failPid tells us that it was because of a pid=-1 (indicating a "version" record)...:
1172 if (!count($temp_sys_page->getRootLine($this->id, $this->MP)) && $temp_sys_page->error_getRootLine_failPid == -1) {
1173 // Setting versioningPreview flag and try again:
1174 $temp_sys_page->versioningPreview = TRUE;
1175 if (count($temp_sys_page->getRootLine($this->id, $this->MP))) {
1176 // 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.
1177 $this->fePreview = 1;
1178 }
1179 }
1180 }
1181 }
1182 // The preview flag will be set if a backend user is in an offline workspace
1183 if (($GLOBALS['BE_USER']->user['workspace_preview'] || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_view') || $this->doWorkspacePreview()) && ($this->whichWorkspace() === -1 || $this->whichWorkspace() > 0)) {
1184 // Will show special preview message.
1185 $this->fePreview = 2;
1186 }
1187 // If the front-end is showing a preview, caching MUST be disabled.
1188 if ($this->fePreview) {
1189 $this->disableCache();
1190 }
1191 }
1192 $GLOBALS['TT']->pull();
1193 // Now, get the id, validate access etc:
1194 $this->fetch_the_id();
1195 // Check if backend user has read access to this page. If not, recalculate the id.
1196 if ($this->beUserLogin && $this->fePreview) {
1197 if (!$GLOBALS['BE_USER']->doesUserHaveAccess($this->page, 1)) {
1198 // Resetting
1199 $this->clear_preview();
1200 $this->fe_user->user['usergroup'] = $fe_user_OLD_USERGROUP;
1201 // Fetching the id again, now with the preview settings reset.
1202 $this->fetch_the_id();
1203 }
1204 }
1205 // Checks if user logins are blocked for a certain branch and if so, will unset user login and re-fetch ID.
1206 $this->loginAllowedInBranch = $this->checkIfLoginAllowedInBranch();
1207 // Logins are not allowed:
1208 if (!$this->loginAllowedInBranch) {
1209 // Only if there is a login will we run this...
1210 if ($this->isUserOrGroupSet()) {
1211 if ($this->loginAllowedInBranch_mode == 'all') {
1212 // Clear out user and group:
1213 unset($this->fe_user->user);
1214 $this->gr_list = '0,-1';
1215 } else {
1216 $this->gr_list = '0,-2';
1217 }
1218 // Fetching the id again, now with the preview settings reset.
1219 $this->fetch_the_id();
1220 }
1221 }
1222 // Final cleaning.
1223 // Make sure it's an integer
1224 $this->id = ($this->contentPid = intval($this->id));
1225 // Make sure it's an integer
1226 $this->type = intval($this->type);
1227 // Call post processing function for id determination:
1228 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'])) {
1229 $_params = array('pObj' => &$this);
1230 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['determineId-PostProc'] as $_funcRef) {
1231 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1232 }
1233 }
1234 }
1235
1236 /**
1237 * Checks if the page is hidden in the active workspace.
1238 * If it is hidden, preview flags will be set.
1239 *
1240 * @return boolean
1241 */
1242 protected function determineIdIsHiddenPage() {
1243 $field = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->id) ? 'uid' : 'alias';
1244 $pageSelectCondition = $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->id, 'pages');
1245 $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid,hidden,starttime,endtime', 'pages', $pageSelectCondition . ' AND pid>=0 AND deleted=0');
1246 $workspace = $this->whichWorkspace();
1247 if ($workspace !== 0 && $workspace !== FALSE) {
1248 // Fetch overlay of page if in workspace and check if it is hidden
1249 $pageSelectObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1250 $pageSelectObject->versioningPreview = TRUE;
1251 $pageSelectObject->init(FALSE);
1252 $targetPage = $pageSelectObject->getWorkspaceVersionOfRecord($this->whichWorkspace(), 'pages', $page['uid']);
1253 $result = $targetPage === -1 || $targetPage === -2;
1254 } else {
1255 $result = is_array($page) && ($page['hidden'] || $page['starttime'] > $GLOBALS['SIM_EXEC_TIME'] || $page['endtime'] != 0 && $page['endtime'] <= $GLOBALS['SIM_EXEC_TIME']);
1256 }
1257 return $result;
1258 }
1259
1260 /**
1261 * Get The Page ID
1262 * This gets the id of the page, checks if the page is in the domain and if the page is accessible
1263 * Sets variables such as $this->sys_page, $this->loginUser, $this->gr_list, $this->id, $this->type, $this->domainStartPage, $this->idParts
1264 *
1265 * @return void
1266 * @access private
1267 * @todo Define visibility
1268 */
1269 public function fetch_the_id() {
1270 $GLOBALS['TT']->push('fetch_the_id initialize/', '');
1271 // Initialize the page-select functions.
1272 $this->sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
1273 $this->sys_page->versioningPreview = $this->fePreview === 2 || intval($this->workspacePreview) || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_view') ? TRUE : FALSE;
1274 $this->sys_page->versioningWorkspaceId = $this->whichWorkspace();
1275 $this->sys_page->init($this->showHiddenPage);
1276 // Set the valid usergroups for FE
1277 $this->initUserGroups();
1278 // Sets sys_page where-clause
1279 $this->setSysPageWhereClause();
1280 // Splitting $this->id by a period (.).
1281 // First part is 'id' and second part (if exists) will overrule the &type param
1282 $idParts = explode('.', $this->id, 2);
1283 $this->id = $idParts[0];
1284 if (isset($idParts[1])) {
1285 $this->type = $idParts[1];
1286 }
1287 // Splitting $this->id by a comma (,).
1288 // First part is 'id' and other parts are just stored for use in scripts.
1289 // Still used in the old wapversion.lib files.
1290 $this->idParts = explode(',', $this->id);
1291 $this->id = $this->idParts[0];
1292
1293 // Hook for further id manipulation
1294 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['modifyPageId'])) {
1295 $_params = array('id' => $this->id);
1296 $newId = FALSE;
1297 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['modifyPageId'] as $_funcRef) {
1298 $deprecationMessage = 'Hook $TYPO3_CONF_VARS[SC_OPTIONS][tslib/class.tslib_fe.php][modifyPageId] is ' .
1299 'deprecated since 6.0 and will be removed two versions later';
1300 if (!is_object($_funcRef) || !is_a($_funcRef, 'Closure')) {
1301 $deprecationMessage .= '- used by ' . $_funcRef;
1302 }
1303 \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog($deprecationMessage);
1304 $newIdFromFunc = \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1305 if ($newIdFromFunc !== FALSE) {
1306 $newId = $newIdFromFunc;
1307 }
1308 }
1309 if ($newId !== FALSE) {
1310 $this->id = $newId;
1311 }
1312 }
1313
1314 // If $this->id is a string, it's an alias
1315 $this->checkAndSetAlias();
1316 // The id and type is set to the integer-value - just to be sure...
1317 $this->id = intval($this->id);
1318 $this->type = intval($this->type);
1319 $GLOBALS['TT']->pull();
1320 // We find the first page belonging to the current domain
1321 $GLOBALS['TT']->push('fetch_the_id domain/', '');
1322 // The page_id of the current domain
1323 $this->domainStartPage = $this->findDomainRecord($this->TYPO3_CONF_VARS['SYS']['recursiveDomainSearch']);
1324 if (!$this->id) {
1325 if ($this->domainStartPage) {
1326 // If the id was not previously set, set it to the id of the domain.
1327 $this->id = $this->domainStartPage;
1328 } else {
1329 // Find the first 'visible' page in that domain
1330 $theFirstPage = $this->sys_page->getFirstWebPage($this->id);
1331 if ($theFirstPage) {
1332 $this->id = $theFirstPage['uid'];
1333 } else {
1334 $message = 'No pages are found on the rootlevel!';
1335 if ($this->checkPageUnavailableHandler()) {
1336 $this->pageUnavailableAndExit($message);
1337 } else {
1338 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1339 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1301648975);
1340 }
1341 }
1342 }
1343 }
1344 $GLOBALS['TT']->pull();
1345 $GLOBALS['TT']->push('fetch_the_id rootLine/', '');
1346 // We store the originally requested id
1347 $requestedId = $this->id;
1348 $this->getPageAndRootlineWithDomain($this->domainStartPage);
1349 $GLOBALS['TT']->pull();
1350 if ($this->pageNotFound && $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
1351 $pNotFoundMsg = array(
1352 1 => 'ID was not an accessible page',
1353 2 => 'Subsection was found and not accessible',
1354 3 => 'ID was outside the domain',
1355 4 => 'The requested page alias does not exist'
1356 );
1357 $this->pageNotFoundAndExit($pNotFoundMsg[$this->pageNotFound]);
1358 }
1359 if ($this->page['url_scheme'] > 0) {
1360 $newUrl = '';
1361 $requestUrlScheme = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), PHP_URL_SCHEME);
1362 if ((int) $this->page['url_scheme'] === \t3lib_utility_http::SCHEME_HTTP && $requestUrlScheme == 'https') {
1363 $newUrl = 'http://' . substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 8);
1364 } elseif ((int) $this->page['url_scheme'] === \t3lib_utility_http::SCHEME_HTTPS && $requestUrlScheme == 'http') {
1365 $newUrl = 'https://' . substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 7);
1366 }
1367 if ($newUrl !== '') {
1368 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
1369 $headerCode = \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303;
1370 } else {
1371 $headerCode = \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_301;
1372 }
1373 \t3lib_utility_http::redirect($newUrl, $headerCode);
1374 }
1375 }
1376 // Set no_cache if set
1377 if ($this->page['no_cache']) {
1378 $this->set_no_cache();
1379 }
1380 // Init SYS_LASTCHANGED
1381 $this->register['SYS_LASTCHANGED'] = intval($this->page['tstamp']);
1382 if ($this->register['SYS_LASTCHANGED'] < intval($this->page['SYS_LASTCHANGED'])) {
1383 $this->register['SYS_LASTCHANGED'] = intval($this->page['SYS_LASTCHANGED']);
1384 }
1385 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['fetchPageId-PostProcessing'])) {
1386 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['fetchPageId-PostProcessing'] as $functionReference) {
1387 $parameters = array('parentObject' => $this);
1388 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($functionReference, $parameters, $this);
1389 }
1390 }
1391 }
1392
1393 /**
1394 * Gets the page and rootline arrays based on the id, $this->id
1395 *
1396 * If the id does not correspond to a proper page, the 'previous' valid page in the rootline is found
1397 * If the page is a shortcut (doktype=4), the ->id is loaded with that id
1398 *
1399 * 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.
1400 *
1401 * Sets or manipulates internal variables such as: $this->id, $this->page, $this->rootLine, $this->MP, $this->pageNotFound
1402 *
1403 * @return void
1404 * @access private
1405 * @todo Define visibility
1406 */
1407 public function getPageAndRootline() {
1408 $this->page = $this->sys_page->getPage($this->id);
1409 if (!count($this->page)) {
1410 // If no page, we try to find the page before in the rootLine.
1411 // Page is 'not found' in case the id itself was not an accessible page. code 1
1412 $this->pageNotFound = 1;
1413 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1414 if (count($this->rootLine)) {
1415 $c = count($this->rootLine) - 1;
1416 while ($c > 0) {
1417 // Add to page access failure history:
1418 $this->pageAccessFailureHistory['direct_access'][] = $this->rootLine[$c];
1419 // Decrease to next page in rootline and check the access to that, if OK, set as page record and ID value.
1420 $c--;
1421 $this->id = $this->rootLine[$c]['uid'];
1422 $this->page = $this->sys_page->getPage($this->id);
1423 if (count($this->page)) {
1424 break;
1425 }
1426 }
1427 }
1428 // If still no page...
1429 if (!count($this->page)) {
1430 $message = 'The requested page does not exist!';
1431 if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
1432 $this->pageNotFoundAndExit($message);
1433 } else {
1434 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1435 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648780);
1436 }
1437 }
1438 }
1439 // Spacer is not accessible in frontend
1440 if ($this->page['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SPACER) {
1441 $message = 'The requested page does not exist!';
1442 if ($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling']) {
1443 $this->pageNotFoundAndExit($message);
1444 } else {
1445 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1446 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648781);
1447 }
1448 }
1449 // Is the ID a link to another page??
1450 if ($this->page['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1451 // 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.
1452 $this->MP = '';
1453 // saving the page so that we can check later - when we know
1454 // about languages - whether we took the correct shortcut or
1455 // whether a translation of the page overwrites the shortcut
1456 // target and we need to follow the new target
1457 $this->originalShortcutPage = $this->page;
1458 $this->page = $this->getPageShortcut($this->page['shortcut'], $this->page['shortcut_mode'], $this->page['uid']);
1459 $this->id = $this->page['uid'];
1460 }
1461 // Gets the rootLine
1462 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1463 // If not rootline we're off...
1464 if (!count($this->rootLine)) {
1465 $ws = $this->whichWorkspace();
1466 if ($this->sys_page->error_getRootLine_failPid == -1 && $ws) {
1467 $this->sys_page->versioningPreview = TRUE;
1468 $this->versioningWorkspaceId = $ws;
1469 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1470 }
1471 if (!count($this->rootLine)) {
1472 $message = 'The requested page didn\'t have a proper connection to the tree-root!';
1473 if ($this->checkPageUnavailableHandler()) {
1474 $this->pageUnavailableAndExit($message);
1475 } else {
1476 $rootline = '(' . $this->sys_page->error_getRootLine . ')';
1477 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1478 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message . '<br /><br />' . $rootline, 1301648167);
1479 }
1480 }
1481 $this->fePreview = 1;
1482 }
1483 // Checking for include section regarding the hidden/starttime/endtime/fe_user (that is access control of a whole subbranch!)
1484 if ($this->checkRootlineForIncludeSection()) {
1485 if (!count($this->rootLine)) {
1486 $message = 'The requested page was not accessible!';
1487 if ($this->checkPageUnavailableHandler()) {
1488 $this->pageUnavailableAndExit($message);
1489 } else {
1490 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1491 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1301648234);
1492 }
1493 } else {
1494 $el = reset($this->rootLine);
1495 $this->id = $el['uid'];
1496 $this->page = $this->sys_page->getPage($this->id);
1497 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
1498 }
1499 }
1500 }
1501
1502 /**
1503 * Get page shortcut; Finds the records pointed to by input value $SC (the shortcut value)
1504 *
1505 * @param integer $SC The value of the "shortcut" field from the pages record
1506 * @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
1507 * @param integer $thisUid The current page UID of the page which is a shortcut
1508 * @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...)
1509 * @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.
1510 * @return mixed Returns the page record of the page that the shortcut pointed to.
1511 * @access private
1512 * @see getPageAndRootline()
1513 * @todo Define visibility
1514 */
1515 public function getPageShortcut($SC, $mode, $thisUid, $itera = 20, $pageLog = array()) {
1516 $idArray = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $SC);
1517 // Find $page record depending on shortcut mode:
1518 switch ($mode) {
1519 case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
1520
1521 case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE:
1522 $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);
1523 $pO = 0;
1524 if ($mode == \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE && count($pageArray)) {
1525 $randval = intval(rand(0, count($pageArray) - 1));
1526 $pO = $randval;
1527 }
1528 $c = 0;
1529 foreach ($pageArray as $pV) {
1530 if ($c == $pO) {
1531 $page = $pV;
1532 break;
1533 }
1534 $c++;
1535 }
1536 if (count($page) == 0) {
1537 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a subpage. ' . 'However, this page has no accessible subpages.';
1538 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648328);
1539 }
1540 break;
1541 case \TYPO3\CMS\Frontend\Page\PageRepository::SHORTCUT_MODE_PARENT_PAGE:
1542 $parent = $this->sys_page->getPage($thisUid);
1543 $page = $this->sys_page->getPage($parent['pid']);
1544 if (count($page) == 0) {
1545 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to its parent page. ' . 'However, the parent page is not accessible.';
1546 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648358);
1547 }
1548 break;
1549 default:
1550 $page = $this->sys_page->getPage($idArray[0]);
1551 if (count($page) == 0) {
1552 $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a page, which is not accessible (ID ' . $idArray[0] . ').';
1553 throw new \TYPO3\CMS\Core\Error\Http\PageNotFoundException($message, 1301648404);
1554 }
1555 break;
1556 }
1557 // Check if short cut page was a shortcut itself, if so look up recursively:
1558 if ($page['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1559 if (!in_array($page['uid'], $pageLog) && $itera > 0) {
1560 $pageLog[] = $page['uid'];
1561 $page = $this->getPageShortcut($page['shortcut'], $page['shortcut_mode'], $page['uid'], $itera - 1, $pageLog);
1562 } else {
1563 $pageLog[] = $page['uid'];
1564 $message = 'Page shortcuts were looping in uids ' . implode(',', $pageLog) . '...!';
1565 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
1566 throw new \RuntimeException($message, 1294587212);
1567 }
1568 }
1569 // Return resulting page:
1570 return $page;
1571 }
1572
1573 /**
1574 * Checks the current rootline for defined sections.
1575 *
1576 * @return boolean
1577 * @access private
1578 * @todo Define visibility
1579 */
1580 public function checkRootlineForIncludeSection() {
1581 $c = count($this->rootLine);
1582 $removeTheRestFlag = 0;
1583 for ($a = 0; $a < $c; $a++) {
1584 if (!$this->checkPagerecordForIncludeSection($this->rootLine[$a])) {
1585 // Add to page access failure history:
1586 $this->pageAccessFailureHistory['sub_section'][] = $this->rootLine[$a];
1587 $removeTheRestFlag = 1;
1588 }
1589 if ($this->rootLine[$a]['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_BE_USER_SECTION) {
1590 // If there is a backend user logged in, check if he has read access to the page:
1591 if ($this->beUserLogin) {
1592 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid=' . intval($this->id) . ' AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1));
1593 // versionOL()?
1594 list($isPage) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
1595 if (!$isPage) {
1596 // 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...
1597 $removeTheRestFlag = 1;
1598 }
1599 } else {
1600 // Dont go here, if there is no backend user logged in.
1601 $removeTheRestFlag = 1;
1602 }
1603 }
1604 if ($removeTheRestFlag) {
1605 // Page is 'not found' in case a subsection was found and not accessible, code 2
1606 $this->pageNotFound = 2;
1607 unset($this->rootLine[$a]);
1608 }
1609 }
1610 return $removeTheRestFlag;
1611 }
1612
1613 /**
1614 * Checks page record for enableFields
1615 * Returns TRUE if enableFields does not disable the page record.
1616 * Takes notice of the ->showHiddenPage flag and uses SIM_ACCESS_TIME for start/endtime evaluation
1617 *
1618 * @param array $row The page record to evaluate (needs fields: hidden, starttime, endtime, fe_group)
1619 * @param boolean $bypassGroupCheck Bypass group-check
1620 * @return boolean TRUE, if record is viewable.
1621 * @see tslib_cObj::getTreeList(), checkPagerecordForIncludeSection()
1622 * @todo Define visibility
1623 */
1624 public function checkEnableFields($row, $bypassGroupCheck = FALSE) {
1625 if ((!$row['hidden'] || $this->showHiddenPage) && $row['starttime'] <= $GLOBALS['SIM_ACCESS_TIME'] && ($row['endtime'] == 0 || $row['endtime'] > $GLOBALS['SIM_ACCESS_TIME']) && ($bypassGroupCheck || $this->checkPageGroupAccess($row))) {
1626 return TRUE;
1627 }
1628 }
1629
1630 /**
1631 * Check group access against a page record
1632 *
1633 * @param array $row The page record to evaluate (needs field: fe_group)
1634 * @param mixed $groupList List of group id's (comma list or array). Default is $this->gr_list
1635 * @return boolean TRUE, if group access is granted.
1636 * @access private
1637 * @todo Define visibility
1638 */
1639 public function checkPageGroupAccess($row, $groupList = NULL) {
1640 if (is_null($groupList)) {
1641 $groupList = $this->gr_list;
1642 }
1643 if (!is_array($groupList)) {
1644 $groupList = explode(',', $groupList);
1645 }
1646 $pageGroupList = explode(',', $row['fe_group'] ? $row['fe_group'] : 0);
1647 return count(array_intersect($groupList, $pageGroupList)) > 0;
1648 }
1649
1650 /**
1651 * Checks page record for include section
1652 *
1653 * @param array $row The page record to evaluate (needs fields: extendToSubpages + hidden, starttime, endtime, fe_group)
1654 * @return boolean Returns TRUE if either extendToSubpages is not checked or if the enableFields does not disable the page record.
1655 * @access private
1656 * @see checkEnableFields(), tslib_cObj::getTreeList(), checkRootlineForIncludeSection()
1657 * @todo Define visibility
1658 */
1659 public function checkPagerecordForIncludeSection($row) {
1660 return !$row['extendToSubpages'] || $this->checkEnableFields($row) ? 1 : 0;
1661 }
1662
1663 /**
1664 * 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!)
1665 *
1666 * @return boolean returns TRUE if logins are OK, otherwise FALSE (and then the login user must be unset!)
1667 * @todo Define visibility
1668 */
1669 public function checkIfLoginAllowedInBranch() {
1670 // Initialize:
1671 $c = count($this->rootLine);
1672 $disable = FALSE;
1673 // Traverse root line from root and outwards:
1674 for ($a = 0; $a < $c; $a++) {
1675 // If a value is set for login state:
1676 if ($this->rootLine[$a]['fe_login_mode'] > 0) {
1677 // Determine state from value:
1678 if ((int) $this->rootLine[$a]['fe_login_mode'] === 1) {
1679 $disable = TRUE;
1680 $this->loginAllowedInBranch_mode = 'all';
1681 } elseif ((int) $this->rootLine[$a]['fe_login_mode'] === 3) {
1682 $disable = TRUE;
1683 $this->loginAllowedInBranch_mode = 'groups';
1684 } else {
1685 $disable = FALSE;
1686 }
1687 }
1688 }
1689 return !$disable;
1690 }
1691
1692 /**
1693 * 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
1694 *
1695 * @return array Summary of why page access was not allowed.
1696 * @todo Define visibility
1697 */
1698 public function getPageAccessFailureReasons() {
1699 $output = array();
1700 $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());
1701 if (count($combinedRecords)) {
1702 foreach ($combinedRecords as $k => $pagerec) {
1703 // 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
1704 // 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!
1705 if (!$k || $pagerec['extendToSubpages']) {
1706 if ($pagerec['hidden']) {
1707 $output['hidden'][$pagerec['uid']] = TRUE;
1708 }
1709 if ($pagerec['starttime'] > $GLOBALS['SIM_ACCESS_TIME']) {
1710 $output['starttime'][$pagerec['uid']] = $pagerec['starttime'];
1711 }
1712 if ($pagerec['endtime'] != 0 && $pagerec['endtime'] <= $GLOBALS['SIM_ACCESS_TIME']) {
1713 $output['endtime'][$pagerec['uid']] = $pagerec['endtime'];
1714 }
1715 if (!$this->checkPageGroupAccess($pagerec)) {
1716 $output['fe_group'][$pagerec['uid']] = $pagerec['fe_group'];
1717 }
1718 }
1719 }
1720 }
1721 return $output;
1722 }
1723
1724 /**
1725 * This checks if there are ARGV-parameters in the QUERY_STRING and if so, those are used for the id
1726 * $this->id must be 'FALSE' in order for any processing to happen in here
1727 * If an id/alias value is extracted from the QUERY_STRING it is set in $this->id
1728 *
1729 * @return void
1730 * @access private
1731 * @todo Define visibility
1732 */
1733 public function setIDfromArgV() {
1734 if (!$this->id) {
1735 list($theAlias) = explode('&', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('QUERY_STRING'));
1736 $theAlias = trim($theAlias);
1737 $this->id = $theAlias != '' && strpos($theAlias, '=') === FALSE ? $theAlias : 0;
1738 }
1739 }
1740
1741 /**
1742 * Gets ->page and ->rootline information based on ->id. ->id may change during this operation.
1743 * If not inside domain, then default to first page in domain.
1744 *
1745 * @param integer $domainStartPage Page uid of the page where the found domain record is (pid of the domain record)
1746 * @return void
1747 * @access private
1748 * @todo Define visibility
1749 */
1750 public function getPageAndRootlineWithDomain($domainStartPage) {
1751 $this->getPageAndRootline();
1752 // 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.
1753 if ($domainStartPage && is_array($this->rootLine)) {
1754 $idFound = 0;
1755 foreach ($this->rootLine as $key => $val) {
1756 if ($val['uid'] == $domainStartPage) {
1757 $idFound = 1;
1758 break;
1759 }
1760 }
1761 if (!$idFound) {
1762 // Page is 'not found' in case the id was outside the domain, code 3
1763 $this->pageNotFound = 3;
1764 $this->id = $domainStartPage;
1765 // re-get the page and rootline if the id was not found.
1766 $this->getPageAndRootline();
1767 }
1768 }
1769 }
1770
1771 /**
1772 * Sets sys_page where-clause
1773 *
1774 * @return void
1775 * @access private
1776 * @todo Define visibility
1777 */
1778 public function setSysPageWhereClause() {
1779 $this->sys_page->where_hid_del .= ' AND pages.doktype<200';
1780 $this->sys_page->where_groupAccess = $this->sys_page->getMultipleGroupsWhereClause('pages.fe_group', 'pages');
1781 }
1782
1783 /**
1784 * Looking up a domain record based on HTTP_HOST
1785 *
1786 * @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.
1787 * @return integer Returns the page id of the page where the domain record was found.
1788 * @access private
1789 * @todo Define visibility
1790 */
1791 public function findDomainRecord($recursive = 0) {
1792 if ($recursive) {
1793 $host = explode('.', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'));
1794 while (count($host)) {
1795 $pageUid = $this->sys_page->getDomainStartPage(implode('.', $host), \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME'), \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
1796 if ($pageUid) {
1797 return $pageUid;
1798 } else {
1799 array_shift($host);
1800 }
1801 }
1802 return $pageUid;
1803 } else {
1804 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'));
1805 }
1806 }
1807
1808 /**
1809 * Page unavailable handler for use in frontend plugins from extensions.
1810 *
1811 * @param string $reason Reason text
1812 * @param string $header HTTP header to send
1813 * @return void Function exits.
1814 * @todo Define visibility
1815 */
1816 public function pageUnavailableAndExit($reason = '', $header = '') {
1817 $header = $header ? $header : $this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling_statheader'];
1818 $this->pageUnavailableHandler($this->TYPO3_CONF_VARS['FE']['pageUnavailable_handling'], $header, $reason);
1819 die;
1820 }
1821
1822 /**
1823 * Page-not-found handler for use in frontend plugins from extensions.
1824 *
1825 * @param string $reason Reason text
1826 * @param string $header HTTP header to send
1827 * @return void Function exits.
1828 * @todo Define visibility
1829 */
1830 public function pageNotFoundAndExit($reason = '', $header = '') {
1831 $header = $header ? $header : $this->TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'];
1832 $this->pageNotFoundHandler($this->TYPO3_CONF_VARS['FE']['pageNotFound_handling'], $header, $reason);
1833 die;
1834 }
1835
1836 /**
1837 * Checks whether the pageUnavailableHandler should be used. To be used, pageUnavailable_handling must be set
1838 * and devIPMask must not match the current visitor's IP address.
1839 *
1840 * @return boolean TRUE/FALSE whether the pageUnavailable_handler should be used.
1841 * @todo Define visibility
1842 */
1843 public function checkPageUnavailableHandler() {
1844 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'])) {
1845 $checkPageUnavailableHandler = TRUE;
1846 } else {
1847 $checkPageUnavailableHandler = FALSE;
1848 }
1849 return $checkPageUnavailableHandler;
1850 }
1851
1852 /**
1853 * Page unavailable handler. Acts a wrapper for the pageErrorHandler method.
1854 *
1855 * @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.
1856 * @param string $header If set, this is passed directly to the PHP function, header()
1857 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1858 * @return void (The function exits!)
1859 * @todo Define visibility
1860 */
1861 public function pageUnavailableHandler($code, $header, $reason) {
1862 $this->pageErrorHandler($code, $header, $reason);
1863 }
1864
1865 /**
1866 * Page not found handler. Acts a wrapper for the pageErrorHandler method.
1867 *
1868 * @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.
1869 * @param string $header If set, this is passed directly to the PHP function, header()
1870 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1871 * @return void (The function exits!)
1872 * @todo Define visibility
1873 */
1874 public function pageNotFoundHandler($code, $header = '', $reason = '') {
1875 $this->pageErrorHandler($code, $header, $reason);
1876 }
1877
1878 /**
1879 * Generic error page handler.
1880 * Exits.
1881 *
1882 * @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.
1883 * @param string $header If set, this is passed directly to the PHP function, header()
1884 * @param string $reason If set, error messages will also mention this as the reason for the page-not-found.
1885 * @return void (The function exits!)
1886 * @todo Define visibility
1887 */
1888 public function pageErrorHandler($code, $header = '', $reason = '') {
1889 // Issue header in any case:
1890 if ($header) {
1891 $headerArr = preg_split('/\\r|\\n/', $header, -1, PREG_SPLIT_NO_EMPTY);
1892 foreach ($headerArr as $header) {
1893 header($header);
1894 }
1895 }
1896 // Create response:
1897 // Simply boolean; Just shows TYPO3 error page with reason:
1898 if (gettype($code) == 'boolean' || !strcmp($code, 1)) {
1899 $title = 'Page Not Found';
1900 $message = 'The page did not exist or was inaccessible.' . ($reason ? ' Reason: ' . htmlspecialchars($reason) : '');
1901 $messagePage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage', $message, $title);
1902 $messagePage->output();
1903 die;
1904 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($code, 'USER_FUNCTION:')) {
1905 $funcRef = trim(substr($code, 14));
1906 $params = array(
1907 'currentUrl' => \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'),
1908 'reasonText' => $reason,
1909 'pageAccessFailureReasons' => $this->getPageAccessFailureReasons()
1910 );
1911 echo \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
1912 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($code, 'READFILE:')) {
1913 $readFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(trim(substr($code, 9)));
1914 if (@is_file($readFile)) {
1915 $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($readFile);
1916 $fileContent = str_replace('###CURRENT_URL###', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'), $fileContent);
1917 $fileContent = str_replace('###REASON###', htmlspecialchars($reason), $fileContent);
1918 echo $fileContent;
1919 } else {
1920 throw new \RuntimeException('Configuration Error: 404 page "' . $readFile . '" could not be found.', 1294587214);
1921 }
1922 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($code, 'REDIRECT:')) {
1923 \TYPO3\CMS\Core\Utility\HttpUtility::redirect(substr($code, 9));
1924 } elseif (strlen($code)) {
1925 // Check if URL is relative
1926 $url_parts = parse_url($code);
1927 if ($url_parts['host'] == '') {
1928 $url_parts['host'] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
1929 if ($code[0] === '/') {
1930 $code = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . $code;
1931 } else {
1932 $code = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_DIR') . $code;
1933 }
1934 $checkBaseTag = FALSE;
1935 } else {
1936 $checkBaseTag = TRUE;
1937 }
1938 // Check recursion
1939 if ($code == \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')) {
1940 if ($reason == '') {
1941 $reason = 'Page cannot be found.';
1942 }
1943 $reason .= LF . LF . 'Additionally, ' . $code . ' was not found while trying to retrieve the error document.';
1944 throw new \RuntimeException(nl2br(htmlspecialchars($reason)), 1294587215);
1945 }
1946 // Prepare headers
1947 $headerArr = array(
1948 'User-agent: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_USER_AGENT'),
1949 'Referer: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')
1950 );
1951 $res = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($code, 1, $headerArr);
1952 // Header and content are separated by an empty line
1953 list($header, $content) = explode(CRLF . CRLF, $res, 2);
1954 $content .= CRLF;
1955 if (FALSE === $res) {
1956 // Last chance -- redirect
1957 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($code);
1958 } else {
1959 // Forward these response headers to the client
1960 $forwardHeaders = array(
1961 'Content-Type:'
1962 );
1963 $headerArr = preg_split('/\\r|\\n/', $header, -1, PREG_SPLIT_NO_EMPTY);
1964 foreach ($headerArr as $header) {
1965 foreach ($forwardHeaders as $h) {
1966 if (preg_match('/^' . $h . '/', $header)) {
1967 header($header);
1968 }
1969 }
1970 }
1971 // Put <base> if necesary
1972 if ($checkBaseTag) {
1973 // If content already has <base> tag, we do not need to do anything
1974 if (FALSE === stristr($content, '<base ')) {
1975 // Generate href for base tag
1976 $base = $url_parts['scheme'] . '://';
1977 if ($url_parts['user'] != '') {
1978 $base .= $url_parts['user'];
1979 if ($url_parts['pass'] != '') {
1980 $base .= ':' . $url_parts['pass'];
1981 }
1982 $base .= '@';
1983 }
1984 $base .= $url_parts['host'];
1985 // Add path portion skipping possible file name
1986 $base .= preg_replace('/(.*\\/)[^\\/]*/', '${1}', $url_parts['path']);
1987 // Put it into content (generate also <head> if necessary)
1988 $replacement = LF . '<base href="' . htmlentities($base) . '" />' . LF;
1989 if (stristr($content, '<head>')) {
1990 $content = preg_replace('/(<head>)/i', '\\1' . $replacement, $content);
1991 } else {
1992 $content = preg_replace('/(<html[^>]*>)/i', '\\1<head>' . $replacement . '</head>', $content);
1993 }
1994 }
1995 }
1996 // Output the content
1997 echo $content;
1998 }
1999 } else {
2000 $title = 'Page Not Found';
2001 $message = $reason ? 'Reason: ' . htmlspecialchars($reason) : 'Page cannot be found.';
2002 $messagePage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\ErrorpageMessage', $message, $title);
2003 $messagePage->output();
2004 }
2005 die;
2006 }
2007
2008 /**
2009 * Fetches the integer page id for a page alias.
2010 * 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
2011 *
2012 * @return void
2013 * @access private
2014 * @todo Define visibility
2015 */
2016 public function checkAndSetAlias() {
2017 if ($this->id && !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($this->id)) {
2018 $aid = $this->sys_page->getPageIdFromAlias($this->id);
2019 if ($aid) {
2020 $this->id = $aid;
2021 } else {
2022 $this->pageNotFound = 4;
2023 }
2024 }
2025 }
2026
2027 /**
2028 * Merging values into the global $_GET
2029 *
2030 * @param array $GET_VARS Array of key/value pairs that will be merged into the current GET-vars. (Non-escaped values)
2031 * @return void
2032 * @todo Define visibility
2033 */
2034 public function mergingWithGetVars($GET_VARS) {
2035 if (is_array($GET_VARS)) {
2036 // Getting $_GET var, unescaped.
2037 $realGet = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
2038 if (!is_array($realGet)) {
2039 $realGet = array();
2040 }
2041 // Merge new values on top:
2042 $realGet = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($realGet, $GET_VARS);
2043 // Write values back to $_GET:
2044 \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset($realGet);
2045 // Setting these specifically (like in the init-function):
2046 if (isset($GET_VARS['type'])) {
2047 $this->type = intval($GET_VARS['type']);
2048 }
2049 if (isset($GET_VARS['cHash'])) {
2050 $this->cHash = $GET_VARS['cHash'];
2051 }
2052 if (isset($GET_VARS['jumpurl'])) {
2053 $this->jumpurl = $GET_VARS['jumpurl'];
2054 }
2055 if (isset($GET_VARS['MP'])) {
2056 $this->MP = $this->TYPO3_CONF_VARS['FE']['enable_mount_pids'] ? $GET_VARS['MP'] : '';
2057 }
2058 if (isset($GET_VARS['no_cache']) && $GET_VARS['no_cache']) {
2059 $this->set_no_cache();
2060 }
2061 }
2062 }
2063
2064 /********************************************
2065 *
2066 * Template and caching related functions.
2067 *
2068 *******************************************/
2069 /**
2070 * Calculates a hash string based on additional parameters in the url.
2071 *
2072 * Calculated hash is stored in $this->cHash_array.
2073 * This is used to cache pages with more parameters than just id and type.
2074 *
2075 * @return void
2076 * @see reqCHash()
2077 * @todo Define visibility
2078 */
2079 public function makeCacheHash() {
2080 // No need to test anything if caching was already disabled.
2081 if ($this->no_cache && !$this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
2082 return;
2083 }
2084 $GET = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
2085 if ($this->cHash && is_array($GET)) {
2086 $this->cHash_array = $this->cacheHash->getRelevantParameters(\TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $GET));
2087 $cHash_calc = $this->cacheHash->calculateCacheHash($this->cHash_array);
2088 if ($cHash_calc != $this->cHash) {
2089 if ($this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
2090 $this->pageNotFoundAndExit('Request parameters could not be validated (&cHash comparison failed)');
2091 } else {
2092 $this->disableCache();
2093 $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);
2094 }
2095 }
2096 } elseif (is_array($GET)) {
2097 // No cHash is set, check if that is correct
2098 if ($this->cacheHash->doParametersRequireCacheHash(\TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $GET))) {
2099 $this->reqCHash();
2100 }
2101 }
2102 }
2103
2104 /**
2105 * Will disable caching if the cHash value was not set.
2106 * 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)
2107 *
2108 * @return void
2109 * @see makeCacheHash(), tslib_pibase::pi_cHashCheck()
2110 * @todo Define visibility
2111 */
2112 public function reqCHash() {
2113 if (!$this->cHash) {
2114 if ($this->TYPO3_CONF_VARS['FE']['pageNotFoundOnCHashError']) {
2115 if ($this->tempContent) {
2116 $this->clearPageCacheContent();
2117 }
2118 $this->pageNotFoundAndExit('Request parameters could not be validated (&cHash empty)');
2119 } else {
2120 $this->disableCache();
2121 $GLOBALS['TT']->setTSlogMessage('TSFE->reqCHash(): No &cHash parameter was sent for GET vars though required so caching is disabled', 2);
2122 }
2123 }
2124 }
2125
2126 /**
2127 * Splits the input query-parameters into an array with certain parameters filtered out.
2128 * Used to create the cHash value
2129 *
2130 * @param string $addQueryParams Query-parameters: "&xxx=yyy&zzz=uuu
2131 * @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
2132 * @access private
2133 * @see makeCacheHash(), tslib_cObj::typoLink()
2134 * @deprecated since TYPO3 4.7 - will be removed in TYPO3 6.1 - use t3lib_cacheHash instead
2135 * @obsolete
2136 * @todo Define visibility
2137 */
2138 public function cHashParams($addQueryParams) {
2139 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
2140 return $this->cacheHash->calculateCacheHash($addQueryParams);
2141 }
2142
2143 /**
2144 * Initialize the TypoScript template parser
2145 *
2146 * @return void
2147 * @todo Define visibility
2148 */
2149 public function initTemplate() {
2150 $this->tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService');
2151 $this->tmpl->init();
2152 $this->tmpl->tt_track = $this->beUserLogin ? 1 : 0;
2153 }
2154
2155 /**
2156 * See if page is in cache and get it if so
2157 * Stores the page content in $this->content if something is found.
2158 *
2159 * @return void
2160 * @todo Define visibility
2161 */
2162 public function getFromCache() {
2163 if (!$this->no_cache) {
2164 $cc = $this->tmpl->getCurrentPageData();
2165 if (!is_array($cc)) {
2166 $key = $this->id . '::' . $this->MP;
2167 // Returns TRUE if the lock is active now
2168 $isLocked = $this->acquirePageGenerationLock($this->pagesection_lockObj, $key);
2169 if (!$isLocked) {
2170 // Lock is no longer active, the data in "cache_pagesection" is now ready
2171 $cc = $this->tmpl->getCurrentPageData();
2172 if (is_array($cc)) {
2173 // Release the lock
2174 $this->releasePageGenerationLock($this->pagesection_lockObj);
2175 }
2176 }
2177 }
2178 if (is_array($cc)) {
2179 // 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.
2180 // If this hash is not the same in here in this section and after page-generation, then the page will not be properly cached!
2181 // 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.
2182 $cc = $this->tmpl->matching($cc);
2183 ksort($cc);
2184 $this->all = $cc;
2185 }
2186 unset($cc);
2187 }
2188 // clearing the content-variable, which will hold the pagecontent
2189 $this->content = '';
2190 // Unsetting the lowlevel config
2191 unset($this->config);
2192 $this->cacheContentFlag = 0;
2193 // Look for page in cache only if caching is not disabled and if a shift-reload is not sent to the server.
2194 if (!$this->no_cache && !$this->headerNoCache()) {
2195 $lockHash = $this->getLockHash();
2196 if ($this->all) {
2197 $this->newHash = $this->getHash();
2198 $GLOBALS['TT']->push('Cache Row', '');
2199 $row = $this->getFromCache_queryRow();
2200 if (!is_array($row)) {
2201 $isLocked = $this->acquirePageGenerationLock($this->pages_lockObj, $lockHash);
2202 if (!$isLocked) {
2203 // Lock is no longer active, the data in "cache_pages" is now ready
2204 $row = $this->getFromCache_queryRow();
2205 if (is_array($row)) {
2206 // Release the lock
2207 $this->releasePageGenerationLock($this->pages_lockObj);
2208 }
2209 }
2210 }
2211 if (is_array($row)) {
2212 // Release this lock
2213 $this->releasePageGenerationLock($this->pages_lockObj);
2214 // Call hook when a page is retrieved from cache:
2215 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'])) {
2216 $_params = array('pObj' => &$this, 'cache_pages_row' => &$row);
2217 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['pageLoadedFromCache'] as $_funcRef) {
2218 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2219 }
2220 }
2221 // Fetches the lowlevel config stored with the cached data
2222 $this->config = (array) unserialize($row['cache_data']);
2223 // Getting the content
2224 $this->content = $row['content'];
2225 // Flag for temp content
2226 $this->tempContent = $row['temp_content'];
2227 // Setting flag, so we know, that some cached content has been loaded
2228 $this->cacheContentFlag = 1;
2229 $this->cacheExpires = $row['expires'];
2230 if ($this->TYPO3_CONF_VARS['FE']['debug'] || isset($this->config['config']['debug']) && $this->config['config']['debug']) {
2231 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
2232 $timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
2233 $this->content .= LF . '<!-- Cached page generated ' . date(($dateFormat . ' ' . $timeFormat), $row['tstamp']) . '. Expires ' . Date(($dateFormat . ' ' . $timeFormat), $row['expires']) . ' -->';
2234 }
2235 }
2236 $GLOBALS['TT']->pull();
2237 } else {
2238 $this->acquirePageGenerationLock($this->pages_lockObj, $lockHash);
2239 }
2240 }
2241 }
2242
2243 /**
2244 * Returning the cached version of page with hash = newHash
2245 *
2246 * @return array Cached row, if any. Otherwise void.
2247 * @todo Define visibility
2248 */
2249 public function getFromCache_queryRow() {
2250 $GLOBALS['TT']->push('Cache Query', '');
2251 $row = $this->pageCache->get($this->newHash);
2252 $GLOBALS['TT']->pull();
2253 return $row;
2254 }
2255
2256 /**
2257 * Detecting if shift-reload has been clicked
2258 * Will not be called if re-generation of page happens by other reasons (for instance that the page is not in cache yet!)
2259 * Also, a backend user MUST be logged in for the shift-reload to be detected due to DoS-attack-security reasons.
2260 *
2261 * @return boolean If shift-reload in client browser has been clicked, disable getting cached page (and regenerate it).
2262 * @todo Define visibility
2263 */
2264 public function headerNoCache() {
2265 $disableAcquireCacheData = FALSE;
2266 if ($this->beUserLogin) {
2267 if (strtolower($_SERVER['HTTP_CACHE_CONTROL']) === 'no-cache' || strtolower($_SERVER['HTTP_PRAGMA']) === 'no-cache') {
2268 $disableAcquireCacheData = TRUE;
2269 }
2270 }
2271 // Call hook for possible by-pass of requiring of page cache (for recaching purpose)
2272 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['headerNoCache'])) {
2273 $_params = array('pObj' => &$this, 'disableAcquireCacheData' => &$disableAcquireCacheData);
2274 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['headerNoCache'] as $_funcRef) {
2275 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2276 }
2277 }
2278 return $disableAcquireCacheData;
2279 }
2280
2281 /**
2282 * Calculates the cache-hash
2283 * This hash is unique to the template, the variables ->id, ->type, ->gr_list (list of groups), ->MP (Mount Points) and cHash array
2284 * Used to get and later store the cached data.
2285 *
2286 * @return string MD5 hash of $this->hash_base which is a serialized version of there variables.
2287 * @access private
2288 * @see getFromCache(), getLockHash()
2289 * @todo Define visibility
2290 */
2291 public function getHash() {
2292 $this->hash_base = $this->createHashBase(FALSE);
2293 return md5($this->hash_base);
2294 }
2295
2296 /**
2297 * Calculates the lock-hash
2298 * This hash is unique to the above hash, except that it doesn't contain the template information in $this->all.
2299 *
2300 * @return string MD5 hash
2301 * @access private
2302 * @see getFromCache(), getHash()
2303 * @todo Define visibility
2304 */
2305 public function getLockHash() {
2306 $lockHash = $this->createHashBase(TRUE);
2307 return md5($lockHash);
2308 }
2309
2310 /**
2311 * Calculates the cache-hash (or the lock-hash)
2312 * This hash is unique to the template,
2313 * the variables ->id, ->type, ->gr_list (list of groups),
2314 * ->MP (Mount Points) and cHash array
2315 * Used to get and later store the cached data.
2316 *
2317 * @param boolean $createLockHashBase Whether to create the lock hash, which doesn't contain the "this->all" (the template information)
2318 * @return string the serialized hash base
2319 */
2320 protected function createHashBase($createLockHashBase = FALSE) {
2321 $hashParameters = array(
2322 'id' => intval($this->id),
2323 'type' => intval($this->type),
2324 'gr_list' => (string) $this->gr_list,
2325 'MP' => (string) $this->MP,
2326 'cHash' => $this->cHash_array,
2327 'domainStartPage' => $this->domainStartPage
2328 );
2329 // Include the template information if we shouldn't create a lock hash
2330 if (!$createLockHashBase) {
2331 $hashParameters['all'] = $this->all;
2332 }
2333 // Call hook to influence the hash calculation
2334 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'])) {
2335 $_params = array(
2336 'hashParameters' => &$hashParameters,
2337 'createLockHashBase' => $createLockHashBase
2338 );
2339 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'] as $_funcRef) {
2340 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2341 }
2342 }
2343 return serialize($hashParameters);
2344 }
2345
2346 /**
2347 * Checks if config-array exists already but if not, gets it
2348 *
2349 * @return void
2350 * @todo Define visibility
2351 */
2352 public function getConfigArray() {
2353 $setStatPageName = FALSE;
2354 // 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
2355 if (!is_array($this->config) || is_array($this->config['INTincScript']) || $this->forceTemplateParsing) {
2356 $GLOBALS['TT']->push('Parse template', '');
2357 // Force parsing, if set?:
2358 $this->tmpl->forceTemplateParsing = $this->forceTemplateParsing;
2359 // Start parsing the TS template. Might return cached version.
2360 $this->tmpl->start($this->rootLine);
2361 $GLOBALS['TT']->pull();
2362 if ($this->tmpl->loaded) {
2363 $GLOBALS['TT']->push('Setting the config-array', '');
2364 // toplevel - objArrayName
2365 $this->sPre = $this->tmpl->setup['types.'][$this->type];
2366 $this->pSetup = $this->tmpl->setup[$this->sPre . '.'];
2367 if (!is_array($this->pSetup)) {
2368 $message = 'The page is not configured! [type=' . $this->type . '][' . $this->sPre . '].';
2369 if ($this->checkPageUnavailableHandler()) {
2370 $this->pageUnavailableAndExit($message);
2371 } else {
2372 $explanation = 'This means that there is no TypoScript object of type PAGE with typeNum=' . $this->type . ' configured.';
2373 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
2374 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message . ' ' . $explanation, 1294587217);
2375 }
2376 } else {
2377 $this->config['config'] = array();
2378 // Filling the config-array, first with the main "config." part
2379 if (is_array($this->tmpl->setup['config.'])) {
2380 $this->config['config'] = $this->tmpl->setup['config.'];
2381 }
2382 // override it with the page/type-specific "config."
2383 if (is_array($this->pSetup['config.'])) {
2384 $this->config['config'] = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($this->config['config'], $this->pSetup['config.']);
2385 }
2386 if ($this->config['config']['typolinkEnableLinksAcrossDomains']) {
2387 $this->config['config']['typolinkCheckRootline'] = TRUE;
2388 }
2389 // Set default values for removeDefaultJS and inlineStyle2TempFile so CSS and JS are externalized if compatversion is higher than 4.0
2390 if (\TYPO3\CMS\Core\Utility\GeneralUtility::compat_version('4.0')) {
2391 if (!isset($this->config['config']['removeDefaultJS'])) {
2392 $this->config['config']['removeDefaultJS'] = 'external';
2393 }
2394 if (!isset($this->config['config']['inlineStyle2TempFile'])) {
2395 $this->config['config']['inlineStyle2TempFile'] = 1;
2396 }
2397 }
2398 if (!isset($this->config['config']['compressJs'])) {
2399 $this->config['config']['compressJs'] = 0;
2400 }
2401 // Processing for the config_array:
2402 $this->config['rootLine'] = $this->tmpl->rootLine;
2403 $this->config['mainScript'] = trim($this->config['config']['mainScript']) ? trim($this->config['config']['mainScript']) : 'index.php';
2404 // Class for render Header and Footer parts
2405 $template = '';
2406 if ($this->pSetup['pageHeaderFooterTemplateFile']) {
2407 $file = $this->tmpl->getFileName($this->pSetup['pageHeaderFooterTemplateFile']);
2408 if ($file) {
2409 $this->setTemplateFile($file);
2410 }
2411 }
2412 }
2413 $GLOBALS['TT']->pull();
2414 } else {
2415 if ($this->checkPageUnavailableHandler()) {
2416 $this->pageUnavailableAndExit('No TypoScript template found!');
2417 } else {
2418 $message = 'No TypoScript template found!';
2419 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
2420 throw new \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException($message, 1294587218);
2421 }
2422 }
2423 }
2424 // Initialize charset settings etc.
2425 $this->initLLvars();
2426 // No cache
2427 // Set $this->no_cache TRUE if the config.no_cache value is set!
2428 if ($this->config['config']['no_cache']) {
2429 $this->set_no_cache();
2430 }
2431 // Merge GET with defaultGetVars
2432 if (!empty($this->config['config']['defaultGetVars.'])) {
2433 $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());
2434 \TYPO3\CMS\Core\Utility\GeneralUtility::_GETset($modifiedGetVars);
2435 }
2436 // Hook for postProcessing the configuration array
2437 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'])) {
2438 $params = array('config' => &$this->config['config']);
2439 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'] as $funcRef) {
2440 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
2441 }
2442 }
2443 }
2444
2445 /********************************************
2446 *
2447 * Further initialization and data processing
2448 * (jumpurl/submission of forms)
2449 *
2450 *******************************************/
2451 /**
2452 * Get the compressed $GLOBALS['TCA'] array for use in the front-end
2453 * 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.
2454 * Operates on the global variable, $TCA
2455 *
2456 * @return void
2457 * @see includeTCA()
2458 * @todo Define visibility
2459 */
2460 public function getCompressedTCarray() {
2461 $GLOBALS['TT']->push('Get Compressed TC array');
2462 if (!$this->TCAloaded) {
2463 // Create hash string for storage / retrieval of cached content:
2464 $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) : ''));
2465 list($GLOBALS['TCA'], $this->TCAcachedExtras) = unserialize($this->sys_page->getHash($tempHash));
2466 // If no result, create it:
2467 if (!is_array($GLOBALS['TCA'])) {
2468 $this->includeTCA(0);
2469 $newTc = array();
2470 // Collects other information
2471 $this->TCAcachedExtras = array();
2472 foreach ($GLOBALS['TCA'] as $key => $val) {
2473 $newTc[$key]['ctrl'] = $val['ctrl'];
2474 $newTc[$key]['feInterface'] = $val['feInterface'];
2475 // Collect information about localization exclusion of fields:
2476 \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA($key);
2477 if (is_array($GLOBALS['TCA'][$key]['columns'])) {
2478 $this->TCAcachedExtras[$key]['l10n_mode'] = array();
2479 foreach ($GLOBALS['TCA'][$key]['columns'] as $fN => $fV) {
2480 if ($fV['l10n_mode']) {
2481 $this->TCAcachedExtras[$key]['l10n_mode'][$fN] = $fV['l10n_mode'];
2482 }
2483 }
2484 }
2485 }
2486 $GLOBALS['TCA'] = $newTc;
2487 $this->sys_page->storeHash($tempHash, serialize(array($newTc, $this->TCAcachedExtras)), 'SHORT_TC');
2488 }
2489 }
2490 $GLOBALS['TT']->pull();
2491 }
2492
2493 /**
2494 * Includes TCA definitions from loaded extensions (ext_table.php files).
2495 * Normally in the frontend only a part of the global $TCA array is loaded,
2496 * namely the "ctrl" part. Thus it doesn't take up too much memory. To load
2497 * full TCA for the table, use t3lib_div::loadTCA($tableName) after calling
2498 * this function.
2499 *
2500 * @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())
2501 * @return void
2502 * @see getCompressedTCarray()
2503 */
2504 public function includeTCA($TCAloaded = 1) {
2505 if (!$this->TCAloaded) {
2506 $GLOBALS['TCA'] = array();
2507 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(TRUE);
2508 $this->TCAloaded = $TCAloaded;
2509 }
2510 }
2511
2512 /**
2513 * Setting the language key that will be used by the current page.
2514 * 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.
2515 *
2516 * @return void
2517 * @access private
2518 * @todo Define visibility
2519 */
2520 public function settingLanguage() {
2521 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess'])) {
2522 $_params = array();
2523 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_preProcess'] as $_funcRef) {
2524 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2525 }
2526 }
2527 // Get values from TypoScript:
2528 $this->sys_language_uid = ($this->sys_language_content = intval($this->config['config']['sys_language_uid']));
2529 list($this->sys_language_mode, $sys_language_content) = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(';', $this->config['config']['sys_language_mode']);
2530 $this->sys_language_contentOL = $this->config['config']['sys_language_overlay'];
2531 // If sys_language_uid is set to another language than default:
2532 if ($this->sys_language_uid > 0) {
2533 // check whether a shortcut is overwritten by a translated page
2534 // we can only do this now, as this is the place where we get
2535 // to know about translations
2536 $this->checkTranslatedShortcut();
2537 // Request the overlay record for the sys_language_uid:
2538 $olRec = $this->sys_page->getPageOverlay($this->id, $this->sys_language_uid);
2539 if (!count($olRec)) {
2540 // If no OL record exists and a foreign language is asked for...
2541 if ($this->sys_language_uid) {
2542 // If requested translation is not available:
2543 if (\TYPO3\CMS\Core\Utility\GeneralUtility::hideIfNotTranslated($this->page['l18n_cfg'])) {
2544 $this->pageNotFoundAndExit('Page is not available in the requested language.');
2545 } else {
2546 switch ((string) $this->sys_language_mode) {
2547 case 'strict':
2548 $this->pageNotFoundAndExit('Page is not available in the requested language (strict).');
2549 break;
2550 case 'content_fallback':
2551 $fallBackOrder = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $sys_language_content);
2552 foreach ($fallBackOrder as $orderValue) {
2553 if (!strcmp($orderValue, '0') || count($this->sys_page->getPageOverlay($this->id, $orderValue))) {
2554 $this->sys_language_content = $orderValue;
2555 // Setting content uid (but leaving the sys_language_uid)
2556 break;
2557 }
2558 }
2559 break;
2560 case 'ignore':
2561 $this->sys_language_content = $this->sys_language_uid;
2562 break;
2563 default:
2564 // Default is that everything defaults to the default language...
2565 $this->sys_language_uid = ($this->sys_language_content = 0);
2566 break;
2567 }
2568 }
2569 }
2570 } else {
2571 // Setting sys_language if an overlay record was found (which it is only if a language is used)
2572 $this->page = $this->sys_page->getPageOverlay($this->page, $this->sys_language_uid);
2573 }
2574 }
2575 // Setting sys_language_uid inside sys-page:
2576 $this->sys_page->sys_language_uid = $this->sys_language_uid;
2577 // If default translation is not available:
2578 if ((!$this->sys_language_uid || !$this->sys_language_content) && $this->page['l18n_cfg'] & 1) {
2579 $message = 'Page is not available in default language.';
2580 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($message, 'cms', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
2581 $this->pageNotFoundAndExit($message);
2582 }
2583 // Updating content of the two rootLines IF the language key is set!
2584 if ($this->sys_language_uid && is_array($this->tmpl->rootLine)) {
2585 $this->tmpl->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
2586 }
2587 if ($this->sys_language_uid && is_array($this->rootLine)) {
2588 $this->rootLine = $this->sys_page->getRootLine($this->id, $this->MP);
2589 }
2590 // Finding the ISO code:
2591 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables') && $this->sys_language_content) {
2592 // using sys_language_content because the ISO code only (currently) affect content selection from FlexForms - which should follow "sys_language_content"
2593 $sys_language_row = $this->sys_page->getRawRecord('sys_language', $this->sys_language_content, 'static_lang_isocode');
2594 if (is_array($sys_language_row) && $sys_language_row['static_lang_isocode']) {
2595 $stLrow = $this->sys_page->getRawRecord('static_languages', $sys_language_row['static_lang_isocode'], 'lg_iso_2');
2596 $this->sys_language_isocode = $stLrow['lg_iso_2'];
2597 }
2598 }
2599 // Setting softMergeIfNotBlank:
2600 $table_fields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->config['config']['sys_language_softMergeIfNotBlank'], 1);
2601 foreach ($table_fields as $TF) {
2602 list($tN, $fN) = explode(':', $TF);
2603 $this->TCAcachedExtras[$tN]['l10n_mode'][$fN] = 'mergeIfNotBlank';
2604 }
2605 // Setting softExclude:
2606 $table_fields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->config['config']['sys_language_softExclude'], 1);
2607 foreach ($table_fields as $TF) {
2608 list($tN, $fN) = explode(':', $TF);
2609 $this->TCAcachedExtras[$tN]['l10n_mode'][$fN] = 'exclude';
2610 }
2611 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess'])) {
2612 $_params = array();
2613 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['settingLanguage_postProcess'] as $_funcRef) {
2614 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($_funcRef, $_params, $this);
2615 }
2616 }
2617 }
2618
2619 /**
2620 * Setting locale for frontend rendering
2621 *
2622 * @return void
2623 * @todo Define visibility
2624 */
2625 public function settingLocale() {
2626 // Setting locale
2627 if ($this->config['config']['locale_all']) {
2628 // There's a problem that PHP parses float values in scripts wrong if the
2629 // locale LC_NUMERIC is set to something with a comma as decimal point
2630 // Do we set all except LC_NUMERIC
2631 $locale = setlocale(LC_COLLATE, $this->config['config']['locale_all']);
2632 if ($locale) {
2633 // PHP fatals with uppercase I characters in method names with turkish locale LC_CTYPE
2634 // @see http://bugs.php.net/bug.php?id=35050
2635 if (substr($this->config['config']['locale_all'], 0, 2) != 'tr') {
2636 setlocale(LC_CTYPE, $this->config['config']['locale_all']);
2637 }
2638 setlocale(LC_MONETARY, $this->config['config']['locale_all']);
2639 setlocale(LC_TIME, $this->config['config']['locale_all']);
2640 $this->localeCharset = $this->csConvObj->get_locale_charset($this->config['config']['locale_all']);
2641 } else {
2642 $GLOBALS['TT']->setTSlogMessage('Locale "' . htmlspecialchars($this->config['config']['locale_all']) . '" not found.', 3);
2643 }
2644 }
2645 }
2646
2647 /**
2648 * Checks whether a translated shortcut page has a different shortcut
2649 * target than the original language page.
2650 * If that is the case, things get corrected to follow that alternative
2651 * shortcut
2652 *
2653 * @return void
2654 * @author Ingo Renner <ingo@typo3.org>
2655 */
2656 protected function checkTranslatedShortcut() {
2657 if (!is_null($this->originalShortcutPage)) {
2658 $originalShortcutPageOverlay = $this->sys_page->getPageOverlay($this->originalShortcutPage['uid'], $this->sys_language_uid);
2659 if (!empty($originalShortcutPageOverlay['shortcut']) && $originalShortcutPageOverlay['shortcut'] != $this->id) {
2660 // the translation of the original shortcut page has a different shortcut target!
2661 // set the correct page and id
2662 $shortcut = $this->getPageShortcut($originalShortcutPageOverlay['shortcut'], $originalShortcutPageOverlay['shortcut_mode'], $originalShortcutPageOverlay['uid']);
2663 $this->id = ($this->contentPid = $shortcut['uid']);
2664 $this->page = $this->sys_page->getPage($this->id);
2665 // Fix various effects on things like menus f.e.
2666 $this->fetch_the_id();
2667 $this->tmpl->rootLine = array_reverse($this->rootLine);
2668 }
2669 }
2670 }
2671
2672 /**
2673 * Checks if any email-submissions
2674 *
2675 * @return string "email" if a formmail has been sent, "" if none.
2676 * @todo Define visibility
2677 */
2678 public function checkDataSubmission() {
2679 $ret = '';
2680 $formtype_mail = isset($_POST['formtype_mail']) || isset($_POST['formtype_mail_x']);
2681 if ($formtype_mail) {
2682 $refInfo = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_REFERER'));
2683 if (\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') == $refInfo['host'] || $this->TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) {
2684 if ($this->locDataCheck($_POST['locationData'])) {
2685 if ($formtype_mail) {
2686 $ret = 'email';
2687 }
2688 $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": Return value: ' . $ret, 0);
2689 return $ret;
2690 }
2691 } else {
2692 $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": HTTP_HOST and REFERER HOST did not match when processing submitted formdata!', 3);
2693 }
2694 }
2695 // Hook for processing data submission to extensions:
2696 if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission'])) {
2697 foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkDataSubmission'] as $_classRef) {
2698 $_procObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($_classRef);
2699 $_procObj->checkDataSubmission($this);
2700 }
2701 }
2702 return $ret;
2703 }
2704
2705 /**
2706 * Processes submitted user data (obsolete "Frontend TCE")
2707 *
2708 * @return void
2709 * @see tslib_feTCE
2710 * @deprecated since 6.0, will be removed two versions later
2711 * @todo Define visibility
2712 */
2713 public function fe_tce() {
2714 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
2715 }
2716
2717 /**
2718 * Checks if a formmail submission can be sent as email
2719 *
2720 * @param string $locationData The input from $_POST['locationData']
2721 * @return void
2722 * @access private
2723 * @see checkDataSubmission()
2724 * @todo Define visibility
2725 */
2726 public function locDataCheck($locationData) {
2727 $locData = explode(':', $locationData);
2728 if (!$locData[1] || $this->sys_page->checkRecord($locData[1], $locData[2], 1)) {
2729 // $locData[1] -check means that a record is checked only if the locationData has a value for a record else than the page.
2730 if (count($this->sys_page->getPage($locData[0]))) {
2731 return 1;
2732 } else {
2733 $GLOBALS['TT']->setTSlogMessage('LocationData Error: The page pointed to by location data (' . $locationData . ') was not accessible.', 2);
2734 }
2735 } else {
2736 $GLOBALS['TT']->setTSlogMessage('LocationData Error: Location data (' . $locationData . ') record pointed to was not accessible.', 2);
2737 }
2738 }
2739
2740 /**
2741 * Sends the emails from the formmail content object.
2742 *
2743 * @return void
2744 * @access private
2745 * @see checkDataSubmission()
2746 * @todo Define visibility
2747 */
2748 public function sendFormmail() {
2749 $formmail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_formmail');
2750 $EMAIL_VARS = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST();
2751 $locationData = $EMAIL_VARS['locationData'];
2752 unset($EMAIL_VARS['locationData']);
2753 unset($EMAIL_VARS['formtype_mail'], $EMAIL_VARS['formtype_mail_x'], $EMAIL_VARS['formtype_mail_y']);
2754 $integrityCheck = $this->TYPO3_CONF_VARS['FE']['strictFormmail'];
2755 if (!$this->TYPO3_CONF_VARS['FE']['secureFormmail']) {
2756 // Check recipient field:
2757 // These two fields are the ones which contain recipient addresses that can be misused to send mail from foreign servers.
2758 $encodedFields = explode(',',