diff options
author | friendica <info@friendica.com> | 2015-01-27 20:00:43 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2015-01-27 20:00:43 -0800 |
commit | a2cdd1499c968c31ae1b95933231f80be5fc639b (patch) | |
tree | 231780d92f46a0f265e79fa478c3b7e7fc84d085 /include/text.php | |
parent | 0bfbe6d61d3c6250a162a29d2cdb0ec78ad02f1d (diff) | |
parent | 145b30adfc21b7f29d1431ebd1e2e0f4ebd853bf (diff) | |
download | volse-hubzilla-a2cdd1499c968c31ae1b95933231f80be5fc639b.tar.gz volse-hubzilla-a2cdd1499c968c31ae1b95933231f80be5fc639b.tar.bz2 volse-hubzilla-a2cdd1499c968c31ae1b95933231f80be5fc639b.zip |
Merge branch 'master' into tres
Conflicts:
include/socgraph.php
Diffstat (limited to 'include/text.php')
-rw-r--r-- | include/text.php | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/include/text.php b/include/text.php index 2aa270f3b..9a13e5e72 100644 --- a/include/text.php +++ b/include/text.php @@ -2377,3 +2377,74 @@ function linkify_tags($a, &$body, $uid) { return $results; } +/** + * @brief returns icon name for use with e.g. font-awesome based on mime-type + * + * @param string $type + * @return string + */ +function getIconFromType($type) { + $iconMap = array( + //Folder + t('Collection') => 'icon-folder-close', + //Common file + 'application/octet-stream' => 'icon-file-alt', + //Text + 'text/plain' => 'icon-file-text-alt', + 'application/msword' => 'icon-file-text-alt', + 'application/pdf' => 'icon-file-text-alt', + 'application/vnd.oasis.opendocument.text' => 'icon-file-text-alt', + 'application/epub+zip' => 'icon-book', + //Spreadsheet + 'application/vnd.oasis.opendocument.spreadsheet' => 'icon-table', + 'application/vnd.ms-excel' => 'icon-table', + //Image + 'image/jpeg' => 'icon-picture', + 'image/png' => 'icon-picture', + 'image/gif' => 'icon-picture', + 'image/svg+xml' => 'icon-picture', + //Archive + 'application/zip' => 'icon-archive', + 'application/x-rar-compressed' => 'icon-archive', + //Audio + 'audio/mpeg' => 'icon-music', + 'audio/wav' => 'icon-music', + 'application/ogg' => 'icon-music', + 'audio/ogg' => 'icon-music', + 'audio/webm' => 'icon-music', + 'audio/mp4' => 'icon-music', + //Video + 'video/quicktime' => 'icon-film', + 'video/webm' => 'icon-film', + 'video/mp4' => 'icon-film' + ); + + $iconFromType = 'icon-file-alt'; + + if (array_key_exists($type, $iconMap)) { + $iconFromType = $iconMap[$type]; + } + + return $iconFromType; +} + +/** + * @brief Returns a human readable formatted string for filesizes. + * + * @param int $size filesize in bytes + * @return string + */ +function userReadableSize($size) { + $ret = ""; + if (is_numeric($size)) { + $incr = 0; + $k = 1024; + $unit = array('bytes', 'KB', 'MB', 'GB', 'TB', 'PB'); + while (($size / $k) >= 1){ + $incr++; + $size = round($size / $k, 2); + } + $ret = $size . " " . $unit[$incr]; + } + return $ret; +} |