From: Vincent Vanwaelscappel Date: Thu, 16 Feb 2023 11:19:40 +0000 (+0100) Subject: wip #5718 @0:10 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=71ddb096305947864888d71a40c93abcc88bdd2e;p=cubist_util.git wip #5718 @0:10 --- diff --git a/src/Files/Files.php b/src/Files/Files.php index 192ea84..3ca3392 100644 --- a/src/Files/Files.php +++ b/src/Files/Files.php @@ -3,6 +3,7 @@ namespace Cubist\Util\Files; use Cubist\Util\CommandLine; +use Cubist\Util\Text; class Files { @@ -340,5 +341,31 @@ class Files } } + public static function tidyName($f) + { + $f = Text::cleanUTF8($f, '-'); + $path = explode('/', $f); + $file = array_pop($path); + $f = explode('.', $file); + if (count($f) > 1) { + $ext = array_pop($f); + $name = implode('-', $f); + } else { + $ext = null; + $name = $f[0]; + } + + $r = []; + foreach ($path as $p) { + $r[] = Text::str2URL($p); + } + $n = Text::str2URL($name); + if (!is_null($ext)) { + $n .= '.' . $ext; + } + $r[] = $n; + return implode('/', $r); + } + } \ No newline at end of file