summaryrefslogtreecommitdiff
path: root/includes/components/header.inc
blob: 940991776af1df057a79e9e6525f6367b629709b (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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?php global $title; global $pages; global $readOnly;
$start = microtime(true);
$use2023UI = $useNewUI = true;
global $use2023UI;

$isNormallyLoggedIn = false;

require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $isUserLoggedIn; global $isLowerLoggedIn;
if ($readOnly && $isLoggedIn || $readOnly && $isUserLoggedIn) {
    $isLoggedIn = false;
    $isUserLoggedIn = false;
    $isNormallyLoggedIn = true;
}

$pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true);

global $_MemberName;
global $_MemberPage;
global $_SystemName;
global $_SystemPage;
global $toplevel;

$pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true);
$page = $pages[$toplevel] ?? [
    "rail" => false
];

require_once $_SERVER["DOCUMENT_ROOT"] . "/includes/util/travelling.inc"; global $travelling;
require_once $_SERVER["DOCUMENT_ROOT"] . "/includes/util/score.inc";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/banner.inc";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/rainbow.inc";

?>
<!doctype html>
<html lang="en">
<head>
    <script>
        document.cookie = "new2023UIDarkMode=" + (window.matchMedia("(prefers-color-scheme: dark)").matches ? "yes" : "no") + "; max-age=" + (60*60*24*365) + "; path=/; samesite; secure";
    </script>
    <link href="/assets/logo/custom-2023.css" rel="preload" as="style">
    <link href="/assets/logo/light-2023.css" rel="preload" as="style">
    <link href="/assets/logo/custom-2023.css" rel="stylesheet">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <title><?= $title && $title !== "-" ? $title . " · " : "" ?>Ponycule</title>
    <link rel="shortcut icon" href="/assets/logo/newlogo-ng.png" type="image/png">
    <link href="/assets/logo/light-2023.css" rel="stylesheet">
