mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-03-19 12:00:01 +01:00
More PHP refactorings. 'cs' lang update.
This commit is contained in:
parent
42cfe55ef3
commit
bd65025a4c
@ -1,16 +1,19 @@
|
||||
{
|
||||
"lang": "čeština",
|
||||
"details": "podrobnosti",
|
||||
"icons": "ikony",
|
||||
"details": "Podrobnosti",
|
||||
"list": "Dlaždice",
|
||||
"grid": "Seznam",
|
||||
"icons": "Velké ikony",
|
||||
"name": "Název",
|
||||
"lastModified": "Upraveno",
|
||||
"lastModified": "Datum změny",
|
||||
"size": "Velikost",
|
||||
"parentDirectory": "Nadřazený adresář",
|
||||
"empty": "prázdný",
|
||||
"empty": "Prázdná složka",
|
||||
"folders": "složek",
|
||||
"files": "souborů",
|
||||
"download": "stáhnout",
|
||||
"noMatch": "žádná shoda",
|
||||
"download": "Stáhnout",
|
||||
"noMatch": "Žádná shoda",
|
||||
"dateFormat": "DD.MM.YYYY HH:mm",
|
||||
"filter": "filtr"
|
||||
"filter": "Filtr",
|
||||
"delete": "Odstranit"
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
|
||||
- var appHref = "/_{{pkg.name}}/client"
|
||||
- var href = "/_{{pkg.name}}/"
|
||||
|
||||
doctype 5
|
||||
//if lt IE 9
|
||||
@ -11,14 +11,14 @@ doctype 5
|
||||
head
|
||||
meta( charset="utf-8" )
|
||||
meta( http-equiv="X-UA-Compatible", content="IE=edge,chrome=1" )
|
||||
title Directory index · styled with {{pkg.name}} {{pkg.version}}
|
||||
meta( name="description", content="Directory index styled with {{pkg.name}} {{pkg.version}} ({{pkg.url}})" )
|
||||
title index · styled with {{pkg.name}} {{pkg.version}} ({{pkg.url}})
|
||||
meta( name="description", content="index styled with {{pkg.name}} {{pkg.version}} ({{pkg.url}})" )
|
||||
meta( name="viewport", content="width=device-width" )
|
||||
link( rel="shortcut icon", href="#{appHref}/images/app-16x16.ico" )
|
||||
link( rel="apple-touch-icon", type="image/png", href="#{appHref}/images/app-48x48.png" )
|
||||
link( rel="shortcut icon", href="#{href}client/images/app-16x16.ico" )
|
||||
link( rel="apple-touch-icon", type="image/png", href="#{href}client/images/app-48x48.png" )
|
||||
link( rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic,700italic|Ubuntu:400,700,400italic,700italic" )
|
||||
link( rel="stylesheet", href="#{appHref}/css/styles.css" )
|
||||
script( src="#{appHref}/js/scripts.js" )
|
||||
link( rel="stylesheet", href="#{href}client/css/styles.css" )
|
||||
script( src="#{href}client/js/scripts.js" )
|
||||
|
||||
|<body id="h5ai-main">
|
||||
|
||||
|
@ -80,7 +80,9 @@ class App {
|
||||
$parts = explode("/", $abs_path);
|
||||
$encoded_parts = array();
|
||||
foreach ($parts as $part) {
|
||||
$encoded_parts[] = rawurlencode($part);
|
||||
if ($part) {
|
||||
$encoded_parts[] = rawurlencode($part);
|
||||
}
|
||||
}
|
||||
|
||||
return normalize_path($this->root_abs_href . implode("/", $encoded_parts), $trailing_slash);
|
||||
@ -147,7 +149,7 @@ class App {
|
||||
return 200;
|
||||
}
|
||||
}
|
||||
return "h5ai";
|
||||
return App::$MAGIC_SEQUENCE;
|
||||
}
|
||||
|
||||
|
||||
@ -189,27 +191,30 @@ class App {
|
||||
|
||||
public function get_entries($abs_href, $what) {
|
||||
|
||||
$folder = Entry::get($this, $this->get_abs_path($abs_href), $abs_href);
|
||||
$cache = array();
|
||||
$folder = Entry::get($this, $this->get_abs_path($abs_href), $cache);
|
||||
|
||||
if ($what > 1 && $folder !== null) {
|
||||
foreach ($folder->getContent() as $entry) {
|
||||
$entry->getContent();
|
||||
// add content of subfolders
|
||||
if ($what >= 2 && $folder !== null) {
|
||||
foreach ($folder->get_content($cache) as $entry) {
|
||||
$entry->get_content($cache);
|
||||
}
|
||||
$folder = $folder->getParent();
|
||||
$folder = $folder->get_parent($cache);
|
||||
}
|
||||
|
||||
while ($what > 0 && $folder !== null) {
|
||||
$folder->getContent();
|
||||
$folder = $folder->getParent();
|
||||
}
|
||||
Entry::sort();
|
||||
|
||||
$entries = array();
|
||||
foreach (Entry::get_cache() as $entry) {
|
||||
$entries[] = $entry->toJsonObject(true);
|
||||
// add content of this folder and all parent folders
|
||||
while ($what >= 1 && $folder !== null) {
|
||||
$folder->get_content($cache);
|
||||
$folder = $folder->get_parent($cache);
|
||||
}
|
||||
|
||||
return $entries;
|
||||
uasort($cache, array("Entry", "cmp"));
|
||||
$result = array();
|
||||
foreach ($cache as $p => $entry) {
|
||||
$result[] = $entry->to_json_object();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@ -217,31 +222,32 @@ class App {
|
||||
|
||||
date_default_timezone_set("UTC");
|
||||
|
||||
function _cmp_no_js_fallback($entry1, $entry2) {
|
||||
// function _cmp_no_js_fallback($entry1, $entry2) {
|
||||
|
||||
if ($entry1->isFolder && !$entry2->isFolder) {
|
||||
return -1;
|
||||
}
|
||||
if (!$entry1->isFolder && $entry2->isFolder) {
|
||||
return 1;
|
||||
}
|
||||
// if ($entry1->isFolder && !$entry2->isFolder) {
|
||||
// return -1;
|
||||
// }
|
||||
// if (!$entry1->isFolder && $entry2->isFolder) {
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
return strcasecmp($entry1->absHref, $entry2->absHref);
|
||||
}
|
||||
// return strcasecmp($entry1->abs_href, $entry2->abs_href);
|
||||
// }
|
||||
|
||||
$folder = Entry::get($this, $this->abs_path, $this->abs_href);
|
||||
$entries = $folder->getContent();
|
||||
uasort($entries, "_cmp_no_js_fallback");
|
||||
$cache = array();
|
||||
$folder = Entry::get($this, $this->abs_path, $cache);
|
||||
$entries = $folder->get_content($cache);
|
||||
uasort($entries, array("Entry", "cmp"));
|
||||
|
||||
$html = "<table>";
|
||||
$html .= "<tr><th></th><th><span>Name</span></th><th><span>Last modified</span></th><th><span>Size</span></th></tr>";
|
||||
if ($folder->parent) {
|
||||
if ($folder->get_parent($cache)) {
|
||||
$html .= "<tr><td></td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
|
||||
}
|
||||
foreach ($entries as $entry) {
|
||||
$html .= "<tr>";
|
||||
$html .= "<td></td>";
|
||||
$html .= "<td><a href=\"" . $entry->absHref . "\">" . basename($entry->absPath) . ($entry->isFolder ? "/" : "") . "</a></td>";
|
||||
$html .= "<td>" . ($entry->is_folder ? "[D]" : "[F]") . "</td>";
|
||||
$html .= "<td><a href=\"" . $entry->abs_href . "\">" . basename($entry->abs_path) . ($entry->is_folder ? "/" : "") . "</a></td>";
|
||||
$html .= "<td>" . date("Y-m-d H:i", $entry->date) . "</td>";
|
||||
$html .= "<td>" . ($entry->size !== null ? intval($entry->size / 1000) . " KB" : "" ) . "</td>";
|
||||
$html .= "</tr>";
|
||||
|
@ -4,119 +4,105 @@ class Entry {
|
||||
|
||||
private static $FOLDER_SIZE_CMD = "du -sb \"[DIR]\"";
|
||||
|
||||
public static function cmp($entry1, $entry2) {
|
||||
|
||||
private static $cache = array();
|
||||
|
||||
|
||||
public static function get_cache() {
|
||||
|
||||
return Entry::$cache;
|
||||
return strcasecmp($entry1->abs_path, $entry2->abs_path);
|
||||
}
|
||||
|
||||
public static function get($app, $abs_path, &$cache) {
|
||||
|
||||
public static function get($h5ai, $absPath, $absHref) {
|
||||
|
||||
if (!starts_with($absHref, $h5ai->get_root_abs_href())) {
|
||||
error_log("ILLEGAL REQUEST: " . $absHref . ", " . $absPath . ", " . $h5ai->get_root_abs_href());
|
||||
if (!starts_with($abs_path, $app->get_root_abs_path())) {
|
||||
error_log("ILLEGAL REQUEST: " . $abs_path . ", " . $app->get_root_abs_path());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (array_key_exists($absHref, Entry::$cache)) {
|
||||
return Entry::$cache[$absHref];
|
||||
if (is_array($cache) && array_key_exists($abs_path, $cache)) {
|
||||
return $cache[$abs_path];
|
||||
}
|
||||
|
||||
return new Entry($h5ai, $absPath, $absHref);
|
||||
$entry = new Entry($app, $abs_path);
|
||||
|
||||
if (is_array($cache)) {
|
||||
$cache[$abs_path] = $entry;
|
||||
}
|
||||
return $entry;
|
||||
}
|
||||
|
||||
|
||||
public static function sort() {
|
||||
|
||||
function cmp($entry1, $entry2) {
|
||||
|
||||
return strcasecmp($entry1->absHref, $entry2->absHref);
|
||||
}
|
||||
|
||||
uasort(Entry::$cache, "cmp");
|
||||
}
|
||||
public $app,
|
||||
$abs_path, $abs_href,
|
||||
$date, $size,
|
||||
$is_folder,
|
||||
$is_content_fetched;
|
||||
|
||||
|
||||
private function __construct($app, $abs_path) {
|
||||
|
||||
$this->app = $app;
|
||||
|
||||
public $h5ai, $absPath, $absHref, $date, $size, $isFolder, $parent, $isContentFetched;
|
||||
$this->abs_path = normalize_path($abs_path);
|
||||
$this->is_folder = is_dir($this->abs_path);
|
||||
$this->abs_href = $this->app->get_abs_href($abs_path, $this->is_folder);
|
||||
|
||||
$this->date = filemtime($this->abs_path);
|
||||
|
||||
private function __construct($h5ai, $absPath, $absHref) {
|
||||
|
||||
$this->h5ai = $h5ai;
|
||||
|
||||
$this->absPath = normalize_path($absPath);
|
||||
|
||||
$this->isFolder = is_dir($this->absPath);
|
||||
$this->absHref = normalize_path($absHref, $this->isFolder);
|
||||
|
||||
$this->date = filemtime($this->absPath);
|
||||
|
||||
if ($this->isFolder) {
|
||||
if ($this->is_folder) {
|
||||
$this->size = null;
|
||||
$options = $h5ai->get_options();
|
||||
$options = $app->get_options();
|
||||
if ($options["foldersize"]["enabled"]) {
|
||||
$cmd = str_replace("[DIR]", $this->absPath, Entry::$FOLDER_SIZE_CMD);
|
||||
$cmd = str_replace("[DIR]", $this->abs_path, Entry::$FOLDER_SIZE_CMD);
|
||||
$this->size = intval(preg_replace("/\s.*$/", "", `$cmd`), 10);
|
||||
}
|
||||
} else {
|
||||
$this->size = filesize($this->absPath);
|
||||
$this->size = filesize($this->abs_path);
|
||||
}
|
||||
|
||||
$this->parent = null;
|
||||
$parentAbsHref = normalize_path(dirname($this->absHref), true);
|
||||
if ($this->absHref !== "/" && starts_with($parentAbsHref, $h5ai->get_root_abs_href())) {
|
||||
$this->parent = Entry::get($this->h5ai, normalize_path(dirname($this->absPath)), $parentAbsHref);
|
||||
}
|
||||
|
||||
$this->isContentFetched = false;
|
||||
|
||||
Entry::$cache[$this->absHref] = $this;
|
||||
$this->is_content_fetched = false;
|
||||
}
|
||||
|
||||
|
||||
public function toJsonObject($withStatus) {
|
||||
public function to_json_object() {
|
||||
|
||||
$obj = array(
|
||||
"absHref" => $this->absHref,
|
||||
"time" => ($this->date * 1000),
|
||||
"absHref" => $this->abs_href,
|
||||
"time" => $this->date * 1000, // seconds (PHP) to milliseconds (JavaScript)
|
||||
"size" => $this->size
|
||||
);
|
||||
|
||||
if ($withStatus && $this->isFolder) {
|
||||
$obj["status"] = $this->h5ai->get_http_code($this->absHref);
|
||||
$obj["content"] = $this->isContentFetched;
|
||||
if ($this->is_folder) {
|
||||
$obj["status"] = $this->app->get_http_code($this->abs_href);
|
||||
$obj["content"] = $this->is_content_fetched;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
public function getParent() {
|
||||
public function get_parent(&$cache) {
|
||||
|
||||
return $this->parent;
|
||||
$parentAbsPath = normalize_path(dirname($this->abs_path));
|
||||
if (starts_with($parentAbsPath, $this->app->get_root_abs_path())) {
|
||||
return Entry::get($this->app, $parentAbsPath, $cache);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function getContent() {
|
||||
public function get_content(&$cache) {
|
||||
|
||||
$content = array();
|
||||
|
||||
if ($this->h5ai->get_http_code($this->absHref) !== "h5ai") {
|
||||
if ($this->app->get_http_code($this->abs_href) !== App::$MAGIC_SEQUENCE) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$files = $this->h5ai->read_dir($this->absPath);
|
||||
$files = $this->app->read_dir($this->abs_path);
|
||||
foreach ($files as $file) {
|
||||
$entry = Entry::get($this->h5ai, $this->absPath . "/" . $file, $this->absHref . rawurlencode($file));
|
||||
$content[$entry->absPath] = $entry;
|
||||
$entry = Entry::get($this->app, $this->abs_path . "/" . $file, $cache);
|
||||
$content[$entry->abs_path] = $entry;
|
||||
}
|
||||
|
||||
$this->isContentFetched = true;
|
||||
$this->is_content_fetched = true;
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
@ -1,14 +1,9 @@
|
||||
|<?php
|
||||
| header("Content-type: text/html;{{pkg.name}}={{pkg.version}}");
|
||||
| require_once(str_replace("\\", "/", dirname(__FILE__)) . "/inc/init.php");
|
||||
| $app_abs_href = $APP->get_app_abs_href();
|
||||
| $is_head_request = stripos($_SERVER["REQUEST_METHOD"], "HEAD");
|
||||
|?>
|
||||
|<?php require_once(str_replace("\\", "/", dirname(__FILE__)) . "/inc/init.php"); ?>
|
||||
|
||||
- var appHref = "<?php echo $app_abs_href; ?>client"
|
||||
- var json = "<?php if (!$is_head_request) { echo $APP->get_generic_json(); }?>"
|
||||
- var fallback = "<?php if (!$is_head_request) { echo $APP->get_no_js_fallback(); }?>"
|
||||
- var config = "<?php if (!$is_head_request) { echo $APP->get_custom_config(); }?>"
|
||||
- var href = "<?php echo $APP->get_app_abs_href(); ?>"
|
||||
- var json = "<?php echo $APP->get_generic_json(); ?>"
|
||||
- var fallback = "<?php echo $APP->get_no_js_fallback(); ?>"
|
||||
- var config = "<?php echo $APP->get_custom_config(); ?>"
|
||||
|
||||
doctype 5
|
||||
//if lt IE 9
|
||||
@ -20,14 +15,14 @@ html.no-js( lang="en" )
|
||||
head
|
||||
meta( charset="utf-8" )
|
||||
meta( http-equiv="X-UA-Compatible", content="IE=edge,chrome=1" )
|
||||
title Directory index · styled with {{pkg.name}} {{pkg.version}}
|
||||
meta( name="description", content="Directory index styled with {{pkg.name}} {{pkg.version}} ({{pkg.url}})" )
|
||||
title index · styled with {{pkg.name}} {{pkg.version}} ({{pkg.url}})
|
||||
meta( name="description", content="index styled with {{pkg.name}} {{pkg.version}} ({{pkg.url}})" )
|
||||
meta( name="viewport", content="width=device-width" )
|
||||
link( rel="shortcut icon", href!="#{appHref}/images/app-16x16.ico" )
|
||||
link( rel="apple-touch-icon", type="image/png", href!="#{appHref}/images/app-48x48.png" )
|
||||
link( rel="shortcut icon", href!="#{href}client/images/app-16x16.ico" )
|
||||
link( rel="apple-touch-icon", type="image/png", href!="#{href}client/images/app-48x48.png" )
|
||||
link( rel="stylesheet", href="//fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic,700italic|Ubuntu:400,700,400italic,700italic" )
|
||||
link( rel="stylesheet", href!="#{appHref}/css/styles.css" )
|
||||
script( src!="#{appHref}/js/scripts.js", data-config!="#{config}" )
|
||||
link( rel="stylesheet", href!="#{href}client/css/styles.css" )
|
||||
script( src!="#{href}client/js/scripts.js", data-config!="#{config}" )
|
||||
|
||||
body#h5ai-main
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user