[BUGFIX] Delay start of TSFE Time Tracking
[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 // Set error reporting
47 // *******************************
48 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
49
50
51 // ******************
52 // Constants defined
53 // ******************
54 $TYPO3_MISC['microtime_start'] = microtime(TRUE);
55 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
56 define('TYPO3_MODE','FE');
57
58 if(!defined('PATH_thisScript')) {
59 define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
60 (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
61 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
62 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
63 ($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
64 }
65
66 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
67 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
68
69 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
70 define('PATH_typo3', PATH_site.TYPO3_mainDir);
71 define('PATH_typo3conf', PATH_site.'typo3conf/');
72
73 if (!defined('PATH_tslib')) {
74 if (@is_dir(PATH_site.TYPO3_mainDir.'sysext/cms/tslib/')) {
75 define('PATH_tslib', PATH_site.TYPO3_mainDir.'sysext/cms/tslib/');
76 } elseif (@is_dir(PATH_site.'tslib/')) {
77 define('PATH_tslib', PATH_site.'tslib/');
78 }
79 }
80
81 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
82
83 // *********************
84 // Unset variable(s) in global scope (fixes #13959)
85 // *********************
86 unset($error);
87
88 // *********************
89 // Prevent any output until AJAX/compression is initialized to stop
90 // AJAX/compression data corruption
91 // *********************
92 ob_start();
93
94
95 // *********************
96 // Mandatory libraries included
97 // *********************
98 require_once(PATH_t3lib . 'class.t3lib_div.php');
99 require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
100
101
102 // **********************
103 // Include configuration
104 // **********************
105 require(PATH_t3lib.'config_default.php');
106 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.
107 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.');
108
109 if (!defined('PATH_tslib')) {
110 define('PATH_tslib', t3lib_extMgm::extPath('cms').'tslib/');
111 }
112
113
114 // *********************
115 // Timetracking started
116 // *********************
117 if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {
118 require_once(PATH_t3lib . 'class.t3lib_timetrack.php');
119 $TT = new t3lib_timeTrack();
120 } else {
121 require_once(PATH_t3lib . 'class.t3lib_timetracknull.php');
122 $TT = new t3lib_timeTrackNull();
123 }
124 $TT->start();
125 $TT->push('', 'Script start');
126
127 // *********************
128 // Error & Exception handling
129 // *********************
130 if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
131 $TT->push('Register Exceptionhandler', '');
132 if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
133 // register an error handler for the given errorHandlerErrors
134 $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
135 // set errors which will be converted in an exception
136 $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
137 }
138 $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
139 $TT->pull();
140 }
141
142 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
143 $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
144
145 $CLIENT = t3lib_div::clientInfo(); // Set to the browser: net / msie if 4+ browsers
146 $TT->pull();
147
148 // *******************************
149 // Checking environment
150 // *******************************
151 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
152 throw new Exception('You cannot set the GLOBALS-array from outside the script.', 1294585200);
153 }
154 if (!get_magic_quotes_gpc()) {
155 $TT->push('Add slashes to GET/POST arrays','');
156 t3lib_div::addSlashesOnArray($_GET);
157 t3lib_div::addSlashesOnArray($_POST);
158 $HTTP_GET_VARS = $_GET;
159 $HTTP_POST_VARS = $_POST;
160 $TT->pull();
161 }
162
163
164 // Hook to preprocess the current request:
165 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
166 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
167 $hookParameters = array();
168 t3lib_div::callUserFunction($hookFunction, $hookParameters, $hookParameters);
169 }
170 unset($hookFunction);
171 unset($hookParameters);
172 }
173
174
175 // *********************
176 // Look for extension ID which will launch alternative output engine
177 // *********************
178 if ($temp_extId = t3lib_div::_GP('eID')) {
179 if ($classPath = t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
180 // Remove any output produced until now
181 ob_clean();
182
183 require($classPath);
184 }
185 exit;
186 }
187
188
189 // ***********************************
190 // Create $TSFE object (TSFE = TypoScript Front End)
191 // Connecting to database
192 // ***********************************
193 $TSFE = t3lib_div::makeInstance('tslib_fe',
194 $TYPO3_CONF_VARS,
195 t3lib_div::_GP('id'),
196 t3lib_div::_GP('type'),
197 t3lib_div::_GP('no_cache'),
198 t3lib_div::_GP('cHash'),
199 t3lib_div::_GP('jumpurl'),
200 t3lib_div::_GP('MP'),
201 t3lib_div::_GP('RDCT')
202 );
203 /** @var $TSFE tslib_fe */
204
205 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
206 !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
207 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
208 }
209
210
211 $TSFE->connectToDB();
212
213 // In case of a keyword-authenticated preview, re-initialize the TSFE object:
214 if ($temp_previewConfig = $TSFE->ADMCMD_preview()) {
215 $TSFE = t3lib_div::makeInstance('tslib_fe',
216 $TYPO3_CONF_VARS,
217 t3lib_div::_GP('id'),
218 t3lib_div::_GP('type'),
219 t3lib_div::_GP('no_cache'),
220 t3lib_div::_GP('cHash'),
221 t3lib_div::_GP('jumpurl'),
222 t3lib_div::_GP('MP'),
223 t3lib_div::_GP('RDCT')
224 );
225 $TSFE->ADMCMD_preview_postInit($temp_previewConfig);
226 }
227
228
229 $TSFE->sendRedirect();
230
231
232 // *******************
233 // Output compression
234 // *******************
235 // Remove any output produced until now
236 ob_clean();
237 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
238 if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
239 // Prevent errors if ini_set() is unavailable (safe mode)
240 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
241 }
242 ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
243 }
244
245 // *********
246 // FE_USER
247 // *********
248 $TT->push('Front End user initialized','');
249 /* @var $TSFE tslib_fe */
250 $TSFE->initFEuser();
251 $TT->pull();
252
253
254 // *********
255 // BE_USER
256 // *********
257 /** @var $BE_USER t3lib_tsfeBeUserAuth */
258 $BE_USER = $TSFE->initializeBackendUser();
259
260
261 // ********************
262 // Workspace preview:
263 // ********************
264 $TSFE->workspacePreviewInit();
265
266
267 // *****************************************
268 // Process the ID, type and other parameters
269 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
270 // *****************************************
271 $TT->push('Process ID','');
272 // Initialize admin panel since simulation settings are required here:
273 if ($TSFE->isBackendUserLoggedIn()) {
274 $BE_USER->initializeAdminPanel();
275 }
276
277 $TSFE->checkAlternativeIdMethods();
278 $TSFE->clear_preview();
279 $TSFE->determineId();
280
281 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
282 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!
283
284 // Remove user
285 unset($BE_USER);
286 $TSFE->beUserLogin = 0;
287
288 // Re-evaluate the page-id.
289 $TSFE->checkAlternativeIdMethods();
290 $TSFE->clear_preview();
291 $TSFE->determineId();
292 }
293 $TSFE->makeCacheHash();
294 $TT->pull();
295
296 // *****************************************
297 // Admin Panel & Frontend editing
298 // *****************************************
299 if ($TSFE->isBackendUserLoggedIn()) {
300 // if a BE User is present load, the sprite manager for frontend-editing
301 $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
302 $spriteManager->loadCacheFile();
303
304 $BE_USER->initializeFrontendEdit();
305 if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
306 $LANG = t3lib_div::makeInstance('language');
307 $LANG->init($BE_USER->uc['lang']);
308 }
309 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
310 $BE_USER->frontendEdit->initConfigOptions();
311 }
312 }
313
314 // *******************************************
315 // Get compressed $TCA-Array();
316 // After this, we should now have a valid $TCA, though minimized
317 // *******************************************
318 $TSFE->getCompressedTCarray();
319
320
321 // ********************************
322 // Starts the template
323 // *******************************
324 $TT->push('Start Template','');
325 $TSFE->initTemplate();
326 $TT->pull();
327
328
329 // ********************************
330 // Get from cache
331 // *******************************
332 $TT->push('Get Page from cache','');
333 $TSFE->getFromCache();
334 $TT->pull();
335
336
337 // ******************************************************
338 // Get config if not already gotten
339 // After this, we should have a valid config-array ready
340 // ******************************************************
341 $TSFE->getConfigArray();
342
343 // ********************************
344 // Convert POST data to internal "renderCharset" if different from the metaCharset
345 // *******************************
346 $TSFE->convPOSTCharset();
347
348
349 // *******************************************
350 // Setting language and locale
351 // *******************************************
352 $TT->push('Setting language and locale','');
353 $TSFE->settingLanguage();
354 $TSFE->settingLocale();
355 $TT->pull();
356
357
358 // ********************************
359 // Check JumpUrl
360 // *******************************
361 $TSFE->setExternalJumpUrl();
362 $TSFE->checkJumpUrlReferer();
363
364
365 // ********************************
366 // Check Submission of data.
367 // This is done at this point, because we need the config values
368 // *******************************
369 switch($TSFE->checkDataSubmission()) {
370 case 'email':
371 $TSFE->sendFormmail();
372 break;
373 case 'fe_tce':
374 $TSFE->includeTCA();
375 $TT->push('fe_tce','');
376 $TSFE->fe_tce();
377 $TT->pull();
378 break;
379 }
380
381
382 // *******************************
383 // Check for shortcut page and redirect
384 // *******************************
385 $TSFE->checkPageForShortcutRedirect();
386
387
388 // ********************************
389 // Generate page
390 // *******************************
391 $TSFE->setUrlIdToken();
392
393 $TT->push('Page generation','');
394 if ($TSFE->isGeneratePage()) {
395 $TSFE->generatePage_preProcessing();
396 $temp_theScript=$TSFE->generatePage_whichScript();
397
398 if ($temp_theScript) {
399 include($temp_theScript);
400 } else {
401 include(PATH_tslib.'pagegen.php');
402 }
403 $TSFE->generatePage_postProcessing();
404 } elseif ($TSFE->isINTincScript()) {
405 include(PATH_tslib.'pagegen.php');
406 }
407 $TT->pull();
408
409
410 // ********************************
411 // $TSFE->config['INTincScript']
412 // *******************************
413 if ($TSFE->isINTincScript()) {
414 $TT->push('Non-cached objects','');
415 $TSFE->INTincScript();
416 $TT->pull();
417 }
418
419 // ***************
420 // Output content
421 // ***************
422 $sendTSFEContent = FALSE;
423 if ($TSFE->isOutputting()) {
424 $TT->push('Print Content','');
425 $TSFE->processOutput();
426
427 // ***************************************
428 // Outputs content / Includes EXT scripts
429 // ***************************************
430 if ($TSFE->isEXTincScript()) {
431 $TT->push('External PHP-script','');
432 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
433 $EXTiS_config = $TSFE->config['EXTincScript'];
434 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content); // Splits content with the key
435
436 // Special feature: Include libraries
437 foreach ($EXTiS_config as $EXTiS_cPart) {
438 if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
439 $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], TRUE);
440 $TSFE->includeLibraries($EXTiS_resourceList);
441 }
442 }
443
444 foreach ($EXTiS_splitC as $EXTiS_c => $EXTiS_cPart) {
445 if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
446 $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
447 if (is_array($EXTiS_config[$EXTiS_key])) {
448 $REC = $EXTiS_config[$EXTiS_key]['data'];
449 $CONF = $EXTiS_config[$EXTiS_key]['conf'];
450 $content = '';
451 include($EXTiS_config[$EXTiS_key]['file']);
452 echo $content; // The script MAY return content in $content or the script may just output the result directly!
453 }
454 echo substr($EXTiS_cPart,35);
455 } else {
456 echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
457 }
458 }
459
460 $TT->pull();
461 } else {
462 $sendTSFEContent = TRUE;
463 }
464 $TT->pull();
465 }
466
467
468 // ********************************
469 // Store session data for fe_users
470 // ********************************
471 $TSFE->storeSessionData();
472
473
474 // ***********
475 // Statistics
476 // ***********
477 $TYPO3_MISC['microtime_end'] = microtime(TRUE);
478 $TSFE->setParseTime();
479 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
480 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
481 }
482 $TSFE->statistics();
483
484
485 // ***************
486 // Check JumpUrl
487 // ***************
488 $TSFE->jumpurl();
489
490
491 // *************
492 // Preview info
493 // *************
494 $TSFE->previewInfo();
495
496
497 // ******************
498 // Hook for end-of-frontend
499 // ******************
500 $TSFE->hook_eofe();
501
502
503 // ********************
504 // Finish timetracking
505 // ********************
506 $TT->pull();
507
508 // ******************
509 // Check memory usage
510 // ******************
511 t3lib_utility_Monitor::peakMemoryUsage();
512
513 // ******************
514 // beLoginLinkIPList
515 // ******************
516 echo $TSFE->beLoginLinkIPList();
517
518
519 // *************
520 // Admin panel
521 // *************
522 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->isBackendUserLoggedIn()) {
523 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
524 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
525 }
526
527 if ($sendTSFEContent) {
528 echo $TSFE->content;
529 }
530
531 // *************
532 // Debugging Output
533 // *************
534 if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
535 $error->debugOutput();
536 }
537 if (TYPO3_DLOG) {
538 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
539 }
540
541 ?>