Allow opening folder lisings on client
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
This commit is contained in:
43
Path.php
43
Path.php
@@ -103,6 +103,49 @@ class Path
|
||||
return $pathInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a real filesystem path back to a configured alias, if available.
|
||||
*
|
||||
* Example: root "/share/Datascape/" with alias "/Scape/" maps
|
||||
* "/share/Datascape/some/folder" -> "/Scape/some/folder".
|
||||
*
|
||||
* If no alias matches, the input path is returned unchanged (except for
|
||||
* normalization of slashes and dot-segments).
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function mapToAliasPath($path)
|
||||
{
|
||||
if (!is_string($path) || $path === '') return $path;
|
||||
|
||||
// normalize input for matching, but do not force a trailing slash
|
||||
$normalized = static::cleanPath($path, false);
|
||||
|
||||
// collect root->alias mappings (avoid alias keys that reference the same config)
|
||||
$mappings = [];
|
||||
foreach ($this->paths as $key => $info) {
|
||||
if (!isset($info['root']) || $key !== $info['root']) continue;
|
||||
if (empty($info['alias'])) continue;
|
||||
$mappings[$info['root']] = $info['alias'];
|
||||
}
|
||||
|
||||
if ($mappings === []) return $normalized;
|
||||
|
||||
// Prefer the longest matching root (handles nested/overlapping roots)
|
||||
uksort($mappings, static fn($a, $b) => strlen($b) - strlen($a));
|
||||
|
||||
foreach ($mappings as $root => $alias) {
|
||||
if (str_starts_with($normalized, $root)) {
|
||||
$suffix = substr($normalized, strlen($root));
|
||||
$alias = static::cleanPath($alias, true);
|
||||
return rtrim($alias, '/') . '/' . $suffix;
|
||||
}
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean a path for better comparison
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user