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