]> source.dussan.org Git - nextcloud-server.git/commitdiff
Added helper for filesize, fixed wrong name for mimetypeIcon()
authorJakob Sack <kde@jakobsack.de>
Wed, 2 Mar 2011 21:28:32 +0000 (22:28 +0100)
committerJakob Sack <kde@jakobsack.de>
Wed, 2 Mar 2011 21:28:32 +0000 (22:28 +0100)
lib/helper.php
lib/template.php

index 085ab67e737c615a4ea05b2e4d44da4d5c7051a3..5999c33a458d671b283d7418c03cc8dc7090b48d 100644 (file)
@@ -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";
+       }
 }
 
 ?>
index efa8dde8b9d01b2f86e2a8bd9baf5cbd2f0bd9c3..bdb2ebab03bf3b5d882c13ee0d539e0c9c55dea6 100644 (file)
@@ -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