Issue 10491: Possibility for simple shortening added

This commit is contained in:
Michael
2021-07-12 14:11:51 +00:00
parent 07ef1edfd6
commit e5c312a066
6 changed files with 57 additions and 3 deletions
+9 -3
View File
@@ -31,16 +31,22 @@ class Plaintext
*
* @param string $msg
* @param int $limit
* @param int $uid
* @return string
*
* @todo For Twitter URLs aren't shortened, but they have to be calculated as if.
*/
public static function shorten($msg, $limit)
public static function shorten($msg, $limit, $uid = 0)
{
$ellipsis = html_entity_decode("…", ENT_QUOTES, 'UTF-8');
if (!empty($uid) && DI::pConfig()->get($uid, 'system', 'simple_shortening')) {
return iconv_substr(iconv_substr(trim($msg), 0, $limit, "UTF-8"), 0, -3, "UTF-8") . $ellipsis;
}
$lines = explode("\n", $msg);
$msg = "";
$recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
$ellipsis = html_entity_decode("…", ENT_QUOTES, 'UTF-8');
foreach ($lines as $row => $line) {
if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
$msg = trim($msg . "\n" . $line);
@@ -241,7 +247,7 @@ class Plaintext
} elseif (DI::pConfig()->get($item['uid'], 'system', 'no_intelligent_shortening')) {
$post['url'] = $item['plink'];
}
$msg = self::shorten($msg, $limit);
$msg = self::shorten($msg, $limit, $item['uid']);
}
}