Changed lots of stuff...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 * On UNIX: You should create a symlink to this file from the directory from which you want your TYPO3 website to run (which is ../)
34 * ln -s tslib/index_ts.php index.php
35 *
36 * On Windows this file should copied to "index.php" in your website root (which is ../)
37 *
38 * $Id$
39 * Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
40 *
41 * @author Kasper Skaarhoj <kasper@typo3.com>
42 * @package TYPO3
43 * @subpackage tslib
44 */
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 define('PATH_thisScript',str_replace('//','/', str_replace('\\','/', php_sapi_name()=='cgi'||php_sapi_name()=='isapi'||php_sapi_name()=='cgi-fcgi' ? $HTTP_SERVER_VARS['PATH_TRANSLATED']:$HTTP_SERVER_VARS['SCRIPT_FILENAME'])));
59
60 define('PATH_site', dirname(PATH_thisScript).'/');
61 define('PATH_t3lib', PATH_site.'t3lib/');
62 define('PATH_tslib', PATH_site.'tslib/');
63 define('PATH_typo3conf', PATH_site.'typo3conf/');
64 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
65
66 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
67
68 // *********************
69 // Timetracking started
70 // *********************
71 require_once(PATH_t3lib.'class.t3lib_timetrack.php');
72 $TT = new t3lib_timeTrack;
73 $TT->start();
74 $TT->push('','Script start');
75
76
77 // *********************
78 // DIV Library included
79 // *********************
80 $TT->push('Include class t3lib_div','');
81 require(PATH_t3lib.'class.t3lib_div.php');
82 require(PATH_t3lib.'class.t3lib_extmgm.php');
83 $TT->pull();
84
85
86
87 // **********************
88 // Include configuration
89 // **********************
90 $TT->push('Include config files','');
91 require(PATH_t3lib.'config_default.php');
92 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.
93 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.');
94
95 $CLIENT=t3lib_div::clientInfo(); // Set to the browser: net / msie if 4+ browsers
96 $TT->pull();
97
98
99 // *********************
100 // Libraries included
101 // *********************
102 $TT->push('Include Frontend libraries','');
103 require_once(PATH_tslib.'class.tslib_fe.php');
104 require_once(PATH_t3lib.'class.t3lib_page.php');
105 require_once(PATH_t3lib.'class.t3lib_userauth.php');
106 require_once(PATH_tslib.'class.tslib_feuserauth.php');
107 require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
108 require_once(PATH_t3lib.'class.t3lib_cs.php');
109 $TT->pull();
110
111
112 // *******************************
113 // Checking environment
114 // *******************************
115 if (t3lib_div::int_from_ver(phpversion())<4000006) die ('TYPO3 runs with PHP4.0.6+ only');
116
117 if (isset($HTTP_POST_VARS['GLOBALS']) || isset($HTTP_GET_VARS['GLOBALS'])) die('You cannot set the GLOBALS-array from outside the script.');
118 if (!get_magic_quotes_gpc()) {
119 $TT->push('Add slashes to GET/POST arrays','');
120 t3lib_div::addSlashesOnArray($HTTP_GET_VARS);
121 t3lib_div::addSlashesOnArray($HTTP_POST_VARS);
122 $_GET = $HTTP_GET_VARS;
123 $_POST = $HTTP_POST_VARS;
124 $TT->pull();
125 }
126
127 // ***********************************
128 // Create $TSFE object (TSFE = TypoScript Front End)
129 // Connecting to database
130 // ***********************************
131 $temp_TSFEclassName=t3lib_div::makeInstanceClassName('tslib_fe');
132 $TSFE = new $temp_TSFEclassName(
133 $TYPO3_CONF_VARS,
134 t3lib_div::_GP('id'),
135 t3lib_div::_GP('type'),
136 t3lib_div::_GP('no_cache'),
137 t3lib_div::_GP('cHash'),
138 t3lib_div::_GP('jumpurl'),
139 t3lib_div::_GP('MP'),
140 t3lib_div::_GP('RDCT')
141 );
142 $TSFE->connectToMySQL();
143 if ($TSFE->RDCT) {$TSFE->sendRedirect();}
144
145
146 // *******************
147 // output compression
148 // *******************
149 if ($TYPO3_CONF_VARS['FE']['compressionLevel']) {
150 ob_start();
151 require_once(PATH_t3lib.'class.gzip_encode.php');
152 }
153
154 // *********
155 // FE_USER
156 // *********
157 $TT->push('Front End user initialized','');
158 $TSFE->initFEuser();
159 $TT->pull();
160
161 // *********
162 // BE_USER
163 // *********
164 $BE_USER='';
165 if ($HTTP_COOKIE_VARS['be_typo_user']) { // If the backend cookie is set, we proceed and checks if a backend user is logged in.
166 $TYPO3_MISC['microtime_BE_USER_start'] = microtime();
167 $TT->push('Back End user initialized','');
168 require_once (PATH_t3lib.'class.t3lib_befunc.php');
169 require_once (PATH_t3lib.'class.t3lib_userauthgroup.php');
170 require_once (PATH_t3lib.'class.t3lib_beuserauth.php');
171 require_once (PATH_t3lib.'class.t3lib_tsfebeuserauth.php');
172
173 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
174 $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
175 $BE_USER->OS = TYPO3_OS;
176 $BE_USER->start(); // Object is initialized
177 $BE_USER->unpack_uc('');
178 if ($BE_USER->user['uid']) {
179 $BE_USER->fetchGroupData();
180 $TSFE->beUserLogin=1;
181 }
182 if ($BE_USER->checkLockToIP() && $BE_USER->checkBackendAccessSettingsFromInitPhp()) {
183 $BE_USER->extInitFeAdmin();
184 if ($BE_USER->extAdmEnabled) {
185 require_once(t3lib_extMgm::extPath('lang').'lang.php');
186 $LANG = t3lib_div::makeInstance('language');
187 $LANG->init($BE_USER->uc['lang']);
188
189 $BE_USER->extSaveFeAdminConfig();
190 // Setting some values based on the admin panel
191 $TSFE->forceTemplateParsing = $BE_USER->extGetFeAdminValue('tsdebug', 'forceTemplateParsing');
192 $TSFE->displayEditIcons = $BE_USER->extGetFeAdminValue('edit', 'displayIcons');
193 $TSFE->displayFieldEditIcons = $BE_USER->extGetFeAdminValue('edit', 'displayFieldIcons');
194
195 if (t3lib_div::_GP('ADMCMD_editIcons')) {
196 $TSFE->displayFieldEditIcons=1;
197 $BE_USER->uc['TSFE_adminConfig']['edit_editNoPopup']=1;
198 }
199 if (t3lib_div::_GP('ADMCMD_simUser')) {
200 $BE_USER->uc['TSFE_adminConfig']['preview_simulateUserGroup']=intval(t3lib_div::_GP('ADMCMD_simUser'));
201 $BE_USER->ext_forcePreview=1;
202 }
203 if (t3lib_div::_GP('ADMCMD_simTime')) {
204 $BE_USER->uc['TSFE_adminConfig']['preview_simulateDate']=intval(t3lib_div::_GP('ADMCMD_simTime'));
205 $BE_USER->ext_forcePreview=1;
206 }
207
208 // Include classes for editing IF editing module in Admin Panel is open (it is assumed that $TSFE->displayEditIcons is set only if the Edit module is open in the Admin Panel)
209 if ($BE_USER->extAdmModuleEnabled('edit') && $BE_USER->extIsAdmMenuOpen('edit')) {
210 $TSFE->includeTCA();
211 if ($BE_USER->extIsEditAction()) {
212 require_once (PATH_t3lib.'class.t3lib_tcemain.php');
213 $BE_USER->extEditAction();
214 }
215 if ($BE_USER->extIsFormShown()) {
216 require_once(PATH_t3lib.'class.t3lib_tceforms.php');
217 require_once(PATH_t3lib.'class.t3lib_iconworks.php');
218 require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
219 require_once(PATH_t3lib.'class.t3lib_transferdata.php');
220 }
221 }
222
223 if ($TSFE->forceTemplateParsing || $TSFE->displayEditIcons || $TSFE->displayFieldEditIcons) { $TSFE->set_no_cache(); }
224 }
225
226 // $WEBMOUNTS = (string)($BE_USER->groupData['webmounts'])!='' ? explode(',',$BE_USER->groupData['webmounts']) : Array();
227 // $FILEMOUNTS = $BE_USER->groupData['filemounts'];
228 } else { // Unset the user initialization.
229 $BE_USER='';
230 $TSFE->beUserLogin=0;
231 }
232 $TT->pull();
233 $TYPO3_MISC['microtime_BE_USER_end'] = microtime();
234 }
235
236
237 // *****************************************
238 // Proces the ID, type and other parameters
239 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
240 // *****************************************
241 $TT->push('Process ID','');
242 $TSFE->checkAlternativeIdMethods();
243 $TSFE->clear_preview();
244 $TSFE->determineId();
245
246 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
247 if (is_object($BE_USER) && !$BE_USER->extPageReadAccess($TSFE->page)) {
248 // Remove user
249 $BE_USER='';
250 $TSFE->beUserLogin=0;
251 // Re-evaluate the page-id.
252 $TSFE->checkAlternativeIdMethods();
253 $TSFE->clear_preview();
254 $TSFE->determineId();
255 }
256 $TSFE->makeCacheHash(); // This was originally placed in the init- function. But moved to here because of the pEnc of simulateStaticDocuments. (200902)
257 $TT->pull();
258
259
260 // ********************************
261 // Starts the template
262 // *******************************
263 $TT->push('Start Template','');
264 $TSFE->initTemplate();
265 $TT->pull();
266
267
268 // ********************************
269 // Get from cache
270 // *******************************
271 $TT->push('Get Page from cache','');
272 $TSFE->getFromCache();
273 $TT->pull();
274
275
276 // ******************************************************
277 // Get config if not already gotten
278 // After this, we should have a valid config-array ready
279 // ******************************************************
280 $TSFE->getConfigArray();
281
282
283 // *******************************************
284 // Get compressed $TCA-Array();
285 // After this, we should now have a valid $TCA, though minimized
286 // *******************************************
287 $TSFE->getCompressedTCarray();
288
289
290 // *******************************************
291 // Setting the internal var, sys_language_uid
292 // *******************************************
293 $TSFE->settingLanguage();
294
295
296 // ********************************
297 // Check Submission of data.
298 // This is done at this point, because we need the config values
299 // *******************************
300 switch($TSFE->checkDataSubmission()) {
301 case 'email':
302 require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
303 require_once(PATH_t3lib.'class.t3lib_formmail.php');
304 $TSFE->sendFormmail();
305 break;
306 case 'fe_tce':
307 require_once(PATH_tslib.'class.tslib_fetce.php');
308 $TSFE->includeTCA();
309 $TT->push('fe_tce','');
310 $TSFE->fe_tce();
311 $TT->pull();
312 break;
313 }
314
315
316 // ********************************
317 // Check JumpUrl
318 // *******************************
319 $TSFE->checkJumpUrl();
320
321
322 // ********************************
323 // Generate page
324 // *******************************
325 $TSFE->setUrlIdToken();
326
327 $TT->push('Page generation','');
328 if ($TSFE->doXHTML_cleaning()) {require_once(PATH_t3lib.'class.t3lib_parsehtml.php');}
329 if ($TSFE->isGeneratePage()) {
330 $TSFE->generatePage_preProcessing();
331 $temp_theScript=$TSFE->generatePage_whichScript();
332
333 if ($temp_theScript) {
334 include($temp_theScript);
335 } else {
336 require_once(PATH_tslib.'class.tslib_pagegen.php');
337 include(PATH_tslib.'pagegen.php');
338 }
339 if ($TSFE->isSearchIndexPage()) {
340 if ($TSFE->config['config']['index_externals']) {require_once(PATH_t3lib.'class.t3lib_htmlmail.php');}
341 require_once(t3lib_extMgm::extPath('indexed_search','class.indexer.php'));
342 }
343 $TSFE->generatePage_postProcessing();
344 } elseif ($TSFE->isINTincScript()) {
345 require_once(PATH_tslib.'class.tslib_pagegen.php');
346 include(PATH_tslib.'pagegen.php');
347 }
348 $TT->pull();
349
350
351 // ********************************
352 // $GLOBALS['TSFE']->config['INTincScript']
353 // *******************************
354 if ($TSFE->isINTincScript()) {
355 $TT->push('Non-cached objects','');
356 $INTiS_config = $GLOBALS['TSFE']->config['INTincScript'];
357
358 // Special feature: Include libraries
359 $TT->push('Include libraries');
360 reset($INTiS_config);
361 while(list(,$INTiS_cPart)=each($INTiS_config)) {
362 if ($INTiS_cPart['conf']['includeLibs']) {
363 $INTiS_resourceList = t3lib_div::trimExplode(',',$INTiS_cPart['conf']['includeLibs'],1);
364 $GLOBALS['TT']->setTSlogMessage('Files for inclusion: "'.implode(', ',$INTiS_resourceList).'"');
365 reset($INTiS_resourceList);
366 while(list(,$INTiS_theLib)=each($INTiS_resourceList)) {
367 $INTiS_incFile=$GLOBALS['TSFE']->tmpl->getFileName($INTiS_theLib);
368 if ($INTiS_incFile) {
369 require_once('./'.$INTiS_incFile);
370 } else {
371 $GLOBALS['TT']->setTSlogMessage('Include file "'.$INTiS_theLib.'" did not exist!',2);
372 }
373 }
374 }
375 }
376 $TT->pull();
377 $TSFE->INTincScript();
378 $TT->pull();
379 }
380
381 // ***************
382 // Output content
383 // ***************
384 if ($TSFE->isOutputting()) {
385 $TT->push('Print Content','');
386 $TSFE->processOutput();
387
388 // ***************************************
389 // Outputs content / Includes EXT scripts
390 // ***************************************
391 if ($TSFE->isEXTincScript()) {
392 $TT->push('External PHP-script','');
393 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
394 $EXTiS_config = $GLOBALS['TSFE']->config['EXTincScript'];
395 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$GLOBALS['TSFE']->content); // Splits content with the key.
396
397 // Special feature: Include libraries
398 reset($EXTiS_config);
399 while(list(,$EXTiS_cPart)=each($EXTiS_config)) {
400 if ($EXTiS_cPart['conf']['includeLibs']) {
401 $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'],1);
402 $GLOBALS['TT']->setTSlogMessage('Files for inclusion: "'.implode(', ',$EXTiS_resourceList).'"');
403 reset($EXTiS_resourceList);
404 while(list(,$EXTiS_theLib)=each($EXTiS_resourceList)) {
405 $EXTiS_incFile=$GLOBALS['TSFE']->tmpl->getFileName($EXTiS_theLib);
406 if ($EXTiS_incFile) {
407 require_once($EXTiS_incFile);
408 } else {
409 $GLOBALS['TT']->setTSlogMessage('Include file "'.$EXTiS_theLib.'" did not exist!',2);
410 }
411 }
412 }
413 }
414
415 reset($EXTiS_splitC);
416 while(list($EXTiS_c,$EXTiS_cPart)=each($EXTiS_splitC)) {
417 if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
418 $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
419 if (is_array($EXTiS_config[$EXTiS_key])) {
420 $REC = $EXTiS_config[$EXTiS_key]['data'];
421 $CONF = $EXTiS_config[$EXTiS_key]['conf'];
422 $content='';
423 include($EXTiS_config[$EXTiS_key]['file']);
424 echo $content; // The script MAY return content in $content or the script may just output the result directly!
425 }
426 echo substr($EXTiS_cPart,35);
427 } else {
428 echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
429 }
430 }
431
432 $TT->pull();
433 } else {
434 echo $GLOBALS['TSFE']->content;
435 }
436 $TT->pull();
437 }
438
439
440 // ********************************
441 // Store session data for fe_users
442 // ********************************
443 $TSFE->storeSessionData();
444
445
446 // ***********
447 // Statistics
448 // ***********
449 $TYPO3_MISC['microtime_end'] = microtime();
450 $TSFE->setParseTime();
451 if ($TSFE->isOutputting() && ($TSFE->TYPO3_CONF_VARS['FE']['debug'] || $TSFE->config['config']['debug'])) {
452 echo '
453 <!-- Parsetime: '.$TSFE->scriptParseTime.' ms-->';
454 }
455 $TSFE->statistics();
456
457
458 // ***************
459 // Check JumpUrl
460 // ***************
461 $TSFE->jumpurl();
462
463
464 // *************
465 // Preview info
466 // *************
467 $TSFE->previewInfo();
468
469
470 // ******************
471 // Publishing static
472 // ******************
473 if (is_object($BE_USER)) {
474 if ($BE_USER->extAdmModuleEnabled('publish') && $BE_USER->extPublishList) {
475 include_once(PATH_tslib.'publish.php');
476 }
477 }
478
479
480 // ********************
481 // Finish timetracking
482 // ********************
483 $TT->pull();
484
485
486 // ******************
487 // beLoginLinkIPList
488 // ******************
489 echo $GLOBALS['TSFE']->beLoginLinkIPList();
490
491
492 // *************
493 // Admin panel
494 // *************
495 if (is_object($BE_USER)
496 && $GLOBALS['TSFE']->beUserLogin
497 && $GLOBALS['TSFE']->config['config']['admPanel']
498 && $BE_USER->extAdmEnabled
499 // && $BE_USER->extPageReadAccess($GLOBALS['TSFE']->page) // This is already done, if there is a BE_USER object at this point!
500 && !$BE_USER->extAdminConfig['hide']) {
501 echo $BE_USER->extPrintFeAdminDialog();
502 }
503
504
505 // *************
506 // Debugging Output
507 // *************
508 if(@is_callable(array($error,'debugOutput'))) {
509 $error->debugOutput();
510 }
511
512
513 // *************
514 // Compressions
515 // *************
516 if ($TYPO3_CONF_VARS['FE']['compressionLevel']) {
517 new gzip_encode($TYPO3_CONF_VARS['FE']['compressionLevel'], false, $GLOBALS['TYPO3_CONF_VARS']['FE']['compressionDebugInfo']);
518 }
519
520 ?>