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