mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 00:34:44 +02:00

* Update Server Listing * Update Edit/Create Server Pages Re-arrange limits, CPU->Memory->Disk * Remove auto focus its cancer on mobile... * Hide Title, Quick yaml fix * Hide columns on mobile * Hide backup locked on mobile * Fix schedules for mobile * Hide Notes on mobile * Consolidate and clean these up * Simplify * Remove unused imports * Replace tabler icon package * Update app/Filament/Server/Resources/FileResource/Pages/EditFiles.php Co-authored-by: Lance Pioch <git@lance.sh> * Allow the unit to be changed * Use existing method * Update composer and pint * Update resources/views/tables/columns/server-entry-column.blade.php Co-authored-by: Boy132 <Boy132@users.noreply.github.com> * Simplify html and add small margin * Unused * Add enum --------- Co-authored-by: Lance Pioch <git@lance.sh> Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
|
|
if (!function_exists('is_digit')) {
|
|
/**
|
|
* Deal with normal (and irritating) PHP behavior to determine if
|
|
* a value is a non-float positive integer.
|
|
*/
|
|
function is_digit(mixed $value): bool
|
|
{
|
|
return !is_bool($value) && ctype_digit(strval($value));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('is_ip')) {
|
|
function is_ip(?string $address): bool
|
|
{
|
|
return $address !== null && filter_var($address, FILTER_VALIDATE_IP) !== false;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('convert_bytes_to_readable')) {
|
|
function convert_bytes_to_readable(int $bytes, int $decimals = 2, ?int $base = null): string
|
|
{
|
|
$conversionUnit = config('panel.use_binary_prefix') ? 1024 : 1000;
|
|
$suffix = config('panel.use_binary_prefix') ? ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'] : ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
if ($bytes <= 0) {
|
|
return '0 ' . $suffix[0];
|
|
}
|
|
|
|
$fromBase = log($bytes) / log($conversionUnit);
|
|
$base ??= floor($fromBase);
|
|
|
|
return round(pow($conversionUnit, $fromBase - $base), $decimals) . ' ' . $suffix[$base];
|
|
}
|
|
}
|
|
|
|
if (!function_exists('join_paths')) {
|
|
function join_paths(string $base, string ...$paths): string
|
|
{
|
|
if ($base === '/') {
|
|
return str_replace('//', '', implode('/', $paths));
|
|
}
|
|
|
|
return str_replace('//', '', $base . '/' . implode('/', $paths));
|
|
}
|
|
}
|
|
|
|
if (!function_exists('resolve_path')) {
|
|
function resolve_path(string $path): string
|
|
{
|
|
// @phpstan-ignore-next-line
|
|
$parts = array_filter(explode('/', $path), 'strlen');
|
|
|
|
$absolutes = [];
|
|
foreach ($parts as $part) {
|
|
if ($part == '.') {
|
|
continue;
|
|
}
|
|
|
|
if ($part == '..') {
|
|
array_pop($absolutes);
|
|
} else {
|
|
$absolutes[] = $part;
|
|
}
|
|
}
|
|
|
|
return implode('/', $absolutes);
|
|
}
|
|
}
|