Skip to content
Snippets Groups Projects
Commit 13ebab63 authored by echicken's avatar echicken :chicken:
Browse files

Merge branch 'web-mods'

parents f5c5187d 070248ac
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #256 passed
Showing
with 169 additions and 83 deletions
# Ignore processed XJS files # Ignore processed XJS files
*.xjs.ssjs *.xjs.ssjs
# Ignore non-example pages mods/*
pages/*
!pages/.examples
# Ignore non-example sidebar modules
sidebar/*
!sidebar/.examples
# Ignore non-example components
components/*
!components/.examples
root/css/custom.css root/css/custom.css
root/logo.gif root/logo.gif
......
File moved
File moved
File moved
...@@ -11,19 +11,19 @@ ...@@ -11,19 +11,19 @@
<?xjs } ?> <?xjs } ?>
<?xjs <?xjs
function menu(obj, path) { function menu(arr, path) {
Object.keys(obj).forEach(function (e) { arr.forEach(function (e) {
if (obj[e].type == 'list') { if (e.type == 'list') {
subMenu(obj[e], e, (path || '') + e + '/'); subMenu(e, e.title, (path || '') + e.title + '/');
} else { } else {
?> ?>
<li> <li>
<?xjs if (obj[e].type == 'link') { ?> <?xjs if (e.type == 'link') { ?>
<a class="dropdown-item" href="./?page=<?xjs write(obj[e].page); ?>" target="_blank"> <a class="dropdown-item" href="./?page=<?xjs write(e.page); ?>" target="_blank">
<?xjs } else { ?> <?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 } ?> <?xjs } ?>
<? write(e); ?> <? write(e.title); ?>
</a> </a>
</li> </li>
<?xjs <?xjs
......
require('sbbsdefs.js', 'SYS_CLOSED'); require('sbbsdefs.js', 'SYS_CLOSED');
load('array.js');
// Paths // Paths
settings.web_directory = fullpath( settings.web_directory = fullpath(
...@@ -19,6 +20,9 @@ settings.web_lib = backslash(settings.web_directory + 'lib/'); ...@@ -19,6 +20,9 @@ settings.web_lib = backslash(settings.web_directory + 'lib/');
settings.web_components = backslash(settings.web_directory + 'components/'); settings.web_components = backslash(settings.web_directory + 'components/');
settings.web_pages = backslash(fullpath(settings.web_root + '../pages')); settings.web_pages = backslash(fullpath(settings.web_root + '../pages'));
settings.web_sidebar = backslash(fullpath(settings.web_root + '../sidebar')); 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 = { var defaults = {
guest : { guest : {
......
...@@ -37,7 +37,9 @@ function getCtrlLine(file) { ...@@ -37,7 +37,9 @@ function getCtrlLine(file) {
title: file_getname(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 = ''; var ctrl = '';
const f = new File(file); const f = new File(file);
...@@ -88,27 +90,34 @@ function getCtrlLine(file) { ...@@ -88,27 +90,34 @@ function getCtrlLine(file) {
} }
function getPageList(dir) { function _getPageList(dir) {
dir = backslash(fullpath(dir)); if (!file_isdir(dir)) return [];
if (dir.indexOf(settings.web_pages) !== 0) return {};
const webctrl = getWebCtrl(dir); const webctrl = getWebCtrl(dir);
const sep = system.platform.search(/^win/i) == 0 ? '\\' : '/'; const sep = system.platform.search(/^win/i) == 0 ? '\\' : '/';
const pages = directory(dir + '*').reduce(function (a, c) { const pages = directory(dir + '*').reduce(function (a, c) {
if (file_isdir(c)) { if (file_isdir(c)) {
const list = getPageList(c); const list = _getPageList(c);
if (Object.keys(list).length) { 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; return a;
} }
const ext = file_getext(c).toUpperCase(); const ext = file_getext(c).toUpperCase();
if (c.search(/(\.xjs\.ssjs|webctrl\.ini)$/i) < 0 if (c.search(/(\.xjs\.ssjs|webctrl\.ini)$/i) >= 0) return a;
&& ['.HTML', '.SSJS', '.XJS', '.TXT', '.LINK'].indexOf(ext) > -1 if (['.HTML', '.SSJS', '.XJS', '.TXT', '.LINK'].indexOf(ext) < 0) return a;
) {
const fn = file_getname(c); const fn = file_getname(c);
if (webctrl && !webCtrlTest(webctrl, fn)) return a; if (webctrl && !webCtrlTest(webctrl, fn)) return a;
if (ext == '.LINK') { if (ext == '.LINK') {
...@@ -117,28 +126,82 @@ function getPageList(dir) { ...@@ -117,28 +126,82 @@ function getPageList(dir) {
const l = f.readln().split(','); const l = f.readln().split(',');
f.close(); f.close();
if (l.length < 2) return a; if (l.length < 2) return a;
a[l[1]] = { page: l[0], type: 'link' }; a.push({
file: fn,
name: pageName(c),
title: l[1],
page: l[0],
type: 'link'
});
} else { } else {
const ctrl = getCtrlLine(c); const ctrl = getCtrlLine(c);
if (!ctrl.options.hidden) { if (!ctrl.options.hidden) {
a[ctrl.title] = { page: file_getname(c), type: 'page' }; a.push({
} file: fn,
name: pageName(fn),
page: fn,
title: ctrl.title,
type: 'page',
});
} }
} }
return a; return a;
}, {}); }, []);
return pages; 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) { function getPage(page) {
var ret = ''; var ret = '';
var p = settings.web_pages + page; var p = getPagePath(page);
if (p === null) return ret;
if (!file_exists(p)) return ret;
var ext = file_getext(p).toUpperCase(); var ext = file_getext(p).toUpperCase();
...@@ -186,7 +249,8 @@ function getPage(page) { ...@@ -186,7 +249,8 @@ function getPage(page) {
} }
function writePage(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)) { if ((typeof ini === "boolean" && !ini) || webCtrlTest(ini, page)) {
write(getPage(page)); write(getPage(page));
} }
......
...@@ -6,12 +6,43 @@ function getFileContents(file) { ...@@ -6,12 +6,43 @@ function getFileContents(file) {
return ret; return ret;
} }
function getSidebarModules() { function moduleName(m) {
return directory(settings.web_sidebar + '*').filter(function (e) { 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)); 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) { function getSidebarModule(module) {
var ret = ''; var ret = '';
......
File moved
File moved
File moved
File moved
File moved
File moved
File moved
...@@ -12,11 +12,9 @@ ...@@ -12,11 +12,9 @@
http_reply.header['Location'] = page; http_reply.header['Location'] = page;
exit(); exit();
} }
var pagePath = getPagePath(page);
if (!file_exists(fullpath(settings.web_pages + page)) || fullpath(settings.web_pages + page).indexOf(fullpath(settings.web_pages)) !== 0) { if (pagePath == null) page = '000-home.xjs';
page = '000-home.xjs'; var page_ctrl = getCtrlLine(pagePath);
}
var page_ctrl = getCtrlLine(settings.web_pages + page);
?> ?>
<?xjs <?xjs
...@@ -28,6 +26,23 @@ ...@@ -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> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
...@@ -51,19 +66,9 @@ ...@@ -51,19 +66,9 @@
<script src="./js/common.js"></script> <script src="./js/common.js"></script>
<?xjs <?xjs
(function () { loadComponent('modal.xjs');
load(xjs_compile(settings.web_components + 'modal.xjs')); loadComponent('header.xjs');
})(); loadComponent('navbar.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'));
})();
?> ?>
<div class="container<?xjs if (settings.layout_full_width) write('-fluid'); ?>"> <div class="container<?xjs if (settings.layout_full_width) write('-fluid'); ?>">
...@@ -81,17 +86,9 @@ ...@@ -81,17 +86,9 @@
</div> </div>
<hr> <hr>
<footer> <footer>
<?xjs <?xjs if (!loadComponent('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> <p>&copy; <?xjs write(system.name + ", " + strftime("%Y")); ?></p>
<?xjs <?xjs } ?>
}
?>
</footer> </footer>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment