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