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