示例#1
0
 /**
  * @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']);
 }
示例#2
0
 /**
  * @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']);
         }
     }
 }
示例#3
0
 /**
  * @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;
 }