From ca77bff933f9a964919d44bcfd2ff09e590028a5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 7 Jan 2018 10:01:41 -0500 Subject: [PATCH 1/3] Restore tryoembed callback - Remove irritating extra
before shared content --- include/bbcode.php | 45 +++++++++++++++++++++++++++++++++------------ include/text.php | 2 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index f20942dbad..fed535db57 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/include/text.php b/include/text.php index 0b763d687c..a79a201358 100644 --- a/include/text.php +++ b/include/text.php @@ -1203,7 +1203,7 @@ function put_item_in_cache(&$item, $update = false) { $rendered_hash = defaults($item, 'rendered-hash', ''); - if ($rendered_hash == '' + if (true || $rendered_hash == '' || $item["rendered-html"] == "" || $rendered_hash != hash("md5", $item["body"]) || Config::get("system", "ignore_cache") From 5605bdd2894a53f240aac46b7d0b2804d11a8fb0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 7 Jan 2018 10:02:21 -0500 Subject: [PATCH 2/3] Remove debug code --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/text.php b/include/text.php index a79a201358..0b763d687c 100644 --- a/include/text.php +++ b/include/text.php @@ -1203,7 +1203,7 @@ function put_item_in_cache(&$item, $update = false) { $rendered_hash = defaults($item, 'rendered-hash', ''); - if (true || $rendered_hash == '' + if ($rendered_hash == '' || $item["rendered-html"] == "" || $rendered_hash != hash("md5", $item["body"]) || Config::get("system", "ignore_cache") From 96221a58a2e0b19ab73dcb0dc0fb164a79213c84 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 7 Jan 2018 10:15:46 -0500 Subject: [PATCH 3/3] Fix typo in admin settings --- mod/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/admin.php b/mod/admin.php index 8eff23aa8a..75e28e0fbc 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'])) : '');