app_abs_path = normalize_path($app_abs_path); $this->root_abs_path = normalize_path(dirname($this->app_abs_path)); $this->app_abs_href = normalize_path($app_abs_href, true); $this->root_abs_href = normalize_path(dirname($this->app_abs_href), true); $this->abs_href = normalize_path($abs_href, true); $this->abs_path = $this->get_abs_path($this->abs_href); $this->options = load_commented_json($this->app_abs_path . "/conf/options.json"); } public function get_root_abs_path() { return $this->root_abs_path; } public function get_root_abs_href() { return $this->root_abs_href; } public function get_app_abs_href() { return $this->app_abs_href; } public function get_cache_abs_path() { return $this->app_abs_path . '/' . App::$CACHE_DIR; } public function get_cache_abs_href() { return $this->app_abs_href . App::$CACHE_DIR . '/'; } public function get_abs_href($abs_path = null, $trailing_slash = true) { if ($abs_path === null) { return $this->abs_href; } $abs_path = substr($abs_path, strlen($this->root_abs_path)); $parts = explode("/", $abs_path); $encoded_parts = array(); foreach ($parts as $part) { if ($part) { $encoded_parts[] = rawurlencode($part); } } return normalize_path($this->root_abs_href . implode("/", $encoded_parts), $trailing_slash); } public function get_abs_path($abs_href = null) { if ($abs_href === null) { return $this->abs_path; } $abs_href = substr($abs_href, strlen($this->root_abs_href)); return normalize_path($this->root_abs_path . "/" . rawurldecode($abs_href)); } public function is_ignored($name) { // always ignore if ($name === "." || $name === "..") { return true; } foreach ($this->options["view"]["ignore"] as $re) { $re = App::$RE_DELIMITER . str_replace(App::$RE_DELIMITER, '\\' . App::$RE_DELIMITER, $re) . App::$RE_DELIMITER; if (preg_match($re, $name)) { return true; } } return false; } public function read_dir($path) { $content = array(); if (is_dir($path)) { if ($dir = opendir($path)) { while (($file = readdir($dir)) !== false) { if (!$this->is_ignored($file) && !$this->is_ignored($this->get_abs_href($path) . $file)) { $content[] = $file; } } closedir($dir); } } return $content; } public function get_options() { return $this->options; } public function get_http_code($abs_href) { if (!is_dir($this->get_abs_path($abs_href))) { return 500; } $abs_path = $this->get_abs_path($abs_href); foreach ($this->options["view"]["indexFiles"] as $if) { if (file_exists($abs_path . "/" . $if)) { return 200; } } return App::$MAGIC_SEQUENCE; } public function get_generic_json() { return json_encode(array("items" => $this->get_items($this->abs_href, 1))) . "\n"; } public function get_items($abs_href, $what) { $cache = array(); $folder = Item::get($this, $this->get_abs_path($abs_href), $cache); // add content of subfolders if ($what >= 2 && $folder !== null) { foreach ($folder->get_content($cache) as $item) { $item->get_content($cache); } $folder = $folder->get_parent($cache); } // add content of this folder and all parent folders while ($what >= 1 && $folder !== null) { $folder->get_content($cache); $folder = $folder->get_parent($cache); } uasort($cache, array("Item", "cmp")); $result = array(); foreach ($cache as $p => $item) { $result[] = $item->to_json_object(); } return $result; } public function get_no_js_fallback() { date_default_timezone_set("UTC"); $cache = array(); $folder = Item::get($this, $this->abs_path, $cache); $items = $folder->get_content($cache); uasort($items, array("Item", "cmp")); $html = "
Name | Last modified | Size | |
---|---|---|---|
Parent Directory | |||
abs_href . "\">" . basename($item->abs_path) . " | "; $html .= "" . date("Y-m-d H:i", $item->date) . " | "; $html .= "" . ($item->size !== null ? intval($item->size / 1000) . " KB" : "" ) . " | "; $html .= "