diff --git a/core/modules/FileManager/Controller/File.php b/core/modules/FileManager/Controller/File.php index 672570bb..0dfa5fde 100644 --- a/core/modules/FileManager/Controller/File.php +++ b/core/modules/FileManager/Controller/File.php @@ -38,11 +38,12 @@ public function show($path, $name, $ext, $req) return $this->get404($req); } - $file = self::core()->getDir('files_public', 'app/files') . "$path$name$ext"; - if (!is_file($file)) { + $spl = new \SplFileInfo( + self::core()->getDir('files_public', 'app/files') . "$path$name$ext" + ); + if (!$spl->isFile()) { return $this->get404($req); } - $spl = new \SplFileInfo($file); $data = self::filemanager()->parseFile($spl, $path); return self::template() @@ -60,10 +61,13 @@ public function store($path, $req) return $this->get404($req); } if ($req->isMaxSize()) { - $output[ 'messages' ][ 'errors' ] = [ t('The total amount of data received exceeds the maximum value allowed by the post_max_size directive in your php.ini file.') ]; + $output[ 'messages' ][ 'errors' ] = [ + t('The total amount of data received exceeds the maximum value allowed by the post_max_size directive in your php.ini file.') + ]; return $this->json(400, $output); } + $dir = self::core()->getDir('files_public', 'app/files') . $path; $profil = $this->get('filemanager.hook.user')->getRight($path); $rules = [ @@ -74,8 +78,9 @@ public function store($path, $req) if (!empty($profil[ 'file_extensions_all' ])) { $rules[ 'file' ] .= '|file_extensions:' . implode(',', FileManager::getWhiteList()); } else { - $rules[ 'file' ] .= '|file_extensions:' . $profil['file_extensions']; + $rules[ 'file' ] .= '|file_extensions:' . $profil[ 'file_extensions' ]; } + if (!empty($profil[ 'file_size' ])) { $rules[ 'file' ] .= '|max:' . $profil[ 'file_size' ] . 'mb'; } @@ -92,15 +97,16 @@ public function store($path, $req) } else { $validator->addInput('folder', 0); } - + if (!$validator->isValid()) { $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); return $this->json(400, $output); } - $file = $validator->getInput('file'); + $file = $validator->getInput('file'); $serviceFile = self::file(); + if (self::config()->get('settings.replace_file') === 2) { $serviceFile = self::file()->setResolveName(); } elseif (self::config()->get('settings.replace_file') === 3 && is_file($dir . '/' . $file->getClientFilename())) { @@ -126,11 +132,12 @@ public function edit($path, $name, $ext, $req) return $this->get404($req); } - $file = self::core()->getDir('files_public', 'app/files') . "$path$name$ext"; - if (!is_file($file)) { + $spl = new \SplFileInfo( + self::core()->getDir('files_public', 'app/files') . "$path$name$ext" + ); + if (!$spl->isFile()) { return $this->get404($req); } - $spl = new \SplFileInfo($file); $data = self::filemanager()->parseFile($spl, $path); if (isset($_SESSION[ 'inputs' ])) { @@ -176,8 +183,9 @@ public function update($path, $name, $ext, $req) if (!$req->isAjax()) { return $this->get404($req); } - $file_old = self::core()->getDir('files_public', 'app/files') . "$path$name$ext"; - if (!is_file($file_old)) { + + $fileOld = self::core()->getDir('files_public', 'app/files') . "$path$name$ext"; + if (!is_file($fileOld)) { return $this->get404($req); } $dir = self::core()->getDir('files_public', 'app/files') . $path; @@ -193,31 +201,30 @@ public function update($path, $name, $ext, $req) $output = []; /* Si les valeur attendues sont les bonnes. */ - if (!$validator->isValid() || !is_file($file_old)) { + if (!$validator->isValid()) { $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); - $statut = 400; - return $this->json($statut, $output); + return $this->json(400, $output); } - $folder = Util::strSlug($validator->getInput('name')); - $file_update = "$dir/$folder$ext"; + $folder = Util::strSlug($validator->getInput('name')); + $fileUpdate = "$dir/$folder$ext"; - /* Si le nouveau nom du répertoire est déjà utilisé. */ - if (!is_dir($file_update)) { + /* Si le nouveau nom du fichier est déjà utilisé. */ + if (!is_file($fileUpdate)) { $folder = Util::strSlug($validator->getInput('name')); - rename($file_old, $file_update); + rename($fileOld, $fileUpdate); $output[ 'messages' ][ 'success' ] = [ t('The file has been renamed') ]; - $statut = 200; - } else { - $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); - $output[ 'messages' ][ 'errors' ] = [ t('You can not use this name to rename the file') ]; - $statut = 400; + + return $this->json(200, $output); } - return $this->json($statut, $output); + $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); + $output[ 'messages' ][ 'errors' ] = [ t('You can not use this name to rename the file') ]; + + return $this->json(400, $output); } public function remove($path, $name, $ext, $req) @@ -226,12 +233,12 @@ public function remove($path, $name, $ext, $req) return $this->get404($req); } - $file = self::core()->getDir('files_public', 'app/files') . "$path$name$ext"; - if (!is_file($file)) { + $spl = new \SplFileInfo( + self::core()->getDir('files_public', 'app/files') . "$path$name$ext" + ); + if (!$spl->isFile()) { return $this->get404($req); } - $spl = new \SplFileInfo($file); - $data = self::filemanager()->parseFile($spl, $path); $form = (new FormBuilder([ 'action' => self::router()->getRoute('filemanager.file.delete', [ @@ -255,7 +262,7 @@ public function remove($path, $name, $ext, $req) return self::template() ->createBlock('modal.php', $this->pathViews) ->addVars([ 'title' => t('Deleting the file'), - 'info' => $data, + 'info' => self::filemanager()->parseFile($spl, $path), 'form' => $form ]); } @@ -264,32 +271,32 @@ public function delete($path, $name, $ext, $req) if (!$req->isAjax()) { return $this->get404($req); } + $file = self::core()->getDir('files_public', 'app/files') . "$path$name$ext"; if (!is_file($file)) { return $this->get404($req); } - $dir = self::core()->getDir('files_public', 'app/files') . $path; $validator = (new Validator()) ->setRules([ 'dir' => 'required|dir', 'token_file_delete' => 'token' ]) ->setInputs($req->getParsedBody()) - ->addInput('dir', $dir); + ->addInput('dir', self::core()->getDir('files_public', 'app/files') . $path); $output = []; if ($validator->isValid()) { unlink($file); $output[ 'messages' ][ 'success' ] = [ t('The file has been deleted') ]; - $statut = 200; - } else { - $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); - $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); - $statut = 400; + + return $this->json(200, $output); } - return $this->json($statut, $output); + $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); + $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); + + return $this->json(400, $output); } public function download($path, $name, $ext, $req) @@ -299,19 +306,15 @@ public function download($path, $name, $ext, $req) return $this->get404($req); } - if (\is_file($file)) { - $stream = new Stream(fopen($file, 'r+')); - - return (new Response(200, $stream)) - ->withHeader('content-type', 'application/octet-stream') - ->withHeader('content-length', $stream->getSize()) - ->withHeader('content-disposition', 'attachment; filename=' . substr(strrchr("$name$ext", '/'), 1)) - ->withHeader('pragma', 'no-cache') - ->withHeader('cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0') - ->withHeader('expires', '0'); - } + $stream = new Stream(fopen($file, 'r+')); - return $this->get404($req); + return (new Response(200, $stream)) + ->withHeader('content-type', 'application/octet-stream') + ->withHeader('content-length', $stream->getSize()) + ->withHeader('content-disposition', 'attachment; filename=' . substr("$name$ext", 1)) + ->withHeader('pragma', 'no-cache') + ->withHeader('cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0') + ->withHeader('expires', '0'); } protected function visualizeFile(array $info, $path) diff --git a/core/modules/FileManager/Controller/Folder.php b/core/modules/FileManager/Controller/Folder.php index ffe6ae6c..b3a38ca6 100644 --- a/core/modules/FileManager/Controller/Folder.php +++ b/core/modules/FileManager/Controller/Folder.php @@ -20,13 +20,14 @@ public function create($path, $req) return $this->get404($req); } - $dir = self::core()->getDir('files_public', 'app/files') . $path; - if (!is_dir($dir)) { + $spl = new \SplFileInfo( + self::core()->getDir('files_public', 'app/files') . "$path" + ); + if (!$spl->isDir()) { return $this->get404($req); } - $spl = new \SplFileInfo($dir); - $values[ 'name' ] = ''; + $values = []; if (isset($_SESSION[ 'inputs' ])) { $values = $_SESSION[ 'inputs' ]; unset($_SESSION[ 'inputs' ]); @@ -43,7 +44,7 @@ public function create($path, $req) ->createBlock('modal.php', $this->pathViews) ->addVars([ 'title' => t('Create a new directory'), - 'info' => ['actions' => []], + 'info' => [ 'actions' => [] ], 'form' => $form ]); } @@ -67,25 +68,24 @@ public function store($path, $req) $output = []; if (!$validator->isValid()) { $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); - $statut = 400; - return $this->json($statut, $output); + return $this->json(400, $output); } - $folder = Util::strSlug($validator->getInput('name')); - $dir_create = "$dir/$folder"; + $folder = Util::strSlug($validator->getInput('name')); + $newDir = "$dir/$folder"; - if (!is_dir($dir_create)) { - mkdir($dir_create, 0755, true); + if (!is_dir($newDir)) { + mkdir($newDir, 0755, true); $output[ 'messages' ][ 'success' ] = [ t('The directory is created') ]; - $statut = 200; - } else { - $output[ 'messages' ][ 'errors' ] = [ t('You can not use this directory name') ]; - $statut = 400; + + return $this->json(200, $output); } - return $this->json($statut, $output); + $output[ 'messages' ][ 'errors' ] = [ t('You can not use this directory name') ]; + + return $this->json(400, $output); } public function edit($path, $req) @@ -95,12 +95,13 @@ public function edit($path, $req) } $path = Util::cleanPath($path); - $dir = self::core()->getDir('files_public', 'app/files') . $path; - if (!is_dir($dir)) { + $spl = new \SplFileInfo( + self::core()->getDir('files_public', 'app/files') . "$path" + ); + if (!$spl->isDir()) { return $this->get404($req); } - $spl = new \SplFileInfo($dir); $values = self::filemanager()->parseDir($spl, $path); if (isset($_SESSION[ 'inputs' ])) { $values = $_SESSION[ 'inputs' ]; @@ -118,7 +119,7 @@ public function edit($path, $req) ->createBlock('modal.php', $this->pathViews) ->addVars([ 'title' => t('Rename the directory'), - 'info' => $data, + 'info' => $values, 'form' => $form ]); } @@ -143,28 +144,27 @@ public function update($path, $req) if (!$validator->isValid()) { $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); - $statut = 400; - return $this->json($statut, $output); + return $this->json(400, $output); } - $folder = Util::strSlug($validator->getInput('name')); - $dir_update = dirname($dir) . "/$folder"; + $folder = Util::strSlug($validator->getInput('name')); + $dirUpdate = dirname($dir) . "/$folder"; /* Si le nouveau nom du répertoire est déjà utilisé. */ - if (!is_dir($dir_update)) { + if (!is_dir($dirUpdate)) { $folder = Util::strSlug($validator->getInput('name')); - rename($dir, $dir_update); + rename($dir, $dirUpdate); $output[ 'messages' ][ 'success' ] = [ t('The directory is renamed') ]; - $statut = 200; - } else { - $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); - $output[ 'messages' ][ 'errors' ] = [ t('You can not use this name to rename the directory') ]; - $statut = 400; + + return $this->json(200, $output); } - return $this->json($statut, $output); + $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); + $output[ 'messages' ][ 'errors' ] = [ t('You can not use this name to rename the directory') ]; + + return $this->json(400, $output); } public function remove($path, $req) @@ -173,12 +173,13 @@ public function remove($path, $req) return $this->get404($req); } - $dir = self::core()->getDir('files_public', 'app/files') . $path; - if (!is_dir($dir)) { + $spl = new \SplFileInfo( + self::core()->getDir('files_public', 'app/files') . "$path" + ); + if (!$spl->isDir()) { return $this->get404($req); } - $spl = new \SplFileInfo($dir); - $data = self::filemanager()->parseDir($spl, $path); + $values = self::filemanager()->parseDir($spl, $path); $form = (new FormBuilder([ 'action' => self::router()->getRoute('filemanager.folder.delete', [ ':path' => $path ]), @@ -196,7 +197,7 @@ public function remove($path, $req) return self::template() ->createBlock('modal.php', $this->pathViews) ->addVars([ 'title' => t('Delete directory'), - 'info' => $data, + 'info' => $values, 'form' => $form ]); } @@ -217,8 +218,8 @@ public function delete($path, $req) $output = []; if ($validator->isValid()) { - $dir_iterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); - $iterator = new \RecursiveIteratorIterator($dir_iterator); + $dirIterator = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); + $iterator = new \RecursiveIteratorIterator($dirIterator); /* Supprime tous les dossiers et fichiers */ foreach ($iterator as $file) { @@ -230,13 +231,13 @@ public function delete($path, $req) rmdir($dir); $output[ 'messages' ][ 'success' ] = [ t('The directory has been deleted') ]; - $statut = 200; - } else { - $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); - $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); - $statut = 400; + + return $this->json(200, $output); } - return $this->json($statut, $output); + $output[ 'errors_keys' ] = $validator->getKeyInputErrors(); + $output[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); + + return $this->json(400, $output); } } diff --git a/core/modules/FileManager/Controller/Manager.php b/core/modules/FileManager/Controller/Manager.php index 4aaf327f..2c50d4e7 100644 --- a/core/modules/FileManager/Controller/Manager.php +++ b/core/modules/FileManager/Controller/Manager.php @@ -18,13 +18,14 @@ public function admin($path, $req) { $user = self::user()->isConnected(); $profils = self::fileprofil()->getProfilsFileByUser($user[ 'user_id' ]); + if (empty($profils)) { return $this->get404(); - } else { - $path = $profils[ 0 ][ 'folder_show' ]; - $path = str_replace(':user_id', $user[ 'user_id' ], $path); } + $path = $profils[ 0 ][ 'folder_show' ]; + $path = str_replace(':user_id', $user[ 'user_id' ], $path); + return self::template() ->getTheme('theme_admin') ->view('page', [ @@ -46,29 +47,36 @@ public function show($path, $req) 'onclick' => 'document.getElementById(\'file\').click();', ])) ->group('filemanager-group', 'div', function ($form) { - $form->label('filemanager-box_file-label', ' ' . t('Choose a file') . ' ' . t('or drag it here.')) + $form->label( + 'filemanager-box_file-label', + ' ' + . t('Choose a file') + . ' ' + . t('or drag it here.') + ) ->file('file', [ 'multiple' => 1, - 'style' => 'display:none' ]); + 'style' => 'display:none' + ]); }); $breadcrumb = self::template() ->createBlock('breadcrumb.php', $this->pathViews) ->addVar('links', self::filemanager()->getBreadcrumb($path)); - $files_public = self::core()->getDir('files_public', 'app/files') . $path; - $files = []; - $nb_dir = 0; - $size = 0; - $nb_file = 0; + $filesPublic = self::core()->getDir('files_public', 'app/files') . $path; + $files = []; + $nbDir = 0; + $size = 0; + $nbFile = 0; - if (is_dir($files_public)) { - $dir_iterator = new \DirectoryIterator($files_public); - $iterator = $this->get('filemanager.filter.iterator')->load($path, $dir_iterator); + if (is_dir($filesPublic)) { + $dirIterator = new \DirectoryIterator($filesPublic); + $iterator = $this->get('filemanager.filter.iterator')->load($path, $dirIterator); foreach ($iterator as $file) { try { if ($file->isDir()) { - $nb_dir++; + $nbDir++; $spl = self::filemanager()->parseDir($file, "$path/", $file->getBasename()); $size += $spl[ 'size_octet' ]; $files[] = $spl; @@ -80,7 +88,7 @@ public function show($path, $req) foreach ($iterator as $file) { try { if ($file->isFile()) { - $nb_file++; + $nbFile++; $spl = self::filemanager()->parseFile($file, $path); $size += $spl[ 'size_octet' ]; $files[] = $spl; @@ -104,8 +112,8 @@ public function show($path, $req) ]), 'form' => $form, 'files' => $files, - 'nb_dir' => $nb_dir, - 'nb_file' => $nb_file, + 'nb_dir' => $nbDir, + 'nb_file' => $nbFile, 'size_all' => Util::strFileSizeFormatted($size) ]) ->addBlock('breadcrumb', $breadcrumb); diff --git a/core/modules/FileManager/Controller/Profil.php b/core/modules/FileManager/Controller/Profil.php index 7f8c22f3..e91d2802 100644 --- a/core/modules/FileManager/Controller/Profil.php +++ b/core/modules/FileManager/Controller/Profil.php @@ -54,7 +54,8 @@ public function create($req) $action = self::router()->getRoute('filemanager.profil.store'); $form = (new FormPermission([ 'method' => 'post', 'action' => $action ])) ->setValues($values) - ->roles(self::query()->from('role')->where('role_id', '>', 1)->fetchAll(), []) + ->roles(self::query()->from('role')->where('role_id', '>', 1)->fetchAll(), [ + ]) ->makeFields(); $this->container->callHook('filemanager.profil.create.form', [ &$form, $values ]); @@ -85,7 +86,7 @@ public function store($req) $validator = $this->getValidator($req); $this->container->callHook('filemanager.profil.store.validator', [ &$validator ]); - + $validatorExtension = new Validator(); $isValid = $validator->isValid(); $listExtension = implode(',', FileManager::getWhiteList()); @@ -98,14 +99,19 @@ public function store($req) $isValid &= $validatorExtension->isValid(); if ($isValid) { - $data = $this->getData($validator); - $this->container->callHook('filemanager.profil.store.before', [ $validator, &$data ]); + $data = $this->getData($validator); + $this->container->callHook('filemanager.profil.store.before', [ + $validator, &$data + ]); + self::query() ->insertInto('profil_file', array_keys($data)) ->values($data) ->execute(); - $id_permission_file = self::schema()->getIncrement('profil_file'); - $this->storeProfilRole($validator, $id_permission_file); + + $permissionFileId = self::schema()->getIncrement('profil_file'); + $this->storeProfilRole($validator, $permissionFileId); + $this->container->callHook('filemanager.profil.store.after', [ $validator ]); $_SESSION[ 'messages' ][ 'success' ] = [ t('Saved configuration') ]; @@ -144,13 +150,14 @@ public function edit($id, $req) ->makeFields(); $this->container->callHook('filemanager.profil.edit.form', [ &$form, $values ]); - + $messages = []; if (isset($_SESSION[ 'messages' ])) { $messages = $_SESSION[ 'messages' ]; unset($_SESSION[ 'messages' ]); } if (isset($_SESSION[ 'errors_keys' ])) { + $form->addAttrs($_SESSION[ 'errors_keys' ], [ 'class' => 'is-invalid' ]); unset($_SESSION[ 'errors_keys' ]); } @@ -174,42 +181,44 @@ public function update($id, $req) $validator = $this->getValidator($req); - $this->container->callHook('filemanager.profil.update.validator', [ &$validator, $id ]); + $this->container->callHook('filemanager.profil.update.validator', [ &$validator, + $id ]); $validatorExtension = new Validator(); - $isValid = $validator->isValid(); - $listExtension = implode(',', FileManager::getWhiteList()); + + $listExtension = implode(',', FileManager::getWhiteList()); foreach ($validator->getInput('file_extensions', []) as $key => $extension) { $validatorExtension ->addRule($key, 'inarray:' . $listExtension) ->addLabel($key, $extension) ->addInput($key, $key); } - $isValid &= $validatorExtension->isValid(); + $isValid = $validator->isValid() && $validatorExtension->isValid(); if ($isValid) { $data = $this->getData($validator); - $this->container->callHook('filemanager.profil.update.before', [ $validator, &$data, $id ]); + $this->container->callHook('filemanager.profil.update.before', [ $validator, + &$data, $id ]); self::query() ->update('profil_file', $data) ->where('profil_file_id', '==', $id) ->execute(); $this->updateProfilRole($validator, $id); - $this->container->callHook('filemanager.profil.update.after', [ $validator, $id ]); + $this->container->callHook('filemanager.profil.update.after', [ $validator, + $id ]); $_SESSION[ 'messages' ][ 'success' ] = [ t('Saved configuration') ]; - $route = self::router()->getRoute('filemanager.profil.admin'); - return new Redirect($route); + return new Redirect(self::router()->getRoute('filemanager.profil.admin')); } $_SESSION[ 'inputs' ] = $validator->getInputs(); $_SESSION[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); $_SESSION[ 'errors_keys' ] = $validator->getKeyInputErrors(); - $route = self::router()->getRoute('filemanager.profil.edit', [ ':id' => $id ]); - - return new Redirect($route); + return new Redirect(self::router()->getRoute('filemanager.profil.edit', [ + ':id' => $id + ])); } public function remove($id, $req) @@ -259,52 +268,54 @@ public function delete($id, $req) $validator = (new Validator()) ->addRule('token_file_permission', 'token') ->setInputs($req->getParsedBody()); - $this->container->callHook('filemanager.profil.delete.validator', [ &$validator, - $id ]); + $this->container->callHook('filemanager.profil.delete.validator', [ + &$validator, $id + ]); if ($validator->isValid()) { - $this->container->callHook('filemanager.profil.delete.before', [ $validator, - $id ]); + $this->container->callHook('filemanager.profil.delete.before', [ + $validator, $id + ]); self::query() ->from('profil_file') ->delete() ->where('profil_file_id', '==', $id) ->execute(); - $this->container->callHook('filemanager.profil.delete.after', [ $validator, - $id ]); - $route = self::router()->getRoute('filemanager.profil.admin'); + $this->container->callHook('filemanager.profil.delete.after', [ + $validator, $id + ]); - return new Redirect($route); + return new Redirect(self::router()->getRoute('filemanager.profil.admin')); } $_SESSION[ 'inputs' ] = $validator->getInputs(); $_SESSION[ 'messages' ][ 'errors' ] = $validator->getKeyErrors(); - $route = self::router()->getRoute('filemanager.profil.remove', [ - ':id' => $id ]); - return new Redirect($route); + return new Redirect(self::router()->getRoute('filemanager.profil.remove', [ + ':id' => $id + ])); } - protected function storeProfilRole($validator, $profil_file_id) + protected function storeProfilRole($validator, $profilFileId) { self::query()->insertInto('profil_file_role', [ 'profil_file_id', 'role_id' ]); - foreach (array_keys($validator->getInput('roles')) as $role_id) { - self::query()->values([ $profil_file_id, $role_id ]); + foreach (array_keys($validator->getInput('roles')) as $roleId) { + self::query()->values([ $profilFileId, $roleId ]); } self::query()->execute(); } - protected function updateProfilRole($validator, $profil_file_id) + protected function updateProfilRole($validator, $profilFileId) { self::query() ->from('profil_file_role') - ->where('profil_file_id', '==', $profil_file_id) + ->where('profil_file_id', '==', $profilFileId) ->delete()->execute(); self::query() ->insertInto('profil_file_role', [ 'profil_file_id', 'role_id' ]); - foreach (array_keys($validator->getInput('roles', [])) as $role_id) { - self::query()->values([ $profil_file_id, $role_id ]); + foreach (array_keys($validator->getInput('roles', [])) as $roleId) { + self::query()->values([ $profilFileId, $roleId ]); } self::query()->execute(); } diff --git a/core/modules/FileManager/Services/FileManager.php b/core/modules/FileManager/Services/FileManager.php index 7b5af264..f1acff98 100644 --- a/core/modules/FileManager/Services/FileManager.php +++ b/core/modules/FileManager/Services/FileManager.php @@ -63,6 +63,7 @@ public function getBreadcrumb($path) if (!$this->hookUser->hookFolderShow($nextPath)) { continue; } + $breadcrumb[ $key ] = [ 'title_link' => empty($value) ? ' ' . t('Home') @@ -91,7 +92,9 @@ public function parseDir(\SplFileInfo $dir, $path, $name = '') 'path' => $dir->getPath(), 'size' => Util::strFileSizeFormatted($info[ 'size' ]), 'size_octet' => $info[ 'size' ], - 'time' => strftime('%d/%m/%Y %H:%M', $info[ 'time' ] ? $info[ 'time' ] : $dir->getMTime()), + 'time' => strftime('%d/%m/%Y %H:%M', $info[ 'time' ] + ? $info[ 'time' ] + : $dir->getMTime()), 'type' => 'dir', 'actions' => $this->getActionsFolder($dir, $path, $name) ]; @@ -219,11 +222,11 @@ public function getActionsFile(\SplFileInfo $file, $path) public function parseRecursive($dir) { - $dir_iterator = new \RecursiveDirectoryIterator($dir); - $iterator = new \RecursiveIteratorIterator($dir_iterator); - $size = 0; - $time = 0; - + $dirIterator = new \RecursiveDirectoryIterator($dir); + $iterator = new \RecursiveIteratorIterator($dirIterator); + $size = 0; + $time = 0; + $iterator->rewind(); foreach ($iterator as $file) { if ($iterator->isDot() || $iterator->isLink()) { diff --git a/core/modules/FileManager/Services/FileProfil.php b/core/modules/FileManager/Services/FileProfil.php index e53d5c3a..74649e19 100644 --- a/core/modules/FileManager/Services/FileProfil.php +++ b/core/modules/FileManager/Services/FileProfil.php @@ -9,36 +9,36 @@ public function __construct($query) $this->query = $query; } - public function find($profil_id) + public function find($profilId) { return $this->query->from('profil_file') - ->where('profil_file_id', (int) $profil_id) + ->where('profil_file_id', (int) $profilId) ->fetch(); } - public function getProfil($user_id) + public function getProfil($userId) { return $this->query->from('user_role') ->leftJoin('role', 'role_id', 'role.role_id') ->leftJoin('profil_file_role', 'role_id', 'role.role_id') ->rightJoin('profil_file', 'profil_file_id', 'profil_file.profil_file_id') - ->where('user_id', '==', $user_id) + ->where('user_id', '==', $userId) ->orderBy('role_weight', 'desc') ->orderBy('profil_weight', 'desc') ->fetchAll(); } - public function getRolesUserByProfil($profil_id) + public function getRolesUserByProfil($profilId) { return $this->query->from('profil_file_role') ->leftJoin('role', 'role_id', 'role.role_id') - ->where('profil_file_id', '==', $profil_id) + ->where('profil_file_id', '==', $profilId) ->fetchAll(); } - public function getIdRolesUser($profil_id) + public function getIdRolesUser($profilId) { - $data = $this->getRolesUserByProfil($profil_id); + $data = $this->getRolesUserByProfil($profilId); $out = []; foreach ($data as $value) { $out[] = $value[ 'role_id' ]; @@ -47,13 +47,13 @@ public function getIdRolesUser($profil_id) return $out; } - public function getProfilsFileByUser($user_id) + public function getProfilsFileByUser($userId) { - if (!empty($this->profil[ $user_id ])) { - return $this->profil[ $user_id ]; + if (!empty($this->profil[ $userId ])) { + return $this->profil[ $userId ]; } - $this->profil[ $user_id ] = $this->getProfil($user_id); + $this->profil[ $userId ] = $this->getProfil($userId); - return $this->profil[ $user_id ]; + return $this->profil[ $userId ]; } } diff --git a/core/modules/FileManager/Services/HookMenu.php b/core/modules/FileManager/Services/HookMenu.php index 0c16f757..c8f3dddd 100644 --- a/core/modules/FileManager/Services/HookMenu.php +++ b/core/modules/FileManager/Services/HookMenu.php @@ -19,14 +19,16 @@ public function __construct($router, $profil) $this->profil = $profil; } - public function hookUsersMenu(&$menu, $id_user) + public function hookUsersMenu(&$menu, $userId) { - $profils = $this->profil->getProfilsFileByUser($id_user); + $profils = $this->profil->getProfilsFileByUser($userId); if (empty($profils)) { return; } - $path = Util::cleanPath($profils[ 0 ][ 'folder_show' ]); - $path = str_replace(':user_id', $id_user, $path); + + $path = Util::cleanPath($profils[ 0 ][ 'folder_show' ]); + $path = str_replace(':user_id', $userId, $path); + $menu[] = [ 'link' => $this->router->getRoute('filemanager.admin', [ ':path' => $path diff --git a/core/modules/FileManager/Services/HookUser.php b/core/modules/FileManager/Services/HookUser.php index 576fae2d..d9b80221 100644 --- a/core/modules/FileManager/Services/HookUser.php +++ b/core/modules/FileManager/Services/HookUser.php @@ -12,22 +12,23 @@ public function __construct($user, $profil) $this->profil = $profil; } - public function getRight($path, $user_id = null) + public function getRight($path, $userId = null) { - if (empty($user_id) && ($user = $this->user->isConnected())) { - $user_id = $user[ 'user_id' ]; + if (empty($userId) && ($user = $this->user->isConnected())) { + $userId = $user[ 'user_id' ]; } $path = '/' . Util::cleanPath($path); - $profils = $this->profil->getProfilsFileByUser($user_id); + $profils = $this->profil->getProfilsFileByUser($userId); foreach ($profils as $profil) { $pattern = '/' . Util::cleanPath($profil[ 'folder_show' ]); - $pattern = str_replace(':user_id', $user_id, $pattern); + $pattern = str_replace(':user_id', $userId, $pattern); $pattern .= $profil[ 'folder_show_sub' ] ? '.*' : ''; $pattern = str_replace('/', '\/', $pattern); + if (preg_match('/^' . $pattern . '$/', $path)) { return $profil; } @@ -74,6 +75,7 @@ public function hookFileUpdate( $user = null ) { $right = $this->getRight($path, $user[ 'user_id' ]); + if (empty($right[ 'file_update' ])) { return false; } @@ -85,6 +87,7 @@ public function hookFileCopyClipboard( $path, $name, $ext, + $req = null, $user = null ) { $right = $this->getRight($path, $user[ 'user_id' ]); @@ -100,6 +103,7 @@ public function hookFileDelete( $user = null ) { $right = $this->getRight($path, $user[ 'user_id' ]); + if (empty($right[ 'file_delete' ])) { return false; }