Clean up rawlist.php and fix non-array request
This commit is contained in:
parent
83d3df4111
commit
4d62f747fa
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue