diff --git a/include/bbcode.php b/include/bbcode.php index 87a8eaa9b3..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,14 +77,16 @@ 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 (strstr(strtolower($oembed), "'; } @@ -356,24 +395,4 @@ class OEmbed return $innerHTML; } - /** - * Determines if rich content OEmbed is allowed for the provided URL - * - * @brief Determines if rich content OEmbed is allowed for the provided URL - * @param string $url - * @return boolean - */ - private static function isAllowedURL($url) - { - if (!Config::get('system', 'no_oembed_rich_content')) { - return true; - } - - $domain = parse_url($url, PHP_URL_HOST); - - $str_allowed = Config::get('system', 'allowed_oembed', ''); - $allowed = explode(',', $str_allowed); - - return allowed_domain($domain, $allowed, true); - } }