Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Trying to add a langauge system
  • Loading branch information
NaysKutzu committed Nov 23, 2023
1 parent f42c05e commit d5f6aec
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ migrates.ini
/logs/*.txt
/cli/logs
/public/pma.zip
/cli/*.yml
/cli/*.yml
/caches/github.json
46 changes: 46 additions & 0 deletions app/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
?>
1 change: 1 addition & 0 deletions caches/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not delete this plz!
3 changes: 2 additions & 1 deletion cli/scripts/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public static void CreateConfig()
{"debug", "false"},
{"silent_debug", "false"},
{"encryptionkey", "<keyhere>"},
{"disable_console", "false"}
{"disable_console", "false"},
{"lang", "en_US"}
}
},
{"database", new YamlMappingNode
Expand Down
12 changes: 10 additions & 2 deletions cli/scripts/SettingsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -223,7 +232,6 @@ public void DisableAntiVPN()
{
Program.logger.Log(LogType.Error, "It looks like the config file does not exist!");
}

}
public void DisableTurnstile()
{
Expand Down
Empty file added lang/en_US.php
Empty file.
9 changes: 2 additions & 7 deletions view/admin/health.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@
<h4 class="fw-bold py-3 mb-4"><span class="text-muted fw-light">Admin /</span> Health</h4>
<?php include(__DIR__ . '/../components/alert.php') ?>
<?php
$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);
$data = json_decode($response, true);

$data = Main::getLatestReleaseInfo();
if ($data && isset($data['tag_name'])) {
$latestVersion = $data['tag_name'];
$pr = $data['prerelease'];
Expand Down
9 changes: 2 additions & 7 deletions view/admin/main.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use MythicalDash\SettingsManager;
use MythicalDash\Main;

include(__DIR__ . '/../requirements/page.php');
include(__DIR__ . '/../requirements/admin.php');
Expand Down Expand Up @@ -53,13 +54,7 @@
<h4 class="fw-bold py-3 mb-4"><span class="text-muted fw-light">Admin /</span> Statistics</h4>
<?php include(__DIR__ . '/../components/alert.php') ?>
<?php
$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);
$data = json_decode($response, true);
$data = Main::getLatestReleaseInfo();
if ($data && isset($data['tag_name'])) {
$latestVersion = $data['tag_name'];
$pr = $data['prerelease'];
Expand Down

0 comments on commit d5f6aec

Please sign in to comment.