[RELEASE] Release of TYPO3 6.0.8
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Core / SystemEnvironmentBuilder.php
1 <?php
2 namespace TYPO3\CMS\Core\Core;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Class to encapsulate base setup of bootstrap.
32 *
33 * This class contains all code that must be executed by every entry script.
34 *
35 * It sets up all basic paths, constants, global variables and checks
36 * the basic environment TYPO3 runs in.
37 *
38 * This class does not use any TYPO3 instance specific configuration, it only
39 * sets up things based on the server environment and core code. Even with a
40 * missing typo3conf/localconf.php this script will be successful.
41 *
42 * The script aborts execution with an error message if
43 * some part fails or conditions are not met.
44 *
45 * This script is internal code and subject to change.
46 * DO NOT use it in own code, or be prepared your code might
47 * break in future versions of the core.
48 */
49 class SystemEnvironmentBuilder {
50
51 /**
52 * Run base setup.
53 * This entry method is used in all scopes (FE, BE, eid, ajax, ...)
54 *
55 * @internal This method should not be used by 3rd party code. It will change without further notice.
56 * @param string $relativePathPart Relative path of the entry script back to document root
57 * @return void
58 */
59 static public function run($relativePathPart = '') {
60 self::ensureRequiredEnvironment();
61 self::checkGlobalsAreNotSetViaPostOrGet();
62 self::defineBaseConstants();
63 self::definePaths($relativePathPart);
64 self::checkMainPathsExist();
65 self::requireBaseClasses();
66 self::setupClassAliasForLegacyBaseClasses();
67 self::handleMagicQuotesGpc();
68 self::addCorePearPathToIncludePath();
69 self::initializeGlobalVariables();
70 self::initializeGlobalTimeTrackingVariables();
71 self::initializeBasicErrorReporting();
72 }
73
74 /**
75 * Check php version requirement or exit script
76 *
77 * @return void
78 */
79 static protected function ensureRequiredEnvironment() {
80 if (version_compare(phpversion(), '5.3', '<')) {
81 die('TYPO3 requires PHP 5.3.0 or higher.');
82 }
83 if (self::getPhpIniValueBoolean('register_globals')) {
84 die('TYPO3 requires PHP setting "register_globals" set to Off. (Error: #1345284320)');
85 }
86 }
87
88 /**
89 * Cast a on/off php ini value to boolean
90 *
91 * @param string $configOption
92 * @return boolean TRUE if the given option is enabled, FALSE if disabled
93 * @see t3lib_utility_PhpOptions::getIniValueBoolean
94 */
95 static protected function getPhpIniValueBoolean($configOption) {
96 return filter_var(ini_get($configOption), FILTER_VALIDATE_BOOLEAN, array(FILTER_REQUIRE_SCALAR, FILTER_NULL_ON_FAILURE));
97 }
98
99 /**
100 * Exit script if globals are set via post or get
101 *
102 * @return void
103 */
104 static protected function checkGlobalsAreNotSetViaPostOrGet() {
105 if (isset($_POST['GLOBALS']) || isset($_GET['GLOBALS'])) {
106 die('You cannot set the GLOBALS array from outside the script.');
107 }
108 }
109
110 /**
111 * Define all simple constants that have no dependency to local configuration
112 *
113 * @return void
114 */
115 static protected function defineBaseConstants() {
116 // This version, branch and copyright
117 define('TYPO3_version', '6.0.8');
118 define('TYPO3_branch', '6.0');
119 define('TYPO3_copyright_year', '1998-2013');
120
121 // TYPO3 external links
122 define('TYPO3_URL_GENERAL', 'http://typo3.org/');
123 define('TYPO3_URL_ORG', 'http://typo3.org/');
124 define('TYPO3_URL_LICENSE', 'http://typo3.org/licenses');
125 define('TYPO3_URL_EXCEPTION', 'http://typo3.org/go/exception/CMS/');
126 define('TYPO3_URL_MAILINGLISTS', 'http://lists.typo3.org/cgi-bin/mailman/listinfo');
127 define('TYPO3_URL_DOCUMENTATION', 'http://typo3.org/documentation/');
128 define('TYPO3_URL_DOCUMENTATION_TSREF', 'http://docs.typo3.org/typo3cms/TyposcriptReference/');
129 define('TYPO3_URL_DOCUMENTATION_TSCONFIG', 'http://docs.typo3.org/typo3cms/TSconfigReference/');
130 define('TYPO3_URL_CONSULTANCY', 'http://typo3.org/support/professional-services/');
131 define('TYPO3_URL_CONTRIBUTE', 'http://typo3.org/contribute/');
132 define('TYPO3_URL_SECURITY', 'http://typo3.org/teams/security/');
133 define('TYPO3_URL_DOWNLOAD', 'http://typo3.org/download/');
134 define('TYPO3_URL_SYSTEMREQUIREMENTS', 'http://typo3.org/about/typo3-the-cms/system-requirements/');
135 define('TYPO3_URL_DONATE', 'http://typo3.org/donate/online-donation/');
136
137 // A tabulator, a linefeed, a carriage return, a CR-LF combination
138 define('TAB', chr(9));
139 define('LF', chr(10));
140 define('CR', chr(13));
141 define('CRLF', CR . LF);
142
143 // Security related constant: Default value of fileDenyPattern
144 define('FILE_DENY_PATTERN_DEFAULT', '\\.(php[3-6]?|phpsh|phtml)(\\..*)?$|^\\.htaccess$');
145 // Security related constant: List of file extensions that should be registered as php script file extensions
146 define('PHP_EXTENSIONS_DEFAULT', 'php,php3,php4,php5,php6,phpsh,inc,phtml');
147
148 // List of extensions required to run the core
149 define('REQUIRED_EXTENSIONS', 'core,backend,frontend,cms,lang,sv,extensionmanager,recordlist,extbase,fluid,cshmanual,install');
150
151 // Operating system identifier
152 // Either "WIN" or empty string
153 define('TYPO3_OS', self::getTypo3Os());
154
155 // Service error constants
156 // General error - something went wrong
157 define('T3_ERR_SV_GENERAL', -1);
158 // During execution it showed that the service is not available and should be ignored. The service itself should call $this->setNonAvailable()
159 define('T3_ERR_SV_NOT_AVAIL', -2);
160 // Passed subtype is not possible with this service
161 define('T3_ERR_SV_WRONG_SUBTYPE', -3);
162 // Passed subtype is not possible with this service
163 define('T3_ERR_SV_NO_INPUT', -4);
164 // File not found which the service should process
165 define('T3_ERR_SV_FILE_NOT_FOUND', -20);
166 // File not readable
167 define('T3_ERR_SV_FILE_READ', -21);
168 // File not writable
169 define('T3_ERR_SV_FILE_WRITE', -22);
170 // Passed subtype is not possible with this service
171 define('T3_ERR_SV_PROG_NOT_FOUND', -40);
172 // Passed subtype is not possible with this service
173 define('T3_ERR_SV_PROG_FAILED', -41);
174 }
175
176 /**
177 * Calculate all required base paths and set as constants.
178 *
179 * @param string $relativePathPart Relative path of the entry script back to document root
180 * @return void
181 */
182 static protected function definePaths($relativePathPart = '') {
183 // Relative path from document root to typo3/ directory
184 // Hardcoded to "typo3/"
185 define('TYPO3_mainDir', 'typo3/');
186 // Absolute path of the entry script that was called
187 // All paths are unified between Windows and Unix, so the \ of Windows is substituted to a /
188 // Example "/var/www/instance-name/htdocs/typo3conf/ext/wec_map/mod1/index.php"
189 // Example "c:/var/www/instance-name/htdocs/typo3/backend.php" for a path in Windows
190 define('PATH_thisScript', self::getPathThisScript());
191 // Absolute path of the document root of the instance with trailing slash
192 // Example "/var/www/instance-name/htdocs/"
193 define('PATH_site', self::getPathSite($relativePathPart));
194 // Absolute path of the typo3 directory of the instance with trailing slash
195 // Example "/var/www/instance-name/htdocs/typo3/"
196 define('PATH_typo3', PATH_site . TYPO3_mainDir);
197 // Relative path (from the PATH_typo3) to a BE module NOT using mod.php dispatcher with trailing slash
198 // Example "sysext/perms/mod/" for an extension installed in typo3/sysext/
199 // Example "install/" for the install tool entry script
200 // Example "../typo3conf/ext/templavoila/mod2/ for an extension installed in typo3conf/ext/
201 define('PATH_typo3_mod', defined('TYPO3_MOD_PATH') ? TYPO3_MOD_PATH : '');
202 // Absolute path to the t3lib directory with trailing slash
203 // Example "/var/www/instance-name/htdocs/t3lib/"
204 define('PATH_t3lib', PATH_site . 't3lib/');
205 // Absolute path to the typo3conf directory with trailing slash
206 // Example "/var/www/instance-name/htdocs/typo3conf/"
207 define('PATH_typo3conf', PATH_site . 'typo3conf/');
208 // Absolute path to the tslib directory with trailing slash
209 // Example "/var/www/instance-name/htdocs/typo3/sysext/cms/tslib/"
210 define('PATH_tslib', PATH_typo3 . 'sysext/cms/tslib/');
211 }
212
213 /**
214 * Check if path and script file name calculation was successful, exit if not.
215 *
216 * @return void
217 */
218 static protected function checkMainPathsExist() {
219 if (!is_file(PATH_thisScript)) {
220 die('Unable to determine path to entry script.');
221 }
222 if (!is_dir(PATH_t3lib)) {
223 die('Calculated absolute path to t3lib directory does not exist.');
224 }
225 if (!is_dir(PATH_tslib)) {
226 die('Calculated absolute path to tslib directory does not exist.');
227 }
228 if (!is_dir(PATH_typo3conf)) {
229 die('Calculated absolute path to typo3conf directory does not exist');
230 }
231 }
232
233 /**
234 * Load several base classes during bootstrap
235 *
236 * @return void
237 */
238 static protected function requireBaseClasses() {
239 require_once __DIR__ . '/../Utility/GeneralUtility.php';
240 require_once __DIR__ . '/../Utility/ArrayUtility.php';
241 require_once __DIR__ . '/../SingletonInterface.php';
242 require_once __DIR__ . '/../Configuration/ConfigurationManager.php';
243 require_once __DIR__ . '/../Utility/ExtensionManagementUtility.php';
244 require_once __DIR__ . '/../Cache/Cache.php';
245 require_once __DIR__ . '/../Cache/Exception.php';
246 require_once __DIR__ . '/../Cache/Exception/NoSuchCacheException.php';
247 require_once __DIR__ . '/../Cache/Exception/InvalidDataException.php';
248 require_once __DIR__ . '/../Cache/CacheFactory.php';
249 require_once __DIR__ . '/../Cache/CacheManager.php';
250 require_once __DIR__ . '/../Cache/Frontend/FrontendInterface.php';
251 require_once __DIR__ . '/../Cache/Frontend/AbstractFrontend.php';
252 require_once __DIR__ . '/../Cache/Frontend/StringFrontend.php';
253 require_once __DIR__ . '/../Cache/Frontend/PhpFrontend.php';
254 require_once __DIR__ . '/../Cache/Backend/BackendInterface.php';
255 require_once __DIR__ . '/../Cache/Backend/TaggableBackendInterface.php';
256 require_once __DIR__ . '/../Cache/Backend/AbstractBackend.php';
257 require_once __DIR__ . '/../Cache/Backend/PhpCapableBackendInterface.php';
258 require_once __DIR__ . '/../Cache/Backend/SimpleFileBackend.php';
259 require_once __DIR__ . '/../Cache/Backend/NullBackend.php';
260 require_once __DIR__ . '/../Log/LogLevel.php';
261 require_once __DIR__ . '/../Utility/MathUtility.php';
262 require_once __DIR__ . '/ClassLoader.php';
263 if (PHP_VERSION_ID < 50307) {
264 require_once __DIR__ . '/../Compatibility/CompatbilityClassLoaderPhpBelow50307.php';
265 }
266 }
267
268 /**
269 * Compatibility layer for early t3lib_div or t3lib_extMgm usage
270 *
271 * @return void
272 * @deprecated since 6.0, will be removed in 6.2
273 * @see t3lib/class.t3lib_div.php, t3lib/class.t3lib_extmgm.php
274 */
275 static public function setupClassAliasForLegacyBaseClasses() {
276 class_alias('TYPO3\\CMS\\Core\\Utility\\GeneralUtility', 't3lib_div');
277 class_alias('TYPO3\\CMS\\Core\\Utility\\ExtensionManagementUtility', 't3lib_extMgm');
278 }
279
280 /**
281 * Compatibility layer for magic quotes
282 *
283 * @return void
284 */
285 static protected function handleMagicQuotesGpc() {
286 if (!get_magic_quotes_gpc()) {
287 \TYPO3\CMS\Core\Utility\GeneralUtility::addSlashesOnArray($_GET);
288 \TYPO3\CMS\Core\Utility\GeneralUtility::addSlashesOnArray($_POST);
289 $GLOBALS['HTTP_GET_VARS'] = $_GET;
290 $GLOBALS['HTTP_POST_VARS'] = $_POST;
291 }
292 }
293
294 /**
295 * Add typo3/contrib/pear/ as first include folder in
296 * include path, because the shipped PEAR packages use
297 * relative paths to include their files.
298 *
299 * This is required for t3lib_http_Request to work.
300 *
301 * Having the TYPO3 folder first will make sure that the
302 * shipped version is loaded before any local PEAR package,
303 * thus avoiding any incompatibilities with newer or older
304 * versions.
305 *
306 * @return void
307 */
308 static protected function addCorePearPathToIncludePath() {
309 set_include_path(PATH_typo3 . 'contrib/pear/' . PATH_SEPARATOR . get_include_path());
310 }
311
312 /**
313 * Set up / initialize several globals variables
314 *
315 * @return void
316 */
317 static protected function initializeGlobalVariables() {
318 // Unset variable(s) in global scope (security issue #13959)
319 unset($GLOBALS['error']);
320 // Set up base information about browser/user-agent
321 $GLOBALS['CLIENT'] = \TYPO3\CMS\Core\Utility\GeneralUtility::clientInfo();
322 $GLOBALS['TYPO3_MISC'] = array();
323 $GLOBALS['T3_VAR'] = array();
324 $GLOBALS['T3_SERVICES'] = array();
325 }
326
327 /**
328 * Initialize global time tracking variables.
329 * These are helpers to for example output script parsetime at the end of a script.
330 *
331 * @return void
332 */
333 static protected function initializeGlobalTimeTrackingVariables() {
334 // Set PARSETIME_START to the system time in milliseconds.
335 $GLOBALS['PARSETIME_START'] = \TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds();
336 // Microtime of (nearly) script start
337 $GLOBALS['TYPO3_MISC']['microtime_start'] = microtime(TRUE);
338 // EXEC_TIME is set so that the rest of the script has a common value for the script execution time
339 $GLOBALS['EXEC_TIME'] = time();
340 // $ACCESS_TIME is a common time in minutes for access control
341 $GLOBALS['ACCESS_TIME'] = $GLOBALS['EXEC_TIME'] - $GLOBALS['EXEC_TIME'] % 60;
342 // $SIM_EXEC_TIME is set to $EXEC_TIME but can be altered later in the script if we want to
343 // simulate another execution-time when selecting from eg. a database
344 $GLOBALS['SIM_EXEC_TIME'] = $GLOBALS['EXEC_TIME'];
345 // If $SIM_EXEC_TIME is changed this value must be set accordingly
346 $GLOBALS['SIM_ACCESS_TIME'] = $GLOBALS['ACCESS_TIME'];
347 }
348
349 /**
350 * Initialize basic error reporting.
351 *
352 * There are a lot of extensions that have no strict / notice / deprecated free
353 * ext_localconf or ext_tables. Since the final error reporting must be set up
354 * after those extension files are read, a default configuration is needed to
355 * suppress error reporting meanwhile during further bootstrap.
356 *
357 * @return void
358 */
359 static protected function initializeBasicErrorReporting() {
360 // Core should be notice free at least until this point ...
361 error_reporting(E_ALL & ~(E_STRICT | E_NOTICE | E_DEPRECATED));
362 }
363
364 /**
365 * Determine the operating system TYPO3 is running on.
366 *
367 * @return string Either 'WIN' if running on Windows, else empty string
368 */
369 static protected function getTypo3Os() {
370 $typoOs = '';
371 if (!stristr(PHP_OS, 'darwin') && stristr(PHP_OS, 'win')) {
372 $typoOs = 'WIN';
373 }
374 return $typoOs;
375 }
376
377 /**
378 * Calculate PATH_thisScript
379 *
380 * First step in path calculation: Goal is to find the absolute path of the entry script
381 * that was called without resolving any links. This is important since the TYPO3 entry
382 * points are often linked to a central core location, so we can not use the php magic
383 * __FILE__ here, but resolve the called script path from given server environments.
384 *
385 * This path is important to calculate the document root (PATH_site). The strategy is to
386 * find out the script name that was called in the first place and to subtract the local
387 * part from it to find the document root.
388 *
389 * @return string Absolute path to entry script
390 */
391 static protected function getPathThisScript() {
392 if (defined('TYPO3_cliMode') && TYPO3_cliMode === TRUE) {
393 return self::getPathThisScriptCli();
394 } else {
395 return self::getPathThisScriptNonCli();
396 }
397 }
398
399 /**
400 * Calculate path to entry script if not in cli mode.
401 *
402 * Depending on the environment, the script path is found in different $_SERVER variables.
403 *
404 * @return string Absolute path to entry script
405 */
406 static protected function getPathThisScriptNonCli() {
407 $cgiPath = '';
408 if (isset($_SERVER['ORIG_PATH_TRANSLATED'])) {
409 $cgiPath = $_SERVER['ORIG_PATH_TRANSLATED'];
410 } elseif (isset($_SERVER['PATH_TRANSLATED'])) {
411 $cgiPath = $_SERVER['PATH_TRANSLATED'];
412 }
413 if ($cgiPath && (PHP_SAPI === 'fpm-fcgi' || PHP_SAPI === 'cgi' || PHP_SAPI === 'isapi' || PHP_SAPI === 'cgi-fcgi')) {
414 $scriptPath = $cgiPath;
415 } else {
416 if (isset($_SERVER['ORIG_SCRIPT_FILENAME'])) {
417 $scriptPath = $_SERVER['ORIG_SCRIPT_FILENAME'];
418 } else {
419 $scriptPath = $_SERVER['SCRIPT_FILENAME'];
420 }
421 }
422 // Replace \ to / for Windows
423 $scriptPath = str_replace('\\', '/', $scriptPath);
424 // Replace double // to /
425 $scriptPath = str_replace('//', '/', $scriptPath);
426 return $scriptPath;
427 }
428
429 /**
430 * Calculate path to entry script if in cli mode.
431 *
432 * First argument of a cli script is the path to the script that was called. If the script does not start
433 * with / (or A:\ for Windows), the path is not absolute yet, and the current working directory is added.
434 *
435 * @return string Absolute path to entry script
436 */
437 static protected function getPathThisScriptCli() {
438 // Possible relative path of the called script
439 if (isset($_SERVER['argv'][0])) {
440 $scriptPath = $_SERVER['argv'][0];
441 } elseif (isset($_ENV['_'])) {
442 $scriptPath = $_ENV['_'];
443 } else {
444 $scriptPath = $_SERVER['_'];
445 }
446 // Find out if path is relative or not
447 $isRelativePath = FALSE;
448 if (TYPO3_OS === 'WIN') {
449 if (!preg_match('/^([A-Z]:)?\\\\/', $scriptPath)) {
450 $isRelativePath = TRUE;
451 }
452 } else {
453 if (substr($scriptPath, 0, 1) !== '/') {
454 $isRelativePath = TRUE;
455 }
456 }
457 // Concatenate path to current working directory with relative path and remove "/./" constructs
458 if ($isRelativePath) {
459 if (isset($_SERVER['PWD'])) {
460 $workingDirectory = $_SERVER['PWD'];
461 } else {
462 $workingDirectory = getcwd();
463 }
464 $scriptPath = $workingDirectory . '/' . preg_replace('/\\.\\//', '', $scriptPath);
465 }
466 return $scriptPath;
467 }
468
469 /**
470 * Calculate the document root part to the instance from PATH_thisScript
471 *
472 * There are two ways to hint correct calculation:
473 * Either an explicit specified sub path or the defined constant TYPO3_MOD_PATH. Which one is
474 * used depends on which entry script was called in the first place.
475 *
476 * We have two main scenarios for entry points:
477 * - Directly called documentRoot/index.php (-> FE call or eiD include): index.php sets $relativePathPart to
478 * empty string to hint this code that the document root is identical to the directory the script is located at.
479 * - An indirect include of typo3/init.php (-> a backend module, the install tool, or scripts like thumbs.php).
480 * If init.php is included we distinguish two cases:
481 * -- A backend module defines 'TYPO3_MOD_PATH': This is the case for "old" modules that are not called through
482 * "mod.php" dispatcher, and in the install tool. The TYPO3_MOD_PATH defines the relative path to the typo3/
483 * directory. This is taken as base to calculate the document root.
484 * -- A script includes init.php and does not define 'TYPO3_MOD_PATH': This is the case for the mod.php dispatcher
485 * and other entry scripts like 'cli_dispatch.phpsh' or 'thumbs.php' that are located parallel to init.php. In
486 * this case init.php sets 'typo3/' as $relativePathPart as base to calculate the document root.
487 *
488 * This basically boils down to the following code:
489 * If TYPO3_MOD_PATH is defined, subtract this 'local' part from the entry point directory, else use
490 * $relativePathPart to subtract this from the the script entry point to find out the document root.
491 *
492 * @param string $relativePathPart Relative directory part from document root to script path if TYPO3_MOD_PATH is not used
493 * @return string Absolute path to document root of installation
494 */
495 static protected function getPathSite($relativePathPart) {
496 // If end of path is not "typo3/" and TYPO3_MOD_PATH is given
497 if (defined('TYPO3_MOD_PATH')) {
498 return self::getPathSiteByTypo3ModulePath();
499 } else {
500 return self::getPathSiteByRelativePathPart($relativePathPart);
501 }
502 }
503
504 /**
505 * Calculate document root by TYPO3_MOD_PATH
506 *
507 * TYPO3_MOD_PATH can have the following values:
508 * - "sysext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3/sysext
509 * - "ext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3/ext
510 * - "../typo3conf/ext/extensionName/path/entryScript.php" -> extension is below 'docRoot'/typo3conf/ext
511 * - "install/index.php" -> install tool in 'docRoot'/typo3/install/
512 *
513 * The method unifies the above and subtracts the calculated path part from PATH_thisScript
514 *
515 * @return string Absolute path to document root of installation
516 */
517 static protected function getPathSiteByTypo3ModulePath() {
518 if (substr(TYPO3_MOD_PATH, 0, strlen('sysext/')) === 'sysext/' || substr(TYPO3_MOD_PATH, 0, strlen('ext/')) === 'ext/' || substr(TYPO3_MOD_PATH, 0, strlen('install/')) === 'install/') {
519 $pathPartRelativeToDocumentRoot = TYPO3_mainDir . TYPO3_MOD_PATH;
520 } elseif (substr(TYPO3_MOD_PATH, 0, strlen('../typo3conf/')) === '../typo3conf/') {
521 $pathPartRelativeToDocumentRoot = substr(TYPO3_MOD_PATH, 3);
522 } else {
523 die('Unable to determine TYPO3 document root.');
524 }
525 $entryScriptDirectory = self::getUnifiedDirectoryNameWithTrailingSlash(PATH_thisScript);
526 return substr($entryScriptDirectory, 0, -strlen($pathPartRelativeToDocumentRoot));
527 }
528
529 /**
530 * Find out document root by subtracting $relativePathPart from PATH_thisScript
531 *
532 * @param string $relativePathPart Relative part of script from document root
533 * @return string Absolute path to document root of installation
534 */
535 static protected function getPathSiteByRelativePathPart($relativePathPart) {
536 $entryScriptDirectory = self::getUnifiedDirectoryNameWithTrailingSlash(PATH_thisScript);
537 if (strlen($relativePathPart) > 0) {
538 $pathSite = substr($entryScriptDirectory, 0, -strlen($relativePathPart));
539 } else {
540 $pathSite = $entryScriptDirectory;
541 }
542 return $pathSite;
543 }
544
545 /**
546 * Remove file name from script path and unify for Windows and Unix
547 *
548 * @param string $absolutePath Absolute path to script
549 * @return string Directory name of script file location, unified for Windows and Unix
550 */
551 static protected function getUnifiedDirectoryNameWithTrailingSlash($absolutePath) {
552 $directory = dirname($absolutePath);
553 if (TYPO3_OS === 'WIN') {
554 $directory = str_replace('\\', '/', $directory);
555 }
556 return $directory . '/';
557 }
558
559 }
560
561
562 ?>