Merge pull request #4735 from owncloud/multiple_mimetypes_rawlist
Make it possible to pass rawlist.php an JSON array, to filter by more than one mimetype
This commit is contained in:
commit
b7205d97d7
|
@ -11,22 +11,56 @@ OCP\JSON::checkLoggedIn();
|
|||
|
||||
// Load the files
|
||||
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
|
||||
$mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : '';
|
||||
$mimetypes = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes'], true) : '';
|
||||
|
||||
// Clean up duplicates from array and deal with non-array requests
|
||||
if (is_array($mimetypes)) {
|
||||
$mimetypes = array_unique($mimetypes);
|
||||
} elseif (is_null($mimetypes)) {
|
||||
$mimetypes = array($_GET['mimetypes']);
|
||||
}
|
||||
|
||||
// make filelist
|
||||
$files = array();
|
||||
// If a type other than directory is requested first load them.
|
||||
if($mimetype && strpos($mimetype, 'httpd/unix-directory') === false) {
|
||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $i ) {
|
||||
$i["date"] = OCP\Util::formatDate($i["mtime"] );
|
||||
$i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']);
|
||||
$files[] = $i;
|
||||
if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
|
||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $file ) {
|
||||
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
||||
$file['mimetype_icon'] = \mimetype_icon('dir');
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $i ) {
|
||||
$i["date"] = OCP\Util::formatDate($i["mtime"] );
|
||||
$i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']);
|
||||
$files[] = $i;
|
||||
}
|
||||
|
||||
OCP\JSON::success(array('data' => $files));
|
||||
if (is_array($mimetypes) && count($mimetypes)) {
|
||||
foreach ($mimetypes as $mimetype) {
|
||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) {
|
||||
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
||||
if ($file['type'] === "dir") {
|
||||
$file['mimetype_icon'] = \mimetype_icon('dir');
|
||||
} else {
|
||||
$file['mimetype_icon'] = \mimetype_icon($file['mimetype']);
|
||||
}
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) {
|
||||
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
||||
if ($file['type'] === "dir") {
|
||||
$file['mimetype_icon'] = \mimetype_icon('dir');
|
||||
} else {
|
||||
$file['mimetype_icon'] = \mimetype_icon($file['mimetype']);
|
||||
}
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by name
|
||||
usort($files, function ($a, $b) {
|
||||
if ($a['name'] === $b['name']) {
|
||||
return 0;
|
||||
}
|
||||
return ($a['name'] < $b['name']) ? -1 : 1;
|
||||
});
|
||||
|
||||
OC_JSON::success(array('data' => $files));
|
||||
|
|
|
@ -244,9 +244,16 @@ var OCdialogs = {
|
|||
return defer.promise();
|
||||
},
|
||||
_getFileList: function(dir, mimeType) {
|
||||
if (typeof(mimeType) === "string") {
|
||||
mimeType = [mimeType];
|
||||
}
|
||||
|
||||
return $.getJSON(
|
||||
OC.filePath('files', 'ajax', 'rawlist.php'),
|
||||
{dir: dir, mimetype: mimeType}
|
||||
{
|
||||
dir: dir,
|
||||
mimetypes: JSON.stringify(mimeType)
|
||||
}
|
||||
);
|
||||
},
|
||||
_determineValue: function(element) {
|
||||
|
|
Loading…
Reference in New Issue