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