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