page: replace links to current page in menu include
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 12 Sep 2017 00:19:31 +0000 (02:19 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 18 Sep 2017 18:21:28 +0000 (20:21 +0200)
Replaces similar client-side javascript on Excelsior for direct/static
results.

head.inc.php

index 5e19024665e5806c53638657671142020309d1d2..2522ad737ab2ff8794efc2f222476853a3ed9451 100644 (file)
@@ -2,7 +2,16 @@
 include_once 'head.inc.html';
 
 print "<header>\n";
+
+ob_start();
 include 'menu.html';
+$nav = ob_get_clean();
+$nav = preg_replace_callback('{<a href="([^"]+)">(.*?)</a>}', function ($m) {
+       $request = $_SERVER['REQUEST_URI'];
+       $html = $request == $m[1] ? $m[2] : $m[0]; # text or full link
+       return $m[1] == substr($request, 0, strlen($m[1])) ? "<b>$html</b>" : $html;
+}, $nav);
+print $nav;
 print "</header>\n\n";
 
 print '<div class="article">'."\n\n";