[TASK] Move GlobalScope template-init to Bootstrap
[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 /**
29 * This class encapsulates bootstrap related methods.
30 * It is required directly as the very first thing in entry scripts and
31 * used to define all base things like constants and pathes and so on.
32 *
33 * Most methods in this class have dependencies to each other. They can
34 * not be called in arbitrary order. The methods are ordered top down, so
35 * a method at the beginning has lower dependencies than a method further
36 * down. Do not fiddle with the load order in own scripts except you know
37 * exactly what you are doing!
38 *
39 * @author Christian Kuhn <lolli@schwarzbu.ch>
40 * @package TYPO3
41 * @subpackage core
42 */
43 class Typo3_Bootstrap {
44 /**
45 * @var Typo3_Bootstrap
46 */
47 protected static $instance = NULL;
48
49 /**
50 * Disable direct creation of this object.
51 */
52 protected function __construct() {
53 }
54
55 /**
56 * Disable direct cloning of this object.
57 */
58 protected function __clone() {
59 }
60
61 /**
62 * @return Typo3_Bootstrap
63 */
64 public static function getInstance() {
65 if (is_null(self::$instance)) {
66 self::$instance = new Typo3_Bootstrap();
67 }
68 return self::$instance;
69 }
70
71 /**
72 * Prevent any unwanted output that may corrupt AJAX/compression.
73 * This does not interfeer with "die()" or "echo"+"exit()" messages!
74 *
75 * @return Typo3_Bootstrap
76 */
77 public function startOutputBuffering() {
78 ob_start();
79
80 return $this;
81 }
82
83 /**
84 * Check several a priori conditions like the current
85 * php version or exit the script with an error.
86 *
87 * @return Typo3_Bootstrap
88 */
89 public function checkEnvironmentOrDie() {
90 $this->checkPhpVersionOrDie();
91 $this->checkGlobalsAreNotSetViaPostOrGet();
92
93 return $this;
94 }
95
96 /**
97 * Define all simple base constants
98 *
99 * @return Typo3_Bootstrap
100 */
101 public function defineBaseConstants() {
102 // This version, branch and copyright
103 define('TYPO3_version', '6.0-dev');
104 define('TYPO3_branch', '6.0');
105 define('TYPO3_copyright_year', '1998-2012');
106
107 // TYPO3 external links
108 define('TYPO3_URL_GENERAL', 'http://typo3.org/');
109 define('TYPO3_URL_ORG', 'http://typo3.org/');
110 define('TYPO3_URL_LICENSE', 'http://typo3.org/licenses');
111 define('TYPO3_URL_EXCEPTION', 'http://typo3.org/go/exception/v4/');
112 define('TYPO3_URL_MAILINGLISTS', 'http://lists.typo3.org/cgi-bin/mailman/listinfo');
113 define('TYPO3_URL_DOCUMENTATION', 'http://typo3.org/documentation/');
114 define('TYPO3_URL_DOCUMENTATION_TSREF', 'http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/current/view/');
115 define('TYPO3_URL_DOCUMENTATION_TSCONFIG', 'http://typo3.org/documentation/document-library/core-documentation/doc_core_tsconfig/current/view/');
116 define('TYPO3_URL_CONSULTANCY', 'http://typo3.org/support/professional-services/');
117 define('TYPO3_URL_CONTRIBUTE', 'http://typo3.org/contribute/');
118 define('TYPO3_URL_SECURITY', 'http://typo3.org/teams/security/');
119 define('TYPO3_URL_DOWNLOAD', 'http://typo3.org/download/');
120 define('TYPO3_URL_SYSTEMREQUIREMENTS', 'http://typo3.org/about/typo3-the-cms/system-requirements/');
121 define('TYPO3_URL_DONATE', 'http://typo3.org/donate/online-donation/');
122
123 // A tabulator, a linefeed, a carriage return, a CR-LF combination
124 define('TAB', chr(9));
125 define('LF', chr(10));
126 define('CR', chr(13));
127 define('CRLF', CR . LF);
128
129 // Security related constant: Default value of fileDenyPattern
130 define('FILE_DENY_PATTERN_DEFAULT', '\.(php[3-6]?|phpsh|phtml)(\..*)?$|^\.htaccess$');
131
132 // Security related constant: List of file extensions that should be registered as php script file extensions
133 define('PHP_EXTENSIONS_DEFAULT', 'php,php3,php4,php5,php6,phpsh,inc,phtml');
134
135 // List of extensions required to run the core
136 define('REQUIRED_EXTENSIONS', 'cms,lang,sv,em,recordlist,extbase,fluid');
137
138 // Operating system identifier
139 // Either "WIN" or empty string
140 define('TYPO3_OS', $this->getTypo3Os());
141
142 return $this;
143 }
144
145 /**
146 * Calculate all required base paths and set as constants.
147 * The script execution will be aborted if this fails.
148 *
149 * @param string $relativePathPart The relative path of the entry script to the document root
150 * @return Typo3_Bootstrap
151 */
152 public function defineAndCheckPaths($relativePathPart = '') {
153 // Relative path from document root to typo3/ directory
154 // Hardcoded to "typo3/"
155 define('TYPO3_mainDir', 'typo3/');
156
157 // Absolute path of the entry script that was called
158 // All paths are unified between Windows and Unix, so the \ of Windows is substituted to a /
159 // Example "/var/www/instance-name/htdocs/typo3conf/ext/wec_map/mod1/index.php"
160 // Example "c:/var/www/instance-name/htdocs/typo3/backend.php" for a path in Windows
161 define('PATH_thisScript', $this->getPathThisScript());
162
163 // Absolute path of the document root of the instance with trailing slash
164 // Example "/var/www/instance-name/htdocs/"
165 define('PATH_site', $this->getPathSite($relativePathPart));
166
167 // Absolute path of the typo3 directory of the instance with trailing slash
168 // Example "/var/www/instance-name/htdocs/typo3/"
169 define('PATH_typo3', PATH_site . TYPO3_mainDir);
170
171 // Relative path (from the PATH_typo3) to a BE module NOT using mod.php dispatcher with trailing slash
172 // Example "sysext/perms/mod/" for an extension installed in typo3/sysext/
173 // Example "install/" for the install tool entry script
174 // Example "../typo3conf/ext/templavoila/mod2/ for an extension installed in typo3conf/ext/
175 define('PATH_typo3_mod', defined('TYPO3_MOD_PATH') ? TYPO3_MOD_PATH : '');
176
177 // Absolute path to the t3lib directory with trailing slash
178 // Example "/var/www/instance-name/htdocs/t3lib/"
179 define('PATH_t3lib', PATH_site . 't3lib/');
180
181 // Absolute path to the typo3conf directory with trailing slash
182 // Example "/var/www/instance-name/htdocs/typo3conf/"
183 define('PATH_typo3conf', PATH_site . 'typo3conf/');
184
185 // Absolute path to the tslib directory with trailing slash
186 // Example "/var/www/instance-name/htdocs/typo3/sysext/cms/tslib/"
187 define('PATH_tslib', PATH_typo3 . 'sysext/cms/tslib/');
188
189 // Check above defines and exit with error message on error
190 $this->checkMainPathsExist();
191
192 return $this;
193 }
194
195 /**
196 * Load several base classes during bootstrap
197 *
198 * @return Typo3_Bootstrap
199 */
200 public function requireBaseClasses() {
201 require_once(PATH_t3lib . 'class.t3lib_div.php');
202
203 require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
204
205 require_once(PATH_t3lib . 'class.t3lib_cache.php');
206 require_once(PATH_t3lib . 'cache/class.t3lib_cache_exception.php');
207 require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_nosuchcache.php');
208 require_once(PATH_t3lib . 'cache/exception/class.t3lib_cache_exception_invaliddata.php');
209 require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
210 require_once(PATH_t3lib . 'cache/class.t3lib_cache_factory.php');
211 require_once(PATH_t3lib . 'cache/class.t3lib_cache_manager.php');
212 require_once(PATH_t3lib . 'cache/frontend/interfaces/interface.t3lib_cache_frontend_frontend.php');
213 require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php');
214 require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_stringfrontend.php');
215 require_once(PATH_t3lib . 'cache/frontend/class.t3lib_cache_frontend_phpfrontend.php');
216 require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_backend.php');
217 require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_abstractbackend.php');
218 require_once(PATH_t3lib . 'cache/backend/interfaces/interface.t3lib_cache_backend_phpcapablebackend.php');
219 require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_filebackend.php');
220 require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_nullbackend.php');
221
222 require_once(PATH_t3lib . 'class.t3lib_autoloader.php');
223
224 return $this;
225 }
226
227 /**
228 * Set up php error reporting and various things like time tracking
229 *
230 * @return Typo3_Bootstrap
231 */
232 public function setUpEnvironment() {
233 // Core should be notice free at least until this point ...
234 // @TODO: Move further down / get rid of it until errorHandler is initialized
235 error_reporting(E_ALL & ~(E_STRICT | E_NOTICE | E_DEPRECATED));
236
237 // Unset variable(s) in global scope (security issue #13959)
238 unset($GLOBALS['error']);
239
240 // Include information about the browser/user-agent
241 $GLOBALS['CLIENT'] = t3lib_div::clientInfo();
242
243 // Is set to the system time in milliseconds.
244 // This could be used to output script parsetime in the end of the script
245 $GLOBALS['PARSETIME_START'] = t3lib_div::milliseconds();
246 $GLOBALS['TYPO3_MISC'] = array();
247 $GLOBALS['TYPO3_MISC']['microtime_start'] = microtime(TRUE);
248
249 // Compatibility layer for magic quotes
250 if (!get_magic_quotes_gpc()) {
251 t3lib_div::addSlashesOnArray($_GET);
252 t3lib_div::addSlashesOnArray($_POST);
253 $GLOBALS['HTTP_GET_VARS'] = $_GET;
254 $GLOBALS['HTTP_POST_VARS'] = $_POST;
255 }
256
257 return $this;
258 }
259
260 /**
261 * Throws an exception if no browser could be identified
262 *
263 * @return Typo3_Bootstrap
264 * @throws RuntimeException
265 */
266 public function checkValidBrowserOrDie() {
267 // Checks for proper browser
268 if (empty($GLOBALS['CLIENT']['BROWSER'])) {
269 throw new RuntimeException('Browser Error: Your browser version looks incompatible with this TYPO3 version!', 1294587023);
270 }
271
272 return $this;
273 }
274
275
276 /**
277 * Load default TYPO3_CONF_VARS
278 *
279 * @return Typo3_Bootstrap
280 */
281 public function loadDefaultTypo3ConfVars() {
282 $GLOBALS['TYPO3_CONF_VARS'] = require(PATH_t3lib . 'stddb/DefaultSettings.php');
283
284 return $this;
285 }
286
287 /**
288 * Register default ExtDirect components
289 *
290 * @return Typo3_Bootstrap
291 */
292 public function registerExtDirectComponents() {
293 if (TYPO3_MODE === 'BE') {
294 t3lib_extMgm::registerExtDirectComponent(
295 'TYPO3.Components.PageTree.DataProvider',
296 PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:t3lib_tree_pagetree_extdirect_Tree',
297 'web',
298 'user,group'
299 );
300
301 t3lib_extMgm::registerExtDirectComponent(
302 'TYPO3.Components.PageTree.Commands',
303 PATH_t3lib . 'tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_tree.php:t3lib_tree_pagetree_extdirect_Commands',
304 'web',
305 'user,group'
306 );
307
308 t3lib_extMgm::registerExtDirectComponent(
309 'TYPO3.Components.PageTree.ContextMenuDataProvider',
310 PATH_t3lib . 'contextmenu/pagetree/extdirect/class.t3lib_contextmenu_pagetree_extdirect_contextmenu.php:t3lib_contextmenu_pagetree_extdirect_ContextMenu',
311 'web',
312 'user,group'
313 );
314
315 t3lib_extMgm::registerExtDirectComponent(
316 'TYPO3.LiveSearchActions.ExtDirect',
317 PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_backendlivesearch.php:extDirect_DataProvider_BackendLiveSearch',
318 'web_list',
319 'user,group'
320 );
321
322 t3lib_extMgm::registerExtDirectComponent(
323 'TYPO3.BackendUserSettings.ExtDirect',
324 PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_beusersettings.php:extDirect_DataProvider_BackendUserSettings'
325 );
326
327 t3lib_extMgm::registerExtDirectComponent(
328 'TYPO3.CSH.ExtDirect',
329 PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_contexthelp.php:extDirect_DataProvider_ContextHelp'
330 );
331
332 t3lib_extMgm::registerExtDirectComponent(
333 'TYPO3.ExtDirectStateProvider.ExtDirect',
334 PATH_t3lib . 'extjs/dataprovider/class.extdirect_dataprovider_state.php:extDirect_DataProvider_State'
335 );
336 }
337
338 return $this;
339 }
340
341 /**
342 * Initialize some globals
343 *
344 * @return Typo3_Bootstrap
345 */
346 public function initializeGlobalVariables() {
347 $GLOBALS['T3_VAR'] = array();
348 $GLOBALS['T3_SERVICES'] = array();
349
350 return $this;
351 }
352
353 /**
354 * Check typo3conf/localconf.php exists
355 *
356 * @throws RuntimeException
357 * @return Typo3_Bootstrap
358 */
359 public function checkLocalconfExistsOrDie() {
360 if (!@is_file(PATH_typo3conf . 'localconf.php')) {
361 throw new RuntimeException('localconf.php is not found!', 1333754332);
362 }
363
364 return $this;
365 }
366
367 /**
368 * Set global database variables to empty string.
369 * Database-variables are cleared!
370 *
371 * @TODO: Figure out why we do this (security reasons with register globals?)
372 * @return Typo3_Bootstrap
373 */
374 public function setGlobalDatabaseVariablesToEmptyString() {
375 // The database name
376 $GLOBALS['typo_db'] = '';
377 // The database username
378 $GLOBALS['typo_db_username'] = '';
379 // The database password
380 $GLOBALS['typo_db_password'] = '';
381 // The database host
382 $GLOBALS['typo_db_host'] = '';
383 // The filename of an additional script in typo3conf/-folder which is included after
384 // tables.php. Code in this script should modify the tables.php-configuration only,
385 // and this provides a good way to extend the standard-distributed tables.php file.
386 $GLOBALS['typo_db_extTableDef_script'] = '';
387
388 return $this;
389 }
390
391 /**
392 * Loads the main configuration file (localconf.php)
393 *
394 * @return Typo3_Bootstrap
395 */
396 public function loadMainConfigurationFile() {
397 global $TYPO3_CONF_VARS, $typo_db, $typo_db_username, $typo_db_password, $typo_db_host, $typo_db_extTableDef_script;
398 require(PATH_typo3conf . 'localconf.php');
399
400 return $this;
401 }
402
403 /**
404 * Define the database setup as constants
405 * and unset no longer needed global variables
406 *
407 * @return Typo3_Bootstrap
408 */
409 public function defineTypo3DatabaseConstants() {
410 define('TYPO3_db', $GLOBALS['typo_db']);
411 define('TYPO3_db_username', $GLOBALS['typo_db_username']);
412 define('TYPO3_db_password', $GLOBALS['typo_db_password']);
413 define('TYPO3_db_host', $GLOBALS['typo_db_host']);
414 define('TYPO3_extTableDef_script', $GLOBALS['typo_db_extTableDef_script']);
415 define('TYPO3_user_agent', 'User-Agent: '. $GLOBALS['TYPO3_CONF_VARS']['HTTP']['userAgent']);
416
417 unset($GLOBALS['typo_db']);
418 unset($GLOBALS['typo_db_username']);
419 unset($GLOBALS['typo_db_password']);
420 unset($GLOBALS['typo_db_host']);
421 unset($GLOBALS['typo_db_extTableDef_script']);
422
423 return $this;
424 }
425
426 /**
427 * Redirect to install tool if database host and database are not defined
428 *
429 * @return Typo3_Bootstrap
430 */
431 public function redirectToInstallToolIfDatabaseCredentialsAreMissing() {
432 if (!TYPO3_db_host && !TYPO3_db) {
433 t3lib_utility_Http::redirect('install/index.php?mode=123&step=1&password=joh316');
434 }
435
436 return $this;
437 }
438
439 /**
440 * Initialize caching framework
441 *
442 * @return Typo3_Bootstrap
443 */
444 public function initializeCachingFramework() {
445 t3lib_cache::initializeCachingFramework();
446
447 return $this;
448 }
449
450 /**
451 * Register autoloader
452 *
453 * @return Typo3_Bootstrap
454 */
455 public function registerAutoloader() {
456 t3lib_autoloader::registerAutoloader();
457
458 return $this;
459 }
460
461 /**
462 * Add typo3/contrib/pear/ as first include folder in
463 * include path, because the shipped PEAR packages use
464 * relative paths to include their files.
465 *
466 * This is required for t3lib_http_Request to work.
467 *
468 * Having the TYPO3 folder first will make sure that the
469 * shipped version is loaded before any local PEAR package,
470 * thus avoiding any incompatibilities with newer or older
471 * versions.
472 *
473 * @return Typo3_Bootstrap
474 */
475 public function addCorePearPathToIncludePath() {
476 set_include_path(PATH_typo3 . 'contrib/pear/' . PATH_SEPARATOR . get_include_path());
477
478 return $this;
479 }
480
481 /**
482 * Checking for UTF-8 in the settings since TYPO3 4.5
483 *
484 * Since TYPO3 4.5, everything other than UTF-8 is deprecated.
485 *
486 * [BE][forceCharset] is set to the charset that TYPO3 is using
487 * [SYS][setDBinit] is used to set the DB connection
488 * and both settings need to be adjusted for UTF-8 in order to work properly
489 *
490 * @return Typo3_Bootstrap
491 */
492 public function checkUtf8DatabaseSettingsOrDie() {
493 // Check if [BE][forceCharset] has been set in localconf.php
494 if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'])) {
495 // die() unless we're already on UTF-8
496 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] != 'utf-8' &&
497 $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] &&
498 TYPO3_enterInstallScript !== '1'
499 ) {
500 die('This installation was just upgraded to a new TYPO3 version. Since TYPO3 4.7, utf-8 is always enforced.<br />' .
501 'The configuration option $GLOBALS[\'TYPO3_CONF_VARS\'][BE][forceCharset] was marked as deprecated in TYPO3 4.5 and is now ignored.<br />' .
502 'You have configured the value to something different, which is not supported anymore.<br />' .
503 'Please proceed to the Update Wizard in the TYPO3 Install Tool to update your configuration.'
504 );
505 } else {
506 unset($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']);
507 }
508 }
509
510 if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) &&
511 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] !== '-1' &&
512 preg_match('/SET NAMES utf8/', $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']) === FALSE &&
513 TYPO3_enterInstallScript !== '1'
514 ) {
515 // Only accept "SET NAMES utf8" for this setting, otherwise die with a nice error
516 die('This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'setDBinit\'] property with the following value:' . chr(10) .
517 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] . chr(10) . chr(10) .
518 'It looks like UTF-8 is not used for this connection.' . chr(10) . chr(10) .
519 'Everything other than UTF-8 is unsupported since TYPO3 4.7.' . chr(10) .
520 'The DB, its connection and TYPO3 should be migrated to UTF-8 therefore. Please check your setup.');
521 } else {
522 $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'] = 'SET NAMES utf8;';
523 }
524
525 return $this;
526 }
527
528 /**
529 * Parse old curl options and set new http ones instead
530 *
531 * @TODO: This code segment must still be finished
532 * @return Typo3_Bootstrap
533 */
534 public function transferDeprecatedCurlSettings() {
535 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) {
536 $proxyParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'], 2);
537 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_host'] = $proxyParts[0];
538 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_port'] = $proxyParts[1];
539 /* TODO: uncomment after refactoring getUrl()
540 t3lib_div::deprecationLog(
541 'This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'curlProxyServer\'] property with the following value: ' .
542 $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'] . LF . 'Please make sure to set $GLOBALS[\'TYPO3_CONF_VARS\'][\'HTTP\'][\'proxy_host\']' .
543 ' and $GLOBALS['TYPO3_CONF_VARS'][\'HTTP\'][\'proxy_port\'] instead.' . LF . 'Remove this line from your localconf.php.'
544 );*/
545 }
546 if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'])) {
547 $userPassParts = explode(':', $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'], 2);
548 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_user'] = $userPassParts[0];
549 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_password'] = $userPassParts[1];
550 /* TODO: uncomment after refactoring getUrl()
551 t3lib_div::deprecationLog(
552 'This TYPO3 installation is using the $GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'curlProxyUserPass\'] property with the following value: ' .
553 $GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyUserPass'] . LF . 'Please make sure to set $GLOBALS[\'TYPO3_CONF_VARS\'][\'HTTP\'][\'proxy_user\']' .
554 ' and $GLOBALS['TYPO3_CONF_VARS'][\'HTTP\'][\'proxy_password\'] instead.' . LF . 'Remove this line from your localconf.php.'
555 );*/
556 }
557
558 return $this;
559 }
560
561 /**
562 * Set cacheHash options
563 *
564 * @return Typo3_Bootstrap
565 */
566 public function setCacheHashOptions() {
567 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash'] = array(
568 'cachedParametersWhiteList' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashOnlyForParameters'], TRUE),
569 'excludedParameters' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParameters'], TRUE),
570 'requireCacheHashPresenceParameters' => t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashRequiredParameters'], TRUE),
571 );
572 if (trim($GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty']) === '*') {
573 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludeAllEmptyParameters'] = TRUE;
574 } else {
575 $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParametersIfEmpty'] = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['cHashExcludedParametersIfEmpty'], TRUE);
576 }
577
578 return $this;
579 }
580
581 /**
582 * $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] must be either
583 * 'digest' or 'basic' with fallback to 'basic'
584 *
585 * @return Typo3_Bootstrap
586 */
587 public function enforceCorrectProxyAuthScheme() {
588 $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] === 'digest' ?
589 : $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy_auth_scheme'] = 'basic';
590
591 return $this;
592 }
593
594 /**
595 * Set default timezone
596 *
597 * @return Typo3_Bootstrap
598 */
599 public function setDefaultTimezone() {
600 $timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
601 if (empty($timeZone)) {
602 // Time zone from the server environment (TZ env or OS query)
603 $defaultTimeZone = @date_default_timezone_get();
604 if ($defaultTimeZone !== '') {
605 $timeZone = $defaultTimeZone;
606 } else {
607 $timeZone = 'UTC';
608 }
609 }
610 // Set default to avoid E_WARNINGs with PHP > 5.3
611 date_default_timezone_set($timeZone);
612
613 return $this;
614 }
615
616 /**
617 * Initialize the locales handled by TYPO3
618 *
619 * @return Typo3_Bootstrap
620 */
621 public function initializeL10nLocales() {
622 t3lib_l10n_Locales::initialize();
623
624 return $this;
625 }
626
627 /**
628 * Based on the configuration of the image processing some options are forced
629 * to simplify configuration settings and combinations
630 *
631 * @return Typo3_Bootstrap
632 */
633 public function configureImageProcessingOptions() {
634 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['image_processing']) {
635 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im'] = 0;
636 $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'] = 0;
637 }
638 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['im']) {
639 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path'] = '';
640 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path_lzw'] = '';
641 $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] = 'gif,jpg,jpeg,png';
642 $GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'] = 0;
643 }
644 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']) {
645 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 1;
646 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
647 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_mask_temp_ext_gif'] = 1;
648 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5']==='gm') {
649 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = 0;
650 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState'] = 0;
651 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_no_effects'] = 1;
652 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_v5effects'] = -1;
653 }
654 }
655 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_imvMaskState']) {
656 $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] = $GLOBALS['TYPO3_CONF_VARS']['GFX']['im_negate_mask'] ? 0 : 1;
657 }
658
659 return $this;
660 }
661
662 /**
663 * Convert type of "pageNotFound_handling" setting in case it was written as a
664 * string (e.g. if edited in Install Tool)
665 *
666 * @TODO: Remove, if the Install Tool handles such data types correctly
667 * @return Typo3_Bootstrap
668 */
669 public function convertPageNotFoundHandlingToBoolean() {
670 if (!strcasecmp($GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'], 'TRUE')) {
671 $GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = TRUE;
672 }
673
674 return $this;
675 }
676
677 /**
678 * Register xdebug(), debug(), debugBegin() and debugEnd() as global functions
679 *
680 * Note: Yes, this is possible in php! xdebug() is then a global function, even
681 * if registerGlobalDebugFunctions() is encapsulated in class scope.
682 *
683 * @return Typo3_Bootstrap
684 */
685 public function registerGlobalDebugFunctions() {
686 // Simple debug function which prints output immediately
687 function xdebug($var = '', $debugTitle = 'xdebug') {
688 // If you wish to use the debug()-function, and it does not output something,
689 // please edit the IP mask in TYPO3_CONF_VARS
690 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
691 return;
692 }
693 t3lib_utility_Debug::debug($var, $debugTitle);
694 }
695
696 // Debug function which calls $GLOBALS['error'] error handler if available
697 function debug($variable = '', $name = '*variable*', $line = '*line*', $file = '*file*', $recursiveDepth = 3, $debugLevel = E_DEBUG) {
698 // If you wish to use the debug()-function, and it does not output something,
699 // please edit the IP mask in TYPO3_CONF_VARS
700 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
701 return;
702 }
703 if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'], 'debug'))) {
704 $GLOBALS['error']->debug($variable, $name, $line, $file, $recursiveDepth, $debugLevel);
705 } else {
706 $title = ($name === '*variable*') ? '' : $name;
707 $group = ($line === '*line*') ? NULL : $line;
708 t3lib_utility_Debug::debug($variable, $title, $group);
709 }
710 }
711
712 function debugBegin() {
713 if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'],'debugBegin'))) {
714 $GLOBALS['error']->debugBegin();
715 }
716 }
717
718 function debugEnd() {
719 if (is_object($GLOBALS['error']) && @is_callable(array($GLOBALS['error'],'debugEnd'))) {
720 $GLOBALS['error']->debugEnd();
721 }
722 }
723
724 return $this;
725 }
726
727 /**
728 * Mail sending via Swift Mailer
729 *
730 * @return Typo3_Bootstrap
731 */
732 public function registerSwiftMailer() {
733 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'][]
734 = 't3lib_mail_SwiftMailerAdapter';
735
736 return $this;
737 }
738
739 /**
740 * Configure and set up exception and error handling
741 *
742 * @return Typo3_Bootstrap
743 */
744 public function configureExceptionHandling() {
745 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'];
746 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'];
747
748 // Turn error logging on/off.
749 if (($displayErrors = intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'])) != '-1') {
750 // Special value "2" enables this feature only if $GLOBALS['TYPO3_CONF_VARS'][SYS][devIPmask] matches
751 if ($displayErrors == 2) {
752 if (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
753 $displayErrors = 1;
754 } else {
755 $displayErrors = 0;
756 }
757 }
758 if ($displayErrors == 0) {
759 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors'] = 0;
760 }
761 if ($displayErrors == 1) {
762 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
763 define('TYPO3_ERRORHANDLER_MODE', 'debug');
764 }
765
766 @ini_set('display_errors', $displayErrors);
767 } elseif (t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'])) {
768 // With displayErrors = -1 (default), turn on debugging if devIPmask matches:
769 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'];
770 }
771
772 return $this;
773 }
774
775 /**
776 * Set PHP memory limit depending on value of
777 * $GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']
778 *
779 * @return Typo3_Bootstrap
780 */
781 public function setMemoryLimit() {
782 if (intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) > 16) {
783 @ini_set('memory_limit', intval($GLOBALS['TYPO3_CONF_VARS']['SYS']['setMemoryLimit']) . 'm');
784 }
785
786 return $this;
787 }
788
789 /**
790 * Define TYPO3_REQUESTTYPE* constants
791 * so devs exactly know what type of request it is
792 *
793 * @return Typo3_Bootstrap
794 */
795 public function defineTypo3RequestTypes() {
796 define('TYPO3_REQUESTTYPE_FE', 1);
797 define('TYPO3_REQUESTTYPE_BE', 2);
798 define('TYPO3_REQUESTTYPE_CLI', 4);
799 define('TYPO3_REQUESTTYPE_AJAX', 8);
800 define('TYPO3_REQUESTTYPE_INSTALL', 16);
801 define('TYPO3_REQUESTTYPE',
802 (TYPO3_MODE == 'FE' ? TYPO3_REQUESTTYPE_FE : 0) |
803 (TYPO3_MODE == 'BE' ? TYPO3_REQUESTTYPE_BE : 0) |
804 ((defined('TYPO3_cliMode') && TYPO3_cliMode) ? TYPO3_REQUESTTYPE_CLI : 0) |
805 ((defined('TYPO3_enterInstallScript') && TYPO3_enterInstallScript) ? TYPO3_REQUESTTYPE_INSTALL : 0) |
806 ($GLOBALS['TYPO3_AJAX'] ? TYPO3_REQUESTTYPE_AJAX : 0)
807 );
808
809 return $this;
810 }
811
812 /**
813 * Load extension configuration files (ext_localconf.php)
814 *
815 * The ext_localconf.php files in extensions are meant to make changes
816 * to the global $TYPO3_CONF_VARS configuration array.
817 *
818 * @return Typo3_Bootstrap
819 */
820 public function loadAdditionalConfigurationFromExtensions() {
821 // This is the main array meant to be manipulated in the ext_localconf.php files
822 // In general it is recommended to not rely on it to be globally defined in that
823 // scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
824 // Nevertheless we define it here as global for backwards compatibility.
825 global $TYPO3_CONF_VARS;
826
827 // These globals for internal use only. Manipulating them directly is highly discouraged!
828 // We set them here as global for backwards compatibility, but this will change in
829 // future versions.
830 // @deprecated since 6.0 Will be removed in two versions.
831 global $T3_SERVICES, $T3_VAR;
832
833 // Load extensions:
834 $GLOBALS['TYPO3_LOADED_EXT'] = t3lib_extMgm::typo3_loadExtensions();
835
836 // Load temp_CACHED file of ext_tables or each ext_tables.php of loaded extensions
837 if ($GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']
838 && file_exists(PATH_typo3conf . $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] . '_ext_localconf.php')
839 ) {
840 require(PATH_typo3conf . $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] . '_ext_localconf.php');
841 } else {
842 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
843 if (is_array($extensionInformation) && $extensionInformation['ext_localconf.php']) {
844 // $_EXTKEY and $_EXTCONF are available in ext_localconf.php
845 // and are explicitly set in temp_CACHED file as well
846 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
847 require($extensionInformation['ext_localconf.php']);
848 }
849 }
850 }
851
852 return $this;
853 }
854
855 /**
856 * Write deprecation log if the TYPO3 instance uses deprecated XCLASS
857 * registrations via $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']
858 *
859 * @return Typo3_Bootstrap
860 */
861 public function deprecationLogForOldXclassRegistration() {
862 if (count($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']) > 0) {
863 t3lib_div::deprecationLog(
864 'This installation runs with extensions that use XCLASSing by setting the XCLASS path in ext_localconf.php. ' .
865 'This is deprecated and will be removed in TYPO3 6.2 and later. It is preferred to define XCLASSes in ' .
866 'ext_autoload.php instead. See http://wiki.typo3.org/Autoload for more information.'
867 );
868 }
869
870 return $this;
871 }
872
873 /**
874 * Initialize exception handling
875 *
876 * @return Typo3_Bootstrap
877 */
878 public function initializeExceptionHandling() {
879 if ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler'] !== '') {
880 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] !== '') {
881 // Register an error handler for the given errorHandlerErrors
882 $errorHandler = t3lib_div::makeInstance(
883 $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'],
884 $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors']
885 );
886 // Set errors which will be converted in an exception
887 $errorHandler->setExceptionalErrors($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionalErrors']);
888 }
889 // Instantiate the exception handler once to make sure object is registered
890 // @TODO: Figure out if this is really needed
891 t3lib_div::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']);
892 }
893
894 return $this;
895 }
896
897 /**
898 * Load some additional classes that are encapsulated in extensions
899 *
900 * @return Typo3_Bootstrap
901 */
902 public function requireAdditionalExtensionFiles() {
903 require_once(t3lib_extMgm::extPath('lang') . 'lang.php');
904
905 return $this;
906 }
907
908 /**
909 * Extensions may register new caches, so we set the
910 * global cache array to the manager again at this point
911 *
912 * @return Typo3_Bootstrap
913 */
914 public function setFinalCachingFrameworkCacheConfiguration() {
915 $GLOBALS['typo3CacheManager']->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
916
917 return $this;
918 }
919
920 /**
921 * Define logging and exception constants
922 *
923 * @return Typo3_Bootstrap
924 */
925 public function defineLoggingAndExceptionConstants() {
926 define('TYPO3_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']);
927 define('TYPO3_ERROR_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG']);
928 define('TYPO3_EXCEPTION_DLOG', $GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG']);
929
930 return $this;
931 }
932
933 /**
934 * Unsetting reserved global variables:
935 * Those which are/can be set in "stddb/tables.php" files:
936 *
937 * @return Typo3_Bootstrap
938 */
939 public function unsetReservedGlobalVariables() {
940 unset($GLOBALS['PAGES_TYPES']);
941 unset($GLOBALS['TCA']);
942 unset($GLOBALS['TBE_MODULES']);
943 unset($GLOBALS['TBE_STYLES']);
944 unset($GLOBALS['FILEICONS']);
945
946 // Those set in init.php:
947 unset($GLOBALS['WEBMOUNTS']);
948 unset($GLOBALS['FILEMOUNTS']);
949 unset($GLOBALS['BE_USER']);
950
951 // Those set otherwise:
952 unset($GLOBALS['TBE_MODULES_EXT']);
953 unset($GLOBALS['TCA_DESCR']);
954 unset($GLOBALS['LOCAL_LANG']);
955 unset($GLOBALS['TYPO3_AJAX']);
956
957 return $this;
958 }
959
960 /**
961 * Initialize some global time variables
962 *
963 * @return Typo3_Bootstrap
964 */
965 public function initializeGlobalTimeVariables() {
966 // $EXEC_TIME is set so that the rest of the script has a common value for the script execution time
967 $GLOBALS['EXEC_TIME'] = time();
968 // $SIM_EXEC_TIME is set to $EXEC_TIME but can be altered later in the script if we want to
969 // simulate another execution-time when selecting from eg. a database
970 $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
971 // $ACCESS_TIME is a common time in minutes for access control
972 $GLOBALS['ACCESS_TIME'] = $GLOBALS['EXEC_TIME'] - ($GLOBALS['EXEC_TIME'] % 60);
973 // If $SIM_EXEC_TIME is changed this value must be set accordingly
974 $GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
975
976 return $this;
977 }
978
979 /**
980 * Initialize t3lib_db in $GLOBALS and connect if requested
981 *
982 * @param bool $connect Whether or not the db should be connected already
983 * @return Typo3_Bootstrap
984 */
985 public function initializeTypo3DbGlobal($connect = TRUE) {
986 /** @var TYPO3_DB t3lib_db */
987 $GLOBALS['TYPO3_DB'] = t3lib_div::makeInstance('t3lib_DB');
988 $GLOBALS['TYPO3_DB']->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
989 if ($connect) {
990 $this->establishDatabaseConnection();
991 }
992
993 return $this;
994 }
995
996 /**
997 * Check adminOnly configuration variable and redirects
998 * to an URL in file typo3conf/LOCK_BACKEND or exit the script
999 *
1000 * @throws RuntimeException
1001 * @return Typo3_Bootstrap
1002 */
1003 public function checkLockedBackendAndRedirectOrDie() {
1004 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
1005 throw new RuntimeException(
1006 'TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly']) . '".',
1007 1294586847
1008 );
1009 }
1010 if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
1011 if (TYPO3_PROCEED_IF_NO_USER === 2) {
1012 // Ajax poll for login, let it pass
1013 } else {
1014 $fileContent = t3lib_div::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
1015 if ($fileContent) {
1016 header('Location: ' . $fileContent);
1017 } else {
1018 throw new RuntimeException(
1019 'TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.',
1020 1294586848
1021 );
1022 }
1023 exit;
1024 }
1025 }
1026
1027 return $this;
1028 }
1029
1030 /**
1031 * Compare client IP with IPmaskList and exit the script run
1032 * if the client is not allowed to access the backend
1033 *
1034 * @return Typo3_Bootstrap
1035 */
1036 public function checkBackendIpOrDie() {
1037 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
1038 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
1039 // Send Not Found header - if the webserver can make use of it
1040 header('Status: 404 Not Found');
1041 // Just point us away from here...
1042 header('Location: http://');
1043 // ... and exit good!
1044 exit;
1045 }
1046 }
1047
1048 return $this;
1049 }
1050
1051 /**
1052 * Check lockSSL configuration variable and redirect
1053 * to https version of the backend if needed
1054 *
1055 * @return Typo3_Bootstrap
1056 */
1057 public function checkSslBackendAndRedirectIfNeeded() {
1058 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
1059 if(intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
1060 $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
1061 } else {
1062 $sslPortSuffix = '';
1063 }
1064 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
1065 $requestStr = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
1066 if ($requestStr === 'index.php' && !t3lib_div::getIndpEnv('TYPO3_SSL')) {
1067 list(, $url) = explode('://', t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), 2);
1068 list($server, $address) = explode('/', $url, 2);
1069 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
1070 exit;
1071 }
1072 } elseif (!t3lib_div::getIndpEnv('TYPO3_SSL')) {
1073 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) === 2) {
1074 list(, $url) = explode('://', t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
1075 list($server, $address) = explode('/', $url, 2);
1076 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
1077 } else {
1078 // Send Not Found header - if the webserver can make use of it...
1079 header('Status: 404 Not Found');
1080 // Just point us away from here...
1081 header('Location: http://');
1082 }
1083 // ... and exit good!
1084 exit;
1085 }
1086 }
1087
1088 return $this;
1089 }
1090
1091 /**
1092 * Establish connection to the database
1093 *
1094 * @return Typo3_Bootstrap
1095 */
1096 public function establishDatabaseConnection() {
1097 $GLOBALS['TYPO3_DB']->connectDB();
1098
1099 return $this;
1100 }
1101
1102 /**
1103 * Load ext_tables and friends.
1104 *
1105 * This will mainly set up $TCA and several other global arrays
1106 * through API's like extMgm.
1107 * Executes ext_tables.php files of loaded extensions or the
1108 * according typo3conf/temp_CACHED_*_ext_tables.php if exists.
1109 *
1110 * Note: For backwards compatibility some global variables are
1111 * explicitly set as global to be used without $GLOBALS[] in
1112 * ext_tables.php. It is discouraged to access variables like
1113 * $TBE_MODULES directly in ext_tables.php, but we can not prohibit
1114 * this without heavily breaking backwards compatibility.
1115 * @TODO: We could write a scheduler / reports module or an update checker
1116 * that hints extension authors about discouraged direct variable access.
1117 *
1118 * Note: include / require are used instead of include_once / require_once on
1119 * purpose here: in FE (tslib_fe), this method here can be loaded mulitple times
1120 *
1121 * @TODO: It should be defined, which global arrays are ok to be manipulated
1122 *
1123 * @return Typo3_Bootstrap
1124 */
1125 public function loadExtensionTables() {
1126 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
1127 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
1128 global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
1129
1130 // Include standard tables.php file
1131 require(PATH_t3lib . 'stddb/tables.php');
1132
1133 if (
1134 $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE']
1135 && file_exists(PATH_typo3conf . $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] . '_ext_tables.php')
1136 ) {
1137 // Load temp_CACHED_x_ext_tables.php file if exists
1138 require(PATH_typo3conf . $GLOBALS['TYPO3_LOADED_EXT']['_CACHEFILE'] . '_ext_tables.php');
1139 } else {
1140 // Load each ext_tables.php file of loaded extensions
1141 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $_EXTKEY => $extensionInformation) {
1142 if (is_array($extensionInformation) && $extensionInformation['ext_tables.php']) {
1143 // $_EXTKEY and $_EXTCONF are available in ext_tables.php
1144 // and are explicitly set in temp_CACHED file as well
1145 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
1146 require($extensionInformation['ext_tables.php']);
1147 }
1148 }
1149 }
1150
1151 // Load additional ext tables script if registered
1152 if (TYPO3_extTableDef_script) {
1153 include(PATH_typo3conf . TYPO3_extTableDef_script);
1154 }
1155
1156 // Run post hook for additional manipulation
1157 $this->runExtTablesPostProcessingHooks();
1158
1159 return $this;
1160 }
1161
1162 /**
1163 * Check for registered ext tables hooks and run them
1164 *
1165 * @throws UnexpectedValueException
1166 * @return Typo3_Bootstrap
1167 */
1168 protected function runExtTablesPostProcessingHooks() {
1169 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
1170 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
1171 /** @var $hookObject t3lib_extTables_PostProcessingHook */
1172 $hookObject = t3lib_div::getUserObj($classReference);
1173 if (!$hookObject instanceof t3lib_extTables_PostProcessingHook) {
1174 throw new UnexpectedValueException('$hookObject must implement interface t3lib_extTables_PostProcessingHook', 1320585902);
1175 }
1176 $hookObject->processData();
1177 }
1178 }
1179
1180 return $this;
1181 }
1182
1183 /**
1184 * Initialize sprite manager global
1185 *
1186 * @param bool $allowRegeneration
1187 * @return Typo3_Bootstrap
1188 */
1189 public function initializeSpriteManager($allowRegeneration = TRUE) {
1190 /** @var $spriteManager t3lib_SpriteManager */
1191 $GLOBALS['spriteManager'] = t3lib_div::makeInstance('t3lib_SpriteManager', $allowRegeneration);
1192 $GLOBALS['spriteManager']->loadCacheFile();
1193
1194 return $this;
1195 }
1196
1197 /**
1198 * Initialize backend user object in globals
1199 *
1200 * @return Typo3_Bootstrap
1201 */
1202 public function initializeBackendUser() {
1203 /** @var $backendUser t3lib_beUserAuth */
1204 $backendUser = t3lib_div::makeInstance('t3lib_beUserAuth');
1205 $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
1206 $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
1207 $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
1208 $backendUser->OS = TYPO3_OS;
1209 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
1210 $backendUser->dontSetCookie = TRUE;
1211 }
1212 $backendUser->start();
1213 $backendUser->checkCLIuser();
1214 $backendUser->backendCheckLogin();
1215 $GLOBALS['BE_USER'] = $backendUser;
1216
1217 return $this;
1218 }
1219
1220 /**
1221 * Initialize backend user mount points
1222 *
1223 * @return Typo3_Bootstrap
1224 */
1225 public function initializeBackendUserMounts() {
1226 // Includes deleted mount pages as well! @TODO: Figure out why ...
1227 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
1228 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->returnFilemounts();
1229
1230 return $this;
1231 }
1232
1233 /**
1234 * Initialize language object
1235 *
1236 * @return Typo3_Bootstrap
1237 */
1238 public function initializeLanguageObject() {
1239 /** @var $GLOBALS['LANG'] language */
1240 $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
1241 $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
1242
1243 return $this;
1244 }
1245
1246 /**
1247 * Throw away all output that may have happened during bootstrapping by weird extensions
1248 *
1249 * @return Typo3_Bootstrap
1250 */
1251 public function endOutputBufferingAndCleanPreviousOutput() {
1252 ob_clean();
1253
1254 return $this;
1255 }
1256
1257 /**
1258 * Initialize output compression if configured
1259 *
1260 * @return Typo3_Bootstrap
1261 */
1262 public function initializeOutputCompression() {
1263 if (extension_loaded('zlib') && $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']) {
1264 if (t3lib_utility_Math::canBeInterpretedAsInteger($GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'])) {
1265 @ini_set('zlib.output_compression_level', $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel']);
1266 }
1267 ob_start('ob_gzhandler');
1268 }
1269
1270 return $this;
1271 }
1272
1273 /**
1274 * Things that should be performed to shut down the framework.
1275 * This method is called in all important scripts for a clean
1276 * shut down of the system.
1277 *
1278 * @return Typo3_Bootstrap
1279 */
1280 public function shutdown() {
1281 t3lib_autoloader::unregisterAutoloader();
1282
1283 return $this;
1284 }
1285
1286 /**
1287 * Check php version requirement or exit script
1288 *
1289 * @return void
1290 */
1291 protected function checkPhpVersionOrDie() {
1292 if (version_compare(phpversion(), '5.3', '<')) {
1293 die('TYPO3 requires PHP 5.3.0 or higher.');
1294 }
1295 }
1296
1297 /**
1298 * Exit script if globals are set via post or get
1299 *
1300 * @return void
1301 */
1302 protected function checkGlobalsAreNotSetViaPostOrGet() {
1303 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
1304 die('You cannot set the GLOBALS array from outside the script.');
1305 }
1306 }
1307
1308 /**
1309 * Determine the operating system TYPO3 is running on.
1310 *
1311 * @return string Either 'WIN' if running on Windows, else empty string
1312 */
1313 protected function getTypo3Os() {
1314 $typoOs = '';
1315 if (!stristr(PHP_OS, 'darwin') && stristr(PHP_OS, 'win')) {
1316 $typoOs = 'WIN';
1317 }
1318 return $typoOs;
1319 }
1320
1321 /**
1322 * Calculate PATH_thisScript
1323 *
1324 * First step in path calculation: Goal is to find the absolute path of the entry script
1325 * that was called without resolving any links. This is important since the TYPO3 entry
1326 * points are often linked to a central core location, so we can not use the php magic
1327 * __FILE__ here, but resolve the called script path from given server environments.
1328 *
1329 * This path is important to calculate the document root (PATH_site). The strategy is to
1330 * find out the script name that was called in the first place and to subtract the local
1331 * part from it to find the document root.
1332 *
1333 * @return string Absolute path to entry script
1334 */
1335 protected function getPathThisScript() {
1336 if (defined('TYPO3_cliMode') && TYPO3_cliMode === TRUE) {
1337 return $this->getPathThisScriptCli();
1338 } else {
1339 return $this->getPathThisScriptNonCli();
1340 }
1341 }
1342
1343 /**
1344 * Calculate path to entry script if not in cli mode.
1345 *
1346 * Depending on the environment, the script path is found in different $_SERVER variables.
1347 *
1348 * @return string Absolute path to entry script
1349 */
1350 protected function getPathThisScriptNonCli() {
1351 $cgiPath = '';
1352 if (isset($_SERVER['ORIG_PATH_TRANSLATED'])) {
1353 $cgiPath = $_SERVER['ORIG_PATH_TRANSLATED'];
1354 } elseif (isset($_SERVER['PATH_TRANSLATED'])) {
1355 $cgiPath = $_SERVER['PATH_TRANSLATED'];
1356 }
1357 if ($cgiPath && (PHP_SAPI === 'fpm-fcgi' || PHP_SAPI === 'cgi' || PHP_SAPI === 'isapi' || PHP_SAPI === 'cgi-fcgi')) {
1358 $scriptPath = $cgiPath;
1359 } else {
1360 if (isset($_SERVER['ORIG_SCRIPT_FILENAME'])) {
1361 $scriptPath = $_SERVER['ORIG_SCRIPT_FILENAME'];
1362 } else {
1363 $scriptPath = $_SERVER['SCRIPT_FILENAME'];
1364 }
1365 }
1366 // Replace \ to / for Windows
1367 $scriptPath = str_replace('\\', '/', $scriptPath);
1368 // Replace double // to /
1369 $scriptPath = str_replace('//', '/', $scriptPath);
1370
1371 return $scriptPath;
1372 }
1373
1374 /**
1375 * Calculate path to entry script if in cli mode.
1376 *
1377 * First argument of a cli script is the path to the script that was called. If the script does not start
1378 * with / (or A:\ for Windows), the path is not absolute yet, and the current working directory is added.
1379 *
1380 * @return string Absolute path to entry script
1381 */
1382 protected function getPathThisScriptCli() {
1383 // Possible relative path of the called script
1384 if (isset($_SERVER['argv'][0])) {
1385 $scriptPath = $_SERVER['argv'][0];
1386 } elseif (isset($_ENV['_'])) {
1387 $scriptPath = $_ENV['_'];
1388 } else {
1389 $scriptPath = $_SERVER['_'];
1390 }
1391
1392 // Find out if path is relative or not
1393 $isRelativePath = FALSE;
1394 if (TYPO3_OS === 'WIN') {
1395 if (!preg_match('/^([A-Z]:)?\\\/', $scriptPath)) {
1396 $isRelativePath = TRUE;
1397 }
1398 } else {
1399 if (substr($scriptPath, 0, 1) !== '/') {
1400 $isRelativePath = TRUE;
1401 }
1402 }
1403
1404 // Concatenate path to current working directory with relative path and remove "/./" constructs
1405 if ($isRelativePath) {
1406 if (isset($_SERVER['PWD'])) {
1407 $workingDirectory = $_SERVER['PWD'];
1408 } else {
1409 $workingDirectory = getcwd();
1410 }
1411 $scriptPath = $workingDirectory . '/' . preg_replace('/\.\//', '', $scriptPath);
1412 }
1413
1414 return $scriptPath;
1415 }
1416
1417 /**
1418 * Calculate the document root part to the instance from PATH_thisScript
1419 *
1420 * There are two ways to hint correct calculation:
1421 * Either an explicit specified sub path or the defined constant TYPO3_MOD_PATH. Which one is
1422 * used depends on which entry script was called in the first place.
1423 *
1424 * We have two main scenarios for entry points:
1425 * - Directly called documentRoot/index.php (-> FE call or eiD include): index.php sets $relativePathPart to
1426 * empty string to hint this code that the document root is identical to the directory the script is located at.
1427 * - An indirect include of typo3/init.php (-> a backend module, the install tool, or scripts like thumbs.php).
1428 * If init.php is included we distinguish two cases:
1429 * -- A backend module defines 'TYPO3_MOD_PATH': This is the case for "old" modules that are not called through
1430 * "mod.php" dispatcher, and in the install tool. The TYPO3_MOD_PATH defines the relative path to the typo3/
1431 * directory. This is taken as base to calculate the document root.
1432 * -- A script includes init.php and does not define 'TYPO3_MOD_PATH': This is the case for the mod.php dispatcher
1433 * and other entry scripts like 'cli_dispatch.phpsh' or 'thumbs.php' that are located parallel to init.php. In
1434 * this case init.php sets 'typo3/' as $relativePathPart as base to calculate the document root.
1435 *
1436 * This basically boils down to the following code:
1437 * If TYPO3_MOD_PATH is defined, subtract this 'local' part from the entry point directory, else use
1438 * $relativePathPart to subtract this from the the script entry point to find out the document root.
1439 *
1440 * @param string $relativePathPart Relative directory part from document root to script path if TYPO3_MOD_PATH is not used
1441 * @return string Absolute path to document root of installation
1442 */
1443 protected function getPathSite($relativePathPart) {
1444 // If end of path is not "typo3/" and TYPO3_MOD_PATH is given
1445 if (defined('TYPO3_MOD_PATH')) {
1446 return $this->getPathSiteByTypo3ModulePath();
1447 } else {
1448 return $this->getPathSiteByRelativePathPart($relativePathPart);
1449 }
1450 }
1451
1452 /**
1453 * Calculate document root by TYPO3_MOD_PATH
1454 *
1455 * TYPO3_MOD_PATH can have the following values:
1456 * - "sysext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3/sysext
1457 * - "ext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3/ext
1458 * - "../typo3conf/ext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3conf/ext
1459 *- "install/index.php" -> install tool in 'docRoot'/typo3/install/
1460 *
1461 * The method unifies the above and subtracts the calculated path part from PATH_thisScript
1462 *
1463 * @return string Absolute path to document root of installation
1464 */
1465 protected function getPathSiteByTypo3ModulePath() {
1466 if (
1467 substr(TYPO3_MOD_PATH, 0, strlen('sysext/')) === 'sysext/'
1468 || substr(TYPO3_MOD_PATH, 0, strlen('ext/')) === 'ext/'
1469 || substr(TYPO3_MOD_PATH, 0, strlen('install/')) === 'install/'
1470 ) {
1471 $pathPartRelativeToDocumentRoot = TYPO3_mainDir . TYPO3_MOD_PATH;
1472 } elseif (substr(TYPO3_MOD_PATH, 0, strlen('../typo3conf/')) === '../typo3conf/') {
1473 $pathPartRelativeToDocumentRoot = substr(TYPO3_MOD_PATH, 3);
1474 } else {
1475 die('Unable to determine TYPO3 document root.');
1476 }
1477
1478 $entryScriptDirectory = $this->getUnifiedDirectoryNameWithTrailingSlash(PATH_thisScript);
1479
1480 return substr($entryScriptDirectory, 0, -strlen($pathPartRelativeToDocumentRoot));
1481 }
1482
1483 /**
1484 * Find out document root by subtracting $relativePathPart from PATH_thisScript
1485 *
1486 * @param string $relativePathPart Relative part of script from document root
1487 * @return string Absolute path to document root of installation
1488 */
1489 protected function getPathSiteByRelativePathPart($relativePathPart) {
1490 $entryScriptDirectory = $this->getUnifiedDirectoryNameWithTrailingSlash(PATH_thisScript);
1491 if (strlen($relativePathPart) > 0) {
1492 $pathSite = substr($entryScriptDirectory, 0, -strlen($relativePathPart));
1493 } else {
1494 $pathSite = $entryScriptDirectory;
1495 }
1496 return $pathSite;
1497 }
1498
1499 /**
1500 * Remove file name from script path and unify for Windows and Unix
1501 *
1502 * @param string $absolutePath Absolute path to script
1503 * @return string Directory name of script file location, unified for Windows and Unix
1504 */
1505 protected function getUnifiedDirectoryNameWithTrailingSlash($absolutePath) {
1506 $directory = dirname($absolutePath);
1507 if (TYPO3_OS === 'WIN') {
1508 $directory = str_replace('\\', '/', $directory);
1509 }
1510 return $directory . '/';
1511 }
1512
1513 /**
1514 * Check if path and script file name calculation was successful, exit if not.
1515 *
1516 * @return void
1517 */
1518 protected function checkMainPathsExist() {
1519 if (!is_file(PATH_thisScript)) {
1520 die('Unable to determine path to entry script.');
1521 }
1522 if (!is_dir(PATH_t3lib)) {
1523 die('Calculated absolute path to t3lib directory does not exist.');
1524 }
1525 if (!is_dir(PATH_tslib)) {
1526 die('Calculated absolute path to tslib directory does not exist.');
1527 }
1528 if (!is_dir(PATH_typo3conf)) {
1529 die('Calculated absolute path to typo3conf directory does not exist');
1530 }
1531 }
1532
1533 /**
1534 * Provides an instance of "template" for backend-modules to
1535 * work with.
1536 *
1537 * @return Typo3_Bootstrap
1538 */
1539 public function initializeBackendTemplate() {
1540 $GLOBALS['TBE_TEMPLATE'] = t3lib_div::makeInstance('template');
1541
1542 return $this;
1543 }
1544
1545 }
1546 ?>