diff --git a/include/bbcode.php b/include/bbcode.php
index 4ccab8db5..d6fc81983 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -2,6 +2,79 @@
require_once("include/oembed.php");
require_once('include/event.php');
+function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
+ $Text = preg_replace_callback("/\[attachment(.*?)\](.*?)\[\/attachment\]/ism",
+ function ($match) use ($plaintext){
+
+ $attributes = $match[1];
+
+ $type = "";
+ preg_match("/type='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $type = $matches[1];
+
+ preg_match('/type="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $type = $matches[1];
+
+ if ($type == "")
+ return($match[0]);
+
+ if (!in_array($type, array("link", "audio", "video")))
+ return($match[0]);
+
+ $url = "";
+ preg_match("/url='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $url = $matches[1];
+
+ preg_match('/url="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $url = $matches[1];
+
+ $title = "";
+ preg_match("/title='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $title = $matches[1];
+
+ preg_match('/title="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $title = $matches[1];
+
+ $image = "";
+ preg_match("/image='(.*?)'/ism", $attributes, $matches);
+ if ($matches[1] != "")
+ $image = $matches[1];
+
+ preg_match('/image="(.*?)"/ism', $attributes, $matches);
+ if ($matches[1] != "")
+ $image = $matches[1];
+
+ if ($plaintext)
+ $text = sprintf('%s', $url, $title);
+ else {
+ $text = sprintf('', $type);
+
+ $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $url, $title), $title, $url);
+ if ($tryoembed)
+ $oembed = tryoembed($bookmark);
+ else
+ $oembed = $bookmark[0];
+
+ if (($image != "") AND !strstr(strtolower($oembed), "', $image, $title); // To-Do: Anführungszeichen in "alt"
+
+ $text .= $oembed;
+
+ $text .= sprintf('%s
', trim($match[2]));
+ }
+
+ return($text);
+ },$Text);
+
+ return($Text);
+}
+
function bb_rearrange_link($shared) {
if ($shared[1] != "type-link")
return($shared[0]);
@@ -706,6 +779,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = preg_replace("/\n\[code\]/ism", "[code]", $Text);
$Text = preg_replace("/\[\/code\]\n/ism", "[/code]", $Text);
+ // Handle attached links or videos
+ $Text = bb_attachment($Text, ($simplehtml != 4) AND ($simplehtml != 0), $tryoembed);
+
// Rearrange shared links
if (get_config("system", "rearrange_shared_links") AND (!$simplehtml OR $tryoembed))
$Text = preg_replace_callback("(\[class=(.*?)\](.*?)\[\/class\])ism","bb_rearrange_link",$Text);