Added feature #10155: Add controller switching for frontend editing
[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 // Create $TSFE object (TSFE = TypoScript Front End)
155 // Connecting to database
156 // ***********************************
157 $temp_TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
158 /* @var $TSFE tslib_fe */
159 $TSFE = new $temp_TSFEclassName(
160 $TYPO3_CONF_VARS,
161 t3lib_div::_GP('id'),
162 t3lib_div::_GP('type'),
163 t3lib_div::_GP('no_cache'),
164 t3lib_div::_GP('cHash'),
165 t3lib_div::_GP('jumpurl'),
166 t3lib_div::_GP('MP'),
167 t3lib_div::_GP('RDCT')
168 );
169
170 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
171 !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
172 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
173 }
174
175
176 $TSFE->connectToDB();
177
178 // In case of a keyword-authenticated preview, re-initialize the TSFE object:
179 if ($temp_previewConfig = $TSFE->ADMCMD_preview()) {
180 $TSFE = new $temp_TSFEclassName(
181 $TYPO3_CONF_VARS,
182 t3lib_div::_GP('id'),
183 t3lib_div::_GP('type'),
184 t3lib_div::_GP('no_cache'),
185 t3lib_div::_GP('cHash'),
186 t3lib_div::_GP('jumpurl'),
187 t3lib_div::_GP('MP'),
188 t3lib_div::_GP('RDCT')
189 );
190 $TSFE->ADMCMD_preview_postInit($temp_previewConfig);
191 }
192
193 if ($TSFE->RDCT) {$TSFE->sendRedirect();}
194
195
196 // *******************
197 // output compression
198 // *******************
199 if ($TYPO3_CONF_VARS['FE']['compressionLevel']) {
200 ob_start();
201 require_once(PATH_t3lib.'class.gzip_encode.php');
202 }
203
204 // *********
205 // FE_USER
206 // *********
207 $TT->push('Front End user initialized','');
208 /* @var $TSFE tslib_fe */
209 $TSFE->initFEuser();
210 $TT->pull();
211
212 // ****************
213 // PRE BE_USER HOOK
214 // ****************
215 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'])) {
216 foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preBeUser'] as $_funcRef) {
217 $_params = array();
218 t3lib_div::callUserFunction($_funcRef, $_params , $_params);
219 }
220 }
221
222
223 // *********
224 // BE_USER
225 // *********
226 $BE_USER='';
227 if ($_COOKIE['be_typo_user']) { // If the backend cookie is set, we proceed and checks if a backend user is logged in.
228 $TYPO3_MISC['microtime_BE_USER_start'] = microtime();
229 $TT->push('Back End user initialized','');
230 require_once (PATH_t3lib.'class.t3lib_befunc.php');
231 require_once (PATH_t3lib.'class.t3lib_userauthgroup.php');
232 require_once (PATH_t3lib.'class.t3lib_beuserauth.php');
233 require_once (PATH_t3lib.'class.t3lib_tsfebeuserauth.php');
234
235 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
236 $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
237 $BE_USER->OS = TYPO3_OS;
238 $BE_USER->lockIP = $TYPO3_CONF_VARS['BE']['lockIP'];
239 $BE_USER->start(); // Object is initialized
240 $BE_USER->unpack_uc('');
241 if ($BE_USER->user['uid']) {
242 $BE_USER->fetchGroupData();
243 $TSFE->beUserLogin = 1;
244 }
245 // Unset the user initialization.
246 if (!$BE_USER->checkLockToIP() || !$BE_USER->checkBackendAccessSettingsFromInitPhp() || !$BE_USER->user['uid']) {
247 $BE_USER='';
248 $TSFE->beUserLogin=0;
249 }
250 $TT->pull();
251 $TYPO3_MISC['microtime_BE_USER_end'] = microtime();
252 } elseif ($TSFE->ADMCMD_preview_BEUSER_uid) {
253 require_once (PATH_t3lib.'class.t3lib_befunc.php');
254 require_once (PATH_t3lib.'class.t3lib_userauthgroup.php');
255 require_once (PATH_t3lib.'class.t3lib_beuserauth.php');
256 require_once (PATH_t3lib.'class.t3lib_tsfebeuserauth.php');
257
258 // the value this->formfield_status is set to empty in order to disable login-attempts to the backend account through this script
259 $BE_USER = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth'); // New backend user object
260 $BE_USER->userTS_dontGetCached = 1;
261 $BE_USER->OS = TYPO3_OS;
262 $BE_USER->setBeUserByUid($TSFE->ADMCMD_preview_BEUSER_uid);
263 $BE_USER->unpack_uc('');
264 if ($BE_USER->user['uid']) {
265 $BE_USER->fetchGroupData();
266 $TSFE->beUserLogin = 1;
267 } else {
268 $BE_USER = '';
269 $TSFE->beUserLogin = 0;
270 }
271 }
272
273 // ********************
274 // Workspace preview:
275 // ********************
276 $TSFE->workspacePreviewInit();
277
278
279 // *****************************************
280 // Process the ID, type and other parameters
281 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
282 // *****************************************
283 $TT->push('Process ID','');
284 $TSFE->checkAlternativeIdMethods();
285 $TSFE->clear_preview();
286 $TSFE->determineId();
287
288 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
289 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!
290
291 // Remove user
292 unset($BE_USER);
293 $TSFE->beUserLogin = 0;
294
295 // Re-evaluate the page-id.
296 $TSFE->checkAlternativeIdMethods();
297 $TSFE->clear_preview();
298 $TSFE->determineId();
299 }
300 $TSFE->makeCacheHash();
301 $TT->pull();
302
303 // *******************************************
304 // Get compressed $TCA-Array();
305 // After this, we should now have a valid $TCA, though minimized
306 // *******************************************
307 $TSFE->getCompressedTCarray();
308
309
310 // ********************************
311 // Starts the template
312 // *******************************
313 $TT->push('Start Template','');
314 $TSFE->initTemplate();
315 $TT->pull();
316
317
318 // ********************************
319 // Get from cache
320 // *******************************
321 $TT->push('Get Page from cache','');
322 $TSFE->getFromCache();
323 $TT->pull();
324
325
326 // ******************************************************
327 // Get config if not already gotten
328 // After this, we should have a valid config-array ready
329 // ******************************************************
330 $TSFE->getConfigArray();
331
332 // *****************************************
333 // Frontend editing
334 // *****************************************
335 if ($TSFE->beUserLogin) {
336 $BE_USER->initializeFrontendEdit();
337 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
338 require_once(t3lib_extMgm::extPath('lang').'lang.php');
339 $LANG = t3lib_div::makeInstance('language');
340 $LANG->init($BE_USER->uc['lang']);
341
342 $BE_USER->frontendEdit->initConfigOptions();
343 }
344 }
345
346 // ********************************
347 // Convert POST data to internal "renderCharset" if different from the metaCharset
348 // *******************************
349 $TSFE->convPOSTCharset();
350
351
352 // *******************************************
353 // Setting language and locale
354 // *******************************************
355 $TT->push('Setting language and locale','');
356 $TSFE->settingLanguage();
357 $TSFE->settingLocale();
358 $TT->pull();
359
360
361 // ********************************
362 // Check JumpUrl
363 // *******************************
364 $TSFE->setExternalJumpUrl();
365 $TSFE->checkJumpUrlReferer();
366
367
368 // ********************************
369 // Check Submission of data.
370 // This is done at this point, because we need the config values
371 // *******************************
372 switch($TSFE->checkDataSubmission()) {
373 case 'email':
374 require_once(PATH_t3lib.'class.t3lib_htmlmail.php');
375 require_once(PATH_t3lib.'class.t3lib_formmail.php');
376 $TSFE->sendFormmail();
377 break;
378 case 'fe_tce':
379 require_once(PATH_tslib.'class.tslib_fetce.php');
380 $TSFE->includeTCA();
381 $TT->push('fe_tce','');
382 $TSFE->fe_tce();
383 $TT->pull();
384 break;
385 }
386
387
388 // ********************************
389 // Generate page
390 // *******************************
391 $TSFE->setUrlIdToken();
392
393 $TT->push('Page generation','');
394 if ($TSFE->doXHTML_cleaning()) {
395 require_once(PATH_t3lib.'class.t3lib_parsehtml.php');
396 }
397 if ($TSFE->isGeneratePage()) {
398 $TSFE->generatePage_preProcessing();
399 $temp_theScript=$TSFE->generatePage_whichScript();
400
401 if ($temp_theScript) {
402 include($temp_theScript);
403 } else {
404 require_once(PATH_tslib.'class.tslib_pagegen.php');
405 include(PATH_tslib.'pagegen.php');
406 }
407 $TSFE->generatePage_postProcessing();
408 } elseif ($TSFE->isINTincScript()) {
409 require_once(PATH_tslib.'class.tslib_pagegen.php');
410 include(PATH_tslib.'pagegen.php');
411 }
412 $TT->pull();
413
414
415 // ********************************
416 // $TSFE->config['INTincScript']
417 // *******************************
418 if ($TSFE->isINTincScript()) {
419 $TT->push('Non-cached objects','');
420 $TSFE->INTincScript();
421 $TT->pull();
422 }
423
424 // ***************
425 // Output content
426 // ***************
427 if ($TSFE->isOutputting()) {
428 $TT->push('Print Content','');
429 $TSFE->processOutput();
430
431 // ***************************************
432 // Outputs content / Includes EXT scripts
433 // ***************************************
434 if ($TSFE->isEXTincScript()) {
435 $TT->push('External PHP-script','');
436 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
437 $EXTiS_config = $TSFE->config['EXTincScript'];
438 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content); // Splits content with the key
439
440 // Special feature: Include libraries
441 reset($EXTiS_config);
442 while(list(,$EXTiS_cPart)=each($EXTiS_config)) {
443 if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
444 $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], true);
445 $TSFE->includeLibraries($EXTiS_resourceList);
446 }
447 }
448
449 reset($EXTiS_splitC);
450 while(list($EXTiS_c,$EXTiS_cPart)=each($EXTiS_splitC)) {
451 if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
452 $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
453 if (is_array($EXTiS_config[$EXTiS_key])) {
454 $REC = $EXTiS_config[$EXTiS_key]['data'];
455 $CONF = $EXTiS_config[$EXTiS_key]['conf'];
456 $content = '';
457 include($EXTiS_config[$EXTiS_key]['file']);
458 echo $content; // The script MAY return content in $content or the script may just output the result directly!
459 }
460 echo substr($EXTiS_cPart,35);
461 } else {
462 echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
463 }
464 }
465
466 $TT->pull();
467 } else {
468 echo $TSFE->content;
469 }
470 $TT->pull();
471 }
472
473
474 // ********************************
475 // Store session data for fe_users
476 // ********************************
477 $TSFE->storeSessionData();
478
479
480 // ***********
481 // Statistics
482 // ***********
483 $TYPO3_MISC['microtime_end'] = microtime();
484 $TSFE->setParseTime();
485 if ($TSFE->isOutputting() && ($TSFE->TYPO3_CONF_VARS['FE']['debug'] || $TSFE->config['config']['debug'])) {
486 echo '
487 <!-- Parsetime: '.$TSFE->scriptParseTime.' ms-->';
488 }
489 $TSFE->statistics();
490
491
492 // ***************
493 // Check JumpUrl
494 // ***************
495 $TSFE->jumpurl();
496
497
498 // *************
499 // Preview info
500 // *************
501 $TSFE->previewInfo();
502
503
504 // ******************
505 // Publishing static
506 // ******************
507 if (is_object($BE_USER) && ($BE_USER->frontendEdit instanceof t3lib_frontendedit)) {
508 if ($BE_USER->frontendEdit->isAdminModuleEnabled('publish') && $BE_USER->frontendEdit->getExtPublishList()) {
509 include_once(PATH_tslib.'publish.php');
510 }
511 }
512
513
514 // ******************
515 // Hook for end-of-frontend
516 // ******************
517 $TSFE->hook_eofe();
518
519
520 // ********************
521 // Finish timetracking
522 // ********************
523 $TT->pull();
524
525
526 // ******************
527 // beLoginLinkIPList
528 // ******************
529 echo $TSFE->beLoginLinkIPList();
530
531
532 // *************
533 // Admin panel
534 // *************
535 if (is_object($BE_USER) && $TSFE->beUserLogin && ($BE_USER->frontendEdit instanceof t3lib_frontendedit)) {
536 echo $BE_USER->frontendEdit->displayAdmin();
537 }
538
539 // *************
540 // Debugging Output
541 // *************
542 if(@is_callable(array($error,'debugOutput'))) {
543 $error->debugOutput();
544 }
545 if (TYPO3_DLOG) {
546 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
547 }
548
549
550 // *************
551 // Compressions
552 // *************
553 if ($TYPO3_CONF_VARS['FE']['compressionLevel']) {
554 new gzip_encode($TYPO3_CONF_VARS['FE']['compressionLevel'], false, $TYPO3_CONF_VARS['FE']['compressionDebugInfo']);
555 }
556
557 ?>