@@ -30,97 +30,97 @@ |
||
30 | 30 | use OCP\Files\Cache\ICacheEntry; |
31 | 31 | |
32 | 32 | class Helper { |
33 | - /** |
|
34 | - * Retrieves the contents of a trash bin directory. |
|
35 | - * |
|
36 | - * @param string $dir path to the directory inside the trashbin |
|
37 | - * or empty to retrieve the root of the trashbin |
|
38 | - * @param string $user |
|
39 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
40 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
41 | - * @return \OCP\Files\FileInfo[] |
|
42 | - */ |
|
43 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
44 | - $result = array(); |
|
45 | - $timestamp = null; |
|
33 | + /** |
|
34 | + * Retrieves the contents of a trash bin directory. |
|
35 | + * |
|
36 | + * @param string $dir path to the directory inside the trashbin |
|
37 | + * or empty to retrieve the root of the trashbin |
|
38 | + * @param string $user |
|
39 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
40 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
41 | + * @return \OCP\Files\FileInfo[] |
|
42 | + */ |
|
43 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
44 | + $result = array(); |
|
45 | + $timestamp = null; |
|
46 | 46 | |
47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
47 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
48 | 48 | |
49 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
50 | - throw new \Exception('Directory does not exists'); |
|
51 | - } |
|
49 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
50 | + throw new \Exception('Directory does not exists'); |
|
51 | + } |
|
52 | 52 | |
53 | - $mount = $view->getMount($dir); |
|
54 | - $storage = $mount->getStorage(); |
|
55 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
56 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
53 | + $mount = $view->getMount($dir); |
|
54 | + $storage = $mount->getStorage(); |
|
55 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
56 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
57 | 57 | |
58 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
59 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
60 | - foreach ($dirContent as $entry) { |
|
61 | - $entryName = $entry->getName(); |
|
62 | - $id = $entry->getId(); |
|
63 | - $name = $entryName; |
|
64 | - if ($dir === '' || $dir === '/') { |
|
65 | - $pathparts = pathinfo($entryName); |
|
66 | - $timestamp = substr($pathparts['extension'], 1); |
|
67 | - $name = $pathparts['filename']; |
|
58 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
59 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
60 | + foreach ($dirContent as $entry) { |
|
61 | + $entryName = $entry->getName(); |
|
62 | + $id = $entry->getId(); |
|
63 | + $name = $entryName; |
|
64 | + if ($dir === '' || $dir === '/') { |
|
65 | + $pathparts = pathinfo($entryName); |
|
66 | + $timestamp = substr($pathparts['extension'], 1); |
|
67 | + $name = $pathparts['filename']; |
|
68 | 68 | |
69 | - } else if ($timestamp === null) { |
|
70 | - // for subfolders we need to calculate the timestamp only once |
|
71 | - $parts = explode('/', ltrim($dir, '/')); |
|
72 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
73 | - } |
|
74 | - $originalPath = ''; |
|
75 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
76 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
77 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
78 | - if (substr($originalPath, -1) === '/') { |
|
79 | - $originalPath = substr($originalPath, 0, -1); |
|
80 | - } |
|
81 | - } |
|
82 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
83 | - $i = array( |
|
84 | - 'name' => $name, |
|
85 | - 'mtime' => $timestamp, |
|
86 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
87 | - 'type' => $type, |
|
88 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
89 | - 'size' => $entry->getSize(), |
|
90 | - 'etag' => '', |
|
91 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE |
|
92 | - ); |
|
93 | - if ($originalPath) { |
|
94 | - if ($originalPath !== '.') { |
|
95 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
96 | - } else { |
|
97 | - $i['extraData'] = $originalName; |
|
98 | - } |
|
99 | - } |
|
100 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
101 | - } |
|
69 | + } else if ($timestamp === null) { |
|
70 | + // for subfolders we need to calculate the timestamp only once |
|
71 | + $parts = explode('/', ltrim($dir, '/')); |
|
72 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
73 | + } |
|
74 | + $originalPath = ''; |
|
75 | + $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
76 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
77 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
78 | + if (substr($originalPath, -1) === '/') { |
|
79 | + $originalPath = substr($originalPath, 0, -1); |
|
80 | + } |
|
81 | + } |
|
82 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
83 | + $i = array( |
|
84 | + 'name' => $name, |
|
85 | + 'mtime' => $timestamp, |
|
86 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
87 | + 'type' => $type, |
|
88 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
89 | + 'size' => $entry->getSize(), |
|
90 | + 'etag' => '', |
|
91 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE |
|
92 | + ); |
|
93 | + if ($originalPath) { |
|
94 | + if ($originalPath !== '.') { |
|
95 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
96 | + } else { |
|
97 | + $i['extraData'] = $originalName; |
|
98 | + } |
|
99 | + } |
|
100 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
101 | + } |
|
102 | 102 | |
103 | - if ($sortAttribute !== '') { |
|
104 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
105 | - } |
|
106 | - return $result; |
|
107 | - } |
|
103 | + if ($sortAttribute !== '') { |
|
104 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
105 | + } |
|
106 | + return $result; |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Format file infos for JSON |
|
111 | - * |
|
112 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
113 | - */ |
|
114 | - public static function formatFileInfos($fileInfos) { |
|
115 | - $files = array(); |
|
116 | - $id = 0; |
|
117 | - foreach ($fileInfos as $i) { |
|
118 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
119 | - $entry['id'] = $id++; |
|
120 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
121 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
122 | - $files[] = $entry; |
|
123 | - } |
|
124 | - return $files; |
|
125 | - } |
|
109 | + /** |
|
110 | + * Format file infos for JSON |
|
111 | + * |
|
112 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
113 | + */ |
|
114 | + public static function formatFileInfos($fileInfos) { |
|
115 | + $files = array(); |
|
116 | + $id = 0; |
|
117 | + foreach ($fileInfos as $i) { |
|
118 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
119 | + $entry['id'] = $id++; |
|
120 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
121 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
122 | + $files[] = $entry; |
|
123 | + } |
|
124 | + return $files; |
|
125 | + } |
|
126 | 126 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $result = array(); |
45 | 45 | $timestamp = null; |
46 | 46 | |
47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
48 | 48 | |
49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
73 | 73 | } |
74 | 74 | $originalPath = ''; |
75 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
75 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
76 | 76 | if (isset($originalLocations[$originalName][$timestamp])) { |
77 | 77 | $originalPath = $originalLocations[$originalName][$timestamp]; |
78 | 78 | if (substr($originalPath, -1) === '/') { |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | ); |
93 | 93 | if ($originalPath) { |
94 | 94 | if ($originalPath !== '.') { |
95 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
95 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
96 | 96 | } else { |
97 | 97 | $i['extraData'] = $originalName; |
98 | 98 | } |
99 | 99 | } |
100 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
100 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | if ($sortAttribute !== '') { |