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