2012-04-02 17:39:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// only need filesystem apps
|
|
|
|
$RUNTIME_APPTYPES=array('filesystem');
|
|
|
|
|
|
|
|
// Init owncloud
|
2012-04-17 17:31:29 +00:00
|
|
|
|
2012-08-28 22:50:12 +00:00
|
|
|
require_once 'lib/template.php';
|
2012-04-02 17:39:24 +00:00
|
|
|
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::checkLoggedIn();
|
2012-04-02 17:39:24 +00:00
|
|
|
|
|
|
|
// Load the files
|
|
|
|
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
|
2013-09-11 22:21:01 +00:00
|
|
|
$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']);
|
|
|
|
}
|
2012-04-02 17:39:24 +00:00
|
|
|
|
|
|
|
// make filelist
|
|
|
|
$files = array();
|
2013-05-17 02:54:08 +00:00
|
|
|
// If a type other than directory is requested first load them.
|
2013-09-05 16:40:55 +00:00
|
|
|
if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
|
2013-09-11 22:21:01 +00:00
|
|
|
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $file ) {
|
2013-09-14 12:35:23 +00:00
|
|
|
$file['directory'] = $dir;
|
|
|
|
$file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']);
|
2013-09-11 22:21:01 +00:00
|
|
|
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
2013-09-14 12:35:23 +00:00
|
|
|
$file['mimetype_icon'] = \OCA\files\lib\Helper::determineIcon($file);
|
2013-09-11 22:21:01 +00:00
|
|
|
$files[] = $file;
|
2013-05-17 02:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-05 14:54:12 +00:00
|
|
|
|
2013-09-05 16:40:55 +00:00
|
|
|
if (is_array($mimetypes) && count($mimetypes)) {
|
|
|
|
foreach ($mimetypes as $mimetype) {
|
2013-09-11 22:21:01 +00:00
|
|
|
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) {
|
2013-09-14 12:35:23 +00:00
|
|
|
$file['directory'] = $dir;
|
|
|
|
$file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']);
|
2013-09-11 22:21:01 +00:00
|
|
|
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
2013-09-14 12:35:23 +00:00
|
|
|
$file['mimetype_icon'] = \OCA\files\lib\Helper::determineIcon($file);
|
2013-09-11 22:21:01 +00:00
|
|
|
$files[] = $file;
|
2013-09-05 14:54:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-09-11 22:21:01 +00:00
|
|
|
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) {
|
2013-09-14 12:35:23 +00:00
|
|
|
$file['directory'] = $dir;
|
|
|
|
$file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']);
|
2013-09-11 22:21:01 +00:00
|
|
|
$file["date"] = OCP\Util::formatDate($file["mtime"]);
|
2013-09-14 12:35:23 +00:00
|
|
|
$file['mimetype_icon'] = \OCA\files\lib\Helper::determineIcon($file);
|
2013-09-11 22:21:01 +00:00
|
|
|
$files[] = $file;
|
2013-09-05 14:54:12 +00:00
|
|
|
}
|
2012-04-02 17:39:24 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 21:17:53 +00:00
|
|
|
// Sort by name
|
2013-09-11 22:21:01 +00:00
|
|
|
usort($files, function ($a, $b) {
|
2013-09-05 21:17:53 +00:00
|
|
|
if ($a['name'] === $b['name']) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ($a['name'] < $b['name']) ? -1 : 1;
|
2013-09-11 22:21:01 +00:00
|
|
|
});
|
2013-09-05 21:17:53 +00:00
|
|
|
|
2013-09-05 16:40:55 +00:00
|
|
|
OC_JSON::success(array('data' => $files));
|