- '/home/extranet/share:/application/share'
- '/home/toolbox/www:/application'
- '/home/toolbox/www/storage/app/public/:/application/public/storage/'
+ - '/data/extranet/ftp/:/application/ftp/'
- '/mnt/sshfs/godzilla/data/fluidbook/docs/:/application/protected/fluidbookpublication/docs/'
- '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
- '/home/extranet:/home/extranet'
- '/home/extranet/share:/application/share'
- '/home/toolbox/www:/application'
- '/home/toolbox/www/storage/app/public/:/application/public/storage/'
+ - '/data/extranet/ftp/:/application/ftp/'
- '/mnt/sshfs/godzilla/data/fluidbook/docs/:/application/protected/fluidbookpublication/docs/'
- '/data/extranet/www/fluidbook/books/working/:/application/protected/fluidbookpublication/working/'
- '/home/extranet:/home/extranet'
--- /dev/null
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use App\Http\Controllers\Controller;
+use App\Models\User;
+use Cubedesigners\UserDatabase\Permissions;
+use Cubist\Util\Files\Files;
+
+class FilesController extends Controller
+{
+ protected function files($id = 'me')
+ {
+ if (!can('files:read')) {
+ abort(404);
+ }
+ return view('files.files', ['files' => $this->getFiles($id), 'id' => $id]);
+ }
+
+ protected function getFiles($id = 'me')
+ {
+ if ($id === 'me' || !can('files:admin')) {
+ return $this->_getFiles(backpack_user()->id);
+ }
+ return $this->_getFiles($id);
+ }
+
+ protected function _getFiles($id)
+ {
+ /** @var User $user */
+ $user = User::withoutGlobalScopes()->find($id);
+ if (null === $user) {
+ abort(404);
+ }
+ $users = $user->getManagedUsers();
+ $files = [];
+ foreach ($users as $user) {
+ $this->_listFilesOfUser($user, $files);
+ }
+ usort($files, function ($a, $b) {
+ return -($a['mtime'] - $b['mtime']);
+ });
+ return $files;
+ }
+
+ protected function _listFilesOfUser($id, &$files)
+ {
+ $uFiles = cache()->remember('files_list_user_' . $id, 86400, function () use ($id) {
+ return $this->___listFilesOfUser($id);
+ });
+
+ foreach ($uFiles as $path => $uFile) {
+ if (isset($files[$path])) {
+ continue;
+ }
+ $files[$path] = $uFile;
+ }
+ }
+
+ protected function ___listFilesOfUser($id)
+ {
+
+ $path = '/application/ftp/' . $id;
+ if (!file_exists($path) || !is_dir($path)) {
+ return [];
+ }
+ $res = [];
+ $userFiles = Files::getRecursiveDirectoryIterator($path);
+ foreach ($userFiles as $file) {
+ /** @var $file \SplFileInfo */
+ if ($file->isDir()) {
+ continue;
+ }
+
+ $pathname = $file->getPathname();
+ if (isset($files[$pathname])) {
+ continue;
+ }
+
+ if (preg_match('|\.in\/(\d)+\/|', $pathname, $matches)) {
+ $from = $matches[1];
+ $to = $id;
+ } else {
+ $from = $id;
+ $to = false;
+ }
+
+ $res[$pathname] = [
+ 'path' => $pathname,
+ 'name' => $file->getFilename(),
+ 'ext' => mb_strtolower($file->getExtension()),
+ 'mtime' => $file->getMTime(),
+ 'date' => date('Y/m/d', $file->getMTime()),
+ 'size' => Files::humanReadableSize($file->getSize()),
+ 'from' => $from,
+ 'to' => $to,
+ ];
+ }
+
+ return $res;
+ }
+}