mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-25 07:50:23 +01:00
Merge branch 'master' of github.com:vichan-devel/Tinyboard
This commit is contained in:
commit
0f9e2a5a9d
@ -253,6 +253,16 @@ function truncate($body, $url, $max_lines = false, $max_chars = false) {
|
|||||||
return $body;
|
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) {
|
function bidi_cleanup($data) {
|
||||||
// Closes all embedded RTL and LTR unicode formatting blocks in a string so that
|
// Closes all embedded RTL and LTR unicode formatting blocks in a string so that
|
||||||
// it can be used inside another without controlling its direction.
|
// it can be used inside another without controlling its direction.
|
||||||
|
@ -13,6 +13,7 @@ class Twig_Extensions_Extension_Tinyboard extends Twig_Extension
|
|||||||
new Twig_SimpleFilter('filesize', 'format_bytes'),
|
new Twig_SimpleFilter('filesize', 'format_bytes'),
|
||||||
new Twig_SimpleFilter('truncate', 'twig_truncate_filter'),
|
new Twig_SimpleFilter('truncate', 'twig_truncate_filter'),
|
||||||
new Twig_SimpleFilter('truncate_body', 'truncate'),
|
new Twig_SimpleFilter('truncate_body', 'truncate'),
|
||||||
|
new Twig_SimpleFilter('truncate_filename', 'truncate_filename'),
|
||||||
new Twig_SimpleFilter('extension', 'twig_extension_filter'),
|
new Twig_SimpleFilter('extension', 'twig_extension_filter'),
|
||||||
new Twig_SimpleFilter('sprintf', 'sprintf'),
|
new Twig_SimpleFilter('sprintf', 'sprintf'),
|
||||||
new Twig_SimpleFilter('capcode', 'capcode'),
|
new Twig_SimpleFilter('capcode', 'capcode'),
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
{% if config.show_filename and file.filename %}
|
{% if config.show_filename and file.filename %}
|
||||||
,
|
,
|
||||||
{% if file.filename|length > config.max_filename_display %}
|
{% 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 %}
|
{% else %}
|
||||||
<span class="postfilename">{{ file.filename|e|bidi_cleanup }}</span>
|
<span class="postfilename">{{ file.filename|e|bidi_cleanup }}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
Loading…
Reference in New Issue
Block a user