2 namespace TYPO3\CMS\Core\Utility;
31 return self::getRelativePath(
dirname(PATH_thisScript), $targetPath);
42 if (self::isAbsolutePath($targetPath)) {
44 $targetPath = self::stripPathSitePrefix($targetPath);
45 if (!defined(
'TYPO3_cliMode')) {
49 }
elseif (strpos($targetPath,
'://') !==
false) {
54 $targetPath = self::stripPathSitePrefix($targetPath);
55 if (!defined(
'TYPO3_cliMode')) {
75 if ($sourcePath !== $targetPath) {
76 $commonPrefix = self::getCommonPrefix(array($sourcePath, $targetPath));
78 $commonPrefixLength = strlen($commonPrefix);
79 $resolvedSourcePath =
'';
80 $resolvedTargetPath =
'';
82 if (strlen($sourcePath) > $commonPrefixLength) {
83 $resolvedSourcePath = (string)substr($sourcePath, $commonPrefixLength);
85 if (strlen($targetPath) > $commonPrefixLength) {
86 $resolvedTargetPath = (string)substr($targetPath, $commonPrefixLength);
88 if ($resolvedSourcePath !==
'') {
89 $sourcePathSteps = count(explode(
'/', $resolvedSourcePath));
91 $relativePath = self::sanitizeTrailingSeparator(str_repeat(
'../', $sourcePathSteps) . $resolvedTargetPath);
109 $paths = array_map(array(\TYPO3\CMS\Core\Utility\GeneralUtility::class,
'fixWindowsFilePath'), $paths);
111 if (count($paths) === 1) {
112 $commonPath = array_shift($paths);
113 }
elseif (count($paths) > 1) {
114 $parts = explode(
'/', array_shift($paths));
117 foreach ($parts as $part) {
118 $comparePath .= $part .
'/';
119 foreach ($paths as $path) {
120 if (strpos($path .
'/', $comparePath) !== 0) {
128 $commonPath = $comparePath;
131 if ($commonPath !== null) {
132 $commonPath = self::sanitizeTrailingSeparator($commonPath,
'/');
147 return rtrim($path, $separator) . $separator;
165 $currentLocale = setlocale(LC_CTYPE, 0);
166 setlocale(LC_CTYPE,
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLocale']);
168 setlocale(LC_CTYPE, $currentLocale);
187 $currentLocale = setlocale(LC_CTYPE, 0);
188 setlocale(LC_CTYPE,
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLocale']);
190 setlocale(LC_CTYPE, $currentLocale);
208 public static function pathinfo($path, $options = null)
210 $currentLocale = setlocale(LC_CTYPE, 0);
211 setlocale(LC_CTYPE,
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'systemLocale']);
213 setlocale(LC_CTYPE, $currentLocale);
226 if (static::isWindows() && (substr($path, 1, 2) ===
':/' || substr($path, 1, 2) ===
':\\')) {
230 return $path[0] ===
'/';
258 $fileName = static::basename($includeFileName);
259 $basePath = substr($baseFilenameOrPath, -1) ===
'/' ? $baseFilenameOrPath : static::dirname($baseFilenameOrPath);
260 $newDir = static::getCanonicalPath($basePath .
'/' . static::dirname($includeFileName));
262 $result = (($newDir !==
'/') ? $newDir :
'') .
'/' . $fileName;
281 $path = trim(str_replace(
'\\',
'/', $path));
285 if (strpos($path,
'://') !==
false) {
286 list($protocol, $path) = explode(
'://', $path);
290 $absolutePathPrefix =
'';
291 if (static::isAbsolutePath($path)) {
292 if (static::isWindows() && substr($path, 1, 2) ===
':/') {
293 $absolutePathPrefix = substr($path, 0, 3);
294 $path = substr($path, 3);
296 $path = ltrim($path,
'/');
297 $absolutePathPrefix =
'/';
301 $theDirParts = explode(
'/', $path);
302 $theDirPartsCount = count($theDirParts);
303 for ($partCount = 0; $partCount < $theDirPartsCount; $partCount++) {
305 if ($theDirParts[$partCount] ===
'') {
306 array_splice($theDirParts, $partCount, 1);
311 if ($theDirParts[$partCount] ===
'.') {
312 array_splice($theDirParts, $partCount, 1);
317 if ($theDirParts[$partCount] ===
'..') {
318 if ($partCount >= 1) {
320 array_splice($theDirParts, $partCount - 1, 2);
322 $theDirPartsCount -= 2;
323 }
elseif ($absolutePathPrefix) {
326 array_splice($theDirParts, $partCount, 1);
333 return $protocol . $absolutePathPrefix . implode(
'/', $theDirParts);
345 static $pathSiteLength = null;
348 if (!isset($pathSiteLength)) {
349 $pathSiteLength = strlen(PATH_site);
351 return substr($path, $pathSiteLength);
367 return TYPO3_OS ===
'WIN';