[TASK] CGL cleanup in bootstrap
[Packages/TYPO3.CMS.git] / typo3 / 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 /**
46 * Check several a priori conditions like the current
47 * php version or exit the script with an error.
48 *
49 * @return void
50 */
51 public static function checkEnvironmentOrDie() {
52 self::checkPhpVersionOrDie();
53 self::checkGlobalsAreNotSetViaPostOrGet();
54 }
55
56 /**
57 * Define all simple base constants
58 *
59 * @return void
60 */
61 public static function defineBaseConstants() {
62 // This version, branch and copyright
63 define('TYPO3_version', '6.0-dev');
64 define('TYPO3_branch', '6.0');
65 define('TYPO3_copyright_year', '1998-2012');
66
67 // TYPO3 external links
68 define('TYPO3_URL_GENERAL', 'http://typo3.org/');
69 define('TYPO3_URL_ORG', 'http://typo3.org/');
70 define('TYPO3_URL_LICENSE', 'http://typo3.org/licenses');
71 define('TYPO3_URL_EXCEPTION', 'http://typo3.org/go/exception/v4/');
72 define('TYPO3_URL_MAILINGLISTS', 'http://lists.typo3.org/cgi-bin/mailman/listinfo');
73 define('TYPO3_URL_DOCUMENTATION', 'http://typo3.org/documentation/');
74 define('TYPO3_URL_DOCUMENTATION_TSREF', 'http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/current/view/');
75 define('TYPO3_URL_DOCUMENTATION_TSCONFIG', 'http://typo3.org/documentation/document-library/core-documentation/doc_core_tsconfig/current/view/');
76 define('TYPO3_URL_CONSULTANCY', 'http://typo3.org/support/professional-services/');
77 define('TYPO3_URL_CONTRIBUTE', 'http://typo3.org/contribute/');
78 define('TYPO3_URL_SECURITY', 'http://typo3.org/teams/security/');
79 define('TYPO3_URL_DOWNLOAD', 'http://typo3.org/download/');
80 define('TYPO3_URL_SYSTEMREQUIREMENTS', 'http://typo3.org/about/typo3-the-cms/system-requirements/');
81 define('TYPO3_URL_DONATE', 'http://typo3.org/donate/online-donation/');
82
83 // A tabulator, a linefeed, a carriage return, a CR-LF combination
84 define('TAB', chr(9));
85 define('LF', chr(10));
86 define('CR', chr(13));
87 define('CRLF', CR . LF);
88
89 // Security related constant: Default value of fileDenyPattern
90 define('FILE_DENY_PATTERN_DEFAULT', '\.(php[3-6]?|phpsh|phtml)(\..*)?$|^\.htaccess$');
91
92 // Security related constant: List of file extensions that should be registered as php script file extensions
93 define('PHP_EXTENSIONS_DEFAULT', 'php,php3,php4,php5,php6,phpsh,inc,phtml');
94
95 // List of extensions required to run the core
96 define('REQUIRED_EXTENSIONS', 'cms,lang,sv,em,recordlist,extbase,fluid');
97
98 // Operating system identifier
99 // Either "WIN" or empty string
100 define('TYPO3_OS', self::getTypo3Os());
101 }
102
103 /**
104 * Calculate all required base paths and set as constants.
105 * The script execution will be aborted if this fails.
106 *
107 * @param string $relativePathPart The relative path of the entry script to the document root
108 * @return void
109 */
110 public static function defineAndCheckPaths($relativePathPart = '') {
111 // Relative path from document root to typo3/ directory
112 // Hardcoded to "typo3/"
113 define('TYPO3_mainDir', 'typo3/');
114
115 // Absolute path of the entry script that was called
116 // All paths are unified between Windows and Unix, so the \ of Windows is substituted to a /
117 // Example "/var/www/instance-name/htdocs/typo3conf/ext/wec_map/mod1/index.php"
118 // Example "c:/var/www/instance-name/htdocs/typo3/backend.php" for a path in Windows
119 define('PATH_thisScript', self::getPathThisScript());
120
121 // Absolute path of the document root of the instance with trailing slash
122 // Example "/var/www/instance-name/htdocs/"
123 define('PATH_site', self::getPathSite($relativePathPart));
124
125 // Absolute path of the typo3 directory of the instance with trailing slash
126 // Example "/var/www/instance-name/htdocs/typo3/"
127 define('PATH_typo3', PATH_site . TYPO3_mainDir);
128
129 // Relative path (from the PATH_typo3) to a BE module NOT using mod.php dispatcher with trailing slash
130 // Example "sysext/perms/mod/" for an extension installed in typo3/sysext/
131 // Example "install/" for the install tool entry script
132 // Example "../typo3conf/ext/templavoila/mod2/ for an extension installed in typo3conf/ext/
133 define('PATH_typo3_mod', defined('TYPO3_MOD_PATH') ? TYPO3_MOD_PATH : '');
134
135 // Absolute path to the t3lib directory with trailing slash
136 // Example "/var/www/instance-name/htdocs/t3lib/"
137 define('PATH_t3lib', PATH_site . 't3lib/');
138
139 // Absolute path to the typo3conf directory with trailing slash
140 // Example "/var/www/instance-name/htdocs/typo3conf/"
141 define('PATH_typo3conf', PATH_site . 'typo3conf/');
142
143 // Absolute path to the tslib directory with trailing slash
144 // Example "/var/www/instance-name/htdocs/typo3/sysext/cms/tslib/"
145 define('PATH_tslib', PATH_typo3 . 'sysext/cms/tslib/');
146
147 // Check above defines and exit with error message on error
148 self::checkMainPathsExist();
149 }
150
151 /**
152 * Load several base classes during bootstrap
153 *
154 * @return void
155 */
156 public static function requireBaseClasses() {
157 require_once(PATH_t3lib . 'class.t3lib_div.php');
158 require_once(PATH_t3lib . 'class.t3lib_extmgm.php');
159 }
160
161 /**
162 * Set up php error reporting and various things like time tracking
163 *
164 * @return void
165 */
166 public static function setUpEnvironment() {
167 // Core should be notice free at least until this point ...
168 // @TODO: Move further down / get rid of it until errorHandler is initialized
169 error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
170
171 // Unset variable(s) in global scope (security issue #13959)
172 unset($GLOBALS['error']);
173
174 // Include information about the browser/user-agent
175 $GLOBALS['CLIENT'] = t3lib_div::clientInfo();
176
177 // Is set to the system time in milliseconds.
178 // This could be used to output script parsetime in the end of the script
179 $GLOBALS['PARSETIME_START'] = t3lib_div::milliseconds();
180 $GLOBALS['TYPO3_MISC'] = array();
181 $GLOBALS['TYPO3_MISC']['microtime_start'] = microtime(TRUE);
182
183 // Compatibility layer for magic quotes
184 if (!get_magic_quotes_gpc()) {
185 t3lib_div::addSlashesOnArray($_GET);
186 t3lib_div::addSlashesOnArray($_POST);
187 $GLOBALS['HTTP_GET_VARS'] = $_GET;
188 $GLOBALS['HTTP_POST_VARS'] = $_POST;
189 }
190 }
191
192 /**
193 * Initialize t3lib_db in $GLOBALS and connect if requested
194 *
195 * @param bool $connect Whether or not the db should be connected already
196 * @return void
197 */
198 public static function initializeTypo3DbGlobal($connect = TRUE) {
199 /** @var TYPO3_DB t3lib_db */
200 $GLOBALS['TYPO3_DB'] = t3lib_div::makeInstance('t3lib_DB');
201 $GLOBALS['TYPO3_DB']->debugOutput = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sqlDebug'];
202 if ($connect) {
203 $GLOBALS['TYPO3_DB']->connectDB();
204 }
205 }
206
207 /**
208 * Check adminOnly configuration variable and redirects
209 * to an URL in file typo3conf/LOCK_BACKEND or exit the script
210 *
211 * @throws RuntimeException
212 * @return void
213 */
214 public static function checkLockedBackendAndRedirectOrDie() {
215 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
216 throw new RuntimeException(
217 'TYPO3 Backend locked: Backend and Install Tool are locked for maintenance. [BE][adminOnly] is set to "' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly']) . '".',
218 1294586847
219 );
220 }
221 if (@is_file(PATH_typo3conf . 'LOCK_BACKEND')) {
222 if (TYPO3_PROCEED_IF_NO_USER === 2) {
223 // Ajax poll for login, let it pass
224 } else {
225 $fileContent = t3lib_div::getUrl(PATH_typo3conf . 'LOCK_BACKEND');
226 if ($fileContent) {
227 header('Location: ' . $fileContent);
228 } else {
229 throw new RuntimeException(
230 'TYPO3 Backend locked: Browser backend is locked for maintenance. Remove lock by removing the file "typo3conf/LOCK_BACKEND" or use CLI-scripts.',
231 1294586848
232 );
233 }
234 exit;
235 }
236 }
237 }
238
239 /**
240 * Compare client IP with IPmaskList and exit the script run
241 * if the client is not allowed to access the backend
242 *
243 * @return void
244 */
245 public static function checkBackendIpOrDie() {
246 if (trim($GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
247 if (!t3lib_div::cmpIP(t3lib_div::getIndpEnv('REMOTE_ADDR'), $GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
248 // Send Not Found header - if the webserver can make use of it
249 header('Status: 404 Not Found');
250 // Just point us away from here...
251 header('Location: http://');
252 // ... and exit good!
253 exit;
254 }
255 }
256 }
257
258 /**
259 * Check lockSSL configuration variable and redirect
260 * to https version of the backend if needed
261 *
262 * @return void
263 */
264 public static function checkSslBackendAndRedirectIfNeeded() {
265 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'])) {
266 if(intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort'])) {
267 $sslPortSuffix = ':' . intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
268 } else {
269 $sslPortSuffix = '';
270 }
271 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] == 3) {
272 $requestStr = substr(t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT'), strlen(t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir));
273 if ($requestStr === 'index.php' && !t3lib_div::getIndpEnv('TYPO3_SSL')) {
274 list(,$url) = explode('://', t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'), 2);
275 list($server, $address) = explode('/', $url, 2);
276 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
277 exit;
278 }
279 } elseif (!t3lib_div::getIndpEnv('TYPO3_SSL')) {
280 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL']) === 2) {
281 list(,$url) = explode('://', t3lib_div::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir, 2);
282 list($server, $address) = explode('/', $url, 2);
283 header('Location: https://' . $server . $sslPortSuffix . '/' . $address);
284 } else {
285 // Send Not Found header - if the webserver can make use of it...
286 header('Status: 404 Not Found');
287 // Just point us away from here...
288 header('Location: http://');
289 }
290 // ... and exit good!
291 exit;
292 }
293 }
294 }
295
296 /**
297 * Check for registered ext tables hooks and run them
298 *
299 * @throws UnexpectedValueException
300 * @return void
301 */
302 public static function runExtTablesPostProcessingHooks() {
303 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'])) {
304 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['extTablesInclusion-PostProcessing'] as $classReference) {
305 /** @var $hookObject t3lib_extTables_PostProcessingHook */
306 $hookObject = t3lib_div::getUserObj($classReference);
307 if (!$hookObject instanceof t3lib_extTables_PostProcessingHook) {
308 throw new UnexpectedValueException('$hookObject must implement interface t3lib_extTables_PostProcessingHook', 1320585902);
309 }
310 $hookObject->processData();
311 }
312 }
313 }
314
315 /**
316 * Initialize sprite manager global
317 *
318 * @param bool $allowRegeneration
319 * @return void
320 */
321 public static function initializeSpriteManager($allowRegeneration = TRUE) {
322 /** @var $spriteManager t3lib_SpriteManager */
323 $GLOBALS['spriteManager'] = t3lib_div::makeInstance('t3lib_SpriteManager', $allowRegeneration);
324 $GLOBALS['spriteManager']->loadCacheFile();
325 }
326
327 /**
328 * Initialize backend user object in globals
329 *
330 * @return void
331 */
332 public static function initializeBackendUser() {
333 /** @var $backendUser t3lib_beUserAuth */
334 $backendUser = t3lib_div::makeInstance('t3lib_beUserAuth');
335 $backendUser->warningEmail = $GLOBALS['TYPO3_CONF_VARS']['BE']['warning_email_addr'];
336 $backendUser->lockIP = $GLOBALS['TYPO3_CONF_VARS']['BE']['lockIP'];
337 $backendUser->auth_timeout_field = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout']);
338 $backendUser->OS = TYPO3_OS;
339 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI) {
340 $backendUser->dontSetCookie = TRUE;
341 }
342 $backendUser->start();
343 $backendUser->checkCLIuser();
344 $backendUser->backendCheckLogin();
345 $GLOBALS['BE_USER'] = $backendUser;
346 }
347
348 /**
349 * Initialize backend user mount points
350 *
351 * @return void
352 */
353 public static function initializeBackendUserMounts() {
354 // Includes deleted mount pages as well! @TODO: Figure out why ...
355 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
356 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->returnFilemounts();
357 }
358
359 /**
360 * Initialize language object
361 *
362 * @return void
363 */
364 public static function initializeLanguageObject() {
365 /** @var $GLOBALS['LANG'] language */
366 $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
367 $GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
368 }
369
370 /**
371 * Check php version requirement or exit script
372 *
373 * @return void
374 */
375 protected static function checkPhpVersionOrDie() {
376 if (version_compare(phpversion(), '5.3', '<')) {
377 die('TYPO3 requires PHP 5.3.0 or higher.');
378 }
379 }
380
381 /**
382 * Exit script if globals are set via post or get
383 *
384 * @return void
385 */
386 protected static function checkGlobalsAreNotSetViaPostOrGet() {
387 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
388 die('You cannot set the GLOBALS array from outside the script.');
389 }
390 }
391
392 /**
393 * Determine the operating system TYPO3 is running on.
394 *
395 * @return string Either 'WIN' if running on Windows, else empty string
396 */
397 protected static function getTypo3Os() {
398 $typoOs = '';
399 if (!stristr(PHP_OS, 'darwin') && stristr(PHP_OS, 'win')) {
400 $typoOs = 'WIN';
401 }
402 return $typoOs;
403 }
404
405 /**
406 * Calculate PATH_thisScript
407 *
408 * First step in path calculation: Goal is to find the absolute path of the entry script
409 * that was called without resolving any links. This is important since the TYPO3 entry
410 * points are often linked to a central core location, so we can not use the php magic
411 * __FILE__ here, but resolve the called script path from given server environments.
412 *
413 * This path is important to calculate the document root (PATH_site). The strategy is to
414 * find out the script name that was called in the first place and to subtract the local
415 * part from it to find the document root.
416 *
417 * @return string Absolute path to entry script
418 */
419 protected static function getPathThisScript() {
420 if (defined('TYPO3_cliMode') && TYPO3_cliMode === TRUE) {
421 return self::getPathThisScriptCli();
422 } else {
423 return self::getPathThisScriptNonCli();
424 }
425 }
426
427 /**
428 * Calculate path to entry script if not in cli mode.
429 *
430 * Depending on the environment, the script path is found in different $_SERVER variables.
431 *
432 * @return string Absolute path to entry script
433 */
434 protected static function getPathThisScriptNonCli() {
435 $cgiPath = '';
436 if (isset($_SERVER['ORIG_PATH_TRANSLATED'])) {
437 $cgiPath = $_SERVER['ORIG_PATH_TRANSLATED'];
438 } elseif (isset($_SERVER['PATH_TRANSLATED'])) {
439 $cgiPath = $_SERVER['PATH_TRANSLATED'];
440 }
441 if ($cgiPath && (PHP_SAPI === 'fpm-fcgi' || PHP_SAPI === 'cgi' || PHP_SAPI === 'isapi' || PHP_SAPI === 'cgi-fcgi')) {
442 $scriptPath = $cgiPath;
443 } else {
444 if (isset($_SERVER['ORIG_SCRIPT_FILENAME'])) {
445 $scriptPath = $_SERVER['ORIG_SCRIPT_FILENAME'];
446 } else {
447 $scriptPath = $_SERVER['SCRIPT_FILENAME'];
448 }
449 }
450 // Replace \ to / for Windows
451 $scriptPath = str_replace('\\', '/', $scriptPath);
452 // Replace double // to /
453 $scriptPath = str_replace('//', '/', $scriptPath);
454
455 return $scriptPath;
456 }
457
458 /**
459 * Calculate path to entry script if in cli mode.
460 *
461 * First argument of a cli script is the path to the script that was called. If the script does not start
462 * with / (or A:\ for Windows), the path is not absolute yet, and the current working directory is added.
463 *
464 * @return string Absolute path to entry script
465 */
466 protected static function getPathThisScriptCli() {
467 // Possible relative path of the called script
468 if (isset($_SERVER['argv'][0])) {
469 $scriptPath = $_SERVER['argv'][0];
470 } elseif (isset($_ENV['_'])) {
471 $scriptPath = $_ENV['_'];
472 } else {
473 $scriptPath = $_SERVER['_'];
474 }
475
476 // Find out if path is relative or not
477 $isRelativePath = FALSE;
478 if (TYPO3_OS === 'WIN') {
479 if (!preg_match('/^([A-Z]:)?\\\/', $scriptPath)) {
480 $isRelativePath = TRUE;
481 }
482 } else {
483 if (substr($scriptPath, 0, 1) !== '/') {
484 $isRelativePath = TRUE;
485 }
486 }
487
488 // Concatenate path to current working directory with relative path and remove "/./" constructs
489 if ($isRelativePath) {
490 if (isset($_SERVER['PWD'])) {
491 $workingDirectory = $_SERVER['PWD'];
492 } else {
493 $workingDirectory = getcwd();
494 }
495 $scriptPath = $workingDirectory . '/' . preg_replace('/\.\//', '', $scriptPath);
496 }
497
498 return $scriptPath;
499 }
500
501 /**
502 * Calculate the document root part to the instance from PATH_thisScript
503 *
504 * There are two ways to hint correct calculation:
505 * Either an explicit specified sub path or the defined constant TYPO3_MOD_PATH. Which one is
506 * used depends on which entry script was called in the first place.
507 *
508 * We have two main scenarios for entry points:
509 * - Directly called documentRoot/index.php (-> FE call or eiD include): index.php sets $relativePathPart to
510 * empty string to hint this code that the document root is identical to the directory the script is located at.
511 * - An indirect include of typo3/init.php (-> a backend module, the install tool, or scripts like thumbs.php).
512 * If init.php is included we distinguish two cases:
513 * -- A backend module defines 'TYPO3_MOD_PATH': This is the case for "old" modules that are not called through
514 * "mod.php" dispatcher, and in the install tool. The TYPO3_MOD_PATH defines the relative path to the typo3/
515 * directory. This is taken as base to calculate the document root.
516 * -- A script includes init.php and does not define 'TYPO3_MOD_PATH': This is the case for the mod.php dispatcher
517 * and other entry scripts like 'cli_dispatch.phpsh' or 'thumbs.php' that are located parallel to init.php. In
518 * this case init.php sets 'typo3/' as $relativePathPart as base to calculate the document root.
519 *
520 * This basically boils down to the following code:
521 * If TYPO3_MOD_PATH is defined, subtract this 'local' part from the entry point directory, else use
522 * $relativePathPart to subtract this from the the script entry point to find out the document root.
523 *
524 * @param string $relativePathPart Relative directory part from document root to script path if TYPO3_MOD_PATH is not used
525 * @return string Absolute path to document root of installation
526 */
527 protected static function getPathSite($relativePathPart) {
528 // If end of path is not "typo3/" and TYPO3_MOD_PATH is given
529 if (defined('TYPO3_MOD_PATH')) {
530 return self::getPathSiteByTypo3ModulePath();
531 } else {
532 return self::getPathSiteByRelativePathPart($relativePathPart);
533 }
534 }
535
536 /**
537 * Calculate document root by TYPO3_MOD_PATH
538 *
539 * TYPO3_MOD_PATH can have the following values:
540 * - "sysext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3/sysext
541 * - "ext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3/ext
542 * - "../typo3conf/ext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3conf/ext
543 *- "install/index.php" -> install tool in 'docRoot'/typo3/install/
544 *
545 * The method unifies the above and subtracts the calculated path part from PATH_thisScript
546 *
547 * @return string Absolute path to document root of installation
548 */
549 protected static function getPathSiteByTypo3ModulePath() {
550 if (
551 substr(TYPO3_MOD_PATH, 0, strlen('sysext/')) === 'sysext/'
552 || substr(TYPO3_MOD_PATH, 0, strlen('ext/')) === 'ext/'
553 || substr(TYPO3_MOD_PATH, 0, strlen('install/')) === 'install/'
554 ) {
555 $pathPartRelativeToDocumentRoot = TYPO3_mainDir . TYPO3_MOD_PATH;
556 } elseif (substr(TYPO3_MOD_PATH, 0, strlen('../typo3conf/')) === '../typo3conf/') {
557 $pathPartRelativeToDocumentRoot = substr(TYPO3_MOD_PATH, 3);
558 } else {
559 die('Unable to determine TYPO3 document root.');
560 }
561
562 $entryScriptDirectory = self::getUnifiedDirectoryNameWithTrailingSlash(PATH_thisScript);
563
564 return substr($entryScriptDirectory, 0, -strlen($pathPartRelativeToDocumentRoot));
565 }
566
567 /**
568 * Find out document root by subtracting $relativePathPart from PATH_thisScript
569 *
570 * @param string $relativePathPart Relative part of script from document root
571 * @return string Absolute path to document root of installation
572 */
573 protected static function getPathSiteByRelativePathPart($relativePathPart) {
574 $entryScriptDirectory = self::getUnifiedDirectoryNameWithTrailingSlash(PATH_thisScript);
575 if (strlen($relativePathPart) > 0) {
576 $pathSite = substr($entryScriptDirectory, 0, -strlen($relativePathPart));
577 } else {
578 $pathSite = $entryScriptDirectory;
579 }
580 return $pathSite;
581 }
582
583 /**
584 * Remove file name from script path and unify for Windows and Unix
585 *
586 * @param string $absolutePath Absolute path to script
587 * @return string Directory name of script file location, unified for Windows and Unix
588 */
589 protected static function getUnifiedDirectoryNameWithTrailingSlash($absolutePath) {
590 $directory = dirname($absolutePath);
591 if (TYPO3_OS === 'WIN') {
592 $directory = str_replace('\\', '/', $directory);
593 }
594 return $directory . '/';
595 }
596
597 /**
598 * Check if path and script file name calculation was successful, exit if not.
599 *
600 * @return void
601 */
602 protected static function checkMainPathsExist() {
603 if (!is_file(PATH_thisScript)) {
604 die('Unable to determine path to entry script.');
605 }
606 if (!is_dir(PATH_t3lib)) {
607 die('Calculated absolute path to t3lib directory does not exist.');
608 }
609 if (!is_dir(PATH_tslib)) {
610 die('Calculated absolute path to tslib directory does not exist.');
611 }
612 if (!is_dir(PATH_typo3conf)) {
613 die('Calculated absolute path to typo3conf directory does not exist');
614 }
615 }
616 }
617 ?>