diff options
| author | czaks <marcin@6irc.net> | 2014-05-10 21:58:34 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2014-05-10 21:58:34 +0200 |
| commit | 4288898dfa118f04b3f557f861c9da712fd4161c (patch) | |
| tree | f09c92c2b42370b74bf2831bc3dd24bf9d0b913d /inc | |
| parent | 19ce50c545bf4c4eced7b7d4223125a41d1648ea (diff) | |
| parent | 7b57a4b9119f8e1e539957188c06c43831782349 (diff) | |
Merge branch 'master' of github.com:vichan-devel/Tinyboard
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/display.php | 10 | ||||
| -rw-r--r-- | inc/lib/Twig/Extensions/Extension/Tinyboard.php | 1 |
2 files changed, 11 insertions, 0 deletions
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. 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'), |
