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