Allow opening folder lisings on client
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled

This commit is contained in:
2026-01-06 10:13:12 +01:00
parent 30bb9e3bbd
commit dbc9de37e0
4 changed files with 84 additions and 2 deletions

View File

@@ -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
*