1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 05:37:32 +02:00

Merge pull request #56 from rica-carv/rica-carv-patch-texttruncate

Add files via upload
This commit is contained in:
rica-carv
2024-08-03 15:51:50 +01:00
committed by GitHub

View File

@@ -1275,7 +1275,7 @@ class e_parse
/** /**
* @param string $text string to process * @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 * @param string $more string which will be added if truncation
* @return string Always returns text. * @return string Always returns text.
* @deprecated for public use. Will be made private. Use $tp->truncate() instead. * @deprecated for public use. Will be made private. Use $tp->truncate() instead.
@@ -1283,9 +1283,11 @@ class e_parse
* Uses current CHARSET for utf-8, returns $len characters rather than $len bytes * 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) if ($this->ustrlen($text) <= $len)
{ {
return $text; return $text;
@@ -1296,15 +1298,16 @@ class e_parse
$text = $this->toText($text); $text = $this->toText($text);
} }
$text = html_entity_decode($text, ENT_QUOTES, 'utf-8'); $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); return mb_strimwidth($text, 0, $len, $more);
} }
else
$ret = $this->usubstr($text, 0, $len); {$ret = $this->usubstr($text, 0, $len);}
// search for possible broken html entities // search for possible broken html entities
// - if an & is in the last 8 chars, removing it and whatever follows shouldn't hurt // - if an & is in the last 8 chars, removing it and whatever follows shouldn't hurt
@@ -4308,22 +4311,14 @@ class e_parse
$image = (!empty($userData['user_image'])) ? varset($userData['user_image']) : null; $image = (!empty($userData['user_image'])) ? varset($userData['user_image']) : null;
$genericFile = e_IMAGE . 'generic/blank_avatar.jpg'; $genericFile = e_IMAGE . 'generic/blank_avatar.jpg';
$genericImg = $tp->thumbUrl($genericFile, 'w=' . $width . '&h=' . $height, false, $full); $genericImg = $tp->thumbUrl($genericFile, 'w=' . $width . '&h=' . $height, true, $full);
if (!empty($image)) if (!empty($image))
{ {
if (strpos($image, '://') !== false) // Remote Image if (strpos($image, '://') !== false) // Remote Image
{ {
if (@fopen($image, 'r')) $url = $image;
{
$url = $image;
}
else
{
$file = $genericFile;
$url = $genericImg;
}
} }
elseif (strpos($image, '-upload-') === 0) elseif (strpos($image, '-upload-') === 0)
{ {