From 992b59f70bec5dcc6681db14c3a97036b4961403 Mon Sep 17 00:00:00 2001 From: kondou Date: Thu, 5 Sep 2013 16:54:12 +0200 Subject: Make it possible to pass rawlist.php an JSON array, to filter by more than one mimetype --- apps/files/ajax/rawlist.php | 22 +++++++++++++++++----- core/js/oc-dialogs.js | 15 +++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index f568afad4da..37fd12f71d0 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -12,21 +12,33 @@ OCP\JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; $mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : ''; +$mimetypeList = isset($_GET['mimetype_list']) ? json_decode($_GET['mimetype_list'], true) : ''; // make filelist $files = array(); // If a type other than directory is requested first load them. -if($mimetype && strpos($mimetype, 'httpd/unix-directory') === false) { +if( ($mimetype || $mimetypeList) && 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; } } -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($mimetypeList)) { + foreach ($mimetypeList as $mimetype) { + 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; + } + } +} else { + 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)); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f184a1022bc..f4c339702e1 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -244,10 +244,17 @@ var OCdialogs = { return defer.promise(); }, _getFileList: function(dir, mimeType) { - return $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - {dir: dir, mimetype: mimeType} - ); + if (typeof(mimeType) === "object") { + return $.getJSON( + OC.filePath('files', 'ajax', 'rawlist.php'), + {dir: dir, "mimetype_list": JSON.stringify(mimeType)} + ); + } else { + return $.getJSON( + OC.filePath('files', 'ajax', 'rawlist.php'), + {dir: dir, mimetype: mimeType} + ); + } }, _determineValue: function(element) { if ( $(element).attr('type') === 'checkbox' ) { -- cgit v1.2.3 From f84fe479a5af35cc51b4bee39492093c75ddc64e Mon Sep 17 00:00:00 2001 From: kondou Date: Thu, 5 Sep 2013 18:40:55 +0200 Subject: Only use mimetype_list and clean up a bit --- apps/files/ajax/rawlist.php | 19 ++++++++++--------- core/js/oc-dialogs.js | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 37fd12f71d0..2fd6f67d308 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -11,22 +11,23 @@ OCP\JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; -$mimetype = isset($_GET['mimetype']) ? $_GET['mimetype'] : ''; -$mimetypeList = isset($_GET['mimetype_list']) ? json_decode($_GET['mimetype_list'], true) : ''; +$mimetypes = isset($_GET['mimetypes']) ? array_unique(json_decode($_GET['mimetypes'], true)) : ''; // make filelist $files = array(); // If a type other than directory is requested first load them. -if( ($mimetype || $mimetypeList) && 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 ) { $i["date"] = OCP\Util::formatDate($i["mtime"] ); - $i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']); + $i['mimetype_icon'] = ($i['type'] == 'dir') + ? \mimetype_icon('dir') + : \mimetype_icon($i['mimetype']); $files[] = $i; } } -if (is_array($mimetypeList)) { - foreach ($mimetypeList as $mimetype) { +if (is_array($mimetypes) && count($mimetypes)) { + foreach ($mimetypes as $mimetype) { 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']); @@ -34,11 +35,11 @@ if (is_array($mimetypeList)) { } } } else { - foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $i ) { - $i["date"] = OCP\Util::formatDate($i["mtime"] ); + foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) 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)); +OC_JSON::success(array('data' => $files)); diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index f4c339702e1..ed4d7c678e1 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -244,17 +244,19 @@ var OCdialogs = { return defer.promise(); }, _getFileList: function(dir, mimeType) { - if (typeof(mimeType) === "object") { - return $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - {dir: dir, "mimetype_list": JSON.stringify(mimeType)} - ); - } else { - return $.getJSON( - OC.filePath('files', 'ajax', 'rawlist.php'), - {dir: dir, mimetype: mimeType} - ); + if (typeof(mimeType) === "string") { + var tmp = mimeType; + mimeType = new Array(); + mimeType[0] = tmp; } + + return $.getJSON( + OC.filePath('files', 'ajax', 'rawlist.php'), + { + dir: dir, + mimetypes: JSON.stringify(mimeType) + } + ); }, _determineValue: function(element) { if ( $(element).attr('type') === 'checkbox' ) { -- cgit v1.2.3 From 85e41d95005a60429681ad99f7ecb18698d0a1c3 Mon Sep 17 00:00:00 2001 From: kondou Date: Thu, 5 Sep 2013 23:17:53 +0200 Subject: Sort files by name, not by mimetype --- apps/files/ajax/rawlist.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 2fd6f67d308..e51932dff0f 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -42,4 +42,13 @@ if (is_array($mimetypes) && count($mimetypes)) { } } +// Sort by name +function cmp($a, $b) { + if ($a['name'] === $b['name']) { + return 0; + } + return ($a['name'] < $b['name']) ? -1 : 1; +} +uasort($files, 'cmp'); + OC_JSON::success(array('data' => $files)); -- cgit v1.2.3 From 226c205631480a2df14fa9a6e594da01054b311e Mon Sep 17 00:00:00 2001 From: kondou Date: Fri, 6 Sep 2013 06:44:49 +0200 Subject: Use usort() instead of uasort() to not maintain keys --- apps/files/ajax/rawlist.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index e51932dff0f..0541353e98a 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -49,6 +49,6 @@ function cmp($a, $b) { } return ($a['name'] < $b['name']) ? -1 : 1; } -uasort($files, 'cmp'); +usort($files, 'cmp'); OC_JSON::success(array('data' => $files)); -- cgit v1.2.3 From c6ca9c1e9d8e25f4dad5ca18f2f335b19a4a3c0c Mon Sep 17 00:00:00 2001 From: kondou Date: Fri, 6 Sep 2013 13:33:17 +0200 Subject: Use shorter array-conversion --- core/js/oc-dialogs.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/js/oc-dialogs.js b/core/js/oc-dialogs.js index ed4d7c678e1..61b58d00fa6 100644 --- a/core/js/oc-dialogs.js +++ b/core/js/oc-dialogs.js @@ -245,9 +245,7 @@ var OCdialogs = { }, _getFileList: function(dir, mimeType) { if (typeof(mimeType) === "string") { - var tmp = mimeType; - mimeType = new Array(); - mimeType[0] = tmp; + mimeType = [mimeType]; } return $.getJSON( -- cgit v1.2.3 From 83d3df41117b1886cb728a79cb80f4722cc118c9 Mon Sep 17 00:00:00 2001 From: kondou Date: Wed, 11 Sep 2013 12:12:40 +0200 Subject: Split some lines, use ===, avoid unnecessary operation --- apps/files/ajax/rawlist.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 0541353e98a..23d9926b9fc 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -19,9 +19,7 @@ $files = array(); if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) { 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']); + $i['mimetype_icon'] = \mimetype_icon('dir'); $files[] = $i; } } @@ -30,14 +28,18 @@ if (is_array($mimetypes) && count($mimetypes)) { foreach ($mimetypes as $mimetype) { 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']); + $i['mimetype_icon'] = $i['type'] === 'dir' ? + \mimetype_icon('dir') : + \mimetype_icon($i['mimetype']); $files[] = $i; } } } else { foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $i ) { $i["date"] = OCP\Util::formatDate($i["mtime"]); - $i['mimetype_icon'] = $i['type'] == 'dir' ? \mimetype_icon('dir'): \mimetype_icon($i['mimetype']); + $i['mimetype_icon'] = $i['type'] === 'dir' ? + \mimetype_icon('dir') : + \mimetype_icon($i['mimetype']); $files[] = $i; } } -- cgit v1.2.3 From 4d62f747fadaea09c9f8a25cf24c2b6d12f7ee2a Mon Sep 17 00:00:00 2001 From: kondou Date: Thu, 12 Sep 2013 00:21:01 +0200 Subject: Clean up rawlist.php and fix non-array request --- apps/files/ajax/rawlist.php | 50 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/apps/files/ajax/rawlist.php b/apps/files/ajax/rawlist.php index 23d9926b9fc..e9ae1f5305f 100644 --- a/apps/files/ajax/rawlist.php +++ b/apps/files/ajax/rawlist.php @@ -11,46 +11,56 @@ OCP\JSON::checkLoggedIn(); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; -$mimetypes = isset($_GET['mimetypes']) ? array_unique(json_decode($_GET['mimetypes'], true)) : ''; +$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($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) { - foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $i ) { - $i["date"] = OCP\Util::formatDate($i["mtime"] ); - $i['mimetype_icon'] = \mimetype_icon('dir'); - $files[] = $i; + 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; } } if (is_array($mimetypes) && count($mimetypes)) { foreach ($mimetypes as $mimetype) { - 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; + 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 $i ) { - $i["date"] = OCP\Util::formatDate($i["mtime"]); - $i['mimetype_icon'] = $i['type'] === 'dir' ? - \mimetype_icon('dir') : - \mimetype_icon($i['mimetype']); - $files[] = $i; + 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 -function cmp($a, $b) { +usort($files, function ($a, $b) { if ($a['name'] === $b['name']) { return 0; } return ($a['name'] < $b['name']) ? -1 : 1; -} -usort($files, 'cmp'); +}); OC_JSON::success(array('data' => $files)); -- cgit v1.2.3