Adds core/mode. Lots of changes to make installation more flexible.

This commit is contained in:
Lars Jung 2012-08-17 16:35:25 +02:00
parent fd89ea1d90
commit f1a2a44079
14 changed files with 116 additions and 82 deletions

View file

@ -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;

View file

@ -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";