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/controllers/file/file_default.php | 30 ++------------------------- application/service/files.php | 28 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/application/controllers/file/file_default.php b/application/controllers/file/file_default.php index 8d1f67636..2a16521a1 100644 --- a/application/controllers/file/file_default.php +++ b/application/controllers/file/file_default.php @@ -216,7 +216,7 @@ class File_default extends MY_Controller { $base = explode("/", $filedata["mimetype"])[0]; if (\libraries\Image::type_supported($mimetype)) { - $filedata["tooltip"] = $this->_tooltip_for_image($filedata); + $filedata["tooltip"] = \service\files::tooltip($filedata); $filedata["orientation"] = libraries\Image::get_exif_orientation($file); $output_cache->add_merge( array("items" => array($filedata)), @@ -378,32 +378,6 @@ class File_default extends MY_Controller { $output_cache->render_now($data, $this->var->view_dir.'/html_paste_footer'); } - private function _tooltip_for_image($filedata) - { - $filesize = format_bytes($filedata["filesize"]); - $file = $this->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; - } private function _display_info($id) { @@ -699,7 +673,7 @@ class File_default extends MY_Controller { unset($query[$key]); continue; } - $query[$key]["tooltip"] = $this->_tooltip_for_image($item); + $query[$key]["tooltip"] = \service\files::tooltip($item); $query[$key]["orientation"] = libraries\Image::get_exif_orientation($this->mfile->file($item["data_id"])); } 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