From a703f4987c69670f0d4007624d3dd61ef27bccb0 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 2 Sep 2016 00:46:18 +0200 Subject: Extract tooltip function into \service\files Signed-off-by: Florian Pritz --- application/service/files.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'application/service') diff --git a/application/service/files.php b/application/service/files.php index 54b1f85af..746cd1162 100644 --- a/application/service/files.php +++ b/application/service/files.php @@ -411,4 +411,32 @@ class files { return true; } + + static public function tooltip(array $filedata) + { + $filesize = format_bytes($filedata["filesize"]); + $file = get_instance()->mfile->file($filedata["data_id"]); + $upload_date = date("r", $filedata["date"]); + + $height = 0; + $width = 0; + try { + list($width, $height) = getimagesize($file); + } catch (\ErrorException $e) { + // likely unsupported filetype + } + + $tooltip = "${filedata["id"]} - $filesize
"; + $tooltip .= "$upload_date
"; + + + if ($height > 0 && $width > 0) { + $tooltip .= "${width}x${height} - ${filedata["mimetype"]}
"; + } else { + $tooltip .= "${filedata["mimetype"]}
"; + } + + return $tooltip; + } + } -- cgit v1.2.3-24-g4f1b