2012-06-07 Hirofumi Kosaka <kosaka@rworks.jp>

* include/functions_ui.php: Merged from 4.0.x: Fixed bug:
	string truncation did not always work for multi-byte
	characters.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6437 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
hkosaka 2012-06-07 09:54:03 +00:00
parent 5c009d2ddc
commit 0a8d926336
2 changed files with 14 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2012-06-07 Hirofumi Kosaka <kosaka@rworks.jp>
* include/functions_ui.php: Merged from 4.0.x: Fixed bug:
string truncation did not always work for multi-byte
characters.
2012-06-07 Dario Rodriguez <dario.rodriguez@artica.es>
* operation/tree.php,

View File

@ -52,12 +52,13 @@ function ui_print_truncate_text($text, $numChars = 25, $showTextInAToopTip = tru
}
$text = io_safe_output($text);
if ((strlen($text)) > ($numChars)) {
if (mb_strlen($text, "UTF-8") > ($numChars)) {
$half_length = intval(($numChars - 3) / 2); // '/2' because [...] is in the middle of the word.
$truncateText2 = mb_strimwidth($text, (strlen($text) - $half_length), strlen($text));
// In case $numChars were an odd number.
$half_length = $numChars - $half_length - 3;
$truncateText = mb_strimwidth($text, 0, $half_length) . $suffix;
// Depending on the strange behavior of mb_strimwidth() itself,
// the 3rd parameter is not to be $numChars but the length of original text (just means 'large enough').
$truncateText2 = mb_strimwidth($text, (mb_strlen($text, "UTF-8") - $half_length), strlen($text), "", "UTF-8" );
$truncateText = mb_strimwidth($text, 0, ($numChars - $half_length), $suffix, "UTF-8");
$truncateText=$truncateText . $truncateText2;
if ($showTextInTitle) {