From 25c93f376c0cce76204600a654a504929b14602d Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Sun, 18 Nov 2018 19:40:35 -0500 Subject: model/Navigator: Refactor navigator class --- model/Navigator.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'model') diff --git a/model/Navigator.php b/model/Navigator.php index a8150e9..d146c13 100644 --- a/model/Navigator.php +++ b/model/Navigator.php @@ -29,7 +29,8 @@ function navBar() } $navbar = [ - $location => ['link' => $uri], //Hidden link shown in mobile responsive mode. + //Hidden link shown in mobile responsive mode. + $location => ['link' => $uri], 'Home' => ['link' => '/'], 'Posts' => ['link' => '/posts/'], 'Feedback' => ['link' => '/feedback/'], @@ -39,13 +40,6 @@ function navBar() foreach ($navbar as $title => $route) { $append =''; - // Bad css coding results in this... - // Due to the strpos check method for which page is active, - // "Home" is always active because "/" is always in - // the request uri. Run a seperate check for the home - // page and continue with the looped check. Will refactor - // to make the exception the rule. - if ($title === 'Home') { if ($route['link'] === $_SERVER['REQUEST_URI']) { echo 'Home'; @@ -78,9 +72,24 @@ function navBarPost() foreach ($navbar as $title => $route) { $append =''; - if ($route['uri'] === $_SERVER['REQUEST_URI']) { - $append = 'class="active" '; + + if ($_SERVER['REQUEST_URI'] === '/' + && $_SERVER['REQUEST_URI'] === $route['uri'] + ) { + $append = 'active'; + } + + if (!empty(trim($route['uri'], '/')) + && strpos( + trim($_SERVER['REQUEST_URI'], '/'), + trim($route['uri'], '/') + ) !== false + ) { + $append = 'active'; }; - echo str_repeat("\t", 4) . '' . $title . '' . "\n"; + + echo str_repeat("\t", 4) . '' . $title . '' . "\n"; } } -- cgit v1.2.3