From e5ea0a3daa307d6df6c864d13adcf733a286213e Mon Sep 17 00:00:00 2001 From: Jakob Sack Date: Wed, 2 Mar 2011 22:28:32 +0100 Subject: [PATCH] Added helper for filesize, fixed wrong name for mimetypeIcon() --- lib/helper.php | 24 +++++++++++++++++++++++- lib/template.php | 14 ++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/helper.php b/lib/helper.php index 085ab67e737..5999c33a458 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -60,7 +60,7 @@ class OC_HELPER { * show an icon for a filetype * */ - public static function showIcon( $mimetype ){ + public static function mimetypeIcon( $mimetype ){ global $SERVERROOT; global $WEBROOT; // Replace slash with a minus @@ -79,6 +79,28 @@ class OC_HELPER { return "$WEBROOT/img/mimetypes/application-octet-stream.png"; } } + + /** + * Human filesize (1 kB for 1024 etc. ) + * + */ + public static function humanFileSize( $bytes ){ + if( $bytes < 1024 ){ + return "$bytes B"; + } + $bytes = round( $bytes / 1024, 1 ); + if( $bytes < 1024 ){ + return "$bytes kB"; + } + $bytes = round( $bytes / 1024, 1 ); + if( $bytes < 1024 ){ + return "$bytes MB"; + } + + // Wow, heavy duty for owncloud + $bytes = round( $bytes / 1024, 1 ); + return "$bytes GB"; + } } ?> diff --git a/lib/template.php b/lib/template.php index efa8dde8b9d..bdb2ebab03b 100644 --- a/lib/template.php +++ b/lib/template.php @@ -37,6 +37,20 @@ function image_path( $app, $file ){ return OC_HELPER::imagePath( $app, $file ); } +/** + * + */ +function mimetype_icon( $mimetype ){ + return OC_HELPER::mimetypeIcon( $app, $file ); +} + +/** + * + */ +function human_file_size( $bytes ){ + return OC_HELPER::humanFileSize( $bytes ); +} + class OC_TEMPLATE{ private $renderas; // Create a full page? private $application; // template Application -- 2.39.5