\s*<\/script>/i';
- $outputString = preg_replace_callback($pattern, function($match) {
+ return preg_replace_callback($pattern, function($match) {
$src = $match[1];
$jsContent = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/' . $src);
@@ -43,11 +43,10 @@ function inlineScriptFromSrc($inputString) {
$jsContent = minifyJs($jsContent);
return "";
}, $inputString);
-
- return $outputString;
}
-function minifyCss($css) {
+function minifyCss($css): string
+{
// Remove comments
$css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css);
@@ -66,7 +65,8 @@ function minifyCss($css) {
return trim($css);
}
-function minifyJs($js) {
+function minifyJs($js): string
+{
// Remove newlines and tabs
$js = str_replace("\t", '', $js);
diff --git a/lib/navigation.php b/lib/navigation.php
index 82b0ca6..19efeb8 100644
--- a/lib/navigation.php
+++ b/lib/navigation.php
@@ -7,11 +7,11 @@ function getDynamicPermission($file): int {
$permission_level = $page_tmp["parameters"]["minimal_permission_level"];
if (!is_numeric($permission_level) || $permission_level <= 0) {
- $permission_level = $routerConfig["default_page_permission_level"];
+ $permission_level = $routerConfig["page"]["default_permissions"];
}
}
catch (Exception){
- $permission_level = $routerConfig["default_page_permission_level"];
+ $permission_level = $routerConfig["page"]["default_permissions"];
} finally {
return $permission_level;
}
@@ -32,16 +32,11 @@ function generateNavigation(): string
$site_name = str_replace("_", " ", $site_dir);
- $site_subdomain = $site_dir . ".";
- if ($site_name == $routerConfig["default_site"]) {
- $site_subdomain = "";
- }
-
$site_name = ucfirst($site_name);
- $site_location = $routerConfig["protocol"] . $site_subdomain . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $routerConfig["default_page"];
+ $site_location = "/" . $site_dir . "/" . $routerConfig["default_page"];
- if ($routerRequest["subdomain"] == $site_dir) {
+ if ($routerRequest["site_name"] == $site_dir) {
//this is the current page
$site_class = "class=\"navsite_link active\"";
}
@@ -49,17 +44,17 @@ function generateNavigation(): string
$site_class = "class=\"navsite_link\"";
}
- $navpages = "";
+ $navigation_pages = "";
foreach ($pages_dir as $page_file) {
$page_file_tmp = explode(".", $page_file);
$page_basename = $page_file_tmp[0];
$page_class = "class=\"navpage_link\"";
- if ($routerRequest["subdomain"] == $site_dir && $routerRequest["page_name"] == $page_basename) {
+ if ($routerRequest["site_name"] == $site_dir && $routerRequest["page_name"] == $page_basename) {
$page_class = "class=\"navpage_link active\"";
}
- $page_location = $routerConfig["protocol"] . $site_subdomain . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $page_basename;
+ $page_location = "/" . $site_dir . "/" . $page_basename;
$page_name = str_replace("_", " ", $page_basename);
$page_name = explode(".", $page_name)[0];
@@ -73,23 +68,26 @@ function generateNavigation(): string
$page_required_permission = intval($pageMetadata["parameters"]["minimal_permission_level"]);
}
else{
- $page_required_permission = $routerConfig["default_page_permission_level"];
+ $page_required_permission = $routerConfig["page"]["default_permissions"];
}
}
elseif($page_file_tmp[1] == "php"){
$page_required_permission = getDynamicPermission($page_file_path);
}
else{
- $page_required_permission = $routerConfig["default_page_permission_level"];
+ $page_required_permission = $routerConfig["page"]["default_permissions"];
}
+
if($page_required_permission <= $_SESSION["privilege_level"]) {
- $navpages .= "$page_name";
+ $navpage_attributes = "data-site='$site_dir' data-page='$page_basename'";
+ $navigation_pages .= "$page_name";
}
}
- if(!empty($navpages)){
+ if(!empty($navigation_pages)){
$default_page = $routerConfig["default_page"];
- $nav_out .= "$site_name";
+ $navsite_attributes = "data-page='$default_page' data-site='$site_dir'";
+ $nav_out .= "$site_name";
}
}
diff --git a/lib/page.php b/lib/page.php
index 6411b75..77c3a75 100644
--- a/lib/page.php
+++ b/lib/page.php
@@ -1,5 +1,4 @@
$routerConfig["default_page"],
]);
- $navpages = generateNavigation();
+ $navigation = generateNavigation();
$out = $skeleton;
- $out = str_replace("__TEMPLATE__NAV__", $navpages, $out);
+ $out = str_replace("__TEMPLATE__NAV__", $navigation, $out);
$out = str_replace("__TEMPLATE__PAGE__", $page, $out);
- $out = str_replace("__TEMPLATE__DYNASCRIPT__", $dynamic_script, $out);
- $out = str_replace("__TEMPLATE__DYNASTYLE__", $dynamic_style, $out);
- $out = inlineLocalStylesFromHref($out);
- $out = inlineScriptFromSrc($out);
+ $out = str_replace("__TEMPLATE__DYNAMIC__SCRIPT__", $dynamic_script, $out);
+ $out = str_replace("__TEMPLATE__DYNAMIC__STYLE__", $dynamic_style, $out);
+ if($routerConfig["inlining"]) {
+ require_once "lib/inliner.php";
+ $out = inlineLocalStylesFromHref($out);
+ $out = inlineScriptFromSrc($out);
+ }
return str_replace("__TEMPLATE_PAGE_TITLE__", $page_title, $out);
}
function getPageEndpoint($page_name, $site_name) :array
{
- global $routerRequest, $routerConfig;
- if(!empty($site_name)){
- $subdomain = "$site_name.";
- }
- else{
- $subdomain = "";
- }
- $page_location = $routerConfig["protocol"] . $subdomain . $routerRequest["domain"] . "." . $routerRequest["tld"] . "/" . $page_name;
+ $page_location = "/" . $site_name . "/" . $page_name;
$page_tmp = renderPage($page_name, $site_name);
return [
"Status" => "Success",
diff --git a/lib/router.php b/lib/router.php
index 2ad4038..0b704be 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -1,68 +1,36 @@
+