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