Blame view

sources/apps/files/ajax/rawlist.php 1.98 KB
03e52840d   Kload   Init
1
2
3
4
  <?php
  
  // only need filesystem apps
  $RUNTIME_APPTYPES=array('filesystem');
03e52840d   Kload   Init
5
6
7
8
  OCP\JSON::checkLoggedIn();
  
  // Load the files
  $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
31b7f2792   Kload   Upgrade to ownclo...
9
10
11
12
13
14
15
16
  $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']);
  }
03e52840d   Kload   Init
17
18
19
  
  // make filelist
  $files = array();
31b7f2792   Kload   Upgrade to ownclo...
20
21
22
23
24
25
26
27
28
  // 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'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
  		$file["date"] = OCP\Util::formatDate($file["mtime"]);
  		$file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
  		$files[] = $file;
  	}
03e52840d   Kload   Init
29
  }
31b7f2792   Kload   Upgrade to ownclo...
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
55
56
57
58
  if (is_array($mimetypes) && count($mimetypes)) {
  	foreach ($mimetypes as $mimetype) {
  		foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) {
  			$file['directory'] = $dir;
  			$file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
  			$file["date"] = OCP\Util::formatDate($file["mtime"]);
  			$file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
  			$files[] = $file;
  		}
  	}
  } else {
  	foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) {
  		$file['directory'] = $dir;
  		$file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
  		$file["date"] = OCP\Util::formatDate($file["mtime"]);
  		$file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
  		$files[] = $file;
  	}
  }
  
  // Sort by name
  usort($files, function ($a, $b) {
  	if ($a['name'] === $b['name']) {
  		 return 0;
  	}
  	return ($a['name'] < $b['name']) ? -1 : 1;
  });
  
  OC_JSON::success(array('data' => $files));