mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-27 13:34:30 -04:00
Adds core/mode. Lots of changes to make installation more flexible.
This commit is contained in:
parent
fd89ea1d90
commit
f1a2a44079
14 changed files with 116 additions and 82 deletions
|
@ -8,6 +8,12 @@ class Entry {
|
|||
private static $cache = array();
|
||||
|
||||
|
||||
private static function startsWith($sequence, $part) {
|
||||
|
||||
return (substr($sequence, 0, strlen($part)) === $part);
|
||||
}
|
||||
|
||||
|
||||
public static function get_cache() {
|
||||
|
||||
return Entry::$cache;
|
||||
|
@ -16,6 +22,11 @@ class Entry {
|
|||
|
||||
public static function get($h5ai, $absPath, $absHref) {
|
||||
|
||||
if (!Entry::startsWith($absHref, $h5ai->getRootAbsHref())) {
|
||||
error_log("ILLEGAL REQUEST: " . $absHref . ", " . $absPath . ", " . $h5ai->getRootAbsHref());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (array_key_exists($absHref, Entry::$cache)) {
|
||||
return Entry::$cache[$absHref];
|
||||
}
|
||||
|
@ -63,8 +74,9 @@ class Entry {
|
|||
}
|
||||
|
||||
$this->parent = null;
|
||||
if ($this->absHref !== "/") {
|
||||
$this->parent = Entry::get($this->h5ai, H5ai::normalize_path(dirname($this->absPath)), H5ai::normalize_path(dirname($this->absHref), true));
|
||||
$parentAbsHref = H5ai::normalize_path(dirname($this->absHref), true);
|
||||
if ($this->absHref !== "/" && Entry::startsWith($parentAbsHref, $h5ai->getRootAbsHref())) {
|
||||
$this->parent = Entry::get($this->h5ai, H5ai::normalize_path(dirname($this->absPath)), $parentAbsHref);
|
||||
}
|
||||
|
||||
$this->isContentFetched = false;
|
||||
|
|
|
@ -56,9 +56,9 @@ class H5ai {
|
|||
$this->requested_from = H5ai::normalize_path($requested_from);
|
||||
|
||||
$this->h5aiAbsPath = H5ai::normalize_path(H5AI_ABS_PATH);
|
||||
$this->rootAbsPath = H5ai::normalize_path(dirname(H5AI_ABS_PATH));
|
||||
|
||||
global $H5AI_CONFIG;
|
||||
$this->rootAbsPath = H5ai::normalize_path($H5AI_CONFIG["ROOT_ABS_PATH"]);
|
||||
$this->ignore_names = $H5AI_CONFIG["IGNORE"];
|
||||
$this->ignore_patterns = $H5AI_CONFIG["IGNORE_PATTERNS"];
|
||||
$this->index_files = $H5AI_CONFIG["INDEX_FILES"];
|
||||
|
@ -66,8 +66,8 @@ class H5ai {
|
|||
$this->config = H5ai::load_config($this->h5aiAbsPath . "/config.js");
|
||||
$this->options = $this->config["options"];
|
||||
|
||||
$this->rootAbsHref = H5ai::normalize_path($this->options["rootAbsHref"], true);
|
||||
$this->h5aiAbsHref = H5ai::normalize_path($this->options["h5aiAbsHref"], true);
|
||||
$this->rootAbsHref = H5ai::normalize_path(dirname($this->options["h5aiAbsHref"]), true);
|
||||
|
||||
$this->absHref = H5ai::normalize_path(preg_replace('/[^\\/]*$/', '', getenv("REQUEST_URI")), true);
|
||||
$this->absPath = $this->getAbsPath($this->absHref);
|
||||
|
@ -275,14 +275,12 @@ class H5ai {
|
|||
$footer = $this->fileExists($footer ? $this->absPath . "/" . $footer : null) ? $footer : null;
|
||||
|
||||
$json = array(
|
||||
"entries" => $entries,
|
||||
"id" => $this->requested_from === $this->h5aiAbsPath . "/php/h5ai-index.php" ? "php" : "idx.php",
|
||||
"serverName" => strtolower(preg_replace("/\\/.*$/", "", getenv("SERVER_SOFTWARE"))),
|
||||
"serverVersion" => strtolower(preg_replace("/^.*\\//", "", preg_replace("/\\s.*$/", "", getenv("SERVER_SOFTWARE")))),
|
||||
"customHeader" => $header,
|
||||
"customFooter" => $footer,
|
||||
"mode" => $this->requested_from === $this->h5aiAbsPath . "/php/h5ai-index.php" ? "php" : "idx.php",
|
||||
"server" => array(
|
||||
"name" => strtolower(preg_replace("/\\/.*$/", "", getenv("SERVER_SOFTWARE"))),
|
||||
"version" => strtolower(preg_replace("/^.*\\//", "", preg_replace("/\\s.*$/", "", getenv("SERVER_SOFTWARE"))))
|
||||
)
|
||||
"entries" => $entries
|
||||
);
|
||||
|
||||
return json_encode($json) . "\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue