diff --git a/include/bbcode.php b/include/bbcode.php
index f20942dba..fed535db5 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -515,7 +515,7 @@ function bb_ShareAttributes($share, $simplehtml)
$preshare = trim($share[1]);
if ($preshare != "") {
- $preshare .= "
";
+ $preshare .= "
";
}
switch ($simplehtml) {
@@ -862,10 +862,31 @@ function bb_highlight($match) {
* @param bool $forplaintext
* @return string
*/
-function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = false, $forplaintext = false) {
-
+function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = false, $forplaintext = false)
+{
$a = get_app();
+ /*
+ * preg_match_callback function to replace potential Oembed tags with Oembed content
+ *
+ * $match[0] = [tag]$url[/tag] or [tag=$url]$title[/tag]
+ * $match[1] = $url
+ * $match[2] = $title or absent
+ */
+ $tryoembed_callback = function ($match)
+ {
+ $url = $match[1];
+ $title = defaults($match, 2, null);
+
+ try {
+ $return = OEmbed::getHTML($url, $title);
+ } catch (Exception $ex) {
+ $return = $match[0];
+ }
+
+ return $return;
+ };
+
// Hide all [noparse] contained bbtags by spacefying them
// POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
@@ -988,7 +1009,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
// Perform URL Search
if ($tryoembed) {
- $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $tryoembed_callback, $Text);
}
if ($simplehtml == 5) {
@@ -1023,7 +1044,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
// }
if ($tryoembed) {
- $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $tryoembed_callback, $Text);
}
$Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
@@ -1222,8 +1243,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
$Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '', $Text);
$Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '', $Text);
- $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
- $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", $tryoembed_callback, $Text);
+ $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", $tryoembed_callback, $Text);
} else {
$Text = preg_replace("/\[video\](.*?)\[\/video\]/",
'$1', $Text);
@@ -1242,9 +1263,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
// Youtube extensions
if ($tryoembed) {
- $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
- $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
- $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", $tryoembed_callback, $Text);
+ $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", $tryoembed_callback, $Text);
+ $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism", $tryoembed_callback, $Text);
}
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism", '[youtube]$1[/youtube]', $Text);
@@ -1259,8 +1280,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
}
if ($tryoembed) {
- $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism", 'tryoembed', $Text);
- $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism", 'tryoembed', $Text);
+ $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism", $tryoembed_callback, $Text);
+ $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism", $tryoembed_callback, $Text);
}
$Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism", '[vimeo]$1[/vimeo]', $Text);
diff --git a/mod/admin.php b/mod/admin.php
index 8eff23aa8..75e28e0fb 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -895,7 +895,7 @@ function admin_page_site_post(App $a)
$allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
$allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
$no_oembed_rich_content = x($_POST,'no_oembed_rich_content');
- $allowed_oembed = ((x($_POST,'allowed_embed')) ? notags(trim($_POST['allowed_embed'])) : '');
+ $allowed_oembed = ((x($_POST,'allowed_oembed')) ? notags(trim($_POST['allowed_oembed'])) : '');
$block_public = ((x($_POST,'block_public')) ? True : False);
$force_publish = ((x($_POST,'publish_all')) ? True : False);
$global_directory = ((x($_POST,'directory')) ? notags(trim($_POST['directory'])) : '');