From 78968aaf4d2730f480447627c997d79b770044de Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Mon, 3 Sep 2018 18:46:21 +0200 Subject: [PATCH] bug fix in truncate function --- bl-kernel/helpers/text.class.php | 18 +++++------------- bl-kernel/pages.class.php | 6 ++++-- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/bl-kernel/helpers/text.class.php b/bl-kernel/helpers/text.class.php index ff27d38d..59c89f3a 100644 --- a/bl-kernel/helpers/text.class.php +++ b/bl-kernel/helpers/text.class.php @@ -256,26 +256,18 @@ class Text { $string); } - // Truncates the string under the limit specified by the limit parameter. - public static function truncate($string, $limit, $end = '...') + // Truncates the string under the limit specified by the limit parameter + public static function truncate($string, $limit, $end='...') { // Check if over $limit - if(mb_strlen($string) > $limit) { - - // Check if string is only one word - if(preg_match('/\s/', $string)) { - - // Append the string specified by the end parameter to the end of the string as it is over the limit. - $truncate = trim(mb_substr($string, 0, mb_strpos($string, ' ', $limit, CHARSET), CHARSET)); - } else { - $truncate = trim(mb_substr($string, 0, $limit, CHARSET)); - } + if (mb_strlen($string) > $limit) { + $truncate = trim(mb_substr($string, 0, $limit, CHARSET)); $truncate = $truncate.$end; } else { $truncate = $string; } - if(empty($truncate)) { + if (empty($truncate)) { return ''; } diff --git a/bl-kernel/pages.class.php b/bl-kernel/pages.class.php index f35b86f3..12f77043 100644 --- a/bl-kernel/pages.class.php +++ b/bl-kernel/pages.class.php @@ -603,10 +603,12 @@ class Pages extends dbJSON { // Returns string without HTML tags and truncated - private function generateSlug($text, $truncateLength=60) { + private function generateSlug($text, $truncateLength=60) + { $tmpslug = Text::removeHTMLTags($text); $tmpslug = Text::removeLineBreaks($tmpslug); - return Text::truncate($tmpslug, $truncateLength, ''); + $tmpslug = Text::truncate($tmpslug, $truncateLength, ''); + return $tmpslug; } // Returns TRUE if there are new pages published, FALSE otherwise