41e22ec294bf0d9412c1f396b769edb0306fe126
[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 /**
29 * This is the MAIN DOCUMENT of the TypoScript driven standard front-end (from the "cms" extension)
30 * Basically put this is the "index.php" script which all requests for TYPO3 delivered pages goes to in the frontend (the website)
31 * 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.
32 * All the real data processing goes on in the "tslib/" classes which this script will include and use as needed.
33 *
34 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 * @package TYPO3
38 * @subpackage tslib
39 */
40
41 // Constants defined
42 define('TYPO3_MODE', 'FE');
43
44 // Prevent any output until AJAX/compression is initialized to stop
45 // AJAX/compression data corruption
46 ob_start();
47
48 Typo3_Bootstrap_Backend::getInstance()->loadDefaultTypo3ConfVars()
49 ->registerExtDirectComponents()
50 ->initializeGlobalVariables()
51 ->checkLocalconfExistsOrDie()
52 ->setGlobalDatabaseVariablesToEmptyString()
53 ->loadMainConfigurationFile()
54 ->defineTypo3DatabaseConstants()
55 ->initializeCachingFramework()
56 ->registerAutoloader()
57 ->addCorePearPathToIncludePath()
58 ->checkUtf8DatabaseSettingsOrDie()
59 ->transferDeprecatedCurlSettings()
60 ->setCacheHashOptions()
61 ->enforceCorrectProxyAuthScheme()
62 ->setDefaultTimezone()
63 ->initializeL10nLocales()
64 ->configureImageProcessingOptions()
65 ->convertPageNotFoundHandlingToBoolean()
66 ->registerGlobalDebugFunctions()
67 ->registerSwiftMailer()
68 ->configureExceptionHandling()
69 ->setMemoryLimit()
70 ->defineTypo3RequestTypes()
71 ->loadAdditionalConfigurationFromExtensions()
72 ->deprecationLogForOldXclassRegistration()
73 ->initializeExceptionHandling()
74 ->requireAdditionalExtensionFiles()
75 ->setFinalCachingFrameworkCacheConfiguration()
76 ->defineLoggingAndExceptionConstants()
77 ->unsetReservedGlobalVariables()
78 ->initializeGlobalTimeVariables();
79
80 if (!t3lib_extMgm::isLoaded('cms')) {
81 die('<strong>Error:</strong> The main frontend extension "cms" was not loaded. Enable it in the extension manager in the backend.');
82 }
83
84 // Timetracking started
85 if ($_COOKIE[t3lib_beUserAuth::getCookieName()]) {
86 require_once(PATH_t3lib . 'class.t3lib_timetrack.php');
87 $TT = new t3lib_timeTrack();
88 } else {
89 require_once(PATH_t3lib . 'class.t3lib_timetracknull.php');
90 $TT = new t3lib_timeTrackNull();
91 }
92 $TT->start();
93
94 Typo3_Bootstrap_Backend::getInstance()->initializeTypo3DbGlobal(FALSE);
95
96 // Hook to preprocess the current request:
97 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
98 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
99 $hookParameters = array();
100 t3lib_div::callUserFunction($hookFunction, $hookParameters, $hookParameters);
101 }
102 unset($hookFunction);
103 unset($hookParameters);
104 }
105
106 // Look for extension ID which will launch alternative output engine
107 if ($temp_extId = t3lib_div::_GP('eID')) {
108 if ($classPath = t3lib_div::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
109 // Remove any output produced until now
110 ob_clean();
111
112 require($classPath);
113 }
114 exit;
115 }
116
117 // Create $TSFE object (TSFE = TypoScript Front End)
118 // Connecting to database
119 /** @var $TSFE tslib_fe */
120 $TSFE = t3lib_div::makeInstance('tslib_fe',
121 $TYPO3_CONF_VARS,
122 t3lib_div::_GP('id'),
123 t3lib_div::_GP('type'),
124 t3lib_div::_GP('no_cache'),
125 t3lib_div::_GP('cHash'),
126 t3lib_div::_GP('jumpurl'),
127 t3lib_div::_GP('MP'),
128 t3lib_div::_GP('RDCT')
129 );
130
131
132 if ($TYPO3_CONF_VARS['FE']['pageUnavailable_force'] &&
133 !t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $TYPO3_CONF_VARS['SYS']['devIPmask'])) {
134 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
135 }
136
137 $TSFE->connectToDB();
138 $TSFE->sendRedirect();
139
140 // Output compression
141 // Remove any output produced until now
142 ob_clean();
143 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
144 if (t3lib_utility_Math::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
145 // Prevent errors if ini_set() is unavailable (safe mode)
146 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
147 }
148 ob_start(array(t3lib_div::makeInstance('tslib_fecompression'), 'compressionOutputHandler'));
149 }
150
151 // FE_USER
152 $TT->push('Front End user initialized', '');
153 /** @var $TSFE tslib_fe */
154 $TSFE->initFEuser();
155 $TT->pull();
156
157 // BE_USER
158 /** @var $BE_USER t3lib_tsfeBeUserAuth */
159 $BE_USER = $TSFE->initializeBackendUser();
160
161 // Process the ID, type and other parameters
162 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
163 $TT->push('Process ID', '');
164 // Initialize admin panel since simulation settings are required here:
165 if ($TSFE->isBackendUserLoggedIn()) {
166 $BE_USER->initializeAdminPanel();
167 }
168
169 $TSFE->checkAlternativeIdMethods();
170 $TSFE->clear_preview();
171 $TSFE->determineId();
172
173 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
174 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!
175
176 // Remove user
177 unset($BE_USER);
178 $TSFE->beUserLogin = 0;
179
180 // Re-evaluate the page-id.
181 $TSFE->checkAlternativeIdMethods();
182 $TSFE->clear_preview();
183 $TSFE->determineId();
184 }
185 $TSFE->makeCacheHash();
186 $TT->pull();
187
188 // Admin Panel & Frontend editing
189 if ($TSFE->isBackendUserLoggedIn()) {
190 Typo3_Bootstrap_Backend::getInstance()->initializeSpriteManager(FALSE);
191
192 $BE_USER->initializeFrontendEdit();
193 if ($BE_USER->adminPanel instanceof tslib_AdminPanel) {
194 Typo3_Bootstrap_Backend::getInstance()->initializeLanguageObject();
195 }
196 if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
197 $BE_USER->frontendEdit->initConfigOptions();
198 }
199 }
200
201 // Get compressed $TCA-Array();
202 // After this, we should now have a valid $TCA, though minimized
203 $TSFE->getCompressedTCarray();
204
205 // Starts the template
206 $TT->push('Start Template', '');
207 $TSFE->initTemplate();
208 $TT->pull();
209
210 // Get from cache
211 $TT->push('Get Page from cache', '');
212 $TSFE->getFromCache();
213 $TT->pull();
214
215 // Get config if not already gotten
216 // After this, we should have a valid config-array ready
217 $TSFE->getConfigArray();
218
219 // Convert POST data to internal "renderCharset" if different from the metaCharset
220 $TSFE->convPOSTCharset();
221
222 // Setting language and locale
223 $TT->push('Setting language and locale', '');
224 $TSFE->settingLanguage();
225 $TSFE->settingLocale();
226 $TT->pull();
227
228 // Check JumpUrl
229 $TSFE->setExternalJumpUrl();
230 $TSFE->checkJumpUrlReferer();
231
232 // Check Submission of data.
233 // This is done at this point, because we need the config values
234 switch ($TSFE->checkDataSubmission()) {
235 case 'email':
236 $TSFE->sendFormmail();
237 break;
238 }
239
240 // Check for shortcut page and redirect
241 $TSFE->checkPageForShortcutRedirect();
242
243 // Generate page
244 $TSFE->setUrlIdToken();
245
246 $TT->push('Page generation', '');
247 if ($TSFE->isGeneratePage()) {
248 $TSFE->generatePage_preProcessing();
249 $temp_theScript=$TSFE->generatePage_whichScript();
250
251 if ($temp_theScript) {
252 include($temp_theScript);
253 } else {
254 include(PATH_tslib.'pagegen.php');
255 }
256 $TSFE->generatePage_postProcessing();
257 } elseif ($TSFE->isINTincScript()) {
258 include(PATH_tslib.'pagegen.php');
259 }
260 $TT->pull();
261
262 // $TSFE->config['INTincScript']
263 if ($TSFE->isINTincScript()) {
264 $TT->push('Non-cached objects', '');
265 $TSFE->INTincScript();
266 $TT->pull();
267 }
268
269 // Output content
270 $sendTSFEContent = FALSE;
271 if ($TSFE->isOutputting()) {
272 $TT->push('Print Content', '');
273 $TSFE->processOutput();
274 $sendTSFEContent = TRUE;
275 $TT->pull();
276 }
277
278 // Store session data for fe_users
279 $TSFE->storeSessionData();
280
281 // Statistics
282 $TYPO3_MISC['microtime_end'] = microtime(TRUE);
283 $TSFE->setParseTime();
284 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
285 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
286 }
287 $TSFE->statistics();
288
289 // Check JumpUrl
290 $TSFE->jumpurl();
291
292 // Preview info
293 $TSFE->previewInfo();
294
295 // Hook for end-of-frontend
296 $TSFE->hook_eofe();
297
298 // Finish timetracking
299 $TT->pull();
300
301 // Check memory usage
302 t3lib_utility_Monitor::peakMemoryUsage();
303
304 // beLoginLinkIPList
305 echo $TSFE->beLoginLinkIPList();
306
307 // Admin panel
308 if (is_object($BE_USER) && $BE_USER->isAdminPanelVisible() && $TSFE->isBackendUserLoggedIn()) {
309 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
310 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
311 }
312
313 if ($sendTSFEContent) {
314 echo $TSFE->content;
315 }
316
317 // Debugging Output
318 if (isset($error) && is_object($error) && @is_callable(array($error, 'debugOutput'))) {
319 $error->debugOutput();
320 }
321 if (TYPO3_DLOG) {
322 t3lib_div::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
323 }
324
325 Typo3_Bootstrap_Backend::getInstance()->shutdown();
326
327 ?>