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