From a11b258fd65379f3096a90751b170e408bcabca3 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Jun 2019 20:34:21 +0000 Subject: [PATCH] Issue 7223: Don't strip links --- src/Content/Text/BBCode.php | 22 ++++++++-------------- src/Protocol/ActivityPub/Transmitter.php | 4 ++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 7560019ae..f90d9272e 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -569,7 +569,7 @@ class BBCode extends BaseObject } $return = ''; - if ($simplehtml == 7) { + if (in_array($simplehtml, [7, 9])) { $return = self::convertUrlForOStatus($data["url"]); } elseif (($simplehtml != 4) && ($simplehtml != 0)) { $return = sprintf('%s
', $data["url"], $data["title"]); @@ -985,16 +985,9 @@ class BBCode extends BaseObject $text = ($is_quote_share? '
' : '') . '

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

' . "\n" . $content; break; case 7: // statusnet/GNU Social + case 9: $text = ($is_quote_share? '
' : '') . '

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

' . "\n"; break; - case 9: // Google+ - $text = ($is_quote_share? '
' : '') . '

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

' . "\n"; - $text .= '

' . $content . '

' . "\n"; - - if ($attributes['link'] != '') { - $text .= '

' . $attributes['link'] . '

'; - } - 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'])) { @@ -1146,13 +1139,14 @@ class BBCode extends BaseObject * Simple HTML values meaning: * - 0: Friendica display * - 1: Unused - * - 2: Used for Google+, Windows Phone push, Friendica API + * - 2: Used for Windows Phone push, Friendica API * - 3: Used before converting to Markdown in bb2diaspora.php * - 4: Used for WordPress, Libertree (before Markdown), pump.io and tumblr * - 5: Unused * - 6: Unused * - 7: Used for dfrn, OStatus * - 8: Used for WP backlink text setting + * - 9: ActivityPub * * @param string $text * @param bool $try_oembed @@ -1298,7 +1292,7 @@ class BBCode extends BaseObject // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text if (!$for_plaintext) { $text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text); - if ($simple_html == 7) { + if (in_array($simple_html, [7, 9])) { $text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); $text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'self::convertUrlForOStatusCallback', $text); } @@ -1310,14 +1304,14 @@ class BBCode extends BaseObject $text = str_replace(["\r","\n"], ['
', '
'], $text); // Remove all hashtag addresses - if ((!$try_oembed || $simple_html) && !in_array($simple_html, [3, 7])) { + if ((!$try_oembed || $simple_html) && !in_array($simple_html, [3, 7, 9])) { $text = preg_replace("/([#@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text); } elseif ($simple_html == 3) { // The ! is converted to @ since Diaspora only understands the @ $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '@$3', $text); - } elseif ($simple_html == 7) { + } elseif (in_array($simple_html, [7, 9])) { $text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text); @@ -1333,7 +1327,7 @@ class BBCode extends BaseObject $text = preg_replace("/#\[url\=[$URLSearchString]*\]\^\[\/url\]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/i", "[bookmark=$1]$2[/bookmark]", $text); - if (in_array($simple_html, [2, 6, 7, 8, 9])) { + if (in_array($simple_html, [2, 6, 7, 8])) { $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); diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 5f3325711..81b8bc1de 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1141,7 +1141,7 @@ class Transmitter { $event = []; $event['name'] = $item['event-summary']; - $event['content'] = BBCode::convert($item['event-desc'], false, 7); + $event['content'] = BBCode::convert($item['event-desc'], false, 9); $event['startTime'] = DateTimeFormat::utc($item['event-start'] . '+00:00', DateTimeFormat::ATOM); if (!$item['event-nofinish']) { @@ -1231,7 +1231,7 @@ class Transmitter $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism"; $body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body); - $data['content'] = BBCode::convert($body, false, 7); + $data['content'] = BBCode::convert($body, false, 9); } $data['source'] = ['content' => $item['body'], 'mediaType' => "text/bbcode"];