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