A lot of code cleanup and code sanitation done.

This commit is contained in:
2026-06-20 00:31:32 +02:00
parent be392b8149
commit d781078c0d
100 changed files with 733 additions and 2097 deletions

View File

@@ -1,13 +1,5 @@
<?php
function setResponse($type, $text)
{
$value = json_encode([$type => $text]);
$_SESSION['response'] = $value;
header('location: ' . $_SERVER['HTTP_REFERER']);
exit;
}
function checkIfUser()
function checkIfUser(): bool
{
if ($_SESSION['user']['user_group_type'] == 'user') {
return true;
@@ -19,25 +11,31 @@ function checkIfUser()
function showTime($timestamp)
{
if (empty($timestamp)) {
echo __('never');
return;
return __('never');
}
$dt = new DateTime("@$timestamp");
$dt->setTimezone(new DateTimeZone($_SESSION['user']['user_timezone']));
try {
$dt = new DateTime("@$timestamp");
echo $dt->format('Y-m-d H:i:s');
$timezone = $_SESSION['user']['user_timezone'] ?? 'UTC';
$dt->setTimezone(new DateTimeZone($timezone));
return $dt->format('Y-m-d H:i:s');
} catch (DateInvalidTimeZoneException) {
return __('invalid_date');
}
}
function human_filesize($bytes, $decimals = 2)
function human_filesize($bytes, $decimals = 2): string
{
$sizes = ['B', 'K', 'M', 'G', 'T', 'P']; // Array instead of string
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sizes[$factor];
}
function retrieveAvailableLocales()
function retrieveAvailableLocales(): array
{
$availableLocales = array();
$localeDir = $_SERVER['DOCUMENT_ROOT'] . "/bin/locales/";
@@ -58,10 +56,7 @@ function getPreferredLocale()
$availableLocales = retrieveAvailableLocales();
$defaultLocale = 'en';
$selectedLocale = in_array($_SESSION['user']['user_pref_language'], $availableLocales)
? $_SESSION['user']['user_pref_language']
: $defaultLocale;
return $selectedLocale;
return in_array($_SESSION['user']['user_pref_language'], $availableLocales) ? $_SESSION['user']['user_pref_language'] : $defaultLocale;
}
function __(string $key, array $replacements = [])
@@ -72,13 +67,13 @@ function __(string $key, array $replacements = [])
// Replace placeholders with dynamic values
foreach ($replacements as $placeholder => $value) {
$translation = str_replace(":{$placeholder}", $value, $translation);
$translation = str_replace(":$placeholder", $value, $translation);
}
return $translation;
}
function get_enabled_platforms($conn)
function get_enabled_platforms($conn): array
{
$platforms_enabled = [];
$query = "SELECT * FROM autop_platforms WHERE platform_enabled = 1";
@@ -98,7 +93,7 @@ function get_enabled_platforms($conn)
return $platforms_enabled;
}
function getEnabledModules()
function getEnabledModules(): array
{
$modules_enabled = [];
$query = "SELECT * FROM system_modules";
@@ -116,7 +111,7 @@ function getEnabledModules()
}
function returnServerStateColor($serverState)
function returnServerStateColor($serverState): string
{
$server_state_color = 'secondary';
if (strlen($serverState) > 0) {