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:
Thomas Tanghus 2013-09-11 17:18:04 -07:00
commit b7205d97d7
2 changed files with 53 additions and 12 deletions

View File

@ -11,22 +11,56 @@ OCP\JSON::checkLoggedIn();
// Load the files // Load the files
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; $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 // make filelist
$files = array(); $files = array();
// If a type other than directory is requested first load them. // If a type other than directory is requested first load them.
if($mimetype && strpos($mimetype, 'httpd/unix-directory') === false) { if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $i ) { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $file ) {
$i["date"] = OCP\Util::formatDate($i["mtime"] ); $file["date"] = OCP\Util::formatDate($file["mtime"]);
$i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']); $file['mimetype_icon'] = \mimetype_icon('dir');
$files[] = $i; $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));

View File

@ -244,9 +244,16 @@ var OCdialogs = {
return defer.promise(); return defer.promise();
}, },
_getFileList: function(dir, mimeType) { _getFileList: function(dir, mimeType) {
if (typeof(mimeType) === "string") {
mimeType = [mimeType];
}
return $.getJSON( return $.getJSON(
OC.filePath('files', 'ajax', 'rawlist.php'), OC.filePath('files', 'ajax', 'rawlist.php'),
{dir: dir, mimetype: mimeType} {
dir: dir,
mimetypes: JSON.stringify(mimeType)
}
); );
}, },
_determineValue: function(element) { _determineValue: function(element) {