- $title2 = $data["title"];
-
- $test1 = trim(html_entity_decode($data["text"],ENT_QUOTES,'UTF-8'));
- $test2 = trim(html_entity_decode($data["title"],ENT_QUOTES,'UTF-8'));
-
- // If the link description is similar to the text above then don't add the link description
- if (($data["title"] != "") AND ((strpos($test1,$test2) !== false) OR
- (similar_text($test1,$test2) / strlen($data["title"])) > 0.9))
- $title2 = $data["url"];
- $text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a><br />',
- $data["url"], $data["title"], $title2);
- } elseif (($simplehtml != 4) AND ($simplehtml != 0))
- $text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
- else {
- $text = sprintf('<span class="type-%s">', $data["type"]);
-
- $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]);
- if ($tryoembed)
- $oembed = tryoembed($bookmark);
- else
- $oembed = $bookmark[0];
-
- if (strstr(strtolower($oembed), "<iframe "))
- $text = $oembed;
- else {
- if (($data["image"] != "") AND !strstr(strtolower($oembed), "<img "))
- $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
- elseif (($data["preview"] != "") AND !strstr(strtolower($oembed), "<img "))
- $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);
-
- if (($data["type"] == "photo") AND ($data["url"] != "") AND ($data["image"] != ""))
- $text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]);
- else
- $text .= $oembed;
-
- if (trim($data["description"]) != "")
- $text .= sprintf('<blockquote>%s</blockquote></span>', trim($data["description"]));
+ $return = style_url_for_mastodon($data["url"]);
+ } elseif (($simplehtml != 4) && ($simplehtml != 0)) {
+ $return = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
+ } else {
+ try {
+ if ($tryoembed && OEmbed::isAllowedURL($data['url'])) {
+ $return = OEmbed::getHTML($data['url'], $data['title']);
+ } else {
+ throw new Exception('OEmbed is disabled for this attachment.');
+ }
+ } catch (Exception $e) {
+ if ($simplehtml != 4) {
+ $return = sprintf('<div class="type-%s">', $data["type"]);
+ }
+
+ if ($data["image"] != "") {
+ $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
+ } elseif ($data["preview"] != "") {
+ $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);
+ }
+
+ if (($data["type"] == "photo") && ($data["url"] != "") && ($data["image"] != "")) {
+ $return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]);
+ } else {
+ $return .= sprintf('<h4><a href="%s">%s</a></h4>', $data['url'], $data['title']);
+ }
+
+ if ($data["description"] != "" && $data["description"] != $data["title"]) {
+ $return .= sprintf('<blockquote>%s</blockquote>', trim(bbcode($data["description"])));
+ }
+
+ if ($data["type"] == "link") {
+ $return .= sprintf('<sup><a href="%s">%s</a></sup>', $data['url'], parse_url($data['url'], PHP_URL_HOST));
+ }
+
+ if ($simplehtml != 4) {
+ $return .= '</div>';
+ }