Blame view
sources/apps/files_trashbin/lib/helper.php
2.65 KB
|
31b7f2792
|
1 2 3 |
<?php namespace OCA\Files_Trashbin; |
|
6d9380f96
|
4 |
use OC\Files\FileInfo; |
|
31b7f2792
|
5 6 7 8 |
class Helper
{
/**
* Retrieves the contents of a trash bin directory.
|
|
6d9380f96
|
9 |
* |
|
31b7f2792
|
10 11 |
* @param string $dir path to the directory inside the trashbin * or empty to retrieve the root of the trashbin |
|
6d9380f96
|
12 13 14 15 |
* @param string $user * @param string $sortAttribute attribute to sort on or empty to disable sorting * @param bool $sortDescending true for descending sort, false otherwise * @return \OCP\Files\FileInfo[] |
|
31b7f2792
|
16 |
*/ |
|
6d9380f96
|
17 |
public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false){
|
|
31b7f2792
|
18 |
$result = array(); |
|
6d9380f96
|
19 |
$timestamp = null; |
|
31b7f2792
|
20 |
|
|
6d9380f96
|
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 |
$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
throw new \Exception('Directory does not exists');
}
$dirContent = $view->opendir($dir);
if ($dirContent === false) {
return $result;
}
list($storage, $internalPath) = $view->resolvePath($dir);
$absoluteDir = $view->getAbsolutePath($dir);
if (is_resource($dirContent)) {
while (($entryName = readdir($dirContent)) !== false) {
if (!\OC\Files\Filesystem::isIgnoredDir($entryName)) {
$id = $entryName;
if ($dir === '' || $dir === '/') {
$pathparts = pathinfo($entryName);
$timestamp = substr($pathparts['extension'], 1);
$id = $pathparts['filename'];
} else if ($timestamp === null) {
// for subfolders we need to calculate the timestamp only once
$parts = explode('/', ltrim($dir, '/'));
$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
|
|
31b7f2792
|
47 |
} |
|
6d9380f96
|
48 49 50 51 52 53 54 55 |
$i = array( 'name' => $id, 'mtime' => $timestamp, 'mimetype' => \OC_Helper::getFileNameMimeType($id), 'type' => $view->is_dir($dir . '/' . $entryName) ? 'dir' : 'file', 'directory' => ($dir === '/') ? '' : $dir, ); $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i); |
|
31b7f2792
|
56 |
} |
|
31b7f2792
|
57 |
} |
|
6d9380f96
|
58 |
closedir($dirContent); |
|
31b7f2792
|
59 |
} |
|
6d9380f96
|
60 61 |
if ($sortAttribute !== '') {
return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
|
|
31b7f2792
|
62 |
} |
|
6d9380f96
|
63 |
return $result; |
|
31b7f2792
|
64 65 66 |
} /** |
|
6d9380f96
|
67 68 |
* Format file infos for JSON * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
31b7f2792
|
69 |
*/ |
|
6d9380f96
|
70 71 72 73 74 75 76 77 78 79 |
public static function formatFileInfos($fileInfos) {
$files = array();
$id = 0;
foreach ($fileInfos as $i) {
$entry = \OCA\Files\Helper::formatFileInfo($i);
$entry['id'] = $id++;
$entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
$entry['permissions'] = \OCP\PERMISSION_READ;
if (\OCP\App::isEnabled('files_encryption')) {
$entry['isPreviewAvailable'] = false;
|
|
31b7f2792
|
80 |
} |
|
6d9380f96
|
81 |
$files[] = $entry; |
|
31b7f2792
|
82 |
} |
|
6d9380f96
|
83 |
return $files; |
|
31b7f2792
|
84 85 |
} } |