diff options
Diffstat (limited to 'pages/stats.inc')
-rw-r--r-- | pages/stats.inc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/pages/stats.inc b/pages/stats.inc index de501bb..742fb87 100644 --- a/pages/stats.inc +++ b/pages/stats.inc @@ -3,8 +3,9 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc'; -$switchesRaindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/switches.json"), true); -$switchesCloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/switches.json"), true); +if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/stats.json")) file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/stats.json", "{}"); + +$cache = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/stats.json"), true); ?> @@ -16,6 +17,11 @@ $switchesCloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . <h2>Statistics</h2> <?php + if (!isset($cache["content"]) || date('Y-m-d') !== $cache["day"]): ob_start(); + + $switchesRaindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/switches.json"), true); + $switchesCloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/switches.json"), true); + $weeks = []; $weeksRectified = []; @@ -486,6 +492,12 @@ $switchesCloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . } }); </script> + <?php $cache["content"] = ob_get_contents(); $cache["day"] = date('Y-m-d'); ob_end_clean(); endif; + + echo($cache["content"]); + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/stats.json", json_encode($cache)); + + ?> </div> </div> |