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