diff options
author | RaindropsSys <raindrops@equestria.dev> | 2024-03-29 22:05:35 +0100 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2024-03-29 22:05:35 +0100 |
commit | 5860551daa0f60103ad24e93da29f401a653f144 (patch) | |
tree | 9ad97e04152a6edc11d5096c87880978df39086a /includes/system | |
parent | a51979ad60074db84af78a06d30fcb888ccb0b03 (diff) | |
download | pluralconnect-5860551daa0f60103ad24e93da29f401a653f144.tar.gz pluralconnect-5860551daa0f60103ad24e93da29f401a653f144.tar.bz2 pluralconnect-5860551daa0f60103ad24e93da29f401a653f144.zip |
Updated 20 files, added 6 files, deleted 144 files and renamed .idea/ponycule.iml (automated)
Diffstat (limited to 'includes/system')
-rw-r--r-- | includes/system/history.inc | 174 |
1 files changed, 0 insertions, 174 deletions
diff --git a/includes/system/history.inc b/includes/system/history.inc deleted file mode 100644 index ddf49bb..0000000 --- a/includes/system/history.inc +++ /dev/null @@ -1,174 +0,0 @@ -<?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; -} - -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; - } -} - -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; global $isLoggedIn; global $isLowerLoggedIn; ?> - <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; - } - }); - - ?> - <h2><?= $systemID === $app["other"]["id"] ? "Front history in " . $app["other"]["name"] : $lang["history"]["title"] . " " . $systemCommonName ?></h2> - <div class="alert alert-warning" id="timezone" style="display: none;"> - <?= str_replace("%1", '<span id="timezone-name">-</span>', str_replace("%2", '<span id="day-start">-</span>', $lang["history"]["timezone"])) ?> - <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]); - if (isset($switchesDay[count($switchesDay) - 1])) { - $switchesDay[] = getSwitchBefore($switchesDay[count($switchesDay) - 1]["id"]); - } - ?> - <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; ?> - <?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="/<?= (isset($member) && $member["name"] === "unknown") ? ($systemID === "gdapd" ? "unknown-rd" : $app["other"]["unknown"]) : $member["name"] ?>"> - <img src="<?= getAsset($systemID, $member["id"], "heads") ?>" style="width:24px;"> <?= $member["display_name"] ?? $member["name"] ?> - </a> - <?php if (count($switch["members"]) > 1): ?> - and - <?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"><?= $lang["history"]["fallback"] ?></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 } - -?> - -<?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(); - - if ($systemID !== $app["other"]["id"]) { - ob_start(); - $isLoggedInOldState = $isLoggedIn; - $isLowerLoggedInOldState = $isLowerLoggedIn; - $isLoggedIn = false; - $isLowerLoggedIn = false; - page(); - $isLoggedIn = $isLoggedInOldState; - $isLowerLoggedIn = $isLowerLoggedInOldState; - $cache[$systemID]["public"] = ob_get_contents(); - ob_end_clean(); - } else { - $cache[$systemID]["public"] = ""; - } -} - -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 |