From: Hypolite Petovan Date: Sun, 7 Jan 2018 05:44:23 +0000 (-0500) Subject: Move tryoembed to Content\OEmbed X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d8a312d286eb64b16c0345723389bb15a2803553;p=friendica.git Move tryoembed to Content\OEmbed - Add bbcode functions documentation - Add Exception handling to OEmbed::getHTML - Fix formatting --- 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, "