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