コード例 #1
0
ファイル: Zip.php プロジェクト: ixtrum/file-manager-plugins
 /**
  * Zip files
  *
  * @param string $targetDir Target dir path
  * @param array  $files     Files to zip
  *
  * @throws \Exception
  */
 private function zipFiles($targetDir, $files)
 {
     $zip = new \ZipArchive();
     $zipName = pathinfo($files[0], PATHINFO_FILENAME);
     $zipPath = FileSystem::getUniquePath($targetDir . DIRECTORY_SEPARATOR . $zipName . ".zip");
     if ($zip->open($zipPath, \ZipArchive::CREATE)) {
         foreach ($files as $file) {
             $path = $targetDir . DIRECTORY_SEPARATOR . $file;
             if (is_dir($path)) {
                 $zip->addEmptyDir($file);
                 foreach (Finder::find("*")->from($path) as $item) {
                     $name = $file . DIRECTORY_SEPARATOR . substr_replace($item->getPathname(), "", 0, strlen($path) + 1);
                     if ($item->isDir()) {
                         $zip->addEmptyDir($name);
                     } else {
                         $zip->addFile($item->getRealPath(), $name);
                     }
                 }
             } else {
                 $zip->addFile($path, $file);
             }
         }
         $zip->close();
     } else {
         throw new \Exception("Can not create ZIP archive '{$zipPath}' from '{$targetDir}'.");
     }
 }
コード例 #2
0
 /**
  * Create navigation structure
  *
  * @param string $dir Source directory in relative format
  *
  * @return array
  */
 protected function getNav($dir)
 {
     $var = array();
     $rootname = FileSystem::getRootName();
     if ($dir === $rootname) {
         $var[] = array("name" => $rootname, "link" => $this->link("openDir", $rootname));
     } else {
         $nav = explode("/", $dir);
         $path = "/";
         foreach ($nav as $item) {
             if ($item) {
                 $path .= "{$item}/";
                 $var[] = array("name" => $item, "link" => $this->link("openDir", $path));
             }
         }
     }
     return $var;
 }
コード例 #3
0
ファイル: FileManager.php プロジェクト: ixtrum/file-manager
 /**
  * Get directory content
  *
  * @param string $dir   Directory
  * @param string $mask  Mask
  * @param string $order Order
  *
  * @return array
  */
 private function getContent($dir, $mask, $order)
 {
     $path = $this->getAbsolutePath($dir);
     // Default filter mask
     if (empty($mask)) {
         $mask = "*";
     }
     if ($this->system->parameters["cache"] && $mask === "*") {
         $cache = $this->system->caching->getItem(array("content", $path));
         if ($cache) {
             return $cache;
         }
     }
     $content = array();
     foreach (FileSystem\Finder::findDirectories($mask)->in($path)->orderBy($order) as $item) {
         $entity = new Entities\Directory();
         $entity->actualDir = $dir;
         $entity->name = $item->getFilename();
         $entity->path = $dir . "{$entity->name}/";
         if ($dir === FileSystem::getRootname()) {
             $entity->path = "/{$entity->name}/";
         }
         $entity->modified = $item->getMTime();
         $content["directories"][] = $entity;
     }
     foreach (FileSystem\Finder::findFiles($mask)->in($path)->orderBy($order) as $item) {
         $entity = new Entities\File();
         $entity->actualDir = $dir;
         $entity->name = $item->getFilename();
         $entity->modified = $item->getMTime();
         $entity->size = $this->system->filesystem->getSize($item->getPathName());
         $entity->extension = strtolower(pathinfo($item->getFilename(), PATHINFO_EXTENSION));
         $entity->thumb = false;
         if ($this->system->parameters["thumbs"]) {
             $entity->thumb = in_array($entity->extension, $this->system->thumbs->supported);
         }
         $content["files"][] = $entity;
     }
     if ($this->system->parameters["cache"]) {
         $this->system->caching->saveItem(array("content", $path), $content);
     }
     return $content;
 }
コード例 #4
0
 /**
  * Render in toolbar
  */
 public function renderToolbar()
 {
     $this->template->setFile(__DIR__ . "/toolbar.latte");
     $this->template->setTranslator($this->translator);
     $this->template->clipboard = $this->system->session->clipboard;
     $this->template->rootname = FileSystem::getRootName();
     $this->template->render();
 }