- $Text = preg_replace_callback("/(.*?)\[attachment(.*?)\](.*?)\[\/attachment\]/ism",
- function ($match) use ($simplehtml, $tryoembed){
-
- $attributes = $match[2];
-
- $type = "";
- preg_match("/type='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
- $type = strtolower($matches[1]);
-
- preg_match('/type="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
- $type = strtolower($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];
-
- //$title = htmlentities($title, ENT_QUOTES, 'UTF-8', false);
- $title = bbcode(html_entity_decode($title, ENT_QUOTES, 'UTF-8'), false, false, true);
- $title = str_replace(array("[", "]"), array("[", "]"), $title);
-
- $image = "";
- if ($type != "video") {
- preg_match("/image='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
- $image = $matches[1];
-
- preg_match('/image="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
- $image = $matches[1];
- }
-
- $preview = "";
- if ($type != "video") {
- preg_match("/preview='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
- $preview = $matches[1];
-
- preg_match('/preview="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "")
- $preview = $matches[1];
- }
-
- if (((strpos($match[1], "[img=") !== false) OR (strpos($match[1], "[img]") !== false)) AND ($image != "")) {
- $preview = $image;
- $image = "";
- }
-
- if ($simplehtml == 7)
- $text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a>',
- $url, $title, $title);
- elseif (($simplehtml != 4) AND ($simplehtml != 0))
- $text = sprintf('<a href="%s" target="_blank">%s</a><br>', $url, $title);
- else {
- $text = sprintf('<span class="type-%s">', $type);
-
- $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $url, $title), $url, $title);
- if ($tryoembed)
- $oembed = tryoembed($bookmark);
- else
- $oembed = $bookmark[0];