[TASK] inline BEUserAuth::getCookieName
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / index_ts.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2013 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 text file 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 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36 define('TYPO3_MODE', 'FE');
37
38 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
39 ->startOutputBuffering()
40 ->loadConfigurationAndInitialize()
41 ->loadTypo3LoadedExtAndExtLocalconf(TRUE)
42 ->applyAdditionalConfigurationSettings();
43
44 // Timetracking started
45 $configuredCookieName = trim($GLOBALS['TYPO3_CONF_VARS']['BE']['cookieName']);
46 if (empty($configuredCookieName)) {
47 $configuredCookieName = 'be_typo_user';
48 }
49 if ($_COOKIE[$configuredCookieName]) {
50 $TT = new \TYPO3\CMS\Core\TimeTracker\TimeTracker();
51 } else {
52 $TT = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker();
53 }
54
55 $TT->start();
56
57 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->initializeTypo3DbGlobal();
58 // Hook to preprocess the current request:
59 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'])) {
60 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/index_ts.php']['preprocessRequest'] as $hookFunction) {
61 $hookParameters = array();
62 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $hookParameters);
63 }
64 unset($hookFunction);
65 unset($hookParameters);
66 }
67 // Look for extension ID which will launch alternative output engine
68 if ($temp_extId = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('eID')) {
69 if ($classPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($TYPO3_CONF_VARS['FE']['eID_include'][$temp_extId])) {
70 // Remove any output produced until now
71 ob_clean();
72 require $classPath;
73 }
74 die;
75 }
76
77 /** @var $TSFE \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
78 $TSFE = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
79 'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController',
80 $TYPO3_CONF_VARS,
81 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id'),
82 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('type'),
83 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('no_cache'),
84 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cHash'),
85 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('jumpurl'),
86 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('MP'),
87 \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RDCT')
88 );
89
90 if ($TYPO3_CONF_VARS['FE']['pageUnavailable_force']
91 && !\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(
92 \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'),
93 $TYPO3_CONF_VARS['SYS']['devIPmask'])
94 ) {
95 $TSFE->pageUnavailableAndExit('This page is temporarily unavailable.');
96 }
97
98 $TSFE->connectToDB();
99 $TSFE->sendRedirect();
100
101 // Output compression
102 // Remove any output produced until now
103 ob_clean();
104 if ($TYPO3_CONF_VARS['FE']['compressionLevel'] && extension_loaded('zlib')) {
105 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($TYPO3_CONF_VARS['FE']['compressionLevel'])) {
106 // Prevent errors if ini_set() is unavailable (safe mode)
107 @ini_set('zlib.output_compression_level', $TYPO3_CONF_VARS['FE']['compressionLevel']);
108 }
109 ob_start(array(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Utility\\CompressionUtility'), 'compressionOutputHandler'));
110 }
111
112 // FE_USER
113 $TT->push('Front End user initialized', '');
114 /** @var $TSFE \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
115 $TSFE->initFEuser();
116 $TT->pull();
117
118 // BE_USER
119 /** @var $BE_USER \TYPO3\CMS\Backend\FrontendBackendUserAuthentication */
120 $BE_USER = $TSFE->initializeBackendUser();
121
122 // Process the ID, type and other parameters
123 // After this point we have an array, $page in TSFE, which is the page-record of the current page, $id
124 $TT->push('Process ID', '');
125 // Initialize admin panel since simulation settings are required here:
126 if ($TSFE->isBackendUserLoggedIn()) {
127 $BE_USER->initializeAdminPanel();
128 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadExtensionTables(TRUE);
129 } else {
130 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->loadCachedTca();
131 }
132 $TSFE->checkAlternativeIdMethods();
133 $TSFE->clear_preview();
134 $TSFE->determineId();
135 // Now, if there is a backend user logged in and he has NO access to this page, then re-evaluate the id shown!
136 if ($TSFE->isBackendUserLoggedIn() && (!$BE_USER->extPageReadAccess($TSFE->page) || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_noBeUser'))) {
137 // \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_noBeUser') is placed here because
138 // \TYPO3\CMS\Version\Hook\PreviewHook might need to know if a backend user is logged in!
139 // Remove user
140 unset($BE_USER);
141 $TSFE->beUserLogin = 0;
142 // Re-evaluate the page-id.
143 $TSFE->checkAlternativeIdMethods();
144 $TSFE->clear_preview();
145 $TSFE->determineId();
146 }
147 $TSFE->makeCacheHash();
148 $TT->pull();
149
150 // Admin Panel & Frontend editing
151 if ($TSFE->isBackendUserLoggedIn()) {
152 $BE_USER->initializeFrontendEdit();
153 if ($BE_USER->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
154 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
155 ->initializeLanguageObject()
156 ->initializeSpriteManager();
157 }
158 if ($BE_USER->frontendEdit instanceof \TYPO3\CMS\Core\FrontendEditing\FrontendEditingController) {
159 $BE_USER->frontendEdit->initConfigOptions();
160 }
161 }
162
163 // Starts the template
164 $TT->push('Start Template', '');
165 $TSFE->initTemplate();
166 $TT->pull();
167 // Get from cache
168 $TT->push('Get Page from cache', '');
169 $TSFE->getFromCache();
170 $TT->pull();
171 // Get config if not already gotten
172 // After this, we should have a valid config-array ready
173 $TSFE->getConfigArray();
174 // Setting language and locale
175 $TT->push('Setting language and locale', '');
176 $TSFE->settingLanguage();
177 $TSFE->settingLocale();
178 $TT->pull();
179 // Convert POST data to internal "renderCharset" if different from the metaCharset
180 $TSFE->convPOSTCharset();
181 // Check JumpUrl
182 $TSFE->setExternalJumpUrl();
183 $TSFE->checkJumpUrlReferer();
184
185 $TSFE->handleDataSubmission();
186
187 // Check for shortcut page and redirect
188 $TSFE->checkPageForShortcutRedirect();
189
190 // Generate page
191 $TSFE->setUrlIdToken();
192 $TT->push('Page generation', '');
193 if ($TSFE->isGeneratePage()) {
194 $TSFE->generatePage_preProcessing();
195 $temp_theScript = $TSFE->generatePage_whichScript();
196 if ($temp_theScript) {
197 include $temp_theScript;
198 } else {
199 \TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
200 // Global content object
201 $TSFE->newCObj();
202 // LIBRARY INCLUSION, TypoScript
203 $temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
204 foreach ($temp_incFiles as $temp_file) {
205 include_once './' . $temp_file;
206 }
207 // Content generation
208 if (!$TSFE->isINTincScript()) {
209 \TYPO3\CMS\Frontend\Page\PageGenerator::renderContent();
210 $TSFE->setAbsRefPrefix();
211 }
212 }
213 $TSFE->generatePage_postProcessing();
214 } elseif ($TSFE->isINTincScript()) {
215 \TYPO3\CMS\Frontend\Page\PageGenerator::pagegenInit();
216 // Global content object
217 $TSFE->newCObj();
218 // LIBRARY INCLUSION, TypoScript
219 $temp_incFiles = \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles();
220 foreach ($temp_incFiles as $temp_file) {
221 include_once './' . $temp_file;
222 }
223 }
224 $TT->pull();
225
226 // $TSFE->config['INTincScript']
227 if ($TSFE->isINTincScript()) {
228 $TT->push('Non-cached objects', '');
229 $TSFE->INTincScript();
230 $TT->pull();
231 }
232 // Output content
233 $sendTSFEContent = FALSE;
234 if ($TSFE->isOutputting()) {
235 $TT->push('Print Content', '');
236 $TSFE->processOutput();
237 $sendTSFEContent = TRUE;
238 $TT->pull();
239 }
240 // Store session data for fe_users
241 $TSFE->storeSessionData();
242 // Statistics
243 $TYPO3_MISC['microtime_end'] = microtime(TRUE);
244 $TSFE->setParseTime();
245 if ($TSFE->isOutputting() && (!empty($TSFE->TYPO3_CONF_VARS['FE']['debug']) || !empty($TSFE->config['config']['debug']))) {
246 $TSFE->content .= LF . '<!-- Parsetime: ' . $TSFE->scriptParseTime . 'ms -->';
247 }
248 // Check JumpUrl
249 $TSFE->jumpurl();
250 // Preview info
251 $TSFE->previewInfo();
252 // Hook for end-of-frontend
253 $TSFE->hook_eofe();
254 // Finish timetracking
255 $TT->pull();
256 // Check memory usage
257 \TYPO3\CMS\Core\Utility\MonitorUtility::peakMemoryUsage();
258 // beLoginLinkIPList
259 echo $TSFE->beLoginLinkIPList();
260
261 // Admin panel
262 if (
263 $TSFE->isBackendUserLoggedIn()
264 && $BE_USER instanceof \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
265 && $BE_USER->isAdminPanelVisible()
266 ) {
267 $TSFE->content = str_ireplace('</head>', $BE_USER->adminPanel->getAdminPanelHeaderData() . '</head>', $TSFE->content);
268 $TSFE->content = str_ireplace('</body>', $BE_USER->displayAdminPanel() . '</body>', $TSFE->content);
269 }
270
271 if ($sendTSFEContent) {
272 echo $TSFE->content;
273 }
274 // Debugging Output
275 if (isset($error) && is_object($error) && @is_callable(array($error, 'debugOutput'))) {
276 $error->debugOutput();
277 }
278 if (TYPO3_DLOG) {
279 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('END of FRONTEND session', 'cms', 0, array('_FLUSH' => TRUE));
280 }
281 \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->shutdown();