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