X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FText%2FBBCode.php;h=c9a1bfe0521ec58fe56352c149989fce3895094e;hb=3842f02b021f2f32dbe6707c22af5760c3353dfa;hp=b2fb1da7af8c258dfdb2fac143f49c2e4a8ff66f;hpb=19c3e55ca88e43d4dee6ba49f4b435034b660ecd;p=friendica.git diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index b2fb1da7af..c9a1bfe052 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1,6 +1,6 @@ 0) { return Post\Link::getByLink($uriid, $image, $size); } else { - return ProxyUtils::proxifyUrl($image, $size); + return Proxy::proxifyUrl($image, $size); } } @@ -499,11 +502,13 @@ class BBCode continue; } - $curlResult = DI::httpClient()->get($mtch[1]); + $curlResult = DI::httpClient()->get($mtch[1], HttpClientAccept::IMAGE); if (!$curlResult->isSuccess()) { continue; } + Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $mtch[1]]); + $i = $curlResult->getBody(); $type = $curlResult->getContentType(); $type = Images::getMimeTypeByData($i, $mtch[1], $type); @@ -685,7 +690,7 @@ class BBCode } elseif (!empty($data['preview'])) { $return .= sprintf('
', $data['url'], self::proxyUrl($data['preview'], $simplehtml, $uriid), $data['title']); } - $return .= sprintf('

%s

', $data['url'], $data['title']); + $return .= sprintf('

%s

', $data['url'], $data['title']); } } @@ -696,9 +701,9 @@ class BBCode if (!empty($data['provider_url']) && !empty($data['provider_name'])) { if (!empty($data['author_name'])) { - $return .= sprintf('%s (%s)', $data['provider_url'], $data['author_name'], $data['provider_name']); + $return .= sprintf('%s (%s)', $data['provider_url'], $data['author_name'], $data['provider_name']); } else { - $return .= sprintf('%s', $data['provider_url'], $data['provider_name']); + $return .= sprintf('%s', $data['provider_url'], $data['provider_name']); } } @@ -1050,16 +1055,16 @@ class BBCode $author_contact = Contact::getByURL($attributes['profile'], false, ['id', 'url', 'addr', 'name', 'micro']); $author_contact['url'] = ($author_contact['url'] ?? $attributes['profile']); - $author_contact['addr'] = ($author_contact['addr'] ?? '') ?: Protocol::getAddrFromProfileUrl($attributes['profile']); + $author_contact['addr'] = ($author_contact['addr'] ?? ''); $attributes['author'] = ($author_contact['name'] ?? '') ?: $attributes['author']; $attributes['avatar'] = ($author_contact['micro'] ?? '') ?: $attributes['avatar']; $attributes['profile'] = ($author_contact['url'] ?? '') ?: $attributes['profile']; if (!empty($author_contact['id'])) { - $attributes['avatar'] = Contact::getAvatarUrlForId($author_contact['id'], ProxyUtils::SIZE_THUMB); + $attributes['avatar'] = Contact::getAvatarUrlForId($author_contact['id'], Proxy::SIZE_THUMB); } elseif ($attributes['avatar']) { - $attributes['avatar'] = self::proxyUrl($attributes['avatar'], self::INTERNAL, $uriid, ProxyUtils::SIZE_THUMB); + $attributes['avatar'] = self::proxyUrl($attributes['avatar'], self::INTERNAL, $uriid, Proxy::SIZE_THUMB); } $content = preg_replace(Strings::autoLinkRegEx(), '$1', $match[3]); @@ -1094,7 +1099,7 @@ class BBCode $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8'); } - $img_str = ' $value) { if (!empty($value)) { @@ -1127,13 +1132,13 @@ class BBCode private static function convertShareCallback(array $attributes, array $author_contact, $content, $is_quote_share, $simplehtml) { DI::profiler()->startRecording('rendering'); - $mention = Protocol::formatMention($attributes['profile'], $attributes['author']); + $mention = $attributes['author'] . ' (' . ($author_contact['addr'] ?? '') . ')'; switch ($simplehtml) { case self::API: $text = ($is_quote_share? '
' : '') . - '' . html_entity_decode('♲ ', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ":
\n" . - '
' . $content . '
'; + '' . html_entity_decode('♲', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ":
\n" . + '
' . $content . '
'; break; case self::DIASPORA: if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0) { @@ -1158,7 +1163,7 @@ class BBCode $headline .= DI::l10n()->t('%2$s %3$s', $attributes['link'], $mention, $attributes['posted']); $headline .= ':

