summaryrefslogtreecommitdiffstats
path: root/apps/files/ajax/rawlist.php
blob: e51932dff0fe2e9030ff00d0150a291f99a6dc0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

// only need filesystem apps
$RUNTIME_APPTYPES=array('filesystem');

// Init owncloud

require_once 'lib/template.php';

OCP\JSON::checkLoggedIn();

// Load the files
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
$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($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']);
		$files[] = $i;
	}
}

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;
		}
	}
} 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;
	}
}

// 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));