Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinfoneo <infoneo@yahoo.pl>2013-06-08 19:39:25 +0400
committerinfoneo <infoneo@yahoo.pl>2013-06-08 19:39:25 +0400
commitb39113ae3ea59db7058fe829fc0a5e4dfd49bac6 (patch)
treef0c35932b9933ce1624ecdce333dcce16832ca47 /lib/files/mapper.php
parentbe4eef682ae515fd542ec351eef05cc54fe3247c (diff)
Update mapper.php
Now slugify is performed on whole filename (including extension). Changed method of adding index number (using regular expressions pathinfo() method removed).
Diffstat (limited to 'lib/files/mapper.php')
-rw-r--r--lib/files/mapper.php33
1 files changed, 8 insertions, 25 deletions
diff --git a/lib/files/mapper.php b/lib/files/mapper.php
index d9e116bf25b..748b65dc4f1 100644
--- a/lib/files/mapper.php
+++ b/lib/files/mapper.php
@@ -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);