From 51609351f2c4b5082b7e6f0744cd3811c325303f Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 11 Oct 2016 14:01:29 +0200 Subject: * initial template --- lib/smarty/plugins/shared.mb_wordwrap.php | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lib/smarty/plugins/shared.mb_wordwrap.php (limited to 'lib/smarty/plugins/shared.mb_wordwrap.php') diff --git a/lib/smarty/plugins/shared.mb_wordwrap.php b/lib/smarty/plugins/shared.mb_wordwrap.php new file mode 100644 index 0000000..ba3498c --- /dev/null +++ b/lib/smarty/plugins/shared.mb_wordwrap.php @@ -0,0 +1,83 @@ + $width) { + // remove last space + $t = mb_substr($t, 0, -1, Smarty::$_CHARSET); + $_previous = false; + $length = 0; + + if ($cut) { + $_tokens = preg_split('!(.{' . $width . '})!S' . Smarty::$_UTF8_MODIFIER, $_token, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE); + // broken words go on a new line + $t .= $break; + } + } + + foreach ($_tokens as $token) { + $_space = !!preg_match('!^\s$!S' . Smarty::$_UTF8_MODIFIER, $token); + $token_length = mb_strlen($token, Smarty::$_CHARSET); + $length += $token_length; + + if ($length > $width) { + // remove space before inserted break + if ($_previous && $token_length < $width) { + $t = mb_substr($t, 0, -1, Smarty::$_CHARSET); + } + + // add the break before the token + $t .= $break; + $length = $token_length; + + // skip space after inserting a break + if ($_space) { + $length = 0; + continue; + } + } else if ($token == "\n") { + // hard break must reset counters + $_previous = 0; + $length = 0; + } else { + // remember if we had a space or not + $_previous = $_space; + } + // add the token + $t .= $token; + } + } + + return $t; + } + +} +?> \ No newline at end of file -- cgit v1.2.3