aboutsummaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2019-01-21 07:01:31 -0500
committerThedro Neely <thedroneely@gmail.com>2019-01-21 07:01:31 -0500
commit4526fa0316d8a6d8e616b82de2f39f39a89851ef (patch)
treeffc29cd113baf31d986f7f83e70a97e292574f0b /model
parent9d616d6bdb583c22da1c7bf951f00afcf3f55978 (diff)
downloadedwinmattiacci.com-4526fa0316d8a6d8e616b82de2f39f39a89851ef.tar.gz
edwinmattiacci.com-4526fa0316d8a6d8e616b82de2f39f39a89851ef.tar.bz2
edwinmattiacci.com-4526fa0316d8a6d8e616b82de2f39f39a89851ef.zip
views/partials/navigator: Rework Navigator to be more compact
Diffstat (limited to 'model')
-rw-r--r--model/Navigator.php46
1 files changed, 21 insertions, 25 deletions
diff --git a/model/Navigator.php b/model/Navigator.php
index 199d3c1..10ba623 100644
--- a/model/Navigator.php
+++ b/model/Navigator.php
@@ -1,34 +1,30 @@
<?php
-function navBar()
+class Navigator
{
- $navbar = [
- 'Home' => ['uri' => '/'],
- 'Posts' => ['uri' => '/posts/'],
- 'Feedback' => ['uri' => '/feedback/'],
- 'Contact' => ['uri' => '/contact/'],
- ];
-
- foreach ($navbar as $title => $route) {
- $append ='';
+ public function requestContains($route)
+ {
+ if (strpos($_SERVER['REQUEST_URI'], $route) !== false) {
+ return true;
+ }
+ return false;
+ }
- if ($_SERVER['REQUEST_URI'] === '/'
- && $_SERVER['REQUEST_URI'] === $route['uri']
- ) {
- $append = 'active';
+ public function isActiveHome()
+ {
+ if ($_SERVER['REQUEST_URI'] === '/') {
+ return 'active ';
}
+ return;
+ }
- if (!empty(trim($route['uri'], '/'))
- && strpos(
- trim($_SERVER['REQUEST_URI'], '/'),
- trim($route['uri'], '/')
- ) !== false
+ public function isActive($route)
+ {
+ if ($_SERVER['REQUEST_URI'] === $route
+ || $this->requestContains($route)
) {
- $append = 'active';
- };
-
- echo str_repeat("\t", 4) . '<a class="' . $append . '" '
- . 'href="' . $route['uri'] . '" ' . 'onclick="closeNav()"'
- . '>' . $title . '</a>' . "\n";
+ return 'active ';
+ }
+ return;
}
}