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