[!!!][TASK] Bootstrap: Central constants and path handling
[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 // Checking PHP version
42 // *******************************
43 if (version_compare(phpversion(), '5.3', '<')) die ('TYPO3 requires PHP 5.3.0 or higher.');
44
45
46 // ******************
47 // Constants defined
48 // ******************
49 $TYPO3_MISC['microtime_start'] = microtime(TRUE);
50 define('TYPO3_MODE','FE');
51
52 // *********************
53 // Unset variable(s) in global scope (fixes #13959)
54 // *********************
55 unset($error);
56
57 // *********************
58 // Prevent any output until AJAX/compression is initialized to stop
59 // AJAX/compression data corruption
60 // *********************
61 ob_start();
62
63
64 // *********************
65 // Mandatory libraries included
66 // *********************
67 require_once(PATH_t3lib . 'class.t3lib_div.php');
68 require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
69
70
71 // **********************
72 // Include configuration
73 // **********************
74 require(PATH_t3lib.'config_default.php');
75 if (!defined ('TYPO3_db')) die ('The configuration file was not included.'); // the name of the TYPO3 database is stored in this constant. Here the inclusion of the config-file is verified by checking if this var is set.
76 if (!t3lib_extMgm::isLoaded('cms')) die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
77
78
79 // *********************
80 // Timetracking started
81 // *********************
82 if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {
83 require_once(PATH_t3lib . 'class.t3lib_timetrack.php');
84 $TT = new t3lib_timeTrack();
85 } else {
86 require_once(PATH_t3lib . 'class.t3lib_timetracknull.php');
87 $TT = new t3lib_timeTrackNull();
88 }
89 $TT->start();
90 $TT->push('', 'Script start');
91
92 // *********************
93 // Error & Exception handling
94 // *********************
95 if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
96 $TT->push('Register Exceptionhandler', '');
97 if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
98 // register an error handler for the given errorHandlerErrors
99 $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
100 // set errors which will be converted in an exception
101 $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
102 }
103 $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
104 $TT->pull();
105 }
106
107 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
108 $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
109
110 $CLIENT = t3lib_div::clientInfo(); // Set to the browser: net / msie if 4+ browsers
111 $TT->pull();
112
113 // *******************************
114 // Checking environment
115 // *******************************
116 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
117 throw new Exception('You cannot set the GLOBALS-array from outside the script.', 1294585200);
118 }
119 if (!get_magic_quotes_gpc()) {
120 $TT->push('Add slashes to GET/POST arrays','');
121 t3lib_div::addSlashesOnArray($_GET);
122 t3lib_div::addSlashesOnArray($_POST);
123 $HTTP_GET_VARS = $_GET;
124 $HTTP_POST_VARS = $_POST;
125 $TT->pull();
126 }
127
128
129 // Hook to preprocess the current request:
130 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
131 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
132 $hookParameters = array();
133 t3lib_div::callUserFunction($hookFunction, $hookParameters, $hookParameters);
134 }
135 unset($hookFunction);
136 unset($hookParameters);
137 }
138
139
140 // *********************
141 // Look for extension ID which will launch alternative output engine
142 // *********************
143 if ($temp_extId = t3lib_div::_GP('eID')) {
144 if ($classPath = t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
145 // Remove any output produced until now
146 ob_clean();
147
148 require($classPath);
149 }
150 exit;
151 }
152
153
154 // ***********************************
155 // Create $TSFE object (TSFE = TypoScript Front End)
156 // Connecting to database
157 // ***********************************
158 $TSFE = t3lib_div::makeInstance('tslib_fe',
159 $TYPO3_CONF_VARS,
160 t3lib_div::_GP('id'),
161 t3lib_div::_GP('type'),
162 t3lib_div::_GP('no_cache'),
163 t3lib_div::_GP('cHash'),
164 t3lib_div::_GP('jumpurl'),
165 t3lib_div::_GP('MP'),
166 t3lib_div::_GP('RDCT')
167 );
168 /** @var $TSFE tslib_fe */
169
170 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
171 !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
172 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
173 }
174
175
176 $TSFE->connectToDB();
177
178 $TSFE->sendRedirect();
179
180
181 // *******************
182 // Output compression
183 // *******************
184 // Remove any output produced until now
185 ob_clean();
186 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
187 if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
188 // Prevent errors if ini_set() is unavailable (safe mode)
189 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
190 }
191 ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
192 }
193
194 // *********
195 // FE_USER
196 // *********
197 $TT->push('Front End user initialized','');
198 /* @var $TSFE tslib_fe */
199 $TSFE->initFEuser();
200 $TT->pull();
201
202
203 // *********
204 // BE_USER
205 // *********
206 /** @var $BE_USER t3lib_tsfeBeUserAuth */
207 $BE_USER = $TSFE->initializeBackendUser();
208
209
210 // *****************************************
211 // Process the ID, type and other parameters
212 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
213 // *****************************************
214 $TT->push('Process ID','');
215 // Initialize admin panel since simulation settings are required here:
216 if ($TSFE->isBackendUserLoggedIn()) {
217 $BE_USER->initializeAdminPanel();
218 }
219
220 $TSFE->checkAlternativeIdMethods();
221 $TSFE->clear_preview();
222 $TSFE->determineId();
223
224 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
225 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!
226
227 // Remove user
228 unset($BE_USER);
229 $TSFE->beUserLogin = 0;
230
231 // Re-evaluate the page-id.
232 $TSFE->checkAlternativeIdMethods();
233 $TSFE->clear_preview();
234 $TSFE->determineId();
235 }
236 $TSFE->makeCacheHash();
237 $TT->pull();
238
239 // *****************************************
240 // Admin Panel & Frontend editing
241 // *****************************************
242 if ($TSFE->isBackendUserLoggedIn()) {
243 // if a BE User is present load, the sprite manager for frontend-editing
244 $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
245 $spriteManager->loadCacheFile();
246
247 $BE_USER->initializeFrontendEdit();
248 if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
249 $LANG = t3lib_div::makeInstance('language');
250 $LANG->init($BE_USER->uc['lang']);
251 }
252 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
253 $BE_USER->frontendEdit->initConfigOptions();
254 }
255 }
256
257 // *******************************************
258 // Get compressed $TCA-Array();
259 // After this, we should now have a valid $TCA, though minimized
260 // *******************************************
261 $TSFE->getCompressedTCarray();
262
263
264 // ********************************
265 // Starts the template
266 // *******************************
267 $TT->push('Start Template','');
268 $TSFE->initTemplate();
269 $TT->pull();
270
271
272 // ********************************
273 // Get from cache
274 // *******************************
275 $TT->push('Get Page from cache','');
276 $TSFE->getFromCache();
277 $TT->pull();
278
279
280 // ******************************************************
281 // Get config if not already gotten
282 // After this, we should have a valid config-array ready
283 // ******************************************************
284 $TSFE->getConfigArray();
285
286 // ********************************
287 // Convert POST data to internal "renderCharset" if different from the metaCharset
288 // *******************************
289 $TSFE->convPOSTCharset();
290
291
292 // *******************************************
293 // Setting language and locale
294 // *******************************************
295 $TT->push('Setting language and locale','');
296 $TSFE->settingLanguage();
297 $TSFE->settingLocale();
298 $TT->pull();
299
300
301 // ********************************
302 // Check JumpUrl
303 // *******************************
304 $TSFE->setExternalJumpUrl();
305 $TSFE->checkJumpUrlReferer();
306
307
308 // ********************************
309 // Check Submission of data.
310 // This is done at this point, because we need the config values
311 // *******************************
312 switch($TSFE->checkDataSubmission()) {
313 case 'email':
314 $TSFE->sendFormmail();
315 break;
316 }
317
318
319 // *******************************
320 // Check for shortcut page and redirect
321 // *******************************
322 $TSFE->checkPageForShortcutRedirect();
323
324
325 // ********************************
326 // Generate page
327 // *******************************
328 $TSFE->setUrlIdToken();
329
330 $TT->push('Page generation','');
331 if ($TSFE->isGeneratePage()) {
332 $TSFE->generatePage_preProcessing();
333 $temp_theScript=$TSFE->generatePage_whichScript();
334
335 if ($temp_theScript) {
336 include($temp_theScript);
337 } else {
338 include(PATH_tslib.'pagegen.php');
339 }
340 $TSFE->generatePage_postProcessing();
341 } elseif ($TSFE->isINTincScript()) {
342 include(PATH_tslib.'pagegen.php');
343 }
344 $TT->pull();
345
346
347 // ********************************
348 // $TSFE->config['INTincScript']
349 // *******************************
350 if ($TSFE->isINTincScript()) {
351 $TT->push('Non-cached objects','');
352 $TSFE->INTincScript();
353 $TT->pull();
354 }
355
356 // ***************
357 // Output content
358 // ***************
359 $sendTSFEContent = FALSE;
360 if ($TSFE->isOutputting()) {
361 $TT->push('Print Content','');
362 $TSFE->processOutput();
363 $sendTSFEContent = TRUE;
364 $TT->pull();
365 }
366
367
368 // ********************************
369 // Store session data for fe_users
370 // ********************************
371 $TSFE->storeSessionData();
372
373
374 // ***********
375 // Statistics
376 // ***********
377 $TYPO3_MISC['microtime_end'] = microtime(TRUE);
378 $TSFE->setParseTime();
379 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
380 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
381 }
382 $TSFE->statistics();
383
384
385 // ***************
386 // Check JumpUrl
387 // ***************
388 $TSFE->jumpurl();
389
390
391 // *************
392 // Preview info
393 // *************
394 $TSFE->previewInfo();
395
396
397 // ******************
398 // Hook for end-of-frontend
399 // ******************
400 $TSFE->hook_eofe();
401
402
403 // ********************
404 // Finish timetracking
405 // ********************
406 $TT->pull();
407
408 // ******************
409 // Check memory usage
410 // ******************
411 t3lib_utility_Monitor::peakMemoryUsage();
412
413 // ******************
414 // beLoginLinkIPList
415 // ******************
416 echo $TSFE->beLoginLinkIPList();
417
418
419 // *************
420 // Admin panel
421 // *************
422 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->isBackendUserLoggedIn()) {
423 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
424 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
425 }
426
427 if ($sendTSFEContent) {
428 echo $TSFE->content;
429 }
430
431 // *************
432 // Debugging Output
433 // *************
434 if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
435 $error->debugOutput();
436 }
437 if (TYPO3_DLOG) {
438 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
439 }
440
441 ?>