diff options
Diffstat (limited to 'pages/byspecies.inc')
-rw-r--r-- | pages/byspecies.inc | 98 |
1 files changed, 63 insertions, 35 deletions
diff --git a/pages/byspecies.inc b/pages/byspecies.inc index e3bdcc4..672493e 100644 --- a/pages/byspecies.inc +++ b/pages/byspecies.inc @@ -1,6 +1,8 @@ -<?php global $system; global $systemCommonName; global $lang; global $pages; global $systemID; $pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true); $title = $pages["s:species"]["name"][$lang["_name"]]; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; global $travelling; +<?php global $system; global $systemCommonName; global $lang; global $pages; global $systemID; $pages = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/pages.json"), true); $title = $pages["s:species"]["name"][$lang["_name"]]; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; global $travelling; global $isLowerLoggedIn; global $isLoggedIn; -$members = scoreOrderGlobal(); +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/species.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/species.json", "{}"); + +$cache = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/species.json"), true); function species(array $members, string $id, string $name) { global $systemID; global $travelling; ?> <div class="relation" style="background-color:rgba(255, 255, 255, .1);margin-bottom:10px;padding:10px;border-radius:10px;display:grid;grid-template-columns: 1fr 4fr;"> @@ -16,45 +18,71 @@ function species(array $members, string $id, string $name) { global $systemID; g </div> <?php } +function page() { global $lang; + $members = scoreOrderGlobal(); + + $earth = []; + $pegasus = []; + $unicorn = []; + $alicorn = []; + $batpony = []; + $crystal = []; + $changeling = []; + $merpony = []; + + foreach ($members as $member) { + foreach ($member["_metadata"]["species"] as $species) { + if ($species === "earth") $earth[] = $member; + if ($species === "pegasus") $pegasus[] = $member; + if ($species === "unicorn") $unicorn[] = $member; + if ($species === "alicorn") $alicorn[] = $member; + if ($species === "batpony") $batpony[] = $member; + if ($species === "crystal") $crystal[] = $member; + if ($species === "changeling") $changeling[] = $member; + if ($species === "merpony") $merpony[] = $member; + } + } + + species($earth, "earth", $lang["species"]["earth"][3]); + species($pegasus, "pegasus", $lang["species"]["pegasus"][3]); + species($unicorn, "unicorn", $lang["species"]["unicorn"][3]); + species($alicorn, "alicorn", $lang["species"]["alicorn"][3]); + species($batpony, "batpony", $lang["species"]["batpony"][3]); + species($crystal, "crystal", $lang["species"]["crystal"][3]); + species($changeling, "changeling", "Changelings"); + species($merpony, "merpony", "Merponies"); +} + ?> <br> <div class="container" id="page-content"> - <h2><?= str_replace("%1", "All", $lang["species_compare"]["title"]) ?></h2> - <?php - - $earth = []; - $pegasus = []; - $unicorn = []; - $alicorn = []; - $batpony = []; - $crystal = []; - $changeling = []; - $merpony = []; - - foreach ($members as $member) { - foreach ($member["_metadata"]["species"] as $species) { - if ($species === "earth") $earth[] = $member; - if ($species === "pegasus") $pegasus[] = $member; - if ($species === "unicorn") $unicorn[] = $member; - if ($species === "alicorn") $alicorn[] = $member; - if ($species === "batpony") $batpony[] = $member; - if ($species === "crystal") $crystal[] = $member; - if ($species === "changeling") $changeling[] = $member; - if ($species === "merpony") $merpony[] = $member; - } - } + <h2>Members by species</h2> + <?php if (!isset($cache["private"]) || !isset($cache["public"])) { + ob_start(); + $isLoggedInOldState = $isLoggedIn; + $isLowerLoggedInOldState = $isLowerLoggedIn; + $isLoggedIn = true; + $isLowerLoggedIn = true; + page(); + $isLoggedIn = $isLoggedInOldState; + $isLowerLoggedIn = $isLowerLoggedInOldState; + $cache["private"] = ob_get_contents(); + ob_end_clean(); - ?> + ob_start(); + $isLoggedInOldState = $isLoggedIn; + $isLowerLoggedInOldState = $isLowerLoggedIn; + $isLoggedIn = false; + $isLowerLoggedIn = false; + page(); + $isLoggedIn = $isLoggedInOldState; + $isLowerLoggedIn = $isLowerLoggedInOldState; + $cache["public"] = ob_get_contents(); + ob_end_clean(); + } - <?php species($earth, "earth", $lang["species"]["earth"][3]); ?> - <?php species($pegasus, "pegasus", $lang["species"]["pegasus"][3]); ?> - <?php species($unicorn, "unicorn", $lang["species"]["unicorn"][3]); ?> - <?php species($alicorn, "alicorn", $lang["species"]["alicorn"][3]); ?> - <?php species($batpony, "batpony", $lang["species"]["batpony"][3]); ?> - <?php species($crystal, "crystal", $lang["species"]["crystal"][3]); ?> - <?php species($changeling, "changeling", "Changelings"); ?> - <?php species($merpony, "merpony", "Merponies"); ?> + echo($isLoggedIn ? $cache["private"] : $cache["public"]); file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/species.json", json_encode($cache)); ?> </div> <?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/footer.inc'; ?>
\ No newline at end of file |