Merge pull request #10493 from annando/api

Improve how shared posting look on mobile apps
This commit is contained in:
Hypolite Petovan 2021-07-13 22:48:31 -04:00 committed by GitHub
commit 2b5f1f8bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -51,7 +51,7 @@ use Friendica\Util\XML;
class BBCode class BBCode
{ {
// Update this value to the current date whenever changes are made to BBCode::convert // 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 INTERNAL = 0;
const EXTERNAL = 1; const EXTERNAL = 1;
@ -417,9 +417,9 @@ class BBCode
if (empty($attach_data['url'])) { if (empty($attach_data['url'])) {
return $match[0]; return $match[0];
} elseif (empty($attach_data['title']) || $no_link_desc) { } 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 { } else {
return "\n[url=" . $attach_data['url'] . ']' . $attach_data['title'] . "[/url]\n"; return " \n[url=" . $attach_data['url'] . ']' . $attach_data['title'] . "[/url]\n";
} }
}, $body); }, $body);
} }
@ -1057,7 +1057,7 @@ class BBCode
switch ($simplehtml) { switch ($simplehtml) {
case self::API: case self::API:
$text = ($is_quote_share? '<br>' : '') . $text = ($is_quote_share? '<br>' : '') .
'<p><b><a href="' . $attributes['link'] . '">' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . "</a>:</b> </p>\n" . '<b><a href="' . $attributes['link'] . '">' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . "</a>:</b><br>\n" .
'<blockquote class="shared_content">' . $content . '</blockquote>'; '<blockquote class="shared_content">' . $content . '</blockquote>';
break; break;
case self::DIASPORA: case self::DIASPORA:
@ -1431,12 +1431,9 @@ class BBCode
} while ($oldtext != $text); } while ($oldtext != $text);
} }
// Add HTML new lines
$text = str_replace("\n", '<br>', $text);
/// @todo Have a closer look at the different html modes /// @todo Have a closer look at the different html modes
// Handle attached links or videos // Handle attached links or videos
if ($simple_html == self::ACTIVITYPUB) { if (in_array($simple_html, [self::API, self::ACTIVITYPUB])) {
$text = self::removeAttachment($text); $text = self::removeAttachment($text);
} elseif (!in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::CONNECTORS])) { } elseif (!in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::CONNECTORS])) {
$text = self::removeAttachment($text, true); $text = self::removeAttachment($text, true);
@ -1444,6 +1441,9 @@ class BBCode
$text = self::convertAttachment($text, $simple_html, $try_oembed, [], $uriid); $text = self::convertAttachment($text, $simple_html, $try_oembed, [], $uriid);
} }
// Add HTML new lines
$text = str_replace("\n", '<br>', $text);
$nosmile = strpos($text, '[nosmile]') !== false; $nosmile = strpos($text, '[nosmile]') !== false;
$text = str_replace('[nosmile]', '', $text); $text = str_replace('[nosmile]', '', $text);
@ -1749,7 +1749,7 @@ class BBCode
} }
if (!$for_plaintext) { 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);
$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", $text = preg_replace("/#\[url\=.*?\]\^\[\/url\]\[url\=(.*?)\](.*?)\[\/url\]/i",
"[bookmark=$1]$2[/bookmark]", $text); "[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_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text);
//$Text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $Text); //$Text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $Text);
$text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]',$text); $text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]',$text);
@ -1821,7 +1821,7 @@ class BBCode
* - [url=<anything>]#<term>[/url] * - [url=<anything>]#<term>[/url]
*/ */
$text = preg_replace_callback("/(?:#\[url\=[^\[\]]*\]|\[url\=[^\[\]]*\]#)(.*?)\[\/url\]/ism", function($matches) use ($simple_html) { $text = preg_replace_callback("/(?:#\[url\=[^\[\]]*\]|\[url\=[^\[\]]*\]#)(.*?)\[\/url\]/ism", function($matches) use ($simple_html) {
if ($simple_html == BBCode::ACTIVITYPUB) { if ($simple_html == self::ACTIVITYPUB) {
return '<a href="' . DI::baseUrl() . '/search?tag=' . rawurlencode($matches[1]) return '<a href="' . DI::baseUrl() . '/search?tag=' . rawurlencode($matches[1])
. '" data-tag="' . XML::escape($matches[1]) . '" rel="tag ugc">#' . '" data-tag="' . XML::escape($matches[1]) . '" rel="tag ugc">#'
. XML::escape($matches[1]) . '</a>'; . XML::escape($matches[1]) . '</a>';
@ -2115,7 +2115,7 @@ class BBCode
{ {
$ret = []; $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 // Convert hashtag links to hashtags
$string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2 ', $string); $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2 ', $string);
@ -2222,8 +2222,8 @@ class BBCode
*/ */
public static function setMentions($body, $profile_uid = 0, $network = '') public static function setMentions($body, $profile_uid = 0, $network = '')
{ {
BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) { self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) {
$tags = BBCode::getTags($body); $tags = self::getTags($body);
$tagged = []; $tagged = [];
$inform = ''; $inform = '';

View File

@ -131,7 +131,7 @@ class Status extends BaseDataTransferObject
$this->muted = $userAttributes->muted; $this->muted = $userAttributes->muted;
$this->bookmarked = $userAttributes->bookmarked; $this->bookmarked = $userAttributes->bookmarked;
$this->pinned = $userAttributes->pinned; $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->reblog = $reblog;
$this->application = $application->toArray(); $this->application = $application->toArray();
$this->account = $account->toArray(); $this->account = $account->toArray();