]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update mapper.php
authorinfoneo <infoneo@yahoo.pl>
Sat, 8 Jun 2013 15:39:25 +0000 (18:39 +0300)
committerinfoneo <infoneo@yahoo.pl>
Sat, 8 Jun 2013 15:39:25 +0000 (18:39 +0300)
Now slugify is performed on whole filename (including extension). Changed method of adding index number (using regular expressions pathinfo() method removed).

lib/files/mapper.php

index d9e116bf25b88b267aa66cfdf5e2f2162786d9b5..748b65dc4f120af77758caa66de8ce36b653343d 100644 (file)
@@ -174,26 +174,7 @@ class Mapper
                $sluggedElements = array();
                
                $last= end($pathElements);
-               $parts = pathinfo($last);
                
-               $filename = $parts['filename'];
-               $extension = $parts['extension'];
-
-                       
-               if ((preg_match('~[-\w]+~', $filename)) && (preg_match('~[-\w]+~', $extension))){
-                       
-               // rip off the extension ext from last element
-               array_pop($pathElements);
-               array_push($pathElements, $filename);
-                       
-               } else {
-                       
-                       if (isset($parts['extension'])) {
-                               unset($parts['extension']);
-                               }
-      
-               } 
-
                foreach ($pathElements as $pathElement) {
                        // remove empty elements
                        if (empty($pathElement)) {
@@ -206,13 +187,15 @@ class Mapper
                // apply index to file name
                if ($index !== null) {
                        $last= array_pop($sluggedElements);
-                       array_push($sluggedElements, $last.'-'.$index);
-               }
+                       
+                       // if filename contains periods - add index number before last period
+                       if (preg_match('~\.[^\.]+$~i',$last,$extension)){
+                               array_push($sluggedElements, substr($last,0,-(strlen($extension[0]))).'-'.$index.$extension[0]);
+                       } else {
+                               // if filename doesn't contain periods add index ofter the last char
+                               array_push($sluggedElements, $last.'-'.$index);
+                               }
 
-               // add back the extension
-               if (isset($parts['extension'])) {
-                       $last= array_pop($sluggedElements);
-                       array_push($sluggedElements, $last.'.'.$parts['extension']);
                }
 
                $sluggedPath = $this->unchangedPhysicalRoot.implode('/', $sluggedElements);