diff options
Diffstat (limited to 'lib/helper')
-rw-r--r-- | lib/helper/FilesHelper.php | 27 | ||||
-rw-r--r-- | lib/helper/SortHeaderHelper.php | 21 |
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/helper/FilesHelper.php b/lib/helper/FilesHelper.php new file mode 100644 index 0000000..ff290d6 --- /dev/null +++ b/lib/helper/FilesHelper.php @@ -0,0 +1,27 @@ +<?php + +function format_bytes($val, $digits = 3, $mode = "SI", $bB = "B") +{ + $si = array("", "k", "M", "G", "T", "P", "E", "Z", "Y"); + $iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"); + + switch(strtoupper($mode)) + { + case "SI" : $factor = 1000; $symbols = $si; break; + case "IEC" : $factor = 1024; $symbols = $iec; break; + default : $factor = 1000; $symbols = $si; break; + } + switch($bB) + { + case "b" : $val *= 8; break; + default : $bB = "B"; break; + } + for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++) + $val /= $factor; + $p = strpos($val, "."); + if($p !== false && $p > $digits) $val = round($val); + elseif($p !== false) $val = round($val, $digits-$p); + return round($val, $digits) . " " . $symbols[$i] . $bB; +} + +?> diff --git a/lib/helper/SortHeaderHelper.php b/lib/helper/SortHeaderHelper.php new file mode 100644 index 0000000..ef16eb1 --- /dev/null +++ b/lib/helper/SortHeaderHelper.php @@ -0,0 +1,21 @@ +<?php + +use_helper("Asset"); + +function sortheader_link_to($caption, $targetURI, $column, $headers) +{ + $uri = $targetURI."?sort=".$column; + if($headers[$column]) + $uri .= "&type=".($headers[$column]=="asc" ? "desc": "asc"); + return link_to($caption, $uri); +} + +function sortheader_type_if($column, $headers, $asc, $desc) +{ + if($headers[$column]) + { + return ($headers[$column]=="asc" ? $asc: $desc); + } +} + +?> |