[BUGFIX] Fix the element browsers
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Core / Bootstrap.php
1 <?php
2 namespace TYPO3\CMS\Core\Core;
3
4 /**
5 * This class encapsulates bootstrap related methods.
6 * It is required directly as the very first thing in entry scripts and
7 * used to define all base things like constants and pathes and so on.
8 *
9 * Most methods in this class have dependencies to each other. They can
10 * not be called in arbitrary order. The methods are ordered top down, so
11 * a method at the beginning has lower dependencies than a method further
12 * down. Do not fiddle with the load order in own scripts except you know
13 * exactly what you are doing!
14 *
15 * @author Christian Kuhn <lolli@schwarzbu.ch>
16 * @package TYPO3
17 * @subpackage core
18 */
19 class Bootstrap {
20
21 /**
22 * @var \TYPO3\CMS\Core\Core\Bootstrap
23 */
24 static protected $instance = NULL;
25
26 /**
27 * Unique Request ID
28 *
29 * @var string
30 */
31 protected $requestId;
32
33 /**
34 * Disable direct creation of this object.
35 */
36 protected function __construct() {
37 $this->requestId = uniqid();
38 }
39
40 /**
41 * Disable direct cloning of this object.
42 */
43 protected function __clone() {
44
45 }
46
47 /**
48 * Return 'this' as singleton
49 *
50 * @return \TYPO3\CMS\Core\Core\Bootstrap
51 */
52 static public function getInstance() {
53 if (is_null(self::$instance)) {
54 self::$instance = new \TYPO3\CMS\Core\Core\Bootstrap();
55 }
56 return self::$instance;
57 }
58
59 /**
60 * Gets the request's unique ID
61 *
62 * @return string Unique request ID
63 */
64 public function getRequestId() {
65 return $this->requestId;
66 }
67
68 /**
69 * Prevent any unwanted output that may corrupt AJAX/compression.
70 * This does not interfere with "die()" or "echo"+"exit()" messages!
71 *
72 * @return \TYPO3\CMS\Core\Core\Bootstrap
73 */
74 public function startOutputBuffering() {
75 ob_start();
76 return $this;
77 }
78
79 /**
80 * Run the base setup that checks server environment,
81 * determines pathes, populates base files and sets common configuration.
82 *
83 * Script execution will be aborted if something fails here.
84 *
85 * @param string $relativePathPart Relative path of the entry script back to document root
86 * @return \TYPO3\CMS\Core\Core\Bootstrap
87 */
88 public function baseSetup($relativePathPart = '') {
89 \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run($relativePathPart);
90 return $this;
91 }
92
93 /**
94 * Throws an exception if no browser could be identified
95 *
96 * @return \TYPO3\CMS\Core\Core\Bootstrap
97 * @throws RuntimeException
98 */
99 public function checkValidBrowserOrDie() {
100 // Checks for proper browser
101 if (empty($GLOBALS['CLIENT']['BROWSER'])) {
102 throw new \RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
103 }
104 return $this;
105 }
106
107 /**
108 * Register default ExtDirect components
109 *
110 * @return \TYPO3\CMS\Core\Core\Bootstrap
111 */
112 public function registerExtDirectComponents() {
113 if (TYPO3_MODE === 'BE') {
114 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.Components.PageTree.DataProvider', PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeDataProvide', 'web', 'user,group');
115 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.Components.PageTree.Commands', PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:TYPO3\\CMS\\Backend\\Tree\\Pagetree\\ExtdirectTreeCommands', 'web', 'user,group');
116 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.Components.PageTree.ContextMenuDataProvider', PATH_t3lib . 'contextmenu/pagetree/extdirect/class.t3lib_contextmenu_pagetree_extdirect_contextmenu.php:TYPO3\\CMS\\Backend\\ContextMenu\\Pagetree\\Extdirect\\ContextMenuConfiguration', 'web', 'user,group');
117 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.LiveSearchActions.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_backendlivesearch.php:extDirect_DataProvider_BackendLiveSearch', 'web_list', 'user,group');
118 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.BackendUserSettings.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php:TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
119 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.CSH.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_contexthelp.php:TYPO3\\CMS\\ContextHelp\\ExtDirect\\ContextHelpDataProvider');
120 \TYPO3\CMS\Core\Extension\ExtensionManager::registerExtDirectComponent('TYPO3.ExtDirectStateProvider.ExtDirect', PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_state.php:TYPO3\\CMS\\Backend\\InterfaceState\\ExtDirect\\DataProvider');
121 }
122 return $this;
123 }
124
125 /**
126 * Populate the local configuration.
127 * Merge default TYPO3_CONF_VARS with content of typo3conf/LocalConfiguration.php,
128 * execute typo3conf/AdditionalConfiguration.php, define database related constants.
129 *
130 * @return \TYPO3\CMS\Core\Core\Bootstrap
131 */
132 public function populateLocalConfiguration() {
133 if (@is_file((PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCAL_CONFIGURATION_FILE))) {
134 $localConfiguration = \TYPO3\CMS\Core\Configuration\ConfigurationManager::getLocalConfiguration();
135 if (is_array($localConfiguration)) {
136 $GLOBALS['TYPO3_CONF_VARS'] = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($GLOBALS['TYPO3_CONF_VARS'], $localConfiguration);
137 } else {
138 die('LocalConfiguration invalid.');
139 }
140 if (@is_file((PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::ADDITIONAL_CONFIGURATION_FILE))) {
141 require PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::ADDITIONAL_CONFIGURATION_FILE;
142 }
143 define('TYPO3_db', $GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
144 define('TYPO3_db_username', $GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
145 define('TYPO3_db_password', $GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
146 define('TYPO3_db_host', $GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
147 define('TYPO3_extTableDef_script', $GLOBALS['TYPO3_CONF_VARS']['DB']['extTablesDefinitionScript']);
148 unset($GLOBALS['TYPO3_CONF_VARS']['DB']);
149 } elseif (@is_file((PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCALCONF_FILE))) {
150 // Legacy localconf.php handling
151 // @deprecated: Can be removed if old localconf.php is not supported anymore
152 global $TYPO3_CONF_VARS, $typo_db, $typo_db_username, $typo_db_password, $typo_db_host, $typo_db_extTableDef_script;
153 require PATH_site . \TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCALCONF_FILE;
154 // If the localconf.php was not upgraded to LocalConfiguration.php, the default extListArray
155 // from t3lib/stddb/DefaultConfiguration.php is still set. In this case we just unset
156 // this key here, so t3lib_extMgm::getLoadedExtensionListArray() falls back to use extList string
157 // @deprecated: This case can be removed later if localconf.php is not supported anymore
158 unset($TYPO3_CONF_VARS['EXT']['extListArray']);
159 define('TYPO3_db', $typo_db);
160 define('TYPO3_db_username', $typo_db_username);
161 define('TYPO3_db_password', $typo_db_password);
162 define('TYPO3_db_host', $typo_db_host);
163 define('TYPO3_extTableDef_script', $typo_db_extTableDef_script);
164 unset($GLOBALS['typo_db']);
165 unset($GLOBALS['typo_db_username']);
166 unset($GLOBALS['typo_db_password']);
167 unset($GLOBALS['typo_db_host']);
168 unset($GLOBALS['typo_db_extTableDef_script']);
169 } else {
170 die(\TYPO3\CMS\Core\Configuration\ConfigurationManager::LOCALCONF_FILE . ' not found!');
171 }
172 define('TYPO3_user_agent', 'User-Agent: ' . $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
173 return $this;
174 }
175
176 /**
177 * Redirect to install tool if database host and database are not defined
178 *
179 * @return \TYPO3\CMS\Core\Core\Bootstrap
180 */
181 public function redirectToInstallToolIfDatabaseCredentialsAreMissing() {
182 if (!TYPO3_db_host && !TYPO3_db) {
183 \TYPO3\CMS\Core\Utility\HttpUtility::redirect('install/index.php?mode=123&step=1&password=joh316');
184 }
185 return $this;
186 }
187
188 /**
189 * Initialize caching framework
190 *
191 * @return \TYPO3\CMS\Core\Core\Bootstrap
192 */
193 public function initializeCachingFramework() {
194 \TYPO3\CMS\Core\Cache\Cache::initializeCachingFramework();
195 return $this;
196 }
197
198 /**
199 * Register autoloader
200 *
201 * @return \TYPO3\CMS\Core\Core\Bootstrap
202 */
203 public function registerAutoloader() {
204 \TYPO3\CMS\Core\Autoloader::registerAutoloader();
205 return $this;
206 }
207
208 /**
209 * Checking for UTF-8 in the settings since TYPO3 4.5
210 *
211 * Since TYPO3 4.5, everything other than UTF-8 is deprecated.
212 *
213 * [BE][forceCharset] is set to the charset that TYPO3 is using
214 * [SYS][setDBinit] is used to set the DB connection
215 * and both settings need to be adjusted for UTF-8 in order to work properly
216 *
217 * @return \TYPO3\CMS\Core\Core\Bootstrap
218 */
219 public function checkUtf8DatabaseSettingsOrDie() {
220 // Check if [BE][forceCharset] has been set in localconf.php
221 if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'])) {
222 // die() unless we're already on UTF-8
223 if (($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] != 'utf-8' && $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']) && TYPO3_enterInstallScript !== '1') {
224 die((('This installation was just upgraded to a new TYPO3 version. Since TYPO3 4.7, utf-8 is always enforced.<br />' . 'The configuration option $GLOBALS[\'TYPO3_CONF_VARS\'][BE][forceCharset] was marked as deprecated in TYPO3 4.5 and is now ignored.<br />') . 'You have configured the value to something different, which is not supported anymore.<br />') . 'Please proceed to the Update Wizard in the TYPO3 Install Tool to update your configuration.');
225 } else {
226 unset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
227 }
228 }
229 if (((isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) && $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] !== '-1') && preg_match('/SET NAMES utf8/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) === FALSE) && TYPO3_enterInstallScript !== '1') {
230 // Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
231 die(((((((((('This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10)) . $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) . chr(10)) . chr(10)) . 'It looks like UTF-8 is not used for this connection.') . chr(10)) . chr(10)) . 'Everything other than UTF-8 is unsupported since TYPO3 4.7.') . chr(10)) . 'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.');
232 } else {
233 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] = 'SET NAMES utf8;';
234 }
235 return $this;
236 }
237
238 /**
239 * Parse old curl options and set new http ones instead
240 *
241 * @TODO : This code segment must still be finished
242 * @return \TYPO3\CMS\Core\Core\Bootstrap
243 */
244 public function transferDeprecatedCurlSettings() {
245 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
246 $proxyParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
247 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
248 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
249 }
250 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
251 $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
252 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
253 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
254 }
255 return $this;
256 }
257
258 /**
259 * Set cacheHash options
260 *
261 * @return \TYPO3\CMS\Core\Core\Bootstrap
262 */
263 public function setCacheHashOptions() {
264 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
265 'cachedParametersWhiteList' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
266 'excludedParameters' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
267 'requireCacheHashPresenceParameters' => \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE)
268 );
269 if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
270 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
271 } else {
272 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
273 }
274 return $this;
275 }
276
277 /**
278 * $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] must be either
279 * 'digest' or 'basic' with fallback to 'basic'
280 *
281 * @return \TYPO3\CMS\Core\Core\Bootstrap
282 */
283 public function enforceCorrectProxyAuthScheme() {
284 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] === 'digest' ?: ($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'basic');
285 return $this;
286 }
287
288 /**
289 * Set default timezone
290 *
291 * @return \TYPO3\CMS\Core\Core\Bootstrap
292 */
293 public function setDefaultTimezone() {
294 $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
295 if (empty($timeZone)) {
296 // Time zone from the server environment (TZ env or OS query)
297 $defaultTimeZone = @date_default_timezone_get();
298 if ($defaultTimeZone !== '') {
299 $timeZone = $defaultTimeZone;
300 } else {
301 $timeZone = 'UTC';
302 }
303 }
304 // Set default to avoid E_WARNINGs with PHP > 5.3
305 date_default_timezone_set($timeZone);
306 return $this;
307 }
308
309 /**
310 * Initialize the locales handled by TYPO3
311 *
312 * @return \TYPO3\CMS\Core\Core\Bootstrap
313 */
314 public function initializeL10nLocales() {
315 \TYPO3\CMS\Core\Localization\Locales::initialize();
316 return $this;
317 }
318
319 /**
320 * Based on the configuration of the image processing some options are forced
321 * to simplify configuration settings and combinations
322 *
323 * @return \TYPO3\CMS\Core\Core\Bootstrap
324 */
325 public function configureImageProcessingOptions() {
326 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['image_processing']) {
327 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] = 0;
328 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = 0;
329 }
330 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
331 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'] = '';
332 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] = '';
333 $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,png';
334 $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] = 0;
335 }
336 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']) {
337 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 1;
338 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
339 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
340 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] === 'gm') {
341 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
342 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
343 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
344 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
345 }
346 }
347 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
348 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? 0 : 1;
349 }
350 return $this;
351 }
352
353 /**
354 * Convert type of "pageNotFound_handling" setting in case it was written as a
355 * string (e.g. if edited in Install Tool)
356 *
357 * @TODO : Remove, if the Install Tool handles such data types correctly
358 * @return \TYPO3\CMS\Core\Core\Bootstrap
359 */
360 public function convertPageNotFoundHandlingToBoolean() {
361 if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
362 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
363 }
364 return $this;
365 }
366
367 /**
368 * Register xdebug(), debug(), debugBegin() and debugEnd() as global functions
369 *
370 * Note: Yes, this is possible in php! xdebug() is then a global function, even
371 * if registerGlobalDebugFunctions() is encapsulated in class scope.
372 *
373 * @return \TYPO3\CMS\Core\Core\Bootstrap
374 */
375 public function registerGlobalDebugFunctions() {
376 require_once('GlobalDebugFunctions.php');
377 return $this;
378 }
379
380 /**
381 * Mail sending via Swift Mailer
382 *
383 * @return \TYPO3\CMS\Core\Core\Bootstrap
384 */
385 public function registerSwiftMailer() {
386 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][] = 'TYPO3\\CMS\\Core\\Mail\\SwiftMailerAdapter';
387 return $this;
388 }
389
390 /**
391 * Configure and set up exception and error handling
392 *
393 * @return \TYPO3\CMS\Core\Core\Bootstrap
394 */
395 public function configureExceptionHandling() {
396 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
397 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
398 // Turn error logging on/off.
399 if (($displayErrors = intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'])) != '-1') {
400 // Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
401 if ($displayErrors == 2) {
402 if (\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
403 $displayErrors = 1;
404 } else {
405 $displayErrors = 0;
406 }
407 }
408 if ($displayErrors == 0) {
409 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
410 }
411 if ($displayErrors == 1) {
412 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
413 define('TYPO3_ERRORHANDLER_MODE', 'debug');
414 }
415 @ini_set('display_errors', $displayErrors);
416 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
417 // With displayErrors = -1 (default), turn on debugging if devIPmask matches:
418 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
419 }
420 return $this;
421 }
422
423 /**
424 * Set PHP memory limit depending on value of
425 * $GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']
426 *
427 * @return \TYPO3\CMS\Core\Core\Bootstrap
428 */
429 public function setMemoryLimit() {
430 if (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) > 16) {
431 @ini_set('memory_limit', (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) . 'm'));
432 }
433 return $this;
434 }
435
436 /**
437 * Define TYPO3_REQUESTTYPE* constants
438 * so devs exactly know what type of request it is
439 *
440 * @return \TYPO3\CMS\Core\Core\Bootstrap
441 */
442 public function defineTypo3RequestTypes() {
443 define('TYPO3_REQUESTTYPE_FE', 1);
444 define('TYPO3_REQUESTTYPE_BE', 2);
445 define('TYPO3_REQUESTTYPE_CLI', 4);
446 define('TYPO3_REQUESTTYPE_AJAX', 8);
447 define('TYPO3_REQUESTTYPE_INSTALL', 16);
448 define('TYPO3_REQUESTTYPE', ((((TYPO3_MODE == 'FE' ? TYPO3_REQUESTTYPE_FE : 0) | (TYPO3_MODE == 'BE' ? TYPO3_REQUESTTYPE_BE : 0)) | (defined('TYPO3_cliMode') && TYPO3_cliMode ? TYPO3_REQUESTTYPE_CLI : 0)) | (defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript ? TYPO3_REQUESTTYPE_INSTALL : 0)) | ($GLOBALS['TYPO3_AJAX'] ? TYPO3_REQUESTTYPE_AJAX : 0));
449 return $this;
450 }
451
452 /**
453 * Set up $GLOBALS['TYPO3_LOADED_EXT'] array with basic information
454 * about extensions.
455 *
456 * @param boolean $allowCaching
457 * @return \TYPO3\CMS\Core\Core\Bootstrap
458 */
459 public function populateTypo3LoadedExtGlobal($allowCaching = TRUE) {
460 $GLOBALS['TYPO3_LOADED_EXT'] = \TYPO3\CMS\Core\Extension\ExtensionManager::loadTypo3LoadedExtensionInformation($allowCaching);
461 return $this;
462 }
463
464 /**
465 * Load extension configuration files (ext_localconf.php)
466 *
467 * The ext_localconf.php files in extensions are meant to make changes
468 * to the global $TYPO3_CONF_VARS configuration array.
469 *
470 * @param boolean $allowCaching
471 * @return \TYPO3\CMS\Core\Core\Bootstrap
472 */
473 public function loadAdditionalConfigurationFromExtensions($allowCaching = TRUE) {
474 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtLocalconf($allowCaching);
475 return $this;
476 }
477
478 /**
479 * Write deprecation log if deprecated extCache setting was set in the instance.
480 *
481 * @return \TYPO3\CMS\Core\Core\Bootstrap
482 * @deprecated since 6.0, the check will be removed two version later.
483 */
484 public function deprecationLogForOldExtCacheSetting() {
485 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache']) && $GLOBALS['TYPO3_CONF_VARS']['SYS']['extCache'] !== -1) {
486 \TYPO3\CMS\Core\Utility\GeneralUtility::deprecationLog('Setting $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'extCache\'] is unused and can be removed from localconf.php');
487 }
488 return $this;
489 }
490
491 /**
492 * Initialize exception handling
493 *
494 * @return \TYPO3\CMS\Core\Core\Bootstrap
495 */
496 public function initializeExceptionHandling() {
497 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
498 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== '') {
499 // Register an error handler for the given errorHandlerErrors
500 $errorHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']);
501 // Set errors which will be converted in an exception
502 $errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
503 }
504 // Instantiate the exception handler once to make sure object is registered
505 // @TODO: Figure out if this is really needed
506 \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']);
507 }
508 return $this;
509 }
510
511 /**
512 * Load some additional classes that are encapsulated in extensions
513 *
514 * @return \TYPO3\CMS\Core\Core\Bootstrap
515 */
516 public function requireAdditionalExtensionFiles() {
517 require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('lang') . 'lang.php';
518 return $this;
519 }
520
521 /**
522 * Extensions may register new caches, so we set the
523 * global cache array to the manager again at this point
524 *
525 * @return \TYPO3\CMS\Core\Core\Bootstrap
526 */
527 public function setFinalCachingFrameworkCacheConfiguration() {
528 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
529 return $this;
530 }
531
532 /**
533 * Define logging and exception constants
534 *
535 * @return \TYPO3\CMS\Core\Core\Bootstrap
536 */
537 public function defineLoggingAndExceptionConstants() {
538 define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
539 define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
540 define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
541 return $this;
542 }
543
544 /**
545 * Unsetting reserved global variables:
546 * Those which are/can be set in "stddb/tables.php" files:
547 *
548 * @return \TYPO3\CMS\Core\Core\Bootstrap
549 */
550 public function unsetReservedGlobalVariables() {
551 unset($GLOBALS['PAGES_TYPES']);
552 unset($GLOBALS['TCA']);
553 unset($GLOBALS['TBE_MODULES']);
554 unset($GLOBALS['TBE_STYLES']);
555 unset($GLOBALS['FILEICONS']);
556 // Those set in init.php:
557 unset($GLOBALS['WEBMOUNTS']);
558 unset($GLOBALS['FILEMOUNTS']);
559 unset($GLOBALS['BE_USER']);
560 // Those set otherwise:
561 unset($GLOBALS['TBE_MODULES_EXT']);
562 unset($GLOBALS['TCA_DESCR']);
563 unset($GLOBALS['LOCAL_LANG']);
564 unset($GLOBALS['TYPO3_AJAX']);
565 return $this;
566 }
567
568 /**
569 * Initialize t3lib_db in $GLOBALS and connect if requested
570 *
571 * @param boolean $connect Whether or not the db should be connected already
572 * @return \TYPO3\CMS\Core\Core\Bootstrap
573 */
574 public function initializeTypo3DbGlobal($connect = TRUE) {
575 /** @var TYPO3_DB t3lib_db */
576 $GLOBALS['TYPO3_DB'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
577 $GLOBALS['TYPO3_DB']->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
578 if ($connect) {
579 $this->establishDatabaseConnection();
580 }
581 return $this;
582 }
583
584 /**
585 * Check adminOnly configuration variable and redirects
586 * to an URL in file typo3conf/LOCK_BACKEND or exit the script
587 *
588 * @throws RuntimeException
589 * @return \TYPO3\CMS\Core\Core\Bootstrap
590 */
591 public function checkLockedBackendAndRedirectOrDie() {
592 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
593 throw new \RuntimeException(('TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'])) . '".', 1294586847);
594 }
595 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
596 if (TYPO3_PROCEED_IF_NO_USER === 2) {
597
598 } else {
599 $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
600 if ($fileContent) {
601 header('Location: ' . $fileContent);
602 } else {
603 throw new \RuntimeException('TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.', 1294586848);
604 }
605 die;
606 }
607 }
608 return $this;
609 }
610
611 /**
612 * Compare client IP with IPmaskList and exit the script run
613 * if the client is not allowed to access the backend
614 *
615 * @return \TYPO3\CMS\Core\Core\Bootstrap
616 */
617 public function checkBackendIpOrDie() {
618 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
619 if (!\TYPO3\CMS\Core\Utility\GeneralUtility::cmpIP(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
620 // Send Not Found header - if the webserver can make use of it
621 header('Status: 404 Not Found');
622 // Just point us away from here...
623 header('Location: http://');
624 // ... and exit good!
625 die;
626 }
627 }
628 return $this;
629 }
630
631 /**
632 * Check lockSSL configuration variable and redirect
633 * to https version of the backend if needed
634 *
635 * @return \TYPO3\CMS\Core\Core\Bootstrap
636 */
637 public function checkSslBackendAndRedirectIfNeeded() {
638 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
639 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
640 $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
641 } else {
642 $sslPortSuffix = '';
643 }
644 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
645 $requestStr = substr(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
646 if ($requestStr === 'index.php' && !\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
647 list(, $url) = explode('://', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'), 2);
648 list($server, $address) = explode('/', $url, 2);
649 header(((('Location: https://' . $server) . $sslPortSuffix) . '/') . $address);
650 die;
651 }
652 } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL')) {
653 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) === 2) {
654 list(, $url) = explode('://', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
655 list($server, $address) = explode('/', $url, 2);
656 header(((('Location: https://' . $server) . $sslPortSuffix) . '/') . $address);
657 } else {
658 // Send Not Found header - if the webserver can make use of it...
659 header('Status: 404 Not Found');
660 // Just point us away from here...
661 header('Location: http://');
662 }
663 // ... and exit good!
664 die;
665 }
666 }
667 return $this;
668 }
669
670 /**
671 * Establish connection to the database
672 *
673 * @return \TYPO3\CMS\Core\Core\Bootstrap
674 */
675 public function establishDatabaseConnection() {
676 $GLOBALS['TYPO3_DB']->connectDB();
677 return $this;
678 }
679
680 /**
681 * Load ext_tables and friends.
682 *
683 * This will mainly set up $TCA and several other global arrays
684 * through API's like extMgm.
685 * Executes ext_tables.php files of loaded extensions or the
686 * according cache file if exists.
687 *
688 * Note: For backwards compatibility some global variables are
689 * explicitly set as global to be used without $GLOBALS[] in
690 * ext_tables.php. It is discouraged to access variables like
691 * $TBE_MODULES directly in ext_tables.php, but we can not prohibit
692 * this without heavily breaking backwards compatibility.
693 *
694 * @TODO : We could write a scheduler / reports module or an update checker
695 * @TODO : It should be defined, which global arrays are ok to be manipulated
696 * @param boolean $allowCaching True, if reading compiled ext_tables file from cache is allowed
697 * @return \TYPO3\CMS\Core\Core\Bootstrap
698 */
699 public function loadExtensionTables($allowCaching = TRUE) {
700 // It is discouraged to use those global variables directly, but we
701 // can not prohibit this without breaking backwards compatibility
702 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
703 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
704 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
705 global $_EXTKEY;
706 // Include standard tables.php file
707 require PATH_t3lib . 'stddb/tables.php';
708 \TYPO3\CMS\Core\Extension\ExtensionManager::loadExtTables($allowCaching);
709 // Load additional ext tables script if registered
710 if (TYPO3_extTableDef_script) {
711 include PATH_typo3conf . TYPO3_extTableDef_script;
712 }
713 // Run post hook for additional manipulation
714 $this->runExtTablesPostProcessingHooks();
715 return $this;
716 }
717
718 /**
719 * Check for registered ext tables hooks and run them
720 *
721 * @throws UnexpectedValueException
722 * @return \TYPO3\CMS\Core\Core\Bootstrap
723 */
724 protected function runExtTablesPostProcessingHooks() {
725 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
726 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
727 /** @var $hookObject \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface */
728 $hookObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classReference);
729 if (!$hookObject instanceof \TYPO3\CMS\Core\Database\TableConfigurationPostProcessingHookInterface) {
730 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\Database\\TableConfigurationPostProcessingHookInterface', 1320585902);
731 }
732 $hookObject->processData();
733 }
734 }
735 return $this;
736 }
737
738 /**
739 * Initialize sprite manager
740 *
741 * @return \TYPO3\CMS\Core\Core\Bootstrap
742 */
743 public function initializeSpriteManager() {
744 \TYPO3\CMS\Backend\Sprite\SpriteManager::initialize();
745 return $this;
746 }
747
748 /**
749 * Initialize backend user object in globals
750 *
751 * @return \TYPO3\CMS\Core\Core\Bootstrap
752 */
753 public function initializeBackendUser() {
754 /** @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
755 $backendUser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
756 $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
757 $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
758 $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
759 $backendUser->OS = TYPO3_OS;
760 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
761 $backendUser->dontSetCookie = TRUE;
762 }
763 $backendUser->start();
764 $backendUser->checkCLIuser();
765 $backendUser->backendCheckLogin();
766 $GLOBALS['BE_USER'] = $backendUser;
767 return $this;
768 }
769
770 /**
771 * Initialize backend user mount points
772 *
773 * @return \TYPO3\CMS\Core\Core\Bootstrap
774 */
775 public function initializeBackendUserMounts() {
776 // Includes deleted mount pages as well! @TODO: Figure out why ...
777 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
778 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->returnFilemounts();
779 return $this;
780 }
781
782 /**
783 * Initialize language object
784 *
785 * @return \TYPO3\CMS\Core\Core\Bootstrap
786 */
787 public function initializeLanguageObject() {
788 /** @var $GLOBALS['LANG'] \TYPO3\CMS\Lang\LanguageService */
789 $GLOBALS['LANG'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Lang\LanguageService');
790 $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
791 return $this;
792 }
793
794 /**
795 * Throw away all output that may have happened during bootstrapping by weird extensions
796 *
797 * @return \TYPO3\CMS\Core\Core\Bootstrap
798 */
799 public function endOutputBufferingAndCleanPreviousOutput() {
800 ob_clean();
801 return $this;
802 }
803
804 /**
805 * Initialize output compression if configured
806 *
807 * @return \TYPO3\CMS\Core\Core\Bootstrap
808 */
809 public function initializeOutputCompression() {
810 if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
811 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
812 @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
813 }
814 ob_start('ob_gzhandler');
815 }
816 return $this;
817 }
818
819 /**
820 * Initialize module menu object
821 *
822 * @return \TYPO3\CMS\Core\Core\Bootstrap
823 */
824 public function initializeModuleMenuObject() {
825 /** @var $moduleMenuUtility Typo3_BackendModule_Utility */
826 $moduleMenuUtility = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleController');
827 $moduleMenuUtility->createModuleMenu();
828 return $this;
829 }
830
831 /**
832 * Things that should be performed to shut down the framework.
833 * This method is called in all important scripts for a clean
834 * shut down of the system.
835 *
836 * @return \TYPO3\CMS\Core\Core\Bootstrap
837 */
838 public function shutdown() {
839 \TYPO3\CMS\Core\Autoloader::unregisterAutoloader();
840 return $this;
841 }
842
843 /**
844 * Provides an instance of "template" for backend-modules to
845 * work with.
846 *
847 * @return \TYPO3\CMS\Core\Core\Bootstrap
848 */
849 public function initializeBackendTemplate() {
850 $GLOBALS['TBE_TEMPLATE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
851 return $this;
852 }
853
854 }
855
856
857 ?>