/** * @param Nette\Application\UI\Form $form * @param $values * @throws InvalidPathException */ public function renameFormSubmitted(Nette\Application\UI\Form $form, $values) { if ($form->submitted === $form['rename']) { $newName = $values->name . ($this->fileManager->isFeatureEnabled('renameExtension') ? '' : '.' . (new \SplFileInfo($values->file))->getExtension()); if ($this->fileManager->isFeatureEnabled('renameFile') && $values->file != $newName) { $old = self::getPath($this, $values->file); $new = self::getPath($this, $newName); if (!Zax\Utils\PathHelpers::isSubdirOf($this->getRoot(), $new, TRUE)) { throw new InvalidPathException('Invalid name specified.'); } Nette\Utils\FileSystem::rename($old, $new); $this->onFileRename($old, $new); $this->flashMessage('fileManager.alert.fileRenamed', 'success'); } } $this->fileList->go('this', ['view' => 'Default']); }
/** * @param Nette\Application\UI\Form $form * @param $values * @throws InvalidPathException */ public function renameFormSubmitted(Nette\Application\UI\Form $form, $values) { $newName = $values->dir; if ($this->fileManager->isFeatureEnabled('renameDir') && $form->submitted === $form['rename']) { $newName = $values->name; if ($values->dir != $newName) { $dir = $this->getAbsoluteDirectory(); $newPath = Zax\Utils\PathHelpers::rename($dir, $newName); if (!Zax\Utils\PathHelpers::isSubdirOf($this->getRoot(), $newPath, TRUE)) { throw new InvalidPathException('Invalid name specified - ' . $newPath . ' is not inside ' . $this->getRoot()); } Nette\Utils\FileSystem::rename($dir, $newPath); $this->onDirRename($dir, $newPath); $this->flashMessage('fileManager.alert.dirRenamed', 'success'); $newPath = str_replace($this->root, '', $newPath); $this->fileManager->setDirectory($newPath); $this->fileManager->go('this', ['view' => 'Default', 'dir' => $newPath, 'directoryList-view' => 'Default']); } } }
/** * @param Nette\Application\UI\Form $form * @param $values */ public function deleteFormSubmitted(Nette\Application\UI\Form $form, $values) { $goToDir = $this->getDirectory(); $name = $this->getAbsoluteDirectory(); if ($this->fileManager->isFeatureEnabled('deleteDir') && !$this->fileManager->isRootSelected() && $form->submitted === $form['delete']) { Nette\Utils\FileSystem::delete($this->getAbsoluteDirectory()); $goToDir = Zax\Utils\PathHelpers::getParentDir($this->getDirectory()); $this->onDirDelete($name); $this->flashMessage('fileManager.alert.dirDeleted', 'success'); } else { if ($this->fileManager->isFeatureEnabled('truncateDir') && $form->submitted === $form['truncate']) { foreach (Nette\Utils\Finder::find('*')->in($this->getAbsoluteDirectory()) as $k => $file) { Nette\Utils\FileSystem::delete($k); } $this->onDirTruncate($name); $this->flashMessage('fileManager.alert.dirTruncated', 'success'); } } $this->fileManager->setDirectory($goToDir); $this->fileManager->go('this', ['dir' => $goToDir, 'view' => 'Default', 'directoryList-view' => 'Default']); }
public function beforeRender() { $this->template->processedFile = Zax\Utils\PathHelpers::getPath($this->getBasePath(), $this->getRoot(), new \SplFileInfo($this->process())); }
/** * @return string * @throws InvalidPathException */ public function getAbsoluteDirectory() { $dir = realpath($this->getRoot() . $this->getDirectory()); if (!(Zax\Utils\PathHelpers::isSubdirOf($this->getRoot(), $dir) || Zax\Utils\PathHelpers::isEqual($this->getRoot(), $dir))) { throw new InvalidPathException('Outside of allowed folder - ' . $dir . ' is not inside ' . $this->getRoot()); } return $dir; }
public function isRootSelected() { $dir = realpath($this->getRoot() . $this->getDirectory()); return Zax\Utils\PathHelpers::isEqual($this->getRoot(), $dir); }