From f68652d61c393e4092890744e77a6c0adfce1b4c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 4 Jun 2020 11:11:44 -0400 Subject: [PATCH 1/2] Revert "Move share content conversion before link handling in Text\BBCode::convert" This reverts commit 010ec99b35c2bee8f23060e96c2af3ba5849cf84. --- src/Content/Text/BBCode.php | 17 ++++++++--------- tests/src/Content/Text/BBCodeTest.php | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index ac869d0d87..67dbe3b19a 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1765,15 +1765,6 @@ class BBCode $text); } - // Shared content conversion - // Notice: may create [bookmark] tags so this must be ran before the link handling - $text = self::convertShare( - $text, - function (array $attributes, array $author_contact, $content, $is_quote_share) use ($simple_html) { - return self::convertShareCallback($attributes, $author_contact, $content, $is_quote_share, $simple_html); - } - ); - // Bookmarks in red - will be converted to bookmarks in friendica $text = preg_replace("/#\^\[url\](.*?)\[\/url\]/ism", '[bookmark=$1]$1[/bookmark]', $text); $text = preg_replace("/#\^\[url\=(.*?)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $text); @@ -1892,6 +1883,14 @@ class BBCode $regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism'; $text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 data-original-href="$3" class="invalid-href" title="' . DI::l10n()->t('Invalid link protocol') . '">', $text); + // Shared content + $text = self::convertShare( + $text, + function (array $attributes, array $author_contact, $content, $is_quote_share) use ($simple_html) { + return self::convertShareCallback($attributes, $author_contact, $content, $is_quote_share, $simple_html); + } + ); + if ($saved_image) { $text = self::interpolateSavedImagesIntoItemBody($text, $saved_image); } diff --git a/tests/src/Content/Text/BBCodeTest.php b/tests/src/Content/Text/BBCodeTest.php index 28db30567d..35dff87d9f 100644 --- a/tests/src/Content/Text/BBCodeTest.php +++ b/tests/src/Content/Text/BBCodeTest.php @@ -236,7 +236,7 @@ class BBCodeTest extends MockedTest 'bug-7808-code-amp' => [ 'expectedHtml' => '&', 'text' => '[code]&[/code]', - ], + ] ]; } From e0152bec7d34a20c3c075ade8cd643c69fde3895 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 4 Jun 2020 11:13:31 -0400 Subject: [PATCH 2/2] Remove Twitter exception for shared blocks in Text\BBCode::convertShareCallback - Twitter stopped supporting OEmbed which defaulted to an undesirable fallback --- src/Content/Text/BBCode.php | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 67dbe3b19a..fa2e3db923 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1071,26 +1071,17 @@ class BBCode $text = '
' . html_entity_decode('♲', ENT_QUOTES, 'UTF-8') . ' ' . $author . '
' . $content . '
' . "\n"; break; default: - // Transforms quoted tweets in rich attachments to avoid nested tweets - if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($attributes['link'])) { - try { - $text = ($is_quote_share? '
' : '') . OEmbed::getHTML($attributes['link']); - } catch (Exception $e) { - $text = ($is_quote_share? '
' : '') . sprintf('[bookmark=%s]%s[/bookmark]', $attributes['link'], $content); - } - } else { - $text = ($is_quote_share? "\n" : ''); + $text = ($is_quote_share? "\n" : ''); - $tpl = Renderer::getMarkupTemplate('shared_content.tpl'); - $text .= Renderer::replaceMacros($tpl, [ - '$profile' => $attributes['profile'], - '$avatar' => $attributes['avatar'], - '$author' => $attributes['author'], - '$link' => $attributes['link'], - '$posted' => $attributes['posted'], - '$content' => trim($content) - ]); - } + $tpl = Renderer::getMarkupTemplate('shared_content.tpl'); + $text .= Renderer::replaceMacros($tpl, [ + '$profile' => $attributes['profile'], + '$avatar' => $attributes['avatar'], + '$author' => $attributes['author'], + '$link' => $attributes['link'], + '$posted' => $attributes['posted'], + '$content' => trim($content) + ]); break; }