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