From 9bd0572b63e5a2bc98da0375ab2bd32b546efd12 Mon Sep 17 00:00:00 2001 From: Jason Lam <3edgy6u@gmail.com> Date: Fri, 9 May 2014 20:37:31 -0400 Subject: [PATCH 1/3] use new truncate_filename function --- templates/post/fileinfo.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/post/fileinfo.html b/templates/post/fileinfo.html index dcbb249d..c2a0aa6a 100644 --- a/templates/post/fileinfo.html +++ b/templates/post/fileinfo.html @@ -22,7 +22,7 @@ {% if config.show_filename and file.filename %} , {% if file.filename|length > config.max_filename_display %} - {{ file.filename|truncate(config.max_filename_display)|bidi_cleanup }} + {{ file.filename|truncate_filename(config.max_filename_display)|bidi_cleanup }} {% else %} {{ file.filename|e|bidi_cleanup }} {% endif %} 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 2/3] 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. From ff51706bfd60373919e4820601cd697b55dc957a Mon Sep 17 00:00:00 2001 From: Jason Lam <3edgy6u@gmail.com> Date: Fri, 9 May 2014 20:42:57 -0400 Subject: [PATCH 3/3] add new truncate_filename filter --- inc/lib/Twig/Extensions/Extension/Tinyboard.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 960bb844..e5dff993 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -13,6 +13,7 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension new Twig_SimpleFilter('filesize', 'format_bytes'), new Twig_SimpleFilter('truncate', 'twig_truncate_filter'), new Twig_SimpleFilter('truncate_body', 'truncate'), + new Twig_SimpleFilter('truncate_filename', 'truncate_filename'), new Twig_SimpleFilter('extension', 'twig_extension_filter'), new Twig_SimpleFilter('sprintf', 'sprintf'), new Twig_SimpleFilter('capcode', 'capcode'),