login/pass: error messages below page title
[minimedit.git] / format.inc.php
1 <?php
2 global $monthname;
3 $monthname = ['?',
4         'januari', 'februari', 'maart', 'april', 'mei', 'juni',
5         'juli', 'augustus', 'september', 'oktober', 'november', 'december',
6 ];
7
8 function showdate($parts)
9 {
10         global $monthname;
11         return implode(' ', array_filter([
12                 intval(@$parts[2]), $parts[1] > 0 ? $monthname[intval($parts[1])] : '', $parts[0],
13                 count($parts) > 5 ? "$parts[3]:$parts[4]" : '',
14         ]));
15 }
16
17 function showsize($bytes)
18 {
19         $units = ['', 'k', 'M', 'G', 'T'];
20         $log = strlen($bytes) - 1;
21         $order = floor($log / 3);
22         if (!isset($units[$order])) return $bytes;
23         return implode('&thinsp;', [
24                 number_format($bytes / (1000 ** $order), $log % 3 ? 0 : 1, ',', ''),
25                 $units[$order],
26         ]);
27 }
28
29 function showlink($title, $href)
30 {
31         return empty($href) ? $title :
32                 sprintf('<a href="%s">%s</a>', $href, $title);
33 }
34