summaryrefslogtreecommitdiff
path: root/includes/titlebar.inc
blob: de585492d17368b0b4cd80460ec63e523cdaf007 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php global $toplevel; $pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true); ?>
<span>
    <?php

$parts = explode("/", $_GET['_']);
$name = $toplevel === "" ? "home" : $toplevel;

$actionsProfile = "default";
$part1 = "<page>";
$part2 = null;
$part3 = null;

if (isset($pages[$name])) {
    if (($name === "docs" || $name === "toys" || $name === "actions") && isset($parts[2])) {
        $part3 = "<a class='title-bar-backlink' href='/-/dashboard'>Dashboard</a>";
        $part2 = "<a class='title-bar-backlink' href='/-/$name'>" . $pages[$name]['name'] . "</a>";

        if ($name === "docs") {
            $actionsProfile = "docs-item";
            $part1 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $parts[2] . ".json"), true)["name"];
        } else {
            $actionsProfile = "$name-item";
            $list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($name === "toys" ? "toys/toys" : "actions/actions") . ".json"), true);
            $part1 = array_values(array_filter($list, function ($i) use ($parts) {
                return $i["id"] === $parts[2];
            }))[0]["name"];
        }
    } else {
        if ($pages[$name]["admin"]) {
            $part1 = $pages[$name]['name'];
            $part2 = "<a class='title-bar-backlink' href='/-/dashboard'>Dashboard</a>";
        } else {
            $part1 = $pages[$name]['name'];
        }
    }
} elseif ($name === "cloudburst") {
    if (isset($parts[2])) {
        $part2 = "<a class='title-bar-backlink' href='/cloudburst'>Cloudburst System</a>";

        if ($parts[2] === "subsystem") {
            $actionsProfile = "subsystem";
            $part1 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/subsystems/ynmuc-$parts[3].json"), true)["name"];
        } else {
            $part1 = $pages["s:" . $parts[2]]['name'] ?? $parts[2];
        }
    } else {
        $actionsProfile = "system";
        $part1 = "Cloudburst System";
    }
} elseif ($name === "raindrops") {
    if (isset($parts[2])) {
        $part2 = "<a class='title-bar-backlink' href='/raindrops'>Raindrops System</a>";

        if ($parts[2] === "subsystem") {
            $actionsProfile = "subsystem";
            $part1 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/subsystems/gdapd-$parts[3].json"), true)["name"];
        } else {
            $part1 = $pages["s:" . $parts[2]]['name'] ?? $parts[2];
        }
    } else {
        $actionsProfile = "system";
        $part1 = "Raindrops System";
    }
} else {
    $member = getMemberFromName($name);
    $actionsProfile = "member";

    if (isset($member)) {
        $memberName = $member["display_name"] ?? $member["name"];
        $part1 = "$memberName";

        if ($member["_system"] === "gdapd") {
            $part2 = "<a class='title-bar-backlink' href='/raindrops'>Raindrops System</a>";
        } else {
            $part2 = "<a class='title-bar-backlink' href='/cloudburst'>Cloudburst System</a>";
        }
    } else {
        $part1 = "$name";
    }
}

if ($actionsProfile === "default") {
    switch ($name) {
        case "home":
            $actionsProfile = "home";
            break;

        case "emergency":
        case "wakeup":
        case "pleasure":
            $actionsProfile = "alert";
            break;

        case "fronting":
            $actionsProfile = "planner";
            break;

        case "actions":
        case "toys":
            $actionsProfile = "actions-or-toys";
            break;

        case "docs":
            $actionsProfile = "docs";
            break;

        case "debug":
            $actionsProfile = "debug";
            break;

        case "bitset":
            $actionsProfile = "bitset";
            break;

        case "parser":
        case "prefix":
            $actionsProfile = "parser-prefix";
            break;
    }
}

if (isset($part3)) {
    echo "$part3 > $part2 > <b>$part1</b>";
} elseif (isset($part2)) {
    echo "$part2 > <b>$part1</b>";
} else {
    echo "<b>$part1</b>";
}

$links = [
    "default" => [
        [
            "name" => "Go back to top",
            "link" => [
                "type" => "js",
                "text" => "document.body.scrollTop = 0; document.documentElement.scrollTop = 0;"
            ],
            "icon" => "/assets/icons/up.svg",
            "invert" => true
        ]
    ]
];

$linksList = $links[isset($links[$actionsProfile]) ? $actionsProfile : "default"];

?> (<code><?= $actionsProfile ?></code>)<!--<pre><?php var_dump($parts); ?></pre>-->
    <span id="title-bar-actions">
        <?php foreach ($linksList as $index => $link): ?>
        <a style="display: inline-block; padding: 4px;" id="title-bar-action-<?= $index ?>" <?php if ($link["link"]["type"] === "url"): ?>href<?php else: ?>onclick<?php endif; ?>="<?= $link["link"]["text"] ?>" title="<?= $link["name"] ?>" data-bs-toggle="tooltip" class="title-bar-action tooltip-nohelp">
            <img src="<?= $link["icon"] ?>" <?php if ($link["invert"]): ?>class="dropdown-icon"<?php endif; ?> alt="" style="width:24px;vertical-align: middle;">
        </a>
        <?php endforeach; ?>
    </span>
</span>

<style>
    .title-bar-backlink {
        color: white !important;
        text-decoration: none;
    }

    .title-bar-backlink:hover {
        opacity: .75;
    }

    #title-bar-actions {
        position: fixed;
        right: 0;
        height: 34px;
        top: 0;
        display: block;
        border-left: 1px solid rgba(255, 255, 255, .25);
    }

    .title-bar-action {
        cursor: pointer;
    }

    .title-bar-action:hover {
        background-color: rgba(255, 255, 255, .1);
    }
</style>