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