]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/Plaintext.php
Merge pull request #11230 from annando/account-type
[friendica.git] / src / Content / Text / Plaintext.php
index b6d767f15999cd461facca3de72288af69ab0668..2fcff72d59230364b2eaba245c081e01feface76 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -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(string $msg, int $limit, int $uid = 0):string
        {
+               $ellipsis = html_entity_decode("&#x2026;", 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("&#x2672; ", ENT_QUOTES, 'UTF-8');
-               $ellipsis = html_entity_decode("&#x2026;", ENT_QUOTES, 'UTF-8');
                foreach ($lines as $row => $line) {
                        if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
                                $msg = trim($msg . "\n" . $line);
@@ -169,7 +175,7 @@ class Plaintext
                        }
                }
 
-               $html = BBCode::convert($post['text'] . ($post['after'] ?? ''), false, $htmlmode);
+               $html = BBCode::convertForUriId($item['uri-id'], $post['text'] . ($post['after'] ?? ''), $htmlmode);
                $msg = HTML::toPlaintext($html, 0, true);
                $msg = trim(html_entity_decode($msg, ENT_QUOTES, 'UTF-8'));
 
@@ -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']);
                        }
                }