Skip to content

Commit

Permalink
-> Push removed github cache due to a lot of errors
Browse files Browse the repository at this point in the history
-> Bump translations
-> Added notifications
-> Made it so you can now select a timezone from settings so it will get the date by the timezone
-> Added sidebar links
-> Added a easter egg inside the cli for kids that use dumps :)
-> Optimized how everything works
-> Now it displays what languages you have installed on your system!
-> Now you can see the current selected language and timezone!
  • Loading branch information
NaysKutzu committed Feb 28, 2024
1 parent 2a04b32 commit 5d3f301
Show file tree
Hide file tree
Showing 30 changed files with 706 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ migrates.ini
/mythicaldash_backup.sql
public/FIRST_INSTALL
public/FIRST_USER
/caches/notifications.json
33 changes: 31 additions & 2 deletions app/Database/Connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ public function connectToDatabase() {

return $conn;
}

public static function getUserInfo(string $userToken, string $info) {
/**
* Get some information from the user database
*
* @param string $userToken The user api key :)
* @param string $info The info you want to get :)
*
* @return string The info that you wanted
*/
public static function getUserInfo(string $userToken, string $info) : string {
$connclass = new Connect();
$conn = $connclass->connectToDatabase();
$session_id = mysqli_real_escape_string($conn, $userToken);
Expand All @@ -40,7 +47,29 @@ public static function getUserInfo(string $userToken, string $info) {
} else {
return null;
}
}
/**
* Get server info from the database
*
* @param string $pid The server id from panel
* @param string $info What you want to get
*
* @return string The info you wanted :)
*/
public static function getServerInfo(string $pid, string $info) : string {
$connclass = new Connect();
$conn = $connclass->connectToDatabase();
$session_id = mysqli_real_escape_string($conn, $pid);
$safeInfo = $conn->real_escape_string($info);
$query = "SELECT `$safeInfo` FROM mythicaldash_servers WHERE pid='$session_id' LIMIT 1";
$result = $conn->query($query);

if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
return $row[$info];
} else {
return null;
}
}
}
?>
33 changes: 14 additions & 19 deletions app/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use Symfony\Component\Yaml\Yaml;
use MythicalDash\SettingsManager;
use DateTimeZone;

class Main
{
public static function isHTTPS()
Expand All @@ -12,19 +14,21 @@ public static function isHTTPS()
}
return false;
}
public static function generatePassword($length = 12) {
public static function generatePassword($length = 12)
{
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";
$password = "";

$charArrayLength = strlen($chars) - 1;

for ($i = 0; $i < $length; $i++) {
$password .= $chars[mt_rand(0, $charArrayLength)];
}

return $password;
}
public static function getAppUrl() {
public static function getAppUrl()
{
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://';
$host = $_SERVER['HTTP_HOST'];
$url = $protocol . $host . $_SERVER['REQUEST_URI'];
Expand All @@ -36,26 +40,17 @@ public static function getAppUrl() {
*
* @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();
public static function getLatestReleaseInfo()
{
$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()
{
Expand Down
193 changes: 193 additions & 0 deletions app/NotificationHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?php
namespace MythicalDash;

class NotificationHandler
{
/**
* Get notifications from the JSON file.
*
* @return array
*/
private static function getNotifications(): array
{
$file = '../caches/notifications.json';
if (file_exists($file)) {
$data = file_get_contents($file);
return json_decode($data, true);
} else {
return [];
}
}

/**
* Save notifications to the JSON file.
*
* @param array $notifications
*
* @return void
*/
private static function saveNotifications(array $notifications): void
{
$file = '../caches/notifications.json';
file_put_contents($file, json_encode($notifications, JSON_PRETTY_PRINT));
}

/**
* Create a new notification.
*
* @param string $user_id The user id.
* @param string $name The notification name.
* @param string $description The notification description.
*
* @return int The id of the created notification.
*/
public static function create(string $user_id, string $name, string $description): int
{
$notifications = self::getNotifications();
$notificationID = count($notifications) + 1;
$notification = [
'id' => $notificationID,
'user_id' => $user_id,
'name' => $name,
'description' => $description,
'date' => date('Y-m-d H:i'),
];

$notifications[] = $notification;
self::saveNotifications($notifications);
return $notificationID;
}

/**
* Edit an existing notification by ID.
*
* @param int $id The id of the notification to edit.
* @param string $name The new notification name.
* @param string $description The new notification description.
*
* @return void
*/
public static function edit(int $id, string $name, string $description): void
{
$notifications = self::getNotifications();

foreach ($notifications as &$notification) {
if ($notification['id'] === $id) {
$notification['name'] = $name;
$notification['description'] = $description;
break;
}
}

self::saveNotifications($notifications);
}

/**
* Delete a notification by ID.
*
* @param int $id The id of the notification to delete.
*
* @return void
*/
public static function delete(int $id): void
{
$notifications = self::getNotifications();

$notifications = array_filter($notifications, function ($notification) use ($id) {
return $notification['id'] !== $id;
});

self::saveNotifications(array_values($notifications));
}

/**
* Delete all notifications.
*
* @return void
*/
public static function deleteAll(): void
{
self::saveNotifications([]);
}

/**
* Get a single notification by ID.
*
* @param int $id The id of the notification to retrieve.
*
* @return array|null The notification data or null if not found.
*/
public static function getOne(int $id): ?array
{
$notifications = self::getNotifications();

foreach ($notifications as $notification) {
if ($notification['id'] === $id) {
return $notification;
}
}

return null;
}

/**
* Get all notifications.
*
* @return array All notifications.
*/
public static function getAll(): array
{
return self::getNotifications();
}

/**
* Get all notifications sorted by ID in descending order.
*
* @return array Sorted notifications.
*/
public static function getAllSortedById(): array
{
$notifications = self::getNotifications();

usort($notifications, function ($a, $b) {
return $b['id'] - $a['id'];
});

return $notifications;
}

/**
* Get all notifications sorted by date in descending order.
*
* @return array Sorted notifications.
*/
public static function getAllSortedByDate(): array
{
$notifications = self::getNotifications();

usort($notifications, function ($a, $b) {
return strtotime($b['date']) - strtotime($a['date']);
});

return $notifications;
}

/**
* Get notifications filtered by user ID.
*
* @param string $user_id The user id to filter by.
*
* @return array Filtered notifications.
*/
public static function getByUserId(string $user_id): array
{
$notifications = self::getNotifications();

$filteredNotifications = array_filter($notifications, function ($notification) use ($user_id) {
return $notification['user_id'] === $user_id;
});

return $filteredNotifications;
}
}
?>
13 changes: 11 additions & 2 deletions app/Pterodactyl/User.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace MythicalDash\Pterodactyl;

use MythicalDash\Pterodactyl\Connection;

class User extends Connection
{
/**
Expand Down Expand Up @@ -50,11 +52,11 @@ public static function Create(string $first_name, string $last_name, string $use
} elseif ($statusCode == 422) {
$errorResponse = json_decode($response, true);
$errorMessages = array();

foreach ($errorResponse['errors'] as $error) {
$errorMessages[] = $error['detail'];
}

return implode("|", $errorMessages);
} else {
return "Unexpected error: " . $statusCode;
Expand All @@ -72,5 +74,12 @@ public static function Delete(string $id): bool
{
return false;
}
/**
* SOON
*/
public static function Info(string $id, string $info): string
{
return "";
}
}
?>
1 change: 0 additions & 1 deletion caches/github.json

This file was deleted.

Loading

0 comments on commit 5d3f301

Please sign in to comment.