h5ai = $h5ai; $this->label = $this->h5ai->getLabel($absHref); $this->absPath = $this->h5ai->normalizePath($absPath, false); $this->isFolder = is_dir($this->absPath); $this->absHref = $this->h5ai->normalizePath($absHref, $this->isFolder); $this->type = $type !== null ? $type : ($this->isFolder ? "folder" : $this->h5ai->getType($this->absPath)); $this->content = null; } public function loadContent() { $this->content = array(); if ($this->h5ai->getHttpCode($this->absHref) !== "h5ai") { return; } $files = $this->h5ai->readDir($this->absPath); foreach ($files as $file) { $tree = new TreeEntry($this->h5ai, $this->absPath . "/" . $file, $this->absHref . rawurlencode($file)); if ($tree->isFolder) { $this->content[$tree->absPath] = $tree; } } $this->sort(); } public function cmpTrees($t1, $t2) { if ($t1->isFolder && !$t2->isFolder) { return -1; } if (!$t1->isFolder && $t2->isFolder) { return 1; } return strcasecmp($t1->absPath, $t2->absPath); } public function sort() { if ($this->content !== null) { uasort($this->content, array($this, "cmpTrees")); } } public function toHtml() { $classes = "entry " . $this->type . ($this->absHref === $this->h5ai->getAbsHref() ? " current" : ""); $icon = $this->type; if ($this->absHref === "/") { $icon = "folder-home"; } $hint = ""; $code = "h5ai"; if ($this->isFolder) { $code = $this->h5ai->getHttpCode($this->absHref); $classes .= " checkedHttpCode"; if ($code !== "h5ai") { if ($code === 200) { $icon = "folder-page"; $hint = "page"; } else { $classes .= " error"; $hint = " " . $code . " "; } } } $html = "
\n"; if ($this->content !== null && count($this->content) === 0 || $code !== "h5ai") { $html .= "\n"; } else { $indicatorState = $this->content === null ? " unknown" : " open"; $html .= ">\n"; } $html .= "\n"; $html .= "" . $icon . "\n"; $html .= "" . $this->label . "" . $hint . "\n"; $html .= "\n"; $html .= $this->contentToHtml(); $html .= "
\n"; return $html; } public function contentToHtml() { $html = "\n"; return $html; } public function getRoot() { if ($this->absHref === "/") { return $this; }; $tree = new TreeEntry($this->h5ai, safe_dirname($this->absPath), safe_dirname($this->absHref, true)); $tree->loadContent(); $tree->content[$this->absPath] = $this; return $tree->getRoot(); } } class Tree { private $h5ai; public function __construct($h5ai) { $this->h5ai = $h5ai; } public function toHtml() { $options = $this->h5ai->getOptions(); if ($options["showTree"] === false) { return ""; } $tree = new TreeEntry($this->h5ai, $this->h5ai->getAbsPath(), $this->h5ai->getAbsHref()); $tree->loadContent(); $root = $tree->getRoot(); return "
\n" . $root->toHtml() . "
\n"; } } ?>