From 0c28d683f53668ff268c86e349ce948cb075eb86 Mon Sep 17 00:00:00 2001 From: axelalex2 <39660135+axelalex2@users.noreply.github.com> Date: Sat, 27 Apr 2019 19:22:42 +0200 Subject: [PATCH] New function to help resolve not-found files/directories (#217) * ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP * fixed unregister-functions of CallbackManager * Reducing menuItemHeight in Configurator to avoid overlapping of the menu items * Fully rebuild the admins menu after a player rights changed * Added function to FileUtil to improve realpath, so symbolic links can be resolved * Fixed indentation * Update FileUtil.php Fixed error in case of an absolute path on Unix-like systems. --- core/Files/FileUtil.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/Files/FileUtil.php b/core/Files/FileUtil.php index 9d48b4a2..ca079e11 100644 --- a/core/Files/FileUtil.php +++ b/core/Files/FileUtil.php @@ -236,4 +236,31 @@ abstract class FileUtil { public static function isHiddenFile($fileName) { return (substr($fileName, 0, 1) === '.'); } + + /** + * Shortens a path. + * Opposed to realpath, it follows symbolic links. + * + * @param string $path + * @return string + */ + public static function shortenPath(string $path) { + $root = substr($path, 0, 1) === '/'; + $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); + $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen'); + $absolutes = array(); + foreach ($parts as $part) { + if ('.' === $part) + continue; + + if ('..' === $part) + array_pop($absolutes); + else + array_push($absolutes, $part); + } + $path = implode(DIRECTORY_SEPARATOR, $absolutes); + if ($root) + $path = '/'.$path; + return $path; + } }