function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $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) { $title2 = $title; $test1 = trim(html_entity_decode($match[1], ENT_QUOTES, 'UTF-8')); $test2 = trim(html_entity_decode($title, ENT_QUOTES, 'UTF-8')); // If the link description is similar to the text above then don't add the link description if ($title != "" and (strpos($test1, $test2) !== false or similar_text($test1, $test2) / strlen($title) > 0.9)) { $title2 = $url; } $text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a><br />', $url, $title, $title2); } 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]; } if (strstr(strtolower($oembed), "<iframe ")) { $text = $oembed; } else { if ($image != "" and !strstr(strtolower($oembed), "<img ")) { $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $url, proxy_url($image), $title); } elseif ($preview != "" and !strstr(strtolower($oembed), "<img ")) { $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $url, proxy_url($preview), $title); } $text .= $oembed; $text .= sprintf('<blockquote>%s</blockquote></span>', trim($match[3])); } } return $match[1] . $text; }, $Text); return $Text; }
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 = 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); $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 ($plaintext) { $text = sprintf('<a href="%s" target="_blank">%s</a>', $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]; } if ($image != "" and !strstr(strtolower($oembed), "<img ")) { $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $url, $image, $title); } elseif ($preview != "" and !strstr(strtolower($oembed), "<img ")) { $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $url, $preview, $title); } $text .= $oembed; $text .= sprintf('<blockquote>%s</blockquote></span>', trim($match[2])); } return $text; }, $Text); return $Text; }