From 267b652857f09e73d06946c82788852e3c846838 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 13 Jul 2021 08:30:05 +0000 Subject: [PATCH 1/3] Improve how shared posting look on mobile apps --- src/Content/Text/BBCode.php | 2 +- src/Object/Api/Mastodon/Status.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 5f9a3ee78a..1de3c0a68d 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1057,7 +1057,7 @@ class BBCode switch ($simplehtml) { case self::API: $text = ($is_quote_share? '
' : '') . - '

' . html_entity_decode('♲ ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ":

\n" . + '' . html_entity_decode('♲ ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ":
\n" . '
' . $content . '
'; break; case self::DIASPORA: diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index 90e8732ce2..468126b4e6 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -131,7 +131,7 @@ class Status extends BaseDataTransferObject $this->muted = $userAttributes->muted; $this->bookmarked = $userAttributes->bookmarked; $this->pinned = $userAttributes->pinned; - $this->content = BBCode::convertForUriId($item['uri-id'], ($item['raw-body'] ?? $item['body']), BBCode::EXTERNAL); + $this->content = BBCode::convertForUriId($item['uri-id'], ($item['raw-body'] ?? $item['body']), BBCode::API); $this->reblog = $reblog; $this->application = $application->toArray(); $this->account = $account->toArray(); From 875a6b81eff1efe5847e560f0582b01ccf17a10d Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 13 Jul 2021 14:40:10 +0000 Subject: [PATCH 2/3] Improve links for API --- src/Content/Text/BBCode.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 1de3c0a68d..d4ed504994 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -417,9 +417,9 @@ class BBCode if (empty($attach_data['url'])) { return $match[0]; } elseif (empty($attach_data['title']) || $no_link_desc) { - return "\n[url]" . $attach_data['url'] . "[/url]\n"; + return " \n[url]" . $attach_data['url'] . "[/url]\n"; } else { - return "\n[url=" . $attach_data['url'] . ']' . $attach_data['title'] . "[/url]\n"; + return " \n[url=" . $attach_data['url'] . ']' . $attach_data['title'] . "[/url]\n"; } }, $body); } @@ -1431,12 +1431,9 @@ class BBCode } while ($oldtext != $text); } - // Add HTML new lines - $text = str_replace("\n", '
', $text); - /// @todo Have a closer look at the different html modes // Handle attached links or videos - if ($simple_html == self::ACTIVITYPUB) { + if (in_array($simple_html, [self::API, self::ACTIVITYPUB])) { $text = self::removeAttachment($text); } elseif (!in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::CONNECTORS])) { $text = self::removeAttachment($text, true); @@ -1444,6 +1441,9 @@ class BBCode $text = self::convertAttachment($text, $simple_html, $try_oembed, [], $uriid); } + // Add HTML new lines + $text = str_replace("\n", '
', $text); + $nosmile = strpos($text, '[nosmile]') !== false; $text = str_replace('[nosmile]', '', $text); @@ -1749,7 +1749,7 @@ class BBCode } if (!$for_plaintext) { - if (in_array($simple_html, [self::OSTATUS, self::ACTIVITYPUB])) { + if (in_array($simple_html, [self::OSTATUS, self::API, self::ACTIVITYPUB])) { $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); $text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); } @@ -1782,7 +1782,7 @@ class BBCode $text = preg_replace("/#\[url\=.*?\]\^\[\/url\]\[url\=(.*?)\](.*?)\[\/url\]/i", "[bookmark=$1]$2[/bookmark]", $text); - if (in_array($simple_html, [self::API, self::OSTATUS, self::TWITTER])) { + if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) { $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text); //$Text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $Text); $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]',$text); @@ -1821,7 +1821,7 @@ class BBCode * - [url=]#[/url] */ $text = preg_replace_callback("/(?:#\[url\=[^\[\]]*\]|\[url\=[^\[\]]*\]#)(.*?)\[\/url\]/ism", function($matches) use ($simple_html) { - if ($simple_html == BBCode::ACTIVITYPUB) { + if ($simple_html == self::ACTIVITYPUB) { return '#' . XML::escape($matches[1]) . ''; @@ -2115,7 +2115,7 @@ class BBCode { $ret = []; - BBCode::performWithEscapedTags($string, ['noparse', 'pre', 'code', 'img'], function ($string) use (&$ret) { + self::performWithEscapedTags($string, ['noparse', 'pre', 'code', 'img'], function ($string) use (&$ret) { // Convert hashtag links to hashtags $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2 ', $string); @@ -2222,8 +2222,8 @@ class BBCode */ public static function setMentions($body, $profile_uid = 0, $network = '') { - BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) { - $tags = BBCode::getTags($body); + self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) { + $tags = self::getTags($body); $tagged = []; $inform = ''; From ff8f350a4294a5589686810ae3766c7e4d4b0bf0 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 13 Jul 2021 20:37:06 +0000 Subject: [PATCH 3/3] Change the BBCode version --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index d4ed504994..17e630a8fc 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -51,7 +51,7 @@ use Friendica\Util\XML; class BBCode { // Update this value to the current date whenever changes are made to BBCode::convert - const VERSION = '2021-05-21'; + const VERSION = '2021-07-13'; const INTERNAL = 0; const EXTERNAL = 1;