Page 1 of 2
youtube auto-embedding for phpBB
Posted: Fri Dec 22, 2006 1:46 pm
by Kieran Huggins
I just wrote some code for a phpBB installation (I guess it's a MOD, sort-of) that I thought people could pitch-in to if they find it useful:
This MOD replaces URLs to youTube videos with their embedded counterparts.
Edit 'includes/bbcode.php' and find:
Code: Select all
function make_clickable($text)
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;
then add:
Code: Select all
// youtube code..
$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://(www\.)?youtube\.com/watch\?v=([a-zA-Z0-9\-_]+)(</a>)?#im",' <!-- BEGIN youtube --><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$4"></param><embed src="http://www.youtube.com/v/$4" type="application/x-shockwave-flash" width="425" height="350"></embed></object><br /><a href="http://youtube.com/watch?v=$4" target="_blank">http://youtube.com/watch?v=$4</a><!-- END youtube -->', $ret);
This works with plaintext URLs and already linked URLs, and with or without the "www".
If anyone wants to improve this code, my suggestion would be to not embed the video if it's quoted.
Any takers?
Maybe after we're done here one of the mods would drop this in the snippets section?
Cheers,
Kieran
Posted: Fri Dec 22, 2006 7:42 pm
by Ambush Commander
If someone linked to the youtube video, they probably want it to stay a link. This should be implemented as
a custom BBcode tag.
Posted: Sat Dec 30, 2006 8:53 am
by Neno
Hi,
youtube auto-embedding is perfect for me. Could you write a similar code for google videos auto-embedding?
Thank you
Posted: Sat Dec 30, 2006 4:13 pm
by Kieran Huggins
I'll make you a deal - if you try to write it and post it here, I'll help fix it if it's broken

Posted: Sat Dec 30, 2006 6:47 pm
by Neno

OK I've tried
Code: Select all
$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://video.google.com/videoplay\?docid=([a-zA-Z0-9\-_]+)(</a>)?#im",'<!-- BEGIN GVideo --><object width="425" height="350"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=$4"></param><embed src="http://video.google.com/googleplayer.swf?docId=$4" type="application/x-shockwave-flash" width="425" height="350"></embed></object></p><!-- END Gvideo -->', $ret);
The first part is ok, I can see the player, but don't know how to link a movie...

Posted: Sat Dec 30, 2006 7:06 pm
by Kieran Huggins
not quite.. if you check out google's embed code, it's quite different from youtube:
Code: Select all
// google video code...
$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://video.google.com/videoplay\?docid=([0-9]+)(</a>)?#im",'<!-- BEGIN GVideo --><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=$3"> </embed><br /><a href="http://video.google.com/videoplay?docid=$3" target="_blank">http://video.google.com/videoplay?docid=$3</a><!-- END Gvideo -->', $ret);
also, the "docid" is only numeric in GV's case
Posted: Sat Dec 30, 2006 7:26 pm
by Neno
Great!
Thank you very much
Posted: Sat Dec 30, 2006 8:33 pm
by thiscatis
freebies for all!.
Would be cool for a newer version that you just have to select from which video hosting site your linking (like the 5 biggest one)
instead of having 5 mods
Posted: Sun Dec 31, 2006 4:11 am
by Kieran Huggins
thiscatis wrote:freebies for all!.
Would be cool for a newer version that you just have to select from which video hosting site your linking (like the 5 biggest one)
instead of having 5 mods
You can just paste these next to one another in 'includes/bbcode.php'... I don't know how to make it any simpler

Posted: Sun Mar 25, 2007 8:36 am
by tvleeuwen
Thanks for the code.
little modifications for your sripts so it works with al language codes. for my with video.google.nl
Code: Select all
// google video code...
$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://video.google.([a-z]+)/videoplay\?docid=([0-9\-_]+)(</a>)?#im",'<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.$3/googleplayer.swf?docId=$4"> </embed><br /><a href="http://video.google.$3/videoplay?docid=$4" target="_blank">http://video.google.$3/videoplay?docid=$4</a>, $ret);
Posted: Mon Mar 26, 2007 2:42 am
by Kieran Huggins
a welcome addition

Thanks tvleeuwen
Re: youtube auto-embedding for phpBB
Posted: Fri Apr 20, 2007 6:15 am
by libralion
Kieran Huggins wrote:I just wrote some code for a phpBB installation (I guess it's a MOD, sort-of) that I thought people could pitch-in to if they find it useful:
This MOD replaces URLs to youTube videos with their embedded counterparts.
Edit 'includes/bbcode.php' and find:
Code: Select all
function make_clickable($text)
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;
then add:
Code: Select all
// youtube code..
$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://(www\.)?youtube\.com/watch\?v=([a-zA-Z0-9\-_]+)(</a>)?#im",' <!-- BEGIN youtube --><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$4"></param><embed src="http://www.youtube.com/v/$4" type="application/x-shockwave-flash" width="425" height="350"></embed></object><br /><a href="http://youtube.com/watch?v=$4" target="_blank">http://youtube.com/watch?v=$4</a><!-- END youtube -->', $ret);
This works with plaintext URLs and already linked URLs, and with or without the "www".
If anyone wants to improve this code, my suggestion would be to not embed the video if it's quoted.
Any takers?
Maybe after we're done here one of the mods would drop this in the snippets section?
Cheers,
Kieran
Hello Kieran,
I changed the bbcode.php, but I don't see the videoplayer of youtube on my page.
What am I doing wrong?
http://tina-turner.nl/phpBB2/viewtopic.php?p=324#324
Johanna
Posted: Fri Apr 20, 2007 9:15 am
by Kieran Huggins
seems to be working...
Works now
Posted: Fri Apr 20, 2007 9:36 am
by libralion
Kieran Huggins wrote:seems to be working...
Hello Kieran,
Yes I just had to insert the complete embed code. I thought I only had to write down an url.
Thanks,
Johanna

Posted: Sat Apr 21, 2007 2:23 am
by Kieran Huggins
I just type in the URL... the code above should transform it into the embed code