From eca5c383e1035d538d2bc81a9802c76929bf053e Mon Sep 17 00:00:00 2001 From: Jason Lam <3edgy6u@gmail.com> Date: Fri, 9 May 2014 20:42:05 -0400 Subject: [PATCH] added truncate_filename function --- inc/display.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inc/display.php b/inc/display.php index c836247e..a859fbdb 100644 --- a/inc/display.php +++ b/inc/display.php @@ -253,6 +253,16 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) { return $body; } +function truncate_filename($filename, $length) { + if (strlen($filename) <= $length) return $filename; + $matches = array(); + if (!preg_match("/.*(\\..+)/", $filename, $matches)) return $filename // what, no extension + $length -= strlen($matches[1]); + if ($length <= 0) return '(...)' . $matches[1]; // lmao + $filename = substr($filename, 0, $length) . '(...)' . $matches[1]; + return $filename; +} + function bidi_cleanup($data) { // Closes all embedded RTL and LTR unicode formatting blocks in a string so that // it can be used inside another without controlling its direction.