X-Git-Url: http://git.shiar.net/minimedit.git/blobdiff_plain/8fd22c9ade887e18e01dafd8a24842f6cfdc93ab..f316947b98249a964b814d65377efda2405e2de1:/format.inc.php diff --git a/format.inc.php b/format.inc.php index 10908f3..74d53e3 100644 --- a/format.inc.php +++ b/format.inc.php @@ -14,3 +14,21 @@ function showdate($parts) ])); } +function showsize($bytes) +{ + $units = ['', 'k', 'M', 'G', 'T']; + $log = strlen($bytes) - 1; + $order = floor($log / 3); + if (!isset($units[$order])) return $bytes; + return implode(' ', [ + number_format($bytes / (1000 ** $order), $log % 3 ? 0 : 1, ',', ''), + $units[$order], + ]); +} + +function showlink($title, $href) +{ + return empty($href) ? $title : + sprintf('%s', $href, $title); +} +