login/pass: error messages below page title
[minimedit.git] / format.inc.php
index 10908f3893afa07cfa09d9e176254ac27fbcf308..74d53e3fe833e5d6b3a6144084975cc61a8e8ab5 100644 (file)
@@ -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('<a href="%s">%s</a>', $href, $title);
+}
+