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
|
<?php global $system; global $systemCommonName; $pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true); $title = $pages["s:history"]["name"] . " · " . $systemCommonName; global $systemID; $title = "Front history · " . $systemCommonName; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
function getMember(string $id) {
global $systemID;
$members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID/members.json"), true);
$member = null;
foreach ($members as $m) {
if ($m["id"] === $id) $member = $m;
}
return $member;
}
?>
<br>
<div class="container" id="page-content">
<?php
$switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$systemID/switches.json"), true);
uksort($switches, function ($a, $b) {
if (isset($b["timestamp"]) && isset($a["timestamp"])) {
return strtotime($b["timestamp"]) - strtotime($a["timestamp"]);
} else {
return null;
}
});
function getSwitchesForDay(int $day) {
global $switches;
$filtered = array_values(array_filter($switches, function ($i) use ($day) {
$diff = strtotime(date("Y-m-d")) - strtotime(explode("T", $i["timestamp"])[0]);
return $diff <= (86400 * $day) && $diff > (86400 * ($day - 1));
}));
uksort($filtered, function ($a, $b) {
if (isset($b["timestamp"]) && isset($a["timestamp"])) {
return strtotime($b["timestamp"]) - strtotime($a["timestamp"]);
} else {
return null;
}
});
return $filtered;
}
function getSwitchBefore(string $id) {
global $switches;
$currentPassed = false;
$before = null;
foreach ($switches as $switch) {
if ($currentPassed) {
$before = $switch;
break;
} else {
if ($switch["id"] === $id) {
$currentPassed = true;
}
}
}
return $before;
}
function isNotToday(int $timestamp, int $offset) {
if (date('Y-m-d', $timestamp) !== date('Y-m-d', time() - (86400 * $offset))) {
return true;
} else {
return false;
}
}
?>
<h2>Front history in the <?= $systemCommonName ?></h2>
<div class="alert alert-warning" id="timezone" style="display: none;">
Times on this page are now shown using your local timezone (<span id="timezone-name">-</span>). Days start at <span id="day-start">-</span> (00:00 on UTC).
<script>
document.getElementById("day-start").innerText = new Date(<?= strtotime(date('Y-m-d')) ?> * 1000).toTimeString().substring(0, 5);
document.getElementById("timezone-name").innerText = new Date().toTimeString().split("(")[1].split(")")[0];
</script>
</div>
<?php foreach ([
[ "Today", 0 ],
[ "Yesterday", 1 ],
[ date('D j M', time() - (86400 * 2)), 2 ],
[ date('D j M', time() - (86400 * 3)), 3 ],
[ date('D j M', time() - (86400 * 4)), 4 ],
[ date('D j M', time() - (86400 * 5)), 5 ],
[ date('D j M', time() - (86400 * 6)), 6 ],
[ date('D j M', time() - (86400 * 7)), 7 ],
[ date('D j M', time() - (86400 * 8)), 8 ],
[ date('D j M', time() - (86400 * 9)), 9 ],
] as $day):
$switchesDay = getSwitchesForDay($day[1]);
$switchesDay[] = getSwitchBefore($switchesDay[count($switchesDay) - 1]["id"]);
?>
<h4 style="margin-top:15px;"><?= $day[0] ?></h4>
<?php foreach ($switchesDay as $switch): $switch["timestamp"] = strtotime($switch["timestamp"]); ?>
<?php if (isset($switch["members"][0])): $member = getMemberWithoutSystem($switch["members"][0]); ?>
<div class="fronter">
<span class="fronter-date" data-date-time="<?= isNotToday($switch["timestamp"], $day[1]) ? strtotime(date('Y-m-d', $switch["timestamp"])) : $switch["timestamp"] ?>" style="opacity:.5;font-family: monospace;font-size:14px;vertical-align: middle;">
<?= isNotToday($switch["timestamp"], $day[1]) ? "00:00" : date('H:i', $switch["timestamp"]) ?>
</span>
<span class="fronter-profile" style="vertical-align: middle;">
<a class="member-link" href="/<?= $member["name"] ?>">
<img src="<?= getAsset($systemID, $member["id"], "heads") ?>" style="width:24px;"> <?= $member["display_name"] ?? $member["name"] ?>
</a>
<?php if (count($switch["members"]) > 1): ?>
(with
<?php if (isset($switch["members"][1])): $member2 = getMember($switch["members"][1]); ?><a class="member-link" href="/<?= $member2["name"] ?>"><img src="<?= getAsset($systemID, $member2["id"], "heads") ?>" style="width:24px;"> <?= $member2["display_name"] ?? $member2["name"] ?></a><?php endif; ?><?php if (isset($switch["members"][2])): $member2 = getMember($switch["members"][2]); ?>, <a class="member-link" href="/<?= $member2["name"] ?>"><img src="<?= getAsset($systemID, $member2["id"], "heads") ?>" style="width:24px;"> <?= $member2["display_name"] ?? $member2["name"] ?></a><?php endif; ?><?php if (isset($switch["members"][3])): $member2 = getMember($switch["members"][3]); ?>, <a class="member-link" href="/<?= $member2["name"] ?>"><img src="<?= getAsset($systemID, $member2["id"], "heads") ?>" style="width:24px;"> <?= $member2["display_name"] ?? $member2["name"] ?></a><?php endif; ?>)
<?php endif; ?>
</span>
</div>
<?php else: ?>
<div class="fronter">
<span class="fronter-date" data-date-time="<?= isNotToday($switch["timestamp"], $day[1]) ? strtotime(date('Y-m-d', $switch["timestamp"])) : $switch["timestamp"] ?>" style="opacity:.5;font-family: monospace;font-size:14px;vertical-align: middle;">
<?= isNotToday($switch["timestamp"], $day[1]) ? "00:00" : date('H:i', $switch["timestamp"]) ?>
</span>
<span class="fronter-profile" style="vertical-align: middle;">
<span class="text-muted">Fallback pony</span>
</span>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</div>
<script>
Array.from(document.getElementsByClassName("fronter-date")).forEach((i) => { i.innerText = new Date(parseInt(i.getAttribute("data-date-time").trim()) * 1000).toTimeString().split(" ")[0].substring(0, 5) + " " });
document.getElementById("timezone").style.display = "";
</script>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.inc'; ?>
|