' . "\n"; - $text = ($is_quote_share? '
' : '') . $headline . '
' . trim($content) . '
' . "\n"; + $text = ($is_quote_share? '
' : '') . $headline . '
' . trim($content) . '
' . "\n"; break; case self::OSTATUS: @@ -1199,7 +1204,7 @@ class BBCode $text = DI::cache()->get($cache_key); if (is_null($text)) { - $curlResult = DI::httpClient()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); + $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); if ($curlResult->isSuccess()) { $mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; } else { @@ -1212,7 +1217,7 @@ class BBCode $text = "[url=" . $match[2] . ']' . $match[2] . "[/url]"; // if its not a picture then look if its a page that contains a picture link - $body = DI::httpClient()->fetch($match[1]); + $body = DI::httpClient()->fetch($match[1], HttpClientAccept::HTML, 0); if (empty($body)) { DI::cache()->set($cache_key, $text); return $text; @@ -1270,7 +1275,7 @@ class BBCode return $text; } - $curlResult = DI::httpClient()->head($match[1], [HTTPClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); + $curlResult = DI::httpClient()->head($match[1], [HttpClientOptions::TIMEOUT => DI::config()->get('system', 'xrd_timeout')]); if ($curlResult->isSuccess()) { $mimetype = $curlResult->getHeader('Content-Type')[0] ?? ''; } else { @@ -1288,7 +1293,7 @@ class BBCode } // if its not a picture then look if its a page that contains a picture link - $body = DI::httpClient()->fetch($match[1]); + $body = DI::httpClient()->fetch($match[1], HttpClientAccept::HTML, 0); if (empty($body)) { DI::cache()->set($cache_key, $text); return $text; @@ -1558,9 +1563,6 @@ 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); @@ -1643,11 +1645,20 @@ class BBCode // Check for list text $text = str_replace("[*]", "
  • ", $text); - // Check for style sheet commands + // Check for block-level custom CSS + $text = preg_replace('#(?<=^|\n)\[style=(.*?)](.*?)\[/style](?:\n|$)#ism', '
    $2
    ', $text); + + // Check for inline custom CSS $text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism", '$2', $text); + // Mastodon Emoji (internal tag, do not document for users) + $text = preg_replace("(\[emoji=(.*?)](.*?)\[/emoji])ism", '$2', $text); + // Check for CSS classes + // @deprecated since 2021.12, left for backward-compatibility reasons $text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism", '$2', $text); + // Add HTML new lines + $text = str_replace("\n", '
    ', $text); // handle nested lists $endlessloop = 0; @@ -1772,7 +1783,7 @@ class BBCode $text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . DI::l10n()->t('Image/photo') . '', $text); $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . DI::l10n()->t('Image/photo') . '', $text); - + $text = self::convertImages($text, $simple_html, $uriid); $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '
    ' . DI::l10n()->t('Encrypted content') . '
    ', $text); @@ -1855,7 +1866,6 @@ class BBCode $text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism", $sub, $text); $text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism", '', $text); $text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism", '', $text); - $text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism", '', $text); $text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism", '', $text); } @@ -1887,7 +1897,7 @@ class BBCode } else { $text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text); } - + if (!$for_plaintext) { if (in_array($simple_html, [self::OSTATUS, self::API, self::ACTIVITYPUB])) { $text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text); @@ -2079,8 +2089,8 @@ class BBCode public static function stripAbstract($text) { DI::profiler()->startRecording('rendering'); - $text = preg_replace("/[\s|\n]*\[abstract\].*?\[\/abstract\][\s|\n]*/ism", '', $text); - $text = preg_replace("/[\s|\n]*\[abstract=.*?\].*?\[\/abstract][\s|\n]*/ism", '', $text); + $text = preg_replace("/[\s|\n]*\[abstract\].*?\[\/abstract\][\s|\n]*/ism", ' ', $text); + $text = preg_replace("/[\s|\n]*\[abstract=.*?\].*?\[\/abstract][\s|\n]*/ism", ' ', $text); DI::profiler()->stopRecording(); return $text; @@ -2101,7 +2111,7 @@ class BBCode $addon = strtolower($addon); if (preg_match_all("/\[abstract=(.*?)\](.*?)\[\/abstract\]/ism", $text, $results, PREG_SET_ORDER)) { - foreach ($results AS $result) { + foreach ($results as $result) { $abstracts[strtolower($result[1])] = $result[2]; } } @@ -2315,7 +2325,7 @@ class BBCode break; case '#': default: - return $match[1] . '[url=' . 'https://' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]'; + return $match[1] . '[url=' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]'; } }, $body); } @@ -2339,7 +2349,7 @@ class BBCode } /** - * Replaces mentions in the provided message body for the provided user and network if any + * Replaces mentions in the provided message body in BBCode links for the provided user and network if any * * @param $body * @param $profile_uid @@ -2351,11 +2361,10 @@ class BBCode public static function setMentions($body, $profile_uid = 0, $network = '') { DI::profiler()->startRecording('rendering'); - self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) { + $body = self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) { $tags = self::getTags($body); $tagged = []; - $inform = ''; foreach ($tags as $tag) { $tag_type = substr($tag, 0, 1); @@ -2374,7 +2383,7 @@ class BBCode } } - if (($success = Item::replaceTag($body, $inform, $profile_uid, $tag, $network)) && $success['replaced']) { + if (($success = Item::replaceTag($body, $profile_uid, $tag, $network)) && $success['replaced']) { $tagged[] = $tag; } }