Browse Source

Merge branch 'master' of github.com:vichan-devel/Tinyboard

pull/40/head
czaks 10 years ago
parent
commit
4288898dfa
  1. 10
      inc/display.php
  2. 1
      inc/lib/Twig/Extensions/Extension/Tinyboard.php
  3. 2
      templates/post/fileinfo.html

10
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.

1
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'),

2
templates/post/fileinfo.html

@ -22,7 +22,7 @@
{% if config.show_filename and file.filename %}
,
{% if file.filename|length > config.max_filename_display %}
<span class="postfilename" title="{{ file.filename|e }}">{{ file.filename|truncate(config.max_filename_display)|bidi_cleanup }}</span>
<span class="postfilename" title="{{ file.filename|e }}">{{ file.filename|truncate_filename(config.max_filename_display)|bidi_cleanup }}</span>
{% else %}
<span class="postfilename">{{ file.filename|e|bidi_cleanup }}</span>
{% endif %}

Loading…
Cancel
Save