X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FText%2FBBCode.php;h=a38d2de7856ec39f7c24c38c36d7a5af6c92eee2;hb=a8402109b183e81dad4e5443883dd292df094b86;hp=9be7def903e98fc9f9b21400200ac4df98b60c98;hpb=2497817c2a687d10f376f27617b1da35d94d0587;p=friendica.git
diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php
index 9be7def903..a38d2de785 100644
--- a/src/Content/Text/BBCode.php
+++ b/src/Content/Text/BBCode.php
@@ -1,6 +1,6 @@
Message type ('link', 'video', 'photo')
- * 'text' -> Text before the shared message
- * 'after' -> Text after the shared message
- * 'image' -> Preview image of the message
- * 'url' -> Url to the attached message
- * 'title' -> Title of the attachment
- * 'description' -> Description of the attachment
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- private static function getOldAttachmentData(string $body): array
- {
- $post = [];
-
- // Simplify image codes
- $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
-
- if (preg_match_all("(\[class=(.*?)\](.*?)\[\/class\])ism", $body, $attached, PREG_SET_ORDER)) {
- foreach ($attached as $data) {
- if (!in_array($data[1], ['type-link', 'type-video', 'type-photo'])) {
- continue;
- }
-
- $post['type'] = substr($data[1], 5);
-
- $pos = strpos($body, $data[0]);
- if ($pos > 0) {
- $post['text'] = trim(substr($body, 0, $pos));
- $post['after'] = trim(substr($body, $pos + strlen($data[0])));
- } else {
- $post['text'] = trim(str_replace($data[0], '', $body));
- $post['after'] = '';
- }
-
- $attacheddata = $data[2];
-
- if (preg_match("/\[img\](.*?)\[\/img\]/ism", $attacheddata, $matches)) {
-
- $picturedata = Images::getInfoFromURLCached($matches[1]);
-
- if ($picturedata) {
- if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1])) {
- $post['image'] = $matches[1];
- } else {
- $post['preview'] = $matches[1];
- }
- }
- }
-
- if (preg_match("/\[bookmark\=(.*?)\](.*?)\[\/bookmark\]/ism", $attacheddata, $matches)) {
- $post['url'] = $matches[1];
- $post['title'] = $matches[2];
- }
- if (!empty($post['url']) && (in_array($post['type'], ['link', 'video']))
- && preg_match("/\[url\=(.*?)\](.*?)\[\/url\]/ism", $attacheddata, $matches)) {
- $post['url'] = $matches[1];
- }
-
- // Search for description
- if (preg_match("/\[quote\](.*?)\[\/quote\]/ism", $attacheddata, $matches)) {
- $post['description'] = $matches[1];
- }
- }
- }
- return $post;
- }
-
/**
* Fetches attachment data that were generated with the "attachment" element
*
@@ -178,7 +103,7 @@ class BBCode
if (!preg_match("/(.*)\[attachment(.*?)\](.*?)\[\/attachment\](.*)/ism", $body, $match)) {
DI::profiler()->stopRecording();
- return self::getOldAttachmentData($body);
+ return [];
}
$attributes = $match[2];
@@ -253,183 +178,6 @@ class BBCode
return $data;
}
- public static function getAttachedData(string $body, array $item = []): array
- {
- /*
- - text:
- - type: link, video, photo
- - title:
- - url:
- - image:
- - description:
- - (thumbnail)
- */
-
- DI::profiler()->startRecording('rendering');
- $has_title = !empty($item['title']);
- $plink = $item['plink'] ?? '';
- $post = self::getAttachmentData($body);
-
- // Get all linked images with alternative image description
- if (preg_match_all("/\[img=(http[^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
- foreach ($pictures as $picture) {
- if ($id = Photo::getIdForName($picture[1])) {
- $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => $picture[2], 'id' => $id];
- } else {
- $post['remote_images'][] = ['url' => $picture[1], 'description' => $picture[2]];
- }
- }
- if (!empty($post['images']) && !empty($post['images'][0]['description'])) {
- $post['image_description'] = $post['images'][0]['description'];
- }
- }
-
- if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
- foreach ($pictures as $picture) {
- if ($id = Photo::getIdForName($picture[1])) {
- $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => '', 'id' => $id];
- } else {
- $post['remote_images'][] = ['url' => $picture[1], 'description' => ''];
- }
- }
- }
-
- if (!isset($post['type'])) {
- $post['text'] = $body;
- }
-
- // Simplify image codes
- $post['text'] = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $post['text']);
- $post['text'] = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $post['text']);
-
- // if nothing is found, it maybe having an image.
- if (!isset($post['type'])) {
- if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]#ism", $post['text'], $pictures, PREG_SET_ORDER)) {
- if ((count($pictures) == 1) && !$has_title) {
- if (!empty($item['object-type']) && ($item['object-type'] == Activity\ObjectType::IMAGE)) {
- // Replace the preview picture with the real picture
- $url = str_replace('-1.', '-0.', $pictures[0][2]);
- $data = ['url' => $url, 'type' => 'photo'];
- } else {
- // Checking, if the link goes to a picture
- $data = ParseUrl::getSiteinfoCached($pictures[0][1]);
- }
-
- // Workaround:
- // Sometimes photo posts to the own album are not detected at the start.
- // So we seem to cannot use the cache for these cases. That's strange.
- if (($data['type'] != 'photo') && strstr($pictures[0][1], '/photos/')) {
- $data = ParseUrl::getSiteinfo($pictures[0][1]);
- }
-
- if ($data['type'] == 'photo') {
- $post['type'] = 'photo';
- if (isset($data['images'][0])) {
- $post['image'] = $data['images'][0]['src'];
- $post['url'] = $data['url'];
- } else {
- $post['image'] = $data['url'];
- }
-
- $post['preview'] = $pictures[0][2];
- $post['text'] = trim(str_replace($pictures[0][0], '', $post['text']));
- } else {
- $imgdata = Images::getInfoFromURLCached($pictures[0][1]);
- if (($imgdata) && substr($imgdata['mime'], 0, 6) == 'image/') {
- $post['type'] = 'photo';
- $post['image'] = $pictures[0][1];
- $post['preview'] = $pictures[0][2];
- $post['text'] = trim(str_replace($pictures[0][0], '', $post['text']));
- }
- }
- } elseif (count($pictures) > 0) {
- if (count($pictures) > 4) {
- $post['type'] = 'link';
- $post['url'] = $plink;
- } else {
- $post['type'] = 'photo';
- }
-
- $post['image'] = $pictures[0][2];
-
- foreach ($pictures as $picture) {
- $post['text'] = trim(str_replace($picture[0], '', $post['text']));
- }
- }
- } elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $post['text'], $pictures, PREG_SET_ORDER)) {
- if ($has_title) {
- $post['type'] = 'link';
- $post['url'] = $plink;
- } else {
- $post['type'] = 'photo';
- }
-
- $post['image'] = $pictures[0][1];
- foreach ($pictures as $picture) {
- $post['text'] = trim(str_replace($picture[0], '', $post['text']));
- }
- }
-
- // Test for the external links
- preg_match_all("(\[url\](.*?)\[\/url\])ism", $post['text'], $links1, PREG_SET_ORDER);
- preg_match_all("(\[url\=(.*?)\].*?\[\/url\])ism", $post['text'], $links2, PREG_SET_ORDER);
-
- $links = array_merge($links1, $links2);
-
- // If there is only a single one, then use it.
- // This should cover link posts via API.
- if ((count($links) == 1) && !isset($post['preview']) && !$has_title) {
- $post['type'] = 'link';
- $post['url'] = $links[0][1];
- }
-
- // Simplify "video" element
- $post['text'] = preg_replace('(\[video.*?\ssrc\s?=\s?([^\s\]]+).*?\].*?\[/video\])ism', '[video]$1[/video]', $post['text']);
-
- // Now count the number of external media links
- preg_match_all("(\[vimeo\](.*?)\[\/vimeo\])ism", $post['text'], $links1, PREG_SET_ORDER);
- preg_match_all("(\[youtube\\](.*?)\[\/youtube\\])ism", $post['text'], $links2, PREG_SET_ORDER);
- preg_match_all("(\[video\\](.*?)\[\/video\\])ism", $post['text'], $links3, PREG_SET_ORDER);
- preg_match_all("(\[audio\\](.*?)\[\/audio\\])ism", $post['text'], $links4, PREG_SET_ORDER);
-
- // Add them to the other external links
- $links = array_merge($links, $links1, $links2, $links3, $links4);
-
- // Are there more than one?
- if (count($links) > 1) {
- // The post will be the type "text", which means a blog post
- unset($post['type']);
- $post['url'] = $plink;
- }
-
- if (!isset($post['type'])) {
- $post['type'] = 'text';
- }
-
- if (($post['type'] == 'photo') && empty($post['images']) && !empty($post['remote_images'])) {
- $post['images'] = $post['remote_images'];
- $post['image'] = $post['images'][0]['url'];
- if (!empty($post['images']) && !empty($post['images'][0]['description'])) {
- $post['image_description'] = $post['images'][0]['description'];
- }
- }
- unset($post['remote_images']);
- } elseif (isset($post['url']) && ($post['type'] == 'video')) {
- $data = ParseUrl::getSiteinfoCached($post['url']);
-
- if (isset($data['images'][0])) {
- $post['image'] = $data['images'][0]['src'];
- }
- } elseif (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]#ism", $post['text'], $pictures, PREG_SET_ORDER)) {
- foreach ($pictures as $picture) {
- $post['text'] = trim(str_replace($picture[0], '', $post['text']));
- }
- }
-
- DI::profiler()->stopRecording();
- return $post;
- }
-
/**
* Remove [attachment] BBCode and replaces it with a regular [url]
*
@@ -437,9 +185,10 @@ class BBCode
* @param boolean $no_link_desc No link description
* @return string with replaced body
*/
- public static function removeAttachment(string $body, bool $no_link_desc = false): string
+ public static function replaceAttachment(string $body, bool $no_link_desc = false): string
{
- return preg_replace_callback("/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
+ return preg_replace_callback(
+ "/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
function ($match) use ($body, $no_link_desc) {
$attach_data = self::getAttachmentData($match[0]);
if (empty($attach_data['url'])) {
@@ -451,7 +200,20 @@ class BBCode
} else {
return " \n[url=" . $attach_data['url'] . ']' . $attach_data['title'] . "[/url]\n";
}
- }, $body);
+ },
+ $body
+ );
+ }
+
+ /**
+ * Remove [attachment] BBCode
+ *
+ * @param string $body
+ * @return string with removed attachment
+ */
+ public static function removeAttachment(string $body): string
+ {
+ return trim(preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body));
}
/**
@@ -469,7 +231,7 @@ class BBCode
$text = preg_replace("/\[img.*?\[\/img\]/ism", ' ', $text);
// Remove attachment
- $text = self::removeAttachment($text);
+ $text = self::replaceAttachment($text);
$naked_text = HTML::toPlaintext(self::convert($text, false, 0, true), 0, !$keep_urls);
@@ -489,72 +251,6 @@ class BBCode
}
}
- /**
- * This function changing the visual size (not the real size) of images.
- * The function does not work for pictures with an alternate text description.
- * This could only be changed by using some new "img" BBCode format.
- *
- * @param string $srctext The body with images
- * @return string The body with possibly scaled images
- */
- public static function scaleExternalImages(string $srctext): string
- {
- DI::profiler()->startRecording('rendering');
- $s = $srctext;
-
- // Simplify image links
- $s = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $s);
-
- $matches = null;
- $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER);
- if ($c) {
- foreach ($matches as $mtch) {
- Logger::debug('scale_external_image', ['image' => $mtch[1]]);
-
- $hostname = str_replace('www.', '', substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3));
- if (stristr($mtch[1], $hostname)) {
- continue;
- }
-
- $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);
-
- if ($i) {
- $Image = new Image($i, $type);
- if ($Image->isValid()) {
- $orig_width = $Image->getWidth();
- $orig_height = $Image->getHeight();
-
- if ($orig_width > 640 || $orig_height > 640) {
- $Image->scaleDown(640);
- $new_width = $Image->getWidth();
- $new_height = $Image->getHeight();
- Logger::debug('External images scaled', ['orig_width' => $orig_width, 'new_width' => $new_width, 'orig_height' => $orig_height, 'new_height' => $new_height, 'match' => $mtch[0]]);
- $s = str_replace(
- $mtch[0],
- '[img=' . $new_width . 'x' . $new_height. ']' . $mtch[1] . '[/img]'
- . "\n",
- $s
- );
- Logger::debug('New string', ['image' => $s]);
- }
- }
- }
- }
- }
-
- DI::profiler()->stopRecording();
- return $s;
- }
-
/**
* Truncates imported message body string length to max_import_size
*
@@ -1011,8 +707,11 @@ class BBCode
// We're depending on the property of 'foreach' (specified on the PHP website) that
// it loops over the array starting from the first element and going sequentially
// to the last element
- $newbody = str_replace('[$#saved_image' . $cnt . '#$]',
- '', $newbody);
+ $newbody = str_replace(
+ '[$#saved_image' . $cnt . '#$]',
+ '',
+ $newbody
+ );
$cnt++;
}
@@ -1167,8 +866,7 @@ class BBCode
$attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8');
}
- $img_str = ' $value) {
if (!empty($value)) {
$img_str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT) . '"';
@@ -1205,13 +903,13 @@ class BBCode
switch ($simplehtml) {
case self::MASTODON_API:
case self::TWITTER_API:
- $text = ($is_quote_share? '
' : '') .
- '' . html_entity_decode('♲', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . ":
\n" .
- '
' . $content . ''; + $text = ($is_quote_share ? '
' . $content . ''; break; case self::DIASPORA: if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0) { - $text = ($is_quote_share? '
â² ' . $attributes['author'] . ':
' . "\n"; @@ -1219,7 +917,7 @@ class BBCode $headline = 'â² ' . $attributes['author'] . ' - ' . $attributes['posted'] . ' GMT
' . "\n"; } - $text = ($is_quote_share? '' . trim($content) . '' . "\n"; + $text = ($is_quote_share ? '
' . trim($content) . '' . "\n"; if (empty($attributes['posted']) && !empty($attributes['link'])) { $text .= '' . "\n"; @@ -1232,18 +930,18 @@ class BBCode $headline .= DI::l10n()->t('%2$s %3$s', $attributes['link'], $mention, $attributes['posted']); $headline .= ':' . "\n"; - $text = ($is_quote_share? '
' . trim($content) . '' . "\n"; + $text = ($is_quote_share ? '
' . trim($content) . '' . "\n"; break; case self::OSTATUS: - $text = ($is_quote_share? '
' . html_entity_decode('♲ ', ENT_QUOTES, 'UTF-8') . ' @' . $author_contact['addr'] . ': ' . $content . '
' . "\n"; + $text = ($is_quote_share ? '' . html_entity_decode('♲ ', ENT_QUOTES, 'UTF-8') . ' @' . $author_contact['addr'] . ': ' . $content . '
' . "\n"; break; case self::ACTIVITYPUB: $author = '@' . $author_contact['addr'] . ':'; $text = '' . $content . '
', $text); + $text = preg_replace("(\[h2\](.*?)\[\/h2\])ism", '
', $text); + $text = preg_replace("(\[h3\](.*?)\[\/h3\])ism", '
', $text); + $text = preg_replace("(\[h4\](.*?)\[\/h4\])ism", '
', $text); + $text = preg_replace("(\[h5\](.*?)\[\/h5\])ism", '
', $text); + $text = preg_replace("(\[h6\](.*?)\[\/h6\])ism", '
', $text); // Check for paragraph $text = preg_replace("(\[p\](.*?)\[\/p\])ism", '
$1
', $text); @@ -1751,36 +1458,37 @@ class BBCode // @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\n", '', $text);
$text = str_replace("\n", '
', $text);
// handle nested lists
$endlessloop = 0;
while ((((strpos($text, "[/list]") !== false) && (strpos($text, "[list") !== false)) ||
- ((strpos($text, "[/ol]") !== false) && (strpos($text, "[ol]") !== false)) ||
- ((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) ||
- ((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) {
- $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '
', $text); + $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '
', $text); + $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '
', $text); + $text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism", '
', $text); + $text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '
', $text); + $text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '
', $text); + $text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '
', $text); + $text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '
', $text); + $text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '
', $text); $text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '
', $text); - $text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '
', $text); + $text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '
', $text); - $text = str_replace('[hr]', '
', $text);
if (!$for_plaintext) {
$text = self::performWithEscapedTags($text, ['url', 'img', 'audio', 'video', 'youtube', 'vimeo', 'share', 'attachment', 'iframe', 'bookmark'], function ($text) {
@@ -1805,14 +1513,16 @@ class BBCode
// handle nested quotes
$endlessloop = 0;
- while ((strpos($text, "[/spoiler]")!== false) && (strpos($text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
- $text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
+ while ((strpos($text, "[/spoiler]") !== false) && (strpos($text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
+ $text = preg_replace(
+ "/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
'$1
$2
$1'; + $QuoteLayout = '
$1
'; // Check for [quote] text // handle nested quotes @@ -1827,10 +1537,12 @@ class BBCode // handle nested quotes $endlessloop = 0; - while ((strpos($text, "[/quote]")!== false) && (strpos($text, "[quote=") !== false) && (++$endlessloop < 20)) { - $text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", - "
" . $t_wrote . "
$2", - $text); + while ((strpos($text, "[/quote]") !== false) && (strpos($text, "[quote=") !== false) && (++$endlessloop < 20)) { + $text = preg_replace( + "/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", + "
" . $t_wrote . "
$2", + $text + ); } @@ -1851,18 +1563,25 @@ class BBCode $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '', $text); $text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '', $text); - $text = preg_replace_callback("/\[img\=(.*?)\](.*?)\[\/img\]/ism", + $text = preg_replace_callback( + "/\[[iz]mg\=(.*?)\](.*?)\[\/[iz]mg\]/ism", function ($matches) use ($simple_html, $uriid) { $matches[1] = self::proxyUrl($matches[1], $simple_html, $uriid); - $matches[2] = htmlspecialchars($matches[2], ENT_COMPAT); - return ''; + $alt = htmlspecialchars($matches[2], ENT_COMPAT); + // Fix for Markdown problems with Diaspora, see issue #12701 + if (($simple_html != self::DIASPORA) || strpos($matches[2], '"') === false) { + return ''; + } else { + return ''; + } }, - $text); + $text + ); // Images // [img]pathtoimage[/img] $text = preg_replace_callback( - "/\[img\](.*?)\[\/img\]/ism", + "/\[[iz]mg\](.*?)\[\/[iz]mg\]/ism", function ($matches) use ($simple_html, $uriid) { if (strpos($matches[1], "data:image/") === 0) { return $matches[0]; @@ -1879,8 +1598,8 @@ class BBCode $text = self::convertImages($text, $simple_html, $uriid); - $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '
' . htmlentities(trim($matches[2], "\n\r"), ENT_NOQUOTES, 'UTF-8') . '
';
@@ -2165,9 +1928,9 @@ class BBCode
// Default iframe allowed domains/path
$allowedIframeDomains = [
- DI::baseUrl()->getHostname()
- . (DI::baseUrl()->getUrlPath() ? '/' . DI::baseUrl()->getUrlPath() : '')
- . '/oembed/', # The path part has to change with the source in Content\Oembed::iframe
+ DI::baseUrl()->getHost()
+ . (DI::baseUrl()->getPath() ? '/' . DI::baseUrl()->getPath() : '')
+ . '/oembed/', # The path part has to change with the source in Content\Oembed::iframe
'www.youtube.com/embed/',
'player.vimeo.com/video/',
];
@@ -2179,6 +1942,10 @@ class BBCode
: []
);
+ if (strpos($text, '') !== false || strpos($text, '
') !== false) { + $text = '' . $text . '
'; + } + $text = HTML::purify($text, $allowedIframeDomains); DI::profiler()->stopRecording(); @@ -2280,7 +2047,8 @@ class BBCode * Transform #tags, strip off the [url] and replace spaces with underscore */ $url_search_string = "^\[\]"; - $text = preg_replace_callback("/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/i", + $text = preg_replace_callback( + "/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/i", function ($matches) { return '#' . str_replace(' ', '_', $matches[2]); }, @@ -2327,7 +2095,7 @@ class BBCode $url_search_string = "^\[\]"; $text = preg_replace_callback( "/([@!])\[(.*?)\]\(([$url_search_string]*?)\)/ism", - ['self', 'bbCodeMention2DiasporaCallback'], + [self::class, 'bbCodeMention2DiasporaCallback'], $text ); } @@ -2355,7 +2123,7 @@ class BBCode DI::profiler()->startRecording('rendering'); $ret = []; - self::performWithEscapedTags($string, ['noparse', 'pre', 'code', 'img'], function ($string) use (&$ret) { + self::performWithEscapedTags($string, ['noparse', 'pre', 'code', 'img', 'attachment'], function ($string) use (&$ret) { // Convert hashtag links to hashtags $string = preg_replace('/#\[url\=([^\[\]]*)\](.*?)\[\/url\]/ism', '#$2 ', $string); @@ -2415,7 +2183,8 @@ class BBCode */ public static function expandTags(string $body): string { - return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/", + return preg_replace_callback( + "/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/", function (array $match) { switch ($match[1]) { case '!': @@ -2432,7 +2201,9 @@ class BBCode default: return $match[1] . '[url=' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]'; } - }, $body); + }, + $body + ); } /**