From 569156422037859d13ae75cea3d4bd57651d8bb4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 8 Jan 2018 23:52:26 -0500 Subject: [PATCH] Trust OEmbed HTML when it's available - Reworked bb_attachment() to trust OEmbed content when it's successfully pulled - Fix coding standard by renaming parameter and variables --- include/bbcode.php | 61 ++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index fed535db57..08bfab3ed7 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -46,16 +46,16 @@ function bb_map_location($match) { * Note: Can produce a [bookmark] tag in the returned string * * @brief Processes [attachment] tags - * @param string $Text + * @param string $return * @param bool|int $simplehtml * @param bool $tryoembed * @return string */ -function bb_attachment($Text, $simplehtml = false, $tryoembed = true) +function bb_attachment($return, $simplehtml = false, $tryoembed = true) { - $data = get_attachment_data($Text); + $data = get_attachment_data($return); if (!$data) { - return $Text; + return $return; } if (isset($data["title"])) { @@ -68,49 +68,46 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) $data["image"] = ""; } + $return = ''; if ($simplehtml == 7) { - $text = style_url_for_mastodon($data["url"]); + $return = style_url_for_mastodon($data["url"]); } elseif (($simplehtml != 4) && ($simplehtml != 0)) { - $text = sprintf('%s
', $data["url"], $data["title"]); + $return = sprintf('%s
', $data["url"], $data["title"]); } else { - if ($simplehtml != 4) { - $text = sprintf('', $data["type"]); - } - - $oembed = sprintf('[bookmark=%s]%s[/bookmark]', $data['url'], $data['title']); - if ($tryoembed) { - try { - $oembed = OEmbed::getHTML($data['url'], $data['title']); - } catch (Exception $e) { - // $oembed isn't modified + try { + if ($tryoembed) { + $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('', $data["type"]); } - } - if (stripos($oembed, "