summaryrefslogtreecommitdiffstats
path: root/apps/files/ajax
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2013-09-11 17:18:04 -0700
committerThomas Tanghus <thomas@tanghus.net>2013-09-11 17:18:04 -0700
commitb7205d97d7797daf057d47a5a07d2bad3b0db4da (patch)
tree524080f4643ddcb1c76a1159e0bbc15cd0bcd3d7 /apps/files/ajax
parent80bf1969f97fca3d2cb5f9edd6ad09115728497a (diff)
parent4d62f747fadaea09c9f8a25cf24c2b6d12f7ee2a (diff)
downloadnextcloud-server-b7205d97d7797daf057d47a5a07d2bad3b0db4da.tar.gz
nextcloud-server-b7205d97d7797daf057d47a5a07d2bad3b0db4da.zip
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
Diffstat (limited to 'apps/files/ajax')
-rw-r--r--apps/files/ajax/rawlist.php56
1 files changed, 45 insertions, 11 deletions
diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php
index f568afad4da..e9ae1f5305f 100644
--- a/apps/files/ajax/rawlist.php
+++ b/apps/files/ajax/rawlist.php
@@ -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;
+
+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;
+ }
}
-OCP\JSON::success(array('data' => $files));
+// 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));