[FEATURE] Bootstrap: Introduce shutdown and use in autoloader
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * This is the MAIN DOCUMENT of the TypoScript driven standard front-end (from the "cms" extension)
29 * Basically put this is the "index.php" script which all requests for TYPO3 delivered pages goes to in the frontend (the website)
30 * The script configures constants, includes libraries and does a little logic here and there in order to instantiate the right classes to create the webpage.
31 * All the real data processing goes on in the "tslib/" classes which this script will include and use as needed.
32 *
33 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * @package TYPO3
37 * @subpackage tslib
38 */
39
40 // ******************
41 // Constants defined
42 // ******************
43 define('TYPO3_MODE','FE');
44
45 // *********************
46 // Prevent any output until AJAX/compression is initialized to stop
47 // AJAX/compression data corruption
48 // *********************
49 ob_start();
50
51
52
53 // **********************
54 // Include configuration
55 // **********************
56 require(PATH_t3lib.'config_default.php');
57 if (!t3lib_extMgm::isLoaded('cms')) {
58 die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
59 }
60
61
62 // *********************
63 // Timetracking started
64 // *********************
65 if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {
66 require_once(PATH_t3lib . 'class.t3lib_timetrack.php');
67 $TT = new t3lib_timeTrack();
68 } else {
69 require_once(PATH_t3lib . 'class.t3lib_timetracknull.php');
70 $TT = new t3lib_timeTrackNull();
71 }
72 $TT->start();
73
74 Typo3_Bootstrap::initializeTypo3DbGlobal(FALSE);
75
76
77
78 // Hook to preprocess the current request:
79 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
80 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
81 $hookParameters = array();
82 t3lib_div::callUserFunction($hookFunction, $hookParameters, $hookParameters);
83 }
84 unset($hookFunction);
85 unset($hookParameters);
86 }
87
88
89 // *********************
90 // Look for extension ID which will launch alternative output engine
91 // *********************
92 if ($temp_extId = t3lib_div::_GP('eID')) {
93 if ($classPath = t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
94 // Remove any output produced until now
95 ob_clean();
96
97 require($classPath);
98 }
99 exit;
100 }
101
102
103 // ***********************************
104 // Create $TSFE object (TSFE = TypoScript Front End)
105 // Connecting to database
106 // ***********************************
107 $TSFE = t3lib_div::makeInstance('tslib_fe',
108 $TYPO3_CONF_VARS,
109 t3lib_div::_GP('id'),
110 t3lib_div::_GP('type'),
111 t3lib_div::_GP('no_cache'),
112 t3lib_div::_GP('cHash'),
113 t3lib_div::_GP('jumpurl'),
114 t3lib_div::_GP('MP'),
115 t3lib_div::_GP('RDCT')
116 );
117 /** @var $TSFE tslib_fe */
118
119 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
120 !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
121 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
122 }
123
124
125 $TSFE->connectToDB();
126
127 $TSFE->sendRedirect();
128
129
130 // *******************
131 // Output compression
132 // *******************
133 // Remove any output produced until now
134 ob_clean();
135 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
136 if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
137 // Prevent errors if ini_set() is unavailable (safe mode)
138 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
139 }
140 ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
141 }
142
143 // *********
144 // FE_USER
145 // *********
146 $TT->push('Front End user initialized','');
147 /* @var $TSFE tslib_fe */
148 $TSFE->initFEuser();
149 $TT->pull();
150
151
152 // *********
153 // BE_USER
154 // *********
155 /** @var $BE_USER t3lib_tsfeBeUserAuth */
156 $BE_USER = $TSFE->initializeBackendUser();
157
158
159 // *****************************************
160 // Process the ID, type and other parameters
161 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
162 // *****************************************
163 $TT->push('Process ID','');
164 // Initialize admin panel since simulation settings are required here:
165 if ($TSFE->isBackendUserLoggedIn()) {
166 $BE_USER->initializeAdminPanel();
167 }
168
169 $TSFE->checkAlternativeIdMethods();
170 $TSFE->clear_preview();
171 $TSFE->determineId();
172
173 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
174 if ($TSFE->isBackendUserLoggedIn() && (!$BE_USER->extPageReadAccess($TSFE->page) || t3lib_div::_GP('ADMCMD_noBeUser'))) { // t3lib_div::_GP('ADMCMD_noBeUser') is placed here because workspacePreviewInit() might need to know if a backend user is logged in!
175
176 // Remove user
177 unset($BE_USER);
178 $TSFE->beUserLogin = 0;
179
180 // Re-evaluate the page-id.
181 $TSFE->checkAlternativeIdMethods();
182 $TSFE->clear_preview();
183 $TSFE->determineId();
184 }
185 $TSFE->makeCacheHash();
186 $TT->pull();
187
188 // *****************************************
189 // Admin Panel & Frontend editing
190 // *****************************************
191 if ($TSFE->isBackendUserLoggedIn()) {
192 Typo3_Bootstrap::initializeSpriteManager(FALSE);
193
194 $BE_USER->initializeFrontendEdit();
195 if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
196 Typo3_Bootstrap::initializeLanguageObject();
197 }
198 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
199 $BE_USER->frontendEdit->initConfigOptions();
200 }
201 }
202
203 // *******************************************
204 // Get compressed $TCA-Array();
205 // After this, we should now have a valid $TCA, though minimized
206 // *******************************************
207 $TSFE->getCompressedTCarray();
208
209
210 // ********************************
211 // Starts the template
212 // *******************************
213 $TT->push('Start Template','');
214 $TSFE->initTemplate();
215 $TT->pull();
216
217
218 // ********************************
219 // Get from cache
220 // *******************************
221 $TT->push('Get Page from cache','');
222 $TSFE->getFromCache();
223 $TT->pull();
224
225
226 // ******************************************************
227 // Get config if not already gotten
228 // After this, we should have a valid config-array ready
229 // ******************************************************
230 $TSFE->getConfigArray();
231
232 // ********************************
233 // Convert POST data to internal "renderCharset" if different from the metaCharset
234 // *******************************
235 $TSFE->convPOSTCharset();
236
237
238 // *******************************************
239 // Setting language and locale
240 // *******************************************
241 $TT->push('Setting language and locale','');
242 $TSFE->settingLanguage();
243 $TSFE->settingLocale();
244 $TT->pull();
245
246
247 // ********************************
248 // Check JumpUrl
249 // *******************************
250 $TSFE->setExternalJumpUrl();
251 $TSFE->checkJumpUrlReferer();
252
253
254 // ********************************
255 // Check Submission of data.
256 // This is done at this point, because we need the config values
257 // *******************************
258 switch($TSFE->checkDataSubmission()) {
259 case 'email':
260 $TSFE->sendFormmail();
261 break;
262 }
263
264
265 // *******************************
266 // Check for shortcut page and redirect
267 // *******************************
268 $TSFE->checkPageForShortcutRedirect();
269
270
271 // ********************************
272 // Generate page
273 // *******************************
274 $TSFE->setUrlIdToken();
275
276 $TT->push('Page generation','');
277 if ($TSFE->isGeneratePage()) {
278 $TSFE->generatePage_preProcessing();
279 $temp_theScript=$TSFE->generatePage_whichScript();
280
281 if ($temp_theScript) {
282 include($temp_theScript);
283 } else {
284 include(PATH_tslib.'pagegen.php');
285 }
286 $TSFE->generatePage_postProcessing();
287 } elseif ($TSFE->isINTincScript()) {
288 include(PATH_tslib.'pagegen.php');
289 }
290 $TT->pull();
291
292
293 // ********************************
294 // $TSFE->config['INTincScript']
295 // *******************************
296 if ($TSFE->isINTincScript()) {
297 $TT->push('Non-cached objects','');
298 $TSFE->INTincScript();
299 $TT->pull();
300 }
301
302 // ***************
303 // Output content
304 // ***************
305 $sendTSFEContent = FALSE;
306 if ($TSFE->isOutputting()) {
307 $TT->push('Print Content','');
308 $TSFE->processOutput();
309 $sendTSFEContent = TRUE;
310 $TT->pull();
311 }
312
313
314 // ********************************
315 // Store session data for fe_users
316 // ********************************
317 $TSFE->storeSessionData();
318
319
320 // ***********
321 // Statistics
322 // ***********
323 $TYPO3_MISC['microtime_end'] = microtime(TRUE);
324 $TSFE->setParseTime();
325 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
326 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
327 }
328 $TSFE->statistics();
329
330
331 // ***************
332 // Check JumpUrl
333 // ***************
334 $TSFE->jumpurl();
335
336
337 // *************
338 // Preview info
339 // *************
340 $TSFE->previewInfo();
341
342
343 // ******************
344 // Hook for end-of-frontend
345 // ******************
346 $TSFE->hook_eofe();
347
348
349 // ********************
350 // Finish timetracking
351 // ********************
352 $TT->pull();
353
354 // ******************
355 // Check memory usage
356 // ******************
357 t3lib_utility_Monitor::peakMemoryUsage();
358
359 // ******************
360 // beLoginLinkIPList
361 // ******************
362 echo $TSFE->beLoginLinkIPList();
363
364
365 // *************
366 // Admin panel
367 // *************
368 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->isBackendUserLoggedIn()) {
369 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
370 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
371 }
372
373 if ($sendTSFEContent) {
374 echo $TSFE->content;
375 }
376
377 // *************
378 // Debugging Output
379 // *************
380 if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
381 $error->debugOutput();
382 }
383 if (TYPO3_DLOG) {
384 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
385 }
386
387 Typo3_Bootstrap::shutdown();
388
389 ?>