blob: 5078140e7f5013fa375d6041c7508a052813a638 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
<?php
/**
* ownCloud - gallery
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Olivier Paroz <owncloud@interfasys.ch>
*
* @copyright Olivier Paroz 2015
*/
namespace OCA\Gallery\Controller;
/**
* @package OCA\Gallery\Controller
*/
trait PathManipulation {
/**
* Returns a shortened path for the gallery view
*
* We only want to keep one folder between the current folder and the found media file
* /root/folder/sub1/sub2/file.ext
* becomes
* /root/folder/file.ext
*
* @param string $path the full path to a file, which never starts with a slash
* @param string $currFolderPath the current folder, which never starts with a slash
*
* @return string
*/
private function getReducedPath($path, $currFolderPath) {
// Adding a slash to make sure we don't cut a folder in half
if ($currFolderPath) {
$currFolderPath .= '/';
$relativePath = str_replace($currFolderPath, '', $path);
} else {
$relativePath = $path;
}
$subFolders = explode('/', $relativePath);
if (count($subFolders) > 2) {
$reducedPath = $currFolderPath . $subFolders[0] . '/' . array_pop($subFolders);
} else {
$reducedPath = $path;
}
return $reducedPath;
}
}
|