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