aboutsummaryrefslogtreecommitdiff
path: root/model/Navigator.php
blob: a8150e9664425bcc5c091e92afa6a039d079a560 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php

function navBar()
{
    switch ($_SERVER['REQUEST_URI']) {
    case '/posts/':
        $uri = $_SERVER['REQUEST_URI'];
        $location = 'Posts ';
        break;

    case '/feedback/':
        $uri = $_SERVER['REQUEST_URI'];
        $location = 'Feedback ';
        break;

    case '/contact/':
        $uri = $_SERVER['REQUEST_URI'];
        $location = 'Contact ';
        break;

    case '/login/':
        $uri = $_SERVER['REQUEST_URI'];
        $location = 'Login ';
        break;

    default:
        $uri = '/';
        $location = 'Home ';
    }

    $navbar = [
        $location => ['link' => $uri], //Hidden link shown in mobile responsive mode.
        'Home' => ['link' => '/'],
        'Posts' => ['link' => '/posts/'],
        'Feedback' => ['link' => '/feedback/'],
        'Contact' => ['link' => '/contact/'],
    ];

    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 '<a class="active" href="/">Home</a>';
                continue;
            }
            echo '<a href="/">Home</a>';
            continue;
        }

        if ($title === $location && $route['link'] === $_SERVER['REQUEST_URI']) {
            echo '<a style="cursor: default; pointer-events: none;" href="/">' . $location . '</a>';
            continue;
        }

        if ($route['link'] === $_SERVER['REQUEST_URI'] || strpos($_SERVER['REQUEST_URI'], $route['link']) !== false) {
            $append = 'class="active" ';
        }
        echo str_repeat("\t", 4) . '<a ' . $append . 'href="' . $route['link'] . '">' . $title . '</a>' . "\n";
    }
}

function navBarPost()
{
    $navbar = [
        'Home' => ['uri' => '/'],
        'Posts' => ['uri' => '/posts/'],
        'Feedback' => ['uri' => '/feedback/'],
        'Contact' => ['uri' => '/contact/'],
    ];

    foreach ($navbar as $title => $route) {
        $append ='';
        if ($route['uri'] === $_SERVER['REQUEST_URI']) {
            $append = 'class="active" ';
        };
        echo str_repeat("\t", 4) . '<a ' . $append . 'href="' . $route['uri'] . '" ' . 'onclick="closeNav()"' . '>' . $title . '</a>' . "\n";
    }
}