diff options
-rw-r--r-- | .idea/inspectionProfiles/Project_Default.xml | 3 | ||||
-rw-r--r-- | assets/icons/evening.svg | 1 | ||||
-rw-r--r-- | includes/components/navigation.inc | 14 | ||||
-rw-r--r-- | includes/components/planner.inc | 4 | ||||
-rw-r--r-- | includes/external/addressbook/twitter-tag-to-id.js | 4 | ||||
-rw-r--r-- | includes/luna.php | 2 | ||||
-rw-r--r-- | includes/pages.json | 11 | ||||
-rw-r--r-- | includes/util/functions.inc | 12 | ||||
-rw-r--r-- | pages/api/computer.php | 2 | ||||
-rw-r--r-- | pages/api/computername.php | 2 | ||||
-rw-r--r-- | pages/computers.inc | 6 | ||||
-rw-r--r-- | pages/evening.inc | 262 | ||||
-rw-r--r-- | pages/fronting.inc | 3 |
13 files changed, 314 insertions, 12 deletions
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index a43a458..4558473 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -5,7 +5,7 @@ <inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true"> <option name="myValues"> <value> - <list size="8"> + <list size="9"> <item index="0" class="java.lang.String" itemvalue="nobr" /> <item index="1" class="java.lang.String" itemvalue="noembed" /> <item index="2" class="java.lang.String" itemvalue="comment" /> @@ -14,6 +14,7 @@ <item index="5" class="java.lang.String" itemvalue="script" /> <item index="6" class="java.lang.String" itemvalue="style" /> <item index="7" class="java.lang.String" itemvalue="peh-muted" /> + <item index="8" class="java.lang.String" itemvalue="p" /> </list> </value> </option> diff --git a/assets/icons/evening.svg b/assets/icons/evening.svg new file mode 100644 index 0000000..c18d9ef --- /dev/null +++ b/assets/icons/evening.svg @@ -0,0 +1 @@ +<svg width="24" height="24" fill="none" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M13.002 8.009c3.168 0 4.966 2.097 5.227 4.63h.08a3.687 3.687 0 0 1 3.692 3.683 3.687 3.687 0 0 1-3.692 3.682H7.694a3.687 3.687 0 0 1-3.692-3.682 3.687 3.687 0 0 1 3.692-3.683h.08c.263-2.55 2.06-4.63 5.228-4.63Zm0 1.497c-2.072 0-3.877 1.634-3.877 3.89 0 .357-.319.638-.684.638h-.69c-1.262 0-2.284 1-2.284 2.236 0 1.235 1.022 2.236 2.283 2.236h10.503c1.261 0 2.283-1 2.283-2.236 0-1.235-1.022-2.236-2.283-2.236h-.69c-.366 0-.685-.28-.685-.638 0-2.285-1.805-3.89-3.876-3.89ZM6.589 4.001a5.058 5.058 0 0 1 2.263.674A5.057 5.057 0 0 1 11.06 7.27c-.5.14-.963.338-1.386.584a3.555 3.555 0 0 0-2.19-2.162c.16 1.352-.047 2.513-.622 3.611l-.118.213c-.571.976-1.432 1.708-2.719 2.304a3.603 3.603 0 0 0 1.07.614c-.45.302-.845.681-1.166 1.119a5.06 5.06 0 0 1-1.797-1.599.75.75 0 0 1 .366-1.132c1.643-.588 2.527-1.25 3.034-2.216.552-1.055.654-2.174.287-3.677A.75.75 0 0 1 6.59 4Z" fill="#000000"/></svg>
\ No newline at end of file diff --git a/includes/components/navigation.inc b/includes/components/navigation.inc index 478420d..4d0cc5e 100644 --- a/includes/components/navigation.inc +++ b/includes/components/navigation.inc @@ -118,7 +118,7 @@ $navigation_admin = [ "minimal" => false, "items" => [ time() >= 1686787200 ? null : [ - "name" => $pages["fronting"]["name"][$lang["_name"]], + "name" => "Front planner<span class='badge bg-warning text-black rounded-pill' style='position:relative;top:-1px; margin-left: 5px;'>EOL</span>", "icon" => "/assets/icons/fronting.svg", "invert" => true, "link" => "/-/fronting", @@ -126,6 +126,14 @@ $navigation_admin = [ "private" => false ], [ + "name" => $pages["evening"]["name"][$lang["_name"]] . (time() >= 1686787200 ? "" : "<span class='badge bg-info text-black rounded-pill' style='position:relative;top:-1px; margin-left: 5px;'>Beta</span>"), + "icon" => "/assets/icons/evening.svg", + "invert" => true, + "link" => "/-/evening", + "stepped" => null, + "private" => false + ], + [ "name" => $pages["profiles"]["name"][$lang["_name"]], "icon" => "/assets/icons/profiles.svg", "invert" => true, @@ -173,8 +181,8 @@ $navigation_admin = [ "stepped" => null, "private" => true ], - [ - "name" => $pages["computers"]["name"][$lang["_name"]] . "<span class='badge bg-warning text-black rounded-pill' style='position:relative;top:-1px; margin-left: 5px;'>EOL</span>", + time() >= 1688169600 ? null : [ + "name" => "Devices<span class='badge bg-warning text-black rounded-pill' style='position:relative;top:-1px; margin-left: 5px;'>EOL</span>", "icon" => "/assets/icons/computers.svg", "invert" => true, "link" => "/-/computers", diff --git a/includes/components/planner.inc b/includes/components/planner.inc index b5fc7a5..9385b67 100644 --- a/includes/components/planner.inc +++ b/includes/components/planner.inc @@ -577,7 +577,7 @@ if (fronting[system][date][id][0] === "lzlaq" || fronting[system][date][id][0] === "irxyh") { document.getElementById("edit-fronter-name").innerText = "merged members"; } else { - document.getElementById("edit-fronter-name").innerText = names[fronting[system][date][id][0]] ?? fronting[system][date][id][0]; + document.getElementById("edit-fronter-name").innerText = names[fronting[system][date][id][0]] ?? fronting[system][date][id][0] + " [" + fronting[system][date][id][0] + "]"; } document.getElementById("edit-fronter-date").innerText = display; @@ -863,7 +863,7 @@ <div id="list"> <div class="list-group"> <?php foreach (array_filter(scoreOrderGlobal(), function ($i) { return $i["system"] === "gdapd" || $i["system"] === "ynmuc"; }) as $member): ?> - <a id="list-pony-<?= $member['id'] ?>" onclick="confirmFronterAdd(window.addSystem, '<?= $member['id'] ?>');" class="new-fronter-link list-group-item list-group-item-action"><img src="<?= getAsset($member["system"], $member["id"], "heads") ?>" style="width:24px;"> <?= $member["display_name"] ?? $member["name"] ?><peh-schedule-add></peh-schedule-add></a> + <a id="list-pony-<?= $member['id'] ?>" onclick="confirmFronterAdd(window.addSystem, '<?= $member['id'] ?>');" class="new-fronter-link list-group-item list-group-item-action"><img src="<?= getAsset($member["system"], $member["id"], "heads") ?>" style="width:24px;"> <?= $member["display_name"] ?? $member["name"] ?> [<?= $member["id"] ?>]<peh-schedule-add></peh-schedule-add></a> <?php endforeach; $member = getSystemMember("gdapd", "irxyh") ?> <a id="list-pony-irxyh" onclick="confirmFronterAdd(window.addSystem, 'irxyh');" class="new-fronter-link list-group-item list-group-item-action"><img src="/assets/logo/newlogo3.png" style="filter:grayscale(1);width:24px;"> <span style="opacity:.75">Multiple merged members</span></a> <a id="list-pony-zdtsg" onclick="confirmFronterAdd(window.addSystem, 'zdtsg');" class="new-fronter-link list-group-item list-group-item-action"><img src="/assets/logo/newlogo3.png" style="filter:grayscale(1);width:24px;"> <span style="opacity:.75">Other/unknown</span></a> diff --git a/includes/external/addressbook/twitter-tag-to-id.js b/includes/external/addressbook/twitter-tag-to-id.js index 663f195..6abccc0 100644 --- a/includes/external/addressbook/twitter-tag-to-id.js +++ b/includes/external/addressbook/twitter-tag-to-id.js @@ -29,6 +29,8 @@ function sleep(ms) { Authorization: `Bearer ${app.twitter.bearer}` } })).data.data[0].id); - } catch (e) {} + } catch (e) { + console.error(e); + } } })();
\ No newline at end of file diff --git a/includes/luna.php b/includes/luna.php index ceb9266..4033a9e 100644 --- a/includes/luna.php +++ b/includes/luna.php @@ -15,6 +15,6 @@ file_get_contents('https://' . $ntfy["server"] . '/' . $ntfy["topic"], false, st "Title: " . formatPonypush("⚠️ Luna is out of support") . "\r\n" . "Tags: reminder\r\n" . "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), - 'content' => formatPonypush("Luna is now out of support on Windows, Linux, macOS, Chrome OS and Android. It is recommended that you uninstall the application before the servers are disabled later this summer.") + 'content' => formatPonypush("Luna is now out of support on Windows, Linux, macOS, Chrome OS and Android. It is recommended that you uninstall the application before the servers are disabled on July 1st.") ] ]));
\ No newline at end of file diff --git a/includes/pages.json b/includes/pages.json index 4753214..9cb2bf5 100644 --- a/includes/pages.json +++ b/includes/pages.json @@ -15,7 +15,7 @@ }, "computers": { "name": { - "en": "Devices" + "en": "Devices [EOL]" }, "admin": true, "limited": false @@ -55,9 +55,16 @@ "admin": true, "limited": true }, + "evening": { + "name": { + "en": "Evening schedule" + }, + "admin": true, + "limited": true + }, "fronting": { "name": { - "en": "Front planner" + "en": "Front planner [EOL]" }, "admin": true, "limited": true diff --git a/includes/util/functions.inc b/includes/util/functions.inc index e64bc5a..ad54706 100644 --- a/includes/util/functions.inc +++ b/includes/util/functions.inc @@ -5,6 +5,18 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/bitset.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/homepage.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/random.inc"; +if (!function_exists("getLastFronted")) { + function getLastFronted($members, $id) { + foreach ($members as $member) { + if ($member["id"] === $id) { + return $member["_lastFronted"]; + } + } + + return -1; + } +} + if (!function_exists("createJob")) { function createJob($title, $options) { $job = [ diff --git a/pages/api/computer.php b/pages/api/computer.php index 7dce4b6..2c75183 100644 --- a/pages/api/computer.php +++ b/pages/api/computer.php @@ -1,5 +1,7 @@ <?php +if (time() >= 1688169600) die(); + if (isset($_GET["chrome"])) { header("Access-Control-Allow-Origin: chrome-extension://" . preg_replace("/[^a-z]/m", "", $_GET["chrome"])); header("Access-Control-Allow-Credentials: true"); diff --git a/pages/api/computername.php b/pages/api/computername.php index 1a719b0..477a8e6 100644 --- a/pages/api/computername.php +++ b/pages/api/computername.php @@ -1,5 +1,7 @@ <?php +if (time() >= 1688169600) die(); + require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; if (!$isLoggedIn) header("Location: /-/login") and die(); diff --git a/pages/computers.inc b/pages/computers.inc index 643fe87..55d8ec5 100644 --- a/pages/computers.inc +++ b/pages/computers.inc @@ -1,5 +1,9 @@ <?php +if (time() >= 1688169600) { + peh_error("Page not found: computers", 404); +} + require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; global $pagename; global $_USER; global $_PROFILE; $computer = []; $parts = explode("/", $pagename); @@ -897,7 +901,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; <p>Click on a device to view information about it</p> <div class="alert alert-warning"> - <b>Luna and the Cold Haze Devices software are deprecated.</b> These applications are now deprecated and monitoring devices through Luna is not supported anymore. Basic support and servers will be shut down in August 2023. + <b>Luna and the Cold Haze Devices software are deprecated.</b> These applications are now deprecated and monitoring devices through Luna is not supported anymore. Basic support and servers will be shut down on July 1<sup>st</sup>. </div> <ul class="list-group"> diff --git a/pages/evening.inc b/pages/evening.inc new file mode 100644 index 0000000..6f9e7b8 --- /dev/null +++ b/pages/evening.inc @@ -0,0 +1,262 @@ +<?php + +$emergencyHeader = true; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; + +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json", "[]"); + +$pairs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/pairs.json"), true); +$ignored = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json"), true); + +if (isset($_GET["ignore"]) && isset($_GET["day"])) { + if ($_GET["ignore"] === "1") { + if (preg_match("/^\d{4}-\d{2}-\d{2}$/m", $_GET["day"]) === false) { + header("Location: /-/evening"); + die(); + } + + if (!in_array($_GET["day"], $ignored)) { + $ignored[] = $_GET["day"]; + } + + if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"); + + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json", json_encode($ignored)); + header("Location: /-/evening"); + die(); + } elseif ($_GET["ignore"] === "0") { + if (preg_match("/^\d{4}-\d{2}-\d{2}$/m", $_GET["day"]) === false) { + header("Location: /-/evening"); + die(); + } + + if (in_array($_GET["day"], $ignored)) { + unset($ignored[array_search($_GET["day"], $ignored)]); + } + + if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"); + + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/evening/ignored.json", json_encode($ignored)); + header("Location: /-/evening"); + die(); + } + + die(); +} + +require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; + +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json", "{}"); +$cache = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json"), true); + +if (!isset($cache["content"]) || date('Y-m-d') !== $cache["day"]) { + ob_start(); + + $members = $members = [ + ...array_map(function ($i) { + $system = "ynmuc"; + $i["_lastFronted"] = -1; + $id = $i["id"]; + $memberData = $i; + + $fronters = array_map(function ($item) { + return $item["id"]; + }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]); + + if (in_array($id, $fronters)) { + $i["_lastFronted"] = time(); + } else { + $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true); + + $thisMember = array_filter($switches, function ($item) use ($memberData) { + return in_array($memberData["id"], $item["members"]); + }); + + $thisMember = array_values($thisMember); + $frontingEnd = null; + + if (count($thisMember) > 0) { + $thisIndex = array_search($thisMember[0], $switches); + + $frontingStart = $thisMember[0]; + $frontingEnd = $switches[$thisIndex - 1]; + } + + if ($frontingEnd !== null && isset($frontingStart)) { + $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]); + } + } + + return $i; + }, array_values(array_filter(scoreOrderGlobal(), function ($i) { + return $i["_system"] === "ynmuc"; + }))), + ...array_map(function ($i) { + $system = "gdapd"; + $i["_lastFronted"] = -1; + $id = $i["id"]; + $memberData = $i; + + $fronters = array_map(function ($item) { + return $item["id"]; + }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/fronters.json"), true)["members"]); + + if (in_array($id, $fronters)) { + $i["_lastFronted"] = time(); + } else { + $switches = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system/switches.json"), true); + + $thisMember = array_filter($switches, function ($item) use ($memberData) { + return in_array($memberData["id"], $item["members"]); + }); + + $thisMember = array_values($thisMember); + $frontingEnd = null; + + if (count($thisMember) > 0) { + $thisIndex = array_search($thisMember[0], $switches); + + $frontingStart = $thisMember[0]; + $frontingEnd = $switches[$thisIndex - 1]; + } + + if ($frontingEnd !== null && isset($frontingStart)) { + $i["_lastFronted"] = strtotime($frontingEnd["timestamp"]); + } + } + + return $i; + }, array_values(array_filter(scoreOrderGlobal(), function ($i) { + return $i["_system"] === "gdapd"; + }))) + ]; + + ?> + +<style> + @media (max-width: 767px) { + .member-name, .member-list-separator { + display: none; + } + + .member-collection { + width: 100%; + text-align: center; + } + } + + .member-link:hover { + opacity: .75; + } +</style> + +<br> +<div class="container"> + <div> + <h2><?= $pages["evening"]["name"][$lang["_name"]] ?><?= time() >= 1686787200 ? "" : " (Beta)" ?></h2> + + <div class="alert alert-warning"> + <b>The evening schedule will replace the fronting schedule starting June 15<sup>th</sup>.</b> The fronting schedule page contains more information and shows the schedule up to that date. The evening schedule is experimental until then. + </div> + + <details> + <summary style="list-style: none; outline: none; cursor: text;"> + <p>Click on the "Ignore" button to mark an evening as ignored and shift the schedule one day after. You can revert this by clicking on "Unignore".</p> + </summary> + <ul> + <?php usort($pairs, function ($a, $b) use ($members) { + $times = []; + + foreach ($a[0] as $id) { + $times[] = getLastFronted($members, $id); + } + foreach ($a[1] as $id) { + $times[] = getLastFronted($members, $id); + } + + $timeA = time() - min(...$times); + $times = []; + + foreach ($b[0] as $id) { + $times[] = getLastFronted($members, $id); + } + foreach ($b[1] as $id) { + $times[] = getLastFronted($members, $id); + } + + $timeB = time() - min(...$times); + + return $timeB - $timeA; + }); $pairs = array_values($pairs); foreach ($pairs as $pair): $times = []; ?> + <li> + <?php foreach ($pair[0] as $id): ?> + <img style="width: 24px;" src="<?= getAsset("ynmuc", $id) ?>"> <?= getMemberWithoutSystem($id)["display_name"] ?> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + with + <?php foreach ($pair[1] as $id): ?> + <img style="width: 24px;" src="<?= getAsset("gdapd", $id) ?>"> <?= getMemberWithoutSystem($id)["display_name"] ?> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + (<?= time() - max(...$times) ?>) + </li> + <?php endforeach; ?> + </ul> + </details> + + <?php $listI = 0; for ($i = 0; $i < 15; $i++): $pair = $pairs[$listI]; if (time() + 86400 * $i >= 1686787200): ?> + <h4><?= date('l j', time() + 86400 * $i) ?></h4> + <div style="display: grid; grid-template-columns: repeat(2, 1fr) 100px 100px; grid-gap: 20px; margin-bottom: 10px;"> + <div style="display: flex; align-items: center;<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>opacity: .75; filter: saturate(0);<?php endif; ?>"> + <div class="member-collection"> + <?php foreach ($pair[0] as $id): ?> + <a class="member-link" href="/<?= getMemberWithoutSystem($id)["name"] ?>"><img style="width: 24px;" src="<?= getAsset("ynmuc", $id, "heads") ?>"> <span class="member-name" style="<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>text-decoration: line-through;<?php endif; ?>"><?= getMemberWithoutSystem($id)["display_name"] ?></span></a><br class="member-list-separator"> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + </div> + </div> + <div style="display: flex; align-items: center;<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>opacity: .75; filter: saturate(0);<?php endif; ?>"> + <div class="member-collection"> + <?php foreach ($pair[1] as $id): ?> + <a class="member-link" href="/<?= getMemberWithoutSystem($id)["name"] ?>"><img style="width: 24px;" src="<?= getAsset("gdapd", $id, "heads") ?>"> <span class="member-name" style="<?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?>text-decoration: line-through;<?php endif; ?>"><?= getMemberWithoutSystem($id)["display_name"] ?></span></a><br class="member-list-separator"> + <?php $times[] = getLastFronted($members, $id); endforeach; ?> + </div> + </div> + <div style="display: flex; align-items: center; justify-content: center;"> + <?php + + $times = []; + + foreach ($pair[0] as $id) { + $times[] = getLastFronted($members, $id); + } + foreach ($pair[1] as $id) { + $times[] = getLastFronted($members, $id); + } + + $time = time() - min(...$times); + echo(timeAgo(time() - $time)); + + ?> + </div> + <div style="display: flex; align-items: center; justify-content: center;"> + <?php if (in_array(date('Y-m-d', time() + 86400 * $i), $ignored)): ?> + <a href="?ignore=0&day=<?= date('Y-m-d', time() + 86400 * $i) ?>" class="btn btn-outline-success">Unignore</a> + <?php else: ?> + <a href="?ignore=1&day=<?= date('Y-m-d', time() + 86400 * $i) ?>" class="btn btn-outline-danger">Ignore</a> + <?php endif; ?> + </div> + </div> + <?= $i < 14 ? "<hr>" : "" ?> + <?php endif; if (!in_array(date('Y-m-d', time() + 86400 * $i), $ignored)) $listI++; if ($listI === count($pairs)) $listI = 0; endfor; ?> + </div> +</div> +<?php + + $cache["content"] = ob_get_contents(); + $cache["day"] = date('Y-m-d'); + ob_end_clean(); +} + +echo($cache["content"]); +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/evening.json", json_encode($cache)); + +?> + +<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?> diff --git a/pages/fronting.inc b/pages/fronting.inc index 9873b81..1c16a80 100644 --- a/pages/fronting.inc +++ b/pages/fronting.inc @@ -1,7 +1,8 @@ <?php if (time() >= 1686787200) { - peh_error("Page not found: fronting", 404); + header("Location: /evening"); + die(); } require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; |