</head>
<body style="background-color: var(--palette-1);">
    <?php
        $palettes = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/themes.json"), true);

        $selectedPalette = $palettes["default"];

        global $memberID; global $systemID; if (isset($memberID) || isset($systemID)) {
            if (isset($memberID)) {
                $member = getMemberWithoutSystem($memberID);
                $color = $member["color"];
            } else {
                $systemDataForColor = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID/general.json"), true);
                $color = $systemDataForColor["color"] ?? "000000";
            }

            if (isset($_GET["debug"])) {
                ob_clean();
                echo("<pre>");

                echo("Color difference debug\n======================\n\n");
                echo("Color: #" . $member["color"] . "\n\n");
            }

            $sr = hexdec(substr($member["color"], 0, 2));
            $sg = hexdec(substr($member["color"], 2, 2));
            $sb = hexdec(substr($member["color"], 4, 2));

            $differencesAll = [];

            foreach ($palettes["list"] as $id => $palette) {
                $colors = [
                    ...explode(",", $palette["dark"]),
                    ...explode(",", $palette["light"])
                ];

                $importantColors = [
                    $colors[5],
                    $colors[9],
                    $colors[15],
                    $colors[19]
                ];
                $differences = [];

                if (isset($_GET["debug"])) echo("Palette " . $id . ": " . implode(", ", array_map(function ($i) { return "#$i"; }, $importantColors)) . "\n");

                foreach ($importantColors as $color) {
                    $r = hexdec(substr($color, 0, 2));
                    $g = hexdec(substr($color, 2, 2));
                    $b = hexdec(substr($color, 4, 2));

                    $dr = abs($r - $sr);
                    $dg = abs($g - $sg);
                    $db = abs($b - $sb);

                    $differences[] = $dr + $dg + $db;
                }

                $total = array_reduce($differences, function ($a, $b) { return $a + $b; }) / count($differences);

                if (isset($_GET["debug"])) {
                    echo("    " . implode(", ", $differences) . "\n");
                    echo("    " . $total . "\n\n");
                }

                $differencesAll[] = [
                    "id" => $id,
                    "difference" => $total
                ];
            }

            usort($differencesAll, function ($a, $b) {
                return $a["difference"] - $b["difference"];
            });

            if (isset($_GET["debug"])) {
                echo("Smaller: " . $differencesAll[0]["id"] . ", " . $differencesAll[0]["difference"]);
            }

            $selectedPalette = $differencesAll[0]["id"];

            if (isset($_GET["debug"])) {
                echo("</pre>");
                die();
            }
        }

        global $userPalette;
        $userPalette = $palettes["list"][$selectedPalette];

        function rgb($color) {
            return hexdec(substr($color, 0, 2)) . "," . hexdec(substr($color, 2, 2)) . "," . hexdec(substr($color, 4, 2));
        }

        function icon($name, $dark = null, $body = false) {
            global $userPalette;

            if (isset($dark)) {
                return "/assets/icons/new/" . $name . ".svg?color=" . explode(",", $userPalette[$dark ? "dark" : "light"])[$body ? 6 : 9];
            } else {
                return "/assets/icons/new/" . $name . ".svg?color=" . explode(",", $userPalette[isset($_COOKIE["new2023UIDarkMode"]) && $_COOKIE["new2023UIDarkMode"] === "yes" ? "dark" : "light"])[$body ? 6 : 9];
            }
        }

        foreach ([ "dark", "light" ] as $theme) { $palette = explode(",", $userPalette[$theme]); ?>
            <style>
                @media (prefers-color-scheme: <?= $theme ?>)<?= $theme === "light" ? ", (prefers-color-scheme: no-preference)" : "" ?> {
                    :root {
                        --bs-body-color:            #<?= $palette[6] ?>         !important;
                        --bs-body-color-rgb:        <?= rgb($palette[6]) ?>     !important;
                        --bs-body-bg:               #<?= $palette[0] ?>         !important;
                        --bs-body-bg-rgb:           <?= rgb($palette[0]) ?>     !important;
                        --bs-white:                 #<?= $palette[0] ?>         !important;
                        --bs-white-rgb:             <?= rgb($palette[0]) ?>     !important;

                        --bs-secondary-color:       #<?= $palette[6] ?>         !important;
                        --bs-secondary-color-rgb:   <?= rgb($palette[6]) ?>     !important;
                        --bs-secondary-bg:          #<?= $palette[1] ?>         !important;
                        --bs-secondary:             #<?= $palette[6] ?>         !important;
                        --bs-secondary-bg-rgb:      <?= rgb($palette[1]) ?>     !important;

                        --bs-tertiary-color:        #<?= $palette[6] ?>         !important;
                        --bs-tertiary-color-rgb:    <?= rgb($palette[6]) ?>     !important;
                        --bs-tertiary-bg:           #<?= $palette[2] ?>         !important;
                        --bs-tertiary-bg-rgb:       <?= rgb($palette[2]) ?>     !important;

                        --bs-light:                 #<?= $palette[2] ?>         !important;
                        --bs-light-rgb:             <?= rgb($palette[2]) ?>     !important;

                        --bs-link-color:            #<?= $palette[9] ?>         !important;
                        --bs-link-hover-color:      #<?= $palette[9] ?>77       !important;
                        --bs-link-active-color:     #<?= $palette[9] ?>77       !important;

                        --palette-0:                #<?= $palette[0] ?>         !important;
                        --palette-1:                #<?= $palette[1] ?>         !important;
                        --palette-2:                #<?= $palette[2] ?>         !important;
                        --palette-3:                #<?= $palette[3] ?>         !important;
                        --palette-4:                #<?= $palette[4] ?>         !important;
                        --palette-5:                #<?= $palette[5] ?>         !important;
                        --palette-6:                #<?= $palette[6] ?>         !important;
                        --palette-7:                #<?= $palette[7] ?>         !important;
                        --palette-8:                #<?= $palette[8] ?>         !important;
                        --palette-9:                #<?= $palette[9] ?>         !important;

                        --palette-0-rgb:            <?= rgb($palette[0]) ?>     !important;
                        --palette-1-rgb:            <?= rgb($palette[1]) ?>     !important;
                        --palette-2-rgb:            <?= rgb($palette[2]) ?>     !important;
                        --palette-3-rgb:            <?= rgb($palette[3]) ?>     !important;
                        --palette-4-rgb:            <?= rgb($palette[4]) ?>     !important;
                        --palette-5-rgb:            <?= rgb($palette[5]) ?>     !important;
                        --palette-6-rgb:            <?= rgb($palette[6]) ?>     !important;
                        --palette-7-rgb:            <?= rgb($palette[7]) ?>     !important;
                        --palette-8-rgb:            <?= rgb($palette[8]) ?>     !important;
                        --palette-9-rgb:            <?= rgb($palette[9]) ?>     !important;
                    }

                    .dropdown-menu {
                        background-color: #<?= $palette[1] ?> !important;
                        --bs-dropdown-bg: #<?= $palette[1] ?> !important;
                        --bs-dropdown-link-color: #<?= $palette[6] ?> !important;
                        --bs-dropdown-link-disabled-color: #<?= $palette[6] ?>77 !important;
                        --bs-dropdown-link-hover-color: #<?= $palette[6] ?> !important;
                        --bs-dropdown-link-hover-bg: #<?= $palette[3] ?> !important;
                        --bs-dropdown-link-active-bg: #<?= $palette[6] ?> !important;
                        --bs-dropdown-link-active-color: #<?= $palette[6] ?> !important;
                    }

                    .dropdown-item {
                        color: #<?= $palette[6] ?> !important;
                    }

                    .dropdown-item:hover {
                        color: #<?= $palette[6] ?> !important;
                        background-color: #<?= $palette[3] ?> !important;
                    }

                    .dropdown-item:active {
                        color: #<?= $palette[6] ?> !important;
                        background-color: #<?= $palette[6] ?> !important;
                    }

                    .dropdown-item.disabled {
                        color: #<?= $palette[6] ?>77 !important;
                    }

                    .coins {
                        color: #<?= $palette[6] ?> !important;
                        background-color: #<?= $palette[1] ?> !important;
                    }

                    .list-group-item-primary {
                        color: var(--bs-body-bg);
                        background-color: #<?= $palette[6] ?>;
                    }

                    .list-group-item-action.list-group-item-primary:hover, .list-group-item-action.list-group-item-primary:active, .list-group-item-action.list-group-item-primary:focus {
                        background-color: #<?= $palette[6] ?>dd;
                        color: var(--bs-body-bg);
                    }

                    .profile-border-inner-active {
                        background-color: var(--bs-tertiary-bg) !important;
                    }

                    .bg-secondary {
                        background-color: #<?= $palette[9] ?> !important;
                        color: #<?= $palette[0] ?> !important;
                    }

                    .list-group-item-primary small {
                        color: #<?= $palette[0] ?>77 !important;
                    }

                    .list-group, .list-group-item, .list-group-item-action {
                        --bs-list-group-color: var(--bs-body-color) !important;
                        --bs-list-group-action-color: var(--bs-body-color) !important;
                        --bs-list-group-action-hover-color: var(--bs-body-color) !important;
                        --bs-list-group-action-active-color: var(--bs-body-color) !important;
                        --bs-list-group-border-color: #<?= $palette[5] ?> !important;
                        --bs-list-group-bg: #<?= $palette[2] ?> !important;
                        --bs-list-group-action-hover-bg: #<?= $palette[1] ?> !important;
                        --bs-list-group-action-active-bg: #<?= $palette[1] ?> !important;
                    }

                    .btn-outline-dark, .btn-outline-secondary {
                        --bs-btn-color: var(--bs-body-color);
                        --bs-btn-border-color: var(--bs-body-color);
                        --bs-btn-hover-color: var(--bs-body-bg);
                        --bs-btn-hover-bg: var(--bs-body-color);
                        --bs-btn-hover-border-color: var(--bs-body-color);
                        --bs-btn-focus-shadow-rgb: <?= rgb($palette[6]) ?>;
                        --bs-btn-active-color: var(--bs-body-bg);
                        --bs-btn-active-bg: var(--bs-body-color);
                        --bs-btn-active-border-color: var(--bs-body-color);
                        --bs-btn-active-shadow: inset 0 3px 5px rgba(<?= rgb($palette[6]) ?>, 0.125);
                        --bs-btn-disabled-color: #<?= $palette[6] ?>77;
                        --bs-btn-disabled-bg: transparent;
                        --bs-btn-disabled-border-color: #<?= $palette[6] ?>77;
                        --bs-gradient: none;
                    }

                    .alert-primary {
                        --bs-alert-color: var(--bs-body-bg);
                        --bs-alert-bg: var(--bs-body-color);
                        --bs-alert-border-color: var(--bs-body-color);
                    }

                    .alert-danger .btn-close, .alert-success .btn-close, .alert-warning .btn-close {
                        background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23<?= $palette[0] ?>'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat
                    }

                    .alert-danger, .alert-success, .alert-warning, .list-group-item-warning {
                        --bs-alert-color: var(--bs-body-bg) !important;
                        --bs-alert-bg: #<?= $palette[9] ?> !important;
                        --bs-alert-border-color: #<?= $palette[9] ?> !important;
                        --bs-list-group-border-color: #<?= $palette[8] ?> !important;
                    }

                    .list-group-item-warning, .list-group-item-success, .list-group-item-danger, .list-group-item-warning:hover, .list-group-item-success:hover, .list-group-item-danger:hover, .list-group-item-warning:active, .list-group-item-success:active, .list-group-item-danger:active {
                        color: var(--bs-body-color) !important;
                        background-color: #<?= $palette[8] ?> !important;
                    }

                    .list-group-item-warning:hover, .list-group-item-success:hover, .list-group-item-danger:hover {
                        opacity: .75;
                    }

                    .list-group-item-warning:active, .list-group-item-success:active, .list-group-item-danger:active {
                        opacity: .5;
                    }

                    .list-group-item[open] {
                        opacity: 1 !important;
                    }

                    .alert-secondary {
                        --bs-alert-color: var(--bs-secondary-color);
                        --bs-alert-bg: var(--bs-secondary-bg);
                        --bs-alert-border-color: var(--bs-secondary-bg);
                    }

                    .badge.bg-success, .badge.bg-danger, .badge.bg-warning {
                        background-color: var(--bs-body-color) !important;
                        color: var(--bs-body-bg) !important;
                    }

                    .badge.bg-secondary, .badge.bg-black {
                        background-color: var(--bs-body-bg) !important;
                        color: var(--bs-body-color) !important;
                    }

                    .text-muted {
                        color: #<?= $palette[6] ?>77 !important;
                    }

                    body.bg-light {
                        background-color: var(--bs-body-bg) !important;
                    }

                    .btn-primary {
                        --bs-btn-color: #<?= $palette[8] ?>;
                        --bs-btn-bg: #<?= $palette[9] ?>;
                        --bs-btn-border-color: #<?= $palette[9] ?>;
                        --bs-btn-hover-color: #<?= $palette[8] ?>;
                        --bs-btn-hover-bg: #<?= $palette[9] ?>;
                        --bs-btn-hover-border-color: #<?= $palette[9] ?>;
                        --bs-btn-focus-shadow-rgb: <?= rgb($palette[9]) ?>;
                        --bs-btn-active-color: #<?= $palette[8] ?>;
                        --bs-btn-active-bg: #<?= $palette[9] ?>;
                        --bs-btn-active-border-color: #<?= $palette[9] ?>;
                        --bs-btn-active-shadow: inset 0 3px 5px rgba(<?= rgb($palette[9]) ?>, 0.25);
                        --bs-btn-disabled-color: #<?= $palette[8] ?>;
                        --bs-btn-disabled-bg: #<?= $palette[9] ?>77;
                        --bs-btn-disabled-border-color: #<?= $palette[9] ?>77;
                    }

                    .btn-outline-primary {
                        --bs-btn-color: #<?= $palette[9] ?>;
                        --bs-btn-border-color: #<?= $palette[9] ?>;
                        --bs-btn-hover-color: var(--bs-body-bg);
                        --bs-btn-hover-bg: #<?= $palette[9] ?>;
                        --bs-btn-hover-border-color: #<?= $palette[9] ?>;
                        --bs-btn-focus-shadow-rgb: <?= rgb($palette[6]) ?>;
                        --bs-btn-active-color: var(--bs-body-bg);
                        --bs-btn-active-bg: #<?= $palette[9] ?>;
                        --bs-btn-active-border-color: #<?= $palette[9] ?>;
                        --bs-btn-active-shadow: inset 0 3px 5px rgba(<?= rgb($palette[6]) ?>, 0.125);
                        --bs-btn-disabled-color: #<?= $palette[6] ?>77;
                        --bs-btn-disabled-bg: transparent;
                        --bs-btn-disabled-border-color: #<?= $palette[6] ?>77;
                        --bs-gradient: none;
                    }

                    .progress {
                        background-color: #<?= $palette[2] ?> !important;
                    }

                    .progress-bar.bg-success {
                        background-color: #<?= $palette[9] ?> !important;
                    }

                    .progress-bar.bg-danger {
                        background-color: #<?= $palette[7] ?> !important;
                    }

                    .card {
                        background-color: #<?= $palette[2] ?> !important;
                        border-color: #<?= $palette[5] ?> !important;
                    }

                    .form-control, .form-control:focus, .form-select, .form-select:focus, .form-check-input, .form-check-input:focus {
                        color: var(--bs-body-color);
                        background-color: #<?= $palette[2] ?> !important;
                        border-color: #<?= $palette[3] ?> !important;
                    }

                    .form-check-input:checked, .form-check-input:checked:focus {
                        background-color: #<?= $palette[9] ?> !important;
                        border-color: #<?= $palette[9] ?> !important;
                    }

                    .form-control:focus, .form-select:focus, .form-check-input:focus {
                        box-shadow: 0 0 0 0.25rem rgba(<?= rgb($palette[9]) ?>, .25);
                        transition: box-shadow 200ms;
                    }

                    .form-control::placeholder, .form-select::placeholder {
                        color: #<?= $palette[6] ?>77;
                    }

                    .modal {
                        --bs-modal-bg: #<?= $palette[1] ?> !important;
                        --bs-modal-header-border-color: #<?= $palette[3] ?> !important;
                    }

                    .card {
                        --bs-card-bg: #<?= $palette[1] ?> !important;
                    }

                    .btn-close {
                        background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23<?= $palette[6] ?>'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
                        opacity: 1 !important;
                    }

                    .antialias, #new-homepage img, #hpd-other img, #hpd-raindrops img, #hpd-cloudburst img, .ck img, #system-info img, #member-card img {
                        image-rendering: auto !important;
                    }

                    #member-relations img {
                        image-rendering: pixelated !important;
                    }

                    .btn-close:hover {
                        opacity: .75 !important;
                    }

                    .btn-close:active {
                        opacity: .5 !important;
                    }

                    .ck-editor {
                        color: var(--bs-black);
                    }

                    .alert-primary a, .alert-danger a, .alert-success a, .alert-warning a {
                        color: var(--bs-body-bg);
                    }

                    #plus-box, #plus-box > div > div > div > span, #plus-box h2 {
                        color: var(--bs-body-color);
                    }

                    #plus-box {
                        background: #<?= $palette[2] ?> !important;
                    }

                    #plus-box > div {
                        background-image: none !important;
                    }
                }
            </style>
        <?php } ?>

    <?php require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/components/2023ui.inc"; ?>
<?php $GLOBALS["ColdHazePerformance"]["header"] = (microtime(true) - $start) * 1000; $start = microtime(true); ?>
<main id="app" style="background-color: var(--palette-0);">