[BUGFIX] Core calls deprecated ADMCMD_preview()
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * @package TYPO3
37 * @subpackage tslib
38 */
39
40 // *******************************
41 // Checking PHP version
42 // *******************************
43 if (version_compare(phpversion(), '5.3', '<')) die ('TYPO3 requires PHP 5.3.0 or higher.');
44
45 // *******************************
46 // Set error reporting
47 // *******************************
48 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
49
50
51 // ******************
52 // Constants defined
53 // ******************
54 $TYPO3_MISC['microtime_start'] = microtime(TRUE);
55 define('TYPO3_OS', stristr(PHP_OS,'win')&&!stristr(PHP_OS,'darwin')?'WIN':'');
56 define('TYPO3_MODE','FE');
57
58 if(!defined('PATH_thisScript')) {
59 define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
60 (PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
61 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
62 ($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
63 ($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
64 }
65
66 if (!defined('PATH_site')) define('PATH_site', dirname(PATH_thisScript).'/');
67 if (!defined('PATH_t3lib')) define('PATH_t3lib', PATH_site.'t3lib/');
68
69 define('TYPO3_mainDir', 'typo3/'); // This is the directory of the backend administration for the sites of this TYPO3 installation.
70 define('PATH_typo3', PATH_site.TYPO3_mainDir);
71 define('PATH_typo3conf', PATH_site.'typo3conf/');
72
73 if (!defined('PATH_tslib')) {
74 if (@is_dir(PATH_site.TYPO3_mainDir.'sysext/cms/tslib/')) {
75 define('PATH_tslib', PATH_site.TYPO3_mainDir.'sysext/cms/tslib/');
76 } elseif (@is_dir(PATH_site.'tslib/')) {
77 define('PATH_tslib', PATH_site.'tslib/');
78 }
79 }
80
81 if (!@is_dir(PATH_typo3conf)) die('Cannot find configuration. This file is probably executed from the wrong location.');
82
83 // *********************
84 // Unset variable(s) in global scope (fixes #13959)
85 // *********************
86 unset($error);
87
88 // *********************
89 // Prevent any output until AJAX/compression is initialized to stop
90 // AJAX/compression data corruption
91 // *********************
92 ob_start();
93
94
95 // *********************
96 // Mandatory libraries included
97 // *********************
98 require_once(PATH_t3lib . 'class.t3lib_div.php');
99 require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
100
101
102 // **********************
103 // Include configuration
104 // **********************
105 require(PATH_t3lib.'config_default.php');
106 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.
107 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.');
108
109 if (!defined('PATH_tslib')) {
110 define('PATH_tslib', t3lib_extMgm::extPath('cms').'tslib/');
111 }
112
113
114 // *********************
115 // Timetracking started
116 // *********************
117 if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {
118 require_once(PATH_t3lib . 'class.t3lib_timetrack.php');
119 $TT = new t3lib_timeTrack();
120 } else {
121 require_once(PATH_t3lib . 'class.t3lib_timetracknull.php');
122 $TT = new t3lib_timeTrackNull();
123 }
124 $TT->start();
125 $TT->push('', 'Script start');
126
127 // *********************
128 // Error & Exception handling
129 // *********************
130 if ($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
131 $TT->push('Register Exceptionhandler', '');
132 if ($TYPO3_CONF_VARS['SYS']['errorHandler'] !== '') {
133 // register an error handler for the given errorHandlerErrors
134 $errorHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SYS']['errorHandler'], $TYPO3_CONF_VARS['SYS']['errorHandlerErrors']);
135 // set errors which will be converted in an exception
136 $errorHandler->setExceptionalErrors($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionalErrors']);
137 }
138 $exceptionHandler = t3lib_div::makeInstance($TYPO3_CONF_VARS['SC_OPTIONS']['errors']['exceptionHandler']);
139 $TT->pull();
140 }
141
142 $TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
143 $TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
144
145 $CLIENT = t3lib_div::clientInfo(); // Set to the browser: net / msie if 4+ browsers
146 $TT->pull();
147
148 // *******************************
149 // Checking environment
150 // *******************************
151 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
152 throw new Exception('You cannot set the GLOBALS-array from outside the script.', 1294585200);
153 }
154 if (!get_magic_quotes_gpc()) {
155 $TT->push('Add slashes to GET/POST arrays','');
156 t3lib_div::addSlashesOnArray($_GET);
157 t3lib_div::addSlashesOnArray($_POST);
158 $HTTP_GET_VARS = $_GET;
159 $HTTP_POST_VARS = $_POST;
160 $TT->pull();
161 }
162
163
164 // Hook to preprocess the current request:
165 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
166 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
167 $hookParameters = array();
168 t3lib_div::callUserFunction($hookFunction, $hookParameters, $hookParameters);
169 }
170 unset($hookFunction);
171 unset($hookParameters);
172 }
173
174
175 // *********************
176 // Look for extension ID which will launch alternative output engine
177 // *********************
178 if ($temp_extId = t3lib_div::_GP('eID')) {
179 if ($classPath = t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
180 // Remove any output produced until now
181 ob_clean();
182
183 require($classPath);
184 }
185 exit;
186 }
187
188
189 // ***********************************
190 // Create $TSFE object (TSFE = TypoScript Front End)
191 // Connecting to database
192 // ***********************************
193 $TSFE = t3lib_div::makeInstance('tslib_fe',
194 $TYPO3_CONF_VARS,
195 t3lib_div::_GP('id'),
196 t3lib_div::_GP('type'),
197 t3lib_div::_GP('no_cache'),
198 t3lib_div::_GP('cHash'),
199 t3lib_div::_GP('jumpurl'),
200 t3lib_div::_GP('MP'),
201 t3lib_div::_GP('RDCT')
202 );
203 /** @var $TSFE tslib_fe */
204
205 if($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
206 !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
207 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
208 }
209
210
211 $TSFE->connectToDB();
212
213 $TSFE->sendRedirect();
214
215
216 // *******************
217 // Output compression
218 // *******************
219 // Remove any output produced until now
220 ob_clean();
221 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
222 if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
223 // Prevent errors if ini_set() is unavailable (safe mode)
224 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
225 }
226 ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
227 }
228
229 // *********
230 // FE_USER
231 // *********
232 $TT->push('Front End user initialized','');
233 /* @var $TSFE tslib_fe */
234 $TSFE->initFEuser();
235 $TT->pull();
236
237
238 // *********
239 // BE_USER
240 // *********
241 /** @var $BE_USER t3lib_tsfeBeUserAuth */
242 $BE_USER = $TSFE->initializeBackendUser();
243
244
245 // ********************
246 // Workspace preview:
247 // ********************
248 $TSFE->workspacePreviewInit();
249
250
251 // *****************************************
252 // Process the ID, type and other parameters
253 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
254 // *****************************************
255 $TT->push('Process ID','');
256 // Initialize admin panel since simulation settings are required here:
257 if ($TSFE->isBackendUserLoggedIn()) {
258 $BE_USER->initializeAdminPanel();
259 }
260
261 $TSFE->checkAlternativeIdMethods();
262 $TSFE->clear_preview();
263 $TSFE->determineId();
264
265 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
266 if ($TSFE->isBackendUserLoggedIn() && (!$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!
267
268 // Remove user
269 unset($BE_USER);
270 $TSFE->beUserLogin = 0;
271
272 // Re-evaluate the page-id.
273 $TSFE->checkAlternativeIdMethods();
274 $TSFE->clear_preview();
275 $TSFE->determineId();
276 }
277 $TSFE->makeCacheHash();
278 $TT->pull();
279
280 // *****************************************
281 // Admin Panel & Frontend editing
282 // *****************************************
283 if ($TSFE->isBackendUserLoggedIn()) {
284 // if a BE User is present load, the sprite manager for frontend-editing
285 $spriteManager = t3lib_div::makeInstance('t3lib_SpriteManager', FALSE);
286 $spriteManager->loadCacheFile();
287
288 $BE_USER->initializeFrontendEdit();
289 if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
290 $LANG = t3lib_div::makeInstance('language');
291 $LANG->init($BE_USER->uc['lang']);
292 }
293 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
294 $BE_USER->frontendEdit->initConfigOptions();
295 }
296 }
297
298 // *******************************************
299 // Get compressed $TCA-Array();
300 // After this, we should now have a valid $TCA, though minimized
301 // *******************************************
302 $TSFE->getCompressedTCarray();
303
304
305 // ********************************
306 // Starts the template
307 // *******************************
308 $TT->push('Start Template','');
309 $TSFE->initTemplate();
310 $TT->pull();
311
312
313 // ********************************
314 // Get from cache
315 // *******************************
316 $TT->push('Get Page from cache','');
317 $TSFE->getFromCache();
318 $TT->pull();
319
320
321 // ******************************************************
322 // Get config if not already gotten
323 // After this, we should have a valid config-array ready
324 // ******************************************************
325 $TSFE->getConfigArray();
326
327 // ********************************
328 // Convert POST data to internal "renderCharset" if different from the metaCharset
329 // *******************************
330 $TSFE->convPOSTCharset();
331
332
333 // *******************************************
334 // Setting language and locale
335 // *******************************************
336 $TT->push('Setting language and locale','');
337 $TSFE->settingLanguage();
338 $TSFE->settingLocale();
339 $TT->pull();
340
341
342 // ********************************
343 // Check JumpUrl
344 // *******************************
345 $TSFE->setExternalJumpUrl();
346 $TSFE->checkJumpUrlReferer();
347
348
349 // ********************************
350 // Check Submission of data.
351 // This is done at this point, because we need the config values
352 // *******************************
353 switch($TSFE->checkDataSubmission()) {
354 case 'email':
355 $TSFE->sendFormmail();
356 break;
357 case 'fe_tce':
358 $TSFE->includeTCA();
359 $TT->push('fe_tce','');
360 $TSFE->fe_tce();
361 $TT->pull();
362 break;
363 }
364
365
366 // *******************************
367 // Check for shortcut page and redirect
368 // *******************************
369 $TSFE->checkPageForShortcutRedirect();
370
371
372 // ********************************
373 // Generate page
374 // *******************************
375 $TSFE->setUrlIdToken();
376
377 $TT->push('Page generation','');
378 if ($TSFE->isGeneratePage()) {
379 $TSFE->generatePage_preProcessing();
380 $temp_theScript=$TSFE->generatePage_whichScript();
381
382 if ($temp_theScript) {
383 include($temp_theScript);
384 } else {
385 include(PATH_tslib.'pagegen.php');
386 }
387 $TSFE->generatePage_postProcessing();
388 } elseif ($TSFE->isINTincScript()) {
389 include(PATH_tslib.'pagegen.php');
390 }
391 $TT->pull();
392
393
394 // ********************************
395 // $TSFE->config['INTincScript']
396 // *******************************
397 if ($TSFE->isINTincScript()) {
398 $TT->push('Non-cached objects','');
399 $TSFE->INTincScript();
400 $TT->pull();
401 }
402
403 // ***************
404 // Output content
405 // ***************
406 $sendTSFEContent = FALSE;
407 if ($TSFE->isOutputting()) {
408 $TT->push('Print Content','');
409 $TSFE->processOutput();
410
411 // ***************************************
412 // Outputs content / Includes EXT scripts
413 // ***************************************
414 if ($TSFE->isEXTincScript()) {
415 $TT->push('External PHP-script','');
416 // Important global variables here are $EXTiS_*, they must not be overridden in include-scripts!!!
417 $EXTiS_config = $TSFE->config['EXTincScript'];
418 $EXTiS_splitC = explode('<!--EXT_SCRIPT.',$TSFE->content); // Splits content with the key
419
420 // Special feature: Include libraries
421 foreach ($EXTiS_config as $EXTiS_cPart) {
422 if (isset($EXTiS_cPart['conf']['includeLibs']) && $EXTiS_cPart['conf']['includeLibs']) {
423 $EXTiS_resourceList = t3lib_div::trimExplode(',',$EXTiS_cPart['conf']['includeLibs'], TRUE);
424 $TSFE->includeLibraries($EXTiS_resourceList);
425 }
426 }
427
428 foreach ($EXTiS_splitC as $EXTiS_c => $EXTiS_cPart) {
429 if (substr($EXTiS_cPart,32,3)=='-->') { // If the split had a comment-end after 32 characters it's probably a split-string
430 $EXTiS_key = 'EXT_SCRIPT.'.substr($EXTiS_cPart,0,32);
431 if (is_array($EXTiS_config[$EXTiS_key])) {
432 $REC = $EXTiS_config[$EXTiS_key]['data'];
433 $CONF = $EXTiS_config[$EXTiS_key]['conf'];
434 $content = '';
435 include($EXTiS_config[$EXTiS_key]['file']);
436 echo $content; // The script MAY return content in $content or the script may just output the result directly!
437 }
438 echo substr($EXTiS_cPart,35);
439 } else {
440 echo ($c?'<!--EXT_SCRIPT.':'').$EXTiS_cPart;
441 }
442 }
443
444 $TT->pull();
445 } else {
446 $sendTSFEContent = TRUE;
447 }
448 $TT->pull();
449 }
450
451
452 // ********************************
453 // Store session data for fe_users
454 // ********************************
455 $TSFE->storeSessionData();
456
457
458 // ***********
459 // Statistics
460 // ***********
461 $TYPO3_MISC['microtime_end'] = microtime(TRUE);
462 $TSFE->setParseTime();
463 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
464 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
465 }
466 $TSFE->statistics();
467
468
469 // ***************
470 // Check JumpUrl
471 // ***************
472 $TSFE->jumpurl();
473
474
475 // *************
476 // Preview info
477 // *************
478 $TSFE->previewInfo();
479
480
481 // ******************
482 // Hook for end-of-frontend
483 // ******************
484 $TSFE->hook_eofe();
485
486
487 // ********************
488 // Finish timetracking
489 // ********************
490 $TT->pull();
491
492 // ******************
493 // Check memory usage
494 // ******************
495 t3lib_utility_Monitor::peakMemoryUsage();
496
497 // ******************
498 // beLoginLinkIPList
499 // ******************
500 echo $TSFE->beLoginLinkIPList();
501
502
503 // *************
504 // Admin panel
505 // *************
506 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->isBackendUserLoggedIn()) {
507 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
508 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
509 }
510
511 if ($sendTSFEContent) {
512 echo $TSFE->content;
513 }
514
515 // *************
516 // Debugging Output
517 // *************
518 if(isset($error) && is_object($error) && @is_callable(array($error,'debugOutput'))) {
519 $error->debugOutput();
520 }
521 if (TYPO3_DLOG) {
522 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
523 }
524
525 ?>