nextcloud/apps/files/ajax/rawlist.php

65 lines
2.0 KiB
PHP
Raw Normal View History

2012-04-02 21:39:24 +04:00
<?php
// only need filesystem apps
$RUNTIME_APPTYPES=array('filesystem');
// Init owncloud
2012-08-29 02:50:12 +04:00
require_once 'lib/template.php';
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
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$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();
2013-05-17 06:54:08 +04:00
// 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 $file ) {
$file['directory'] = $dir;
$file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']);
$file["date"] = OCP\Util::formatDate($file["mtime"]);
$file['mimetype_icon'] = \OCA\Files\Lib\Helper::determineIcon($file);
$files[] = $file;
2013-05-17 06:54:08 +04:00
}
}
if (is_array($mimetypes) && count($mimetypes)) {
foreach ($mimetypes as $mimetype) {
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) {
$file['directory'] = $dir;
$file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']);
$file["date"] = OCP\Util::formatDate($file["mtime"]);
$file['mimetype_icon'] = \OCA\Files\Lib\Helper::determineIcon($file);
$files[] = $file;
}
}
} else {
foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) {
$file['directory'] = $dir;
$file['isPreviewAvailable'] = \OCP\Preview::isMimeSupported($file['mimetype']);
$file["date"] = OCP\Util::formatDate($file["mtime"]);
$file['mimetype_icon'] = \OCA\Files\Lib\Helper::determineIcon($file);
$files[] = $file;
}
2012-04-02 21:39:24 +04:00
}
2013-09-06 01:17:53 +04:00
// Sort by name
usort($files, function ($a, $b) {
2013-09-06 01:17:53 +04:00
if ($a['name'] === $b['name']) {
return 0;
}
return ($a['name'] < $b['name']) ? -1 : 1;
});
2013-09-06 01:17:53 +04:00
OC_JSON::success(array('data' => $files));