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