diff --git a/include/bbcode.php b/include/bbcode.php index ab599e7c91..f20942dbad 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -40,8 +40,19 @@ function bb_map_location($match) { return str_replace($match[0], '
' . Map::byLocation($match[1]) . '
', $match[0]); } -function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { - +/** + * Processes [attachment] tags + * + * Note: Can produce a [bookmark] tag in the returned string + * + * @brief Processes [attachment] tags + * @param string $Text + * @param bool|int $simplehtml + * @param bool $tryoembed + * @return string + */ +function bb_attachment($Text, $simplehtml = false, $tryoembed = true) +{ $data = get_attachment_data($Text); if (!$data) { return $Text; @@ -52,10 +63,7 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $data["title"] = str_replace(array("http://", "https://"), "", $data["title"]); } - if (((strpos($data["text"], "[img=") !== false) - || (strpos($data["text"], "[img]") !== false) - || Config::get('system', 'always_show_preview')) - && ($data["image"] != "")) { + if (((strpos($data["text"], "[img=") !== false) || (strpos($data["text"], "[img]") !== false) || Config::get('system', 'always_show_preview')) && ($data["image"] != "")) { $data["preview"] = $data["image"]; $data["image"] = ""; } @@ -69,11 +77,13 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { $text = sprintf('', $data["type"]); } - $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]); + $oembed = sprintf('[bookmark=%s]%s[/bookmark]', $data['url'], $data['title']); if ($tryoembed) { - $oembed = tryoembed($bookmark); - } else { - $oembed = $bookmark[0]; + try { + $oembed = OEmbed::getHTML($data['url'], $data['title']); + } catch (Exception $e) { + // $oembed isn't modified + } } if (stripos($oembed, "