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