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