rawlist.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // only need filesystem apps
  3. $RUNTIME_APPTYPES=array('filesystem');
  4. OCP\JSON::checkLoggedIn();
  5. // Load the files
  6. $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
  7. $mimetypes = isset($_GET['mimetypes']) ? json_decode($_GET['mimetypes'], true) : '';
  8. // Clean up duplicates from array and deal with non-array requests
  9. if (is_array($mimetypes)) {
  10. $mimetypes = array_unique($mimetypes);
  11. } elseif (is_null($mimetypes)) {
  12. $mimetypes = array($_GET['mimetypes']);
  13. }
  14. // make filelist
  15. $files = array();
  16. // If a type other than directory is requested first load them.
  17. if($mimetypes && !in_array('httpd/unix-directory', $mimetypes)) {
  18. foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, 'httpd/unix-directory' ) as $file ) {
  19. $file['directory'] = $dir;
  20. $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
  21. $file["date"] = OCP\Util::formatDate($file["mtime"]);
  22. $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
  23. $files[] = $file;
  24. }
  25. }
  26. if (is_array($mimetypes) && count($mimetypes)) {
  27. foreach ($mimetypes as $mimetype) {
  28. foreach( \OC\Files\Filesystem::getDirectoryContent( $dir, $mimetype ) as $file ) {
  29. $file['directory'] = $dir;
  30. $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
  31. $file["date"] = OCP\Util::formatDate($file["mtime"]);
  32. $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
  33. $files[] = $file;
  34. }
  35. }
  36. } else {
  37. foreach( \OC\Files\Filesystem::getDirectoryContent( $dir ) as $file ) {
  38. $file['directory'] = $dir;
  39. $file['isPreviewAvailable'] = \OC::$server->getPreviewManager()->isMimeSupported($file['mimetype']);
  40. $file["date"] = OCP\Util::formatDate($file["mtime"]);
  41. $file['mimetype_icon'] = \OCA\Files\Helper::determineIcon($file);
  42. $files[] = $file;
  43. }
  44. }
  45. // Sort by name
  46. usort($files, function ($a, $b) {
  47. if ($a['name'] === $b['name']) {
  48. return 0;
  49. }
  50. return ($a['name'] < $b['name']) ? -1 : 1;
  51. });
  52. OC_JSON::success(array('data' => $files));