Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text_truncate patch for discussion #5278 #5306

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions e107_handlers/e_parse_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1275,16 +1275,18 @@ public function html_truncate($text, $length = 100, $ending = '...', $exact = tr

/**
* @param string $text string to process
* @param integer $len length of characters to be truncated
* @param integer $len length of characters to be truncated, if it has 'w' at the end, it truncates on word instead of chars (example: limit=50w)
* @param string $more string which will be added if truncation
* @return string Always returns text.
* @deprecated for public use. Will be made private. Use $tp->truncate() instead.
* Truncate a string of text to a maximum length $len append the string $more if it was truncated
* Uses current CHARSET for utf-8, returns $len characters rather than $len bytes
*
*/
public function text_truncate($text, $len = 200, $more = ' ... ')
public function text_truncate($text, $lenght = 200, $more = ' ... ')
{

$len = intval($lenght);

if ($this->ustrlen($text) <= $len)
{
Expand All @@ -1296,15 +1298,16 @@ public function text_truncate($text, $len = 200, $more = ' ... ')
$text = $this->toText($text);
}


$text = html_entity_decode($text, ENT_QUOTES, 'utf-8');

if (function_exists('mb_strimwidth'))
if (stristr($lenght, "w") && false !== ($p = strpos(wordwrap($text, $len, $more), $more)))
{$ret = sprintf('%.'. $p . 's', $text);}
elseif (function_exists('mb_strimwidth'))
{
return mb_strimwidth($text, 0, $len, $more);
}

$ret = $this->usubstr($text, 0, $len);
else
{$ret = $this->usubstr($text, 0, $len);}

// search for possible broken html entities
// - if an & is in the last 8 chars, removing it and whatever follows shouldn't hurt
Expand Down
Loading