]>
Commit | Line | Data |
---|---|---|
997305cf JP |
1 | <?php |
2 | ||
3 | ## FORMATTING FUNCTIONS | |
4 | ||
5 | function sprintSize($bytes, $float=2) { | |
6 | if (is_null($bytes)) return null; | |
7 | $kb = round($bytes / 1024, $float); | |
8 | $mb = round($bytes / 1024 / 1024, $float); | |
9 | $gb = round($bytes / 1024 / 1024 / 1024, $float); | |
10 | ||
11 | return ($bytes<1||$kb<1?$bytes.' B':($mb<1?$kb.' KB':($gb<1?$mb.' MB':$gb.' GB'))); | |
12 | } | |
13 | ||
14 | function sprintTS($timestamp) { | |
15 | return substr($timestamp,0,4). | |
16 | '-'.substr($timestamp,4,2). | |
17 | '-'.substr($timestamp,6,2). | |
18 | ' '.substr($timestamp,8,2). | |
19 | ':'.substr($timestamp,10,2). | |
20 | ':'.substr($timestamp,12,2); | |
21 | } | |
22 | ||
88b7d384 JP |
23 | function printBar($percent, $txt1 = '', $txt2 = '') { |
24 | $color1 = 'black'; | |
25 | $color2 = 'white'; | |
26 | $color3 = 'white'; | |
27 | $color4 = 'black'; | |
9c70b481 | 28 | /* if ($percent>1) { |
88b7d384 | 29 | $percent = $percent/100; |
9c70b481 | 30 | } |
88b7d384 JP |
31 | } elseif (!is_integer($percent) && $percent<2) { |
32 | $percent = $percent*100; | |
33 | } elseif ($percent == 1) { | |
34 | $percent = 100; | |
35 | } */ | |
9c70b481 JP |
36 | $per1 = $per2 = floor($percent*100); |
37 | if ($per1>100) { | |
38 | $per1 = 100; | |
39 | $per2 = 0; | |
40 | } else { | |
41 | $per2 = 100 - $per2; | |
42 | } | |
88b7d384 JP |
43 | $per1 .= "%"; |
44 | $per2 .= "%"; | |
9c70b481 | 45 | /* return '<table cellpadding=0 cellspacing=0 width="100%" class="bargraph"> |
88b7d384 JP |
46 | <tr> |
47 | <td class="bar" align="left" width="'.$per1.'"><div style="position: relative;"><div style="left: 0; display: inline; position: absolute;"> '.$txt1.' </div> </div></td> | |
9c70b481 JP |
48 | <td class="fill" align="left" width="'.$per2.'"><div style="position: relative;"> <div style="right: 0; display: inline; position: absolute;">'.$txt2.' <em>'.$per1.'</em></div></div></td> |
49 | </tr></table>';*/ | |
50 | return '<table cellpadding=0 cellspacing=0 width="100%" class="bargraph"> | |
51 | <tr> | |
52 | <td class="bar" align="left" width="'.$per1.'"><div style="position: relative;"></div></td> | |
53 | <td class="fill" align="right" width="'.$per2.'"><div style="position: relative;"></div></td> | |
54 | </tr> | |
55 | </table><table cellpadding=0 cellspacing=0 width="100%"> | |
56 | <tr style="height: 1px;"> | |
57 | <td class="bar" align="left" width="50%"><div style="position: relative;"><div style="bottom: 3px; left: 5px; position: absolute;">'.$txt1.'</div></div></td> | |
58 | <td class="fill" align="right" width="50%"><div style="position: relative;"><div style="bottom: 3px; right: 3px; position: absolute;">'.$txt2.' <em>'.$per1.'</em></div></div></td> | |
59 | </tr> | |
60 | </table>'; | |
88b7d384 JP |
61 | } |
62 | ||
6e7cd1d3 JP |
63 | function chars_encode($string) { |
64 | $chars = array(); | |
65 | $ent = null; | |
66 | $chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); | |
67 | for ($i = 0; $i < count($chars); $i++) | |
68 | $ent[$i] = '&#' . ord($chars[$i]) . ';'; | |
69 | if (sizeof($ent) < 1) return ''; | |
70 | return implode('',$ent); | |
71 | } | |
72 | ||
997305cf | 73 | ?> |