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