mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -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
|
@ -10,10 +10,9 @@ var H5AI_CONFIG = {
|
||||||
"options": {
|
"options": {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The absolute links to webroot and h5ai.
|
The absolute link to h5ai.
|
||||||
Do not change this unless you know what you are doing.
|
Must point to the "_h5ai" directory.
|
||||||
*/
|
*/
|
||||||
"rootAbsHref": "/",
|
|
||||||
"h5aiAbsHref": "/_h5ai/",
|
"h5aiAbsHref": "/_h5ai/",
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -10,12 +10,6 @@ global $H5AI_CONFIG;
|
||||||
|
|
||||||
$H5AI_CONFIG = array(
|
$H5AI_CONFIG = array(
|
||||||
|
|
||||||
/*
|
|
||||||
* This configuration assumes that h5ai is installed
|
|
||||||
* in the webroot directory of the web server.
|
|
||||||
*/
|
|
||||||
"ROOT_ABS_PATH" => dirname(dirname(__FILE__)),
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Files/folders that should not be listed. Specified
|
* Files/folders that should not be listed. Specified
|
||||||
* by the complete filename or by a regular expression.
|
* by the complete filename or by a regular expression.
|
||||||
|
@ -26,7 +20,7 @@ $H5AI_CONFIG = array(
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Folders that contain one of these files will be considered
|
* Folders that contain one of these files will be considered
|
||||||
* as none h5ai folders.
|
* not to be h5ai indexed folders.
|
||||||
*/
|
*/
|
||||||
"INDEX_FILES" => array("index.html", "index.htm", "index.php")
|
"INDEX_FILES" => array("index.html", "index.htm", "index.php")
|
||||||
);
|
);
|
||||||
|
|
12
src/_h5ai/js/inc/core/mode.js
Normal file
12
src/_h5ai/js/inc/core/mode.js
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
modulejs.define('core/mode', [], function () {
|
||||||
|
|
||||||
|
var mode = {
|
||||||
|
// id: null,
|
||||||
|
// dataType: null,
|
||||||
|
// serverName: null,
|
||||||
|
// serverVersion: null
|
||||||
|
};
|
||||||
|
|
||||||
|
return mode;
|
||||||
|
});
|
|
@ -9,14 +9,7 @@ modulejs.define('core/parser', ['$'], function ($) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'none',
|
dataType: 'N/A',
|
||||||
mode: null,
|
parse: function () { return []; }
|
||||||
server: {
|
|
||||||
name: null,
|
|
||||||
version: null
|
|
||||||
},
|
|
||||||
parse: function () {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('core/refresh', ['_', 'core/ajax', 'model/entry'], function (_, ajax, Entry) {
|
modulejs.define('core/refresh', ['_', 'core/mode', 'core/ajax', 'model/entry'], function (_, mode, ajax, Entry) {
|
||||||
|
|
||||||
var parseJson = function (entry, json) {
|
var parseJson = function (entry, json) {
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@ modulejs.define('core/refresh', ['_', 'core/ajax', 'model/entry'], function (_,
|
||||||
|
|
||||||
refresh = function () {
|
refresh = function () {
|
||||||
|
|
||||||
|
if (mode.id !== 'php') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var entry = Entry.get();
|
var entry = Entry.get();
|
||||||
ajax.getEntries(entry.absHref, 1, function (json) {
|
ajax.getEntries(entry.absHref, 1, function (json) {
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,13 @@ modulejs.define('core/settings', ['config', '_'], function (config, _) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
rootAbsHref: '/',
|
rootAbsHref: '/',
|
||||||
h5aiAbsHref: '/_h5ai/',
|
h5aiAbsHref: '/_h5ai/'
|
||||||
server: 'unknown',
|
|
||||||
mode: 'unknown'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return _.extend({}, defaults, config.options);
|
var settings = _.extend({}, defaults, config.options);
|
||||||
|
|
||||||
|
settings.h5aiAbsHref = settings.h5aiAbsHref.replace(/\/*$/, '/');
|
||||||
|
settings.rootAbsHref = /^(.*\/)[^\/]+\/?$/.exec(settings.h5aiAbsHref)[1];
|
||||||
|
|
||||||
|
return settings;
|
||||||
});
|
});
|
||||||
|
|
|
@ -39,6 +39,11 @@ modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/
|
||||||
$a.find('img').attr('src', resource.image('home'));
|
$a.find('img').attr('src', resource.image('home'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entry.isRoot()) {
|
||||||
|
$html.addClass('root');
|
||||||
|
$a.find('img').attr('src', resource.image('home'));
|
||||||
|
}
|
||||||
|
|
||||||
if (entry.isCurrentFolder()) {
|
if (entry.isCurrentFolder()) {
|
||||||
$html.addClass('current');
|
$html.addClass('current');
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('ext/mode', ['_', '$', 'core/settings', 'core/parser'], function (_, $, allsettings, parser) {
|
modulejs.define('ext/mode', ['_', '$', 'core/mode', 'core/settings'], function (_, $, mode, allsettings) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -16,14 +16,14 @@ modulejs.define('ext/mode', ['_', '$', 'core/settings', 'core/parser'], function
|
||||||
|
|
||||||
var info = '';
|
var info = '';
|
||||||
|
|
||||||
if (parser.mode) {
|
if (mode.id) {
|
||||||
info += parser.mode;
|
info += mode.id;
|
||||||
}
|
}
|
||||||
if (settings.display > 0 && parser.server.name) {
|
if (settings.display > 0 && mode.serverName) {
|
||||||
info += (info ? ' on ' : '') + parser.server.name;
|
info += (info ? ' on ' : '') + mode.serverName;
|
||||||
}
|
}
|
||||||
if (settings.display > 1 && parser.server.version) {
|
if (settings.display > 1 && mode.serverVersion) {
|
||||||
info += (info ? '-' : '') + parser.server.version;
|
info += (info ? '-' : '') + mode.serverVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
|
|
|
@ -61,6 +61,12 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
||||||
$img.attr('src', resource.icon('folder-home'));
|
$img.attr('src', resource.icon('folder-home'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is it the root?
|
||||||
|
if (entry.isRoot()) {
|
||||||
|
$html.addClass('root');
|
||||||
|
$img.attr('src', resource.icon('folder-home'));
|
||||||
|
}
|
||||||
|
|
||||||
// is it the current folder?
|
// is it the current folder?
|
||||||
if (entry.isCurrentFolder()) {
|
if (entry.isCurrentFolder()) {
|
||||||
$html.addClass('current');
|
$html.addClass('current');
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('model/entry', ['_', 'core/types', 'core/ajax', 'core/event'], function (_, types, ajax, event) {
|
modulejs.define('model/entry', ['_', 'core/types', 'core/ajax', 'core/event', 'core/settings'], function (_, types, ajax, event, settings) {
|
||||||
|
|
||||||
var doc = document,
|
var doc = document,
|
||||||
domain = doc.domain,
|
domain = doc.domain,
|
||||||
|
@ -59,33 +59,36 @@ modulejs.define('model/entry', ['_', 'core/types', 'core/ajax', 'core/event'], f
|
||||||
reEndsWithSlash = /\/$/,
|
reEndsWithSlash = /\/$/,
|
||||||
|
|
||||||
|
|
||||||
|
startsWith = function (sequence, part) {
|
||||||
|
|
||||||
|
return sequence.length >= part.length && sequence.slice(0, part.length) === part;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
createLabel = function (sequence) {
|
createLabel = function (sequence) {
|
||||||
|
|
||||||
if (sequence.length > 1 && reEndsWithSlash.test(sequence)) {
|
sequence = sequence.replace(reEndsWithSlash, '');
|
||||||
sequence = sequence.slice(0, -1);
|
|
||||||
}
|
|
||||||
try { sequence = decodeURIComponent(sequence); } catch (e) {}
|
try { sequence = decodeURIComponent(sequence); } catch (e) {}
|
||||||
return sequence;
|
return sequence;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
reSplitPath = /^\/([^\/]+\/?)$/,
|
reSplitPath = /^(.*\/)([^\/]+\/?)$/,
|
||||||
reSplitPath2 = /^(\/(?:.*\/)*?([^\/]+)\/)([^\/]+\/?)$/,
|
|
||||||
|
|
||||||
splitPath = function (sequence) {
|
splitPath = function (sequence) {
|
||||||
|
|
||||||
var match;
|
|
||||||
|
|
||||||
if (sequence === '/') {
|
if (sequence === '/') {
|
||||||
return { parent: null, name: '/' };
|
return { parent: null, name: '/' };
|
||||||
}
|
}
|
||||||
match = reSplitPath2.exec(sequence);
|
|
||||||
|
var match = reSplitPath.exec(sequence);
|
||||||
if (match) {
|
if (match) {
|
||||||
return { parent: match[1], name: match[3] };
|
var split = { parent: match[1], name: match[2] };
|
||||||
|
|
||||||
|
if (split.parent && !startsWith(split.parent, settings.rootAbsHref)) {
|
||||||
|
split.parent = null;
|
||||||
}
|
}
|
||||||
match = reSplitPath.exec(sequence);
|
return split;
|
||||||
if (match) {
|
|
||||||
return { parent: '/', name: match[1] };
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -112,6 +115,10 @@ modulejs.define('model/entry', ['_', 'core/types', 'core/ajax', 'core/event'], f
|
||||||
|
|
||||||
absHref = forceEncoding(absHref || location);
|
absHref = forceEncoding(absHref || location);
|
||||||
|
|
||||||
|
if (!startsWith(absHref, settings.rootAbsHref)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var created = !cache[absHref],
|
var created = !cache[absHref],
|
||||||
changed = false;
|
changed = false;
|
||||||
|
|
||||||
|
@ -251,6 +258,16 @@ modulejs.define('model/entry', ['_', 'core/types', 'core/ajax', 'core/event'], f
|
||||||
return this.absHref === '/';
|
return this.absHref === '/';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
isRoot: function () {
|
||||||
|
|
||||||
|
return this.absHref === settings.rootAbsHref;
|
||||||
|
},
|
||||||
|
|
||||||
|
isH5ai: function () {
|
||||||
|
|
||||||
|
return this.absHref === settings.h5aiAbsHref;
|
||||||
|
},
|
||||||
|
|
||||||
isEmpty: function () {
|
isEmpty: function () {
|
||||||
|
|
||||||
return _.keys(this.content).length === 0;
|
return _.keys(this.content).length === 0;
|
||||||
|
@ -320,7 +337,7 @@ modulejs.define('model/entry', ['_', 'core/types', 'core/ajax', 'core/event'], f
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return window.ENTRY = {
|
return {
|
||||||
get: getEntry,
|
get: getEntry,
|
||||||
remove: removeEntry
|
remove: removeEntry
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
modulejs.define('parser/apache-autoindex', ['_', '$', 'core/settings', 'core/format', 'model/entry'], function (_, $, settings, format, Entry) {
|
modulejs.define('parser/apache-autoindex', ['_', '$', 'core/mode', 'core/settings', 'core/format', 'model/entry'], function (_, $, mode, settings, format, Entry) {
|
||||||
|
|
||||||
var parseTableRow = function (absHref, tr) {
|
var parseTableRow = function (absHref, tr) {
|
||||||
|
|
||||||
|
@ -35,13 +35,13 @@ modulejs.define('parser/apache-autoindex', ['_', '$', 'core/settings', 'core/for
|
||||||
return parseTable(absHref, $id.find('table'));
|
return parseTable(absHref, $id.find('table'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mode.id = 'aai';
|
||||||
|
mode.dataType = 'apache-autoindex';
|
||||||
|
mode.serverName = 'apache';
|
||||||
|
mode.serverVersion = null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: 'apache-autoindex',
|
dataType: 'apache-autoindex',
|
||||||
mode: 'aai',
|
|
||||||
server: {
|
|
||||||
name: 'apache',
|
|
||||||
version: null
|
|
||||||
},
|
|
||||||
parse: parse
|
parse: parse
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
|
|
||||||
modulejs.define('parser/generic-json', ['_', '$', 'core/settings', 'model/entry'], function (_, $, settings, Entry) {
|
modulejs.define('parser/generic-json', ['_', '$', 'core/mode', 'core/settings', 'model/entry'], function (_, $, mode, settings, Entry) {
|
||||||
|
|
||||||
var parser = {
|
var parseJson = function (absHref, json) {
|
||||||
id: 'generic-json',
|
|
||||||
mode: null,
|
|
||||||
server: {
|
|
||||||
name: null,
|
|
||||||
version: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
parseJson = function (absHref, json) {
|
mode.id = json.id;
|
||||||
|
mode.serverName = json.serverName;
|
||||||
|
mode.serverVersion = json.serverVersion;
|
||||||
|
|
||||||
if (_.has(json, 'customHeader')) {
|
if (_.has(json, 'customHeader')) {
|
||||||
settings.custom.header = json.customHeader;
|
settings.custom.header = json.customHeader;
|
||||||
|
@ -18,13 +13,6 @@ modulejs.define('parser/generic-json', ['_', '$', 'core/settings', 'model/entry'
|
||||||
if (_.has(json, 'customFooter')) {
|
if (_.has(json, 'customFooter')) {
|
||||||
settings.custom.footer = json.customFooter;
|
settings.custom.footer = json.customFooter;
|
||||||
}
|
}
|
||||||
if (_.has(json, 'mode')) {
|
|
||||||
parser.mode = json.mode;
|
|
||||||
}
|
|
||||||
if (_.has(json, 'server')) {
|
|
||||||
parser.server = json.server;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _.map(json.entries, function (jsonEntry) {
|
return _.map(json.entries, function (jsonEntry) {
|
||||||
|
|
||||||
return Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
|
return Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
|
||||||
|
@ -49,7 +37,10 @@ modulejs.define('parser/generic-json', ['_', '$', 'core/settings', 'model/entry'
|
||||||
return parseJsonStr(absHref, $id.text());
|
return parseJsonStr(absHref, $id.text());
|
||||||
};
|
};
|
||||||
|
|
||||||
parser.parse = parse;
|
mode.dataType = 'generic-json';
|
||||||
|
|
||||||
return parser;
|
return {
|
||||||
|
dataType: 'generic-json',
|
||||||
|
parse: parse
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,6 +8,12 @@ class Entry {
|
||||||
private static $cache = array();
|
private static $cache = array();
|
||||||
|
|
||||||
|
|
||||||
|
private static function startsWith($sequence, $part) {
|
||||||
|
|
||||||
|
return (substr($sequence, 0, strlen($part)) === $part);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function get_cache() {
|
public static function get_cache() {
|
||||||
|
|
||||||
return Entry::$cache;
|
return Entry::$cache;
|
||||||
|
@ -16,6 +22,11 @@ class Entry {
|
||||||
|
|
||||||
public static function get($h5ai, $absPath, $absHref) {
|
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)) {
|
if (array_key_exists($absHref, Entry::$cache)) {
|
||||||
return Entry::$cache[$absHref];
|
return Entry::$cache[$absHref];
|
||||||
}
|
}
|
||||||
|
@ -63,8 +74,9 @@ class Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parent = null;
|
$this->parent = null;
|
||||||
if ($this->absHref !== "/") {
|
$parentAbsHref = H5ai::normalize_path(dirname($this->absHref), true);
|
||||||
$this->parent = Entry::get($this->h5ai, H5ai::normalize_path(dirname($this->absPath)), 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;
|
$this->isContentFetched = false;
|
||||||
|
|
|
@ -56,9 +56,9 @@ class H5ai {
|
||||||
$this->requested_from = H5ai::normalize_path($requested_from);
|
$this->requested_from = H5ai::normalize_path($requested_from);
|
||||||
|
|
||||||
$this->h5aiAbsPath = H5ai::normalize_path(H5AI_ABS_PATH);
|
$this->h5aiAbsPath = H5ai::normalize_path(H5AI_ABS_PATH);
|
||||||
|
$this->rootAbsPath = H5ai::normalize_path(dirname(H5AI_ABS_PATH));
|
||||||
|
|
||||||
global $H5AI_CONFIG;
|
global $H5AI_CONFIG;
|
||||||
$this->rootAbsPath = H5ai::normalize_path($H5AI_CONFIG["ROOT_ABS_PATH"]);
|
|
||||||
$this->ignore_names = $H5AI_CONFIG["IGNORE"];
|
$this->ignore_names = $H5AI_CONFIG["IGNORE"];
|
||||||
$this->ignore_patterns = $H5AI_CONFIG["IGNORE_PATTERNS"];
|
$this->ignore_patterns = $H5AI_CONFIG["IGNORE_PATTERNS"];
|
||||||
$this->index_files = $H5AI_CONFIG["INDEX_FILES"];
|
$this->index_files = $H5AI_CONFIG["INDEX_FILES"];
|
||||||
|
@ -66,8 +66,8 @@ class H5ai {
|
||||||
$this->config = H5ai::load_config($this->h5aiAbsPath . "/config.js");
|
$this->config = H5ai::load_config($this->h5aiAbsPath . "/config.js");
|
||||||
$this->options = $this->config["options"];
|
$this->options = $this->config["options"];
|
||||||
|
|
||||||
$this->rootAbsHref = H5ai::normalize_path($this->options["rootAbsHref"], true);
|
|
||||||
$this->h5aiAbsHref = H5ai::normalize_path($this->options["h5aiAbsHref"], 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->absHref = H5ai::normalize_path(preg_replace('/[^\\/]*$/', '', getenv("REQUEST_URI")), true);
|
||||||
$this->absPath = $this->getAbsPath($this->absHref);
|
$this->absPath = $this->getAbsPath($this->absHref);
|
||||||
|
@ -275,14 +275,12 @@ class H5ai {
|
||||||
$footer = $this->fileExists($footer ? $this->absPath . "/" . $footer : null) ? $footer : null;
|
$footer = $this->fileExists($footer ? $this->absPath . "/" . $footer : null) ? $footer : null;
|
||||||
|
|
||||||
$json = array(
|
$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,
|
"customHeader" => $header,
|
||||||
"customFooter" => $footer,
|
"customFooter" => $footer,
|
||||||
"mode" => $this->requested_from === $this->h5aiAbsPath . "/php/h5ai-index.php" ? "php" : "idx.php",
|
"entries" => $entries
|
||||||
"server" => array(
|
|
||||||
"name" => strtolower(preg_replace("/\\/.*$/", "", getenv("SERVER_SOFTWARE"))),
|
|
||||||
"version" => strtolower(preg_replace("/^.*\\//", "", preg_replace("/\\s.*$/", "", getenv("SERVER_SOFTWARE"))))
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return json_encode($json) . "\n";
|
return json_encode($json) . "\n";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue