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