From 0a8d9263362c189cf6ea26689f5b694cde6f8c7b Mon Sep 17 00:00:00 2001 From: hkosaka Date: Thu, 7 Jun 2012 09:54:03 +0000 Subject: [PATCH] 2012-06-07 Hirofumi Kosaka * 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 --- pandora_console/ChangeLog | 6 ++++++ pandora_console/include/functions_ui.php | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 10fc05b9ff..31490c6156 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,9 @@ +2012-06-07 Hirofumi Kosaka + + * 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 * operation/tree.php, diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index 5dc8d9bede..6dc2852ce0 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -50,16 +50,17 @@ function ui_print_truncate_text($text, $numChars = 25, $showTextInAToopTip = tru echo $text; } } - + $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) { if ($style !== false){ $truncateText = ''.$truncateText.'';