From 0abf2f11c6b3caaad2f9a833f477a094b7488e9a Mon Sep 17 00:00:00 2001 From: Friendika Date: Fri, 20 May 2011 15:46:41 -0700 Subject: [PATCH] patches for youtube's change in link and embed formats, please test --- include/bbcode.php | 6 +++++- include/items.php | 10 ++++++++++ mod/update_network.php | 2 ++ mod/update_profile.php | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/bbcode.php b/include/bbcode.php index 89a14988a..195fc9181 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -94,7 +94,11 @@ function bbcode($Text,$preserve_nl = false) { // Youtube extensions $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); - $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '', $Text); + $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); + + $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '', $Text); + +// $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '', $Text); // oembed tag $Text = oembed_bbcode2html($Text); diff --git a/include/items.php b/include/items.php index 8c2c78696..3170b9384 100644 --- a/include/items.php +++ b/include/items.php @@ -354,6 +354,9 @@ function get_atom_elements($feed,$item) { $res['body'] = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $res['body']); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/[A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + $res['body'] = oembed_html2bbcode($res['body']); $config = HTMLPurifier_Config::createDefault(); @@ -521,6 +524,10 @@ function get_atom_elements($feed,$item) { $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $body); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/[A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + + $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); @@ -560,6 +567,9 @@ function get_atom_elements($feed,$item) { $body = preg_replace('#]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?#s', '[youtube]$1[/youtube]', $body); + $res['body'] = preg_replace('#].+?' . 'http://www.youtube.com/embed/[A-Za-z0-9\-_=]+).+?#s', + '[youtube]$1[/youtube]', $res['body']); + $config = HTMLPurifier_Config::createDefault(); $config->set('Cache.DefinitionImpl', null); diff --git a/mod/update_network.php b/mod/update_network.php index f9914abc2..36de0722a 100644 --- a/mod/update_network.php +++ b/mod/update_network.php @@ -26,6 +26,8 @@ function update_network_content(&$a) { $text = preg_replace($pattern, $replace, $text); $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; + $text = preg_replace($pattern, $replace, $text); echo str_replace("\t",' ',$text); diff --git a/mod/update_profile.php b/mod/update_profile.php index 40ee33325..c4884b30f 100644 --- a/mod/update_profile.php +++ b/mod/update_profile.php @@ -45,6 +45,8 @@ function update_profile_content(&$a) { $text = preg_replace($pattern, $replace, $text); $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; + $text = preg_replace($pattern, $replace, $text); /** * reportedly some versions of MSIE don't handle tabs in XMLHttpRequest documents very well