示例#1
0
 /**
  * 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;
 }
示例#2
0
 /**
  * Get file/directory size
  *
  * @param string $path Path to file/dir
  *
  * @return string
  */
 public function getSize($path)
 {
     if (is_dir($path)) {
         $size = 0;
         $files = Finder::findFiles("*")->from($path);
         foreach ($files as $file) {
             $size += $this->getSize($file->getPathName());
         }
         return $size;
     }
     $fileSize = new FileSystem\FileSize($path);
     return $fileSize->getSize();
 }
示例#3
0
 /**
  * Get files count in directory
  *
  * @param string $path Dir path
  *
  * @return integer
  */
 private function getDirFilesCount($path)
 {
     $count = 0;
     $files = Finder::findFiles("*")->from($path);
     foreach ($files as $file) {
         if ($file->isFile()) {
             $count++;
         }
     }
     return $count;
 }
示例#4
0
 /**
  * Get available languages
  *
  * @todo Get lanugage title too
  *
  * @return array
  */
 private function getLanguages($langDir)
 {
     $langs = array($this->defaults["lang"] => $this->defaults["lang"]);
     foreach (Finder::findFiles("*.json")->in($langDir) as $file) {
         $langs[$file->getBasename(".json")] = $file->getBasename(".json");
     }
     return $langs;
 }
示例#5
0
 /**
  * Delete all thumbs from directory recursively
  *
  * @param string $dir Directory path
  *
  * @throws \Exception
  */
 public function deleteDirThumbs($dir)
 {
     if (!is_dir($dir)) {
         throw new \Exception("Directory '{$dir}' not found!");
     }
     $mask = $this->supported;
     foreach ($mask as $key => $val) {
         $mask[$key] = "*.{$val}";
     }
     $files = Finder::findFiles($mask)->from($dir);
     foreach ($files as $file) {
         $thumbPath = $this->getThumbPath($file->getPathname());
         if (file_exists($thumbPath)) {
             unlink($thumbPath);
         }
     }
 }