Fix issue 785.

This commit is contained in:
Thomas Keller 2012-02-24 01:29:25 +01:00
parent c0506c460d
commit 9bd5912884
2 changed files with 6 additions and 3 deletions

View File

@ -4,6 +4,9 @@
## Bugfixes
- Ensure that IDF does not break UTF-8 encoded strings when
shortening them for view rendering (issue 785)
## Documentation
## Translations

View File

@ -506,12 +506,12 @@ function IDF_Views_Source_PrettySizeSimple($size)
function IDF_Views_Source_ShortenString($string, $length)
{
$ellipse = "...";
$length = max(strlen($ellipse) + 2, $length);
$length = max(mb_strlen($ellipse) + 2, $length);
$preflen = ceil($length / 10);
if (mb_strlen($string) < $length)
return $string;
return substr($string, 0, $preflen).$ellipse.
substr($string, -($length - $preflen - mb_strlen($ellipse)));
return mb_substr($string, 0, $preflen).$ellipse.
mb_substr($string, -($length - $preflen - mb_strlen($ellipse)));
}