diff --git a/.gitignore b/.gitignore index 65acb34a..2b46eb55 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ migrates.ini /logs/*.txt /cli/logs /public/pma.zip -/cli/*.yml \ No newline at end of file +/cli/*.yml +/caches/github.json diff --git a/app/Main.php b/app/Main.php index 5e02418e..7b773fd5 100644 --- a/app/Main.php +++ b/app/Main.php @@ -28,7 +28,53 @@ public static function getAppUrl() { $url = $protocol . $host . $_SERVER['REQUEST_URI']; return $url; } + + /** + * Get info from our github api + * + * @return string The json file + */ + public static function getLatestReleaseInfo() { + $cacheFile = '../caches/github.json'; + $cacheDuration = 15 * 60; + + if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheDuration) { + $cachedData = file_get_contents($cacheFile); + return json_decode($cachedData, true); + } else { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "https://api.github.com/repos/mythicalltd/mythicaldash/releases/latest"); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['User-Agent: MythicalDash']); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $response = curl_exec($ch); + curl_close($ch); + file_put_contents($cacheFile, $response); + return json_decode($response, true); + } + } + + public static function getLang() + { + $langConfig = ConfigHandler::get("app", "lang"); + + if ($langConfig == null) { + self::handleLanguageError("Failed to start the dash. Please use a valid language file."); + } else { + $langFilePath = __DIR__ . '/../lang/' . $langConfig . '.php'; + + if (file_exists($langFilePath)) { + return include($langFilePath); + } else { + self::handleLanguageError("Failed to start the dash. Please use a valid language file."); + } + } + } + private static function handleLanguageError($errorMessage) + { + ErrorHandler::ShowCritical($errorMessage); + die(); + } } ?> \ No newline at end of file diff --git a/caches/README b/caches/README new file mode 100644 index 00000000..63c8f2fa --- /dev/null +++ b/caches/README @@ -0,0 +1 @@ +Do not delete this plz! \ No newline at end of file diff --git a/cli/scripts/ConfigHandler.cs b/cli/scripts/ConfigHandler.cs index e42b7aff..65c98907 100644 --- a/cli/scripts/ConfigHandler.cs +++ b/cli/scripts/ConfigHandler.cs @@ -30,7 +30,8 @@ public static void CreateConfig() {"debug", "false"}, {"silent_debug", "false"}, {"encryptionkey", ""}, - {"disable_console", "false"} + {"disable_console", "false"}, + {"lang", "en_US"} } }, {"database", new YamlMappingNode diff --git a/cli/scripts/SettingsHandler.cs b/cli/scripts/SettingsHandler.cs index ef1dc24e..0b9dea95 100644 --- a/cli/scripts/SettingsHandler.cs +++ b/cli/scripts/SettingsHandler.cs @@ -85,7 +85,16 @@ public void Setup() Program.logger.Log(LogType.Error, "It looks like the config file does not exist!"); } } - + public void setLang(string lang) { + if (fm.ConfigExists() == true) + { + + } + else + { + Program.logger.Log(LogType.Error, "It looks like the config file does not exist!"); + } + } public void SetMaintenance(bool status) { try @@ -223,7 +232,6 @@ public void DisableAntiVPN() { Program.logger.Log(LogType.Error, "It looks like the config file does not exist!"); } - } public void DisableTurnstile() { diff --git a/lang/en_US.php b/lang/en_US.php new file mode 100644 index 00000000..e69de29b diff --git a/view/admin/health.php b/view/admin/health.php index 476228aa..9e36eecf 100644 --- a/view/admin/health.php +++ b/view/admin/health.php @@ -53,13 +53,8 @@

Admin / Health

Admin / Statistics