/** * Edit a file or a directory * * @retun array */ protected function editFile() { $editForm = null; $isDirectory = false; // get a path $userPath = $this->getUserPath(); $filePath = $this->getRequest()->getQuery('file_path', null); $fileName = null != $this->getRequest()->getQuery('slug', null) ? FileManagerBaseModel::slugifyFileName($this->getRequest()->getQuery('slug'), false, true) : null; // get current user directories structure $userDirectories = $this->getModel()->getUserDirectories(); // get absolute paths $userDirectory = $this->getModel()->getUserDirectory($userPath); $currentDirectory = $this->getModel()->getUserDirectory($filePath); // check the paths if (false !== $userDirectory && false !== $currentDirectory && $fileName) { // check the file name $fullFilePath = $currentDirectory . $fileName; $isDirectory = is_dir($fullFilePath); if ($fileName != '.' && $fileName != '..' && file_exists($fullFilePath)) { // get a form $editForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('FileManager\\Form\\FileManagerEdit')->setFileName($fileName)->setFullFilePath($currentDirectory)->setFullUserPath($userDirectory)->isDirectory($isDirectory)->setUserPath($userPath); $request = $this->getRequest(); // validate the form if ($request->isPost()) { // fill the form with received values $editForm->getForm()->setData($request->getPost(), false); // save data if ($editForm->getForm()->isValid()) { // check the permission and increase permission's actions track if (true !== ($result = $this->aclCheckPermission())) { return $result; } // edit the file if (false === ($newFileName = $this->getModel()->editFile($editForm->getForm()->getData()['name'], $fullFilePath, $userDirectory, $isDirectory))) { $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate(!$isDirectory ? 'Impossible edit selected file' : 'Impossible edit selected directory')); } else { $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate(!$isDirectory ? 'The file has been edited' : 'The directory has been edited')); } return $this->redirectTo($this->params('controller'), 'edit', [], false, ['path' => $userPath, 'file_path' => $userPath, 'slug' => $newFileName ? $newFileName : $fileName]); } } } } return ['is_directory' => $isDirectory, 'edit_form' => $editForm ? $editForm->getForm() : null, 'path' => $userPath, 'file_path' => $filePath, 'file_name' => $fileName, 'user_directories' => $userDirectories]; }