bug fix in truncate function
This commit is contained in:
parent
335f159c78
commit
78968aaf4d
|
@ -256,26 +256,18 @@ class Text {
|
||||||
$string);
|
$string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Truncates the string under the limit specified by the limit parameter.
|
// Truncates the string under the limit specified by the limit parameter
|
||||||
public static function truncate($string, $limit, $end = '...')
|
public static function truncate($string, $limit, $end='...')
|
||||||
{
|
{
|
||||||
// Check if over $limit
|
// Check if over $limit
|
||||||
if(mb_strlen($string) > $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));
|
$truncate = trim(mb_substr($string, 0, $limit, CHARSET));
|
||||||
}
|
|
||||||
$truncate = $truncate.$end;
|
$truncate = $truncate.$end;
|
||||||
} else {
|
} else {
|
||||||
$truncate = $string;
|
$truncate = $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($truncate)) {
|
if (empty($truncate)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -603,10 +603,12 @@ class Pages extends dbJSON {
|
||||||
|
|
||||||
|
|
||||||
// Returns string without HTML tags and truncated
|
// 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::removeHTMLTags($text);
|
||||||
$tmpslug = Text::removeLineBreaks($tmpslug);
|
$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
|
// Returns TRUE if there are new pages published, FALSE otherwise
|
||||||
|
|
Loading…
Reference in New Issue