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