summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Kohl <gitlab@jonaskohl.de>2024-07-21 13:23:33 +0200
committerJonas Kohl <gitlab@jonaskohl.de>2024-07-21 13:23:33 +0200
commitd79fb0f0ce4744974d45d7d4e80c3af8c2cca717 (patch)
treebf7a46b251b3047ef5704613fa93c3912427497f
parentd3db01ccb363db3f48695abd7dd9eef404ebc670 (diff)
Switch to more flexible params system and add active navlink state
-rw-r--r--common.php22
-rw-r--r--src/pages/about.php3
-rw-r--r--src/pages/index.php3
-rw-r--r--src/pages/not_found.php2
-rw-r--r--src/static/nava.gifbin0 -> 1778 bytes
-rw-r--r--src/static/style.css8
-rw-r--r--src/template.php13
7 files changed, 33 insertions, 18 deletions
diff --git a/common.php b/common.php
index c505660..cba823a 100644
--- a/common.php
+++ b/common.php
@@ -2,19 +2,19 @@
define("SRCDIR", realpath(__DIR__ . "/src/"));
-function hzcom_expand(string $__page): string {
- $title = "";
- $__page = preg_replace_callback(
- ';<title>(.*?)</title>;i',
- function(array $matches) use(&$title): string {
- $title = $matches[1];
+function hzcom_expand(string $pageContents): string {
+ $params = [];
+ $page = SRCDIR . "/pages/" . bin2hex(random_bytes(8)) . ".tmp";
+ file_put_contents($page, preg_replace_callback(
+ "/<param:(?'paramName'[a-z][a-z0-9_-]*?)\s*>" .
+ "(?'paramValue'.*?)<\/param:\\1\s*>/s",
+ function(array $matches) use (&$params) {
+ $params[$matches['paramName']] = $matches['paramValue'];
return "";
},
- $__page
- );
- $page = SRCDIR . "/pages/" . bin2hex(random_bytes(8)) . ".tmp";
- file_put_contents($page, $__page);
- unset($__page);
+ $pageContents
+ ));
+ unset($pageContents);
ob_start();
include SRCDIR . "/template.php";
diff --git a/src/pages/about.php b/src/pages/about.php
index 99d8e25..9e7b31b 100644
--- a/src/pages/about.php
+++ b/src/pages/about.php
@@ -9,7 +9,8 @@ $age = date_diff(
?>
-<title>About me</title>
+<param:title>About me</param:title>
+<param:active-link>about</param:active-link>
<h1>About me</h1>
diff --git a/src/pages/index.php b/src/pages/index.php
index 3b15088..cb9b417 100644
--- a/src/pages/index.php
+++ b/src/pages/index.php
@@ -1,3 +1,4 @@
-<title>hozyro's site</title>
+<param:title>hozyro's site</param:title>
+<param:active-link>home</param:active-link>
<?php include SRCDIR . "/includes/under-construction.php"; ?>
diff --git a/src/pages/not_found.php b/src/pages/not_found.php
index b71d6c3..abe4c3f 100644
--- a/src/pages/not_found.php
+++ b/src/pages/not_found.php
@@ -1,2 +1,2 @@
-<title>Not found</title>
+<param:title>Not found</param:title>
<p>The requested page could not be found.</p>
diff --git a/src/static/nava.gif b/src/static/nava.gif
new file mode 100644
index 0000000..005f34b
--- /dev/null
+++ b/src/static/nava.gif
Binary files differ
diff --git a/src/static/style.css b/src/static/style.css
index 0b94ca4..1c1cd5e 100644
--- a/src/static/style.css
+++ b/src/static/style.css
@@ -53,6 +53,14 @@ a {
color: #05456a;
background: url("navh.gif");
}
+.navCell.active {
+ border-left-color: #000;
+ border-right-color: #7d9cb0;
+}
+.navCell.active a {
+ color: #fffca2;
+ background: url("nava.gif");
+}
#mainCell {
border: 1px solid #000;
border-top: none;
diff --git a/src/template.php b/src/template.php
index 6e2ad0c..ca781b9 100644
--- a/src/template.php
+++ b/src/template.php
@@ -1,9 +1,14 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+<?php
+
+$nav = fn(string $ln) =>
+ (($params["active-link"] ?? null) === $ln) ? ' active' : '';
+
+?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
- <title><?= htmlentities($title) ?></title>
+ <title><?= htmlentities($params["title"] ?? "") ?></title>
<link rel="stylesheet" href="/static/style.css" type="text/css" />
</head>
<body>
@@ -27,7 +32,7 @@
<table id="navLayout" cellspacing="0">
<tbody>
<tr>
- <td class="navCell" style="border-left:0">
+ <td class="navCell<?= $nav("home") ?>" style="border-left:0">
<a href="/"><img
class="navIcon"
alt=""
@@ -36,7 +41,7 @@
src="/static/icons/home.gif"
/>&nbsp;Home page</a>
</td>
- <td class="navCell">
+ <td class="navCell<?= $nav("about") ?>">
<a href="/about"><img
class="navIcon"
alt=""