[FEATURE] stdWrap caching
[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 $TSFE->sendRedirect();
214
215
216 // *******************
217 // Output compression
218 // *******************
219 // Remove any output produced until now
220 ob_clean();
221 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
222 if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
223 // Prevent errors if ini_set() is unavailable (safe mode)
224 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
225 }
226 ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
227 }
228
229 // *********
230 // FE_USER
231 // *********
232 $TT->push('Front End user initialized','');
233 /* @var $TSFE tslib_fe */
234 $TSFE->initFEuser();
235 $TT->pull();
236
237
238 // *********
239 // BE_USER
240 // *********
241 /** @var $BE_USER t3lib_tsfeBeUserAuth */
242 $BE_USER = $TSFE->initializeBackendUser();
243
244
245 // *****************************************
246 // Process the ID, type and other parameters
247 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
248 // *****************************************
249 $TT->push('Process ID','');
250 // Initialize admin panel since simulation settings are required here:
251 if ($TSFE->isBackendUserLoggedIn()) {
252 $BE_USER->initializeAdminPanel();
253 }
254
255 $TSFE->checkAlternativeIdMethods();
256 $TSFE->clear_preview();
257 $TSFE->determineId();
258
259 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
260 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!
261
262 // Remove user
263 unset($BE_USER);
264 $TSFE->beUserLogin = 0;
265
266 // Re-evaluate the page-id.
267 $TSFE->checkAlternativeIdMethods();
268 $TSFE->clear_preview();
269 $TSFE->determineId();
270 }
271 $TSFE->makeCacheHash();
272 $TT->pull();
273
274 // *****************************************
275 // Admin Panel & Frontend editing
276 // *****************************************
277 if ($TSFE->isBackendUserLoggedIn()) {
278 // if a BE User is present load, the sprite manager for frontend-editing
279 $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
280 $spriteManager->loadCacheFile();
281
282 $BE_USER->initializeFrontendEdit();
283 if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
284 $LANG = t3lib_div::makeInstance('language');
285 $LANG->init($BE_USER->uc['lang']);
286 }
287 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
288 $BE_USER->frontendEdit->initConfigOptions();
289 }
290 }
291
292 // *******************************************
293 // Get compressed $TCA-Array();
294 // After this, we should now have a valid $TCA, though minimized
295 // *******************************************
296 $TSFE->getCompressedTCarray();
297
298
299 // ********************************
300 // Starts the template
301 // *******************************
302 $TT->push('Start Template','');
303 $TSFE->initTemplate();
304 $TT->pull();
305
306
307 // ********************************
308 // Get from cache
309 // *******************************
310 $TT->push('Get Page from cache','');
311 $TSFE->getFromCache();
312 $TT->pull();
313
314
315 // ******************************************************
316 // Get config if not already gotten
317 // After this, we should have a valid config-array ready
318 // ******************************************************
319 $TSFE->getConfigArray();
320
321 // ********************************
322 // Convert POST data to internal "renderCharset" if different from the metaCharset
323 // *******************************
324 $TSFE->convPOSTCharset();
325
326
327 // *******************************************
328 // Setting language and locale
329 // *******************************************
330 $TT->push('Setting language and locale','');
331 $TSFE->settingLanguage();
332 $TSFE->settingLocale();
333 $TT->pull();
334
335
336 // ********************************
337 // Check JumpUrl
338 // *******************************
339 $TSFE->setExternalJumpUrl();
340 $TSFE->checkJumpUrlReferer();
341
342
343 // ********************************
344 // Check Submission of data.
345 // This is done at this point, because we need the config values
346 // *******************************
347 switch($TSFE->checkDataSubmission()) {
348 case 'email':
349 $TSFE->sendFormmail();
350 break;
351 case 'fe_tce':
352 $TSFE->includeTCA();
353 $TT->push('fe_tce','');
354 $TSFE->fe_tce();
355 $TT->pull();
356 break;
357 }
358
359
360 // *******************************
361 // Check for shortcut page and redirect
362 // *******************************
363 $TSFE->checkPageForShortcutRedirect();
364
365
366 // ********************************
367 // Generate page
368 // *******************************
369 $TSFE->setUrlIdToken();
370
371 $TT->push('Page generation','');
372 if ($TSFE->isGeneratePage()) {
373 $TSFE->generatePage_preProcessing();
374 $temp_theScript=$TSFE->generatePage_whichScript();
375
376 if ($temp_theScript) {
377 include($temp_theScript);
378 } else {
379 include(PATH_tslib.'pagegen.php');
380 }
381 $TSFE->generatePage_postProcessing();
382 } elseif ($TSFE->isINTincScript()) {
383 include(PATH_tslib.'pagegen.php');
384 }
385 $TT->pull();
386
387
388 // ********************************
389 // $TSFE->config['INTincScript']
390 // *******************************
391 if ($TSFE->isINTincScript()) {
392 $TT->push('Non-cached objects','');
393 $TSFE->INTincScript();
394 $TT->pull();
395 }
396
397 // ***************
398 // Output content
399 // ***************
400 $sendTSFEContent = FALSE;
401 if ($TSFE->isOutputting()) {
402 $TT->push('Print Content','');
403 $TSFE->processOutput();
404
405 // ***************************************
406 // Outputs content / Includes EXT scripts
407 // ***************************************
408 if ($TSFE->isEXTincScript()) {
409 $TT->push('External PHP-script','');
410 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
411 $EXTiS_config = $TSFE->config['EXTincScript'];
412 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content); // Splits content with the key
413
414 // Special feature: Include libraries
415 foreach ($EXTiS_config as $EXTiS_cPart) {
416 if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
417 $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], TRUE);
418 $TSFE->includeLibraries($EXTiS_resourceList);
419 }
420 }
421
422 foreach ($EXTiS_splitC as $EXTiS_c => $EXTiS_cPart) {
423 if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
424 $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
425 if (is_array($EXTiS_config[$EXTiS_key])) {
426 $REC = $EXTiS_config[$EXTiS_key]['data'];
427 $CONF = $EXTiS_config[$EXTiS_key]['conf'];
428 $content = '';
429 include($EXTiS_config[$EXTiS_key]['file']);
430 echo $content; // The script MAY return content in $content or the script may just output the result directly!
431 }
432 echo substr($EXTiS_cPart,35);
433 } else {
434 echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
435 }
436 }
437
438 $TT->pull();
439 } else {
440 $sendTSFEContent = TRUE;
441 }
442 $TT->pull();
443 }
444
445
446 // ********************************
447 // Store session data for fe_users
448 // ********************************
449 $TSFE->storeSessionData();
450
451
452 // ***********
453 // Statistics
454 // ***********
455 $TYPO3_MISC['microtime_end'] = microtime(TRUE);
456 $TSFE->setParseTime();
457 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
458 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
459 }
460 $TSFE->statistics();
461
462
463 // ***************
464 // Check JumpUrl
465 // ***************
466 $TSFE->jumpurl();
467
468
469 // *************
470 // Preview info
471 // *************
472 $TSFE->previewInfo();
473
474
475 // ******************
476 // Hook for end-of-frontend
477 // ******************
478 $TSFE->hook_eofe();
479
480
481 // ********************
482 // Finish timetracking
483 // ********************
484 $TT->pull();
485
486 // ******************
487 // Check memory usage
488 // ******************
489 t3lib_utility_Monitor::peakMemoryUsage();
490
491 // ******************
492 // beLoginLinkIPList
493 // ******************
494 echo $TSFE->beLoginLinkIPList();
495
496
497 // *************
498 // Admin panel
499 // *************
500 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->isBackendUserLoggedIn()) {
501 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
502 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
503 }
504
505 if ($sendTSFEContent) {
506 echo $TSFE->content;
507 }
508
509 // *************
510 // Debugging Output
511 // *************
512 if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
513 $error->debugOutput();
514 }
515 if (TYPO3_DLOG) {
516 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
517 }
518
519 ?>