aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-04-13 10:35:45 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-04-14 14:10:46 +0200
commit1e60931119ebd350d6d6ad6fba0dba2c94c9a177 (patch)
tree283402eb00243189f162c20b00194b29b42169bf
parent9dac69b21b8a2e5f04b85df5581ac120727135ea (diff)
downloadnextcloud-server-1e60931119ebd350d6d6ad6fba0dba2c94c9a177.tar.gz
nextcloud-server-1e60931119ebd350d6d6ad6fba0dba2c94c9a177.zip
fix filepicker
* add ability to filter for mimetype * fixes #15526 * fixes #11563
-rw-r--r--apps/files/ajax/list.php26
-rw-r--r--apps/files/lib/helper.php5
-rw-r--r--core/js/oc-dialogs.js2
3 files changed, 28 insertions, 5 deletions
diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php
index 4aed79d70f7..f9facd0d7f7 100644
--- a/apps/files/ajax/list.php
+++ b/apps/files/ajax/list.php
@@ -22,10 +22,32 @@ try {
$sortAttribute = isset($_GET['sort']) ? $_GET['sort'] : 'name';
$sortDirection = isset($_GET['sortdirection']) ? ($_GET['sortdirection'] === 'desc') : false;
+ $mimetypeFilters = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes']) : '';
- // make filelist
+ $files = [];
+ // Clean up duplicates from array
+ if (is_array($mimetypeFilters) && count($mimetypeFilters)) {
+ $mimetypeFilters = array_unique($mimetypeFilters);
+
+ if (!in_array('httpd/unix-directory', $mimetypeFilters)) {
+ // append folder filter to be able to browse folders
+ $mimetypeFilters[] = 'httpd/unix-directory';
+ }
+
+ // create filelist with mimetype filter - as getFiles only supports on
+ // mimetype filter at once we will filter this folder for each
+ // mimetypeFilter
+ foreach ($mimetypeFilters as $mimetypeFilter) {
+ $files = array_merge($files, \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection, $mimetypeFilter));
+ }
+
+ // sort the files accordingly
+ $files = \OCA\Files\Helper::sortFiles($files, $sortAttribute, $sortDirection);
+ } else {
+ // create file list without mimetype filter
+ $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
+ }
- $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
$files = \OCA\Files\Helper::populateTags($files);
$data['directory'] = $dir;
$data['files'] = \OCA\Files\Helper::formatFileInfos($files);
diff --git a/apps/files/lib/helper.php b/apps/files/lib/helper.php
index 84b1a0f1662..d92e69674f9 100644
--- a/apps/files/lib/helper.php
+++ b/apps/files/lib/helper.php
@@ -170,10 +170,11 @@ class Helper
* @param string $dir path to the directory
* @param string $sortAttribute attribute to sort on
* @param bool $sortDescending true for descending sort, false otherwise
+ * @param string $mimetypeFilter limit returned content to this mimetype or mimepart
* @return \OCP\Files\FileInfo[] files
*/
- public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false) {
- $content = \OC\Files\Filesystem::getDirectoryContent($dir);
+ public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false, $mimetypeFilter = '') {
+ $content = \OC\Files\Filesystem::getDirectoryContent($dir, $mimetypeFilter);
return self::sortFiles($content, $sortAttribute, $sortDescending);
}
diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js
index 0c046d8ef0e..f3bf4361d76 100644
--- a/core/js/oc-dialogs.js
+++ b/core/js/oc-dialogs.js
@@ -138,7 +138,7 @@ var OCdialogs = {
* @param title dialog title
* @param callback which will be triggered when user presses Choose
* @param multiselect whether it should be possible to select multiple files
- * @param mimetypeFilter mimetype to filter by
+ * @param mimetypeFilter mimetype to filter by - directories will always be included
* @param modal make the dialog modal
*/
filepicker:function(title, callback, multiselect, mimetypeFilter, modal) {