/** * 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; }
/** * 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; }
/** * Delete file/directory * * @param string $path Path to file/directory * * @return boolean */ public function delete($path) { if (is_dir($path)) { foreach (Finder::find("*")->in($path) as $item) { if ($item->isDir()) { $this->delete($item->getRealPath()); } else { unlink($item->getPathName()); } } if (!@rmdir($path)) { return false; } } else { unlink($path); } return true; }