summaryrefslogtreecommitdiff
path: root/includes/system/history.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/system/history.inc')
-rw-r--r--includes/system/history.inc177
1 files changed, 107 insertions, 70 deletions
diff --git a/includes/system/history.inc b/includes/system/history.inc
index bf1d016..963e124 100644
--- a/includes/system/history.inc
+++ b/includes/system/history.inc
@@ -1,70 +1,74 @@
-<?php global $system; global $lang; global $pages; global $systemCommonName; $pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true); $title = $pages["s:history"]["name"][$lang["_name"]] . " · " . $systemCommonName; global $systemID; global $app; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc';
+<?php global $system; global $lang; global $pages; global $systemCommonName; $pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true); $title = $pages["s:history"]["name"][$lang["_name"]] . " · " . $systemCommonName; global $systemID; global $app; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; global $isLoggedIn; global $isLowerLoggedIn;
-?>
+function frenchIfRequired($original) {
+ return $original;
+}
- <br>
- <div class="container" id="page-content">
- <?php
+function getSwitchesForDay(int $day) {
+ global $switches;
- $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;
- }
- });
+ $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));
+ }));
- function frenchIfRequired($original) {
- return $original;
+ uksort($filtered, 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;
+ return $filtered;
+}
- $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));
- }));
+function getSwitchBefore(string $id) {
+ global $switches;
- uksort($filtered, function ($a, $b) {
- if (isset($b["timestamp"]) && isset($a["timestamp"])) {
- return strtotime($b["timestamp"]) - strtotime($a["timestamp"]);
- } else {
- return null;
- }
- });
+ $currentPassed = false;
+ $before = null;
- return $filtered;
+ foreach ($switches as $switch) {
+ if ($currentPassed) {
+ $before = $switch;
+ break;
+ } else {
+ if ($switch["id"] === $id) {
+ $currentPassed = true;
+ }
}
+ }
- 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;
+}
- 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;
+ }
+}
- function isNotToday(int $timestamp, int $offset) {
- if (date('Y-m-d', $timestamp) !== date('Y-m-d', time() - (86400 * $offset))) {
- return true;
+if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/history.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/history.json", "{}");
+
+$cache = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/history.json"), true);
+
+function page() { global $lang; global $systemCommonName; global $systemID; global $app; global $switches; ?>
+ <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 false;
+ return null;
}
- }
+ });
?>
<h2><?= $systemID === $app["other"]["id"] ? "Front history in " . $app["other"]["name"] : $lang["history"]["title"] . " " . $systemCommonName ?></h2>
@@ -76,28 +80,28 @@
</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):
+ [ "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]);
if (isset($switchesDay[count($switchesDay) - 1])) {
$switchesDay[] = getSwitchBefore($switchesDay[count($switchesDay) - 1]["id"]);
}
?>
- <h4 style="margin-top:15px;"><?= frenchIfRequired($day[0]) ?></h4>
+ <h4 style="margin-top:15px;"><?= frenchIfRequired($day[0]) ?></h4>
<?php if (count($switchesDay) === 0): ?>
- <p class="text-muted">No switches happened on that day</p>
- <?php endif; ?>
+ <p class="text-muted">No switches happened on that day</p>
+ <?php endif; ?>
<?php foreach ($switchesDay as $switch): $switch["timestamp"] = strtotime($switch["timestamp"]); ?>
- <?php if (isset($switch["members"][0])): $member = getMemberWithoutSystem($switch["members"][0]); ?>
+ <?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"]) ?>
@@ -112,7 +116,7 @@
<?php endif; ?>
</span>
</div>
- <?php else: ?>
+ <?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"]) ?>
@@ -121,13 +125,46 @@
<span class="text-muted"><?= $lang["history"]["fallback"] ?></span>
</span>
</div>
- <?php endif; ?>
- <?php endforeach; ?>
+ <?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 }
+
+?>
+
+<?php
+
+if (!isset($cache[$systemID])) $cache[$systemID] = [];
+
+if (!isset($cache[$systemID]["private"]) || !isset($cache[$systemID]["public"])) {
+ ob_start();
+ $isLoggedInOldState = $isLoggedIn;
+ $isLowerLoggedInOldState = $isLowerLoggedIn;
+ $isLoggedIn = true;
+ $isLowerLoggedIn = true;
+ page();
+ $isLoggedIn = $isLoggedInOldState;
+ $isLowerLoggedIn = $isLowerLoggedInOldState;
+ $cache[$systemID]["private"] = ob_get_contents();
+ ob_end_clean();
+
+ ob_start();
+ $isLoggedInOldState = $isLoggedIn;
+ $isLowerLoggedInOldState = $isLowerLoggedIn;
+ $isLoggedIn = false;
+ $isLowerLoggedIn = false;
+ page();
+ $isLoggedIn = $isLoggedInOldState;
+ $isLowerLoggedIn = $isLowerLoggedInOldState;
+ $cache[$systemID]["public"] = ob_get_contents();
+ ob_end_clean();
+}
+
+echo($isLoggedIn ? $cache[$systemID]["private"] : $cache[$systemID]["public"]); file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/history.json", json_encode($cache)); ?>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?> \ No newline at end of file