[BUGFIX] Redirect on direct access to overlaid mountpoint
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / FrontendRequestHandler.php
1 <?php
2 namespace TYPO3\CMS\Frontend;
3 /**
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16 /**
17 * This is the MAIN DOCUMENT of the TypoScript driven standard front-end
18 *
19 * Basically put this is the script which all requests for TYPO3
20 * delivered pages goes to in the frontend (the website). The script configures
21 * constants, includes libraries and does a little logic here and there in order
22 * to instantiate the right classes to create the webpage.
23 */
24 class FrontendRequestHandler {
25
26 /**
27 * Handles a frontend request
28 *
29 * @return void
30 */
31 public function handleRequest() {
32 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
33 ->loadTypo3LoadedExtAndExtLocalconf(TRUE)
34 ->applyAdditionalConfigurationSettings();
35
36 // Timetracking started
37 $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
38 if (empty($configuredCookieName)) {
39 $configuredCookieName = 'be_typo_user';
40 }
41 if ($_COOKIE[$configuredCookieName]) {
42 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\TimeTracker();
43 } else {
44 $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
45 }
46
47 $GLOBALS['TT']->start();
48
49 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeTypo3DbGlobal();
50 // Hook to preprocess the current request:
51 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
52 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
53 $hookParameters = array();
54 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
55 }
56 unset($hookFunction);
57 unset($hookParameters);
58 }
59 // Look for extension ID which will launch alternative output engine
60 if ($temp_extId = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID')) {
61 if ($classPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include'][$temp_extId])) {
62 // Remove any output produced until now
63 ob_clean();
64 require $classPath;
65 }
66 die;
67 }
68
69 /** @var $GLOBALS['TSFE'] \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
70 $GLOBALS['TSFE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
71 'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
72 $GLOBALS['TYPO3_CONF_VARS'],
73 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'),
74 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('type'),
75 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('no_cache'),
76 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cHash'),
77 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('jumpurl'),
78 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('MP'),
79 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RDCT')
80 );
81
82 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['pageUnavailable_force']
83 && !\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(
84 \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'),
85 $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])
86 ) {
87 $GLOBALS['TSFE']->pageUnavailableAndExit('This page is temporarily unavailable.');
88 }
89
90 $GLOBALS['TSFE']->connectToDB();
91 $GLOBALS['TSFE']->sendRedirect();
92
93 // Output compression
94 // Remove any output produced until now
95 ob_clean();
96 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel'] && extension_loaded('zlib')) {
97 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel'])) {
98 // Prevent errors if ini_set() is unavailable (safe mode)
99 @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['FE']['compressionLevel']);
100 }
101 ob_start(array(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Utility\\CompressionUtility'), 'compressionOutputHandler'));
102 }
103
104 // FE_USER
105 $GLOBALS['TT']->push('Front End user initialized', '');
106 /** @var $GLOBALS['TSFE'] \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
107 $GLOBALS['TSFE']->initFEuser();
108 $GLOBALS['TT']->pull();
109
110 // BE_USER
111 /** @var $GLOBALS['BE_USER'] \TYPO3\CMS\Backend\FrontendBackendUserAuthentication */
112 $GLOBALS['BE_USER'] = $GLOBALS['TSFE']->initializeBackendUser();
113
114 // Process the ID, type and other parameters.
115 // After this point we have an array, $page in TSFE, which is the page-record
116 // of the current page, $id.
117 $GLOBALS['TT']->push('Process ID', '');
118 // Initialize admin panel since simulation settings are required here:
119 if ($GLOBALS['TSFE']->isBackendUserLoggedIn()) {
120 $GLOBALS['BE_USER']->initializeAdminPanel();
121 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(TRUE);
122 } else {
123 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadCachedTca();
124 }
125 $GLOBALS['TSFE']->checkAlternativeIdMethods();
126 $GLOBALS['TSFE']->clear_preview();
127 $GLOBALS['TSFE']->determineId();
128
129 // Now, if there is a backend user logged in and he has NO access to this page,
130 // then re-evaluate the id shown! _GP('ADMCMD_noBeUser') is placed here because
131 // \TYPO3\CMS\Version\Hook\PreviewHook might need to know if a backend user is logged in.
132 if (
133 $GLOBALS['TSFE']->isBackendUserLoggedIn()
134 && (!$GLOBALS['BE_USER']->extPageReadAccess($GLOBALS['TSFE']->page) || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_noBeUser'))
135 ) {
136 // Remove user
137 unset($GLOBALS['BE_USER']);
138 $GLOBALS['TSFE']->beUserLogin = FALSE;
139 // Re-evaluate the page-id.
140 $GLOBALS['TSFE']->checkAlternativeIdMethods();
141 $GLOBALS['TSFE']->clear_preview();
142 $GLOBALS['TSFE']->determineId();
143 }
144
145 $GLOBALS['TSFE']->makeCacheHash();
146 $GLOBALS['TT']->pull();
147
148 // Admin Panel & Frontend editing
149 if ($GLOBALS['TSFE']->isBackendUserLoggedIn()) {
150 $GLOBALS['BE_USER']->initializeFrontendEdit();
151 if ($GLOBALS['BE_USER']->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
152 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
153 ->initializeLanguageObject()
154 ->initializeSpriteManager();
155 }
156 if ($GLOBALS['BE_USER']->frontendEdit instanceof \TYPO3\CMS\Core\FrontendEditing\FrontendEditingController) {
157 $GLOBALS['BE_USER']->frontendEdit->initConfigOptions();
158 }
159 }
160
161 // Starts the template
162 $GLOBALS['TT']->push('Start Template', '');
163 $GLOBALS['TSFE']->initTemplate();
164 $GLOBALS['TT']->pull();
165 // Get from cache
166 $GLOBALS['TT']->push('Get Page from cache', '');
167 $GLOBALS['TSFE']->getFromCache();
168 $GLOBALS['TT']->pull();
169 // Get config if not already gotten
170 // After this, we should have a valid config-array ready
171 $GLOBALS['TSFE']->getConfigArray();
172 // Setting language and locale
173 $GLOBALS['TT']->push('Setting language and locale', '');
174 $GLOBALS['TSFE']->settingLanguage();
175 $GLOBALS['TSFE']->settingLocale();
176 $GLOBALS['TT']->pull();
177
178 // Convert POST data to internal "renderCharset" if different from the metaCharset
179 $GLOBALS['TSFE']->convPOSTCharset();
180
181 // Check JumpUrl
182 $GLOBALS['TSFE']->setExternalJumpUrl();
183 $GLOBALS['TSFE']->checkJumpUrlReferer();
184
185 $GLOBALS['TSFE']->handleDataSubmission();
186
187 // Check for shortcut page and redirect
188 $GLOBALS['TSFE']->checkPageForShortcutRedirect();
189 $GLOBALS['TSFE']->checkPageForMountpointRedirect();
190
191 // Generate page
192 $GLOBALS['TSFE']->setUrlIdToken();
193 $GLOBALS['TT']->push('Page generation', '');
194 if ($GLOBALS['TSFE']->isGeneratePage()) {
195 $GLOBALS['TSFE']->generatePage_preProcessing();
196 $temp_theScript = $GLOBALS['TSFE']->generatePage_whichScript();
197 if ($temp_theScript) {
198 include $temp_theScript;
199 } else {
200 \TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
201 // Global content object
202 $GLOBALS['TSFE']->newCObj();
203 // LIBRARY INCLUSION, TypoScript
204 $temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
205 foreach ($temp_incFiles as $temp_file) {
206 include_once './' . $temp_file;
207 }
208 // Content generation
209 if (!$GLOBALS['TSFE']->isINTincScript()) {
210 \TYPO3\CMS\Frontend\Page\PageGenerator::renderContent();
211 $GLOBALS['TSFE']->setAbsRefPrefix();
212 }
213 }
214 $GLOBALS['TSFE']->generatePage_postProcessing();
215 } elseif ($GLOBALS['TSFE']->isINTincScript()) {
216 \TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
217 // Global content object
218 $GLOBALS['TSFE']->newCObj();
219 // LIBRARY INCLUSION, TypoScript
220 $temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
221 foreach ($temp_incFiles as $temp_file) {
222 include_once './' . $temp_file;
223 }
224 }
225 $GLOBALS['TT']->pull();
226
227 // $GLOBALS['TSFE']->config['INTincScript']
228 if ($GLOBALS['TSFE']->isINTincScript()) {
229 $GLOBALS['TT']->push('Non-cached objects', '');
230 $GLOBALS['TSFE']->INTincScript();
231 $GLOBALS['TT']->pull();
232 }
233 // Output content
234 $sendTSFEContent = FALSE;
235 if ($GLOBALS['TSFE']->isOutputting()) {
236 $GLOBALS['TT']->push('Print Content', '');
237 $GLOBALS['TSFE']->processOutput();
238 $sendTSFEContent = TRUE;
239 $GLOBALS['TT']->pull();
240 }
241 // Store session data for fe_users
242 $GLOBALS['TSFE']->storeSessionData();
243 // Statistics
244 $GLOBALS['TYPO3_MISC']['microtime_end'] = microtime(TRUE);
245 $GLOBALS['TSFE']->setParseTime();
246 if (isset($GLOBALS['TSFE']->config['config']['debug'])) {
247 $debugParseTime = (bool)$GLOBALS['TSFE']->config['config']['debug'];
248 } else {
249 $debugParseTime = !empty($GLOBALS['TSFE']->TYPO3_CONF_VARS['FE']['debug']);
250 }
251 if ($GLOBALS['TSFE']->isOutputting() && $debugParseTime) {
252 $GLOBALS['TSFE']->content .= LF . '<!-- Parsetime: ' . $GLOBALS['TSFE']->scriptParseTime . 'ms -->';
253 }
254 // Check JumpUrl
255 $GLOBALS['TSFE']->jumpurl();
256 // Preview info
257 $GLOBALS['TSFE']->previewInfo();
258 // Hook for end-of-frontend
259 $GLOBALS['TSFE']->hook_eofe();
260 // Finish timetracking
261 $GLOBALS['TT']->pull();
262 // Check memory usage
263 \TYPO3\CMS\Core\Utility\MonitorUtility::peakMemoryUsage();
264 // beLoginLinkIPList
265 echo $GLOBALS['TSFE']->beLoginLinkIPList();
266
267 // Admin panel
268 if (
269 $GLOBALS['TSFE']->isBackendUserLoggedIn()
270 && $GLOBALS['BE_USER'] instanceof \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
271 && $GLOBALS['BE_USER']->isAdminPanelVisible()
272 ) {
273 $GLOBALS['TSFE']->content = str_ireplace('</head>', $GLOBALS['BE_USER']->adminPanel->getAdminPanelHeaderData() . '</head>', $GLOBALS['TSFE']->content);
274 $GLOBALS['TSFE']->content = str_ireplace('</body>', $GLOBALS['BE_USER']->displayAdminPanel() . '</body>', $GLOBALS['TSFE']->content);
275 }
276
277 if ($sendTSFEContent) {
278 echo $GLOBALS['TSFE']->content;
279 }
280 // Debugging Output
281 if (isset($GLOBALS['error']) && is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'], 'debugOutput'))) {
282 $GLOBALS['error']->debugOutput();
283 }
284 if (TYPO3_DLOG) {
285 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
286 }
287 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->shutdown();
288 }
289 }