2012-04-02 21:39:24 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// only need filesystem apps
|
2014-02-27 17:04:19 +04:00
|
|
|
$RUNTIME_APPTYPES = array('filesystem');
|
2012-04-02 21:39:24 +04:00
|
|
|
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::checkLoggedIn();
|
2012-04-02 21:39:24 +04:00
|
|
|
|
|
|
|
// Load the files
|
2014-02-27 17:04:19 +04:00
|
|
|
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
|
2013-09-12 02:21:01 +04: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 21:39:24 +04:00
|
|
|
|
|
|
|
// make filelist
|
|
|
|
$files = array();
|
2014-02-27 17:04:19 +04:00
|
|
|
/**
|
|
|
|
* @var \OCP\Files\FileInfo[] $files
|
|
|
|
*/
|
2013-05-17 06:54:08 +04:00
|
|
|
// If a type other than directory is requested first load them.
|
2014-02-27 17:04:19 +04:00
|
|
|
if ($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
|
|
|
|
$files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, 'httpd/unix-directory'));
|
2013-05-17 06:54:08 +04:00
|
|
|
}
|
2013-09-05 18:54:12 +04:00
|
|
|
|
2013-09-05 20:40:55 +04:00
|
|
|
if (is_array($mimetypes) && count($mimetypes)) {
|
|
|
|
foreach ($mimetypes as $mimetype) {
|
2014-02-27 17:04:19 +04:00
|
|
|
$files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir, $mimetype));
|
2013-09-05 18:54:12 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-02-27 17:04:19 +04:00
|
|
|
$files = array_merge($files, \OC\Files\Filesystem::getDirectoryContent($dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$fileData = array();
|
|
|
|
$fileData['directory'] = $dir;
|
|
|
|
$fileData['name'] = $file->getName();
|
|
|
|
$fileData['type'] = $file->getType();
|
|
|
|
$fileData['path'] = $file['path'];
|
|
|
|
$fileData['id'] = $file->getId();
|
|
|
|
$fileData['size'] = $file->getSize();
|
|
|
|
$fileData['mtime'] = $file->getMtime();
|
|
|
|
$fileData['mimetype'] = $file->getMimetype();
|
|
|
|
$fileData['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file->getMimetype());
|
|
|
|
$fileData["date"] = OCP\Util::formatDate($file->getMtime());
|
|
|
|
$fileData['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
|
|
|
|
$result[] = $fileData;
|
2012-04-02 21:39:24 +04:00
|
|
|
}
|
|
|
|
|
2013-09-06 01:17:53 +04:00
|
|
|
// Sort by name
|
2014-02-27 17:04:19 +04:00
|
|
|
usort($result, array('\OCA\Files\Helper', 'fileCmp'));
|
2013-09-06 01:17:53 +04:00
|
|
|
|
2014-02-27 17:04:19 +04:00
|
|
|
OC_JSON::success(array('data' => $result));
|