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