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