...
 
Commits (13)
# Ignore processed XJS files
*.xjs.ssjs
# Ignore non-example pages
pages/*
!pages/.examples
# Ignore non-example sidebar modules
sidebar/*
!sidebar/.examples
# Ignore non-example components
components/*
!components/.examples
mods/*
root/css/custom.css
root/logo.gif
......
......@@ -11,19 +11,19 @@
<?xjs } ?>
<?xjs
function menu(obj, path) {
Object.keys(obj).forEach(function (e) {
if (obj[e].type == 'list') {
subMenu(obj[e], e, (path || '') + e + '/');
function menu(arr, path) {
arr.forEach(function (e) {
if (e.type == 'list') {
subMenu(e, e.title, (path || '') + e.title + '/');
} else {
?>
<li>
<?xjs if (obj[e].type == 'link') { ?>
<a class="dropdown-item" href="./?page=<?xjs write(obj[e].page); ?>" target="_blank">
<?xjs if (e.type == 'link') { ?>
<a class="dropdown-item" href="./?page=<?xjs write(e.page); ?>" target="_blank">
<?xjs } else { ?>
<a class="dropdown-item" href="./?page=<?xjs write((path || '') + obj[e].page); ?>">
<a class="dropdown-item" href="./?page=<?xjs write((path || '') + e.page); ?>">
<?xjs } ?>
<? write(e); ?>
<? write(e.title); ?>
</a>
</li>
<?xjs
......
require('sbbsdefs.js', 'SYS_CLOSED');
load('array.js');
// Paths
settings.web_directory = fullpath(
......@@ -19,6 +20,9 @@ settings.web_lib = backslash(settings.web_directory + 'lib/');
settings.web_components = backslash(settings.web_directory + 'components/');
settings.web_pages = backslash(fullpath(settings.web_root + '../pages'));
settings.web_sidebar = backslash(fullpath(settings.web_root + '../sidebar'));
settings.web_mods = backslash(fullpath(settings.web_directory + 'mods/'));
settings.web_mods_pages = backslash(fullpath(settings.web_mods + 'pages/'));
settings.web_mods_sidebar = backslash(fullpath(settings.web_mods + 'sidebar/'));
var defaults = {
guest : {
......
......@@ -37,7 +37,9 @@ function getCtrlLine(file) {
title: file_getname(file)
};
if (fullpath(file).indexOf(fullpath(settings.web_pages)) != 0) return ret;
const _file = fullpath(file);
if (_file.indexOf(settings.web_pages) != 0 && _file.indexOf(settings.web_mods_pages) != 0) return ret;
var ctrl = '';
const f = new File(file);
......@@ -88,57 +90,118 @@ function getCtrlLine(file) {
}
function getPageList(dir) {
function _getPageList(dir) {
dir = backslash(fullpath(dir));
if (dir.indexOf(settings.web_pages) !== 0) return {};
if (!file_isdir(dir)) return [];
const webctrl = getWebCtrl(dir);
const sep = system.platform.search(/^win/i) == 0 ? '\\' : '/';
const pages = directory(dir + '*').reduce(function (a, c) {
if (file_isdir(c)) {
const list = getPageList(c);
if (file_isdir(c)) {
const list = _getPageList(c);
if (Object.keys(list).length) {
a[c.replace(/\\*\/*$/, '').split(sep).slice(-1)] = { type: 'list', list: list };
const t = c.replace(/\\*\/*$/, '').split(sep).slice(-1)[0];
a.push({
file: t,
name: pageName(t),
type: 'list',
title: t,
list: list
});
}
return a;
}
const ext = file_getext(c).toUpperCase();
if (c.search(/(\.xjs\.ssjs|webctrl\.ini)$/i) < 0
&& ['.HTML', '.SSJS', '.XJS', '.TXT', '.LINK'].indexOf(ext) > -1
) {
const fn = file_getname(c);
if (webctrl && !webCtrlTest(webctrl, fn)) return a;
if (ext == '.LINK') {
const f = new File(c);
if (!f.open('r')) return a;
const l = f.readln().split(',');
f.close();
if (l.length < 2) return a;
a[l[1]] = { page: l[0], type: 'link' };
} else {
const ctrl = getCtrlLine(c);
if (!ctrl.options.hidden) {
a[ctrl.title] = { page: file_getname(c), type: 'page' };
}
}
}
const ext = file_getext(c).toUpperCase();
if (c.search(/(\.xjs\.ssjs|webctrl\.ini)$/i) >= 0) return a;
if (['.HTML', '.SSJS', '.XJS', '.TXT', '.LINK'].indexOf(ext) < 0) return a;
const fn = file_getname(c);
if (webctrl && !webCtrlTest(webctrl, fn)) return a;
if (ext == '.LINK') {
const f = new File(c);
if (!f.open('r')) return a;
const l = f.readln().split(',');
f.close();
if (l.length < 2) return a;
a.push({
file: fn,
name: pageName(c),
title: l[1],
page: l[0],
type: 'link'
});
} else {
const ctrl = getCtrlLine(c);
if (!ctrl.options.hidden) {
a.push({
file: fn,
name: pageName(fn),
page: fn,
title: ctrl.title,
type: 'page',
});
}
}
return a;
}, {});
}, []);
return pages;
}
function pageName(p) {
return p.replace(/^\d*-/, '');
}
function mergePageLists(stock, mods) {
return mods.reduce(function (a, c) {
const idx = a.findIndex(function (e) {
return e.name == c.name;
});
if (idx < 0) {
a.push(c);
} else if (a[idx].type != c.type) {
a[idx] = c;
} else if (a[idx].type == 'page' || a[idx].type == 'link') {
a[idx] = c;
} else if (a[idx].type == 'list') {
a[idx].list = mergePageLists(a[idx].list, c.list);
}
return a;
}, stock).sort(function (a, b) {
if (a.file < b.file) return -1;
if (a.file > b.file) return 1;
return 0;
});
}
function getPageList() {
var stock = _getPageList(settings.web_pages);
var mods = _getPageList(settings.web_mods_pages);
return mergePageLists(stock, mods);
}
function getPagePath(page) {
var ret = null;
if (file_exists(settings.web_mods_pages + page)) {
ret = fullpath(settings.web_mods_pages + page);
if (ret.indexOf(settings.web_mods_pages) != 0) ret = null;
} else if (file_exists(settings.web_pages + page)) {
ret = fullpath(settings.web_pages + page);
if (ret.indexOf(settings.web_pages) != 0) ret = null;
}
return ret;
}
function getPage(page) {
var ret = '';
var p = settings.web_pages + page;
if (!file_exists(p)) return ret;
var p = getPagePath(page);
if (p === null) return ret;
var ext = file_getext(p).toUpperCase();
......@@ -186,7 +249,8 @@ function getPage(page) {
}
function writePage(page) {
var ini = getWebCtrl(settings.web_pages + '/' + page.replace(file_getname(page), ''));
const pp = getPagePath(page);
var ini = getWebCtrl(pp.replace(file_getname(page), ''));
if ((typeof ini === "boolean" && !ini) || webCtrlTest(ini, page)) {
write(getPage(page));
}
......
......@@ -6,12 +6,43 @@ function getFileContents(file) {
return ret;
}
function getSidebarModules() {
return directory(settings.web_sidebar + '*').filter(function (e) {
function moduleName(m) {
return file_getname(m).replace(/^\d*-/, '');
}
function mergeModuleLists(stock, mods) {
return mods.reduce(function (a, c) {
const idx = a.findIndex(function (e) {
return moduleName(e) == moduleName(c);
});
if (idx < 0) {
a.push(c);
} else {
a[idx] = c;
}
return a;
}, stock).sort(function (a, b) {
const fna = file_getname(a);
const fnb = file_getname(b);
if (fna < fnb) return -1;
if (fna > fnb) return 1;
return 0;
});
}
function _getSidebarModules(dir) {
if (!file_isdir(dir)) return [];
return directory(dir + '*').filter(function (e) {
return (!file_isdir(e));
});
}
function getSidebarModules() {
const stock = _getSidebarModules(settings.web_sidebar);
const mods = _getSidebarModules(settings.web_mods_sidebar);
return mergeModuleLists(stock, mods);
}
function getSidebarModule(module) {
var ret = '';
......
......@@ -12,11 +12,9 @@
http_reply.header['Location'] = page;
exit();
}
if (!file_exists(fullpath(settings.web_pages + page)) || fullpath(settings.web_pages + page).indexOf(fullpath(settings.web_pages)) !== 0) {
page = '000-home.xjs';
}
var page_ctrl = getCtrlLine(settings.web_pages + page);
var pagePath = getPagePath(page);
if (pagePath == null) page = '000-home.xjs';
var page_ctrl = getCtrlLine(pagePath);
?>
<?xjs
......@@ -28,6 +26,23 @@
}
?>
<?xjs
function loadComponent(fn) {
return (function () {
const cdir = backslash(fullpath(settings.web_mods + 'components'));
if (file_isdir(cdir) && file_exists(cdir + fn)) {
load(xjs_compile(cdir + fn));
return true;
}
if (file_exists(settings.web_components + fn)) {
load(xjs_compile(settings.web_components + fn));
return true;
}
return false;
})();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
......@@ -51,19 +66,9 @@
<script src="./js/common.js"></script>
<?xjs
(function () {
load(xjs_compile(settings.web_components + 'modal.xjs'));
})();
if (file_exists(settings.web_components + 'header.xjs')) {
(function () {
load(xjs_compile(settings.web_components + 'header.xjs'));
})();
}
(function () {
load(xjs_compile(settings.web_components + 'navbar.xjs'));
})();
loadComponent('modal.xjs');
loadComponent('header.xjs');
loadComponent('navbar.xjs');
?>
<div class="container<?xjs if (settings.layout_full_width) write('-fluid'); ?>">
......@@ -81,17 +86,9 @@
</div>
<hr>
<footer>
<?xjs
if (file_exists(settings.web_components + 'footer.xjs')) {
(function () {
load(xjs_compile(settings.web_components + 'footer.xjs'));
})();
} else {
?>
<p>&copy; <?xjs write(system.name + ", " + strftime("%Y")); ?></p>
<?xjs
}
?>
<?xjs if (!loadComponent('footer.xjs')) { ?>
<p>&copy; <?xjs write(system.name + ", " + strftime("%Y")); ?></p>
<?xjs } ?>
</footer>
</div>
......