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