]> _ Git - cubist_util.git/commitdiff
wip #5718 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Feb 2023 11:19:40 +0000 (12:19 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Feb 2023 11:19:40 +0000 (12:19 +0100)
src/Files/Files.php

index 192ea845b3facbd64cc0d33ebc6158b337fbac3a..3ca33920ff682d8a941db0080d1b3c251ee6ee61 100644 (file)
@@ -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