+
+$active_page = NULL;
+
+foreach ($pages as $name => $page)
+{
+ $script = $_SERVER['SCRIPT_FILENAME'];
+ $tok = split($script, "/");
+ if (strlen($page) == 0) {
+ $active_page = "";
+ }
+ else if (str_ends_with($script, BASE_URL . "index.php") && BASE_URL != "/" && !strlen($tok[0]))
+ {
+ $active_page = $tok[0];
+ }
+ else if (!str_ends_with($page, ".php"))
+ {
+ $script2 = rtrim($script, "/index.php");
+ if (str_ends_with($script2, $page))
+ $active_page = $page;
+ }
+ else if (str_ends_with($script, $page))
+ {
+ $active_page = $page;
+ } elseif (!$active_page)
+ $active_page = false;
+}