3 * @file src/Content/Text/Plaintext.php
5 namespace Friendica\Content\Text;
16 * @todo For Twitter URLs aren't shortened, but they have to be calculated as if.
18 public static function shorten($msg, $limit)
20 $lines = explode("\n", $msg);
22 $recycle = html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8');
23 $ellipsis = html_entity_decode("…", ENT_QUOTES, 'UTF-8');
24 foreach ($lines as $row => $line) {
25 if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
26 $msg = trim($msg . "\n" . $line);
27 } elseif (($msg == "") || (($row == 1) && (substr($msg, 0, 4) == $recycle))) {
28 // Is the new message empty by now or is it a reshared message?
29 $msg = iconv_substr(iconv_substr(trim($msg . "\n" . $line), 0, $limit, "UTF-8"), 0, -3, "UTF-8") . $ellipsis;