Beispiel #1
0
 /**
  * Get dir structure
  *
  * @param string $dir Dir path
  *
  * @return array
  */
 private function getDirTree($dir)
 {
     $x = array();
     $dirs = Finder::findDirectories("*")->in($dir);
     foreach ($dirs as $dir) {
         $x[$dir->getFilename()] = $this->getDirTree($dir->getPathName());
     }
     return $x;
 }
Beispiel #2
0
 /**
  * Delete items from cache with recursion
  *
  * @param string $absDir Absolute directory path
  */
 public function deleteItemsRecursive($absDir)
 {
     $dirs = Finder::findDirectories("*")->from($absDir);
     $cache = $this->cache;
     foreach ($dirs as $dir) {
         unset($cache[array("content", $dir->getRealPath())]);
     }
     unset($cache[array("content", $absDir)]);
     $this->deleteItem(null, array("tags" => "treeview"));
 }
Beispiel #3
0
 /**
  * Load themes from theme dir
  *
  * @param string $themeDir Dir with themes
  *
  * @return array
  */
 public function loadThemes($themeDir)
 {
     $themes = array();
     if (!is_dir($themeDir)) {
         return $themes;
     }
     $dirs = Finder::findDirectories("*")->in($themeDir);
     foreach ($dirs as $dir) {
         $themes[$dir->getFilename()] = ucfirst($dir->getFilename());
     }
     return $themes;
 }
Beispiel #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;
 }
Beispiel #5
0
 /**
  * Get info about files
  *
  * @param string  $dir     Dir
  * @param array   $files   Files
  * @param boolean $iterate Iterate? (optional)
  *
  * @return array
  */
 private function getFilesInfo($dir, $files, $iterate = true)
 {
     $path = $this->getAbsolutePath($dir);
     $info = array("size" => 0, "dirCount" => 0, "filesCount" => 0);
     foreach ($files as $file) {
         $filePath = $path . DIRECTORY_SEPARATOR . $file;
         if (!is_dir($filePath)) {
             $info['size'] += $this->system->filesystem->getSize($filePath);
             $info['filesCount']++;
         } elseif ($iterate) {
             $info['dirCount']++;
             $items = Finder::find('*')->from($filePath);
             foreach ($items as $item) {
                 if ($item->isDir()) {
                     $info['dirCount']++;
                 } else {
                     $info['size'] += $this->system->filesystem->getSize($item->getPathName());
                     $info['filesCount']++;
                 }
             }
         }
     }
     return $info;
 }
Beispiel #6
0
 /**
  * Get directory content
  *
  * @param string $dir   Directory
  * @param string $mask  Mask
  * @param string $view  View
  * @param string $order Order
  *
  * @return array
  *
  * @todo Finder does not support mask for directories
  */
 private function getDirectoryContent($dir, $mask, $view, $order)
 {
     $files = Finder::find($mask)->in($this->getAbsolutePath($dir))->orderBy($order);
     $content = array();
     foreach ($files as $file) {
         $name = $file->getFilename();
         $content[$name]["modified"] = $file->getMTime();
         $content[$name]["dir"] = false;
         if ($file->isFile()) {
             $content[$name]["size"] = $this->system->filesystem->getSize($file->getPathName());
             $content[$name]["extension"] = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
             $content[$name]["thumb"] = false;
             if ($this->system->parameters["thumbs"]) {
                 $content[$name]["thumb"] = in_array($content[$name]["extension"], $this->system->thumbs->supported);
             }
         } else {
             $content[$name]["dir"] = true;
         }
     }
     return $content;
 }
Beispiel #7
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);
         }
     }
 }
Beispiel #8
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();
 }