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